org-agenda.el 446 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398
  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 for org agenda clock report mode"
  1089. :group 'org-agenda
  1090. :type '(choice
  1091. (string :tag "Header")
  1092. (const :tag "No header" nil))
  1093. :safe #'stringp
  1094. :package-version '(Org . "9.6"))
  1095. (defun org-agenda-time-of-day-to-ampm (time)
  1096. "Convert TIME of a string like \"13:45\" to an AM/PM style time string."
  1097. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1098. (minute (substring time -2))
  1099. (ampm "am"))
  1100. (cond
  1101. ((equal hour-number 12)
  1102. (setq ampm "pm"))
  1103. ((> hour-number 12)
  1104. (setq ampm "pm")
  1105. (setq hour-number (- hour-number 12))))
  1106. (concat
  1107. (if org-agenda-time-leading-zero
  1108. (format "%02d" hour-number)
  1109. (format "%02s" (number-to-string hour-number)))
  1110. ":" minute ampm)))
  1111. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1112. "Conditionally convert TIME to AM/PM format.
  1113. This is based on `org-agenda-timegrid-use-ampm'."
  1114. (if org-agenda-timegrid-use-ampm
  1115. (org-agenda-time-of-day-to-ampm time)
  1116. time))
  1117. (defcustom org-agenda-weekend-days '(6 0)
  1118. "Which days are weekend?
  1119. These days get the special face `org-agenda-date-weekend' in the agenda."
  1120. :group 'org-agenda-daily/weekly
  1121. :type '(set :greedy t
  1122. (const :tag "Monday" 1)
  1123. (const :tag "Tuesday" 2)
  1124. (const :tag "Wednesday" 3)
  1125. (const :tag "Thursday" 4)
  1126. (const :tag "Friday" 5)
  1127. (const :tag "Saturday" 6)
  1128. (const :tag "Sunday" 0)))
  1129. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1130. "Non-nil means jump to today when moving a past date forward in time.
  1131. When using S-right in the agenda to move a date forward, and the date
  1132. stamp currently points to the past, the first key press will move it
  1133. to today. When nil, just move one day forward even if the date stays
  1134. in the past."
  1135. :group 'org-agenda-daily/weekly
  1136. :version "24.1"
  1137. :type 'boolean)
  1138. (defcustom org-agenda-diary-file 'diary-file
  1139. "File to which to add new entries with the `i' key in agenda and calendar.
  1140. When this is the symbol `diary-file', the functionality in the Emacs
  1141. calendar will be used to add entries to the `diary-file'. But when this
  1142. points to a file, `org-agenda-diary-entry' will be used instead."
  1143. :group 'org-agenda
  1144. :type '(choice
  1145. (const :tag "The standard Emacs diary file" diary-file)
  1146. (file :tag "Special Org file diary entries")))
  1147. (defcustom org-agenda-include-diary nil
  1148. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1149. Custom commands can set this variable in the options section."
  1150. :group 'org-agenda-daily/weekly
  1151. :type 'boolean)
  1152. (defcustom org-agenda-include-deadlines t
  1153. "If non-nil, include entries within their deadline warning period.
  1154. Custom commands can set this variable in the options section."
  1155. :group 'org-agenda-daily/weekly
  1156. :version "24.1"
  1157. :type 'boolean)
  1158. (defcustom org-agenda-show-future-repeats t
  1159. "Non-nil shows repeated entries in the future part of the agenda.
  1160. When set to the symbol `next' only the first future repeat is shown."
  1161. :group 'org-agenda-daily/weekly
  1162. :type '(choice
  1163. (const :tag "Show all repeated entries" t)
  1164. (const :tag "Show next repeated entry" next)
  1165. (const :tag "Do not show repeated entries" nil))
  1166. :version "26.1"
  1167. :package-version '(Org . "9.1")
  1168. :safe #'symbolp)
  1169. (defcustom org-agenda-prefer-last-repeat nil
  1170. "Non-nil sets date for repeated entries to their last repeat.
  1171. When nil, display SCHEDULED and DEADLINE dates at their base
  1172. date, and in today's agenda, as a reminder. Display plain
  1173. time-stamps, on the other hand, at every repeat date in the past
  1174. in addition to the base date.
  1175. When non-nil, show a repeated entry at its latest repeat date,
  1176. possibly being today even if it wasn't marked as done. This
  1177. setting is useful if you do not always mark repeated entries as
  1178. done and, yet, consider that reaching repeat date starts the task
  1179. anew.
  1180. When set to a list of strings, prefer last repeats only for
  1181. entries with these TODO keywords."
  1182. :group 'org-agenda-daily/weekly
  1183. :type '(choice
  1184. (const :tag "Prefer last repeat" t)
  1185. (const :tag "Prefer base date" nil)
  1186. (repeat :tag "Prefer last repeat for entries with these TODO keywords"
  1187. (string :tag "TODO keyword")))
  1188. :version "26.1"
  1189. :package-version '(Org . "9.1")
  1190. :safe (lambda (x) (or (booleanp x) (consp x))))
  1191. (defcustom org-scheduled-past-days 10000
  1192. "Number of days to continue listing scheduled items not marked DONE.
  1193. When an item is scheduled on a date, it shows up in the agenda on
  1194. this day and will be listed until it is marked done or for the
  1195. number of days given here."
  1196. :group 'org-agenda-daily/weekly
  1197. :type 'integer
  1198. :safe 'integerp)
  1199. (defcustom org-deadline-past-days 10000
  1200. "Number of days to warn about missed deadlines.
  1201. When an item has deadline on a date, it shows up in the agenda on
  1202. this day and will appear as a reminder until it is marked DONE or
  1203. for the number of days given here."
  1204. :group 'org-agenda-daily/weekly
  1205. :type 'integer
  1206. :version "26.1"
  1207. :package-version '(Org . "9.1")
  1208. :safe 'integerp)
  1209. (defcustom org-agenda-log-mode-items '(closed clock)
  1210. "List of items that should be shown in agenda log mode.
  1211. \\<org-agenda-mode-map>\
  1212. This list may contain the following symbols:
  1213. closed Show entries that have been closed on that day.
  1214. clock Show entries that have received clocked time on that day.
  1215. state Show all logged state changes.
  1216. Note that instead of changing this variable, you can also press \
  1217. `\\[universal-argument] \\[org-agenda-log-mode]' in
  1218. the agenda to display all available LOG items temporarily."
  1219. :group 'org-agenda-daily/weekly
  1220. :type '(set :greedy t (const closed) (const clock) (const state)))
  1221. (defcustom org-agenda-clock-consistency-checks
  1222. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1223. :gap-ok-around ("4:00")
  1224. :default-face ((:background "DarkRed") (:foreground "white"))
  1225. :overlap-face nil :gap-face nil :no-end-time-face nil
  1226. :long-face nil :short-face nil)
  1227. "This is a property list, with the following keys:
  1228. :max-duration Mark clocking chunks that are longer than this time.
  1229. This is a time string like \"HH:MM\", or the number
  1230. of minutes as an integer.
  1231. :min-duration Mark clocking chunks that are shorter that this.
  1232. This is a time string like \"HH:MM\", or the number
  1233. of minutes as an integer.
  1234. :max-gap Mark gaps between clocking chunks that are longer than
  1235. this duration. A number of minutes, or a string
  1236. like \"HH:MM\".
  1237. :gap-ok-around List of times during the day which are usually not working
  1238. times. When a gap is detected, but the gap contains any
  1239. of these times, the gap is *not* reported. For example,
  1240. if this is (\"4:00\" \"13:00\") then gaps that contain
  1241. 4:00 in the morning (i.e. the night) and 13:00
  1242. (i.e. a typical lunch time) do not cause a warning.
  1243. You should have at least one time during the night in this
  1244. list, or otherwise the first task each morning will trigger
  1245. a warning because it follows a long gap.
  1246. Furthermore, the following properties can be used to define faces for
  1247. issue display.
  1248. :default-face the default face, if the specific face is undefined
  1249. :overlap-face face for overlapping clocks
  1250. :gap-face face for gaps between clocks
  1251. :no-end-time-face face for incomplete clocks
  1252. :long-face face for clock intervals that are too long
  1253. :short-face face for clock intervals that are too short"
  1254. :group 'org-agenda-daily/weekly
  1255. :group 'org-clock
  1256. :version "24.1"
  1257. :type 'plist)
  1258. (defcustom org-agenda-log-mode-add-notes t
  1259. "Non-nil means add first line of notes to log entries in agenda views.
  1260. If a log item like a state change or a clock entry is associated with
  1261. notes, the first line of these notes will be added to the entry in the
  1262. agenda display."
  1263. :group 'org-agenda-daily/weekly
  1264. :type 'boolean)
  1265. (defcustom org-agenda-start-with-log-mode nil
  1266. "The initial value of log-mode in a newly created agenda window.
  1267. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1268. explanations on the possible values."
  1269. :group 'org-agenda-startup
  1270. :group 'org-agenda-daily/weekly
  1271. :type '(choice (const :tag "Don't show log items" nil)
  1272. (const :tag "Show only log items" only)
  1273. (const :tag "Show all possible log items" clockcheck)
  1274. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1275. (choice (const :tag "Show closed log items" closed)
  1276. (const :tag "Show clocked log items" clock)
  1277. (const :tag "Show all logged state changes" state)))))
  1278. (defcustom org-agenda-start-with-clockreport-mode nil
  1279. "The initial value of clockreport-mode in a newly created agenda window."
  1280. :group 'org-agenda-startup
  1281. :group 'org-agenda-daily/weekly
  1282. :type 'boolean)
  1283. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1284. "Property list with parameters for the clocktable in clockreport mode.
  1285. This is the display mode that shows a clock table in the daily/weekly
  1286. agenda, the properties for this dynamic block can be set here.
  1287. The usual clocktable parameters are allowed here, but you cannot set
  1288. the properties :name, :tstart, :tend, :block, and :scope - these will
  1289. be overwritten to make sure the content accurately reflects the
  1290. current display in the agenda."
  1291. :group 'org-agenda-daily/weekly
  1292. :type 'plist)
  1293. (defvaralias 'org-agenda-search-view-search-words-only
  1294. 'org-agenda-search-view-always-boolean)
  1295. (defcustom org-agenda-search-view-always-boolean nil
  1296. "Non-nil means the search string is interpreted as individual parts.
  1297. The search string for search view can either be interpreted as a phrase,
  1298. or as a list of snippets that define a boolean search for a number of
  1299. strings.
  1300. When this is non-nil, the string will be split on whitespace, and each
  1301. snippet will be searched individually, and all must match in order to
  1302. select an entry. A snippet is then a single string of non-white
  1303. characters, or a string in double quotes, or a regexp in {} braces.
  1304. If a snippet is preceded by \"-\", the snippet must *not* match.
  1305. \"+\" is syntactic sugar for positive selection. Each snippet may
  1306. be found as a full word or a partial word, but see the variable
  1307. `org-agenda-search-view-force-full-words'.
  1308. When this is nil, search will look for the entire search phrase as one,
  1309. with each space character matching any amount of whitespace, including
  1310. line breaks.
  1311. Even when this is nil, you can still switch to Boolean search dynamically
  1312. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1313. is a regexp marked with braces like \"{abc}\", this will also switch to
  1314. boolean search."
  1315. :group 'org-agenda-search-view
  1316. :version "24.1"
  1317. :type 'boolean)
  1318. (defcustom org-agenda-search-view-force-full-words nil
  1319. "Non-nil means, search words must be matches as complete words.
  1320. When nil, they may also match part of a word."
  1321. :group 'org-agenda-search-view
  1322. :version "24.1"
  1323. :type 'boolean)
  1324. (defcustom org-agenda-search-view-max-outline-level 0
  1325. "Maximum outline level to display in search view.
  1326. E.g. when this is set to 1, the search view will only
  1327. show headlines of level 1. When set to 0, the default
  1328. value, don't limit agenda view by outline level."
  1329. :group 'org-agenda-search-view
  1330. :version "26.1"
  1331. :package-version '(Org . "8.3")
  1332. :type 'integer)
  1333. (defgroup org-agenda-time-grid nil
  1334. "Options concerning the time grid in the Org Agenda."
  1335. :tag "Org Agenda Time Grid"
  1336. :group 'org-agenda)
  1337. (defcustom org-agenda-search-headline-for-time t
  1338. "Non-nil means search headline for a time-of-day.
  1339. If the headline contains a time-of-day in one format or another, it will
  1340. be used to sort the entry into the time sequence of items for a day.
  1341. Some people have time stamps in the headline that refer to the creation
  1342. time or so, and then this produces an unwanted side effect. If this is
  1343. the case for your, use this variable to turn off searching the headline
  1344. for a time."
  1345. :group 'org-agenda-time-grid
  1346. :type 'boolean)
  1347. (defcustom org-agenda-use-time-grid t
  1348. "Non-nil means show a time grid in the agenda schedule.
  1349. A time grid is a set of lines for specific times (like every two hours between
  1350. 8:00 and 20:00). The items scheduled for a day at specific times are
  1351. sorted in between these lines.
  1352. For details about when the grid will be shown, and what it will look like, see
  1353. the variable `org-agenda-time-grid'."
  1354. :group 'org-agenda-time-grid
  1355. :type 'boolean)
  1356. (defcustom org-agenda-time-grid
  1357. (let ((graphical (and (display-graphic-p)
  1358. (char-displayable-p ?┄))))
  1359. `((daily today require-timed)
  1360. (800 1000 1200 1400 1600 1800 2000)
  1361. ,(if graphical " ┄┄┄┄┄ " "......")
  1362. ,(if graphical "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄" "----------------")))
  1363. "The settings for time grid for agenda display.
  1364. This is a list of four items. The first item is again a list. It contains
  1365. symbols specifying conditions when the grid should be displayed:
  1366. daily if the agenda shows a single day
  1367. weekly if the agenda shows an entire week
  1368. today show grid on current date, independent of daily/weekly display
  1369. require-timed show grid only if at least one item has a time specification
  1370. remove-match skip grid times already present in an entry
  1371. The second item is a list of integers, indicating the times that
  1372. should have a grid line.
  1373. The third item is a string which will be placed right after the
  1374. times that have a grid line.
  1375. The fourth item is a string placed after the grid times. This
  1376. will align with agenda items."
  1377. :group 'org-agenda-time-grid
  1378. :version "29.1"
  1379. :type
  1380. '(list
  1381. (set :greedy t :tag "Grid Display Options"
  1382. (const :tag "Show grid in single day agenda display" daily)
  1383. (const :tag "Show grid in weekly agenda display" weekly)
  1384. (const :tag "Always show grid for today" today)
  1385. (const :tag "Show grid only if any timed entries are present"
  1386. require-timed)
  1387. (const :tag "Skip grid times already present in an entry"
  1388. remove-match))
  1389. (repeat :tag "Grid Times" (integer :tag "Time"))
  1390. (string :tag "Grid String (after agenda times)")
  1391. (string :tag "Grid String (aligns with agenda items)")))
  1392. (defcustom org-agenda-show-current-time-in-grid t
  1393. "Non-nil means show the current time in the time grid."
  1394. :group 'org-agenda-time-grid
  1395. :version "24.1"
  1396. :type 'boolean)
  1397. (defcustom org-agenda-current-time-string
  1398. (if (and (display-graphic-p)
  1399. (char-displayable-p ?⭠)
  1400. (char-displayable-p ?─))
  1401. "⭠ now ───────────────────────────────────────────────"
  1402. "now - - - - - - - - - - - - - - - - - - - - - - - - -")
  1403. "The string for the current time marker in the agenda."
  1404. :group 'org-agenda-time-grid
  1405. :version "29.1"
  1406. :type 'string)
  1407. (defgroup org-agenda-sorting nil
  1408. "Options concerning sorting in the Org Agenda."
  1409. :tag "Org Agenda Sorting"
  1410. :group 'org-agenda)
  1411. (defcustom org-agenda-sorting-strategy
  1412. '((agenda habit-down time-up priority-down category-keep)
  1413. (todo priority-down category-keep)
  1414. (tags priority-down category-keep)
  1415. (search category-keep))
  1416. "Sorting structure for the agenda items of a single day.
  1417. This is a list of symbols which will be used in sequence to determine
  1418. if an entry should be listed before another entry. The following
  1419. symbols are recognized:
  1420. time-up Put entries with time-of-day indications first, early first.
  1421. time-down Put entries with time-of-day indications first, late first.
  1422. timestamp-up Sort by any timestamp, early first.
  1423. timestamp-down Sort by any timestamp, late first.
  1424. scheduled-up Sort by scheduled timestamp, early first.
  1425. scheduled-down Sort by scheduled timestamp, late first.
  1426. deadline-up Sort by deadline timestamp, early first.
  1427. deadline-down Sort by deadline timestamp, late first.
  1428. ts-up Sort by active timestamp, early first.
  1429. ts-down Sort by active timestamp, late first.
  1430. tsia-up Sort by inactive timestamp, early first.
  1431. tsia-down Sort by inactive timestamp, late first.
  1432. category-keep Keep the default order of categories, corresponding to the
  1433. sequence in `org-agenda-files'.
  1434. category-up Sort alphabetically by category, A-Z.
  1435. category-down Sort alphabetically by category, Z-A.
  1436. tag-up Sort alphabetically by last tag, A-Z.
  1437. tag-down Sort alphabetically by last tag, Z-A.
  1438. priority-up Sort numerically by priority, high priority last.
  1439. priority-down Sort numerically by priority, high priority first.
  1440. todo-state-up Sort by todo state, tasks that are done last.
  1441. todo-state-down Sort by todo state, tasks that are done first.
  1442. effort-up Sort numerically by estimated effort, high effort last.
  1443. effort-down Sort numerically by estimated effort, high effort first.
  1444. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1445. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1446. habit-up Put entries that are habits first.
  1447. habit-down Put entries that are habits last.
  1448. alpha-up Sort headlines alphabetically.
  1449. alpha-down Sort headlines alphabetically, reversed.
  1450. The different possibilities will be tried in sequence, and testing stops
  1451. if one comparison returns a \"not-equal\". For example, the default
  1452. \\='(time-up category-keep priority-down)
  1453. means: Pull out all entries having a specified time of day and sort them,
  1454. in order to make a time schedule for the current day the first thing in the
  1455. agenda listing for the day. Of the entries without a time indication, keep
  1456. the grouped in categories, don't sort the categories, but keep them in
  1457. the sequence given in `org-agenda-files'. Within each category sort by
  1458. priority.
  1459. Leaving out `category-keep' would mean that items will be sorted across
  1460. categories by priority.
  1461. Instead of a single list, this can also be a set of list for specific
  1462. contents, with a context symbol in the car of the list, any of
  1463. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1464. Custom commands can bind this variable in the options section."
  1465. :group 'org-agenda-sorting
  1466. :type `(choice
  1467. (repeat :tag "General" ,org-sorting-choice)
  1468. (list :tag "Individually"
  1469. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1470. (repeat ,org-sorting-choice))
  1471. (cons (const :tag "Strategy for TODO lists" todo)
  1472. (repeat ,org-sorting-choice))
  1473. (cons (const :tag "Strategy for Tags matches" tags)
  1474. (repeat ,org-sorting-choice))
  1475. (cons (const :tag "Strategy for search matches" search)
  1476. (repeat ,org-sorting-choice)))))
  1477. (defcustom org-agenda-cmp-user-defined nil
  1478. "A function to define the comparison `user-defined'.
  1479. This function must receive two arguments, agenda entry a and b.
  1480. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1481. the user comparison, return nil.
  1482. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1483. part of an agenda sorting strategy."
  1484. :group 'org-agenda-sorting
  1485. :type 'symbol)
  1486. (defcustom org-agenda-sort-notime-is-late t
  1487. "Non-nil means items without time are considered late.
  1488. This is only relevant for sorting. When t, items which have no explicit
  1489. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1490. do have a time. When nil, the default time is before 0:00. You can use this
  1491. option to decide if the schedule for today should come before or after timeless
  1492. agenda entries."
  1493. :group 'org-agenda-sorting
  1494. :type 'boolean)
  1495. (defcustom org-agenda-sort-noeffort-is-high t
  1496. "Non-nil means items without effort estimate are sorted as high effort.
  1497. This also applies when filtering an agenda view with respect to the
  1498. < or > effort operator. Then, tasks with no effort defined will be treated
  1499. as tasks with high effort.
  1500. When nil, such items are sorted as 0 minutes effort."
  1501. :group 'org-agenda-sorting
  1502. :type 'boolean)
  1503. (defgroup org-agenda-line-format nil
  1504. "Options concerning the entry prefix in the Org agenda display."
  1505. :tag "Org Agenda Line Format"
  1506. :group 'org-agenda)
  1507. (defcustom org-agenda-prefix-format
  1508. '((agenda . " %i %-12:c%?-12t% s")
  1509. (todo . " %i %-12:c")
  1510. (tags . " %i %-12:c")
  1511. (search . " %i %-12:c"))
  1512. "Format specifications for the prefix of items in the agenda views.
  1513. An alist with one entry per agenda type. The keys of the
  1514. sublists are `agenda', `todo', `search' and `tags'. The values
  1515. are format strings.
  1516. This format works similar to a printf format, with the following meaning:
  1517. %c the category of the item, \"Diary\" for entries from the diary,
  1518. or as given by the CATEGORY keyword or derived from the file name
  1519. %e the effort required by the item
  1520. %l the level of the item (insert X space(s) if item is of level X)
  1521. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1522. %T the last tag of the item (ignore inherited tags, which come first)
  1523. %t the HH:MM time-of-day specification if one applies to the entry
  1524. %s Scheduling/Deadline information, a short string
  1525. %b show breadcrumbs, i.e., the names of the higher levels
  1526. %(expression) Eval EXPRESSION and replace the control string
  1527. by the result
  1528. All specifiers work basically like the standard `%s' of printf, but may
  1529. contain two additional characters: a question mark just after the `%'
  1530. and a whitespace/punctuation character just before the final letter.
  1531. If the first character after `%' is a question mark, the entire field
  1532. will only be included if the corresponding value applies to the current
  1533. entry. This is useful for fields which should have fixed width when
  1534. present, but zero width when absent. For example, \"%?-12t\" will
  1535. result in a 12 character time field if a time of the day is specified,
  1536. but will completely disappear in entries which do not contain a time.
  1537. If there is punctuation or whitespace character just before the
  1538. final format letter, this character will be appended to the field
  1539. value if the value is not empty. For example, the format
  1540. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1541. the category is empty, no additional colon is inserted.
  1542. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1543. which means:
  1544. - Indent the line with two space characters
  1545. - Give the category a 12 chars wide field, padded with whitespace on
  1546. the right (because of `-'). Append a colon if there is a category
  1547. (because of `:').
  1548. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1549. time, don't put in an empty field, just skip it (because of '?').
  1550. - Finally, put the scheduling information.
  1551. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1552. `org-agenda-remove-tags'.
  1553. Custom commands can set this variable in the options section."
  1554. :type '(choice
  1555. (string :tag "General format")
  1556. (list :greedy t :tag "View dependent"
  1557. (cons (const agenda) (string :tag "Format"))
  1558. (cons (const todo) (string :tag "Format"))
  1559. (cons (const tags) (string :tag "Format"))
  1560. (cons (const search) (string :tag "Format"))))
  1561. :group 'org-agenda-line-format
  1562. :version "26.1"
  1563. :package-version '(Org . "9.1"))
  1564. (defcustom org-agenda-breadcrumbs-separator "->"
  1565. "The separator of breadcrumbs in agenda lines."
  1566. :group 'org-agenda-line-format
  1567. :package-version '(Org . "9.3")
  1568. :type 'string
  1569. :safe #'stringp)
  1570. (defvar org-prefix-format-compiled nil
  1571. "The compiled prefix format and associated variables.
  1572. This is a list where first element is a list of variable bindings, and second
  1573. element is the compiled format expression. See the variable
  1574. `org-agenda-prefix-format'.")
  1575. (defcustom org-agenda-todo-keyword-format "%-1s"
  1576. "Format for the TODO keyword in agenda lines.
  1577. Set this to something like \"%-12s\" if you want all TODO keywords
  1578. to occupy a fixed space in the agenda display."
  1579. :group 'org-agenda-line-format
  1580. :type 'string)
  1581. (defcustom org-agenda-diary-sexp-prefix nil
  1582. "A regexp that matches part of a diary sexp entry
  1583. which should be treated as scheduling/deadline information in
  1584. `org-agenda'.
  1585. For example, you can use this to extract the `diary-remind-message' from
  1586. `diary-remind' entries."
  1587. :group 'org-agenda-line-format
  1588. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1589. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1590. "Text preceding timerange entries in the agenda view.
  1591. This is a list with two strings. The first applies when the range
  1592. is entirely on one day. The second applies if the range spans several days.
  1593. The strings may have two \"%d\" format specifiers which will be filled
  1594. with the sequence number of the days, and the total number of days in the
  1595. range, respectively."
  1596. :group 'org-agenda-line-format
  1597. :type '(list
  1598. (string :tag "Deadline today ")
  1599. (choice :tag "Deadline relative"
  1600. (string :tag "Format string")
  1601. (function))))
  1602. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1603. "Text preceding scheduled items in the agenda view.
  1604. This is a list with two strings. The first applies when the item is
  1605. scheduled on the current day. The second applies when it has been scheduled
  1606. previously, it may contain a %d indicating that this is the nth time that
  1607. this item is scheduled, due to automatic rescheduling of unfinished items
  1608. for the following day. So this number is one larger than the number of days
  1609. that passed since this item was scheduled first."
  1610. :group 'org-agenda-line-format
  1611. :version "24.4"
  1612. :package-version '(Org . "8.0")
  1613. :type '(list
  1614. (string :tag "Scheduled today ")
  1615. (string :tag "Scheduled previously")))
  1616. (defcustom org-agenda-inactive-leader "["
  1617. "Text preceding item pulled into the agenda by inactive time stamps.
  1618. These entries are added to the agenda when pressing \"[\"."
  1619. :group 'org-agenda-line-format
  1620. :version "24.1"
  1621. :type 'string)
  1622. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1623. "Text preceding deadline items in the agenda view.
  1624. This is a list with three strings. The first applies when the item has its
  1625. deadline on the current day. The second applies when the deadline is in the
  1626. future, the third one when it is in the past. The strings may contain %d
  1627. to capture the number of days."
  1628. :group 'org-agenda-line-format
  1629. :version "24.4"
  1630. :package-version '(Org . "8.0")
  1631. :type '(list
  1632. (string :tag "Deadline today ")
  1633. (string :tag "Deadline in the future ")
  1634. (string :tag "Deadline in the past ")))
  1635. (defcustom org-agenda-remove-times-when-in-prefix t
  1636. "Non-nil means remove duplicate time specifications in agenda items.
  1637. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1638. time-of-day specification in a headline or diary entry is extracted and
  1639. placed into the prefix. If this option is non-nil, the original specification
  1640. \(a timestamp or -range, or just a plain time(range) specification like
  1641. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1642. cluttered.
  1643. The option can be t or nil. It may also be the symbol `beg', indicating
  1644. that the time should only be removed when it is located at the beginning of
  1645. the headline/diary entry."
  1646. :group 'org-agenda-line-format
  1647. :type '(choice
  1648. (const :tag "Always" t)
  1649. (const :tag "Never" nil)
  1650. (const :tag "When at beginning of entry" beg)))
  1651. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1652. "Non-nil means remove time ranges specifications in agenda
  1653. items that span on several days."
  1654. :group 'org-agenda-line-format
  1655. :version "24.1"
  1656. :type 'boolean)
  1657. (defcustom org-agenda-default-appointment-duration nil
  1658. "Default duration for appointments that only have a starting time.
  1659. When nil, no duration is specified in such cases.
  1660. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1661. :group 'org-agenda-line-format
  1662. :type '(choice
  1663. (integer :tag "Minutes")
  1664. (const :tag "No default duration")))
  1665. (defcustom org-agenda-show-inherited-tags t
  1666. "Non-nil means show inherited tags in each agenda line.
  1667. When this option is set to `always', it takes precedence over
  1668. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1669. in every agenda.
  1670. When this option is set to t (the default), inherited tags are
  1671. shown when they are available, i.e. when the value of
  1672. `org-agenda-use-tag-inheritance' enables tag inheritance for the
  1673. given agenda type.
  1674. This can be set to a list of agenda types in which the agenda
  1675. must display the inherited tags. Available types are `todo',
  1676. `agenda' and `search'.
  1677. When set to nil, never show inherited tags in agenda lines."
  1678. :group 'org-agenda-line-format
  1679. :group 'org-agenda
  1680. :version "24.3"
  1681. :type '(choice
  1682. (const :tag "Show inherited tags when available" t)
  1683. (const :tag "Always show inherited tags" always)
  1684. (repeat :tag "Show inherited tags only in selected agenda types"
  1685. (symbol :tag "Agenda type"))))
  1686. (defcustom org-agenda-use-tag-inheritance '(todo search agenda)
  1687. "List of agenda view types where to use tag inheritance.
  1688. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1689. controlled by `org-use-tag-inheritance'. In other agenda types,
  1690. `org-use-tag-inheritance' is not used for the selection of the
  1691. agenda entries. Still, you may want the agenda to be aware of
  1692. the inherited tags anyway, e.g. for later tag filtering.
  1693. Allowed value are `todo', `search' and `agenda'.
  1694. This variable has no effect if `org-agenda-show-inherited-tags'
  1695. is set to `always'. In that case, the agenda is aware of those
  1696. tags.
  1697. The default value sets tags in every agenda type. Setting this
  1698. option to nil will speed up non-tags agenda view a lot."
  1699. :group 'org-agenda
  1700. :version "26.1"
  1701. :package-version '(Org . "9.1")
  1702. :type '(choice
  1703. (const :tag "Use tag inheritance in all agenda types" t)
  1704. (repeat :tag "Use tag inheritance in selected agenda types"
  1705. (symbol :tag "Agenda type"))))
  1706. (defcustom org-agenda-hide-tags-regexp nil
  1707. "Regular expression used to filter away specific tags in agenda views.
  1708. This means that these tags will be present, but not be shown in the agenda
  1709. line. Secondary filtering will still work on the hidden tags.
  1710. Nil means don't hide any tags."
  1711. :group 'org-agenda-line-format
  1712. :type '(choice
  1713. (const :tag "Hide none" nil)
  1714. (regexp :tag "Regexp ")))
  1715. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1716. 'org-agenda-remove-tags)
  1717. (defcustom org-agenda-remove-tags nil
  1718. "Non-nil means remove the tags from the headline copy in the agenda.
  1719. When this is the symbol `prefix', only remove tags when
  1720. `org-agenda-prefix-format' contains a `%T' specifier."
  1721. :group 'org-agenda-line-format
  1722. :type '(choice
  1723. (const :tag "Always" t)
  1724. (const :tag "Never" nil)
  1725. (const :tag "When prefix format contains %T" prefix)))
  1726. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1727. (defcustom org-agenda-tags-column 'auto
  1728. "Shift tags in agenda items to this column.
  1729. If set to `auto', tags will be automatically aligned to the right
  1730. edge of the window.
  1731. If set to a positive number, tags will be left-aligned to that
  1732. column. If set to a negative number, tags will be right-aligned
  1733. to that column. For example, -80 works well for a normal 80
  1734. character screen."
  1735. :group 'org-agenda-line-format
  1736. :type '(choice
  1737. (const :tag "Automatically align to right edge of window" auto)
  1738. (integer :tag "Specific column" -80))
  1739. :package-version '(Org . "9.1")
  1740. :version "26.1")
  1741. (defcustom org-agenda-fontify-priorities 'cookies
  1742. "Non-nil means highlight low and high priorities in agenda.
  1743. When t, the highest priority entries are bold, lowest priority italic.
  1744. However, settings in `org-priority-faces' will overrule these faces.
  1745. When this variable is the symbol `cookies', only fontify the
  1746. cookies, not the entire task.
  1747. This may also be an association list of priority faces, whose
  1748. keys are the character values of `org-priority-highest',
  1749. `org-priority-default', and `org-priority-lowest' (the default values
  1750. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1751. color as a string, or a list like `(:background \"Red\")'.
  1752. If it is a color, the variable `org-faces-easy-properties'
  1753. determines if it is a foreground or a background color."
  1754. :group 'org-agenda-line-format
  1755. :type '(choice
  1756. (const :tag "Never" nil)
  1757. (const :tag "Defaults" t)
  1758. (const :tag "Cookies only" cookies)
  1759. (repeat :tag "Specify"
  1760. (list (character :tag "Priority" :value ?A)
  1761. (choice :tag "Face "
  1762. (string :tag "Color")
  1763. (sexp :tag "Face"))))))
  1764. (defcustom org-agenda-day-face-function nil
  1765. "Function called to determine what face should be used to display a day.
  1766. The only argument passed to that function is the day. It should
  1767. returns a face, or nil if does not want to specify a face and let
  1768. the normal rules apply."
  1769. :group 'org-agenda-line-format
  1770. :version "24.1"
  1771. :type '(choice (const nil) (function)))
  1772. (defcustom org-agenda-category-icon-alist nil
  1773. "Alist of category icon to be displayed in agenda views.
  1774. Each entry should have the following format:
  1775. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1776. Where CATEGORY-REGEXP is a regexp matching the categories where
  1777. the icon should be displayed.
  1778. FILE-OR-DATA either a file path or a string containing image data.
  1779. The other fields can be omitted safely if not needed:
  1780. TYPE indicates the image type.
  1781. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1782. image data.
  1783. PROPS are additional image attributes to assign to the image,
  1784. like, e.g. `:ascent center'.
  1785. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1786. If you want to set the display properties yourself, just put a
  1787. list as second element:
  1788. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1789. For example, to display a 16px horizontal space for Emacs
  1790. category, you can use:
  1791. (\"Emacs\" \\='(space . (:width (16))))"
  1792. :group 'org-agenda-line-format
  1793. :version "24.1"
  1794. :type '(alist :key-type (regexp :tag "Regexp matching category")
  1795. :value-type (choice (list :tag "Icon"
  1796. (string :tag "File or data")
  1797. (symbol :tag "Type")
  1798. (boolean :tag "Data?")
  1799. (repeat :tag "Extra image properties" :inline t sexp))
  1800. (list :tag "Display properties" sexp))))
  1801. (defgroup org-agenda-column-view nil
  1802. "Options concerning column view in the agenda."
  1803. :tag "Org Agenda Column View"
  1804. :group 'org-agenda)
  1805. (defcustom org-agenda-view-columns-initially nil
  1806. "When non-nil, switch to columns view right after creating the agenda."
  1807. :group 'org-agenda-column-view
  1808. :type 'boolean
  1809. :version "26.1"
  1810. :package-version '(Org . "9.0")
  1811. :safe #'booleanp)
  1812. (defcustom org-agenda-columns-show-summaries t
  1813. "Non-nil means show summaries for columns displayed in the agenda view."
  1814. :group 'org-agenda-column-view
  1815. :type 'boolean)
  1816. (defcustom org-agenda-columns-compute-summary-properties t
  1817. "Non-nil means recompute all summary properties before column view.
  1818. When column view in the agenda is listing properties that have a summary
  1819. operator, it can go to all relevant buffers and recompute the summaries
  1820. there. This can mean overhead for the agenda column view, but is necessary
  1821. to have thing up to date.
  1822. As a special case, a CLOCKSUM property also makes sure that the clock
  1823. computations are current."
  1824. :group 'org-agenda-column-view
  1825. :type 'boolean)
  1826. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1827. "Non-nil means the duration of an appointment will add to day effort.
  1828. The property to which appointment durations will be added is the one given
  1829. in the option `org-effort-property'. If an appointment does not have
  1830. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1831. is not set, an appointment without end time will not contribute to the time
  1832. estimate."
  1833. :group 'org-agenda-column-view
  1834. :type 'boolean)
  1835. (defcustom org-agenda-auto-exclude-function nil
  1836. "A function called with a tag to decide if it is filtered on \
  1837. \\<org-agenda-mode-map>`\\[org-agenda-filter-by-tag] RET'.
  1838. The sole argument to the function, which is called once for each
  1839. possible tag, is a string giving the name of the tag. The
  1840. function should return either nil if the tag should be included
  1841. as normal, \"-<TAG>\" to exclude the tag, or \"+<TAG>\" to exclude
  1842. lines not carrying this tag.
  1843. Note that for the purpose of tag filtering, only the lower-case version of
  1844. all tags will be considered, so that this function will only ever see
  1845. the lower-case version of all tags."
  1846. :group 'org-agenda
  1847. :type '(choice (const nil) (function)))
  1848. (defcustom org-agenda-bulk-custom-functions nil
  1849. "Alist of characters and custom functions for bulk actions.
  1850. For example, this value makes those two functions available:
  1851. \\='((?R set-category)
  1852. (?C bulk-cut))
  1853. With selected entries in an agenda buffer, `B R' will call
  1854. the custom function `set-category' on the selected entries.
  1855. Note that functions in this alist don't need to be quoted.
  1856. You can also specify a function which collects arguments to be
  1857. used for each call to your bulk custom function. The argument
  1858. collecting function will be run once and should return a list of
  1859. arguments to pass to the bulk function. For example:
  1860. \\='((?R set-category get-category))
  1861. Now, `B R' will call the custom `get-category' which would prompt
  1862. the user once for a category. That category is then passed as an
  1863. argument to `set-category' for each entry it's called against."
  1864. :type
  1865. '(alist :key-type character
  1866. :value-type
  1867. (group (function :tag "Bulk Custom Function")
  1868. (choice (function :tag "Bulk Custom Argument Function")
  1869. (const :tag "No Bulk Custom Argument Function" nil))))
  1870. :package-version '(Org . "9.5")
  1871. :group 'org-agenda)
  1872. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1873. "Execute BODY with point at location given by `org-hd-marker' property.
  1874. If STRING is non-nil, the text property will be fetched from position 0
  1875. in that string. If STRING is nil, it will be fetched from the beginning
  1876. of the current line."
  1877. (declare (debug t) (indent 1))
  1878. (org-with-gensyms (marker)
  1879. `(let ((,marker (get-text-property (if ,string 0 (point-at-bol))
  1880. 'org-hd-marker ,string)))
  1881. (with-current-buffer (marker-buffer ,marker)
  1882. (save-excursion
  1883. (goto-char ,marker)
  1884. ,@body)))))
  1885. (defun org-add-agenda-custom-command (entry)
  1886. "Replace or add a command in `org-agenda-custom-commands'.
  1887. This is mostly for hacking and trying a new command - once the command
  1888. works you probably want to add it to `org-agenda-custom-commands' for good."
  1889. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1890. (if ass
  1891. (setcdr ass (cdr entry))
  1892. (push entry org-agenda-custom-commands))))
  1893. (defmacro org-agenda--insert-overriding-header (default)
  1894. "Insert header into agenda view.
  1895. The inserted header depends on `org-agenda-overriding-header'.
  1896. If the empty string, don't insert a header. If any other string,
  1897. insert it as a header. If nil, insert DEFAULT, which should
  1898. evaluate to a string. If a function, call it and insert the
  1899. string that it returns."
  1900. (declare (debug (form)) (indent defun))
  1901. `(cond
  1902. ((not org-agenda-overriding-header) (insert ,default))
  1903. ((equal org-agenda-overriding-header "") nil)
  1904. ((stringp org-agenda-overriding-header)
  1905. (insert (propertize org-agenda-overriding-header
  1906. 'face 'org-agenda-structure)
  1907. "\n"))
  1908. ((functionp org-agenda-overriding-header)
  1909. (insert (funcall org-agenda-overriding-header)))
  1910. (t (user-error "Invalid value for `org-agenda-overriding-header': %S"
  1911. org-agenda-overriding-header))))
  1912. ;;; Define the org-agenda-mode
  1913. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1914. (defvar org-agenda-mode-map (make-sparse-keymap)
  1915. "Keymap for `org-agenda-mode'.")
  1916. (org-remap org-agenda-mode-map 'move-end-of-line 'org-agenda-end-of-line)
  1917. (defvar org-agenda-menu) ; defined later in this file.
  1918. (defvar org-agenda-restrict nil)
  1919. (defvar org-agenda-follow-mode nil)
  1920. (defvar org-agenda-entry-text-mode nil)
  1921. (defvar org-agenda-clockreport-mode nil)
  1922. (defvar org-agenda-show-log nil
  1923. "When non-nil, show the log in the agenda.
  1924. Do not set this directly; instead use
  1925. `org-agenda-start-with-log-mode', which see.")
  1926. (defvar org-agenda-redo-command nil)
  1927. (defvar org-agenda-query-string nil)
  1928. (defvar org-agenda-mode-hook nil
  1929. "Hook run after `org-agenda-mode' is turned on.
  1930. The buffer is still writable when this hook is called.")
  1931. (defvar org-agenda-type nil)
  1932. (defvar org-agenda-force-single-file nil)
  1933. (defvar org-agenda-bulk-marked-entries nil
  1934. "List of markers that refer to marked entries in the agenda.")
  1935. (defvar org-agenda-current-date nil
  1936. "Active date when building the agenda.")
  1937. ;;; Multiple agenda buffers support
  1938. (defcustom org-agenda-sticky nil
  1939. "Non-nil means agenda q key will bury agenda buffers.
  1940. Agenda commands will then show existing buffer instead of generating new ones.
  1941. When nil, `q' will kill the single agenda buffer."
  1942. :group 'org-agenda
  1943. :version "24.3"
  1944. :type 'boolean)
  1945. ;;;###autoload
  1946. (defun org-toggle-sticky-agenda (&optional arg)
  1947. "Toggle `org-agenda-sticky'."
  1948. (interactive "P")
  1949. (let ((new-value (if arg
  1950. (> (prefix-numeric-value arg) 0)
  1951. (not org-agenda-sticky))))
  1952. (if (equal new-value org-agenda-sticky)
  1953. (and (called-interactively-p 'interactive)
  1954. (message "Sticky agenda was already %s"
  1955. (if org-agenda-sticky "enabled" "disabled")))
  1956. (setq org-agenda-sticky new-value)
  1957. (org-agenda-kill-all-agenda-buffers)
  1958. (and (called-interactively-p 'interactive)
  1959. (message "Sticky agenda %s"
  1960. (if org-agenda-sticky "enabled" "disabled"))))))
  1961. (defvar org-agenda-buffer nil
  1962. "Agenda buffer currently being generated.")
  1963. (defvar org-agenda-last-prefix-arg nil)
  1964. (defvar org-agenda-this-buffer-name nil)
  1965. (defvar org-agenda-doing-sticky-redo nil)
  1966. (defvar org-agenda-this-buffer-is-sticky nil)
  1967. (defvar org-agenda-last-indirect-buffer nil
  1968. "Last buffer loaded by `org-agenda-tree-to-indirect-buffer'.")
  1969. (defconst org-agenda-local-vars
  1970. '(org-agenda-this-buffer-name
  1971. org-agenda-undo-list
  1972. org-agenda-pending-undo-list
  1973. org-agenda-follow-mode
  1974. org-agenda-entry-text-mode
  1975. org-agenda-clockreport-mode
  1976. org-agenda-show-log
  1977. org-agenda-redo-command
  1978. org-agenda-query-string
  1979. org-agenda-type
  1980. org-agenda-bulk-marked-entries
  1981. org-agenda-undo-has-started-in
  1982. org-agenda-info
  1983. org-agenda-pre-window-conf
  1984. org-agenda-columns-active
  1985. org-agenda-tag-filter
  1986. org-agenda-category-filter
  1987. org-agenda-top-headline-filter
  1988. org-agenda-regexp-filter
  1989. org-agenda-effort-filter
  1990. org-agenda-markers
  1991. org-agenda-last-search-view-search-was-boolean
  1992. org-agenda-last-indirect-buffer
  1993. org-agenda-filtered-by-category
  1994. org-agenda-filter-form
  1995. org-agenda-cycle-counter
  1996. org-agenda-last-prefix-arg)
  1997. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1998. (defun org-agenda-mode ()
  1999. "Mode for time-sorted view on action items in Org files.
  2000. The following commands are available:
  2001. \\{org-agenda-mode-map}"
  2002. (interactive)
  2003. (ignore-errors (require 'face-remap))
  2004. (let ((agenda-local-vars-to-keep
  2005. '(text-scale-mode-amount
  2006. text-scale-mode
  2007. text-scale-mode-lighter
  2008. face-remapping-alist))
  2009. (save (buffer-local-variables)))
  2010. (kill-all-local-variables)
  2011. (cl-flet ((reset-saved (var-set)
  2012. "Reset variables in VAR-SET to possibly stored value in SAVE."
  2013. (dolist (elem save)
  2014. (pcase elem
  2015. (`(,var . ,val) ;ignore unbound variables
  2016. (when (and val (memq var var-set))
  2017. (set var val)))))))
  2018. (cond (org-agenda-doing-sticky-redo
  2019. ;; Refreshing sticky agenda-buffer
  2020. ;;
  2021. ;; Preserve the value of `org-agenda-local-vars' variables.
  2022. (mapc #'make-local-variable org-agenda-local-vars)
  2023. (reset-saved org-agenda-local-vars)
  2024. (setq-local org-agenda-this-buffer-is-sticky t))
  2025. (org-agenda-sticky
  2026. ;; Creating a sticky Agenda buffer for the first time
  2027. (mapc #'make-local-variable org-agenda-local-vars)
  2028. (setq-local org-agenda-this-buffer-is-sticky t))
  2029. (t
  2030. ;; Creating a non-sticky agenda buffer
  2031. (setq-local org-agenda-this-buffer-is-sticky nil)))
  2032. (mapc #'make-local-variable agenda-local-vars-to-keep)
  2033. (reset-saved agenda-local-vars-to-keep)))
  2034. (setq org-agenda-undo-list nil
  2035. org-agenda-pending-undo-list nil
  2036. org-agenda-bulk-marked-entries nil)
  2037. (setq major-mode 'org-agenda-mode)
  2038. ;; Keep global-font-lock-mode from turning on font-lock-mode
  2039. (setq-local font-lock-global-modes (list 'not major-mode))
  2040. (setq mode-name "Org-Agenda")
  2041. (setq indent-tabs-mode nil)
  2042. (use-local-map org-agenda-mode-map)
  2043. (when org-startup-truncated (setq truncate-lines t))
  2044. (setq-local line-move-visual nil)
  2045. (add-hook 'post-command-hook #'org-agenda-update-agenda-type nil 'local)
  2046. (add-hook 'pre-command-hook #'org-unhighlight nil 'local)
  2047. ;; Make sure properties are removed when copying text
  2048. (if (boundp 'filter-buffer-substring-functions)
  2049. (add-hook 'filter-buffer-substring-functions
  2050. (lambda (fun start end delete)
  2051. (substring-no-properties (funcall fun start end delete)))
  2052. nil t)
  2053. ;; Emacs >= 24.4.
  2054. (add-function :filter-return (local 'filter-buffer-substring-function)
  2055. #'substring-no-properties))
  2056. (unless org-agenda-keep-modes
  2057. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  2058. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  2059. org-agenda-show-log org-agenda-start-with-log-mode
  2060. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode))
  2061. (add-to-invisibility-spec '(org-filtered))
  2062. (org-fold-core-initialize `(,org-link--description-folding-spec
  2063. ,org-link--link-folding-spec))
  2064. (easy-menu-change
  2065. '("Agenda") "Agenda Files"
  2066. (append
  2067. (list
  2068. (vector
  2069. (if (get 'org-agenda-files 'org-restrict)
  2070. "Restricted to single file"
  2071. "Edit File List")
  2072. '(org-edit-agenda-file-list)
  2073. (not (get 'org-agenda-files 'org-restrict)))
  2074. "--")
  2075. (mapcar #'org-file-menu-entry (org-agenda-files))))
  2076. (org-agenda-set-mode-name)
  2077. (run-mode-hooks 'org-agenda-mode-hook))
  2078. (substitute-key-definition #'undo #'org-agenda-undo
  2079. org-agenda-mode-map global-map)
  2080. (org-defkey org-agenda-mode-map "\C-i" #'org-agenda-goto)
  2081. (org-defkey org-agenda-mode-map [(tab)] #'org-agenda-goto)
  2082. (org-defkey org-agenda-mode-map "\C-m" #'org-agenda-switch-to)
  2083. (org-defkey org-agenda-mode-map "\C-k" #'org-agenda-kill)
  2084. (org-defkey org-agenda-mode-map "\C-c\C-w" #'org-agenda-refile)
  2085. (org-defkey org-agenda-mode-map [(meta down)] #'org-agenda-drag-line-forward)
  2086. (org-defkey org-agenda-mode-map [(meta up)] #'org-agenda-drag-line-backward)
  2087. (org-defkey org-agenda-mode-map "m" #'org-agenda-bulk-mark)
  2088. (org-defkey org-agenda-mode-map "\M-m" #'org-agenda-bulk-toggle)
  2089. (org-defkey org-agenda-mode-map "*" #'org-agenda-bulk-mark-all)
  2090. (org-defkey org-agenda-mode-map "\M-*" #'org-agenda-bulk-toggle-all)
  2091. (org-defkey org-agenda-mode-map "#" #'org-agenda-dim-blocked-tasks)
  2092. (org-defkey org-agenda-mode-map "%" #'org-agenda-bulk-mark-regexp)
  2093. (org-defkey org-agenda-mode-map "u" #'org-agenda-bulk-unmark)
  2094. (org-defkey org-agenda-mode-map "U" #'org-agenda-bulk-unmark-all)
  2095. (org-defkey org-agenda-mode-map "B" #'org-agenda-bulk-action)
  2096. (org-defkey org-agenda-mode-map "k" #'org-agenda-capture)
  2097. (org-defkey org-agenda-mode-map "A" #'org-agenda-append-agenda)
  2098. (org-defkey org-agenda-mode-map "\C-c\C-x!" #'org-reload)
  2099. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" #'org-agenda-archive-default)
  2100. (org-defkey org-agenda-mode-map "\C-c\C-xa" #'org-agenda-toggle-archive-tag)
  2101. (org-defkey org-agenda-mode-map "\C-c\C-xA" #'org-agenda-archive-to-archive-sibling)
  2102. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" #'org-agenda-archive)
  2103. (org-defkey org-agenda-mode-map "\C-c$" #'org-agenda-archive)
  2104. (org-defkey org-agenda-mode-map "$" #'org-agenda-archive)
  2105. (org-defkey org-agenda-mode-map "\C-c\C-o" #'org-agenda-open-link)
  2106. (org-defkey org-agenda-mode-map " " #'org-agenda-show-and-scroll-up)
  2107. (org-defkey org-agenda-mode-map [backspace] #'org-agenda-show-scroll-down)
  2108. (org-defkey org-agenda-mode-map "\d" #'org-agenda-show-scroll-down)
  2109. (org-defkey org-agenda-mode-map [(control shift right)] #'org-agenda-todo-nextset)
  2110. (org-defkey org-agenda-mode-map [(control shift left)] #'org-agenda-todo-previousset)
  2111. (org-defkey org-agenda-mode-map "\C-c\C-xb" #'org-agenda-tree-to-indirect-buffer)
  2112. (org-defkey org-agenda-mode-map "o" #'delete-other-windows)
  2113. (org-defkey org-agenda-mode-map "L" #'org-agenda-recenter)
  2114. (org-defkey org-agenda-mode-map "\C-c\C-t" #'org-agenda-todo)
  2115. (org-defkey org-agenda-mode-map "t" #'org-agenda-todo)
  2116. (org-defkey org-agenda-mode-map "a" #'org-agenda-archive-default-with-confirmation)
  2117. (org-defkey org-agenda-mode-map ":" #'org-agenda-set-tags)
  2118. (org-defkey org-agenda-mode-map "\C-c\C-q" #'org-agenda-set-tags)
  2119. (org-defkey org-agenda-mode-map "." #'org-agenda-goto-today)
  2120. (org-defkey org-agenda-mode-map "j" #'org-agenda-goto-date)
  2121. (org-defkey org-agenda-mode-map "d" #'org-agenda-day-view)
  2122. (org-defkey org-agenda-mode-map "w" #'org-agenda-week-view)
  2123. (org-defkey org-agenda-mode-map "y" #'org-agenda-year-view)
  2124. (org-defkey org-agenda-mode-map "\C-c\C-z" #'org-agenda-add-note)
  2125. (org-defkey org-agenda-mode-map "z" #'org-agenda-add-note)
  2126. (org-defkey org-agenda-mode-map [(shift right)] #'org-agenda-do-date-later)
  2127. (org-defkey org-agenda-mode-map [(shift left)] #'org-agenda-do-date-earlier)
  2128. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] #'org-agenda-do-date-later)
  2129. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] #'org-agenda-do-date-earlier)
  2130. (org-defkey org-agenda-mode-map ">" #'org-agenda-date-prompt)
  2131. (org-defkey org-agenda-mode-map "\C-c\C-s" #'org-agenda-schedule)
  2132. (org-defkey org-agenda-mode-map "\C-c\C-d" #'org-agenda-deadline)
  2133. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  2134. (while l (org-defkey org-agenda-mode-map
  2135. (number-to-string (pop l)) #'digit-argument)))
  2136. (org-defkey org-agenda-mode-map "F" #'org-agenda-follow-mode)
  2137. (org-defkey org-agenda-mode-map "R" #'org-agenda-clockreport-mode)
  2138. (org-defkey org-agenda-mode-map "E" #'org-agenda-entry-text-mode)
  2139. (org-defkey org-agenda-mode-map "l" #'org-agenda-log-mode)
  2140. (org-defkey org-agenda-mode-map "v" #'org-agenda-view-mode-dispatch)
  2141. (org-defkey org-agenda-mode-map "D" #'org-agenda-toggle-diary)
  2142. (org-defkey org-agenda-mode-map "!" #'org-agenda-toggle-deadlines)
  2143. (org-defkey org-agenda-mode-map "G" #'org-agenda-toggle-time-grid)
  2144. (org-defkey org-agenda-mode-map "r" #'org-agenda-redo)
  2145. (org-defkey org-agenda-mode-map "g" #'org-agenda-redo-all)
  2146. (org-defkey org-agenda-mode-map "e" #'org-agenda-set-effort)
  2147. (org-defkey org-agenda-mode-map "\C-c\C-xe" #'org-agenda-set-effort)
  2148. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  2149. #'org-clock-modify-effort-estimate)
  2150. (org-defkey org-agenda-mode-map "\C-c\C-xp" #'org-agenda-set-property)
  2151. (org-defkey org-agenda-mode-map "q" #'org-agenda-quit)
  2152. (org-defkey org-agenda-mode-map "Q" #'org-agenda-Quit)
  2153. (org-defkey org-agenda-mode-map "x" #'org-agenda-exit)
  2154. (org-defkey org-agenda-mode-map "\C-x\C-w" #'org-agenda-write)
  2155. (org-defkey org-agenda-mode-map "\C-x\C-s" #'org-save-all-org-buffers)
  2156. (org-defkey org-agenda-mode-map "s" #'org-save-all-org-buffers)
  2157. (org-defkey org-agenda-mode-map "T" #'org-agenda-show-tags)
  2158. (org-defkey org-agenda-mode-map "n" #'org-agenda-next-line)
  2159. (org-defkey org-agenda-mode-map "p" #'org-agenda-previous-line)
  2160. (org-defkey org-agenda-mode-map "N" #'org-agenda-next-item)
  2161. (org-defkey org-agenda-mode-map "P" #'org-agenda-previous-item)
  2162. (substitute-key-definition #'next-line #'org-agenda-next-line
  2163. org-agenda-mode-map global-map)
  2164. (substitute-key-definition #'previous-line #'org-agenda-previous-line
  2165. org-agenda-mode-map global-map)
  2166. (org-defkey org-agenda-mode-map "\C-c\C-a" #'org-attach)
  2167. (org-defkey org-agenda-mode-map "\C-c\C-n" #'org-agenda-next-date-line)
  2168. (org-defkey org-agenda-mode-map "\C-c\C-p" #'org-agenda-previous-date-line)
  2169. (org-defkey org-agenda-mode-map "\C-c," #'org-agenda-priority)
  2170. (org-defkey org-agenda-mode-map "," #'org-agenda-priority)
  2171. (org-defkey org-agenda-mode-map "i" #'org-agenda-diary-entry)
  2172. (org-defkey org-agenda-mode-map "c" #'org-agenda-goto-calendar)
  2173. (org-defkey org-agenda-mode-map "C" #'org-agenda-convert-date)
  2174. (org-defkey org-agenda-mode-map "M" #'org-agenda-phases-of-moon)
  2175. (org-defkey org-agenda-mode-map "S" #'org-agenda-sunrise-sunset)
  2176. (org-defkey org-agenda-mode-map "h" #'org-agenda-holidays)
  2177. (org-defkey org-agenda-mode-map "H" #'org-agenda-holidays)
  2178. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" #'org-agenda-clock-in)
  2179. (org-defkey org-agenda-mode-map "I" #'org-agenda-clock-in)
  2180. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" #'org-agenda-clock-out)
  2181. (org-defkey org-agenda-mode-map "O" #'org-agenda-clock-out)
  2182. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" #'org-agenda-clock-cancel)
  2183. (org-defkey org-agenda-mode-map "X" #'org-agenda-clock-cancel)
  2184. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" #'org-clock-goto)
  2185. (org-defkey org-agenda-mode-map "J" #'org-agenda-clock-goto)
  2186. (org-defkey org-agenda-mode-map "+" #'org-agenda-priority-up)
  2187. (org-defkey org-agenda-mode-map "-" #'org-agenda-priority-down)
  2188. (org-defkey org-agenda-mode-map [(shift up)] #'org-agenda-priority-up)
  2189. (org-defkey org-agenda-mode-map [(shift down)] #'org-agenda-priority-down)
  2190. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] #'org-agenda-priority-up)
  2191. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] #'org-agenda-priority-down)
  2192. (org-defkey org-agenda-mode-map "f" #'org-agenda-later)
  2193. (org-defkey org-agenda-mode-map "b" #'org-agenda-earlier)
  2194. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" #'org-agenda-columns)
  2195. (org-defkey org-agenda-mode-map "\C-c\C-x>" #'org-agenda-remove-restriction-lock)
  2196. (org-defkey org-agenda-mode-map "\C-c\C-x<" #'org-agenda-set-restriction-lock-from-agenda)
  2197. (org-defkey org-agenda-mode-map "[" #'org-agenda-manipulate-query-add)
  2198. (org-defkey org-agenda-mode-map "]" #'org-agenda-manipulate-query-subtract)
  2199. (org-defkey org-agenda-mode-map "{" #'org-agenda-manipulate-query-add-re)
  2200. (org-defkey org-agenda-mode-map "}" #'org-agenda-manipulate-query-subtract-re)
  2201. (org-defkey org-agenda-mode-map "\\" #'org-agenda-filter-by-tag)
  2202. (org-defkey org-agenda-mode-map "_" #'org-agenda-filter-by-effort)
  2203. (org-defkey org-agenda-mode-map "=" #'org-agenda-filter-by-regexp)
  2204. (org-defkey org-agenda-mode-map "/" #'org-agenda-filter)
  2205. (org-defkey org-agenda-mode-map "|" #'org-agenda-filter-remove-all)
  2206. (org-defkey org-agenda-mode-map "~" #'org-agenda-limit-interactively)
  2207. (org-defkey org-agenda-mode-map "<" #'org-agenda-filter-by-category)
  2208. (org-defkey org-agenda-mode-map "^" #'org-agenda-filter-by-top-headline)
  2209. (org-defkey org-agenda-mode-map ";" #'org-timer-set-timer)
  2210. (org-defkey org-agenda-mode-map "\C-c\C-x_" #'org-timer-stop)
  2211. (org-defkey org-agenda-mode-map "?" #'org-agenda-show-the-flagging-note)
  2212. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" #'org-mobile-pull)
  2213. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" #'org-mobile-push)
  2214. (org-defkey org-agenda-mode-map "\C-c\C-xI" #'org-info-find-node)
  2215. (org-defkey org-agenda-mode-map [mouse-2] #'org-agenda-goto-mouse)
  2216. (org-defkey org-agenda-mode-map [mouse-3] #'org-agenda-show-mouse)
  2217. (org-defkey org-agenda-mode-map [remap forward-paragraph] #'org-agenda-forward-block)
  2218. (org-defkey org-agenda-mode-map [remap backward-paragraph] #'org-agenda-backward-block)
  2219. (org-defkey org-agenda-mode-map "\C-c\C-c" #'org-agenda-ctrl-c-ctrl-c)
  2220. (when org-agenda-mouse-1-follows-link
  2221. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2222. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu."
  2223. '("Agenda"
  2224. ("Agenda Files")
  2225. "--"
  2226. ("Agenda Dates"
  2227. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda)]
  2228. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2229. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2230. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2231. "--"
  2232. ("View"
  2233. ["Day View" org-agenda-day-view
  2234. :active (org-agenda-check-type nil 'agenda)
  2235. :style radio :selected (eq org-agenda-current-span 'day)
  2236. :keys "v d (or just d)"]
  2237. ["Week View" org-agenda-week-view
  2238. :active (org-agenda-check-type nil 'agenda)
  2239. :style radio :selected (eq org-agenda-current-span 'week)
  2240. :keys "v w"]
  2241. ["Fortnight View" org-agenda-fortnight-view
  2242. :active (org-agenda-check-type nil 'agenda)
  2243. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2244. :keys "v t"]
  2245. ["Month View" org-agenda-month-view
  2246. :active (org-agenda-check-type nil 'agenda)
  2247. :style radio :selected (eq org-agenda-current-span 'month)
  2248. :keys "v m"]
  2249. ["Year View" org-agenda-year-view
  2250. :active (org-agenda-check-type nil 'agenda)
  2251. :style radio :selected (eq org-agenda-current-span 'year)
  2252. :keys "v y"]
  2253. "--"
  2254. ["Include Diary" org-agenda-toggle-diary
  2255. :style toggle :selected org-agenda-include-diary
  2256. :active (org-agenda-check-type nil 'agenda)]
  2257. ["Include Deadlines" org-agenda-toggle-deadlines
  2258. :style toggle :selected org-agenda-include-deadlines
  2259. :active (org-agenda-check-type nil 'agenda)]
  2260. ["Use Time Grid" org-agenda-toggle-time-grid
  2261. :style toggle :selected org-agenda-use-time-grid
  2262. :active (org-agenda-check-type nil 'agenda)]
  2263. "--"
  2264. ["Show clock report" org-agenda-clockreport-mode
  2265. :style toggle :selected org-agenda-clockreport-mode
  2266. :active (org-agenda-check-type nil 'agenda)]
  2267. ["Show some entry text" org-agenda-entry-text-mode
  2268. :style toggle :selected org-agenda-entry-text-mode
  2269. :active t]
  2270. "--"
  2271. ["Show Logbook entries" org-agenda-log-mode
  2272. :style toggle :selected org-agenda-show-log
  2273. :active (org-agenda-check-type nil 'agenda)
  2274. :keys "v l (or just l)"]
  2275. ["Include archived trees" org-agenda-archives-mode
  2276. :style toggle :selected org-agenda-archives-mode :active t
  2277. :keys "v a"]
  2278. ["Include archive files" (org-agenda-archives-mode t)
  2279. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2280. :keys "v A"]
  2281. "--"
  2282. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2283. ("Filter current view"
  2284. ["with generic interface" org-agenda-filter t]
  2285. "--"
  2286. ["by category at cursor" org-agenda-filter-by-category t]
  2287. ["by tag" org-agenda-filter-by-tag t]
  2288. ["by effort" org-agenda-filter-by-effort t]
  2289. ["by regexp" org-agenda-filter-by-regexp t]
  2290. ["by top-level headline" org-agenda-filter-by-top-headline t]
  2291. "--"
  2292. ["Remove all filtering" org-agenda-filter-remove-all t]
  2293. "--"
  2294. ["limit" org-agenda-limit-interactively t])
  2295. ["Rebuild buffer" org-agenda-redo t]
  2296. ["Write view to file" org-agenda-write t]
  2297. ["Save all Org buffers" org-save-all-org-buffers t]
  2298. "--"
  2299. ["Show original entry" org-agenda-show t]
  2300. ["Go To (other window)" org-agenda-goto t]
  2301. ["Go To (this window)" org-agenda-switch-to t]
  2302. ["Capture with cursor date" org-agenda-capture t]
  2303. ["Follow Mode" org-agenda-follow-mode
  2304. :style toggle :selected org-agenda-follow-mode :active t]
  2305. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2306. "--"
  2307. ("TODO"
  2308. ["Cycle TODO" org-agenda-todo t]
  2309. ["Next TODO set" org-agenda-todo-nextset t]
  2310. ["Previous TODO set" org-agenda-todo-previousset t]
  2311. ["Add note" org-agenda-add-note t])
  2312. ("Archive/Refile/Delete"
  2313. ["Archive default" org-agenda-archive-default t]
  2314. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2315. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2316. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2317. ["Archive subtree" org-agenda-archive t]
  2318. "--"
  2319. ["Refile" org-agenda-refile t]
  2320. "--"
  2321. ["Delete subtree" org-agenda-kill t])
  2322. ("Bulk action"
  2323. ["Mark entry" org-agenda-bulk-mark t]
  2324. ["Mark all" org-agenda-bulk-mark-all t]
  2325. ["Unmark entry" org-agenda-bulk-unmark t]
  2326. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2327. ["Toggle mark" org-agenda-bulk-toggle t]
  2328. ["Toggle all" org-agenda-bulk-toggle-all t]
  2329. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2330. ["Act on all marked" org-agenda-bulk-action t]
  2331. "--"
  2332. ("Tags and Properties"
  2333. ["Show all Tags" org-agenda-show-tags t]
  2334. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2335. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2336. "--"
  2337. ["Column View" org-columns t])
  2338. ("Deadline/Schedule"
  2339. ["Schedule" org-agenda-schedule t]
  2340. ["Set Deadline" org-agenda-deadline t]
  2341. "--"
  2342. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda)]
  2343. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda)]
  2344. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u S-right"]
  2345. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u S-left"]
  2346. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-right"]
  2347. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda) :keys "C-u C-u S-left"]
  2348. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda)])
  2349. ("Clock and Effort"
  2350. ["Clock in" org-agenda-clock-in t]
  2351. ["Clock out" org-agenda-clock-out t]
  2352. ["Clock cancel" org-agenda-clock-cancel t]
  2353. ["Goto running clock" org-clock-goto t]
  2354. "--"
  2355. ["Set Effort" org-agenda-set-effort t]
  2356. ["Change clocked effort" org-clock-modify-effort-estimate
  2357. (org-clock-is-active)])
  2358. ("Priority"
  2359. ["Set Priority" org-agenda-priority t]
  2360. ["Increase Priority" org-agenda-priority-up t]
  2361. ["Decrease Priority" org-agenda-priority-down t]
  2362. ["Show Priority" org-priority-show t])
  2363. ("Calendar/Diary"
  2364. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda)]
  2365. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda)]
  2366. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda)]
  2367. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda)]
  2368. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda)]
  2369. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda)]
  2370. "--"
  2371. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2372. "--"
  2373. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2374. "--"
  2375. ("MobileOrg"
  2376. ["Push Files and Views" org-mobile-push t]
  2377. ["Get Captured and Flagged" org-mobile-pull t]
  2378. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "\\[org-agenda] ?"]
  2379. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2380. "--"
  2381. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2382. "--"
  2383. ["Quit" org-agenda-quit t]
  2384. ["Exit and Release Buffers" org-agenda-exit t]
  2385. ))
  2386. ;;; Agenda undo
  2387. (defvar org-agenda-allow-remote-undo t
  2388. "Non-nil means allow remote undo from the agenda buffer.")
  2389. (defvar org-agenda-undo-has-started-in nil
  2390. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2391. (defun org-agenda-undo ()
  2392. "Undo a remote editing step in the agenda.
  2393. This undoes changes both in the agenda buffer and in the remote buffer
  2394. that have been changed along."
  2395. (interactive)
  2396. (or org-agenda-allow-remote-undo
  2397. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2398. (when (not (eq this-command last-command))
  2399. (setq org-agenda-undo-has-started-in nil
  2400. org-agenda-pending-undo-list org-agenda-undo-list))
  2401. (when (not org-agenda-pending-undo-list)
  2402. (user-error "No further undo information"))
  2403. (let* ((entry (pop org-agenda-pending-undo-list))
  2404. buf line cmd rembuf)
  2405. (setq cmd (pop entry) line (pop entry))
  2406. (setq rembuf (nth 2 entry))
  2407. (org-with-remote-undo rembuf
  2408. (while (bufferp (setq buf (pop entry)))
  2409. (when (pop entry)
  2410. (with-current-buffer buf
  2411. (let (;; (last-undo-buffer buf)
  2412. (inhibit-read-only t))
  2413. (unless (memq buf org-agenda-undo-has-started-in)
  2414. (push buf org-agenda-undo-has-started-in)
  2415. (make-local-variable 'pending-undo-list)
  2416. (undo-start))
  2417. (while (and pending-undo-list
  2418. (listp pending-undo-list)
  2419. (not (car pending-undo-list)))
  2420. (pop pending-undo-list))
  2421. (undo-more 1))))))
  2422. (org-goto-line line)
  2423. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2424. (defun org-verify-change-for-undo (l1 l2)
  2425. "Verify that a real change occurred between the undo lists L1 and L2."
  2426. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2427. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2428. (not (eq l1 l2)))
  2429. ;;; Agenda dispatch
  2430. (defvar org-agenda-restrict-begin (make-marker))
  2431. (defvar org-agenda-restrict-end (make-marker))
  2432. (defvar org-agenda-last-dispatch-buffer nil)
  2433. (defvar org-agenda-overriding-restriction nil)
  2434. (defcustom org-agenda-custom-commands-contexts nil
  2435. "Alist of custom agenda keys and contextual rules.
  2436. For example, if you have a custom agenda command \"p\" and you
  2437. want this command to be accessible only from plain text files,
  2438. use this:
  2439. \\='((\"p\" ((in-file . \"\\\\.txt\\\\'\"))))
  2440. Here are the available contexts definitions:
  2441. in-file: command displayed only in matching files
  2442. in-mode: command displayed only in matching modes
  2443. not-in-file: command not displayed in matching files
  2444. not-in-mode: command not displayed in matching modes
  2445. in-buffer: command displayed only in matching buffers
  2446. not-in-buffer: command not displayed in matching buffers
  2447. [function]: a custom function taking no argument
  2448. If you define several checks, the agenda command will be
  2449. accessible if there is at least one valid check.
  2450. You can also bind a key to another agenda custom command
  2451. depending on contextual rules.
  2452. \\='((\"p\" \"q\" ((in-file . \"\\\\.txt\\\\'\"))))
  2453. Here it means: in .txt files, use \"p\" as the key for the
  2454. agenda command otherwise associated with \"q\". (The command
  2455. originally associated with \"q\" is not displayed to avoid
  2456. duplicates.)"
  2457. :version "24.3"
  2458. :group 'org-agenda-custom-commands
  2459. :type '(repeat (list :tag "Rule"
  2460. (string :tag " Agenda key")
  2461. (string :tag "Replace by command")
  2462. (repeat :tag "Available when"
  2463. (choice
  2464. (cons :tag "Condition"
  2465. (choice
  2466. (const :tag "In file" in-file)
  2467. (const :tag "Not in file" not-in-file)
  2468. (const :tag "In buffer" in-buffer)
  2469. (const :tag "Not in buffer" not-in-buffer)
  2470. (const :tag "In mode" in-mode)
  2471. (const :tag "Not in mode" not-in-mode))
  2472. (regexp))
  2473. (function :tag "Custom function"))))))
  2474. (defcustom org-agenda-max-entries nil
  2475. "Maximum number of entries to display in an agenda.
  2476. This can be nil (no limit) or an integer or an alist of agenda
  2477. types with an associated number of entries to display in this
  2478. type."
  2479. :version "24.4"
  2480. :package-version '(Org . "8.0")
  2481. :group 'org-agenda-custom-commands
  2482. :type '(choice (symbol :tag "No limit" nil)
  2483. (integer :tag "Max number of entries")
  2484. (repeat
  2485. (cons (choice :tag "Agenda type"
  2486. (const agenda)
  2487. (const todo)
  2488. (const tags)
  2489. (const search))
  2490. (integer :tag "Max number of entries")))))
  2491. (defcustom org-agenda-max-todos nil
  2492. "Maximum number of TODOs to display in an agenda.
  2493. This can be nil (no limit) or an integer or an alist of agenda
  2494. types with an associated number of entries to display in this
  2495. type."
  2496. :version "24.4"
  2497. :package-version '(Org . "8.0")
  2498. :group 'org-agenda-custom-commands
  2499. :type '(choice (symbol :tag "No limit" nil)
  2500. (integer :tag "Max number of TODOs")
  2501. (repeat
  2502. (cons (choice :tag "Agenda type"
  2503. (const agenda)
  2504. (const todo)
  2505. (const tags)
  2506. (const search))
  2507. (integer :tag "Max number of TODOs")))))
  2508. (defcustom org-agenda-max-tags nil
  2509. "Maximum number of tagged entries to display in an agenda.
  2510. This can be nil (no limit) or an integer or an alist of agenda
  2511. types with an associated number of entries to display in this
  2512. type."
  2513. :version "24.4"
  2514. :package-version '(Org . "8.0")
  2515. :group 'org-agenda-custom-commands
  2516. :type '(choice (symbol :tag "No limit" nil)
  2517. (integer :tag "Max number of tagged entries")
  2518. (repeat
  2519. (cons (choice :tag "Agenda type"
  2520. (const agenda)
  2521. (const todo)
  2522. (const tags)
  2523. (const search))
  2524. (integer :tag "Max number of tagged entries")))))
  2525. (defcustom org-agenda-max-effort nil
  2526. "Maximum cumulated effort duration for the agenda.
  2527. This can be nil (no limit) or a number of minutes (as an integer)
  2528. or an alist of agenda types with an associated number of minutes
  2529. to limit entries to in this type."
  2530. :version "24.4"
  2531. :package-version '(Org . "8.0")
  2532. :group 'org-agenda-custom-commands
  2533. :type '(choice (symbol :tag "No limit" nil)
  2534. (integer :tag "Max number of minutes")
  2535. (repeat
  2536. (cons (choice :tag "Agenda type"
  2537. (const agenda)
  2538. (const todo)
  2539. (const tags)
  2540. (const search))
  2541. (integer :tag "Max number of minutes")))))
  2542. (defvar org-agenda-keep-restricted-file-list nil)
  2543. (defvar org-keys nil)
  2544. (defvar org-match nil)
  2545. ;;;###autoload
  2546. (defun org-agenda (&optional arg keys restriction)
  2547. "Dispatch agenda commands to collect entries to the agenda buffer.
  2548. Prompts for a command to execute. Any prefix arg will be passed
  2549. on to the selected command. The default selections are:
  2550. a Call `org-agenda-list' to display the agenda for current day or week.
  2551. t Call `org-todo-list' to display the global todo list.
  2552. T Call `org-todo-list' to display the global todo list, select only
  2553. entries with a specific TODO keyword (the user gets a prompt).
  2554. m Call `org-tags-view' to display headlines with tags matching
  2555. a condition (the user is prompted for the condition).
  2556. M Like `m', but select only TODO entries, no ordinary headlines.
  2557. e Export views to associated files.
  2558. s Search entries for keywords.
  2559. S Search entries for keywords, only with TODO keywords.
  2560. / Multi occur across all agenda files and also files listed
  2561. in `org-agenda-text-search-extra-files'.
  2562. < Restrict agenda commands to buffer, subtree, or region.
  2563. Press several times to get the desired effect.
  2564. > Remove a previous restriction.
  2565. # List \"stuck\" projects.
  2566. ! Configure what \"stuck\" means.
  2567. C Configure custom agenda commands.
  2568. More commands can be added by configuring the variable
  2569. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2570. searches can be pre-defined in this way.
  2571. If the current buffer is in Org mode and visiting a file, you can also
  2572. first press `<' once to indicate that the agenda should be temporarily
  2573. \(until the next use of `\\[org-agenda]') restricted to the current file.
  2574. Pressing `<' twice means to restrict to the current subtree or region
  2575. \(if active)."
  2576. (interactive "P")
  2577. (catch 'exit
  2578. (let* ((org-keys keys)
  2579. (prefix-descriptions nil)
  2580. (org-agenda-buffer-name org-agenda-buffer-name)
  2581. (org-agenda-window-setup (if (equal (buffer-name)
  2582. org-agenda-buffer-name)
  2583. 'current-window
  2584. org-agenda-window-setup))
  2585. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2586. (org-agenda-custom-commands
  2587. ;; normalize different versions
  2588. (delq nil
  2589. (mapcar
  2590. (lambda (x)
  2591. (cond ((stringp (cdr x))
  2592. (push x prefix-descriptions)
  2593. nil)
  2594. ((stringp (nth 1 x)) x)
  2595. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2596. (t (cons (car x) (cons "" (cdr x))))))
  2597. org-agenda-custom-commands)))
  2598. (org-agenda-custom-commands
  2599. (org-contextualize-keys
  2600. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2601. ;; (buf (current-buffer))
  2602. (bfn (buffer-file-name (buffer-base-buffer)))
  2603. entry type org-match lprops ans) ;; key
  2604. ;; Turn off restriction unless there is an overriding one,
  2605. (unless org-agenda-overriding-restriction
  2606. (unless org-agenda-keep-restricted-file-list
  2607. ;; There is a request to keep the file list in place
  2608. (put 'org-agenda-files 'org-restrict nil))
  2609. (setq org-agenda-restrict nil)
  2610. (move-marker org-agenda-restrict-begin nil)
  2611. (move-marker org-agenda-restrict-end nil))
  2612. ;; Delete old local properties
  2613. (put 'org-agenda-redo-command 'org-lprops nil)
  2614. ;; Delete previously set last-arguments
  2615. (put 'org-agenda-redo-command 'last-args nil)
  2616. ;; Remember where this call originated
  2617. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2618. (unless org-keys
  2619. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2620. org-keys (car ans)
  2621. restriction (cdr ans)))
  2622. ;; If we have sticky agenda buffers, set a name for the buffer,
  2623. ;; depending on the invoking keys. The user may still set this
  2624. ;; as a command option, which will overwrite what we do here.
  2625. (when org-agenda-sticky
  2626. (setq org-agenda-buffer-name
  2627. (format "*Org Agenda(%s)*" org-keys)))
  2628. ;; Establish the restriction, if any
  2629. (when (and (not org-agenda-overriding-restriction) restriction)
  2630. (put 'org-agenda-files 'org-restrict (list bfn))
  2631. (cond
  2632. ((eq restriction 'region)
  2633. (setq org-agenda-restrict (current-buffer))
  2634. (move-marker org-agenda-restrict-begin (region-beginning))
  2635. (move-marker org-agenda-restrict-end (region-end)))
  2636. ((eq restriction 'subtree)
  2637. (save-excursion
  2638. (setq org-agenda-restrict (current-buffer))
  2639. (org-back-to-heading t)
  2640. (move-marker org-agenda-restrict-begin (point))
  2641. (move-marker org-agenda-restrict-end
  2642. (progn (org-end-of-subtree t)))))
  2643. ((and (eq restriction 'buffer)
  2644. (or (< 1 (point-min))
  2645. (< (point-max) (1+ (buffer-size)))))
  2646. (setq org-agenda-restrict (current-buffer))
  2647. (move-marker org-agenda-restrict-begin (point-min))
  2648. (move-marker org-agenda-restrict-end (point-max)))))
  2649. ;; For example the todo list should not need it (but does...)
  2650. (cond
  2651. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2652. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2653. (progn
  2654. ;; FIXME: Is (nth 3 entry) supposed to have access (via dynvars)
  2655. ;; to some of the local variables? There's no doc about
  2656. ;; that for `org-agenda-custom-commands'.
  2657. (setq type (nth 2 entry) org-match (eval (nth 3 entry) t)
  2658. lprops (nth 4 entry))
  2659. (when org-agenda-sticky
  2660. (setq org-agenda-buffer-name
  2661. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2662. (format "*Org Agenda(%s)*" org-keys))))
  2663. (put 'org-agenda-redo-command 'org-lprops lprops)
  2664. (cl-progv
  2665. (mapcar #'car lprops)
  2666. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  2667. (pcase type
  2668. (`agenda
  2669. (org-agenda-list current-prefix-arg))
  2670. (`agenda*
  2671. (org-agenda-list current-prefix-arg nil nil t))
  2672. (`alltodo
  2673. (org-todo-list current-prefix-arg))
  2674. (`search
  2675. (org-search-view current-prefix-arg org-match nil))
  2676. (`stuck
  2677. (org-agenda-list-stuck-projects current-prefix-arg))
  2678. (`tags
  2679. (org-tags-view current-prefix-arg org-match))
  2680. (`tags-todo
  2681. (org-tags-view '(4) org-match))
  2682. (`todo
  2683. (org-todo-list org-match))
  2684. (`tags-tree
  2685. (org-check-for-org-mode)
  2686. (org-match-sparse-tree current-prefix-arg org-match))
  2687. (`todo-tree
  2688. (org-check-for-org-mode)
  2689. (org-occur (concat "^" org-outline-regexp "[ \t]*"
  2690. (regexp-quote org-match) "\\>")))
  2691. (`occur-tree
  2692. (org-check-for-org-mode)
  2693. (org-occur org-match))
  2694. ((pred functionp)
  2695. (funcall type org-match))
  2696. ;; FIXME: Will signal an error since it's not `functionp'!
  2697. ((pred fboundp) (funcall type org-match))
  2698. (_ (user-error "Invalid custom agenda command type %s" type)))))
  2699. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2700. ((equal org-keys "C")
  2701. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2702. (customize-variable 'org-agenda-custom-commands))
  2703. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2704. ((equal org-keys "s") (call-interactively 'org-search-view))
  2705. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2706. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2707. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2708. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2709. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2710. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2711. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2712. (add-hook
  2713. 'post-command-hook
  2714. (lambda ()
  2715. (unless (current-message)
  2716. (let* ((m (org-agenda-get-any-marker))
  2717. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2718. (when note
  2719. (message "FLAGGING-NOTE ([?] for more info): %s"
  2720. (org-add-props
  2721. (replace-regexp-in-string
  2722. "\\\\n" "//"
  2723. (copy-sequence note))
  2724. nil 'face 'org-warning))))))
  2725. t t))
  2726. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2727. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2728. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2729. (t (user-error "Invalid agenda key"))))))
  2730. (defvar org-agenda-multi)
  2731. (defun org-agenda-append-agenda ()
  2732. "Append another agenda view to the current one.
  2733. This function allows interactive building of block agendas.
  2734. Agenda views are separated by `org-agenda-block-separator'."
  2735. (interactive)
  2736. (unless (derived-mode-p 'org-agenda-mode)
  2737. (user-error "Can only append from within agenda buffer"))
  2738. (let ((org-agenda-multi t))
  2739. (org-agenda)
  2740. (widen)
  2741. (org-agenda-finalize)
  2742. (setq buffer-read-only t)
  2743. (org-agenda-fit-window-to-buffer)))
  2744. (defun org-agenda-normalize-custom-commands (cmds)
  2745. "Normalize custom commands CMDS."
  2746. (delq nil
  2747. (mapcar
  2748. (lambda (x)
  2749. (cond ((stringp (cdr x)) nil)
  2750. ((stringp (nth 1 x)) x)
  2751. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2752. (t (cons (car x) (cons "" (cdr x))))))
  2753. cmds)))
  2754. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2755. "The user interface for selecting an agenda command."
  2756. (catch 'exit
  2757. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2758. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2759. (region-p (org-region-active-p))
  2760. (custom org-agenda-custom-commands)
  2761. (selstring "")
  2762. restriction second-time
  2763. c entry key type match prefixes rmheader header-end custom1 desc
  2764. line lines left right n n1)
  2765. (save-window-excursion
  2766. (delete-other-windows)
  2767. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2768. (erase-buffer)
  2769. (insert (eval-when-compile
  2770. (let ((header
  2771. (copy-sequence
  2772. "Press key for an agenda command:
  2773. -------------------------------- < Buffer, subtree/region restriction
  2774. a Agenda for current week or day > Remove restriction
  2775. t List of all TODO entries e Export agenda views
  2776. m Match a TAGS/PROP/TODO query T Entries with special TODO kwd
  2777. s Search for keywords M Like m, but only TODO entries
  2778. / Multi-occur S Like s, but only TODO entries
  2779. ? Find :FLAGGED: entries C Configure custom agenda commands
  2780. * Toggle sticky agenda views # List stuck projects (!=configure)
  2781. "))
  2782. (start 0))
  2783. (while (string-match
  2784. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2785. header start)
  2786. (setq start (match-end 0))
  2787. (add-text-properties (match-beginning 2) (match-end 2)
  2788. '(face bold) header))
  2789. header)))
  2790. (setq header-end (point-marker))
  2791. (while t
  2792. (setq custom1 custom)
  2793. (when (eq rmheader t)
  2794. (org-goto-line 1)
  2795. (re-search-forward ":" nil t)
  2796. (delete-region (match-end 0) (point-at-eol))
  2797. (forward-char 1)
  2798. (looking-at "-+")
  2799. (delete-region (match-end 0) (point-at-eol))
  2800. (move-marker header-end (match-end 0)))
  2801. (goto-char header-end)
  2802. (delete-region (point) (point-max))
  2803. ;; Produce all the lines that describe custom commands and prefixes
  2804. (setq lines nil)
  2805. (while (setq entry (pop custom1))
  2806. (setq key (car entry) desc (nth 1 entry)
  2807. type (nth 2 entry)
  2808. match (nth 3 entry))
  2809. (if (> (length key) 1)
  2810. (cl-pushnew (string-to-char key) prefixes :test #'equal)
  2811. (setq line
  2812. (format
  2813. "%-4s%-14s"
  2814. (org-add-props (copy-sequence key)
  2815. '(face bold))
  2816. (cond
  2817. ((string-match "\\S-" desc) desc)
  2818. ((eq type 'agenda) "Agenda for current week or day")
  2819. ((eq type 'agenda*) "Appointments for current week or day")
  2820. ((eq type 'alltodo) "List of all TODO entries")
  2821. ((eq type 'search) "Word search")
  2822. ((eq type 'stuck) "List of stuck projects")
  2823. ((eq type 'todo) "TODO keyword")
  2824. ((eq type 'tags) "Tags query")
  2825. ((eq type 'tags-todo) "Tags (TODO)")
  2826. ((eq type 'tags-tree) "Tags tree")
  2827. ((eq type 'todo-tree) "TODO kwd tree")
  2828. ((eq type 'occur-tree) "Occur tree")
  2829. ((functionp type) (if (symbolp type)
  2830. (symbol-name type)
  2831. "Lambda expression"))
  2832. (t "???"))))
  2833. (cond
  2834. ((not (org-string-nw-p match)) nil)
  2835. (org-agenda-menu-show-matcher
  2836. (setq line
  2837. (concat line ": "
  2838. (cond
  2839. ((stringp match)
  2840. (propertize match 'face 'org-warning))
  2841. ((listp type)
  2842. (format "set of %d commands" (length type)))))))
  2843. (t
  2844. (org-add-props line nil 'help-echo (concat "Matcher: " match))))
  2845. (push line lines)))
  2846. (setq lines (nreverse lines))
  2847. (when prefixes
  2848. (mapc (lambda (x)
  2849. (push
  2850. (format "%s %s"
  2851. (org-add-props (char-to-string x)
  2852. nil 'face 'bold)
  2853. (or (cdr (assoc (concat selstring
  2854. (char-to-string x))
  2855. prefix-descriptions))
  2856. "Prefix key"))
  2857. lines))
  2858. prefixes))
  2859. ;; Check if we should display in two columns
  2860. (if org-agenda-menu-two-columns
  2861. (progn
  2862. (setq n (length lines)
  2863. n1 (+ (/ n 2) (mod n 2))
  2864. right (nthcdr n1 lines)
  2865. left (copy-sequence lines))
  2866. (setcdr (nthcdr (1- n1) left) nil))
  2867. (setq left lines right nil))
  2868. (while left
  2869. (insert "\n" (pop left))
  2870. (when right
  2871. (if (< (current-column) 40)
  2872. (move-to-column 40 t)
  2873. (insert " "))
  2874. (insert (pop right))))
  2875. ;; Make the window the right size
  2876. (goto-char (point-min))
  2877. (if second-time
  2878. (when (not (pos-visible-in-window-p (point-max)))
  2879. (org-fit-window-to-buffer))
  2880. (setq second-time t)
  2881. (org-fit-window-to-buffer))
  2882. ;; Hint to navigation if window too small for all information
  2883. (setq header-line-format
  2884. (when (not (pos-visible-in-window-p (point-max)))
  2885. "Use C-v, M-v, C-n or C-p to navigate."))
  2886. ;; Ask for selection
  2887. (cl-loop
  2888. do (progn
  2889. (message "Press key for agenda command%s:"
  2890. (if (or restrict-ok org-agenda-overriding-restriction)
  2891. (if org-agenda-overriding-restriction
  2892. " (restriction lock active)"
  2893. (if restriction
  2894. (format " (restricted to %s)" restriction)
  2895. " (unrestricted)"))
  2896. ""))
  2897. (setq c (read-char-exclusive)))
  2898. until (not (memq c '(14 16 22 134217846)))
  2899. do (org-scroll c))
  2900. (message "")
  2901. (cond
  2902. ((assoc (char-to-string c) custom)
  2903. (setq selstring (concat selstring (char-to-string c)))
  2904. (throw 'exit (cons selstring restriction)))
  2905. ((memq c prefixes)
  2906. (setq selstring (concat selstring (char-to-string c))
  2907. prefixes nil
  2908. rmheader (or rmheader t)
  2909. custom (delq nil (mapcar
  2910. (lambda (x)
  2911. (if (or (= (length (car x)) 1)
  2912. (/= (string-to-char (car x)) c))
  2913. nil
  2914. (cons (substring (car x) 1) (cdr x))))
  2915. custom))))
  2916. ((eq c ?*)
  2917. (call-interactively 'org-toggle-sticky-agenda)
  2918. (sit-for 2))
  2919. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2920. (message "Restriction is only possible in Org buffers")
  2921. (ding) (sit-for 1))
  2922. ((eq c ?1)
  2923. (org-agenda-remove-restriction-lock 'noupdate)
  2924. (setq restriction 'buffer))
  2925. ((eq c ?0)
  2926. (org-agenda-remove-restriction-lock 'noupdate)
  2927. (setq restriction (if region-p 'region 'subtree)))
  2928. ((eq c ?<)
  2929. (org-agenda-remove-restriction-lock 'noupdate)
  2930. (setq restriction
  2931. (cond
  2932. ((eq restriction 'buffer)
  2933. (if region-p 'region 'subtree))
  2934. ((memq restriction '(subtree region))
  2935. nil)
  2936. (t 'buffer))))
  2937. ((eq c ?>)
  2938. (org-agenda-remove-restriction-lock 'noupdate)
  2939. (setq restriction nil))
  2940. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2941. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2942. ((and (> (length selstring) 0) (eq c ?\d))
  2943. (delete-window)
  2944. (org-agenda-get-restriction-and-command prefix-descriptions))
  2945. ((equal c ?q) (user-error "Abort"))
  2946. (t (user-error "Invalid key %c" c))))))))
  2947. (defun org-agenda-fit-window-to-buffer ()
  2948. "Fit the window to the buffer size."
  2949. (and (memq org-agenda-window-setup '(reorganize-frame))
  2950. (fboundp 'fit-window-to-buffer)
  2951. (if (and (= (cdr org-agenda-window-frame-fractions) 1.0)
  2952. (= (car org-agenda-window-frame-fractions) 1.0))
  2953. (delete-other-windows)
  2954. (org-fit-window-to-buffer
  2955. nil
  2956. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2957. (floor (* (frame-height) (car org-agenda-window-frame-fractions)))))))
  2958. (defvar org-cmd nil)
  2959. (defvar org-agenda-overriding-cmd nil)
  2960. (defvar org-agenda-overriding-arguments nil)
  2961. (defvar org-agenda-overriding-cmd-arguments nil)
  2962. (defun org-let (list &rest body) ;FIXME: So many kittens are suffering here.
  2963. (declare (indent 1) (obsolete cl-progv "2021"))
  2964. (eval (cons 'let (cons list body))))
  2965. (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
  2966. (declare (indent 2) (obsolete cl-progv "2021"))
  2967. (eval (cons 'let (cons list1 (list (cons 'let (cons list2 body)))))))
  2968. (defun org-agenda-run-series (name series)
  2969. "Run agenda NAME as a SERIES of agenda commands."
  2970. (let* ((gprops (nth 1 series))
  2971. (gvars (mapcar #'car gprops))
  2972. (gvals (mapcar (lambda (binding) (eval (cadr binding) t)) gprops)))
  2973. (cl-progv gvars gvals (org-agenda-prepare name))
  2974. ;; We need to reset agenda markers here, because when constructing a
  2975. ;; block agenda, the individual blocks do not do that.
  2976. (org-agenda-reset-markers)
  2977. (with-no-warnings
  2978. (defvar match)) ;Used via the `eval' below.
  2979. (let* ((org-agenda-multi t)
  2980. ;; FIXME: Redo should contain lists of (FUNS . ARGS) rather
  2981. ;; than expressions, so you don't need to `quote' the args
  2982. ;; and you just need to `apply' instead of `eval' when using it.
  2983. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2984. (cmds (car series))
  2985. match
  2986. org-cmd type lprops)
  2987. (while (setq org-cmd (pop cmds))
  2988. (setq type (car org-cmd))
  2989. (setq match (eval (nth 1 org-cmd) t))
  2990. (setq lprops (nth 2 org-cmd))
  2991. (let ((org-agenda-overriding-arguments
  2992. (if (eq org-agenda-overriding-cmd org-cmd)
  2993. (or org-agenda-overriding-arguments
  2994. org-agenda-overriding-cmd-arguments)))
  2995. (lvars (mapcar #'car lprops))
  2996. (lvals (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)))
  2997. (cl-progv (append gvars lvars) (append gvals lvals)
  2998. (pcase type
  2999. (`agenda
  3000. (call-interactively 'org-agenda-list))
  3001. (`agenda*
  3002. (funcall 'org-agenda-list nil nil t))
  3003. (`alltodo
  3004. (call-interactively 'org-todo-list))
  3005. (`search
  3006. (org-search-view current-prefix-arg match nil))
  3007. (`stuck
  3008. (call-interactively 'org-agenda-list-stuck-projects))
  3009. (`tags
  3010. (org-tags-view current-prefix-arg match))
  3011. (`tags-todo
  3012. (org-tags-view '(4) match))
  3013. (`todo
  3014. (org-todo-list match))
  3015. ((pred fboundp)
  3016. (funcall type match))
  3017. (_ (error "Invalid type in command series"))))))
  3018. (widen)
  3019. (let ((inhibit-read-only t))
  3020. (add-text-properties (point-min) (point-max)
  3021. `(org-series t org-series-redo-cmd ,redo)))
  3022. (setq org-agenda-redo-command redo)
  3023. (goto-char (point-min)))
  3024. (org-agenda-fit-window-to-buffer)
  3025. (cl-progv gvars gvals (org-agenda-finalize))))
  3026. (defun org-agenda--split-plist (plist)
  3027. ;; We could/should arguably use `map-keys' and `map-values'.
  3028. (let (keys vals)
  3029. (while plist
  3030. (push (pop plist) keys)
  3031. (push (pop plist) vals))
  3032. (cons (nreverse keys) (nreverse vals))))
  3033. ;;;###autoload
  3034. (defmacro org-batch-agenda (cmd-key &rest parameters)
  3035. "Run an agenda command in batch mode and send the result to STDOUT.
  3036. If CMD-KEY is a string of length 1, it is used as a key in
  3037. `org-agenda-custom-commands' and triggers this command. If it is a
  3038. longer string it is used as a tags/todo match string.
  3039. Parameters are alternating variable names and values that will be bound
  3040. before running the agenda command."
  3041. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3042. `(org--batch-agenda ,cmd-key ',vars (list ,@exps))))
  3043. (defun org--batch-agenda (cmd-key vars vals)
  3044. ;; `org-batch-agenda' is a macro because every other "parameter" is
  3045. ;; a variable name rather than an expression to evaluate. Yuck!
  3046. (cl-progv vars vals
  3047. (let (org-agenda-sticky)
  3048. (if (> (length cmd-key) 1)
  3049. (org-tags-view nil cmd-key)
  3050. (org-agenda nil cmd-key))))
  3051. (set-buffer org-agenda-buffer-name)
  3052. (princ (buffer-string)))
  3053. (defvar org-agenda-info nil)
  3054. ;;;###autoload
  3055. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  3056. "Run an agenda command in batch mode and send the result to STDOUT.
  3057. If CMD-KEY is a string of length 1, it is used as a key in
  3058. `org-agenda-custom-commands' and triggers this command. If it is a
  3059. longer string it is used as a tags/todo match string.
  3060. Parameters are alternating variable names and values that will be bound
  3061. before running the agenda command.
  3062. The output gives a line for each selected agenda item. Each
  3063. item is a list of comma-separated values, like this:
  3064. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  3065. category The category of the item
  3066. head The headline, without TODO kwd, TAGS and PRIORITY
  3067. type The type of the agenda entry, can be
  3068. todo selected in TODO match
  3069. tagsmatch selected in tags match
  3070. diary imported from diary
  3071. deadline a deadline on given date
  3072. scheduled scheduled on given date
  3073. timestamp entry has timestamp on given date
  3074. closed entry was closed on given date
  3075. upcoming-deadline warning about deadline
  3076. past-scheduled forwarded scheduled item
  3077. block entry has date block including g. date
  3078. todo The todo keyword, if any
  3079. tags All tags including inherited ones, separated by colons
  3080. date The relevant date, like 2007-2-14
  3081. time The time, like 15:00-16:50
  3082. extra String with extra planning info
  3083. priority-l The priority letter if any was given
  3084. priority-n The computed numerical priority
  3085. agenda-day The day in the agenda where this is listed"
  3086. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3087. `(org--batch-agenda-csv ,cmd-key ',vars (list ,@exps))))
  3088. (defun org--batch-agenda-csv (cmd-key vars vals)
  3089. ;; `org-batch-agenda-csv' is a macro because every other "parameter" is
  3090. ;; a variable name rather than an expression to evaluate. Yuck!
  3091. (let ((org-agenda-remove-tags t))
  3092. (cl-progv vars vals
  3093. ;; FIXME: Shouldn't this be 1 (see commit 10173ad6d610b)?
  3094. (if (> (length cmd-key) 2)
  3095. (org-tags-view nil cmd-key)
  3096. (org-agenda nil cmd-key))))
  3097. (set-buffer org-agenda-buffer-name)
  3098. (let ((lines (org-split-string (buffer-string) "\n")))
  3099. (dolist (line lines)
  3100. (when (get-text-property 0 'org-category line)
  3101. (setq org-agenda-info
  3102. (org-fix-agenda-info (text-properties-at 0 line)))
  3103. (princ
  3104. (mapconcat #'org-agenda-export-csv-mapper
  3105. '(org-category txt type todo tags date time extra
  3106. priority-letter priority agenda-day)
  3107. ","))
  3108. (princ "\n")))))
  3109. (defun org-fix-agenda-info (props)
  3110. "Make sure all properties on an agenda item have a canonical form.
  3111. This ensures the export commands can easily use it."
  3112. (let (tmp re)
  3113. (when (setq tmp (plist-get props 'tags))
  3114. (setq props (plist-put props 'tags (mapconcat #'identity tmp ":"))))
  3115. (when (setq tmp (plist-get props 'date))
  3116. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3117. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3118. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  3119. (setq tmp (calendar-date-string tmp)))
  3120. (setq props (plist-put props 'date tmp)))
  3121. (when (setq tmp (plist-get props 'day))
  3122. (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  3123. (let ((calendar-date-display-form '(year "-" month "-" day)))
  3124. (setq tmp (calendar-date-string tmp)))
  3125. (setq props (plist-put props 'day tmp))
  3126. (setq props (plist-put props 'agenda-day tmp)))
  3127. (when (setq tmp (plist-get props 'txt))
  3128. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  3129. (plist-put props 'priority-letter (match-string 1 tmp))
  3130. (setq tmp (replace-match "" t t tmp)))
  3131. (when (and (setq re (plist-get props 'org-todo-regexp))
  3132. (setq re (concat "\\`\\.*" re " ?"))
  3133. (let ((case-fold-search nil)) (string-match re tmp)))
  3134. (plist-put props 'todo (match-string 1 tmp))
  3135. (setq tmp (replace-match "" t t tmp)))
  3136. (plist-put props 'txt tmp)))
  3137. props)
  3138. (defun org-agenda-export-csv-mapper (prop)
  3139. (let ((res (plist-get org-agenda-info prop)))
  3140. (setq res
  3141. (cond
  3142. ((not res) "")
  3143. ((stringp res) res)
  3144. (t (prin1-to-string res))))
  3145. (org-trim (replace-regexp-in-string "," ";" res nil t))))
  3146. ;;;###autoload
  3147. (defun org-store-agenda-views (&rest _parameters)
  3148. "Store agenda views."
  3149. (interactive)
  3150. (org--batch-store-agenda-views nil nil))
  3151. ;;;###autoload
  3152. (defmacro org-batch-store-agenda-views (&rest parameters)
  3153. "Run all custom agenda commands that have a file argument."
  3154. (pcase-let ((`(,vars . ,exps) (org-agenda--split-plist parameters)))
  3155. `(org--batch-store-agenda-views ',vars (list ,@exps))))
  3156. (defun org--batch-store-agenda-views (vars vals)
  3157. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  3158. (pop-up-frames nil)
  3159. (dir default-directory)
  3160. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  3161. (save-window-excursion
  3162. (while cmds
  3163. (setq cmd (pop cmds)
  3164. thiscmdkey (car cmd)
  3165. thiscmdcmd (cdr cmd)
  3166. match (nth 2 thiscmdcmd)
  3167. bufname (if org-agenda-sticky
  3168. (or (and (stringp match)
  3169. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  3170. (format "*Org Agenda(%s)*" thiscmdkey))
  3171. org-agenda-buffer-name)
  3172. cmd-or-set (nth 2 cmd)
  3173. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  3174. files (nth (if (listp cmd-or-set) 4 5) cmd))
  3175. (if (stringp files) (setq files (list files)))
  3176. (when files
  3177. (let* ((opts (append org-agenda-exporter-settings opts))
  3178. (vars (append (mapcar #'car opts) vars))
  3179. (vals (append (mapcar (lambda (binding) (eval (cadr binding) t))
  3180. opts)
  3181. vals)))
  3182. (cl-progv vars vals
  3183. (org-agenda nil thiscmdkey))
  3184. (set-buffer bufname)
  3185. (while files
  3186. (cl-progv vars vals
  3187. (org-agenda-write (expand-file-name (pop files) dir)
  3188. nil t bufname))))
  3189. (and (get-buffer bufname)
  3190. (kill-buffer bufname)))))))
  3191. (defvar org-agenda-current-span nil
  3192. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3193. (defun org-agenda-mark-header-line (pos)
  3194. "Mark the line at POS as an agenda structure header."
  3195. (save-excursion
  3196. (goto-char pos)
  3197. (put-text-property (point-at-bol) (point-at-eol)
  3198. 'org-agenda-structural-header t)
  3199. (when org-agenda-title-append
  3200. (put-text-property (point-at-bol) (point-at-eol)
  3201. 'org-agenda-title-append org-agenda-title-append))))
  3202. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  3203. (defvar org-agenda-write-buffer-name "Agenda View")
  3204. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  3205. "Write the current buffer (an agenda view) as a file.
  3206. Depending on the extension of the file name, plain text (.txt),
  3207. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  3208. If the extension is .ics, translate visible agenda into iCalendar
  3209. format. If the extension is .org, collect all subtrees
  3210. corresponding to the agenda entries and add them in an .org file.
  3211. With prefix argument OPEN, open the new file immediately. If
  3212. NOSETTINGS is given, do not scope the settings of
  3213. `org-agenda-exporter-settings' into the export commands. This is
  3214. used when the settings have already been scoped and we do not
  3215. wish to overrule other, higher priority settings. If
  3216. AGENDA-BUFFER-NAME is provided, use this as the buffer name for
  3217. the agenda to write."
  3218. (interactive "FWrite agenda to file: \nP")
  3219. (if (or (not (file-writable-p file))
  3220. (and (file-exists-p file)
  3221. (if (called-interactively-p 'any)
  3222. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3223. (user-error "Cannot write agenda to file %s" file))
  3224. (cl-progv
  3225. (if nosettings nil (mapcar #'car org-agenda-exporter-settings))
  3226. (if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
  3227. org-agenda-exporter-settings))
  3228. (save-excursion
  3229. (save-window-excursion
  3230. (let ((bs (copy-sequence (buffer-string)))
  3231. (extension (file-name-extension file))
  3232. (default-directory (file-name-directory file))
  3233. ) ;; beg content
  3234. (with-temp-buffer
  3235. (rename-buffer org-agenda-write-buffer-name t)
  3236. (set-buffer-modified-p nil)
  3237. (insert bs)
  3238. (org-agenda-remove-marked-text 'invisible 'org-filtered)
  3239. (run-hooks 'org-agenda-before-write-hook)
  3240. (cond
  3241. ((bound-and-true-p org-mobile-creating-agendas)
  3242. (org-mobile-write-agenda-for-mobile file))
  3243. ((string= "org" extension)
  3244. (let (content p m message-log-max)
  3245. (goto-char (point-min))
  3246. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3247. (goto-char p)
  3248. (setq m (get-text-property (point) 'org-hd-marker))
  3249. (when m
  3250. (push (with-current-buffer (marker-buffer m)
  3251. (goto-char m)
  3252. (org-copy-subtree 1 nil t t)
  3253. org-subtree-clip)
  3254. content)))
  3255. (find-file file)
  3256. (erase-buffer)
  3257. (dolist (s content) (org-paste-subtree 1 s))
  3258. (write-file file)
  3259. (kill-buffer (current-buffer))
  3260. (message "Org file written to %s" file)))
  3261. ((member extension '("html" "htm"))
  3262. (or (require 'htmlize nil t)
  3263. (error "Please install htmlize from https://github.com/hniksic/emacs-htmlize"))
  3264. (declare-function htmlize-buffer "htmlize" (&optional buffer))
  3265. (set-buffer (htmlize-buffer (current-buffer)))
  3266. (when org-agenda-export-html-style
  3267. ;; replace <style> section with org-agenda-export-html-style
  3268. (goto-char (point-min))
  3269. (kill-region (- (search-forward "<style") 6)
  3270. (search-forward "</style>"))
  3271. (insert org-agenda-export-html-style))
  3272. (write-file file)
  3273. (kill-buffer (current-buffer))
  3274. (message "HTML written to %s" file))
  3275. ((string= "ps" extension)
  3276. (require 'ps-print)
  3277. (ps-print-buffer-with-faces file)
  3278. (message "Postscript written to %s" file))
  3279. ((string= "pdf" extension)
  3280. (require 'ps-print)
  3281. (ps-print-buffer-with-faces
  3282. (concat (file-name-sans-extension file) ".ps"))
  3283. (call-process "ps2pdf" nil nil nil
  3284. (expand-file-name
  3285. (concat (file-name-sans-extension file) ".ps"))
  3286. (expand-file-name file))
  3287. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3288. (message "PDF written to %s" file))
  3289. ((string= "ics" extension)
  3290. (require 'ox-icalendar)
  3291. (declare-function org-icalendar-export-current-agenda
  3292. "ox-icalendar" (file))
  3293. (org-icalendar-export-current-agenda (expand-file-name file)))
  3294. (t
  3295. (let ((bs (buffer-string)))
  3296. (find-file file)
  3297. (erase-buffer)
  3298. (insert bs)
  3299. (save-buffer 0)
  3300. (kill-buffer (current-buffer))
  3301. (message "Plain text written to %s" file))))))))
  3302. (set-buffer (or agenda-bufname
  3303. ;; FIXME: I'm pretty sure called-interactively-p
  3304. ;; doesn't do what we want here!
  3305. (and (called-interactively-p 'any) (buffer-name))
  3306. org-agenda-buffer-name)))
  3307. (when open (org-open-file file)))
  3308. (defun org-agenda-remove-marked-text (property &optional value)
  3309. "Delete all text marked with VALUE of PROPERTY.
  3310. VALUE defaults to t."
  3311. (let (beg)
  3312. (setq value (or value t))
  3313. (while (setq beg (text-property-any (point-min) (point-max)
  3314. property value))
  3315. (delete-region
  3316. beg (or (next-single-property-change beg property)
  3317. (point-max))))))
  3318. (defun org-agenda-add-entry-text ()
  3319. "Add entry text to agenda lines.
  3320. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3321. entry text following headings shown in the agenda.
  3322. Drawers will be excluded, also the line with scheduling/deadline info."
  3323. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3324. (not (bound-and-true-p org-mobile-creating-agendas)))
  3325. (let (m txt)
  3326. (goto-char (point-min))
  3327. (while (not (eobp))
  3328. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3329. (beginning-of-line 2)
  3330. (setq txt (org-agenda-get-some-entry-text
  3331. m org-agenda-add-entry-text-maxlines " > "))
  3332. (end-of-line 1)
  3333. (if (string-match "\\S-" txt)
  3334. (insert "\n" txt)
  3335. (or (eobp) (forward-char 1))))))))
  3336. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3337. &rest keep)
  3338. "Extract entry text from MARKER, at most N-LINES lines.
  3339. This will ignore drawers etc, just get the text.
  3340. If INDENT is given, prefix every line with this string. If KEEP is
  3341. given, it is a list of symbols, defining stuff that should not be
  3342. removed from the entry content. Currently only `planning' is allowed here."
  3343. (let (txt drawer-re kwd-time-re ind)
  3344. (save-excursion
  3345. (with-current-buffer (marker-buffer marker)
  3346. (if (not (derived-mode-p 'org-mode))
  3347. (setq txt "")
  3348. (org-with-wide-buffer
  3349. (goto-char marker)
  3350. (end-of-line 1)
  3351. (setq txt (buffer-substring
  3352. (min (1+ (point)) (point-max))
  3353. (progn (outline-next-heading) (point)))
  3354. drawer-re org-drawer-regexp
  3355. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3356. ".*\n?"))
  3357. (with-temp-buffer
  3358. (insert txt)
  3359. (when org-agenda-add-entry-text-descriptive-links
  3360. (goto-char (point-min))
  3361. (while (org-activate-links (point-max))
  3362. (goto-char (match-end 0))))
  3363. (goto-char (point-min))
  3364. (while (re-search-forward org-link-bracket-re (point-max) t)
  3365. (set-text-properties (match-beginning 0) (match-end 0)
  3366. nil))
  3367. (goto-char (point-min))
  3368. (while (re-search-forward drawer-re nil t)
  3369. (delete-region
  3370. (match-beginning 0)
  3371. (progn (re-search-forward
  3372. "^[ \t]*:END:.*\n?" nil 'move)
  3373. (point))))
  3374. (unless (member 'planning keep)
  3375. (goto-char (point-min))
  3376. (while (re-search-forward kwd-time-re nil t)
  3377. (replace-match "")))
  3378. (goto-char (point-min))
  3379. (when org-agenda-entry-text-exclude-regexps
  3380. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3381. (while (setq re (pop re-list))
  3382. (goto-char (point-min))
  3383. (while (re-search-forward re nil t)
  3384. (replace-match "")))))
  3385. (goto-char (point-max))
  3386. (skip-chars-backward " \t\n")
  3387. (when (looking-at "[ \t\n]+\\'") (replace-match ""))
  3388. ;; find and remove min common indentation
  3389. (goto-char (point-min))
  3390. (untabify (point-min) (point-max))
  3391. (setq ind (current-indentation))
  3392. (while (not (eobp))
  3393. (unless (looking-at "[ \t]*$")
  3394. (setq ind (min ind (current-indentation))))
  3395. (beginning-of-line 2))
  3396. (goto-char (point-min))
  3397. (while (not (eobp))
  3398. (unless (looking-at "[ \t]*$")
  3399. (move-to-column ind)
  3400. (delete-region (point-at-bol) (point)))
  3401. (beginning-of-line 2))
  3402. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3403. (goto-char (point-min))
  3404. (when indent
  3405. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3406. (replace-match indent t t)))
  3407. (goto-char (point-min))
  3408. (while (looking-at "[ \t]*\n") (replace-match ""))
  3409. (goto-char (point-max))
  3410. (when (> (org-current-line)
  3411. n-lines)
  3412. (org-goto-line (1+ n-lines))
  3413. (backward-char 1))
  3414. (setq txt (buffer-substring (point-min) (point))))))))
  3415. txt))
  3416. (defun org-check-for-org-mode ()
  3417. "Make sure current buffer is in Org mode. Error if not."
  3418. (or (derived-mode-p 'org-mode)
  3419. (error "Cannot execute Org agenda command on buffer in %s"
  3420. major-mode)))
  3421. ;;; Agenda prepare and finalize
  3422. (defvar org-agenda-multi nil) ; dynamically scoped
  3423. (defvar org-agenda-pre-window-conf nil)
  3424. (defvar org-agenda-columns-active nil)
  3425. (defvar org-agenda-name nil)
  3426. (defvar org-agenda-tag-filter nil)
  3427. (defvar org-agenda-category-filter nil)
  3428. (defvar org-agenda-regexp-filter nil)
  3429. (defvar org-agenda-effort-filter nil)
  3430. (defvar org-agenda-top-headline-filter nil)
  3431. (defvar org-agenda-represented-categories nil
  3432. "Cache for the list of all categories in the agenda.")
  3433. (defvar org-agenda-represented-tags nil
  3434. "Cache for the list of all categories in the agenda.")
  3435. (defvar org-agenda-tag-filter-preset nil
  3436. "A preset of the tags filter used for secondary agenda filtering.
  3437. This must be a list of strings, each string must be a single tag preceded
  3438. by \"+\" or \"-\".
  3439. This variable should not be set directly, but agenda custom commands can
  3440. bind it in the options section. The preset filter is a global property of
  3441. the entire agenda view. In a block agenda, it will not work reliably to
  3442. define a filter for one of the individual blocks. You need to set it in
  3443. the global options and expect it to be applied to the entire view.")
  3444. (defconst org-agenda-filter-variables
  3445. '((category . org-agenda-category-filter)
  3446. (tag . org-agenda-tag-filter)
  3447. (effort . org-agenda-effort-filter)
  3448. (regexp . org-agenda-regexp-filter))
  3449. "Alist of filter types and associated variables.")
  3450. (defun org-agenda-filter-any ()
  3451. "Is any filter active?"
  3452. (cl-some (lambda (x)
  3453. (or (symbol-value (cdr x))
  3454. (get :preset-filter x)))
  3455. org-agenda-filter-variables))
  3456. (defvar org-agenda-category-filter-preset nil
  3457. "A preset of the category filter used for secondary agenda filtering.
  3458. This must be a list of strings, each string must be a single category
  3459. preceded by \"+\" or \"-\".
  3460. This variable should not be set directly, but agenda custom commands can
  3461. bind it in the options section. The preset filter is a global property of
  3462. the entire agenda view. In a block agenda, it will not work reliably to
  3463. define a filter for one of the individual blocks. You need to set it in
  3464. the global options and expect it to be applied to the entire view.")
  3465. (defvar org-agenda-regexp-filter-preset nil
  3466. "A preset of the regexp filter used for secondary agenda filtering.
  3467. This must be a list of strings, each string must be a single regexp
  3468. preceded by \"+\" or \"-\".
  3469. This variable should not be set directly, but agenda custom commands can
  3470. bind it in the options section. The preset filter is a global property of
  3471. the entire agenda view. In a block agenda, it will not work reliably to
  3472. define a filter for one of the individual blocks. You need to set it in
  3473. the global options and expect it to be applied to the entire view.")
  3474. (defvar org-agenda-effort-filter-preset nil
  3475. "A preset of the effort condition used for secondary agenda filtering.
  3476. This must be a list of strings, each string must be a single regexp
  3477. preceded by \"+\" or \"-\".
  3478. This variable should not be set directly, but agenda custom commands can
  3479. bind it in the options section. The preset filter is a global property of
  3480. the entire agenda view. In a block agenda, it will not work reliably to
  3481. define a filter for one of the individual blocks. You need to set it in
  3482. the global options and expect it to be applied to the entire view.")
  3483. (defun org-agenda-use-sticky-p ()
  3484. "Return non-nil if an agenda buffer named
  3485. `org-agenda-buffer-name' exists and should be shown instead of
  3486. generating a new one."
  3487. (and
  3488. ;; turned off by user
  3489. org-agenda-sticky
  3490. ;; For multi-agenda buffer already exists
  3491. (not org-agenda-multi)
  3492. ;; buffer found
  3493. (get-buffer org-agenda-buffer-name)
  3494. ;; C-u parameter is same as last call
  3495. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3496. (and
  3497. (equal current-prefix-arg
  3498. org-agenda-last-prefix-arg)
  3499. ;; In case user turned stickiness on, while having existing
  3500. ;; Agenda buffer active, don't reuse that buffer, because it
  3501. ;; does not have org variables local
  3502. org-agenda-this-buffer-is-sticky))))
  3503. (defvar org-agenda-buffer-tmp-name nil)
  3504. (defun org-agenda--get-buffer-name (sticky-name)
  3505. (or org-agenda-buffer-tmp-name
  3506. (and org-agenda-doing-sticky-redo org-agenda-buffer-name)
  3507. sticky-name
  3508. "*Org Agenda*"))
  3509. (defun org-agenda-prepare-window (abuf filter-alist)
  3510. "Setup agenda buffer in the window.
  3511. ABUF is the buffer for the agenda window.
  3512. FILTER-ALIST is an alist of filters we need to apply when
  3513. `org-agenda-persistent-filter' is non-nil."
  3514. (let* ((awin (get-buffer-window abuf)) wconf)
  3515. (cond
  3516. ((equal (current-buffer) abuf) nil)
  3517. (awin (select-window awin))
  3518. ((not (setq wconf (current-window-configuration))))
  3519. ((eq org-agenda-window-setup 'current-window)
  3520. (pop-to-buffer-same-window abuf))
  3521. ((eq org-agenda-window-setup 'other-window)
  3522. (org-switch-to-buffer-other-window abuf))
  3523. ((eq org-agenda-window-setup 'other-frame)
  3524. (switch-to-buffer-other-frame abuf))
  3525. ((eq org-agenda-window-setup 'other-tab)
  3526. (if (fboundp 'switch-to-buffer-other-tab)
  3527. (switch-to-buffer-other-tab abuf)
  3528. (user-error "Your version of Emacs does not have tab bar support")))
  3529. ((eq org-agenda-window-setup 'only-window)
  3530. (delete-other-windows)
  3531. (pop-to-buffer-same-window abuf))
  3532. ((eq org-agenda-window-setup 'reorganize-frame)
  3533. (delete-other-windows)
  3534. (org-switch-to-buffer-other-window abuf)))
  3535. (setq org-agenda-tag-filter (cdr (assq 'tag filter-alist)))
  3536. (setq org-agenda-category-filter (cdr (assq 'cat filter-alist)))
  3537. (setq org-agenda-effort-filter (cdr (assq 'effort filter-alist)))
  3538. (setq org-agenda-regexp-filter (cdr (assq 're filter-alist)))
  3539. ;; Additional test in case agenda is invoked from within agenda
  3540. ;; buffer via elisp link.
  3541. (unless (equal (current-buffer) abuf)
  3542. (pop-to-buffer-same-window abuf))
  3543. (setq org-agenda-pre-window-conf
  3544. (or wconf org-agenda-pre-window-conf))))
  3545. (defun org-agenda-prepare (&optional name)
  3546. (let ((filter-alist (when org-agenda-persistent-filter
  3547. (with-current-buffer
  3548. (get-buffer-create org-agenda-buffer-name)
  3549. `((tag . ,org-agenda-tag-filter)
  3550. (re . ,org-agenda-regexp-filter)
  3551. (effort . ,org-agenda-effort-filter)
  3552. (cat . ,org-agenda-category-filter))))))
  3553. (if (org-agenda-use-sticky-p)
  3554. (progn
  3555. (put 'org-agenda-tag-filter :preset-filter nil)
  3556. (put 'org-agenda-category-filter :preset-filter nil)
  3557. (put 'org-agenda-regexp-filter :preset-filter nil)
  3558. (put 'org-agenda-effort-filter :preset-filter nil)
  3559. ;; Popup existing buffer
  3560. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3561. filter-alist)
  3562. (message "Sticky Agenda buffer, use `r' to refresh")
  3563. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3564. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3565. (setq org-todo-keywords-for-agenda nil)
  3566. (put 'org-agenda-tag-filter :preset-filter
  3567. org-agenda-tag-filter-preset)
  3568. (put 'org-agenda-category-filter :preset-filter
  3569. org-agenda-category-filter-preset)
  3570. (put 'org-agenda-regexp-filter :preset-filter
  3571. org-agenda-regexp-filter-preset)
  3572. (put 'org-agenda-effort-filter :preset-filter
  3573. org-agenda-effort-filter-preset)
  3574. (if org-agenda-multi
  3575. (progn
  3576. (setq buffer-read-only nil)
  3577. (goto-char (point-max))
  3578. (unless (or (bobp) org-agenda-compact-blocks
  3579. (not org-agenda-block-separator))
  3580. (insert "\n"
  3581. (if (stringp org-agenda-block-separator)
  3582. org-agenda-block-separator
  3583. (make-string (window-max-chars-per-line) org-agenda-block-separator))
  3584. "\n"))
  3585. (narrow-to-region (point) (point-max)))
  3586. (setq org-done-keywords-for-agenda nil)
  3587. ;; Setting any org variables that are in org-agenda-local-vars
  3588. ;; list need to be done after the prepare call
  3589. (org-agenda-prepare-window
  3590. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3591. (setq buffer-read-only nil)
  3592. (org-agenda-reset-markers)
  3593. (let ((inhibit-read-only t)) (erase-buffer))
  3594. (org-agenda-mode)
  3595. (setq org-agenda-buffer (current-buffer))
  3596. (setq org-agenda-contributing-files nil)
  3597. (setq org-agenda-columns-active nil)
  3598. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3599. (setq org-todo-keywords-for-agenda
  3600. (org-uniquify org-todo-keywords-for-agenda))
  3601. (setq org-done-keywords-for-agenda
  3602. (org-uniquify org-done-keywords-for-agenda))
  3603. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3604. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3605. (and name (not org-agenda-name)
  3606. (setq-local org-agenda-name name)))
  3607. (setq buffer-read-only nil))))
  3608. (defvar org-overriding-columns-format)
  3609. (defvar org-local-columns-format)
  3610. (defun org-agenda-finalize ()
  3611. "Finishing touch for the agenda buffer.
  3612. This function is called just before displaying the agenda. If
  3613. you want to add your own functions to the finalization of the
  3614. agenda display, configure `org-agenda-finalize-hook'."
  3615. (unless org-agenda-multi
  3616. (let ((inhibit-read-only t))
  3617. (save-excursion
  3618. (goto-char (point-min))
  3619. (save-excursion
  3620. (while (org-activate-links (point-max))
  3621. (goto-char (match-end 0))))
  3622. (unless (eq org-agenda-remove-tags t)
  3623. (org-agenda-align-tags))
  3624. (unless org-agenda-with-colors
  3625. (remove-text-properties (point-min) (point-max) '(face nil)))
  3626. (when (bound-and-true-p org-overriding-columns-format)
  3627. (setq-local org-local-columns-format
  3628. org-overriding-columns-format))
  3629. (when org-agenda-view-columns-initially
  3630. (org-agenda-columns))
  3631. (when org-agenda-fontify-priorities
  3632. (org-agenda-fontify-priorities))
  3633. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3634. (org-agenda-dim-blocked-tasks))
  3635. (org-agenda-mark-clocking-task)
  3636. (when org-agenda-entry-text-mode
  3637. (org-agenda-entry-text-hide)
  3638. (org-agenda-entry-text-show))
  3639. (when (and (featurep 'org-habit)
  3640. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3641. (org-habit-insert-consistency-graphs))
  3642. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3643. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3644. (and (listp org-agenda-show-inherited-tags)
  3645. (memq org-agenda-type org-agenda-show-inherited-tags))
  3646. (and (eq org-agenda-show-inherited-tags t)
  3647. (or (eq org-agenda-use-tag-inheritance t)
  3648. (and (listp org-agenda-use-tag-inheritance)
  3649. (not (memq org-agenda-type
  3650. org-agenda-use-tag-inheritance))))))
  3651. (let (mrk)
  3652. (save-excursion
  3653. (goto-char (point-min))
  3654. (while (equal (forward-line) 0)
  3655. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3656. (put-text-property (point-at-bol) (point-at-eol)
  3657. 'tags
  3658. (org-with-point-at mrk
  3659. (org-get-tags))))))))
  3660. (setq org-agenda-represented-tags nil
  3661. org-agenda-represented-categories nil)
  3662. (when org-agenda-top-headline-filter
  3663. (org-agenda-filter-top-headline-apply
  3664. org-agenda-top-headline-filter))
  3665. (when org-agenda-tag-filter
  3666. (org-agenda-filter-apply org-agenda-tag-filter 'tag t))
  3667. (when (get 'org-agenda-tag-filter :preset-filter)
  3668. (org-agenda-filter-apply
  3669. (get 'org-agenda-tag-filter :preset-filter) 'tag t))
  3670. (when org-agenda-category-filter
  3671. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3672. (when (get 'org-agenda-category-filter :preset-filter)
  3673. (org-agenda-filter-apply
  3674. (get 'org-agenda-category-filter :preset-filter) 'category))
  3675. (when org-agenda-regexp-filter
  3676. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3677. (when (get 'org-agenda-regexp-filter :preset-filter)
  3678. (org-agenda-filter-apply
  3679. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3680. (when org-agenda-effort-filter
  3681. (org-agenda-filter-apply org-agenda-effort-filter 'effort))
  3682. (when (get 'org-agenda-effort-filter :preset-filter)
  3683. (org-agenda-filter-apply
  3684. (get 'org-agenda-effort-filter :preset-filter) 'effort))
  3685. (add-hook 'kill-buffer-hook #'org-agenda-reset-markers 'append 'local))
  3686. (run-hooks 'org-agenda-finalize-hook))))
  3687. (defun org-agenda-mark-clocking-task ()
  3688. "Mark the current clock entry in the agenda if it is present."
  3689. ;; We need to widen when `org-agenda-finalize' is called from
  3690. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in').
  3691. (when (bound-and-true-p org-clock-current-task)
  3692. (save-restriction
  3693. (widen)
  3694. (org-agenda-unmark-clocking-task)
  3695. (when (marker-buffer org-clock-hd-marker)
  3696. (save-excursion
  3697. (goto-char (point-min))
  3698. (let (s ov)
  3699. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3700. (goto-char s)
  3701. (when (equal (org-get-at-bol 'org-hd-marker)
  3702. org-clock-hd-marker)
  3703. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3704. (overlay-put ov 'type 'org-agenda-clocking)
  3705. (overlay-put ov 'face 'org-agenda-clocking)
  3706. (overlay-put ov 'help-echo
  3707. "The clock is running in this item")))))))))
  3708. (defun org-agenda-unmark-clocking-task ()
  3709. "Unmark the current clocking task."
  3710. (mapc (lambda (o)
  3711. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  3712. (delete-overlay o)))
  3713. (overlays-in (point-min) (point-max))))
  3714. (defun org-agenda-fontify-priorities ()
  3715. "Make highest priority lines bold, and lowest italic."
  3716. (interactive)
  3717. (mapc (lambda (o) (when (eq (overlay-get o 'org-type) 'org-priority)
  3718. (delete-overlay o)))
  3719. (overlays-in (point-min) (point-max)))
  3720. (save-excursion
  3721. (let (b e p ov h l)
  3722. (goto-char (point-min))
  3723. (while (re-search-forward org-priority-regexp nil t)
  3724. (setq h (or (get-char-property (point) 'org-priority-highest)
  3725. org-priority-highest)
  3726. l (or (get-char-property (point) 'org-priority-lowest)
  3727. org-priority-lowest)
  3728. p (string-to-char (match-string 2))
  3729. b (match-beginning 1)
  3730. e (if (eq org-agenda-fontify-priorities 'cookies)
  3731. (1+ (match-end 2))
  3732. (point-at-eol))
  3733. ov (make-overlay b e))
  3734. (overlay-put
  3735. ov 'face
  3736. (let ((special-face
  3737. (cond ((org-face-from-face-or-color
  3738. 'priority 'org-priority
  3739. (cdr (assoc p org-priority-faces))))
  3740. ((and (listp org-agenda-fontify-priorities)
  3741. (org-face-from-face-or-color
  3742. 'priority 'org-priority
  3743. (cdr (assoc p org-agenda-fontify-priorities)))))
  3744. ((equal p l) 'italic)
  3745. ((equal p h) 'bold))))
  3746. (if special-face (list special-face 'org-priority) 'org-priority)))
  3747. (overlay-put ov 'org-type 'org-priority)))))
  3748. (defvar org-depend-tag-blocked)
  3749. (defun org-agenda-dim-blocked-tasks (&optional _invisible)
  3750. "Dim currently blocked TODOs in the agenda display.
  3751. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3752. dimming them." ;FIXME: The arg isn't used, actually!
  3753. (interactive "P")
  3754. (when (called-interactively-p 'interactive)
  3755. (message "Dim or hide blocked tasks..."))
  3756. (dolist (o (overlays-in (point-min) (point-max)))
  3757. (when (eq (overlay-get o 'face) 'org-agenda-dimmed-todo-face)
  3758. (delete-overlay o)))
  3759. (save-excursion
  3760. (let ((inhibit-read-only t))
  3761. (goto-char (point-min))
  3762. (while (let ((pos (text-property-not-all
  3763. (point) (point-max) 'org-todo-blocked nil)))
  3764. (when pos (goto-char pos)))
  3765. (let* ((invisible
  3766. (eq (org-get-at-bol 'org-todo-blocked) 'invisible))
  3767. (todo-blocked
  3768. (eq (org-get-at-bol 'org-filter-type) 'todo-blocked))
  3769. (ov (make-overlay (if invisible
  3770. (line-end-position 0)
  3771. (line-beginning-position))
  3772. (line-end-position))))
  3773. (when todo-blocked
  3774. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3775. (when invisible
  3776. (org-agenda-filter-hide-line 'todo-blocked)))
  3777. (if (= (point-max) (line-end-position))
  3778. (goto-char (point-max))
  3779. (move-beginning-of-line 2)))))
  3780. (when (called-interactively-p 'interactive)
  3781. (message "Dim or hide blocked tasks...done")))
  3782. (defun org-agenda--mark-blocked-entry (entry)
  3783. "If ENTRY is blocked, mark it for fontification or invisibility.
  3784. If the header at `org-hd-marker' is blocked according to
  3785. `org-entry-blocked-p', then if `org-agenda-dim-blocked-tasks' is
  3786. \\='invisible and the header is not blocked by checkboxes, set the
  3787. text property `org-todo-blocked' to `invisible', otherwise set it
  3788. to t."
  3789. (when (get-text-property 0 'todo-state entry)
  3790. (let ((entry-marker (get-text-property 0 'org-hd-marker entry))
  3791. (org-blocked-by-checkboxes nil)
  3792. ;; Necessary so that `org-entry-blocked-p' does not change
  3793. ;; the buffer.
  3794. (org-depend-tag-blocked nil))
  3795. (when entry-marker
  3796. (let ((blocked
  3797. (with-current-buffer (marker-buffer entry-marker)
  3798. (save-excursion
  3799. (goto-char entry-marker)
  3800. (org-entry-blocked-p)))))
  3801. (when blocked
  3802. (let ((really-invisible
  3803. (and (not org-blocked-by-checkboxes)
  3804. (eq org-agenda-dim-blocked-tasks 'invisible))))
  3805. (put-text-property
  3806. 0 (length entry) 'org-todo-blocked
  3807. (if really-invisible 'invisible t)
  3808. entry)
  3809. (put-text-property
  3810. 0 (length entry) 'org-filter-type 'todo-blocked entry)))))))
  3811. entry)
  3812. (defvar org-agenda-skip-function nil
  3813. "Function to be called at each match during agenda construction.
  3814. If this function returns nil, the current match should not be skipped.
  3815. Otherwise, the function must return a position from where the search
  3816. should be continued.
  3817. This may also be a Lisp form, it will be evaluated.
  3818. Never set this variable using `setq' or so, because then it will apply
  3819. to all future agenda commands. If you do want a global skipping condition,
  3820. use the option `org-agenda-skip-function-global' instead.
  3821. The correct usage for `org-agenda-skip-function' is to bind it with
  3822. `let' to scope it dynamically into the agenda-constructing command.
  3823. A good way to set it is through options in `org-agenda-custom-commands'.")
  3824. (defun org-agenda-skip (&optional element)
  3825. "Throw to `:skip' in places that should be skipped.
  3826. Also moves point to the end of the skipped region, so that search can
  3827. continue from there.
  3828. Optional argument ELEMENT contains element at point."
  3829. (let ((p (point-at-bol)) to)
  3830. (when (or
  3831. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3832. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3833. (or (and (save-match-data (org-in-archived-heading-p nil element))
  3834. (org-end-of-subtree t element))
  3835. (and (member org-archive-tag org-file-tags)
  3836. (goto-char (point-max)))))
  3837. (and org-agenda-skip-comment-trees
  3838. (org-in-commented-heading-p nil element)
  3839. (org-end-of-subtree t element))
  3840. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3841. (org-agenda-skip-eval org-agenda-skip-function)))
  3842. (goto-char to))
  3843. (org-in-src-block-p t))
  3844. (throw :skip t))))
  3845. (defun org-agenda-skip-eval (form)
  3846. "If FORM is a function or a list, call (or eval) it and return the result.
  3847. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3848. and match data are returned to the previous state no matter what these
  3849. functions do."
  3850. (let (fp)
  3851. (and form
  3852. (or (setq fp (functionp form))
  3853. (consp form))
  3854. (save-excursion
  3855. (save-match-data
  3856. (if fp
  3857. (funcall form)
  3858. (eval form t)))))))
  3859. (defvar org-agenda-markers nil
  3860. "List of all currently active markers created by `org-agenda'.")
  3861. (defvar org-agenda-last-marker-time (float-time)
  3862. "Creation time of the last agenda marker.")
  3863. (defun org-agenda-new-marker (&optional pos)
  3864. "Return a new agenda marker.
  3865. Marker is at point, or at POS if non-nil. Org mode keeps a list
  3866. of these markers and resets them when they are no longer in use."
  3867. (let ((m (copy-marker (or pos (point)) t)))
  3868. (setq org-agenda-last-marker-time (float-time))
  3869. (if org-agenda-buffer
  3870. (with-current-buffer org-agenda-buffer
  3871. (push m org-agenda-markers))
  3872. (push m org-agenda-markers))
  3873. m))
  3874. (defun org-agenda-reset-markers ()
  3875. "Reset markers created by `org-agenda'."
  3876. (while org-agenda-markers
  3877. (move-marker (pop org-agenda-markers) nil)))
  3878. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3879. "Save relative positions of markers in region.
  3880. This check for agenda markers in all agenda buffers currently active."
  3881. (dolist (buf (buffer-list))
  3882. (with-current-buffer buf
  3883. (when (eq major-mode 'org-agenda-mode)
  3884. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3885. org-agenda-markers)))))
  3886. ;;; Entry text mode
  3887. (defun org-agenda-entry-text-show-here ()
  3888. "Add some text from the entry as context to the current line."
  3889. (let (m txt o)
  3890. (setq m (org-get-at-bol 'org-hd-marker))
  3891. (unless (marker-buffer m)
  3892. (error "No marker points to an entry here"))
  3893. (setq txt (concat "\n" (org-no-properties
  3894. (org-agenda-get-some-entry-text
  3895. m org-agenda-entry-text-maxlines
  3896. org-agenda-entry-text-leaders))))
  3897. (when (string-match "\\S-" txt)
  3898. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3899. (overlay-put o 'evaporate t)
  3900. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3901. (overlay-put o 'after-string txt))))
  3902. (defun org-agenda-entry-text-show ()
  3903. "Add entry context for all agenda lines."
  3904. (interactive)
  3905. (save-excursion
  3906. (goto-char (point-max))
  3907. (beginning-of-line 1)
  3908. (while (not (bobp))
  3909. (when (org-get-at-bol 'org-hd-marker)
  3910. (org-agenda-entry-text-show-here))
  3911. (beginning-of-line 0))))
  3912. (defun org-agenda-entry-text-hide ()
  3913. "Remove any shown entry context."
  3914. (mapc (lambda (o)
  3915. (when (eq (overlay-get o 'org-overlay-type)
  3916. 'agenda-entry-content)
  3917. (delete-overlay o)))
  3918. (overlays-in (point-min) (point-max))))
  3919. (defun org-agenda-get-day-face (date)
  3920. "Return the face DATE should be displayed with."
  3921. (cond ((and (functionp org-agenda-day-face-function)
  3922. (funcall org-agenda-day-face-function date)))
  3923. ((and (org-agenda-today-p date)
  3924. (memq (calendar-day-of-week date) org-agenda-weekend-days))
  3925. 'org-agenda-date-weekend-today)
  3926. ((org-agenda-today-p date) 'org-agenda-date-today)
  3927. ((memq (calendar-day-of-week date) org-agenda-weekend-days)
  3928. 'org-agenda-date-weekend)
  3929. (t 'org-agenda-date)))
  3930. (defvar org-agenda-show-log-scoped)
  3931. ;;; Agenda Daily/Weekly
  3932. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3933. "Start day for the agenda view.
  3934. Custom commands can set this variable in the options section.
  3935. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3936. input allowed when reading a date through the Org calendar.
  3937. See the docstring of `org-read-date' for details.")
  3938. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3939. (defvar org-arg-loc nil) ; local variable
  3940. ;;;###autoload
  3941. (defun org-agenda-list (&optional arg start-day span with-hour)
  3942. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3943. The view will be for the current day or week, but from the overview buffer
  3944. you will be able to go to other days/weeks.
  3945. With a numeric prefix argument in an interactive call, the agenda will
  3946. span ARG days. Lisp programs should instead specify SPAN to change
  3947. the number of days. SPAN defaults to `org-agenda-span'.
  3948. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3949. given in `org-agenda-start-on-weekday'.
  3950. When WITH-HOUR is non-nil, only include scheduled and deadline
  3951. items if they have an hour specification like [h]h:mm."
  3952. (interactive "P")
  3953. (when org-agenda-overriding-arguments
  3954. (setq arg (car org-agenda-overriding-arguments)
  3955. start-day (nth 1 org-agenda-overriding-arguments)
  3956. span (nth 2 org-agenda-overriding-arguments)))
  3957. (when (and (integerp arg) (> arg 0))
  3958. (setq span arg arg nil))
  3959. (when (numberp span)
  3960. (unless (< 0 span)
  3961. (user-error "Agenda creation impossible for this span(=%d days)" span)))
  3962. (catch 'exit
  3963. (setq org-agenda-buffer-name
  3964. (org-agenda--get-buffer-name
  3965. (and org-agenda-sticky
  3966. (cond ((and org-keys (stringp org-match))
  3967. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3968. (org-keys
  3969. (format "*Org Agenda(%s)*" org-keys))
  3970. (t "*Org Agenda(a)*")))))
  3971. (org-agenda-prepare "Day/Week")
  3972. (setq start-day (or start-day org-agenda-start-day))
  3973. (when (stringp start-day)
  3974. ;; Convert to an absolute day number
  3975. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3976. (org-compile-prefix-format 'agenda)
  3977. (org-set-sorting-strategy 'agenda)
  3978. (let* ((span (org-agenda-ndays-to-span (or span org-agenda-span)))
  3979. (today (org-today))
  3980. (sd (or start-day today))
  3981. (ndays (org-agenda-span-to-ndays span sd))
  3982. (org-agenda-start-on-weekday
  3983. (and (or (eq ndays 7) (eq ndays 14))
  3984. org-agenda-start-on-weekday))
  3985. (thefiles (org-agenda-files nil 'ifmode))
  3986. (files thefiles)
  3987. (start (if (or (null org-agenda-start-on-weekday)
  3988. (< ndays 7))
  3989. sd
  3990. (let* ((nt (calendar-day-of-week
  3991. (calendar-gregorian-from-absolute sd)))
  3992. (n1 org-agenda-start-on-weekday)
  3993. (d (- nt n1)))
  3994. (- sd (+ (if (< d 0) 7 0) d)))))
  3995. (day-numbers (list start))
  3996. (day-cnt 0)
  3997. (inhibit-redisplay (not debug-on-error))
  3998. (org-agenda-show-log-scoped org-agenda-show-log)
  3999. s rtn rtnall file date d start-pos end-pos todayp ;; e
  4000. clocktable-start clocktable-end) ;; filter
  4001. (setq org-agenda-redo-command
  4002. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  4003. (dotimes (_ (1- ndays))
  4004. (push (1+ (car day-numbers)) day-numbers))
  4005. (setq day-numbers (nreverse day-numbers))
  4006. (setq clocktable-start (car day-numbers)
  4007. clocktable-end (1+ (or (org-last day-numbers) 0)))
  4008. (setq-local org-starting-day (car day-numbers))
  4009. (setq-local org-arg-loc arg)
  4010. (setq-local org-agenda-current-span (org-agenda-ndays-to-span span))
  4011. (unless org-agenda-compact-blocks
  4012. (let* ((d1 (car day-numbers))
  4013. (d2 (org-last day-numbers))
  4014. (w1 (org-days-to-iso-week d1))
  4015. (w2 (org-days-to-iso-week d2)))
  4016. (setq s (point))
  4017. (org-agenda--insert-overriding-header
  4018. (concat (org-agenda-span-name span)
  4019. "-agenda"
  4020. (cond ((<= 350 (- d2 d1)) "")
  4021. ((= w1 w2) (format " (W%02d)" w1))
  4022. (t (format " (W%02d-W%02d)" w1 w2)))
  4023. ":\n")))
  4024. ;; Add properties if we actually inserted a header.
  4025. (when (> (point) s)
  4026. (add-text-properties s (1- (point))
  4027. (list 'face 'org-agenda-structure
  4028. 'org-date-line t))
  4029. (org-agenda-mark-header-line s)))
  4030. (while (setq d (pop day-numbers))
  4031. (setq date (calendar-gregorian-from-absolute d)
  4032. s (point))
  4033. (if (or (setq todayp (= d today))
  4034. (and (not start-pos) (= d sd)))
  4035. (setq start-pos (point))
  4036. (when (and start-pos (not end-pos))
  4037. (setq end-pos (point))))
  4038. (setq files thefiles
  4039. rtnall nil)
  4040. (while (setq file (pop files))
  4041. (catch 'nextfile
  4042. (org-check-agenda-file file)
  4043. (let ((org-agenda-entry-types org-agenda-entry-types))
  4044. ;; Starred types override non-starred equivalents
  4045. (when (member :deadline* org-agenda-entry-types)
  4046. (setq org-agenda-entry-types
  4047. (delq :deadline org-agenda-entry-types)))
  4048. (when (member :scheduled* org-agenda-entry-types)
  4049. (setq org-agenda-entry-types
  4050. (delq :scheduled org-agenda-entry-types)))
  4051. ;; Honor with-hour
  4052. (when with-hour
  4053. (when (member :deadline org-agenda-entry-types)
  4054. (setq org-agenda-entry-types
  4055. (delq :deadline org-agenda-entry-types))
  4056. (push :deadline* org-agenda-entry-types))
  4057. (when (member :scheduled org-agenda-entry-types)
  4058. (setq org-agenda-entry-types
  4059. (delq :scheduled org-agenda-entry-types))
  4060. (push :scheduled* org-agenda-entry-types)))
  4061. (unless org-agenda-include-deadlines
  4062. (setq org-agenda-entry-types
  4063. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  4064. (cond
  4065. ((memq org-agenda-show-log-scoped '(only clockcheck))
  4066. (setq rtn (org-agenda-get-day-entries
  4067. file date :closed)))
  4068. (org-agenda-show-log-scoped
  4069. (setq rtn (apply #'org-agenda-get-day-entries
  4070. file date
  4071. (append '(:closed) org-agenda-entry-types))))
  4072. (t
  4073. (setq rtn (apply #'org-agenda-get-day-entries
  4074. file date
  4075. org-agenda-entry-types)))))
  4076. (setq rtnall (append rtnall rtn)))) ;; all entries
  4077. (when org-agenda-include-diary
  4078. (let ((org-agenda-search-headline-for-time t))
  4079. (require 'diary-lib)
  4080. (setq rtn (org-get-entries-from-diary date))
  4081. (setq rtnall (append rtnall rtn))))
  4082. (when (or rtnall org-agenda-show-all-dates)
  4083. (setq day-cnt (1+ day-cnt))
  4084. (insert
  4085. (if (stringp org-agenda-format-date)
  4086. (format-time-string org-agenda-format-date
  4087. (org-time-from-absolute date))
  4088. (funcall org-agenda-format-date date))
  4089. "\n")
  4090. (put-text-property s (1- (point)) 'face
  4091. (org-agenda-get-day-face date))
  4092. (put-text-property s (1- (point)) 'org-date-line t)
  4093. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  4094. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  4095. (when todayp
  4096. (put-text-property s (1- (point)) 'org-today t))
  4097. (setq rtnall
  4098. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  4099. (when rtnall (insert ;; all entries
  4100. (org-agenda-finalize-entries rtnall 'agenda)
  4101. "\n"))
  4102. (put-text-property s (1- (point)) 'day d)
  4103. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)))
  4104. (when (and org-agenda-clockreport-mode clocktable-start)
  4105. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  4106. ;; the above line is to ensure the restricted range!
  4107. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  4108. tbl)
  4109. (setq p (org-plist-delete p :block))
  4110. (setq p (plist-put p :tstart clocktable-start))
  4111. (setq p (plist-put p :tend clocktable-end))
  4112. (setq p (plist-put p :scope 'agenda))
  4113. (setq tbl (apply #'org-clock-get-clocktable p))
  4114. (when org-agenda-clock-report-header
  4115. (insert (propertize org-agenda-clock-report-header 'face 'org-agenda-structure)))
  4116. (insert tbl)))
  4117. (goto-char (point-min))
  4118. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4119. (unless (or (not (get-buffer-window org-agenda-buffer-name))
  4120. (and (pos-visible-in-window-p (point-min))
  4121. (pos-visible-in-window-p (point-max))))
  4122. (goto-char (1- (point-max)))
  4123. (recenter -1)
  4124. (when (not (pos-visible-in-window-p (or start-pos 1)))
  4125. (goto-char (or start-pos 1))
  4126. (recenter 1)))
  4127. (goto-char (or start-pos 1))
  4128. (add-text-properties (point-min) (point-max)
  4129. `(org-agenda-type agenda
  4130. org-last-args (,arg ,start-day ,span)
  4131. org-redo-cmd ,org-agenda-redo-command
  4132. org-series-cmd ,org-cmd))
  4133. (when (eq org-agenda-show-log-scoped 'clockcheck)
  4134. (org-agenda-show-clocking-issues))
  4135. (org-agenda-finalize)
  4136. (setq buffer-read-only t)
  4137. (message ""))))
  4138. (defun org-agenda-ndays-to-span (n)
  4139. "Return a span symbol for a span of N days, or N if none matches."
  4140. (cond ((symbolp n) n)
  4141. ((= n 1) 'day)
  4142. ((= n 7) 'week)
  4143. ((= n 14) 'fortnight)
  4144. (t n)))
  4145. (defun org-agenda-span-to-ndays (span &optional start-day)
  4146. "Return ndays from SPAN, possibly starting at START-DAY.
  4147. START-DAY is an absolute time value."
  4148. (cond ((numberp span) span)
  4149. ((eq span 'day) 1)
  4150. ((eq span 'week) 7)
  4151. ((eq span 'fortnight) 14)
  4152. ((eq span 'month)
  4153. (let ((date (calendar-gregorian-from-absolute start-day)))
  4154. (calendar-last-day-of-month (car date) (cl-caddr date))))
  4155. ((eq span 'year)
  4156. (let ((date (calendar-gregorian-from-absolute start-day)))
  4157. (if (calendar-leap-year-p (cl-caddr date)) 366 365)))))
  4158. (defun org-agenda-span-name (span)
  4159. "Return a SPAN name."
  4160. (if (null span)
  4161. ""
  4162. (if (symbolp span)
  4163. (capitalize (symbol-name span))
  4164. (format "%d days" span))))
  4165. ;;; Agenda word search
  4166. (defvar org-agenda-search-history nil)
  4167. (defvar org-search-syntax-table nil
  4168. "Special syntax table for Org search.
  4169. In this table, we have single quotes not as word constituents, to
  4170. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4171. (defvar org-mode-syntax-table) ; From org.el
  4172. (defun org-search-syntax-table ()
  4173. (unless org-search-syntax-table
  4174. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4175. (modify-syntax-entry ?' "." org-search-syntax-table)
  4176. (modify-syntax-entry ?` "." org-search-syntax-table))
  4177. org-search-syntax-table)
  4178. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4179. ;;;###autoload
  4180. (defun org-search-view (&optional todo-only string edit-at)
  4181. "Show all entries that contain a phrase or words or regular expressions.
  4182. With optional prefix argument TODO-ONLY, only consider entries that are
  4183. TODO entries. The argument STRING can be used to pass a default search
  4184. string into this function. If EDIT-AT is non-nil, it means that the
  4185. user should get a chance to edit this string, with cursor at position
  4186. EDIT-AT.
  4187. The search string can be viewed either as a phrase that should be found as
  4188. is, or it can be broken into a number of snippets, each of which must match
  4189. in a Boolean way to select an entry. The default depends on the variable
  4190. `org-agenda-search-view-always-boolean'.
  4191. Even if this is turned off (the default) you can always switch to
  4192. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4193. The default is a direct search of the whole phrase, where each space in
  4194. the search string can expand to an arbitrary amount of whitespace,
  4195. including newlines.
  4196. If using a Boolean search, the search string is split on whitespace and
  4197. each snippet is searched separately, with logical AND to select an entry.
  4198. Words prefixed with a minus must *not* occur in the entry. Words without
  4199. a prefix or prefixed with a plus must occur in the entry. Matching is
  4200. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4201. match whole words, not parts of a word) if
  4202. `org-agenda-search-view-force-full-words' is set (default is nil).
  4203. Boolean search snippets enclosed by curly braces are interpreted as
  4204. regular expressions that must or (when preceded with \"-\") must not
  4205. match in the entry. Snippets enclosed into double quotes will be taken
  4206. as a whole, to include whitespace.
  4207. - If the search string starts with an asterisk, search only in headlines.
  4208. - If (possibly after the leading star) the search string starts with an
  4209. exclamation mark, this also means to look at TODO entries only, an effect
  4210. that can also be achieved with a prefix argument.
  4211. - If (possibly after star and exclamation mark) the search string starts
  4212. with a colon, this will mean that the (non-regexp) snippets of the
  4213. Boolean search must match as full words.
  4214. This command searches the agenda files, and in addition the files
  4215. listed in `org-agenda-text-search-extra-files' unless a restriction lock
  4216. is active."
  4217. (interactive "P")
  4218. (when org-agenda-overriding-arguments
  4219. (setq todo-only (car org-agenda-overriding-arguments)
  4220. string (nth 1 org-agenda-overriding-arguments)
  4221. edit-at (nth 2 org-agenda-overriding-arguments)))
  4222. (let* ((props (list 'face nil
  4223. 'done-face 'org-agenda-done
  4224. 'org-not-done-regexp org-not-done-regexp
  4225. 'org-todo-regexp org-todo-regexp
  4226. 'org-complex-heading-regexp org-complex-heading-regexp
  4227. 'mouse-face 'highlight
  4228. 'help-echo "mouse-2 or RET jump to location"))
  4229. (full-words org-agenda-search-view-force-full-words)
  4230. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4231. regexp rtn rtnall files file pos inherited-tags
  4232. marker category level tags c neg re boolean
  4233. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4234. (unless (and (not edit-at)
  4235. (stringp string)
  4236. (string-match "\\S-" string))
  4237. (setq string (read-string
  4238. (if org-agenda-search-view-always-boolean
  4239. "[+-]Word/{Regexp} ...: "
  4240. "Phrase or [+-]Word/{Regexp} ...: ")
  4241. (cond
  4242. ((integerp edit-at) (cons string edit-at))
  4243. (edit-at string))
  4244. 'org-agenda-search-history)))
  4245. (catch 'exit
  4246. (setq org-agenda-buffer-name
  4247. (org-agenda--get-buffer-name
  4248. (and org-agenda-sticky
  4249. (if (stringp string)
  4250. (format "*Org Agenda(%s:%s)*"
  4251. (or org-keys (or (and todo-only "S") "s"))
  4252. string)
  4253. (format "*Org Agenda(%s)*"
  4254. (or (and todo-only "S") "s"))))))
  4255. (org-agenda-prepare "SEARCH")
  4256. (org-compile-prefix-format 'search)
  4257. (org-set-sorting-strategy 'search)
  4258. (setq org-agenda-redo-command
  4259. (list 'org-search-view (if todo-only t nil)
  4260. (list 'if 'current-prefix-arg nil string)))
  4261. (setq org-agenda-query-string string)
  4262. (if (equal (string-to-char string) ?*)
  4263. (setq hdl-only t
  4264. words (substring string 1))
  4265. (setq words string))
  4266. (when (equal (string-to-char words) ?!)
  4267. (setq todo-only t
  4268. words (substring words 1)))
  4269. (when (equal (string-to-char words) ?:)
  4270. (setq full-words t
  4271. words (substring words 1)))
  4272. (when (or org-agenda-search-view-always-boolean
  4273. (member (string-to-char words) '(?- ?+ ?\{)))
  4274. (setq boolean t))
  4275. (setq words (split-string words))
  4276. (let (www w)
  4277. (while (setq w (pop words))
  4278. (while (and (string-match "\\\\\\'" w) words)
  4279. (setq w (concat (substring w 0 -1) " " (pop words))))
  4280. (push w www))
  4281. (setq words (nreverse www) www nil)
  4282. (while (setq w (pop words))
  4283. (when (and (string-match "\\`[-+]?{" w)
  4284. (not (string-match "}\\'" w)))
  4285. (while (and words (not (string-match "}\\'" (car words))))
  4286. (setq w (concat w " " (pop words))))
  4287. (setq w (concat w " " (pop words))))
  4288. (push w www))
  4289. (setq words (nreverse www)))
  4290. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4291. (when boolean
  4292. (let (wds w)
  4293. (while (setq w (pop words))
  4294. (when (or (equal (substring w 0 1) "\"")
  4295. (and (> (length w) 1)
  4296. (member (substring w 0 1) '("+" "-"))
  4297. (equal (substring w 1 2) "\"")))
  4298. (while (and words (not (equal (substring w -1) "\"")))
  4299. (setq w (concat w " " (pop words)))))
  4300. (and (string-match "\\`\\([-+]?\\)\"" w)
  4301. (setq w (replace-match "\\1" nil nil w)))
  4302. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4303. (push w wds))
  4304. (setq words (nreverse wds))))
  4305. (if boolean
  4306. (mapc (lambda (w)
  4307. (setq c (string-to-char w))
  4308. (if (equal c ?-)
  4309. (setq neg t w (substring w 1))
  4310. (if (equal c ?+)
  4311. (setq neg nil w (substring w 1))
  4312. (setq neg nil)))
  4313. (if (string-match "\\`{.*}\\'" w)
  4314. (setq re (substring w 1 -1))
  4315. (if full-words
  4316. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4317. (setq re (regexp-quote (downcase w)))))
  4318. (if neg (push re regexps-) (push re regexps+)))
  4319. words)
  4320. (push (mapconcat #'regexp-quote words "\\s-+")
  4321. regexps+))
  4322. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4323. (if (not regexps+)
  4324. (setq regexp org-outline-regexp-bol)
  4325. (setq regexp (pop regexps+))
  4326. (when hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4327. regexp))))
  4328. (setq files (org-agenda-files nil 'ifmode))
  4329. ;; Add `org-agenda-text-search-extra-files' unless there is some
  4330. ;; restriction.
  4331. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4332. (pop org-agenda-text-search-extra-files)
  4333. (unless (get 'org-agenda-files 'org-restrict)
  4334. (setq files (org-add-archive-files files))))
  4335. ;; Uniquify files. However, let `org-check-agenda-file' handle
  4336. ;; non-existent ones.
  4337. (setq files (cl-remove-duplicates
  4338. (append files org-agenda-text-search-extra-files)
  4339. :test (lambda (a b)
  4340. (and (file-exists-p a)
  4341. (file-exists-p b)
  4342. (file-equal-p a b))))
  4343. rtnall nil)
  4344. (while (setq file (pop files))
  4345. (setq ee nil)
  4346. (catch 'nextfile
  4347. (org-check-agenda-file file)
  4348. (setq buffer (if (file-exists-p file)
  4349. (org-get-agenda-file-buffer file)
  4350. (error "No such file %s" file)))
  4351. (unless buffer
  4352. ;; If file does not exist, make sure an error message is sent
  4353. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4354. file))))
  4355. (with-current-buffer buffer
  4356. (with-syntax-table (org-search-syntax-table)
  4357. (unless (derived-mode-p 'org-mode)
  4358. (error "Agenda file %s is not in Org mode" file))
  4359. (let ((case-fold-search t))
  4360. (save-excursion
  4361. (save-restriction
  4362. (if (eq buffer org-agenda-restrict)
  4363. (narrow-to-region org-agenda-restrict-begin
  4364. org-agenda-restrict-end)
  4365. (widen))
  4366. (goto-char (point-min))
  4367. (unless (or (org-at-heading-p)
  4368. (outline-next-heading))
  4369. (throw 'nextfile t))
  4370. (goto-char (max (point-min) (1- (point))))
  4371. (while (re-search-forward regexp nil t)
  4372. (org-back-to-heading t)
  4373. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4374. (> (org-reduced-level (org-outline-level))
  4375. org-agenda-search-view-max-outline-level)
  4376. (forward-line -1)
  4377. (org-back-to-heading t)))
  4378. (skip-chars-forward "* ")
  4379. (setq beg (point-at-bol)
  4380. beg1 (point)
  4381. end (progn
  4382. (outline-next-heading)
  4383. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4384. (> (org-reduced-level (org-outline-level))
  4385. org-agenda-search-view-max-outline-level)
  4386. (forward-line 1)
  4387. (outline-next-heading)))
  4388. (point)))
  4389. (catch :skip
  4390. (goto-char beg)
  4391. (org-agenda-skip)
  4392. (setq str (buffer-substring-no-properties
  4393. (point-at-bol)
  4394. (if hdl-only (point-at-eol) end)))
  4395. (mapc (lambda (wr) (when (string-match wr str)
  4396. (goto-char (1- end))
  4397. (throw :skip t)))
  4398. regexps-)
  4399. (mapc (lambda (wr) (unless (string-match wr str)
  4400. (goto-char (1- end))
  4401. (throw :skip t)))
  4402. (if todo-only
  4403. (cons (concat "^\\*+[ \t]+"
  4404. org-not-done-regexp)
  4405. regexps+)
  4406. regexps+))
  4407. (goto-char beg)
  4408. (setq marker (org-agenda-new-marker (point))
  4409. category (org-get-category)
  4410. level (make-string (org-reduced-level (org-outline-level)) ? )
  4411. inherited-tags
  4412. (or (eq org-agenda-show-inherited-tags 'always)
  4413. (and (listp org-agenda-show-inherited-tags)
  4414. (memq 'todo org-agenda-show-inherited-tags))
  4415. (and (eq org-agenda-show-inherited-tags t)
  4416. (or (eq org-agenda-use-tag-inheritance t)
  4417. (memq 'todo org-agenda-use-tag-inheritance))))
  4418. tags (org-get-tags nil (not inherited-tags))
  4419. txt (org-agenda-format-item
  4420. ""
  4421. (buffer-substring-no-properties
  4422. beg1 (point-at-eol))
  4423. level category tags t))
  4424. (org-add-props txt props
  4425. 'org-marker marker 'org-hd-marker marker
  4426. 'org-todo-regexp org-todo-regexp
  4427. 'level level
  4428. 'org-complex-heading-regexp org-complex-heading-regexp
  4429. 'priority 1000
  4430. 'type "search")
  4431. (push txt ee)
  4432. (goto-char (1- end))))))))))
  4433. (setq rtn (nreverse ee))
  4434. (setq rtnall (append rtnall rtn)))
  4435. (org-agenda--insert-overriding-header
  4436. (with-temp-buffer
  4437. (insert "Search words: ")
  4438. (add-text-properties (point-min) (1- (point))
  4439. (list 'face 'org-agenda-structure))
  4440. (setq pos (point))
  4441. (insert string "\n")
  4442. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4443. (setq pos (point))
  4444. (unless org-agenda-multi
  4445. (insert (substitute-command-keys "\\<org-agenda-mode-map>\
  4446. Press `\\[org-agenda-manipulate-query-add]', \
  4447. `\\[org-agenda-manipulate-query-subtract]' to add/sub word, \
  4448. `\\[org-agenda-manipulate-query-add-re]', \
  4449. `\\[org-agenda-manipulate-query-subtract-re]' to add/sub regexp, \
  4450. `\\[universal-argument] \\[org-agenda-redo]' for a fresh search\n"))
  4451. (add-text-properties pos (1- (point))
  4452. (list 'face 'org-agenda-structure-secondary)))
  4453. (buffer-string)))
  4454. (org-agenda-mark-header-line (point-min))
  4455. (when rtnall
  4456. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4457. (goto-char (point-min))
  4458. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4459. (add-text-properties (point-min) (point-max)
  4460. `(org-agenda-type search
  4461. org-last-args (,todo-only ,string ,edit-at)
  4462. org-redo-cmd ,org-agenda-redo-command
  4463. org-series-cmd ,org-cmd))
  4464. (org-agenda-finalize)
  4465. (setq buffer-read-only t))))
  4466. ;;; Agenda TODO list
  4467. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4468. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4469. (concat
  4470. (if (or (equal keywords "ALL") (not keywords))
  4471. (propertize "ALL" 'face 'org-agenda-structure-filter)
  4472. (mapconcat
  4473. (lambda (kw)
  4474. (propertize kw 'face (list (org-get-todo-face kw) 'org-agenda-structure)))
  4475. (org-split-string keywords "|")
  4476. "|"))
  4477. "\n"))
  4478. (defvar org-select-this-todo-keyword nil)
  4479. (defvar org-last-arg nil)
  4480. (defvar crm-separator)
  4481. ;;;###autoload
  4482. (defun org-todo-list (&optional arg)
  4483. "Show all (not done) TODO entries from all agenda files in a single list.
  4484. The prefix arg can be used to select a specific TODO keyword and limit
  4485. the list to these. When using `\\[universal-argument]', you will be prompted
  4486. for a keyword. A numeric prefix directly selects the Nth keyword in
  4487. `org-todo-keywords-1'."
  4488. (interactive "P")
  4489. (when org-agenda-overriding-arguments
  4490. (setq arg org-agenda-overriding-arguments))
  4491. (when (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4492. (let* ((today (org-today))
  4493. (date (calendar-gregorian-from-absolute today))
  4494. (completion-ignore-case t)
  4495. kwds org-select-this-todo-keyword rtn rtnall files file pos)
  4496. (catch 'exit
  4497. (setq org-agenda-buffer-name
  4498. (org-agenda--get-buffer-name
  4499. (and org-agenda-sticky
  4500. (if (stringp org-select-this-todo-keyword)
  4501. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4502. org-select-this-todo-keyword)
  4503. (format "*Org Agenda(%s)*" (or org-keys "t"))))))
  4504. (org-agenda-prepare "TODO")
  4505. (setq kwds org-todo-keywords-for-agenda
  4506. org-select-this-todo-keyword (if (stringp arg) arg
  4507. (and (integerp arg)
  4508. (> arg 0)
  4509. (nth (1- arg) kwds))))
  4510. (when (equal arg '(4))
  4511. (setq org-select-this-todo-keyword
  4512. (mapconcat #'identity
  4513. (let ((crm-separator "|"))
  4514. (completing-read-multiple
  4515. "Keyword (or KWD1|KWD2|...): "
  4516. (mapcar #'list kwds) nil nil))
  4517. "|")))
  4518. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4519. (org-compile-prefix-format 'todo)
  4520. (org-set-sorting-strategy 'todo)
  4521. (setq org-agenda-redo-command
  4522. `(org-todo-list (or (and (numberp current-prefix-arg)
  4523. current-prefix-arg)
  4524. ,org-select-this-todo-keyword
  4525. current-prefix-arg ,arg)))
  4526. (setq files (org-agenda-files nil 'ifmode)
  4527. rtnall nil)
  4528. (while (setq file (pop files))
  4529. (catch 'nextfile
  4530. (org-check-agenda-file file)
  4531. (setq rtn (org-agenda-get-day-entries file date :todo))
  4532. (setq rtnall (append rtnall rtn))))
  4533. (org-agenda--insert-overriding-header
  4534. (with-temp-buffer
  4535. (insert "Global list of TODO items of type: ")
  4536. (add-text-properties (point-min) (1- (point))
  4537. (list 'face 'org-agenda-structure
  4538. 'short-heading
  4539. (concat "ToDo: "
  4540. (or org-select-this-todo-keyword "ALL"))))
  4541. (org-agenda-mark-header-line (point-min))
  4542. (insert (org-agenda-propertize-selected-todo-keywords
  4543. org-select-this-todo-keyword))
  4544. (setq pos (point))
  4545. (unless org-agenda-multi
  4546. (insert (substitute-command-keys "Press \
  4547. \\<org-agenda-mode-map>`N \\[org-agenda-redo]' (e.g. `0 \\[org-agenda-redo]') \
  4548. to search again: (0)[ALL]"))
  4549. (let ((n 0))
  4550. (dolist (k kwds)
  4551. (let ((s (format "(%d)%s" (cl-incf n) k)))
  4552. (when (> (+ (current-column) (string-width s) 1) (window-max-chars-per-line))
  4553. (insert "\n "))
  4554. (insert " " s))))
  4555. (insert "\n"))
  4556. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-secondary))
  4557. (buffer-string)))
  4558. (org-agenda-mark-header-line (point-min))
  4559. (when rtnall
  4560. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4561. (goto-char (point-min))
  4562. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4563. (add-text-properties (point-min) (point-max)
  4564. `(org-agenda-type todo
  4565. org-last-args ,arg
  4566. org-redo-cmd ,org-agenda-redo-command
  4567. org-series-cmd ,org-cmd))
  4568. (org-agenda-finalize)
  4569. (setq buffer-read-only t))))
  4570. ;;; Agenda tags match
  4571. ;;;###autoload
  4572. (defun org-tags-view (&optional todo-only match)
  4573. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4574. The prefix arg TODO-ONLY limits the search to TODO entries."
  4575. (interactive "P")
  4576. (when org-agenda-overriding-arguments
  4577. (setq todo-only (car org-agenda-overriding-arguments)
  4578. match (nth 1 org-agenda-overriding-arguments)))
  4579. (let* ((org-tags-match-list-sublevels
  4580. org-tags-match-list-sublevels)
  4581. (completion-ignore-case t)
  4582. (org--matcher-tags-todo-only todo-only)
  4583. rtn rtnall files file pos matcher
  4584. buffer)
  4585. (when (and (stringp match) (not (string-match "\\S-" match)))
  4586. (setq match nil))
  4587. (catch 'exit
  4588. (setq org-agenda-buffer-name
  4589. (org-agenda--get-buffer-name
  4590. (and org-agenda-sticky
  4591. (if (stringp match)
  4592. (format "*Org Agenda(%s:%s)*"
  4593. (or org-keys (or (and todo-only "M") "m"))
  4594. match)
  4595. (format "*Org Agenda(%s)*"
  4596. (or (and todo-only "M") "m"))))))
  4597. (setq matcher (org-make-tags-matcher match))
  4598. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4599. ;; expanding tags within `org-make-tags-matcher'
  4600. (org-agenda-prepare (concat "TAGS " match))
  4601. (setq match (car matcher)
  4602. matcher (cdr matcher))
  4603. (org-compile-prefix-format 'tags)
  4604. (org-set-sorting-strategy 'tags)
  4605. (setq org-agenda-query-string match)
  4606. (setq org-agenda-redo-command
  4607. (list 'org-tags-view
  4608. `(quote ,org--matcher-tags-todo-only)
  4609. `(if current-prefix-arg nil ,org-agenda-query-string)))
  4610. (setq files (org-agenda-files nil 'ifmode)
  4611. rtnall nil)
  4612. (while (setq file (pop files))
  4613. (catch 'nextfile
  4614. (org-check-agenda-file file)
  4615. (setq buffer (if (file-exists-p file)
  4616. (org-get-agenda-file-buffer file)
  4617. (error "No such file %s" file)))
  4618. (if (not buffer)
  4619. ;; If file does not exist, error message to agenda
  4620. (setq rtn (list
  4621. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4622. rtnall (append rtnall rtn))
  4623. (with-current-buffer buffer
  4624. (unless (derived-mode-p 'org-mode)
  4625. (error "Agenda file %s is not in Org mode" file))
  4626. (save-excursion
  4627. (save-restriction
  4628. (if (eq buffer org-agenda-restrict)
  4629. (narrow-to-region org-agenda-restrict-begin
  4630. org-agenda-restrict-end)
  4631. (widen))
  4632. (setq rtn (org-scan-tags 'agenda
  4633. matcher
  4634. org--matcher-tags-todo-only))
  4635. (setq rtnall (append rtnall rtn))))))))
  4636. (org-agenda--insert-overriding-header
  4637. (with-temp-buffer
  4638. (insert "Headlines with TAGS match: ")
  4639. (add-text-properties (point-min) (1- (point))
  4640. (list 'face 'org-agenda-structure
  4641. 'short-heading
  4642. (concat "Match: " match)))
  4643. (setq pos (point))
  4644. (insert match "\n")
  4645. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure-filter))
  4646. (setq pos (point))
  4647. (unless org-agenda-multi
  4648. (insert (substitute-command-keys
  4649. "Press \
  4650. \\<org-agenda-mode-map>`\\[universal-argument] \\[org-agenda-redo]' \
  4651. to search again\n")))
  4652. (add-text-properties pos (1- (point))
  4653. (list 'face 'org-agenda-structure-secondary))
  4654. (buffer-string)))
  4655. (org-agenda-mark-header-line (point-min))
  4656. (when rtnall
  4657. (insert (org-agenda-finalize-entries rtnall 'tags) "\n"))
  4658. (goto-char (point-min))
  4659. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4660. (add-text-properties
  4661. (point-min) (point-max)
  4662. `(org-agenda-type tags
  4663. org-last-args (,org--matcher-tags-todo-only ,match)
  4664. org-redo-cmd ,org-agenda-redo-command
  4665. org-series-cmd ,org-cmd))
  4666. (org-agenda-finalize)
  4667. (setq buffer-read-only t))))
  4668. ;;; Agenda Finding stuck projects
  4669. (defvar org-agenda-skip-regexp nil
  4670. "Regular expression used in skipping subtrees for the agenda.
  4671. This is basically a temporary global variable that can be set and then
  4672. used by user-defined selections using `org-agenda-skip-function'.")
  4673. (defvar org-agenda-overriding-header nil
  4674. "When set during agenda, todo and tags searches it replaces the header.
  4675. If an empty string, no header will be inserted. If any other
  4676. string, it will be inserted as a header. If a function, insert
  4677. the string returned by the function as a header. If nil, a
  4678. header will be generated automatically according to the command.
  4679. This variable should not be set directly, but custom commands can
  4680. bind it in the options section.")
  4681. (defun org-agenda-skip-entry-if (&rest conditions)
  4682. "Skip entry if any of CONDITIONS is true.
  4683. See `org-agenda-skip-if' for details."
  4684. (org-agenda-skip-if nil conditions))
  4685. (defun org-agenda-skip-subtree-if (&rest conditions)
  4686. "Skip subtree if any of CONDITIONS is true.
  4687. See `org-agenda-skip-if' for details."
  4688. (org-agenda-skip-if t conditions))
  4689. (defun org-agenda-skip-if (subtree conditions)
  4690. "Check current entity for CONDITIONS.
  4691. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4692. the entry (i.e. the text before the next heading) is checked.
  4693. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4694. from different tests. Valid conditions are:
  4695. scheduled Check if there is a scheduled cookie
  4696. notscheduled Check if there is no scheduled cookie
  4697. deadline Check if there is a deadline
  4698. notdeadline Check if there is no deadline
  4699. timestamp Check if there is a timestamp (also deadline or scheduled)
  4700. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4701. regexp Check if regexp matches
  4702. notregexp Check if regexp does not match.
  4703. todo Check if TODO keyword matches
  4704. nottodo Check if TODO keyword does not match
  4705. The regexp is taken from the conditions list, it must come right after
  4706. the `regexp' or `notregexp' element.
  4707. `todo' and `nottodo' accept as an argument a list of todo
  4708. keywords, which may include \"*\" to match any todo keyword.
  4709. (org-agenda-skip-entry-if \\='todo \\='(\"TODO\" \"WAITING\"))
  4710. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4711. Instead of a list, a keyword class may be given. For example:
  4712. (org-agenda-skip-entry-if \\='nottodo \\='done)
  4713. would skip entries that haven't been marked with any of \"DONE\"
  4714. keywords. Possible classes are: `todo', `done', `any'.
  4715. If any of these conditions is met, this function returns the end point of
  4716. the entity, causing the search to continue from there. This is a function
  4717. that can be put into `org-agenda-skip-function' for the duration of a command."
  4718. (org-back-to-heading t)
  4719. (let* (;; (beg (point))
  4720. (end (if subtree (save-excursion (org-end-of-subtree t) (point))
  4721. (org-entry-end-position)))
  4722. (planning-end (if subtree end (line-end-position 2)))
  4723. m)
  4724. (and
  4725. (or (and (memq 'scheduled conditions)
  4726. (re-search-forward org-scheduled-time-regexp planning-end t))
  4727. (and (memq 'notscheduled conditions)
  4728. (not
  4729. (save-excursion
  4730. (re-search-forward org-scheduled-time-regexp planning-end t))))
  4731. (and (memq 'deadline conditions)
  4732. (re-search-forward org-deadline-time-regexp planning-end t))
  4733. (and (memq 'notdeadline conditions)
  4734. (not
  4735. (save-excursion
  4736. (re-search-forward org-deadline-time-regexp planning-end t))))
  4737. (and (memq 'timestamp conditions)
  4738. (re-search-forward org-ts-regexp end t))
  4739. (and (memq 'nottimestamp conditions)
  4740. (not (save-excursion (re-search-forward org-ts-regexp end t))))
  4741. (and (setq m (memq 'regexp conditions))
  4742. (stringp (nth 1 m))
  4743. (re-search-forward (nth 1 m) end t))
  4744. (and (setq m (memq 'notregexp conditions))
  4745. (stringp (nth 1 m))
  4746. (not (save-excursion (re-search-forward (nth 1 m) end t))))
  4747. (and (or
  4748. (setq m (memq 'nottodo conditions))
  4749. (setq m (memq 'todo-unblocked conditions))
  4750. (setq m (memq 'nottodo-unblocked conditions))
  4751. (setq m (memq 'todo conditions)))
  4752. (org-agenda-skip-if-todo m end)))
  4753. end)))
  4754. (defun org-agenda-skip-if-todo (args end)
  4755. "Helper function for `org-agenda-skip-if', do not use it directly.
  4756. ARGS is a list with first element either `todo', `nottodo',
  4757. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4758. a list of TODO keywords, or a state symbol `todo' or `done' or
  4759. `any'."
  4760. (let ((todo-re
  4761. (concat "^\\*+[ \t]+"
  4762. (regexp-opt
  4763. (pcase args
  4764. (`(,_ todo)
  4765. (org-delete-all org-done-keywords
  4766. (copy-sequence org-todo-keywords-1)))
  4767. (`(,_ done) org-done-keywords)
  4768. (`(,_ any) org-todo-keywords-1)
  4769. (`(,_ ,(pred atom))
  4770. (error "Invalid TODO class or type: %S" args))
  4771. (`(,_ ,(pred (member "*"))) org-todo-keywords-1)
  4772. (`(,_ ,todo-list) todo-list))
  4773. 'words))))
  4774. (pcase args
  4775. (`(todo . ,_)
  4776. (let (case-fold-search) (re-search-forward todo-re end t)))
  4777. (`(nottodo . ,_)
  4778. (not (let (case-fold-search) (re-search-forward todo-re end t))))
  4779. (`(todo-unblocked . ,_)
  4780. (catch :unblocked
  4781. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4782. (when (org-entry-blocked-p) (throw :unblocked t)))
  4783. nil))
  4784. (`(nottodo-unblocked . ,_)
  4785. (catch :unblocked
  4786. (while (let (case-fold-search) (re-search-forward todo-re end t))
  4787. (when (org-entry-blocked-p) (throw :unblocked nil)))
  4788. t))
  4789. (`(,type . ,_) (error "Unknown TODO skip type: %S" type)))))
  4790. ;;;###autoload
  4791. (defun org-agenda-list-stuck-projects (&rest _ignore)
  4792. "Create agenda view for projects that are stuck.
  4793. Stuck projects are project that have no next actions. For the definitions
  4794. of what a project is and how to check if it stuck, customize the variable
  4795. `org-stuck-projects'."
  4796. (interactive)
  4797. (let* ((org-agenda-overriding-header
  4798. (or org-agenda-overriding-header "List of stuck projects: "))
  4799. (matcher (nth 0 org-stuck-projects))
  4800. (todo (nth 1 org-stuck-projects))
  4801. (tags (nth 2 org-stuck-projects))
  4802. (gen-re (org-string-nw-p (nth 3 org-stuck-projects)))
  4803. (todo-wds
  4804. (if (not (member "*" todo)) todo
  4805. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  4806. (org-delete-all org-done-keywords-for-agenda
  4807. (copy-sequence org-todo-keywords-for-agenda))))
  4808. (todo-re (and todo
  4809. (format "^\\*+[ \t]+\\(%s\\)\\>"
  4810. (mapconcat #'identity todo-wds "\\|"))))
  4811. (tags-re (cond ((null tags) nil)
  4812. ((member "*" tags) org-tag-line-re)
  4813. (tags
  4814. (let ((other-tags (format "\\(?:%s:\\)*" org-tag-re)))
  4815. (concat org-outline-regexp-bol
  4816. ".*?[ \t]:"
  4817. other-tags
  4818. (regexp-opt tags t)
  4819. ":" other-tags "[ \t]*$")))
  4820. (t nil)))
  4821. (re-list (delq nil (list todo-re tags-re gen-re)))
  4822. (skip-re
  4823. (if (null re-list)
  4824. (error "Missing information to identify unstuck projects")
  4825. (mapconcat #'identity re-list "\\|")))
  4826. (org-agenda-skip-function
  4827. ;; Skip entry if `org-agenda-skip-regexp' matches anywhere
  4828. ;; in the subtree.
  4829. (lambda ()
  4830. (and (save-excursion
  4831. (let ((case-fold-search nil))
  4832. (re-search-forward
  4833. skip-re (save-excursion (org-end-of-subtree t)) t)))
  4834. (progn (outline-next-heading) (point))))))
  4835. (org-tags-view nil matcher)
  4836. (setq org-agenda-buffer-name (buffer-name))
  4837. (with-current-buffer org-agenda-buffer-name
  4838. (setq org-agenda-redo-command
  4839. `(org-agenda-list-stuck-projects ,current-prefix-arg))
  4840. (let ((inhibit-read-only t))
  4841. (add-text-properties
  4842. (point-min) (point-max)
  4843. `(org-redo-cmd ,org-agenda-redo-command))))))
  4844. ;;; Diary integration
  4845. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4846. (defvar diary-list-entries-hook)
  4847. (defvar diary-time-regexp)
  4848. (defvar diary-modify-entry-list-string-function)
  4849. (defvar diary-file-name-prefix)
  4850. (defvar diary-display-function)
  4851. (defun org-get-entries-from-diary (date)
  4852. "Get the (Emacs Calendar) diary entries for DATE."
  4853. (require 'diary-lib)
  4854. (declare-function diary-fancy-display "diary-lib" ())
  4855. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4856. (diary-display-function #'diary-fancy-display)
  4857. (pop-up-frames nil)
  4858. (diary-list-entries-hook
  4859. (cons 'org-diary-default-entry diary-list-entries-hook))
  4860. (diary-file-name-prefix nil) ; turn this feature off
  4861. (diary-modify-entry-list-string-function
  4862. #'org-modify-diary-entry-string)
  4863. (diary-time-regexp (concat "^" diary-time-regexp))
  4864. entries
  4865. (org-disable-agenda-to-diary t))
  4866. (save-excursion
  4867. (save-window-excursion
  4868. (diary-list-entries date 1)))
  4869. (if (not (get-buffer diary-fancy-buffer))
  4870. (setq entries nil)
  4871. (with-current-buffer diary-fancy-buffer
  4872. (setq buffer-read-only nil)
  4873. (if (zerop (buffer-size))
  4874. ;; No entries
  4875. (setq entries nil)
  4876. ;; Omit the date and other unnecessary stuff
  4877. (org-agenda-cleanup-fancy-diary)
  4878. ;; Add prefix to each line and extend the text properties
  4879. (if (zerop (buffer-size))
  4880. (setq entries nil)
  4881. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4882. (setq entries
  4883. (with-temp-buffer
  4884. (insert entries) (goto-char (point-min))
  4885. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4886. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4887. (replace-match (concat "; " (match-string 1)))))
  4888. (buffer-string)))))
  4889. (set-buffer-modified-p nil)
  4890. (kill-buffer diary-fancy-buffer)))
  4891. (when entries
  4892. (setq entries (org-split-string entries "\n"))
  4893. (setq entries
  4894. (mapcar
  4895. (lambda (x)
  4896. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4897. ;; Extend the text properties to the beginning of the line
  4898. (org-add-props x (text-properties-at (1- (length x)) x)
  4899. 'type "diary" 'date date 'face 'org-agenda-diary))
  4900. entries)))))
  4901. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4902. "Hook run when the fancy diary buffer is cleaned up.")
  4903. (defun org-agenda-cleanup-fancy-diary ()
  4904. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4905. This gets rid of the date, the underline under the date, and the
  4906. dummy entry installed by Org mode to ensure non-empty diary for
  4907. each date. It also removes lines that contain only whitespace."
  4908. (goto-char (point-min))
  4909. (if (looking-at ".*?:[ \t]*")
  4910. (progn
  4911. (replace-match "")
  4912. (re-search-forward "\n=+$" nil t)
  4913. (replace-match "")
  4914. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4915. (re-search-forward "\n=+$" nil t)
  4916. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4917. (goto-char (point-min))
  4918. (while (re-search-forward "^ +\n" nil t)
  4919. (replace-match ""))
  4920. (goto-char (point-min))
  4921. (when (re-search-forward "^Org mode dummy\n?" nil t)
  4922. (replace-match ""))
  4923. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4924. (defun org-modify-diary-entry-string (string)
  4925. "Add text properties to string, allowing Org to act on it."
  4926. (org-add-props string nil
  4927. 'mouse-face 'highlight
  4928. 'help-echo (if buffer-file-name
  4929. (format "mouse-2 or RET jump to diary file %s"
  4930. (abbreviate-file-name buffer-file-name))
  4931. "")
  4932. 'org-agenda-diary-link t
  4933. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4934. (defun org-diary-default-entry ()
  4935. "Add a dummy entry to the diary.
  4936. Needed to avoid empty dates which mess up holiday display."
  4937. ;; Catch the error if dealing with the new add-to-diary-alist
  4938. (when org-disable-agenda-to-diary
  4939. (diary-add-to-list original-date "Org mode dummy" "")))
  4940. (defvar org-diary-last-run-time nil)
  4941. ;;;###autoload
  4942. (defun org-diary (&rest args)
  4943. "Return diary information from org files.
  4944. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4945. It accesses org files and extracts information from those files to be
  4946. listed in the diary. The function accepts arguments specifying what
  4947. items should be listed. For a list of arguments allowed here, see the
  4948. variable `org-agenda-entry-types'.
  4949. The call in the diary file should look like this:
  4950. &%%(org-diary) ~/path/to/some/orgfile.org
  4951. Use a separate line for each org file to check. Or, if you omit the file name,
  4952. all files listed in `org-agenda-files' will be checked automatically:
  4953. &%%(org-diary)
  4954. If you don't give any arguments (as in the example above), the default value
  4955. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4956. So the example above may also be written as
  4957. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4958. The function expects the lisp variables `entry' and `date' to be provided
  4959. by the caller, because this is how the calendar works. Don't use this
  4960. function from a program - use `org-agenda-get-day-entries' instead."
  4961. (with-no-warnings (defvar date) (defvar entry))
  4962. (when (> (- (float-time)
  4963. org-agenda-last-marker-time)
  4964. 5)
  4965. ;; I am not sure if this works with sticky agendas, because the marker
  4966. ;; list is then no longer a global variable.
  4967. (org-agenda-reset-markers))
  4968. (org-compile-prefix-format 'agenda)
  4969. (org-set-sorting-strategy 'agenda)
  4970. (setq args (or args org-agenda-entry-types))
  4971. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4972. (list entry)
  4973. (org-agenda-files t)))
  4974. (time (float-time))
  4975. file rtn results)
  4976. (when (or (not org-diary-last-run-time)
  4977. (> (- time
  4978. org-diary-last-run-time)
  4979. 3))
  4980. (org-agenda-prepare-buffers files))
  4981. (setq org-diary-last-run-time time)
  4982. ;; If this is called during org-agenda, don't return any entries to
  4983. ;; the calendar. Org Agenda will list these entries itself.
  4984. (when org-disable-agenda-to-diary (setq files nil))
  4985. (while (setq file (pop files))
  4986. (setq rtn (apply #'org-agenda-get-day-entries file date args))
  4987. (setq results (append results rtn)))
  4988. (when results
  4989. (setq results
  4990. (mapcar (lambda (i) (replace-regexp-in-string
  4991. org-link-bracket-re "\\2" i))
  4992. results))
  4993. (concat (org-agenda-finalize-entries results) "\n"))))
  4994. ;;; Agenda entry finders
  4995. (defun org-agenda--timestamp-to-absolute (&rest args)
  4996. "Call `org-time-string-to-absolute' with ARGS.
  4997. However, throw `:skip' whenever an error is raised."
  4998. (condition-case e
  4999. (apply #'org-time-string-to-absolute args)
  5000. (org-diary-sexp-no-match (throw :skip nil))
  5001. (error
  5002. (message "%s; Skipping entry" (error-message-string e))
  5003. (throw :skip nil))))
  5004. (defun org-agenda-get-day-entries (file date &rest args)
  5005. "Does the work for `org-diary' and `org-agenda'.
  5006. FILE is the path to a file to be checked for entries. DATE is date like
  5007. the one returned by `calendar-current-date'. ARGS are symbols indicating
  5008. which kind of entries should be extracted. For details about these, see
  5009. the documentation of `org-diary'."
  5010. (let* ((org-startup-folded nil)
  5011. (org-startup-align-all-tables nil)
  5012. (buffer (if (file-exists-p file) (org-get-agenda-file-buffer file)
  5013. (error "No such file %s" file))))
  5014. (if (not buffer)
  5015. ;; If file does not exist, signal it in diary nonetheless.
  5016. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  5017. (with-current-buffer buffer
  5018. (unless (derived-mode-p 'org-mode)
  5019. (error "Agenda file %s is not in Org mode" file))
  5020. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  5021. (setf org-agenda-current-date date)
  5022. (save-excursion
  5023. (save-restriction
  5024. (if (eq buffer org-agenda-restrict)
  5025. (narrow-to-region org-agenda-restrict-begin
  5026. org-agenda-restrict-end)
  5027. (widen))
  5028. ;; Rationalize ARGS. Also make sure `:deadline' comes
  5029. ;; first in order to populate DEADLINES before passing it.
  5030. ;;
  5031. ;; We use `delq' since `org-uniquify' duplicates ARGS,
  5032. ;; guarding us from modifying `org-agenda-entry-types'.
  5033. (setf args (org-uniquify (or args org-agenda-entry-types)))
  5034. (when (and (memq :scheduled args) (memq :scheduled* args))
  5035. (setf args (delq :scheduled* args)))
  5036. (cond
  5037. ((memq :deadline args)
  5038. (setf args (cons :deadline
  5039. (delq :deadline (delq :deadline* args)))))
  5040. ((memq :deadline* args)
  5041. (setf args (cons :deadline* (delq :deadline* args)))))
  5042. ;; Collect list of headlines. Return them flattened.
  5043. (let ((case-fold-search nil) results deadlines)
  5044. (org-dlet
  5045. ((date date))
  5046. (dolist (arg args (apply #'nconc (nreverse results)))
  5047. (pcase arg
  5048. ((and :todo (guard (org-agenda-today-p date)))
  5049. (push (org-agenda-get-todos) results))
  5050. (:timestamp
  5051. (push (org-agenda-get-blocks) results)
  5052. (push (org-agenda-get-timestamps deadlines) results))
  5053. (:sexp
  5054. (push (org-agenda-get-sexps) results))
  5055. (:scheduled
  5056. (push (org-agenda-get-scheduled deadlines) results))
  5057. (:scheduled*
  5058. (push (org-agenda-get-scheduled deadlines t) results))
  5059. (:closed
  5060. (push (org-agenda-get-progress) results))
  5061. (:deadline
  5062. (setf deadlines (org-agenda-get-deadlines))
  5063. (push deadlines results))
  5064. (:deadline*
  5065. (setf deadlines (org-agenda-get-deadlines t))
  5066. (push deadlines results))))))))))))
  5067. (defsubst org-em (x y list)
  5068. "Is X or Y a member of LIST?"
  5069. (or (memq x list) (memq y list)))
  5070. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  5071. (defvar org-agenda-sorting-strategy-selected nil)
  5072. (defun org-agenda-entry-get-agenda-timestamp (pom)
  5073. "Retrieve timestamp information for sorting agenda views.
  5074. Given a point or marker POM, returns a cons cell of the timestamp
  5075. and the timestamp type relevant for the sorting strategy in
  5076. `org-agenda-sorting-strategy-selected'."
  5077. (let (ts ts-date-type)
  5078. (save-match-data
  5079. (cond ((org-em 'scheduled-up 'scheduled-down
  5080. org-agenda-sorting-strategy-selected)
  5081. (setq ts (org-entry-get pom "SCHEDULED")
  5082. ts-date-type " scheduled"))
  5083. ((org-em 'deadline-up 'deadline-down
  5084. org-agenda-sorting-strategy-selected)
  5085. (setq ts (org-entry-get pom "DEADLINE")
  5086. ts-date-type " deadline"))
  5087. ((org-em 'ts-up 'ts-down
  5088. org-agenda-sorting-strategy-selected)
  5089. (setq ts (org-entry-get pom "TIMESTAMP")
  5090. ts-date-type " timestamp"))
  5091. ((org-em 'tsia-up 'tsia-down
  5092. org-agenda-sorting-strategy-selected)
  5093. (setq ts (org-entry-get pom "TIMESTAMP_IA")
  5094. ts-date-type " timestamp_ia"))
  5095. ((org-em 'timestamp-up 'timestamp-down
  5096. org-agenda-sorting-strategy-selected)
  5097. (setq ts (or (org-entry-get pom "SCHEDULED")
  5098. (org-entry-get pom "DEADLINE")
  5099. (org-entry-get pom "TIMESTAMP")
  5100. (org-entry-get pom "TIMESTAMP_IA"))
  5101. ts-date-type ""))
  5102. (t (setq ts-date-type "")))
  5103. (cons (when ts (ignore-errors (org-time-string-to-absolute ts)))
  5104. ts-date-type))))
  5105. (defun org-agenda-get-todos ()
  5106. "Return the TODO information for agenda display."
  5107. (let* ((props (list 'face nil
  5108. 'done-face 'org-agenda-done
  5109. 'org-not-done-regexp org-not-done-regexp
  5110. 'org-todo-regexp org-todo-regexp
  5111. 'org-complex-heading-regexp org-complex-heading-regexp
  5112. 'mouse-face 'highlight
  5113. 'help-echo
  5114. (format "mouse-2 or RET jump to org file %s"
  5115. (abbreviate-file-name buffer-file-name))))
  5116. (case-fold-search nil)
  5117. (regexp (format org-heading-keyword-regexp-format
  5118. (cond
  5119. ((and org-select-this-todo-keyword
  5120. (equal org-select-this-todo-keyword "*"))
  5121. org-todo-regexp)
  5122. (org-select-this-todo-keyword
  5123. (concat "\\("
  5124. (mapconcat #'identity
  5125. (org-split-string
  5126. org-select-this-todo-keyword
  5127. "|")
  5128. "\\|")
  5129. "\\)"))
  5130. (t org-not-done-regexp))))
  5131. marker priority category level tags todo-state
  5132. ts-date ts-date-type ts-date-pair
  5133. ee txt beg end inherited-tags todo-state-end-pos
  5134. effort effort-minutes)
  5135. (goto-char (point-min))
  5136. (while (re-search-forward regexp nil t)
  5137. (catch :skip
  5138. (save-match-data
  5139. (beginning-of-line)
  5140. (org-agenda-skip)
  5141. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  5142. (unless (and (setq todo-state (org-get-todo-state))
  5143. (setq todo-state-end-pos (match-end 2)))
  5144. (goto-char end)
  5145. (throw :skip nil))
  5146. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  5147. (goto-char (1+ beg))
  5148. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  5149. (throw :skip nil)))
  5150. (goto-char (match-beginning 2))
  5151. (setq marker (org-agenda-new-marker (match-beginning 0))
  5152. category (org-get-category)
  5153. effort (save-match-data (or (get-text-property (point) 'effort)
  5154. (org-entry-get (point) org-effort-property)))
  5155. effort-minutes (when effort (save-match-data (org-duration-to-minutes effort)))
  5156. ts-date-pair (org-agenda-entry-get-agenda-timestamp (point))
  5157. ts-date (car ts-date-pair)
  5158. ts-date-type (cdr ts-date-pair)
  5159. txt (org-trim (buffer-substring (match-beginning 2) (match-end 0)))
  5160. inherited-tags
  5161. (or (eq org-agenda-show-inherited-tags 'always)
  5162. (and (listp org-agenda-show-inherited-tags)
  5163. (memq 'todo org-agenda-show-inherited-tags))
  5164. (and (eq org-agenda-show-inherited-tags t)
  5165. (or (eq org-agenda-use-tag-inheritance t)
  5166. (memq 'todo org-agenda-use-tag-inheritance))))
  5167. tags (org-get-tags nil (not inherited-tags))
  5168. level (make-string (org-reduced-level (org-outline-level)) ? )
  5169. txt (org-agenda-format-item ""
  5170. (org-add-props txt nil
  5171. 'effort effort
  5172. 'effort-minutes effort-minutes)
  5173. level category tags t)
  5174. priority (1+ (org-get-priority txt)))
  5175. (org-add-props txt props
  5176. 'org-marker marker 'org-hd-marker marker
  5177. 'priority priority
  5178. 'effort effort 'effort-minutes effort-minutes
  5179. 'level level
  5180. 'ts-date ts-date
  5181. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  5182. (push txt ee)
  5183. (if org-agenda-todo-list-sublevels
  5184. (goto-char todo-state-end-pos)
  5185. (org-end-of-subtree 'invisible))))
  5186. (nreverse ee)))
  5187. (defun org-agenda-todo-custom-ignore-p (time n)
  5188. "Check whether timestamp is farther away than n number of days.
  5189. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5190. `org-agenda-todo-ignore-scheduled' or
  5191. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5192. (let ((days (org-time-stamp-to-now
  5193. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5194. (if (>= n 0)
  5195. (>= days n)
  5196. (<= days n))))
  5197. ;;;###autoload
  5198. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5199. (&optional end)
  5200. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5201. (when (or org-agenda-todo-ignore-with-date
  5202. org-agenda-todo-ignore-scheduled
  5203. org-agenda-todo-ignore-deadlines
  5204. org-agenda-todo-ignore-timestamp)
  5205. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5206. (save-excursion
  5207. (or (and org-agenda-todo-ignore-with-date
  5208. (re-search-forward org-ts-regexp end t))
  5209. (and org-agenda-todo-ignore-scheduled
  5210. (re-search-forward org-scheduled-time-regexp end t)
  5211. (cond
  5212. ((eq org-agenda-todo-ignore-scheduled 'future)
  5213. (> (org-time-stamp-to-now
  5214. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5215. 0))
  5216. ((eq org-agenda-todo-ignore-scheduled 'past)
  5217. (<= (org-time-stamp-to-now
  5218. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5219. 0))
  5220. ((numberp org-agenda-todo-ignore-scheduled)
  5221. (org-agenda-todo-custom-ignore-p
  5222. (match-string 1) org-agenda-todo-ignore-scheduled))
  5223. (t)))
  5224. (and org-agenda-todo-ignore-deadlines
  5225. (re-search-forward org-deadline-time-regexp end t)
  5226. (cond
  5227. ((eq org-agenda-todo-ignore-deadlines 'all) t)
  5228. ((eq org-agenda-todo-ignore-deadlines 'far)
  5229. (not (org-deadline-close-p (match-string 1))))
  5230. ((eq org-agenda-todo-ignore-deadlines 'future)
  5231. (> (org-time-stamp-to-now
  5232. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5233. 0))
  5234. ((eq org-agenda-todo-ignore-deadlines 'past)
  5235. (<= (org-time-stamp-to-now
  5236. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5237. 0))
  5238. ((numberp org-agenda-todo-ignore-deadlines)
  5239. (org-agenda-todo-custom-ignore-p
  5240. (match-string 1) org-agenda-todo-ignore-deadlines))
  5241. (t (org-deadline-close-p (match-string 1)))))
  5242. (and org-agenda-todo-ignore-timestamp
  5243. (let ((buffer (current-buffer))
  5244. (regexp
  5245. (concat
  5246. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5247. (start (point)))
  5248. ;; Copy current buffer into a temporary one
  5249. (with-temp-buffer
  5250. (insert-buffer-substring buffer start end)
  5251. (goto-char (point-min))
  5252. ;; Delete SCHEDULED and DEADLINE items
  5253. (while (re-search-forward regexp end t)
  5254. (delete-region (match-beginning 0) (match-end 0)))
  5255. (goto-char (point-min))
  5256. ;; No search for timestamp left
  5257. (when (re-search-forward org-ts-regexp nil t)
  5258. (cond
  5259. ((eq org-agenda-todo-ignore-timestamp 'future)
  5260. (> (org-time-stamp-to-now
  5261. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5262. 0))
  5263. ((eq org-agenda-todo-ignore-timestamp 'past)
  5264. (<= (org-time-stamp-to-now
  5265. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds)
  5266. 0))
  5267. ((numberp org-agenda-todo-ignore-timestamp)
  5268. (org-agenda-todo-custom-ignore-p
  5269. (match-string 1) org-agenda-todo-ignore-timestamp))
  5270. (t))))))))))
  5271. (defun org-agenda-get-timestamps (&optional deadlines)
  5272. "Return the date stamp information for agenda display.
  5273. Optional argument DEADLINES is a list of deadline items to be
  5274. displayed in agenda view."
  5275. (with-no-warnings (defvar date))
  5276. (let* ((props (list 'face 'org-agenda-calendar-event
  5277. 'org-not-done-regexp org-not-done-regexp
  5278. 'org-todo-regexp org-todo-regexp
  5279. 'org-complex-heading-regexp org-complex-heading-regexp
  5280. 'mouse-face 'highlight
  5281. 'help-echo
  5282. (format "mouse-2 or RET jump to Org file %s"
  5283. (abbreviate-file-name buffer-file-name))))
  5284. (current (calendar-absolute-from-gregorian date))
  5285. (today (org-today))
  5286. (deadline-position-alist
  5287. (mapcar (lambda (d)
  5288. (let ((m (get-text-property 0 'org-hd-marker d)))
  5289. (and m (marker-position m))))
  5290. deadlines))
  5291. ;; Match time-stamps set to current date, time-stamps with
  5292. ;; a repeater, and S-exp time-stamps.
  5293. (regexp
  5294. (concat
  5295. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5296. (regexp-quote
  5297. (substring
  5298. (format-time-string
  5299. (car org-time-stamp-formats)
  5300. (encode-time ; DATE bound by calendar
  5301. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5302. 1 11))
  5303. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5304. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5305. timestamp-items)
  5306. (goto-char (point-min))
  5307. (while (re-search-forward regexp nil t)
  5308. ;; Skip date ranges, scheduled and deadlines, which are handled
  5309. ;; specially. Also skip time-stamps before first headline as
  5310. ;; there would be no entry to add to the agenda. Eventually,
  5311. ;; ignore clock entries.
  5312. (catch :skip
  5313. (save-match-data
  5314. (when (or (org-at-date-range-p)
  5315. (org-at-planning-p)
  5316. (org-before-first-heading-p)
  5317. (and org-agenda-include-inactive-timestamps
  5318. (org-at-clock-log-p))
  5319. (not (org-at-timestamp-p 'agenda)))
  5320. (throw :skip nil))
  5321. (org-agenda-skip))
  5322. (let* ((pos (match-beginning 0))
  5323. (repeat (match-string 1))
  5324. (sexp-entry (match-string 3))
  5325. (time-stamp (if (or repeat sexp-entry) (match-string 0)
  5326. (save-excursion
  5327. (goto-char pos)
  5328. (looking-at org-ts-regexp-both)
  5329. (match-string 0))))
  5330. (todo-state (org-get-todo-state))
  5331. (warntime (get-text-property (point) 'org-appt-warntime))
  5332. (done? (member todo-state org-done-keywords)))
  5333. ;; Possibly skip done tasks.
  5334. (when (and done? org-agenda-skip-timestamp-if-done)
  5335. (throw :skip t))
  5336. ;; S-exp entry doesn't match current day: skip it.
  5337. (when (and sexp-entry (not (org-diary-sexp-entry sexp-entry "" date)))
  5338. (throw :skip nil))
  5339. (when repeat
  5340. (let* ((past
  5341. ;; A repeating time stamp is shown at its base
  5342. ;; date and every repeated date up to TODAY. If
  5343. ;; `org-agenda-prefer-last-repeat' is non-nil,
  5344. ;; however, only the last repeat before today
  5345. ;; (inclusive) is shown.
  5346. (org-agenda--timestamp-to-absolute
  5347. repeat
  5348. (if (or (> current today)
  5349. (eq org-agenda-prefer-last-repeat t)
  5350. (member todo-state org-agenda-prefer-last-repeat))
  5351. today
  5352. current)
  5353. 'past (current-buffer) pos))
  5354. (future
  5355. ;; Display every repeated date past TODAY
  5356. ;; (exclusive) unless
  5357. ;; `org-agenda-show-future-repeats' is nil. If
  5358. ;; this variable is set to `next', only display
  5359. ;; the first repeated date after TODAY
  5360. ;; (exclusive).
  5361. (cond
  5362. ((<= current today) past)
  5363. ((not org-agenda-show-future-repeats) past)
  5364. (t
  5365. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5366. (1+ today)
  5367. current)))
  5368. (org-agenda--timestamp-to-absolute
  5369. repeat base 'future (current-buffer) pos))))))
  5370. (when (and (/= current past) (/= current future))
  5371. (throw :skip nil))))
  5372. (save-excursion
  5373. (re-search-backward org-outline-regexp-bol nil t)
  5374. ;; Possibly skip time-stamp when a deadline is set.
  5375. (when (and org-agenda-skip-timestamp-if-deadline-is-shown
  5376. (assq (point) deadline-position-alist))
  5377. (throw :skip nil))
  5378. (let* ((category (org-get-category pos))
  5379. (effort (org-entry-get pos org-effort-property))
  5380. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5381. (inherited-tags
  5382. (or (eq org-agenda-show-inherited-tags 'always)
  5383. (and (consp org-agenda-show-inherited-tags)
  5384. (memq 'agenda org-agenda-show-inherited-tags))
  5385. (and (eq org-agenda-show-inherited-tags t)
  5386. (or (eq org-agenda-use-tag-inheritance t)
  5387. (memq 'agenda
  5388. org-agenda-use-tag-inheritance)))))
  5389. (tags (org-get-tags nil (not inherited-tags)))
  5390. (level (make-string (org-reduced-level (org-outline-level))
  5391. ?\s))
  5392. (head (and (looking-at "\\*+[ \t]+\\(.*\\)")
  5393. (match-string 1)))
  5394. (inactive? (= (char-after pos) ?\[))
  5395. (habit? (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  5396. (item
  5397. (org-agenda-format-item
  5398. (and inactive? org-agenda-inactive-leader)
  5399. (org-add-props head nil
  5400. 'effort effort
  5401. 'effort-minutes effort-minutes)
  5402. level category tags time-stamp org-ts-regexp habit?)))
  5403. (org-add-props item props
  5404. 'priority (if habit?
  5405. (org-habit-get-priority (org-habit-parse-todo))
  5406. (org-get-priority item))
  5407. 'org-marker (org-agenda-new-marker pos)
  5408. 'org-hd-marker (org-agenda-new-marker)
  5409. 'date date
  5410. 'level level
  5411. 'effort effort 'effort-minutes effort-minutes
  5412. 'ts-date (if repeat (org-agenda--timestamp-to-absolute repeat)
  5413. current)
  5414. 'todo-state todo-state
  5415. 'warntime warntime
  5416. 'type "timestamp")
  5417. (push item timestamp-items))))
  5418. (when org-agenda-skip-additional-timestamps-same-entry
  5419. (outline-next-heading))))
  5420. (nreverse timestamp-items)))
  5421. (defun org-agenda-get-sexps ()
  5422. "Return the sexp information for agenda display."
  5423. (require 'diary-lib)
  5424. (with-no-warnings (defvar date) (defvar entry))
  5425. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5426. 'mouse-face 'highlight
  5427. 'help-echo
  5428. (format "mouse-2 or RET jump to org file %s"
  5429. (abbreviate-file-name buffer-file-name))))
  5430. (regexp "^&?%%(")
  5431. ;; FIXME: Is this `entry' binding intended to be dynamic,
  5432. ;; so as to "hide" any current binding for it?
  5433. marker category extra level ee txt tags entry
  5434. result beg b sexp sexp-entry todo-state warntime inherited-tags
  5435. effort effort-minutes)
  5436. (goto-char (point-min))
  5437. (while (re-search-forward regexp nil t)
  5438. (catch :skip
  5439. (org-agenda-skip)
  5440. (setq beg (match-beginning 0))
  5441. (goto-char (1- (match-end 0)))
  5442. (setq b (point))
  5443. (forward-sexp 1)
  5444. (setq sexp (buffer-substring b (point)))
  5445. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5446. (org-trim (match-string 1))
  5447. ""))
  5448. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5449. (when result
  5450. (setq marker (org-agenda-new-marker beg)
  5451. level (make-string (org-reduced-level (org-outline-level)) ? )
  5452. category (org-get-category beg)
  5453. effort (save-match-data (or (get-text-property (point) 'effort)
  5454. (org-entry-get (point) org-effort-property)))
  5455. inherited-tags
  5456. (or (eq org-agenda-show-inherited-tags 'always)
  5457. (and (listp org-agenda-show-inherited-tags)
  5458. (memq 'agenda org-agenda-show-inherited-tags))
  5459. (and (eq org-agenda-show-inherited-tags t)
  5460. (or (eq org-agenda-use-tag-inheritance t)
  5461. (memq 'agenda org-agenda-use-tag-inheritance))))
  5462. tags (org-get-tags nil (not inherited-tags))
  5463. todo-state (org-get-todo-state)
  5464. warntime (get-text-property (point) 'org-appt-warntime)
  5465. extra nil)
  5466. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5467. (dolist (r (if (stringp result)
  5468. (list result)
  5469. result)) ;; we expect a list here
  5470. (when (and org-agenda-diary-sexp-prefix
  5471. (string-match org-agenda-diary-sexp-prefix r))
  5472. (setq extra (match-string 0 r)
  5473. r (replace-match "" nil nil r)))
  5474. (if (string-match "\\S-" r)
  5475. (setq txt r)
  5476. (setq txt "SEXP entry returned empty string"))
  5477. (setq txt (org-agenda-format-item extra
  5478. (org-add-props txt nil
  5479. 'effort effort
  5480. 'effort-minutes effort-minutes)
  5481. level category tags 'time))
  5482. (org-add-props txt props 'org-marker marker
  5483. 'date date 'todo-state todo-state
  5484. 'effort effort 'effort-minutes effort-minutes
  5485. 'level level 'type "sexp" 'warntime warntime)
  5486. (push txt ee)))))
  5487. (nreverse ee)))
  5488. ;; Calendar sanity: define some functions that are independent of
  5489. ;; `calendar-date-style'.
  5490. (defun org-anniversary (year month day &optional mark)
  5491. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5492. (with-no-warnings
  5493. (let ((calendar-date-style 'iso))
  5494. (diary-anniversary year month day mark))))
  5495. (defun org-cyclic (N year month day &optional mark)
  5496. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5497. (with-no-warnings
  5498. (let ((calendar-date-style 'iso))
  5499. (diary-cyclic N year month day mark))))
  5500. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5501. "Like `diary-block', but with fixed (ISO) order of arguments."
  5502. (with-no-warnings
  5503. (let ((calendar-date-style 'iso))
  5504. (diary-block Y1 M1 D1 Y2 M2 D2 mark))))
  5505. (defun org-date (year month day &optional mark)
  5506. "Like `diary-date', but with fixed (ISO) order of arguments."
  5507. (with-no-warnings
  5508. (let ((calendar-date-style 'iso))
  5509. (diary-date year month day mark))))
  5510. ;; Define the `org-class' function
  5511. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5512. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5513. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5514. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5515. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5516. `holidays', then any date that is known by the Emacs calendar to be a
  5517. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5518. then those holidays will be skipped."
  5519. (with-no-warnings (defvar date) (defvar entry))
  5520. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5521. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5522. (d (calendar-absolute-from-gregorian date))
  5523. (h (when skip-weeks (calendar-check-holidays date))))
  5524. (and
  5525. (<= date1 d)
  5526. (<= d date2)
  5527. (= (calendar-day-of-week date) dayname)
  5528. (or (not skip-weeks)
  5529. (progn
  5530. (require 'cal-iso)
  5531. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5532. (not (or (and h (memq 'holidays skip-weeks))
  5533. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5534. entry)))
  5535. (defalias 'org-get-closed #'org-agenda-get-progress)
  5536. (defun org-agenda-get-progress ()
  5537. "Return the logged TODO entries for agenda display."
  5538. (with-no-warnings (defvar date))
  5539. (let* ((props (list 'mouse-face 'highlight
  5540. 'org-not-done-regexp org-not-done-regexp
  5541. 'org-todo-regexp org-todo-regexp
  5542. 'org-complex-heading-regexp org-complex-heading-regexp
  5543. 'help-echo
  5544. (format "mouse-2 or RET jump to org file %s"
  5545. (abbreviate-file-name buffer-file-name))))
  5546. (items (if (consp org-agenda-show-log-scoped)
  5547. org-agenda-show-log-scoped
  5548. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5549. '(clock)
  5550. org-agenda-log-mode-items)))
  5551. (parts
  5552. (delq nil
  5553. (list
  5554. (when (memq 'closed items) (concat "\\<" org-closed-string))
  5555. (when (memq 'clock items) (concat "\\<" org-clock-string))
  5556. (when (memq 'state items)
  5557. (format "- +State \"%s\".*?" org-todo-regexp)))))
  5558. (parts-re (if parts (mapconcat #'identity parts "\\|")
  5559. (error "`org-agenda-log-mode-items' is empty")))
  5560. (regexp (concat
  5561. "\\(" parts-re "\\)"
  5562. " *\\["
  5563. (regexp-quote
  5564. (substring
  5565. (format-time-string
  5566. (car org-time-stamp-formats)
  5567. (encode-time ; DATE bound by calendar
  5568. 0 0 0 (nth 1 date) (car date) (nth 2 date)))
  5569. 1 11))))
  5570. (org-agenda-search-headline-for-time nil)
  5571. marker hdmarker priority category level tags closedp type
  5572. statep clockp state ee txt extra timestr rest clocked inherited-tags
  5573. effort effort-minutes)
  5574. (goto-char (point-min))
  5575. (while (re-search-forward regexp nil t)
  5576. (catch :skip
  5577. (org-agenda-skip)
  5578. (setq marker (org-agenda-new-marker (match-beginning 0))
  5579. closedp (equal (match-string 1) org-closed-string)
  5580. statep (equal (string-to-char (match-string 1)) ?-)
  5581. clockp (not (or closedp statep))
  5582. state (and statep (match-string 2))
  5583. category (org-get-category (match-beginning 0))
  5584. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  5585. effort (save-match-data (or (get-text-property (point) 'effort)
  5586. (org-entry-get (point) org-effort-property))))
  5587. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5588. (when (string-match "\\]" timestr)
  5589. ;; substring should only run to end of time stamp
  5590. (setq rest (substring timestr (match-end 0))
  5591. timestr (substring timestr 0 (match-end 0)))
  5592. (if (and (not closedp) (not statep)
  5593. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5594. rest))
  5595. (progn (setq timestr (concat (substring timestr 0 -1)
  5596. "-" (match-string 1 rest) "]"))
  5597. (setq clocked (match-string 2 rest)))
  5598. (setq clocked "-")))
  5599. (save-excursion
  5600. (setq extra
  5601. (cond
  5602. ((not org-agenda-log-mode-add-notes) nil)
  5603. (statep
  5604. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5605. (match-string 1)))
  5606. (clockp
  5607. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5608. (match-string 1)))))
  5609. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5610. (throw :skip nil)
  5611. (goto-char (match-beginning 0))
  5612. (setq hdmarker (org-agenda-new-marker)
  5613. inherited-tags
  5614. (or (eq org-agenda-show-inherited-tags 'always)
  5615. (and (listp org-agenda-show-inherited-tags)
  5616. (memq 'todo org-agenda-show-inherited-tags))
  5617. (and (eq org-agenda-show-inherited-tags t)
  5618. (or (eq org-agenda-use-tag-inheritance t)
  5619. (memq 'todo org-agenda-use-tag-inheritance))))
  5620. tags (org-get-tags nil (not inherited-tags))
  5621. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5622. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5623. (setq txt (match-string 1))
  5624. (when extra
  5625. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5626. (setq txt (concat (substring txt 0 (match-beginning 1))
  5627. " - " extra " " (match-string 2 txt)))
  5628. (setq txt (concat txt " - " extra))))
  5629. (setq txt (org-agenda-format-item
  5630. (cond
  5631. (closedp "Closed: ")
  5632. (statep (concat "State: (" state ")"))
  5633. (t (concat "Clocked: (" clocked ")")))
  5634. (org-add-props txt nil
  5635. 'effort effort
  5636. 'effort-minutes effort-minutes)
  5637. level category tags timestr)))
  5638. (setq type (cond (closedp "closed")
  5639. (statep "state")
  5640. (t "clock")))
  5641. (setq priority 100000)
  5642. (org-add-props txt props
  5643. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5644. 'priority priority 'level level
  5645. 'effort effort 'effort-minutes effort-minutes
  5646. 'type type 'date date
  5647. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5648. (push txt ee))
  5649. (goto-char (point-at-eol))))
  5650. (nreverse ee)))
  5651. (defun org-agenda-show-clocking-issues ()
  5652. "Add overlays, showing issues with clocking.
  5653. See also the user option `org-agenda-clock-consistency-checks'."
  5654. (interactive)
  5655. (let* ((pl org-agenda-clock-consistency-checks)
  5656. (re (concat "^[ \t]*"
  5657. org-clock-string
  5658. "[ \t]+"
  5659. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5660. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5661. (tlstart 0.)
  5662. (tlend 0.)
  5663. (maxtime (org-duration-to-minutes
  5664. (or (plist-get pl :max-duration) "24:00")))
  5665. (mintime (org-duration-to-minutes
  5666. (or (plist-get pl :min-duration) 0)))
  5667. (maxgap (org-duration-to-minutes
  5668. ;; default 30:00 means never complain
  5669. (or (plist-get pl :max-gap) "30:00")))
  5670. (gapok (mapcar #'org-duration-to-minutes
  5671. (plist-get pl :gap-ok-around)))
  5672. (def-face (or (plist-get pl :default-face)
  5673. '((:background "DarkRed") (:foreground "white"))))
  5674. issue face m te ts dt ov)
  5675. (goto-char (point-min))
  5676. (while (re-search-forward " Clocked: +(\\(?:-\\|\\([0-9]+:[0-9]+\\)\\))" nil t)
  5677. (setq issue nil face def-face)
  5678. (catch 'next
  5679. (setq m (org-get-at-bol 'org-marker)
  5680. te nil ts nil)
  5681. (unless (and m (markerp m))
  5682. (setq issue "No valid clock line") (throw 'next t))
  5683. (org-with-point-at m
  5684. (save-excursion
  5685. (goto-char (point-at-bol))
  5686. (unless (looking-at re)
  5687. (error "No valid Clock line")
  5688. (throw 'next t))
  5689. (unless (match-end 3)
  5690. (setq issue
  5691. (format
  5692. "No end time: (%s)"
  5693. (org-duration-from-minutes
  5694. (floor
  5695. (- (float-time (org-current-time))
  5696. (float-time (org-time-string-to-time (match-string 1))))
  5697. 60)))
  5698. face (or (plist-get pl :no-end-time-face) face))
  5699. (throw 'next t))
  5700. (setq ts (match-string 1)
  5701. te (match-string 3)
  5702. ts (float-time (org-time-string-to-time ts))
  5703. te (float-time (org-time-string-to-time te))
  5704. dt (- te ts))))
  5705. (cond
  5706. ((> dt (* 60 maxtime))
  5707. ;; a very long clocking chunk
  5708. (setq issue (format "Clocking interval is very long: %s"
  5709. (org-duration-from-minutes (floor dt 60)))
  5710. face (or (plist-get pl :long-face) face)))
  5711. ((< dt (* 60 mintime))
  5712. ;; a very short clocking chunk
  5713. (setq issue (format "Clocking interval is very short: %s"
  5714. (org-duration-from-minutes (floor dt 60)))
  5715. face (or (plist-get pl :short-face) face)))
  5716. ((and (> tlend 0) (< ts tlend))
  5717. ;; Two clock entries are overlapping
  5718. (setq issue (format "Clocking overlap: %d minutes"
  5719. (/ (- tlend ts) 60))
  5720. face (or (plist-get pl :overlap-face) face)))
  5721. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5722. ;; There is a gap, lets see if we need to report it
  5723. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5724. (setq issue (format "Clocking gap: %d minutes"
  5725. (/ (- ts tlend) 60))
  5726. face (or (plist-get pl :gap-face) face))))
  5727. (t nil)))
  5728. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5729. (when issue
  5730. ;; OK, there was some issue, add an overlay to show the issue
  5731. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5732. (overlay-put ov 'before-string
  5733. (concat
  5734. (org-add-props
  5735. (format "%-43s" (concat " " issue))
  5736. nil
  5737. 'face face)
  5738. "\n"))
  5739. (overlay-put ov 'evaporate t)))))
  5740. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5741. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5742. (catch 'exit
  5743. (unless ok-list
  5744. ;; there are no OK times for gaps...
  5745. (throw 'exit nil))
  5746. (when (> (- (/ t2 36000) (/ t1 36000)) 24)
  5747. ;; This is more than 24 hours, so it is OK.
  5748. ;; because we have at least one OK time, that must be in the
  5749. ;; 24 hour interval.
  5750. (throw 'exit t))
  5751. ;; We have a shorter gap.
  5752. ;; Now we have to get the minute of the day when these times are
  5753. (let* ((t1dec (decode-time t1))
  5754. (t2dec (decode-time t2))
  5755. ;; compute the minute on the day
  5756. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5757. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5758. (when (< min2 min1)
  5759. ;; if min2 is smaller than min1, this means it is on the next day.
  5760. ;; Wrap it to after midnight.
  5761. (setq min2 (+ min2 1440)))
  5762. ;; Now check if any of the OK times is in the gap
  5763. (mapc (lambda (x)
  5764. ;; Wrap the time to after midnight if necessary
  5765. (when (< x min1) (setq x (+ x 1440)))
  5766. ;; Check if in interval
  5767. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5768. ok-list)
  5769. ;; Nope, this gap is not OK
  5770. nil)))
  5771. (defun org-agenda-get-deadlines (&optional with-hour)
  5772. "Return the deadline information for agenda display.
  5773. When WITH-HOUR is non-nil, only return deadlines with an hour
  5774. specification like [h]h:mm."
  5775. (with-no-warnings (defvar date))
  5776. (let* ((props (list 'mouse-face 'highlight
  5777. 'org-not-done-regexp org-not-done-regexp
  5778. 'org-todo-regexp org-todo-regexp
  5779. 'org-complex-heading-regexp org-complex-heading-regexp
  5780. 'help-echo
  5781. (format "mouse-2 or RET jump to org file %s"
  5782. (abbreviate-file-name buffer-file-name))))
  5783. (regexp (if with-hour
  5784. org-deadline-time-hour-regexp
  5785. org-deadline-time-regexp))
  5786. (today (org-today))
  5787. (today? (org-agenda-today-p date)) ; DATE bound by calendar.
  5788. (current (calendar-absolute-from-gregorian date))
  5789. deadline-items)
  5790. (goto-char (point-min))
  5791. (if (org-element--cache-active-p)
  5792. (org-element-cache-map
  5793. (lambda (el)
  5794. (when (and (org-element-property :deadline el)
  5795. (or (not with-hour)
  5796. (org-element-property
  5797. :hour-start
  5798. (org-element-property :deadline el))
  5799. (org-element-property
  5800. :hour-end
  5801. (org-element-property :deadline el))))
  5802. (goto-char (org-element-property :contents-begin el))
  5803. (catch :skip
  5804. (org-agenda-skip el)
  5805. (let* ((s (substring (org-element-property
  5806. :raw-value
  5807. (org-element-property :deadline el))
  5808. 1 -1))
  5809. (pos (save-excursion
  5810. (goto-char (org-element-property :contents-begin el))
  5811. ;; We intentionally leave NOERROR
  5812. ;; argument in `re-search-forward' nil. If
  5813. ;; the search fails here, something went
  5814. ;; wrong and we are looking at
  5815. ;; non-matching headline.
  5816. (re-search-forward regexp (line-end-position))
  5817. (1- (match-beginning 1))))
  5818. (todo-state (org-element-property :todo-keyword el))
  5819. (done? (eq 'done (org-element-property :todo-type el)))
  5820. (sexp? (eq 'diary
  5821. (org-element-property
  5822. :type (org-element-property :deadline el))))
  5823. ;; DEADLINE is the deadline date for the entry. It is
  5824. ;; either the base date or the last repeat, according
  5825. ;; to `org-agenda-prefer-last-repeat'.
  5826. (deadline
  5827. (cond
  5828. (sexp? (org-agenda--timestamp-to-absolute s current))
  5829. ((or (eq org-agenda-prefer-last-repeat t)
  5830. (member todo-state org-agenda-prefer-last-repeat))
  5831. (org-agenda--timestamp-to-absolute
  5832. s today 'past (current-buffer) pos))
  5833. (t (org-agenda--timestamp-to-absolute s))))
  5834. ;; REPEAT is the future repeat closest from CURRENT,
  5835. ;; according to `org-agenda-show-future-repeats'. If
  5836. ;; the latter is nil, or if the time stamp has no
  5837. ;; repeat part, default to DEADLINE.
  5838. (repeat
  5839. (cond
  5840. (sexp? deadline)
  5841. ((<= current today) deadline)
  5842. ((not org-agenda-show-future-repeats) deadline)
  5843. (t
  5844. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5845. (1+ today)
  5846. current)))
  5847. (org-agenda--timestamp-to-absolute
  5848. s base 'future (current-buffer) pos)))))
  5849. (diff (- deadline current))
  5850. (suppress-prewarning
  5851. (let ((scheduled
  5852. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5853. (org-element-property
  5854. :raw-value
  5855. (org-element-property :scheduled el)))))
  5856. (cond
  5857. ((not scheduled) nil)
  5858. ;; The current item has a scheduled date, so
  5859. ;; evaluate its prewarning lead time.
  5860. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5861. ;; Use global prewarning-restart lead time.
  5862. org-agenda-skip-deadline-prewarning-if-scheduled)
  5863. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5864. 'pre-scheduled)
  5865. ;; Set pre-warning to no earlier than SCHEDULED.
  5866. (min (- deadline
  5867. (org-agenda--timestamp-to-absolute scheduled))
  5868. org-deadline-warning-days))
  5869. ;; Set pre-warning to deadline.
  5870. (t 0))))
  5871. (wdays (or suppress-prewarning (org-get-wdays s))))
  5872. (cond
  5873. ;; Only display deadlines at their base date, at future
  5874. ;; repeat occurrences or in today agenda.
  5875. ((= current deadline) nil)
  5876. ((= current repeat) nil)
  5877. ((not today?) (throw :skip nil))
  5878. ;; Upcoming deadline: display within warning period WDAYS.
  5879. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  5880. ;; Overdue deadline: warn about it for
  5881. ;; `org-deadline-past-days' duration.
  5882. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  5883. ;; Possibly skip done tasks.
  5884. (when (and done?
  5885. (or org-agenda-skip-deadline-if-done
  5886. (/= deadline current)))
  5887. (throw :skip nil))
  5888. (save-excursion
  5889. (goto-char (org-element-property :begin el))
  5890. (let* ((category (org-get-category))
  5891. (effort (save-match-data (or (get-text-property (point) 'effort)
  5892. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  5893. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  5894. (level (make-string (org-element-property :level el)
  5895. ?\s))
  5896. (head (save-excursion
  5897. (goto-char (org-element-property :begin el))
  5898. (re-search-forward org-outline-regexp-bol)
  5899. (buffer-substring-no-properties (point) (line-end-position))))
  5900. (inherited-tags
  5901. (or (eq org-agenda-show-inherited-tags 'always)
  5902. (and (listp org-agenda-show-inherited-tags)
  5903. (memq 'agenda org-agenda-show-inherited-tags))
  5904. (and (eq org-agenda-show-inherited-tags t)
  5905. (or (eq org-agenda-use-tag-inheritance t)
  5906. (memq 'agenda
  5907. org-agenda-use-tag-inheritance)))))
  5908. (tags (org-get-tags el (not inherited-tags)))
  5909. (time
  5910. (cond
  5911. ;; No time of day designation if it is only
  5912. ;; a reminder.
  5913. ((and (/= current deadline) (/= current repeat)) nil)
  5914. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5915. (concat (substring s (match-beginning 1)) " "))
  5916. (t 'time)))
  5917. (item
  5918. (org-agenda-format-item
  5919. ;; Insert appropriate suffixes before deadlines.
  5920. ;; Those only apply to today agenda.
  5921. (pcase-let ((`(,now ,future ,past)
  5922. org-agenda-deadline-leaders))
  5923. (cond
  5924. ((and today? (< deadline today)) (format past (- diff)))
  5925. ((and today? (> deadline today)) (format future diff))
  5926. (t now)))
  5927. (org-add-props head nil
  5928. 'effort effort
  5929. 'effort-minutes effort-minutes)
  5930. level category tags time))
  5931. (face (org-agenda-deadline-face
  5932. (- 1 (/ (float diff) (max wdays 1)))))
  5933. (upcoming? (and today? (> deadline today)))
  5934. (warntime (get-text-property (point) 'org-appt-warntime)))
  5935. (org-add-props item props
  5936. 'org-marker (org-agenda-new-marker pos)
  5937. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  5938. 'warntime warntime
  5939. 'level level
  5940. 'effort effort 'effort-minutes effort-minutes
  5941. 'ts-date deadline
  5942. 'priority
  5943. ;; Adjust priority to today reminders about deadlines.
  5944. ;; Overdue deadlines get the highest priority
  5945. ;; increase, then imminent deadlines and eventually
  5946. ;; more distant deadlines.
  5947. (let ((adjust (if today? (- diff) 0)))
  5948. (+ adjust (org-get-priority item)))
  5949. 'todo-state todo-state
  5950. 'type (if upcoming? "upcoming-deadline" "deadline")
  5951. 'date (if upcoming? date deadline)
  5952. 'face (if done? 'org-agenda-done face)
  5953. 'undone-face face
  5954. 'done-face 'org-agenda-done)
  5955. (push item deadline-items)))))))
  5956. :next-re regexp
  5957. :fail-re regexp
  5958. :narrow t)
  5959. (while (re-search-forward regexp nil t)
  5960. (catch :skip
  5961. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  5962. (org-agenda-skip)
  5963. (let* ((s (match-string 1))
  5964. (pos (1- (match-beginning 1)))
  5965. (todo-state (save-match-data (org-get-todo-state)))
  5966. (done? (member todo-state org-done-keywords))
  5967. (sexp? (string-prefix-p "%%" s))
  5968. ;; DEADLINE is the deadline date for the entry. It is
  5969. ;; either the base date or the last repeat, according
  5970. ;; to `org-agenda-prefer-last-repeat'.
  5971. (deadline
  5972. (cond
  5973. (sexp? (org-agenda--timestamp-to-absolute s current))
  5974. ((or (eq org-agenda-prefer-last-repeat t)
  5975. (member todo-state org-agenda-prefer-last-repeat))
  5976. (org-agenda--timestamp-to-absolute
  5977. s today 'past (current-buffer) pos))
  5978. (t (org-agenda--timestamp-to-absolute s))))
  5979. ;; REPEAT is the future repeat closest from CURRENT,
  5980. ;; according to `org-agenda-show-future-repeats'. If
  5981. ;; the latter is nil, or if the time stamp has no
  5982. ;; repeat part, default to DEADLINE.
  5983. (repeat
  5984. (cond
  5985. (sexp? deadline)
  5986. ((<= current today) deadline)
  5987. ((not org-agenda-show-future-repeats) deadline)
  5988. (t
  5989. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  5990. (1+ today)
  5991. current)))
  5992. (org-agenda--timestamp-to-absolute
  5993. s base 'future (current-buffer) pos)))))
  5994. (diff (- deadline current))
  5995. (suppress-prewarning
  5996. (let ((scheduled
  5997. (and org-agenda-skip-deadline-prewarning-if-scheduled
  5998. (org-entry-get nil "SCHEDULED"))))
  5999. (cond
  6000. ((not scheduled) nil)
  6001. ;; The current item has a scheduled date, so
  6002. ;; evaluate its prewarning lead time.
  6003. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  6004. ;; Use global prewarning-restart lead time.
  6005. org-agenda-skip-deadline-prewarning-if-scheduled)
  6006. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  6007. 'pre-scheduled)
  6008. ;; Set pre-warning to no earlier than SCHEDULED.
  6009. (min (- deadline
  6010. (org-agenda--timestamp-to-absolute scheduled))
  6011. org-deadline-warning-days))
  6012. ;; Set pre-warning to deadline.
  6013. (t 0))))
  6014. (wdays (or suppress-prewarning (org-get-wdays s))))
  6015. (cond
  6016. ;; Only display deadlines at their base date, at future
  6017. ;; repeat occurrences or in today agenda.
  6018. ((= current deadline) nil)
  6019. ((= current repeat) nil)
  6020. ((not today?) (throw :skip nil))
  6021. ;; Upcoming deadline: display within warning period WDAYS.
  6022. ((> deadline current) (when (> diff wdays) (throw :skip nil)))
  6023. ;; Overdue deadline: warn about it for
  6024. ;; `org-deadline-past-days' duration.
  6025. (t (when (< org-deadline-past-days (- diff)) (throw :skip nil))))
  6026. ;; Possibly skip done tasks.
  6027. (when (and done?
  6028. (or org-agenda-skip-deadline-if-done
  6029. (/= deadline current)))
  6030. (throw :skip nil))
  6031. (save-excursion
  6032. (re-search-backward "^\\*+[ \t]+" nil t)
  6033. (goto-char (match-end 0))
  6034. (let* ((category (org-get-category))
  6035. (effort (save-match-data (or (get-text-property (point) 'effort)
  6036. (org-entry-get (point) org-effort-property))))
  6037. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6038. (level (make-string (org-reduced-level (org-outline-level))
  6039. ?\s))
  6040. (head (buffer-substring-no-properties
  6041. (point) (line-end-position)))
  6042. (inherited-tags
  6043. (or (eq org-agenda-show-inherited-tags 'always)
  6044. (and (listp org-agenda-show-inherited-tags)
  6045. (memq 'agenda org-agenda-show-inherited-tags))
  6046. (and (eq org-agenda-show-inherited-tags t)
  6047. (or (eq org-agenda-use-tag-inheritance t)
  6048. (memq 'agenda
  6049. org-agenda-use-tag-inheritance)))))
  6050. (tags (org-get-tags nil (not inherited-tags)))
  6051. (time
  6052. (cond
  6053. ;; No time of day designation if it is only
  6054. ;; a reminder.
  6055. ((and (/= current deadline) (/= current repeat)) nil)
  6056. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6057. (concat (substring s (match-beginning 1)) " "))
  6058. (t 'time)))
  6059. (item
  6060. (org-agenda-format-item
  6061. ;; Insert appropriate suffixes before deadlines.
  6062. ;; Those only apply to today agenda.
  6063. (pcase-let ((`(,now ,future ,past)
  6064. org-agenda-deadline-leaders))
  6065. (cond
  6066. ((and today? (< deadline today)) (format past (- diff)))
  6067. ((and today? (> deadline today)) (format future diff))
  6068. (t now)))
  6069. (org-add-props head nil
  6070. 'effort effort
  6071. 'effort-minutes effort-minutes)
  6072. level category tags time))
  6073. (face (org-agenda-deadline-face
  6074. (- 1 (/ (float diff) (max wdays 1)))))
  6075. (upcoming? (and today? (> deadline today)))
  6076. (warntime (get-text-property (point) 'org-appt-warntime)))
  6077. (org-add-props item props
  6078. 'org-marker (org-agenda-new-marker pos)
  6079. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6080. 'warntime warntime
  6081. 'level level
  6082. 'effort effort 'effort-minutes effort-minutes
  6083. 'ts-date deadline
  6084. 'priority
  6085. ;; Adjust priority to today reminders about deadlines.
  6086. ;; Overdue deadlines get the highest priority
  6087. ;; increase, then imminent deadlines and eventually
  6088. ;; more distant deadlines.
  6089. (let ((adjust (if today? (- diff) 0)))
  6090. (+ adjust (org-get-priority item)))
  6091. 'todo-state todo-state
  6092. 'type (if upcoming? "upcoming-deadline" "deadline")
  6093. 'date (if upcoming? date deadline)
  6094. 'face (if done? 'org-agenda-done face)
  6095. 'undone-face face
  6096. 'done-face 'org-agenda-done)
  6097. (push item deadline-items)))))))
  6098. (nreverse deadline-items)))
  6099. (defun org-agenda-deadline-face (fraction)
  6100. "Return the face to displaying a deadline item.
  6101. FRACTION is what fraction of the head-warning time has passed."
  6102. (assoc-default fraction org-agenda-deadline-faces #'<=))
  6103. (defun org-agenda-get-scheduled (&optional deadlines with-hour)
  6104. "Return the scheduled information for agenda display.
  6105. Optional argument DEADLINES is a list of deadline items to be
  6106. displayed in agenda view. When WITH-HOUR is non-nil, only return
  6107. scheduled items with an hour specification like [h]h:mm."
  6108. (with-no-warnings (defvar date))
  6109. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  6110. 'org-todo-regexp org-todo-regexp
  6111. 'org-complex-heading-regexp org-complex-heading-regexp
  6112. 'done-face 'org-agenda-done
  6113. 'mouse-face 'highlight
  6114. 'help-echo
  6115. (format "mouse-2 or RET jump to Org file %s"
  6116. (abbreviate-file-name buffer-file-name))))
  6117. (regexp (if with-hour
  6118. org-scheduled-time-hour-regexp
  6119. org-scheduled-time-regexp))
  6120. (today (org-today))
  6121. (todayp (org-agenda-today-p date)) ; DATE bound by calendar.
  6122. (current (calendar-absolute-from-gregorian date))
  6123. (deadline-pos
  6124. (mapcar (lambda (d)
  6125. (let ((m (get-text-property 0 'org-hd-marker d)))
  6126. (and m (marker-position m))))
  6127. deadlines))
  6128. scheduled-items)
  6129. (goto-char (point-min))
  6130. (if (org-element--cache-active-p)
  6131. (org-element-cache-map
  6132. (lambda (el)
  6133. (when (and (org-element-property :scheduled el)
  6134. (or (not with-hour)
  6135. (org-element-property
  6136. :hour-start
  6137. (org-element-property :scheduled el))
  6138. (org-element-property
  6139. :hour-end
  6140. (org-element-property :scheduled el))))
  6141. (goto-char (org-element-property :contents-begin el))
  6142. (catch :skip
  6143. (org-agenda-skip el)
  6144. (let* ((s (substring (org-element-property
  6145. :raw-value
  6146. (org-element-property :scheduled el))
  6147. 1 -1))
  6148. (pos (save-excursion
  6149. (goto-char (org-element-property :contents-begin el))
  6150. ;; We intentionally leave NOERROR
  6151. ;; argument in `re-search-forward' nil. If
  6152. ;; the search fails here, something went
  6153. ;; wrong and we are looking at
  6154. ;; non-matching headline.
  6155. (re-search-forward regexp (line-end-position))
  6156. (1- (match-beginning 1))))
  6157. (todo-state (org-element-property :todo-keyword el))
  6158. (donep (eq 'done (org-element-property :todo-type el)))
  6159. (sexp? (eq 'diary
  6160. (org-element-property
  6161. :type (org-element-property :scheduled el))))
  6162. ;; SCHEDULE is the scheduled date for the entry. It is
  6163. ;; either the bare date or the last repeat, according
  6164. ;; to `org-agenda-prefer-last-repeat'.
  6165. (schedule
  6166. (cond
  6167. (sexp? (org-agenda--timestamp-to-absolute s current))
  6168. ((or (eq org-agenda-prefer-last-repeat t)
  6169. (member todo-state org-agenda-prefer-last-repeat))
  6170. (org-agenda--timestamp-to-absolute
  6171. s today 'past (current-buffer) pos))
  6172. (t (org-agenda--timestamp-to-absolute s))))
  6173. ;; REPEAT is the future repeat closest from CURRENT,
  6174. ;; according to `org-agenda-show-future-repeats'. If
  6175. ;; the latter is nil, or if the time stamp has no
  6176. ;; repeat part, default to SCHEDULE.
  6177. (repeat
  6178. (cond
  6179. (sexp? schedule)
  6180. ((<= current today) schedule)
  6181. ((not org-agenda-show-future-repeats) schedule)
  6182. (t
  6183. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6184. (1+ today)
  6185. current)))
  6186. (org-agenda--timestamp-to-absolute
  6187. s base 'future (current-buffer) pos)))))
  6188. (diff (- current schedule))
  6189. (warntime (get-text-property (point) 'org-appt-warntime))
  6190. (pastschedp (< schedule today))
  6191. (futureschedp (> schedule today))
  6192. (habitp (and (fboundp 'org-is-habit-p)
  6193. (string= "habit" (org-element-property :STYLE el))))
  6194. (suppress-delay
  6195. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6196. (org-element-property
  6197. :raw-value
  6198. (org-element-property :deadline el)))))
  6199. (cond
  6200. ((not deadline) nil)
  6201. ;; The current item has a deadline date, so
  6202. ;; evaluate its delay time.
  6203. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6204. ;; Use global delay time.
  6205. (- org-agenda-skip-scheduled-delay-if-deadline))
  6206. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6207. 'post-deadline)
  6208. ;; Set delay to no later than DEADLINE.
  6209. (min (- schedule
  6210. (org-agenda--timestamp-to-absolute deadline))
  6211. org-scheduled-delay-days))
  6212. (t 0))))
  6213. (ddays
  6214. (cond
  6215. ;; Nullify delay when a repeater triggered already
  6216. ;; and the delay is of the form --Xd.
  6217. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6218. (> schedule (org-agenda--timestamp-to-absolute s)))
  6219. 0)
  6220. (suppress-delay
  6221. (let ((org-scheduled-delay-days suppress-delay))
  6222. (org-get-wdays s t t)))
  6223. (t (org-get-wdays s t)))))
  6224. ;; Display scheduled items at base date (SCHEDULE), today if
  6225. ;; scheduled before the current date, and at any repeat past
  6226. ;; today. However, skip delayed items and items that have
  6227. ;; been displayed for more than `org-scheduled-past-days'.
  6228. (unless (and todayp
  6229. habitp
  6230. (bound-and-true-p org-habit-show-all-today))
  6231. (when (or (and (> ddays 0) (< diff ddays))
  6232. (> diff (or (and habitp org-habit-scheduled-past-days)
  6233. org-scheduled-past-days))
  6234. (> schedule current)
  6235. (and (/= current schedule)
  6236. (/= current today)
  6237. (/= current repeat)))
  6238. (throw :skip nil)))
  6239. ;; Possibly skip done tasks.
  6240. (when (and donep
  6241. (or org-agenda-skip-scheduled-if-done
  6242. (/= schedule current)))
  6243. (throw :skip nil))
  6244. ;; Skip entry if it already appears as a deadline, per
  6245. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6246. ;; doesn't apply to habits.
  6247. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6248. ((guard
  6249. (or (not (memq (line-beginning-position 0) deadline-pos))
  6250. habitp))
  6251. nil)
  6252. (`repeated-after-deadline
  6253. (let ((deadline (time-to-days
  6254. (when (org-element-property :deadline el)
  6255. (org-time-string-to-time
  6256. (org-element-property :deadline el))))))
  6257. (and (<= schedule deadline) (> current deadline))))
  6258. (`not-today pastschedp)
  6259. (`t t)
  6260. (_ nil))
  6261. (throw :skip nil))
  6262. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6263. ;; only show them for today. Also skip done habits.
  6264. (when (and habitp
  6265. (or donep
  6266. (not (bound-and-true-p org-habit-show-habits))
  6267. (and (not todayp)
  6268. (bound-and-true-p
  6269. org-habit-show-habits-only-for-today))))
  6270. (throw :skip nil))
  6271. (save-excursion
  6272. (goto-char (org-element-property :begin el))
  6273. (let* ((category (org-get-category))
  6274. (effort (save-match-data
  6275. (or (get-text-property (point) 'effort)
  6276. (org-element-property (intern (concat ":" (upcase org-effort-property))) el))))
  6277. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6278. (inherited-tags
  6279. (or (eq org-agenda-show-inherited-tags 'always)
  6280. (and (listp org-agenda-show-inherited-tags)
  6281. (memq 'agenda org-agenda-show-inherited-tags))
  6282. (and (eq org-agenda-show-inherited-tags t)
  6283. (or (eq org-agenda-use-tag-inheritance t)
  6284. (memq 'agenda
  6285. org-agenda-use-tag-inheritance)))))
  6286. (tags (org-get-tags el (not inherited-tags)))
  6287. (level (make-string (org-element-property :level el)
  6288. ?\s))
  6289. (head (save-excursion
  6290. (goto-char (org-element-property :begin el))
  6291. (re-search-forward org-outline-regexp-bol)
  6292. (buffer-substring (point) (line-end-position))))
  6293. (time
  6294. (cond
  6295. ;; No time of day designation if it is only a
  6296. ;; reminder, except for habits, which always show
  6297. ;; the time of day. Habits are an exception
  6298. ;; because if there is a time of day, that is
  6299. ;; interpreted to mean they should usually happen
  6300. ;; then, even if doing the habit was missed.
  6301. ((and
  6302. (not habitp)
  6303. (/= current schedule)
  6304. (/= current repeat))
  6305. nil)
  6306. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6307. (concat (substring s (match-beginning 1)) " "))
  6308. (t 'time)))
  6309. (item
  6310. (org-agenda-format-item
  6311. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6312. ;; Show a reminder of a past scheduled today.
  6313. (if (and todayp pastschedp)
  6314. (format past diff)
  6315. first))
  6316. (org-add-props head nil
  6317. 'effort effort
  6318. 'effort-minutes effort-minutes)
  6319. level category tags time nil habitp))
  6320. (face (cond ((and (not habitp) pastschedp)
  6321. 'org-scheduled-previously)
  6322. ((and habitp futureschedp)
  6323. 'org-agenda-done)
  6324. (todayp 'org-scheduled-today)
  6325. (t 'org-scheduled)))
  6326. (habitp (and habitp (org-habit-parse-todo (org-element-property :begin el)))))
  6327. (org-add-props item props
  6328. 'undone-face face
  6329. 'face (if donep 'org-agenda-done face)
  6330. 'org-marker (org-agenda-new-marker pos)
  6331. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6332. 'type (if pastschedp "past-scheduled" "scheduled")
  6333. 'date (if pastschedp schedule date)
  6334. 'ts-date schedule
  6335. 'warntime warntime
  6336. 'level level
  6337. 'effort effort 'effort-minutes effort-minutes
  6338. 'priority (if habitp (org-habit-get-priority habitp)
  6339. (+ 99 diff (org-get-priority item)))
  6340. 'org-habit-p habitp
  6341. 'todo-state todo-state)
  6342. (push item scheduled-items)))))))
  6343. :next-re regexp
  6344. :fail-re regexp
  6345. :narrow t)
  6346. (while (re-search-forward regexp nil t)
  6347. (catch :skip
  6348. (unless (save-match-data (org-at-planning-p)) (throw :skip nil))
  6349. (org-agenda-skip)
  6350. (let* ((s (match-string 1))
  6351. (pos (1- (match-beginning 1)))
  6352. (todo-state (save-match-data (org-get-todo-state)))
  6353. (donep (member todo-state org-done-keywords))
  6354. (sexp? (string-prefix-p "%%" s))
  6355. ;; SCHEDULE is the scheduled date for the entry. It is
  6356. ;; either the bare date or the last repeat, according
  6357. ;; to `org-agenda-prefer-last-repeat'.
  6358. (schedule
  6359. (cond
  6360. (sexp? (org-agenda--timestamp-to-absolute s current))
  6361. ((or (eq org-agenda-prefer-last-repeat t)
  6362. (member todo-state org-agenda-prefer-last-repeat))
  6363. (org-agenda--timestamp-to-absolute
  6364. s today 'past (current-buffer) pos))
  6365. (t (org-agenda--timestamp-to-absolute s))))
  6366. ;; REPEAT is the future repeat closest from CURRENT,
  6367. ;; according to `org-agenda-show-future-repeats'. If
  6368. ;; the latter is nil, or if the time stamp has no
  6369. ;; repeat part, default to SCHEDULE.
  6370. (repeat
  6371. (cond
  6372. (sexp? schedule)
  6373. ((<= current today) schedule)
  6374. ((not org-agenda-show-future-repeats) schedule)
  6375. (t
  6376. (let ((base (if (eq org-agenda-show-future-repeats 'next)
  6377. (1+ today)
  6378. current)))
  6379. (org-agenda--timestamp-to-absolute
  6380. s base 'future (current-buffer) pos)))))
  6381. (diff (- current schedule))
  6382. (warntime (get-text-property (point) 'org-appt-warntime))
  6383. (pastschedp (< schedule today))
  6384. (futureschedp (> schedule today))
  6385. (habitp (and (fboundp 'org-is-habit-p) (org-is-habit-p)))
  6386. (suppress-delay
  6387. (let ((deadline (and org-agenda-skip-scheduled-delay-if-deadline
  6388. (org-entry-get nil "DEADLINE"))))
  6389. (cond
  6390. ((not deadline) nil)
  6391. ;; The current item has a deadline date, so
  6392. ;; evaluate its delay time.
  6393. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  6394. ;; Use global delay time.
  6395. (- org-agenda-skip-scheduled-delay-if-deadline))
  6396. ((eq org-agenda-skip-scheduled-delay-if-deadline
  6397. 'post-deadline)
  6398. ;; Set delay to no later than DEADLINE.
  6399. (min (- schedule
  6400. (org-agenda--timestamp-to-absolute deadline))
  6401. org-scheduled-delay-days))
  6402. (t 0))))
  6403. (ddays
  6404. (cond
  6405. ;; Nullify delay when a repeater triggered already
  6406. ;; and the delay is of the form --Xd.
  6407. ((and (string-match-p "--[0-9]+[hdwmy]" s)
  6408. (> schedule (org-agenda--timestamp-to-absolute s)))
  6409. 0)
  6410. (suppress-delay
  6411. (let ((org-scheduled-delay-days suppress-delay))
  6412. (org-get-wdays s t t)))
  6413. (t (org-get-wdays s t)))))
  6414. ;; Display scheduled items at base date (SCHEDULE), today if
  6415. ;; scheduled before the current date, and at any repeat past
  6416. ;; today. However, skip delayed items and items that have
  6417. ;; been displayed for more than `org-scheduled-past-days'.
  6418. (unless (and todayp
  6419. habitp
  6420. (bound-and-true-p org-habit-show-all-today))
  6421. (when (or (and (> ddays 0) (< diff ddays))
  6422. (> diff (or (and habitp org-habit-scheduled-past-days)
  6423. org-scheduled-past-days))
  6424. (> schedule current)
  6425. (and (/= current schedule)
  6426. (/= current today)
  6427. (/= current repeat)))
  6428. (throw :skip nil)))
  6429. ;; Possibly skip done tasks.
  6430. (when (and donep
  6431. (or org-agenda-skip-scheduled-if-done
  6432. (/= schedule current)))
  6433. (throw :skip nil))
  6434. ;; Skip entry if it already appears as a deadline, per
  6435. ;; `org-agenda-skip-scheduled-if-deadline-is-shown'. This
  6436. ;; doesn't apply to habits.
  6437. (when (pcase org-agenda-skip-scheduled-if-deadline-is-shown
  6438. ((guard
  6439. (or (not (memq (line-beginning-position 0) deadline-pos))
  6440. habitp))
  6441. nil)
  6442. (`repeated-after-deadline
  6443. (let ((deadline (time-to-days
  6444. (org-get-deadline-time (point)))))
  6445. (and (<= schedule deadline) (> current deadline))))
  6446. (`not-today pastschedp)
  6447. (`t t)
  6448. (_ nil))
  6449. (throw :skip nil))
  6450. ;; Skip habits if `org-habit-show-habits' is nil, or if we
  6451. ;; only show them for today. Also skip done habits.
  6452. (when (and habitp
  6453. (or donep
  6454. (not (bound-and-true-p org-habit-show-habits))
  6455. (and (not todayp)
  6456. (bound-and-true-p
  6457. org-habit-show-habits-only-for-today))))
  6458. (throw :skip nil))
  6459. (save-excursion
  6460. (re-search-backward "^\\*+[ \t]+" nil t)
  6461. (goto-char (match-end 0))
  6462. (let* ((category (org-get-category))
  6463. (effort (save-match-data (or (get-text-property (point) 'effort)
  6464. (org-entry-get (point) org-effort-property))))
  6465. (effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6466. (inherited-tags
  6467. (or (eq org-agenda-show-inherited-tags 'always)
  6468. (and (listp org-agenda-show-inherited-tags)
  6469. (memq 'agenda org-agenda-show-inherited-tags))
  6470. (and (eq org-agenda-show-inherited-tags t)
  6471. (or (eq org-agenda-use-tag-inheritance t)
  6472. (memq 'agenda
  6473. org-agenda-use-tag-inheritance)))))
  6474. (tags (org-get-tags nil (not inherited-tags)))
  6475. (level (make-string (org-reduced-level (org-outline-level))
  6476. ?\s))
  6477. (head (buffer-substring (point) (line-end-position)))
  6478. (time
  6479. (cond
  6480. ;; No time of day designation if it is only a
  6481. ;; reminder, except for habits, which always show
  6482. ;; the time of day. Habits are an exception
  6483. ;; because if there is a time of day, that is
  6484. ;; interpreted to mean they should usually happen
  6485. ;; then, even if doing the habit was missed.
  6486. ((and
  6487. (not habitp)
  6488. (/= current schedule)
  6489. (/= current repeat))
  6490. nil)
  6491. ((string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  6492. (concat (substring s (match-beginning 1)) " "))
  6493. (t 'time)))
  6494. (item
  6495. (org-agenda-format-item
  6496. (pcase-let ((`(,first ,past) org-agenda-scheduled-leaders))
  6497. ;; Show a reminder of a past scheduled today.
  6498. (if (and todayp pastschedp)
  6499. (format past diff)
  6500. first))
  6501. (org-add-props head nil
  6502. 'effort effort
  6503. 'effort-minutes effort-minutes)
  6504. level category tags time nil habitp))
  6505. (face (cond ((and (not habitp) pastschedp)
  6506. 'org-scheduled-previously)
  6507. ((and habitp futureschedp)
  6508. 'org-agenda-done)
  6509. (todayp 'org-scheduled-today)
  6510. (t 'org-scheduled)))
  6511. (habitp (and habitp (org-habit-parse-todo))))
  6512. (org-add-props item props
  6513. 'undone-face face
  6514. 'face (if donep 'org-agenda-done face)
  6515. 'org-marker (org-agenda-new-marker pos)
  6516. 'org-hd-marker (org-agenda-new-marker (line-beginning-position))
  6517. 'type (if pastschedp "past-scheduled" "scheduled")
  6518. 'date (if pastschedp schedule date)
  6519. 'ts-date schedule
  6520. 'warntime warntime
  6521. 'level level
  6522. 'effort effort 'effort-minutes effort-minutes
  6523. 'priority (if habitp (org-habit-get-priority habitp)
  6524. (+ 99 diff (org-get-priority item)))
  6525. 'org-habit-p habitp
  6526. 'todo-state todo-state)
  6527. (push item scheduled-items)))))))
  6528. (nreverse scheduled-items)))
  6529. (defun org-agenda-get-blocks ()
  6530. "Return the date-range information for agenda display."
  6531. (with-no-warnings (defvar date))
  6532. (let* ((props (list 'face nil
  6533. 'org-not-done-regexp org-not-done-regexp
  6534. 'org-todo-regexp org-todo-regexp
  6535. 'org-complex-heading-regexp org-complex-heading-regexp
  6536. 'mouse-face 'highlight
  6537. 'help-echo
  6538. (format "mouse-2 or RET jump to org file %s"
  6539. (abbreviate-file-name buffer-file-name))))
  6540. (regexp org-tr-regexp)
  6541. (d0 (calendar-absolute-from-gregorian date))
  6542. marker hdmarker ee txt d1 d2 s1 s2 category
  6543. level todo-state tags pos head donep inherited-tags
  6544. effort effort-minutes)
  6545. (goto-char (point-min))
  6546. (while (re-search-forward regexp nil t)
  6547. (catch :skip
  6548. (org-agenda-skip)
  6549. (setq pos (point))
  6550. (let ((start-time (match-string 1))
  6551. (end-time (match-string 2)))
  6552. (setq s1 (match-string 1)
  6553. s2 (match-string 2)
  6554. d1 (time-to-days
  6555. (condition-case err
  6556. (org-time-string-to-time s1)
  6557. (error
  6558. (error
  6559. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6560. s1
  6561. pos
  6562. (current-buffer)
  6563. (error-message-string err)))))
  6564. d2 (time-to-days
  6565. (condition-case err
  6566. (org-time-string-to-time s2)
  6567. (error
  6568. (error
  6569. "Bad timestamp %S at %d in buffer %S\nError was: %s"
  6570. s2
  6571. pos
  6572. (current-buffer)
  6573. (error-message-string err))))))
  6574. (when (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  6575. ;; Only allow days between the limits, because the normal
  6576. ;; date stamps will catch the limits.
  6577. (save-excursion
  6578. (setq todo-state (org-get-todo-state))
  6579. (setq donep (member todo-state org-done-keywords))
  6580. (when (and donep org-agenda-skip-timestamp-if-done)
  6581. (throw :skip t))
  6582. (setq marker (org-agenda-new-marker (point))
  6583. category (org-get-category))
  6584. (setq effort (save-match-data (or (get-text-property (point) 'effort)
  6585. (org-entry-get (point) org-effort-property))))
  6586. (setq effort-minutes (when effort (save-match-data (org-duration-to-minutes effort))))
  6587. (if (not (re-search-backward org-outline-regexp-bol nil t))
  6588. (throw :skip nil)
  6589. (goto-char (match-beginning 0))
  6590. (setq hdmarker (org-agenda-new-marker (point))
  6591. inherited-tags
  6592. (or (eq org-agenda-show-inherited-tags 'always)
  6593. (and (listp org-agenda-show-inherited-tags)
  6594. (memq 'agenda org-agenda-show-inherited-tags))
  6595. (and (eq org-agenda-show-inherited-tags t)
  6596. (or (eq org-agenda-use-tag-inheritance t)
  6597. (memq 'agenda org-agenda-use-tag-inheritance))))
  6598. tags (org-get-tags nil (not inherited-tags)))
  6599. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  6600. (looking-at "\\*+[ \t]+\\(.*\\)")
  6601. (setq head (match-string 1))
  6602. (let ((remove-re
  6603. (if org-agenda-remove-timeranges-from-blocks
  6604. (concat
  6605. "<" (regexp-quote s1) ".*?>"
  6606. "--"
  6607. "<" (regexp-quote s2) ".*?>")
  6608. nil)))
  6609. (setq txt (org-agenda-format-item
  6610. (format
  6611. (nth (if (= d1 d2) 0 1)
  6612. org-agenda-timerange-leaders)
  6613. (1+ (- d0 d1)) (1+ (- d2 d1)))
  6614. (org-add-props head nil
  6615. 'effort effort
  6616. 'effort-minutes effort-minutes)
  6617. level category tags
  6618. (save-match-data
  6619. (let ((hhmm1 (and (string-match org-ts-regexp1 s1)
  6620. (match-string 6 s1)))
  6621. (hhmm2 (and (string-match org-ts-regexp1 s2)
  6622. (match-string 6 s2))))
  6623. (cond ((string= hhmm1 hhmm2)
  6624. (concat "<" start-time ">--<" end-time ">"))
  6625. ((and (= d1 d0) (= d2 d0))
  6626. (concat "<" start-time ">--<" end-time ">"))
  6627. ((= d1 d0)
  6628. (concat "<" start-time ">"))
  6629. ((= d2 d0)
  6630. (concat "<" end-time ">")))))
  6631. remove-re))))
  6632. (org-add-props txt props
  6633. 'org-marker marker 'org-hd-marker hdmarker
  6634. 'type "block" 'date date
  6635. 'level level
  6636. 'effort effort 'effort-minutes effort-minutes
  6637. 'todo-state todo-state
  6638. 'priority (org-get-priority txt))
  6639. (push txt ee))))
  6640. (goto-char pos)))
  6641. ;; Sort the entries by expiration date.
  6642. (nreverse ee)))
  6643. ;;; Agenda presentation and sorting
  6644. (defvar org-prefix-has-time nil
  6645. "A flag, set by `org-compile-prefix-format'.
  6646. The flag is set if the currently compiled format contains a `%t'.")
  6647. (defvar org-prefix-has-tag nil
  6648. "A flag, set by `org-compile-prefix-format'.
  6649. The flag is set if the currently compiled format contains a `%T'.")
  6650. (defvar org-prefix-has-effort nil
  6651. "A flag, set by `org-compile-prefix-format'.
  6652. The flag is set if the currently compiled format contains a `%e'.")
  6653. (defvar org-prefix-has-breadcrumbs nil
  6654. "A flag, set by `org-compile-prefix-format'.
  6655. The flag is set if the currently compiled format contains a `%b'.")
  6656. (defvar org-prefix-category-length nil
  6657. "Used by `org-compile-prefix-format' to remember the category field width.")
  6658. (defvar org-prefix-category-max-length nil
  6659. "Used by `org-compile-prefix-format' to remember the category field width.")
  6660. (defun org-agenda-get-category-icon (category)
  6661. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  6662. (cl-dolist (entry org-agenda-category-icon-alist)
  6663. (when (string-match-p (car entry) category)
  6664. (if (listp (cadr entry))
  6665. (cl-return (cadr entry))
  6666. (cl-return (apply #'create-image (cdr entry)))))))
  6667. (defun org-agenda-format-item (extra txt &optional with-level with-category tags dotime
  6668. remove-re habitp)
  6669. "Format TXT to be inserted into the agenda buffer.
  6670. In particular, add the prefix and corresponding text properties.
  6671. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  6672. WITH-LEVEL may be a string to replace the `%l' specifier.
  6673. WITH-CATEGORY (a string, a symbol or nil) may be used to overrule the default
  6674. category taken from local variable or file name. It will replace the `%c'
  6675. specifier in the format.
  6676. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  6677. TXT for sorting of this entry, and for the `%t' specifier in the format.
  6678. When DOTIME is a string, this string is searched for a time before TXT is.
  6679. TAGS can be the tags of the headline.
  6680. Any match of REMOVE-RE will be removed from TXT."
  6681. ;; We keep the org-prefix-* variable values along with a compiled
  6682. ;; formatter, so that multiple agendas existing at the same time do
  6683. ;; not step on each other toes.
  6684. ;;
  6685. ;; It was inconvenient to make these variables buffer local in
  6686. ;; Agenda buffers, because this function expects to be called with
  6687. ;; the buffer where item comes from being current, and not agenda
  6688. ;; buffer
  6689. (let* ((bindings (car org-prefix-format-compiled))
  6690. (formatter (cadr org-prefix-format-compiled)))
  6691. (cl-loop for (var value) in bindings
  6692. do (set var value))
  6693. (save-match-data
  6694. ;; Diary entries sometimes have extra whitespace at the beginning
  6695. (setq txt (org-trim txt))
  6696. ;; Fix the tags part in txt
  6697. (setq txt (org-agenda-fix-displayed-tags
  6698. txt tags
  6699. org-agenda-show-inherited-tags
  6700. org-agenda-hide-tags-regexp))
  6701. (with-no-warnings
  6702. ;; `time', `tag', `effort' are needed for the eval of the prefix format.
  6703. ;; Based on what I see in `org-compile-prefix-format', I added
  6704. ;; a few more.
  6705. (defvar breadcrumbs) (defvar category) (defvar category-icon)
  6706. (defvar effort) (defvar extra)
  6707. (defvar level) (defvar tag) (defvar time))
  6708. (let* ((category (or with-category
  6709. (if buffer-file-name
  6710. (file-name-sans-extension
  6711. (file-name-nondirectory buffer-file-name))
  6712. "")))
  6713. (category-icon (org-agenda-get-category-icon category))
  6714. (category-icon (if category-icon
  6715. (propertize " " 'display category-icon)
  6716. ""))
  6717. (effort (and (not (string= txt ""))
  6718. (get-text-property 1 'effort txt)))
  6719. (tag (if tags (nth (1- (length tags)) tags) ""))
  6720. (time-grid-trailing-characters (nth 2 org-agenda-time-grid))
  6721. (extra (or (and (not habitp) extra) ""))
  6722. time
  6723. (ts (when dotime (concat
  6724. (if (stringp dotime) dotime "")
  6725. (and org-agenda-search-headline-for-time txt))))
  6726. (time-of-day (and dotime (org-get-time-of-day ts)))
  6727. stamp plain s0 s1 s2 rtn srp l
  6728. duration breadcrumbs)
  6729. (and (derived-mode-p 'org-mode) buffer-file-name
  6730. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6731. (when (and dotime time-of-day)
  6732. ;; Extract starting and ending time and move them to prefix
  6733. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6734. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6735. (setq s0 (match-string 0 ts)
  6736. srp (and stamp (match-end 3))
  6737. s1 (match-string (if plain 1 2) ts)
  6738. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6739. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6740. ;; them, we might want to remove them there to avoid duplication.
  6741. ;; The user can turn this off with a variable.
  6742. (when (and org-prefix-has-time
  6743. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6744. (string-match (concat (regexp-quote s0) " *") txt)
  6745. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6746. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6747. (= (match-beginning 0) 0)
  6748. t))
  6749. (setq txt (replace-match "" nil nil txt))))
  6750. ;; Normalize the time(s) to 24 hour.
  6751. (when s1 (setq s1 (org-get-time-of-day s1 t)))
  6752. (when s2 (setq s2 (org-get-time-of-day s2 t)))
  6753. ;; Try to set s2 if s1 and
  6754. ;; `org-agenda-default-appointment-duration' are set
  6755. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6756. (setq s2
  6757. (org-duration-from-minutes
  6758. (+ (org-duration-to-minutes s1 t)
  6759. org-agenda-default-appointment-duration)
  6760. nil t)))
  6761. ;; Compute the duration
  6762. (when s2
  6763. (setq duration (- (org-duration-to-minutes s2)
  6764. (org-duration-to-minutes s1))))
  6765. ;; Format S1 and S2 for display.
  6766. (when s1 (setq s1 (format "%5s" (org-get-time-of-day s1 'overtime))))
  6767. (when s2 (setq s2 (org-get-time-of-day s2 'overtime))))
  6768. (when (string-match org-tag-group-re txt)
  6769. ;; Tags are in the string
  6770. (if (or (eq org-agenda-remove-tags t)
  6771. (and org-agenda-remove-tags
  6772. org-prefix-has-tag))
  6773. (setq txt (replace-match "" t t txt))
  6774. (setq txt (replace-match
  6775. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6776. (match-string 1 txt))
  6777. t t txt))))
  6778. (when remove-re
  6779. (while (string-match remove-re txt)
  6780. (setq txt (replace-match "" t t txt))))
  6781. ;; Set org-heading property on `txt' to mark the start of the
  6782. ;; heading.
  6783. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6784. ;; Prepare the variables needed in the eval of the compiled format
  6785. (when org-prefix-has-breadcrumbs
  6786. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6787. (let ((s (org-format-outline-path (org-get-outline-path)
  6788. (1- (frame-width))
  6789. nil org-agenda-breadcrumbs-separator)))
  6790. (if (eq "" s) "" (concat s org-agenda-breadcrumbs-separator))))))
  6791. (setq time (cond (s2 (concat
  6792. (org-agenda-time-of-day-to-ampm-maybe s1)
  6793. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6794. (when org-agenda-timegrid-use-ampm " ")))
  6795. (s1 (concat
  6796. (org-agenda-time-of-day-to-ampm-maybe s1)
  6797. (if org-agenda-timegrid-use-ampm
  6798. (concat time-grid-trailing-characters " ")
  6799. time-grid-trailing-characters)))
  6800. (t ""))
  6801. category (if (symbolp category) (symbol-name category) category)
  6802. level (or with-level ""))
  6803. (if (string-match org-link-bracket-re category)
  6804. (progn
  6805. (setq l (string-width (or (match-string 2) (match-string 1))))
  6806. (when (< l (or org-prefix-category-length 0))
  6807. (setq category (copy-sequence category))
  6808. (org-add-props category nil
  6809. 'extra-space (make-string
  6810. (- org-prefix-category-length l 1) ?\ ))))
  6811. (when (and org-prefix-category-max-length
  6812. (>= (length category) org-prefix-category-max-length))
  6813. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6814. ;; Evaluate the compiled format
  6815. (setq rtn (concat (eval formatter t) txt))
  6816. ;; And finally add the text properties
  6817. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6818. (org-add-props rtn nil
  6819. 'org-category category
  6820. 'tags tags
  6821. 'org-priority-highest org-priority-highest
  6822. 'org-priority-lowest org-priority-lowest
  6823. 'time-of-day time-of-day
  6824. 'duration duration
  6825. 'breadcrumbs breadcrumbs
  6826. 'txt txt
  6827. 'level level
  6828. 'time time
  6829. 'extra extra
  6830. 'format org-prefix-format-compiled
  6831. 'dotime dotime)))))
  6832. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6833. "Remove tags string from TXT, and add a modified list of tags.
  6834. The modified list may contain inherited tags, and tags matched by
  6835. `org-agenda-hide-tags-regexp' will be removed."
  6836. (when (or add-inherited hide-re)
  6837. (when (string-match org-tag-group-re txt)
  6838. (setq txt (substring txt 0 (match-beginning 0))))
  6839. (setq tags
  6840. (delq nil
  6841. (mapcar (lambda (tg)
  6842. (if (or (and hide-re (string-match hide-re tg))
  6843. (and (not add-inherited)
  6844. (get-text-property 0 'inherited tg)))
  6845. nil
  6846. tg))
  6847. tags)))
  6848. (when tags
  6849. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6850. i)
  6851. (setq txt (concat txt " :"
  6852. (mapconcat
  6853. (lambda (x)
  6854. (setq i (get-text-property 0 'inherited x))
  6855. (if (and have-i (not i))
  6856. (progn
  6857. (setq have-i nil)
  6858. (concat ":" x))
  6859. x))
  6860. tags ":")
  6861. (if have-i "::" ":"))))))
  6862. txt)
  6863. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6864. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6865. "Add a time-grid for agenda items which need it.
  6866. LIST is the list of agenda items formatted by `org-agenda-list'.
  6867. NDAYS is the span of the current agenda view.
  6868. TODAYP is t when the current agenda view is on today."
  6869. (catch 'exit
  6870. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6871. ((and todayp (member 'today (car org-agenda-time-grid))))
  6872. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6873. ((member 'weekly (car org-agenda-time-grid)))
  6874. (t (throw 'exit list)))
  6875. (let* ((have (delq nil (mapcar
  6876. (lambda (x) (get-text-property 1 'time-of-day x))
  6877. list)))
  6878. (string (nth 3 org-agenda-time-grid))
  6879. (gridtimes (nth 1 org-agenda-time-grid))
  6880. (req (car org-agenda-time-grid))
  6881. (remove (member 'remove-match req))
  6882. new time)
  6883. (when (and (member 'require-timed req) (not have))
  6884. ;; don't show empty grid
  6885. (throw 'exit list))
  6886. (while (setq time (pop gridtimes))
  6887. (unless (and remove (member time have))
  6888. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6889. (push (org-agenda-format-item
  6890. nil string nil "" nil
  6891. (concat (substring time 0 -2) ":" (substring time -2)))
  6892. new)
  6893. (put-text-property
  6894. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6895. (when (and todayp org-agenda-show-current-time-in-grid)
  6896. (push (org-agenda-format-item
  6897. nil org-agenda-current-time-string nil "" nil
  6898. (format-time-string "%H:%M "))
  6899. new)
  6900. (put-text-property
  6901. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6902. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6903. (append new list)
  6904. (append list new)))))
  6905. (defun org-compile-prefix-format (key)
  6906. "Compile the prefix format into a Lisp form that can be evaluated.
  6907. KEY is the agenda type (see `org-agenda-prefix-format').
  6908. The resulting form and associated variable bindings is returned
  6909. and stored in the variable `org-prefix-format-compiled'."
  6910. (setq org-prefix-has-time nil
  6911. org-prefix-has-tag nil
  6912. org-prefix-category-length nil
  6913. org-prefix-has-effort nil
  6914. org-prefix-has-breadcrumbs nil)
  6915. (let ((s (cond
  6916. ((stringp org-agenda-prefix-format)
  6917. org-agenda-prefix-format)
  6918. ((assq key org-agenda-prefix-format)
  6919. (cdr (assq key org-agenda-prefix-format)))
  6920. (t " %-12:c%?-12t% s")))
  6921. (start 0)
  6922. varform vars var c f opt) ;; e
  6923. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+?)\\)"
  6924. s start)
  6925. (setq var (or (cdr (assoc (match-string 4 s)
  6926. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6927. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6928. 'eval)
  6929. c (or (match-string 3 s) "")
  6930. opt (match-beginning 1)
  6931. start (1+ (match-beginning 0)))
  6932. (cl-case var
  6933. (time (setq org-prefix-has-time t))
  6934. (tag (setq org-prefix-has-tag t))
  6935. (effort (setq org-prefix-has-effort t))
  6936. (breadcrumbs (setq org-prefix-has-breadcrumbs t)))
  6937. (setq f (concat "%" (match-string 2 s) "s"))
  6938. (when (eq var 'category)
  6939. (setq org-prefix-category-length
  6940. (floor (abs (string-to-number (match-string 2 s)))))
  6941. (setq org-prefix-category-max-length
  6942. (let ((x (match-string 2 s)))
  6943. (save-match-data
  6944. (and (string-match "\\.[0-9]+" x)
  6945. (string-to-number (substring (match-string 0 x) 1)))))))
  6946. (if (eq var 'eval)
  6947. (setq varform `(format ,f (org-eval ,(read (substring s (match-beginning 4))))))
  6948. (if opt
  6949. (setq varform
  6950. `(if (member ,var '("" nil))
  6951. ""
  6952. (format ,f (concat ,var ,c))))
  6953. (setq varform
  6954. `(format ,f (if (member ,var '("" nil)) ""
  6955. (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6956. (if (eq var 'eval)
  6957. (setf (substring s (match-beginning 0)
  6958. (+ (match-beginning 4)
  6959. (length (format "%S" (read (substring s (match-beginning 4)))))))
  6960. "%s")
  6961. (setq s (replace-match "%s" t nil s)))
  6962. (push varform vars))
  6963. (setq vars (nreverse vars))
  6964. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6965. (setq org-prefix-format-compiled
  6966. (list
  6967. `((org-prefix-has-time ,org-prefix-has-time)
  6968. (org-prefix-has-tag ,org-prefix-has-tag)
  6969. (org-prefix-category-length ,org-prefix-category-length)
  6970. (org-prefix-has-effort ,org-prefix-has-effort)
  6971. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6972. `(format ,s ,@vars))))))
  6973. (defun org-set-sorting-strategy (key)
  6974. (setq org-agenda-sorting-strategy-selected
  6975. (if (symbolp (car org-agenda-sorting-strategy))
  6976. ;; the old format
  6977. org-agenda-sorting-strategy
  6978. (or (cdr (assq key org-agenda-sorting-strategy))
  6979. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6980. '(time-up category-keep priority-down)))))
  6981. (defun org-get-time-of-day (s &optional string)
  6982. "Check string S for a time of day.
  6983. If found, return it as a military time number between 0 and 2400.
  6984. If not found, return nil.
  6985. The optional STRING argument forces conversion into a 5 character wide string
  6986. HH:MM. When it is `overtime', any time above 24:00 is turned into \"+H:MM\"
  6987. where H:MM is the duration above midnight."
  6988. (let ((case-fold-search t)
  6989. (time-regexp
  6990. (rx word-start
  6991. (group (opt (any "012")) digit) ;group 1: hours
  6992. (or (and ":" (group (any "012345") digit) ;group 2: minutes
  6993. (opt (group (or "am" "pm")))) ;group 3: am/pm
  6994. ;; Special "HHam/pm" case.
  6995. (group-n 3 (or "am" "pm")))
  6996. word-end)))
  6997. (save-match-data
  6998. (when (and (string-match time-regexp s)
  6999. (not (eq 'org-link (get-text-property 1 'face s))))
  7000. (let ((hours
  7001. (let* ((ampm (and (match-end 3) (downcase (match-string 3 s))))
  7002. (am-p (equal ampm "am")))
  7003. (pcase (string-to-number (match-string 1 s))
  7004. ((and (guard (not ampm)) h) h)
  7005. (12 (if am-p 0 12))
  7006. (h (+ h (if am-p 0 12))))))
  7007. (minutes
  7008. (if (match-end 2)
  7009. (string-to-number (match-string 2 s))
  7010. 0)))
  7011. (pcase string
  7012. (`nil (+ minutes (* hours 100)))
  7013. ((and `overtime
  7014. (guard (or (> hours 24)
  7015. (and (= hours 24)
  7016. (> minutes 0)))))
  7017. (format "+%d:%02d" (- hours 24) minutes))
  7018. ((guard org-agenda-time-leading-zero)
  7019. (format "%02d:%02d" hours minutes))
  7020. (_
  7021. (format "%d:%02d" hours minutes))))))))
  7022. (defvar org-agenda-before-sorting-filter-function nil
  7023. "Function to be applied to agenda items prior to sorting.
  7024. Prior to sorting also means just before they are inserted into the agenda.
  7025. To aid sorting, you may revisit the original entries and add more text
  7026. properties which will later be used by the sorting functions.
  7027. The function should take a string argument, an agenda line.
  7028. It has access to the text properties in that line, which contain among
  7029. other things, the property `org-hd-marker' that points to the entry
  7030. where the line comes from. Note that not all lines going into the agenda
  7031. have this property, only most.
  7032. The function should return the modified string. It is probably best
  7033. to ONLY change text properties.
  7034. You can also use this function as a filter, by returning nil for lines
  7035. you don't want to have in the agenda at all. For this application, you
  7036. could bind the variable in the options section of a custom command.")
  7037. (defun org-agenda-finalize-entries (list &optional type)
  7038. "Sort, limit and concatenate the LIST of agenda items.
  7039. The optional argument TYPE tells the agenda type."
  7040. (let ((max-effort (cond ((listp org-agenda-max-effort)
  7041. (cdr (assoc type org-agenda-max-effort)))
  7042. (t org-agenda-max-effort)))
  7043. (max-todo (cond ((listp org-agenda-max-todos)
  7044. (cdr (assoc type org-agenda-max-todos)))
  7045. (t org-agenda-max-todos)))
  7046. (max-tags (cond ((listp org-agenda-max-tags)
  7047. (cdr (assoc type org-agenda-max-tags)))
  7048. (t org-agenda-max-tags)))
  7049. (max-entries (cond ((listp org-agenda-max-entries)
  7050. (cdr (assoc type org-agenda-max-entries)))
  7051. (t org-agenda-max-entries))))
  7052. (when org-agenda-before-sorting-filter-function
  7053. (setq list
  7054. (delq nil
  7055. (mapcar
  7056. org-agenda-before-sorting-filter-function list))))
  7057. (setq list (mapcar #'org-agenda-highlight-todo list)
  7058. list (mapcar #'identity (sort list #'org-entries-lessp)))
  7059. (when max-effort
  7060. (setq list (org-agenda-limit-entries
  7061. list 'effort-minutes max-effort
  7062. (lambda (e) (or e (if org-agenda-sort-noeffort-is-high
  7063. 32767 -1))))))
  7064. (when max-todo
  7065. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  7066. (when max-tags
  7067. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  7068. (when max-entries
  7069. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  7070. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  7071. (setq list (mapcar #'org-agenda--mark-blocked-entry list)))
  7072. (mapconcat #'identity list "\n")))
  7073. (defun org-agenda-limit-entries (list prop limit &optional fn)
  7074. "Limit the number of agenda entries."
  7075. (let ((include (and limit (< limit 0))))
  7076. (if limit
  7077. (let ((fun (or fn (lambda (p) (when p 1))))
  7078. (lim 0))
  7079. (delq nil
  7080. (mapcar
  7081. (lambda (e)
  7082. (let ((pval (funcall
  7083. fun (get-text-property (1- (length e))
  7084. prop e))))
  7085. (when pval (setq lim (+ lim pval)))
  7086. (cond ((and pval (<= lim (abs limit))) e)
  7087. ((and include (not pval)) e))))
  7088. list)))
  7089. list)))
  7090. (defun org-agenda-limit-interactively (remove)
  7091. "In agenda, interactively limit entries to various maximums."
  7092. (interactive "P")
  7093. (if remove
  7094. (progn (setq org-agenda-max-entries nil
  7095. org-agenda-max-todos nil
  7096. org-agenda-max-tags nil
  7097. org-agenda-max-effort nil)
  7098. (org-agenda-redo))
  7099. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  7100. (msg (cond ((= max ?E) "How many minutes? ")
  7101. ((= max ?e) "How many entries? ")
  7102. ((= max ?t) "How many TODO entries? ")
  7103. ((= max ?T) "How many tagged entries? ")
  7104. (t (user-error "Wrong input"))))
  7105. (num (string-to-number (read-from-minibuffer msg))))
  7106. (cond ((equal max ?e)
  7107. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  7108. ((equal max ?t)
  7109. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  7110. ((equal max ?T)
  7111. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  7112. ((equal max ?E)
  7113. (let ((org-agenda-max-effort num)) (org-agenda-redo))))))
  7114. (org-agenda-fit-window-to-buffer))
  7115. (defun org-agenda-highlight-todo (x)
  7116. (let ((org-done-keywords org-done-keywords-for-agenda)
  7117. (case-fold-search nil)
  7118. re)
  7119. (if (eq x 'line)
  7120. (save-excursion
  7121. (beginning-of-line 1)
  7122. (setq re (org-get-at-bol 'org-todo-regexp))
  7123. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  7124. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  7125. (add-text-properties (match-beginning 0) (match-end 1)
  7126. (list 'face (org-get-todo-face 1)))
  7127. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  7128. (delete-region (match-beginning 1) (1- (match-end 0)))
  7129. (goto-char (match-beginning 1))
  7130. (insert (format org-agenda-todo-keyword-format s)))))
  7131. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  7132. (setq re (get-text-property 0 'org-todo-regexp x))
  7133. (when (and re
  7134. ;; Test `pl' because if there's no heading content,
  7135. ;; there's no point matching to highlight. Note
  7136. ;; that if we didn't test `pl' first, and there
  7137. ;; happened to be no keyword from `org-todo-regexp'
  7138. ;; on this heading line, then the `equal' comparison
  7139. ;; afterwards would spuriously succeed in the case
  7140. ;; where `pl' is nil -- causing an args-out-of-range
  7141. ;; error when we try to add text properties to text
  7142. ;; that isn't there.
  7143. pl
  7144. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  7145. x pl)
  7146. pl))
  7147. (add-text-properties
  7148. (or (match-end 1) (match-end 0)) (match-end 0)
  7149. (list 'face (org-get-todo-face (match-string 2 x)))
  7150. x)
  7151. (when (match-end 1)
  7152. (setq x
  7153. (concat
  7154. (substring x 0 (match-end 1))
  7155. (unless (string= org-agenda-todo-keyword-format "")
  7156. (format org-agenda-todo-keyword-format
  7157. (match-string 2 x)))
  7158. (unless (string= org-agenda-todo-keyword-format "")
  7159. ;; Remove `display' property as the icon could leak
  7160. ;; on the white space.
  7161. (org-add-props " " (org-plist-delete (text-properties-at 0 x)
  7162. 'display)))
  7163. (substring x (match-end 3)))))))
  7164. x)))
  7165. (defsubst org-cmp-values (a b property)
  7166. "Compare the numeric value of text PROPERTY for string A and B."
  7167. (let ((pa (or (get-text-property (1- (length a)) property a) 0))
  7168. (pb (or (get-text-property (1- (length b)) property b) 0)))
  7169. (cond ((> pa pb) +1)
  7170. ((< pa pb) -1))))
  7171. (defsubst org-cmp-effort (a b)
  7172. "Compare the effort values of string A and B."
  7173. (let* ((def (if org-agenda-sort-noeffort-is-high 32767 -1))
  7174. ;; `effort-minutes' property is not directly accessible from
  7175. ;; the strings, but is stored as a property in `txt'.
  7176. (ea (or (get-text-property
  7177. 0 'effort-minutes (get-text-property 0 'txt a))
  7178. def))
  7179. (eb (or (get-text-property
  7180. 0 'effort-minutes (get-text-property 0 'txt b))
  7181. def)))
  7182. (cond ((> ea eb) +1)
  7183. ((< ea eb) -1))))
  7184. (defsubst org-cmp-category (a b)
  7185. "Compare the string values of categories of strings A and B."
  7186. (let ((ca (or (get-text-property (1- (length a)) 'org-category a) ""))
  7187. (cb (or (get-text-property (1- (length b)) 'org-category b) "")))
  7188. (cond ((string-lessp ca cb) -1)
  7189. ((string-lessp cb ca) +1))))
  7190. (defsubst org-cmp-todo-state (a b)
  7191. "Compare the todo states of strings A and B."
  7192. (let* ((ma (or (get-text-property 1 'org-marker a)
  7193. (get-text-property 1 'org-hd-marker a)))
  7194. (mb (or (get-text-property 1 'org-marker b)
  7195. (get-text-property 1 'org-hd-marker b)))
  7196. (fa (and ma (marker-buffer ma)))
  7197. (fb (and mb (marker-buffer mb)))
  7198. (todo-kwds
  7199. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  7200. (and fb (with-current-buffer fb org-todo-keywords-1))))
  7201. (ta (or (get-text-property 1 'todo-state a) ""))
  7202. (tb (or (get-text-property 1 'todo-state b) ""))
  7203. (la (- (length (member ta todo-kwds))))
  7204. (lb (- (length (member tb todo-kwds))))
  7205. (donepa (member ta org-done-keywords-for-agenda))
  7206. (donepb (member tb org-done-keywords-for-agenda)))
  7207. (cond ((and donepa (not donepb)) -1)
  7208. ((and (not donepa) donepb) +1)
  7209. ((< la lb) -1)
  7210. ((< lb la) +1))))
  7211. (defsubst org-cmp-alpha (a b)
  7212. "Compare the headlines, alphabetically."
  7213. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  7214. (plb (text-property-any 0 (length b) 'org-heading t b))
  7215. (ta (and pla (substring a pla)))
  7216. (tb (and plb (substring b plb)))
  7217. (case-fold-search nil))
  7218. (when pla
  7219. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  7220. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7221. ta)
  7222. (setq ta (substring ta (match-end 0))))
  7223. (setq ta (downcase ta)))
  7224. (when plb
  7225. (when (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  7226. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *")
  7227. tb)
  7228. (setq tb (substring tb (match-end 0))))
  7229. (setq tb (downcase tb)))
  7230. (cond ((not (or ta tb)) nil)
  7231. ((not ta) +1)
  7232. ((not tb) -1)
  7233. ((string-lessp ta tb) -1)
  7234. ((string-lessp tb ta) +1))))
  7235. (defsubst org-cmp-tag (a b)
  7236. "Compare the string values of the first tags of A and B."
  7237. (let ((ta (car (last (get-text-property 1 'tags a))))
  7238. (tb (car (last (get-text-property 1 'tags b)))))
  7239. (cond ((not (or ta tb)) nil)
  7240. ((not ta) +1)
  7241. ((not tb) -1)
  7242. ((string-lessp ta tb) -1)
  7243. ((string-lessp tb ta) +1))))
  7244. (defsubst org-cmp-time (a b)
  7245. "Compare the time-of-day values of strings A and B."
  7246. (let* ((def (if org-agenda-sort-notime-is-late 9901 -1))
  7247. (ta (or (get-text-property 1 'time-of-day a) def))
  7248. (tb (or (get-text-property 1 'time-of-day b) def)))
  7249. (cond ((< ta tb) -1)
  7250. ((< tb ta) +1))))
  7251. (defsubst org-cmp-ts (a b type)
  7252. "Compare the timestamps values of entries A and B.
  7253. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  7254. \"timestamp_ia\", compare within each of these type. When TYPE
  7255. is the empty string, compare all timestamps without respect of
  7256. their type."
  7257. (let* ((def (if org-agenda-sort-notime-is-late 99999999 -1))
  7258. (ta (or (and (string-match type (or (get-text-property 1 'type a) ""))
  7259. (get-text-property 1 'ts-date a))
  7260. def))
  7261. (tb (or (and (string-match type (or (get-text-property 1 'type b) ""))
  7262. (get-text-property 1 'ts-date b))
  7263. def)))
  7264. (cond ((if ta (and tb (< ta tb)) tb) -1)
  7265. ((if tb (and ta (< tb ta)) ta) +1))))
  7266. (defsubst org-cmp-habit-p (a b)
  7267. "Compare the todo states of strings A and B."
  7268. (let ((ha (get-text-property 1 'org-habit-p a))
  7269. (hb (get-text-property 1 'org-habit-p b)))
  7270. (cond ((and ha (not hb)) -1)
  7271. ((and (not ha) hb) +1))))
  7272. (defun org-entries-lessp (a b)
  7273. "Predicate for sorting agenda entries."
  7274. ;; The following variables will be used when the form is evaluated.
  7275. ;; So even though the compiler complains, keep them.
  7276. (let ((ss org-agenda-sorting-strategy-selected))
  7277. (org-dlet
  7278. ((timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  7279. (org-cmp-ts a b "")))
  7280. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  7281. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  7282. (org-cmp-ts a b "scheduled")))
  7283. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  7284. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  7285. (org-cmp-ts a b "deadline")))
  7286. (deadline-down (if deadline-up (- deadline-up) nil))
  7287. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  7288. (org-cmp-ts a b "timestamp_ia")))
  7289. (tsia-down (if tsia-up (- tsia-up) nil))
  7290. (ts-up (and (org-em 'ts-up 'ts-down ss)
  7291. (org-cmp-ts a b "timestamp")))
  7292. (ts-down (if ts-up (- ts-up) nil))
  7293. (time-up (and (org-em 'time-up 'time-down ss)
  7294. (org-cmp-time a b)))
  7295. (time-down (if time-up (- time-up) nil))
  7296. (stats-up (and (org-em 'stats-up 'stats-down ss)
  7297. (org-cmp-values a b 'org-stats)))
  7298. (stats-down (if stats-up (- stats-up) nil))
  7299. (priority-up (and (org-em 'priority-up 'priority-down ss)
  7300. (org-cmp-values a b 'priority)))
  7301. (priority-down (if priority-up (- priority-up) nil))
  7302. (effort-up (and (org-em 'effort-up 'effort-down ss)
  7303. (org-cmp-effort a b)))
  7304. (effort-down (if effort-up (- effort-up) nil))
  7305. (category-up (and (or (org-em 'category-up 'category-down ss)
  7306. (memq 'category-keep ss))
  7307. (org-cmp-category a b)))
  7308. (category-down (if category-up (- category-up) nil))
  7309. (category-keep (if category-up +1 nil))
  7310. (tag-up (and (org-em 'tag-up 'tag-down ss)
  7311. (org-cmp-tag a b)))
  7312. (tag-down (if tag-up (- tag-up) nil))
  7313. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  7314. (org-cmp-todo-state a b)))
  7315. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  7316. (habit-up (and (org-em 'habit-up 'habit-down ss)
  7317. (org-cmp-habit-p a b)))
  7318. (habit-down (if habit-up (- habit-up) nil))
  7319. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  7320. (org-cmp-alpha a b)))
  7321. (alpha-down (if alpha-up (- alpha-up) nil))
  7322. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  7323. user-defined-up user-defined-down)
  7324. (when (and need-user-cmp org-agenda-cmp-user-defined
  7325. (functionp org-agenda-cmp-user-defined))
  7326. (setq user-defined-up
  7327. (funcall org-agenda-cmp-user-defined a b)
  7328. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  7329. (cdr (assoc
  7330. (eval (cons 'or org-agenda-sorting-strategy-selected) t)
  7331. '((-1 . t) (1 . nil) (nil . nil)))))))
  7332. ;;; Agenda restriction lock
  7333. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  7334. "Overlay to mark the headline to which agenda commands are restricted.")
  7335. (overlay-put org-agenda-restriction-lock-overlay
  7336. 'face 'org-agenda-restriction-lock)
  7337. (overlay-put org-agenda-restriction-lock-overlay
  7338. 'help-echo "Agendas are currently limited to this subtree.")
  7339. (delete-overlay org-agenda-restriction-lock-overlay)
  7340. (defun org-agenda-set-restriction-lock-from-agenda (arg)
  7341. "Set the restriction lock to the agenda item at point from within the agenda.
  7342. When called with a `\\[universal-argument]' prefix, restrict to
  7343. the file which contains the item.
  7344. Argument ARG is the prefix argument."
  7345. (interactive "P")
  7346. (unless (derived-mode-p 'org-agenda-mode)
  7347. (user-error "Not in an Org agenda buffer"))
  7348. (let* ((marker (or (org-get-at-bol 'org-marker)
  7349. (org-agenda-error)))
  7350. (buffer (marker-buffer marker))
  7351. (pos (marker-position marker)))
  7352. (with-current-buffer buffer
  7353. (goto-char pos)
  7354. (org-agenda-set-restriction-lock arg))))
  7355. ;;;###autoload
  7356. (defun org-agenda-set-restriction-lock (&optional type)
  7357. "Set restriction lock for agenda to current subtree or file.
  7358. When in a restricted subtree, remove it.
  7359. The restriction will span over the entire file if TYPE is `file',
  7360. or if type is \\='(4), or if the cursor is before the first headline
  7361. in the file. Otherwise, only apply the restriction to the current
  7362. subtree."
  7363. (interactive "P")
  7364. (if (and org-agenda-overriding-restriction
  7365. (member org-agenda-restriction-lock-overlay
  7366. (overlays-at (point)))
  7367. (equal (overlay-start org-agenda-restriction-lock-overlay)
  7368. (point)))
  7369. (org-agenda-remove-restriction-lock 'noupdate)
  7370. (org-agenda-remove-restriction-lock 'noupdate)
  7371. (and (equal type '(4)) (setq type 'file))
  7372. (setq type (cond
  7373. (type type)
  7374. ((org-at-heading-p) 'subtree)
  7375. ((condition-case nil (org-back-to-heading t) (error nil))
  7376. 'subtree)
  7377. (t 'file)))
  7378. (if (eq type 'subtree)
  7379. (progn
  7380. (setq org-agenda-restrict (current-buffer))
  7381. (setq org-agenda-overriding-restriction 'subtree)
  7382. (put 'org-agenda-files 'org-restrict
  7383. (list (buffer-file-name (buffer-base-buffer))))
  7384. (org-back-to-heading t)
  7385. (move-overlay org-agenda-restriction-lock-overlay
  7386. (point)
  7387. (if org-agenda-restriction-lock-highlight-subtree
  7388. (save-excursion (org-end-of-subtree t t) (point))
  7389. (point-at-eol)))
  7390. (move-marker org-agenda-restrict-begin (point))
  7391. (move-marker org-agenda-restrict-end
  7392. (save-excursion (org-end-of-subtree t t)))
  7393. (message "Locking agenda restriction to subtree"))
  7394. (put 'org-agenda-files 'org-restrict
  7395. (list (buffer-file-name (buffer-base-buffer))))
  7396. (setq org-agenda-restrict nil)
  7397. (setq org-agenda-overriding-restriction 'file)
  7398. (move-marker org-agenda-restrict-begin nil)
  7399. (move-marker org-agenda-restrict-end nil)
  7400. (message "Locking agenda restriction to file"))
  7401. (setq current-prefix-arg nil))
  7402. (org-agenda-maybe-redo))
  7403. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  7404. "Remove agenda restriction lock."
  7405. (interactive "P")
  7406. (if (not org-agenda-restrict)
  7407. (message "No agenda restriction to remove.")
  7408. (delete-overlay org-agenda-restriction-lock-overlay)
  7409. (delete-overlay org-speedbar-restriction-lock-overlay)
  7410. (setq org-agenda-overriding-restriction nil)
  7411. (setq org-agenda-restrict nil)
  7412. (put 'org-agenda-files 'org-restrict nil)
  7413. (move-marker org-agenda-restrict-begin nil)
  7414. (move-marker org-agenda-restrict-end nil)
  7415. (setq current-prefix-arg nil)
  7416. (message "Agenda restriction lock removed")
  7417. (or noupdate (org-agenda-maybe-redo))))
  7418. (defun org-agenda-maybe-redo ()
  7419. "If there is any window showing the agenda view, update it."
  7420. (let ((w (get-buffer-window (or org-agenda-this-buffer-name
  7421. org-agenda-buffer-name)
  7422. t))
  7423. (w0 (selected-window)))
  7424. (when w
  7425. (select-window w)
  7426. (org-agenda-redo)
  7427. (select-window w0)
  7428. (if org-agenda-overriding-restriction
  7429. (message "Agenda view shifted to new %s restriction"
  7430. org-agenda-overriding-restriction)
  7431. (message "Agenda restriction lock removed")))))
  7432. ;;; Agenda commands
  7433. (defun org-agenda-check-type (error &rest types)
  7434. "Check if agenda buffer or component is of allowed type.
  7435. If ERROR is non-nil, throw an error, otherwise just return nil.
  7436. Allowed types are `agenda' `todo' `tags' `search'."
  7437. (cond ((not org-agenda-type)
  7438. (error "No Org agenda currently displayed"))
  7439. ((memq org-agenda-type types) t)
  7440. (error
  7441. (error "Not allowed in '%s'-type agenda buffer or component" org-agenda-type))
  7442. (t nil)))
  7443. (defun org-agenda-Quit ()
  7444. "Exit the agenda, killing the agenda buffer.
  7445. Like `org-agenda-quit', but kill the buffer even when
  7446. `org-agenda-sticky' is non-nil."
  7447. (interactive)
  7448. (org-agenda--quit))
  7449. (defun org-agenda-quit ()
  7450. "Exit the agenda.
  7451. When `org-agenda-sticky' is non-nil, bury the agenda buffer
  7452. instead of killing it.
  7453. When `org-agenda-restore-windows-after-quit' is non-nil, restore
  7454. the pre-agenda window configuration.
  7455. When column view is active, exit column view instead of the
  7456. agenda."
  7457. (interactive)
  7458. (org-agenda--quit org-agenda-sticky))
  7459. (defun org-agenda--quit (&optional bury)
  7460. (if org-agenda-columns-active
  7461. (org-columns-quit)
  7462. (let ((wconf org-agenda-pre-window-conf)
  7463. (buf (current-buffer))
  7464. (org-agenda-last-indirect-window
  7465. (and (eq org-indirect-buffer-display 'other-window)
  7466. org-agenda-last-indirect-buffer
  7467. (get-buffer-window org-agenda-last-indirect-buffer))))
  7468. (cond
  7469. ((eq org-agenda-window-setup 'other-frame)
  7470. (delete-frame))
  7471. ((eq org-agenda-window-setup 'other-tab)
  7472. (if (fboundp 'tab-bar-close-tab)
  7473. (tab-bar-close-tab)
  7474. (user-error "Your version of Emacs does not have tab bar mode support")))
  7475. ((and org-agenda-restore-windows-after-quit
  7476. wconf)
  7477. ;; Maybe restore the pre-agenda window configuration. Reset
  7478. ;; `org-agenda-pre-window-conf' before running
  7479. ;; `set-window-configuration', which loses the current buffer.
  7480. (setq org-agenda-pre-window-conf nil)
  7481. (set-window-configuration wconf))
  7482. (t
  7483. (when org-agenda-last-indirect-window
  7484. (delete-window org-agenda-last-indirect-window))
  7485. (and (not (eq org-agenda-window-setup 'current-window))
  7486. (not (one-window-p))
  7487. (delete-window))))
  7488. (if bury
  7489. ;; Set the agenda buffer as the current buffer instead of
  7490. ;; passing it as an argument to `bury-buffer' so that
  7491. ;; `bury-buffer' removes it from the window.
  7492. (with-current-buffer buf
  7493. (bury-buffer))
  7494. (kill-buffer buf)
  7495. (setq org-agenda-archives-mode nil
  7496. org-agenda-buffer nil)))))
  7497. (defun org-agenda-exit ()
  7498. "Exit the agenda, killing Org buffers loaded by the agenda.
  7499. Like `org-agenda-Quit', but kill any buffers that were created by
  7500. the agenda. Org buffers visited directly by the user will not be
  7501. touched. Also, exit the agenda even if it is in column view."
  7502. (interactive)
  7503. (when org-agenda-columns-active
  7504. (org-columns-quit))
  7505. (org-release-buffers org-agenda-new-buffers)
  7506. (setq org-agenda-new-buffers nil)
  7507. (org-agenda-Quit))
  7508. (defun org-agenda-kill-all-agenda-buffers ()
  7509. "Kill all buffers in `org-agenda-mode'.
  7510. This is used when toggling sticky agendas."
  7511. (interactive)
  7512. (let (blist)
  7513. (dolist (buf (buffer-list))
  7514. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  7515. (push buf blist)))
  7516. (mapc #'kill-buffer blist)))
  7517. (defun org-agenda-execute (arg)
  7518. "Execute another agenda command, keeping same window.
  7519. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  7520. in the agenda."
  7521. (interactive "P")
  7522. (let ((org-agenda-window-setup 'current-window))
  7523. (org-agenda arg)))
  7524. (defun org-agenda-redo (&optional all)
  7525. "Rebuild possibly ALL agenda view(s) in the current buffer."
  7526. (interactive "P")
  7527. (defvar org-agenda-tag-filter-while-redo) ;FIXME: Where is this var used?
  7528. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  7529. (cpa (unless (eq all t) current-prefix-arg))
  7530. (org-agenda-doing-sticky-redo org-agenda-sticky)
  7531. (org-agenda-sticky nil)
  7532. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  7533. org-agenda-buffer-name))
  7534. (org-agenda-keep-modes t)
  7535. (tag-filter org-agenda-tag-filter)
  7536. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  7537. (top-hl-filter org-agenda-top-headline-filter)
  7538. (cat-filter org-agenda-category-filter)
  7539. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  7540. (re-filter org-agenda-regexp-filter)
  7541. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  7542. (effort-filter org-agenda-effort-filter)
  7543. (effort-preset (get 'org-agenda-effort-filter :preset-filter))
  7544. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  7545. (cols org-agenda-columns-active)
  7546. (line (org-current-line))
  7547. (window-line (- line (org-current-line (window-start))))
  7548. (lprops (get 'org-agenda-redo-command 'org-lprops))
  7549. (redo-cmd (get-text-property p 'org-redo-cmd))
  7550. (last-args (get-text-property p 'org-last-args))
  7551. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  7552. (org-agenda-overriding-cmd-arguments
  7553. (unless (eq all t)
  7554. (cond ((listp last-args)
  7555. (cons (or cpa (car last-args)) (cdr last-args)))
  7556. ((stringp last-args)
  7557. last-args))))
  7558. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  7559. (put 'org-agenda-tag-filter :preset-filter nil)
  7560. (put 'org-agenda-category-filter :preset-filter nil)
  7561. (put 'org-agenda-regexp-filter :preset-filter nil)
  7562. (put 'org-agenda-effort-filter :preset-filter nil)
  7563. (and cols (org-columns-quit))
  7564. (message "Rebuilding agenda buffer...")
  7565. (if series-redo-cmd
  7566. (eval series-redo-cmd t)
  7567. (cl-progv
  7568. (mapcar #'car lprops)
  7569. (mapcar (lambda (binding) (eval (cadr binding) t)) lprops)
  7570. (eval redo-cmd t)))
  7571. (setq org-agenda-undo-list nil
  7572. org-agenda-pending-undo-list nil
  7573. org-agenda-tag-filter tag-filter
  7574. org-agenda-category-filter cat-filter
  7575. org-agenda-regexp-filter re-filter
  7576. org-agenda-effort-filter effort-filter
  7577. org-agenda-top-headline-filter top-hl-filter)
  7578. (message "Rebuilding agenda buffer...done")
  7579. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  7580. (put 'org-agenda-category-filter :preset-filter cat-preset)
  7581. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  7582. (put 'org-agenda-effort-filter :preset-filter effort-preset)
  7583. (let ((tag (or tag-filter tag-preset))
  7584. (cat (or cat-filter cat-preset))
  7585. (effort (or effort-filter effort-preset))
  7586. (re (or re-filter re-preset)))
  7587. (when tag (org-agenda-filter-apply tag 'tag t))
  7588. (when cat (org-agenda-filter-apply cat 'category))
  7589. (when effort (org-agenda-filter-apply effort 'effort))
  7590. (when re (org-agenda-filter-apply re 'regexp)))
  7591. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  7592. (and cols (called-interactively-p 'any) (org-agenda-columns))
  7593. (org-goto-line line)
  7594. (when (called-interactively-p 'any) (recenter window-line))))
  7595. (defun org-agenda-redo-all (&optional exhaustive)
  7596. "Rebuild all agenda views in the current buffer.
  7597. With a prefix argument, do so in all agenda buffers."
  7598. (interactive "P")
  7599. (if exhaustive
  7600. (dolist (buffer (buffer-list))
  7601. (with-current-buffer buffer
  7602. (when (derived-mode-p 'org-agenda-mode)
  7603. (org-agenda-redo t))))
  7604. (org-agenda-redo t)))
  7605. (defvar org-global-tags-completion-table nil)
  7606. (defvar org-agenda-filter-form nil)
  7607. (defvar org-agenda-filtered-by-category nil)
  7608. (defsubst org-agenda-get-category ()
  7609. "Return the category of the agenda line."
  7610. (org-get-at-bol 'org-category))
  7611. (defun org-agenda-filter-by-category (strip)
  7612. "Filter lines in the agenda buffer that have a specific category.
  7613. The category is that of the current line.
  7614. With a `\\[universal-argument]' prefix argument, exclude the lines of that category.
  7615. When there is already a category filter in place, this command removes the
  7616. filter."
  7617. (interactive "P")
  7618. (if (and org-agenda-filtered-by-category
  7619. org-agenda-category-filter)
  7620. (org-agenda-filter-show-all-cat)
  7621. (let ((cat (org-no-properties (org-get-at-eol 'org-category 1))))
  7622. (cond
  7623. ((and cat strip)
  7624. (org-agenda-filter-apply
  7625. (push (concat "-" cat) org-agenda-category-filter) 'category))
  7626. (cat
  7627. (org-agenda-filter-apply
  7628. (setq org-agenda-category-filter
  7629. (list (concat "+" cat)))
  7630. 'category))
  7631. (t (error "No category at point"))))))
  7632. (defun org-find-top-headline (&optional pos)
  7633. "Find the topmost parent headline and return it.
  7634. POS when non-nil is the marker or buffer position to start the
  7635. search from."
  7636. (save-excursion
  7637. (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
  7638. (when pos (goto-char pos))
  7639. ;; Skip up to the topmost parent.
  7640. (while (org-up-heading-safe))
  7641. (ignore-errors
  7642. (replace-regexp-in-string
  7643. "^\\[[0-9]+/[0-9]+\\] *\\|^\\[%[0-9]+\\] *" ""
  7644. (nth 4 (org-heading-components)))))))
  7645. (defvar org-agenda-filtered-by-top-headline nil)
  7646. (defun org-agenda-filter-by-top-headline (strip)
  7647. "Keep only those lines that are descendants from the same top headline.
  7648. The top headline is that of the current line. With prefix arg STRIP, hide
  7649. all lines of the category at point."
  7650. (interactive "P")
  7651. (if org-agenda-filtered-by-top-headline
  7652. (progn
  7653. (setq org-agenda-filtered-by-top-headline nil
  7654. org-agenda-top-headline-filter nil)
  7655. (org-agenda-filter-show-all-top-filter))
  7656. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  7657. (if toph (org-agenda-filter-top-headline-apply toph strip)
  7658. (error "No top-level headline at point")))))
  7659. (defvar org-agenda-regexp-filter nil)
  7660. (defun org-agenda-filter-by-regexp (strip-or-accumulate)
  7661. "Filter agenda entries by a regular expressions.
  7662. You will be prompted for the regular expression, and the agenda
  7663. view will only show entries that are matched by that expression.
  7664. With one `\\[universal-argument]' prefix argument, hide entries matching the regexp.
  7665. When there is already a regexp filter active, this command removed the
  7666. filter. However, with two `\\[universal-argument]' prefix arguments, add a new condition to
  7667. an already existing regexp filter."
  7668. (interactive "P")
  7669. (let* ((strip (equal strip-or-accumulate '(4)))
  7670. (accumulate (equal strip-or-accumulate '(16))))
  7671. (cond
  7672. ((and org-agenda-regexp-filter (not accumulate))
  7673. (org-agenda-filter-show-all-re)
  7674. (message "Regexp filter removed"))
  7675. (t (let ((flt (concat (if strip "-" "+")
  7676. (read-from-minibuffer
  7677. (if strip
  7678. "Hide entries matching regexp: "
  7679. "Narrow to entries matching regexp: ")))))
  7680. (push flt org-agenda-regexp-filter)
  7681. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))))))
  7682. (defvar org-agenda-effort-filter nil)
  7683. (defun org-agenda-filter-by-effort (strip-or-accumulate)
  7684. "Filter agenda entries by effort.
  7685. With no `\\[universal-argument]' prefix argument, keep entries matching the effort condition.
  7686. With one `\\[universal-argument]' prefix argument, filter out entries matching the condition.
  7687. With two `\\[universal-argument]' prefix arguments, add a second condition to the existing filter.
  7688. This last option is in practice not very useful, but it is available for
  7689. consistency with the other filter commands."
  7690. (interactive "P")
  7691. (let* ((efforts (split-string
  7692. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7693. org-global-properties
  7694. t))
  7695. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")))
  7696. ;; XXX: the following handles only up to 10 different
  7697. ;; effort values.
  7698. (allowed-keys (if (null efforts) nil
  7699. (mapcar (lambda (n) (mod n 10)) ;turn 10 into 0
  7700. (number-sequence 1 (length efforts)))))
  7701. (keep (equal strip-or-accumulate '(16)))
  7702. (negative (equal strip-or-accumulate '(4)))
  7703. (current org-agenda-effort-filter)
  7704. (op nil))
  7705. (while (not (memq op '(?< ?> ?= ?_)))
  7706. (setq op (read-char-exclusive
  7707. "Effort operator? (> = or <) or press `_' again to remove filter")))
  7708. ;; Select appropriate duration. Ignore non-digit characters.
  7709. (if (eq op ?_)
  7710. (progn
  7711. (org-agenda-filter-show-all-effort)
  7712. (message "Effort filter removed"))
  7713. (let ((prompt
  7714. (apply #'format
  7715. (concat "Effort %c "
  7716. (mapconcat (lambda (s) (concat "[%d]" s))
  7717. efforts
  7718. " "))
  7719. op allowed-keys))
  7720. (eff -1))
  7721. (while (not (memq eff allowed-keys))
  7722. (message prompt)
  7723. (setq eff (- (read-char-exclusive) 48)))
  7724. (org-agenda-filter-show-all-effort)
  7725. (setq org-agenda-effort-filter
  7726. (append
  7727. (list (concat (if negative "-" "+")
  7728. (char-to-string op)
  7729. ;; Numbering is 1 2 3 ... 9 0, but we want
  7730. ;; 0 1 2 ... 8 9.
  7731. (nth (mod (1- eff) 10) efforts)))
  7732. (if keep current nil)))
  7733. (org-agenda-filter-apply org-agenda-effort-filter 'effort)))))
  7734. (defun org-agenda-filter (&optional strip-or-accumulate)
  7735. "Prompt for a general filter string and apply it to the agenda.
  7736. The string may contain filter elements like
  7737. +category
  7738. +tag
  7739. +<effort > and = are also allowed as effort operators
  7740. +/regexp/
  7741. Instead of `+', `-' is allowed to strip the agenda of matching entries.
  7742. `+' is optional if it is not required to separate two string parts.
  7743. Multiple filter elements can be concatenated without spaces, for example
  7744. +work-John<0:10-/plot/
  7745. selects entries with category `work' and effort estimates below 10 minutes,
  7746. and deselects entries with tag `John' or matching the regexp `plot'.
  7747. During entry of the filter, completion for tags, categories and effort
  7748. values is offered. Since the syntax for categories and tags is identical
  7749. there should be no overlap between categories and tags. If there is, tags
  7750. get priority.
  7751. A single `\\[universal-argument]' prefix arg STRIP-OR-ACCUMULATE will negate the
  7752. entire filter, which can be useful in connection with the prompt history.
  7753. A double `\\[universal-argument] \\[universal-argument]' prefix arg will add the new filter elements to the
  7754. existing ones. A shortcut for this is to add an additional `+' at the
  7755. beginning of the string, like `+-John'.
  7756. With a triple prefix argument, execute the computed filtering defined in
  7757. the variable `org-agenda-auto-exclude-function'."
  7758. (interactive "P")
  7759. (if (equal strip-or-accumulate '(64))
  7760. ;; Execute the auto-exclude action
  7761. (if (not org-agenda-auto-exclude-function)
  7762. (user-error "`org-agenda-auto-exclude-function' is undefined")
  7763. (org-agenda-filter-show-all-tag)
  7764. (setq org-agenda-tag-filter nil)
  7765. (dolist (tag (org-agenda-get-represented-tags))
  7766. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7767. (when modifier
  7768. (push modifier org-agenda-tag-filter))))
  7769. (unless (null org-agenda-tag-filter)
  7770. (org-agenda-filter-apply org-agenda-tag-filter 'tag 'expand)))
  7771. ;; Prompt for a filter and act
  7772. (let* ((tag-list (org-agenda-get-represented-tags))
  7773. (category-list (org-agenda-get-represented-categories))
  7774. (negate (equal strip-or-accumulate '(4)))
  7775. (cf (mapconcat #'identity org-agenda-category-filter ""))
  7776. (tf (mapconcat #'identity org-agenda-tag-filter ""))
  7777. ;; (rpl-fn (lambda (c) (replace-regexp-in-string "^\\+" "" (or (car c) ""))))
  7778. (ef (replace-regexp-in-string "^\\+" "" (or (car org-agenda-effort-filter) "")))
  7779. (rf (replace-regexp-in-string "^\\+" "" (or (car org-agenda-regexp-filter) "")))
  7780. (ff (concat cf tf ef (when (not (equal rf "")) (concat "/" rf "/"))))
  7781. (f-string (completing-read
  7782. (concat
  7783. (if negate "Negative filter" "Filter")
  7784. " [+cat-tag<0:10-/regexp/]: ")
  7785. #'org-agenda-filter-completion-function
  7786. nil nil ff))
  7787. (keep (or (if (string-match "^\\+[+-]" f-string)
  7788. (progn (setq f-string (substring f-string 1)) t))
  7789. (equal strip-or-accumulate '(16))))
  7790. (fc (if keep org-agenda-category-filter))
  7791. (ft (if keep org-agenda-tag-filter))
  7792. (fe (if keep org-agenda-effort-filter))
  7793. (fr (if keep org-agenda-regexp-filter))
  7794. pm s)
  7795. ;; If the filter contains a double-quoted string, replace a
  7796. ;; single hyphen by the arbitrary and temporary string "~~~"
  7797. ;; to disambiguate such hyphens from syntactic ones.
  7798. (setq f-string (replace-regexp-in-string
  7799. "\"\\([^\"]*\\)-\\([^\"]*\\)\"" "\"\\1~~~\\2\"" f-string))
  7800. (while (string-match "^[ \t]*\\([-+]\\)?\\(\\([^-+<>=/ \t]+\\)\\|\\([<>=][0-9:]+\\)\\|\\(/\\([^/]+\\)/?\\)\\)" f-string)
  7801. (setq pm (if (match-beginning 1) (match-string 1 f-string) "+"))
  7802. (when negate
  7803. (setq pm (if (equal pm "+") "-" "+")))
  7804. (cond
  7805. ((match-beginning 3)
  7806. ;; category or tag
  7807. (setq s (replace-regexp-in-string ; Remove the temporary special string.
  7808. "~~~" "-" (match-string 3 f-string)))
  7809. (cond
  7810. ((member s tag-list)
  7811. (org-pushnew-to-end (concat pm s) ft))
  7812. ((member s category-list)
  7813. (org-pushnew-to-end (concat pm ; Remove temporary double quotes.
  7814. (replace-regexp-in-string "\"\\(.*\\)\"" "\\1" s))
  7815. fc))
  7816. (t (message
  7817. "`%s%s' filter ignored because tag/category is not represented"
  7818. pm s))))
  7819. ((match-beginning 4)
  7820. ;; effort
  7821. (org-pushnew-to-end (concat pm (match-string 4 f-string)) fe))
  7822. ((match-beginning 5)
  7823. ;; regexp
  7824. (org-pushnew-to-end (concat pm (match-string 6 f-string)) fr)))
  7825. (setq f-string (substring f-string (match-end 0))))
  7826. (org-agenda-filter-remove-all)
  7827. (and fc (org-agenda-filter-apply
  7828. (setq org-agenda-category-filter fc) 'category))
  7829. (and ft (org-agenda-filter-apply
  7830. (setq org-agenda-tag-filter ft) 'tag 'expand))
  7831. (and fe (org-agenda-filter-apply
  7832. (setq org-agenda-effort-filter fe) 'effort))
  7833. (and fr (org-agenda-filter-apply
  7834. (setq org-agenda-regexp-filter fr) 'regexp))
  7835. (run-hooks 'org-agenda-filter-hook))))
  7836. (defun org-agenda-filter-completion-function (string _predicate &optional flag)
  7837. "Complete a complex filter string.
  7838. FLAG specifies the type of completion operation to perform. This
  7839. function is passed as a collection function to `completing-read',
  7840. which see."
  7841. (let ((completion-ignore-case t) ;tags are case-sensitive
  7842. (confirm (lambda (x) (stringp x)))
  7843. (prefix "")
  7844. (operator "")
  7845. table)
  7846. (when (string-match "^\\(.*\\([-+<>=]\\)\\)\\([^-+<>=]*\\)$" string)
  7847. (setq prefix (match-string 1 string)
  7848. operator (match-string 2 string)
  7849. string (match-string 3 string)))
  7850. (cond
  7851. ((member operator '("+" "-" "" nil))
  7852. (setq table (append (org-agenda-get-represented-categories)
  7853. (org-agenda-get-represented-tags))))
  7854. ((member operator '("<" ">" "="))
  7855. (setq table (split-string
  7856. (or (cdr (assoc-string (concat org-effort-property "_ALL")
  7857. org-global-properties
  7858. t))
  7859. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00")
  7860. " +")))
  7861. (t (setq table nil)))
  7862. (pcase flag
  7863. (`t (all-completions string table confirm))
  7864. (`lambda (assoc string table)) ;exact match?
  7865. (`nil
  7866. (pcase (try-completion string table confirm)
  7867. ((and completion (pred stringp))
  7868. (concat prefix completion))
  7869. (completion completion)))
  7870. (_ nil))))
  7871. (defun org-agenda-filter-remove-all ()
  7872. "Remove all filters from the current agenda buffer."
  7873. (interactive)
  7874. (when org-agenda-tag-filter
  7875. (org-agenda-filter-show-all-tag))
  7876. (when org-agenda-category-filter
  7877. (org-agenda-filter-show-all-cat))
  7878. (when org-agenda-regexp-filter
  7879. (org-agenda-filter-show-all-re))
  7880. (when org-agenda-top-headline-filter
  7881. (org-agenda-filter-show-all-top-filter))
  7882. (when org-agenda-effort-filter
  7883. (org-agenda-filter-show-all-effort))
  7884. (org-agenda-finalize)
  7885. (when (called-interactively-p 'interactive)
  7886. (message "All agenda filters removed")))
  7887. (defun org-agenda-filter-by-tag (strip-or-accumulate &optional char exclude)
  7888. "Keep only those lines in the agenda buffer that have a specific tag.
  7889. The tag is selected with its fast selection letter, as configured.
  7890. With a `\\[universal-argument]' prefix, apply the filter negatively, stripping all matches.
  7891. With a `\\[universal-argument] \\[universal-argument]' prefix, add the new tag to the existing filter
  7892. instead of replacing it.
  7893. With a `\\[universal-argument] \\[universal-argument] \\[universal-argument]' prefix, filter the literal tag, \
  7894. i.e. don't
  7895. filter on all its group members.
  7896. A Lisp caller can specify CHAR. EXCLUDE means that the new tag
  7897. should be used to exclude the search - the interactive user can
  7898. also press `-' or `+' to switch between filtering and excluding."
  7899. (interactive "P")
  7900. (let* ((alist org-tag-alist-for-agenda)
  7901. (seen-chars nil)
  7902. (tag-chars (mapconcat
  7903. (lambda (x) (if (and (not (symbolp (car x)))
  7904. (cdr x)
  7905. (not (member (cdr x) seen-chars)))
  7906. (progn
  7907. (push (cdr x) seen-chars)
  7908. (char-to-string (cdr x)))
  7909. ""))
  7910. org-tag-alist-for-agenda ""))
  7911. (valid-char-list (append '(?\t ?\r ?\\ ?. ?\s ?q)
  7912. (string-to-list tag-chars)))
  7913. (exclude (or exclude (equal strip-or-accumulate '(4))))
  7914. (accumulate (equal strip-or-accumulate '(16)))
  7915. (expand (not (equal strip-or-accumulate '(64))))
  7916. (inhibit-read-only t)
  7917. (current org-agenda-tag-filter)
  7918. a tag) ;; n
  7919. (unless char
  7920. (while (not (memq char valid-char-list))
  7921. (org-unlogged-message
  7922. "%s by tag%s: [%s ]tag-char [TAB]tag %s[\\]off [q]uit"
  7923. (if exclude "Exclude[+]" "Filter[-]")
  7924. (if expand "" " (no grouptag expand)")
  7925. tag-chars
  7926. (if org-agenda-auto-exclude-function "[RET] " ""))
  7927. (setq char (read-char-exclusive))
  7928. ;; Excluding or filtering down
  7929. (cond ((eq char ?-) (setq exclude t))
  7930. ((eq char ?+) (setq exclude nil)))))
  7931. (when (eq char ?\t)
  7932. (unless (local-variable-p 'org-global-tags-completion-table)
  7933. (setq-local org-global-tags-completion-table
  7934. (org-global-tags-completion-table)))
  7935. (let ((completion-ignore-case t))
  7936. (setq tag (completing-read
  7937. "Tag: " org-global-tags-completion-table nil t))))
  7938. (cond
  7939. ((eq char ?\r)
  7940. (org-agenda-filter-show-all-tag)
  7941. (when org-agenda-auto-exclude-function
  7942. (setq org-agenda-tag-filter nil)
  7943. (dolist (tag (org-agenda-get-represented-tags))
  7944. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  7945. (when modifier
  7946. (push modifier org-agenda-tag-filter))))
  7947. (unless (null org-agenda-tag-filter)
  7948. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))))
  7949. ((eq char ?\\)
  7950. (org-agenda-filter-show-all-tag)
  7951. (when (get 'org-agenda-tag-filter :preset-filter)
  7952. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand)))
  7953. ((eq char ?.)
  7954. (setq org-agenda-tag-filter
  7955. (mapcar (lambda(tag) (concat "+" tag))
  7956. (org-get-at-bol 'tags)))
  7957. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7958. ((eq char ?q)) ;If q, abort (even if there is a q-key for a tag...)
  7959. ((or (eq char ?\s)
  7960. (setq a (rassoc char alist))
  7961. (and tag (setq a (cons tag nil))))
  7962. (org-agenda-filter-show-all-tag)
  7963. (setq tag (car a))
  7964. (setq org-agenda-tag-filter
  7965. (cons (concat (if exclude "-" "+") tag)
  7966. (if accumulate current nil)))
  7967. (org-agenda-filter-apply org-agenda-tag-filter 'tag expand))
  7968. (t (error "Invalid tag selection character %c" char)))))
  7969. (defun org-agenda-get-represented-categories ()
  7970. "Return a list of all categories used in this agenda buffer."
  7971. (or org-agenda-represented-categories
  7972. (when (derived-mode-p 'org-agenda-mode)
  7973. (let ((pos (point-min)) categories)
  7974. (while (and (< pos (point-max))
  7975. (setq pos (next-single-property-change
  7976. pos 'org-category nil (point-max))))
  7977. (push (get-text-property pos 'org-category) categories))
  7978. (setq org-agenda-represented-categories
  7979. ;; Enclose category names with a hyphen in double
  7980. ;; quotes to process them specially in `org-agenda-filter'.
  7981. (mapcar (lambda (s) (if (string-match-p "-" s) (format "\"%s\"" s) s))
  7982. (nreverse (org-uniquify (delq nil categories)))))))))
  7983. (defvar org-tag-groups-alist-for-agenda)
  7984. (defun org-agenda-get-represented-tags ()
  7985. "Return a list of all tags used in this agenda buffer.
  7986. These will be lower-case, for filtering."
  7987. (or org-agenda-represented-tags
  7988. (when (derived-mode-p 'org-agenda-mode)
  7989. (let ((pos (point-min)) tags-lists tt)
  7990. (while (and (< pos (point-max))
  7991. (setq pos (next-single-property-change
  7992. pos 'tags nil (point-max))))
  7993. (setq tt (get-text-property pos 'tags))
  7994. (if tt (push tt tags-lists)))
  7995. (setq tags-lists
  7996. (nreverse (org-uniquify
  7997. (delq nil (apply #'append tags-lists)))))
  7998. (dolist (tag tags-lists)
  7999. (mapc
  8000. (lambda (group)
  8001. (when (member tag group)
  8002. (push (car group) tags-lists)))
  8003. org-tag-groups-alist-for-agenda))
  8004. (setq org-agenda-represented-tags tags-lists)))))
  8005. (defun org-agenda-filter-make-matcher (filter type &optional expand)
  8006. "Create the form that tests a line for agenda filter.
  8007. Optional argument EXPAND can be used for the TYPE tag and will
  8008. expand the tags in the FILTER if any of the tags in FILTER are
  8009. grouptags."
  8010. (let ((multi-pos-cats
  8011. (and (eq type 'category)
  8012. (string-match-p "\\+.*\\+"
  8013. (mapconcat (lambda (cat) (substring cat 0 1))
  8014. filter ""))))
  8015. f f1)
  8016. (cond
  8017. ;; Tag filter
  8018. ((eq type 'tag)
  8019. (setq filter
  8020. (delete-dups
  8021. (append (get 'org-agenda-tag-filter :preset-filter)
  8022. filter)))
  8023. (dolist (x filter)
  8024. (let ((op (string-to-char x)))
  8025. (if expand (setq x (org-agenda-filter-expand-tags (list x) t))
  8026. (setq x (list x)))
  8027. (setq f1 (org-agenda-filter-make-matcher-tag-exp x op))
  8028. (push f1 f))))
  8029. ;; Category filter
  8030. ((eq type 'category)
  8031. (setq filter
  8032. (delete-dups
  8033. (append (get 'org-agenda-category-filter :preset-filter)
  8034. filter)))
  8035. (dolist (x filter)
  8036. (if (equal "-" (substring x 0 1))
  8037. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  8038. (setq f1 (list 'equal (substring x 1) 'cat)))
  8039. (push f1 f)))
  8040. ;; Regexp filter
  8041. ((eq type 'regexp)
  8042. (setq filter
  8043. (delete-dups
  8044. (append (get 'org-agenda-regexp-filter :preset-filter)
  8045. filter)))
  8046. (dolist (x filter)
  8047. (if (equal "-" (substring x 0 1))
  8048. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  8049. (setq f1 (list 'string-match (substring x 1) 'txt)))
  8050. (push f1 f)))
  8051. ;; Effort filter
  8052. ((eq type 'effort)
  8053. (setq filter
  8054. (delete-dups
  8055. (append (get 'org-agenda-effort-filter :preset-filter)
  8056. filter)))
  8057. (dolist (x filter)
  8058. (push (org-agenda-filter-effort-form x) f))))
  8059. (cons (if multi-pos-cats 'or 'and) (nreverse f))))
  8060. (defun org-agenda-filter-make-matcher-tag-exp (tags op)
  8061. "Return a form associated to tag-expression TAGS.
  8062. Build a form testing a line for agenda filter for
  8063. tag-expressions. OP is an operator of type CHAR that allows the
  8064. function to set the right switches in the returned form."
  8065. (let (form)
  8066. ;; Any of the expressions can match if OP is +, all must match if
  8067. ;; the operator is -.
  8068. (dolist (x tags (cons (if (eq op ?-) 'and 'or) form))
  8069. (let* ((tag (substring x 1))
  8070. (f (cond
  8071. ((string= "" tag) 'tags)
  8072. ((and (string-match-p "\\`{" tag) (string-match-p "}\\'" tag))
  8073. ;; TAG is a regexp.
  8074. (list 'org-match-any-p (substring tag 1 -1) 'tags))
  8075. (t (list 'member tag 'tags)))))
  8076. (push (if (eq op ?-) (list 'not f) f) form)))))
  8077. (defun org-agenda-filter-effort-form (e)
  8078. "Return the form to compare the effort of the current line with what E says.
  8079. E looks like \"+<2:25\"."
  8080. (let (op)
  8081. (setq e (substring e 1))
  8082. (setq op (string-to-char e) e (substring e 1))
  8083. (setq op (cond ((equal op ?<) '<=)
  8084. ((equal op ?>) '>=)
  8085. ((equal op ??) op)
  8086. (t '=)))
  8087. (list 'org-agenda-compare-effort (list 'quote op)
  8088. (org-duration-to-minutes e))))
  8089. (defun org-agenda-compare-effort (op value)
  8090. "Compare the effort of the current line with VALUE, using OP.
  8091. If the line does not have an effort defined, return nil."
  8092. ;; `effort-minutes' property cannot be extracted directly from
  8093. ;; current line but is stored as a property in `txt'.
  8094. (let ((effort (get-text-property 0 'effort-minutes (org-get-at-bol 'txt))))
  8095. (funcall op
  8096. (or effort (if org-agenda-sort-noeffort-is-high 32767 -1))
  8097. value)))
  8098. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  8099. "Expand group tags in FILTER for the agenda.
  8100. When NO-OPERATOR is non-nil, do not add the + operator to
  8101. returned tags."
  8102. (if org-group-tags
  8103. (let (case-fold-search rtn)
  8104. (mapc
  8105. (lambda (f)
  8106. (let (f0 dir)
  8107. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  8108. (setq dir (match-string 1 f) f0 (match-string 2 f))
  8109. (setq dir (if no-operator "" "+") f0 f))
  8110. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  8111. (org-tags-expand f0 t))
  8112. rtn))))
  8113. filter)
  8114. (reverse rtn))
  8115. filter))
  8116. (defun org-agenda-filter-apply (filter type &optional expand)
  8117. "Set FILTER as the new agenda filter and apply it.
  8118. Optional argument EXPAND can be used for the TYPE tag and will
  8119. expand the tags in the FILTER if any of the tags in FILTER are
  8120. grouptags."
  8121. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  8122. (when org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  8123. (setq org-agenda-filter-form (org-agenda-filter-make-matcher
  8124. filter type expand))
  8125. ;; Only set `org-agenda-filtered-by-category' to t when a unique
  8126. ;; category is used as the filter:
  8127. (setq org-agenda-filtered-by-category
  8128. (and (eq type 'category)
  8129. (not (equal (substring (car filter) 0 1) "-"))))
  8130. (org-agenda-set-mode-name)
  8131. (save-excursion
  8132. (goto-char (point-min))
  8133. (while (not (eobp))
  8134. (when (or (org-get-at-bol 'org-hd-marker)
  8135. (org-get-at-bol 'org-marker))
  8136. (org-dlet
  8137. ((tags (org-get-at-bol 'tags))
  8138. (cat (org-agenda-get-category))
  8139. (txt (or (org-get-at-bol 'txt) "")))
  8140. (unless (eval org-agenda-filter-form t)
  8141. (org-agenda-filter-hide-line type))))
  8142. (beginning-of-line 2)))
  8143. (when (get-char-property (point) 'invisible)
  8144. (ignore-errors (org-agenda-previous-line))))
  8145. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  8146. "Filter by top headline HL."
  8147. (org-agenda-set-mode-name)
  8148. (save-excursion
  8149. (goto-char (point-min))
  8150. (while (not (eobp))
  8151. (let* ((pos (org-get-at-bol 'org-hd-marker))
  8152. (tophl (and pos (org-find-top-headline pos))))
  8153. (when (and tophl (funcall (if negative 'identity 'not)
  8154. (string= hl tophl)))
  8155. (org-agenda-filter-hide-line 'top-headline)))
  8156. (beginning-of-line 2)))
  8157. (when (get-char-property (point) 'invisible)
  8158. (org-agenda-previous-line))
  8159. (setq org-agenda-top-headline-filter hl
  8160. org-agenda-filtered-by-top-headline t))
  8161. (defun org-agenda-filter-hide-line (type)
  8162. "If current line is TYPE, hide it in the agenda buffer."
  8163. (let* (buffer-invisibility-spec
  8164. (beg (max (point-min) (1- (point-at-bol))))
  8165. (end (point-at-eol)))
  8166. (let ((inhibit-read-only t))
  8167. (add-text-properties
  8168. beg end `(invisible org-filtered org-filter-type ,type)))))
  8169. (defun org-agenda-remove-filter (type)
  8170. "Remove filter of type TYPE from the agenda buffer."
  8171. (interactive)
  8172. (save-excursion
  8173. (goto-char (point-min))
  8174. (let ((inhibit-read-only t) pos)
  8175. (while (setq pos (text-property-any (point) (point-max)
  8176. 'org-filter-type type))
  8177. (goto-char pos)
  8178. (remove-text-properties
  8179. (point) (next-single-property-change (point) 'org-filter-type)
  8180. `(invisible org-filtered org-filter-type ,type))))
  8181. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  8182. (setq org-agenda-filter-form nil)
  8183. (org-agenda-set-mode-name)
  8184. (org-agenda-finalize)))
  8185. (defun org-agenda-filter-show-all-tag nil
  8186. (org-agenda-remove-filter 'tag))
  8187. (defun org-agenda-filter-show-all-re nil
  8188. (org-agenda-remove-filter 'regexp))
  8189. (defun org-agenda-filter-show-all-effort nil
  8190. (org-agenda-remove-filter 'effort))
  8191. (defun org-agenda-filter-show-all-cat nil
  8192. (org-agenda-remove-filter 'category))
  8193. (defun org-agenda-filter-show-all-top-filter nil
  8194. (org-agenda-remove-filter 'top-headline))
  8195. (defun org-agenda-manipulate-query-add ()
  8196. "Manipulate the query by adding a search term with positive selection.
  8197. Positive selection means the term must be matched for selection of an entry."
  8198. (interactive)
  8199. (org-agenda-manipulate-query ?\[))
  8200. (defun org-agenda-manipulate-query-subtract ()
  8201. "Manipulate the query by adding a search term with negative selection.
  8202. Negative selection means term must not be matched for selection of an entry."
  8203. (interactive)
  8204. (org-agenda-manipulate-query ?\]))
  8205. (defun org-agenda-manipulate-query-add-re ()
  8206. "Manipulate the query by adding a search regexp with positive selection.
  8207. Positive selection means the regexp must match for selection of an entry."
  8208. (interactive)
  8209. (org-agenda-manipulate-query ?\{))
  8210. (defun org-agenda-manipulate-query-subtract-re ()
  8211. "Manipulate the query by adding a search regexp with negative selection.
  8212. Negative selection means regexp must not match for selection of an entry."
  8213. (interactive)
  8214. (org-agenda-manipulate-query ?\}))
  8215. (defun org-agenda-manipulate-query (char)
  8216. (cond
  8217. ((eq org-agenda-type 'agenda)
  8218. (let ((org-agenda-include-inactive-timestamps t))
  8219. (org-agenda-redo))
  8220. (message "Display now includes inactive timestamps as well"))
  8221. ((eq org-agenda-type 'search)
  8222. (org-add-to-string
  8223. 'org-agenda-query-string
  8224. (if org-agenda-last-search-view-search-was-boolean
  8225. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  8226. (?\{ . " +{}") (?\} . " -{}"))))
  8227. " "))
  8228. (setq org-agenda-redo-command
  8229. (list 'org-search-view
  8230. (car (get-text-property (min (1- (point-max)) (point))
  8231. 'org-last-args))
  8232. org-agenda-query-string
  8233. (+ (length org-agenda-query-string)
  8234. (if (member char '(?\{ ?\})) 0 1))))
  8235. (set-register org-agenda-query-register org-agenda-query-string)
  8236. (let ((org-agenda-overriding-arguments
  8237. (cdr org-agenda-redo-command)))
  8238. (org-agenda-redo)))
  8239. (t (error "Cannot manipulate query for %s-type agenda buffers"
  8240. org-agenda-type))))
  8241. (defun org-add-to-string (var string)
  8242. (set var (concat (symbol-value var) string)))
  8243. (defun org-agenda-goto-date (date)
  8244. "Jump to DATE in the agenda buffer.
  8245. When called interactively, prompt for the date.
  8246. When called from Lisp, DATE should be a date as returned by
  8247. `org-read-date'.
  8248. See also:
  8249. `org-agenda-earlier' (\\[org-agenda-earlier])
  8250. `org-agenda-later' (\\[org-agenda-later])
  8251. `org-agenda-goto-today' (\\[org-agenda-goto-today])"
  8252. (interactive
  8253. (list
  8254. (let ((org-read-date-prefer-future org-agenda-jump-prefer-future))
  8255. (org-read-date))))
  8256. (let* ((day (time-to-days (org-time-string-to-time date)))
  8257. (org-agenda-sticky-orig org-agenda-sticky)
  8258. (org-agenda-buffer-tmp-name (buffer-name))
  8259. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8260. (0-arg (or current-prefix-arg (car args)))
  8261. (2-arg (nth 2 args))
  8262. (with-hour-p (nth 4 org-agenda-redo-command))
  8263. (newcmd (list 'org-agenda-list 0-arg date
  8264. (org-agenda-span-to-ndays
  8265. 2-arg (org-time-string-to-absolute date))
  8266. with-hour-p))
  8267. (newargs (cdr newcmd))
  8268. (inhibit-read-only t)
  8269. org-agenda-sticky)
  8270. (if (not (org-agenda-check-type t 'agenda))
  8271. (error "Not available in non-agenda views")
  8272. (add-text-properties (point-min) (point-max)
  8273. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  8274. (org-agenda-redo)
  8275. (goto-char (point-min))
  8276. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  8277. (save-excursion (move-beginning-of-line 2) (eobp))))
  8278. (move-beginning-of-line 2))
  8279. (setq org-agenda-sticky org-agenda-sticky-orig
  8280. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  8281. (defun org-agenda-goto-today ()
  8282. "Go to today's date in the agenda buffer.
  8283. See also:
  8284. `org-agenda-later' (\\[org-agenda-later])
  8285. `org-agenda-earlier' (\\[org-agenda-earlier])
  8286. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8287. (interactive)
  8288. (org-agenda-check-type t 'agenda)
  8289. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8290. (curspan (nth 2 args))
  8291. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  8292. (cond
  8293. (tdpos (goto-char tdpos))
  8294. ((eq org-agenda-type 'agenda)
  8295. (let* ((sd (org-agenda-compute-starting-span
  8296. (org-today) (or curspan org-agenda-span)))
  8297. (org-agenda-overriding-arguments args))
  8298. (setf (nth 1 org-agenda-overriding-arguments) sd)
  8299. (org-agenda-redo)
  8300. (org-agenda-find-same-or-today-or-agenda)))
  8301. (t (error "Cannot find today")))))
  8302. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  8303. (goto-char
  8304. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  8305. (text-property-any (point-min) (point-max) 'org-today t)
  8306. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  8307. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  8308. (org-agenda-backward-block))
  8309. (point-min))))
  8310. (defun org-agenda-backward-block ()
  8311. "Move backward by one agenda block."
  8312. (interactive)
  8313. (org-agenda-forward-block 'backward))
  8314. (defun org-agenda-forward-block (&optional backward)
  8315. "Move forward by one agenda block.
  8316. When optional argument BACKWARD is set, go backward."
  8317. (interactive)
  8318. (cond ((not (derived-mode-p 'org-agenda-mode))
  8319. (user-error
  8320. "Cannot execute this command outside of org-agenda-mode buffers"))
  8321. ((looking-at (if backward "\\`" "\\'"))
  8322. (message "Already at the %s block" (if backward "first" "last")))
  8323. (t (let ((_pos (prog1 (point)
  8324. (ignore-errors (if backward (backward-char 1)
  8325. (move-end-of-line 1)))))
  8326. (f (if backward
  8327. #'previous-single-property-change
  8328. #'next-single-property-change))
  8329. moved dest)
  8330. (while (and (setq dest (funcall
  8331. f (point) 'org-agenda-structural-header))
  8332. (not (get-text-property
  8333. (point) 'org-agenda-structural-header)))
  8334. (setq moved t)
  8335. (goto-char dest))
  8336. (if moved (move-beginning-of-line 1)
  8337. (goto-char (if backward (point-min) (point-max)))
  8338. (move-beginning-of-line 1)
  8339. (message "No %s block" (if backward "previous" "further")))))))
  8340. (defun org-agenda-later (arg)
  8341. "Go forward in time by the current span in the agenda buffer.
  8342. With prefix ARG, go forward that many times the current span.
  8343. See also:
  8344. `org-agenda-earlier' (\\[org-agenda-earlier])
  8345. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8346. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8347. (interactive "p")
  8348. (org-agenda-check-type t 'agenda)
  8349. (let* ((wstart (window-start))
  8350. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8351. (span (or (nth 2 args) org-agenda-current-span))
  8352. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  8353. (greg (calendar-gregorian-from-absolute sd))
  8354. (cnt (org-get-at-bol 'org-day-cnt))
  8355. greg2)
  8356. (cond
  8357. ((numberp span)
  8358. (setq sd (+ (* span arg) sd)))
  8359. ((eq span 'day)
  8360. (setq sd (+ arg sd)))
  8361. ((eq span 'week)
  8362. (setq sd (+ (* 7 arg) sd)))
  8363. ((eq span 'fortnight)
  8364. (setq sd (+ (* 14 arg) sd)))
  8365. ((eq span 'month)
  8366. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  8367. sd (calendar-absolute-from-gregorian greg2))
  8368. (setcar greg2 (1+ (car greg2))))
  8369. ((eq span 'year)
  8370. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  8371. sd (calendar-absolute-from-gregorian greg2))
  8372. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  8373. (t
  8374. (setq sd (+ (* span arg) sd))))
  8375. (let ((org-agenda-overriding-cmd
  8376. ;; `cmd' may have been set by `org-agenda-run-series' which
  8377. ;; uses `org-agenda-overriding-cmd' to decide whether
  8378. ;; overriding is allowed for `cmd'
  8379. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8380. (org-agenda-overriding-arguments
  8381. (list (car args) sd span)))
  8382. (org-agenda-redo)
  8383. (org-agenda-find-same-or-today-or-agenda cnt))
  8384. (set-window-start nil wstart)))
  8385. (defun org-agenda-earlier (arg)
  8386. "Go backward in time by the current span in the agenda buffer.
  8387. With prefix ARG, go backward that many times the current span.
  8388. See also:
  8389. `org-agenda-later' (\\[org-agenda-later])
  8390. `org-agenda-goto-today' (\\[org-agenda-goto-today])
  8391. `org-agenda-goto-date' (\\[org-agenda-goto-date])"
  8392. (interactive "p")
  8393. (org-agenda-later (- arg)))
  8394. (defun org-agenda-view-mode-dispatch ()
  8395. "Call one of the view mode commands."
  8396. (interactive)
  8397. (org-unlogged-message
  8398. "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  8399. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  8400. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  8401. (pcase (read-char-exclusive)
  8402. (?\ (call-interactively 'org-agenda-reset-view))
  8403. (?d (call-interactively 'org-agenda-day-view))
  8404. (?w (call-interactively 'org-agenda-week-view))
  8405. (?t (call-interactively 'org-agenda-fortnight-view))
  8406. (?m (call-interactively 'org-agenda-month-view))
  8407. (?y (call-interactively 'org-agenda-year-view))
  8408. (?l (call-interactively 'org-agenda-log-mode))
  8409. (?L (org-agenda-log-mode '(4)))
  8410. (?c (org-agenda-log-mode 'clockcheck))
  8411. ((or ?F ?f) (call-interactively 'org-agenda-follow-mode))
  8412. (?a (call-interactively 'org-agenda-archives-mode))
  8413. (?A (org-agenda-archives-mode 'files))
  8414. ((or ?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  8415. ((or ?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  8416. (?G (call-interactively 'org-agenda-toggle-time-grid))
  8417. (?D (call-interactively 'org-agenda-toggle-diary))
  8418. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  8419. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  8420. (org-agenda-check-type t 'agenda)
  8421. (org-agenda-redo))
  8422. (message "Display now includes inactive timestamps as well"))
  8423. (?q (message "Abort"))
  8424. (key (user-error "Invalid key: %s" key))))
  8425. (defun org-agenda-reset-view ()
  8426. "Switch to default view for agenda."
  8427. (interactive)
  8428. (org-agenda-change-time-span org-agenda-span))
  8429. (defun org-agenda-day-view (&optional day-of-month)
  8430. "Switch to daily view for agenda.
  8431. With argument DAY-OF-MONTH, switch to that day of the month."
  8432. (interactive "P")
  8433. (org-agenda-change-time-span 'day day-of-month))
  8434. (defun org-agenda-week-view (&optional iso-week)
  8435. "Switch to weekly view for agenda.
  8436. With argument ISO-WEEK, switch to the corresponding ISO week.
  8437. If ISO-WEEK has more then 2 digits, only the last two encode
  8438. the week. Any digits before this encode a year. So 200712
  8439. means week 12 of year 2007. Years ranging from 70 years ago
  8440. to 30 years in the future can also be written as 2-digit years."
  8441. (interactive "P")
  8442. (org-agenda-change-time-span 'week iso-week))
  8443. (defun org-agenda-fortnight-view (&optional iso-week)
  8444. "Switch to fortnightly view for agenda.
  8445. With argument ISO-WEEK, switch to the corresponding ISO week.
  8446. If ISO-WEEK has more then 2 digits, only the last two encode
  8447. the week. Any digits before this encode a year. So 200712
  8448. means week 12 of year 2007. Years ranging from 70 years ago
  8449. to 30 years in the future can also be written as 2-digit years."
  8450. (interactive "P")
  8451. (org-agenda-change-time-span 'fortnight iso-week))
  8452. (defun org-agenda-month-view (&optional month)
  8453. "Switch to monthly view for agenda.
  8454. With argument MONTH, switch to that month. If MONTH has more
  8455. then 2 digits, only the last two encode the month. Any digits
  8456. before this encode a year. So 200712 means December year 2007.
  8457. Years ranging from 70 years ago to 30 years in the future can
  8458. also be written as 2-digit years."
  8459. (interactive "P")
  8460. (org-agenda-change-time-span 'month month))
  8461. (defun org-agenda-year-view (&optional year)
  8462. "Switch to yearly view for agenda.
  8463. With argument YEAR, switch to that year. Years ranging from 70
  8464. years ago to 30 years in the future can also be written as
  8465. 2-digit years."
  8466. (interactive "P")
  8467. (when year
  8468. (setq year (org-small-year-to-year year)))
  8469. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  8470. (org-agenda-change-time-span 'year year)
  8471. (error "Abort")))
  8472. (defun org-agenda-change-time-span (span &optional n)
  8473. "Change the agenda view to SPAN.
  8474. SPAN may be `day', `week', `fortnight', `month', `year'."
  8475. (org-agenda-check-type t 'agenda)
  8476. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  8477. (curspan (nth 2 args)))
  8478. (when (and (not n) (equal curspan span))
  8479. (error "Viewing span is already \"%s\"" span))
  8480. (let* ((sd (or (org-get-at-bol 'day)
  8481. (nth 1 args)
  8482. org-starting-day))
  8483. (sd (org-agenda-compute-starting-span sd span n))
  8484. (org-agenda-overriding-cmd
  8485. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  8486. (org-agenda-overriding-arguments
  8487. (list (car args) sd span)))
  8488. (org-agenda-redo)
  8489. (org-agenda-find-same-or-today-or-agenda))
  8490. (org-agenda-set-mode-name)
  8491. (message "Switched to %s view" span)))
  8492. (defun org-agenda-compute-starting-span (sd span &optional n)
  8493. "Compute starting date for agenda.
  8494. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  8495. is a cons cell with the starting date and the number of days,
  8496. so that the date SD will be in that range."
  8497. (let* ((greg (calendar-gregorian-from-absolute sd))
  8498. ;; (dg (nth 1 greg))
  8499. (mg (car greg))
  8500. (yg (nth 2 greg)))
  8501. (cond
  8502. ((eq span 'day)
  8503. (when n
  8504. (setq sd (+ (calendar-absolute-from-gregorian
  8505. (list mg 1 yg))
  8506. n -1))))
  8507. ((or (eq span 'week) (eq span 'fortnight))
  8508. (let* ((nt (calendar-day-of-week
  8509. (calendar-gregorian-from-absolute sd)))
  8510. (d (if org-agenda-start-on-weekday
  8511. (- nt org-agenda-start-on-weekday)
  8512. 0))
  8513. y1)
  8514. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  8515. (when n
  8516. (require 'cal-iso)
  8517. (when (> n 99)
  8518. (setq y1 (org-small-year-to-year (/ n 100))
  8519. n (mod n 100)))
  8520. (setq sd
  8521. (calendar-iso-to-absolute
  8522. (list n 1
  8523. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  8524. ((eq span 'month)
  8525. (let (y1)
  8526. (when (and n (> n 99))
  8527. (setq y1 (org-small-year-to-year (/ n 100))
  8528. n (mod n 100)))
  8529. (setq sd (calendar-absolute-from-gregorian
  8530. (list (or n mg) 1 (or y1 yg))))))
  8531. ((eq span 'year)
  8532. (setq sd (calendar-absolute-from-gregorian
  8533. (list 1 1 (or n yg))))))
  8534. sd))
  8535. (defun org-agenda-next-date-line (&optional arg)
  8536. "Jump to the next line indicating a date in agenda buffer."
  8537. (interactive "p")
  8538. (org-agenda-check-type t 'agenda)
  8539. (beginning-of-line 1)
  8540. ;; This does not work if user makes date format that starts with a blank
  8541. (when (looking-at-p "^\\S-") (forward-char 1))
  8542. (unless (re-search-forward "^\\S-" nil t arg)
  8543. (backward-char 1)
  8544. (error "No next date after this line in this buffer"))
  8545. (goto-char (match-beginning 0)))
  8546. (defun org-agenda-previous-date-line (&optional arg)
  8547. "Jump to the previous line indicating a date in agenda buffer."
  8548. (interactive "p")
  8549. (org-agenda-check-type t 'agenda)
  8550. (beginning-of-line 1)
  8551. (unless (re-search-backward "^\\S-" nil t arg)
  8552. (error "No previous date before this line in this buffer")))
  8553. ;; Initialize the highlight
  8554. (defvar org-hl (make-overlay 1 1))
  8555. (overlay-put org-hl 'face 'highlight)
  8556. (defun org-highlight (begin end &optional buffer)
  8557. "Highlight a region with overlay."
  8558. (move-overlay org-hl begin end (or buffer (current-buffer))))
  8559. (defun org-unhighlight ()
  8560. "Detach overlay INDEX."
  8561. (delete-overlay org-hl))
  8562. (defun org-unhighlight-once ()
  8563. "Remove the highlight from its position, and this function from the hook."
  8564. (remove-hook 'pre-command-hook #'org-unhighlight-once)
  8565. (org-unhighlight))
  8566. (defvar org-agenda-pre-follow-window-conf nil)
  8567. (defun org-agenda-follow-mode ()
  8568. "Toggle follow mode in an agenda buffer."
  8569. (interactive)
  8570. (unless org-agenda-follow-mode
  8571. (setq org-agenda-pre-follow-window-conf
  8572. (current-window-configuration)))
  8573. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  8574. (unless org-agenda-follow-mode
  8575. (set-window-configuration org-agenda-pre-follow-window-conf))
  8576. (org-agenda-set-mode-name)
  8577. (org-agenda-do-context-action)
  8578. (message "Follow mode is %s"
  8579. (if org-agenda-follow-mode "on" "off")))
  8580. (defun org-agenda-entry-text-mode (&optional arg)
  8581. "Toggle entry text mode in an agenda buffer."
  8582. (interactive "P")
  8583. (if (or org-agenda-tag-filter
  8584. org-agenda-category-filter
  8585. org-agenda-regexp-filter
  8586. org-agenda-top-headline-filter)
  8587. (user-error "Can't show entry text in filtered views")
  8588. (setq org-agenda-entry-text-mode (or (integerp arg)
  8589. (not org-agenda-entry-text-mode)))
  8590. (org-agenda-entry-text-hide)
  8591. (and org-agenda-entry-text-mode
  8592. (let ((org-agenda-entry-text-maxlines
  8593. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  8594. (org-agenda-entry-text-show)))
  8595. (org-agenda-set-mode-name)
  8596. (message "Entry text mode is %s%s"
  8597. (if org-agenda-entry-text-mode "on" "off")
  8598. (if (not org-agenda-entry-text-mode) ""
  8599. (format " (maximum number of lines is %d)"
  8600. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  8601. (defun org-agenda-clockreport-mode ()
  8602. "Toggle clocktable mode in an agenda buffer."
  8603. (interactive)
  8604. (org-agenda-check-type t 'agenda)
  8605. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  8606. (org-agenda-set-mode-name)
  8607. (org-agenda-redo)
  8608. (message "Clocktable mode is %s"
  8609. (if org-agenda-clockreport-mode "on" "off")))
  8610. (defun org-agenda-log-mode (&optional special)
  8611. "Toggle log mode in an agenda buffer.
  8612. With argument SPECIAL, show all possible log items, not only the ones
  8613. configured in `org-agenda-log-mode-items'.
  8614. With a `\\[universal-argument] \\[universal-argument]' prefix, show *only* \
  8615. log items, nothing else."
  8616. (interactive "P")
  8617. (org-agenda-check-type t 'agenda)
  8618. (setq org-agenda-show-log
  8619. (cond
  8620. ((equal special '(16)) 'only)
  8621. ((eq special 'clockcheck)
  8622. (if (eq org-agenda-show-log 'clockcheck)
  8623. nil 'clockcheck))
  8624. (special '(closed clock state))
  8625. (t (not org-agenda-show-log))))
  8626. (org-agenda-set-mode-name)
  8627. (org-agenda-redo)
  8628. (message "Log mode is %s" (if org-agenda-show-log "on" "off")))
  8629. (defun org-agenda-archives-mode (&optional with-files)
  8630. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  8631. When called with a prefix argument, include all archive files as well."
  8632. (interactive "P")
  8633. (setq org-agenda-archives-mode
  8634. (cond ((and with-files (eq org-agenda-archives-mode t)) nil)
  8635. (with-files t)
  8636. (org-agenda-archives-mode nil)
  8637. (t 'trees)))
  8638. (org-agenda-set-mode-name)
  8639. (org-agenda-redo)
  8640. (message
  8641. "%s"
  8642. (cond
  8643. ((eq org-agenda-archives-mode nil)
  8644. "No archives are included")
  8645. ((eq org-agenda-archives-mode 'trees)
  8646. (format "Trees with :%s: tag are included" org-archive-tag))
  8647. ((eq org-agenda-archives-mode t)
  8648. (format "Trees with :%s: tag and all active archive files are included"
  8649. org-archive-tag)))))
  8650. (defun org-agenda-toggle-diary ()
  8651. "Toggle diary inclusion in an agenda buffer."
  8652. (interactive)
  8653. (org-agenda-check-type t 'agenda)
  8654. (setq org-agenda-include-diary (not org-agenda-include-diary))
  8655. (org-agenda-redo)
  8656. (org-agenda-set-mode-name)
  8657. (message "Diary inclusion turned %s"
  8658. (if org-agenda-include-diary "on" "off")))
  8659. (defun org-agenda-toggle-deadlines ()
  8660. "Toggle inclusion of entries with a deadline in an agenda buffer."
  8661. (interactive)
  8662. (org-agenda-check-type t 'agenda)
  8663. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  8664. (org-agenda-redo)
  8665. (org-agenda-set-mode-name)
  8666. (message "Deadlines inclusion turned %s"
  8667. (if org-agenda-include-deadlines "on" "off")))
  8668. (defun org-agenda-toggle-time-grid ()
  8669. "Toggle time grid in an agenda buffer."
  8670. (interactive)
  8671. (org-agenda-check-type t 'agenda)
  8672. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  8673. (org-agenda-redo)
  8674. (org-agenda-set-mode-name)
  8675. (message "Time-grid turned %s"
  8676. (if org-agenda-use-time-grid "on" "off")))
  8677. (defun org-agenda-set-mode-name ()
  8678. "Set the mode name to indicate all the small mode settings."
  8679. (setq mode-name
  8680. (list "Org-Agenda"
  8681. (if (get 'org-agenda-files 'org-restrict) " []" "")
  8682. " "
  8683. '(:eval (org-agenda-span-name org-agenda-current-span))
  8684. (if org-agenda-follow-mode " Follow" "")
  8685. (if org-agenda-entry-text-mode " ETxt" "")
  8686. (if org-agenda-include-diary " Diary" "")
  8687. (if org-agenda-include-deadlines " Ddl" "")
  8688. (if org-agenda-use-time-grid " Grid" "")
  8689. (if (and (boundp 'org-habit-show-habits)
  8690. org-habit-show-habits)
  8691. " Habit" "")
  8692. (cond
  8693. ((consp org-agenda-show-log) " LogAll")
  8694. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  8695. (org-agenda-show-log " Log")
  8696. (t ""))
  8697. (if (org-agenda-filter-any) " " "")
  8698. (if (or org-agenda-category-filter
  8699. (get 'org-agenda-category-filter :preset-filter))
  8700. '(:eval (propertize
  8701. (concat "["
  8702. (mapconcat
  8703. #'identity
  8704. (append
  8705. (get 'org-agenda-category-filter :preset-filter)
  8706. org-agenda-category-filter)
  8707. "")
  8708. "]")
  8709. 'face 'org-agenda-filter-category
  8710. 'help-echo "Category used in filtering"))
  8711. "")
  8712. (if (or org-agenda-tag-filter
  8713. (get 'org-agenda-tag-filter :preset-filter))
  8714. '(:eval (propertize
  8715. (concat (mapconcat
  8716. #'identity
  8717. (append
  8718. (get 'org-agenda-tag-filter :preset-filter)
  8719. org-agenda-tag-filter)
  8720. ""))
  8721. 'face 'org-agenda-filter-tags
  8722. 'help-echo "Tags used in filtering"))
  8723. "")
  8724. (if (or org-agenda-effort-filter
  8725. (get 'org-agenda-effort-filter :preset-filter))
  8726. '(:eval (propertize
  8727. (concat (mapconcat
  8728. #'identity
  8729. (append
  8730. (get 'org-agenda-effort-filter :preset-filter)
  8731. org-agenda-effort-filter)
  8732. ""))
  8733. 'face 'org-agenda-filter-effort
  8734. 'help-echo "Effort conditions used in filtering"))
  8735. "")
  8736. (if (or org-agenda-regexp-filter
  8737. (get 'org-agenda-regexp-filter :preset-filter))
  8738. '(:eval (propertize
  8739. (concat (mapconcat
  8740. (lambda (x) (concat (substring x 0 1) "/" (substring x 1) "/"))
  8741. (append
  8742. (get 'org-agenda-regexp-filter :preset-filter)
  8743. org-agenda-regexp-filter)
  8744. ""))
  8745. 'face 'org-agenda-filter-regexp
  8746. 'help-echo "Regexp used in filtering"))
  8747. "")
  8748. (if org-agenda-archives-mode
  8749. (if (eq org-agenda-archives-mode t)
  8750. " Archives"
  8751. (format " :%s:" org-archive-tag))
  8752. "")
  8753. (if org-agenda-clockreport-mode " Clock" "")))
  8754. (force-mode-line-update))
  8755. (defun org-agenda-update-agenda-type ()
  8756. "Update the agenda type after each command."
  8757. (setq org-agenda-type
  8758. (or (get-text-property (point) 'org-agenda-type)
  8759. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  8760. (defun org-agenda-next-line ()
  8761. "Move cursor to the next line, and show if follow mode is active."
  8762. (interactive)
  8763. (call-interactively 'next-line)
  8764. (org-agenda-do-context-action))
  8765. (defun org-agenda-previous-line ()
  8766. "Move cursor to the previous line, and show if follow-mode is active."
  8767. (interactive)
  8768. (call-interactively 'previous-line)
  8769. (org-agenda-do-context-action))
  8770. (defun org-agenda-next-item (n)
  8771. "Move cursor to next agenda item."
  8772. (interactive "p")
  8773. (let ((col (current-column)))
  8774. (dotimes (_ n)
  8775. (when (next-single-property-change (point-at-eol) 'org-marker)
  8776. (move-end-of-line 1)
  8777. (goto-char (next-single-property-change (point) 'org-marker))))
  8778. (org-move-to-column col))
  8779. (org-agenda-do-context-action))
  8780. (defun org-agenda-previous-item (n)
  8781. "Move cursor to next agenda item."
  8782. (interactive "p")
  8783. (dotimes (_ n)
  8784. (let ((col (current-column))
  8785. (goto (save-excursion
  8786. (move-end-of-line 0)
  8787. (previous-single-property-change (point) 'org-marker))))
  8788. (when goto (goto-char goto))
  8789. (org-move-to-column col)))
  8790. (org-agenda-do-context-action))
  8791. (defun org-agenda-do-context-action ()
  8792. "Show outline path and, maybe, follow mode window."
  8793. (let ((m (org-get-at-bol 'org-marker)))
  8794. (when (and (markerp m) (marker-buffer m))
  8795. (and org-agenda-follow-mode
  8796. (if org-agenda-follow-indirect
  8797. (org-agenda-tree-to-indirect-buffer nil)
  8798. (org-agenda-show)))
  8799. (and org-agenda-show-outline-path
  8800. (org-with-point-at m (org-display-outline-path t))))))
  8801. (defun org-agenda-show-tags ()
  8802. "Show the tags applicable to the current item."
  8803. (interactive)
  8804. (let* ((tags (org-get-at-bol 'tags)))
  8805. (if tags
  8806. (message "Tags are :%s:"
  8807. (org-no-properties (mapconcat #'identity tags ":")))
  8808. (message "No tags associated with this line"))))
  8809. (defun org-agenda-goto (&optional highlight)
  8810. "Go to the entry at point in the corresponding Org file."
  8811. (interactive)
  8812. (let* ((marker (or (org-get-at-bol 'org-marker)
  8813. (org-agenda-error)))
  8814. (buffer (marker-buffer marker))
  8815. (pos (marker-position marker)))
  8816. ;; FIXME: use `org-switch-to-buffer-other-window'?
  8817. (switch-to-buffer-other-window buffer)
  8818. (widen)
  8819. (push-mark)
  8820. (goto-char pos)
  8821. (when (derived-mode-p 'org-mode)
  8822. (org-fold-show-context 'agenda)
  8823. (recenter (/ (window-height) 2))
  8824. (org-back-to-heading t)
  8825. (let ((case-fold-search nil))
  8826. (when (re-search-forward org-complex-heading-regexp nil t)
  8827. (goto-char (match-beginning 4)))))
  8828. (run-hooks 'org-agenda-after-show-hook)
  8829. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  8830. (defvar org-agenda-after-show-hook nil
  8831. "Normal hook run after an item has been shown from the agenda.
  8832. Point is in the buffer where the item originated.")
  8833. ;; Defined later in org-agenda.el
  8834. (defvar org-agenda-loop-over-headlines-in-active-region nil)
  8835. (defun org-agenda-do-in-region (beg end cmd &optional arg force-arg delete)
  8836. "Between region BEG and END, call agenda command CMD.
  8837. When optional argument ARG is non-nil or FORCE-ARG is t, pass
  8838. ARG to CMD. When optional argument DELETE is non-nil, assume CMD
  8839. deletes the agenda entry and don't move to the next entry."
  8840. (save-excursion
  8841. (goto-char beg)
  8842. (let ((mend (move-marker (make-marker) end))
  8843. (all (eq org-agenda-loop-over-headlines-in-active-region t))
  8844. (match (and (stringp org-agenda-loop-over-headlines-in-active-region)
  8845. org-agenda-loop-over-headlines-in-active-region))
  8846. (level (and (eq org-agenda-loop-over-headlines-in-active-region 'start-level)
  8847. (org-get-at-bol 'level))))
  8848. (while (< (point) mend)
  8849. (let ((ov (make-overlay (point) (point-at-eol))))
  8850. (if (not (or all
  8851. (and match (looking-at-p match))
  8852. (eq level (org-get-at-bol 'level))))
  8853. (org-agenda-next-item 1)
  8854. (overlay-put ov 'face 'region)
  8855. (if (or arg force-arg) (funcall cmd arg) (funcall cmd))
  8856. (when (not delete) (org-agenda-next-item 1))
  8857. (delete-overlay ov)))))))
  8858. ;; org-agenda-[schedule,deadline,date-prompt,todo,[toggle]archive*,
  8859. ;; kill,set-property,set-effort] commands may loop over agenda
  8860. ;; entries. Commands `org-agenda-set-tags' and `org-agenda-bulk-mark'
  8861. ;; use their own mechanisms on active regions.
  8862. (defmacro org-agenda-maybe-loop (cmd arg force-arg delete &rest body)
  8863. "Maybe loop over agenda entries and perform CMD.
  8864. Pass ARG, FORCE-ARG, DELETE and BODY to `org-agenda-do-in-region'."
  8865. (declare (debug t))
  8866. `(if (and (called-interactively-p 'any)
  8867. org-agenda-loop-over-headlines-in-active-region
  8868. (org-region-active-p))
  8869. (org-agenda-do-in-region
  8870. (region-beginning) (region-end) ,cmd ,arg ,force-arg ,delete)
  8871. ,@body))
  8872. (defun org-agenda-kill ()
  8873. "Kill the entry or subtree belonging to the current agenda entry."
  8874. (interactive)
  8875. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8876. (org-agenda-maybe-loop
  8877. #'org-agenda-kill nil nil t
  8878. (let* ((bufname-orig (buffer-name))
  8879. (marker (or (org-get-at-bol 'org-marker)
  8880. (org-agenda-error)))
  8881. (buffer (marker-buffer marker))
  8882. (pos (marker-position marker))
  8883. (type (org-get-at-bol 'type))
  8884. dbeg dend (n 0))
  8885. (org-with-remote-undo buffer
  8886. (with-current-buffer buffer
  8887. (save-excursion
  8888. (goto-char pos)
  8889. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  8890. (setq dbeg (progn (org-back-to-heading t) (point))
  8891. dend (org-end-of-subtree t t))
  8892. (setq dbeg (point-at-bol)
  8893. dend (min (point-max) (1+ (point-at-eol)))))
  8894. (goto-char dbeg)
  8895. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  8896. (when (or (eq t org-agenda-confirm-kill)
  8897. (and (numberp org-agenda-confirm-kill)
  8898. (> n org-agenda-confirm-kill)))
  8899. (let ((win-conf (current-window-configuration)))
  8900. (unwind-protect
  8901. (and
  8902. (prog2
  8903. (org-agenda-tree-to-indirect-buffer nil)
  8904. (not (y-or-n-p
  8905. (format "Delete entry with %d lines in buffer \"%s\"? "
  8906. n (buffer-name buffer))))
  8907. (kill-buffer org-last-indirect-buffer))
  8908. (error "Abort"))
  8909. (set-window-configuration win-conf))))
  8910. (let ((org-agenda-buffer-name bufname-orig))
  8911. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  8912. (with-current-buffer buffer (delete-region dbeg dend))
  8913. (message "Agenda item and source killed")))))
  8914. (defvar org-archive-default-command) ; defined in org-archive.el
  8915. (defun org-agenda-archive-default ()
  8916. "Archive the entry or subtree belonging to the current agenda entry."
  8917. (interactive)
  8918. (require 'org-archive)
  8919. (funcall-interactively
  8920. #'org-agenda-archive-with org-archive-default-command))
  8921. (defun org-agenda-archive-default-with-confirmation ()
  8922. "Archive the entry or subtree belonging to the current agenda entry."
  8923. (interactive)
  8924. (require 'org-archive)
  8925. (funcall-interactively
  8926. #'org-agenda-archive-with org-archive-default-command 'confirm))
  8927. (defun org-agenda-archive ()
  8928. "Archive the entry or subtree belonging to the current agenda entry."
  8929. (interactive)
  8930. (funcall-interactively
  8931. #'org-agenda-archive-with 'org-archive-subtree))
  8932. (defun org-agenda-archive-to-archive-sibling ()
  8933. "Move the entry to the archive sibling."
  8934. (interactive)
  8935. (funcall-interactively
  8936. #'org-agenda-archive-with 'org-archive-to-archive-sibling))
  8937. (defvar org-archive-from-agenda)
  8938. (defun org-agenda-archive-with (cmd &optional confirm)
  8939. "Move the entry to the archive sibling."
  8940. (interactive)
  8941. (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda"))
  8942. (org-agenda-maybe-loop
  8943. #'org-agenda-archive-with cmd nil t
  8944. (let* ((bufname-orig (buffer-name))
  8945. (marker (or (org-get-at-bol 'org-marker)
  8946. (org-agenda-error)))
  8947. (buffer (marker-buffer marker))
  8948. (pos (marker-position marker)))
  8949. (org-with-remote-undo buffer
  8950. (with-current-buffer buffer
  8951. (if (derived-mode-p 'org-mode)
  8952. (if (and confirm
  8953. (not (y-or-n-p "Archive this subtree or entry? ")))
  8954. (error "Abort")
  8955. (save-window-excursion
  8956. (goto-char pos)
  8957. (let ((org-agenda-buffer-name bufname-orig))
  8958. (org-remove-subtree-entries-from-agenda))
  8959. (org-back-to-heading t)
  8960. (let ((org-archive-from-agenda t))
  8961. (funcall cmd))))
  8962. (error "Archiving works only in Org files")))))))
  8963. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  8964. "Remove all lines in the agenda that correspond to a given subtree.
  8965. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  8966. If this information is not given, the function uses the tree at point."
  8967. (let ((buf (or buf (current-buffer))) m p)
  8968. (save-excursion
  8969. (unless (and beg end)
  8970. (org-back-to-heading t)
  8971. (setq beg (point))
  8972. (org-end-of-subtree t)
  8973. (setq end (point)))
  8974. (set-buffer (get-buffer org-agenda-buffer-name))
  8975. (save-excursion
  8976. (goto-char (point-max))
  8977. (beginning-of-line 1)
  8978. (while (not (bobp))
  8979. (when (and (setq m (org-get-at-bol 'org-marker))
  8980. (equal buf (marker-buffer m))
  8981. (setq p (marker-position m))
  8982. (>= p beg)
  8983. (< p end))
  8984. (let ((inhibit-read-only t))
  8985. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  8986. (beginning-of-line 0))))))
  8987. (defun org-agenda-refile (&optional goto rfloc no-update)
  8988. "Refile the item at point.
  8989. When called with `\\[universal-argument] \\[universal-argument]', \
  8990. go to the location of the last
  8991. refiled item.
  8992. When called with `\\[universal-argument] \\[universal-argument] \
  8993. \\[universal-argument]' prefix or when GOTO is 0, clear
  8994. the refile cache.
  8995. RFLOC can be a refile location obtained in a different way.
  8996. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  8997. (interactive "P")
  8998. (cond
  8999. ((member goto '(0 (64)))
  9000. (org-refile-cache-clear))
  9001. ((equal goto '(16))
  9002. (org-refile-goto-last-stored))
  9003. (t
  9004. (let* ((buffer-orig (buffer-name))
  9005. (marker (or (org-get-at-bol 'org-hd-marker)
  9006. (org-agenda-error)))
  9007. (buffer (marker-buffer marker))
  9008. ;; (pos (marker-position marker))
  9009. (rfloc (or rfloc
  9010. (org-refile-get-location
  9011. (if goto "Goto" "Refile to") buffer
  9012. org-refile-allow-creating-parent-nodes))))
  9013. (with-current-buffer buffer
  9014. (org-with-wide-buffer
  9015. (goto-char marker)
  9016. (let ((org-agenda-buffer-name buffer-orig))
  9017. (org-remove-subtree-entries-from-agenda))
  9018. (org-refile goto buffer rfloc))))
  9019. (unless no-update (org-agenda-redo)))))
  9020. (defun org-agenda-open-link (&optional arg)
  9021. "Open the link(s) in the current entry, if any.
  9022. This looks for a link in the displayed line in the agenda.
  9023. It also looks at the text of the entry itself."
  9024. (interactive "P")
  9025. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  9026. (org-get-at-bol 'org-marker)))
  9027. (buffer (and marker (marker-buffer marker)))
  9028. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  9029. (lkall (and buffer (org-offer-links-in-entry
  9030. buffer marker arg prefix)))
  9031. (lk0 (car lkall))
  9032. (lk (if (stringp lk0) (list lk0) lk0))
  9033. (lkend (cdr lkall))
  9034. trg)
  9035. (cond
  9036. ((and buffer lk)
  9037. (mapcar (lambda(l)
  9038. (with-current-buffer buffer
  9039. (setq trg (and (string-match org-link-bracket-re l)
  9040. (match-string 1 l)))
  9041. (if (or (not trg) (string-match org-link-any-re trg))
  9042. ;; Don't use `org-with-wide-buffer' here as
  9043. ;; opening the link may result in moving the point
  9044. (save-restriction
  9045. (widen)
  9046. (goto-char marker)
  9047. (when (search-forward l nil lkend)
  9048. (goto-char (match-beginning 0))
  9049. (org-open-at-point)))
  9050. ;; This is an internal link, widen the buffer
  9051. ;; FIXME: use `org-switch-to-buffer-other-window'?
  9052. (switch-to-buffer-other-window buffer)
  9053. (widen)
  9054. (goto-char marker)
  9055. (when (search-forward l nil lkend)
  9056. (goto-char (match-beginning 0))
  9057. (org-open-at-point)))))
  9058. lk))
  9059. ((or (org-in-regexp (concat "\\(" org-link-bracket-re "\\)"))
  9060. (save-excursion
  9061. (beginning-of-line 1)
  9062. (looking-at (concat ".*?\\(" org-link-bracket-re "\\)"))))
  9063. (org-link-open-from-string (match-string 1)))
  9064. (t (message "No link to open here")))))
  9065. (defun org-agenda-copy-local-variable (var)
  9066. "Get a variable from a referenced buffer and install it here."
  9067. (let ((m (org-get-at-bol 'org-marker)))
  9068. (when (and m (buffer-live-p (marker-buffer m)))
  9069. (set (make-local-variable var)
  9070. (with-current-buffer (marker-buffer m)
  9071. (symbol-value var))))))
  9072. (defun org-agenda-switch-to (&optional delete-other-windows)
  9073. "Go to the Org mode file which contains the item at point.
  9074. When optional argument DELETE-OTHER-WINDOWS is non-nil, the
  9075. displayed Org file fills the frame."
  9076. (interactive)
  9077. (if (and org-return-follows-link
  9078. (not (org-get-at-bol 'org-marker))
  9079. (org-in-regexp org-link-bracket-re))
  9080. (org-link-open-from-string (match-string 0))
  9081. (let* ((marker (or (org-get-at-bol 'org-marker)
  9082. (org-agenda-error)))
  9083. (buffer (marker-buffer marker))
  9084. (pos (marker-position marker)))
  9085. (unless buffer (user-error "Trying to switch to non-existent buffer"))
  9086. (pop-to-buffer-same-window buffer)
  9087. (when delete-other-windows (delete-other-windows))
  9088. (widen)
  9089. (goto-char pos)
  9090. (when (derived-mode-p 'org-mode)
  9091. (org-fold-show-context 'agenda)
  9092. (run-hooks 'org-agenda-after-show-hook)))))
  9093. (defun org-agenda-goto-mouse (ev)
  9094. "Go to the Org file which contains the item at the mouse click."
  9095. (interactive "e")
  9096. (mouse-set-point ev)
  9097. (org-agenda-goto))
  9098. (defun org-agenda-show (&optional full-entry)
  9099. "Display the Org file which contains the item at point.
  9100. With prefix argument FULL-ENTRY, make the entire entry visible
  9101. if it was hidden in the outline."
  9102. (interactive "P")
  9103. (let ((win (selected-window)))
  9104. (org-agenda-goto t)
  9105. (when full-entry (org-fold-show-entry))
  9106. (select-window win)))
  9107. (defvar org-agenda-show-window nil)
  9108. (defun org-agenda-show-and-scroll-up (&optional arg)
  9109. "Display the Org file which contains the item at point.
  9110. When called repeatedly, scroll the window that is displaying the buffer.
  9111. With a `\\[universal-argument]' prefix argument, display the item, but \
  9112. fold drawers."
  9113. (interactive "P")
  9114. (let ((win (selected-window)))
  9115. (if (and (window-live-p org-agenda-show-window)
  9116. (eq this-command last-command))
  9117. (progn
  9118. (select-window org-agenda-show-window)
  9119. (ignore-errors (scroll-up)))
  9120. (org-agenda-goto t)
  9121. (org-fold-show-entry)
  9122. (if arg (org-cycle-hide-drawers 'children)
  9123. (org-with-wide-buffer
  9124. (narrow-to-region (org-entry-beginning-position)
  9125. (org-entry-end-position))
  9126. (org-fold-show-all '(drawers))))
  9127. (setq org-agenda-show-window (selected-window)))
  9128. (select-window win)))
  9129. (defun org-agenda-show-scroll-down ()
  9130. "Scroll down the window showing the agenda."
  9131. (interactive)
  9132. (let ((win (selected-window)))
  9133. (when (window-live-p org-agenda-show-window)
  9134. (select-window org-agenda-show-window)
  9135. (ignore-errors (scroll-down))
  9136. (select-window win))))
  9137. (defun org-agenda-show-1 (&optional more)
  9138. "Display the Org file which contains the item at point.
  9139. The prefix arg selects the amount of information to display:
  9140. 0 hide the subtree
  9141. 1 just show the entry according to defaults.
  9142. 2 show the children view
  9143. 3 show the subtree view
  9144. 4 show the entire subtree and any drawers
  9145. With prefix argument FULL-ENTRY, make the entire entry visible
  9146. if it was hidden in the outline."
  9147. (interactive "p")
  9148. (let ((win (selected-window)))
  9149. (org-agenda-goto t)
  9150. (org-back-to-heading)
  9151. (set-window-start (selected-window) (point-at-bol))
  9152. (cond
  9153. ((= more 0)
  9154. (org-fold-subtree t)
  9155. (save-excursion
  9156. (org-back-to-heading)
  9157. (run-hook-with-args 'org-cycle-hook 'folded))
  9158. (message "Remote: FOLDED"))
  9159. ((and (called-interactively-p 'any) (= more 1))
  9160. (message "Remote: show with default settings"))
  9161. ((= more 2)
  9162. (org-fold-show-entry)
  9163. (org-fold-show-children)
  9164. (save-excursion
  9165. (org-back-to-heading)
  9166. (run-hook-with-args 'org-cycle-hook 'children))
  9167. (message "Remote: CHILDREN"))
  9168. ((= more 3)
  9169. (org-fold-show-subtree)
  9170. (save-excursion
  9171. (org-back-to-heading)
  9172. (run-hook-with-args 'org-cycle-hook 'subtree))
  9173. (message "Remote: SUBTREE"))
  9174. ((> more 3)
  9175. (org-fold-show-subtree)
  9176. (message "Remote: SUBTREE AND ALL DRAWERS")))
  9177. (select-window win)))
  9178. (defvar org-agenda-cycle-counter nil)
  9179. (defun org-agenda-cycle-show (&optional n)
  9180. "Show the current entry in another window, with default settings.
  9181. Default settings are taken from `org-show-context-detail'. When
  9182. use repeatedly in immediate succession, the remote entry will
  9183. cycle through visibility
  9184. children -> subtree -> folded
  9185. When called with a numeric prefix arg, that arg will be passed through to
  9186. `org-agenda-show-1'. For the interpretation of that argument, see the
  9187. docstring of `org-agenda-show-1'."
  9188. (interactive "P")
  9189. (if (integerp n)
  9190. (setq org-agenda-cycle-counter n)
  9191. (if (not (eq last-command this-command))
  9192. (setq org-agenda-cycle-counter 1)
  9193. (if (equal org-agenda-cycle-counter 0)
  9194. (setq org-agenda-cycle-counter 2)
  9195. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  9196. (when (> org-agenda-cycle-counter 3)
  9197. (setq org-agenda-cycle-counter 0)))))
  9198. (org-agenda-show-1 org-agenda-cycle-counter))
  9199. (defun org-agenda-recenter (arg)
  9200. "Display the Org file which contains the item at point and recenter."
  9201. (interactive "P")
  9202. (let ((win (selected-window)))
  9203. (org-agenda-goto t)
  9204. (recenter arg)
  9205. (select-window win)))
  9206. (defun org-agenda-show-mouse (ev)
  9207. "Display the Org file which contains the item at the mouse click."
  9208. (interactive "e")
  9209. (mouse-set-point ev)
  9210. (org-agenda-show))
  9211. (defun org-agenda-check-no-diary ()
  9212. "Check if the entry is a diary link and abort if yes."
  9213. (when (org-get-at-bol 'org-agenda-diary-link)
  9214. (org-agenda-error)))
  9215. (defun org-agenda-error ()
  9216. "Throw an error when a command is not allowed in the agenda."
  9217. (user-error "Command not allowed in this line"))
  9218. (defun org-agenda-tree-to-indirect-buffer (arg)
  9219. "Show the subtree corresponding to the current entry in an indirect buffer.
  9220. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  9221. With a numerical prefix ARG, go up to this level and then take that tree.
  9222. With a negative numeric ARG, go up by this number of levels.
  9223. With a `\\[universal-argument]' prefix, make a separate frame for this tree, \
  9224. i.e. don't use
  9225. the dedicated frame."
  9226. (interactive "P")
  9227. (if current-prefix-arg
  9228. (org-agenda-do-tree-to-indirect-buffer arg)
  9229. (let ((agenda-buffer (buffer-name))
  9230. (agenda-window (selected-window))
  9231. (indirect-window
  9232. (and org-last-indirect-buffer
  9233. (get-buffer-window org-last-indirect-buffer))))
  9234. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  9235. (unless (or (eq org-indirect-buffer-display 'new-frame)
  9236. (eq org-indirect-buffer-display 'dedicated-frame))
  9237. (unwind-protect
  9238. (unless (and indirect-window (window-live-p indirect-window))
  9239. (setq indirect-window (split-window agenda-window)))
  9240. (and indirect-window (select-window indirect-window))
  9241. (switch-to-buffer org-last-indirect-buffer :norecord)
  9242. (fit-window-to-buffer indirect-window)))
  9243. (select-window (get-buffer-window agenda-buffer))
  9244. (setq org-agenda-last-indirect-buffer org-last-indirect-buffer))))
  9245. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  9246. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  9247. (org-agenda-check-no-diary)
  9248. (let* ((marker (or (org-get-at-bol 'org-marker)
  9249. (org-agenda-error)))
  9250. (buffer (marker-buffer marker))
  9251. (pos (marker-position marker)))
  9252. (with-current-buffer buffer
  9253. (save-excursion
  9254. (goto-char pos)
  9255. (org-tree-to-indirect-buffer arg)))))
  9256. (defvar org-last-heading-marker (make-marker)
  9257. "Marker pointing to the headline that last changed its TODO state
  9258. by a remote command from the agenda.")
  9259. (defun org-agenda-todo-nextset ()
  9260. "Switch TODO entry to next sequence."
  9261. (interactive)
  9262. (org-agenda-todo 'nextset))
  9263. (defun org-agenda-todo-previousset ()
  9264. "Switch TODO entry to previous sequence."
  9265. (interactive)
  9266. (org-agenda-todo 'previousset))
  9267. (defvar org-agenda-headline-snapshot-before-repeat)
  9268. (defun org-agenda-todo (&optional arg)
  9269. "Cycle TODO state of line at point, also in Org file.
  9270. This changes the line at point, all other lines in the agenda referring to
  9271. the same tree node, and the headline of the tree node in the Org file."
  9272. (interactive "P")
  9273. (org-agenda-check-no-diary)
  9274. (org-agenda-maybe-loop
  9275. #'org-agenda-todo arg nil nil
  9276. (let* ((col (current-column))
  9277. (marker (or (org-get-at-bol 'org-marker)
  9278. (org-agenda-error)))
  9279. (buffer (marker-buffer marker))
  9280. (pos (marker-position marker))
  9281. (hdmarker (org-get-at-bol 'org-hd-marker))
  9282. (todayp (org-agenda-today-p (org-get-at-bol 'day)))
  9283. (inhibit-read-only t)
  9284. org-loop-over-headlines-in-active-region
  9285. org-agenda-headline-snapshot-before-repeat newhead just-one)
  9286. (org-with-remote-undo buffer
  9287. (with-current-buffer buffer
  9288. (widen)
  9289. (goto-char pos)
  9290. (org-fold-show-context 'agenda)
  9291. (let ((current-prefix-arg arg))
  9292. (call-interactively 'org-todo)
  9293. ;; Make sure that log is recorded in current undo.
  9294. (when (and org-log-setup
  9295. (not (eq org-log-note-how 'note)))
  9296. (org-add-log-note)))
  9297. (and (bolp) (forward-char 1))
  9298. (setq newhead (org-get-heading))
  9299. (when (and org-agenda-headline-snapshot-before-repeat
  9300. (not (equal org-agenda-headline-snapshot-before-repeat
  9301. newhead))
  9302. todayp)
  9303. (setq newhead org-agenda-headline-snapshot-before-repeat
  9304. just-one t))
  9305. (save-excursion
  9306. (org-back-to-heading)
  9307. (move-marker org-last-heading-marker (point))))
  9308. (beginning-of-line 1)
  9309. (save-window-excursion
  9310. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  9311. (when (bound-and-true-p org-clock-out-when-done)
  9312. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  9313. newhead)
  9314. (org-agenda-unmark-clocking-task))
  9315. (org-move-to-column col)
  9316. (org-agenda-mark-clocking-task)))))
  9317. (defun org-agenda-add-note (&optional _arg)
  9318. "Add a time-stamped note to the entry at point."
  9319. (interactive) ;; "P"
  9320. (org-agenda-check-no-diary)
  9321. (let* ((marker (or (org-get-at-bol 'org-marker)
  9322. (org-agenda-error)))
  9323. (buffer (marker-buffer marker))
  9324. (pos (marker-position marker))
  9325. (_hdmarker (org-get-at-bol 'org-hd-marker))
  9326. (inhibit-read-only t))
  9327. (with-current-buffer buffer
  9328. (widen)
  9329. (goto-char pos)
  9330. (org-fold-show-context 'agenda)
  9331. (org-add-note))))
  9332. (defun org-agenda-change-all-lines (newhead hdmarker
  9333. &optional fixface just-this)
  9334. "Change all lines in the agenda buffer which match HDMARKER.
  9335. The new content of the line will be NEWHEAD (as modified by
  9336. `org-agenda-format-item'). HDMARKER is checked with
  9337. `equal' against all `org-hd-marker' text properties in the file.
  9338. If FIXFACE is non-nil, the face of each item is modified according to
  9339. the new TODO state.
  9340. If JUST-THIS is non-nil, change just the current line, not all.
  9341. If FORCE-TAGS is non-nil, the car of it returns the new tags."
  9342. (let* ((inhibit-read-only t)
  9343. (line (org-current-line))
  9344. (org-agenda-buffer (current-buffer))
  9345. (thetags (with-current-buffer (marker-buffer hdmarker)
  9346. (org-get-tags hdmarker)))
  9347. props m undone-face done-face finish new dotime level cat tags
  9348. effort effort-minutes) ;; pl
  9349. (save-excursion
  9350. (goto-char (point-max))
  9351. (beginning-of-line 1)
  9352. (while (not finish)
  9353. (setq finish (bobp))
  9354. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  9355. (or (not just-this) (= (org-current-line) line))
  9356. (equal m hdmarker))
  9357. (setq props (text-properties-at (point))
  9358. dotime (org-get-at-bol 'dotime)
  9359. cat (org-agenda-get-category)
  9360. level (org-get-at-bol 'level)
  9361. tags thetags
  9362. effort (org-get-at-bol 'effort)
  9363. effort-minutes (org-get-at-bol 'effort-minutes)
  9364. new
  9365. (let ((org-prefix-format-compiled
  9366. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  9367. org-prefix-format-compiled))
  9368. (extra (org-get-at-bol 'extra)))
  9369. (with-current-buffer (marker-buffer hdmarker)
  9370. (org-with-wide-buffer
  9371. (org-agenda-format-item extra
  9372. (org-add-props newhead nil
  9373. 'effort effort
  9374. 'effort-minutes effort-minutes)
  9375. level cat tags dotime))))
  9376. ;; pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  9377. undone-face (org-get-at-bol 'undone-face)
  9378. done-face (org-get-at-bol 'done-face))
  9379. (beginning-of-line 1)
  9380. (cond
  9381. ((equal new "") (delete-region (point) (line-beginning-position 2)))
  9382. ((looking-at ".*")
  9383. ;; When replacing the whole line, preserve bulk mark
  9384. ;; overlay, if any.
  9385. (let ((mark (catch :overlay
  9386. (dolist (o (overlays-in (point) (+ 2 (point))))
  9387. (when (eq (overlay-get o 'type)
  9388. 'org-marked-entry-overlay)
  9389. (throw :overlay o))))))
  9390. (replace-match new t t)
  9391. (beginning-of-line)
  9392. (when mark (move-overlay mark (point) (+ 2 (point)))))
  9393. (add-text-properties (point-at-bol) (point-at-eol) props)
  9394. (when fixface
  9395. (add-text-properties
  9396. (point-at-bol) (point-at-eol)
  9397. (list 'face
  9398. (if org-last-todo-state-is-todo
  9399. undone-face done-face))))
  9400. (org-agenda-highlight-todo 'line)
  9401. (beginning-of-line 1))
  9402. (t (error "Line update did not work")))
  9403. (save-restriction
  9404. (narrow-to-region (point-at-bol) (point-at-eol))
  9405. (org-agenda-finalize)))
  9406. (beginning-of-line 0)))))
  9407. (defun org-agenda-align-tags (&optional line)
  9408. "Align all tags in agenda items to `org-agenda-tags-column'.
  9409. When optional argument LINE is non-nil, align tags only on the
  9410. current line."
  9411. (let ((inhibit-read-only t)
  9412. (org-agenda-tags-column (if (eq 'auto org-agenda-tags-column)
  9413. (- (window-max-chars-per-line))
  9414. org-agenda-tags-column))
  9415. (end (and line (line-end-position)))
  9416. l c)
  9417. (save-excursion
  9418. (goto-char (if line (line-beginning-position) (point-min)))
  9419. (while (re-search-forward org-tag-group-re end t)
  9420. (add-text-properties
  9421. (match-beginning 1) (match-end 1)
  9422. (list 'face (delq nil (let ((prop (get-text-property
  9423. (match-beginning 1) 'face)))
  9424. (or (listp prop) (setq prop (list prop)))
  9425. (if (memq 'org-tag prop)
  9426. prop
  9427. (cons 'org-tag prop))))))
  9428. (setq l (string-width (match-string 1))
  9429. c (if (< org-agenda-tags-column 0)
  9430. (- (abs org-agenda-tags-column) l)
  9431. org-agenda-tags-column))
  9432. (goto-char (match-beginning 1))
  9433. (delete-region (save-excursion (skip-chars-backward " \t") (point))
  9434. (point))
  9435. (insert (org-add-props
  9436. (make-string (max 1 (- c (current-column))) ?\s)
  9437. (plist-put (copy-sequence (text-properties-at (point)))
  9438. 'face nil))))
  9439. (goto-char (point-min))
  9440. (org-font-lock-add-tag-faces (point-max)))))
  9441. (defun org-agenda-priority-up ()
  9442. "Increase the priority of line at point, also in Org file."
  9443. (interactive)
  9444. (org-agenda-priority 'up))
  9445. (defun org-agenda-priority-down ()
  9446. "Decrease the priority of line at point, also in Org file."
  9447. (interactive)
  9448. (org-agenda-priority 'down))
  9449. (defun org-agenda-priority (&optional force-direction)
  9450. "Set the priority of line at point, also in Org file.
  9451. This changes the line at point, all other lines in the agenda
  9452. referring to the same tree node, and the headline of the tree
  9453. node in the Org file.
  9454. Called with one universal prefix arg, show the priority instead
  9455. of setting it.
  9456. When called programmatically, FORCE-DIRECTION can be `set', `up',
  9457. `down', or a character."
  9458. (interactive "P")
  9459. (unless org-priority-enable-commands
  9460. (user-error "Priority commands are disabled"))
  9461. (org-agenda-check-no-diary)
  9462. (let* ((col (current-column))
  9463. (hdmarker (org-get-at-bol 'org-hd-marker))
  9464. (buffer (marker-buffer hdmarker))
  9465. (pos (marker-position hdmarker))
  9466. (inhibit-read-only t)
  9467. newhead)
  9468. (org-with-remote-undo buffer
  9469. (with-current-buffer buffer
  9470. (widen)
  9471. (goto-char pos)
  9472. (org-fold-show-context 'agenda)
  9473. (org-priority force-direction)
  9474. (end-of-line 1)
  9475. (setq newhead (org-get-heading)))
  9476. (org-agenda-change-all-lines newhead hdmarker)
  9477. (org-move-to-column col))))
  9478. ;; FIXME: should fix the tags property of the agenda line.
  9479. (defun org-agenda-set-tags (&optional tag onoff)
  9480. "Set tags for the current headline."
  9481. (interactive)
  9482. (org-agenda-check-no-diary)
  9483. (if (and (org-region-active-p) (called-interactively-p 'any))
  9484. (call-interactively 'org-change-tag-in-region)
  9485. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9486. (org-agenda-error)))
  9487. (buffer (marker-buffer hdmarker))
  9488. (pos (marker-position hdmarker))
  9489. (inhibit-read-only t)
  9490. newhead)
  9491. (org-with-remote-undo buffer
  9492. (with-current-buffer buffer
  9493. (widen)
  9494. (goto-char pos)
  9495. (org-fold-show-context 'agenda)
  9496. (if tag
  9497. (org-toggle-tag tag onoff)
  9498. (call-interactively #'org-set-tags-command))
  9499. (end-of-line 1)
  9500. (setq newhead (org-get-heading)))
  9501. (org-agenda-change-all-lines newhead hdmarker)
  9502. (beginning-of-line 1)))))
  9503. (defun org-agenda-set-property ()
  9504. "Set a property for the current headline."
  9505. (interactive)
  9506. (org-agenda-check-no-diary)
  9507. (org-agenda-maybe-loop
  9508. #'org-agenda-set-property nil nil nil
  9509. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9510. (org-agenda-error)))
  9511. (buffer (marker-buffer hdmarker))
  9512. (pos (marker-position hdmarker))
  9513. (inhibit-read-only t)
  9514. ) ;; newhead
  9515. (org-with-remote-undo buffer
  9516. (with-current-buffer buffer
  9517. (widen)
  9518. (goto-char pos)
  9519. (org-fold-show-context 'agenda)
  9520. (call-interactively 'org-set-property))))))
  9521. (defun org-agenda-set-effort ()
  9522. "Set the effort property for the current headline."
  9523. (interactive)
  9524. (org-agenda-check-no-diary)
  9525. (org-agenda-maybe-loop
  9526. #'org-agenda-set-effort nil nil nil
  9527. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9528. (org-agenda-error)))
  9529. (buffer (marker-buffer hdmarker))
  9530. (pos (marker-position hdmarker))
  9531. (inhibit-read-only t)
  9532. newhead)
  9533. (org-with-remote-undo buffer
  9534. (with-current-buffer buffer
  9535. (widen)
  9536. (goto-char pos)
  9537. (org-fold-show-context 'agenda)
  9538. (call-interactively 'org-set-effort)
  9539. (end-of-line 1)
  9540. (setq newhead (org-get-heading)))
  9541. (org-agenda-change-all-lines newhead hdmarker)))))
  9542. (defun org-agenda-toggle-archive-tag ()
  9543. "Toggle the archive tag for the current entry."
  9544. (interactive)
  9545. (org-agenda-check-no-diary)
  9546. (org-agenda-maybe-loop
  9547. #'org-agenda-toggle-archive-tag nil nil nil
  9548. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  9549. (org-agenda-error)))
  9550. (buffer (marker-buffer hdmarker))
  9551. (pos (marker-position hdmarker))
  9552. (inhibit-read-only t)
  9553. newhead)
  9554. (org-with-remote-undo buffer
  9555. (with-current-buffer buffer
  9556. (widen)
  9557. (goto-char pos)
  9558. (org-fold-show-context 'agenda)
  9559. (call-interactively 'org-toggle-archive-tag)
  9560. (end-of-line 1)
  9561. (setq newhead (org-get-heading)))
  9562. (org-agenda-change-all-lines newhead hdmarker)
  9563. (beginning-of-line 1)))))
  9564. (defun org-agenda-do-date-later (arg)
  9565. (interactive "P")
  9566. (cond
  9567. ((or (equal arg '(16))
  9568. (memq last-command
  9569. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9570. (setq this-command 'org-agenda-date-later-minutes)
  9571. (org-agenda-date-later-minutes 1))
  9572. ((or (equal arg '(4))
  9573. (memq last-command
  9574. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9575. (setq this-command 'org-agenda-date-later-hours)
  9576. (org-agenda-date-later-hours 1))
  9577. (t
  9578. (org-agenda-date-later (prefix-numeric-value arg)))))
  9579. (defun org-agenda-do-date-earlier (arg)
  9580. (interactive "P")
  9581. (cond
  9582. ((or (equal arg '(16))
  9583. (memq last-command
  9584. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  9585. (setq this-command 'org-agenda-date-earlier-minutes)
  9586. (org-agenda-date-earlier-minutes 1))
  9587. ((or (equal arg '(4))
  9588. (memq last-command
  9589. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  9590. (setq this-command 'org-agenda-date-earlier-hours)
  9591. (org-agenda-date-earlier-hours 1))
  9592. (t
  9593. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  9594. (defun org-agenda-date-later (arg &optional what)
  9595. "Change the date of this item to ARG day(s) later."
  9596. (interactive "p")
  9597. (org-agenda-check-type t 'agenda)
  9598. (org-agenda-check-no-diary)
  9599. (let* ((marker (or (org-get-at-bol 'org-marker)
  9600. (org-agenda-error)))
  9601. (buffer (marker-buffer marker))
  9602. (pos (marker-position marker))
  9603. cdate today)
  9604. (org-with-remote-undo buffer
  9605. (with-current-buffer buffer
  9606. (widen)
  9607. (goto-char pos)
  9608. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9609. (when (and org-agenda-move-date-from-past-immediately-to-today
  9610. (equal arg 1)
  9611. (or (not what) (eq what 'day))
  9612. (not (save-match-data (org-at-date-range-p))))
  9613. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  9614. cdate (calendar-absolute-from-gregorian
  9615. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  9616. today (org-today))
  9617. (when (> today cdate)
  9618. ;; immediately shift to today
  9619. (setq arg (- today cdate))))
  9620. (org-timestamp-change arg (or what 'day))
  9621. (when (and (org-at-date-range-p)
  9622. (re-search-backward org-tr-regexp-both (point-at-bol)))
  9623. (let ((end org-last-changed-timestamp))
  9624. (org-timestamp-change arg (or what 'day))
  9625. (setq org-last-changed-timestamp
  9626. (concat org-last-changed-timestamp "--" end)))))
  9627. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9628. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  9629. (defun org-agenda-date-earlier (arg &optional what)
  9630. "Change the date of this item to ARG day(s) earlier."
  9631. (interactive "p")
  9632. (org-agenda-date-later (- arg) what))
  9633. (defun org-agenda-date-later-minutes (arg)
  9634. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9635. (interactive "p")
  9636. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9637. (org-agenda-date-later arg 'minute))
  9638. (defun org-agenda-date-earlier-minutes (arg)
  9639. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  9640. (interactive "p")
  9641. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  9642. (org-agenda-date-earlier arg 'minute))
  9643. (defun org-agenda-date-later-hours (arg)
  9644. "Change the time of this item, in hour steps."
  9645. (interactive "p")
  9646. (org-agenda-date-later arg 'hour))
  9647. (defun org-agenda-date-earlier-hours (arg)
  9648. "Change the time of this item, in hour steps."
  9649. (interactive "p")
  9650. (org-agenda-date-earlier arg 'hour))
  9651. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  9652. "Show new date stamp via text properties."
  9653. ;; We use text properties to make this undoable
  9654. (let ((inhibit-read-only t))
  9655. (setq stamp (concat prefix " => " stamp " "))
  9656. (save-excursion
  9657. (goto-char (point-max))
  9658. (while (not (bobp))
  9659. (when (equal marker (org-get-at-bol 'org-marker))
  9660. (remove-text-properties (line-beginning-position)
  9661. (line-end-position)
  9662. '(display nil))
  9663. (org-move-to-column
  9664. (- (window-max-chars-per-line)
  9665. (length stamp))
  9666. t)
  9667. (add-text-properties
  9668. (1- (point)) (point-at-eol)
  9669. (list 'display (org-add-props stamp nil
  9670. 'face '(secondary-selection default))))
  9671. (beginning-of-line 1))
  9672. (beginning-of-line 0)))))
  9673. (defun org-agenda-date-prompt (arg)
  9674. "Change the date of this item. Date is prompted for, with default today.
  9675. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  9676. be used to request time specification in the time stamp."
  9677. (interactive "P")
  9678. (org-agenda-check-type t 'agenda)
  9679. (org-agenda-check-no-diary)
  9680. (org-agenda-maybe-loop
  9681. #'org-agenda-date-prompt arg t nil
  9682. (let* ((marker (or (org-get-at-bol 'org-marker)
  9683. (org-agenda-error)))
  9684. (buffer (marker-buffer marker))
  9685. (pos (marker-position marker)))
  9686. (org-with-remote-undo buffer
  9687. (with-current-buffer buffer
  9688. (widen)
  9689. (goto-char pos)
  9690. (unless (org-at-timestamp-p 'lax) (error "Cannot find time stamp"))
  9691. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  9692. (org-agenda-show-new-time marker org-last-changed-timestamp))
  9693. (message "Time stamp changed to %s" org-last-changed-timestamp))))
  9694. (defun org-agenda-schedule (arg &optional time)
  9695. "Schedule the item at point.
  9696. ARG is passed through to `org-schedule'."
  9697. (interactive "P")
  9698. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9699. (org-agenda-check-no-diary)
  9700. (org-agenda-maybe-loop
  9701. #'org-agenda-schedule arg t nil
  9702. (let* ((marker (or (org-get-at-bol 'org-marker)
  9703. (org-agenda-error)))
  9704. ;; (type (marker-insertion-type marker))
  9705. (buffer (marker-buffer marker))
  9706. (pos (marker-position marker))
  9707. ts)
  9708. (set-marker-insertion-type marker t)
  9709. (org-with-remote-undo buffer
  9710. (with-current-buffer buffer
  9711. (widen)
  9712. (goto-char pos)
  9713. (setq ts (org-schedule arg time)))
  9714. (org-agenda-show-new-time marker ts " S"))
  9715. (message "%s" ts))))
  9716. (defun org-agenda-deadline (arg &optional time)
  9717. "Schedule the item at point.
  9718. ARG is passed through to `org-deadline'."
  9719. (interactive "P")
  9720. (org-agenda-check-type t 'agenda 'todo 'tags 'search)
  9721. (org-agenda-check-no-diary)
  9722. (org-agenda-maybe-loop
  9723. #'org-agenda-deadline arg t nil
  9724. (let* ((marker (or (org-get-at-bol 'org-marker)
  9725. (org-agenda-error)))
  9726. (buffer (marker-buffer marker))
  9727. (pos (marker-position marker))
  9728. ts)
  9729. (org-with-remote-undo buffer
  9730. (with-current-buffer buffer
  9731. (widen)
  9732. (goto-char pos)
  9733. (setq ts (org-deadline arg time)))
  9734. (org-agenda-show-new-time marker ts " D"))
  9735. (message "%s" ts))))
  9736. (defun org-agenda-clock-in (&optional arg)
  9737. "Start the clock on the currently selected item."
  9738. (interactive "P")
  9739. (org-agenda-check-no-diary)
  9740. (if (equal arg '(4))
  9741. (org-clock-in arg)
  9742. (let* ((marker (or (org-get-at-bol 'org-marker)
  9743. (org-agenda-error)))
  9744. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  9745. (pos (marker-position marker))
  9746. (col (current-column))
  9747. newhead)
  9748. (org-with-remote-undo (marker-buffer marker)
  9749. (with-current-buffer (marker-buffer marker)
  9750. (widen)
  9751. (goto-char pos)
  9752. (org-fold-show-context 'agenda)
  9753. (org-clock-in arg)
  9754. (setq newhead (org-get-heading)))
  9755. (org-agenda-change-all-lines newhead hdmarker))
  9756. (org-move-to-column col))))
  9757. (defun org-agenda-clock-out ()
  9758. "Stop the currently running clock."
  9759. (interactive)
  9760. (unless (marker-buffer org-clock-marker)
  9761. (user-error "No running clock"))
  9762. (let ((marker (make-marker)) (col (current-column)) newhead)
  9763. (org-with-remote-undo (marker-buffer org-clock-marker)
  9764. (with-current-buffer (marker-buffer org-clock-marker)
  9765. (org-with-wide-buffer
  9766. (goto-char org-clock-marker)
  9767. (org-back-to-heading t)
  9768. (move-marker marker (point))
  9769. (org-clock-out)
  9770. (setq newhead (org-get-heading)))))
  9771. (org-agenda-change-all-lines newhead marker)
  9772. (move-marker marker nil)
  9773. (org-move-to-column col)
  9774. (org-agenda-unmark-clocking-task)))
  9775. (defun org-agenda-clock-cancel (&optional _arg)
  9776. "Cancel the currently running clock."
  9777. (interactive) ;; "P"
  9778. (unless (marker-buffer org-clock-marker)
  9779. (user-error "No running clock"))
  9780. (org-with-remote-undo (marker-buffer org-clock-marker)
  9781. (org-clock-cancel)))
  9782. (defun org-agenda-clock-goto ()
  9783. "Jump to the currently clocked in task within the agenda.
  9784. If the currently clocked in task is not listed in the agenda
  9785. buffer, display it in another window."
  9786. (interactive)
  9787. (let (pos)
  9788. (mapc (lambda (o)
  9789. (when (eq (overlay-get o 'type) 'org-agenda-clocking)
  9790. (setq pos (overlay-start o))))
  9791. (overlays-in (point-min) (point-max)))
  9792. (cond (pos (goto-char pos))
  9793. ;; If the currently clocked entry is not in the agenda
  9794. ;; buffer, we visit it in another window:
  9795. ((bound-and-true-p org-clock-current-task)
  9796. (org-switch-to-buffer-other-window (org-clock-goto)))
  9797. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  9798. (defun org-agenda-diary-entry-in-org-file ()
  9799. "Make a diary entry in the file `org-agenda-diary-file'."
  9800. (let (d1 d2 char (text "") dp1 dp2)
  9801. (if (equal (buffer-name) "*Calendar*")
  9802. (setq d1 (calendar-cursor-to-date t)
  9803. d2 (car calendar-mark-ring))
  9804. (setq dp1 (get-text-property (point-at-bol) 'day))
  9805. (unless dp1 (user-error "No date defined in current line"))
  9806. (setq d1 (calendar-gregorian-from-absolute dp1)
  9807. d2 (and (ignore-errors (mark))
  9808. (save-excursion
  9809. (goto-char (mark))
  9810. (setq dp2 (get-text-property (point-at-bol) 'day)))
  9811. (calendar-gregorian-from-absolute dp2))))
  9812. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  9813. (setq char (read-char-exclusive))
  9814. (cond
  9815. ((equal char ?d)
  9816. (setq text (read-string "Day entry: "))
  9817. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  9818. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9819. ((equal char ?a)
  9820. (setq d1 (list (car d1) (nth 1 d1)
  9821. (read-number (format "Reference year [%d]: " (nth 2 d1))
  9822. (nth 2 d1))))
  9823. (setq text (read-string "Anniversary (use %d to show years): "))
  9824. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  9825. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9826. ((equal char ?b)
  9827. (setq text (read-string "Block entry: "))
  9828. (unless (and d1 d2 (not (equal d1 d2)))
  9829. (user-error "No block of days selected"))
  9830. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  9831. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  9832. ((equal char ?j)
  9833. (org-switch-to-buffer-other-window
  9834. (find-file-noselect org-agenda-diary-file))
  9835. (require 'org-datetree)
  9836. (org-datetree-find-date-create d1)
  9837. (org-fold-reveal t))
  9838. (t (user-error "Invalid selection character `%c'" char)))))
  9839. (defcustom org-agenda-insert-diary-strategy 'date-tree
  9840. "Where in `org-agenda-diary-file' should new entries be added?
  9841. Valid values:
  9842. date-tree in the date tree, as first child of the date
  9843. date-tree-last in the date tree, as last child of the date
  9844. top-level as top-level entries at the end of the file."
  9845. :group 'org-agenda
  9846. :type '(choice
  9847. (const :tag "first in a date tree" date-tree)
  9848. (const :tag "last in a date tree" date-tree-last)
  9849. (const :tag "as top level at end of file" top-level)))
  9850. (defcustom org-agenda-insert-diary-extract-time nil
  9851. "Non-nil means extract any time specification from the diary entry."
  9852. :group 'org-agenda
  9853. :version "24.1"
  9854. :type 'boolean)
  9855. (defcustom org-agenda-bulk-mark-char ">"
  9856. "A single-character string to be used as the bulk mark."
  9857. :group 'org-agenda
  9858. :version "24.1"
  9859. :type 'string)
  9860. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  9861. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  9862. If TEXT is not empty, it will become the headline of the new entry, and
  9863. the resulting entry will not be shown. When TEXT is empty, switch to
  9864. `org-agenda-diary-file' and let the user finish the entry there."
  9865. (let ((cw (current-window-configuration)))
  9866. (org-switch-to-buffer-other-window
  9867. (find-file-noselect org-agenda-diary-file))
  9868. (widen)
  9869. (goto-char (point-min))
  9870. (cl-case type
  9871. (anniversary
  9872. (or (re-search-forward "^\\*[ \t]+Anniversaries" nil t)
  9873. (progn
  9874. (or (org-at-heading-p)
  9875. (progn
  9876. (outline-next-heading)
  9877. (insert "* Anniversaries\n\n")
  9878. (beginning-of-line -1)))))
  9879. (outline-next-heading)
  9880. (org-back-over-empty-lines)
  9881. (backward-char 1)
  9882. (insert "\n")
  9883. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  9884. (nth 2 d1) (car d1) (nth 1 d1) text)))
  9885. (day
  9886. (let ((org-prefix-has-time t)
  9887. (org-agenda-time-leading-zero t)
  9888. fmt time time2)
  9889. (when org-agenda-insert-diary-extract-time
  9890. ;; Use org-agenda-format-item to parse text for a time-range and
  9891. ;; remove it. FIXME: This is a hack, we should refactor
  9892. ;; that function to make time extraction available separately
  9893. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  9894. time (get-text-property 0 'time fmt)
  9895. time2 (if (> (length time) 0)
  9896. ;; split-string removes trailing ...... if
  9897. ;; no end time given. First space
  9898. ;; separates time from date.
  9899. (concat " " (car (split-string time "\\.")))
  9900. nil)
  9901. text (get-text-property 0 'txt fmt)))
  9902. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9903. (org-agenda-insert-diary-as-top-level text)
  9904. (require 'org-datetree)
  9905. (org-datetree-find-date-create d1)
  9906. (org-agenda-insert-diary-make-new-entry text))
  9907. (org-insert-time-stamp (org-time-from-absolute
  9908. (calendar-absolute-from-gregorian d1))
  9909. nil nil nil nil time2))
  9910. (end-of-line 0))
  9911. ((block) ;; Wrap this in (strictly unnecessary) parens because
  9912. ;; otherwise the indentation gets confused by the
  9913. ;; special meaning of 'block
  9914. (when (> (calendar-absolute-from-gregorian d1)
  9915. (calendar-absolute-from-gregorian d2))
  9916. (setq d1 (prog1 d2 (setq d2 d1))))
  9917. (if (eq org-agenda-insert-diary-strategy 'top-level)
  9918. (org-agenda-insert-diary-as-top-level text)
  9919. (require 'org-datetree)
  9920. (org-datetree-find-date-create d1)
  9921. (org-agenda-insert-diary-make-new-entry text))
  9922. (org-insert-time-stamp (org-time-from-absolute
  9923. (calendar-absolute-from-gregorian d1)))
  9924. (insert "--")
  9925. (org-insert-time-stamp (org-time-from-absolute
  9926. (calendar-absolute-from-gregorian d2)))
  9927. (end-of-line 0)))
  9928. (if (string-match "\\S-" text)
  9929. (progn
  9930. (set-window-configuration cw)
  9931. (message "%s entry added to %s"
  9932. (capitalize (symbol-name type))
  9933. (abbreviate-file-name org-agenda-diary-file)))
  9934. (org-fold-reveal t)
  9935. (message "Please finish entry here"))))
  9936. (defun org-agenda-insert-diary-as-top-level (text)
  9937. "Make new entry as a top-level entry at the end of the file.
  9938. Add TEXT as headline, and position the cursor in the second line so that
  9939. a timestamp can be added there."
  9940. (widen)
  9941. (goto-char (point-max))
  9942. (unless (bolp) (insert "\n"))
  9943. (org-insert-heading nil t t)
  9944. (insert text)
  9945. (org-end-of-meta-data)
  9946. (unless (bolp) (insert "\n"))
  9947. (when org-adapt-indentation (indent-to-column 2)))
  9948. (defun org-agenda-insert-diary-make-new-entry (text)
  9949. "Make a new entry with TEXT as a child of the current subtree.
  9950. Position the point in the heading's first body line so that
  9951. a timestamp can be added there."
  9952. (cond
  9953. ((eq org-agenda-insert-diary-strategy 'date-tree-last)
  9954. (end-of-line)
  9955. (org-insert-heading '(4) t)
  9956. (org-do-demote))
  9957. (t
  9958. (outline-next-heading)
  9959. (org-back-over-empty-lines)
  9960. (unless (looking-at "[ \t]*$") (save-excursion (insert "\n")))
  9961. (org-insert-heading nil t)
  9962. (org-do-demote)))
  9963. (let ((col (current-column)))
  9964. (insert text)
  9965. (org-end-of-meta-data)
  9966. ;; Ensure point is left on a blank line, at proper indentation.
  9967. (unless (bolp) (insert "\n"))
  9968. (unless (looking-at-p "^[ \t]*$") (save-excursion (insert "\n")))
  9969. (when org-adapt-indentation (indent-to-column col)))
  9970. (org-fold-show-set-visibility 'lineage))
  9971. (defun org-agenda-diary-entry ()
  9972. "Make a diary entry, like the `i' command from the calendar.
  9973. All the standard commands work: block, weekly etc.
  9974. When `org-agenda-diary-file' points to a file,
  9975. `org-agenda-diary-entry-in-org-file' is called instead to create
  9976. entries in that Org file."
  9977. (interactive)
  9978. (if (not (eq org-agenda-diary-file 'diary-file))
  9979. (org-agenda-diary-entry-in-org-file)
  9980. (require 'diary-lib)
  9981. (let* ((char (read-char-exclusive
  9982. "Diary entry: [d]ay [w]eekly [m]onthly [y]early\
  9983. [a]nniversary [b]lock [c]yclic"))
  9984. (cmd (cdr (assoc char
  9985. '((?d . diary-insert-entry)
  9986. (?w . diary-insert-weekly-entry)
  9987. (?m . diary-insert-monthly-entry)
  9988. (?y . diary-insert-yearly-entry)
  9989. (?a . diary-insert-anniversary-entry)
  9990. (?b . diary-insert-block-entry)
  9991. (?c . diary-insert-cyclic-entry)))))
  9992. (oldf (symbol-function 'calendar-cursor-to-date))
  9993. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  9994. (point (point))
  9995. (mark (or (mark t) (point))))
  9996. (unless cmd
  9997. (user-error "No command associated with <%c>" char))
  9998. (unless (and (get-text-property point 'day)
  9999. (or (not (equal ?b char))
  10000. (get-text-property mark 'day)))
  10001. (user-error "Don't know which date to use for diary entry"))
  10002. ;; We implement this by hacking the `calendar-cursor-to-date' function
  10003. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  10004. (let ((calendar-mark-ring
  10005. (list (calendar-gregorian-from-absolute
  10006. (or (get-text-property mark 'day)
  10007. (get-text-property point 'day))))))
  10008. (unwind-protect
  10009. (progn
  10010. (fset 'calendar-cursor-to-date
  10011. (lambda (&optional _error _dummy)
  10012. (calendar-gregorian-from-absolute
  10013. (get-text-property point 'day))))
  10014. (call-interactively cmd))
  10015. (fset 'calendar-cursor-to-date oldf))))))
  10016. (defun org-agenda-execute-calendar-command (cmd)
  10017. "Execute a calendar command from the agenda with date from cursor."
  10018. (org-agenda-check-type t 'agenda)
  10019. (require 'diary-lib)
  10020. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  10021. (user-error "Don't know which date to use for the calendar command"))
  10022. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  10023. (point (point))
  10024. (date (calendar-gregorian-from-absolute
  10025. (get-text-property point 'day))))
  10026. ;; the following 2 vars are needed in the calendar
  10027. (org-dlet
  10028. ((displayed-month (car date))
  10029. (displayed-year (nth 2 date)))
  10030. (unwind-protect
  10031. (progn
  10032. (fset 'calendar-cursor-to-date
  10033. (lambda (&optional _error _dummy)
  10034. (calendar-gregorian-from-absolute
  10035. (get-text-property point 'day))))
  10036. (call-interactively cmd))
  10037. (fset 'calendar-cursor-to-date oldf)))))
  10038. (defun org-agenda-phases-of-moon ()
  10039. "Display the phases of the moon for the 3 months around the cursor date."
  10040. (interactive)
  10041. (org-agenda-execute-calendar-command 'calendar-lunar-phases))
  10042. (defun org-agenda-holidays ()
  10043. "Display the holidays for the 3 months around the cursor date."
  10044. (interactive)
  10045. (org-agenda-execute-calendar-command 'calendar-list-holidays))
  10046. (defvar calendar-longitude) ; defined in calendar.el
  10047. (defvar calendar-latitude) ; defined in calendar.el
  10048. (defvar calendar-location-name) ; defined in calendar.el
  10049. (defun org-agenda-sunrise-sunset (arg)
  10050. "Display sunrise and sunset for the cursor date.
  10051. Latitude and longitude can be specified with the variables
  10052. `calendar-latitude' and `calendar-longitude'. When called with prefix
  10053. argument, latitude and longitude will be prompted for."
  10054. (interactive "P")
  10055. (require 'solar)
  10056. (let ((calendar-longitude (if arg nil calendar-longitude))
  10057. (calendar-latitude (if arg nil calendar-latitude))
  10058. (calendar-location-name
  10059. (if arg "the given coordinates" calendar-location-name)))
  10060. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  10061. (defun org-agenda-goto-calendar ()
  10062. "Open the Emacs calendar with the date at the cursor."
  10063. (interactive)
  10064. (org-agenda-check-type t 'agenda)
  10065. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  10066. (user-error "Don't know which date to open in calendar")))
  10067. (date (calendar-gregorian-from-absolute day))
  10068. (calendar-move-hook nil)
  10069. (calendar-view-holidays-initially-flag nil)
  10070. (calendar-view-diary-initially-flag nil))
  10071. (calendar)
  10072. (calendar-goto-date date)))
  10073. ;;;###autoload
  10074. (defun org-calendar-goto-agenda ()
  10075. "Compute the Org agenda for the calendar date displayed at the cursor.
  10076. This is a command that has to be installed in `calendar-mode-map'."
  10077. (interactive)
  10078. ;; Temporarily disable sticky agenda since user clearly wants to
  10079. ;; refresh view anyway.
  10080. (let ((org-agenda-buffer-tmp-name "*Org Agenda(a)*")
  10081. (org-agenda-sticky nil))
  10082. (org-agenda-list nil (calendar-absolute-from-gregorian
  10083. (calendar-cursor-to-date))
  10084. nil)))
  10085. (defun org-agenda-convert-date ()
  10086. (interactive)
  10087. (org-agenda-check-type t 'agenda)
  10088. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  10089. date s)
  10090. (unless day
  10091. (user-error "Don't know which date to convert"))
  10092. (setq date (calendar-gregorian-from-absolute day))
  10093. (setq s (concat
  10094. "Gregorian: " (calendar-date-string date) "\n"
  10095. "ISO: " (calendar-iso-date-string date) "\n"
  10096. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  10097. "Julian: " (calendar-julian-date-string date) "\n"
  10098. "Astron. JD: " (calendar-astro-date-string date)
  10099. " (Julian date number at noon UTC)\n"
  10100. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  10101. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  10102. "French: " (calendar-french-date-string date) "\n"
  10103. "Bahá’í: " (calendar-bahai-date-string date) " (until sunset)\n"
  10104. "Mayan: " (calendar-mayan-date-string date) "\n"
  10105. "Coptic: " (calendar-coptic-date-string date) "\n"
  10106. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  10107. "Persian: " (calendar-persian-date-string date) "\n"
  10108. "Chinese: " (calendar-chinese-date-string date) "\n"))
  10109. (with-output-to-temp-buffer "*Dates*"
  10110. (princ s))
  10111. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  10112. ;;; Bulk commands
  10113. (defun org-agenda-bulk-marked-p ()
  10114. "Non-nil when current entry is marked for bulk action."
  10115. (eq (get-char-property (point-at-bol) 'type)
  10116. 'org-marked-entry-overlay))
  10117. (defun org-agenda-bulk-mark (&optional arg)
  10118. "Mark entries for future bulk action.
  10119. When ARG is nil or one and region is not active then mark the
  10120. entry at point.
  10121. When ARG is nil or one and region is active then mark the entries
  10122. in the region.
  10123. When ARG is greater than one mark ARG lines."
  10124. (interactive "p")
  10125. (when (and (or (not arg) (= arg 1)) (use-region-p))
  10126. (setq arg (count-lines (region-beginning) (region-end)))
  10127. (goto-char (region-beginning))
  10128. (deactivate-mark))
  10129. (dotimes (_ (or arg 1))
  10130. (unless (org-get-at-bol 'org-agenda-diary-link)
  10131. (let* ((m (org-get-at-bol 'org-hd-marker))
  10132. ov)
  10133. (unless (org-agenda-bulk-marked-p)
  10134. (unless m (user-error "Nothing to mark at point"))
  10135. (push m org-agenda-bulk-marked-entries)
  10136. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  10137. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  10138. (org-get-todo-face "TODO")
  10139. 'evaporate)
  10140. (overlay-put ov 'type 'org-marked-entry-overlay))
  10141. (end-of-line 1)
  10142. (or (ignore-errors
  10143. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10144. (beginning-of-line 2))
  10145. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10146. (beginning-of-line 2)))))
  10147. (message "%d entries marked for bulk action"
  10148. (length org-agenda-bulk-marked-entries)))
  10149. (defun org-agenda-bulk-mark-all ()
  10150. "Mark all entries for future agenda bulk action."
  10151. (interactive)
  10152. (org-agenda-bulk-mark-regexp "."))
  10153. (defun org-agenda-bulk-mark-regexp (regexp)
  10154. "Mark entries matching REGEXP for future agenda bulk action."
  10155. (interactive "sMark entries matching regexp: ")
  10156. (let ((entries-marked 0) txt-at-point)
  10157. (save-excursion
  10158. (goto-char (point-min))
  10159. (goto-char (next-single-property-change (point) 'org-hd-marker))
  10160. (while (and (re-search-forward regexp nil t)
  10161. (setq txt-at-point
  10162. (get-text-property (match-beginning 0) 'txt)))
  10163. (if (get-char-property (point) 'invisible)
  10164. (beginning-of-line 2)
  10165. (when (string-match-p regexp txt-at-point)
  10166. (setq entries-marked (1+ entries-marked))
  10167. (call-interactively 'org-agenda-bulk-mark)))))
  10168. (unless entries-marked
  10169. (message "No entry matching this regexp."))))
  10170. (defun org-agenda-bulk-unmark (&optional arg)
  10171. "Unmark the entry at point for future bulk action."
  10172. (interactive "P")
  10173. (if arg
  10174. (org-agenda-bulk-unmark-all)
  10175. (cond ((org-agenda-bulk-marked-p)
  10176. (org-agenda-bulk-remove-overlays
  10177. (point-at-bol) (+ 2 (point-at-bol)))
  10178. (setq org-agenda-bulk-marked-entries
  10179. (delete (org-get-at-bol 'org-hd-marker)
  10180. org-agenda-bulk-marked-entries))
  10181. (end-of-line 1)
  10182. (or (ignore-errors
  10183. (goto-char (next-single-property-change (point) 'txt)))
  10184. (beginning-of-line 2))
  10185. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  10186. (beginning-of-line 2))
  10187. (message "%d entries left marked for bulk action"
  10188. (length org-agenda-bulk-marked-entries)))
  10189. (t (message "No entry to unmark here")))))
  10190. (defun org-agenda-bulk-toggle-all ()
  10191. "Toggle all marks for bulk action."
  10192. (interactive)
  10193. (save-excursion
  10194. (goto-char (point-min))
  10195. (while (ignore-errors
  10196. (goto-char (next-single-property-change (point) 'org-hd-marker)))
  10197. (org-agenda-bulk-toggle))))
  10198. (defun org-agenda-bulk-toggle ()
  10199. "Toggle the mark at point for bulk action."
  10200. (interactive)
  10201. (if (org-agenda-bulk-marked-p)
  10202. (org-agenda-bulk-unmark)
  10203. (org-agenda-bulk-mark)))
  10204. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  10205. "Remove the mark overlays between BEG and END in the agenda buffer.
  10206. BEG and END default to the buffer limits.
  10207. This only removes the overlays, it does not remove the markers
  10208. from the list in `org-agenda-bulk-marked-entries'."
  10209. (interactive)
  10210. (mapc (lambda (ov)
  10211. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  10212. (delete-overlay ov)))
  10213. (overlays-in (or beg (point-min)) (or end (point-max)))))
  10214. (defun org-agenda-bulk-unmark-all ()
  10215. "Remove all marks in the agenda buffer.
  10216. This will remove the markers and the overlays."
  10217. (interactive)
  10218. (if (null org-agenda-bulk-marked-entries)
  10219. (message "No entry to unmark")
  10220. (setq org-agenda-bulk-marked-entries nil)
  10221. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  10222. (defcustom org-agenda-persistent-marks nil
  10223. "Non-nil means marked items will stay marked after a bulk action.
  10224. You can toggle this interactively by typing `p' when prompted for a
  10225. bulk action."
  10226. :group 'org-agenda
  10227. :version "24.1"
  10228. :type 'boolean)
  10229. (defcustom org-agenda-loop-over-headlines-in-active-region t
  10230. "Shall some commands act upon headlines in the active region?
  10231. When set to t, some commands will be performed in all headlines
  10232. within the active region.
  10233. When set to `start-level', some commands will be performed in all
  10234. headlines within the active region, provided that these headlines
  10235. are of the same level than the first one.
  10236. When set to a regular expression, those commands will be
  10237. performed on the matching headlines within the active region.
  10238. The list of commands is: `org-agenda-schedule',
  10239. `org-agenda-deadline', `org-agenda-date-prompt',
  10240. `org-agenda-todo', `org-agenda-archive*', `org-agenda-kill'.
  10241. See `org-loop-over-headlines-in-active-region' for the equivalent
  10242. option for Org buffers."
  10243. :type '(choice (const :tag "Don't loop" nil)
  10244. (const :tag "All headlines in active region" t)
  10245. (const :tag "In active region, headlines at the same level than the first one" start-level)
  10246. (regexp :tag "Regular expression matcher"))
  10247. :version "27.1"
  10248. :package-version '(Org . "9.4")
  10249. :group 'org-agenda)
  10250. (defun org-agenda-bulk-action (&optional arg)
  10251. "Execute an remote-editing action on all marked entries.
  10252. The prefix arg is passed through to the command if possible."
  10253. (interactive "P")
  10254. ;; When there is no mark, act on the agenda entry at point.
  10255. (if (not org-agenda-bulk-marked-entries)
  10256. (save-excursion (org-agenda-bulk-mark)))
  10257. (dolist (m org-agenda-bulk-marked-entries)
  10258. (unless (and (markerp m)
  10259. (marker-buffer m)
  10260. (buffer-live-p (marker-buffer m))
  10261. (marker-position m))
  10262. (user-error "Marker %s for bulk command is invalid" m)))
  10263. ;; Prompt for the bulk command.
  10264. (org-unlogged-message
  10265. (concat "Bulk (" (if org-agenda-persistent-marks "" "don't ") "[p]ersist marks): "
  10266. "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  10267. "[S]catter [f]unction "
  10268. (and org-agenda-bulk-custom-functions
  10269. (format " Custom: [%s]"
  10270. (mapconcat (lambda (f) (char-to-string (car f)))
  10271. org-agenda-bulk-custom-functions
  10272. "")))))
  10273. (catch 'exit
  10274. (let* ((org-log-refile (if org-log-refile 'time nil))
  10275. (entries (reverse org-agenda-bulk-marked-entries))
  10276. (org-overriding-default-time
  10277. (and (get-text-property (point) 'org-agenda-date-header)
  10278. (org-get-cursor-date)))
  10279. redo-at-end
  10280. cmd)
  10281. (pcase (read-char-exclusive)
  10282. (?p
  10283. (let ((org-agenda-persistent-marks
  10284. (not org-agenda-persistent-marks)))
  10285. (org-agenda-bulk-action)
  10286. (throw 'exit nil)))
  10287. (?$
  10288. (setq cmd #'org-agenda-archive))
  10289. (?A
  10290. (setq cmd #'org-agenda-archive-to-archive-sibling))
  10291. ((or ?r ?w)
  10292. (let ((refile-location
  10293. (org-refile-get-location
  10294. "Refile to"
  10295. (marker-buffer (car entries))
  10296. org-refile-allow-creating-parent-nodes)))
  10297. (when (nth 3 refile-location)
  10298. (setcar (nthcdr 3 refile-location)
  10299. (move-marker
  10300. (make-marker)
  10301. (nth 3 refile-location)
  10302. (or (get-file-buffer (nth 1 refile-location))
  10303. (find-buffer-visiting (nth 1 refile-location))
  10304. (error "This should not happen")))))
  10305. (setq cmd (lambda () (org-agenda-refile nil refile-location t)))
  10306. (setq redo-at-end t)))
  10307. (?t
  10308. (let ((state (completing-read
  10309. "Todo state: "
  10310. (with-current-buffer (marker-buffer (car entries))
  10311. (mapcar #'list org-todo-keywords-1)))))
  10312. (setq cmd (lambda ()
  10313. (let ((org-inhibit-blocking t)
  10314. (org-inhibit-logging 'note))
  10315. (org-agenda-todo state))))))
  10316. ((and (or ?- ?+) action)
  10317. (let ((tag (completing-read
  10318. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  10319. (with-current-buffer (marker-buffer (car entries))
  10320. (delq nil
  10321. (mapcar (lambda (x) (and (stringp (car x)) x))
  10322. org-current-tag-alist))))))
  10323. (setq cmd
  10324. (lambda ()
  10325. (org-agenda-set-tags tag
  10326. (if (eq action ?+) 'on 'off))))))
  10327. ((and (or ?s ?d) c)
  10328. (let* ((schedule? (eq c ?s))
  10329. (prompt (if schedule? "(Re)Schedule to" "(Re)Set Deadline to"))
  10330. (time
  10331. (and (not arg)
  10332. (let ((new (org-read-date
  10333. nil nil nil prompt org-overriding-default-time)))
  10334. ;; A "double plus" answer applies to every
  10335. ;; scheduled time. Do not turn it into
  10336. ;; a fixed date yet.
  10337. (if (string-match-p "\\`[ \t]*\\+\\+"
  10338. org-read-date-final-answer)
  10339. org-read-date-final-answer
  10340. new)))))
  10341. ;; Make sure to not prompt for a note when bulk
  10342. ;; rescheduling/resetting deadline as Org cannot cope with
  10343. ;; simultaneous notes. Besides, it could be annoying
  10344. ;; depending on the number of marked items.
  10345. (setq cmd
  10346. (if schedule?
  10347. (lambda ()
  10348. (let ((org-log-reschedule
  10349. (and org-log-reschedule 'time)))
  10350. (org-agenda-schedule arg time)))
  10351. (lambda ()
  10352. (let ((org-log-redeadline (and org-log-redeadline 'time)))
  10353. (org-agenda-deadline arg time)))))))
  10354. (?S
  10355. (unless (org-agenda-check-type nil 'agenda 'todo)
  10356. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type))
  10357. (let ((days (read-number
  10358. (format "Scatter tasks across how many %sdays: "
  10359. (if arg "week" ""))
  10360. 7)))
  10361. (setq cmd
  10362. (lambda ()
  10363. (let ((distance (1+ (random days))))
  10364. (when arg
  10365. (let ((dist distance)
  10366. (day-of-week
  10367. (calendar-day-of-week
  10368. (calendar-gregorian-from-absolute (org-today)))))
  10369. (dotimes (_ (1+ dist))
  10370. (while (member day-of-week org-agenda-weekend-days)
  10371. (cl-incf distance)
  10372. (cl-incf day-of-week)
  10373. (when (= day-of-week 7)
  10374. (setq day-of-week 0)))
  10375. (cl-incf day-of-week)
  10376. (when (= day-of-week 7)
  10377. (setq day-of-week 0)))))
  10378. ;; Silently fail when try to replan a sexp entry.
  10379. (ignore-errors
  10380. (let* ((date (calendar-gregorian-from-absolute
  10381. (+ (org-today) distance)))
  10382. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  10383. (nth 2 date))))
  10384. (org-agenda-schedule nil time))))))))
  10385. (?f
  10386. (setq cmd
  10387. (intern
  10388. (completing-read "Function: " obarray #'fboundp t nil nil))))
  10389. (action
  10390. (setq cmd
  10391. (pcase (assoc action org-agenda-bulk-custom-functions)
  10392. (`(,_ ,fn)
  10393. fn)
  10394. (`(,_ ,fn ,arg-fn)
  10395. (apply #'apply-partially fn (funcall arg-fn)))
  10396. (_
  10397. (user-error "Invalid bulk action: %c" action))))
  10398. (setq redo-at-end t)))
  10399. ;; Sort the markers, to make sure that parents are handled
  10400. ;; before children.
  10401. (setq entries (sort entries
  10402. (lambda (a b)
  10403. (cond
  10404. ((eq (marker-buffer a) (marker-buffer b))
  10405. (< (marker-position a) (marker-position b)))
  10406. (t
  10407. (string< (buffer-name (marker-buffer a))
  10408. (buffer-name (marker-buffer b))))))))
  10409. ;; Now loop over all markers and apply CMD.
  10410. (let ((processed 0)
  10411. (skipped 0))
  10412. (dolist (e entries)
  10413. (let ((pos (text-property-any (point-min) (point-max) 'org-hd-marker e)))
  10414. (if (not pos)
  10415. (progn (message "Skipping removed entry at %s" e)
  10416. (cl-incf skipped))
  10417. (goto-char pos)
  10418. (let (org-loop-over-headlines-in-active-region) (funcall cmd))
  10419. ;; `post-command-hook' is not run yet. We make sure any
  10420. ;; pending log note is processed.
  10421. (when org-log-setup (org-add-log-note))
  10422. (cl-incf processed))))
  10423. (when redo-at-end (org-agenda-redo))
  10424. (unless org-agenda-persistent-marks (org-agenda-bulk-unmark-all))
  10425. (message "Acted on %d entries%s%s"
  10426. processed
  10427. (if (= skipped 0)
  10428. ""
  10429. (format ", skipped %d (disappeared before their turn)"
  10430. skipped))
  10431. (if (not org-agenda-persistent-marks) "" " (kept marked)"))))))
  10432. (defun org-agenda-capture (&optional with-time)
  10433. "Call `org-capture' with the date at point.
  10434. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  10435. current HH:MM time."
  10436. (interactive "P")
  10437. (if (not (eq major-mode 'org-agenda-mode))
  10438. (user-error "You cannot do this outside of agenda buffers")
  10439. (let ((org-overriding-default-time
  10440. (org-get-cursor-date (equal with-time 1))))
  10441. (call-interactively 'org-capture))))
  10442. ;;; Dragging agenda lines forward/backward
  10443. (defun org-agenda-reapply-filters ()
  10444. "Re-apply all agenda filters."
  10445. (mapcar
  10446. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f) t)))
  10447. `((,org-agenda-tag-filter tag)
  10448. (,org-agenda-category-filter category)
  10449. (,org-agenda-regexp-filter regexp)
  10450. (,org-agenda-effort-filter effort)
  10451. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  10452. (,(get 'org-agenda-category-filter :preset-filter) category)
  10453. (,(get 'org-agenda-effort-filter :preset-filter) effort)
  10454. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  10455. (defun org-agenda-drag-line-forward (arg &optional backward)
  10456. "Drag an agenda line forward by ARG lines.
  10457. When the optional argument `backward' is non-nil, move backward."
  10458. (interactive "p")
  10459. (let ((inhibit-read-only t) lst line)
  10460. (if (or (not (get-text-property (point) 'txt))
  10461. (save-excursion
  10462. (dotimes (_ arg)
  10463. (move-beginning-of-line (if backward 0 2))
  10464. (push (not (get-text-property (point) 'txt)) lst))
  10465. (delq nil lst)))
  10466. (message "Cannot move line forward")
  10467. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  10468. (move-beginning-of-line 1)
  10469. (setq line (buffer-substring (point) end))
  10470. (delete-region (point) end)
  10471. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  10472. (insert line)
  10473. (org-agenda-reapply-filters)
  10474. (org-agenda-mark-clocking-task)
  10475. (move-beginning-of-line 0)))))
  10476. (defun org-agenda-drag-line-backward (arg)
  10477. "Drag an agenda line backward by ARG lines."
  10478. (interactive "p")
  10479. (org-agenda-drag-line-forward arg t))
  10480. ;;; Flagging notes
  10481. (defun org-agenda-show-the-flagging-note ()
  10482. "Display the flagging note in the other window.
  10483. When called a second time in direct sequence, offer to remove the FLAGGING
  10484. tag and (if present) the flagging note."
  10485. (interactive)
  10486. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  10487. (win (selected-window))
  10488. note) ;; heading newhead
  10489. (unless hdmarker
  10490. (user-error "No linked entry at point"))
  10491. (if (and (eq this-command last-command)
  10492. (y-or-n-p "Unflag and remove any flagging note? "))
  10493. (progn
  10494. (org-agenda-remove-flag hdmarker)
  10495. (let ((win (get-buffer-window "*Flagging Note*")))
  10496. (and win (delete-window win)))
  10497. (message "Entry unflagged"))
  10498. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  10499. (unless note
  10500. (user-error "No flagging note"))
  10501. (org-kill-new note)
  10502. (org-switch-to-buffer-other-window "*Flagging Note*")
  10503. (erase-buffer)
  10504. (insert note)
  10505. (goto-char (point-min))
  10506. (while (re-search-forward "\\\\n" nil t)
  10507. (replace-match "\n" t t))
  10508. (goto-char (point-min))
  10509. (select-window win)
  10510. (message "%s" (substitute-command-keys "Flagging note pushed to \
  10511. kill ring. Press `\\[org-agenda-show-the-flagging-note]' again to remove \
  10512. tag and note")))))
  10513. (defun org-agenda-remove-flag (marker)
  10514. "Remove the FLAGGED tag and any flagging note in the entry."
  10515. (let ((newhead
  10516. (org-with-point-at marker
  10517. (org-toggle-tag "FLAGGED" 'off)
  10518. (org-entry-delete nil "THEFLAGGINGNOTE")
  10519. (org-get-heading))))
  10520. (org-agenda-change-all-lines newhead marker)
  10521. (message "Entry unflagged")))
  10522. (defun org-agenda-get-any-marker (&optional pos)
  10523. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  10524. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  10525. ;;; Appointment reminders
  10526. (defvar appt-time-msg-list) ; defined in appt.el
  10527. ;;;###autoload
  10528. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  10529. "Activate appointments found in `org-agenda-files'.
  10530. With a `\\[universal-argument]' prefix, refresh the list of \
  10531. appointments.
  10532. If FILTER is t, interactively prompt the user for a regular
  10533. expression, and filter out entries that don't match it.
  10534. If FILTER is a string, use this string as a regular expression
  10535. for filtering entries out.
  10536. If FILTER is a function, filter out entries against which
  10537. calling the function returns nil. This function takes one
  10538. argument: an entry from `org-agenda-get-day-entries'.
  10539. FILTER can also be an alist with the car of each cell being
  10540. either `headline' or `category'. For example:
  10541. \\='((headline \"IMPORTANT\")
  10542. (category \"Work\"))
  10543. will only add headlines containing IMPORTANT or headlines
  10544. belonging to the \"Work\" category.
  10545. ARGS are symbols indicating what kind of entries to consider.
  10546. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  10547. \(i.e., deadlines and scheduled items with a hh:mm specification)
  10548. and :timestamp entries. See the docstring of `org-diary' for
  10549. details and examples.
  10550. If an entry has a APPT_WARNTIME property, its value will be used
  10551. to override `appt-message-warning-time'."
  10552. (interactive "P")
  10553. (when refresh (setq appt-time-msg-list nil))
  10554. (when (eq filter t)
  10555. (setq filter (read-from-minibuffer "Regexp filter: ")))
  10556. (let* ((cnt 0) ; count added events
  10557. (scope (or args '(:deadline* :scheduled* :timestamp)))
  10558. (org-agenda-new-buffers nil)
  10559. (org-deadline-warning-days 0)
  10560. ;; Do not use `org-today' here because appt only takes
  10561. ;; time and without date as argument, so it may pass wrong
  10562. ;; information otherwise
  10563. (today (org-date-to-gregorian
  10564. (time-to-days nil)))
  10565. (org-agenda-restrict nil)
  10566. (files (org-agenda-files 'unrestricted)) entries file
  10567. (org-agenda-buffer nil))
  10568. ;; Get all entries which may contain an appt
  10569. (org-agenda-prepare-buffers files)
  10570. (while (setq file (pop files))
  10571. (setq entries
  10572. (delq nil
  10573. (append entries
  10574. (apply #'org-agenda-get-day-entries
  10575. file today scope)))))
  10576. ;; Map through entries and find if we should filter them out
  10577. (mapc
  10578. (lambda (x)
  10579. (let* ((evt (org-trim
  10580. (replace-regexp-in-string
  10581. org-link-bracket-re "\\2"
  10582. (or (get-text-property 1 'txt x) ""))))
  10583. (cat (get-text-property (1- (length x)) 'org-category x))
  10584. (tod (get-text-property 1 'time-of-day x))
  10585. (ok (or (null filter)
  10586. (and (stringp filter) (string-match filter evt))
  10587. (and (functionp filter) (funcall filter x))
  10588. (and (listp filter)
  10589. (let ((cat-filter (cadr (assq 'category filter)))
  10590. (evt-filter (cadr (assq 'headline filter))))
  10591. (or (and (stringp cat-filter)
  10592. (string-match cat-filter cat))
  10593. (and (stringp evt-filter)
  10594. (string-match evt-filter evt)))))))
  10595. (wrn (get-text-property 1 'warntime x)))
  10596. ;; FIXME: Shall we remove text-properties for the appt text?
  10597. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  10598. (when (and ok tod (not (string-match "\\`DONE\\|CANCELLED" evt)))
  10599. (setq tod (concat "00" (number-to-string tod)))
  10600. (setq tod (when (string-match
  10601. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  10602. (concat (match-string 1 tod) ":"
  10603. (match-string 2 tod))))
  10604. (when (appt-add tod evt wrn)
  10605. (setq cnt (1+ cnt))))))
  10606. entries)
  10607. (org-release-buffers org-agenda-new-buffers)
  10608. (if (eq cnt 0)
  10609. (message "No event to add")
  10610. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  10611. (defun org-agenda-today-p (date)
  10612. "Non-nil when DATE means today.
  10613. DATE is either a list of the form (month day year) or a number of
  10614. days as returned by `calendar-absolute-from-gregorian' or
  10615. `org-today'. This function considers `org-extend-today-until'
  10616. when defining today."
  10617. (eq (org-today)
  10618. (if (consp date) (calendar-absolute-from-gregorian date) date)))
  10619. (defun org-agenda-todo-yesterday (&optional arg)
  10620. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  10621. (interactive "P")
  10622. (let* ((org-use-effective-time t)
  10623. (hour (nth 2 (decode-time (org-current-time))))
  10624. (org-extend-today-until (1+ hour)))
  10625. (org-agenda-todo arg)))
  10626. (defun org-agenda-ctrl-c-ctrl-c ()
  10627. "Set tags in agenda buffer."
  10628. (interactive)
  10629. (org-agenda-set-tags))
  10630. (provide 'org-agenda)
  10631. ;;; org-agenda.el ends here