org-agenda.el 447 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; URL: https://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 <https://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org.
  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 'cl-lib)
  42. (require 'ol)
  43. (require 'org-fold-core)
  44. (require 'org)
  45. (require 'org-macs)
  46. (require 'org-refile)
  47. (declare-function diary-add-to-list "diary-lib"
  48. (date string specifier &optional marker globcolor literal))
  49. (declare-function calendar-iso-to-absolute "cal-iso" (date))
  50. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  51. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  52. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  53. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  54. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  55. (declare-function calendar-french-date-string "cal-french" (&optional date))
  56. (declare-function calendar-goto-date "cal-move" (date))
  57. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  58. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  59. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  60. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  61. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  62. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  63. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  64. (declare-function calendar-check-holidays "holidays" (date))
  65. (declare-function org-columns-remove-overlays "org-colview" ())
  66. (declare-function org-datetree-find-date-create "org-datetree"
  67. (date &optional keep-restriction))
  68. (declare-function org-columns-quit "org-colview" ())
  69. (declare-function diary-date-display-form "diary-lib" (&optional type))
  70. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  71. (declare-function org-element-property "org-element" (property element))
  72. (declare-function org-element--cache-active-p "org-element"
  73. (&optional called-from-cache-change-func-p))
  74. (declare-function org-habit-insert-consistency-graphs
  75. "org-habit" (&optional line))
  76. (declare-function org-is-habit-p "org-habit" (&optional pom))
  77. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  78. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  79. (declare-function org-agenda-columns "org-colview" ())
  80. (declare-function org-add-archive-files "org-archive" (files))
  81. (declare-function org-capture "org-capture" (&optional goto keys))
  82. (declare-function org-clock-modify-effort-estimate "org-clock" (&optional value))
  83. (declare-function org-element-type "org-element" (&optional element))
  84. (defvar calendar-mode-map)
  85. (defvar org-clock-current-task)
  86. (defvar org-current-tag-alist)
  87. (defvar org-mobile-force-id-on-agenda-items)
  88. (defvar org-habit-show-habits)
  89. (defvar org-habit-show-habits-only-for-today)
  90. (defvar org-habit-show-all-today)
  91. (defvar org-habit-scheduled-past-days)
  92. ;; Defined somewhere in this file, but used before definition.
  93. (defvar org-agenda-buffer-name "*Org Agenda*")
  94. (defvar org-agenda-title-append nil)
  95. (defvar org-agenda-overriding-header)
  96. ;; (with-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  97. ;; (with-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  98. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  99. (defvar org-agenda-undo-list nil
  100. "List of undoable operations in the agenda since last refresh.")
  101. (defvar org-agenda-pending-undo-list nil
  102. "In a series of undo commands, this is the list of remaining undo items.")
  103. (defcustom org-agenda-confirm-kill 1
  104. "When set, remote killing from the agenda buffer needs confirmation.
  105. When t, a confirmation is always needed. When a number N, confirmation is
  106. only needed when the text to be killed contains more than N non-white lines."
  107. :group 'org-agenda
  108. :type '(choice
  109. (const :tag "Never" nil)
  110. (const :tag "Always" t)
  111. (integer :tag "When more than N lines")))
  112. (defcustom org-agenda-compact-blocks nil
  113. "Non-nil means make the block agenda more compact.
  114. This is done globally by leaving out lines like the agenda span
  115. name and week number or the separator lines."
  116. :group 'org-agenda
  117. :type 'boolean)
  118. (defcustom org-agenda-block-separator
  119. (if (and (display-graphic-p)
  120. (char-displayable-p ?─))
  121. ?─
  122. ?=)
  123. "The separator between blocks in the agenda.
  124. If this is a string, it will be used as the separator, with a newline added.
  125. If it is a character, it will be repeated to fill the window width.
  126. If nil the separator is disabled. In `org-agenda-custom-commands' this
  127. addresses the separator between the current and the previous block."
  128. :group 'org-agenda
  129. :version "29.1"
  130. :type '(choice
  131. (const :tag "Disabled" nil)
  132. (character)
  133. (string)))
  134. (defgroup org-agenda-export nil
  135. "Options concerning exporting agenda views in Org mode."
  136. :tag "Org Agenda Export"
  137. :group 'org-agenda)
  138. (defcustom org-agenda-with-colors t
  139. "Non-nil means use colors in agenda views."
  140. :group 'org-agenda-export
  141. :type 'boolean)
  142. (defcustom org-agenda-exporter-settings nil
  143. ;; FIXME: Do we really want to evaluate those settings and thus force
  144. ;; the user to use `quote' all the time?
  145. "Alist of variable/value pairs that should be active during agenda export.
  146. This is a good place to set options for ps-print and for htmlize.
  147. Note that the way this is implemented, the values will be evaluated
  148. before assigned to the variables. So make sure to quote values you do
  149. *not* want evaluated, for example
  150. (setq org-agenda-exporter-settings
  151. \\='((ps-print-color-p \\='black-white)))"
  152. :group 'org-agenda-export
  153. :type '(repeat
  154. (list
  155. (variable)
  156. (sexp :tag "Value"))))
  157. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  158. "Hook run in a temporary buffer before writing the agenda to an export file.
  159. A useful function for this hook is `org-agenda-add-entry-text'."
  160. :group 'org-agenda-export
  161. :type 'hook
  162. :options '(org-agenda-add-entry-text))
  163. (defcustom org-agenda-add-entry-text-maxlines 0
  164. "Maximum number of entry text lines to be added to agenda.
  165. This is only relevant when `org-agenda-add-entry-text' is part of
  166. `org-agenda-before-write-hook', which is the default.
  167. When this is 0, nothing will happen. When it is greater than 0, it
  168. specifies the maximum number of lines that will be added for each entry
  169. that is listed in the agenda view.
  170. Note that this variable is not used during display, only when exporting
  171. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  172. and `org-agenda-entry-text-maxlines'."
  173. :group 'org-agenda
  174. :type 'integer)
  175. (defcustom org-agenda-add-entry-text-descriptive-links t
  176. "Non-nil means export org-links as descriptive links in agenda added text.
  177. This variable applies to the text added to the agenda when
  178. `org-agenda-add-entry-text-maxlines' is larger than 0.
  179. When this variable is nil, the URL will (also) be shown."
  180. :group 'org-agenda
  181. :type 'boolean)
  182. (defcustom org-agenda-export-html-style nil
  183. "The style specification for exported HTML Agenda files.
  184. If this variable contains a string, it will replace the default <style>
  185. section as produced by `htmlize'.
  186. Since there are different ways of setting style information, this variable
  187. needs to contain the full HTML structure to provide a style, including the
  188. surrounding HTML tags. The style specifications should include definitions
  189. the fonts used by the agenda, here is an example:
  190. <style type=\"text/css\">
  191. p { font-weight: normal; color: gray; }
  192. .org-agenda-structure {
  193. font-size: 110%;
  194. color: #003399;
  195. font-weight: 600;
  196. }
  197. .org-todo {
  198. color: #cc6666;
  199. font-weight: bold;
  200. }
  201. .org-agenda-done {
  202. color: #339933;
  203. }
  204. .org-done {
  205. color: #339933;
  206. }
  207. .title { text-align: center; }
  208. .todo, .deadline { color: red; }
  209. .done { color: green; }
  210. </style>
  211. or, if you want to keep the style in a file,
  212. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  213. As the value of this option simply gets inserted into the HTML <head> header,
  214. you can \"misuse\" it to also add other text to the header."
  215. :group 'org-agenda-export
  216. :group 'org-export-html
  217. :type '(choice
  218. (const nil)
  219. (string)))
  220. (defcustom org-agenda-persistent-filter nil
  221. "When set, keep filters from one agenda view to the next."
  222. :group 'org-agenda
  223. :type 'boolean)
  224. (defgroup org-agenda-custom-commands nil
  225. "Options concerning agenda views in Org mode."
  226. :tag "Org Agenda Custom Commands"
  227. :group 'org-agenda)
  228. (defconst org-sorting-choice
  229. '(choice
  230. (const time-up) (const time-down)
  231. (const timestamp-up) (const timestamp-down)
  232. (const scheduled-up) (const scheduled-down)
  233. (const deadline-up) (const deadline-down)
  234. (const ts-up) (const ts-down)
  235. (const tsia-up) (const tsia-down)
  236. (const category-keep) (const category-up) (const category-down)
  237. (const tag-down) (const tag-up)
  238. (const priority-up) (const priority-down)
  239. (const todo-state-up) (const todo-state-down)
  240. (const effort-up) (const effort-down)
  241. (const habit-up) (const habit-down)
  242. (const alpha-up) (const alpha-down)
  243. (const user-defined-up) (const user-defined-down))
  244. "Sorting choices.")
  245. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  246. ;; the new variable `org-agenda-tag-filter-preset'.
  247. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  248. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  249. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  250. "List of types searched for when creating the daily/weekly agenda.
  251. This variable is a list of symbols that controls the types of
  252. items that appear in the daily/weekly agenda. Allowed symbols in this
  253. list are
  254. :timestamp List items containing a date stamp or date range matching
  255. the selected date. This includes sexp entries in angular
  256. brackets.
  257. :sexp List entries resulting from plain diary-like sexps.
  258. :deadline List deadline due on that date. When the date is today,
  259. also list any deadlines past due, or due within
  260. `org-deadline-warning-days'.
  261. :deadline* Same as above, but only include the deadline if it has an
  262. hour specification as [h]h:mm.
  263. :scheduled List all items which are scheduled for the given date.
  264. The diary for *today* also contains items which were
  265. scheduled earlier and are not yet marked DONE.
  266. :scheduled* Same as above, but only include the scheduled item if it
  267. has an hour specification as [h]h:mm.
  268. By default, all four non-starred types are turned on.
  269. When :scheduled* or :deadline* are included, :schedule or :deadline
  270. will be ignored.
  271. Never set this variable globally using `setq', because then it
  272. will apply to all future agenda commands. Instead, bind it with
  273. `let' to scope it dynamically into the agenda-constructing
  274. command. A good way to set it is through options in
  275. `org-agenda-custom-commands'. For a more flexible (though
  276. somewhat less efficient) way of determining what is included in
  277. the daily/weekly agenda, see `org-agenda-skip-function'.")
  278. (defconst org-agenda-custom-commands-local-options
  279. `(repeat :tag "Local settings for this command. Remember to quote values"
  280. (choice :tag "Setting"
  281. (list :tag "Heading for this block"
  282. (const org-agenda-overriding-header)
  283. (string :tag "Headline"))
  284. (list :tag "Files to be searched"
  285. (const org-agenda-files)
  286. (list
  287. (const :format "" quote)
  288. (repeat (file))))
  289. (list :tag "Sorting strategy"
  290. (const org-agenda-sorting-strategy)
  291. (list
  292. (const :format "" quote)
  293. (repeat
  294. ,org-sorting-choice)))
  295. (list :tag "Prefix format"
  296. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  297. (string))
  298. (list :tag "Number of days in agenda"
  299. (const org-agenda-span)
  300. (list
  301. (const :format "" quote)
  302. (choice (const :tag "Day" day)
  303. (const :tag "Week" week)
  304. (const :tag "Fortnight" fortnight)
  305. (const :tag "Month" month)
  306. (const :tag "Year" year)
  307. (integer :tag "Custom"))))
  308. (list :tag "Fixed starting date"
  309. (const org-agenda-start-day)
  310. (string :value "2007-11-01"))
  311. (list :tag "Start on day of week"
  312. (const org-agenda-start-on-weekday)
  313. (choice :value 1
  314. (const :tag "Today" nil)
  315. (integer :tag "Weekday No.")))
  316. (list :tag "Include data from diary"
  317. (const org-agenda-include-diary)
  318. (boolean))
  319. (list :tag "Deadline Warning days"
  320. (const org-deadline-warning-days)
  321. (integer :value 1))
  322. (list :tag "Category filter preset"
  323. (const org-agenda-category-filter-preset)
  324. (list
  325. (const :format "" quote)
  326. (repeat
  327. (string :tag "+category or -category"))))
  328. (list :tag "Tags filter preset"
  329. (const org-agenda-tag-filter-preset)
  330. (list
  331. (const :format "" quote)
  332. (repeat
  333. (string :tag "+tag or -tag"))))
  334. (list :tag "Effort filter preset"
  335. (const org-agenda-effort-filter-preset)
  336. (list
  337. (const :format "" quote)
  338. (repeat
  339. (string :tag "+=10 or -=10 or +<10 or ->10"))))
  340. (list :tag "Regexp filter preset"
  341. (const org-agenda-regexp-filter-preset)
  342. (list
  343. (const :format "" quote)
  344. (repeat
  345. (string :tag "+regexp or -regexp"))))
  346. (list :tag "Set daily/weekly entry types"
  347. (const org-agenda-entry-types)
  348. (list
  349. (const :format "" quote)
  350. (set :greedy t :value ,org-agenda-entry-types
  351. (const :deadline)
  352. (const :scheduled)
  353. (const :deadline*)
  354. (const :scheduled*)
  355. (const :timestamp)
  356. (const :sexp))))
  357. (list :tag "Columns format"
  358. (const org-overriding-columns-format)
  359. (string :tag "Format"))
  360. (list :tag "Standard skipping condition"
  361. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  362. (const org-agenda-skip-function)
  363. (list
  364. (const :format "" quote)
  365. (list
  366. (choice
  367. :tag "Skipping range"
  368. (const :tag "Skip entry" org-agenda-skip-entry-if)
  369. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  370. (repeat :inline t :tag "Conditions for skipping"
  371. (choice
  372. :tag "Condition type"
  373. (list :tag "Regexp matches" :inline t
  374. (const :format "" regexp)
  375. (regexp))
  376. (list :tag "Regexp does not match" :inline t
  377. (const :format "" notregexp)
  378. (regexp))
  379. (list :tag "TODO state is" :inline t
  380. (const todo)
  381. (choice
  382. (const :tag "Any not-done state" todo)
  383. (const :tag "Any done state" done)
  384. (const :tag "Any state" any)
  385. (list :tag "Keyword list"
  386. (const :format "" quote)
  387. (repeat (string :tag "Keyword")))))
  388. (list :tag "TODO state is not" :inline t
  389. (const nottodo)
  390. (choice
  391. (const :tag "Any not-done state" todo)
  392. (const :tag "Any done state" done)
  393. (const :tag "Any state" any)
  394. (list :tag "Keyword list"
  395. (const :format "" quote)
  396. (repeat (string :tag "Keyword")))))
  397. (const :tag "scheduled" scheduled)
  398. (const :tag "not scheduled" notscheduled)
  399. (const :tag "deadline" deadline)
  400. (const :tag "no deadline" notdeadline)
  401. (const :tag "timestamp" timestamp)
  402. (const :tag "no timestamp" nottimestamp))))))
  403. (list :tag "Non-standard skipping condition"
  404. :value (org-agenda-skip-function)
  405. (const org-agenda-skip-function)
  406. (sexp :tag "Function or form (quoted!)"))
  407. (list :tag "Any variable"
  408. (variable :tag "Variable")
  409. (sexp :tag "Value (sexp)"))))
  410. "Selection of examples for agenda command settings.
  411. This will be spliced into the custom type of
  412. `org-agenda-custom-commands'.")
  413. (defcustom org-agenda-custom-commands
  414. '(("n" "Agenda and all TODOs" ((agenda "") (alltodo ""))))
  415. "Custom commands for the agenda.
  416. \\<org-mode-map>
  417. These commands will be offered on the splash screen displayed by the
  418. agenda dispatcher `\\[org-agenda]'. Each entry is a list like this:
  419. (key desc type match settings files)
  420. key The key (one or more characters as a string) to be associated
  421. with the command.
  422. desc A description of the command. When omitted or nil, a default
  423. description is built using MATCH.
  424. type The command type, any of the following symbols:
  425. agenda The daily/weekly agenda.
  426. agenda* Appointments for current week/day.
  427. todo Entries with a specific TODO keyword, in all agenda files.
  428. search Entries containing search words entry or headline.
  429. tags Tags/Property/TODO match in all agenda files.
  430. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  431. todo-tree Sparse tree of specific TODO keyword in *current* file.
  432. tags-tree Sparse tree with all tags matches in *current* file.
  433. occur-tree Occur sparse tree for *current* file.
  434. alltodo The global TODO list.
  435. stuck Stuck projects.
  436. ... A user-defined function.
  437. match What to search for:
  438. - a single keyword for TODO keyword searches
  439. - a tags/property/todo match expression for searches
  440. - a word search expression for text searches.
  441. - a regular expression for occur searches
  442. For all other commands, this should be the empty string.
  443. settings A list of option settings, similar to that in a let form, so like
  444. this: ((opt1 val1) (opt2 val2) ...). The values will be
  445. evaluated at the moment of execution, so quote them when needed.
  446. files A list of files to write the produced agenda buffer to with
  447. the command `org-store-agenda-views'.
  448. If a file name ends in \".html\", an HTML version of the buffer
  449. is written out. If it ends in \".ps\", a PostScript version is
  450. produced. Otherwise, only the plain text is written to the file.
  451. You can also define a set of commands, to create a composite agenda buffer.
  452. In this case, an entry looks like this:
  453. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  454. where
  455. desc A description string to be displayed in the dispatcher menu.
  456. cmd An agenda command, similar to the above. However, tree commands
  457. are not allowed. Valid commands for a set are:
  458. (agenda \"\" settings)
  459. (agenda* \"\" settings)
  460. (alltodo \"\" settings)
  461. (stuck \"\" settings)
  462. (todo \"match\" settings files)
  463. (search \"match\" settings files)
  464. (tags \"match\" settings files)
  465. (tags-todo \"match\" settings files)
  466. Each command can carry a list of options, and another set of options can be
  467. given for the whole set of commands. Individual command options take
  468. precedence over the general options.
  469. When using several characters as key to a command, the first characters
  470. are prefix commands. For the dispatcher to display useful information, you
  471. should provide a description for the prefix, like
  472. (setq org-agenda-custom-commands
  473. \\='((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  474. (\"hl\" tags \"+HOME+Lisa\")
  475. (\"hp\" tags \"+HOME+Peter\")
  476. (\"hk\" tags \"+HOME+Kim\")))
  477. See also Info node `(org) Custom Agenda Views'."
  478. :group 'org-agenda-custom-commands
  479. :type `(repeat
  480. (choice :value ("x" "Describe command here" tags "" nil)
  481. (list :tag "Single command"
  482. (string :tag "Access Key(s) ")
  483. (option (string :tag "Description"))
  484. (choice
  485. (const :tag "Agenda" agenda)
  486. (const :tag "TODO list" alltodo)
  487. (const :tag "Search words" search)
  488. (const :tag "Stuck projects" stuck)
  489. (const :tag "Tags/Property match (all agenda files)" tags)
  490. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  491. (const :tag "TODO keyword search (all agenda files)" todo)
  492. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  493. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  494. (const :tag "Occur tree (current buffer)" occur-tree)
  495. (sexp :tag "Other, user-defined function"))
  496. (string :tag "Match (only for some commands)")
  497. ,org-agenda-custom-commands-local-options
  498. (option (repeat :tag "Export" (file :tag "Export to"))))
  499. (list :tag "Command series, all agenda files"
  500. (string :tag "Access Key(s)")
  501. (string :tag "Description ")
  502. (repeat :tag "Component"
  503. (choice
  504. (list :tag "Agenda"
  505. (const :format "" agenda)
  506. (const :tag "" :format "" "")
  507. ,org-agenda-custom-commands-local-options)
  508. (list :tag "TODO list (all keywords)"
  509. (const :format "" alltodo)
  510. (const :tag "" :format "" "")
  511. ,org-agenda-custom-commands-local-options)
  512. (list :tag "Search words"
  513. (const :format "" search)
  514. (string :tag "Match")
  515. ,org-agenda-custom-commands-local-options)
  516. (list :tag "Stuck projects"
  517. (const :format "" stuck)
  518. (const :tag "" :format "" "")
  519. ,org-agenda-custom-commands-local-options)
  520. (list :tag "Tags/Property match (all agenda files)"
  521. (const :format "" tags)
  522. (string :tag "Match")
  523. ,org-agenda-custom-commands-local-options)
  524. (list :tag "Tags/Property match of TODO entries (all agenda files)"
  525. (const :format "" tags-todo)
  526. (string :tag "Match")
  527. ,org-agenda-custom-commands-local-options)
  528. (list :tag "TODO keyword search"
  529. (const :format "" todo)
  530. (string :tag "Match")
  531. ,org-agenda-custom-commands-local-options)
  532. (list :tag "Other, user-defined function"
  533. (symbol :tag "function")
  534. (string :tag "Match")
  535. ,org-agenda-custom-commands-local-options)))
  536. (repeat :tag "Settings for entire command set"
  537. (list (variable :tag "Any variable")
  538. (sexp :tag "Value")))
  539. (option (repeat :tag "Export" (file :tag "Export to"))))
  540. (cons :tag "Prefix key documentation"
  541. (string :tag "Access Key(s)")
  542. (string :tag "Description ")))))
  543. (defcustom org-agenda-query-register ?o
  544. "The register holding the current query string.
  545. The purpose of this is that if you construct a query string interactively,
  546. you can then use it to define a custom command."
  547. :group 'org-agenda-custom-commands
  548. :type 'character)
  549. (defcustom org-stuck-projects
  550. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  551. "How to identify stuck projects.
  552. This is a list of four items:
  553. 1. A tags/todo/property matcher string that is used to identify a project.
  554. See the manual for a description of tag and property searches.
  555. The entire tree below a headline matched by this is considered one project.
  556. 2. A list of TODO keywords identifying non-stuck projects.
  557. If the project subtree contains any headline with one of these todo
  558. keywords, the project is considered to be not stuck. If you specify
  559. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  560. 3. A list of tags identifying non-stuck projects.
  561. If the project subtree contains any headline with one of these tags,
  562. the project is considered to be not stuck. If you specify \"*\" as
  563. a tag, any tag will mark the project unstuck. Note that this is about
  564. the explicit presence of a tag somewhere in the subtree, inherited
  565. tags do not count here. If inherited tags make a project not stuck,
  566. use \"-TAG\" in the tags part of the matcher under (1.) above.
  567. 4. An arbitrary regular expression matching non-stuck projects.
  568. If the project turns out to be not stuck, search continues also in the
  569. subtree to see if any of the subtasks have project status.
  570. See also the variable `org-tags-match-list-sublevels' which applies
  571. to projects matched by this search as well.
  572. After defining this variable, you may use `org-agenda-list-stuck-projects'
  573. \(bound to `\\[org-agenda] #') to produce the list."
  574. :group 'org-agenda-custom-commands
  575. :type '(list
  576. (string :tag "Tags/TODO match to identify a project")
  577. (repeat :tag "Projects are *not* stuck if they have an entry with \
  578. TODO keyword any of" (string))
  579. (repeat :tag "Projects are *not* stuck if they have an entry with \
  580. TAG being any of" (string))
  581. (regexp :tag "Projects are *not* stuck if this regexp matches inside \
  582. the subtree")))
  583. (defgroup org-agenda-skip nil
  584. "Options concerning skipping parts of agenda files."
  585. :tag "Org Agenda Skip"
  586. :group 'org-agenda)
  587. (defcustom org-agenda-skip-function-global nil
  588. "Function to be called at each match during agenda construction.
  589. If this function returns nil, the current match should not be skipped.
  590. If the function decided to skip an agenda match, is must return the
  591. buffer position from which the search should be continued.
  592. This may also be a Lisp form, which will be evaluated.
  593. This variable will be applied to every agenda match, including
  594. tags/property searches and TODO lists. So try to make the test function
  595. do its checking as efficiently as possible. To implement a skipping
  596. condition just for specific agenda commands, use the variable
  597. `org-agenda-skip-function' which can be set in the options section
  598. of custom agenda commands."
  599. :group 'org-agenda-skip
  600. :type 'sexp)
  601. (defgroup org-agenda-daily/weekly nil
  602. "Options concerning the daily/weekly agenda."
  603. :tag "Org Agenda Daily/Weekly"
  604. :group 'org-agenda)
  605. (defgroup org-agenda-todo-list nil
  606. "Options concerning the global todo list agenda view."
  607. :tag "Org Agenda Todo List"
  608. :group 'org-agenda)
  609. (defgroup org-agenda-match-view nil
  610. "Options concerning the general tags/property/todo match agenda view."
  611. :tag "Org Agenda Match View"
  612. :group 'org-agenda)
  613. (defgroup org-agenda-search-view nil
  614. "Options concerning the search agenda view."
  615. :tag "Org Agenda Search View"
  616. :group 'org-agenda)
  617. (defvar org-agenda-archives-mode nil
  618. "Non-nil means the agenda will include archived items.
  619. If this is the symbol `trees', trees in the selected agenda scope
  620. that are marked with the ARCHIVE tag will be included anyway. When this is
  621. t, also all archive files associated with the current selection of agenda
  622. files will be included.")
  623. (defcustom org-agenda-restriction-lock-highlight-subtree t
  624. "Non-nil means highlight the whole subtree when restriction is active.
  625. Otherwise only highlight the headline. Highlighting the whole subtree is
  626. useful to ensure no edits happen beyond the restricted region."
  627. :group 'org-agenda
  628. :type 'boolean)
  629. (defcustom org-agenda-skip-comment-trees t
  630. "Non-nil means skip trees that start with the COMMENT keyword.
  631. When nil, these trees are also scanned by agenda commands."
  632. :group 'org-agenda-skip
  633. :type 'boolean)
  634. (defcustom org-agenda-todo-list-sublevels t
  635. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  636. When nil, the sublevels of a TODO entry are not checked, resulting in
  637. potentially much shorter TODO lists."
  638. :group 'org-agenda-skip
  639. :group 'org-agenda-todo-list
  640. :type 'boolean)
  641. (defcustom org-agenda-todo-ignore-with-date nil
  642. "Non-nil means don't show entries with a date in the global todo list.
  643. You can use this if you prefer to mark mere appointments with a TODO keyword,
  644. but don't want them to show up in the TODO list.
  645. When this is set, it also covers deadlines and scheduled items, the settings
  646. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  647. will be ignored.
  648. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  649. :group 'org-agenda-skip
  650. :group 'org-agenda-todo-list
  651. :type 'boolean)
  652. (defcustom org-agenda-todo-ignore-timestamp nil
  653. "Non-nil means don't show entries with a timestamp.
  654. This applies when creating the global todo list.
  655. Valid values are:
  656. past Don't show entries for today or in the past.
  657. future Don't show entries with a timestamp in the future.
  658. The idea behind this is that if it has a future
  659. timestamp, you don't want to think about it until the
  660. date.
  661. all Don't show any entries with a timestamp in the global todo list.
  662. The idea behind this is that by setting a timestamp, you
  663. have already \"taken care\" of this item.
  664. This variable can also have an integer as a value. If positive (N),
  665. todos with a timestamp N or more days in the future will be ignored. If
  666. negative (-N), todos with a timestamp N or more days in the past will be
  667. ignored. If 0, todos with a timestamp either today or in the future will
  668. be ignored. For example, a value of -1 will exclude todos with a
  669. timestamp in the past (yesterday or earlier), while a value of 7 will
  670. exclude todos with a timestamp a week or more in the future.
  671. See also `org-agenda-todo-ignore-with-date'.
  672. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  673. to make his option also apply to the tags-todo list."
  674. :group 'org-agenda-skip
  675. :group 'org-agenda-todo-list
  676. :version "24.1"
  677. :type '(choice
  678. (const :tag "Ignore future timestamp todos" future)
  679. (const :tag "Ignore past or present timestamp todos" past)
  680. (const :tag "Ignore all timestamp todos" all)
  681. (const :tag "Show timestamp todos" nil)
  682. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  683. (defcustom org-agenda-todo-ignore-scheduled nil
  684. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  685. This applies when creating the global todo list.
  686. Valid values are:
  687. past Don't show entries scheduled today or in the past.
  688. future Don't show entries scheduled in the future.
  689. The idea behind this is that by scheduling it, you don't want to
  690. think about it until the scheduled date.
  691. all Don't show any scheduled entries in the global todo list.
  692. The idea behind this is that by scheduling it, you have already
  693. \"taken care\" of this item.
  694. t Same as `all', for backward compatibility.
  695. This variable can also have an integer as a value. See
  696. `org-agenda-todo-ignore-timestamp' for more details.
  697. See also `org-agenda-todo-ignore-with-date'.
  698. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  699. to make his option also apply to the tags-todo list."
  700. :group 'org-agenda-skip
  701. :group 'org-agenda-todo-list
  702. :type '(choice
  703. (const :tag "Ignore future-scheduled todos" future)
  704. (const :tag "Ignore past- or present-scheduled todos" past)
  705. (const :tag "Ignore all scheduled todos" all)
  706. (const :tag "Ignore all scheduled todos (compatibility)" t)
  707. (const :tag "Show scheduled todos" nil)
  708. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  709. (defcustom org-agenda-todo-ignore-deadlines nil
  710. "Non-nil means ignore some deadline TODO items when making TODO list.
  711. There are different motivations for using different values, please think
  712. carefully when configuring this variable.
  713. This applies when creating the global TODO list.
  714. Valid values are:
  715. near Don't show near deadline entries. A deadline is near when it is
  716. closer than `org-deadline-warning-days' days. The idea behind this
  717. is that such items will appear in the agenda anyway.
  718. far Don't show TODO entries where a deadline has been defined, but
  719. is not going to happen anytime soon. This is useful if you want to use
  720. the TODO list to figure out what to do now.
  721. past Don't show entries with a deadline timestamp for today or in the past.
  722. future Don't show entries with a deadline timestamp in the future, not even
  723. when they become `near' ones. Use it with caution.
  724. all Ignore all TODO entries that do have a deadline.
  725. t Same as `near', for backward compatibility.
  726. This variable can also have an integer as a value. See
  727. `org-agenda-todo-ignore-timestamp' for more details.
  728. See also `org-agenda-todo-ignore-with-date'.
  729. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  730. to make his option also apply to the tags-todo list."
  731. :group 'org-agenda-skip
  732. :group 'org-agenda-todo-list
  733. :type '(choice
  734. (const :tag "Ignore near deadlines" near)
  735. (const :tag "Ignore near deadlines (compatibility)" t)
  736. (const :tag "Ignore far deadlines" far)
  737. (const :tag "Ignore all TODOs with a deadlines" all)
  738. (const :tag "Show all TODOs, even if they have a deadline" nil)
  739. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  740. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  741. "Time unit to use when possibly ignoring an agenda item.
  742. See the docstring of various `org-agenda-todo-ignore-*' options.
  743. The default is to compare time stamps using days. An item is thus
  744. considered to be in the future if it is at least one day after today.
  745. Non-nil means to compare time stamps using seconds. An item is then
  746. considered future if it has a time value later than current time."
  747. :group 'org-agenda-skip
  748. :group 'org-agenda-todo-list
  749. :version "24.4"
  750. :package-version '(Org . "8.0")
  751. :type '(choice
  752. (const :tag "Compare time with days" nil)
  753. (const :tag "Compare time with seconds" t)))
  754. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  755. "Non-nil means honor todo-list ignores options also in tags-todo search.
  756. The variables
  757. `org-agenda-todo-ignore-with-date',
  758. `org-agenda-todo-ignore-timestamp',
  759. `org-agenda-todo-ignore-scheduled',
  760. `org-agenda-todo-ignore-deadlines'
  761. make the global TODO list skip entries that have time stamps of certain
  762. kinds. If this option is set, the same options will also apply for the
  763. tags-todo search, which is the general tags/property matcher
  764. restricted to unfinished TODO entries only."
  765. :group 'org-agenda-skip
  766. :group 'org-agenda-todo-list
  767. :group 'org-agenda-match-view
  768. :type 'boolean)
  769. (defcustom org-agenda-skip-scheduled-if-done nil
  770. "Non-nil means don't show scheduled items in agenda when they are done.
  771. This is relevant for the daily/weekly agenda, not for the TODO list. It
  772. applies only to the actual date of the scheduling. Warnings about an item
  773. with a past scheduling dates are always turned off when the item is DONE."
  774. :group 'org-agenda-skip
  775. :group 'org-agenda-daily/weekly
  776. :type 'boolean)
  777. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  778. "Non-nil means skip scheduling line if same entry shows because of deadline.
  779. In the agenda of today, an entry can show up multiple times
  780. because it is both scheduled and has a nearby deadline, and maybe
  781. a plain time stamp as well.
  782. When this variable is nil, the entry will be shown several times.
  783. When set to t, then only the deadline is shown and the fact that
  784. the entry is scheduled today or was scheduled previously is not
  785. shown.
  786. When set to the symbol `not-today', skip scheduled previously,
  787. but not scheduled today.
  788. When set to the symbol `repeated-after-deadline', skip scheduled
  789. items if they are repeated beyond the current deadline."
  790. :group 'org-agenda-skip
  791. :group 'org-agenda-daily/weekly
  792. :type '(choice
  793. (const :tag "Never" nil)
  794. (const :tag "Always" t)
  795. (const :tag "Not when scheduled today" not-today)
  796. (const :tag "When repeated past deadline" repeated-after-deadline)))
  797. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  798. "Non-nil means skip timestamp line if same entry shows because of deadline.
  799. In the agenda of today, an entry can show up multiple times
  800. because it has both a plain timestamp and has a nearby deadline.
  801. When this variable is t, then only the deadline is shown and the
  802. fact that the entry has a timestamp for or including today is not
  803. shown. When this variable is nil, the entry will be shown
  804. several times."
  805. :group 'org-agenda-skip
  806. :group 'org-agenda-daily/weekly
  807. :version "24.1"
  808. :type '(choice
  809. (const :tag "Never" nil)
  810. (const :tag "Always" t)))
  811. (defcustom org-agenda-skip-deadline-if-done nil
  812. "Non-nil means don't show deadlines when the corresponding item is done.
  813. When nil, the deadline is still shown and should give you a happy feeling.
  814. This is relevant for the daily/weekly agenda. It applies only to the
  815. actual date of the deadline. Warnings about approaching and past-due
  816. deadlines are always turned off when the item is DONE."
  817. :group 'org-agenda-skip
  818. :group 'org-agenda-daily/weekly
  819. :type 'boolean)
  820. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  821. "Non-nil means skip deadline prewarning when entry is also scheduled.
  822. This will apply on all days where a prewarning for the deadline would
  823. be shown, but not at the day when the entry is actually due. On that day,
  824. the deadline will be shown anyway.
  825. This variable may be set to nil, t, the symbol `pre-scheduled',
  826. or a number which will then give the number of days before the actual
  827. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  828. eliminates the deadline prewarning only prior to the scheduled date.
  829. This can be used in a workflow where the first showing of the deadline will
  830. trigger you to schedule it, and then you don't want to be reminded of it
  831. because you will take care of it on the day when scheduled."
  832. :group 'org-agenda-skip
  833. :group 'org-agenda-daily/weekly
  834. :version "24.1"
  835. :type '(choice
  836. (const :tag "Always show prewarning" nil)
  837. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  838. (const :tag "Remove prewarning if entry is scheduled" t)
  839. (integer :tag "Restart prewarning N days before deadline")))
  840. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  841. "Non-nil means skip scheduled delay when entry also has a deadline.
  842. This variable may be set to nil, t, the symbol `post-deadline',
  843. or a number which will then give the number of days after the actual
  844. scheduled date when the delay should expire. The symbol `post-deadline'
  845. eliminates the schedule delay when the date is posterior to the deadline."
  846. :group 'org-agenda-skip
  847. :group 'org-agenda-daily/weekly
  848. :version "24.4"
  849. :package-version '(Org . "8.0")
  850. :type '(choice
  851. (const :tag "Always honor delay" nil)
  852. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  853. (const :tag "Ignore delay if entry has a deadline" t)
  854. (integer :tag "Honor delay up until N days after the scheduled date")))
  855. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  856. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  857. When non-nil, after the search for timestamps has matched once in an
  858. entry, the rest of the entry will not be searched."
  859. :group 'org-agenda-skip
  860. :type 'boolean)
  861. (defcustom org-agenda-skip-timestamp-if-done nil
  862. "Non-nil means don't select item by timestamp or -range if it is DONE."
  863. :group 'org-agenda-skip
  864. :group 'org-agenda-daily/weekly
  865. :type 'boolean)
  866. (defcustom org-agenda-dim-blocked-tasks t
  867. "Non-nil means dim blocked tasks in the agenda display.
  868. This causes some overhead during agenda construction, but if you
  869. have turned on `org-enforce-todo-dependencies',
  870. `org-enforce-todo-checkbox-dependencies', or any other blocking
  871. mechanism, this will create useful feedback in the agenda.
  872. Instead of t, this variable can also have the value `invisible'.
  873. Then blocked tasks will be invisible and only become visible when
  874. they become unblocked. An exemption to this behavior is when a task is
  875. blocked because of unchecked checkboxes below it. Since checkboxes do
  876. not show up in the agenda views, making this task invisible you remove any
  877. trace from agenda views that there is something to do. Therefore, a task
  878. that is blocked because of checkboxes will never be made invisible, it
  879. will only be dimmed."
  880. :group 'org-agenda-daily/weekly
  881. :group 'org-agenda-todo-list
  882. :version "24.3"
  883. :type '(choice
  884. (const :tag "Do not dim" nil)
  885. (const :tag "Dim to a gray face" t)
  886. (const :tag "Make invisible" invisible)))
  887. (defgroup org-agenda-startup nil
  888. "Options concerning initial settings in the Agenda in Org Mode."
  889. :tag "Org Agenda Startup"
  890. :group 'org-agenda)
  891. (defcustom org-agenda-menu-show-matcher t
  892. "Non-nil means show the match string in the agenda dispatcher menu.
  893. When nil, the matcher string is not shown, but is put into the help-echo
  894. property so than moving the mouse over the command shows it.
  895. Setting it to nil is good if matcher strings are very long and/or if
  896. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  897. :group 'org-agenda
  898. :version "24.1"
  899. :type 'boolean)
  900. (defcustom org-agenda-menu-two-columns nil
  901. "Non-nil means, use two columns to show custom commands in the dispatcher.
  902. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  903. to nil."
  904. :group 'org-agenda
  905. :version "24.1"
  906. :type 'boolean)
  907. (defcustom org-agenda-finalize-hook nil
  908. "Hook run just before displaying an agenda buffer.
  909. The buffer is still writable when the hook is called.
  910. You can modify some of the buffer substrings but you should be
  911. extra careful not to modify the text properties of the agenda
  912. headlines as the agenda display heavily relies on them."
  913. :group 'org-agenda-startup
  914. :type 'hook)
  915. (defcustom org-agenda-filter-hook nil
  916. "Hook run just after filtering with `org-agenda-filter'."
  917. :group 'org-agenda-startup
  918. :package-version '(Org . "9.4")
  919. :type 'hook)
  920. (defcustom org-agenda-mouse-1-follows-link nil
  921. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  922. A longer mouse click will still set point. Needs to be set
  923. before org.el is loaded."
  924. :group 'org-agenda-startup
  925. :type 'boolean)
  926. (defcustom org-agenda-start-with-follow-mode nil
  927. "The initial value of follow mode in a newly created agenda window."
  928. :group 'org-agenda-startup
  929. :type 'boolean)
  930. (defcustom org-agenda-follow-indirect nil
  931. "Non-nil means `org-agenda-follow-mode' displays only the
  932. current item's tree, in an indirect buffer."
  933. :group 'org-agenda
  934. :version "24.1"
  935. :type 'boolean)
  936. (defcustom org-agenda-show-outline-path t
  937. "Non-nil means show outline path in echo area after line motion."
  938. :group 'org-agenda-startup
  939. :type 'boolean)
  940. (defcustom org-agenda-start-with-entry-text-mode nil
  941. "The initial value of entry-text-mode in a newly created agenda window."
  942. :group 'org-agenda-startup
  943. :type 'boolean)
  944. (defcustom org-agenda-entry-text-maxlines 5
  945. "Number of text lines to be added when `E' is pressed in the agenda.
  946. Note that this variable only used during agenda display. To add entry text
  947. when exporting the agenda, configure the variable
  948. `org-agenda-add-entry-text-maxlines'."
  949. :group 'org-agenda
  950. :type 'integer)
  951. (defcustom org-agenda-entry-text-exclude-regexps nil
  952. "List of regular expressions to clean up entry text.
  953. The complete matches of all regular expressions in this list will be
  954. removed from entry text before it is shown in the agenda."
  955. :group 'org-agenda
  956. :type '(repeat (regexp)))
  957. (defcustom org-agenda-entry-text-leaders " > "
  958. "Text prepended to the entry text in agenda buffers."
  959. :version "24.4"
  960. :package-version '(Org . "8.0")
  961. :group 'org-agenda
  962. :type 'string)
  963. (defvar org-agenda-entry-text-cleanup-hook nil
  964. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  965. This cleanup is done in a temporary buffer, so the function may inspect and
  966. change the entire buffer.
  967. Some default stuff like drawers and scheduling/deadline dates will already
  968. have been removed when this is called, as will any matches for regular
  969. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  970. (defvar org-agenda-include-inactive-timestamps nil
  971. "Non-nil means include inactive time stamps in agenda.
  972. Dynamically scoped.")
  973. (defgroup org-agenda-windows nil
  974. "Options concerning the windows used by the Agenda in Org Mode."
  975. :tag "Org Agenda Windows"
  976. :group 'org-agenda)
  977. (defcustom org-agenda-window-setup 'reorganize-frame
  978. "How the agenda buffer should be displayed.
  979. Possible values for this option are:
  980. current-window Show agenda in the current window, keeping all other windows.
  981. other-window Use `switch-to-buffer-other-window' to display agenda.
  982. only-window Show agenda, deleting all other windows.
  983. reorganize-frame Show only two windows on the current frame, the current
  984. window and the agenda.
  985. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  986. Also, when exiting the agenda, kill that frame.
  987. other-tab Use `switch-to-buffer-other-tab' to display the
  988. agenda, making use of the `tab-bar-mode' introduced
  989. in Emacs version 27.1. Also, kill that tab when
  990. exiting the agenda view.
  991. See also the variable `org-agenda-restore-windows-after-quit'."
  992. :group 'org-agenda-windows
  993. :type '(choice
  994. (const current-window)
  995. (const other-frame)
  996. (const other-tab)
  997. (const other-window)
  998. (const only-window)
  999. (const reorganize-frame))
  1000. :package-version '(Org . "9.4"))
  1001. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  1002. "The min and max height of the agenda window as a fraction of frame height.
  1003. The value of the variable is a cons cell with two numbers between 0 and 1.
  1004. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  1005. :group 'org-agenda-windows
  1006. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  1007. (defcustom org-agenda-restore-windows-after-quit nil
  1008. "Non-nil means restore window configuration upon exiting agenda.
  1009. Before the window configuration is changed for displaying the
  1010. agenda, the current status is recorded. When the agenda is
  1011. exited with `q' or `x' and this option is set, the old state is
  1012. restored. If `org-agenda-window-setup' is `other-frame' or
  1013. `other-tab', the value of this option will be ignored."
  1014. :group 'org-agenda-windows
  1015. :type 'boolean)
  1016. (defcustom org-agenda-span 'week
  1017. "Number of days to include in overview display.
  1018. Can be day, week, month, year, or any number of days.
  1019. Custom commands can set this variable in the options section."
  1020. :group 'org-agenda-daily/weekly
  1021. :type '(choice (const :tag "Day" day)
  1022. (const :tag "Week" week)
  1023. (const :tag "Fortnight" fortnight)
  1024. (const :tag "Month" month)
  1025. (const :tag "Year" year)
  1026. (integer :tag "Custom")))
  1027. (defcustom org-agenda-start-on-weekday 1
  1028. "Non-nil means start the overview always on the specified weekday.
  1029. 0 denotes Sunday, 1 denotes Monday, etc.
  1030. When nil, always start on the current day.
  1031. Custom commands can set this variable in the options section."
  1032. :group 'org-agenda-daily/weekly
  1033. :type '(choice (const :tag "Today" nil)
  1034. (integer :tag "Weekday No.")))
  1035. (defcustom org-agenda-show-all-dates t
  1036. "Non-nil means `org-agenda' shows every day in the selected range.
  1037. When nil, only the days which actually have entries are shown."
  1038. :group 'org-agenda-daily/weekly
  1039. :type 'boolean)
  1040. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1041. "Format string for displaying dates in the agenda.
  1042. Used by the daily/weekly agenda. This should be a format string
  1043. understood by `format-time-string', or a function returning the
  1044. formatted date as a string. The function must take a single
  1045. argument, a calendar-style date list like (month day year)."
  1046. :group 'org-agenda-daily/weekly
  1047. :type '(choice
  1048. (string :tag "Format string")
  1049. (function :tag "Function")))
  1050. (defun org-agenda-end-of-line ()
  1051. "Go to the end of visible line."
  1052. (interactive)
  1053. (goto-char (line-end-position)))
  1054. (defun org-agenda-format-date-aligned (date)
  1055. "Format a DATE string for display in the daily/weekly agenda.
  1056. This function makes sure that dates are aligned for easy reading."
  1057. (require 'cal-iso)
  1058. (let* ((dayname (calendar-day-name date))
  1059. (day (cadr date))
  1060. (day-of-week (calendar-day-of-week date))
  1061. (month (car date))
  1062. (monthname (calendar-month-name month))
  1063. (year (nth 2 date))
  1064. (iso-week (org-days-to-iso-week
  1065. (calendar-absolute-from-gregorian date)))
  1066. ;; (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1067. ;; (1- year))
  1068. ;; ((and (= month 12) (<= iso-week 1))
  1069. ;; (1+ year))
  1070. ;; (t year)))
  1071. (weekstring (if (= day-of-week 1)
  1072. (format " W%02d" iso-week)
  1073. "")))
  1074. (format "%-10s %2d %s %4d%s"
  1075. dayname day monthname year weekstring)))
  1076. (defcustom org-agenda-time-leading-zero nil
  1077. "Non-nil means use leading zero for military times in agenda.
  1078. For example, 9:30am would become 09:30 rather than 9:30."
  1079. :group 'org-agenda-daily/weekly
  1080. :version "24.1"
  1081. :type 'boolean)
  1082. (defcustom org-agenda-timegrid-use-ampm nil
  1083. "When set, show AM/PM style timestamps on the timegrid."
  1084. :group 'org-agenda
  1085. :version "24.1"
  1086. :type 'boolean)
  1087. (defcustom org-agenda-clock-report-header nil
  1088. "Header inserted before the table in Org agenda clock report mode.
  1089. See Info node `(org) Agenda Commands' for more details."
  1090. :group 'org-agenda
  1091. :type '(choice
  1092. (string :tag "Header")
  1093. (const :tag "No header" nil))
  1094. :safe #'stringp
  1095. :package-version '(Org . "9.6"))
  1096. (defun org-agenda-time-of-day-to-ampm (time)
  1097. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1098. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1099. (minute (substring time -2))
  1100. (ampm "am"))
  1101. (cond
  1102. ((equal hour-number 12)
  1103. (setq ampm "pm"))
  1104. ((> hour-number 12)
  1105. (setq ampm "pm")
  1106. (setq hour-number (- hour-number 12))))
  1107. (concat
  1108. (if org-agenda-time-leading-zero
  1109. (format "%02d" hour-number)
  1110. (format "%02s" (number-to-string hour-number)))
  1111. ":" minute ampm)))
  1112. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1113. "Conditionally convert TIME to AM/PM format.
  1114. This is based on `org-agenda-timegrid-use-ampm'."
  1115. (if org-agenda-timegrid-use-ampm
  1116. (org-agenda-time-of-day-to-ampm time)
  1117. time))
  1118. (defcustom org-agenda-weekend-days '(6 0)
  1119. "Which days are weekend?
  1120. These days get the special face `org-agenda-date-weekend' in the agenda."
  1121. :group 'org-agenda-daily/weekly
  1122. :type '(set :greedy t
  1123. (const :tag "Monday" 1)
  1124. (const :tag "Tuesday" 2)
  1125. (const :tag "Wednesday" 3)
  1126. (const :tag "Thursday" 4)
  1127. (const :tag "Friday" 5)
  1128. (const :tag "Saturday" 6)
  1129. (const :tag "Sunday" 0)))
  1130. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1131. "Non-nil means jump to today when moving a past date forward in time.
  1132. When using S-right in the agenda to move a date forward, and the date
  1133. stamp currently points to the past, the first key press will move it
  1134. to today. When nil, just move one day forward even if the date stays
  1135. in the past."
  1136. :group 'org-agenda-daily/weekly
  1137. :version "24.1"
  1138. :type 'boolean)
  1139. (defcustom org-agenda-diary-file 'diary-file
  1140. "File to which to add new entries with the `i' key in agenda and calendar.
  1141. When this is the symbol `diary-file', the functionality in the Emacs
  1142. calendar will be used to add entries to the `diary-file'. But when this
  1143. points to a file, `org-agenda-diary-entry' will be used instead."
  1144. :group 'org-agenda
  1145. :type '(choice
  1146. (const :tag "The standard Emacs diary file" diary-file)
  1147. (file :tag "Special Org file diary entries")))
  1148. (defcustom org-agenda-include-diary nil
  1149. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1150. Custom commands can set this variable in the options section."
  1151. :group 'org-agenda-daily/weekly
  1152. :type 'boolean)
  1153. (defcustom org-agenda-include-deadlines t
  1154. "If non-nil, include entries within their deadline warning period.
  1155. Custom commands can set this variable in the options section."
  1156. :group 'org-agenda-daily/weekly
  1157. :version "24.1"
  1158. :type 'boolean)
  1159. (defcustom org-agenda-show-future-repeats t
  1160. "Non-nil shows repeated entries in the future part of the agenda.
  1161. When set to the symbol `next' only the first future repeat is shown."
  1162. :group 'org-agenda-daily/weekly
  1163. :type '(choice
  1164. (const :tag "Show all repeated entries" t)
  1165. (const :tag "Show next repeated entry" next)
  1166. (const :tag "Do not show repeated entries" nil))
  1167. :version "26.1"
  1168. :package-version '(Org . "9.1")
  1169. :safe #'symbolp)
  1170. (defcustom org-agenda-prefer-last-repeat nil
  1171. "Non-nil sets date for repeated entries to their last repeat.
  1172. When nil, display SCHEDULED and DEADLINE dates at their base
  1173. date, and in today's agenda, as a reminder. Display plain
  1174. time-stamps, on the other hand, at every repeat date in the past
  1175. in addition to the base date.
  1176. When non-nil, show a repeated entry at its latest repeat date,
  1177. possibly being today even if it wasn't marked as done. This
  1178. setting is useful if you do not always mark repeated entries as
  1179. done and, yet, consider that reaching repeat date starts the task
  1180. anew.
  1181. When set to a list of strings, prefer last repeats only for
  1182. entries with these TODO keywords."
  1183. :group 'org-agenda-daily/weekly
  1184. :type '(choice
  1185. (const :tag "Prefer last repeat" t)
  1186. (const :tag "Prefer base date" nil)
  1187. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1188. (string :tag "TODO keyword")))
  1189. :version "26.1"
  1190. :package-version '(Org . "9.1")
  1191. :safe (lambda (x) (or (booleanp x) (consp x))))
  1192. (defcustom org-scheduled-past-days 10000
  1193. "Number of days to continue listing scheduled items not marked DONE.
  1194. When an item is scheduled on a date, it shows up in the agenda on
  1195. this day and will be listed until it is marked done or for the
  1196. number of days given here."
  1197. :group 'org-agenda-daily/weekly
  1198. :type 'integer
  1199. :safe 'integerp)
  1200. (defcustom org-deadline-past-days 10000
  1201. "Number of days to warn about missed deadlines.
  1202. When an item has deadline on a date, it shows up in the agenda on
  1203. this day and will appear as a reminder until it is marked DONE or
  1204. for the number of days given here."
  1205. :group 'org-agenda-daily/weekly
  1206. :type 'integer
  1207. :version "26.1"
  1208. :package-version '(Org . "9.1")
  1209. :safe 'integerp)
  1210. (defcustom org-agenda-log-mode-items '(closed clock)
  1211. "List of items that should be shown in agenda log mode.
  1212. \\<org-agenda-mode-map>\
  1213. This list may contain the following symbols:
  1214. closed Show entries that have been closed on that day.
  1215. clock Show entries that have received clocked time on that day.
  1216. state Show all logged state changes.
  1217. Note that instead of changing this variable, you can also press \
  1218. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1219. the agenda to display all available LOG items temporarily."
  1220. :group 'org-agenda-daily/weekly
  1221. :type '(set :greedy t (const closed) (const clock) (const state)))
  1222. (defcustom org-agenda-clock-consistency-checks
  1223. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1224. :gap-ok-around ("4:00")
  1225. :default-face ((:background "DarkRed") (:foreground "white"))
  1226. :overlap-face nil :gap-face nil :no-end-time-face nil
  1227. :long-face nil :short-face nil)
  1228. "This is a property list, with the following keys:
  1229. :max-duration Mark clocking chunks that are longer than this time.
  1230. This is a time string like \"HH:MM\", or the number
  1231. of minutes as an integer.
  1232. :min-duration Mark clocking chunks that are shorter that this.
  1233. This is a time string like \"HH:MM\", or the number
  1234. of minutes as an integer.
  1235. :max-gap Mark gaps between clocking chunks that are longer than
  1236. this duration. A number of minutes, or a string
  1237. like \"HH:MM\".
  1238. :gap-ok-around List of times during the day which are usually not working
  1239. times. When a gap is detected, but the gap contains any
  1240. of these times, the gap is *not* reported. For example,
  1241. if this is (\"4:00\" \"13:00\") then gaps that contain
  1242. 4:00 in the morning (i.e. the night) and 13:00
  1243. (i.e. a typical lunch time) do not cause a warning.
  1244. You should have at least one time during the night in this
  1245. list, or otherwise the first task each morning will trigger
  1246. a warning because it follows a long gap.
  1247. Furthermore, the following properties can be used to define faces for
  1248. issue display.
  1249. :default-face the default face, if the specific face is undefined
  1250. :overlap-face face for overlapping clocks
  1251. :gap-face face for gaps between clocks
  1252. :no-end-time-face face for incomplete clocks
  1253. :long-face face for clock intervals that are too long
  1254. :short-face face for clock intervals that are too short"
  1255. :group 'org-agenda-daily/weekly
  1256. :group 'org-clock
  1257. :version "24.1"
  1258. :type 'plist)
  1259. (defcustom org-agenda-log-mode-add-notes t
  1260. "Non-nil means add first line of notes to log entries in agenda views.
  1261. If a log item like a state change or a clock entry is associated with
  1262. notes, the first line of these notes will be added to the entry in the
  1263. agenda display."
  1264. :group 'org-agenda-daily/weekly
  1265. :type 'boolean)
  1266. (defcustom org-agenda-start-with-log-mode nil
  1267. "The initial value of log-mode in a newly created agenda window.
  1268. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1269. explanations on the possible values."
  1270. :group 'org-agenda-startup
  1271. :group 'org-agenda-daily/weekly
  1272. :type '(choice (const :tag "Don't show log items" nil)
  1273. (const :tag "Show only log items" only)
  1274. (const :tag "Show all possible log items" clockcheck)
  1275. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1276. (choice (const :tag "Show closed log items" closed)
  1277. (const :tag "Show clocked log items" clock)
  1278. (const :tag "Show all logged state changes" state)))))
  1279. (defcustom org-agenda-start-with-clockreport-mode nil
  1280. "The initial value of clockreport-mode in a newly created agenda window."
  1281. :group 'org-agenda-startup
  1282. :group 'org-agenda-daily/weekly
  1283. :type 'boolean)
  1284. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1285. "Property list with parameters for the clocktable in clockreport mode.
  1286. This is the display mode that shows a clock table in the daily/weekly
  1287. agenda, the properties for this dynamic block can be set here.
  1288. The usual clocktable parameters are allowed here, but you cannot set
  1289. the properties :name, :tstart, :tend, :block, and :scope - these will
  1290. be overwritten to make sure the content accurately reflects the
  1291. current display in the agenda."
  1292. :group 'org-agenda-daily/weekly
  1293. :type 'plist)
  1294. (defvaralias 'org-agenda-search-view-search-words-only
  1295. 'org-agenda-search-view-always-boolean)
  1296. (defcustom org-agenda-search-view-always-boolean nil
  1297. "Non-nil means the search string is interpreted as individual parts.
  1298. The search string for search view can either be interpreted as a phrase,
  1299. or as a list of snippets that define a boolean search for a number of
  1300. strings.
  1301. When this is non-nil, the string will be split on whitespace, and each
  1302. snippet will be searched individually, and all must match in order to
  1303. select an entry. A snippet is then a single string of non-white
  1304. characters, or a string in double quotes, or a regexp in {} braces.
  1305. If a snippet is preceded by \"-\", the snippet must *not* match.
  1306. \"+\" is syntactic sugar for positive selection. Each snippet may
  1307. be found as a full word or a partial word, but see the variable
  1308. `org-agenda-search-view-force-full-words'.
  1309. When this is nil, search will look for the entire search phrase as one,
  1310. with each space character matching any amount of whitespace, including
  1311. line breaks.
  1312. Even when this is nil, you can still switch to Boolean search dynamically
  1313. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1314. is a regexp marked with braces like \"{abc}\", this will also switch to
  1315. boolean search."
  1316. :group 'org-agenda-search-view
  1317. :version "24.1"
  1318. :type 'boolean)
  1319. (defcustom org-agenda-search-view-force-full-words nil
  1320. "Non-nil means, search words must be matches as complete words.
  1321. When nil, they may also match part of a word."
  1322. :group 'org-agenda-search-view
  1323. :version "24.1"
  1324. :type 'boolean)
  1325. (defcustom org-agenda-search-view-max-outline-level 0
  1326. "Maximum outline level to display in search view.
  1327. E.g. when this is set to 1, the search view will only
  1328. show headlines of level 1. When set to 0, the default
  1329. value, don't limit agenda view by outline level."
  1330. :group 'org-agenda-search-view
  1331. :version "26.1"
  1332. :package-version '(Org . "8.3")
  1333. :type 'integer)
  1334. (defgroup org-agenda-time-grid nil
  1335. "Options concerning the time grid in the Org Agenda."
  1336. :tag "Org Agenda Time Grid"
  1337. :group 'org-agenda)
  1338. (defcustom org-agenda-search-headline-for-time t
  1339. "Non-nil means search headline for a time-of-day.
  1340. If the headline contains a time-of-day in one format or another, it will
  1341. be used to sort the entry into the time sequence of items for a day.
  1342. Some people have time stamps in the headline that refer to the creation
  1343. time or so, and then this produces an unwanted side effect. If this is
  1344. the case for your, use this variable to turn off searching the headline
  1345. for a time."
  1346. :group 'org-agenda-time-grid
  1347. :type 'boolean)
  1348. (defcustom org-agenda-use-time-grid t
  1349. "Non-nil means show a time grid in the agenda schedule.
  1350. A time grid is a set of lines for specific times (like every two hours between
  1351. 8:00 and 20:00). The items scheduled for a day at specific times are
  1352. sorted in between these lines.
  1353. For details about when the grid will be shown, and what it will look like, see
  1354. the variable `org-agenda-time-grid'."
  1355. :group 'org-agenda-time-grid
  1356. :type 'boolean)
  1357. (defcustom org-agenda-time-grid
  1358. (let ((graphical (and (display-graphic-p)
  1359. (char-displayable-p ?┄))))
  1360. `((daily today require-timed)
  1361. (800 1000 1200 1400 1600 1800 2000)
  1362. ,(if graphical " ┄┄┄┄┄ " "......")
  1363. ,(if graphical "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" "----------------")))
  1364. "The settings for time grid for agenda display.
  1365. This is a list of four items. The first item is again a list. It contains
  1366. symbols specifying conditions when the grid should be displayed:
  1367. daily if the agenda shows a single day
  1368. weekly if the agenda shows an entire week
  1369. today show grid on current date, independent of daily/weekly display
  1370. require-timed show grid only if at least one item has a time specification
  1371. remove-match skip grid times already present in an entry
  1372. The second item is a list of integers, indicating the times that
  1373. should have a grid line.
  1374. The third item is a string which will be placed right after the
  1375. times that have a grid line.
  1376. The fourth item is a string placed after the grid times. This
  1377. will align with agenda items."
  1378. :group 'org-agenda-time-grid
  1379. :version "29.1"
  1380. :type
  1381. '(list
  1382. (set :greedy t :tag "Grid Display Options"
  1383. (const :tag "Show grid in single day agenda display" daily)
  1384. (const :tag "Show grid in weekly agenda display" weekly)
  1385. (const :tag "Always show grid for today" today)
  1386. (const :tag "Show grid only if any timed entries are present"
  1387. require-timed)
  1388. (const :tag "Skip grid times already present in an entry"
  1389. remove-match))
  1390. (repeat :tag "Grid Times" (integer :tag "Time"))
  1391. (string :tag "Grid String (after agenda times)")
  1392. (string :tag "Grid String (aligns with agenda items)")))
  1393. (defcustom org-agenda-show-current-time-in-grid t
  1394. "Non-nil means show the current time in the time grid."
  1395. :group 'org-agenda-time-grid
  1396. :version "24.1"
  1397. :type 'boolean)
  1398. (defcustom org-agenda-current-time-string
  1399. (if (and (display-graphic-p)
  1400. (char-displayable-p ?←)
  1401. (char-displayable-p ?─))
  1402. "← now ───────────────────────────────────────────────"
  1403. "now - - - - - - - - - - - - - - - - - - - - - - - - -")
  1404. "The string for the current time marker in the agenda."
  1405. :group 'org-agenda-time-grid
  1406. :version "29.1"
  1407. :type 'string)
  1408. (defgroup org-agenda-sorting nil
  1409. "Options concerning sorting in the Org Agenda."
  1410. :tag "Org Agenda Sorting"
  1411. :group 'org-agenda)
  1412. (defcustom org-agenda-sorting-strategy
  1413. '((agenda habit-down time-up priority-down category-keep)
  1414. (todo priority-down category-keep)
  1415. (tags priority-down category-keep)
  1416. (search category-keep))
  1417. "Sorting structure for the agenda items of a single day.
  1418. This is a list of symbols which will be used in sequence to determine
  1419. if an entry should be listed before another entry. The following
  1420. symbols are recognized:
  1421. time-up Put entries with time-of-day indications first, early first.
  1422. time-down Put entries with time-of-day indications first, late first.
  1423. timestamp-up Sort by any timestamp, early first.
  1424. timestamp-down Sort by any timestamp, late first.
  1425. scheduled-up Sort by scheduled timestamp, early first.
  1426. scheduled-down Sort by scheduled timestamp, late first.
  1427. deadline-up Sort by deadline timestamp, early first.
  1428. deadline-down Sort by deadline timestamp, late first.
  1429. ts-up Sort by active timestamp, early first.
  1430. ts-down Sort by active timestamp, late first.
  1431. tsia-up Sort by inactive timestamp, early first.
  1432. tsia-down Sort by inactive timestamp, late first.
  1433. category-keep Keep the default order of categories, corresponding to the
  1434. sequence in `org-agenda-files'.
  1435. category-up Sort alphabetically by category, A-Z.
  1436. category-down Sort alphabetically by category, Z-A.
  1437. tag-up Sort alphabetically by last tag, A-Z.
  1438. tag-down Sort alphabetically by last tag, Z-A.
  1439. priority-up Sort numerically by priority, high priority last.
  1440. priority-down Sort numerically by priority, high priority first.
  1441. todo-state-up Sort by todo state, tasks that are done last.
  1442. todo-state-down Sort by todo state, tasks that are done first.
  1443. effort-up Sort numerically by estimated effort, high effort last.
  1444. effort-down Sort numerically by estimated effort, high effort first.
  1445. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1446. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1447. habit-up Put entries that are habits first.
  1448. habit-down Put entries that are habits last.
  1449. alpha-up Sort headlines alphabetically.
  1450. alpha-down Sort headlines alphabetically, reversed.
  1451. The different possibilities will be tried in sequence, and testing stops
  1452. if one comparison returns a \"not-equal\". For example,
  1453. (setq org-agenda-sorting-strategy
  1454. \\='(time-up category-keep priority-down))
  1455. means: Pull out all entries having a specified time of day and sort them,
  1456. in order to make a time schedule for the current day the first thing in the
  1457. agenda listing for the day. Of the entries without a time indication, keep
  1458. the grouped in categories, don't sort the categories, but keep them in
  1459. the sequence given in `org-agenda-files'. Within each category sort by
  1460. priority.
  1461. Leaving out `category-keep' would mean that items will be sorted across
  1462. categories by priority.
  1463. Instead of a single list, this can also be a set of list for specific
  1464. contents, with a context symbol in the car of the list, any of
  1465. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1466. Custom commands can bind this variable in the options section."
  1467. :group 'org-agenda-sorting
  1468. :type `(choice
  1469. (repeat :tag "General" ,org-sorting-choice)
  1470. (list :tag "Individually"
  1471. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1472. (repeat ,org-sorting-choice))
  1473. (cons (const :tag "Strategy for TODO lists" todo)
  1474. (repeat ,org-sorting-choice))
  1475. (cons (const :tag "Strategy for Tags matches" tags)
  1476. (repeat ,org-sorting-choice))
  1477. (cons (const :tag "Strategy for search matches" search)
  1478. (repeat ,org-sorting-choice)))))
  1479. (defcustom org-agenda-cmp-user-defined nil
  1480. "A function to define the comparison `user-defined'.
  1481. This function must receive two arguments, agenda entry a and b.
  1482. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1483. the user comparison, return nil.
  1484. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1485. part of an agenda sorting strategy."
  1486. :group 'org-agenda-sorting
  1487. :type 'symbol)
  1488. (defcustom org-agenda-sort-notime-is-late t
  1489. "Non-nil means items without time are considered late.
  1490. This is only relevant for sorting. When t, items which have no explicit
  1491. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1492. do have a time. When nil, the default time is before 0:00. You can use this
  1493. option to decide if the schedule for today should come before or after timeless
  1494. agenda entries."
  1495. :group 'org-agenda-sorting
  1496. :type 'boolean)
  1497. (defcustom org-agenda-sort-noeffort-is-high t
  1498. "Non-nil means items without effort estimate are sorted as high effort.
  1499. This also applies when filtering an agenda view with respect to the
  1500. < or > effort operator. Then, tasks with no effort defined will be treated
  1501. as tasks with high effort.
  1502. When nil, such items are sorted as 0 minutes effort."
  1503. :group 'org-agenda-sorting
  1504. :type 'boolean)
  1505. (defgroup org-agenda-line-format nil
  1506. "Options concerning the entry prefix in the Org agenda display."
  1507. :tag "Org Agenda Line Format"
  1508. :group 'org-agenda)
  1509. (defcustom org-agenda-prefix-format
  1510. '((agenda . " %i %-12:c%?-12t% s")
  1511. (todo . " %i %-12:c")
  1512. (tags . " %i %-12:c")
  1513. (search . " %i %-12:c"))
  1514. "Format specifications for the prefix of items in the agenda views.
  1515. An alist with one entry per agenda type. The keys of the
  1516. sublists are `agenda', `todo', `search' and `tags'. The values
  1517. are format strings.
  1518. This format works similar to a printf format, with the following meaning:
  1519. %c the category of the item, \"Diary\" for entries from the diary,
  1520. or as given by the CATEGORY keyword or derived from the file name
  1521. %e the effort required by the item
  1522. %l the level of the item (insert X space(s) if item is of level X)
  1523. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1524. %T the last tag of the item (ignore inherited tags, which come first)
  1525. %t the HH:MM time-of-day specification if one applies to the entry
  1526. %s Scheduling/Deadline information, a short string
  1527. %b show breadcrumbs, i.e., the names of the higher levels
  1528. %(expression) Eval EXPRESSION and replace the control string
  1529. by the result
  1530. All specifiers work basically like the standard `%s' of printf, but may
  1531. contain two additional characters: a question mark just after the `%'
  1532. and a whitespace/punctuation character just before the final letter.
  1533. If the first character after `%' is a question mark, the entire field
  1534. will only be included if the corresponding value applies to the current
  1535. entry. This is useful for fields which should have fixed width when
  1536. present, but zero width when absent. For example, \"%?-12t\" will
  1537. result in a 12 character time field if a time of the day is specified,
  1538. but will completely disappear in entries which do not contain a time.
  1539. If there is punctuation or whitespace character just before the
  1540. final format letter, this character will be appended to the field
  1541. value if the value is not empty. For example, the format
  1542. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1543. the category is empty, no additional colon is inserted.
  1544. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1545. which means:
  1546. - Indent the line with two space characters
  1547. - Give the category a 12 chars wide field, padded with whitespace on
  1548. the right (because of `-'). Append a colon if there is a category
  1549. (because of `:').
  1550. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1551. time, don't put in an empty field, just skip it (because of '?').
  1552. - Finally, put the scheduling information.
  1553. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1554. `org-agenda-remove-tags'.
  1555. Custom commands can set this variable in the options section."
  1556. :type '(choice
  1557. (string :tag "General format")
  1558. (list :greedy t :tag "View dependent"
  1559. (cons (const agenda) (string :tag "Format"))
  1560. (cons (const todo) (string :tag "Format"))
  1561. (cons (const tags) (string :tag "Format"))
  1562. (cons (const search) (string :tag "Format"))))
  1563. :group 'org-agenda-line-format
  1564. :version "26.1"
  1565. :package-version '(Org . "9.1"))
  1566. (defcustom org-agenda-breadcrumbs-separator "->"
  1567. "The separator of breadcrumbs in agenda lines."
  1568. :group 'org-agenda-line-format
  1569. :package-version '(Org . "9.3")
  1570. :type 'string
  1571. :safe #'stringp)
  1572. (defvar org-prefix-format-compiled nil
  1573. "The compiled prefix format and associated variables.
  1574. This is a list where first element is a list of variable bindings, and second
  1575. element is the compiled format expression. See the variable
  1576. `org-agenda-prefix-format'.")
  1577. (defcustom org-agenda-todo-keyword-format "%-1s"
  1578. "Format for the TODO keyword in agenda lines.
  1579. Set this to something like \"%-12s\" if you want all TODO keywords
  1580. to occupy a fixed space in the agenda display."
  1581. :group 'org-agenda-line-format
  1582. :type 'string)
  1583. (defcustom org-agenda-diary-sexp-prefix nil
  1584. "A regexp that matches part of a diary sexp entry
  1585. which should be treated as scheduling/deadline information in
  1586. `org-agenda'.
  1587. For example, you can use this to extract the `diary-remind-message' from
  1588. `diary-remind' entries."
  1589. :group 'org-agenda-line-format
  1590. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1591. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1592. "Text preceding timerange entries in the agenda view.
  1593. This is a list with two strings. The first applies when the range
  1594. is entirely on one day. The second applies if the range spans several days.
  1595. The strings may have two \"%d\" format specifiers which will be filled
  1596. with the sequence number of the days, and the total number of days in the
  1597. range, respectively."
  1598. :group 'org-agenda-line-format
  1599. :type '(list
  1600. (string :tag "Deadline today ")
  1601. (choice :tag "Deadline relative"
  1602. (string :tag "Format string")
  1603. (function))))
  1604. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1605. "Text preceding scheduled items in the agenda view.
  1606. This is a list with two strings. The first applies when the item is
  1607. scheduled on the current day. The second applies when it has been scheduled
  1608. previously, it may contain a %d indicating that this is the nth time that
  1609. this item is scheduled, due to automatic rescheduling of unfinished items
  1610. for the following day. So this number is one larger than the number of days
  1611. that passed since this item was scheduled first."
  1612. :group 'org-agenda-line-format
  1613. :version "24.4"
  1614. :package-version '(Org . "8.0")
  1615. :type '(list
  1616. (string :tag "Scheduled today ")
  1617. (string :tag "Scheduled previously")))
  1618. (defcustom org-agenda-inactive-leader "["
  1619. "Text preceding item pulled into the agenda by inactive time stamps.
  1620. These entries are added to the agenda when pressing \"[\"."
  1621. :group 'org-agenda-line-format
  1622. :version "24.1"
  1623. :type 'string)
  1624. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1625. "Text preceding deadline items in the agenda view.
  1626. This is a list with three strings. The first applies when the item has its
  1627. deadline on the current day. The second applies when the deadline is in the
  1628. future, the third one when it is in the past. The strings may contain %d
  1629. to capture the number of days."
  1630. :group 'org-agenda-line-format
  1631. :version "24.4"
  1632. :package-version '(Org . "8.0")
  1633. :type '(list
  1634. (string :tag "Deadline today ")
  1635. (string :tag "Deadline in the future ")
  1636. (string :tag "Deadline in the past ")))
  1637. (defcustom org-agenda-remove-times-when-in-prefix t
  1638. "Non-nil means remove duplicate time specifications in agenda items.
  1639. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1640. time-of-day specification in a headline or diary entry is extracted and
  1641. placed into the prefix. If this option is non-nil, the original specification
  1642. \(a timestamp or -range, or just a plain time(range) specification like
  1643. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1644. cluttered.
  1645. The option can be t or nil. It may also be the symbol `beg', indicating
  1646. that the time should only be removed when it is located at the beginning of
  1647. the headline/diary entry."
  1648. :group 'org-agenda-line-format
  1649. :type '(choice
  1650. (const :tag "Always" t)
  1651. (const :tag "Never" nil)
  1652. (const :tag "When at beginning of entry" beg)))
  1653. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1654. "Non-nil means remove time ranges specifications in agenda
  1655. items that span on several days."
  1656. :group 'org-agenda-line-format
  1657. :version "24.1"
  1658. :type 'boolean)
  1659. (defcustom org-agenda-default-appointment-duration nil
  1660. "Default duration for appointments that only have a starting time.
  1661. When nil, no duration is specified in such cases.
  1662. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1663. :group 'org-agenda-line-format
  1664. :type '(choice
  1665. (integer :tag "Minutes")
  1666. (const :tag "No default duration")))
  1667. (defcustom org-agenda-show-inherited-tags t
  1668. "Non-nil means show inherited tags in each agenda line.
  1669. When this option is set to `always', it takes precedence over
  1670. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1671. in every agenda.
  1672. When this option is set to t (the default), inherited tags are
  1673. shown when they are available, i.e. when the value of
  1674. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1675. given agenda type.
  1676. This can be set to a list of agenda types in which the agenda
  1677. must display the inherited tags. Available types are `todo',
  1678. `agenda' and `search'.
  1679. When set to nil, never show inherited tags in agenda lines."
  1680. :group 'org-agenda-line-format
  1681. :group 'org-agenda
  1682. :version "24.3"
  1683. :type '(choice
  1684. (const :tag "Show inherited tags when available" t)
  1685. (const :tag "Always show inherited tags" always)
  1686. (repeat :tag "Show inherited tags only in selected agenda types"
  1687. (symbol :tag "Agenda type"))))
  1688. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1689. "List of agenda view types where to use tag inheritance.
  1690. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1691. controlled by `org-use-tag-inheritance'. In other agenda types,
  1692. `org-use-tag-inheritance' is not used for the selection of the
  1693. agenda entries. Still, you may want the agenda to be aware of
  1694. the inherited tags anyway, e.g. for later tag filtering.
  1695. Allowed value are `todo', `search' and `agenda'.
  1696. This variable has no effect if `org-agenda-show-inherited-tags'
  1697. is set to `always'. In that case, the agenda is aware of those
  1698. tags.
  1699. The default value sets tags in every agenda type. Setting this
  1700. option to nil will speed up non-tags agenda view a lot."
  1701. :group 'org-agenda
  1702. :version "26.1"
  1703. :package-version '(Org . "9.1")
  1704. :type '(choice
  1705. (const :tag "Use tag inheritance in all agenda types" t)
  1706. (repeat :tag "Use tag inheritance in selected agenda types"
  1707. (symbol :tag "Agenda type"))))
  1708. (defcustom org-agenda-hide-tags-regexp nil
  1709. "Regular expression used to filter away specific tags in agenda views.
  1710. This means that these tags will be present, but not be shown in the agenda
  1711. line. Secondary filtering will still work on the hidden tags.
  1712. Nil means don't hide any tags."
  1713. :group 'org-agenda-line-format
  1714. :type '(choice
  1715. (const :tag "Hide none" nil)
  1716. (regexp :tag "Regexp ")))
  1717. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1718. 'org-agenda-remove-tags)
  1719. (defcustom org-agenda-remove-tags nil
  1720. "Non-nil means remove the tags from the headline copy in the agenda.
  1721. When this is the symbol `prefix', only remove tags when
  1722. `org-agenda-prefix-format' contains a `%T' specifier."
  1723. :group 'org-agenda-line-format
  1724. :type '(choice
  1725. (const :tag "Always" t)
  1726. (const :tag "Never" nil)
  1727. (const :tag "When prefix format contains %T" prefix)))
  1728. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1729. (defcustom org-agenda-tags-column 'auto
  1730. "Shift tags in agenda items to this column.
  1731. If set to `auto', tags will be automatically aligned to the right
  1732. edge of the window.
  1733. If set to a positive number, tags will be left-aligned to that
  1734. column. If set to a negative number, tags will be right-aligned
  1735. to that column. For example, -80 works well for a normal 80
  1736. character screen."
  1737. :group 'org-agenda-line-format
  1738. :type '(choice
  1739. (const :tag "Automatically align to right edge of window" auto)
  1740. (integer :tag "Specific column" -80))
  1741. :package-version '(Org . "9.1")
  1742. :version "26.1")
  1743. (defcustom org-agenda-fontify-priorities 'cookies
  1744. "Non-nil means highlight low and high priorities in agenda.
  1745. When t, the highest priority entries are bold, lowest priority italic.
  1746. However, settings in `org-priority-faces' will overrule these faces.
  1747. When this variable is the symbol `cookies', only fontify the
  1748. cookies, not the entire task.
  1749. This may also be an association list of priority faces, whose
  1750. keys are the character values of `org-priority-highest',
  1751. `org-priority-default', and `org-priority-lowest' (the default values
  1752. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1753. color as a string, or a list like `(:background \"Red\")'.
  1754. If it is a color, the variable `org-faces-easy-properties'
  1755. determines if it is a foreground or a background color."
  1756. :group 'org-agenda-line-format
  1757. :type '(choice
  1758. (const :tag "Never" nil)
  1759. (const :tag "Defaults" t)
  1760. (const :tag "Cookies only" cookies)
  1761. (repeat :tag "Specify"
  1762. (list (character :tag "Priority" :value ?A)
  1763. (choice :tag "Face "
  1764. (string :tag "Color")
  1765. (sexp :tag "Face"))))))
  1766. (defcustom org-agenda-day-face-function nil
  1767. "Function called to determine what face should be used to display a day.
  1768. The only argument passed to that function is the day. It should
  1769. returns a face, or nil if does not want to specify a face and let
  1770. the normal rules apply."
  1771. :group 'org-agenda-line-format
  1772. :version "24.1"
  1773. :type '(choice (const nil) (function)))
  1774. (defcustom org-agenda-category-icon-alist nil
  1775. "Alist of category icon to be displayed in agenda views.
  1776. Each entry should have the following format:
  1777. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1778. Where CATEGORY-REGEXP is a regexp matching the categories where
  1779. the icon should be displayed.
  1780. FILE-OR-DATA either a file path or a string containing image data.
  1781. The other fields can be omitted safely if not needed:
  1782. TYPE indicates the image type.
  1783. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1784. image data.
  1785. PROPS are additional image attributes to assign to the image,
  1786. like, e.g. `:ascent center'.
  1787. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1788. If you want to set the display properties yourself, just put a
  1789. list as second element:
  1790. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1791. For example, to display a 16px horizontal space for Emacs
  1792. category, you can use:
  1793. (\"Emacs\" \\='(space . (:width (16))))"
  1794. :group 'org-agenda-line-format
  1795. :version "24.1"
  1796. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1797. :value-type (choice (list :tag "Icon"
  1798. (string :tag "File or data")
  1799. (symbol :tag "Type")
  1800. (boolean :tag "Data?")
  1801. (repeat :tag "Extra image properties" :inline t sexp))
  1802. (list :tag "Display properties" sexp))))
  1803. (defgroup org-agenda-column-view nil
  1804. "Options concerning column view in the agenda."
  1805. :tag "Org Agenda Column View"
  1806. :group 'org-agenda)
  1807. (defcustom org-agenda-view-columns-initially nil
  1808. "When non-nil, switch to columns view right after creating the agenda."
  1809. :group 'org-agenda-column-view
  1810. :type 'boolean
  1811. :version "26.1"
  1812. :package-version '(Org . "9.0")
  1813. :safe #'booleanp)
  1814. (defcustom org-agenda-columns-show-summaries t
  1815. "Non-nil means show summaries for columns displayed in the agenda view."
  1816. :group 'org-agenda-column-view
  1817. :type 'boolean)
  1818. (defcustom org-agenda-columns-compute-summary-properties t
  1819. "Non-nil means recompute all summary properties before column view.
  1820. When column view in the agenda is listing properties that have a summary
  1821. operator, it can go to all relevant buffers and recompute the summaries
  1822. there. This can mean overhead for the agenda column view, but is necessary
  1823. to have thing up to date.
  1824. As a special case, a CLOCKSUM property also makes sure that the clock
  1825. computations are current."
  1826. :group 'org-agenda-column-view
  1827. :type 'boolean)
  1828. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1829. "Non-nil means the duration of an appointment will add to day effort.
  1830. The property to which appointment durations will be added is the one given
  1831. in the option `org-effort-property'. If an appointment does not have
  1832. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1833. is not set, an appointment without end time will not contribute to the time
  1834. estimate."
  1835. :group 'org-agenda-column-view
  1836. :type 'boolean)
  1837. (defcustom org-agenda-auto-exclude-function nil
  1838. "A function called with a tag to decide if it is filtered on \
  1839. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1840. The sole argument to the function, which is called once for each
  1841. possible tag, is a string giving the name of the tag. The
  1842. function should return either nil if the tag should be included
  1843. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1844. lines not carrying this tag.
  1845. Note that for the purpose of tag filtering, only the lower-case version of
  1846. all tags will be considered, so that this function will only ever see
  1847. the lower-case version of all tags."
  1848. :group 'org-agenda
  1849. :type '(choice (const nil) (function)))
  1850. (defcustom org-agenda-bulk-custom-functions nil
  1851. "Alist of characters and custom functions for bulk actions.
  1852. For example, this makes those two functions available:
  1853. (setq org-agenda-bulk-custom-functions
  1854. \\='((?R set-category)
  1855. (?C bulk-cut)))
  1856. With selected entries in an agenda buffer, `B R' will call
  1857. the custom function `set-category' on the selected entries.
  1858. Note that functions in this alist don't need to be quoted.
  1859. You can also specify a function which collects arguments to be
  1860. used for each call to your bulk custom function. The argument
  1861. collecting function will be run once and should return a list of
  1862. arguments to pass to the bulk function. For example:
  1863. (setq org-agenda-bulk-custom-functions
  1864. \\='((?R set-category get-category)))
  1865. Now, `B R' will call the custom `get-category' which would prompt
  1866. the user once for a category. That category is then passed as an
  1867. argument to `set-category' for each entry it's called against."
  1868. :type
  1869. '(alist :key-type character
  1870. :value-type
  1871. (group (function :tag "Bulk Custom Function")
  1872. (choice (function :tag "Bulk Custom Argument Function")
  1873. (const :tag "No Bulk Custom Argument Function" nil))))
  1874. :package-version '(Org . "9.5")
  1875. :group 'org-agenda)
  1876. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1877. "Execute BODY with point at location given by `org-hd-marker' property.
  1878. If STRING is non-nil, the text property will be fetched from position 0
  1879. in that string. If STRING is nil, it will be fetched from the beginning
  1880. of the current line."
  1881. (declare (debug t) (indent 1))
  1882. (org-with-gensyms (marker)
  1883. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1884. 'org-hd-marker ,string)))
  1885. (with-current-buffer (marker-buffer ,marker)
  1886. (save-excursion
  1887. (goto-char ,marker)
  1888. ,@body)))))
  1889. (defun org-add-agenda-custom-command (entry)
  1890. "Replace or add a command in `org-agenda-custom-commands'.
  1891. This is mostly for hacking and trying a new command - once the command
  1892. works you probably want to add it to `org-agenda-custom-commands' for good."
  1893. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1894. (if ass
  1895. (setcdr ass (cdr entry))
  1896. (push entry org-agenda-custom-commands))))
  1897. (defmacro org-agenda--insert-overriding-header (default)
  1898. "Insert header into agenda view.
  1899. The inserted header depends on `org-agenda-overriding-header'.
  1900. If the empty string, don't insert a header. If any other string,
  1901. insert it as a header. If nil, insert DEFAULT, which should
  1902. evaluate to a string. If a function, call it and insert the
  1903. string that it returns."
  1904. (declare (debug (form)) (indent defun))
  1905. `(cond
  1906. ((not org-agenda-overriding-header) (insert ,default))
  1907. ((equal org-agenda-overriding-header "") nil)
  1908. ((stringp org-agenda-overriding-header)
  1909. (insert (propertize org-agenda-overriding-header
  1910. 'face 'org-agenda-structure)
  1911. "\n"))
  1912. ((functionp org-agenda-overriding-header)
  1913. (insert (funcall org-agenda-overriding-header)))
  1914. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1915. org-agenda-overriding-header))))
  1916. ;;; Define the org-agenda-mode
  1917. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1918. (defvar org-agenda-mode-map (make-sparse-keymap)
  1919. "Keymap for `org-agenda-mode'.")
  1920. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1921. (defvar org-agenda-menu) ; defined later in this file.
  1922. (defvar org-agenda-restrict nil)
  1923. (defvar org-agenda-follow-mode nil)
  1924. (defvar org-agenda-entry-text-mode nil)
  1925. (defvar org-agenda-clockreport-mode nil)
  1926. (defvar org-agenda-show-log nil
  1927. "When non-nil, show the log in the agenda.
  1928. Do not set this directly; instead use
  1929. `org-agenda-start-with-log-mode', which see.")
  1930. (defvar org-agenda-redo-command nil)
  1931. (defvar org-agenda-query-string nil)
  1932. (defvar org-agenda-mode-hook nil
  1933. "Hook run after `org-agenda-mode' is turned on.
  1934. The buffer is still writable when this hook is called.")
  1935. (defvar org-agenda-type nil)
  1936. (defvar org-agenda-force-single-file nil)
  1937. (defvar org-agenda-bulk-marked-entries nil
  1938. "List of markers that refer to marked entries in the agenda.")
  1939. (defvar org-agenda-current-date nil
  1940. "Active date when building the agenda.")
  1941. ;;; Multiple agenda buffers support
  1942. (defcustom org-agenda-sticky nil
  1943. "Non-nil means agenda q key will bury agenda buffers.
  1944. Agenda commands will then show existing buffer instead of generating new ones.
  1945. When nil, `q' will kill the single agenda buffer."
  1946. :group 'org-agenda
  1947. :version "24.3"
  1948. :type 'boolean)
  1949. ;;;###autoload
  1950. (defun org-toggle-sticky-agenda (&optional arg)
  1951. "Toggle `org-agenda-sticky'."
  1952. (interactive "P")
  1953. (let ((new-value (if arg
  1954. (> (prefix-numeric-value arg) 0)
  1955. (not org-agenda-sticky))))
  1956. (if (equal new-value org-agenda-sticky)
  1957. (and (called-interactively-p 'interactive)
  1958. (message "Sticky agenda was already %s"
  1959. (if org-agenda-sticky "enabled" "disabled")))
  1960. (setq org-agenda-sticky new-value)
  1961. (org-agenda-kill-all-agenda-buffers)
  1962. (and (called-interactively-p 'interactive)
  1963. (message "Sticky agenda %s"
  1964. (if org-agenda-sticky "enabled" "disabled"))))))
  1965. (defvar org-agenda-buffer nil
  1966. "Agenda buffer currently being generated.")
  1967. (defvar org-agenda-last-prefix-arg nil)
  1968. (defvar org-agenda-this-buffer-name nil)
  1969. (defvar org-agenda-doing-sticky-redo nil)
  1970. (defvar org-agenda-this-buffer-is-sticky nil)
  1971. (defvar org-agenda-last-indirect-buffer nil
  1972. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1973. (defconst org-agenda-local-vars
  1974. '(org-agenda-this-buffer-name
  1975. org-agenda-undo-list
  1976. org-agenda-pending-undo-list
  1977. org-agenda-follow-mode
  1978. org-agenda-entry-text-mode
  1979. org-agenda-clockreport-mode
  1980. org-agenda-show-log
  1981. org-agenda-redo-command
  1982. org-agenda-query-string
  1983. org-agenda-type
  1984. org-agenda-bulk-marked-entries
  1985. org-agenda-undo-has-started-in
  1986. org-agenda-info
  1987. org-agenda-pre-window-conf
  1988. org-agenda-columns-active
  1989. org-agenda-tag-filter
  1990. org-agenda-category-filter
  1991. org-agenda-top-headline-filter
  1992. org-agenda-regexp-filter
  1993. org-agenda-effort-filter
  1994. org-agenda-markers
  1995. org-agenda-last-search-view-search-was-boolean
  1996. org-agenda-last-indirect-buffer
  1997. org-agenda-filtered-by-category
  1998. org-agenda-filter-form
  1999. org-agenda-cycle-counter
  2000. org-agenda-last-prefix-arg)
  2001. "Variables that must be local in agenda buffers to allow multiple buffers.")
  2002. (defun org-agenda-mode ()
  2003. "Mode for time-sorted view on action items in Org files.
  2004. The following commands are available:
  2005. \\{org-agenda-mode-map}"
  2006. (interactive)
  2007. (ignore-errors (require 'face-remap))
  2008. (let ((agenda-local-vars-to-keep
  2009. '(text-scale-mode-amount
  2010. text-scale-mode
  2011. text-scale-mode-lighter
  2012. face-remapping-alist))
  2013. (save (buffer-local-variables)))
  2014. (kill-all-local-variables)
  2015. (cl-flet ((reset-saved (var-set)
  2016. "Reset variables in VAR-SET to possibly stored value in SAVE."
  2017. (dolist (elem save)
  2018. (pcase elem
  2019. (`(,var . ,val) ;ignore unbound variables
  2020. (when (and val (memq var var-set))
  2021. (set var val)))))))
  2022. (cond (org-agenda-doing-sticky-redo
  2023. ;; Refreshing sticky agenda-buffer
  2024. ;;
  2025. ;; Preserve the value of `org-agenda-local-vars' variables.
  2026. (mapc #'make-local-variable org-agenda-local-vars)
  2027. (reset-saved org-agenda-local-vars)
  2028. (setq-local org-agenda-this-buffer-is-sticky t))
  2029. (org-agenda-sticky
  2030. ;; Creating a sticky Agenda buffer for the first time
  2031. (mapc #'make-local-variable org-agenda-local-vars)
  2032. (setq-local org-agenda-this-buffer-is-sticky t))
  2033. (t
  2034. ;; Creating a non-sticky agenda buffer
  2035. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2036. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2037. (reset-saved agenda-local-vars-to-keep)))
  2038. (setq org-agenda-undo-list nil
  2039. org-agenda-pending-undo-list nil
  2040. org-agenda-bulk-marked-entries nil)
  2041. (setq major-mode 'org-agenda-mode)
  2042. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2043. (setq-local font-lock-global-modes (list 'not major-mode))
  2044. (setq mode-name "Org-Agenda")
  2045. (setq indent-tabs-mode nil)
  2046. (use-local-map org-agenda-mode-map)
  2047. (when org-startup-truncated (setq truncate-lines t))
  2048. (setq-local line-move-visual nil)
  2049. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2050. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2051. ;; Make sure properties are removed when copying text
  2052. (if (boundp 'filter-buffer-substring-functions)
  2053. (add-hook 'filter-buffer-substring-functions
  2054. (lambda (fun start end delete)
  2055. (substring-no-properties (funcall fun start end delete)))
  2056. nil t)
  2057. ;; Emacs >= 24.4.
  2058. (add-function :filter-return (local 'filter-buffer-substring-function)
  2059. #'substring-no-properties))
  2060. (unless org-agenda-keep-modes
  2061. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2062. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2063. org-agenda-show-log org-agenda-start-with-log-mode
  2064. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2065. (add-to-invisibility-spec '(org-filtered))
  2066. (org-fold-core-initialize `(,org-link--description-folding-spec
  2067. ,org-link--link-folding-spec))
  2068. (easy-menu-change
  2069. '("Agenda") "Agenda Files"
  2070. (append
  2071. (list
  2072. (vector
  2073. (if (get 'org-agenda-files 'org-restrict)
  2074. "Restricted to single file"
  2075. "Edit File List")
  2076. '(org-edit-agenda-file-list)
  2077. (not (get 'org-agenda-files 'org-restrict)))
  2078. "--")
  2079. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2080. (org-agenda-set-mode-name)
  2081. (run-mode-hooks 'org-agenda-mode-hook))
  2082. (substitute-key-definition #'undo #'org-agenda-undo
  2083. org-agenda-mode-map global-map)
  2084. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2085. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2086. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2087. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2088. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2089. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2090. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2091. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2092. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2093. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2094. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2095. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2096. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2097. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2098. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2099. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2100. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2101. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2102. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2103. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2104. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2105. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2106. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2107. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2108. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2109. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2110. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2111. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2112. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2113. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2114. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2115. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2116. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2117. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2118. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2119. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2120. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2121. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2122. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2123. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2124. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2125. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2126. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2127. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2128. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2129. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2130. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2131. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2132. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2133. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2134. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2135. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2136. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2137. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2138. (while l (org-defkey org-agenda-mode-map
  2139. (number-to-string (pop l)) #'digit-argument)))
  2140. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2141. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2142. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2143. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2144. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2145. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2146. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2147. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2148. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2149. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2150. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2151. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2152. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2153. #'org-clock-modify-effort-estimate)
  2154. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2155. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2156. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2157. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2158. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2159. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2160. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2161. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2162. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2163. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2164. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2165. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2166. (substitute-key-definition #'next-line #'org-agenda-next-line
  2167. org-agenda-mode-map global-map)
  2168. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2169. org-agenda-mode-map global-map)
  2170. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2171. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2172. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2173. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2174. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2175. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2176. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2177. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2178. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2179. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2180. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2181. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2182. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2183. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2184. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2185. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2186. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2187. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2188. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2189. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2190. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2191. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2192. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2193. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2194. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2195. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2196. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2197. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2198. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2199. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2200. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2201. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2202. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2203. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2204. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2205. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2206. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2207. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2208. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2209. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2210. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2211. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2212. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2213. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2214. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2215. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2216. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2217. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2218. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2219. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2220. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2221. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2222. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2223. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2224. (when org-agenda-mouse-1-follows-link
  2225. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2226. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2227. '("Agenda"
  2228. ("Agenda Files")
  2229. "--"
  2230. ("Agenda Dates"
  2231. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2232. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2233. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2234. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2235. "--"
  2236. ("View"
  2237. ["Day View" org-agenda-day-view
  2238. :active (org-agenda-check-type nil 'agenda)
  2239. :style radio :selected (eq org-agenda-current-span 'day)
  2240. :keys "v d (or just d)"]
  2241. ["Week View" org-agenda-week-view
  2242. :active (org-agenda-check-type nil 'agenda)
  2243. :style radio :selected (eq org-agenda-current-span 'week)
  2244. :keys "v w"]
  2245. ["Fortnight View" org-agenda-fortnight-view
  2246. :active (org-agenda-check-type nil 'agenda)
  2247. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2248. :keys "v t"]
  2249. ["Month View" org-agenda-month-view
  2250. :active (org-agenda-check-type nil 'agenda)
  2251. :style radio :selected (eq org-agenda-current-span 'month)
  2252. :keys "v m"]
  2253. ["Year View" org-agenda-year-view
  2254. :active (org-agenda-check-type nil 'agenda)
  2255. :style radio :selected (eq org-agenda-current-span 'year)
  2256. :keys "v y"]
  2257. "--"
  2258. ["Include Diary" org-agenda-toggle-diary
  2259. :style toggle :selected org-agenda-include-diary
  2260. :active (org-agenda-check-type nil 'agenda)]
  2261. ["Include Deadlines" org-agenda-toggle-deadlines
  2262. :style toggle :selected org-agenda-include-deadlines
  2263. :active (org-agenda-check-type nil 'agenda)]
  2264. ["Use Time Grid" org-agenda-toggle-time-grid
  2265. :style toggle :selected org-agenda-use-time-grid
  2266. :active (org-agenda-check-type nil 'agenda)]
  2267. "--"
  2268. ["Show clock report" org-agenda-clockreport-mode
  2269. :style toggle :selected org-agenda-clockreport-mode
  2270. :active (org-agenda-check-type nil 'agenda)]
  2271. ["Show some entry text" org-agenda-entry-text-mode
  2272. :style toggle :selected org-agenda-entry-text-mode
  2273. :active t]
  2274. "--"
  2275. ["Show Logbook entries" org-agenda-log-mode
  2276. :style toggle :selected org-agenda-show-log
  2277. :active (org-agenda-check-type nil 'agenda)
  2278. :keys "v l (or just l)"]
  2279. ["Include archived trees" org-agenda-archives-mode
  2280. :style toggle :selected org-agenda-archives-mode :active t
  2281. :keys "v a"]
  2282. ["Include archive files" (org-agenda-archives-mode t)
  2283. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2284. :keys "v A"]
  2285. "--"
  2286. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2287. ("Filter current view"
  2288. ["with generic interface" org-agenda-filter t]
  2289. "--"
  2290. ["by category at cursor" org-agenda-filter-by-category t]
  2291. ["by tag" org-agenda-filter-by-tag t]
  2292. ["by effort" org-agenda-filter-by-effort t]
  2293. ["by regexp" org-agenda-filter-by-regexp t]
  2294. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2295. "--"
  2296. ["Remove all filtering" org-agenda-filter-remove-all t]
  2297. "--"
  2298. ["limit" org-agenda-limit-interactively t])
  2299. ["Rebuild buffer" org-agenda-redo t]
  2300. ["Write view to file" org-agenda-write t]
  2301. ["Save all Org buffers" org-save-all-org-buffers t]
  2302. "--"
  2303. ["Show original entry" org-agenda-show t]
  2304. ["Go To (other window)" org-agenda-goto t]
  2305. ["Go To (this window)" org-agenda-switch-to t]
  2306. ["Capture with cursor date" org-agenda-capture t]
  2307. ["Follow Mode" org-agenda-follow-mode
  2308. :style toggle :selected org-agenda-follow-mode :active t]
  2309. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2310. "--"
  2311. ("TODO"
  2312. ["Cycle TODO" org-agenda-todo t]
  2313. ["Next TODO set" org-agenda-todo-nextset t]
  2314. ["Previous TODO set" org-agenda-todo-previousset t]
  2315. ["Add note" org-agenda-add-note t])
  2316. ("Archive/Refile/Delete"
  2317. ["Archive default" org-agenda-archive-default t]
  2318. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2319. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2320. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2321. ["Archive subtree" org-agenda-archive t]
  2322. "--"
  2323. ["Refile" org-agenda-refile t]
  2324. "--"
  2325. ["Delete subtree" org-agenda-kill t])
  2326. ("Bulk action"
  2327. ["Mark entry" org-agenda-bulk-mark t]
  2328. ["Mark all" org-agenda-bulk-mark-all t]
  2329. ["Unmark entry" org-agenda-bulk-unmark t]
  2330. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2331. ["Toggle mark" org-agenda-bulk-toggle t]
  2332. ["Toggle all" org-agenda-bulk-toggle-all t]
  2333. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2334. ["Act on all marked" org-agenda-bulk-action t]
  2335. "--"
  2336. ("Tags and Properties"
  2337. ["Show all Tags" org-agenda-show-tags t]
  2338. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2339. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2340. "--"
  2341. ["Column View" org-columns t])
  2342. ("Deadline/Schedule"
  2343. ["Schedule" org-agenda-schedule t]
  2344. ["Set Deadline" org-agenda-deadline t]
  2345. "--"
  2346. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2347. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2348. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2349. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2350. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2351. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2352. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2353. ("Clock and Effort"
  2354. ["Clock in" org-agenda-clock-in t]
  2355. ["Clock out" org-agenda-clock-out t]
  2356. ["Clock cancel" org-agenda-clock-cancel t]
  2357. ["Goto running clock" org-clock-goto t]
  2358. "--"
  2359. ["Set Effort" org-agenda-set-effort t]
  2360. ["Change clocked effort" org-clock-modify-effort-estimate
  2361. (org-clock-is-active)])
  2362. ("Priority"
  2363. ["Set Priority" org-agenda-priority t]
  2364. ["Increase Priority" org-agenda-priority-up t]
  2365. ["Decrease Priority" org-agenda-priority-down t]
  2366. ["Show Priority" org-priority-show t])
  2367. ("Calendar/Diary"
  2368. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2369. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2370. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2371. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2372. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2373. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2374. "--"
  2375. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2376. "--"
  2377. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2378. "--"
  2379. ("MobileOrg"
  2380. ["Push Files and Views" org-mobile-push t]
  2381. ["Get Captured and Flagged" org-mobile-pull t]
  2382. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2383. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2384. "--"
  2385. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2386. "--"
  2387. ["Quit" org-agenda-quit t]
  2388. ["Exit and Release Buffers" org-agenda-exit t]
  2389. ))
  2390. ;;; Agenda undo
  2391. (defvar org-agenda-allow-remote-undo t
  2392. "Non-nil means allow remote undo from the agenda buffer.")
  2393. (defvar org-agenda-undo-has-started-in nil
  2394. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2395. (defun org-agenda-undo ()
  2396. "Undo a remote editing step in the agenda.
  2397. This undoes changes both in the agenda buffer and in the remote buffer
  2398. that have been changed along."
  2399. (interactive)
  2400. (or org-agenda-allow-remote-undo
  2401. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2402. (when (not (eq this-command last-command))
  2403. (setq org-agenda-undo-has-started-in nil
  2404. org-agenda-pending-undo-list org-agenda-undo-list))
  2405. (when (not org-agenda-pending-undo-list)
  2406. (user-error "No further undo information"))
  2407. (let* ((entry (pop org-agenda-pending-undo-list))
  2408. buf line cmd rembuf)
  2409. (setq cmd (pop entry) line (pop entry))
  2410. (setq rembuf (nth 2 entry))
  2411. (org-with-remote-undo rembuf
  2412. (while (bufferp (setq buf (pop entry)))
  2413. (when (pop entry)
  2414. (with-current-buffer buf
  2415. (let (;; (last-undo-buffer buf)
  2416. (inhibit-read-only t))
  2417. (unless (memq buf org-agenda-undo-has-started-in)
  2418. (push buf org-agenda-undo-has-started-in)
  2419. (make-local-variable 'pending-undo-list)
  2420. (undo-start))
  2421. (while (and pending-undo-list
  2422. (listp pending-undo-list)
  2423. (not (car pending-undo-list)))
  2424. (pop pending-undo-list))
  2425. (undo-more 1))))))
  2426. (org-goto-line line)
  2427. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2428. (defun org-verify-change-for-undo (l1 l2)
  2429. "Verify that a real change occurred between the undo lists L1 and L2."
  2430. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2431. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2432. (not (eq l1 l2)))
  2433. ;;; Agenda dispatch
  2434. (defvar org-agenda-restrict-begin (make-marker))
  2435. (defvar org-agenda-restrict-end (make-marker))
  2436. (defvar org-agenda-last-dispatch-buffer nil)
  2437. (defvar org-agenda-overriding-restriction nil)
  2438. (defcustom org-agenda-custom-commands-contexts nil
  2439. "Alist of custom agenda keys and contextual rules.
  2440. For example, if you have a custom agenda command \"p\" and you
  2441. want this command to be accessible only from plain text files,
  2442. use this:
  2443. (setq org-agenda-custom-commands-contexts
  2444. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\")))))
  2445. Here are the available contexts definitions:
  2446. in-file: command displayed only in matching files
  2447. in-mode: command displayed only in matching modes
  2448. not-in-file: command not displayed in matching files
  2449. not-in-mode: command not displayed in matching modes
  2450. in-buffer: command displayed only in matching buffers
  2451. not-in-buffer: command not displayed in matching buffers
  2452. [function]: a custom function taking no argument
  2453. If you define several checks, the agenda command will be
  2454. accessible if there is at least one valid check.
  2455. You can also bind a key to another agenda custom command
  2456. depending on contextual rules.
  2457. (setq org-agenda-custom-commands-contexts
  2458. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\")))))
  2459. Here it means: in .txt files, use \"p\" as the key for the
  2460. agenda command otherwise associated with \"q\". (The command
  2461. originally associated with \"q\" is not displayed to avoid
  2462. duplicates.)"
  2463. :version "24.3"
  2464. :group 'org-agenda-custom-commands
  2465. :type '(repeat (list :tag "Rule"
  2466. (string :tag " Agenda key")
  2467. (string :tag "Replace by command")
  2468. (repeat :tag "Available when"
  2469. (choice
  2470. (cons :tag "Condition"
  2471. (choice
  2472. (const :tag "In file" in-file)
  2473. (const :tag "Not in file" not-in-file)
  2474. (const :tag "In buffer" in-buffer)
  2475. (const :tag "Not in buffer" not-in-buffer)
  2476. (const :tag "In mode" in-mode)
  2477. (const :tag "Not in mode" not-in-mode))
  2478. (regexp))
  2479. (function :tag "Custom function"))))))
  2480. (defcustom org-agenda-max-entries nil
  2481. "Maximum number of entries to display in an agenda.
  2482. This can be nil (no limit) or an integer or an alist of agenda
  2483. types with an associated number of entries to display in this
  2484. type."
  2485. :version "24.4"
  2486. :package-version '(Org . "8.0")
  2487. :group 'org-agenda-custom-commands
  2488. :type '(choice (symbol :tag "No limit" nil)
  2489. (integer :tag "Max number of entries")
  2490. (repeat
  2491. (cons (choice :tag "Agenda type"
  2492. (const agenda)
  2493. (const todo)
  2494. (const tags)
  2495. (const search))
  2496. (integer :tag "Max number of entries")))))
  2497. (defcustom org-agenda-max-todos nil
  2498. "Maximum number of TODOs to display in an agenda.
  2499. This can be nil (no limit) or an integer or an alist of agenda
  2500. types with an associated number of entries to display in this
  2501. type."
  2502. :version "24.4"
  2503. :package-version '(Org . "8.0")
  2504. :group 'org-agenda-custom-commands
  2505. :type '(choice (symbol :tag "No limit" nil)
  2506. (integer :tag "Max number of TODOs")
  2507. (repeat
  2508. (cons (choice :tag "Agenda type"
  2509. (const agenda)
  2510. (const todo)
  2511. (const tags)
  2512. (const search))
  2513. (integer :tag "Max number of TODOs")))))
  2514. (defcustom org-agenda-max-tags nil
  2515. "Maximum number of tagged entries to display in an agenda.
  2516. This can be nil (no limit) or an integer or an alist of agenda
  2517. types with an associated number of entries to display in this
  2518. type."
  2519. :version "24.4"
  2520. :package-version '(Org . "8.0")
  2521. :group 'org-agenda-custom-commands
  2522. :type '(choice (symbol :tag "No limit" nil)
  2523. (integer :tag "Max number of tagged entries")
  2524. (repeat
  2525. (cons (choice :tag "Agenda type"
  2526. (const agenda)
  2527. (const todo)
  2528. (const tags)
  2529. (const search))
  2530. (integer :tag "Max number of tagged entries")))))
  2531. (defcustom org-agenda-max-effort nil
  2532. "Maximum cumulated effort duration for the agenda.
  2533. This can be nil (no limit) or a number of minutes (as an integer)
  2534. or an alist of agenda types with an associated number of minutes
  2535. to limit entries to in this type."
  2536. :version "24.4"
  2537. :package-version '(Org . "8.0")
  2538. :group 'org-agenda-custom-commands
  2539. :type '(choice (symbol :tag "No limit" nil)
  2540. (integer :tag "Max number of minutes")
  2541. (repeat
  2542. (cons (choice :tag "Agenda type"
  2543. (const agenda)
  2544. (const todo)
  2545. (const tags)
  2546. (const search))
  2547. (integer :tag "Max number of minutes")))))
  2548. (defvar org-agenda-keep-restricted-file-list nil)
  2549. (defvar org-keys nil)
  2550. (defvar org-match nil)
  2551. ;;;###autoload
  2552. (defun org-agenda (&optional arg keys restriction)
  2553. "Dispatch agenda commands to collect entries to the agenda buffer.
  2554. Prompts for a command to execute. Any prefix arg will be passed
  2555. on to the selected command. The default selections are:
  2556. a Call `org-agenda-list' to display the agenda for current day or week.
  2557. t Call `org-todo-list' to display the global todo list.
  2558. T Call `org-todo-list' to display the global todo list, select only
  2559. entries with a specific TODO keyword (the user gets a prompt).
  2560. m Call `org-tags-view' to display headlines with tags matching
  2561. a condition (the user is prompted for the condition).
  2562. M Like `m', but select only TODO entries, no ordinary headlines.
  2563. e Export views to associated files.
  2564. s Search entries for keywords.
  2565. S Search entries for keywords, only with TODO keywords.
  2566. / Multi occur across all agenda files and also files listed
  2567. in `org-agenda-text-search-extra-files'.
  2568. < Restrict agenda commands to buffer, subtree, or region.
  2569. Press several times to get the desired effect.
  2570. > Remove a previous restriction.
  2571. # List \"stuck\" projects.
  2572. ! Configure what \"stuck\" means.
  2573. C Configure custom agenda commands.
  2574. More commands can be added by configuring the variable
  2575. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2576. searches can be pre-defined in this way.
  2577. If the current buffer is in Org mode and visiting a file, you can also
  2578. first press `<' once to indicate that the agenda should be temporarily
  2579. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2580. Pressing `<' twice means to restrict to the current subtree or region
  2581. \(if active)."
  2582. (interactive "P")
  2583. (catch 'exit
  2584. (let* ((org-keys keys)
  2585. (prefix-descriptions nil)
  2586. (org-agenda-buffer-name org-agenda-buffer-name)
  2587. (org-agenda-window-setup (if (equal (buffer-name)
  2588. org-agenda-buffer-name)
  2589. 'current-window
  2590. org-agenda-window-setup))
  2591. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2592. (org-agenda-custom-commands
  2593. ;; normalize different versions
  2594. (delq nil
  2595. (mapcar
  2596. (lambda (x)
  2597. (cond ((stringp (cdr x))
  2598. (push x prefix-descriptions)
  2599. nil)
  2600. ((stringp (nth 1 x)) x)
  2601. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2602. (t (cons (car x) (cons "" (cdr x))))))
  2603. org-agenda-custom-commands)))
  2604. (org-agenda-custom-commands
  2605. (org-contextualize-keys
  2606. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2607. ;; (buf (current-buffer))
  2608. (bfn (buffer-file-name (buffer-base-buffer)))
  2609. entry type org-match lprops ans) ;; key
  2610. ;; Turn off restriction unless there is an overriding one,
  2611. (unless org-agenda-overriding-restriction
  2612. (unless org-agenda-keep-restricted-file-list
  2613. ;; There is a request to keep the file list in place
  2614. (put 'org-agenda-files 'org-restrict nil))
  2615. (setq org-agenda-restrict nil)
  2616. (move-marker org-agenda-restrict-begin nil)
  2617. (move-marker org-agenda-restrict-end nil))
  2618. ;; Delete old local properties
  2619. (put 'org-agenda-redo-command 'org-lprops nil)
  2620. ;; Delete previously set last-arguments
  2621. (put 'org-agenda-redo-command 'last-args nil)
  2622. ;; Remember where this call originated
  2623. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2624. (unless org-keys
  2625. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2626. org-keys (car ans)
  2627. restriction (cdr ans)))
  2628. ;; If we have sticky agenda buffers, set a name for the buffer,
  2629. ;; depending on the invoking keys. The user may still set this
  2630. ;; as a command option, which will overwrite what we do here.
  2631. (when org-agenda-sticky
  2632. (setq org-agenda-buffer-name
  2633. (format "*Org Agenda(%s)*" org-keys)))
  2634. ;; Establish the restriction, if any
  2635. (when (and (not org-agenda-overriding-restriction) restriction)
  2636. (put 'org-agenda-files 'org-restrict (list bfn))
  2637. (cond
  2638. ((eq restriction 'region)
  2639. (setq org-agenda-restrict (current-buffer))
  2640. (move-marker org-agenda-restrict-begin (region-beginning))
  2641. (move-marker org-agenda-restrict-end (region-end)))
  2642. ((eq restriction 'subtree)
  2643. (save-excursion
  2644. (setq org-agenda-restrict (current-buffer))
  2645. (org-back-to-heading t)
  2646. (move-marker org-agenda-restrict-begin (point))
  2647. (move-marker org-agenda-restrict-end
  2648. (progn (org-end-of-subtree t)))))
  2649. ((and (eq restriction 'buffer)
  2650. (or (< 1 (point-min))
  2651. (< (point-max) (1+ (buffer-size)))))
  2652. (setq org-agenda-restrict (current-buffer))
  2653. (move-marker org-agenda-restrict-begin (point-min))
  2654. (move-marker org-agenda-restrict-end (point-max)))))
  2655. ;; For example the todo list should not need it (but does...)
  2656. (cond
  2657. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2658. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2659. (progn
  2660. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2661. ;; to some of the local variables? There's no doc about
  2662. ;; that for `org-agenda-custom-commands'.
  2663. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2664. lprops (nth 4 entry))
  2665. (when org-agenda-sticky
  2666. (setq org-agenda-buffer-name
  2667. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2668. (format "*Org Agenda(%s)*" org-keys))))
  2669. (put 'org-agenda-redo-command 'org-lprops lprops)
  2670. (cl-progv
  2671. (mapcar #'car lprops)
  2672. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2673. (pcase type
  2674. (`agenda
  2675. (org-agenda-list arg))
  2676. (`agenda*
  2677. (org-agenda-list arg nil nil t))
  2678. (`alltodo
  2679. (org-todo-list arg))
  2680. (`search
  2681. (org-search-view arg org-match nil))
  2682. (`stuck
  2683. (org-agenda-list-stuck-projects arg))
  2684. (`tags
  2685. (org-tags-view arg org-match))
  2686. (`tags-todo
  2687. (org-tags-view '(4) org-match))
  2688. (`todo
  2689. (org-todo-list org-match))
  2690. (`tags-tree
  2691. (org-check-for-org-mode)
  2692. (org-match-sparse-tree arg org-match))
  2693. (`todo-tree
  2694. (org-check-for-org-mode)
  2695. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2696. (regexp-quote org-match) "\\>")))
  2697. (`occur-tree
  2698. (org-check-for-org-mode)
  2699. (org-occur org-match))
  2700. ((pred functionp)
  2701. (funcall type org-match))
  2702. ;; FIXME: Will signal an error since it's not `functionp'!
  2703. ((pred fboundp) (funcall type org-match))
  2704. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2705. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2706. ((equal org-keys "C")
  2707. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2708. (customize-variable 'org-agenda-custom-commands))
  2709. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2710. ((equal org-keys "s") (call-interactively 'org-search-view))
  2711. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2712. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2713. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2714. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2715. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2716. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2717. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2718. (add-hook
  2719. 'post-command-hook
  2720. (lambda ()
  2721. (unless (current-message)
  2722. (let* ((m (org-agenda-get-any-marker))
  2723. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2724. (when note
  2725. (message "FLAGGING-NOTE ([?] for more info): %s"
  2726. (org-add-props
  2727. (replace-regexp-in-string
  2728. "\\\\n" "//"
  2729. (copy-sequence note))
  2730. nil 'face 'org-warning))))))
  2731. t t))
  2732. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2733. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2734. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2735. (t (user-error "Invalid agenda key"))))))
  2736. (defvar org-agenda-multi)
  2737. (defun org-agenda-append-agenda ()
  2738. "Append another agenda view to the current one.
  2739. This function allows interactive building of block agendas.
  2740. Agenda views are separated by `org-agenda-block-separator'."
  2741. (interactive)
  2742. (unless (derived-mode-p 'org-agenda-mode)
  2743. (user-error "Can only append from within agenda buffer"))
  2744. (let ((org-agenda-multi t))
  2745. (org-agenda)
  2746. (widen)
  2747. (org-agenda-finalize)
  2748. (setq buffer-read-only t)
  2749. (org-agenda-fit-window-to-buffer)))
  2750. (defun org-agenda-normalize-custom-commands (cmds)
  2751. "Normalize custom commands CMDS."
  2752. (delq nil
  2753. (mapcar
  2754. (lambda (x)
  2755. (cond ((stringp (cdr x)) nil)
  2756. ((stringp (nth 1 x)) x)
  2757. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2758. (t (cons (car x) (cons "" (cdr x))))))
  2759. cmds)))
  2760. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2761. "The user interface for selecting an agenda command."
  2762. (catch 'exit
  2763. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2764. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2765. (region-p (org-region-active-p))
  2766. (custom org-agenda-custom-commands)
  2767. (selstring "")
  2768. restriction second-time
  2769. c entry key type match prefixes rmheader header-end custom1 desc
  2770. line lines left right n n1)
  2771. (save-window-excursion
  2772. (delete-other-windows)
  2773. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2774. (erase-buffer)
  2775. (insert (eval-when-compile
  2776. (let ((header
  2777. (copy-sequence
  2778. "Press key for an agenda command:
  2779. -------------------------------- < Buffer, subtree/region restriction
  2780. a Agenda for current week or day > Remove restriction
  2781. t List of all TODO entries e Export agenda views
  2782. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2783. s Search for keywords M Like m, but only TODO entries
  2784. / Multi-occur S Like s, but only TODO entries
  2785. ? Find :FLAGGED: entries C Configure custom agenda commands
  2786. * Toggle sticky agenda views # List stuck projects (!=configure)
  2787. "))
  2788. (start 0))
  2789. (while (string-match
  2790. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2791. header start)
  2792. (setq start (match-end 0))
  2793. (add-text-properties (match-beginning 2) (match-end 2)
  2794. '(face bold) header))
  2795. header)))
  2796. (setq header-end (point-marker))
  2797. (while t
  2798. (setq custom1 custom)
  2799. (when (eq rmheader t)
  2800. (org-goto-line 1)
  2801. (re-search-forward ":" nil t)
  2802. (delete-region (match-end 0) (point-at-eol))
  2803. (forward-char 1)
  2804. (looking-at "-+")
  2805. (delete-region (match-end 0) (point-at-eol))
  2806. (move-marker header-end (match-end 0)))
  2807. (goto-char header-end)
  2808. (delete-region (point) (point-max))
  2809. ;; Produce all the lines that describe custom commands and prefixes
  2810. (setq lines nil)
  2811. (while (setq entry (pop custom1))
  2812. (setq key (car entry) desc (nth 1 entry)
  2813. type (nth 2 entry)
  2814. match (nth 3 entry))
  2815. (if (> (length key) 1)
  2816. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2817. (setq line
  2818. (format
  2819. "%-4s%-14s"
  2820. (org-add-props (copy-sequence key)
  2821. '(face bold))
  2822. (cond
  2823. ((string-match "\\S-" desc) desc)
  2824. ((eq type 'agenda) "Agenda for current week or day")
  2825. ((eq type 'agenda*) "Appointments for current week or day")
  2826. ((eq type 'alltodo) "List of all TODO entries")
  2827. ((eq type 'search) "Word search")
  2828. ((eq type 'stuck) "List of stuck projects")
  2829. ((eq type 'todo) "TODO keyword")
  2830. ((eq type 'tags) "Tags query")
  2831. ((eq type 'tags-todo) "Tags (TODO)")
  2832. ((eq type 'tags-tree) "Tags tree")
  2833. ((eq type 'todo-tree) "TODO kwd tree")
  2834. ((eq type 'occur-tree) "Occur tree")
  2835. ((functionp type) (if (symbolp type)
  2836. (symbol-name type)
  2837. "Lambda expression"))
  2838. (t "???"))))
  2839. (cond
  2840. ((not (org-string-nw-p match)) nil)
  2841. (org-agenda-menu-show-matcher
  2842. (setq line
  2843. (concat line ": "
  2844. (cond
  2845. ((stringp match)
  2846. (propertize match 'face 'org-warning))
  2847. ((listp type)
  2848. (format "set of %d commands" (length type)))))))
  2849. (t
  2850. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2851. (push line lines)))
  2852. (setq lines (nreverse lines))
  2853. (when prefixes
  2854. (mapc (lambda (x)
  2855. (push
  2856. (format "%s %s"
  2857. (org-add-props (char-to-string x)
  2858. nil 'face 'bold)
  2859. (or (cdr (assoc (concat selstring
  2860. (char-to-string x))
  2861. prefix-descriptions))
  2862. "Prefix key"))
  2863. lines))
  2864. prefixes))
  2865. ;; Check if we should display in two columns
  2866. (if org-agenda-menu-two-columns
  2867. (progn
  2868. (setq n (length lines)
  2869. n1 (+ (/ n 2) (mod n 2))
  2870. right (nthcdr n1 lines)
  2871. left (copy-sequence lines))
  2872. (setcdr (nthcdr (1- n1) left) nil))
  2873. (setq left lines right nil))
  2874. (while left
  2875. (insert "\n" (pop left))
  2876. (when right
  2877. (if (< (current-column) 40)
  2878. (move-to-column 40 t)
  2879. (insert " "))
  2880. (insert (pop right))))
  2881. ;; Make the window the right size
  2882. (goto-char (point-min))
  2883. (if second-time
  2884. (when (not (pos-visible-in-window-p (point-max)))
  2885. (org-fit-window-to-buffer))
  2886. (setq second-time t)
  2887. (org-fit-window-to-buffer))
  2888. ;; Hint to navigation if window too small for all information
  2889. (setq header-line-format
  2890. (when (not (pos-visible-in-window-p (point-max)))
  2891. "Use C-v, M-v, C-n or C-p to navigate."))
  2892. ;; Ask for selection
  2893. (cl-loop
  2894. do (progn
  2895. (message "Press key for agenda command%s:"
  2896. (if (or restrict-ok org-agenda-overriding-restriction)
  2897. (if org-agenda-overriding-restriction
  2898. " (restriction lock active)"
  2899. (if restriction
  2900. (format " (restricted to %s)" restriction)
  2901. " (unrestricted)"))
  2902. ""))
  2903. (setq c (read-char-exclusive)))
  2904. until (not (memq c '(14 16 22 134217846)))
  2905. do (org-scroll c))
  2906. (message "")
  2907. (cond
  2908. ((assoc (char-to-string c) custom)
  2909. (setq selstring (concat selstring (char-to-string c)))
  2910. (throw 'exit (cons selstring restriction)))
  2911. ((memq c prefixes)
  2912. (setq selstring (concat selstring (char-to-string c))
  2913. prefixes nil
  2914. rmheader (or rmheader t)
  2915. custom (delq nil (mapcar
  2916. (lambda (x)
  2917. (if (or (= (length (car x)) 1)
  2918. (/= (string-to-char (car x)) c))
  2919. nil
  2920. (cons (substring (car x) 1) (cdr x))))
  2921. custom))))
  2922. ((eq c ?*)
  2923. (call-interactively 'org-toggle-sticky-agenda)
  2924. (sit-for 2))
  2925. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2926. (message "Restriction is only possible in Org buffers")
  2927. (ding) (sit-for 1))
  2928. ((eq c ?1)
  2929. (org-agenda-remove-restriction-lock 'noupdate)
  2930. (setq restriction 'buffer))
  2931. ((eq c ?0)
  2932. (org-agenda-remove-restriction-lock 'noupdate)
  2933. (setq restriction (if region-p 'region 'subtree)))
  2934. ((eq c ?<)
  2935. (org-agenda-remove-restriction-lock 'noupdate)
  2936. (setq restriction
  2937. (cond
  2938. ((eq restriction 'buffer)
  2939. (if region-p 'region 'subtree))
  2940. ((memq restriction '(subtree region))
  2941. nil)
  2942. (t 'buffer))))
  2943. ((eq c ?>)
  2944. (org-agenda-remove-restriction-lock 'noupdate)
  2945. (setq restriction nil))
  2946. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2947. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2948. ((and (> (length selstring) 0) (eq c ?\d))
  2949. (delete-window)
  2950. (org-agenda-get-restriction-and-command prefix-descriptions))
  2951. ((equal c ?q) (user-error "Abort"))
  2952. (t (user-error "Invalid key %c" c))))))))
  2953. (defun org-agenda-fit-window-to-buffer ()
  2954. "Fit the window to the buffer size."
  2955. (and (memq org-agenda-window-setup '(reorganize-frame))
  2956. (fboundp 'fit-window-to-buffer)
  2957. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2958. (= (car org-agenda-window-frame-fractions) 1.0))
  2959. (delete-other-windows)
  2960. (org-fit-window-to-buffer
  2961. nil
  2962. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2963. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2964. (defvar org-cmd nil)
  2965. (defvar org-agenda-overriding-cmd nil)
  2966. (defvar org-agenda-overriding-arguments nil)
  2967. (defvar org-agenda-overriding-cmd-arguments nil)
  2968. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2969. (declare (indent 1) (obsolete cl-progv "2021"))
  2970. (eval (cons 'let (cons list body))))
  2971. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2972. (declare (indent 2) (obsolete cl-progv "2021"))
  2973. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2974. (defun org-agenda-run-series (name series)
  2975. "Run agenda NAME as a SERIES of agenda commands."
  2976. (let* ((gprops (nth 1 series))
  2977. (gvars (mapcar #'car gprops))
  2978. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2979. (cl-progv gvars gvals (org-agenda-prepare name))
  2980. ;; We need to reset agenda markers here, because when constructing a
  2981. ;; block agenda, the individual blocks do not do that.
  2982. (org-agenda-reset-markers)
  2983. (with-no-warnings
  2984. (defvar match)) ;Used via the `eval' below.
  2985. (let* ((org-agenda-multi t)
  2986. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2987. ;; than expressions, so you don't need to `quote' the args
  2988. ;; and you just need to `apply' instead of `eval' when using it.
  2989. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2990. (cmds (car series))
  2991. match
  2992. org-cmd type lprops)
  2993. (while (setq org-cmd (pop cmds))
  2994. (setq type (car org-cmd))
  2995. (setq match (eval (nth 1 org-cmd) t))
  2996. (setq lprops (nth 2 org-cmd))
  2997. (let ((org-agenda-overriding-arguments
  2998. (if (eq org-agenda-overriding-cmd org-cmd)
  2999. (or org-agenda-overriding-arguments
  3000. org-agenda-overriding-cmd-arguments)))
  3001. (lvars (mapcar #'car lprops))
  3002. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  3003. (cl-progv (append gvars lvars) (append gvals lvals)
  3004. (pcase type
  3005. (`agenda
  3006. (call-interactively 'org-agenda-list))
  3007. (`agenda*
  3008. (funcall 'org-agenda-list nil nil t))
  3009. (`alltodo
  3010. (call-interactively 'org-todo-list))
  3011. (`search
  3012. (org-search-view current-prefix-arg match nil))
  3013. (`stuck
  3014. (call-interactively 'org-agenda-list-stuck-projects))
  3015. (`tags
  3016. (org-tags-view current-prefix-arg match))
  3017. (`tags-todo
  3018. (org-tags-view '(4) match))
  3019. (`todo
  3020. (org-todo-list match))
  3021. ((pred fboundp)
  3022. (funcall type match))
  3023. (_ (error "Invalid type in command series"))))))
  3024. (widen)
  3025. (let ((inhibit-read-only t))
  3026. (add-text-properties (point-min) (point-max)
  3027. `(org-series t org-series-redo-cmd ,redo)))
  3028. (setq org-agenda-redo-command redo)
  3029. (goto-char (point-min)))
  3030. (org-agenda-fit-window-to-buffer)
  3031. (cl-progv gvars gvals (org-agenda-finalize))))
  3032. (defun org-agenda--split-plist (plist)
  3033. ;; We could/should arguably use `map-keys' and `map-values'.
  3034. (let (keys vals)
  3035. (while plist
  3036. (push (pop plist) keys)
  3037. (push (pop plist) vals))
  3038. (cons (nreverse keys) (nreverse vals))))
  3039. ;;;###autoload
  3040. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3041. "Run an agenda command in batch mode and send the result to STDOUT.
  3042. If CMD-KEY is a string of length 1, it is used as a key in
  3043. `org-agenda-custom-commands' and triggers this command. If it is a
  3044. longer string it is used as a tags/todo match string.
  3045. Parameters are alternating variable names and values that will be bound
  3046. before running the agenda command."
  3047. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3048. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3049. (defun org--batch-agenda (cmd-key vars vals)
  3050. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3051. ;; a variable name rather than an expression to evaluate. Yuck!
  3052. (cl-progv vars vals
  3053. (let (org-agenda-sticky)
  3054. (if (> (length cmd-key) 1)
  3055. (org-tags-view nil cmd-key)
  3056. (org-agenda nil cmd-key))))
  3057. (set-buffer org-agenda-buffer-name)
  3058. (princ (buffer-string)))
  3059. (defvar org-agenda-info nil)
  3060. ;;;###autoload
  3061. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3062. "Run an agenda command in batch mode and send the result to STDOUT.
  3063. If CMD-KEY is a string of length 1, it is used as a key in
  3064. `org-agenda-custom-commands' and triggers this command. If it is a
  3065. longer string it is used as a tags/todo match string.
  3066. Parameters are alternating variable names and values that will be bound
  3067. before running the agenda command.
  3068. The output gives a line for each selected agenda item. Each
  3069. item is a list of comma-separated values, like this:
  3070. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3071. category The category of the item
  3072. head The headline, without TODO kwd, TAGS and PRIORITY
  3073. type The type of the agenda entry, can be
  3074. todo selected in TODO match
  3075. tagsmatch selected in tags match
  3076. diary imported from diary
  3077. deadline a deadline on given date
  3078. scheduled scheduled on given date
  3079. timestamp entry has timestamp on given date
  3080. closed entry was closed on given date
  3081. upcoming-deadline warning about deadline
  3082. past-scheduled forwarded scheduled item
  3083. block entry has date block including g. date
  3084. todo The todo keyword, if any
  3085. tags All tags including inherited ones, separated by colons
  3086. date The relevant date, like 2007-2-14
  3087. time The time, like 15:00-16:50
  3088. extra String with extra planning info
  3089. priority-l The priority letter if any was given
  3090. priority-n The computed numerical priority
  3091. agenda-day The day in the agenda where this is listed"
  3092. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3093. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3094. (defun org--batch-agenda-csv (cmd-key vars vals)
  3095. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3096. ;; a variable name rather than an expression to evaluate. Yuck!
  3097. (let ((org-agenda-remove-tags t))
  3098. (cl-progv vars vals
  3099. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3100. (if (> (length cmd-key) 2)
  3101. (org-tags-view nil cmd-key)
  3102. (org-agenda nil cmd-key))))
  3103. (set-buffer org-agenda-buffer-name)
  3104. (let ((lines (org-split-string (buffer-string) "\n")))
  3105. (dolist (line lines)
  3106. (when (get-text-property 0 'org-category line)
  3107. (setq org-agenda-info
  3108. (org-fix-agenda-info (text-properties-at 0 line)))
  3109. (princ
  3110. (mapconcat #'org-agenda-export-csv-mapper
  3111. '(org-category txt type todo tags date time extra
  3112. priority-letter priority agenda-day)
  3113. ","))
  3114. (princ "\n")))))
  3115. (defun org-fix-agenda-info (props)
  3116. "Make sure all properties on an agenda item have a canonical form.
  3117. This ensures the export commands can easily use it."
  3118. (let (tmp re)
  3119. (when (setq tmp (plist-get props 'tags))
  3120. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3121. (when (setq tmp (plist-get props 'date))
  3122. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3123. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3124. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3125. (setq tmp (calendar-date-string tmp)))
  3126. (setq props (plist-put props 'date tmp)))
  3127. (when (setq tmp (plist-get props 'day))
  3128. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3129. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3130. (setq tmp (calendar-date-string tmp)))
  3131. (setq props (plist-put props 'day tmp))
  3132. (setq props (plist-put props 'agenda-day tmp)))
  3133. (when (setq tmp (plist-get props 'txt))
  3134. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3135. (plist-put props 'priority-letter (match-string 1 tmp))
  3136. (setq tmp (replace-match "" t t tmp)))
  3137. (when (and (setq re (plist-get props 'org-todo-regexp))
  3138. (setq re (concat "\\`\\.*" re " ?"))
  3139. (let ((case-fold-search nil)) (string-match re tmp)))
  3140. (plist-put props 'todo (match-string 1 tmp))
  3141. (setq tmp (replace-match "" t t tmp)))
  3142. (plist-put props 'txt tmp)))
  3143. props)
  3144. (defun org-agenda-export-csv-mapper (prop)
  3145. (let ((res (plist-get org-agenda-info prop)))
  3146. (setq res
  3147. (cond
  3148. ((not res) "")
  3149. ((stringp res) res)
  3150. (t (prin1-to-string res))))
  3151. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3152. ;;;###autoload
  3153. (defun org-store-agenda-views (&rest _parameters)
  3154. "Store agenda views."
  3155. (interactive)
  3156. (org--batch-store-agenda-views nil nil))
  3157. ;;;###autoload
  3158. (defmacro org-batch-store-agenda-views (&rest parameters)
  3159. "Run all custom agenda commands that have a file argument."
  3160. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3161. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3162. (defun org--batch-store-agenda-views (vars vals)
  3163. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3164. (pop-up-frames nil)
  3165. (dir default-directory)
  3166. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3167. (save-window-excursion
  3168. (while cmds
  3169. (setq cmd (pop cmds)
  3170. thiscmdkey (car cmd)
  3171. thiscmdcmd (cdr cmd)
  3172. match (nth 2 thiscmdcmd)
  3173. bufname (if org-agenda-sticky
  3174. (or (and (stringp match)
  3175. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3176. (format "*Org Agenda(%s)*" thiscmdkey))
  3177. org-agenda-buffer-name)
  3178. cmd-or-set (nth 2 cmd)
  3179. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3180. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3181. (if (stringp files) (setq files (list files)))
  3182. (when files
  3183. (let* ((opts (append org-agenda-exporter-settings opts))
  3184. (vars (append (mapcar #'car opts) vars))
  3185. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3186. opts)
  3187. vals)))
  3188. (cl-progv vars vals
  3189. (org-agenda nil thiscmdkey))
  3190. (set-buffer bufname)
  3191. (while files
  3192. (cl-progv vars vals
  3193. (org-agenda-write (expand-file-name (pop files) dir)
  3194. nil t bufname))))
  3195. (and (get-buffer bufname)
  3196. (kill-buffer bufname)))))))
  3197. (defvar org-agenda-current-span nil
  3198. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3199. (defun org-agenda-mark-header-line (pos)
  3200. "Mark the line at POS as an agenda structure header."
  3201. (save-excursion
  3202. (goto-char pos)
  3203. (put-text-property (point-at-bol) (point-at-eol)
  3204. 'org-agenda-structural-header t)
  3205. (when org-agenda-title-append
  3206. (put-text-property (point-at-bol) (point-at-eol)
  3207. 'org-agenda-title-append org-agenda-title-append))))
  3208. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3209. (defvar org-agenda-write-buffer-name "Agenda View")
  3210. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3211. "Write the current buffer (an agenda view) as a file.
  3212. Depending on the extension of the file name, plain text (.txt),
  3213. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3214. If the extension is .ics, translate visible agenda into iCalendar
  3215. format. If the extension is .org, collect all subtrees
  3216. corresponding to the agenda entries and add them in an .org file.
  3217. With prefix argument OPEN, open the new file immediately. If
  3218. NOSETTINGS is given, do not scope the settings of
  3219. `org-agenda-exporter-settings' into the export commands. This is
  3220. used when the settings have already been scoped and we do not
  3221. wish to overrule other, higher priority settings. If
  3222. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3223. the agenda to write."
  3224. (interactive "FWrite agenda to file: \nP")
  3225. (if (or (not (file-writable-p file))
  3226. (and (file-exists-p file)
  3227. (if (called-interactively-p 'any)
  3228. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3229. (user-error "Cannot write agenda to file %s" file))
  3230. (cl-progv
  3231. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3232. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3233. org-agenda-exporter-settings))
  3234. (save-excursion
  3235. (save-window-excursion
  3236. (let ((bs (copy-sequence (buffer-string)))
  3237. (extension (file-name-extension file))
  3238. (default-directory (file-name-directory file))
  3239. ) ;; beg content
  3240. (with-temp-buffer
  3241. (rename-buffer org-agenda-write-buffer-name t)
  3242. (set-buffer-modified-p nil)
  3243. (insert bs)
  3244. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3245. (run-hooks 'org-agenda-before-write-hook)
  3246. (cond
  3247. ((bound-and-true-p org-mobile-creating-agendas)
  3248. (org-mobile-write-agenda-for-mobile file))
  3249. ((string= "org" extension)
  3250. (let (content p m message-log-max)
  3251. (goto-char (point-min))
  3252. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3253. (goto-char p)
  3254. (setq m (get-text-property (point) 'org-hd-marker))
  3255. (when m
  3256. (push (with-current-buffer (marker-buffer m)
  3257. (goto-char m)
  3258. (org-copy-subtree 1 nil t t)
  3259. org-subtree-clip)
  3260. content)))
  3261. (find-file file)
  3262. (erase-buffer)
  3263. (dolist (s content) (org-paste-subtree 1 s))
  3264. (write-file file)
  3265. (kill-buffer (current-buffer))
  3266. (message "Org file written to %s" file)))
  3267. ((member extension '("html" "htm"))
  3268. (or (require 'htmlize nil t)
  3269. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3270. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3271. (set-buffer (htmlize-buffer (current-buffer)))
  3272. (when org-agenda-export-html-style
  3273. ;; replace <style> section with org-agenda-export-html-style
  3274. (goto-char (point-min))
  3275. (kill-region (- (search-forward "<style") 6)
  3276. (search-forward "</style>"))
  3277. (insert org-agenda-export-html-style))
  3278. (write-file file)
  3279. (kill-buffer (current-buffer))
  3280. (message "HTML written to %s" file))
  3281. ((string= "ps" extension)
  3282. (require 'ps-print)
  3283. (ps-print-buffer-with-faces file)
  3284. (message "Postscript written to %s" file))
  3285. ((string= "pdf" extension)
  3286. (require 'ps-print)
  3287. (ps-print-buffer-with-faces
  3288. (concat (file-name-sans-extension file) ".ps"))
  3289. (call-process "ps2pdf" nil nil nil
  3290. (expand-file-name
  3291. (concat (file-name-sans-extension file) ".ps"))
  3292. (expand-file-name file))
  3293. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3294. (message "PDF written to %s" file))
  3295. ((string= "ics" extension)
  3296. (require 'ox-icalendar)
  3297. (declare-function org-icalendar-export-current-agenda
  3298. "ox-icalendar" (file))
  3299. (org-icalendar-export-current-agenda (expand-file-name file)))
  3300. (t
  3301. (let ((bs (buffer-string)))
  3302. (find-file file)
  3303. (erase-buffer)
  3304. (insert bs)
  3305. (save-buffer 0)
  3306. (kill-buffer (current-buffer))
  3307. (message "Plain text written to %s" file))))))))
  3308. (set-buffer (or agenda-bufname
  3309. ;; FIXME: I'm pretty sure called-interactively-p
  3310. ;; doesn't do what we want here!
  3311. (and (called-interactively-p 'any) (buffer-name))
  3312. org-agenda-buffer-name)))
  3313. (when open (org-open-file file)))
  3314. (defun org-agenda-remove-marked-text (property &optional value)
  3315. "Delete all text marked with VALUE of PROPERTY.
  3316. VALUE defaults to t."
  3317. (let (beg)
  3318. (setq value (or value t))
  3319. (while (setq beg (text-property-any (point-min) (point-max)
  3320. property value))
  3321. (delete-region
  3322. beg (or (next-single-property-change beg property)
  3323. (point-max))))))
  3324. (defun org-agenda-add-entry-text ()
  3325. "Add entry text to agenda lines.
  3326. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3327. entry text following headings shown in the agenda.
  3328. Drawers will be excluded, also the line with scheduling/deadline info."
  3329. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3330. (not (bound-and-true-p org-mobile-creating-agendas)))
  3331. (let (m txt)
  3332. (goto-char (point-min))
  3333. (while (not (eobp))
  3334. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3335. (beginning-of-line 2)
  3336. (setq txt (org-agenda-get-some-entry-text
  3337. m org-agenda-add-entry-text-maxlines " > "))
  3338. (end-of-line 1)
  3339. (if (string-match "\\S-" txt)
  3340. (insert "\n" txt)
  3341. (or (eobp) (forward-char 1))))))))
  3342. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3343. &rest keep)
  3344. "Extract entry text from MARKER, at most N-LINES lines.
  3345. This will ignore drawers etc, just get the text.
  3346. If INDENT is given, prefix every line with this string. If KEEP is
  3347. given, it is a list of symbols, defining stuff that should not be
  3348. removed from the entry content. Currently only `planning' is allowed here."
  3349. (let (txt drawer-re kwd-time-re ind)
  3350. (save-excursion
  3351. (with-current-buffer (marker-buffer marker)
  3352. (if (not (derived-mode-p 'org-mode))
  3353. (setq txt "")
  3354. (org-with-wide-buffer
  3355. (goto-char marker)
  3356. (end-of-line 1)
  3357. (setq txt (buffer-substring
  3358. (min (1+ (point)) (point-max))
  3359. (progn (outline-next-heading) (point)))
  3360. drawer-re org-drawer-regexp
  3361. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3362. ".*\n?"))
  3363. (with-temp-buffer
  3364. (insert txt)
  3365. (when org-agenda-add-entry-text-descriptive-links
  3366. (goto-char (point-min))
  3367. (while (org-activate-links (point-max))
  3368. (goto-char (match-end 0))))
  3369. (goto-char (point-min))
  3370. (while (re-search-forward org-link-bracket-re (point-max) t)
  3371. (set-text-properties (match-beginning 0) (match-end 0)
  3372. nil))
  3373. (goto-char (point-min))
  3374. (while (re-search-forward drawer-re nil t)
  3375. (delete-region
  3376. (match-beginning 0)
  3377. (progn (re-search-forward
  3378. "^[ \t]*:END:.*\n?" nil 'move)
  3379. (point))))
  3380. (unless (member 'planning keep)
  3381. (goto-char (point-min))
  3382. (while (re-search-forward kwd-time-re nil t)
  3383. (replace-match "")))
  3384. (goto-char (point-min))
  3385. (when org-agenda-entry-text-exclude-regexps
  3386. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3387. (while (setq re (pop re-list))
  3388. (goto-char (point-min))
  3389. (while (re-search-forward re nil t)
  3390. (replace-match "")))))
  3391. (goto-char (point-max))
  3392. (skip-chars-backward " \t\n")
  3393. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3394. ;; find and remove min common indentation
  3395. (goto-char (point-min))
  3396. (untabify (point-min) (point-max))
  3397. (setq ind (current-indentation))
  3398. (while (not (eobp))
  3399. (unless (looking-at "[ \t]*$")
  3400. (setq ind (min ind (current-indentation))))
  3401. (beginning-of-line 2))
  3402. (goto-char (point-min))
  3403. (while (not (eobp))
  3404. (unless (looking-at "[ \t]*$")
  3405. (move-to-column ind)
  3406. (delete-region (point-at-bol) (point)))
  3407. (beginning-of-line 2))
  3408. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3409. (goto-char (point-min))
  3410. (when indent
  3411. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3412. (replace-match indent t t)))
  3413. (goto-char (point-min))
  3414. (while (looking-at "[ \t]*\n") (replace-match ""))
  3415. (goto-char (point-max))
  3416. (when (> (org-current-line)
  3417. n-lines)
  3418. (org-goto-line (1+ n-lines))
  3419. (backward-char 1))
  3420. (setq txt (buffer-substring (point-min) (point))))))))
  3421. txt))
  3422. (defun org-check-for-org-mode ()
  3423. "Make sure current buffer is in Org mode. Error if not."
  3424. (or (derived-mode-p 'org-mode)
  3425. (error "Cannot execute Org agenda command on buffer in %s"
  3426. major-mode)))
  3427. ;;; Agenda prepare and finalize
  3428. (defvar org-agenda-multi nil) ; dynamically scoped
  3429. (defvar org-agenda-pre-window-conf nil)
  3430. (defvar org-agenda-columns-active nil)
  3431. (defvar org-agenda-name nil)
  3432. (defvar org-agenda-tag-filter nil)
  3433. (defvar org-agenda-category-filter nil)
  3434. (defvar org-agenda-regexp-filter nil)
  3435. (defvar org-agenda-effort-filter nil)
  3436. (defvar org-agenda-top-headline-filter nil)
  3437. (defvar org-agenda-represented-categories nil
  3438. "Cache for the list of all categories in the agenda.")
  3439. (defvar org-agenda-represented-tags nil
  3440. "Cache for the list of all categories in the agenda.")
  3441. (defvar org-agenda-tag-filter-preset nil
  3442. "A preset of the tags filter used for secondary agenda filtering.
  3443. This must be a list of strings, each string must be a single tag preceded
  3444. by \"+\" or \"-\".
  3445. This variable should not be set directly, but agenda custom commands can
  3446. bind it in the options section. The preset filter is a global property of
  3447. the entire agenda view. In a block agenda, it will not work reliably to
  3448. define a filter for one of the individual blocks. You need to set it in
  3449. the global options and expect it to be applied to the entire view.")
  3450. (defconst org-agenda-filter-variables
  3451. '((category . org-agenda-category-filter)
  3452. (tag . org-agenda-tag-filter)
  3453. (effort . org-agenda-effort-filter)
  3454. (regexp . org-agenda-regexp-filter))
  3455. "Alist of filter types and associated variables.")
  3456. (defun org-agenda-filter-any ()
  3457. "Is any filter active?"
  3458. (cl-some (lambda (x)
  3459. (or (symbol-value (cdr x))
  3460. (get :preset-filter x)))
  3461. org-agenda-filter-variables))
  3462. (defvar org-agenda-category-filter-preset nil
  3463. "A preset of the category filter used for secondary agenda filtering.
  3464. This must be a list of strings, each string must be a single category
  3465. preceded by \"+\" or \"-\".
  3466. This variable should not be set directly, but agenda custom commands can
  3467. bind it in the options section. The preset filter is a global property of
  3468. the entire agenda view. In a block agenda, it will not work reliably to
  3469. define a filter for one of the individual blocks. You need to set it in
  3470. the global options and expect it to be applied to the entire view.")
  3471. (defvar org-agenda-regexp-filter-preset nil
  3472. "A preset of the regexp filter used for secondary agenda filtering.
  3473. This must be a list of strings, each string must be a single regexp
  3474. preceded by \"+\" or \"-\".
  3475. This variable should not be set directly, but agenda custom commands can
  3476. bind it in the options section. The preset filter is a global property of
  3477. the entire agenda view. In a block agenda, it will not work reliably to
  3478. define a filter for one of the individual blocks. You need to set it in
  3479. the global options and expect it to be applied to the entire view.")
  3480. (defvar org-agenda-effort-filter-preset nil
  3481. "A preset of the effort condition used for secondary agenda filtering.
  3482. This must be a list of strings, each string must be a single regexp
  3483. preceded by \"+\" or \"-\".
  3484. This variable should not be set directly, but agenda custom commands can
  3485. bind it in the options section. The preset filter is a global property of
  3486. the entire agenda view. In a block agenda, it will not work reliably to
  3487. define a filter for one of the individual blocks. You need to set it in
  3488. the global options and expect it to be applied to the entire view.")
  3489. (defun org-agenda-use-sticky-p ()
  3490. "Return non-nil if an agenda buffer named
  3491. `org-agenda-buffer-name' exists and should be shown instead of
  3492. generating a new one."
  3493. (and
  3494. ;; turned off by user
  3495. org-agenda-sticky
  3496. ;; For multi-agenda buffer already exists
  3497. (not org-agenda-multi)
  3498. ;; buffer found
  3499. (get-buffer org-agenda-buffer-name)
  3500. ;; C-u parameter is same as last call
  3501. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3502. (and
  3503. (equal current-prefix-arg
  3504. org-agenda-last-prefix-arg)
  3505. ;; In case user turned stickiness on, while having existing
  3506. ;; Agenda buffer active, don't reuse that buffer, because it
  3507. ;; does not have org variables local
  3508. org-agenda-this-buffer-is-sticky))))
  3509. (defvar org-agenda-buffer-tmp-name nil)
  3510. (defun org-agenda--get-buffer-name (sticky-name)
  3511. (or org-agenda-buffer-tmp-name
  3512. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3513. sticky-name
  3514. "*Org Agenda*"))
  3515. (defun org-agenda-prepare-window (abuf filter-alist)
  3516. "Setup agenda buffer in the window.
  3517. ABUF is the buffer for the agenda window.
  3518. FILTER-ALIST is an alist of filters we need to apply when
  3519. `org-agenda-persistent-filter' is non-nil."
  3520. (let* ((awin (get-buffer-window abuf)) wconf)
  3521. (cond
  3522. ((equal (current-buffer) abuf) nil)
  3523. (awin (select-window awin))
  3524. ((not (setq wconf (current-window-configuration))))
  3525. ((eq org-agenda-window-setup 'current-window)
  3526. (pop-to-buffer-same-window abuf))
  3527. ((eq org-agenda-window-setup 'other-window)
  3528. (org-switch-to-buffer-other-window abuf))
  3529. ((eq org-agenda-window-setup 'other-frame)
  3530. (switch-to-buffer-other-frame abuf))
  3531. ((eq org-agenda-window-setup 'other-tab)
  3532. (if (fboundp 'switch-to-buffer-other-tab)
  3533. (switch-to-buffer-other-tab abuf)
  3534. (user-error "Your version of Emacs does not have tab bar support")))
  3535. ((eq org-agenda-window-setup 'only-window)
  3536. (delete-other-windows)
  3537. (pop-to-buffer-same-window abuf))
  3538. ((eq org-agenda-window-setup 'reorganize-frame)
  3539. (delete-other-windows)
  3540. (org-switch-to-buffer-other-window abuf)))
  3541. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3542. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3543. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3544. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3545. ;; Additional test in case agenda is invoked from within agenda
  3546. ;; buffer via elisp link.
  3547. (unless (equal (current-buffer) abuf)
  3548. (pop-to-buffer-same-window abuf))
  3549. (setq org-agenda-pre-window-conf
  3550. (or wconf org-agenda-pre-window-conf))))
  3551. (defun org-agenda-prepare (&optional name)
  3552. (let ((filter-alist (when org-agenda-persistent-filter
  3553. (with-current-buffer
  3554. (get-buffer-create org-agenda-buffer-name)
  3555. `((tag . ,org-agenda-tag-filter)
  3556. (re . ,org-agenda-regexp-filter)
  3557. (effort . ,org-agenda-effort-filter)
  3558. (cat . ,org-agenda-category-filter))))))
  3559. (if (org-agenda-use-sticky-p)
  3560. (progn
  3561. (put 'org-agenda-tag-filter :preset-filter nil)
  3562. (put 'org-agenda-category-filter :preset-filter nil)
  3563. (put 'org-agenda-regexp-filter :preset-filter nil)
  3564. (put 'org-agenda-effort-filter :preset-filter nil)
  3565. ;; Popup existing buffer
  3566. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3567. filter-alist)
  3568. (message "Sticky Agenda buffer, use `r' to refresh")
  3569. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3570. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3571. (setq org-todo-keywords-for-agenda nil)
  3572. (put 'org-agenda-tag-filter :preset-filter
  3573. org-agenda-tag-filter-preset)
  3574. (put 'org-agenda-category-filter :preset-filter
  3575. org-agenda-category-filter-preset)
  3576. (put 'org-agenda-regexp-filter :preset-filter
  3577. org-agenda-regexp-filter-preset)
  3578. (put 'org-agenda-effort-filter :preset-filter
  3579. org-agenda-effort-filter-preset)
  3580. (if org-agenda-multi
  3581. (progn
  3582. (setq buffer-read-only nil)
  3583. (goto-char (point-max))
  3584. (unless (or (bobp) org-agenda-compact-blocks
  3585. (not org-agenda-block-separator))
  3586. (insert "\n"
  3587. (if (stringp org-agenda-block-separator)
  3588. org-agenda-block-separator
  3589. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3590. "\n"))
  3591. (narrow-to-region (point) (point-max)))
  3592. (setq org-done-keywords-for-agenda nil)
  3593. ;; Setting any org variables that are in org-agenda-local-vars
  3594. ;; list need to be done after the prepare call
  3595. (org-agenda-prepare-window
  3596. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3597. (setq buffer-read-only nil)
  3598. (org-agenda-reset-markers)
  3599. (let ((inhibit-read-only t)) (erase-buffer))
  3600. (org-agenda-mode)
  3601. (setq org-agenda-buffer (current-buffer))
  3602. (setq org-agenda-contributing-files nil)
  3603. (setq org-agenda-columns-active nil)
  3604. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3605. (setq org-todo-keywords-for-agenda
  3606. (org-uniquify org-todo-keywords-for-agenda))
  3607. (setq org-done-keywords-for-agenda
  3608. (org-uniquify org-done-keywords-for-agenda))
  3609. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3610. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3611. (and name (not org-agenda-name)
  3612. (setq-local org-agenda-name name)))
  3613. (setq buffer-read-only nil))))
  3614. (defvar org-overriding-columns-format)
  3615. (defvar org-local-columns-format)
  3616. (defun org-agenda-finalize ()
  3617. "Finishing touch for the agenda buffer.
  3618. This function is called just before displaying the agenda. If
  3619. you want to add your own functions to the finalization of the
  3620. agenda display, configure `org-agenda-finalize-hook'."
  3621. (unless org-agenda-multi
  3622. (let ((inhibit-read-only t))
  3623. (save-excursion
  3624. (goto-char (point-min))
  3625. (save-excursion
  3626. (while (org-activate-links (point-max))
  3627. (goto-char (match-end 0))))
  3628. (unless (eq org-agenda-remove-tags t)
  3629. (org-agenda-align-tags))
  3630. (unless org-agenda-with-colors
  3631. (remove-text-properties (point-min) (point-max) '(face nil)))
  3632. (when (bound-and-true-p org-overriding-columns-format)
  3633. (setq-local org-local-columns-format
  3634. org-overriding-columns-format))
  3635. (when org-agenda-view-columns-initially
  3636. (org-agenda-columns))
  3637. (when org-agenda-fontify-priorities
  3638. (org-agenda-fontify-priorities))
  3639. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3640. (org-agenda-dim-blocked-tasks))
  3641. (org-agenda-mark-clocking-task)
  3642. (when org-agenda-entry-text-mode
  3643. (org-agenda-entry-text-hide)
  3644. (org-agenda-entry-text-show))
  3645. (when (and (featurep 'org-habit)
  3646. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3647. (org-habit-insert-consistency-graphs))
  3648. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3649. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3650. (and (listp org-agenda-show-inherited-tags)
  3651. (memq org-agenda-type org-agenda-show-inherited-tags))
  3652. (and (eq org-agenda-show-inherited-tags t)
  3653. (or (eq org-agenda-use-tag-inheritance t)
  3654. (and (listp org-agenda-use-tag-inheritance)
  3655. (not (memq org-agenda-type
  3656. org-agenda-use-tag-inheritance))))))
  3657. (let (mrk)
  3658. (save-excursion
  3659. (goto-char (point-min))
  3660. (while (equal (forward-line) 0)
  3661. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3662. (put-text-property (point-at-bol) (point-at-eol)
  3663. 'tags
  3664. (org-with-point-at mrk
  3665. (org-get-tags))))))))
  3666. (setq org-agenda-represented-tags nil
  3667. org-agenda-represented-categories nil)
  3668. (when org-agenda-top-headline-filter
  3669. (org-agenda-filter-top-headline-apply
  3670. org-agenda-top-headline-filter))
  3671. (when org-agenda-tag-filter
  3672. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3673. (when (get 'org-agenda-tag-filter :preset-filter)
  3674. (org-agenda-filter-apply
  3675. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3676. (when org-agenda-category-filter
  3677. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3678. (when (get 'org-agenda-category-filter :preset-filter)
  3679. (org-agenda-filter-apply
  3680. (get 'org-agenda-category-filter :preset-filter) 'category))
  3681. (when org-agenda-regexp-filter
  3682. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3683. (when (get 'org-agenda-regexp-filter :preset-filter)
  3684. (org-agenda-filter-apply
  3685. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3686. (when org-agenda-effort-filter
  3687. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3688. (when (get 'org-agenda-effort-filter :preset-filter)
  3689. (org-agenda-filter-apply
  3690. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3691. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3692. (run-hooks 'org-agenda-finalize-hook))))
  3693. (defun org-agenda-mark-clocking-task ()
  3694. "Mark the current clock entry in the agenda if it is present."
  3695. ;; We need to widen when `org-agenda-finalize' is called from
  3696. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3697. (when (bound-and-true-p org-clock-current-task)
  3698. (save-restriction
  3699. (widen)
  3700. (org-agenda-unmark-clocking-task)
  3701. (when (marker-buffer org-clock-hd-marker)
  3702. (save-excursion
  3703. (goto-char (point-min))
  3704. (let (s ov)
  3705. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3706. (goto-char s)
  3707. (when (equal (org-get-at-bol 'org-hd-marker)
  3708. org-clock-hd-marker)
  3709. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3710. (overlay-put ov 'type 'org-agenda-clocking)
  3711. (overlay-put ov 'face 'org-agenda-clocking)
  3712. (overlay-put ov 'help-echo
  3713. "The clock is running in this item")))))))))
  3714. (defun org-agenda-unmark-clocking-task ()
  3715. "Unmark the current clocking task."
  3716. (mapc (lambda (o)
  3717. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3718. (delete-overlay o)))
  3719. (overlays-in (point-min) (point-max))))
  3720. (defun org-agenda-fontify-priorities ()
  3721. "Make highest priority lines bold, and lowest italic."
  3722. (interactive)
  3723. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3724. (delete-overlay o)))
  3725. (overlays-in (point-min) (point-max)))
  3726. (save-excursion
  3727. (let (b e p ov h l)
  3728. (goto-char (point-min))
  3729. (while (re-search-forward org-priority-regexp nil t)
  3730. (setq h (or (get-char-property (point) 'org-priority-highest)
  3731. org-priority-highest)
  3732. l (or (get-char-property (point) 'org-priority-lowest)
  3733. org-priority-lowest)
  3734. p (string-to-char (match-string 2))
  3735. b (match-beginning 1)
  3736. e (if (eq org-agenda-fontify-priorities 'cookies)
  3737. (1+ (match-end 2))
  3738. (point-at-eol))
  3739. ov (make-overlay b e))
  3740. (overlay-put
  3741. ov 'face
  3742. (let ((special-face
  3743. (cond ((org-face-from-face-or-color
  3744. 'priority 'org-priority
  3745. (cdr (assoc p org-priority-faces))))
  3746. ((and (listp org-agenda-fontify-priorities)
  3747. (org-face-from-face-or-color
  3748. 'priority 'org-priority
  3749. (cdr (assoc p org-agenda-fontify-priorities)))))
  3750. ((equal p l) 'italic)
  3751. ((equal p h) 'bold))))
  3752. (if special-face (list special-face 'org-priority) 'org-priority)))
  3753. (overlay-put ov 'org-type 'org-priority)))))
  3754. (defvar org-depend-tag-blocked)
  3755. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3756. "Dim currently blocked TODOs in the agenda display.
  3757. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3758. dimming them." ;FIXME: The arg isn't used, actually!
  3759. (interactive "P")
  3760. (when (called-interactively-p 'interactive)
  3761. (message "Dim or hide blocked tasks..."))
  3762. (dolist (o (overlays-in (point-min) (point-max)))
  3763. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3764. (delete-overlay o)))
  3765. (save-excursion
  3766. (let ((inhibit-read-only t))
  3767. (goto-char (point-min))
  3768. (while (let ((pos (text-property-not-all
  3769. (point) (point-max) 'org-todo-blocked nil)))
  3770. (when pos (goto-char pos)))
  3771. (let* ((invisible
  3772. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3773. (todo-blocked
  3774. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3775. (ov (make-overlay (if invisible
  3776. (line-end-position 0)
  3777. (line-beginning-position))
  3778. (line-end-position))))
  3779. (when todo-blocked
  3780. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3781. (when invisible
  3782. (org-agenda-filter-hide-line 'todo-blocked)))
  3783. (if (= (point-max) (line-end-position))
  3784. (goto-char (point-max))
  3785. (move-beginning-of-line 2)))))
  3786. (when (called-interactively-p 'interactive)
  3787. (message "Dim or hide blocked tasks...done")))
  3788. (defun org-agenda--mark-blocked-entry (entry)
  3789. "If ENTRY is blocked, mark it for fontification or invisibility.
  3790. If the header at `org-hd-marker' is blocked according to
  3791. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3792. `invisible' and the header is not blocked by checkboxes, set the
  3793. text property `org-todo-blocked' to `invisible', otherwise set it
  3794. to t."
  3795. (when (get-text-property 0 'todo-state entry)
  3796. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3797. (org-blocked-by-checkboxes nil)
  3798. ;; Necessary so that `org-entry-blocked-p' does not change
  3799. ;; the buffer.
  3800. (org-depend-tag-blocked nil))
  3801. (when entry-marker
  3802. (let ((blocked
  3803. (with-current-buffer (marker-buffer entry-marker)
  3804. (save-excursion
  3805. (goto-char entry-marker)
  3806. (org-entry-blocked-p)))))
  3807. (when blocked
  3808. (let ((really-invisible
  3809. (and (not org-blocked-by-checkboxes)
  3810. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3811. (put-text-property
  3812. 0 (length entry) 'org-todo-blocked
  3813. (if really-invisible 'invisible t)
  3814. entry)
  3815. (put-text-property
  3816. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3817. entry)
  3818. (defvar org-agenda-skip-function nil
  3819. "Function to be called at each match during agenda construction.
  3820. If this function returns nil, the current match should not be skipped.
  3821. Otherwise, the function must return a position from where the search
  3822. should be continued.
  3823. This may also be a Lisp form, it will be evaluated.
  3824. Never set this variable using `setq' or so, because then it will apply
  3825. to all future agenda commands. If you do want a global skipping condition,
  3826. use the option `org-agenda-skip-function-global' instead.
  3827. The correct usage for `org-agenda-skip-function' is to bind it with
  3828. `let' to scope it dynamically into the agenda-constructing command.
  3829. A good way to set it is through options in `org-agenda-custom-commands'.")
  3830. (defun org-agenda-skip (&optional element)
  3831. "Throw to `:skip' in places that should be skipped.
  3832. Also moves point to the end of the skipped region, so that search can
  3833. continue from there.
  3834. Optional argument ELEMENT contains element at point."
  3835. (let ((p (point-at-bol)) to)
  3836. (when (or
  3837. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3838. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3839. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3840. (org-end-of-subtree t element))
  3841. (and (member org-archive-tag org-file-tags)
  3842. (goto-char (point-max)))))
  3843. (and org-agenda-skip-comment-trees
  3844. (org-in-commented-heading-p nil element)
  3845. (org-end-of-subtree t element))
  3846. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3847. (org-agenda-skip-eval org-agenda-skip-function)))
  3848. (goto-char to))
  3849. (org-in-src-block-p t))
  3850. (throw :skip t))))
  3851. (defun org-agenda-skip-eval (form)
  3852. "If FORM is a function or a list, call (or eval) it and return the result.
  3853. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3854. and match data are returned to the previous state no matter what these
  3855. functions do."
  3856. (let (fp)
  3857. (and form
  3858. (or (setq fp (functionp form))
  3859. (consp form))
  3860. (save-excursion
  3861. (save-match-data
  3862. (if fp
  3863. (funcall form)
  3864. (eval form t)))))))
  3865. (defvar org-agenda-markers nil
  3866. "List of all currently active markers created by `org-agenda'.")
  3867. (defvar org-agenda-last-marker-time (float-time)
  3868. "Creation time of the last agenda marker.")
  3869. (defun org-agenda-new-marker (&optional pos)
  3870. "Return a new agenda marker.
  3871. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3872. of these markers and resets them when they are no longer in use."
  3873. (let ((m (copy-marker (or pos (point)) t)))
  3874. (setq org-agenda-last-marker-time (float-time))
  3875. (if org-agenda-buffer
  3876. (with-current-buffer org-agenda-buffer
  3877. (push m org-agenda-markers))
  3878. (push m org-agenda-markers))
  3879. m))
  3880. (defun org-agenda-reset-markers ()
  3881. "Reset markers created by `org-agenda'."
  3882. (while org-agenda-markers
  3883. (move-marker (pop org-agenda-markers) nil)))
  3884. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3885. "Save relative positions of markers in region.
  3886. This check for agenda markers in all agenda buffers currently active."
  3887. (dolist (buf (buffer-list))
  3888. (with-current-buffer buf
  3889. (when (eq major-mode 'org-agenda-mode)
  3890. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3891. org-agenda-markers)))))
  3892. ;;; Entry text mode
  3893. (defun org-agenda-entry-text-show-here ()
  3894. "Add some text from the entry as context to the current line."
  3895. (let (m txt o)
  3896. (setq m (org-get-at-bol 'org-hd-marker))
  3897. (unless (marker-buffer m)
  3898. (error "No marker points to an entry here"))
  3899. (setq txt (concat "\n" (org-no-properties
  3900. (org-agenda-get-some-entry-text
  3901. m org-agenda-entry-text-maxlines
  3902. org-agenda-entry-text-leaders))))
  3903. (when (string-match "\\S-" txt)
  3904. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3905. (overlay-put o 'evaporate t)
  3906. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3907. (overlay-put o 'after-string txt))))
  3908. (defun org-agenda-entry-text-show ()
  3909. "Add entry context for all agenda lines."
  3910. (interactive)
  3911. (save-excursion
  3912. (goto-char (point-max))
  3913. (beginning-of-line 1)
  3914. (while (not (bobp))
  3915. (when (org-get-at-bol 'org-hd-marker)
  3916. (org-agenda-entry-text-show-here))
  3917. (beginning-of-line 0))))
  3918. (defun org-agenda-entry-text-hide ()
  3919. "Remove any shown entry context."
  3920. (mapc (lambda (o)
  3921. (when (eq (overlay-get o 'org-overlay-type)
  3922. 'agenda-entry-content)
  3923. (delete-overlay o)))
  3924. (overlays-in (point-min) (point-max))))
  3925. (defun org-agenda-get-day-face (date)
  3926. "Return the face DATE should be displayed with."
  3927. (cond ((and (functionp org-agenda-day-face-function)
  3928. (funcall org-agenda-day-face-function date)))
  3929. ((and (org-agenda-today-p date)
  3930. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3931. 'org-agenda-date-weekend-today)
  3932. ((org-agenda-today-p date) 'org-agenda-date-today)
  3933. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3934. 'org-agenda-date-weekend)
  3935. (t 'org-agenda-date)))
  3936. (defvar org-agenda-show-log-scoped)
  3937. ;;; Agenda Daily/Weekly
  3938. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3939. "Start day for the agenda view.
  3940. Custom commands can set this variable in the options section.
  3941. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3942. input allowed when reading a date through the Org calendar.
  3943. See the docstring of `org-read-date' for details.")
  3944. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3945. (defvar org-arg-loc nil) ; local variable
  3946. ;;;###autoload
  3947. (defun org-agenda-list (&optional arg start-day span with-hour)
  3948. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3949. The view will be for the current day or week, but from the overview buffer
  3950. you will be able to go to other days/weeks.
  3951. With a numeric prefix argument in an interactive call, the agenda will
  3952. span ARG days. Lisp programs should instead specify SPAN to change
  3953. the number of days. SPAN defaults to `org-agenda-span'.
  3954. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3955. given in `org-agenda-start-on-weekday'.
  3956. When WITH-HOUR is non-nil, only include scheduled and deadline
  3957. items if they have an hour specification like [h]h:mm."
  3958. (interactive "P")
  3959. (when org-agenda-overriding-arguments
  3960. (setq arg (car org-agenda-overriding-arguments)
  3961. start-day (nth 1 org-agenda-overriding-arguments)
  3962. span (nth 2 org-agenda-overriding-arguments)))
  3963. (when (and (integerp arg) (> arg 0))
  3964. (setq span arg arg nil))
  3965. (when (numberp span)
  3966. (unless (< 0 span)
  3967. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3968. (catch 'exit
  3969. (setq org-agenda-buffer-name
  3970. (org-agenda--get-buffer-name
  3971. (and org-agenda-sticky
  3972. (cond ((and org-keys (stringp org-match))
  3973. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3974. (org-keys
  3975. (format "*Org Agenda(%s)*" org-keys))
  3976. (t "*Org Agenda(a)*")))))
  3977. (org-agenda-prepare "Day/Week")
  3978. (setq start-day (or start-day org-agenda-start-day))
  3979. (when (stringp start-day)
  3980. ;; Convert to an absolute day number
  3981. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3982. (org-compile-prefix-format 'agenda)
  3983. (org-set-sorting-strategy 'agenda)
  3984. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3985. (today (org-today))
  3986. (sd (or start-day today))
  3987. (ndays (org-agenda-span-to-ndays span sd))
  3988. (org-agenda-start-on-weekday
  3989. (and (or (eq ndays 7) (eq ndays 14))
  3990. org-agenda-start-on-weekday))
  3991. (thefiles (org-agenda-files nil 'ifmode))
  3992. (files thefiles)
  3993. (start (if (or (null org-agenda-start-on-weekday)
  3994. (< ndays 7))
  3995. sd
  3996. (let* ((nt (calendar-day-of-week
  3997. (calendar-gregorian-from-absolute sd)))
  3998. (n1 org-agenda-start-on-weekday)
  3999. (d (- nt n1)))
  4000. (- sd (+ (if (< d 0) 7 0) d)))))
  4001. (day-numbers (list start))
  4002. (day-cnt 0)
  4003. (inhibit-redisplay (not debug-on-error))
  4004. (org-agenda-show-log-scoped org-agenda-show-log)
  4005. s rtn rtnall file date d start-pos end-pos todayp ;; e
  4006. clocktable-start clocktable-end) ;; filter
  4007. (setq org-agenda-redo-command
  4008. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  4009. (dotimes (_ (1- ndays))
  4010. (push (1+ (car day-numbers)) day-numbers))
  4011. (setq day-numbers (nreverse day-numbers))
  4012. (setq clocktable-start (car day-numbers)
  4013. clocktable-end (1+ (or (org-last day-numbers) 0)))
  4014. (setq-local org-starting-day (car day-numbers))
  4015. (setq-local org-arg-loc arg)
  4016. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  4017. (unless org-agenda-compact-blocks
  4018. (let* ((d1 (car day-numbers))
  4019. (d2 (org-last day-numbers))
  4020. (w1 (org-days-to-iso-week d1))
  4021. (w2 (org-days-to-iso-week d2)))
  4022. (setq s (point))
  4023. (org-agenda--insert-overriding-header
  4024. (concat (org-agenda-span-name span)
  4025. "-agenda"
  4026. (cond ((<= 350 (- d2 d1)) "")
  4027. ((= w1 w2) (format " (W%02d)" w1))
  4028. (t (format " (W%02d-W%02d)" w1 w2)))
  4029. ":\n")))
  4030. ;; Add properties if we actually inserted a header.
  4031. (when (> (point) s)
  4032. (add-text-properties s (1- (point))
  4033. (list 'face 'org-agenda-structure
  4034. 'org-date-line t))
  4035. (org-agenda-mark-header-line s)))
  4036. (while (setq d (pop day-numbers))
  4037. (setq date (calendar-gregorian-from-absolute d)
  4038. s (point))
  4039. (if (or (setq todayp (= d today))
  4040. (and (not start-pos) (= d sd)))
  4041. (setq start-pos (point))
  4042. (when (and start-pos (not end-pos))
  4043. (setq end-pos (point))))
  4044. (setq files thefiles
  4045. rtnall nil)
  4046. (while (setq file (pop files))
  4047. (catch 'nextfile
  4048. (org-check-agenda-file file)
  4049. (let ((org-agenda-entry-types org-agenda-entry-types))
  4050. ;; Starred types override non-starred equivalents
  4051. (when (member :deadline* org-agenda-entry-types)
  4052. (setq org-agenda-entry-types
  4053. (delq :deadline org-agenda-entry-types)))
  4054. (when (member :scheduled* org-agenda-entry-types)
  4055. (setq org-agenda-entry-types
  4056. (delq :scheduled org-agenda-entry-types)))
  4057. ;; Honor with-hour
  4058. (when with-hour
  4059. (when (member :deadline org-agenda-entry-types)
  4060. (setq org-agenda-entry-types
  4061. (delq :deadline org-agenda-entry-types))
  4062. (push :deadline* org-agenda-entry-types))
  4063. (when (member :scheduled org-agenda-entry-types)
  4064. (setq org-agenda-entry-types
  4065. (delq :scheduled org-agenda-entry-types))
  4066. (push :scheduled* org-agenda-entry-types)))
  4067. (unless org-agenda-include-deadlines
  4068. (setq org-agenda-entry-types
  4069. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4070. (cond
  4071. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4072. (setq rtn (org-agenda-get-day-entries
  4073. file date :closed)))
  4074. (org-agenda-show-log-scoped
  4075. (setq rtn (apply #'org-agenda-get-day-entries
  4076. file date
  4077. (append '(:closed) org-agenda-entry-types))))
  4078. (t
  4079. (setq rtn (apply #'org-agenda-get-day-entries
  4080. file date
  4081. org-agenda-entry-types)))))
  4082. (setq rtnall (append rtnall rtn)))) ;; all entries
  4083. (when org-agenda-include-diary
  4084. (let ((org-agenda-search-headline-for-time t))
  4085. (require 'diary-lib)
  4086. (setq rtn (org-get-entries-from-diary date))
  4087. (setq rtnall (append rtnall rtn))))
  4088. (when (or rtnall org-agenda-show-all-dates)
  4089. (setq day-cnt (1+ day-cnt))
  4090. (insert
  4091. (if (stringp org-agenda-format-date)
  4092. (format-time-string org-agenda-format-date
  4093. (org-time-from-absolute date))
  4094. (funcall org-agenda-format-date date))
  4095. "\n")
  4096. (put-text-property s (1- (point)) 'face
  4097. (org-agenda-get-day-face date))
  4098. (put-text-property s (1- (point)) 'org-date-line t)
  4099. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4100. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4101. (when todayp
  4102. (put-text-property s (1- (point)) 'org-today t))
  4103. (setq rtnall
  4104. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4105. (when rtnall (insert ;; all entries
  4106. (org-agenda-finalize-entries rtnall 'agenda)
  4107. "\n"))
  4108. (put-text-property s (1- (point)) 'day d)
  4109. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4110. (when (and org-agenda-clockreport-mode clocktable-start)
  4111. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4112. ;; the above line is to ensure the restricted range!
  4113. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4114. tbl)
  4115. (setq p (org-plist-delete p :block))
  4116. (setq p (plist-put p :tstart clocktable-start))
  4117. (setq p (plist-put p :tend clocktable-end))
  4118. (setq p (plist-put p :scope 'agenda))
  4119. (setq tbl (apply #'org-clock-get-clocktable p))
  4120. (when org-agenda-clock-report-header
  4121. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure))
  4122. (unless (string-suffix-p "\n" org-agenda-clock-report-header)
  4123. (insert "\n")))
  4124. (insert tbl)))
  4125. (goto-char (point-min))
  4126. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4127. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4128. (and (pos-visible-in-window-p (point-min))
  4129. (pos-visible-in-window-p (point-max))))
  4130. (goto-char (1- (point-max)))
  4131. (recenter -1)
  4132. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4133. (goto-char (or start-pos 1))
  4134. (recenter 1)))
  4135. (goto-char (or start-pos 1))
  4136. (add-text-properties (point-min) (point-max)
  4137. `(org-agenda-type agenda
  4138. org-last-args (,arg ,start-day ,span)
  4139. org-redo-cmd ,org-agenda-redo-command
  4140. org-series-cmd ,org-cmd))
  4141. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4142. (org-agenda-show-clocking-issues))
  4143. (org-agenda-finalize)
  4144. (setq buffer-read-only t)
  4145. (message ""))))
  4146. (defun org-agenda-ndays-to-span (n)
  4147. "Return a span symbol for a span of N days, or N if none matches."
  4148. (cond ((symbolp n) n)
  4149. ((= n 1) 'day)
  4150. ((= n 7) 'week)
  4151. ((= n 14) 'fortnight)
  4152. (t n)))
  4153. (defun org-agenda-span-to-ndays (span &optional start-day)
  4154. "Return ndays from SPAN, possibly starting at START-DAY.
  4155. START-DAY is an absolute time value."
  4156. (cond ((numberp span) span)
  4157. ((eq span 'day) 1)
  4158. ((eq span 'week) 7)
  4159. ((eq span 'fortnight) 14)
  4160. ((eq span 'month)
  4161. (let ((date (calendar-gregorian-from-absolute start-day)))
  4162. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4163. ((eq span 'year)
  4164. (let ((date (calendar-gregorian-from-absolute start-day)))
  4165. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4166. (defun org-agenda-span-name (span)
  4167. "Return a SPAN name."
  4168. (if (null span)
  4169. ""
  4170. (if (symbolp span)
  4171. (capitalize (symbol-name span))
  4172. (format "%d days" span))))
  4173. ;;; Agenda word search
  4174. (defvar org-agenda-search-history nil)
  4175. (defvar org-search-syntax-table nil
  4176. "Special syntax table for Org search.
  4177. In this table, we have single quotes not as word constituents, to
  4178. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4179. (defvar org-mode-syntax-table) ; From org.el
  4180. (defun org-search-syntax-table ()
  4181. (unless org-search-syntax-table
  4182. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4183. (modify-syntax-entry ?' "." org-search-syntax-table)
  4184. (modify-syntax-entry ?` "." org-search-syntax-table))
  4185. org-search-syntax-table)
  4186. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4187. ;;;###autoload
  4188. (defun org-search-view (&optional todo-only string edit-at)
  4189. "Show all entries that contain a phrase or words or regular expressions.
  4190. With optional prefix argument TODO-ONLY, only consider entries that are
  4191. TODO entries. The argument STRING can be used to pass a default search
  4192. string into this function. If EDIT-AT is non-nil, it means that the
  4193. user should get a chance to edit this string, with cursor at position
  4194. EDIT-AT.
  4195. The search string can be viewed either as a phrase that should be found as
  4196. is, or it can be broken into a number of snippets, each of which must match
  4197. in a Boolean way to select an entry. The default depends on the variable
  4198. `org-agenda-search-view-always-boolean'.
  4199. Even if this is turned off (the default) you can always switch to
  4200. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4201. The default is a direct search of the whole phrase, where each space in
  4202. the search string can expand to an arbitrary amount of whitespace,
  4203. including newlines.
  4204. If using a Boolean search, the search string is split on whitespace and
  4205. each snippet is searched separately, with logical AND to select an entry.
  4206. Words prefixed with a minus must *not* occur in the entry. Words without
  4207. a prefix or prefixed with a plus must occur in the entry. Matching is
  4208. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4209. match whole words, not parts of a word) if
  4210. `org-agenda-search-view-force-full-words' is set (default is nil).
  4211. Boolean search snippets enclosed by curly braces are interpreted as
  4212. regular expressions that must or (when preceded with \"-\") must not
  4213. match in the entry. Snippets enclosed into double quotes will be taken
  4214. as a whole, to include whitespace.
  4215. - If the search string starts with an asterisk, search only in headlines.
  4216. - If (possibly after the leading star) the search string starts with an
  4217. exclamation mark, this also means to look at TODO entries only, an effect
  4218. that can also be achieved with a prefix argument.
  4219. - If (possibly after star and exclamation mark) the search string starts
  4220. with a colon, this will mean that the (non-regexp) snippets of the
  4221. Boolean search must match as full words.
  4222. This command searches the agenda files, and in addition the files
  4223. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4224. is active."
  4225. (interactive "P")
  4226. (when org-agenda-overriding-arguments
  4227. (setq todo-only (car org-agenda-overriding-arguments)
  4228. string (nth 1 org-agenda-overriding-arguments)
  4229. edit-at (nth 2 org-agenda-overriding-arguments)))
  4230. (let* ((props (list 'face nil
  4231. 'done-face 'org-agenda-done
  4232. 'org-not-done-regexp org-not-done-regexp
  4233. 'org-todo-regexp org-todo-regexp
  4234. 'org-complex-heading-regexp org-complex-heading-regexp
  4235. 'mouse-face 'highlight
  4236. 'help-echo "mouse-2 or RET jump to location"))
  4237. (full-words org-agenda-search-view-force-full-words)
  4238. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4239. regexp rtn rtnall files file pos inherited-tags
  4240. marker category level tags c neg re boolean
  4241. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4242. (unless (and (not edit-at)
  4243. (stringp string)
  4244. (string-match "\\S-" string))
  4245. (setq string (read-string
  4246. (if org-agenda-search-view-always-boolean
  4247. "[+-]Word/{Regexp} ...: "
  4248. "Phrase or [+-]Word/{Regexp} ...: ")
  4249. (cond
  4250. ((integerp edit-at) (cons string edit-at))
  4251. (edit-at string))
  4252. 'org-agenda-search-history)))
  4253. (catch 'exit
  4254. (setq org-agenda-buffer-name
  4255. (org-agenda--get-buffer-name
  4256. (and org-agenda-sticky
  4257. (if (stringp string)
  4258. (format "*Org Agenda(%s:%s)*"
  4259. (or org-keys (or (and todo-only "S") "s"))
  4260. string)
  4261. (format "*Org Agenda(%s)*"
  4262. (or (and todo-only "S") "s"))))))
  4263. (org-agenda-prepare "SEARCH")
  4264. (org-compile-prefix-format 'search)
  4265. (org-set-sorting-strategy 'search)
  4266. (setq org-agenda-redo-command
  4267. (list 'org-search-view (if todo-only t nil)
  4268. (list 'if 'current-prefix-arg nil string)))
  4269. (setq org-agenda-query-string string)
  4270. (if (equal (string-to-char string) ?*)
  4271. (setq hdl-only t
  4272. words (substring string 1))
  4273. (setq words string))
  4274. (when (equal (string-to-char words) ?!)
  4275. (setq todo-only t
  4276. words (substring words 1)))
  4277. (when (equal (string-to-char words) ?:)
  4278. (setq full-words t
  4279. words (substring words 1)))
  4280. (when (or org-agenda-search-view-always-boolean
  4281. (member (string-to-char words) '(?- ?+ ?\{)))
  4282. (setq boolean t))
  4283. (setq words (split-string words))
  4284. (let (www w)
  4285. (while (setq w (pop words))
  4286. (while (and (string-match "\\\\\\'" w) words)
  4287. (setq w (concat (substring w 0 -1) " " (pop words))))
  4288. (push w www))
  4289. (setq words (nreverse www) www nil)
  4290. (while (setq w (pop words))
  4291. (when (and (string-match "\\`[-+]?{" w)
  4292. (not (string-match "}\\'" w)))
  4293. (while (and words (not (string-match "}\\'" (car words))))
  4294. (setq w (concat w " " (pop words))))
  4295. (setq w (concat w " " (pop words))))
  4296. (push w www))
  4297. (setq words (nreverse www)))
  4298. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4299. (when boolean
  4300. (let (wds w)
  4301. (while (setq w (pop words))
  4302. (when (or (equal (substring w 0 1) "\"")
  4303. (and (> (length w) 1)
  4304. (member (substring w 0 1) '("+" "-"))
  4305. (equal (substring w 1 2) "\"")))
  4306. (while (and words (not (equal (substring w -1) "\"")))
  4307. (setq w (concat w " " (pop words)))))
  4308. (and (string-match "\\`\\([-+]?\\)\"" w)
  4309. (setq w (replace-match "\\1" nil nil w)))
  4310. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4311. (push w wds))
  4312. (setq words (nreverse wds))))
  4313. (if boolean
  4314. (mapc (lambda (w)
  4315. (setq c (string-to-char w))
  4316. (if (equal c ?-)
  4317. (setq neg t w (substring w 1))
  4318. (if (equal c ?+)
  4319. (setq neg nil w (substring w 1))
  4320. (setq neg nil)))
  4321. (if (string-match "\\`{.*}\\'" w)
  4322. (setq re (substring w 1 -1))
  4323. (if full-words
  4324. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4325. (setq re (regexp-quote (downcase w)))))
  4326. (if neg (push re regexps-) (push re regexps+)))
  4327. words)
  4328. (push (mapconcat #'regexp-quote words "\\s-+")
  4329. regexps+))
  4330. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4331. (if (not regexps+)
  4332. (setq regexp org-outline-regexp-bol)
  4333. (setq regexp (pop regexps+))
  4334. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4335. regexp))))
  4336. (setq files (org-agenda-files nil 'ifmode))
  4337. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4338. ;; restriction.
  4339. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4340. (pop org-agenda-text-search-extra-files)
  4341. (unless (get 'org-agenda-files 'org-restrict)
  4342. (setq files (org-add-archive-files files))))
  4343. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4344. ;; non-existent ones.
  4345. (setq files (cl-remove-duplicates
  4346. (append files org-agenda-text-search-extra-files)
  4347. :test (lambda (a b)
  4348. (and (file-exists-p a)
  4349. (file-exists-p b)
  4350. (file-equal-p a b))))
  4351. rtnall nil)
  4352. (while (setq file (pop files))
  4353. (setq ee nil)
  4354. (catch 'nextfile
  4355. (org-check-agenda-file file)
  4356. (setq buffer (if (file-exists-p file)
  4357. (org-get-agenda-file-buffer file)
  4358. (error "No such file %s" file)))
  4359. (unless buffer
  4360. ;; If file does not exist, make sure an error message is sent
  4361. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4362. file))))
  4363. (with-current-buffer buffer
  4364. (with-syntax-table (org-search-syntax-table)
  4365. (unless (derived-mode-p 'org-mode)
  4366. (error "Agenda file %s is not in Org mode" file))
  4367. (let ((case-fold-search t))
  4368. (save-excursion
  4369. (save-restriction
  4370. (if (eq buffer org-agenda-restrict)
  4371. (narrow-to-region org-agenda-restrict-begin
  4372. org-agenda-restrict-end)
  4373. (widen))
  4374. (goto-char (point-min))
  4375. (unless (or (org-at-heading-p)
  4376. (outline-next-heading))
  4377. (throw 'nextfile t))
  4378. (goto-char (max (point-min) (1- (point))))
  4379. (while (re-search-forward regexp nil t)
  4380. (org-back-to-heading t)
  4381. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4382. (> (org-reduced-level (org-outline-level))
  4383. org-agenda-search-view-max-outline-level)
  4384. (forward-line -1)
  4385. (org-back-to-heading t)))
  4386. (skip-chars-forward "* ")
  4387. (setq beg (point-at-bol)
  4388. beg1 (point)
  4389. end (progn
  4390. (outline-next-heading)
  4391. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4392. (> (org-reduced-level (org-outline-level))
  4393. org-agenda-search-view-max-outline-level)
  4394. (forward-line 1)
  4395. (outline-next-heading)))
  4396. (point)))
  4397. (catch :skip
  4398. (goto-char beg)
  4399. (org-agenda-skip)
  4400. (setq str (buffer-substring-no-properties
  4401. (point-at-bol)
  4402. (if hdl-only (point-at-eol) end)))
  4403. (mapc (lambda (wr) (when (string-match wr str)
  4404. (goto-char (1- end))
  4405. (throw :skip t)))
  4406. regexps-)
  4407. (mapc (lambda (wr) (unless (string-match wr str)
  4408. (goto-char (1- end))
  4409. (throw :skip t)))
  4410. (if todo-only
  4411. (cons (concat "^\\*+[ \t]+"
  4412. org-not-done-regexp)
  4413. regexps+)
  4414. regexps+))
  4415. (goto-char beg)
  4416. (setq marker (org-agenda-new-marker (point))
  4417. category (org-get-category)
  4418. level (make-string (org-reduced-level (org-outline-level)) ? )
  4419. inherited-tags
  4420. (or (eq org-agenda-show-inherited-tags 'always)
  4421. (and (listp org-agenda-show-inherited-tags)
  4422. (memq 'todo org-agenda-show-inherited-tags))
  4423. (and (eq org-agenda-show-inherited-tags t)
  4424. (or (eq org-agenda-use-tag-inheritance t)
  4425. (memq 'todo org-agenda-use-tag-inheritance))))
  4426. tags (org-get-tags nil (not inherited-tags))
  4427. txt (org-agenda-format-item
  4428. ""
  4429. (buffer-substring-no-properties
  4430. beg1 (point-at-eol))
  4431. level category tags t))
  4432. (org-add-props txt props
  4433. 'org-marker marker 'org-hd-marker marker
  4434. 'org-todo-regexp org-todo-regexp
  4435. 'level level
  4436. 'org-complex-heading-regexp org-complex-heading-regexp
  4437. 'priority 1000
  4438. 'type "search")
  4439. (push txt ee)
  4440. (goto-char (1- end))))))))))
  4441. (setq rtn (nreverse ee))
  4442. (setq rtnall (append rtnall rtn)))
  4443. (org-agenda--insert-overriding-header
  4444. (with-temp-buffer
  4445. (insert "Search words: ")
  4446. (add-text-properties (point-min) (1- (point))
  4447. (list 'face 'org-agenda-structure))
  4448. (setq pos (point))
  4449. (insert string "\n")
  4450. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4451. (setq pos (point))
  4452. (unless org-agenda-multi
  4453. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4454. Press `\\[org-agenda-manipulate-query-add]', \
  4455. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4456. `\\[org-agenda-manipulate-query-add-re]', \
  4457. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4458. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4459. (add-text-properties pos (1- (point))
  4460. (list 'face 'org-agenda-structure-secondary)))
  4461. (buffer-string)))
  4462. (org-agenda-mark-header-line (point-min))
  4463. (when rtnall
  4464. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4465. (goto-char (point-min))
  4466. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4467. (add-text-properties (point-min) (point-max)
  4468. `(org-agenda-type search
  4469. org-last-args (,todo-only ,string ,edit-at)
  4470. org-redo-cmd ,org-agenda-redo-command
  4471. org-series-cmd ,org-cmd))
  4472. (org-agenda-finalize)
  4473. (setq buffer-read-only t))))
  4474. ;;; Agenda TODO list
  4475. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4476. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4477. (concat
  4478. (if (or (equal keywords "ALL") (not keywords))
  4479. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4480. (mapconcat
  4481. (lambda (kw)
  4482. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4483. (org-split-string keywords "|")
  4484. "|"))
  4485. "\n"))
  4486. (defvar org-select-this-todo-keyword nil)
  4487. (defvar org-last-arg nil)
  4488. (defvar crm-separator)
  4489. ;;;###autoload
  4490. (defun org-todo-list (&optional arg)
  4491. "Show all (not done) TODO entries from all agenda files in a single list.
  4492. The prefix arg can be used to select a specific TODO keyword and limit
  4493. the list to these. When using `\\[universal-argument]', you will be prompted
  4494. for a keyword. A numeric prefix directly selects the Nth keyword in
  4495. `org-todo-keywords-1'."
  4496. (interactive "P")
  4497. (when org-agenda-overriding-arguments
  4498. (setq arg org-agenda-overriding-arguments))
  4499. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4500. (let* ((today (org-today))
  4501. (date (calendar-gregorian-from-absolute today))
  4502. (completion-ignore-case t)
  4503. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4504. (catch 'exit
  4505. (setq org-agenda-buffer-name
  4506. (org-agenda--get-buffer-name
  4507. (and org-agenda-sticky
  4508. (if (stringp org-select-this-todo-keyword)
  4509. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4510. org-select-this-todo-keyword)
  4511. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4512. (org-agenda-prepare "TODO")
  4513. (setq kwds org-todo-keywords-for-agenda
  4514. org-select-this-todo-keyword (if (stringp arg) arg
  4515. (and (integerp arg)
  4516. (> arg 0)
  4517. (nth (1- arg) kwds))))
  4518. (when (equal arg '(4))
  4519. (setq org-select-this-todo-keyword
  4520. (mapconcat #'identity
  4521. (let ((crm-separator "|"))
  4522. (completing-read-multiple
  4523. "Keyword (or KWD1|KWD2|...): "
  4524. (mapcar #'list kwds) nil nil))
  4525. "|")))
  4526. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4527. (org-compile-prefix-format 'todo)
  4528. (org-set-sorting-strategy 'todo)
  4529. (setq org-agenda-redo-command
  4530. `(org-todo-list (or (and (numberp current-prefix-arg)
  4531. current-prefix-arg)
  4532. ,org-select-this-todo-keyword
  4533. current-prefix-arg ,arg)))
  4534. (setq files (org-agenda-files nil 'ifmode)
  4535. rtnall nil)
  4536. (while (setq file (pop files))
  4537. (catch 'nextfile
  4538. (org-check-agenda-file file)
  4539. (setq rtn (org-agenda-get-day-entries file date :todo))
  4540. (setq rtnall (append rtnall rtn))))
  4541. (org-agenda--insert-overriding-header
  4542. (with-temp-buffer
  4543. (insert "Global list of TODO items of type: ")
  4544. (add-text-properties (point-min) (1- (point))
  4545. (list 'face 'org-agenda-structure
  4546. 'short-heading
  4547. (concat "ToDo: "
  4548. (or org-select-this-todo-keyword "ALL"))))
  4549. (org-agenda-mark-header-line (point-min))
  4550. (insert (org-agenda-propertize-selected-todo-keywords
  4551. org-select-this-todo-keyword))
  4552. (setq pos (point))
  4553. (unless org-agenda-multi
  4554. (insert (substitute-command-keys "Press \
  4555. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4556. to search again: (0)[ALL]"))
  4557. (let ((n 0))
  4558. (dolist (k kwds)
  4559. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4560. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4561. (insert "\n "))
  4562. (insert " " s))))
  4563. (insert "\n"))
  4564. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4565. (buffer-string)))
  4566. (org-agenda-mark-header-line (point-min))
  4567. (when rtnall
  4568. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4569. (goto-char (point-min))
  4570. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4571. (add-text-properties (point-min) (point-max)
  4572. `(org-agenda-type todo
  4573. org-last-args ,arg
  4574. org-redo-cmd ,org-agenda-redo-command
  4575. org-series-cmd ,org-cmd))
  4576. (org-agenda-finalize)
  4577. (setq buffer-read-only t))))
  4578. ;;; Agenda tags match
  4579. ;;;###autoload
  4580. (defun org-tags-view (&optional todo-only match)
  4581. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4582. The prefix arg TODO-ONLY limits the search to TODO entries."
  4583. (interactive "P")
  4584. (when org-agenda-overriding-arguments
  4585. (setq todo-only (car org-agenda-overriding-arguments)
  4586. match (nth 1 org-agenda-overriding-arguments)))
  4587. (let* ((org-tags-match-list-sublevels
  4588. org-tags-match-list-sublevels)
  4589. (completion-ignore-case t)
  4590. (org--matcher-tags-todo-only todo-only)
  4591. rtn rtnall files file pos matcher
  4592. buffer)
  4593. (when (and (stringp match) (not (string-match "\\S-" match)))
  4594. (setq match nil))
  4595. (catch 'exit
  4596. (setq org-agenda-buffer-name
  4597. (org-agenda--get-buffer-name
  4598. (and org-agenda-sticky
  4599. (if (stringp match)
  4600. (format "*Org Agenda(%s:%s)*"
  4601. (or org-keys (or (and todo-only "M") "m"))
  4602. match)
  4603. (format "*Org Agenda(%s)*"
  4604. (or (and todo-only "M") "m"))))))
  4605. (setq matcher (org-make-tags-matcher match))
  4606. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4607. ;; expanding tags within `org-make-tags-matcher'
  4608. (org-agenda-prepare (concat "TAGS " match))
  4609. (setq match (car matcher)
  4610. matcher (cdr matcher))
  4611. (org-compile-prefix-format 'tags)
  4612. (org-set-sorting-strategy 'tags)
  4613. (setq org-agenda-query-string match)
  4614. (setq org-agenda-redo-command
  4615. (list 'org-tags-view
  4616. `(quote ,org--matcher-tags-todo-only)
  4617. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4618. (setq files (org-agenda-files nil 'ifmode)
  4619. rtnall nil)
  4620. (while (setq file (pop files))
  4621. (catch 'nextfile
  4622. (org-check-agenda-file file)
  4623. (setq buffer (if (file-exists-p file)
  4624. (org-get-agenda-file-buffer file)
  4625. (error "No such file %s" file)))
  4626. (if (not buffer)
  4627. ;; If file does not exist, error message to agenda
  4628. (setq rtn (list
  4629. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4630. rtnall (append rtnall rtn))
  4631. (with-current-buffer buffer
  4632. (unless (derived-mode-p 'org-mode)
  4633. (error "Agenda file %s is not in Org mode" file))
  4634. (save-excursion
  4635. (save-restriction
  4636. (if (eq buffer org-agenda-restrict)
  4637. (narrow-to-region org-agenda-restrict-begin
  4638. org-agenda-restrict-end)
  4639. (widen))
  4640. (setq rtn (org-scan-tags 'agenda
  4641. matcher
  4642. org--matcher-tags-todo-only))
  4643. (setq rtnall (append rtnall rtn))))))))
  4644. (org-agenda--insert-overriding-header
  4645. (with-temp-buffer
  4646. (insert "Headlines with TAGS match: ")
  4647. (add-text-properties (point-min) (1- (point))
  4648. (list 'face 'org-agenda-structure
  4649. 'short-heading
  4650. (concat "Match: " match)))
  4651. (setq pos (point))
  4652. (insert match "\n")
  4653. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4654. (setq pos (point))
  4655. (unless org-agenda-multi
  4656. (insert (substitute-command-keys
  4657. "Press \
  4658. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4659. to search again\n")))
  4660. (add-text-properties pos (1- (point))
  4661. (list 'face 'org-agenda-structure-secondary))
  4662. (buffer-string)))
  4663. (org-agenda-mark-header-line (point-min))
  4664. (when rtnall
  4665. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4666. (goto-char (point-min))
  4667. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4668. (add-text-properties
  4669. (point-min) (point-max)
  4670. `(org-agenda-type tags
  4671. org-last-args (,org--matcher-tags-todo-only ,match)
  4672. org-redo-cmd ,org-agenda-redo-command
  4673. org-series-cmd ,org-cmd))
  4674. (org-agenda-finalize)
  4675. (setq buffer-read-only t))))
  4676. ;;; Agenda Finding stuck projects
  4677. (defvar org-agenda-skip-regexp nil
  4678. "Regular expression used in skipping subtrees for the agenda.
  4679. This is basically a temporary global variable that can be set and then
  4680. used by user-defined selections using `org-agenda-skip-function'.")
  4681. (defvar org-agenda-overriding-header nil
  4682. "When set during agenda, todo and tags searches it replaces the header.
  4683. If an empty string, no header will be inserted. If any other
  4684. string, it will be inserted as a header. If a function, insert
  4685. the string returned by the function as a header. If nil, a
  4686. header will be generated automatically according to the command.
  4687. This variable should not be set directly, but custom commands can
  4688. bind it in the options section.")
  4689. (defun org-agenda-skip-entry-if (&rest conditions)
  4690. "Skip entry if any of CONDITIONS is true.
  4691. See `org-agenda-skip-if' for details."
  4692. (org-agenda-skip-if nil conditions))
  4693. (defun org-agenda-skip-subtree-if (&rest conditions)
  4694. "Skip subtree if any of CONDITIONS is true.
  4695. See `org-agenda-skip-if' for details."
  4696. (org-agenda-skip-if t conditions))
  4697. (defun org-agenda-skip-if (subtree conditions)
  4698. "Check current entity for CONDITIONS.
  4699. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4700. the entry (i.e. the text before the next heading) is checked.
  4701. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4702. from different tests. Valid conditions are:
  4703. scheduled Check if there is a scheduled cookie
  4704. notscheduled Check if there is no scheduled cookie
  4705. deadline Check if there is a deadline
  4706. notdeadline Check if there is no deadline
  4707. timestamp Check if there is a timestamp (also deadline or scheduled)
  4708. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4709. regexp Check if regexp matches
  4710. notregexp Check if regexp does not match.
  4711. todo Check if TODO keyword matches
  4712. nottodo Check if TODO keyword does not match
  4713. The regexp is taken from the conditions list, it must come right after
  4714. the `regexp' or `notregexp' element.
  4715. `todo' and `nottodo' accept as an argument a list of todo
  4716. keywords, which may include \"*\" to match any todo keyword.
  4717. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4718. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4719. Instead of a list, a keyword class may be given. For example:
  4720. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4721. would skip entries that haven't been marked with any of \"DONE\"
  4722. keywords. Possible classes are: `todo', `done', `any'.
  4723. If any of these conditions is met, this function returns the end point of
  4724. the entity, causing the search to continue from there. This is a function
  4725. that can be put into `org-agenda-skip-function' for the duration of a command."
  4726. (org-back-to-heading t)
  4727. (let* (;; (beg (point))
  4728. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4729. (org-entry-end-position)))
  4730. (planning-end (if subtree end (line-end-position 2)))
  4731. m)
  4732. (and
  4733. (or (and (memq 'scheduled conditions)
  4734. (re-search-forward org-scheduled-time-regexp planning-end t))
  4735. (and (memq 'notscheduled conditions)
  4736. (not
  4737. (save-excursion
  4738. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4739. (and (memq 'deadline conditions)
  4740. (re-search-forward org-deadline-time-regexp planning-end t))
  4741. (and (memq 'notdeadline conditions)
  4742. (not
  4743. (save-excursion
  4744. (re-search-forward org-deadline-time-regexp planning-end t))))
  4745. (and (memq 'timestamp conditions)
  4746. (re-search-forward org-ts-regexp end t))
  4747. (and (memq 'nottimestamp conditions)
  4748. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4749. (and (setq m (memq 'regexp conditions))
  4750. (stringp (nth 1 m))
  4751. (re-search-forward (nth 1 m) end t))
  4752. (and (setq m (memq 'notregexp conditions))
  4753. (stringp (nth 1 m))
  4754. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4755. (and (or
  4756. (setq m (memq 'nottodo conditions))
  4757. (setq m (memq 'todo-unblocked conditions))
  4758. (setq m (memq 'nottodo-unblocked conditions))
  4759. (setq m (memq 'todo conditions)))
  4760. (org-agenda-skip-if-todo m end)))
  4761. end)))
  4762. (defun org-agenda-skip-if-todo (args end)
  4763. "Helper function for `org-agenda-skip-if', do not use it directly.
  4764. ARGS is a list with first element either `todo', `nottodo',
  4765. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4766. a list of TODO keywords, or a state symbol `todo' or `done' or
  4767. `any'."
  4768. (let ((todo-re
  4769. (concat "^\\*+[ \t]+"
  4770. (regexp-opt
  4771. (pcase args
  4772. (`(,_ todo)
  4773. (org-delete-all org-done-keywords
  4774. (copy-sequence org-todo-keywords-1)))
  4775. (`(,_ done) org-done-keywords)
  4776. (`(,_ any) org-todo-keywords-1)
  4777. (`(,_ ,(pred atom))
  4778. (error "Invalid TODO class or type: %S" args))
  4779. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4780. (`(,_ ,todo-list) todo-list))
  4781. 'words))))
  4782. (pcase args
  4783. (`(todo . ,_)
  4784. (let (case-fold-search) (re-search-forward todo-re end t)))
  4785. (`(nottodo . ,_)
  4786. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4787. (`(todo-unblocked . ,_)
  4788. (catch :unblocked
  4789. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4790. (when (org-entry-blocked-p) (throw :unblocked t)))
  4791. nil))
  4792. (`(nottodo-unblocked . ,_)
  4793. (catch :unblocked
  4794. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4795. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4796. t))
  4797. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4798. ;;;###autoload
  4799. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4800. "Create agenda view for projects that are stuck.
  4801. Stuck projects are project that have no next actions. For the definitions
  4802. of what a project is and how to check if it stuck, customize the variable
  4803. `org-stuck-projects'."
  4804. (interactive)
  4805. (let* ((org-agenda-overriding-header
  4806. (or org-agenda-overriding-header "List of stuck projects: "))
  4807. (matcher (nth 0 org-stuck-projects))
  4808. (todo (nth 1 org-stuck-projects))
  4809. (tags (nth 2 org-stuck-projects))
  4810. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4811. (todo-wds
  4812. (if (not (member "*" todo)) todo
  4813. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4814. (org-delete-all org-done-keywords-for-agenda
  4815. (copy-sequence org-todo-keywords-for-agenda))))
  4816. (todo-re (and todo
  4817. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4818. (mapconcat #'identity todo-wds "\\|"))))
  4819. (tags-re (cond ((null tags) nil)
  4820. ((member "*" tags) org-tag-line-re)
  4821. (tags
  4822. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4823. (concat org-outline-regexp-bol
  4824. ".*?[ \t]:"
  4825. other-tags
  4826. (regexp-opt tags t)
  4827. ":" other-tags "[ \t]*$")))
  4828. (t nil)))
  4829. (re-list (delq nil (list todo-re tags-re gen-re)))
  4830. (skip-re
  4831. (if (null re-list)
  4832. (error "Missing information to identify unstuck projects")
  4833. (mapconcat #'identity re-list "\\|")))
  4834. (org-agenda-skip-function
  4835. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4836. ;; in the subtree.
  4837. (lambda ()
  4838. (and (save-excursion
  4839. (let ((case-fold-search nil))
  4840. (re-search-forward
  4841. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4842. (progn (outline-next-heading) (point))))))
  4843. (org-tags-view nil matcher)
  4844. (setq org-agenda-buffer-name (buffer-name))
  4845. (with-current-buffer org-agenda-buffer-name
  4846. (setq org-agenda-redo-command
  4847. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4848. (let ((inhibit-read-only t))
  4849. (add-text-properties
  4850. (point-min) (point-max)
  4851. `(org-redo-cmd ,org-agenda-redo-command))))))
  4852. ;;; Diary integration
  4853. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4854. (defvar diary-list-entries-hook)
  4855. (defvar diary-time-regexp)
  4856. (defvar diary-modify-entry-list-string-function)
  4857. (defvar diary-file-name-prefix)
  4858. (defvar diary-display-function)
  4859. (defun org-get-entries-from-diary (date)
  4860. "Get the (Emacs Calendar) diary entries for DATE."
  4861. (require 'diary-lib)
  4862. (declare-function diary-fancy-display "diary-lib" ())
  4863. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4864. (diary-display-function #'diary-fancy-display)
  4865. (pop-up-frames nil)
  4866. (diary-list-entries-hook
  4867. (cons 'org-diary-default-entry diary-list-entries-hook))
  4868. (diary-file-name-prefix nil) ; turn this feature off
  4869. (diary-modify-entry-list-string-function
  4870. #'org-modify-diary-entry-string)
  4871. (diary-time-regexp (concat "^" diary-time-regexp))
  4872. entries
  4873. (org-disable-agenda-to-diary t))
  4874. (save-excursion
  4875. (save-window-excursion
  4876. (diary-list-entries date 1)))
  4877. (if (not (get-buffer diary-fancy-buffer))
  4878. (setq entries nil)
  4879. (with-current-buffer diary-fancy-buffer
  4880. (setq buffer-read-only nil)
  4881. (if (zerop (buffer-size))
  4882. ;; No entries
  4883. (setq entries nil)
  4884. ;; Omit the date and other unnecessary stuff
  4885. (org-agenda-cleanup-fancy-diary)
  4886. ;; Add prefix to each line and extend the text properties
  4887. (if (zerop (buffer-size))
  4888. (setq entries nil)
  4889. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4890. (setq entries
  4891. (with-temp-buffer
  4892. (insert entries) (goto-char (point-min))
  4893. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4894. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4895. (replace-match (concat "; " (match-string 1)))))
  4896. (buffer-string)))))
  4897. (set-buffer-modified-p nil)
  4898. (kill-buffer diary-fancy-buffer)))
  4899. (when entries
  4900. (setq entries (org-split-string entries "\n"))
  4901. (setq entries
  4902. (mapcar
  4903. (lambda (x)
  4904. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4905. ;; Extend the text properties to the beginning of the line
  4906. (org-add-props x (text-properties-at (1- (length x)) x)
  4907. 'type "diary" 'date date 'face 'org-agenda-diary))
  4908. entries)))))
  4909. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4910. "Hook run when the fancy diary buffer is cleaned up.")
  4911. (defun org-agenda-cleanup-fancy-diary ()
  4912. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4913. This gets rid of the date, the underline under the date, and the
  4914. dummy entry installed by Org mode to ensure non-empty diary for
  4915. each date. It also removes lines that contain only whitespace."
  4916. (goto-char (point-min))
  4917. (if (looking-at ".*?:[ \t]*")
  4918. (progn
  4919. (replace-match "")
  4920. (re-search-forward "\n=+$" nil t)
  4921. (replace-match "")
  4922. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4923. (re-search-forward "\n=+$" nil t)
  4924. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4925. (goto-char (point-min))
  4926. (while (re-search-forward "^ +\n" nil t)
  4927. (replace-match ""))
  4928. (goto-char (point-min))
  4929. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4930. (replace-match ""))
  4931. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4932. (defun org-modify-diary-entry-string (string)
  4933. "Add text properties to string, allowing Org to act on it."
  4934. (org-add-props string nil
  4935. 'mouse-face 'highlight
  4936. 'help-echo (if buffer-file-name
  4937. (format "mouse-2 or RET jump to diary file %s"
  4938. (abbreviate-file-name buffer-file-name))
  4939. "")
  4940. 'org-agenda-diary-link t
  4941. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4942. (defun org-diary-default-entry ()
  4943. "Add a dummy entry to the diary.
  4944. Needed to avoid empty dates which mess up holiday display."
  4945. ;; Catch the error if dealing with the new add-to-diary-alist
  4946. (when org-disable-agenda-to-diary
  4947. (diary-add-to-list original-date "Org mode dummy" "")))
  4948. (defvar org-diary-last-run-time nil)
  4949. ;;;###autoload
  4950. (defun org-diary (&rest args)
  4951. "Return diary information from org files.
  4952. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4953. It accesses org files and extracts information from those files to be
  4954. listed in the diary. The function accepts arguments specifying what
  4955. items should be listed. For a list of arguments allowed here, see the
  4956. variable `org-agenda-entry-types'.
  4957. The call in the diary file should look like this:
  4958. &%%(org-diary) ~/path/to/some/orgfile.org
  4959. Use a separate line for each org file to check. Or, if you omit the file name,
  4960. all files listed in `org-agenda-files' will be checked automatically:
  4961. &%%(org-diary)
  4962. If you don't give any arguments (as in the example above), the default value
  4963. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4964. So the example above may also be written as
  4965. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4966. The function expects the lisp variables `entry' and `date' to be provided
  4967. by the caller, because this is how the calendar works. Don't use this
  4968. function from a program - use `org-agenda-get-day-entries' instead."
  4969. (with-no-warnings (defvar date) (defvar entry))
  4970. (when (> (- (float-time)
  4971. org-agenda-last-marker-time)
  4972. 5)
  4973. ;; I am not sure if this works with sticky agendas, because the marker
  4974. ;; list is then no longer a global variable.
  4975. (org-agenda-reset-markers))
  4976. (org-compile-prefix-format 'agenda)
  4977. (org-set-sorting-strategy 'agenda)
  4978. (setq args (or args org-agenda-entry-types))
  4979. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4980. (list entry)
  4981. (org-agenda-files t)))
  4982. (time (float-time))
  4983. file rtn results)
  4984. (when (or (not org-diary-last-run-time)
  4985. (> (- time
  4986. org-diary-last-run-time)
  4987. 3))
  4988. (org-agenda-prepare-buffers files))
  4989. (setq org-diary-last-run-time time)
  4990. ;; If this is called during org-agenda, don't return any entries to
  4991. ;; the calendar. Org Agenda will list these entries itself.
  4992. (when org-disable-agenda-to-diary (setq files nil))
  4993. (while (setq file (pop files))
  4994. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4995. (setq results (append results rtn)))
  4996. (when results
  4997. (setq results
  4998. (mapcar (lambda (i) (replace-regexp-in-string
  4999. org-link-bracket-re "\\2" i))
  5000. results))
  5001. (concat (org-agenda-finalize-entries results) "\n"))))
  5002. ;;; Agenda entry finders
  5003. (defun org-agenda--timestamp-to-absolute (&rest args)
  5004. "Call `org-time-string-to-absolute' with ARGS.
  5005. However, throw `:skip' whenever an error is raised."
  5006. (condition-case e
  5007. (apply #'org-time-string-to-absolute args)
  5008. (org-diary-sexp-no-match (throw :skip nil))
  5009. (error
  5010. (message "%s; Skipping entry" (error-message-string e))
  5011. (throw :skip nil))))
  5012. (defun org-agenda-get-day-entries (file date &rest args)
  5013. "Does the work for `org-diary' and `org-agenda'.
  5014. FILE is the path to a file to be checked for entries. DATE is date like
  5015. the one returned by `calendar-current-date'. ARGS are symbols indicating
  5016. which kind of entries should be extracted. For details about these, see
  5017. the documentation of `org-diary'."
  5018. (let* ((org-startup-folded nil)
  5019. (org-startup-align-all-tables nil)
  5020. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  5021. (error "No such file %s" file))))
  5022. (if (not buffer)
  5023. ;; If file does not exist, signal it in diary nonetheless.
  5024. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5025. (with-current-buffer buffer
  5026. (unless (derived-mode-p 'org-mode)
  5027. (error "Agenda file %s is not in Org mode" file))
  5028. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5029. (setf org-agenda-current-date date)
  5030. (save-excursion
  5031. (save-restriction
  5032. (if (eq buffer org-agenda-restrict)
  5033. (narrow-to-region org-agenda-restrict-begin
  5034. org-agenda-restrict-end)
  5035. (widen))
  5036. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5037. ;; first in order to populate DEADLINES before passing it.
  5038. ;;
  5039. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5040. ;; guarding us from modifying `org-agenda-entry-types'.
  5041. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5042. (when (and (memq :scheduled args) (memq :scheduled* args))
  5043. (setf args (delq :scheduled* args)))
  5044. (cond
  5045. ((memq :deadline args)
  5046. (setf args (cons :deadline
  5047. (delq :deadline (delq :deadline* args)))))
  5048. ((memq :deadline* args)
  5049. (setf args (cons :deadline* (delq :deadline* args)))))
  5050. ;; Collect list of headlines. Return them flattened.
  5051. (let ((case-fold-search nil) results deadlines)
  5052. (org-dlet
  5053. ((date date))
  5054. (dolist (arg args (apply #'nconc (nreverse results)))
  5055. (pcase arg
  5056. ((and :todo (guard (org-agenda-today-p date)))
  5057. (push (org-agenda-get-todos) results))
  5058. (:timestamp
  5059. (push (org-agenda-get-blocks) results)
  5060. (push (org-agenda-get-timestamps deadlines) results))
  5061. (:sexp
  5062. (push (org-agenda-get-sexps) results))
  5063. (:scheduled
  5064. (push (org-agenda-get-scheduled deadlines) results))
  5065. (:scheduled*
  5066. (push (org-agenda-get-scheduled deadlines t) results))
  5067. (:closed
  5068. (push (org-agenda-get-progress) results))
  5069. (:deadline
  5070. (setf deadlines (org-agenda-get-deadlines))
  5071. (push deadlines results))
  5072. (:deadline*
  5073. (setf deadlines (org-agenda-get-deadlines t))
  5074. (push deadlines results))))))))))))
  5075. (defsubst org-em (x y list)
  5076. "Is X or Y a member of LIST?"
  5077. (or (memq x list) (memq y list)))
  5078. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5079. (defvar org-agenda-sorting-strategy-selected nil)
  5080. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5081. "Retrieve timestamp information for sorting agenda views.
  5082. Given a point or marker POM, returns a cons cell of the timestamp
  5083. and the timestamp type relevant for the sorting strategy in
  5084. `org-agenda-sorting-strategy-selected'."
  5085. (let (ts ts-date-type)
  5086. (save-match-data
  5087. (cond ((org-em 'scheduled-up 'scheduled-down
  5088. org-agenda-sorting-strategy-selected)
  5089. (setq ts (org-entry-get pom "SCHEDULED")
  5090. ts-date-type " scheduled"))
  5091. ((org-em 'deadline-up 'deadline-down
  5092. org-agenda-sorting-strategy-selected)
  5093. (setq ts (org-entry-get pom "DEADLINE")
  5094. ts-date-type " deadline"))
  5095. ((org-em 'ts-up 'ts-down
  5096. org-agenda-sorting-strategy-selected)
  5097. (setq ts (org-entry-get pom "TIMESTAMP")
  5098. ts-date-type " timestamp"))
  5099. ((org-em 'tsia-up 'tsia-down
  5100. org-agenda-sorting-strategy-selected)
  5101. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5102. ts-date-type " timestamp_ia"))
  5103. ((org-em 'timestamp-up 'timestamp-down
  5104. org-agenda-sorting-strategy-selected)
  5105. (setq ts (or (org-entry-get pom "SCHEDULED")
  5106. (org-entry-get pom "DEADLINE")
  5107. (org-entry-get pom "TIMESTAMP")
  5108. (org-entry-get pom "TIMESTAMP_IA"))
  5109. ts-date-type ""))
  5110. (t (setq ts-date-type "")))
  5111. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5112. ts-date-type))))
  5113. (defun org-agenda-get-todos ()
  5114. "Return the TODO information for agenda display."
  5115. (let* ((props (list 'face nil
  5116. 'done-face 'org-agenda-done
  5117. 'org-not-done-regexp org-not-done-regexp
  5118. 'org-todo-regexp org-todo-regexp
  5119. 'org-complex-heading-regexp org-complex-heading-regexp
  5120. 'mouse-face 'highlight
  5121. 'help-echo
  5122. (format "mouse-2 or RET jump to org file %s"
  5123. (abbreviate-file-name buffer-file-name))))
  5124. (case-fold-search nil)
  5125. (regexp (format org-heading-keyword-regexp-format
  5126. (cond
  5127. ((and org-select-this-todo-keyword
  5128. (equal org-select-this-todo-keyword "*"))
  5129. org-todo-regexp)
  5130. (org-select-this-todo-keyword
  5131. (concat "\\("
  5132. (mapconcat #'identity
  5133. (org-split-string
  5134. org-select-this-todo-keyword
  5135. "|")
  5136. "\\|")
  5137. "\\)"))
  5138. (t org-not-done-regexp))))
  5139. marker priority category level tags todo-state
  5140. ts-date ts-date-type ts-date-pair
  5141. ee txt beg end inherited-tags todo-state-end-pos
  5142. effort effort-minutes)
  5143. (goto-char (point-min))
  5144. (while (re-search-forward regexp nil t)
  5145. (catch :skip
  5146. (save-match-data
  5147. (beginning-of-line)
  5148. (org-agenda-skip)
  5149. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5150. (unless (and (setq todo-state (org-get-todo-state))
  5151. (setq todo-state-end-pos (match-end 2)))
  5152. (goto-char end)
  5153. (throw :skip nil))
  5154. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5155. (goto-char (1+ beg))
  5156. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5157. (throw :skip nil)))
  5158. (goto-char (match-beginning 2))
  5159. (setq marker (org-agenda-new-marker (match-beginning 0))
  5160. category (org-get-category)
  5161. effort (save-match-data (or (get-text-property (point) 'effort)
  5162. (org-entry-get (point) org-effort-property)))
  5163. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5164. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5165. ts-date (car ts-date-pair)
  5166. ts-date-type (cdr ts-date-pair)
  5167. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5168. inherited-tags
  5169. (or (eq org-agenda-show-inherited-tags 'always)
  5170. (and (listp org-agenda-show-inherited-tags)
  5171. (memq 'todo org-agenda-show-inherited-tags))
  5172. (and (eq org-agenda-show-inherited-tags t)
  5173. (or (eq org-agenda-use-tag-inheritance t)
  5174. (memq 'todo org-agenda-use-tag-inheritance))))
  5175. tags (org-get-tags nil (not inherited-tags))
  5176. level (make-string (org-reduced-level (org-outline-level)) ? )
  5177. txt (org-agenda-format-item ""
  5178. (org-add-props txt nil
  5179. 'effort effort
  5180. 'effort-minutes effort-minutes)
  5181. level category tags t)
  5182. priority (1+ (org-get-priority txt)))
  5183. (org-add-props txt props
  5184. 'org-marker marker 'org-hd-marker marker
  5185. 'priority priority
  5186. 'effort effort 'effort-minutes effort-minutes
  5187. 'level level
  5188. 'ts-date ts-date
  5189. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5190. (push txt ee)
  5191. (if org-agenda-todo-list-sublevels
  5192. (goto-char todo-state-end-pos)
  5193. (org-end-of-subtree 'invisible))))
  5194. (nreverse ee)))
  5195. (defun org-agenda-todo-custom-ignore-p (time n)
  5196. "Check whether timestamp is farther away than n number of days.
  5197. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5198. `org-agenda-todo-ignore-scheduled' or
  5199. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5200. (let ((days (org-time-stamp-to-now
  5201. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5202. (if (>= n 0)
  5203. (>= days n)
  5204. (<= days n))))
  5205. ;;;###autoload
  5206. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5207. (&optional end)
  5208. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5209. (when (or org-agenda-todo-ignore-with-date
  5210. org-agenda-todo-ignore-scheduled
  5211. org-agenda-todo-ignore-deadlines
  5212. org-agenda-todo-ignore-timestamp)
  5213. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5214. (save-excursion
  5215. (or (and org-agenda-todo-ignore-with-date
  5216. (re-search-forward org-ts-regexp end t))
  5217. (and org-agenda-todo-ignore-scheduled
  5218. (re-search-forward org-scheduled-time-regexp end t)
  5219. (cond
  5220. ((eq org-agenda-todo-ignore-scheduled 'future)
  5221. (> (org-time-stamp-to-now
  5222. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5223. 0))
  5224. ((eq org-agenda-todo-ignore-scheduled 'past)
  5225. (<= (org-time-stamp-to-now
  5226. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5227. 0))
  5228. ((numberp org-agenda-todo-ignore-scheduled)
  5229. (org-agenda-todo-custom-ignore-p
  5230. (match-string 1) org-agenda-todo-ignore-scheduled))
  5231. (t)))
  5232. (and org-agenda-todo-ignore-deadlines
  5233. (re-search-forward org-deadline-time-regexp end t)
  5234. (cond
  5235. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5236. ((eq org-agenda-todo-ignore-deadlines 'far)
  5237. (not (org-deadline-close-p (match-string 1))))
  5238. ((eq org-agenda-todo-ignore-deadlines 'future)
  5239. (> (org-time-stamp-to-now
  5240. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5241. 0))
  5242. ((eq org-agenda-todo-ignore-deadlines 'past)
  5243. (<= (org-time-stamp-to-now
  5244. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5245. 0))
  5246. ((numberp org-agenda-todo-ignore-deadlines)
  5247. (org-agenda-todo-custom-ignore-p
  5248. (match-string 1) org-agenda-todo-ignore-deadlines))
  5249. (t (org-deadline-close-p (match-string 1)))))
  5250. (and org-agenda-todo-ignore-timestamp
  5251. (let ((buffer (current-buffer))
  5252. (regexp
  5253. (concat
  5254. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5255. (start (point)))
  5256. ;; Copy current buffer into a temporary one
  5257. (with-temp-buffer
  5258. (insert-buffer-substring buffer start end)
  5259. (goto-char (point-min))
  5260. ;; Delete SCHEDULED and DEADLINE items
  5261. (while (re-search-forward regexp end t)
  5262. (delete-region (match-beginning 0) (match-end 0)))
  5263. (goto-char (point-min))
  5264. ;; No search for timestamp left
  5265. (when (re-search-forward org-ts-regexp nil t)
  5266. (cond
  5267. ((eq org-agenda-todo-ignore-timestamp 'future)
  5268. (> (org-time-stamp-to-now
  5269. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5270. 0))
  5271. ((eq org-agenda-todo-ignore-timestamp 'past)
  5272. (<= (org-time-stamp-to-now
  5273. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5274. 0))
  5275. ((numberp org-agenda-todo-ignore-timestamp)
  5276. (org-agenda-todo-custom-ignore-p
  5277. (match-string 1) org-agenda-todo-ignore-timestamp))
  5278. (t))))))))))
  5279. (defun org-agenda-get-timestamps (&optional deadlines)
  5280. "Return the date stamp information for agenda display.
  5281. Optional argument DEADLINES is a list of deadline items to be
  5282. displayed in agenda view."
  5283. (with-no-warnings (defvar date))
  5284. (let* ((props (list 'face 'org-agenda-calendar-event
  5285. 'org-not-done-regexp org-not-done-regexp
  5286. 'org-todo-regexp org-todo-regexp
  5287. 'org-complex-heading-regexp org-complex-heading-regexp
  5288. 'mouse-face 'highlight
  5289. 'help-echo
  5290. (format "mouse-2 or RET jump to Org file %s"
  5291. (abbreviate-file-name buffer-file-name))))
  5292. (current (calendar-absolute-from-gregorian date))
  5293. (today (org-today))
  5294. (deadline-position-alist
  5295. (mapcar (lambda (d)
  5296. (let ((m (get-text-property 0 'org-hd-marker d)))
  5297. (and m (marker-position m))))
  5298. deadlines))
  5299. ;; Match time-stamps set to current date, time-stamps with
  5300. ;; a repeater, and S-exp time-stamps.
  5301. (regexp
  5302. (concat
  5303. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5304. (regexp-quote
  5305. (substring
  5306. (format-time-string
  5307. (car org-time-stamp-formats)
  5308. (org-encode-time ; DATE bound by calendar
  5309. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5310. 1 11))
  5311. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5312. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5313. timestamp-items)
  5314. (goto-char (point-min))
  5315. (while (re-search-forward regexp nil t)
  5316. ;; Skip date ranges, scheduled and deadlines, which are handled
  5317. ;; specially. Also skip time-stamps before first headline as
  5318. ;; there would be no entry to add to the agenda. Eventually,
  5319. ;; ignore clock entries.
  5320. (catch :skip
  5321. (save-match-data
  5322. (when (or (org-at-date-range-p)
  5323. (org-at-planning-p)
  5324. (org-before-first-heading-p)
  5325. (and org-agenda-include-inactive-timestamps
  5326. (org-at-clock-log-p))
  5327. (not (org-at-timestamp-p 'agenda)))
  5328. (throw :skip nil))
  5329. (org-agenda-skip))
  5330. (let* ((pos (match-beginning 0))
  5331. (repeat (match-string 1))
  5332. (sexp-entry (match-string 3))
  5333. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5334. (save-excursion
  5335. (goto-char pos)
  5336. (looking-at org-ts-regexp-both)
  5337. (match-string 0))))
  5338. (todo-state (org-get-todo-state))
  5339. (warntime (get-text-property (point) 'org-appt-warntime))
  5340. (done? (member todo-state org-done-keywords)))
  5341. ;; Possibly skip done tasks.
  5342. (when (and done? org-agenda-skip-timestamp-if-done)
  5343. (throw :skip t))
  5344. ;; S-exp entry doesn't match current day: skip it.
  5345. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5346. (throw :skip nil))
  5347. (when repeat
  5348. (let* ((past
  5349. ;; A repeating time stamp is shown at its base
  5350. ;; date and every repeated date up to TODAY. If
  5351. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5352. ;; however, only the last repeat before today
  5353. ;; (inclusive) is shown.
  5354. (org-agenda--timestamp-to-absolute
  5355. repeat
  5356. (if (or (> current today)
  5357. (eq org-agenda-prefer-last-repeat t)
  5358. (member todo-state org-agenda-prefer-last-repeat))
  5359. today
  5360. current)
  5361. 'past (current-buffer) pos))
  5362. (future
  5363. ;; Display every repeated date past TODAY
  5364. ;; (exclusive) unless
  5365. ;; `org-agenda-show-future-repeats' is nil. If
  5366. ;; this variable is set to `next', only display
  5367. ;; the first repeated date after TODAY
  5368. ;; (exclusive).
  5369. (cond
  5370. ((<= current today) past)
  5371. ((not org-agenda-show-future-repeats) past)
  5372. (t
  5373. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5374. (1+ today)
  5375. current)))
  5376. (org-agenda--timestamp-to-absolute
  5377. repeat base 'future (current-buffer) pos))))))
  5378. (when (and (/= current past) (/= current future))
  5379. (throw :skip nil))))
  5380. (save-excursion
  5381. (re-search-backward org-outline-regexp-bol nil t)
  5382. ;; Possibly skip time-stamp when a deadline is set.
  5383. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5384. (assq (point) deadline-position-alist))
  5385. (throw :skip nil))
  5386. (let* ((category (org-get-category pos))
  5387. (effort (org-entry-get pos org-effort-property))
  5388. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5389. (inherited-tags
  5390. (or (eq org-agenda-show-inherited-tags 'always)
  5391. (and (consp org-agenda-show-inherited-tags)
  5392. (memq 'agenda org-agenda-show-inherited-tags))
  5393. (and (eq org-agenda-show-inherited-tags t)
  5394. (or (eq org-agenda-use-tag-inheritance t)
  5395. (memq 'agenda
  5396. org-agenda-use-tag-inheritance)))))
  5397. (tags (org-get-tags nil (not inherited-tags)))
  5398. (level (make-string (org-reduced-level (org-outline-level))
  5399. ?\s))
  5400. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5401. (match-string 1)))
  5402. (inactive? (= (char-after pos) ?\[))
  5403. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5404. (item
  5405. (org-agenda-format-item
  5406. (and inactive? org-agenda-inactive-leader)
  5407. (org-add-props head nil
  5408. 'effort effort
  5409. 'effort-minutes effort-minutes)
  5410. level category tags time-stamp org-ts-regexp habit?)))
  5411. (org-add-props item props
  5412. 'priority (if habit?
  5413. (org-habit-get-priority (org-habit-parse-todo))
  5414. (org-get-priority item))
  5415. 'org-marker (org-agenda-new-marker pos)
  5416. 'org-hd-marker (org-agenda-new-marker)
  5417. 'date date
  5418. 'level level
  5419. 'effort effort 'effort-minutes effort-minutes
  5420. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5421. current)
  5422. 'todo-state todo-state
  5423. 'warntime warntime
  5424. 'type "timestamp")
  5425. (push item timestamp-items))))
  5426. (when org-agenda-skip-additional-timestamps-same-entry
  5427. (outline-next-heading))))
  5428. (nreverse timestamp-items)))
  5429. (defun org-agenda-get-sexps ()
  5430. "Return the sexp information for agenda display."
  5431. (require 'diary-lib)
  5432. (with-no-warnings (defvar date) (defvar entry))
  5433. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5434. 'mouse-face 'highlight
  5435. 'help-echo
  5436. (format "mouse-2 or RET jump to org file %s"
  5437. (abbreviate-file-name buffer-file-name))))
  5438. (regexp "^&?%%(")
  5439. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5440. ;; so as to "hide" any current binding for it?
  5441. marker category extra level ee txt tags entry
  5442. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5443. effort effort-minutes)
  5444. (goto-char (point-min))
  5445. (while (re-search-forward regexp nil t)
  5446. (catch :skip
  5447. (org-agenda-skip)
  5448. (setq beg (match-beginning 0))
  5449. (goto-char (1- (match-end 0)))
  5450. (setq b (point))
  5451. (forward-sexp 1)
  5452. (setq sexp (buffer-substring b (point)))
  5453. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5454. (org-trim (match-string 1))
  5455. ""))
  5456. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5457. (when result
  5458. (setq marker (org-agenda-new-marker beg)
  5459. level (make-string (org-reduced-level (org-outline-level)) ? )
  5460. category (org-get-category beg)
  5461. effort (save-match-data (or (get-text-property (point) 'effort)
  5462. (org-entry-get (point) org-effort-property)))
  5463. inherited-tags
  5464. (or (eq org-agenda-show-inherited-tags 'always)
  5465. (and (listp org-agenda-show-inherited-tags)
  5466. (memq 'agenda org-agenda-show-inherited-tags))
  5467. (and (eq org-agenda-show-inherited-tags t)
  5468. (or (eq org-agenda-use-tag-inheritance t)
  5469. (memq 'agenda org-agenda-use-tag-inheritance))))
  5470. tags (org-get-tags nil (not inherited-tags))
  5471. todo-state (org-get-todo-state)
  5472. warntime (get-text-property (point) 'org-appt-warntime)
  5473. extra nil)
  5474. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5475. (dolist (r (if (stringp result)
  5476. (list result)
  5477. result)) ;; we expect a list here
  5478. (when (and org-agenda-diary-sexp-prefix
  5479. (string-match org-agenda-diary-sexp-prefix r))
  5480. (setq extra (match-string 0 r)
  5481. r (replace-match "" nil nil r)))
  5482. (if (string-match "\\S-" r)
  5483. (setq txt r)
  5484. (setq txt "SEXP entry returned empty string"))
  5485. (setq txt (org-agenda-format-item extra
  5486. (org-add-props txt nil
  5487. 'effort effort
  5488. 'effort-minutes effort-minutes)
  5489. level category tags 'time))
  5490. (org-add-props txt props 'org-marker marker
  5491. 'date date 'todo-state todo-state
  5492. 'effort effort 'effort-minutes effort-minutes
  5493. 'level level 'type "sexp" 'warntime warntime)
  5494. (push txt ee)))))
  5495. (nreverse ee)))
  5496. ;; Calendar sanity: define some functions that are independent of
  5497. ;; `calendar-date-style'.
  5498. (defun org-anniversary (year month day &optional mark)
  5499. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5500. (with-no-warnings
  5501. (let ((calendar-date-style 'iso))
  5502. (diary-anniversary year month day mark))))
  5503. (defun org-cyclic (N year month day &optional mark)
  5504. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5505. (with-no-warnings
  5506. (let ((calendar-date-style 'iso))
  5507. (diary-cyclic N year month day mark))))
  5508. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5509. "Like `diary-block', but with fixed (ISO) order of arguments."
  5510. (with-no-warnings
  5511. (let ((calendar-date-style 'iso))
  5512. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5513. (defun org-date (year month day &optional mark)
  5514. "Like `diary-date', but with fixed (ISO) order of arguments."
  5515. (with-no-warnings
  5516. (let ((calendar-date-style 'iso))
  5517. (diary-date year month day mark))))
  5518. ;; Define the `org-class' function
  5519. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5520. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5521. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5522. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5523. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5524. `holidays', then any date that is known by the Emacs calendar to be a
  5525. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5526. then those holidays will be skipped."
  5527. (with-no-warnings (defvar date) (defvar entry))
  5528. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5529. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5530. (d (calendar-absolute-from-gregorian date))
  5531. (h (when skip-weeks (calendar-check-holidays date))))
  5532. (and
  5533. (<= date1 d)
  5534. (<= d date2)
  5535. (= (calendar-day-of-week date) dayname)
  5536. (or (not skip-weeks)
  5537. (progn
  5538. (require 'cal-iso)
  5539. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5540. (not (or (and h (memq 'holidays skip-weeks))
  5541. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5542. entry)))
  5543. (defalias 'org-get-closed #'org-agenda-get-progress)
  5544. (defun org-agenda-get-progress ()
  5545. "Return the logged TODO entries for agenda display."
  5546. (with-no-warnings (defvar date))
  5547. (let* ((props (list 'mouse-face 'highlight
  5548. 'org-not-done-regexp org-not-done-regexp
  5549. 'org-todo-regexp org-todo-regexp
  5550. 'org-complex-heading-regexp org-complex-heading-regexp
  5551. 'help-echo
  5552. (format "mouse-2 or RET jump to org file %s"
  5553. (abbreviate-file-name buffer-file-name))))
  5554. (items (if (consp org-agenda-show-log-scoped)
  5555. org-agenda-show-log-scoped
  5556. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5557. '(clock)
  5558. org-agenda-log-mode-items)))
  5559. (parts
  5560. (delq nil
  5561. (list
  5562. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5563. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5564. (when (memq 'state items)
  5565. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5566. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5567. (error "`org-agenda-log-mode-items' is empty")))
  5568. (regexp (concat
  5569. "\\(" parts-re "\\)"
  5570. " *\\["
  5571. (regexp-quote
  5572. (substring
  5573. (format-time-string
  5574. (car org-time-stamp-formats)
  5575. (org-encode-time ; DATE bound by calendar
  5576. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5577. 1 11))))
  5578. (org-agenda-search-headline-for-time nil)
  5579. marker hdmarker priority category level tags closedp type
  5580. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5581. effort effort-minutes)
  5582. (goto-char (point-min))
  5583. (while (re-search-forward regexp nil t)
  5584. (catch :skip
  5585. (org-agenda-skip)
  5586. (setq marker (org-agenda-new-marker (match-beginning 0))
  5587. closedp (equal (match-string 1) org-closed-string)
  5588. statep (equal (string-to-char (match-string 1)) ?-)
  5589. clockp (not (or closedp statep))
  5590. state (and statep (match-string 2))
  5591. category (org-get-category (match-beginning 0))
  5592. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  5593. effort (save-match-data (or (get-text-property (point) 'effort)
  5594. (org-entry-get (point) org-effort-property))))
  5595. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5596. (when (string-match "\\]" timestr)
  5597. ;; substring should only run to end of time stamp
  5598. (setq rest (substring timestr (match-end 0))
  5599. timestr (substring timestr 0 (match-end 0)))
  5600. (if (and (not closedp) (not statep)
  5601. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5602. rest))
  5603. (progn (setq timestr (concat (substring timestr 0 -1)
  5604. "-" (match-string 1 rest) "]"))
  5605. (setq clocked (match-string 2 rest)))
  5606. (setq clocked "-")))
  5607. (save-excursion
  5608. (setq extra
  5609. (cond
  5610. ((not org-agenda-log-mode-add-notes) nil)
  5611. (statep
  5612. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5613. (match-string 1)))
  5614. (clockp
  5615. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5616. (match-string 1)))))
  5617. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5618. (throw :skip nil)
  5619. (goto-char (match-beginning 0))
  5620. (setq hdmarker (org-agenda-new-marker)
  5621. inherited-tags
  5622. (or (eq org-agenda-show-inherited-tags 'always)
  5623. (and (listp org-agenda-show-inherited-tags)
  5624. (memq 'todo org-agenda-show-inherited-tags))
  5625. (and (eq org-agenda-show-inherited-tags t)
  5626. (or (eq org-agenda-use-tag-inheritance t)
  5627. (memq 'todo org-agenda-use-tag-inheritance))))
  5628. tags (org-get-tags nil (not inherited-tags))
  5629. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5630. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5631. (setq txt (match-string 1))
  5632. (when extra
  5633. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5634. (setq txt (concat (substring txt 0 (match-beginning 1))
  5635. " - " extra " " (match-string 2 txt)))
  5636. (setq txt (concat txt " - " extra))))
  5637. (setq txt (org-agenda-format-item
  5638. (cond
  5639. (closedp "Closed: ")
  5640. (statep (concat "State: (" state ")"))
  5641. (t (concat "Clocked: (" clocked ")")))
  5642. (org-add-props txt nil
  5643. 'effort effort
  5644. 'effort-minutes effort-minutes)
  5645. level category tags timestr)))
  5646. (setq type (cond (closedp "closed")
  5647. (statep "state")
  5648. (t "clock")))
  5649. (setq priority 100000)
  5650. (org-add-props txt props
  5651. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5652. 'priority priority 'level level
  5653. 'effort effort 'effort-minutes effort-minutes
  5654. 'type type 'date date
  5655. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5656. (push txt ee))
  5657. (goto-char (point-at-eol))))
  5658. (nreverse ee)))
  5659. (defun org-agenda-show-clocking-issues ()
  5660. "Add overlays, showing issues with clocking.
  5661. See also the user option `org-agenda-clock-consistency-checks'."
  5662. (interactive)
  5663. (let* ((pl org-agenda-clock-consistency-checks)
  5664. (re (concat "^[ \t]*"
  5665. org-clock-string
  5666. "[ \t]+"
  5667. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5668. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5669. (tlstart 0.)
  5670. (tlend 0.)
  5671. (maxtime (org-duration-to-minutes
  5672. (or (plist-get pl :max-duration) "24:00")))
  5673. (mintime (org-duration-to-minutes
  5674. (or (plist-get pl :min-duration) 0)))
  5675. (maxgap (org-duration-to-minutes
  5676. ;; default 30:00 means never complain
  5677. (or (plist-get pl :max-gap) "30:00")))
  5678. (gapok (mapcar #'org-duration-to-minutes
  5679. (plist-get pl :gap-ok-around)))
  5680. (def-face (or (plist-get pl :default-face)
  5681. '((:background "DarkRed") (:foreground "white"))))
  5682. issue face m te ts dt ov)
  5683. (goto-char (point-min))
  5684. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5685. (setq issue nil face def-face)
  5686. (catch 'next
  5687. (setq m (org-get-at-bol 'org-marker)
  5688. te nil ts nil)
  5689. (unless (and m (markerp m))
  5690. (setq issue "No valid clock line") (throw 'next t))
  5691. (org-with-point-at m
  5692. (save-excursion
  5693. (goto-char (point-at-bol))
  5694. (unless (looking-at re)
  5695. (error "No valid Clock line")
  5696. (throw 'next t))
  5697. (unless (match-end 3)
  5698. (setq issue
  5699. (format
  5700. "No end time: (%s)"
  5701. (org-duration-from-minutes
  5702. (floor
  5703. (- (float-time (org-current-time))
  5704. (float-time (org-time-string-to-time (match-string 1))))
  5705. 60)))
  5706. face (or (plist-get pl :no-end-time-face) face))
  5707. (throw 'next t))
  5708. (setq ts (match-string 1)
  5709. te (match-string 3)
  5710. ts (float-time (org-time-string-to-time ts))
  5711. te (float-time (org-time-string-to-time te))
  5712. dt (- te ts))))
  5713. (cond
  5714. ((> dt (* 60 maxtime))
  5715. ;; a very long clocking chunk
  5716. (setq issue (format "Clocking interval is very long: %s"
  5717. (org-duration-from-minutes (floor dt 60)))
  5718. face (or (plist-get pl :long-face) face)))
  5719. ((< dt (* 60 mintime))
  5720. ;; a very short clocking chunk
  5721. (setq issue (format "Clocking interval is very short: %s"
  5722. (org-duration-from-minutes (floor dt 60)))
  5723. face (or (plist-get pl :short-face) face)))
  5724. ((and (> tlend 0) (< ts tlend))
  5725. ;; Two clock entries are overlapping
  5726. (setq issue (format "Clocking overlap: %d minutes"
  5727. (/ (- tlend ts) 60))
  5728. face (or (plist-get pl :overlap-face) face)))
  5729. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5730. ;; There is a gap, lets see if we need to report it
  5731. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5732. (setq issue (format "Clocking gap: %d minutes"
  5733. (/ (- ts tlend) 60))
  5734. face (or (plist-get pl :gap-face) face))))
  5735. (t nil)))
  5736. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5737. (when issue
  5738. ;; OK, there was some issue, add an overlay to show the issue
  5739. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5740. (overlay-put ov 'before-string
  5741. (concat
  5742. (org-add-props
  5743. (format "%-43s" (concat " " issue))
  5744. nil
  5745. 'face face)
  5746. "\n"))
  5747. (overlay-put ov 'evaporate t)))))
  5748. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5749. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5750. (catch 'exit
  5751. (unless ok-list
  5752. ;; there are no OK times for gaps...
  5753. (throw 'exit nil))
  5754. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5755. ;; This is more than 24 hours, so it is OK.
  5756. ;; because we have at least one OK time, that must be in the
  5757. ;; 24 hour interval.
  5758. (throw 'exit t))
  5759. ;; We have a shorter gap.
  5760. ;; Now we have to get the minute of the day when these times are
  5761. (let* ((t1dec (decode-time t1))
  5762. (t2dec (decode-time t2))
  5763. ;; compute the minute on the day
  5764. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5765. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5766. (when (< min2 min1)
  5767. ;; if min2 is smaller than min1, this means it is on the next day.
  5768. ;; Wrap it to after midnight.
  5769. (setq min2 (+ min2 1440)))
  5770. ;; Now check if any of the OK times is in the gap
  5771. (mapc (lambda (x)
  5772. ;; Wrap the time to after midnight if necessary
  5773. (when (< x min1) (setq x (+ x 1440)))
  5774. ;; Check if in interval
  5775. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5776. ok-list)
  5777. ;; Nope, this gap is not OK
  5778. nil)))
  5779. (defun org-agenda-get-deadlines (&optional with-hour)
  5780. "Return the deadline information for agenda display.
  5781. When WITH-HOUR is non-nil, only return deadlines with an hour
  5782. specification like [h]h:mm."
  5783. (with-no-warnings (defvar date))
  5784. (let* ((props (list 'mouse-face 'highlight
  5785. 'org-not-done-regexp org-not-done-regexp
  5786. 'org-todo-regexp org-todo-regexp
  5787. 'org-complex-heading-regexp org-complex-heading-regexp
  5788. 'help-echo
  5789. (format "mouse-2 or RET jump to org file %s"
  5790. (abbreviate-file-name buffer-file-name))))
  5791. (regexp (if with-hour
  5792. org-deadline-time-hour-regexp
  5793. org-deadline-time-regexp))
  5794. (today (org-today))
  5795. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5796. (current (calendar-absolute-from-gregorian date))
  5797. deadline-items)
  5798. (goto-char (point-min))
  5799. (if (org-element--cache-active-p)
  5800. (org-element-cache-map
  5801. (lambda (el)
  5802. (when (and (org-element-property :deadline el)
  5803. (or (not with-hour)
  5804. (org-element-property
  5805. :hour-start
  5806. (org-element-property :deadline el))
  5807. (org-element-property
  5808. :hour-end
  5809. (org-element-property :deadline el))))
  5810. (goto-char (org-element-property :contents-begin el))
  5811. (catch :skip
  5812. (org-agenda-skip el)
  5813. (let* ((s (substring (org-element-property
  5814. :raw-value
  5815. (org-element-property :deadline el))
  5816. 1 -1))
  5817. (pos (save-excursion
  5818. (goto-char (org-element-property :contents-begin el))
  5819. ;; We intentionally leave NOERROR
  5820. ;; argument in `re-search-forward' nil. If
  5821. ;; the search fails here, something went
  5822. ;; wrong and we are looking at
  5823. ;; non-matching headline.
  5824. (re-search-forward regexp (line-end-position))
  5825. (1- (match-beginning 1))))
  5826. (todo-state (org-element-property :todo-keyword el))
  5827. (done? (eq 'done (org-element-property :todo-type el)))
  5828. (sexp? (eq 'diary
  5829. (org-element-property
  5830. :type (org-element-property :deadline el))))
  5831. ;; DEADLINE is the deadline date for the entry. It is
  5832. ;; either the base date or the last repeat, according
  5833. ;; to `org-agenda-prefer-last-repeat'.
  5834. (deadline
  5835. (cond
  5836. (sexp? (org-agenda--timestamp-to-absolute s current))
  5837. ((or (eq org-agenda-prefer-last-repeat t)
  5838. (member todo-state org-agenda-prefer-last-repeat))
  5839. (org-agenda--timestamp-to-absolute
  5840. s today 'past (current-buffer) pos))
  5841. (t (org-agenda--timestamp-to-absolute s))))
  5842. ;; REPEAT is the future repeat closest from CURRENT,
  5843. ;; according to `org-agenda-show-future-repeats'. If
  5844. ;; the latter is nil, or if the time stamp has no
  5845. ;; repeat part, default to DEADLINE.
  5846. (repeat
  5847. (cond
  5848. (sexp? deadline)
  5849. ((<= current today) deadline)
  5850. ((not org-agenda-show-future-repeats) deadline)
  5851. (t
  5852. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5853. (1+ today)
  5854. current)))
  5855. (org-agenda--timestamp-to-absolute
  5856. s base 'future (current-buffer) pos)))))
  5857. (diff (- deadline current))
  5858. (suppress-prewarning
  5859. (let ((scheduled
  5860. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5861. (org-element-property
  5862. :raw-value
  5863. (org-element-property :scheduled el)))))
  5864. (cond
  5865. ((not scheduled) nil)
  5866. ;; The current item has a scheduled date, so
  5867. ;; evaluate its prewarning lead time.
  5868. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5869. ;; Use global prewarning-restart lead time.
  5870. org-agenda-skip-deadline-prewarning-if-scheduled)
  5871. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5872. 'pre-scheduled)
  5873. ;; Set pre-warning to no earlier than SCHEDULED.
  5874. (min (- deadline
  5875. (org-agenda--timestamp-to-absolute scheduled))
  5876. org-deadline-warning-days))
  5877. ;; Set pre-warning to deadline.
  5878. (t 0))))
  5879. (wdays (or suppress-prewarning (org-get-wdays s))))
  5880. (cond
  5881. ;; Only display deadlines at their base date, at future
  5882. ;; repeat occurrences or in today agenda.
  5883. ((= current deadline) nil)
  5884. ((= current repeat) nil)
  5885. ((not today?) (throw :skip nil))
  5886. ;; Upcoming deadline: display within warning period WDAYS.
  5887. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5888. ;; Overdue deadline: warn about it for
  5889. ;; `org-deadline-past-days' duration.
  5890. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5891. ;; Possibly skip done tasks.
  5892. (when (and done?
  5893. (or org-agenda-skip-deadline-if-done
  5894. (/= deadline current)))
  5895. (throw :skip nil))
  5896. (save-excursion
  5897. (goto-char (org-element-property :begin el))
  5898. (let* ((category (org-get-category))
  5899. (effort (save-match-data (or (get-text-property (point) 'effort)
  5900. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5901. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5902. (level (make-string (org-element-property :level el)
  5903. ?\s))
  5904. (head (save-excursion
  5905. (goto-char (org-element-property :begin el))
  5906. (re-search-forward org-outline-regexp-bol)
  5907. (buffer-substring-no-properties (point) (line-end-position))))
  5908. (inherited-tags
  5909. (or (eq org-agenda-show-inherited-tags 'always)
  5910. (and (listp org-agenda-show-inherited-tags)
  5911. (memq 'agenda org-agenda-show-inherited-tags))
  5912. (and (eq org-agenda-show-inherited-tags t)
  5913. (or (eq org-agenda-use-tag-inheritance t)
  5914. (memq 'agenda
  5915. org-agenda-use-tag-inheritance)))))
  5916. (tags (org-get-tags el (not inherited-tags)))
  5917. (time
  5918. (cond
  5919. ;; No time of day designation if it is only
  5920. ;; a reminder.
  5921. ((and (/= current deadline) (/= current repeat)) nil)
  5922. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5923. (concat (substring s (match-beginning 1)) " "))
  5924. (t 'time)))
  5925. (item
  5926. (org-agenda-format-item
  5927. ;; Insert appropriate suffixes before deadlines.
  5928. ;; Those only apply to today agenda.
  5929. (pcase-let ((`(,now ,future ,past)
  5930. org-agenda-deadline-leaders))
  5931. (cond
  5932. ((and today? (< deadline today)) (format past (- diff)))
  5933. ((and today? (> deadline today)) (format future diff))
  5934. (t now)))
  5935. (org-add-props head nil
  5936. 'effort effort
  5937. 'effort-minutes effort-minutes)
  5938. level category tags time))
  5939. (face (org-agenda-deadline-face
  5940. (- 1 (/ (float diff) (max wdays 1)))))
  5941. (upcoming? (and today? (> deadline today)))
  5942. (warntime (get-text-property (point) 'org-appt-warntime)))
  5943. (org-add-props item props
  5944. 'org-marker (org-agenda-new-marker pos)
  5945. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5946. 'warntime warntime
  5947. 'level level
  5948. 'effort effort 'effort-minutes effort-minutes
  5949. 'ts-date deadline
  5950. 'priority
  5951. ;; Adjust priority to today reminders about deadlines.
  5952. ;; Overdue deadlines get the highest priority
  5953. ;; increase, then imminent deadlines and eventually
  5954. ;; more distant deadlines.
  5955. (let ((adjust (if today? (- diff) 0)))
  5956. (+ adjust (org-get-priority item)))
  5957. 'todo-state todo-state
  5958. 'type (if upcoming? "upcoming-deadline" "deadline")
  5959. 'date (if upcoming? date deadline)
  5960. 'face (if done? 'org-agenda-done face)
  5961. 'undone-face face
  5962. 'done-face 'org-agenda-done)
  5963. (push item deadline-items)))))))
  5964. :next-re regexp
  5965. :fail-re regexp
  5966. :narrow t)
  5967. (while (re-search-forward regexp nil t)
  5968. (catch :skip
  5969. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5970. (org-agenda-skip)
  5971. (let* ((s (match-string 1))
  5972. (pos (1- (match-beginning 1)))
  5973. (todo-state (save-match-data (org-get-todo-state)))
  5974. (done? (member todo-state org-done-keywords))
  5975. (sexp? (string-prefix-p "%%" s))
  5976. ;; DEADLINE is the deadline date for the entry. It is
  5977. ;; either the base date or the last repeat, according
  5978. ;; to `org-agenda-prefer-last-repeat'.
  5979. (deadline
  5980. (cond
  5981. (sexp? (org-agenda--timestamp-to-absolute s current))
  5982. ((or (eq org-agenda-prefer-last-repeat t)
  5983. (member todo-state org-agenda-prefer-last-repeat))
  5984. (org-agenda--timestamp-to-absolute
  5985. s today 'past (current-buffer) pos))
  5986. (t (org-agenda--timestamp-to-absolute s))))
  5987. ;; REPEAT is the future repeat closest from CURRENT,
  5988. ;; according to `org-agenda-show-future-repeats'. If
  5989. ;; the latter is nil, or if the time stamp has no
  5990. ;; repeat part, default to DEADLINE.
  5991. (repeat
  5992. (cond
  5993. (sexp? deadline)
  5994. ((<= current today) deadline)
  5995. ((not org-agenda-show-future-repeats) deadline)
  5996. (t
  5997. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5998. (1+ today)
  5999. current)))
  6000. (org-agenda--timestamp-to-absolute
  6001. s base 'future (current-buffer) pos)))))
  6002. (diff (- deadline current))
  6003. (suppress-prewarning
  6004. (let ((scheduled
  6005. (and org-agenda-skip-deadline-prewarning-if-scheduled
  6006. (org-entry-get nil "SCHEDULED"))))
  6007. (cond
  6008. ((not scheduled) nil)
  6009. ;; The current item has a scheduled date, so
  6010. ;; evaluate its prewarning lead time.
  6011. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  6012. ;; Use global prewarning-restart lead time.
  6013. org-agenda-skip-deadline-prewarning-if-scheduled)
  6014. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  6015. 'pre-scheduled)
  6016. ;; Set pre-warning to no earlier than SCHEDULED.
  6017. (min (- deadline
  6018. (org-agenda--timestamp-to-absolute scheduled))
  6019. org-deadline-warning-days))
  6020. ;; Set pre-warning to deadline.
  6021. (t 0))))
  6022. (wdays (or suppress-prewarning (org-get-wdays s))))
  6023. (cond
  6024. ;; Only display deadlines at their base date, at future
  6025. ;; repeat occurrences or in today agenda.
  6026. ((= current deadline) nil)
  6027. ((= current repeat) nil)
  6028. ((not today?) (throw :skip nil))
  6029. ;; Upcoming deadline: display within warning period WDAYS.
  6030. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6031. ;; Overdue deadline: warn about it for
  6032. ;; `org-deadline-past-days' duration.
  6033. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6034. ;; Possibly skip done tasks.
  6035. (when (and done?
  6036. (or org-agenda-skip-deadline-if-done
  6037. (/= deadline current)))
  6038. (throw :skip nil))
  6039. (save-excursion
  6040. (re-search-backward "^\\*+[ \t]+" nil t)
  6041. (goto-char (match-end 0))
  6042. (let* ((category (org-get-category))
  6043. (effort (save-match-data (or (get-text-property (point) 'effort)
  6044. (org-entry-get (point) org-effort-property))))
  6045. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6046. (level (make-string (org-reduced-level (org-outline-level))
  6047. ?\s))
  6048. (head (buffer-substring-no-properties
  6049. (point) (line-end-position)))
  6050. (inherited-tags
  6051. (or (eq org-agenda-show-inherited-tags 'always)
  6052. (and (listp org-agenda-show-inherited-tags)
  6053. (memq 'agenda org-agenda-show-inherited-tags))
  6054. (and (eq org-agenda-show-inherited-tags t)
  6055. (or (eq org-agenda-use-tag-inheritance t)
  6056. (memq 'agenda
  6057. org-agenda-use-tag-inheritance)))))
  6058. (tags (org-get-tags nil (not inherited-tags)))
  6059. (time
  6060. (cond
  6061. ;; No time of day designation if it is only
  6062. ;; a reminder.
  6063. ((and (/= current deadline) (/= current repeat)) nil)
  6064. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6065. (concat (substring s (match-beginning 1)) " "))
  6066. (t 'time)))
  6067. (item
  6068. (org-agenda-format-item
  6069. ;; Insert appropriate suffixes before deadlines.
  6070. ;; Those only apply to today agenda.
  6071. (pcase-let ((`(,now ,future ,past)
  6072. org-agenda-deadline-leaders))
  6073. (cond
  6074. ((and today? (< deadline today)) (format past (- diff)))
  6075. ((and today? (> deadline today)) (format future diff))
  6076. (t now)))
  6077. (org-add-props head nil
  6078. 'effort effort
  6079. 'effort-minutes effort-minutes)
  6080. level category tags time))
  6081. (face (org-agenda-deadline-face
  6082. (- 1 (/ (float diff) (max wdays 1)))))
  6083. (upcoming? (and today? (> deadline today)))
  6084. (warntime (get-text-property (point) 'org-appt-warntime)))
  6085. (org-add-props item props
  6086. 'org-marker (org-agenda-new-marker pos)
  6087. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6088. 'warntime warntime
  6089. 'level level
  6090. 'effort effort 'effort-minutes effort-minutes
  6091. 'ts-date deadline
  6092. 'priority
  6093. ;; Adjust priority to today reminders about deadlines.
  6094. ;; Overdue deadlines get the highest priority
  6095. ;; increase, then imminent deadlines and eventually
  6096. ;; more distant deadlines.
  6097. (let ((adjust (if today? (- diff) 0)))
  6098. (+ adjust (org-get-priority item)))
  6099. 'todo-state todo-state
  6100. 'type (if upcoming? "upcoming-deadline" "deadline")
  6101. 'date (if upcoming? date deadline)
  6102. 'face (if done? 'org-agenda-done face)
  6103. 'undone-face face
  6104. 'done-face 'org-agenda-done)
  6105. (push item deadline-items)))))))
  6106. (nreverse deadline-items)))
  6107. (defun org-agenda-deadline-face (fraction)
  6108. "Return the face to displaying a deadline item.
  6109. FRACTION is what fraction of the head-warning time has passed."
  6110. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6111. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6112. "Return the scheduled information for agenda display.
  6113. Optional argument DEADLINES is a list of deadline items to be
  6114. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6115. scheduled items with an hour specification like [h]h:mm."
  6116. (with-no-warnings (defvar date))
  6117. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6118. 'org-todo-regexp org-todo-regexp
  6119. 'org-complex-heading-regexp org-complex-heading-regexp
  6120. 'done-face 'org-agenda-done
  6121. 'mouse-face 'highlight
  6122. 'help-echo
  6123. (format "mouse-2 or RET jump to Org file %s"
  6124. (abbreviate-file-name buffer-file-name))))
  6125. (regexp (if with-hour
  6126. org-scheduled-time-hour-regexp
  6127. org-scheduled-time-regexp))
  6128. (today (org-today))
  6129. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6130. (current (calendar-absolute-from-gregorian date))
  6131. (deadline-pos
  6132. (mapcar (lambda (d)
  6133. (let ((m (get-text-property 0 'org-hd-marker d)))
  6134. (and m (marker-position m))))
  6135. deadlines))
  6136. scheduled-items)
  6137. (goto-char (point-min))
  6138. (if (org-element--cache-active-p)
  6139. (org-element-cache-map
  6140. (lambda (el)
  6141. (when (and (org-element-property :scheduled el)
  6142. (or (not with-hour)
  6143. (org-element-property
  6144. :hour-start
  6145. (org-element-property :scheduled el))
  6146. (org-element-property
  6147. :hour-end
  6148. (org-element-property :scheduled el))))
  6149. (goto-char (org-element-property :contents-begin el))
  6150. (catch :skip
  6151. (org-agenda-skip el)
  6152. (let* ((s (substring (org-element-property
  6153. :raw-value
  6154. (org-element-property :scheduled el))
  6155. 1 -1))
  6156. (pos (save-excursion
  6157. (goto-char (org-element-property :contents-begin el))
  6158. ;; We intentionally leave NOERROR
  6159. ;; argument in `re-search-forward' nil. If
  6160. ;; the search fails here, something went
  6161. ;; wrong and we are looking at
  6162. ;; non-matching headline.
  6163. (re-search-forward regexp (line-end-position))
  6164. (1- (match-beginning 1))))
  6165. (todo-state (org-element-property :todo-keyword el))
  6166. (donep (eq 'done (org-element-property :todo-type el)))
  6167. (sexp? (eq 'diary
  6168. (org-element-property
  6169. :type (org-element-property :scheduled el))))
  6170. ;; SCHEDULE is the scheduled date for the entry. It is
  6171. ;; either the bare date or the last repeat, according
  6172. ;; to `org-agenda-prefer-last-repeat'.
  6173. (schedule
  6174. (cond
  6175. (sexp? (org-agenda--timestamp-to-absolute s current))
  6176. ((or (eq org-agenda-prefer-last-repeat t)
  6177. (member todo-state org-agenda-prefer-last-repeat))
  6178. (org-agenda--timestamp-to-absolute
  6179. s today 'past (current-buffer) pos))
  6180. (t (org-agenda--timestamp-to-absolute s))))
  6181. ;; REPEAT is the future repeat closest from CURRENT,
  6182. ;; according to `org-agenda-show-future-repeats'. If
  6183. ;; the latter is nil, or if the time stamp has no
  6184. ;; repeat part, default to SCHEDULE.
  6185. (repeat
  6186. (cond
  6187. (sexp? schedule)
  6188. ((<= current today) schedule)
  6189. ((not org-agenda-show-future-repeats) schedule)
  6190. (t
  6191. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6192. (1+ today)
  6193. current)))
  6194. (org-agenda--timestamp-to-absolute
  6195. s base 'future (current-buffer) pos)))))
  6196. (diff (- current schedule))
  6197. (warntime (get-text-property (point) 'org-appt-warntime))
  6198. (pastschedp (< schedule today))
  6199. (futureschedp (> schedule today))
  6200. (habitp (and (fboundp 'org-is-habit-p)
  6201. (string= "habit" (org-element-property :STYLE el))))
  6202. (suppress-delay
  6203. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6204. (org-element-property
  6205. :raw-value
  6206. (org-element-property :deadline el)))))
  6207. (cond
  6208. ((not deadline) nil)
  6209. ;; The current item has a deadline date, so
  6210. ;; evaluate its delay time.
  6211. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6212. ;; Use global delay time.
  6213. (- org-agenda-skip-scheduled-delay-if-deadline))
  6214. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6215. 'post-deadline)
  6216. ;; Set delay to no later than DEADLINE.
  6217. (min (- schedule
  6218. (org-agenda--timestamp-to-absolute deadline))
  6219. org-scheduled-delay-days))
  6220. (t 0))))
  6221. (ddays
  6222. (cond
  6223. ;; Nullify delay when a repeater triggered already
  6224. ;; and the delay is of the form --Xd.
  6225. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6226. (> schedule (org-agenda--timestamp-to-absolute s)))
  6227. 0)
  6228. (suppress-delay
  6229. (let ((org-scheduled-delay-days suppress-delay))
  6230. (org-get-wdays s t t)))
  6231. (t (org-get-wdays s t)))))
  6232. ;; Display scheduled items at base date (SCHEDULE), today if
  6233. ;; scheduled before the current date, and at any repeat past
  6234. ;; today. However, skip delayed items and items that have
  6235. ;; been displayed for more than `org-scheduled-past-days'.
  6236. (unless (and todayp
  6237. habitp
  6238. (bound-and-true-p org-habit-show-all-today))
  6239. (when (or (and (> ddays 0) (< diff ddays))
  6240. (> diff (or (and habitp org-habit-scheduled-past-days)
  6241. org-scheduled-past-days))
  6242. (> schedule current)
  6243. (and (/= current schedule)
  6244. (/= current today)
  6245. (/= current repeat)))
  6246. (throw :skip nil)))
  6247. ;; Possibly skip done tasks.
  6248. (when (and donep
  6249. (or org-agenda-skip-scheduled-if-done
  6250. (/= schedule current)))
  6251. (throw :skip nil))
  6252. ;; Skip entry if it already appears as a deadline, per
  6253. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6254. ;; doesn't apply to habits.
  6255. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6256. ((guard
  6257. (or (not (memq (line-beginning-position 0) deadline-pos))
  6258. habitp))
  6259. nil)
  6260. (`repeated-after-deadline
  6261. (let ((deadline (time-to-days
  6262. (when (org-element-property :deadline el)
  6263. (org-time-string-to-time
  6264. (org-element-property :deadline el))))))
  6265. (and (<= schedule deadline) (> current deadline))))
  6266. (`not-today pastschedp)
  6267. (`t t)
  6268. (_ nil))
  6269. (throw :skip nil))
  6270. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6271. ;; only show them for today. Also skip done habits.
  6272. (when (and habitp
  6273. (or donep
  6274. (not (bound-and-true-p org-habit-show-habits))
  6275. (and (not todayp)
  6276. (bound-and-true-p
  6277. org-habit-show-habits-only-for-today))))
  6278. (throw :skip nil))
  6279. (save-excursion
  6280. (goto-char (org-element-property :begin el))
  6281. (let* ((category (org-get-category))
  6282. (effort (save-match-data
  6283. (or (get-text-property (point) 'effort)
  6284. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6285. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6286. (inherited-tags
  6287. (or (eq org-agenda-show-inherited-tags 'always)
  6288. (and (listp org-agenda-show-inherited-tags)
  6289. (memq 'agenda org-agenda-show-inherited-tags))
  6290. (and (eq org-agenda-show-inherited-tags t)
  6291. (or (eq org-agenda-use-tag-inheritance t)
  6292. (memq 'agenda
  6293. org-agenda-use-tag-inheritance)))))
  6294. (tags (org-get-tags el (not inherited-tags)))
  6295. (level (make-string (org-element-property :level el)
  6296. ?\s))
  6297. (head (save-excursion
  6298. (goto-char (org-element-property :begin el))
  6299. (re-search-forward org-outline-regexp-bol)
  6300. (buffer-substring (point) (line-end-position))))
  6301. (time
  6302. (cond
  6303. ;; No time of day designation if it is only a
  6304. ;; reminder, except for habits, which always show
  6305. ;; the time of day. Habits are an exception
  6306. ;; because if there is a time of day, that is
  6307. ;; interpreted to mean they should usually happen
  6308. ;; then, even if doing the habit was missed.
  6309. ((and
  6310. (not habitp)
  6311. (/= current schedule)
  6312. (/= current repeat))
  6313. nil)
  6314. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6315. (concat (substring s (match-beginning 1)) " "))
  6316. (t 'time)))
  6317. (item
  6318. (org-agenda-format-item
  6319. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6320. ;; Show a reminder of a past scheduled today.
  6321. (if (and todayp pastschedp)
  6322. (format past diff)
  6323. first))
  6324. (org-add-props head nil
  6325. 'effort effort
  6326. 'effort-minutes effort-minutes)
  6327. level category tags time nil habitp))
  6328. (face (cond ((and (not habitp) pastschedp)
  6329. 'org-scheduled-previously)
  6330. ((and habitp futureschedp)
  6331. 'org-agenda-done)
  6332. (todayp 'org-scheduled-today)
  6333. (t 'org-scheduled)))
  6334. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6335. (org-add-props item props
  6336. 'undone-face face
  6337. 'face (if donep 'org-agenda-done face)
  6338. 'org-marker (org-agenda-new-marker pos)
  6339. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6340. 'type (if pastschedp "past-scheduled" "scheduled")
  6341. 'date (if pastschedp schedule date)
  6342. 'ts-date schedule
  6343. 'warntime warntime
  6344. 'level level
  6345. 'effort effort 'effort-minutes effort-minutes
  6346. 'priority (if habitp (org-habit-get-priority habitp)
  6347. (+ 99 diff (org-get-priority item)))
  6348. 'org-habit-p habitp
  6349. 'todo-state todo-state)
  6350. (push item scheduled-items)))))))
  6351. :next-re regexp
  6352. :fail-re regexp
  6353. :narrow t)
  6354. (while (re-search-forward regexp nil t)
  6355. (catch :skip
  6356. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6357. (org-agenda-skip)
  6358. (let* ((s (match-string 1))
  6359. (pos (1- (match-beginning 1)))
  6360. (todo-state (save-match-data (org-get-todo-state)))
  6361. (donep (member todo-state org-done-keywords))
  6362. (sexp? (string-prefix-p "%%" s))
  6363. ;; SCHEDULE is the scheduled date for the entry. It is
  6364. ;; either the bare date or the last repeat, according
  6365. ;; to `org-agenda-prefer-last-repeat'.
  6366. (schedule
  6367. (cond
  6368. (sexp? (org-agenda--timestamp-to-absolute s current))
  6369. ((or (eq org-agenda-prefer-last-repeat t)
  6370. (member todo-state org-agenda-prefer-last-repeat))
  6371. (org-agenda--timestamp-to-absolute
  6372. s today 'past (current-buffer) pos))
  6373. (t (org-agenda--timestamp-to-absolute s))))
  6374. ;; REPEAT is the future repeat closest from CURRENT,
  6375. ;; according to `org-agenda-show-future-repeats'. If
  6376. ;; the latter is nil, or if the time stamp has no
  6377. ;; repeat part, default to SCHEDULE.
  6378. (repeat
  6379. (cond
  6380. (sexp? schedule)
  6381. ((<= current today) schedule)
  6382. ((not org-agenda-show-future-repeats) schedule)
  6383. (t
  6384. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6385. (1+ today)
  6386. current)))
  6387. (org-agenda--timestamp-to-absolute
  6388. s base 'future (current-buffer) pos)))))
  6389. (diff (- current schedule))
  6390. (warntime (get-text-property (point) 'org-appt-warntime))
  6391. (pastschedp (< schedule today))
  6392. (futureschedp (> schedule today))
  6393. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6394. (suppress-delay
  6395. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6396. (org-entry-get nil "DEADLINE"))))
  6397. (cond
  6398. ((not deadline) nil)
  6399. ;; The current item has a deadline date, so
  6400. ;; evaluate its delay time.
  6401. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6402. ;; Use global delay time.
  6403. (- org-agenda-skip-scheduled-delay-if-deadline))
  6404. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6405. 'post-deadline)
  6406. ;; Set delay to no later than DEADLINE.
  6407. (min (- schedule
  6408. (org-agenda--timestamp-to-absolute deadline))
  6409. org-scheduled-delay-days))
  6410. (t 0))))
  6411. (ddays
  6412. (cond
  6413. ;; Nullify delay when a repeater triggered already
  6414. ;; and the delay is of the form --Xd.
  6415. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6416. (> schedule (org-agenda--timestamp-to-absolute s)))
  6417. 0)
  6418. (suppress-delay
  6419. (let ((org-scheduled-delay-days suppress-delay))
  6420. (org-get-wdays s t t)))
  6421. (t (org-get-wdays s t)))))
  6422. ;; Display scheduled items at base date (SCHEDULE), today if
  6423. ;; scheduled before the current date, and at any repeat past
  6424. ;; today. However, skip delayed items and items that have
  6425. ;; been displayed for more than `org-scheduled-past-days'.
  6426. (unless (and todayp
  6427. habitp
  6428. (bound-and-true-p org-habit-show-all-today))
  6429. (when (or (and (> ddays 0) (< diff ddays))
  6430. (> diff (or (and habitp org-habit-scheduled-past-days)
  6431. org-scheduled-past-days))
  6432. (> schedule current)
  6433. (and (/= current schedule)
  6434. (/= current today)
  6435. (/= current repeat)))
  6436. (throw :skip nil)))
  6437. ;; Possibly skip done tasks.
  6438. (when (and donep
  6439. (or org-agenda-skip-scheduled-if-done
  6440. (/= schedule current)))
  6441. (throw :skip nil))
  6442. ;; Skip entry if it already appears as a deadline, per
  6443. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6444. ;; doesn't apply to habits.
  6445. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6446. ((guard
  6447. (or (not (memq (line-beginning-position 0) deadline-pos))
  6448. habitp))
  6449. nil)
  6450. (`repeated-after-deadline
  6451. (let ((deadline (time-to-days
  6452. (org-get-deadline-time (point)))))
  6453. (and (<= schedule deadline) (> current deadline))))
  6454. (`not-today pastschedp)
  6455. (`t t)
  6456. (_ nil))
  6457. (throw :skip nil))
  6458. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6459. ;; only show them for today. Also skip done habits.
  6460. (when (and habitp
  6461. (or donep
  6462. (not (bound-and-true-p org-habit-show-habits))
  6463. (and (not todayp)
  6464. (bound-and-true-p
  6465. org-habit-show-habits-only-for-today))))
  6466. (throw :skip nil))
  6467. (save-excursion
  6468. (re-search-backward "^\\*+[ \t]+" nil t)
  6469. (goto-char (match-end 0))
  6470. (let* ((category (org-get-category))
  6471. (effort (save-match-data (or (get-text-property (point) 'effort)
  6472. (org-entry-get (point) org-effort-property))))
  6473. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6474. (inherited-tags
  6475. (or (eq org-agenda-show-inherited-tags 'always)
  6476. (and (listp org-agenda-show-inherited-tags)
  6477. (memq 'agenda org-agenda-show-inherited-tags))
  6478. (and (eq org-agenda-show-inherited-tags t)
  6479. (or (eq org-agenda-use-tag-inheritance t)
  6480. (memq 'agenda
  6481. org-agenda-use-tag-inheritance)))))
  6482. (tags (org-get-tags nil (not inherited-tags)))
  6483. (level (make-string (org-reduced-level (org-outline-level))
  6484. ?\s))
  6485. (head (buffer-substring (point) (line-end-position)))
  6486. (time
  6487. (cond
  6488. ;; No time of day designation if it is only a
  6489. ;; reminder, except for habits, which always show
  6490. ;; the time of day. Habits are an exception
  6491. ;; because if there is a time of day, that is
  6492. ;; interpreted to mean they should usually happen
  6493. ;; then, even if doing the habit was missed.
  6494. ((and
  6495. (not habitp)
  6496. (/= current schedule)
  6497. (/= current repeat))
  6498. nil)
  6499. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6500. (concat (substring s (match-beginning 1)) " "))
  6501. (t 'time)))
  6502. (item
  6503. (org-agenda-format-item
  6504. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6505. ;; Show a reminder of a past scheduled today.
  6506. (if (and todayp pastschedp)
  6507. (format past diff)
  6508. first))
  6509. (org-add-props head nil
  6510. 'effort effort
  6511. 'effort-minutes effort-minutes)
  6512. level category tags time nil habitp))
  6513. (face (cond ((and (not habitp) pastschedp)
  6514. 'org-scheduled-previously)
  6515. ((and habitp futureschedp)
  6516. 'org-agenda-done)
  6517. (todayp 'org-scheduled-today)
  6518. (t 'org-scheduled)))
  6519. (habitp (and habitp (org-habit-parse-todo))))
  6520. (org-add-props item props
  6521. 'undone-face face
  6522. 'face (if donep 'org-agenda-done face)
  6523. 'org-marker (org-agenda-new-marker pos)
  6524. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6525. 'type (if pastschedp "past-scheduled" "scheduled")
  6526. 'date (if pastschedp schedule date)
  6527. 'ts-date schedule
  6528. 'warntime warntime
  6529. 'level level
  6530. 'effort effort 'effort-minutes effort-minutes
  6531. 'priority (if habitp (org-habit-get-priority habitp)
  6532. (+ 99 diff (org-get-priority item)))
  6533. 'org-habit-p habitp
  6534. 'todo-state todo-state)
  6535. (push item scheduled-items)))))))
  6536. (nreverse scheduled-items)))
  6537. (defun org-agenda-get-blocks ()
  6538. "Return the date-range information for agenda display."
  6539. (with-no-warnings (defvar date))
  6540. (let* ((props (list 'face nil
  6541. 'org-not-done-regexp org-not-done-regexp
  6542. 'org-todo-regexp org-todo-regexp
  6543. 'org-complex-heading-regexp org-complex-heading-regexp
  6544. 'mouse-face 'highlight
  6545. 'help-echo
  6546. (format "mouse-2 or RET jump to org file %s"
  6547. (abbreviate-file-name buffer-file-name))))
  6548. (regexp org-tr-regexp)
  6549. (d0 (calendar-absolute-from-gregorian date))
  6550. marker hdmarker ee txt d1 d2 s1 s2 category
  6551. level todo-state tags pos head donep inherited-tags
  6552. effort effort-minutes)
  6553. (goto-char (point-min))
  6554. (while (re-search-forward regexp nil t)
  6555. (catch :skip
  6556. (org-agenda-skip)
  6557. (setq pos (point))
  6558. (let ((start-time (match-string 1))
  6559. (end-time (match-string 2)))
  6560. (setq s1 (match-string 1)
  6561. s2 (match-string 2)
  6562. d1 (time-to-days
  6563. (condition-case err
  6564. (org-time-string-to-time s1)
  6565. (error
  6566. (error
  6567. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6568. s1
  6569. pos
  6570. (current-buffer)
  6571. (error-message-string err)))))
  6572. d2 (time-to-days
  6573. (condition-case err
  6574. (org-time-string-to-time s2)
  6575. (error
  6576. (error
  6577. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6578. s2
  6579. pos
  6580. (current-buffer)
  6581. (error-message-string err))))))
  6582. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6583. ;; Only allow days between the limits, because the normal
  6584. ;; date stamps will catch the limits.
  6585. (save-excursion
  6586. (setq todo-state (org-get-todo-state))
  6587. (setq donep (member todo-state org-done-keywords))
  6588. (when (and donep org-agenda-skip-timestamp-if-done)
  6589. (throw :skip t))
  6590. (setq marker (org-agenda-new-marker (point))
  6591. category (org-get-category))
  6592. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6593. (org-entry-get (point) org-effort-property))))
  6594. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6595. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6596. (throw :skip nil)
  6597. (goto-char (match-beginning 0))
  6598. (setq hdmarker (org-agenda-new-marker (point))
  6599. inherited-tags
  6600. (or (eq org-agenda-show-inherited-tags 'always)
  6601. (and (listp org-agenda-show-inherited-tags)
  6602. (memq 'agenda org-agenda-show-inherited-tags))
  6603. (and (eq org-agenda-show-inherited-tags t)
  6604. (or (eq org-agenda-use-tag-inheritance t)
  6605. (memq 'agenda org-agenda-use-tag-inheritance))))
  6606. tags (org-get-tags nil (not inherited-tags)))
  6607. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6608. (looking-at "\\*+[ \t]+\\(.*\\)")
  6609. (setq head (match-string 1))
  6610. (let ((remove-re
  6611. (if org-agenda-remove-timeranges-from-blocks
  6612. (concat
  6613. "<" (regexp-quote s1) ".*?>"
  6614. "--"
  6615. "<" (regexp-quote s2) ".*?>")
  6616. nil)))
  6617. (setq txt (org-agenda-format-item
  6618. (format
  6619. (nth (if (= d1 d2) 0 1)
  6620. org-agenda-timerange-leaders)
  6621. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6622. (org-add-props head nil
  6623. 'effort effort
  6624. 'effort-minutes effort-minutes)
  6625. level category tags
  6626. (save-match-data
  6627. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6628. (match-string 6 s1)))
  6629. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6630. (match-string 6 s2))))
  6631. (cond ((string= hhmm1 hhmm2)
  6632. (concat "<" start-time ">--<" end-time ">"))
  6633. ((and (= d1 d0) (= d2 d0))
  6634. (concat "<" start-time ">--<" end-time ">"))
  6635. ((= d1 d0)
  6636. (concat "<" start-time ">"))
  6637. ((= d2 d0)
  6638. (concat "<" end-time ">")))))
  6639. remove-re))))
  6640. (org-add-props txt props
  6641. 'org-marker marker 'org-hd-marker hdmarker
  6642. 'type "block" 'date date
  6643. 'level level
  6644. 'effort effort 'effort-minutes effort-minutes
  6645. 'todo-state todo-state
  6646. 'priority (org-get-priority txt))
  6647. (push txt ee))))
  6648. (goto-char pos)))
  6649. ;; Sort the entries by expiration date.
  6650. (nreverse ee)))
  6651. ;;; Agenda presentation and sorting
  6652. (defvar org-prefix-has-time nil
  6653. "A flag, set by `org-compile-prefix-format'.
  6654. The flag is set if the currently compiled format contains a `%t'.")
  6655. (defvar org-prefix-has-tag nil
  6656. "A flag, set by `org-compile-prefix-format'.
  6657. The flag is set if the currently compiled format contains a `%T'.")
  6658. (defvar org-prefix-has-effort nil
  6659. "A flag, set by `org-compile-prefix-format'.
  6660. The flag is set if the currently compiled format contains a `%e'.")
  6661. (defvar org-prefix-has-breadcrumbs nil
  6662. "A flag, set by `org-compile-prefix-format'.
  6663. The flag is set if the currently compiled format contains a `%b'.")
  6664. (defvar org-prefix-category-length nil
  6665. "Used by `org-compile-prefix-format' to remember the category field width.")
  6666. (defvar org-prefix-category-max-length nil
  6667. "Used by `org-compile-prefix-format' to remember the category field width.")
  6668. (defun org-agenda-get-category-icon (category)
  6669. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6670. (cl-dolist (entry org-agenda-category-icon-alist)
  6671. (when (string-match-p (car entry) category)
  6672. (if (listp (cadr entry))
  6673. (cl-return (cadr entry))
  6674. (cl-return (apply #'create-image (cdr entry)))))))
  6675. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6676. remove-re habitp)
  6677. "Format TXT to be inserted into the agenda buffer.
  6678. In particular, add the prefix and corresponding text properties.
  6679. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6680. WITH-LEVEL may be a string to replace the `%l' specifier.
  6681. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6682. category taken from local variable or file name. It will replace the `%c'
  6683. specifier in the format.
  6684. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6685. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6686. When DOTIME is a string, this string is searched for a time before TXT is.
  6687. TAGS can be the tags of the headline.
  6688. Any match of REMOVE-RE will be removed from TXT."
  6689. ;; We keep the org-prefix-* variable values along with a compiled
  6690. ;; formatter, so that multiple agendas existing at the same time do
  6691. ;; not step on each other toes.
  6692. ;;
  6693. ;; It was inconvenient to make these variables buffer local in
  6694. ;; Agenda buffers, because this function expects to be called with
  6695. ;; the buffer where item comes from being current, and not agenda
  6696. ;; buffer
  6697. (let* ((bindings (car org-prefix-format-compiled))
  6698. (formatter (cadr org-prefix-format-compiled)))
  6699. (cl-loop for (var value) in bindings
  6700. do (set var value))
  6701. (save-match-data
  6702. ;; Diary entries sometimes have extra whitespace at the beginning
  6703. (setq txt (org-trim txt))
  6704. ;; Fix the tags part in txt
  6705. (setq txt (org-agenda-fix-displayed-tags
  6706. txt tags
  6707. org-agenda-show-inherited-tags
  6708. org-agenda-hide-tags-regexp))
  6709. (with-no-warnings
  6710. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6711. ;; Based on what I see in `org-compile-prefix-format', I added
  6712. ;; a few more.
  6713. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6714. (defvar effort) (defvar extra)
  6715. (defvar level) (defvar tag) (defvar time))
  6716. (let* ((category (or with-category
  6717. (if buffer-file-name
  6718. (file-name-sans-extension
  6719. (file-name-nondirectory buffer-file-name))
  6720. "")))
  6721. (category-icon (org-agenda-get-category-icon category))
  6722. (category-icon (if category-icon
  6723. (propertize " " 'display category-icon)
  6724. ""))
  6725. (effort (and (not (string= txt ""))
  6726. (get-text-property 1 'effort txt)))
  6727. (tag (if tags (nth (1- (length tags)) tags) ""))
  6728. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6729. (extra (or (and (not habitp) extra) ""))
  6730. time
  6731. (ts (when dotime (concat
  6732. (if (stringp dotime) dotime "")
  6733. (and org-agenda-search-headline-for-time txt))))
  6734. (time-of-day (and dotime (org-get-time-of-day ts)))
  6735. stamp plain s0 s1 s2 rtn srp l
  6736. duration breadcrumbs)
  6737. (and (derived-mode-p 'org-mode) buffer-file-name
  6738. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6739. (when (and dotime time-of-day)
  6740. ;; Extract starting and ending time and move them to prefix
  6741. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6742. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6743. (setq s0 (match-string 0 ts)
  6744. srp (and stamp (match-end 3))
  6745. s1 (match-string (if plain 1 2) ts)
  6746. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6747. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6748. ;; them, we might want to remove them there to avoid duplication.
  6749. ;; The user can turn this off with a variable.
  6750. (when (and org-prefix-has-time
  6751. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6752. (string-match (concat (regexp-quote s0) " *") txt)
  6753. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6754. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6755. (= (match-beginning 0) 0)
  6756. t))
  6757. (setq txt (replace-match "" nil nil txt))))
  6758. ;; Normalize the time(s) to 24 hour.
  6759. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6760. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6761. ;; Try to set s2 if s1 and
  6762. ;; `org-agenda-default-appointment-duration' are set
  6763. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6764. (setq s2
  6765. (org-duration-from-minutes
  6766. (+ (org-duration-to-minutes s1 t)
  6767. org-agenda-default-appointment-duration)
  6768. nil t)))
  6769. ;; Compute the duration
  6770. (when s2
  6771. (setq duration (- (org-duration-to-minutes s2)
  6772. (org-duration-to-minutes s1))))
  6773. ;; Format S1 and S2 for display.
  6774. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6775. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6776. (when (string-match org-tag-group-re txt)
  6777. ;; Tags are in the string
  6778. (if (or (eq org-agenda-remove-tags t)
  6779. (and org-agenda-remove-tags
  6780. org-prefix-has-tag))
  6781. (setq txt (replace-match "" t t txt))
  6782. (setq txt (replace-match
  6783. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6784. (match-string 1 txt))
  6785. t t txt))))
  6786. (when remove-re
  6787. (while (string-match remove-re txt)
  6788. (setq txt (replace-match "" t t txt))))
  6789. ;; Set org-heading property on `txt' to mark the start of the
  6790. ;; heading.
  6791. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6792. ;; Prepare the variables needed in the eval of the compiled format
  6793. (when org-prefix-has-breadcrumbs
  6794. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6795. (let ((s (org-format-outline-path (org-get-outline-path)
  6796. (1- (frame-width))
  6797. nil org-agenda-breadcrumbs-separator)))
  6798. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6799. (setq time (cond (s2 (concat
  6800. (org-agenda-time-of-day-to-ampm-maybe s1)
  6801. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6802. (when org-agenda-timegrid-use-ampm " ")))
  6803. (s1 (concat
  6804. (org-agenda-time-of-day-to-ampm-maybe s1)
  6805. (if org-agenda-timegrid-use-ampm
  6806. (concat time-grid-trailing-characters " ")
  6807. time-grid-trailing-characters)))
  6808. (t ""))
  6809. category (if (symbolp category) (symbol-name category) category)
  6810. level (or with-level ""))
  6811. (if (string-match org-link-bracket-re category)
  6812. (progn
  6813. (setq l (string-width (or (match-string 2) (match-string 1))))
  6814. (when (< l (or org-prefix-category-length 0))
  6815. (setq category (copy-sequence category))
  6816. (org-add-props category nil
  6817. 'extra-space (make-string
  6818. (- org-prefix-category-length l 1) ?\ ))))
  6819. (when (and org-prefix-category-max-length
  6820. (>= (length category) org-prefix-category-max-length))
  6821. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6822. ;; Evaluate the compiled format
  6823. (setq rtn (concat (eval formatter t) txt))
  6824. ;; And finally add the text properties
  6825. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6826. (org-add-props rtn nil
  6827. 'org-category category
  6828. 'tags tags
  6829. 'org-priority-highest org-priority-highest
  6830. 'org-priority-lowest org-priority-lowest
  6831. 'time-of-day time-of-day
  6832. 'duration duration
  6833. 'breadcrumbs breadcrumbs
  6834. 'txt txt
  6835. 'level level
  6836. 'time time
  6837. 'extra extra
  6838. 'format org-prefix-format-compiled
  6839. 'dotime dotime)))))
  6840. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6841. "Remove tags string from TXT, and add a modified list of tags.
  6842. The modified list may contain inherited tags, and tags matched by
  6843. `org-agenda-hide-tags-regexp' will be removed."
  6844. (when (or add-inherited hide-re)
  6845. (when (string-match org-tag-group-re txt)
  6846. (setq txt (substring txt 0 (match-beginning 0))))
  6847. (setq tags
  6848. (delq nil
  6849. (mapcar (lambda (tg)
  6850. (if (or (and hide-re (string-match hide-re tg))
  6851. (and (not add-inherited)
  6852. (get-text-property 0 'inherited tg)))
  6853. nil
  6854. tg))
  6855. tags)))
  6856. (when tags
  6857. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6858. i)
  6859. (setq txt (concat txt " :"
  6860. (mapconcat
  6861. (lambda (x)
  6862. (setq i (get-text-property 0 'inherited x))
  6863. (if (and have-i (not i))
  6864. (progn
  6865. (setq have-i nil)
  6866. (concat ":" x))
  6867. x))
  6868. tags ":")
  6869. (if have-i "::" ":"))))))
  6870. txt)
  6871. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6872. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6873. "Add a time-grid for agenda items which need it.
  6874. LIST is the list of agenda items formatted by `org-agenda-list'.
  6875. NDAYS is the span of the current agenda view.
  6876. TODAYP is t when the current agenda view is on today."
  6877. (catch 'exit
  6878. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6879. ((and todayp (member 'today (car org-agenda-time-grid))))
  6880. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6881. ((member 'weekly (car org-agenda-time-grid)))
  6882. (t (throw 'exit list)))
  6883. (let* ((have (delq nil (mapcar
  6884. (lambda (x) (get-text-property 1 'time-of-day x))
  6885. list)))
  6886. (string (nth 3 org-agenda-time-grid))
  6887. (gridtimes (nth 1 org-agenda-time-grid))
  6888. (req (car org-agenda-time-grid))
  6889. (remove (member 'remove-match req))
  6890. new time)
  6891. (when (and (member 'require-timed req) (not have))
  6892. ;; don't show empty grid
  6893. (throw 'exit list))
  6894. (while (setq time (pop gridtimes))
  6895. (unless (and remove (member time have))
  6896. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6897. (push (org-agenda-format-item
  6898. nil string nil "" nil
  6899. (concat (substring time 0 -2) ":" (substring time -2)))
  6900. new)
  6901. (put-text-property
  6902. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6903. (when (and todayp org-agenda-show-current-time-in-grid)
  6904. (push (org-agenda-format-item
  6905. nil org-agenda-current-time-string nil "" nil
  6906. (format-time-string "%H:%M "))
  6907. new)
  6908. (put-text-property
  6909. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6910. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6911. (append new list)
  6912. (append list new)))))
  6913. (defun org-compile-prefix-format (key)
  6914. "Compile the prefix format into a Lisp form that can be evaluated.
  6915. KEY is the agenda type (see `org-agenda-prefix-format').
  6916. The resulting form and associated variable bindings is returned
  6917. and stored in the variable `org-prefix-format-compiled'."
  6918. (setq org-prefix-has-time nil
  6919. org-prefix-has-tag nil
  6920. org-prefix-category-length nil
  6921. org-prefix-has-effort nil
  6922. org-prefix-has-breadcrumbs nil)
  6923. (let ((s (cond
  6924. ((stringp org-agenda-prefix-format)
  6925. org-agenda-prefix-format)
  6926. ((assq key org-agenda-prefix-format)
  6927. (cdr (assq key org-agenda-prefix-format)))
  6928. (t " %-12:c%?-12t% s")))
  6929. (start 0)
  6930. varform vars var c f opt) ;; e
  6931. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6932. s start)
  6933. (setq var (or (cdr (assoc (match-string 4 s)
  6934. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6935. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6936. 'eval)
  6937. c (or (match-string 3 s) "")
  6938. opt (match-beginning 1)
  6939. start (1+ (match-beginning 0)))
  6940. (cl-case var
  6941. (time (setq org-prefix-has-time t))
  6942. (tag (setq org-prefix-has-tag t))
  6943. (effort (setq org-prefix-has-effort t))
  6944. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6945. (setq f (concat "%" (match-string 2 s) "s"))
  6946. (when (eq var 'category)
  6947. (setq org-prefix-category-length
  6948. (floor (abs (string-to-number (match-string 2 s)))))
  6949. (setq org-prefix-category-max-length
  6950. (let ((x (match-string 2 s)))
  6951. (save-match-data
  6952. (and (string-match "\\.[0-9]+" x)
  6953. (string-to-number (substring (match-string 0 x) 1)))))))
  6954. (if (eq var 'eval)
  6955. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6956. (if opt
  6957. (setq varform
  6958. `(if (member ,var '("" nil))
  6959. ""
  6960. (format ,f (concat ,var ,c))))
  6961. (setq varform
  6962. `(format ,f (if (member ,var '("" nil)) ""
  6963. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6964. (if (eq var 'eval)
  6965. (setf (substring s (match-beginning 0)
  6966. (+ (match-beginning 4)
  6967. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6968. "%s")
  6969. (setq s (replace-match "%s" t nil s)))
  6970. (push varform vars))
  6971. (setq vars (nreverse vars))
  6972. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6973. (setq org-prefix-format-compiled
  6974. (list
  6975. `((org-prefix-has-time ,org-prefix-has-time)
  6976. (org-prefix-has-tag ,org-prefix-has-tag)
  6977. (org-prefix-category-length ,org-prefix-category-length)
  6978. (org-prefix-has-effort ,org-prefix-has-effort)
  6979. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6980. `(format ,s ,@vars))))))
  6981. (defun org-set-sorting-strategy (key)
  6982. (setq org-agenda-sorting-strategy-selected
  6983. (if (symbolp (car org-agenda-sorting-strategy))
  6984. ;; the old format
  6985. org-agenda-sorting-strategy
  6986. (or (cdr (assq key org-agenda-sorting-strategy))
  6987. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6988. '(time-up category-keep priority-down)))))
  6989. (defun org-get-time-of-day (s &optional string)
  6990. "Check string S for a time of day.
  6991. If found, return it as a military time number between 0 and 2400.
  6992. If not found, return nil.
  6993. The optional STRING argument forces conversion into a 5 character wide string
  6994. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6995. where H:MM is the duration above midnight."
  6996. (let ((case-fold-search t)
  6997. (time-regexp
  6998. (rx word-start
  6999. (group (opt (any "012")) digit) ;group 1: hours
  7000. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  7001. (opt (group (or "am" "pm")))) ;group 3: am/pm
  7002. ;; Special "HHam/pm" case.
  7003. (group-n 3 (or "am" "pm")))
  7004. word-end)))
  7005. (save-match-data
  7006. (when (and (string-match time-regexp s)
  7007. (not (eq 'org-link (get-text-property 1 'face s))))
  7008. (let ((hours
  7009. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  7010. (am-p (equal ampm "am")))
  7011. (pcase (string-to-number (match-string 1 s))
  7012. ((and (guard (not ampm)) h) h)
  7013. (12 (if am-p 0 12))
  7014. (h (+ h (if am-p 0 12))))))
  7015. (minutes
  7016. (if (match-end 2)
  7017. (string-to-number (match-string 2 s))
  7018. 0)))
  7019. (pcase string
  7020. (`nil (+ minutes (* hours 100)))
  7021. ((and `overtime
  7022. (guard (or (> hours 24)
  7023. (and (= hours 24)
  7024. (> minutes 0)))))
  7025. (format "+%d:%02d" (- hours 24) minutes))
  7026. ((guard org-agenda-time-leading-zero)
  7027. (format "%02d:%02d" hours minutes))
  7028. (_
  7029. (format "%d:%02d" hours minutes))))))))
  7030. (defvar org-agenda-before-sorting-filter-function nil
  7031. "Function to be applied to agenda items prior to sorting.
  7032. Prior to sorting also means just before they are inserted into the agenda.
  7033. To aid sorting, you may revisit the original entries and add more text
  7034. properties which will later be used by the sorting functions.
  7035. The function should take a string argument, an agenda line.
  7036. It has access to the text properties in that line, which contain among
  7037. other things, the property `org-hd-marker' that points to the entry
  7038. where the line comes from. Note that not all lines going into the agenda
  7039. have this property, only most.
  7040. The function should return the modified string. It is probably best
  7041. to ONLY change text properties.
  7042. You can also use this function as a filter, by returning nil for lines
  7043. you don't want to have in the agenda at all. For this application, you
  7044. could bind the variable in the options section of a custom command.")
  7045. (defun org-agenda-finalize-entries (list &optional type)
  7046. "Sort, limit and concatenate the LIST of agenda items.
  7047. The optional argument TYPE tells the agenda type."
  7048. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7049. (cdr (assoc type org-agenda-max-effort)))
  7050. (t org-agenda-max-effort)))
  7051. (max-todo (cond ((listp org-agenda-max-todos)
  7052. (cdr (assoc type org-agenda-max-todos)))
  7053. (t org-agenda-max-todos)))
  7054. (max-tags (cond ((listp org-agenda-max-tags)
  7055. (cdr (assoc type org-agenda-max-tags)))
  7056. (t org-agenda-max-tags)))
  7057. (max-entries (cond ((listp org-agenda-max-entries)
  7058. (cdr (assoc type org-agenda-max-entries)))
  7059. (t org-agenda-max-entries))))
  7060. (when org-agenda-before-sorting-filter-function
  7061. (setq list
  7062. (delq nil
  7063. (mapcar
  7064. org-agenda-before-sorting-filter-function list))))
  7065. (setq list (mapcar #'org-agenda-highlight-todo list)
  7066. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7067. (when max-effort
  7068. (setq list (org-agenda-limit-entries
  7069. list 'effort-minutes max-effort
  7070. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7071. 32767 -1))))))
  7072. (when max-todo
  7073. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7074. (when max-tags
  7075. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7076. (when max-entries
  7077. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7078. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7079. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7080. (mapconcat #'identity list "\n")))
  7081. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7082. "Limit the number of agenda entries."
  7083. (let ((include (and limit (< limit 0))))
  7084. (if limit
  7085. (let ((fun (or fn (lambda (p) (when p 1))))
  7086. (lim 0))
  7087. (delq nil
  7088. (mapcar
  7089. (lambda (e)
  7090. (let ((pval (funcall
  7091. fun (get-text-property (1- (length e))
  7092. prop e))))
  7093. (when pval (setq lim (+ lim pval)))
  7094. (cond ((and pval (<= lim (abs limit))) e)
  7095. ((and include (not pval)) e))))
  7096. list)))
  7097. list)))
  7098. (defun org-agenda-limit-interactively (remove)
  7099. "In agenda, interactively limit entries to various maximums."
  7100. (interactive "P")
  7101. (if remove
  7102. (progn (setq org-agenda-max-entries nil
  7103. org-agenda-max-todos nil
  7104. org-agenda-max-tags nil
  7105. org-agenda-max-effort nil)
  7106. (org-agenda-redo))
  7107. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7108. (msg (cond ((= max ?E) "How many minutes? ")
  7109. ((= max ?e) "How many entries? ")
  7110. ((= max ?t) "How many TODO entries? ")
  7111. ((= max ?T) "How many tagged entries? ")
  7112. (t (user-error "Wrong input"))))
  7113. (num (string-to-number (read-from-minibuffer msg))))
  7114. (cond ((equal max ?e)
  7115. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7116. ((equal max ?t)
  7117. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7118. ((equal max ?T)
  7119. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7120. ((equal max ?E)
  7121. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7122. (org-agenda-fit-window-to-buffer))
  7123. (defun org-agenda-highlight-todo (x)
  7124. (let ((org-done-keywords org-done-keywords-for-agenda)
  7125. (case-fold-search nil)
  7126. re)
  7127. (if (eq x 'line)
  7128. (save-excursion
  7129. (beginning-of-line 1)
  7130. (setq re (org-get-at-bol 'org-todo-regexp))
  7131. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  7132. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7133. (add-text-properties (match-beginning 0) (match-end 1)
  7134. (list 'face (org-get-todo-face 1)))
  7135. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7136. (delete-region (match-beginning 1) (1- (match-end 0)))
  7137. (goto-char (match-beginning 1))
  7138. (insert (format org-agenda-todo-keyword-format s)))))
  7139. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7140. (setq re (get-text-property 0 'org-todo-regexp x))
  7141. (when (and re
  7142. ;; Test `pl' because if there's no heading content,
  7143. ;; there's no point matching to highlight. Note
  7144. ;; that if we didn't test `pl' first, and there
  7145. ;; happened to be no keyword from `org-todo-regexp'
  7146. ;; on this heading line, then the `equal' comparison
  7147. ;; afterwards would spuriously succeed in the case
  7148. ;; where `pl' is nil -- causing an args-out-of-range
  7149. ;; error when we try to add text properties to text
  7150. ;; that isn't there.
  7151. pl
  7152. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7153. x pl)
  7154. pl))
  7155. (add-text-properties
  7156. (or (match-end 1) (match-end 0)) (match-end 0)
  7157. (list 'face (org-get-todo-face (match-string 2 x)))
  7158. x)
  7159. (when (match-end 1)
  7160. (setq x
  7161. (concat
  7162. (substring x 0 (match-end 1))
  7163. (unless (string= org-agenda-todo-keyword-format "")
  7164. (format org-agenda-todo-keyword-format
  7165. (match-string 2 x)))
  7166. (unless (string= org-agenda-todo-keyword-format "")
  7167. ;; Remove `display' property as the icon could leak
  7168. ;; on the white space.
  7169. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7170. 'display)))
  7171. (substring x (match-end 3)))))))
  7172. x)))
  7173. (defsubst org-cmp-values (a b property)
  7174. "Compare the numeric value of text PROPERTY for string A and B."
  7175. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7176. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7177. (cond ((> pa pb) +1)
  7178. ((< pa pb) -1))))
  7179. (defsubst org-cmp-effort (a b)
  7180. "Compare the effort values of string A and B."
  7181. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7182. ;; `effort-minutes' property is not directly accessible from
  7183. ;; the strings, but is stored as a property in `txt'.
  7184. (ea (or (get-text-property
  7185. 0 'effort-minutes (get-text-property 0 'txt a))
  7186. def))
  7187. (eb (or (get-text-property
  7188. 0 'effort-minutes (get-text-property 0 'txt b))
  7189. def)))
  7190. (cond ((> ea eb) +1)
  7191. ((< ea eb) -1))))
  7192. (defsubst org-cmp-category (a b)
  7193. "Compare the string values of categories of strings A and B."
  7194. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7195. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7196. (cond ((string-lessp ca cb) -1)
  7197. ((string-lessp cb ca) +1))))
  7198. (defsubst org-cmp-todo-state (a b)
  7199. "Compare the todo states of strings A and B."
  7200. (let* ((ma (or (get-text-property 1 'org-marker a)
  7201. (get-text-property 1 'org-hd-marker a)))
  7202. (mb (or (get-text-property 1 'org-marker b)
  7203. (get-text-property 1 'org-hd-marker b)))
  7204. (fa (and ma (marker-buffer ma)))
  7205. (fb (and mb (marker-buffer mb)))
  7206. (todo-kwds
  7207. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7208. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7209. (ta (or (get-text-property 1 'todo-state a) ""))
  7210. (tb (or (get-text-property 1 'todo-state b) ""))
  7211. (la (- (length (member ta todo-kwds))))
  7212. (lb (- (length (member tb todo-kwds))))
  7213. (donepa (member ta org-done-keywords-for-agenda))
  7214. (donepb (member tb org-done-keywords-for-agenda)))
  7215. (cond ((and donepa (not donepb)) -1)
  7216. ((and (not donepa) donepb) +1)
  7217. ((< la lb) -1)
  7218. ((< lb la) +1))))
  7219. (defsubst org-cmp-alpha (a b)
  7220. "Compare the headlines, alphabetically."
  7221. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7222. (plb (text-property-any 0 (length b) 'org-heading t b))
  7223. (ta (and pla (substring a pla)))
  7224. (tb (and plb (substring b plb)))
  7225. (case-fold-search nil))
  7226. (when pla
  7227. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7228. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7229. ta)
  7230. (setq ta (substring ta (match-end 0))))
  7231. (setq ta (downcase ta)))
  7232. (when plb
  7233. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7234. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7235. tb)
  7236. (setq tb (substring tb (match-end 0))))
  7237. (setq tb (downcase tb)))
  7238. (cond ((not (or ta tb)) nil)
  7239. ((not ta) +1)
  7240. ((not tb) -1)
  7241. ((string-lessp ta tb) -1)
  7242. ((string-lessp tb ta) +1))))
  7243. (defsubst org-cmp-tag (a b)
  7244. "Compare the string values of the first tags of A and B."
  7245. (let ((ta (car (last (get-text-property 1 'tags a))))
  7246. (tb (car (last (get-text-property 1 'tags b)))))
  7247. (cond ((not (or ta tb)) nil)
  7248. ((not ta) +1)
  7249. ((not tb) -1)
  7250. ((string-lessp ta tb) -1)
  7251. ((string-lessp tb ta) +1))))
  7252. (defsubst org-cmp-time (a b)
  7253. "Compare the time-of-day values of strings A and B."
  7254. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7255. (ta (or (get-text-property 1 'time-of-day a) def))
  7256. (tb (or (get-text-property 1 'time-of-day b) def)))
  7257. (cond ((< ta tb) -1)
  7258. ((< tb ta) +1))))
  7259. (defsubst org-cmp-ts (a b type)
  7260. "Compare the timestamps values of entries A and B.
  7261. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7262. \"timestamp_ia\", compare within each of these type. When TYPE
  7263. is the empty string, compare all timestamps without respect of
  7264. their type."
  7265. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7266. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7267. (get-text-property 1 'ts-date a))
  7268. def))
  7269. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7270. (get-text-property 1 'ts-date b))
  7271. def)))
  7272. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7273. ((if tb (and ta (< tb ta)) ta) +1))))
  7274. (defsubst org-cmp-habit-p (a b)
  7275. "Compare the todo states of strings A and B."
  7276. (let ((ha (get-text-property 1 'org-habit-p a))
  7277. (hb (get-text-property 1 'org-habit-p b)))
  7278. (cond ((and ha (not hb)) -1)
  7279. ((and (not ha) hb) +1))))
  7280. (defun org-entries-lessp (a b)
  7281. "Predicate for sorting agenda entries."
  7282. ;; The following variables will be used when the form is evaluated.
  7283. ;; So even though the compiler complains, keep them.
  7284. (let ((ss org-agenda-sorting-strategy-selected))
  7285. (org-dlet
  7286. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7287. (org-cmp-ts a b "")))
  7288. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7289. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7290. (org-cmp-ts a b "scheduled")))
  7291. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7292. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7293. (org-cmp-ts a b "deadline")))
  7294. (deadline-down (if deadline-up (- deadline-up) nil))
  7295. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7296. (org-cmp-ts a b "timestamp_ia")))
  7297. (tsia-down (if tsia-up (- tsia-up) nil))
  7298. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7299. (org-cmp-ts a b "timestamp")))
  7300. (ts-down (if ts-up (- ts-up) nil))
  7301. (time-up (and (org-em 'time-up 'time-down ss)
  7302. (org-cmp-time a b)))
  7303. (time-down (if time-up (- time-up) nil))
  7304. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7305. (org-cmp-values a b 'org-stats)))
  7306. (stats-down (if stats-up (- stats-up) nil))
  7307. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7308. (org-cmp-values a b 'priority)))
  7309. (priority-down (if priority-up (- priority-up) nil))
  7310. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7311. (org-cmp-effort a b)))
  7312. (effort-down (if effort-up (- effort-up) nil))
  7313. (category-up (and (or (org-em 'category-up 'category-down ss)
  7314. (memq 'category-keep ss))
  7315. (org-cmp-category a b)))
  7316. (category-down (if category-up (- category-up) nil))
  7317. (category-keep (if category-up +1 nil))
  7318. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7319. (org-cmp-tag a b)))
  7320. (tag-down (if tag-up (- tag-up) nil))
  7321. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7322. (org-cmp-todo-state a b)))
  7323. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7324. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7325. (org-cmp-habit-p a b)))
  7326. (habit-down (if habit-up (- habit-up) nil))
  7327. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7328. (org-cmp-alpha a b)))
  7329. (alpha-down (if alpha-up (- alpha-up) nil))
  7330. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7331. user-defined-up user-defined-down)
  7332. (when (and need-user-cmp org-agenda-cmp-user-defined
  7333. (functionp org-agenda-cmp-user-defined))
  7334. (setq user-defined-up
  7335. (funcall org-agenda-cmp-user-defined a b)
  7336. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7337. (cdr (assoc
  7338. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7339. '((-1 . t) (1 . nil) (nil . nil)))))))
  7340. ;;; Agenda restriction lock
  7341. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7342. "Overlay to mark the headline to which agenda commands are restricted.")
  7343. (overlay-put org-agenda-restriction-lock-overlay
  7344. 'face 'org-agenda-restriction-lock)
  7345. (overlay-put org-agenda-restriction-lock-overlay
  7346. 'help-echo "Agendas are currently limited to this subtree.")
  7347. (delete-overlay org-agenda-restriction-lock-overlay)
  7348. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7349. "Set the restriction lock to the agenda item at point from within the agenda.
  7350. When called with a `\\[universal-argument]' prefix, restrict to
  7351. the file which contains the item.
  7352. Argument ARG is the prefix argument."
  7353. (interactive "P")
  7354. (unless (derived-mode-p 'org-agenda-mode)
  7355. (user-error "Not in an Org agenda buffer"))
  7356. (let* ((marker (or (org-get-at-bol 'org-marker)
  7357. (org-agenda-error)))
  7358. (buffer (marker-buffer marker))
  7359. (pos (marker-position marker)))
  7360. (with-current-buffer buffer
  7361. (goto-char pos)
  7362. (org-agenda-set-restriction-lock arg))))
  7363. ;;;###autoload
  7364. (defun org-agenda-set-restriction-lock (&optional type)
  7365. "Set restriction lock for agenda to current subtree or file.
  7366. When in a restricted subtree, remove it.
  7367. The restriction will span over the entire file if TYPE is `file',
  7368. or if TYPE is (4), or if the cursor is before the first headline
  7369. in the file. Otherwise, only apply the restriction to the current
  7370. subtree."
  7371. (interactive "P")
  7372. (if (and org-agenda-overriding-restriction
  7373. (member org-agenda-restriction-lock-overlay
  7374. (overlays-at (point)))
  7375. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7376. (point)))
  7377. (org-agenda-remove-restriction-lock 'noupdate)
  7378. (org-agenda-remove-restriction-lock 'noupdate)
  7379. (and (equal type '(4)) (setq type 'file))
  7380. (setq type (cond
  7381. (type type)
  7382. ((org-at-heading-p) 'subtree)
  7383. ((condition-case nil (org-back-to-heading t) (error nil))
  7384. 'subtree)
  7385. (t 'file)))
  7386. (if (eq type 'subtree)
  7387. (progn
  7388. (setq org-agenda-restrict (current-buffer))
  7389. (setq org-agenda-overriding-restriction 'subtree)
  7390. (put 'org-agenda-files 'org-restrict
  7391. (list (buffer-file-name (buffer-base-buffer))))
  7392. (org-back-to-heading t)
  7393. (move-overlay org-agenda-restriction-lock-overlay
  7394. (point)
  7395. (if org-agenda-restriction-lock-highlight-subtree
  7396. (save-excursion (org-end-of-subtree t t) (point))
  7397. (point-at-eol)))
  7398. (move-marker org-agenda-restrict-begin (point))
  7399. (move-marker org-agenda-restrict-end
  7400. (save-excursion (org-end-of-subtree t t)))
  7401. (message "Locking agenda restriction to subtree"))
  7402. (put 'org-agenda-files 'org-restrict
  7403. (list (buffer-file-name (buffer-base-buffer))))
  7404. (setq org-agenda-restrict nil)
  7405. (setq org-agenda-overriding-restriction 'file)
  7406. (move-marker org-agenda-restrict-begin nil)
  7407. (move-marker org-agenda-restrict-end nil)
  7408. (message "Locking agenda restriction to file"))
  7409. (setq current-prefix-arg nil))
  7410. (org-agenda-maybe-redo))
  7411. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7412. "Remove agenda restriction lock."
  7413. (interactive "P")
  7414. (if (not (or org-agenda-restrict org-agenda-overriding-restriction))
  7415. (message "No agenda restriction to remove.")
  7416. (delete-overlay org-agenda-restriction-lock-overlay)
  7417. (delete-overlay org-speedbar-restriction-lock-overlay)
  7418. (setq org-agenda-overriding-restriction nil)
  7419. (unless org-agenda-keep-restricted-file-list
  7420. ;; There is a request to keep the file list in place
  7421. (put 'org-agenda-files 'org-restrict nil))
  7422. (setq org-agenda-restrict nil)
  7423. (put 'org-agenda-files 'org-restrict nil)
  7424. (move-marker org-agenda-restrict-begin nil)
  7425. (move-marker org-agenda-restrict-end nil)
  7426. (setq current-prefix-arg nil)
  7427. (message "Agenda restriction lock removed")
  7428. (or noupdate (org-agenda-maybe-redo))))
  7429. (defun org-agenda-maybe-redo ()
  7430. "If there is any window showing the agenda view, update it."
  7431. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7432. org-agenda-buffer-name)
  7433. t))
  7434. (w0 (selected-window)))
  7435. (when w
  7436. (select-window w)
  7437. (org-agenda-redo)
  7438. (select-window w0)
  7439. (if org-agenda-overriding-restriction
  7440. (message "Agenda view shifted to new %s restriction"
  7441. org-agenda-overriding-restriction)
  7442. (message "Agenda restriction lock removed")))))
  7443. ;;; Agenda commands
  7444. (defun org-agenda-check-type (error &rest types)
  7445. "Check if agenda buffer or component is of allowed type.
  7446. If ERROR is non-nil, throw an error, otherwise just return nil.
  7447. Allowed types are `agenda' `todo' `tags' `search'."
  7448. (cond ((not org-agenda-type)
  7449. (error "No Org agenda currently displayed"))
  7450. ((memq org-agenda-type types) t)
  7451. (error
  7452. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7453. (t nil)))
  7454. (defun org-agenda-Quit ()
  7455. "Exit the agenda, killing the agenda buffer.
  7456. Like `org-agenda-quit', but kill the buffer even when
  7457. `org-agenda-sticky' is non-nil."
  7458. (interactive)
  7459. (org-agenda--quit))
  7460. (defun org-agenda-quit ()
  7461. "Exit the agenda.
  7462. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7463. instead of killing it.
  7464. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7465. the pre-agenda window configuration.
  7466. When column view is active, exit column view instead of the
  7467. agenda."
  7468. (interactive)
  7469. (org-agenda--quit org-agenda-sticky))
  7470. (defun org-agenda--quit (&optional bury)
  7471. (if org-agenda-columns-active
  7472. (org-columns-quit)
  7473. (let ((wconf org-agenda-pre-window-conf)
  7474. (buf (current-buffer))
  7475. (org-agenda-last-indirect-window
  7476. (and (eq org-indirect-buffer-display 'other-window)
  7477. org-agenda-last-indirect-buffer
  7478. (get-buffer-window org-agenda-last-indirect-buffer))))
  7479. (cond
  7480. ((eq org-agenda-window-setup 'other-frame)
  7481. (delete-frame))
  7482. ((eq org-agenda-window-setup 'other-tab)
  7483. (if (fboundp 'tab-bar-close-tab)
  7484. (tab-bar-close-tab)
  7485. (user-error "Your version of Emacs does not have tab bar mode support")))
  7486. ((and org-agenda-restore-windows-after-quit
  7487. wconf)
  7488. ;; Maybe restore the pre-agenda window configuration. Reset
  7489. ;; `org-agenda-pre-window-conf' before running
  7490. ;; `set-window-configuration', which loses the current buffer.
  7491. (setq org-agenda-pre-window-conf nil)
  7492. (set-window-configuration wconf))
  7493. (t
  7494. (when org-agenda-last-indirect-window
  7495. (delete-window org-agenda-last-indirect-window))
  7496. (and (not (eq org-agenda-window-setup 'current-window))
  7497. (not (one-window-p))
  7498. (delete-window))))
  7499. (if bury
  7500. ;; Set the agenda buffer as the current buffer instead of
  7501. ;; passing it as an argument to `bury-buffer' so that
  7502. ;; `bury-buffer' removes it from the window.
  7503. (with-current-buffer buf
  7504. (bury-buffer))
  7505. (kill-buffer buf)
  7506. (setq org-agenda-archives-mode nil
  7507. org-agenda-buffer nil)))))
  7508. (defun org-agenda-exit ()
  7509. "Exit the agenda, killing Org buffers loaded by the agenda.
  7510. Like `org-agenda-Quit', but kill any buffers that were created by
  7511. the agenda. Org buffers visited directly by the user will not be
  7512. touched. Also, exit the agenda even if it is in column view."
  7513. (interactive)
  7514. (when org-agenda-columns-active
  7515. (org-columns-quit))
  7516. (org-release-buffers org-agenda-new-buffers)
  7517. (setq org-agenda-new-buffers nil)
  7518. (org-agenda-Quit))
  7519. (defun org-agenda-kill-all-agenda-buffers ()
  7520. "Kill all buffers in `org-agenda-mode'.
  7521. This is used when toggling sticky agendas."
  7522. (interactive)
  7523. (let (blist)
  7524. (dolist (buf (buffer-list))
  7525. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7526. (push buf blist)))
  7527. (mapc #'kill-buffer blist)))
  7528. (defun org-agenda-execute (arg)
  7529. "Execute another agenda command, keeping same window.
  7530. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7531. in the agenda."
  7532. (interactive "P")
  7533. (let ((org-agenda-window-setup 'current-window))
  7534. (org-agenda arg)))
  7535. (defun org-agenda-redo (&optional all)
  7536. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7537. (interactive "P")
  7538. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7539. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7540. (cpa (unless (eq all t) current-prefix-arg))
  7541. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7542. (org-agenda-sticky nil)
  7543. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7544. org-agenda-buffer-name))
  7545. (org-agenda-keep-modes t)
  7546. (tag-filter org-agenda-tag-filter)
  7547. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7548. (top-hl-filter org-agenda-top-headline-filter)
  7549. (cat-filter org-agenda-category-filter)
  7550. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7551. (re-filter org-agenda-regexp-filter)
  7552. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7553. (effort-filter org-agenda-effort-filter)
  7554. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7555. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7556. (cols org-agenda-columns-active)
  7557. (line (org-current-line))
  7558. (window-line (- line (org-current-line (window-start))))
  7559. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7560. (redo-cmd (get-text-property p 'org-redo-cmd))
  7561. (last-args (get-text-property p 'org-last-args))
  7562. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7563. (org-agenda-overriding-cmd-arguments
  7564. (unless (eq all t)
  7565. (cond ((listp last-args)
  7566. (cons (or cpa (car last-args)) (cdr last-args)))
  7567. ((stringp last-args)
  7568. last-args))))
  7569. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7570. (put 'org-agenda-tag-filter :preset-filter nil)
  7571. (put 'org-agenda-category-filter :preset-filter nil)
  7572. (put 'org-agenda-regexp-filter :preset-filter nil)
  7573. (put 'org-agenda-effort-filter :preset-filter nil)
  7574. (and cols (org-columns-quit))
  7575. (message "Rebuilding agenda buffer...")
  7576. (if series-redo-cmd
  7577. (eval series-redo-cmd t)
  7578. (cl-progv
  7579. (mapcar #'car lprops)
  7580. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7581. (eval redo-cmd t)))
  7582. (setq org-agenda-undo-list nil
  7583. org-agenda-pending-undo-list nil
  7584. org-agenda-tag-filter tag-filter
  7585. org-agenda-category-filter cat-filter
  7586. org-agenda-regexp-filter re-filter
  7587. org-agenda-effort-filter effort-filter
  7588. org-agenda-top-headline-filter top-hl-filter)
  7589. (message "Rebuilding agenda buffer...done")
  7590. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7591. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7592. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7593. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7594. (let ((tag (or tag-filter tag-preset))
  7595. (cat (or cat-filter cat-preset))
  7596. (effort (or effort-filter effort-preset))
  7597. (re (or re-filter re-preset)))
  7598. (when tag (org-agenda-filter-apply tag 'tag t))
  7599. (when cat (org-agenda-filter-apply cat 'category))
  7600. (when effort (org-agenda-filter-apply effort 'effort))
  7601. (when re (org-agenda-filter-apply re 'regexp)))
  7602. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7603. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7604. (org-goto-line line)
  7605. (when (called-interactively-p 'any) (recenter window-line))))
  7606. (defun org-agenda-redo-all (&optional exhaustive)
  7607. "Rebuild all agenda views in the current buffer.
  7608. With a prefix argument, do so in all agenda buffers."
  7609. (interactive "P")
  7610. (if exhaustive
  7611. (dolist (buffer (buffer-list))
  7612. (with-current-buffer buffer
  7613. (when (derived-mode-p 'org-agenda-mode)
  7614. (org-agenda-redo t))))
  7615. (org-agenda-redo t)))
  7616. (defvar org-global-tags-completion-table nil)
  7617. (defvar org-agenda-filter-form nil)
  7618. (defvar org-agenda-filtered-by-category nil)
  7619. (defsubst org-agenda-get-category ()
  7620. "Return the category of the agenda line."
  7621. (org-get-at-bol 'org-category))
  7622. (defun org-agenda-filter-by-category (strip)
  7623. "Filter lines in the agenda buffer that have a specific category.
  7624. The category is that of the current line.
  7625. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7626. When there is already a category filter in place, this command removes the
  7627. filter."
  7628. (interactive "P")
  7629. (if (and org-agenda-filtered-by-category
  7630. org-agenda-category-filter)
  7631. (org-agenda-filter-show-all-cat)
  7632. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7633. (cond
  7634. ((and cat strip)
  7635. (org-agenda-filter-apply
  7636. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7637. (cat
  7638. (org-agenda-filter-apply
  7639. (setq org-agenda-category-filter
  7640. (list (concat "+" cat)))
  7641. 'category))
  7642. (t (error "No category at point"))))))
  7643. (defun org-find-top-headline (&optional pos)
  7644. "Find the topmost parent headline and return it.
  7645. POS when non-nil is the marker or buffer position to start the
  7646. search from."
  7647. (save-excursion
  7648. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7649. (when pos (goto-char pos))
  7650. ;; Skip up to the topmost parent.
  7651. (while (org-up-heading-safe))
  7652. (ignore-errors
  7653. (replace-regexp-in-string
  7654. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7655. (nth 4 (org-heading-components)))))))
  7656. (defvar org-agenda-filtered-by-top-headline nil)
  7657. (defun org-agenda-filter-by-top-headline (strip)
  7658. "Keep only those lines that are descendants from the same top headline.
  7659. The top headline is that of the current line. With prefix arg STRIP, hide
  7660. all lines of the category at point."
  7661. (interactive "P")
  7662. (if org-agenda-filtered-by-top-headline
  7663. (progn
  7664. (setq org-agenda-filtered-by-top-headline nil
  7665. org-agenda-top-headline-filter nil)
  7666. (org-agenda-filter-show-all-top-filter))
  7667. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7668. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7669. (error "No top-level headline at point")))))
  7670. (defvar org-agenda-regexp-filter nil)
  7671. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7672. "Filter agenda entries by a regular expressions.
  7673. You will be prompted for the regular expression, and the agenda
  7674. view will only show entries that are matched by that expression.
  7675. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7676. When there is already a regexp filter active, this command removed the
  7677. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7678. an already existing regexp filter."
  7679. (interactive "P")
  7680. (let* ((strip (equal strip-or-accumulate '(4)))
  7681. (accumulate (equal strip-or-accumulate '(16))))
  7682. (cond
  7683. ((and org-agenda-regexp-filter (not accumulate))
  7684. (org-agenda-filter-show-all-re)
  7685. (message "Regexp filter removed"))
  7686. (t (let ((flt (concat (if strip "-" "+")
  7687. (read-from-minibuffer
  7688. (if strip
  7689. "Hide entries matching regexp: "
  7690. "Narrow to entries matching regexp: ")))))
  7691. (push flt org-agenda-regexp-filter)
  7692. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7693. (defvar org-agenda-effort-filter nil)
  7694. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7695. "Filter agenda entries by effort.
  7696. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7697. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7698. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7699. This last option is in practice not very useful, but it is available for
  7700. consistency with the other filter commands."
  7701. (interactive "P")
  7702. (let* ((efforts (split-string
  7703. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7704. org-global-properties
  7705. t))
  7706. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7707. ;; XXX: the following handles only up to 10 different
  7708. ;; effort values.
  7709. (allowed-keys (if (null efforts) nil
  7710. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7711. (number-sequence 1 (length efforts)))))
  7712. (keep (equal strip-or-accumulate '(16)))
  7713. (negative (equal strip-or-accumulate '(4)))
  7714. (current org-agenda-effort-filter)
  7715. (op nil))
  7716. (while (not (memq op '(?< ?> ?= ?_)))
  7717. (setq op (read-char-exclusive
  7718. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7719. ;; Select appropriate duration. Ignore non-digit characters.
  7720. (if (eq op ?_)
  7721. (progn
  7722. (org-agenda-filter-show-all-effort)
  7723. (message "Effort filter removed"))
  7724. (let ((prompt
  7725. (apply #'format
  7726. (concat "Effort %c "
  7727. (mapconcat (lambda (s) (concat "[%d]" s))
  7728. efforts
  7729. " "))
  7730. op allowed-keys))
  7731. (eff -1))
  7732. (while (not (memq eff allowed-keys))
  7733. (message prompt)
  7734. (setq eff (- (read-char-exclusive) 48)))
  7735. (org-agenda-filter-show-all-effort)
  7736. (setq org-agenda-effort-filter
  7737. (append
  7738. (list (concat (if negative "-" "+")
  7739. (char-to-string op)
  7740. ;; Numbering is 1 2 3 ... 9 0, but we want
  7741. ;; 0 1 2 ... 8 9.
  7742. (nth (mod (1- eff) 10) efforts)))
  7743. (if keep current nil)))
  7744. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7745. (defun org-agenda-filter (&optional strip-or-accumulate)
  7746. "Prompt for a general filter string and apply it to the agenda.
  7747. The string may contain filter elements like
  7748. +category
  7749. +tag
  7750. +<effort > and = are also allowed as effort operators
  7751. +/regexp/
  7752. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7753. `+' is optional if it is not required to separate two string parts.
  7754. Multiple filter elements can be concatenated without spaces, for example
  7755. +work-John<0:10-/plot/
  7756. selects entries with category `work' and effort estimates below 10 minutes,
  7757. and deselects entries with tag `John' or matching the regexp `plot'.
  7758. During entry of the filter, completion for tags, categories and effort
  7759. values is offered. Since the syntax for categories and tags is identical
  7760. there should be no overlap between categories and tags. If there is, tags
  7761. get priority.
  7762. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7763. entire filter, which can be useful in connection with the prompt history.
  7764. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7765. existing ones. A shortcut for this is to add an additional `+' at the
  7766. beginning of the string, like `+-John'.
  7767. With a triple prefix argument, execute the computed filtering defined in
  7768. the variable `org-agenda-auto-exclude-function'."
  7769. (interactive "P")
  7770. (if (equal strip-or-accumulate '(64))
  7771. ;; Execute the auto-exclude action
  7772. (if (not org-agenda-auto-exclude-function)
  7773. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7774. (org-agenda-filter-show-all-tag)
  7775. (setq org-agenda-tag-filter nil)
  7776. (dolist (tag (org-agenda-get-represented-tags))
  7777. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7778. (when modifier
  7779. (push modifier org-agenda-tag-filter))))
  7780. (unless (null org-agenda-tag-filter)
  7781. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7782. ;; Prompt for a filter and act
  7783. (let* ((tag-list (org-agenda-get-represented-tags))
  7784. (category-list (org-agenda-get-represented-categories))
  7785. (negate (equal strip-or-accumulate '(4)))
  7786. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7787. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7788. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7789. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7790. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7791. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7792. (f-string (completing-read
  7793. (concat
  7794. (if negate "Negative filter" "Filter")
  7795. " [+cat-tag<0:10-/regexp/]: ")
  7796. #'org-agenda-filter-completion-function
  7797. nil nil ff))
  7798. (keep (or (if (string-match "^\\+[+-]" f-string)
  7799. (progn (setq f-string (substring f-string 1)) t))
  7800. (equal strip-or-accumulate '(16))))
  7801. (fc (if keep org-agenda-category-filter))
  7802. (ft (if keep org-agenda-tag-filter))
  7803. (fe (if keep org-agenda-effort-filter))
  7804. (fr (if keep org-agenda-regexp-filter))
  7805. pm s)
  7806. ;; If the filter contains a double-quoted string, replace a
  7807. ;; single hyphen by the arbitrary and temporary string "~~~"
  7808. ;; to disambiguate such hyphens from syntactic ones.
  7809. (setq f-string (replace-regexp-in-string
  7810. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7811. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7812. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7813. (when negate
  7814. (setq pm (if (equal pm "+") "-" "+")))
  7815. (cond
  7816. ((match-beginning 3)
  7817. ;; category or tag
  7818. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7819. "~~~" "-" (match-string 3 f-string)))
  7820. (cond
  7821. ((member s tag-list)
  7822. (org-pushnew-to-end (concat pm s) ft))
  7823. ((member s category-list)
  7824. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7825. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7826. fc))
  7827. (t (message
  7828. "`%s%s' filter ignored because tag/category is not represented"
  7829. pm s))))
  7830. ((match-beginning 4)
  7831. ;; effort
  7832. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7833. ((match-beginning 5)
  7834. ;; regexp
  7835. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7836. (setq f-string (substring f-string (match-end 0))))
  7837. (org-agenda-filter-remove-all)
  7838. (and fc (org-agenda-filter-apply
  7839. (setq org-agenda-category-filter fc) 'category))
  7840. (and ft (org-agenda-filter-apply
  7841. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7842. (and fe (org-agenda-filter-apply
  7843. (setq org-agenda-effort-filter fe) 'effort))
  7844. (and fr (org-agenda-filter-apply
  7845. (setq org-agenda-regexp-filter fr) 'regexp))
  7846. (run-hooks 'org-agenda-filter-hook))))
  7847. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7848. "Complete a complex filter string.
  7849. FLAG specifies the type of completion operation to perform. This
  7850. function is passed as a collection function to `completing-read',
  7851. which see."
  7852. (let ((completion-ignore-case t) ;tags are case-sensitive
  7853. (confirm (lambda (x) (stringp x)))
  7854. (prefix "")
  7855. (operator "")
  7856. table)
  7857. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7858. (setq prefix (match-string 1 string)
  7859. operator (match-string 2 string)
  7860. string (match-string 3 string)))
  7861. (cond
  7862. ((member operator '("+" "-" "" nil))
  7863. (setq table (append (org-agenda-get-represented-categories)
  7864. (org-agenda-get-represented-tags))))
  7865. ((member operator '("<" ">" "="))
  7866. (setq table (split-string
  7867. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7868. org-global-properties
  7869. t))
  7870. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7871. " +")))
  7872. (t (setq table nil)))
  7873. (pcase flag
  7874. (`t (all-completions string table confirm))
  7875. (`lambda (assoc string table)) ;exact match?
  7876. (`nil
  7877. (pcase (try-completion string table confirm)
  7878. ((and completion (pred stringp))
  7879. (concat prefix completion))
  7880. (completion completion)))
  7881. (_ nil))))
  7882. (defun org-agenda-filter-remove-all ()
  7883. "Remove all filters from the current agenda buffer."
  7884. (interactive)
  7885. (when org-agenda-tag-filter
  7886. (org-agenda-filter-show-all-tag))
  7887. (when org-agenda-category-filter
  7888. (org-agenda-filter-show-all-cat))
  7889. (when org-agenda-regexp-filter
  7890. (org-agenda-filter-show-all-re))
  7891. (when org-agenda-top-headline-filter
  7892. (org-agenda-filter-show-all-top-filter))
  7893. (when org-agenda-effort-filter
  7894. (org-agenda-filter-show-all-effort))
  7895. (org-agenda-finalize)
  7896. (when (called-interactively-p 'interactive)
  7897. (message "All agenda filters removed")))
  7898. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7899. "Keep only those lines in the agenda buffer that have a specific tag.
  7900. The tag is selected with its fast selection letter, as configured.
  7901. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7902. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7903. instead of replacing it.
  7904. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7905. i.e. don't
  7906. filter on all its group members.
  7907. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7908. should be used to exclude the search - the interactive user can
  7909. also press `-' or `+' to switch between filtering and excluding."
  7910. (interactive "P")
  7911. (let* ((alist org-tag-alist-for-agenda)
  7912. (seen-chars nil)
  7913. (tag-chars (mapconcat
  7914. (lambda (x) (if (and (not (symbolp (car x)))
  7915. (cdr x)
  7916. (not (member (cdr x) seen-chars)))
  7917. (progn
  7918. (push (cdr x) seen-chars)
  7919. (char-to-string (cdr x)))
  7920. ""))
  7921. org-tag-alist-for-agenda ""))
  7922. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7923. (string-to-list tag-chars)))
  7924. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7925. (accumulate (equal strip-or-accumulate '(16)))
  7926. (expand (not (equal strip-or-accumulate '(64))))
  7927. (inhibit-read-only t)
  7928. (current org-agenda-tag-filter)
  7929. a tag) ;; n
  7930. (unless char
  7931. (while (not (memq char valid-char-list))
  7932. (org-unlogged-message
  7933. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7934. (if exclude "Exclude[+]" "Filter[-]")
  7935. (if expand "" " (no grouptag expand)")
  7936. tag-chars
  7937. (if org-agenda-auto-exclude-function "[RET] " ""))
  7938. (setq char (read-char-exclusive))
  7939. ;; Excluding or filtering down
  7940. (cond ((eq char ?-) (setq exclude t))
  7941. ((eq char ?+) (setq exclude nil)))))
  7942. (when (eq char ?\t)
  7943. (unless (local-variable-p 'org-global-tags-completion-table)
  7944. (setq-local org-global-tags-completion-table
  7945. (org-global-tags-completion-table)))
  7946. (let ((completion-ignore-case t))
  7947. (setq tag (completing-read
  7948. "Tag: " org-global-tags-completion-table nil t))))
  7949. (cond
  7950. ((eq char ?\r)
  7951. (org-agenda-filter-show-all-tag)
  7952. (when org-agenda-auto-exclude-function
  7953. (setq org-agenda-tag-filter nil)
  7954. (dolist (tag (org-agenda-get-represented-tags))
  7955. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7956. (when modifier
  7957. (push modifier org-agenda-tag-filter))))
  7958. (unless (null org-agenda-tag-filter)
  7959. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7960. ((eq char ?\\)
  7961. (org-agenda-filter-show-all-tag)
  7962. (when (get 'org-agenda-tag-filter :preset-filter)
  7963. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7964. ((eq char ?.)
  7965. (setq org-agenda-tag-filter
  7966. (mapcar (lambda(tag) (concat "+" tag))
  7967. (org-get-at-bol 'tags)))
  7968. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7969. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7970. ((or (eq char ?\s)
  7971. (setq a (rassoc char alist))
  7972. (and tag (setq a (cons tag nil))))
  7973. (org-agenda-filter-show-all-tag)
  7974. (setq tag (car a))
  7975. (setq org-agenda-tag-filter
  7976. (cons (concat (if exclude "-" "+") tag)
  7977. (if accumulate current nil)))
  7978. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7979. (t (error "Invalid tag selection character %c" char)))))
  7980. (defun org-agenda-get-represented-categories ()
  7981. "Return a list of all categories used in this agenda buffer."
  7982. (or org-agenda-represented-categories
  7983. (when (derived-mode-p 'org-agenda-mode)
  7984. (let ((pos (point-min)) categories)
  7985. (while (and (< pos (point-max))
  7986. (setq pos (next-single-property-change
  7987. pos 'org-category nil (point-max))))
  7988. (push (get-text-property pos 'org-category) categories))
  7989. (setq org-agenda-represented-categories
  7990. ;; Enclose category names with a hyphen in double
  7991. ;; quotes to process them specially in `org-agenda-filter'.
  7992. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7993. (nreverse (org-uniquify (delq nil categories)))))))))
  7994. (defvar org-tag-groups-alist-for-agenda)
  7995. (defun org-agenda-get-represented-tags ()
  7996. "Return a list of all tags used in this agenda buffer.
  7997. These will be lower-case, for filtering."
  7998. (or org-agenda-represented-tags
  7999. (when (derived-mode-p 'org-agenda-mode)
  8000. (let ((pos (point-min)) tags-lists tt)
  8001. (while (and (< pos (point-max))
  8002. (setq pos (next-single-property-change
  8003. pos 'tags nil (point-max))))
  8004. (setq tt (get-text-property pos 'tags))
  8005. (if tt (push tt tags-lists)))
  8006. (setq tags-lists
  8007. (nreverse (org-uniquify
  8008. (delq nil (apply #'append tags-lists)))))
  8009. (dolist (tag tags-lists)
  8010. (mapc
  8011. (lambda (group)
  8012. (when (member tag group)
  8013. (push (car group) tags-lists)))
  8014. org-tag-groups-alist-for-agenda))
  8015. (setq org-agenda-represented-tags tags-lists)))))
  8016. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  8017. "Create the form that tests a line for agenda filter.
  8018. Optional argument EXPAND can be used for the TYPE tag and will
  8019. expand the tags in the FILTER if any of the tags in FILTER are
  8020. grouptags."
  8021. (let ((multi-pos-cats
  8022. (and (eq type 'category)
  8023. (string-match-p "\\+.*\\+"
  8024. (mapconcat (lambda (cat) (substring cat 0 1))
  8025. filter ""))))
  8026. f f1)
  8027. (cond
  8028. ;; Tag filter
  8029. ((eq type 'tag)
  8030. (setq filter
  8031. (delete-dups
  8032. (append (get 'org-agenda-tag-filter :preset-filter)
  8033. filter)))
  8034. (dolist (x filter)
  8035. (let ((op (string-to-char x)))
  8036. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8037. (setq x (list x)))
  8038. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8039. (push f1 f))))
  8040. ;; Category filter
  8041. ((eq type 'category)
  8042. (setq filter
  8043. (delete-dups
  8044. (append (get 'org-agenda-category-filter :preset-filter)
  8045. filter)))
  8046. (dolist (x filter)
  8047. (if (equal "-" (substring x 0 1))
  8048. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8049. (setq f1 (list 'equal (substring x 1) 'cat)))
  8050. (push f1 f)))
  8051. ;; Regexp filter
  8052. ((eq type 'regexp)
  8053. (setq filter
  8054. (delete-dups
  8055. (append (get 'org-agenda-regexp-filter :preset-filter)
  8056. filter)))
  8057. (dolist (x filter)
  8058. (if (equal "-" (substring x 0 1))
  8059. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8060. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8061. (push f1 f)))
  8062. ;; Effort filter
  8063. ((eq type 'effort)
  8064. (setq filter
  8065. (delete-dups
  8066. (append (get 'org-agenda-effort-filter :preset-filter)
  8067. filter)))
  8068. (dolist (x filter)
  8069. (push (org-agenda-filter-effort-form x) f))))
  8070. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8071. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8072. "Return a form associated to tag-expression TAGS.
  8073. Build a form testing a line for agenda filter for
  8074. tag-expressions. OP is an operator of type CHAR that allows the
  8075. function to set the right switches in the returned form."
  8076. (let (form)
  8077. ;; Any of the expressions can match if OP is +, all must match if
  8078. ;; the operator is -.
  8079. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8080. (let* ((tag (substring x 1))
  8081. (f (cond
  8082. ((string= "" tag) 'tags)
  8083. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8084. ;; TAG is a regexp.
  8085. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8086. (t (list 'member tag 'tags)))))
  8087. (push (if (eq op ?-) (list 'not f) f) form)))))
  8088. (defun org-agenda-filter-effort-form (e)
  8089. "Return the form to compare the effort of the current line with what E says.
  8090. E looks like \"+<2:25\"."
  8091. (let (op)
  8092. (setq e (substring e 1))
  8093. (setq op (string-to-char e) e (substring e 1))
  8094. (setq op (cond ((equal op ?<) '<=)
  8095. ((equal op ?>) '>=)
  8096. ((equal op ??) op)
  8097. (t '=)))
  8098. (list 'org-agenda-compare-effort (list 'quote op)
  8099. (org-duration-to-minutes e))))
  8100. (defun org-agenda-compare-effort (op value)
  8101. "Compare the effort of the current line with VALUE, using OP.
  8102. If the line does not have an effort defined, return nil."
  8103. ;; `effort-minutes' property cannot be extracted directly from
  8104. ;; current line but is stored as a property in `txt'.
  8105. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8106. (funcall op
  8107. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8108. value)))
  8109. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8110. "Expand group tags in FILTER for the agenda.
  8111. When NO-OPERATOR is non-nil, do not add the + operator to
  8112. returned tags."
  8113. (if org-group-tags
  8114. (let (case-fold-search rtn)
  8115. (mapc
  8116. (lambda (f)
  8117. (let (f0 dir)
  8118. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8119. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8120. (setq dir (if no-operator "" "+") f0 f))
  8121. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8122. (org-tags-expand f0 t))
  8123. rtn))))
  8124. filter)
  8125. (reverse rtn))
  8126. filter))
  8127. (defun org-agenda-filter-apply (filter type &optional expand)
  8128. "Set FILTER as the new agenda filter and apply it.
  8129. Optional argument EXPAND can be used for the TYPE tag and will
  8130. expand the tags in the FILTER if any of the tags in FILTER are
  8131. grouptags."
  8132. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8133. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8134. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8135. filter type expand))
  8136. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8137. ;; category is used as the filter:
  8138. (setq org-agenda-filtered-by-category
  8139. (and (eq type 'category)
  8140. (not (equal (substring (car filter) 0 1) "-"))))
  8141. (org-agenda-set-mode-name)
  8142. (save-excursion
  8143. (goto-char (point-min))
  8144. (while (not (eobp))
  8145. (when (or (org-get-at-bol 'org-hd-marker)
  8146. (org-get-at-bol 'org-marker))
  8147. (org-dlet
  8148. ((tags (org-get-at-bol 'tags))
  8149. (cat (org-agenda-get-category))
  8150. (txt (or (org-get-at-bol 'txt) "")))
  8151. (unless (eval org-agenda-filter-form t)
  8152. (org-agenda-filter-hide-line type))))
  8153. (beginning-of-line 2)))
  8154. (when (get-char-property (point) 'invisible)
  8155. (ignore-errors (org-agenda-previous-line))))
  8156. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8157. "Filter by top headline HL."
  8158. (org-agenda-set-mode-name)
  8159. (save-excursion
  8160. (goto-char (point-min))
  8161. (while (not (eobp))
  8162. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8163. (tophl (and pos (org-find-top-headline pos))))
  8164. (when (and tophl (funcall (if negative 'identity 'not)
  8165. (string= hl tophl)))
  8166. (org-agenda-filter-hide-line 'top-headline)))
  8167. (beginning-of-line 2)))
  8168. (when (get-char-property (point) 'invisible)
  8169. (org-agenda-previous-line))
  8170. (setq org-agenda-top-headline-filter hl
  8171. org-agenda-filtered-by-top-headline t))
  8172. (defun org-agenda-filter-hide-line (type)
  8173. "If current line is TYPE, hide it in the agenda buffer."
  8174. (let* (buffer-invisibility-spec
  8175. (beg (max (point-min) (1- (point-at-bol))))
  8176. (end (point-at-eol)))
  8177. (let ((inhibit-read-only t))
  8178. (add-text-properties
  8179. beg end `(invisible org-filtered org-filter-type ,type)))))
  8180. (defun org-agenda-remove-filter (type)
  8181. "Remove filter of type TYPE from the agenda buffer."
  8182. (interactive)
  8183. (save-excursion
  8184. (goto-char (point-min))
  8185. (let ((inhibit-read-only t) pos)
  8186. (while (setq pos (text-property-any (point) (point-max)
  8187. 'org-filter-type type))
  8188. (goto-char pos)
  8189. (remove-text-properties
  8190. (point) (next-single-property-change (point) 'org-filter-type)
  8191. `(invisible org-filtered org-filter-type ,type))))
  8192. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8193. (setq org-agenda-filter-form nil)
  8194. (org-agenda-set-mode-name)
  8195. (org-agenda-finalize)))
  8196. (defun org-agenda-filter-show-all-tag nil
  8197. (org-agenda-remove-filter 'tag))
  8198. (defun org-agenda-filter-show-all-re nil
  8199. (org-agenda-remove-filter 'regexp))
  8200. (defun org-agenda-filter-show-all-effort nil
  8201. (org-agenda-remove-filter 'effort))
  8202. (defun org-agenda-filter-show-all-cat nil
  8203. (org-agenda-remove-filter 'category))
  8204. (defun org-agenda-filter-show-all-top-filter nil
  8205. (org-agenda-remove-filter 'top-headline))
  8206. (defun org-agenda-manipulate-query-add ()
  8207. "Manipulate the query by adding a search term with positive selection.
  8208. Positive selection means the term must be matched for selection of an entry."
  8209. (interactive)
  8210. (org-agenda-manipulate-query ?\[))
  8211. (defun org-agenda-manipulate-query-subtract ()
  8212. "Manipulate the query by adding a search term with negative selection.
  8213. Negative selection means term must not be matched for selection of an entry."
  8214. (interactive)
  8215. (org-agenda-manipulate-query ?\]))
  8216. (defun org-agenda-manipulate-query-add-re ()
  8217. "Manipulate the query by adding a search regexp with positive selection.
  8218. Positive selection means the regexp must match for selection of an entry."
  8219. (interactive)
  8220. (org-agenda-manipulate-query ?\{))
  8221. (defun org-agenda-manipulate-query-subtract-re ()
  8222. "Manipulate the query by adding a search regexp with negative selection.
  8223. Negative selection means regexp must not match for selection of an entry."
  8224. (interactive)
  8225. (org-agenda-manipulate-query ?\}))
  8226. (defun org-agenda-manipulate-query (char)
  8227. (cond
  8228. ((eq org-agenda-type 'agenda)
  8229. (let ((org-agenda-include-inactive-timestamps t))
  8230. (org-agenda-redo))
  8231. (message "Display now includes inactive timestamps as well"))
  8232. ((eq org-agenda-type 'search)
  8233. (org-add-to-string
  8234. 'org-agenda-query-string
  8235. (if org-agenda-last-search-view-search-was-boolean
  8236. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8237. (?\{ . " +{}") (?\} . " -{}"))))
  8238. " "))
  8239. (setq org-agenda-redo-command
  8240. (list 'org-search-view
  8241. (car (get-text-property (min (1- (point-max)) (point))
  8242. 'org-last-args))
  8243. org-agenda-query-string
  8244. (+ (length org-agenda-query-string)
  8245. (if (member char '(?\{ ?\})) 0 1))))
  8246. (set-register org-agenda-query-register org-agenda-query-string)
  8247. (let ((org-agenda-overriding-arguments
  8248. (cdr org-agenda-redo-command)))
  8249. (org-agenda-redo)))
  8250. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8251. org-agenda-type))))
  8252. (defun org-add-to-string (var string)
  8253. (set var (concat (symbol-value var) string)))
  8254. (defun org-agenda-goto-date (date)
  8255. "Jump to DATE in the agenda buffer.
  8256. When called interactively, prompt for the date.
  8257. When called from Lisp, DATE should be a date as returned by
  8258. `org-read-date'.
  8259. See also:
  8260. `org-agenda-earlier' (\\[org-agenda-earlier])
  8261. `org-agenda-later' (\\[org-agenda-later])
  8262. `org-agenda-goto-today' (\\[org-agenda-goto-today])"
  8263. (interactive
  8264. (list
  8265. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8266. (org-read-date))))
  8267. (let* ((day (time-to-days (org-time-string-to-time date)))
  8268. (org-agenda-sticky-orig org-agenda-sticky)
  8269. (org-agenda-buffer-tmp-name (buffer-name))
  8270. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8271. (0-arg (or current-prefix-arg (car args)))
  8272. (2-arg (nth 2 args))
  8273. (with-hour-p (nth 4 org-agenda-redo-command))
  8274. (newcmd (list 'org-agenda-list 0-arg date
  8275. (org-agenda-span-to-ndays
  8276. 2-arg (org-time-string-to-absolute date))
  8277. with-hour-p))
  8278. (newargs (cdr newcmd))
  8279. (inhibit-read-only t)
  8280. org-agenda-sticky)
  8281. (if (not (org-agenda-check-type t 'agenda))
  8282. (error "Not available in non-agenda views")
  8283. (add-text-properties (point-min) (point-max)
  8284. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8285. (org-agenda-redo)
  8286. (goto-char (point-min))
  8287. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8288. (save-excursion (move-beginning-of-line 2) (eobp))))
  8289. (move-beginning-of-line 2))
  8290. (setq org-agenda-sticky org-agenda-sticky-orig
  8291. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8292. (defun org-agenda-goto-today ()
  8293. "Go to today's date in the agenda buffer.
  8294. See also:
  8295. `org-agenda-later' (\\[org-agenda-later])
  8296. `org-agenda-earlier' (\\[org-agenda-earlier])
  8297. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8298. (interactive)
  8299. (org-agenda-check-type t 'agenda)
  8300. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8301. (curspan (nth 2 args))
  8302. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8303. (cond
  8304. (tdpos (goto-char tdpos))
  8305. ((eq org-agenda-type 'agenda)
  8306. (let* ((sd (org-agenda-compute-starting-span
  8307. (org-today) (or curspan org-agenda-span)))
  8308. (org-agenda-overriding-arguments args))
  8309. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8310. (org-agenda-redo)
  8311. (org-agenda-find-same-or-today-or-agenda)))
  8312. (t (error "Cannot find today")))))
  8313. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8314. (goto-char
  8315. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8316. (text-property-any (point-min) (point-max) 'org-today t)
  8317. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8318. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8319. (org-agenda-backward-block))
  8320. (point-min))))
  8321. (defun org-agenda-backward-block ()
  8322. "Move backward by one agenda block."
  8323. (interactive)
  8324. (org-agenda-forward-block 'backward))
  8325. (defun org-agenda-forward-block (&optional backward)
  8326. "Move forward by one agenda block.
  8327. When optional argument BACKWARD is set, go backward."
  8328. (interactive)
  8329. (cond ((not (derived-mode-p 'org-agenda-mode))
  8330. (user-error
  8331. "Cannot execute this command outside of org-agenda-mode buffers"))
  8332. ((looking-at (if backward "\\`" "\\'"))
  8333. (message "Already at the %s block" (if backward "first" "last")))
  8334. (t (let ((_pos (prog1 (point)
  8335. (ignore-errors (if backward (backward-char 1)
  8336. (move-end-of-line 1)))))
  8337. (f (if backward
  8338. #'previous-single-property-change
  8339. #'next-single-property-change))
  8340. moved dest)
  8341. (while (and (setq dest (funcall
  8342. f (point) 'org-agenda-structural-header))
  8343. (not (get-text-property
  8344. (point) 'org-agenda-structural-header)))
  8345. (setq moved t)
  8346. (goto-char dest))
  8347. (if moved (move-beginning-of-line 1)
  8348. (goto-char (if backward (point-min) (point-max)))
  8349. (move-beginning-of-line 1)
  8350. (message "No %s block" (if backward "previous" "further")))))))
  8351. (defun org-agenda-later (arg)
  8352. "Go forward in time by the current span in the agenda buffer.
  8353. With prefix ARG, go forward that many times the current span.
  8354. See also:
  8355. `org-agenda-earlier' (\\[org-agenda-earlier])
  8356. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8357. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8358. (interactive "p")
  8359. (org-agenda-check-type t 'agenda)
  8360. (let* ((wstart (window-start))
  8361. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8362. (span (or (nth 2 args) org-agenda-current-span))
  8363. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8364. (greg (calendar-gregorian-from-absolute sd))
  8365. (cnt (org-get-at-bol 'org-day-cnt))
  8366. greg2)
  8367. (cond
  8368. ((numberp span)
  8369. (setq sd (+ (* span arg) sd)))
  8370. ((eq span 'day)
  8371. (setq sd (+ arg sd)))
  8372. ((eq span 'week)
  8373. (setq sd (+ (* 7 arg) sd)))
  8374. ((eq span 'fortnight)
  8375. (setq sd (+ (* 14 arg) sd)))
  8376. ((eq span 'month)
  8377. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8378. sd (calendar-absolute-from-gregorian greg2))
  8379. (setcar greg2 (1+ (car greg2))))
  8380. ((eq span 'year)
  8381. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8382. sd (calendar-absolute-from-gregorian greg2))
  8383. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8384. (t
  8385. (setq sd (+ (* span arg) sd))))
  8386. (let ((org-agenda-overriding-cmd
  8387. ;; `cmd' may have been set by `org-agenda-run-series' which
  8388. ;; uses `org-agenda-overriding-cmd' to decide whether
  8389. ;; overriding is allowed for `cmd'
  8390. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8391. (org-agenda-overriding-arguments
  8392. (list (car args) sd span)))
  8393. (org-agenda-redo)
  8394. (org-agenda-find-same-or-today-or-agenda cnt))
  8395. (set-window-start nil wstart)))
  8396. (defun org-agenda-earlier (arg)
  8397. "Go backward in time by the current span in the agenda buffer.
  8398. With prefix ARG, go backward that many times the current span.
  8399. See also:
  8400. `org-agenda-later' (\\[org-agenda-later])
  8401. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8402. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8403. (interactive "p")
  8404. (org-agenda-later (- arg)))
  8405. (defun org-agenda-view-mode-dispatch ()
  8406. "Call one of the view mode commands."
  8407. (interactive)
  8408. (org-unlogged-message
  8409. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8410. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8411. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8412. (pcase (read-char-exclusive)
  8413. (?\ (call-interactively 'org-agenda-reset-view))
  8414. (?d (call-interactively 'org-agenda-day-view))
  8415. (?w (call-interactively 'org-agenda-week-view))
  8416. (?t (call-interactively 'org-agenda-fortnight-view))
  8417. (?m (call-interactively 'org-agenda-month-view))
  8418. (?y (call-interactively 'org-agenda-year-view))
  8419. (?l (call-interactively 'org-agenda-log-mode))
  8420. (?L (org-agenda-log-mode '(4)))
  8421. (?c (org-agenda-log-mode 'clockcheck))
  8422. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8423. (?a (call-interactively 'org-agenda-archives-mode))
  8424. (?A (org-agenda-archives-mode 'files))
  8425. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8426. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8427. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8428. (?D (call-interactively 'org-agenda-toggle-diary))
  8429. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8430. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8431. (org-agenda-check-type t 'agenda)
  8432. (org-agenda-redo))
  8433. (message "Display now includes inactive timestamps as well"))
  8434. (?q (message "Abort"))
  8435. (key (user-error "Invalid key: %s" key))))
  8436. (defun org-agenda-reset-view ()
  8437. "Switch to default view for agenda."
  8438. (interactive)
  8439. (org-agenda-change-time-span org-agenda-span))
  8440. (defun org-agenda-day-view (&optional day-of-month)
  8441. "Switch to daily view for agenda.
  8442. With argument DAY-OF-MONTH, switch to that day of the month."
  8443. (interactive "P")
  8444. (org-agenda-change-time-span 'day day-of-month))
  8445. (defun org-agenda-week-view (&optional iso-week)
  8446. "Switch to weekly view for agenda.
  8447. With argument ISO-WEEK, switch to the corresponding ISO week.
  8448. If ISO-WEEK has more then 2 digits, only the last two encode
  8449. the week. Any digits before this encode a year. So 200712
  8450. means week 12 of year 2007. Years ranging from 70 years ago
  8451. to 30 years in the future can also be written as 2-digit years."
  8452. (interactive "P")
  8453. (org-agenda-change-time-span 'week iso-week))
  8454. (defun org-agenda-fortnight-view (&optional iso-week)
  8455. "Switch to fortnightly view for agenda.
  8456. With argument ISO-WEEK, switch to the corresponding ISO week.
  8457. If ISO-WEEK has more then 2 digits, only the last two encode
  8458. the week. Any digits before this encode a year. So 200712
  8459. means week 12 of year 2007. Years ranging from 70 years ago
  8460. to 30 years in the future can also be written as 2-digit years."
  8461. (interactive "P")
  8462. (org-agenda-change-time-span 'fortnight iso-week))
  8463. (defun org-agenda-month-view (&optional month)
  8464. "Switch to monthly view for agenda.
  8465. With argument MONTH, switch to that month. If MONTH has more
  8466. then 2 digits, only the last two encode the month. Any digits
  8467. before this encode a year. So 200712 means December year 2007.
  8468. Years ranging from 70 years ago to 30 years in the future can
  8469. also be written as 2-digit years."
  8470. (interactive "P")
  8471. (org-agenda-change-time-span 'month month))
  8472. (defun org-agenda-year-view (&optional year)
  8473. "Switch to yearly view for agenda.
  8474. With argument YEAR, switch to that year. Years ranging from 70
  8475. years ago to 30 years in the future can also be written as
  8476. 2-digit years."
  8477. (interactive "P")
  8478. (when year
  8479. (setq year (org-small-year-to-year year)))
  8480. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8481. (org-agenda-change-time-span 'year year)
  8482. (error "Abort")))
  8483. (defun org-agenda-change-time-span (span &optional n)
  8484. "Change the agenda view to SPAN.
  8485. SPAN may be `day', `week', `fortnight', `month', `year'."
  8486. (org-agenda-check-type t 'agenda)
  8487. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8488. (curspan (nth 2 args)))
  8489. (when (and (not n) (equal curspan span))
  8490. (error "Viewing span is already \"%s\"" span))
  8491. (let* ((sd (or (org-get-at-bol 'day)
  8492. (nth 1 args)
  8493. org-starting-day))
  8494. (sd (org-agenda-compute-starting-span sd span n))
  8495. (org-agenda-overriding-cmd
  8496. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8497. (org-agenda-overriding-arguments
  8498. (list (car args) sd span)))
  8499. (org-agenda-redo)
  8500. (org-agenda-find-same-or-today-or-agenda))
  8501. (org-agenda-set-mode-name)
  8502. (message "Switched to %s view" span)))
  8503. (defun org-agenda-compute-starting-span (sd span &optional n)
  8504. "Compute starting date for agenda.
  8505. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8506. is a cons cell with the starting date and the number of days,
  8507. so that the date SD will be in that range."
  8508. (let* ((greg (calendar-gregorian-from-absolute sd))
  8509. ;; (dg (nth 1 greg))
  8510. (mg (car greg))
  8511. (yg (nth 2 greg)))
  8512. (cond
  8513. ((eq span 'day)
  8514. (when n
  8515. (setq sd (+ (calendar-absolute-from-gregorian
  8516. (list mg 1 yg))
  8517. n -1))))
  8518. ((or (eq span 'week) (eq span 'fortnight))
  8519. (let* ((nt (calendar-day-of-week
  8520. (calendar-gregorian-from-absolute sd)))
  8521. (d (if org-agenda-start-on-weekday
  8522. (- nt org-agenda-start-on-weekday)
  8523. 0))
  8524. y1)
  8525. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8526. (when n
  8527. (require 'cal-iso)
  8528. (when (> n 99)
  8529. (setq y1 (org-small-year-to-year (/ n 100))
  8530. n (mod n 100)))
  8531. (setq sd
  8532. (calendar-iso-to-absolute
  8533. (list n 1
  8534. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8535. ((eq span 'month)
  8536. (let (y1)
  8537. (when (and n (> n 99))
  8538. (setq y1 (org-small-year-to-year (/ n 100))
  8539. n (mod n 100)))
  8540. (setq sd (calendar-absolute-from-gregorian
  8541. (list (or n mg) 1 (or y1 yg))))))
  8542. ((eq span 'year)
  8543. (setq sd (calendar-absolute-from-gregorian
  8544. (list 1 1 (or n yg))))))
  8545. sd))
  8546. (defun org-agenda-next-date-line (&optional arg)
  8547. "Jump to the next line indicating a date in agenda buffer."
  8548. (interactive "p")
  8549. (org-agenda-check-type t 'agenda)
  8550. (beginning-of-line 1)
  8551. ;; This does not work if user makes date format that starts with a blank
  8552. (when (looking-at-p "^\\S-") (forward-char 1))
  8553. (unless (re-search-forward "^\\S-" nil t arg)
  8554. (backward-char 1)
  8555. (error "No next date after this line in this buffer"))
  8556. (goto-char (match-beginning 0)))
  8557. (defun org-agenda-previous-date-line (&optional arg)
  8558. "Jump to the previous line indicating a date in agenda buffer."
  8559. (interactive "p")
  8560. (org-agenda-check-type t 'agenda)
  8561. (beginning-of-line 1)
  8562. (unless (re-search-backward "^\\S-" nil t arg)
  8563. (error "No previous date before this line in this buffer")))
  8564. ;; Initialize the highlight
  8565. (defvar org-hl (make-overlay 1 1))
  8566. (overlay-put org-hl 'face 'highlight)
  8567. (defun org-highlight (begin end &optional buffer)
  8568. "Highlight a region with overlay."
  8569. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8570. (defun org-unhighlight ()
  8571. "Detach overlay INDEX."
  8572. (delete-overlay org-hl))
  8573. (defun org-unhighlight-once ()
  8574. "Remove the highlight from its position, and this function from the hook."
  8575. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8576. (org-unhighlight))
  8577. (defvar org-agenda-pre-follow-window-conf nil)
  8578. (defun org-agenda-follow-mode ()
  8579. "Toggle follow mode in an agenda buffer."
  8580. (interactive)
  8581. (unless org-agenda-follow-mode
  8582. (setq org-agenda-pre-follow-window-conf
  8583. (current-window-configuration)))
  8584. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8585. (unless org-agenda-follow-mode
  8586. (set-window-configuration org-agenda-pre-follow-window-conf))
  8587. (org-agenda-set-mode-name)
  8588. (org-agenda-do-context-action)
  8589. (message "Follow mode is %s"
  8590. (if org-agenda-follow-mode "on" "off")))
  8591. (defun org-agenda-entry-text-mode (&optional arg)
  8592. "Toggle entry text mode in an agenda buffer."
  8593. (interactive "P")
  8594. (if (or org-agenda-tag-filter
  8595. org-agenda-category-filter
  8596. org-agenda-regexp-filter
  8597. org-agenda-top-headline-filter)
  8598. (user-error "Can't show entry text in filtered views")
  8599. (setq org-agenda-entry-text-mode (or (integerp arg)
  8600. (not org-agenda-entry-text-mode)))
  8601. (org-agenda-entry-text-hide)
  8602. (and org-agenda-entry-text-mode
  8603. (let ((org-agenda-entry-text-maxlines
  8604. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8605. (org-agenda-entry-text-show)))
  8606. (org-agenda-set-mode-name)
  8607. (message "Entry text mode is %s%s"
  8608. (if org-agenda-entry-text-mode "on" "off")
  8609. (if (not org-agenda-entry-text-mode) ""
  8610. (format " (maximum number of lines is %d)"
  8611. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8612. (defun org-agenda-clockreport-mode ()
  8613. "Toggle clocktable mode in an agenda buffer."
  8614. (interactive)
  8615. (org-agenda-check-type t 'agenda)
  8616. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8617. (org-agenda-set-mode-name)
  8618. (org-agenda-redo)
  8619. (message "Clocktable mode is %s"
  8620. (if org-agenda-clockreport-mode "on" "off")))
  8621. (defun org-agenda-log-mode (&optional special)
  8622. "Toggle log mode in an agenda buffer.
  8623. With argument SPECIAL, show all possible log items, not only the ones
  8624. configured in `org-agenda-log-mode-items'.
  8625. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8626. log items, nothing else."
  8627. (interactive "P")
  8628. (org-agenda-check-type t 'agenda)
  8629. (setq org-agenda-show-log
  8630. (cond
  8631. ((equal special '(16)) 'only)
  8632. ((eq special 'clockcheck)
  8633. (if (eq org-agenda-show-log 'clockcheck)
  8634. nil 'clockcheck))
  8635. (special '(closed clock state))
  8636. (t (not org-agenda-show-log))))
  8637. (org-agenda-set-mode-name)
  8638. (org-agenda-redo)
  8639. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8640. (defun org-agenda-archives-mode (&optional with-files)
  8641. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8642. When called with a prefix argument, include all archive files as well."
  8643. (interactive "P")
  8644. (setq org-agenda-archives-mode
  8645. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8646. (with-files t)
  8647. (org-agenda-archives-mode nil)
  8648. (t 'trees)))
  8649. (org-agenda-set-mode-name)
  8650. (org-agenda-redo)
  8651. (message
  8652. "%s"
  8653. (cond
  8654. ((eq org-agenda-archives-mode nil)
  8655. "No archives are included")
  8656. ((eq org-agenda-archives-mode 'trees)
  8657. (format "Trees with :%s: tag are included" org-archive-tag))
  8658. ((eq org-agenda-archives-mode t)
  8659. (format "Trees with :%s: tag and all active archive files are included"
  8660. org-archive-tag)))))
  8661. (defun org-agenda-toggle-diary ()
  8662. "Toggle diary inclusion in an agenda buffer."
  8663. (interactive)
  8664. (org-agenda-check-type t 'agenda)
  8665. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8666. (org-agenda-redo)
  8667. (org-agenda-set-mode-name)
  8668. (message "Diary inclusion turned %s"
  8669. (if org-agenda-include-diary "on" "off")))
  8670. (defun org-agenda-toggle-deadlines ()
  8671. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8672. (interactive)
  8673. (org-agenda-check-type t 'agenda)
  8674. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8675. (org-agenda-redo)
  8676. (org-agenda-set-mode-name)
  8677. (message "Deadlines inclusion turned %s"
  8678. (if org-agenda-include-deadlines "on" "off")))
  8679. (defun org-agenda-toggle-time-grid ()
  8680. "Toggle time grid in an agenda buffer."
  8681. (interactive)
  8682. (org-agenda-check-type t 'agenda)
  8683. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8684. (org-agenda-redo)
  8685. (org-agenda-set-mode-name)
  8686. (message "Time-grid turned %s"
  8687. (if org-agenda-use-time-grid "on" "off")))
  8688. (defun org-agenda-set-mode-name ()
  8689. "Set the mode name to indicate all the small mode settings."
  8690. (setq mode-name
  8691. (list "Org-Agenda"
  8692. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8693. " "
  8694. '(:eval (org-agenda-span-name org-agenda-current-span))
  8695. (if org-agenda-follow-mode " Follow" "")
  8696. (if org-agenda-entry-text-mode " ETxt" "")
  8697. (if org-agenda-include-diary " Diary" "")
  8698. (if org-agenda-include-deadlines " Ddl" "")
  8699. (if org-agenda-use-time-grid " Grid" "")
  8700. (if (and (boundp 'org-habit-show-habits)
  8701. org-habit-show-habits)
  8702. " Habit" "")
  8703. (cond
  8704. ((consp org-agenda-show-log) " LogAll")
  8705. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8706. (org-agenda-show-log " Log")
  8707. (t ""))
  8708. (if (org-agenda-filter-any) " " "")
  8709. (if (or org-agenda-category-filter
  8710. (get 'org-agenda-category-filter :preset-filter))
  8711. '(:eval (propertize
  8712. (concat "["
  8713. (mapconcat
  8714. #'identity
  8715. (append
  8716. (get 'org-agenda-category-filter :preset-filter)
  8717. org-agenda-category-filter)
  8718. "")
  8719. "]")
  8720. 'face 'org-agenda-filter-category
  8721. 'help-echo "Category used in filtering"))
  8722. "")
  8723. (if (or org-agenda-tag-filter
  8724. (get 'org-agenda-tag-filter :preset-filter))
  8725. '(:eval (propertize
  8726. (concat (mapconcat
  8727. #'identity
  8728. (append
  8729. (get 'org-agenda-tag-filter :preset-filter)
  8730. org-agenda-tag-filter)
  8731. ""))
  8732. 'face 'org-agenda-filter-tags
  8733. 'help-echo "Tags used in filtering"))
  8734. "")
  8735. (if (or org-agenda-effort-filter
  8736. (get 'org-agenda-effort-filter :preset-filter))
  8737. '(:eval (propertize
  8738. (concat (mapconcat
  8739. #'identity
  8740. (append
  8741. (get 'org-agenda-effort-filter :preset-filter)
  8742. org-agenda-effort-filter)
  8743. ""))
  8744. 'face 'org-agenda-filter-effort
  8745. 'help-echo "Effort conditions used in filtering"))
  8746. "")
  8747. (if (or org-agenda-regexp-filter
  8748. (get 'org-agenda-regexp-filter :preset-filter))
  8749. '(:eval (propertize
  8750. (concat (mapconcat
  8751. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8752. (append
  8753. (get 'org-agenda-regexp-filter :preset-filter)
  8754. org-agenda-regexp-filter)
  8755. ""))
  8756. 'face 'org-agenda-filter-regexp
  8757. 'help-echo "Regexp used in filtering"))
  8758. "")
  8759. (if org-agenda-archives-mode
  8760. (if (eq org-agenda-archives-mode t)
  8761. " Archives"
  8762. (format " :%s:" org-archive-tag))
  8763. "")
  8764. (if org-agenda-clockreport-mode " Clock" "")))
  8765. (force-mode-line-update))
  8766. (defun org-agenda-update-agenda-type ()
  8767. "Update the agenda type after each command."
  8768. (setq org-agenda-type
  8769. (or (get-text-property (point) 'org-agenda-type)
  8770. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8771. (defun org-agenda-next-line ()
  8772. "Move cursor to the next line, and show if follow mode is active."
  8773. (interactive)
  8774. (call-interactively 'next-line)
  8775. (org-agenda-do-context-action))
  8776. (defun org-agenda-previous-line ()
  8777. "Move cursor to the previous line, and show if follow-mode is active."
  8778. (interactive)
  8779. (call-interactively 'previous-line)
  8780. (org-agenda-do-context-action))
  8781. (defun org-agenda-next-item (n)
  8782. "Move cursor to next agenda item."
  8783. (interactive "p")
  8784. (let ((col (current-column)))
  8785. (dotimes (_ n)
  8786. (when (next-single-property-change (point-at-eol) 'org-marker)
  8787. (move-end-of-line 1)
  8788. (goto-char (next-single-property-change (point) 'org-marker))))
  8789. (org-move-to-column col))
  8790. (org-agenda-do-context-action))
  8791. (defun org-agenda-previous-item (n)
  8792. "Move cursor to next agenda item."
  8793. (interactive "p")
  8794. (dotimes (_ n)
  8795. (let ((col (current-column))
  8796. (goto (save-excursion
  8797. (move-end-of-line 0)
  8798. (previous-single-property-change (point) 'org-marker))))
  8799. (when goto (goto-char goto))
  8800. (org-move-to-column col)))
  8801. (org-agenda-do-context-action))
  8802. (defun org-agenda-do-context-action ()
  8803. "Show outline path and, maybe, follow mode window."
  8804. (let ((m (org-get-at-bol 'org-marker)))
  8805. (when (and (markerp m) (marker-buffer m))
  8806. (and org-agenda-follow-mode
  8807. (if org-agenda-follow-indirect
  8808. (org-agenda-tree-to-indirect-buffer nil)
  8809. (org-agenda-show)))
  8810. (and org-agenda-show-outline-path
  8811. (org-with-point-at m (org-display-outline-path t))))))
  8812. (defun org-agenda-show-tags ()
  8813. "Show the tags applicable to the current item."
  8814. (interactive)
  8815. (let* ((tags (org-get-at-bol 'tags)))
  8816. (if tags
  8817. (message "Tags are :%s:"
  8818. (org-no-properties (mapconcat #'identity tags ":")))
  8819. (message "No tags associated with this line"))))
  8820. (defun org-agenda-goto (&optional highlight)
  8821. "Go to the entry at point in the corresponding Org file."
  8822. (interactive)
  8823. (let* ((marker (or (org-get-at-bol 'org-marker)
  8824. (org-agenda-error)))
  8825. (buffer (marker-buffer marker))
  8826. (pos (marker-position marker)))
  8827. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8828. (switch-to-buffer-other-window buffer)
  8829. (widen)
  8830. (push-mark)
  8831. (goto-char pos)
  8832. (when (derived-mode-p 'org-mode)
  8833. (org-fold-show-context 'agenda)
  8834. (recenter (/ (window-height) 2))
  8835. (org-back-to-heading t)
  8836. (let ((case-fold-search nil))
  8837. (when (re-search-forward org-complex-heading-regexp nil t)
  8838. (goto-char (match-beginning 4)))))
  8839. (run-hooks 'org-agenda-after-show-hook)
  8840. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  8841. (defvar org-agenda-after-show-hook nil
  8842. "Normal hook run after an item has been shown from the agenda.
  8843. Point is in the buffer where the item originated.")
  8844. ;; Defined later in org-agenda.el
  8845. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8846. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8847. "Between region BEG and END, call agenda command CMD.
  8848. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8849. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8850. deletes the agenda entry and don't move to the next entry."
  8851. (save-excursion
  8852. (goto-char beg)
  8853. (let ((mend (move-marker (make-marker) end))
  8854. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8855. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8856. org-agenda-loop-over-headlines-in-active-region))
  8857. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8858. (org-get-at-bol 'level))))
  8859. (while (< (point) mend)
  8860. (let ((ov (make-overlay (point) (point-at-eol))))
  8861. (if (not (or all
  8862. (and match (looking-at-p match))
  8863. (eq level (org-get-at-bol 'level))))
  8864. (org-agenda-next-item 1)
  8865. (overlay-put ov 'face 'region)
  8866. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8867. (when (not delete) (org-agenda-next-item 1))
  8868. (delete-overlay ov)))))))
  8869. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8870. ;; kill,set-property,set-effort] commands may loop over agenda
  8871. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8872. ;; use their own mechanisms on active regions.
  8873. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8874. "Maybe loop over agenda entries and perform CMD.
  8875. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8876. (declare (debug t))
  8877. `(if (and (called-interactively-p 'any)
  8878. org-agenda-loop-over-headlines-in-active-region
  8879. (org-region-active-p))
  8880. (org-agenda-do-in-region
  8881. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8882. ,@body))
  8883. (defun org-agenda-kill ()
  8884. "Kill the entry or subtree belonging to the current agenda entry."
  8885. (interactive)
  8886. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8887. (org-agenda-maybe-loop
  8888. #'org-agenda-kill nil nil t
  8889. (let* ((bufname-orig (buffer-name))
  8890. (marker (or (org-get-at-bol 'org-marker)
  8891. (org-agenda-error)))
  8892. (buffer (marker-buffer marker))
  8893. (pos (marker-position marker))
  8894. (type (org-get-at-bol 'type))
  8895. dbeg dend (n 0))
  8896. (org-with-remote-undo buffer
  8897. (with-current-buffer buffer
  8898. (save-excursion
  8899. (goto-char pos)
  8900. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8901. (setq dbeg (progn (org-back-to-heading t) (point))
  8902. dend (org-end-of-subtree t t))
  8903. (setq dbeg (point-at-bol)
  8904. dend (min (point-max) (1+ (point-at-eol)))))
  8905. (goto-char dbeg)
  8906. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8907. (when (or (eq t org-agenda-confirm-kill)
  8908. (and (numberp org-agenda-confirm-kill)
  8909. (> n org-agenda-confirm-kill)))
  8910. (let ((win-conf (current-window-configuration)))
  8911. (unwind-protect
  8912. (and
  8913. (prog2
  8914. (org-agenda-tree-to-indirect-buffer nil)
  8915. (not (y-or-n-p
  8916. (format "Delete entry with %d lines in buffer \"%s\"? "
  8917. n (buffer-name buffer))))
  8918. (kill-buffer org-last-indirect-buffer))
  8919. (error "Abort"))
  8920. (set-window-configuration win-conf))))
  8921. (let ((org-agenda-buffer-name bufname-orig))
  8922. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8923. (with-current-buffer buffer (delete-region dbeg dend))
  8924. (message "Agenda item and source killed")))))
  8925. (defvar org-archive-default-command) ; defined in org-archive.el
  8926. (defun org-agenda-archive-default ()
  8927. "Archive the entry or subtree belonging to the current agenda entry."
  8928. (interactive)
  8929. (require 'org-archive)
  8930. (funcall-interactively
  8931. #'org-agenda-archive-with org-archive-default-command))
  8932. (defun org-agenda-archive-default-with-confirmation ()
  8933. "Archive the entry or subtree belonging to the current agenda entry."
  8934. (interactive)
  8935. (require 'org-archive)
  8936. (funcall-interactively
  8937. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8938. (defun org-agenda-archive ()
  8939. "Archive the entry or subtree belonging to the current agenda entry."
  8940. (interactive)
  8941. (funcall-interactively
  8942. #'org-agenda-archive-with 'org-archive-subtree))
  8943. (defun org-agenda-archive-to-archive-sibling ()
  8944. "Move the entry to the archive sibling."
  8945. (interactive)
  8946. (funcall-interactively
  8947. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8948. (defvar org-archive-from-agenda)
  8949. (defun org-agenda-archive-with (cmd &optional confirm)
  8950. "Move the entry to the archive sibling."
  8951. (interactive)
  8952. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8953. (org-agenda-maybe-loop
  8954. #'org-agenda-archive-with cmd nil t
  8955. (let* ((bufname-orig (buffer-name))
  8956. (marker (or (org-get-at-bol 'org-marker)
  8957. (org-agenda-error)))
  8958. (buffer (marker-buffer marker))
  8959. (pos (marker-position marker)))
  8960. (org-with-remote-undo buffer
  8961. (with-current-buffer buffer
  8962. (if (derived-mode-p 'org-mode)
  8963. (if (and confirm
  8964. (not (y-or-n-p "Archive this subtree or entry? ")))
  8965. (error "Abort")
  8966. (save-window-excursion
  8967. (goto-char pos)
  8968. (let ((org-agenda-buffer-name bufname-orig))
  8969. (org-remove-subtree-entries-from-agenda))
  8970. (org-back-to-heading t)
  8971. (let ((org-archive-from-agenda t))
  8972. (funcall cmd))))
  8973. (error "Archiving works only in Org files")))))))
  8974. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8975. "Remove all lines in the agenda that correspond to a given subtree.
  8976. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8977. If this information is not given, the function uses the tree at point."
  8978. (let ((buf (or buf (current-buffer))) m p)
  8979. (save-excursion
  8980. (unless (and beg end)
  8981. (org-back-to-heading t)
  8982. (setq beg (point))
  8983. (org-end-of-subtree t)
  8984. (setq end (point)))
  8985. (set-buffer (get-buffer org-agenda-buffer-name))
  8986. (save-excursion
  8987. (goto-char (point-max))
  8988. (beginning-of-line 1)
  8989. (while (not (bobp))
  8990. (when (and (setq m (org-get-at-bol 'org-marker))
  8991. (equal buf (marker-buffer m))
  8992. (setq p (marker-position m))
  8993. (>= p beg)
  8994. (< p end))
  8995. (let ((inhibit-read-only t))
  8996. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8997. (beginning-of-line 0))))))
  8998. (defun org-agenda-refile (&optional goto rfloc no-update)
  8999. "Refile the item at point.
  9000. When called with `\\[universal-argument] \\[universal-argument]', \
  9001. go to the location of the last
  9002. refiled item.
  9003. When called with `\\[universal-argument] \\[universal-argument] \
  9004. \\[universal-argument]' prefix or when GOTO is 0, clear
  9005. the refile cache.
  9006. RFLOC can be a refile location obtained in a different way.
  9007. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  9008. (interactive "P")
  9009. (cond
  9010. ((member goto '(0 (64)))
  9011. (org-refile-cache-clear))
  9012. ((equal goto '(16))
  9013. (org-refile-goto-last-stored))
  9014. (t
  9015. (let* ((buffer-orig (buffer-name))
  9016. (marker (or (org-get-at-bol 'org-hd-marker)
  9017. (org-agenda-error)))
  9018. (buffer (marker-buffer marker))
  9019. ;; (pos (marker-position marker))
  9020. (rfloc (or rfloc
  9021. (org-refile-get-location
  9022. (if goto "Goto" "Refile to") buffer
  9023. org-refile-allow-creating-parent-nodes))))
  9024. (with-current-buffer buffer
  9025. (org-with-wide-buffer
  9026. (goto-char marker)
  9027. (let ((org-agenda-buffer-name buffer-orig))
  9028. (org-remove-subtree-entries-from-agenda))
  9029. (org-refile goto buffer rfloc))))
  9030. (unless no-update (org-agenda-redo)))))
  9031. (defun org-agenda-open-link (&optional arg)
  9032. "Open the link(s) in the current entry, if any.
  9033. This looks for a link in the displayed line in the agenda.
  9034. It also looks at the text of the entry itself."
  9035. (interactive "P")
  9036. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  9037. (org-get-at-bol 'org-marker)))
  9038. (buffer (and marker (marker-buffer marker)))
  9039. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  9040. (lkall (and buffer (org-offer-links-in-entry
  9041. buffer marker arg prefix)))
  9042. (lk0 (car lkall))
  9043. (lk (if (stringp lk0) (list lk0) lk0))
  9044. (lkend (cdr lkall))
  9045. trg)
  9046. (cond
  9047. ((and buffer lk)
  9048. (mapcar (lambda(l)
  9049. (with-current-buffer buffer
  9050. (setq trg (and (string-match org-link-bracket-re l)
  9051. (match-string 1 l)))
  9052. (if (or (not trg) (string-match org-link-any-re trg))
  9053. ;; Don't use `org-with-wide-buffer' here as
  9054. ;; opening the link may result in moving the point
  9055. (save-restriction
  9056. (widen)
  9057. (goto-char marker)
  9058. (when (search-forward l nil lkend)
  9059. (goto-char (match-beginning 0))
  9060. (org-open-at-point)))
  9061. ;; This is an internal link, widen the buffer
  9062. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9063. (switch-to-buffer-other-window buffer)
  9064. (widen)
  9065. (goto-char marker)
  9066. (when (search-forward l nil lkend)
  9067. (goto-char (match-beginning 0))
  9068. (org-open-at-point)))))
  9069. lk))
  9070. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9071. (save-excursion
  9072. (beginning-of-line 1)
  9073. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9074. (org-link-open-from-string (match-string 1)))
  9075. (t (message "No link to open here")))))
  9076. (defun org-agenda-copy-local-variable (var)
  9077. "Get a variable from a referenced buffer and install it here."
  9078. (let ((m (org-get-at-bol 'org-marker)))
  9079. (when (and m (buffer-live-p (marker-buffer m)))
  9080. (set (make-local-variable var)
  9081. (with-current-buffer (marker-buffer m)
  9082. (symbol-value var))))))
  9083. (defun org-agenda-switch-to (&optional delete-other-windows)
  9084. "Go to the Org mode file which contains the item at point.
  9085. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9086. displayed Org file fills the frame."
  9087. (interactive)
  9088. (if (and org-return-follows-link
  9089. (not (org-get-at-bol 'org-marker))
  9090. (org-in-regexp org-link-bracket-re))
  9091. (org-link-open-from-string (match-string 0))
  9092. (let* ((marker (or (org-get-at-bol 'org-marker)
  9093. (org-agenda-error)))
  9094. (buffer (marker-buffer marker))
  9095. (pos (marker-position marker)))
  9096. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9097. (pop-to-buffer-same-window buffer)
  9098. (when delete-other-windows (delete-other-windows))
  9099. (widen)
  9100. (goto-char pos)
  9101. (when (derived-mode-p 'org-mode)
  9102. (org-fold-show-context 'agenda)
  9103. (run-hooks 'org-agenda-after-show-hook)))))
  9104. (defun org-agenda-goto-mouse (ev)
  9105. "Go to the Org file which contains the item at the mouse click."
  9106. (interactive "e")
  9107. (mouse-set-point ev)
  9108. (org-agenda-goto))
  9109. (defun org-agenda-show (&optional full-entry)
  9110. "Display the Org file which contains the item at point.
  9111. With prefix argument FULL-ENTRY, make the entire entry visible
  9112. if it was hidden in the outline."
  9113. (interactive "P")
  9114. (let ((win (selected-window)))
  9115. (org-agenda-goto t)
  9116. (when full-entry (org-fold-show-entry 'hide-drawers))
  9117. (select-window win)))
  9118. (defvar org-agenda-show-window nil)
  9119. (defun org-agenda-show-and-scroll-up (&optional arg)
  9120. "Display the Org file which contains the item at point.
  9121. When called repeatedly, scroll the window that is displaying the buffer.
  9122. With a `\\[universal-argument]' prefix argument, display the item, but \
  9123. fold drawers."
  9124. (interactive "P")
  9125. (let ((win (selected-window)))
  9126. (if (and (window-live-p org-agenda-show-window)
  9127. (eq this-command last-command))
  9128. (progn
  9129. (select-window org-agenda-show-window)
  9130. (ignore-errors (scroll-up)))
  9131. (org-agenda-goto t)
  9132. (org-fold-show-entry 'hide-drawers)
  9133. (if arg (org-cycle-hide-drawers 'children)
  9134. (org-with-wide-buffer
  9135. (narrow-to-region (org-entry-beginning-position)
  9136. (org-entry-end-position))
  9137. (org-fold-show-all '(drawers))))
  9138. (setq org-agenda-show-window (selected-window)))
  9139. (select-window win)))
  9140. (defun org-agenda-show-scroll-down ()
  9141. "Scroll down the window showing the agenda."
  9142. (interactive)
  9143. (let ((win (selected-window)))
  9144. (when (window-live-p org-agenda-show-window)
  9145. (select-window org-agenda-show-window)
  9146. (ignore-errors (scroll-down))
  9147. (select-window win))))
  9148. (defun org-agenda-show-1 (&optional more)
  9149. "Display the Org file which contains the item at point.
  9150. The prefix arg selects the amount of information to display:
  9151. 0 hide the subtree
  9152. 1 just show the entry according to defaults.
  9153. 2 show the children view
  9154. 3 show the subtree view
  9155. 4 show the entire subtree and any drawers
  9156. With prefix argument FULL-ENTRY, make the entire entry visible
  9157. if it was hidden in the outline."
  9158. (interactive "p")
  9159. (let ((win (selected-window)))
  9160. (org-agenda-goto t)
  9161. (org-back-to-heading)
  9162. (set-window-start (selected-window) (point-at-bol))
  9163. (cond
  9164. ((= more 0)
  9165. (org-fold-subtree t)
  9166. (save-excursion
  9167. (org-back-to-heading)
  9168. (run-hook-with-args 'org-cycle-hook 'folded))
  9169. (message "Remote: FOLDED"))
  9170. ((and (called-interactively-p 'any) (= more 1))
  9171. (message "Remote: show with default settings"))
  9172. ((= more 2)
  9173. (org-fold-show-entry 'hide-drawers)
  9174. (org-fold-show-children)
  9175. (save-excursion
  9176. (org-back-to-heading)
  9177. (run-hook-with-args 'org-cycle-hook 'children))
  9178. (message "Remote: CHILDREN"))
  9179. ((= more 3)
  9180. (org-fold-show-subtree)
  9181. (save-excursion
  9182. (org-back-to-heading)
  9183. (run-hook-with-args 'org-cycle-hook 'subtree))
  9184. (message "Remote: SUBTREE"))
  9185. ((> more 3)
  9186. (org-fold-show-subtree)
  9187. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9188. (select-window win)))
  9189. (defvar org-agenda-cycle-counter nil)
  9190. (defun org-agenda-cycle-show (&optional n)
  9191. "Show the current entry in another window, with default settings.
  9192. Default settings are taken from `org-show-context-detail'. When
  9193. use repeatedly in immediate succession, the remote entry will
  9194. cycle through visibility
  9195. children -> subtree -> folded
  9196. When called with a numeric prefix arg, that arg will be passed through to
  9197. `org-agenda-show-1'. For the interpretation of that argument, see the
  9198. docstring of `org-agenda-show-1'."
  9199. (interactive "P")
  9200. (if (integerp n)
  9201. (setq org-agenda-cycle-counter n)
  9202. (if (not (eq last-command this-command))
  9203. (setq org-agenda-cycle-counter 1)
  9204. (if (equal org-agenda-cycle-counter 0)
  9205. (setq org-agenda-cycle-counter 2)
  9206. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9207. (when (> org-agenda-cycle-counter 3)
  9208. (setq org-agenda-cycle-counter 0)))))
  9209. (org-agenda-show-1 org-agenda-cycle-counter))
  9210. (defun org-agenda-recenter (arg)
  9211. "Display the Org file which contains the item at point and recenter."
  9212. (interactive "P")
  9213. (let ((win (selected-window)))
  9214. (org-agenda-goto t)
  9215. (recenter arg)
  9216. (select-window win)))
  9217. (defun org-agenda-show-mouse (ev)
  9218. "Display the Org file which contains the item at the mouse click."
  9219. (interactive "e")
  9220. (mouse-set-point ev)
  9221. (org-agenda-show))
  9222. (defun org-agenda-check-no-diary ()
  9223. "Check if the entry is a diary link and abort if yes."
  9224. (when (org-get-at-bol 'org-agenda-diary-link)
  9225. (org-agenda-error)))
  9226. (defun org-agenda-error ()
  9227. "Throw an error when a command is not allowed in the agenda."
  9228. (user-error "Command not allowed in this line"))
  9229. (defun org-agenda-tree-to-indirect-buffer (arg)
  9230. "Show the subtree corresponding to the current entry in an indirect buffer.
  9231. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9232. With a numerical prefix ARG, go up to this level and then take that tree.
  9233. With a negative numeric ARG, go up by this number of levels.
  9234. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9235. i.e. don't use
  9236. the dedicated frame."
  9237. (interactive "P")
  9238. (if current-prefix-arg
  9239. (org-agenda-do-tree-to-indirect-buffer arg)
  9240. (let ((agenda-buffer (buffer-name))
  9241. (agenda-window (selected-window))
  9242. (indirect-window
  9243. (and org-last-indirect-buffer
  9244. (get-buffer-window org-last-indirect-buffer))))
  9245. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9246. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9247. (eq org-indirect-buffer-display 'dedicated-frame))
  9248. (unwind-protect
  9249. (unless (and indirect-window (window-live-p indirect-window))
  9250. (setq indirect-window (split-window agenda-window)))
  9251. (and indirect-window (select-window indirect-window))
  9252. (switch-to-buffer org-last-indirect-buffer :norecord)
  9253. (fit-window-to-buffer indirect-window)))
  9254. (select-window (get-buffer-window agenda-buffer))
  9255. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9256. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9257. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9258. (org-agenda-check-no-diary)
  9259. (let* ((marker (or (org-get-at-bol 'org-marker)
  9260. (org-agenda-error)))
  9261. (buffer (marker-buffer marker))
  9262. (pos (marker-position marker)))
  9263. (with-current-buffer buffer
  9264. (save-excursion
  9265. (goto-char pos)
  9266. (org-tree-to-indirect-buffer arg)))))
  9267. (defvar org-last-heading-marker (make-marker)
  9268. "Marker pointing to the headline that last changed its TODO state
  9269. by a remote command from the agenda.")
  9270. (defun org-agenda-todo-nextset ()
  9271. "Switch TODO entry to next sequence."
  9272. (interactive)
  9273. (org-agenda-todo 'nextset))
  9274. (defun org-agenda-todo-previousset ()
  9275. "Switch TODO entry to previous sequence."
  9276. (interactive)
  9277. (org-agenda-todo 'previousset))
  9278. (defvar org-agenda-headline-snapshot-before-repeat)
  9279. (defun org-agenda-todo (&optional arg)
  9280. "Cycle TODO state of line at point, also in Org file.
  9281. This changes the line at point, all other lines in the agenda referring to
  9282. the same tree node, and the headline of the tree node in the Org file."
  9283. (interactive "P")
  9284. (org-agenda-check-no-diary)
  9285. (org-agenda-maybe-loop
  9286. #'org-agenda-todo arg nil nil
  9287. (let* ((col (current-column))
  9288. (marker (or (org-get-at-bol 'org-marker)
  9289. (org-agenda-error)))
  9290. (buffer (marker-buffer marker))
  9291. (pos (marker-position marker))
  9292. (hdmarker (org-get-at-bol 'org-hd-marker))
  9293. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9294. (inhibit-read-only t)
  9295. org-loop-over-headlines-in-active-region
  9296. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9297. (org-with-remote-undo buffer
  9298. (with-current-buffer buffer
  9299. (widen)
  9300. (goto-char pos)
  9301. (org-fold-show-context 'agenda)
  9302. (let ((current-prefix-arg arg))
  9303. (call-interactively 'org-todo)
  9304. ;; Make sure that log is recorded in current undo.
  9305. (when (and org-log-setup
  9306. (not (eq org-log-note-how 'note)))
  9307. (org-add-log-note)))
  9308. (and (bolp) (forward-char 1))
  9309. (setq newhead (org-get-heading))
  9310. (when (and org-agenda-headline-snapshot-before-repeat
  9311. (not (equal org-agenda-headline-snapshot-before-repeat
  9312. newhead))
  9313. todayp)
  9314. (setq newhead org-agenda-headline-snapshot-before-repeat
  9315. just-one t))
  9316. (save-excursion
  9317. (org-back-to-heading)
  9318. (move-marker org-last-heading-marker (point))))
  9319. (beginning-of-line 1)
  9320. (save-window-excursion
  9321. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9322. (when (bound-and-true-p org-clock-out-when-done)
  9323. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9324. newhead)
  9325. (org-agenda-unmark-clocking-task))
  9326. (org-move-to-column col)
  9327. (org-agenda-mark-clocking-task)))))
  9328. (defun org-agenda-add-note (&optional _arg)
  9329. "Add a time-stamped note to the entry at point."
  9330. (interactive) ;; "P"
  9331. (org-agenda-check-no-diary)
  9332. (let* ((marker (or (org-get-at-bol 'org-marker)
  9333. (org-agenda-error)))
  9334. (buffer (marker-buffer marker))
  9335. (pos (marker-position marker))
  9336. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9337. (inhibit-read-only t))
  9338. (with-current-buffer buffer
  9339. (widen)
  9340. (goto-char pos)
  9341. (org-fold-show-context 'agenda)
  9342. (org-add-note))))
  9343. (defun org-agenda-change-all-lines (newhead hdmarker
  9344. &optional fixface just-this)
  9345. "Change all lines in the agenda buffer which match HDMARKER.
  9346. The new content of the line will be NEWHEAD (as modified by
  9347. `org-agenda-format-item'). HDMARKER is checked with
  9348. `equal' against all `org-hd-marker' text properties in the file.
  9349. If FIXFACE is non-nil, the face of each item is modified according to
  9350. the new TODO state.
  9351. If JUST-THIS is non-nil, change just the current line, not all.
  9352. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9353. (let* ((inhibit-read-only t)
  9354. (line (org-current-line))
  9355. (org-agenda-buffer (current-buffer))
  9356. (thetags (with-current-buffer (marker-buffer hdmarker)
  9357. (org-get-tags hdmarker)))
  9358. props m undone-face done-face finish new dotime level cat tags
  9359. effort effort-minutes) ;; pl
  9360. (save-excursion
  9361. (goto-char (point-max))
  9362. (beginning-of-line 1)
  9363. (while (not finish)
  9364. (setq finish (bobp))
  9365. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9366. (or (not just-this) (= (org-current-line) line))
  9367. (equal m hdmarker))
  9368. (setq props (text-properties-at (point))
  9369. dotime (org-get-at-bol 'dotime)
  9370. cat (org-agenda-get-category)
  9371. level (org-get-at-bol 'level)
  9372. tags thetags
  9373. effort (org-get-at-bol 'effort)
  9374. effort-minutes (org-get-at-bol 'effort-minutes)
  9375. new
  9376. (let ((org-prefix-format-compiled
  9377. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9378. org-prefix-format-compiled))
  9379. (extra (org-get-at-bol 'extra)))
  9380. (with-current-buffer (marker-buffer hdmarker)
  9381. (org-with-wide-buffer
  9382. (org-agenda-format-item extra
  9383. (org-add-props newhead nil
  9384. 'effort effort
  9385. 'effort-minutes effort-minutes)
  9386. level cat tags dotime))))
  9387. ;; pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  9388. undone-face (org-get-at-bol 'undone-face)
  9389. done-face (org-get-at-bol 'done-face))
  9390. (beginning-of-line 1)
  9391. (cond
  9392. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9393. ((looking-at ".*")
  9394. ;; When replacing the whole line, preserve bulk mark
  9395. ;; overlay, if any.
  9396. (let ((mark (catch :overlay
  9397. (dolist (o (overlays-in (point) (+ 2 (point))))
  9398. (when (eq (overlay-get o 'type)
  9399. 'org-marked-entry-overlay)
  9400. (throw :overlay o))))))
  9401. (replace-match new t t)
  9402. (beginning-of-line)
  9403. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9404. (add-text-properties (point-at-bol) (point-at-eol) props)
  9405. (when fixface
  9406. (add-text-properties
  9407. (point-at-bol) (point-at-eol)
  9408. (list 'face
  9409. (if org-last-todo-state-is-todo
  9410. undone-face done-face))))
  9411. (org-agenda-highlight-todo 'line)
  9412. (beginning-of-line 1))
  9413. (t (error "Line update did not work")))
  9414. (save-restriction
  9415. (narrow-to-region (point-at-bol) (point-at-eol))
  9416. (org-agenda-finalize)))
  9417. (beginning-of-line 0)))))
  9418. (defun org-agenda-align-tags (&optional line)
  9419. "Align all tags in agenda items to `org-agenda-tags-column'.
  9420. When optional argument LINE is non-nil, align tags only on the
  9421. current line."
  9422. (let ((inhibit-read-only t)
  9423. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9424. (- (window-max-chars-per-line))
  9425. org-agenda-tags-column))
  9426. (end (and line (line-end-position)))
  9427. l c)
  9428. (save-excursion
  9429. (goto-char (if line (line-beginning-position) (point-min)))
  9430. (while (re-search-forward org-tag-group-re end t)
  9431. (add-text-properties
  9432. (match-beginning 1) (match-end 1)
  9433. (list 'face (delq nil (let ((prop (get-text-property
  9434. (match-beginning 1) 'face)))
  9435. (or (listp prop) (setq prop (list prop)))
  9436. (if (memq 'org-tag prop)
  9437. prop
  9438. (cons 'org-tag prop))))))
  9439. (setq l (string-width (match-string 1))
  9440. c (if (< org-agenda-tags-column 0)
  9441. (- (abs org-agenda-tags-column) l)
  9442. org-agenda-tags-column))
  9443. (goto-char (match-beginning 1))
  9444. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9445. (point))
  9446. (insert (org-add-props
  9447. (make-string (max 1 (- c (current-column))) ?\s)
  9448. (plist-put (copy-sequence (text-properties-at (point)))
  9449. 'face nil))))
  9450. (goto-char (point-min))
  9451. (org-font-lock-add-tag-faces (point-max)))))
  9452. (defun org-agenda-priority-up ()
  9453. "Increase the priority of line at point, also in Org file."
  9454. (interactive)
  9455. (org-agenda-priority 'up))
  9456. (defun org-agenda-priority-down ()
  9457. "Decrease the priority of line at point, also in Org file."
  9458. (interactive)
  9459. (org-agenda-priority 'down))
  9460. (defun org-agenda-priority (&optional force-direction)
  9461. "Set the priority of line at point, also in Org file.
  9462. This changes the line at point, all other lines in the agenda
  9463. referring to the same tree node, and the headline of the tree
  9464. node in the Org file.
  9465. Called with one universal prefix arg, show the priority instead
  9466. of setting it.
  9467. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9468. `down', or a character."
  9469. (interactive "P")
  9470. (unless org-priority-enable-commands
  9471. (user-error "Priority commands are disabled"))
  9472. (org-agenda-check-no-diary)
  9473. (let* ((col (current-column))
  9474. (hdmarker (org-get-at-bol 'org-hd-marker))
  9475. (buffer (marker-buffer hdmarker))
  9476. (pos (marker-position hdmarker))
  9477. (inhibit-read-only t)
  9478. newhead)
  9479. (org-with-remote-undo buffer
  9480. (with-current-buffer buffer
  9481. (widen)
  9482. (goto-char pos)
  9483. (org-fold-show-context 'agenda)
  9484. (org-priority force-direction)
  9485. (end-of-line 1)
  9486. (setq newhead (org-get-heading)))
  9487. (org-agenda-change-all-lines newhead hdmarker)
  9488. (org-move-to-column col))))
  9489. ;; FIXME: should fix the tags property of the agenda line.
  9490. (defun org-agenda-set-tags (&optional tag onoff)
  9491. "Set tags for the current headline."
  9492. (interactive)
  9493. (org-agenda-check-no-diary)
  9494. (if (and (org-region-active-p) (called-interactively-p 'any))
  9495. (call-interactively 'org-change-tag-in-region)
  9496. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9497. (org-agenda-error)))
  9498. (buffer (marker-buffer hdmarker))
  9499. (pos (marker-position hdmarker))
  9500. (inhibit-read-only t)
  9501. newhead)
  9502. (org-with-remote-undo buffer
  9503. (with-current-buffer buffer
  9504. (widen)
  9505. (goto-char pos)
  9506. (org-fold-show-context 'agenda)
  9507. (if tag
  9508. (org-toggle-tag tag onoff)
  9509. (call-interactively #'org-set-tags-command))
  9510. (end-of-line 1)
  9511. (setq newhead (org-get-heading)))
  9512. (org-agenda-change-all-lines newhead hdmarker)
  9513. (beginning-of-line 1)))))
  9514. (defun org-agenda-set-property ()
  9515. "Set a property for the current headline."
  9516. (interactive)
  9517. (org-agenda-check-no-diary)
  9518. (org-agenda-maybe-loop
  9519. #'org-agenda-set-property nil nil nil
  9520. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9521. (org-agenda-error)))
  9522. (buffer (marker-buffer hdmarker))
  9523. (pos (marker-position hdmarker))
  9524. (inhibit-read-only t)
  9525. ) ;; newhead
  9526. (org-with-remote-undo buffer
  9527. (with-current-buffer buffer
  9528. (widen)
  9529. (goto-char pos)
  9530. (org-fold-show-context 'agenda)
  9531. (call-interactively 'org-set-property))))))
  9532. (defun org-agenda-set-effort ()
  9533. "Set the effort property for the current headline."
  9534. (interactive)
  9535. (org-agenda-check-no-diary)
  9536. (org-agenda-maybe-loop
  9537. #'org-agenda-set-effort nil nil nil
  9538. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9539. (org-agenda-error)))
  9540. (buffer (marker-buffer hdmarker))
  9541. (pos (marker-position hdmarker))
  9542. (inhibit-read-only t)
  9543. newhead)
  9544. (org-with-remote-undo buffer
  9545. (with-current-buffer buffer
  9546. (widen)
  9547. (goto-char pos)
  9548. (org-fold-show-context 'agenda)
  9549. (call-interactively 'org-set-effort)
  9550. (end-of-line 1)
  9551. (setq newhead (org-get-heading)))
  9552. (org-agenda-change-all-lines newhead hdmarker)))))
  9553. (defun org-agenda-toggle-archive-tag ()
  9554. "Toggle the archive tag for the current entry."
  9555. (interactive)
  9556. (org-agenda-check-no-diary)
  9557. (org-agenda-maybe-loop
  9558. #'org-agenda-toggle-archive-tag nil nil nil
  9559. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9560. (org-agenda-error)))
  9561. (buffer (marker-buffer hdmarker))
  9562. (pos (marker-position hdmarker))
  9563. (inhibit-read-only t)
  9564. newhead)
  9565. (org-with-remote-undo buffer
  9566. (with-current-buffer buffer
  9567. (widen)
  9568. (goto-char pos)
  9569. (org-fold-show-context 'agenda)
  9570. (call-interactively 'org-toggle-archive-tag)
  9571. (end-of-line 1)
  9572. (setq newhead (org-get-heading)))
  9573. (org-agenda-change-all-lines newhead hdmarker)
  9574. (beginning-of-line 1)))))
  9575. (defun org-agenda-do-date-later (arg)
  9576. (interactive "P")
  9577. (cond
  9578. ((or (equal arg '(16))
  9579. (memq last-command
  9580. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9581. (setq this-command 'org-agenda-date-later-minutes)
  9582. (org-agenda-date-later-minutes 1))
  9583. ((or (equal arg '(4))
  9584. (memq last-command
  9585. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9586. (setq this-command 'org-agenda-date-later-hours)
  9587. (org-agenda-date-later-hours 1))
  9588. (t
  9589. (org-agenda-date-later (prefix-numeric-value arg)))))
  9590. (defun org-agenda-do-date-earlier (arg)
  9591. (interactive "P")
  9592. (cond
  9593. ((or (equal arg '(16))
  9594. (memq last-command
  9595. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9596. (setq this-command 'org-agenda-date-earlier-minutes)
  9597. (org-agenda-date-earlier-minutes 1))
  9598. ((or (equal arg '(4))
  9599. (memq last-command
  9600. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9601. (setq this-command 'org-agenda-date-earlier-hours)
  9602. (org-agenda-date-earlier-hours 1))
  9603. (t
  9604. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9605. (defun org-agenda-date-later (arg &optional what)
  9606. "Change the date of this item to ARG day(s) later."
  9607. (interactive "p")
  9608. (org-agenda-check-type t 'agenda)
  9609. (org-agenda-check-no-diary)
  9610. (let* ((marker (or (org-get-at-bol 'org-marker)
  9611. (org-agenda-error)))
  9612. (buffer (marker-buffer marker))
  9613. (pos (marker-position marker))
  9614. cdate today)
  9615. (org-with-remote-undo buffer
  9616. (with-current-buffer buffer
  9617. (widen)
  9618. (goto-char pos)
  9619. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9620. (when (and org-agenda-move-date-from-past-immediately-to-today
  9621. (equal arg 1)
  9622. (or (not what) (eq what 'day))
  9623. (not (save-match-data (org-at-date-range-p))))
  9624. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9625. cdate (calendar-absolute-from-gregorian
  9626. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9627. today (org-today))
  9628. (when (> today cdate)
  9629. ;; immediately shift to today
  9630. (setq arg (- today cdate))))
  9631. (org-timestamp-change arg (or what 'day))
  9632. (when (and (org-at-date-range-p)
  9633. (re-search-backward org-tr-regexp-both (point-at-bol)))
  9634. (let ((end org-last-changed-timestamp))
  9635. (org-timestamp-change arg (or what 'day))
  9636. (setq org-last-changed-timestamp
  9637. (concat org-last-changed-timestamp "--" end)))))
  9638. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9639. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9640. (defun org-agenda-date-earlier (arg &optional what)
  9641. "Change the date of this item to ARG day(s) earlier."
  9642. (interactive "p")
  9643. (org-agenda-date-later (- arg) what))
  9644. (defun org-agenda-date-later-minutes (arg)
  9645. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9646. (interactive "p")
  9647. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9648. (org-agenda-date-later arg 'minute))
  9649. (defun org-agenda-date-earlier-minutes (arg)
  9650. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9651. (interactive "p")
  9652. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9653. (org-agenda-date-earlier arg 'minute))
  9654. (defun org-agenda-date-later-hours (arg)
  9655. "Change the time of this item, in hour steps."
  9656. (interactive "p")
  9657. (org-agenda-date-later arg 'hour))
  9658. (defun org-agenda-date-earlier-hours (arg)
  9659. "Change the time of this item, in hour steps."
  9660. (interactive "p")
  9661. (org-agenda-date-earlier arg 'hour))
  9662. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9663. "Show new date stamp via text properties."
  9664. ;; We use text properties to make this undoable
  9665. (let ((inhibit-read-only t))
  9666. (setq stamp (concat prefix " => " stamp " "))
  9667. (save-excursion
  9668. (goto-char (point-max))
  9669. (while (not (bobp))
  9670. (when (equal marker (org-get-at-bol 'org-marker))
  9671. (remove-text-properties (line-beginning-position)
  9672. (line-end-position)
  9673. '(display nil))
  9674. (org-move-to-column
  9675. (- (window-max-chars-per-line)
  9676. (length stamp))
  9677. t)
  9678. (add-text-properties
  9679. (1- (point)) (point-at-eol)
  9680. (list 'display (org-add-props stamp nil
  9681. 'face '(secondary-selection default))))
  9682. (beginning-of-line 1))
  9683. (beginning-of-line 0)))))
  9684. (defun org-agenda-date-prompt (arg)
  9685. "Change the date of this item. Date is prompted for, with default today.
  9686. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9687. be used to request time specification in the time stamp."
  9688. (interactive "P")
  9689. (org-agenda-check-type t 'agenda)
  9690. (org-agenda-check-no-diary)
  9691. (org-agenda-maybe-loop
  9692. #'org-agenda-date-prompt arg t nil
  9693. (let* ((marker (or (org-get-at-bol 'org-marker)
  9694. (org-agenda-error)))
  9695. (buffer (marker-buffer marker))
  9696. (pos (marker-position marker)))
  9697. (org-with-remote-undo buffer
  9698. (with-current-buffer buffer
  9699. (widen)
  9700. (goto-char pos)
  9701. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9702. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9703. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9704. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9705. (defun org-agenda-schedule (arg &optional time)
  9706. "Schedule the item at point.
  9707. ARG is passed through to `org-schedule'."
  9708. (interactive "P")
  9709. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9710. (org-agenda-check-no-diary)
  9711. (org-agenda-maybe-loop
  9712. #'org-agenda-schedule arg t nil
  9713. (let* ((marker (or (org-get-at-bol 'org-marker)
  9714. (org-agenda-error)))
  9715. ;; (type (marker-insertion-type marker))
  9716. (buffer (marker-buffer marker))
  9717. (pos (marker-position marker))
  9718. ts)
  9719. (set-marker-insertion-type marker t)
  9720. (org-with-remote-undo buffer
  9721. (with-current-buffer buffer
  9722. (widen)
  9723. (goto-char pos)
  9724. (setq ts (org-schedule arg time)))
  9725. (org-agenda-show-new-time marker ts " S"))
  9726. (message "%s" ts))))
  9727. (defun org-agenda-deadline (arg &optional time)
  9728. "Schedule the item at point.
  9729. ARG is passed through to `org-deadline'."
  9730. (interactive "P")
  9731. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9732. (org-agenda-check-no-diary)
  9733. (org-agenda-maybe-loop
  9734. #'org-agenda-deadline arg t nil
  9735. (let* ((marker (or (org-get-at-bol 'org-marker)
  9736. (org-agenda-error)))
  9737. (buffer (marker-buffer marker))
  9738. (pos (marker-position marker))
  9739. ts)
  9740. (org-with-remote-undo buffer
  9741. (with-current-buffer buffer
  9742. (widen)
  9743. (goto-char pos)
  9744. (setq ts (org-deadline arg time)))
  9745. (org-agenda-show-new-time marker ts " D"))
  9746. (message "%s" ts))))
  9747. (defun org-agenda-clock-in (&optional arg)
  9748. "Start the clock on the currently selected item."
  9749. (interactive "P")
  9750. (org-agenda-check-no-diary)
  9751. (if (equal arg '(4))
  9752. (org-clock-in arg)
  9753. (let* ((marker (or (org-get-at-bol 'org-marker)
  9754. (org-agenda-error)))
  9755. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9756. (pos (marker-position marker))
  9757. (col (current-column))
  9758. newhead)
  9759. (org-with-remote-undo (marker-buffer marker)
  9760. (with-current-buffer (marker-buffer marker)
  9761. (widen)
  9762. (goto-char pos)
  9763. (org-fold-show-context 'agenda)
  9764. (org-clock-in arg)
  9765. (setq newhead (org-get-heading)))
  9766. (org-agenda-change-all-lines newhead hdmarker))
  9767. (org-move-to-column col))))
  9768. (defun org-agenda-clock-out ()
  9769. "Stop the currently running clock."
  9770. (interactive)
  9771. (unless (marker-buffer org-clock-marker)
  9772. (user-error "No running clock"))
  9773. (let ((marker (make-marker)) (col (current-column)) newhead)
  9774. (org-with-remote-undo (marker-buffer org-clock-marker)
  9775. (with-current-buffer (marker-buffer org-clock-marker)
  9776. (org-with-wide-buffer
  9777. (goto-char org-clock-marker)
  9778. (org-back-to-heading t)
  9779. (move-marker marker (point))
  9780. (org-clock-out)
  9781. (setq newhead (org-get-heading)))))
  9782. (org-agenda-change-all-lines newhead marker)
  9783. (move-marker marker nil)
  9784. (org-move-to-column col)
  9785. (org-agenda-unmark-clocking-task)))
  9786. (defun org-agenda-clock-cancel (&optional _arg)
  9787. "Cancel the currently running clock."
  9788. (interactive) ;; "P"
  9789. (unless (marker-buffer org-clock-marker)
  9790. (user-error "No running clock"))
  9791. (org-with-remote-undo (marker-buffer org-clock-marker)
  9792. (org-clock-cancel)))
  9793. (defun org-agenda-clock-goto ()
  9794. "Jump to the currently clocked in task within the agenda.
  9795. If the currently clocked in task is not listed in the agenda
  9796. buffer, display it in another window."
  9797. (interactive)
  9798. (let (pos)
  9799. (mapc (lambda (o)
  9800. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9801. (setq pos (overlay-start o))))
  9802. (overlays-in (point-min) (point-max)))
  9803. (cond (pos (goto-char pos))
  9804. ;; If the currently clocked entry is not in the agenda
  9805. ;; buffer, we visit it in another window:
  9806. ((bound-and-true-p org-clock-current-task)
  9807. (org-switch-to-buffer-other-window (org-clock-goto)))
  9808. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9809. (defun org-agenda-diary-entry-in-org-file ()
  9810. "Make a diary entry in the file `org-agenda-diary-file'."
  9811. (let (d1 d2 char (text "") dp1 dp2)
  9812. (if (equal (buffer-name) "*Calendar*")
  9813. (setq d1 (calendar-cursor-to-date t)
  9814. d2 (car calendar-mark-ring))
  9815. (setq dp1 (get-text-property (point-at-bol) 'day))
  9816. (unless dp1 (user-error "No date defined in current line"))
  9817. (setq d1 (calendar-gregorian-from-absolute dp1)
  9818. d2 (and (ignore-errors (mark))
  9819. (save-excursion
  9820. (goto-char (mark))
  9821. (setq dp2 (get-text-property (point-at-bol) 'day)))
  9822. (calendar-gregorian-from-absolute dp2))))
  9823. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9824. (setq char (read-char-exclusive))
  9825. (cond
  9826. ((equal char ?d)
  9827. (setq text (read-string "Day entry: "))
  9828. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9829. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9830. ((equal char ?a)
  9831. (setq d1 (list (car d1) (nth 1 d1)
  9832. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9833. (nth 2 d1))))
  9834. (setq text (read-string "Anniversary (use %d to show years): "))
  9835. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9836. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9837. ((equal char ?b)
  9838. (setq text (read-string "Block entry: "))
  9839. (unless (and d1 d2 (not (equal d1 d2)))
  9840. (user-error "No block of days selected"))
  9841. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9842. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9843. ((equal char ?j)
  9844. (org-switch-to-buffer-other-window
  9845. (find-file-noselect org-agenda-diary-file))
  9846. (require 'org-datetree)
  9847. (org-datetree-find-date-create d1)
  9848. (org-fold-reveal t))
  9849. (t (user-error "Invalid selection character `%c'" char)))))
  9850. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9851. "Where in `org-agenda-diary-file' should new entries be added?
  9852. Valid values:
  9853. date-tree in the date tree, as first child of the date
  9854. date-tree-last in the date tree, as last child of the date
  9855. top-level as top-level entries at the end of the file."
  9856. :group 'org-agenda
  9857. :type '(choice
  9858. (const :tag "first in a date tree" date-tree)
  9859. (const :tag "last in a date tree" date-tree-last)
  9860. (const :tag "as top level at end of file" top-level)))
  9861. (defcustom org-agenda-insert-diary-extract-time nil
  9862. "Non-nil means extract any time specification from the diary entry."
  9863. :group 'org-agenda
  9864. :version "24.1"
  9865. :type 'boolean)
  9866. (defcustom org-agenda-bulk-mark-char ">"
  9867. "A single-character string to be used as the bulk mark."
  9868. :group 'org-agenda
  9869. :version "24.1"
  9870. :type 'string)
  9871. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9872. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9873. If TEXT is not empty, it will become the headline of the new entry, and
  9874. the resulting entry will not be shown. When TEXT is empty, switch to
  9875. `org-agenda-diary-file' and let the user finish the entry there."
  9876. (let ((cw (current-window-configuration)))
  9877. (org-switch-to-buffer-other-window
  9878. (find-file-noselect org-agenda-diary-file))
  9879. (widen)
  9880. (goto-char (point-min))
  9881. (cl-case type
  9882. (anniversary
  9883. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9884. (progn
  9885. (or (org-at-heading-p)
  9886. (progn
  9887. (outline-next-heading)
  9888. (insert "* Anniversaries\n\n")
  9889. (beginning-of-line -1)))))
  9890. (outline-next-heading)
  9891. (org-back-over-empty-lines)
  9892. (backward-char 1)
  9893. (insert "\n")
  9894. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9895. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9896. (day
  9897. (let ((org-prefix-has-time t)
  9898. (org-agenda-time-leading-zero t)
  9899. fmt time time2)
  9900. (when org-agenda-insert-diary-extract-time
  9901. ;; Use org-agenda-format-item to parse text for a time-range and
  9902. ;; remove it. FIXME: This is a hack, we should refactor
  9903. ;; that function to make time extraction available separately
  9904. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9905. time (get-text-property 0 'time fmt)
  9906. time2 (if (> (length time) 0)
  9907. ;; split-string removes trailing ...... if
  9908. ;; no end time given. First space
  9909. ;; separates time from date.
  9910. (concat " " (car (split-string time "\\.")))
  9911. nil)
  9912. text (get-text-property 0 'txt fmt)))
  9913. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9914. (org-agenda-insert-diary-as-top-level text)
  9915. (require 'org-datetree)
  9916. (org-datetree-find-date-create d1)
  9917. (org-agenda-insert-diary-make-new-entry text))
  9918. (org-insert-time-stamp (org-time-from-absolute
  9919. (calendar-absolute-from-gregorian d1))
  9920. nil nil nil nil time2))
  9921. (end-of-line 0))
  9922. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9923. ;; otherwise the indentation gets confused by the
  9924. ;; special meaning of 'block
  9925. (when (> (calendar-absolute-from-gregorian d1)
  9926. (calendar-absolute-from-gregorian d2))
  9927. (setq d1 (prog1 d2 (setq d2 d1))))
  9928. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9929. (org-agenda-insert-diary-as-top-level text)
  9930. (require 'org-datetree)
  9931. (org-datetree-find-date-create d1)
  9932. (org-agenda-insert-diary-make-new-entry text))
  9933. (org-insert-time-stamp (org-time-from-absolute
  9934. (calendar-absolute-from-gregorian d1)))
  9935. (insert "--")
  9936. (org-insert-time-stamp (org-time-from-absolute
  9937. (calendar-absolute-from-gregorian d2)))
  9938. (end-of-line 0)))
  9939. (if (string-match "\\S-" text)
  9940. (progn
  9941. (set-window-configuration cw)
  9942. (message "%s entry added to %s"
  9943. (capitalize (symbol-name type))
  9944. (abbreviate-file-name org-agenda-diary-file)))
  9945. (org-fold-reveal t)
  9946. (message "Please finish entry here"))))
  9947. (defun org-agenda-insert-diary-as-top-level (text)
  9948. "Make new entry as a top-level entry at the end of the file.
  9949. Add TEXT as headline, and position the cursor in the second line so that
  9950. a timestamp can be added there."
  9951. (widen)
  9952. (goto-char (point-max))
  9953. (unless (bolp) (insert "\n"))
  9954. (org-insert-heading nil t t)
  9955. (insert text)
  9956. (org-end-of-meta-data)
  9957. (unless (bolp) (insert "\n"))
  9958. (when org-adapt-indentation (indent-to-column 2)))
  9959. (defun org-agenda-insert-diary-make-new-entry (text)
  9960. "Make a new entry with TEXT as a child of the current subtree.
  9961. Position the point in the heading's first body line so that
  9962. a timestamp can be added there."
  9963. (cond
  9964. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9965. (end-of-line)
  9966. (org-insert-heading '(4) t)
  9967. (org-do-demote))
  9968. (t
  9969. (outline-next-heading)
  9970. (org-back-over-empty-lines)
  9971. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9972. (org-insert-heading nil t)
  9973. (org-do-demote)))
  9974. (let ((col (current-column)))
  9975. (insert text)
  9976. (org-end-of-meta-data)
  9977. ;; Ensure point is left on a blank line, at proper indentation.
  9978. (unless (bolp) (insert "\n"))
  9979. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9980. (when org-adapt-indentation (indent-to-column col)))
  9981. (org-fold-show-set-visibility 'lineage))
  9982. (defun org-agenda-diary-entry ()
  9983. "Make a diary entry, like the `i' command from the calendar.
  9984. All the standard commands work: block, weekly etc.
  9985. When `org-agenda-diary-file' points to a file,
  9986. `org-agenda-diary-entry-in-org-file' is called instead to create
  9987. entries in that Org file."
  9988. (interactive)
  9989. (if (not (eq org-agenda-diary-file 'diary-file))
  9990. (org-agenda-diary-entry-in-org-file)
  9991. (require 'diary-lib)
  9992. (let* ((char (read-char-exclusive
  9993. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9994. [a]nniversary [b]lock [c]yclic"))
  9995. (cmd (cdr (assoc char
  9996. '((?d . diary-insert-entry)
  9997. (?w . diary-insert-weekly-entry)
  9998. (?m . diary-insert-monthly-entry)
  9999. (?y . diary-insert-yearly-entry)
  10000. (?a . diary-insert-anniversary-entry)
  10001. (?b . diary-insert-block-entry)
  10002. (?c . diary-insert-cyclic-entry)))))
  10003. (oldf (symbol-function 'calendar-cursor-to-date))
  10004. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  10005. (point (point))
  10006. (mark (or (mark t) (point))))
  10007. (unless cmd
  10008. (user-error "No command associated with <%c>" char))
  10009. (unless (and (get-text-property point 'day)
  10010. (or (not (equal ?b char))
  10011. (get-text-property mark 'day)))
  10012. (user-error "Don't know which date to use for diary entry"))
  10013. ;; We implement this by hacking the `calendar-cursor-to-date' function
  10014. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  10015. (let ((calendar-mark-ring
  10016. (list (calendar-gregorian-from-absolute
  10017. (or (get-text-property mark 'day)
  10018. (get-text-property point 'day))))))
  10019. (unwind-protect
  10020. (progn
  10021. (fset 'calendar-cursor-to-date
  10022. (lambda (&optional _error _dummy)
  10023. (calendar-gregorian-from-absolute
  10024. (get-text-property point 'day))))
  10025. (call-interactively cmd))
  10026. (fset 'calendar-cursor-to-date oldf))))))
  10027. (defun org-agenda-execute-calendar-command (cmd)
  10028. "Execute a calendar command from the agenda with date from cursor."
  10029. (org-agenda-check-type t 'agenda)
  10030. (require 'diary-lib)
  10031. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  10032. (user-error "Don't know which date to use for the calendar command"))
  10033. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  10034. (point (point))
  10035. (date (calendar-gregorian-from-absolute
  10036. (get-text-property point 'day))))
  10037. ;; the following 2 vars are needed in the calendar
  10038. (org-dlet
  10039. ((displayed-month (car date))
  10040. (displayed-year (nth 2 date)))
  10041. (unwind-protect
  10042. (progn
  10043. (fset 'calendar-cursor-to-date
  10044. (lambda (&optional _error _dummy)
  10045. (calendar-gregorian-from-absolute
  10046. (get-text-property point 'day))))
  10047. (call-interactively cmd))
  10048. (fset 'calendar-cursor-to-date oldf)))))
  10049. (defun org-agenda-phases-of-moon ()
  10050. "Display the phases of the moon for the 3 months around the cursor date."
  10051. (interactive)
  10052. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10053. (defun org-agenda-holidays ()
  10054. "Display the holidays for the 3 months around the cursor date."
  10055. (interactive)
  10056. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10057. (defvar calendar-longitude) ; defined in calendar.el
  10058. (defvar calendar-latitude) ; defined in calendar.el
  10059. (defvar calendar-location-name) ; defined in calendar.el
  10060. (defun org-agenda-sunrise-sunset (arg)
  10061. "Display sunrise and sunset for the cursor date.
  10062. Latitude and longitude can be specified with the variables
  10063. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10064. argument, latitude and longitude will be prompted for."
  10065. (interactive "P")
  10066. (require 'solar)
  10067. (let ((calendar-longitude (if arg nil calendar-longitude))
  10068. (calendar-latitude (if arg nil calendar-latitude))
  10069. (calendar-location-name
  10070. (if arg "the given coordinates" calendar-location-name)))
  10071. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10072. (defun org-agenda-goto-calendar ()
  10073. "Open the Emacs calendar with the date at the cursor."
  10074. (interactive)
  10075. (org-agenda-check-type t 'agenda)
  10076. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10077. (user-error "Don't know which date to open in calendar")))
  10078. (date (calendar-gregorian-from-absolute day))
  10079. (calendar-move-hook nil)
  10080. (calendar-view-holidays-initially-flag nil)
  10081. (calendar-view-diary-initially-flag nil))
  10082. (calendar)
  10083. (calendar-goto-date date)))
  10084. ;;;###autoload
  10085. (defun org-calendar-goto-agenda ()
  10086. "Compute the Org agenda for the calendar date displayed at the cursor.
  10087. This is a command that has to be installed in `calendar-mode-map'."
  10088. (interactive)
  10089. ;; Temporarily disable sticky agenda since user clearly wants to
  10090. ;; refresh view anyway.
  10091. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10092. (org-agenda-sticky nil))
  10093. (org-agenda-list nil (calendar-absolute-from-gregorian
  10094. (calendar-cursor-to-date))
  10095. nil)))
  10096. (defun org-agenda-convert-date ()
  10097. (interactive)
  10098. (org-agenda-check-type t 'agenda)
  10099. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10100. date s)
  10101. (unless day
  10102. (user-error "Don't know which date to convert"))
  10103. (setq date (calendar-gregorian-from-absolute day))
  10104. (setq s (concat
  10105. "Gregorian: " (calendar-date-string date) "\n"
  10106. "ISO: " (calendar-iso-date-string date) "\n"
  10107. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10108. "Julian: " (calendar-julian-date-string date) "\n"
  10109. "Astron. JD: " (calendar-astro-date-string date)
  10110. " (Julian date number at noon UTC)\n"
  10111. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10112. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10113. "French: " (calendar-french-date-string date) "\n"
  10114. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10115. "Mayan: " (calendar-mayan-date-string date) "\n"
  10116. "Coptic: " (calendar-coptic-date-string date) "\n"
  10117. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10118. "Persian: " (calendar-persian-date-string date) "\n"
  10119. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10120. (with-output-to-temp-buffer "*Dates*"
  10121. (princ s))
  10122. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10123. ;;; Bulk commands
  10124. (defun org-agenda-bulk-marked-p ()
  10125. "Non-nil when current entry is marked for bulk action."
  10126. (eq (get-char-property (point-at-bol) 'type)
  10127. 'org-marked-entry-overlay))
  10128. (defun org-agenda-bulk-mark (&optional arg)
  10129. "Mark entries for future bulk action.
  10130. When ARG is nil or one and region is not active then mark the
  10131. entry at point.
  10132. When ARG is nil or one and region is active then mark the entries
  10133. in the region.
  10134. When ARG is greater than one mark ARG lines."
  10135. (interactive "p")
  10136. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10137. (setq arg (count-lines (region-beginning) (region-end)))
  10138. (goto-char (region-beginning))
  10139. (deactivate-mark))
  10140. (dotimes (_ (or arg 1))
  10141. (unless (org-get-at-bol 'org-agenda-diary-link)
  10142. (let* ((m (org-get-at-bol 'org-hd-marker))
  10143. ov)
  10144. (unless (org-agenda-bulk-marked-p)
  10145. (unless m (user-error "Nothing to mark at point"))
  10146. (push m org-agenda-bulk-marked-entries)
  10147. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  10148. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10149. (org-get-todo-face "TODO")
  10150. 'evaporate)
  10151. (overlay-put ov 'type 'org-marked-entry-overlay))
  10152. (end-of-line 1)
  10153. (or (ignore-errors
  10154. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10155. (beginning-of-line 2))
  10156. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10157. (beginning-of-line 2)))))
  10158. (message "%d entries marked for bulk action"
  10159. (length org-agenda-bulk-marked-entries)))
  10160. (defun org-agenda-bulk-mark-all ()
  10161. "Mark all entries for future agenda bulk action."
  10162. (interactive)
  10163. (org-agenda-bulk-mark-regexp "."))
  10164. (defun org-agenda-bulk-mark-regexp (regexp)
  10165. "Mark entries matching REGEXP for future agenda bulk action."
  10166. (interactive "sMark entries matching regexp: ")
  10167. (let ((entries-marked 0) txt-at-point)
  10168. (save-excursion
  10169. (goto-char (point-min))
  10170. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10171. (while (and (re-search-forward regexp nil t)
  10172. (setq txt-at-point
  10173. (get-text-property (match-beginning 0) 'txt)))
  10174. (if (get-char-property (point) 'invisible)
  10175. (beginning-of-line 2)
  10176. (when (string-match-p regexp txt-at-point)
  10177. (setq entries-marked (1+ entries-marked))
  10178. (call-interactively 'org-agenda-bulk-mark)))))
  10179. (unless entries-marked
  10180. (message "No entry matching this regexp."))))
  10181. (defun org-agenda-bulk-unmark (&optional arg)
  10182. "Unmark the entry at point for future bulk action."
  10183. (interactive "P")
  10184. (if arg
  10185. (org-agenda-bulk-unmark-all)
  10186. (cond ((org-agenda-bulk-marked-p)
  10187. (org-agenda-bulk-remove-overlays
  10188. (point-at-bol) (+ 2 (point-at-bol)))
  10189. (setq org-agenda-bulk-marked-entries
  10190. (delete (org-get-at-bol 'org-hd-marker)
  10191. org-agenda-bulk-marked-entries))
  10192. (end-of-line 1)
  10193. (or (ignore-errors
  10194. (goto-char (next-single-property-change (point) 'txt)))
  10195. (beginning-of-line 2))
  10196. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10197. (beginning-of-line 2))
  10198. (message "%d entries left marked for bulk action"
  10199. (length org-agenda-bulk-marked-entries)))
  10200. (t (message "No entry to unmark here")))))
  10201. (defun org-agenda-bulk-toggle-all ()
  10202. "Toggle all marks for bulk action."
  10203. (interactive)
  10204. (save-excursion
  10205. (goto-char (point-min))
  10206. (while (ignore-errors
  10207. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10208. (org-agenda-bulk-toggle))))
  10209. (defun org-agenda-bulk-toggle ()
  10210. "Toggle the mark at point for bulk action."
  10211. (interactive)
  10212. (if (org-agenda-bulk-marked-p)
  10213. (org-agenda-bulk-unmark)
  10214. (org-agenda-bulk-mark)))
  10215. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10216. "Remove the mark overlays between BEG and END in the agenda buffer.
  10217. BEG and END default to the buffer limits.
  10218. This only removes the overlays, it does not remove the markers
  10219. from the list in `org-agenda-bulk-marked-entries'."
  10220. (interactive)
  10221. (mapc (lambda (ov)
  10222. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10223. (delete-overlay ov)))
  10224. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10225. (defun org-agenda-bulk-unmark-all ()
  10226. "Remove all marks in the agenda buffer.
  10227. This will remove the markers and the overlays."
  10228. (interactive)
  10229. (if (null org-agenda-bulk-marked-entries)
  10230. (message "No entry to unmark")
  10231. (setq org-agenda-bulk-marked-entries nil)
  10232. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10233. (defcustom org-agenda-persistent-marks nil
  10234. "Non-nil means marked items will stay marked after a bulk action.
  10235. You can toggle this interactively by typing `p' when prompted for a
  10236. bulk action."
  10237. :group 'org-agenda
  10238. :version "24.1"
  10239. :type 'boolean)
  10240. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10241. "Shall some commands act upon headlines in the active region?
  10242. When set to t, some commands will be performed in all headlines
  10243. within the active region.
  10244. When set to `start-level', some commands will be performed in all
  10245. headlines within the active region, provided that these headlines
  10246. are of the same level than the first one.
  10247. When set to a regular expression, those commands will be
  10248. performed on the matching headlines within the active region.
  10249. The list of commands is: `org-agenda-schedule',
  10250. `org-agenda-deadline', `org-agenda-date-prompt',
  10251. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10252. See `org-loop-over-headlines-in-active-region' for the equivalent
  10253. option for Org buffers."
  10254. :type '(choice (const :tag "Don't loop" nil)
  10255. (const :tag "All headlines in active region" t)
  10256. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10257. (regexp :tag "Regular expression matcher"))
  10258. :version "27.1"
  10259. :package-version '(Org . "9.4")
  10260. :group 'org-agenda)
  10261. (defun org-agenda-bulk-action (&optional arg)
  10262. "Execute an remote-editing action on all marked entries.
  10263. The prefix arg is passed through to the command if possible."
  10264. (interactive "P")
  10265. ;; When there is no mark, act on the agenda entry at point.
  10266. (if (not org-agenda-bulk-marked-entries)
  10267. (save-excursion (org-agenda-bulk-mark)))
  10268. (dolist (m org-agenda-bulk-marked-entries)
  10269. (unless (and (markerp m)
  10270. (marker-buffer m)
  10271. (buffer-live-p (marker-buffer m))
  10272. (marker-position m))
  10273. (user-error "Marker %s for bulk command is invalid" m)))
  10274. ;; Prompt for the bulk command.
  10275. (org-unlogged-message
  10276. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10277. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10278. "[S]catter [f]unction "
  10279. (and org-agenda-bulk-custom-functions
  10280. (format " Custom: [%s]"
  10281. (mapconcat (lambda (f) (char-to-string (car f)))
  10282. org-agenda-bulk-custom-functions
  10283. "")))))
  10284. (catch 'exit
  10285. (let* ((org-log-refile (if org-log-refile 'time nil))
  10286. (entries (reverse org-agenda-bulk-marked-entries))
  10287. (org-overriding-default-time
  10288. (and (get-text-property (point) 'org-agenda-date-header)
  10289. (org-get-cursor-date)))
  10290. redo-at-end
  10291. cmd)
  10292. (pcase (read-char-exclusive)
  10293. (?p
  10294. (let ((org-agenda-persistent-marks
  10295. (not org-agenda-persistent-marks)))
  10296. (org-agenda-bulk-action)
  10297. (throw 'exit nil)))
  10298. (?$
  10299. (setq cmd #'org-agenda-archive))
  10300. (?A
  10301. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10302. ((or ?r ?w)
  10303. (let ((refile-location
  10304. (org-refile-get-location
  10305. "Refile to"
  10306. (marker-buffer (car entries))
  10307. org-refile-allow-creating-parent-nodes)))
  10308. (when (nth 3 refile-location)
  10309. (setcar (nthcdr 3 refile-location)
  10310. (move-marker
  10311. (make-marker)
  10312. (nth 3 refile-location)
  10313. (or (get-file-buffer (nth 1 refile-location))
  10314. (find-buffer-visiting (nth 1 refile-location))
  10315. (error "This should not happen")))))
  10316. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10317. (setq redo-at-end t)))
  10318. (?t
  10319. (let ((state (completing-read
  10320. "Todo state: "
  10321. (with-current-buffer (marker-buffer (car entries))
  10322. (mapcar #'list org-todo-keywords-1)))))
  10323. (setq cmd (lambda ()
  10324. (let ((org-inhibit-blocking t)
  10325. (org-inhibit-logging 'note))
  10326. (org-agenda-todo state))))))
  10327. ((and (or ?- ?+) action)
  10328. (let ((tag (completing-read
  10329. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10330. (with-current-buffer (marker-buffer (car entries))
  10331. (delq nil
  10332. (mapcar (lambda (x) (and (stringp (car x)) x))
  10333. org-current-tag-alist))))))
  10334. (setq cmd
  10335. (lambda ()
  10336. (org-agenda-set-tags tag
  10337. (if (eq action ?+) 'on 'off))))))
  10338. ((and (or ?s ?d) c)
  10339. (let* ((schedule? (eq c ?s))
  10340. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10341. (time
  10342. (and (not arg)
  10343. (let ((new (org-read-date
  10344. nil nil nil prompt org-overriding-default-time)))
  10345. ;; A "double plus" answer applies to every
  10346. ;; scheduled time. Do not turn it into
  10347. ;; a fixed date yet.
  10348. (if (string-match-p "\\`[ \t]*\\+\\+"
  10349. org-read-date-final-answer)
  10350. org-read-date-final-answer
  10351. new)))))
  10352. ;; Make sure to not prompt for a note when bulk
  10353. ;; rescheduling/resetting deadline as Org cannot cope with
  10354. ;; simultaneous notes. Besides, it could be annoying
  10355. ;; depending on the number of marked items.
  10356. (setq cmd
  10357. (if schedule?
  10358. (lambda ()
  10359. (let ((org-log-reschedule
  10360. (and org-log-reschedule 'time)))
  10361. (org-agenda-schedule arg time)))
  10362. (lambda ()
  10363. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10364. (org-agenda-deadline arg time)))))))
  10365. (?S
  10366. (unless (org-agenda-check-type nil 'agenda 'todo)
  10367. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10368. (let ((days (read-number
  10369. (format "Scatter tasks across how many %sdays: "
  10370. (if arg "week" ""))
  10371. 7)))
  10372. (setq cmd
  10373. (lambda ()
  10374. (let ((distance (1+ (random days))))
  10375. (when arg
  10376. (let ((dist distance)
  10377. (day-of-week
  10378. (calendar-day-of-week
  10379. (calendar-gregorian-from-absolute (org-today)))))
  10380. (dotimes (_ (1+ dist))
  10381. (while (member day-of-week org-agenda-weekend-days)
  10382. (cl-incf distance)
  10383. (cl-incf day-of-week)
  10384. (when (= day-of-week 7)
  10385. (setq day-of-week 0)))
  10386. (cl-incf day-of-week)
  10387. (when (= day-of-week 7)
  10388. (setq day-of-week 0)))))
  10389. ;; Silently fail when try to replan a sexp entry.
  10390. (ignore-errors
  10391. (let* ((date (calendar-gregorian-from-absolute
  10392. (+ (org-today) distance)))
  10393. (time (org-encode-time
  10394. 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  10395. (org-agenda-schedule nil time))))))))
  10396. (?f
  10397. (setq cmd
  10398. (intern
  10399. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10400. (action
  10401. (setq cmd
  10402. (pcase (assoc action org-agenda-bulk-custom-functions)
  10403. (`(,_ ,fn)
  10404. fn)
  10405. (`(,_ ,fn ,arg-fn)
  10406. (apply #'apply-partially fn (funcall arg-fn)))
  10407. (_
  10408. (user-error "Invalid bulk action: %c" action))))
  10409. (setq redo-at-end t)))
  10410. ;; Sort the markers, to make sure that parents are handled
  10411. ;; before children.
  10412. (setq entries (sort entries
  10413. (lambda (a b)
  10414. (cond
  10415. ((eq (marker-buffer a) (marker-buffer b))
  10416. (< (marker-position a) (marker-position b)))
  10417. (t
  10418. (string< (buffer-name (marker-buffer a))
  10419. (buffer-name (marker-buffer b))))))))
  10420. ;; Now loop over all markers and apply CMD.
  10421. (let ((processed 0)
  10422. (skipped 0))
  10423. (dolist (e entries)
  10424. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10425. (if (not pos)
  10426. (progn (message "Skipping removed entry at %s" e)
  10427. (cl-incf skipped))
  10428. (goto-char pos)
  10429. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10430. ;; `post-command-hook' is not run yet. We make sure any
  10431. ;; pending log note is processed.
  10432. (when org-log-setup (org-add-log-note))
  10433. (cl-incf processed))))
  10434. (when redo-at-end (org-agenda-redo))
  10435. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10436. (message "Acted on %d entries%s%s"
  10437. processed
  10438. (if (= skipped 0)
  10439. ""
  10440. (format ", skipped %d (disappeared before their turn)"
  10441. skipped))
  10442. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10443. (defun org-agenda-capture (&optional with-time)
  10444. "Call `org-capture' with the date at point.
  10445. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10446. current HH:MM time."
  10447. (interactive "P")
  10448. (if (not (eq major-mode 'org-agenda-mode))
  10449. (user-error "You cannot do this outside of agenda buffers")
  10450. (let ((org-overriding-default-time
  10451. (org-get-cursor-date (equal with-time 1))))
  10452. (call-interactively 'org-capture))))
  10453. ;;; Dragging agenda lines forward/backward
  10454. (defun org-agenda-reapply-filters ()
  10455. "Re-apply all agenda filters."
  10456. (mapcar
  10457. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10458. `((,org-agenda-tag-filter tag)
  10459. (,org-agenda-category-filter category)
  10460. (,org-agenda-regexp-filter regexp)
  10461. (,org-agenda-effort-filter effort)
  10462. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  10463. (,(get 'org-agenda-category-filter :preset-filter) category)
  10464. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  10465. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  10466. (defun org-agenda-drag-line-forward (arg &optional backward)
  10467. "Drag an agenda line forward by ARG lines.
  10468. When the optional argument `backward' is non-nil, move backward."
  10469. (interactive "p")
  10470. (let ((inhibit-read-only t) lst line)
  10471. (if (or (not (get-text-property (point) 'txt))
  10472. (save-excursion
  10473. (dotimes (_ arg)
  10474. (move-beginning-of-line (if backward 0 2))
  10475. (push (not (get-text-property (point) 'txt)) lst))
  10476. (delq nil lst)))
  10477. (message "Cannot move line forward")
  10478. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10479. (move-beginning-of-line 1)
  10480. (setq line (buffer-substring (point) end))
  10481. (delete-region (point) end)
  10482. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10483. (insert line)
  10484. (org-agenda-reapply-filters)
  10485. (org-agenda-mark-clocking-task)
  10486. (move-beginning-of-line 0)))))
  10487. (defun org-agenda-drag-line-backward (arg)
  10488. "Drag an agenda line backward by ARG lines."
  10489. (interactive "p")
  10490. (org-agenda-drag-line-forward arg t))
  10491. ;;; Flagging notes
  10492. (defun org-agenda-show-the-flagging-note ()
  10493. "Display the flagging note in the other window.
  10494. When called a second time in direct sequence, offer to remove the FLAGGING
  10495. tag and (if present) the flagging note."
  10496. (interactive)
  10497. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10498. (win (selected-window))
  10499. note) ;; heading newhead
  10500. (unless hdmarker
  10501. (user-error "No linked entry at point"))
  10502. (if (and (eq this-command last-command)
  10503. (y-or-n-p "Unflag and remove any flagging note? "))
  10504. (progn
  10505. (org-agenda-remove-flag hdmarker)
  10506. (let ((win (get-buffer-window "*Flagging Note*")))
  10507. (and win (delete-window win)))
  10508. (message "Entry unflagged"))
  10509. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10510. (unless note
  10511. (user-error "No flagging note"))
  10512. (org-kill-new note)
  10513. (org-switch-to-buffer-other-window "*Flagging Note*")
  10514. (erase-buffer)
  10515. (insert note)
  10516. (goto-char (point-min))
  10517. (while (re-search-forward "\\\\n" nil t)
  10518. (replace-match "\n" t t))
  10519. (goto-char (point-min))
  10520. (select-window win)
  10521. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10522. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10523. tag and note")))))
  10524. (defun org-agenda-remove-flag (marker)
  10525. "Remove the FLAGGED tag and any flagging note in the entry."
  10526. (let ((newhead
  10527. (org-with-point-at marker
  10528. (org-toggle-tag "FLAGGED" 'off)
  10529. (org-entry-delete nil "THEFLAGGINGNOTE")
  10530. (org-get-heading))))
  10531. (org-agenda-change-all-lines newhead marker)
  10532. (message "Entry unflagged")))
  10533. (defun org-agenda-get-any-marker (&optional pos)
  10534. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  10535. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  10536. ;;; Appointment reminders
  10537. (defvar appt-time-msg-list) ; defined in appt.el
  10538. ;;;###autoload
  10539. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10540. "Activate appointments found in `org-agenda-files'.
  10541. With a `\\[universal-argument]' prefix, refresh the list of \
  10542. appointments.
  10543. If FILTER is t, interactively prompt the user for a regular
  10544. expression, and filter out entries that don't match it.
  10545. If FILTER is a string, use this string as a regular expression
  10546. for filtering entries out.
  10547. If FILTER is a function, filter out entries against which
  10548. calling the function returns nil. This function takes one
  10549. argument: an entry from `org-agenda-get-day-entries'.
  10550. FILTER can also be an alist with the car of each cell being
  10551. either `headline' or `category'. For example:
  10552. ((headline \"IMPORTANT\")
  10553. (category \"Work\"))
  10554. will only add headlines containing IMPORTANT or headlines
  10555. belonging to the \"Work\" category.
  10556. ARGS are symbols indicating what kind of entries to consider.
  10557. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10558. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10559. and :timestamp entries. See the docstring of `org-diary' for
  10560. details and examples.
  10561. If an entry has a APPT_WARNTIME property, its value will be used
  10562. to override `appt-message-warning-time'."
  10563. (interactive "P")
  10564. (when refresh (setq appt-time-msg-list nil))
  10565. (when (eq filter t)
  10566. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10567. (let* ((cnt 0) ; count added events
  10568. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10569. (org-agenda-new-buffers nil)
  10570. (org-deadline-warning-days 0)
  10571. ;; Do not use `org-today' here because appt only takes
  10572. ;; time and without date as argument, so it may pass wrong
  10573. ;; information otherwise
  10574. (today (org-date-to-gregorian
  10575. (time-to-days nil)))
  10576. (org-agenda-restrict nil)
  10577. (files (org-agenda-files 'unrestricted)) entries file
  10578. (org-agenda-buffer nil))
  10579. ;; Get all entries which may contain an appt
  10580. (org-agenda-prepare-buffers files)
  10581. (while (setq file (pop files))
  10582. (setq entries
  10583. (delq nil
  10584. (append entries
  10585. (apply #'org-agenda-get-day-entries
  10586. file today scope)))))
  10587. ;; Map through entries and find if we should filter them out
  10588. (mapc
  10589. (lambda (x)
  10590. (let* ((evt (org-trim
  10591. (replace-regexp-in-string
  10592. org-link-bracket-re "\\2"
  10593. (or (get-text-property 1 'txt x) ""))))
  10594. (cat (get-text-property (1- (length x)) 'org-category x))
  10595. (tod (get-text-property 1 'time-of-day x))
  10596. (ok (or (null filter)
  10597. (and (stringp filter) (string-match filter evt))
  10598. (and (functionp filter) (funcall filter x))
  10599. (and (listp filter)
  10600. (let ((cat-filter (cadr (assq 'category filter)))
  10601. (evt-filter (cadr (assq 'headline filter))))
  10602. (or (and (stringp cat-filter)
  10603. (string-match cat-filter cat))
  10604. (and (stringp evt-filter)
  10605. (string-match evt-filter evt)))))))
  10606. (wrn (get-text-property 1 'warntime x)))
  10607. ;; FIXME: Shall we remove text-properties for the appt text?
  10608. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10609. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10610. (setq tod (concat "00" (number-to-string tod)))
  10611. (setq tod (when (string-match
  10612. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10613. (concat (match-string 1 tod) ":"
  10614. (match-string 2 tod))))
  10615. (when (appt-add tod evt wrn)
  10616. (setq cnt (1+ cnt))))))
  10617. entries)
  10618. (org-release-buffers org-agenda-new-buffers)
  10619. (if (eq cnt 0)
  10620. (message "No event to add")
  10621. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10622. (defun org-agenda-today-p (date)
  10623. "Non-nil when DATE means today.
  10624. DATE is either a list of the form (month day year) or a number of
  10625. days as returned by `calendar-absolute-from-gregorian' or
  10626. `org-today'. This function considers `org-extend-today-until'
  10627. when defining today."
  10628. (eq (org-today)
  10629. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10630. (defun org-agenda-todo-yesterday (&optional arg)
  10631. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10632. (interactive "P")
  10633. (let* ((org-use-effective-time t)
  10634. (hour (nth 2 (decode-time (org-current-time))))
  10635. (org-extend-today-until (1+ hour)))
  10636. (org-agenda-todo arg)))
  10637. (defun org-agenda-ctrl-c-ctrl-c ()
  10638. "Set tags in agenda buffer."
  10639. (interactive)
  10640. (org-agenda-set-tags))
  10641. (provide 'org-agenda)
  10642. ;;; org-agenda.el ends here