org-agenda.el 390 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2014 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type '(choice
  203. (const nil)
  204. (string)))
  205. (defcustom org-agenda-persistent-filter nil
  206. "When set, keep filters from one agenda view to the next."
  207. :group 'org-agenda
  208. :type 'boolean)
  209. (defgroup org-agenda-custom-commands nil
  210. "Options concerning agenda views in Org-mode."
  211. :tag "Org Agenda Custom Commands"
  212. :group 'org-agenda)
  213. (defconst org-sorting-choice
  214. '(choice
  215. (const time-up) (const time-down)
  216. (const timestamp-up) (const timestamp-down)
  217. (const scheduled-up) (const scheduled-down)
  218. (const deadline-up) (const deadline-down)
  219. (const ts-up) (const ts-down)
  220. (const tsia-up) (const tsia-down)
  221. (const category-keep) (const category-up) (const category-down)
  222. (const tag-down) (const tag-up)
  223. (const priority-up) (const priority-down)
  224. (const todo-state-up) (const todo-state-down)
  225. (const effort-up) (const effort-down)
  226. (const habit-up) (const habit-down)
  227. (const alpha-up) (const alpha-down)
  228. (const user-defined-up) (const user-defined-down))
  229. "Sorting choices.")
  230. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  231. ;; the new variable `org-agenda-tag-filter-preset'.
  232. (org-defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  233. (org-defvaralias 'org-agenda-filter 'org-agenda-tag-filter)
  234. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  235. "List of types searched for when creating the daily/weekly agenda.
  236. This variable is a list of symbols that controls the types of
  237. items that appear in the daily/weekly agenda. Allowed symbols in this
  238. list are are
  239. :timestamp List items containing a date stamp or date range matching
  240. the selected date. This includes sexp entries in angular
  241. brackets.
  242. :sexp List entries resulting from plain diary-like sexps.
  243. :deadline List deadline due on that date. When the date is today,
  244. also list any deadlines past due, or due within
  245. `org-deadline-warning-days'. `:deadline' must appear before
  246. `:scheduled' if the setting of
  247. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  248. any effect.
  249. :deadline* Same as above, but only include the deadline if it has an
  250. hour specification as [h]h:mm.
  251. :scheduled List all items which are scheduled for the given date.
  252. The diary for *today* also contains items which were
  253. scheduled earlier and are not yet marked DONE.
  254. :scheduled* Same as above, but only include the scheduled item if it
  255. has an hour specification as [h]h:mm.
  256. By default, all four non-starred types are turned on.
  257. When :scheduled* or :deadline* are included, :schedule or :deadline
  258. will be ignored.
  259. Never set this variable globally using `setq', because then it
  260. will apply to all future agenda commands. Instead, bind it with
  261. `let' to scope it dynamically into the agenda-constructing
  262. command. A good way to set it is through options in
  263. `org-agenda-custom-commands'. For a more flexible (though
  264. somewhat less efficient) way of determining what is included in
  265. the daily/weekly agenda, see `org-agenda-skip-function'.")
  266. (defconst org-agenda-custom-commands-local-options
  267. `(repeat :tag "Local settings for this command. Remember to quote values"
  268. (choice :tag "Setting"
  269. (list :tag "Heading for this block"
  270. (const org-agenda-overriding-header)
  271. (string :tag "Headline"))
  272. (list :tag "Files to be searched"
  273. (const org-agenda-files)
  274. (list
  275. (const :format "" quote)
  276. (repeat (file))))
  277. (list :tag "Sorting strategy"
  278. (const org-agenda-sorting-strategy)
  279. (list
  280. (const :format "" quote)
  281. (repeat
  282. ,org-sorting-choice)))
  283. (list :tag "Prefix format"
  284. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  285. (string))
  286. (list :tag "Number of days in agenda"
  287. (const org-agenda-span)
  288. (choice (const :tag "Day" day)
  289. (const :tag "Week" week)
  290. (const :tag "Fortnight" fortnight)
  291. (const :tag "Month" month)
  292. (const :tag "Year" year)
  293. (integer :tag "Custom")))
  294. (list :tag "Fixed starting date"
  295. (const org-agenda-start-day)
  296. (string :value "2007-11-01"))
  297. (list :tag "Start on day of week"
  298. (const org-agenda-start-on-weekday)
  299. (choice :value 1
  300. (const :tag "Today" nil)
  301. (integer :tag "Weekday No.")))
  302. (list :tag "Include data from diary"
  303. (const org-agenda-include-diary)
  304. (boolean))
  305. (list :tag "Deadline Warning days"
  306. (const org-deadline-warning-days)
  307. (integer :value 1))
  308. (list :tag "Category filter preset"
  309. (const org-agenda-category-filter-preset)
  310. (list
  311. (const :format "" quote)
  312. (repeat
  313. (string :tag "+category or -category"))))
  314. (list :tag "Tags filter preset"
  315. (const org-agenda-tag-filter-preset)
  316. (list
  317. (const :format "" quote)
  318. (repeat
  319. (string :tag "+tag or -tag"))))
  320. (list :tag "Regexp filter preset"
  321. (const org-agenda-regexp-filter-preset)
  322. (list
  323. (const :format "" quote)
  324. (repeat
  325. (string :tag "+regexp or -regexp"))))
  326. (list :tag "Set daily/weekly entry types"
  327. (const org-agenda-entry-types)
  328. (list
  329. (const :format "" quote)
  330. (set :greedy t :value ,org-agenda-entry-types
  331. (const :deadline)
  332. (const :scheduled)
  333. (const :deadline*)
  334. (const :scheduled*)
  335. (const :timestamp)
  336. (const :sexp))))
  337. (list :tag "Standard skipping condition"
  338. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  339. (const org-agenda-skip-function)
  340. (list
  341. (const :format "" quote)
  342. (list
  343. (choice
  344. :tag "Skipping range"
  345. (const :tag "Skip entry" org-agenda-skip-entry-if)
  346. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  347. (repeat :inline t :tag "Conditions for skipping"
  348. (choice
  349. :tag "Condition type"
  350. (list :tag "Regexp matches" :inline t
  351. (const :format "" 'regexp)
  352. (regexp))
  353. (list :tag "Regexp does not match" :inline t
  354. (const :format "" 'notregexp)
  355. (regexp))
  356. (list :tag "TODO state is" :inline t
  357. (const 'todo)
  358. (choice
  359. (const :tag "Any not-done state" 'todo)
  360. (const :tag "Any done state" 'done)
  361. (const :tag "Any state" 'any)
  362. (list :tag "Keyword list"
  363. (const :format "" quote)
  364. (repeat (string :tag "Keyword")))))
  365. (list :tag "TODO state is not" :inline t
  366. (const 'nottodo)
  367. (choice
  368. (const :tag "Any not-done state" 'todo)
  369. (const :tag "Any done state" 'done)
  370. (const :tag "Any state" 'any)
  371. (list :tag "Keyword list"
  372. (const :format "" quote)
  373. (repeat (string :tag "Keyword")))))
  374. (const :tag "scheduled" 'scheduled)
  375. (const :tag "not scheduled" 'notscheduled)
  376. (const :tag "deadline" 'deadline)
  377. (const :tag "no deadline" 'notdeadline)
  378. (const :tag "timestamp" 'timestamp)
  379. (const :tag "no timestamp" 'nottimestamp))))))
  380. (list :tag "Non-standard skipping condition"
  381. :value (org-agenda-skip-function)
  382. (const org-agenda-skip-function)
  383. (sexp :tag "Function or form (quoted!)"))
  384. (list :tag "Any variable"
  385. (variable :tag "Variable")
  386. (sexp :tag "Value (sexp)"))))
  387. "Selection of examples for agenda command settings.
  388. This will be spliced into the custom type of
  389. `org-agenda-custom-commands'.")
  390. (defcustom org-agenda-custom-commands
  391. '(("n" "Agenda and all TODO's" ((agenda "") (alltodo ""))))
  392. "Custom commands for the agenda.
  393. These commands will be offered on the splash screen displayed by the
  394. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  395. (key desc type match settings files)
  396. key The key (one or more characters as a string) to be associated
  397. with the command.
  398. desc A description of the command, when omitted or nil, a default
  399. description is built using MATCH.
  400. type The command type, any of the following symbols:
  401. agenda The daily/weekly agenda.
  402. todo Entries with a specific TODO keyword, in all agenda files.
  403. search Entries containing search words entry or headline.
  404. tags Tags/Property/TODO match in all agenda files.
  405. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  406. todo-tree Sparse tree of specific TODO keyword in *current* file.
  407. tags-tree Sparse tree with all tags matches in *current* file.
  408. occur-tree Occur sparse tree for *current* file.
  409. ... A user-defined function.
  410. match What to search for:
  411. - a single keyword for TODO keyword searches
  412. - a tags match expression for tags searches
  413. - a word search expression for text searches.
  414. - a regular expression for occur searches
  415. For all other commands, this should be the empty string.
  416. settings A list of option settings, similar to that in a let form, so like
  417. this: ((opt1 val1) (opt2 val2) ...). The values will be
  418. evaluated at the moment of execution, so quote them when needed.
  419. files A list of files file to write the produced agenda buffer to
  420. with the command `org-store-agenda-views'.
  421. If a file name ends in \".html\", an HTML version of the buffer
  422. is written out. If it ends in \".ps\", a postscript version is
  423. produced. Otherwise, only the plain text is written to the file.
  424. You can also define a set of commands, to create a composite agenda buffer.
  425. In this case, an entry looks like this:
  426. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  427. where
  428. desc A description string to be displayed in the dispatcher menu.
  429. cmd An agenda command, similar to the above. However, tree commands
  430. are not allowed, but instead you can get agenda and global todo list.
  431. So valid commands for a set are:
  432. (agenda \"\" settings)
  433. (alltodo \"\" settings)
  434. (stuck \"\" settings)
  435. (todo \"match\" settings files)
  436. (search \"match\" settings files)
  437. (tags \"match\" settings files)
  438. (tags-todo \"match\" settings files)
  439. Each command can carry a list of options, and another set of options can be
  440. given for the whole set of commands. Individual command options take
  441. precedence over the general options.
  442. When using several characters as key to a command, the first characters
  443. are prefix commands. For the dispatcher to display useful information, you
  444. should provide a description for the prefix, like
  445. (setq org-agenda-custom-commands
  446. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  447. (\"hl\" tags \"+HOME+Lisa\")
  448. (\"hp\" tags \"+HOME+Peter\")
  449. (\"hk\" tags \"+HOME+Kim\")))"
  450. :group 'org-agenda-custom-commands
  451. :type `(repeat
  452. (choice :value ("x" "Describe command here" tags "" nil)
  453. (list :tag "Single command"
  454. (string :tag "Access Key(s) ")
  455. (option (string :tag "Description"))
  456. (choice
  457. (const :tag "Agenda" agenda)
  458. (const :tag "TODO list" alltodo)
  459. (const :tag "Search words" search)
  460. (const :tag "Stuck projects" stuck)
  461. (const :tag "Tags/Property match (all agenda files)" tags)
  462. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  463. (const :tag "TODO keyword search (all agenda files)" todo)
  464. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  465. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  466. (const :tag "Occur tree (current buffer)" occur-tree)
  467. (sexp :tag "Other, user-defined function"))
  468. (string :tag "Match (only for some commands)")
  469. ,org-agenda-custom-commands-local-options
  470. (option (repeat :tag "Export" (file :tag "Export to"))))
  471. (list :tag "Command series, all agenda files"
  472. (string :tag "Access Key(s)")
  473. (string :tag "Description ")
  474. (repeat :tag "Component"
  475. (choice
  476. (list :tag "Agenda"
  477. (const :format "" agenda)
  478. (const :tag "" :format "" "")
  479. ,org-agenda-custom-commands-local-options)
  480. (list :tag "TODO list (all keywords)"
  481. (const :format "" alltodo)
  482. (const :tag "" :format "" "")
  483. ,org-agenda-custom-commands-local-options)
  484. (list :tag "Search words"
  485. (const :format "" search)
  486. (string :tag "Match")
  487. ,org-agenda-custom-commands-local-options)
  488. (list :tag "Stuck projects"
  489. (const :format "" stuck)
  490. (const :tag "" :format "" "")
  491. ,org-agenda-custom-commands-local-options)
  492. (list :tag "Tags search"
  493. (const :format "" tags)
  494. (string :tag "Match")
  495. ,org-agenda-custom-commands-local-options)
  496. (list :tag "Tags search, TODO entries only"
  497. (const :format "" tags-todo)
  498. (string :tag "Match")
  499. ,org-agenda-custom-commands-local-options)
  500. (list :tag "TODO keyword search"
  501. (const :format "" todo)
  502. (string :tag "Match")
  503. ,org-agenda-custom-commands-local-options)
  504. (list :tag "Other, user-defined function"
  505. (symbol :tag "function")
  506. (string :tag "Match")
  507. ,org-agenda-custom-commands-local-options)))
  508. (repeat :tag "Settings for entire command set"
  509. (list (variable :tag "Any variable")
  510. (sexp :tag "Value")))
  511. (option (repeat :tag "Export" (file :tag "Export to"))))
  512. (cons :tag "Prefix key documentation"
  513. (string :tag "Access Key(s)")
  514. (string :tag "Description ")))))
  515. (defcustom org-agenda-query-register ?o
  516. "The register holding the current query string.
  517. The purpose of this is that if you construct a query string interactively,
  518. you can then use it to define a custom command."
  519. :group 'org-agenda-custom-commands
  520. :type 'character)
  521. (defcustom org-stuck-projects
  522. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  523. "How to identify stuck projects.
  524. This is a list of four items:
  525. 1. A tags/todo/property matcher string that is used to identify a project.
  526. See the manual for a description of tag and property searches.
  527. The entire tree below a headline matched by this is considered one project.
  528. 2. A list of TODO keywords identifying non-stuck projects.
  529. If the project subtree contains any headline with one of these todo
  530. keywords, the project is considered to be not stuck. If you specify
  531. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  532. 3. A list of tags identifying non-stuck projects.
  533. If the project subtree contains any headline with one of these tags,
  534. the project is considered to be not stuck. If you specify \"*\" as
  535. a tag, any tag will mark the project unstuck. Note that this is about
  536. the explicit presence of a tag somewhere in the subtree, inherited
  537. tags do not count here. If inherited tags make a project not stuck,
  538. use \"-TAG\" in the tags part of the matcher under (1.) above.
  539. 4. An arbitrary regular expression matching non-stuck projects.
  540. If the project turns out to be not stuck, search continues also in the
  541. subtree to see if any of the subtasks have project status.
  542. See also the variable `org-tags-match-list-sublevels' which applies
  543. to projects matched by this search as well.
  544. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  545. or `C-c a #' to produce the list."
  546. :group 'org-agenda-custom-commands
  547. :type '(list
  548. (string :tag "Tags/TODO match to identify a project")
  549. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  550. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  551. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  552. (defcustom org-agenda-filter-effort-default-operator "<"
  553. "The default operator for effort estimate filtering.
  554. If you select an effort estimate limit without first pressing an operator,
  555. this one will be used."
  556. :group 'org-agenda-custom-commands
  557. :type '(choice (const :tag "less or equal" "<")
  558. (const :tag "greater or equal"">")
  559. (const :tag "equal" "=")))
  560. (defgroup org-agenda-skip nil
  561. "Options concerning skipping parts of agenda files."
  562. :tag "Org Agenda Skip"
  563. :group 'org-agenda)
  564. (defcustom org-agenda-skip-function-global nil
  565. "Function to be called at each match during agenda construction.
  566. If this function returns nil, the current match should not be skipped.
  567. If the function decided to skip an agenda match, is must return the
  568. buffer position from which the search should be continued.
  569. This may also be a Lisp form, which will be evaluated.
  570. This variable will be applied to every agenda match, including
  571. tags/property searches and TODO lists. So try to make the test function
  572. do its checking as efficiently as possible. To implement a skipping
  573. condition just for specific agenda commands, use the variable
  574. `org-agenda-skip-function' which can be set in the options section
  575. of custom agenda commands."
  576. :group 'org-agenda-skip
  577. :type 'sexp)
  578. (defgroup org-agenda-daily/weekly nil
  579. "Options concerning the daily/weekly agenda."
  580. :tag "Org Agenda Daily/Weekly"
  581. :group 'org-agenda)
  582. (defgroup org-agenda-todo-list nil
  583. "Options concerning the global todo list agenda view."
  584. :tag "Org Agenda Todo List"
  585. :group 'org-agenda)
  586. (defgroup org-agenda-match-view nil
  587. "Options concerning the general tags/property/todo match agenda view."
  588. :tag "Org Agenda Match View"
  589. :group 'org-agenda)
  590. (defgroup org-agenda-search-view nil
  591. "Options concerning the search agenda view."
  592. :tag "Org Agenda Search View"
  593. :group 'org-agenda)
  594. (defvar org-agenda-archives-mode nil
  595. "Non-nil means the agenda will include archived items.
  596. If this is the symbol `trees', trees in the selected agenda scope
  597. that are marked with the ARCHIVE tag will be included anyway. When this is
  598. t, also all archive files associated with the current selection of agenda
  599. files will be included.")
  600. (defcustom org-agenda-restriction-lock-highlight-subtree t
  601. "Non-nil means highlight the whole subtree when restriction is active.
  602. Otherwise only highlight the headline. Highlighting the whole subtree is
  603. useful to ensure no edits happen beyond the restricted region."
  604. :group 'org-agenda
  605. :type 'boolean)
  606. (defcustom org-agenda-skip-comment-trees t
  607. "Non-nil means skip trees that start with the COMMENT keyword.
  608. When nil, these trees are also scanned by agenda commands."
  609. :group 'org-agenda-skip
  610. :type 'boolean)
  611. (defcustom org-agenda-todo-list-sublevels t
  612. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  613. When nil, the sublevels of a TODO entry are not checked, resulting in
  614. potentially much shorter TODO lists."
  615. :group 'org-agenda-skip
  616. :group 'org-agenda-todo-list
  617. :type 'boolean)
  618. (defcustom org-agenda-todo-ignore-with-date nil
  619. "Non-nil means don't show entries with a date in the global todo list.
  620. You can use this if you prefer to mark mere appointments with a TODO keyword,
  621. but don't want them to show up in the TODO list.
  622. When this is set, it also covers deadlines and scheduled items, the settings
  623. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  624. will be ignored.
  625. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  626. :group 'org-agenda-skip
  627. :group 'org-agenda-todo-list
  628. :type 'boolean)
  629. (defcustom org-agenda-todo-ignore-timestamp nil
  630. "Non-nil means don't show entries with a timestamp.
  631. This applies when creating the global todo list.
  632. Valid values are:
  633. past Don't show entries for today or in the past.
  634. future Don't show entries with a timestamp in the future.
  635. The idea behind this is that if it has a future
  636. timestamp, you don't want to think about it until the
  637. date.
  638. all Don't show any entries with a timestamp in the global todo list.
  639. The idea behind this is that by setting a timestamp, you
  640. have already \"taken care\" of this item.
  641. This variable can also have an integer as a value. If positive (N),
  642. todos with a timestamp N or more days in the future will be ignored. If
  643. negative (-N), todos with a timestamp N or more days in the past will be
  644. ignored. If 0, todos with a timestamp either today or in the future will
  645. be ignored. For example, a value of -1 will exclude todos with a
  646. timestamp in the past (yesterday or earlier), while a value of 7 will
  647. exclude todos with a timestamp a week or more in the future.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :version "24.1"
  654. :type '(choice
  655. (const :tag "Ignore future timestamp todos" future)
  656. (const :tag "Ignore past or present timestamp todos" past)
  657. (const :tag "Ignore all timestamp todos" all)
  658. (const :tag "Show timestamp todos" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-scheduled nil
  661. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  662. This applies when creating the global todo list.
  663. Valid values are:
  664. past Don't show entries scheduled today or in the past.
  665. future Don't show entries scheduled in the future.
  666. The idea behind this is that by scheduling it, you don't want to
  667. think about it until the scheduled date.
  668. all Don't show any scheduled entries in the global todo list.
  669. The idea behind this is that by scheduling it, you have already
  670. \"taken care\" of this item.
  671. t Same as `all', for backward compatibility.
  672. This variable can also have an integer as a value. See
  673. `org-agenda-todo-ignore-timestamp' for more details.
  674. See also `org-agenda-todo-ignore-with-date'.
  675. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  676. to make his option also apply to the tags-todo list."
  677. :group 'org-agenda-skip
  678. :group 'org-agenda-todo-list
  679. :type '(choice
  680. (const :tag "Ignore future-scheduled todos" future)
  681. (const :tag "Ignore past- or present-scheduled todos" past)
  682. (const :tag "Ignore all scheduled todos" all)
  683. (const :tag "Ignore all scheduled todos (compatibility)" t)
  684. (const :tag "Show scheduled todos" nil)
  685. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  686. (defcustom org-agenda-todo-ignore-deadlines nil
  687. "Non-nil means ignore some deadline TODO items when making TODO list.
  688. There are different motivations for using different values, please think
  689. carefully when configuring this variable.
  690. This applies when creating the global todo list.
  691. Valid values are:
  692. near Don't show near deadline entries. A deadline is near when it is
  693. closer than `org-deadline-warning-days' days. The idea behind this
  694. is that such items will appear in the agenda anyway.
  695. far Don't show TODO entries where a deadline has been defined, but
  696. the deadline is not near. This is useful if you don't want to
  697. use the todo list to figure out what to do now.
  698. past Don't show entries with a deadline timestamp for today or in the past.
  699. future Don't show entries with a deadline timestamp in the future, not even
  700. when they become `near' ones. Use it with caution.
  701. all Ignore all TODO entries that do have a deadline.
  702. t Same as `near', for backward compatibility.
  703. This variable can also have an integer as a value. See
  704. `org-agenda-todo-ignore-timestamp' for more details.
  705. See also `org-agenda-todo-ignore-with-date'.
  706. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  707. to make his option also apply to the tags-todo list."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-todo-list
  710. :type '(choice
  711. (const :tag "Ignore near deadlines" near)
  712. (const :tag "Ignore near deadlines (compatibility)" t)
  713. (const :tag "Ignore far deadlines" far)
  714. (const :tag "Ignore all TODOs with a deadlines" all)
  715. (const :tag "Show all TODOs, even if they have a deadline" nil)
  716. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  717. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  718. "Time unit to use when possibly ignoring an agenda item.
  719. See the docstring of various `org-agenda-todo-ignore-*' options.
  720. The default is to compare time stamps using days. An item is thus
  721. considered to be in the future if it is at least one day after today.
  722. Non-nil means to compare time stamps using seconds. An item is then
  723. considered future if it has a time value later than current time."
  724. :group 'org-agenda-skip
  725. :group 'org-agenda-todo-list
  726. :version "24.4"
  727. :package-version '(Org . "8.0")
  728. :type '(choice
  729. (const :tag "Compare time with days" nil)
  730. (const :tag "Compare time with seconds" t)))
  731. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  732. "Non-nil means honor todo-list ignores options also in tags-todo search.
  733. The variables
  734. `org-agenda-todo-ignore-with-date',
  735. `org-agenda-todo-ignore-timestamp',
  736. `org-agenda-todo-ignore-scheduled',
  737. `org-agenda-todo-ignore-deadlines'
  738. make the global TODO list skip entries that have time stamps of certain
  739. kinds. If this option is set, the same options will also apply for the
  740. tags-todo search, which is the general tags/property matcher
  741. restricted to unfinished TODO entries only."
  742. :group 'org-agenda-skip
  743. :group 'org-agenda-todo-list
  744. :group 'org-agenda-match-view
  745. :type 'boolean)
  746. (defcustom org-agenda-skip-scheduled-if-done nil
  747. "Non-nil means don't show scheduled items in agenda when they are done.
  748. This is relevant for the daily/weekly agenda, not for the TODO list. And
  749. it applies only to the actual date of the scheduling. Warnings about
  750. an item with a past scheduling dates are always turned off when the item
  751. is DONE."
  752. :group 'org-agenda-skip
  753. :group 'org-agenda-daily/weekly
  754. :type 'boolean)
  755. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  756. "Non-nil means skip scheduling line if same entry shows because of deadline.
  757. In the agenda of today, an entry can show up multiple times
  758. because it is both scheduled and has a nearby deadline, and maybe
  759. a plain time stamp as well.
  760. When this variable is nil, the entry will be shown several times.
  761. When set to t, then only the deadline is shown and the fact that
  762. the entry is scheduled today or was scheduled previously is not
  763. shown.
  764. When set to the symbol `not-today', skip scheduled previously,
  765. but not scheduled today.
  766. When set to the symbol `repeated-after-deadline', skip scheduled
  767. items if they are repeated beyond the current deadline."
  768. :group 'org-agenda-skip
  769. :group 'org-agenda-daily/weekly
  770. :type '(choice
  771. (const :tag "Never" nil)
  772. (const :tag "Always" t)
  773. (const :tag "Not when scheduled today" not-today)
  774. (const :tag "When repeated past deadline" repeated-after-deadline)))
  775. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  776. "Non-nil means skip timestamp line if same entry shows because of deadline.
  777. In the agenda of today, an entry can show up multiple times
  778. because it has both a plain timestamp and has a nearby deadline.
  779. When this variable is t, then only the deadline is shown and the
  780. fact that the entry has a timestamp for or including today is not
  781. shown. When this variable is nil, the entry will be shown
  782. several times."
  783. :group 'org-agenda-skip
  784. :group 'org-agenda-daily/weekly
  785. :version "24.1"
  786. :type '(choice
  787. (const :tag "Never" nil)
  788. (const :tag "Always" t)))
  789. (defcustom org-agenda-skip-deadline-if-done nil
  790. "Non-nil means don't show deadlines when the corresponding item is done.
  791. When nil, the deadline is still shown and should give you a happy feeling.
  792. This is relevant for the daily/weekly agenda. And it applied only to the
  793. actually date of the deadline. Warnings about approaching and past-due
  794. deadlines are always turned off when the item is DONE."
  795. :group 'org-agenda-skip
  796. :group 'org-agenda-daily/weekly
  797. :type 'boolean)
  798. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  799. "Non-nil means skip deadline prewarning when entry is also scheduled.
  800. This will apply on all days where a prewarning for the deadline would
  801. be shown, but not at the day when the entry is actually due. On that day,
  802. the deadline will be shown anyway.
  803. This variable may be set to nil, t, the symbol `pre-scheduled',
  804. or a number which will then give the number of days before the actual
  805. deadline when the prewarnings should resume. The symbol `pre-scheduled'
  806. eliminates the deadline prewarning only prior to the scheduled date.
  807. This can be used in a workflow where the first showing of the deadline will
  808. trigger you to schedule it, and then you don't want to be reminded of it
  809. because you will take care of it on the day when scheduled."
  810. :group 'org-agenda-skip
  811. :group 'org-agenda-daily/weekly
  812. :version "24.1"
  813. :type '(choice
  814. (const :tag "Always show prewarning" nil)
  815. (const :tag "Remove prewarning prior to scheduled date" pre-scheduled)
  816. (const :tag "Remove prewarning if entry is scheduled" t)
  817. (integer :tag "Restart prewarning N days before deadline")))
  818. (defcustom org-agenda-skip-scheduled-delay-if-deadline nil
  819. "Non-nil means skip scheduled delay when entry also has a deadline.
  820. This variable may be set to nil, t, the symbol `post-deadline',
  821. or a number which will then give the number of days after the actual
  822. scheduled date when the delay should expire. The symbol `post-deadline'
  823. eliminates the schedule delay when the date is posterior to the deadline."
  824. :group 'org-agenda-skip
  825. :group 'org-agenda-daily/weekly
  826. :version "24.4"
  827. :package-version '(Org . "8.0")
  828. :type '(choice
  829. (const :tag "Always honor delay" nil)
  830. (const :tag "Ignore delay if posterior to the deadline" post-deadline)
  831. (const :tag "Ignore delay if entry has a deadline" t)
  832. (integer :tag "Honor delay up until N days after the scheduled date")))
  833. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  834. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  835. When non-nil, after the search for timestamps has matched once in an
  836. entry, the rest of the entry will not be searched."
  837. :group 'org-agenda-skip
  838. :type 'boolean)
  839. (defcustom org-agenda-skip-timestamp-if-done nil
  840. "Non-nil means don't select item by timestamp or -range if it is DONE."
  841. :group 'org-agenda-skip
  842. :group 'org-agenda-daily/weekly
  843. :type 'boolean)
  844. (defcustom org-agenda-dim-blocked-tasks t
  845. "Non-nil means dim blocked tasks in the agenda display.
  846. This causes some overhead during agenda construction, but if you
  847. have turned on `org-enforce-todo-dependencies',
  848. `org-enforce-todo-checkbox-dependencies', or any other blocking
  849. mechanism, this will create useful feedback in the agenda.
  850. Instead of t, this variable can also have the value `invisible'.
  851. Then blocked tasks will be invisible and only become visible when
  852. they become unblocked. An exemption to this behavior is when a task is
  853. blocked because of unchecked checkboxes below it. Since checkboxes do
  854. not show up in the agenda views, making this task invisible you remove any
  855. trace from agenda views that there is something to do. Therefore, a task
  856. that is blocked because of checkboxes will never be made invisible, it
  857. will only be dimmed."
  858. :group 'org-agenda-daily/weekly
  859. :group 'org-agenda-todo-list
  860. :version "24.3"
  861. :type '(choice
  862. (const :tag "Do not dim" nil)
  863. (const :tag "Dim to a gray face" t)
  864. (const :tag "Make invisible" invisible)))
  865. (defcustom org-timeline-show-empty-dates 3
  866. "Non-nil means `org-timeline' also shows dates without an entry.
  867. When nil, only the days which actually have entries are shown.
  868. When t, all days between the first and the last date are shown.
  869. When an integer, show also empty dates, but if there is a gap of more than
  870. N days, just insert a special line indicating the size of the gap."
  871. :group 'org-agenda-skip
  872. :type '(choice
  873. (const :tag "None" nil)
  874. (const :tag "All" t)
  875. (integer :tag "at most")))
  876. (defgroup org-agenda-startup nil
  877. "Options concerning initial settings in the Agenda in Org Mode."
  878. :tag "Org Agenda Startup"
  879. :group 'org-agenda)
  880. (defcustom org-agenda-menu-show-matcher t
  881. "Non-nil means show the match string in the agenda dispatcher menu.
  882. When nil, the matcher string is not shown, but is put into the help-echo
  883. property so than moving the mouse over the command shows it.
  884. Setting it to nil is good if matcher strings are very long and/or if
  885. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  886. :group 'org-agenda
  887. :version "24.1"
  888. :type 'boolean)
  889. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  890. (defcustom org-agenda-menu-two-columns nil
  891. "Non-nil means, use two columns to show custom commands in the dispatcher.
  892. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  893. to nil."
  894. :group 'org-agenda
  895. :version "24.1"
  896. :type 'boolean)
  897. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  898. (defcustom org-agenda-finalize-hook nil
  899. "Hook run just before displaying an agenda buffer.
  900. The buffer is still writable when the hook is called.
  901. You can modify some of the buffer substrings but you should be
  902. extra careful not to modify the text properties of the agenda
  903. headlines as the agenda display heavily relies on them."
  904. :group 'org-agenda-startup
  905. :type 'hook)
  906. (defcustom org-agenda-mouse-1-follows-link nil
  907. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  908. A longer mouse click will still set point. Does not work on XEmacs.
  909. Needs to be set before org.el is loaded."
  910. :group 'org-agenda-startup
  911. :type 'boolean)
  912. (defcustom org-agenda-start-with-follow-mode nil
  913. "The initial value of follow mode in a newly created agenda window."
  914. :group 'org-agenda-startup
  915. :type 'boolean)
  916. (defcustom org-agenda-follow-indirect nil
  917. "Non-nil means `org-agenda-follow-mode' displays only the
  918. current item's tree, in an indirect buffer."
  919. :group 'org-agenda
  920. :version "24.1"
  921. :type 'boolean)
  922. (defcustom org-agenda-show-outline-path t
  923. "Non-nil means show outline path in echo area after line motion."
  924. :group 'org-agenda-startup
  925. :type 'boolean)
  926. (defcustom org-agenda-start-with-entry-text-mode nil
  927. "The initial value of entry-text-mode in a newly created agenda window."
  928. :group 'org-agenda-startup
  929. :type 'boolean)
  930. (defcustom org-agenda-entry-text-maxlines 5
  931. "Number of text lines to be added when `E' is pressed in the agenda.
  932. Note that this variable only used during agenda display. Add add entry text
  933. when exporting the agenda, configure the variable
  934. `org-agenda-add-entry-ext-maxlines'."
  935. :group 'org-agenda
  936. :type 'integer)
  937. (defcustom org-agenda-entry-text-exclude-regexps nil
  938. "List of regular expressions to clean up entry text.
  939. The complete matches of all regular expressions in this list will be
  940. removed from entry text before it is shown in the agenda."
  941. :group 'org-agenda
  942. :type '(repeat (regexp)))
  943. (defcustom org-agenda-entry-text-leaders " > "
  944. "Text prepended to the entry text in agenda buffers."
  945. :version "24.4"
  946. :package-version '(Org . "8.0")
  947. :group 'org-agenda
  948. :type 'string)
  949. (defvar org-agenda-entry-text-cleanup-hook nil
  950. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  951. This cleanup is done in a temporary buffer, so the function may inspect and
  952. change the entire buffer.
  953. Some default stuff like drawers and scheduling/deadline dates will already
  954. have been removed when this is called, as will any matches for regular
  955. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  956. (defvar org-agenda-include-inactive-timestamps nil
  957. "Non-nil means include inactive time stamps in agenda and timeline.
  958. Dynamically scoped.")
  959. (defgroup org-agenda-windows nil
  960. "Options concerning the windows used by the Agenda in Org Mode."
  961. :tag "Org Agenda Windows"
  962. :group 'org-agenda)
  963. (defcustom org-agenda-window-setup 'reorganize-frame
  964. "How the agenda buffer should be displayed.
  965. Possible values for this option are:
  966. current-window Show agenda in the current window, keeping all other windows.
  967. other-window Use `switch-to-buffer-other-window' to display agenda.
  968. reorganize-frame Show only two windows on the current frame, the current
  969. window and the agenda.
  970. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  971. Also, when exiting the agenda, kill that frame.
  972. See also the variable `org-agenda-restore-windows-after-quit'."
  973. :group 'org-agenda-windows
  974. :type '(choice
  975. (const current-window)
  976. (const other-frame)
  977. (const other-window)
  978. (const reorganize-frame)))
  979. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  980. "The min and max height of the agenda window as a fraction of frame height.
  981. The value of the variable is a cons cell with two numbers between 0 and 1.
  982. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  983. :group 'org-agenda-windows
  984. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  985. (defcustom org-agenda-restore-windows-after-quit nil
  986. "Non-nil means restore window configuration upon exiting agenda.
  987. Before the window configuration is changed for displaying the agenda,
  988. the current status is recorded. When the agenda is exited with
  989. `q' or `x' and this option is set, the old state is restored. If
  990. `org-agenda-window-setup' is `other-frame', the value of this
  991. option will be ignored."
  992. :group 'org-agenda-windows
  993. :type 'boolean)
  994. (defcustom org-agenda-ndays nil
  995. "Number of days to include in overview display.
  996. Should be 1 or 7.
  997. Obsolete, see `org-agenda-span'."
  998. :group 'org-agenda-daily/weekly
  999. :type '(choice (const nil)
  1000. (integer)))
  1001. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  1002. (defcustom org-agenda-span 'week
  1003. "Number of days to include in overview display.
  1004. Can be day, week, month, year, or any number of days.
  1005. Custom commands can set this variable in the options section."
  1006. :group 'org-agenda-daily/weekly
  1007. :type '(choice (const :tag "Day" day)
  1008. (const :tag "Week" week)
  1009. (const :tag "Fortnight" fortnight)
  1010. (const :tag "Month" month)
  1011. (const :tag "Year" year)
  1012. (integer :tag "Custom")))
  1013. (defcustom org-agenda-start-on-weekday 1
  1014. "Non-nil means start the overview always on the specified weekday.
  1015. 0 denotes Sunday, 1 denotes Monday, etc.
  1016. When nil, always start on the current day.
  1017. Custom commands can set this variable in the options section."
  1018. :group 'org-agenda-daily/weekly
  1019. :type '(choice (const :tag "Today" nil)
  1020. (integer :tag "Weekday No.")))
  1021. (defcustom org-agenda-show-all-dates t
  1022. "Non-nil means `org-agenda' shows every day in the selected range.
  1023. When nil, only the days which actually have entries are shown."
  1024. :group 'org-agenda-daily/weekly
  1025. :type 'boolean)
  1026. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  1027. "Format string for displaying dates in the agenda.
  1028. Used by the daily/weekly agenda and by the timeline. This should be
  1029. a format string understood by `format-time-string', or a function returning
  1030. the formatted date as a string. The function must take a single argument,
  1031. a calendar-style date list like (month day year)."
  1032. :group 'org-agenda-daily/weekly
  1033. :type '(choice
  1034. (string :tag "Format string")
  1035. (function :tag "Function")))
  1036. (defun org-agenda-format-date-aligned (date)
  1037. "Format a DATE string for display in the daily/weekly agenda, or timeline.
  1038. This function makes sure that dates are aligned for easy reading."
  1039. (require 'cal-iso)
  1040. (let* ((dayname (calendar-day-name date))
  1041. (day (cadr date))
  1042. (day-of-week (calendar-day-of-week date))
  1043. (month (car date))
  1044. (monthname (calendar-month-name month))
  1045. (year (nth 2 date))
  1046. (iso-week (org-days-to-iso-week
  1047. (calendar-absolute-from-gregorian date)))
  1048. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  1049. (1- year))
  1050. ((and (= month 12) (<= iso-week 1))
  1051. (1+ year))
  1052. (t year)))
  1053. (weekstring (if (= day-of-week 1)
  1054. (format " W%02d" iso-week)
  1055. "")))
  1056. (format "%-10s %2d %s %4d%s"
  1057. dayname day monthname year weekstring)))
  1058. (defcustom org-agenda-time-leading-zero nil
  1059. "Non-nil means use leading zero for military times in agenda.
  1060. For example, 9:30am would become 09:30 rather than 9:30."
  1061. :group 'org-agenda-daily/weekly
  1062. :version "24.1"
  1063. :type 'boolean)
  1064. (defcustom org-agenda-timegrid-use-ampm nil
  1065. "When set, show AM/PM style timestamps on the timegrid."
  1066. :group 'org-agenda
  1067. :version "24.1"
  1068. :type 'boolean)
  1069. (defun org-agenda-time-of-day-to-ampm (time)
  1070. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  1071. (let* ((hour-number (string-to-number (substring time 0 -3)))
  1072. (minute (substring time -2))
  1073. (ampm "am"))
  1074. (cond
  1075. ((equal hour-number 12)
  1076. (setq ampm "pm"))
  1077. ((> hour-number 12)
  1078. (setq ampm "pm")
  1079. (setq hour-number (- hour-number 12))))
  1080. (concat
  1081. (if org-agenda-time-leading-zero
  1082. (format "%02d" hour-number)
  1083. (format "%02s" (number-to-string hour-number)))
  1084. ":" minute ampm)))
  1085. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  1086. "Conditionally convert TIME to AM/PM format based on `org-agenda-timegrid-use-ampm'."
  1087. (if org-agenda-timegrid-use-ampm
  1088. (org-agenda-time-of-day-to-ampm time)
  1089. time))
  1090. (defcustom org-agenda-weekend-days '(6 0)
  1091. "Which days are weekend?
  1092. These days get the special face `org-agenda-date-weekend' in the agenda
  1093. and timeline buffers."
  1094. :group 'org-agenda-daily/weekly
  1095. :type '(set :greedy t
  1096. (const :tag "Monday" 1)
  1097. (const :tag "Tuesday" 2)
  1098. (const :tag "Wednesday" 3)
  1099. (const :tag "Thursday" 4)
  1100. (const :tag "Friday" 5)
  1101. (const :tag "Saturday" 6)
  1102. (const :tag "Sunday" 0)))
  1103. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1104. "Non-nil means jump to today when moving a past date forward in time.
  1105. When using S-right in the agenda to move a a date forward, and the date
  1106. stamp currently points to the past, the first key press will move it
  1107. to today. WHen nil, just move one day forward even if the date stays
  1108. in the past."
  1109. :group 'org-agenda-daily/weekly
  1110. :version "24.1"
  1111. :type 'boolean)
  1112. (defcustom org-agenda-include-diary nil
  1113. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1114. Custom commands can set this variable in the options section."
  1115. :group 'org-agenda-daily/weekly
  1116. :type 'boolean)
  1117. (defcustom org-agenda-include-deadlines t
  1118. "If non-nil, include entries within their deadline warning period.
  1119. Custom commands can set this variable in the options section."
  1120. :group 'org-agenda-daily/weekly
  1121. :version "24.1"
  1122. :type 'boolean)
  1123. (defcustom org-agenda-repeating-timestamp-show-all t
  1124. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1125. When set to a list of strings, only show occurrences of repeating
  1126. stamps for these TODO keywords. When nil, only one occurrence is
  1127. shown, either today or the nearest into the future."
  1128. :group 'org-agenda-daily/weekly
  1129. :type '(choice
  1130. (const :tag "Show repeating stamps" t)
  1131. (repeat :tag "Show repeating stamps for these TODO keywords"
  1132. (string :tag "TODO Keyword"))
  1133. (const :tag "Don't show repeating stamps" nil)))
  1134. (defcustom org-scheduled-past-days 10000
  1135. "Number of days to continue listing scheduled items not marked DONE.
  1136. When an item is scheduled on a date, it shows up in the agenda on this
  1137. day and will be listed until it is marked done for the number of days
  1138. given here."
  1139. :group 'org-agenda-daily/weekly
  1140. :type 'integer)
  1141. (defcustom org-agenda-log-mode-items '(closed clock)
  1142. "List of items that should be shown in agenda log mode.
  1143. This list may contain the following symbols:
  1144. closed Show entries that have been closed on that day.
  1145. clock Show entries that have received clocked time on that day.
  1146. state Show all logged state changes.
  1147. Note that instead of changing this variable, you can also press `C-u l' in
  1148. the agenda to display all available LOG items temporarily."
  1149. :group 'org-agenda-daily/weekly
  1150. :type '(set :greedy t (const closed) (const clock) (const state)))
  1151. (defcustom org-agenda-clock-consistency-checks
  1152. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1153. :gap-ok-around ("4:00")
  1154. :default-face ((:background "DarkRed") (:foreground "white"))
  1155. :overlap-face nil :gap-face nil :no-end-time-face nil
  1156. :long-face nil :short-face nil)
  1157. "This is a property list, with the following keys:
  1158. :max-duration Mark clocking chunks that are longer than this time.
  1159. This is a time string like \"HH:MM\", or the number
  1160. of minutes as an integer.
  1161. :min-duration Mark clocking chunks that are shorter that this.
  1162. This is a time string like \"HH:MM\", or the number
  1163. of minutes as an integer.
  1164. :max-gap Mark gaps between clocking chunks that are longer than
  1165. this duration. A number of minutes, or a string
  1166. like \"HH:MM\".
  1167. :gap-ok-around List of times during the day which are usually not working
  1168. times. When a gap is detected, but the gap contains any
  1169. of these times, the gap is *not* reported. For example,
  1170. if this is (\"4:00\" \"13:00\") then gaps that contain
  1171. 4:00 in the morning (i.e. the night) and 13:00
  1172. (i.e. a typical lunch time) do not cause a warning.
  1173. You should have at least one time during the night in this
  1174. list, or otherwise the first task each morning will trigger
  1175. a warning because it follows a long gap.
  1176. Furthermore, the following properties can be used to define faces for
  1177. issue display.
  1178. :default-face the default face, if the specific face is undefined
  1179. :overlap-face face for overlapping clocks
  1180. :gap-face face for gaps between clocks
  1181. :no-end-time-face face for incomplete clocks
  1182. :long-face face for clock intervals that are too long
  1183. :short-face face for clock intervals that are too short"
  1184. :group 'org-agenda-daily/weekly
  1185. :group 'org-clock
  1186. :version "24.1"
  1187. :type 'plist)
  1188. (defcustom org-agenda-log-mode-add-notes t
  1189. "Non-nil means add first line of notes to log entries in agenda views.
  1190. If a log item like a state change or a clock entry is associated with
  1191. notes, the first line of these notes will be added to the entry in the
  1192. agenda display."
  1193. :group 'org-agenda-daily/weekly
  1194. :type 'boolean)
  1195. (defcustom org-agenda-start-with-log-mode nil
  1196. "The initial value of log-mode in a newly created agenda window.
  1197. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1198. explanations on the possible values."
  1199. :group 'org-agenda-startup
  1200. :group 'org-agenda-daily/weekly
  1201. :type '(choice (const :tag "Don't show log items" nil)
  1202. (const :tag "Show only log items" only)
  1203. (const :tag "Show all possible log items" clockcheck)
  1204. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1205. (choice (const :tag "Show closed log items" closed)
  1206. (const :tag "Show clocked log items" clock)
  1207. (const :tag "Show all logged state changes" state)))))
  1208. (defcustom org-agenda-start-with-clockreport-mode nil
  1209. "The initial value of clockreport-mode in a newly created agenda window."
  1210. :group 'org-agenda-startup
  1211. :group 'org-agenda-daily/weekly
  1212. :type 'boolean)
  1213. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1214. "Property list with parameters for the clocktable in clockreport mode.
  1215. This is the display mode that shows a clock table in the daily/weekly
  1216. agenda, the properties for this dynamic block can be set here.
  1217. The usual clocktable parameters are allowed here, but you cannot set
  1218. the properties :name, :tstart, :tend, :block, and :scope - these will
  1219. be overwritten to make sure the content accurately reflects the
  1220. current display in the agenda."
  1221. :group 'org-agenda-daily/weekly
  1222. :type 'plist)
  1223. (defcustom org-agenda-search-view-always-boolean nil
  1224. "Non-nil means the search string is interpreted as individual parts.
  1225. The search string for search view can either be interpreted as a phrase,
  1226. or as a list of snippets that define a boolean search for a number of
  1227. strings.
  1228. When this is non-nil, the string will be split on whitespace, and each
  1229. snippet will be searched individually, and all must match in order to
  1230. select an entry. A snippet is then a single string of non-white
  1231. characters, or a string in double quotes, or a regexp in {} braces.
  1232. If a snippet is preceded by \"-\", the snippet must *not* match.
  1233. \"+\" is syntactic sugar for positive selection. Each snippet may
  1234. be found as a full word or a partial word, but see the variable
  1235. `org-agenda-search-view-force-full-words'.
  1236. When this is nil, search will look for the entire search phrase as one,
  1237. with each space character matching any amount of whitespace, including
  1238. line breaks.
  1239. Even when this is nil, you can still switch to Boolean search dynamically
  1240. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1241. is a regexp marked with braces like \"{abc}\", this will also switch to
  1242. boolean search."
  1243. :group 'org-agenda-search-view
  1244. :version "24.1"
  1245. :type 'boolean)
  1246. (org-defvaralias 'org-agenda-search-view-search-words-only
  1247. 'org-agenda-search-view-always-boolean)
  1248. (defcustom org-agenda-search-view-force-full-words nil
  1249. "Non-nil means, search words must be matches as complete words.
  1250. When nil, they may also match part of a word."
  1251. :group 'org-agenda-search-view
  1252. :version "24.1"
  1253. :type 'boolean)
  1254. (defcustom org-agenda-search-view-max-outline-level 0
  1255. "Maximum outline level to display in search view.
  1256. E.g. when this is set to 1, the search view will only
  1257. show headlines of level 1. When set to 0, the default
  1258. value, don't limit agenda view by outline level."
  1259. :group 'org-agenda-search-view
  1260. :version "24.4"
  1261. :package-version '(Org . "8.3")
  1262. :type 'integer)
  1263. (defgroup org-agenda-time-grid nil
  1264. "Options concerning the time grid in the Org-mode Agenda."
  1265. :tag "Org Agenda Time Grid"
  1266. :group 'org-agenda)
  1267. (defcustom org-agenda-search-headline-for-time t
  1268. "Non-nil means search headline for a time-of-day.
  1269. If the headline contains a time-of-day in one format or another, it will
  1270. be used to sort the entry into the time sequence of items for a day.
  1271. Some people have time stamps in the headline that refer to the creation
  1272. time or so, and then this produces an unwanted side effect. If this is
  1273. the case for your, use this variable to turn off searching the headline
  1274. for a time."
  1275. :group 'org-agenda-time-grid
  1276. :type 'boolean)
  1277. (defcustom org-agenda-use-time-grid t
  1278. "Non-nil means show a time grid in the agenda schedule.
  1279. A time grid is a set of lines for specific times (like every two hours between
  1280. 8:00 and 20:00). The items scheduled for a day at specific times are
  1281. sorted in between these lines.
  1282. For details about when the grid will be shown, and what it will look like, see
  1283. the variable `org-agenda-time-grid'."
  1284. :group 'org-agenda-time-grid
  1285. :type 'boolean)
  1286. (defcustom org-agenda-time-grid
  1287. '((daily today require-timed)
  1288. "----------------"
  1289. (800 1000 1200 1400 1600 1800 2000))
  1290. "The settings for time grid for agenda display.
  1291. This is a list of three items. The first item is again a list. It contains
  1292. symbols specifying conditions when the grid should be displayed:
  1293. daily if the agenda shows a single day
  1294. weekly if the agenda shows an entire week
  1295. today show grid on current date, independent of daily/weekly display
  1296. require-timed show grid only if at least one item has a time specification
  1297. The second item is a string which will be placed behind the grid time.
  1298. The third item is a list of integers, indicating the times that should have
  1299. a grid line."
  1300. :group 'org-agenda-time-grid
  1301. :type
  1302. '(list
  1303. (set :greedy t :tag "Grid Display Options"
  1304. (const :tag "Show grid in single day agenda display" daily)
  1305. (const :tag "Show grid in weekly agenda display" weekly)
  1306. (const :tag "Always show grid for today" today)
  1307. (const :tag "Show grid only if any timed entries are present"
  1308. require-timed)
  1309. (const :tag "Skip grid times already present in an entry"
  1310. remove-match))
  1311. (string :tag "Grid String")
  1312. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1313. (defcustom org-agenda-show-current-time-in-grid t
  1314. "Non-nil means show the current time in the time grid."
  1315. :group 'org-agenda-time-grid
  1316. :version "24.1"
  1317. :type 'boolean)
  1318. (defcustom org-agenda-current-time-string
  1319. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1320. "The string for the current time marker in the agenda."
  1321. :group 'org-agenda-time-grid
  1322. :version "24.1"
  1323. :type 'string)
  1324. (defgroup org-agenda-sorting nil
  1325. "Options concerning sorting in the Org-mode Agenda."
  1326. :tag "Org Agenda Sorting"
  1327. :group 'org-agenda)
  1328. (defcustom org-agenda-sorting-strategy
  1329. '((agenda habit-down time-up priority-down category-keep)
  1330. (todo priority-down category-keep)
  1331. (tags priority-down category-keep)
  1332. (search category-keep))
  1333. "Sorting structure for the agenda items of a single day.
  1334. This is a list of symbols which will be used in sequence to determine
  1335. if an entry should be listed before another entry. The following
  1336. symbols are recognized:
  1337. time-up Put entries with time-of-day indications first, early first
  1338. time-down Put entries with time-of-day indications first, late first
  1339. timestamp-up Sort by any timestamp, early first
  1340. timestamp-down Sort by any timestamp, late first
  1341. scheduled-up Sort by scheduled timestamp, early first
  1342. scheduled-down Sort by scheduled timestamp, late first
  1343. deadline-up Sort by deadline timestamp, early first
  1344. deadline-down Sort by deadline timestamp, late first
  1345. ts-up Sort by active timestamp, early first
  1346. ts-down Sort by active timestamp, late first
  1347. tsia-up Sort by inactive timestamp, early first
  1348. tsia-down Sort by inactive timestamp, late first
  1349. category-keep Keep the default order of categories, corresponding to the
  1350. sequence in `org-agenda-files'.
  1351. category-up Sort alphabetically by category, A-Z.
  1352. category-down Sort alphabetically by category, Z-A.
  1353. tag-up Sort alphabetically by last tag, A-Z.
  1354. tag-down Sort alphabetically by last tag, Z-A.
  1355. priority-up Sort numerically by priority, high priority last.
  1356. priority-down Sort numerically by priority, high priority first.
  1357. todo-state-up Sort by todo state, tasks that are done last.
  1358. todo-state-down Sort by todo state, tasks that are done first.
  1359. effort-up Sort numerically by estimated effort, high effort last.
  1360. effort-down Sort numerically by estimated effort, high effort first.
  1361. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1362. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1363. habit-up Put entries that are habits first
  1364. habit-down Put entries that are habits last
  1365. alpha-up Sort headlines alphabetically
  1366. alpha-down Sort headlines alphabetically, reversed
  1367. The different possibilities will be tried in sequence, and testing stops
  1368. if one comparison returns a \"not-equal\". For example, the default
  1369. '(time-up category-keep priority-down)
  1370. means: Pull out all entries having a specified time of day and sort them,
  1371. in order to make a time schedule for the current day the first thing in the
  1372. agenda listing for the day. Of the entries without a time indication, keep
  1373. the grouped in categories, don't sort the categories, but keep them in
  1374. the sequence given in `org-agenda-files'. Within each category sort by
  1375. priority.
  1376. Leaving out `category-keep' would mean that items will be sorted across
  1377. categories by priority.
  1378. Instead of a single list, this can also be a set of list for specific
  1379. contents, with a context symbol in the car of the list, any of
  1380. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1381. Custom commands can bind this variable in the options section."
  1382. :group 'org-agenda-sorting
  1383. :type `(choice
  1384. (repeat :tag "General" ,org-sorting-choice)
  1385. (list :tag "Individually"
  1386. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1387. (repeat ,org-sorting-choice))
  1388. (cons (const :tag "Strategy for TODO lists" todo)
  1389. (repeat ,org-sorting-choice))
  1390. (cons (const :tag "Strategy for Tags matches" tags)
  1391. (repeat ,org-sorting-choice))
  1392. (cons (const :tag "Strategy for search matches" search)
  1393. (repeat ,org-sorting-choice)))))
  1394. (defcustom org-agenda-cmp-user-defined nil
  1395. "A function to define the comparison `user-defined'.
  1396. This function must receive two arguments, agenda entry a and b.
  1397. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1398. the user comparison, return nil.
  1399. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1400. part of an agenda sorting strategy."
  1401. :group 'org-agenda-sorting
  1402. :type 'symbol)
  1403. (defcustom org-sort-agenda-notime-is-late t
  1404. "Non-nil means items without time are considered late.
  1405. This is only relevant for sorting. When t, items which have no explicit
  1406. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1407. do have a time. When nil, the default time is before 0:00. You can use this
  1408. option to decide if the schedule for today should come before or after timeless
  1409. agenda entries."
  1410. :group 'org-agenda-sorting
  1411. :type 'boolean)
  1412. (defcustom org-sort-agenda-noeffort-is-high t
  1413. "Non-nil means items without effort estimate are sorted as high effort.
  1414. This also applies when filtering an agenda view with respect to the
  1415. < or > effort operator. Then, tasks with no effort defined will be treated
  1416. as tasks with high effort.
  1417. When nil, such items are sorted as 0 minutes effort."
  1418. :group 'org-agenda-sorting
  1419. :type 'boolean)
  1420. (defgroup org-agenda-line-format nil
  1421. "Options concerning the entry prefix in the Org-mode agenda display."
  1422. :tag "Org Agenda Line Format"
  1423. :group 'org-agenda)
  1424. (defcustom org-agenda-prefix-format
  1425. '((agenda . " %i %-12:c%?-12t% s")
  1426. (timeline . " % s")
  1427. (todo . " %i %-12:c")
  1428. (tags . " %i %-12:c")
  1429. (search . " %i %-12:c"))
  1430. "Format specifications for the prefix of items in the agenda views.
  1431. An alist with five entries, each for the different agenda types. The
  1432. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1433. The values are format strings.
  1434. This format works similar to a printf format, with the following meaning:
  1435. %c the category of the item, \"Diary\" for entries from the diary,
  1436. or as given by the CATEGORY keyword or derived from the file name
  1437. %e the effort required by the item
  1438. %l the level of the item (insert X space(s) if item is of level X)
  1439. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1440. %T the last tag of the item (ignore inherited tags, which come first)
  1441. %t the HH:MM time-of-day specification if one applies to the entry
  1442. %s Scheduling/Deadline information, a short string
  1443. %b show breadcrumbs, i.e., the names of the higher levels
  1444. %(expression) Eval EXPRESSION and replace the control string
  1445. by the result
  1446. All specifiers work basically like the standard `%s' of printf, but may
  1447. contain two additional characters: a question mark just after the `%'
  1448. and a whitespace/punctuation character just before the final letter.
  1449. If the first character after `%' is a question mark, the entire field
  1450. will only be included if the corresponding value applies to the current
  1451. entry. This is useful for fields which should have fixed width when
  1452. present, but zero width when absent. For example, \"%?-12t\" will
  1453. result in a 12 character time field if a time of the day is specified,
  1454. but will completely disappear in entries which do not contain a time.
  1455. If there is punctuation or whitespace character just before the
  1456. final format letter, this character will be appended to the field
  1457. value if the value is not empty. For example, the format
  1458. \"%-12:c\" leads to \"Diary: \" if the category is \"Diary\". If
  1459. the category is empty, no additional colon is inserted.
  1460. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1461. which means:
  1462. - Indent the line with two space characters
  1463. - Give the category a 12 chars wide field, padded with whitespace on
  1464. the right (because of `-'). Append a colon if there is a category
  1465. (because of `:').
  1466. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1467. time, don't put in an empty field, just skip it (because of '?').
  1468. - Finally, put the scheduling information.
  1469. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1470. `org-agenda-remove-tags'.
  1471. Custom commands can set this variable in the options section."
  1472. :type '(choice
  1473. (string :tag "General format")
  1474. (list :greedy t :tag "View dependent"
  1475. (cons (const agenda) (string :tag "Format"))
  1476. (cons (const timeline) (string :tag "Format"))
  1477. (cons (const todo) (string :tag "Format"))
  1478. (cons (const tags) (string :tag "Format"))
  1479. (cons (const search) (string :tag "Format"))))
  1480. :group 'org-agenda-line-format)
  1481. (defvar org-prefix-format-compiled nil
  1482. "The compiled prefix format and associated variables.
  1483. This is a list where first element is a list of variable bindings, and second
  1484. element is the compiled format expression. See the variable
  1485. `org-agenda-prefix-format'.")
  1486. (defcustom org-agenda-todo-keyword-format "%-1s"
  1487. "Format for the TODO keyword in agenda lines.
  1488. Set this to something like \"%-12s\" if you want all TODO keywords
  1489. to occupy a fixed space in the agenda display."
  1490. :group 'org-agenda-line-format
  1491. :type 'string)
  1492. (defcustom org-agenda-diary-sexp-prefix nil
  1493. "A regexp that matches part of a diary sexp entry
  1494. which should be treated as scheduling/deadline information in
  1495. `org-agenda'.
  1496. For example, you can use this to extract the `diary-remind-message' from
  1497. `diary-remind' entries."
  1498. :group 'org-agenda-line-format
  1499. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1500. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1501. "Text preceding timerange entries in the agenda view.
  1502. This is a list with two strings. The first applies when the range
  1503. is entirely on one day. The second applies if the range spans several days.
  1504. The strings may have two \"%d\" format specifiers which will be filled
  1505. with the sequence number of the days, and the total number of days in the
  1506. range, respectively."
  1507. :group 'org-agenda-line-format
  1508. :type '(list
  1509. (string :tag "Deadline today ")
  1510. (choice :tag "Deadline relative"
  1511. (string :tag "Format string")
  1512. (function))))
  1513. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1514. "Text preceding scheduled items in the agenda view.
  1515. This is a list with two strings. The first applies when the item is
  1516. scheduled on the current day. The second applies when it has been scheduled
  1517. previously, it may contain a %d indicating that this is the nth time that
  1518. this item is scheduled, due to automatic rescheduling of unfinished items
  1519. for the following day. So this number is one larger than the number of days
  1520. that passed since this item was scheduled first."
  1521. :group 'org-agenda-line-format
  1522. :version "24.4"
  1523. :package-version '(Org . "8.0")
  1524. :type '(list
  1525. (string :tag "Scheduled today ")
  1526. (string :tag "Scheduled previously")))
  1527. (defcustom org-agenda-inactive-leader "["
  1528. "Text preceding item pulled into the agenda by inactive time stamps.
  1529. These entries are added to the agenda when pressing \"[\"."
  1530. :group 'org-agenda-line-format
  1531. :version "24.1"
  1532. :type 'string)
  1533. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: " "%2d d. ago: ")
  1534. "Text preceding deadline items in the agenda view.
  1535. This is a list with three strings. The first applies when the item has its
  1536. deadline on the current day. The second applies when the deadline is in the
  1537. future, the third one when it is in the past. The strings may contain %d
  1538. to capture the number of days."
  1539. :group 'org-agenda-line-format
  1540. :version "24.4"
  1541. :package-version '(Org . "8.0")
  1542. :type '(list
  1543. (string :tag "Deadline today ")
  1544. (string :tag "Deadline in the future ")
  1545. (string :tag "Deadline in the past ")))
  1546. (defcustom org-agenda-remove-times-when-in-prefix t
  1547. "Non-nil means remove duplicate time specifications in agenda items.
  1548. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1549. time-of-day specification in a headline or diary entry is extracted and
  1550. placed into the prefix. If this option is non-nil, the original specification
  1551. \(a timestamp or -range, or just a plain time(range) specification like
  1552. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1553. cluttered.
  1554. The option can be t or nil. It may also be the symbol `beg', indicating
  1555. that the time should only be removed when it is located at the beginning of
  1556. the headline/diary entry."
  1557. :group 'org-agenda-line-format
  1558. :type '(choice
  1559. (const :tag "Always" t)
  1560. (const :tag "Never" nil)
  1561. (const :tag "When at beginning of entry" beg)))
  1562. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1563. "Non-nil means remove time ranges specifications in agenda
  1564. items that span on several days."
  1565. :group 'org-agenda-line-format
  1566. :version "24.1"
  1567. :type 'boolean)
  1568. (defcustom org-agenda-default-appointment-duration nil
  1569. "Default duration for appointments that only have a starting time.
  1570. When nil, no duration is specified in such cases.
  1571. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1572. :group 'org-agenda-line-format
  1573. :type '(choice
  1574. (integer :tag "Minutes")
  1575. (const :tag "No default duration")))
  1576. (defcustom org-agenda-show-inherited-tags t
  1577. "Non-nil means show inherited tags in each agenda line.
  1578. When this option is set to 'always, it take precedences over
  1579. `org-agenda-use-tag-inheritance' and inherited tags are shown
  1580. in every agenda.
  1581. When this option is set to t (the default), inherited tags are
  1582. shown when they are available, i.e. when the value of
  1583. `org-agenda-use-tag-inheritance' has been taken into account.
  1584. This can be set to a list of agenda types in which the agenda
  1585. must display the inherited tags. Available types are 'todo,
  1586. 'agenda, 'search and 'timeline.
  1587. When set to nil, never show inherited tags in agenda lines."
  1588. :group 'org-agenda-line-format
  1589. :group 'org-agenda
  1590. :version "24.3"
  1591. :type '(choice
  1592. (const :tag "Show inherited tags when available" t)
  1593. (const :tag "Always show inherited tags" always)
  1594. (repeat :tag "Show inherited tags only in selected agenda types"
  1595. (symbol :tag "Agenda type"))))
  1596. (defcustom org-agenda-use-tag-inheritance '(todo search timeline agenda)
  1597. "List of agenda view types where to use tag inheritance.
  1598. In tags/tags-todo/tags-tree agenda views, tag inheritance is
  1599. controlled by `org-use-tag-inheritance'. In other agenda types,
  1600. `org-use-tag-inheritance' is not used for the selection of the
  1601. agenda entries. Still, you may want the agenda to be aware of
  1602. the inherited tags anyway, e.g. for later tag filtering.
  1603. Allowed value are 'todo, 'search, 'timeline and 'agenda.
  1604. This variable has no effect if `org-agenda-show-inherited-tags'
  1605. is set to 'always. In that case, the agenda is aware of those
  1606. tags.
  1607. The default value sets tags in every agenda type. Setting this
  1608. option to nil will speed up non-tags agenda view a lot."
  1609. :group 'org-agenda
  1610. :version "24.3"
  1611. :type '(choice
  1612. (const :tag "Use tag inheritance in all agenda types" t)
  1613. (repeat :tag "Use tag inheritance in selected agenda types"
  1614. (symbol :tag "Agenda type"))))
  1615. (defcustom org-agenda-hide-tags-regexp nil
  1616. "Regular expression used to filter away specific tags in agenda views.
  1617. This means that these tags will be present, but not be shown in the agenda
  1618. line. Secondary filtering will still work on the hidden tags.
  1619. Nil means don't hide any tags."
  1620. :group 'org-agenda-line-format
  1621. :type '(choice
  1622. (const :tag "Hide none" nil)
  1623. (string :tag "Regexp ")))
  1624. (defcustom org-agenda-remove-tags nil
  1625. "Non-nil means remove the tags from the headline copy in the agenda.
  1626. When this is the symbol `prefix', only remove tags when
  1627. `org-agenda-prefix-format' contains a `%T' specifier."
  1628. :group 'org-agenda-line-format
  1629. :type '(choice
  1630. (const :tag "Always" t)
  1631. (const :tag "Never" nil)
  1632. (const :tag "When prefix format contains %T" prefix)))
  1633. (org-defvaralias 'org-agenda-remove-tags-when-in-prefix
  1634. 'org-agenda-remove-tags)
  1635. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1636. "Shift tags in agenda items to this column.
  1637. If this number is positive, it specifies the column. If it is negative,
  1638. it means that the tags should be flushright to that column. For example,
  1639. -80 works well for a normal 80 character screen."
  1640. :group 'org-agenda-line-format
  1641. :type 'integer)
  1642. (org-defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column)
  1643. (defcustom org-agenda-fontify-priorities 'cookies
  1644. "Non-nil means highlight low and high priorities in agenda.
  1645. When t, the highest priority entries are bold, lowest priority italic.
  1646. However, settings in `org-priority-faces' will overrule these faces.
  1647. When this variable is the symbol `cookies', only fontify the
  1648. cookies, not the entire task.
  1649. This may also be an association list of priority faces, whose
  1650. keys are the character values of `org-highest-priority',
  1651. `org-default-priority', and `org-lowest-priority' (the default values
  1652. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1653. color as a string, or a list like `(:background \"Red\")'.
  1654. If it is a color, the variable `org-faces-easy-properties'
  1655. determines if it is a foreground or a background color."
  1656. :group 'org-agenda-line-format
  1657. :type '(choice
  1658. (const :tag "Never" nil)
  1659. (const :tag "Defaults" t)
  1660. (const :tag "Cookies only" cookies)
  1661. (repeat :tag "Specify"
  1662. (list (character :tag "Priority" :value ?A)
  1663. (choice :tag "Face "
  1664. (string :tag "Color")
  1665. (sexp :tag "Face"))))))
  1666. (defcustom org-agenda-day-face-function nil
  1667. "Function called to determine what face should be used to display a day.
  1668. The only argument passed to that function is the day. It should
  1669. returns a face, or nil if does not want to specify a face and let
  1670. the normal rules apply."
  1671. :group 'org-agenda-line-format
  1672. :version "24.1"
  1673. :type '(choice (const nil) (function)))
  1674. (defcustom org-agenda-category-icon-alist nil
  1675. "Alist of category icon to be displayed in agenda views.
  1676. Each entry should have the following format:
  1677. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1678. Where CATEGORY-REGEXP is a regexp matching the categories where
  1679. the icon should be displayed.
  1680. FILE-OR-DATA either a file path or a string containing image data.
  1681. The other fields can be omitted safely if not needed:
  1682. TYPE indicates the image type.
  1683. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1684. image data.
  1685. PROPS are additional image attributes to assign to the image,
  1686. like, e.g. `:ascent center'.
  1687. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1688. If you want to set the display properties yourself, just put a
  1689. list as second element:
  1690. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1691. For example, to display a 16px horizontal space for Emacs
  1692. category, you can use:
  1693. (\"Emacs\" '(space . (:width (16))))"
  1694. :group 'org-agenda-line-format
  1695. :version "24.1"
  1696. :type '(alist :key-type (string :tag "Regexp matching category")
  1697. :value-type (choice (list :tag "Icon"
  1698. (string :tag "File or data")
  1699. (symbol :tag "Type")
  1700. (boolean :tag "Data?")
  1701. (repeat :tag "Extra image properties" :inline t symbol))
  1702. (list :tag "Display properties" sexp))))
  1703. (defgroup org-agenda-column-view nil
  1704. "Options concerning column view in the agenda."
  1705. :tag "Org Agenda Column View"
  1706. :group 'org-agenda)
  1707. (defcustom org-agenda-columns-show-summaries t
  1708. "Non-nil means show summaries for columns displayed in the agenda view."
  1709. :group 'org-agenda-column-view
  1710. :type 'boolean)
  1711. (defcustom org-agenda-columns-compute-summary-properties t
  1712. "Non-nil means recompute all summary properties before column view.
  1713. When column view in the agenda is listing properties that have a summary
  1714. operator, it can go to all relevant buffers and recompute the summaries
  1715. there. This can mean overhead for the agenda column view, but is necessary
  1716. to have thing up to date.
  1717. As a special case, a CLOCKSUM property also makes sure that the clock
  1718. computations are current."
  1719. :group 'org-agenda-column-view
  1720. :type 'boolean)
  1721. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1722. "Non-nil means the duration of an appointment will add to day effort.
  1723. The property to which appointment durations will be added is the one given
  1724. in the option `org-effort-property'. If an appointment does not have
  1725. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1726. is not set, an appointment without end time will not contribute to the time
  1727. estimate."
  1728. :group 'org-agenda-column-view
  1729. :type 'boolean)
  1730. (defcustom org-agenda-auto-exclude-function nil
  1731. "A function called with a tag to decide if it is filtered on '/ RET'.
  1732. The sole argument to the function, which is called once for each
  1733. possible tag, is a string giving the name of the tag. The
  1734. function should return either nil if the tag should be included
  1735. as normal, or \"-<TAG>\" to exclude the tag.
  1736. Note that for the purpose of tag filtering, only the lower-case version of
  1737. all tags will be considered, so that this function will only ever see
  1738. the lower-case version of all tags."
  1739. :group 'org-agenda
  1740. :type '(choice (const nil) (function)))
  1741. (defcustom org-agenda-bulk-custom-functions nil
  1742. "Alist of characters and custom functions for bulk actions.
  1743. For example, this value makes those two functions available:
  1744. '((?R set-category)
  1745. (?C bulk-cut))
  1746. With selected entries in an agenda buffer, `B R' will call
  1747. the custom function `set-category' on the selected entries.
  1748. Note that functions in this alist don't need to be quoted."
  1749. :type 'alist
  1750. :version "24.1"
  1751. :group 'org-agenda)
  1752. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1753. "Execute BODY with point at location given by `org-hd-marker' property.
  1754. If STRING is non-nil, the text property will be fetched from position 0
  1755. in that string. If STRING is nil, it will be fetched from the beginning
  1756. of the current line."
  1757. (org-with-gensyms (marker)
  1758. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1759. 'org-hd-marker ,string)))
  1760. (with-current-buffer (marker-buffer ,marker)
  1761. (save-excursion
  1762. (goto-char ,marker)
  1763. ,@body)))))
  1764. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1765. (defun org-add-agenda-custom-command (entry)
  1766. "Replace or add a command in `org-agenda-custom-commands'.
  1767. This is mostly for hacking and trying a new command - once the command
  1768. works you probably want to add it to `org-agenda-custom-commands' for good."
  1769. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1770. (if ass
  1771. (setcdr ass (cdr entry))
  1772. (push entry org-agenda-custom-commands))))
  1773. ;;; Define the org-agenda-mode
  1774. (defvar org-agenda-mode-map (make-sparse-keymap)
  1775. "Keymap for `org-agenda-mode'.")
  1776. (org-defvaralias 'org-agenda-keymap 'org-agenda-mode-map)
  1777. (defvar org-agenda-menu) ; defined later in this file.
  1778. (defvar org-agenda-restrict nil) ; defined later in this file.
  1779. (defvar org-agenda-follow-mode nil)
  1780. (defvar org-agenda-entry-text-mode nil)
  1781. (defvar org-agenda-clockreport-mode nil)
  1782. (defvar org-agenda-show-log nil)
  1783. (defvar org-agenda-redo-command nil)
  1784. (defvar org-agenda-query-string nil)
  1785. (defvar org-agenda-mode-hook nil
  1786. "Hook run after `org-agenda-mode' is turned on.
  1787. The buffer is still writable when this hook is called.")
  1788. (defvar org-agenda-type nil)
  1789. (defvar org-agenda-force-single-file nil)
  1790. (defvar org-agenda-bulk-marked-entries nil
  1791. "List of markers that refer to marked entries in the agenda.")
  1792. ;;; Multiple agenda buffers support
  1793. (defcustom org-agenda-sticky nil
  1794. "Non-nil means agenda q key will bury agenda buffers.
  1795. Agenda commands will then show existing buffer instead of generating new ones.
  1796. When nil, `q' will kill the single agenda buffer."
  1797. :group 'org-agenda
  1798. :version "24.3"
  1799. :type 'boolean)
  1800. ;;;###autoload
  1801. (defun org-toggle-sticky-agenda (&optional arg)
  1802. "Toggle `org-agenda-sticky'."
  1803. (interactive "P")
  1804. (let ((new-value (if arg
  1805. (> (prefix-numeric-value arg) 0)
  1806. (not org-agenda-sticky))))
  1807. (if (equal new-value org-agenda-sticky)
  1808. (and (org-called-interactively-p 'interactive)
  1809. (message "Sticky agenda was already %s"
  1810. (if org-agenda-sticky "enabled" "disabled")))
  1811. (setq org-agenda-sticky new-value)
  1812. (org-agenda-kill-all-agenda-buffers)
  1813. (and (org-called-interactively-p 'interactive)
  1814. (message "Sticky agenda was %s"
  1815. (if org-agenda-sticky "enabled" "disabled"))))))
  1816. (defvar org-agenda-buffer nil
  1817. "Agenda buffer currently being generated.")
  1818. (defvar org-agenda-last-prefix-arg nil)
  1819. (defvar org-agenda-this-buffer-name nil)
  1820. (defvar org-agenda-doing-sticky-redo nil)
  1821. (defvar org-agenda-this-buffer-is-sticky nil)
  1822. (defconst org-agenda-local-vars
  1823. '(org-agenda-this-buffer-name
  1824. org-agenda-undo-list
  1825. org-agenda-pending-undo-list
  1826. org-agenda-follow-mode
  1827. org-agenda-entry-text-mode
  1828. org-agenda-clockreport-mode
  1829. org-agenda-show-log
  1830. org-agenda-redo-command
  1831. org-agenda-query-string
  1832. org-agenda-type
  1833. org-agenda-bulk-marked-entries
  1834. org-agenda-undo-has-started-in
  1835. org-agenda-info
  1836. org-agenda-pre-window-conf
  1837. org-agenda-columns-active
  1838. org-agenda-tag-filter
  1839. org-agenda-category-filter
  1840. org-agenda-top-headline-filter
  1841. org-agenda-regexp-filter
  1842. org-agenda-markers
  1843. org-agenda-last-search-view-search-was-boolean
  1844. org-agenda-filtered-by-category
  1845. org-agenda-filter-form
  1846. org-agenda-cycle-counter
  1847. org-agenda-last-prefix-arg)
  1848. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1849. (defun org-agenda-mode ()
  1850. "Mode for time-sorted view on action items in Org-mode files.
  1851. The following commands are available:
  1852. \\{org-agenda-mode-map}"
  1853. (interactive)
  1854. (cond (org-agenda-doing-sticky-redo
  1855. ;; Refreshing sticky agenda-buffer
  1856. ;;
  1857. ;; Preserve the value of `org-agenda-local-vars' variables,
  1858. ;; while letting `kill-all-local-variables' kill the rest
  1859. (let ((save (buffer-local-variables)))
  1860. (kill-all-local-variables)
  1861. (mapc 'make-local-variable org-agenda-local-vars)
  1862. (dolist (elem save)
  1863. (let ((var (car elem))
  1864. (val (cdr elem)))
  1865. (when (and val
  1866. (member var org-agenda-local-vars))
  1867. (set var val)))))
  1868. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1869. (org-agenda-sticky
  1870. ;; Creating a sticky Agenda buffer for the first time
  1871. (kill-all-local-variables)
  1872. (mapc 'make-local-variable org-agenda-local-vars)
  1873. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1874. (t
  1875. ;; Creating a non-sticky agenda buffer
  1876. (kill-all-local-variables)
  1877. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1878. (setq org-agenda-undo-list nil
  1879. org-agenda-pending-undo-list nil
  1880. org-agenda-bulk-marked-entries nil)
  1881. (setq major-mode 'org-agenda-mode)
  1882. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1883. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1884. (setq mode-name "Org-Agenda")
  1885. (setq indent-tabs-mode nil)
  1886. (use-local-map org-agenda-mode-map)
  1887. (easy-menu-add org-agenda-menu)
  1888. (if org-startup-truncated (setq truncate-lines t))
  1889. (org-set-local 'line-move-visual nil)
  1890. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1891. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1892. ;; Make sure properties are removed when copying text
  1893. (org-add-hook 'filter-buffer-substring-functions
  1894. (lambda (fun start end delete)
  1895. (substring-no-properties (funcall fun start end delete)))
  1896. nil t)
  1897. (unless org-agenda-keep-modes
  1898. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1899. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode))
  1900. (setq org-agenda-show-log org-agenda-start-with-log-mode)
  1901. (setq org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode)
  1902. (add-to-invisibility-spec '(org-filtered))
  1903. (add-to-invisibility-spec '(org-link))
  1904. (easy-menu-change
  1905. '("Agenda") "Agenda Files"
  1906. (append
  1907. (list
  1908. (vector
  1909. (if (get 'org-agenda-files 'org-restrict)
  1910. "Restricted to single file"
  1911. "Edit File List")
  1912. '(org-edit-agenda-file-list)
  1913. (not (get 'org-agenda-files 'org-restrict)))
  1914. "--")
  1915. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1916. (org-agenda-set-mode-name)
  1917. (apply
  1918. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1919. (list 'org-agenda-mode-hook)))
  1920. (substitute-key-definition 'undo 'org-agenda-undo
  1921. org-agenda-mode-map global-map)
  1922. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1923. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1924. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1925. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1926. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1927. (org-defkey org-agenda-mode-map [(meta down)] 'org-agenda-drag-line-forward)
  1928. (org-defkey org-agenda-mode-map [(meta up)] 'org-agenda-drag-line-backward)
  1929. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1930. (org-defkey org-agenda-mode-map "\M-m" 'org-agenda-bulk-toggle)
  1931. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1932. (org-defkey org-agenda-mode-map "\M-*" 'org-agenda-bulk-toggle-all)
  1933. (org-defkey org-agenda-mode-map "#" 'org-agenda-dim-blocked-tasks)
  1934. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1935. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1936. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1937. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1938. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1939. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1940. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1941. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1942. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1943. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1944. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1945. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1946. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1947. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1948. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1949. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1950. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1951. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1952. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1953. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1954. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1955. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1956. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1957. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1958. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1959. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1960. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1961. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1962. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1963. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1964. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1965. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1966. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1967. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1968. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1969. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1970. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1971. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1972. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1973. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1974. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1975. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1976. (while l (org-defkey org-agenda-mode-map
  1977. (int-to-string (pop l)) 'digit-argument)))
  1978. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1979. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1980. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1981. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1982. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1983. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1984. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1985. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1986. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1987. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1988. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1989. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1990. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1991. 'org-clock-modify-effort-estimate)
  1992. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1993. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1994. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1995. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1996. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1997. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1998. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1999. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  2000. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  2001. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  2002. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  2003. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  2004. (substitute-key-definition 'next-line 'org-agenda-next-line
  2005. org-agenda-mode-map global-map)
  2006. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  2007. org-agenda-mode-map global-map)
  2008. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  2009. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  2010. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  2011. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  2012. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  2013. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  2014. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  2015. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  2016. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  2017. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  2018. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  2019. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  2020. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  2021. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  2022. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  2023. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  2024. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  2025. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  2026. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  2027. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  2028. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  2029. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  2030. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  2031. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  2032. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  2033. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  2034. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  2035. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  2036. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  2037. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  2038. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  2039. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  2040. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  2041. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  2042. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  2043. (org-defkey org-agenda-mode-map "=" 'org-agenda-filter-by-regexp)
  2044. (org-defkey org-agenda-mode-map "|" 'org-agenda-filter-remove-all)
  2045. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  2046. (org-defkey org-agenda-mode-map "~" 'org-agenda-limit-interactively)
  2047. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  2048. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-headline)
  2049. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  2050. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  2051. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  2052. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  2053. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  2054. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  2055. (when org-agenda-mouse-1-follows-link
  2056. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  2057. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  2058. '("Agenda"
  2059. ("Agenda Files")
  2060. "--"
  2061. ("Agenda Dates"
  2062. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  2063. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  2064. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  2065. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  2066. "--"
  2067. ("View"
  2068. ["Day View" org-agenda-day-view
  2069. :active (org-agenda-check-type nil 'agenda)
  2070. :style radio :selected (eq org-agenda-current-span 'day)
  2071. :keys "v d (or just d)"]
  2072. ["Week View" org-agenda-week-view
  2073. :active (org-agenda-check-type nil 'agenda)
  2074. :style radio :selected (eq org-agenda-current-span 'week)
  2075. :keys "v w"]
  2076. ["Fortnight View" org-agenda-fortnight-view
  2077. :active (org-agenda-check-type nil 'agenda)
  2078. :style radio :selected (eq org-agenda-current-span 'fortnight)
  2079. :keys "v f"]
  2080. ["Month View" org-agenda-month-view
  2081. :active (org-agenda-check-type nil 'agenda)
  2082. :style radio :selected (eq org-agenda-current-span 'month)
  2083. :keys "v m"]
  2084. ["Year View" org-agenda-year-view
  2085. :active (org-agenda-check-type nil 'agenda)
  2086. :style radio :selected (eq org-agenda-current-span 'year)
  2087. :keys "v y"]
  2088. "--"
  2089. ["Include Diary" org-agenda-toggle-diary
  2090. :style toggle :selected org-agenda-include-diary
  2091. :active (org-agenda-check-type nil 'agenda)]
  2092. ["Include Deadlines" org-agenda-toggle-deadlines
  2093. :style toggle :selected org-agenda-include-deadlines
  2094. :active (org-agenda-check-type nil 'agenda)]
  2095. ["Use Time Grid" org-agenda-toggle-time-grid
  2096. :style toggle :selected org-agenda-use-time-grid
  2097. :active (org-agenda-check-type nil 'agenda)]
  2098. "--"
  2099. ["Show clock report" org-agenda-clockreport-mode
  2100. :style toggle :selected org-agenda-clockreport-mode
  2101. :active (org-agenda-check-type nil 'agenda)]
  2102. ["Show some entry text" org-agenda-entry-text-mode
  2103. :style toggle :selected org-agenda-entry-text-mode
  2104. :active t]
  2105. "--"
  2106. ["Show Logbook entries" org-agenda-log-mode
  2107. :style toggle :selected org-agenda-show-log
  2108. :active (org-agenda-check-type nil 'agenda 'timeline)
  2109. :keys "v l (or just l)"]
  2110. ["Include archived trees" org-agenda-archives-mode
  2111. :style toggle :selected org-agenda-archives-mode :active t
  2112. :keys "v a"]
  2113. ["Include archive files" (org-agenda-archives-mode t)
  2114. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  2115. :keys "v A"]
  2116. "--"
  2117. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  2118. ["Write view to file" org-agenda-write t]
  2119. ["Rebuild buffer" org-agenda-redo t]
  2120. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  2121. "--"
  2122. ["Show original entry" org-agenda-show t]
  2123. ["Go To (other window)" org-agenda-goto t]
  2124. ["Go To (this window)" org-agenda-switch-to t]
  2125. ["Capture with cursor date" org-agenda-capture t]
  2126. ["Follow Mode" org-agenda-follow-mode
  2127. :style toggle :selected org-agenda-follow-mode :active t]
  2128. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  2129. "--"
  2130. ("TODO"
  2131. ["Cycle TODO" org-agenda-todo t]
  2132. ["Next TODO set" org-agenda-todo-nextset t]
  2133. ["Previous TODO set" org-agenda-todo-previousset t]
  2134. ["Add note" org-agenda-add-note t])
  2135. ("Archive/Refile/Delete"
  2136. ["Archive default" org-agenda-archive-default t]
  2137. ["Archive default" org-agenda-archive-default-with-confirmation t]
  2138. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  2139. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  2140. ["Archive subtree" org-agenda-archive t]
  2141. "--"
  2142. ["Refile" org-agenda-refile t]
  2143. "--"
  2144. ["Delete subtree" org-agenda-kill t])
  2145. ("Bulk action"
  2146. ["Mark entry" org-agenda-bulk-mark t]
  2147. ["Mark all" org-agenda-bulk-mark-all t]
  2148. ["Unmark entry" org-agenda-bulk-unmark t]
  2149. ["Unmark all" org-agenda-bulk-unmark-all :active t :keys "U"]
  2150. ["Toggle mark" org-agenda-bulk-toggle t]
  2151. ["Toggle all" org-agenda-bulk-toggle-all t]
  2152. ["Mark regexp" org-agenda-bulk-mark-regexp t])
  2153. ["Act on all marked" org-agenda-bulk-action t]
  2154. "--"
  2155. ("Tags and Properties"
  2156. ["Show all Tags" org-agenda-show-tags t]
  2157. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2158. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2159. "--"
  2160. ["Column View" org-columns t])
  2161. ("Deadline/Schedule"
  2162. ["Schedule" org-agenda-schedule t]
  2163. ["Set Deadline" org-agenda-deadline t]
  2164. "--"
  2165. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2166. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2167. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2168. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2169. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2170. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2171. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2172. ("Clock and Effort"
  2173. ["Clock in" org-agenda-clock-in t]
  2174. ["Clock out" org-agenda-clock-out t]
  2175. ["Clock cancel" org-agenda-clock-cancel t]
  2176. ["Goto running clock" org-clock-goto t]
  2177. "--"
  2178. ["Set Effort" org-agenda-set-effort t]
  2179. ["Change clocked effort" org-clock-modify-effort-estimate
  2180. (org-clock-is-active)])
  2181. ("Priority"
  2182. ["Set Priority" org-agenda-priority t]
  2183. ["Increase Priority" org-agenda-priority-up t]
  2184. ["Decrease Priority" org-agenda-priority-down t]
  2185. ["Show Priority" org-show-priority t])
  2186. ("Calendar/Diary"
  2187. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2188. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2189. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2190. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2191. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2192. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2193. "--"
  2194. ["Create iCalendar File" org-icalendar-combine-agenda-files t])
  2195. "--"
  2196. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2197. "--"
  2198. ("MobileOrg"
  2199. ["Push Files and Views" org-mobile-push t]
  2200. ["Get Captured and Flagged" org-mobile-pull t]
  2201. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2202. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2203. "--"
  2204. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2205. "--"
  2206. ["Quit" org-agenda-quit t]
  2207. ["Exit and Release Buffers" org-agenda-exit t]
  2208. ))
  2209. ;;; Agenda undo
  2210. (defvar org-agenda-allow-remote-undo t
  2211. "Non-nil means allow remote undo from the agenda buffer.")
  2212. (defvar org-agenda-undo-has-started-in nil
  2213. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2214. (defun org-agenda-undo ()
  2215. "Undo a remote editing step in the agenda.
  2216. This undoes changes both in the agenda buffer and in the remote buffer
  2217. that have been changed along."
  2218. (interactive)
  2219. (or org-agenda-allow-remote-undo
  2220. (user-error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2221. (if (not (eq this-command last-command))
  2222. (setq org-agenda-undo-has-started-in nil
  2223. org-agenda-pending-undo-list org-agenda-undo-list))
  2224. (if (not org-agenda-pending-undo-list)
  2225. (user-error "No further undo information"))
  2226. (let* ((entry (pop org-agenda-pending-undo-list))
  2227. buf line cmd rembuf)
  2228. (setq cmd (pop entry) line (pop entry))
  2229. (setq rembuf (nth 2 entry))
  2230. (org-with-remote-undo rembuf
  2231. (while (bufferp (setq buf (pop entry)))
  2232. (if (pop entry)
  2233. (with-current-buffer buf
  2234. (let ((last-undo-buffer buf)
  2235. (inhibit-read-only t))
  2236. (unless (memq buf org-agenda-undo-has-started-in)
  2237. (push buf org-agenda-undo-has-started-in)
  2238. (make-local-variable 'pending-undo-list)
  2239. (undo-start))
  2240. (while (and pending-undo-list
  2241. (listp pending-undo-list)
  2242. (not (car pending-undo-list)))
  2243. (pop pending-undo-list))
  2244. (undo-more 1))))))
  2245. (org-goto-line line)
  2246. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2247. (defun org-verify-change-for-undo (l1 l2)
  2248. "Verify that a real change occurred between the undo lists L1 and L2."
  2249. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2250. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2251. (not (eq l1 l2)))
  2252. ;;; Agenda dispatch
  2253. (defvar org-agenda-restrict-begin (make-marker))
  2254. (defvar org-agenda-restrict-end (make-marker))
  2255. (defvar org-agenda-last-dispatch-buffer nil)
  2256. (defvar org-agenda-overriding-restriction nil)
  2257. (defcustom org-agenda-custom-commands-contexts nil
  2258. "Alist of custom agenda keys and contextual rules.
  2259. For example, if you have a custom agenda command \"p\" and you
  2260. want this command to be accessible only from plain text files,
  2261. use this:
  2262. '((\"p\" ((in-file . \"\\.txt\"))))
  2263. Here are the available contexts definitions:
  2264. in-file: command displayed only in matching files
  2265. in-mode: command displayed only in matching modes
  2266. not-in-file: command not displayed in matching files
  2267. not-in-mode: command not displayed in matching modes
  2268. in-buffer: command displayed only in matching buffers
  2269. not-in-buffer: command not displayed in matching buffers
  2270. [function]: a custom function taking no argument
  2271. If you define several checks, the agenda command will be
  2272. accessible if there is at least one valid check.
  2273. You can also bind a key to another agenda custom command
  2274. depending on contextual rules.
  2275. '((\"p\" \"q\" ((in-file . \"\\.txt\"))))
  2276. Here it means: in .txt files, use \"p\" as the key for the
  2277. agenda command otherwise associated with \"q\". (The command
  2278. originally associated with \"q\" is not displayed to avoid
  2279. duplicates.)"
  2280. :version "24.3"
  2281. :group 'org-agenda-custom-commands
  2282. :type '(repeat (list :tag "Rule"
  2283. (string :tag " Agenda key")
  2284. (string :tag "Replace by command")
  2285. (repeat :tag "Available when"
  2286. (choice
  2287. (cons :tag "Condition"
  2288. (choice
  2289. (const :tag "In file" in-file)
  2290. (const :tag "Not in file" not-in-file)
  2291. (const :tag "In buffer" in-buffer)
  2292. (const :tag "Not in buffer" not-in-buffer)
  2293. (const :tag "In mode" in-mode)
  2294. (const :tag "Not in mode" not-in-mode))
  2295. (regexp))
  2296. (function :tag "Custom function"))))))
  2297. (defcustom org-agenda-max-entries nil
  2298. "Maximum number of entries to display in an agenda.
  2299. This can be nil (no limit) or an integer or an alist of agenda
  2300. types with an associated number of entries to display in this
  2301. type."
  2302. :version "24.4"
  2303. :package-version '(Org . "8.0")
  2304. :group 'org-agenda-custom-commands
  2305. :type '(choice (symbol :tag "No limit" nil)
  2306. (integer :tag "Max number of entries")
  2307. (repeat
  2308. (cons (choice :tag "Agenda type"
  2309. (const agenda)
  2310. (const todo)
  2311. (const tags)
  2312. (const search)
  2313. (const timeline))
  2314. (integer :tag "Max number of entries")))))
  2315. (defcustom org-agenda-max-todos nil
  2316. "Maximum number of TODOs to display in an agenda.
  2317. This can be nil (no limit) or an integer or an alist of agenda
  2318. types with an associated number of entries to display in this
  2319. type."
  2320. :version "24.4"
  2321. :package-version '(Org . "8.0")
  2322. :group 'org-agenda-custom-commands
  2323. :type '(choice (symbol :tag "No limit" nil)
  2324. (integer :tag "Max number of TODOs")
  2325. (repeat
  2326. (cons (choice :tag "Agenda type"
  2327. (const agenda)
  2328. (const todo)
  2329. (const tags)
  2330. (const search)
  2331. (const timeline))
  2332. (integer :tag "Max number of TODOs")))))
  2333. (defcustom org-agenda-max-tags nil
  2334. "Maximum number of tagged entries to display in an agenda.
  2335. This can be nil (no limit) or an integer or an alist of agenda
  2336. types with an associated number of entries to display in this
  2337. type."
  2338. :version "24.4"
  2339. :package-version '(Org . "8.0")
  2340. :group 'org-agenda-custom-commands
  2341. :type '(choice (symbol :tag "No limit" nil)
  2342. (integer :tag "Max number of tagged entries")
  2343. (repeat
  2344. (cons (choice :tag "Agenda type"
  2345. (const agenda)
  2346. (const todo)
  2347. (const tags)
  2348. (const search)
  2349. (const timeline))
  2350. (integer :tag "Max number of tagged entries")))))
  2351. (defcustom org-agenda-max-effort nil
  2352. "Maximum cumulated effort duration for the agenda.
  2353. This can be nil (no limit) or a number of minutes (as an integer)
  2354. or an alist of agenda types with an associated number of minutes
  2355. to limit entries to in this type."
  2356. :version "24.4"
  2357. :package-version '(Org . "8.0")
  2358. :group 'org-agenda-custom-commands
  2359. :type '(choice (symbol :tag "No limit" nil)
  2360. (integer :tag "Max number of minutes")
  2361. (repeat
  2362. (cons (choice :tag "Agenda type"
  2363. (const agenda)
  2364. (const todo)
  2365. (const tags)
  2366. (const search)
  2367. (const timeline))
  2368. (integer :tag "Max number of minutes")))))
  2369. (defvar org-keys nil)
  2370. (defvar org-match nil)
  2371. ;;;###autoload
  2372. (defun org-agenda (&optional arg org-keys restriction)
  2373. "Dispatch agenda commands to collect entries to the agenda buffer.
  2374. Prompts for a command to execute. Any prefix arg will be passed
  2375. on to the selected command. The default selections are:
  2376. a Call `org-agenda-list' to display the agenda for current day or week.
  2377. t Call `org-todo-list' to display the global todo list.
  2378. T Call `org-todo-list' to display the global todo list, select only
  2379. entries with a specific TODO keyword (the user gets a prompt).
  2380. m Call `org-tags-view' to display headlines with tags matching
  2381. a condition (the user is prompted for the condition).
  2382. M Like `m', but select only TODO entries, no ordinary headlines.
  2383. L Create a timeline for the current buffer.
  2384. e Export views to associated files.
  2385. s Search entries for keywords.
  2386. S Search entries for keywords, only with TODO keywords.
  2387. / Multi occur across all agenda files and also files listed
  2388. in `org-agenda-text-search-extra-files'.
  2389. < Restrict agenda commands to buffer, subtree, or region.
  2390. Press several times to get the desired effect.
  2391. > Remove a previous restriction.
  2392. # List \"stuck\" projects.
  2393. ! Configure what \"stuck\" means.
  2394. C Configure custom agenda commands.
  2395. More commands can be added by configuring the variable
  2396. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2397. searches can be pre-defined in this way.
  2398. If the current buffer is in Org-mode and visiting a file, you can also
  2399. first press `<' once to indicate that the agenda should be temporarily
  2400. \(until the next use of \\[org-agenda]) restricted to the current file.
  2401. Pressing `<' twice means to restrict to the current subtree or region
  2402. \(if active)."
  2403. (interactive "P")
  2404. (catch 'exit
  2405. (let* ((prefix-descriptions nil)
  2406. (org-agenda-buffer-name org-agenda-buffer-name)
  2407. (org-agenda-window-setup (if (equal (buffer-name)
  2408. org-agenda-buffer-name)
  2409. 'current-window
  2410. org-agenda-window-setup))
  2411. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2412. (org-agenda-custom-commands
  2413. ;; normalize different versions
  2414. (delq nil
  2415. (mapcar
  2416. (lambda (x)
  2417. (cond ((stringp (cdr x))
  2418. (push x prefix-descriptions)
  2419. nil)
  2420. ((stringp (nth 1 x)) x)
  2421. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2422. (t (cons (car x) (cons "" (cdr x))))))
  2423. org-agenda-custom-commands)))
  2424. (org-agenda-custom-commands
  2425. (org-contextualize-keys
  2426. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2427. (buf (current-buffer))
  2428. (bfn (buffer-file-name (buffer-base-buffer)))
  2429. entry key type org-match lprops ans)
  2430. ;; Turn off restriction unless there is an overriding one,
  2431. (unless org-agenda-overriding-restriction
  2432. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2433. ;; There is a request to keep the file list in place
  2434. (put 'org-agenda-files 'org-restrict nil))
  2435. (setq org-agenda-restrict nil)
  2436. (move-marker org-agenda-restrict-begin nil)
  2437. (move-marker org-agenda-restrict-end nil))
  2438. ;; Delete old local properties
  2439. (put 'org-agenda-redo-command 'org-lprops nil)
  2440. ;; Delete previously set last-arguments
  2441. (put 'org-agenda-redo-command 'last-args nil)
  2442. ;; Remember where this call originated
  2443. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2444. (unless org-keys
  2445. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2446. org-keys (car ans)
  2447. restriction (cdr ans)))
  2448. ;; If we have sticky agenda buffers, set a name for the buffer,
  2449. ;; depending on the invoking keys. The user may still set this
  2450. ;; as a command option, which will overwrite what we do here.
  2451. (if org-agenda-sticky
  2452. (setq org-agenda-buffer-name
  2453. (format "*Org Agenda(%s)*" org-keys)))
  2454. ;; Establish the restriction, if any
  2455. (when (and (not org-agenda-overriding-restriction) restriction)
  2456. (put 'org-agenda-files 'org-restrict (list bfn))
  2457. (cond
  2458. ((eq restriction 'region)
  2459. (setq org-agenda-restrict (current-buffer))
  2460. (move-marker org-agenda-restrict-begin (region-beginning))
  2461. (move-marker org-agenda-restrict-end (region-end)))
  2462. ((eq restriction 'subtree)
  2463. (save-excursion
  2464. (setq org-agenda-restrict (current-buffer))
  2465. (org-back-to-heading t)
  2466. (move-marker org-agenda-restrict-begin (point))
  2467. (move-marker org-agenda-restrict-end
  2468. (progn (org-end-of-subtree t)))))))
  2469. ;; For example the todo list should not need it (but does...)
  2470. (cond
  2471. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2472. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2473. (progn
  2474. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2475. lprops (nth 4 entry))
  2476. (if org-agenda-sticky
  2477. (setq org-agenda-buffer-name
  2478. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2479. (format "*Org Agenda(%s)*" org-keys))))
  2480. (put 'org-agenda-redo-command 'org-lprops lprops)
  2481. (cond
  2482. ((eq type 'agenda)
  2483. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2484. ((eq type 'agenda*)
  2485. (org-let lprops '(org-agenda-list current-prefix-arg nil nil t)))
  2486. ((eq type 'alltodo)
  2487. (org-let lprops '(org-todo-list current-prefix-arg)))
  2488. ((eq type 'search)
  2489. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2490. ((eq type 'stuck)
  2491. (org-let lprops '(org-agenda-list-stuck-projects
  2492. current-prefix-arg)))
  2493. ((eq type 'tags)
  2494. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2495. ((eq type 'tags-todo)
  2496. (org-let lprops '(org-tags-view '(4) org-match)))
  2497. ((eq type 'todo)
  2498. (org-let lprops '(org-todo-list org-match)))
  2499. ((eq type 'tags-tree)
  2500. (org-check-for-org-mode)
  2501. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2502. ((eq type 'todo-tree)
  2503. (org-check-for-org-mode)
  2504. (org-let lprops
  2505. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2506. (regexp-quote org-match) "\\>"))))
  2507. ((eq type 'occur-tree)
  2508. (org-check-for-org-mode)
  2509. (org-let lprops '(org-occur org-match)))
  2510. ((functionp type)
  2511. (org-let lprops '(funcall type org-match)))
  2512. ((fboundp type)
  2513. (org-let lprops '(funcall type org-match)))
  2514. (t (user-error "Invalid custom agenda command type %s" type))))
  2515. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2516. ((equal org-keys "C")
  2517. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2518. (customize-variable 'org-agenda-custom-commands))
  2519. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2520. ((equal org-keys "s") (call-interactively 'org-search-view))
  2521. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2522. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2523. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2524. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2525. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2526. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2527. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2528. (org-add-hook
  2529. 'post-command-hook
  2530. (lambda ()
  2531. (unless (current-message)
  2532. (let* ((m (org-agenda-get-any-marker))
  2533. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2534. (when note
  2535. (message (concat
  2536. "FLAGGING-NOTE ([?] for more info): "
  2537. (org-add-props
  2538. (replace-regexp-in-string
  2539. "\\\\n" "//"
  2540. (copy-sequence note))
  2541. nil 'face 'org-warning)))))))
  2542. t t))
  2543. ((equal org-keys "L")
  2544. (unless (derived-mode-p 'org-mode)
  2545. (user-error "This is not an Org-mode file"))
  2546. (unless restriction
  2547. (put 'org-agenda-files 'org-restrict (list bfn))
  2548. (org-call-with-arg 'org-timeline arg)))
  2549. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2550. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2551. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2552. (t (user-error "Invalid agenda key"))))))
  2553. (defvar org-agenda-multi)
  2554. (defun org-agenda-append-agenda ()
  2555. "Append another agenda view to the current one.
  2556. This function allows interactive building of block agendas.
  2557. Agenda views are separated by `org-agenda-block-separator'."
  2558. (interactive)
  2559. (unless (derived-mode-p 'org-agenda-mode)
  2560. (user-error "Can only append from within agenda buffer"))
  2561. (let ((org-agenda-multi t))
  2562. (org-agenda)
  2563. (widen)
  2564. (org-agenda-finalize)
  2565. (setq buffer-read-only t)
  2566. (org-agenda-fit-window-to-buffer)))
  2567. (defun org-agenda-normalize-custom-commands (cmds)
  2568. "Normalize custom commands CMDS."
  2569. (delq nil
  2570. (mapcar
  2571. (lambda (x)
  2572. (cond ((stringp (cdr x)) nil)
  2573. ((stringp (nth 1 x)) x)
  2574. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2575. (t (cons (car x) (cons "" (cdr x))))))
  2576. cmds)))
  2577. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2578. "The user interface for selecting an agenda command."
  2579. (catch 'exit
  2580. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2581. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2582. (region-p (org-region-active-p))
  2583. (custom org-agenda-custom-commands)
  2584. (selstring "")
  2585. restriction second-time
  2586. c entry key type match prefixes rmheader header-end custom1 desc
  2587. line lines left right n n1)
  2588. (save-window-excursion
  2589. (delete-other-windows)
  2590. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2591. (erase-buffer)
  2592. (insert (eval-when-compile
  2593. (let ((header
  2594. "Press key for an agenda command: < Buffer, subtree/region restriction
  2595. -------------------------------- > Remove restriction
  2596. a Agenda for current week or day e Export agenda views
  2597. t List of all TODO entries T Entries with special TODO kwd
  2598. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2599. s Search for keywords S Like s, but only TODO entries
  2600. L Timeline for current buffer # List stuck projects (!=configure)
  2601. / Multi-occur C Configure custom agenda commands
  2602. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2603. ")
  2604. (start 0))
  2605. (while (string-match
  2606. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2607. header start)
  2608. (setq start (match-end 0))
  2609. (add-text-properties (match-beginning 2) (match-end 2)
  2610. '(face bold) header))
  2611. header)))
  2612. (setq header-end (point-marker))
  2613. (while t
  2614. (setq custom1 custom)
  2615. (when (eq rmheader t)
  2616. (org-goto-line 1)
  2617. (re-search-forward ":" nil t)
  2618. (delete-region (match-end 0) (point-at-eol))
  2619. (forward-char 1)
  2620. (looking-at "-+")
  2621. (delete-region (match-end 0) (point-at-eol))
  2622. (move-marker header-end (match-end 0)))
  2623. (goto-char header-end)
  2624. (delete-region (point) (point-max))
  2625. ;; Produce all the lines that describe custom commands and prefixes
  2626. (setq lines nil)
  2627. (while (setq entry (pop custom1))
  2628. (setq key (car entry) desc (nth 1 entry)
  2629. type (nth 2 entry)
  2630. match (nth 3 entry))
  2631. (if (> (length key) 1)
  2632. (add-to-list 'prefixes (string-to-char key))
  2633. (setq line
  2634. (format
  2635. "%-4s%-14s"
  2636. (org-add-props (copy-sequence key)
  2637. '(face bold))
  2638. (cond
  2639. ((string-match "\\S-" desc) desc)
  2640. ((eq type 'agenda) "Agenda for current week or day")
  2641. ((eq type 'agenda*) "Appointments for current week or day")
  2642. ((eq type 'alltodo) "List of all TODO entries")
  2643. ((eq type 'search) "Word search")
  2644. ((eq type 'stuck) "List of stuck projects")
  2645. ((eq type 'todo) "TODO keyword")
  2646. ((eq type 'tags) "Tags query")
  2647. ((eq type 'tags-todo) "Tags (TODO)")
  2648. ((eq type 'tags-tree) "Tags tree")
  2649. ((eq type 'todo-tree) "TODO kwd tree")
  2650. ((eq type 'occur-tree) "Occur tree")
  2651. ((functionp type) (if (symbolp type)
  2652. (symbol-name type)
  2653. "Lambda expression"))
  2654. (t "???"))))
  2655. (if org-agenda-menu-show-matcher
  2656. (setq line
  2657. (concat line ": "
  2658. (cond
  2659. ((stringp match)
  2660. (setq match (copy-sequence match))
  2661. (org-add-props match nil 'face 'org-warning))
  2662. ((listp type)
  2663. (format "set of %d commands" (length type))))))
  2664. (if (org-string-nw-p match)
  2665. (add-text-properties
  2666. 0 (length line) (list 'help-echo
  2667. (concat "Matcher: " match)) line)))
  2668. (push line lines)))
  2669. (setq lines (nreverse lines))
  2670. (when prefixes
  2671. (mapc (lambda (x)
  2672. (push
  2673. (format "%s %s"
  2674. (org-add-props (char-to-string x)
  2675. nil 'face 'bold)
  2676. (or (cdr (assoc (concat selstring
  2677. (char-to-string x))
  2678. prefix-descriptions))
  2679. "Prefix key"))
  2680. lines))
  2681. prefixes))
  2682. ;; Check if we should display in two columns
  2683. (if org-agenda-menu-two-columns
  2684. (progn
  2685. (setq n (length lines)
  2686. n1 (+ (/ n 2) (mod n 2))
  2687. right (nthcdr n1 lines)
  2688. left (copy-sequence lines))
  2689. (setcdr (nthcdr (1- n1) left) nil))
  2690. (setq left lines right nil))
  2691. (while left
  2692. (insert "\n" (pop left))
  2693. (when right
  2694. (if (< (current-column) 40)
  2695. (move-to-column 40 t)
  2696. (insert " "))
  2697. (insert (pop right))))
  2698. ;; Make the window the right size
  2699. (goto-char (point-min))
  2700. (if second-time
  2701. (if (not (pos-visible-in-window-p (point-max)))
  2702. (org-fit-window-to-buffer))
  2703. (setq second-time t)
  2704. (org-fit-window-to-buffer))
  2705. ;; Ask for selection
  2706. (message "Press key for agenda command%s:"
  2707. (if (or restrict-ok org-agenda-overriding-restriction)
  2708. (if org-agenda-overriding-restriction
  2709. " (restriction lock active)"
  2710. (if restriction
  2711. (format " (restricted to %s)" restriction)
  2712. " (unrestricted)"))
  2713. ""))
  2714. (setq c (read-char-exclusive))
  2715. (message "")
  2716. (cond
  2717. ((assoc (char-to-string c) custom)
  2718. (setq selstring (concat selstring (char-to-string c)))
  2719. (throw 'exit (cons selstring restriction)))
  2720. ((memq c prefixes)
  2721. (setq selstring (concat selstring (char-to-string c))
  2722. prefixes nil
  2723. rmheader (or rmheader t)
  2724. custom (delq nil (mapcar
  2725. (lambda (x)
  2726. (if (or (= (length (car x)) 1)
  2727. (/= (string-to-char (car x)) c))
  2728. nil
  2729. (cons (substring (car x) 1) (cdr x))))
  2730. custom))))
  2731. ((eq c ?*)
  2732. (call-interactively 'org-toggle-sticky-agenda)
  2733. (sit-for 2))
  2734. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2735. (message "Restriction is only possible in Org-mode buffers")
  2736. (ding) (sit-for 1))
  2737. ((eq c ?1)
  2738. (org-agenda-remove-restriction-lock 'noupdate)
  2739. (setq restriction 'buffer))
  2740. ((eq c ?0)
  2741. (org-agenda-remove-restriction-lock 'noupdate)
  2742. (setq restriction (if region-p 'region 'subtree)))
  2743. ((eq c ?<)
  2744. (org-agenda-remove-restriction-lock 'noupdate)
  2745. (setq restriction
  2746. (cond
  2747. ((eq restriction 'buffer)
  2748. (if region-p 'region 'subtree))
  2749. ((memq restriction '(subtree region))
  2750. nil)
  2751. (t 'buffer))))
  2752. ((eq c ?>)
  2753. (org-agenda-remove-restriction-lock 'noupdate)
  2754. (setq restriction nil))
  2755. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2756. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2757. ((and (> (length selstring) 0) (eq c ?\d))
  2758. (delete-window)
  2759. (org-agenda-get-restriction-and-command prefix-descriptions))
  2760. ((equal c ?q) (error "Abort"))
  2761. (t (user-error "Invalid key %c" c))))))))
  2762. (defun org-agenda-fit-window-to-buffer ()
  2763. "Fit the window to the buffer size."
  2764. (and (memq org-agenda-window-setup '(reorganize-frame))
  2765. (fboundp 'fit-window-to-buffer)
  2766. (org-fit-window-to-buffer
  2767. nil
  2768. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2769. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2770. (defvar org-cmd nil)
  2771. (defvar org-agenda-overriding-cmd nil)
  2772. (defvar org-agenda-overriding-arguments nil)
  2773. (defvar org-agenda-overriding-cmd-arguments nil)
  2774. (defun org-agenda-run-series (name series)
  2775. "Run agenda NAME as a SERIES of agenda commands."
  2776. (org-let (nth 1 series) '(org-agenda-prepare name))
  2777. ;; We need to reset agenda markers here, because when constructing a
  2778. ;; block agenda, the individual blocks do not do that.
  2779. (org-agenda-reset-markers)
  2780. (let* ((org-agenda-multi t)
  2781. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2782. (cmds (car series))
  2783. (gprops (nth 1 series))
  2784. match ;; The byte compiler incorrectly complains about this. Keep it!
  2785. org-cmd type lprops)
  2786. (while (setq org-cmd (pop cmds))
  2787. (setq type (car org-cmd)
  2788. match (eval (nth 1 org-cmd))
  2789. lprops (nth 2 org-cmd))
  2790. (let ((org-agenda-overriding-arguments
  2791. (if (eq org-agenda-overriding-cmd org-cmd)
  2792. (or org-agenda-overriding-arguments
  2793. org-agenda-overriding-cmd-arguments))))
  2794. (cond
  2795. ((eq type 'agenda)
  2796. (org-let2 gprops lprops
  2797. '(call-interactively 'org-agenda-list)))
  2798. ((eq type 'agenda*)
  2799. (org-let2 gprops lprops
  2800. '(funcall 'org-agenda-list nil nil t)))
  2801. ((eq type 'alltodo)
  2802. (org-let2 gprops lprops
  2803. '(call-interactively 'org-todo-list)))
  2804. ((eq type 'search)
  2805. (org-let2 gprops lprops
  2806. '(org-search-view current-prefix-arg match nil)))
  2807. ((eq type 'stuck)
  2808. (org-let2 gprops lprops
  2809. '(call-interactively 'org-agenda-list-stuck-projects)))
  2810. ((eq type 'tags)
  2811. (org-let2 gprops lprops
  2812. '(org-tags-view current-prefix-arg match)))
  2813. ((eq type 'tags-todo)
  2814. (org-let2 gprops lprops
  2815. '(org-tags-view '(4) match)))
  2816. ((eq type 'todo)
  2817. (org-let2 gprops lprops
  2818. '(org-todo-list match)))
  2819. ((fboundp type)
  2820. (org-let2 gprops lprops
  2821. '(funcall type match)))
  2822. (t (error "Invalid type in command series")))))
  2823. (widen)
  2824. (let ((inhibit-read-only t))
  2825. (add-text-properties (point-min) (point-max)
  2826. `(org-series t org-series-redo-cmd ,redo)))
  2827. (setq org-agenda-redo-command redo)
  2828. (goto-char (point-min)))
  2829. (org-agenda-fit-window-to-buffer)
  2830. (org-let (nth 1 series) '(org-agenda-finalize)))
  2831. ;;;###autoload
  2832. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2833. "Run an agenda command in batch mode and send the result to STDOUT.
  2834. If CMD-KEY is a string of length 1, it is used as a key in
  2835. `org-agenda-custom-commands' and triggers this command. If it is a
  2836. longer string it is used as a tags/todo match string.
  2837. Parameters are alternating variable names and values that will be bound
  2838. before running the agenda command."
  2839. (org-eval-in-environment (org-make-parameter-alist parameters)
  2840. (let (org-agenda-sticky)
  2841. (if (> (length cmd-key) 2)
  2842. (org-tags-view nil cmd-key)
  2843. (org-agenda nil cmd-key))))
  2844. (set-buffer org-agenda-buffer-name)
  2845. (princ (buffer-string)))
  2846. (defvar org-agenda-info nil)
  2847. ;;;###autoload
  2848. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2849. "Run an agenda command in batch mode and send the result to STDOUT.
  2850. If CMD-KEY is a string of length 1, it is used as a key in
  2851. `org-agenda-custom-commands' and triggers this command. If it is a
  2852. longer string it is used as a tags/todo match string.
  2853. Parameters are alternating variable names and values that will be bound
  2854. before running the agenda command.
  2855. The output gives a line for each selected agenda item. Each
  2856. item is a list of comma-separated values, like this:
  2857. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2858. category The category of the item
  2859. head The headline, without TODO kwd, TAGS and PRIORITY
  2860. type The type of the agenda entry, can be
  2861. todo selected in TODO match
  2862. tagsmatch selected in tags match
  2863. diary imported from diary
  2864. deadline a deadline on given date
  2865. scheduled scheduled on given date
  2866. timestamp entry has timestamp on given date
  2867. closed entry was closed on given date
  2868. upcoming-deadline warning about deadline
  2869. past-scheduled forwarded scheduled item
  2870. block entry has date block including g. date
  2871. todo The todo keyword, if any
  2872. tags All tags including inherited ones, separated by colons
  2873. date The relevant date, like 2007-2-14
  2874. time The time, like 15:00-16:50
  2875. extra Sting with extra planning info
  2876. priority-l The priority letter if any was given
  2877. priority-n The computed numerical priority
  2878. agenda-day The day in the agenda where this is listed"
  2879. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2880. (org-make-parameter-alist parameters))
  2881. (if (> (length cmd-key) 2)
  2882. (org-tags-view nil cmd-key)
  2883. (org-agenda nil cmd-key)))
  2884. (set-buffer org-agenda-buffer-name)
  2885. (let* ((lines (org-split-string (buffer-string) "\n"))
  2886. line)
  2887. (while (setq line (pop lines))
  2888. (catch 'next
  2889. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2890. (setq org-agenda-info
  2891. (org-fix-agenda-info (text-properties-at 0 line)))
  2892. (princ
  2893. (mapconcat 'org-agenda-export-csv-mapper
  2894. '(org-category txt type todo tags date time extra
  2895. priority-letter priority agenda-day)
  2896. ","))
  2897. (princ "\n")))))
  2898. (defun org-fix-agenda-info (props)
  2899. "Make sure all properties on an agenda item have a canonical form.
  2900. This ensures the export commands can easily use it."
  2901. (let (tmp re)
  2902. (when (setq tmp (plist-get props 'tags))
  2903. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2904. (when (setq tmp (plist-get props 'date))
  2905. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2906. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2907. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2908. (setq tmp (calendar-date-string tmp)))
  2909. (setq props (plist-put props 'date tmp)))
  2910. (when (setq tmp (plist-get props 'day))
  2911. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2912. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2913. (setq tmp (calendar-date-string tmp)))
  2914. (setq props (plist-put props 'day tmp))
  2915. (setq props (plist-put props 'agenda-day tmp)))
  2916. (when (setq tmp (plist-get props 'txt))
  2917. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2918. (plist-put props 'priority-letter (match-string 1 tmp))
  2919. (setq tmp (replace-match "" t t tmp)))
  2920. (when (and (setq re (plist-get props 'org-todo-regexp))
  2921. (setq re (concat "\\`\\.*" re " ?"))
  2922. (string-match re tmp))
  2923. (plist-put props 'todo (match-string 1 tmp))
  2924. (setq tmp (replace-match "" t t tmp)))
  2925. (plist-put props 'txt tmp)))
  2926. props)
  2927. (defun org-agenda-export-csv-mapper (prop)
  2928. (let ((res (plist-get org-agenda-info prop)))
  2929. (setq res
  2930. (cond
  2931. ((not res) "")
  2932. ((stringp res) res)
  2933. (t (prin1-to-string res))))
  2934. (while (string-match "," res)
  2935. (setq res (replace-match ";" t t res)))
  2936. (org-trim res)))
  2937. ;;;###autoload
  2938. (defun org-store-agenda-views (&rest parameters)
  2939. "Store agenda views."
  2940. (interactive)
  2941. (eval (list 'org-batch-store-agenda-views)))
  2942. ;;;###autoload
  2943. (defmacro org-batch-store-agenda-views (&rest parameters)
  2944. "Run all custom agenda commands that have a file argument."
  2945. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2946. (pop-up-frames nil)
  2947. (dir default-directory)
  2948. (pars (org-make-parameter-alist parameters))
  2949. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2950. (save-window-excursion
  2951. (while cmds
  2952. (setq cmd (pop cmds)
  2953. thiscmdkey (car cmd)
  2954. thiscmdcmd (cdr cmd)
  2955. match (nth 2 thiscmdcmd)
  2956. bufname (if org-agenda-sticky
  2957. (or (and (stringp match)
  2958. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2959. (format "*Org Agenda(%s)*" thiscmdkey))
  2960. org-agenda-buffer-name)
  2961. cmd-or-set (nth 2 cmd)
  2962. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2963. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2964. (if (stringp files) (setq files (list files)))
  2965. (when files
  2966. (org-eval-in-environment (append org-agenda-exporter-settings
  2967. opts pars)
  2968. (org-agenda nil thiscmdkey))
  2969. (set-buffer bufname)
  2970. (while files
  2971. (org-eval-in-environment (append org-agenda-exporter-settings
  2972. opts pars)
  2973. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2974. (and (get-buffer bufname)
  2975. (kill-buffer bufname)))))))
  2976. (defvar org-agenda-current-span nil
  2977. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2978. (defun org-agenda-mark-header-line (pos)
  2979. "Mark the line at POS as an agenda structure header."
  2980. (save-excursion
  2981. (goto-char pos)
  2982. (put-text-property (point-at-bol) (point-at-eol)
  2983. 'org-agenda-structural-header t)
  2984. (when org-agenda-title-append
  2985. (put-text-property (point-at-bol) (point-at-eol)
  2986. 'org-agenda-title-append org-agenda-title-append))))
  2987. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2988. (defvar org-agenda-write-buffer-name "Agenda View")
  2989. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2990. "Write the current buffer (an agenda view) as a file.
  2991. Depending on the extension of the file name, plain text (.txt),
  2992. HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
  2993. If the extension is .ics, run icalendar export over all files used
  2994. to construct the agenda and limit the export to entries listed in the
  2995. agenda now.
  2996. If the extension is .org, collect all subtrees corresponding to the
  2997. agenda entries and add them in an .org file.
  2998. With prefix argument OPEN, open the new file immediately.
  2999. If NOSETTINGS is given, do not scope the settings of
  3000. `org-agenda-exporter-settings' into the export commands. This is used when
  3001. the settings have already been scoped and we do not wish to overrule other,
  3002. higher priority settings.
  3003. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  3004. (interactive "FWrite agenda to file: \nP")
  3005. (if (or (not (file-writable-p file))
  3006. (and (file-exists-p file)
  3007. (if (org-called-interactively-p 'any)
  3008. (not (y-or-n-p (format "Overwrite existing file %s? " file))))))
  3009. (user-error "Cannot write agenda to file %s" file))
  3010. (org-let (if nosettings nil org-agenda-exporter-settings)
  3011. '(save-excursion
  3012. (save-window-excursion
  3013. (let ((bs (copy-sequence (buffer-string))) beg content)
  3014. (with-temp-buffer
  3015. (rename-buffer org-agenda-write-buffer-name t)
  3016. (set-buffer-modified-p nil)
  3017. (insert bs)
  3018. (org-agenda-remove-marked-text 'org-filtered)
  3019. (run-hooks 'org-agenda-before-write-hook)
  3020. (cond
  3021. ((org-bound-and-true-p org-mobile-creating-agendas)
  3022. (org-mobile-write-agenda-for-mobile file))
  3023. ((string-match "\\.org\\'" file)
  3024. (let (content p m message-log-max)
  3025. (goto-char (point-min))
  3026. (while (setq p (next-single-property-change (point) 'org-hd-marker nil))
  3027. (goto-char p)
  3028. (setq m (get-text-property (point) 'org-hd-marker))
  3029. (when m
  3030. (push (save-excursion
  3031. (set-buffer (marker-buffer m))
  3032. (goto-char m)
  3033. (org-copy-subtree 1 nil t t)
  3034. org-subtree-clip)
  3035. content)))
  3036. (find-file file)
  3037. (erase-buffer)
  3038. (mapcar (lambda (s) (org-paste-subtree 1 s)) (reverse content))
  3039. (write-file file)
  3040. (kill-buffer (current-buffer))
  3041. (message "Org file written to %s" file)))
  3042. ((string-match "\\.html?\\'" file)
  3043. (require 'htmlize)
  3044. (set-buffer (htmlize-buffer (current-buffer)))
  3045. (when org-agenda-export-html-style
  3046. ;; replace <style> section with org-agenda-export-html-style
  3047. (goto-char (point-min))
  3048. (kill-region (- (search-forward "<style") 6)
  3049. (search-forward "</style>"))
  3050. (insert org-agenda-export-html-style))
  3051. (write-file file)
  3052. (kill-buffer (current-buffer))
  3053. (message "HTML written to %s" file))
  3054. ((string-match "\\.ps\\'" file)
  3055. (require 'ps-print)
  3056. (ps-print-buffer-with-faces file)
  3057. (message "Postscript written to %s" file))
  3058. ((string-match "\\.pdf\\'" file)
  3059. (require 'ps-print)
  3060. (ps-print-buffer-with-faces
  3061. (concat (file-name-sans-extension file) ".ps"))
  3062. (call-process "ps2pdf" nil nil nil
  3063. (expand-file-name
  3064. (concat (file-name-sans-extension file) ".ps"))
  3065. (expand-file-name file))
  3066. (delete-file (concat (file-name-sans-extension file) ".ps"))
  3067. (message "PDF written to %s" file))
  3068. ((string-match "\\.ics\\'" file)
  3069. (require 'ox-icalendar)
  3070. (org-icalendar-export-current-agenda (expand-file-name file)))
  3071. (t
  3072. (let ((bs (buffer-string)))
  3073. (find-file file)
  3074. (erase-buffer)
  3075. (insert bs)
  3076. (save-buffer 0)
  3077. (kill-buffer (current-buffer))
  3078. (message "Plain text written to %s" file))))))))
  3079. (set-buffer (or agenda-bufname
  3080. (and (org-called-interactively-p 'any) (buffer-name))
  3081. org-agenda-buffer-name)))
  3082. (when open (org-open-file file)))
  3083. (defun org-agenda-remove-marked-text (property &optional value)
  3084. "Delete all text marked with VALUE of PROPERTY.
  3085. VALUE defaults to t."
  3086. (let (beg)
  3087. (setq value (or value t))
  3088. (while (setq beg (text-property-any (point-min) (point-max)
  3089. property value))
  3090. (delete-region
  3091. beg (or (next-single-property-change beg property)
  3092. (point-max))))))
  3093. (defun org-agenda-add-entry-text ()
  3094. "Add entry text to agenda lines.
  3095. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  3096. entry text following headings shown in the agenda.
  3097. Drawers will be excluded, also the line with scheduling/deadline info."
  3098. (when (and (> org-agenda-add-entry-text-maxlines 0)
  3099. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  3100. (let (m txt)
  3101. (goto-char (point-min))
  3102. (while (not (eobp))
  3103. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  3104. (beginning-of-line 2)
  3105. (setq txt (org-agenda-get-some-entry-text
  3106. m org-agenda-add-entry-text-maxlines " > "))
  3107. (end-of-line 1)
  3108. (if (string-match "\\S-" txt)
  3109. (insert "\n" txt)
  3110. (or (eobp) (forward-char 1))))))))
  3111. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  3112. &rest keep)
  3113. "Extract entry text from MARKER, at most N-LINES lines.
  3114. This will ignore drawers etc, just get the text.
  3115. If INDENT is given, prefix every line with this string. If KEEP is
  3116. given, it is a list of symbols, defining stuff that should not be
  3117. removed from the entry content. Currently only `planning' is allowed here."
  3118. (let (txt drawer-re kwd-time-re ind)
  3119. (save-excursion
  3120. (with-current-buffer (marker-buffer marker)
  3121. (if (not (derived-mode-p 'org-mode))
  3122. (setq txt "")
  3123. (save-excursion
  3124. (save-restriction
  3125. (widen)
  3126. (goto-char marker)
  3127. (end-of-line 1)
  3128. (setq txt (buffer-substring
  3129. (min (1+ (point)) (point-max))
  3130. (progn (outline-next-heading) (point)))
  3131. drawer-re org-drawer-regexp
  3132. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  3133. ".*\n?"))
  3134. (with-temp-buffer
  3135. (insert txt)
  3136. (when org-agenda-add-entry-text-descriptive-links
  3137. (goto-char (point-min))
  3138. (while (org-activate-bracket-links (point-max))
  3139. (add-text-properties (match-beginning 0) (match-end 0)
  3140. '(face org-link))))
  3141. (goto-char (point-min))
  3142. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  3143. (set-text-properties (match-beginning 0) (match-end 0)
  3144. nil))
  3145. (goto-char (point-min))
  3146. (while (re-search-forward drawer-re nil t)
  3147. (delete-region
  3148. (match-beginning 0)
  3149. (progn (re-search-forward
  3150. "^[ \t]*:END:.*\n?" nil 'move)
  3151. (point))))
  3152. (unless (member 'planning keep)
  3153. (goto-char (point-min))
  3154. (while (re-search-forward kwd-time-re nil t)
  3155. (replace-match "")))
  3156. (goto-char (point-min))
  3157. (when org-agenda-entry-text-exclude-regexps
  3158. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3159. (while (setq re (pop re-list))
  3160. (goto-char (point-min))
  3161. (while (re-search-forward re nil t)
  3162. (replace-match "")))))
  3163. (goto-char (point-max))
  3164. (skip-chars-backward " \t\n")
  3165. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3166. ;; find and remove min common indentation
  3167. (goto-char (point-min))
  3168. (untabify (point-min) (point-max))
  3169. (setq ind (org-get-indentation))
  3170. (while (not (eobp))
  3171. (unless (looking-at "[ \t]*$")
  3172. (setq ind (min ind (org-get-indentation))))
  3173. (beginning-of-line 2))
  3174. (goto-char (point-min))
  3175. (while (not (eobp))
  3176. (unless (looking-at "[ \t]*$")
  3177. (move-to-column ind)
  3178. (delete-region (point-at-bol) (point)))
  3179. (beginning-of-line 2))
  3180. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3181. (goto-char (point-min))
  3182. (when indent
  3183. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3184. (replace-match indent t t)))
  3185. (goto-char (point-min))
  3186. (while (looking-at "[ \t]*\n") (replace-match ""))
  3187. (goto-char (point-max))
  3188. (when (> (org-current-line)
  3189. n-lines)
  3190. (org-goto-line (1+ n-lines))
  3191. (backward-char 1))
  3192. (setq txt (buffer-substring (point-min) (point)))))))))
  3193. txt))
  3194. (defun org-check-for-org-mode ()
  3195. "Make sure current buffer is in org-mode. Error if not."
  3196. (or (derived-mode-p 'org-mode)
  3197. (error "Cannot execute org-mode agenda command on buffer in %s"
  3198. major-mode)))
  3199. ;;; Agenda prepare and finalize
  3200. (defvar org-agenda-multi nil) ; dynamically scoped
  3201. (defvar org-agenda-pre-window-conf nil)
  3202. (defvar org-agenda-columns-active nil)
  3203. (defvar org-agenda-name nil)
  3204. (defvar org-agenda-tag-filter nil)
  3205. (defvar org-agenda-category-filter nil)
  3206. (defvar org-agenda-regexp-filter nil)
  3207. (defvar org-agenda-top-headline-filter nil)
  3208. (defvar org-agenda-tag-filter-preset nil
  3209. "A preset of the tags filter used for secondary agenda filtering.
  3210. This must be a list of strings, each string must be a single tag preceded
  3211. by \"+\" or \"-\".
  3212. This variable should not be set directly, but agenda custom commands can
  3213. bind it in the options section. The preset filter is a global property of
  3214. the entire agenda view. In a block agenda, it will not work reliably to
  3215. define a filter for one of the individual blocks. You need to set it in
  3216. the global options and expect it to be applied to the entire view.")
  3217. (defvar org-agenda-category-filter-preset nil
  3218. "A preset of the category filter used for secondary agenda filtering.
  3219. This must be a list of strings, each string must be a single category
  3220. preceded by \"+\" or \"-\".
  3221. This variable should not be set directly, but agenda custom commands can
  3222. bind it in the options section. The preset filter is a global property of
  3223. the entire agenda view. In a block agenda, it will not work reliably to
  3224. define a filter for one of the individual blocks. You need to set it in
  3225. the global options and expect it to be applied to the entire view.")
  3226. (defvar org-agenda-regexp-filter-preset nil
  3227. "A preset of the regexp filter used for secondary agenda filtering.
  3228. This must be a list of strings, each string must be a single regexp
  3229. preceded by \"+\" or \"-\".
  3230. This variable should not be set directly, but agenda custom commands can
  3231. bind it in the options section. The preset filter is a global property of
  3232. the entire agenda view. In a block agenda, it will not work reliably to
  3233. define a filter for one of the individual blocks. You need to set it in
  3234. the global options and expect it to be applied to the entire view.")
  3235. (defun org-agenda-use-sticky-p ()
  3236. "Return non-nil if an agenda buffer named
  3237. `org-agenda-buffer-name' exists and should be shown instead of
  3238. generating a new one."
  3239. (and
  3240. ;; turned off by user
  3241. org-agenda-sticky
  3242. ;; For multi-agenda buffer already exists
  3243. (not org-agenda-multi)
  3244. ;; buffer found
  3245. (get-buffer org-agenda-buffer-name)
  3246. ;; C-u parameter is same as last call
  3247. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3248. (and
  3249. (equal current-prefix-arg
  3250. org-agenda-last-prefix-arg)
  3251. ;; In case user turned stickiness on, while having existing
  3252. ;; Agenda buffer active, don't reuse that buffer, because it
  3253. ;; does not have org variables local
  3254. org-agenda-this-buffer-is-sticky))))
  3255. (defun org-agenda-prepare-window (abuf filter-alist)
  3256. "Setup agenda buffer in the window.
  3257. ABUF is the buffer for the agenda window.
  3258. FILTER-ALIST is an alist of filters we need to apply when
  3259. `org-agenda-persistent-filter' is non-nil."
  3260. (let* ((awin (get-buffer-window abuf)) wconf)
  3261. (cond
  3262. ((equal (current-buffer) abuf) nil)
  3263. (awin (select-window awin))
  3264. ((not (setq wconf (current-window-configuration))))
  3265. ((equal org-agenda-window-setup 'current-window)
  3266. (org-pop-to-buffer-same-window abuf))
  3267. ((equal org-agenda-window-setup 'other-window)
  3268. (org-switch-to-buffer-other-window abuf))
  3269. ((equal org-agenda-window-setup 'other-frame)
  3270. (switch-to-buffer-other-frame abuf))
  3271. ((equal org-agenda-window-setup 'reorganize-frame)
  3272. (delete-other-windows)
  3273. (org-switch-to-buffer-other-window abuf)))
  3274. (setq org-agenda-tag-filter (cdr (assoc 'tag filter-alist)))
  3275. (setq org-agenda-category-filter (cdr (assoc 'cat filter-alist)))
  3276. (setq org-agenda-regexp-filter (cdr (assoc 're filter-alist)))
  3277. ;; Additional test in case agenda is invoked from within agenda
  3278. ;; buffer via elisp link.
  3279. (unless (equal (current-buffer) abuf)
  3280. (org-pop-to-buffer-same-window abuf))
  3281. (setq org-agenda-pre-window-conf
  3282. (or org-agenda-pre-window-conf wconf))))
  3283. (defun org-agenda-prepare (&optional name)
  3284. (let ((filter-alist (if org-agenda-persistent-filter
  3285. (list `(tag . ,org-agenda-tag-filter)
  3286. `(re . ,org-agenda-regexp-filter)
  3287. `(car . ,org-agenda-category-filter)))))
  3288. (if (org-agenda-use-sticky-p)
  3289. (progn
  3290. ;; Popup existing buffer
  3291. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name)
  3292. filter-alist)
  3293. (message "Sticky Agenda buffer, use `r' to refresh")
  3294. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3295. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3296. (setq org-todo-keywords-for-agenda nil)
  3297. (setq org-drawers-for-agenda nil)
  3298. (put 'org-agenda-tag-filter :preset-filter
  3299. org-agenda-tag-filter-preset)
  3300. (put 'org-agenda-category-filter :preset-filter
  3301. org-agenda-category-filter-preset)
  3302. (put 'org-agenda-regexp-filter :preset-filter
  3303. org-agenda-regexp-filter-preset)
  3304. (if org-agenda-multi
  3305. (progn
  3306. (setq buffer-read-only nil)
  3307. (goto-char (point-max))
  3308. (unless (or (bobp) org-agenda-compact-blocks
  3309. (not org-agenda-block-separator))
  3310. (insert "\n"
  3311. (if (stringp org-agenda-block-separator)
  3312. org-agenda-block-separator
  3313. (make-string (window-width) org-agenda-block-separator))
  3314. "\n"))
  3315. (narrow-to-region (point) (point-max)))
  3316. (setq org-done-keywords-for-agenda nil)
  3317. ;; Setting any org variables that are in org-agenda-local-vars
  3318. ;; list need to be done after the prepare call
  3319. (org-agenda-prepare-window
  3320. (get-buffer-create org-agenda-buffer-name) filter-alist)
  3321. (setq buffer-read-only nil)
  3322. (org-agenda-reset-markers)
  3323. (let ((inhibit-read-only t)) (erase-buffer))
  3324. (org-agenda-mode)
  3325. (setq org-agenda-buffer (current-buffer))
  3326. (setq org-agenda-contributing-files nil)
  3327. (setq org-agenda-columns-active nil)
  3328. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3329. (setq org-todo-keywords-for-agenda
  3330. (org-uniquify org-todo-keywords-for-agenda))
  3331. (setq org-done-keywords-for-agenda
  3332. (org-uniquify org-done-keywords-for-agenda))
  3333. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3334. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3335. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3336. (and name (not org-agenda-name)
  3337. (org-set-local 'org-agenda-name name)))
  3338. (setq buffer-read-only nil))))
  3339. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3340. (defun org-agenda-finalize ()
  3341. "Finishing touch for the agenda buffer, called just before displaying it."
  3342. (unless org-agenda-multi
  3343. (save-excursion
  3344. (let ((inhibit-read-only t))
  3345. (goto-char (point-min))
  3346. (save-excursion
  3347. (while (org-activate-bracket-links (point-max))
  3348. (add-text-properties (match-beginning 0) (match-end 0)
  3349. '(face org-link))))
  3350. (save-excursion
  3351. (while (org-activate-plain-links (point-max))
  3352. (add-text-properties (match-beginning 0) (match-end 0)
  3353. '(face org-link))))
  3354. (unless (eq org-agenda-remove-tags t)
  3355. (org-agenda-align-tags))
  3356. (unless org-agenda-with-colors
  3357. (remove-text-properties (point-min) (point-max) '(face nil)))
  3358. (if (and (boundp 'org-agenda-overriding-columns-format)
  3359. org-agenda-overriding-columns-format)
  3360. (org-set-local 'org-agenda-overriding-columns-format
  3361. org-agenda-overriding-columns-format))
  3362. (if (and (boundp 'org-agenda-view-columns-initially)
  3363. org-agenda-view-columns-initially)
  3364. (org-agenda-columns))
  3365. (when org-agenda-fontify-priorities
  3366. (org-agenda-fontify-priorities))
  3367. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3368. (org-agenda-dim-blocked-tasks))
  3369. (org-agenda-mark-clocking-task)
  3370. (when org-agenda-entry-text-mode
  3371. (org-agenda-entry-text-hide)
  3372. (org-agenda-entry-text-show))
  3373. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3374. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3375. (org-habit-insert-consistency-graphs))
  3376. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3377. (unless (or (eq org-agenda-show-inherited-tags 'always)
  3378. (and (listp org-agenda-show-inherited-tags)
  3379. (memq org-agenda-type org-agenda-show-inherited-tags))
  3380. (and (eq org-agenda-show-inherited-tags t)
  3381. (or (eq org-agenda-use-tag-inheritance t)
  3382. (and (listp org-agenda-use-tag-inheritance)
  3383. (not (memq org-agenda-type
  3384. org-agenda-use-tag-inheritance))))))
  3385. (let (mrk)
  3386. (save-excursion
  3387. (goto-char (point-min))
  3388. (while (equal (forward-line) 0)
  3389. (when (setq mrk (get-text-property (point) 'org-hd-marker))
  3390. (put-text-property (point-at-bol) (point-at-eol)
  3391. 'tags (org-with-point-at mrk
  3392. (delete-dups
  3393. (mapcar 'downcase (org-get-tags-at))))))))))
  3394. (run-hooks 'org-agenda-finalize-hook)
  3395. (when org-agenda-top-headline-filter
  3396. (org-agenda-filter-top-headline-apply
  3397. org-agenda-top-headline-filter))
  3398. (when org-agenda-tag-filter
  3399. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3400. (when (get 'org-agenda-tag-filter :preset-filter)
  3401. (org-agenda-filter-apply
  3402. (get 'org-agenda-tag-filter :preset-filter) 'tag))
  3403. (when org-agenda-category-filter
  3404. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3405. (when (get 'org-agenda-category-filter :preset-filter)
  3406. (org-agenda-filter-apply
  3407. (get 'org-agenda-category-filter :preset-filter) 'category))
  3408. (when org-agenda-regexp-filter
  3409. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  3410. (when (get 'org-agenda-regexp-filter :preset-filter)
  3411. (org-agenda-filter-apply
  3412. (get 'org-agenda-regexp-filter :preset-filter) 'regexp))
  3413. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)))))
  3414. (defun org-agenda-mark-clocking-task ()
  3415. "Mark the current clock entry in the agenda if it is present."
  3416. ;; We need to widen when `org-agenda-finalize' is called from
  3417. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3418. (when org-clock-current-task
  3419. (save-restriction
  3420. (widen)
  3421. (org-agenda-unmark-clocking-task)
  3422. (when (marker-buffer org-clock-hd-marker)
  3423. (save-excursion
  3424. (goto-char (point-min))
  3425. (let (s ov)
  3426. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3427. (goto-char s)
  3428. (when (equal (org-get-at-bol 'org-hd-marker)
  3429. org-clock-hd-marker)
  3430. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3431. (overlay-put ov 'type 'org-agenda-clocking)
  3432. (overlay-put ov 'face 'org-agenda-clocking)
  3433. (overlay-put ov 'help-echo
  3434. "The clock is running in this item")))))))))
  3435. (defun org-agenda-unmark-clocking-task ()
  3436. "Unmark the current clocking task."
  3437. (mapc (lambda (o)
  3438. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3439. (delete-overlay o)))
  3440. (overlays-in (point-min) (point-max))))
  3441. (defun org-agenda-fontify-priorities ()
  3442. "Make highest priority lines bold, and lowest italic."
  3443. (interactive)
  3444. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3445. (delete-overlay o)))
  3446. (overlays-in (point-min) (point-max)))
  3447. (save-excursion
  3448. (let (b e p ov h l)
  3449. (goto-char (point-min))
  3450. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3451. (setq h (or (get-char-property (point) 'org-highest-priority)
  3452. org-highest-priority)
  3453. l (or (get-char-property (point) 'org-lowest-priority)
  3454. org-lowest-priority)
  3455. p (string-to-char (match-string 1))
  3456. b (match-beginning 0)
  3457. e (if (eq org-agenda-fontify-priorities 'cookies)
  3458. (match-end 0)
  3459. (point-at-eol))
  3460. ov (make-overlay b e))
  3461. (overlay-put
  3462. ov 'face
  3463. (cons (cond ((org-face-from-face-or-color
  3464. 'priority nil
  3465. (cdr (assoc p org-priority-faces))))
  3466. ((and (listp org-agenda-fontify-priorities)
  3467. (org-face-from-face-or-color
  3468. 'priority nil
  3469. (cdr (assoc p org-agenda-fontify-priorities)))))
  3470. ((equal p l) 'italic)
  3471. ((equal p h) 'bold))
  3472. 'org-priority))
  3473. (overlay-put ov 'org-type 'org-priority)))))
  3474. (defvar org-depend-tag-blocked)
  3475. (defun org-agenda-dim-blocked-tasks (&optional invisible)
  3476. "Dim currently blocked TODO's in the agenda display.
  3477. When INVISIBLE is non-nil, hide currently blocked TODO instead of
  3478. dimming them."
  3479. (interactive "P")
  3480. (when (org-called-interactively-p 'interactive)
  3481. (message "Dim or hide blocked tasks..."))
  3482. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3483. (delete-overlay o)))
  3484. (overlays-in (point-min) (point-max)))
  3485. (save-excursion
  3486. (let ((inhibit-read-only t)
  3487. (org-depend-tag-blocked nil)
  3488. (invis (or (not (null invisible))
  3489. (eq org-agenda-dim-blocked-tasks 'invisible)))
  3490. org-blocked-by-checkboxes
  3491. invis1 b e p ov h l)
  3492. (goto-char (point-min))
  3493. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3494. (and pos (goto-char (1+ pos))))
  3495. (setq org-blocked-by-checkboxes nil invis1 invis)
  3496. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3497. (when (and marker
  3498. (with-current-buffer (marker-buffer marker)
  3499. (save-excursion (goto-char marker)
  3500. (org-entry-blocked-p))))
  3501. (if org-blocked-by-checkboxes (setq invis1 nil))
  3502. (setq b (if invis1
  3503. (max (point-min) (1- (point-at-bol)))
  3504. (point-at-bol))
  3505. e (point-at-eol)
  3506. ov (make-overlay b e))
  3507. (if invis1
  3508. (progn (overlay-put ov 'invisible t)
  3509. (overlay-put ov 'intangible t))
  3510. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3511. (overlay-put ov 'org-type 'org-blocked-todo))))))
  3512. (when (org-called-interactively-p 'interactive)
  3513. (message "Dim or hide blocked tasks...done")))
  3514. (defvar org-agenda-skip-function nil
  3515. "Function to be called at each match during agenda construction.
  3516. If this function returns nil, the current match should not be skipped.
  3517. Otherwise, the function must return a position from where the search
  3518. should be continued.
  3519. This may also be a Lisp form, it will be evaluated.
  3520. Never set this variable using `setq' or so, because then it will apply
  3521. to all future agenda commands. If you do want a global skipping condition,
  3522. use the option `org-agenda-skip-function-global' instead.
  3523. The correct usage for `org-agenda-skip-function' is to bind it with
  3524. `let' to scope it dynamically into the agenda-constructing command.
  3525. A good way to set it is through options in `org-agenda-custom-commands'.")
  3526. (defun org-agenda-skip ()
  3527. "Throw to `:skip' in places that should be skipped.
  3528. Also moves point to the end of the skipped region, so that search can
  3529. continue from there."
  3530. (let ((p (point-at-bol)) to)
  3531. (when (or
  3532. (save-excursion (goto-char p) (looking-at comment-start-skip))
  3533. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3534. (get-text-property p :org-archived)
  3535. (org-end-of-subtree t))
  3536. (and org-agenda-skip-comment-trees
  3537. (get-text-property p :org-comment)
  3538. (org-end-of-subtree t))
  3539. (and (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3540. (org-agenda-skip-eval org-agenda-skip-function)))
  3541. (goto-char to))
  3542. (org-in-src-block-p t))
  3543. (throw :skip t))))
  3544. (defun org-agenda-skip-eval (form)
  3545. "If FORM is a function or a list, call (or eval) it and return the result.
  3546. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3547. and match data are returned to the previous state no matter what these
  3548. functions do."
  3549. (let (fp)
  3550. (and form
  3551. (or (setq fp (functionp form))
  3552. (consp form))
  3553. (save-excursion
  3554. (save-match-data
  3555. (if fp
  3556. (funcall form)
  3557. (eval form)))))))
  3558. (defvar org-agenda-markers nil
  3559. "List of all currently active markers created by `org-agenda'.")
  3560. (defvar org-agenda-last-marker-time (org-float-time)
  3561. "Creation time of the last agenda marker.")
  3562. (defun org-agenda-new-marker (&optional pos)
  3563. "Return a new agenda marker.
  3564. Org-mode keeps a list of these markers and resets them when they are
  3565. no longer in use."
  3566. (let ((m (copy-marker (or pos (point)))))
  3567. (setq org-agenda-last-marker-time (org-float-time))
  3568. (if org-agenda-buffer
  3569. (with-current-buffer org-agenda-buffer
  3570. (push m org-agenda-markers))
  3571. (push m org-agenda-markers))
  3572. m))
  3573. (defun org-agenda-reset-markers ()
  3574. "Reset markers created by `org-agenda'."
  3575. (while org-agenda-markers
  3576. (move-marker (pop org-agenda-markers) nil)))
  3577. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3578. "Save relative positions of markers in region.
  3579. This check for agenda markers in all agenda buffers currently active."
  3580. (dolist (buf (buffer-list))
  3581. (with-current-buffer buf
  3582. (when (eq major-mode 'org-agenda-mode)
  3583. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3584. org-agenda-markers)))))
  3585. ;;; Entry text mode
  3586. (defun org-agenda-entry-text-show-here ()
  3587. "Add some text from the entry as context to the current line."
  3588. (let (m txt o)
  3589. (setq m (org-get-at-bol 'org-hd-marker))
  3590. (unless (marker-buffer m)
  3591. (error "No marker points to an entry here"))
  3592. (setq txt (concat "\n" (org-no-properties
  3593. (org-agenda-get-some-entry-text
  3594. m org-agenda-entry-text-maxlines
  3595. org-agenda-entry-text-leaders))))
  3596. (when (string-match "\\S-" txt)
  3597. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3598. (overlay-put o 'evaporate t)
  3599. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3600. (overlay-put o 'after-string txt))))
  3601. (defun org-agenda-entry-text-show ()
  3602. "Add entry context for all agenda lines."
  3603. (interactive)
  3604. (save-excursion
  3605. (goto-char (point-max))
  3606. (beginning-of-line 1)
  3607. (while (not (bobp))
  3608. (when (org-get-at-bol 'org-hd-marker)
  3609. (org-agenda-entry-text-show-here))
  3610. (beginning-of-line 0))))
  3611. (defun org-agenda-entry-text-hide ()
  3612. "Remove any shown entry context."
  3613. (delq nil
  3614. (mapcar (lambda (o)
  3615. (if (eq (overlay-get o 'org-overlay-type)
  3616. 'agenda-entry-content)
  3617. (progn (delete-overlay o) t)))
  3618. (overlays-in (point-min) (point-max)))))
  3619. (defun org-agenda-get-day-face (date)
  3620. "Return the face DATE should be displayed with."
  3621. (or (and (functionp org-agenda-day-face-function)
  3622. (funcall org-agenda-day-face-function date))
  3623. (cond ((org-agenda-todayp date)
  3624. 'org-agenda-date-today)
  3625. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3626. 'org-agenda-date-weekend)
  3627. (t 'org-agenda-date))))
  3628. ;;; Agenda timeline
  3629. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3630. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  3631. (defun org-timeline (&optional dotodo)
  3632. "Show a time-sorted view of the entries in the current org file.
  3633. Only entries with a time stamp of today or later will be listed. With
  3634. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3635. under the current date.
  3636. If the buffer contains an active region, only check the region for
  3637. dates."
  3638. (interactive "P")
  3639. (let* ((dopast t)
  3640. (org-agenda-show-log-scoped org-agenda-show-log)
  3641. (org-agenda-show-log org-agenda-show-log-scoped)
  3642. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3643. (current-buffer))))
  3644. (date (calendar-current-date))
  3645. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3646. (end (if (org-region-active-p) (region-end) (point-max)))
  3647. (day-numbers (org-get-all-dates
  3648. beg end 'no-ranges
  3649. t org-agenda-show-log-scoped ; always include today
  3650. org-timeline-show-empty-dates))
  3651. (org-deadline-warning-days 0)
  3652. (org-agenda-only-exact-dates t)
  3653. (today (org-today))
  3654. (past t)
  3655. args
  3656. s e rtn d emptyp)
  3657. (setq org-agenda-redo-command
  3658. (list 'let
  3659. (list (list 'org-agenda-show-log 'org-agenda-show-log))
  3660. (list 'org-switch-to-buffer-other-window (current-buffer))
  3661. (list 'org-timeline (list 'quote dotodo))))
  3662. (put 'org-agenda-redo-command 'org-lprops nil)
  3663. (if (not dopast)
  3664. ;; Remove past dates from the list of dates.
  3665. (setq day-numbers (delq nil (mapcar (lambda(x)
  3666. (if (>= x today) x nil))
  3667. day-numbers))))
  3668. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3669. (org-compile-prefix-format 'timeline)
  3670. (org-set-sorting-strategy 'timeline)
  3671. (if org-agenda-show-log-scoped (push :closed args))
  3672. (push :timestamp args)
  3673. (push :deadline args)
  3674. (push :scheduled args)
  3675. (push :sexp args)
  3676. (if dotodo (push :todo args))
  3677. (insert "Timeline of file " entry "\n")
  3678. (add-text-properties (point-min) (point)
  3679. (list 'face 'org-agenda-structure))
  3680. (org-agenda-mark-header-line (point-min))
  3681. (while (setq d (pop day-numbers))
  3682. (if (and (listp d) (eq (car d) :omitted))
  3683. (progn
  3684. (setq s (point))
  3685. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3686. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3687. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3688. (if (and (>= d today)
  3689. dopast
  3690. past)
  3691. (progn
  3692. (setq past nil)
  3693. (insert (make-string 79 ?-) "\n")))
  3694. (setq date (calendar-gregorian-from-absolute d))
  3695. (setq s (point))
  3696. (setq rtn (and (not emptyp)
  3697. (apply 'org-agenda-get-day-entries entry
  3698. date args)))
  3699. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3700. (progn
  3701. (insert
  3702. (if (stringp org-agenda-format-date)
  3703. (format-time-string org-agenda-format-date
  3704. (org-time-from-absolute date))
  3705. (funcall org-agenda-format-date date))
  3706. "\n")
  3707. (put-text-property s (1- (point)) 'face
  3708. (org-agenda-get-day-face date))
  3709. (put-text-property s (1- (point)) 'org-date-line t)
  3710. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3711. (if (equal d today)
  3712. (put-text-property s (1- (point)) 'org-today t))
  3713. (and rtn (insert (org-agenda-finalize-entries rtn 'timeline) "\n"))
  3714. (put-text-property s (1- (point)) 'day d)))))
  3715. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3716. (point-min)))
  3717. (add-text-properties
  3718. (point-min) (point-max)
  3719. `(org-agenda-type timeline org-redo-cmd ,org-agenda-redo-command))
  3720. (org-agenda-finalize)
  3721. (setq buffer-read-only t)))
  3722. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3723. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3724. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3725. not every single day in the range. If FORCE-TODAY is non-nil, make
  3726. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3727. inactive time stamps (those in square brackets) are included.
  3728. When EMPTY is non-nil, also include days without any entries."
  3729. (let ((re (concat
  3730. (if pre-re pre-re "")
  3731. (if inactive org-ts-regexp-both org-ts-regexp)))
  3732. dates dates1 date day day1 day2 ts1 ts2 pos)
  3733. (if force-today
  3734. (setq dates (list (org-today))))
  3735. (save-excursion
  3736. (goto-char beg)
  3737. (while (re-search-forward re end t)
  3738. (setq day (time-to-days (org-time-string-to-time
  3739. (substring (match-string 1) 0 10)
  3740. (current-buffer) (match-beginning 0))))
  3741. (or (memq day dates) (push day dates)))
  3742. (unless no-ranges
  3743. (goto-char beg)
  3744. (while (re-search-forward org-tr-regexp end t)
  3745. (setq pos (match-beginning 0))
  3746. (setq ts1 (substring (match-string 1) 0 10)
  3747. ts2 (substring (match-string 2) 0 10)
  3748. day1 (time-to-days (org-time-string-to-time
  3749. ts1 (current-buffer) pos))
  3750. day2 (time-to-days (org-time-string-to-time
  3751. ts2 (current-buffer) pos)))
  3752. (while (< (setq day1 (1+ day1)) day2)
  3753. (or (memq day1 dates) (push day1 dates)))))
  3754. (setq dates (sort dates '<))
  3755. (when empty
  3756. (while (setq day (pop dates))
  3757. (setq day2 (car dates))
  3758. (push day dates1)
  3759. (when (and day2 empty)
  3760. (if (or (eq empty t)
  3761. (and (numberp empty) (<= (- day2 day) empty)))
  3762. (while (< (setq day (1+ day)) day2)
  3763. (push (list day) dates1))
  3764. (push (cons :omitted (- day2 day)) dates1))))
  3765. (setq dates (nreverse dates1)))
  3766. dates)))
  3767. ;;; Agenda Daily/Weekly
  3768. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3769. "Start day for the agenda view.
  3770. Custom commands can set this variable in the options section.
  3771. This is usually a string like \"2007-11-01\", \"+2d\" or any other
  3772. input allowed when reading a date through the Org calendar.
  3773. See the docstring of `org-read-date' for details.")
  3774. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3775. (defvar org-arg-loc nil) ; local variable
  3776. (defvar org-agenda-buffer-tmp-name nil)
  3777. ;;;###autoload
  3778. (defun org-agenda-list (&optional arg start-day span with-hour)
  3779. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3780. The view will be for the current day or week, but from the overview buffer
  3781. you will be able to go to other days/weeks.
  3782. With a numeric prefix argument in an interactive call, the agenda will
  3783. span ARG days. Lisp programs should instead specify SPAN to change
  3784. the number of days. SPAN defaults to `org-agenda-span'.
  3785. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3786. given in `org-agenda-start-on-weekday'.
  3787. When WITH-HOUR is non-nil, only include scheduled and deadline
  3788. items if they have an hour specification like [h]h:mm."
  3789. (interactive "P")
  3790. (if org-agenda-overriding-arguments
  3791. (setq arg (car org-agenda-overriding-arguments)
  3792. start-day (nth 1 org-agenda-overriding-arguments)
  3793. span (nth 2 org-agenda-overriding-arguments)))
  3794. (if (and (integerp arg) (> arg 0))
  3795. (setq span arg arg nil))
  3796. (catch 'exit
  3797. (setq org-agenda-buffer-name
  3798. (or org-agenda-buffer-tmp-name
  3799. (if org-agenda-sticky
  3800. (cond ((and org-keys (stringp org-match))
  3801. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3802. (org-keys
  3803. (format "*Org Agenda(%s)*" org-keys))
  3804. (t "*Org Agenda(a)*")))
  3805. org-agenda-buffer-name))
  3806. (org-agenda-prepare "Day/Week")
  3807. (setq start-day (or start-day org-agenda-start-day))
  3808. (if (stringp start-day)
  3809. ;; Convert to an absolute day number
  3810. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3811. (org-compile-prefix-format 'agenda)
  3812. (org-set-sorting-strategy 'agenda)
  3813. (let* ((span (org-agenda-ndays-to-span
  3814. (or span org-agenda-ndays org-agenda-span)))
  3815. (today (org-today))
  3816. (sd (or start-day today))
  3817. (ndays (org-agenda-span-to-ndays span sd))
  3818. (org-agenda-start-on-weekday
  3819. (if (or (eq ndays 7) (eq ndays 14))
  3820. org-agenda-start-on-weekday))
  3821. (thefiles (org-agenda-files nil 'ifmode))
  3822. (files thefiles)
  3823. (start (if (or (null org-agenda-start-on-weekday)
  3824. (< ndays 7))
  3825. sd
  3826. (let* ((nt (calendar-day-of-week
  3827. (calendar-gregorian-from-absolute sd)))
  3828. (n1 org-agenda-start-on-weekday)
  3829. (d (- nt n1)))
  3830. (- sd (+ (if (< d 0) 7 0) d)))))
  3831. (day-numbers (list start))
  3832. (day-cnt 0)
  3833. (inhibit-redisplay (not debug-on-error))
  3834. (org-agenda-show-log-scoped org-agenda-show-log)
  3835. s e rtn rtnall file date d start-pos end-pos todayp
  3836. clocktable-start clocktable-end filter)
  3837. (setq org-agenda-redo-command
  3838. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span) with-hour))
  3839. (dotimes (n (1- ndays))
  3840. (push (1+ (car day-numbers)) day-numbers))
  3841. (setq day-numbers (nreverse day-numbers))
  3842. (setq clocktable-start (car day-numbers)
  3843. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3844. (org-set-local 'org-starting-day (car day-numbers))
  3845. (org-set-local 'org-arg-loc arg)
  3846. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3847. (unless org-agenda-compact-blocks
  3848. (let* ((d1 (car day-numbers))
  3849. (d2 (org-last day-numbers))
  3850. (w1 (org-days-to-iso-week d1))
  3851. (w2 (org-days-to-iso-week d2)))
  3852. (setq s (point))
  3853. (if org-agenda-overriding-header
  3854. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3855. nil 'face 'org-agenda-structure) "\n")
  3856. (insert (org-agenda-span-name span)
  3857. "-agenda"
  3858. (if (< (- d2 d1) 350)
  3859. (if (= w1 w2)
  3860. (format " (W%02d)" w1)
  3861. (format " (W%02d-W%02d)" w1 w2))
  3862. "")
  3863. ":\n")))
  3864. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3865. 'org-date-line t))
  3866. (org-agenda-mark-header-line s))
  3867. (while (setq d (pop day-numbers))
  3868. (setq date (calendar-gregorian-from-absolute d)
  3869. s (point))
  3870. (if (or (setq todayp (= d today))
  3871. (and (not start-pos) (= d sd)))
  3872. (setq start-pos (point))
  3873. (if (and start-pos (not end-pos))
  3874. (setq end-pos (point))))
  3875. (setq files thefiles
  3876. rtnall nil)
  3877. (while (setq file (pop files))
  3878. (catch 'nextfile
  3879. (org-check-agenda-file file)
  3880. (let ((org-agenda-entry-types org-agenda-entry-types))
  3881. ;; Starred types override non-starred equivalents
  3882. (when (member :deadline* org-agenda-entry-types)
  3883. (setq org-agenda-entry-types
  3884. (delq :deadline org-agenda-entry-types)))
  3885. (when (member :scheduled* org-agenda-entry-types)
  3886. (setq org-agenda-entry-types
  3887. (delq :scheduled org-agenda-entry-types)))
  3888. ;; Honor with-hour
  3889. (when with-hour
  3890. (when (member :deadline org-agenda-entry-types)
  3891. (setq org-agenda-entry-types
  3892. (delq :deadline org-agenda-entry-types))
  3893. (push :deadline* org-agenda-entry-types))
  3894. (when (member :scheduled org-agenda-entry-types)
  3895. (setq org-agenda-entry-types
  3896. (delq :scheduled org-agenda-entry-types))
  3897. (push :scheduled* org-agenda-entry-types)))
  3898. (unless org-agenda-include-deadlines
  3899. (setq org-agenda-entry-types
  3900. (delq :deadline* (delq :deadline org-agenda-entry-types))))
  3901. (cond
  3902. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3903. (setq rtn (org-agenda-get-day-entries
  3904. file date :closed)))
  3905. (org-agenda-show-log-scoped
  3906. (setq rtn (apply 'org-agenda-get-day-entries
  3907. file date
  3908. (append '(:closed) org-agenda-entry-types))))
  3909. (t
  3910. (setq rtn (apply 'org-agenda-get-day-entries
  3911. file date
  3912. org-agenda-entry-types)))))
  3913. (setq rtnall (append rtnall rtn)))) ;; all entries
  3914. (if org-agenda-include-diary
  3915. (let ((org-agenda-search-headline-for-time t))
  3916. (require 'diary-lib)
  3917. (setq rtn (org-get-entries-from-diary date))
  3918. (setq rtnall (append rtnall rtn))))
  3919. (if (or rtnall org-agenda-show-all-dates)
  3920. (progn
  3921. (setq day-cnt (1+ day-cnt))
  3922. (insert
  3923. (if (stringp org-agenda-format-date)
  3924. (format-time-string org-agenda-format-date
  3925. (org-time-from-absolute date))
  3926. (funcall org-agenda-format-date date))
  3927. "\n")
  3928. (put-text-property s (1- (point)) 'face
  3929. (org-agenda-get-day-face date))
  3930. (put-text-property s (1- (point)) 'org-date-line t)
  3931. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3932. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3933. (when todayp
  3934. (put-text-property s (1- (point)) 'org-today t))
  3935. (setq rtnall
  3936. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3937. (if rtnall (insert ;; all entries
  3938. (org-agenda-finalize-entries rtnall 'agenda)
  3939. "\n"))
  3940. (put-text-property s (1- (point)) 'day d)
  3941. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3942. (when (and org-agenda-clockreport-mode clocktable-start)
  3943. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3944. ;; the above line is to ensure the restricted range!
  3945. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3946. tbl)
  3947. (setq p (org-plist-delete p :block))
  3948. (setq p (plist-put p :tstart clocktable-start))
  3949. (setq p (plist-put p :tend clocktable-end))
  3950. (setq p (plist-put p :scope 'agenda))
  3951. (setq tbl (apply 'org-clock-get-clocktable p))
  3952. (insert tbl)))
  3953. (goto-char (point-min))
  3954. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3955. (unless (and (pos-visible-in-window-p (point-min))
  3956. (pos-visible-in-window-p (point-max)))
  3957. (goto-char (1- (point-max)))
  3958. (recenter -1)
  3959. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3960. (progn
  3961. (goto-char (or start-pos 1))
  3962. (recenter 1))))
  3963. (goto-char (or start-pos 1))
  3964. (add-text-properties (point-min) (point-max)
  3965. `(org-agenda-type agenda
  3966. org-last-args (,arg ,start-day ,span)
  3967. org-redo-cmd ,org-agenda-redo-command
  3968. org-series-cmd ,org-cmd))
  3969. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3970. (org-agenda-show-clocking-issues))
  3971. (org-agenda-finalize)
  3972. (setq buffer-read-only t)
  3973. (message ""))))
  3974. (defun org-agenda-ndays-to-span (n)
  3975. "Return a span symbol for a span of N days, or N if none matches."
  3976. (cond ((symbolp n) n)
  3977. ((= n 1) 'day)
  3978. ((= n 7) 'week)
  3979. ((= n 14) 'fortnight)
  3980. (t n)))
  3981. (defun org-agenda-span-to-ndays (span &optional start-day)
  3982. "Return ndays from SPAN, possibly starting at START-DAY.
  3983. START-DAY is an absolute time value."
  3984. (cond ((numberp span) span)
  3985. ((eq span 'day) 1)
  3986. ((eq span 'week) 7)
  3987. ((eq span 'fortnight) 14)
  3988. ((eq span 'month)
  3989. (let ((date (calendar-gregorian-from-absolute start-day)))
  3990. (calendar-last-day-of-month (car date) (caddr date))))
  3991. ((eq span 'year)
  3992. (let ((date (calendar-gregorian-from-absolute start-day)))
  3993. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3994. (defun org-agenda-span-name (span)
  3995. "Return a SPAN name."
  3996. (if (null span)
  3997. ""
  3998. (if (symbolp span)
  3999. (capitalize (symbol-name span))
  4000. (format "%d days" span))))
  4001. ;;; Agenda word search
  4002. (defvar org-agenda-search-history nil)
  4003. (defvar org-search-syntax-table nil
  4004. "Special syntax table for org-mode search.
  4005. In this table, we have single quotes not as word constituents, to
  4006. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  4007. (defvar org-mode-syntax-table) ; From org.el
  4008. (defun org-search-syntax-table ()
  4009. (unless org-search-syntax-table
  4010. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  4011. (modify-syntax-entry ?' "." org-search-syntax-table)
  4012. (modify-syntax-entry ?` "." org-search-syntax-table))
  4013. org-search-syntax-table)
  4014. (defvar org-agenda-last-search-view-search-was-boolean nil)
  4015. ;;;###autoload
  4016. (defun org-search-view (&optional todo-only string edit-at)
  4017. "Show all entries that contain a phrase or words or regular expressions.
  4018. With optional prefix argument TODO-ONLY, only consider entries that are
  4019. TODO entries. The argument STRING can be used to pass a default search
  4020. string into this function. If EDIT-AT is non-nil, it means that the
  4021. user should get a chance to edit this string, with cursor at position
  4022. EDIT-AT.
  4023. The search string can be viewed either as a phrase that should be found as
  4024. is, or it can be broken into a number of snippets, each of which must match
  4025. in a Boolean way to select an entry. The default depends on the variable
  4026. `org-agenda-search-view-always-boolean'.
  4027. Even if this is turned off (the default) you can always switch to
  4028. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4029. The default is a direct search of the whole phrase, where each space in
  4030. the search string can expand to an arbitrary amount of whitespace,
  4031. including newlines.
  4032. If using a Boolean search, the search string is split on whitespace and
  4033. each snippet is searched separately, with logical AND to select an entry.
  4034. Words prefixed with a minus must *not* occur in the entry. Words without
  4035. a prefix or prefixed with a plus must occur in the entry. Matching is
  4036. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4037. match whole words, not parts of a word) if
  4038. `org-agenda-search-view-force-full-words' is set (default is nil).
  4039. Boolean search snippets enclosed by curly braces are interpreted as
  4040. regular expressions that must or (when preceded with \"-\") must not
  4041. match in the entry. Snippets enclosed into double quotes will be taken
  4042. as a whole, to include whitespace.
  4043. - If the search string starts with an asterisk, search only in headlines.
  4044. - If (possibly after the leading star) the search string starts with an
  4045. exclamation mark, this also means to look at TODO entries only, an effect
  4046. that can also be achieved with a prefix argument.
  4047. - If (possibly after star and exclamation mark) the search string starts
  4048. with a colon, this will mean that the (non-regexp) snippets of the
  4049. Boolean search must match as full words.
  4050. This command searches the agenda files, and in addition the files listed
  4051. in `org-agenda-text-search-extra-files'."
  4052. (interactive "P")
  4053. (if org-agenda-overriding-arguments
  4054. (setq todo-only (car org-agenda-overriding-arguments)
  4055. string (nth 1 org-agenda-overriding-arguments)
  4056. edit-at (nth 2 org-agenda-overriding-arguments)))
  4057. (let* ((props (list 'face nil
  4058. 'done-face 'org-agenda-done
  4059. 'org-not-done-regexp org-not-done-regexp
  4060. 'org-todo-regexp org-todo-regexp
  4061. 'org-complex-heading-regexp org-complex-heading-regexp
  4062. 'mouse-face 'highlight
  4063. 'help-echo (format "mouse-2 or RET jump to location")))
  4064. (full-words org-agenda-search-view-force-full-words)
  4065. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  4066. regexp rtn rtnall files file pos inherited-tags
  4067. marker category category-pos level tags c neg re boolean
  4068. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  4069. (unless (and (not edit-at)
  4070. (stringp string)
  4071. (string-match "\\S-" string))
  4072. (setq string (read-string
  4073. (if org-agenda-search-view-always-boolean
  4074. "[+-]Word/{Regexp} ...: "
  4075. "Phrase or [+-]Word/{Regexp} ...: ")
  4076. (cond
  4077. ((integerp edit-at) (cons string edit-at))
  4078. (edit-at string))
  4079. 'org-agenda-search-history)))
  4080. (catch 'exit
  4081. (if org-agenda-sticky
  4082. (setq org-agenda-buffer-name
  4083. (if (stringp string)
  4084. (format "*Org Agenda(%s:%s)*"
  4085. (or org-keys (or (and todo-only "S") "s")) string)
  4086. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  4087. (org-agenda-prepare "SEARCH")
  4088. (org-compile-prefix-format 'search)
  4089. (org-set-sorting-strategy 'search)
  4090. (setq org-agenda-redo-command
  4091. (list 'org-search-view (if todo-only t nil)
  4092. (list 'if 'current-prefix-arg nil string)))
  4093. (setq org-agenda-query-string string)
  4094. (if (equal (string-to-char string) ?*)
  4095. (setq hdl-only t
  4096. words (substring string 1))
  4097. (setq words string))
  4098. (when (equal (string-to-char words) ?!)
  4099. (setq todo-only t
  4100. words (substring words 1)))
  4101. (when (equal (string-to-char words) ?:)
  4102. (setq full-words t
  4103. words (substring words 1)))
  4104. (if (or org-agenda-search-view-always-boolean
  4105. (member (string-to-char words) '(?- ?+ ?\{)))
  4106. (setq boolean t))
  4107. (setq words (org-split-string words))
  4108. (let (www w)
  4109. (while (setq w (pop words))
  4110. (while (and (string-match "\\\\\\'" w) words)
  4111. (setq w (concat (substring w 0 -1) " " (pop words))))
  4112. (push w www))
  4113. (setq words (nreverse www) www nil)
  4114. (while (setq w (pop words))
  4115. (when (and (string-match "\\`[-+]?{" w)
  4116. (not (string-match "}\\'" w)))
  4117. (while (and words (not (string-match "}\\'" (car words))))
  4118. (setq w (concat w " " (pop words))))
  4119. (setq w (concat w " " (pop words))))
  4120. (push w www))
  4121. (setq words (nreverse www)))
  4122. (setq org-agenda-last-search-view-search-was-boolean boolean)
  4123. (when boolean
  4124. (let (wds w)
  4125. (while (setq w (pop words))
  4126. (if (or (equal (substring w 0 1) "\"")
  4127. (and (> (length w) 1)
  4128. (member (substring w 0 1) '("+" "-"))
  4129. (equal (substring w 1 2) "\"")))
  4130. (while (and words (not (equal (substring w -1) "\"")))
  4131. (setq w (concat w " " (pop words)))))
  4132. (and (string-match "\\`\\([-+]?\\)\"" w)
  4133. (setq w (replace-match "\\1" nil nil w)))
  4134. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  4135. (push w wds))
  4136. (setq words (nreverse wds))))
  4137. (if boolean
  4138. (mapc (lambda (w)
  4139. (setq c (string-to-char w))
  4140. (if (equal c ?-)
  4141. (setq neg t w (substring w 1))
  4142. (if (equal c ?+)
  4143. (setq neg nil w (substring w 1))
  4144. (setq neg nil)))
  4145. (if (string-match "\\`{.*}\\'" w)
  4146. (setq re (substring w 1 -1))
  4147. (if full-words
  4148. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  4149. (setq re (regexp-quote (downcase w)))))
  4150. (if neg (push re regexps-) (push re regexps+)))
  4151. words)
  4152. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  4153. regexps+))
  4154. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  4155. (if (not regexps+)
  4156. (setq regexp org-outline-regexp-bol)
  4157. (setq regexp (pop regexps+))
  4158. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  4159. regexp))))
  4160. (setq files (org-agenda-files nil 'ifmode))
  4161. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  4162. (pop org-agenda-text-search-extra-files)
  4163. (setq files (org-add-archive-files files)))
  4164. (setq files (append files org-agenda-text-search-extra-files)
  4165. rtnall nil)
  4166. (while (setq file (pop files))
  4167. (setq ee nil)
  4168. (catch 'nextfile
  4169. (org-check-agenda-file file)
  4170. (setq buffer (if (file-exists-p file)
  4171. (org-get-agenda-file-buffer file)
  4172. (error "No such file %s" file)))
  4173. (if (not buffer)
  4174. ;; If file does not exist, make sure an error message is sent
  4175. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  4176. file))))
  4177. (with-current-buffer buffer
  4178. (with-syntax-table (org-search-syntax-table)
  4179. (unless (derived-mode-p 'org-mode)
  4180. (error "Agenda file %s is not in `org-mode'" file))
  4181. (let ((case-fold-search t))
  4182. (save-excursion
  4183. (save-restriction
  4184. (if (eq buffer org-agenda-restrict)
  4185. (narrow-to-region org-agenda-restrict-begin
  4186. org-agenda-restrict-end)
  4187. (widen))
  4188. (goto-char (point-min))
  4189. (unless (or (org-at-heading-p)
  4190. (outline-next-heading))
  4191. (throw 'nextfile t))
  4192. (goto-char (max (point-min) (1- (point))))
  4193. (while (re-search-forward regexp nil t)
  4194. (org-back-to-heading t)
  4195. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4196. (> (org-reduced-level (org-outline-level))
  4197. org-agenda-search-view-max-outline-level)
  4198. (forward-line -1)
  4199. (outline-back-to-heading t)))
  4200. (skip-chars-forward "* ")
  4201. (setq beg (point-at-bol)
  4202. beg1 (point)
  4203. end (progn
  4204. (outline-next-heading)
  4205. (while (and (not (zerop org-agenda-search-view-max-outline-level))
  4206. (> (org-reduced-level (org-outline-level))
  4207. org-agenda-search-view-max-outline-level)
  4208. (forward-line 1)
  4209. (outline-next-heading)))
  4210. (point)))
  4211. (catch :skip
  4212. (goto-char beg)
  4213. (org-agenda-skip)
  4214. (setq str (buffer-substring-no-properties
  4215. (point-at-bol)
  4216. (if hdl-only (point-at-eol) end)))
  4217. (mapc (lambda (wr) (when (string-match wr str)
  4218. (goto-char (1- end))
  4219. (throw :skip t)))
  4220. regexps-)
  4221. (mapc (lambda (wr) (unless (string-match wr str)
  4222. (goto-char (1- end))
  4223. (throw :skip t)))
  4224. (if todo-only
  4225. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4226. regexps+)
  4227. regexps+))
  4228. (goto-char beg)
  4229. (setq marker (org-agenda-new-marker (point))
  4230. category (org-get-category)
  4231. level (make-string (org-reduced-level (org-outline-level)) ? )
  4232. category-pos (get-text-property (point) 'org-category-position)
  4233. inherited-tags
  4234. (or (eq org-agenda-show-inherited-tags 'always)
  4235. (and (listp org-agenda-show-inherited-tags)
  4236. (memq 'todo org-agenda-show-inherited-tags))
  4237. (and (eq org-agenda-show-inherited-tags t)
  4238. (or (eq org-agenda-use-tag-inheritance t)
  4239. (memq 'todo org-agenda-use-tag-inheritance))))
  4240. tags (org-get-tags-at nil (not inherited-tags))
  4241. txt (org-agenda-format-item
  4242. ""
  4243. (buffer-substring-no-properties
  4244. beg1 (point-at-eol))
  4245. level category tags t))
  4246. (org-add-props txt props
  4247. 'org-marker marker 'org-hd-marker marker
  4248. 'org-todo-regexp org-todo-regexp
  4249. 'level level
  4250. 'org-complex-heading-regexp org-complex-heading-regexp
  4251. 'priority 1000 'org-category category
  4252. 'org-category-position category-pos
  4253. 'type "search")
  4254. (push txt ee)
  4255. (goto-char (1- end))))))))))
  4256. (setq rtn (nreverse ee))
  4257. (setq rtnall (append rtnall rtn)))
  4258. (if org-agenda-overriding-header
  4259. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4260. nil 'face 'org-agenda-structure) "\n")
  4261. (insert "Search words: ")
  4262. (add-text-properties (point-min) (1- (point))
  4263. (list 'face 'org-agenda-structure))
  4264. (setq pos (point))
  4265. (insert string "\n")
  4266. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4267. (setq pos (point))
  4268. (unless org-agenda-multi
  4269. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4270. (add-text-properties pos (1- (point))
  4271. (list 'face 'org-agenda-structure))))
  4272. (org-agenda-mark-header-line (point-min))
  4273. (when rtnall
  4274. (insert (org-agenda-finalize-entries rtnall 'search) "\n"))
  4275. (goto-char (point-min))
  4276. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4277. (add-text-properties (point-min) (point-max)
  4278. `(org-agenda-type search
  4279. org-last-args (,todo-only ,string ,edit-at)
  4280. org-redo-cmd ,org-agenda-redo-command
  4281. org-series-cmd ,org-cmd))
  4282. (org-agenda-finalize)
  4283. (setq buffer-read-only t))))
  4284. ;;; Agenda TODO list
  4285. (defun org-agenda-propertize-selected-todo-keywords (keywords)
  4286. "Use `org-todo-keyword-faces' for the selected todo KEYWORDS."
  4287. (concat
  4288. (if (or (equal keywords "ALL") (not keywords))
  4289. (propertize "ALL" 'face 'warning)
  4290. (mapconcat
  4291. (lambda (kw)
  4292. (propertize kw 'face (org-get-todo-face kw)))
  4293. (org-split-string keywords "|")
  4294. "|"))
  4295. "\n"))
  4296. (defvar org-select-this-todo-keyword nil)
  4297. (defvar org-last-arg nil)
  4298. ;;;###autoload
  4299. (defun org-todo-list (&optional arg)
  4300. "Show all (not done) TODO entries from all agenda file in a single list.
  4301. The prefix arg can be used to select a specific TODO keyword and limit
  4302. the list to these. When using \\[universal-argument], you will be prompted
  4303. for a keyword. A numeric prefix directly selects the Nth keyword in
  4304. `org-todo-keywords-1'."
  4305. (interactive "P")
  4306. (if org-agenda-overriding-arguments
  4307. (setq arg org-agenda-overriding-arguments))
  4308. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4309. (let* ((today (org-today))
  4310. (date (calendar-gregorian-from-absolute today))
  4311. (kwds org-todo-keywords-for-agenda)
  4312. (completion-ignore-case t)
  4313. (org-select-this-todo-keyword
  4314. (if (stringp arg) arg
  4315. (and arg (integerp arg) (> arg 0)
  4316. (nth (1- arg) kwds))))
  4317. rtn rtnall files file pos)
  4318. (when (equal arg '(4))
  4319. (setq org-select-this-todo-keyword
  4320. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4321. (mapcar 'list kwds) nil nil)))
  4322. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4323. (catch 'exit
  4324. (if org-agenda-sticky
  4325. (setq org-agenda-buffer-name
  4326. (if (stringp org-select-this-todo-keyword)
  4327. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4328. org-select-this-todo-keyword)
  4329. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4330. (org-agenda-prepare "TODO")
  4331. (org-compile-prefix-format 'todo)
  4332. (org-set-sorting-strategy 'todo)
  4333. (setq org-agenda-redo-command
  4334. `(org-todo-list (or (and (numberp current-prefix-arg)
  4335. current-prefix-arg)
  4336. ,org-select-this-todo-keyword
  4337. current-prefix-arg ,arg)))
  4338. (setq files (org-agenda-files nil 'ifmode)
  4339. rtnall nil)
  4340. (while (setq file (pop files))
  4341. (catch 'nextfile
  4342. (org-check-agenda-file file)
  4343. (setq rtn (org-agenda-get-day-entries file date :todo))
  4344. (setq rtnall (append rtnall rtn))))
  4345. (if org-agenda-overriding-header
  4346. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4347. nil 'face 'org-agenda-structure) "\n")
  4348. (insert "Global list of TODO items of type: ")
  4349. (add-text-properties (point-min) (1- (point))
  4350. (list 'face 'org-agenda-structure
  4351. 'short-heading
  4352. (concat "ToDo: "
  4353. (or org-select-this-todo-keyword "ALL"))))
  4354. (org-agenda-mark-header-line (point-min))
  4355. (insert (org-agenda-propertize-selected-todo-keywords
  4356. org-select-this-todo-keyword))
  4357. (setq pos (point))
  4358. (unless org-agenda-multi
  4359. (insert "Available with `N r': (0)[ALL]")
  4360. (let ((n 0) s)
  4361. (mapc (lambda (x)
  4362. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4363. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4364. (insert "\n "))
  4365. (insert " " s))
  4366. kwds))
  4367. (insert "\n"))
  4368. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4369. (org-agenda-mark-header-line (point-min))
  4370. (when rtnall
  4371. (insert (org-agenda-finalize-entries rtnall 'todo) "\n"))
  4372. (goto-char (point-min))
  4373. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4374. (add-text-properties (point-min) (point-max)
  4375. `(org-agenda-type todo
  4376. org-last-args ,arg
  4377. org-redo-cmd ,org-agenda-redo-command
  4378. org-series-cmd ,org-cmd))
  4379. (org-agenda-finalize)
  4380. (setq buffer-read-only t))))
  4381. ;;; Agenda tags match
  4382. ;;;###autoload
  4383. (defun org-tags-view (&optional todo-only match)
  4384. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4385. The prefix arg TODO-ONLY limits the search to TODO entries."
  4386. (interactive "P")
  4387. (if org-agenda-overriding-arguments
  4388. (setq todo-only (car org-agenda-overriding-arguments)
  4389. match (nth 1 org-agenda-overriding-arguments)))
  4390. (let* ((org-tags-match-list-sublevels
  4391. org-tags-match-list-sublevels)
  4392. (completion-ignore-case t)
  4393. rtn rtnall files file pos matcher
  4394. buffer)
  4395. (when (and (stringp match) (not (string-match "\\S-" match)))
  4396. (setq match nil))
  4397. (catch 'exit
  4398. (if org-agenda-sticky
  4399. (setq org-agenda-buffer-name
  4400. (if (stringp match)
  4401. (format "*Org Agenda(%s:%s)*"
  4402. (or org-keys (or (and todo-only "M") "m")) match)
  4403. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4404. ;; Prepare agendas (and `org-tag-alist-for-agenda') before
  4405. ;; expanding tags within `org-make-tags-matcher'
  4406. (org-agenda-prepare (concat "TAGS " match))
  4407. (setq matcher (org-make-tags-matcher match)
  4408. match (car matcher) matcher (cdr matcher))
  4409. (org-compile-prefix-format 'tags)
  4410. (org-set-sorting-strategy 'tags)
  4411. (setq org-agenda-query-string match)
  4412. (setq org-agenda-redo-command
  4413. (list 'org-tags-view `(quote ,todo-only)
  4414. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4415. (setq files (org-agenda-files nil 'ifmode)
  4416. rtnall nil)
  4417. (while (setq file (pop files))
  4418. (catch 'nextfile
  4419. (org-check-agenda-file file)
  4420. (setq buffer (if (file-exists-p file)
  4421. (org-get-agenda-file-buffer file)
  4422. (error "No such file %s" file)))
  4423. (if (not buffer)
  4424. ;; If file does not exist, error message to agenda
  4425. (setq rtn (list
  4426. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4427. rtnall (append rtnall rtn))
  4428. (with-current-buffer buffer
  4429. (unless (derived-mode-p 'org-mode)
  4430. (error "Agenda file %s is not in `org-mode'" file))
  4431. (save-excursion
  4432. (save-restriction
  4433. (if (eq buffer org-agenda-restrict)
  4434. (narrow-to-region org-agenda-restrict-begin
  4435. org-agenda-restrict-end)
  4436. (widen))
  4437. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4438. (setq rtnall (append rtnall rtn))))))))
  4439. (if org-agenda-overriding-header
  4440. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4441. nil 'face 'org-agenda-structure) "\n")
  4442. (insert "Headlines with TAGS match: ")
  4443. (add-text-properties (point-min) (1- (point))
  4444. (list 'face 'org-agenda-structure
  4445. 'short-heading
  4446. (concat "Match: " match)))
  4447. (setq pos (point))
  4448. (insert match "\n")
  4449. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4450. (setq pos (point))
  4451. (unless org-agenda-multi
  4452. (insert "Press `C-u r' to search again with new search string\n"))
  4453. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4454. (org-agenda-mark-header-line (point-min))
  4455. (when rtnall
  4456. (insert (org-agenda-finalize-entries rtnall 'tags) "\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 tags
  4461. org-last-args (,todo-only ,match)
  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 Finding stuck projects
  4467. (defvar org-agenda-skip-regexp nil
  4468. "Regular expression used in skipping subtrees for the agenda.
  4469. This is basically a temporary global variable that can be set and then
  4470. used by user-defined selections using `org-agenda-skip-function'.")
  4471. (defvar org-agenda-overriding-header nil
  4472. "When set during agenda, todo and tags searches it replaces the header.
  4473. This variable should not be set directly, but custom commands can bind it
  4474. in the options section.")
  4475. (defun org-agenda-skip-entry-when-regexp-matches ()
  4476. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4477. If yes, it returns the end position of this entry, causing agenda commands
  4478. to skip the entry but continuing the search in the subtree. This is a
  4479. function that can be put into `org-agenda-skip-function' for the duration
  4480. of a command."
  4481. (let ((end (save-excursion (org-end-of-subtree t)))
  4482. skip)
  4483. (save-excursion
  4484. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4485. (and skip end)))
  4486. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4487. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4488. If yes, it returns the end position of this tree, causing agenda commands
  4489. to skip this subtree. This is a function that can be put into
  4490. `org-agenda-skip-function' for the duration of a command."
  4491. (let ((end (save-excursion (org-end-of-subtree t)))
  4492. skip)
  4493. (save-excursion
  4494. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4495. (and skip end)))
  4496. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4497. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4498. If yes, it returns the end position of the current entry (NOT the tree),
  4499. causing agenda commands to skip the entry but continuing the search in
  4500. the subtree. This is a function that can be put into
  4501. `org-agenda-skip-function' for the duration of a command. An important
  4502. use of this function is for the stuck project list."
  4503. (let ((end (save-excursion (org-end-of-subtree t)))
  4504. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4505. skip)
  4506. (save-excursion
  4507. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4508. (and skip entry-end)))
  4509. (defun org-agenda-skip-entry-if (&rest conditions)
  4510. "Skip entry if any of CONDITIONS is true.
  4511. See `org-agenda-skip-if' for details."
  4512. (org-agenda-skip-if nil conditions))
  4513. (defun org-agenda-skip-subtree-if (&rest conditions)
  4514. "Skip subtree if any of CONDITIONS is true.
  4515. See `org-agenda-skip-if' for details."
  4516. (org-agenda-skip-if t conditions))
  4517. (defun org-agenda-skip-if (subtree conditions)
  4518. "Checks current entity for CONDITIONS.
  4519. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4520. the entry (i.e. the text before the next heading) is checked.
  4521. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4522. from different tests. Valid conditions are:
  4523. scheduled Check if there is a scheduled cookie
  4524. notscheduled Check if there is no scheduled cookie
  4525. deadline Check if there is a deadline
  4526. notdeadline Check if there is no deadline
  4527. timestamp Check if there is a timestamp (also deadline or scheduled)
  4528. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4529. regexp Check if regexp matches
  4530. notregexp Check if regexp does not match.
  4531. todo Check if TODO keyword matches
  4532. nottodo Check if TODO keyword does not match
  4533. The regexp is taken from the conditions list, it must come right after
  4534. the `regexp' or `notregexp' element.
  4535. `todo' and `nottodo' accept as an argument a list of todo
  4536. keywords, which may include \"*\" to match any todo keyword.
  4537. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4538. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4539. Instead of a list, a keyword class may be given. For example:
  4540. (org-agenda-skip-entry-if 'nottodo 'done)
  4541. would skip entries that haven't been marked with any of \"DONE\"
  4542. keywords. Possible classes are: `todo', `done', `any'.
  4543. If any of these conditions is met, this function returns the end point of
  4544. the entity, causing the search to continue from there. This is a function
  4545. that can be put into `org-agenda-skip-function' for the duration of a command."
  4546. (let (beg end m)
  4547. (org-back-to-heading t)
  4548. (setq beg (point)
  4549. end (if subtree
  4550. (progn (org-end-of-subtree t) (point))
  4551. (progn (outline-next-heading) (1- (point)))))
  4552. (goto-char beg)
  4553. (and
  4554. (or
  4555. (and (memq 'scheduled conditions)
  4556. (re-search-forward org-scheduled-time-regexp end t))
  4557. (and (memq 'notscheduled conditions)
  4558. (not (re-search-forward org-scheduled-time-regexp end t)))
  4559. (and (memq 'deadline conditions)
  4560. (re-search-forward org-deadline-time-regexp end t))
  4561. (and (memq 'notdeadline conditions)
  4562. (not (re-search-forward org-deadline-time-regexp end t)))
  4563. (and (memq 'timestamp conditions)
  4564. (re-search-forward org-ts-regexp end t))
  4565. (and (memq 'nottimestamp conditions)
  4566. (not (re-search-forward org-ts-regexp end t)))
  4567. (and (setq m (memq 'regexp conditions))
  4568. (stringp (nth 1 m))
  4569. (re-search-forward (nth 1 m) end t))
  4570. (and (setq m (memq 'notregexp conditions))
  4571. (stringp (nth 1 m))
  4572. (not (re-search-forward (nth 1 m) end t)))
  4573. (and (or
  4574. (setq m (memq 'nottodo conditions))
  4575. (setq m (memq 'todo-unblocked conditions))
  4576. (setq m (memq 'nottodo-unblocked conditions))
  4577. (setq m (memq 'todo conditions)))
  4578. (org-agenda-skip-if-todo m end)))
  4579. end)))
  4580. (defun org-agenda-skip-if-todo (args end)
  4581. "Helper function for `org-agenda-skip-if', do not use it directly.
  4582. ARGS is a list with first element either `todo', `nottodo',
  4583. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4584. a list of TODO keywords, or a state symbol `todo' or `done' or
  4585. `any'."
  4586. (let ((kw (car args))
  4587. (arg (cadr args))
  4588. todo-wds todo-re)
  4589. (setq todo-wds
  4590. (org-uniquify
  4591. (cond
  4592. ((listp arg) ;; list of keywords
  4593. (if (member "*" arg)
  4594. (mapcar 'substring-no-properties org-todo-keywords-1)
  4595. arg))
  4596. ((symbolp arg) ;; keyword class name
  4597. (cond
  4598. ((eq arg 'todo)
  4599. (org-delete-all org-done-keywords
  4600. (mapcar 'substring-no-properties
  4601. org-todo-keywords-1)))
  4602. ((eq arg 'done) org-done-keywords)
  4603. ((eq arg 'any)
  4604. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4605. (setq todo-re
  4606. (concat "^\\*+[ \t]+\\<\\("
  4607. (mapconcat 'identity todo-wds "\\|")
  4608. "\\)\\>"))
  4609. (cond
  4610. ((eq kw 'todo) (re-search-forward todo-re end t))
  4611. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4612. ((eq kw 'todo-unblocked)
  4613. (catch 'unblocked
  4614. (while (re-search-forward todo-re end t)
  4615. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4616. nil))
  4617. ((eq kw 'nottodo-unblocked)
  4618. (catch 'unblocked
  4619. (while (re-search-forward todo-re end t)
  4620. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4621. t))
  4622. )))
  4623. ;;;###autoload
  4624. (defun org-agenda-list-stuck-projects (&rest ignore)
  4625. "Create agenda view for projects that are stuck.
  4626. Stuck projects are project that have no next actions. For the definitions
  4627. of what a project is and how to check if it stuck, customize the variable
  4628. `org-stuck-projects'."
  4629. (interactive)
  4630. (let* ((org-agenda-skip-function
  4631. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4632. ;; We could have used org-agenda-skip-if here.
  4633. (org-agenda-overriding-header
  4634. (or org-agenda-overriding-header "List of stuck projects: "))
  4635. (matcher (nth 0 org-stuck-projects))
  4636. (todo (nth 1 org-stuck-projects))
  4637. (todo-wds (if (member "*" todo)
  4638. (progn
  4639. (org-agenda-prepare-buffers (org-agenda-files
  4640. nil 'ifmode))
  4641. (org-delete-all
  4642. org-done-keywords-for-agenda
  4643. (copy-sequence org-todo-keywords-for-agenda)))
  4644. todo))
  4645. (todo-re (concat "^\\*+[ \t]+\\("
  4646. (mapconcat 'identity todo-wds "\\|")
  4647. "\\)\\>"))
  4648. (tags (nth 2 org-stuck-projects))
  4649. (tags-re (if (member "*" tags)
  4650. (concat org-outline-regexp-bol
  4651. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4652. (if tags
  4653. (concat org-outline-regexp-bol
  4654. ".*:\\("
  4655. (mapconcat 'identity tags "\\|")
  4656. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4657. (gen-re (nth 3 org-stuck-projects))
  4658. (re-list
  4659. (delq nil
  4660. (list
  4661. (if todo todo-re)
  4662. (if tags tags-re)
  4663. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4664. gen-re)))))
  4665. (setq org-agenda-skip-regexp
  4666. (if re-list
  4667. (mapconcat 'identity re-list "\\|")
  4668. (error "No information how to identify unstuck projects")))
  4669. (org-tags-view nil matcher)
  4670. (setq org-agenda-buffer-name (buffer-name))
  4671. (with-current-buffer org-agenda-buffer-name
  4672. (setq org-agenda-redo-command
  4673. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4674. ;;; Diary integration
  4675. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4676. (defvar diary-list-entries-hook)
  4677. (defvar diary-time-regexp)
  4678. (defun org-get-entries-from-diary (date)
  4679. "Get the (Emacs Calendar) diary entries for DATE."
  4680. (require 'diary-lib)
  4681. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4682. (diary-display-hook '(fancy-diary-display))
  4683. (diary-display-function 'fancy-diary-display)
  4684. (pop-up-frames nil)
  4685. (diary-list-entries-hook
  4686. (cons 'org-diary-default-entry diary-list-entries-hook))
  4687. (diary-file-name-prefix nil) ; turn this feature off
  4688. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4689. entries
  4690. (org-disable-agenda-to-diary t))
  4691. (save-excursion
  4692. (save-window-excursion
  4693. (funcall (if (fboundp 'diary-list-entries)
  4694. 'diary-list-entries 'list-diary-entries)
  4695. date 1)))
  4696. (if (not (get-buffer diary-fancy-buffer))
  4697. (setq entries nil)
  4698. (with-current-buffer diary-fancy-buffer
  4699. (setq buffer-read-only nil)
  4700. (if (zerop (buffer-size))
  4701. ;; No entries
  4702. (setq entries nil)
  4703. ;; Omit the date and other unnecessary stuff
  4704. (org-agenda-cleanup-fancy-diary)
  4705. ;; Add prefix to each line and extend the text properties
  4706. (if (zerop (buffer-size))
  4707. (setq entries nil)
  4708. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4709. (setq entries
  4710. (with-temp-buffer
  4711. (insert entries) (goto-char (point-min))
  4712. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4713. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4714. (replace-match (concat "; " (match-string 1)))))
  4715. (buffer-string)))))
  4716. (set-buffer-modified-p nil)
  4717. (kill-buffer diary-fancy-buffer)))
  4718. (when entries
  4719. (setq entries (org-split-string entries "\n"))
  4720. (setq entries
  4721. (mapcar
  4722. (lambda (x)
  4723. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4724. ;; Extend the text properties to the beginning of the line
  4725. (org-add-props x (text-properties-at (1- (length x)) x)
  4726. 'type "diary" 'date date 'face 'org-agenda-diary))
  4727. entries)))))
  4728. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4729. "Hook run when the fancy diary buffer is cleaned up.")
  4730. (defun org-agenda-cleanup-fancy-diary ()
  4731. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4732. This gets rid of the date, the underline under the date, and
  4733. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4734. date. It also removes lines that contain only whitespace."
  4735. (goto-char (point-min))
  4736. (if (looking-at ".*?:[ \t]*")
  4737. (progn
  4738. (replace-match "")
  4739. (re-search-forward "\n=+$" nil t)
  4740. (replace-match "")
  4741. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4742. (re-search-forward "\n=+$" nil t)
  4743. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4744. (goto-char (point-min))
  4745. (while (re-search-forward "^ +\n" nil t)
  4746. (replace-match ""))
  4747. (goto-char (point-min))
  4748. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4749. (replace-match ""))
  4750. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4751. ;; Make sure entries from the diary have the right text properties.
  4752. (eval-after-load "diary-lib"
  4753. '(if (boundp 'diary-modify-entry-list-string-function)
  4754. ;; We can rely on the hook, nothing to do
  4755. nil
  4756. ;; Hook not available, must use advice to make this work
  4757. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4758. "Make the position visible."
  4759. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4760. (stringp string)
  4761. buffer-file-name)
  4762. (setq string (org-modify-diary-entry-string string))))))
  4763. (defun org-modify-diary-entry-string (string)
  4764. "Add text properties to string, allowing org-mode to act on it."
  4765. (org-add-props string nil
  4766. 'mouse-face 'highlight
  4767. 'help-echo (if buffer-file-name
  4768. (format "mouse-2 or RET jump to diary file %s"
  4769. (abbreviate-file-name buffer-file-name))
  4770. "")
  4771. 'org-agenda-diary-link t
  4772. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4773. (defun org-diary-default-entry ()
  4774. "Add a dummy entry to the diary.
  4775. Needed to avoid empty dates which mess up holiday display."
  4776. ;; Catch the error if dealing with the new add-to-diary-alist
  4777. (when org-disable-agenda-to-diary
  4778. (condition-case nil
  4779. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4780. (error
  4781. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4782. (defun org-add-to-diary-list (&rest args)
  4783. (if (fboundp 'diary-add-to-list)
  4784. (apply 'diary-add-to-list args)
  4785. (apply 'add-to-diary-list args)))
  4786. (defvar org-diary-last-run-time nil)
  4787. ;;;###autoload
  4788. (defun org-diary (&rest args)
  4789. "Return diary information from org files.
  4790. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4791. It accesses org files and extracts information from those files to be
  4792. listed in the diary. The function accepts arguments specifying what
  4793. items should be listed. For a list of arguments allowed here, see the
  4794. variable `org-agenda-entry-types'.
  4795. The call in the diary file should look like this:
  4796. &%%(org-diary) ~/path/to/some/orgfile.org
  4797. Use a separate line for each org file to check. Or, if you omit the file name,
  4798. all files listed in `org-agenda-files' will be checked automatically:
  4799. &%%(org-diary)
  4800. If you don't give any arguments (as in the example above), the default value
  4801. of `org-agenda-entry-types' is used: (:deadline :scheduled :timestamp :sexp).
  4802. So the example above may also be written as
  4803. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4804. The function expects the lisp variables `entry' and `date' to be provided
  4805. by the caller, because this is how the calendar works. Don't use this
  4806. function from a program - use `org-agenda-get-day-entries' instead."
  4807. (when (> (- (org-float-time)
  4808. org-agenda-last-marker-time)
  4809. 5)
  4810. ;; I am not sure if this works with sticky agendas, because the marker
  4811. ;; list is then no longer a global variable.
  4812. (org-agenda-reset-markers))
  4813. (org-compile-prefix-format 'agenda)
  4814. (org-set-sorting-strategy 'agenda)
  4815. (setq args (or args org-agenda-entry-types))
  4816. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4817. (list entry)
  4818. (org-agenda-files t)))
  4819. (time (org-float-time))
  4820. file rtn results)
  4821. (when (or (not org-diary-last-run-time)
  4822. (> (- time
  4823. org-diary-last-run-time)
  4824. 3))
  4825. (org-agenda-prepare-buffers files))
  4826. (setq org-diary-last-run-time time)
  4827. ;; If this is called during org-agenda, don't return any entries to
  4828. ;; the calendar. Org Agenda will list these entries itself.
  4829. (if org-disable-agenda-to-diary (setq files nil))
  4830. (while (setq file (pop files))
  4831. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4832. (setq results (append results rtn)))
  4833. (when results
  4834. (setq results
  4835. (mapcar (lambda (i) (replace-regexp-in-string
  4836. org-bracket-link-regexp "\\3" i)) results))
  4837. (concat (org-agenda-finalize-entries results) "\n"))))
  4838. ;;; Agenda entry finders
  4839. (defun org-agenda-get-day-entries (file date &rest args)
  4840. "Does the work for `org-diary' and `org-agenda'.
  4841. FILE is the path to a file to be checked for entries. DATE is date like
  4842. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4843. which kind of entries should be extracted. For details about these, see
  4844. the documentation of `org-diary'."
  4845. (setq args (or args org-agenda-entry-types))
  4846. (let* ((org-startup-folded nil)
  4847. (org-startup-align-all-tables nil)
  4848. (buffer (if (file-exists-p file)
  4849. (org-get-agenda-file-buffer file)
  4850. (error "No such file %s" file)))
  4851. arg results rtn deadline-results)
  4852. (if (not buffer)
  4853. ;; If file does not exist, make sure an error message ends up in diary
  4854. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4855. (with-current-buffer buffer
  4856. (unless (derived-mode-p 'org-mode)
  4857. (error "Agenda file %s is not in `org-mode'" file))
  4858. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4859. (let ((case-fold-search nil))
  4860. (save-excursion
  4861. (save-restriction
  4862. (if (eq buffer org-agenda-restrict)
  4863. (narrow-to-region org-agenda-restrict-begin
  4864. org-agenda-restrict-end)
  4865. (widen))
  4866. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4867. (while (setq arg (pop args))
  4868. (cond
  4869. ((and (eq arg :todo)
  4870. (equal date (calendar-gregorian-from-absolute
  4871. (org-today))))
  4872. (setq rtn (org-agenda-get-todos))
  4873. (setq results (append results rtn)))
  4874. ((eq arg :timestamp)
  4875. (setq rtn (org-agenda-get-blocks))
  4876. (setq results (append results rtn))
  4877. (setq rtn (org-agenda-get-timestamps deadline-results))
  4878. (setq results (append results rtn)))
  4879. ((eq arg :sexp)
  4880. (setq rtn (org-agenda-get-sexps))
  4881. (setq results (append results rtn)))
  4882. ((eq arg :scheduled)
  4883. (setq rtn (org-agenda-get-scheduled deadline-results))
  4884. (setq results (append results rtn)))
  4885. ((eq arg :scheduled*)
  4886. (setq rtn (org-agenda-get-scheduled deadline-results t))
  4887. (setq results (append results rtn)))
  4888. ((eq arg :closed)
  4889. (setq rtn (org-agenda-get-progress))
  4890. (setq results (append results rtn)))
  4891. ((eq arg :deadline)
  4892. (setq rtn (org-agenda-get-deadlines))
  4893. (setq deadline-results (copy-sequence rtn))
  4894. (setq results (append results rtn)))
  4895. ((eq arg :deadline*)
  4896. (setq rtn (org-agenda-get-deadlines t))
  4897. (setq deadline-results (copy-sequence rtn))
  4898. (setq results (append results rtn))))))))
  4899. results))))
  4900. (defsubst org-em (x y list)
  4901. "Is X or Y a member of LIST?"
  4902. (or (memq x list) (memq y list)))
  4903. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4904. (defvar org-agenda-sorting-strategy-selected nil)
  4905. (defun org-agenda-get-todos ()
  4906. "Return the TODO information for agenda display."
  4907. (let* ((props (list 'face nil
  4908. 'done-face 'org-agenda-done
  4909. 'org-not-done-regexp org-not-done-regexp
  4910. 'org-todo-regexp org-todo-regexp
  4911. 'org-complex-heading-regexp org-complex-heading-regexp
  4912. 'mouse-face 'highlight
  4913. 'help-echo
  4914. (format "mouse-2 or RET jump to org file %s"
  4915. (abbreviate-file-name buffer-file-name))))
  4916. (regexp (format org-heading-keyword-regexp-format
  4917. (cond
  4918. ((and org-select-this-todo-keyword
  4919. (equal org-select-this-todo-keyword "*"))
  4920. org-todo-regexp)
  4921. (org-select-this-todo-keyword
  4922. (concat "\\("
  4923. (mapconcat 'identity
  4924. (org-split-string
  4925. org-select-this-todo-keyword
  4926. "|")
  4927. "\\|") "\\)"))
  4928. (t org-not-done-regexp))))
  4929. marker priority category category-pos level tags todo-state ts-date ts-date-type
  4930. ee txt beg end inherited-tags todo-state-end-pos)
  4931. (goto-char (point-min))
  4932. (while (re-search-forward regexp nil t)
  4933. (catch :skip
  4934. (save-match-data
  4935. (beginning-of-line)
  4936. (org-agenda-skip)
  4937. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4938. (unless (and (setq todo-state (org-get-todo-state))
  4939. (setq todo-state-end-pos (match-end 2)))
  4940. (goto-char end)
  4941. (throw :skip nil))
  4942. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4943. (goto-char (1+ beg))
  4944. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4945. (throw :skip nil)))
  4946. (goto-char (match-beginning 2))
  4947. (setq marker (org-agenda-new-marker (match-beginning 0))
  4948. category (org-get-category)
  4949. ts-date (let (ts)
  4950. (save-match-data
  4951. (cond ((org-em 'scheduled-up 'scheduled-down
  4952. org-agenda-sorting-strategy-selected)
  4953. (setq ts (org-entry-get (point) "SCHEDULED")
  4954. ts-date-type " scheduled"))
  4955. ((org-em 'deadline-up 'deadline-down
  4956. org-agenda-sorting-strategy-selected)
  4957. (setq ts (org-entry-get (point) "DEADLINE")
  4958. ts-date-type " deadline"))
  4959. ((org-em 'ts-up 'ts-down
  4960. org-agenda-sorting-strategy-selected)
  4961. (setq ts (org-entry-get (point) "TIMESTAMP")
  4962. ts-date-type " timestamp"))
  4963. ((org-em 'tsia-up 'tsia-down
  4964. org-agenda-sorting-strategy-selected)
  4965. (setq ts (org-entry-get (point) "TIMESTAMP_IA")
  4966. ts-date-type " timestamp_ia"))
  4967. ((org-em 'timestamp-up 'timestamp-down
  4968. org-agenda-sorting-strategy-selected)
  4969. (setq ts (or (org-entry-get (point) "SCHEDULED")
  4970. (org-entry-get (point) "DEADLINE")
  4971. (org-entry-get (point) "TIMESTAMP")
  4972. (org-entry-get (point) "TIMESTAMP_IA"))
  4973. ts-date-type ""))
  4974. (t (setq ts-date-type "")))
  4975. (when ts (ignore-errors (org-time-string-to-absolute ts)))))
  4976. category-pos (get-text-property (point) 'org-category-position)
  4977. txt (org-trim
  4978. (buffer-substring (match-beginning 2) (match-end 0)))
  4979. inherited-tags
  4980. (or (eq org-agenda-show-inherited-tags 'always)
  4981. (and (listp org-agenda-show-inherited-tags)
  4982. (memq 'todo org-agenda-show-inherited-tags))
  4983. (and (eq org-agenda-show-inherited-tags t)
  4984. (or (eq org-agenda-use-tag-inheritance t)
  4985. (memq 'todo org-agenda-use-tag-inheritance))))
  4986. tags (org-get-tags-at nil (not inherited-tags))
  4987. level (make-string (org-reduced-level (org-outline-level)) ? )
  4988. txt (org-agenda-format-item "" txt level category tags t)
  4989. priority (1+ (org-get-priority txt)))
  4990. (org-add-props txt props
  4991. 'org-marker marker 'org-hd-marker marker
  4992. 'priority priority 'org-category category
  4993. 'level level
  4994. 'ts-date ts-date
  4995. 'org-category-position category-pos
  4996. 'type (concat "todo" ts-date-type) 'todo-state todo-state)
  4997. (push txt ee)
  4998. (if org-agenda-todo-list-sublevels
  4999. (goto-char todo-state-end-pos)
  5000. (org-end-of-subtree 'invisible))))
  5001. (nreverse ee)))
  5002. (defun org-agenda-todo-custom-ignore-p (time n)
  5003. "Check whether timestamp is farther away than n number of days.
  5004. This function is invoked if `org-agenda-todo-ignore-deadlines',
  5005. `org-agenda-todo-ignore-scheduled' or
  5006. `org-agenda-todo-ignore-timestamp' is set to an integer."
  5007. (let ((days (org-time-stamp-to-now
  5008. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  5009. (if (>= n 0)
  5010. (>= days n)
  5011. (<= days n))))
  5012. ;;;###autoload
  5013. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  5014. (&optional end)
  5015. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  5016. (when (or org-agenda-todo-ignore-with-date
  5017. org-agenda-todo-ignore-scheduled
  5018. org-agenda-todo-ignore-deadlines
  5019. org-agenda-todo-ignore-timestamp)
  5020. (setq end (or end (save-excursion (outline-next-heading) (point))))
  5021. (save-excursion
  5022. (or (and org-agenda-todo-ignore-with-date
  5023. (re-search-forward org-ts-regexp end t))
  5024. (and org-agenda-todo-ignore-scheduled
  5025. (re-search-forward org-scheduled-time-regexp end t)
  5026. (cond
  5027. ((eq org-agenda-todo-ignore-scheduled 'future)
  5028. (> (org-time-stamp-to-now
  5029. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5030. ((eq org-agenda-todo-ignore-scheduled 'past)
  5031. (<= (org-time-stamp-to-now
  5032. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5033. ((numberp org-agenda-todo-ignore-scheduled)
  5034. (org-agenda-todo-custom-ignore-p
  5035. (match-string 1) org-agenda-todo-ignore-scheduled))
  5036. (t)))
  5037. (and org-agenda-todo-ignore-deadlines
  5038. (re-search-forward org-deadline-time-regexp end t)
  5039. (cond
  5040. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  5041. ((eq org-agenda-todo-ignore-deadlines 'far)
  5042. (not (org-deadline-close (match-string 1))))
  5043. ((eq org-agenda-todo-ignore-deadlines 'future)
  5044. (> (org-time-stamp-to-now
  5045. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5046. ((eq org-agenda-todo-ignore-deadlines 'past)
  5047. (<= (org-time-stamp-to-now
  5048. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5049. ((numberp org-agenda-todo-ignore-deadlines)
  5050. (org-agenda-todo-custom-ignore-p
  5051. (match-string 1) org-agenda-todo-ignore-deadlines))
  5052. (t (org-deadline-close (match-string 1)))))
  5053. (and org-agenda-todo-ignore-timestamp
  5054. (let ((buffer (current-buffer))
  5055. (regexp
  5056. (concat
  5057. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  5058. (start (point)))
  5059. ;; Copy current buffer into a temporary one
  5060. (with-temp-buffer
  5061. (insert-buffer-substring buffer start end)
  5062. (goto-char (point-min))
  5063. ;; Delete SCHEDULED and DEADLINE items
  5064. (while (re-search-forward regexp end t)
  5065. (delete-region (match-beginning 0) (match-end 0)))
  5066. (goto-char (point-min))
  5067. ;; No search for timestamp left
  5068. (when (re-search-forward org-ts-regexp nil t)
  5069. (cond
  5070. ((eq org-agenda-todo-ignore-timestamp 'future)
  5071. (> (org-time-stamp-to-now
  5072. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5073. ((eq org-agenda-todo-ignore-timestamp 'past)
  5074. (<= (org-time-stamp-to-now
  5075. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  5076. ((numberp org-agenda-todo-ignore-timestamp)
  5077. (org-agenda-todo-custom-ignore-p
  5078. (match-string 1) org-agenda-todo-ignore-timestamp))
  5079. (t))))))))))
  5080. (defun org-agenda-get-timestamps (&optional deadline-results)
  5081. "Return the date stamp information for agenda display."
  5082. (let* ((props (list 'face 'org-agenda-calendar-event
  5083. 'org-not-done-regexp org-not-done-regexp
  5084. 'org-todo-regexp org-todo-regexp
  5085. 'org-complex-heading-regexp org-complex-heading-regexp
  5086. 'mouse-face 'highlight
  5087. 'help-echo
  5088. (format "mouse-2 or RET jump to org file %s"
  5089. (abbreviate-file-name buffer-file-name))))
  5090. (d1 (calendar-absolute-from-gregorian date))
  5091. mm
  5092. (deadline-position-alist
  5093. (mapcar (lambda (a) (and (setq mm (get-text-property
  5094. 0 'org-hd-marker a))
  5095. (cons (marker-position mm) a)))
  5096. deadline-results))
  5097. (remove-re org-ts-regexp)
  5098. (regexp
  5099. (concat
  5100. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  5101. (regexp-quote
  5102. (substring
  5103. (format-time-string
  5104. (car org-time-stamp-formats)
  5105. (apply 'encode-time ; DATE bound by calendar
  5106. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5107. 1 11))
  5108. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  5109. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  5110. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  5111. donep tmp priority category category-pos level ee txt timestr tags
  5112. b0 b3 e3 head todo-state end-of-match show-all warntime habitp
  5113. inherited-tags ts-date)
  5114. (goto-char (point-min))
  5115. (while (setq end-of-match (re-search-forward regexp nil t))
  5116. (setq b0 (match-beginning 0)
  5117. b3 (match-beginning 3) e3 (match-end 3)
  5118. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  5119. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  5120. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5121. (member todo-state
  5122. org-agenda-repeating-timestamp-show-all)))
  5123. (catch :skip
  5124. (and (org-at-date-range-p) (throw :skip nil))
  5125. (org-agenda-skip)
  5126. (if (and (match-end 1)
  5127. (not (= d1 (org-time-string-to-absolute
  5128. (match-string 1) d1 nil show-all
  5129. (current-buffer) b0))))
  5130. (throw :skip nil))
  5131. (if (and e3
  5132. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  5133. (throw :skip nil))
  5134. (setq tmp (buffer-substring (max (point-min)
  5135. (- b0 org-ds-keyword-length))
  5136. b0)
  5137. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  5138. inactivep (= (char-after b0) ?\[)
  5139. deadlinep (string-match org-deadline-regexp tmp)
  5140. scheduledp (string-match org-scheduled-regexp tmp)
  5141. closedp (and org-agenda-include-inactive-timestamps
  5142. (string-match org-closed-string tmp))
  5143. clockp (and org-agenda-include-inactive-timestamps
  5144. (or (string-match org-clock-string tmp)
  5145. (string-match "]-+\\'" tmp)))
  5146. warntime (get-text-property (point) 'org-appt-warntime)
  5147. donep (member todo-state org-done-keywords))
  5148. (if (or scheduledp deadlinep closedp clockp
  5149. (and donep org-agenda-skip-timestamp-if-done))
  5150. (throw :skip t))
  5151. (if (string-match ">" timestr)
  5152. ;; substring should only run to end of time stamp
  5153. (setq timestr (substring timestr 0 (match-end 0))))
  5154. (setq marker (org-agenda-new-marker b0)
  5155. category (org-get-category b0)
  5156. category-pos (get-text-property b0 'org-category-position))
  5157. (save-excursion
  5158. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5159. (throw :skip nil)
  5160. (goto-char (match-beginning 0))
  5161. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  5162. (assoc (point) deadline-position-alist))
  5163. (throw :skip nil))
  5164. (setq hdmarker (org-agenda-new-marker)
  5165. inherited-tags
  5166. (or (eq org-agenda-show-inherited-tags 'always)
  5167. (and (listp org-agenda-show-inherited-tags)
  5168. (memq 'agenda org-agenda-show-inherited-tags))
  5169. (and (eq org-agenda-show-inherited-tags t)
  5170. (or (eq org-agenda-use-tag-inheritance t)
  5171. (memq 'agenda org-agenda-use-tag-inheritance))))
  5172. tags (org-get-tags-at nil (not inherited-tags))
  5173. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5174. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5175. (setq head (or (match-string 1) ""))
  5176. (setq txt (org-agenda-format-item
  5177. (if inactivep org-agenda-inactive-leader nil)
  5178. head level category tags timestr
  5179. remove-re habitp)))
  5180. (setq priority (org-get-priority txt))
  5181. (org-add-props txt props 'priority priority
  5182. 'org-marker marker 'org-hd-marker hdmarker
  5183. 'org-category category 'date date
  5184. 'level level
  5185. 'ts-date
  5186. (ignore-errors (org-time-string-to-absolute timestr))
  5187. 'org-category-position category-pos
  5188. 'todo-state todo-state
  5189. 'warntime warntime
  5190. 'type "timestamp")
  5191. (push txt ee))
  5192. (if org-agenda-skip-additional-timestamps-same-entry
  5193. (outline-next-heading)
  5194. (goto-char end-of-match))))
  5195. (nreverse ee)))
  5196. (defun org-agenda-get-sexps ()
  5197. "Return the sexp information for agenda display."
  5198. (require 'diary-lib)
  5199. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5200. 'mouse-face 'highlight
  5201. 'help-echo
  5202. (format "mouse-2 or RET jump to org file %s"
  5203. (abbreviate-file-name buffer-file-name))))
  5204. (regexp "^&?%%(")
  5205. marker category extra category-pos level ee txt tags entry
  5206. result beg b sexp sexp-entry todo-state warntime inherited-tags)
  5207. (goto-char (point-min))
  5208. (while (re-search-forward regexp nil t)
  5209. (catch :skip
  5210. (org-agenda-skip)
  5211. (setq beg (match-beginning 0))
  5212. (goto-char (1- (match-end 0)))
  5213. (setq b (point))
  5214. (forward-sexp 1)
  5215. (setq sexp (buffer-substring b (point)))
  5216. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5217. (org-trim (match-string 1))
  5218. ""))
  5219. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5220. (when result
  5221. (setq marker (org-agenda-new-marker beg)
  5222. level (make-string (org-reduced-level (org-outline-level)) ? )
  5223. category (org-get-category beg)
  5224. category-pos (get-text-property beg 'org-category-position)
  5225. inherited-tags
  5226. (or (eq org-agenda-show-inherited-tags 'always)
  5227. (and (listp org-agenda-show-inherited-tags)
  5228. (memq 'agenda org-agenda-show-inherited-tags))
  5229. (and (eq org-agenda-show-inherited-tags t)
  5230. (or (eq org-agenda-use-tag-inheritance t)
  5231. (memq 'agenda org-agenda-use-tag-inheritance))))
  5232. tags (org-get-tags-at nil (not inherited-tags))
  5233. todo-state (org-get-todo-state)
  5234. warntime (get-text-property (point) 'org-appt-warntime)
  5235. extra nil)
  5236. (dolist (r (if (stringp result)
  5237. (list result)
  5238. result)) ;; we expect a list here
  5239. (when (and org-agenda-diary-sexp-prefix
  5240. (string-match org-agenda-diary-sexp-prefix r))
  5241. (setq extra (match-string 0 r)
  5242. r (replace-match "" nil nil r)))
  5243. (if (string-match "\\S-" r)
  5244. (setq txt r)
  5245. (setq txt "SEXP entry returned empty string"))
  5246. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5247. (org-add-props txt props 'org-marker marker
  5248. 'org-category category 'date date 'todo-state todo-state
  5249. 'org-category-position category-pos 'tags tags
  5250. 'level level
  5251. 'type "sexp" 'warntime warntime)
  5252. (push txt ee)))))
  5253. (nreverse ee)))
  5254. ;; Calendar sanity: define some functions that are independent of
  5255. ;; `calendar-date-style'.
  5256. ;; Normally I would like to use ISO format when calling the diary functions,
  5257. ;; but to make sure we still have Emacs 22 compatibility we bind
  5258. ;; also `european-calendar-style' and use european format
  5259. (defun org-anniversary (year month day &optional mark)
  5260. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5261. (org-no-warnings
  5262. (let ((calendar-date-style 'european) (european-calendar-style t))
  5263. (diary-anniversary day month year mark))))
  5264. (defun org-cyclic (N year month day &optional mark)
  5265. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5266. (org-no-warnings
  5267. (let ((calendar-date-style 'european) (european-calendar-style t))
  5268. (diary-cyclic N day month year mark))))
  5269. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5270. "Like `diary-block', but with fixed (ISO) order of arguments."
  5271. (org-no-warnings
  5272. (let ((calendar-date-style 'european) (european-calendar-style t))
  5273. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5274. (defun org-date (year month day &optional mark)
  5275. "Like `diary-date', but with fixed (ISO) order of arguments."
  5276. (org-no-warnings
  5277. (let ((calendar-date-style 'european) (european-calendar-style t))
  5278. (diary-date day month year mark))))
  5279. ;; Define the` org-class' function
  5280. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5281. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5282. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5283. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5284. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5285. `holidays', then any date that is known by the Emacs calendar to be a
  5286. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5287. then those holidays will be skipped."
  5288. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5289. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5290. (d (calendar-absolute-from-gregorian date))
  5291. (h (when skip-weeks (calendar-check-holidays date))))
  5292. (and
  5293. (<= date1 d)
  5294. (<= d date2)
  5295. (= (calendar-day-of-week date) dayname)
  5296. (or (not skip-weeks)
  5297. (progn
  5298. (require 'cal-iso)
  5299. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5300. (not (or (and h (memq 'holidays skip-weeks))
  5301. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5302. entry)))
  5303. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5304. "Like `org-class', but honor `calendar-date-style'.
  5305. The order of the first 2 times 3 arguments depends on the variable
  5306. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5307. So for American calendars, give this as MONTH DAY YEAR, for European as
  5308. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5309. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5310. is any number of ISO weeks in the block period for which the item should
  5311. be skipped.
  5312. This function is here only for backward compatibility and it is deprecated,
  5313. please use `org-class' instead."
  5314. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5315. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5316. (org-class
  5317. (nth 2 date1) (car date1) (nth 1 date1)
  5318. (nth 2 date2) (car date2) (nth 1 date2)
  5319. dayname skip-weeks)))
  5320. (make-obsolete 'org-diary-class 'org-class "")
  5321. (defalias 'org-get-closed 'org-agenda-get-progress)
  5322. (defun org-agenda-get-progress ()
  5323. "Return the logged TODO entries for agenda display."
  5324. (let* ((props (list 'mouse-face 'highlight
  5325. 'org-not-done-regexp org-not-done-regexp
  5326. 'org-todo-regexp org-todo-regexp
  5327. 'org-complex-heading-regexp org-complex-heading-regexp
  5328. 'help-echo
  5329. (format "mouse-2 or RET jump to org file %s"
  5330. (abbreviate-file-name buffer-file-name))))
  5331. (items (if (consp org-agenda-show-log-scoped)
  5332. org-agenda-show-log-scoped
  5333. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5334. '(clock)
  5335. org-agenda-log-mode-items)))
  5336. (parts
  5337. (delq nil
  5338. (list
  5339. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5340. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5341. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5342. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5343. (error "`org-agenda-log-mode-items' is empty")))
  5344. (regexp (concat
  5345. "\\(" parts-re "\\)"
  5346. " *\\["
  5347. (regexp-quote
  5348. (substring
  5349. (format-time-string
  5350. (car org-time-stamp-formats)
  5351. (apply 'encode-time ; DATE bound by calendar
  5352. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5353. 1 11))))
  5354. (org-agenda-search-headline-for-time nil)
  5355. marker hdmarker priority category category-pos level tags closedp
  5356. statep clockp state ee txt extra timestr rest clocked inherited-tags)
  5357. (goto-char (point-min))
  5358. (while (re-search-forward regexp nil t)
  5359. (catch :skip
  5360. (org-agenda-skip)
  5361. (setq marker (org-agenda-new-marker (match-beginning 0))
  5362. closedp (equal (match-string 1) org-closed-string)
  5363. statep (equal (string-to-char (match-string 1)) ?-)
  5364. clockp (not (or closedp statep))
  5365. state (and statep (match-string 2))
  5366. category (org-get-category (match-beginning 0))
  5367. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5368. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5369. (when (string-match "\\]" timestr)
  5370. ;; substring should only run to end of time stamp
  5371. (setq rest (substring timestr (match-end 0))
  5372. timestr (substring timestr 0 (match-end 0)))
  5373. (if (and (not closedp) (not statep)
  5374. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5375. rest))
  5376. (progn (setq timestr (concat (substring timestr 0 -1)
  5377. "-" (match-string 1 rest) "]"))
  5378. (setq clocked (match-string 2 rest)))
  5379. (setq clocked "-")))
  5380. (save-excursion
  5381. (setq extra
  5382. (cond
  5383. ((not org-agenda-log-mode-add-notes) nil)
  5384. (statep
  5385. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5386. (match-string 1)))
  5387. (clockp
  5388. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5389. (match-string 1)))))
  5390. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5391. (throw :skip nil)
  5392. (goto-char (match-beginning 0))
  5393. (setq hdmarker (org-agenda-new-marker)
  5394. inherited-tags
  5395. (or (eq org-agenda-show-inherited-tags 'always)
  5396. (and (listp org-agenda-show-inherited-tags)
  5397. (memq 'todo org-agenda-show-inherited-tags))
  5398. (and (eq org-agenda-show-inherited-tags t)
  5399. (or (eq org-agenda-use-tag-inheritance t)
  5400. (memq 'todo org-agenda-use-tag-inheritance))))
  5401. tags (org-get-tags-at nil (not inherited-tags))
  5402. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5403. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5404. (setq txt (match-string 1))
  5405. (when extra
  5406. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5407. (setq txt (concat (substring txt 0 (match-beginning 1))
  5408. " - " extra " " (match-string 2 txt)))
  5409. (setq txt (concat txt " - " extra))))
  5410. (setq txt (org-agenda-format-item
  5411. (cond
  5412. (closedp "Closed: ")
  5413. (statep (concat "State: (" state ")"))
  5414. (t (concat "Clocked: (" clocked ")")))
  5415. txt level category tags timestr)))
  5416. (setq priority 100000)
  5417. (org-add-props txt props
  5418. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5419. 'priority priority 'org-category category
  5420. 'org-category-position category-pos
  5421. 'level level
  5422. 'type "closed" 'date date
  5423. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5424. (push txt ee))
  5425. (goto-char (point-at-eol))))
  5426. (nreverse ee)))
  5427. (defun org-agenda-show-clocking-issues ()
  5428. "Add overlays, showing issues with clocking.
  5429. See also the user option `org-agenda-clock-consistency-checks'."
  5430. (interactive)
  5431. (let* ((org-time-clocksum-use-effort-durations nil)
  5432. (pl org-agenda-clock-consistency-checks)
  5433. (re (concat "^[ \t]*"
  5434. org-clock-string
  5435. "[ \t]+"
  5436. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5437. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5438. (tlstart 0.)
  5439. (tlend 0.)
  5440. (maxtime (org-hh:mm-string-to-minutes
  5441. (or (plist-get pl :max-duration) "24:00")))
  5442. (mintime (org-hh:mm-string-to-minutes
  5443. (or (plist-get pl :min-duration) 0)))
  5444. (maxgap (org-hh:mm-string-to-minutes
  5445. ;; default 30:00 means never complain
  5446. (or (plist-get pl :max-gap) "30:00")))
  5447. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5448. (plist-get pl :gap-ok-around)))
  5449. (def-face (or (plist-get pl :default-face)
  5450. '((:background "DarkRed") (:foreground "white"))))
  5451. issue face m te ts dt ov)
  5452. (goto-char (point-min))
  5453. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5454. (setq issue nil face def-face)
  5455. (catch 'next
  5456. (setq m (org-get-at-bol 'org-marker)
  5457. te nil ts nil)
  5458. (unless (and m (markerp m))
  5459. (setq issue "No valid clock line") (throw 'next t))
  5460. (org-with-point-at m
  5461. (save-excursion
  5462. (goto-char (point-at-bol))
  5463. (unless (looking-at re)
  5464. (error "No valid Clock line")
  5465. (throw 'next t))
  5466. (unless (match-end 3)
  5467. (setq issue "No end time"
  5468. face (or (plist-get pl :no-end-time-face) face))
  5469. (throw 'next t))
  5470. (setq ts (match-string 1)
  5471. te (match-string 3)
  5472. ts (org-float-time
  5473. (apply 'encode-time (org-parse-time-string ts)))
  5474. te (org-float-time
  5475. (apply 'encode-time (org-parse-time-string te)))
  5476. dt (- te ts))))
  5477. (cond
  5478. ((> dt (* 60 maxtime))
  5479. ;; a very long clocking chunk
  5480. (setq issue (format "Clocking interval is very long: %s"
  5481. (org-minutes-to-clocksum-string
  5482. (floor (/ (float dt) 60.))))
  5483. face (or (plist-get pl :long-face) face)))
  5484. ((< dt (* 60 mintime))
  5485. ;; a very short clocking chunk
  5486. (setq issue (format "Clocking interval is very short: %s"
  5487. (org-minutes-to-clocksum-string
  5488. (floor (/ (float dt) 60.))))
  5489. face (or (plist-get pl :short-face) face)))
  5490. ((and (> tlend 0) (< ts tlend))
  5491. ;; Two clock entries are overlapping
  5492. (setq issue (format "Clocking overlap: %d minutes"
  5493. (/ (- tlend ts) 60))
  5494. face (or (plist-get pl :overlap-face) face)))
  5495. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5496. ;; There is a gap, lets see if we need to report it
  5497. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5498. (setq issue (format "Clocking gap: %d minutes"
  5499. (/ (- ts tlend) 60))
  5500. face (or (plist-get pl :gap-face) face))))
  5501. (t nil)))
  5502. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5503. (when issue
  5504. ;; OK, there was some issue, add an overlay to show the issue
  5505. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5506. (overlay-put ov 'before-string
  5507. (concat
  5508. (org-add-props
  5509. (format "%-43s" (concat " " issue))
  5510. nil
  5511. 'face face)
  5512. "\n"))
  5513. (overlay-put ov 'evaporate t)))))
  5514. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5515. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5516. (catch 'exit
  5517. (unless ok-list
  5518. ;; there are no OK times for gaps...
  5519. (throw 'exit nil))
  5520. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5521. ;; This is more than 24 hours, so it is OK.
  5522. ;; because we have at least one OK time, that must be in the
  5523. ;; 24 hour interval.
  5524. (throw 'exit t))
  5525. ;; We have a shorter gap.
  5526. ;; Now we have to get the minute of the day when these times are
  5527. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5528. (t2dec (decode-time (seconds-to-time t2)))
  5529. ;; compute the minute on the day
  5530. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5531. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5532. (when (< min2 min1)
  5533. ;; if min2 is smaller than min1, this means it is on the next day.
  5534. ;; Wrap it to after midnight.
  5535. (setq min2 (+ min2 1440)))
  5536. ;; Now check if any of the OK times is in the gap
  5537. (mapc (lambda (x)
  5538. ;; Wrap the time to after midnight if necessary
  5539. (if (< x min1) (setq x (+ x 1440)))
  5540. ;; Check if in interval
  5541. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5542. ok-list)
  5543. ;; Nope, this gap is not OK
  5544. nil)))
  5545. (defun org-agenda-get-deadlines (&optional with-hour)
  5546. "Return the deadline information for agenda display.
  5547. When WITH-HOUR is non-nil, only return deadlines with an hour
  5548. specification like [h]h:mm."
  5549. (let* ((props (list 'mouse-face 'highlight
  5550. 'org-not-done-regexp org-not-done-regexp
  5551. 'org-todo-regexp org-todo-regexp
  5552. 'org-complex-heading-regexp org-complex-heading-regexp
  5553. 'help-echo
  5554. (format "mouse-2 or RET jump to org file %s"
  5555. (abbreviate-file-name buffer-file-name))))
  5556. (regexp (if with-hour
  5557. org-deadline-time-hour-regexp
  5558. org-deadline-time-regexp))
  5559. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5560. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5561. (dl0 (car org-agenda-deadline-leaders))
  5562. (dl1 (nth 1 org-agenda-deadline-leaders))
  5563. (dl2 (or (nth 2 org-agenda-deadline-leaders) dl1))
  5564. d2 diff dfrac wdays pos pos1 category category-pos level
  5565. tags suppress-prewarning ee txt head face s todo-state
  5566. show-all upcomingp donep timestr warntime inherited-tags ts-date)
  5567. (goto-char (point-min))
  5568. (while (re-search-forward regexp nil t)
  5569. (catch :skip
  5570. (org-agenda-skip)
  5571. (setq s (match-string 1)
  5572. txt nil
  5573. pos (1- (match-beginning 1))
  5574. todo-state (save-match-data (org-get-todo-state))
  5575. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5576. (member todo-state
  5577. org-agenda-repeating-timestamp-show-all))
  5578. d2 (org-time-string-to-absolute
  5579. s d1 'past show-all (current-buffer) pos)
  5580. diff (- d2 d1))
  5581. (setq suppress-prewarning
  5582. (let ((ds (and org-agenda-skip-deadline-prewarning-if-scheduled
  5583. (let ((item (buffer-substring (point-at-bol)
  5584. (point-at-eol))))
  5585. (save-match-data
  5586. (and (string-match
  5587. org-scheduled-time-regexp item)
  5588. (match-string 1 item)))))))
  5589. (cond
  5590. ((not ds) nil)
  5591. ;; The current item has a scheduled date (in ds), so
  5592. ;; evaluate its prewarning lead time.
  5593. ((integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5594. ;; Use global prewarning-restart lead time.
  5595. org-agenda-skip-deadline-prewarning-if-scheduled)
  5596. ((eq org-agenda-skip-deadline-prewarning-if-scheduled
  5597. 'pre-scheduled)
  5598. ;; Set prewarning to no earlier than scheduled.
  5599. (min (- d2 (org-time-string-to-absolute
  5600. ds d1 'past show-all (current-buffer) pos))
  5601. org-deadline-warning-days))
  5602. ;; Set prewarning to deadline.
  5603. (t 0))))
  5604. (setq wdays (if suppress-prewarning
  5605. (let ((org-deadline-warning-days suppress-prewarning))
  5606. (org-get-wdays s))
  5607. (org-get-wdays s))
  5608. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5609. upcomingp (and todayp (> diff 0)))
  5610. ;; When to show a deadline in the calendar:
  5611. ;; If the expiration is within wdays warning time.
  5612. ;; Past-due deadlines are only shown on the current date
  5613. (if (and (or (and (<= diff wdays)
  5614. (and todayp (not org-agenda-only-exact-dates)))
  5615. (= diff 0)))
  5616. (save-excursion
  5617. ;; (setq todo-state (org-get-todo-state))
  5618. (setq donep (member todo-state org-done-keywords))
  5619. (if (and donep
  5620. (or org-agenda-skip-deadline-if-done
  5621. (not (= diff 0))))
  5622. (setq txt nil)
  5623. (setq category (org-get-category)
  5624. warntime (get-text-property (point) 'org-appt-warntime)
  5625. category-pos (get-text-property (point) 'org-category-position))
  5626. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5627. (throw :skip nil)
  5628. (goto-char (match-end 0))
  5629. (setq pos1 (match-beginning 0))
  5630. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5631. (setq inherited-tags
  5632. (or (eq org-agenda-show-inherited-tags 'always)
  5633. (and (listp org-agenda-show-inherited-tags)
  5634. (memq 'agenda org-agenda-show-inherited-tags))
  5635. (and (eq org-agenda-show-inherited-tags t)
  5636. (or (eq org-agenda-use-tag-inheritance t)
  5637. (memq 'agenda org-agenda-use-tag-inheritance))))
  5638. tags (org-get-tags-at pos1 (not inherited-tags)))
  5639. (setq head (buffer-substring
  5640. (point)
  5641. (progn (skip-chars-forward "^\r\n")
  5642. (point))))
  5643. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5644. (setq timestr
  5645. (concat (substring s (match-beginning 1)) " "))
  5646. (setq timestr 'time))
  5647. (setq txt (org-agenda-format-item
  5648. (cond ((= diff 0) dl0)
  5649. ((> diff 0)
  5650. (if (functionp dl1)
  5651. (funcall dl1 diff date)
  5652. (format dl1 diff)))
  5653. (t
  5654. (if (functionp dl2)
  5655. (funcall dl2 diff date)
  5656. (format dl2 (if (string= dl2 dl1)
  5657. diff (abs diff))))))
  5658. head level category tags
  5659. (if (not (= diff 0)) nil timestr)))))
  5660. (when txt
  5661. (setq face (org-agenda-deadline-face dfrac))
  5662. (org-add-props txt props
  5663. 'org-marker (org-agenda-new-marker pos)
  5664. 'warntime warntime
  5665. 'level level
  5666. 'ts-date d2
  5667. 'org-hd-marker (org-agenda-new-marker pos1)
  5668. 'priority (+ (- diff)
  5669. (org-get-priority txt))
  5670. 'org-category category
  5671. 'org-category-position category-pos
  5672. 'todo-state todo-state
  5673. 'type (if upcomingp "upcoming-deadline" "deadline")
  5674. 'date (if upcomingp date d2)
  5675. 'face (if donep 'org-agenda-done face)
  5676. 'undone-face face 'done-face 'org-agenda-done)
  5677. (push txt ee))))))
  5678. (nreverse ee)))
  5679. (defun org-agenda-deadline-face (fraction)
  5680. "Return the face to displaying a deadline item.
  5681. FRACTION is what fraction of the head-warning time has passed."
  5682. (let ((faces org-agenda-deadline-faces) f)
  5683. (catch 'exit
  5684. (while (setq f (pop faces))
  5685. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5686. (defun org-agenda-get-scheduled (&optional deadline-results with-hour)
  5687. "Return the scheduled information for agenda display.
  5688. When WITH-HOUR is non-nil, only return scheduled items with
  5689. an hour specification like [h]h:mm."
  5690. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5691. 'org-todo-regexp org-todo-regexp
  5692. 'org-complex-heading-regexp org-complex-heading-regexp
  5693. 'done-face 'org-agenda-done
  5694. 'mouse-face 'highlight
  5695. 'help-echo
  5696. (format "mouse-2 or RET jump to org file %s"
  5697. (abbreviate-file-name buffer-file-name))))
  5698. (regexp (if with-hour
  5699. org-scheduled-time-hour-regexp
  5700. org-scheduled-time-regexp))
  5701. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5702. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5703. mm
  5704. (deadline-position-alist
  5705. (mapcar (lambda (a) (and (setq mm (get-text-property
  5706. 0 'org-hd-marker a))
  5707. (cons (marker-position mm) a)))
  5708. deadline-results))
  5709. d2 diff pos pos1 category category-pos level tags donep
  5710. ee txt head pastschedp todo-state face timestr s habitp show-all
  5711. did-habit-check-p warntime inherited-tags ts-date suppress-delay
  5712. ddays)
  5713. (goto-char (point-min))
  5714. (while (re-search-forward regexp nil t)
  5715. (catch :skip
  5716. (org-agenda-skip)
  5717. (setq s (match-string 1)
  5718. txt nil
  5719. pos (1- (match-beginning 1))
  5720. todo-state (save-match-data (org-get-todo-state))
  5721. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5722. (member todo-state
  5723. org-agenda-repeating-timestamp-show-all))
  5724. d2 (org-time-string-to-absolute
  5725. s d1 'past show-all (current-buffer) pos)
  5726. diff (- d2 d1)
  5727. warntime (get-text-property (point) 'org-appt-warntime))
  5728. (setq pastschedp (and todayp (< diff 0)))
  5729. (setq did-habit-check-p nil)
  5730. (setq suppress-delay
  5731. (let ((ds (and org-agenda-skip-scheduled-delay-if-deadline
  5732. (let ((item (buffer-substring (point-at-bol) (point-at-eol))))
  5733. (save-match-data
  5734. (and (string-match
  5735. org-deadline-time-regexp item)
  5736. (match-string 1 item)))))))
  5737. (cond
  5738. ((not ds) nil)
  5739. ;; The current item has a deadline date (in ds), so
  5740. ;; evaluate its delay time.
  5741. ((integerp org-agenda-skip-scheduled-delay-if-deadline)
  5742. ;; Use global delay time.
  5743. (- org-agenda-skip-scheduled-delay-if-deadline))
  5744. ((eq org-agenda-skip-scheduled-delay-if-deadline
  5745. 'post-deadline)
  5746. ;; Set delay to no later than deadline.
  5747. (min (- d2 (org-time-string-to-absolute
  5748. ds d1 'past show-all (current-buffer) pos))
  5749. org-scheduled-delay-days))
  5750. (t 0))))
  5751. (setq ddays (if suppress-delay
  5752. (let ((org-scheduled-delay-days suppress-delay))
  5753. (org-get-wdays s t t))
  5754. (org-get-wdays s t)))
  5755. ;; Use a delay of 0 when there is a repeater and the delay is
  5756. ;; of the form --3d
  5757. (when (and (save-match-data (string-match "--[0-9]+[hdwmy]" s))
  5758. (< (org-time-string-to-absolute s)
  5759. (org-time-string-to-absolute
  5760. s d2 'past nil (current-buffer) pos)))
  5761. (setq ddays 0))
  5762. ;; When to show a scheduled item in the calendar:
  5763. ;; If it is on or past the date.
  5764. (when (or (and (> ddays 0) (= diff (- ddays)))
  5765. (and (zerop ddays) (= diff 0))
  5766. (and (< (+ diff ddays) 0)
  5767. (< (abs diff) org-scheduled-past-days)
  5768. (and todayp (not org-agenda-only-exact-dates)))
  5769. ;; org-is-habit-p uses org-entry-get, which is expansive
  5770. ;; so we go extra mile to only call it once
  5771. (and todayp
  5772. (boundp 'org-habit-show-all-today)
  5773. org-habit-show-all-today
  5774. (setq did-habit-check-p t)
  5775. (setq habitp (and (functionp 'org-is-habit-p)
  5776. (org-is-habit-p)))))
  5777. (save-excursion
  5778. (setq donep (member todo-state org-done-keywords))
  5779. (if (and donep
  5780. (or org-agenda-skip-scheduled-if-done
  5781. (not (= diff 0))
  5782. (and (functionp 'org-is-habit-p)
  5783. (org-is-habit-p))))
  5784. (setq txt nil)
  5785. (setq habitp (if did-habit-check-p habitp
  5786. (and (functionp 'org-is-habit-p)
  5787. (org-is-habit-p))))
  5788. (setq category (org-get-category)
  5789. category-pos (get-text-property (point) 'org-category-position))
  5790. (if (and (eq org-agenda-skip-scheduled-if-deadline-is-shown
  5791. 'repeated-after-deadline)
  5792. (org-get-deadline-time (point))
  5793. (<= 0 (- d2 (time-to-days (org-get-deadline-time (point))))))
  5794. (throw :skip nil))
  5795. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5796. (throw :skip nil)
  5797. (goto-char (match-end 0))
  5798. (setq pos1 (match-beginning 0))
  5799. (if habitp
  5800. (if (or (not org-habit-show-habits)
  5801. (and (not todayp)
  5802. (boundp 'org-habit-show-habits-only-for-today)
  5803. org-habit-show-habits-only-for-today))
  5804. (throw :skip nil))
  5805. (if (and
  5806. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5807. (and (eq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
  5808. pastschedp))
  5809. (setq mm (assoc pos1 deadline-position-alist)))
  5810. (throw :skip nil)))
  5811. (setq inherited-tags
  5812. (or (eq org-agenda-show-inherited-tags 'always)
  5813. (and (listp org-agenda-show-inherited-tags)
  5814. (memq 'agenda org-agenda-show-inherited-tags))
  5815. (and (eq org-agenda-show-inherited-tags t)
  5816. (or (eq org-agenda-use-tag-inheritance t)
  5817. (memq 'agenda org-agenda-use-tag-inheritance))))
  5818. tags (org-get-tags-at nil (not inherited-tags)))
  5819. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5820. (setq head (buffer-substring
  5821. (point)
  5822. (progn (skip-chars-forward "^\r\n") (point))))
  5823. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5824. (setq timestr
  5825. (concat (substring s (match-beginning 1)) " "))
  5826. (setq timestr 'time))
  5827. (setq txt (org-agenda-format-item
  5828. (if (= diff 0)
  5829. (car org-agenda-scheduled-leaders)
  5830. (format (nth 1 org-agenda-scheduled-leaders)
  5831. (- 1 diff)))
  5832. head level category tags
  5833. (if (not (= diff 0)) nil timestr)
  5834. nil habitp))))
  5835. (when txt
  5836. (setq face
  5837. (cond
  5838. ((and (not habitp) pastschedp)
  5839. 'org-scheduled-previously)
  5840. (todayp 'org-scheduled-today)
  5841. (t 'org-scheduled))
  5842. habitp (and habitp (org-habit-parse-todo)))
  5843. (org-add-props txt props
  5844. 'undone-face face
  5845. 'face (if donep 'org-agenda-done face)
  5846. 'org-marker (org-agenda-new-marker pos)
  5847. 'org-hd-marker (org-agenda-new-marker pos1)
  5848. 'type (if pastschedp "past-scheduled" "scheduled")
  5849. 'date (if pastschedp d2 date)
  5850. 'ts-date d2
  5851. 'warntime warntime
  5852. 'level level
  5853. 'priority (if habitp
  5854. (org-habit-get-priority habitp)
  5855. (+ 94 (- 5 diff) (org-get-priority txt)))
  5856. 'org-category category
  5857. 'category-position category-pos
  5858. 'org-habit-p habitp
  5859. 'todo-state todo-state)
  5860. (push txt ee))))))
  5861. (nreverse ee)))
  5862. (defun org-agenda-get-blocks ()
  5863. "Return the date-range information for agenda display."
  5864. (let* ((props (list 'face nil
  5865. 'org-not-done-regexp org-not-done-regexp
  5866. 'org-todo-regexp org-todo-regexp
  5867. 'org-complex-heading-regexp org-complex-heading-regexp
  5868. 'mouse-face 'highlight
  5869. 'help-echo
  5870. (format "mouse-2 or RET jump to org file %s"
  5871. (abbreviate-file-name buffer-file-name))))
  5872. (regexp org-tr-regexp)
  5873. (d0 (calendar-absolute-from-gregorian date))
  5874. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5875. level todo-state tags pos head donep inherited-tags)
  5876. (goto-char (point-min))
  5877. (while (re-search-forward regexp nil t)
  5878. (catch :skip
  5879. (org-agenda-skip)
  5880. (setq pos (point))
  5881. (let ((start-time (match-string 1))
  5882. (end-time (match-string 2)))
  5883. (setq s1 (match-string 1)
  5884. s2 (match-string 2)
  5885. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5886. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5887. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5888. ;; Only allow days between the limits, because the normal
  5889. ;; date stamps will catch the limits.
  5890. (save-excursion
  5891. (setq todo-state (org-get-todo-state))
  5892. (setq donep (member todo-state org-done-keywords))
  5893. (if (and donep org-agenda-skip-timestamp-if-done)
  5894. (throw :skip t))
  5895. (setq marker (org-agenda-new-marker (point)))
  5896. (setq category (org-get-category)
  5897. category-pos (get-text-property (point) 'org-category-position))
  5898. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5899. (throw :skip nil)
  5900. (goto-char (match-beginning 0))
  5901. (setq hdmarker (org-agenda-new-marker (point))
  5902. inherited-tags
  5903. (or (eq org-agenda-show-inherited-tags 'always)
  5904. (and (listp org-agenda-show-inherited-tags)
  5905. (memq 'agenda org-agenda-show-inherited-tags))
  5906. (and (eq org-agenda-show-inherited-tags t)
  5907. (or (eq org-agenda-use-tag-inheritance t)
  5908. (memq 'agenda org-agenda-use-tag-inheritance))))
  5909. tags (org-get-tags-at nil (not inherited-tags)))
  5910. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5911. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5912. (setq head (match-string 1))
  5913. (let ((remove-re
  5914. (if org-agenda-remove-timeranges-from-blocks
  5915. (concat
  5916. "<" (regexp-quote s1) ".*?>"
  5917. "--"
  5918. "<" (regexp-quote s2) ".*?>")
  5919. nil)))
  5920. (setq txt (org-agenda-format-item
  5921. (format
  5922. (nth (if (= d1 d2) 0 1)
  5923. org-agenda-timerange-leaders)
  5924. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5925. head level category tags
  5926. (cond ((and (= d1 d0) (= d2 d0))
  5927. (concat "<" start-time ">--<" end-time ">"))
  5928. ((= d1 d0)
  5929. (concat "<" start-time ">"))
  5930. ((= d2 d0)
  5931. (concat "<" end-time ">")))
  5932. remove-re))))
  5933. (org-add-props txt props
  5934. 'org-marker marker 'org-hd-marker hdmarker
  5935. 'type "block" 'date date
  5936. 'level level
  5937. 'todo-state todo-state
  5938. 'priority (org-get-priority txt) 'org-category category
  5939. 'org-category-position category-pos)
  5940. (push txt ee))))
  5941. (goto-char pos)))
  5942. ;; Sort the entries by expiration date.
  5943. (nreverse ee)))
  5944. ;;; Agenda presentation and sorting
  5945. (defvar org-prefix-has-time nil
  5946. "A flag, set by `org-compile-prefix-format'.
  5947. The flag is set if the currently compiled format contains a `%t'.")
  5948. (defvar org-prefix-has-tag nil
  5949. "A flag, set by `org-compile-prefix-format'.
  5950. The flag is set if the currently compiled format contains a `%T'.")
  5951. (defvar org-prefix-has-effort nil
  5952. "A flag, set by `org-compile-prefix-format'.
  5953. The flag is set if the currently compiled format contains a `%e'.")
  5954. (defvar org-prefix-has-breadcrumbs nil
  5955. "A flag, set by `org-compile-prefix-format'.
  5956. The flag is set if the currently compiled format contains a `%b'.")
  5957. (defvar org-prefix-category-length nil
  5958. "Used by `org-compile-prefix-format' to remember the category field width.")
  5959. (defvar org-prefix-category-max-length nil
  5960. "Used by `org-compile-prefix-format' to remember the category field width.")
  5961. (defun org-agenda-get-category-icon (category)
  5962. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5963. (dolist (entry org-agenda-category-icon-alist)
  5964. (when (org-string-match-p (car entry) category)
  5965. (if (listp (cadr entry))
  5966. (return (cadr entry))
  5967. (return (apply 'create-image (cdr entry)))))))
  5968. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5969. remove-re habitp)
  5970. "Format TXT to be inserted into the agenda buffer.
  5971. In particular, add the prefix and corresponding text properties.
  5972. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5973. LEVEL may be a string to replace the `%l' specifier.
  5974. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5975. category taken from local variable or file name. It will replace the `%c'
  5976. specifier in the format.
  5977. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5978. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5979. When DOTIME is a string, this string is searched for a time before TXT is.
  5980. TAGS can be the tags of the headline.
  5981. Any match of REMOVE-RE will be removed from TXT."
  5982. ;; We keep the org-prefix-* variable values along with a compiled
  5983. ;; formatter, so that multiple agendas existing at the same time do
  5984. ;; not step on each other toes.
  5985. ;;
  5986. ;; It was inconvenient to make these variables buffer local in
  5987. ;; Agenda buffers, because this function expects to be called with
  5988. ;; the buffer where item comes from being current, and not agenda
  5989. ;; buffer
  5990. (let* ((bindings (car org-prefix-format-compiled))
  5991. (formatter (cadr org-prefix-format-compiled)))
  5992. (loop for (var value) in bindings
  5993. do (set var value))
  5994. (save-match-data
  5995. ;; Diary entries sometimes have extra whitespace at the beginning
  5996. (setq txt (org-trim txt))
  5997. ;; Fix the tags part in txt
  5998. (setq txt (org-agenda-fix-displayed-tags
  5999. txt tags
  6000. org-agenda-show-inherited-tags
  6001. org-agenda-hide-tags-regexp))
  6002. (let* ((category (or category
  6003. (if (stringp org-category)
  6004. org-category
  6005. (and org-category (symbol-name org-category)))
  6006. (if buffer-file-name
  6007. (file-name-sans-extension
  6008. (file-name-nondirectory buffer-file-name))
  6009. "")))
  6010. (category-icon (org-agenda-get-category-icon category))
  6011. (category-icon (if category-icon
  6012. (propertize " " 'display category-icon)
  6013. ""))
  6014. ;; time, tag, effort are needed for the eval of the prefix format
  6015. (tag (if tags (nth (1- (length tags)) tags) ""))
  6016. time effort neffort
  6017. (ts (if dotime (concat
  6018. (if (stringp dotime) dotime "")
  6019. (and org-agenda-search-headline-for-time txt))))
  6020. (time-of-day (and dotime (org-get-time-of-day ts)))
  6021. stamp plain s0 s1 s2 rtn srp l
  6022. duration thecategory breadcrumbs)
  6023. (and (derived-mode-p 'org-mode) buffer-file-name
  6024. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  6025. (when (and dotime time-of-day)
  6026. ;; Extract starting and ending time and move them to prefix
  6027. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  6028. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  6029. (setq s0 (match-string 0 ts)
  6030. srp (and stamp (match-end 3))
  6031. s1 (match-string (if plain 1 2) ts)
  6032. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  6033. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  6034. ;; them, we might want to remove them there to avoid duplication.
  6035. ;; The user can turn this off with a variable.
  6036. (if (and org-prefix-has-time
  6037. org-agenda-remove-times-when-in-prefix (or stamp plain)
  6038. (string-match (concat (regexp-quote s0) " *") txt)
  6039. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  6040. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  6041. (= (match-beginning 0) 0)
  6042. t))
  6043. (setq txt (replace-match "" nil nil txt))))
  6044. ;; Normalize the time(s) to 24 hour
  6045. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  6046. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  6047. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  6048. (let (org-time-clocksum-use-effort-durations)
  6049. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  6050. (setq s2
  6051. (org-minutes-to-clocksum-string
  6052. (+ (org-hh:mm-string-to-minutes s1)
  6053. org-agenda-default-appointment-duration)))))
  6054. ;; Compute the duration
  6055. (when s2
  6056. (setq duration (- (org-hh:mm-string-to-minutes s2)
  6057. (org-hh:mm-string-to-minutes s1)))))
  6058. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6059. txt)
  6060. ;; Tags are in the string
  6061. (if (or (eq org-agenda-remove-tags t)
  6062. (and org-agenda-remove-tags
  6063. org-prefix-has-tag))
  6064. (setq txt (replace-match "" t t txt))
  6065. (setq txt (replace-match
  6066. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  6067. (match-string 2 txt))
  6068. t t txt))))
  6069. (when (derived-mode-p 'org-mode)
  6070. (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
  6071. ;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
  6072. ;; current buffer, so move this check outside of above
  6073. (if effort
  6074. (setq neffort (org-duration-string-to-minutes effort)
  6075. effort (setq effort (concat "[" effort "]")))
  6076. ;; prevent erroring out with %e format when there is no effort
  6077. (setq effort ""))
  6078. (when remove-re
  6079. (while (string-match remove-re txt)
  6080. (setq txt (replace-match "" t t txt))))
  6081. ;; Set org-heading property on `txt' to mark the start of the
  6082. ;; heading.
  6083. (add-text-properties 0 (length txt) '(org-heading t) txt)
  6084. ;; Prepare the variables needed in the eval of the compiled format
  6085. (if org-prefix-has-breadcrumbs
  6086. (setq breadcrumbs (org-with-point-at (org-get-at-bol 'org-marker)
  6087. (let ((s (org-display-outline-path nil nil "->" t)))
  6088. (if (eq "" s) "" (concat s "->"))))))
  6089. (setq time (cond (s2 (concat
  6090. (org-agenda-time-of-day-to-ampm-maybe s1)
  6091. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  6092. (if org-agenda-timegrid-use-ampm " ")))
  6093. (s1 (concat
  6094. (org-agenda-time-of-day-to-ampm-maybe s1)
  6095. (if org-agenda-timegrid-use-ampm
  6096. "........ "
  6097. "......")))
  6098. (t ""))
  6099. extra (or (and (not habitp) extra) "")
  6100. category (if (symbolp category) (symbol-name category) category)
  6101. thecategory (copy-sequence category)
  6102. level (or level ""))
  6103. (if (string-match org-bracket-link-regexp category)
  6104. (progn
  6105. (setq l (if (match-end 3)
  6106. (- (match-end 3) (match-beginning 3))
  6107. (- (match-end 1) (match-beginning 1))))
  6108. (when (< l (or org-prefix-category-length 0))
  6109. (setq category (copy-sequence category))
  6110. (org-add-props category nil
  6111. 'extra-space (make-string
  6112. (- org-prefix-category-length l 1) ?\ ))))
  6113. (if (and org-prefix-category-max-length
  6114. (>= (length category) org-prefix-category-max-length))
  6115. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  6116. ;; Evaluate the compiled format
  6117. (setq rtn (concat (eval formatter) txt))
  6118. ;; And finally add the text properties
  6119. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  6120. (org-add-props rtn nil
  6121. 'org-category (if thecategory (downcase thecategory) category)
  6122. 'tags (mapcar 'org-downcase-keep-props tags)
  6123. 'org-highest-priority org-highest-priority
  6124. 'org-lowest-priority org-lowest-priority
  6125. 'time-of-day time-of-day
  6126. 'duration duration
  6127. 'effort effort
  6128. 'effort-minutes neffort
  6129. 'breadcrumbs breadcrumbs
  6130. 'txt txt
  6131. 'level level
  6132. 'time time
  6133. 'extra extra
  6134. 'format org-prefix-format-compiled
  6135. 'dotime dotime)))))
  6136. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  6137. "Remove tags string from TXT, and add a modified list of tags.
  6138. The modified list may contain inherited tags, and tags matched by
  6139. `org-agenda-hide-tags-regexp' will be removed."
  6140. (when (or add-inherited hide-re)
  6141. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  6142. (setq txt (substring txt 0 (match-beginning 0))))
  6143. (setq tags
  6144. (delq nil
  6145. (mapcar (lambda (tg)
  6146. (if (or (and hide-re (string-match hide-re tg))
  6147. (and (not add-inherited)
  6148. (get-text-property 0 'inherited tg)))
  6149. nil
  6150. tg))
  6151. tags)))
  6152. (when tags
  6153. (let ((have-i (get-text-property 0 'inherited (car tags)))
  6154. i)
  6155. (setq txt (concat txt " :"
  6156. (mapconcat
  6157. (lambda (x)
  6158. (setq i (get-text-property 0 'inherited x))
  6159. (if (and have-i (not i))
  6160. (progn
  6161. (setq have-i nil)
  6162. (concat ":" x))
  6163. x))
  6164. tags ":")
  6165. (if have-i "::" ":"))))))
  6166. txt)
  6167. (defun org-downcase-keep-props (s)
  6168. (let ((props (text-properties-at 0 s)))
  6169. (setq s (downcase s))
  6170. (add-text-properties 0 (length s) props s)
  6171. s))
  6172. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  6173. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  6174. "Add a time-grid for agenda items which need it.
  6175. LIST is the list of agenda items formatted by `org-agenda-list'.
  6176. NDAYS is the span of the current agenda view.
  6177. TODAYP is `t' when the current agenda view is on today."
  6178. (catch 'exit
  6179. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  6180. ((and todayp (member 'today (car org-agenda-time-grid))))
  6181. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  6182. ((member 'weekly (car org-agenda-time-grid)))
  6183. (t (throw 'exit list)))
  6184. (let* ((have (delq nil (mapcar
  6185. (lambda (x) (get-text-property 1 'time-of-day x))
  6186. list)))
  6187. (string (nth 1 org-agenda-time-grid))
  6188. (gridtimes (nth 2 org-agenda-time-grid))
  6189. (req (car org-agenda-time-grid))
  6190. (remove (member 'remove-match req))
  6191. new time)
  6192. (if (and (member 'require-timed req) (not have))
  6193. ;; don't show empty grid
  6194. (throw 'exit list))
  6195. (while (setq time (pop gridtimes))
  6196. (unless (and remove (member time have))
  6197. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  6198. (push (org-agenda-format-item
  6199. nil string nil "" nil
  6200. (concat (substring time 0 -2) ":" (substring time -2)))
  6201. new)
  6202. (put-text-property
  6203. 2 (length (car new)) 'face 'org-time-grid (car new))))
  6204. (when (and todayp org-agenda-show-current-time-in-grid)
  6205. (push (org-agenda-format-item
  6206. nil org-agenda-current-time-string nil "" nil
  6207. (format-time-string "%H:%M "))
  6208. new)
  6209. (put-text-property
  6210. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  6211. (if (member 'time-up org-agenda-sorting-strategy-selected)
  6212. (append new list)
  6213. (append list new)))))
  6214. (defun org-compile-prefix-format (key)
  6215. "Compile the prefix format into a Lisp form that can be evaluated.
  6216. The resulting form and associated variable bindings is returned
  6217. and stored in the variable `org-prefix-format-compiled'."
  6218. (setq org-prefix-has-time nil
  6219. org-prefix-has-tag nil
  6220. org-prefix-category-length nil
  6221. org-prefix-has-effort nil
  6222. org-prefix-has-breadcrumbs nil)
  6223. (let ((s (cond
  6224. ((stringp org-agenda-prefix-format)
  6225. org-agenda-prefix-format)
  6226. ((assq key org-agenda-prefix-format)
  6227. (cdr (assq key org-agenda-prefix-format)))
  6228. (t " %-12:c%?-12t% s")))
  6229. (start 0)
  6230. varform vars var e c f opt)
  6231. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltseib]\\|(.+)\\)"
  6232. s start)
  6233. (setq var (or (cdr (assoc (match-string 4 s)
  6234. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  6235. ("i" . category-icon) ("T" . tag) ("e" . effort) ("b" . breadcrumbs))))
  6236. 'eval)
  6237. c (or (match-string 3 s) "")
  6238. opt (match-beginning 1)
  6239. start (1+ (match-beginning 0)))
  6240. (if (equal var 'time) (setq org-prefix-has-time t))
  6241. (if (equal var 'tag) (setq org-prefix-has-tag t))
  6242. (if (equal var 'effort) (setq org-prefix-has-effort t))
  6243. (if (equal var 'breadcrumbs) (setq org-prefix-has-breadcrumbs t))
  6244. (setq f (concat "%" (match-string 2 s) "s"))
  6245. (when (equal var 'category)
  6246. (setq org-prefix-category-length
  6247. (floor (abs (string-to-number (match-string 2 s)))))
  6248. (setq org-prefix-category-max-length
  6249. (let ((x (match-string 2 s)))
  6250. (save-match-data
  6251. (if (string-match "\\.[0-9]+" x)
  6252. (string-to-number (substring (match-string 0 x) 1)))))))
  6253. (if (eq var 'eval)
  6254. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  6255. (if opt
  6256. (setq varform
  6257. `(if (equal "" ,var)
  6258. ""
  6259. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  6260. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  6261. (setq s (replace-match "%s" t nil s))
  6262. (push varform vars))
  6263. (setq vars (nreverse vars))
  6264. (with-current-buffer (or org-agenda-buffer (current-buffer))
  6265. (setq org-prefix-format-compiled
  6266. (list
  6267. `((org-prefix-has-time ,org-prefix-has-time)
  6268. (org-prefix-has-tag ,org-prefix-has-tag)
  6269. (org-prefix-category-length ,org-prefix-category-length)
  6270. (org-prefix-has-effort ,org-prefix-has-effort)
  6271. (org-prefix-has-breadcrumbs ,org-prefix-has-breadcrumbs))
  6272. `(format ,s ,@vars))))))
  6273. (defun org-set-sorting-strategy (key)
  6274. (if (symbolp (car org-agenda-sorting-strategy))
  6275. ;; the old format
  6276. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  6277. (setq org-agenda-sorting-strategy-selected
  6278. (or (cdr (assq key org-agenda-sorting-strategy))
  6279. (cdr (assq 'agenda org-agenda-sorting-strategy))
  6280. '(time-up category-keep priority-down)))))
  6281. (defun org-get-time-of-day (s &optional string mod24)
  6282. "Check string S for a time of day.
  6283. If found, return it as a military time number between 0 and 2400.
  6284. If not found, return nil.
  6285. The optional STRING argument forces conversion into a 5 character wide string
  6286. HH:MM."
  6287. (save-match-data
  6288. (when
  6289. (and
  6290. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  6291. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  6292. (not (eq (get-text-property 1 'face s) 'org-link)))
  6293. (let* ((h (string-to-number (match-string 1 s)))
  6294. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  6295. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  6296. (am-p (equal ampm "am"))
  6297. (h1 (cond ((not ampm) h)
  6298. ((= h 12) (if am-p 0 12))
  6299. (t (+ h (if am-p 0 12)))))
  6300. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  6301. (mod h1 24) h1))
  6302. (t0 (+ (* 100 h2) m))
  6303. (t1 (concat (if (>= h1 24) "+" " ")
  6304. (if (and org-agenda-time-leading-zero
  6305. (< t0 1000)) "0" "")
  6306. (if (< t0 100) "0" "")
  6307. (if (< t0 10) "0" "")
  6308. (int-to-string t0))))
  6309. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6310. (defvar org-agenda-before-sorting-filter-function nil
  6311. "Function to be applied to agenda items prior to sorting.
  6312. Prior to sorting also means just before they are inserted into the agenda.
  6313. To aid sorting, you may revisit the original entries and add more text
  6314. properties which will later be used by the sorting functions.
  6315. The function should take a string argument, an agenda line.
  6316. It has access to the text properties in that line, which contain among
  6317. other things, the property `org-hd-marker' that points to the entry
  6318. where the line comes from. Note that not all lines going into the agenda
  6319. have this property, only most.
  6320. The function should return the modified string. It is probably best
  6321. to ONLY change text properties.
  6322. You can also use this function as a filter, by returning nil for lines
  6323. you don't want to have in the agenda at all. For this application, you
  6324. could bind the variable in the options section of a custom command.")
  6325. (defun org-agenda-finalize-entries (list &optional type)
  6326. "Sort, limit and concatenate the LIST of agenda items.
  6327. The optional argument TYPE tells the agenda type."
  6328. (let ((max-effort (cond ((listp org-agenda-max-effort)
  6329. (cdr (assoc type org-agenda-max-effort)))
  6330. (t org-agenda-max-effort)))
  6331. (max-todo (cond ((listp org-agenda-max-todos)
  6332. (cdr (assoc type org-agenda-max-todos)))
  6333. (t org-agenda-max-todos)))
  6334. (max-tags (cond ((listp org-agenda-max-tags)
  6335. (cdr (assoc type org-agenda-max-tags)))
  6336. (t org-agenda-max-tags)))
  6337. (max-entries (cond ((listp org-agenda-max-entries)
  6338. (cdr (assoc type org-agenda-max-entries)))
  6339. (t org-agenda-max-entries))) l)
  6340. (when org-agenda-before-sorting-filter-function
  6341. (setq list
  6342. (delq nil
  6343. (mapcar
  6344. org-agenda-before-sorting-filter-function list))))
  6345. (setq list (mapcar 'org-agenda-highlight-todo list)
  6346. list (mapcar 'identity (sort list 'org-entries-lessp)))
  6347. (when max-effort
  6348. (setq list (org-agenda-limit-entries
  6349. list 'effort-minutes max-effort 'identity)))
  6350. (when max-todo
  6351. (setq list (org-agenda-limit-entries list 'todo-state max-todo)))
  6352. (when max-tags
  6353. (setq list (org-agenda-limit-entries list 'tags max-tags)))
  6354. (when max-entries
  6355. (setq list (org-agenda-limit-entries list 'org-hd-marker max-entries)))
  6356. (mapconcat 'identity list "\n")))
  6357. (defun org-agenda-limit-entries (list prop limit &optional fn)
  6358. "Limit the number of agenda entries."
  6359. (let ((include (and limit (< limit 0))))
  6360. (if limit
  6361. (let ((fun (or fn (lambda (p) (if p 1))))
  6362. (lim 0))
  6363. (delq nil
  6364. (mapcar
  6365. (lambda (e)
  6366. (let ((pval (funcall fun (get-text-property 1 prop e))))
  6367. (if pval (setq lim (+ lim pval)))
  6368. (cond ((and pval (<= lim (abs limit))) e)
  6369. ((and include (not pval)) e))))
  6370. list)))
  6371. list)))
  6372. (defun org-agenda-limit-interactively ()
  6373. "In agenda, interactively limit entries to various maximums."
  6374. (interactive)
  6375. (let* ((max (read-char "Number of [e]ntries [t]odos [T]ags [E]ffort? "))
  6376. (num (string-to-number (read-from-minibuffer "How many? "))))
  6377. (cond ((equal max ?e)
  6378. (let ((org-agenda-max-entries num)) (org-agenda-redo)))
  6379. ((equal max ?t)
  6380. (let ((org-agenda-max-todos num)) (org-agenda-redo)))
  6381. ((equal max ?T)
  6382. (let ((org-agenda-max-tags num)) (org-agenda-redo)))
  6383. ((equal max ?E)
  6384. (let ((org-agenda-max-effort num)) (org-agenda-redo)))))
  6385. (org-agenda-fit-window-to-buffer))
  6386. (defun org-agenda-highlight-todo (x)
  6387. (let ((org-done-keywords org-done-keywords-for-agenda)
  6388. (case-fold-search nil)
  6389. re)
  6390. (if (eq x 'line)
  6391. (save-excursion
  6392. (beginning-of-line 1)
  6393. (setq re (org-get-at-bol 'org-todo-regexp))
  6394. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6395. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6396. (add-text-properties (match-beginning 0) (match-end 1)
  6397. (list 'face (org-get-todo-face 1)))
  6398. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6399. (delete-region (match-beginning 1) (1- (match-end 0)))
  6400. (goto-char (match-beginning 1))
  6401. (insert (format org-agenda-todo-keyword-format s)))))
  6402. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6403. (setq re (get-text-property 0 'org-todo-regexp x))
  6404. (when (and re
  6405. ;; Test `pl' because if there's no heading content,
  6406. ;; there's no point matching to highlight. Note
  6407. ;; that if we didn't test `pl' first, and there
  6408. ;; happened to be no keyword from `org-todo-regexp'
  6409. ;; on this heading line, then the `equal' comparison
  6410. ;; afterwards would spuriously succeed in the case
  6411. ;; where `pl' is nil -- causing an args-out-of-range
  6412. ;; error when we try to add text properties to text
  6413. ;; that isn't there.
  6414. pl
  6415. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6416. x pl) pl))
  6417. (add-text-properties
  6418. (or (match-end 1) (match-end 0)) (match-end 0)
  6419. (list 'face (org-get-todo-face (match-string 2 x)))
  6420. x)
  6421. (when (match-end 1)
  6422. (setq x (concat (substring x 0 (match-end 1))
  6423. (format org-agenda-todo-keyword-format
  6424. (match-string 2 x))
  6425. (org-add-props " " (text-properties-at 0 x))
  6426. (substring x (match-end 3)))))))
  6427. x)))
  6428. (defsubst org-cmp-priority (a b)
  6429. "Compare the priorities of string A and B."
  6430. (let ((pa (or (get-text-property 1 'priority a) 0))
  6431. (pb (or (get-text-property 1 'priority b) 0)))
  6432. (cond ((> pa pb) +1)
  6433. ((< pa pb) -1))))
  6434. (defsubst org-cmp-effort (a b)
  6435. "Compare the effort values of string A and B."
  6436. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6437. (ea (or (get-text-property 1 'effort-minutes a) def))
  6438. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6439. (cond ((> ea eb) +1)
  6440. ((< ea eb) -1))))
  6441. (defsubst org-cmp-category (a b)
  6442. "Compare the string values of categories of strings A and B."
  6443. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6444. (cb (or (get-text-property 1 'org-category b) "")))
  6445. (cond ((string-lessp ca cb) -1)
  6446. ((string-lessp cb ca) +1))))
  6447. (defsubst org-cmp-todo-state (a b)
  6448. "Compare the todo states of strings A and B."
  6449. (let* ((ma (or (get-text-property 1 'org-marker a)
  6450. (get-text-property 1 'org-hd-marker a)))
  6451. (mb (or (get-text-property 1 'org-marker b)
  6452. (get-text-property 1 'org-hd-marker b)))
  6453. (fa (and ma (marker-buffer ma)))
  6454. (fb (and mb (marker-buffer mb)))
  6455. (todo-kwds
  6456. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6457. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6458. (ta (or (get-text-property 1 'todo-state a) ""))
  6459. (tb (or (get-text-property 1 'todo-state b) ""))
  6460. (la (- (length (member ta todo-kwds))))
  6461. (lb (- (length (member tb todo-kwds))))
  6462. (donepa (member ta org-done-keywords-for-agenda))
  6463. (donepb (member tb org-done-keywords-for-agenda)))
  6464. (cond ((and donepa (not donepb)) -1)
  6465. ((and (not donepa) donepb) +1)
  6466. ((< la lb) -1)
  6467. ((< lb la) +1))))
  6468. (defsubst org-cmp-alpha (a b)
  6469. "Compare the headlines, alphabetically."
  6470. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6471. (plb (text-property-any 0 (length b) 'org-heading t b))
  6472. (ta (and pla (substring a pla)))
  6473. (tb (and plb (substring b plb))))
  6474. (when pla
  6475. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6476. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6477. (setq ta (substring ta (match-end 0))))
  6478. (setq ta (downcase ta)))
  6479. (when plb
  6480. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6481. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6482. (setq tb (substring tb (match-end 0))))
  6483. (setq tb (downcase tb)))
  6484. (cond ((not ta) +1)
  6485. ((not tb) -1)
  6486. ((string-lessp ta tb) -1)
  6487. ((string-lessp tb ta) +1))))
  6488. (defsubst org-cmp-tag (a b)
  6489. "Compare the string values of the first tags of A and B."
  6490. (let ((ta (car (last (get-text-property 1 'tags a))))
  6491. (tb (car (last (get-text-property 1 'tags b)))))
  6492. (cond ((not ta) +1)
  6493. ((not tb) -1)
  6494. ((string-lessp ta tb) -1)
  6495. ((string-lessp tb ta) +1))))
  6496. (defsubst org-cmp-time (a b)
  6497. "Compare the time-of-day values of strings A and B."
  6498. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6499. (ta (or (get-text-property 1 'time-of-day a) def))
  6500. (tb (or (get-text-property 1 'time-of-day b) def)))
  6501. (cond ((< ta tb) -1)
  6502. ((< tb ta) +1))))
  6503. (defsubst org-cmp-ts (a b type)
  6504. "Compare the timestamps values of entries A and B.
  6505. When TYPE is \"scheduled\", \"deadline\", \"timestamp\" or
  6506. \"timestamp_ia\", compare within each of these type. When TYPE
  6507. is the empty string, compare all timestamps without respect of
  6508. their type."
  6509. (let* ((def (if org-sort-agenda-notime-is-late most-positive-fixnum -1))
  6510. (ta (or (and (string-match type (or (get-text-property 1 type a) ""))
  6511. (get-text-property 1 'ts-date a)) def))
  6512. (tb (or (and (string-match type (or (get-text-property 1 type b) ""))
  6513. (get-text-property 1 'ts-date b)) def)))
  6514. (cond ((< ta tb) -1)
  6515. ((< tb ta) +1))))
  6516. (defsubst org-cmp-habit-p (a b)
  6517. "Compare the todo states of strings A and B."
  6518. (let ((ha (get-text-property 1 'org-habit-p a))
  6519. (hb (get-text-property 1 'org-habit-p b)))
  6520. (cond ((and ha (not hb)) -1)
  6521. ((and (not ha) hb) +1))))
  6522. (defun org-entries-lessp (a b)
  6523. "Predicate for sorting agenda entries."
  6524. ;; The following variables will be used when the form is evaluated.
  6525. ;; So even though the compiler complains, keep them.
  6526. (let* ((ss org-agenda-sorting-strategy-selected)
  6527. (timestamp-up (and (org-em 'timestamp-up 'timestamp-down ss)
  6528. (org-cmp-ts a b "")))
  6529. (timestamp-down (if timestamp-up (- timestamp-up) nil))
  6530. (scheduled-up (and (org-em 'scheduled-up 'scheduled-down ss)
  6531. (org-cmp-ts a b "scheduled")))
  6532. (scheduled-down (if scheduled-up (- scheduled-up) nil))
  6533. (deadline-up (and (org-em 'deadline-up 'deadline-down ss)
  6534. (org-cmp-ts a b "deadline")))
  6535. (deadline-down (if deadline-up (- deadline-up) nil))
  6536. (tsia-up (and (org-em 'tsia-up 'tsia-down ss)
  6537. (org-cmp-ts a b "timestamp_ia")))
  6538. (tsia-down (if tsia-up (- tsia-up) nil))
  6539. (ts-up (and (org-em 'ts-up 'ts-down ss)
  6540. (org-cmp-ts a b "timestamp")))
  6541. (ts-down (if ts-up (- ts-up) nil))
  6542. (time-up (and (org-em 'time-up 'time-down ss)
  6543. (org-cmp-time a b)))
  6544. (time-down (if time-up (- time-up) nil))
  6545. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6546. (org-cmp-priority a b)))
  6547. (priority-down (if priority-up (- priority-up) nil))
  6548. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6549. (org-cmp-effort a b)))
  6550. (effort-down (if effort-up (- effort-up) nil))
  6551. (category-up (and (or (org-em 'category-up 'category-down ss)
  6552. (memq 'category-keep ss))
  6553. (org-cmp-category a b)))
  6554. (category-down (if category-up (- category-up) nil))
  6555. (category-keep (if category-up +1 nil))
  6556. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6557. (org-cmp-tag a b)))
  6558. (tag-down (if tag-up (- tag-up) nil))
  6559. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6560. (org-cmp-todo-state a b)))
  6561. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6562. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6563. (org-cmp-habit-p a b)))
  6564. (habit-down (if habit-up (- habit-up) nil))
  6565. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6566. (org-cmp-alpha a b)))
  6567. (alpha-down (if alpha-up (- alpha-up) nil))
  6568. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6569. user-defined-up user-defined-down)
  6570. (if (and need-user-cmp org-agenda-cmp-user-defined
  6571. (functionp org-agenda-cmp-user-defined))
  6572. (setq user-defined-up
  6573. (funcall org-agenda-cmp-user-defined a b)
  6574. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6575. (cdr (assoc
  6576. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6577. '((-1 . t) (1 . nil) (nil . nil))))))
  6578. ;;; Agenda restriction lock
  6579. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6580. "Overlay to mark the headline to which agenda commands are restricted.")
  6581. (overlay-put org-agenda-restriction-lock-overlay
  6582. 'face 'org-agenda-restriction-lock)
  6583. (overlay-put org-agenda-restriction-lock-overlay
  6584. 'help-echo "Agendas are currently limited to this subtree.")
  6585. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6586. ;;;###autoload
  6587. (defun org-agenda-set-restriction-lock (&optional type)
  6588. "Set restriction lock for agenda, to current subtree or file.
  6589. Restriction will be the file if TYPE is `file', or if type is the
  6590. universal prefix '(4), or if the cursor is before the first headline
  6591. in the file. Otherwise, restriction will be to the current subtree."
  6592. (interactive "P")
  6593. (and (equal type '(4)) (setq type 'file))
  6594. (setq type (cond
  6595. (type type)
  6596. ((org-at-heading-p) 'subtree)
  6597. ((condition-case nil (org-back-to-heading t) (error nil))
  6598. 'subtree)
  6599. (t 'file)))
  6600. (if (eq type 'subtree)
  6601. (progn
  6602. (setq org-agenda-restrict (current-buffer))
  6603. (setq org-agenda-overriding-restriction 'subtree)
  6604. (put 'org-agenda-files 'org-restrict
  6605. (list (buffer-file-name (buffer-base-buffer))))
  6606. (org-back-to-heading t)
  6607. (move-overlay org-agenda-restriction-lock-overlay
  6608. (point)
  6609. (if org-agenda-restriction-lock-highlight-subtree
  6610. (save-excursion (org-end-of-subtree t t) (point))
  6611. (point-at-eol)))
  6612. (move-marker org-agenda-restrict-begin (point))
  6613. (move-marker org-agenda-restrict-end
  6614. (save-excursion (org-end-of-subtree t t)))
  6615. (message "Locking agenda restriction to subtree"))
  6616. (put 'org-agenda-files 'org-restrict
  6617. (list (buffer-file-name (buffer-base-buffer))))
  6618. (setq org-agenda-restrict nil)
  6619. (setq org-agenda-overriding-restriction 'file)
  6620. (move-marker org-agenda-restrict-begin nil)
  6621. (move-marker org-agenda-restrict-end nil)
  6622. (message "Locking agenda restriction to file"))
  6623. (setq current-prefix-arg nil)
  6624. (org-agenda-maybe-redo))
  6625. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6626. "Remove the agenda restriction lock."
  6627. (interactive "P")
  6628. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6629. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6630. (setq org-agenda-overriding-restriction nil)
  6631. (setq org-agenda-restrict nil)
  6632. (put 'org-agenda-files 'org-restrict nil)
  6633. (move-marker org-agenda-restrict-begin nil)
  6634. (move-marker org-agenda-restrict-end nil)
  6635. (setq current-prefix-arg nil)
  6636. (message "Agenda restriction lock removed")
  6637. (or noupdate (org-agenda-maybe-redo)))
  6638. (defun org-agenda-maybe-redo ()
  6639. "If there is any window showing the agenda view, update it."
  6640. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6641. (w0 (selected-window)))
  6642. (when w
  6643. (select-window w)
  6644. (org-agenda-redo)
  6645. (select-window w0)
  6646. (if org-agenda-overriding-restriction
  6647. (message "Agenda view shifted to new %s restriction"
  6648. org-agenda-overriding-restriction)
  6649. (message "Agenda restriction lock removed")))))
  6650. ;;; Agenda commands
  6651. (defun org-agenda-check-type (error &rest types)
  6652. "Check if agenda buffer is of allowed type.
  6653. If ERROR is non-nil, throw an error, otherwise just return nil.
  6654. Allowed types are 'agenda 'timeline 'todo 'tags 'search."
  6655. (if (not org-agenda-type)
  6656. (error "No Org agenda currently displayed")
  6657. (if (memq org-agenda-type types)
  6658. t
  6659. (if error
  6660. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6661. nil))))
  6662. (defun org-agenda-Quit ()
  6663. "Exit the agenda and kill buffers loaded by `org-agenda'.
  6664. Also restore the window configuration."
  6665. (interactive)
  6666. (if org-agenda-columns-active
  6667. (org-columns-quit)
  6668. (let ((buf (current-buffer)))
  6669. (if (eq org-agenda-window-setup 'other-frame)
  6670. (progn
  6671. (org-agenda-reset-markers)
  6672. (kill-buffer buf)
  6673. (org-columns-remove-overlays)
  6674. (setq org-agenda-archives-mode nil)
  6675. (delete-frame))
  6676. (and (not (eq org-agenda-window-setup 'current-window))
  6677. (not (one-window-p))
  6678. (delete-window))
  6679. (org-agenda-reset-markers)
  6680. (kill-buffer buf)
  6681. (org-columns-remove-overlays)
  6682. (setq org-agenda-archives-mode nil)))
  6683. (setq org-agenda-buffer nil)
  6684. ;; Maybe restore the pre-agenda window configuration.
  6685. (and org-agenda-restore-windows-after-quit
  6686. (not (eq org-agenda-window-setup 'other-frame))
  6687. org-agenda-pre-window-conf
  6688. (set-window-configuration org-agenda-pre-window-conf)
  6689. (setq org-agenda-pre-window-conf nil))))
  6690. (defun org-agenda-quit ()
  6691. "Exit the agenda and restore the window configuration.
  6692. When `org-agenda-sticky' is non-nil, only bury the agenda."
  6693. (interactive)
  6694. (if (and (eq org-indirect-buffer-display 'other-window)
  6695. org-last-indirect-buffer)
  6696. (let ((org-last-indirect-window
  6697. (get-buffer-window org-last-indirect-buffer)))
  6698. (if org-last-indirect-window
  6699. (delete-window org-last-indirect-window))))
  6700. (if org-agenda-columns-active
  6701. (org-columns-quit)
  6702. (if org-agenda-sticky
  6703. (let ((buf (current-buffer)))
  6704. (if (eq org-agenda-window-setup 'other-frame)
  6705. (progn
  6706. (delete-frame))
  6707. (and (not (eq org-agenda-window-setup 'current-window))
  6708. (not (one-window-p))
  6709. (delete-window)))
  6710. (with-current-buffer buf
  6711. (bury-buffer)
  6712. ;; Maybe restore the pre-agenda window configuration.
  6713. (and org-agenda-restore-windows-after-quit
  6714. (not (eq org-agenda-window-setup 'other-frame))
  6715. org-agenda-pre-window-conf
  6716. (set-window-configuration org-agenda-pre-window-conf)
  6717. (setq org-agenda-pre-window-conf nil))))
  6718. (org-agenda-Quit))))
  6719. (defun org-agenda-exit ()
  6720. "Exit the agenda and restore the window configuration.
  6721. Also kill Org-mode buffers loaded by `org-agenda'. Org-mode
  6722. buffers visited directly by the user will not be touched."
  6723. (interactive)
  6724. (org-release-buffers org-agenda-new-buffers)
  6725. (setq org-agenda-new-buffers nil)
  6726. (org-agenda-Quit))
  6727. (defun org-agenda-kill-all-agenda-buffers ()
  6728. "Kill all buffers in `org-agenda-mode'.
  6729. This is used when toggling sticky agendas.
  6730. You can also explicitly invoke it with `C-c a C-k'."
  6731. (interactive)
  6732. (let (blist)
  6733. (dolist (buf (buffer-list))
  6734. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6735. (push buf blist)))
  6736. (mapc 'kill-buffer blist)))
  6737. (defun org-agenda-execute (arg)
  6738. "Execute another agenda command, keeping same window.
  6739. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6740. in the agenda."
  6741. (interactive "P")
  6742. (let ((org-agenda-window-setup 'current-window))
  6743. (org-agenda arg)))
  6744. (defun org-agenda-redo (&optional all)
  6745. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6746. (interactive "P")
  6747. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6748. (cpa (unless (eq all t) current-prefix-arg))
  6749. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6750. (org-agenda-sticky nil)
  6751. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6752. org-agenda-buffer-name))
  6753. (org-agenda-keep-modes t)
  6754. (tag-filter org-agenda-tag-filter)
  6755. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6756. (top-hl-filter org-agenda-top-headline-filter)
  6757. (cat-filter org-agenda-category-filter)
  6758. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6759. (re-filter org-agenda-regexp-filter)
  6760. (re-preset (get 'org-agenda-regexp-filter :preset-filter))
  6761. (cols org-agenda-columns-active)
  6762. (line (org-current-line))
  6763. (window-line (- line (org-current-line (window-start))))
  6764. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6765. (redo-cmd (get-text-property p 'org-redo-cmd))
  6766. (last-args (get-text-property p 'org-last-args))
  6767. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6768. (org-agenda-overriding-cmd-arguments
  6769. (unless (eq all t)
  6770. (cond ((listp last-args)
  6771. (cons (or cpa (car last-args)) (cdr last-args)))
  6772. ((stringp last-args)
  6773. last-args))))
  6774. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6775. (put 'org-agenda-tag-filter :preset-filter nil)
  6776. (put 'org-agenda-category-filter :preset-filter nil)
  6777. (put 'org-agenda-regexp-filter :preset-filter nil)
  6778. (and cols (org-columns-quit))
  6779. (message "Rebuilding agenda buffer...")
  6780. (if series-redo-cmd
  6781. (eval series-redo-cmd)
  6782. (org-let lprops redo-cmd))
  6783. (setq org-agenda-undo-list nil
  6784. org-agenda-pending-undo-list nil
  6785. org-agenda-tag-filter tag-filter
  6786. org-agenda-category-filter cat-filter
  6787. org-agenda-regexp-filter re-filter
  6788. org-agenda-top-headline-filter top-hl-filter)
  6789. (message "Rebuilding agenda buffer...done")
  6790. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6791. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6792. (put 'org-agenda-regexp-filter :preset-filter re-preset)
  6793. (let ((tag (or tag-filter tag-preset))
  6794. (cat (or cat-filter cat-preset))
  6795. (re (or re-filter re-preset)))
  6796. (when tag (org-agenda-filter-apply tag 'tag))
  6797. (when cat (org-agenda-filter-apply cat 'category))
  6798. (when re (org-agenda-filter-apply re 'regexp)))
  6799. (and top-hl-filter (org-agenda-filter-top-headline-apply top-hl-filter))
  6800. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6801. (org-goto-line line)
  6802. (recenter window-line)))
  6803. (defvar org-global-tags-completion-table nil)
  6804. (defvar org-agenda-filter-form nil)
  6805. (defvar org-agenda-filtered-by-category nil)
  6806. (defun org-agenda-filter-by-category (strip)
  6807. "Keep only those lines in the agenda buffer that have a specific category.
  6808. The category is that of the current line."
  6809. (interactive "P")
  6810. (if (and org-agenda-filtered-by-category
  6811. org-agenda-category-filter)
  6812. (org-agenda-filter-show-all-cat)
  6813. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6814. (cond
  6815. ((and cat strip)
  6816. (org-agenda-filter-apply
  6817. (push (concat "-" cat) org-agenda-category-filter) 'category))
  6818. ((and cat)
  6819. (org-agenda-filter-apply
  6820. (setq org-agenda-category-filter
  6821. (list (concat "+" cat))) 'category))
  6822. (t (error "No category at point"))))))
  6823. (defun org-find-top-headline (&optional pos)
  6824. "Find the topmost parent headline and return it."
  6825. (save-excursion
  6826. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6827. (if pos (goto-char pos))
  6828. ;; Skip up to the topmost parent
  6829. (while (ignore-errors (outline-up-heading 1) t))
  6830. (ignore-errors
  6831. (nth 4 (org-heading-components))))))
  6832. (defvar org-agenda-filtered-by-top-headline nil)
  6833. (defun org-agenda-filter-by-top-headline (strip)
  6834. "Keep only those lines that are descendants from the same top headline.
  6835. The top headline is that of the current line."
  6836. (interactive "P")
  6837. (if org-agenda-filtered-by-top-headline
  6838. (progn
  6839. (setq org-agenda-filtered-by-top-headline nil
  6840. org-agenda-top-headline-filter nil)
  6841. (org-agenda-filter-show-all-top-filter))
  6842. (let ((toph (org-find-top-headline (org-get-at-bol 'org-hd-marker))))
  6843. (if toph (org-agenda-filter-top-headline-apply toph strip)
  6844. (error "No top-level headline at point")))))
  6845. (defvar org-agenda-regexp-filter nil)
  6846. (defun org-agenda-filter-by-regexp (strip)
  6847. "Filter agenda entries by a regular expression.
  6848. Regexp filters are cumulative.
  6849. With no prefix argument, keep entries matching the regexp.
  6850. With one prefix argument, filter out entries matching the regexp.
  6851. With two prefix arguments, remove the regexp filters."
  6852. (interactive "P")
  6853. (if (not (equal strip '(16)))
  6854. (let ((flt (concat (if (equal strip '(4)) "-" "+")
  6855. (read-from-minibuffer
  6856. (if (equal strip '(4))
  6857. "Filter out entries matching regexp: "
  6858. "Narrow to entries matching regexp: ")))))
  6859. (push flt org-agenda-regexp-filter)
  6860. (org-agenda-filter-apply org-agenda-regexp-filter 'regexp))
  6861. (org-agenda-filter-show-all-re)
  6862. (message "Regexp filter removed")))
  6863. (defun org-agenda-filter-remove-all ()
  6864. "Remove all filters from the current agenda buffer."
  6865. (interactive)
  6866. (when org-agenda-tag-filter
  6867. (org-agenda-filter-show-all-tag))
  6868. (when org-agenda-category-filter
  6869. (org-agenda-filter-show-all-cat))
  6870. (when org-agenda-regexp-filter
  6871. (org-agenda-filter-show-all-re))
  6872. (when org-agenda-top-headline-filter
  6873. (org-agenda-filter-show-all-top-filter))
  6874. (org-agenda-finalize))
  6875. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6876. "Keep only those lines in the agenda buffer that have a specific tag.
  6877. The tag is selected with its fast selection letter, as configured.
  6878. With prefix argument STRIP, remove all lines that do have the tag.
  6879. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6880. used to narrow the search - the interactive user can also press `-' or `+'
  6881. to switch to narrowing."
  6882. (interactive "P")
  6883. (let* ((alist org-tag-alist-for-agenda)
  6884. (tag-chars (mapconcat
  6885. (lambda (x) (if (and (not (symbolp (car x)))
  6886. (cdr x))
  6887. (char-to-string (cdr x))
  6888. ""))
  6889. alist ""))
  6890. (efforts (org-split-string
  6891. (or (cdr (assoc (concat org-effort-property "_ALL")
  6892. org-global-properties))
  6893. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6894. "")))
  6895. (effort-op org-agenda-filter-effort-default-operator)
  6896. (effort-prompt "")
  6897. (inhibit-read-only t)
  6898. (current org-agenda-tag-filter)
  6899. maybe-refresh a n tag)
  6900. (unless char
  6901. (message
  6902. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6903. (if narrow "Narrow" "Filter") tag-chars
  6904. (if org-agenda-auto-exclude-function "[RET], " ""))
  6905. (setq char (read-char-exclusive)))
  6906. (when (member char '(?+ ?-))
  6907. ;; Narrowing down
  6908. (cond ((equal char ?-) (setq strip t narrow t))
  6909. ((equal char ?+) (setq strip nil narrow t)))
  6910. (message
  6911. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6912. (setq char (read-char-exclusive)))
  6913. (when (member char '(?< ?> ?= ??))
  6914. ;; An effort operator
  6915. (setq effort-op (char-to-string char))
  6916. (setq alist nil) ; to make sure it will be interpreted as effort.
  6917. (unless (equal char ??)
  6918. (loop for i from 0 to 9 do
  6919. (setq effort-prompt
  6920. (concat
  6921. effort-prompt " ["
  6922. (if (= i 9) "0" (int-to-string (1+ i)))
  6923. "]" (nth i efforts))))
  6924. (message "Effort%s: %s " effort-op effort-prompt)
  6925. (setq char (read-char-exclusive))
  6926. (when (or (< char ?0) (> char ?9))
  6927. (error "Need 1-9,0 to select effort"))))
  6928. (when (equal char ?\t)
  6929. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6930. (org-set-local 'org-global-tags-completion-table
  6931. (org-global-tags-completion-table)))
  6932. (let ((completion-ignore-case t))
  6933. (setq tag (org-icompleting-read
  6934. "Tag: " org-global-tags-completion-table))))
  6935. (cond
  6936. ((equal char ?\r)
  6937. (org-agenda-filter-show-all-tag)
  6938. (when org-agenda-auto-exclude-function
  6939. (setq org-agenda-tag-filter nil)
  6940. (dolist (tag (org-agenda-get-represented-tags))
  6941. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6942. (if modifier
  6943. (push modifier org-agenda-tag-filter))))
  6944. (if (not (null org-agenda-tag-filter))
  6945. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6946. (setq maybe-refresh t))
  6947. ((equal char ?/)
  6948. (org-agenda-filter-show-all-tag)
  6949. (when (get 'org-agenda-tag-filter :preset-filter)
  6950. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6951. (setq maybe-refresh t))
  6952. ((equal char ?. )
  6953. (setq org-agenda-tag-filter
  6954. (mapcar (lambda(tag) (concat "+" tag))
  6955. (org-get-at-bol 'tags)))
  6956. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6957. (setq maybe-refresh t))
  6958. ((or (equal char ?\ )
  6959. (setq a (rassoc char alist))
  6960. (and (>= char ?0) (<= char ?9)
  6961. (setq n (if (= char ?0) 9 (- char ?0 1))
  6962. tag (concat effort-op (nth n efforts))
  6963. a (cons tag nil)))
  6964. (and (= char ??)
  6965. (setq tag "?eff")
  6966. a (cons tag nil))
  6967. (and tag (setq a (cons tag nil))))
  6968. (org-agenda-filter-show-all-tag)
  6969. (setq tag (car a))
  6970. (setq org-agenda-tag-filter
  6971. (cons (concat (if strip "-" "+") tag)
  6972. (if narrow current nil)))
  6973. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6974. (setq maybe-refresh t))
  6975. (t (error "Invalid tag selection character %c" char)))
  6976. (when maybe-refresh
  6977. (org-agenda-redo))))
  6978. (defun org-agenda-get-represented-tags ()
  6979. "Get a list of all tags currently represented in the agenda."
  6980. (let (p tags)
  6981. (save-excursion
  6982. (goto-char (point-min))
  6983. (while (setq p (next-single-property-change (point) 'tags))
  6984. (goto-char p)
  6985. (mapc (lambda (x) (add-to-list 'tags x))
  6986. (get-text-property (point) 'tags))))
  6987. tags))
  6988. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6989. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6990. (interactive "P")
  6991. (org-agenda-filter-by-tag strip char 'refine))
  6992. (defun org-agenda-filter-make-matcher (filter type)
  6993. "Create the form that tests a line for agenda filter."
  6994. (let (f f1)
  6995. (cond
  6996. ;; Tag filter
  6997. ((eq type 'tag)
  6998. (setq filter
  6999. (delete-dups
  7000. (append (get 'org-agenda-tag-filter :preset-filter)
  7001. filter)))
  7002. (dolist (x filter)
  7003. (let ((nfilter (org-agenda-filter-expand-tags filter)) nf nf1
  7004. (ffunc
  7005. (lambda (nf0 nf01 fltr notgroup op)
  7006. (dolist (x fltr)
  7007. (if (member x '("-" "+"))
  7008. (setq nf01 (if (equal x "-") 'tags '(not tags)))
  7009. (if (string-match "[<=>?]" x)
  7010. (setq nf01 (org-agenda-filter-effort-form x))
  7011. (setq nf01 (list 'member (downcase (substring x 1))
  7012. 'tags)))
  7013. (when (equal (string-to-char x) ?-)
  7014. (setq nf01 (list 'not nf01))
  7015. (when (not notgroup) (setq op 'and))))
  7016. (push nf01 nf0))
  7017. (if notgroup
  7018. (push (cons 'and nf0) f)
  7019. (push (cons (or op 'or) nf0) f)))))
  7020. (cond ((equal filter '("+"))
  7021. (setq f (list (list 'not 'tags))))
  7022. ((equal nfilter filter)
  7023. (funcall ffunc f1 f filter t nil))
  7024. (t (funcall ffunc nf1 nf nfilter nil nil))))))
  7025. ;; Category filter
  7026. ((eq type 'category)
  7027. (setq filter
  7028. (delete-dups
  7029. (append (get 'org-agenda-category-filter :preset-filter)
  7030. filter)))
  7031. (dolist (x filter)
  7032. (if (equal "-" (substring x 0 1))
  7033. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  7034. (setq f1 (list 'equal (substring x 1) 'cat)))
  7035. (push f1 f)))
  7036. ;; Regexp filter
  7037. ((eq type 'regexp)
  7038. (setq filter
  7039. (delete-dups
  7040. (append (get 'org-agenda-regexp-filter :preset-filter)
  7041. filter)))
  7042. (dolist (x filter)
  7043. (if (equal "-" (substring x 0 1))
  7044. (setq f1 (list 'not (list 'string-match (substring x 1) 'txt)))
  7045. (setq f1 (list 'string-match (substring x 1) 'txt)))
  7046. (push f1 f))))
  7047. (cons 'and (nreverse f))))
  7048. (defun org-agenda-filter-effort-form (e)
  7049. "Return the form to compare the effort of the current line with what E says.
  7050. E looks like \"+<2:25\"."
  7051. (let (op)
  7052. (setq e (substring e 1))
  7053. (setq op (string-to-char e) e (substring e 1))
  7054. (setq op (cond ((equal op ?<) '<=)
  7055. ((equal op ?>) '>=)
  7056. ((equal op ??) op)
  7057. (t '=)))
  7058. (list 'org-agenda-compare-effort (list 'quote op)
  7059. (org-duration-string-to-minutes e))))
  7060. (defun org-agenda-compare-effort (op value)
  7061. "Compare the effort of the current line with VALUE, using OP.
  7062. If the line does not have an effort defined, return nil."
  7063. (let ((eff (org-get-at-bol 'effort-minutes)))
  7064. (if (equal op ??)
  7065. (not eff)
  7066. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  7067. value))))
  7068. (defun org-agenda-filter-expand-tags (filter &optional no-operator)
  7069. "Expand group tags in FILTER for the agenda.
  7070. When NO-OPERATOR is non-nil, do not add the + operator to returned tags."
  7071. (if org-group-tags
  7072. (let ((case-fold-search t) rtn)
  7073. (mapc
  7074. (lambda (f)
  7075. (let (f0 dir)
  7076. (if (string-match "^\\([+-]\\)\\(.+\\)" f)
  7077. (setq dir (match-string 1 f) f0 (match-string 2 f))
  7078. (setq dir (if no-operator "" "+") f0 f))
  7079. (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
  7080. (org-tags-expand f0 t t))
  7081. rtn))))
  7082. filter)
  7083. (reverse rtn))
  7084. filter))
  7085. (defun org-agenda-filter-apply (filter type)
  7086. "Set FILTER as the new agenda filter and apply it."
  7087. ;; Deactivate `org-agenda-entry-text-mode' when filtering
  7088. (if org-agenda-entry-text-mode (org-agenda-entry-text-mode))
  7089. (let (tags cat txt)
  7090. (setq org-agenda-filter-form
  7091. (org-agenda-filter-make-matcher filter type))
  7092. (if (and (eq type 'category)
  7093. (not (equal (substring (car filter) 0 1) "-")))
  7094. ;; Only set `org-agenda-filtered-by-category' to t
  7095. ;; when a unique category is used as the filter
  7096. (setq org-agenda-filtered-by-category t))
  7097. (org-agenda-set-mode-name)
  7098. (save-excursion
  7099. (goto-char (point-min))
  7100. (while (not (eobp))
  7101. (if (org-get-at-bol 'org-marker)
  7102. (progn
  7103. (setq tags ; used in eval
  7104. (apply 'append
  7105. (mapcar (lambda (f)
  7106. (org-agenda-filter-expand-tags (list f) t))
  7107. (org-get-at-bol 'tags)))
  7108. cat (get-text-property (point) 'org-category)
  7109. txt (get-text-property (point) 'txt))
  7110. (if (not (eval org-agenda-filter-form))
  7111. (org-agenda-filter-hide-line type))
  7112. (beginning-of-line 2))
  7113. (beginning-of-line 2))))
  7114. (if (get-char-property (point) 'invisible)
  7115. (ignore-errors (org-agenda-previous-line)))))
  7116. (defun org-agenda-filter-top-headline-apply (hl &optional negative)
  7117. "Filter by top headline HL."
  7118. (org-agenda-set-mode-name)
  7119. (save-excursion
  7120. (goto-char (point-min))
  7121. (while (not (eobp))
  7122. (let* ((pos (org-get-at-bol 'org-hd-marker))
  7123. (tophl (and pos (org-find-top-headline pos))))
  7124. (if (and tophl (funcall (if negative 'identity 'not)
  7125. (string= hl tophl)))
  7126. (org-agenda-filter-hide-line 'top-headline)))
  7127. (beginning-of-line 2)))
  7128. (if (get-char-property (point) 'invisible)
  7129. (org-agenda-previous-line))
  7130. (setq org-agenda-top-headline-filter hl
  7131. org-agenda-filtered-by-top-headline t))
  7132. (defun org-agenda-filter-hide-line (type)
  7133. "Hide lines with TYPE in the agenda buffer."
  7134. (let* ((b (max (point-min) (1- (point-at-bol))))
  7135. (e (point-at-eol)))
  7136. (let ((inhibit-read-only t))
  7137. (add-text-properties
  7138. b e `(invisible org-filtered org-filter-type ,type)))))
  7139. (defun org-agenda-remove-filter (type)
  7140. (interactive)
  7141. "Remove filter of type TYPE from the agenda buffer."
  7142. (save-excursion
  7143. (goto-char (point-min))
  7144. (let ((inhibit-read-only t) pos)
  7145. (while (setq pos (text-property-any (point) (point-max) 'org-filter-type type))
  7146. (goto-char pos)
  7147. (remove-text-properties
  7148. (point) (next-single-property-change (point) 'org-filter-type)
  7149. `(invisible org-filtered org-filter-type ,type))))
  7150. (set (intern (format "org-agenda-%s-filter" (intern-soft type))) nil)
  7151. (setq org-agenda-filter-form nil)
  7152. (org-agenda-set-mode-name)
  7153. (org-agenda-finalize)))
  7154. (defun org-agenda-filter-show-all-tag nil
  7155. (org-agenda-remove-filter 'tag))
  7156. (defun org-agenda-filter-show-all-re nil
  7157. (org-agenda-remove-filter 'regexp))
  7158. (defun org-agenda-filter-show-all-cat nil
  7159. (org-agenda-remove-filter 'category))
  7160. (defun org-agenda-filter-show-all-top-filter nil
  7161. (org-agenda-remove-filter 'top-headline))
  7162. (defun org-agenda-manipulate-query-add ()
  7163. "Manipulate the query by adding a search term with positive selection.
  7164. Positive selection means the term must be matched for selection of an entry."
  7165. (interactive)
  7166. (org-agenda-manipulate-query ?\[))
  7167. (defun org-agenda-manipulate-query-subtract ()
  7168. "Manipulate the query by adding a search term with negative selection.
  7169. Negative selection means term must not be matched for selection of an entry."
  7170. (interactive)
  7171. (org-agenda-manipulate-query ?\]))
  7172. (defun org-agenda-manipulate-query-add-re ()
  7173. "Manipulate the query by adding a search regexp with positive selection.
  7174. Positive selection means the regexp must match for selection of an entry."
  7175. (interactive)
  7176. (org-agenda-manipulate-query ?\{))
  7177. (defun org-agenda-manipulate-query-subtract-re ()
  7178. "Manipulate the query by adding a search regexp with negative selection.
  7179. Negative selection means regexp must not match for selection of an entry."
  7180. (interactive)
  7181. (org-agenda-manipulate-query ?\}))
  7182. (defun org-agenda-manipulate-query (char)
  7183. (cond
  7184. ((memq org-agenda-type '(timeline agenda))
  7185. (let ((org-agenda-include-inactive-timestamps t))
  7186. (org-agenda-redo))
  7187. (message "Display now includes inactive timestamps as well"))
  7188. ((eq org-agenda-type 'search)
  7189. (org-add-to-string
  7190. 'org-agenda-query-string
  7191. (if org-agenda-last-search-view-search-was-boolean
  7192. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  7193. (?\{ . " +{}") (?\} . " -{}"))))
  7194. " "))
  7195. (setq org-agenda-redo-command
  7196. (list 'org-search-view
  7197. (car (get-text-property (min (1- (point-max)) (point))
  7198. 'org-last-args))
  7199. org-agenda-query-string
  7200. (+ (length org-agenda-query-string)
  7201. (if (member char '(?\{ ?\})) 0 1))))
  7202. (set-register org-agenda-query-register org-agenda-query-string)
  7203. (let ((org-agenda-overriding-arguments
  7204. (cdr org-agenda-redo-command)))
  7205. (org-agenda-redo)))
  7206. (t (error "Cannot manipulate query for %s-type agenda buffers"
  7207. org-agenda-type))))
  7208. (defun org-add-to-string (var string)
  7209. (set var (concat (symbol-value var) string)))
  7210. (defun org-agenda-goto-date (span)
  7211. "Jump to DATE in agenda."
  7212. (interactive "P")
  7213. (let* ((org-read-date-prefer-future
  7214. (eval org-agenda-jump-prefer-future))
  7215. (date (org-read-date))
  7216. (day (time-to-days (org-time-string-to-time date)))
  7217. (org-agenda-sticky-orig org-agenda-sticky)
  7218. (org-agenda-buffer-tmp-name (buffer-name))
  7219. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7220. (0-arg (or current-prefix-arg (car args)))
  7221. (2-arg (nth 2 args))
  7222. (with-hour-p (nth 4 org-agenda-redo-command))
  7223. (newcmd (list 'org-agenda-list 0-arg date
  7224. (org-agenda-span-to-ndays
  7225. 2-arg (org-time-string-to-absolute date))
  7226. with-hour-p))
  7227. (newargs (cdr newcmd))
  7228. (inhibit-read-only t)
  7229. org-agenda-sticky)
  7230. (if (not (org-agenda-check-type t 'agenda))
  7231. (error "Not available in non-agenda views")
  7232. (add-text-properties (point-min) (point-max)
  7233. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  7234. (org-agenda-redo)
  7235. (goto-char (point-min))
  7236. (while (not (or (= (or (get-text-property (point) 'day) 0) day)
  7237. (save-excursion (move-beginning-of-line 2) (eobp))))
  7238. (move-beginning-of-line 2))
  7239. (setq org-agenda-sticky org-agenda-sticky-orig
  7240. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  7241. (defun org-agenda-goto-today ()
  7242. "Go to today."
  7243. (interactive)
  7244. (org-agenda-check-type t 'timeline 'agenda)
  7245. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7246. (curspan (nth 2 args))
  7247. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  7248. (cond
  7249. (tdpos (goto-char tdpos))
  7250. ((eq org-agenda-type 'agenda)
  7251. (let* ((sd (org-agenda-compute-starting-span
  7252. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  7253. (org-agenda-overriding-arguments args))
  7254. (setf (nth 1 org-agenda-overriding-arguments) sd)
  7255. (org-agenda-redo)
  7256. (org-agenda-find-same-or-today-or-agenda)))
  7257. (t (error "Cannot find today")))))
  7258. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  7259. (goto-char
  7260. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  7261. (text-property-any (point-min) (point-max) 'org-today t)
  7262. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  7263. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  7264. (org-agenda-goto-block-beginning))
  7265. (point-min))))
  7266. (defun org-agenda-goto-block-beginning ()
  7267. "Go the agenda block beginning."
  7268. (interactive)
  7269. (if (not (derived-mode-p 'org-agenda-mode))
  7270. (error "Cannot execute this command outside of org-agenda-mode buffers")
  7271. (let (dest)
  7272. (save-excursion
  7273. (unless (looking-at "\\'")
  7274. (forward-char))
  7275. (let* ((prop 'org-agenda-structural-header)
  7276. (p (previous-single-property-change (point) prop))
  7277. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  7278. (1- (point))) prop)))
  7279. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  7280. (if (not dest)
  7281. (error "Cannot find the beginning of the blog")
  7282. (goto-char dest)
  7283. (move-beginning-of-line 1)))))
  7284. (defun org-agenda-later (arg)
  7285. "Go forward in time by the current span.
  7286. With prefix ARG, go forward that many times the current span."
  7287. (interactive "p")
  7288. (org-agenda-check-type t 'agenda)
  7289. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7290. (span (or (nth 2 args) org-agenda-current-span))
  7291. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  7292. (greg (calendar-gregorian-from-absolute sd))
  7293. (cnt (org-get-at-bol 'org-day-cnt))
  7294. greg2)
  7295. (cond
  7296. ((numberp span)
  7297. (setq sd (+ (* span arg) sd)))
  7298. ((eq span 'day)
  7299. (setq sd (+ arg sd)))
  7300. ((eq span 'week)
  7301. (setq sd (+ (* 7 arg) sd)))
  7302. ((eq span 'fortnight)
  7303. (setq sd (+ (* 14 arg) sd)))
  7304. ((eq span 'month)
  7305. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  7306. sd (calendar-absolute-from-gregorian greg2))
  7307. (setcar greg2 (1+ (car greg2))))
  7308. ((eq span 'year)
  7309. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  7310. sd (calendar-absolute-from-gregorian greg2))
  7311. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  7312. (t
  7313. (setq sd (+ (* span arg) sd))))
  7314. (let ((org-agenda-overriding-cmd
  7315. ;; `cmd' may have been set by `org-agenda-run-series' which
  7316. ;; uses `org-agenda-overriding-cmd' to decide whether
  7317. ;; overriding is allowed for `cmd'
  7318. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7319. (org-agenda-overriding-arguments
  7320. (list (car args) sd span)))
  7321. (org-agenda-redo)
  7322. (org-agenda-find-same-or-today-or-agenda cnt))))
  7323. (defun org-agenda-earlier (arg)
  7324. "Go backward in time by the current span.
  7325. With prefix ARG, go backward that many times the current span."
  7326. (interactive "p")
  7327. (org-agenda-later (- arg)))
  7328. (defun org-agenda-view-mode-dispatch ()
  7329. "Call one of the view mode commands."
  7330. (interactive)
  7331. (message "View: [d]ay [w]eek for[t]night [m]onth [y]ear [SPC]reset [q]uit/abort
  7332. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  7333. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  7334. (let ((a (read-char-exclusive)))
  7335. (case a
  7336. (?\ (call-interactively 'org-agenda-reset-view))
  7337. (?d (call-interactively 'org-agenda-day-view))
  7338. (?w (call-interactively 'org-agenda-week-view))
  7339. (?t (call-interactively 'org-agenda-fortnight-view))
  7340. (?m (call-interactively 'org-agenda-month-view))
  7341. (?y (call-interactively 'org-agenda-year-view))
  7342. (?l (call-interactively 'org-agenda-log-mode))
  7343. (?L (org-agenda-log-mode '(4)))
  7344. (?c (org-agenda-log-mode 'clockcheck))
  7345. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  7346. (?a (call-interactively 'org-agenda-archives-mode))
  7347. (?A (org-agenda-archives-mode 'files))
  7348. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  7349. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  7350. (?G (call-interactively 'org-agenda-toggle-time-grid))
  7351. (?D (call-interactively 'org-agenda-toggle-diary))
  7352. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  7353. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  7354. (org-agenda-check-type t 'timeline 'agenda)
  7355. (org-agenda-redo))
  7356. (message "Display now includes inactive timestamps as well"))
  7357. (?q (message "Abort"))
  7358. (otherwise (error "Invalid key" )))))
  7359. (defun org-agenda-reset-view ()
  7360. "Switch to default view for agenda."
  7361. (interactive)
  7362. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  7363. (defun org-agenda-day-view (&optional day-of-month)
  7364. "Switch to daily view for agenda.
  7365. With argument DAY-OF-MONTH, switch to that day of the month."
  7366. (interactive "P")
  7367. (org-agenda-change-time-span 'day day-of-month))
  7368. (defun org-agenda-week-view (&optional iso-week)
  7369. "Switch to daily view for agenda.
  7370. With argument ISO-WEEK, switch to the corresponding ISO week.
  7371. If ISO-WEEK has more then 2 digits, only the last two encode the
  7372. week. Any digits before this encode a year. So 200712 means
  7373. week 12 of year 2007. Years in the range 1938-2037 can also be
  7374. written as 2-digit years."
  7375. (interactive "P")
  7376. (org-agenda-change-time-span 'week iso-week))
  7377. (defun org-agenda-fortnight-view (&optional iso-week)
  7378. "Switch to daily view for agenda.
  7379. With argument ISO-WEEK, switch to the corresponding ISO week.
  7380. If ISO-WEEK has more then 2 digits, only the last two encode the
  7381. week. Any digits before this encode a year. So 200712 means
  7382. week 12 of year 2007. Years in the range 1938-2037 can also be
  7383. written as 2-digit years."
  7384. (interactive "P")
  7385. (org-agenda-change-time-span 'fortnight iso-week))
  7386. (defun org-agenda-month-view (&optional month)
  7387. "Switch to monthly view for agenda.
  7388. With argument MONTH, switch to that month."
  7389. (interactive "P")
  7390. (org-agenda-change-time-span 'month month))
  7391. (defun org-agenda-year-view (&optional year)
  7392. "Switch to yearly view for agenda.
  7393. With argument YEAR, switch to that year.
  7394. If MONTH has more then 2 digits, only the last two encode the
  7395. month. Any digits before this encode a year. So 200712 means
  7396. December year 2007. Years in the range 1938-2037 can also be
  7397. written as 2-digit years."
  7398. (interactive "P")
  7399. (when year
  7400. (setq year (org-small-year-to-year year)))
  7401. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  7402. (org-agenda-change-time-span 'year year)
  7403. (error "Abort")))
  7404. (defun org-agenda-change-time-span (span &optional n)
  7405. "Change the agenda view to SPAN.
  7406. SPAN may be `day', `week', `fortnight', `month', `year'."
  7407. (org-agenda-check-type t 'agenda)
  7408. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  7409. (curspan (nth 2 args)))
  7410. (if (and (not n) (equal curspan span))
  7411. (error "Viewing span is already \"%s\"" span))
  7412. (let* ((sd (or (org-get-at-bol 'day)
  7413. (nth 1 args)
  7414. org-starting-day))
  7415. (sd (org-agenda-compute-starting-span sd span n))
  7416. (org-agenda-overriding-cmd
  7417. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  7418. (org-agenda-overriding-arguments
  7419. (list (car args) sd span)))
  7420. (org-agenda-redo)
  7421. (org-agenda-find-same-or-today-or-agenda))
  7422. (org-agenda-set-mode-name)
  7423. (message "Switched to %s view" span)))
  7424. (defun org-agenda-compute-starting-span (sd span &optional n)
  7425. "Compute starting date for agenda.
  7426. SPAN may be `day', `week', `fortnight', `month', `year'. The return value
  7427. is a cons cell with the starting date and the number of days,
  7428. so that the date SD will be in that range."
  7429. (let* ((greg (calendar-gregorian-from-absolute sd))
  7430. (dg (nth 1 greg))
  7431. (mg (car greg))
  7432. (yg (nth 2 greg)))
  7433. (cond
  7434. ((eq span 'day)
  7435. (when n
  7436. (setq sd (+ (calendar-absolute-from-gregorian
  7437. (list mg 1 yg))
  7438. n -1))))
  7439. ((or (eq span 'week) (eq span 'fortnight))
  7440. (let* ((nt (calendar-day-of-week
  7441. (calendar-gregorian-from-absolute sd)))
  7442. (d (if org-agenda-start-on-weekday
  7443. (- nt org-agenda-start-on-weekday)
  7444. 0))
  7445. y1)
  7446. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  7447. (when n
  7448. (require 'cal-iso)
  7449. (when (> n 99)
  7450. (setq y1 (org-small-year-to-year (/ n 100))
  7451. n (mod n 100)))
  7452. (setq sd
  7453. (calendar-absolute-from-iso
  7454. (list n 1
  7455. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  7456. ((eq span 'month)
  7457. (let (y1)
  7458. (when (and n (> n 99))
  7459. (setq y1 (org-small-year-to-year (/ n 100))
  7460. n (mod n 100)))
  7461. (setq sd (calendar-absolute-from-gregorian
  7462. (list (or n mg) 1 (or y1 yg))))))
  7463. ((eq span 'year)
  7464. (setq sd (calendar-absolute-from-gregorian
  7465. (list 1 1 (or n yg))))))
  7466. sd))
  7467. (defun org-agenda-next-date-line (&optional arg)
  7468. "Jump to the next line indicating a date in agenda buffer."
  7469. (interactive "p")
  7470. (org-agenda-check-type t 'agenda 'timeline)
  7471. (beginning-of-line 1)
  7472. ;; This does not work if user makes date format that starts with a blank
  7473. (if (looking-at "^\\S-") (forward-char 1))
  7474. (if (not (re-search-forward "^\\S-" nil t arg))
  7475. (progn
  7476. (backward-char 1)
  7477. (error "No next date after this line in this buffer")))
  7478. (goto-char (match-beginning 0)))
  7479. (defun org-agenda-previous-date-line (&optional arg)
  7480. "Jump to the previous line indicating a date in agenda buffer."
  7481. (interactive "p")
  7482. (org-agenda-check-type t 'agenda 'timeline)
  7483. (beginning-of-line 1)
  7484. (if (not (re-search-backward "^\\S-" nil t arg))
  7485. (error "No previous date before this line in this buffer")))
  7486. ;; Initialize the highlight
  7487. (defvar org-hl (make-overlay 1 1))
  7488. (overlay-put org-hl 'face 'highlight)
  7489. (defun org-highlight (begin end &optional buffer)
  7490. "Highlight a region with overlay."
  7491. (move-overlay org-hl begin end (or buffer (current-buffer))))
  7492. (defun org-unhighlight ()
  7493. "Detach overlay INDEX."
  7494. (org-detach-overlay org-hl))
  7495. (defun org-unhighlight-once ()
  7496. "Remove the highlight from its position, and this function from the hook."
  7497. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  7498. (org-unhighlight))
  7499. (defvar org-agenda-pre-follow-window-conf nil)
  7500. (defun org-agenda-follow-mode ()
  7501. "Toggle follow mode in an agenda buffer."
  7502. (interactive)
  7503. (unless org-agenda-follow-mode
  7504. (setq org-agenda-pre-follow-window-conf
  7505. (current-window-configuration)))
  7506. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  7507. (unless org-agenda-follow-mode
  7508. (set-window-configuration org-agenda-pre-follow-window-conf))
  7509. (org-agenda-set-mode-name)
  7510. (org-agenda-do-context-action)
  7511. (message "Follow mode is %s"
  7512. (if org-agenda-follow-mode "on" "off")))
  7513. (defun org-agenda-entry-text-mode (&optional arg)
  7514. "Toggle entry text mode in an agenda buffer."
  7515. (interactive "P")
  7516. (if (or org-agenda-tag-filter
  7517. org-agenda-category-filter
  7518. org-agenda-regexp-filter
  7519. org-agenda-top-headline-filter)
  7520. (user-error "Can't show entry text in filtered views")
  7521. (setq org-agenda-entry-text-mode (or (integerp arg)
  7522. (not org-agenda-entry-text-mode)))
  7523. (org-agenda-entry-text-hide)
  7524. (and org-agenda-entry-text-mode
  7525. (let ((org-agenda-entry-text-maxlines
  7526. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7527. (org-agenda-entry-text-show)))
  7528. (org-agenda-set-mode-name)
  7529. (message "Entry text mode is %s%s"
  7530. (if org-agenda-entry-text-mode "on" "off")
  7531. (if (not org-agenda-entry-text-mode) ""
  7532. (format " (maximum number of lines is %d)"
  7533. (if (integerp arg) arg org-agenda-entry-text-maxlines))))))
  7534. (defun org-agenda-clockreport-mode ()
  7535. "Toggle clocktable mode in an agenda buffer."
  7536. (interactive)
  7537. (org-agenda-check-type t 'agenda)
  7538. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  7539. (setq org-agenda-start-with-clockreport-mode org-agenda-clockreport-mode)
  7540. (org-agenda-set-mode-name)
  7541. (org-agenda-redo)
  7542. (message "Clocktable mode is %s"
  7543. (if org-agenda-clockreport-mode "on" "off")))
  7544. (defun org-agenda-log-mode (&optional special)
  7545. "Toggle log mode in an agenda buffer.
  7546. With argument SPECIAL, show all possible log items, not only the ones
  7547. configured in `org-agenda-log-mode-items'.
  7548. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7549. (interactive "P")
  7550. (org-agenda-check-type t 'agenda 'timeline)
  7551. (setq org-agenda-show-log
  7552. (cond
  7553. ((equal special '(16)) 'only)
  7554. ((eq special 'clockcheck)
  7555. (if (eq org-agenda-show-log 'clockcheck)
  7556. nil 'clockcheck))
  7557. (special '(closed clock state))
  7558. (t (not org-agenda-show-log))))
  7559. (setq org-agenda-start-with-log-mode org-agenda-show-log)
  7560. (org-agenda-set-mode-name)
  7561. (org-agenda-redo)
  7562. (message "Log mode is %s"
  7563. (if org-agenda-show-log "on" "off")))
  7564. (defun org-agenda-archives-mode (&optional with-files)
  7565. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7566. When called with a prefix argument, include all archive files as well."
  7567. (interactive "P")
  7568. (setq org-agenda-archives-mode
  7569. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7570. (org-agenda-set-mode-name)
  7571. (org-agenda-redo)
  7572. (message
  7573. "%s"
  7574. (cond
  7575. ((eq org-agenda-archives-mode nil)
  7576. "No archives are included")
  7577. ((eq org-agenda-archives-mode 'trees)
  7578. (format "Trees with :%s: tag are included" org-archive-tag))
  7579. ((eq org-agenda-archives-mode t)
  7580. (format "Trees with :%s: tag and all active archive files are included"
  7581. org-archive-tag)))))
  7582. (defun org-agenda-toggle-diary ()
  7583. "Toggle diary inclusion in an agenda buffer."
  7584. (interactive)
  7585. (org-agenda-check-type t 'agenda)
  7586. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7587. (org-agenda-redo)
  7588. (org-agenda-set-mode-name)
  7589. (message "Diary inclusion turned %s"
  7590. (if org-agenda-include-diary "on" "off")))
  7591. (defun org-agenda-toggle-deadlines ()
  7592. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7593. (interactive)
  7594. (org-agenda-check-type t 'agenda)
  7595. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7596. (org-agenda-redo)
  7597. (org-agenda-set-mode-name)
  7598. (message "Deadlines inclusion turned %s"
  7599. (if org-agenda-include-deadlines "on" "off")))
  7600. (defun org-agenda-toggle-time-grid ()
  7601. "Toggle time grid in an agenda buffer."
  7602. (interactive)
  7603. (org-agenda-check-type t 'agenda)
  7604. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7605. (org-agenda-redo)
  7606. (org-agenda-set-mode-name)
  7607. (message "Time-grid turned %s"
  7608. (if org-agenda-use-time-grid "on" "off")))
  7609. (defun org-agenda-set-mode-name ()
  7610. "Set the mode name to indicate all the small mode settings."
  7611. (setq mode-name
  7612. (list "Org-Agenda"
  7613. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7614. " "
  7615. '(:eval (org-agenda-span-name org-agenda-current-span))
  7616. (if org-agenda-follow-mode " Follow" "")
  7617. (if org-agenda-entry-text-mode " ETxt" "")
  7618. (if org-agenda-include-diary " Diary" "")
  7619. (if org-agenda-include-deadlines " Ddl" "")
  7620. (if org-agenda-use-time-grid " Grid" "")
  7621. (if (and (boundp 'org-habit-show-habits)
  7622. org-habit-show-habits) " Habit" "")
  7623. (cond
  7624. ((consp org-agenda-show-log) " LogAll")
  7625. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7626. (org-agenda-show-log " Log")
  7627. (t ""))
  7628. (if (or org-agenda-category-filter
  7629. (get 'org-agenda-category-filter :preset-filter))
  7630. '(:eval (org-propertize
  7631. (concat " <"
  7632. (mapconcat
  7633. 'identity
  7634. (append
  7635. (get 'org-agenda-category-filter :preset-filter)
  7636. org-agenda-category-filter)
  7637. "")
  7638. ">")
  7639. 'face 'org-agenda-filter-category
  7640. 'help-echo "Category used in filtering")) "")
  7641. (if (or org-agenda-tag-filter
  7642. (get 'org-agenda-tag-filter :preset-filter))
  7643. '(:eval (org-propertize
  7644. (concat " {"
  7645. (mapconcat
  7646. 'identity
  7647. (append
  7648. (get 'org-agenda-tag-filter :preset-filter)
  7649. org-agenda-tag-filter)
  7650. "")
  7651. "}")
  7652. 'face 'org-agenda-filter-tags
  7653. 'help-echo "Tags used in filtering")) "")
  7654. (if (or org-agenda-regexp-filter
  7655. (get 'org-agenda-regexp-filter :preset-filter))
  7656. '(:eval (org-propertize
  7657. (concat " ["
  7658. (mapconcat
  7659. 'identity
  7660. (append
  7661. (get 'org-agenda-regexp-filter :preset-filter)
  7662. org-agenda-regexp-filter)
  7663. "")
  7664. "]")
  7665. 'face 'org-agenda-filter-regexp
  7666. 'help-echo "Regexp used in filtering")) "")
  7667. (if org-agenda-archives-mode
  7668. (if (eq org-agenda-archives-mode t)
  7669. " Archives"
  7670. (format " :%s:" org-archive-tag))
  7671. "")
  7672. (if org-agenda-clockreport-mode " Clock" "")))
  7673. (force-mode-line-update))
  7674. (define-obsolete-function-alias
  7675. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7676. (defun org-agenda-update-agenda-type ()
  7677. "Update the agenda type after each command."
  7678. (setq org-agenda-type
  7679. (or (get-text-property (point) 'org-agenda-type)
  7680. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7681. (defun org-agenda-next-line ()
  7682. "Move cursor to the next line, and show if follow mode is active."
  7683. (interactive)
  7684. (call-interactively 'next-line)
  7685. (org-agenda-do-context-action))
  7686. (defun org-agenda-previous-line ()
  7687. "Move cursor to the previous line, and show if follow-mode is active."
  7688. (interactive)
  7689. (call-interactively 'previous-line)
  7690. (org-agenda-do-context-action))
  7691. (defun org-agenda-next-item (n)
  7692. "Move cursor to next agenda item."
  7693. (interactive "p")
  7694. (let ((col (current-column)))
  7695. (dotimes (c n)
  7696. (when (next-single-property-change (point-at-eol) 'org-marker)
  7697. (move-end-of-line 1)
  7698. (goto-char (next-single-property-change (point) 'org-marker))))
  7699. (org-move-to-column col))
  7700. (org-agenda-do-context-action))
  7701. (defun org-agenda-previous-item (n)
  7702. "Move cursor to next agenda item."
  7703. (interactive "p")
  7704. (dotimes (c n)
  7705. (let ((col (current-column))
  7706. (goto (save-excursion
  7707. (move-end-of-line 0)
  7708. (previous-single-property-change (point) 'org-marker))))
  7709. (if goto (goto-char goto))
  7710. (org-move-to-column col)))
  7711. (org-agenda-do-context-action))
  7712. (defun org-agenda-do-context-action ()
  7713. "Show outline path and, maybe, follow mode window."
  7714. (let ((m (org-get-at-bol 'org-marker)))
  7715. (when (and (markerp m) (marker-buffer m))
  7716. (and org-agenda-follow-mode
  7717. (if org-agenda-follow-indirect
  7718. (org-agenda-tree-to-indirect-buffer nil)
  7719. (org-agenda-show)))
  7720. (and org-agenda-show-outline-path
  7721. (org-with-point-at m (org-display-outline-path t))))))
  7722. (defun org-agenda-show-tags ()
  7723. "Show the tags applicable to the current item."
  7724. (interactive)
  7725. (let* ((tags (org-get-at-bol 'tags)))
  7726. (if tags
  7727. (message "Tags are :%s:"
  7728. (org-no-properties (mapconcat 'identity tags ":")))
  7729. (message "No tags associated with this line"))))
  7730. (defun org-agenda-goto (&optional highlight)
  7731. "Go to the Org-mode file which contains the item at point."
  7732. (interactive)
  7733. (let* ((marker (or (org-get-at-bol 'org-marker)
  7734. (org-agenda-error)))
  7735. (buffer (marker-buffer marker))
  7736. (pos (marker-position marker)))
  7737. (switch-to-buffer-other-window buffer)
  7738. (widen)
  7739. (push-mark)
  7740. (goto-char pos)
  7741. (when (derived-mode-p 'org-mode)
  7742. (org-show-context 'agenda)
  7743. (save-excursion
  7744. (and (outline-next-heading)
  7745. (org-flag-heading nil)))) ; show the next heading
  7746. (when (outline-invisible-p)
  7747. (show-entry)) ; display invisible text
  7748. (recenter (/ (window-height) 2))
  7749. (run-hooks 'org-agenda-after-show-hook)
  7750. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7751. (defvar org-agenda-after-show-hook nil
  7752. "Normal hook run after an item has been shown from the agenda.
  7753. Point is in the buffer where the item originated.")
  7754. (defun org-agenda-kill ()
  7755. "Kill the entry or subtree belonging to the current agenda entry."
  7756. (interactive)
  7757. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7758. (let* ((bufname-orig (buffer-name))
  7759. (marker (or (org-get-at-bol 'org-marker)
  7760. (org-agenda-error)))
  7761. (buffer (marker-buffer marker))
  7762. (pos (marker-position marker))
  7763. (type (org-get-at-bol 'type))
  7764. dbeg dend (n 0) conf)
  7765. (org-with-remote-undo buffer
  7766. (with-current-buffer buffer
  7767. (save-excursion
  7768. (goto-char pos)
  7769. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7770. (setq dbeg (progn (org-back-to-heading t) (point))
  7771. dend (org-end-of-subtree t t))
  7772. (setq dbeg (point-at-bol)
  7773. dend (min (point-max) (1+ (point-at-eol)))))
  7774. (goto-char dbeg)
  7775. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7776. (setq conf (or (eq t org-agenda-confirm-kill)
  7777. (and (numberp org-agenda-confirm-kill)
  7778. (> n org-agenda-confirm-kill))))
  7779. (and conf
  7780. (not (y-or-n-p
  7781. (format "Delete entry with %d lines in buffer \"%s\"? "
  7782. n (buffer-name buffer))))
  7783. (error "Abort"))
  7784. (let ((org-agenda-buffer-name bufname-orig))
  7785. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7786. (with-current-buffer buffer (delete-region dbeg dend))
  7787. (message "Agenda item and source killed"))))
  7788. (defvar org-archive-default-command) ; defined in org-archive.el
  7789. (defun org-agenda-archive-default ()
  7790. "Archive the entry or subtree belonging to the current agenda entry."
  7791. (interactive)
  7792. (require 'org-archive)
  7793. (org-agenda-archive-with org-archive-default-command))
  7794. (defun org-agenda-archive-default-with-confirmation ()
  7795. "Archive the entry or subtree belonging to the current agenda entry."
  7796. (interactive)
  7797. (require 'org-archive)
  7798. (org-agenda-archive-with org-archive-default-command 'confirm))
  7799. (defun org-agenda-archive ()
  7800. "Archive the entry or subtree belonging to the current agenda entry."
  7801. (interactive)
  7802. (org-agenda-archive-with 'org-archive-subtree))
  7803. (defun org-agenda-archive-to-archive-sibling ()
  7804. "Move the entry to the archive sibling."
  7805. (interactive)
  7806. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7807. (defun org-agenda-archive-with (cmd &optional confirm)
  7808. "Move the entry to the archive sibling."
  7809. (interactive)
  7810. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7811. (let* ((bufname-orig (buffer-name))
  7812. (marker (or (org-get-at-bol 'org-marker)
  7813. (org-agenda-error)))
  7814. (buffer (marker-buffer marker))
  7815. (pos (marker-position marker)))
  7816. (org-with-remote-undo buffer
  7817. (with-current-buffer buffer
  7818. (if (derived-mode-p 'org-mode)
  7819. (if (and confirm
  7820. (not (y-or-n-p "Archive this subtree or entry? ")))
  7821. (error "Abort")
  7822. (save-window-excursion
  7823. (goto-char pos)
  7824. (let ((org-agenda-buffer-name bufname-orig))
  7825. (org-remove-subtree-entries-from-agenda))
  7826. (org-back-to-heading t)
  7827. (funcall cmd)))
  7828. (error "Archiving works only in Org-mode files"))))))
  7829. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7830. "Remove all lines in the agenda that correspond to a given subtree.
  7831. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7832. If this information is not given, the function uses the tree at point."
  7833. (let ((buf (or buf (current-buffer))) m p)
  7834. (save-excursion
  7835. (unless (and beg end)
  7836. (org-back-to-heading t)
  7837. (setq beg (point))
  7838. (org-end-of-subtree t)
  7839. (setq end (point)))
  7840. (set-buffer (get-buffer org-agenda-buffer-name))
  7841. (save-excursion
  7842. (goto-char (point-max))
  7843. (beginning-of-line 1)
  7844. (while (not (bobp))
  7845. (when (and (setq m (org-get-at-bol 'org-marker))
  7846. (equal buf (marker-buffer m))
  7847. (setq p (marker-position m))
  7848. (>= p beg)
  7849. (< p end))
  7850. (let ((inhibit-read-only t))
  7851. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7852. (beginning-of-line 0))))))
  7853. (defun org-agenda-refile (&optional goto rfloc no-update)
  7854. "Refile the item at point.
  7855. When GOTO is 0 or '(64), clear the refile cache.
  7856. When GOTO is '(16), go to the location of the last refiled item.
  7857. RFLOC can be a refile location obtained in a different way.
  7858. When NO-UPDATE is non-nil, don't redo the agenda buffer."
  7859. (interactive "P")
  7860. (cond
  7861. ((member goto '(0 (64)))
  7862. (org-refile-cache-clear))
  7863. ((equal goto '(16))
  7864. (org-refile-goto-last-stored))
  7865. (t
  7866. (let* ((buffer-orig (buffer-name))
  7867. (marker (or (org-get-at-bol 'org-hd-marker)
  7868. (org-agenda-error)))
  7869. (buffer (marker-buffer marker))
  7870. (pos (marker-position marker))
  7871. (rfloc (or rfloc
  7872. (org-refile-get-location
  7873. (if goto "Goto" "Refile to") buffer
  7874. org-refile-allow-creating-parent-nodes))))
  7875. (with-current-buffer buffer
  7876. (save-excursion
  7877. (save-restriction
  7878. (widen)
  7879. (goto-char marker)
  7880. (let ((org-agenda-buffer-name buffer-orig))
  7881. (org-remove-subtree-entries-from-agenda))
  7882. (org-refile goto buffer rfloc)))))
  7883. (unless no-update (org-agenda-redo)))))
  7884. (defun org-agenda-open-link (&optional arg)
  7885. "Open the link(s) in the current entry, if any.
  7886. This looks for a link in the displayed line in the agenda.
  7887. It also looks at the text of the entry itself."
  7888. (interactive "P")
  7889. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7890. (org-get-at-bol 'org-marker)))
  7891. (buffer (and marker (marker-buffer marker)))
  7892. (prefix (buffer-substring (point-at-bol) (point-at-eol)))
  7893. (lkall (and buffer (org-offer-links-in-entry
  7894. buffer marker arg prefix)))
  7895. (lk0 (car lkall))
  7896. (lk (if (stringp lk0) (list lk0) lk0))
  7897. (lkend (cdr lkall))
  7898. trg)
  7899. (cond
  7900. ((and buffer lk)
  7901. (mapcar (lambda(l)
  7902. (with-current-buffer buffer
  7903. (setq trg (and (string-match org-bracket-link-regexp l)
  7904. (match-string 1 l)))
  7905. (if (or (not trg) (string-match org-any-link-re trg))
  7906. (save-excursion
  7907. (save-restriction
  7908. (widen)
  7909. (goto-char marker)
  7910. (when (search-forward l nil lkend)
  7911. (goto-char (match-beginning 0))
  7912. (org-open-at-point))))
  7913. ;; This is an internal link, widen the buffer
  7914. (switch-to-buffer-other-window buffer)
  7915. (widen)
  7916. (goto-char marker)
  7917. (when (search-forward l nil lkend)
  7918. (goto-char (match-beginning 0))
  7919. (org-open-at-point)))))
  7920. lk))
  7921. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7922. (save-excursion
  7923. (beginning-of-line 1)
  7924. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7925. (org-open-link-from-string (match-string 1)))
  7926. (t (message "No link to open here")))))
  7927. (defun org-agenda-copy-local-variable (var)
  7928. "Get a variable from a referenced buffer and install it here."
  7929. (let ((m (org-get-at-bol 'org-marker)))
  7930. (when (and m (buffer-live-p (marker-buffer m)))
  7931. (org-set-local var (with-current-buffer (marker-buffer m)
  7932. (symbol-value var))))))
  7933. (defun org-agenda-switch-to (&optional delete-other-windows)
  7934. "Go to the Org-mode file which contains the item at point."
  7935. (interactive)
  7936. (if (and org-return-follows-link
  7937. (not (org-get-at-bol 'org-marker))
  7938. (org-in-regexp org-bracket-link-regexp))
  7939. (org-open-link-from-string (match-string 0))
  7940. (let* ((marker (or (org-get-at-bol 'org-marker)
  7941. (org-agenda-error)))
  7942. (buffer (marker-buffer marker))
  7943. (pos (marker-position marker)))
  7944. (org-pop-to-buffer-same-window buffer)
  7945. (and delete-other-windows (delete-other-windows))
  7946. (widen)
  7947. (goto-char pos)
  7948. (when (derived-mode-p 'org-mode)
  7949. (org-show-context 'agenda)
  7950. (save-excursion
  7951. (and (outline-next-heading)
  7952. (org-flag-heading nil))) ; show the next heading
  7953. (when (outline-invisible-p)
  7954. (show-entry)) ; display invisible text
  7955. (run-hooks 'org-agenda-after-show-hook)))))
  7956. (defun org-agenda-goto-mouse (ev)
  7957. "Go to the Org-mode file which contains the item at the mouse click."
  7958. (interactive "e")
  7959. (mouse-set-point ev)
  7960. (org-agenda-goto))
  7961. (defun org-agenda-show (&optional full-entry)
  7962. "Display the Org-mode file which contains the item at point.
  7963. With prefix argument FULL-ENTRY, make the entire entry visible
  7964. if it was hidden in the outline."
  7965. (interactive "P")
  7966. (let ((win (selected-window)))
  7967. (if full-entry
  7968. (let ((org-show-entry-below t))
  7969. (org-agenda-goto t))
  7970. (org-agenda-goto t))
  7971. (select-window win)))
  7972. (defvar org-agenda-show-window nil)
  7973. (defun org-agenda-show-and-scroll-up (&optional arg)
  7974. "Display the Org-mode file which contains the item at point.
  7975. When called repeatedly, scroll the window that is displaying the buffer.
  7976. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7977. `show-subtree' to display the item, so that drawers and logbooks stay
  7978. folded."
  7979. (interactive "P")
  7980. (let ((win (selected-window)))
  7981. (if (and (window-live-p org-agenda-show-window)
  7982. (eq this-command last-command))
  7983. (progn
  7984. (select-window org-agenda-show-window)
  7985. (ignore-errors (scroll-up)))
  7986. (org-agenda-goto t)
  7987. (if arg (org-show-entry) (show-subtree))
  7988. (setq org-agenda-show-window (selected-window)))
  7989. (select-window win)))
  7990. (defun org-agenda-show-scroll-down ()
  7991. "Scroll down the window showing the agenda."
  7992. (interactive)
  7993. (let ((win (selected-window)))
  7994. (when (window-live-p org-agenda-show-window)
  7995. (select-window org-agenda-show-window)
  7996. (ignore-errors (scroll-down))
  7997. (select-window win))))
  7998. (defun org-agenda-show-1 (&optional more)
  7999. "Display the Org-mode file which contains the item at point.
  8000. The prefix arg selects the amount of information to display:
  8001. 0 hide the subtree
  8002. 1 just show the entry according to defaults.
  8003. 2 show the children view
  8004. 3 show the subtree view
  8005. 4 show the entire subtree and any LOGBOOK drawers
  8006. 5 show the entire subtree and any drawers
  8007. With prefix argument FULL-ENTRY, make the entire entry visible
  8008. if it was hidden in the outline."
  8009. (interactive "p")
  8010. (let ((win (selected-window)))
  8011. (org-agenda-goto t)
  8012. (org-back-to-heading)
  8013. (set-window-start (selected-window) (point-at-bol))
  8014. (cond
  8015. ((= more 0)
  8016. (hide-subtree)
  8017. (save-excursion
  8018. (org-back-to-heading)
  8019. (run-hook-with-args 'org-cycle-hook 'folded))
  8020. (message "Remote: FOLDED"))
  8021. ((and (org-called-interactively-p 'any) (= more 1))
  8022. (message "Remote: show with default settings"))
  8023. ((= more 2)
  8024. (show-entry)
  8025. (show-children)
  8026. (save-excursion
  8027. (org-back-to-heading)
  8028. (run-hook-with-args 'org-cycle-hook 'children))
  8029. (message "Remote: CHILDREN"))
  8030. ((= more 3)
  8031. (show-subtree)
  8032. (save-excursion
  8033. (org-back-to-heading)
  8034. (run-hook-with-args 'org-cycle-hook 'subtree))
  8035. (message "Remote: SUBTREE"))
  8036. ((= more 4)
  8037. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  8038. (org-drawer-regexp
  8039. (concat "^[ \t]*:\\("
  8040. (mapconcat 'regexp-quote org-drawers "\\|")
  8041. "\\):[ \t]*$")))
  8042. (show-subtree)
  8043. (save-excursion
  8044. (org-back-to-heading)
  8045. (org-cycle-hide-drawers 'subtree)))
  8046. (message "Remote: SUBTREE AND LOGBOOK"))
  8047. ((> more 4)
  8048. (show-subtree)
  8049. (message "Remote: SUBTREE AND ALL DRAWERS")))
  8050. (select-window win)))
  8051. (defvar org-agenda-cycle-counter nil)
  8052. (defun org-agenda-cycle-show (&optional n)
  8053. "Show the current entry in another window, with default settings.
  8054. Default settings are taken from `org-show-hierarchy-above' and siblings.
  8055. When use repeatedly in immediate succession, the remote entry will cycle
  8056. through visibility
  8057. children -> subtree -> folded
  8058. When called with a numeric prefix arg, that arg will be passed through to
  8059. `org-agenda-show-1'. For the interpretation of that argument, see the
  8060. docstring of `org-agenda-show-1'."
  8061. (interactive "P")
  8062. (if (integerp n)
  8063. (setq org-agenda-cycle-counter n)
  8064. (if (not (eq last-command this-command))
  8065. (setq org-agenda-cycle-counter 1)
  8066. (if (equal org-agenda-cycle-counter 0)
  8067. (setq org-agenda-cycle-counter 2)
  8068. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  8069. (if (> org-agenda-cycle-counter 3)
  8070. (setq org-agenda-cycle-counter 0)))))
  8071. (org-agenda-show-1 org-agenda-cycle-counter))
  8072. (defun org-agenda-recenter (arg)
  8073. "Display the Org-mode file which contains the item at point and recenter."
  8074. (interactive "P")
  8075. (let ((win (selected-window)))
  8076. (org-agenda-goto t)
  8077. (recenter arg)
  8078. (select-window win)))
  8079. (defun org-agenda-show-mouse (ev)
  8080. "Display the Org-mode file which contains the item at the mouse click."
  8081. (interactive "e")
  8082. (mouse-set-point ev)
  8083. (org-agenda-show))
  8084. (defun org-agenda-check-no-diary ()
  8085. "Check if the entry is a diary link and abort if yes."
  8086. (if (org-get-at-bol 'org-agenda-diary-link)
  8087. (org-agenda-error)))
  8088. (defun org-agenda-error ()
  8089. (error "Command not allowed in this line"))
  8090. (defun org-agenda-tree-to-indirect-buffer (arg)
  8091. "Show the subtree corresponding to the current entry in an indirect buffer.
  8092. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  8093. With a numerical prefix ARG, go up to this level and then take that tree.
  8094. With a negative numeric ARG, go up by this number of levels.
  8095. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  8096. use the dedicated frame)."
  8097. (interactive "P")
  8098. (if current-prefix-arg
  8099. (org-agenda-do-tree-to-indirect-buffer arg)
  8100. (let ((agenda-buffer (buffer-name))
  8101. (agenda-window (selected-window))
  8102. (indirect-window
  8103. (and org-last-indirect-buffer
  8104. (get-buffer-window org-last-indirect-buffer))))
  8105. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  8106. (unless (or (eq org-indirect-buffer-display 'new-frame)
  8107. (eq org-indirect-buffer-display 'dedicated-frame))
  8108. (unwind-protect
  8109. (unless (and indirect-window (window-live-p indirect-window))
  8110. (setq indirect-window (split-window agenda-window)))
  8111. (and indirect-window (select-window indirect-window))
  8112. (switch-to-buffer org-last-indirect-buffer :norecord)
  8113. (fit-window-to-buffer indirect-window)))
  8114. (select-window (get-buffer-window agenda-buffer)))))
  8115. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  8116. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  8117. (org-agenda-check-no-diary)
  8118. (let* ((marker (or (org-get-at-bol 'org-marker)
  8119. (org-agenda-error)))
  8120. (buffer (marker-buffer marker))
  8121. (pos (marker-position marker)))
  8122. (with-current-buffer buffer
  8123. (save-excursion
  8124. (goto-char pos)
  8125. (funcall 'org-tree-to-indirect-buffer arg)))))
  8126. (defvar org-last-heading-marker (make-marker)
  8127. "Marker pointing to the headline that last changed its TODO state
  8128. by a remote command from the agenda.")
  8129. (defun org-agenda-todo-nextset ()
  8130. "Switch TODO entry to next sequence."
  8131. (interactive)
  8132. (org-agenda-todo 'nextset))
  8133. (defun org-agenda-todo-previousset ()
  8134. "Switch TODO entry to previous sequence."
  8135. (interactive)
  8136. (org-agenda-todo 'previousset))
  8137. (defun org-agenda-todo (&optional arg)
  8138. "Cycle TODO state of line at point, also in Org-mode file.
  8139. This changes the line at point, all other lines in the agenda referring to
  8140. the same tree node, and the headline of the tree node in the Org-mode file."
  8141. (interactive "P")
  8142. (org-agenda-check-no-diary)
  8143. (let* ((col (current-column))
  8144. (marker (or (org-get-at-bol 'org-marker)
  8145. (org-agenda-error)))
  8146. (buffer (marker-buffer marker))
  8147. (pos (marker-position marker))
  8148. (hdmarker (org-get-at-bol 'org-hd-marker))
  8149. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  8150. (inhibit-read-only t)
  8151. org-agenda-headline-snapshot-before-repeat newhead just-one)
  8152. (org-with-remote-undo buffer
  8153. (with-current-buffer buffer
  8154. (widen)
  8155. (goto-char pos)
  8156. (org-show-context 'agenda)
  8157. (save-excursion
  8158. (and (outline-next-heading)
  8159. (org-flag-heading nil))) ; show the next heading
  8160. (let ((current-prefix-arg arg))
  8161. (call-interactively 'org-todo))
  8162. (and (bolp) (forward-char 1))
  8163. (setq newhead (org-get-heading))
  8164. (when (and (org-bound-and-true-p
  8165. org-agenda-headline-snapshot-before-repeat)
  8166. (not (equal org-agenda-headline-snapshot-before-repeat
  8167. newhead))
  8168. todayp)
  8169. (setq newhead org-agenda-headline-snapshot-before-repeat
  8170. just-one t))
  8171. (save-excursion
  8172. (org-back-to-heading)
  8173. (move-marker org-last-heading-marker (point))))
  8174. (beginning-of-line 1)
  8175. (save-window-excursion
  8176. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  8177. (when (org-bound-and-true-p org-clock-out-when-done)
  8178. (string-match (concat "^" (regexp-opt org-done-keywords-for-agenda))
  8179. newhead)
  8180. (org-agenda-unmark-clocking-task))
  8181. (org-move-to-column col))))
  8182. (defun org-agenda-add-note (&optional arg)
  8183. "Add a time-stamped note to the entry at point."
  8184. (interactive "P")
  8185. (org-agenda-check-no-diary)
  8186. (let* ((marker (or (org-get-at-bol 'org-marker)
  8187. (org-agenda-error)))
  8188. (buffer (marker-buffer marker))
  8189. (pos (marker-position marker))
  8190. (hdmarker (org-get-at-bol 'org-hd-marker))
  8191. (inhibit-read-only t))
  8192. (with-current-buffer buffer
  8193. (widen)
  8194. (goto-char pos)
  8195. (org-show-context 'agenda)
  8196. (save-excursion
  8197. (and (outline-next-heading)
  8198. (org-flag-heading nil))) ; show the next heading
  8199. (org-add-note))))
  8200. (defun org-agenda-change-all-lines (newhead hdmarker
  8201. &optional fixface just-this)
  8202. "Change all lines in the agenda buffer which match HDMARKER.
  8203. The new content of the line will be NEWHEAD (as modified by
  8204. `org-agenda-format-item'). HDMARKER is checked with
  8205. `equal' against all `org-hd-marker' text properties in the file.
  8206. If FIXFACE is non-nil, the face of each item is modified according to
  8207. the new TODO state.
  8208. If JUST-THIS is non-nil, change just the current line, not all.
  8209. If FORCE-TAGS is non nil, the car of it returns the new tags."
  8210. (let* ((inhibit-read-only t)
  8211. (line (org-current-line))
  8212. (org-agenda-buffer (current-buffer))
  8213. (thetags (with-current-buffer (marker-buffer hdmarker)
  8214. (save-excursion (save-restriction (widen)
  8215. (goto-char hdmarker)
  8216. (org-get-tags-at)))))
  8217. props m pl undone-face done-face finish new dotime level cat tags)
  8218. (save-excursion
  8219. (goto-char (point-max))
  8220. (beginning-of-line 1)
  8221. (while (not finish)
  8222. (setq finish (bobp))
  8223. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  8224. (or (not just-this) (= (org-current-line) line))
  8225. (equal m hdmarker))
  8226. (setq props (text-properties-at (point))
  8227. dotime (org-get-at-bol 'dotime)
  8228. cat (org-get-at-bol 'org-category)
  8229. level (org-get-at-bol 'level)
  8230. tags thetags
  8231. new
  8232. (let ((org-prefix-format-compiled
  8233. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  8234. org-prefix-format-compiled))
  8235. (extra (org-get-at-bol 'extra)))
  8236. (with-current-buffer (marker-buffer hdmarker)
  8237. (save-excursion
  8238. (save-restriction
  8239. (widen)
  8240. (org-agenda-format-item extra newhead level cat tags dotime)))))
  8241. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  8242. undone-face (org-get-at-bol 'undone-face)
  8243. done-face (org-get-at-bol 'done-face))
  8244. (beginning-of-line 1)
  8245. (cond
  8246. ((equal new "")
  8247. (and (looking-at ".*\n?") (replace-match "")))
  8248. ((looking-at ".*")
  8249. (replace-match new t t)
  8250. (beginning-of-line 1)
  8251. (add-text-properties (point-at-bol) (point-at-eol) props)
  8252. (when fixface
  8253. (add-text-properties
  8254. (point-at-bol) (point-at-eol)
  8255. (list 'face
  8256. (if org-last-todo-state-is-todo
  8257. undone-face done-face))))
  8258. (org-agenda-highlight-todo 'line)
  8259. (beginning-of-line 1))
  8260. (t (error "Line update did not work")))
  8261. (save-restriction
  8262. (narrow-to-region (point-at-bol) (point-at-eol))
  8263. (org-agenda-finalize)))
  8264. (beginning-of-line 0)))))
  8265. (defun org-agenda-align-tags (&optional line)
  8266. "Align all tags in agenda items to `org-agenda-tags-column'."
  8267. (let ((inhibit-read-only t) l c)
  8268. (save-excursion
  8269. (goto-char (if line (point-at-bol) (point-min)))
  8270. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  8271. (if line (point-at-eol) nil) t)
  8272. (add-text-properties
  8273. (match-beginning 2) (match-end 2)
  8274. (list 'face (delq nil (let ((prop (get-text-property
  8275. (match-beginning 2) 'face)))
  8276. (or (listp prop) (setq prop (list prop)))
  8277. (if (memq 'org-tag prop)
  8278. prop
  8279. (cons 'org-tag prop))))))
  8280. (setq l (- (match-end 2) (match-beginning 2))
  8281. c (if (< org-agenda-tags-column 0)
  8282. (- (abs org-agenda-tags-column) l)
  8283. org-agenda-tags-column))
  8284. (delete-region (match-beginning 1) (match-end 1))
  8285. (goto-char (match-beginning 1))
  8286. (insert (org-add-props
  8287. (make-string (max 1 (- c (current-column))) ?\ )
  8288. (plist-put (copy-sequence (text-properties-at (point)))
  8289. 'face nil))))
  8290. (goto-char (point-min))
  8291. (org-font-lock-add-tag-faces (point-max)))))
  8292. (defun org-agenda-priority-up ()
  8293. "Increase the priority of line at point, also in Org-mode file."
  8294. (interactive)
  8295. (org-agenda-priority 'up))
  8296. (defun org-agenda-priority-down ()
  8297. "Decrease the priority of line at point, also in Org-mode file."
  8298. (interactive)
  8299. (org-agenda-priority 'down))
  8300. (defun org-agenda-priority (&optional force-direction)
  8301. "Set the priority of line at point, also in Org-mode file.
  8302. This changes the line at point, all other lines in the agenda referring to
  8303. the same tree node, and the headline of the tree node in the Org-mode file.
  8304. Called with a universal prefix arg, show the priority instead of setting it."
  8305. (interactive "P")
  8306. (if (equal force-direction '(4))
  8307. (org-show-priority)
  8308. (unless org-enable-priority-commands
  8309. (error "Priority commands are disabled"))
  8310. (org-agenda-check-no-diary)
  8311. (let* ((col (current-column))
  8312. (marker (or (org-get-at-bol 'org-marker)
  8313. (org-agenda-error)))
  8314. (hdmarker (org-get-at-bol 'org-hd-marker))
  8315. (buffer (marker-buffer hdmarker))
  8316. (pos (marker-position hdmarker))
  8317. (inhibit-read-only t)
  8318. newhead)
  8319. (org-with-remote-undo buffer
  8320. (with-current-buffer buffer
  8321. (widen)
  8322. (goto-char pos)
  8323. (org-show-context 'agenda)
  8324. (save-excursion
  8325. (and (outline-next-heading)
  8326. (org-flag-heading nil))) ; show the next heading
  8327. (funcall 'org-priority force-direction)
  8328. (end-of-line 1)
  8329. (setq newhead (org-get-heading)))
  8330. (org-agenda-change-all-lines newhead hdmarker)
  8331. (org-move-to-column col)))))
  8332. ;; FIXME: should fix the tags property of the agenda line.
  8333. (defun org-agenda-set-tags (&optional tag onoff)
  8334. "Set tags for the current headline."
  8335. (interactive)
  8336. (org-agenda-check-no-diary)
  8337. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  8338. (call-interactively 'org-change-tag-in-region)
  8339. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8340. (org-agenda-error)))
  8341. (buffer (marker-buffer hdmarker))
  8342. (pos (marker-position hdmarker))
  8343. (inhibit-read-only t)
  8344. newhead)
  8345. (org-with-remote-undo buffer
  8346. (with-current-buffer buffer
  8347. (widen)
  8348. (goto-char pos)
  8349. (save-excursion
  8350. (org-show-context 'agenda))
  8351. (save-excursion
  8352. (and (outline-next-heading)
  8353. (org-flag-heading nil))) ; show the next heading
  8354. (goto-char pos)
  8355. (if tag
  8356. (org-toggle-tag tag onoff)
  8357. (call-interactively 'org-set-tags))
  8358. (end-of-line 1)
  8359. (setq newhead (org-get-heading)))
  8360. (org-agenda-change-all-lines newhead hdmarker)
  8361. (beginning-of-line 1)))))
  8362. (defun org-agenda-set-property ()
  8363. "Set a property for the current headline."
  8364. (interactive)
  8365. (org-agenda-check-no-diary)
  8366. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8367. (org-agenda-error)))
  8368. (buffer (marker-buffer hdmarker))
  8369. (pos (marker-position hdmarker))
  8370. (inhibit-read-only t)
  8371. newhead)
  8372. (org-with-remote-undo buffer
  8373. (with-current-buffer buffer
  8374. (widen)
  8375. (goto-char pos)
  8376. (save-excursion
  8377. (org-show-context 'agenda))
  8378. (save-excursion
  8379. (and (outline-next-heading)
  8380. (org-flag-heading nil))) ; show the next heading
  8381. (goto-char pos)
  8382. (call-interactively 'org-set-property)))))
  8383. (defun org-agenda-set-effort ()
  8384. "Set the effort property for the current headline."
  8385. (interactive)
  8386. (org-agenda-check-no-diary)
  8387. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8388. (org-agenda-error)))
  8389. (buffer (marker-buffer hdmarker))
  8390. (pos (marker-position hdmarker))
  8391. (inhibit-read-only t)
  8392. newhead)
  8393. (org-with-remote-undo buffer
  8394. (with-current-buffer buffer
  8395. (widen)
  8396. (goto-char pos)
  8397. (save-excursion
  8398. (org-show-context 'agenda))
  8399. (save-excursion
  8400. (and (outline-next-heading)
  8401. (org-flag-heading nil))) ; show the next heading
  8402. (goto-char pos)
  8403. (call-interactively 'org-set-effort)
  8404. (end-of-line 1)
  8405. (setq newhead (org-get-heading)))
  8406. (org-agenda-change-all-lines newhead hdmarker))))
  8407. (defun org-agenda-toggle-archive-tag ()
  8408. "Toggle the archive tag for the current entry."
  8409. (interactive)
  8410. (org-agenda-check-no-diary)
  8411. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  8412. (org-agenda-error)))
  8413. (buffer (marker-buffer hdmarker))
  8414. (pos (marker-position hdmarker))
  8415. (inhibit-read-only t)
  8416. newhead)
  8417. (org-with-remote-undo buffer
  8418. (with-current-buffer buffer
  8419. (widen)
  8420. (goto-char pos)
  8421. (org-show-context 'agenda)
  8422. (save-excursion
  8423. (and (outline-next-heading)
  8424. (org-flag-heading nil))) ; show the next heading
  8425. (call-interactively 'org-toggle-archive-tag)
  8426. (end-of-line 1)
  8427. (setq newhead (org-get-heading)))
  8428. (org-agenda-change-all-lines newhead hdmarker)
  8429. (beginning-of-line 1))))
  8430. (defun org-agenda-do-date-later (arg)
  8431. (interactive "P")
  8432. (cond
  8433. ((or (equal arg '(16))
  8434. (memq last-command
  8435. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8436. (setq this-command 'org-agenda-date-later-minutes)
  8437. (org-agenda-date-later-minutes 1))
  8438. ((or (equal arg '(4))
  8439. (memq last-command
  8440. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8441. (setq this-command 'org-agenda-date-later-hours)
  8442. (org-agenda-date-later-hours 1))
  8443. (t
  8444. (org-agenda-date-later (prefix-numeric-value arg)))))
  8445. (defun org-agenda-do-date-earlier (arg)
  8446. (interactive "P")
  8447. (cond
  8448. ((or (equal arg '(16))
  8449. (memq last-command
  8450. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  8451. (setq this-command 'org-agenda-date-earlier-minutes)
  8452. (org-agenda-date-earlier-minutes 1))
  8453. ((or (equal arg '(4))
  8454. (memq last-command
  8455. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  8456. (setq this-command 'org-agenda-date-earlier-hours)
  8457. (org-agenda-date-earlier-hours 1))
  8458. (t
  8459. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  8460. (defun org-agenda-date-later (arg &optional what)
  8461. "Change the date of this item to ARG day(s) later."
  8462. (interactive "p")
  8463. (org-agenda-check-type t 'agenda 'timeline)
  8464. (org-agenda-check-no-diary)
  8465. (let* ((marker (or (org-get-at-bol 'org-marker)
  8466. (org-agenda-error)))
  8467. (buffer (marker-buffer marker))
  8468. (pos (marker-position marker))
  8469. cdate today)
  8470. (org-with-remote-undo buffer
  8471. (with-current-buffer buffer
  8472. (widen)
  8473. (goto-char pos)
  8474. (if (not (org-at-timestamp-p))
  8475. (error "Cannot find time stamp"))
  8476. (when (and org-agenda-move-date-from-past-immediately-to-today
  8477. (equal arg 1)
  8478. (or (not what) (eq what 'day))
  8479. (not (save-match-data (org-at-date-range-p))))
  8480. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  8481. cdate (calendar-absolute-from-gregorian
  8482. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  8483. today (org-today))
  8484. (if (> today cdate)
  8485. ;; immediately shift to today
  8486. (setq arg (- today cdate))))
  8487. (org-timestamp-change arg (or what 'day))
  8488. (when (and (org-at-date-range-p)
  8489. (re-search-backward org-tr-regexp-both (point-at-bol)))
  8490. (let ((end org-last-changed-timestamp))
  8491. (org-timestamp-change arg (or what 'day))
  8492. (setq org-last-changed-timestamp
  8493. (concat org-last-changed-timestamp "--" end)))))
  8494. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8495. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8496. (defun org-agenda-date-earlier (arg &optional what)
  8497. "Change the date of this item to ARG day(s) earlier."
  8498. (interactive "p")
  8499. (org-agenda-date-later (- arg) what))
  8500. (defun org-agenda-date-later-minutes (arg)
  8501. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8502. (interactive "p")
  8503. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8504. (org-agenda-date-later arg 'minute))
  8505. (defun org-agenda-date-earlier-minutes (arg)
  8506. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  8507. (interactive "p")
  8508. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  8509. (org-agenda-date-earlier arg 'minute))
  8510. (defun org-agenda-date-later-hours (arg)
  8511. "Change the time of this item, in hour steps."
  8512. (interactive "p")
  8513. (org-agenda-date-later arg 'hour))
  8514. (defun org-agenda-date-earlier-hours (arg)
  8515. "Change the time of this item, in hour steps."
  8516. (interactive "p")
  8517. (org-agenda-date-earlier arg 'hour))
  8518. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  8519. "Show new date stamp via text properties."
  8520. ;; We use text properties to make this undoable
  8521. (let ((inhibit-read-only t))
  8522. (setq stamp (concat prefix " => " stamp " "))
  8523. (save-excursion
  8524. (goto-char (point-max))
  8525. (while (not (bobp))
  8526. (when (equal marker (org-get-at-bol 'org-marker))
  8527. (remove-text-properties (point-at-bol) (point-at-eol) '(display))
  8528. (org-move-to-column (- (window-width) (length stamp)) t)
  8529. (if (featurep 'xemacs)
  8530. ;; Use `duplicable' property to trigger undo recording
  8531. (let ((ex (make-extent nil nil))
  8532. (gl (make-glyph stamp)))
  8533. (set-glyph-face gl 'secondary-selection)
  8534. (set-extent-properties
  8535. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  8536. (insert-extent ex (1- (point)) (point-at-eol)))
  8537. (add-text-properties
  8538. (1- (point)) (point-at-eol)
  8539. (list 'display (org-add-props stamp nil
  8540. 'face '(secondary-selection default)))))
  8541. (beginning-of-line 1))
  8542. (beginning-of-line 0)))))
  8543. (defun org-agenda-date-prompt (arg)
  8544. "Change the date of this item. Date is prompted for, with default today.
  8545. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  8546. be used to request time specification in the time stamp."
  8547. (interactive "P")
  8548. (org-agenda-check-type t 'agenda 'timeline)
  8549. (org-agenda-check-no-diary)
  8550. (let* ((marker (or (org-get-at-bol 'org-marker)
  8551. (org-agenda-error)))
  8552. (buffer (marker-buffer marker))
  8553. (pos (marker-position marker)))
  8554. (org-with-remote-undo buffer
  8555. (with-current-buffer buffer
  8556. (widen)
  8557. (goto-char pos)
  8558. (if (not (org-at-timestamp-p t))
  8559. (error "Cannot find time stamp"))
  8560. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8561. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8562. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8563. (defun org-agenda-schedule (arg &optional time)
  8564. "Schedule the item at point.
  8565. ARG is passed through to `org-schedule'."
  8566. (interactive "P")
  8567. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8568. (org-agenda-check-no-diary)
  8569. (let* ((marker (or (org-get-at-bol 'org-marker)
  8570. (org-agenda-error)))
  8571. (type (marker-insertion-type marker))
  8572. (buffer (marker-buffer marker))
  8573. (pos (marker-position marker))
  8574. (org-insert-labeled-timestamps-at-point nil)
  8575. ts)
  8576. (set-marker-insertion-type marker t)
  8577. (org-with-remote-undo buffer
  8578. (with-current-buffer buffer
  8579. (widen)
  8580. (goto-char pos)
  8581. (setq ts (org-schedule arg time)))
  8582. (org-agenda-show-new-time marker ts " S"))
  8583. (message "%s" ts)))
  8584. (defun org-agenda-deadline (arg &optional time)
  8585. "Schedule the item at point.
  8586. ARG is passed through to `org-deadline'."
  8587. (interactive "P")
  8588. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8589. (org-agenda-check-no-diary)
  8590. (let* ((marker (or (org-get-at-bol 'org-marker)
  8591. (org-agenda-error)))
  8592. (buffer (marker-buffer marker))
  8593. (pos (marker-position marker))
  8594. (org-insert-labeled-timestamps-at-point nil)
  8595. ts)
  8596. (org-with-remote-undo buffer
  8597. (with-current-buffer buffer
  8598. (widen)
  8599. (goto-char pos)
  8600. (setq ts (org-deadline arg time)))
  8601. (org-agenda-show-new-time marker ts " D"))
  8602. (message "%s" ts)))
  8603. (defun org-agenda-clock-in (&optional arg)
  8604. "Start the clock on the currently selected item."
  8605. (interactive "P")
  8606. (org-agenda-check-no-diary)
  8607. (if (equal arg '(4))
  8608. (org-clock-in arg)
  8609. (let* ((marker (or (org-get-at-bol 'org-marker)
  8610. (org-agenda-error)))
  8611. (hdmarker (or (org-get-at-bol 'org-hd-marker) marker))
  8612. (pos (marker-position marker))
  8613. (col (current-column))
  8614. newhead)
  8615. (org-with-remote-undo (marker-buffer marker)
  8616. (with-current-buffer (marker-buffer marker)
  8617. (widen)
  8618. (goto-char pos)
  8619. (org-show-context 'agenda)
  8620. (org-show-entry)
  8621. (org-cycle-hide-drawers 'children)
  8622. (org-clock-in arg)
  8623. (setq newhead (org-get-heading)))
  8624. (org-agenda-change-all-lines newhead hdmarker))
  8625. (org-move-to-column col))))
  8626. (defun org-agenda-clock-out ()
  8627. "Stop the currently running clock."
  8628. (interactive)
  8629. (unless (marker-buffer org-clock-marker)
  8630. (error "No running clock"))
  8631. (let ((marker (make-marker)) (col (current-column)) newhead)
  8632. (org-with-remote-undo (marker-buffer org-clock-marker)
  8633. (with-current-buffer (marker-buffer org-clock-marker)
  8634. (save-excursion
  8635. (save-restriction
  8636. (widen)
  8637. (goto-char org-clock-marker)
  8638. (org-back-to-heading t)
  8639. (move-marker marker (point))
  8640. (org-clock-out)
  8641. (setq newhead (org-get-heading))))))
  8642. (org-agenda-change-all-lines newhead marker)
  8643. (move-marker marker nil)
  8644. (org-move-to-column col)
  8645. (org-agenda-unmark-clocking-task)))
  8646. (defun org-agenda-clock-cancel (&optional arg)
  8647. "Cancel the currently running clock."
  8648. (interactive "P")
  8649. (unless (marker-buffer org-clock-marker)
  8650. (user-error "No running clock"))
  8651. (org-with-remote-undo (marker-buffer org-clock-marker)
  8652. (org-clock-cancel)))
  8653. (defun org-agenda-clock-goto ()
  8654. "Jump to the currently clocked in task within the agenda.
  8655. If the currently clocked in task is not listed in the agenda
  8656. buffer, display it in another window."
  8657. (interactive)
  8658. (let (pos)
  8659. (mapc (lambda (o)
  8660. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8661. (setq pos (overlay-start o))))
  8662. (overlays-in (point-min) (point-max)))
  8663. (cond (pos (goto-char pos))
  8664. ;; If the currently clocked entry is not in the agenda
  8665. ;; buffer, we visit it in another window:
  8666. (org-clock-current-task
  8667. (org-switch-to-buffer-other-window (org-clock-goto)))
  8668. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8669. (defun org-agenda-diary-entry-in-org-file ()
  8670. "Make a diary entry in the file `org-agenda-diary-file'."
  8671. (let (d1 d2 char (text "") dp1 dp2)
  8672. (if (equal (buffer-name) "*Calendar*")
  8673. (setq d1 (calendar-cursor-to-date t)
  8674. d2 (car calendar-mark-ring))
  8675. (setq dp1 (get-text-property (point-at-bol) 'day))
  8676. (unless dp1 (user-error "No date defined in current line"))
  8677. (setq d1 (calendar-gregorian-from-absolute dp1)
  8678. d2 (and (ignore-errors (mark))
  8679. (save-excursion
  8680. (goto-char (mark))
  8681. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8682. (calendar-gregorian-from-absolute dp2))))
  8683. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8684. (setq char (read-char-exclusive))
  8685. (cond
  8686. ((equal char ?d)
  8687. (setq text (read-string "Day entry: "))
  8688. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8689. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8690. ((equal char ?a)
  8691. (setq d1 (list (car d1) (nth 1 d1)
  8692. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8693. (nth 2 d1))))
  8694. (setq text (read-string "Anniversary (use %d to show years): "))
  8695. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8696. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8697. ((equal char ?b)
  8698. (setq text (read-string "Block entry: "))
  8699. (unless (and d1 d2 (not (equal d1 d2)))
  8700. (user-error "No block of days selected"))
  8701. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8702. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8703. ((equal char ?j)
  8704. (org-switch-to-buffer-other-window
  8705. (find-file-noselect org-agenda-diary-file))
  8706. (require 'org-datetree)
  8707. (org-datetree-find-date-create d1)
  8708. (org-reveal t))
  8709. (t (user-error "Invalid selection character `%c'" char)))))
  8710. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8711. "Where in `org-agenda-diary-file' should new entries be added?
  8712. Valid values:
  8713. date-tree in the date tree, as child of the date
  8714. top-level as top-level entries at the end of the file."
  8715. :group 'org-agenda
  8716. :type '(choice
  8717. (const :tag "in a date tree" date-tree)
  8718. (const :tag "as top level at end of file" top-level)))
  8719. (defcustom org-agenda-insert-diary-extract-time nil
  8720. "Non-nil means extract any time specification from the diary entry."
  8721. :group 'org-agenda
  8722. :version "24.1"
  8723. :type 'boolean)
  8724. (defcustom org-agenda-bulk-mark-char ">"
  8725. "A single-character string to be used as the bulk mark."
  8726. :group 'org-agenda
  8727. :version "24.1"
  8728. :type 'string)
  8729. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8730. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8731. If TEXT is not empty, it will become the headline of the new entry, and
  8732. the resulting entry will not be shown. When TEXT is empty, switch to
  8733. `org-agenda-diary-file' and let the user finish the entry there."
  8734. (let ((cw (current-window-configuration)))
  8735. (org-switch-to-buffer-other-window
  8736. (find-file-noselect org-agenda-diary-file))
  8737. (widen)
  8738. (goto-char (point-min))
  8739. (cond
  8740. ((eq type 'anniversary)
  8741. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8742. (progn
  8743. (or (org-at-heading-p t)
  8744. (progn
  8745. (outline-next-heading)
  8746. (insert "* Anniversaries\n\n")
  8747. (beginning-of-line -1)))))
  8748. (outline-next-heading)
  8749. (org-back-over-empty-lines)
  8750. (backward-char 1)
  8751. (insert "\n")
  8752. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8753. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8754. ((eq type 'day)
  8755. (let ((org-prefix-has-time t)
  8756. (org-agenda-time-leading-zero t)
  8757. fmt time time2)
  8758. (if org-agenda-insert-diary-extract-time
  8759. ;; Use org-agenda-format-item to parse text for a time-range and
  8760. ;; remove it. FIXME: This is a hack, we should refactor
  8761. ;; that function to make time extraction available separately
  8762. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8763. time (get-text-property 0 'time fmt)
  8764. time2 (if (> (length time) 0)
  8765. ;; split-string removes trailing ...... if
  8766. ;; no end time given. First space
  8767. ;; separates time from date.
  8768. (concat " " (car (split-string time "\\.")))
  8769. nil)
  8770. text (get-text-property 0 'txt fmt)))
  8771. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8772. (org-agenda-insert-diary-as-top-level text)
  8773. (require 'org-datetree)
  8774. (org-datetree-find-date-create d1)
  8775. (org-agenda-insert-diary-make-new-entry text))
  8776. (org-insert-time-stamp (org-time-from-absolute
  8777. (calendar-absolute-from-gregorian d1))
  8778. nil nil nil nil time2))
  8779. (end-of-line 0))
  8780. ((eq type 'block)
  8781. (if (> (calendar-absolute-from-gregorian d1)
  8782. (calendar-absolute-from-gregorian d2))
  8783. (setq d1 (prog1 d2 (setq d2 d1))))
  8784. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8785. (org-agenda-insert-diary-as-top-level text)
  8786. (require 'org-datetree)
  8787. (org-datetree-find-date-create d1)
  8788. (org-agenda-insert-diary-make-new-entry text))
  8789. (org-insert-time-stamp (org-time-from-absolute
  8790. (calendar-absolute-from-gregorian d1)))
  8791. (insert "--")
  8792. (org-insert-time-stamp (org-time-from-absolute
  8793. (calendar-absolute-from-gregorian d2)))
  8794. (end-of-line 0)))
  8795. (if (string-match "\\S-" text)
  8796. (progn
  8797. (set-window-configuration cw)
  8798. (message "%s entry added to %s"
  8799. (capitalize (symbol-name type))
  8800. (abbreviate-file-name org-agenda-diary-file)))
  8801. (org-reveal t)
  8802. (message "Please finish entry here"))))
  8803. (defun org-agenda-insert-diary-as-top-level (text)
  8804. "Make new entry as a top-level entry at the end of the file.
  8805. Add TEXT as headline, and position the cursor in the second line so that
  8806. a timestamp can be added there."
  8807. (widen)
  8808. (goto-char (point-max))
  8809. (or (bolp) (insert "\n"))
  8810. (insert "* " text "\n")
  8811. (if org-adapt-indentation (org-indent-to-column 2)))
  8812. (defun org-agenda-insert-diary-make-new-entry (text)
  8813. "Make a new entry with TEXT as the first child of the current subtree.
  8814. Position the point in the line right after the new heading so
  8815. that a timestamp can be added there."
  8816. (let ((org-show-following-heading t)
  8817. (org-show-siblings t)
  8818. (org-show-hierarchy-above t)
  8819. (org-show-entry-below t)
  8820. col)
  8821. (outline-next-heading)
  8822. (org-back-over-empty-lines)
  8823. (or (looking-at "[ \t]*$")
  8824. (progn (insert "\n") (backward-char 1)))
  8825. (org-insert-heading nil t)
  8826. (org-do-demote)
  8827. (setq col (current-column))
  8828. (insert text "\n")
  8829. (if org-adapt-indentation (org-indent-to-column col))
  8830. (let ((org-show-following-heading t)
  8831. (org-show-siblings t)
  8832. (org-show-hierarchy-above t)
  8833. (org-show-entry-below t))
  8834. (org-show-context))))
  8835. (defun org-agenda-diary-entry ()
  8836. "Make a diary entry, like the `i' command from the calendar.
  8837. All the standard commands work: block, weekly etc.
  8838. When `org-agenda-diary-file' points to a file,
  8839. `org-agenda-diary-entry-in-org-file' is called instead to create
  8840. entries in that Org-mode file."
  8841. (interactive)
  8842. (if (not (eq org-agenda-diary-file 'diary-file))
  8843. (org-agenda-diary-entry-in-org-file)
  8844. (require 'diary-lib)
  8845. (let* ((char (progn
  8846. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8847. (read-char-exclusive)))
  8848. (cmd (cdr (assoc char
  8849. '((?d . insert-diary-entry)
  8850. (?w . insert-weekly-diary-entry)
  8851. (?m . insert-monthly-diary-entry)
  8852. (?y . insert-yearly-diary-entry)
  8853. (?a . insert-anniversary-diary-entry)
  8854. (?b . insert-block-diary-entry)
  8855. (?c . insert-cyclic-diary-entry)))))
  8856. (oldf (symbol-function 'calendar-cursor-to-date))
  8857. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8858. (point (point))
  8859. (mark (or (mark t) (point))))
  8860. (unless cmd
  8861. (user-error "No command associated with <%c>" char))
  8862. (unless (and (get-text-property point 'day)
  8863. (or (not (equal ?b char))
  8864. (get-text-property mark 'day)))
  8865. (user-error "Don't know which date to use for diary entry"))
  8866. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8867. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8868. (let ((calendar-mark-ring
  8869. (list (calendar-gregorian-from-absolute
  8870. (or (get-text-property mark 'day)
  8871. (get-text-property point 'day))))))
  8872. (unwind-protect
  8873. (progn
  8874. (fset 'calendar-cursor-to-date
  8875. (lambda (&optional error dummy)
  8876. (calendar-gregorian-from-absolute
  8877. (get-text-property point 'day))))
  8878. (call-interactively cmd))
  8879. (fset 'calendar-cursor-to-date oldf))))))
  8880. (defun org-agenda-execute-calendar-command (cmd)
  8881. "Execute a calendar command from the agenda with date from cursor."
  8882. (org-agenda-check-type t 'agenda 'timeline)
  8883. (require 'diary-lib)
  8884. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8885. (user-error "Don't know which date to use for the calendar command"))
  8886. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8887. (point (point))
  8888. (date (calendar-gregorian-from-absolute
  8889. (get-text-property point 'day)))
  8890. ;; the following 2 vars are needed in the calendar
  8891. (displayed-month (car date))
  8892. (displayed-year (nth 2 date)))
  8893. (unwind-protect
  8894. (progn
  8895. (fset 'calendar-cursor-to-date
  8896. (lambda (&optional error dummy)
  8897. (calendar-gregorian-from-absolute
  8898. (get-text-property point 'day))))
  8899. (call-interactively cmd))
  8900. (fset 'calendar-cursor-to-date oldf))))
  8901. (defun org-agenda-phases-of-moon ()
  8902. "Display the phases of the moon for the 3 months around the cursor date."
  8903. (interactive)
  8904. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8905. (defun org-agenda-holidays ()
  8906. "Display the holidays for the 3 months around the cursor date."
  8907. (interactive)
  8908. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8909. (defvar calendar-longitude) ; defined in calendar.el
  8910. (defvar calendar-latitude) ; defined in calendar.el
  8911. (defvar calendar-location-name) ; defined in calendar.el
  8912. (defun org-agenda-sunrise-sunset (arg)
  8913. "Display sunrise and sunset for the cursor date.
  8914. Latitude and longitude can be specified with the variables
  8915. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8916. argument, latitude and longitude will be prompted for."
  8917. (interactive "P")
  8918. (require 'solar)
  8919. (let ((calendar-longitude (if arg nil calendar-longitude))
  8920. (calendar-latitude (if arg nil calendar-latitude))
  8921. (calendar-location-name
  8922. (if arg "the given coordinates" calendar-location-name)))
  8923. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8924. (defun org-agenda-goto-calendar ()
  8925. "Open the Emacs calendar with the date at the cursor."
  8926. (interactive)
  8927. (org-agenda-check-type t 'agenda 'timeline)
  8928. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8929. (user-error "Don't know which date to open in calendar")))
  8930. (date (calendar-gregorian-from-absolute day))
  8931. (calendar-move-hook nil)
  8932. (calendar-view-holidays-initially-flag nil)
  8933. (calendar-view-diary-initially-flag nil))
  8934. (calendar)
  8935. (calendar-goto-date date)))
  8936. ;;;###autoload
  8937. (defun org-calendar-goto-agenda ()
  8938. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8939. This is a command that has to be installed in `calendar-mode-map'."
  8940. (interactive)
  8941. (org-agenda-list nil (calendar-absolute-from-gregorian
  8942. (calendar-cursor-to-date))
  8943. nil))
  8944. (defun org-agenda-convert-date ()
  8945. (interactive)
  8946. (org-agenda-check-type t 'agenda 'timeline)
  8947. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8948. date s)
  8949. (unless day
  8950. (user-error "Don't know which date to convert"))
  8951. (setq date (calendar-gregorian-from-absolute day))
  8952. (setq s (concat
  8953. "Gregorian: " (calendar-date-string date) "\n"
  8954. "ISO: " (calendar-iso-date-string date) "\n"
  8955. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8956. "Julian: " (calendar-julian-date-string date) "\n"
  8957. "Astron. JD: " (calendar-astro-date-string date)
  8958. " (Julian date number at noon UTC)\n"
  8959. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8960. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8961. "French: " (calendar-french-date-string date) "\n"
  8962. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8963. "Mayan: " (calendar-mayan-date-string date) "\n"
  8964. "Coptic: " (calendar-coptic-date-string date) "\n"
  8965. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8966. "Persian: " (calendar-persian-date-string date) "\n"
  8967. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8968. (with-output-to-temp-buffer "*Dates*"
  8969. (princ s))
  8970. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8971. ;;; Bulk commands
  8972. (defun org-agenda-bulk-marked-p ()
  8973. (eq (get-char-property (point-at-bol) 'type)
  8974. 'org-marked-entry-overlay))
  8975. (defun org-agenda-bulk-mark (&optional arg)
  8976. "Mark the entry at point for future bulk action."
  8977. (interactive "p")
  8978. (dotimes (i (or arg 1))
  8979. (unless (org-get-at-bol 'org-agenda-diary-link)
  8980. (let* ((m (org-get-at-bol 'org-hd-marker))
  8981. ov)
  8982. (unless (org-agenda-bulk-marked-p)
  8983. (unless m (user-error "Nothing to mark at point"))
  8984. (push m org-agenda-bulk-marked-entries)
  8985. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8986. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8987. (org-get-todo-face "TODO")
  8988. 'evaporate)
  8989. (overlay-put ov 'type 'org-marked-entry-overlay))
  8990. (end-of-line 1)
  8991. (or (ignore-errors
  8992. (goto-char (next-single-property-change (point) 'txt)))
  8993. (beginning-of-line 2))
  8994. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8995. (beginning-of-line 2))
  8996. (message "%d entries marked for bulk action"
  8997. (length org-agenda-bulk-marked-entries))))))
  8998. (defun org-agenda-bulk-mark-all ()
  8999. "Mark all entries for future agenda bulk action."
  9000. (interactive)
  9001. (org-agenda-bulk-mark-regexp "."))
  9002. (defun org-agenda-bulk-mark-regexp (regexp)
  9003. "Mark entries matching REGEXP for future agenda bulk action."
  9004. (interactive "sMark entries matching regexp: ")
  9005. (let ((entries-marked 0) txt-at-point)
  9006. (save-excursion
  9007. (goto-char (point-min))
  9008. (goto-char (next-single-property-change (point) 'txt))
  9009. (while (and (re-search-forward regexp nil t)
  9010. (setq txt-at-point (get-text-property (point) 'txt)))
  9011. (when (string-match regexp txt-at-point)
  9012. (setq entries-marked (1+ entries-marked))
  9013. (call-interactively 'org-agenda-bulk-mark))))
  9014. (if (not entries-marked)
  9015. (message "No entry matching this regexp."))))
  9016. (defun org-agenda-bulk-unmark (&optional arg)
  9017. "Unmark the entry at point for future bulk action."
  9018. (interactive "P")
  9019. (if arg
  9020. (org-agenda-bulk-unmark-all)
  9021. (cond ((org-agenda-bulk-marked-p)
  9022. (org-agenda-bulk-remove-overlays
  9023. (point-at-bol) (+ 2 (point-at-bol)))
  9024. (setq org-agenda-bulk-marked-entries
  9025. (delete (org-get-at-bol 'org-hd-marker)
  9026. org-agenda-bulk-marked-entries))
  9027. (end-of-line 1)
  9028. (or (ignore-errors
  9029. (goto-char (next-single-property-change (point) 'txt)))
  9030. (beginning-of-line 2))
  9031. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  9032. (beginning-of-line 2))
  9033. (message "%d entries left marked for bulk action"
  9034. (length org-agenda-bulk-marked-entries)))
  9035. (t (message "No entry to unmark here")))))
  9036. (defun org-agenda-bulk-toggle-all ()
  9037. "Toggle all marks for bulk action."
  9038. (interactive)
  9039. (save-excursion
  9040. (goto-char (point-min))
  9041. (while (ignore-errors
  9042. (goto-char (next-single-property-change (point) 'txt)))
  9043. (org-agenda-bulk-toggle))))
  9044. (defun org-agenda-bulk-toggle ()
  9045. "Toggle the mark at point for bulk action."
  9046. (interactive)
  9047. (if (org-agenda-bulk-marked-p)
  9048. (org-agenda-bulk-unmark)
  9049. (org-agenda-bulk-mark)))
  9050. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  9051. "Remove the mark overlays between BEG and END in the agenda buffer.
  9052. BEG and END default to the buffer limits.
  9053. This only removes the overlays, it does not remove the markers
  9054. from the list in `org-agenda-bulk-marked-entries'."
  9055. (interactive)
  9056. (mapc (lambda (ov)
  9057. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  9058. (delete-overlay ov)))
  9059. (overlays-in (or beg (point-min)) (or end (point-max)))))
  9060. (defun org-agenda-bulk-unmark-all ()
  9061. "Remove all marks in the agenda buffer.
  9062. This will remove the markers and the overlays."
  9063. (interactive)
  9064. (if (null org-agenda-bulk-marked-entries)
  9065. (message "No entry to unmark")
  9066. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  9067. (setq org-agenda-bulk-marked-entries nil)
  9068. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  9069. (defcustom org-agenda-persistent-marks nil
  9070. "Non-nil means marked items will stay marked after a bulk action.
  9071. You can toggle this interactively by typing `p' when prompted for a
  9072. bulk action."
  9073. :group 'org-agenda
  9074. :version "24.1"
  9075. :type 'boolean)
  9076. (defun org-agenda-bulk-action (&optional arg)
  9077. "Execute an remote-editing action on all marked entries.
  9078. The prefix arg is passed through to the command if possible."
  9079. (interactive "P")
  9080. ;; Make sure we have markers, and only valid ones
  9081. (unless org-agenda-bulk-marked-entries (user-error "No entries are marked"))
  9082. (mapc
  9083. (lambda (m)
  9084. (unless (and (markerp m)
  9085. (marker-buffer m)
  9086. (buffer-live-p (marker-buffer m))
  9087. (marker-position m))
  9088. (user-error "Marker %s for bulk command is invalid" m)))
  9089. org-agenda-bulk-marked-entries)
  9090. ;; Prompt for the bulk command
  9091. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  9092. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  9093. "[S]catter [f]unction "
  9094. (when org-agenda-bulk-custom-functions
  9095. (concat " Custom: ["
  9096. (mapconcat (lambda(f) (char-to-string (car f)))
  9097. org-agenda-bulk-custom-functions "")
  9098. "]"))))
  9099. (catch 'exit
  9100. (let* ((action (read-char-exclusive))
  9101. (org-log-refile (if org-log-refile 'time nil))
  9102. (entries (reverse org-agenda-bulk-marked-entries))
  9103. (org-overriding-default-time
  9104. (if (get-text-property (point) 'org-agenda-date-header)
  9105. (org-get-cursor-date)))
  9106. redo-at-end
  9107. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  9108. (cond
  9109. ((equal action ?p)
  9110. (let ((org-agenda-persistent-marks
  9111. (not org-agenda-persistent-marks)))
  9112. (org-agenda-bulk-action)
  9113. (throw 'exit nil)))
  9114. ((equal action ?$)
  9115. (setq cmd '(org-agenda-archive)))
  9116. ((equal action ?A)
  9117. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  9118. ((member action '(?r ?w))
  9119. (setq rfloc (org-refile-get-location
  9120. "Refile to"
  9121. (marker-buffer (car entries))
  9122. org-refile-allow-creating-parent-nodes))
  9123. (if (nth 3 rfloc)
  9124. (setcar (nthcdr 3 rfloc)
  9125. (move-marker (make-marker) (nth 3 rfloc)
  9126. (or (get-file-buffer (nth 1 rfloc))
  9127. (find-buffer-visiting (nth 1 rfloc))
  9128. (error "This should not happen")))))
  9129. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  9130. redo-at-end t))
  9131. ((equal action ?t)
  9132. (setq state (org-icompleting-read
  9133. "Todo state: "
  9134. (with-current-buffer (marker-buffer (car entries))
  9135. (mapcar 'list org-todo-keywords-1))))
  9136. (setq cmd `(let ((org-inhibit-blocking t)
  9137. (org-inhibit-logging 'note))
  9138. (org-agenda-todo ,state))))
  9139. ((memq action '(?- ?+))
  9140. (setq tag (org-icompleting-read
  9141. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  9142. (with-current-buffer (marker-buffer (car entries))
  9143. (delq nil
  9144. (mapcar (lambda (x)
  9145. (if (stringp (car x)) x)) org-tag-alist)))))
  9146. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  9147. ((memq action '(?s ?d))
  9148. (let* ((time
  9149. (unless arg
  9150. (org-read-date
  9151. nil nil nil
  9152. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  9153. org-overriding-default-time)))
  9154. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  9155. (setq cmd `(eval '(,c1 arg ,time)))))
  9156. ((equal action ?S)
  9157. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  9158. (user-error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  9159. (let ((days (read-number
  9160. (format "Scatter tasks across how many %sdays: "
  9161. (if arg "week" "")) 7)))
  9162. (setq cmd
  9163. `(let ((distance (1+ (random ,days))))
  9164. (if arg
  9165. (let ((dist distance)
  9166. (day-of-week
  9167. (calendar-day-of-week
  9168. (calendar-gregorian-from-absolute (org-today)))))
  9169. (dotimes (i (1+ dist))
  9170. (while (member day-of-week org-agenda-weekend-days)
  9171. (incf distance)
  9172. (incf day-of-week)
  9173. (if (= day-of-week 7)
  9174. (setq day-of-week 0)))
  9175. (incf day-of-week)
  9176. (if (= day-of-week 7)
  9177. (setq day-of-week 0)))))
  9178. ;; silently fail when try to replan a sexp entry
  9179. (condition-case nil
  9180. (let* ((date (calendar-gregorian-from-absolute
  9181. (+ (org-today) distance)))
  9182. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  9183. (nth 2 date))))
  9184. (org-agenda-schedule nil time))
  9185. (error nil)))))))
  9186. ((assoc action org-agenda-bulk-custom-functions)
  9187. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  9188. redo-at-end t))
  9189. ((equal action ?f)
  9190. (setq cmd (list (intern
  9191. (org-icompleting-read "Function: "
  9192. obarray 'fboundp t nil nil)))))
  9193. (t (user-error "Invalid bulk action")))
  9194. ;; Sort the markers, to make sure that parents are handled before children
  9195. (setq entries (sort entries
  9196. (lambda (a b)
  9197. (cond
  9198. ((equal (marker-buffer a) (marker-buffer b))
  9199. (< (marker-position a) (marker-position b)))
  9200. (t
  9201. (string< (buffer-name (marker-buffer a))
  9202. (buffer-name (marker-buffer b))))))))
  9203. ;; Now loop over all markers and apply cmd
  9204. (while (setq e (pop entries))
  9205. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  9206. (if (not pos)
  9207. (progn (message "Skipping removed entry at %s" e)
  9208. (setq cntskip (1+ cntskip)))
  9209. (goto-char pos)
  9210. (let (org-loop-over-headlines-in-active-region)
  9211. (eval cmd))
  9212. (setq cnt (1+ cnt))))
  9213. (when redo-at-end (org-agenda-redo))
  9214. (unless org-agenda-persistent-marks
  9215. (org-agenda-bulk-unmark-all))
  9216. (message "Acted on %d entries%s%s"
  9217. cnt
  9218. (if (= cntskip 0)
  9219. ""
  9220. (format ", skipped %d (disappeared before their turn)"
  9221. cntskip))
  9222. (if (not org-agenda-persistent-marks)
  9223. "" " (kept marked)"))))))
  9224. (defun org-agenda-capture (&optional with-time)
  9225. "Call `org-capture' with the date at point.
  9226. With a `C-1' prefix, use the HH:MM value at point (if any) or the
  9227. current HH:MM time."
  9228. (interactive "P")
  9229. (if (not (eq major-mode 'org-agenda-mode))
  9230. (user-error "You cannot do this outside of agenda buffers")
  9231. (let ((org-overriding-default-time
  9232. (org-get-cursor-date (equal with-time 1))))
  9233. (call-interactively 'org-capture))))
  9234. ;;; Dragging agenda lines forward/backward
  9235. (defun org-agenda-reapply-filters ()
  9236. "Re-apply all agenda filters."
  9237. (mapcar
  9238. (lambda(f) (when (car f) (org-agenda-filter-apply (car f) (cadr f))))
  9239. `((,org-agenda-tag-filter tag)
  9240. (,org-agenda-category-filter category)
  9241. (,org-agenda-regexp-filter regexp)
  9242. (,(get 'org-agenda-tag-filter :preset-filter) tag)
  9243. (,(get 'org-agenda-category-filter :preset-filter) category)
  9244. (,(get 'org-agenda-regexp-filter :preset-filter) regexp))))
  9245. (defun org-agenda-drag-line-forward (arg &optional backward)
  9246. "Drag an agenda line forward by ARG lines.
  9247. When the optional argument `backward' is non-nil, move backward."
  9248. (interactive "p")
  9249. (let ((inhibit-read-only t) lst line)
  9250. (if (or (not (get-text-property (point) 'txt))
  9251. (save-excursion
  9252. (dotimes (n arg)
  9253. (move-beginning-of-line (if backward 0 2))
  9254. (push (not (get-text-property (point) 'txt)) lst))
  9255. (delq nil lst)))
  9256. (message "Cannot move line forward")
  9257. (let ((end (save-excursion (move-beginning-of-line 2) (point))))
  9258. (move-beginning-of-line 1)
  9259. (setq line (buffer-substring (point) end))
  9260. (delete-region (point) end)
  9261. (move-beginning-of-line (funcall (if backward '1- '1+) arg))
  9262. (insert line)
  9263. (org-agenda-reapply-filters)
  9264. (org-agenda-mark-clocking-task)
  9265. (move-beginning-of-line 0)))))
  9266. (defun org-agenda-drag-line-backward (arg)
  9267. "Drag an agenda line backward by ARG lines."
  9268. (interactive "p")
  9269. (org-agenda-drag-line-forward arg t))
  9270. ;;; Flagging notes
  9271. (defun org-agenda-show-the-flagging-note ()
  9272. "Display the flagging note in the other window.
  9273. When called a second time in direct sequence, offer to remove the FLAGGING
  9274. tag and (if present) the flagging note."
  9275. (interactive)
  9276. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  9277. (win (selected-window))
  9278. note heading newhead)
  9279. (unless hdmarker
  9280. (user-error "No linked entry at point"))
  9281. (if (and (eq this-command last-command)
  9282. (y-or-n-p "Unflag and remove any flagging note? "))
  9283. (progn
  9284. (org-agenda-remove-flag hdmarker)
  9285. (let ((win (get-buffer-window "*Flagging Note*")))
  9286. (and win (delete-window win)))
  9287. (message "Entry unflagged"))
  9288. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  9289. (unless note
  9290. (user-error "No flagging note"))
  9291. (org-kill-new note)
  9292. (org-switch-to-buffer-other-window "*Flagging Note*")
  9293. (erase-buffer)
  9294. (insert note)
  9295. (goto-char (point-min))
  9296. (while (re-search-forward "\\\\n" nil t)
  9297. (replace-match "\n" t t))
  9298. (goto-char (point-min))
  9299. (select-window win)
  9300. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  9301. (defun org-agenda-remove-flag (marker)
  9302. "Remove the FLAGGED tag and any flagging note in the entry."
  9303. (let (newhead)
  9304. (org-with-point-at marker
  9305. (org-toggle-tag "FLAGGED" 'off)
  9306. (org-entry-delete nil "THEFLAGGINGNOTE")
  9307. (setq newhead (org-get-heading)))
  9308. (org-agenda-change-all-lines newhead marker)
  9309. (message "Entry unflagged")))
  9310. (defun org-agenda-get-any-marker (&optional pos)
  9311. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  9312. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  9313. ;;; Appointment reminders
  9314. (defvar appt-time-msg-list) ; defined in appt.el
  9315. ;;;###autoload
  9316. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  9317. "Activate appointments found in `org-agenda-files'.
  9318. With a \\[universal-argument] prefix, refresh the list of
  9319. appointments.
  9320. If FILTER is t, interactively prompt the user for a regular
  9321. expression, and filter out entries that don't match it.
  9322. If FILTER is a string, use this string as a regular expression
  9323. for filtering entries out.
  9324. If FILTER is a function, filter out entries against which
  9325. calling the function returns nil. This function takes one
  9326. argument: an entry from `org-agenda-get-day-entries'.
  9327. FILTER can also be an alist with the car of each cell being
  9328. either 'headline or 'category. For example:
  9329. '((headline \"IMPORTANT\")
  9330. (category \"Work\"))
  9331. will only add headlines containing IMPORTANT or headlines
  9332. belonging to the \"Work\" category.
  9333. ARGS are symbols indicating what kind of entries to consider.
  9334. By default `org-agenda-to-appt' will use :deadline*, :scheduled*
  9335. \(i.e., deadlines and scheduled items with a hh:mm specification)
  9336. and :timestamp entries. See the docstring of `org-diary' for
  9337. details and examples.
  9338. If an entry has a APPT_WARNTIME property, its value will be used
  9339. to override `appt-message-warning-time'."
  9340. (interactive "P")
  9341. (if refresh (setq appt-time-msg-list nil))
  9342. (if (eq filter t)
  9343. (setq filter (read-from-minibuffer "Regexp filter: ")))
  9344. (let* ((cnt 0) ; count added events
  9345. (scope (or args '(:deadline* :scheduled* :timestamp)))
  9346. (org-agenda-new-buffers nil)
  9347. (org-deadline-warning-days 0)
  9348. ;; Do not use `org-today' here because appt only takes
  9349. ;; time and without date as argument, so it may pass wrong
  9350. ;; information otherwise
  9351. (today (org-date-to-gregorian
  9352. (time-to-days (current-time))))
  9353. (org-agenda-restrict nil)
  9354. (files (org-agenda-files 'unrestricted)) entries file
  9355. (org-agenda-buffer nil))
  9356. ;; Get all entries which may contain an appt
  9357. (org-agenda-prepare-buffers files)
  9358. (while (setq file (pop files))
  9359. (setq entries
  9360. (delq nil
  9361. (append entries
  9362. (apply 'org-agenda-get-day-entries
  9363. file today scope)))))
  9364. ;; Map thru entries and find if we should filter them out
  9365. (mapc
  9366. (lambda(x)
  9367. (let* ((evt (org-trim
  9368. (replace-regexp-in-string
  9369. org-bracket-link-regexp "\\3"
  9370. (or (get-text-property 1 'txt x) ""))))
  9371. (cat (get-text-property 1 'org-category x))
  9372. (tod (get-text-property 1 'time-of-day x))
  9373. (ok (or (null filter)
  9374. (and (stringp filter) (string-match filter evt))
  9375. (and (functionp filter) (funcall filter x))
  9376. (and (listp filter)
  9377. (let ((cat-filter (cadr (assoc 'category filter)))
  9378. (evt-filter (cadr (assoc 'headline filter))))
  9379. (or (and (stringp cat-filter)
  9380. (string-match cat-filter cat))
  9381. (and (stringp evt-filter)
  9382. (string-match evt-filter evt)))))))
  9383. (wrn (get-text-property 1 'warntime x)))
  9384. ;; FIXME: Shall we remove text-properties for the appt text?
  9385. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  9386. (when (and ok tod)
  9387. (setq tod (concat "00" (number-to-string tod))
  9388. tod (when (string-match
  9389. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  9390. (concat (match-string 1 tod) ":"
  9391. (match-string 2 tod))))
  9392. (if (version< emacs-version "23.3")
  9393. (appt-add tod evt)
  9394. (appt-add tod evt wrn))
  9395. (setq cnt (1+ cnt))))) entries)
  9396. (org-release-buffers org-agenda-new-buffers)
  9397. (if (eq cnt 0)
  9398. (message "No event to add")
  9399. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  9400. (defun org-agenda-todayp (date)
  9401. "Does DATE mean today, when considering `org-extend-today-until'?"
  9402. (let ((today (org-today))
  9403. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  9404. date)))
  9405. (eq date today)))
  9406. (defun org-agenda-todo-yesterday (&optional arg)
  9407. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  9408. (interactive "P")
  9409. (let* ((hour (third (decode-time
  9410. (org-current-time))))
  9411. (org-extend-today-until (1+ hour)))
  9412. (org-agenda-todo arg)))
  9413. (provide 'org-agenda)
  9414. ;;; org-agenda.el ends here