org-agenda.el 387 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021
  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 timestamp-up) (const timestamp-down)
  215. (const scheduled-up) (const scheduled-down)
  216. (const deadline-up) (const deadline-down)
  217. (const ts-up) (const ts-down)
  218. (const tsia-up) (const tsia-down)
  219. (const category-keep) (const category-up) (const category-down)
  220. (const tag-down) (const tag-up)
  221. (const priority-up) (const priority-down)
  222. (const todo-state-up) (const todo-state-down)
  223. (const effort-up) (const effort-down)
  224. (const habit-up) (const habit-down)
  225. (const alpha-up) (const alpha-down)
  226. (const user-defined-up) (const user-defined-down))
  227. "Sorting choices.")
  228. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  229. ;; the new variable `org-agenda-tag-filter-preset'.
  230. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  231. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  232. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  233. "List of types searched for when creating the daily/weekly agenda.
  234. This variable is a list of symbols that controls the types of
  235. items that appear in the daily/weekly agenda. Allowed symbols in this
  236. list are are
  237. :timestamp List items containing a date stamp or date range matching
  238. the selected date. This includes sexp entries in angular
  239. brackets.
  240. :sexp List entries resulting from plain diary-like sexps.
  241. :deadline List deadline due on that date. When the date is today,
  242. also list any deadlines past due, or due within
  243. `org-deadline-warning-days'. `:deadline' must appear before
  244. `:scheduled' if the setting of
  245. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  246. any effect.
  247. :deadline* Same as above, but only include the deadline if it has an
  248. hour specification as [h]h:mm.
  249. :scheduled List all items which are scheduled for the given date.
  250. The diary for *today* also contains items which were
  251. scheduled earlier and are not yet marked DONE.
  252. :scheduled* Same as above, but only include the scheduled item if it
  253. has an hour specification as [h]h:mm.
  254. By default, all four non-starred types are turned on.
  255. When :scheduled* or :deadline* are included, :schedule or :deadline
  256. will be ignored.
  257. Never set this variable globally using `setq', because then it
  258. will apply to all future agenda commands. Instead, bind it with
  259. `let' to scope it dynamically into the agenda-constructing
  260. command. A good way to set it is through options in
  261. `org-agenda-custom-commands'. For a more flexible (though
  262. somewhat less efficient) way of determining what is included in
  263. the daily/weekly agenda, see `org-agenda-skip-function'.")
  264. (defconst org-agenda-custom-commands-local-options
  265. `(repeat :tag "Local settings for this command. Remember to quote values"
  266. (choice :tag "Setting"
  267. (list :tag "Heading for this block"
  268. (const org-agenda-overriding-header)
  269. (string :tag "Headline"))
  270. (list :tag "Files to be searched"
  271. (const org-agenda-files)
  272. (list
  273. (const :format "" quote)
  274. (repeat (file))))
  275. (list :tag "Sorting strategy"
  276. (const org-agenda-sorting-strategy)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. ,org-sorting-choice)))
  281. (list :tag "Prefix format"
  282. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  283. (string))
  284. (list :tag "Number of days in agenda"
  285. (const org-agenda-span)
  286. (choice (const :tag "Day" 'day)
  287. (const :tag "Week" 'week)
  288. (const :tag "Month" 'month)
  289. (const :tag "Year" 'year)
  290. (integer :tag "Custom")))
  291. (list :tag "Fixed starting date"
  292. (const org-agenda-start-day)
  293. (string :value "2007-11-01"))
  294. (list :tag "Start on day of week"
  295. (const org-agenda-start-on-weekday)
  296. (choice :value 1
  297. (const :tag "Today" nil)
  298. (integer :tag "Weekday No.")))
  299. (list :tag "Include data from diary"
  300. (const org-agenda-include-diary)
  301. (boolean))
  302. (list :tag "Deadline Warning days"
  303. (const org-deadline-warning-days)
  304. (integer :value 1))
  305. (list :tag "Category filter preset"
  306. (const org-agenda-category-filter-preset)
  307. (list
  308. (const :format "" quote)
  309. (repeat
  310. (string :tag "+category or -category"))))
  311. (list :tag "Tags filter preset"
  312. (const org-agenda-tag-filter-preset)
  313. (list
  314. (const :format "" quote)
  315. (repeat
  316. (string :tag "+tag or -tag"))))
  317. (list :tag "Regexp filter preset"
  318. (const org-agenda-regexp-filter-preset)
  319. (list
  320. (const :format "" quote)
  321. (repeat
  322. (string :tag "+regexp or -regexp"))))
  323. (list :tag "Set daily/weekly entry types"
  324. (const org-agenda-entry-types)
  325. (list
  326. (const :format "" quote)
  327. (set :greedy t :value ,org-agenda-entry-types
  328. (const :deadline)
  329. (const :scheduled)
  330. (const :deadline*)
  331. (const :scheduled*)
  332. (const :timestamp)
  333. (const :sexp))))
  334. (list :tag "Standard skipping condition"
  335. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  336. (const org-agenda-skip-function)
  337. (list
  338. (const :format "" quote)
  339. (list
  340. (choice
  341. :tag "Skipping range"
  342. (const :tag "Skip entry" org-agenda-skip-entry-if)
  343. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  344. (repeat :inline t :tag "Conditions for skipping"
  345. (choice
  346. :tag "Condition type"
  347. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  348. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  349. (list :tag "TODO state is" :inline t
  350. (const 'todo)
  351. (choice
  352. (const :tag "any not-done state" 'todo)
  353. (const :tag "any done state" 'done)
  354. (const :tag "any state" 'any)
  355. (list :tag "Keyword list"
  356. (const :format "" quote)
  357. (repeat (string :tag "Keyword")))))
  358. (list :tag "TODO state is not" :inline t
  359. (const 'nottodo)
  360. (choice
  361. (const :tag "any not-done state" 'todo)
  362. (const :tag "any done state" 'done)
  363. (const :tag "any state" 'any)
  364. (list :tag "Keyword list"
  365. (const :format "" quote)
  366. (repeat (string :tag "Keyword")))))
  367. (const :tag "scheduled" 'scheduled)
  368. (const :tag "not scheduled" 'notscheduled)
  369. (const :tag "deadline" 'deadline)
  370. (const :tag "no deadline" 'notdeadline)
  371. (const :tag "timestamp" 'timestamp)
  372. (const :tag "no timestamp" 'nottimestamp))))))
  373. (list :tag "Non-standard skipping condition"
  374. :value (org-agenda-skip-function)
  375. (const org-agenda-skip-function)
  376. (sexp :tag "Function or form (quoted!)"))
  377. (list :tag "Any variable"
  378. (variable :tag "Variable")
  379. (sexp :tag "Value (sexp)"))))
  380. "Selection of examples for agenda command settings.
  381. This will be spliced into the custom type of
  382. `org-agenda-custom-commands'.")
  383. (defcustom org-agenda-custom-commands
  384. '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
  385. "Custom commands for the agenda.
  386. These commands will be offered on the splash screen displayed by the
  387. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  388. (key desc type match settings files)
  389. key The key (one or more characters as a string) to be associated
  390. with the command.
  391. desc A description of the command, when omitted or nil, a default
  392. description is built using MATCH.
  393. type The command type, any of the following symbols:
  394. agenda The daily/weekly agenda.
  395. todo Entries with a specific TODO keyword, in all agenda files.
  396. search Entries containing search words entry or headline.
  397. tags Tags/Property/TODO match in all agenda files.
  398. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  399. todo-tree Sparse tree of specific TODO keyword in *current* file.
  400. tags-tree Sparse tree with all tags matches in *current* file.
  401. occur-tree Occur sparse tree for *current* file.
  402. ... A user-defined function.
  403. match What to search for:
  404. - a single keyword for TODO keyword searches
  405. - a tags match expression for tags searches
  406. - a word search expression for text searches.
  407. - a regular expression for occur searches
  408. For all other commands, this should be the empty string.
  409. settings A list of option settings, similar to that in a let form, so like
  410. this: ((opt1 val1) (opt2 val2) ...). The values will be
  411. evaluated at the moment of execution, so quote them when needed.
  412. files A list of files file to write the produced agenda buffer to
  413. with the command `org-store-agenda-views'.
  414. If a file name ends in \".html\", an HTML version of the buffer
  415. is written out. If it ends in \".ps\", a postscript version is
  416. produced. Otherwise, only the plain text is written to the file.
  417. You can also define a set of commands, to create a composite agenda buffer.
  418. In this case, an entry looks like this:
  419. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  420. where
  421. desc A description string to be displayed in the dispatcher menu.
  422. cmd An agenda command, similar to the above. However, tree commands
  423. are not allowed, but instead you can get agenda and global todo list.
  424. So valid commands for a set are:
  425. (agenda \"\" settings)
  426. (alltodo \"\" settings)
  427. (stuck \"\" settings)
  428. (todo \"match\" settings files)
  429. (search \"match\" settings files)
  430. (tags \"match\" settings files)
  431. (tags-todo \"match\" settings files)
  432. Each command can carry a list of options, and another set of options can be
  433. given for the whole set of commands. Individual command options take
  434. precedence over the general options.
  435. When using several characters as key to a command, the first characters
  436. are prefix commands. For the dispatcher to display useful information, you
  437. should provide a description for the prefix, like
  438. (setq org-agenda-custom-commands
  439. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  440. (\"hl\" tags \"+HOME+Lisa\")
  441. (\"hp\" tags \"+HOME+Peter\")
  442. (\"hk\" tags \"+HOME+Kim\")))"
  443. :group 'org-agenda-custom-commands
  444. :type `(repeat
  445. (choice :value ("x" "Describe command here" tags "" nil)
  446. (list :tag "Single command"
  447. (string :tag "Access Key(s) ")
  448. (option (string :tag "Description"))
  449. (choice
  450. (const :tag "Agenda" agenda)
  451. (const :tag "TODO list" alltodo)
  452. (const :tag "Search words" search)
  453. (const :tag "Stuck projects" stuck)
  454. (const :tag "Tags/Property match (all agenda files)" tags)
  455. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  456. (const :tag "TODO keyword search (all agenda files)" todo)
  457. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  458. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  459. (const :tag "Occur tree (current buffer)" occur-tree)
  460. (sexp :tag "Other, user-defined function"))
  461. (string :tag "Match (only for some commands)")
  462. ,org-agenda-custom-commands-local-options
  463. (option (repeat :tag "Export" (file :tag "Export to"))))
  464. (list :tag "Command series, all agenda files"
  465. (string :tag "Access Key(s)")
  466. (string :tag "Description ")
  467. (repeat :tag "Component"
  468. (choice
  469. (list :tag "Agenda"
  470. (const :format "" agenda)
  471. (const :tag "" :format "" "")
  472. ,org-agenda-custom-commands-local-options)
  473. (list :tag "TODO list (all keywords)"
  474. (const :format "" alltodo)
  475. (const :tag "" :format "" "")
  476. ,org-agenda-custom-commands-local-options)
  477. (list :tag "Search words"
  478. (const :format "" search)
  479. (string :tag "Match")
  480. ,org-agenda-custom-commands-local-options)
  481. (list :tag "Stuck projects"
  482. (const :format "" stuck)
  483. (const :tag "" :format "" "")
  484. ,org-agenda-custom-commands-local-options)
  485. (list :tag "Tags search"
  486. (const :format "" tags)
  487. (string :tag "Match")
  488. ,org-agenda-custom-commands-local-options)
  489. (list :tag "Tags search, TODO entries only"
  490. (const :format "" tags-todo)
  491. (string :tag "Match")
  492. ,org-agenda-custom-commands-local-options)
  493. (list :tag "TODO keyword search"
  494. (const :format "" todo)
  495. (string :tag "Match")
  496. ,org-agenda-custom-commands-local-options)
  497. (list :tag "Other, user-defined function"
  498. (symbol :tag "function")
  499. (string :tag "Match")
  500. ,org-agenda-custom-commands-local-options)))
  501. (repeat :tag "Settings for entire command set"
  502. (list (variable :tag "Any variable")
  503. (sexp :tag "Value")))
  504. (option (repeat :tag "Export" (file :tag "Export to"))))
  505. (cons :tag "Prefix key documentation"
  506. (string :tag "Access Key(s)")
  507. (string :tag "Description ")))))
  508. (defcustom org-agenda-query-register ?o
  509. "The register holding the current query string.
  510. The purpose of this is that if you construct a query string interactively,
  511. you can then use it to define a custom command."
  512. :group 'org-agenda-custom-commands
  513. :type 'character)
  514. (defcustom org-stuck-projects
  515. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  516. "How to identify stuck projects.
  517. This is a list of four items:
  518. 1. A tags/todo/property matcher string that is used to identify a project.
  519. See the manual for a description of tag and property searches.
  520. The entire tree below a headline matched by this is considered one project.
  521. 2. A list of TODO keywords identifying non-stuck projects.
  522. If the project subtree contains any headline with one of these todo
  523. keywords, the project is considered to be not stuck. If you specify
  524. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  525. 3. A list of tags identifying non-stuck projects.
  526. If the project subtree contains any headline with one of these tags,
  527. the project is considered to be not stuck. If you specify \"*\" as
  528. a tag, any tag will mark the project unstuck. Note that this is about
  529. the explicit presence of a tag somewhere in the subtree, inherited
  530. tags do not count here. If inherited tags make a project not stuck,
  531. use \"-TAG\" in the tags part of the matcher under (1.) above.
  532. 4. An arbitrary regular expression matching non-stuck projects.
  533. If the project turns out to be not stuck, search continues also in the
  534. subtree to see if any of the subtasks have project status.
  535. See also the variable `org-tags-match-list-sublevels' which applies
  536. to projects matched by this search as well.
  537. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  538. or `C-c a #' to produce the list."
  539. :group 'org-agenda-custom-commands
  540. :type '(list
  541. (string :tag "Tags/TODO match to identify a project")
  542. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  543. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  544. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  545. (defcustom org-agenda-filter-effort-default-operator "<"
  546. "The default operator for effort estimate filtering.
  547. If you select an effort estimate limit without first pressing an operator,
  548. this one will be used."
  549. :group 'org-agenda-custom-commands
  550. :type '(choice (const :tag "less or equal" "<")
  551. (const :tag "greater or equal"">")
  552. (const :tag "equal" "=")))
  553. (defgroup org-agenda-skip nil
  554. "Options concerning skipping parts of agenda files."
  555. :tag "Org Agenda Skip"
  556. :group 'org-agenda)
  557. (defcustom org-agenda-skip-function-global nil
  558. "Function to be called at each match during agenda construction.
  559. If this function returns nil, the current match should not be skipped.
  560. If the function decided to skip an agenda match, is must return the
  561. buffer position from which the search should be continued.
  562. This may also be a Lisp form, which will be evaluated.
  563. This variable will be applied to every agenda match, including
  564. tags/property searches and TODO lists. So try to make the test function
  565. do its checking as efficiently as possible. To implement a skipping
  566. condition just for specific agenda commands, use the variable
  567. `org-agenda-skip-function' which can be set in the options section
  568. of custom agenda commands."
  569. :group 'org-agenda-skip
  570. :type 'sexp)
  571. (defgroup org-agenda-daily/weekly nil
  572. "Options concerning the daily/weekly agenda."
  573. :tag "Org Agenda Daily/Weekly"
  574. :group 'org-agenda)
  575. (defgroup org-agenda-todo-list nil
  576. "Options concerning the global todo list agenda view."
  577. :tag "Org Agenda Todo List"
  578. :group 'org-agenda)
  579. (defgroup org-agenda-match-view nil
  580. "Options concerning the general tags/property/todo match agenda view."
  581. :tag "Org Agenda Match View"
  582. :group 'org-agenda)
  583. (defgroup org-agenda-search-view nil
  584. "Options concerning the general tags/property/todo match agenda view."
  585. :tag "Org Agenda Match View"
  586. :group 'org-agenda)
  587. (defvar org-agenda-archives-mode nil
  588. "Non-nil means the agenda will include archived items.
  589. If this is the symbol `trees', trees in the selected agenda scope
  590. that are marked with the ARCHIVE tag will be included anyway. When this is
  591. t, also all archive files associated with the current selection of agenda
  592. files will be included.")
  593. (defcustom org-agenda-restriction-lock-highlight-subtree t
  594. "Non-nil means highlight the whole subtree when restriction is active.
  595. Otherwise only highlight the headline. Highlighting the whole subtree is
  596. useful to ensure no edits happen beyond the restricted region."
  597. :group 'org-agenda
  598. :type 'boolean)
  599. (defcustom org-agenda-skip-comment-trees t
  600. "Non-nil means skip trees that start with the COMMENT keyword.
  601. When nil, these trees are also scanned by agenda commands."
  602. :group 'org-agenda-skip
  603. :type 'boolean)
  604. (defcustom org-agenda-todo-list-sublevels t
  605. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  606. When nil, the sublevels of a TODO entry are not checked, resulting in
  607. potentially much shorter TODO lists."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-todo-list
  610. :type 'boolean)
  611. (defcustom org-agenda-todo-ignore-with-date nil
  612. "Non-nil means don't show entries with a date in the global todo list.
  613. You can use this if you prefer to mark mere appointments with a TODO keyword,
  614. but don't want them to show up in the TODO list.
  615. When this is set, it also covers deadlines and scheduled items, the settings
  616. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  617. will be ignored.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  619. :group 'org-agenda-skip
  620. :group 'org-agenda-todo-list
  621. :type 'boolean)
  622. (defcustom org-agenda-todo-ignore-timestamp nil
  623. "Non-nil means don't show entries with a timestamp.
  624. This applies when creating the global todo list.
  625. Valid values are:
  626. past Don't show entries for today or in the past.
  627. future Don't show entries with a timestamp in the future.
  628. The idea behind this is that if it has a future
  629. timestamp, you don't want to think about it until the
  630. date.
  631. all Don't show any entries with a timestamp in the global todo list.
  632. The idea behind this is that by setting a timestamp, you
  633. have already \"taken care\" of this item.
  634. This variable can also have an integer as a value. If positive (N),
  635. todos with a timestamp N or more days in the future will be ignored. If
  636. negative (-N), todos with a timestamp N or more days in the past will be
  637. ignored. If 0, todos with a timestamp either today or in the future will
  638. be ignored. For example, a value of -1 will exclude todos with a
  639. timestamp in the past (yesterday or earlier), while a value of 7 will
  640. exclude todos with a timestamp a week or more in the future.
  641. See also `org-agenda-todo-ignore-with-date'.
  642. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  643. to make his option also apply to the tags-todo list."
  644. :group 'org-agenda-skip
  645. :group 'org-agenda-todo-list
  646. :version "24.1"
  647. :type '(choice
  648. (const :tag "Ignore future timestamp todos" future)
  649. (const :tag "Ignore past or present timestamp todos" past)
  650. (const :tag "Ignore all timestamp todos" all)
  651. (const :tag "Show timestamp todos" nil)
  652. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  653. (defcustom org-agenda-todo-ignore-scheduled nil
  654. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  655. This applies when creating the global todo list.
  656. Valid values are:
  657. past Don't show entries scheduled today or in the past.
  658. future Don't show entries scheduled in the future.
  659. The idea behind this is that by scheduling it, you don't want to
  660. think about it until the scheduled date.
  661. all Don't show any scheduled entries in the global todo list.
  662. The idea behind this is that by scheduling it, you have already
  663. \"taken care\" of this item.
  664. t Same as `all', for backward compatibility.
  665. This variable can also have an integer as a value. See
  666. `org-agenda-todo-ignore-timestamp' for more details.
  667. See also `org-agenda-todo-ignore-with-date'.
  668. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  669. to make his option also apply to the tags-todo list."
  670. :group 'org-agenda-skip
  671. :group 'org-agenda-todo-list
  672. :type '(choice
  673. (const :tag "Ignore future-scheduled todos" future)
  674. (const :tag "Ignore past- or present-scheduled todos" past)
  675. (const :tag "Ignore all scheduled todos" all)
  676. (const :tag "Ignore all scheduled todos (compatibility)" t)
  677. (const :tag "Show scheduled todos" nil)
  678. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  679. (defcustom org-agenda-todo-ignore-deadlines nil
  680. "Non-nil means ignore some deadlined TODO items when making TODO list.
  681. There are different motivations for using different values, please think
  682. carefully when configuring this variable.
  683. This applies when creating the global todo list.
  684. Valid values are:
  685. near Don't show near deadline entries. A deadline is near when it is
  686. closer than `org-deadline-warning-days' days. The idea behind this
  687. is that such items will appear in the agenda anyway.
  688. far Don't show TODO entries where a deadline has been defined, but
  689. the deadline is not near. This is useful if you don't want to
  690. use the todo list to figure out what to do now.
  691. past Don't show entries with a deadline timestamp for today or in the past.
  692. future Don't show entries with a deadline timestamp in the future, not even
  693. when they become `near' ones. Use it with caution.
  694. all Ignore all TODO entries that do have a deadline.
  695. t Same as `near', for backward compatibility.
  696. This variable can also have an integer as a value. See
  697. `org-agenda-todo-ignore-timestamp' for more details.
  698. See also `org-agenda-todo-ignore-with-date'.
  699. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  700. to make his option also apply to the tags-todo list."
  701. :group 'org-agenda-skip
  702. :group 'org-agenda-todo-list
  703. :type '(choice
  704. (const :tag "Ignore near deadlines" near)
  705. (const :tag "Ignore near deadlines (compatibility)" t)
  706. (const :tag "Ignore far deadlines" far)
  707. (const :tag "Ignore all TODOs with a deadlines" all)
  708. (const :tag "Show all TODOs, even if they have a deadline" nil)
  709. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  710. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  711. "Time unit to use when possibly ignoring an agenda item.
  712. See the docstring of various `org-agenda-todo-ignore-*' options.
  713. The default is to compare time stamps using days. An item is thus
  714. considered to be in the future if it is at least one day after today.
  715. Non-nil means to compare time stamps using seconds. An item is then
  716. considered future if it has a time value later than current time."
  717. :group 'org-agenda-skip
  718. :group 'org-agenda-todo-list
  719. :version "24.4"
  720. :package-version '(Org . "8.0")
  721. :type '(choice
  722. (const :tag "Compare time with days" nil)
  723. (const :tag "Compare time with seconds" t)))
  724. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  725. "Non-nil means honor todo-list ignores options also in tags-todo search.
  726. The variables
  727. `org-agenda-todo-ignore-with-date',
  728. `org-agenda-todo-ignore-timestamp',
  729. `org-agenda-todo-ignore-scheduled',
  730. `org-agenda-todo-ignore-deadlines'
  731. make the global TODO list skip entries that have time stamps of certain
  732. kinds. If this option is set, the same options will also apply for the
  733. tags-todo search, which is the general tags/property matcher
  734. restricted to unfinished TODO entries only."
  735. :group 'org-agenda-skip
  736. :group 'org-agenda-todo-list
  737. :group 'org-agenda-match-view
  738. :type 'boolean)
  739. (defcustom org-agenda-skip-scheduled-if-done nil
  740. "Non-nil means don't show scheduled items in agenda when they are done.
  741. This is relevant for the daily/weekly agenda, not for the TODO list. And
  742. it applies only to the actual date of the scheduling. Warnings about
  743. an item with a past scheduling dates are always turned off when the item
  744. is DONE."
  745. :group 'org-agenda-skip
  746. :group 'org-agenda-daily/weekly
  747. :type 'boolean)
  748. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  749. "Non-nil means skip scheduling line if same entry shows because of deadline.
  750. In the agenda of today, an entry can show up multiple times
  751. because it is both scheduled and has a nearby deadline, and maybe
  752. a plain time stamp as well.
  753. When this variable is nil, the entry will be shown several times.
  754. When set to t, then only the deadline is shown and the fact that
  755. the entry is scheduled today or was scheduled previously is not
  756. shown.
  757. When set to the symbol `not-today', skip scheduled previously,
  758. but not scheduled today.
  759. When set to the symbol `repeated-after-deadline', skip scheduled
  760. items if they are repeated beyond the current dealine."
  761. :group 'org-agenda-skip
  762. :group 'org-agenda-daily/weekly
  763. :type '(choice
  764. (const :tag "Never" nil)
  765. (const :tag "Always" t)
  766. (const :tag "Not when scheduled today" not-today)
  767. (const :tag "When repeated past deadline" repeated-after-deadline)))
  768. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  769. "Non-nil means skip timestamp line if same entry shows because of deadline.
  770. In the agenda of today, an entry can show up multiple times
  771. because it has both a plain timestamp and has a nearby deadline.
  772. When this variable is t, then only the deadline is shown and the
  773. fact that the entry has a timestamp for or including today is not
  774. shown. When this variable is nil, the entry will be shown
  775. several times."
  776. :group 'org-agenda-skip
  777. :group 'org-agenda-daily/weekly
  778. :version "24.1"
  779. :type '(choice
  780. (const :tag "Never" nil)
  781. (const :tag "Always" t)))
  782. (defcustom org-agenda-skip-deadline-if-done nil
  783. "Non-nil means don't show deadlines when the corresponding item is done.
  784. When nil, the deadline is still shown and should give you a happy feeling.
  785. This is relevant for the daily/weekly agenda. And it applied only to the
  786. actually date of the deadline. Warnings about approaching and past-due
  787. deadlines are always turned off when the item is DONE."
  788. :group 'org-agenda-skip
  789. :group 'org-agenda-daily/weekly
  790. :type 'boolean)
  791. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  792. "Non-nil means skip deadline prewarning when entry is also scheduled.
  793. This will apply on all days where a prewarning for the deadline would
  794. be shown, but not at the day when the entry is actually due. On that day,
  795. the deadline will be shown anyway.
  796. This variable may be set to nil, t, the symbol `pre-scheduled',
  797. or a number which will then give the number of days before the actual
  798. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  799. eliminates the deadline prewarning only prior to the scheduled date.
  800. This can be used in a workflow where the first showing of the deadline will
  801. trigger you to schedule it, and then you don't want to be reminded of it
  802. because you will take care of it on the day when scheduled."
  803. :group 'org-agenda-skip
  804. :group 'org-agenda-daily/weekly
  805. :version "24.1"
  806. :type '(choice
  807. (const :tag "Always show prewarning" nil)
  808. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  809. (const :tag "Remove prewarning if entry is scheduled" t)
  810. (integer :tag "Restart prewarning N days before deadline")))
  811. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  812. "Non-nil means skip scheduled delay when entry also has a deadline.
  813. This variable may be set to nil, t, the symbol `post-deadline',
  814. or a number which will then give the number of days after the actual
  815. scheduled date when the delay should expire. The symbol `post-deadline'
  816. eliminates the schedule delay when the date is posterior to the deadline."
  817. :group 'org-agenda-skip
  818. :group 'org-agenda-daily/weekly
  819. :version "24.4"
  820. :package-version '(Org . "8.0")
  821. :type '(choice
  822. (const :tag "Always honor delay" nil)
  823. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  824. (const :tag "Ignore delay if entry has a deadline" t)
  825. (integer :tag "Honor delay up until N days after the scheduled date")))
  826. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  827. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  828. When non-nil, after the search for timestamps has matched once in an
  829. entry, the rest of the entry will not be searched."
  830. :group 'org-agenda-skip
  831. :type 'boolean)
  832. (defcustom org-agenda-skip-timestamp-if-done nil
  833. "Non-nil means don't select item by timestamp or -range if it is DONE."
  834. :group 'org-agenda-skip
  835. :group 'org-agenda-daily/weekly
  836. :type 'boolean)
  837. (defcustom org-agenda-dim-blocked-tasks t
  838. "Non-nil means dim blocked tasks in the agenda display.
  839. This causes some overhead during agenda construction, but if you
  840. have turned on `org-enforce-todo-dependencies',
  841. `org-enforce-todo-checkbox-dependencies', or any other blocking
  842. mechanism, this will create useful feedback in the agenda.
  843. Instead of t, this variable can also have the value `invisible'.
  844. Then blocked tasks will be invisible and only become visible when
  845. they become unblocked. An exemption to this behavior is when a task is
  846. blocked because of unchecked checkboxes below it. Since checkboxes do
  847. not show up in the agenda views, making this task invisible you remove any
  848. trace from agenda views that there is something to do. Therefore, a task
  849. that is blocked because of checkboxes will never be made invisible, it
  850. will only be dimmed."
  851. :group 'org-agenda-daily/weekly
  852. :group 'org-agenda-todo-list
  853. :version "24.3"
  854. :type '(choice
  855. (const :tag "Do not dim" nil)
  856. (const :tag "Dim to a gray face" t)
  857. (const :tag "Make invisible" invisible)))
  858. (defcustom org-timeline-show-empty-dates 3
  859. "Non-nil means `org-timeline' also shows dates without an entry.
  860. When nil, only the days which actually have entries are shown.
  861. When t, all days between the first and the last date are shown.
  862. When an integer, show also empty dates, but if there is a gap of more than
  863. N days, just insert a special line indicating the size of the gap."
  864. :group 'org-agenda-skip
  865. :type '(choice
  866. (const :tag "None" nil)
  867. (const :tag "All" t)
  868. (integer :tag "at most")))
  869. (defgroup org-agenda-startup nil
  870. "Options concerning initial settings in the Agenda in Org Mode."
  871. :tag "Org Agenda Startup"
  872. :group 'org-agenda)
  873. (defcustom org-agenda-menu-show-matcher t
  874. "Non-nil means show the match string in the agenda dispatcher menu.
  875. When nil, the matcher string is not shown, but is put into the help-echo
  876. property so than moving the mouse over the command shows it.
  877. Setting it to nil is good if matcher strings are very long and/or if
  878. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  879. :group 'org-agenda
  880. :version "24.1"
  881. :type 'boolean)
  882. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  883. (defcustom org-agenda-menu-two-columns nil
  884. "Non-nil means, use two columns to show custom commands in the dispatcher.
  885. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  886. to nil."
  887. :group 'org-agenda
  888. :version "24.1"
  889. :type 'boolean)
  890. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  891. (defcustom org-agenda-finalize-hook nil
  892. "Hook run just before displaying an agenda buffer.
  893. The buffer is still writable when the hook is called.
  894. You can modify some of the buffer substrings but you should be
  895. extra careful not to modify the text properties of the agenda
  896. headlines as the agenda display heavily relies on them."
  897. :group 'org-agenda-startup
  898. :type 'hook)
  899. (defcustom org-agenda-mouse-1-follows-link nil
  900. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  901. A longer mouse click will still set point. Does not work on XEmacs.
  902. Needs to be set before org.el is loaded."
  903. :group 'org-agenda-startup
  904. :type 'boolean)
  905. (defcustom org-agenda-start-with-follow-mode nil
  906. "The initial value of follow mode in a newly created agenda window."
  907. :group 'org-agenda-startup
  908. :type 'boolean)
  909. (defcustom org-agenda-follow-indirect nil
  910. "Non-nil means `org-agenda-follow-mode' displays only the
  911. current item's tree, in an indirect buffer."
  912. :group 'org-agenda
  913. :version "24.1"
  914. :type 'boolean)
  915. (defcustom org-agenda-show-outline-path t
  916. "Non-nil means show outline path in echo area after line motion."
  917. :group 'org-agenda-startup
  918. :type 'boolean)
  919. (defcustom org-agenda-start-with-entry-text-mode nil
  920. "The initial value of entry-text-mode in a newly created agenda window."
  921. :group 'org-agenda-startup
  922. :type 'boolean)
  923. (defcustom org-agenda-entry-text-maxlines 5
  924. "Number of text lines to be added when `E' is pressed in the agenda.
  925. Note that this variable only used during agenda display. Add add entry text
  926. when exporting the agenda, configure the variable
  927. `org-agenda-add-entry-ext-maxlines'."
  928. :group 'org-agenda
  929. :type 'integer)
  930. (defcustom org-agenda-entry-text-exclude-regexps nil
  931. "List of regular expressions to clean up entry text.
  932. The complete matches of all regular expressions in this list will be
  933. removed from entry text before it is shown in the agenda."
  934. :group 'org-agenda
  935. :type '(repeat (regexp)))
  936. (defcustom org-agenda-entry-text-leaders " > "
  937. "Text prepended to the entry text in agenda buffers."
  938. :version "24.4"
  939. :package-version '(Org . "8.0")
  940. :group 'org-agenda
  941. :type 'string)
  942. (defvar org-agenda-entry-text-cleanup-hook nil
  943. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  944. This cleanup is done in a temporary buffer, so the function may inspect and
  945. change the entire buffer.
  946. Some default stuff like drawers and scheduling/deadline dates will already
  947. have been removed when this is called, as will any matches for regular
  948. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  949. (defvar org-agenda-include-inactive-timestamps nil
  950. "Non-nil means include inactive time stamps in agenda and timeline.
  951. Dynamically scoped.")
  952. (defgroup org-agenda-windows nil
  953. "Options concerning the windows used by the Agenda in Org Mode."
  954. :tag "Org Agenda Windows"
  955. :group 'org-agenda)
  956. (defcustom org-agenda-window-setup 'reorganize-frame
  957. "How the agenda buffer should be displayed.
  958. Possible values for this option are:
  959. current-window Show agenda in the current window, keeping all other windows.
  960. other-window Use `switch-to-buffer-other-window' to display agenda.
  961. reorganize-frame Show only two windows on the current frame, the current
  962. window and the agenda.
  963. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  964. Also, when exiting the agenda, kill that frame.
  965. See also the variable `org-agenda-restore-windows-after-quit'."
  966. :group 'org-agenda-windows
  967. :type '(choice
  968. (const current-window)
  969. (const other-frame)
  970. (const other-window)
  971. (const reorganize-frame)))
  972. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  973. "The min and max height of the agenda window as a fraction of frame height.
  974. The value of the variable is a cons cell with two numbers between 0 and 1.
  975. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  976. :group 'org-agenda-windows
  977. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  978. (defcustom org-agenda-restore-windows-after-quit nil
  979. "Non-nil means restore window configuration upon exiting agenda.
  980. Before the window configuration is changed for displaying the agenda,
  981. the current status is recorded. When the agenda is exited with
  982. `q' or `x' and this option is set, the old state is restored. If
  983. `org-agenda-window-setup' is `other-frame', the value of this
  984. option will be ignored."
  985. :group 'org-agenda-windows
  986. :type 'boolean)
  987. (defcustom org-agenda-ndays nil
  988. "Number of days to include in overview display.
  989. Should be 1 or 7.
  990. Obsolete, see `org-agenda-span'."
  991. :group 'org-agenda-daily/weekly
  992. :type 'integer)
  993. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  994. (defcustom org-agenda-span 'week
  995. "Number of days to include in overview display.
  996. Can be day, week, month, year, or any number of days.
  997. Custom commands can set this variable in the options section."
  998. :group 'org-agenda-daily/weekly
  999. :type '(choice (const :tag "Day" day)
  1000. (const :tag "Week" week)
  1001. (const :tag "Month" month)
  1002. (const :tag "Year" year)
  1003. (integer :tag "Custom")))
  1004. (defcustom org-agenda-start-on-weekday 1
  1005. "Non-nil means start the overview always on the specified weekday.
  1006. 0 denotes Sunday, 1 denotes Monday, etc.
  1007. When nil, always start on the current day.
  1008. Custom commands can set this variable in the options section."
  1009. :group 'org-agenda-daily/weekly
  1010. :type '(choice (const :tag "Today" nil)
  1011. (integer :tag "Weekday No.")))
  1012. (defcustom org-agenda-show-all-dates t
  1013. "Non-nil means `org-agenda' shows every day in the selected range.
  1014. When nil, only the days which actually have entries are shown."
  1015. :group 'org-agenda-daily/weekly
  1016. :type 'boolean)
  1017. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1018. "Format string for displaying dates in the agenda.
  1019. Used by the daily/weekly agenda and by the timeline. This should be
  1020. a format string understood by `format-time-string', or a function returning
  1021. the formatted date as a string. The function must take a single argument,
  1022. a calendar-style date list like (month day year)."
  1023. :group 'org-agenda-daily/weekly
  1024. :type '(choice
  1025. (string :tag "Format string")
  1026. (function :tag "Function")))
  1027. (defun org-agenda-format-date-aligned (date)
  1028. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1029. This function makes sure that dates are aligned for easy reading."
  1030. (require 'cal-iso)
  1031. (let* ((dayname (calendar-day-name date))
  1032. (day (cadr date))
  1033. (day-of-week (calendar-day-of-week date))
  1034. (month (car date))
  1035. (monthname (calendar-month-name month))
  1036. (year (nth 2 date))
  1037. (iso-week (org-days-to-iso-week
  1038. (calendar-absolute-from-gregorian date)))
  1039. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1040. (1- year))
  1041. ((and (= month 12) (<= iso-week 1))
  1042. (1+ year))
  1043. (t year)))
  1044. (weekstring (if (= day-of-week 1)
  1045. (format " W%02d" iso-week)
  1046. "")))
  1047. (format "%-10s %2d %s %4d%s"
  1048. dayname day monthname year weekstring)))
  1049. (defcustom org-agenda-time-leading-zero nil
  1050. "Non-nil means use leading zero for military times in agenda.
  1051. For example, 9:30am would become 09:30 rather than 9:30."
  1052. :group 'org-agenda-daily/weekly
  1053. :version "24.1"
  1054. :type 'boolean)
  1055. (defcustom org-agenda-timegrid-use-ampm nil
  1056. "When set, show AM/PM style timestamps on the timegrid."
  1057. :group 'org-agenda
  1058. :version "24.1"
  1059. :type 'boolean)
  1060. (defun org-agenda-time-of-day-to-ampm (time)
  1061. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1062. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1063. (minute (substring time -2))
  1064. (ampm "am"))
  1065. (cond
  1066. ((equal hour-number 12)
  1067. (setq ampm "pm"))
  1068. ((> hour-number 12)
  1069. (setq ampm "pm")
  1070. (setq hour-number (- hour-number 12))))
  1071. (concat
  1072. (if org-agenda-time-leading-zero
  1073. (format "%02d" hour-number)
  1074. (format "%02s" (number-to-string hour-number)))
  1075. ":" minute ampm)))
  1076. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1077. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1078. (if org-agenda-timegrid-use-ampm
  1079. (org-agenda-time-of-day-to-ampm time)
  1080. time))
  1081. (defcustom org-agenda-weekend-days '(6 0)
  1082. "Which days are weekend?
  1083. These days get the special face `org-agenda-date-weekend' in the agenda
  1084. and timeline buffers."
  1085. :group 'org-agenda-daily/weekly
  1086. :type '(set :greedy t
  1087. (const :tag "Monday" 1)
  1088. (const :tag "Tuesday" 2)
  1089. (const :tag "Wednesday" 3)
  1090. (const :tag "Thursday" 4)
  1091. (const :tag "Friday" 5)
  1092. (const :tag "Saturday" 6)
  1093. (const :tag "Sunday" 0)))
  1094. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1095. "Non-nil means jump to today when moving a past date forward in time.
  1096. When using S-right in the agenda to move a a date forward, and the date
  1097. stamp currently points to the past, the first key press will move it
  1098. to today. WHen nil, just move one day forward even if the date stays
  1099. in the past."
  1100. :group 'org-agenda-daily/weekly
  1101. :version "24.1"
  1102. :type 'boolean)
  1103. (defcustom org-agenda-include-diary nil
  1104. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1105. Custom commands can set this variable in the options section."
  1106. :group 'org-agenda-daily/weekly
  1107. :type 'boolean)
  1108. (defcustom org-agenda-include-deadlines t
  1109. "If non-nil, include entries within their deadline warning period.
  1110. Custom commands can set this variable in the options section."
  1111. :group 'org-agenda-daily/weekly
  1112. :version "24.1"
  1113. :type 'boolean)
  1114. (defcustom org-agenda-repeating-timestamp-show-all t
  1115. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1116. When set to a list of strings, only show occurrences of repeating
  1117. stamps for these TODO keywords. When nil, only one occurrence is
  1118. shown, either today or the nearest into the future."
  1119. :group 'org-agenda-daily/weekly
  1120. :type '(choice
  1121. (const :tag "Show repeating stamps" t)
  1122. (repeat :tag "Show repeating stamps for these TODO keywords"
  1123. (string :tag "TODO Keyword"))
  1124. (const :tag "Don't show repeating stamps" nil)))
  1125. (defcustom org-scheduled-past-days 10000
  1126. "Number of days to continue listing scheduled items not marked DONE.
  1127. When an item is scheduled on a date, it shows up in the agenda on this
  1128. day and will be listed until it is marked done for the number of days
  1129. given here."
  1130. :group 'org-agenda-daily/weekly
  1131. :type 'integer)
  1132. (defcustom org-agenda-log-mode-items '(closed clock)
  1133. "List of items that should be shown in agenda log mode.
  1134. This list may contain the following symbols:
  1135. closed Show entries that have been closed on that day.
  1136. clock Show entries that have received clocked time on that day.
  1137. state Show all logged state changes.
  1138. Note that instead of changing this variable, you can also press `C-u l' in
  1139. the agenda to display all available LOG items temporarily."
  1140. :group 'org-agenda-daily/weekly
  1141. :type '(set :greedy t (const closed) (const clock) (const state)))
  1142. (defcustom org-agenda-clock-consistency-checks
  1143. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1144. :gap-ok-around ("4:00")
  1145. :default-face ((:background "DarkRed") (:foreground "white"))
  1146. :overlap-face nil :gap-face nil :no-end-time-face nil
  1147. :long-face nil :short-face nil)
  1148. "This is a property list, with the following keys:
  1149. :max-duration Mark clocking chunks that are longer than this time.
  1150. This is a time string like \"HH:MM\", or the number
  1151. of minutes as an integer.
  1152. :min-duration Mark clocking chunks that are shorter that this.
  1153. This is a time string like \"HH:MM\", or the number
  1154. of minutes as an integer.
  1155. :max-gap Mark gaps between clocking chunks that are longer than
  1156. this duration. A number of minutes, or a string
  1157. like \"HH:MM\".
  1158. :gap-ok-around List of times during the day which are usually not working
  1159. times. When a gap is detected, but the gap contains any
  1160. of these times, the gap is *not* reported. For example,
  1161. if this is (\"4:00\" \"13:00\") then gaps that contain
  1162. 4:00 in the morning (i.e. the night) and 13:00
  1163. (i.e. a typical lunch time) do not cause a warning.
  1164. You should have at least one time during the night in this
  1165. list, or otherwise the first task each morning will trigger
  1166. a warning because it follows a long gap.
  1167. Furthermore, the following properties can be used to define faces for
  1168. issue display.
  1169. :default-face the default face, if the specific face is undefined
  1170. :overlap-face face for overlapping clocks
  1171. :gap-face face for gaps between clocks
  1172. :no-end-time-face face for incomplete clocks
  1173. :long-face face for clock intervals that are too long
  1174. :short-face face for clock intervals that are too short"
  1175. :group 'org-agenda-daily/weekly
  1176. :group 'org-clock
  1177. :version "24.1"
  1178. :type 'plist)
  1179. (defcustom org-agenda-log-mode-add-notes t
  1180. "Non-nil means add first line of notes to log entries in agenda views.
  1181. If a log item like a state change or a clock entry is associated with
  1182. notes, the first line of these notes will be added to the entry in the
  1183. agenda display."
  1184. :group 'org-agenda-daily/weekly
  1185. :type 'boolean)
  1186. (defcustom org-agenda-start-with-log-mode nil
  1187. "The initial value of log-mode in a newly created agenda window.
  1188. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1189. explanations on the possible values."
  1190. :group 'org-agenda-startup
  1191. :group 'org-agenda-daily/weekly
  1192. :type '(choice (const :tag "Don't show log items" nil)
  1193. (const :tag "Show only log items" 'only)
  1194. (const :tag "Show all possible log items" 'clockcheck)
  1195. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1196. (choice (const :tag "Show closed log items" 'closed)
  1197. (const :tag "Show clocked log items" 'clock)
  1198. (const :tag "Show all logged state changes" 'state)))))
  1199. (defcustom org-agenda-start-with-clockreport-mode nil
  1200. "The initial value of clockreport-mode in a newly created agenda window."
  1201. :group 'org-agenda-startup
  1202. :group 'org-agenda-daily/weekly
  1203. :type 'boolean)
  1204. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1205. "Property list with parameters for the clocktable in clockreport mode.
  1206. This is the display mode that shows a clock table in the daily/weekly
  1207. agenda, the properties for this dynamic block can be set here.
  1208. The usual clocktable parameters are allowed here, but you cannot set
  1209. the properties :name, :tstart, :tend, :block, and :scope - these will
  1210. be overwritten to make sure the content accurately reflects the
  1211. current display in the agenda."
  1212. :group 'org-agenda-daily/weekly
  1213. :type 'plist)
  1214. (defcustom org-agenda-search-view-always-boolean nil
  1215. "Non-nil means the search string is interpreted as individual parts.
  1216. The search string for search view can either be interpreted as a phrase,
  1217. or as a list of snippets that define a boolean search for a number of
  1218. strings.
  1219. When this is non-nil, the string will be split on whitespace, and each
  1220. snippet will be searched individually, and all must match in order to
  1221. select an entry. A snippet is then a single string of non-white
  1222. characters, or a string in double quotes, or a regexp in {} braces.
  1223. If a snippet is preceded by \"-\", the snippet must *not* match.
  1224. \"+\" is syntactic sugar for positive selection. Each snippet may
  1225. be found as a full word or a partial word, but see the variable
  1226. `org-agenda-search-view-force-full-words'.
  1227. When this is nil, search will look for the entire search phrase as one,
  1228. with each space character matching any amount of whitespace, including
  1229. line breaks.
  1230. Even when this is nil, you can still switch to Boolean search dynamically
  1231. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1232. is a regexp marked with braces like \"{abc}\", this will also switch to
  1233. boolean search."
  1234. :group 'org-agenda-search-view
  1235. :version "24.1"
  1236. :type 'boolean)
  1237. (org-defvaralias 'org-agenda-search-view-search-words-only
  1238. 'org-agenda-search-view-always-boolean)
  1239. (defcustom org-agenda-search-view-force-full-words nil
  1240. "Non-nil means, search words must be matches as complete words.
  1241. When nil, they may also match part of a word."
  1242. :group 'org-agenda-search-view
  1243. :version "24.1"
  1244. :type 'boolean)
  1245. (defcustom org-agenda-search-view-max-outline-level nil
  1246. "Maximum outline level to display in search view.
  1247. E.g. when this is set to 1, the search view will only
  1248. show headlines of level 1."
  1249. :group 'org-agenda-search-view
  1250. :version "24.4"
  1251. :package-version '(Org . "8.0")
  1252. :type 'integer)
  1253. (defgroup org-agenda-time-grid nil
  1254. "Options concerning the time grid in the Org-mode Agenda."
  1255. :tag "Org Agenda Time Grid"
  1256. :group 'org-agenda)
  1257. (defcustom org-agenda-search-headline-for-time t
  1258. "Non-nil means search headline for a time-of-day.
  1259. If the headline contains a time-of-day in one format or another, it will
  1260. be used to sort the entry into the time sequence of items for a day.
  1261. Some people have time stamps in the headline that refer to the creation
  1262. time or so, and then this produces an unwanted side effect. If this is
  1263. the case for your, use this variable to turn off searching the headline
  1264. for a time."
  1265. :group 'org-agenda-time-grid
  1266. :type 'boolean)
  1267. (defcustom org-agenda-use-time-grid t
  1268. "Non-nil means show a time grid in the agenda schedule.
  1269. A time grid is a set of lines for specific times (like every two hours between
  1270. 8:00 and 20:00). The items scheduled for a day at specific times are
  1271. sorted in between these lines.
  1272. For details about when the grid will be shown, and what it will look like, see
  1273. the variable `org-agenda-time-grid'."
  1274. :group 'org-agenda-time-grid
  1275. :type 'boolean)
  1276. (defcustom org-agenda-time-grid
  1277. '((daily today require-timed)
  1278. "----------------"
  1279. (800 1000 1200 1400 1600 1800 2000))
  1280. "The settings for time grid for agenda display.
  1281. This is a list of three items. The first item is again a list. It contains
  1282. symbols specifying conditions when the grid should be displayed:
  1283. daily if the agenda shows a single day
  1284. weekly if the agenda shows an entire week
  1285. today show grid on current date, independent of daily/weekly display
  1286. require-timed show grid only if at least one item has a time specification
  1287. The second item is a string which will be placed behind the grid time.
  1288. The third item is a list of integers, indicating the times that should have
  1289. a grid line."
  1290. :group 'org-agenda-time-grid
  1291. :type
  1292. '(list
  1293. (set :greedy t :tag "Grid Display Options"
  1294. (const :tag "Show grid in single day agenda display" daily)
  1295. (const :tag "Show grid in weekly agenda display" weekly)
  1296. (const :tag "Always show grid for today" today)
  1297. (const :tag "Show grid only if any timed entries are present"
  1298. require-timed)
  1299. (const :tag "Skip grid times already present in an entry"
  1300. remove-match))
  1301. (string :tag "Grid String")
  1302. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1303. (defcustom org-agenda-show-current-time-in-grid t
  1304. "Non-nil means show the current time in the time grid."
  1305. :group 'org-agenda-time-grid
  1306. :version "24.1"
  1307. :type 'boolean)
  1308. (defcustom org-agenda-current-time-string
  1309. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1310. "The string for the current time marker in the agenda."
  1311. :group 'org-agenda-time-grid
  1312. :version "24.1"
  1313. :type 'string)
  1314. (defgroup org-agenda-sorting nil
  1315. "Options concerning sorting in the Org-mode Agenda."
  1316. :tag "Org Agenda Sorting"
  1317. :group 'org-agenda)
  1318. (defcustom org-agenda-sorting-strategy
  1319. '((agenda habit-down time-up priority-down category-keep)
  1320. (todo priority-down category-keep)
  1321. (tags priority-down category-keep)
  1322. (search category-keep))
  1323. "Sorting structure for the agenda items of a single day.
  1324. This is a list of symbols which will be used in sequence to determine
  1325. if an entry should be listed before another entry. The following
  1326. symbols are recognized:
  1327. time-up Put entries with time-of-day indications first, early first
  1328. time-down Put entries with time-of-day indications first, late first
  1329. timestamp-up Sort by any timestamp, early first
  1330. timestamp-down Sort by any timestamp, late first
  1331. scheduled-up Sort by scheduled timestamp, early first
  1332. scheduled-down Sort by scheduled timestamp, late first
  1333. deadline-up Sort by deadline timestamp, early first
  1334. deadline-down Sort by deadline timestamp, late first
  1335. ts-up Sort by active timestamp, early first
  1336. ts-down Sort by active timestamp, late first
  1337. tsia-up Sort by inactive timestamp, early first
  1338. tsia-down Sort by inactive timestamp, late first
  1339. category-keep Keep the default order of categories, corresponding to the
  1340. sequence in `org-agenda-files'.
  1341. category-up Sort alphabetically by category, A-Z.
  1342. category-down Sort alphabetically by category, Z-A.
  1343. tag-up Sort alphabetically by last tag, A-Z.
  1344. tag-down Sort alphabetically by last tag, Z-A.
  1345. priority-up Sort numerically by priority, high priority last.
  1346. priority-down Sort numerically by priority, high priority first.
  1347. todo-state-up Sort by todo state, tasks that are done last.
  1348. todo-state-down Sort by todo state, tasks that are done first.
  1349. effort-up Sort numerically by estimated effort, high effort last.
  1350. effort-down Sort numerically by estimated effort, high effort first.
  1351. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1352. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1353. habit-up Put entries that are habits first
  1354. habit-down Put entries that are habits last
  1355. alpha-up Sort headlines alphabetically
  1356. alpha-down Sort headlines alphabetically, reversed
  1357. The different possibilities will be tried in sequence, and testing stops
  1358. if one comparison returns a \"not-equal\". For example, the default
  1359. '(time-up category-keep priority-down)
  1360. means: Pull out all entries having a specified time of day and sort them,
  1361. in order to make a time schedule for the current day the first thing in the
  1362. agenda listing for the day. Of the entries without a time indication, keep
  1363. the grouped in categories, don't sort the categories, but keep them in
  1364. the sequence given in `org-agenda-files'. Within each category sort by
  1365. priority.
  1366. Leaving out `category-keep' would mean that items will be sorted across
  1367. categories by priority.
  1368. Instead of a single list, this can also be a set of list for specific
  1369. contents, with a context symbol in the car of the list, any of
  1370. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1371. Custom commands can bind this variable in the options section."
  1372. :group 'org-agenda-sorting
  1373. :type `(choice
  1374. (repeat :tag "General" ,org-sorting-choice)
  1375. (list :tag "Individually"
  1376. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1377. (repeat ,org-sorting-choice))
  1378. (cons (const :tag "Strategy for TODO lists" todo)
  1379. (repeat ,org-sorting-choice))
  1380. (cons (const :tag "Strategy for Tags matches" tags)
  1381. (repeat ,org-sorting-choice))
  1382. (cons (const :tag "Strategy for search matches" search)
  1383. (repeat ,org-sorting-choice)))))
  1384. (defcustom org-agenda-cmp-user-defined nil
  1385. "A function to define the comparison `user-defined'.
  1386. This function must receive two arguments, agenda entry a and b.
  1387. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1388. the user comparison, return nil.
  1389. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1390. part of an agenda sorting strategy."
  1391. :group 'org-agenda-sorting
  1392. :type 'symbol)
  1393. (defcustom org-sort-agenda-notime-is-late t
  1394. "Non-nil means items without time are considered late.
  1395. This is only relevant for sorting. When t, items which have no explicit
  1396. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1397. do have a time. When nil, the default time is before 0:00. You can use this
  1398. option to decide if the schedule for today should come before or after timeless
  1399. agenda entries."
  1400. :group 'org-agenda-sorting
  1401. :type 'boolean)
  1402. (defcustom org-sort-agenda-noeffort-is-high t
  1403. "Non-nil means items without effort estimate are sorted as high effort.
  1404. This also applies when filtering an agenda view with respect to the
  1405. < or > effort operator. Then, tasks with no effort defined will be treated
  1406. as tasks with high effort.
  1407. When nil, such items are sorted as 0 minutes effort."
  1408. :group 'org-agenda-sorting
  1409. :type 'boolean)
  1410. (defgroup org-agenda-line-format nil
  1411. "Options concerning the entry prefix in the Org-mode agenda display."
  1412. :tag "Org Agenda Line Format"
  1413. :group 'org-agenda)
  1414. (defcustom org-agenda-prefix-format
  1415. '((agenda . " %i %-12:c%?-12t% s")
  1416. (timeline . " % s")
  1417. (todo . " %i %-12:c")
  1418. (tags . " %i %-12:c")
  1419. (search . " %i %-12:c"))
  1420. "Format specifications for the prefix of items in the agenda views.
  1421. An alist with five entries, each for the different agenda types. The
  1422. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1423. The values are format strings.
  1424. This format works similar to a printf format, with the following meaning:
  1425. %c the category of the item, \"Diary\" for entries from the diary,
  1426. or as given by the CATEGORY keyword or derived from the file name
  1427. %e the effort required by the item
  1428. %l the level of the item (insert X space(s) if item is of level X)
  1429. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1430. %T the last tag of the item (ignore inherited tags, which come first)
  1431. %t the HH:MM time-of-day specification if one applies to the entry
  1432. %s Scheduling/Deadline information, a short string
  1433. %b show breadcrumbs, i.e., the names of the higher levels
  1434. %(expression) Eval EXPRESSION and replace the control string
  1435. by the result
  1436. All specifiers work basically like the standard `%s' of printf, but may
  1437. contain two additional characters: a question mark just after the `%'
  1438. and a whitespace/punctuation character just before the final letter.
  1439. If the first character after `%' is a question mark, the entire field
  1440. will only be included if the corresponding value applies to the current
  1441. entry. This is useful for fields which should have fixed width when
  1442. present, but zero width when absent. For example, \"%?-12t\" will
  1443. result in a 12 character time field if a time of the day is specified,
  1444. but will completely disappear in entries which do not contain a time.
  1445. If there is punctuation or whitespace character just before the
  1446. final format letter, this character will be appended to the field
  1447. value if the value is not empty. For example, the format
  1448. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1449. the category is empty, no additional colon is inserted.
  1450. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1451. which means:
  1452. - Indent the line with two space characters
  1453. - Give the category a 12 chars wide field, padded with whitespace on
  1454. the right (because of `-'). Append a colon if there is a category
  1455. (because of `:').
  1456. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1457. time, don't put in an empty field, just skip it (because of '?').
  1458. - Finally, put the scheduling information.
  1459. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1460. `org-agenda-remove-tags'.
  1461. Custom commands can set this variable in the options section."
  1462. :type '(choice
  1463. (string :tag "General format")
  1464. (list :greedy t :tag "View dependent"
  1465. (cons (const agenda) (string :tag "Format"))
  1466. (cons (const timeline) (string :tag "Format"))
  1467. (cons (const todo) (string :tag "Format"))
  1468. (cons (const tags) (string :tag "Format"))
  1469. (cons (const search) (string :tag "Format"))))
  1470. :group 'org-agenda-line-format)
  1471. (defvar org-prefix-format-compiled nil
  1472. "The compiled prefix format and associated variables.
  1473. This is a list where first element is a list of variable bindings, and second
  1474. element is the compiled format expression. See the variable
  1475. `org-agenda-prefix-format'.")
  1476. (defcustom org-agenda-todo-keyword-format "%-1s"
  1477. "Format for the TODO keyword in agenda lines.
  1478. Set this to something like \"%-12s\" if you want all TODO keywords
  1479. to occupy a fixed space in the agenda display."
  1480. :group 'org-agenda-line-format
  1481. :type 'string)
  1482. (defcustom org-agenda-diary-sexp-prefix nil
  1483. "A regexp that matches part of a diary sexp entry
  1484. which should be treated as scheduling/deadline information in
  1485. `org-agenda'.
  1486. For example, you can use this to extract the `diary-remind-message' from
  1487. `diary-remind' entries."
  1488. :group 'org-agenda-line-format
  1489. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1490. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1491. "Text preceding timerange entries in the agenda view.
  1492. This is a list with two strings. The first applies when the range
  1493. is entirely on one day. The second applies if the range spans several days.
  1494. The strings may have two \"%d\" format specifiers which will be filled
  1495. with the sequence number of the days, and the total number of days in the
  1496. range, respectively."
  1497. :group 'org-agenda-line-format
  1498. :type '(list
  1499. (string :tag "Deadline today ")
  1500. (choice :tag "Deadline relative"
  1501. (string :tag "Format string")
  1502. (function))))
  1503. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1504. "Text preceding scheduled items in the agenda view.
  1505. This is a list with two strings. The first applies when the item is
  1506. scheduled on the current day. The second applies when it has been scheduled
  1507. previously, it may contain a %d indicating that this is the nth time that
  1508. this item is scheduled, due to automatic rescheduling of unfinished items
  1509. for the following day. So this number is one larger than the number of days
  1510. that passed since this item was scheduled first."
  1511. :group 'org-agenda-line-format
  1512. :version "24.4"
  1513. :package-version '(Org . "8.0")
  1514. :type '(list
  1515. (string :tag "Scheduled today ")
  1516. (string :tag "Scheduled previously")))
  1517. (defcustom org-agenda-inactive-leader "["
  1518. "Text preceding item pulled into the agenda by inactive time stamps.
  1519. These entries are added to the agenda when pressing \"[\"."
  1520. :group 'org-agenda-line-format
  1521. :version "24.1"
  1522. :type '(list
  1523. (string :tag "Scheduled today ")
  1524. (string :tag "Scheduled previously")))
  1525. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1526. "Text preceding deadline items in the agenda view.
  1527. This is a list with three strings. The first applies when the item has its
  1528. deadline on the current day. The second applies when the deadline is in the
  1529. future, the third one when it is in the past. The strings may contain %d
  1530. to capture the number of days."
  1531. :group 'org-agenda-line-format
  1532. :version "24.4"
  1533. :package-version '(Org . "8.0")
  1534. :type '(list
  1535. (string :tag "Deadline today ")
  1536. (choice :tag "Deadline relative"
  1537. (string :tag "Format string")
  1538. (function))))
  1539. (defcustom org-agenda-remove-times-when-in-prefix t
  1540. "Non-nil means remove duplicate time specifications in agenda items.
  1541. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1542. time-of-day specification in a headline or diary entry is extracted and
  1543. placed into the prefix. If this option is non-nil, the original specification
  1544. \(a timestamp or -range, or just a plain time(range) specification like
  1545. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1546. cluttered.
  1547. The option can be t or nil. It may also be the symbol `beg', indicating
  1548. that the time should only be removed when it is located at the beginning of
  1549. the headline/diary entry."
  1550. :group 'org-agenda-line-format
  1551. :type '(choice
  1552. (const :tag "Always" t)
  1553. (const :tag "Never" nil)
  1554. (const :tag "When at beginning of entry" beg)))
  1555. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1556. "Non-nil means remove time ranges specifications in agenda
  1557. items that span on several days."
  1558. :group 'org-agenda-line-format
  1559. :version "24.1"
  1560. :type 'boolean)
  1561. (defcustom org-agenda-default-appointment-duration nil
  1562. "Default duration for appointments that only have a starting time.
  1563. When nil, no duration is specified in such cases.
  1564. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1565. :group 'org-agenda-line-format
  1566. :type '(choice
  1567. (integer :tag "Minutes")
  1568. (const :tag "No default duration")))
  1569. (defcustom org-agenda-show-inherited-tags t
  1570. "Non-nil means show inherited tags in each agenda line.
  1571. When this option is set to 'always, it take precedences over
  1572. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1573. in every agenda.
  1574. When this option is set to t (the default), inherited tags are
  1575. shown when they are available, i.e. when the value of
  1576. `org-agenda-use-tag-inheritance' has been taken into account.
  1577. This can be set to a list of agenda types in which the agenda
  1578. must display the inherited tags. Available types are 'todo,
  1579. 'agenda, 'search and 'timeline.
  1580. When set to nil, never show inherited tags in agenda lines."
  1581. :group 'org-agenda-line-format
  1582. :group 'org-agenda
  1583. :version "24.3"
  1584. :type '(choice
  1585. (const :tag "Show inherited tags when available" t)
  1586. (const :tag "Always show inherited tags" 'always)
  1587. (repeat :tag "Show inherited tags only in selected agenda types"
  1588. (symbol :tag "Agenda type"))))
  1589. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1590. "List of agenda view types where to use tag inheritance.
  1591. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1592. controlled by `org-use-tag-inheritance'. In other agenda types,
  1593. `org-use-tag-inheritance' is not used for the selection of the
  1594. agenda entries. Still, you may want the agenda to be aware of
  1595. the inherited tags anyway, e.g. for later tag filtering.
  1596. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1597. This variable has no effect if `org-agenda-show-inherited-tags'
  1598. is set to 'always. In that case, the agenda is aware of those
  1599. tags.
  1600. The default value sets tags in every agenda type. Setting this
  1601. option to nil will speed up non-tags agenda view a lot."
  1602. :group 'org-agenda
  1603. :version "24.3"
  1604. :type '(choice
  1605. (const :tag "Use tag inheritance in all agenda types" t)
  1606. (repeat :tag "Use tag inheritance in selected agenda types"
  1607. (symbol :tag "Agenda type"))))
  1608. (defcustom org-agenda-hide-tags-regexp nil
  1609. "Regular expression used to filter away specific tags in agenda views.
  1610. This means that these tags will be present, but not be shown in the agenda
  1611. line. Secondary filtering will still work on the hidden tags.
  1612. Nil means don't hide any tags."
  1613. :group 'org-agenda-line-format
  1614. :type '(choice
  1615. (const :tag "Hide none" nil)
  1616. (string :tag "Regexp ")))
  1617. (defcustom org-agenda-remove-tags nil
  1618. "Non-nil means remove the tags from the headline copy in the agenda.
  1619. When this is the symbol `prefix', only remove tags when
  1620. `org-agenda-prefix-format' contains a `%T' specifier."
  1621. :group 'org-agenda-line-format
  1622. :type '(choice
  1623. (const :tag "Always" t)
  1624. (const :tag "Never" nil)
  1625. (const :tag "When prefix format contains %T" prefix)))
  1626. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1627. 'org-agenda-remove-tags)
  1628. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1629. "Shift tags in agenda items to this column.
  1630. If this number is positive, it specifies the column. If it is negative,
  1631. it means that the tags should be flushright to that column. For example,
  1632. -80 works well for a normal 80 character screen."
  1633. :group 'org-agenda-line-format
  1634. :type 'integer)
  1635. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1636. (defcustom org-agenda-fontify-priorities 'cookies
  1637. "Non-nil means highlight low and high priorities in agenda.
  1638. When t, the highest priority entries are bold, lowest priority italic.
  1639. However, settings in `org-priority-faces' will overrule these faces.
  1640. When this variable is the symbol `cookies', only fontify the
  1641. cookies, not the entire task.
  1642. This may also be an association list of priority faces, whose
  1643. keys are the character values of `org-highest-priority',
  1644. `org-default-priority', and `org-lowest-priority' (the default values
  1645. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1646. color as a string, or a list like `(:background \"Red\")'.
  1647. If it is a color, the variable `org-faces-easy-properties'
  1648. determines if it is a foreground or a background color."
  1649. :group 'org-agenda-line-format
  1650. :type '(choice
  1651. (const :tag "Never" nil)
  1652. (const :tag "Defaults" t)
  1653. (const :tag "Cookies only" cookies)
  1654. (repeat :tag "Specify"
  1655. (list (character :tag "Priority" :value ?A)
  1656. (choice :tag "Face "
  1657. (string :tag "Color")
  1658. (sexp :tag "Face"))))))
  1659. (defcustom org-agenda-day-face-function nil
  1660. "Function called to determine what face should be used to display a day.
  1661. The only argument passed to that function is the day. It should
  1662. returns a face, or nil if does not want to specify a face and let
  1663. the normal rules apply."
  1664. :group 'org-agenda-line-format
  1665. :version "24.1"
  1666. :type 'function)
  1667. (defcustom org-agenda-category-icon-alist nil
  1668. "Alist of category icon to be displayed in agenda views.
  1669. Each entry should have the following format:
  1670. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1671. Where CATEGORY-REGEXP is a regexp matching the categories where
  1672. the icon should be displayed.
  1673. FILE-OR-DATA either a file path or a string containing image data.
  1674. The other fields can be omitted safely if not needed:
  1675. TYPE indicates the image type.
  1676. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1677. image data.
  1678. PROPS are additional image attributes to assign to the image,
  1679. like, e.g. `:ascent center'.
  1680. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1681. If you want to set the display properties yourself, just put a
  1682. list as second element:
  1683. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1684. For example, to display a 16px horizontal space for Emacs
  1685. category, you can use:
  1686. (\"Emacs\" '(space . (:width (16))))"
  1687. :group 'org-agenda-line-format
  1688. :version "24.1"
  1689. :type '(alist :key-type (string :tag "Regexp matching category")
  1690. :value-type (choice (list :tag "Icon"
  1691. (string :tag "File or data")
  1692. (symbol :tag "Type")
  1693. (boolean :tag "Data?")
  1694. (repeat :tag "Extra image properties" :inline t symbol))
  1695. (list :tag "Display properties" sexp))))
  1696. (defgroup org-agenda-column-view nil
  1697. "Options concerning column view in the agenda."
  1698. :tag "Org Agenda Column View"
  1699. :group 'org-agenda)
  1700. (defcustom org-agenda-columns-show-summaries t
  1701. "Non-nil means show summaries for columns displayed in the agenda view."
  1702. :group 'org-agenda-column-view
  1703. :type 'boolean)
  1704. (defcustom org-agenda-columns-compute-summary-properties t
  1705. "Non-nil means recompute all summary properties before column view.
  1706. When column view in the agenda is listing properties that have a summary
  1707. operator, it can go to all relevant buffers and recompute the summaries
  1708. there. This can mean overhead for the agenda column view, but is necessary
  1709. to have thing up to date.
  1710. As a special case, a CLOCKSUM property also makes sure that the clock
  1711. computations are current."
  1712. :group 'org-agenda-column-view
  1713. :type 'boolean)
  1714. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1715. "Non-nil means the duration of an appointment will add to day effort.
  1716. The property to which appointment durations will be added is the one given
  1717. in the option `org-effort-property'. If an appointment does not have
  1718. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1719. is not set, an appointment without end time will not contribute to the time
  1720. estimate."
  1721. :group 'org-agenda-column-view
  1722. :type 'boolean)
  1723. (defcustom org-agenda-auto-exclude-function nil
  1724. "A function called with a tag to decide if it is filtered on '/ RET'.
  1725. The sole argument to the function, which is called once for each
  1726. possible tag, is a string giving the name of the tag. The
  1727. function should return either nil if the tag should be included
  1728. as normal, or \"-<TAG>\" to exclude the tag.
  1729. Note that for the purpose of tag filtering, only the lower-case version of
  1730. all tags will be considered, so that this function will only ever see
  1731. the lower-case version of all tags."
  1732. :group 'org-agenda
  1733. :type 'function)
  1734. (defcustom org-agenda-bulk-custom-functions nil
  1735. "Alist of characters and custom functions for bulk actions.
  1736. For example, this value makes those two functions available:
  1737. '((?R set-category)
  1738. (?C bulk-cut))
  1739. With selected entries in an agenda buffer, `B R' will call
  1740. the custom function `set-category' on the selected entries.
  1741. Note that functions in this alist don't need to be quoted."
  1742. :type 'alist
  1743. :version "24.1"
  1744. :group 'org-agenda)
  1745. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1746. "Execute BODY with point at location given by `org-hd-marker' property.
  1747. If STRING is non-nil, the text property will be fetched from position 0
  1748. in that string. If STRING is nil, it will be fetched from the beginning
  1749. of the current line."
  1750. (org-with-gensyms (marker)
  1751. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1752. 'org-hd-marker ,string)))
  1753. (with-current-buffer (marker-buffer ,marker)
  1754. (save-excursion
  1755. (goto-char ,marker)
  1756. ,@body)))))
  1757. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1758. (defun org-add-agenda-custom-command (entry)
  1759. "Replace or add a command in `org-agenda-custom-commands'.
  1760. This is mostly for hacking and trying a new command - once the command
  1761. works you probably want to add it to `org-agenda-custom-commands' for good."
  1762. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1763. (if ass
  1764. (setcdr ass (cdr entry))
  1765. (push entry org-agenda-custom-commands))))
  1766. ;;; Define the org-agenda-mode
  1767. (defvar org-agenda-mode-map (make-sparse-keymap)
  1768. "Keymap for `org-agenda-mode'.")
  1769. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1770. (defvar org-agenda-menu) ; defined later in this file.
  1771. (defvar org-agenda-restrict nil) ; defined later in this file.
  1772. (defvar org-agenda-follow-mode nil)
  1773. (defvar org-agenda-entry-text-mode nil)
  1774. (defvar org-agenda-clockreport-mode nil)
  1775. (defvar org-agenda-show-log nil)
  1776. (defvar org-agenda-redo-command nil)
  1777. (defvar org-agenda-query-string nil)
  1778. (defvar org-agenda-mode-hook nil
  1779. "Hook run after `org-agenda-mode' is turned on.
  1780. The buffer is still writable when this hook is called.")
  1781. (defvar org-agenda-type nil)
  1782. (defvar org-agenda-force-single-file nil)
  1783. (defvar org-agenda-bulk-marked-entries nil
  1784. "List of markers that refer to marked entries in the agenda.")
  1785. ;;; Multiple agenda buffers support
  1786. (defcustom org-agenda-sticky nil
  1787. "Non-nil means agenda q key will bury agenda buffers.
  1788. Agenda commands will then show existing buffer instead of generating new ones.
  1789. When nil, `q' will kill the single agenda buffer."
  1790. :group 'org-agenda
  1791. :version "24.3"
  1792. :type 'boolean)
  1793. ;;;###autoload
  1794. (defun org-toggle-sticky-agenda (&optional arg)
  1795. "Toggle `org-agenda-sticky'."
  1796. (interactive "P")
  1797. (let ((new-value (if arg
  1798. (> (prefix-numeric-value arg) 0)
  1799. (not org-agenda-sticky))))
  1800. (if (equal new-value org-agenda-sticky)
  1801. (and (org-called-interactively-p 'interactive)
  1802. (message "Sticky agenda was already %s"
  1803. (if org-agenda-sticky "enabled" "disabled")))
  1804. (setq org-agenda-sticky new-value)
  1805. (org-agenda-kill-all-agenda-buffers)
  1806. (and (org-called-interactively-p 'interactive)
  1807. (message "Sticky agenda was %s"
  1808. (if org-agenda-sticky "enabled" "disabled"))))))
  1809. (defvar org-agenda-buffer nil
  1810. "Agenda buffer currently being generated.")
  1811. (defvar org-agenda-last-prefix-arg nil)
  1812. (defvar org-agenda-this-buffer-name nil)
  1813. (defvar org-agenda-doing-sticky-redo nil)
  1814. (defvar org-agenda-this-buffer-is-sticky nil)
  1815. (defconst org-agenda-local-vars
  1816. '(org-agenda-this-buffer-name
  1817. org-agenda-undo-list
  1818. org-agenda-pending-undo-list
  1819. org-agenda-follow-mode
  1820. org-agenda-entry-text-mode
  1821. org-agenda-clockreport-mode
  1822. org-agenda-show-log
  1823. org-agenda-redo-command
  1824. org-agenda-query-string
  1825. org-agenda-type
  1826. org-agenda-bulk-marked-entries
  1827. org-agenda-undo-has-started-in
  1828. org-agenda-info
  1829. org-agenda-pre-window-conf
  1830. org-agenda-columns-active
  1831. org-agenda-tag-filter-overlays
  1832. org-agenda-tag-filter
  1833. org-agenda-cat-filter-overlays
  1834. org-agenda-category-filter
  1835. org-agenda-re-filter-overlays
  1836. org-agenda-regexp-filter
  1837. org-agenda-markers
  1838. org-agenda-last-search-view-search-was-boolean
  1839. org-agenda-filtered-by-category
  1840. org-agenda-filter-form
  1841. org-agenda-cycle-counter
  1842. org-agenda-last-prefix-arg)
  1843. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1844. (defun org-agenda-mode ()
  1845. "Mode for time-sorted view on action items in Org-mode files.
  1846. The following commands are available:
  1847. \\{org-agenda-mode-map}"
  1848. (interactive)
  1849. (cond (org-agenda-doing-sticky-redo
  1850. ;; Refreshing sticky agenda-buffer
  1851. ;;
  1852. ;; Preserve the value of `org-agenda-local-vars' variables,
  1853. ;; while letting `kill-all-local-variables' kill the rest
  1854. (let ((save (buffer-local-variables)))
  1855. (kill-all-local-variables)
  1856. (mapc 'make-local-variable org-agenda-local-vars)
  1857. (dolist (elem save)
  1858. (let ((var (car elem))
  1859. (val (cdr elem)))
  1860. (when (and val
  1861. (member var org-agenda-local-vars))
  1862. (set var val)))))
  1863. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1864. (org-agenda-sticky
  1865. ;; Creating a sticky Agenda buffer for the first time
  1866. (kill-all-local-variables)
  1867. (mapc 'make-local-variable org-agenda-local-vars)
  1868. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1869. (t
  1870. ;; Creating a non-sticky agenda buffer
  1871. (kill-all-local-variables)
  1872. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1873. (setq org-agenda-undo-list nil
  1874. org-agenda-pending-undo-list nil
  1875. org-agenda-bulk-marked-entries nil)
  1876. (setq major-mode 'org-agenda-mode)
  1877. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1878. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1879. (setq mode-name "Org-Agenda")
  1880. (use-local-map org-agenda-mode-map)
  1881. (easy-menu-add org-agenda-menu)
  1882. (if org-startup-truncated (setq truncate-lines t))
  1883. (org-set-local 'line-move-visual nil)
  1884. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1885. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1886. ;; Make sure properties are removed when copying text
  1887. (make-local-variable 'filter-buffer-substring-functions)
  1888. (add-hook 'filter-buffer-substring-functions
  1889. (lambda (fun start end delete)
  1890. (substring-no-properties (funcall fun start end delete))))
  1891. (unless org-agenda-keep-modes
  1892. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1893. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1894. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1895. org-agenda-show-log org-agenda-start-with-log-mode))
  1896. (easy-menu-change
  1897. '("Agenda") "Agenda Files"
  1898. (append
  1899. (list
  1900. (vector
  1901. (if (get 'org-agenda-files 'org-restrict)
  1902. "Restricted to single file"
  1903. "Edit File List")
  1904. '(org-edit-agenda-file-list)
  1905. (not (get 'org-agenda-files 'org-restrict)))
  1906. "--")
  1907. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1908. (org-agenda-set-mode-name)
  1909. (apply
  1910. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1911. (list 'org-agenda-mode-hook)))
  1912. (substitute-key-definition 'undo 'org-agenda-undo
  1913. org-agenda-mode-map global-map)
  1914. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1915. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1916. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1917. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1918. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1919. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1920. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1921. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1922. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1923. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1924. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1925. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1926. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1927. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1928. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1929. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1930. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1931. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1932. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1933. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1934. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1935. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1936. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1937. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1938. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1939. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1940. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1941. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1942. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1943. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1944. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1945. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1946. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1947. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1948. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1949. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1950. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1951. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1952. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1953. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1954. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1955. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1956. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1957. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1958. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1959. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1960. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1961. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1962. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1963. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1964. (while l (org-defkey org-agenda-mode-map
  1965. (int-to-string (pop l)) 'digit-argument)))
  1966. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1967. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1968. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1969. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1970. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1971. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1972. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1973. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1974. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1975. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1976. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1977. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1978. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1979. 'org-clock-modify-effort-estimate)
  1980. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1981. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1982. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1983. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1984. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1985. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1986. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1987. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1988. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1989. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1990. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1991. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1992. (substitute-key-definition 'next-line 'org-agenda-next-line
  1993. org-agenda-mode-map global-map)
  1994. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1995. org-agenda-mode-map global-map)
  1996. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1997. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1998. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1999. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2000. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2001. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2002. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2003. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2004. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2005. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2006. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2007. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2008. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2009. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2010. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2011. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2012. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2013. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2014. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2015. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2016. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2017. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2018. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2019. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2020. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2021. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2022. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2023. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2024. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2025. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2026. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2027. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2028. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2029. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2030. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2031. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2032. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2033. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2034. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2035. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2036. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2037. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2038. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2039. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2040. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2041. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2042. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2043. (when org-agenda-mouse-1-follows-link
  2044. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2045. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2046. '("Agenda"
  2047. ("Agenda Files")
  2048. "--"
  2049. ("Agenda Dates"
  2050. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2051. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2052. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2053. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2054. "--"
  2055. ("View"
  2056. ["Day View" org-agenda-day-view
  2057. :active (org-agenda-check-type nil 'agenda)
  2058. :style radio :selected (eq org-agenda-current-span 'day)
  2059. :keys "v d (or just d)"]
  2060. ["Week View" org-agenda-week-view
  2061. :active (org-agenda-check-type nil 'agenda)
  2062. :style radio :selected (eq org-agenda-current-span 'week)
  2063. :keys "v w (or just w)"]
  2064. ["Month View" org-agenda-month-view
  2065. :active (org-agenda-check-type nil 'agenda)
  2066. :style radio :selected (eq org-agenda-current-span 'month)
  2067. :keys "v m"]
  2068. ["Year View" org-agenda-year-view
  2069. :active (org-agenda-check-type nil 'agenda)
  2070. :style radio :selected (eq org-agenda-current-span 'year)
  2071. :keys "v y"]
  2072. "--"
  2073. ["Include Diary" org-agenda-toggle-diary
  2074. :style toggle :selected org-agenda-include-diary
  2075. :active (org-agenda-check-type nil 'agenda)]
  2076. ["Include Deadlines" org-agenda-toggle-deadlines
  2077. :style toggle :selected org-agenda-include-deadlines
  2078. :active (org-agenda-check-type nil 'agenda)]
  2079. ["Use Time Grid" org-agenda-toggle-time-grid
  2080. :style toggle :selected org-agenda-use-time-grid
  2081. :active (org-agenda-check-type nil 'agenda)]
  2082. "--"
  2083. ["Show clock report" org-agenda-clockreport-mode
  2084. :style toggle :selected org-agenda-clockreport-mode
  2085. :active (org-agenda-check-type nil 'agenda)]
  2086. ["Show some entry text" org-agenda-entry-text-mode
  2087. :style toggle :selected org-agenda-entry-text-mode
  2088. :active t]
  2089. "--"
  2090. ["Show Logbook entries" org-agenda-log-mode
  2091. :style toggle :selected org-agenda-show-log
  2092. :active (org-agenda-check-type nil 'agenda 'timeline)
  2093. :keys "v l (or just l)"]
  2094. ["Include archived trees" org-agenda-archives-mode
  2095. :style toggle :selected org-agenda-archives-mode :active t
  2096. :keys "v a"]
  2097. ["Include archive files" (org-agenda-archives-mode t)
  2098. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2099. :keys "v A"]
  2100. "--"
  2101. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2102. ["Write view to file" org-agenda-write t]
  2103. ["Rebuild buffer" org-agenda-redo t]
  2104. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2105. "--"
  2106. ["Show original entry" org-agenda-show t]
  2107. ["Go To (other window)" org-agenda-goto t]
  2108. ["Go To (this window)" org-agenda-switch-to t]
  2109. ["Capture with cursor date" org-agenda-capture t]
  2110. ["Follow Mode" org-agenda-follow-mode
  2111. :style toggle :selected org-agenda-follow-mode :active t]
  2112. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2113. "--"
  2114. ("TODO"
  2115. ["Cycle TODO" org-agenda-todo t]
  2116. ["Next TODO set" org-agenda-todo-nextset t]
  2117. ["Previous TODO set" org-agenda-todo-previousset t]
  2118. ["Add note" org-agenda-add-note t])
  2119. ("Archive/Refile/Delete"
  2120. ["Archive default" org-agenda-archive-default t]
  2121. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2122. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2123. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2124. ["Archive subtree" org-agenda-archive t]
  2125. "--"
  2126. ["Refile" org-agenda-refile t]
  2127. "--"
  2128. ["Delete subtree" org-agenda-kill t])
  2129. ("Bulk action"
  2130. ["Mark entry" org-agenda-bulk-mark t]
  2131. ["Mark all" org-agenda-bulk-mark-all t]
  2132. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  2133. ["Unmark entry" org-agenda-bulk-unmark t]
  2134. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2135. ["Act on all marked" org-agenda-bulk-action t]
  2136. "--"
  2137. ("Tags and Properties"
  2138. ["Show all Tags" org-agenda-show-tags t]
  2139. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2140. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2141. "--"
  2142. ["Column View" org-columns t])
  2143. ("Deadline/Schedule"
  2144. ["Schedule" org-agenda-schedule t]
  2145. ["Set Deadline" org-agenda-deadline t]
  2146. "--"
  2147. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2148. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2149. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2150. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2151. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2152. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2153. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2154. ("Clock and Effort"
  2155. ["Clock in" org-agenda-clock-in t]
  2156. ["Clock out" org-agenda-clock-out t]
  2157. ["Clock cancel" org-agenda-clock-cancel t]
  2158. ["Goto running clock" org-clock-goto t]
  2159. "--"
  2160. ["Set Effort" org-agenda-set-effort t]
  2161. ["Change clocked effort" org-clock-modify-effort-estimate
  2162. (org-clock-is-active)])
  2163. ("Priority"
  2164. ["Set Priority" org-agenda-priority t]
  2165. ["Increase Priority" org-agenda-priority-up t]
  2166. ["Decrease Priority" org-agenda-priority-down t]
  2167. ["Show Priority" org-show-priority t])
  2168. ("Calendar/Diary"
  2169. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2170. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2171. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2172. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2173. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2174. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2175. "--"
  2176. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2177. "--"
  2178. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2179. "--"
  2180. ("MobileOrg"
  2181. ["Push Files and Views" org-mobile-push t]
  2182. ["Get Captured and Flagged" org-mobile-pull t]
  2183. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2184. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2185. "--"
  2186. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2187. "--"
  2188. ["Quit" org-agenda-quit t]
  2189. ["Exit and Release Buffers" org-agenda-exit t]
  2190. ))
  2191. ;;; Agenda undo
  2192. (defvar org-agenda-allow-remote-undo t
  2193. "Non-nil means allow remote undo from the agenda buffer.")
  2194. (defvar org-agenda-undo-has-started-in nil
  2195. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2196. (defun org-agenda-undo ()
  2197. "Undo a remote editing step in the agenda.
  2198. This undoes changes both in the agenda buffer and in the remote buffer
  2199. that have been changed along."
  2200. (interactive)
  2201. (or org-agenda-allow-remote-undo
  2202. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2203. (if (not (eq this-command last-command))
  2204. (setq org-agenda-undo-has-started-in nil
  2205. org-agenda-pending-undo-list org-agenda-undo-list))
  2206. (if (not org-agenda-pending-undo-list)
  2207. (user-error "No further undo information"))
  2208. (let* ((entry (pop org-agenda-pending-undo-list))
  2209. buf line cmd rembuf)
  2210. (setq cmd (pop entry) line (pop entry))
  2211. (setq rembuf (nth 2 entry))
  2212. (org-with-remote-undo rembuf
  2213. (while (bufferp (setq buf (pop entry)))
  2214. (if (pop entry)
  2215. (with-current-buffer buf
  2216. (let ((last-undo-buffer buf)
  2217. (inhibit-read-only t))
  2218. (unless (memq buf org-agenda-undo-has-started-in)
  2219. (push buf org-agenda-undo-has-started-in)
  2220. (make-local-variable 'pending-undo-list)
  2221. (undo-start))
  2222. (while (and pending-undo-list
  2223. (listp pending-undo-list)
  2224. (not (car pending-undo-list)))
  2225. (pop pending-undo-list))
  2226. (undo-more 1))))))
  2227. (org-goto-line line)
  2228. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2229. (defun org-verify-change-for-undo (l1 l2)
  2230. "Verify that a real change occurred between the undo lists L1 and L2."
  2231. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2232. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2233. (not (eq l1 l2)))
  2234. ;;; Agenda dispatch
  2235. (defvar org-agenda-restrict-begin (make-marker))
  2236. (defvar org-agenda-restrict-end (make-marker))
  2237. (defvar org-agenda-last-dispatch-buffer nil)
  2238. (defvar org-agenda-overriding-restriction nil)
  2239. (defcustom org-agenda-custom-commands-contexts nil
  2240. "Alist of custom agenda keys and contextual rules.
  2241. For example, if you have a custom agenda command \"p\" and you
  2242. want this command to be accessible only from plain text files,
  2243. use this:
  2244. '((\"p\" ((in-file . \"\\.txt\"))))
  2245. Here are the available contexts definitions:
  2246. in-file: command displayed only in matching files
  2247. in-mode: command displayed only in matching modes
  2248. not-in-file: command not displayed in matching files
  2249. not-in-mode: command not displayed in matching modes
  2250. in-buffer: command displayed only in matching buffers
  2251. not-in-buffer: command not displayed in matching buffers
  2252. [function]: a custom function taking no argument
  2253. If you define several checks, the agenda command will be
  2254. accessible if there is at least one valid check.
  2255. You can also bind a key to another agenda custom command
  2256. depending on contextual rules.
  2257. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2258. Here it means: in .txt files, use \"p\" as the key for the
  2259. agenda command otherwise associated with \"q\". (The command
  2260. originally associated with \"q\" is not displayed to avoid
  2261. duplicates.)"
  2262. :version "24.3"
  2263. :group 'org-agenda-custom-commands
  2264. :type '(repeat (list :tag "Rule"
  2265. (string :tag " Agenda key")
  2266. (string :tag "Replace by command")
  2267. (repeat :tag "Available when"
  2268. (choice
  2269. (cons :tag "Condition"
  2270. (choice
  2271. (const :tag "In file" in-file)
  2272. (const :tag "Not in file" not-in-file)
  2273. (const :tag "In buffer" in-buffer)
  2274. (const :tag "Not in buffer" not-in-buffer)
  2275. (const :tag "In mode" in-mode)
  2276. (const :tag "Not in mode" not-in-mode))
  2277. (regexp))
  2278. (function :tag "Custom function"))))))
  2279. (defcustom org-agenda-max-entries nil
  2280. "Maximum number of entries to display in an agenda.
  2281. This can be nil (no limit) or an integer or an alist of agenda
  2282. types with an associated number of entries to display in this
  2283. type."
  2284. :version "24.4"
  2285. :package-version '(Org . "8.0")
  2286. :group 'org-agenda-custom-commands
  2287. :type '(choice (symbol :tag "No limit" nil)
  2288. (integer :tag "Max number of entries")
  2289. (repeat
  2290. (cons (choice :tag "Agenda type"
  2291. (const agenda)
  2292. (const todo)
  2293. (const tags)
  2294. (const search)
  2295. (const timeline))
  2296. (integer :tag "Max number of entries")))))
  2297. (defcustom org-agenda-max-todos nil
  2298. "Maximum number of TODOs to display in an agenda.
  2299. This can be nil (no limit) or an integer or an alist of agenda
  2300. types with an associated number of entries to display in this
  2301. type."
  2302. :version "24.4"
  2303. :package-version '(Org . "8.0")
  2304. :group 'org-agenda-custom-commands
  2305. :type '(choice (symbol :tag "No limit" nil)
  2306. (integer :tag "Max number of entries")
  2307. (repeat
  2308. (cons (choice :tag "Agenda type"
  2309. (const agenda)
  2310. (const todo)
  2311. (const tags)
  2312. (const search)
  2313. (const timeline))
  2314. (integer :tag "Max number of entries")))))
  2315. (defcustom org-agenda-max-tags nil
  2316. "Maximum number of tagged entries to display in an agenda.
  2317. This can be nil (no limit) or an integer or an alist of agenda
  2318. types with an associated number of entries to display in this
  2319. type."
  2320. :version "24.4"
  2321. :package-version '(Org . "8.0")
  2322. :group 'org-agenda-custom-commands
  2323. :type '(choice (symbol :tag "No limit" nil)
  2324. (integer :tag "Max number of entries")
  2325. (repeat
  2326. (cons (choice :tag "Agenda type"
  2327. (const agenda)
  2328. (const todo)
  2329. (const tags)
  2330. (const search)
  2331. (const timeline))
  2332. (integer :tag "Max number of entries")))))
  2333. (defcustom org-agenda-max-effort nil
  2334. "Maximum cumulated effort duration for the agenda.
  2335. This can be nil (no limit) or a number of minutes (as an integer)
  2336. or an alist of agenda types with an associated number of minutes
  2337. to limit entries to in this type."
  2338. :version "24.4"
  2339. :package-version '(Org . "8.0")
  2340. :group 'org-agenda-custom-commands
  2341. :type '(choice (symbol :tag "No limit" nil)
  2342. (integer :tag "Max number of entries")
  2343. (repeat
  2344. (cons (choice :tag "Agenda type"
  2345. (const agenda)
  2346. (const todo)
  2347. (const tags)
  2348. (const search)
  2349. (const timeline))
  2350. (integer :tag "Max number of entries")))))
  2351. (defvar org-keys nil)
  2352. (defvar org-match nil)
  2353. ;;;###autoload
  2354. (defun org-agenda (&optional arg org-keys restriction)
  2355. "Dispatch agenda commands to collect entries to the agenda buffer.
  2356. Prompts for a command to execute. Any prefix arg will be passed
  2357. on to the selected command. The default selections are:
  2358. a Call `org-agenda-list' to display the agenda for current day or week.
  2359. t Call `org-todo-list' to display the global todo list.
  2360. T Call `org-todo-list' to display the global todo list, select only
  2361. entries with a specific TODO keyword (the user gets a prompt).
  2362. m Call `org-tags-view' to display headlines with tags matching
  2363. a condition (the user is prompted for the condition).
  2364. M Like `m', but select only TODO entries, no ordinary headlines.
  2365. L Create a timeline for the current buffer.
  2366. e Export views to associated files.
  2367. s Search entries for keywords.
  2368. S Search entries for keywords, only with TODO keywords.
  2369. / Multi occur across all agenda files and also files listed
  2370. in `org-agenda-text-search-extra-files'.
  2371. < Restrict agenda commands to buffer, subtree, or region.
  2372. Press several times to get the desired effect.
  2373. > Remove a previous restriction.
  2374. # List \"stuck\" projects.
  2375. ! Configure what \"stuck\" means.
  2376. C Configure custom agenda commands.
  2377. More commands can be added by configuring the variable
  2378. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2379. searches can be pre-defined in this way.
  2380. If the current buffer is in Org-mode and visiting a file, you can also
  2381. first press `<' once to indicate that the agenda should be temporarily
  2382. \(until the next use of \\[org-agenda]) restricted to the current file.
  2383. Pressing `<' twice means to restrict to the current subtree or region
  2384. \(if active)."
  2385. (interactive "P")
  2386. (catch 'exit
  2387. (let* ((prefix-descriptions nil)
  2388. (org-agenda-buffer-name org-agenda-buffer-name)
  2389. (org-agenda-window-setup (if (equal (buffer-name)
  2390. org-agenda-buffer-name)
  2391. 'current-window
  2392. org-agenda-window-setup))
  2393. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2394. (org-agenda-custom-commands
  2395. ;; normalize different versions
  2396. (delq nil
  2397. (mapcar
  2398. (lambda (x)
  2399. (cond ((stringp (cdr x))
  2400. (push x prefix-descriptions)
  2401. nil)
  2402. ((stringp (nth 1 x)) x)
  2403. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2404. (t (cons (car x) (cons "" (cdr x))))))
  2405. org-agenda-custom-commands)))
  2406. (org-agenda-custom-commands
  2407. (org-contextualize-keys
  2408. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2409. (buf (current-buffer))
  2410. (bfn (buffer-file-name (buffer-base-buffer)))
  2411. entry key type org-match lprops ans)
  2412. ;; Turn off restriction unless there is an overriding one,
  2413. (unless org-agenda-overriding-restriction
  2414. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2415. ;; There is a request to keep the file list in place
  2416. (put 'org-agenda-files 'org-restrict nil))
  2417. (setq org-agenda-restrict nil)
  2418. (move-marker org-agenda-restrict-begin nil)
  2419. (move-marker org-agenda-restrict-end nil))
  2420. ;; Delete old local properties
  2421. (put 'org-agenda-redo-command 'org-lprops nil)
  2422. ;; Delete previously set last-arguments
  2423. (put 'org-agenda-redo-command 'last-args nil)
  2424. ;; Remember where this call originated
  2425. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2426. (unless org-keys
  2427. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2428. org-keys (car ans)
  2429. restriction (cdr ans)))
  2430. ;; If we have sticky agenda buffers, set a name for the buffer,
  2431. ;; depending on the invoking keys. The user may still set this
  2432. ;; as a command option, which will overwrite what we do here.
  2433. (if org-agenda-sticky
  2434. (setq org-agenda-buffer-name
  2435. (format "*Org Agenda(%s)*" org-keys)))
  2436. ;; Establish the restriction, if any
  2437. (when (and (not org-agenda-overriding-restriction) restriction)
  2438. (put 'org-agenda-files 'org-restrict (list bfn))
  2439. (cond
  2440. ((eq restriction 'region)
  2441. (setq org-agenda-restrict t)
  2442. (move-marker org-agenda-restrict-begin (region-beginning))
  2443. (move-marker org-agenda-restrict-end (region-end)))
  2444. ((eq restriction 'subtree)
  2445. (save-excursion
  2446. (setq org-agenda-restrict t)
  2447. (org-back-to-heading t)
  2448. (move-marker org-agenda-restrict-begin (point))
  2449. (move-marker org-agenda-restrict-end
  2450. (progn (org-end-of-subtree t)))))))
  2451. ;; For example the todo list should not need it (but does...)
  2452. (cond
  2453. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2454. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2455. (progn
  2456. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2457. lprops (nth 4 entry))
  2458. (if org-agenda-sticky
  2459. (setq org-agenda-buffer-name
  2460. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2461. (format "*Org Agenda(%s)*" org-keys))))
  2462. (put 'org-agenda-redo-command 'org-lprops lprops)
  2463. (cond
  2464. ((eq type 'agenda)
  2465. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2466. ((eq type 'agenda*)
  2467. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2468. ((eq type 'alltodo)
  2469. (org-let lprops '(org-todo-list current-prefix-arg)))
  2470. ((eq type 'search)
  2471. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2472. ((eq type 'stuck)
  2473. (org-let lprops '(org-agenda-list-stuck-projects
  2474. current-prefix-arg)))
  2475. ((eq type 'tags)
  2476. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2477. ((eq type 'tags-todo)
  2478. (org-let lprops '(org-tags-view '(4) org-match)))
  2479. ((eq type 'todo)
  2480. (org-let lprops '(org-todo-list org-match)))
  2481. ((eq type 'tags-tree)
  2482. (org-check-for-org-mode)
  2483. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2484. ((eq type 'todo-tree)
  2485. (org-check-for-org-mode)
  2486. (org-let lprops
  2487. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2488. (regexp-quote org-match) "\\>"))))
  2489. ((eq type 'occur-tree)
  2490. (org-check-for-org-mode)
  2491. (org-let lprops '(org-occur org-match)))
  2492. ((functionp type)
  2493. (org-let lprops '(funcall type org-match)))
  2494. ((fboundp type)
  2495. (org-let lprops '(funcall type org-match)))
  2496. (t (user-error "Invalid custom agenda command type %s" type))))
  2497. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2498. ((equal org-keys "C")
  2499. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2500. (customize-variable 'org-agenda-custom-commands))
  2501. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2502. ((equal org-keys "s") (call-interactively 'org-search-view))
  2503. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2504. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2505. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2506. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2507. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2508. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2509. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2510. (org-add-hook
  2511. 'post-command-hook
  2512. (lambda ()
  2513. (unless (current-message)
  2514. (let* ((m (org-agenda-get-any-marker))
  2515. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2516. (when note
  2517. (message (concat
  2518. "FLAGGING-NOTE ([?] for more info): "
  2519. (org-add-props
  2520. (replace-regexp-in-string
  2521. "\\\\n" "//"
  2522. (copy-sequence note))
  2523. nil 'face 'org-warning)))))))
  2524. t t))
  2525. ((equal org-keys "L")
  2526. (unless (derived-mode-p 'org-mode)
  2527. (user-error "This is not an Org-mode file"))
  2528. (unless restriction
  2529. (put 'org-agenda-files 'org-restrict (list bfn))
  2530. (org-call-with-arg 'org-timeline arg)))
  2531. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2532. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2533. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2534. (t (user-error "Invalid agenda key"))))))
  2535. (defun org-agenda-append-agenda ()
  2536. "Append another agenda view to the current one.
  2537. This function allows interactive building of block agendas.
  2538. Agenda views are separated by `org-agenda-block-separator'."
  2539. (interactive)
  2540. (unless (derived-mode-p 'org-agenda-mode)
  2541. (user-error "Can only append from within agenda buffer"))
  2542. (let ((org-agenda-multi t))
  2543. (org-agenda)
  2544. (widen)
  2545. (org-agenda-finalize)
  2546. (setq buffer-read-only t)
  2547. (org-agenda-fit-window-to-buffer)))
  2548. (defun org-agenda-normalize-custom-commands (cmds)
  2549. "Normalize custom commands CMDS."
  2550. (delq nil
  2551. (mapcar
  2552. (lambda (x)
  2553. (cond ((stringp (cdr x)) nil)
  2554. ((stringp (nth 1 x)) x)
  2555. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2556. (t (cons (car x) (cons "" (cdr x))))))
  2557. cmds)))
  2558. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2559. "The user interface for selecting an agenda command."
  2560. (catch 'exit
  2561. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2562. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2563. (region-p (org-region-active-p))
  2564. (custom org-agenda-custom-commands)
  2565. (selstring "")
  2566. restriction second-time
  2567. c entry key type match prefixes rmheader header-end custom1 desc
  2568. line lines left right n n1)
  2569. (save-window-excursion
  2570. (delete-other-windows)
  2571. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2572. (erase-buffer)
  2573. (insert (eval-when-compile
  2574. (let ((header
  2575. "Press key for an agenda command: < Buffer, subtree/region restriction
  2576. -------------------------------- > Remove restriction
  2577. a Agenda for current week or day e Export agenda views
  2578. t List of all TODO entries T Entries with special TODO kwd
  2579. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2580. s Search for keywords S Like s, but only TODO entries
  2581. L Timeline for current buffer # List stuck projects (!=configure)
  2582. / Multi-occur C Configure custom agenda commands
  2583. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2584. ")
  2585. (start 0))
  2586. (while (string-match
  2587. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2588. header start)
  2589. (setq start (match-end 0))
  2590. (add-text-properties (match-beginning 2) (match-end 2)
  2591. '(face bold) header))
  2592. header)))
  2593. (setq header-end (point-marker))
  2594. (while t
  2595. (setq custom1 custom)
  2596. (when (eq rmheader t)
  2597. (org-goto-line 1)
  2598. (re-search-forward ":" nil t)
  2599. (delete-region (match-end 0) (point-at-eol))
  2600. (forward-char 1)
  2601. (looking-at "-+")
  2602. (delete-region (match-end 0) (point-at-eol))
  2603. (move-marker header-end (match-end 0)))
  2604. (goto-char header-end)
  2605. (delete-region (point) (point-max))
  2606. ;; Produce all the lines that describe custom commands and prefixes
  2607. (setq lines nil)
  2608. (while (setq entry (pop custom1))
  2609. (setq key (car entry) desc (nth 1 entry)
  2610. type (nth 2 entry)
  2611. match (nth 3 entry))
  2612. (if (> (length key) 1)
  2613. (add-to-list 'prefixes (string-to-char key))
  2614. (setq line
  2615. (format
  2616. "%-4s%-14s"
  2617. (org-add-props (copy-sequence key)
  2618. '(face bold))
  2619. (cond
  2620. ((string-match "\\S-" desc) desc)
  2621. ((eq type 'agenda) "Agenda for current week or day")
  2622. ((eq type 'agenda*) "Appointments for current week or day")
  2623. ((eq type 'alltodo) "List of all TODO entries")
  2624. ((eq type 'search) "Word search")
  2625. ((eq type 'stuck) "List of stuck projects")
  2626. ((eq type 'todo) "TODO keyword")
  2627. ((eq type 'tags) "Tags query")
  2628. ((eq type 'tags-todo) "Tags (TODO)")
  2629. ((eq type 'tags-tree) "Tags tree")
  2630. ((eq type 'todo-tree) "TODO kwd tree")
  2631. ((eq type 'occur-tree) "Occur tree")
  2632. ((functionp type) (if (symbolp type)
  2633. (symbol-name type)
  2634. "Lambda expression"))
  2635. (t "???"))))
  2636. (if org-agenda-menu-show-matcher
  2637. (setq line
  2638. (concat line ": "
  2639. (cond
  2640. ((stringp match)
  2641. (setq match (copy-sequence match))
  2642. (org-add-props match nil 'face 'org-warning))
  2643. ((listp type)
  2644. (format "set of %d commands" (length type))))))
  2645. (if (org-string-nw-p match)
  2646. (add-text-properties
  2647. 0 (length line) (list 'help-echo
  2648. (concat "Matcher: " match)) line)))
  2649. (push line lines)))
  2650. (setq lines (nreverse lines))
  2651. (when prefixes
  2652. (mapc (lambda (x)
  2653. (push
  2654. (format "%s %s"
  2655. (org-add-props (char-to-string x)
  2656. nil 'face 'bold)
  2657. (or (cdr (assoc (concat selstring
  2658. (char-to-string x))
  2659. prefix-descriptions))
  2660. "Prefix key"))
  2661. lines))
  2662. prefixes))
  2663. ;; Check if we should display in two columns
  2664. (if org-agenda-menu-two-columns
  2665. (progn
  2666. (setq n (length lines)
  2667. n1 (+ (/ n 2) (mod n 2))
  2668. right (nthcdr n1 lines)
  2669. left (copy-sequence lines))
  2670. (setcdr (nthcdr (1- n1) left) nil))
  2671. (setq left lines right nil))
  2672. (while left
  2673. (insert "\n" (pop left))
  2674. (when right
  2675. (if (< (current-column) 40)
  2676. (move-to-column 40 t)
  2677. (insert " "))
  2678. (insert (pop right))))
  2679. ;; Make the window the right size
  2680. (goto-char (point-min))
  2681. (if second-time
  2682. (if (not (pos-visible-in-window-p (point-max)))
  2683. (org-fit-window-to-buffer))
  2684. (setq second-time t)
  2685. (org-fit-window-to-buffer))
  2686. ;; Ask for selection
  2687. (message "Press key for agenda command%s:"
  2688. (if (or restrict-ok org-agenda-overriding-restriction)
  2689. (if org-agenda-overriding-restriction
  2690. " (restriction lock active)"
  2691. (if restriction
  2692. (format " (restricted to %s)" restriction)
  2693. " (unrestricted)"))
  2694. ""))
  2695. (setq c (read-char-exclusive))
  2696. (message "")
  2697. (cond
  2698. ((assoc (char-to-string c) custom)
  2699. (setq selstring (concat selstring (char-to-string c)))
  2700. (throw 'exit (cons selstring restriction)))
  2701. ((memq c prefixes)
  2702. (setq selstring (concat selstring (char-to-string c))
  2703. prefixes nil
  2704. rmheader (or rmheader t)
  2705. custom (delq nil (mapcar
  2706. (lambda (x)
  2707. (if (or (= (length (car x)) 1)
  2708. (/= (string-to-char (car x)) c))
  2709. nil
  2710. (cons (substring (car x) 1) (cdr x))))
  2711. custom))))
  2712. ((eq c ?*)
  2713. (call-interactively 'org-toggle-sticky-agenda)
  2714. (sit-for 2))
  2715. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2716. (message "Restriction is only possible in Org-mode buffers")
  2717. (ding) (sit-for 1))
  2718. ((eq c ?1)
  2719. (org-agenda-remove-restriction-lock 'noupdate)
  2720. (setq restriction 'buffer))
  2721. ((eq c ?0)
  2722. (org-agenda-remove-restriction-lock 'noupdate)
  2723. (setq restriction (if region-p 'region 'subtree)))
  2724. ((eq c ?<)
  2725. (org-agenda-remove-restriction-lock 'noupdate)
  2726. (setq restriction
  2727. (cond
  2728. ((eq restriction 'buffer)
  2729. (if region-p 'region 'subtree))
  2730. ((memq restriction '(subtree region))
  2731. nil)
  2732. (t 'buffer))))
  2733. ((eq c ?>)
  2734. (org-agenda-remove-restriction-lock 'noupdate)
  2735. (setq restriction nil))
  2736. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2737. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2738. ((and (> (length selstring) 0) (eq c ?\d))
  2739. (delete-window)
  2740. (org-agenda-get-restriction-and-command prefix-descriptions))
  2741. ((equal c ?q) (error "Abort"))
  2742. (t (user-error "Invalid key %c" c))))))))
  2743. (defun org-agenda-fit-window-to-buffer ()
  2744. "Fit the window to the buffer size."
  2745. (and (memq org-agenda-window-setup '(reorganize-frame))
  2746. (fboundp 'fit-window-to-buffer)
  2747. (org-fit-window-to-buffer
  2748. nil
  2749. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2750. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2751. (defvar org-cmd nil)
  2752. (defvar org-agenda-overriding-cmd nil)
  2753. (defvar org-agenda-overriding-arguments nil)
  2754. (defvar org-agenda-overriding-cmd-arguments nil)
  2755. (defun org-agenda-run-series (name series)
  2756. "Run agenda NAME as a SERIES of agenda commands."
  2757. (org-let (nth 1 series) '(org-agenda-prepare name))
  2758. ;; We need to reset agenda markers here, because when constructing a
  2759. ;; block agenda, the individual blocks do not do that.
  2760. (org-agenda-reset-markers)
  2761. (let* ((org-agenda-multi t)
  2762. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2763. (cmds (car series))
  2764. (gprops (nth 1 series))
  2765. match ;; The byte compiler incorrectly complains about this. Keep it!
  2766. org-cmd type lprops)
  2767. (while (setq org-cmd (pop cmds))
  2768. (setq type (car org-cmd)
  2769. match (eval (nth 1 org-cmd))
  2770. lprops (nth 2 org-cmd))
  2771. (let ((org-agenda-overriding-arguments
  2772. (if (eq org-agenda-overriding-cmd org-cmd)
  2773. (or org-agenda-overriding-arguments
  2774. org-agenda-overriding-cmd-arguments))))
  2775. (cond
  2776. ((eq type 'agenda)
  2777. (org-let2 gprops lprops
  2778. '(call-interactively 'org-agenda-list)))
  2779. ((eq type 'agenda*)
  2780. (org-let2 gprops lprops
  2781. '(funcall 'org-agenda-list nil nil t)))
  2782. ((eq type 'alltodo)
  2783. (org-let2 gprops lprops
  2784. '(call-interactively 'org-todo-list)))
  2785. ((eq type 'search)
  2786. (org-let2 gprops lprops
  2787. '(org-search-view current-prefix-arg match nil)))
  2788. ((eq type 'stuck)
  2789. (org-let2 gprops lprops
  2790. '(call-interactively 'org-agenda-list-stuck-projects)))
  2791. ((eq type 'tags)
  2792. (org-let2 gprops lprops
  2793. '(org-tags-view current-prefix-arg match)))
  2794. ((eq type 'tags-todo)
  2795. (org-let2 gprops lprops
  2796. '(org-tags-view '(4) match)))
  2797. ((eq type 'todo)
  2798. (org-let2 gprops lprops
  2799. '(org-todo-list match)))
  2800. ((fboundp type)
  2801. (org-let2 gprops lprops
  2802. '(funcall type match)))
  2803. (t (error "Invalid type in command series")))))
  2804. (widen)
  2805. (let ((inhibit-read-only t))
  2806. (add-text-properties (point-min) (point-max)
  2807. `(org-series t org-series-redo-cmd ,redo)))
  2808. (setq org-agenda-redo-command redo)
  2809. (goto-char (point-min)))
  2810. (org-agenda-fit-window-to-buffer)
  2811. (org-let (nth 1 series) '(org-agenda-finalize)))
  2812. ;;;###autoload
  2813. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2814. "Run an agenda command in batch mode and send the result to STDOUT.
  2815. If CMD-KEY is a string of length 1, it is used as a key in
  2816. `org-agenda-custom-commands' and triggers this command. If it is a
  2817. longer string it is used as a tags/todo match string.
  2818. Parameters are alternating variable names and values that will be bound
  2819. before running the agenda command."
  2820. (org-eval-in-environment (org-make-parameter-alist parameters)
  2821. (if (> (length cmd-key) 2)
  2822. (org-tags-view nil cmd-key)
  2823. (org-agenda nil cmd-key)))
  2824. (set-buffer org-agenda-buffer-name)
  2825. (princ (buffer-string)))
  2826. (defvar org-agenda-info nil)
  2827. ;;;###autoload
  2828. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2829. "Run an agenda command in batch mode and send the result to STDOUT.
  2830. If CMD-KEY is a string of length 1, it is used as a key in
  2831. `org-agenda-custom-commands' and triggers this command. If it is a
  2832. longer string it is used as a tags/todo match string.
  2833. Parameters are alternating variable names and values that will be bound
  2834. before running the agenda command.
  2835. The output gives a line for each selected agenda item. Each
  2836. item is a list of comma-separated values, like this:
  2837. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2838. category The category of the item
  2839. head The headline, without TODO kwd, TAGS and PRIORITY
  2840. type The type of the agenda entry, can be
  2841. todo selected in TODO match
  2842. tagsmatch selected in tags match
  2843. diary imported from diary
  2844. deadline a deadline on given date
  2845. scheduled scheduled on given date
  2846. timestamp entry has timestamp on given date
  2847. closed entry was closed on given date
  2848. upcoming-deadline warning about deadline
  2849. past-scheduled forwarded scheduled item
  2850. block entry has date block including g. date
  2851. todo The todo keyword, if any
  2852. tags All tags including inherited ones, separated by colons
  2853. date The relevant date, like 2007-2-14
  2854. time The time, like 15:00-16:50
  2855. extra Sting with extra planning info
  2856. priority-l The priority letter if any was given
  2857. priority-n The computed numerical priority
  2858. agenda-day The day in the agenda where this is listed"
  2859. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2860. (org-make-parameter-alist parameters))
  2861. (if (> (length cmd-key) 2)
  2862. (org-tags-view nil cmd-key)
  2863. (org-agenda nil cmd-key)))
  2864. (set-buffer org-agenda-buffer-name)
  2865. (let* ((lines (org-split-string (buffer-string) "\n"))
  2866. line)
  2867. (while (setq line (pop lines))
  2868. (catch 'next
  2869. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2870. (setq org-agenda-info
  2871. (org-fix-agenda-info (text-properties-at 0 line)))
  2872. (princ
  2873. (mapconcat 'org-agenda-export-csv-mapper
  2874. '(org-category txt type todo tags date time extra
  2875. priority-letter priority agenda-day)
  2876. ","))
  2877. (princ "\n")))))
  2878. (defun org-fix-agenda-info (props)
  2879. "Make sure all properties on an agenda item have a canonical form.
  2880. This ensures the export commands can easily use it."
  2881. (let (tmp re)
  2882. (when (setq tmp (plist-get props 'tags))
  2883. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2884. (when (setq tmp (plist-get props 'date))
  2885. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2886. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2887. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2888. (setq tmp (calendar-date-string tmp)))
  2889. (setq props (plist-put props 'date tmp)))
  2890. (when (setq tmp (plist-get props 'day))
  2891. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2892. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2893. (setq tmp (calendar-date-string tmp)))
  2894. (setq props (plist-put props 'day tmp))
  2895. (setq props (plist-put props 'agenda-day tmp)))
  2896. (when (setq tmp (plist-get props 'txt))
  2897. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2898. (plist-put props 'priority-letter (match-string 1 tmp))
  2899. (setq tmp (replace-match "" t t tmp)))
  2900. (when (and (setq re (plist-get props 'org-todo-regexp))
  2901. (setq re (concat "\\`\\.*" re " ?"))
  2902. (string-match re tmp))
  2903. (plist-put props 'todo (match-string 1 tmp))
  2904. (setq tmp (replace-match "" t t tmp)))
  2905. (plist-put props 'txt tmp)))
  2906. props)
  2907. (defun org-agenda-export-csv-mapper (prop)
  2908. (let ((res (plist-get org-agenda-info prop)))
  2909. (setq res
  2910. (cond
  2911. ((not res) "")
  2912. ((stringp res) res)
  2913. (t (prin1-to-string res))))
  2914. (while (string-match "," res)
  2915. (setq res (replace-match ";" t t res)))
  2916. (org-trim res)))
  2917. ;;;###autoload
  2918. (defun org-store-agenda-views (&rest parameters)
  2919. "Store agenda views."
  2920. (interactive)
  2921. (eval (list 'org-batch-store-agenda-views)))
  2922. ;;;###autoload
  2923. (defmacro org-batch-store-agenda-views (&rest parameters)
  2924. "Run all custom agenda commands that have a file argument."
  2925. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2926. (pop-up-frames nil)
  2927. (dir default-directory)
  2928. (pars (org-make-parameter-alist parameters))
  2929. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2930. (save-window-excursion
  2931. (while cmds
  2932. (setq cmd (pop cmds)
  2933. thiscmdkey (car cmd)
  2934. thiscmdcmd (cdr cmd)
  2935. match (nth 2 thiscmdcmd)
  2936. bufname (if org-agenda-sticky
  2937. (or (and (stringp match)
  2938. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2939. (format "*Org Agenda(%s)*" thiscmdkey))
  2940. org-agenda-buffer-name)
  2941. cmd-or-set (nth 2 cmd)
  2942. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2943. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2944. (if (stringp files) (setq files (list files)))
  2945. (when files
  2946. (org-eval-in-environment (append org-agenda-exporter-settings
  2947. opts pars)
  2948. (org-agenda nil thiscmdkey))
  2949. (set-buffer bufname)
  2950. (while files
  2951. (org-eval-in-environment (append org-agenda-exporter-settings
  2952. opts pars)
  2953. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2954. (and (get-buffer bufname)
  2955. (kill-buffer bufname)))))))
  2956. (defvar org-agenda-current-span nil
  2957. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2958. (defun org-agenda-mark-header-line (pos)
  2959. "Mark the line at POS as an agenda structure header."
  2960. (save-excursion
  2961. (goto-char pos)
  2962. (put-text-property (point-at-bol) (point-at-eol)
  2963. 'org-agenda-structural-header t)
  2964. (when org-agenda-title-append
  2965. (put-text-property (point-at-bol) (point-at-eol)
  2966. 'org-agenda-title-append org-agenda-title-append))))
  2967. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2968. (defvar org-agenda-write-buffer-name "Agenda View")
  2969. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2970. "Write the current buffer (an agenda view) as a file.
  2971. Depending on the extension of the file name, plain text (.txt),
  2972. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2973. If the extension is .ics, run icalendar export over all files used
  2974. to construct the agenda and limit the export to entries listed in the
  2975. agenda now.
  2976. If the extension is .org, collect all subtrees corresponding to the
  2977. agenda entries and add them in an .org file.
  2978. With prefix argument OPEN, open the new file immediately.
  2979. If NOSETTINGS is given, do not scope the settings of
  2980. `org-agenda-exporter-settings' into the export commands. This is used when
  2981. the settings have already been scoped and we do not wish to overrule other,
  2982. higher priority settings.
  2983. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2984. (interactive "FWrite agenda to file: \nP")
  2985. (if (or (not (file-writable-p file))
  2986. (and (file-exists-p file)
  2987. (if (called-interactively-p 'any)
  2988. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  2989. (user-error "Cannot write agenda to file %s" file))
  2990. (org-let (if nosettings nil org-agenda-exporter-settings)
  2991. '(save-excursion
  2992. (save-window-excursion
  2993. (org-agenda-mark-filtered-text)
  2994. (let ((bs (copy-sequence (buffer-string))) beg content)
  2995. (org-agenda-unmark-filtered-text)
  2996. (with-temp-buffer
  2997. (rename-buffer org-agenda-write-buffer-name t)
  2998. (set-buffer-modified-p nil)
  2999. (insert bs)
  3000. (org-agenda-remove-marked-text 'org-filtered)
  3001. (while (setq beg (text-property-any (point-min) (point-max)
  3002. 'org-filtered t))
  3003. (delete-region
  3004. beg (or (next-single-property-change beg 'org-filtered)
  3005. (point-max))))
  3006. (run-hooks 'org-agenda-before-write-hook)
  3007. (cond
  3008. ((org-bound-and-true-p org-mobile-creating-agendas)
  3009. (org-mobile-write-agenda-for-mobile file))
  3010. ((string-match "\\.org\\'" file)
  3011. (let (content p m message-log-max)
  3012. (goto-char (point-min))
  3013. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3014. (goto-char p)
  3015. (setq m (get-text-property (point) 'org-hd-marker))
  3016. (when m
  3017. (push (save-excursion
  3018. (set-buffer (marker-buffer m))
  3019. (goto-char m)
  3020. (org-copy-subtree 1 nil t t)
  3021. org-subtree-clip)
  3022. content)))
  3023. (find-file file)
  3024. (erase-buffer)
  3025. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3026. (write-file file)
  3027. (kill-buffer (current-buffer))
  3028. (message "Org file written to %s" file)))
  3029. ((string-match "\\.html?\\'" file)
  3030. (require 'htmlize)
  3031. (set-buffer (htmlize-buffer (current-buffer)))
  3032. (when org-agenda-export-html-style
  3033. ;; replace <style> section with org-agenda-export-html-style
  3034. (goto-char (point-min))
  3035. (kill-region (- (search-forward "<style") 6)
  3036. (search-forward "</style>"))
  3037. (insert org-agenda-export-html-style))
  3038. (write-file file)
  3039. (kill-buffer (current-buffer))
  3040. (message "HTML written to %s" file))
  3041. ((string-match "\\.ps\\'" file)
  3042. (require 'ps-print)
  3043. (ps-print-buffer-with-faces file)
  3044. (message "Postscript written to %s" file))
  3045. ((string-match "\\.pdf\\'" file)
  3046. (require 'ps-print)
  3047. (ps-print-buffer-with-faces
  3048. (concat (file-name-sans-extension file) ".ps"))
  3049. (call-process "ps2pdf" nil nil nil
  3050. (expand-file-name
  3051. (concat (file-name-sans-extension file) ".ps"))
  3052. (expand-file-name file))
  3053. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3054. (message "PDF written to %s" file))
  3055. ((string-match "\\.ics\\'" file)
  3056. (require 'ox-icalendar)
  3057. (org-icalendar-export-current-agenda (expand-file-name file)))
  3058. (t
  3059. (let ((bs (buffer-string)))
  3060. (find-file file)
  3061. (erase-buffer)
  3062. (insert bs)
  3063. (save-buffer 0)
  3064. (kill-buffer (current-buffer))
  3065. (message "Plain text written to %s" file))))))))
  3066. (set-buffer (or agenda-bufname
  3067. (and (org-called-interactively-p 'any) (buffer-name))
  3068. org-agenda-buffer-name)))
  3069. (when open (org-open-file file)))
  3070. (defvar org-agenda-tag-filter-overlays nil)
  3071. (defvar org-agenda-cat-filter-overlays nil)
  3072. (defvar org-agenda-re-filter-overlays nil)
  3073. (defun org-agenda-mark-filtered-text ()
  3074. "Mark all text hidden by filtering with a text property."
  3075. (let ((inhibit-read-only t))
  3076. (mapc
  3077. (lambda (o)
  3078. (when (equal (overlay-buffer o) (current-buffer))
  3079. (put-text-property
  3080. (overlay-start o) (overlay-end o)
  3081. 'org-filtered t)))
  3082. (append org-agenda-tag-filter-overlays
  3083. org-agenda-cat-filter-overlays
  3084. org-agenda-re-filter-overlays))))
  3085. (defun org-agenda-unmark-filtered-text ()
  3086. "Remove the filtering text property."
  3087. (let ((inhibit-read-only t))
  3088. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  3089. (defun org-agenda-remove-marked-text (property &optional value)
  3090. "Delete all text marked with VALUE of PROPERTY.
  3091. VALUE defaults to t."
  3092. (let (beg)
  3093. (setq value (or value t))
  3094. (while (setq beg (text-property-any (point-min) (point-max)
  3095. property value))
  3096. (delete-region
  3097. beg (or (next-single-property-change beg 'org-filtered)
  3098. (point-max))))))
  3099. (defun org-agenda-add-entry-text ()
  3100. "Add entry text to agenda lines.
  3101. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3102. entry text following headings shown in the agenda.
  3103. Drawers will be excluded, also the line with scheduling/deadline info."
  3104. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3105. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3106. (let (m txt)
  3107. (goto-char (point-min))
  3108. (while (not (eobp))
  3109. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3110. (beginning-of-line 2)
  3111. (setq txt (org-agenda-get-some-entry-text
  3112. m org-agenda-add-entry-text-maxlines " > "))
  3113. (end-of-line 1)
  3114. (if (string-match "\\S-" txt)
  3115. (insert "\n" txt)
  3116. (or (eobp) (forward-char 1))))))))
  3117. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3118. &rest keep)
  3119. "Extract entry text from MARKER, at most N-LINES lines.
  3120. This will ignore drawers etc, just get the text.
  3121. If INDENT is given, prefix every line with this string. If KEEP is
  3122. given, it is a list of symbols, defining stuff that should not be
  3123. removed from the entry content. Currently only `planning' is allowed here."
  3124. (let (txt drawer-re kwd-time-re ind)
  3125. (save-excursion
  3126. (with-current-buffer (marker-buffer marker)
  3127. (if (not (derived-mode-p 'org-mode))
  3128. (setq txt "")
  3129. (save-excursion
  3130. (save-restriction
  3131. (widen)
  3132. (goto-char marker)
  3133. (end-of-line 1)
  3134. (setq txt (buffer-substring
  3135. (min (1+ (point)) (point-max))
  3136. (progn (outline-next-heading) (point)))
  3137. drawer-re org-drawer-regexp
  3138. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3139. ".*\n?"))
  3140. (with-temp-buffer
  3141. (insert txt)
  3142. (when org-agenda-add-entry-text-descriptive-links
  3143. (goto-char (point-min))
  3144. (while (org-activate-bracket-links (point-max))
  3145. (add-text-properties (match-beginning 0) (match-end 0)
  3146. '(face org-link))))
  3147. (goto-char (point-min))
  3148. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3149. (set-text-properties (match-beginning 0) (match-end 0)
  3150. nil))
  3151. (goto-char (point-min))
  3152. (while (re-search-forward drawer-re nil t)
  3153. (delete-region
  3154. (match-beginning 0)
  3155. (progn (re-search-forward
  3156. "^[ \t]*:END:.*\n?" nil 'move)
  3157. (point))))
  3158. (unless (member 'planning keep)
  3159. (goto-char (point-min))
  3160. (while (re-search-forward kwd-time-re nil t)
  3161. (replace-match "")))
  3162. (goto-char (point-min))
  3163. (when org-agenda-entry-text-exclude-regexps
  3164. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3165. (while (setq re (pop re-list))
  3166. (goto-char (point-min))
  3167. (while (re-search-forward re nil t)
  3168. (replace-match "")))))
  3169. (goto-char (point-max))
  3170. (skip-chars-backward " \t\n")
  3171. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3172. ;; find and remove min common indentation
  3173. (goto-char (point-min))
  3174. (untabify (point-min) (point-max))
  3175. (setq ind (org-get-indentation))
  3176. (while (not (eobp))
  3177. (unless (looking-at "[ \t]*$")
  3178. (setq ind (min ind (org-get-indentation))))
  3179. (beginning-of-line 2))
  3180. (goto-char (point-min))
  3181. (while (not (eobp))
  3182. (unless (looking-at "[ \t]*$")
  3183. (move-to-column ind)
  3184. (delete-region (point-at-bol) (point)))
  3185. (beginning-of-line 2))
  3186. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3187. (goto-char (point-min))
  3188. (when indent
  3189. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3190. (replace-match indent t t)))
  3191. (goto-char (point-min))
  3192. (while (looking-at "[ \t]*\n") (replace-match ""))
  3193. (goto-char (point-max))
  3194. (when (> (org-current-line)
  3195. n-lines)
  3196. (org-goto-line (1+ n-lines))
  3197. (backward-char 1))
  3198. (setq txt (buffer-substring (point-min) (point)))))))))
  3199. txt))
  3200. (defun org-check-for-org-mode ()
  3201. "Make sure current buffer is in org-mode. Error if not."
  3202. (or (derived-mode-p 'org-mode)
  3203. (error "Cannot execute org-mode agenda command on buffer in %s"
  3204. major-mode)))
  3205. ;;; Agenda prepare and finalize
  3206. (defvar org-agenda-multi nil) ; dynamically scoped
  3207. (defvar org-agenda-pre-window-conf nil)
  3208. (defvar org-agenda-columns-active nil)
  3209. (defvar org-agenda-name nil)
  3210. (defvar org-agenda-tag-filter nil)
  3211. (defvar org-agenda-category-filter nil)
  3212. (defvar org-agenda-regexp-filter nil)
  3213. (defvar org-agenda-top-headline-filter nil)
  3214. (defvar org-agenda-tag-filter-while-redo nil)
  3215. (defvar org-agenda-tag-filter-preset nil
  3216. "A preset of the tags filter used for secondary agenda filtering.
  3217. This must be a list of strings, each string must be a single tag preceded
  3218. by \"+\" or \"-\".
  3219. This variable should not be set directly, but agenda custom commands can
  3220. bind it in the options section. The preset filter is a global property of
  3221. the entire agenda view. In a block agenda, it will not work reliably to
  3222. define a filter for one of the individual blocks. You need to set it in
  3223. the global options and expect it to be applied to the entire view.")
  3224. (defvar org-agenda-category-filter-preset nil
  3225. "A preset of the category filter used for secondary agenda filtering.
  3226. This must be a list of strings, each string must be a single category
  3227. preceded by \"+\" or \"-\".
  3228. This variable should not be set directly, but agenda custom commands can
  3229. bind it in the options section. The preset filter is a global property of
  3230. the entire agenda view. In a block agenda, it will not work reliably to
  3231. define a filter for one of the individual blocks. You need to set it in
  3232. the global options and expect it to be applied to the entire view.")
  3233. (defvar org-agenda-regexp-filter-preset nil
  3234. "A preset of the regexp filter used for secondary agenda filtering.
  3235. This must be a list of strings, each string must be a single category
  3236. preceded by \"+\" or \"-\".
  3237. This variable should not be set directly, but agenda custom commands can
  3238. bind it in the options section. The preset filter is a global property of
  3239. the entire agenda view. In a block agenda, it will not work reliably to
  3240. define a filter for one of the individual blocks. You need to set it in
  3241. the global options and expect it to be applied to the entire view.")
  3242. (defun org-agenda-use-sticky-p ()
  3243. "Return non-nil if an agenda buffer named
  3244. `org-agenda-buffer-name' exists and should be shown instead of
  3245. generating a new one."
  3246. (and
  3247. ;; turned off by user
  3248. org-agenda-sticky
  3249. ;; For multi-agenda buffer already exists
  3250. (not org-agenda-multi)
  3251. ;; buffer found
  3252. (get-buffer org-agenda-buffer-name)
  3253. ;; C-u parameter is same as last call
  3254. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3255. (and
  3256. (equal current-prefix-arg
  3257. org-agenda-last-prefix-arg)
  3258. ;; In case user turned stickiness on, while having existing
  3259. ;; Agenda buffer active, don't reuse that buffer, because it
  3260. ;; does not have org variables local
  3261. org-agenda-this-buffer-is-sticky))))
  3262. (defun org-agenda-prepare-window (abuf)
  3263. "Setup agenda buffer in the window."
  3264. (let* ((awin (get-buffer-window abuf))
  3265. wconf)
  3266. (cond
  3267. ((equal (current-buffer) abuf) nil)
  3268. (awin (select-window awin))
  3269. ((not (setq wconf (current-window-configuration))))
  3270. ((equal org-agenda-window-setup 'current-window)
  3271. (org-pop-to-buffer-same-window abuf))
  3272. ((equal org-agenda-window-setup 'other-window)
  3273. (org-switch-to-buffer-other-window abuf))
  3274. ((equal org-agenda-window-setup 'other-frame)
  3275. (switch-to-buffer-other-frame abuf))
  3276. ((equal org-agenda-window-setup 'reorganize-frame)
  3277. (delete-other-windows)
  3278. (org-switch-to-buffer-other-window abuf)))
  3279. ;; additional test in case agenda is invoked from within agenda
  3280. ;; buffer via elisp link
  3281. (unless (equal (current-buffer) abuf)
  3282. (org-pop-to-buffer-same-window abuf))
  3283. (setq org-agenda-pre-window-conf
  3284. (or org-agenda-pre-window-conf wconf))))
  3285. (defun org-agenda-prepare (&optional name)
  3286. (if (org-agenda-use-sticky-p)
  3287. (progn
  3288. ;; Popup existing buffer
  3289. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3290. (message "Sticky Agenda buffer, use `r' to refresh")
  3291. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3292. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3293. (setq org-todo-keywords-for-agenda nil)
  3294. (setq org-drawers-for-agenda nil)
  3295. (unless org-agenda-persistent-filter
  3296. (setq org-agenda-tag-filter nil
  3297. org-agenda-category-filter nil
  3298. org-agenda-regexp-filter nil))
  3299. (put 'org-agenda-tag-filter :preset-filter
  3300. org-agenda-tag-filter-preset)
  3301. (put 'org-agenda-category-filter :preset-filter
  3302. org-agenda-category-filter-preset)
  3303. (put 'org-agenda-regexp-filter :preset-filter
  3304. org-agenda-regexp-filter-preset)
  3305. (if org-agenda-multi
  3306. (progn
  3307. (setq buffer-read-only nil)
  3308. (goto-char (point-max))
  3309. (unless (or (bobp) org-agenda-compact-blocks
  3310. (not org-agenda-block-separator))
  3311. (insert "\n"
  3312. (if (stringp org-agenda-block-separator)
  3313. org-agenda-block-separator
  3314. (make-string (window-width) org-agenda-block-separator))
  3315. "\n"))
  3316. (narrow-to-region (point) (point-max)))
  3317. (setq org-done-keywords-for-agenda nil)
  3318. ;; Setting any org variables that are in org-agenda-local-vars
  3319. ;; list need to be done after the prepare call
  3320. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3321. (setq buffer-read-only nil)
  3322. (org-agenda-reset-markers)
  3323. (let ((inhibit-read-only t)) (erase-buffer))
  3324. (org-agenda-mode)
  3325. (setq org-agenda-buffer (current-buffer))
  3326. (setq org-agenda-contributing-files nil)
  3327. (setq org-agenda-columns-active nil)
  3328. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3329. (setq org-todo-keywords-for-agenda
  3330. (org-uniquify org-todo-keywords-for-agenda))
  3331. (setq org-done-keywords-for-agenda
  3332. (org-uniquify org-done-keywords-for-agenda))
  3333. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3334. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3335. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3336. (and name (not org-agenda-name)
  3337. (org-set-local 'org-agenda-name name)))
  3338. (setq buffer-read-only nil)))
  3339. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3340. (defun org-agenda-finalize ()
  3341. "Finishing touch for the agenda buffer, called just before displaying it."
  3342. (unless org-agenda-multi
  3343. (save-excursion
  3344. (let ((inhibit-read-only t))
  3345. (goto-char (point-min))
  3346. (save-excursion
  3347. (while (org-activate-bracket-links (point-max))
  3348. (add-text-properties (match-beginning 0) (match-end 0)
  3349. '(face org-link))))
  3350. (save-excursion
  3351. (while (org-activate-plain-links (point-max))
  3352. (add-text-properties (match-beginning 0) (match-end 0)
  3353. '(face org-link))))
  3354. (unless (eq org-agenda-remove-tags t)
  3355. (org-agenda-align-tags))
  3356. (unless org-agenda-with-colors
  3357. (remove-text-properties (point-min) (point-max) '(face nil)))
  3358. (if (and (boundp 'org-agenda-overriding-columns-format)
  3359. org-agenda-overriding-columns-format)
  3360. (org-set-local 'org-agenda-overriding-columns-format
  3361. org-agenda-overriding-columns-format))
  3362. (if (and (boundp 'org-agenda-view-columns-initially)
  3363. org-agenda-view-columns-initially)
  3364. (org-agenda-columns))
  3365. (when org-agenda-fontify-priorities
  3366. (org-agenda-fontify-priorities))
  3367. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3368. (org-agenda-dim-blocked-tasks))
  3369. ;; We need to widen when `org-agenda-finalize' is called from
  3370. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3371. (when org-clock-current-task
  3372. (save-restriction
  3373. (widen)
  3374. (org-agenda-mark-clocking-task)))
  3375. (when org-agenda-entry-text-mode
  3376. (org-agenda-entry-text-hide)
  3377. (org-agenda-entry-text-show))
  3378. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3379. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3380. (org-habit-insert-consistency-graphs))
  3381. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3382. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3383. (and (listp org-agenda-show-inherited-tags)
  3384. (memq org-agenda-type org-agenda-show-inherited-tags))
  3385. (and (eq org-agenda-show-inherited-tags t)
  3386. (or (eq org-agenda-use-tag-inheritance t)
  3387. (and (listp org-agenda-use-tag-inheritance)
  3388. (not (memq org-agenda-type
  3389. org-agenda-use-tag-inheritance))))))
  3390. (let (mrk)
  3391. (save-excursion
  3392. (goto-char (point-min))
  3393. (while (equal (forward-line) 0)
  3394. (when (setq mrk (or (get-text-property (point) 'org-hd-marker)
  3395. (get-text-property (point) 'org-hd-marker)))
  3396. (put-text-property (point-at-bol) (point-at-eol)
  3397. 'tags (org-with-point-at mrk
  3398. (delete-dups
  3399. (mapcar 'downcase (org-get-tags-at))))))))))
  3400. (run-hooks 'org-agenda-finalize-hook)
  3401. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3402. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3403. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3404. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3405. (when (or org-agenda-regexp-filter (get 'org-agenda-regexp-filter :preset-filter))
  3406. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3407. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3408. (defun org-agenda-mark-clocking-task ()
  3409. "Mark the current clock entry in the agenda if it is present."
  3410. (org-agenda-unmark-clocking-task)
  3411. (when (marker-buffer org-clock-hd-marker)
  3412. (save-excursion
  3413. (goto-char (point-min))
  3414. (let (s ov)
  3415. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3416. (goto-char s)
  3417. (when (equal (org-get-at-bol 'org-hd-marker)
  3418. org-clock-hd-marker)
  3419. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3420. (overlay-put ov 'type 'org-agenda-clocking)
  3421. (overlay-put ov 'face 'org-agenda-clocking)
  3422. (overlay-put ov 'help-echo
  3423. "The clock is running in this item")))))))
  3424. (defun org-agenda-unmark-clocking-task ()
  3425. "Unmark the current clocking task."
  3426. (mapc (lambda (o)
  3427. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3428. (delete-overlay o)))
  3429. (overlays-in (point-min) (point-max))))
  3430. (defun org-agenda-fontify-priorities ()
  3431. "Make highest priority lines bold, and lowest italic."
  3432. (interactive)
  3433. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3434. (delete-overlay o)))
  3435. (overlays-in (point-min) (point-max)))
  3436. (save-excursion
  3437. (let (b e p ov h l)
  3438. (goto-char (point-min))
  3439. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3440. (setq h (or (get-char-property (point) 'org-highest-priority)
  3441. org-highest-priority)
  3442. l (or (get-char-property (point) 'org-lowest-priority)
  3443. org-lowest-priority)
  3444. p (string-to-char (match-string 1))
  3445. b (match-beginning 0)
  3446. e (if (eq org-agenda-fontify-priorities 'cookies)
  3447. (match-end 0)
  3448. (point-at-eol))
  3449. ov (make-overlay b e))
  3450. (overlay-put
  3451. ov 'face
  3452. (cons (cond ((org-face-from-face-or-color
  3453. 'priority nil
  3454. (cdr (assoc p org-priority-faces))))
  3455. ((and (listp org-agenda-fontify-priorities)
  3456. (org-face-from-face-or-color
  3457. 'priority nil
  3458. (cdr (assoc p org-agenda-fontify-priorities)))))
  3459. ((equal p l) 'italic)
  3460. ((equal p h) 'bold))
  3461. 'org-priority))
  3462. (overlay-put ov 'org-type 'org-priority)))))
  3463. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3464. "Dim currently blocked TODO's in the agenda display.
  3465. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3466. dimming them."
  3467. (interactive "P")
  3468. (when (org-called-interactively-p 'interactive)
  3469. (message "Dim or hide blocked tasks..."))
  3470. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3471. (delete-overlay o)))
  3472. (overlays-in (point-min) (point-max)))
  3473. (save-excursion
  3474. (let ((inhibit-read-only t)
  3475. (org-depend-tag-blocked nil)
  3476. (invis (or (not (null invisible))
  3477. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3478. org-blocked-by-checkboxes
  3479. invis1 b e p ov h l)
  3480. (goto-char (point-min))
  3481. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3482. (and pos (goto-char (1+ pos))))
  3483. (setq org-blocked-by-checkboxes nil invis1 invis)
  3484. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3485. (when (and marker
  3486. (with-current-buffer (marker-buffer marker)
  3487. (save-excursion (goto-char marker)
  3488. (org-entry-blocked-p))))
  3489. (if org-blocked-by-checkboxes (setq invis1 nil))
  3490. (setq b (if invis1
  3491. (max (point-min) (1- (point-at-bol)))
  3492. (point-at-bol))
  3493. e (point-at-eol)
  3494. ov (make-overlay b e))
  3495. (if invis1
  3496. (overlay-put ov 'invisible t)
  3497. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3498. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3499. (when (org-called-interactively-p 'interactive)
  3500. (message "Dim or hide blocked tasks...done")))
  3501. (defvar org-agenda-skip-function nil
  3502. "Function to be called at each match during agenda construction.
  3503. If this function returns nil, the current match should not be skipped.
  3504. Otherwise, the function must return a position from where the search
  3505. should be continued.
  3506. This may also be a Lisp form, it will be evaluated.
  3507. Never set this variable using `setq' or so, because then it will apply
  3508. to all future agenda commands. If you do want a global skipping condition,
  3509. use the option `org-agenda-skip-function-global' instead.
  3510. The correct usage for `org-agenda-skip-function' is to bind it with
  3511. `let' to scope it dynamically into the agenda-constructing command.
  3512. A good way to set it is through options in `org-agenda-custom-commands'.")
  3513. (defun org-agenda-skip ()
  3514. "Throw to `:skip' in places that should be skipped.
  3515. Also moves point to the end of the skipped region, so that search can
  3516. continue from there."
  3517. (let ((p (point-at-bol)) to)
  3518. (when (or
  3519. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3520. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3521. (get-text-property p :org-archived)
  3522. (org-end-of-subtree t))
  3523. (and org-agenda-skip-comment-trees
  3524. (get-text-property p :org-comment)
  3525. (org-end-of-subtree t))
  3526. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3527. (org-agenda-skip-eval org-agenda-skip-function)))
  3528. (goto-char to))
  3529. (org-in-src-block-p t))
  3530. (throw :skip t))))
  3531. (defun org-agenda-skip-eval (form)
  3532. "If FORM is a function or a list, call (or eval) is and return result.
  3533. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3534. and match data are returned to the previous state no matter what these
  3535. functions do."
  3536. (let (fp)
  3537. (and form
  3538. (or (setq fp (functionp form))
  3539. (consp form))
  3540. (save-excursion
  3541. (save-match-data
  3542. (if fp
  3543. (funcall form)
  3544. (eval form)))))))
  3545. (defvar org-agenda-markers nil
  3546. "List of all currently active markers created by `org-agenda'.")
  3547. (defvar org-agenda-last-marker-time (org-float-time)
  3548. "Creation time of the last agenda marker.")
  3549. (defun org-agenda-new-marker (&optional pos)
  3550. "Return a new agenda marker.
  3551. Org-mode keeps a list of these markers and resets them when they are
  3552. no longer in use."
  3553. (let ((m (copy-marker (or pos (point)))))
  3554. (setq org-agenda-last-marker-time (org-float-time))
  3555. (if org-agenda-buffer
  3556. (with-current-buffer org-agenda-buffer
  3557. (push m org-agenda-markers))
  3558. (push m org-agenda-markers))
  3559. m))
  3560. (defun org-agenda-reset-markers ()
  3561. "Reset markers created by `org-agenda'."
  3562. (while org-agenda-markers
  3563. (move-marker (pop org-agenda-markers) nil)))
  3564. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3565. "Save relative positions of markers in region.
  3566. This check for agenda markers in all agenda buffers currently active."
  3567. (dolist (buf (buffer-list))
  3568. (with-current-buffer buf
  3569. (when (eq major-mode 'org-agenda-mode)
  3570. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3571. org-agenda-markers)))))
  3572. ;;; Entry text mode
  3573. (defun org-agenda-entry-text-show-here ()
  3574. "Add some text from the entry as context to the current line."
  3575. (let (m txt o)
  3576. (setq m (org-get-at-bol 'org-hd-marker))
  3577. (unless (marker-buffer m)
  3578. (error "No marker points to an entry here"))
  3579. (setq txt (concat "\n" (org-no-properties
  3580. (org-agenda-get-some-entry-text
  3581. m org-agenda-entry-text-maxlines
  3582. org-agenda-entry-text-leaders))))
  3583. (when (string-match "\\S-" txt)
  3584. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3585. (overlay-put o 'evaporate t)
  3586. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3587. (overlay-put o 'after-string txt))))
  3588. (defun org-agenda-entry-text-show ()
  3589. "Add entry context for all agenda lines."
  3590. (interactive)
  3591. (save-excursion
  3592. (goto-char (point-max))
  3593. (beginning-of-line 1)
  3594. (while (not (bobp))
  3595. (when (org-get-at-bol 'org-hd-marker)
  3596. (org-agenda-entry-text-show-here))
  3597. (beginning-of-line 0))))
  3598. (defun org-agenda-entry-text-hide ()
  3599. "Remove any shown entry context."
  3600. (delq nil
  3601. (mapcar (lambda (o)
  3602. (if (eq (overlay-get o 'org-overlay-type)
  3603. 'agenda-entry-content)
  3604. (progn (delete-overlay o) t)))
  3605. (overlays-in (point-min) (point-max)))))
  3606. (defun org-agenda-get-day-face (date)
  3607. "Return the face DATE should be displayed with."
  3608. (or (and (functionp org-agenda-day-face-function)
  3609. (funcall org-agenda-day-face-function date))
  3610. (cond ((org-agenda-todayp date)
  3611. 'org-agenda-date-today)
  3612. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3613. 'org-agenda-date-weekend)
  3614. (t 'org-agenda-date))))
  3615. ;;; Agenda timeline
  3616. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3617. (defun org-timeline (&optional dotodo)
  3618. "Show a time-sorted view of the entries in the current org file.
  3619. Only entries with a time stamp of today or later will be listed. With
  3620. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3621. under the current date.
  3622. If the buffer contains an active region, only check the region for
  3623. dates."
  3624. (interactive "P")
  3625. (let* ((dopast t)
  3626. (org-agenda-show-log-scoped org-agenda-show-log)
  3627. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3628. (current-buffer))))
  3629. (date (calendar-current-date))
  3630. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3631. (end (if (org-region-active-p) (region-end) (point-max)))
  3632. (day-numbers (org-get-all-dates
  3633. beg end 'no-ranges
  3634. t org-agenda-show-log-scoped ; always include today
  3635. org-timeline-show-empty-dates))
  3636. (org-deadline-warning-days 0)
  3637. (org-agenda-only-exact-dates t)
  3638. (today (org-today))
  3639. (past t)
  3640. args
  3641. s e rtn d emptyp)
  3642. (setq org-agenda-redo-command
  3643. (list 'progn
  3644. (list 'org-switch-to-buffer-other-window (current-buffer))
  3645. (list 'org-timeline (list 'quote dotodo))))
  3646. (if (not dopast)
  3647. ;; Remove past dates from the list of dates.
  3648. (setq day-numbers (delq nil (mapcar (lambda(x)
  3649. (if (>= x today) x nil))
  3650. day-numbers))))
  3651. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3652. (org-compile-prefix-format 'timeline)
  3653. (org-set-sorting-strategy 'timeline)
  3654. (if org-agenda-show-log-scoped (push :closed args))
  3655. (push :timestamp args)
  3656. (push :deadline args)
  3657. (push :scheduled args)
  3658. (push :sexp args)
  3659. (if dotodo (push :todo args))
  3660. (insert "Timeline of file " entry "\n")
  3661. (add-text-properties (point-min) (point)
  3662. (list 'face 'org-agenda-structure))
  3663. (org-agenda-mark-header-line (point-min))
  3664. (while (setq d (pop day-numbers))
  3665. (if (and (listp d) (eq (car d) :omitted))
  3666. (progn
  3667. (setq s (point))
  3668. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3669. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3670. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3671. (if (and (>= d today)
  3672. dopast
  3673. past)
  3674. (progn
  3675. (setq past nil)
  3676. (insert (make-string 79 ?-) "\n")))
  3677. (setq date (calendar-gregorian-from-absolute d))
  3678. (setq s (point))
  3679. (setq rtn (and (not emptyp)
  3680. (apply 'org-agenda-get-day-entries entry
  3681. date args)))
  3682. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3683. (progn
  3684. (insert
  3685. (if (stringp org-agenda-format-date)
  3686. (format-time-string org-agenda-format-date
  3687. (org-time-from-absolute date))
  3688. (funcall org-agenda-format-date date))
  3689. "\n")
  3690. (put-text-property s (1- (point)) 'face
  3691. (org-agenda-get-day-face date))
  3692. (put-text-property s (1- (point)) 'org-date-line t)
  3693. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3694. (if (equal d today)
  3695. (put-text-property s (1- (point)) 'org-today t))
  3696. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3697. (put-text-property s (1- (point)) 'day d)))))
  3698. (goto-char (point-min))
  3699. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3700. (point-min)))
  3701. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3702. (org-agenda-finalize)
  3703. (setq buffer-read-only t)))
  3704. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3705. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3706. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3707. not every single day in the range. If FORCE-TODAY is non-nil, make
  3708. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3709. inactive time stamps (those in square brackets) are included.
  3710. When EMPTY is non-nil, also include days without any entries."
  3711. (let ((re (concat
  3712. (if pre-re pre-re "")
  3713. (if inactive org-ts-regexp-both org-ts-regexp)))
  3714. dates dates1 date day day1 day2 ts1 ts2 pos)
  3715. (if force-today
  3716. (setq dates (list (org-today))))
  3717. (save-excursion
  3718. (goto-char beg)
  3719. (while (re-search-forward re end t)
  3720. (setq day (time-to-days (org-time-string-to-time
  3721. (substring (match-string 1) 0 10)
  3722. (current-buffer) (match-beginning 0))))
  3723. (or (memq day dates) (push day dates)))
  3724. (unless no-ranges
  3725. (goto-char beg)
  3726. (while (re-search-forward org-tr-regexp end t)
  3727. (setq pos (match-beginning 0))
  3728. (setq ts1 (substring (match-string 1) 0 10)
  3729. ts2 (substring (match-string 2) 0 10)
  3730. day1 (time-to-days (org-time-string-to-time
  3731. ts1 (current-buffer) pos))
  3732. day2 (time-to-days (org-time-string-to-time
  3733. ts2 (current-buffer) pos)))
  3734. (while (< (setq day1 (1+ day1)) day2)
  3735. (or (memq day1 dates) (push day1 dates)))))
  3736. (setq dates (sort dates '<))
  3737. (when empty
  3738. (while (setq day (pop dates))
  3739. (setq day2 (car dates))
  3740. (push day dates1)
  3741. (when (and day2 empty)
  3742. (if (or (eq empty t)
  3743. (and (numberp empty) (<= (- day2 day) empty)))
  3744. (while (< (setq day (1+ day)) day2)
  3745. (push (list day) dates1))
  3746. (push (cons :omitted (- day2 day)) dates1))))
  3747. (setq dates (nreverse dates1)))
  3748. dates)))
  3749. ;;; Agenda Daily/Weekly
  3750. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3751. "Start day for the agenda view.
  3752. Custom commands can set this variable in the options section.
  3753. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3754. input allowed when reading a date through the Org calendar.
  3755. See the docstring of `org-read-date' for details.")
  3756. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3757. (defvar org-arg-loc nil) ; local variable
  3758. (defvar org-agenda-buffer-tmp-name nil)
  3759. ;;;###autoload
  3760. (defun org-agenda-list (&optional arg start-day span with-hour)
  3761. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3762. The view will be for the current day or week, but from the overview buffer
  3763. you will be able to go to other days/weeks.
  3764. With a numeric prefix argument in an interactive call, the agenda will
  3765. span ARG days. Lisp programs should instead specify SPAN to change
  3766. the number of days. SPAN defaults to `org-agenda-span'.
  3767. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3768. given in `org-agenda-start-on-weekday'.
  3769. When WITH-HOUR is non-nil, only include scheduled and deadline
  3770. items if they have an hour specification like [h]h:mm."
  3771. (interactive "P")
  3772. (if org-agenda-overriding-arguments
  3773. (setq arg (car org-agenda-overriding-arguments)
  3774. start-day (nth 1 org-agenda-overriding-arguments)
  3775. span (nth 2 org-agenda-overriding-arguments)))
  3776. (if (and (integerp arg) (> arg 0))
  3777. (setq span arg arg nil))
  3778. (catch 'exit
  3779. (setq org-agenda-buffer-name
  3780. (or org-agenda-buffer-tmp-name
  3781. (if org-agenda-sticky
  3782. (cond ((and org-keys (stringp org-match))
  3783. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3784. (org-keys
  3785. (format "*Org Agenda(%s)*" org-keys))
  3786. (t "*Org Agenda(a)*")))
  3787. org-agenda-buffer-name))
  3788. (org-agenda-prepare "Day/Week")
  3789. (setq start-day (or start-day org-agenda-start-day))
  3790. (if (stringp start-day)
  3791. ;; Convert to an absolute day number
  3792. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3793. (org-compile-prefix-format 'agenda)
  3794. (org-set-sorting-strategy 'agenda)
  3795. (let* ((span (org-agenda-ndays-to-span
  3796. (or span org-agenda-ndays org-agenda-span)))
  3797. (today (org-today))
  3798. (sd (or start-day today))
  3799. (ndays (org-agenda-span-to-ndays span sd))
  3800. (org-agenda-start-on-weekday
  3801. (if (eq ndays 7)
  3802. org-agenda-start-on-weekday))
  3803. (thefiles (org-agenda-files nil 'ifmode))
  3804. (files thefiles)
  3805. (start (if (or (null org-agenda-start-on-weekday)
  3806. (< ndays 7))
  3807. sd
  3808. (let* ((nt (calendar-day-of-week
  3809. (calendar-gregorian-from-absolute sd)))
  3810. (n1 org-agenda-start-on-weekday)
  3811. (d (- nt n1)))
  3812. (- sd (+ (if (< d 0) 7 0) d)))))
  3813. (day-numbers (list start))
  3814. (day-cnt 0)
  3815. (inhibit-redisplay (not debug-on-error))
  3816. (org-agenda-show-log-scoped org-agenda-show-log)
  3817. s e rtn rtnall file date d start-pos end-pos todayp
  3818. clocktable-start clocktable-end filter)
  3819. (setq org-agenda-redo-command
  3820. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3821. (dotimes (n (1- ndays))
  3822. (push (1+ (car day-numbers)) day-numbers))
  3823. (setq day-numbers (nreverse day-numbers))
  3824. (setq clocktable-start (car day-numbers)
  3825. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3826. (org-set-local 'org-starting-day (car day-numbers))
  3827. (org-set-local 'org-arg-loc arg)
  3828. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3829. (unless org-agenda-compact-blocks
  3830. (let* ((d1 (car day-numbers))
  3831. (d2 (org-last day-numbers))
  3832. (w1 (org-days-to-iso-week d1))
  3833. (w2 (org-days-to-iso-week d2)))
  3834. (setq s (point))
  3835. (if org-agenda-overriding-header
  3836. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3837. nil 'face 'org-agenda-structure) "\n")
  3838. (insert (org-agenda-span-name span)
  3839. "-agenda"
  3840. (if (< (- d2 d1) 350)
  3841. (if (= w1 w2)
  3842. (format " (W%02d)" w1)
  3843. (format " (W%02d-W%02d)" w1 w2))
  3844. "")
  3845. ":\n")))
  3846. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3847. 'org-date-line t))
  3848. (org-agenda-mark-header-line s))
  3849. (while (setq d (pop day-numbers))
  3850. (setq date (calendar-gregorian-from-absolute d)
  3851. s (point))
  3852. (if (or (setq todayp (= d today))
  3853. (and (not start-pos) (= d sd)))
  3854. (setq start-pos (point))
  3855. (if (and start-pos (not end-pos))
  3856. (setq end-pos (point))))
  3857. (setq files thefiles
  3858. rtnall nil)
  3859. (while (setq file (pop files))
  3860. (catch 'nextfile
  3861. (org-check-agenda-file file)
  3862. (let ((org-agenda-entry-types org-agenda-entry-types))
  3863. ;; Starred types override non-starred equivalents
  3864. (when (member :deadline* org-agenda-entry-types)
  3865. (setq org-agenda-entry-types
  3866. (delq :deadline org-agenda-entry-types)))
  3867. (when (member :scheduled* org-agenda-entry-types)
  3868. (setq org-agenda-entry-types
  3869. (delq :scheduled org-agenda-entry-types)))
  3870. ;; Honor with-hour
  3871. (when with-hour
  3872. (when (member :deadline org-agenda-entry-types)
  3873. (setq org-agenda-entry-types
  3874. (delq :deadline org-agenda-entry-types))
  3875. (push :deadline* org-agenda-entry-types))
  3876. (when (member :scheduled org-agenda-entry-types)
  3877. (setq org-agenda-entry-types
  3878. (delq :scheduled org-agenda-entry-types))
  3879. (push :scheduled* org-agenda-entry-types)))
  3880. (unless org-agenda-include-deadlines
  3881. (setq org-agenda-entry-types
  3882. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3883. (cond
  3884. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3885. (setq rtn (org-agenda-get-day-entries
  3886. file date :closed)))
  3887. (org-agenda-show-log-scoped
  3888. (setq rtn (apply 'org-agenda-get-day-entries
  3889. file date
  3890. (append '(:closed) org-agenda-entry-types))))
  3891. (t
  3892. (setq rtn (apply 'org-agenda-get-day-entries
  3893. file date
  3894. org-agenda-entry-types)))))
  3895. (setq rtnall (append rtnall rtn)))) ;; all entries
  3896. (if org-agenda-include-diary
  3897. (let ((org-agenda-search-headline-for-time t))
  3898. (require 'diary-lib)
  3899. (setq rtn (org-get-entries-from-diary date))
  3900. (setq rtnall (append rtnall rtn))))
  3901. (if (or rtnall org-agenda-show-all-dates)
  3902. (progn
  3903. (setq day-cnt (1+ day-cnt))
  3904. (insert
  3905. (if (stringp org-agenda-format-date)
  3906. (format-time-string org-agenda-format-date
  3907. (org-time-from-absolute date))
  3908. (funcall org-agenda-format-date date))
  3909. "\n")
  3910. (put-text-property s (1- (point)) 'face
  3911. (org-agenda-get-day-face date))
  3912. (put-text-property s (1- (point)) 'org-date-line t)
  3913. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3914. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3915. (when todayp
  3916. (put-text-property s (1- (point)) 'org-today t))
  3917. (setq rtnall
  3918. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3919. (if rtnall (insert ;; all entries
  3920. (org-agenda-finalize-entries rtnall 'agenda)
  3921. "\n"))
  3922. (put-text-property s (1- (point)) 'day d)
  3923. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3924. (when (and org-agenda-clockreport-mode clocktable-start)
  3925. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3926. ;; the above line is to ensure the restricted range!
  3927. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3928. tbl)
  3929. (setq p (org-plist-delete p :block))
  3930. (setq p (plist-put p :tstart clocktable-start))
  3931. (setq p (plist-put p :tend clocktable-end))
  3932. (setq p (plist-put p :scope 'agenda))
  3933. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3934. (setq filter (or org-agenda-tag-filter-while-redo
  3935. (get 'org-agenda-tag-filter :preset-filter))))
  3936. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3937. (if (string-match "[<>=]" x)
  3938. ""
  3939. x))
  3940. filter ""))))
  3941. (setq tbl (apply 'org-clock-get-clocktable p))
  3942. (insert tbl)))
  3943. (goto-char (point-min))
  3944. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3945. (unless (and (pos-visible-in-window-p (point-min))
  3946. (pos-visible-in-window-p (point-max)))
  3947. (goto-char (1- (point-max)))
  3948. (recenter -1)
  3949. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3950. (progn
  3951. (goto-char (or start-pos 1))
  3952. (recenter 1))))
  3953. (goto-char (or start-pos 1))
  3954. (add-text-properties (point-min) (point-max)
  3955. `(org-agenda-type agenda
  3956. org-last-args (,arg ,start-day ,span)
  3957. org-redo-cmd ,org-agenda-redo-command
  3958. org-series-cmd ,org-cmd))
  3959. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3960. (org-agenda-show-clocking-issues))
  3961. (org-agenda-finalize)
  3962. (setq buffer-read-only t)
  3963. (message ""))))
  3964. (defun org-agenda-ndays-to-span (n)
  3965. "Return a span symbol for a span of N days, or N if none matches."
  3966. (cond ((symbolp n) n)
  3967. ((= n 1) 'day)
  3968. ((= n 7) 'week)
  3969. (t n)))
  3970. (defun org-agenda-span-to-ndays (span &optional start-day)
  3971. "Return ndays from SPAN, possibly starting at START-DAY.
  3972. START-DAY is an absolute time value."
  3973. (cond ((numberp span) span)
  3974. ((eq span 'day) 1)
  3975. ((eq span 'week) 7)
  3976. ((eq span 'month)
  3977. (let ((date (calendar-gregorian-from-absolute start-day)))
  3978. (calendar-last-day-of-month (car date) (caddr date))))
  3979. ((eq span 'year)
  3980. (let ((date (calendar-gregorian-from-absolute start-day)))
  3981. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3982. (defun org-agenda-span-name (span)
  3983. "Return a SPAN name."
  3984. (if (null span)
  3985. ""
  3986. (if (symbolp span)
  3987. (capitalize (symbol-name span))
  3988. (format "%d days" span))))
  3989. ;;; Agenda word search
  3990. (defvar org-agenda-search-history nil)
  3991. (defvar org-search-syntax-table nil
  3992. "Special syntax table for org-mode search.
  3993. In this table, we have single quotes not as word constituents, to
  3994. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3995. (defvar org-mode-syntax-table) ; From org.el
  3996. (defun org-search-syntax-table ()
  3997. (unless org-search-syntax-table
  3998. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3999. (modify-syntax-entry ?' "." org-search-syntax-table)
  4000. (modify-syntax-entry ?` "." org-search-syntax-table))
  4001. org-search-syntax-table)
  4002. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4003. ;;;###autoload
  4004. (defun org-search-view (&optional todo-only string edit-at)
  4005. "Show all entries that contain a phrase or words or regular expressions.
  4006. With optional prefix argument TODO-ONLY, only consider entries that are
  4007. TODO entries. The argument STRING can be used to pass a default search
  4008. string into this function. If EDIT-AT is non-nil, it means that the
  4009. user should get a chance to edit this string, with cursor at position
  4010. EDIT-AT.
  4011. The search string can be viewed either as a phrase that should be found as
  4012. is, or it can be broken into a number of snippets, each of which must match
  4013. in a Boolean way to select an entry. The default depends on the variable
  4014. `org-agenda-search-view-always-boolean'.
  4015. Even if this is turned off (the default) you can always switch to
  4016. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4017. The default is a direct search of the whole phrase, where each space in
  4018. the search string can expand to an arbitrary amount of whitespace,
  4019. including newlines.
  4020. If using a Boolean search, the search string is split on whitespace and
  4021. each snippet is searched separately, with logical AND to select an entry.
  4022. Words prefixed with a minus must *not* occur in the entry. Words without
  4023. a prefix or prefixed with a plus must occur in the entry. Matching is
  4024. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4025. match whole words, not parts of a word) if
  4026. `org-agenda-search-view-force-full-words' is set (default is nil).
  4027. Boolean search snippets enclosed by curly braces are interpreted as
  4028. regular expressions that must or (when preceded with \"-\") must not
  4029. match in the entry. Snippets enclosed into double quotes will be taken
  4030. as a whole, to include whitespace.
  4031. - If the search string starts with an asterisk, search only in headlines.
  4032. - If (possibly after the leading star) the search string starts with an
  4033. exclamation mark, this also means to look at TODO entries only, an effect
  4034. that can also be achieved with a prefix argument.
  4035. - If (possibly after star and exclamation mark) the search string starts
  4036. with a colon, this will mean that the (non-regexp) snippets of the
  4037. Boolean search must match as full words.
  4038. This command searches the agenda files, and in addition the files listed
  4039. in `org-agenda-text-search-extra-files'."
  4040. (interactive "P")
  4041. (if org-agenda-overriding-arguments
  4042. (setq todo-only (car org-agenda-overriding-arguments)
  4043. string (nth 1 org-agenda-overriding-arguments)
  4044. edit-at (nth 2 org-agenda-overriding-arguments)))
  4045. (let* ((props (list 'face nil
  4046. 'done-face 'org-agenda-done
  4047. 'org-not-done-regexp org-not-done-regexp
  4048. 'org-todo-regexp org-todo-regexp
  4049. 'org-complex-heading-regexp org-complex-heading-regexp
  4050. 'mouse-face 'highlight
  4051. 'help-echo (format "mouse-2 or RET jump to location")))
  4052. (full-words org-agenda-search-view-force-full-words)
  4053. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4054. regexp rtn rtnall files file pos inherited-tags
  4055. marker category category-pos level tags c neg re boolean
  4056. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4057. (unless (and (not edit-at)
  4058. (stringp string)
  4059. (string-match "\\S-" string))
  4060. (setq string (read-string
  4061. (if org-agenda-search-view-always-boolean
  4062. "[+-]Word/{Regexp} ...: "
  4063. "Phrase or [+-]Word/{Regexp} ...: ")
  4064. (cond
  4065. ((integerp edit-at) (cons string edit-at))
  4066. (edit-at string))
  4067. 'org-agenda-search-history)))
  4068. (catch 'exit
  4069. (if org-agenda-sticky
  4070. (setq org-agenda-buffer-name
  4071. (if (stringp string)
  4072. (format "*Org Agenda(%s:%s)*"
  4073. (or org-keys (or (and todo-only "S") "s")) string)
  4074. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4075. (org-agenda-prepare "SEARCH")
  4076. (org-compile-prefix-format 'search)
  4077. (org-set-sorting-strategy 'search)
  4078. (setq org-agenda-redo-command
  4079. (list 'org-search-view (if todo-only t nil)
  4080. (list 'if 'current-prefix-arg nil string)))
  4081. (setq org-agenda-query-string string)
  4082. (if (equal (string-to-char string) ?*)
  4083. (setq hdl-only t
  4084. words (substring string 1))
  4085. (setq words string))
  4086. (when (equal (string-to-char words) ?!)
  4087. (setq todo-only t
  4088. words (substring words 1)))
  4089. (when (equal (string-to-char words) ?:)
  4090. (setq full-words t
  4091. words (substring words 1)))
  4092. (if (or org-agenda-search-view-always-boolean
  4093. (member (string-to-char words) '(?- ?+ ?\{)))
  4094. (setq boolean t))
  4095. (setq words (org-split-string words))
  4096. (let (www w)
  4097. (while (setq w (pop words))
  4098. (while (and (string-match "\\\\\\'" w) words)
  4099. (setq w (concat (substring w 0 -1) " " (pop words))))
  4100. (push w www))
  4101. (setq words (nreverse www) www nil)
  4102. (while (setq w (pop words))
  4103. (when (and (string-match "\\`[-+]?{" w)
  4104. (not (string-match "}\\'" w)))
  4105. (while (and words (not (string-match "}\\'" (car words))))
  4106. (setq w (concat w " " (pop words))))
  4107. (setq w (concat w " " (pop words))))
  4108. (push w www))
  4109. (setq words (nreverse www)))
  4110. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4111. (when boolean
  4112. (let (wds w)
  4113. (while (setq w (pop words))
  4114. (if (or (equal (substring w 0 1) "\"")
  4115. (and (> (length w) 1)
  4116. (member (substring w 0 1) '("+" "-"))
  4117. (equal (substring w 1 2) "\"")))
  4118. (while (and words (not (equal (substring w -1) "\"")))
  4119. (setq w (concat w " " (pop words)))))
  4120. (and (string-match "\\`\\([-+]?\\)\"" w)
  4121. (setq w (replace-match "\\1" nil nil w)))
  4122. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4123. (push w wds))
  4124. (setq words (nreverse wds))))
  4125. (if boolean
  4126. (mapc (lambda (w)
  4127. (setq c (string-to-char w))
  4128. (if (equal c ?-)
  4129. (setq neg t w (substring w 1))
  4130. (if (equal c ?+)
  4131. (setq neg nil w (substring w 1))
  4132. (setq neg nil)))
  4133. (if (string-match "\\`{.*}\\'" w)
  4134. (setq re (substring w 1 -1))
  4135. (if full-words
  4136. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4137. (setq re (regexp-quote (downcase w)))))
  4138. (if neg (push re regexps-) (push re regexps+)))
  4139. words)
  4140. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4141. regexps+))
  4142. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4143. (if (not regexps+)
  4144. (setq regexp org-outline-regexp-bol)
  4145. (setq regexp (pop regexps+))
  4146. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4147. regexp))))
  4148. (setq files (org-agenda-files nil 'ifmode))
  4149. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4150. (pop org-agenda-text-search-extra-files)
  4151. (setq files (org-add-archive-files files)))
  4152. (setq files (append files org-agenda-text-search-extra-files)
  4153. rtnall nil)
  4154. (while (setq file (pop files))
  4155. (setq ee nil)
  4156. (catch 'nextfile
  4157. (org-check-agenda-file file)
  4158. (setq buffer (if (file-exists-p file)
  4159. (org-get-agenda-file-buffer file)
  4160. (error "No such file %s" file)))
  4161. (if (not buffer)
  4162. ;; If file does not exist, make sure an error message is sent
  4163. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4164. file))))
  4165. (with-current-buffer buffer
  4166. (with-syntax-table (org-search-syntax-table)
  4167. (unless (derived-mode-p 'org-mode)
  4168. (error "Agenda file %s is not in `org-mode'" file))
  4169. (let ((case-fold-search t))
  4170. (save-excursion
  4171. (save-restriction
  4172. (if org-agenda-restrict
  4173. (narrow-to-region org-agenda-restrict-begin
  4174. org-agenda-restrict-end)
  4175. (widen))
  4176. (goto-char (point-min))
  4177. (unless (or (org-at-heading-p)
  4178. (outline-next-heading))
  4179. (throw 'nextfile t))
  4180. (goto-char (max (point-min) (1- (point))))
  4181. (while (re-search-forward regexp nil t)
  4182. (org-back-to-heading t)
  4183. (while (and org-agenda-search-view-max-outline-level
  4184. (> (org-reduced-level (org-outline-level))
  4185. org-agenda-search-view-max-outline-level)
  4186. (forward-line -1)
  4187. (outline-back-to-heading t)))
  4188. (skip-chars-forward "* ")
  4189. (setq beg (point-at-bol)
  4190. beg1 (point)
  4191. end (progn
  4192. (outline-next-heading)
  4193. (while (and org-agenda-search-view-max-outline-level
  4194. (> (org-reduced-level (org-outline-level))
  4195. org-agenda-search-view-max-outline-level)
  4196. (forward-line 1)
  4197. (outline-next-heading)))
  4198. (point)))
  4199. (catch :skip
  4200. (goto-char beg)
  4201. (org-agenda-skip)
  4202. (setq str (buffer-substring-no-properties
  4203. (point-at-bol)
  4204. (if hdl-only (point-at-eol) end)))
  4205. (mapc (lambda (wr) (when (string-match wr str)
  4206. (goto-char (1- end))
  4207. (throw :skip t)))
  4208. regexps-)
  4209. (mapc (lambda (wr) (unless (string-match wr str)
  4210. (goto-char (1- end))
  4211. (throw :skip t)))
  4212. (if todo-only
  4213. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4214. regexps+)
  4215. regexps+))
  4216. (goto-char beg)
  4217. (setq marker (org-agenda-new-marker (point))
  4218. category (org-get-category)
  4219. level (make-string (org-reduced-level (org-outline-level)) ? )
  4220. category-pos (get-text-property (point) 'org-category-position)
  4221. inherited-tags
  4222. (or (eq org-agenda-show-inherited-tags 'always)
  4223. (and (listp org-agenda-show-inherited-tags)
  4224. (memq 'todo org-agenda-show-inherited-tags))
  4225. (and (eq org-agenda-show-inherited-tags t)
  4226. (or (eq org-agenda-use-tag-inheritance t)
  4227. (memq 'todo org-agenda-use-tag-inheritance))))
  4228. tags (org-get-tags-at nil (not inherited-tags))
  4229. txt (org-agenda-format-item
  4230. ""
  4231. (buffer-substring-no-properties
  4232. beg1 (point-at-eol))
  4233. level category tags t))
  4234. (org-add-props txt props
  4235. 'org-marker marker 'org-hd-marker marker
  4236. 'org-todo-regexp org-todo-regexp
  4237. 'level level
  4238. 'org-complex-heading-regexp org-complex-heading-regexp
  4239. 'priority 1000 'org-category category
  4240. 'org-category-position category-pos
  4241. 'type "search")
  4242. (push txt ee)
  4243. (goto-char (1- end))))))))))
  4244. (setq rtn (nreverse ee))
  4245. (setq rtnall (append rtnall rtn)))
  4246. (if org-agenda-overriding-header
  4247. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4248. nil 'face 'org-agenda-structure) "\n")
  4249. (insert "Search words: ")
  4250. (add-text-properties (point-min) (1- (point))
  4251. (list 'face 'org-agenda-structure))
  4252. (setq pos (point))
  4253. (insert string "\n")
  4254. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4255. (setq pos (point))
  4256. (unless org-agenda-multi
  4257. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4258. (add-text-properties pos (1- (point))
  4259. (list 'face 'org-agenda-structure))))
  4260. (org-agenda-mark-header-line (point-min))
  4261. (when rtnall
  4262. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4263. (goto-char (point-min))
  4264. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4265. (add-text-properties (point-min) (point-max)
  4266. `(org-agenda-type search
  4267. org-last-args (,todo-only ,string ,edit-at)
  4268. org-redo-cmd ,org-agenda-redo-command
  4269. org-series-cmd ,org-cmd))
  4270. (org-agenda-finalize)
  4271. (setq buffer-read-only t))))
  4272. ;;; Agenda TODO list
  4273. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4274. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4275. (concat
  4276. (if (or (equal keywords "ALL") (not keywords))
  4277. (propertize "ALL" 'face 'warning)
  4278. (mapconcat
  4279. (lambda (kw)
  4280. (propertize kw 'face (org-get-todo-face kw)))
  4281. (org-split-string keywords "|")
  4282. "|"))
  4283. "\n"))
  4284. (defvar org-select-this-todo-keyword nil)
  4285. (defvar org-last-arg nil)
  4286. ;;;###autoload
  4287. (defun org-todo-list (&optional arg)
  4288. "Show all (not done) TODO entries from all agenda file in a single list.
  4289. The prefix arg can be used to select a specific TODO keyword and limit
  4290. the list to these. When using \\[universal-argument], you will be prompted
  4291. for a keyword. A numeric prefix directly selects the Nth keyword in
  4292. `org-todo-keywords-1'."
  4293. (interactive "P")
  4294. (if org-agenda-overriding-arguments
  4295. (setq arg org-agenda-overriding-arguments))
  4296. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4297. (let* ((today (org-today))
  4298. (date (calendar-gregorian-from-absolute today))
  4299. (kwds org-todo-keywords-for-agenda)
  4300. (completion-ignore-case t)
  4301. (org-select-this-todo-keyword
  4302. (if (stringp arg) arg
  4303. (and arg (integerp arg) (> arg 0)
  4304. (nth (1- arg) kwds))))
  4305. rtn rtnall files file pos)
  4306. (when (equal arg '(4))
  4307. (setq org-select-this-todo-keyword
  4308. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4309. (mapcar 'list kwds) nil nil)))
  4310. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4311. (catch 'exit
  4312. (if org-agenda-sticky
  4313. (setq org-agenda-buffer-name
  4314. (if (stringp org-select-this-todo-keyword)
  4315. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4316. org-select-this-todo-keyword)
  4317. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4318. (org-agenda-prepare "TODO")
  4319. (org-compile-prefix-format 'todo)
  4320. (org-set-sorting-strategy 'todo)
  4321. (setq org-agenda-redo-command
  4322. `(org-todo-list (or (and (numberp current-prefix-arg)
  4323. current-prefix-arg)
  4324. ,org-select-this-todo-keyword
  4325. current-prefix-arg ,arg)))
  4326. (setq files (org-agenda-files nil 'ifmode)
  4327. rtnall nil)
  4328. (while (setq file (pop files))
  4329. (catch 'nextfile
  4330. (org-check-agenda-file file)
  4331. (setq rtn (org-agenda-get-day-entries file date :todo))
  4332. (setq rtnall (append rtnall rtn))))
  4333. (if org-agenda-overriding-header
  4334. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4335. nil 'face 'org-agenda-structure) "\n")
  4336. (insert "Global list of TODO items of type: ")
  4337. (add-text-properties (point-min) (1- (point))
  4338. (list 'face 'org-agenda-structure
  4339. 'short-heading
  4340. (concat "ToDo: "
  4341. (or org-select-this-todo-keyword "ALL"))))
  4342. (org-agenda-mark-header-line (point-min))
  4343. (insert (org-agenda-propertize-selected-todo-keywords
  4344. org-select-this-todo-keyword))
  4345. (setq pos (point))
  4346. (unless org-agenda-multi
  4347. (insert "Available with `N r': (0)[ALL]")
  4348. (let ((n 0) s)
  4349. (mapc (lambda (x)
  4350. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4351. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4352. (insert "\n "))
  4353. (insert " " s))
  4354. kwds))
  4355. (insert "\n"))
  4356. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4357. (org-agenda-mark-header-line (point-min))
  4358. (when rtnall
  4359. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4360. (goto-char (point-min))
  4361. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4362. (add-text-properties (point-min) (point-max)
  4363. `(org-agenda-type todo
  4364. org-last-args ,arg
  4365. org-redo-cmd ,org-agenda-redo-command
  4366. org-series-cmd ,org-cmd))
  4367. (org-agenda-finalize)
  4368. (setq buffer-read-only t))))
  4369. ;;; Agenda tags match
  4370. ;;;###autoload
  4371. (defun org-tags-view (&optional todo-only match)
  4372. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4373. The prefix arg TODO-ONLY limits the search to TODO entries."
  4374. (interactive "P")
  4375. (if org-agenda-overriding-arguments
  4376. (setq todo-only (car org-agenda-overriding-arguments)
  4377. match (nth 1 org-agenda-overriding-arguments)))
  4378. (let* ((org-tags-match-list-sublevels
  4379. org-tags-match-list-sublevels)
  4380. (completion-ignore-case t)
  4381. rtn rtnall files file pos matcher
  4382. buffer)
  4383. (when (and (stringp match) (not (string-match "\\S-" match)))
  4384. (setq match nil))
  4385. (catch 'exit
  4386. (if org-agenda-sticky
  4387. (setq org-agenda-buffer-name
  4388. (if (stringp match)
  4389. (format "*Org Agenda(%s:%s)*"
  4390. (or org-keys (or (and todo-only "M") "m")) match)
  4391. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4392. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4393. ;; expanding tags within `org-make-tags-matcher'
  4394. (org-agenda-prepare (concat "TAGS " match))
  4395. (setq matcher (org-make-tags-matcher match)
  4396. match (car matcher) matcher (cdr matcher))
  4397. (org-compile-prefix-format 'tags)
  4398. (org-set-sorting-strategy 'tags)
  4399. (setq org-agenda-query-string match)
  4400. (setq org-agenda-redo-command
  4401. (list 'org-tags-view `(quote ,todo-only)
  4402. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4403. (setq files (org-agenda-files nil 'ifmode)
  4404. rtnall nil)
  4405. (while (setq file (pop files))
  4406. (catch 'nextfile
  4407. (org-check-agenda-file file)
  4408. (setq buffer (if (file-exists-p file)
  4409. (org-get-agenda-file-buffer file)
  4410. (error "No such file %s" file)))
  4411. (if (not buffer)
  4412. ;; If file does not exist, error message to agenda
  4413. (setq rtn (list
  4414. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4415. rtnall (append rtnall rtn))
  4416. (with-current-buffer buffer
  4417. (unless (derived-mode-p 'org-mode)
  4418. (error "Agenda file %s is not in `org-mode'" file))
  4419. (save-excursion
  4420. (save-restriction
  4421. (if org-agenda-restrict
  4422. (narrow-to-region org-agenda-restrict-begin
  4423. org-agenda-restrict-end)
  4424. (widen))
  4425. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4426. (setq rtnall (append rtnall rtn))))))))
  4427. (if org-agenda-overriding-header
  4428. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4429. nil 'face 'org-agenda-structure) "\n")
  4430. (insert "Headlines with TAGS match: ")
  4431. (add-text-properties (point-min) (1- (point))
  4432. (list 'face 'org-agenda-structure
  4433. 'short-heading
  4434. (concat "Match: " match)))
  4435. (setq pos (point))
  4436. (insert match "\n")
  4437. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4438. (setq pos (point))
  4439. (unless org-agenda-multi
  4440. (insert "Press `C-u r' to search again with new search string\n"))
  4441. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4442. (org-agenda-mark-header-line (point-min))
  4443. (when rtnall
  4444. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4445. (goto-char (point-min))
  4446. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4447. (add-text-properties (point-min) (point-max)
  4448. `(org-agenda-type tags
  4449. org-last-args (,todo-only ,match)
  4450. org-redo-cmd ,org-agenda-redo-command
  4451. org-series-cmd ,org-cmd))
  4452. (org-agenda-finalize)
  4453. (setq buffer-read-only t))))
  4454. ;;; Agenda Finding stuck projects
  4455. (defvar org-agenda-skip-regexp nil
  4456. "Regular expression used in skipping subtrees for the agenda.
  4457. This is basically a temporary global variable that can be set and then
  4458. used by user-defined selections using `org-agenda-skip-function'.")
  4459. (defvar org-agenda-overriding-header nil
  4460. "When set during agenda, todo and tags searches it replaces the header.
  4461. This variable should not be set directly, but custom commands can bind it
  4462. in the options section.")
  4463. (defun org-agenda-skip-entry-when-regexp-matches ()
  4464. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4465. If yes, it returns the end position of this entry, causing agenda commands
  4466. to skip the entry but continuing the search in the subtree. This is a
  4467. function that can be put into `org-agenda-skip-function' for the duration
  4468. of a command."
  4469. (let ((end (save-excursion (org-end-of-subtree t)))
  4470. skip)
  4471. (save-excursion
  4472. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4473. (and skip end)))
  4474. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4475. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4476. If yes, it returns the end position of this tree, causing agenda commands
  4477. to skip this subtree. This is a function that can be put into
  4478. `org-agenda-skip-function' for the duration of a command."
  4479. (let ((end (save-excursion (org-end-of-subtree t)))
  4480. skip)
  4481. (save-excursion
  4482. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4483. (and skip end)))
  4484. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4485. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4486. If yes, it returns the end position of the current entry (NOT the tree),
  4487. causing agenda commands to skip the entry but continuing the search in
  4488. the subtree. This is a function that can be put into
  4489. `org-agenda-skip-function' for the duration of a command. An important
  4490. use of this function is for the stuck project list."
  4491. (let ((end (save-excursion (org-end-of-subtree t)))
  4492. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4493. skip)
  4494. (save-excursion
  4495. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4496. (and skip entry-end)))
  4497. (defun org-agenda-skip-entry-if (&rest conditions)
  4498. "Skip entry if any of CONDITIONS is true.
  4499. See `org-agenda-skip-if' for details."
  4500. (org-agenda-skip-if nil conditions))
  4501. (defun org-agenda-skip-subtree-if (&rest conditions)
  4502. "Skip entry if any of CONDITIONS is true.
  4503. See `org-agenda-skip-if' for details."
  4504. (org-agenda-skip-if t conditions))
  4505. (defun org-agenda-skip-if (subtree conditions)
  4506. "Checks current entity for CONDITIONS.
  4507. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4508. the entry (i.e. the text before the next heading) is checked.
  4509. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4510. from different tests. Valid conditions are:
  4511. scheduled Check if there is a scheduled cookie
  4512. notscheduled Check if there is no scheduled cookie
  4513. deadline Check if there is a deadline
  4514. notdeadline Check if there is no deadline
  4515. timestamp Check if there is a timestamp (also deadline or scheduled)
  4516. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4517. regexp Check if regexp matches
  4518. notregexp Check if regexp does not match.
  4519. todo Check if TODO keyword matches
  4520. nottodo Check if TODO keyword does not match
  4521. The regexp is taken from the conditions list, it must come right after
  4522. the `regexp' or `notregexp' element.
  4523. `todo' and `nottodo' accept as an argument a list of todo
  4524. keywords, which may include \"*\" to match any todo keyword.
  4525. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4526. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4527. Instead of a list, a keyword class may be given. For example:
  4528. (org-agenda-skip-entry-if 'nottodo 'done)
  4529. would skip entries that haven't been marked with any of \"DONE\"
  4530. keywords. Possible classes are: `todo', `done', `any'.
  4531. If any of these conditions is met, this function returns the end point of
  4532. the entity, causing the search to continue from there. This is a function
  4533. that can be put into `org-agenda-skip-function' for the duration of a command."
  4534. (let (beg end m)
  4535. (org-back-to-heading t)
  4536. (setq beg (point)
  4537. end (if subtree
  4538. (progn (org-end-of-subtree t) (point))
  4539. (progn (outline-next-heading) (1- (point)))))
  4540. (goto-char beg)
  4541. (and
  4542. (or
  4543. (and (memq 'scheduled conditions)
  4544. (re-search-forward org-scheduled-time-regexp end t))
  4545. (and (memq 'notscheduled conditions)
  4546. (not (re-search-forward org-scheduled-time-regexp end t)))
  4547. (and (memq 'deadline conditions)
  4548. (re-search-forward org-deadline-time-regexp end t))
  4549. (and (memq 'notdeadline conditions)
  4550. (not (re-search-forward org-deadline-time-regexp end t)))
  4551. (and (memq 'timestamp conditions)
  4552. (re-search-forward org-ts-regexp end t))
  4553. (and (memq 'nottimestamp conditions)
  4554. (not (re-search-forward org-ts-regexp end t)))
  4555. (and (setq m (memq 'regexp conditions))
  4556. (stringp (nth 1 m))
  4557. (re-search-forward (nth 1 m) end t))
  4558. (and (setq m (memq 'notregexp conditions))
  4559. (stringp (nth 1 m))
  4560. (not (re-search-forward (nth 1 m) end t)))
  4561. (and (or
  4562. (setq m (memq 'nottodo conditions))
  4563. (setq m (memq 'todo-unblocked conditions))
  4564. (setq m (memq 'nottodo-unblocked conditions))
  4565. (setq m (memq 'todo conditions)))
  4566. (org-agenda-skip-if-todo m end)))
  4567. end)))
  4568. (defun org-agenda-skip-if-todo (args end)
  4569. "Helper function for `org-agenda-skip-if', do not use it directly.
  4570. ARGS is a list with first element either `todo', `nottodo',
  4571. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4572. a list of TODO keywords, or a state symbol `todo' or `done' or
  4573. `any'."
  4574. (let ((kw (car args))
  4575. (arg (cadr args))
  4576. todo-wds todo-re)
  4577. (setq todo-wds
  4578. (org-uniquify
  4579. (cond
  4580. ((listp arg) ;; list of keywords
  4581. (if (member "*" arg)
  4582. (mapcar 'substring-no-properties org-todo-keywords-1)
  4583. arg))
  4584. ((symbolp arg) ;; keyword class name
  4585. (cond
  4586. ((eq arg 'todo)
  4587. (org-delete-all org-done-keywords
  4588. (mapcar 'substring-no-properties
  4589. org-todo-keywords-1)))
  4590. ((eq arg 'done) org-done-keywords)
  4591. ((eq arg 'any)
  4592. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4593. (setq todo-re
  4594. (concat "^\\*+[ \t]+\\<\\("
  4595. (mapconcat 'identity todo-wds "\\|")
  4596. "\\)\\>"))
  4597. (cond
  4598. ((eq kw 'todo) (re-search-forward todo-re end t))
  4599. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4600. ((eq kw 'todo-unblocked)
  4601. (catch 'unblocked
  4602. (while (re-search-forward todo-re end t)
  4603. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4604. nil))
  4605. ((eq kw 'nottodo-unblocked)
  4606. (catch 'unblocked
  4607. (while (re-search-forward todo-re end t)
  4608. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4609. t))
  4610. )))
  4611. ;;;###autoload
  4612. (defun org-agenda-list-stuck-projects (&rest ignore)
  4613. "Create agenda view for projects that are stuck.
  4614. Stuck projects are project that have no next actions. For the definitions
  4615. of what a project is and how to check if it stuck, customize the variable
  4616. `org-stuck-projects'."
  4617. (interactive)
  4618. (let* ((org-agenda-skip-function
  4619. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4620. ;; We could have used org-agenda-skip-if here.
  4621. (org-agenda-overriding-header
  4622. (or org-agenda-overriding-header "List of stuck projects: "))
  4623. (matcher (nth 0 org-stuck-projects))
  4624. (todo (nth 1 org-stuck-projects))
  4625. (todo-wds (if (member "*" todo)
  4626. (progn
  4627. (org-agenda-prepare-buffers (org-agenda-files
  4628. nil 'ifmode))
  4629. (org-delete-all
  4630. org-done-keywords-for-agenda
  4631. (copy-sequence org-todo-keywords-for-agenda)))
  4632. todo))
  4633. (todo-re (concat "^\\*+[ \t]+\\("
  4634. (mapconcat 'identity todo-wds "\\|")
  4635. "\\)\\>"))
  4636. (tags (nth 2 org-stuck-projects))
  4637. (tags-re (if (member "*" tags)
  4638. (concat org-outline-regexp-bol
  4639. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4640. (if tags
  4641. (concat org-outline-regexp-bol
  4642. ".*:\\("
  4643. (mapconcat 'identity tags "\\|")
  4644. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4645. (gen-re (nth 3 org-stuck-projects))
  4646. (re-list
  4647. (delq nil
  4648. (list
  4649. (if todo todo-re)
  4650. (if tags tags-re)
  4651. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4652. gen-re)))))
  4653. (setq org-agenda-skip-regexp
  4654. (if re-list
  4655. (mapconcat 'identity re-list "\\|")
  4656. (error "No information how to identify unstuck projects")))
  4657. (org-tags-view nil matcher)
  4658. (with-current-buffer org-agenda-buffer-name
  4659. (setq org-agenda-redo-command
  4660. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4661. ;;; Diary integration
  4662. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4663. (defvar diary-list-entries-hook)
  4664. (defvar diary-time-regexp)
  4665. (defun org-get-entries-from-diary (date)
  4666. "Get the (Emacs Calendar) diary entries for DATE."
  4667. (require 'diary-lib)
  4668. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4669. (diary-display-hook '(fancy-diary-display))
  4670. (diary-display-function 'fancy-diary-display)
  4671. (pop-up-frames nil)
  4672. (diary-list-entries-hook
  4673. (cons 'org-diary-default-entry diary-list-entries-hook))
  4674. (diary-file-name-prefix nil) ; turn this feature off
  4675. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4676. entries
  4677. (org-disable-agenda-to-diary t))
  4678. (save-excursion
  4679. (save-window-excursion
  4680. (funcall (if (fboundp 'diary-list-entries)
  4681. 'diary-list-entries 'list-diary-entries)
  4682. date 1)))
  4683. (if (not (get-buffer diary-fancy-buffer))
  4684. (setq entries nil)
  4685. (with-current-buffer diary-fancy-buffer
  4686. (setq buffer-read-only nil)
  4687. (if (zerop (buffer-size))
  4688. ;; No entries
  4689. (setq entries nil)
  4690. ;; Omit the date and other unnecessary stuff
  4691. (org-agenda-cleanup-fancy-diary)
  4692. ;; Add prefix to each line and extend the text properties
  4693. (if (zerop (buffer-size))
  4694. (setq entries nil)
  4695. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4696. (setq entries
  4697. (with-temp-buffer
  4698. (insert entries) (goto-char (point-min))
  4699. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4700. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4701. (replace-match (concat "; " (match-string 1)))))
  4702. (buffer-string)))))
  4703. (set-buffer-modified-p nil)
  4704. (kill-buffer diary-fancy-buffer)))
  4705. (when entries
  4706. (setq entries (org-split-string entries "\n"))
  4707. (setq entries
  4708. (mapcar
  4709. (lambda (x)
  4710. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4711. ;; Extend the text properties to the beginning of the line
  4712. (org-add-props x (text-properties-at (1- (length x)) x)
  4713. 'type "diary" 'date date 'face 'org-agenda-diary))
  4714. entries)))))
  4715. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4716. "Hook run when the fancy diary buffer is cleaned up.")
  4717. (defun org-agenda-cleanup-fancy-diary ()
  4718. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4719. This gets rid of the date, the underline under the date, and
  4720. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4721. date. It also removes lines that contain only whitespace."
  4722. (goto-char (point-min))
  4723. (if (looking-at ".*?:[ \t]*")
  4724. (progn
  4725. (replace-match "")
  4726. (re-search-forward "\n=+$" nil t)
  4727. (replace-match "")
  4728. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4729. (re-search-forward "\n=+$" nil t)
  4730. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4731. (goto-char (point-min))
  4732. (while (re-search-forward "^ +\n" nil t)
  4733. (replace-match ""))
  4734. (goto-char (point-min))
  4735. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4736. (replace-match ""))
  4737. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4738. ;; Make sure entries from the diary have the right text properties.
  4739. (eval-after-load "diary-lib"
  4740. '(if (boundp 'diary-modify-entry-list-string-function)
  4741. ;; We can rely on the hook, nothing to do
  4742. nil
  4743. ;; Hook not available, must use advice to make this work
  4744. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4745. "Make the position visible."
  4746. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4747. (stringp string)
  4748. buffer-file-name)
  4749. (setq string (org-modify-diary-entry-string string))))))
  4750. (defun org-modify-diary-entry-string (string)
  4751. "Add text properties to string, allowing org-mode to act on it."
  4752. (org-add-props string nil
  4753. 'mouse-face 'highlight
  4754. 'help-echo (if buffer-file-name
  4755. (format "mouse-2 or RET jump to diary file %s"
  4756. (abbreviate-file-name buffer-file-name))
  4757. "")
  4758. 'org-agenda-diary-link t
  4759. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4760. (defun org-diary-default-entry ()
  4761. "Add a dummy entry to the diary.
  4762. Needed to avoid empty dates which mess up holiday display."
  4763. ;; Catch the error if dealing with the new add-to-diary-alist
  4764. (when org-disable-agenda-to-diary
  4765. (condition-case nil
  4766. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4767. (error
  4768. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4769. (defun org-add-to-diary-list (&rest args)
  4770. (if (fboundp 'diary-add-to-list)
  4771. (apply 'diary-add-to-list args)
  4772. (apply 'add-to-diary-list args)))
  4773. (defvar org-diary-last-run-time nil)
  4774. ;;;###autoload
  4775. (defun org-diary (&rest args)
  4776. "Return diary information from org files.
  4777. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4778. It accesses org files and extracts information from those files to be
  4779. listed in the diary. The function accepts arguments specifying what
  4780. items should be listed. For a list of arguments allowed here, see the
  4781. variable `org-agenda-entry-types'.
  4782. The call in the diary file should look like this:
  4783. &%%(org-diary) ~/path/to/some/orgfile.org
  4784. Use a separate line for each org file to check. Or, if you omit the file name,
  4785. all files listed in `org-agenda-files' will be checked automatically:
  4786. &%%(org-diary)
  4787. If you don't give any arguments (as in the example above), the default value
  4788. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4789. So the example above may also be written as
  4790. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4791. The function expects the lisp variables `entry' and `date' to be provided
  4792. by the caller, because this is how the calendar works. Don't use this
  4793. function from a program - use `org-agenda-get-day-entries' instead."
  4794. (when (> (- (org-float-time)
  4795. org-agenda-last-marker-time)
  4796. 5)
  4797. ;; I am not sure if this works with sticky agendas, because the marker
  4798. ;; list is then no longer a global variable.
  4799. (org-agenda-reset-markers))
  4800. (org-compile-prefix-format 'agenda)
  4801. (org-set-sorting-strategy 'agenda)
  4802. (setq args (or args org-agenda-entry-types))
  4803. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4804. (list entry)
  4805. (org-agenda-files t)))
  4806. (time (org-float-time))
  4807. file rtn results)
  4808. (when (or (not org-diary-last-run-time)
  4809. (> (- time
  4810. org-diary-last-run-time)
  4811. 3))
  4812. (org-agenda-prepare-buffers files))
  4813. (setq org-diary-last-run-time time)
  4814. ;; If this is called during org-agenda, don't return any entries to
  4815. ;; the calendar. Org Agenda will list these entries itself.
  4816. (if org-disable-agenda-to-diary (setq files nil))
  4817. (while (setq file (pop files))
  4818. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4819. (setq results (append results rtn)))
  4820. (when results
  4821. (setq results
  4822. (mapcar (lambda (i) (replace-regexp-in-string
  4823. org-bracket-link-regexp "\\3" i)) results))
  4824. (concat (org-agenda-finalize-entries results) "\n"))))
  4825. ;;; Agenda entry finders
  4826. (defun org-agenda-get-day-entries (file date &rest args)
  4827. "Does the work for `org-diary' and `org-agenda'.
  4828. FILE is the path to a file to be checked for entries. DATE is date like
  4829. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4830. which kind of entries should be extracted. For details about these, see
  4831. the documentation of `org-diary'."
  4832. (setq args (or args org-agenda-entry-types))
  4833. (let* ((org-startup-folded nil)
  4834. (org-startup-align-all-tables nil)
  4835. (buffer (if (file-exists-p file)
  4836. (org-get-agenda-file-buffer file)
  4837. (error "No such file %s" file)))
  4838. arg results rtn deadline-results)
  4839. (if (not buffer)
  4840. ;; If file does not exist, make sure an error message ends up in diary
  4841. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4842. (with-current-buffer buffer
  4843. (unless (derived-mode-p 'org-mode)
  4844. (error "Agenda file %s is not in `org-mode'" file))
  4845. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4846. (let ((case-fold-search nil))
  4847. (save-excursion
  4848. (save-restriction
  4849. (if org-agenda-restrict
  4850. (narrow-to-region org-agenda-restrict-begin
  4851. org-agenda-restrict-end)
  4852. (widen))
  4853. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4854. (while (setq arg (pop args))
  4855. (cond
  4856. ((and (eq arg :todo)
  4857. (equal date (calendar-gregorian-from-absolute
  4858. (org-today))))
  4859. (setq rtn (org-agenda-get-todos))
  4860. (setq results (append results rtn)))
  4861. ((eq arg :timestamp)
  4862. (setq rtn (org-agenda-get-blocks))
  4863. (setq results (append results rtn))
  4864. (setq rtn (org-agenda-get-timestamps deadline-results))
  4865. (setq results (append results rtn)))
  4866. ((eq arg :sexp)
  4867. (setq rtn (org-agenda-get-sexps))
  4868. (setq results (append results rtn)))
  4869. ((eq arg :scheduled)
  4870. (setq rtn (org-agenda-get-scheduled deadline-results))
  4871. (setq results (append results rtn)))
  4872. ((eq arg :scheduled*)
  4873. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4874. (setq results (append results rtn)))
  4875. ((eq arg :closed)
  4876. (setq rtn (org-agenda-get-progress))
  4877. (setq results (append results rtn)))
  4878. ((eq arg :deadline)
  4879. (setq rtn (org-agenda-get-deadlines))
  4880. (setq deadline-results (copy-sequence rtn))
  4881. (setq results (append results rtn)))
  4882. ((eq arg :deadline*)
  4883. (setq rtn (org-agenda-get-deadlines t))
  4884. (setq deadline-results (copy-sequence rtn))
  4885. (setq results (append results rtn))))))))
  4886. results))))
  4887. (defsubst org-em (x y list)
  4888. "Is X or Y a member of LIST?"
  4889. (or (memq x list) (memq y list)))
  4890. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4891. (defvar org-agenda-sorting-strategy-selected nil)
  4892. (defun org-agenda-get-todos ()
  4893. "Return the TODO information for agenda display."
  4894. (let* ((props (list 'face nil
  4895. 'done-face 'org-agenda-done
  4896. 'org-not-done-regexp org-not-done-regexp
  4897. 'org-todo-regexp org-todo-regexp
  4898. 'org-complex-heading-regexp org-complex-heading-regexp
  4899. 'mouse-face 'highlight
  4900. 'help-echo
  4901. (format "mouse-2 or RET jump to org file %s"
  4902. (abbreviate-file-name buffer-file-name))))
  4903. (regexp (format org-heading-keyword-regexp-format
  4904. (cond
  4905. ((and org-select-this-todo-keyword
  4906. (equal org-select-this-todo-keyword "*"))
  4907. org-todo-regexp)
  4908. (org-select-this-todo-keyword
  4909. (concat "\\("
  4910. (mapconcat 'identity
  4911. (org-split-string
  4912. org-select-this-todo-keyword
  4913. "|")
  4914. "\\|") "\\)"))
  4915. (t org-not-done-regexp))))
  4916. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4917. ee txt beg end inherited-tags todo-state-end-pos)
  4918. (goto-char (point-min))
  4919. (while (re-search-forward regexp nil t)
  4920. (catch :skip
  4921. (save-match-data
  4922. (beginning-of-line)
  4923. (org-agenda-skip)
  4924. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4925. (unless (and (setq todo-state (org-get-todo-state))
  4926. (setq todo-state-end-pos (match-end 2)))
  4927. (goto-char end)
  4928. (throw :skip nil))
  4929. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4930. (goto-char (1+ beg))
  4931. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4932. (throw :skip nil)))
  4933. (goto-char (match-beginning 2))
  4934. (setq marker (org-agenda-new-marker (match-beginning 0))
  4935. category (org-get-category)
  4936. ts-date (let (ts)
  4937. (save-match-data
  4938. (cond ((org-em 'scheduled-up 'scheduled-down
  4939. org-agenda-sorting-strategy-selected)
  4940. (setq ts (org-entry-get (point) "SCHEDULED")
  4941. ts-date-type " scheduled"))
  4942. ((org-em 'deadline-up 'deadline-down
  4943. org-agenda-sorting-strategy-selected)
  4944. (setq ts (org-entry-get (point) "DEADLINE")
  4945. ts-date-type " deadline"))
  4946. ((org-em 'ts-up 'ts-down
  4947. org-agenda-sorting-strategy-selected)
  4948. (setq ts (org-entry-get (point) "TIMESTAMP")
  4949. ts-date-type " timestamp"))
  4950. ((org-em 'tsia-up 'tsia-down
  4951. org-agenda-sorting-strategy-selected)
  4952. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4953. ts-date-type " timestamp_ia"))
  4954. ((org-em 'timestamp-up 'timestamp-down
  4955. org-agenda-sorting-strategy-selected)
  4956. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4957. (org-entry-get (point) "DEADLINE")
  4958. (org-entry-get (point) "TIMESTAMP")
  4959. (org-entry-get (point) "TIMESTAMP_IA"))
  4960. ts-date-type ""))
  4961. (t (setq ts-date-type "")))
  4962. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4963. category-pos (get-text-property (point) 'org-category-position)
  4964. txt (org-trim
  4965. (buffer-substring (match-beginning 2) (match-end 0)))
  4966. inherited-tags
  4967. (or (eq org-agenda-show-inherited-tags 'always)
  4968. (and (listp org-agenda-show-inherited-tags)
  4969. (memq 'todo org-agenda-show-inherited-tags))
  4970. (and (eq org-agenda-show-inherited-tags t)
  4971. (or (eq org-agenda-use-tag-inheritance t)
  4972. (memq 'todo org-agenda-use-tag-inheritance))))
  4973. tags (org-get-tags-at nil (not inherited-tags))
  4974. level (make-string (org-reduced-level (org-outline-level)) ? )
  4975. txt (org-agenda-format-item "" txt level category tags t)
  4976. priority (1+ (org-get-priority txt)))
  4977. (org-add-props txt props
  4978. 'org-marker marker 'org-hd-marker marker
  4979. 'priority priority 'org-category category
  4980. 'level level
  4981. 'ts-date ts-date
  4982. 'org-category-position category-pos
  4983. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4984. (push txt ee)
  4985. (if org-agenda-todo-list-sublevels
  4986. (goto-char todo-state-end-pos)
  4987. (org-end-of-subtree 'invisible))))
  4988. (nreverse ee)))
  4989. (defun org-agenda-todo-custom-ignore-p (time n)
  4990. "Check whether timestamp is farther away than n number of days.
  4991. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4992. `org-agenda-todo-ignore-scheduled' or
  4993. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4994. (let ((days (org-time-stamp-to-now
  4995. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4996. (if (>= n 0)
  4997. (>= days n)
  4998. (<= days n))))
  4999. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5000. (&optional end)
  5001. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5002. (when (or org-agenda-todo-ignore-with-date
  5003. org-agenda-todo-ignore-scheduled
  5004. org-agenda-todo-ignore-deadlines
  5005. org-agenda-todo-ignore-timestamp)
  5006. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5007. (save-excursion
  5008. (or (and org-agenda-todo-ignore-with-date
  5009. (re-search-forward org-ts-regexp end t))
  5010. (and org-agenda-todo-ignore-scheduled
  5011. (re-search-forward org-scheduled-time-regexp end t)
  5012. (cond
  5013. ((eq org-agenda-todo-ignore-scheduled 'future)
  5014. (> (org-time-stamp-to-now
  5015. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5016. ((eq org-agenda-todo-ignore-scheduled 'past)
  5017. (<= (org-time-stamp-to-now
  5018. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5019. ((numberp org-agenda-todo-ignore-scheduled)
  5020. (org-agenda-todo-custom-ignore-p
  5021. (match-string 1) org-agenda-todo-ignore-scheduled))
  5022. (t)))
  5023. (and org-agenda-todo-ignore-deadlines
  5024. (re-search-forward org-deadline-time-regexp end t)
  5025. (cond
  5026. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5027. ((eq org-agenda-todo-ignore-deadlines 'far)
  5028. (not (org-deadline-close (match-string 1))))
  5029. ((eq org-agenda-todo-ignore-deadlines 'future)
  5030. (> (org-time-stamp-to-now
  5031. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5032. ((eq org-agenda-todo-ignore-deadlines 'past)
  5033. (<= (org-time-stamp-to-now
  5034. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5035. ((numberp org-agenda-todo-ignore-deadlines)
  5036. (org-agenda-todo-custom-ignore-p
  5037. (match-string 1) org-agenda-todo-ignore-deadlines))
  5038. (t (org-deadline-close (match-string 1)))))
  5039. (and org-agenda-todo-ignore-timestamp
  5040. (let ((buffer (current-buffer))
  5041. (regexp
  5042. (concat
  5043. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5044. (start (point)))
  5045. ;; Copy current buffer into a temporary one
  5046. (with-temp-buffer
  5047. (insert-buffer-substring buffer start end)
  5048. (goto-char (point-min))
  5049. ;; Delete SCHEDULED and DEADLINE items
  5050. (while (re-search-forward regexp end t)
  5051. (delete-region (match-beginning 0) (match-end 0)))
  5052. (goto-char (point-min))
  5053. ;; No search for timestamp left
  5054. (when (re-search-forward org-ts-regexp nil t)
  5055. (cond
  5056. ((eq org-agenda-todo-ignore-timestamp 'future)
  5057. (> (org-time-stamp-to-now
  5058. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5059. ((eq org-agenda-todo-ignore-timestamp 'past)
  5060. (<= (org-time-stamp-to-now
  5061. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5062. ((numberp org-agenda-todo-ignore-timestamp)
  5063. (org-agenda-todo-custom-ignore-p
  5064. (match-string 1) org-agenda-todo-ignore-timestamp))
  5065. (t))))))))))
  5066. (defun org-agenda-get-timestamps (&optional deadline-results)
  5067. "Return the date stamp information for agenda display."
  5068. (let* ((props (list 'face 'org-agenda-calendar-event
  5069. 'org-not-done-regexp org-not-done-regexp
  5070. 'org-todo-regexp org-todo-regexp
  5071. 'org-complex-heading-regexp org-complex-heading-regexp
  5072. 'mouse-face 'highlight
  5073. 'help-echo
  5074. (format "mouse-2 or RET jump to org file %s"
  5075. (abbreviate-file-name buffer-file-name))))
  5076. (d1 (calendar-absolute-from-gregorian date))
  5077. mm
  5078. (deadline-position-alist
  5079. (mapcar (lambda (a) (and (setq mm (get-text-property
  5080. 0 'org-hd-marker a))
  5081. (cons (marker-position mm) a)))
  5082. deadline-results))
  5083. (remove-re org-ts-regexp)
  5084. (regexp
  5085. (concat
  5086. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5087. (regexp-quote
  5088. (substring
  5089. (format-time-string
  5090. (car org-time-stamp-formats)
  5091. (apply 'encode-time ; DATE bound by calendar
  5092. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5093. 1 11))
  5094. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5095. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5096. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5097. donep tmp priority category category-pos level ee txt timestr tags
  5098. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5099. inherited-tags ts-date)
  5100. (goto-char (point-min))
  5101. (while (setq end-of-match (re-search-forward regexp nil t))
  5102. (setq b0 (match-beginning 0)
  5103. b3 (match-beginning 3) e3 (match-end 3)
  5104. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5105. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5106. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5107. (member todo-state
  5108. org-agenda-repeating-timestamp-show-all)))
  5109. (catch :skip
  5110. (and (org-at-date-range-p) (throw :skip nil))
  5111. (org-agenda-skip)
  5112. (if (and (match-end 1)
  5113. (not (= d1 (org-time-string-to-absolute
  5114. (match-string 1) d1 nil show-all
  5115. (current-buffer) b0))))
  5116. (throw :skip nil))
  5117. (if (and e3
  5118. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5119. (throw :skip nil))
  5120. (setq tmp (buffer-substring (max (point-min)
  5121. (- b0 org-ds-keyword-length))
  5122. b0)
  5123. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5124. inactivep (= (char-after b0) ?\[)
  5125. deadlinep (string-match org-deadline-regexp tmp)
  5126. scheduledp (string-match org-scheduled-regexp tmp)
  5127. closedp (and org-agenda-include-inactive-timestamps
  5128. (string-match org-closed-string tmp))
  5129. clockp (and org-agenda-include-inactive-timestamps
  5130. (or (string-match org-clock-string tmp)
  5131. (string-match "]-+\\'" tmp)))
  5132. warntime (get-text-property (point) 'org-appt-warntime)
  5133. donep (member todo-state org-done-keywords))
  5134. (if (or scheduledp deadlinep closedp clockp
  5135. (and donep org-agenda-skip-timestamp-if-done))
  5136. (throw :skip t))
  5137. (if (string-match ">" timestr)
  5138. ;; substring should only run to end of time stamp
  5139. (setq timestr (substring timestr 0 (match-end 0))))
  5140. (setq marker (org-agenda-new-marker b0)
  5141. category (org-get-category b0)
  5142. category-pos (get-text-property b0 'org-category-position))
  5143. (save-excursion
  5144. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5145. (throw :skip nil)
  5146. (goto-char (match-beginning 0))
  5147. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5148. (assoc (point) deadline-position-alist))
  5149. (throw :skip nil))
  5150. (setq hdmarker (org-agenda-new-marker)
  5151. inherited-tags
  5152. (or (eq org-agenda-show-inherited-tags 'always)
  5153. (and (listp org-agenda-show-inherited-tags)
  5154. (memq 'agenda org-agenda-show-inherited-tags))
  5155. (and (eq org-agenda-show-inherited-tags t)
  5156. (or (eq org-agenda-use-tag-inheritance t)
  5157. (memq 'agenda org-agenda-use-tag-inheritance))))
  5158. tags (org-get-tags-at nil (not inherited-tags))
  5159. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5160. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5161. (setq head (or (match-string 1) ""))
  5162. (setq txt (org-agenda-format-item
  5163. (if inactivep org-agenda-inactive-leader nil)
  5164. head level category tags timestr
  5165. remove-re habitp)))
  5166. (setq priority (org-get-priority txt))
  5167. (org-add-props txt props 'priority priority
  5168. 'org-marker marker 'org-hd-marker hdmarker
  5169. 'org-category category 'date date
  5170. 'level level
  5171. 'ts-date
  5172. (ignore-errors (org-time-string-to-absolute timestr))
  5173. 'org-category-position category-pos
  5174. 'todo-state todo-state
  5175. 'warntime warntime
  5176. 'type "timestamp")
  5177. (push txt ee))
  5178. (if org-agenda-skip-additional-timestamps-same-entry
  5179. (outline-next-heading)
  5180. (goto-char end-of-match))))
  5181. (nreverse ee)))
  5182. (defun org-agenda-get-sexps ()
  5183. "Return the sexp information for agenda display."
  5184. (require 'diary-lib)
  5185. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5186. 'mouse-face 'highlight
  5187. 'help-echo
  5188. (format "mouse-2 or RET jump to org file %s"
  5189. (abbreviate-file-name buffer-file-name))))
  5190. (regexp "^&?%%(")
  5191. marker category extra category-pos level ee txt tags entry
  5192. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5193. (goto-char (point-min))
  5194. (while (re-search-forward regexp nil t)
  5195. (catch :skip
  5196. (org-agenda-skip)
  5197. (setq beg (match-beginning 0))
  5198. (goto-char (1- (match-end 0)))
  5199. (setq b (point))
  5200. (forward-sexp 1)
  5201. (setq sexp (buffer-substring b (point)))
  5202. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5203. (org-trim (match-string 1))
  5204. ""))
  5205. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5206. (when result
  5207. (setq marker (org-agenda-new-marker beg)
  5208. level (make-string (org-reduced-level (org-outline-level)) ? )
  5209. category (org-get-category beg)
  5210. category-pos (get-text-property beg 'org-category-position)
  5211. inherited-tags
  5212. (or (eq org-agenda-show-inherited-tags 'always)
  5213. (and (listp org-agenda-show-inherited-tags)
  5214. (memq 'agenda org-agenda-show-inherited-tags))
  5215. (and (eq org-agenda-show-inherited-tags t)
  5216. (or (eq org-agenda-use-tag-inheritance t)
  5217. (memq 'agenda org-agenda-use-tag-inheritance))))
  5218. tags (org-get-tags-at nil (not inherited-tags))
  5219. todo-state (org-get-todo-state)
  5220. warntime (get-text-property (point) 'org-appt-warntime)
  5221. extra nil)
  5222. (dolist (r (if (stringp result)
  5223. (list result)
  5224. result)) ;; we expect a list here
  5225. (when (and org-agenda-diary-sexp-prefix
  5226. (string-match org-agenda-diary-sexp-prefix r))
  5227. (setq extra (match-string 0 r)
  5228. r (replace-match "" nil nil r)))
  5229. (if (string-match "\\S-" r)
  5230. (setq txt r)
  5231. (setq txt "SEXP entry returned empty string"))
  5232. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5233. (org-add-props txt props 'org-marker marker
  5234. 'org-category category 'date date 'todo-state todo-state
  5235. 'org-category-position category-pos 'tags tags
  5236. 'level level
  5237. 'type "sexp" 'warntime warntime)
  5238. (push txt ee)))))
  5239. (nreverse ee)))
  5240. ;; Calendar sanity: define some functions that are independent of
  5241. ;; `calendar-date-style'.
  5242. ;; Normally I would like to use ISO format when calling the diary functions,
  5243. ;; but to make sure we still have Emacs 22 compatibility we bind
  5244. ;; also `european-calendar-style' and use european format
  5245. (defun org-anniversary (year month day &optional mark)
  5246. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5247. (org-no-warnings
  5248. (let ((calendar-date-style 'european) (european-calendar-style t))
  5249. (diary-anniversary day month year mark))))
  5250. (defun org-cyclic (N year month day &optional mark)
  5251. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5252. (org-no-warnings
  5253. (let ((calendar-date-style 'european) (european-calendar-style t))
  5254. (diary-cyclic N day month year mark))))
  5255. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5256. "Like `diary-block', but with fixed (ISO) order of arguments."
  5257. (org-no-warnings
  5258. (let ((calendar-date-style 'european) (european-calendar-style t))
  5259. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5260. (defun org-date (year month day &optional mark)
  5261. "Like `diary-date', but with fixed (ISO) order of arguments."
  5262. (org-no-warnings
  5263. (let ((calendar-date-style 'european) (european-calendar-style t))
  5264. (diary-date day month year mark))))
  5265. ;; Define the` org-class' function
  5266. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5267. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5268. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5269. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5270. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5271. `holidays', then any date that is known by the Emacs calendar to be a
  5272. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5273. then those holidays will be skipped."
  5274. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5275. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5276. (d (calendar-absolute-from-gregorian date))
  5277. (h (when skip-weeks (calendar-check-holidays date))))
  5278. (and
  5279. (<= date1 d)
  5280. (<= d date2)
  5281. (= (calendar-day-of-week date) dayname)
  5282. (or (not skip-weeks)
  5283. (progn
  5284. (require 'cal-iso)
  5285. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5286. (not (or (and h (memq 'holidays skip-weeks))
  5287. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5288. entry)))
  5289. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5290. "Like `org-class', but honor `calendar-date-style'.
  5291. The order of the first 2 times 3 arguments depends on the variable
  5292. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5293. So for American calendars, give this as MONTH DAY YEAR, for European as
  5294. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5295. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5296. is any number of ISO weeks in the block period for which the item should
  5297. be skipped.
  5298. This function is here only for backward compatibility and it is deprecated,
  5299. please use `org-class' instead."
  5300. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5301. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5302. (org-class
  5303. (nth 2 date1) (car date1) (nth 1 date1)
  5304. (nth 2 date2) (car date2) (nth 1 date2)
  5305. dayname skip-weeks)))
  5306. (make-obsolete 'org-diary-class 'org-class "")
  5307. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5308. (defalias 'org-get-closed 'org-agenda-get-progress)
  5309. (defun org-agenda-get-progress ()
  5310. "Return the logged TODO entries for agenda display."
  5311. (let* ((props (list 'mouse-face 'highlight
  5312. 'org-not-done-regexp org-not-done-regexp
  5313. 'org-todo-regexp org-todo-regexp
  5314. 'org-complex-heading-regexp org-complex-heading-regexp
  5315. 'help-echo
  5316. (format "mouse-2 or RET jump to org file %s"
  5317. (abbreviate-file-name buffer-file-name))))
  5318. (items (if (consp org-agenda-show-log-scoped)
  5319. org-agenda-show-log-scoped
  5320. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5321. '(clock)
  5322. org-agenda-log-mode-items)))
  5323. (parts
  5324. (delq nil
  5325. (list
  5326. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5327. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5328. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5329. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5330. (error "`org-agenda-log-mode-items' is empty")))
  5331. (regexp (concat
  5332. "\\(" parts-re "\\)"
  5333. " *\\["
  5334. (regexp-quote
  5335. (substring
  5336. (format-time-string
  5337. (car org-time-stamp-formats)
  5338. (apply 'encode-time ; DATE bound by calendar
  5339. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5340. 1 11))))
  5341. (org-agenda-search-headline-for-time nil)
  5342. marker hdmarker priority category category-pos level tags closedp
  5343. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5344. (goto-char (point-min))
  5345. (while (re-search-forward regexp nil t)
  5346. (catch :skip
  5347. (org-agenda-skip)
  5348. (setq marker (org-agenda-new-marker (match-beginning 0))
  5349. closedp (equal (match-string 1) org-closed-string)
  5350. statep (equal (string-to-char (match-string 1)) ?-)
  5351. clockp (not (or closedp statep))
  5352. state (and statep (match-string 2))
  5353. category (org-get-category (match-beginning 0))
  5354. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5355. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5356. (when (string-match "\\]" timestr)
  5357. ;; substring should only run to end of time stamp
  5358. (setq rest (substring timestr (match-end 0))
  5359. timestr (substring timestr 0 (match-end 0)))
  5360. (if (and (not closedp) (not statep)
  5361. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5362. rest))
  5363. (progn (setq timestr (concat (substring timestr 0 -1)
  5364. "-" (match-string 1 rest) "]"))
  5365. (setq clocked (match-string 2 rest)))
  5366. (setq clocked "-")))
  5367. (save-excursion
  5368. (setq extra
  5369. (cond
  5370. ((not org-agenda-log-mode-add-notes) nil)
  5371. (statep
  5372. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5373. (match-string 1)))
  5374. (clockp
  5375. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5376. (match-string 1)))))
  5377. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5378. (throw :skip nil)
  5379. (goto-char (match-beginning 0))
  5380. (setq hdmarker (org-agenda-new-marker)
  5381. inherited-tags
  5382. (or (eq org-agenda-show-inherited-tags 'always)
  5383. (and (listp org-agenda-show-inherited-tags)
  5384. (memq 'todo org-agenda-show-inherited-tags))
  5385. (and (eq org-agenda-show-inherited-tags t)
  5386. (or (eq org-agenda-use-tag-inheritance t)
  5387. (memq 'todo org-agenda-use-tag-inheritance))))
  5388. tags (org-get-tags-at nil (not inherited-tags))
  5389. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5390. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5391. (setq txt (match-string 1))
  5392. (when extra
  5393. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5394. (setq txt (concat (substring txt 0 (match-beginning 1))
  5395. " - " extra " " (match-string 2 txt)))
  5396. (setq txt (concat txt " - " extra))))
  5397. (setq txt (org-agenda-format-item
  5398. (cond
  5399. (closedp "Closed: ")
  5400. (statep (concat "State: (" state ")"))
  5401. (t (concat "Clocked: (" clocked ")")))
  5402. txt level category tags timestr)))
  5403. (setq priority 100000)
  5404. (org-add-props txt props
  5405. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5406. 'priority priority 'org-category category
  5407. 'org-category-position category-pos
  5408. 'level level
  5409. 'type "closed" 'date date
  5410. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5411. (push txt ee))
  5412. (goto-char (point-at-eol))))
  5413. (nreverse ee)))
  5414. (defun org-agenda-show-clocking-issues ()
  5415. "Add overlays, showing issues with clocking.
  5416. See also the user option `org-agenda-clock-consistency-checks'."
  5417. (interactive)
  5418. (let* ((org-time-clocksum-use-effort-durations nil)
  5419. (pl org-agenda-clock-consistency-checks)
  5420. (re (concat "^[ \t]*"
  5421. org-clock-string
  5422. "[ \t]+"
  5423. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5424. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5425. (tlstart 0.)
  5426. (tlend 0.)
  5427. (maxtime (org-hh:mm-string-to-minutes
  5428. (or (plist-get pl :max-duration) "24:00")))
  5429. (mintime (org-hh:mm-string-to-minutes
  5430. (or (plist-get pl :min-duration) 0)))
  5431. (maxgap (org-hh:mm-string-to-minutes
  5432. ;; default 30:00 means never complain
  5433. (or (plist-get pl :max-gap) "30:00")))
  5434. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5435. (plist-get pl :gap-ok-around)))
  5436. (def-face (or (plist-get pl :default-face)
  5437. '((:background "DarkRed") (:foreground "white"))))
  5438. issue face m te ts dt ov)
  5439. (goto-char (point-min))
  5440. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5441. (setq issue nil face def-face)
  5442. (catch 'next
  5443. (setq m (org-get-at-bol 'org-marker)
  5444. te nil ts nil)
  5445. (unless (and m (markerp m))
  5446. (setq issue "No valid clock line") (throw 'next t))
  5447. (org-with-point-at m
  5448. (save-excursion
  5449. (goto-char (point-at-bol))
  5450. (unless (looking-at re)
  5451. (error "No valid Clock line")
  5452. (throw 'next t))
  5453. (unless (match-end 3)
  5454. (setq issue "No end time"
  5455. face (or (plist-get pl :no-end-time-face) face))
  5456. (throw 'next t))
  5457. (setq ts (match-string 1)
  5458. te (match-string 3)
  5459. ts (org-float-time
  5460. (apply 'encode-time (org-parse-time-string ts)))
  5461. te (org-float-time
  5462. (apply 'encode-time (org-parse-time-string te)))
  5463. dt (- te ts))))
  5464. (cond
  5465. ((> dt (* 60 maxtime))
  5466. ;; a very long clocking chunk
  5467. (setq issue (format "Clocking interval is very long: %s"
  5468. (org-minutes-to-clocksum-string
  5469. (floor (/ (float dt) 60.))))
  5470. face (or (plist-get pl :long-face) face)))
  5471. ((< dt (* 60 mintime))
  5472. ;; a very short clocking chunk
  5473. (setq issue (format "Clocking interval is very short: %s"
  5474. (org-minutes-to-clocksum-string
  5475. (floor (/ (float dt) 60.))))
  5476. face (or (plist-get pl :short-face) face)))
  5477. ((and (> tlend 0) (< ts tlend))
  5478. ;; Two clock entries are overlapping
  5479. (setq issue (format "Clocking overlap: %d minutes"
  5480. (/ (- tlend ts) 60))
  5481. face (or (plist-get pl :overlap-face) face)))
  5482. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5483. ;; There is a gap, lets see if we need to report it
  5484. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5485. (setq issue (format "Clocking gap: %d minutes"
  5486. (/ (- ts tlend) 60))
  5487. face (or (plist-get pl :gap-face) face))))
  5488. (t nil)))
  5489. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5490. (when issue
  5491. ;; OK, there was some issue, add an overlay to show the issue
  5492. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5493. (overlay-put ov 'before-string
  5494. (concat
  5495. (org-add-props
  5496. (format "%-43s" (concat " " issue))
  5497. nil
  5498. 'face face)
  5499. "\n"))
  5500. (overlay-put ov 'evaporate t)))))
  5501. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5502. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5503. (catch 'exit
  5504. (unless ok-list
  5505. ;; there are no OK times for gaps...
  5506. (throw 'exit nil))
  5507. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5508. ;; This is more than 24 hours, so it is OK.
  5509. ;; because we have at least one OK time, that must be in the
  5510. ;; 24 hour interval.
  5511. (throw 'exit t))
  5512. ;; We have a shorter gap.
  5513. ;; Now we have to get the minute of the day when these times are
  5514. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5515. (t2dec (decode-time (seconds-to-time t2)))
  5516. ;; compute the minute on the day
  5517. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5518. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5519. (when (< min2 min1)
  5520. ;; if min2 is smaller than min1, this means it is on the next day.
  5521. ;; Wrap it to after midnight.
  5522. (setq min2 (+ min2 1440)))
  5523. ;; Now check if any of the OK times is in the gap
  5524. (mapc (lambda (x)
  5525. ;; Wrap the time to after midnight if necessary
  5526. (if (< x min1) (setq x (+ x 1440)))
  5527. ;; Check if in interval
  5528. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5529. ok-list)
  5530. ;; Nope, this gap is not OK
  5531. nil)))
  5532. (defun org-agenda-get-deadlines (&optional with-hour)
  5533. "Return the deadline information for agenda display.
  5534. When WITH-HOUR is non-nil, only return deadlines with an hour
  5535. specification like [h]h:mm."
  5536. (let* ((props (list 'mouse-face 'highlight
  5537. '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. 'help-echo
  5541. (format "mouse-2 or RET jump to org file %s"
  5542. (abbreviate-file-name buffer-file-name))))
  5543. (regexp (if with-hour
  5544. org-deadline-time-hour-regexp
  5545. org-deadline-time-regexp))
  5546. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5547. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5548. (dl0 (car org-agenda-deadline-leaders))
  5549. (dl1 (nth 1 org-agenda-deadline-leaders))
  5550. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5551. d2 diff dfrac wdays pos pos1 category category-pos level
  5552. tags suppress-prewarning ee txt head face s todo-state
  5553. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5554. (goto-char (point-min))
  5555. (while (re-search-forward regexp nil t)
  5556. (catch :skip
  5557. (org-agenda-skip)
  5558. (setq s (match-string 1)
  5559. txt nil
  5560. pos (1- (match-beginning 1))
  5561. todo-state (save-match-data (org-get-todo-state))
  5562. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5563. (member todo-state
  5564. org-agenda-repeating-timestamp-show-all))
  5565. d2 (org-time-string-to-absolute
  5566. s d1 'past show-all (current-buffer) pos)
  5567. diff (- d2 d1))
  5568. (setq suppress-prewarning
  5569. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5570. (let ((item (buffer-substring (point-at-bol)
  5571. (point-at-eol))))
  5572. (save-match-data
  5573. (and (string-match
  5574. org-scheduled-time-regexp item)
  5575. (match-string 1 item)))))))
  5576. (cond
  5577. ((not ds) nil)
  5578. ;; The current item has a scheduled date (in ds), so
  5579. ;; evaluate its prewarning lead time.
  5580. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5581. ;; Use global prewarning-restart lead time.
  5582. org-agenda-skip-deadline-prewarning-if-scheduled)
  5583. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5584. 'pre-scheduled)
  5585. ;; Set prewarning to no earlier than scheduled.
  5586. (min (- d2 (org-time-string-to-absolute
  5587. ds d1 'past show-all (current-buffer) pos))
  5588. org-deadline-warning-days))
  5589. ;; Set prewarning to deadline.
  5590. (t 0))))
  5591. (setq wdays (if suppress-prewarning
  5592. (let ((org-deadline-warning-days suppress-prewarning))
  5593. (org-get-wdays s))
  5594. (org-get-wdays s))
  5595. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5596. upcomingp (and todayp (> diff 0)))
  5597. ;; When to show a deadline in the calendar:
  5598. ;; If the expiration is within wdays warning time.
  5599. ;; Past-due deadlines are only shown on the current date
  5600. (if (and (or (and (<= diff wdays)
  5601. (and todayp (not org-agenda-only-exact-dates)))
  5602. (= diff 0)))
  5603. (save-excursion
  5604. ;; (setq todo-state (org-get-todo-state))
  5605. (setq donep (member todo-state org-done-keywords))
  5606. (if (and donep
  5607. (or org-agenda-skip-deadline-if-done
  5608. (not (= diff 0))))
  5609. (setq txt nil)
  5610. (setq category (org-get-category)
  5611. warntime (get-text-property (point) 'org-appt-warntime)
  5612. category-pos (get-text-property (point) 'org-category-position))
  5613. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5614. (throw :skip nil)
  5615. (goto-char (match-end 0))
  5616. (setq pos1 (match-beginning 0))
  5617. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5618. (setq inherited-tags
  5619. (or (eq org-agenda-show-inherited-tags 'always)
  5620. (and (listp org-agenda-show-inherited-tags)
  5621. (memq 'agenda org-agenda-show-inherited-tags))
  5622. (and (eq org-agenda-show-inherited-tags t)
  5623. (or (eq org-agenda-use-tag-inheritance t)
  5624. (memq 'agenda org-agenda-use-tag-inheritance))))
  5625. tags (org-get-tags-at pos1 (not inherited-tags)))
  5626. (setq head (buffer-substring
  5627. (point)
  5628. (progn (skip-chars-forward "^\r\n")
  5629. (point))))
  5630. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5631. (setq timestr
  5632. (concat (substring s (match-beginning 1)) " "))
  5633. (setq timestr 'time))
  5634. (setq txt (org-agenda-format-item
  5635. (cond ((= diff 0) dl0)
  5636. ((> diff 0)
  5637. (if (functionp dl1)
  5638. (funcall dl1 diff date)
  5639. (format dl1 diff)))
  5640. (t
  5641. (if (functionp dl2)
  5642. (funcall dl2 diff date)
  5643. (format dl2 (if (string= dl2 dl1)
  5644. diff (abs diff))))))
  5645. head level category tags
  5646. (if (not (= diff 0)) nil timestr)))))
  5647. (when txt
  5648. (setq face (org-agenda-deadline-face dfrac))
  5649. (org-add-props txt props
  5650. 'org-marker (org-agenda-new-marker pos)
  5651. 'warntime warntime
  5652. 'level level
  5653. 'ts-date d2
  5654. 'org-hd-marker (org-agenda-new-marker pos1)
  5655. 'priority (+ (- diff)
  5656. (org-get-priority txt))
  5657. 'org-category category
  5658. 'org-category-position category-pos
  5659. 'todo-state todo-state
  5660. 'type (if upcomingp "upcoming-deadline" "deadline")
  5661. 'date (if upcomingp date d2)
  5662. 'face (if donep 'org-agenda-done face)
  5663. 'undone-face face 'done-face 'org-agenda-done)
  5664. (push txt ee))))))
  5665. (nreverse ee)))
  5666. (defun org-agenda-deadline-face (fraction)
  5667. "Return the face to displaying a deadline item.
  5668. FRACTION is what fraction of the head-warning time has passed."
  5669. (let ((faces org-agenda-deadline-faces) f)
  5670. (catch 'exit
  5671. (while (setq f (pop faces))
  5672. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5673. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5674. "Return the scheduled information for agenda display.
  5675. When WITH-HOUR is non-nil, only return scheduled items with
  5676. an hour specification like [h]h:mm."
  5677. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5678. 'org-todo-regexp org-todo-regexp
  5679. 'org-complex-heading-regexp org-complex-heading-regexp
  5680. 'done-face 'org-agenda-done
  5681. 'mouse-face 'highlight
  5682. 'help-echo
  5683. (format "mouse-2 or RET jump to org file %s"
  5684. (abbreviate-file-name buffer-file-name))))
  5685. (regexp (if with-hour
  5686. org-scheduled-time-hour-regexp
  5687. org-scheduled-time-regexp))
  5688. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5689. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5690. mm
  5691. (deadline-position-alist
  5692. (mapcar (lambda (a) (and (setq mm (get-text-property
  5693. 0 'org-hd-marker a))
  5694. (cons (marker-position mm) a)))
  5695. deadline-results))
  5696. d2 diff pos pos1 category category-pos level tags donep
  5697. ee txt head pastschedp todo-state face timestr s habitp show-all
  5698. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5699. ddays)
  5700. (goto-char (point-min))
  5701. (while (re-search-forward regexp nil t)
  5702. (catch :skip
  5703. (org-agenda-skip)
  5704. (setq s (match-string 1)
  5705. txt nil
  5706. pos (1- (match-beginning 1))
  5707. todo-state (save-match-data (org-get-todo-state))
  5708. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5709. (member todo-state
  5710. org-agenda-repeating-timestamp-show-all))
  5711. d2 (org-time-string-to-absolute
  5712. s d1 'past show-all (current-buffer) pos)
  5713. diff (- d2 d1)
  5714. warntime (get-text-property (point) 'org-appt-warntime))
  5715. (setq pastschedp (and todayp (< diff 0)))
  5716. (setq did-habit-check-p nil)
  5717. (setq suppress-delay
  5718. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5719. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5720. (save-match-data
  5721. (and (string-match
  5722. org-deadline-time-regexp item)
  5723. (match-string 1 item)))))))
  5724. (cond
  5725. ((not ds) nil)
  5726. ;; The current item has a deadline date (in ds), so
  5727. ;; evaluate its delay time.
  5728. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5729. ;; Use global delay time.
  5730. (- org-agenda-skip-scheduled-delay-if-deadline))
  5731. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5732. 'post-deadline)
  5733. ;; Set delay to no later than deadline.
  5734. (min (- d2 (org-time-string-to-absolute
  5735. ds d1 'past show-all (current-buffer) pos))
  5736. org-scheduled-delay-days))
  5737. (t 0))))
  5738. (setq ddays (if suppress-delay
  5739. (let ((org-scheduled-delay-days suppress-delay))
  5740. (org-get-wdays s t t))
  5741. (org-get-wdays s t)))
  5742. ;; Use a delay of 0 when there is a repeater and the delay is
  5743. ;; of the form --3d
  5744. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5745. (< (org-time-string-to-absolute s)
  5746. (org-time-string-to-absolute
  5747. s d2 'past nil (current-buffer) pos)))
  5748. (setq ddays 0))
  5749. ;; When to show a scheduled item in the calendar:
  5750. ;; If it is on or past the date.
  5751. (when (or (and (> ddays 0) (= diff (- ddays)))
  5752. (and (zerop ddays) (= diff 0))
  5753. (and (< (+ diff ddays) 0)
  5754. (< (abs diff) org-scheduled-past-days)
  5755. (and todayp (not org-agenda-only-exact-dates)))
  5756. ;; org-is-habit-p uses org-entry-get, which is expansive
  5757. ;; so we go extra mile to only call it once
  5758. (and todayp
  5759. (boundp 'org-habit-show-all-today)
  5760. org-habit-show-all-today
  5761. (setq did-habit-check-p t)
  5762. (setq habitp (and (functionp 'org-is-habit-p)
  5763. (org-is-habit-p)))))
  5764. (save-excursion
  5765. (setq donep (member todo-state org-done-keywords))
  5766. (if (and donep
  5767. (or org-agenda-skip-scheduled-if-done
  5768. (not (= diff 0))
  5769. (and (functionp 'org-is-habit-p)
  5770. (org-is-habit-p))))
  5771. (setq txt nil)
  5772. (setq habitp (if did-habit-check-p habitp
  5773. (and (functionp 'org-is-habit-p)
  5774. (org-is-habit-p))))
  5775. (setq category (org-get-category)
  5776. category-pos (get-text-property (point) 'org-category-position))
  5777. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5778. 'repeated-after-deadline)
  5779. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5780. (throw :skip nil))
  5781. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5782. (throw :skip nil)
  5783. (goto-char (match-end 0))
  5784. (setq pos1 (match-beginning 0))
  5785. (if habitp
  5786. (if (or (not org-habit-show-habits)
  5787. (and (not todayp)
  5788. (boundp 'org-habit-show-habits-only-for-today)
  5789. org-habit-show-habits-only-for-today))
  5790. (throw :skip nil))
  5791. (if (and
  5792. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5793. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5794. pastschedp))
  5795. (setq mm (assoc pos1 deadline-position-alist)))
  5796. (throw :skip nil)))
  5797. (setq inherited-tags
  5798. (or (eq org-agenda-show-inherited-tags 'always)
  5799. (and (listp org-agenda-show-inherited-tags)
  5800. (memq 'agenda org-agenda-show-inherited-tags))
  5801. (and (eq org-agenda-show-inherited-tags t)
  5802. (or (eq org-agenda-use-tag-inheritance t)
  5803. (memq 'agenda org-agenda-use-tag-inheritance))))
  5804. tags (org-get-tags-at nil (not inherited-tags)))
  5805. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5806. (setq head (buffer-substring
  5807. (point)
  5808. (progn (skip-chars-forward "^\r\n") (point))))
  5809. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5810. (setq timestr
  5811. (concat (substring s (match-beginning 1)) " "))
  5812. (setq timestr 'time))
  5813. (setq txt (org-agenda-format-item
  5814. (if (= diff 0)
  5815. (car org-agenda-scheduled-leaders)
  5816. (format (nth 1 org-agenda-scheduled-leaders)
  5817. (- 1 diff)))
  5818. head level category tags
  5819. (if (not (= diff 0)) nil timestr)
  5820. nil habitp))))
  5821. (when txt
  5822. (setq face
  5823. (cond
  5824. ((and (not habitp) pastschedp)
  5825. 'org-scheduled-previously)
  5826. (todayp 'org-scheduled-today)
  5827. (t 'org-scheduled))
  5828. habitp (and habitp (org-habit-parse-todo)))
  5829. (org-add-props txt props
  5830. 'undone-face face
  5831. 'face (if donep 'org-agenda-done face)
  5832. 'org-marker (org-agenda-new-marker pos)
  5833. 'org-hd-marker (org-agenda-new-marker pos1)
  5834. 'type (if pastschedp "past-scheduled" "scheduled")
  5835. 'date (if pastschedp d2 date)
  5836. 'ts-date d2
  5837. 'warntime warntime
  5838. 'level level
  5839. 'priority (if habitp
  5840. (org-habit-get-priority habitp)
  5841. (+ 94 (- 5 diff) (org-get-priority txt)))
  5842. 'org-category category
  5843. 'category-position category-pos
  5844. 'org-habit-p habitp
  5845. 'todo-state todo-state)
  5846. (push txt ee))))))
  5847. (nreverse ee)))
  5848. (defun org-agenda-get-blocks ()
  5849. "Return the date-range information for agenda display."
  5850. (let* ((props (list 'face nil
  5851. 'org-not-done-regexp org-not-done-regexp
  5852. 'org-todo-regexp org-todo-regexp
  5853. 'org-complex-heading-regexp org-complex-heading-regexp
  5854. 'mouse-face 'highlight
  5855. 'help-echo
  5856. (format "mouse-2 or RET jump to org file %s"
  5857. (abbreviate-file-name buffer-file-name))))
  5858. (regexp org-tr-regexp)
  5859. (d0 (calendar-absolute-from-gregorian date))
  5860. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5861. level todo-state tags pos head donep inherited-tags)
  5862. (goto-char (point-min))
  5863. (while (re-search-forward regexp nil t)
  5864. (catch :skip
  5865. (org-agenda-skip)
  5866. (setq pos (point))
  5867. (let ((start-time (match-string 1))
  5868. (end-time (match-string 2)))
  5869. (setq s1 (match-string 1)
  5870. s2 (match-string 2)
  5871. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5872. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5873. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5874. ;; Only allow days between the limits, because the normal
  5875. ;; date stamps will catch the limits.
  5876. (save-excursion
  5877. (setq todo-state (org-get-todo-state))
  5878. (setq donep (member todo-state org-done-keywords))
  5879. (if (and donep org-agenda-skip-timestamp-if-done)
  5880. (throw :skip t))
  5881. (setq marker (org-agenda-new-marker (point)))
  5882. (setq category (org-get-category)
  5883. category-pos (get-text-property (point) 'org-category-position))
  5884. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5885. (throw :skip nil)
  5886. (goto-char (match-beginning 0))
  5887. (setq hdmarker (org-agenda-new-marker (point))
  5888. inherited-tags
  5889. (or (eq org-agenda-show-inherited-tags 'always)
  5890. (and (listp org-agenda-show-inherited-tags)
  5891. (memq 'agenda org-agenda-show-inherited-tags))
  5892. (and (eq org-agenda-show-inherited-tags t)
  5893. (or (eq org-agenda-use-tag-inheritance t)
  5894. (memq 'agenda org-agenda-use-tag-inheritance))))
  5895. tags (org-get-tags-at nil (not inherited-tags)))
  5896. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5897. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5898. (setq head (match-string 1))
  5899. (let ((remove-re
  5900. (if org-agenda-remove-timeranges-from-blocks
  5901. (concat
  5902. "<" (regexp-quote s1) ".*?>"
  5903. "--"
  5904. "<" (regexp-quote s2) ".*?>")
  5905. nil)))
  5906. (setq txt (org-agenda-format-item
  5907. (format
  5908. (nth (if (= d1 d2) 0 1)
  5909. org-agenda-timerange-leaders)
  5910. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5911. head level category tags
  5912. (cond ((and (= d1 d0) (= d2 d0))
  5913. (concat "<" start-time ">--<" end-time ">"))
  5914. ((= d1 d0)
  5915. (concat "<" start-time ">"))
  5916. ((= d2 d0)
  5917. (concat "<" end-time ">")))
  5918. remove-re))))
  5919. (org-add-props txt props
  5920. 'org-marker marker 'org-hd-marker hdmarker
  5921. 'type "block" 'date date
  5922. 'level level
  5923. 'todo-state todo-state
  5924. 'priority (org-get-priority txt) 'org-category category
  5925. 'org-category-position category-pos)
  5926. (push txt ee))))
  5927. (goto-char pos)))
  5928. ;; Sort the entries by expiration date.
  5929. (nreverse ee)))
  5930. ;;; Agenda presentation and sorting
  5931. (defvar org-prefix-has-time nil
  5932. "A flag, set by `org-compile-prefix-format'.
  5933. The flag is set if the currently compiled format contains a `%t'.")
  5934. (defvar org-prefix-has-tag nil
  5935. "A flag, set by `org-compile-prefix-format'.
  5936. The flag is set if the currently compiled format contains a `%T'.")
  5937. (defvar org-prefix-has-effort nil
  5938. "A flag, set by `org-compile-prefix-format'.
  5939. The flag is set if the currently compiled format contains a `%e'.")
  5940. (defvar org-prefix-has-breadcrumbs nil
  5941. "A flag, set by `org-compile-prefix-format'.
  5942. The flag is set if the currently compiled format contains a `%b'.")
  5943. (defvar org-prefix-category-length nil
  5944. "Used by `org-compile-prefix-format' to remember the category field width.")
  5945. (defvar org-prefix-category-max-length nil
  5946. "Used by `org-compile-prefix-format' to remember the category field width.")
  5947. (defun org-agenda-get-category-icon (category)
  5948. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5949. (dolist (entry org-agenda-category-icon-alist)
  5950. (when (org-string-match-p (car entry) category)
  5951. (if (listp (cadr entry))
  5952. (return (cadr entry))
  5953. (return (apply 'create-image (cdr entry)))))))
  5954. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5955. remove-re habitp)
  5956. "Format TXT to be inserted into the agenda buffer.
  5957. In particular, add the prefix and corresponding text properties.
  5958. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5959. LEVEL may be a string to replace the `%l' specifier.
  5960. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5961. category taken from local variable or file name. It will replace the `%c'
  5962. specifier in the format.
  5963. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5964. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5965. When DOTIME is a string, this string is searched for a time before TXT is.
  5966. TAGS can be the tags of the headline.
  5967. Any match of REMOVE-RE will be removed from TXT."
  5968. ;; We keep the org-prefix-* variable values along with a compiled
  5969. ;; formatter, so that multiple agendas existing at the same time do
  5970. ;; not step on each other toes.
  5971. ;;
  5972. ;; It was inconvenient to make these variables buffer local in
  5973. ;; Agenda buffers, because this function expects to be called with
  5974. ;; the buffer where item comes from being current, and not agenda
  5975. ;; buffer
  5976. (let* ((bindings (car org-prefix-format-compiled))
  5977. (formatter (cadr org-prefix-format-compiled)))
  5978. (loop for (var value) in bindings
  5979. do (set var value))
  5980. (save-match-data
  5981. ;; Diary entries sometimes have extra whitespace at the beginning
  5982. (setq txt (org-trim txt))
  5983. ;; Fix the tags part in txt
  5984. (setq txt (org-agenda-fix-displayed-tags
  5985. txt tags
  5986. org-agenda-show-inherited-tags
  5987. org-agenda-hide-tags-regexp))
  5988. (let* ((category (or category
  5989. (if (stringp org-category)
  5990. org-category
  5991. (and org-category (symbol-name org-category)))
  5992. (if buffer-file-name
  5993. (file-name-sans-extension
  5994. (file-name-nondirectory buffer-file-name))
  5995. "")))
  5996. (category-icon (org-agenda-get-category-icon category))
  5997. (category-icon (if category-icon
  5998. (propertize " " 'display category-icon)
  5999. ""))
  6000. ;; time, tag, effort are needed for the eval of the prefix format
  6001. (tag (if tags (nth (1- (length tags)) tags) ""))
  6002. time effort neffort
  6003. (ts (if dotime (concat
  6004. (if (stringp dotime) dotime "")
  6005. (and org-agenda-search-headline-for-time txt))))
  6006. (time-of-day (and dotime (org-get-time-of-day ts)))
  6007. stamp plain s0 s1 s2 rtn srp l
  6008. duration thecategory breadcrumbs)
  6009. (and (derived-mode-p 'org-mode) buffer-file-name
  6010. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6011. (when (and dotime time-of-day)
  6012. ;; Extract starting and ending time and move them to prefix
  6013. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6014. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6015. (setq s0 (match-string 0 ts)
  6016. srp (and stamp (match-end 3))
  6017. s1 (match-string (if plain 1 2) ts)
  6018. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6019. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6020. ;; them, we might want to remove them there to avoid duplication.
  6021. ;; The user can turn this off with a variable.
  6022. (if (and org-prefix-has-time
  6023. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6024. (string-match (concat (regexp-quote s0) " *") txt)
  6025. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6026. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6027. (= (match-beginning 0) 0)
  6028. t))
  6029. (setq txt (replace-match "" nil nil txt))))
  6030. ;; Normalize the time(s) to 24 hour
  6031. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6032. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6033. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6034. (let (org-time-clocksum-use-effort-durations)
  6035. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6036. (setq s2
  6037. (org-minutes-to-clocksum-string
  6038. (+ (org-hh:mm-string-to-minutes s1)
  6039. org-agenda-default-appointment-duration)))))
  6040. ;; Compute the duration
  6041. (when s2
  6042. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6043. (org-hh:mm-string-to-minutes s1)))))
  6044. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6045. txt)
  6046. ;; Tags are in the string
  6047. (if (or (eq org-agenda-remove-tags t)
  6048. (and org-agenda-remove-tags
  6049. org-prefix-has-tag))
  6050. (setq txt (replace-match "" t t txt))
  6051. (setq txt (replace-match
  6052. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6053. (match-string 2 txt))
  6054. t t txt))))
  6055. (when (derived-mode-p 'org-mode)
  6056. (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
  6057. ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
  6058. ;; current buffer, so move this check outside of above
  6059. (if effort
  6060. (setq neffort (org-duration-string-to-minutes effort)
  6061. effort (setq effort (concat "[" effort "]")))
  6062. ;; prevent erroring out with %e format when there is no effort
  6063. (setq effort ""))
  6064. (when remove-re
  6065. (while (string-match remove-re txt)
  6066. (setq txt (replace-match "" t t txt))))
  6067. ;; Set org-heading property on `txt' to mark the start of the
  6068. ;; heading.
  6069. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6070. ;; Prepare the variables needed in the eval of the compiled format
  6071. (if org-prefix-has-breadcrumbs
  6072. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6073. (let ((s (org-display-outline-path nil nil "->" t)))
  6074. (if (eq "" s) "" (concat s "->"))))))
  6075. (setq time (cond (s2 (concat
  6076. (org-agenda-time-of-day-to-ampm-maybe s1)
  6077. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6078. (if org-agenda-timegrid-use-ampm " ")))
  6079. (s1 (concat
  6080. (org-agenda-time-of-day-to-ampm-maybe s1)
  6081. (if org-agenda-timegrid-use-ampm
  6082. "........ "
  6083. "......")))
  6084. (t ""))
  6085. extra (or (and (not habitp) extra) "")
  6086. category (if (symbolp category) (symbol-name category) category)
  6087. thecategory (copy-sequence category)
  6088. level (or level ""))
  6089. (if (string-match org-bracket-link-regexp category)
  6090. (progn
  6091. (setq l (if (match-end 3)
  6092. (- (match-end 3) (match-beginning 3))
  6093. (- (match-end 1) (match-beginning 1))))
  6094. (when (< l (or org-prefix-category-length 0))
  6095. (setq category (copy-sequence category))
  6096. (org-add-props category nil
  6097. 'extra-space (make-string
  6098. (- org-prefix-category-length l 1) ?\ ))))
  6099. (if (and org-prefix-category-max-length
  6100. (>= (length category) org-prefix-category-max-length))
  6101. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6102. ;; Evaluate the compiled format
  6103. (setq rtn (concat (eval formatter) txt))
  6104. ;; And finally add the text properties
  6105. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6106. (org-add-props rtn nil
  6107. 'org-category (if thecategory (downcase thecategory) category)
  6108. 'tags (mapcar 'org-downcase-keep-props tags)
  6109. 'org-highest-priority org-highest-priority
  6110. 'org-lowest-priority org-lowest-priority
  6111. 'time-of-day time-of-day
  6112. 'duration duration
  6113. 'effort effort
  6114. 'effort-minutes neffort
  6115. 'breadcrumbs breadcrumbs
  6116. 'txt txt
  6117. 'level level
  6118. 'time time
  6119. 'extra extra
  6120. 'format org-prefix-format-compiled
  6121. 'dotime dotime)))))
  6122. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6123. "Remove tags string from TXT, and add a modified list of tags.
  6124. The modified list may contain inherited tags, and tags matched by
  6125. `org-agenda-hide-tags-regexp' will be removed."
  6126. (when (or add-inherited hide-re)
  6127. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6128. (setq txt (substring txt 0 (match-beginning 0))))
  6129. (setq tags
  6130. (delq nil
  6131. (mapcar (lambda (tg)
  6132. (if (or (and hide-re (string-match hide-re tg))
  6133. (and (not add-inherited)
  6134. (get-text-property 0 'inherited tg)))
  6135. nil
  6136. tg))
  6137. tags)))
  6138. (when tags
  6139. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6140. i)
  6141. (setq txt (concat txt " :"
  6142. (mapconcat
  6143. (lambda (x)
  6144. (setq i (get-text-property 0 'inherited x))
  6145. (if (and have-i (not i))
  6146. (progn
  6147. (setq have-i nil)
  6148. (concat ":" x))
  6149. x))
  6150. tags ":")
  6151. (if have-i "::" ":"))))))
  6152. txt)
  6153. (defun org-downcase-keep-props (s)
  6154. (let ((props (text-properties-at 0 s)))
  6155. (setq s (downcase s))
  6156. (add-text-properties 0 (length s) props s)
  6157. s))
  6158. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6159. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6160. "Add a time-grid for agenda items which need it.
  6161. LIST is the list of agenda items formatted by `org-agenda-list'.
  6162. NDAYS is the span of the current agenda view.
  6163. TODAYP is `t' when the current agenda view is on today."
  6164. (catch 'exit
  6165. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6166. ((and todayp (member 'today (car org-agenda-time-grid))))
  6167. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6168. ((member 'weekly (car org-agenda-time-grid)))
  6169. (t (throw 'exit list)))
  6170. (let* ((have (delq nil (mapcar
  6171. (lambda (x) (get-text-property 1 'time-of-day x))
  6172. list)))
  6173. (string (nth 1 org-agenda-time-grid))
  6174. (gridtimes (nth 2 org-agenda-time-grid))
  6175. (req (car org-agenda-time-grid))
  6176. (remove (member 'remove-match req))
  6177. new time)
  6178. (if (and (member 'require-timed req) (not have))
  6179. ;; don't show empty grid
  6180. (throw 'exit list))
  6181. (while (setq time (pop gridtimes))
  6182. (unless (and remove (member time have))
  6183. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6184. (push (org-agenda-format-item
  6185. nil string nil "" nil
  6186. (concat (substring time 0 -2) ":" (substring time -2)))
  6187. new)
  6188. (put-text-property
  6189. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6190. (when (and todayp org-agenda-show-current-time-in-grid)
  6191. (push (org-agenda-format-item
  6192. nil org-agenda-current-time-string nil "" nil
  6193. (format-time-string "%H:%M "))
  6194. new)
  6195. (put-text-property
  6196. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6197. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6198. (append new list)
  6199. (append list new)))))
  6200. (defun org-compile-prefix-format (key)
  6201. "Compile the prefix format into a Lisp form that can be evaluated.
  6202. The resulting form and associated variable bindings is returned
  6203. and stored in the variable `org-prefix-format-compiled'."
  6204. (setq org-prefix-has-time nil
  6205. org-prefix-has-tag nil
  6206. org-prefix-category-length nil
  6207. org-prefix-has-effort nil
  6208. org-prefix-has-breadcrumbs nil)
  6209. (let ((s (cond
  6210. ((stringp org-agenda-prefix-format)
  6211. org-agenda-prefix-format)
  6212. ((assq key org-agenda-prefix-format)
  6213. (cdr (assq key org-agenda-prefix-format)))
  6214. (t " %-12:c%?-12t% s")))
  6215. (start 0)
  6216. varform vars var e c f opt)
  6217. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6218. s start)
  6219. (setq var (or (cdr (assoc (match-string 4 s)
  6220. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6221. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6222. 'eval)
  6223. c (or (match-string 3 s) "")
  6224. opt (match-beginning 1)
  6225. start (1+ (match-beginning 0)))
  6226. (if (equal var 'time) (setq org-prefix-has-time t))
  6227. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6228. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6229. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6230. (setq f (concat "%" (match-string 2 s) "s"))
  6231. (when (equal var 'category)
  6232. (setq org-prefix-category-length
  6233. (floor (abs (string-to-number (match-string 2 s)))))
  6234. (setq org-prefix-category-max-length
  6235. (let ((x (match-string 2 s)))
  6236. (save-match-data
  6237. (if (string-match "\\.[0-9]+" x)
  6238. (string-to-number (substring (match-string 0 x) 1)))))))
  6239. (if (eq var 'eval)
  6240. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6241. (if opt
  6242. (setq varform
  6243. `(if (equal "" ,var)
  6244. ""
  6245. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6246. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6247. (setq s (replace-match "%s" t nil s))
  6248. (push varform vars))
  6249. (setq vars (nreverse vars))
  6250. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6251. (setq org-prefix-format-compiled
  6252. (list
  6253. `((org-prefix-has-time ,org-prefix-has-time)
  6254. (org-prefix-has-tag ,org-prefix-has-tag)
  6255. (org-prefix-category-length ,org-prefix-category-length)
  6256. (org-prefix-has-effort ,org-prefix-has-effort)
  6257. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6258. `(format ,s ,@vars))))))
  6259. (defun org-set-sorting-strategy (key)
  6260. (if (symbolp (car org-agenda-sorting-strategy))
  6261. ;; the old format
  6262. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6263. (setq org-agenda-sorting-strategy-selected
  6264. (or (cdr (assq key org-agenda-sorting-strategy))
  6265. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6266. '(time-up category-keep priority-down)))))
  6267. (defun org-get-time-of-day (s &optional string mod24)
  6268. "Check string S for a time of day.
  6269. If found, return it as a military time number between 0 and 2400.
  6270. If not found, return nil.
  6271. The optional STRING argument forces conversion into a 5 character wide string
  6272. HH:MM."
  6273. (save-match-data
  6274. (when
  6275. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6276. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6277. (let* ((h (string-to-number (match-string 1 s)))
  6278. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6279. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6280. (am-p (equal ampm "am"))
  6281. (h1 (cond ((not ampm) h)
  6282. ((= h 12) (if am-p 0 12))
  6283. (t (+ h (if am-p 0 12)))))
  6284. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6285. (mod h1 24) h1))
  6286. (t0 (+ (* 100 h2) m))
  6287. (t1 (concat (if (>= h1 24) "+" " ")
  6288. (if (and org-agenda-time-leading-zero
  6289. (< t0 1000)) "0" "")
  6290. (if (< t0 100) "0" "")
  6291. (if (< t0 10) "0" "")
  6292. (int-to-string t0))))
  6293. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6294. (defvar org-agenda-before-sorting-filter-function nil
  6295. "Function to be applied to agenda items prior to sorting.
  6296. Prior to sorting also means just before they are inserted into the agenda.
  6297. To aid sorting, you may revisit the original entries and add more text
  6298. properties which will later be used by the sorting functions.
  6299. The function should take a string argument, an agenda line.
  6300. It has access to the text properties in that line, which contain among
  6301. other things, the property `org-hd-marker' that points to the entry
  6302. where the line comes from. Note that not all lines going into the agenda
  6303. have this property, only most.
  6304. The function should return the modified string. It is probably best
  6305. to ONLY change text properties.
  6306. You can also use this function as a filter, by returning nil for lines
  6307. you don't want to have in the agenda at all. For this application, you
  6308. could bind the variable in the options section of a custom command.")
  6309. (defun org-agenda-finalize-entries (list &optional type)
  6310. "Sort, limit and concatenate the LIST of agenda items.
  6311. The optional argument TYPE tells the agenda type."
  6312. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6313. (cdr (assoc type org-agenda-max-effort)))
  6314. (t org-agenda-max-effort)))
  6315. (max-todo (cond ((listp org-agenda-max-todos)
  6316. (cdr (assoc type org-agenda-max-todos)))
  6317. (t org-agenda-max-todos)))
  6318. (max-tags (cond ((listp org-agenda-max-tags)
  6319. (cdr (assoc type org-agenda-max-tags)))
  6320. (t org-agenda-max-tags)))
  6321. (max-entries (cond ((listp org-agenda-max-entries)
  6322. (cdr (assoc type org-agenda-max-entries)))
  6323. (t org-agenda-max-entries))) l)
  6324. (when org-agenda-before-sorting-filter-function
  6325. (setq list
  6326. (delq nil
  6327. (mapcar
  6328. org-agenda-before-sorting-filter-function list))))
  6329. (setq list (mapcar 'org-agenda-highlight-todo list)
  6330. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6331. (when max-effort
  6332. (setq list (org-agenda-limit-entries
  6333. list 'effort-minutes max-effort 'identity)))
  6334. (when max-todo
  6335. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6336. (when max-tags
  6337. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6338. (when max-entries
  6339. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6340. (mapconcat 'identity list "\n")))
  6341. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6342. "Limit the number of agenda entries."
  6343. (let ((include (and limit (< limit 0))))
  6344. (if limit
  6345. (let ((fun (or fn (lambda (p) (if p 1))))
  6346. (lim 0))
  6347. (delq nil
  6348. (mapcar
  6349. (lambda (e)
  6350. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6351. (if pval (setq lim (+ lim pval)))
  6352. (cond ((and pval (<= lim (abs limit))) e)
  6353. ((and include (not pval)) e))))
  6354. list)))
  6355. list)))
  6356. (defun org-agenda-limit-interactively ()
  6357. "In agenda, interactively limit entries to various maximums."
  6358. (interactive)
  6359. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6360. (num (string-to-number (read-from-minibuffer "How many? "))))
  6361. (cond ((equal max ?e)
  6362. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6363. ((equal max ?t)
  6364. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6365. ((equal max ?T)
  6366. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6367. ((equal max ?E)
  6368. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6369. (org-agenda-fit-window-to-buffer))
  6370. (defun org-agenda-highlight-todo (x)
  6371. (let ((org-done-keywords org-done-keywords-for-agenda)
  6372. (case-fold-search nil)
  6373. re)
  6374. (if (eq x 'line)
  6375. (save-excursion
  6376. (beginning-of-line 1)
  6377. (setq re (org-get-at-bol 'org-todo-regexp))
  6378. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6379. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6380. (add-text-properties (match-beginning 0) (match-end 1)
  6381. (list 'face (org-get-todo-face 1)))
  6382. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6383. (delete-region (match-beginning 1) (1- (match-end 0)))
  6384. (goto-char (match-beginning 1))
  6385. (insert (format org-agenda-todo-keyword-format s)))))
  6386. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6387. (setq re (get-text-property 0 'org-todo-regexp x))
  6388. (when (and re
  6389. ;; Test `pl' because if there's no heading content,
  6390. ;; there's no point matching to highlight. Note
  6391. ;; that if we didn't test `pl' first, and there
  6392. ;; happened to be no keyword from `org-todo-regexp'
  6393. ;; on this heading line, then the `equal' comparison
  6394. ;; afterwards would spuriously succeed in the case
  6395. ;; where `pl' is nil -- causing an args-out-of-range
  6396. ;; error when we try to add text properties to text
  6397. ;; that isn't there.
  6398. pl
  6399. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6400. x pl) pl))
  6401. (add-text-properties
  6402. (or (match-end 1) (match-end 0)) (match-end 0)
  6403. (list 'face (org-get-todo-face (match-string 2 x)))
  6404. x)
  6405. (when (match-end 1)
  6406. (setq x (concat (substring x 0 (match-end 1))
  6407. (format org-agenda-todo-keyword-format
  6408. (match-string 2 x))
  6409. (org-add-props " " (text-properties-at 0 x))
  6410. (substring x (match-end 3)))))))
  6411. x)))
  6412. (defsubst org-cmp-priority (a b)
  6413. "Compare the priorities of string A and B."
  6414. (let ((pa (or (get-text-property 1 'priority a) 0))
  6415. (pb (or (get-text-property 1 'priority b) 0)))
  6416. (cond ((> pa pb) +1)
  6417. ((< pa pb) -1))))
  6418. (defsubst org-cmp-effort (a b)
  6419. "Compare the effort values of string A and B."
  6420. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6421. (ea (or (get-text-property 1 'effort-minutes a) def))
  6422. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6423. (cond ((> ea eb) +1)
  6424. ((< ea eb) -1))))
  6425. (defsubst org-cmp-category (a b)
  6426. "Compare the string values of categories of strings A and B."
  6427. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6428. (cb (or (get-text-property 1 'org-category b) "")))
  6429. (cond ((string-lessp ca cb) -1)
  6430. ((string-lessp cb ca) +1))))
  6431. (defsubst org-cmp-todo-state (a b)
  6432. "Compare the todo states of strings A and B."
  6433. (let* ((ma (or (get-text-property 1 'org-marker a)
  6434. (get-text-property 1 'org-hd-marker a)))
  6435. (mb (or (get-text-property 1 'org-marker b)
  6436. (get-text-property 1 'org-hd-marker b)))
  6437. (fa (and ma (marker-buffer ma)))
  6438. (fb (and mb (marker-buffer mb)))
  6439. (todo-kwds
  6440. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6441. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6442. (ta (or (get-text-property 1 'todo-state a) ""))
  6443. (tb (or (get-text-property 1 'todo-state b) ""))
  6444. (la (- (length (member ta todo-kwds))))
  6445. (lb (- (length (member tb todo-kwds))))
  6446. (donepa (member ta org-done-keywords-for-agenda))
  6447. (donepb (member tb org-done-keywords-for-agenda)))
  6448. (cond ((and donepa (not donepb)) -1)
  6449. ((and (not donepa) donepb) +1)
  6450. ((< la lb) -1)
  6451. ((< lb la) +1))))
  6452. (defsubst org-cmp-alpha (a b)
  6453. "Compare the headlines, alphabetically."
  6454. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6455. (plb (text-property-any 0 (length b) 'org-heading t b))
  6456. (ta (and pla (substring a pla)))
  6457. (tb (and plb (substring b plb))))
  6458. (when pla
  6459. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6460. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6461. (setq ta (substring ta (match-end 0))))
  6462. (setq ta (downcase ta)))
  6463. (when plb
  6464. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6465. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6466. (setq tb (substring tb (match-end 0))))
  6467. (setq tb (downcase tb)))
  6468. (cond ((not ta) +1)
  6469. ((not tb) -1)
  6470. ((string-lessp ta tb) -1)
  6471. ((string-lessp tb ta) +1))))
  6472. (defsubst org-cmp-tag (a b)
  6473. "Compare the string values of the first tags of A and B."
  6474. (let ((ta (car (last (get-text-property 1 'tags a))))
  6475. (tb (car (last (get-text-property 1 'tags b)))))
  6476. (cond ((not ta) +1)
  6477. ((not tb) -1)
  6478. ((string-lessp ta tb) -1)
  6479. ((string-lessp tb ta) +1))))
  6480. (defsubst org-cmp-time (a b)
  6481. "Compare the time-of-day values of strings A and B."
  6482. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6483. (ta (or (get-text-property 1 'time-of-day a) def))
  6484. (tb (or (get-text-property 1 'time-of-day b) def)))
  6485. (cond ((< ta tb) -1)
  6486. ((< tb ta) +1))))
  6487. (defsubst org-cmp-ts (a b &optional type)
  6488. "Compare the timestamps values of entries A and B.
  6489. When TYPE is \"scheduled\", \"deadline\", \"timestamp\"
  6490. or \"timestamp_ia\", compare within each of these type.
  6491. When TYPE is the empty string, compare all timestamps
  6492. without respect of their type."
  6493. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6494. (ta (or (and (string-match type (get-text-property 1 'type a))
  6495. (get-text-property 1 'ts-date a)) def))
  6496. (tb (or (and (string-match type (get-text-property 1 'type b))
  6497. (get-text-property 1 'ts-date b)) def)))
  6498. (cond ((< ta tb) -1)
  6499. ((< tb ta) +1))))
  6500. (defsubst org-cmp-habit-p (a b)
  6501. "Compare the todo states of strings A and B."
  6502. (let ((ha (get-text-property 1 'org-habit-p a))
  6503. (hb (get-text-property 1 'org-habit-p b)))
  6504. (cond ((and ha (not hb)) -1)
  6505. ((and (not ha) hb) +1))))
  6506. (defun org-entries-lessp (a b)
  6507. "Predicate for sorting agenda entries."
  6508. ;; The following variables will be used when the form is evaluated.
  6509. ;; So even though the compiler complains, keep them.
  6510. (let* ((ss org-agenda-sorting-strategy-selected)
  6511. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6512. (org-cmp-ts a b "")))
  6513. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6514. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6515. (org-cmp-ts a b "scheduled")))
  6516. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6517. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6518. (org-cmp-ts a b "deadline")))
  6519. (deadline-down (if deadline-up (- deadline-up) nil))
  6520. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6521. (org-cmp-ts a b "iatimestamp_ia")))
  6522. (tsia-down (if tsia-up (- tsia-up) nil))
  6523. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6524. (org-cmp-ts a b "timestamp")))
  6525. (ts-down (if ts-up (- ts-up) nil))
  6526. (time-up (and (org-em 'time-up 'time-down ss)
  6527. (org-cmp-time a b)))
  6528. (time-down (if time-up (- time-up) nil))
  6529. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6530. (org-cmp-priority a b)))
  6531. (priority-down (if priority-up (- priority-up) nil))
  6532. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6533. (org-cmp-effort a b)))
  6534. (effort-down (if effort-up (- effort-up) nil))
  6535. (category-up (and (or (org-em 'category-up 'category-down ss)
  6536. (memq 'category-keep ss))
  6537. (org-cmp-category a b)))
  6538. (category-down (if category-up (- category-up) nil))
  6539. (category-keep (if category-up +1 nil))
  6540. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6541. (org-cmp-tag a b)))
  6542. (tag-down (if tag-up (- tag-up) nil))
  6543. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6544. (org-cmp-todo-state a b)))
  6545. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6546. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6547. (org-cmp-habit-p a b)))
  6548. (habit-down (if habit-up (- habit-up) nil))
  6549. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6550. (org-cmp-alpha a b)))
  6551. (alpha-down (if alpha-up (- alpha-up) nil))
  6552. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6553. user-defined-up user-defined-down)
  6554. (if (and need-user-cmp org-agenda-cmp-user-defined
  6555. (functionp org-agenda-cmp-user-defined))
  6556. (setq user-defined-up
  6557. (funcall org-agenda-cmp-user-defined a b)
  6558. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6559. (cdr (assoc
  6560. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6561. '((-1 . t) (1 . nil) (nil . nil))))))
  6562. ;;; Agenda restriction lock
  6563. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6564. "Overlay to mark the headline to which agenda commands are restricted.")
  6565. (overlay-put org-agenda-restriction-lock-overlay
  6566. 'face 'org-agenda-restriction-lock)
  6567. (overlay-put org-agenda-restriction-lock-overlay
  6568. 'help-echo "Agendas are currently limited to this subtree.")
  6569. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6570. (defun org-agenda-set-restriction-lock (&optional type)
  6571. "Set restriction lock for agenda, to current subtree or file.
  6572. Restriction will be the file if TYPE is `file', or if type is the
  6573. universal prefix '(4), or if the cursor is before the first headline
  6574. in the file. Otherwise, restriction will be to the current subtree."
  6575. (interactive "P")
  6576. (and (equal type '(4)) (setq type 'file))
  6577. (setq type (cond
  6578. (type type)
  6579. ((org-at-heading-p) 'subtree)
  6580. ((condition-case nil (org-back-to-heading t) (error nil))
  6581. 'subtree)
  6582. (t 'file)))
  6583. (if (eq type 'subtree)
  6584. (progn
  6585. (setq org-agenda-restrict t)
  6586. (setq org-agenda-overriding-restriction 'subtree)
  6587. (put 'org-agenda-files 'org-restrict
  6588. (list (buffer-file-name (buffer-base-buffer))))
  6589. (org-back-to-heading t)
  6590. (move-overlay org-agenda-restriction-lock-overlay
  6591. (point)
  6592. (if org-agenda-restriction-lock-highlight-subtree
  6593. (save-excursion (org-end-of-subtree t t) (point))
  6594. (point-at-eol)))
  6595. (move-marker org-agenda-restrict-begin (point))
  6596. (move-marker org-agenda-restrict-end
  6597. (save-excursion (org-end-of-subtree t t)))
  6598. (message "Locking agenda restriction to subtree"))
  6599. (put 'org-agenda-files 'org-restrict
  6600. (list (buffer-file-name (buffer-base-buffer))))
  6601. (setq org-agenda-restrict nil)
  6602. (setq org-agenda-overriding-restriction 'file)
  6603. (move-marker org-agenda-restrict-begin nil)
  6604. (move-marker org-agenda-restrict-end nil)
  6605. (message "Locking agenda restriction to file"))
  6606. (setq current-prefix-arg nil)
  6607. (org-agenda-maybe-redo))
  6608. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6609. "Remove the agenda restriction lock."
  6610. (interactive "P")
  6611. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6612. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6613. (setq org-agenda-overriding-restriction nil)
  6614. (setq org-agenda-restrict nil)
  6615. (put 'org-agenda-files 'org-restrict nil)
  6616. (move-marker org-agenda-restrict-begin nil)
  6617. (move-marker org-agenda-restrict-end nil)
  6618. (setq current-prefix-arg nil)
  6619. (message "Agenda restriction lock removed")
  6620. (or noupdate (org-agenda-maybe-redo)))
  6621. (defun org-agenda-maybe-redo ()
  6622. "If there is any window showing the agenda view, update it."
  6623. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6624. (w0 (selected-window)))
  6625. (when w
  6626. (select-window w)
  6627. (org-agenda-redo)
  6628. (select-window w0)
  6629. (if org-agenda-overriding-restriction
  6630. (message "Agenda view shifted to new %s restriction"
  6631. org-agenda-overriding-restriction)
  6632. (message "Agenda restriction lock removed")))))
  6633. ;;; Agenda commands
  6634. (defun org-agenda-check-type (error &rest types)
  6635. "Check if agenda buffer is of allowed type.
  6636. If ERROR is non-nil, throw an error, otherwise just return nil.
  6637. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6638. (if (not org-agenda-type)
  6639. (error "No Org agenda currently displayed")
  6640. (if (memq org-agenda-type types)
  6641. t
  6642. (if error
  6643. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6644. nil))))
  6645. (defun org-agenda-Quit ()
  6646. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6647. Also restore the window configuration."
  6648. (interactive)
  6649. (if org-agenda-columns-active
  6650. (org-columns-quit)
  6651. (let ((buf (current-buffer)))
  6652. (if (eq org-agenda-window-setup 'other-frame)
  6653. (progn
  6654. (org-agenda-reset-markers)
  6655. (kill-buffer buf)
  6656. (org-columns-remove-overlays)
  6657. (setq org-agenda-archives-mode nil)
  6658. (delete-frame))
  6659. (and (not (eq org-agenda-window-setup 'current-window))
  6660. (not (one-window-p))
  6661. (delete-window))
  6662. (org-agenda-reset-markers)
  6663. (kill-buffer buf)
  6664. (org-columns-remove-overlays)
  6665. (setq org-agenda-archives-mode nil)))
  6666. (setq org-agenda-buffer nil)
  6667. ;; Maybe restore the pre-agenda window configuration.
  6668. (and org-agenda-restore-windows-after-quit
  6669. (not (eq org-agenda-window-setup 'other-frame))
  6670. org-agenda-pre-window-conf
  6671. (set-window-configuration org-agenda-pre-window-conf)
  6672. (setq org-agenda-pre-window-conf nil))))
  6673. (defun org-agenda-quit ()
  6674. "Exit the agenda and restore the window configuration.
  6675. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6676. (interactive)
  6677. (if (and (eq org-indirect-buffer-display 'other-window)
  6678. org-last-indirect-buffer)
  6679. (let ((org-last-indirect-window
  6680. (get-buffer-window org-last-indirect-buffer)))
  6681. (if org-last-indirect-window
  6682. (delete-window org-last-indirect-window))))
  6683. (if org-agenda-columns-active
  6684. (org-columns-quit)
  6685. (if org-agenda-sticky
  6686. (let ((buf (current-buffer)))
  6687. (if (eq org-agenda-window-setup 'other-frame)
  6688. (progn
  6689. (delete-frame))
  6690. (and (not (eq org-agenda-window-setup 'current-window))
  6691. (not (one-window-p))
  6692. (delete-window)))
  6693. (with-current-buffer buf
  6694. (bury-buffer)
  6695. ;; Maybe restore the pre-agenda window configuration.
  6696. (and org-agenda-restore-windows-after-quit
  6697. (not (eq org-agenda-window-setup 'other-frame))
  6698. org-agenda-pre-window-conf
  6699. (set-window-configuration org-agenda-pre-window-conf)
  6700. (setq org-agenda-pre-window-conf nil))))
  6701. (org-agenda-Quit))))
  6702. (defun org-agenda-exit ()
  6703. "Exit the agenda and restore the window configuration.
  6704. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6705. buffers visited directly by the user will not be touched."
  6706. (interactive)
  6707. (org-release-buffers org-agenda-new-buffers)
  6708. (setq org-agenda-new-buffers nil)
  6709. (org-agenda-Quit))
  6710. (defun org-agenda-kill-all-agenda-buffers ()
  6711. "Kill all buffers in `org-agenda-mode'.
  6712. This is used when toggling sticky agendas.
  6713. You can also explicitly invoke it with `C-c a C-k'."
  6714. (interactive)
  6715. (let (blist)
  6716. (dolist (buf (buffer-list))
  6717. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6718. (push buf blist)))
  6719. (mapc 'kill-buffer blist)))
  6720. (defun org-agenda-execute (arg)
  6721. "Execute another agenda command, keeping same window.
  6722. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6723. in the agenda."
  6724. (interactive "P")
  6725. (let ((org-agenda-window-setup 'current-window))
  6726. (org-agenda arg)))
  6727. (defun org-agenda-redo (&optional all)
  6728. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6729. (interactive "P")
  6730. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6731. (cpa (unless (eq all t) current-prefix-arg))
  6732. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6733. (org-agenda-sticky nil)
  6734. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6735. org-agenda-buffer-name))
  6736. (org-agenda-keep-modes t)
  6737. (tag-filter org-agenda-tag-filter)
  6738. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6739. (top-hl-filter org-agenda-top-headline-filter)
  6740. (cat-filter org-agenda-category-filter)
  6741. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6742. (re-filter org-agenda-regexp-filter)
  6743. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6744. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6745. (cols org-agenda-columns-active)
  6746. (line (org-current-line))
  6747. (window-line (- line (org-current-line (window-start))))
  6748. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6749. (redo-cmd (get-text-property p 'org-redo-cmd))
  6750. (last-args (get-text-property p 'org-last-args))
  6751. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6752. (org-agenda-overriding-cmd-arguments
  6753. (unless (eq all t)
  6754. (cond ((listp last-args)
  6755. (cons (or cpa (car last-args)) (cdr last-args)))
  6756. ((stringp last-args)
  6757. last-args))))
  6758. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6759. (put 'org-agenda-tag-filter :preset-filter nil)
  6760. (put 'org-agenda-category-filter :preset-filter nil)
  6761. (put 'org-agenda-regexp-filter :preset-filter nil)
  6762. (and cols (org-columns-quit))
  6763. (message "Rebuilding agenda buffer...")
  6764. (if series-redo-cmd
  6765. (eval series-redo-cmd)
  6766. (org-let lprops redo-cmd))
  6767. (setq org-agenda-undo-list nil
  6768. org-agenda-pending-undo-list nil
  6769. org-agenda-tag-filter tag-filter
  6770. org-agenda-category-filter cat-filter
  6771. org-agenda-regexp-filter re-filter
  6772. org-agenda-top-headline-filter top-hl-filter)
  6773. (message "Rebuilding agenda buffer...done")
  6774. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6775. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6776. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6777. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6778. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6779. (and (or re-filter re-preset) (org-agenda-filter-apply re-filter 'regexp))
  6780. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6781. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6782. (org-goto-line line)
  6783. (recenter window-line)))
  6784. (defvar org-global-tags-completion-table nil)
  6785. (defvar org-agenda-filter-form nil)
  6786. (defvar org-agenda-filtered-by-category nil)
  6787. (defun org-agenda-filter-by-category (strip)
  6788. "Keep only those lines in the agenda buffer that have a specific category.
  6789. The category is that of the current line."
  6790. (interactive "P")
  6791. (if (and org-agenda-filtered-by-category
  6792. org-agenda-category-filter)
  6793. (org-agenda-filter-show-all-cat)
  6794. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6795. (if (and cat (not (string= "" cat)))
  6796. (org-agenda-filter-apply
  6797. (setq org-agenda-category-filter
  6798. (list (concat (if strip "-" "+") cat)))
  6799. 'category)
  6800. (error "No category at point")))))
  6801. (defun org-find-top-headline (&optional pos)
  6802. "Find the topmost parent headline and return it."
  6803. (save-excursion
  6804. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6805. (if pos (goto-char pos))
  6806. ;; Skip up to the topmost parent
  6807. (while (ignore-errors (outline-up-heading 1) t))
  6808. (ignore-errors
  6809. (nth 4 (org-heading-components))))))
  6810. (defvar org-agenda-filtered-by-top-headline nil)
  6811. (defun org-agenda-filter-by-top-headline (strip)
  6812. "Keep only those lines that are descendants from the same top headline.
  6813. The top headline is that of the current line."
  6814. (interactive "P")
  6815. (if org-agenda-filtered-by-top-headline
  6816. (progn
  6817. (setq org-agenda-filtered-by-top-headline nil
  6818. org-agenda-top-headline-filter nil)
  6819. (org-agenda-filter-show-all-cat))
  6820. (let ((cat (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6821. (if cat (org-agenda-filter-top-headline-apply cat strip)
  6822. (error "No top-level category at point")))))
  6823. (defvar org-agenda-regexp-filter nil)
  6824. (defun org-agenda-filter-by-regexp (strip)
  6825. "Filter agenda entries by a regular expression.
  6826. Regexp filters are cumulative.
  6827. With no prefix argument, keep entries matching the regexp.
  6828. With one prefix argument, filter out entries matching the regexp.
  6829. With two prefix arguments, remove the regexp filters."
  6830. (interactive "P")
  6831. (if (not (equal strip '(16)))
  6832. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6833. (read-from-minibuffer
  6834. (if (equal strip '(4))
  6835. "Filter out entries matching regexp: "
  6836. "Narrow to entries matching regexp: ")))))
  6837. (push flt org-agenda-regexp-filter)
  6838. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6839. (org-agenda-filter-show-all-re)
  6840. (message "Regexp filter removed")))
  6841. (defun org-agenda-filter-remove-all ()
  6842. "Remove all filters from the current agenda buffer."
  6843. (interactive)
  6844. (when org-agenda-tag-filter
  6845. (org-agenda-filter-show-all-tag))
  6846. (when org-agenda-category-filter
  6847. (org-agenda-filter-show-all-cat))
  6848. (when org-agenda-regexp-filter
  6849. (org-agenda-filter-show-all-re)))
  6850. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6851. "Keep only those lines in the agenda buffer that have a specific tag.
  6852. The tag is selected with its fast selection letter, as configured.
  6853. With prefix argument STRIP, remove all lines that do have the tag.
  6854. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6855. used to narrow the search - the interactive user can also press `-' or `+'
  6856. to switch to narrowing."
  6857. (interactive "P")
  6858. (let* ((alist org-tag-alist-for-agenda)
  6859. (tag-chars (mapconcat
  6860. (lambda (x) (if (and (not (symbolp (car x)))
  6861. (cdr x))
  6862. (char-to-string (cdr x))
  6863. ""))
  6864. alist ""))
  6865. (efforts (org-split-string
  6866. (or (cdr (assoc (concat org-effort-property "_ALL")
  6867. org-global-properties))
  6868. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6869. "")))
  6870. (effort-op org-agenda-filter-effort-default-operator)
  6871. (effort-prompt "")
  6872. (inhibit-read-only t)
  6873. (current org-agenda-tag-filter)
  6874. maybe-refresh a n tag)
  6875. (unless char
  6876. (message
  6877. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6878. (if narrow "Narrow" "Filter") tag-chars
  6879. (if org-agenda-auto-exclude-function "[RET], " ""))
  6880. (setq char (read-char-exclusive)))
  6881. (when (member char '(?+ ?-))
  6882. ;; Narrowing down
  6883. (cond ((equal char ?-) (setq strip t narrow t))
  6884. ((equal char ?+) (setq strip nil narrow t)))
  6885. (message
  6886. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6887. (setq char (read-char-exclusive)))
  6888. (when (member char '(?< ?> ?= ??))
  6889. ;; An effort operator
  6890. (setq effort-op (char-to-string char))
  6891. (setq alist nil) ; to make sure it will be interpreted as effort.
  6892. (unless (equal char ??)
  6893. (loop for i from 0 to 9 do
  6894. (setq effort-prompt
  6895. (concat
  6896. effort-prompt " ["
  6897. (if (= i 9) "0" (int-to-string (1+ i)))
  6898. "]" (nth i efforts))))
  6899. (message "Effort%s: %s " effort-op effort-prompt)
  6900. (setq char (read-char-exclusive))
  6901. (when (or (< char ?0) (> char ?9))
  6902. (error "Need 1-9,0 to select effort"))))
  6903. (when (equal char ?\t)
  6904. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6905. (org-set-local 'org-global-tags-completion-table
  6906. (org-global-tags-completion-table)))
  6907. (let ((completion-ignore-case t))
  6908. (setq tag (org-icompleting-read
  6909. "Tag: " org-global-tags-completion-table))))
  6910. (cond
  6911. ((equal char ?\r)
  6912. (org-agenda-filter-show-all-tag)
  6913. (when org-agenda-auto-exclude-function
  6914. (setq org-agenda-tag-filter nil)
  6915. (dolist (tag (org-agenda-get-represented-tags))
  6916. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6917. (if modifier
  6918. (push modifier org-agenda-tag-filter))))
  6919. (if (not (null org-agenda-tag-filter))
  6920. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6921. (setq maybe-refresh t))
  6922. ((equal char ?/)
  6923. (org-agenda-filter-show-all-tag)
  6924. (when (get 'org-agenda-tag-filter :preset-filter)
  6925. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6926. (setq maybe-refresh t))
  6927. ((equal char ?. )
  6928. (setq org-agenda-tag-filter
  6929. (mapcar (lambda(tag) (concat "+" tag))
  6930. (org-get-at-bol 'tags)))
  6931. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6932. (setq maybe-refresh t))
  6933. ((or (equal char ?\ )
  6934. (setq a (rassoc char alist))
  6935. (and (>= char ?0) (<= char ?9)
  6936. (setq n (if (= char ?0) 9 (- char ?0 1))
  6937. tag (concat effort-op (nth n efforts))
  6938. a (cons tag nil)))
  6939. (and (= char ??)
  6940. (setq tag "?eff")
  6941. a (cons tag nil))
  6942. (and tag (setq a (cons tag nil))))
  6943. (org-agenda-filter-show-all-tag)
  6944. (setq tag (car a))
  6945. (setq org-agenda-tag-filter
  6946. (cons (concat (if strip "-" "+") tag)
  6947. (if narrow current nil)))
  6948. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6949. (setq maybe-refresh t))
  6950. (t (error "Invalid tag selection character %c" char)))
  6951. (when (and maybe-refresh
  6952. (eq org-agenda-clockreport-mode 'with-filter))
  6953. (org-agenda-redo))))
  6954. (defun org-agenda-get-represented-tags ()
  6955. "Get a list of all tags currently represented in the agenda."
  6956. (let (p tags)
  6957. (save-excursion
  6958. (goto-char (point-min))
  6959. (while (setq p (next-single-property-change (point) 'tags))
  6960. (goto-char p)
  6961. (mapc (lambda (x) (add-to-list 'tags x))
  6962. (get-text-property (point) 'tags))))
  6963. tags))
  6964. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6965. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6966. (interactive "P")
  6967. (org-agenda-filter-by-tag strip char 'refine))
  6968. (defun org-agenda-filter-make-matcher (filter type)
  6969. "Create the form that tests a line for agenda filter."
  6970. (let (f f1)
  6971. (cond
  6972. ;; Tag filter
  6973. ((eq type 'tag)
  6974. (setq filter
  6975. (delete-dups
  6976. (append (get 'org-agenda-tag-filter :preset-filter)
  6977. filter)))
  6978. (dolist (x filter)
  6979. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  6980. (ffunc
  6981. (lambda (nf0 nf01 fltr notgroup op)
  6982. (dolist (x fltr)
  6983. (if (member x '("-" "+"))
  6984. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  6985. (if (string-match "[<=>?]" x)
  6986. (setq nf01 (org-agenda-filter-effort-form x))
  6987. (setq nf01 (list 'member (downcase (substring x 1))
  6988. 'tags)))
  6989. (when (equal (string-to-char x) ?-)
  6990. (setq nf01 (list 'not nf01))
  6991. (when (not notgroup) (setq op 'and))))
  6992. (push nf01 nf0))
  6993. (if notgroup
  6994. (push (cons 'and nf0) f)
  6995. (push (cons (or op 'or) nf0) f)))))
  6996. (if (equal nfilter filter)
  6997. (funcall ffunc f1 f filter t nil)
  6998. (funcall ffunc nf1 nf nfilter nil nil)))))
  6999. ;; Category filter
  7000. ((eq type 'category)
  7001. (setq filter
  7002. (delete-dups
  7003. (append (get 'org-agenda-category-filter :preset-filter)
  7004. filter)))
  7005. (dolist (x filter)
  7006. (if (equal "-" (substring x 0 1))
  7007. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7008. (setq f1 (list 'equal (substring x 1) 'cat)))
  7009. (push f1 f)))
  7010. ;; Regexp filter
  7011. ((eq type 'regexp)
  7012. (setq filter
  7013. (delete-dups
  7014. (append (get 'org-agenda-regexp-filter :preset-filter)
  7015. filter)))
  7016. (dolist (x filter)
  7017. (if (equal "-" (substring x 0 1))
  7018. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7019. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7020. (push f1 f))))
  7021. (cons 'and (nreverse f))))
  7022. (defun org-agenda-filter-effort-form (e)
  7023. "Return the form to compare the effort of the current line with what E says.
  7024. E looks like \"+<2:25\"."
  7025. (let (op)
  7026. (setq e (substring e 1))
  7027. (setq op (string-to-char e) e (substring e 1))
  7028. (setq op (cond ((equal op ?<) '<=)
  7029. ((equal op ?>) '>=)
  7030. ((equal op ??) op)
  7031. (t '=)))
  7032. (list 'org-agenda-compare-effort (list 'quote op)
  7033. (org-duration-string-to-minutes e))))
  7034. (defun org-agenda-compare-effort (op value)
  7035. "Compare the effort of the current line with VALUE, using OP.
  7036. If the line does not have an effort defined, return nil."
  7037. (let ((eff (org-get-at-bol 'effort-minutes)))
  7038. (if (equal op ??)
  7039. (not eff)
  7040. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  7041. value))))
  7042. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7043. "Expand group tags in FILTER for the agenda.
  7044. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7045. (if org-group-tags
  7046. (let ((case-fold-search t) rtn)
  7047. (mapc
  7048. (lambda (f)
  7049. (let (f0 dir)
  7050. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7051. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7052. (setq dir (if no-operator "" "+") f0 f))
  7053. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7054. (org-tags-expand f0 t t))
  7055. rtn))))
  7056. filter)
  7057. (reverse rtn))
  7058. filter))
  7059. (defun org-agenda-filter-apply (filter type)
  7060. "Set FILTER as the new agenda filter and apply it."
  7061. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7062. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7063. (let (tags cat txt)
  7064. (setq org-agenda-filter-form
  7065. (org-agenda-filter-make-matcher filter type))
  7066. (if (and (eq type 'category)
  7067. (not (equal (substring (car filter) 0 1) "-")))
  7068. ;; Only set `org-agenda-filtered-by-category' to t
  7069. ;; when a unique category is used as the filter
  7070. (setq org-agenda-filtered-by-category t))
  7071. (org-agenda-set-mode-name)
  7072. (save-excursion
  7073. (goto-char (point-min))
  7074. (while (not (eobp))
  7075. (if (org-get-at-bol 'org-marker)
  7076. (progn
  7077. (setq tags ; used in eval
  7078. (apply 'append
  7079. (mapcar (lambda (f)
  7080. (org-agenda-filter-expand-tags (list f) t))
  7081. (org-get-at-bol 'tags)))
  7082. cat (get-text-property (point) 'org-category)
  7083. txt (get-text-property (point) 'txt))
  7084. (if (not (eval org-agenda-filter-form))
  7085. (org-agenda-filter-hide-line type))
  7086. (beginning-of-line 2))
  7087. (beginning-of-line 2))))
  7088. (if (get-char-property (point) 'invisible)
  7089. (ignore-errors (org-agenda-previous-line)))))
  7090. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7091. "Filter by top headline HL."
  7092. (org-agenda-set-mode-name)
  7093. (save-excursion
  7094. (goto-char (point-min))
  7095. (while (not (eobp))
  7096. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7097. (tophl (and pos (org-find-top-headline pos))))
  7098. (if (and tophl (funcall (if negative 'identity 'not)
  7099. (string= hl tophl)))
  7100. (org-agenda-filter-hide-line 'category)))
  7101. (beginning-of-line 2)))
  7102. (if (get-char-property (point) 'invisible)
  7103. (org-agenda-previous-line))
  7104. (setq org-agenda-top-headline-filter hl
  7105. org-agenda-filtered-by-top-headline t))
  7106. (defun org-agenda-filter-hide-line (type)
  7107. "Hide lines with TYPE in the agenda buffer."
  7108. (let (ov)
  7109. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  7110. (point-at-eol)))
  7111. (overlay-put ov 'invisible t)
  7112. (overlay-put ov 'type type)
  7113. (cond ((eq type 'tag) (push ov org-agenda-tag-filter-overlays))
  7114. ((eq type 'category) (push ov org-agenda-cat-filter-overlays))
  7115. ((eq type 'regexp) (push ov org-agenda-re-filter-overlays)))))
  7116. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  7117. (setq pos (or pos (point)))
  7118. (save-excursion
  7119. (dolist (ov (overlays-at pos))
  7120. (when (and (overlay-get ov 'invisible)
  7121. (eq (overlay-get ov 'type) 'tag))
  7122. (goto-char pos)
  7123. (if (< (overlay-start ov) (point-at-eol))
  7124. (move-overlay ov (point-at-eol)
  7125. (overlay-end ov)))))))
  7126. (defun org-agenda-filter-show-all-tag nil
  7127. "Remove tag filter overlays from the agenda buffer."
  7128. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  7129. (setq org-agenda-tag-filter-overlays nil
  7130. org-agenda-tag-filter nil
  7131. org-agenda-filter-form nil)
  7132. (org-agenda-set-mode-name))
  7133. (defun org-agenda-filter-show-all-re nil
  7134. "Remove regexp filter overlays from the agenda buffer."
  7135. (mapc 'delete-overlay org-agenda-re-filter-overlays)
  7136. (setq org-agenda-re-filter-overlays nil
  7137. org-agenda-regexp-filter nil
  7138. org-agenda-filter-form nil)
  7139. (org-agenda-set-mode-name))
  7140. (defun org-agenda-filter-show-all-cat nil
  7141. "Remove category filter overlays from the agenda buffer."
  7142. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  7143. (setq org-agenda-cat-filter-overlays nil
  7144. org-agenda-filtered-by-category nil
  7145. org-agenda-category-filter nil
  7146. org-agenda-filter-form nil)
  7147. (org-agenda-set-mode-name))
  7148. (defun org-agenda-manipulate-query-add ()
  7149. "Manipulate the query by adding a search term with positive selection.
  7150. Positive selection means the term must be matched for selection of an entry."
  7151. (interactive)
  7152. (org-agenda-manipulate-query ?\[))
  7153. (defun org-agenda-manipulate-query-subtract ()
  7154. "Manipulate the query by adding a search term with negative selection.
  7155. Negative selection means term must not be matched for selection of an entry."
  7156. (interactive)
  7157. (org-agenda-manipulate-query ?\]))
  7158. (defun org-agenda-manipulate-query-add-re ()
  7159. "Manipulate the query by adding a search regexp with positive selection.
  7160. Positive selection means the regexp must match for selection of an entry."
  7161. (interactive)
  7162. (org-agenda-manipulate-query ?\{))
  7163. (defun org-agenda-manipulate-query-subtract-re ()
  7164. "Manipulate the query by adding a search regexp with negative selection.
  7165. Negative selection means regexp must not match for selection of an entry."
  7166. (interactive)
  7167. (org-agenda-manipulate-query ?\}))
  7168. (defun org-agenda-manipulate-query (char)
  7169. (cond
  7170. ((memq org-agenda-type '(timeline agenda))
  7171. (let ((org-agenda-include-inactive-timestamps t))
  7172. (org-agenda-redo))
  7173. (message "Display now includes inactive timestamps as well"))
  7174. ((eq org-agenda-type 'search)
  7175. (org-add-to-string
  7176. 'org-agenda-query-string
  7177. (if org-agenda-last-search-view-search-was-boolean
  7178. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7179. (?\{ . " +{}") (?\} . " -{}"))))
  7180. " "))
  7181. (setq org-agenda-redo-command
  7182. (list 'org-search-view
  7183. (car (get-text-property (min (1- (point-max)) (point))
  7184. 'org-last-args))
  7185. org-agenda-query-string
  7186. (+ (length org-agenda-query-string)
  7187. (if (member char '(?\{ ?\})) 0 1))))
  7188. (set-register org-agenda-query-register org-agenda-query-string)
  7189. (let ((org-agenda-overriding-arguments
  7190. (cdr org-agenda-redo-command)))
  7191. (org-agenda-redo)))
  7192. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7193. org-agenda-type))))
  7194. (defun org-add-to-string (var string)
  7195. (set var (concat (symbol-value var) string)))
  7196. (defun org-agenda-goto-date (span)
  7197. "Jump to DATE in agenda."
  7198. (interactive "P")
  7199. (let* ((org-read-date-prefer-future
  7200. (eval org-agenda-jump-prefer-future))
  7201. (date (org-read-date))
  7202. (day (time-to-days (org-time-string-to-time date)))
  7203. (org-agenda-sticky-orig org-agenda-sticky)
  7204. (org-agenda-buffer-tmp-name (buffer-name))
  7205. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7206. (0-arg (or current-prefix-arg (car args)))
  7207. (2-arg (nth 2 args))
  7208. (with-hour-p (nth 4 org-agenda-redo-command))
  7209. (newcmd (list 'org-agenda-list 0-arg date
  7210. (org-agenda-span-to-ndays
  7211. 2-arg (org-time-string-to-absolute date))
  7212. with-hour-p))
  7213. (newargs (cdr newcmd))
  7214. (inhibit-read-only t)
  7215. org-agenda-sticky)
  7216. (if (not (org-agenda-check-type t 'agenda))
  7217. (error "Not available in non-agenda views")
  7218. (add-text-properties (point-min) (point-max)
  7219. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7220. (org-agenda-redo)
  7221. (goto-char (point-min))
  7222. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7223. (save-excursion (move-beginning-of-line 2) (eobp))))
  7224. (move-beginning-of-line 2))
  7225. (setq org-agenda-sticky org-agenda-sticky-orig
  7226. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7227. (defun org-agenda-goto-today ()
  7228. "Go to today."
  7229. (interactive)
  7230. (org-agenda-check-type t 'timeline 'agenda)
  7231. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7232. (curspan (nth 2 args))
  7233. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7234. (cond
  7235. (tdpos (goto-char tdpos))
  7236. ((eq org-agenda-type 'agenda)
  7237. (let* ((sd (org-agenda-compute-starting-span
  7238. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7239. (org-agenda-overriding-arguments args))
  7240. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7241. (org-agenda-redo)
  7242. (org-agenda-find-same-or-today-or-agenda)))
  7243. (t (error "Cannot find today")))))
  7244. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7245. (goto-char
  7246. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7247. (text-property-any (point-min) (point-max) 'org-today t)
  7248. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7249. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7250. (org-agenda-goto-block-beginning))
  7251. (point-min))))
  7252. (defun org-agenda-goto-block-beginning ()
  7253. "Go the agenda block beginning."
  7254. (interactive)
  7255. (if (not (derived-mode-p 'org-agenda-mode))
  7256. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7257. (let (dest)
  7258. (save-excursion
  7259. (unless (looking-at "\\'")
  7260. (forward-char))
  7261. (let* ((prop 'org-agenda-structural-header)
  7262. (p (previous-single-property-change (point) prop))
  7263. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7264. (1- (point))) prop)))
  7265. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7266. (if (not dest)
  7267. (error "Cannot find the beginning of the blog")
  7268. (goto-char dest)
  7269. (move-beginning-of-line 1)))))
  7270. (defun org-agenda-later (arg)
  7271. "Go forward in time by the current span.
  7272. With prefix ARG, go forward that many times the current span."
  7273. (interactive "p")
  7274. (org-agenda-check-type t 'agenda)
  7275. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7276. (span (or (nth 2 args) org-agenda-current-span))
  7277. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7278. (greg (calendar-gregorian-from-absolute sd))
  7279. (cnt (org-get-at-bol 'org-day-cnt))
  7280. greg2)
  7281. (cond
  7282. ((numberp span)
  7283. (setq sd (+ (* span arg) sd)))
  7284. ((eq span 'day)
  7285. (setq sd (+ arg sd)))
  7286. ((eq span 'week)
  7287. (setq sd (+ (* 7 arg) sd)))
  7288. ((eq span 'month)
  7289. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7290. sd (calendar-absolute-from-gregorian greg2))
  7291. (setcar greg2 (1+ (car greg2))))
  7292. ((eq span 'year)
  7293. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7294. sd (calendar-absolute-from-gregorian greg2))
  7295. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7296. (t
  7297. (setq sd (+ (* span arg) sd))))
  7298. (let ((org-agenda-overriding-cmd
  7299. ;; `cmd' may have been set by `org-agenda-run-series' which
  7300. ;; uses `org-agenda-overriding-cmd' to decide whether
  7301. ;; overriding is allowed for `cmd'
  7302. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7303. (org-agenda-overriding-arguments
  7304. (list (car args) sd span)))
  7305. (org-agenda-redo)
  7306. (org-agenda-find-same-or-today-or-agenda cnt))))
  7307. (defun org-agenda-earlier (arg)
  7308. "Go backward in time by the current span.
  7309. With prefix ARG, go backward that many times the current span."
  7310. (interactive "p")
  7311. (org-agenda-later (- arg)))
  7312. (defun org-agenda-view-mode-dispatch ()
  7313. "Call one of the view mode commands."
  7314. (interactive)
  7315. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  7316. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7317. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7318. (let ((a (read-char-exclusive)))
  7319. (case a
  7320. (?\ (call-interactively 'org-agenda-reset-view))
  7321. (?d (call-interactively 'org-agenda-day-view))
  7322. (?w (call-interactively 'org-agenda-week-view))
  7323. (?m (call-interactively 'org-agenda-month-view))
  7324. (?y (call-interactively 'org-agenda-year-view))
  7325. (?l (call-interactively 'org-agenda-log-mode))
  7326. (?L (org-agenda-log-mode '(4)))
  7327. (?c (org-agenda-log-mode 'clockcheck))
  7328. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7329. (?a (call-interactively 'org-agenda-archives-mode))
  7330. (?A (org-agenda-archives-mode 'files))
  7331. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7332. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7333. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7334. (?D (call-interactively 'org-agenda-toggle-diary))
  7335. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7336. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7337. (org-agenda-check-type t 'timeline 'agenda)
  7338. (org-agenda-redo))
  7339. (message "Display now includes inactive timestamps as well"))
  7340. (?q (message "Abort"))
  7341. (otherwise (error "Invalid key" )))))
  7342. (defun org-agenda-reset-view ()
  7343. "Switch to default view for agenda."
  7344. (interactive)
  7345. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7346. (defun org-agenda-day-view (&optional day-of-month)
  7347. "Switch to daily view for agenda.
  7348. With argument DAY-OF-MONTH, switch to that day of the month."
  7349. (interactive "P")
  7350. (org-agenda-change-time-span 'day day-of-month))
  7351. (defun org-agenda-week-view (&optional iso-week)
  7352. "Switch to daily view for agenda.
  7353. With argument ISO-WEEK, switch to the corresponding ISO week.
  7354. If ISO-WEEK has more then 2 digits, only the last two encode the
  7355. week. Any digits before this encode a year. So 200712 means
  7356. week 12 of year 2007. Years in the range 1938-2037 can also be
  7357. written as 2-digit years."
  7358. (interactive "P")
  7359. (org-agenda-change-time-span 'week iso-week))
  7360. (defun org-agenda-month-view (&optional month)
  7361. "Switch to monthly view for agenda.
  7362. With argument MONTH, switch to that month."
  7363. (interactive "P")
  7364. (org-agenda-change-time-span 'month month))
  7365. (defun org-agenda-year-view (&optional year)
  7366. "Switch to yearly view for agenda.
  7367. With argument YEAR, switch to that year.
  7368. If MONTH has more then 2 digits, only the last two encode the
  7369. month. Any digits before this encode a year. So 200712 means
  7370. December year 2007. Years in the range 1938-2037 can also be
  7371. written as 2-digit years."
  7372. (interactive "P")
  7373. (when year
  7374. (setq year (org-small-year-to-year year)))
  7375. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7376. (org-agenda-change-time-span 'year year)
  7377. (error "Abort")))
  7378. (defun org-agenda-change-time-span (span &optional n)
  7379. "Change the agenda view to SPAN.
  7380. SPAN may be `day', `week', `month', `year'."
  7381. (org-agenda-check-type t 'agenda)
  7382. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7383. (curspan (nth 2 args)))
  7384. (if (and (not n) (equal curspan span))
  7385. (error "Viewing span is already \"%s\"" span))
  7386. (let* ((sd (or (org-get-at-bol 'day)
  7387. (nth 1 args)
  7388. org-starting-day))
  7389. (sd (org-agenda-compute-starting-span sd span n))
  7390. (org-agenda-overriding-cmd
  7391. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7392. (org-agenda-overriding-arguments
  7393. (list (car args) sd span)))
  7394. (org-agenda-redo)
  7395. (org-agenda-find-same-or-today-or-agenda))
  7396. (org-agenda-set-mode-name)
  7397. (message "Switched to %s view" span)))
  7398. (defun org-agenda-compute-starting-span (sd span &optional n)
  7399. "Compute starting date for agenda.
  7400. SPAN may be `day', `week', `month', `year'. The return value
  7401. is a cons cell with the starting date and the number of days,
  7402. so that the date SD will be in that range."
  7403. (let* ((greg (calendar-gregorian-from-absolute sd))
  7404. (dg (nth 1 greg))
  7405. (mg (car greg))
  7406. (yg (nth 2 greg)))
  7407. (cond
  7408. ((eq span 'day)
  7409. (when n
  7410. (setq sd (+ (calendar-absolute-from-gregorian
  7411. (list mg 1 yg))
  7412. n -1))))
  7413. ((eq span 'week)
  7414. (let* ((nt (calendar-day-of-week
  7415. (calendar-gregorian-from-absolute sd)))
  7416. (d (if org-agenda-start-on-weekday
  7417. (- nt org-agenda-start-on-weekday)
  7418. 0))
  7419. y1)
  7420. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7421. (when n
  7422. (require 'cal-iso)
  7423. (when (> n 99)
  7424. (setq y1 (org-small-year-to-year (/ n 100))
  7425. n (mod n 100)))
  7426. (setq sd
  7427. (calendar-absolute-from-iso
  7428. (list n 1
  7429. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7430. ((eq span 'month)
  7431. (let (y1)
  7432. (when (and n (> n 99))
  7433. (setq y1 (org-small-year-to-year (/ n 100))
  7434. n (mod n 100)))
  7435. (setq sd (calendar-absolute-from-gregorian
  7436. (list (or n mg) 1 (or y1 yg))))))
  7437. ((eq span 'year)
  7438. (setq sd (calendar-absolute-from-gregorian
  7439. (list 1 1 (or n yg))))))
  7440. sd))
  7441. (defun org-agenda-next-date-line (&optional arg)
  7442. "Jump to the next line indicating a date in agenda buffer."
  7443. (interactive "p")
  7444. (org-agenda-check-type t 'agenda 'timeline)
  7445. (beginning-of-line 1)
  7446. ;; This does not work if user makes date format that starts with a blank
  7447. (if (looking-at "^\\S-") (forward-char 1))
  7448. (if (not (re-search-forward "^\\S-" nil t arg))
  7449. (progn
  7450. (backward-char 1)
  7451. (error "No next date after this line in this buffer")))
  7452. (goto-char (match-beginning 0)))
  7453. (defun org-agenda-previous-date-line (&optional arg)
  7454. "Jump to the previous line indicating a date in agenda buffer."
  7455. (interactive "p")
  7456. (org-agenda-check-type t 'agenda 'timeline)
  7457. (beginning-of-line 1)
  7458. (if (not (re-search-backward "^\\S-" nil t arg))
  7459. (error "No previous date before this line in this buffer")))
  7460. ;; Initialize the highlight
  7461. (defvar org-hl (make-overlay 1 1))
  7462. (overlay-put org-hl 'face 'highlight)
  7463. (defun org-highlight (begin end &optional buffer)
  7464. "Highlight a region with overlay."
  7465. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7466. (defun org-unhighlight ()
  7467. "Detach overlay INDEX."
  7468. (org-detach-overlay org-hl))
  7469. (defun org-unhighlight-once ()
  7470. "Remove the highlight from its position, and this function from the hook."
  7471. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7472. (org-unhighlight))
  7473. (defvar org-agenda-pre-follow-window-conf nil)
  7474. (defun org-agenda-follow-mode ()
  7475. "Toggle follow mode in an agenda buffer."
  7476. (interactive)
  7477. (unless org-agenda-follow-mode
  7478. (setq org-agenda-pre-follow-window-conf
  7479. (current-window-configuration)))
  7480. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7481. (unless org-agenda-follow-mode
  7482. (set-window-configuration org-agenda-pre-follow-window-conf))
  7483. (org-agenda-set-mode-name)
  7484. (org-agenda-do-context-action)
  7485. (message "Follow mode is %s"
  7486. (if org-agenda-follow-mode "on" "off")))
  7487. (defun org-agenda-entry-text-mode (&optional arg)
  7488. "Toggle entry text mode in an agenda buffer."
  7489. (interactive "P")
  7490. (if (or org-agenda-tag-filter
  7491. org-agenda-category-filter
  7492. org-agenda-top-headline-filter)
  7493. (user-error "Can't show entry text in filtered views")
  7494. (setq org-agenda-entry-text-mode (or (integerp arg)
  7495. (not org-agenda-entry-text-mode)))
  7496. (org-agenda-entry-text-hide)
  7497. (and org-agenda-entry-text-mode
  7498. (let ((org-agenda-entry-text-maxlines
  7499. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7500. (org-agenda-entry-text-show)))
  7501. (org-agenda-set-mode-name)
  7502. (message "Entry text mode is %s%s"
  7503. (if org-agenda-entry-text-mode "on" "off")
  7504. (if (not org-agenda-entry-text-mode) ""
  7505. (format " (maximum number of lines is %d)"
  7506. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7507. (defun org-agenda-clockreport-mode (&optional with-filter)
  7508. "Toggle clocktable mode in an agenda buffer.
  7509. With prefix arg WITH-FILTER, make the clocktable respect the current
  7510. agenda filter."
  7511. (interactive "P")
  7512. (org-agenda-check-type t 'agenda)
  7513. (if with-filter
  7514. (setq org-agenda-clockreport-mode 'with-filter)
  7515. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7516. (org-agenda-set-mode-name)
  7517. (org-agenda-redo)
  7518. (message "Clocktable mode is %s"
  7519. (if org-agenda-clockreport-mode "on" "off")))
  7520. (defun org-agenda-log-mode (&optional special)
  7521. "Toggle log mode in an agenda buffer.
  7522. With argument SPECIAL, show all possible log items, not only the ones
  7523. configured in `org-agenda-log-mode-items'.
  7524. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7525. (interactive "P")
  7526. (org-agenda-check-type t 'agenda 'timeline)
  7527. (setq org-agenda-show-log
  7528. (cond
  7529. ((equal special '(16)) 'only)
  7530. ((eq special 'clockcheck)
  7531. (if (eq org-agenda-show-log 'clockcheck)
  7532. nil 'clockcheck))
  7533. (special '(closed clock state))
  7534. (t (not org-agenda-show-log))))
  7535. (org-agenda-set-mode-name)
  7536. (org-agenda-redo)
  7537. (message "Log mode is %s"
  7538. (if org-agenda-show-log "on" "off")))
  7539. (defun org-agenda-archives-mode (&optional with-files)
  7540. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7541. When called with a prefix argument, include all archive files as well."
  7542. (interactive "P")
  7543. (setq org-agenda-archives-mode
  7544. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7545. (org-agenda-set-mode-name)
  7546. (org-agenda-redo)
  7547. (message
  7548. "%s"
  7549. (cond
  7550. ((eq org-agenda-archives-mode nil)
  7551. "No archives are included")
  7552. ((eq org-agenda-archives-mode 'trees)
  7553. (format "Trees with :%s: tag are included" org-archive-tag))
  7554. ((eq org-agenda-archives-mode t)
  7555. (format "Trees with :%s: tag and all active archive files are included"
  7556. org-archive-tag)))))
  7557. (defun org-agenda-toggle-diary ()
  7558. "Toggle diary inclusion in an agenda buffer."
  7559. (interactive)
  7560. (org-agenda-check-type t 'agenda)
  7561. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7562. (org-agenda-redo)
  7563. (org-agenda-set-mode-name)
  7564. (message "Diary inclusion turned %s"
  7565. (if org-agenda-include-diary "on" "off")))
  7566. (defun org-agenda-toggle-deadlines ()
  7567. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7568. (interactive)
  7569. (org-agenda-check-type t 'agenda)
  7570. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7571. (org-agenda-redo)
  7572. (org-agenda-set-mode-name)
  7573. (message "Deadlines inclusion turned %s"
  7574. (if org-agenda-include-deadlines "on" "off")))
  7575. (defun org-agenda-toggle-time-grid ()
  7576. "Toggle time grid in an agenda buffer."
  7577. (interactive)
  7578. (org-agenda-check-type t 'agenda)
  7579. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7580. (org-agenda-redo)
  7581. (org-agenda-set-mode-name)
  7582. (message "Time-grid turned %s"
  7583. (if org-agenda-use-time-grid "on" "off")))
  7584. (defun org-agenda-set-mode-name ()
  7585. "Set the mode name to indicate all the small mode settings."
  7586. (setq mode-name
  7587. (list "Org-Agenda"
  7588. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7589. " "
  7590. '(:eval (org-agenda-span-name org-agenda-current-span))
  7591. (if org-agenda-follow-mode " Follow" "")
  7592. (if org-agenda-entry-text-mode " ETxt" "")
  7593. (if org-agenda-include-diary " Diary" "")
  7594. (if org-agenda-include-deadlines " Ddl" "")
  7595. (if org-agenda-use-time-grid " Grid" "")
  7596. (if (and (boundp 'org-habit-show-habits)
  7597. org-habit-show-habits) " Habit" "")
  7598. (cond
  7599. ((consp org-agenda-show-log) " LogAll")
  7600. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7601. (org-agenda-show-log " Log")
  7602. (t ""))
  7603. (if (or org-agenda-category-filter
  7604. (get 'org-agenda-category-filter :preset-filter))
  7605. '(:eval (org-propertize
  7606. (concat " <"
  7607. (mapconcat
  7608. 'identity
  7609. (append
  7610. (get 'org-agenda-category-filter :preset-filter)
  7611. org-agenda-category-filter)
  7612. "")
  7613. ">")
  7614. 'face 'org-agenda-filter-category
  7615. 'help-echo "Category used in filtering")) "")
  7616. (if (or org-agenda-tag-filter
  7617. (get 'org-agenda-tag-filter :preset-filter))
  7618. '(:eval (org-propertize
  7619. (concat " {"
  7620. (mapconcat
  7621. 'identity
  7622. (append
  7623. (get 'org-agenda-tag-filter :preset-filter)
  7624. org-agenda-tag-filter)
  7625. "")
  7626. "}")
  7627. 'face 'org-agenda-filter-tags
  7628. 'help-echo "Tags used in filtering")) "")
  7629. (if (or org-agenda-regexp-filter
  7630. (get 'org-agenda-regexp-filter :preset-filter))
  7631. '(:eval (org-propertize
  7632. (concat " ["
  7633. (mapconcat
  7634. 'identity
  7635. (append
  7636. (get 'org-agenda-regexp-filter :preset-filter)
  7637. org-agenda-regexp-filter)
  7638. "")
  7639. "]")
  7640. 'face 'org-agenda-filter-regexp
  7641. 'help-echo "Regexp used in filtering")) "")
  7642. (if org-agenda-archives-mode
  7643. (if (eq org-agenda-archives-mode t)
  7644. " Archives"
  7645. (format " :%s:" org-archive-tag))
  7646. "")
  7647. (if org-agenda-clockreport-mode
  7648. (if (eq org-agenda-clockreport-mode 'with-filter)
  7649. " Clock{}" " Clock")
  7650. "")))
  7651. (force-mode-line-update))
  7652. (define-obsolete-function-alias
  7653. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7654. (defun org-agenda-update-agenda-type ()
  7655. "Update the agenda type after each command."
  7656. (setq org-agenda-type
  7657. (or (get-text-property (point) 'org-agenda-type)
  7658. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7659. (defun org-agenda-next-line ()
  7660. "Move cursor to the next line, and show if follow mode is active."
  7661. (interactive)
  7662. (call-interactively 'next-line)
  7663. (org-agenda-do-context-action))
  7664. (defun org-agenda-previous-line ()
  7665. "Move cursor to the previous line, and show if follow-mode is active."
  7666. (interactive)
  7667. (call-interactively 'previous-line)
  7668. (org-agenda-do-context-action))
  7669. (defun org-agenda-next-item (n)
  7670. "Move cursor to next agenda item."
  7671. (interactive "p")
  7672. (let ((col (current-column)))
  7673. (dotimes (c n)
  7674. (when (next-single-property-change (point-at-eol) 'org-marker)
  7675. (move-end-of-line 1)
  7676. (goto-char (next-single-property-change (point) 'org-marker))))
  7677. (org-move-to-column col))
  7678. (org-agenda-do-context-action))
  7679. (defun org-agenda-previous-item (n)
  7680. "Move cursor to next agenda item."
  7681. (interactive "p")
  7682. (dotimes (c n)
  7683. (let ((col (current-column))
  7684. (goto (save-excursion
  7685. (move-end-of-line 0)
  7686. (previous-single-property-change (point) 'org-marker))))
  7687. (if goto (goto-char goto))
  7688. (org-move-to-column col)))
  7689. (org-agenda-do-context-action))
  7690. (defun org-agenda-do-context-action ()
  7691. "Show outline path and, maybe, follow mode window."
  7692. (let ((m (org-get-at-bol 'org-marker)))
  7693. (when (and (markerp m) (marker-buffer m))
  7694. (and org-agenda-follow-mode
  7695. (if org-agenda-follow-indirect
  7696. (org-agenda-tree-to-indirect-buffer nil)
  7697. (org-agenda-show)))
  7698. (and org-agenda-show-outline-path
  7699. (org-with-point-at m (org-display-outline-path t))))))
  7700. (defun org-agenda-show-tags ()
  7701. "Show the tags applicable to the current item."
  7702. (interactive)
  7703. (let* ((tags (org-get-at-bol 'tags)))
  7704. (if tags
  7705. (message "Tags are :%s:"
  7706. (org-no-properties (mapconcat 'identity tags ":")))
  7707. (message "No tags associated with this line"))))
  7708. (defun org-agenda-goto (&optional highlight)
  7709. "Go to the Org-mode file which contains the item at point."
  7710. (interactive)
  7711. (let* ((marker (or (org-get-at-bol 'org-marker)
  7712. (org-agenda-error)))
  7713. (buffer (marker-buffer marker))
  7714. (pos (marker-position marker)))
  7715. (switch-to-buffer-other-window buffer)
  7716. (widen)
  7717. (push-mark)
  7718. (goto-char pos)
  7719. (when (derived-mode-p 'org-mode)
  7720. (org-show-context 'agenda)
  7721. (save-excursion
  7722. (and (outline-next-heading)
  7723. (org-flag-heading nil)))) ; show the next heading
  7724. (when (outline-invisible-p)
  7725. (show-entry)) ; display invisible text
  7726. (recenter (/ (window-height) 2))
  7727. (run-hooks 'org-agenda-after-show-hook)
  7728. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7729. (defvar org-agenda-after-show-hook nil
  7730. "Normal hook run after an item has been shown from the agenda.
  7731. Point is in the buffer where the item originated.")
  7732. (defun org-agenda-kill ()
  7733. "Kill the entry or subtree belonging to the current agenda entry."
  7734. (interactive)
  7735. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7736. (let* ((bufname-orig (buffer-name))
  7737. (marker (or (org-get-at-bol 'org-marker)
  7738. (org-agenda-error)))
  7739. (buffer (marker-buffer marker))
  7740. (pos (marker-position marker))
  7741. (type (org-get-at-bol 'type))
  7742. dbeg dend (n 0) conf)
  7743. (org-with-remote-undo buffer
  7744. (with-current-buffer buffer
  7745. (save-excursion
  7746. (goto-char pos)
  7747. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7748. (setq dbeg (progn (org-back-to-heading t) (point))
  7749. dend (org-end-of-subtree t t))
  7750. (setq dbeg (point-at-bol)
  7751. dend (min (point-max) (1+ (point-at-eol)))))
  7752. (goto-char dbeg)
  7753. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7754. (setq conf (or (eq t org-agenda-confirm-kill)
  7755. (and (numberp org-agenda-confirm-kill)
  7756. (> n org-agenda-confirm-kill))))
  7757. (and conf
  7758. (not (y-or-n-p
  7759. (format "Delete entry with %d lines in buffer \"%s\"? "
  7760. n (buffer-name buffer))))
  7761. (error "Abort"))
  7762. (let ((org-agenda-buffer-name bufname-orig))
  7763. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7764. (with-current-buffer buffer (delete-region dbeg dend))
  7765. (message "Agenda item and source killed"))))
  7766. (defvar org-archive-default-command) ; defined in org-archive.el
  7767. (defun org-agenda-archive-default ()
  7768. "Archive the entry or subtree belonging to the current agenda entry."
  7769. (interactive)
  7770. (require 'org-archive)
  7771. (org-agenda-archive-with org-archive-default-command))
  7772. (defun org-agenda-archive-default-with-confirmation ()
  7773. "Archive the entry or subtree belonging to the current agenda entry."
  7774. (interactive)
  7775. (require 'org-archive)
  7776. (org-agenda-archive-with org-archive-default-command 'confirm))
  7777. (defun org-agenda-archive ()
  7778. "Archive the entry or subtree belonging to the current agenda entry."
  7779. (interactive)
  7780. (org-agenda-archive-with 'org-archive-subtree))
  7781. (defun org-agenda-archive-to-archive-sibling ()
  7782. "Move the entry to the archive sibling."
  7783. (interactive)
  7784. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7785. (defun org-agenda-archive-with (cmd &optional confirm)
  7786. "Move the entry to the archive sibling."
  7787. (interactive)
  7788. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7789. (let* ((bufname-orig (buffer-name))
  7790. (marker (or (org-get-at-bol 'org-marker)
  7791. (org-agenda-error)))
  7792. (buffer (marker-buffer marker))
  7793. (pos (marker-position marker)))
  7794. (org-with-remote-undo buffer
  7795. (with-current-buffer buffer
  7796. (if (derived-mode-p 'org-mode)
  7797. (if (and confirm
  7798. (not (y-or-n-p "Archive this subtree or entry? ")))
  7799. (error "Abort")
  7800. (save-excursion
  7801. (goto-char pos)
  7802. (let ((org-agenda-buffer-name bufname-orig))
  7803. (org-remove-subtree-entries-from-agenda))
  7804. (org-back-to-heading t)
  7805. (funcall cmd)))
  7806. (error "Archiving works only in Org-mode files"))))))
  7807. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7808. "Remove all lines in the agenda that correspond to a given subtree.
  7809. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7810. If this information is not given, the function uses the tree at point."
  7811. (let ((buf (or buf (current-buffer))) m p)
  7812. (save-excursion
  7813. (unless (and beg end)
  7814. (org-back-to-heading t)
  7815. (setq beg (point))
  7816. (org-end-of-subtree t)
  7817. (setq end (point)))
  7818. (set-buffer (get-buffer org-agenda-buffer-name))
  7819. (save-excursion
  7820. (goto-char (point-max))
  7821. (beginning-of-line 1)
  7822. (while (not (bobp))
  7823. (when (and (setq m (org-get-at-bol 'org-marker))
  7824. (equal buf (marker-buffer m))
  7825. (setq p (marker-position m))
  7826. (>= p beg)
  7827. (< p end))
  7828. (let ((inhibit-read-only t))
  7829. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7830. (beginning-of-line 0))))))
  7831. (defun org-agenda-refile (&optional goto rfloc no-update)
  7832. "Refile the item at point.
  7833. When GOTO is 0 or '(64), clear the refile cache.
  7834. When GOTO is '(16), go to the location of the last refiled item.
  7835. RFLOC can be a refile location obtained in a different way.
  7836. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7837. (interactive "P")
  7838. (cond
  7839. ((member goto '(0 (64)))
  7840. (org-refile-cache-clear))
  7841. ((equal goto '(16))
  7842. (org-refile-goto-last-stored))
  7843. (t
  7844. (let* ((buffer-orig (buffer-name))
  7845. (marker (or (org-get-at-bol 'org-hd-marker)
  7846. (org-agenda-error)))
  7847. (buffer (marker-buffer marker))
  7848. (pos (marker-position marker))
  7849. (rfloc (or rfloc
  7850. (org-refile-get-location
  7851. (if goto "Goto" "Refile to") buffer
  7852. org-refile-allow-creating-parent-nodes))))
  7853. (with-current-buffer buffer
  7854. (save-excursion
  7855. (save-restriction
  7856. (widen)
  7857. (goto-char marker)
  7858. (let ((org-agenda-buffer-name buffer-orig))
  7859. (org-remove-subtree-entries-from-agenda))
  7860. (org-refile goto buffer rfloc)))))
  7861. (unless no-update (org-agenda-redo)))))
  7862. (defun org-agenda-open-link (&optional arg)
  7863. "Open the link(s) in the current entry, if any.
  7864. This looks for a link in the displayed line in the agenda.
  7865. It also looks at the text of the entry itself."
  7866. (interactive "P")
  7867. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7868. (org-get-at-bol 'org-marker)))
  7869. (buffer (and marker (marker-buffer marker)))
  7870. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7871. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7872. (lk0 (car lkall))
  7873. (lk (if (stringp lk0) (list lk0) lk0))
  7874. (lkend (cdr lkall))
  7875. trg)
  7876. (cond
  7877. ((and buffer lk)
  7878. (mapcar (lambda(l)
  7879. (with-current-buffer buffer
  7880. (setq trg (and (string-match org-bracket-link-regexp l)
  7881. (match-string 1 l)))
  7882. (if (or (not trg) (string-match org-any-link-re trg))
  7883. (save-excursion
  7884. (save-restriction
  7885. (widen)
  7886. (goto-char marker)
  7887. (when (search-forward l nil lkend)
  7888. (goto-char (match-beginning 0))
  7889. (org-open-at-point))))
  7890. ;; This is an internal link, widen the buffer
  7891. (switch-to-buffer-other-window buffer)
  7892. (widen)
  7893. (goto-char marker)
  7894. (when (search-forward l nil lkend)
  7895. (goto-char (match-beginning 0))
  7896. (org-open-at-point)))))
  7897. lk))
  7898. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7899. (save-excursion
  7900. (beginning-of-line 1)
  7901. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7902. (org-open-link-from-string (match-string 1)))
  7903. (t (message "No link to open here")))))
  7904. (defun org-agenda-copy-local-variable (var)
  7905. "Get a variable from a referenced buffer and install it here."
  7906. (let ((m (org-get-at-bol 'org-marker)))
  7907. (when (and m (buffer-live-p (marker-buffer m)))
  7908. (org-set-local var (with-current-buffer (marker-buffer m)
  7909. (symbol-value var))))))
  7910. (defun org-agenda-switch-to (&optional delete-other-windows)
  7911. "Go to the Org-mode file which contains the item at point."
  7912. (interactive)
  7913. (if (and org-return-follows-link
  7914. (not (org-get-at-bol 'org-marker))
  7915. (org-in-regexp org-bracket-link-regexp))
  7916. (org-open-link-from-string (match-string 0))
  7917. (let* ((marker (or (org-get-at-bol 'org-marker)
  7918. (org-agenda-error)))
  7919. (buffer (marker-buffer marker))
  7920. (pos (marker-position marker)))
  7921. (org-pop-to-buffer-same-window buffer)
  7922. (and delete-other-windows (delete-other-windows))
  7923. (widen)
  7924. (goto-char pos)
  7925. (when (derived-mode-p 'org-mode)
  7926. (org-show-context 'agenda)
  7927. (save-excursion
  7928. (and (outline-next-heading)
  7929. (org-flag-heading nil))) ; show the next heading
  7930. (when (outline-invisible-p)
  7931. (show-entry)) ; display invisible text
  7932. (run-hooks 'org-agenda-after-show-hook)))))
  7933. (defun org-agenda-goto-mouse (ev)
  7934. "Go to the Org-mode file which contains the item at the mouse click."
  7935. (interactive "e")
  7936. (mouse-set-point ev)
  7937. (org-agenda-goto))
  7938. (defun org-agenda-show (&optional full-entry)
  7939. "Display the Org-mode file which contains the item at point.
  7940. With prefix argument FULL-ENTRY, make the entire entry visible
  7941. if it was hidden in the outline."
  7942. (interactive "P")
  7943. (let ((win (selected-window)))
  7944. (if full-entry
  7945. (let ((org-show-entry-below t))
  7946. (org-agenda-goto t))
  7947. (org-agenda-goto t))
  7948. (select-window win)))
  7949. (defvar org-agenda-show-window nil)
  7950. (defun org-agenda-show-and-scroll-up (&optional arg)
  7951. "Display the Org-mode file which contains the item at point.
  7952. When called repeatedly, scroll the window that is displaying the buffer.
  7953. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7954. `show-subtree' to display the item, so that drawers and logbooks stay
  7955. folded."
  7956. (interactive "P")
  7957. (let ((win (selected-window)))
  7958. (if (and (window-live-p org-agenda-show-window)
  7959. (eq this-command last-command))
  7960. (progn
  7961. (select-window org-agenda-show-window)
  7962. (ignore-errors (scroll-up)))
  7963. (org-agenda-goto t)
  7964. (if arg (org-show-entry) (show-subtree))
  7965. (setq org-agenda-show-window (selected-window)))
  7966. (select-window win)))
  7967. (defun org-agenda-show-scroll-down ()
  7968. "Scroll down the window showing the agenda."
  7969. (interactive)
  7970. (let ((win (selected-window)))
  7971. (when (window-live-p org-agenda-show-window)
  7972. (select-window org-agenda-show-window)
  7973. (ignore-errors (scroll-down))
  7974. (select-window win))))
  7975. (defun org-agenda-show-1 (&optional more)
  7976. "Display the Org-mode file which contains the item at point.
  7977. The prefix arg selects the amount of information to display:
  7978. 0 hide the subtree
  7979. 1 just show the entry according to defaults.
  7980. 2 show the children view
  7981. 3 show the subtree view
  7982. 4 show the entire subtree and any LOGBOOK drawers
  7983. 5 show the entire subtree and any drawers
  7984. With prefix argument FULL-ENTRY, make the entire entry visible
  7985. if it was hidden in the outline."
  7986. (interactive "p")
  7987. (let ((win (selected-window)))
  7988. (org-agenda-goto t)
  7989. (org-recenter-heading 1)
  7990. (cond
  7991. ((= more 0)
  7992. (hide-subtree)
  7993. (save-excursion
  7994. (org-back-to-heading)
  7995. (run-hook-with-args 'org-cycle-hook 'folded))
  7996. (message "Remote: FOLDED"))
  7997. ((and (org-called-interactively-p 'any) (= more 1))
  7998. (message "Remote: show with default settings"))
  7999. ((= more 2)
  8000. (show-entry)
  8001. (show-children)
  8002. (save-excursion
  8003. (org-back-to-heading)
  8004. (run-hook-with-args 'org-cycle-hook 'children))
  8005. (message "Remote: CHILDREN"))
  8006. ((= more 3)
  8007. (show-subtree)
  8008. (save-excursion
  8009. (org-back-to-heading)
  8010. (run-hook-with-args 'org-cycle-hook 'subtree))
  8011. (message "Remote: SUBTREE"))
  8012. ((= more 4)
  8013. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  8014. (org-drawer-regexp
  8015. (concat "^[ \t]*:\\("
  8016. (mapconcat 'regexp-quote org-drawers "\\|")
  8017. "\\):[ \t]*$")))
  8018. (show-subtree)
  8019. (save-excursion
  8020. (org-back-to-heading)
  8021. (org-cycle-hide-drawers 'subtree)))
  8022. (message "Remote: SUBTREE AND LOGBOOK"))
  8023. ((> more 4)
  8024. (show-subtree)
  8025. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8026. (select-window win)))
  8027. (defun org-recenter-heading (n)
  8028. (save-excursion
  8029. (org-back-to-heading)
  8030. (recenter n)))
  8031. (defvar org-agenda-cycle-counter nil)
  8032. (defun org-agenda-cycle-show (&optional n)
  8033. "Show the current entry in another window, with default settings.
  8034. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8035. When use repeatedly in immediate succession, the remote entry will cycle
  8036. through visibility
  8037. children -> subtree -> folded
  8038. When called with a numeric prefix arg, that arg will be passed through to
  8039. `org-agenda-show-1'. For the interpretation of that argument, see the
  8040. docstring of `org-agenda-show-1'."
  8041. (interactive "P")
  8042. (if (integerp n)
  8043. (setq org-agenda-cycle-counter n)
  8044. (if (not (eq last-command this-command))
  8045. (setq org-agenda-cycle-counter 1)
  8046. (if (equal org-agenda-cycle-counter 0)
  8047. (setq org-agenda-cycle-counter 2)
  8048. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8049. (if (> org-agenda-cycle-counter 3)
  8050. (setq org-agenda-cycle-counter 0)))))
  8051. (org-agenda-show-1 org-agenda-cycle-counter))
  8052. (defun org-agenda-recenter (arg)
  8053. "Display the Org-mode file which contains the item at point and recenter."
  8054. (interactive "P")
  8055. (let ((win (selected-window)))
  8056. (org-agenda-goto t)
  8057. (recenter arg)
  8058. (select-window win)))
  8059. (defun org-agenda-show-mouse (ev)
  8060. "Display the Org-mode file which contains the item at the mouse click."
  8061. (interactive "e")
  8062. (mouse-set-point ev)
  8063. (org-agenda-show))
  8064. (defun org-agenda-check-no-diary ()
  8065. "Check if the entry is a diary link and abort if yes."
  8066. (if (org-get-at-bol 'org-agenda-diary-link)
  8067. (org-agenda-error)))
  8068. (defun org-agenda-error ()
  8069. (error "Command not allowed in this line"))
  8070. (defun org-agenda-tree-to-indirect-buffer (arg)
  8071. "Show the subtree corresponding to the current entry in an indirect buffer.
  8072. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8073. With a numerical prefix ARG, go up to this level and then take that tree.
  8074. With a negative numeric ARG, go up by this number of levels.
  8075. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8076. use the dedicated frame)."
  8077. (interactive "P")
  8078. (if current-prefix-arg
  8079. (org-agenda-do-tree-to-indirect-buffer arg)
  8080. (let ((agenda-buffer (buffer-name))
  8081. (agenda-window (selected-window))
  8082. (indirect-window
  8083. (and org-last-indirect-buffer
  8084. (get-buffer-window org-last-indirect-buffer))))
  8085. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8086. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8087. (eq org-indirect-buffer-display 'dedicated-frame))
  8088. (unwind-protect
  8089. (unless (and indirect-window (window-live-p indirect-window))
  8090. (setq indirect-window (split-window agenda-window)))
  8091. (and indirect-window (select-window indirect-window))
  8092. (switch-to-buffer org-last-indirect-buffer :norecord)
  8093. (fit-window-to-buffer indirect-window)))
  8094. (select-window (get-buffer-window agenda-buffer)))))
  8095. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8096. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8097. (org-agenda-check-no-diary)
  8098. (let* ((marker (or (org-get-at-bol 'org-marker)
  8099. (org-agenda-error)))
  8100. (buffer (marker-buffer marker))
  8101. (pos (marker-position marker)))
  8102. (with-current-buffer buffer
  8103. (save-excursion
  8104. (goto-char pos)
  8105. (funcall 'org-tree-to-indirect-buffer arg)))))
  8106. (defvar org-last-heading-marker (make-marker)
  8107. "Marker pointing to the headline that last changed its TODO state
  8108. by a remote command from the agenda.")
  8109. (defun org-agenda-todo-nextset ()
  8110. "Switch TODO entry to next sequence."
  8111. (interactive)
  8112. (org-agenda-todo 'nextset))
  8113. (defun org-agenda-todo-previousset ()
  8114. "Switch TODO entry to previous sequence."
  8115. (interactive)
  8116. (org-agenda-todo 'previousset))
  8117. (defun org-agenda-todo (&optional arg)
  8118. "Cycle TODO state of line at point, also in Org-mode file.
  8119. This changes the line at point, all other lines in the agenda referring to
  8120. the same tree node, and the headline of the tree node in the Org-mode file."
  8121. (interactive "P")
  8122. (org-agenda-check-no-diary)
  8123. (let* ((col (current-column))
  8124. (marker (or (org-get-at-bol 'org-marker)
  8125. (org-agenda-error)))
  8126. (buffer (marker-buffer marker))
  8127. (pos (marker-position marker))
  8128. (hdmarker (org-get-at-bol 'org-hd-marker))
  8129. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8130. (inhibit-read-only t)
  8131. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8132. (org-with-remote-undo buffer
  8133. (with-current-buffer buffer
  8134. (widen)
  8135. (goto-char pos)
  8136. (org-show-context 'agenda)
  8137. (save-excursion
  8138. (and (outline-next-heading)
  8139. (org-flag-heading nil))) ; show the next heading
  8140. (let ((current-prefix-arg arg))
  8141. (call-interactively 'org-todo))
  8142. (and (bolp) (forward-char 1))
  8143. (setq newhead (org-get-heading))
  8144. (when (and (org-bound-and-true-p
  8145. org-agenda-headline-snapshot-before-repeat)
  8146. (not (equal org-agenda-headline-snapshot-before-repeat
  8147. newhead))
  8148. todayp)
  8149. (setq newhead org-agenda-headline-snapshot-before-repeat
  8150. just-one t))
  8151. (save-excursion
  8152. (org-back-to-heading)
  8153. (move-marker org-last-heading-marker (point))))
  8154. (beginning-of-line 1)
  8155. (save-excursion
  8156. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8157. (org-move-to-column col))))
  8158. (defun org-agenda-add-note (&optional arg)
  8159. "Add a time-stamped note to the entry at point."
  8160. (interactive "P")
  8161. (org-agenda-check-no-diary)
  8162. (let* ((marker (or (org-get-at-bol 'org-marker)
  8163. (org-agenda-error)))
  8164. (buffer (marker-buffer marker))
  8165. (pos (marker-position marker))
  8166. (hdmarker (org-get-at-bol 'org-hd-marker))
  8167. (inhibit-read-only t))
  8168. (with-current-buffer buffer
  8169. (widen)
  8170. (goto-char pos)
  8171. (org-show-context 'agenda)
  8172. (save-excursion
  8173. (and (outline-next-heading)
  8174. (org-flag-heading nil))) ; show the next heading
  8175. (org-add-note))))
  8176. (defun org-agenda-change-all-lines (newhead hdmarker
  8177. &optional fixface just-this)
  8178. "Change all lines in the agenda buffer which match HDMARKER.
  8179. The new content of the line will be NEWHEAD (as modified by
  8180. `org-agenda-format-item'). HDMARKER is checked with
  8181. `equal' against all `org-hd-marker' text properties in the file.
  8182. If FIXFACE is non-nil, the face of each item is modified according to
  8183. the new TODO state.
  8184. If JUST-THIS is non-nil, change just the current line, not all.
  8185. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8186. (let* ((inhibit-read-only t)
  8187. (line (org-current-line))
  8188. (org-agenda-buffer (current-buffer))
  8189. (thetags (with-current-buffer (marker-buffer hdmarker)
  8190. (save-excursion (save-restriction (widen)
  8191. (goto-char hdmarker)
  8192. (org-get-tags-at)))))
  8193. props m pl undone-face done-face finish new dotime level cat tags)
  8194. (save-excursion
  8195. (goto-char (point-max))
  8196. (beginning-of-line 1)
  8197. (while (not finish)
  8198. (setq finish (bobp))
  8199. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8200. (or (not just-this) (= (org-current-line) line))
  8201. (equal m hdmarker))
  8202. (setq props (text-properties-at (point))
  8203. dotime (org-get-at-bol 'dotime)
  8204. cat (org-get-at-bol 'org-category)
  8205. level (org-get-at-bol 'level)
  8206. tags thetags
  8207. new
  8208. (let ((org-prefix-format-compiled
  8209. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8210. org-prefix-format-compiled))
  8211. (extra (org-get-at-bol 'extra)))
  8212. (with-current-buffer (marker-buffer hdmarker)
  8213. (save-excursion
  8214. (save-restriction
  8215. (widen)
  8216. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8217. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8218. undone-face (org-get-at-bol 'undone-face)
  8219. done-face (org-get-at-bol 'done-face))
  8220. (beginning-of-line 1)
  8221. (cond
  8222. ((equal new "")
  8223. (and (looking-at ".*\n?") (replace-match "")))
  8224. ((looking-at ".*")
  8225. (replace-match new t t)
  8226. (beginning-of-line 1)
  8227. (add-text-properties (point-at-bol) (point-at-eol) props)
  8228. (when fixface
  8229. (add-text-properties
  8230. (point-at-bol) (point-at-eol)
  8231. (list 'face
  8232. (if org-last-todo-state-is-todo
  8233. undone-face done-face))))
  8234. (org-agenda-highlight-todo 'line)
  8235. (beginning-of-line 1))
  8236. (t (error "Line update did not work")))
  8237. (save-restriction
  8238. (narrow-to-region (point-at-bol) (point-at-eol))
  8239. (org-agenda-finalize)))
  8240. (beginning-of-line 0)))))
  8241. (defun org-agenda-align-tags (&optional line)
  8242. "Align all tags in agenda items to `org-agenda-tags-column'."
  8243. (let ((inhibit-read-only t) l c)
  8244. (save-excursion
  8245. (goto-char (if line (point-at-bol) (point-min)))
  8246. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8247. (if line (point-at-eol) nil) t)
  8248. (add-text-properties
  8249. (match-beginning 2) (match-end 2)
  8250. (list 'face (delq nil (let ((prop (get-text-property
  8251. (match-beginning 2) 'face)))
  8252. (or (listp prop) (setq prop (list prop)))
  8253. (if (memq 'org-tag prop)
  8254. prop
  8255. (cons 'org-tag prop))))))
  8256. (setq l (- (match-end 2) (match-beginning 2))
  8257. c (if (< org-agenda-tags-column 0)
  8258. (- (abs org-agenda-tags-column) l)
  8259. org-agenda-tags-column))
  8260. (delete-region (match-beginning 1) (match-end 1))
  8261. (goto-char (match-beginning 1))
  8262. (insert (org-add-props
  8263. (make-string (max 1 (- c (current-column))) ?\ )
  8264. (plist-put (copy-sequence (text-properties-at (point)))
  8265. 'face nil))))
  8266. (goto-char (point-min))
  8267. (org-font-lock-add-tag-faces (point-max)))))
  8268. (defun org-agenda-priority-up ()
  8269. "Increase the priority of line at point, also in Org-mode file."
  8270. (interactive)
  8271. (org-agenda-priority 'up))
  8272. (defun org-agenda-priority-down ()
  8273. "Decrease the priority of line at point, also in Org-mode file."
  8274. (interactive)
  8275. (org-agenda-priority 'down))
  8276. (defun org-agenda-priority (&optional force-direction)
  8277. "Set the priority of line at point, also in Org-mode file.
  8278. This changes the line at point, all other lines in the agenda referring to
  8279. the same tree node, and the headline of the tree node in the Org-mode file.
  8280. Called with a universal prefix arg, show the priority instead of setting it."
  8281. (interactive "P")
  8282. (if (equal force-direction '(4))
  8283. (org-show-priority)
  8284. (unless org-enable-priority-commands
  8285. (error "Priority commands are disabled"))
  8286. (org-agenda-check-no-diary)
  8287. (let* ((marker (or (org-get-at-bol 'org-marker)
  8288. (org-agenda-error)))
  8289. (hdmarker (org-get-at-bol 'org-hd-marker))
  8290. (buffer (marker-buffer hdmarker))
  8291. (pos (marker-position hdmarker))
  8292. (inhibit-read-only t)
  8293. newhead)
  8294. (org-with-remote-undo buffer
  8295. (with-current-buffer buffer
  8296. (widen)
  8297. (goto-char pos)
  8298. (org-show-context 'agenda)
  8299. (save-excursion
  8300. (and (outline-next-heading)
  8301. (org-flag-heading nil))) ; show the next heading
  8302. (funcall 'org-priority force-direction)
  8303. (end-of-line 1)
  8304. (setq newhead (org-get-heading)))
  8305. (org-agenda-change-all-lines newhead hdmarker)
  8306. (beginning-of-line 1)))))
  8307. ;; FIXME: should fix the tags property of the agenda line.
  8308. (defun org-agenda-set-tags (&optional tag onoff)
  8309. "Set tags for the current headline."
  8310. (interactive)
  8311. (org-agenda-check-no-diary)
  8312. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8313. (call-interactively 'org-change-tag-in-region)
  8314. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8315. (org-agenda-error)))
  8316. (buffer (marker-buffer hdmarker))
  8317. (pos (marker-position hdmarker))
  8318. (inhibit-read-only t)
  8319. newhead)
  8320. (org-with-remote-undo buffer
  8321. (with-current-buffer buffer
  8322. (widen)
  8323. (goto-char pos)
  8324. (save-excursion
  8325. (org-show-context 'agenda))
  8326. (save-excursion
  8327. (and (outline-next-heading)
  8328. (org-flag-heading nil))) ; show the next heading
  8329. (goto-char pos)
  8330. (if tag
  8331. (org-toggle-tag tag onoff)
  8332. (call-interactively 'org-set-tags))
  8333. (end-of-line 1)
  8334. (setq newhead (org-get-heading)))
  8335. (org-agenda-change-all-lines newhead hdmarker)
  8336. (beginning-of-line 1)))))
  8337. (defun org-agenda-set-property ()
  8338. "Set a property for the current headline."
  8339. (interactive)
  8340. (org-agenda-check-no-diary)
  8341. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8342. (org-agenda-error)))
  8343. (buffer (marker-buffer hdmarker))
  8344. (pos (marker-position hdmarker))
  8345. (inhibit-read-only t)
  8346. newhead)
  8347. (org-with-remote-undo buffer
  8348. (with-current-buffer buffer
  8349. (widen)
  8350. (goto-char pos)
  8351. (save-excursion
  8352. (org-show-context 'agenda))
  8353. (save-excursion
  8354. (and (outline-next-heading)
  8355. (org-flag-heading nil))) ; show the next heading
  8356. (goto-char pos)
  8357. (call-interactively 'org-set-property)))))
  8358. (defun org-agenda-set-effort ()
  8359. "Set the effort property for the current headline."
  8360. (interactive)
  8361. (org-agenda-check-no-diary)
  8362. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8363. (org-agenda-error)))
  8364. (buffer (marker-buffer hdmarker))
  8365. (pos (marker-position hdmarker))
  8366. (inhibit-read-only t)
  8367. newhead)
  8368. (org-with-remote-undo buffer
  8369. (with-current-buffer buffer
  8370. (widen)
  8371. (goto-char pos)
  8372. (save-excursion
  8373. (org-show-context 'agenda))
  8374. (save-excursion
  8375. (and (outline-next-heading)
  8376. (org-flag-heading nil))) ; show the next heading
  8377. (goto-char pos)
  8378. (call-interactively 'org-set-effort)
  8379. (end-of-line 1)
  8380. (setq newhead (org-get-heading)))
  8381. (org-agenda-change-all-lines newhead hdmarker))))
  8382. (defun org-agenda-toggle-archive-tag ()
  8383. "Toggle the archive tag for the current entry."
  8384. (interactive)
  8385. (org-agenda-check-no-diary)
  8386. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8387. (org-agenda-error)))
  8388. (buffer (marker-buffer hdmarker))
  8389. (pos (marker-position hdmarker))
  8390. (inhibit-read-only t)
  8391. newhead)
  8392. (org-with-remote-undo buffer
  8393. (with-current-buffer buffer
  8394. (widen)
  8395. (goto-char pos)
  8396. (org-show-context 'agenda)
  8397. (save-excursion
  8398. (and (outline-next-heading)
  8399. (org-flag-heading nil))) ; show the next heading
  8400. (call-interactively 'org-toggle-archive-tag)
  8401. (end-of-line 1)
  8402. (setq newhead (org-get-heading)))
  8403. (org-agenda-change-all-lines newhead hdmarker)
  8404. (beginning-of-line 1))))
  8405. (defun org-agenda-do-date-later (arg)
  8406. (interactive "P")
  8407. (cond
  8408. ((or (equal arg '(16))
  8409. (memq last-command
  8410. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8411. (setq this-command 'org-agenda-date-later-minutes)
  8412. (org-agenda-date-later-minutes 1))
  8413. ((or (equal arg '(4))
  8414. (memq last-command
  8415. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8416. (setq this-command 'org-agenda-date-later-hours)
  8417. (org-agenda-date-later-hours 1))
  8418. (t
  8419. (org-agenda-date-later (prefix-numeric-value arg)))))
  8420. (defun org-agenda-do-date-earlier (arg)
  8421. (interactive "P")
  8422. (cond
  8423. ((or (equal arg '(16))
  8424. (memq last-command
  8425. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8426. (setq this-command 'org-agenda-date-earlier-minutes)
  8427. (org-agenda-date-earlier-minutes 1))
  8428. ((or (equal arg '(4))
  8429. (memq last-command
  8430. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8431. (setq this-command 'org-agenda-date-earlier-hours)
  8432. (org-agenda-date-earlier-hours 1))
  8433. (t
  8434. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8435. (defun org-agenda-date-later (arg &optional what)
  8436. "Change the date of this item to ARG day(s) later."
  8437. (interactive "p")
  8438. (org-agenda-check-type t 'agenda 'timeline)
  8439. (org-agenda-check-no-diary)
  8440. (let* ((marker (or (org-get-at-bol 'org-marker)
  8441. (org-agenda-error)))
  8442. (buffer (marker-buffer marker))
  8443. (pos (marker-position marker))
  8444. cdate today)
  8445. (org-with-remote-undo buffer
  8446. (with-current-buffer buffer
  8447. (widen)
  8448. (goto-char pos)
  8449. (if (not (org-at-timestamp-p))
  8450. (error "Cannot find time stamp"))
  8451. (when (and org-agenda-move-date-from-past-immediately-to-today
  8452. (equal arg 1)
  8453. (or (not what) (eq what 'day))
  8454. (not (save-match-data (org-at-date-range-p))))
  8455. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8456. cdate (calendar-absolute-from-gregorian
  8457. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8458. today (org-today))
  8459. (if (> today cdate)
  8460. ;; immediately shift to today
  8461. (setq arg (- today cdate))))
  8462. (org-timestamp-change arg (or what 'day))
  8463. (when (and (org-at-date-range-p)
  8464. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8465. (let ((end org-last-changed-timestamp))
  8466. (org-timestamp-change arg (or what 'day))
  8467. (setq org-last-changed-timestamp
  8468. (concat org-last-changed-timestamp "--" end)))))
  8469. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8470. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8471. (defun org-agenda-date-earlier (arg &optional what)
  8472. "Change the date of this item to ARG day(s) earlier."
  8473. (interactive "p")
  8474. (org-agenda-date-later (- arg) what))
  8475. (defun org-agenda-date-later-minutes (arg)
  8476. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8477. (interactive "p")
  8478. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8479. (org-agenda-date-later arg 'minute))
  8480. (defun org-agenda-date-earlier-minutes (arg)
  8481. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8482. (interactive "p")
  8483. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8484. (org-agenda-date-earlier arg 'minute))
  8485. (defun org-agenda-date-later-hours (arg)
  8486. "Change the time of this item, in hour steps."
  8487. (interactive "p")
  8488. (org-agenda-date-later arg 'hour))
  8489. (defun org-agenda-date-earlier-hours (arg)
  8490. "Change the time of this item, in hour steps."
  8491. (interactive "p")
  8492. (org-agenda-date-earlier arg 'hour))
  8493. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8494. "Show new date stamp via text properties."
  8495. ;; We use text properties to make this undoable
  8496. (let ((inhibit-read-only t))
  8497. (setq stamp (concat prefix " => " stamp " "))
  8498. (save-excursion
  8499. (goto-char (point-max))
  8500. (while (not (bobp))
  8501. (when (equal marker (org-get-at-bol 'org-marker))
  8502. (org-move-to-column (- (window-width) (length stamp)) t)
  8503. (org-agenda-fix-tags-filter-overlays-at (point))
  8504. (if (featurep 'xemacs)
  8505. ;; Use `duplicable' property to trigger undo recording
  8506. (let ((ex (make-extent nil nil))
  8507. (gl (make-glyph stamp)))
  8508. (set-glyph-face gl 'secondary-selection)
  8509. (set-extent-properties
  8510. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8511. (insert-extent ex (1- (point)) (point-at-eol)))
  8512. (add-text-properties
  8513. (1- (point)) (point-at-eol)
  8514. (list 'display (org-add-props stamp nil
  8515. 'face 'secondary-selection))))
  8516. (beginning-of-line 1))
  8517. (beginning-of-line 0)))))
  8518. (defun org-agenda-date-prompt (arg)
  8519. "Change the date of this item. Date is prompted for, with default today.
  8520. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8521. be used to request time specification in the time stamp."
  8522. (interactive "P")
  8523. (org-agenda-check-type t 'agenda 'timeline)
  8524. (org-agenda-check-no-diary)
  8525. (let* ((marker (or (org-get-at-bol 'org-marker)
  8526. (org-agenda-error)))
  8527. (buffer (marker-buffer marker))
  8528. (pos (marker-position marker)))
  8529. (org-with-remote-undo buffer
  8530. (with-current-buffer buffer
  8531. (widen)
  8532. (goto-char pos)
  8533. (if (not (org-at-timestamp-p t))
  8534. (error "Cannot find time stamp"))
  8535. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8536. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8537. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8538. (defun org-agenda-schedule (arg &optional time)
  8539. "Schedule the item at point.
  8540. ARG is passed through to `org-schedule'."
  8541. (interactive "P")
  8542. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8543. (org-agenda-check-no-diary)
  8544. (let* ((marker (or (org-get-at-bol 'org-marker)
  8545. (org-agenda-error)))
  8546. (type (marker-insertion-type marker))
  8547. (buffer (marker-buffer marker))
  8548. (pos (marker-position marker))
  8549. (org-insert-labeled-timestamps-at-point nil)
  8550. ts)
  8551. (set-marker-insertion-type marker t)
  8552. (org-with-remote-undo buffer
  8553. (with-current-buffer buffer
  8554. (widen)
  8555. (goto-char pos)
  8556. (setq ts (org-schedule arg time)))
  8557. (org-agenda-show-new-time marker ts " S"))
  8558. (message "%s" ts)))
  8559. (defun org-agenda-deadline (arg &optional time)
  8560. "Schedule the item at point.
  8561. ARG is passed through to `org-deadline'."
  8562. (interactive "P")
  8563. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8564. (org-agenda-check-no-diary)
  8565. (let* ((marker (or (org-get-at-bol 'org-marker)
  8566. (org-agenda-error)))
  8567. (buffer (marker-buffer marker))
  8568. (pos (marker-position marker))
  8569. (org-insert-labeled-timestamps-at-point nil)
  8570. ts)
  8571. (org-with-remote-undo buffer
  8572. (with-current-buffer buffer
  8573. (widen)
  8574. (goto-char pos)
  8575. (setq ts (org-deadline arg time)))
  8576. (org-agenda-show-new-time marker ts " D"))
  8577. (message "%s" ts)))
  8578. (defun org-agenda-clock-in (&optional arg)
  8579. "Start the clock on the currently selected item."
  8580. (interactive "P")
  8581. (org-agenda-check-no-diary)
  8582. (if (equal arg '(4))
  8583. (org-clock-in arg)
  8584. (let* ((marker (or (org-get-at-bol 'org-marker)
  8585. (org-agenda-error)))
  8586. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8587. (pos (marker-position marker))
  8588. (col (current-column))
  8589. newhead)
  8590. (org-with-remote-undo (marker-buffer marker)
  8591. (with-current-buffer (marker-buffer marker)
  8592. (widen)
  8593. (goto-char pos)
  8594. (org-show-context 'agenda)
  8595. (org-show-entry)
  8596. (org-cycle-hide-drawers 'children)
  8597. (org-clock-in arg)
  8598. (setq newhead (org-get-heading)))
  8599. (org-agenda-change-all-lines newhead hdmarker))
  8600. (org-move-to-column col))))
  8601. (defun org-agenda-clock-out ()
  8602. "Stop the currently running clock."
  8603. (interactive)
  8604. (unless (marker-buffer org-clock-marker)
  8605. (error "No running clock"))
  8606. (let ((marker (make-marker)) (col (current-column)) newhead)
  8607. (org-with-remote-undo (marker-buffer org-clock-marker)
  8608. (with-current-buffer (marker-buffer org-clock-marker)
  8609. (save-excursion
  8610. (save-restriction
  8611. (widen)
  8612. (goto-char org-clock-marker)
  8613. (org-back-to-heading t)
  8614. (move-marker marker (point))
  8615. (org-clock-out)
  8616. (setq newhead (org-get-heading))))))
  8617. (org-agenda-change-all-lines newhead marker)
  8618. (move-marker marker nil)
  8619. (org-move-to-column col)
  8620. (org-agenda-unmark-clocking-task)))
  8621. (defun org-agenda-clock-cancel (&optional arg)
  8622. "Cancel the currently running clock."
  8623. (interactive "P")
  8624. (unless (marker-buffer org-clock-marker)
  8625. (user-error "No running clock"))
  8626. (org-with-remote-undo (marker-buffer org-clock-marker)
  8627. (org-clock-cancel)))
  8628. (defun org-agenda-clock-goto ()
  8629. "Jump to the currently clocked in task within the agenda.
  8630. If the currently clocked in task is not listed in the agenda
  8631. buffer, display it in another window."
  8632. (interactive)
  8633. (let (pos)
  8634. (mapc (lambda (o)
  8635. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8636. (setq pos (overlay-start o))))
  8637. (overlays-in (point-min) (point-max)))
  8638. (cond (pos (goto-char pos))
  8639. ;; If the currently clocked entry is not in the agenda
  8640. ;; buffer, we visit it in another window:
  8641. (org-clock-current-task
  8642. (org-switch-to-buffer-other-window (org-clock-goto)))
  8643. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8644. (defun org-agenda-diary-entry-in-org-file ()
  8645. "Make a diary entry in the file `org-agenda-diary-file'."
  8646. (let (d1 d2 char (text "") dp1 dp2)
  8647. (if (equal (buffer-name) "*Calendar*")
  8648. (setq d1 (calendar-cursor-to-date t)
  8649. d2 (car calendar-mark-ring))
  8650. (setq dp1 (get-text-property (point-at-bol) 'day))
  8651. (unless dp1 (user-error "No date defined in current line"))
  8652. (setq d1 (calendar-gregorian-from-absolute dp1)
  8653. d2 (and (ignore-errors (mark))
  8654. (save-excursion
  8655. (goto-char (mark))
  8656. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8657. (calendar-gregorian-from-absolute dp2))))
  8658. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8659. (setq char (read-char-exclusive))
  8660. (cond
  8661. ((equal char ?d)
  8662. (setq text (read-string "Day entry: "))
  8663. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8664. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8665. ((equal char ?a)
  8666. (setq d1 (list (car d1) (nth 1 d1)
  8667. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8668. (nth 2 d1))))
  8669. (setq text (read-string "Anniversary (use %d to show years): "))
  8670. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8671. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8672. ((equal char ?b)
  8673. (setq text (read-string "Block entry: "))
  8674. (unless (and d1 d2 (not (equal d1 d2)))
  8675. (user-error "No block of days selected"))
  8676. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8677. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8678. ((equal char ?j)
  8679. (org-switch-to-buffer-other-window
  8680. (find-file-noselect org-agenda-diary-file))
  8681. (require 'org-datetree)
  8682. (org-datetree-find-date-create d1)
  8683. (org-reveal t))
  8684. (t (user-error "Invalid selection character `%c'" char)))))
  8685. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8686. "Where in `org-agenda-diary-file' should new entries be added?
  8687. Valid values:
  8688. date-tree in the date tree, as child of the date
  8689. top-level as top-level entries at the end of the file."
  8690. :group 'org-agenda
  8691. :type '(choice
  8692. (const :tag "in a date tree" date-tree)
  8693. (const :tag "as top level at end of file" top-level)))
  8694. (defcustom org-agenda-insert-diary-extract-time nil
  8695. "Non-nil means extract any time specification from the diary entry."
  8696. :group 'org-agenda
  8697. :version "24.1"
  8698. :type 'boolean)
  8699. (defcustom org-agenda-bulk-mark-char ">"
  8700. "A single-character string to be used as the bulk mark."
  8701. :group 'org-agenda
  8702. :version "24.1"
  8703. :type 'string)
  8704. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8705. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8706. If TEXT is not empty, it will become the headline of the new entry, and
  8707. the resulting entry will not be shown. When TEXT is empty, switch to
  8708. `org-agenda-diary-file' and let the user finish the entry there.&