org-agenda.el 372 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 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 convenient 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. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags to not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  661. "Time unit to use when possibly ignoring an agenda item.
  662. See the docstring of various `org-agenda-todo-ignore-*' options.
  663. The default is to compare time stamps using days. An item is thus
  664. considered to be in the future if it is at least one day after today.
  665. Non-nil means to compare time stamps using seconds. An item is then
  666. considered future if it has a time value later than current time."
  667. :group 'org-agenda-skip
  668. :group 'org-agenda-todo-list
  669. :type '(choice
  670. (const :tag "Compare time with days" nil)
  671. (const :tag "Compare time with seconds" t)))
  672. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  673. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  674. The variables
  675. `org-agenda-todo-ignore-with-date',
  676. `org-agenda-todo-ignore-timestamp',
  677. `org-agenda-todo-ignore-scheduled',
  678. `org-agenda-todo-ignore-deadlines'
  679. make the global TODO list skip entries that have time stamps of certain
  680. kinds. If this option is set, the same options will also apply for the
  681. tags-todo search, which is the general tags/property matcher
  682. restricted to unfinished TODO entries only."
  683. :group 'org-agenda-skip
  684. :group 'org-agenda-todo-list
  685. :group 'org-agenda-match-view
  686. :type 'boolean)
  687. (defcustom org-agenda-skip-scheduled-if-done nil
  688. "Non-nil means don't show scheduled items in agenda when they are done.
  689. This is relevant for the daily/weekly agenda, not for the TODO list. And
  690. it applies only to the actual date of the scheduling. Warnings about
  691. an item with a past scheduling dates are always turned off when the item
  692. is DONE."
  693. :group 'org-agenda-skip
  694. :group 'org-agenda-daily/weekly
  695. :type 'boolean)
  696. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  697. "Non-nil means skip scheduling line if same entry shows because of deadline.
  698. In the agenda of today, an entry can show up multiple times because
  699. it is both scheduled and has a nearby deadline, and maybe a plain time
  700. stamp as well.
  701. When this variable is t, then only the deadline is shown and the fact that
  702. the entry is scheduled today or was scheduled previously is not shown.
  703. When this variable is nil, the entry will be shown several times. When
  704. the variable is the symbol `not-today', then skip scheduled previously,
  705. but not scheduled today."
  706. :group 'org-agenda-skip
  707. :group 'org-agenda-daily/weekly
  708. :type '(choice
  709. (const :tag "Never" nil)
  710. (const :tag "Always" t)
  711. (const :tag "Not when scheduled today" not-today)))
  712. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  713. "Non-nil means skip timestamp line if same entry shows because of deadline.
  714. In the agenda of today, an entry can show up multiple times
  715. because it has both a plain timestamp and has a nearby deadline.
  716. When this variable is t, then only the deadline is shown and the
  717. fact that the entry has a timestamp for or including today is not
  718. shown. When this variable is nil, the entry will be shown
  719. several times."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :version "24.1"
  723. :type '(choice
  724. (const :tag "Never" nil)
  725. (const :tag "Always" t)))
  726. (defcustom org-agenda-skip-deadline-if-done nil
  727. "Non-nil means don't show deadlines when the corresponding item is done.
  728. When nil, the deadline is still shown and should give you a happy feeling.
  729. This is relevant for the daily/weekly agenda. And it applied only to the
  730. actually date of the deadline. Warnings about approaching and past-due
  731. deadlines are always turned off when the item is DONE."
  732. :group 'org-agenda-skip
  733. :group 'org-agenda-daily/weekly
  734. :type 'boolean)
  735. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  736. "Non-nil means skip deadline prewarning when entry is also scheduled.
  737. This will apply on all days where a prewarning for the deadline would
  738. be shown, but not at the day when the entry is actually due. On that day,
  739. the deadline will be shown anyway.
  740. This variable may be set to nil, t, the symbol `pre-scheduled',
  741. or a number which will then give the number of days before the actual
  742. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  743. eliminates the deadline prewarning only prior to the scheduled date.
  744. This can be used in a workflow where the first showing of the deadline will
  745. trigger you to schedule it, and then you don't want to be reminded of it
  746. because you will take care of it on the day when scheduled."
  747. :group 'org-agenda-skip
  748. :group 'org-agenda-daily/weekly
  749. :version "24.1"
  750. :type '(choice
  751. (const :tag "Always show prewarning" nil)
  752. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  753. (const :tag "Remove prewarning if entry is scheduled" t)
  754. (integer :tag "Restart prewarning N days before deadline")))
  755. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  756. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  757. When non-nil, after the search for timestamps has matched once in an
  758. entry, the rest of the entry will not be searched."
  759. :group 'org-agenda-skip
  760. :type 'boolean)
  761. (defcustom org-agenda-skip-timestamp-if-done nil
  762. "Non-nil means don't select item by timestamp or -range if it is DONE."
  763. :group 'org-agenda-skip
  764. :group 'org-agenda-daily/weekly
  765. :type 'boolean)
  766. (defcustom org-agenda-dim-blocked-tasks nil
  767. "Non-nil means dim blocked tasks in the agenda display.
  768. This causes some overhead during agenda construction, but if you
  769. have turned on `org-enforce-todo-dependencies',
  770. `org-enforce-todo-checkbox-dependencies', or any other blocking
  771. mechanism, this will create useful feedback in the agenda.
  772. Instead of t, this variable can also have the value `invisible'.
  773. Then blocked tasks will be invisible and only become visible when
  774. they become unblocked. An exemption to this behavior is when a task is
  775. blocked because of unchecked checkboxes below it. Since checkboxes do
  776. not show up in the agenda views, making this task invisible you remove any
  777. trace from agenda views that there is something to do. Therefore, a task
  778. that is blocked because of checkboxes will never be made invisible, it
  779. will only be dimmed."
  780. :group 'org-agenda-daily/weekly
  781. :group 'org-agenda-todo-list
  782. :version "24.3"
  783. :type '(choice
  784. (const :tag "Do not dim" nil)
  785. (const :tag "Dim to a gray face" t)
  786. (const :tag "Make invisible" invisible)))
  787. (defcustom org-timeline-show-empty-dates 3
  788. "Non-nil means `org-timeline' also shows dates without an entry.
  789. When nil, only the days which actually have entries are shown.
  790. When t, all days between the first and the last date are shown.
  791. When an integer, show also empty dates, but if there is a gap of more than
  792. N days, just insert a special line indicating the size of the gap."
  793. :group 'org-agenda-skip
  794. :type '(choice
  795. (const :tag "None" nil)
  796. (const :tag "All" t)
  797. (integer :tag "at most")))
  798. (defgroup org-agenda-startup nil
  799. "Options concerning initial settings in the Agenda in Org Mode."
  800. :tag "Org Agenda Startup"
  801. :group 'org-agenda)
  802. (defcustom org-agenda-menu-show-matcher t
  803. "Non-nil means show the match string in the agenda dispatcher menu.
  804. When nil, the matcher string is not shown, but is put into the help-echo
  805. property so than moving the mouse over the command shows it.
  806. Setting it to nil is good if matcher strings are very long and/or if
  807. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  808. :group 'org-agenda
  809. :version "24.1"
  810. :type 'boolean)
  811. (org-define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  812. (defcustom org-agenda-menu-two-columns nil
  813. "Non-nil means, use two columns to show custom commands in the dispatcher.
  814. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  815. to nil."
  816. :group 'org-agenda
  817. :version "24.1"
  818. :type 'boolean)
  819. (org-define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  820. (defcustom org-agenda-finalize-hook nil
  821. "Hook run just before displaying an agenda buffer.
  822. The buffer is still writable when the hook is called.
  823. You can modify some of the buffer substrings but you should be
  824. extra careful not to modify the text properties of the agenda
  825. headlines as the agenda display heavily relies on them."
  826. :group 'org-agenda-startup
  827. :type 'hook)
  828. (defcustom org-agenda-mouse-1-follows-link nil
  829. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  830. A longer mouse click will still set point. Does not work on XEmacs.
  831. Needs to be set before org.el is loaded."
  832. :group 'org-agenda-startup
  833. :type 'boolean)
  834. (defcustom org-agenda-start-with-follow-mode nil
  835. "The initial value of follow mode in a newly created agenda window."
  836. :group 'org-agenda-startup
  837. :type 'boolean)
  838. (defcustom org-agenda-follow-indirect nil
  839. "Non-nil means `org-agenda-follow-mode' displays only the
  840. current item's tree, in an indirect buffer."
  841. :group 'org-agenda
  842. :version "24.1"
  843. :type 'boolean)
  844. (defcustom org-agenda-show-outline-path t
  845. "Non-nil means show outline path in echo area after line motion."
  846. :group 'org-agenda-startup
  847. :type 'boolean)
  848. (defcustom org-agenda-start-with-entry-text-mode nil
  849. "The initial value of entry-text-mode in a newly created agenda window."
  850. :group 'org-agenda-startup
  851. :type 'boolean)
  852. (defcustom org-agenda-entry-text-maxlines 5
  853. "Number of text lines to be added when `E' is pressed in the agenda.
  854. Note that this variable only used during agenda display. Add add entry text
  855. when exporting the agenda, configure the variable
  856. `org-agenda-add-entry-ext-maxlines'."
  857. :group 'org-agenda
  858. :type 'integer)
  859. (defcustom org-agenda-entry-text-exclude-regexps nil
  860. "List of regular expressions to clean up entry text.
  861. The complete matches of all regular expressions in this list will be
  862. removed from entry text before it is shown in the agenda."
  863. :group 'org-agenda
  864. :type '(repeat (regexp)))
  865. (defvar org-agenda-entry-text-cleanup-hook nil
  866. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  867. This cleanup is done in a temporary buffer, so the function may inspect and
  868. change the entire buffer.
  869. Some default stuff like drawers and scheduling/deadline dates will already
  870. have been removed when this is called, as will any matches for regular
  871. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  872. (defvar org-agenda-include-inactive-timestamps nil
  873. "Non-nil means include inactive time stamps in agenda and timeline.
  874. Dynamically scoped.")
  875. (defgroup org-agenda-windows nil
  876. "Options concerning the windows used by the Agenda in Org Mode."
  877. :tag "Org Agenda Windows"
  878. :group 'org-agenda)
  879. (defcustom org-agenda-window-setup 'reorganize-frame
  880. "How the agenda buffer should be displayed.
  881. Possible values for this option are:
  882. current-window Show agenda in the current window, keeping all other windows.
  883. other-window Use `switch-to-buffer-other-window' to display agenda.
  884. reorganize-frame Show only two windows on the current frame, the current
  885. window and the agenda.
  886. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  887. Also, when exiting the agenda, kill that frame.
  888. See also the variable `org-agenda-restore-windows-after-quit'."
  889. :group 'org-agenda-windows
  890. :type '(choice
  891. (const current-window)
  892. (const other-frame)
  893. (const other-window)
  894. (const reorganize-frame)))
  895. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  896. "The min and max height of the agenda window as a fraction of frame height.
  897. The value of the variable is a cons cell with two numbers between 0 and 1.
  898. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  899. :group 'org-agenda-windows
  900. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  901. (defcustom org-agenda-restore-windows-after-quit nil
  902. "Non-nil means restore window configuration upon exiting agenda.
  903. Before the window configuration is changed for displaying the agenda,
  904. the current status is recorded. When the agenda is exited with
  905. `q' or `x' and this option is set, the old state is restored. If
  906. `org-agenda-window-setup' is `other-frame', the value of this
  907. option will be ignored."
  908. :group 'org-agenda-windows
  909. :type 'boolean)
  910. (defcustom org-agenda-ndays nil
  911. "Number of days to include in overview display.
  912. Should be 1 or 7.
  913. Obsolete, see `org-agenda-span'."
  914. :group 'org-agenda-daily/weekly
  915. :type 'integer)
  916. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  917. (defcustom org-agenda-span 'week
  918. "Number of days to include in overview display.
  919. Can be day, week, month, year, or any number of days.
  920. Custom commands can set this variable in the options section."
  921. :group 'org-agenda-daily/weekly
  922. :type '(choice (const :tag "Day" day)
  923. (const :tag "Week" week)
  924. (const :tag "Month" month)
  925. (const :tag "Year" year)
  926. (integer :tag "Custom")))
  927. (defcustom org-agenda-start-on-weekday 1
  928. "Non-nil means start the overview always on the specified weekday.
  929. 0 denotes Sunday, 1 denotes Monday etc.
  930. When nil, always start on the current day.
  931. Custom commands can set this variable in the options section."
  932. :group 'org-agenda-daily/weekly
  933. :type '(choice (const :tag "Today" nil)
  934. (integer :tag "Weekday No.")))
  935. (defcustom org-agenda-show-all-dates t
  936. "Non-nil means `org-agenda' shows every day in the selected range.
  937. When nil, only the days which actually have entries are shown."
  938. :group 'org-agenda-daily/weekly
  939. :type 'boolean)
  940. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  941. "Format string for displaying dates in the agenda.
  942. Used by the daily/weekly agenda and by the timeline. This should be
  943. a format string understood by `format-time-string', or a function returning
  944. the formatted date as a string. The function must take a single argument,
  945. a calendar-style date list like (month day year)."
  946. :group 'org-agenda-daily/weekly
  947. :type '(choice
  948. (string :tag "Format string")
  949. (function :tag "Function")))
  950. (defun org-agenda-format-date-aligned (date)
  951. "Format a date string for display in the daily/weekly agenda, or timeline.
  952. This function makes sure that dates are aligned for easy reading."
  953. (require 'cal-iso)
  954. (let* ((dayname (calendar-day-name date))
  955. (day (cadr date))
  956. (day-of-week (calendar-day-of-week date))
  957. (month (car date))
  958. (monthname (calendar-month-name month))
  959. (year (nth 2 date))
  960. (iso-week (org-days-to-iso-week
  961. (calendar-absolute-from-gregorian date)))
  962. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  963. (1- year))
  964. ((and (= month 12) (<= iso-week 1))
  965. (1+ year))
  966. (t year)))
  967. (weekstring (if (= day-of-week 1)
  968. (format " W%02d" iso-week)
  969. "")))
  970. (format "%-10s %2d %s %4d%s"
  971. dayname day monthname year weekstring)))
  972. (defcustom org-agenda-time-leading-zero nil
  973. "Non-nil means use leading zero for military times in agenda.
  974. For example, 9:30am would become 09:30 rather than 9:30."
  975. :group 'org-agenda-daily/weekly
  976. :version "24.1"
  977. :type 'boolean)
  978. (defcustom org-agenda-timegrid-use-ampm nil
  979. "When set, show AM/PM style timestamps on the timegrid."
  980. :group 'org-agenda
  981. :version "24.1"
  982. :type 'boolean)
  983. (defun org-agenda-time-of-day-to-ampm (time)
  984. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  985. (let* ((hour-number (string-to-number (substring time 0 -3)))
  986. (minute (substring time -2))
  987. (ampm "am"))
  988. (cond
  989. ((equal hour-number 12)
  990. (setq ampm "pm"))
  991. ((> hour-number 12)
  992. (setq ampm "pm")
  993. (setq hour-number (- hour-number 12))))
  994. (concat
  995. (if org-agenda-time-leading-zero
  996. (format "%02d" hour-number)
  997. (format "%02s" (number-to-string hour-number)))
  998. ":" minute ampm)))
  999. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1000. "Conditionally convert TIME to AM/PM format
  1001. based on `org-agenda-timegrid-use-ampm'"
  1002. (if org-agenda-timegrid-use-ampm
  1003. (org-agenda-time-of-day-to-ampm time)
  1004. time))
  1005. (defcustom org-agenda-weekend-days '(6 0)
  1006. "Which days are weekend?
  1007. These days get the special face `org-agenda-date-weekend' in the agenda
  1008. and timeline buffers."
  1009. :group 'org-agenda-daily/weekly
  1010. :type '(set :greedy t
  1011. (const :tag "Monday" 1)
  1012. (const :tag "Tuesday" 2)
  1013. (const :tag "Wednesday" 3)
  1014. (const :tag "Thursday" 4)
  1015. (const :tag "Friday" 5)
  1016. (const :tag "Saturday" 6)
  1017. (const :tag "Sunday" 0)))
  1018. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1019. "Non-nil means jump to today when moving a past date forward in time.
  1020. When using S-right in the agenda to move a a date forward, and the date
  1021. stamp currently points to the past, the first key press will move it
  1022. to today. WHen nil, just move one day forward even if the date stays
  1023. in the past."
  1024. :group 'org-agenda-daily/weekly
  1025. :version "24.1"
  1026. :type 'boolean)
  1027. (defcustom org-agenda-include-diary nil
  1028. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1029. Custom commands can set this variable in the options section."
  1030. :group 'org-agenda-daily/weekly
  1031. :type 'boolean)
  1032. (defcustom org-agenda-include-deadlines t
  1033. "If non-nil, include entries within their deadline warning period.
  1034. Custom commands can set this variable in the options section."
  1035. :group 'org-agenda-daily/weekly
  1036. :version "24.1"
  1037. :type 'boolean)
  1038. (defcustom org-agenda-repeating-timestamp-show-all t
  1039. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1040. When set to a list of strings, only show occurrences of repeating
  1041. stamps for these TODO keywords. When nil, only one occurrence is
  1042. shown, either today or the nearest into the future."
  1043. :group 'org-agenda-daily/weekly
  1044. :type '(choice
  1045. (const :tag "Show repeating stamps" t)
  1046. (repeat :tag "Show repeating stamps for these TODO keywords"
  1047. (string :tag "TODO Keyword"))
  1048. (const :tag "Don't show repeating stamps" nil)))
  1049. (defcustom org-scheduled-past-days 10000
  1050. "No. of days to continue listing scheduled items that are not marked DONE.
  1051. When an item is scheduled on a date, it shows up in the agenda on this
  1052. day and will be listed until it is marked done for the number of days
  1053. given here."
  1054. :group 'org-agenda-daily/weekly
  1055. :type 'integer)
  1056. (defcustom org-agenda-log-mode-items '(closed clock)
  1057. "List of items that should be shown in agenda log mode.
  1058. This list may contain the following symbols:
  1059. closed Show entries that have been closed on that day.
  1060. clock Show entries that have received clocked time on that day.
  1061. state Show all logged state changes.
  1062. Note that instead of changing this variable, you can also press `C-u l' in
  1063. the agenda to display all available LOG items temporarily."
  1064. :group 'org-agenda-daily/weekly
  1065. :type '(set :greedy t (const closed) (const clock) (const state)))
  1066. (defcustom org-agenda-clock-consistency-checks
  1067. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1068. :gap-ok-around ("4:00")
  1069. :default-face ((:background "DarkRed") (:foreground "white"))
  1070. :overlap-face nil :gap-face nil :no-end-time-face nil
  1071. :long-face nil :short-face nil)
  1072. "This is a property list, with the following keys:
  1073. :max-duration Mark clocking chunks that are longer than this time.
  1074. This is a time string like \"HH:MM\", or the number
  1075. of minutes as an integer.
  1076. :min-duration Mark clocking chunks that are shorter that this.
  1077. This is a time string like \"HH:MM\", or the number
  1078. of minutes as an integer.
  1079. :max-gap Mark gaps between clocking chunks that are longer than
  1080. this duration. A number of minutes, or a string
  1081. like \"HH:MM\".
  1082. :gap-ok-around List of times during the day which are usually not working
  1083. times. When a gap is detected, but the gap contains any
  1084. of these times, the gap is *not* reported. For example,
  1085. if this is (\"4:00\" \"13:00\") then gaps that contain
  1086. 4:00 in the morning (i.e. the night) and 13:00
  1087. (i.e. a typical lunch time) do not cause a warning.
  1088. You should have at least one time during the night in this
  1089. list, or otherwise the first task each morning will trigger
  1090. a warning because it follows a long gap.
  1091. Furthermore, the following properties can be used to define faces for
  1092. issue display.
  1093. :default-face the default face, if the specific face is undefined
  1094. :overlap-face face for overlapping clocks
  1095. :gap-face face for gaps between clocks
  1096. :no-end-time-face face for incomplete clocks
  1097. :long-face face for clock intervals that are too long
  1098. :short-face face for clock intervals that are too short"
  1099. :group 'org-agenda-daily/weekly
  1100. :group 'org-clock
  1101. :version "24.1"
  1102. :type 'plist)
  1103. (defcustom org-agenda-log-mode-add-notes t
  1104. "Non-nil means add first line of notes to log entries in agenda views.
  1105. If a log item like a state change or a clock entry is associated with
  1106. notes, the first line of these notes will be added to the entry in the
  1107. agenda display."
  1108. :group 'org-agenda-daily/weekly
  1109. :type 'boolean)
  1110. (defcustom org-agenda-start-with-log-mode nil
  1111. "The initial value of log-mode in a newly created agenda window.
  1112. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1113. explanations on the possible values."
  1114. :group 'org-agenda-startup
  1115. :group 'org-agenda-daily/weekly
  1116. :type '(choice (const :tag "Don't show log items" nil)
  1117. (const :tag "Show only log items" 'only)
  1118. (const :tag "Show all possible log items" 'clockcheck)
  1119. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1120. (choice (const :tag "Show closed log items" 'closed)
  1121. (const :tag "Show clocked log items" 'clock)
  1122. (const :tag "Show all logged state changes" 'state)))))
  1123. (defcustom org-agenda-start-with-clockreport-mode nil
  1124. "The initial value of clockreport-mode in a newly created agenda window."
  1125. :group 'org-agenda-startup
  1126. :group 'org-agenda-daily/weekly
  1127. :type 'boolean)
  1128. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1129. "Property list with parameters for the clocktable in clockreport mode.
  1130. This is the display mode that shows a clock table in the daily/weekly
  1131. agenda, the properties for this dynamic block can be set here.
  1132. The usual clocktable parameters are allowed here, but you cannot set
  1133. the properties :name, :tstart, :tend, :block, and :scope - these will
  1134. be overwritten to make sure the content accurately reflects the
  1135. current display in the agenda."
  1136. :group 'org-agenda-daily/weekly
  1137. :type 'plist)
  1138. (defcustom org-agenda-search-view-always-boolean nil
  1139. "Non-nil means the search string is interpreted as individual parts.
  1140. The search string for search view can either be interpreted as a phrase,
  1141. or as a list of snippets that define a boolean search for a number of
  1142. strings.
  1143. When this is non-nil, the string will be split on whitespace, and each
  1144. snippet will be searched individually, and all must match in order to
  1145. select an entry. A snippet is then a single string of non-white
  1146. characters, or a string in double quotes, or a regexp in {} braces.
  1147. If a snippet is preceded by \"-\", the snippet must *not* match.
  1148. \"+\" is syntactic sugar for positive selection. Each snippet may
  1149. be found as a full word or a partial word, but see the variable
  1150. `org-agenda-search-view-force-full-words'.
  1151. When this is nil, search will look for the entire search phrase as one,
  1152. with each space character matching any amount of whitespace, including
  1153. line breaks.
  1154. Even when this is nil, you can still switch to Boolean search dynamically
  1155. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1156. is a regexp marked with braces like \"{abc}\", this will also switch to
  1157. boolean search."
  1158. :group 'org-agenda-search-view
  1159. :version "24.1"
  1160. :type 'boolean)
  1161. (if (fboundp 'defvaralias)
  1162. (defvaralias 'org-agenda-search-view-search-words-only
  1163. 'org-agenda-search-view-always-boolean))
  1164. (defcustom org-agenda-search-view-force-full-words nil
  1165. "Non-nil means, search words must be matches as complete words.
  1166. When nil, they may also match part of a word."
  1167. :group 'org-agenda-search-view
  1168. :version "24.1"
  1169. :type 'boolean)
  1170. (defcustom org-agenda-search-view-max-outline-level nil
  1171. "Maximum outline level to display in search view.
  1172. E.g. when this is set to 1, the search view will only
  1173. show headlines of level 1."
  1174. :group 'org-agenda-search-view
  1175. :version "24.3"
  1176. :type 'integer)
  1177. (defgroup org-agenda-time-grid nil
  1178. "Options concerning the time grid in the Org-mode Agenda."
  1179. :tag "Org Agenda Time Grid"
  1180. :group 'org-agenda)
  1181. (defcustom org-agenda-search-headline-for-time t
  1182. "Non-nil means search headline for a time-of-day.
  1183. If the headline contains a time-of-day in one format or another, it will
  1184. be used to sort the entry into the time sequence of items for a day.
  1185. Some people have time stamps in the headline that refer to the creation
  1186. time or so, and then this produces an unwanted side effect. If this is
  1187. the case for your, use this variable to turn off searching the headline
  1188. for a time."
  1189. :group 'org-agenda-time-grid
  1190. :type 'boolean)
  1191. (defcustom org-agenda-use-time-grid t
  1192. "Non-nil means show a time grid in the agenda schedule.
  1193. A time grid is a set of lines for specific times (like every two hours between
  1194. 8:00 and 20:00). The items scheduled for a day at specific times are
  1195. sorted in between these lines.
  1196. For details about when the grid will be shown, and what it will look like, see
  1197. the variable `org-agenda-time-grid'."
  1198. :group 'org-agenda-time-grid
  1199. :type 'boolean)
  1200. (defcustom org-agenda-time-grid
  1201. '((daily today require-timed)
  1202. "----------------"
  1203. (800 1000 1200 1400 1600 1800 2000))
  1204. "The settings for time grid for agenda display.
  1205. This is a list of three items. The first item is again a list. It contains
  1206. symbols specifying conditions when the grid should be displayed:
  1207. daily if the agenda shows a single day
  1208. weekly if the agenda shows an entire week
  1209. today show grid on current date, independent of daily/weekly display
  1210. require-timed show grid only if at least one item has a time specification
  1211. The second item is a string which will be placed behind the grid time.
  1212. The third item is a list of integers, indicating the times that should have
  1213. a grid line."
  1214. :group 'org-agenda-time-grid
  1215. :type
  1216. '(list
  1217. (set :greedy t :tag "Grid Display Options"
  1218. (const :tag "Show grid in single day agenda display" daily)
  1219. (const :tag "Show grid in weekly agenda display" weekly)
  1220. (const :tag "Always show grid for today" today)
  1221. (const :tag "Show grid only if any timed entries are present"
  1222. require-timed)
  1223. (const :tag "Skip grid times already present in an entry"
  1224. remove-match))
  1225. (string :tag "Grid String")
  1226. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1227. (defcustom org-agenda-show-current-time-in-grid t
  1228. "Non-nil means show the current time in the time grid."
  1229. :group 'org-agenda-time-grid
  1230. :version "24.1"
  1231. :type 'boolean)
  1232. (defcustom org-agenda-current-time-string
  1233. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1234. "The string for the current time marker in the agenda."
  1235. :group 'org-agenda-time-grid
  1236. :version "24.1"
  1237. :type 'string)
  1238. (defgroup org-agenda-sorting nil
  1239. "Options concerning sorting in the Org-mode Agenda."
  1240. :tag "Org Agenda Sorting"
  1241. :group 'org-agenda)
  1242. (defcustom org-agenda-sorting-strategy
  1243. '((agenda habit-down time-up priority-down category-keep)
  1244. (todo priority-down category-keep)
  1245. (tags priority-down category-keep)
  1246. (search category-keep))
  1247. "Sorting structure for the agenda items of a single day.
  1248. This is a list of symbols which will be used in sequence to determine
  1249. if an entry should be listed before another entry. The following
  1250. symbols are recognized:
  1251. time-up Put entries with time-of-day indications first, early first
  1252. time-down Put entries with time-of-day indications first, late first
  1253. category-keep Keep the default order of categories, corresponding to the
  1254. sequence in `org-agenda-files'.
  1255. category-up Sort alphabetically by category, A-Z.
  1256. category-down Sort alphabetically by category, Z-A.
  1257. tag-up Sort alphabetically by last tag, A-Z.
  1258. tag-down Sort alphabetically by last tag, Z-A.
  1259. priority-up Sort numerically by priority, high priority last.
  1260. priority-down Sort numerically by priority, high priority first.
  1261. todo-state-up Sort by todo state, tasks that are done last.
  1262. todo-state-down Sort by todo state, tasks that are done first.
  1263. effort-up Sort numerically by estimated effort, high effort last.
  1264. effort-down Sort numerically by estimated effort, high effort first.
  1265. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1266. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1267. habit-up Put entries that are habits first
  1268. habit-down Put entries that are habits last
  1269. alpha-up Sort headlines alphabetically
  1270. alpha-down Sort headlines alphabetically, reversed
  1271. The different possibilities will be tried in sequence, and testing stops
  1272. if one comparison returns a \"not-equal\". For example, the default
  1273. '(time-up category-keep priority-down)
  1274. means: Pull out all entries having a specified time of day and sort them,
  1275. in order to make a time schedule for the current day the first thing in the
  1276. agenda listing for the day. Of the entries without a time indication, keep
  1277. the grouped in categories, don't sort the categories, but keep them in
  1278. the sequence given in `org-agenda-files'. Within each category sort by
  1279. priority.
  1280. Leaving out `category-keep' would mean that items will be sorted across
  1281. categories by priority.
  1282. Instead of a single list, this can also be a set of list for specific
  1283. contents, with a context symbol in the car of the list, any of
  1284. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1285. Custom commands can bind this variable in the options section."
  1286. :group 'org-agenda-sorting
  1287. :type `(choice
  1288. (repeat :tag "General" ,org-sorting-choice)
  1289. (list :tag "Individually"
  1290. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1291. (repeat ,org-sorting-choice))
  1292. (cons (const :tag "Strategy for TODO lists" todo)
  1293. (repeat ,org-sorting-choice))
  1294. (cons (const :tag "Strategy for Tags matches" tags)
  1295. (repeat ,org-sorting-choice))
  1296. (cons (const :tag "Strategy for search matches" search)
  1297. (repeat ,org-sorting-choice)))))
  1298. (defcustom org-agenda-cmp-user-defined nil
  1299. "A function to define the comparison `user-defined'.
  1300. This function must receive two arguments, agenda entry a and b.
  1301. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1302. the user comparison, return nil.
  1303. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1304. part of an agenda sorting strategy."
  1305. :group 'org-agenda-sorting
  1306. :type 'symbol)
  1307. (defcustom org-sort-agenda-notime-is-late t
  1308. "Non-nil means items without time are considered late.
  1309. This is only relevant for sorting. When t, items which have no explicit
  1310. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1311. do have a time. When nil, the default time is before 0:00. You can use this
  1312. option to decide if the schedule for today should come before or after timeless
  1313. agenda entries."
  1314. :group 'org-agenda-sorting
  1315. :type 'boolean)
  1316. (defcustom org-sort-agenda-noeffort-is-high t
  1317. "Non-nil means items without effort estimate are sorted as high effort.
  1318. This also applies when filtering an agenda view with respect to the
  1319. < or > effort operator. Then, tasks with no effort defined will be treated
  1320. as tasks with high effort.
  1321. When nil, such items are sorted as 0 minutes effort."
  1322. :group 'org-agenda-sorting
  1323. :type 'boolean)
  1324. (defgroup org-agenda-line-format nil
  1325. "Options concerning the entry prefix in the Org-mode agenda display."
  1326. :tag "Org Agenda Line Format"
  1327. :group 'org-agenda)
  1328. (defcustom org-agenda-prefix-format
  1329. '((agenda . " %i %-12:c%?-12t% s")
  1330. (timeline . " % s")
  1331. (todo . " %i %-12:c")
  1332. (tags . " %i %-12:c")
  1333. (search . " %i %-12:c"))
  1334. "Format specifications for the prefix of items in the agenda views.
  1335. An alist with five entries, each for the different agenda types. The
  1336. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1337. The values are format strings.
  1338. This format works similar to a printf format, with the following meaning:
  1339. %c the category of the item, \"Diary\" for entries from the diary,
  1340. or as given by the CATEGORY keyword or derived from the file name
  1341. %e the effort required by the item
  1342. %l the level of the item (insert X space(s) if item is of level X)
  1343. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1344. %T the last tag of the item (ignore inherited tags, which come first)
  1345. %t the HH:MM time-of-day specification if one applies to the entry
  1346. %s Scheduling/Deadline information, a short string
  1347. %(expression) Eval EXPRESSION and replace the control string
  1348. by the result
  1349. All specifiers work basically like the standard `%s' of printf, but may
  1350. contain two additional characters: a question mark just after the `%'
  1351. and a whitespace/punctuation character just before the final letter.
  1352. If the first character after `%' is a question mark, the entire field
  1353. will only be included if the corresponding value applies to the current
  1354. entry. This is useful for fields which should have fixed width when
  1355. present, but zero width when absent. For example, \"%?-12t\" will
  1356. result in a 12 character time field if a time of the day is specified,
  1357. but will completely disappear in entries which do not contain a time.
  1358. If there is punctuation or whitespace character just before the final
  1359. format letter, this character will be appended to the field value if
  1360. the value is not empty. For example, the format \"%-12:c\" leads to
  1361. \"Diary: \" if the category is \"Diary\". If the category were be
  1362. empty, no additional colon would be inserted.
  1363. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1364. which means:
  1365. - Indent the line with two space characters
  1366. - Give the category a 12 chars wide field, padded with whitespace on
  1367. the right (because of `-'). Append a colon if there is a category
  1368. (because of `:').
  1369. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1370. time, don't put in an empty field, just skip it (because of '?').
  1371. - Finally, put the scheduling information.
  1372. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1373. `org-agenda-remove-tags'.
  1374. Custom commands can set this variable in the options section."
  1375. :type '(choice
  1376. (string :tag "General format")
  1377. (list :greedy t :tag "View dependent"
  1378. (cons (const agenda) (string :tag "Format"))
  1379. (cons (const timeline) (string :tag "Format"))
  1380. (cons (const todo) (string :tag "Format"))
  1381. (cons (const tags) (string :tag "Format"))
  1382. (cons (const search) (string :tag "Format"))))
  1383. :group 'org-agenda-line-format)
  1384. (defvar org-prefix-format-compiled nil
  1385. "The compiled prefix format and associated variables.
  1386. This is a list where first element is a list of variable bindings, and second
  1387. element is the compiled format expression. See the variable
  1388. `org-agenda-prefix-format'.")
  1389. (defcustom org-agenda-todo-keyword-format "%-1s"
  1390. "Format for the TODO keyword in agenda lines.
  1391. Set this to something like \"%-12s\" if you want all TODO keywords
  1392. to occupy a fixed space in the agenda display."
  1393. :group 'org-agenda-line-format
  1394. :type 'string)
  1395. (defcustom org-agenda-diary-sexp-prefix nil
  1396. "A regexp that matches part of a diary sexp entry
  1397. which should be treated as scheduling/deadline information in
  1398. `org-agenda'.
  1399. For example, you can use this to extract the `diary-remind-message' from
  1400. `diary-remind' entries."
  1401. :group 'org-agenda-line-format
  1402. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1403. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1404. "Text preceding timerange entries in the agenda view.
  1405. This is a list with two strings. The first applies when the range
  1406. is entirely on one day. The second applies if the range spans several days.
  1407. The strings may have two \"%d\" format specifiers which will be filled
  1408. with the sequence number of the days, and the total number of days in the
  1409. range, respectively."
  1410. :group 'org-agenda-line-format
  1411. :type '(list
  1412. (string :tag "Deadline today ")
  1413. (choice :tag "Deadline relative"
  1414. (string :tag "Format string")
  1415. (function))))
  1416. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1417. "Text preceding scheduled items in the agenda view.
  1418. This is a list with two strings. The first applies when the item is
  1419. scheduled on the current day. The second applies when it has been scheduled
  1420. previously, it may contain a %d indicating that this is the nth time that
  1421. this item is scheduled, due to automatic rescheduling of unfinished items
  1422. for the following day. So this number is one larger than the number of days
  1423. that passed since this item was scheduled first."
  1424. :group 'org-agenda-line-format
  1425. :type '(list
  1426. (string :tag "Scheduled today ")
  1427. (string :tag "Scheduled previously")))
  1428. (defcustom org-agenda-inactive-leader "["
  1429. "Text preceding item pulled into the agenda by inactive time stamps.
  1430. These entries are added to the agenda when pressing \"[\"."
  1431. :group 'org-agenda-line-format
  1432. :version "24.1"
  1433. :type '(list
  1434. (string :tag "Scheduled today ")
  1435. (string :tag "Scheduled previously")))
  1436. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1437. "Text preceding deadline items in the agenda view.
  1438. This is a list with two strings. The first applies when the item has its
  1439. deadline on the current day. The second applies when it is in the past or
  1440. in the future, it may contain %d to capture how many days away the deadline
  1441. is (was)."
  1442. :group 'org-agenda-line-format
  1443. :type '(list
  1444. (string :tag "Deadline today ")
  1445. (choice :tag "Deadline relative"
  1446. (string :tag "Format string")
  1447. (function))))
  1448. (defcustom org-agenda-remove-times-when-in-prefix t
  1449. "Non-nil means remove duplicate time specifications in agenda items.
  1450. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1451. time-of-day specification in a headline or diary entry is extracted and
  1452. placed into the prefix. If this option is non-nil, the original specification
  1453. \(a timestamp or -range, or just a plain time(range) specification like
  1454. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1455. cluttered.
  1456. The option can be t or nil. It may also be the symbol `beg', indicating
  1457. that the time should only be removed when it is located at the beginning of
  1458. the headline/diary entry."
  1459. :group 'org-agenda-line-format
  1460. :type '(choice
  1461. (const :tag "Always" t)
  1462. (const :tag "Never" nil)
  1463. (const :tag "When at beginning of entry" beg)))
  1464. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1465. "Non-nil means remove time ranges specifications in agenda
  1466. items that span on several days."
  1467. :group 'org-agenda-line-format
  1468. :version "24.1"
  1469. :type 'boolean)
  1470. (defcustom org-agenda-default-appointment-duration nil
  1471. "Default duration for appointments that only have a starting time.
  1472. When nil, no duration is specified in such cases.
  1473. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1474. :group 'org-agenda-line-format
  1475. :type '(choice
  1476. (integer :tag "Minutes")
  1477. (const :tag "No default duration")))
  1478. (defcustom org-agenda-show-inherited-tags t
  1479. "Non-nil means show inherited tags in each agenda line."
  1480. :group 'org-agenda-line-format
  1481. :type 'boolean)
  1482. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1483. "List of agenda view types where to use tag inheritance.
  1484. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1485. controlled by `org-use-tag-inheritance'. In other agenda types,
  1486. `org-use-tag-inheritance' is not used when selecting the agenda
  1487. entries, but you may want the agenda to use the inherited tags
  1488. anyway, e.g. for later tag filtering.
  1489. The default value reset tags in every agenda type. Setting this
  1490. option to nil will speed up non-tags agenda view a lot.
  1491. Allowed value are 'todo, 'search, 'timeline and 'agenda."
  1492. :version "24.3"
  1493. :group 'org-agenda
  1494. :type '(repeat (symbol :tag "Agenda type")))
  1495. (defcustom org-agenda-hide-tags-regexp nil
  1496. "Regular expression used to filter away specific tags in agenda views.
  1497. This means that these tags will be present, but not be shown in the agenda
  1498. line. Secondary filtering will still work on the hidden tags.
  1499. Nil means don't hide any tags."
  1500. :group 'org-agenda-line-format
  1501. :type '(choice
  1502. (const :tag "Hide none" nil)
  1503. (string :tag "Regexp ")))
  1504. (defcustom org-agenda-remove-tags nil
  1505. "Non-nil means remove the tags from the headline copy in the agenda.
  1506. When this is the symbol `prefix', only remove tags when
  1507. `org-agenda-prefix-format' contains a `%T' specifier."
  1508. :group 'org-agenda-line-format
  1509. :type '(choice
  1510. (const :tag "Always" t)
  1511. (const :tag "Never" nil)
  1512. (const :tag "When prefix format contains %T" prefix)))
  1513. (if (fboundp 'defvaralias)
  1514. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1515. 'org-agenda-remove-tags))
  1516. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1517. "Shift tags in agenda items to this column.
  1518. If this number is positive, it specifies the column. If it is negative,
  1519. it means that the tags should be flushright to that column. For example,
  1520. -80 works well for a normal 80 character screen."
  1521. :group 'org-agenda-line-format
  1522. :type 'integer)
  1523. (if (fboundp 'defvaralias)
  1524. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1525. (defcustom org-agenda-fontify-priorities 'cookies
  1526. "Non-nil means highlight low and high priorities in agenda.
  1527. When t, the highest priority entries are bold, lowest priority italic.
  1528. However, settings in `org-priority-faces' will overrule these faces.
  1529. When this variable is the symbol `cookies', only fontify the
  1530. cookies, not the entire task.
  1531. This may also be an association list of priority faces, whose
  1532. keys are the character values of `org-highest-priority',
  1533. `org-default-priority', and `org-lowest-priority' (the default values
  1534. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1535. color as a string, or a list like `(:background \"Red\")'.
  1536. If it is a color, the variable `org-faces-easy-properties'
  1537. determines if it is a foreground or a background color."
  1538. :group 'org-agenda-line-format
  1539. :type '(choice
  1540. (const :tag "Never" nil)
  1541. (const :tag "Defaults" t)
  1542. (const :tag "Cookies only" cookies)
  1543. (repeat :tag "Specify"
  1544. (list (character :tag "Priority" :value ?A)
  1545. (choice :tag "Face "
  1546. (string :tag "Color")
  1547. (sexp :tag "Face"))))))
  1548. (defcustom org-agenda-day-face-function nil
  1549. "Function called to determine what face should be used to display a day.
  1550. The only argument passed to that function is the day. It should
  1551. returns a face, or nil if does not want to specify a face and let
  1552. the normal rules apply."
  1553. :group 'org-agenda-line-format
  1554. :version "24.1"
  1555. :type 'function)
  1556. (defcustom org-agenda-category-icon-alist nil
  1557. "Alist of category icon to be displayed in agenda views.
  1558. Each entry should have the following format:
  1559. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1560. Where CATEGORY-REGEXP is a regexp matching the categories where
  1561. the icon should be displayed.
  1562. FILE-OR-DATA either a file path or a string containing image data.
  1563. The other fields can be omitted safely if not needed:
  1564. TYPE indicates the image type.
  1565. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1566. image data.
  1567. PROPS are additional image attributes to assign to the image,
  1568. like, e.g. `:ascent center'.
  1569. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1570. If you want to set the display properties yourself, just put a
  1571. list as second element:
  1572. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1573. For example, to display a 16px horizontal space for Emacs
  1574. category, you can use:
  1575. (\"Emacs\" '(space . (:width (16))))"
  1576. :group 'org-agenda-line-format
  1577. :version "24.1"
  1578. :type '(alist :key-type (string :tag "Regexp matching category")
  1579. :value-type (choice (list :tag "Icon"
  1580. (string :tag "File or data")
  1581. (symbol :tag "Type")
  1582. (boolean :tag "Data?")
  1583. (repeat :tag "Extra image properties" :inline t symbol))
  1584. (list :tag "Display properties" sexp))))
  1585. (defgroup org-agenda-column-view nil
  1586. "Options concerning column view in the agenda."
  1587. :tag "Org Agenda Column View"
  1588. :group 'org-agenda)
  1589. (defcustom org-agenda-columns-show-summaries t
  1590. "Non-nil means show summaries for columns displayed in the agenda view."
  1591. :group 'org-agenda-column-view
  1592. :type 'boolean)
  1593. (defcustom org-agenda-columns-compute-summary-properties t
  1594. "Non-nil means recompute all summary properties before column view.
  1595. When column view in the agenda is listing properties that have a summary
  1596. operator, it can go to all relevant buffers and recompute the summaries
  1597. there. This can mean overhead for the agenda column view, but is necessary
  1598. to have thing up to date.
  1599. As a special case, a CLOCKSUM property also makes sure that the clock
  1600. computations are current."
  1601. :group 'org-agenda-column-view
  1602. :type 'boolean)
  1603. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1604. "Non-nil means the duration of an appointment will add to day effort.
  1605. The property to which appointment durations will be added is the one given
  1606. in the option `org-effort-property'. If an appointment does not have
  1607. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1608. is not set, an appointment without end time will not contribute to the time
  1609. estimate."
  1610. :group 'org-agenda-column-view
  1611. :type 'boolean)
  1612. (defcustom org-agenda-auto-exclude-function nil
  1613. "A function called with a tag to decide if it is filtered on '/ RET'.
  1614. The sole argument to the function, which is called once for each
  1615. possible tag, is a string giving the name of the tag. The
  1616. function should return either nil if the tag should be included
  1617. as normal, or \"-<TAG>\" to exclude the tag.
  1618. Note that for the purpose of tag filtering, only the lower-case version of
  1619. all tags will be considered, so that this function will only ever see
  1620. the lower-case version of all tags."
  1621. :group 'org-agenda
  1622. :type 'function)
  1623. (defcustom org-agenda-bulk-custom-functions nil
  1624. "Alist of characters and custom functions for bulk actions.
  1625. For example, this value makes those two functions available:
  1626. '((?R set-category)
  1627. (?C bulk-cut))
  1628. With selected entries in an agenda buffer, `B R' will call
  1629. the custom function `set-category' on the selected entries.
  1630. Note that functions in this alist don't need to be quoted."
  1631. :type 'alist
  1632. :version "24.1"
  1633. :group 'org-agenda)
  1634. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1635. "Execute BODY with point at location given by `org-hd-marker' property.
  1636. If STRING is non-nil, the text property will be fetched from position 0
  1637. in that string. If STRING is nil, it will be fetched from the beginning
  1638. of the current line."
  1639. (org-with-gensyms (marker)
  1640. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1641. 'org-hd-marker ,string)))
  1642. (with-current-buffer (marker-buffer ,marker)
  1643. (save-excursion
  1644. (goto-char ,marker)
  1645. ,@body)))))
  1646. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1647. (defun org-add-agenda-custom-command (entry)
  1648. "Replace or add a command in `org-agenda-custom-commands'.
  1649. This is mostly for hacking and trying a new command - once the command
  1650. works you probably want to add it to `org-agenda-custom-commands' for good."
  1651. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1652. (if ass
  1653. (setcdr ass (cdr entry))
  1654. (push entry org-agenda-custom-commands))))
  1655. ;;; Define the org-agenda-mode
  1656. (defvar org-agenda-mode-map (make-sparse-keymap)
  1657. "Keymap for `org-agenda-mode'.")
  1658. (if (fboundp 'defvaralias)
  1659. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1660. (defvar org-agenda-menu) ; defined later in this file.
  1661. (defvar org-agenda-restrict nil) ; defined later in this file.
  1662. (defvar org-agenda-follow-mode nil)
  1663. (defvar org-agenda-entry-text-mode nil)
  1664. (defvar org-agenda-clockreport-mode nil)
  1665. (defvar org-agenda-show-log nil)
  1666. (defvar org-agenda-redo-command nil)
  1667. (defvar org-agenda-query-string nil)
  1668. (defvar org-agenda-mode-hook nil
  1669. "Hook run after `org-agenda-mode' is turned on.
  1670. The buffer is still writable when this hook is called.")
  1671. (defvar org-agenda-type nil)
  1672. (defvar org-agenda-force-single-file nil)
  1673. (defvar org-agenda-bulk-marked-entries nil
  1674. "List of markers that refer to marked entries in the agenda.")
  1675. ;;; Multiple agenda buffers support
  1676. (defcustom org-agenda-sticky nil
  1677. "Non-nil means agenda q key will bury agenda buffers.
  1678. Agenda commands will then show existing buffer instead of generating new ones.
  1679. When nil, `q' will kill the single agenda buffer."
  1680. :group 'org-agenda
  1681. :version "24.3"
  1682. :type 'boolean)
  1683. ;;;###autoload
  1684. (defun org-toggle-sticky-agenda (&optional arg)
  1685. "Toggle `org-agenda-sticky'."
  1686. (interactive "P")
  1687. (let ((new-value (if arg
  1688. (> (prefix-numeric-value arg) 0)
  1689. (not org-agenda-sticky))))
  1690. (if (equal new-value org-agenda-sticky)
  1691. (and (org-called-interactively-p 'interactive)
  1692. (message "Sticky agenda was already %s"
  1693. (if org-agenda-sticky "enabled" "disabled")))
  1694. (setq org-agenda-sticky new-value)
  1695. (org-agenda-kill-all-agenda-buffers)
  1696. (and (org-called-interactively-p 'interactive)
  1697. (message "Sticky agenda was %s"
  1698. (if org-agenda-sticky "enabled" "disabled"))))))
  1699. (autoload 'org-toggle-sticky-agenda "org-agenda" "\
  1700. Toggle `org-agenda-sticky'.
  1701. \(fn &optional ARG)" t nil)
  1702. (defvar org-agenda-buffer nil
  1703. "Agenda buffer currently being generated.")
  1704. (defvar org-agenda-last-prefix-arg nil)
  1705. (defvar org-agenda-this-buffer-name nil)
  1706. (defvar org-agenda-doing-sticky-redo nil)
  1707. (defvar org-agenda-this-buffer-is-sticky nil)
  1708. (defconst org-agenda-local-vars
  1709. '(org-agenda-this-buffer-name
  1710. org-agenda-undo-list
  1711. org-agenda-pending-undo-list
  1712. org-agenda-follow-mode
  1713. org-agenda-entry-text-mode
  1714. org-agenda-clockreport-mode
  1715. org-agenda-show-log
  1716. org-agenda-redo-command
  1717. org-agenda-query-string
  1718. org-agenda-type
  1719. org-agenda-bulk-marked-entries
  1720. org-agenda-undo-has-started-in
  1721. org-agenda-info
  1722. org-agenda-tag-filter-overlays
  1723. org-agenda-cat-filter-overlays
  1724. org-agenda-pre-window-conf
  1725. org-agenda-columns-active
  1726. org-agenda-tag-filter
  1727. org-agenda-category-filter
  1728. org-agenda-markers
  1729. org-agenda-last-search-view-search-was-boolean
  1730. org-agenda-filtered-by-category
  1731. org-agenda-filter-form
  1732. org-agenda-show-window
  1733. org-agenda-cycle-counter
  1734. org-agenda-last-prefix-arg)
  1735. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1736. (defun org-agenda-mode ()
  1737. "Mode for time-sorted view on action items in Org-mode files.
  1738. The following commands are available:
  1739. \\{org-agenda-mode-map}"
  1740. (interactive)
  1741. (cond (org-agenda-doing-sticky-redo
  1742. ;; Refreshing sticky agenda-buffer
  1743. ;;
  1744. ;; Preserve the value of `org-agenda-local-vars' variables,
  1745. ;; while letting `kill-all-local-variables' kill the rest
  1746. (let ((save (buffer-local-variables)))
  1747. (kill-all-local-variables)
  1748. (mapc 'make-local-variable org-agenda-local-vars)
  1749. (dolist (elem save)
  1750. (let ((var (car elem))
  1751. (val (cdr elem)))
  1752. (when (and val
  1753. (member var org-agenda-local-vars))
  1754. (set var val)))))
  1755. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1756. (org-agenda-sticky
  1757. ;; Creating a sticky Agenda buffer for the first time
  1758. (kill-all-local-variables)
  1759. (mapc 'make-local-variable org-agenda-local-vars)
  1760. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1761. (t
  1762. ;; Creating a non-sticky agenda buffer
  1763. (kill-all-local-variables)
  1764. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1765. (setq org-agenda-undo-list nil
  1766. org-agenda-pending-undo-list nil
  1767. org-agenda-bulk-marked-entries nil)
  1768. (setq major-mode 'org-agenda-mode)
  1769. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1770. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1771. (setq mode-name "Org-Agenda")
  1772. (use-local-map org-agenda-mode-map)
  1773. (easy-menu-add org-agenda-menu)
  1774. (if org-startup-truncated (setq truncate-lines t))
  1775. (org-set-local 'line-move-visual nil)
  1776. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1777. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1778. ;; Make sure properties are removed when copying text
  1779. (make-local-variable 'filter-buffer-substring-functions)
  1780. (add-hook 'filter-buffer-substring-functions
  1781. (lambda (fun start end delete)
  1782. (substring-no-properties (funcall fun start end delete))))
  1783. (unless org-agenda-keep-modes
  1784. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1785. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1786. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1787. org-agenda-show-log org-agenda-start-with-log-mode))
  1788. (easy-menu-change
  1789. '("Agenda") "Agenda Files"
  1790. (append
  1791. (list
  1792. (vector
  1793. (if (get 'org-agenda-files 'org-restrict)
  1794. "Restricted to single file"
  1795. "Edit File List")
  1796. '(org-edit-agenda-file-list)
  1797. (not (get 'org-agenda-files 'org-restrict)))
  1798. "--")
  1799. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1800. (org-agenda-set-mode-name)
  1801. (apply
  1802. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1803. (list 'org-agenda-mode-hook)))
  1804. (substitute-key-definition 'undo 'org-agenda-undo
  1805. org-agenda-mode-map global-map)
  1806. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1807. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1808. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1809. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1810. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1811. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1812. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1813. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1814. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1815. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1816. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1817. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1818. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1819. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1820. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1821. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1822. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1823. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1824. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1825. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1826. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1827. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1828. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1829. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1830. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1831. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1832. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1833. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1834. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1835. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1836. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1837. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1838. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1839. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1840. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1841. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1842. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1843. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1844. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1845. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1846. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1847. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1848. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1849. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1850. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1851. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1852. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1853. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1854. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1855. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1856. (while l (org-defkey org-agenda-mode-map
  1857. (int-to-string (pop l)) 'digit-argument)))
  1858. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1859. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1860. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1861. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1862. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1863. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1864. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1865. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1866. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1867. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1868. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1869. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1870. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1871. 'org-clock-modify-effort-estimate)
  1872. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1873. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1874. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1875. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1876. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1877. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1878. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1879. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1880. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1881. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1882. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1883. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1884. (substitute-key-definition 'next-line 'org-agenda-next-line
  1885. org-agenda-mode-map global-map)
  1886. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1887. org-agenda-mode-map global-map)
  1888. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1889. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1890. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1891. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1892. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1893. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1894. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1895. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1896. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1897. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1898. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1899. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1900. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1901. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1902. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1903. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1904. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1905. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1906. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1907. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1908. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1909. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1910. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1911. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1912. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1913. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1914. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1915. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1916. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1917. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1918. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1919. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1920. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1921. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1922. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1923. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1924. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1925. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1926. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1927. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1928. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1929. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1930. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1931. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1932. (when org-agenda-mouse-1-follows-link
  1933. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1934. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1935. '("Agenda"
  1936. ("Agenda Files")
  1937. "--"
  1938. ("Agenda Dates"
  1939. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1940. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1941. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1942. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1943. "--"
  1944. ("View"
  1945. ["Day View" org-agenda-day-view
  1946. :active (org-agenda-check-type nil 'agenda)
  1947. :style radio :selected (eq org-agenda-current-span 'day)
  1948. :keys "v d (or just d)"]
  1949. ["Week View" org-agenda-week-view
  1950. :active (org-agenda-check-type nil 'agenda)
  1951. :style radio :selected (eq org-agenda-current-span 'week)
  1952. :keys "v w (or just w)"]
  1953. ["Month View" org-agenda-month-view
  1954. :active (org-agenda-check-type nil 'agenda)
  1955. :style radio :selected (eq org-agenda-current-span 'month)
  1956. :keys "v m"]
  1957. ["Year View" org-agenda-year-view
  1958. :active (org-agenda-check-type nil 'agenda)
  1959. :style radio :selected (eq org-agenda-current-span 'year)
  1960. :keys "v y"]
  1961. "--"
  1962. ["Include Diary" org-agenda-toggle-diary
  1963. :style toggle :selected org-agenda-include-diary
  1964. :active (org-agenda-check-type nil 'agenda)]
  1965. ["Include Deadlines" org-agenda-toggle-deadlines
  1966. :style toggle :selected org-agenda-include-deadlines
  1967. :active (org-agenda-check-type nil 'agenda)]
  1968. ["Use Time Grid" org-agenda-toggle-time-grid
  1969. :style toggle :selected org-agenda-use-time-grid
  1970. :active (org-agenda-check-type nil 'agenda)]
  1971. "--"
  1972. ["Show clock report" org-agenda-clockreport-mode
  1973. :style toggle :selected org-agenda-clockreport-mode
  1974. :active (org-agenda-check-type nil 'agenda)]
  1975. ["Show some entry text" org-agenda-entry-text-mode
  1976. :style toggle :selected org-agenda-entry-text-mode
  1977. :active t]
  1978. "--"
  1979. ["Show Logbook entries" org-agenda-log-mode
  1980. :style toggle :selected org-agenda-show-log
  1981. :active (org-agenda-check-type nil 'agenda 'timeline)
  1982. :keys "v l (or just l)"]
  1983. ["Include archived trees" org-agenda-archives-mode
  1984. :style toggle :selected org-agenda-archives-mode :active t
  1985. :keys "v a"]
  1986. ["Include archive files" (org-agenda-archives-mode t)
  1987. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1988. :keys "v A"]
  1989. "--"
  1990. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1991. ["Write view to file" org-agenda-write t]
  1992. ["Rebuild buffer" org-agenda-redo t]
  1993. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1994. "--"
  1995. ["Show original entry" org-agenda-show t]
  1996. ["Go To (other window)" org-agenda-goto t]
  1997. ["Go To (this window)" org-agenda-switch-to t]
  1998. ["Capture with cursor date" org-agenda-capture t]
  1999. ["Follow Mode" org-agenda-follow-mode
  2000. :style toggle :selected org-agenda-follow-mode :active t]
  2001. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2002. "--"
  2003. ("TODO"
  2004. ["Cycle TODO" org-agenda-todo t]
  2005. ["Next TODO set" org-agenda-todo-nextset t]
  2006. ["Previous TODO set" org-agenda-todo-previousset t]
  2007. ["Add note" org-agenda-add-note t])
  2008. ("Archive/Refile/Delete"
  2009. ["Archive default" org-agenda-archive-default t]
  2010. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2011. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2012. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2013. ["Archive subtree" org-agenda-archive t]
  2014. "--"
  2015. ["Refile" org-agenda-refile t]
  2016. "--"
  2017. ["Delete subtree" org-agenda-kill t])
  2018. ("Bulk action"
  2019. ["Mark entry" org-agenda-bulk-mark t]
  2020. ["Mark all" org-agenda-bulk-mark-all t]
  2021. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  2022. ["Unmark entry" org-agenda-bulk-unmark t]
  2023. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2024. ["Act on all marked" org-agenda-bulk-action t]
  2025. "--"
  2026. ("Tags and Properties"
  2027. ["Show all Tags" org-agenda-show-tags t]
  2028. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2029. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2030. "--"
  2031. ["Column View" org-columns t])
  2032. ("Deadline/Schedule"
  2033. ["Schedule" org-agenda-schedule t]
  2034. ["Set Deadline" org-agenda-deadline t]
  2035. "--"
  2036. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2037. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2038. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2039. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2040. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2041. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2042. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2043. ("Clock and Effort"
  2044. ["Clock in" org-agenda-clock-in t]
  2045. ["Clock out" org-agenda-clock-out t]
  2046. ["Clock cancel" org-agenda-clock-cancel t]
  2047. ["Goto running clock" org-clock-goto t]
  2048. "--"
  2049. ["Set Effort" org-agenda-set-effort t]
  2050. ["Change clocked effort" org-clock-modify-effort-estimate
  2051. (org-clock-is-active)])
  2052. ("Priority"
  2053. ["Set Priority" org-agenda-priority t]
  2054. ["Increase Priority" org-agenda-priority-up t]
  2055. ["Decrease Priority" org-agenda-priority-down t]
  2056. ["Show Priority" org-show-priority t])
  2057. ("Calendar/Diary"
  2058. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2059. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2060. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2061. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2062. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2063. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2064. "--"
  2065. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2066. "--"
  2067. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2068. "--"
  2069. ("MobileOrg"
  2070. ["Push Files and Views" org-mobile-push t]
  2071. ["Get Captured and Flagged" org-mobile-pull t]
  2072. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2073. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2074. "--"
  2075. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2076. "--"
  2077. ["Quit" org-agenda-quit t]
  2078. ["Exit and Release Buffers" org-agenda-exit t]
  2079. ))
  2080. ;;; Agenda undo
  2081. (defvar org-agenda-allow-remote-undo t
  2082. "Non-nil means allow remote undo from the agenda buffer.")
  2083. (defvar org-agenda-undo-has-started-in nil
  2084. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2085. (defun org-agenda-undo ()
  2086. "Undo a remote editing step in the agenda.
  2087. This undoes changes both in the agenda buffer and in the remote buffer
  2088. that have been changed along."
  2089. (interactive)
  2090. (or org-agenda-allow-remote-undo
  2091. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2092. (if (not (eq this-command last-command))
  2093. (setq org-agenda-undo-has-started-in nil
  2094. org-agenda-pending-undo-list org-agenda-undo-list))
  2095. (if (not org-agenda-pending-undo-list)
  2096. (error "No further undo information"))
  2097. (let* ((entry (pop org-agenda-pending-undo-list))
  2098. buf line cmd rembuf)
  2099. (setq cmd (pop entry) line (pop entry))
  2100. (setq rembuf (nth 2 entry))
  2101. (org-with-remote-undo rembuf
  2102. (while (bufferp (setq buf (pop entry)))
  2103. (if (pop entry)
  2104. (with-current-buffer buf
  2105. (let ((last-undo-buffer buf)
  2106. (inhibit-read-only t))
  2107. (unless (memq buf org-agenda-undo-has-started-in)
  2108. (push buf org-agenda-undo-has-started-in)
  2109. (make-local-variable 'pending-undo-list)
  2110. (undo-start))
  2111. (while (and pending-undo-list
  2112. (listp pending-undo-list)
  2113. (not (car pending-undo-list)))
  2114. (pop pending-undo-list))
  2115. (undo-more 1))))))
  2116. (org-goto-line line)
  2117. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2118. (defun org-verify-change-for-undo (l1 l2)
  2119. "Verify that a real change occurred between the undo lists L1 and L2."
  2120. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2121. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2122. (not (eq l1 l2)))
  2123. ;;; Agenda dispatch
  2124. (defvar org-agenda-restrict-begin (make-marker))
  2125. (defvar org-agenda-restrict-end (make-marker))
  2126. (defvar org-agenda-last-dispatch-buffer nil)
  2127. (defvar org-agenda-overriding-restriction nil)
  2128. (defcustom org-agenda-custom-commands-contexts nil
  2129. "Alist of custom agenda keys and contextual rules.
  2130. For example, if you have a custom agenda command \"p\" and you
  2131. want this command to be accessible only from plain text files,
  2132. use this:
  2133. '((\"p\" (in-file . \"\\.txt\")))
  2134. Here are the available contexts definitions:
  2135. in-file: command displayed only in matching files
  2136. in-mode: command displayed only in matching modes
  2137. not-in-file: command not displayed in matching files
  2138. not-in-mode: command not displayed in matching modes
  2139. [function]: a custom function taking no argument
  2140. If you define several checks, the agenda command will be
  2141. accessible if there is at least one valid check.
  2142. You can also bind a key to another agenda custom command
  2143. depending on contextual rules.
  2144. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2145. Here it means: in .txt files, use \"p\" as the key for the
  2146. agenda command otherwise associated with \"q\". (The command
  2147. originally associated with \"q\" is not displayed to avoid
  2148. duplicates.)"
  2149. :version "24.3"
  2150. :group 'org-agenda-custom-commands
  2151. :type '(repeat (list :tag "Rule"
  2152. (string :tag " Agenda key")
  2153. (string :tag "Replace by command")
  2154. (repeat :tag "Available when"
  2155. (choice
  2156. (cons :tag "Condition"
  2157. (choice
  2158. (const :tag "In file" in-file)
  2159. (const :tag "Not in file" not-in-file)
  2160. (const :tag "In mode" in-mode)
  2161. (const :tag "Not in mode" not-in-mode))
  2162. (regexp))
  2163. (function :tag "Custom function"))))))
  2164. (defvar org-keys nil)
  2165. (defvar org-match nil)
  2166. ;;;###autoload
  2167. (defun org-agenda (&optional arg org-keys restriction)
  2168. "Dispatch agenda commands to collect entries to the agenda buffer.
  2169. Prompts for a command to execute. Any prefix arg will be passed
  2170. on to the selected command. The default selections are:
  2171. a Call `org-agenda-list' to display the agenda for current day or week.
  2172. t Call `org-todo-list' to display the global todo list.
  2173. T Call `org-todo-list' to display the global todo list, select only
  2174. entries with a specific TODO keyword (the user gets a prompt).
  2175. m Call `org-tags-view' to display headlines with tags matching
  2176. a condition (the user is prompted for the condition).
  2177. M Like `m', but select only TODO entries, no ordinary headlines.
  2178. L Create a timeline for the current buffer.
  2179. e Export views to associated files.
  2180. s Search entries for keywords.
  2181. S Search entries for keywords, only with TODO keywords.
  2182. / Multi occur across all agenda files and also files listed
  2183. in `org-agenda-text-search-extra-files'.
  2184. < Restrict agenda commands to buffer, subtree, or region.
  2185. Press several times to get the desired effect.
  2186. > Remove a previous restriction.
  2187. # List \"stuck\" projects.
  2188. ! Configure what \"stuck\" means.
  2189. C Configure custom agenda commands.
  2190. More commands can be added by configuring the variable
  2191. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2192. searches can be pre-defined in this way.
  2193. If the current buffer is in Org-mode and visiting a file, you can also
  2194. first press `<' once to indicate that the agenda should be temporarily
  2195. \(until the next use of \\[org-agenda]) restricted to the current file.
  2196. Pressing `<' twice means to restrict to the current subtree or region
  2197. \(if active)."
  2198. (interactive "P")
  2199. (catch 'exit
  2200. (let* ((prefix-descriptions nil)
  2201. (org-agenda-buffer-name org-agenda-buffer-name)
  2202. (org-agenda-window-setup (if (equal (buffer-name)
  2203. org-agenda-buffer-name)
  2204. 'current-window
  2205. org-agenda-window-setup))
  2206. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2207. (org-agenda-custom-commands
  2208. ;; normalize different versions
  2209. (delq nil
  2210. (mapcar
  2211. (lambda (x)
  2212. (cond ((stringp (cdr x))
  2213. (push x prefix-descriptions)
  2214. nil)
  2215. ((stringp (nth 1 x)) x)
  2216. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2217. (t (cons (car x) (cons "" (cdr x))))))
  2218. org-agenda-custom-commands)))
  2219. (org-agenda-custom-commands
  2220. (org-contextualize-keys
  2221. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2222. (buf (current-buffer))
  2223. (bfn (buffer-file-name (buffer-base-buffer)))
  2224. entry key type org-match lprops ans)
  2225. ;; Turn off restriction unless there is an overriding one,
  2226. (unless org-agenda-overriding-restriction
  2227. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2228. ;; There is a request to keep the file list in place
  2229. (put 'org-agenda-files 'org-restrict nil))
  2230. (setq org-agenda-restrict nil)
  2231. (move-marker org-agenda-restrict-begin nil)
  2232. (move-marker org-agenda-restrict-end nil))
  2233. ;; Delete old local properties
  2234. (put 'org-agenda-redo-command 'org-lprops nil)
  2235. ;; Delete previously set last-arguments
  2236. (put 'org-agenda-redo-command 'last-args nil)
  2237. ;; Remember where this call originated
  2238. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2239. (unless org-keys
  2240. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2241. org-keys (car ans)
  2242. restriction (cdr ans)))
  2243. ;; If we have sticky agenda buffers, set a name for the buffer,
  2244. ;; depending on the invoking keys. The user may still set this
  2245. ;; as a command option, which will overwrite what we do here.
  2246. (if org-agenda-sticky
  2247. (setq org-agenda-buffer-name
  2248. (format "*Org Agenda(%s)*" org-keys)))
  2249. ;; Establish the restriction, if any
  2250. (when (and (not org-agenda-overriding-restriction) restriction)
  2251. (put 'org-agenda-files 'org-restrict (list bfn))
  2252. (cond
  2253. ((eq restriction 'region)
  2254. (setq org-agenda-restrict t)
  2255. (move-marker org-agenda-restrict-begin (region-beginning))
  2256. (move-marker org-agenda-restrict-end (region-end)))
  2257. ((eq restriction 'subtree)
  2258. (save-excursion
  2259. (setq org-agenda-restrict t)
  2260. (org-back-to-heading t)
  2261. (move-marker org-agenda-restrict-begin (point))
  2262. (move-marker org-agenda-restrict-end
  2263. (progn (org-end-of-subtree t)))))))
  2264. ;; For example the todo list should not need it (but does...)
  2265. (cond
  2266. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2267. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2268. (progn
  2269. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2270. lprops (nth 4 entry))
  2271. (if org-agenda-sticky
  2272. (setq org-agenda-buffer-name
  2273. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2274. (format "*Org Agenda(%s)*" org-keys))))
  2275. (put 'org-agenda-redo-command 'org-lprops lprops)
  2276. (cond
  2277. ((eq type 'agenda)
  2278. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2279. ((eq type 'alltodo)
  2280. (org-let lprops '(org-todo-list current-prefix-arg)))
  2281. ((eq type 'search)
  2282. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2283. ((eq type 'stuck)
  2284. (org-let lprops '(org-agenda-list-stuck-projects
  2285. current-prefix-arg)))
  2286. ((eq type 'tags)
  2287. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2288. ((eq type 'tags-todo)
  2289. (org-let lprops '(org-tags-view '(4) org-match)))
  2290. ((eq type 'todo)
  2291. (org-let lprops '(org-todo-list org-match)))
  2292. ((eq type 'tags-tree)
  2293. (org-check-for-org-mode)
  2294. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2295. ((eq type 'todo-tree)
  2296. (org-check-for-org-mode)
  2297. (org-let lprops
  2298. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2299. (regexp-quote org-match) "\\>"))))
  2300. ((eq type 'occur-tree)
  2301. (org-check-for-org-mode)
  2302. (org-let lprops '(org-occur org-match)))
  2303. ((functionp type)
  2304. (org-let lprops '(funcall type org-match)))
  2305. ((fboundp type)
  2306. (org-let lprops '(funcall type org-match)))
  2307. (t (error "Invalid custom agenda command type %s" type))))
  2308. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2309. ((equal org-keys "C")
  2310. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2311. (customize-variable 'org-agenda-custom-commands))
  2312. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2313. ((equal org-keys "s") (call-interactively 'org-search-view))
  2314. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2315. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2316. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2317. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2318. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2319. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2320. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2321. (org-add-hook
  2322. 'post-command-hook
  2323. (lambda ()
  2324. (unless (current-message)
  2325. (let* ((m (org-agenda-get-any-marker))
  2326. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2327. (when note
  2328. (message (concat
  2329. "FLAGGING-NOTE ([?] for more info): "
  2330. (org-add-props
  2331. (replace-regexp-in-string
  2332. "\\\\n" "//"
  2333. (copy-sequence note))
  2334. nil 'face 'org-warning)))))))
  2335. t t))
  2336. ((equal org-keys "L")
  2337. (unless (derived-mode-p 'org-mode)
  2338. (error "This is not an Org-mode file"))
  2339. (unless restriction
  2340. (put 'org-agenda-files 'org-restrict (list bfn))
  2341. (org-call-with-arg 'org-timeline arg)))
  2342. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2343. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2344. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2345. (t (error "Invalid agenda key"))))))
  2346. (autoload 'org-agenda "org-agenda" "\
  2347. Dispatch agenda commands to collect entries to the agenda buffer.
  2348. Prompts for a command to execute. Any prefix arg will be passed
  2349. on to the selected command. The default selections are:
  2350. a Call `org-agenda-list' to display the agenda for current day or week.
  2351. t Call `org-todo-list' to display the global todo list.
  2352. T Call `org-todo-list' to display the global todo list, select only
  2353. entries with a specific TODO keyword (the user gets a prompt).
  2354. m Call `org-tags-view' to display headlines with tags matching
  2355. a condition (the user is prompted for the condition).
  2356. M Like `m', but select only TODO entries, no ordinary headlines.
  2357. L Create a timeline for the current buffer.
  2358. e Export views to associated files.
  2359. s Search entries for keywords.
  2360. S Search entries for keywords, only with TODO keywords.
  2361. / Multi occur across all agenda files and also files listed
  2362. in `org-agenda-text-search-extra-files'.
  2363. < Restrict agenda commands to buffer, subtree, or region.
  2364. Press several times to get the desired effect.
  2365. > Remove a previous restriction.
  2366. # List \"stuck\" projects.
  2367. ! Configure what \"stuck\" means.
  2368. C Configure custom agenda commands.
  2369. More commands can be added by configuring the variable
  2370. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2371. searches can be pre-defined in this way.
  2372. If the current buffer is in Org-mode and visiting a file, you can also
  2373. first press `<' once to indicate that the agenda should be temporarily
  2374. \(until the next use of \\[org-agenda]) restricted to the current file.
  2375. Pressing `<' twice means to restrict to the current subtree or region
  2376. \(if active).
  2377. \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
  2378. (defun org-agenda-append-agenda ()
  2379. "Append another agenda view to the current one.
  2380. This function allows interactive building of block agendas.
  2381. Agenda views are separated by `org-agenda-block-separator'."
  2382. (interactive)
  2383. (unless (derived-mode-p 'org-agenda-mode)
  2384. (error "Can only append from within agenda buffer"))
  2385. (let ((org-agenda-multi t))
  2386. (org-agenda)
  2387. (widen)
  2388. (org-agenda-finalize)
  2389. (org-agenda-fit-window-to-buffer)))
  2390. (defun org-agenda-normalize-custom-commands (cmds)
  2391. (delq nil
  2392. (mapcar
  2393. (lambda (x)
  2394. (cond ((stringp (cdr x)) nil)
  2395. ((stringp (nth 1 x)) x)
  2396. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2397. (t (cons (car x) (cons "" (cdr x))))))
  2398. cmds)))
  2399. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2400. "The user interface for selecting an agenda command."
  2401. (catch 'exit
  2402. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2403. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2404. (region-p (org-region-active-p))
  2405. (custom org-agenda-custom-commands)
  2406. (selstring "")
  2407. restriction second-time
  2408. c entry key type match prefixes rmheader header-end custom1 desc
  2409. line lines left right n n1)
  2410. (save-window-excursion
  2411. (delete-other-windows)
  2412. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2413. (erase-buffer)
  2414. (insert (eval-when-compile
  2415. (let ((header
  2416. "Press key for an agenda command: < Buffer, subtree/region restriction
  2417. -------------------------------- > Remove restriction
  2418. a Agenda for current week or day e Export agenda views
  2419. t List of all TODO entries T Entries with special TODO kwd
  2420. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2421. s Search for keywords S Like s, but only TODO entries
  2422. L Timeline for current buffer # List stuck projects (!=configure)
  2423. / Multi-occur C Configure custom agenda commands
  2424. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2425. ")
  2426. (start 0))
  2427. (while (string-match
  2428. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2429. header start)
  2430. (setq start (match-end 0))
  2431. (add-text-properties (match-beginning 2) (match-end 2)
  2432. '(face bold) header))
  2433. header)))
  2434. (setq header-end (point-marker))
  2435. (while t
  2436. (setq custom1 custom)
  2437. (when (eq rmheader t)
  2438. (org-goto-line 1)
  2439. (re-search-forward ":" nil t)
  2440. (delete-region (match-end 0) (point-at-eol))
  2441. (forward-char 1)
  2442. (looking-at "-+")
  2443. (delete-region (match-end 0) (point-at-eol))
  2444. (move-marker header-end (match-end 0)))
  2445. (goto-char header-end)
  2446. (delete-region (point) (point-max))
  2447. ;; Produce all the lines that describe custom commands and prefixes
  2448. (setq lines nil)
  2449. (while (setq entry (pop custom1))
  2450. (setq key (car entry) desc (nth 1 entry)
  2451. type (nth 2 entry)
  2452. match (nth 3 entry))
  2453. (if (> (length key) 1)
  2454. (add-to-list 'prefixes (string-to-char key))
  2455. (setq line
  2456. (format
  2457. "%-4s%-14s"
  2458. (org-add-props (copy-sequence key)
  2459. '(face bold))
  2460. (cond
  2461. ((string-match "\\S-" desc) desc)
  2462. ((eq type 'agenda) "Agenda for current week or day")
  2463. ((eq type 'alltodo) "List of all TODO entries")
  2464. ((eq type 'search) "Word search")
  2465. ((eq type 'stuck) "List of stuck projects")
  2466. ((eq type 'todo) "TODO keyword")
  2467. ((eq type 'tags) "Tags query")
  2468. ((eq type 'tags-todo) "Tags (TODO)")
  2469. ((eq type 'tags-tree) "Tags tree")
  2470. ((eq type 'todo-tree) "TODO kwd tree")
  2471. ((eq type 'occur-tree) "Occur tree")
  2472. ((functionp type) (if (symbolp type)
  2473. (symbol-name type)
  2474. "Lambda expression"))
  2475. (t "???"))))
  2476. (if org-agenda-menu-show-matcher
  2477. (setq line
  2478. (concat line ": "
  2479. (cond
  2480. ((stringp match)
  2481. (setq match (copy-sequence match))
  2482. (org-add-props match nil 'face 'org-warning))
  2483. ((listp type)
  2484. (format "set of %d commands" (length type))))))
  2485. (if (org-string-nw-p match)
  2486. (add-text-properties
  2487. 0 (length line) (list 'help-echo
  2488. (concat "Matcher: " match)) line)))
  2489. (push line lines)))
  2490. (setq lines (nreverse lines))
  2491. (when prefixes
  2492. (mapc (lambda (x)
  2493. (push
  2494. (format "%s %s"
  2495. (org-add-props (char-to-string x)
  2496. nil 'face 'bold)
  2497. (or (cdr (assoc (concat selstring
  2498. (char-to-string x))
  2499. prefix-descriptions))
  2500. "Prefix key"))
  2501. lines))
  2502. prefixes))
  2503. ;; Check if we should display in two columns
  2504. (if org-agenda-menu-two-columns
  2505. (progn
  2506. (setq n (length lines)
  2507. n1 (+ (/ n 2) (mod n 2))
  2508. right (nthcdr n1 lines)
  2509. left (copy-sequence lines))
  2510. (setcdr (nthcdr (1- n1) left) nil))
  2511. (setq left lines right nil))
  2512. (while left
  2513. (insert "\n" (pop left))
  2514. (when right
  2515. (if (< (current-column) 40)
  2516. (move-to-column 40 t)
  2517. (insert " "))
  2518. (insert (pop right))))
  2519. ;; Make the window the right size
  2520. (goto-char (point-min))
  2521. (if second-time
  2522. (if (not (pos-visible-in-window-p (point-max)))
  2523. (org-fit-window-to-buffer))
  2524. (setq second-time t)
  2525. (org-fit-window-to-buffer))
  2526. ;; Ask for selection
  2527. (message "Press key for agenda command%s:"
  2528. (if (or restrict-ok org-agenda-overriding-restriction)
  2529. (if org-agenda-overriding-restriction
  2530. " (restriction lock active)"
  2531. (if restriction
  2532. (format " (restricted to %s)" restriction)
  2533. " (unrestricted)"))
  2534. ""))
  2535. (setq c (read-char-exclusive))
  2536. (message "")
  2537. (cond
  2538. ((assoc (char-to-string c) custom)
  2539. (setq selstring (concat selstring (char-to-string c)))
  2540. (throw 'exit (cons selstring restriction)))
  2541. ((memq c prefixes)
  2542. (setq selstring (concat selstring (char-to-string c))
  2543. prefixes nil
  2544. rmheader (or rmheader t)
  2545. custom (delq nil (mapcar
  2546. (lambda (x)
  2547. (if (or (= (length (car x)) 1)
  2548. (/= (string-to-char (car x)) c))
  2549. nil
  2550. (cons (substring (car x) 1) (cdr x))))
  2551. custom))))
  2552. ((eq c ?*)
  2553. (call-interactively 'org-toggle-sticky-agenda)
  2554. (sit-for 2))
  2555. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2556. (message "Restriction is only possible in Org-mode buffers")
  2557. (ding) (sit-for 1))
  2558. ((eq c ?1)
  2559. (org-agenda-remove-restriction-lock 'noupdate)
  2560. (setq restriction 'buffer))
  2561. ((eq c ?0)
  2562. (org-agenda-remove-restriction-lock 'noupdate)
  2563. (setq restriction (if region-p 'region 'subtree)))
  2564. ((eq c ?<)
  2565. (org-agenda-remove-restriction-lock 'noupdate)
  2566. (setq restriction
  2567. (cond
  2568. ((eq restriction 'buffer)
  2569. (if region-p 'region 'subtree))
  2570. ((memq restriction '(subtree region))
  2571. nil)
  2572. (t 'buffer))))
  2573. ((eq c ?>)
  2574. (org-agenda-remove-restriction-lock 'noupdate)
  2575. (setq restriction nil))
  2576. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2577. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2578. ((and (> (length selstring) 0) (eq c ?\d))
  2579. (delete-window)
  2580. (org-agenda-get-restriction-and-command prefix-descriptions))
  2581. ((equal c ?q) (error "Abort"))
  2582. (t (error "Invalid key %c" c))))))))
  2583. (defun org-agenda-fit-window-to-buffer ()
  2584. "Fit the window to the buffer size."
  2585. (and (memq org-agenda-window-setup '(reorganize-frame))
  2586. (fboundp 'fit-window-to-buffer)
  2587. (org-fit-window-to-buffer
  2588. nil
  2589. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2590. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2591. (defvar org-cmd nil)
  2592. (defvar org-agenda-overriding-cmd nil)
  2593. (defvar org-agenda-overriding-arguments nil)
  2594. (defvar org-agenda-overriding-cmd-arguments nil)
  2595. (defun org-agenda-run-series (name series)
  2596. (org-let (nth 1 series) '(org-agenda-prepare name))
  2597. ;; We need to reset agenda markers here, because when constructing a
  2598. ;; block agenda, the individual blocks do not do that.
  2599. (org-agenda-reset-markers)
  2600. (let* ((org-agenda-multi t)
  2601. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2602. (cmds (car series))
  2603. (gprops (nth 1 series))
  2604. match ;; The byte compiler incorrectly complains about this. Keep it!
  2605. org-cmd type lprops)
  2606. (while (setq org-cmd (pop cmds))
  2607. (setq type (car org-cmd)
  2608. match (eval (nth 1 org-cmd))
  2609. lprops (nth 2 org-cmd))
  2610. (let ((org-agenda-overriding-arguments
  2611. (if (eq org-agenda-overriding-cmd org-cmd)
  2612. (or org-agenda-overriding-arguments
  2613. org-agenda-overriding-cmd-arguments))))
  2614. (cond
  2615. ((eq type 'agenda)
  2616. (org-let2 gprops lprops
  2617. '(call-interactively 'org-agenda-list)))
  2618. ((eq type 'alltodo)
  2619. (org-let2 gprops lprops
  2620. '(call-interactively 'org-todo-list)))
  2621. ((eq type 'search)
  2622. (org-let2 gprops lprops
  2623. '(org-search-view current-prefix-arg match nil)))
  2624. ((eq type 'stuck)
  2625. (org-let2 gprops lprops
  2626. '(call-interactively 'org-agenda-list-stuck-projects)))
  2627. ((eq type 'tags)
  2628. (org-let2 gprops lprops
  2629. '(org-tags-view current-prefix-arg match)))
  2630. ((eq type 'tags-todo)
  2631. (org-let2 gprops lprops
  2632. '(org-tags-view '(4) match)))
  2633. ((eq type 'todo)
  2634. (org-let2 gprops lprops
  2635. '(org-todo-list match)))
  2636. ((fboundp type)
  2637. (org-let2 gprops lprops
  2638. '(funcall type match)))
  2639. (t (error "Invalid type in command series")))))
  2640. (widen)
  2641. (let ((inhibit-read-only t))
  2642. (add-text-properties (point-min) (point-max)
  2643. `(org-series t org-series-redo-cmd ,redo)))
  2644. (setq org-agenda-redo-command redo)
  2645. (goto-char (point-min)))
  2646. (org-agenda-fit-window-to-buffer)
  2647. (org-let (nth 1 series) '(org-agenda-finalize)))
  2648. ;;;###autoload
  2649. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2650. "Run an agenda command in batch mode and send the result to STDOUT.
  2651. If CMD-KEY is a string of length 1, it is used as a key in
  2652. `org-agenda-custom-commands' and triggers this command. If it is a
  2653. longer string it is used as a tags/todo match string.
  2654. Parameters are alternating variable names and values that will be bound
  2655. before running the agenda command."
  2656. (org-eval-in-environment (org-make-parameter-alist parameters)
  2657. (if (> (length cmd-key) 2)
  2658. (org-tags-view nil cmd-key)
  2659. (org-agenda nil cmd-key)))
  2660. (set-buffer org-agenda-buffer-name)
  2661. (princ (buffer-string)))
  2662. (autoload 'org-batch-agenda "org-agenda" "\
  2663. Run an agenda command in batch mode and send the result to STDOUT.
  2664. If CMD-KEY is a string of length 1, it is used as a key in
  2665. `org-agenda-custom-commands' and triggers this command. If it is a
  2666. longer string it is used as a tags/todo match string.
  2667. Parameters are alternating variable names and values that will be bound
  2668. before running the agenda command.
  2669. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2670. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2671. (defvar org-agenda-info nil)
  2672. ;;;###autoload
  2673. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2674. "Run an agenda command in batch mode and send the result to STDOUT.
  2675. If CMD-KEY is a string of length 1, it is used as a key in
  2676. `org-agenda-custom-commands' and triggers this command. If it is a
  2677. longer string it is used as a tags/todo match string.
  2678. Parameters are alternating variable names and values that will be bound
  2679. before running the agenda command.
  2680. The output gives a line for each selected agenda item. Each
  2681. item is a list of comma-separated values, like this:
  2682. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2683. category The category of the item
  2684. head The headline, without TODO kwd, TAGS and PRIORITY
  2685. type The type of the agenda entry, can be
  2686. todo selected in TODO match
  2687. tagsmatch selected in tags match
  2688. diary imported from diary
  2689. deadline a deadline on given date
  2690. scheduled scheduled on given date
  2691. timestamp entry has timestamp on given date
  2692. closed entry was closed on given date
  2693. upcoming-deadline warning about deadline
  2694. past-scheduled forwarded scheduled item
  2695. block entry has date block including g. date
  2696. todo The todo keyword, if any
  2697. tags All tags including inherited ones, separated by colons
  2698. date The relevant date, like 2007-2-14
  2699. time The time, like 15:00-16:50
  2700. extra Sting with extra planning info
  2701. priority-l The priority letter if any was given
  2702. priority-n The computed numerical priority
  2703. agenda-day The day in the agenda where this is listed"
  2704. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2705. (org-make-parameter-alist parameters))
  2706. (if (> (length cmd-key) 2)
  2707. (org-tags-view nil cmd-key)
  2708. (org-agenda nil cmd-key)))
  2709. (set-buffer org-agenda-buffer-name)
  2710. (let* ((lines (org-split-string (buffer-string) "\n"))
  2711. line)
  2712. (while (setq line (pop lines))
  2713. (catch 'next
  2714. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2715. (setq org-agenda-info
  2716. (org-fix-agenda-info (text-properties-at 0 line)))
  2717. (princ
  2718. (mapconcat 'org-agenda-export-csv-mapper
  2719. '(org-category txt type todo tags date time extra
  2720. priority-letter priority agenda-day)
  2721. ","))
  2722. (princ "\n")))))
  2723. (autoload 'org-batch-agenda-csv "org-agenda" "\
  2724. Run an agenda command in batch mode and send the result to STDOUT.
  2725. If CMD-KEY is a string of length 1, it is used as a key in
  2726. `org-agenda-custom-commands' and triggers this command. If it is a
  2727. longer string it is used as a tags/todo match string.
  2728. Parameters are alternating variable names and values that will be bound
  2729. before running the agenda command.
  2730. The output gives a line for each selected agenda item. Each
  2731. item is a list of comma-separated values, like this:
  2732. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2733. category The category of the item
  2734. head The headline, without TODO kwd, TAGS and PRIORITY
  2735. type The type of the agenda entry, can be
  2736. todo selected in TODO match
  2737. tagsmatch selected in tags match
  2738. diary imported from diary
  2739. deadline a deadline on given date
  2740. scheduled scheduled on given date
  2741. timestamp entry has timestamp on given date
  2742. closed entry was closed on given date
  2743. upcoming-deadline warning about deadline
  2744. past-scheduled forwarded scheduled item
  2745. block entry has date block including g. date
  2746. todo The todo keyword, if any
  2747. tags All tags including inherited ones, separated by colons
  2748. date The relevant date, like 2007-2-14
  2749. time The time, like 15:00-16:50
  2750. extra Sting with extra planning info
  2751. priority-l The priority letter if any was given
  2752. priority-n The computed numerical priority
  2753. agenda-day The day in the agenda where this is listed
  2754. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2755. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2756. (defun org-fix-agenda-info (props)
  2757. "Make sure all properties on an agenda item have a canonical form.
  2758. This ensures the export commands can easily use it."
  2759. (let (tmp re)
  2760. (when (setq tmp (plist-get props 'tags))
  2761. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2762. (when (setq tmp (plist-get props 'date))
  2763. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2764. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2765. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2766. (setq tmp (calendar-date-string tmp)))
  2767. (setq props (plist-put props 'date tmp)))
  2768. (when (setq tmp (plist-get props 'day))
  2769. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2770. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2771. (setq tmp (calendar-date-string tmp)))
  2772. (setq props (plist-put props 'day tmp))
  2773. (setq props (plist-put props 'agenda-day tmp)))
  2774. (when (setq tmp (plist-get props 'txt))
  2775. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2776. (plist-put props 'priority-letter (match-string 1 tmp))
  2777. (setq tmp (replace-match "" t t tmp)))
  2778. (when (and (setq re (plist-get props 'org-todo-regexp))
  2779. (setq re (concat "\\`\\.*" re " ?"))
  2780. (string-match re tmp))
  2781. (plist-put props 'todo (match-string 1 tmp))
  2782. (setq tmp (replace-match "" t t tmp)))
  2783. (plist-put props 'txt tmp)))
  2784. props)
  2785. (defun org-agenda-export-csv-mapper (prop)
  2786. (let ((res (plist-get org-agenda-info prop)))
  2787. (setq res
  2788. (cond
  2789. ((not res) "")
  2790. ((stringp res) res)
  2791. (t (prin1-to-string res))))
  2792. (while (string-match "," res)
  2793. (setq res (replace-match ";" t t res)))
  2794. (org-trim res)))
  2795. ;;;###autoload
  2796. (defun org-store-agenda-views (&rest parameters)
  2797. (interactive)
  2798. (eval (list 'org-batch-store-agenda-views)))
  2799. (autoload 'org-store-agenda-views "org-agenda" "\
  2800. \(fn &rest PARAMETERS)" t nil)
  2801. ;;;###autoload
  2802. (defmacro org-batch-store-agenda-views (&rest parameters)
  2803. "Run all custom agenda commands that have a file argument."
  2804. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2805. (pop-up-frames nil)
  2806. (dir default-directory)
  2807. (pars (org-make-parameter-alist parameters))
  2808. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2809. (save-window-excursion
  2810. (while cmds
  2811. (setq cmd (pop cmds)
  2812. thiscmdkey (car cmd)
  2813. thiscmdcmd (cdr cmd)
  2814. match (nth 2 thiscmdcmd)
  2815. bufname (if org-agenda-sticky
  2816. (or (and (stringp match)
  2817. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2818. (format "*Org Agenda(%s)*" thiscmdkey))
  2819. org-agenda-buffer-name)
  2820. cmd-or-set (nth 2 cmd)
  2821. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2822. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2823. (if (stringp files) (setq files (list files)))
  2824. (when files
  2825. (org-eval-in-environment (append org-agenda-exporter-settings
  2826. opts pars)
  2827. (org-agenda nil thiscmdkey))
  2828. (set-buffer bufname)
  2829. (while files
  2830. (org-eval-in-environment (append org-agenda-exporter-settings
  2831. opts pars)
  2832. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2833. (and (get-buffer bufname)
  2834. (kill-buffer bufname)))))))
  2835. (autoload 'org-batch-store-agenda-views "org-agenda" "\
  2836. Run all custom agenda commands that have a file argument.
  2837. \(fn &rest PARAMETERS)" nil t)
  2838. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2839. (defvar org-agenda-current-span nil
  2840. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2841. (defun org-agenda-mark-header-line (pos)
  2842. "Mark the line at POS as an agenda structure header."
  2843. (save-excursion
  2844. (goto-char pos)
  2845. (put-text-property (point-at-bol) (point-at-eol)
  2846. 'org-agenda-structural-header t)
  2847. (when org-agenda-title-append
  2848. (put-text-property (point-at-bol) (point-at-eol)
  2849. 'org-agenda-title-append org-agenda-title-append))))
  2850. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2851. (defvar org-agenda-write-buffer-name "Agenda View")
  2852. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2853. "Write the current buffer (an agenda view) as a file.
  2854. Depending on the extension of the file name, plain text (.txt),
  2855. HTML (.html or .htm) or Postscript (.ps) is produced.
  2856. If the extension is .ics, run icalendar export over all files used
  2857. to construct the agenda and limit the export to entries listed in the
  2858. agenda now.
  2859. With prefix argument OPEN, open the new file immediately.
  2860. If NOSETTINGS is given, do not scope the settings of
  2861. `org-agenda-exporter-settings' into the export commands. This is used when
  2862. the settings have already been scoped and we do not wish to overrule other,
  2863. higher priority settings.
  2864. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2865. (interactive "FWrite agenda to file: \nP")
  2866. (if (not (file-writable-p file))
  2867. (error "Cannot write agenda to file %s" file))
  2868. (org-let (if nosettings nil org-agenda-exporter-settings)
  2869. '(save-excursion
  2870. (save-window-excursion
  2871. (org-agenda-mark-filtered-text)
  2872. (let ((bs (copy-sequence (buffer-string))) beg)
  2873. (org-agenda-unmark-filtered-text)
  2874. (with-temp-buffer
  2875. (rename-buffer org-agenda-write-buffer-name t)
  2876. (set-buffer-modified-p nil)
  2877. (insert bs)
  2878. (org-agenda-remove-marked-text 'org-filtered)
  2879. (while (setq beg (text-property-any (point-min) (point-max)
  2880. 'org-filtered t))
  2881. (delete-region
  2882. beg (or (next-single-property-change beg 'org-filtered)
  2883. (point-max))))
  2884. (run-hooks 'org-agenda-before-write-hook)
  2885. (cond
  2886. ((org-bound-and-true-p org-mobile-creating-agendas)
  2887. (org-mobile-write-agenda-for-mobile file))
  2888. ((string-match "\\.html?\\'" file)
  2889. (require 'htmlize)
  2890. (set-buffer (htmlize-buffer (current-buffer)))
  2891. (when org-agenda-export-html-style
  2892. ;; replace <style> section with org-agenda-export-html-style
  2893. (goto-char (point-min))
  2894. (kill-region (- (search-forward "<style") 6)
  2895. (search-forward "</style>"))
  2896. (insert org-agenda-export-html-style))
  2897. (write-file file)
  2898. (kill-buffer (current-buffer))
  2899. (message "HTML written to %s" file))
  2900. ((string-match "\\.ps\\'" file)
  2901. (require 'ps-print)
  2902. (ps-print-buffer-with-faces file)
  2903. (message "Postscript written to %s" file))
  2904. ((string-match "\\.pdf\\'" file)
  2905. (require 'ps-print)
  2906. (ps-print-buffer-with-faces
  2907. (concat (file-name-sans-extension file) ".ps"))
  2908. (call-process "ps2pdf" nil nil nil
  2909. (expand-file-name
  2910. (concat (file-name-sans-extension file) ".ps"))
  2911. (expand-file-name file))
  2912. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2913. (message "PDF written to %s" file))
  2914. ((string-match "\\.ics\\'" file)
  2915. (require 'org-icalendar)
  2916. (let ((org-agenda-marker-table
  2917. (org-create-marker-find-array
  2918. (org-agenda-collect-markers)))
  2919. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2920. (org-combined-agenda-icalendar-file file))
  2921. (apply 'org-export-icalendar 'combine
  2922. (org-agenda-files nil 'ifmode))))
  2923. (t
  2924. (let ((bs (buffer-string)))
  2925. (find-file file)
  2926. (erase-buffer)
  2927. (insert bs)
  2928. (save-buffer 0)
  2929. (kill-buffer (current-buffer))
  2930. (message "Plain text written to %s" file))))))))
  2931. (set-buffer (or agenda-bufname
  2932. (and (org-called-interactively-p 'any) (buffer-name))
  2933. org-agenda-buffer-name)))
  2934. (when open (org-open-file file)))
  2935. (defvar org-agenda-tag-filter-overlays nil)
  2936. (defvar org-agenda-cat-filter-overlays nil)
  2937. (defun org-agenda-mark-filtered-text ()
  2938. "Mark all text hidden by filtering with a text property."
  2939. (let ((inhibit-read-only t))
  2940. (mapc
  2941. (lambda (o)
  2942. (when (equal (overlay-buffer o) (current-buffer))
  2943. (put-text-property
  2944. (overlay-start o) (overlay-end o)
  2945. 'org-filtered t)))
  2946. (append org-agenda-tag-filter-overlays
  2947. org-agenda-cat-filter-overlays))))
  2948. (defun org-agenda-unmark-filtered-text ()
  2949. "Remove the filtering text property."
  2950. (let ((inhibit-read-only t))
  2951. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2952. (defun org-agenda-remove-marked-text (property &optional value)
  2953. "Delete all text marked with VALUE of PROPERTY.
  2954. VALUE defaults to t."
  2955. (let (beg)
  2956. (setq value (or value t))
  2957. (while (setq beg (text-property-any (point-min) (point-max)
  2958. property value))
  2959. (delete-region
  2960. beg (or (next-single-property-change beg 'org-filtered)
  2961. (point-max))))))
  2962. (defun org-agenda-add-entry-text ()
  2963. "Add entry text to agenda lines.
  2964. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2965. entry text following headings shown in the agenda.
  2966. Drawers will be excluded, also the line with scheduling/deadline info."
  2967. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2968. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2969. (let (m txt)
  2970. (goto-char (point-min))
  2971. (while (not (eobp))
  2972. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2973. (beginning-of-line 2)
  2974. (setq txt (org-agenda-get-some-entry-text
  2975. m org-agenda-add-entry-text-maxlines " > "))
  2976. (end-of-line 1)
  2977. (if (string-match "\\S-" txt)
  2978. (insert "\n" txt)
  2979. (or (eobp) (forward-char 1))))))))
  2980. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2981. &rest keep)
  2982. "Extract entry text from MARKER, at most N-LINES lines.
  2983. This will ignore drawers etc, just get the text.
  2984. If INDENT is given, prefix every line with this string. If KEEP is
  2985. given, it is a list of symbols, defining stuff that should not be
  2986. removed from the entry content. Currently only `planning' is allowed here."
  2987. (let (txt drawer-re kwd-time-re ind)
  2988. (save-excursion
  2989. (with-current-buffer (marker-buffer marker)
  2990. (if (not (derived-mode-p 'org-mode))
  2991. (setq txt "")
  2992. (save-excursion
  2993. (save-restriction
  2994. (widen)
  2995. (goto-char marker)
  2996. (end-of-line 1)
  2997. (setq txt (buffer-substring
  2998. (min (1+ (point)) (point-max))
  2999. (progn (outline-next-heading) (point)))
  3000. drawer-re org-drawer-regexp
  3001. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3002. ".*\n?"))
  3003. (with-temp-buffer
  3004. (insert txt)
  3005. (when org-agenda-add-entry-text-descriptive-links
  3006. (goto-char (point-min))
  3007. (while (org-activate-bracket-links (point-max))
  3008. (add-text-properties (match-beginning 0) (match-end 0)
  3009. '(face org-link))))
  3010. (goto-char (point-min))
  3011. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3012. (set-text-properties (match-beginning 0) (match-end 0)
  3013. nil))
  3014. (goto-char (point-min))
  3015. (while (re-search-forward drawer-re nil t)
  3016. (delete-region
  3017. (match-beginning 0)
  3018. (progn (re-search-forward
  3019. "^[ \t]*:END:.*\n?" nil 'move)
  3020. (point))))
  3021. (unless (member 'planning keep)
  3022. (goto-char (point-min))
  3023. (while (re-search-forward kwd-time-re nil t)
  3024. (replace-match "")))
  3025. (goto-char (point-min))
  3026. (when org-agenda-entry-text-exclude-regexps
  3027. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3028. (while (setq re (pop re-list))
  3029. (goto-char (point-min))
  3030. (while (re-search-forward re nil t)
  3031. (replace-match "")))))
  3032. (goto-char (point-max))
  3033. (skip-chars-backward " \t\n")
  3034. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3035. ;; find and remove min common indentation
  3036. (goto-char (point-min))
  3037. (untabify (point-min) (point-max))
  3038. (setq ind (org-get-indentation))
  3039. (while (not (eobp))
  3040. (unless (looking-at "[ \t]*$")
  3041. (setq ind (min ind (org-get-indentation))))
  3042. (beginning-of-line 2))
  3043. (goto-char (point-min))
  3044. (while (not (eobp))
  3045. (unless (looking-at "[ \t]*$")
  3046. (move-to-column ind)
  3047. (delete-region (point-at-bol) (point)))
  3048. (beginning-of-line 2))
  3049. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3050. (goto-char (point-min))
  3051. (when indent
  3052. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3053. (replace-match indent t t)))
  3054. (goto-char (point-min))
  3055. (while (looking-at "[ \t]*\n") (replace-match ""))
  3056. (goto-char (point-max))
  3057. (when (> (org-current-line)
  3058. n-lines)
  3059. (org-goto-line (1+ n-lines))
  3060. (backward-char 1))
  3061. (setq txt (buffer-substring (point-min) (point)))))))))
  3062. txt))
  3063. (defun org-agenda-collect-markers ()
  3064. "Collect the markers pointing to entries in the agenda buffer."
  3065. (let (m markers)
  3066. (save-excursion
  3067. (goto-char (point-min))
  3068. (while (not (eobp))
  3069. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  3070. (org-get-at-bol 'org-marker)))
  3071. (push m markers))
  3072. (beginning-of-line 2)))
  3073. (nreverse markers)))
  3074. (defun org-create-marker-find-array (marker-list)
  3075. "Create a alist of files names with all marker positions in that file."
  3076. (let (f tbl m a p)
  3077. (while (setq m (pop marker-list))
  3078. (setq p (marker-position m)
  3079. f (buffer-file-name (or (buffer-base-buffer
  3080. (marker-buffer m))
  3081. (marker-buffer m))))
  3082. (if (setq a (assoc f tbl))
  3083. (push (marker-position m) (cdr a))
  3084. (push (list f p) tbl)))
  3085. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  3086. tbl)))
  3087. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  3088. (defun org-check-agenda-marker-table ()
  3089. "Check of the current entry is on the marker list."
  3090. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  3091. a)
  3092. (and (setq a (assoc file org-agenda-marker-table))
  3093. (save-match-data
  3094. (save-excursion
  3095. (org-back-to-heading t)
  3096. (member (point) (cdr a)))))))
  3097. (defun org-check-for-org-mode ()
  3098. "Make sure current buffer is in org-mode. Error if not."
  3099. (or (derived-mode-p 'org-mode)
  3100. (error "Cannot execute org-mode agenda command on buffer in %s"
  3101. major-mode)))
  3102. ;;; Agenda prepare and finalize
  3103. (defvar org-agenda-multi nil) ; dynamically scoped
  3104. (defvar org-agenda-pre-window-conf nil)
  3105. (defvar org-agenda-columns-active nil)
  3106. (defvar org-agenda-name nil)
  3107. (defvar org-agenda-tag-filter nil)
  3108. (defvar org-agenda-category-filter nil)
  3109. (defvar org-agenda-top-category-filter nil)
  3110. (defvar org-agenda-tag-filter-while-redo nil)
  3111. (defvar org-agenda-tag-filter-preset nil
  3112. "A preset of the tags filter used for secondary agenda filtering.
  3113. This must be a list of strings, each string must be a single tag preceded
  3114. by \"+\" or \"-\".
  3115. This variable should not be set directly, but agenda custom commands can
  3116. bind it in the options section. The preset filter is a global property of
  3117. the entire agenda view. In a block agenda, it will not work reliably to
  3118. define a filter for one of the individual blocks. You need to set it in
  3119. the global options and expect it to be applied to the entire view.")
  3120. (defvar org-agenda-category-filter-preset nil
  3121. "A preset of the category filter used for secondary agenda filtering.
  3122. This must be a list of strings, each string must be a single category
  3123. preceded by \"+\" or \"-\".
  3124. This variable should not be set directly, but agenda custom commands can
  3125. bind it in the options section. The preset filter is a global property of
  3126. the entire agenda view. In a block agenda, it will not work reliably to
  3127. define a filter for one of the individual blocks. You need to set it in
  3128. the global options and expect it to be applied to the entire view.")
  3129. (defun org-agenda-use-sticky-p ()
  3130. "Return non-nil if an agenda buffer named
  3131. `org-agenda-buffer-name' exists and should be shown instead of
  3132. generating a new one."
  3133. (and
  3134. ;; turned off by user
  3135. org-agenda-sticky
  3136. ;; For multi-agenda buffer already exists
  3137. (not org-agenda-multi)
  3138. ;; buffer found
  3139. (get-buffer org-agenda-buffer-name)
  3140. ;; C-u parameter is same as last call
  3141. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3142. (and
  3143. (equal current-prefix-arg
  3144. org-agenda-last-prefix-arg)
  3145. ;; In case user turned stickiness on, while having existing
  3146. ;; Agenda buffer active, don't reuse that buffer, because it
  3147. ;; does not have org variables local
  3148. org-agenda-this-buffer-is-sticky))))
  3149. (defun org-agenda-prepare-window (abuf)
  3150. "Setup agenda buffer in the window."
  3151. (let* ((awin (get-buffer-window abuf))
  3152. wconf)
  3153. (cond
  3154. ((equal (current-buffer) abuf) nil)
  3155. (awin (select-window awin))
  3156. ((not (setq wconf (current-window-configuration))))
  3157. ((equal org-agenda-window-setup 'current-window)
  3158. (org-pop-to-buffer-same-window abuf))
  3159. ((equal org-agenda-window-setup 'other-window)
  3160. (org-switch-to-buffer-other-window abuf))
  3161. ((equal org-agenda-window-setup 'other-frame)
  3162. (switch-to-buffer-other-frame abuf))
  3163. ((equal org-agenda-window-setup 'reorganize-frame)
  3164. (delete-other-windows)
  3165. (org-switch-to-buffer-other-window abuf)))
  3166. ;; additional test in case agenda is invoked from within agenda
  3167. ;; buffer via elisp link
  3168. (unless (equal (current-buffer) abuf)
  3169. (org-pop-to-buffer-same-window abuf))
  3170. (setq org-agenda-pre-window-conf
  3171. (or org-agenda-pre-window-conf wconf))))
  3172. (defun org-agenda-prepare (&optional name)
  3173. (if (org-agenda-use-sticky-p)
  3174. (progn
  3175. ;; Popup existing buffer
  3176. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3177. (message "Sticky Agenda buffer, use `r' to refresh")
  3178. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3179. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3180. (setq org-todo-keywords-for-agenda nil)
  3181. (setq org-drawers-for-agenda nil)
  3182. (unless org-agenda-persistent-filter
  3183. (setq org-agenda-tag-filter nil
  3184. org-agenda-category-filter nil))
  3185. (put 'org-agenda-tag-filter :preset-filter
  3186. org-agenda-tag-filter-preset)
  3187. (put 'org-agenda-category-filter :preset-filter
  3188. org-agenda-category-filter-preset)
  3189. (if org-agenda-multi
  3190. (progn
  3191. (setq buffer-read-only nil)
  3192. (goto-char (point-max))
  3193. (unless (or (bobp) org-agenda-compact-blocks
  3194. (not org-agenda-block-separator))
  3195. (insert "\n"
  3196. (if (stringp org-agenda-block-separator)
  3197. org-agenda-block-separator
  3198. (make-string (window-width) org-agenda-block-separator))
  3199. "\n"))
  3200. (narrow-to-region (point) (point-max)))
  3201. (setq org-done-keywords-for-agenda nil)
  3202. ;; Setting any org variables that are in org-agenda-local-vars
  3203. ;; list need to be done after the prepare call
  3204. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3205. (setq buffer-read-only nil)
  3206. (org-agenda-reset-markers)
  3207. (let ((inhibit-read-only t)) (erase-buffer))
  3208. (org-agenda-mode)
  3209. (setq org-agenda-buffer (current-buffer))
  3210. (setq org-agenda-contributing-files nil)
  3211. (setq org-agenda-columns-active nil)
  3212. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3213. (setq org-todo-keywords-for-agenda
  3214. (org-uniquify org-todo-keywords-for-agenda))
  3215. (setq org-done-keywords-for-agenda
  3216. (org-uniquify org-done-keywords-for-agenda))
  3217. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3218. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3219. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3220. (and name (not org-agenda-name)
  3221. (org-set-local 'org-agenda-name name)))
  3222. (setq buffer-read-only nil)))
  3223. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3224. (defun org-agenda-finalize ()
  3225. "Finishing touch for the agenda buffer, called just before displaying it."
  3226. (unless org-agenda-multi
  3227. (save-excursion
  3228. (let ((inhibit-read-only t))
  3229. (goto-char (point-min))
  3230. (save-excursion
  3231. (while (org-activate-bracket-links (point-max))
  3232. (add-text-properties (match-beginning 0) (match-end 0)
  3233. '(face org-link))))
  3234. (save-excursion
  3235. (while (org-activate-plain-links (point-max))
  3236. (add-text-properties (match-beginning 0) (match-end 0)
  3237. '(face org-link))))
  3238. (when (cadr (assoc 'org-prefix-has-tag
  3239. (car org-prefix-format-compiled)))
  3240. (org-agenda-align-tags))
  3241. (unless org-agenda-with-colors
  3242. (remove-text-properties (point-min) (point-max) '(face nil))))
  3243. (if (and (boundp 'org-agenda-overriding-columns-format)
  3244. org-agenda-overriding-columns-format)
  3245. (org-set-local 'org-agenda-overriding-columns-format
  3246. org-agenda-overriding-columns-format))
  3247. (if (and (boundp 'org-agenda-view-columns-initially)
  3248. org-agenda-view-columns-initially)
  3249. (org-agenda-columns))
  3250. (when org-agenda-fontify-priorities
  3251. (org-agenda-fontify-priorities))
  3252. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3253. (org-agenda-dim-blocked-tasks))
  3254. ;; We need to widen when `org-agenda-finalize' is called from
  3255. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3256. (when org-clock-current-task
  3257. (save-restriction
  3258. (widen)
  3259. (org-agenda-mark-clocking-task)))
  3260. (when org-agenda-entry-text-mode
  3261. (org-agenda-entry-text-hide)
  3262. (org-agenda-entry-text-show))
  3263. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3264. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3265. (org-habit-insert-consistency-graphs))
  3266. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3267. (when (delq nil (mapcar (lambda (tp) (org-agenda-check-type nil tp))
  3268. org-agenda-use-tag-inheritance))
  3269. (let (mrk)
  3270. (save-excursion
  3271. (goto-char (point-min))
  3272. (while (equal (forward-line) 0)
  3273. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3274. (get-text-property (point) 'org-hd-marker)))
  3275. (put-text-property (point-at-bol) (point-at-eol)
  3276. 'tags (org-with-point-at mrk
  3277. (delete-dups
  3278. (mapcar 'downcase (org-get-tags-at))))))))))
  3279. (let ((inhibit-read-only t))
  3280. (run-hooks 'org-agenda-finalize-hook))
  3281. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3282. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3283. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3284. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3285. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
  3286. (defun org-agenda-mark-clocking-task ()
  3287. "Mark the current clock entry in the agenda if it is present."
  3288. (mapc (lambda (o)
  3289. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3290. (delete-overlay o)))
  3291. (overlays-in (point-min) (point-max)))
  3292. (when (marker-buffer org-clock-hd-marker)
  3293. (save-excursion
  3294. (goto-char (point-min))
  3295. (let (s ov)
  3296. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3297. (goto-char s)
  3298. (when (equal (org-get-at-bol 'org-hd-marker)
  3299. org-clock-hd-marker)
  3300. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3301. (overlay-put ov 'type 'org-agenda-clocking)
  3302. (overlay-put ov 'face 'org-agenda-clocking)
  3303. (overlay-put ov 'help-echo
  3304. "The clock is running in this item")))))))
  3305. (defun org-agenda-fontify-priorities ()
  3306. "Make highest priority lines bold, and lowest italic."
  3307. (interactive)
  3308. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3309. (delete-overlay o)))
  3310. (overlays-in (point-min) (point-max)))
  3311. (save-excursion
  3312. (let ((inhibit-read-only t)
  3313. b e p ov h l)
  3314. (goto-char (point-min))
  3315. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3316. (setq h (or (get-char-property (point) 'org-highest-priority)
  3317. org-highest-priority)
  3318. l (or (get-char-property (point) 'org-lowest-priority)
  3319. org-lowest-priority)
  3320. p (string-to-char (match-string 1))
  3321. b (match-beginning 0)
  3322. e (if (eq org-agenda-fontify-priorities 'cookies)
  3323. (match-end 0)
  3324. (point-at-eol))
  3325. ov (make-overlay b e))
  3326. (overlay-put
  3327. ov 'face
  3328. (cond ((org-face-from-face-or-color
  3329. 'priority nil
  3330. (cdr (assoc p org-priority-faces))))
  3331. ((and (listp org-agenda-fontify-priorities)
  3332. (org-face-from-face-or-color
  3333. 'priority nil
  3334. (cdr (assoc p org-agenda-fontify-priorities)))))
  3335. ((equal p l) 'italic)
  3336. ((equal p h) 'bold)))
  3337. (overlay-put ov 'org-type 'org-priority)))))
  3338. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3339. (interactive "P")
  3340. "Dim currently blocked TODO's in the agenda display."
  3341. (message "Dim or hide blocked tasks...")
  3342. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3343. (delete-overlay o)))
  3344. (overlays-in (point-min) (point-max)))
  3345. (save-excursion
  3346. (let ((inhibit-read-only t)
  3347. (org-depend-tag-blocked nil)
  3348. (invis (or (not (null invisible))
  3349. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3350. org-blocked-by-checkboxes
  3351. invis1 b e p ov h l)
  3352. (goto-char (point-min))
  3353. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3354. (and pos (goto-char (1+ pos))))
  3355. (setq org-blocked-by-checkboxes nil invis1 invis)
  3356. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3357. (when (and marker
  3358. (with-current-buffer (marker-buffer marker)
  3359. (save-excursion (goto-char marker)
  3360. (org-entry-blocked-p))))
  3361. (if org-blocked-by-checkboxes (setq invis1 nil))
  3362. (setq b (if invis1
  3363. (max (point-min) (1- (point-at-bol)))
  3364. (point-at-bol))
  3365. e (point-at-eol)
  3366. ov (make-overlay b e))
  3367. (if invis1
  3368. (overlay-put ov 'invisible t)
  3369. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3370. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3371. (message "Dim or hide blocked tasks...done"))
  3372. (defvar org-agenda-skip-function nil
  3373. "Function to be called at each match during agenda construction.
  3374. If this function returns nil, the current match should not be skipped.
  3375. Otherwise, the function must return a position from where the search
  3376. should be continued.
  3377. This may also be a Lisp form, it will be evaluated.
  3378. Never set this variable using `setq' or so, because then it will apply
  3379. to all future agenda commands. If you do want a global skipping condition,
  3380. use the option `org-agenda-skip-function-global' instead.
  3381. The correct usage for `org-agenda-skip-function' is to bind it with
  3382. `let' to scope it dynamically into the agenda-constructing command.
  3383. A good way to set it is through options in `org-agenda-custom-commands'.")
  3384. (defun org-agenda-skip ()
  3385. "Throw to `:skip' in places that should be skipped.
  3386. Also moves point to the end of the skipped region, so that search can
  3387. continue from there."
  3388. (let ((p (point-at-bol)) to)
  3389. (when (org-in-src-block-p t) (throw :skip t))
  3390. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3391. (get-text-property p :org-archived)
  3392. (org-end-of-subtree t)
  3393. (throw :skip t))
  3394. (and org-agenda-skip-comment-trees
  3395. (get-text-property p :org-comment)
  3396. (org-end-of-subtree t)
  3397. (throw :skip t))
  3398. (if (equal (char-after p) ?#) (throw :skip t))
  3399. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3400. (org-agenda-skip-eval org-agenda-skip-function)))
  3401. (goto-char to)
  3402. (throw :skip t))))
  3403. (defun org-agenda-skip-eval (form)
  3404. "If FORM is a function or a list, call (or eval) is and return result.
  3405. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3406. and match data are returned to the previous state no matter what these
  3407. functions do."
  3408. (let (fp)
  3409. (and form
  3410. (or (setq fp (functionp form))
  3411. (consp form))
  3412. (save-excursion
  3413. (save-match-data
  3414. (if fp
  3415. (funcall form)
  3416. (eval form)))))))
  3417. (defvar org-agenda-markers nil
  3418. "List of all currently active markers created by `org-agenda'.")
  3419. (defvar org-agenda-last-marker-time (org-float-time)
  3420. "Creation time of the last agenda marker.")
  3421. (defun org-agenda-new-marker (&optional pos)
  3422. "Return a new agenda marker.
  3423. Org-mode keeps a list of these markers and resets them when they are
  3424. no longer in use."
  3425. (let ((m (copy-marker (or pos (point)))))
  3426. (setq org-agenda-last-marker-time (org-float-time))
  3427. (if org-agenda-buffer
  3428. (with-current-buffer org-agenda-buffer
  3429. (push m org-agenda-markers))
  3430. (push m org-agenda-markers))
  3431. m))
  3432. (defun org-agenda-reset-markers ()
  3433. "Reset markers created by `org-agenda'."
  3434. (while org-agenda-markers
  3435. (move-marker (pop org-agenda-markers) nil)))
  3436. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3437. "Save relative positions of markers in region.
  3438. This check for agenda markers in all agenda buffers currently active."
  3439. (dolist (buf (buffer-list))
  3440. (with-current-buffer buf
  3441. (when (eq major-mode 'org-agenda-mode)
  3442. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3443. org-agenda-markers)))))
  3444. ;;; Entry text mode
  3445. (defun org-agenda-entry-text-show-here ()
  3446. "Add some text from the entry as context to the current line."
  3447. (let (m txt o)
  3448. (setq m (org-get-at-bol 'org-hd-marker))
  3449. (unless (marker-buffer m)
  3450. (error "No marker points to an entry here"))
  3451. (setq txt (concat "\n" (org-no-properties
  3452. (org-agenda-get-some-entry-text
  3453. m org-agenda-entry-text-maxlines " > "))))
  3454. (when (string-match "\\S-" txt)
  3455. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3456. (overlay-put o 'evaporate t)
  3457. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3458. (overlay-put o 'after-string txt))))
  3459. (defun org-agenda-entry-text-show ()
  3460. "Add entry context for all agenda lines."
  3461. (interactive)
  3462. (save-excursion
  3463. (goto-char (point-max))
  3464. (beginning-of-line 1)
  3465. (while (not (bobp))
  3466. (when (org-get-at-bol 'org-hd-marker)
  3467. (org-agenda-entry-text-show-here))
  3468. (beginning-of-line 0))))
  3469. (defun org-agenda-entry-text-hide ()
  3470. "Remove any shown entry context."
  3471. (delq nil
  3472. (mapcar (lambda (o)
  3473. (if (eq (overlay-get o 'org-overlay-type)
  3474. 'agenda-entry-content)
  3475. (progn (delete-overlay o) t)))
  3476. (overlays-in (point-min) (point-max)))))
  3477. (defun org-agenda-get-day-face (date)
  3478. "Return the face DATE should be displayed with."
  3479. (or (and (functionp org-agenda-day-face-function)
  3480. (funcall org-agenda-day-face-function date))
  3481. (cond ((org-agenda-todayp date)
  3482. 'org-agenda-date-today)
  3483. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3484. 'org-agenda-date-weekend)
  3485. (t 'org-agenda-date))))
  3486. ;;; Agenda timeline
  3487. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3488. (defun org-timeline (&optional dotodo)
  3489. "Show a time-sorted view of the entries in the current org file.
  3490. Only entries with a time stamp of today or later will be listed. With
  3491. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3492. under the current date.
  3493. If the buffer contains an active region, only check the region for
  3494. dates."
  3495. (interactive "P")
  3496. (let* ((dopast t)
  3497. (org-agenda-show-log-scoped org-agenda-show-log)
  3498. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3499. (current-buffer))))
  3500. (date (calendar-current-date))
  3501. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3502. (end (if (org-region-active-p) (region-end) (point-max)))
  3503. (day-numbers (org-get-all-dates
  3504. beg end 'no-ranges
  3505. t org-agenda-show-log-scoped ; always include today
  3506. org-timeline-show-empty-dates))
  3507. (org-deadline-warning-days 0)
  3508. (org-agenda-only-exact-dates t)
  3509. (today (org-today))
  3510. (past t)
  3511. args
  3512. s e rtn d emptyp)
  3513. (setq org-agenda-redo-command
  3514. (list 'progn
  3515. (list 'org-switch-to-buffer-other-window (current-buffer))
  3516. (list 'org-timeline (list 'quote dotodo))))
  3517. (if (not dopast)
  3518. ;; Remove past dates from the list of dates.
  3519. (setq day-numbers (delq nil (mapcar (lambda(x)
  3520. (if (>= x today) x nil))
  3521. day-numbers))))
  3522. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3523. (org-compile-prefix-format 'timeline)
  3524. (org-set-sorting-strategy 'timeline)
  3525. (if org-agenda-show-log-scoped (push :closed args))
  3526. (push :timestamp args)
  3527. (push :deadline args)
  3528. (push :scheduled args)
  3529. (push :sexp args)
  3530. (if dotodo (push :todo args))
  3531. (insert "Timeline of file " entry "\n")
  3532. (add-text-properties (point-min) (point)
  3533. (list 'face 'org-agenda-structure))
  3534. (org-agenda-mark-header-line (point-min))
  3535. (while (setq d (pop day-numbers))
  3536. (if (and (listp d) (eq (car d) :omitted))
  3537. (progn
  3538. (setq s (point))
  3539. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3540. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3541. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3542. (if (and (>= d today)
  3543. dopast
  3544. past)
  3545. (progn
  3546. (setq past nil)
  3547. (insert (make-string 79 ?-) "\n")))
  3548. (setq date (calendar-gregorian-from-absolute d))
  3549. (setq s (point))
  3550. (setq rtn (and (not emptyp)
  3551. (apply 'org-agenda-get-day-entries entry
  3552. date args)))
  3553. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3554. (progn
  3555. (insert
  3556. (if (stringp org-agenda-format-date)
  3557. (format-time-string org-agenda-format-date
  3558. (org-time-from-absolute date))
  3559. (funcall org-agenda-format-date date))
  3560. "\n")
  3561. (put-text-property s (1- (point)) 'face
  3562. (org-agenda-get-day-face date))
  3563. (put-text-property s (1- (point)) 'org-date-line t)
  3564. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3565. (if (equal d today)
  3566. (put-text-property s (1- (point)) 'org-today t))
  3567. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3568. (put-text-property s (1- (point)) 'day d)))))
  3569. (goto-char (point-min))
  3570. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3571. (point-min)))
  3572. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3573. (org-agenda-finalize)
  3574. (setq buffer-read-only t)))
  3575. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3576. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3577. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3578. not every single day in the range. If FORCE-TODAY is non-nil, make
  3579. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3580. inactive time stamps (those in square brackets) are included.
  3581. When EMPTY is non-nil, also include days without any entries."
  3582. (let ((re (concat
  3583. (if pre-re pre-re "")
  3584. (if inactive org-ts-regexp-both org-ts-regexp)))
  3585. dates dates1 date day day1 day2 ts1 ts2 pos)
  3586. (if force-today
  3587. (setq dates (list (org-today))))
  3588. (save-excursion
  3589. (goto-char beg)
  3590. (while (re-search-forward re end t)
  3591. (setq day (time-to-days (org-time-string-to-time
  3592. (substring (match-string 1) 0 10)
  3593. (current-buffer) (match-beginning 0))))
  3594. (or (memq day dates) (push day dates)))
  3595. (unless no-ranges
  3596. (goto-char beg)
  3597. (while (re-search-forward org-tr-regexp end t)
  3598. (setq pos (match-beginning 0))
  3599. (setq ts1 (substring (match-string 1) 0 10)
  3600. ts2 (substring (match-string 2) 0 10)
  3601. day1 (time-to-days (org-time-string-to-time
  3602. ts1 (current-buffer) pos))
  3603. day2 (time-to-days (org-time-string-to-time
  3604. ts2 (current-buffer) pos)))
  3605. (while (< (setq day1 (1+ day1)) day2)
  3606. (or (memq day1 dates) (push day1 dates)))))
  3607. (setq dates (sort dates '<))
  3608. (when empty
  3609. (while (setq day (pop dates))
  3610. (setq day2 (car dates))
  3611. (push day dates1)
  3612. (when (and day2 empty)
  3613. (if (or (eq empty t)
  3614. (and (numberp empty) (<= (- day2 day) empty)))
  3615. (while (< (setq day (1+ day)) day2)
  3616. (push (list day) dates1))
  3617. (push (cons :omitted (- day2 day)) dates1))))
  3618. (setq dates (nreverse dates1)))
  3619. dates)))
  3620. ;;; Agenda Daily/Weekly
  3621. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3622. "Start day for the agenda view.
  3623. Custom commands can set this variable in the options section.")
  3624. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3625. (defvar org-arg-loc nil) ; local variable
  3626. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3627. "List of types searched for when creating the daily/weekly agenda.
  3628. This variable is a list of symbols that controls the types of
  3629. items that appear in the daily/weekly agenda. Allowed symbols in this
  3630. list are are
  3631. :timestamp List items containing a date stamp or date range matching
  3632. the selected date. This includes sexp entries in
  3633. angular brackets.
  3634. :sexp List entries resulting from plain diary-like sexps.
  3635. :deadline List deadline due on that date. When the date is today,
  3636. also list any deadlines past due, or due within
  3637. `org-deadline-warning-days'. `:deadline' must appear before
  3638. `:scheduled' if the setting of
  3639. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3640. any effect.
  3641. :scheduled List all items which are scheduled for the given date.
  3642. The diary for *today* also contains items which were
  3643. scheduled earlier and are not yet marked DONE.
  3644. By default, all four types are turned on.
  3645. Never set this variable globally using `setq', because then it
  3646. will apply to all future agenda commands. Instead, bind it with
  3647. `let' to scope it dynamically into the agenda-constructing
  3648. command. A good way to set it is through options in
  3649. `org-agenda-custom-commands'. For a more flexible (though
  3650. somewhat less efficient) way of determining what is included in
  3651. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3652. (defvar org-agenda-buffer-tmp-name nil)
  3653. ;;;###autoload
  3654. (defun org-agenda-list (&optional arg start-day span)
  3655. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3656. The view will be for the current day or week, but from the overview buffer
  3657. you will be able to go to other days/weeks.
  3658. With a numeric prefix argument in an interactive call, the agenda will
  3659. span ARG days. Lisp programs should instead specify SPAN to change
  3660. the number of days. SPAN defaults to `org-agenda-span'.
  3661. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3662. given in `org-agenda-start-on-weekday'."
  3663. (interactive "P")
  3664. (if org-agenda-overriding-arguments
  3665. (setq arg (car org-agenda-overriding-arguments)
  3666. start-day (nth 1 org-agenda-overriding-arguments)
  3667. span (nth 2 org-agenda-overriding-arguments)))
  3668. (if (and (integerp arg) (> arg 0))
  3669. (setq span arg arg nil))
  3670. (catch 'exit
  3671. (setq org-agenda-buffer-name
  3672. (or org-agenda-buffer-tmp-name
  3673. (if org-agenda-sticky
  3674. (cond ((and org-keys (stringp org-match))
  3675. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3676. (org-keys
  3677. (format "*Org Agenda(%s)*" org-keys))
  3678. (t "*Org Agenda(a)*")))
  3679. org-agenda-buffer-name))
  3680. (org-agenda-prepare "Day/Week")
  3681. (setq start-day (or start-day org-agenda-start-day))
  3682. (if (stringp start-day)
  3683. ;; Convert to an absolute day number
  3684. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3685. (org-compile-prefix-format 'agenda)
  3686. (org-set-sorting-strategy 'agenda)
  3687. (let* ((span (org-agenda-ndays-to-span
  3688. (or span org-agenda-ndays org-agenda-span)))
  3689. (today (org-today))
  3690. (sd (or start-day today))
  3691. (ndays (org-agenda-span-to-ndays span sd))
  3692. (org-agenda-start-on-weekday
  3693. (if (eq ndays 7)
  3694. org-agenda-start-on-weekday))
  3695. (thefiles (org-agenda-files nil 'ifmode))
  3696. (files thefiles)
  3697. (start (if (or (null org-agenda-start-on-weekday)
  3698. (< ndays 7))
  3699. sd
  3700. (let* ((nt (calendar-day-of-week
  3701. (calendar-gregorian-from-absolute sd)))
  3702. (n1 org-agenda-start-on-weekday)
  3703. (d (- nt n1)))
  3704. (- sd (+ (if (< d 0) 7 0) d)))))
  3705. (day-numbers (list start))
  3706. (day-cnt 0)
  3707. (inhibit-redisplay (not debug-on-error))
  3708. (org-agenda-show-log-scoped org-agenda-show-log)
  3709. s e rtn rtnall file date d start-pos end-pos todayp
  3710. clocktable-start clocktable-end filter)
  3711. (setq org-agenda-redo-command
  3712. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3713. (dotimes (n (1- ndays))
  3714. (push (1+ (car day-numbers)) day-numbers))
  3715. (setq day-numbers (nreverse day-numbers))
  3716. (setq clocktable-start (car day-numbers)
  3717. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3718. (org-set-local 'org-starting-day (car day-numbers))
  3719. (org-set-local 'org-arg-loc arg)
  3720. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3721. (unless org-agenda-compact-blocks
  3722. (let* ((d1 (car day-numbers))
  3723. (d2 (org-last day-numbers))
  3724. (w1 (org-days-to-iso-week d1))
  3725. (w2 (org-days-to-iso-week d2)))
  3726. (setq s (point))
  3727. (if org-agenda-overriding-header
  3728. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3729. nil 'face 'org-agenda-structure) "\n")
  3730. (insert (org-agenda-span-name span)
  3731. "-agenda"
  3732. (if (< (- d2 d1) 350)
  3733. (if (= w1 w2)
  3734. (format " (W%02d)" w1)
  3735. (format " (W%02d-W%02d)" w1 w2))
  3736. "")
  3737. ":\n")))
  3738. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3739. 'org-date-line t))
  3740. (org-agenda-mark-header-line s))
  3741. (while (setq d (pop day-numbers))
  3742. (setq date (calendar-gregorian-from-absolute d)
  3743. s (point))
  3744. (if (or (setq todayp (= d today))
  3745. (and (not start-pos) (= d sd)))
  3746. (setq start-pos (point))
  3747. (if (and start-pos (not end-pos))
  3748. (setq end-pos (point))))
  3749. (setq files thefiles
  3750. rtnall nil)
  3751. (while (setq file (pop files))
  3752. (catch 'nextfile
  3753. (org-check-agenda-file file)
  3754. (let ((org-agenda-entry-types org-agenda-entry-types))
  3755. (unless org-agenda-include-deadlines
  3756. (setq org-agenda-entry-types
  3757. (delq :deadline org-agenda-entry-types)))
  3758. (cond
  3759. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3760. (setq rtn (org-agenda-get-day-entries
  3761. file date :closed)))
  3762. (org-agenda-show-log-scoped
  3763. (setq rtn (apply 'org-agenda-get-day-entries
  3764. file date
  3765. (append '(:closed) org-agenda-entry-types))))
  3766. (t
  3767. (setq rtn (apply 'org-agenda-get-day-entries
  3768. file date
  3769. org-agenda-entry-types)))))
  3770. (setq rtnall (append rtnall rtn)))) ;; all entries
  3771. (if org-agenda-include-diary
  3772. (let ((org-agenda-search-headline-for-time t))
  3773. (require 'diary-lib)
  3774. (setq rtn (org-get-entries-from-diary date))
  3775. (setq rtnall (append rtnall rtn))))
  3776. (if (or rtnall org-agenda-show-all-dates)
  3777. (progn
  3778. (setq day-cnt (1+ day-cnt))
  3779. (insert
  3780. (if (stringp org-agenda-format-date)
  3781. (format-time-string org-agenda-format-date
  3782. (org-time-from-absolute date))
  3783. (funcall org-agenda-format-date date))
  3784. "\n")
  3785. (put-text-property s (1- (point)) 'face
  3786. (org-agenda-get-day-face date))
  3787. (put-text-property s (1- (point)) 'org-date-line t)
  3788. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3789. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3790. (when todayp
  3791. (put-text-property s (1- (point)) 'org-today t))
  3792. (setq rtnall
  3793. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3794. (if rtnall (insert ;; all entries
  3795. (org-agenda-finalize-entries rtnall)
  3796. "\n"))
  3797. (put-text-property s (1- (point)) 'day d)
  3798. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3799. (when (and org-agenda-clockreport-mode clocktable-start)
  3800. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3801. ;; the above line is to ensure the restricted range!
  3802. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3803. tbl)
  3804. (setq p (org-plist-delete p :block))
  3805. (setq p (plist-put p :tstart clocktable-start))
  3806. (setq p (plist-put p :tend clocktable-end))
  3807. (setq p (plist-put p :scope 'agenda))
  3808. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3809. (setq filter (or org-agenda-tag-filter-while-redo
  3810. (get 'org-agenda-tag-filter :preset-filter))))
  3811. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3812. (if (string-match "[<>=]" x)
  3813. ""
  3814. x))
  3815. filter ""))))
  3816. (setq tbl (apply 'org-clock-get-clocktable p))
  3817. (insert tbl)))
  3818. (goto-char (point-min))
  3819. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3820. (unless (and (pos-visible-in-window-p (point-min))
  3821. (pos-visible-in-window-p (point-max)))
  3822. (goto-char (1- (point-max)))
  3823. (recenter -1)
  3824. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3825. (progn
  3826. (goto-char (or start-pos 1))
  3827. (recenter 1))))
  3828. (goto-char (or start-pos 1))
  3829. (add-text-properties (point-min) (point-max)
  3830. `(org-agenda-type agenda
  3831. org-last-args (,arg ,start-day ,span)
  3832. org-redo-cmd ,org-agenda-redo-command
  3833. org-series-cmd ,org-cmd))
  3834. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3835. (org-agenda-show-clocking-issues))
  3836. (org-agenda-finalize)
  3837. (setq buffer-read-only t)
  3838. (message ""))))
  3839. (autoload 'org-agenda-list "org-agenda" "\
  3840. Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3841. The view will be for the current day or week, but from the overview buffer
  3842. you will be able to go to other days/weeks.
  3843. With a numeric prefix argument in an interactive call, the agenda will
  3844. span ARG days. Lisp programs should instead specify SPAN to change
  3845. the number of days. SPAN defaults to `org-agenda-span'.
  3846. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3847. given in `org-agenda-start-on-weekday'.
  3848. \(fn &optional ARG START-DAY SPAN)" t nil)
  3849. (defun org-agenda-ndays-to-span (n)
  3850. "Return a span symbol for a span of N days, or N if none matches."
  3851. (cond ((symbolp n) n)
  3852. ((= n 1) 'day)
  3853. ((= n 7) 'week)
  3854. (t n)))
  3855. (defun org-agenda-span-to-ndays (span &optional start-day)
  3856. "Return ndays from SPAN, possibly starting at START-DAY."
  3857. (cond ((numberp span) span)
  3858. ((eq span 'day) 1)
  3859. ((eq span 'week) 7)
  3860. ((eq span 'month)
  3861. (let ((date (calendar-gregorian-from-absolute start-day)))
  3862. (calendar-last-day-of-month (car date) (caddr date))))
  3863. ((eq span 'year)
  3864. (let ((date (calendar-gregorian-from-absolute start-day)))
  3865. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3866. (defun org-agenda-span-name (span)
  3867. "Return a SPAN name."
  3868. (if (null span)
  3869. ""
  3870. (if (symbolp span)
  3871. (capitalize (symbol-name span))
  3872. (format "%d days" span))))
  3873. ;;; Agenda word search
  3874. (defvar org-agenda-search-history nil)
  3875. (defvar org-search-syntax-table nil
  3876. "Special syntax table for org-mode search.
  3877. In this table, we have single quotes not as word constituents, to
  3878. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3879. (defvar org-mode-syntax-table) ; From org.el
  3880. (defun org-search-syntax-table ()
  3881. (unless org-search-syntax-table
  3882. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3883. (modify-syntax-entry ?' "." org-search-syntax-table)
  3884. (modify-syntax-entry ?` "." org-search-syntax-table))
  3885. org-search-syntax-table)
  3886. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3887. ;;;###autoload
  3888. (defun org-search-view (&optional todo-only string edit-at)
  3889. "Show all entries that contain a phrase or words or regular expressions.
  3890. With optional prefix argument TODO-ONLY, only consider entries that are
  3891. TODO entries. The argument STRING can be used to pass a default search
  3892. string into this function. If EDIT-AT is non-nil, it means that the
  3893. user should get a chance to edit this string, with cursor at position
  3894. EDIT-AT.
  3895. The search string can be viewed either as a phrase that should be found as
  3896. is, or it can be broken into a number of snippets, each of which must match
  3897. in a Boolean way to select an entry. The default depends on the variable
  3898. `org-agenda-search-view-always-boolean'.
  3899. Even if this is turned off (the default) you can always switch to
  3900. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3901. The default is a direct search of the whole phrase, where each space in
  3902. the search string can expand to an arbitrary amount of whitespace,
  3903. including newlines.
  3904. If using a Boolean search, the search string is split on whitespace and
  3905. each snippet is searched separately, with logical AND to select an entry.
  3906. Words prefixed with a minus must *not* occur in the entry. Words without
  3907. a prefix or prefixed with a plus must occur in the entry. Matching is
  3908. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3909. match whole words, not parts of a word) if
  3910. `org-agenda-search-view-force-full-words' is set (default is nil).
  3911. Boolean search snippets enclosed by curly braces are interpreted as
  3912. regular expressions that must or (when preceded with \"-\") must not
  3913. match in the entry. Snippets enclosed into double quotes will be taken
  3914. as a whole, to include whitespace.
  3915. - If the search string starts with an asterisk, search only in headlines.
  3916. - If (possibly after the leading star) the search string starts with an
  3917. exclamation mark, this also means to look at TODO entries only, an effect
  3918. that can also be achieved with a prefix argument.
  3919. - If (possibly after star and exclamation mark) the search string starts
  3920. with a colon, this will mean that the (non-regexp) snippets of the
  3921. Boolean search must match as full words.
  3922. This command searches the agenda files, and in addition the files listed
  3923. in `org-agenda-text-search-extra-files'."
  3924. (interactive "P")
  3925. (if org-agenda-overriding-arguments
  3926. (setq todo-only (car org-agenda-overriding-arguments)
  3927. string (nth 1 org-agenda-overriding-arguments)
  3928. edit-at (nth 2 org-agenda-overriding-arguments)))
  3929. (let* ((props (list 'face nil
  3930. 'done-face 'org-agenda-done
  3931. 'org-not-done-regexp org-not-done-regexp
  3932. 'org-todo-regexp org-todo-regexp
  3933. 'org-complex-heading-regexp org-complex-heading-regexp
  3934. 'mouse-face 'highlight
  3935. 'help-echo (format "mouse-2 or RET jump to location")))
  3936. (full-words org-agenda-search-view-force-full-words)
  3937. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3938. regexp rtn rtnall files file pos
  3939. marker category category-pos level tags c neg re boolean
  3940. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3941. (unless (and (not edit-at)
  3942. (stringp string)
  3943. (string-match "\\S-" string))
  3944. (setq string (read-string
  3945. (if org-agenda-search-view-always-boolean
  3946. "[+-]Word/{Regexp} ...: "
  3947. "Phrase or [+-]Word/{Regexp} ...: ")
  3948. (cond
  3949. ((integerp edit-at) (cons string edit-at))
  3950. (edit-at string))
  3951. 'org-agenda-search-history)))
  3952. (catch 'exit
  3953. (if org-agenda-sticky
  3954. (setq org-agenda-buffer-name
  3955. (if (stringp string)
  3956. (format "*Org Agenda(%s:%s)*"
  3957. (or org-keys (or (and todo-only "S") "s")) string)
  3958. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3959. (org-agenda-prepare "SEARCH")
  3960. (org-compile-prefix-format 'search)
  3961. (org-set-sorting-strategy 'search)
  3962. (setq org-agenda-redo-command
  3963. (list 'org-search-view (if todo-only t nil)
  3964. (list 'if 'current-prefix-arg nil string)))
  3965. (setq org-agenda-query-string string)
  3966. (if (equal (string-to-char string) ?*)
  3967. (setq hdl-only t
  3968. words (substring string 1))
  3969. (setq words string))
  3970. (when (equal (string-to-char words) ?!)
  3971. (setq todo-only t
  3972. words (substring words 1)))
  3973. (when (equal (string-to-char words) ?:)
  3974. (setq full-words t
  3975. words (substring words 1)))
  3976. (if (or org-agenda-search-view-always-boolean
  3977. (member (string-to-char words) '(?- ?+ ?\{)))
  3978. (setq boolean t))
  3979. (setq words (org-split-string words))
  3980. (let (www w)
  3981. (while (setq w (pop words))
  3982. (while (and (string-match "\\\\\\'" w) words)
  3983. (setq w (concat (substring w 0 -1) " " (pop words))))
  3984. (push w www))
  3985. (setq words (nreverse www) www nil)
  3986. (while (setq w (pop words))
  3987. (when (and (string-match "\\`[-+]?{" w)
  3988. (not (string-match "}\\'" w)))
  3989. (while (and words (not (string-match "}\\'" (car words))))
  3990. (setq w (concat w " " (pop words))))
  3991. (setq w (concat w " " (pop words))))
  3992. (push w www))
  3993. (setq words (nreverse www)))
  3994. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3995. (when boolean
  3996. (let (wds w)
  3997. (while (setq w (pop words))
  3998. (if (or (equal (substring w 0 1) "\"")
  3999. (and (> (length w) 1)
  4000. (member (substring w 0 1) '("+" "-"))
  4001. (equal (substring w 1 2) "\"")))
  4002. (while (and words (not (equal (substring w -1) "\"")))
  4003. (setq w (concat w " " (pop words)))))
  4004. (and (string-match "\\`\\([-+]?\\)\"" w)
  4005. (setq w (replace-match "\\1" nil nil w)))
  4006. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4007. (push w wds))
  4008. (setq words (nreverse wds))))
  4009. (if boolean
  4010. (mapc (lambda (w)
  4011. (setq c (string-to-char w))
  4012. (if (equal c ?-)
  4013. (setq neg t w (substring w 1))
  4014. (if (equal c ?+)
  4015. (setq neg nil w (substring w 1))
  4016. (setq neg nil)))
  4017. (if (string-match "\\`{.*}\\'" w)
  4018. (setq re (substring w 1 -1))
  4019. (if full-words
  4020. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4021. (setq re (regexp-quote (downcase w)))))
  4022. (if neg (push re regexps-) (push re regexps+)))
  4023. words)
  4024. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4025. regexps+))
  4026. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4027. (if (not regexps+)
  4028. (setq regexp org-outline-regexp-bol)
  4029. (setq regexp (pop regexps+))
  4030. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4031. regexp))))
  4032. (setq files (org-agenda-files nil 'ifmode))
  4033. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4034. (pop org-agenda-text-search-extra-files)
  4035. (setq files (org-add-archive-files files)))
  4036. (setq files (append files org-agenda-text-search-extra-files)
  4037. rtnall nil)
  4038. (while (setq file (pop files))
  4039. (setq ee nil)
  4040. (catch 'nextfile
  4041. (org-check-agenda-file file)
  4042. (setq buffer (if (file-exists-p file)
  4043. (org-get-agenda-file-buffer file)
  4044. (error "No such file %s" file)))
  4045. (if (not buffer)
  4046. ;; If file does not exist, make sure an error message is sent
  4047. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4048. file))))
  4049. (with-current-buffer buffer
  4050. (with-syntax-table (org-search-syntax-table)
  4051. (unless (derived-mode-p 'org-mode)
  4052. (error "Agenda file %s is not in `org-mode'" file))
  4053. (let ((case-fold-search t))
  4054. (save-excursion
  4055. (save-restriction
  4056. (if org-agenda-restrict
  4057. (narrow-to-region org-agenda-restrict-begin
  4058. org-agenda-restrict-end)
  4059. (widen))
  4060. (goto-char (point-min))
  4061. (unless (or (org-at-heading-p)
  4062. (outline-next-heading))
  4063. (throw 'nextfile t))
  4064. (goto-char (max (point-min) (1- (point))))
  4065. (while (re-search-forward regexp nil t)
  4066. (org-back-to-heading t)
  4067. (while (and org-agenda-search-view-max-outline-level
  4068. (> (org-reduced-level (org-outline-level))
  4069. org-agenda-search-view-max-outline-level)
  4070. (forward-line -1)
  4071. (outline-back-to-heading t)))
  4072. (skip-chars-forward "* ")
  4073. (setq beg (point-at-bol)
  4074. beg1 (point)
  4075. end (progn
  4076. (outline-next-heading)
  4077. (while (and org-agenda-search-view-max-outline-level
  4078. (> (org-reduced-level (org-outline-level))
  4079. org-agenda-search-view-max-outline-level)
  4080. (forward-line 1)
  4081. (outline-next-heading)))
  4082. (point)))
  4083. (catch :skip
  4084. (goto-char beg)
  4085. (org-agenda-skip)
  4086. (setq str (buffer-substring-no-properties
  4087. (point-at-bol)
  4088. (if hdl-only (point-at-eol) end)))
  4089. (mapc (lambda (wr) (when (string-match wr str)
  4090. (goto-char (1- end))
  4091. (throw :skip t)))
  4092. regexps-)
  4093. (mapc (lambda (wr) (unless (string-match wr str)
  4094. (goto-char (1- end))
  4095. (throw :skip t)))
  4096. (if todo-only
  4097. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4098. regexps+)
  4099. regexps+))
  4100. (goto-char beg)
  4101. (setq marker (org-agenda-new-marker (point))
  4102. category (org-get-category)
  4103. level (make-string (org-reduced-level (org-outline-level)) ? )
  4104. category-pos (get-text-property (point) 'org-category-position)
  4105. tags (org-get-tags-at nil t)
  4106. txt (org-agenda-format-item
  4107. ""
  4108. (buffer-substring-no-properties
  4109. beg1 (point-at-eol))
  4110. level category tags t))
  4111. (org-add-props txt props
  4112. 'org-marker marker 'org-hd-marker marker
  4113. 'org-todo-regexp org-todo-regexp
  4114. 'level level
  4115. 'org-complex-heading-regexp org-complex-heading-regexp
  4116. 'priority 1000 'org-category category
  4117. 'org-category-position category-pos
  4118. 'type "search")
  4119. (push txt ee)
  4120. (goto-char (1- end))))))))))
  4121. (setq rtn (nreverse ee))
  4122. (setq rtnall (append rtnall rtn)))
  4123. (if org-agenda-overriding-header
  4124. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4125. nil 'face 'org-agenda-structure) "\n")
  4126. (insert "Search words: ")
  4127. (add-text-properties (point-min) (1- (point))
  4128. (list 'face 'org-agenda-structure))
  4129. (setq pos (point))
  4130. (insert string "\n")
  4131. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4132. (setq pos (point))
  4133. (unless org-agenda-multi
  4134. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4135. (add-text-properties pos (1- (point))
  4136. (list 'face 'org-agenda-structure))))
  4137. (org-agenda-mark-header-line (point-min))
  4138. (when rtnall
  4139. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4140. (goto-char (point-min))
  4141. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4142. (add-text-properties (point-min) (point-max)
  4143. `(org-agenda-type search
  4144. org-last-args (,todo-only ,string ,edit-at)
  4145. org-redo-cmd ,org-agenda-redo-command
  4146. org-series-cmd ,org-cmd))
  4147. (org-agenda-finalize)
  4148. (setq buffer-read-only t))))
  4149. (autoload 'org-search-view "org-agenda" "\
  4150. Show all entries that contain a phrase or words or regular expressions.
  4151. With optional prefix argument TODO-ONLY, only consider entries that are
  4152. TODO entries. The argument STRING can be used to pass a default search
  4153. string into this function. If EDIT-AT is non-nil, it means that the
  4154. user should get a chance to edit this string, with cursor at position
  4155. EDIT-AT.
  4156. The search string can be viewed either as a phrase that should be found as
  4157. is, or it can be broken into a number of snippets, each of which must match
  4158. in a Boolean way to select an entry. The default depends on the variable
  4159. `org-agenda-search-view-always-boolean'.
  4160. Even if this is turned off (the default) you can always switch to
  4161. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4162. The default is a direct search of the whole phrase, where each space in
  4163. the search string can expand to an arbitrary amount of whitespace,
  4164. including newlines.
  4165. If using a Boolean search, the search string is split on whitespace and
  4166. each snippet is searched separately, with logical AND to select an entry.
  4167. Words prefixed with a minus must *not* occur in the entry. Words without
  4168. a prefix or prefixed with a plus must occur in the entry. Matching is
  4169. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4170. match whole words, not parts of a word) if
  4171. `org-agenda-search-view-force-full-words' is set (default is nil).
  4172. Boolean search snippets enclosed by curly braces are interpreted as
  4173. regular expressions that must or (when preceded with \"-\") must not
  4174. match in the entry. Snippets enclosed into double quotes will be taken
  4175. as a whole, to include whitespace.
  4176. - If the search string starts with an asterisk, search only in headlines.
  4177. - If (possibly after the leading star) the search string starts with an
  4178. exclamation mark, this also means to look at TODO entries only, an effect
  4179. that can also be achieved with a prefix argument.
  4180. - If (possibly after star and exclamation mark) the search string starts
  4181. with a colon, this will mean that the (non-regexp) snippets of the
  4182. Boolean search must match as full words.
  4183. This command searches the agenda files, and in addition the files listed
  4184. in `org-agenda-text-search-extra-files'.
  4185. \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
  4186. ;;; Agenda TODO list
  4187. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4188. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4189. (concat
  4190. (if (or (equal keywords "ALL") (not keywords))
  4191. (propertize "ALL" 'face 'warning)
  4192. (mapconcat
  4193. (lambda (kw)
  4194. (propertize kw 'face (org-get-todo-face kw)))
  4195. (org-split-string keywords "|")
  4196. "|"))
  4197. "\n"))
  4198. (defvar org-select-this-todo-keyword nil)
  4199. (defvar org-last-arg nil)
  4200. ;;;###autoload
  4201. (defun org-todo-list (&optional arg)
  4202. "Show all (not done) TODO entries from all agenda file in a single list.
  4203. The prefix arg can be used to select a specific TODO keyword and limit
  4204. the list to these. When using \\[universal-argument], you will be prompted
  4205. for a keyword. A numeric prefix directly selects the Nth keyword in
  4206. `org-todo-keywords-1'."
  4207. (interactive "P")
  4208. (if org-agenda-overriding-arguments
  4209. (setq arg org-agenda-overriding-arguments))
  4210. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4211. (let* ((today (org-today))
  4212. (date (calendar-gregorian-from-absolute today))
  4213. (kwds org-todo-keywords-for-agenda)
  4214. (completion-ignore-case t)
  4215. (org-select-this-todo-keyword
  4216. (if (stringp arg) arg
  4217. (and arg (integerp arg) (> arg 0)
  4218. (nth (1- arg) kwds))))
  4219. rtn rtnall files file pos)
  4220. (when (equal arg '(4))
  4221. (setq org-select-this-todo-keyword
  4222. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4223. (mapcar 'list kwds) nil nil)))
  4224. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4225. (catch 'exit
  4226. (if org-agenda-sticky
  4227. (setq org-agenda-buffer-name
  4228. (if (stringp org-select-this-todo-keyword)
  4229. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4230. org-select-this-todo-keyword)
  4231. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4232. (org-agenda-prepare "TODO")
  4233. (org-compile-prefix-format 'todo)
  4234. (org-set-sorting-strategy 'todo)
  4235. (setq org-agenda-redo-command
  4236. `(org-todo-list (or (and (numberp current-prefix-arg)
  4237. current-prefix-arg)
  4238. ,org-select-this-todo-keyword
  4239. current-prefix-arg ,arg)))
  4240. (setq files (org-agenda-files nil 'ifmode)
  4241. rtnall nil)
  4242. (while (setq file (pop files))
  4243. (catch 'nextfile
  4244. (org-check-agenda-file file)
  4245. (setq rtn (org-agenda-get-day-entries file date :todo))
  4246. (setq rtnall (append rtnall rtn))))
  4247. (if org-agenda-overriding-header
  4248. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4249. nil 'face 'org-agenda-structure) "\n")
  4250. (insert "Global list of TODO items of type: ")
  4251. (add-text-properties (point-min) (1- (point))
  4252. (list 'face 'org-agenda-structure
  4253. 'short-heading
  4254. (concat "ToDo: "
  4255. (or org-select-this-todo-keyword "ALL"))))
  4256. (org-agenda-mark-header-line (point-min))
  4257. (insert (org-agenda-propertize-selected-todo-keywords
  4258. org-select-this-todo-keyword))
  4259. (setq pos (point))
  4260. (unless org-agenda-multi
  4261. (insert "Available with `N r': (0)[ALL]")
  4262. (let ((n 0) s)
  4263. (mapc (lambda (x)
  4264. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4265. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4266. (insert "\n "))
  4267. (insert " " s))
  4268. kwds))
  4269. (insert "\n"))
  4270. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4271. (org-agenda-mark-header-line (point-min))
  4272. (when rtnall
  4273. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4274. (goto-char (point-min))
  4275. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4276. (add-text-properties (point-min) (point-max)
  4277. `(org-agenda-type todo
  4278. org-last-args ,arg
  4279. org-redo-cmd ,org-agenda-redo-command
  4280. org-series-cmd ,org-cmd))
  4281. (org-agenda-finalize)
  4282. (setq buffer-read-only t))))
  4283. (autoload 'org-todo-list "org-agenda" "\
  4284. Show all (not done) TODO entries from all agenda file in a single list.
  4285. The prefix arg can be used to select a specific TODO keyword and limit
  4286. the list to these. When using \\[universal-argument], you will be prompted
  4287. for a keyword. A numeric prefix directly selects the Nth keyword in
  4288. `org-todo-keywords-1'.
  4289. \(fn &optional ARG)" t nil)
  4290. ;;; Agenda tags match
  4291. ;;;###autoload
  4292. (defun org-tags-view (&optional todo-only match)
  4293. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4294. The prefix arg TODO-ONLY limits the search to TODO entries."
  4295. (interactive "P")
  4296. (if org-agenda-overriding-arguments
  4297. (setq todo-only (car org-agenda-overriding-arguments)
  4298. match (nth 1 org-agenda-overriding-arguments)))
  4299. (let* ((org-tags-match-list-sublevels
  4300. org-tags-match-list-sublevels)
  4301. (completion-ignore-case t)
  4302. rtn rtnall files file pos matcher
  4303. buffer)
  4304. (when (and (stringp match) (not (string-match "\\S-" match)))
  4305. (setq match nil))
  4306. (setq matcher (org-make-tags-matcher match)
  4307. match (car matcher) matcher (cdr matcher))
  4308. (catch 'exit
  4309. (if org-agenda-sticky
  4310. (setq org-agenda-buffer-name
  4311. (if (stringp match)
  4312. (format "*Org Agenda(%s:%s)*"
  4313. (or org-keys (or (and todo-only "M") "m")) match)
  4314. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4315. (org-agenda-prepare (concat "TAGS " match))
  4316. (org-compile-prefix-format 'tags)
  4317. (org-set-sorting-strategy 'tags)
  4318. (setq org-agenda-query-string match)
  4319. (setq org-agenda-redo-command
  4320. (list 'org-tags-view `(quote ,todo-only)
  4321. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4322. (setq files (org-agenda-files nil 'ifmode)
  4323. rtnall nil)
  4324. (while (setq file (pop files))
  4325. (catch 'nextfile
  4326. (org-check-agenda-file file)
  4327. (setq buffer (if (file-exists-p file)
  4328. (org-get-agenda-file-buffer file)
  4329. (error "No such file %s" file)))
  4330. (if (not buffer)
  4331. ;; If file does not exist, error message to agenda
  4332. (setq rtn (list
  4333. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4334. rtnall (append rtnall rtn))
  4335. (with-current-buffer buffer
  4336. (unless (derived-mode-p 'org-mode)
  4337. (error "Agenda file %s is not in `org-mode'" file))
  4338. (save-excursion
  4339. (save-restriction
  4340. (if org-agenda-restrict
  4341. (narrow-to-region org-agenda-restrict-begin
  4342. org-agenda-restrict-end)
  4343. (widen))
  4344. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4345. (setq rtnall (append rtnall rtn))))))))
  4346. (if org-agenda-overriding-header
  4347. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4348. nil 'face 'org-agenda-structure) "\n")
  4349. (insert "Headlines with TAGS match: ")
  4350. (add-text-properties (point-min) (1- (point))
  4351. (list 'face 'org-agenda-structure
  4352. 'short-heading
  4353. (concat "Match: " match)))
  4354. (setq pos (point))
  4355. (insert match "\n")
  4356. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4357. (setq pos (point))
  4358. (unless org-agenda-multi
  4359. (insert "Press `C-u r' to search again with new search string\n"))
  4360. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4361. (org-agenda-mark-header-line (point-min))
  4362. (when rtnall
  4363. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4364. (goto-char (point-min))
  4365. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4366. (add-text-properties (point-min) (point-max)
  4367. `(org-agenda-type tags
  4368. org-last-args (,todo-only ,match)
  4369. org-redo-cmd ,org-agenda-redo-command
  4370. org-series-cmd ,org-cmd))
  4371. (org-agenda-finalize)
  4372. (setq buffer-read-only t))))
  4373. (autoload 'org-tags-view "org-agenda" "\
  4374. Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4375. The prefix arg TODO-ONLY limits the search to TODO entries.
  4376. \(fn &optional TODO-ONLY MATCH)" t nil)
  4377. ;;; Agenda Finding stuck projects
  4378. (defvar org-agenda-skip-regexp nil
  4379. "Regular expression used in skipping subtrees for the agenda.
  4380. This is basically a temporary global variable that can be set and then
  4381. used by user-defined selections using `org-agenda-skip-function'.")
  4382. (defvar org-agenda-overriding-header nil
  4383. "When set during agenda, todo and tags searches it replaces the header.
  4384. This variable should not be set directly, but custom commands can bind it
  4385. in the options section.")
  4386. (defun org-agenda-skip-entry-when-regexp-matches ()
  4387. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4388. If yes, it returns the end position of this entry, causing agenda commands
  4389. to skip the entry but continuing the search in the subtree. This is a
  4390. function that can be put into `org-agenda-skip-function' for the duration
  4391. of a command."
  4392. (let ((end (save-excursion (org-end-of-subtree t)))
  4393. skip)
  4394. (save-excursion
  4395. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4396. (and skip end)))
  4397. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4398. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4399. If yes, it returns the end position of this tree, causing agenda commands
  4400. to skip this subtree. This is a function that can be put into
  4401. `org-agenda-skip-function' for the duration of a command."
  4402. (let ((end (save-excursion (org-end-of-subtree t)))
  4403. skip)
  4404. (save-excursion
  4405. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4406. (and skip end)))
  4407. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4408. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4409. If yes, it returns the end position of the current entry (NOT the tree),
  4410. causing agenda commands to skip the entry but continuing the search in
  4411. the subtree. This is a function that can be put into
  4412. `org-agenda-skip-function' for the duration of a command. An important
  4413. use of this function is for the stuck project list."
  4414. (let ((end (save-excursion (org-end-of-subtree t)))
  4415. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4416. skip)
  4417. (save-excursion
  4418. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4419. (and skip entry-end)))
  4420. (defun org-agenda-skip-entry-if (&rest conditions)
  4421. "Skip entry if any of CONDITIONS is true.
  4422. See `org-agenda-skip-if' for details."
  4423. (org-agenda-skip-if nil conditions))
  4424. (defun org-agenda-skip-subtree-if (&rest conditions)
  4425. "Skip entry if any of CONDITIONS is true.
  4426. See `org-agenda-skip-if' for details."
  4427. (org-agenda-skip-if t conditions))
  4428. (defun org-agenda-skip-if (subtree conditions)
  4429. "Checks current entity for CONDITIONS.
  4430. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4431. the entry (i.e. the text before the next heading) is checked.
  4432. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4433. from different tests. Valid conditions are:
  4434. scheduled Check if there is a scheduled cookie
  4435. notscheduled Check if there is no scheduled cookie
  4436. deadline Check if there is a deadline
  4437. notdeadline Check if there is no deadline
  4438. timestamp Check if there is a timestamp (also deadline or scheduled)
  4439. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4440. regexp Check if regexp matches
  4441. notregexp Check if regexp does not match.
  4442. todo Check if TODO keyword matches
  4443. nottodo Check if TODO keyword does not match
  4444. The regexp is taken from the conditions list, it must come right after
  4445. the `regexp' or `notregexp' element.
  4446. `todo' and `nottodo' accept as an argument a list of todo
  4447. keywords, which may include \"*\" to match any todo keyword.
  4448. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4449. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4450. Instead of a list, a keyword class may be given. For example:
  4451. (org-agenda-skip-entry-if 'nottodo 'done)
  4452. would skip entries that haven't been marked with any of \"DONE\"
  4453. keywords. Possible classes are: `todo', `done', `any'.
  4454. If any of these conditions is met, this function returns the end point of
  4455. the entity, causing the search to continue from there. This is a function
  4456. that can be put into `org-agenda-skip-function' for the duration of a command."
  4457. (let (beg end m)
  4458. (org-back-to-heading t)
  4459. (setq beg (point)
  4460. end (if subtree
  4461. (progn (org-end-of-subtree t) (point))
  4462. (progn (outline-next-heading) (1- (point)))))
  4463. (goto-char beg)
  4464. (and
  4465. (or
  4466. (and (memq 'scheduled conditions)
  4467. (re-search-forward org-scheduled-time-regexp end t))
  4468. (and (memq 'notscheduled conditions)
  4469. (not (re-search-forward org-scheduled-time-regexp end t)))
  4470. (and (memq 'deadline conditions)
  4471. (re-search-forward org-deadline-time-regexp end t))
  4472. (and (memq 'notdeadline conditions)
  4473. (not (re-search-forward org-deadline-time-regexp end t)))
  4474. (and (memq 'timestamp conditions)
  4475. (re-search-forward org-ts-regexp end t))
  4476. (and (memq 'nottimestamp conditions)
  4477. (not (re-search-forward org-ts-regexp end t)))
  4478. (and (setq m (memq 'regexp conditions))
  4479. (stringp (nth 1 m))
  4480. (re-search-forward (nth 1 m) end t))
  4481. (and (setq m (memq 'notregexp conditions))
  4482. (stringp (nth 1 m))
  4483. (not (re-search-forward (nth 1 m) end t)))
  4484. (and (or
  4485. (setq m (memq 'nottodo conditions))
  4486. (setq m (memq 'todo-unblocked conditions))
  4487. (setq m (memq 'nottodo-unblocked conditions))
  4488. (setq m (memq 'todo conditions)))
  4489. (org-agenda-skip-if-todo m end)))
  4490. end)))
  4491. (defun org-agenda-skip-if-todo (args end)
  4492. "Helper function for `org-agenda-skip-if', do not use it directly.
  4493. ARGS is a list with first element either `todo', `nottodo',
  4494. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4495. a list of TODO keywords, or a state symbol `todo' or `done' or
  4496. `any'."
  4497. (let ((kw (car args))
  4498. (arg (cadr args))
  4499. todo-wds todo-re)
  4500. (setq todo-wds
  4501. (org-uniquify
  4502. (cond
  4503. ((listp arg) ;; list of keywords
  4504. (if (member "*" arg)
  4505. (mapcar 'substring-no-properties org-todo-keywords-1)
  4506. arg))
  4507. ((symbolp arg) ;; keyword class name
  4508. (cond
  4509. ((eq arg 'todo)
  4510. (org-delete-all org-done-keywords
  4511. (mapcar 'substring-no-properties
  4512. org-todo-keywords-1)))
  4513. ((eq arg 'done) org-done-keywords)
  4514. ((eq arg 'any)
  4515. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4516. (setq todo-re
  4517. (concat "^\\*+[ \t]+\\<\\("
  4518. (mapconcat 'identity todo-wds "\\|")
  4519. "\\)\\>"))
  4520. (cond
  4521. ((eq kw 'todo) (re-search-forward todo-re end t))
  4522. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4523. ((eq kw 'todo-unblocked)
  4524. (catch 'unblocked
  4525. (while (re-search-forward todo-re end t)
  4526. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4527. nil))
  4528. ((eq kw 'nottodo-unblocked)
  4529. (catch 'unblocked
  4530. (while (re-search-forward todo-re end t)
  4531. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4532. t))
  4533. )))
  4534. ;;;###autoload
  4535. (defun org-agenda-list-stuck-projects (&rest ignore)
  4536. "Create agenda view for projects that are stuck.
  4537. Stuck projects are project that have no next actions. For the definitions
  4538. of what a project is and how to check if it stuck, customize the variable
  4539. `org-stuck-projects'."
  4540. (interactive)
  4541. (let* ((org-agenda-skip-function
  4542. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4543. ;; We could have used org-agenda-skip-if here.
  4544. (org-agenda-overriding-header
  4545. (or org-agenda-overriding-header "List of stuck projects: "))
  4546. (matcher (nth 0 org-stuck-projects))
  4547. (todo (nth 1 org-stuck-projects))
  4548. (todo-wds (if (member "*" todo)
  4549. (progn
  4550. (org-agenda-prepare-buffers (org-agenda-files
  4551. nil 'ifmode))
  4552. (org-delete-all
  4553. org-done-keywords-for-agenda
  4554. (copy-sequence org-todo-keywords-for-agenda)))
  4555. todo))
  4556. (todo-re (concat "^\\*+[ \t]+\\("
  4557. (mapconcat 'identity todo-wds "\\|")
  4558. "\\)\\>"))
  4559. (tags (nth 2 org-stuck-projects))
  4560. (tags-re (if (member "*" tags)
  4561. (concat org-outline-regexp-bol
  4562. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4563. (if tags
  4564. (concat org-outline-regexp-bol
  4565. ".*:\\("
  4566. (mapconcat 'identity tags "\\|")
  4567. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4568. (gen-re (nth 3 org-stuck-projects))
  4569. (re-list
  4570. (delq nil
  4571. (list
  4572. (if todo todo-re)
  4573. (if tags tags-re)
  4574. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4575. gen-re)))))
  4576. (setq org-agenda-skip-regexp
  4577. (if re-list
  4578. (mapconcat 'identity re-list "\\|")
  4579. (error "No information how to identify unstuck projects")))
  4580. (org-tags-view nil matcher)
  4581. (with-current-buffer org-agenda-buffer-name
  4582. (setq org-agenda-redo-command
  4583. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4584. (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
  4585. Create agenda view for projects that are stuck.
  4586. Stuck projects are project that have no next actions. For the definitions
  4587. of what a project is and how to check if it stuck, customize the variable
  4588. `org-stuck-projects'.
  4589. \(fn &rest IGNORE)" t nil)
  4590. ;;; Diary integration
  4591. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4592. (defvar diary-list-entries-hook)
  4593. (defvar diary-time-regexp)
  4594. (defun org-get-entries-from-diary (date)
  4595. "Get the (Emacs Calendar) diary entries for DATE."
  4596. (require 'diary-lib)
  4597. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4598. (diary-display-hook '(fancy-diary-display))
  4599. (diary-display-function 'fancy-diary-display)
  4600. (pop-up-frames nil)
  4601. (diary-list-entries-hook
  4602. (cons 'org-diary-default-entry diary-list-entries-hook))
  4603. (diary-file-name-prefix-function nil) ; turn this feature off
  4604. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4605. entries
  4606. (org-disable-agenda-to-diary t))
  4607. (save-excursion
  4608. (save-window-excursion
  4609. (funcall (if (fboundp 'diary-list-entries)
  4610. 'diary-list-entries 'list-diary-entries)
  4611. date 1)))
  4612. (if (not (get-buffer diary-fancy-buffer))
  4613. (setq entries nil)
  4614. (with-current-buffer diary-fancy-buffer
  4615. (setq buffer-read-only nil)
  4616. (if (zerop (buffer-size))
  4617. ;; No entries
  4618. (setq entries nil)
  4619. ;; Omit the date and other unnecessary stuff
  4620. (org-agenda-cleanup-fancy-diary)
  4621. ;; Add prefix to each line and extend the text properties
  4622. (if (zerop (buffer-size))
  4623. (setq entries nil)
  4624. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4625. (setq entries
  4626. (with-temp-buffer
  4627. (insert entries) (goto-char (point-min))
  4628. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4629. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4630. (replace-match (concat "; " (match-string 1)))))
  4631. (buffer-string)))))
  4632. (set-buffer-modified-p nil)
  4633. (kill-buffer diary-fancy-buffer)))
  4634. (when entries
  4635. (setq entries (org-split-string entries "\n"))
  4636. (setq entries
  4637. (mapcar
  4638. (lambda (x)
  4639. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4640. ;; Extend the text properties to the beginning of the line
  4641. (org-add-props x (text-properties-at (1- (length x)) x)
  4642. 'type "diary" 'date date 'face 'org-agenda-diary))
  4643. entries)))))
  4644. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4645. "Hook run when the fancy diary buffer is cleaned up.")
  4646. (defun org-agenda-cleanup-fancy-diary ()
  4647. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4648. This gets rid of the date, the underline under the date, and
  4649. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4650. date. It also removes lines that contain only whitespace."
  4651. (goto-char (point-min))
  4652. (if (looking-at ".*?:[ \t]*")
  4653. (progn
  4654. (replace-match "")
  4655. (re-search-forward "\n=+$" nil t)
  4656. (replace-match "")
  4657. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4658. (re-search-forward "\n=+$" nil t)
  4659. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4660. (goto-char (point-min))
  4661. (while (re-search-forward "^ +\n" nil t)
  4662. (replace-match ""))
  4663. (goto-char (point-min))
  4664. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4665. (replace-match ""))
  4666. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4667. ;; Make sure entries from the diary have the right text properties.
  4668. (eval-after-load "diary-lib"
  4669. '(if (boundp 'diary-modify-entry-list-string-function)
  4670. ;; We can rely on the hook, nothing to do
  4671. nil
  4672. ;; Hook not available, must use advice to make this work
  4673. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4674. "Make the position visible."
  4675. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4676. (stringp string)
  4677. buffer-file-name)
  4678. (setq string (org-modify-diary-entry-string string))))))
  4679. (defun org-modify-diary-entry-string (string)
  4680. "Add text properties to string, allowing org-mode to act on it."
  4681. (org-add-props string nil
  4682. 'mouse-face 'highlight
  4683. 'help-echo (if buffer-file-name
  4684. (format "mouse-2 or RET jump to diary file %s"
  4685. (abbreviate-file-name buffer-file-name))
  4686. "")
  4687. 'org-agenda-diary-link t
  4688. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4689. (defun org-diary-default-entry ()
  4690. "Add a dummy entry to the diary.
  4691. Needed to avoid empty dates which mess up holiday display."
  4692. ;; Catch the error if dealing with the new add-to-diary-alist
  4693. (when org-disable-agenda-to-diary
  4694. (condition-case nil
  4695. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4696. (error
  4697. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4698. (defun org-add-to-diary-list (&rest args)
  4699. (if (fboundp 'diary-add-to-list)
  4700. (apply 'diary-add-to-list args)
  4701. (apply 'add-to-diary-list args)))
  4702. (defvar org-diary-last-run-time nil)
  4703. ;;;###autoload
  4704. (defun org-diary (&rest args)
  4705. "Return diary information from org files.
  4706. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4707. It accesses org files and extracts information from those files to be
  4708. listed in the diary. The function accepts arguments specifying what
  4709. items should be listed. For a list of arguments allowed here, see the
  4710. variable `org-agenda-entry-types'.
  4711. The call in the diary file should look like this:
  4712. &%%(org-diary) ~/path/to/some/orgfile.org
  4713. Use a separate line for each org file to check. Or, if you omit the file name,
  4714. all files listed in `org-agenda-files' will be checked automatically:
  4715. &%%(org-diary)
  4716. If you don't give any arguments (as in the example above), the default
  4717. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4718. So the example above may also be written as
  4719. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4720. The function expects the lisp variables `entry' and `date' to be provided
  4721. by the caller, because this is how the calendar works. Don't use this
  4722. function from a program - use `org-agenda-get-day-entries' instead."
  4723. (when (> (- (org-float-time)
  4724. org-agenda-last-marker-time)
  4725. 5)
  4726. ;; I am not sure if this works with sticky agendas, because the marker
  4727. ;; list is then no longer a global variable.
  4728. (org-agenda-reset-markers))
  4729. (org-compile-prefix-format 'agenda)
  4730. (org-set-sorting-strategy 'agenda)
  4731. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4732. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4733. (list entry)
  4734. (org-agenda-files t)))
  4735. (time (org-float-time))
  4736. file rtn results)
  4737. (when (or (not org-diary-last-run-time)
  4738. (> (- time
  4739. org-diary-last-run-time)
  4740. 3))
  4741. (org-agenda-prepare-buffers files))
  4742. (setq org-diary-last-run-time time)
  4743. ;; If this is called during org-agenda, don't return any entries to
  4744. ;; the calendar. Org Agenda will list these entries itself.
  4745. (if org-disable-agenda-to-diary (setq files nil))
  4746. (while (setq file (pop files))
  4747. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4748. (setq results (append results rtn)))
  4749. (if results
  4750. (concat (org-agenda-finalize-entries results) "\n"))))
  4751. (autoload 'org-diary "org-agenda" "\
  4752. Return diary information from org files.
  4753. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4754. It accesses org files and extracts information from those files to be
  4755. listed in the diary. The function accepts arguments specifying what
  4756. items should be listed. For a list of arguments allowed here, see the
  4757. variable `org-agenda-entry-types'.
  4758. The call in the diary file should look like this:
  4759. &%%(org-diary) ~/path/to/some/orgfile.org
  4760. Use a separate line for each org file to check. Or, if you omit the file name,
  4761. all files listed in `org-agenda-files' will be checked automatically:
  4762. &%%(org-diary)
  4763. If you don't give any arguments (as in the example above), the default
  4764. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4765. So the example above may also be written as
  4766. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4767. The function expects the lisp variables `entry' and `date' to be provided
  4768. by the caller, because this is how the calendar works. Don't use this
  4769. function from a program - use `org-agenda-get-day-entries' instead.
  4770. \(fn &rest ARGS)" nil nil)
  4771. ;;; Agenda entry finders
  4772. (defun org-agenda-get-day-entries (file date &rest args)
  4773. "Does the work for `org-diary' and `org-agenda'.
  4774. FILE is the path to a file to be checked for entries. DATE is date like
  4775. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4776. which kind of entries should be extracted. For details about these, see
  4777. the documentation of `org-diary'."
  4778. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4779. (let* ((org-startup-folded nil)
  4780. (org-startup-align-all-tables nil)
  4781. (buffer (if (file-exists-p file)
  4782. (org-get-agenda-file-buffer file)
  4783. (error "No such file %s" file)))
  4784. arg results rtn deadline-results)
  4785. (if (not buffer)
  4786. ;; If file does not exist, make sure an error message ends up in diary
  4787. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4788. (with-current-buffer buffer
  4789. (unless (derived-mode-p 'org-mode)
  4790. (error "Agenda file %s is not in `org-mode'" file))
  4791. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4792. (let ((case-fold-search nil))
  4793. (save-excursion
  4794. (save-restriction
  4795. (if org-agenda-restrict
  4796. (narrow-to-region org-agenda-restrict-begin
  4797. org-agenda-restrict-end)
  4798. (widen))
  4799. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4800. (while (setq arg (pop args))
  4801. (cond
  4802. ((and (eq arg :todo)
  4803. (equal date (calendar-gregorian-from-absolute
  4804. (org-today))))
  4805. (setq rtn (org-agenda-get-todos))
  4806. (setq results (append results rtn)))
  4807. ((eq arg :timestamp)
  4808. (setq rtn (org-agenda-get-blocks))
  4809. (setq results (append results rtn))
  4810. (setq rtn (org-agenda-get-timestamps deadline-results))
  4811. (setq results (append results rtn)))
  4812. ((eq arg :sexp)
  4813. (setq rtn (org-agenda-get-sexps))
  4814. (setq results (append results rtn)))
  4815. ((eq arg :scheduled)
  4816. (setq rtn (org-agenda-get-scheduled deadline-results))
  4817. (setq results (append results rtn)))
  4818. ((eq arg :closed)
  4819. (setq rtn (org-agenda-get-progress))
  4820. (setq results (append results rtn)))
  4821. ((eq arg :deadline)
  4822. (setq rtn (org-agenda-get-deadlines))
  4823. (setq deadline-results (copy-sequence rtn))
  4824. (setq results (append results rtn))))))))
  4825. results))))
  4826. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4827. (defun org-agenda-get-todos ()
  4828. "Return the TODO information for agenda display."
  4829. (let* ((props (list 'face nil
  4830. 'done-face 'org-agenda-done
  4831. 'org-not-done-regexp org-not-done-regexp
  4832. 'org-todo-regexp org-todo-regexp
  4833. 'org-complex-heading-regexp org-complex-heading-regexp
  4834. 'mouse-face 'highlight
  4835. 'help-echo
  4836. (format "mouse-2 or RET jump to org file %s"
  4837. (abbreviate-file-name buffer-file-name))))
  4838. (regexp (format org-heading-keyword-regexp-format
  4839. (cond
  4840. ((and org-select-this-todo-keyword
  4841. (equal org-select-this-todo-keyword "*"))
  4842. org-todo-regexp)
  4843. (org-select-this-todo-keyword
  4844. (concat "\\("
  4845. (mapconcat 'identity
  4846. (org-split-string
  4847. org-select-this-todo-keyword
  4848. "|")
  4849. "\\|") "\\)"))
  4850. (t org-not-done-regexp))))
  4851. marker priority category category-pos level tags todo-state
  4852. ee txt beg end)
  4853. (goto-char (point-min))
  4854. (while (re-search-forward regexp nil t)
  4855. (catch :skip
  4856. (save-match-data
  4857. (beginning-of-line)
  4858. (org-agenda-skip)
  4859. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4860. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4861. (goto-char (1+ beg))
  4862. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4863. (throw :skip nil)))
  4864. (goto-char (match-beginning 2))
  4865. (setq marker (org-agenda-new-marker (match-beginning 0))
  4866. category (org-get-category)
  4867. category-pos (get-text-property (point) 'org-category-position)
  4868. txt (org-trim
  4869. (buffer-substring (match-beginning 2) (match-end 0)))
  4870. tags (org-get-tags-at nil t)
  4871. level (make-string (org-reduced-level (org-outline-level)) ? )
  4872. txt (org-agenda-format-item "" txt level category tags t)
  4873. priority (1+ (org-get-priority txt))
  4874. todo-state (org-get-todo-state))
  4875. (org-add-props txt props
  4876. 'org-marker marker 'org-hd-marker marker
  4877. 'priority priority 'org-category category
  4878. 'level level
  4879. 'org-category-position category-pos
  4880. 'type "todo" 'todo-state todo-state)
  4881. (push txt ee)
  4882. (if org-agenda-todo-list-sublevels
  4883. (goto-char (match-end 2))
  4884. (org-end-of-subtree 'invisible))))
  4885. (nreverse ee)))
  4886. (defun org-agenda-todo-custom-ignore-p (time n)
  4887. "Check whether timestamp is farther away than n number of days.
  4888. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4889. `org-agenda-todo-ignore-scheduled' or
  4890. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4891. (let ((days (org-time-stamp-to-now
  4892. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4893. (if (>= n 0)
  4894. (>= days n)
  4895. (<= days n))))
  4896. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4897. (&optional end)
  4898. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4899. (when (or org-agenda-todo-ignore-with-date
  4900. org-agenda-todo-ignore-scheduled
  4901. org-agenda-todo-ignore-deadlines
  4902. org-agenda-todo-ignore-timestamp)
  4903. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4904. (save-excursion
  4905. (or (and org-agenda-todo-ignore-with-date
  4906. (re-search-forward org-ts-regexp end t))
  4907. (and org-agenda-todo-ignore-scheduled
  4908. (re-search-forward org-scheduled-time-regexp end t)
  4909. (cond
  4910. ((eq org-agenda-todo-ignore-scheduled 'future)
  4911. (> (org-time-stamp-to-now
  4912. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4913. ((eq org-agenda-todo-ignore-scheduled 'past)
  4914. (<= (org-time-stamp-to-now
  4915. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4916. ((numberp org-agenda-todo-ignore-scheduled)
  4917. (org-agenda-todo-custom-ignore-p
  4918. (match-string 1) org-agenda-todo-ignore-scheduled))
  4919. (t)))
  4920. (and org-agenda-todo-ignore-deadlines
  4921. (re-search-forward org-deadline-time-regexp end t)
  4922. (cond
  4923. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4924. ((eq org-agenda-todo-ignore-deadlines 'far)
  4925. (not (org-deadline-close (match-string 1))))
  4926. ((eq org-agenda-todo-ignore-deadlines 'future)
  4927. (> (org-time-stamp-to-now
  4928. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4929. ((eq org-agenda-todo-ignore-deadlines 'past)
  4930. (<= (org-time-stamp-to-now
  4931. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4932. ((numberp org-agenda-todo-ignore-deadlines)
  4933. (org-agenda-todo-custom-ignore-p
  4934. (match-string 1) org-agenda-todo-ignore-deadlines))
  4935. (t (org-deadline-close (match-string 1)))))
  4936. (and org-agenda-todo-ignore-timestamp
  4937. (let ((buffer (current-buffer))
  4938. (regexp
  4939. (concat
  4940. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4941. (start (point)))
  4942. ;; Copy current buffer into a temporary one
  4943. (with-temp-buffer
  4944. (insert-buffer-substring buffer start end)
  4945. (goto-char (point-min))
  4946. ;; Delete SCHEDULED and DEADLINE items
  4947. (while (re-search-forward regexp end t)
  4948. (delete-region (match-beginning 0) (match-end 0)))
  4949. (goto-char (point-min))
  4950. ;; No search for timestamp left
  4951. (when (re-search-forward org-ts-regexp nil t)
  4952. (cond
  4953. ((eq org-agenda-todo-ignore-timestamp 'future)
  4954. (> (org-time-stamp-to-now
  4955. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4956. ((eq org-agenda-todo-ignore-timestamp 'past)
  4957. (<= (org-time-stamp-to-now
  4958. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4959. ((numberp org-agenda-todo-ignore-timestamp)
  4960. (org-agenda-todo-custom-ignore-p
  4961. (match-string 1) org-agenda-todo-ignore-timestamp))
  4962. (t))))))))))
  4963. (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
  4964. Do we have a reason to ignore this TODO entry because it has a time stamp?
  4965. \(fn &optional END)" nil nil)
  4966. (defconst org-agenda-no-heading-message
  4967. "No heading for this item in buffer or region.")
  4968. (defun org-agenda-get-timestamps (&optional deadline-results)
  4969. "Return the date stamp information for agenda display."
  4970. (let* ((props (list 'face 'org-agenda-calendar-event
  4971. 'org-not-done-regexp org-not-done-regexp
  4972. 'org-todo-regexp org-todo-regexp
  4973. 'org-complex-heading-regexp org-complex-heading-regexp
  4974. 'mouse-face 'highlight
  4975. 'help-echo
  4976. (format "mouse-2 or RET jump to org file %s"
  4977. (abbreviate-file-name buffer-file-name))))
  4978. (d1 (calendar-absolute-from-gregorian date))
  4979. mm
  4980. (deadline-position-alist
  4981. (mapcar (lambda (a) (and (setq mm (get-text-property
  4982. 0 'org-hd-marker a))
  4983. (cons (marker-position mm) a)))
  4984. deadline-results))
  4985. (remove-re org-ts-regexp)
  4986. (regexp
  4987. (concat
  4988. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4989. (regexp-quote
  4990. (substring
  4991. (format-time-string
  4992. (car org-time-stamp-formats)
  4993. (apply 'encode-time ; DATE bound by calendar
  4994. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4995. 1 11))
  4996. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4997. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4998. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4999. donep tmp priority category category-pos level ee txt timestr tags
  5000. b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
  5001. (goto-char (point-min))
  5002. (while (setq end-of-match (re-search-forward regexp nil t))
  5003. (setq b0 (match-beginning 0)
  5004. b3 (match-beginning 3) e3 (match-end 3)
  5005. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5006. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5007. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5008. (member todo-state
  5009. org-agenda-repeating-timestamp-show-all)))
  5010. (catch :skip
  5011. (and (org-at-date-range-p) (throw :skip nil))
  5012. (org-agenda-skip)
  5013. (if (and (match-end 1)
  5014. (not (= d1 (org-time-string-to-absolute
  5015. (match-string 1) d1 nil show-all
  5016. (current-buffer) b0))))
  5017. (throw :skip nil))
  5018. (if (and e3
  5019. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5020. (throw :skip nil))
  5021. (setq tmp (buffer-substring (max (point-min)
  5022. (- b0 org-ds-keyword-length))
  5023. b0)
  5024. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5025. inactivep (= (char-after b0) ?\[)
  5026. deadlinep (string-match org-deadline-regexp tmp)
  5027. scheduledp (string-match org-scheduled-regexp tmp)
  5028. closedp (and org-agenda-include-inactive-timestamps
  5029. (string-match org-closed-string tmp))
  5030. clockp (and org-agenda-include-inactive-timestamps
  5031. (or (string-match org-clock-string tmp)
  5032. (string-match "]-+\\'" tmp)))
  5033. warntime (get-text-property (point) 'org-appt-warntime)
  5034. donep (member todo-state org-done-keywords))
  5035. (if (or scheduledp deadlinep closedp clockp
  5036. (and donep org-agenda-skip-timestamp-if-done))
  5037. (throw :skip t))
  5038. (if (string-match ">" timestr)
  5039. ;; substring should only run to end of time stamp
  5040. (setq timestr (substring timestr 0 (match-end 0))))
  5041. (setq marker (org-agenda-new-marker b0)
  5042. category (org-get-category b0)
  5043. category-pos (get-text-property b0 'org-category-position))
  5044. (save-excursion
  5045. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5046. (setq txt org-agenda-no-heading-message)
  5047. (goto-char (match-beginning 0))
  5048. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5049. (assoc (point) deadline-position-alist))
  5050. (throw :skip nil))
  5051. (setq hdmarker (org-agenda-new-marker)
  5052. tags (org-get-tags-at nil t)
  5053. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5054. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5055. (setq head (or (match-string 1) ""))
  5056. (setq txt (org-agenda-format-item
  5057. (if inactivep org-agenda-inactive-leader nil)
  5058. head level category tags timestr
  5059. remove-re habitp)))
  5060. (setq priority (org-get-priority txt))
  5061. (org-add-props txt props 'priority priority
  5062. 'org-marker marker 'org-hd-marker hdmarker
  5063. 'org-category category 'date date
  5064. 'level level
  5065. 'org-category-position category-pos
  5066. 'todo-state todo-state
  5067. 'warntime warntime
  5068. 'type "timestamp")
  5069. (push txt ee))
  5070. (if org-agenda-skip-additional-timestamps-same-entry
  5071. (outline-next-heading)
  5072. (goto-char end-of-match))))
  5073. (nreverse ee)))
  5074. (defun org-agenda-get-sexps ()
  5075. "Return the sexp information for agenda display."
  5076. (require 'diary-lib)
  5077. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5078. 'mouse-face 'highlight
  5079. 'help-echo
  5080. (format "mouse-2 or RET jump to org file %s"
  5081. (abbreviate-file-name buffer-file-name))))
  5082. (regexp "^&?%%(")
  5083. marker category extra category-pos level ee txt tags entry
  5084. result beg b sexp sexp-entry todo-state warntime)
  5085. (goto-char (point-min))
  5086. (while (re-search-forward regexp nil t)
  5087. (catch :skip
  5088. (org-agenda-skip)
  5089. (setq beg (match-beginning 0))
  5090. (goto-char (1- (match-end 0)))
  5091. (setq b (point))
  5092. (forward-sexp 1)
  5093. (setq sexp (buffer-substring b (point)))
  5094. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5095. (org-trim (match-string 1))
  5096. ""))
  5097. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5098. (when result
  5099. (setq marker (org-agenda-new-marker beg)
  5100. level (make-string (org-reduced-level (org-outline-level)) ? )
  5101. category (org-get-category beg)
  5102. category-pos (get-text-property beg 'org-category-position)
  5103. tags (save-excursion (org-back-to-heading t) (org-get-tags-at nil t))
  5104. todo-state (org-get-todo-state)
  5105. warntime (get-text-property (point) 'org-appt-warntime)
  5106. extra nil)
  5107. (dolist (r (if (stringp result)
  5108. (list result)
  5109. result)) ;; we expect a list here
  5110. (when (and org-agenda-diary-sexp-prefix
  5111. (string-match org-agenda-diary-sexp-prefix r))
  5112. (setq extra (match-string 0 r)
  5113. r (replace-match "" nil nil r)))
  5114. (if (string-match "\\S-" r)
  5115. (setq txt r)
  5116. (setq txt "SEXP entry returned empty string"))
  5117. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5118. (org-add-props txt props 'org-marker marker
  5119. 'org-category category 'date date 'todo-state todo-state
  5120. 'org-category-position category-pos 'tags tags
  5121. 'level level
  5122. 'type "sexp" 'warntime warntime)
  5123. (push txt ee)))))
  5124. (nreverse ee)))
  5125. ;; Calendar sanity: define some functions that are independent of
  5126. ;; `calendar-date-style'.
  5127. ;; Normally I would like to use ISO format when calling the diary functions,
  5128. ;; but to make sure we still have Emacs 22 compatibility we bind
  5129. ;; also `european-calendar-style' and use european format
  5130. (defun org-anniversary (year month day &optional mark)
  5131. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5132. (org-no-warnings
  5133. (let ((calendar-date-style 'european) (european-calendar-style t))
  5134. (diary-anniversary day month year mark))))
  5135. (defun org-cyclic (N year month day &optional mark)
  5136. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5137. (org-no-warnings
  5138. (let ((calendar-date-style 'european) (european-calendar-style t))
  5139. (diary-cyclic N day month year mark))))
  5140. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5141. "Like `diary-block', but with fixed (ISO) order of arguments."
  5142. (org-no-warnings
  5143. (let ((calendar-date-style 'european) (european-calendar-style t))
  5144. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5145. (defun org-date (year month day &optional mark)
  5146. "Like `diary-date', but with fixed (ISO) order of arguments."
  5147. (org-no-warnings
  5148. (let ((calendar-date-style 'european) (european-calendar-style t))
  5149. (diary-date day month year mark))))
  5150. ;; Define the` org-class' function
  5151. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5152. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5153. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5154. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5155. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5156. `holidays', then any date that is known by the Emacs calendar to be a
  5157. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5158. then those holidays will be skipped."
  5159. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5160. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5161. (d (calendar-absolute-from-gregorian date))
  5162. (h (when skip-weeks (calendar-check-holidays date))))
  5163. (and
  5164. (<= date1 d)
  5165. (<= d date2)
  5166. (= (calendar-day-of-week date) dayname)
  5167. (or (not skip-weeks)
  5168. (progn
  5169. (require 'cal-iso)
  5170. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5171. (not (or (and h (memq 'holidays skip-weeks))
  5172. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5173. entry)))
  5174. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5175. "Like `org-class', but honor `calendar-date-style'.
  5176. The order of the first 2 times 3 arguments depends on the variable
  5177. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5178. So for American calendars, give this as MONTH DAY YEAR, for European as
  5179. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5180. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5181. is any number of ISO weeks in the block period for which the item should
  5182. be skipped.
  5183. This function is here only for backward compatibility and it is deprecated,
  5184. please use `org-class' instead."
  5185. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5186. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5187. (org-class
  5188. (nth 2 date1) (car date1) (nth 1 date1)
  5189. (nth 2 date2) (car date2) (nth 1 date2)
  5190. dayname skip-weeks)))
  5191. (make-obsolete 'org-diary-class 'org-class "")
  5192. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5193. (defalias 'org-get-closed 'org-agenda-get-progress)
  5194. (defun org-agenda-get-progress ()
  5195. "Return the logged TODO entries for agenda display."
  5196. (let* ((props (list 'mouse-face 'highlight
  5197. 'org-not-done-regexp org-not-done-regexp
  5198. 'org-todo-regexp org-todo-regexp
  5199. 'org-complex-heading-regexp org-complex-heading-regexp
  5200. 'help-echo
  5201. (format "mouse-2 or RET jump to org file %s"
  5202. (abbreviate-file-name buffer-file-name))))
  5203. (items (if (consp org-agenda-show-log-scoped)
  5204. org-agenda-show-log-scoped
  5205. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5206. '(clock)
  5207. org-agenda-log-mode-items)))
  5208. (parts
  5209. (delq nil
  5210. (list
  5211. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5212. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5213. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5214. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5215. (error "`org-agenda-log-mode-items' is empty")))
  5216. (regexp (concat
  5217. "\\(" parts-re "\\)"
  5218. " *\\["
  5219. (regexp-quote
  5220. (substring
  5221. (format-time-string
  5222. (car org-time-stamp-formats)
  5223. (apply 'encode-time ; DATE bound by calendar
  5224. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5225. 1 11))))
  5226. (org-agenda-search-headline-for-time nil)
  5227. marker hdmarker priority category category-pos level tags closedp
  5228. statep clockp state ee txt extra timestr rest clocked)
  5229. (goto-char (point-min))
  5230. (while (re-search-forward regexp nil t)
  5231. (catch :skip
  5232. (org-agenda-skip)
  5233. (setq marker (org-agenda-new-marker (match-beginning 0))
  5234. closedp (equal (match-string 1) org-closed-string)
  5235. statep (equal (string-to-char (match-string 1)) ?-)
  5236. clockp (not (or closedp statep))
  5237. state (and statep (match-string 2))
  5238. category (org-get-category (match-beginning 0))
  5239. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5240. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5241. (when (string-match "\\]" timestr)
  5242. ;; substring should only run to end of time stamp
  5243. (setq rest (substring timestr (match-end 0))
  5244. timestr (substring timestr 0 (match-end 0)))
  5245. (if (and (not closedp) (not statep)
  5246. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5247. rest))
  5248. (progn (setq timestr (concat (substring timestr 0 -1)
  5249. "-" (match-string 1 rest) "]"))
  5250. (setq clocked (match-string 2 rest)))
  5251. (setq clocked "-")))
  5252. (save-excursion
  5253. (setq extra
  5254. (cond
  5255. ((not org-agenda-log-mode-add-notes) nil)
  5256. (statep
  5257. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5258. (match-string 1)))
  5259. (clockp
  5260. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5261. (match-string 1)))))
  5262. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5263. (setq txt org-agenda-no-heading-message)
  5264. (goto-char (match-beginning 0))
  5265. (setq hdmarker (org-agenda-new-marker)
  5266. tags (org-get-tags-at nil t)
  5267. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5268. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5269. (setq txt (match-string 1))
  5270. (when extra
  5271. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5272. (setq txt (concat (substring txt 0 (match-beginning 1))
  5273. " - " extra " " (match-string 2 txt)))
  5274. (setq txt (concat txt " - " extra))))
  5275. (setq txt (org-agenda-format-item
  5276. (cond
  5277. (closedp "Closed: ")
  5278. (statep (concat "State: (" state ")"))
  5279. (t (concat "Clocked: (" clocked ")")))
  5280. txt level category tags timestr)))
  5281. (setq priority 100000)
  5282. (org-add-props txt props
  5283. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5284. 'priority priority 'org-category category
  5285. 'org-category-position category-pos
  5286. 'level level
  5287. 'type "closed" 'date date
  5288. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5289. (push txt ee))
  5290. (goto-char (point-at-eol))))
  5291. (nreverse ee)))
  5292. (defun org-agenda-show-clocking-issues ()
  5293. "Add overlays, showing issues with clocking.
  5294. See also the user option `org-agenda-clock-consistency-checks'."
  5295. (interactive)
  5296. (let* ((pl org-agenda-clock-consistency-checks)
  5297. (re (concat "^[ \t]*"
  5298. org-clock-string
  5299. "[ \t]+"
  5300. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5301. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5302. (tlstart 0.)
  5303. (tlend 0.)
  5304. (maxtime (org-hh:mm-string-to-minutes
  5305. (or (plist-get pl :max-duration) "24:00")))
  5306. (mintime (org-hh:mm-string-to-minutes
  5307. (or (plist-get pl :min-duration) 0)))
  5308. (maxgap (org-hh:mm-string-to-minutes
  5309. ;; default 30:00 means never complain
  5310. (or (plist-get pl :max-gap) "30:00")))
  5311. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5312. (plist-get pl :gap-ok-around)))
  5313. (def-face (or (plist-get pl :default-face)
  5314. '((:background "DarkRed") (:foreground "white"))))
  5315. issue face m te ts dt ov)
  5316. (goto-char (point-min))
  5317. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5318. (setq issue nil face def-face)
  5319. (catch 'next
  5320. (setq m (org-get-at-bol 'org-marker)
  5321. te nil ts nil)
  5322. (unless (and m (markerp m))
  5323. (setq issue "No valid clock line") (throw 'next t))
  5324. (org-with-point-at m
  5325. (save-excursion
  5326. (goto-char (point-at-bol))
  5327. (unless (looking-at re)
  5328. (error "No valid Clock line")
  5329. (throw 'next t))
  5330. (unless (match-end 3)
  5331. (setq issue "No end time"
  5332. face (or (plist-get pl :no-end-time-face) face))
  5333. (throw 'next t))
  5334. (setq ts (match-string 1)
  5335. te (match-string 3)
  5336. ts (org-float-time
  5337. (apply 'encode-time (org-parse-time-string ts)))
  5338. te (org-float-time
  5339. (apply 'encode-time (org-parse-time-string te)))
  5340. dt (- te ts))))
  5341. (cond
  5342. ((> dt (* 60 maxtime))
  5343. ;; a very long clocking chunk
  5344. (setq issue (format "Clocking interval is very long: %s"
  5345. (org-minutes-to-clocksum-string
  5346. (floor (/ (float dt) 60.))))
  5347. face (or (plist-get pl :long-face) face)))
  5348. ((< dt (* 60 mintime))
  5349. ;; a very short clocking chunk
  5350. (setq issue (format "Clocking interval is very short: %s"
  5351. (org-minutes-to-clocksum-string
  5352. (floor (/ (float dt) 60.))))
  5353. face (or (plist-get pl :short-face) face)))
  5354. ((and (> tlend 0) (< ts tlend))
  5355. ;; Two clock entries are overlapping
  5356. (setq issue (format "Clocking overlap: %d minutes"
  5357. (/ (- tlend ts) 60))
  5358. face (or (plist-get pl :overlap-face) face)))
  5359. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5360. ;; There is a gap, lets see if we need to report it
  5361. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5362. (setq issue (format "Clocking gap: %d minutes"
  5363. (/ (- ts tlend) 60))
  5364. face (or (plist-get pl :gap-face) face))))
  5365. (t nil)))
  5366. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5367. (when issue
  5368. ;; OK, there was some issue, add an overlay to show the issue
  5369. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5370. (overlay-put ov 'before-string
  5371. (concat
  5372. (org-add-props
  5373. (format "%-43s" (concat " " issue))
  5374. nil
  5375. 'face face)
  5376. "\n"))
  5377. (overlay-put ov 'evaporate t)))))
  5378. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5379. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5380. (catch 'exit
  5381. (unless ok-list
  5382. ;; there are no OK times for gaps...
  5383. (throw 'exit nil))
  5384. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5385. ;; This is more than 24 hours, so it is OK.
  5386. ;; because we have at least one OK time, that must be in the
  5387. ;; 24 hour interval.
  5388. (throw 'exit t))
  5389. ;; We have a shorter gap.
  5390. ;; Now we have to get the minute of the day when these times are
  5391. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5392. (t2dec (decode-time (seconds-to-time t2)))
  5393. ;; compute the minute on the day
  5394. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5395. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5396. (when (< min2 min1)
  5397. ;; if min2 is smaller than min1, this means it is on the next day.
  5398. ;; Wrap it to after midnight.
  5399. (setq min2 (+ min2 1440)))
  5400. ;; Now check if any of the OK times is in the gap
  5401. (mapc (lambda (x)
  5402. ;; Wrap the time to after midnight if necessary
  5403. (if (< x min1) (setq x (+ x 1440)))
  5404. ;; Check if in interval
  5405. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5406. ok-list)
  5407. ;; Nope, this gap is not OK
  5408. nil)))
  5409. (defun org-agenda-get-deadlines ()
  5410. "Return the deadline information for agenda display."
  5411. (let* ((props (list 'mouse-face 'highlight
  5412. 'org-not-done-regexp org-not-done-regexp
  5413. 'org-todo-regexp org-todo-regexp
  5414. 'org-complex-heading-regexp org-complex-heading-regexp
  5415. 'help-echo
  5416. (format "mouse-2 or RET jump to org file %s"
  5417. (abbreviate-file-name buffer-file-name))))
  5418. (regexp org-deadline-time-regexp)
  5419. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5420. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5421. d2 diff dfrac wdays pos pos1 category category-pos level
  5422. tags suppress-prewarning ee txt head face s todo-state
  5423. show-all upcomingp donep timestr warntime)
  5424. (goto-char (point-min))
  5425. (while (re-search-forward regexp nil t)
  5426. (catch :skip
  5427. (org-agenda-skip)
  5428. (setq s (match-string 1)
  5429. txt nil
  5430. pos (1- (match-beginning 1))
  5431. todo-state (save-match-data (org-get-todo-state))
  5432. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5433. (member todo-state
  5434. org-agenda-repeating-timestamp-show-all))
  5435. d2 (org-time-string-to-absolute
  5436. (match-string 1) d1 'past show-all
  5437. (current-buffer) pos)
  5438. diff (- d2 d1))
  5439. (setq suppress-prewarning
  5440. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5441. (let ((item (buffer-substring (point-at-bol)
  5442. (point-at-eol))))
  5443. (save-match-data
  5444. (and (string-match
  5445. org-scheduled-time-regexp item)
  5446. (match-string 1 item)))))))
  5447. (cond
  5448. ((not ds) nil)
  5449. ;; The current item has a scheduled date (in ds), so
  5450. ;; evaluate its prewarning lead time.
  5451. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5452. ;; Use global prewarning-restart lead time.
  5453. org-agenda-skip-deadline-prewarning-if-scheduled)
  5454. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5455. 'pre-scheduled)
  5456. ;; Set prewarning to no earlier than scheduled.
  5457. (min (- d2 (org-time-string-to-absolute
  5458. ds d1 'past show-all (current-buffer) pos))
  5459. org-deadline-warning-days))
  5460. ;; Set prewarning to deadline.
  5461. (t 0))))
  5462. (setq wdays (if suppress-prewarning
  5463. (let ((org-deadline-warning-days suppress-prewarning))
  5464. (org-get-wdays s))
  5465. (org-get-wdays s))
  5466. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5467. upcomingp (and todayp (> diff 0)))
  5468. ;; When to show a deadline in the calendar:
  5469. ;; If the expiration is within wdays warning time.
  5470. ;; Past-due deadlines are only shown on the current date
  5471. (if (and (or (and (<= diff wdays)
  5472. (and todayp (not org-agenda-only-exact-dates)))
  5473. (= diff 0)))
  5474. (save-excursion
  5475. ;; (setq todo-state (org-get-todo-state))
  5476. (setq donep (member todo-state org-done-keywords))
  5477. (if (and donep
  5478. (or org-agenda-skip-deadline-if-done
  5479. (not (= diff 0))))
  5480. (setq txt nil)
  5481. (setq category (org-get-category)
  5482. warntime (get-text-property (point) 'org-appt-warntime)
  5483. category-pos (get-text-property (point) 'org-category-position))
  5484. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5485. (setq txt org-agenda-no-heading-message)
  5486. (goto-char (match-end 0))
  5487. (setq pos1 (match-beginning 0))
  5488. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5489. (setq tags (org-get-tags-at pos1 t))
  5490. (setq head (buffer-substring-no-properties
  5491. (point)
  5492. (progn (skip-chars-forward "^\r\n")
  5493. (point))))
  5494. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5495. (setq timestr
  5496. (concat (substring s (match-beginning 1)) " "))
  5497. (setq timestr 'time))
  5498. (setq txt (org-agenda-format-item
  5499. (if (= diff 0)
  5500. (car org-agenda-deadline-leaders)
  5501. (if (functionp
  5502. (nth 1 org-agenda-deadline-leaders))
  5503. (funcall
  5504. (nth 1 org-agenda-deadline-leaders)
  5505. diff date)
  5506. (format (nth 1 org-agenda-deadline-leaders)
  5507. diff)))
  5508. head level category tags
  5509. (if (not (= diff 0)) nil timestr)))))
  5510. (when txt
  5511. (setq face (org-agenda-deadline-face dfrac))
  5512. (org-add-props txt props
  5513. 'org-marker (org-agenda-new-marker pos)
  5514. 'warntime warntime
  5515. 'level level
  5516. 'org-hd-marker (org-agenda-new-marker pos1)
  5517. 'priority (+ (- diff)
  5518. (org-get-priority txt))
  5519. 'org-category category
  5520. 'org-category-position category-pos
  5521. 'todo-state todo-state
  5522. 'type (if upcomingp "upcoming-deadline" "deadline")
  5523. 'date (if upcomingp date d2)
  5524. 'face (if donep 'org-agenda-done face)
  5525. 'undone-face face 'done-face 'org-agenda-done)
  5526. (push txt ee))))))
  5527. (nreverse ee)))
  5528. (defun org-agenda-deadline-face (fraction)
  5529. "Return the face to displaying a deadline item.
  5530. FRACTION is what fraction of the head-warning time has passed."
  5531. (let ((faces org-agenda-deadline-faces) f)
  5532. (catch 'exit
  5533. (while (setq f (pop faces))
  5534. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5535. (defun org-agenda-get-scheduled (&optional deadline-results)
  5536. "Return the scheduled information for agenda display."
  5537. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5538. 'org-todo-regexp org-todo-regexp
  5539. 'org-complex-heading-regexp org-complex-heading-regexp
  5540. 'done-face 'org-agenda-done
  5541. 'mouse-face 'highlight
  5542. 'help-echo
  5543. (format "mouse-2 or RET jump to org file %s"
  5544. (abbreviate-file-name buffer-file-name))))
  5545. (regexp org-scheduled-time-regexp)
  5546. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5547. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5548. mm
  5549. (deadline-position-alist
  5550. (mapcar (lambda (a) (and (setq mm (get-text-property
  5551. 0 'org-hd-marker a))
  5552. (cons (marker-position mm) a)))
  5553. deadline-results))
  5554. d2 diff pos pos1 category category-pos level tags donep
  5555. ee txt head pastschedp todo-state face timestr s habitp show-all
  5556. did-habit-check-p warntime)
  5557. (goto-char (point-min))
  5558. (while (re-search-forward regexp nil t)
  5559. (catch :skip
  5560. (org-agenda-skip)
  5561. (setq s (match-string 1)
  5562. txt nil
  5563. pos (1- (match-beginning 1))
  5564. todo-state (save-match-data (org-get-todo-state))
  5565. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5566. (member todo-state
  5567. org-agenda-repeating-timestamp-show-all))
  5568. d2 (org-time-string-to-absolute
  5569. (match-string 1) d1 'past show-all
  5570. (current-buffer) pos)
  5571. diff (- d2 d1)
  5572. warntime (get-text-property (point) 'org-appt-warntime))
  5573. (setq pastschedp (and todayp (< diff 0)))
  5574. (setq did-habit-check-p nil)
  5575. ;; When to show a scheduled item in the calendar:
  5576. ;; If it is on or past the date.
  5577. (when (or (and (< diff 0)
  5578. (< (abs diff) org-scheduled-past-days)
  5579. (and todayp (not org-agenda-only-exact-dates)))
  5580. (= diff 0)
  5581. ;; org-is-habit-p uses org-entry-get, which is expansive
  5582. ;; so we go extra mile to only call it once
  5583. (and todayp
  5584. (boundp 'org-habit-show-all-today)
  5585. org-habit-show-all-today
  5586. (setq did-habit-check-p t)
  5587. (setq habitp (and (functionp 'org-is-habit-p)
  5588. (org-is-habit-p)))))
  5589. (save-excursion
  5590. (setq donep (member todo-state org-done-keywords))
  5591. (if (and donep
  5592. (or org-agenda-skip-scheduled-if-done
  5593. (not (= diff 0))
  5594. (and (functionp 'org-is-habit-p)
  5595. (org-is-habit-p))))
  5596. (setq txt nil)
  5597. (setq habitp (if did-habit-check-p habitp
  5598. (and (functionp 'org-is-habit-p)
  5599. (org-is-habit-p))))
  5600. (setq category (org-get-category)
  5601. category-pos (get-text-property (point) 'org-category-position))
  5602. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5603. (setq txt org-agenda-no-heading-message)
  5604. (goto-char (match-end 0))
  5605. (setq pos1 (match-beginning 0))
  5606. (if habitp
  5607. (if (or (not org-habit-show-habits)
  5608. (and (not todayp)
  5609. (boundp 'org-habit-show-habits-only-for-today)
  5610. org-habit-show-habits-only-for-today))
  5611. (throw :skip nil))
  5612. (if (and
  5613. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5614. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5615. pastschedp))
  5616. (setq mm (assoc pos1 deadline-position-alist)))
  5617. (throw :skip nil)))
  5618. (setq tags (org-get-tags-at nil t))
  5619. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5620. (setq head (buffer-substring-no-properties
  5621. (point)
  5622. (progn (skip-chars-forward "^\r\n") (point))))
  5623. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5624. (setq timestr
  5625. (concat (substring s (match-beginning 1)) " "))
  5626. (setq timestr 'time))
  5627. (setq txt (org-agenda-format-item
  5628. (if (= diff 0)
  5629. (car org-agenda-scheduled-leaders)
  5630. (format (nth 1 org-agenda-scheduled-leaders)
  5631. (- 1 diff)))
  5632. head level category tags
  5633. (if (not (= diff 0)) nil timestr)
  5634. nil habitp))))
  5635. (when txt
  5636. (setq face
  5637. (cond
  5638. ((and (not habitp) pastschedp)
  5639. 'org-scheduled-previously)
  5640. (todayp 'org-scheduled-today)
  5641. (t 'org-scheduled))
  5642. habitp (and habitp (org-habit-parse-todo)))
  5643. (org-add-props txt props
  5644. 'undone-face face
  5645. 'face (if donep 'org-agenda-done face)
  5646. 'org-marker (org-agenda-new-marker pos)
  5647. 'org-hd-marker (org-agenda-new-marker pos1)
  5648. 'type (if pastschedp "past-scheduled" "scheduled")
  5649. 'date (if pastschedp d2 date)
  5650. 'warntime warntime
  5651. 'level level
  5652. 'priority (if habitp
  5653. (org-habit-get-priority habitp)
  5654. (+ 94 (- 5 diff) (org-get-priority txt)))
  5655. 'org-category category
  5656. 'category-position category-pos
  5657. 'org-habit-p habitp
  5658. 'todo-state todo-state)
  5659. (push txt ee))))))
  5660. (nreverse ee)))
  5661. (defun org-agenda-get-blocks ()
  5662. "Return the date-range information for agenda display."
  5663. (let* ((props (list 'face nil
  5664. 'org-not-done-regexp org-not-done-regexp
  5665. 'org-todo-regexp org-todo-regexp
  5666. 'org-complex-heading-regexp org-complex-heading-regexp
  5667. 'mouse-face 'highlight
  5668. 'help-echo
  5669. (format "mouse-2 or RET jump to org file %s"
  5670. (abbreviate-file-name buffer-file-name))))
  5671. (regexp org-tr-regexp)
  5672. (d0 (calendar-absolute-from-gregorian date))
  5673. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5674. level todo-state tags pos head donep)
  5675. (goto-char (point-min))
  5676. (while (re-search-forward regexp nil t)
  5677. (catch :skip
  5678. (org-agenda-skip)
  5679. (setq pos (point))
  5680. (let ((start-time (match-string 1))
  5681. (end-time (match-string 2)))
  5682. (setq s1 (match-string 1)
  5683. s2 (match-string 2)
  5684. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5685. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5686. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5687. ;; Only allow days between the limits, because the normal
  5688. ;; date stamps will catch the limits.
  5689. (save-excursion
  5690. (setq todo-state (org-get-todo-state))
  5691. (setq donep (member todo-state org-done-keywords))
  5692. (if (and donep org-agenda-skip-timestamp-if-done)
  5693. (throw :skip t))
  5694. (setq marker (org-agenda-new-marker (point)))
  5695. (setq category (org-get-category)
  5696. category-pos (get-text-property (point) 'org-category-position))
  5697. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5698. (setq txt org-agenda-no-heading-message)
  5699. (goto-char (match-beginning 0))
  5700. (setq hdmarker (org-agenda-new-marker (point)))
  5701. (setq tags (org-get-tags-at nil t))
  5702. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5703. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5704. (setq head (match-string 1))
  5705. (let ((remove-re
  5706. (if org-agenda-remove-timeranges-from-blocks
  5707. (concat
  5708. "<" (regexp-quote s1) ".*?>"
  5709. "--"
  5710. "<" (regexp-quote s2) ".*?>")
  5711. nil)))
  5712. (setq txt (org-agenda-format-item
  5713. (format
  5714. (nth (if (= d1 d2) 0 1)
  5715. org-agenda-timerange-leaders)
  5716. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5717. head level category tags
  5718. (cond ((and (= d1 d0) (= d2 d0))
  5719. (concat "<" start-time ">--<" end-time ">"))
  5720. ((= d1 d0)
  5721. (concat "<" start-time ">"))
  5722. ((= d2 d0)
  5723. (concat "<" end-time ">")))
  5724. remove-re))))
  5725. (org-add-props txt props
  5726. 'org-marker marker 'org-hd-marker hdmarker
  5727. 'type "block" 'date date
  5728. 'level level
  5729. 'todo-state todo-state
  5730. 'priority (org-get-priority txt) 'org-category category
  5731. 'org-category-position category-pos)
  5732. (push txt ee))))
  5733. (goto-char pos)))
  5734. ;; Sort the entries by expiration date.
  5735. (nreverse ee)))
  5736. ;;; Agenda presentation and sorting
  5737. (defvar org-prefix-has-time nil
  5738. "A flag, set by `org-compile-prefix-format'.
  5739. The flag is set if the currently compiled format contains a `%t'.")
  5740. (defvar org-prefix-has-tag nil
  5741. "A flag, set by `org-compile-prefix-format'.
  5742. The flag is set if the currently compiled format contains a `%T'.")
  5743. (defvar org-prefix-has-effort nil
  5744. "A flag, set by `org-compile-prefix-format'.
  5745. The flag is set if the currently compiled format contains a `%e'.")
  5746. (defvar org-prefix-category-length nil
  5747. "Used by `org-compile-prefix-format' to remember the category field width.")
  5748. (defvar org-prefix-category-max-length nil
  5749. "Used by `org-compile-prefix-format' to remember the category field width.")
  5750. (defun org-agenda-get-category-icon (category)
  5751. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5752. (dolist (entry org-agenda-category-icon-alist)
  5753. (when (org-string-match-p (car entry) category)
  5754. (if (listp (cadr entry))
  5755. (return (cadr entry))
  5756. (return (apply 'create-image (cdr entry)))))))
  5757. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5758. remove-re habitp)
  5759. "Format TXT to be inserted into the agenda buffer.
  5760. In particular, add the prefix and corresponding text properties.
  5761. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5762. LEVEL may be a string to replace the `%l' specifier.
  5763. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5764. category taken from local variable or file name. It will replace the `%c'
  5765. specifier in the format.
  5766. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5767. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5768. When DOTIME is a string, this string is searched for a time before TXT is.
  5769. TAGS can be the tags of the headline.
  5770. Any match of REMOVE-RE will be removed from TXT."
  5771. ;; We keep the org-prefix-* variable values along with a compiled
  5772. ;; formatter, so that multiple agendas existing at the same time do
  5773. ;; not step on each other toes.
  5774. ;;
  5775. ;; It was inconvenient to make these variables buffer local in
  5776. ;; Agenda buffers, because this function expects to be called with
  5777. ;; the buffer where item comes from being current, and not agenda
  5778. ;; buffer
  5779. (let* ((bindings (car org-prefix-format-compiled))
  5780. (formatter (cadr org-prefix-format-compiled)))
  5781. (loop for (var value) in bindings
  5782. do (set var value))
  5783. (save-match-data
  5784. ;; Diary entries sometimes have extra whitespace at the beginning
  5785. (setq txt (org-trim txt))
  5786. ;; Fix the tags part in txt
  5787. (setq txt (org-agenda-fix-displayed-tags
  5788. txt tags
  5789. org-agenda-show-inherited-tags
  5790. org-agenda-hide-tags-regexp))
  5791. (let* ((category (or category
  5792. (if (stringp org-category)
  5793. org-category
  5794. (and org-category (symbol-name org-category)))
  5795. (if buffer-file-name
  5796. (file-name-sans-extension
  5797. (file-name-nondirectory buffer-file-name))
  5798. "")))
  5799. (category-icon (org-agenda-get-category-icon category))
  5800. (category-icon (if category-icon
  5801. (propertize " " 'display category-icon)
  5802. ""))
  5803. ;; time, tag, effort are needed for the eval of the prefix format
  5804. (tag (if tags (nth (1- (length tags)) tags) ""))
  5805. time effort neffort
  5806. (ts (if dotime (concat
  5807. (if (stringp dotime) dotime "")
  5808. (and org-agenda-search-headline-for-time txt))))
  5809. (time-of-day (and dotime (org-get-time-of-day ts)))
  5810. stamp plain s0 s1 s2 rtn srp l
  5811. duration thecategory)
  5812. (and (derived-mode-p 'org-mode) buffer-file-name
  5813. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5814. (when (and dotime time-of-day)
  5815. ;; Extract starting and ending time and move them to prefix
  5816. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5817. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5818. (setq s0 (match-string 0 ts)
  5819. srp (and stamp (match-end 3))
  5820. s1 (match-string (if plain 1 2) ts)
  5821. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5822. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5823. ;; them, we might want to remove them there to avoid duplication.
  5824. ;; The user can turn this off with a variable.
  5825. (if (and org-prefix-has-time
  5826. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5827. (string-match (concat (regexp-quote s0) " *") txt)
  5828. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5829. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5830. (= (match-beginning 0) 0)
  5831. t))
  5832. (setq txt (replace-match "" nil nil txt))))
  5833. ;; Normalize the time(s) to 24 hour
  5834. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5835. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5836. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5837. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5838. (setq s2
  5839. (org-minutes-to-clocksum-string
  5840. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5841. ;; Compute the duration
  5842. (when s2
  5843. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5844. (org-hh:mm-string-to-minutes s1)))))
  5845. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5846. txt)
  5847. ;; Tags are in the string
  5848. (if (or (eq org-agenda-remove-tags t)
  5849. (and org-agenda-remove-tags
  5850. org-prefix-has-tag))
  5851. (setq txt (replace-match "" t t txt))
  5852. (setq txt (replace-match
  5853. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5854. (match-string 2 txt))
  5855. t t txt))))
  5856. (when (derived-mode-p 'org-mode)
  5857. (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
  5858. (when effort
  5859. (setq neffort (org-duration-string-to-minutes effort)
  5860. effort (setq effort (concat "[" effort "]")))))
  5861. ;; prevent erroring out with %e format when there is no effort
  5862. (or effort (setq effort ""))
  5863. (when remove-re
  5864. (while (string-match remove-re txt)
  5865. (setq txt (replace-match "" t t txt))))
  5866. ;; Set org-heading property on `txt' to mark the start of the
  5867. ;; heading.
  5868. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5869. ;; Prepare the variables needed in the eval of the compiled format
  5870. (setq time (cond (s2 (concat
  5871. (org-agenda-time-of-day-to-ampm-maybe s1)
  5872. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5873. (if org-agenda-timegrid-use-ampm " ")))
  5874. (s1 (concat
  5875. (org-agenda-time-of-day-to-ampm-maybe s1)
  5876. (if org-agenda-timegrid-use-ampm
  5877. "........ "
  5878. "......")))
  5879. (t ""))
  5880. extra (or (and (not habitp) extra) "")
  5881. category (if (symbolp category) (symbol-name category) category)
  5882. thecategory (copy-sequence category)
  5883. level (or level ""))
  5884. (if (string-match org-bracket-link-regexp category)
  5885. (progn
  5886. (setq l (if (match-end 3)
  5887. (- (match-end 3) (match-beginning 3))
  5888. (- (match-end 1) (match-beginning 1))))
  5889. (when (< l (or org-prefix-category-length 0))
  5890. (setq category (copy-sequence category))
  5891. (org-add-props category nil
  5892. 'extra-space (make-string
  5893. (- org-prefix-category-length l 1) ?\ ))))
  5894. (if (and org-prefix-category-max-length
  5895. (>= (length category) org-prefix-category-max-length))
  5896. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5897. ;; Evaluate the compiled format
  5898. (setq rtn (concat (eval formatter) txt))
  5899. ;; And finally add the text properties
  5900. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5901. (org-add-props rtn nil
  5902. 'org-category (if thecategory (downcase thecategory) category)
  5903. 'tags (mapcar 'org-downcase-keep-props tags)
  5904. 'org-highest-priority org-highest-priority
  5905. 'org-lowest-priority org-lowest-priority
  5906. 'time-of-day time-of-day
  5907. 'duration duration
  5908. 'effort effort
  5909. 'effort-minutes neffort
  5910. 'txt txt
  5911. 'level level
  5912. 'time time
  5913. 'extra extra
  5914. 'format org-prefix-format-compiled
  5915. 'dotime dotime)))))
  5916. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5917. "Remove tags string from TXT, and add a modified list of tags.
  5918. The modified list may contain inherited tags, and tags matched by
  5919. `org-agenda-hide-tags-regexp' will be removed."
  5920. (when (or add-inherited hide-re)
  5921. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5922. (setq txt (substring txt 0 (match-beginning 0))))
  5923. (setq tags
  5924. (delq nil
  5925. (mapcar (lambda (tg)
  5926. (if (or (and hide-re (string-match hide-re tg))
  5927. (and (not add-inherited)
  5928. (get-text-property 0 'inherited tg)))
  5929. nil
  5930. tg))
  5931. tags)))
  5932. (when tags
  5933. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5934. i)
  5935. (setq txt (concat txt " :"
  5936. (mapconcat
  5937. (lambda (x)
  5938. (setq i (get-text-property 0 'inherited x))
  5939. (if (and have-i (not i))
  5940. (progn
  5941. (setq have-i nil)
  5942. (concat ":" x))
  5943. x))
  5944. tags ":")
  5945. (if have-i "::" ":"))))))
  5946. txt)
  5947. (defun org-downcase-keep-props (s)
  5948. (let ((props (text-properties-at 0 s)))
  5949. (setq s (downcase s))
  5950. (add-text-properties 0 (length s) props s)
  5951. s))
  5952. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5953. (defvar org-agenda-sorting-strategy-selected nil)
  5954. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5955. "Add a time-grid for agenda items which need it.
  5956. LIST is the list of agenda items formatted by `org-agenda-list'.
  5957. NDAYS is the span of the current agenda view.
  5958. TODAYP is `t' when the current agenda view is on today."
  5959. (catch 'exit
  5960. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5961. ((and todayp (member 'today (car org-agenda-time-grid))))
  5962. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5963. ((member 'weekly (car org-agenda-time-grid)))
  5964. (t (throw 'exit list)))
  5965. (let* ((have (delq nil (mapcar
  5966. (lambda (x) (get-text-property 1 'time-of-day x))
  5967. list)))
  5968. (string (nth 1 org-agenda-time-grid))
  5969. (gridtimes (nth 2 org-agenda-time-grid))
  5970. (req (car org-agenda-time-grid))
  5971. (remove (member 'remove-match req))
  5972. new time)
  5973. (if (and (member 'require-timed req) (not have))
  5974. ;; don't show empty grid
  5975. (throw 'exit list))
  5976. (while (setq time (pop gridtimes))
  5977. (unless (and remove (member time have))
  5978. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5979. (push (org-agenda-format-item
  5980. nil string nil "" nil
  5981. (concat (substring time 0 -2) ":" (substring time -2)))
  5982. new)
  5983. (put-text-property
  5984. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5985. (when (and todayp org-agenda-show-current-time-in-grid)
  5986. (push (org-agenda-format-item
  5987. nil org-agenda-current-time-string nil "" nil
  5988. (format-time-string "%H:%M "))
  5989. new)
  5990. (put-text-property
  5991. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5992. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5993. (append new list)
  5994. (append list new)))))
  5995. (defun org-compile-prefix-format (key)
  5996. "Compile the prefix format into a Lisp form that can be evaluated.
  5997. The resulting form and associated variable bindings is returned
  5998. and stored in the variable `org-prefix-format-compiled'."
  5999. (setq org-prefix-has-time nil
  6000. org-prefix-has-tag nil
  6001. org-prefix-category-length nil
  6002. org-prefix-has-effort nil)
  6003. (let ((s (cond
  6004. ((stringp org-agenda-prefix-format)
  6005. org-agenda-prefix-format)
  6006. ((assq key org-agenda-prefix-format)
  6007. (cdr (assq key org-agenda-prefix-format)))
  6008. (t " %-12:c%?-12t% s")))
  6009. (start 0)
  6010. varform vars var e c f opt)
  6011. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
  6012. s start)
  6013. (setq var (or (cdr (assoc (match-string 4 s)
  6014. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6015. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  6016. 'eval)
  6017. c (or (match-string 3 s) "")
  6018. opt (match-beginning 1)
  6019. start (1+ (match-beginning 0)))
  6020. (if (equal var 'time) (setq org-prefix-has-time t))
  6021. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6022. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6023. (setq f (concat "%" (match-string 2 s) "s"))
  6024. (when (equal var 'category)
  6025. (setq org-prefix-category-length
  6026. (floor (abs (string-to-number (match-string 2 s)))))
  6027. (setq org-prefix-category-max-length
  6028. (let ((x (match-string 2 s)))
  6029. (save-match-data
  6030. (if (string-match "\\.[0-9]+" x)
  6031. (string-to-number (substring (match-string 0 x) 1)))))))
  6032. (if (eq var 'eval)
  6033. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6034. (if opt
  6035. (setq varform
  6036. `(if (equal "" ,var)
  6037. ""
  6038. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6039. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6040. (setq s (replace-match "%s" t nil s))
  6041. (push varform vars))
  6042. (setq vars (nreverse vars))
  6043. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6044. (setq org-prefix-format-compiled
  6045. (list
  6046. `((org-prefix-has-time ,org-prefix-has-time)
  6047. (org-prefix-has-tag ,org-prefix-has-tag)
  6048. (org-prefix-category-length ,org-prefix-category-length)
  6049. (org-prefix-has-effort ,org-prefix-has-effort))
  6050. `(format ,s ,@vars))))))
  6051. (defun org-set-sorting-strategy (key)
  6052. (if (symbolp (car org-agenda-sorting-strategy))
  6053. ;; the old format
  6054. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6055. (setq org-agenda-sorting-strategy-selected
  6056. (or (cdr (assq key org-agenda-sorting-strategy))
  6057. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6058. '(time-up category-keep priority-down)))))
  6059. (defun org-get-time-of-day (s &optional string mod24)
  6060. "Check string S for a time of day.
  6061. If found, return it as a military time number between 0 and 2400.
  6062. If not found, return nil.
  6063. The optional STRING argument forces conversion into a 5 character wide string
  6064. HH:MM."
  6065. (save-match-data
  6066. (when
  6067. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6068. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6069. (let* ((h (string-to-number (match-string 1 s)))
  6070. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6071. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6072. (am-p (equal ampm "am"))
  6073. (h1 (cond ((not ampm) h)
  6074. ((= h 12) (if am-p 0 12))
  6075. (t (+ h (if am-p 0 12)))))
  6076. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6077. (mod h1 24) h1))
  6078. (t0 (+ (* 100 h2) m))
  6079. (t1 (concat (if (>= h1 24) "+" " ")
  6080. (if (and org-agenda-time-leading-zero
  6081. (< t0 1000)) "0" "")
  6082. (if (< t0 100) "0" "")
  6083. (if (< t0 10) "0" "")
  6084. (int-to-string t0))))
  6085. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6086. (defvar org-agenda-before-sorting-filter-function nil
  6087. "Function to be applied to agenda items prior to sorting.
  6088. Prior to sorting also means just before they are inserted into the agenda.
  6089. To aid sorting, you may revisit the original entries and add more text
  6090. properties which will later be used by the sorting functions.
  6091. The function should take a string argument, an agenda line.
  6092. It has access to the text properties in that line, which contain among
  6093. other things, the property `org-hd-marker' that points to the entry
  6094. where the line comes from. Note that not all lines going into the agenda
  6095. have this property, only most.
  6096. The function should return the modified string. It is probably best
  6097. to ONLY change text properties.
  6098. You can also use this function as a filter, by returning nil for lines
  6099. you don't want to have in the agenda at all. For this application, you
  6100. could bind the variable in the options section of a custom command.")
  6101. (defun org-agenda-finalize-entries (list &optional nosort)
  6102. "Sort and concatenate the agenda items."
  6103. (setq list (mapcar 'org-agenda-highlight-todo list))
  6104. (if nosort
  6105. list
  6106. (when org-agenda-before-sorting-filter-function
  6107. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  6108. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  6109. (defun org-agenda-highlight-todo (x)
  6110. (let ((org-done-keywords org-done-keywords-for-agenda)
  6111. (case-fold-search nil)
  6112. re)
  6113. (if (eq x 'line)
  6114. (save-excursion
  6115. (beginning-of-line 1)
  6116. (setq re (org-get-at-bol 'org-todo-regexp))
  6117. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6118. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6119. (add-text-properties (match-beginning 0) (match-end 1)
  6120. (list 'face (org-get-todo-face 1)))
  6121. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6122. (delete-region (match-beginning 1) (1- (match-end 0)))
  6123. (goto-char (match-beginning 1))
  6124. (insert (format org-agenda-todo-keyword-format s)))))
  6125. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6126. (setq re (get-text-property 0 'org-todo-regexp x))
  6127. (when (and re
  6128. ;; Test `pl' because if there's no heading content,
  6129. ;; there's no point matching to highlight. Note
  6130. ;; that if we didn't test `pl' first, and there
  6131. ;; happened to be no keyword from `org-todo-regexp'
  6132. ;; on this heading line, then the `equal' comparison
  6133. ;; afterwards would spuriously succeed in the case
  6134. ;; where `pl' is nil -- causing an args-out-of-range
  6135. ;; error when we try to add text properties to text
  6136. ;; that isn't there.
  6137. pl
  6138. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6139. x pl) pl))
  6140. (add-text-properties
  6141. (or (match-end 1) (match-end 0)) (match-end 0)
  6142. (list 'face (org-get-todo-face (match-string 2 x)))
  6143. x)
  6144. (when (match-end 1)
  6145. (setq x (concat (substring x 0 (match-end 1))
  6146. (format org-agenda-todo-keyword-format
  6147. (match-string 2 x))
  6148. (org-add-props " " (text-properties-at 0 x))
  6149. (substring x (match-end 3)))))))
  6150. x)))
  6151. (defsubst org-cmp-priority (a b)
  6152. "Compare the priorities of string A and B."
  6153. (let ((pa (or (get-text-property 1 'priority a) 0))
  6154. (pb (or (get-text-property 1 'priority b) 0)))
  6155. (cond ((> pa pb) +1)
  6156. ((< pa pb) -1))))
  6157. (defsubst org-cmp-effort (a b)
  6158. "Compare the effort values of string A and B."
  6159. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6160. (ea (or (get-text-property 1 'effort-minutes a) def))
  6161. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6162. (cond ((> ea eb) +1)
  6163. ((< ea eb) -1))))
  6164. (defsubst org-cmp-category (a b)
  6165. "Compare the string values of categories of strings A and B."
  6166. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6167. (cb (or (get-text-property 1 'org-category b) "")))
  6168. (cond ((string-lessp ca cb) -1)
  6169. ((string-lessp cb ca) +1))))
  6170. (defsubst org-cmp-todo-state (a b)
  6171. "Compare the todo states of strings A and B."
  6172. (let* ((ma (or (get-text-property 1 'org-marker a)
  6173. (get-text-property 1 'org-hd-marker a)))
  6174. (mb (or (get-text-property 1 'org-marker b)
  6175. (get-text-property 1 'org-hd-marker b)))
  6176. (fa (and ma (marker-buffer ma)))
  6177. (fb (and mb (marker-buffer mb)))
  6178. (todo-kwds
  6179. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6180. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6181. (ta (or (get-text-property 1 'todo-state a) ""))
  6182. (tb (or (get-text-property 1 'todo-state b) ""))
  6183. (la (- (length (member ta todo-kwds))))
  6184. (lb (- (length (member tb todo-kwds))))
  6185. (donepa (member ta org-done-keywords-for-agenda))
  6186. (donepb (member tb org-done-keywords-for-agenda)))
  6187. (cond ((and donepa (not donepb)) -1)
  6188. ((and (not donepa) donepb) +1)
  6189. ((< la lb) -1)
  6190. ((< lb la) +1))))
  6191. (defsubst org-cmp-alpha (a b)
  6192. "Compare the headlines, alphabetically."
  6193. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6194. (plb (text-property-any 0 (length b) 'org-heading t b))
  6195. (ta (and pla (substring a pla)))
  6196. (tb (and plb (substring b plb))))
  6197. (when pla
  6198. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6199. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6200. (setq ta (substring ta (match-end 0))))
  6201. (setq ta (downcase ta)))
  6202. (when plb
  6203. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6204. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6205. (setq tb (substring tb (match-end 0))))
  6206. (setq tb (downcase tb)))
  6207. (cond ((not ta) +1)
  6208. ((not tb) -1)
  6209. ((string-lessp ta tb) -1)
  6210. ((string-lessp tb ta) +1))))
  6211. (defsubst org-cmp-tag (a b)
  6212. "Compare the string values of the first tags of A and B."
  6213. (let ((ta (car (last (get-text-property 1 'tags a))))
  6214. (tb (car (last (get-text-property 1 'tags b)))))
  6215. (cond ((not ta) +1)
  6216. ((not tb) -1)
  6217. ((string-lessp ta tb) -1)
  6218. ((string-lessp tb ta) +1))))
  6219. (defsubst org-cmp-time (a b)
  6220. "Compare the time-of-day values of strings A and B."
  6221. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6222. (ta (or (get-text-property 1 'time-of-day a) def))
  6223. (tb (or (get-text-property 1 'time-of-day b) def)))
  6224. (cond ((< ta tb) -1)
  6225. ((< tb ta) +1))))
  6226. (defsubst org-cmp-habit-p (a b)
  6227. "Compare the todo states of strings A and B."
  6228. (let ((ha (get-text-property 1 'org-habit-p a))
  6229. (hb (get-text-property 1 'org-habit-p b)))
  6230. (cond ((and ha (not hb)) -1)
  6231. ((and (not ha) hb) +1))))
  6232. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  6233. (defun org-entries-lessp (a b)
  6234. "Predicate for sorting agenda entries."
  6235. ;; The following variables will be used when the form is evaluated.
  6236. ;; So even though the compiler complains, keep them.
  6237. (let* ((ss org-agenda-sorting-strategy-selected)
  6238. (time-up (and (org-em 'time-up 'time-down ss)
  6239. (org-cmp-time a b)))
  6240. (time-down (if time-up (- time-up) nil))
  6241. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6242. (org-cmp-priority a b)))
  6243. (priority-down (if priority-up (- priority-up) nil))
  6244. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6245. (org-cmp-effort a b)))
  6246. (effort-down (if effort-up (- effort-up) nil))
  6247. (category-up (and (or (org-em 'category-up 'category-down ss)
  6248. (memq 'category-keep ss))
  6249. (org-cmp-category a b)))
  6250. (category-down (if category-up (- category-up) nil))
  6251. (category-keep (if category-up +1 nil))
  6252. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6253. (org-cmp-tag a b)))
  6254. (tag-down (if tag-up (- tag-up) nil))
  6255. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6256. (org-cmp-todo-state a b)))
  6257. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6258. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6259. (org-cmp-habit-p a b)))
  6260. (habit-down (if habit-up (- habit-up) nil))
  6261. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6262. (org-cmp-alpha a b)))
  6263. (alpha-down (if alpha-up (- alpha-up) nil))
  6264. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6265. user-defined-up user-defined-down)
  6266. (if (and need-user-cmp org-agenda-cmp-user-defined
  6267. (functionp org-agenda-cmp-user-defined))
  6268. (setq user-defined-up
  6269. (funcall org-agenda-cmp-user-defined a b)
  6270. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6271. (cdr (assoc
  6272. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6273. '((-1 . t) (1 . nil) (nil . nil))))))
  6274. ;;; Agenda restriction lock
  6275. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6276. "Overlay to mark the headline to which agenda commands are restricted.")
  6277. (overlay-put org-agenda-restriction-lock-overlay
  6278. 'face 'org-agenda-restriction-lock)
  6279. (overlay-put org-agenda-restriction-lock-overlay
  6280. 'help-echo "Agendas are currently limited to this subtree.")
  6281. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6282. (defun org-agenda-set-restriction-lock (&optional type)
  6283. "Set restriction lock for agenda, to current subtree or file.
  6284. Restriction will be the file if TYPE is `file', or if type is the
  6285. universal prefix '(4), or if the cursor is before the first headline
  6286. in the file. Otherwise, restriction will be to the current subtree."
  6287. (interactive "P")
  6288. (and (equal type '(4)) (setq type 'file))
  6289. (setq type (cond
  6290. (type type)
  6291. ((org-at-heading-p) 'subtree)
  6292. ((condition-case nil (org-back-to-heading t) (error nil))
  6293. 'subtree)
  6294. (t 'file)))
  6295. (if (eq type 'subtree)
  6296. (progn
  6297. (setq org-agenda-restrict t)
  6298. (setq org-agenda-overriding-restriction 'subtree)
  6299. (put 'org-agenda-files 'org-restrict
  6300. (list (buffer-file-name (buffer-base-buffer))))
  6301. (org-back-to-heading t)
  6302. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6303. (move-marker org-agenda-restrict-begin (point))
  6304. (move-marker org-agenda-restrict-end
  6305. (save-excursion (org-end-of-subtree t)))
  6306. (message "Locking agenda restriction to subtree"))
  6307. (put 'org-agenda-files 'org-restrict
  6308. (list (buffer-file-name (buffer-base-buffer))))
  6309. (setq org-agenda-restrict nil)
  6310. (setq org-agenda-overriding-restriction 'file)
  6311. (move-marker org-agenda-restrict-begin nil)
  6312. (move-marker org-agenda-restrict-end nil)
  6313. (message "Locking agenda restriction to file"))
  6314. (setq current-prefix-arg nil)
  6315. (org-agenda-maybe-redo))
  6316. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6317. "Remove the agenda restriction lock."
  6318. (interactive "P")
  6319. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6320. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6321. (setq org-agenda-overriding-restriction nil)
  6322. (setq org-agenda-restrict nil)
  6323. (put 'org-agenda-files 'org-restrict nil)
  6324. (move-marker org-agenda-restrict-begin nil)
  6325. (move-marker org-agenda-restrict-end nil)
  6326. (setq current-prefix-arg nil)
  6327. (message "Agenda restriction lock removed")
  6328. (or noupdate (org-agenda-maybe-redo)))
  6329. (defun org-agenda-maybe-redo ()
  6330. "If there is any window showing the agenda view, update it."
  6331. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6332. (w0 (selected-window)))
  6333. (when w
  6334. (select-window w)
  6335. (org-agenda-redo)
  6336. (select-window w0)
  6337. (if org-agenda-overriding-restriction
  6338. (message "Agenda view shifted to new %s restriction"
  6339. org-agenda-overriding-restriction)
  6340. (message "Agenda restriction lock removed")))))
  6341. ;;; Agenda commands
  6342. (defun org-agenda-check-type (error &rest types)
  6343. "Check if agenda buffer is of allowed type.
  6344. If ERROR is non-nil, throw an error, otherwise just return nil.
  6345. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6346. (if (not org-agenda-type)
  6347. (error "No Org agenda currently displayed")
  6348. (if (memq org-agenda-type types)
  6349. t
  6350. (if error
  6351. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6352. nil))))
  6353. (defun org-agenda-Quit ()
  6354. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6355. Also restore the window configuration."
  6356. (interactive)
  6357. (if org-agenda-columns-active
  6358. (org-columns-quit)
  6359. (let ((buf (current-buffer)))
  6360. (if (eq org-agenda-window-setup 'other-frame)
  6361. (progn
  6362. (org-agenda-reset-markers)
  6363. (kill-buffer buf)
  6364. (org-columns-remove-overlays)
  6365. (setq org-agenda-archives-mode nil)
  6366. (delete-frame))
  6367. (and (not (eq org-agenda-window-setup 'current-window))
  6368. (not (one-window-p))
  6369. (delete-window))
  6370. (org-agenda-reset-markers)
  6371. (kill-buffer buf)
  6372. (org-columns-remove-overlays)
  6373. (setq org-agenda-archives-mode nil)))
  6374. ;; Maybe restore the pre-agenda window configuration.
  6375. (and org-agenda-restore-windows-after-quit
  6376. (not (eq org-agenda-window-setup 'other-frame))
  6377. org-agenda-pre-window-conf
  6378. (set-window-configuration org-agenda-pre-window-conf)
  6379. (setq org-agenda-pre-window-conf nil))))
  6380. (defun org-agenda-quit ()
  6381. "Exit the agenda and restore the window configuration.
  6382. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6383. (interactive)
  6384. (if (and (eq org-indirect-buffer-display 'other-window)
  6385. org-last-indirect-buffer)
  6386. (delete-window (get-buffer-window org-last-indirect-buffer)))
  6387. (if org-agenda-columns-active
  6388. (org-columns-quit)
  6389. (if org-agenda-sticky
  6390. (let ((buf (current-buffer)))
  6391. (if (eq org-agenda-window-setup 'other-frame)
  6392. (progn
  6393. (delete-frame))
  6394. (and (not (eq org-agenda-window-setup 'current-window))
  6395. (not (one-window-p))
  6396. (delete-window)))
  6397. (with-current-buffer buf
  6398. (bury-buffer)
  6399. ;; Maybe restore the pre-agenda window configuration.
  6400. (and org-agenda-restore-windows-after-quit
  6401. (not (eq org-agenda-window-setup 'other-frame))
  6402. org-agenda-pre-window-conf
  6403. (set-window-configuration org-agenda-pre-window-conf)
  6404. (setq org-agenda-pre-window-conf nil))))
  6405. (org-agenda-Quit))))
  6406. (defun org-agenda-exit ()
  6407. "Exit the agenda and restore the window configuration.
  6408. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6409. buffers visited directly by the user will not be touched."
  6410. (interactive)
  6411. (org-release-buffers org-agenda-new-buffers)
  6412. (setq org-agenda-new-buffers nil)
  6413. (org-agenda-Quit))
  6414. (defun org-agenda-kill-all-agenda-buffers ()
  6415. "Kill all buffers in `org-agenda-mode'.
  6416. This is used when toggling sticky agendas.
  6417. You can also explicitly invoke it with `C-c a C-k'."
  6418. (interactive)
  6419. (let (blist)
  6420. (dolist (buf (buffer-list))
  6421. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6422. (push buf blist)))
  6423. (mapc 'kill-buffer blist)))
  6424. (defun org-agenda-execute (arg)
  6425. "Execute another agenda command, keeping same window.
  6426. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6427. in the agenda."
  6428. (interactive "P")
  6429. (let ((org-agenda-window-setup 'current-window))
  6430. (org-agenda arg)))
  6431. (defun org-agenda-redo (&optional all)
  6432. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6433. (interactive "P")
  6434. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6435. (cpa (unless (eq all t) current-prefix-arg))
  6436. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6437. (org-agenda-sticky nil)
  6438. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6439. org-agenda-buffer-name))
  6440. (org-agenda-keep-modes t)
  6441. (tag-filter org-agenda-tag-filter)
  6442. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6443. (top-cat-filter org-agenda-top-category-filter)
  6444. (cat-filter org-agenda-category-filter)
  6445. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6446. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6447. (cols org-agenda-columns-active)
  6448. (line (org-current-line))
  6449. (window-line (- line (org-current-line (window-start))))
  6450. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6451. (redo-cmd (get-text-property p 'org-redo-cmd))
  6452. (last-args (get-text-property p 'org-last-args))
  6453. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6454. (org-agenda-overriding-cmd-arguments
  6455. (unless (eq all t)
  6456. (cond ((listp last-args)
  6457. (cons (or cpa (car last-args)) (cdr last-args)))
  6458. ((stringp last-args)
  6459. last-args))))
  6460. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6461. (put 'org-agenda-tag-filter :preset-filter nil)
  6462. (put 'org-agenda-category-filter :preset-filter nil)
  6463. (and cols (org-columns-quit))
  6464. (message "Rebuilding agenda buffer...")
  6465. (if series-redo-cmd
  6466. (eval series-redo-cmd)
  6467. (org-let lprops '(eval redo-cmd)))
  6468. (setq org-agenda-undo-list nil
  6469. org-agenda-pending-undo-list nil)
  6470. (message "Rebuilding agenda buffer...done")
  6471. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6472. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6473. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6474. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6475. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6476. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6477. (org-goto-line line)
  6478. (recenter window-line)))
  6479. (defvar org-global-tags-completion-table nil)
  6480. (defvar org-agenda-filter-form nil)
  6481. (defvar org-agenda-filtered-by-category nil)
  6482. (defun org-agenda-filter-by-category (strip)
  6483. "Keep only those lines in the agenda buffer that have a specific category.
  6484. The category is that of the current line."
  6485. (interactive "P")
  6486. (if (and org-agenda-filtered-by-category
  6487. org-agenda-category-filter)
  6488. (org-agenda-filter-show-all-cat)
  6489. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6490. (if cat (org-agenda-filter-apply
  6491. (list (concat (if strip "-" "+") cat)) 'category)
  6492. (error "No category at point")))))
  6493. (defun org-find-top-category (&optional pos)
  6494. (save-excursion
  6495. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6496. (if pos (goto-char pos))
  6497. ;; Skip up to the topmost parent
  6498. (while (ignore-errors (outline-up-heading 1) t))
  6499. (ignore-errors
  6500. (nth 4 (org-heading-components))))))
  6501. (defvar org-agenda-filtered-by-top-category nil)
  6502. (defun org-agenda-filter-by-top-category (strip)
  6503. "Keep only those lines in the agenda buffer that have a specific category.
  6504. The category is that of the current line."
  6505. (interactive "P")
  6506. (if org-agenda-filtered-by-top-category
  6507. (progn
  6508. (setq org-agenda-filtered-by-top-category nil
  6509. org-agenda-top-category-filter nil)
  6510. (org-agenda-filter-show-all-cat))
  6511. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6512. (if cat (org-agenda-filter-top-category-apply cat strip)
  6513. (error "No top-level category at point")))))
  6514. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6515. "Keep only those lines in the agenda buffer that have a specific tag.
  6516. The tag is selected with its fast selection letter, as configured.
  6517. With prefix argument STRIP, remove all lines that do have the tag.
  6518. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6519. used to narrow the search - the interactive user can also press `-' or `+'
  6520. to switch to narrowing."
  6521. (interactive "P")
  6522. (let* ((alist org-tag-alist-for-agenda)
  6523. (tag-chars (mapconcat
  6524. (lambda (x) (if (and (not (symbolp (car x)))
  6525. (cdr x))
  6526. (char-to-string (cdr x))
  6527. ""))
  6528. alist ""))
  6529. (efforts (org-split-string
  6530. (or (cdr (assoc (concat org-effort-property "_ALL")
  6531. org-global-properties))
  6532. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6533. "")))
  6534. (effort-op org-agenda-filter-effort-default-operator)
  6535. (effort-prompt "")
  6536. (inhibit-read-only t)
  6537. (current org-agenda-tag-filter)
  6538. maybe-refresh a n tag)
  6539. (unless char
  6540. (message
  6541. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6542. (if narrow "Narrow" "Filter") tag-chars
  6543. (if org-agenda-auto-exclude-function "[RET], " ""))
  6544. (setq char (read-char-exclusive)))
  6545. (when (member char '(?+ ?-))
  6546. ;; Narrowing down
  6547. (cond ((equal char ?-) (setq strip t narrow t))
  6548. ((equal char ?+) (setq strip nil narrow t)))
  6549. (message
  6550. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6551. (setq char (read-char-exclusive)))
  6552. (when (member char '(?< ?> ?= ??))
  6553. ;; An effort operator
  6554. (setq effort-op (char-to-string char))
  6555. (setq alist nil) ; to make sure it will be interpreted as effort.
  6556. (unless (equal char ??)
  6557. (loop for i from 0 to 9 do
  6558. (setq effort-prompt
  6559. (concat
  6560. effort-prompt " ["
  6561. (if (= i 9) "0" (int-to-string (1+ i)))
  6562. "]" (nth i efforts))))
  6563. (message "Effort%s: %s " effort-op effort-prompt)
  6564. (setq char (read-char-exclusive))
  6565. (when (or (< char ?0) (> char ?9))
  6566. (error "Need 1-9,0 to select effort"))))
  6567. (when (equal char ?\t)
  6568. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6569. (org-set-local 'org-global-tags-completion-table
  6570. (org-global-tags-completion-table)))
  6571. (let ((completion-ignore-case t))
  6572. (setq tag (org-icompleting-read
  6573. "Tag: " org-global-tags-completion-table))))
  6574. (cond
  6575. ((equal char ?\r)
  6576. (org-agenda-filter-show-all-tag)
  6577. (when org-agenda-auto-exclude-function
  6578. (setq org-agenda-tag-filter '())
  6579. (dolist (tag (org-agenda-get-represented-tags))
  6580. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6581. (if modifier
  6582. (push modifier org-agenda-tag-filter))))
  6583. (if (not (null org-agenda-tag-filter))
  6584. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6585. (setq maybe-refresh t))
  6586. ((equal char ?/)
  6587. (org-agenda-filter-show-all-tag)
  6588. (when (get 'org-agenda-tag-filter :preset-filter)
  6589. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6590. (setq maybe-refresh t))
  6591. ((equal char ?. )
  6592. (setq org-agenda-tag-filter
  6593. (mapcar (lambda(tag) (concat "+" tag))
  6594. (org-get-at-bol 'tags)))
  6595. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6596. (setq maybe-refresh t))
  6597. ((or (equal char ?\ )
  6598. (setq a (rassoc char alist))
  6599. (and (>= char ?0) (<= char ?9)
  6600. (setq n (if (= char ?0) 9 (- char ?0 1))
  6601. tag (concat effort-op (nth n efforts))
  6602. a (cons tag nil)))
  6603. (and (= char ??)
  6604. (setq tag "?eff")
  6605. a (cons tag nil))
  6606. (and tag (setq a (cons tag nil))))
  6607. (org-agenda-filter-show-all-tag)
  6608. (setq tag (car a))
  6609. (setq org-agenda-tag-filter
  6610. (cons (concat (if strip "-" "+") tag)
  6611. (if narrow current nil)))
  6612. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6613. (setq maybe-refresh t))
  6614. (t (error "Invalid tag selection character %c" char)))
  6615. (when (and maybe-refresh
  6616. (eq org-agenda-clockreport-mode 'with-filter))
  6617. (org-agenda-redo))))
  6618. (defun org-agenda-get-represented-tags ()
  6619. "Get a list of all tags currently represented in the agenda."
  6620. (let (p tags)
  6621. (save-excursion
  6622. (goto-char (point-min))
  6623. (while (setq p (next-single-property-change (point) 'tags))
  6624. (goto-char p)
  6625. (mapc (lambda (x) (add-to-list 'tags x))
  6626. (get-text-property (point) 'tags))))
  6627. tags))
  6628. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6629. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6630. (interactive "P")
  6631. (org-agenda-filter-by-tag strip char 'refine))
  6632. (defun org-agenda-filter-make-matcher ()
  6633. "Create the form that tests a line for agenda filter."
  6634. (let (f f1)
  6635. ;; first compute the tag-filter matcher
  6636. (dolist (x (delete-dups
  6637. (append (get 'org-agenda-tag-filter
  6638. :preset-filter) org-agenda-tag-filter)))
  6639. (if (member x '("-" "+"))
  6640. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6641. (if (string-match "[<=>?]" x)
  6642. (setq f1 (org-agenda-filter-effort-form x))
  6643. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6644. (if (equal (string-to-char x) ?-)
  6645. (setq f1 (list 'not f1))))
  6646. (push f1 f))
  6647. ;; then compute the category-filter matcher
  6648. (dolist (x (delete-dups
  6649. (append (get 'org-agenda-category-filter
  6650. :preset-filter) org-agenda-category-filter)))
  6651. (if (equal "-" (substring x 0 1))
  6652. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6653. (setq f1 (list 'equal (substring x 1) 'cat)))
  6654. (push f1 f))
  6655. (cons 'and (nreverse f))))
  6656. (defun org-agenda-filter-effort-form (e)
  6657. "Return the form to compare the effort of the current line with what E says.
  6658. E looks like \"+<2:25\"."
  6659. (let (op)
  6660. (setq e (substring e 1))
  6661. (setq op (string-to-char e) e (substring e 1))
  6662. (setq op (cond ((equal op ?<) '<=)
  6663. ((equal op ?>) '>=)
  6664. ((equal op ??) op)
  6665. (t '=)))
  6666. (list 'org-agenda-compare-effort (list 'quote op)
  6667. (org-duration-string-to-minutes e))))
  6668. (defun org-agenda-compare-effort (op value)
  6669. "Compare the effort of the current line with VALUE, using OP.
  6670. If the line does not have an effort defined, return nil."
  6671. (let ((eff (org-get-at-bol 'effort-minutes)))
  6672. (if (equal op ??)
  6673. (not eff)
  6674. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6675. value))))
  6676. (defun org-agenda-filter-apply (filter type)
  6677. "Set FILTER as the new agenda filter and apply it."
  6678. (let (tags cat)
  6679. (if (eq type 'tag)
  6680. (setq org-agenda-tag-filter filter)
  6681. (setq org-agenda-category-filter filter))
  6682. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6683. (if (and (eq type 'category)
  6684. (not (equal (substring (car filter) 0 1) "-")))
  6685. ;; Only set `org-agenda-filtered-by-category' to t
  6686. ;; when a unique category is used as the filter
  6687. (setq org-agenda-filtered-by-category t))
  6688. (org-agenda-set-mode-name)
  6689. (save-excursion
  6690. (goto-char (point-min))
  6691. (while (not (eobp))
  6692. (if (org-get-at-bol 'org-marker)
  6693. (progn
  6694. (setq tags (org-get-at-bol 'tags) ; used in eval
  6695. cat (get-text-property (point) 'org-category))
  6696. (if (not (eval org-agenda-filter-form))
  6697. (org-agenda-filter-hide-line type))
  6698. (beginning-of-line 2))
  6699. (beginning-of-line 2))))
  6700. (if (get-char-property (point) 'invisible)
  6701. (ignore-errors (org-agenda-previous-line)))))
  6702. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6703. "Set FILTER as the new agenda filter and apply it."
  6704. (org-agenda-set-mode-name)
  6705. (save-excursion
  6706. (goto-char (point-min))
  6707. (while (not (eobp))
  6708. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6709. (topcat (and pos (org-find-top-category pos))))
  6710. (if (and topcat (funcall (if negative 'identity 'not)
  6711. (string= category topcat)))
  6712. (org-agenda-filter-hide-line 'category)))
  6713. (beginning-of-line 2)))
  6714. (if (get-char-property (point) 'invisible)
  6715. (org-agenda-previous-line))
  6716. (setq org-agenda-top-category-filter category
  6717. org-agenda-filtered-by-top-category t))
  6718. (defun org-agenda-filter-hide-line (type)
  6719. (let (ov)
  6720. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6721. (point-at-eol)))
  6722. (overlay-put ov 'invisible t)
  6723. (overlay-put ov 'type type)
  6724. (if (eq type 'tag)
  6725. (push ov org-agenda-tag-filter-overlays)
  6726. (push ov org-agenda-cat-filter-overlays))))
  6727. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6728. (setq pos (or pos (point)))
  6729. (save-excursion
  6730. (dolist (ov (overlays-at pos))
  6731. (when (and (overlay-get ov 'invisible)
  6732. (eq (overlay-get ov 'type) 'tag))
  6733. (goto-char pos)
  6734. (if (< (overlay-start ov) (point-at-eol))
  6735. (move-overlay ov (point-at-eol)
  6736. (overlay-end ov)))))))
  6737. (defun org-agenda-filter-show-all-tag nil
  6738. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6739. (setq org-agenda-tag-filter-overlays nil
  6740. org-agenda-tag-filter nil
  6741. org-agenda-filter-form nil)
  6742. (org-agenda-set-mode-name))
  6743. (defun org-agenda-filter-show-all-cat nil
  6744. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6745. (setq org-agenda-cat-filter-overlays nil
  6746. org-agenda-filtered-by-category nil
  6747. org-agenda-category-filter nil
  6748. org-agenda-filter-form nil)
  6749. (org-agenda-set-mode-name))
  6750. (defun org-agenda-manipulate-query-add ()
  6751. "Manipulate the query by adding a search term with positive selection.
  6752. Positive selection means the term must be matched for selection of an entry."
  6753. (interactive)
  6754. (org-agenda-manipulate-query ?\[))
  6755. (defun org-agenda-manipulate-query-subtract ()
  6756. "Manipulate the query by adding a search term with negative selection.
  6757. Negative selection means term must not be matched for selection of an entry."
  6758. (interactive)
  6759. (org-agenda-manipulate-query ?\]))
  6760. (defun org-agenda-manipulate-query-add-re ()
  6761. "Manipulate the query by adding a search regexp with positive selection.
  6762. Positive selection means the regexp must match for selection of an entry."
  6763. (interactive)
  6764. (org-agenda-manipulate-query ?\{))
  6765. (defun org-agenda-manipulate-query-subtract-re ()
  6766. "Manipulate the query by adding a search regexp with negative selection.
  6767. Negative selection means regexp must not match for selection of an entry."
  6768. (interactive)
  6769. (org-agenda-manipulate-query ?\}))
  6770. (defun org-agenda-manipulate-query (char)
  6771. (cond
  6772. ((memq org-agenda-type '(timeline agenda))
  6773. (let ((org-agenda-include-inactive-timestamps t))
  6774. (org-agenda-redo))
  6775. (message "Display now includes inactive timestamps as well"))
  6776. ((eq org-agenda-type 'search)
  6777. (org-add-to-string
  6778. 'org-agenda-query-string
  6779. (if org-agenda-last-search-view-search-was-boolean
  6780. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6781. (?\{ . " +{}") (?\} . " -{}"))))
  6782. " "))
  6783. (setq org-agenda-redo-command
  6784. (list 'org-search-view
  6785. (car (get-text-property (min (1- (point-max)) (point))
  6786. 'org-last-args))
  6787. org-agenda-query-string
  6788. (+ (length org-agenda-query-string)
  6789. (if (member char '(?\{ ?\})) 0 1))))
  6790. (set-register org-agenda-query-register org-agenda-query-string)
  6791. (let ((org-agenda-overriding-arguments
  6792. (cdr org-agenda-redo-command)))
  6793. (org-agenda-redo)))
  6794. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6795. org-agenda-type))))
  6796. (defun org-add-to-string (var string)
  6797. (set var (concat (symbol-value var) string)))
  6798. (defun org-agenda-goto-date (span)
  6799. "Jump to DATE in agenda."
  6800. (interactive "P")
  6801. (let* ((org-read-date-prefer-future
  6802. (eval org-agenda-jump-prefer-future))
  6803. (date (org-read-date))
  6804. (org-agenda-sticky-orig org-agenda-sticky)
  6805. (org-agenda-buffer-tmp-name (buffer-name))
  6806. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6807. (0-arg (or current-prefix-arg (car args)))
  6808. (2-arg (nth 2 args))
  6809. (newcmd (list 'org-agenda-list 0-arg date
  6810. (org-agenda-span-to-ndays 2-arg)))
  6811. (newargs (cdr newcmd))
  6812. (inhibit-read-only t)
  6813. org-agenda-sticky)
  6814. (if (not (org-agenda-check-type t 'agenda))
  6815. (error "Not available in non-agenda blocks")
  6816. (add-text-properties (point-min) (point-max)
  6817. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6818. (org-agenda-redo)
  6819. (setq org-agenda-sticky org-agenda-sticky-orig
  6820. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6821. (defun org-agenda-goto-today ()
  6822. "Go to today."
  6823. (interactive)
  6824. (org-agenda-check-type t 'timeline 'agenda)
  6825. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6826. (curspan (nth 2 args))
  6827. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6828. (cond
  6829. (tdpos (goto-char tdpos))
  6830. ((eq org-agenda-type 'agenda)
  6831. (let* ((sd (org-agenda-compute-starting-span
  6832. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6833. (org-agenda-overriding-arguments args))
  6834. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6835. (org-agenda-redo)
  6836. (org-agenda-find-same-or-today-or-agenda)))
  6837. (t (error "Cannot find today")))))
  6838. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6839. (goto-char
  6840. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6841. (text-property-any (point-min) (point-max) 'org-today t)
  6842. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6843. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  6844. (org-agenda-goto-block-beginning))
  6845. (point-min))))
  6846. (defun org-agenda-goto-block-beginning ()
  6847. "Go the agenda block beginning."
  6848. (interactive)
  6849. (if (not (derived-mode-p 'org-agenda-mode))
  6850. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6851. (let (dest)
  6852. (save-excursion
  6853. (unless (looking-at "\\'")
  6854. (forward-char))
  6855. (let* ((prop 'org-agenda-structural-header)
  6856. (p (previous-single-property-change (point) prop))
  6857. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6858. (1- (point))) prop)))
  6859. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6860. (if (not dest)
  6861. (error "Cannot find the beginning of the blog")
  6862. (goto-char dest)
  6863. (move-beginning-of-line 1)))))
  6864. (defun org-agenda-later (arg)
  6865. "Go forward in time by the current span.
  6866. With prefix ARG, go forward that many times the current span."
  6867. (interactive "p")
  6868. (org-agenda-check-type t 'agenda)
  6869. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6870. (span (or (nth 2 args) org-agenda-current-span))
  6871. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6872. (greg (calendar-gregorian-from-absolute sd))
  6873. (cnt (org-get-at-bol 'org-day-cnt))
  6874. greg2)
  6875. (cond
  6876. ((numberp span)
  6877. (setq sd (+ (* span arg) sd)))
  6878. ((eq span 'day)
  6879. (setq sd (+ arg sd)))
  6880. ((eq span 'week)
  6881. (setq sd (+ (* 7 arg) sd)))
  6882. ((eq span 'month)
  6883. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6884. sd (calendar-absolute-from-gregorian greg2))
  6885. (setcar greg2 (1+ (car greg2))))
  6886. ((eq span 'year)
  6887. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6888. sd (calendar-absolute-from-gregorian greg2))
  6889. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6890. (t
  6891. (setq sd (+ (* span arg) sd))))
  6892. (let ((org-agenda-overriding-cmd
  6893. ;; `cmd' may have been set by `org-agenda-run-series' which
  6894. ;; uses `org-agenda-overriding-cmd' to decide whether
  6895. ;; overriding is allowed for `cmd'
  6896. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  6897. (org-agenda-overriding-arguments
  6898. (list (car args) sd span)))
  6899. (org-agenda-redo)
  6900. (org-agenda-find-same-or-today-or-agenda cnt))))
  6901. (defun org-agenda-earlier (arg)
  6902. "Go backward in time by the current span.
  6903. With prefix ARG, go backward that many times the current span."
  6904. (interactive "p")
  6905. (org-agenda-later (- arg)))
  6906. (defun org-agenda-view-mode-dispatch ()
  6907. "Call one of the view mode commands."
  6908. (interactive)
  6909. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6910. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6911. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6912. (let ((a (read-char-exclusive)))
  6913. (case a
  6914. (?\ (call-interactively 'org-agenda-reset-view))
  6915. (?d (call-interactively 'org-agenda-day-view))
  6916. (?w (call-interactively 'org-agenda-week-view))
  6917. (?m (call-interactively 'org-agenda-month-view))
  6918. (?y (call-interactively 'org-agenda-year-view))
  6919. (?l (call-interactively 'org-agenda-log-mode))
  6920. (?L (org-agenda-log-mode '(4)))
  6921. (?c (org-agenda-log-mode 'clockcheck))
  6922. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6923. (?a (call-interactively 'org-agenda-archives-mode))
  6924. (?A (org-agenda-archives-mode 'files))
  6925. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6926. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6927. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6928. (?D (call-interactively 'org-agenda-toggle-diary))
  6929. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6930. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6931. (org-agenda-check-type t 'timeline 'agenda)
  6932. (org-agenda-redo))
  6933. (message "Display now includes inactive timestamps as well"))
  6934. (?q (message "Abort"))
  6935. (otherwise (error "Invalid key" )))))
  6936. (defun org-agenda-reset-view ()
  6937. "Switch to default view for agenda."
  6938. (interactive)
  6939. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6940. (defun org-agenda-day-view (&optional day-of-year)
  6941. "Switch to daily view for agenda.
  6942. With argument DAY-OF-YEAR, switch to that day of the year."
  6943. (interactive "P")
  6944. (org-agenda-change-time-span 'day day-of-year))
  6945. (defun org-agenda-week-view (&optional iso-week)
  6946. "Switch to daily view for agenda.
  6947. With argument ISO-WEEK, switch to the corresponding ISO week.
  6948. If ISO-WEEK has more then 2 digits, only the last two encode the
  6949. week. Any digits before this encode a year. So 200712 means
  6950. week 12 of year 2007. Years in the range 1938-2037 can also be
  6951. written as 2-digit years."
  6952. (interactive "P")
  6953. (org-agenda-change-time-span 'week iso-week))
  6954. (defun org-agenda-month-view (&optional month)
  6955. "Switch to monthly view for agenda.
  6956. With argument MONTH, switch to that month."
  6957. (interactive "P")
  6958. (org-agenda-change-time-span 'month month))
  6959. (defun org-agenda-year-view (&optional year)
  6960. "Switch to yearly view for agenda.
  6961. With argument YEAR, switch to that year.
  6962. If MONTH has more then 2 digits, only the last two encode the
  6963. month. Any digits before this encode a year. So 200712 means
  6964. December year 2007. Years in the range 1938-2037 can also be
  6965. written as 2-digit years."
  6966. (interactive "P")
  6967. (when year
  6968. (setq year (org-small-year-to-year year)))
  6969. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6970. (org-agenda-change-time-span 'year year)
  6971. (error "Abort")))
  6972. (defun org-agenda-change-time-span (span &optional n)
  6973. "Change the agenda view to SPAN.
  6974. SPAN may be `day', `week', `month', `year'."
  6975. (org-agenda-check-type t 'agenda)
  6976. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6977. (curspan (nth 2 args)))
  6978. (if (and (not n) (equal curspan span))
  6979. (error "Viewing span is already \"%s\"" span))
  6980. (let* ((sd (or (org-get-at-bol 'day)
  6981. (nth 1 args)
  6982. org-starting-day))
  6983. (sd (org-agenda-compute-starting-span sd span n))
  6984. (org-agenda-overriding-cmd
  6985. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  6986. (org-agenda-overriding-arguments
  6987. (list (car args) sd span)))
  6988. (org-agenda-redo)
  6989. (org-agenda-find-same-or-today-or-agenda))
  6990. (org-agenda-set-mode-name)
  6991. (message "Switched to %s view" span)))
  6992. (defun org-agenda-compute-starting-span (sd span &optional n)
  6993. "Compute starting date for agenda.
  6994. SPAN may be `day', `week', `month', `year'. The return value
  6995. is a cons cell with the starting date and the number of days,
  6996. so that the date SD will be in that range."
  6997. (let* ((greg (calendar-gregorian-from-absolute sd))
  6998. (dg (nth 1 greg))
  6999. (mg (car greg))
  7000. (yg (nth 2 greg)))
  7001. (cond
  7002. ((eq span 'day)
  7003. (when n
  7004. (setq sd (+ (calendar-absolute-from-gregorian
  7005. (list mg 1 yg))
  7006. n -1))))
  7007. ((eq span 'week)
  7008. (let* ((nt (calendar-day-of-week
  7009. (calendar-gregorian-from-absolute sd)))
  7010. (d (if org-agenda-start-on-weekday
  7011. (- nt org-agenda-start-on-weekday)
  7012. 0))
  7013. y1)
  7014. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7015. (when n
  7016. (require 'cal-iso)
  7017. (when (> n 99)
  7018. (setq y1 (org-small-year-to-year (/ n 100))
  7019. n (mod n 100)))
  7020. (setq sd
  7021. (calendar-absolute-from-iso
  7022. (list n 1
  7023. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7024. ((eq span 'month)
  7025. (let (y1)
  7026. (when (and n (> n 99))
  7027. (setq y1 (org-small-year-to-year (/ n 100))
  7028. n (mod n 100)))
  7029. (setq sd (calendar-absolute-from-gregorian
  7030. (list (or n mg) 1 (or y1 yg))))))
  7031. ((eq span 'year)
  7032. (setq sd (calendar-absolute-from-gregorian
  7033. (list 1 1 (or n yg))))))
  7034. sd))
  7035. (defun org-agenda-next-date-line (&optional arg)
  7036. "Jump to the next line indicating a date in agenda buffer."
  7037. (interactive "p")
  7038. (org-agenda-check-type t 'agenda 'timeline)
  7039. (beginning-of-line 1)
  7040. ;; This does not work if user makes date format that starts with a blank
  7041. (if (looking-at "^\\S-") (forward-char 1))
  7042. (if (not (re-search-forward "^\\S-" nil t arg))
  7043. (progn
  7044. (backward-char 1)
  7045. (error "No next date after this line in this buffer")))
  7046. (goto-char (match-beginning 0)))
  7047. (defun org-agenda-previous-date-line (&optional arg)
  7048. "Jump to the previous line indicating a date in agenda buffer."
  7049. (interactive "p")
  7050. (org-agenda-check-type t 'agenda 'timeline)
  7051. (beginning-of-line 1)
  7052. (if (not (re-search-backward "^\\S-" nil t arg))
  7053. (error "No previous date before this line in this buffer")))
  7054. ;; Initialize the highlight
  7055. (defvar org-hl (make-overlay 1 1))
  7056. (overlay-put org-hl 'face 'highlight)
  7057. (defun org-highlight (begin end &optional buffer)
  7058. "Highlight a region with overlay."
  7059. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7060. (defun org-unhighlight ()
  7061. "Detach overlay INDEX."
  7062. (org-detach-overlay org-hl))
  7063. (defun org-unhighlight-once ()
  7064. "Remove the highlight from its position, and this function from the hook."
  7065. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7066. (org-unhighlight))
  7067. (defvar org-agenda-pre-follow-window-conf nil)
  7068. (defun org-agenda-follow-mode ()
  7069. "Toggle follow mode in an agenda buffer."
  7070. (interactive)
  7071. (unless org-agenda-follow-mode
  7072. (setq org-agenda-pre-follow-window-conf
  7073. (current-window-configuration)))
  7074. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7075. (unless org-agenda-follow-mode
  7076. (set-window-configuration org-agenda-pre-follow-window-conf))
  7077. (org-agenda-set-mode-name)
  7078. (org-agenda-do-context-action)
  7079. (message "Follow mode is %s"
  7080. (if org-agenda-follow-mode "on" "off")))
  7081. (defun org-agenda-entry-text-mode (&optional arg)
  7082. "Toggle entry text mode in an agenda buffer."
  7083. (interactive "P")
  7084. (setq org-agenda-entry-text-mode (or (integerp arg)
  7085. (not org-agenda-entry-text-mode)))
  7086. (org-agenda-entry-text-hide)
  7087. (and org-agenda-entry-text-mode
  7088. (let ((org-agenda-entry-text-maxlines
  7089. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7090. (org-agenda-entry-text-show)))
  7091. (org-agenda-set-mode-name)
  7092. (message "Entry text mode is %s. Maximum number of lines is %d"
  7093. (if org-agenda-entry-text-mode "on" "off")
  7094. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7095. (defun org-agenda-clockreport-mode (&optional with-filter)
  7096. "Toggle clocktable mode in an agenda buffer.
  7097. With prefix arg WITH-FILTER, make the clocktable respect the current
  7098. agenda filter."
  7099. (interactive "P")
  7100. (org-agenda-check-type t 'agenda)
  7101. (if with-filter
  7102. (setq org-agenda-clockreport-mode 'with-filter)
  7103. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7104. (org-agenda-set-mode-name)
  7105. (org-agenda-redo)
  7106. (message "Clocktable mode is %s"
  7107. (if org-agenda-clockreport-mode "on" "off")))
  7108. (defun org-agenda-log-mode (&optional special)
  7109. "Toggle log mode in an agenda buffer.
  7110. With argument SPECIAL, show all possible log items, not only the ones
  7111. configured in `org-agenda-log-mode-items'.
  7112. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7113. (interactive "P")
  7114. (org-agenda-check-type t 'agenda 'timeline)
  7115. (setq org-agenda-show-log
  7116. (cond
  7117. ((equal special '(16)) 'only)
  7118. ((eq special 'clockcheck)
  7119. (if (eq org-agenda-show-log 'clockcheck)
  7120. nil 'clockcheck))
  7121. (special '(closed clock state))
  7122. (t (not org-agenda-show-log))))
  7123. (org-agenda-set-mode-name)
  7124. (org-agenda-redo)
  7125. (message "Log mode is %s"
  7126. (if org-agenda-show-log "on" "off")))
  7127. (defun org-agenda-archives-mode (&optional with-files)
  7128. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7129. When called with a prefix argument, include all archive files as well."
  7130. (interactive "P")
  7131. (setq org-agenda-archives-mode
  7132. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7133. (org-agenda-set-mode-name)
  7134. (org-agenda-redo)
  7135. (message
  7136. "%s"
  7137. (cond
  7138. ((eq org-agenda-archives-mode nil)
  7139. "No archives are included")
  7140. ((eq org-agenda-archives-mode 'trees)
  7141. (format "Trees with :%s: tag are included" org-archive-tag))
  7142. ((eq org-agenda-archives-mode t)
  7143. (format "Trees with :%s: tag and all active archive files are included"
  7144. org-archive-tag)))))
  7145. (defun org-agenda-toggle-diary ()
  7146. "Toggle diary inclusion in an agenda buffer."
  7147. (interactive)
  7148. (org-agenda-check-type t 'agenda)
  7149. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7150. (org-agenda-redo)
  7151. (org-agenda-set-mode-name)
  7152. (message "Diary inclusion turned %s"
  7153. (if org-agenda-include-diary "on" "off")))
  7154. (defun org-agenda-toggle-deadlines ()
  7155. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7156. (interactive)
  7157. (org-agenda-check-type t 'agenda)
  7158. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7159. (org-agenda-redo)
  7160. (org-agenda-set-mode-name)
  7161. (message "Deadlines inclusion turned %s"
  7162. (if org-agenda-include-deadlines "on" "off")))
  7163. (defun org-agenda-toggle-time-grid ()
  7164. "Toggle time grid in an agenda buffer."
  7165. (interactive)
  7166. (org-agenda-check-type t 'agenda)
  7167. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7168. (org-agenda-redo)
  7169. (org-agenda-set-mode-name)
  7170. (message "Time-grid turned %s"
  7171. (if org-agenda-use-time-grid "on" "off")))
  7172. (defun org-agenda-set-mode-name ()
  7173. "Set the mode name to indicate all the small mode settings."
  7174. (setq mode-name
  7175. (list "Org-Agenda"
  7176. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7177. " "
  7178. '(:eval (org-agenda-span-name org-agenda-current-span))
  7179. (if org-agenda-follow-mode " Follow" "")
  7180. (if org-agenda-entry-text-mode " ETxt" "")
  7181. (if org-agenda-include-diary " Diary" "")
  7182. (if org-agenda-include-deadlines " Ddl" "")
  7183. (if org-agenda-use-time-grid " Grid" "")
  7184. (if (and (boundp 'org-habit-show-habits)
  7185. org-habit-show-habits) " Habit" "")
  7186. (cond
  7187. ((consp org-agenda-show-log) " LogAll")
  7188. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7189. (org-agenda-show-log " Log")
  7190. (t ""))
  7191. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7192. :preset-filter))
  7193. '(:eval (org-propertize
  7194. (concat " <"
  7195. (mapconcat
  7196. 'identity
  7197. (append
  7198. (get 'org-agenda-category-filter :preset-filter)
  7199. org-agenda-category-filter)
  7200. "")
  7201. ">")
  7202. 'face 'org-agenda-filter-category
  7203. 'help-echo "Category used in filtering"))
  7204. "")
  7205. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7206. :preset-filter))
  7207. '(:eval (org-propertize
  7208. (concat " {"
  7209. (mapconcat
  7210. 'identity
  7211. (append
  7212. (get 'org-agenda-tag-filter :preset-filter)
  7213. org-agenda-tag-filter)
  7214. "")
  7215. "}")
  7216. 'face 'org-agenda-filter-tags
  7217. 'help-echo "Tags used in filtering"))
  7218. "")
  7219. (if org-agenda-archives-mode
  7220. (if (eq org-agenda-archives-mode t)
  7221. " Archives"
  7222. (format " :%s:" org-archive-tag))
  7223. "")
  7224. (if org-agenda-clockreport-mode
  7225. (if (eq org-agenda-clockreport-mode 'with-filter)
  7226. " Clock{}" " Clock")
  7227. "")))
  7228. (force-mode-line-update))
  7229. (org-define-obsolete-function-alias
  7230. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7231. (defun org-agenda-update-agenda-type ()
  7232. "Update the agenda type after each command."
  7233. (setq org-agenda-type
  7234. (or (get-text-property (point) 'org-agenda-type)
  7235. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7236. (defun org-agenda-next-line ()
  7237. "Move cursor to the next line, and show if follow mode is active."
  7238. (interactive)
  7239. (call-interactively 'next-line)
  7240. (org-agenda-do-context-action))
  7241. (defun org-agenda-previous-line ()
  7242. "Move cursor to the previous line, and show if follow-mode is active."
  7243. (interactive)
  7244. (call-interactively 'previous-line)
  7245. (org-agenda-do-context-action))
  7246. (defun org-agenda-next-item (n)
  7247. "Move cursor to next agenda item."
  7248. (interactive "p")
  7249. (let ((col (current-column)))
  7250. (dotimes (c n)
  7251. (when (next-single-property-change (point-at-eol) 'org-marker)
  7252. (move-end-of-line 1)
  7253. (goto-char (next-single-property-change (point) 'org-marker))))
  7254. (org-move-to-column col))
  7255. (org-agenda-do-context-action))
  7256. (defun org-agenda-previous-item (n)
  7257. "Move cursor to next agenda item."
  7258. (interactive "p")
  7259. (dotimes (c n)
  7260. (let ((col (current-column))
  7261. (goto (save-excursion
  7262. (move-end-of-line 0)
  7263. (previous-single-property-change (point) 'org-marker))))
  7264. (if goto (goto-char goto))
  7265. (org-move-to-column col)))
  7266. (org-agenda-do-context-action))
  7267. (defun org-agenda-do-context-action ()
  7268. "Show outline path and, maybe, follow mode window."
  7269. (let ((m (org-get-at-bol 'org-marker)))
  7270. (when (and (markerp m) (marker-buffer m))
  7271. (and org-agenda-follow-mode
  7272. (if org-agenda-follow-indirect
  7273. (org-agenda-tree-to-indirect-buffer nil)
  7274. (org-agenda-show)))
  7275. (and org-agenda-show-outline-path
  7276. (org-with-point-at m (org-display-outline-path t))))))
  7277. (defun org-agenda-show-tags ()
  7278. "Show the tags applicable to the current item."
  7279. (interactive)
  7280. (let* ((tags (org-get-at-bol 'tags)))
  7281. (if tags
  7282. (message "Tags are :%s:"
  7283. (org-no-properties (mapconcat 'identity tags ":")))
  7284. (message "No tags associated with this line"))))
  7285. (defun org-agenda-goto (&optional highlight)
  7286. "Go to the Org-mode file which contains the item at point."
  7287. (interactive)
  7288. (let* ((marker (or (org-get-at-bol 'org-marker)
  7289. (org-agenda-error)))
  7290. (buffer (marker-buffer marker))
  7291. (pos (marker-position marker)))
  7292. (switch-to-buffer-other-window buffer)
  7293. (widen)
  7294. (push-mark)
  7295. (goto-char pos)
  7296. (when (derived-mode-p 'org-mode)
  7297. (org-show-context 'agenda)
  7298. (save-excursion
  7299. (and (outline-next-heading)
  7300. (org-flag-heading nil)))) ; show the next heading
  7301. (when (outline-invisible-p)
  7302. (show-entry)) ; display invisible text
  7303. (recenter (/ (window-height) 2))
  7304. (run-hooks 'org-agenda-after-show-hook)
  7305. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7306. (defvar org-agenda-after-show-hook nil
  7307. "Normal hook run after an item has been shown from the agenda.
  7308. Point is in the buffer where the item originated.")
  7309. (defun org-agenda-kill ()
  7310. "Kill the entry or subtree belonging to the current agenda entry."
  7311. (interactive)
  7312. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7313. (let* ((bufname-orig (buffer-name))
  7314. (marker (or (org-get-at-bol 'org-marker)
  7315. (org-agenda-error)))
  7316. (buffer (marker-buffer marker))
  7317. (pos (marker-position marker))
  7318. (type (org-get-at-bol 'type))
  7319. dbeg dend (n 0) conf)
  7320. (org-with-remote-undo buffer
  7321. (with-current-buffer buffer
  7322. (save-excursion
  7323. (goto-char pos)
  7324. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7325. (setq dbeg (progn (org-back-to-heading t) (point))
  7326. dend (org-end-of-subtree t t))
  7327. (setq dbeg (point-at-bol)
  7328. dend (min (point-max) (1+ (point-at-eol)))))
  7329. (goto-char dbeg)
  7330. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7331. (setq conf (or (eq t org-agenda-confirm-kill)
  7332. (and (numberp org-agenda-confirm-kill)
  7333. (> n org-agenda-confirm-kill))))
  7334. (and conf
  7335. (not (y-or-n-p
  7336. (format "Delete entry with %d lines in buffer \"%s\"? "
  7337. n (buffer-name buffer))))
  7338. (error "Abort"))
  7339. (let ((org-agenda-buffer-name bufname-orig))
  7340. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7341. (with-current-buffer buffer (delete-region dbeg dend))
  7342. (message "Agenda item and source killed"))))
  7343. (defvar org-archive-default-command) ; defined in org-archive.el
  7344. (defun org-agenda-archive-default ()
  7345. "Archive the entry or subtree belonging to the current agenda entry."
  7346. (interactive)
  7347. (require 'org-archive)
  7348. (org-agenda-archive-with org-archive-default-command))
  7349. (defun org-agenda-archive-default-with-confirmation ()
  7350. "Archive the entry or subtree belonging to the current agenda entry."
  7351. (interactive)
  7352. (require 'org-archive)
  7353. (org-agenda-archive-with org-archive-default-command 'confirm))
  7354. (defun org-agenda-archive ()
  7355. "Archive the entry or subtree belonging to the current agenda entry."
  7356. (interactive)
  7357. (org-agenda-archive-with 'org-archive-subtree))
  7358. (defun org-agenda-archive-to-archive-sibling ()
  7359. "Move the entry to the archive sibling."
  7360. (interactive)
  7361. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7362. (defun org-agenda-archive-with (cmd &optional confirm)
  7363. "Move the entry to the archive sibling."
  7364. (interactive)
  7365. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7366. (let* ((bufname-orig (buffer-name))
  7367. (marker (or (org-get-at-bol 'org-marker)
  7368. (org-agenda-error)))
  7369. (buffer (marker-buffer marker))
  7370. (pos (marker-position marker)))
  7371. (org-with-remote-undo buffer
  7372. (with-current-buffer buffer
  7373. (if (derived-mode-p 'org-mode)
  7374. (if (and confirm
  7375. (not (y-or-n-p "Archive this subtree or entry? ")))
  7376. (error "Abort")
  7377. (save-excursion
  7378. (goto-char pos)
  7379. (let ((org-agenda-buffer-name bufname-orig))
  7380. (org-remove-subtree-entries-from-agenda))
  7381. (org-back-to-heading t)
  7382. (funcall cmd)))
  7383. (error "Archiving works only in Org-mode files"))))))
  7384. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7385. "Remove all lines in the agenda that correspond to a given subtree.
  7386. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7387. If this information is not given, the function uses the tree at point."
  7388. (let ((buf (or buf (current-buffer))) m p)
  7389. (save-excursion
  7390. (unless (and beg end)
  7391. (org-back-to-heading t)
  7392. (setq beg (point))
  7393. (org-end-of-subtree t)
  7394. (setq end (point)))
  7395. (set-buffer (get-buffer org-agenda-buffer-name))
  7396. (save-excursion
  7397. (goto-char (point-max))
  7398. (beginning-of-line 1)
  7399. (while (not (bobp))
  7400. (when (and (setq m (org-get-at-bol 'org-marker))
  7401. (equal buf (marker-buffer m))
  7402. (setq p (marker-position m))
  7403. (>= p beg)
  7404. (< p end))
  7405. (let ((inhibit-read-only t))
  7406. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7407. (beginning-of-line 0))))))
  7408. (defun org-agenda-refile (&optional goto rfloc no-update)
  7409. "Refile the item at point."
  7410. (interactive "P")
  7411. (if (equal goto '(16))
  7412. (org-refile-goto-last-stored)
  7413. (let* ((buffer-orig (buffer-name))
  7414. (marker (or (org-get-at-bol 'org-hd-marker)
  7415. (org-agenda-error)))
  7416. (buffer (marker-buffer marker))
  7417. (pos (marker-position marker))
  7418. (rfloc (or rfloc
  7419. (org-refile-get-location
  7420. (if goto "Goto" "Refile to") buffer
  7421. org-refile-allow-creating-parent-nodes))))
  7422. (with-current-buffer buffer
  7423. (save-excursion
  7424. (save-restriction
  7425. (widen)
  7426. (goto-char marker)
  7427. (let ((org-agenda-buffer-name buffer-orig))
  7428. (org-remove-subtree-entries-from-agenda))
  7429. (org-refile goto buffer rfloc)))))
  7430. (unless no-update (org-agenda-redo))))
  7431. (defun org-agenda-open-link (&optional arg)
  7432. "Open the link(s) in the current entry, if any.
  7433. This looks for a link in the displayed line in the agenda.
  7434. It also looks at the text of the entry itself."
  7435. (interactive "P")
  7436. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7437. (org-get-at-bol 'org-marker)))
  7438. (buffer (and marker (marker-buffer marker)))
  7439. (prefix (buffer-substring
  7440. (point-at-bol) (point-at-eol)))
  7441. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7442. (lk (car lkall))
  7443. (lkend (cdr lkall))
  7444. trg)
  7445. (cond
  7446. ((and buffer (stringp lk))
  7447. (with-current-buffer buffer
  7448. (setq trg (and (string-match org-bracket-link-regexp lk)
  7449. (match-string 1 lk)))
  7450. (if (or (not trg) (string-match org-any-link-re trg))
  7451. (save-excursion
  7452. (save-restriction
  7453. (widen)
  7454. (goto-char marker)
  7455. (when (search-forward lk nil lkend)
  7456. (goto-char (match-beginning 0))
  7457. (org-open-at-point))))
  7458. ;; This is an internal link, widen the buffer
  7459. (switch-to-buffer-other-window buffer)
  7460. (widen)
  7461. (goto-char marker)
  7462. (when (search-forward lk nil lkend)
  7463. (goto-char (match-beginning 0))
  7464. (org-open-at-point)))))
  7465. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7466. (save-excursion
  7467. (beginning-of-line 1)
  7468. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7469. (org-open-link-from-string (match-string 1)))
  7470. (t (message "No link to open here")))))
  7471. (defun org-agenda-copy-local-variable (var)
  7472. "Get a variable from a referenced buffer and install it here."
  7473. (let ((m (org-get-at-bol 'org-marker)))
  7474. (when (and m (buffer-live-p (marker-buffer m)))
  7475. (org-set-local var (with-current-buffer (marker-buffer m)
  7476. (symbol-value var))))))
  7477. (defun org-agenda-switch-to (&optional delete-other-windows)
  7478. "Go to the Org-mode file which contains the item at point."
  7479. (interactive)
  7480. (if (and org-return-follows-link
  7481. (not (org-get-at-bol 'org-marker))
  7482. (org-in-regexp org-bracket-link-regexp))
  7483. (org-open-link-from-string (match-string 0))
  7484. (let* ((marker (or (org-get-at-bol 'org-marker)
  7485. (org-agenda-error)))
  7486. (buffer (marker-buffer marker))
  7487. (pos (marker-position marker)))
  7488. (org-pop-to-buffer-same-window buffer)
  7489. (and delete-other-windows (delete-other-windows))
  7490. (widen)
  7491. (goto-char pos)
  7492. (when (derived-mode-p 'org-mode)
  7493. (org-show-context 'agenda)
  7494. (save-excursion
  7495. (and (outline-next-heading)
  7496. (org-flag-heading nil))) ; show the next heading
  7497. (when (outline-invisible-p)
  7498. (show-entry)) ; display invisible text
  7499. (run-hooks 'org-agenda-after-show-hook)))))
  7500. (defun org-agenda-goto-mouse (ev)
  7501. "Go to the Org-mode file which contains the item at the mouse click."
  7502. (interactive "e")
  7503. (mouse-set-point ev)
  7504. (org-agenda-goto))
  7505. (defun org-agenda-show (&optional full-entry)
  7506. "Display the Org-mode file which contains the item at point.
  7507. With prefix argument FULL-ENTRY, make the entire entry visible
  7508. if it was hidden in the outline."
  7509. (interactive "P")
  7510. (let ((win (selected-window)))
  7511. (if full-entry
  7512. (let ((org-show-entry-below t))
  7513. (org-agenda-goto t))
  7514. (org-agenda-goto t))
  7515. (select-window win)))
  7516. (defvar org-agenda-show-window nil)
  7517. (defun org-agenda-show-and-scroll-up (&optional arg)
  7518. "Display the Org-mode file which contains the item at point.
  7519. When called repeatedly, scroll the window that is displaying the buffer.
  7520. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7521. `show-subtree' to display the item, so that drawers and logbooks stay
  7522. folded."
  7523. (interactive "P")
  7524. (let ((win (selected-window)))
  7525. (if (and (window-live-p org-agenda-show-window)
  7526. (eq this-command last-command))
  7527. (progn
  7528. (select-window org-agenda-show-window)
  7529. (ignore-errors (scroll-up)))
  7530. (org-agenda-goto t)
  7531. (if arg (org-show-entry) (show-subtree))
  7532. (setq org-agenda-show-window (selected-window)))
  7533. (select-window win)))
  7534. (defun org-agenda-show-scroll-down ()
  7535. "Scroll down the window showing the agenda."
  7536. (interactive)
  7537. (let ((win (selected-window)))
  7538. (when (window-live-p org-agenda-show-window)
  7539. (select-window org-agenda-show-window)
  7540. (ignore-errors (scroll-down))
  7541. (select-window win))))
  7542. (defun org-agenda-show-1 (&optional more)
  7543. "Display the Org-mode file which contains the item at point.
  7544. The prefix arg selects the amount of information to display:
  7545. 0 hide the subtree
  7546. 1 just show the entry according to defaults.
  7547. 2 show the children view
  7548. 3 show the subtree view
  7549. 4 show the entire subtree and any LOGBOOK drawers
  7550. 5 show the entire subtree and any drawers
  7551. With prefix argument FULL-ENTRY, make the entire entry visible
  7552. if it was hidden in the outline."
  7553. (interactive "p")
  7554. (let ((win (selected-window)))
  7555. (org-agenda-goto t)
  7556. (org-recenter-heading 1)
  7557. (cond
  7558. ((= more 0)
  7559. (hide-subtree)
  7560. (save-excursion
  7561. (org-back-to-heading)
  7562. (run-hook-with-args 'org-cycle-hook 'folded))
  7563. (message "Remote: FOLDED"))
  7564. ((and (org-called-interactively-p 'any) (= more 1))
  7565. (message "Remote: show with default settings"))
  7566. ((= more 2)
  7567. (show-entry)
  7568. (show-children)
  7569. (save-excursion
  7570. (org-back-to-heading)
  7571. (run-hook-with-args 'org-cycle-hook 'children))
  7572. (message "Remote: CHILDREN"))
  7573. ((= more 3)
  7574. (show-subtree)
  7575. (save-excursion
  7576. (org-back-to-heading)
  7577. (run-hook-with-args 'org-cycle-hook 'subtree))
  7578. (message "Remote: SUBTREE"))
  7579. ((= more 4)
  7580. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7581. (org-drawer-regexp
  7582. (concat "^[ \t]*:\\("
  7583. (mapconcat 'regexp-quote org-drawers "\\|")
  7584. "\\):[ \t]*$")))
  7585. (show-subtree)
  7586. (save-excursion
  7587. (org-back-to-heading)
  7588. (org-cycle-hide-drawers 'subtree)))
  7589. (message "Remote: SUBTREE AND LOGBOOK"))
  7590. ((> more 4)
  7591. (show-subtree)
  7592. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7593. (select-window win)))
  7594. (defun org-recenter-heading (n)
  7595. (save-excursion
  7596. (org-back-to-heading)
  7597. (recenter n)))
  7598. (defvar org-agenda-cycle-counter nil)
  7599. (defun org-agenda-cycle-show (&optional n)
  7600. "Show the current entry in another window, with default settings.
  7601. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7602. When use repeatedly in immediate succession, the remote entry will cycle
  7603. through visibility
  7604. children -> subtree -> folded
  7605. When called with a numeric prefix arg, that arg will be passed through to
  7606. `org-agenda-show-1'. For the interpretation of that argument, see the
  7607. docstring of `org-agenda-show-1'."
  7608. (interactive "P")
  7609. (if (integerp n)
  7610. (setq org-agenda-cycle-counter n)
  7611. (if (not (eq last-command this-command))
  7612. (setq org-agenda-cycle-counter 1)
  7613. (if (equal org-agenda-cycle-counter 0)
  7614. (setq org-agenda-cycle-counter 2)
  7615. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7616. (if (> org-agenda-cycle-counter 3)
  7617. (setq org-agenda-cycle-counter 0)))))
  7618. (org-agenda-show-1 org-agenda-cycle-counter))
  7619. (defun org-agenda-recenter (arg)
  7620. "Display the Org-mode file which contains the item at point and recenter."
  7621. (interactive "P")
  7622. (let ((win (selected-window)))
  7623. (org-agenda-goto t)
  7624. (recenter arg)
  7625. (select-window win)))
  7626. (defun org-agenda-show-mouse (ev)
  7627. "Display the Org-mode file which contains the item at the mouse click."
  7628. (interactive "e")
  7629. (mouse-set-point ev)
  7630. (org-agenda-show))
  7631. (defun org-agenda-check-no-diary ()
  7632. "Check if the entry is a diary link and abort if yes."
  7633. (if (org-get-at-bol 'org-agenda-diary-link)
  7634. (org-agenda-error)))
  7635. (defun org-agenda-error ()
  7636. (error "Command not allowed in this line"))
  7637. (defun org-agenda-tree-to-indirect-buffer (arg)
  7638. "Show the subtree corresponding to the current entry in an indirect buffer.
  7639. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7640. With a numerical prefix ARG, go up to this level and then take that tree.
  7641. With a negative numeric ARG, go up by this number of levels.
  7642. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7643. use the dedicated frame)."
  7644. (interactive "P")
  7645. (if current-prefix-arg
  7646. (org-agenda-do-tree-to-indirect-buffer arg)
  7647. (let ((agenda-buffer (buffer-name))
  7648. (agenda-window (selected-window))
  7649. (indirect-window
  7650. (and org-last-indirect-buffer
  7651. (get-buffer-window org-last-indirect-buffer))))
  7652. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7653. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7654. (eq org-indirect-buffer-display 'dedicated-frame))
  7655. (unwind-protect
  7656. (unless (and indirect-window (window-live-p indirect-window))
  7657. (setq indirect-window (split-window agenda-window)))
  7658. (and indirect-window (select-window indirect-window))
  7659. (switch-to-buffer org-last-indirect-buffer :norecord)
  7660. (fit-window-to-buffer indirect-window)))
  7661. (select-window (get-buffer-window agenda-buffer)))))
  7662. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7663. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7664. (org-agenda-check-no-diary)
  7665. (let* ((marker (or (org-get-at-bol 'org-marker)
  7666. (org-agenda-error)))
  7667. (buffer (marker-buffer marker))
  7668. (pos (marker-position marker)))
  7669. (with-current-buffer buffer
  7670. (save-excursion
  7671. (goto-char pos)
  7672. (funcall 'org-tree-to-indirect-buffer arg)))))
  7673. (defvar org-last-heading-marker (make-marker)
  7674. "Marker pointing to the headline that last changed its TODO state
  7675. by a remote command from the agenda.")
  7676. (defun org-agenda-todo-nextset ()
  7677. "Switch TODO entry to next sequence."
  7678. (interactive)
  7679. (org-agenda-todo 'nextset))
  7680. (defun org-agenda-todo-previousset ()
  7681. "Switch TODO entry to previous sequence."
  7682. (interactive)
  7683. (org-agenda-todo 'previousset))
  7684. (defun org-agenda-todo (&optional arg)
  7685. "Cycle TODO state of line at point, also in Org-mode file.
  7686. This changes the line at point, all other lines in the agenda referring to
  7687. the same tree node, and the headline of the tree node in the Org-mode file."
  7688. (interactive "P")
  7689. (org-agenda-check-no-diary)
  7690. (let* ((col (current-column))
  7691. (marker (or (org-get-at-bol 'org-marker)
  7692. (org-agenda-error)))
  7693. (buffer (marker-buffer marker))
  7694. (pos (marker-position marker))
  7695. (hdmarker (org-get-at-bol 'org-hd-marker))
  7696. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7697. (inhibit-read-only t)
  7698. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7699. (org-with-remote-undo buffer
  7700. (with-current-buffer buffer
  7701. (widen)
  7702. (goto-char pos)
  7703. (org-show-context 'agenda)
  7704. (save-excursion
  7705. (and (outline-next-heading)
  7706. (org-flag-heading nil))) ; show the next heading
  7707. (let ((current-prefix-arg arg))
  7708. (call-interactively 'org-todo))
  7709. (and (bolp) (forward-char 1))
  7710. (setq newhead (org-get-heading))
  7711. (when (and (org-bound-and-true-p
  7712. org-agenda-headline-snapshot-before-repeat)
  7713. (not (equal org-agenda-headline-snapshot-before-repeat
  7714. newhead))
  7715. todayp)
  7716. (setq newhead org-agenda-headline-snapshot-before-repeat
  7717. just-one t))
  7718. (save-excursion
  7719. (org-back-to-heading)
  7720. (move-marker org-last-heading-marker (point))))
  7721. (beginning-of-line 1)
  7722. (save-excursion
  7723. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7724. (org-move-to-column col))))
  7725. (defun org-agenda-add-note (&optional arg)
  7726. "Add a time-stamped note to the entry at point."
  7727. (interactive "P")
  7728. (org-agenda-check-no-diary)
  7729. (let* ((marker (or (org-get-at-bol 'org-marker)
  7730. (org-agenda-error)))
  7731. (buffer (marker-buffer marker))
  7732. (pos (marker-position marker))
  7733. (hdmarker (org-get-at-bol 'org-hd-marker))
  7734. (inhibit-read-only t))
  7735. (with-current-buffer buffer
  7736. (widen)
  7737. (goto-char pos)
  7738. (org-show-context 'agenda)
  7739. (save-excursion
  7740. (and (outline-next-heading)
  7741. (org-flag-heading nil))) ; show the next heading
  7742. (org-add-note))))
  7743. (defun org-agenda-change-all-lines (newhead hdmarker
  7744. &optional fixface just-this)
  7745. "Change all lines in the agenda buffer which match HDMARKER.
  7746. The new content of the line will be NEWHEAD (as modified by
  7747. `org-agenda-format-item'). HDMARKER is checked with
  7748. `equal' against all `org-hd-marker' text properties in the file.
  7749. If FIXFACE is non-nil, the face of each item is modified according to
  7750. the new TODO state.
  7751. If JUST-THIS is non-nil, change just the current line, not all.
  7752. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7753. (let* ((inhibit-read-only t)
  7754. (line (org-current-line))
  7755. (org-agenda-buffer (current-buffer))
  7756. (thetags (with-current-buffer (marker-buffer hdmarker)
  7757. (save-excursion (save-restriction (widen)
  7758. (goto-char hdmarker)
  7759. (org-get-tags-at)))))
  7760. props m pl undone-face done-face finish new dotime level cat tags)
  7761. (save-excursion
  7762. (goto-char (point-max))
  7763. (beginning-of-line 1)
  7764. (while (not finish)
  7765. (setq finish (bobp))
  7766. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7767. (or (not just-this) (= (org-current-line) line))
  7768. (equal m hdmarker))
  7769. (setq props (text-properties-at (point))
  7770. dotime (org-get-at-bol 'dotime)
  7771. cat (org-get-at-bol 'org-category)
  7772. level (org-get-at-bol 'level)
  7773. tags thetags
  7774. new
  7775. (let ((org-prefix-format-compiled
  7776. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7777. org-prefix-format-compiled))
  7778. (extra (org-get-at-bol 'extra)))
  7779. (with-current-buffer (marker-buffer hdmarker)
  7780. (save-excursion
  7781. (save-restriction
  7782. (widen)
  7783. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7784. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7785. undone-face (org-get-at-bol 'undone-face)
  7786. done-face (org-get-at-bol 'done-face))
  7787. (beginning-of-line 1)
  7788. (cond
  7789. ((equal new "")
  7790. (and (looking-at ".*\n?") (replace-match "")))
  7791. ((looking-at ".*")
  7792. (replace-match new t t)
  7793. (beginning-of-line 1)
  7794. (add-text-properties (point-at-bol) (point-at-eol) props)
  7795. (when fixface
  7796. (add-text-properties
  7797. (point-at-bol) (point-at-eol)
  7798. (list 'face
  7799. (if org-last-todo-state-is-todo
  7800. undone-face done-face))))
  7801. (org-agenda-highlight-todo 'line)
  7802. (beginning-of-line 1))
  7803. (t (error "Line update did not work")))
  7804. (save-restriction
  7805. (narrow-to-region (point-at-bol) (point-at-eol))
  7806. (org-agenda-finalize)))
  7807. (beginning-of-line 0)))))
  7808. (defun org-agenda-align-tags (&optional line)
  7809. "Align all tags in agenda items to `org-agenda-tags-column'."
  7810. (let ((inhibit-read-only t) l c)
  7811. (save-excursion
  7812. (goto-char (if line (point-at-bol) (point-min)))
  7813. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7814. (if line (point-at-eol) nil) t)
  7815. (add-text-properties
  7816. (match-beginning 2) (match-end 2)
  7817. (list 'face (delq nil (let ((prop (get-text-property
  7818. (match-beginning 2) 'face)))
  7819. (or (listp prop) (setq prop (list prop)))
  7820. (if (memq 'org-tag prop)
  7821. prop
  7822. (cons 'org-tag prop))))))
  7823. (setq l (- (match-end 2) (match-beginning 2))
  7824. c (if (< org-agenda-tags-column 0)
  7825. (- (abs org-agenda-tags-column) l)
  7826. org-agenda-tags-column))
  7827. (delete-region (match-beginning 1) (match-end 1))
  7828. (goto-char (match-beginning 1))
  7829. (insert (org-add-props
  7830. (make-string (max 1 (- c (current-column))) ?\ )
  7831. (plist-put (copy-sequence (text-properties-at (point)))
  7832. 'face nil))))
  7833. (goto-char (point-min))
  7834. (org-font-lock-add-tag-faces (point-max)))))
  7835. (defun org-agenda-priority-up ()
  7836. "Increase the priority of line at point, also in Org-mode file."
  7837. (interactive)
  7838. (org-agenda-priority 'up))
  7839. (defun org-agenda-priority-down ()
  7840. "Decrease the priority of line at point, also in Org-mode file."
  7841. (interactive)
  7842. (org-agenda-priority 'down))
  7843. (defun org-agenda-priority (&optional force-direction)
  7844. "Set the priority of line at point, also in Org-mode file.
  7845. This changes the line at point, all other lines in the agenda referring to
  7846. the same tree node, and the headline of the tree node in the Org-mode file.
  7847. Called with a universal prefix arg, show the priority instead of setting it."
  7848. (interactive "P")
  7849. (if (equal force-direction '(4))
  7850. (org-show-priority)
  7851. (unless org-enable-priority-commands
  7852. (error "Priority commands are disabled"))
  7853. (org-agenda-check-no-diary)
  7854. (let* ((marker (or (org-get-at-bol 'org-marker)
  7855. (org-agenda-error)))
  7856. (hdmarker (org-get-at-bol 'org-hd-marker))
  7857. (buffer (marker-buffer hdmarker))
  7858. (pos (marker-position hdmarker))
  7859. (inhibit-read-only t)
  7860. newhead)
  7861. (org-with-remote-undo buffer
  7862. (with-current-buffer buffer
  7863. (widen)
  7864. (goto-char pos)
  7865. (org-show-context 'agenda)
  7866. (save-excursion
  7867. (and (outline-next-heading)
  7868. (org-flag-heading nil))) ; show the next heading
  7869. (funcall 'org-priority force-direction)
  7870. (end-of-line 1)
  7871. (setq newhead (org-get-heading)))
  7872. (org-agenda-change-all-lines newhead hdmarker)
  7873. (beginning-of-line 1)))))
  7874. ;; FIXME: should fix the tags property of the agenda line.
  7875. (defun org-agenda-set-tags (&optional tag onoff)
  7876. "Set tags for the current headline."
  7877. (interactive)
  7878. (org-agenda-check-no-diary)
  7879. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7880. (call-interactively 'org-change-tag-in-region)
  7881. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7882. (org-agenda-error)))
  7883. (buffer (marker-buffer hdmarker))
  7884. (pos (marker-position hdmarker))
  7885. (inhibit-read-only t)
  7886. newhead)
  7887. (org-with-remote-undo buffer
  7888. (with-current-buffer buffer
  7889. (widen)
  7890. (goto-char pos)
  7891. (save-excursion
  7892. (org-show-context 'agenda))
  7893. (save-excursion
  7894. (and (outline-next-heading)
  7895. (org-flag-heading nil))) ; show the next heading
  7896. (goto-char pos)
  7897. (if tag
  7898. (org-toggle-tag tag onoff)
  7899. (call-interactively 'org-set-tags))
  7900. (end-of-line 1)
  7901. (setq newhead (org-get-heading)))
  7902. (org-agenda-change-all-lines newhead hdmarker)
  7903. (beginning-of-line 1)))))
  7904. (defun org-agenda-set-property ()
  7905. "Set a property for the current headline."
  7906. (interactive)
  7907. (org-agenda-check-no-diary)
  7908. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7909. (org-agenda-error)))
  7910. (buffer (marker-buffer hdmarker))
  7911. (pos (marker-position hdmarker))
  7912. (inhibit-read-only t)
  7913. newhead)
  7914. (org-with-remote-undo buffer
  7915. (with-current-buffer buffer
  7916. (widen)
  7917. (goto-char pos)
  7918. (save-excursion
  7919. (org-show-context 'agenda))
  7920. (save-excursion
  7921. (and (outline-next-heading)
  7922. (org-flag-heading nil))) ; show the next heading
  7923. (goto-char pos)
  7924. (call-interactively 'org-set-property)))))
  7925. (defun org-agenda-set-effort ()
  7926. "Set the effort property for the current headline."
  7927. (interactive)
  7928. (org-agenda-check-no-diary)
  7929. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7930. (org-agenda-error)))
  7931. (buffer (marker-buffer hdmarker))
  7932. (pos (marker-position hdmarker))
  7933. (inhibit-read-only t)
  7934. newhead)
  7935. (org-with-remote-undo buffer
  7936. (with-current-buffer buffer
  7937. (widen)
  7938. (goto-char pos)
  7939. (save-excursion
  7940. (org-show-context 'agenda))
  7941. (save-excursion
  7942. (and (outline-next-heading)
  7943. (org-flag-heading nil))) ; show the next heading
  7944. (goto-char pos)
  7945. (call-interactively 'org-set-effort)
  7946. (end-of-line 1)
  7947. (setq newhead (org-get-heading)))
  7948. (org-agenda-change-all-lines newhead hdmarker))))
  7949. (defun org-agenda-toggle-archive-tag ()
  7950. "Toggle the archive tag for the current entry."
  7951. (interactive)
  7952. (org-agenda-check-no-diary)
  7953. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7954. (org-agenda-error)))
  7955. (buffer (marker-buffer hdmarker))
  7956. (pos (marker-position hdmarker))
  7957. (inhibit-read-only t)
  7958. newhead)
  7959. (org-with-remote-undo buffer
  7960. (with-current-buffer buffer
  7961. (widen)
  7962. (goto-char pos)
  7963. (org-show-context 'agenda)
  7964. (save-excursion
  7965. (and (outline-next-heading)
  7966. (org-flag-heading nil))) ; show the next heading
  7967. (call-interactively 'org-toggle-archive-tag)
  7968. (end-of-line 1)
  7969. (setq newhead (org-get-heading)))
  7970. (org-agenda-change-all-lines newhead hdmarker)
  7971. (beginning-of-line 1))))
  7972. (defun org-agenda-do-date-later (arg)
  7973. (interactive "P")
  7974. (cond
  7975. ((or (equal arg '(16))
  7976. (memq last-command
  7977. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7978. (setq this-command 'org-agenda-date-later-minutes)
  7979. (org-agenda-date-later-minutes 1))
  7980. ((or (equal arg '(4))
  7981. (memq last-command
  7982. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7983. (setq this-command 'org-agenda-date-later-hours)
  7984. (org-agenda-date-later-hours 1))
  7985. (t
  7986. (org-agenda-date-later (prefix-numeric-value arg)))))
  7987. (defun org-agenda-do-date-earlier (arg)
  7988. (interactive "P")
  7989. (cond
  7990. ((or (equal arg '(16))
  7991. (memq last-command
  7992. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7993. (setq this-command 'org-agenda-date-earlier-minutes)
  7994. (org-agenda-date-earlier-minutes 1))
  7995. ((or (equal arg '(4))
  7996. (memq last-command
  7997. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7998. (setq this-command 'org-agenda-date-earlier-hours)
  7999. (org-agenda-date-earlier-hours 1))
  8000. (t
  8001. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8002. (defun org-agenda-date-later (arg &optional what)
  8003. "Change the date of this item to ARG day(s) later."
  8004. (interactive "p")
  8005. (org-agenda-check-type t 'agenda 'timeline)
  8006. (org-agenda-check-no-diary)
  8007. (let* ((marker (or (org-get-at-bol 'org-marker)
  8008. (org-agenda-error)))
  8009. (buffer (marker-buffer marker))
  8010. (pos (marker-position marker))
  8011. cdate today)
  8012. (org-with-remote-undo buffer
  8013. (with-current-buffer buffer
  8014. (widen)
  8015. (goto-char pos)
  8016. (if (not (org-at-timestamp-p))
  8017. (error "Cannot find time stamp"))
  8018. (when (and org-agenda-move-date-from-past-immediately-to-today
  8019. (equal arg 1)
  8020. (or (not what) (eq what 'day))
  8021. (not (save-match-data (org-at-date-range-p))))
  8022. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8023. cdate (calendar-absolute-from-gregorian
  8024. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8025. today (org-today))
  8026. (if (> today cdate)
  8027. ;; immediately shift to today
  8028. (setq arg (- today cdate))))
  8029. (org-timestamp-change arg (or what 'day))
  8030. (when (and (org-at-date-range-p)
  8031. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8032. (let ((end org-last-changed-timestamp))
  8033. (org-timestamp-change arg (or what 'day))
  8034. (setq org-last-changed-timestamp
  8035. (concat org-last-changed-timestamp "--" end)))))
  8036. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8037. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8038. (defun org-agenda-date-earlier (arg &optional what)
  8039. "Change the date of this item to ARG day(s) earlier."
  8040. (interactive "p")
  8041. (org-agenda-date-later (- arg) what))
  8042. (defun org-agenda-date-later-minutes (arg)
  8043. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8044. (interactive "p")
  8045. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8046. (org-agenda-date-later arg 'minute))
  8047. (defun org-agenda-date-earlier-minutes (arg)
  8048. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8049. (interactive "p")
  8050. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8051. (org-agenda-date-earlier arg 'minute))
  8052. (defun org-agenda-date-later-hours (arg)
  8053. "Change the time of this item, in hour steps."
  8054. (interactive "p")
  8055. (org-agenda-date-later arg 'hour))
  8056. (defun org-agenda-date-earlier-hours (arg)
  8057. "Change the time of this item, in hour steps."
  8058. (interactive "p")
  8059. (org-agenda-date-earlier arg 'hour))
  8060. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8061. "Show new date stamp via text properties."
  8062. ;; We use text properties to make this undoable
  8063. (let ((inhibit-read-only t)
  8064. (buffer-invisibility-spec))
  8065. (setq stamp (concat " " prefix " => " stamp))
  8066. (save-excursion
  8067. (goto-char (point-max))
  8068. (while (not (bobp))
  8069. (when (equal marker (org-get-at-bol 'org-marker))
  8070. (org-move-to-column (- (window-width) (length stamp)) t)
  8071. (org-agenda-fix-tags-filter-overlays-at (point))
  8072. (if (featurep 'xemacs)
  8073. ;; Use `duplicable' property to trigger undo recording
  8074. (let ((ex (make-extent nil nil))
  8075. (gl (make-glyph stamp)))
  8076. (set-glyph-face gl 'secondary-selection)
  8077. (set-extent-properties
  8078. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8079. (insert-extent ex (1- (point)) (point-at-eol)))
  8080. (add-text-properties
  8081. (1- (point)) (point-at-eol)
  8082. (list 'display (org-add-props stamp nil
  8083. 'face 'secondary-selection))))
  8084. (beginning-of-line 1))
  8085. (beginning-of-line 0)))))
  8086. (defun org-agenda-date-prompt (arg)
  8087. "Change the date of this item. Date is prompted for, with default today.
  8088. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8089. be used to request time specification in the time stamp."
  8090. (interactive "P")
  8091. (org-agenda-check-type t 'agenda 'timeline)
  8092. (org-agenda-check-no-diary)
  8093. (let* ((marker (or (org-get-at-bol 'org-marker)
  8094. (org-agenda-error)))
  8095. (buffer (marker-buffer marker))
  8096. (pos (marker-position marker)))
  8097. (org-with-remote-undo buffer
  8098. (with-current-buffer buffer
  8099. (widen)
  8100. (goto-char pos)
  8101. (if (not (org-at-timestamp-p t))
  8102. (error "Cannot find time stamp"))
  8103. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8104. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8105. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8106. (defun org-agenda-schedule (arg &optional time)
  8107. "Schedule the item at point.
  8108. ARG is passed through to `org-schedule'."
  8109. (interactive "P")
  8110. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8111. (org-agenda-check-no-diary)
  8112. (let* ((marker (or (org-get-at-bol 'org-marker)
  8113. (org-agenda-error)))
  8114. (type (marker-insertion-type marker))
  8115. (buffer (marker-buffer marker))
  8116. (pos (marker-position marker))
  8117. (org-insert-labeled-timestamps-at-point nil)
  8118. ts)
  8119. (set-marker-insertion-type marker t)
  8120. (org-with-remote-undo buffer
  8121. (with-current-buffer buffer
  8122. (widen)
  8123. (goto-char pos)
  8124. (setq ts (org-schedule arg time)))
  8125. (org-agenda-show-new-time marker ts "S"))
  8126. (message "%s" ts)))
  8127. (defun org-agenda-deadline (arg &optional time)
  8128. "Schedule the item at point.
  8129. ARG is passed through to `org-deadline'."
  8130. (interactive "P")
  8131. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8132. (org-agenda-check-no-diary)
  8133. (let* ((marker (or (org-get-at-bol 'org-marker)
  8134. (org-agenda-error)))
  8135. (buffer (marker-buffer marker))
  8136. (pos (marker-position marker))
  8137. (org-insert-labeled-timestamps-at-point nil)
  8138. ts)
  8139. (org-with-remote-undo buffer
  8140. (with-current-buffer buffer
  8141. (widen)
  8142. (goto-char pos)
  8143. (setq ts (org-deadline arg time)))
  8144. (org-agenda-show-new-time marker ts "D"))
  8145. (message "%s" ts)))
  8146. (defun org-agenda-clock-in (&optional arg)
  8147. "Start the clock on the currently selected item."
  8148. (interactive "P")
  8149. (org-agenda-check-no-diary)
  8150. (if (equal arg '(4))
  8151. (org-clock-in arg)
  8152. (let* ((marker (or (org-get-at-bol 'org-marker)
  8153. (org-agenda-error)))
  8154. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  8155. marker))
  8156. (pos (marker-position marker))
  8157. newhead)
  8158. (org-with-remote-undo (marker-buffer marker)
  8159. (with-current-buffer (marker-buffer marker)
  8160. (widen)
  8161. (goto-char pos)
  8162. (org-show-context 'agenda)
  8163. (org-show-entry)
  8164. (org-cycle-hide-drawers 'children)
  8165. (org-clock-in arg)
  8166. (setq newhead (org-get-heading)))
  8167. (org-agenda-change-all-lines newhead hdmarker)))))
  8168. (defun org-agenda-clock-out ()
  8169. "Stop the currently running clock."
  8170. (interactive)
  8171. (unless (marker-buffer org-clock-marker)
  8172. (error "No running clock"))
  8173. (let ((marker (make-marker)) newhead)
  8174. (org-with-remote-undo (marker-buffer org-clock-marker)
  8175. (with-current-buffer (marker-buffer org-clock-marker)
  8176. (save-excursion
  8177. (save-restriction
  8178. (widen)
  8179. (goto-char org-clock-marker)
  8180. (org-back-to-heading t)
  8181. (move-marker marker (point))
  8182. (org-clock-out)
  8183. (setq newhead (org-get-heading))))))
  8184. (org-agenda-change-all-lines newhead marker)
  8185. (move-marker marker nil)))
  8186. (defun org-agenda-clock-cancel (&optional arg)
  8187. "Cancel the currently running clock."
  8188. (interactive "P")
  8189. (unless (marker-buffer org-clock-marker)
  8190. (error "No running clock"))
  8191. (org-with-remote-undo (marker-buffer org-clock-marker)
  8192. (org-clock-cancel)))
  8193. (defun org-agenda-clock-goto ()
  8194. "Jump to the currently clocked in task within the agenda.
  8195. If the currently clocked in task is not listed in the agenda
  8196. buffer, display it in another window."
  8197. (interactive)
  8198. (let (pos)
  8199. (mapc (lambda (o)
  8200. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8201. (setq pos (overlay-start o))))
  8202. (overlays-in (point-min) (point-max)))
  8203. (cond (pos (goto-char pos))
  8204. ;; If the currently clocked entry is not in the agenda
  8205. ;; buffer, we visit it in another window:
  8206. (org-clock-current-task
  8207. (org-switch-to-buffer-other-window (org-clock-goto)))
  8208. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8209. (defun org-agenda-diary-entry-in-org-file ()
  8210. "Make a diary entry in the file `org-agenda-diary-file'."
  8211. (let (d1 d2 char (text "") dp1 dp2)
  8212. (if (equal (buffer-name) "*Calendar*")
  8213. (setq d1 (calendar-cursor-to-date t)
  8214. d2 (car calendar-mark-ring))
  8215. (setq dp1 (get-text-property (point-at-bol) 'day))
  8216. (unless dp1 (error "No date defined in current line"))
  8217. (setq d1 (calendar-gregorian-from-absolute dp1)
  8218. d2 (and (ignore-errors (mark))
  8219. (save-excursion
  8220. (goto-char (mark))
  8221. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8222. (calendar-gregorian-from-absolute dp2))))
  8223. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8224. (setq char (read-char-exclusive))
  8225. (cond
  8226. ((equal char ?d)
  8227. (setq text (read-string "Day entry: "))
  8228. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8229. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8230. ((equal char ?a)
  8231. (setq d1 (list (car d1) (nth 1 d1)
  8232. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8233. (nth 2 d1))))
  8234. (setq text (read-string "Anniversary (use %d to show years): "))
  8235. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8236. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8237. ((equal char ?b)
  8238. (setq text (read-string "Block entry: "))
  8239. (unless (and d1 d2 (not (equal d1 d2)))
  8240. (error "No block of days selected"))
  8241. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8242. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8243. ((equal char ?j)
  8244. (org-switch-to-buffer-other-window
  8245. (find-file-noselect org-agenda-diary-file))
  8246. (require 'org-datetree)
  8247. (org-datetree-find-date-create d1)
  8248. (org-reveal t))
  8249. (t (error "Invalid selection character `%c'" char)))))
  8250. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8251. "Where in `org-agenda-diary-file' should new entries be added?
  8252. Valid values:
  8253. date-tree in the date tree, as child of the date
  8254. top-level as top-level entries at the end of the file."
  8255. :group 'org-agenda
  8256. :type '(choice
  8257. (const :tag "in a date tree" date-tree)
  8258. (const :tag "as top level at end of file" top-level)))
  8259. (defcustom org-agenda-insert-diary-extract-time nil
  8260. "Non-nil means extract any time specification from the diary entry."
  8261. :group 'org-agenda
  8262. :version "24.1"
  8263. :type 'boolean)
  8264. (defcustom org-agenda-bulk-mark-char ">"
  8265. "A single-character string to be used as the bulk mark."
  8266. :group 'org-agenda
  8267. :version "24.1"
  8268. :type 'string)
  8269. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8270. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8271. If TEXT is not empty, it will become the headline of the new entry, and
  8272. the resulting entry will not be shown. When TEXT is empty, switch to
  8273. `org-agenda-diary-file' and let the user finish the entry there."
  8274. (let ((cw (current-window-configuration)))
  8275. (org-switch-to-buffer-other-window
  8276. (find-file-noselect org-agenda-diary-file))
  8277. (widen)
  8278. (goto-char (point-min))
  8279. (cond
  8280. ((eq type 'anniversary)
  8281. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8282. (progn
  8283. (or (org-at-heading-p t)
  8284. (progn
  8285. (outline-next-heading)
  8286. (insert "* Anniversaries\n\n")
  8287. (beginning-of-line -1)))))
  8288. (outline-next-heading)
  8289. (org-back-over-empty-lines)
  8290. (backward-char 1)
  8291. (insert "\n")
  8292. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8293. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8294. ((eq type 'day)
  8295. (let ((org-prefix-has-time t)
  8296. (org-agenda-time-leading-zero t)
  8297. fmt time time2)
  8298. (if org-agenda-insert-diary-extract-time
  8299. ;; Use org-agenda-format-item to parse text for a time-range and
  8300. ;; remove it. FIXME: This is a hack, we should refactor
  8301. ;; that function to make time extraction available separately
  8302. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8303. time (get-text-property 0 'time fmt)
  8304. time2 (if (> (length time) 0)
  8305. ;; split-string removes trailing ...... if
  8306. ;; no end time given. First space
  8307. ;; separates time from date.
  8308. (concat " " (car (split-string time "\\.")))
  8309. nil)
  8310. text (get-text-property 0 'txt fmt)))
  8311. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8312. (org-agenda-insert-diary-as-top-level text)
  8313. (require 'org-datetree)
  8314. (org-datetree-find-date-create d1)
  8315. (org-agenda-insert-diary-make-new-entry text))
  8316. (org-insert-time-stamp (org-time-from-absolute
  8317. (calendar-absolute-from-gregorian d1))
  8318. nil nil nil nil time2))
  8319. (end-of-line 0))
  8320. ((eq type 'block)
  8321. (if (> (calendar-absolute-from-gregorian d1)
  8322. (calendar-absolute-from-gregorian d2))
  8323. (setq d1 (prog1 d2 (setq d2 d1))))
  8324. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8325. (org-agenda-insert-diary-as-top-level text)
  8326. (require 'org-datetree)
  8327. (org-datetree-find-date-create d1)
  8328. (org-agenda-insert-diary-make-new-entry text))
  8329. (org-insert-time-stamp (org-time-from-absolute
  8330. (calendar-absolute-from-gregorian d1)))
  8331. (insert "--")
  8332. (org-insert-time-stamp (org-time-from-absolute
  8333. (calendar-absolute-from-gregorian d2)))
  8334. (end-of-line 0)))
  8335. (if (string-match "\\S-" text)
  8336. (progn
  8337. (set-window-configuration cw)
  8338. (message "%s entry added to %s"
  8339. (capitalize (symbol-name type))
  8340. (abbreviate-file-name org-agenda-diary-file)))
  8341. (org-reveal t)
  8342. (message "Please finish entry here"))))
  8343. (defun org-agenda-insert-diary-as-top-level (text)
  8344. "Make new entry as a top-level entry at the end of the file.
  8345. Add TEXT as headline, and position the cursor in the second line so that
  8346. a timestamp can be added there."
  8347. (widen)
  8348. (goto-char (point-max))
  8349. (or (bolp) (insert "\n"))
  8350. (insert "* " text "\n")
  8351. (if org-adapt-indentation (org-indent-to-column 2)))
  8352. (defun org-agenda-insert-diary-make-new-entry (text)
  8353. "Make new entry as last child of current entry.
  8354. Add TEXT as headline, and position the cursor in the second line so that
  8355. a timestamp can be added there."
  8356. (let ((org-show-following-heading t)
  8357. (org-show-siblings t)
  8358. (org-show-hierarchy-above t)
  8359. (org-show-entry-below t)
  8360. col)
  8361. (outline-next-heading)
  8362. (org-back-over-empty-lines)
  8363. (or (looking-at "[ \t]*$")
  8364. (progn (insert "\n") (backward-char 1)))
  8365. (org-insert-heading nil t)
  8366. (org-do-demote)
  8367. (setq col (current-column))
  8368. (insert text "\n")
  8369. (if org-adapt-indentation (org-indent-to-column col))
  8370. (let ((org-show-following-heading t)
  8371. (org-show-siblings t)
  8372. (org-show-hierarchy-above t)
  8373. (org-show-entry-below t))
  8374. (org-show-context))))
  8375. (defun org-agenda-diary-entry ()
  8376. "Make a diary entry, like the `i' command from the calendar.
  8377. All the standard commands work: block, weekly etc.
  8378. When `org-agenda-diary-file' points to a file,
  8379. `org-agenda-diary-entry-in-org-file' is called instead to create
  8380. entries in that Org-mode file."
  8381. (interactive)
  8382. (if (not (eq org-agenda-diary-file 'diary-file))
  8383. (org-agenda-diary-entry-in-org-file)
  8384. (require 'diary-lib)
  8385. (let* ((char (progn
  8386. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8387. (read-char-exclusive)))
  8388. (cmd (cdr (assoc char
  8389. '((?d . insert-diary-entry)
  8390. (?w . insert-weekly-diary-entry)
  8391. (?m . insert-monthly-diary-entry)
  8392. (?y . insert-yearly-diary-entry)
  8393. (?a . insert-anniversary-diary-entry)
  8394. (?b . insert-block-diary-entry)
  8395. (?c . insert-cyclic-diary-entry)))))
  8396. (oldf (symbol-function 'calendar-cursor-to-date))
  8397. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8398. (point (point))
  8399. (mark (or (mark t) (point))))
  8400. (unless cmd
  8401. (error "No command associated with <%c>" char))
  8402. (unless (and (get-text-property point 'day)
  8403. (or (not (equal ?b char))
  8404. (get-text-property mark 'day)))
  8405. (error "Don't know which date to use for diary entry"))
  8406. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8407. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8408. (let ((calendar-mark-ring
  8409. (list (calendar-gregorian-from-absolute
  8410. (or (get-text-property mark 'day)
  8411. (get-text-property point 'day))))))
  8412. (unwind-protect
  8413. (progn
  8414. (fset 'calendar-cursor-to-date
  8415. (lambda (&optional error dummy)
  8416. (calendar-gregorian-from-absolute
  8417. (get-text-property point 'day))))
  8418. (call-interactively cmd))
  8419. (fset 'calendar-cursor-to-date oldf))))))
  8420. (defun org-agenda-execute-calendar-command (cmd)
  8421. "Execute a calendar command from the agenda with date from cursor."
  8422. (org-agenda-check-type t 'agenda 'timeline)
  8423. (require 'diary-lib)
  8424. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8425. (error "Don't know which date to use for the calendar command"))
  8426. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8427. (point (point))
  8428. (date (calendar-gregorian-from-absolute
  8429. (get-text-property point 'day)))
  8430. ;; the following 2 vars are needed in the calendar
  8431. (displayed-month (car date))
  8432. (displayed-year (nth 2 date)))
  8433. (unwind-protect
  8434. (progn
  8435. (fset 'calendar-cursor-to-date
  8436. (lambda (&optional error dummy)
  8437. (calendar-gregorian-from-absolute
  8438. (get-text-property point 'day))))
  8439. (call-interactively cmd))
  8440. (fset 'calendar-cursor-to-date oldf))))
  8441. (defun org-agenda-phases-of-moon ()
  8442. "Display the phases of the moon for the 3 months around the cursor date."
  8443. (interactive)
  8444. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8445. (defun org-agenda-holidays ()
  8446. "Display the holidays for the 3 months around the cursor date."
  8447. (interactive)
  8448. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8449. (defvar calendar-longitude) ; defined in calendar.el
  8450. (defvar calendar-latitude) ; defined in calendar.el
  8451. (defvar calendar-location-name) ; defined in calendar.el
  8452. (defun org-agenda-sunrise-sunset (arg)
  8453. "Display sunrise and sunset for the cursor date.
  8454. Latitude and longitude can be specified with the variables
  8455. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8456. argument, latitude and longitude will be prompted for."
  8457. (interactive "P")
  8458. (require 'solar)
  8459. (let ((calendar-longitude (if arg nil calendar-longitude))
  8460. (calendar-latitude (if arg nil calendar-latitude))
  8461. (calendar-location-name
  8462. (if arg "the given coordinates" calendar-location-name)))
  8463. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8464. (defun org-agenda-goto-calendar ()
  8465. "Open the Emacs calendar with the date at the cursor."
  8466. (interactive)
  8467. (org-agenda-check-type t 'agenda 'timeline)
  8468. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8469. (error "Don't know which date to open in calendar")))
  8470. (date (calendar-gregorian-from-absolute day))
  8471. (calendar-move-hook nil)
  8472. (calendar-view-holidays-initially-flag nil)
  8473. (calendar-view-diary-initially-flag nil))
  8474. (calendar)
  8475. (calendar-goto-date date)))
  8476. ;;;###autoload
  8477. (defun org-calendar-goto-agenda ()
  8478. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8479. This is a command that has to be installed in `calendar-mode-map'."
  8480. (interactive)
  8481. (org-agenda-list nil (calendar-absolute-from-gregorian
  8482. (calendar-cursor-to-date))
  8483. nil))
  8484. (autoload 'org-calendar-goto-agenda "org-agenda" "\
  8485. Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8486. This is a command that has to be installed in `calendar-mode-map'.
  8487. \(fn)" t nil)
  8488. (defun org-agenda-convert-date ()
  8489. (interactive)
  8490. (org-agenda-check-type t 'agenda 'timeline)
  8491. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8492. date s)
  8493. (unless day
  8494. (error "Don't know which date to convert"))
  8495. (setq date (calendar-gregorian-from-absolute day))
  8496. (setq s (concat
  8497. "Gregorian: " (calendar-date-string date) "\n"
  8498. "ISO: " (calendar-iso-date-string date) "\n"
  8499. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8500. "Julian: " (calendar-julian-date-string date) "\n"
  8501. "Astron. JD: " (calendar-astro-date-string date)
  8502. " (Julian date number at noon UTC)\n"
  8503. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8504. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8505. "French: " (calendar-french-date-string date) "\n"
  8506. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8507. "Mayan: " (calendar-mayan-date-string date) "\n"
  8508. "Coptic: " (calendar-coptic-date-string date) "\n"
  8509. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8510. "Persian: " (calendar-persian-date-string date) "\n"
  8511. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8512. (with-output-to-temp-buffer "*Dates*"
  8513. (princ s))
  8514. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8515. ;;; Bulk commands
  8516. (defun org-agenda-bulk-marked-p ()
  8517. (eq (get-char-property (point-at-bol) 'type)
  8518. 'org-marked-entry-overlay))
  8519. (defun org-agenda-bulk-mark (&optional arg)
  8520. "Mark the entry at point for future bulk action."
  8521. (interactive "p")
  8522. (dotimes (i (or arg 1))
  8523. (unless (org-get-at-bol 'org-agenda-diary-link)
  8524. (let* ((m (org-get-at-bol 'org-hd-marker))
  8525. ov)
  8526. (unless (org-agenda-bulk-marked-p)
  8527. (unless m (error "Nothing to mark at point"))
  8528. (push m org-agenda-bulk-marked-entries)
  8529. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8530. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8531. (org-get-todo-face "TODO")
  8532. 'evaporate)
  8533. (overlay-put ov 'type 'org-marked-entry-overlay))
  8534. (beginning-of-line 2)
  8535. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8536. (beginning-of-line 2))
  8537. (message "%d entries marked for bulk action"
  8538. (length org-agenda-bulk-marked-entries))))))
  8539. (defun org-agenda-bulk-mark-all ()
  8540. "Mark all entries for future agenda bulk action."
  8541. (interactive)
  8542. (org-agenda-bulk-mark-regexp "."))
  8543. (defun org-agenda-bulk-mark-regexp (regexp)
  8544. "Mark entries matching REGEXP for future agenda bulk action."
  8545. (interactive "sMark entries matching regexp: ")
  8546. (let ((entries-marked 0))
  8547. (save-excursion
  8548. (goto-char (point-min))
  8549. (goto-char (next-single-property-change (point) 'txt))
  8550. (while (re-search-forward regexp nil t)
  8551. (when (string-match regexp (get-text-property (point) 'txt))
  8552. (setq entries-marked (1+ entries-marked))
  8553. (call-interactively 'org-agenda-bulk-mark))))
  8554. (if (not entries-marked)
  8555. (message "No entry matching this regexp."))))
  8556. (defun org-agenda-bulk-unmark (&optional arg)
  8557. "Unmark the entry at point for future bulk action."
  8558. (interactive "P")
  8559. (if arg
  8560. (org-agenda-bulk-unmark-all)
  8561. (cond ((org-agenda-bulk-marked-p)
  8562. (org-agenda-bulk-remove-overlays
  8563. (point-at-bol) (+ 2 (point-at-bol)))
  8564. (setq org-agenda-bulk-marked-entries
  8565. (delete (org-get-at-bol 'org-hd-marker)
  8566. org-agenda-bulk-marked-entries))
  8567. (beginning-of-line 2)
  8568. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8569. (beginning-of-line 2))
  8570. (message "%d entries left marked for bulk action"
  8571. (length org-agenda-bulk-marked-entries)))
  8572. (t (message "No entry to unmark here")))))
  8573. (defun org-agenda-bulk-toggle ()
  8574. "Toggle marking the entry at point for bulk action."
  8575. (interactive)
  8576. (if (org-agenda-bulk-marked-p)
  8577. (org-agenda-bulk-unmark)
  8578. (org-agenda-bulk-mark)))
  8579. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8580. "Remove the mark overlays between BEG and END in the agenda buffer.
  8581. BEG and END default to the buffer limits.
  8582. This only removes the overlays, it does not remove the markers
  8583. from the list in `org-agenda-bulk-marked-entries'."
  8584. (interactive)
  8585. (mapc (lambda (ov)
  8586. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8587. (delete-overlay ov)))
  8588. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8589. (defun org-agenda-bulk-unmark-all ()
  8590. "Remove all marks in the agenda buffer.
  8591. This will remove the markers and the overlays."
  8592. (interactive)
  8593. (if (null org-agenda-bulk-marked-entries)
  8594. (message "No entry to unmark")
  8595. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8596. (setq org-agenda-bulk-marked-entries nil)
  8597. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8598. (defcustom org-agenda-persistent-marks nil
  8599. "Non-nil means marked items will stay marked after a bulk action.
  8600. You can toggle this interactively by typing `p' when prompted for a
  8601. bulk action."
  8602. :group 'org-agenda
  8603. :version "24.1"
  8604. :type 'boolean)
  8605. (defun org-agenda-bulk-action (&optional arg)
  8606. "Execute an remote-editing action on all marked entries.
  8607. The prefix arg is passed through to the command if possible."
  8608. (interactive "P")
  8609. ;; Make sure we have markers, and only valid ones
  8610. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8611. (mapc
  8612. (lambda (m)
  8613. (unless (and (markerp m)
  8614. (marker-buffer m)
  8615. (buffer-live-p (marker-buffer m))
  8616. (marker-position m))
  8617. (error "Marker %s for bulk command is invalid" m)))
  8618. org-agenda-bulk-marked-entries)
  8619. ;; Prompt for the bulk command
  8620. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8621. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8622. "[S]catter [f]unction "
  8623. (when org-agenda-bulk-custom-functions
  8624. (concat " Custom: ["
  8625. (mapconcat (lambda(f) (char-to-string (car f)))
  8626. org-agenda-bulk-custom-functions "")
  8627. "]"))))
  8628. (catch 'exit
  8629. (let* ((action (read-char-exclusive))
  8630. (org-log-refile (if org-log-refile 'time nil))
  8631. (entries (reverse org-agenda-bulk-marked-entries))
  8632. (org-overriding-default-time
  8633. (if (get-text-property (point) 'org-agenda-date-header)
  8634. (org-get-cursor-date)))
  8635. redo-at-end
  8636. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8637. (cond
  8638. ((equal action ?p)
  8639. (let ((org-agenda-persistent-marks
  8640. (not org-agenda-persistent-marks)))
  8641. (org-agenda-bulk-action)
  8642. (throw 'exit nil)))
  8643. ((equal action ?$)
  8644. (setq cmd '(org-agenda-archive)))
  8645. ((equal action ?A)
  8646. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8647. ((member action '(?r ?w))
  8648. (setq rfloc (org-refile-get-location
  8649. "Refile to"
  8650. (marker-buffer (car entries))
  8651. org-refile-allow-creating-parent-nodes))
  8652. (if (nth 3 rfloc)
  8653. (setcar (nthcdr 3 rfloc)
  8654. (move-marker (make-marker) (nth 3 rfloc)
  8655. (or (get-file-buffer (nth 1 rfloc))
  8656. (find-buffer-visiting (nth 1 rfloc))
  8657. (error "This should not happen")))))
  8658. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8659. redo-at-end t))
  8660. ((equal action ?t)
  8661. (setq state (org-icompleting-read
  8662. "Todo state: "
  8663. (with-current-buffer (marker-buffer (car entries))
  8664. (mapcar 'list org-todo-keywords-1))))
  8665. (setq cmd `(let ((org-inhibit-blocking t)
  8666. (org-inhibit-logging 'note))
  8667. (org-agenda-todo ,state))))
  8668. ((memq action '(?- ?+))
  8669. (setq tag (org-icompleting-read
  8670. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8671. (with-current-buffer (marker-buffer (car entries))
  8672. (delq nil
  8673. (mapcar (lambda (x)
  8674. (if (stringp (car x)) x)) org-tag-alist)))))
  8675. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8676. ((memq action '(?s ?d))
  8677. (let* ((time
  8678. (unless arg
  8679. (org-read-date
  8680. nil nil nil
  8681. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8682. org-overriding-default-time)))
  8683. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8684. (setq cmd `(eval '(,c1 arg ,time)))))
  8685. ((equal action ?S)
  8686. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8687. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8688. (let ((days (read-number
  8689. (format "Scatter tasks across how many %sdays: "
  8690. (if arg "week" "")) 7)))
  8691. (setq cmd
  8692. `(let ((distance (1+ (random ,days))))
  8693. (if arg
  8694. (let ((dist distance)
  8695. (day-of-week
  8696. (calendar-day-of-week
  8697. (calendar-gregorian-from-absolute (org-today)))))
  8698. (dotimes (i (1+ dist))
  8699. (while (member day-of-week org-agenda-weekend-days)
  8700. (incf distance)
  8701. (incf day-of-week)
  8702. (if (= day-of-week 7)
  8703. (setq day-of-week 0)))
  8704. (incf day-of-week)
  8705. (if (= day-of-week 7)
  8706. (setq day-of-week 0)))))
  8707. ;; silently fail when try to replan a sexp entry
  8708. (condition-case nil
  8709. (let* ((date (calendar-gregorian-from-absolute
  8710. (+ (org-today) distance)))
  8711. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8712. (nth 2 date))))
  8713. (org-agenda-schedule nil time))
  8714. (error nil)))))))
  8715. ((assoc action org-agenda-bulk-custom-functions)
  8716. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8717. redo-at-end t))
  8718. ((equal action ?f)
  8719. (setq cmd (list (intern
  8720. (org-icompleting-read "Function: "
  8721. obarray 'fboundp t nil nil)))))
  8722. (t (error "Invalid bulk action")))
  8723. ;; Sort the markers, to make sure that parents are handled before children
  8724. (setq entries (sort entries
  8725. (lambda (a b)
  8726. (cond
  8727. ((equal (marker-buffer a) (marker-buffer b))
  8728. (< (marker-position a) (marker-position b)))
  8729. (t
  8730. (string< (buffer-name (marker-buffer a))
  8731. (buffer-name (marker-buffer b))))))))
  8732. ;; Now loop over all markers and apply cmd
  8733. (while (setq e (pop entries))
  8734. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8735. (if (not pos)
  8736. (progn (message "Skipping removed entry at %s" e)
  8737. (setq cntskip (1+ cntskip)))
  8738. (goto-char pos)
  8739. (let (org-loop-over-headlines-in-active-region)
  8740. (eval cmd))
  8741. (setq cnt (1+ cnt))))
  8742. (when redo-at-end (org-agenda-redo))
  8743. (unless org-agenda-persistent-marks
  8744. (org-agenda-bulk-unmark-all))
  8745. (message "Acted on %d entries%s%s"
  8746. cnt
  8747. (if (= cntskip 0)
  8748. ""
  8749. (format ", skipped %d (disappeared before their turn)"
  8750. cntskip))
  8751. (if (not org-agenda-persistent-marks)
  8752. "" " (kept marked)"))))))
  8753. (defun org-agenda-capture (&optional with-time)
  8754. "Call `org-capture' with the date at point.
  8755. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  8756. current HH:MM time."
  8757. (interactive "P")
  8758. (if (not (eq major-mode 'org-agenda-mode))
  8759. (user-error "You cannot do this outside of agenda buffers")
  8760. (let ((org-overriding-default-time
  8761. (org-get-cursor-date (equal with-time 1))))
  8762. (call-interactively 'org-capture))))
  8763. ;;; Flagging notes
  8764. (defun org-agenda-show-the-flagging-note ()
  8765. "Display the flagging note in the other window.
  8766. When called a second time in direct sequence, offer to remove the FLAGGING
  8767. tag and (if present) the flagging note."
  8768. (interactive)
  8769. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8770. (win (selected-window))
  8771. note heading newhead)
  8772. (unless hdmarker
  8773. (error "No linked entry at point"))
  8774. (if (and (eq this-command last-command)
  8775. (y-or-n-p "Unflag and remove any flagging note? "))
  8776. (progn
  8777. (org-agenda-remove-flag hdmarker)
  8778. (let ((win (get-buffer-window "*Flagging Note*")))
  8779. (and win (delete-window win)))
  8780. (message "Entry unflagged"))
  8781. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8782. (unless note
  8783. (error "No flagging note"))
  8784. (org-kill-new note)
  8785. (org-switch-to-buffer-other-window "*Flagging Note*")
  8786. (erase-buffer)
  8787. (insert note)
  8788. (goto-char (point-min))
  8789. (while (re-search-forward "\\\\n" nil t)
  8790. (replace-match "\n" t t))
  8791. (goto-char (point-min))
  8792. (select-window win)
  8793. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8794. (defun org-agenda-remove-flag (marker)
  8795. "Remove the FLAGGED tag and any flagging note in the entry."
  8796. (let (newhead)
  8797. (org-with-point-at marker
  8798. (org-toggle-tag "FLAGGED" 'off)
  8799. (org-entry-delete nil "THEFLAGGINGNOTE")
  8800. (setq newhead (org-get-heading)))
  8801. (org-agenda-change-all-lines newhead marker)
  8802. (message "Entry unflagged")))
  8803. (defun org-agenda-get-any-marker (&optional pos)
  8804. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8805. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8806. ;;; Appointment reminders
  8807. (defvar appt-time-msg-list) ; defined in appt.el
  8808. ;;;###autoload
  8809. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8810. "Activate appointments found in `org-agenda-files'.
  8811. With a \\[universal-argument] prefix, refresh the list of
  8812. appointments.
  8813. If FILTER is t, interactively prompt the user for a regular
  8814. expression, and filter out entries that don't match it.
  8815. If FILTER is a string, use this string as a regular expression
  8816. for filtering entries out.
  8817. If FILTER is a function, filter out entries against which
  8818. calling the function returns nil. This function takes one
  8819. argument: an entry from `org-agenda-get-day-entries'.
  8820. FILTER can also be an alist with the car of each cell being
  8821. either 'headline or 'category. For example:
  8822. '((headline \"IMPORTANT\")
  8823. (category \"Work\"))
  8824. will only add headlines containing IMPORTANT or headlines
  8825. belonging to the \"Work\" category.
  8826. ARGS are symbols indicating what kind of entries to consider.
  8827. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8828. and :timestamp entries. See the docstring of `org-diary' for
  8829. details and examples.
  8830. If an entry as a APPT_WARNTIME property, its value will be used
  8831. to override `appt-message-warning-time'."
  8832. (interactive "P")
  8833. (if refresh (setq appt-time-msg-list nil))
  8834. (if (eq filter t)
  8835. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8836. (let* ((cnt 0) ; count added events
  8837. (scope (or args '(:deadline :scheduled :timestamp)))
  8838. (org-agenda-new-buffers nil)
  8839. (org-deadline-warning-days 0)
  8840. ;; Do not use `org-today' here because appt only takes
  8841. ;; time and without date as argument, so it may pass wrong
  8842. ;; information otherwise
  8843. (today (org-date-to-gregorian
  8844. (time-to-days (current-time))))
  8845. (org-agenda-restrict nil)
  8846. (files (org-agenda-files 'unrestricted)) entries file
  8847. (org-agenda-buffer nil))
  8848. ;; Get all entries which may contain an appt
  8849. (org-agenda-prepare-buffers files)
  8850. (while (setq file (pop files))
  8851. (setq entries
  8852. (delq nil
  8853. (append entries
  8854. (apply 'org-agenda-get-day-entries
  8855. file today scope)))))
  8856. ;; Map thru entries and find if we should filter them out
  8857. (mapc
  8858. (lambda(x)
  8859. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8860. (cat (get-text-property 1 'org-category x))
  8861. (tod (get-text-property 1 'time-of-day x))
  8862. (ok (or (null filter)
  8863. (and (stringp filter) (string-match filter evt))
  8864. (and (functionp filter) (funcall filter x))
  8865. (and (listp filter)
  8866. (let ((cat-filter (cadr (assoc 'category filter)))
  8867. (evt-filter (cadr (assoc 'headline filter))))
  8868. (or (and (stringp cat-filter)
  8869. (string-match cat-filter cat))
  8870. (and (stringp evt-filter)
  8871. (string-match evt-filter evt)))))))
  8872. (wrn (get-text-property 1 'warntime x)))
  8873. ;; FIXME: Shall we remove text-properties for the appt text?
  8874. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8875. (when (and ok tod)
  8876. (setq tod (concat "00" (number-to-string tod))
  8877. tod (when (string-match
  8878. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8879. (concat (match-string 1 tod) ":"
  8880. (match-string 2 tod))))
  8881. (if (version< emacs-version "23.3")
  8882. (appt-add tod evt)
  8883. (appt-add tod evt wrn))
  8884. (setq cnt (1+ cnt))))) entries)
  8885. (org-release-buffers org-agenda-new-buffers)
  8886. (if (eq cnt 0)
  8887. (message "No event to add")
  8888. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8889. (autoload 'org-agenda-to-appt "org-agenda" "\
  8890. Activate appointments found in `org-agenda-files'.
  8891. With a \\[universal-argument] prefix, refresh the list of
  8892. appointments.
  8893. If FILTER is t, interactively prompt the user for a regular
  8894. expression, and filter out entries that don't match it.
  8895. If FILTER is a string, use this string as a regular expression
  8896. for filtering entries out.
  8897. If FILTER is a function, filter out entries against which
  8898. calling the function returns nil. This function takes one
  8899. argument: an entry from `org-agenda-get-day-entries'.
  8900. FILTER can also be an alist with the car of each cell being
  8901. either 'headline or 'category. For example:
  8902. '((headline \"IMPORTANT\")
  8903. (category \"Work\"))
  8904. will only add headlines containing IMPORTANT or headlines
  8905. belonging to the \"Work\" category.
  8906. ARGS are symbols indicating what kind of entries to consider.
  8907. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8908. and :timestamp entries. See the docstring of `org-diary' for
  8909. details and examples.
  8910. If an entry as a APPT_WARNTIME property, its value will be used
  8911. to override `appt-message-warning-time'.
  8912. \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
  8913. (defun org-agenda-todayp (date)
  8914. "Does DATE mean today, when considering `org-extend-today-until'?"
  8915. (let ((today (org-today))
  8916. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8917. date)))
  8918. (eq date today)))
  8919. (defun org-agenda-todo-yesterday (&optional arg)
  8920. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8921. (interactive "P")
  8922. (let* ((hour (third (decode-time
  8923. (org-current-time))))
  8924. (org-extend-today-until (1+ hour)))
  8925. (org-agenda-todo arg)))
  8926. (provide 'org-agenda)
  8927. ;;; org-agenda.el ends here