org-agenda.el 347 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 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. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-datetree-find-date-create "org-datetree"
  63. (date &optional keep-restriction))
  64. (declare-function org-columns-quit "org-colview" ())
  65. (declare-function diary-date-display-form "diary-lib" (&optional type))
  66. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  67. (declare-function org-habit-insert-consistency-graphs
  68. "org-habit" (&optional line))
  69. (declare-function org-is-habit-p "org-habit" (&optional pom))
  70. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  71. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  72. (declare-function org-pop-to-buffer-same-window "org-compat"
  73. (&optional buffer-or-name norecord label))
  74. (defvar calendar-mode-map)
  75. (defvar org-clock-current-task) ; defined in org-clock.el
  76. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  77. (defvar org-habit-show-habits)
  78. (defvar org-habit-show-habits-only-for-today)
  79. (defvar org-habit-show-all-today)
  80. ;; Defined somewhere in this file, but used before definition.
  81. (defvar org-agenda-buffer-name)
  82. (defvar org-agenda-overriding-header)
  83. (defvar org-agenda-title-append nil)
  84. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  85. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  86. (defvar org-agenda-undo-list)
  87. (defvar org-agenda-pending-undo-list)
  88. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  89. (defcustom org-agenda-confirm-kill 1
  90. "When set, remote killing from the agenda buffer needs confirmation.
  91. When t, a confirmation is always needed. When a number N, confirmation is
  92. only needed when the text to be killed contains more than N non-white lines."
  93. :group 'org-agenda
  94. :type '(choice
  95. (const :tag "Never" nil)
  96. (const :tag "Always" t)
  97. (integer :tag "When more than N lines")))
  98. (defcustom org-agenda-compact-blocks nil
  99. "Non-nil means make the block agenda more compact.
  100. This is done globally by leaving out lines like the agenda span
  101. name and week number or the separator lines."
  102. :group 'org-agenda
  103. :type 'boolean)
  104. (defcustom org-agenda-block-separator ?=
  105. "The separator between blocks in the agenda.
  106. If this is a string, it will be used as the separator, with a newline added.
  107. If it is a character, it will be repeated to fill the window width.
  108. If nil the separator is disabled. In `org-agenda-custom-commands' this
  109. addresses the separator between the current and the previous block."
  110. :group 'org-agenda
  111. :type '(choice
  112. (const :tag "Disabled" nil)
  113. (character)
  114. (string)))
  115. (defgroup org-agenda-export nil
  116. "Options concerning exporting agenda views in Org-mode."
  117. :tag "Org Agenda Export"
  118. :group 'org-agenda)
  119. (defcustom org-agenda-with-colors t
  120. "Non-nil means use colors in agenda views."
  121. :group 'org-agenda-export
  122. :type 'boolean)
  123. (defcustom org-agenda-exporter-settings nil
  124. "Alist of variable/value pairs that should be active during agenda export.
  125. This is a good place to set options for ps-print and for htmlize.
  126. Note that the way this is implemented, the values will be evaluated
  127. before assigned to the variables. So make sure to quote values you do
  128. *not* want evaluated, for example
  129. (setq org-agenda-exporter-settings
  130. '((ps-print-color-p 'black-white)))"
  131. :group 'org-agenda-export
  132. :type '(repeat
  133. (list
  134. (variable)
  135. (sexp :tag "Value"))))
  136. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  137. "Hook run in temporary buffer before writing it to an export file.
  138. A useful function is `org-agenda-add-entry-text'."
  139. :group 'org-agenda-export
  140. :type 'hook
  141. :options '(org-agenda-add-entry-text))
  142. (defcustom org-agenda-add-entry-text-maxlines 0
  143. "Maximum number of entry text lines to be added to agenda.
  144. This is only relevant when `org-agenda-add-entry-text' is part of
  145. `org-agenda-before-write-hook', which it is by default.
  146. When this is 0, nothing will happen. When it is greater than 0, it
  147. specifies the maximum number of lines that will be added for each entry
  148. that is listed in the agenda view.
  149. Note that this variable is not used during display, only when exporting
  150. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  151. and `org-agenda-entry-text-maxlines'."
  152. :group 'org-agenda
  153. :type 'integer)
  154. (defcustom org-agenda-add-entry-text-descriptive-links t
  155. "Non-nil means export org-links as descriptive links in agenda added text.
  156. This variable applies to the text added to the agenda when
  157. `org-agenda-add-entry-text-maxlines' is larger than 0.
  158. When this variable nil, the URL will (also) be shown."
  159. :group 'org-agenda
  160. :type 'boolean)
  161. (defcustom org-agenda-export-html-style ""
  162. "The style specification for exported HTML Agenda files.
  163. If this variable contains a string, it will replace the default <style>
  164. section as produced by `htmlize'.
  165. Since there are different ways of setting style information, this variable
  166. needs to contain the full HTML structure to provide a style, including the
  167. surrounding HTML tags. The style specifications should include definitions
  168. the fonts used by the agenda, here is an example:
  169. <style type=\"text/css\">
  170. p { font-weight: normal; color: gray; }
  171. .org-agenda-structure {
  172. font-size: 110%;
  173. color: #003399;
  174. font-weight: 600;
  175. }
  176. .org-todo {
  177. color: #cc6666;
  178. font-weight: bold;
  179. }
  180. .org-agenda-done {
  181. color: #339933;
  182. }
  183. .org-done {
  184. color: #339933;
  185. }
  186. .title { text-align: center; }
  187. .todo, .deadline { color: red; }
  188. .done { color: green; }
  189. </style>
  190. or, if you want to keep the style in a file,
  191. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  192. As the value of this option simply gets inserted into the HTML <head> header,
  193. you can \"misuse\" it to also add other text to the header. However,
  194. <style>...</style> is required, if not present the variable will be ignored."
  195. :group 'org-agenda-export
  196. :group 'org-export-html
  197. :type 'string)
  198. (defcustom org-agenda-persistent-filter nil
  199. "When set, keep filters from one agenda view to the next."
  200. :group 'org-agenda
  201. :type 'boolean)
  202. (defgroup org-agenda-custom-commands nil
  203. "Options concerning agenda views in Org-mode."
  204. :tag "Org Agenda Custom Commands"
  205. :group 'org-agenda)
  206. (defconst org-sorting-choice
  207. '(choice
  208. (const time-up) (const time-down)
  209. (const category-keep) (const category-up) (const category-down)
  210. (const tag-down) (const tag-up)
  211. (const priority-up) (const priority-down)
  212. (const todo-state-up) (const todo-state-down)
  213. (const effort-up) (const effort-down)
  214. (const habit-up) (const habit-down)
  215. (const alpha-up) (const alpha-down)
  216. (const user-defined-up) (const user-defined-down))
  217. "Sorting choices.")
  218. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  219. ;; the new variable `org-agenda-tag-filter-preset'.
  220. (if (fboundp 'defvaralias)
  221. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  222. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  223. (defconst org-agenda-custom-commands-local-options
  224. `(repeat :tag "Local settings for this command. Remember to quote values"
  225. (choice :tag "Setting"
  226. (list :tag "Heading for this block"
  227. (const org-agenda-overriding-header)
  228. (string :tag "Headline"))
  229. (list :tag "Files to be searched"
  230. (const org-agenda-files)
  231. (list
  232. (const :format "" quote)
  233. (repeat (file))))
  234. (list :tag "Sorting strategy"
  235. (const org-agenda-sorting-strategy)
  236. (list
  237. (const :format "" quote)
  238. (repeat
  239. ,org-sorting-choice)))
  240. (list :tag "Prefix format"
  241. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  242. (string))
  243. (list :tag "Number of days in agenda"
  244. (const org-agenda-span)
  245. (choice (const :tag "Day" 'day)
  246. (const :tag "Week" 'week)
  247. (const :tag "Month" 'month)
  248. (const :tag "Year" 'year)
  249. (integer :tag "Custom")))
  250. (list :tag "Fixed starting date"
  251. (const org-agenda-start-day)
  252. (string :value "2007-11-01"))
  253. (list :tag "Start on day of week"
  254. (const org-agenda-start-on-weekday)
  255. (choice :value 1
  256. (const :tag "Today" nil)
  257. (integer :tag "Weekday No.")))
  258. (list :tag "Include data from diary"
  259. (const org-agenda-include-diary)
  260. (boolean))
  261. (list :tag "Deadline Warning days"
  262. (const org-deadline-warning-days)
  263. (integer :value 1))
  264. (list :tag "Category filter preset"
  265. (const org-agenda-category-filter-preset)
  266. (list
  267. (const :format "" quote)
  268. (repeat
  269. (string :tag "+category or -category"))))
  270. (list :tag "Tags filter preset"
  271. (const org-agenda-tag-filter-preset)
  272. (list
  273. (const :format "" quote)
  274. (repeat
  275. (string :tag "+tag or -tag"))))
  276. (list :tag "Set daily/weekly entry types"
  277. (const org-agenda-entry-types)
  278. (list
  279. (const :format "" quote)
  280. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  281. (const :deadline)
  282. (const :scheduled)
  283. (const :timestamp)
  284. (const :sexp))))
  285. (list :tag "Standard skipping condition"
  286. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  287. (const org-agenda-skip-function)
  288. (list
  289. (const :format "" quote)
  290. (list
  291. (choice
  292. :tag "Skipping range"
  293. (const :tag "Skip entry" org-agenda-skip-entry-if)
  294. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  295. (repeat :inline t :tag "Conditions for skipping"
  296. (choice
  297. :tag "Condition type"
  298. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  299. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  300. (list :tag "TODO state is" :inline t
  301. (const 'todo)
  302. (choice
  303. (const :tag "any not-done state" 'todo)
  304. (const :tag "any done state" 'done)
  305. (const :tag "any state" 'any)
  306. (list :tag "Keyword list"
  307. (const :format "" quote)
  308. (repeat (string :tag "Keyword")))))
  309. (list :tag "TODO state is not" :inline t
  310. (const 'nottodo)
  311. (choice
  312. (const :tag "any not-done state" 'todo)
  313. (const :tag "any done state" 'done)
  314. (const :tag "any state" 'any)
  315. (list :tag "Keyword list"
  316. (const :format "" quote)
  317. (repeat (string :tag "Keyword")))))
  318. (const :tag "scheduled" 'scheduled)
  319. (const :tag "not scheduled" 'notscheduled)
  320. (const :tag "deadline" 'deadline)
  321. (const :tag "no deadline" 'notdeadline)
  322. (const :tag "timestamp" 'timestamp)
  323. (const :tag "no timestamp" 'nottimestamp))))))
  324. (list :tag "Non-standard skipping condition"
  325. :value (org-agenda-skip-function)
  326. (const org-agenda-skip-function)
  327. (sexp :tag "Function or form (quoted!)"))
  328. (list :tag "Any variable"
  329. (variable :tag "Variable")
  330. (sexp :tag "Value (sexp)"))))
  331. "Selection of examples for agenda command settings.
  332. This will be spliced into the custom type of
  333. `org-agenda-custom-commands'.")
  334. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  335. ((agenda "") (alltodo))))
  336. "Custom commands for the agenda.
  337. These commands will be offered on the splash screen displayed by the
  338. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  339. (key desc type match settings files)
  340. key The key (one or more characters as a string) to be associated
  341. with the command.
  342. desc A description of the command, when omitted or nil, a default
  343. description is built using MATCH.
  344. type The command type, any of the following symbols:
  345. agenda The daily/weekly agenda.
  346. todo Entries with a specific TODO keyword, in all agenda files.
  347. search Entries containing search words entry or headline.
  348. tags Tags/Property/TODO match in all agenda files.
  349. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  350. todo-tree Sparse tree of specific TODO keyword in *current* file.
  351. tags-tree Sparse tree with all tags matches in *current* file.
  352. occur-tree Occur sparse tree for *current* file.
  353. ... A user-defined function.
  354. match What to search for:
  355. - a single keyword for TODO keyword searches
  356. - a tags match expression for tags searches
  357. - a word search expression for text searches.
  358. - a regular expression for occur searches
  359. For all other commands, this should be the empty string.
  360. settings A list of option settings, similar to that in a let form, so like
  361. this: ((opt1 val1) (opt2 val2) ...). The values will be
  362. evaluated at the moment of execution, so quote them when needed.
  363. files A list of files file to write the produced agenda buffer to
  364. with the command `org-store-agenda-views'.
  365. If a file name ends in \".html\", an HTML version of the buffer
  366. is written out. If it ends in \".ps\", a postscript version is
  367. produced. Otherwise, only the plain text is written to the file.
  368. You can also define a set of commands, to create a composite agenda buffer.
  369. In this case, an entry looks like this:
  370. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  371. where
  372. desc A description string to be displayed in the dispatcher menu.
  373. cmd An agenda command, similar to the above. However, tree commands
  374. are not allowed, but instead you can get agenda and global todo list.
  375. So valid commands for a set are:
  376. (agenda \"\" settings)
  377. (alltodo \"\" settings)
  378. (stuck \"\" settings)
  379. (todo \"match\" settings files)
  380. (search \"match\" settings files)
  381. (tags \"match\" settings files)
  382. (tags-todo \"match\" settings files)
  383. Each command can carry a list of options, and another set of options can be
  384. given for the whole set of commands. Individual command options take
  385. precedence over the general options.
  386. When using several characters as key to a command, the first characters
  387. are prefix commands. For the dispatcher to display useful information, you
  388. should provide a description for the prefix, like
  389. (setq org-agenda-custom-commands
  390. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  391. (\"hl\" tags \"+HOME+Lisa\")
  392. (\"hp\" tags \"+HOME+Peter\")
  393. (\"hk\" tags \"+HOME+Kim\")))"
  394. :group 'org-agenda-custom-commands
  395. :type `(repeat
  396. (choice :value ("x" "Describe command here" tags "" nil)
  397. (list :tag "Single command"
  398. (string :tag "Access Key(s) ")
  399. (option (string :tag "Description"))
  400. (choice
  401. (const :tag "Agenda" agenda)
  402. (const :tag "TODO list" alltodo)
  403. (const :tag "Search words" search)
  404. (const :tag "Stuck projects" stuck)
  405. (const :tag "Tags/Property match (all agenda files)" tags)
  406. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  407. (const :tag "TODO keyword search (all agenda files)" todo)
  408. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  409. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  410. (const :tag "Occur tree (current buffer)" occur-tree)
  411. (sexp :tag "Other, user-defined function"))
  412. (string :tag "Match (only for some commands)")
  413. ,org-agenda-custom-commands-local-options
  414. (option (repeat :tag "Export" (file :tag "Export to"))))
  415. (list :tag "Command series, all agenda files"
  416. (string :tag "Access Key(s)")
  417. (string :tag "Description ")
  418. (repeat :tag "Component"
  419. (choice
  420. (list :tag "Agenda"
  421. (const :format "" agenda)
  422. (const :tag "" :format "" "")
  423. ,org-agenda-custom-commands-local-options)
  424. (list :tag "TODO list (all keywords)"
  425. (const :format "" alltodo)
  426. (const :tag "" :format "" "")
  427. ,org-agenda-custom-commands-local-options)
  428. (list :tag "Search words"
  429. (const :format "" search)
  430. (string :tag "Match")
  431. ,org-agenda-custom-commands-local-options)
  432. (list :tag "Stuck projects"
  433. (const :format "" stuck)
  434. (const :tag "" :format "" "")
  435. ,org-agenda-custom-commands-local-options)
  436. (list :tag "Tags search"
  437. (const :format "" tags)
  438. (string :tag "Match")
  439. ,org-agenda-custom-commands-local-options)
  440. (list :tag "Tags search, TODO entries only"
  441. (const :format "" tags-todo)
  442. (string :tag "Match")
  443. ,org-agenda-custom-commands-local-options)
  444. (list :tag "TODO keyword search"
  445. (const :format "" todo)
  446. (string :tag "Match")
  447. ,org-agenda-custom-commands-local-options)
  448. (list :tag "Other, user-defined function"
  449. (symbol :tag "function")
  450. (string :tag "Match")
  451. ,org-agenda-custom-commands-local-options)))
  452. (repeat :tag "Settings for entire command set"
  453. (list (variable :tag "Any variable")
  454. (sexp :tag "Value")))
  455. (option (repeat :tag "Export" (file :tag "Export to"))))
  456. (cons :tag "Prefix key documentation"
  457. (string :tag "Access Key(s)")
  458. (string :tag "Description ")))))
  459. (defcustom org-agenda-query-register ?o
  460. "The register holding the current query string.
  461. The purpose of this is that if you construct a query string interactively,
  462. you can then use it to define a custom command."
  463. :group 'org-agenda-custom-commands
  464. :type 'character)
  465. (defcustom org-stuck-projects
  466. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  467. "How to identify stuck projects.
  468. This is a list of four items:
  469. 1. A tags/todo/property matcher string that is used to identify a project.
  470. See the manual for a description of tag and property searches.
  471. The entire tree below a headline matched by this is considered one project.
  472. 2. A list of TODO keywords identifying non-stuck projects.
  473. If the project subtree contains any headline with one of these todo
  474. keywords, the project is considered to be not stuck. If you specify
  475. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  476. 3. A list of tags identifying non-stuck projects.
  477. If the project subtree contains any headline with one of these tags,
  478. the project is considered to be not stuck. If you specify \"*\" as
  479. a tag, any tag will mark the project unstuck. Note that this is about
  480. the explicit presence of a tag somewhere in the subtree, inherited
  481. tags to not count here. If inherited tags make a project not stuck,
  482. use \"-TAG\" in the tags part of the matcher under (1.) above.
  483. 4. An arbitrary regular expression matching non-stuck projects.
  484. If the project turns out to be not stuck, search continues also in the
  485. subtree to see if any of the subtasks have project status.
  486. See also the variable `org-tags-match-list-sublevels' which applies
  487. to projects matched by this search as well.
  488. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  489. or `C-c a #' to produce the list."
  490. :group 'org-agenda-custom-commands
  491. :type '(list
  492. (string :tag "Tags/TODO match to identify a project")
  493. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  494. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  495. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  496. (defcustom org-agenda-filter-effort-default-operator "<"
  497. "The default operator for effort estimate filtering.
  498. If you select an effort estimate limit without first pressing an operator,
  499. this one will be used."
  500. :group 'org-agenda-custom-commands
  501. :type '(choice (const :tag "less or equal" "<")
  502. (const :tag "greater or equal"">")
  503. (const :tag "equal" "=")))
  504. (defgroup org-agenda-skip nil
  505. "Options concerning skipping parts of agenda files."
  506. :tag "Org Agenda Skip"
  507. :group 'org-agenda)
  508. (defcustom org-agenda-skip-function-global nil
  509. "Function to be called at each match during agenda construction.
  510. If this function returns nil, the current match should not be skipped.
  511. If the function decided to skip an agenda match, is must return the
  512. buffer position from which the search should be continued.
  513. This may also be a Lisp form, which will be evaluated.
  514. This variable will be applied to every agenda match, including
  515. tags/property searches and TODO lists. So try to make the test function
  516. do its checking as efficiently as possible. To implement a skipping
  517. condition just for specific agenda commands, use the variable
  518. `org-agenda-skip-function' which can be set in the options section
  519. of custom agenda commands."
  520. :group 'org-agenda-skip
  521. :type 'sexp)
  522. (defgroup org-agenda-daily/weekly nil
  523. "Options concerning the daily/weekly agenda."
  524. :tag "Org Agenda Daily/Weekly"
  525. :group 'org-agenda)
  526. (defgroup org-agenda-todo-list nil
  527. "Options concerning the global todo list agenda view."
  528. :tag "Org Agenda Todo List"
  529. :group 'org-agenda)
  530. (defgroup org-agenda-match-view nil
  531. "Options concerning the general tags/property/todo match agenda view."
  532. :tag "Org Agenda Match View"
  533. :group 'org-agenda)
  534. (defgroup org-agenda-search-view nil
  535. "Options concerning the general tags/property/todo match agenda view."
  536. :tag "Org Agenda Match View"
  537. :group 'org-agenda)
  538. (defvar org-agenda-archives-mode nil
  539. "Non-nil means the agenda will include archived items.
  540. If this is the symbol `trees', trees in the selected agenda scope
  541. that are marked with the ARCHIVE tag will be included anyway. When this is
  542. t, also all archive files associated with the current selection of agenda
  543. files will be included.")
  544. (defcustom org-agenda-skip-comment-trees t
  545. "Non-nil means skip trees that start with the COMMENT keyword.
  546. When nil, these trees are also scanned by agenda commands."
  547. :group 'org-agenda-skip
  548. :type 'boolean)
  549. (defcustom org-agenda-todo-list-sublevels t
  550. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  551. When nil, the sublevels of a TODO entry are not checked, resulting in
  552. potentially much shorter TODO lists."
  553. :group 'org-agenda-skip
  554. :group 'org-agenda-todo-list
  555. :type 'boolean)
  556. (defcustom org-agenda-todo-ignore-with-date nil
  557. "Non-nil means don't show entries with a date in the global todo list.
  558. You can use this if you prefer to mark mere appointments with a TODO keyword,
  559. but don't want them to show up in the TODO list.
  560. When this is set, it also covers deadlines and scheduled items, the settings
  561. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  562. will be ignored.
  563. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  564. :group 'org-agenda-skip
  565. :group 'org-agenda-todo-list
  566. :type 'boolean)
  567. (defcustom org-agenda-todo-ignore-timestamp nil
  568. "Non-nil means don't show entries with a timestamp.
  569. This applies when creating the global todo list.
  570. Valid values are:
  571. past Don't show entries for today or in the past.
  572. future Don't show entries with a timestamp in the future.
  573. The idea behind this is that if it has a future
  574. timestamp, you don't want to think about it until the
  575. date.
  576. all Don't show any entries with a timestamp in the global todo list.
  577. The idea behind this is that by setting a timestamp, you
  578. have already \"taken care\" of this item.
  579. This variable can also have an integer as a value. If positive (N),
  580. todos with a timestamp N or more days in the future will be ignored. If
  581. negative (-N), todos with a timestamp N or more days in the past will be
  582. ignored. If 0, todos with a timestamp either today or in the future will
  583. be ignored. For example, a value of -1 will exclude todos with a
  584. timestamp in the past (yesterday or earlier), while a value of 7 will
  585. exclude todos with a timestamp a week or more in the future.
  586. See also `org-agenda-todo-ignore-with-date'.
  587. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  588. to make his option also apply to the tags-todo list."
  589. :group 'org-agenda-skip
  590. :group 'org-agenda-todo-list
  591. :version "24.1"
  592. :type '(choice
  593. (const :tag "Ignore future timestamp todos" future)
  594. (const :tag "Ignore past or present timestamp todos" past)
  595. (const :tag "Ignore all timestamp todos" all)
  596. (const :tag "Show timestamp todos" nil)
  597. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  598. (defcustom org-agenda-todo-ignore-scheduled nil
  599. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  600. This applies when creating the global todo list.
  601. Valid values are:
  602. past Don't show entries scheduled today or in the past.
  603. future Don't show entries scheduled in the future.
  604. The idea behind this is that by scheduling it, you don't want to
  605. think about it until the scheduled date.
  606. all Don't show any scheduled entries in the global todo list.
  607. The idea behind this is that by scheduling it, you have already
  608. \"taken care\" of this item.
  609. t Same as `all', for backward compatibility.
  610. This variable can also have an integer as a value. See
  611. `org-agenda-todo-ignore-timestamp' for more details.
  612. See also `org-agenda-todo-ignore-with-date'.
  613. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  614. to make his option also apply to the tags-todo list."
  615. :group 'org-agenda-skip
  616. :group 'org-agenda-todo-list
  617. :type '(choice
  618. (const :tag "Ignore future-scheduled todos" future)
  619. (const :tag "Ignore past- or present-scheduled todos" past)
  620. (const :tag "Ignore all scheduled todos" all)
  621. (const :tag "Ignore all scheduled todos (compatibility)" t)
  622. (const :tag "Show scheduled todos" nil)
  623. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  624. (defcustom org-agenda-todo-ignore-deadlines nil
  625. "Non-nil means ignore some deadlined TODO items when making TODO list.
  626. There are different motivations for using different values, please think
  627. carefully when configuring this variable.
  628. This applies when creating the global todo list.
  629. Valid values are:
  630. near Don't show near deadline entries. A deadline is near when it is
  631. closer than `org-deadline-warning-days' days. The idea behind this
  632. is that such items will appear in the agenda anyway.
  633. far Don't show TODO entries where a deadline has been defined, but
  634. the deadline is not near. This is useful if you don't want to
  635. use the todo list to figure out what to do now.
  636. past Don't show entries with a deadline timestamp for today or in the past.
  637. future Don't show entries with a deadline timestamp in the future, not even
  638. when they become `near' ones. Use it with caution.
  639. all Ignore all TODO entries that do have a deadline.
  640. t Same as `near', for backward compatibility.
  641. This variable can also have an integer as a value. See
  642. `org-agenda-todo-ignore-timestamp' for more details.
  643. See also `org-agenda-todo-ignore-with-date'.
  644. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  645. to make his option also apply to the tags-todo list."
  646. :group 'org-agenda-skip
  647. :group 'org-agenda-todo-list
  648. :type '(choice
  649. (const :tag "Ignore near deadlines" near)
  650. (const :tag "Ignore near deadlines (compatibility)" t)
  651. (const :tag "Ignore far deadlines" far)
  652. (const :tag "Ignore all TODOs with a deadlines" all)
  653. (const :tag "Show all TODOs, even if they have a deadline" nil)
  654. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  655. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  656. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  657. The variables
  658. `org-agenda-todo-ignore-with-date',
  659. `org-agenda-todo-ignore-timestamp',
  660. `org-agenda-todo-ignore-scheduled',
  661. `org-agenda-todo-ignore-deadlines'
  662. make the global TODO list skip entries that have time stamps of certain
  663. kinds. If this option is set, the same options will also apply for the
  664. tags-todo search, which is the general tags/property matcher
  665. restricted to unfinished TODO entries only."
  666. :group 'org-agenda-skip
  667. :group 'org-agenda-todo-list
  668. :group 'org-agenda-match-view
  669. :type 'boolean)
  670. (defcustom org-agenda-skip-scheduled-if-done nil
  671. "Non-nil means don't show scheduled items in agenda when they are done.
  672. This is relevant for the daily/weekly agenda, not for the TODO list. And
  673. it applies only to the actual date of the scheduling. Warnings about
  674. an item with a past scheduling dates are always turned off when the item
  675. is DONE."
  676. :group 'org-agenda-skip
  677. :group 'org-agenda-daily/weekly
  678. :type 'boolean)
  679. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  680. "Non-nil means skip scheduling line if same entry shows because of deadline.
  681. In the agenda of today, an entry can show up multiple times because
  682. it is both scheduled and has a nearby deadline, and maybe a plain time
  683. stamp as well.
  684. When this variable is t, then only the deadline is shown and the fact that
  685. the entry is scheduled today or was scheduled previously is not shown.
  686. When this variable is nil, the entry will be shown several times. When
  687. the variable is the symbol `not-today', then skip scheduled previously,
  688. but not scheduled today."
  689. :group 'org-agenda-skip
  690. :group 'org-agenda-daily/weekly
  691. :type '(choice
  692. (const :tag "Never" nil)
  693. (const :tag "Always" t)
  694. (const :tag "Not when scheduled today" not-today)))
  695. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  696. "Non-nil means skip timestamp line if same entry shows because of deadline.
  697. In the agenda of today, an entry can show up multiple times
  698. because it has both a plain timestamp and has a nearby deadline.
  699. When this variable is t, then only the deadline is shown and the
  700. fact that the entry has a timestamp for or including today is not
  701. shown. When this variable is nil, the entry will be shown
  702. several times."
  703. :group 'org-agenda-skip
  704. :group 'org-agenda-daily/weekly
  705. :version "24.1"
  706. :type '(choice
  707. (const :tag "Never" nil)
  708. (const :tag "Always" t)))
  709. (defcustom org-agenda-skip-deadline-if-done nil
  710. "Non-nil means don't show deadlines when the corresponding item is done.
  711. When nil, the deadline is still shown and should give you a happy feeling.
  712. This is relevant for the daily/weekly agenda. And it applied only to the
  713. actually date of the deadline. Warnings about approaching and past-due
  714. deadlines are always turned off when the item is DONE."
  715. :group 'org-agenda-skip
  716. :group 'org-agenda-daily/weekly
  717. :type 'boolean)
  718. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  719. "Non-nil means skip deadline prewarning when entry is also scheduled.
  720. This will apply on all days where a prewarning for the deadline would
  721. be shown, but not at the day when the entry is actually due. On that day,
  722. the deadline will be shown anyway.
  723. This variable may be set to nil, t, or a number which will then give
  724. the number of days before the actual deadline when the prewarnings
  725. should resume.
  726. This can be used in a workflow where the first showing of the deadline will
  727. trigger you to schedule it, and then you don't want to be reminded of it
  728. because you will take care of it on the day when scheduled."
  729. :group 'org-agenda-skip
  730. :group 'org-agenda-daily/weekly
  731. :version "24.1"
  732. :type '(choice
  733. (const :tag "Alwas show prewarning" nil)
  734. (const :tag "Remove prewarning if entry is scheduled" t)
  735. (integer :tag "Restart prewarning N days before deadline")))
  736. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  737. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  738. When non-nil, after the search for timestamps has matched once in an
  739. entry, the rest of the entry will not be searched."
  740. :group 'org-agenda-skip
  741. :type 'boolean)
  742. (defcustom org-agenda-skip-timestamp-if-done nil
  743. "Non-nil means don't select item by timestamp or -range if it is DONE."
  744. :group 'org-agenda-skip
  745. :group 'org-agenda-daily/weekly
  746. :type 'boolean)
  747. (defcustom org-agenda-dim-blocked-tasks t
  748. "Non-nil means dim blocked tasks in the agenda display.
  749. This causes some overhead during agenda construction, but if you
  750. have turned on `org-enforce-todo-dependencies',
  751. `org-enforce-todo-checkbox-dependencies', or any other blocking
  752. mechanism, this will create useful feedback in the agenda.
  753. Instead of t, this variable can also have the value `invisible'.
  754. Then blocked tasks will be invisible and only become visible when
  755. they become unblocked. An exemption to this behavior is when a task is
  756. blocked because of unchecked checkboxes below it. Since checkboxes do
  757. not show up in the agenda views, making this task invisible you remove any
  758. trace from agenda views that there is something to do. Therefore, a task
  759. that is blocked because of checkboxes will never be made invisible, it
  760. will only be dimmed."
  761. :group 'org-agenda-daily/weekly
  762. :group 'org-agenda-todo-list
  763. :type '(choice
  764. (const :tag "Do not dim" nil)
  765. (const :tag "Dim to a gray face" t)
  766. (const :tag "Make invisible" invisible)))
  767. (defcustom org-timeline-show-empty-dates 3
  768. "Non-nil means `org-timeline' also shows dates without an entry.
  769. When nil, only the days which actually have entries are shown.
  770. When t, all days between the first and the last date are shown.
  771. When an integer, show also empty dates, but if there is a gap of more than
  772. N days, just insert a special line indicating the size of the gap."
  773. :group 'org-agenda-skip
  774. :type '(choice
  775. (const :tag "None" nil)
  776. (const :tag "All" t)
  777. (integer :tag "at most")))
  778. (defgroup org-agenda-startup nil
  779. "Options concerning initial settings in the Agenda in Org Mode."
  780. :tag "Org Agenda Startup"
  781. :group 'org-agenda)
  782. (defcustom org-agenda-menu-show-matcher t
  783. "Non-nil means show the match string in the agenda dispatcher menu.
  784. When nil, the matcher string is not shown, but is put into the help-echo
  785. property so than moving the mouse over the command shows it.
  786. Setting it to nil is good if matcher strings are very long and/or if
  787. you want to use two-column display (see `org-agenda-menu-two-column')."
  788. :group 'org-agenda
  789. :version "24.1"
  790. :type 'boolean)
  791. (defcustom org-agenda-menu-two-column nil
  792. "Non-nil means, use two columns to show custom commands in the dispatcher.
  793. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  794. to nil."
  795. :group 'org-agenda
  796. :version "24.1"
  797. :type 'boolean)
  798. (defcustom org-finalize-agenda-hook nil
  799. "Hook run just before displaying an agenda buffer."
  800. :group 'org-agenda-startup
  801. :type 'hook)
  802. (defcustom org-agenda-mouse-1-follows-link nil
  803. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  804. A longer mouse click will still set point. Does not work on XEmacs.
  805. Needs to be set before org.el is loaded."
  806. :group 'org-agenda-startup
  807. :type 'boolean)
  808. (defcustom org-agenda-start-with-follow-mode nil
  809. "The initial value of follow mode in a newly created agenda window."
  810. :group 'org-agenda-startup
  811. :type 'boolean)
  812. (defcustom org-agenda-follow-indirect nil
  813. "Non-nil means `org-agenda-follow-mode' displays only the
  814. current item's tree, in an indirect buffer."
  815. :group 'org-agenda
  816. :version "24.1"
  817. :type 'boolean)
  818. (defcustom org-agenda-show-outline-path t
  819. "Non-nil means show outline path in echo area after line motion."
  820. :group 'org-agenda-startup
  821. :type 'boolean)
  822. (defcustom org-agenda-start-with-entry-text-mode nil
  823. "The initial value of entry-text-mode in a newly created agenda window."
  824. :group 'org-agenda-startup
  825. :type 'boolean)
  826. (defcustom org-agenda-entry-text-maxlines 5
  827. "Number of text lines to be added when `E' is pressed in the agenda.
  828. Note that this variable only used during agenda display. Add add entry text
  829. when exporting the agenda, configure the variable
  830. `org-agenda-add-entry-ext-maxlines'."
  831. :group 'org-agenda
  832. :type 'integer)
  833. (defcustom org-agenda-entry-text-exclude-regexps nil
  834. "List of regular expressions to clean up entry text.
  835. The complete matches of all regular expressions in this list will be
  836. removed from entry text before it is shown in the agenda."
  837. :group 'org-agenda
  838. :type '(repeat (regexp)))
  839. (defvar org-agenda-entry-text-cleanup-hook nil
  840. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  841. This cleanup is done in a temporary buffer, so the function may inspect and
  842. change the entire buffer.
  843. Some default stuff like drawers and scheduling/deadline dates will already
  844. have been removed when this is called, as will any matches for regular
  845. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  846. (defvar org-agenda-include-inactive-timestamps nil
  847. "Non-nil means include inactive time stamps in agenda and timeline.
  848. Dynamically scoped.")
  849. (defgroup org-agenda-windows nil
  850. "Options concerning the windows used by the Agenda in Org Mode."
  851. :tag "Org Agenda Windows"
  852. :group 'org-agenda)
  853. (defcustom org-agenda-window-setup 'reorganize-frame
  854. "How the agenda buffer should be displayed.
  855. Possible values for this option are:
  856. current-window Show agenda in the current window, keeping all other windows.
  857. other-window Use `switch-to-buffer-other-window' to display agenda.
  858. reorganize-frame Show only two windows on the current frame, the current
  859. window and the agenda.
  860. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  861. Also, when exiting the agenda, kill that frame.
  862. See also the variable `org-agenda-restore-windows-after-quit'."
  863. :group 'org-agenda-windows
  864. :type '(choice
  865. (const current-window)
  866. (const other-frame)
  867. (const other-window)
  868. (const reorganize-frame)))
  869. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  870. "The min and max height of the agenda window as a fraction of frame height.
  871. The value of the variable is a cons cell with two numbers between 0 and 1.
  872. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  873. :group 'org-agenda-windows
  874. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  875. (defcustom org-agenda-restore-windows-after-quit nil
  876. "Non-nil means restore window configuration upon exiting agenda.
  877. Before the window configuration is changed for displaying the agenda,
  878. the current status is recorded. When the agenda is exited with
  879. `q' or `x' and this option is set, the old state is restored. If
  880. `org-agenda-window-setup' is `other-frame', the value of this
  881. option will be ignored."
  882. :group 'org-agenda-windows
  883. :type 'boolean)
  884. (defcustom org-agenda-ndays nil
  885. "Number of days to include in overview display.
  886. Should be 1 or 7.
  887. Obsolete, see `org-agenda-span'."
  888. :group 'org-agenda-daily/weekly
  889. :type 'integer)
  890. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  891. (defcustom org-agenda-span 'week
  892. "Number of days to include in overview display.
  893. Can be day, week, month, year, or any number of days.
  894. Custom commands can set this variable in the options section."
  895. :group 'org-agenda-daily/weekly
  896. :type '(choice (const :tag "Day" day)
  897. (const :tag "Week" week)
  898. (const :tag "Month" month)
  899. (const :tag "Year" year)
  900. (integer :tag "Custom")))
  901. (defcustom org-agenda-start-on-weekday 1
  902. "Non-nil means start the overview always on the specified weekday.
  903. 0 denotes Sunday, 1 denotes Monday etc.
  904. When nil, always start on the current day.
  905. Custom commands can set this variable in the options section."
  906. :group 'org-agenda-daily/weekly
  907. :type '(choice (const :tag "Today" nil)
  908. (integer :tag "Weekday No.")))
  909. (defcustom org-agenda-show-all-dates t
  910. "Non-nil means `org-agenda' shows every day in the selected range.
  911. When nil, only the days which actually have entries are shown."
  912. :group 'org-agenda-daily/weekly
  913. :type 'boolean)
  914. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  915. "Format string for displaying dates in the agenda.
  916. Used by the daily/weekly agenda and by the timeline. This should be
  917. a format string understood by `format-time-string', or a function returning
  918. the formatted date as a string. The function must take a single argument,
  919. a calendar-style date list like (month day year)."
  920. :group 'org-agenda-daily/weekly
  921. :type '(choice
  922. (string :tag "Format string")
  923. (function :tag "Function")))
  924. (defun org-agenda-format-date-aligned (date)
  925. "Format a date string for display in the daily/weekly agenda, or timeline.
  926. This function makes sure that dates are aligned for easy reading."
  927. (require 'cal-iso)
  928. (let* ((dayname (calendar-day-name date))
  929. (day (cadr date))
  930. (day-of-week (calendar-day-of-week date))
  931. (month (car date))
  932. (monthname (calendar-month-name month))
  933. (year (nth 2 date))
  934. (iso-week (org-days-to-iso-week
  935. (calendar-absolute-from-gregorian date)))
  936. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  937. (1- year))
  938. ((and (= month 12) (<= iso-week 1))
  939. (1+ year))
  940. (t year)))
  941. (weekstring (if (= day-of-week 1)
  942. (format " W%02d" iso-week)
  943. "")))
  944. (format "%-10s %2d %s %4d%s"
  945. dayname day monthname year weekstring)))
  946. (defcustom org-agenda-time-leading-zero nil
  947. "Non-nil means use leading zero for military times in agenda.
  948. For example, 9:30am would become 09:30 rather than 9:30."
  949. :group 'org-agenda-daily/weekly
  950. :version "24.1"
  951. :type 'boolean)
  952. (defcustom org-agenda-timegrid-use-ampm nil
  953. "When set, show AM/PM style timestamps on the timegrid."
  954. :group 'org-agenda
  955. :version "24.1"
  956. :type 'boolean)
  957. (defun org-agenda-time-of-day-to-ampm (time)
  958. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  959. (let* ((hour-number (string-to-number (substring time 0 -3)))
  960. (minute (substring time -2))
  961. (ampm "am"))
  962. (cond
  963. ((equal hour-number 12)
  964. (setq ampm "pm"))
  965. ((> hour-number 12)
  966. (setq ampm "pm")
  967. (setq hour-number (- hour-number 12))))
  968. (concat
  969. (if org-agenda-time-leading-zero
  970. (format "%02d" hour-number)
  971. (format "%02s" (number-to-string hour-number)))
  972. ":" minute ampm)))
  973. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  974. "Conditionally convert TIME to AM/PM format
  975. based on `org-agenda-timegrid-use-ampm'"
  976. (if org-agenda-timegrid-use-ampm
  977. (org-agenda-time-of-day-to-ampm time)
  978. time))
  979. (defcustom org-agenda-weekend-days '(6 0)
  980. "Which days are weekend?
  981. These days get the special face `org-agenda-date-weekend' in the agenda
  982. and timeline buffers."
  983. :group 'org-agenda-daily/weekly
  984. :type '(set :greedy t
  985. (const :tag "Monday" 1)
  986. (const :tag "Tuesday" 2)
  987. (const :tag "Wednesday" 3)
  988. (const :tag "Thursday" 4)
  989. (const :tag "Friday" 5)
  990. (const :tag "Saturday" 6)
  991. (const :tag "Sunday" 0)))
  992. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  993. "Non-nil means jump to today when moving a past date forward in time.
  994. When using S-right in the agenda to move a a date forward, and the date
  995. stamp currently points to the past, the first key press will move it
  996. to today. WHen nil, just move one day forward even if the date stays
  997. in the past."
  998. :group 'org-agenda-daily/weekly
  999. :version "24.1"
  1000. :type 'boolean)
  1001. (defcustom org-agenda-include-diary nil
  1002. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1003. Custom commands can set this variable in the options section."
  1004. :group 'org-agenda-daily/weekly
  1005. :type 'boolean)
  1006. (defcustom org-agenda-include-deadlines t
  1007. "If non-nil, include entries within their deadline warning period.
  1008. Custom commands can set this variable in the options section."
  1009. :group 'org-agenda-daily/weekly
  1010. :version "24.1"
  1011. :type 'boolean)
  1012. (defcustom org-agenda-repeating-timestamp-show-all t
  1013. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1014. When set to a list of strings, only show occurrences of repeating
  1015. stamps for these TODO keywords. When nil, only one occurrence is
  1016. shown, either today or the nearest into the future."
  1017. :group 'org-agenda-daily/weekly
  1018. :type '(choice
  1019. (const :tag "Show repeating stamps" t)
  1020. (repeat :tag "Show repeating stamps for these TODO keywords"
  1021. (string :tag "TODO Keyword"))
  1022. (const :tag "Don't show repeating stamps" nil)))
  1023. (defcustom org-scheduled-past-days 10000
  1024. "No. of days to continue listing scheduled items that are not marked DONE.
  1025. When an item is scheduled on a date, it shows up in the agenda on this
  1026. day and will be listed until it is marked done for the number of days
  1027. given here."
  1028. :group 'org-agenda-daily/weekly
  1029. :type 'integer)
  1030. (defcustom org-agenda-log-mode-items '(closed clock)
  1031. "List of items that should be shown in agenda log mode.
  1032. This list may contain the following symbols:
  1033. closed Show entries that have been closed on that day.
  1034. clock Show entries that have received clocked time on that day.
  1035. state Show all logged state changes.
  1036. Note that instead of changing this variable, you can also press `C-u l' in
  1037. the agenda to display all available LOG items temporarily."
  1038. :group 'org-agenda-daily/weekly
  1039. :type '(set :greedy t (const closed) (const clock) (const state)))
  1040. (defcustom org-agenda-clock-consistency-checks
  1041. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1042. :gap-ok-around ("4:00")
  1043. :default-face ((:background "DarkRed") (:foreground "white"))
  1044. :overlap-face nil :gap-face nil :no-end-time-face nil
  1045. :long-face nil :short-face nil)
  1046. "This is a property list, with the following keys:
  1047. :max-duration Mark clocking chunks that are longer than this time.
  1048. This is a time string like \"HH:MM\", or the number
  1049. of minutes as an integer.
  1050. :min-duration Mark clocking chunks that are shorter that this.
  1051. This is a time string like \"HH:MM\", or the number
  1052. of minutes as an integer.
  1053. :max-gap Mark gaps between clocking chunks that are longer than
  1054. this duration. A number of minutes, or a string
  1055. like \"HH:MM\".
  1056. :gap-ok-around List of times during the day which are usually not working
  1057. times. When a gap is detected, but the gap contains any
  1058. of these times, the gap is *not* reported. For example,
  1059. if this is (\"4:00\" \"13:00\") then gaps that contain
  1060. 4:00 in the morning (i.e. the night) and 13:00
  1061. (i.e. a typical lunch time) do not cause a warning.
  1062. You should have at least one time during the night in this
  1063. list, or otherwise the first task each morning will trigger
  1064. a warning because it follows a long gap.
  1065. Furthermore, the following properties can be used to define faces for
  1066. issue display.
  1067. :default-face the default face, if the specific face is undefined
  1068. :overlap-face face for overlapping clocks
  1069. :gap-face face for gaps between clocks
  1070. :no-end-time-face face for incomplete clocks
  1071. :long-face face for clock intervals that are too long
  1072. :short-face face for clock intervals that are too short"
  1073. :group 'org-agenda-daily/weekly
  1074. :group 'org-clock
  1075. :version "24.1"
  1076. :type 'plist)
  1077. (defcustom org-agenda-log-mode-add-notes t
  1078. "Non-nil means add first line of notes to log entries in agenda views.
  1079. If a log item like a state change or a clock entry is associated with
  1080. notes, the first line of these notes will be added to the entry in the
  1081. agenda display."
  1082. :group 'org-agenda-daily/weekly
  1083. :type 'boolean)
  1084. (defcustom org-agenda-start-with-log-mode nil
  1085. "The initial value of log-mode in a newly created agenda window."
  1086. :group 'org-agenda-startup
  1087. :group 'org-agenda-daily/weekly
  1088. :type 'boolean)
  1089. (defcustom org-agenda-start-with-clockreport-mode nil
  1090. "The initial value of clockreport-mode in a newly created agenda window."
  1091. :group 'org-agenda-startup
  1092. :group 'org-agenda-daily/weekly
  1093. :type 'boolean)
  1094. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1095. "Property list with parameters for the clocktable in clockreport mode.
  1096. This is the display mode that shows a clock table in the daily/weekly
  1097. agenda, the properties for this dynamic block can be set here.
  1098. The usual clocktable parameters are allowed here, but you cannot set
  1099. the properties :name, :tstart, :tend, :block, and :scope - these will
  1100. be overwritten to make sure the content accurately reflects the
  1101. current display in the agenda."
  1102. :group 'org-agenda-daily/weekly
  1103. :type 'plist)
  1104. (defcustom org-agenda-search-view-always-boolean nil
  1105. "Non-nil means the search string is interpreted as individual parts.
  1106. The search string for search view can either be interpreted as a phrase,
  1107. or as a list of snippets that define a boolean search for a number of
  1108. strings.
  1109. When this is non-nil, the string will be split on whitespace, and each
  1110. snippet will be searched individually, and all must match in order to
  1111. select an entry. A snippet is then a single string of non-white
  1112. characters, or a string in double quotes, or a regexp in {} braces.
  1113. If a snippet is preceded by \"-\", the snippet must *not* match.
  1114. \"+\" is syntactic sugar for positive selection. Each snippet may
  1115. be found as a full word or a partial word, but see the variable
  1116. `org-agenda-search-view-force-full-words'.
  1117. When this is nil, search will look for the entire search phrase as one,
  1118. with each space character matching any amount of whitespace, including
  1119. line breaks.
  1120. Even when this is nil, you can still switch to Boolean search dynamically
  1121. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1122. is a regexp marked with braces like \"{abc}\", this will also switch to
  1123. boolean search."
  1124. :group 'org-agenda-search-view
  1125. :version "24.1"
  1126. :type 'boolean)
  1127. (if (fboundp 'defvaralias)
  1128. (defvaralias 'org-agenda-search-view-search-words-only
  1129. 'org-agenda-search-view-always-boolean))
  1130. (defcustom org-agenda-search-view-force-full-words nil
  1131. "Non-nil means, search words must be matches as complete words.
  1132. When nil, they may also match part of a word."
  1133. :group 'org-agenda-search-view
  1134. :version "24.1"
  1135. :type 'boolean)
  1136. (defgroup org-agenda-time-grid nil
  1137. "Options concerning the time grid in the Org-mode Agenda."
  1138. :tag "Org Agenda Time Grid"
  1139. :group 'org-agenda)
  1140. (defcustom org-agenda-search-headline-for-time t
  1141. "Non-nil means search headline for a time-of-day.
  1142. If the headline contains a time-of-day in one format or another, it will
  1143. be used to sort the entry into the time sequence of items for a day.
  1144. Some people have time stamps in the headline that refer to the creation
  1145. time or so, and then this produces an unwanted side effect. If this is
  1146. the case for your, use this variable to turn off searching the headline
  1147. for a time."
  1148. :group 'org-agenda-time-grid
  1149. :type 'boolean)
  1150. (defcustom org-agenda-use-time-grid t
  1151. "Non-nil means show a time grid in the agenda schedule.
  1152. A time grid is a set of lines for specific times (like every two hours between
  1153. 8:00 and 20:00). The items scheduled for a day at specific times are
  1154. sorted in between these lines.
  1155. For details about when the grid will be shown, and what it will look like, see
  1156. the variable `org-agenda-time-grid'."
  1157. :group 'org-agenda-time-grid
  1158. :type 'boolean)
  1159. (defcustom org-agenda-time-grid
  1160. '((daily today require-timed)
  1161. "----------------"
  1162. (800 1000 1200 1400 1600 1800 2000))
  1163. "The settings for time grid for agenda display.
  1164. This is a list of three items. The first item is again a list. It contains
  1165. symbols specifying conditions when the grid should be displayed:
  1166. daily if the agenda shows a single day
  1167. weekly if the agenda shows an entire week
  1168. today show grid on current date, independent of daily/weekly display
  1169. require-timed show grid only if at least one item has a time specification
  1170. The second item is a string which will be placed behind the grid time.
  1171. The third item is a list of integers, indicating the times that should have
  1172. a grid line."
  1173. :group 'org-agenda-time-grid
  1174. :type
  1175. '(list
  1176. (set :greedy t :tag "Grid Display Options"
  1177. (const :tag "Show grid in single day agenda display" daily)
  1178. (const :tag "Show grid in weekly agenda display" weekly)
  1179. (const :tag "Always show grid for today" today)
  1180. (const :tag "Show grid only if any timed entries are present"
  1181. require-timed)
  1182. (const :tag "Skip grid times already present in an entry"
  1183. remove-match))
  1184. (string :tag "Grid String")
  1185. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1186. (defcustom org-agenda-show-current-time-in-grid t
  1187. "Non-nil means show the current time in the time grid."
  1188. :group 'org-agenda-time-grid
  1189. :version "24.1"
  1190. :type 'boolean)
  1191. (defcustom org-agenda-current-time-string
  1192. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1193. "The string for the current time marker in the agenda."
  1194. :group 'org-agenda-time-grid
  1195. :version "24.1"
  1196. :type 'string)
  1197. (defgroup org-agenda-sorting nil
  1198. "Options concerning sorting in the Org-mode Agenda."
  1199. :tag "Org Agenda Sorting"
  1200. :group 'org-agenda)
  1201. (defcustom org-agenda-sorting-strategy
  1202. '((agenda habit-down time-up priority-down category-keep)
  1203. (todo priority-down category-keep)
  1204. (tags priority-down category-keep)
  1205. (search category-keep))
  1206. "Sorting structure for the agenda items of a single day.
  1207. This is a list of symbols which will be used in sequence to determine
  1208. if an entry should be listed before another entry. The following
  1209. symbols are recognized:
  1210. time-up Put entries with time-of-day indications first, early first
  1211. time-down Put entries with time-of-day indications first, late first
  1212. category-keep Keep the default order of categories, corresponding to the
  1213. sequence in `org-agenda-files'.
  1214. category-up Sort alphabetically by category, A-Z.
  1215. category-down Sort alphabetically by category, Z-A.
  1216. tag-up Sort alphabetically by last tag, A-Z.
  1217. tag-down Sort alphabetically by last tag, Z-A.
  1218. priority-up Sort numerically by priority, high priority last.
  1219. priority-down Sort numerically by priority, high priority first.
  1220. todo-state-up Sort by todo state, tasks that are done last.
  1221. todo-state-down Sort by todo state, tasks that are done first.
  1222. effort-up Sort numerically by estimated effort, high effort last.
  1223. effort-down Sort numerically by estimated effort, high effort first.
  1224. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1225. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1226. habit-up Put entries that are habits first
  1227. habit-down Put entries that are habits last
  1228. alpha-up Sort headlines alphabetically
  1229. alpha-down Sort headlines alphabetically, reversed
  1230. The different possibilities will be tried in sequence, and testing stops
  1231. if one comparison returns a \"not-equal\". For example, the default
  1232. '(time-up category-keep priority-down)
  1233. means: Pull out all entries having a specified time of day and sort them,
  1234. in order to make a time schedule for the current day the first thing in the
  1235. agenda listing for the day. Of the entries without a time indication, keep
  1236. the grouped in categories, don't sort the categories, but keep them in
  1237. the sequence given in `org-agenda-files'. Within each category sort by
  1238. priority.
  1239. Leaving out `category-keep' would mean that items will be sorted across
  1240. categories by priority.
  1241. Instead of a single list, this can also be a set of list for specific
  1242. contents, with a context symbol in the car of the list, any of
  1243. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1244. Custom commands can bind this variable in the options section."
  1245. :group 'org-agenda-sorting
  1246. :type `(choice
  1247. (repeat :tag "General" ,org-sorting-choice)
  1248. (list :tag "Individually"
  1249. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1250. (repeat ,org-sorting-choice))
  1251. (cons (const :tag "Strategy for TODO lists" todo)
  1252. (repeat ,org-sorting-choice))
  1253. (cons (const :tag "Strategy for Tags matches" tags)
  1254. (repeat ,org-sorting-choice))
  1255. (cons (const :tag "Strategy for search matches" search)
  1256. (repeat ,org-sorting-choice)))))
  1257. (defcustom org-agenda-cmp-user-defined nil
  1258. "A function to define the comparison `user-defined'.
  1259. This function must receive two arguments, agenda entry a and b.
  1260. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1261. the user comparison, return nil.
  1262. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1263. part of an agenda sorting strategy."
  1264. :group 'org-agenda-sorting
  1265. :type 'symbol)
  1266. (defcustom org-sort-agenda-notime-is-late t
  1267. "Non-nil means items without time are considered late.
  1268. This is only relevant for sorting. When t, items which have no explicit
  1269. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1270. do have a time. When nil, the default time is before 0:00. You can use this
  1271. option to decide if the schedule for today should come before or after timeless
  1272. agenda entries."
  1273. :group 'org-agenda-sorting
  1274. :type 'boolean)
  1275. (defcustom org-sort-agenda-noeffort-is-high t
  1276. "Non-nil means items without effort estimate are sorted as high effort.
  1277. This also applies when filtering an agenda view with respect to the
  1278. < or > effort operator. Then, tasks with no effort defined will be treated
  1279. as tasks with high effort.
  1280. When nil, such items are sorted as 0 minutes effort."
  1281. :group 'org-agenda-sorting
  1282. :type 'boolean)
  1283. (defgroup org-agenda-line-format nil
  1284. "Options concerning the entry prefix in the Org-mode agenda display."
  1285. :tag "Org Agenda Line Format"
  1286. :group 'org-agenda)
  1287. (defcustom org-agenda-prefix-format
  1288. '((agenda . " %i %-12:c%?-12t% s")
  1289. (timeline . " % s")
  1290. (todo . " %i %-12:c")
  1291. (tags . " %i %-12:c")
  1292. (search . " %i %-12:c"))
  1293. "Format specifications for the prefix of items in the agenda views.
  1294. An alist with five entries, each for the different agenda types. The
  1295. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1296. The values are format strings.
  1297. This format works similar to a printf format, with the following meaning:
  1298. %c the category of the item, \"Diary\" for entries from the diary,
  1299. or as given by the CATEGORY keyword or derived from the file name
  1300. %e the effort required by the item
  1301. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1302. %T the last tag of the item (ignore inherited tags, which come first)
  1303. %t the HH:MM time-of-day specification if one applies to the entry
  1304. %s Scheduling/Deadline information, a short string
  1305. %(expression) Eval EXPRESSION and replace the control string
  1306. by the result
  1307. All specifiers work basically like the standard `%s' of printf, but may
  1308. contain two additional characters: a question mark just after the `%'
  1309. and a whitespace/punctuation character just before the final letter.
  1310. If the first character after `%' is a question mark, the entire field
  1311. will only be included if the corresponding value applies to the current
  1312. entry. This is useful for fields which should have fixed width when
  1313. present, but zero width when absent. For example, \"%?-12t\" will
  1314. result in a 12 character time field if a time of the day is specified,
  1315. but will completely disappear in entries which do not contain a time.
  1316. If there is punctuation or whitespace character just before the final
  1317. format letter, this character will be appended to the field value if
  1318. the value is not empty. For example, the format \"%-12:c\" leads to
  1319. \"Diary: \" if the category is \"Diary\". If the category were be
  1320. empty, no additional colon would be inserted.
  1321. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1322. which means:
  1323. - Indent the line with two space characters
  1324. - Give the category a 12 chars wide field, padded with whitespace on
  1325. the right (because of `-'). Append a colon if there is a category
  1326. (because of `:').
  1327. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1328. time, don't put in an empty field, just skip it (because of '?').
  1329. - Finally, put the scheduling information.
  1330. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1331. `org-agenda-remove-tags'.
  1332. Custom commands can set this variable in the options section."
  1333. :type '(choice
  1334. (string :tag "General format")
  1335. (list :greedy t :tag "View dependent"
  1336. (cons (const agenda) (string :tag "Format"))
  1337. (cons (const timeline) (string :tag "Format"))
  1338. (cons (const todo) (string :tag "Format"))
  1339. (cons (const tags) (string :tag "Format"))
  1340. (cons (const search) (string :tag "Format"))))
  1341. :group 'org-agenda-line-format)
  1342. (defvar org-prefix-format-compiled nil
  1343. "The compiled prefix format and associated variables.
  1344. This is a list where first element is a list of variable bindings, and second
  1345. element is the compiled format expression. See the variable
  1346. `org-agenda-prefix-format'.")
  1347. (defcustom org-agenda-todo-keyword-format "%-1s"
  1348. "Format for the TODO keyword in agenda lines.
  1349. Set this to something like \"%-12s\" if you want all TODO keywords
  1350. to occupy a fixed space in the agenda display."
  1351. :group 'org-agenda-line-format
  1352. :type 'string)
  1353. (defcustom org-agenda-diary-sexp-prefix nil
  1354. "A regexp that matches part of a diary sexp entry
  1355. which should be treated as scheduling/deadline information in
  1356. `org-agenda'.
  1357. For example, you can use this to extract the `diary-remind-message' from
  1358. `diary-remind' entries."
  1359. :group 'org-agenda-line-format
  1360. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1361. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1362. "Text preceding timerange entries in the agenda view.
  1363. This is a list with two strings. The first applies when the range
  1364. is entirely on one day. The second applies if the range spans several days.
  1365. The strings may have two \"%d\" format specifiers which will be filled
  1366. with the sequence number of the days, and the total number of days in the
  1367. range, respectively."
  1368. :group 'org-agenda-line-format
  1369. :type '(list
  1370. (string :tag "Deadline today ")
  1371. (choice :tag "Deadline relative"
  1372. (string :tag "Format string")
  1373. (function))))
  1374. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1375. "Text preceding scheduled items in the agenda view.
  1376. This is a list with two strings. The first applies when the item is
  1377. scheduled on the current day. The second applies when it has been scheduled
  1378. previously, it may contain a %d indicating that this is the nth time that
  1379. this item is scheduled, due to automatic rescheduling of unfinished items
  1380. for the following day. So this number is one larger than the number of days
  1381. that passed since this item was scheduled first."
  1382. :group 'org-agenda-line-format
  1383. :type '(list
  1384. (string :tag "Scheduled today ")
  1385. (string :tag "Scheduled previously")))
  1386. (defcustom org-agenda-inactive-leader "["
  1387. "Text preceding item pulled into the agenda by inactive time stamps.
  1388. These entries are added to the agenda when pressing \"[\"."
  1389. :group 'org-agenda-line-format
  1390. :version "24.1"
  1391. :type '(list
  1392. (string :tag "Scheduled today ")
  1393. (string :tag "Scheduled previously")))
  1394. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1395. "Text preceding deadline items in the agenda view.
  1396. This is a list with two strings. The first applies when the item has its
  1397. deadline on the current day. The second applies when it is in the past or
  1398. in the future, it may contain %d to capture how many days away the deadline
  1399. is (was)."
  1400. :group 'org-agenda-line-format
  1401. :type '(list
  1402. (string :tag "Deadline today ")
  1403. (choice :tag "Deadline relative"
  1404. (string :tag "Format string")
  1405. (function))))
  1406. (defcustom org-agenda-remove-times-when-in-prefix t
  1407. "Non-nil means remove duplicate time specifications in agenda items.
  1408. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1409. time-of-day specification in a headline or diary entry is extracted and
  1410. placed into the prefix. If this option is non-nil, the original specification
  1411. \(a timestamp or -range, or just a plain time(range) specification like
  1412. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1413. cluttered.
  1414. The option can be t or nil. It may also be the symbol `beg', indicating
  1415. that the time should only be removed when it is located at the beginning of
  1416. the headline/diary entry."
  1417. :group 'org-agenda-line-format
  1418. :type '(choice
  1419. (const :tag "Always" t)
  1420. (const :tag "Never" nil)
  1421. (const :tag "When at beginning of entry" beg)))
  1422. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1423. "Non-nil means remove time ranges specifications in agenda
  1424. items that span on several days."
  1425. :group 'org-agenda-line-format
  1426. :version "24.1"
  1427. :type 'boolean)
  1428. (defcustom org-agenda-default-appointment-duration nil
  1429. "Default duration for appointments that only have a starting time.
  1430. When nil, no duration is specified in such cases.
  1431. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1432. :group 'org-agenda-line-format
  1433. :type '(choice
  1434. (integer :tag "Minutes")
  1435. (const :tag "No default duration")))
  1436. (defcustom org-agenda-show-inherited-tags t
  1437. "Non-nil means show inherited tags in each agenda line."
  1438. :group 'org-agenda-line-format
  1439. :type 'boolean)
  1440. (defcustom org-agenda-hide-tags-regexp nil
  1441. "Regular expression used to filter away specific tags in agenda views.
  1442. This means that these tags will be present, but not be shown in the agenda
  1443. line. Secondary filtering will still work on the hidden tags.
  1444. Nil means don't hide any tags."
  1445. :group 'org-agenda-line-format
  1446. :type '(choice
  1447. (const :tag "Hide none" nil)
  1448. (string :tag "Regexp ")))
  1449. (defcustom org-agenda-remove-tags nil
  1450. "Non-nil means remove the tags from the headline copy in the agenda.
  1451. When this is the symbol `prefix', only remove tags when
  1452. `org-agenda-prefix-format' contains a `%T' specifier."
  1453. :group 'org-agenda-line-format
  1454. :type '(choice
  1455. (const :tag "Always" t)
  1456. (const :tag "Never" nil)
  1457. (const :tag "When prefix format contains %T" prefix)))
  1458. (if (fboundp 'defvaralias)
  1459. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1460. 'org-agenda-remove-tags))
  1461. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1462. "Shift tags in agenda items to this column.
  1463. If this number is positive, it specifies the column. If it is negative,
  1464. it means that the tags should be flushright to that column. For example,
  1465. -80 works well for a normal 80 character screen."
  1466. :group 'org-agenda-line-format
  1467. :type 'integer)
  1468. (if (fboundp 'defvaralias)
  1469. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1470. (defcustom org-agenda-fontify-priorities 'cookies
  1471. "Non-nil means highlight low and high priorities in agenda.
  1472. When t, the highest priority entries are bold, lowest priority italic.
  1473. However, settings in `org-priority-faces' will overrule these faces.
  1474. When this variable is the symbol `cookies', only fontify the
  1475. cookies, not the entire task.
  1476. This may also be an association list of priority faces, whose
  1477. keys are the character values of `org-highest-priority',
  1478. `org-default-priority', and `org-lowest-priority' (the default values
  1479. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1480. color as a string, or a list like `(:background \"Red\")'.
  1481. If it is a color, the variable `org-faces-easy-properties'
  1482. determines if it is a foreground or a background color."
  1483. :group 'org-agenda-line-format
  1484. :type '(choice
  1485. (const :tag "Never" nil)
  1486. (const :tag "Defaults" t)
  1487. (const :tag "Cookies only" cookies)
  1488. (repeat :tag "Specify"
  1489. (list (character :tag "Priority" :value ?A)
  1490. (choice :tag "Face "
  1491. (string :tag "Color")
  1492. (sexp :tag "Face"))))))
  1493. (defcustom org-agenda-day-face-function nil
  1494. "Function called to determine what face should be used to display a day.
  1495. The only argument passed to that function is the day. It should
  1496. returns a face, or nil if does not want to specify a face and let
  1497. the normal rules apply."
  1498. :group 'org-agenda-line-format
  1499. :version "24.1"
  1500. :type 'function)
  1501. (defcustom org-agenda-category-icon-alist nil
  1502. "Alist of category icon to be displayed in agenda views.
  1503. Each entry should have the following format:
  1504. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1505. Where CATEGORY-REGEXP is a regexp matching the categories where
  1506. the icon should be displayed.
  1507. FILE-OR-DATA either a file path or a string containing image data.
  1508. The other fields can be omitted safely if not needed:
  1509. TYPE indicates the image type.
  1510. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1511. image data.
  1512. PROPS are additional image attributes to assign to the image,
  1513. like, e.g. `:ascent center'.
  1514. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1515. If you want to set the display properties yourself, just put a
  1516. list as second element:
  1517. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1518. For example, to display a 16px horizontal space for Emacs
  1519. category, you can use:
  1520. (\"Emacs\" '(space . (:width (16))))"
  1521. :group 'org-agenda-line-format
  1522. :version "24.1"
  1523. :type '(alist :key-type (string :tag "Regexp matching category")
  1524. :value-type (choice (list :tag "Icon"
  1525. (string :tag "File or data")
  1526. (symbol :tag "Type")
  1527. (boolean :tag "Data?")
  1528. (repeat :tag "Extra image properties" :inline t symbol))
  1529. (list :tag "Display properties" sexp))))
  1530. (defgroup org-agenda-column-view nil
  1531. "Options concerning column view in the agenda."
  1532. :tag "Org Agenda Column View"
  1533. :group 'org-agenda)
  1534. (defcustom org-agenda-columns-show-summaries t
  1535. "Non-nil means show summaries for columns displayed in the agenda view."
  1536. :group 'org-agenda-column-view
  1537. :type 'boolean)
  1538. (defcustom org-agenda-columns-compute-summary-properties t
  1539. "Non-nil means recompute all summary properties before column view.
  1540. When column view in the agenda is listing properties that have a summary
  1541. operator, it can go to all relevant buffers and recompute the summaries
  1542. there. This can mean overhead for the agenda column view, but is necessary
  1543. to have thing up to date.
  1544. As a special case, a CLOCKSUM property also makes sure that the clock
  1545. computations are current."
  1546. :group 'org-agenda-column-view
  1547. :type 'boolean)
  1548. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1549. "Non-nil means the duration of an appointment will add to day effort.
  1550. The property to which appointment durations will be added is the one given
  1551. in the option `org-effort-property'. If an appointment does not have
  1552. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1553. is not set, an appointment without end time will not contribute to the time
  1554. estimate."
  1555. :group 'org-agenda-column-view
  1556. :type 'boolean)
  1557. (defcustom org-agenda-auto-exclude-function nil
  1558. "A function called with a tag to decide if it is filtered on '/ RET'.
  1559. The sole argument to the function, which is called once for each
  1560. possible tag, is a string giving the name of the tag. The
  1561. function should return either nil if the tag should be included
  1562. as normal, or \"-<TAG>\" to exclude the tag.
  1563. Note that for the purpose of tag filtering, only the lower-case version of
  1564. all tags will be considered, so that this function will only ever see
  1565. the lower-case version of all tags."
  1566. :group 'org-agenda
  1567. :type 'function)
  1568. (defcustom org-agenda-bulk-custom-functions nil
  1569. "Alist of characters and custom functions for bulk actions.
  1570. For example, this value makes those two functions available:
  1571. '((?R set-category)
  1572. (?C bulk-cut))
  1573. With selected entries in an agenda buffer, `B R' will call
  1574. the custom function `set-category' on the selected entries.
  1575. Note that functions in this alist don't need to be quoted."
  1576. :type 'alist
  1577. :version "24.1"
  1578. :group 'org-agenda)
  1579. (eval-when-compile
  1580. (require 'cl))
  1581. (require 'org)
  1582. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1583. "Execute BODY with point at location given by `org-hd-marker' property.
  1584. If STRING is non-nil, the text property will be fetched from position 0
  1585. in that string. If STRING is nil, it will be fetched from the beginning
  1586. of the current line."
  1587. (org-with-gensyms (marker)
  1588. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1589. 'org-hd-marker ,string)))
  1590. (with-current-buffer (marker-buffer ,marker)
  1591. (save-excursion
  1592. (goto-char ,marker)
  1593. ,@body)))))
  1594. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1595. (defun org-add-agenda-custom-command (entry)
  1596. "Replace or add a command in `org-agenda-custom-commands'.
  1597. This is mostly for hacking and trying a new command - once the command
  1598. works you probably want to add it to `org-agenda-custom-commands' for good."
  1599. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1600. (if ass
  1601. (setcdr ass (cdr entry))
  1602. (push entry org-agenda-custom-commands))))
  1603. ;;; Define the org-agenda-mode
  1604. (defvar org-agenda-mode-map (make-sparse-keymap)
  1605. "Keymap for `org-agenda-mode'.")
  1606. (if (fboundp 'defvaralias)
  1607. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1608. (defvar org-agenda-menu) ; defined later in this file.
  1609. (defvar org-agenda-restrict) ; defined later in this file.
  1610. (defvar org-agenda-follow-mode nil)
  1611. (defvar org-agenda-entry-text-mode nil)
  1612. (defvar org-agenda-clockreport-mode nil)
  1613. (defvar org-agenda-show-log nil)
  1614. (defvar org-agenda-redo-command nil)
  1615. (defvar org-agenda-query-string nil)
  1616. (defvar org-agenda-mode-hook nil
  1617. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1618. (defvar org-agenda-type nil)
  1619. (defvar org-agenda-force-single-file nil)
  1620. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1621. ;;; Multiple agenda buffers support
  1622. (defcustom org-agenda-sticky nil
  1623. "Non-nil means agenda q key will bury agenda buffers.
  1624. Agenda commands will then show existing buffer instead of generating new ones.
  1625. When nil, `q' will kill the single agenda buffer."
  1626. :group 'org-agenda
  1627. :type 'boolean
  1628. :set (lambda (var val)
  1629. (if (boundp var)
  1630. (org-toggle-sticky-agenda (if val 1 0))
  1631. (set var val))))
  1632. (defun org-toggle-sticky-agenda (&optional arg)
  1633. "Toggle `org-agenda-sticky'."
  1634. (interactive "P")
  1635. (let ((new-value (if arg
  1636. (> (prefix-numeric-value arg) 0)
  1637. (not org-agenda-sticky))))
  1638. (if (equal new-value org-agenda-sticky)
  1639. (and (org-called-interactively-p 'interactive)
  1640. (message "Sticky agenda was already %s"
  1641. (if org-agenda-sticky "enabled" "disabled")))
  1642. (setq org-agenda-sticky new-value)
  1643. (org-agenda-kill-all-agenda-buffers)
  1644. (and (org-called-interactively-p 'interactive)
  1645. (message "Sticky agenda was %s"
  1646. (if org-agenda-sticky "enabled" "disabled"))))))
  1647. (defvar org-agenda-buffer nil
  1648. "Agenda buffer currently being generated.")
  1649. (defvar org-agenda-last-prefix-arg nil)
  1650. (defvar org-agenda-this-buffer-name nil)
  1651. (defvar org-agenda-doing-sticky-redo nil)
  1652. (defvar org-agenda-this-buffer-is-sticky nil)
  1653. (defconst org-agenda-local-vars
  1654. '(org-agenda-this-buffer-name
  1655. org-agenda-undo-list
  1656. org-agenda-pending-undo-list
  1657. org-agenda-follow-mode
  1658. org-agenda-entry-text-mode
  1659. org-agenda-clockreport-mode
  1660. org-agenda-show-log
  1661. org-agenda-redo-command
  1662. org-agenda-query-string
  1663. org-agenda-type
  1664. org-agenda-bulk-marked-entries
  1665. org-agenda-undo-has-started-in
  1666. org-agenda-last-arguments
  1667. org-agenda-info
  1668. org-agenda-tag-filter-overlays
  1669. org-agenda-cat-filter-overlays
  1670. org-pre-agenda-window-conf
  1671. org-agenda-columns-active
  1672. org-agenda-tag-filter
  1673. org-agenda-category-filter
  1674. org-agenda-markers
  1675. org-agenda-last-search-view-search-was-boolean
  1676. org-agenda-filtered-by-category
  1677. org-agenda-filter-form
  1678. org-agenda-show-window
  1679. org-agenda-cycle-counter
  1680. org-agenda-last-prefix-arg)
  1681. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1682. (defun org-agenda-mode ()
  1683. "Mode for time-sorted view on action items in Org-mode files.
  1684. The following commands are available:
  1685. \\{org-agenda-mode-map}"
  1686. (interactive)
  1687. (cond (org-agenda-doing-sticky-redo
  1688. ;; Refreshing sticky agenda-buffer
  1689. ;;
  1690. ;; Preserve the value of `org-agenda-local-vars' variables,
  1691. ;; while letting `kill-all-local-variables' kill the rest
  1692. (let ((save (buffer-local-variables)))
  1693. (kill-all-local-variables)
  1694. (mapc 'make-local-variable org-agenda-local-vars)
  1695. (dolist (elem save)
  1696. (let ((var (car elem))
  1697. (val (cdr elem)))
  1698. (when (and val
  1699. (member var org-agenda-local-vars))
  1700. (set var val)))))
  1701. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1702. (org-agenda-sticky
  1703. ;; Creating a sticky Agenda buffer for the first time
  1704. (kill-all-local-variables)
  1705. (mapc 'make-local-variable org-agenda-local-vars)
  1706. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1707. (t
  1708. ;; Creating a non-sticky agenda buffer
  1709. (kill-all-local-variables)
  1710. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1711. (setq org-agenda-undo-list nil
  1712. org-agenda-pending-undo-list nil
  1713. org-agenda-bulk-marked-entries nil)
  1714. (setq major-mode 'org-agenda-mode)
  1715. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1716. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1717. (setq mode-name "Org-Agenda")
  1718. (use-local-map org-agenda-mode-map)
  1719. (easy-menu-add org-agenda-menu)
  1720. (if org-startup-truncated (setq truncate-lines t))
  1721. (org-set-local 'line-move-visual nil)
  1722. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1723. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1724. ;; Make sure properties are removed when copying text
  1725. (make-local-variable 'filter-buffer-substring-functions)
  1726. (add-hook 'filter-buffer-substring-functions
  1727. (lambda (fun start end delete)
  1728. (substring-no-properties (funcall fun start end delete))))
  1729. (unless org-agenda-keep-modes
  1730. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1731. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1732. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1733. org-agenda-show-log org-agenda-start-with-log-mode))
  1734. (easy-menu-change
  1735. '("Agenda") "Agenda Files"
  1736. (append
  1737. (list
  1738. (vector
  1739. (if (get 'org-agenda-files 'org-restrict)
  1740. "Restricted to single file"
  1741. "Edit File List")
  1742. '(org-edit-agenda-file-list)
  1743. (not (get 'org-agenda-files 'org-restrict)))
  1744. "--")
  1745. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1746. (org-agenda-set-mode-name)
  1747. (apply
  1748. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1749. (list 'org-agenda-mode-hook)))
  1750. (substitute-key-definition 'undo 'org-agenda-undo
  1751. org-agenda-mode-map global-map)
  1752. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1753. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1754. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1755. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1756. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1757. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1758. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1759. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1760. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1761. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1762. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1763. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1764. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1765. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1766. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1767. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1768. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1769. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1770. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1771. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1772. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1773. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1774. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1775. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1776. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1777. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1778. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1779. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1780. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1781. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1782. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1783. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1784. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1785. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1786. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1787. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1788. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1789. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1790. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1791. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1792. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1794. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1795. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1796. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1797. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1798. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1799. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1800. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1801. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1802. (while l (org-defkey org-agenda-mode-map
  1803. (int-to-string (pop l)) 'digit-argument)))
  1804. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1805. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1806. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1807. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1808. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1809. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1810. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1811. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1812. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1813. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1814. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1815. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1816. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1817. 'org-clock-modify-effort-estimate)
  1818. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1819. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1820. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1821. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1822. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1823. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1824. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1825. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1826. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1827. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1828. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1829. (substitute-key-definition 'next-line 'org-agenda-next-line
  1830. org-agenda-mode-map global-map)
  1831. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1832. org-agenda-mode-map global-map)
  1833. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1834. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1835. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1836. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1837. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1838. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1839. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1840. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1841. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1842. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1843. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1844. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1845. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1846. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1847. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1848. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1849. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1850. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1851. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1852. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1853. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1854. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1855. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1856. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1857. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1858. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1859. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1860. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1861. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1862. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1863. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1864. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1865. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1866. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1867. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1868. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1869. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1870. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1871. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1872. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1873. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1874. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1875. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1876. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1877. (when org-agenda-mouse-1-follows-link
  1878. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1879. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1880. '("Agenda"
  1881. ("Agenda Files")
  1882. "--"
  1883. ("Agenda Dates"
  1884. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1885. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1886. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1887. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1888. "--"
  1889. ("View"
  1890. ["Day View" org-agenda-day-view
  1891. :active (org-agenda-check-type nil 'agenda)
  1892. :style radio :selected (eq org-agenda-current-span 'day)
  1893. :keys "v d (or just d)"]
  1894. ["Week View" org-agenda-week-view
  1895. :active (org-agenda-check-type nil 'agenda)
  1896. :style radio :selected (eq org-agenda-current-span 'week)
  1897. :keys "v w (or just w)"]
  1898. ["Month View" org-agenda-month-view
  1899. :active (org-agenda-check-type nil 'agenda)
  1900. :style radio :selected (eq org-agenda-current-span 'month)
  1901. :keys "v m"]
  1902. ["Year View" org-agenda-year-view
  1903. :active (org-agenda-check-type nil 'agenda)
  1904. :style radio :selected (eq org-agenda-current-span 'year)
  1905. :keys "v y"]
  1906. "--"
  1907. ["Include Diary" org-agenda-toggle-diary
  1908. :style toggle :selected org-agenda-include-diary
  1909. :active (org-agenda-check-type nil 'agenda)]
  1910. ["Include Deadlines" org-agenda-toggle-deadlines
  1911. :style toggle :selected org-agenda-include-deadlines
  1912. :active (org-agenda-check-type nil 'agenda)]
  1913. ["Use Time Grid" org-agenda-toggle-time-grid
  1914. :style toggle :selected org-agenda-use-time-grid
  1915. :active (org-agenda-check-type nil 'agenda)]
  1916. "--"
  1917. ["Show clock report" org-agenda-clockreport-mode
  1918. :style toggle :selected org-agenda-clockreport-mode
  1919. :active (org-agenda-check-type nil 'agenda)]
  1920. ["Show some entry text" org-agenda-entry-text-mode
  1921. :style toggle :selected org-agenda-entry-text-mode
  1922. :active t]
  1923. "--"
  1924. ["Show Logbook entries" org-agenda-log-mode
  1925. :style toggle :selected org-agenda-show-log
  1926. :active (org-agenda-check-type nil 'agenda 'timeline)
  1927. :keys "v l (or just l)"]
  1928. ["Include archived trees" org-agenda-archives-mode
  1929. :style toggle :selected org-agenda-archives-mode :active t
  1930. :keys "v a"]
  1931. ["Include archive files" (org-agenda-archives-mode t)
  1932. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1933. :keys "v A"]
  1934. "--"
  1935. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1936. ["Write view to file" org-agenda-write t]
  1937. ["Rebuild buffer" org-agenda-redo t]
  1938. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1939. "--"
  1940. ["Show original entry" org-agenda-show t]
  1941. ["Go To (other window)" org-agenda-goto t]
  1942. ["Go To (this window)" org-agenda-switch-to t]
  1943. ["Follow Mode" org-agenda-follow-mode
  1944. :style toggle :selected org-agenda-follow-mode :active t]
  1945. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1946. "--"
  1947. ("TODO"
  1948. ["Cycle TODO" org-agenda-todo t]
  1949. ["Next TODO set" org-agenda-todo-nextset t]
  1950. ["Previous TODO set" org-agenda-todo-previousset t]
  1951. ["Add note" org-agenda-add-note t])
  1952. ("Archive/Refile/Delete"
  1953. ["Archive default" org-agenda-archive-default t]
  1954. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1955. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1956. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1957. ["Archive subtree" org-agenda-archive t]
  1958. "--"
  1959. ["Refile" org-agenda-refile t]
  1960. "--"
  1961. ["Delete subtree" org-agenda-kill t])
  1962. ("Bulk action"
  1963. ["Mark entry" org-agenda-bulk-mark t]
  1964. ["Mark all" org-agenda-bulk-mark-all t]
  1965. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1966. ["Unmark entry" org-agenda-bulk-unmark t]
  1967. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "C-u s"])
  1968. ["Act on all marked" org-agenda-bulk-action t]
  1969. "--"
  1970. ("Tags and Properties"
  1971. ["Show all Tags" org-agenda-show-tags t]
  1972. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1973. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1974. "--"
  1975. ["Column View" org-columns t])
  1976. ("Deadline/Schedule"
  1977. ["Schedule" org-agenda-schedule t]
  1978. ["Set Deadline" org-agenda-deadline t]
  1979. "--"
  1980. ["Mark item" org-agenda-action :active t :keys "k m"]
  1981. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1982. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1983. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1984. "--"
  1985. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1986. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1987. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1988. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1989. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1990. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1991. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1992. ("Clock and Effort"
  1993. ["Clock in" org-agenda-clock-in t]
  1994. ["Clock out" org-agenda-clock-out t]
  1995. ["Clock cancel" org-agenda-clock-cancel t]
  1996. ["Goto running clock" org-clock-goto t]
  1997. "--"
  1998. ["Set Effort" org-agenda-set-effort t]
  1999. ["Change clocked effort" org-clock-modify-effort-estimate
  2000. (org-clock-is-active)])
  2001. ("Priority"
  2002. ["Set Priority" org-agenda-priority t]
  2003. ["Increase Priority" org-agenda-priority-up t]
  2004. ["Decrease Priority" org-agenda-priority-down t]
  2005. ["Show Priority" org-agenda-show-priority t])
  2006. ("Calendar/Diary"
  2007. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2008. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2009. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2010. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2011. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2012. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2013. "--"
  2014. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2015. "--"
  2016. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2017. "--"
  2018. ("MobileOrg"
  2019. ["Push Files and Views" org-mobile-push t]
  2020. ["Get Captured and Flagged" org-mobile-pull t]
  2021. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2022. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2023. "--"
  2024. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2025. "--"
  2026. ["Quit" org-agenda-quit t]
  2027. ["Exit and Release Buffers" org-agenda-exit t]
  2028. ))
  2029. ;;; Agenda undo
  2030. (defvar org-agenda-allow-remote-undo t
  2031. "Non-nil means allow remote undo from the agenda buffer.")
  2032. (defvar org-agenda-undo-list nil
  2033. "List of undoable operations in the agenda since last refresh.")
  2034. (defvar org-agenda-undo-has-started-in nil
  2035. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2036. (defvar org-agenda-pending-undo-list nil
  2037. "In a series of undo commands, this is the list of remaining undo items.")
  2038. (defun org-agenda-undo ()
  2039. "Undo a remote editing step in the agenda.
  2040. This undoes changes both in the agenda buffer and in the remote buffer
  2041. that have been changed along."
  2042. (interactive)
  2043. (or org-agenda-allow-remote-undo
  2044. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2045. (if (not (eq this-command last-command))
  2046. (setq org-agenda-undo-has-started-in nil
  2047. org-agenda-pending-undo-list org-agenda-undo-list))
  2048. (if (not org-agenda-pending-undo-list)
  2049. (error "No further undo information"))
  2050. (let* ((entry (pop org-agenda-pending-undo-list))
  2051. buf line cmd rembuf)
  2052. (setq cmd (pop entry) line (pop entry))
  2053. (setq rembuf (nth 2 entry))
  2054. (org-with-remote-undo rembuf
  2055. (while (bufferp (setq buf (pop entry)))
  2056. (if (pop entry)
  2057. (with-current-buffer buf
  2058. (let ((last-undo-buffer buf)
  2059. (inhibit-read-only t))
  2060. (unless (memq buf org-agenda-undo-has-started-in)
  2061. (push buf org-agenda-undo-has-started-in)
  2062. (make-local-variable 'pending-undo-list)
  2063. (undo-start))
  2064. (while (and pending-undo-list
  2065. (listp pending-undo-list)
  2066. (not (car pending-undo-list)))
  2067. (pop pending-undo-list))
  2068. (undo-more 1))))))
  2069. (org-goto-line line)
  2070. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2071. (defun org-verify-change-for-undo (l1 l2)
  2072. "Verify that a real change occurred between the undo lists L1 and L2."
  2073. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2074. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2075. (not (eq l1 l2)))
  2076. ;;; Agenda dispatch
  2077. (defvar org-agenda-restrict nil)
  2078. (defvar org-agenda-restrict-begin (make-marker))
  2079. (defvar org-agenda-restrict-end (make-marker))
  2080. (defvar org-agenda-last-dispatch-buffer nil)
  2081. (defvar org-agenda-overriding-restriction nil)
  2082. ;;;###autoload
  2083. (defun org-agenda (&optional arg keys restriction)
  2084. "Dispatch agenda commands to collect entries to the agenda buffer.
  2085. Prompts for a command to execute. Any prefix arg will be passed
  2086. on to the selected command. The default selections are:
  2087. a Call `org-agenda-list' to display the agenda for current day or week.
  2088. t Call `org-todo-list' to display the global todo list.
  2089. T Call `org-todo-list' to display the global todo list, select only
  2090. entries with a specific TODO keyword (the user gets a prompt).
  2091. m Call `org-tags-view' to display headlines with tags matching
  2092. a condition (the user is prompted for the condition).
  2093. M Like `m', but select only TODO entries, no ordinary headlines.
  2094. L Create a timeline for the current buffer.
  2095. e Export views to associated files.
  2096. s Search entries for keywords.
  2097. / Multi occur across all agenda files and also files listed
  2098. in `org-agenda-text-search-extra-files'.
  2099. < Restrict agenda commands to buffer, subtree, or region.
  2100. Press several times to get the desired effect.
  2101. > Remove a previous restriction.
  2102. # List \"stuck\" projects.
  2103. ! Configure what \"stuck\" means.
  2104. C Configure custom agenda commands.
  2105. More commands can be added by configuring the variable
  2106. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2107. searches can be pre-defined in this way.
  2108. If the current buffer is in Org-mode and visiting a file, you can also
  2109. first press `<' once to indicate that the agenda should be temporarily
  2110. \(until the next use of \\[org-agenda]) restricted to the current file.
  2111. Pressing `<' twice means to restrict to the current subtree or region
  2112. \(if active)."
  2113. (interactive "P")
  2114. (catch 'exit
  2115. (let* ((prefix-descriptions nil)
  2116. (org-agenda-buffer-name org-agenda-buffer-name)
  2117. (org-agenda-window-setup (if (equal (buffer-name)
  2118. org-agenda-buffer-name)
  2119. 'current-window
  2120. org-agenda-window-setup))
  2121. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2122. (org-agenda-custom-commands
  2123. ;; normalize different versions
  2124. (delq nil
  2125. (mapcar
  2126. (lambda (x)
  2127. (cond ((stringp (cdr x))
  2128. (push x prefix-descriptions)
  2129. nil)
  2130. ((stringp (nth 1 x)) x)
  2131. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2132. (t (cons (car x) (cons "" (cdr x))))))
  2133. org-agenda-custom-commands)))
  2134. (buf (current-buffer))
  2135. (bfn (buffer-file-name (buffer-base-buffer)))
  2136. entry key type match lprops ans)
  2137. ;; Turn off restriction unless there is an overriding one,
  2138. (unless org-agenda-overriding-restriction
  2139. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2140. ;; There is a request to keep the file list in place
  2141. (put 'org-agenda-files 'org-restrict nil))
  2142. (setq org-agenda-restrict nil)
  2143. (move-marker org-agenda-restrict-begin nil)
  2144. (move-marker org-agenda-restrict-end nil))
  2145. ;; Delete old local properties
  2146. (put 'org-agenda-redo-command 'org-lprops nil)
  2147. ;; Delete previously set last-arguments
  2148. (put 'org-agenda-redo-command 'last-args nil)
  2149. ;; Remember where this call originated
  2150. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2151. (unless keys
  2152. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2153. keys (car ans)
  2154. restriction (cdr ans)))
  2155. ;; If we have sticky agenda buffers, set a name for the buffer,
  2156. ;; depending on the invoking keys. The user may still set this
  2157. ;; as a command option, which will overwrite what we do here.
  2158. (if org-agenda-sticky
  2159. (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
  2160. ;; Establish the restriction, if any
  2161. (when (and (not org-agenda-overriding-restriction) restriction)
  2162. (put 'org-agenda-files 'org-restrict (list bfn))
  2163. (cond
  2164. ((eq restriction 'region)
  2165. (setq org-agenda-restrict t)
  2166. (move-marker org-agenda-restrict-begin (region-beginning))
  2167. (move-marker org-agenda-restrict-end (region-end)))
  2168. ((eq restriction 'subtree)
  2169. (save-excursion
  2170. (setq org-agenda-restrict t)
  2171. (org-back-to-heading t)
  2172. (move-marker org-agenda-restrict-begin (point))
  2173. (move-marker org-agenda-restrict-end
  2174. (progn (org-end-of-subtree t)))))))
  2175. ;; For example the todo list should not need it (but does...)
  2176. (cond
  2177. ((setq entry (assoc keys org-agenda-custom-commands))
  2178. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2179. (progn
  2180. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2181. lprops (nth 4 entry))
  2182. (put 'org-agenda-redo-command 'org-lprops lprops)
  2183. (cond
  2184. ((eq type 'agenda)
  2185. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2186. ((eq type 'alltodo)
  2187. (org-let lprops '(org-todo-list current-prefix-arg)))
  2188. ((eq type 'search)
  2189. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2190. ((eq type 'stuck)
  2191. (org-let lprops '(org-agenda-list-stuck-projects
  2192. current-prefix-arg)))
  2193. ((eq type 'tags)
  2194. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2195. ((eq type 'tags-todo)
  2196. (org-let lprops '(org-tags-view '(4) match)))
  2197. ((eq type 'todo)
  2198. (org-let lprops '(org-todo-list match)))
  2199. ((eq type 'tags-tree)
  2200. (org-check-for-org-mode)
  2201. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2202. ((eq type 'todo-tree)
  2203. (org-check-for-org-mode)
  2204. (org-let lprops
  2205. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2206. (regexp-quote match) "\\>"))))
  2207. ((eq type 'occur-tree)
  2208. (org-check-for-org-mode)
  2209. (org-let lprops '(org-occur match)))
  2210. ((functionp type)
  2211. (org-let lprops '(funcall type match)))
  2212. ((fboundp type)
  2213. (org-let lprops '(funcall type match)))
  2214. (t (error "Invalid custom agenda command type %s" type))))
  2215. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2216. ((equal keys "C")
  2217. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2218. (customize-variable 'org-agenda-custom-commands))
  2219. ((equal keys "a") (call-interactively 'org-agenda-list))
  2220. ((equal keys "s") (call-interactively 'org-search-view))
  2221. ((equal keys "t") (call-interactively 'org-todo-list))
  2222. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2223. ((equal keys "m") (call-interactively 'org-tags-view))
  2224. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2225. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2226. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2227. (org-add-hook
  2228. 'post-command-hook
  2229. (lambda ()
  2230. (unless (current-message)
  2231. (let* ((m (org-agenda-get-any-marker))
  2232. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2233. (when note
  2234. (message (concat
  2235. "FLAGGING-NOTE ([?] for more info): "
  2236. (org-add-props
  2237. (replace-regexp-in-string
  2238. "\\\\n" "//"
  2239. (copy-sequence note))
  2240. nil 'face 'org-warning)))))))
  2241. t t))
  2242. ((equal keys "L")
  2243. (unless (derived-mode-p 'org-mode)
  2244. (error "This is not an Org-mode file"))
  2245. (unless restriction
  2246. (put 'org-agenda-files 'org-restrict (list bfn))
  2247. (org-call-with-arg 'org-timeline arg)))
  2248. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2249. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2250. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2251. (t (error "Invalid agenda key"))))))
  2252. (defun org-agenda-append-agenda ()
  2253. "Append another agenda view to the current one.
  2254. This function allows interactive building of block agendas.
  2255. Agenda views are separated by `org-agenda-block-separator'."
  2256. (interactive)
  2257. (unless (string= (buffer-name) org-agenda-buffer-name)
  2258. (error "Can only append from within agenda buffer"))
  2259. (let ((org-agenda-multi t))
  2260. (org-agenda)
  2261. (widen)))
  2262. (defun org-agenda-normalize-custom-commands (cmds)
  2263. (delq nil
  2264. (mapcar
  2265. (lambda (x)
  2266. (cond ((stringp (cdr x)) nil)
  2267. ((stringp (nth 1 x)) x)
  2268. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2269. (t (cons (car x) (cons "" (cdr x))))))
  2270. cmds)))
  2271. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2272. "The user interface for selecting an agenda command."
  2273. (catch 'exit
  2274. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2275. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2276. (region-p (org-region-active-p))
  2277. (custom org-agenda-custom-commands)
  2278. (selstring "")
  2279. restriction second-time
  2280. c entry key type match prefixes rmheader header-end custom1 desc
  2281. line lines left right n n1)
  2282. (save-window-excursion
  2283. (delete-other-windows)
  2284. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2285. (erase-buffer)
  2286. (insert (eval-when-compile
  2287. (let ((header
  2288. "Press key for an agenda command: < Buffer, subtree/region restriction
  2289. -------------------------------- > Remove restriction
  2290. a Agenda for current week or day e Export agenda views
  2291. t List of all TODO entries T Entries with special TODO kwd
  2292. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2293. L Timeline for current buffer # List stuck projects (!=configure)
  2294. s Search for keywords * Toggle sticky agenda views
  2295. / Multi-occur ? Find :FLAGGED: entries
  2296. C Configure custom agenda commands
  2297. ")
  2298. (start 0))
  2299. (while (string-match
  2300. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2301. header start)
  2302. (setq start (match-end 0))
  2303. (add-text-properties (match-beginning 2) (match-end 2)
  2304. '(face bold) header))
  2305. header)))
  2306. (setq header-end (move-marker (make-marker) (point)))
  2307. (while t
  2308. (setq custom1 custom)
  2309. (when (eq rmheader t)
  2310. (org-goto-line 1)
  2311. (re-search-forward ":" nil t)
  2312. (delete-region (match-end 0) (point-at-eol))
  2313. (forward-char 1)
  2314. (looking-at "-+")
  2315. (delete-region (match-end 0) (point-at-eol))
  2316. (move-marker header-end (match-end 0)))
  2317. (goto-char header-end)
  2318. (delete-region (point) (point-max))
  2319. ;; Produce all the lines that describe custom commands and prefixes
  2320. (setq lines nil)
  2321. (while (setq entry (pop custom1))
  2322. (setq key (car entry) desc (nth 1 entry)
  2323. type (nth 2 entry)
  2324. match (nth 3 entry))
  2325. (if (> (length key) 1)
  2326. (add-to-list 'prefixes (string-to-char key))
  2327. (setq line
  2328. (format
  2329. "%-4s%-14s"
  2330. (org-add-props (copy-sequence key)
  2331. '(face bold))
  2332. (cond
  2333. ((string-match "\\S-" desc) desc)
  2334. ((eq type 'agenda) "Agenda for current week or day")
  2335. ((eq type 'alltodo) "List of all TODO entries")
  2336. ((eq type 'search) "Word search")
  2337. ((eq type 'stuck) "List of stuck projects")
  2338. ((eq type 'todo) "TODO keyword")
  2339. ((eq type 'tags) "Tags query")
  2340. ((eq type 'tags-todo) "Tags (TODO)")
  2341. ((eq type 'tags-tree) "Tags tree")
  2342. ((eq type 'todo-tree) "TODO kwd tree")
  2343. ((eq type 'occur-tree) "Occur tree")
  2344. ((functionp type) (if (symbolp type)
  2345. (symbol-name type)
  2346. "Lambda expression"))
  2347. (t "???"))))
  2348. (if org-agenda-menu-show-matcher
  2349. (setq line
  2350. (concat line ": "
  2351. (cond
  2352. ((stringp match)
  2353. (setq match (copy-sequence match))
  2354. (org-add-props match nil 'face 'org-warning))
  2355. (match
  2356. (format "set of %d commands" (length match)))
  2357. (t ""))))
  2358. (if (org-string-nw-p match)
  2359. (add-text-properties
  2360. 0 (length line) (list 'help-echo
  2361. (concat "Matcher: "match)) line)))
  2362. (push line lines)))
  2363. (setq lines (nreverse lines))
  2364. (when prefixes
  2365. (mapc (lambda (x)
  2366. (push
  2367. (format "%s %s"
  2368. (org-add-props (char-to-string x)
  2369. nil 'face 'bold)
  2370. (or (cdr (assoc (concat selstring
  2371. (char-to-string x))
  2372. prefix-descriptions))
  2373. "Prefix key"))
  2374. lines))
  2375. prefixes))
  2376. ;; Check if we should display in two columns
  2377. (if org-agenda-menu-two-column
  2378. (progn
  2379. (setq n (length lines)
  2380. n1 (+ (/ n 2) (mod n 2))
  2381. right (nthcdr n1 lines)
  2382. left (copy-sequence lines))
  2383. (setcdr (nthcdr (1- n1) left) nil))
  2384. (setq left lines right nil))
  2385. (while left
  2386. (insert "\n" (pop left))
  2387. (when right
  2388. (if (< (current-column) 40)
  2389. (move-to-column 40 t)
  2390. (insert " "))
  2391. (insert (pop right))))
  2392. ;; Make the window the right size
  2393. (goto-char (point-min))
  2394. (if second-time
  2395. (if (not (pos-visible-in-window-p (point-max)))
  2396. (org-fit-window-to-buffer))
  2397. (setq second-time t)
  2398. (org-fit-window-to-buffer))
  2399. ;; Ask for selection
  2400. (message "Press key for agenda command%s:"
  2401. (if (or restrict-ok org-agenda-overriding-restriction)
  2402. (if org-agenda-overriding-restriction
  2403. " (restriction lock active)"
  2404. (if restriction
  2405. (format " (restricted to %s)" restriction)
  2406. " (unrestricted)"))
  2407. ""))
  2408. (setq c (read-char-exclusive))
  2409. (message "")
  2410. (cond
  2411. ((assoc (char-to-string c) custom)
  2412. (setq selstring (concat selstring (char-to-string c)))
  2413. (throw 'exit (cons selstring restriction)))
  2414. ((memq c prefixes)
  2415. (setq selstring (concat selstring (char-to-string c))
  2416. prefixes nil
  2417. rmheader (or rmheader t)
  2418. custom (delq nil (mapcar
  2419. (lambda (x)
  2420. (if (or (= (length (car x)) 1)
  2421. (/= (string-to-char (car x)) c))
  2422. nil
  2423. (cons (substring (car x) 1) (cdr x))))
  2424. custom))))
  2425. ((eq c ?*)
  2426. (call-interactively 'org-toggle-sticky-agenda)
  2427. (sit-for 2))
  2428. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2429. (message "Restriction is only possible in Org-mode buffers")
  2430. (ding) (sit-for 1))
  2431. ((eq c ?1)
  2432. (org-agenda-remove-restriction-lock 'noupdate)
  2433. (setq restriction 'buffer))
  2434. ((eq c ?0)
  2435. (org-agenda-remove-restriction-lock 'noupdate)
  2436. (setq restriction (if region-p 'region 'subtree)))
  2437. ((eq c ?<)
  2438. (org-agenda-remove-restriction-lock 'noupdate)
  2439. (setq restriction
  2440. (cond
  2441. ((eq restriction 'buffer)
  2442. (if region-p 'region 'subtree))
  2443. ((memq restriction '(subtree region))
  2444. nil)
  2445. (t 'buffer))))
  2446. ((eq c ?>)
  2447. (org-agenda-remove-restriction-lock 'noupdate)
  2448. (setq restriction nil))
  2449. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2450. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2451. ((and (> (length selstring) 0) (eq c ?\d))
  2452. (delete-window)
  2453. (org-agenda-get-restriction-and-command prefix-descriptions))
  2454. ((equal c ?q) (error "Abort"))
  2455. (t (error "Invalid key %c" c))))))))
  2456. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2457. (defvar org-agenda-last-arguments nil
  2458. "The arguments of the previous call to `org-agenda'.")
  2459. (defun org-agenda-run-series (name series)
  2460. (org-let (nth 1 series) '(org-prepare-agenda name))
  2461. ;; We need to reset agenda markers here, because when constructing a
  2462. ;; block agenda, the individual blocks do not do that.
  2463. (org-agenda-reset-markers)
  2464. (let* ((org-agenda-multi t)
  2465. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2466. (org-agenda-overriding-arguments
  2467. (or org-agenda-overriding-arguments
  2468. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2469. (get 'org-agenda-redo-command 'last-args))))
  2470. (cmds (car series))
  2471. (gprops (nth 1 series))
  2472. match ;; The byte compiler incorrectly complains about this. Keep it!
  2473. cmd type lprops)
  2474. (while (setq cmd (pop cmds))
  2475. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2476. (cond
  2477. ((eq type 'agenda)
  2478. (org-let2 gprops lprops
  2479. '(call-interactively 'org-agenda-list)))
  2480. ((eq type 'alltodo)
  2481. (org-let2 gprops lprops
  2482. '(call-interactively 'org-todo-list)))
  2483. ((eq type 'search)
  2484. (org-let2 gprops lprops
  2485. '(org-search-view current-prefix-arg match nil)))
  2486. ((eq type 'stuck)
  2487. (org-let2 gprops lprops
  2488. '(call-interactively 'org-agenda-list-stuck-projects)))
  2489. ((eq type 'tags)
  2490. (org-let2 gprops lprops
  2491. '(org-tags-view current-prefix-arg match)))
  2492. ((eq type 'tags-todo)
  2493. (org-let2 gprops lprops
  2494. '(org-tags-view '(4) match)))
  2495. ((eq type 'todo)
  2496. (org-let2 gprops lprops
  2497. '(org-todo-list match)))
  2498. ((fboundp type)
  2499. (org-let2 gprops lprops
  2500. '(funcall type match)))
  2501. (t (error "Invalid type in command series"))))
  2502. (widen)
  2503. (setq org-agenda-redo-command redo)
  2504. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2505. (goto-char (point-min)))
  2506. (org-fit-agenda-window)
  2507. (org-let (nth 1 series) '(org-finalize-agenda)))
  2508. ;;;###autoload
  2509. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2510. "Run an agenda command in batch mode and send the result to STDOUT.
  2511. If CMD-KEY is a string of length 1, it is used as a key in
  2512. `org-agenda-custom-commands' and triggers this command. If it is a
  2513. longer string it is used as a tags/todo match string.
  2514. Parameters are alternating variable names and values that will be bound
  2515. before running the agenda command."
  2516. (org-eval-in-environment (org-make-parameter-alist parameters)
  2517. (if (> (length cmd-key) 2)
  2518. (org-tags-view nil cmd-key)
  2519. (org-agenda nil cmd-key)))
  2520. (set-buffer org-agenda-buffer-name)
  2521. (princ (buffer-string)))
  2522. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2523. (defvar org-agenda-info nil)
  2524. ;;;###autoload
  2525. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2526. "Run an agenda command in batch mode and send the result to STDOUT.
  2527. If CMD-KEY is a string of length 1, it is used as a key in
  2528. `org-agenda-custom-commands' and triggers this command. If it is a
  2529. longer string it is used as a tags/todo match string.
  2530. Parameters are alternating variable names and values that will be bound
  2531. before running the agenda command.
  2532. The output gives a line for each selected agenda item. Each
  2533. item is a list of comma-separated values, like this:
  2534. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2535. category The category of the item
  2536. head The headline, without TODO kwd, TAGS and PRIORITY
  2537. type The type of the agenda entry, can be
  2538. todo selected in TODO match
  2539. tagsmatch selected in tags match
  2540. diary imported from diary
  2541. deadline a deadline on given date
  2542. scheduled scheduled on given date
  2543. timestamp entry has timestamp on given date
  2544. closed entry was closed on given date
  2545. upcoming-deadline warning about deadline
  2546. past-scheduled forwarded scheduled item
  2547. block entry has date block including g. date
  2548. todo The todo keyword, if any
  2549. tags All tags including inherited ones, separated by colons
  2550. date The relevant date, like 2007-2-14
  2551. time The time, like 15:00-16:50
  2552. extra Sting with extra planning info
  2553. priority-l The priority letter if any was given
  2554. priority-n The computed numerical priority
  2555. agenda-day The day in the agenda where this is listed"
  2556. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2557. (org-make-parameter-alist parameters))
  2558. (if (> (length cmd-key) 2)
  2559. (org-tags-view nil cmd-key)
  2560. (org-agenda nil cmd-key)))
  2561. (set-buffer org-agenda-buffer-name)
  2562. (let* ((lines (org-split-string (buffer-string) "\n"))
  2563. line)
  2564. (while (setq line (pop lines))
  2565. (catch 'next
  2566. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2567. (setq org-agenda-info
  2568. (org-fix-agenda-info (text-properties-at 0 line)))
  2569. (princ
  2570. (mapconcat 'org-agenda-export-csv-mapper
  2571. '(org-category txt type todo tags date time extra
  2572. priority-letter priority agenda-day)
  2573. ","))
  2574. (princ "\n")))))
  2575. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2576. (defun org-fix-agenda-info (props)
  2577. "Make sure all properties on an agenda item have a canonical form.
  2578. This ensures the export commands can easily use it."
  2579. (let (tmp re)
  2580. (when (setq tmp (plist-get props 'tags))
  2581. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2582. (when (setq tmp (plist-get props 'date))
  2583. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2584. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2585. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2586. (setq tmp (calendar-date-string tmp)))
  2587. (setq props (plist-put props 'date tmp)))
  2588. (when (setq tmp (plist-get props 'day))
  2589. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2590. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2591. (setq tmp (calendar-date-string tmp)))
  2592. (setq props (plist-put props 'day tmp))
  2593. (setq props (plist-put props 'agenda-day tmp)))
  2594. (when (setq tmp (plist-get props 'txt))
  2595. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2596. (plist-put props 'priority-letter (match-string 1 tmp))
  2597. (setq tmp (replace-match "" t t tmp)))
  2598. (when (and (setq re (plist-get props 'org-todo-regexp))
  2599. (setq re (concat "\\`\\.*" re " ?"))
  2600. (string-match re tmp))
  2601. (plist-put props 'todo (match-string 1 tmp))
  2602. (setq tmp (replace-match "" t t tmp)))
  2603. (plist-put props 'txt tmp)))
  2604. props)
  2605. (defun org-agenda-export-csv-mapper (prop)
  2606. (let ((res (plist-get org-agenda-info prop)))
  2607. (setq res
  2608. (cond
  2609. ((not res) "")
  2610. ((stringp res) res)
  2611. (t (prin1-to-string res))))
  2612. (while (string-match "," res)
  2613. (setq res (replace-match ";" t t res)))
  2614. (org-trim res)))
  2615. ;;;###autoload
  2616. (defun org-store-agenda-views (&rest parameters)
  2617. (interactive)
  2618. (eval (list 'org-batch-store-agenda-views)))
  2619. ;;;###autoload
  2620. (defmacro org-batch-store-agenda-views (&rest parameters)
  2621. "Run all custom agenda commands that have a file argument."
  2622. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2623. (pop-up-frames nil)
  2624. (dir default-directory)
  2625. (pars (org-make-parameter-alist parameters))
  2626. cmd thiscmdkey files opts cmd-or-set)
  2627. (save-window-excursion
  2628. (while cmds
  2629. (setq cmd (pop cmds)
  2630. thiscmdkey (car cmd)
  2631. cmd-or-set (nth 2 cmd)
  2632. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2633. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2634. (if (stringp files) (setq files (list files)))
  2635. (when files
  2636. (org-eval-in-environment (append org-agenda-exporter-settings
  2637. opts pars)
  2638. (org-agenda nil thiscmdkey))
  2639. (set-buffer org-agenda-buffer-name)
  2640. (while files
  2641. (org-eval-in-environment (append org-agenda-exporter-settings
  2642. opts pars)
  2643. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2644. (and (get-buffer org-agenda-buffer-name)
  2645. (kill-buffer org-agenda-buffer-name)))))))
  2646. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2647. (defun org-agenda-mark-header-line (pos)
  2648. "Mark the line at POS as an agenda structure header."
  2649. (save-excursion
  2650. (goto-char pos)
  2651. (put-text-property (point-at-bol) (point-at-eol)
  2652. 'org-agenda-structural-header t)
  2653. (when org-agenda-title-append
  2654. (put-text-property (point-at-bol) (point-at-eol)
  2655. 'org-agenda-title-append org-agenda-title-append))))
  2656. (defvar org-mobile-creating-agendas)
  2657. (defvar org-agenda-write-buffer-name "Agenda View")
  2658. (defun org-agenda-write (file &optional open nosettings)
  2659. "Write the current buffer (an agenda view) as a file.
  2660. Depending on the extension of the file name, plain text (.txt),
  2661. HTML (.html or .htm) or Postscript (.ps) is produced.
  2662. If the extension is .ics, run icalendar export over all files used
  2663. to construct the agenda and limit the export to entries listed in the
  2664. agenda now.
  2665. With prefix argument OPEN, open the new file immediately.
  2666. If NOSETTINGS is given, do not scope the settings of
  2667. `org-agenda-exporter-settings' into the export commands. This is used when
  2668. the settings have already been scoped and we do not wish to overrule other,
  2669. higher priority settings."
  2670. (interactive "FWrite agenda to file: \nP")
  2671. (if (not (file-writable-p file))
  2672. (error "Cannot write agenda to file %s" file))
  2673. (org-let (if nosettings nil org-agenda-exporter-settings)
  2674. '(save-excursion
  2675. (save-window-excursion
  2676. (org-agenda-mark-filtered-text)
  2677. (let ((bs (copy-sequence (buffer-string))) beg)
  2678. (org-agenda-unmark-filtered-text)
  2679. (with-temp-buffer
  2680. (rename-buffer org-agenda-write-buffer-name t)
  2681. (set-buffer-modified-p nil)
  2682. (insert bs)
  2683. (org-agenda-remove-marked-text 'org-filtered)
  2684. (while (setq beg (text-property-any (point-min) (point-max)
  2685. 'org-filtered t))
  2686. (delete-region
  2687. beg (or (next-single-property-change beg 'org-filtered)
  2688. (point-max))))
  2689. (run-hooks 'org-agenda-before-write-hook)
  2690. (cond
  2691. ((org-bound-and-true-p org-mobile-creating-agendas)
  2692. (org-mobile-write-agenda-for-mobile file))
  2693. ((string-match "\\.html?\\'" file)
  2694. (require 'htmlize)
  2695. (set-buffer (htmlize-buffer (current-buffer)))
  2696. (when (and org-agenda-export-html-style
  2697. (string-match "<style>" org-agenda-export-html-style))
  2698. ;; replace <style> section with org-agenda-export-html-style
  2699. (goto-char (point-min))
  2700. (kill-region (- (search-forward "<style") 6)
  2701. (search-forward "</style>"))
  2702. (insert org-agenda-export-html-style))
  2703. (write-file file)
  2704. (kill-buffer (current-buffer))
  2705. (message "HTML written to %s" file))
  2706. ((string-match "\\.ps\\'" file)
  2707. (require 'ps-print)
  2708. (ps-print-buffer-with-faces file)
  2709. (message "Postscript written to %s" file))
  2710. ((string-match "\\.pdf\\'" file)
  2711. (require 'ps-print)
  2712. (ps-print-buffer-with-faces
  2713. (concat (file-name-sans-extension file) ".ps"))
  2714. (call-process "ps2pdf" nil nil nil
  2715. (expand-file-name
  2716. (concat (file-name-sans-extension file) ".ps"))
  2717. (expand-file-name file))
  2718. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2719. (message "PDF written to %s" file))
  2720. ((string-match "\\.ics\\'" file)
  2721. (require 'org-icalendar)
  2722. (let ((org-agenda-marker-table
  2723. (org-create-marker-find-array
  2724. (org-agenda-collect-markers)))
  2725. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2726. (org-combined-agenda-icalendar-file file))
  2727. (apply 'org-export-icalendar 'combine
  2728. (org-agenda-files nil 'ifmode))))
  2729. (t
  2730. (let ((bs (buffer-string)))
  2731. (find-file file)
  2732. (erase-buffer)
  2733. (insert bs)
  2734. (save-buffer 0)
  2735. (kill-buffer (current-buffer))
  2736. (message "Plain text written to %s" file))))))))
  2737. (set-buffer org-agenda-buffer-name))
  2738. (when open (org-open-file file)))
  2739. (defvar org-agenda-tag-filter-overlays nil)
  2740. (defvar org-agenda-cat-filter-overlays nil)
  2741. (defun org-agenda-mark-filtered-text ()
  2742. "Mark all text hidden by filtering with a text property."
  2743. (let ((inhibit-read-only t))
  2744. (mapc
  2745. (lambda (o)
  2746. (when (equal (overlay-buffer o) (current-buffer))
  2747. (put-text-property
  2748. (overlay-start o) (overlay-end o)
  2749. 'org-filtered t)))
  2750. (append org-agenda-tag-filter-overlays
  2751. org-agenda-cat-filter-overlays))))
  2752. (defun org-agenda-unmark-filtered-text ()
  2753. "Remove the filtering text property."
  2754. (let ((inhibit-read-only t))
  2755. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2756. (defun org-agenda-remove-marked-text (property &optional value)
  2757. "Delete all text marked with VALUE of PROPERTY.
  2758. VALUE defaults to t."
  2759. (let (beg)
  2760. (setq value (or value t))
  2761. (while (setq beg (text-property-any (point-min) (point-max)
  2762. property value))
  2763. (delete-region
  2764. beg (or (next-single-property-change beg 'org-filtered)
  2765. (point-max))))))
  2766. (defun org-agenda-add-entry-text ()
  2767. "Add entry text to agenda lines.
  2768. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2769. entry text following headings shown in the agenda.
  2770. Drawers will be excluded, also the line with scheduling/deadline info."
  2771. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2772. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2773. (let (m txt)
  2774. (goto-char (point-min))
  2775. (while (not (eobp))
  2776. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2777. (beginning-of-line 2)
  2778. (setq txt (org-agenda-get-some-entry-text
  2779. m org-agenda-add-entry-text-maxlines " > "))
  2780. (end-of-line 1)
  2781. (if (string-match "\\S-" txt)
  2782. (insert "\n" txt)
  2783. (or (eobp) (forward-char 1))))))))
  2784. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2785. &rest keep)
  2786. "Extract entry text from MARKER, at most N-LINES lines.
  2787. This will ignore drawers etc, just get the text.
  2788. If INDENT is given, prefix every line with this string. If KEEP is
  2789. given, it is a list of symbols, defining stuff that should not be
  2790. removed from the entry content. Currently only `planning' is allowed here."
  2791. (let (txt drawer-re kwd-time-re ind)
  2792. (save-excursion
  2793. (with-current-buffer (marker-buffer marker)
  2794. (if (not (derived-mode-p 'org-mode))
  2795. (setq txt "")
  2796. (save-excursion
  2797. (save-restriction
  2798. (widen)
  2799. (goto-char marker)
  2800. (end-of-line 1)
  2801. (setq txt (buffer-substring
  2802. (min (1+ (point)) (point-max))
  2803. (progn (outline-next-heading) (point)))
  2804. drawer-re org-drawer-regexp
  2805. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2806. ".*\n?"))
  2807. (with-temp-buffer
  2808. (insert txt)
  2809. (when org-agenda-add-entry-text-descriptive-links
  2810. (goto-char (point-min))
  2811. (while (org-activate-bracket-links (point-max))
  2812. (add-text-properties (match-beginning 0) (match-end 0)
  2813. '(face org-link))))
  2814. (goto-char (point-min))
  2815. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2816. (set-text-properties (match-beginning 0) (match-end 0)
  2817. nil))
  2818. (goto-char (point-min))
  2819. (while (re-search-forward drawer-re nil t)
  2820. (delete-region
  2821. (match-beginning 0)
  2822. (progn (re-search-forward
  2823. "^[ \t]*:END:.*\n?" nil 'move)
  2824. (point))))
  2825. (unless (member 'planning keep)
  2826. (goto-char (point-min))
  2827. (while (re-search-forward kwd-time-re nil t)
  2828. (replace-match "")))
  2829. (goto-char (point-min))
  2830. (when org-agenda-entry-text-exclude-regexps
  2831. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2832. (while (setq re (pop re-list))
  2833. (goto-char (point-min))
  2834. (while (re-search-forward re nil t)
  2835. (replace-match "")))))
  2836. (goto-char (point-max))
  2837. (skip-chars-backward " \t\n")
  2838. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2839. ;; find and remove min common indentation
  2840. (goto-char (point-min))
  2841. (untabify (point-min) (point-max))
  2842. (setq ind (org-get-indentation))
  2843. (while (not (eobp))
  2844. (unless (looking-at "[ \t]*$")
  2845. (setq ind (min ind (org-get-indentation))))
  2846. (beginning-of-line 2))
  2847. (goto-char (point-min))
  2848. (while (not (eobp))
  2849. (unless (looking-at "[ \t]*$")
  2850. (move-to-column ind)
  2851. (delete-region (point-at-bol) (point)))
  2852. (beginning-of-line 2))
  2853. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2854. (goto-char (point-min))
  2855. (when indent
  2856. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2857. (replace-match indent t t)))
  2858. (goto-char (point-min))
  2859. (while (looking-at "[ \t]*\n") (replace-match ""))
  2860. (goto-char (point-max))
  2861. (when (> (org-current-line)
  2862. n-lines)
  2863. (org-goto-line (1+ n-lines))
  2864. (backward-char 1))
  2865. (setq txt (buffer-substring (point-min) (point)))))))))
  2866. txt))
  2867. (defun org-agenda-collect-markers ()
  2868. "Collect the markers pointing to entries in the agenda buffer."
  2869. (let (m markers)
  2870. (save-excursion
  2871. (goto-char (point-min))
  2872. (while (not (eobp))
  2873. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2874. (org-get-at-bol 'org-marker)))
  2875. (push m markers))
  2876. (beginning-of-line 2)))
  2877. (nreverse markers)))
  2878. (defun org-create-marker-find-array (marker-list)
  2879. "Create a alist of files names with all marker positions in that file."
  2880. (let (f tbl m a p)
  2881. (while (setq m (pop marker-list))
  2882. (setq p (marker-position m)
  2883. f (buffer-file-name (or (buffer-base-buffer
  2884. (marker-buffer m))
  2885. (marker-buffer m))))
  2886. (if (setq a (assoc f tbl))
  2887. (push (marker-position m) (cdr a))
  2888. (push (list f p) tbl)))
  2889. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2890. tbl)))
  2891. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2892. (defun org-check-agenda-marker-table ()
  2893. "Check of the current entry is on the marker list."
  2894. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2895. a)
  2896. (and (setq a (assoc file org-agenda-marker-table))
  2897. (save-match-data
  2898. (save-excursion
  2899. (org-back-to-heading t)
  2900. (member (point) (cdr a)))))))
  2901. (defun org-check-for-org-mode ()
  2902. "Make sure current buffer is in org-mode. Error if not."
  2903. (or (derived-mode-p 'org-mode)
  2904. (error "Cannot execute org-mode agenda command on buffer in %s"
  2905. major-mode)))
  2906. (defun org-fit-agenda-window ()
  2907. "Fit the window to the buffer size."
  2908. (and (memq org-agenda-window-setup '(reorganize-frame))
  2909. (fboundp 'fit-window-to-buffer)
  2910. (org-fit-window-to-buffer
  2911. nil
  2912. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2913. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2914. ;;; Agenda prepare and finalize
  2915. (defvar org-agenda-multi nil) ; dynamically scoped
  2916. (defvar org-agenda-buffer-name "*Org Agenda*")
  2917. (defvar org-pre-agenda-window-conf nil)
  2918. (defvar org-agenda-columns-active nil)
  2919. (defvar org-agenda-name nil)
  2920. (defvar org-agenda-tag-filter nil)
  2921. (defvar org-agenda-category-filter nil)
  2922. (defvar org-agenda-top-category-filter nil)
  2923. (defvar org-agenda-tag-filter-while-redo nil)
  2924. (defvar org-agenda-tag-filter-preset nil
  2925. "A preset of the tags filter used for secondary agenda filtering.
  2926. This must be a list of strings, each string must be a single tag preceded
  2927. by \"+\" or \"-\".
  2928. This variable should not be set directly, but agenda custom commands can
  2929. bind it in the options section. The preset filter is a global property of
  2930. the entire agenda view. In a block agenda, it will not work reliably to
  2931. define a filter for one of the individual blocks. You need to set it in
  2932. the global options and expect it to be applied to the entire view.")
  2933. (defvar org-agenda-category-filter-preset nil
  2934. "A preset of the category filter used for secondary agenda filtering.
  2935. This must be a list of strings, each string must be a single category
  2936. preceded by \"+\" or \"-\".
  2937. This variable should not be set directly, but agenda custom commands can
  2938. bind it in the options section. The preset filter is a global property of
  2939. the entire agenda view. In a block agenda, it will not work reliably to
  2940. define a filter for one of the individual blocks. You need to set it in
  2941. the global options and expect it to be applied to the entire view.")
  2942. (defun org-agenda-use-sticky-p ()
  2943. "Return non-NIL if existing agenda buffer named
  2944. `org-agenda-buffer-name' exists, and should be shown instead of
  2945. generating a new one"
  2946. (and
  2947. ;; turned off by user
  2948. org-agenda-sticky
  2949. ;; For multi-agenda buffer already exists
  2950. (not org-agenda-multi)
  2951. ;; buffer found
  2952. (get-buffer org-agenda-buffer-name)
  2953. ;; C-u parameter is same as last call
  2954. (with-current-buffer (get-buffer org-agenda-buffer-name)
  2955. (and
  2956. (equal current-prefix-arg
  2957. org-agenda-last-prefix-arg)
  2958. ;; In case user turned stickiness on, while having existing
  2959. ;; Agenda buffer active, don't reuse that buffer, because it
  2960. ;; does not have org variables local
  2961. org-agenda-this-buffer-is-sticky))))
  2962. (defun org-prepare-agenda-window (abuf)
  2963. "Setup agenda buffer in the window"
  2964. (let* ((awin (get-buffer-window abuf))
  2965. wconf)
  2966. (cond
  2967. ((equal (current-buffer) abuf) nil)
  2968. (awin (select-window awin))
  2969. ((not (setq wconf (current-window-configuration))))
  2970. ((equal org-agenda-window-setup 'current-window)
  2971. (org-pop-to-buffer-same-window abuf))
  2972. ((equal org-agenda-window-setup 'other-window)
  2973. (org-switch-to-buffer-other-window abuf))
  2974. ((equal org-agenda-window-setup 'other-frame)
  2975. (switch-to-buffer-other-frame abuf))
  2976. ((equal org-agenda-window-setup 'reorganize-frame)
  2977. (delete-other-windows)
  2978. (org-switch-to-buffer-other-window abuf)))
  2979. ;; additional test in case agenda is invoked from within agenda
  2980. ;; buffer via elisp link
  2981. (unless (equal (current-buffer) abuf)
  2982. (org-pop-to-buffer-same-window abuf))
  2983. (setq org-pre-agenda-window-conf wconf)))
  2984. (defun org-prepare-agenda (&optional name)
  2985. (if (org-agenda-use-sticky-p)
  2986. (progn
  2987. ;; Popup existing buffer
  2988. (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
  2989. (message "Sticky Agenda buffer, use `r' to refresh")
  2990. (throw 'exit nil))
  2991. (setq org-todo-keywords-for-agenda nil)
  2992. (setq org-drawers-for-agenda nil)
  2993. (unless org-agenda-persistent-filter
  2994. (setq org-agenda-tag-filter nil
  2995. org-agenda-category-filter nil))
  2996. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2997. (put 'org-agenda-category-filter :preset-filter
  2998. org-agenda-category-filter-preset)
  2999. (if org-agenda-multi
  3000. (progn
  3001. (setq buffer-read-only nil)
  3002. (goto-char (point-max))
  3003. (unless (or (bobp) org-agenda-compact-blocks
  3004. (not org-agenda-block-separator))
  3005. (insert "\n"
  3006. (if (stringp org-agenda-block-separator)
  3007. org-agenda-block-separator
  3008. (make-string (window-width) org-agenda-block-separator))
  3009. "\n"))
  3010. (narrow-to-region (point) (point-max)))
  3011. (setq org-done-keywords-for-agenda nil)
  3012. ;; Setting any org variables that are in org-agenda-local-vars
  3013. ;; list need to be done after the prepare call
  3014. (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
  3015. (setq buffer-read-only nil)
  3016. (org-agenda-reset-markers)
  3017. (let ((inhibit-read-only t)) (erase-buffer))
  3018. (org-agenda-mode)
  3019. (setq org-agenda-buffer (current-buffer))
  3020. (setq org-agenda-contributing-files nil)
  3021. (setq org-agenda-columns-active nil)
  3022. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  3023. (setq org-todo-keywords-for-agenda
  3024. (org-uniquify org-todo-keywords-for-agenda))
  3025. (setq org-done-keywords-for-agenda
  3026. (org-uniquify org-done-keywords-for-agenda))
  3027. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3028. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3029. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3030. (and name (not org-agenda-name)
  3031. (org-set-local 'org-agenda-name name)))
  3032. (setq buffer-read-only nil)))
  3033. (defun org-finalize-agenda ()
  3034. "Finishing touch for the agenda buffer, called just before displaying it."
  3035. (unless org-agenda-multi
  3036. (save-excursion
  3037. (let ((inhibit-read-only t))
  3038. (goto-char (point-min))
  3039. (while (org-activate-bracket-links (point-max))
  3040. (add-text-properties (match-beginning 0) (match-end 0)
  3041. '(face org-link)))
  3042. (org-agenda-align-tags)
  3043. (unless org-agenda-with-colors
  3044. (remove-text-properties (point-min) (point-max) '(face nil))))
  3045. (if (and (boundp 'org-agenda-overriding-columns-format)
  3046. org-agenda-overriding-columns-format)
  3047. (org-set-local 'org-agenda-overriding-columns-format
  3048. org-agenda-overriding-columns-format))
  3049. (if (and (boundp 'org-agenda-view-columns-initially)
  3050. org-agenda-view-columns-initially)
  3051. (org-agenda-columns))
  3052. (when org-agenda-fontify-priorities
  3053. (org-agenda-fontify-priorities))
  3054. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3055. (org-agenda-dim-blocked-tasks))
  3056. (org-agenda-mark-clocking-task)
  3057. (when org-agenda-entry-text-mode
  3058. (org-agenda-entry-text-hide)
  3059. (org-agenda-entry-text-show))
  3060. (if (functionp 'org-habit-insert-consistency-graphs)
  3061. (org-habit-insert-consistency-graphs))
  3062. (run-hooks 'org-finalize-agenda-hook)
  3063. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3064. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3065. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3066. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3067. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3068. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3069. )))
  3070. (defun org-agenda-mark-clocking-task ()
  3071. "Mark the current clock entry in the agenda if it is present."
  3072. (mapc (lambda (o)
  3073. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3074. (delete-overlay o)))
  3075. (overlays-in (point-min) (point-max)))
  3076. (when (marker-buffer org-clock-hd-marker)
  3077. (save-excursion
  3078. (goto-char (point-min))
  3079. (let (s ov)
  3080. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3081. (goto-char s)
  3082. (when (equal (org-get-at-bol 'org-hd-marker)
  3083. org-clock-hd-marker)
  3084. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3085. (overlay-put ov 'type 'org-agenda-clocking)
  3086. (overlay-put ov 'face 'org-agenda-clocking)
  3087. (overlay-put ov 'help-echo
  3088. "The clock is running in this item")))))))
  3089. (defun org-agenda-fontify-priorities ()
  3090. "Make highest priority lines bold, and lowest italic."
  3091. (interactive)
  3092. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3093. (delete-overlay o)))
  3094. (overlays-in (point-min) (point-max)))
  3095. (save-excursion
  3096. (let ((inhibit-read-only t)
  3097. b e p ov h l)
  3098. (goto-char (point-min))
  3099. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3100. (setq h (or (get-char-property (point) 'org-highest-priority)
  3101. org-highest-priority)
  3102. l (or (get-char-property (point) 'org-lowest-priority)
  3103. org-lowest-priority)
  3104. p (string-to-char (match-string 1))
  3105. b (match-beginning 0)
  3106. e (if (eq org-agenda-fontify-priorities 'cookies)
  3107. (match-end 0)
  3108. (point-at-eol))
  3109. ov (make-overlay b e))
  3110. (overlay-put
  3111. ov 'face
  3112. (cond ((org-face-from-face-or-color
  3113. 'priority nil
  3114. (cdr (assoc p org-priority-faces))))
  3115. ((and (listp org-agenda-fontify-priorities)
  3116. (org-face-from-face-or-color
  3117. 'priority nil
  3118. (cdr (assoc p org-agenda-fontify-priorities)))))
  3119. ((equal p l) 'italic)
  3120. ((equal p h) 'bold)))
  3121. (overlay-put ov 'org-type 'org-priority)))))
  3122. (defun org-agenda-dim-blocked-tasks ()
  3123. "Dim currently blocked TODO's in the agenda display."
  3124. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3125. (delete-overlay o)))
  3126. (overlays-in (point-min) (point-max)))
  3127. (save-excursion
  3128. (let ((inhibit-read-only t)
  3129. (org-depend-tag-blocked nil)
  3130. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3131. org-blocked-by-checkboxes
  3132. invis1 b e p ov h l)
  3133. (goto-char (point-min))
  3134. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3135. (and pos (goto-char (1+ pos))))
  3136. (setq org-blocked-by-checkboxes nil invis1 invis)
  3137. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3138. (when (and marker
  3139. (with-current-buffer (marker-buffer marker)
  3140. (save-excursion (goto-char marker)
  3141. (org-entry-blocked-p))))
  3142. (if org-blocked-by-checkboxes (setq invis1 nil))
  3143. (setq b (if invis1
  3144. (max (point-min) (1- (point-at-bol)))
  3145. (point-at-bol))
  3146. e (point-at-eol)
  3147. ov (make-overlay b e))
  3148. (if invis1
  3149. (overlay-put ov 'invisible t)
  3150. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3151. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3152. (defvar org-agenda-skip-function nil
  3153. "Function to be called at each match during agenda construction.
  3154. If this function returns nil, the current match should not be skipped.
  3155. Otherwise, the function must return a position from where the search
  3156. should be continued.
  3157. This may also be a Lisp form, it will be evaluated.
  3158. Never set this variable using `setq' or so, because then it will apply
  3159. to all future agenda commands. If you do want a global skipping condition,
  3160. use the option `org-agenda-skip-function-global' instead.
  3161. The correct usage for `org-agenda-skip-function' is to bind it with
  3162. `let' to scope it dynamically into the agenda-constructing command.
  3163. A good way to set it is through options in `org-agenda-custom-commands'.")
  3164. (defun org-agenda-skip ()
  3165. "Throw to `:skip' in places that should be skipped.
  3166. Also moves point to the end of the skipped region, so that search can
  3167. continue from there."
  3168. (let ((p (point-at-bol)) to)
  3169. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3170. (get-text-property p :org-archived)
  3171. (org-end-of-subtree t)
  3172. (throw :skip t))
  3173. (and org-agenda-skip-comment-trees
  3174. (get-text-property p :org-comment)
  3175. (org-end-of-subtree t)
  3176. (throw :skip t))
  3177. (if (equal (char-after p) ?#) (throw :skip t))
  3178. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3179. (org-agenda-skip-eval org-agenda-skip-function)))
  3180. (goto-char to)
  3181. (throw :skip t))))
  3182. (defun org-agenda-skip-eval (form)
  3183. "If FORM is a function or a list, call (or eval) is and return result.
  3184. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3185. and match data are returned to the previous state no matter what these
  3186. functions do."
  3187. (let (fp)
  3188. (and form
  3189. (or (setq fp (functionp form))
  3190. (consp form))
  3191. (save-excursion
  3192. (save-match-data
  3193. (if fp
  3194. (funcall form)
  3195. (eval form)))))))
  3196. (defvar org-agenda-markers nil
  3197. "List of all currently active markers created by `org-agenda'.")
  3198. (defvar org-agenda-last-marker-time (org-float-time)
  3199. "Creation time of the last agenda marker.")
  3200. (defun org-agenda-new-marker (&optional pos)
  3201. "Return a new agenda marker.
  3202. Org-mode keeps a list of these markers and resets them when they are
  3203. no longer in use."
  3204. (let ((m (copy-marker (or pos (point)))))
  3205. (setq org-agenda-last-marker-time (org-float-time))
  3206. (if org-agenda-buffer
  3207. (with-current-buffer org-agenda-buffer
  3208. (push m org-agenda-markers))
  3209. (push m org-agenda-markers))
  3210. m))
  3211. (defun org-agenda-reset-markers ()
  3212. "Reset markers created by `org-agenda'."
  3213. (while org-agenda-markers
  3214. (move-marker (pop org-agenda-markers) nil)))
  3215. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3216. "Save relative positions of markers in region.
  3217. This check for agenda markers in all agenda buffers currently active."
  3218. (dolist (buf (buffer-list))
  3219. (with-current-buffer buf
  3220. (when (eq major-mode 'org-agenda-mode)
  3221. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3222. org-agenda-markers)))))
  3223. ;;; Entry text mode
  3224. (defun org-agenda-entry-text-show-here ()
  3225. "Add some text from the entry as context to the current line."
  3226. (let (m txt o)
  3227. (setq m (org-get-at-bol 'org-hd-marker))
  3228. (unless (marker-buffer m)
  3229. (error "No marker points to an entry here"))
  3230. (setq txt (concat "\n" (org-no-properties
  3231. (org-agenda-get-some-entry-text
  3232. m org-agenda-entry-text-maxlines " > "))))
  3233. (when (string-match "\\S-" txt)
  3234. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3235. (overlay-put o 'evaporate t)
  3236. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3237. (overlay-put o 'after-string txt))))
  3238. (defun org-agenda-entry-text-show ()
  3239. "Add entry context for all agenda lines."
  3240. (interactive)
  3241. (save-excursion
  3242. (goto-char (point-max))
  3243. (beginning-of-line 1)
  3244. (while (not (bobp))
  3245. (when (org-get-at-bol 'org-hd-marker)
  3246. (org-agenda-entry-text-show-here))
  3247. (beginning-of-line 0))))
  3248. (defun org-agenda-entry-text-hide ()
  3249. "Remove any shown entry context."
  3250. (delq nil
  3251. (mapcar (lambda (o)
  3252. (if (eq (overlay-get o 'org-overlay-type)
  3253. 'agenda-entry-content)
  3254. (progn (delete-overlay o) t)))
  3255. (overlays-in (point-min) (point-max)))))
  3256. (defun org-agenda-get-day-face (date)
  3257. "Return the face DATE should be displayed with."
  3258. (or (and (functionp org-agenda-day-face-function)
  3259. (funcall org-agenda-day-face-function date))
  3260. (cond ((org-agenda-todayp date)
  3261. 'org-agenda-date-today)
  3262. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3263. 'org-agenda-date-weekend)
  3264. (t 'org-agenda-date))))
  3265. ;;; Agenda timeline
  3266. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3267. (defun org-timeline (&optional dotodo)
  3268. "Show a time-sorted view of the entries in the current org file.
  3269. Only entries with a time stamp of today or later will be listed. With
  3270. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3271. under the current date.
  3272. If the buffer contains an active region, only check the region for
  3273. dates."
  3274. (interactive "P")
  3275. (let* ((dopast t)
  3276. (org-agenda-show-log-scoped org-agenda-show-log)
  3277. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3278. (current-buffer))))
  3279. (date (calendar-current-date))
  3280. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3281. (end (if (org-region-active-p) (region-end) (point-max)))
  3282. (day-numbers (org-get-all-dates
  3283. beg end 'no-ranges
  3284. t org-agenda-show-log-scoped ; always include today
  3285. org-timeline-show-empty-dates))
  3286. (org-deadline-warning-days 0)
  3287. (org-agenda-only-exact-dates t)
  3288. (today (org-today))
  3289. (past t)
  3290. args
  3291. s e rtn d emptyp)
  3292. (setq org-agenda-redo-command
  3293. (list 'progn
  3294. (list 'org-switch-to-buffer-other-window (current-buffer))
  3295. (list 'org-timeline (list 'quote dotodo))))
  3296. (if (not dopast)
  3297. ;; Remove past dates from the list of dates.
  3298. (setq day-numbers (delq nil (mapcar (lambda(x)
  3299. (if (>= x today) x nil))
  3300. day-numbers))))
  3301. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3302. (org-compile-prefix-format 'timeline)
  3303. (org-set-sorting-strategy 'timeline)
  3304. (if org-agenda-show-log-scoped (push :closed args))
  3305. (push :timestamp args)
  3306. (push :deadline args)
  3307. (push :scheduled args)
  3308. (push :sexp args)
  3309. (if dotodo (push :todo args))
  3310. (insert "Timeline of file " entry "\n")
  3311. (add-text-properties (point-min) (point)
  3312. (list 'face 'org-agenda-structure))
  3313. (org-agenda-mark-header-line (point-min))
  3314. (while (setq d (pop day-numbers))
  3315. (if (and (listp d) (eq (car d) :omitted))
  3316. (progn
  3317. (setq s (point))
  3318. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3319. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3320. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3321. (if (and (>= d today)
  3322. dopast
  3323. past)
  3324. (progn
  3325. (setq past nil)
  3326. (insert (make-string 79 ?-) "\n")))
  3327. (setq date (calendar-gregorian-from-absolute d))
  3328. (setq s (point))
  3329. (setq rtn (and (not emptyp)
  3330. (apply 'org-agenda-get-day-entries entry
  3331. date args)))
  3332. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3333. (progn
  3334. (insert
  3335. (if (stringp org-agenda-format-date)
  3336. (format-time-string org-agenda-format-date
  3337. (org-time-from-absolute date))
  3338. (funcall org-agenda-format-date date))
  3339. "\n")
  3340. (put-text-property s (1- (point)) 'face
  3341. (org-agenda-get-day-face date))
  3342. (put-text-property s (1- (point)) 'org-date-line t)
  3343. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3344. (if (equal d today)
  3345. (put-text-property s (1- (point)) 'org-today t))
  3346. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3347. (put-text-property s (1- (point)) 'day d)))))
  3348. (goto-char (point-min))
  3349. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3350. (point-min)))
  3351. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3352. (org-finalize-agenda)
  3353. (setq buffer-read-only t)))
  3354. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3355. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3356. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3357. not every single day in the range. If FORCE-TODAY is non-nil, make
  3358. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3359. inactive time stamps (those in square brackets) are included.
  3360. When EMPTY is non-nil, also include days without any entries."
  3361. (let ((re (concat
  3362. (if pre-re pre-re "")
  3363. (if inactive org-ts-regexp-both org-ts-regexp)))
  3364. dates dates1 date day day1 day2 ts1 ts2 pos)
  3365. (if force-today
  3366. (setq dates (list (org-today))))
  3367. (save-excursion
  3368. (goto-char beg)
  3369. (while (re-search-forward re end t)
  3370. (setq day (time-to-days (org-time-string-to-time
  3371. (substring (match-string 1) 0 10)
  3372. (current-buffer) (match-beginning 0))))
  3373. (or (memq day dates) (push day dates)))
  3374. (unless no-ranges
  3375. (goto-char beg)
  3376. (while (re-search-forward org-tr-regexp end t)
  3377. (setq pos (match-beginning 0))
  3378. (setq ts1 (substring (match-string 1) 0 10)
  3379. ts2 (substring (match-string 2) 0 10)
  3380. day1 (time-to-days (org-time-string-to-time
  3381. ts1 (current-buffer) pos))
  3382. day2 (time-to-days (org-time-string-to-time
  3383. ts2 (current-buffer) pos)))
  3384. (while (< (setq day1 (1+ day1)) day2)
  3385. (or (memq day1 dates) (push day1 dates)))))
  3386. (setq dates (sort dates '<))
  3387. (when empty
  3388. (while (setq day (pop dates))
  3389. (setq day2 (car dates))
  3390. (push day dates1)
  3391. (when (and day2 empty)
  3392. (if (or (eq empty t)
  3393. (and (numberp empty) (<= (- day2 day) empty)))
  3394. (while (< (setq day (1+ day)) day2)
  3395. (push (list day) dates1))
  3396. (push (cons :omitted (- day2 day)) dates1))))
  3397. (setq dates (nreverse dates1)))
  3398. dates)))
  3399. ;;; Agenda Daily/Weekly
  3400. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3401. "Start day for the agenda view.
  3402. Custom commands can set this variable in the options section.")
  3403. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3404. (defvar org-agenda-current-span nil
  3405. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3406. (defvar org-arg-loc nil) ; local variable
  3407. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3408. "List of types searched for when creating the daily/weekly agenda.
  3409. This variable is a list of symbols that controls the types of
  3410. items that appear in the daily/weekly agenda. Allowed symbols in this
  3411. list are are
  3412. :timestamp List items containing a date stamp or date range matching
  3413. the selected date. This includes sexp entries in
  3414. angular brackets.
  3415. :sexp List entries resulting from plain diary-like sexps.
  3416. :deadline List deadline due on that date. When the date is today,
  3417. also list any deadlines past due, or due within
  3418. `org-deadline-warning-days'. `:deadline' must appear before
  3419. `:scheduled' if the setting of
  3420. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3421. any effect.
  3422. :scheduled List all items which are scheduled for the given date.
  3423. The diary for *today* also contains items which were
  3424. scheduled earlier and are not yet marked DONE.
  3425. By default, all four types are turned on.
  3426. Never set this variable globally using `setq', because then it
  3427. will apply to all future agenda commands. Instead, bind it with
  3428. `let' to scope it dynamically into the agenda-constructing
  3429. command. A good way to set it is through options in
  3430. `org-agenda-custom-commands'. For a more flexible (though
  3431. somewhat less efficient) way of determining what is included in
  3432. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3433. ;;;###autoload
  3434. (defun org-agenda-list (&optional arg start-day span)
  3435. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3436. The view will be for the current day or week, but from the overview buffer
  3437. you will be able to go to other days/weeks.
  3438. With a numeric prefix argument in an interactive call, the agenda will
  3439. span ARG days. Lisp programs should instead specify SPAN to change
  3440. the number of days. SPAN defaults to `org-agenda-span'.
  3441. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3442. given in `org-agenda-start-on-weekday'."
  3443. (interactive "P")
  3444. (if (and (integerp arg) (> arg 0))
  3445. (setq span arg arg nil))
  3446. (org-prepare-agenda "Day/Week")
  3447. (setq start-day (or start-day org-agenda-start-day))
  3448. (if org-agenda-overriding-arguments
  3449. (setq arg (car org-agenda-overriding-arguments)
  3450. start-day (nth 1 org-agenda-overriding-arguments)
  3451. span (nth 2 org-agenda-overriding-arguments)))
  3452. (if (stringp start-day)
  3453. ;; Convert to an absolute day number
  3454. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3455. (setq org-agenda-last-arguments (list arg start-day span))
  3456. (org-compile-prefix-format 'agenda)
  3457. (org-set-sorting-strategy 'agenda)
  3458. (let* ((span (org-agenda-ndays-to-span
  3459. (or span org-agenda-ndays org-agenda-span)))
  3460. (today (org-today))
  3461. (sd (or start-day today))
  3462. (ndays (org-agenda-span-to-ndays span sd))
  3463. (org-agenda-start-on-weekday
  3464. (if (eq ndays 7)
  3465. org-agenda-start-on-weekday))
  3466. (thefiles (org-agenda-files nil 'ifmode))
  3467. (files thefiles)
  3468. (start (if (or (null org-agenda-start-on-weekday)
  3469. (< ndays 7))
  3470. sd
  3471. (let* ((nt (calendar-day-of-week
  3472. (calendar-gregorian-from-absolute sd)))
  3473. (n1 org-agenda-start-on-weekday)
  3474. (d (- nt n1)))
  3475. (- sd (+ (if (< d 0) 7 0) d)))))
  3476. (day-numbers (list start))
  3477. (day-cnt 0)
  3478. (inhibit-redisplay (not debug-on-error))
  3479. (org-agenda-show-log-scoped org-agenda-show-log)
  3480. s e rtn rtnall file date d start-pos end-pos todayp
  3481. clocktable-start clocktable-end filter)
  3482. (setq org-agenda-redo-command
  3483. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3484. (dotimes (n (1- ndays))
  3485. (push (1+ (car day-numbers)) day-numbers))
  3486. (setq day-numbers (nreverse day-numbers))
  3487. (setq clocktable-start (car day-numbers)
  3488. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3489. (org-set-local 'org-starting-day (car day-numbers))
  3490. (org-set-local 'org-arg-loc arg)
  3491. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3492. (unless org-agenda-compact-blocks
  3493. (let* ((d1 (car day-numbers))
  3494. (d2 (org-last day-numbers))
  3495. (w1 (org-days-to-iso-week d1))
  3496. (w2 (org-days-to-iso-week d2)))
  3497. (setq s (point))
  3498. (if org-agenda-overriding-header
  3499. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3500. nil 'face 'org-agenda-structure) "\n")
  3501. (insert (org-agenda-span-name span)
  3502. "-agenda"
  3503. (if (< (- d2 d1) 350)
  3504. (if (= w1 w2)
  3505. (format " (W%02d)" w1)
  3506. (format " (W%02d-W%02d)" w1 w2))
  3507. "")
  3508. ":\n")))
  3509. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3510. 'org-date-line t))
  3511. (org-agenda-mark-header-line s))
  3512. (while (setq d (pop day-numbers))
  3513. (setq date (calendar-gregorian-from-absolute d)
  3514. s (point))
  3515. (if (or (setq todayp (= d today))
  3516. (and (not start-pos) (= d sd)))
  3517. (setq start-pos (point))
  3518. (if (and start-pos (not end-pos))
  3519. (setq end-pos (point))))
  3520. (setq files thefiles
  3521. rtnall nil)
  3522. (while (setq file (pop files))
  3523. (catch 'nextfile
  3524. (org-check-agenda-file file)
  3525. (let ((org-agenda-entry-types org-agenda-entry-types))
  3526. (unless org-agenda-include-deadlines
  3527. (setq org-agenda-entry-types
  3528. (delq :deadline org-agenda-entry-types)))
  3529. (cond
  3530. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3531. (setq rtn (org-agenda-get-day-entries
  3532. file date :closed)))
  3533. (org-agenda-show-log-scoped
  3534. (setq rtn (apply 'org-agenda-get-day-entries
  3535. file date
  3536. (append '(:closed) org-agenda-entry-types))))
  3537. (t
  3538. (setq rtn (apply 'org-agenda-get-day-entries
  3539. file date
  3540. org-agenda-entry-types)))))
  3541. (setq rtnall (append rtnall rtn)))) ;; all entries
  3542. (if org-agenda-include-diary
  3543. (let ((org-agenda-search-headline-for-time t))
  3544. (require 'diary-lib)
  3545. (setq rtn (org-get-entries-from-diary date))
  3546. (setq rtnall (append rtnall rtn))))
  3547. (if (or rtnall org-agenda-show-all-dates)
  3548. (progn
  3549. (setq day-cnt (1+ day-cnt))
  3550. (insert
  3551. (if (stringp org-agenda-format-date)
  3552. (format-time-string org-agenda-format-date
  3553. (org-time-from-absolute date))
  3554. (funcall org-agenda-format-date date))
  3555. "\n")
  3556. (put-text-property s (1- (point)) 'face
  3557. (org-agenda-get-day-face date))
  3558. (put-text-property s (1- (point)) 'org-date-line t)
  3559. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3560. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3561. (when todayp
  3562. (put-text-property s (1- (point)) 'org-today t))
  3563. (if rtnall (insert ;; all entries
  3564. (org-finalize-agenda-entries
  3565. (org-agenda-add-time-grid-maybe
  3566. rtnall ndays todayp))
  3567. "\n"))
  3568. (put-text-property s (1- (point)) 'day d)
  3569. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3570. (when (and org-agenda-clockreport-mode clocktable-start)
  3571. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3572. ;; the above line is to ensure the restricted range!
  3573. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3574. tbl)
  3575. (setq p (org-plist-delete p :block))
  3576. (setq p (plist-put p :tstart clocktable-start))
  3577. (setq p (plist-put p :tend clocktable-end))
  3578. (setq p (plist-put p :scope 'agenda))
  3579. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3580. (setq filter (or org-agenda-tag-filter-while-redo
  3581. (get 'org-agenda-tag-filter :preset-filter))))
  3582. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3583. (if (string-match "[<>=]" x)
  3584. ""
  3585. x))
  3586. filter ""))))
  3587. (setq tbl (apply 'org-get-clocktable p))
  3588. (insert tbl)))
  3589. (goto-char (point-min))
  3590. (or org-agenda-multi (org-fit-agenda-window))
  3591. (unless (and (pos-visible-in-window-p (point-min))
  3592. (pos-visible-in-window-p (point-max)))
  3593. (goto-char (1- (point-max)))
  3594. (recenter -1)
  3595. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3596. (progn
  3597. (goto-char (or start-pos 1))
  3598. (recenter 1))))
  3599. (goto-char (or start-pos 1))
  3600. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3601. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3602. (org-agenda-show-clocking-issues))
  3603. (org-finalize-agenda)
  3604. (setq buffer-read-only t)
  3605. (message "")))
  3606. (defun org-agenda-ndays-to-span (n)
  3607. "Return a span symbol for a span of N days, or N if none matches."
  3608. (cond ((symbolp n) n)
  3609. ((= n 1) 'day)
  3610. ((= n 7) 'week)
  3611. (t n)))
  3612. (defun org-agenda-span-to-ndays (span start-day)
  3613. "Return ndays from SPAN starting at START-DAY."
  3614. (cond ((numberp span) span)
  3615. ((eq span 'day) 1)
  3616. ((eq span 'week) 7)
  3617. ((eq span 'month)
  3618. (let ((date (calendar-gregorian-from-absolute start-day)))
  3619. (calendar-last-day-of-month (car date) (caddr date))))
  3620. ((eq span 'year)
  3621. (let ((date (calendar-gregorian-from-absolute start-day)))
  3622. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3623. (defun org-agenda-span-name (span)
  3624. "Return a SPAN name."
  3625. (if (null span)
  3626. ""
  3627. (if (symbolp span)
  3628. (capitalize (symbol-name span))
  3629. (format "%d days" span))))
  3630. ;;; Agenda word search
  3631. (defvar org-agenda-search-history nil)
  3632. (defvar org-todo-only nil)
  3633. (defvar org-search-syntax-table nil
  3634. "Special syntax table for org-mode search.
  3635. In this table, we have single quotes not as word constituents, to
  3636. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3637. (defun org-search-syntax-table ()
  3638. (unless org-search-syntax-table
  3639. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3640. (modify-syntax-entry ?' "." org-search-syntax-table)
  3641. (modify-syntax-entry ?` "." org-search-syntax-table))
  3642. org-search-syntax-table)
  3643. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3644. ;;;###autoload
  3645. (defun org-search-view (&optional todo-only string edit-at)
  3646. "Show all entries that contain a phrase or words or regular expressions.
  3647. With optional prefix argument TODO-ONLY, only consider entries that are
  3648. TODO entries. The argument STRING can be used to pass a default search
  3649. string into this function. If EDIT-AT is non-nil, it means that the
  3650. user should get a chance to edit this string, with cursor at position
  3651. EDIT-AT.
  3652. The search string can be viewed either as a phrase that should be found as
  3653. is, or it can be broken into a number of snippets, each of which must match
  3654. in a Boolean way to select an entry. The default depends on the variable
  3655. `org-agenda-search-view-always-boolean'.
  3656. Even if this is turned off (the default) you can always switch to
  3657. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3658. The default is a direct search of the whole phrase, where each space in
  3659. the search string can expand to an arbitrary amount of whitespace,
  3660. including newlines.
  3661. If using a Boolean search, the search string is split on whitespace and
  3662. each snippet is searched separately, with logical AND to select an entry.
  3663. Words prefixed with a minus must *not* occur in the entry. Words without
  3664. a prefix or prefixed with a plus must occur in the entry. Matching is
  3665. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3666. match whole words, not parts of a word) if
  3667. `org-agenda-search-view-force-full-words' is set (default is nil).
  3668. Boolean search snippets enclosed by curly braces are interpreted as
  3669. regular expressions that must or (when preceded with \"-\") must not
  3670. match in the entry. Snippets enclosed into double quotes will be taken
  3671. as a whole, to include whitespace.
  3672. - If the search string starts with an asterisk, search only in headlines.
  3673. - If (possibly after the leading star) the search string starts with an
  3674. exclamation mark, this also means to look at TODO entries only, an effect
  3675. that can also be achieved with a prefix argument.
  3676. - If (possibly after star and exclamation mark) the search string starts
  3677. with a colon, this will mean that the (non-regexp) snippets of the
  3678. Boolean search must match as full words.
  3679. This command searches the agenda files, and in addition the files listed
  3680. in `org-agenda-text-search-extra-files'."
  3681. (interactive "P")
  3682. (org-prepare-agenda "SEARCH")
  3683. (org-compile-prefix-format 'search)
  3684. (org-set-sorting-strategy 'search)
  3685. (let* ((props (list 'face nil
  3686. 'done-face 'org-agenda-done
  3687. 'org-not-done-regexp org-not-done-regexp
  3688. 'org-todo-regexp org-todo-regexp
  3689. 'org-complex-heading-regexp org-complex-heading-regexp
  3690. 'mouse-face 'highlight
  3691. 'help-echo (format "mouse-2 or RET jump to location")))
  3692. (full-words org-agenda-search-view-force-full-words)
  3693. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3694. regexp rtn rtnall files file pos
  3695. marker category org-category-pos tags c neg re boolean
  3696. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3697. (unless (and (not edit-at)
  3698. (stringp string)
  3699. (string-match "\\S-" string))
  3700. (setq string (read-string
  3701. (if org-agenda-search-view-always-boolean
  3702. "[+-]Word/{Regexp} ...: "
  3703. "Phrase, or [+-]Word/{Regexp} ...: ")
  3704. (cond
  3705. ((integerp edit-at) (cons string edit-at))
  3706. (edit-at string))
  3707. 'org-agenda-search-history)))
  3708. (org-set-local 'org-todo-only todo-only)
  3709. (setq org-agenda-redo-command
  3710. (list 'org-search-view (if todo-only t nil) string
  3711. '(if current-prefix-arg 1 nil)))
  3712. (setq org-agenda-query-string string)
  3713. (if (equal (string-to-char string) ?*)
  3714. (setq hdl-only t
  3715. words (substring string 1))
  3716. (setq words string))
  3717. (when (equal (string-to-char words) ?!)
  3718. (setq todo-only t
  3719. words (substring words 1)))
  3720. (when (equal (string-to-char words) ?:)
  3721. (setq full-words t
  3722. words (substring words 1)))
  3723. (if (or org-agenda-search-view-always-boolean
  3724. (member (string-to-char words) '(?- ?+ ?\{)))
  3725. (setq boolean t))
  3726. (setq words (org-split-string words))
  3727. (let (www w)
  3728. (while (setq w (pop words))
  3729. (while (and (string-match "\\\\\\'" w) words)
  3730. (setq w (concat (substring w 0 -1) " " (pop words))))
  3731. (push w www))
  3732. (setq words (nreverse www) www nil)
  3733. (while (setq w (pop words))
  3734. (when (and (string-match "\\`[-+]?{" w)
  3735. (not (string-match "}\\'" w)))
  3736. (while (and words (not (string-match "}\\'" (car words))))
  3737. (setq w (concat w " " (pop words))))
  3738. (setq w (concat w " " (pop words))))
  3739. (push w www))
  3740. (setq words (nreverse www)))
  3741. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3742. (when boolean
  3743. (let (wds w)
  3744. (while (setq w (pop words))
  3745. (if (or (equal (substring w 0 1) "\"")
  3746. (and (> (length w) 1)
  3747. (member (substring w 0 1) '("+" "-"))
  3748. (equal (substring w 1 2) "\"")))
  3749. (while (and words (not (equal (substring w -1) "\"")))
  3750. (setq w (concat w " " (pop words)))))
  3751. (and (string-match "\\`\\([-+]?\\)\"" w)
  3752. (setq w (replace-match "\\1" nil nil w)))
  3753. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3754. (push w wds))
  3755. (setq words (nreverse wds))))
  3756. (if boolean
  3757. (mapc (lambda (w)
  3758. (setq c (string-to-char w))
  3759. (if (equal c ?-)
  3760. (setq neg t w (substring w 1))
  3761. (if (equal c ?+)
  3762. (setq neg nil w (substring w 1))
  3763. (setq neg nil)))
  3764. (if (string-match "\\`{.*}\\'" w)
  3765. (setq re (substring w 1 -1))
  3766. (if full-words
  3767. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3768. (setq re (regexp-quote (downcase w)))))
  3769. (if neg (push re regexps-) (push re regexps+)))
  3770. words)
  3771. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3772. regexps+))
  3773. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3774. (if (not regexps+)
  3775. (setq regexp org-outline-regexp-bol)
  3776. (setq regexp (pop regexps+))
  3777. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3778. regexp))))
  3779. (setq files (org-agenda-files nil 'ifmode))
  3780. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3781. (pop org-agenda-text-search-extra-files)
  3782. (setq files (org-add-archive-files files)))
  3783. (setq files (append files org-agenda-text-search-extra-files)
  3784. rtnall nil)
  3785. (while (setq file (pop files))
  3786. (setq ee nil)
  3787. (catch 'nextfile
  3788. (org-check-agenda-file file)
  3789. (setq buffer (if (file-exists-p file)
  3790. (org-get-agenda-file-buffer file)
  3791. (error "No such file %s" file)))
  3792. (if (not buffer)
  3793. ;; If file does not exist, make sure an error message is sent
  3794. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3795. file))))
  3796. (with-current-buffer buffer
  3797. (with-syntax-table (org-search-syntax-table)
  3798. (unless (derived-mode-p 'org-mode)
  3799. (error "Agenda file %s is not in `org-mode'" file))
  3800. (let ((case-fold-search t))
  3801. (save-excursion
  3802. (save-restriction
  3803. (if org-agenda-restrict
  3804. (narrow-to-region org-agenda-restrict-begin
  3805. org-agenda-restrict-end)
  3806. (widen))
  3807. (goto-char (point-min))
  3808. (unless (or (org-at-heading-p)
  3809. (outline-next-heading))
  3810. (throw 'nextfile t))
  3811. (goto-char (max (point-min) (1- (point))))
  3812. (while (re-search-forward regexp nil t)
  3813. (org-back-to-heading t)
  3814. (skip-chars-forward "* ")
  3815. (setq beg (point-at-bol)
  3816. beg1 (point)
  3817. end (progn (outline-next-heading) (point)))
  3818. (catch :skip
  3819. (goto-char beg)
  3820. (org-agenda-skip)
  3821. (setq str (buffer-substring-no-properties
  3822. (point-at-bol)
  3823. (if hdl-only (point-at-eol) end)))
  3824. (mapc (lambda (wr) (when (string-match wr str)
  3825. (goto-char (1- end))
  3826. (throw :skip t)))
  3827. regexps-)
  3828. (mapc (lambda (wr) (unless (string-match wr str)
  3829. (goto-char (1- end))
  3830. (throw :skip t)))
  3831. (if todo-only
  3832. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3833. regexps+)
  3834. regexps+))
  3835. (goto-char beg)
  3836. (setq marker (org-agenda-new-marker (point))
  3837. category (org-get-category)
  3838. org-category-pos (get-text-property (point) 'org-category-position)
  3839. tags (org-get-tags-at (point))
  3840. txt (org-agenda-format-item
  3841. ""
  3842. (buffer-substring-no-properties
  3843. beg1 (point-at-eol))
  3844. category tags))
  3845. (org-add-props txt props
  3846. 'org-marker marker 'org-hd-marker marker
  3847. 'org-todo-regexp org-todo-regexp
  3848. 'org-complex-heading-regexp org-complex-heading-regexp
  3849. 'priority 1000 'org-category category
  3850. 'org-category-position org-category-pos
  3851. 'type "search")
  3852. (push txt ee)
  3853. (goto-char (1- end))))))))))
  3854. (setq rtn (nreverse ee))
  3855. (setq rtnall (append rtnall rtn)))
  3856. (if org-agenda-overriding-header
  3857. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3858. nil 'face 'org-agenda-structure) "\n")
  3859. (insert "Search words: ")
  3860. (add-text-properties (point-min) (1- (point))
  3861. (list 'face 'org-agenda-structure))
  3862. (setq pos (point))
  3863. (insert string "\n")
  3864. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3865. (setq pos (point))
  3866. (unless org-agenda-multi
  3867. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3868. (add-text-properties pos (1- (point))
  3869. (list 'face 'org-agenda-structure))))
  3870. (org-agenda-mark-header-line (point-min))
  3871. (when rtnall
  3872. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3873. (goto-char (point-min))
  3874. (or org-agenda-multi (org-fit-agenda-window))
  3875. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3876. (org-finalize-agenda)
  3877. (setq buffer-read-only t)))
  3878. ;;; Agenda TODO list
  3879. (defvar org-select-this-todo-keyword nil)
  3880. (defvar org-last-arg nil)
  3881. ;;;###autoload
  3882. (defun org-todo-list (arg)
  3883. "Show all (not done) TODO entries from all agenda file in a single list.
  3884. The prefix arg can be used to select a specific TODO keyword and limit
  3885. the list to these. When using \\[universal-argument], you will be prompted
  3886. for a keyword. A numeric prefix directly selects the Nth keyword in
  3887. `org-todo-keywords-1'."
  3888. (interactive "P")
  3889. (org-prepare-agenda "TODO")
  3890. (org-compile-prefix-format 'todo)
  3891. (org-set-sorting-strategy 'todo)
  3892. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3893. (let* ((today (org-today))
  3894. (date (calendar-gregorian-from-absolute today))
  3895. (kwds org-todo-keywords-for-agenda)
  3896. (completion-ignore-case t)
  3897. (org-select-this-todo-keyword
  3898. (if (stringp arg) arg
  3899. (and arg (integerp arg) (> arg 0)
  3900. (nth (1- arg) kwds))))
  3901. rtn rtnall files file pos)
  3902. (when (equal arg '(4))
  3903. (setq org-select-this-todo-keyword
  3904. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3905. (mapcar 'list kwds) nil nil)))
  3906. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3907. (org-set-local 'org-last-arg arg)
  3908. (setq org-agenda-redo-command
  3909. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3910. (setq files (org-agenda-files nil 'ifmode)
  3911. rtnall nil)
  3912. (while (setq file (pop files))
  3913. (catch 'nextfile
  3914. (org-check-agenda-file file)
  3915. (setq rtn (org-agenda-get-day-entries file date :todo))
  3916. (setq rtnall (append rtnall rtn))))
  3917. (if org-agenda-overriding-header
  3918. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3919. nil 'face 'org-agenda-structure) "\n")
  3920. (insert "Global list of TODO items of type: ")
  3921. (add-text-properties (point-min) (1- (point))
  3922. (list 'face 'org-agenda-structure
  3923. 'short-heading
  3924. (concat "ToDo: "
  3925. (or org-select-this-todo-keyword "ALL"))))
  3926. (org-agenda-mark-header-line (point-min))
  3927. (setq pos (point))
  3928. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3929. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3930. (setq pos (point))
  3931. (unless org-agenda-multi
  3932. (insert "Available with `N r': (0)ALL")
  3933. (let ((n 0) s)
  3934. (mapc (lambda (x)
  3935. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3936. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3937. (insert "\n "))
  3938. (insert " " s))
  3939. kwds))
  3940. (insert "\n"))
  3941. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3942. (org-agenda-mark-header-line (point-min))
  3943. (when rtnall
  3944. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3945. (goto-char (point-min))
  3946. (or org-agenda-multi (org-fit-agenda-window))
  3947. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3948. (org-finalize-agenda)
  3949. (setq buffer-read-only t)))
  3950. ;;; Agenda tags match
  3951. ;;;###autoload
  3952. (defun org-tags-view (&optional todo-only match)
  3953. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3954. The prefix arg TODO-ONLY limits the search to TODO entries."
  3955. (interactive "P")
  3956. (let* ((org-tags-match-list-sublevels
  3957. org-tags-match-list-sublevels)
  3958. (completion-ignore-case t)
  3959. rtn rtnall files file pos matcher
  3960. buffer)
  3961. (when (and (stringp match) (not (string-match "\\S-" match)))
  3962. (setq match nil))
  3963. (setq matcher (org-make-tags-matcher match)
  3964. match (car matcher) matcher (cdr matcher))
  3965. (org-prepare-agenda (concat "TAGS " match))
  3966. (org-compile-prefix-format 'tags)
  3967. (org-set-sorting-strategy 'tags)
  3968. (setq org-agenda-query-string match)
  3969. (setq org-agenda-redo-command
  3970. (list 'org-tags-view (list 'quote todo-only)
  3971. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3972. (setq files (org-agenda-files nil 'ifmode)
  3973. rtnall nil)
  3974. (while (setq file (pop files))
  3975. (catch 'nextfile
  3976. (org-check-agenda-file file)
  3977. (setq buffer (if (file-exists-p file)
  3978. (org-get-agenda-file-buffer file)
  3979. (error "No such file %s" file)))
  3980. (if (not buffer)
  3981. ;; If file does not exist, error message to agenda
  3982. (setq rtn (list
  3983. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3984. rtnall (append rtnall rtn))
  3985. (with-current-buffer buffer
  3986. (unless (derived-mode-p 'org-mode)
  3987. (error "Agenda file %s is not in `org-mode'" file))
  3988. (save-excursion
  3989. (save-restriction
  3990. (if org-agenda-restrict
  3991. (narrow-to-region org-agenda-restrict-begin
  3992. org-agenda-restrict-end)
  3993. (widen))
  3994. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3995. (setq rtnall (append rtnall rtn))))))))
  3996. (if org-agenda-overriding-header
  3997. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3998. nil 'face 'org-agenda-structure) "\n")
  3999. (insert "Headlines with TAGS match: ")
  4000. (add-text-properties (point-min) (1- (point))
  4001. (list 'face 'org-agenda-structure
  4002. 'short-heading
  4003. (concat "Match: " match)))
  4004. (setq pos (point))
  4005. (insert match "\n")
  4006. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4007. (setq pos (point))
  4008. (unless org-agenda-multi
  4009. (insert "Press `C-u r' to search again with new search string\n"))
  4010. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4011. (org-agenda-mark-header-line (point-min))
  4012. (when rtnall
  4013. (insert (org-finalize-agenda-entries rtnall) "\n"))
  4014. (goto-char (point-min))
  4015. (or org-agenda-multi (org-fit-agenda-window))
  4016. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  4017. (org-finalize-agenda)
  4018. (setq buffer-read-only t)))
  4019. ;;; Agenda Finding stuck projects
  4020. (defvar org-agenda-skip-regexp nil
  4021. "Regular expression used in skipping subtrees for the agenda.
  4022. This is basically a temporary global variable that can be set and then
  4023. used by user-defined selections using `org-agenda-skip-function'.")
  4024. (defvar org-agenda-overriding-header nil
  4025. "When set during agenda, todo and tags searches it replaces the header.
  4026. This variable should not be set directly, but custom commands can bind it
  4027. in the options section.")
  4028. (defun org-agenda-skip-entry-when-regexp-matches ()
  4029. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4030. If yes, it returns the end position of this entry, causing agenda commands
  4031. to skip the entry but continuing the search in the subtree. This is a
  4032. function that can be put into `org-agenda-skip-function' for the duration
  4033. of a command."
  4034. (let ((end (save-excursion (org-end-of-subtree t)))
  4035. skip)
  4036. (save-excursion
  4037. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4038. (and skip end)))
  4039. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4040. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4041. If yes, it returns the end position of this tree, causing agenda commands
  4042. to skip this subtree. This is a function that can be put into
  4043. `org-agenda-skip-function' for the duration of a command."
  4044. (let ((end (save-excursion (org-end-of-subtree t)))
  4045. skip)
  4046. (save-excursion
  4047. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4048. (and skip end)))
  4049. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4050. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4051. If yes, it returns the end position of the current entry (NOT the tree),
  4052. causing agenda commands to skip the entry but continuing the search in
  4053. the subtree. This is a function that can be put into
  4054. `org-agenda-skip-function' for the duration of a command. An important
  4055. use of this function is for the stuck project list."
  4056. (let ((end (save-excursion (org-end-of-subtree t)))
  4057. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4058. skip)
  4059. (save-excursion
  4060. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4061. (and skip entry-end)))
  4062. (defun org-agenda-skip-entry-if (&rest conditions)
  4063. "Skip entry if any of CONDITIONS is true.
  4064. See `org-agenda-skip-if' for details."
  4065. (org-agenda-skip-if nil conditions))
  4066. (defun org-agenda-skip-subtree-if (&rest conditions)
  4067. "Skip entry if any of CONDITIONS is true.
  4068. See `org-agenda-skip-if' for details."
  4069. (org-agenda-skip-if t conditions))
  4070. (defun org-agenda-skip-if (subtree conditions)
  4071. "Checks current entity for CONDITIONS.
  4072. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4073. the entry (i.e. the text before the next heading) is checked.
  4074. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4075. from different tests. Valid conditions are:
  4076. scheduled Check if there is a scheduled cookie
  4077. notscheduled Check if there is no scheduled cookie
  4078. deadline Check if there is a deadline
  4079. notdeadline Check if there is no deadline
  4080. timestamp Check if there is a timestamp (also deadline or scheduled)
  4081. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4082. regexp Check if regexp matches
  4083. notregexp Check if regexp does not match.
  4084. todo Check if TODO keyword matches
  4085. nottodo Check if TODO keyword does not match
  4086. The regexp is taken from the conditions list, it must come right after
  4087. the `regexp' or `notregexp' element.
  4088. `todo' and `nottodo' accept as an argument a list of todo
  4089. keywords, which may include \"*\" to match any todo keyword.
  4090. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4091. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4092. Instead of a list, a keyword class may be given. For example:
  4093. (org-agenda-skip-entry-if 'nottodo 'done)
  4094. would skip entries that haven't been marked with any of \"DONE\"
  4095. keywords. Possible classes are: `todo', `done', `any'.
  4096. If any of these conditions is met, this function returns the end point of
  4097. the entity, causing the search to continue from there. This is a function
  4098. that can be put into `org-agenda-skip-function' for the duration of a command."
  4099. (let (beg end m)
  4100. (org-back-to-heading t)
  4101. (setq beg (point)
  4102. end (if subtree
  4103. (progn (org-end-of-subtree t) (point))
  4104. (progn (outline-next-heading) (1- (point)))))
  4105. (goto-char beg)
  4106. (and
  4107. (or
  4108. (and (memq 'scheduled conditions)
  4109. (re-search-forward org-scheduled-time-regexp end t))
  4110. (and (memq 'notscheduled conditions)
  4111. (not (re-search-forward org-scheduled-time-regexp end t)))
  4112. (and (memq 'deadline conditions)
  4113. (re-search-forward org-deadline-time-regexp end t))
  4114. (and (memq 'notdeadline conditions)
  4115. (not (re-search-forward org-deadline-time-regexp end t)))
  4116. (and (memq 'timestamp conditions)
  4117. (re-search-forward org-ts-regexp end t))
  4118. (and (memq 'nottimestamp conditions)
  4119. (not (re-search-forward org-ts-regexp end t)))
  4120. (and (setq m (memq 'regexp conditions))
  4121. (stringp (nth 1 m))
  4122. (re-search-forward (nth 1 m) end t))
  4123. (and (setq m (memq 'notregexp conditions))
  4124. (stringp (nth 1 m))
  4125. (not (re-search-forward (nth 1 m) end t)))
  4126. (and (or
  4127. (setq m (memq 'nottodo conditions))
  4128. (setq m (memq 'todo-unblocked conditions))
  4129. (setq m (memq 'nottodo-unblocked conditions))
  4130. (setq m (memq 'todo conditions)))
  4131. (org-agenda-skip-if-todo m end)))
  4132. end)))
  4133. (defun org-agenda-skip-if-todo (args end)
  4134. "Helper function for `org-agenda-skip-if', do not use it directly.
  4135. ARGS is a list with first element either `todo', `nottodo',
  4136. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4137. a list of TODO keywords, or a state symbol `todo' or `done' or
  4138. `any'."
  4139. (let ((kw (car args))
  4140. (arg (cadr args))
  4141. todo-wds todo-re)
  4142. (setq todo-wds
  4143. (org-uniquify
  4144. (cond
  4145. ((listp arg) ;; list of keywords
  4146. (if (member "*" arg)
  4147. (mapcar 'substring-no-properties org-todo-keywords-1)
  4148. arg))
  4149. ((symbolp arg) ;; keyword class name
  4150. (cond
  4151. ((eq arg 'todo)
  4152. (org-delete-all org-done-keywords
  4153. (mapcar 'substring-no-properties
  4154. org-todo-keywords-1)))
  4155. ((eq arg 'done) org-done-keywords)
  4156. ((eq arg 'any)
  4157. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4158. (setq todo-re
  4159. (concat "^\\*+[ \t]+\\<\\("
  4160. (mapconcat 'identity todo-wds "\\|")
  4161. "\\)\\>"))
  4162. (cond
  4163. ((eq kw 'todo) (re-search-forward todo-re end t))
  4164. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4165. ((eq kw 'todo-unblocked)
  4166. (catch 'unblocked
  4167. (while (re-search-forward todo-re end t)
  4168. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4169. nil))
  4170. ((eq kw 'nottodo-unblocked)
  4171. (catch 'unblocked
  4172. (while (re-search-forward todo-re end t)
  4173. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4174. t))
  4175. )))
  4176. ;;;###autoload
  4177. (defun org-agenda-list-stuck-projects (&rest ignore)
  4178. "Create agenda view for projects that are stuck.
  4179. Stuck projects are project that have no next actions. For the definitions
  4180. of what a project is and how to check if it stuck, customize the variable
  4181. `org-stuck-projects'."
  4182. (interactive)
  4183. (let* ((org-agenda-skip-function
  4184. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4185. ;; We could have used org-agenda-skip-if here.
  4186. (org-agenda-overriding-header
  4187. (or org-agenda-overriding-header "List of stuck projects: "))
  4188. (matcher (nth 0 org-stuck-projects))
  4189. (todo (nth 1 org-stuck-projects))
  4190. (todo-wds (if (member "*" todo)
  4191. (progn
  4192. (org-prepare-agenda-buffers (org-agenda-files
  4193. nil 'ifmode))
  4194. (org-delete-all
  4195. org-done-keywords-for-agenda
  4196. (copy-sequence org-todo-keywords-for-agenda)))
  4197. todo))
  4198. (todo-re (concat "^\\*+[ \t]+\\("
  4199. (mapconcat 'identity todo-wds "\\|")
  4200. "\\)\\>"))
  4201. (tags (nth 2 org-stuck-projects))
  4202. (tags-re (if (member "*" tags)
  4203. (concat org-outline-regexp-bol
  4204. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4205. (if tags
  4206. (concat org-outline-regexp-bol
  4207. ".*:\\("
  4208. (mapconcat 'identity tags "\\|")
  4209. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4210. (gen-re (nth 3 org-stuck-projects))
  4211. (re-list
  4212. (delq nil
  4213. (list
  4214. (if todo todo-re)
  4215. (if tags tags-re)
  4216. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4217. gen-re)))))
  4218. (setq org-agenda-skip-regexp
  4219. (if re-list
  4220. (mapconcat 'identity re-list "\\|")
  4221. (error "No information how to identify unstuck projects")))
  4222. (org-tags-view nil matcher)
  4223. (with-current-buffer org-agenda-buffer-name
  4224. (setq org-agenda-redo-command
  4225. '(org-agenda-list-stuck-projects
  4226. (or current-prefix-arg org-last-arg))))))
  4227. ;;; Diary integration
  4228. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4229. (defvar diary-list-entries-hook)
  4230. (defvar diary-time-regexp)
  4231. (defun org-get-entries-from-diary (date)
  4232. "Get the (Emacs Calendar) diary entries for DATE."
  4233. (require 'diary-lib)
  4234. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4235. (diary-display-hook '(fancy-diary-display))
  4236. (diary-display-function 'fancy-diary-display)
  4237. (pop-up-frames nil)
  4238. (diary-list-entries-hook
  4239. (cons 'org-diary-default-entry diary-list-entries-hook))
  4240. (diary-file-name-prefix-function nil) ; turn this feature off
  4241. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4242. entries
  4243. (org-disable-agenda-to-diary t))
  4244. (save-excursion
  4245. (save-window-excursion
  4246. (funcall (if (fboundp 'diary-list-entries)
  4247. 'diary-list-entries 'list-diary-entries)
  4248. date 1)))
  4249. (if (not (get-buffer diary-fancy-buffer))
  4250. (setq entries nil)
  4251. (with-current-buffer diary-fancy-buffer
  4252. (setq buffer-read-only nil)
  4253. (if (zerop (buffer-size))
  4254. ;; No entries
  4255. (setq entries nil)
  4256. ;; Omit the date and other unnecessary stuff
  4257. (org-agenda-cleanup-fancy-diary)
  4258. ;; Add prefix to each line and extend the text properties
  4259. (if (zerop (buffer-size))
  4260. (setq entries nil)
  4261. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4262. (setq entries
  4263. (with-temp-buffer
  4264. (insert entries) (goto-char (point-min))
  4265. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4266. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4267. (replace-match (concat "; " (match-string 1)))))
  4268. (buffer-string)))))
  4269. (set-buffer-modified-p nil)
  4270. (kill-buffer diary-fancy-buffer)))
  4271. (when entries
  4272. (setq entries (org-split-string entries "\n"))
  4273. (setq entries
  4274. (mapcar
  4275. (lambda (x)
  4276. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4277. ;; Extend the text properties to the beginning of the line
  4278. (org-add-props x (text-properties-at (1- (length x)) x)
  4279. 'type "diary" 'date date 'face 'org-agenda-diary))
  4280. entries)))))
  4281. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4282. "Hook run when the fancy diary buffer is cleaned up.")
  4283. (defun org-agenda-cleanup-fancy-diary ()
  4284. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4285. This gets rid of the date, the underline under the date, and
  4286. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4287. date. It also removes lines that contain only whitespace."
  4288. (goto-char (point-min))
  4289. (if (looking-at ".*?:[ \t]*")
  4290. (progn
  4291. (replace-match "")
  4292. (re-search-forward "\n=+$" nil t)
  4293. (replace-match "")
  4294. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4295. (re-search-forward "\n=+$" nil t)
  4296. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4297. (goto-char (point-min))
  4298. (while (re-search-forward "^ +\n" nil t)
  4299. (replace-match ""))
  4300. (goto-char (point-min))
  4301. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4302. (replace-match ""))
  4303. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4304. ;; Make sure entries from the diary have the right text properties.
  4305. (eval-after-load "diary-lib"
  4306. '(if (boundp 'diary-modify-entry-list-string-function)
  4307. ;; We can rely on the hook, nothing to do
  4308. nil
  4309. ;; Hook not available, must use advice to make this work
  4310. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4311. "Make the position visible."
  4312. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4313. (stringp string)
  4314. buffer-file-name)
  4315. (setq string (org-modify-diary-entry-string string))))))
  4316. (defun org-modify-diary-entry-string (string)
  4317. "Add text properties to string, allowing org-mode to act on it."
  4318. (org-add-props string nil
  4319. 'mouse-face 'highlight
  4320. 'help-echo (if buffer-file-name
  4321. (format "mouse-2 or RET jump to diary file %s"
  4322. (abbreviate-file-name buffer-file-name))
  4323. "")
  4324. 'org-agenda-diary-link t
  4325. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4326. (defun org-diary-default-entry ()
  4327. "Add a dummy entry to the diary.
  4328. Needed to avoid empty dates which mess up holiday display."
  4329. ;; Catch the error if dealing with the new add-to-diary-alist
  4330. (when org-disable-agenda-to-diary
  4331. (condition-case nil
  4332. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4333. (error
  4334. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4335. (defun org-add-to-diary-list (&rest args)
  4336. (if (fboundp 'diary-add-to-list)
  4337. (apply 'diary-add-to-list args)
  4338. (apply 'add-to-diary-list args)))
  4339. (defvar org-diary-last-run-time nil)
  4340. ;;;###autoload
  4341. (defun org-diary (&rest args)
  4342. "Return diary information from org-files.
  4343. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4344. It accesses org files and extracts information from those files to be
  4345. listed in the diary. The function accepts arguments specifying what
  4346. items should be listed. For a list of arguments allowed here, see the
  4347. variable `org-agenda-entry-types'.
  4348. The call in the diary file should look like this:
  4349. &%%(org-diary) ~/path/to/some/orgfile.org
  4350. Use a separate line for each org file to check. Or, if you omit the file name,
  4351. all files listed in `org-agenda-files' will be checked automatically:
  4352. &%%(org-diary)
  4353. If you don't give any arguments (as in the example above), the default
  4354. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4355. So the example above may also be written as
  4356. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4357. The function expects the lisp variables `entry' and `date' to be provided
  4358. by the caller, because this is how the calendar works. Don't use this
  4359. function from a program - use `org-agenda-get-day-entries' instead."
  4360. (when (> (- (org-float-time)
  4361. org-agenda-last-marker-time)
  4362. 5)
  4363. ;; I am not sure if this works with sticky agendas, because the marker
  4364. ;; list is then no longer a global variable.
  4365. (org-agenda-reset-markers))
  4366. ;; Prevent `org-compile-prefix-format' to fail when there is no agenda
  4367. (when (buffer-live-p org-agenda-buffer)
  4368. (org-compile-prefix-format 'agenda))
  4369. (org-set-sorting-strategy 'agenda)
  4370. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4371. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4372. (list entry)
  4373. (org-agenda-files t)))
  4374. (time (org-float-time))
  4375. file rtn results)
  4376. (when (or (not org-diary-last-run-time)
  4377. (> (- time
  4378. org-diary-last-run-time)
  4379. 3))
  4380. (org-prepare-agenda-buffers files))
  4381. (setq org-diary-last-run-time time)
  4382. ;; If this is called during org-agenda, don't return any entries to
  4383. ;; the calendar. Org Agenda will list these entries itself.
  4384. (if org-disable-agenda-to-diary (setq files nil))
  4385. (while (setq file (pop files))
  4386. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4387. (setq results (append results rtn)))
  4388. (if results
  4389. (concat (org-finalize-agenda-entries results) "\n"))))
  4390. ;;; Agenda entry finders
  4391. (defun org-agenda-get-day-entries (file date &rest args)
  4392. "Does the work for `org-diary' and `org-agenda'.
  4393. FILE is the path to a file to be checked for entries. DATE is date like
  4394. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4395. which kind of entries should be extracted. For details about these, see
  4396. the documentation of `org-diary'."
  4397. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4398. (let* ((org-startup-folded nil)
  4399. (org-startup-align-all-tables nil)
  4400. (buffer (if (file-exists-p file)
  4401. (org-get-agenda-file-buffer file)
  4402. (error "No such file %s" file)))
  4403. arg results rtn deadline-results)
  4404. (if (not buffer)
  4405. ;; If file does not exist, make sure an error message ends up in diary
  4406. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4407. (with-current-buffer buffer
  4408. (unless (derived-mode-p 'org-mode)
  4409. (error "Agenda file %s is not in `org-mode'" file))
  4410. (let ((case-fold-search nil))
  4411. (save-excursion
  4412. (save-restriction
  4413. (if org-agenda-restrict
  4414. (narrow-to-region org-agenda-restrict-begin
  4415. org-agenda-restrict-end)
  4416. (widen))
  4417. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4418. (while (setq arg (pop args))
  4419. (cond
  4420. ((and (eq arg :todo)
  4421. (equal date (calendar-gregorian-from-absolute
  4422. (org-today))))
  4423. (setq rtn (org-agenda-get-todos))
  4424. (setq results (append results rtn)))
  4425. ((eq arg :timestamp)
  4426. (setq rtn (org-agenda-get-blocks))
  4427. (setq results (append results rtn))
  4428. (setq rtn (org-agenda-get-timestamps deadline-results))
  4429. (setq results (append results rtn)))
  4430. ((eq arg :sexp)
  4431. (setq rtn (org-agenda-get-sexps))
  4432. (setq results (append results rtn)))
  4433. ((eq arg :scheduled)
  4434. (setq rtn (org-agenda-get-scheduled deadline-results))
  4435. (setq results (append results rtn)))
  4436. ((eq arg :closed)
  4437. (setq rtn (org-agenda-get-progress))
  4438. (setq results (append results rtn)))
  4439. ((eq arg :deadline)
  4440. (setq rtn (org-agenda-get-deadlines))
  4441. (setq deadline-results (copy-sequence rtn))
  4442. (setq results (append results rtn))))))))
  4443. results))))
  4444. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4445. (defun org-agenda-get-todos ()
  4446. "Return the TODO information for agenda display."
  4447. (let* ((props (list 'face nil
  4448. 'done-face 'org-agenda-done
  4449. 'org-not-done-regexp org-not-done-regexp
  4450. 'org-todo-regexp org-todo-regexp
  4451. 'org-complex-heading-regexp org-complex-heading-regexp
  4452. 'mouse-face 'highlight
  4453. 'help-echo
  4454. (format "mouse-2 or RET jump to org file %s"
  4455. (abbreviate-file-name buffer-file-name))))
  4456. (regexp (format org-heading-keyword-regexp-format
  4457. (cond
  4458. ((and org-select-this-todo-keyword
  4459. (equal org-select-this-todo-keyword "*"))
  4460. org-todo-regexp)
  4461. (org-select-this-todo-keyword
  4462. (concat "\\("
  4463. (mapconcat 'identity
  4464. (org-split-string
  4465. org-select-this-todo-keyword
  4466. "|")
  4467. "\\|") "\\)"))
  4468. (t org-not-done-regexp))))
  4469. marker priority category org-category-pos tags todo-state
  4470. ee txt beg end)
  4471. (goto-char (point-min))
  4472. (while (re-search-forward regexp nil t)
  4473. (catch :skip
  4474. (save-match-data
  4475. (beginning-of-line)
  4476. (org-agenda-skip)
  4477. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4478. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4479. (goto-char (1+ beg))
  4480. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4481. (throw :skip nil)))
  4482. (goto-char (match-beginning 2))
  4483. (setq marker (org-agenda-new-marker (match-beginning 0))
  4484. category (org-get-category)
  4485. org-category-pos (get-text-property (point) 'org-category-position)
  4486. txt (org-trim
  4487. (buffer-substring (match-beginning 2) (match-end 0)))
  4488. tags (org-get-tags-at (point))
  4489. txt (org-agenda-format-item "" txt category tags)
  4490. priority (1+ (org-get-priority txt))
  4491. todo-state (org-get-todo-state))
  4492. (org-add-props txt props
  4493. 'org-marker marker 'org-hd-marker marker
  4494. 'priority priority 'org-category category
  4495. 'org-category-position org-category-pos
  4496. 'type "todo" 'todo-state todo-state)
  4497. (push txt ee)
  4498. (if org-agenda-todo-list-sublevels
  4499. (goto-char (match-end 2))
  4500. (org-end-of-subtree 'invisible))))
  4501. (nreverse ee)))
  4502. (defun org-agenda-todo-custom-ignore-p (time n)
  4503. "Check whether timestamp is farther away then n number of days.
  4504. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4505. `org-agenda-todo-ignore-scheduled' or
  4506. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4507. (let ((days (org-days-to-time time)))
  4508. (if (>= n 0)
  4509. (>= days n)
  4510. (<= days n))))
  4511. ;;;###autoload
  4512. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4513. (&optional end)
  4514. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4515. (when (or org-agenda-todo-ignore-with-date
  4516. org-agenda-todo-ignore-scheduled
  4517. org-agenda-todo-ignore-deadlines
  4518. org-agenda-todo-ignore-timestamp)
  4519. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4520. (save-excursion
  4521. (or (and org-agenda-todo-ignore-with-date
  4522. (re-search-forward org-ts-regexp end t))
  4523. (and org-agenda-todo-ignore-scheduled
  4524. (re-search-forward org-scheduled-time-regexp end t)
  4525. (cond
  4526. ((eq org-agenda-todo-ignore-scheduled 'future)
  4527. (> (org-days-to-time (match-string 1)) 0))
  4528. ((eq org-agenda-todo-ignore-scheduled 'past)
  4529. (<= (org-days-to-time (match-string 1)) 0))
  4530. ((numberp org-agenda-todo-ignore-scheduled)
  4531. (org-agenda-todo-custom-ignore-p
  4532. (match-string 1) org-agenda-todo-ignore-scheduled))
  4533. (t)))
  4534. (and org-agenda-todo-ignore-deadlines
  4535. (re-search-forward org-deadline-time-regexp end t)
  4536. (cond
  4537. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4538. ((eq org-agenda-todo-ignore-deadlines 'far)
  4539. (not (org-deadline-close (match-string 1))))
  4540. ((eq org-agenda-todo-ignore-deadlines 'future)
  4541. (> (org-days-to-time (match-string 1)) 0))
  4542. ((eq org-agenda-todo-ignore-deadlines 'past)
  4543. (<= (org-days-to-time (match-string 1)) 0))
  4544. ((numberp org-agenda-todo-ignore-deadlines)
  4545. (org-agenda-todo-custom-ignore-p
  4546. (match-string 1) org-agenda-todo-ignore-deadlines))
  4547. (t (org-deadline-close (match-string 1)))))
  4548. (and org-agenda-todo-ignore-timestamp
  4549. (let ((buffer (current-buffer))
  4550. (regexp
  4551. (concat
  4552. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4553. (start (point)))
  4554. ;; Copy current buffer into a temporary one
  4555. (with-temp-buffer
  4556. (insert-buffer-substring buffer start end)
  4557. (goto-char (point-min))
  4558. ;; Delete SCHEDULED and DEADLINE items
  4559. (while (re-search-forward regexp end t)
  4560. (delete-region (match-beginning 0) (match-end 0)))
  4561. (goto-char (point-min))
  4562. ;; No search for timestamp left
  4563. (when (re-search-forward org-ts-regexp nil t)
  4564. (cond
  4565. ((eq org-agenda-todo-ignore-timestamp 'future)
  4566. (> (org-days-to-time (match-string 1)) 0))
  4567. ((eq org-agenda-todo-ignore-timestamp 'past)
  4568. (<= (org-days-to-time (match-string 1)) 0))
  4569. ((numberp org-agenda-todo-ignore-timestamp)
  4570. (org-agenda-todo-custom-ignore-p
  4571. (match-string 1) org-agenda-todo-ignore-timestamp))
  4572. (t))))))))))
  4573. (defconst org-agenda-no-heading-message
  4574. "No heading for this item in buffer or region.")
  4575. (defun org-agenda-get-timestamps (&optional deadline-results)
  4576. "Return the date stamp information for agenda display."
  4577. (let* ((props (list 'face 'org-agenda-calendar-event
  4578. 'org-not-done-regexp org-not-done-regexp
  4579. 'org-todo-regexp org-todo-regexp
  4580. 'org-complex-heading-regexp org-complex-heading-regexp
  4581. 'mouse-face 'highlight
  4582. 'help-echo
  4583. (format "mouse-2 or RET jump to org file %s"
  4584. (abbreviate-file-name buffer-file-name))))
  4585. (d1 (calendar-absolute-from-gregorian date))
  4586. mm
  4587. (deadline-position-alist
  4588. (mapcar (lambda (a) (and (setq mm (get-text-property
  4589. 0 'org-hd-marker a))
  4590. (cons (marker-position mm) a)))
  4591. deadline-results))
  4592. (remove-re org-ts-regexp)
  4593. (regexp
  4594. (concat
  4595. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4596. (regexp-quote
  4597. (substring
  4598. (format-time-string
  4599. (car org-time-stamp-formats)
  4600. (apply 'encode-time ; DATE bound by calendar
  4601. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4602. 1 11))
  4603. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4604. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4605. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4606. donep tmp priority category org-category-pos ee txt timestr tags
  4607. b0 b3 e3 head todo-state end-of-match show-all)
  4608. (goto-char (point-min))
  4609. (while (setq end-of-match (re-search-forward regexp nil t))
  4610. (setq b0 (match-beginning 0)
  4611. b3 (match-beginning 3) e3 (match-end 3)
  4612. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4613. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4614. (member todo-state
  4615. org-agenda-repeating-timestamp-show-all)))
  4616. (catch :skip
  4617. (and (org-at-date-range-p) (throw :skip nil))
  4618. (org-agenda-skip)
  4619. (if (and (match-end 1)
  4620. (not (= d1 (org-time-string-to-absolute
  4621. (match-string 1) d1 nil show-all
  4622. (current-buffer) b0))))
  4623. (throw :skip nil))
  4624. (if (and e3
  4625. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4626. (throw :skip nil))
  4627. (setq tmp (buffer-substring (max (point-min)
  4628. (- b0 org-ds-keyword-length))
  4629. b0)
  4630. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4631. inactivep (= (char-after b0) ?\[)
  4632. deadlinep (string-match org-deadline-regexp tmp)
  4633. scheduledp (string-match org-scheduled-regexp tmp)
  4634. closedp (and org-agenda-include-inactive-timestamps
  4635. (string-match org-closed-string tmp))
  4636. clockp (and org-agenda-include-inactive-timestamps
  4637. (or (string-match org-clock-string tmp)
  4638. (string-match "]-+\\'" tmp)))
  4639. donep (member todo-state org-done-keywords))
  4640. (if (or scheduledp deadlinep closedp clockp
  4641. (and donep org-agenda-skip-timestamp-if-done))
  4642. (throw :skip t))
  4643. (if (string-match ">" timestr)
  4644. ;; substring should only run to end of time stamp
  4645. (setq timestr (substring timestr 0 (match-end 0))))
  4646. (setq marker (org-agenda-new-marker b0)
  4647. category (org-get-category b0)
  4648. org-category-pos (get-text-property b0 'org-category-position))
  4649. (save-excursion
  4650. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4651. (setq txt org-agenda-no-heading-message)
  4652. (goto-char (match-beginning 0))
  4653. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4654. (assoc (point) deadline-position-alist))
  4655. (throw :skip nil))
  4656. (setq hdmarker (org-agenda-new-marker)
  4657. tags (org-get-tags-at))
  4658. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4659. (setq head (or (match-string 1) ""))
  4660. (setq txt (org-agenda-format-item
  4661. (if inactivep org-agenda-inactive-leader nil)
  4662. head category tags timestr
  4663. remove-re)))
  4664. (setq priority (org-get-priority txt))
  4665. (org-add-props txt props
  4666. 'org-marker marker 'org-hd-marker hdmarker)
  4667. (org-add-props txt nil 'priority priority
  4668. 'org-category category 'date date
  4669. 'org-category-position org-category-pos
  4670. 'todo-state todo-state
  4671. 'type "timestamp")
  4672. (push txt ee))
  4673. (if org-agenda-skip-additional-timestamps-same-entry
  4674. (outline-next-heading)
  4675. (goto-char end-of-match))))
  4676. (nreverse ee)))
  4677. (defun org-agenda-get-sexps ()
  4678. "Return the sexp information for agenda display."
  4679. (require 'diary-lib)
  4680. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4681. 'mouse-face 'highlight
  4682. 'help-echo
  4683. (format "mouse-2 or RET jump to org file %s"
  4684. (abbreviate-file-name buffer-file-name))))
  4685. (regexp "^&?%%(")
  4686. marker category extra org-category-pos ee txt tags entry
  4687. result beg b sexp sexp-entry todo-state)
  4688. (goto-char (point-min))
  4689. (while (re-search-forward regexp nil t)
  4690. (catch :skip
  4691. (org-agenda-skip)
  4692. (setq beg (match-beginning 0))
  4693. (goto-char (1- (match-end 0)))
  4694. (setq b (point))
  4695. (forward-sexp 1)
  4696. (setq sexp (buffer-substring b (point)))
  4697. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4698. (org-trim (match-string 1))
  4699. ""))
  4700. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4701. (when result
  4702. (setq marker (org-agenda-new-marker beg)
  4703. category (org-get-category beg)
  4704. org-category-pos (get-text-property beg 'org-category-position)
  4705. todo-state (org-get-todo-state))
  4706. (dolist (r (if (stringp result)
  4707. (list result)
  4708. result)) ;; we expect a list here
  4709. (when (and org-agenda-diary-sexp-prefix
  4710. (string-match org-agenda-diary-sexp-prefix r))
  4711. (setq extra (match-string 0 r)
  4712. r (replace-match "" nil nil r)))
  4713. (if (string-match "\\S-" r)
  4714. (setq txt r)
  4715. (setq txt "SEXP entry returned empty string"))
  4716. (setq txt (org-agenda-format-item
  4717. extra txt category tags 'time))
  4718. (org-add-props txt props 'org-marker marker)
  4719. (org-add-props txt nil
  4720. 'org-category category 'date date 'todo-state todo-state
  4721. 'org-category-position org-category-pos
  4722. 'type "sexp")
  4723. (push txt ee)))))
  4724. (nreverse ee)))
  4725. ;; Calendar sanity: define some functions that are independent of
  4726. ;; `calendar-date-style'.
  4727. ;; Normally I would like to use ISO format when calling the diary functions,
  4728. ;; but to make sure we still have Emacs 22 compatibility we bind
  4729. ;; also `european-calendar-style' and use european format
  4730. (defun org-anniversary (year month day &optional mark)
  4731. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4732. (org-no-warnings
  4733. (let ((calendar-date-style 'european) (european-calendar-style t))
  4734. (diary-anniversary day month year mark))))
  4735. (defun org-cyclic (N year month day &optional mark)
  4736. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4737. (org-no-warnings
  4738. (let ((calendar-date-style 'european) (european-calendar-style t))
  4739. (diary-cyclic N day month year mark))))
  4740. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4741. "Like `diary-block', but with fixed (ISO) order of arguments."
  4742. (org-no-warnings
  4743. (let ((calendar-date-style 'european) (european-calendar-style t))
  4744. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4745. (defun org-date (year month day &optional mark)
  4746. "Like `diary-date', but with fixed (ISO) order of arguments."
  4747. (org-no-warnings
  4748. (let ((calendar-date-style 'european) (european-calendar-style t))
  4749. (diary-date day month year mark))))
  4750. (defalias 'org-float 'diary-float)
  4751. ;; Define the` org-class' function
  4752. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4753. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4754. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4755. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4756. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4757. `holidays', then any date that is known by the Emacs calendar to be a
  4758. holiday will also be skipped."
  4759. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4760. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4761. (d (calendar-absolute-from-gregorian date)))
  4762. (and
  4763. (<= date1 d)
  4764. (<= d date2)
  4765. (= (calendar-day-of-week date) dayname)
  4766. (or (not skip-weeks)
  4767. (progn
  4768. (require 'cal-iso)
  4769. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4770. (not (and (memq 'holidays skip-weeks)
  4771. (calendar-check-holidays date)))
  4772. entry)))
  4773. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4774. "Like `org-class', but honor `calendar-date-style'.
  4775. The order of the first 2 times 3 arguments depends on the variable
  4776. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4777. So for American calendars, give this as MONTH DAY YEAR, for European as
  4778. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4779. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4780. is any number of ISO weeks in the block period for which the item should
  4781. be skipped.
  4782. This function is here only for backward compatibility and it is deprecated,
  4783. please use `org-class' instead."
  4784. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4785. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4786. (org-class
  4787. (nth 2 date1) (car date1) (nth 1 date1)
  4788. (nth 2 date2) (car date2) (nth 1 date2)
  4789. dayname skip-weeks)))
  4790. (make-obsolete 'org-diary-class 'org-class "")
  4791. (defvar org-agenda-show-log-scoped) ;; dynamically scope in ̀org-timeline' or`org-agenda-list'
  4792. (defalias 'org-get-closed 'org-agenda-get-progress)
  4793. (defun org-agenda-get-progress ()
  4794. "Return the logged TODO entries for agenda display."
  4795. (let* ((props (list 'mouse-face 'highlight
  4796. 'org-not-done-regexp org-not-done-regexp
  4797. 'org-todo-regexp org-todo-regexp
  4798. 'org-complex-heading-regexp org-complex-heading-regexp
  4799. 'help-echo
  4800. (format "mouse-2 or RET jump to org file %s"
  4801. (abbreviate-file-name buffer-file-name))))
  4802. (items (if (consp org-agenda-show-log-scoped)
  4803. org-agenda-show-log-scoped
  4804. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4805. '(clock)
  4806. org-agenda-log-mode-items)))
  4807. (parts
  4808. (delq nil
  4809. (list
  4810. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4811. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4812. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4813. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4814. (error "`org-agenda-log-mode-items' is empty")))
  4815. (regexp (concat
  4816. "\\(" parts-re "\\)"
  4817. " *\\["
  4818. (regexp-quote
  4819. (substring
  4820. (format-time-string
  4821. (car org-time-stamp-formats)
  4822. (apply 'encode-time ; DATE bound by calendar
  4823. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4824. 1 11))))
  4825. (org-agenda-search-headline-for-time nil)
  4826. marker hdmarker priority category org-category-pos tags closedp
  4827. statep clockp state ee txt extra timestr rest clocked)
  4828. (goto-char (point-min))
  4829. (while (re-search-forward regexp nil t)
  4830. (catch :skip
  4831. (org-agenda-skip)
  4832. (setq marker (org-agenda-new-marker (match-beginning 0))
  4833. closedp (equal (match-string 1) org-closed-string)
  4834. statep (equal (string-to-char (match-string 1)) ?-)
  4835. clockp (not (or closedp statep))
  4836. state (and statep (match-string 2))
  4837. category (org-get-category (match-beginning 0))
  4838. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4839. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4840. (when (string-match "\\]" timestr)
  4841. ;; substring should only run to end of time stamp
  4842. (setq rest (substring timestr (match-end 0))
  4843. timestr (substring timestr 0 (match-end 0)))
  4844. (if (and (not closedp) (not statep)
  4845. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4846. rest))
  4847. (progn (setq timestr (concat (substring timestr 0 -1)
  4848. "-" (match-string 1 rest) "]"))
  4849. (setq clocked (match-string 2 rest)))
  4850. (setq clocked "-")))
  4851. (save-excursion
  4852. (setq extra
  4853. (cond
  4854. ((not org-agenda-log-mode-add-notes) nil)
  4855. (statep
  4856. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4857. (match-string 1)))
  4858. (clockp
  4859. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4860. (match-string 1)))))
  4861. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4862. (setq txt org-agenda-no-heading-message)
  4863. (goto-char (match-beginning 0))
  4864. (setq hdmarker (org-agenda-new-marker)
  4865. tags (org-get-tags-at))
  4866. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4867. (setq txt (match-string 1))
  4868. (when extra
  4869. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4870. (setq txt (concat (substring txt 0 (match-beginning 1))
  4871. " - " extra " " (match-string 2 txt)))
  4872. (setq txt (concat txt " - " extra))))
  4873. (setq txt (org-agenda-format-item
  4874. (cond
  4875. (closedp "Closed: ")
  4876. (statep (concat "State: (" state ")"))
  4877. (t (concat "Clocked: (" clocked ")")))
  4878. txt category tags timestr)))
  4879. (setq priority 100000)
  4880. (org-add-props txt props
  4881. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4882. 'priority priority 'org-category category
  4883. 'org-category-position org-category-pos
  4884. 'type "closed" 'date date
  4885. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4886. (push txt ee))
  4887. (goto-char (point-at-eol))))
  4888. (nreverse ee)))
  4889. (defun org-agenda-show-clocking-issues ()
  4890. "Add overlays, showing issues with clocking.
  4891. See also the user option `org-agenda-clock-consistency-checks'."
  4892. (interactive)
  4893. (let* ((pl org-agenda-clock-consistency-checks)
  4894. (re (concat "^[ \t]*"
  4895. org-clock-string
  4896. "[ \t]+"
  4897. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4898. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4899. (tlstart 0.)
  4900. (tlend 0.)
  4901. (maxtime (org-hh:mm-string-to-minutes
  4902. (or (plist-get pl :max-duration) "24:00")))
  4903. (mintime (org-hh:mm-string-to-minutes
  4904. (or (plist-get pl :min-duration) 0)))
  4905. (maxgap (org-hh:mm-string-to-minutes
  4906. ;; default 30:00 means never complain
  4907. (or (plist-get pl :max-gap) "30:00")))
  4908. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4909. (plist-get pl :gap-ok-around)))
  4910. (def-face (or (plist-get pl :default-face)
  4911. '((:background "DarkRed") (:foreground "white"))))
  4912. issue face m te ts dt ov)
  4913. (goto-char (point-min))
  4914. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4915. (setq issue nil face def-face)
  4916. (catch 'next
  4917. (setq m (org-get-at-bol 'org-marker)
  4918. te nil ts nil)
  4919. (unless (and m (markerp m))
  4920. (setq issue "No valid clock line") (throw 'next t))
  4921. (org-with-point-at m
  4922. (save-excursion
  4923. (goto-char (point-at-bol))
  4924. (unless (looking-at re)
  4925. (error "No valid Clock line")
  4926. (throw 'next t))
  4927. (unless (match-end 3)
  4928. (setq issue "No end time"
  4929. face (or (plist-get pl :no-end-time-face) face))
  4930. (throw 'next t))
  4931. (setq ts (match-string 1)
  4932. te (match-string 3)
  4933. ts (org-float-time
  4934. (apply 'encode-time (org-parse-time-string ts)))
  4935. te (org-float-time
  4936. (apply 'encode-time (org-parse-time-string te)))
  4937. dt (- te ts))))
  4938. (cond
  4939. ((> dt (* 60 maxtime))
  4940. ;; a very long clocking chunk
  4941. (setq issue (format "Clocking interval is very long: %s"
  4942. (org-minutes-to-hh:mm-string
  4943. (floor (/ (float dt) 60.))))
  4944. face (or (plist-get pl :long-face) face)))
  4945. ((< dt (* 60 mintime))
  4946. ;; a very short clocking chunk
  4947. (setq issue (format "Clocking interval is very short: %s"
  4948. (org-minutes-to-hh:mm-string
  4949. (floor (/ (float dt) 60.))))
  4950. face (or (plist-get pl :short-face) face)))
  4951. ((and (> tlend 0) (< ts tlend))
  4952. ;; Two clock entries are overlapping
  4953. (setq issue (format "Clocking overlap: %d minutes"
  4954. (/ (- tlend ts) 60))
  4955. face (or (plist-get pl :overlap-face) face)))
  4956. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4957. ;; There is a gap, lets see if we need to report it
  4958. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4959. (setq issue (format "Clocking gap: %d minutes"
  4960. (/ (- ts tlend) 60))
  4961. face (or (plist-get pl :gap-face) face))))
  4962. (t nil)))
  4963. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4964. (when issue
  4965. ;; OK, there was some issue, add an overlay to show the issue
  4966. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4967. (overlay-put ov 'before-string
  4968. (concat
  4969. (org-add-props
  4970. (format "%-43s" (concat " " issue))
  4971. nil
  4972. 'face face)
  4973. "\n"))
  4974. (overlay-put ov 'evaporate t)))))
  4975. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4976. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4977. (catch 'exit
  4978. (unless ok-list
  4979. ;; there are no OK times for gaps...
  4980. (throw 'exit nil))
  4981. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4982. ;; This is more than 24 hours, so it is OK.
  4983. ;; because we have at least one OK time, that must be in the
  4984. ;; 24 hour interval.
  4985. (throw 'exit t))
  4986. ;; We have a shorter gap.
  4987. ;; Now we have to get the minute of the day when these times are
  4988. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4989. (t2dec (decode-time (seconds-to-time t2)))
  4990. ;; compute the minute on the day
  4991. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4992. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4993. (when (< min2 min1)
  4994. ;; if min2 is smaller than min1, this means it is on the next day.
  4995. ;; Wrap it to after midnight.
  4996. (setq min2 (+ min2 1440)))
  4997. ;; Now check if any of the OK times is in the gap
  4998. (mapc (lambda (x)
  4999. ;; Wrap the time to after midnight if necessary
  5000. (if (< x min1) (setq x (+ x 1440)))
  5001. ;; Check if in interval
  5002. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5003. ok-list)
  5004. ;; Nope, this gap is not OK
  5005. nil)))
  5006. (defun org-agenda-get-deadlines ()
  5007. "Return the deadline information for agenda display."
  5008. (let* ((props (list 'mouse-face 'highlight
  5009. 'org-not-done-regexp org-not-done-regexp
  5010. 'org-todo-regexp org-todo-regexp
  5011. 'org-complex-heading-regexp org-complex-heading-regexp
  5012. 'help-echo
  5013. (format "mouse-2 or RET jump to org file %s"
  5014. (abbreviate-file-name buffer-file-name))))
  5015. (regexp org-deadline-time-regexp)
  5016. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5017. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5018. d2 diff dfrac wdays pos pos1 category org-category-pos
  5019. tags suppress-prewarning ee txt head face s todo-state
  5020. show-all upcomingp donep timestr)
  5021. (goto-char (point-min))
  5022. (while (re-search-forward regexp nil t)
  5023. (setq suppress-prewarning nil)
  5024. (catch :skip
  5025. (org-agenda-skip)
  5026. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5027. (save-match-data
  5028. (string-match org-scheduled-time-regexp
  5029. (buffer-substring (point-at-bol)
  5030. (point-at-eol)))))
  5031. (setq suppress-prewarning
  5032. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5033. org-agenda-skip-deadline-prewarning-if-scheduled
  5034. 0)))
  5035. (setq s (match-string 1)
  5036. txt nil
  5037. pos (1- (match-beginning 1))
  5038. todo-state (save-match-data (org-get-todo-state))
  5039. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5040. (member todo-state
  5041. org-agenda-repeating-timestamp-show-all))
  5042. d2 (org-time-string-to-absolute
  5043. (match-string 1) d1 'past show-all
  5044. (current-buffer) pos)
  5045. diff (- d2 d1)
  5046. wdays (if suppress-prewarning
  5047. (let ((org-deadline-warning-days suppress-prewarning))
  5048. (org-get-wdays s))
  5049. (org-get-wdays s))
  5050. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5051. upcomingp (and todayp (> diff 0)))
  5052. ;; When to show a deadline in the calendar:
  5053. ;; If the expiration is within wdays warning time.
  5054. ;; Past-due deadlines are only shown on the current date
  5055. (if (and (or (and (<= diff wdays)
  5056. (and todayp (not org-agenda-only-exact-dates)))
  5057. (= diff 0)))
  5058. (save-excursion
  5059. ;; (setq todo-state (org-get-todo-state))
  5060. (setq donep (member todo-state org-done-keywords))
  5061. (if (and donep
  5062. (or org-agenda-skip-deadline-if-done
  5063. (not (= diff 0))))
  5064. (setq txt nil)
  5065. (setq category (org-get-category)
  5066. org-category-pos (get-text-property (point) 'org-category-position))
  5067. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5068. (setq txt org-agenda-no-heading-message)
  5069. (goto-char (match-end 0))
  5070. (setq pos1 (match-beginning 0))
  5071. (setq tags (org-get-tags-at pos1))
  5072. (setq head (buffer-substring-no-properties
  5073. (point)
  5074. (progn (skip-chars-forward "^\r\n")
  5075. (point))))
  5076. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5077. (setq timestr
  5078. (concat (substring s (match-beginning 1)) " "))
  5079. (setq timestr 'time))
  5080. (setq txt (org-agenda-format-item
  5081. (if (= diff 0)
  5082. (car org-agenda-deadline-leaders)
  5083. (if (functionp
  5084. (nth 1 org-agenda-deadline-leaders))
  5085. (funcall
  5086. (nth 1 org-agenda-deadline-leaders)
  5087. diff date)
  5088. (format (nth 1 org-agenda-deadline-leaders)
  5089. diff)))
  5090. head category tags
  5091. (if (not (= diff 0)) nil timestr)))))
  5092. (when txt
  5093. (setq face (org-agenda-deadline-face dfrac))
  5094. (org-add-props txt props
  5095. 'org-marker (org-agenda-new-marker pos)
  5096. 'org-hd-marker (org-agenda-new-marker pos1)
  5097. 'priority (+ (- diff)
  5098. (org-get-priority txt))
  5099. 'org-category category
  5100. 'org-category-position org-category-pos
  5101. 'todo-state todo-state
  5102. 'type (if upcomingp "upcoming-deadline" "deadline")
  5103. 'date (if upcomingp date d2)
  5104. 'face (if donep 'org-agenda-done face)
  5105. 'undone-face face 'done-face 'org-agenda-done)
  5106. (push txt ee))))))
  5107. (nreverse ee)))
  5108. (defun org-agenda-deadline-face (fraction)
  5109. "Return the face to displaying a deadline item.
  5110. FRACTION is what fraction of the head-warning time has passed."
  5111. (let ((faces org-agenda-deadline-faces) f)
  5112. (catch 'exit
  5113. (while (setq f (pop faces))
  5114. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5115. (defun org-agenda-get-scheduled (&optional deadline-results)
  5116. "Return the scheduled information for agenda display."
  5117. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5118. 'org-todo-regexp org-todo-regexp
  5119. 'org-complex-heading-regexp org-complex-heading-regexp
  5120. 'done-face 'org-agenda-done
  5121. 'mouse-face 'highlight
  5122. 'help-echo
  5123. (format "mouse-2 or RET jump to org file %s"
  5124. (abbreviate-file-name buffer-file-name))))
  5125. (regexp org-scheduled-time-regexp)
  5126. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5127. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5128. mm
  5129. (deadline-position-alist
  5130. (mapcar (lambda (a) (and (setq mm (get-text-property
  5131. 0 'org-hd-marker a))
  5132. (cons (marker-position mm) a)))
  5133. deadline-results))
  5134. d2 diff pos pos1 category org-category-pos tags donep
  5135. ee txt head pastschedp todo-state face timestr s habitp show-all
  5136. did-habit-check-p)
  5137. (goto-char (point-min))
  5138. (while (re-search-forward regexp nil t)
  5139. (catch :skip
  5140. (org-agenda-skip)
  5141. (setq s (match-string 1)
  5142. txt nil
  5143. pos (1- (match-beginning 1))
  5144. todo-state (save-match-data (org-get-todo-state))
  5145. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5146. (member todo-state
  5147. org-agenda-repeating-timestamp-show-all))
  5148. d2 (org-time-string-to-absolute
  5149. (match-string 1) d1 'past show-all
  5150. (current-buffer) pos)
  5151. diff (- d2 d1))
  5152. (setq pastschedp (and todayp (< diff 0)))
  5153. (setq did-habit-check-p nil)
  5154. ;; When to show a scheduled item in the calendar:
  5155. ;; If it is on or past the date.
  5156. (when (or (and (< diff 0)
  5157. (< (abs diff) org-scheduled-past-days)
  5158. (and todayp (not org-agenda-only-exact-dates)))
  5159. (= diff 0)
  5160. ;; org-is-habit-p uses org-entry-get, which is expansive
  5161. ;; so we go extra mile to only call it once
  5162. (and todayp
  5163. org-habit-show-all-today
  5164. (setq did-habit-check-p t)
  5165. (setq habitp (and (functionp 'org-is-habit-p)
  5166. (org-is-habit-p)))))
  5167. (save-excursion
  5168. (setq donep (member todo-state org-done-keywords))
  5169. (if (and donep
  5170. (or org-agenda-skip-scheduled-if-done
  5171. (not (= diff 0))
  5172. (and (functionp 'org-is-habit-p)
  5173. (org-is-habit-p))))
  5174. (setq txt nil)
  5175. (setq habitp (if did-habit-check-p habitp
  5176. (and (functionp 'org-is-habit-p)
  5177. (org-is-habit-p))))
  5178. (setq category (org-get-category)
  5179. org-category-pos (get-text-property (point) 'org-category-position))
  5180. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5181. (setq txt org-agenda-no-heading-message)
  5182. (goto-char (match-end 0))
  5183. (setq pos1 (match-beginning 0))
  5184. (if habitp
  5185. (if (or (not org-habit-show-habits)
  5186. (and (not todayp)
  5187. org-habit-show-habits-only-for-today))
  5188. (throw :skip nil))
  5189. (if (and
  5190. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5191. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5192. pastschedp))
  5193. (setq mm (assoc pos1 deadline-position-alist)))
  5194. (throw :skip nil)))
  5195. (setq tags (org-get-tags-at))
  5196. (setq head (buffer-substring-no-properties
  5197. (point)
  5198. (progn (skip-chars-forward "^\r\n") (point))))
  5199. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5200. (setq timestr
  5201. (concat (substring s (match-beginning 1)) " "))
  5202. (setq timestr 'time))
  5203. (setq txt (org-agenda-format-item
  5204. (if (= diff 0)
  5205. (car org-agenda-scheduled-leaders)
  5206. (format (nth 1 org-agenda-scheduled-leaders)
  5207. (- 1 diff)))
  5208. head category tags
  5209. (if (not (= diff 0)) nil timestr)
  5210. nil habitp))))
  5211. (when txt
  5212. (setq face
  5213. (cond
  5214. ((and (not habitp) pastschedp)
  5215. 'org-scheduled-previously)
  5216. (todayp 'org-scheduled-today)
  5217. (t 'org-scheduled))
  5218. habitp (and habitp (org-habit-parse-todo)))
  5219. (org-add-props txt props
  5220. 'undone-face face
  5221. 'face (if donep 'org-agenda-done face)
  5222. 'org-marker (org-agenda-new-marker pos)
  5223. 'org-hd-marker (org-agenda-new-marker pos1)
  5224. 'type (if pastschedp "past-scheduled" "scheduled")
  5225. 'date (if pastschedp d2 date)
  5226. 'priority (if habitp
  5227. (org-habit-get-priority habitp)
  5228. (+ 94 (- 5 diff) (org-get-priority txt)))
  5229. 'org-category category
  5230. 'org-category-position org-category-pos
  5231. 'org-habit-p habitp
  5232. 'todo-state todo-state)
  5233. (push txt ee))))))
  5234. (nreverse ee)))
  5235. (defun org-agenda-get-blocks ()
  5236. "Return the date-range information for agenda display."
  5237. (let* ((props (list 'face nil
  5238. 'org-not-done-regexp org-not-done-regexp
  5239. 'org-todo-regexp org-todo-regexp
  5240. 'org-complex-heading-regexp org-complex-heading-regexp
  5241. 'mouse-face 'highlight
  5242. 'help-echo
  5243. (format "mouse-2 or RET jump to org file %s"
  5244. (abbreviate-file-name buffer-file-name))))
  5245. (regexp org-tr-regexp)
  5246. (d0 (calendar-absolute-from-gregorian date))
  5247. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5248. todo-state tags pos head donep)
  5249. (goto-char (point-min))
  5250. (while (re-search-forward regexp nil t)
  5251. (catch :skip
  5252. (org-agenda-skip)
  5253. (setq pos (point))
  5254. (let ((start-time (match-string 1))
  5255. (end-time (match-string 2)))
  5256. (setq s1 (match-string 1)
  5257. s2 (match-string 2)
  5258. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5259. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5260. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5261. ;; Only allow days between the limits, because the normal
  5262. ;; date stamps will catch the limits.
  5263. (save-excursion
  5264. (setq todo-state (org-get-todo-state))
  5265. (setq donep (member todo-state org-done-keywords))
  5266. (if (and donep org-agenda-skip-timestamp-if-done)
  5267. (throw :skip t))
  5268. (setq marker (org-agenda-new-marker (point)))
  5269. (setq category (org-get-category)
  5270. org-category-pos (get-text-property (point) 'org-category-position))
  5271. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5272. (setq txt org-agenda-no-heading-message)
  5273. (goto-char (match-beginning 0))
  5274. (setq hdmarker (org-agenda-new-marker (point)))
  5275. (setq tags (org-get-tags-at))
  5276. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5277. (setq head (match-string 1))
  5278. (let ((remove-re
  5279. (if org-agenda-remove-timeranges-from-blocks
  5280. (concat
  5281. "<" (regexp-quote s1) ".*?>"
  5282. "--"
  5283. "<" (regexp-quote s2) ".*?>")
  5284. nil)))
  5285. (setq txt (org-agenda-format-item
  5286. (format
  5287. (nth (if (= d1 d2) 0 1)
  5288. org-agenda-timerange-leaders)
  5289. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5290. head category tags
  5291. (cond ((and (= d1 d0) (= d2 d0))
  5292. (concat "<" start-time ">--<" end-time ">"))
  5293. ((= d1 d0)
  5294. (concat "<" start-time ">"))
  5295. ((= d2 d0)
  5296. (concat "<" end-time ">"))
  5297. (t nil))
  5298. remove-re))))
  5299. (org-add-props txt props
  5300. 'org-marker marker 'org-hd-marker hdmarker
  5301. 'type "block" 'date date
  5302. 'todo-state todo-state
  5303. 'priority (org-get-priority txt) 'org-category category
  5304. 'org-category-position org-category-pos)
  5305. (push txt ee))))
  5306. (goto-char pos)))
  5307. ;; Sort the entries by expiration date.
  5308. (nreverse ee)))
  5309. ;;; Agenda presentation and sorting
  5310. (defvar org-prefix-has-time nil
  5311. "A flag, set by `org-compile-prefix-format'.
  5312. The flag is set if the currently compiled format contains a `%t'.")
  5313. (defvar org-prefix-has-tag nil
  5314. "A flag, set by `org-compile-prefix-format'.
  5315. The flag is set if the currently compiled format contains a `%T'.")
  5316. (defvar org-prefix-has-effort nil
  5317. "A flag, set by `org-compile-prefix-format'.
  5318. The flag is set if the currently compiled format contains a `%e'.")
  5319. (defvar org-prefix-category-length nil
  5320. "Used by `org-compile-prefix-format' to remember the category field width.")
  5321. (defvar org-prefix-category-max-length nil
  5322. "Used by `org-compile-prefix-format' to remember the category field width.")
  5323. (defun org-agenda-get-category-icon (category)
  5324. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5325. (dolist (entry org-agenda-category-icon-alist)
  5326. (when (org-string-match-p (car entry) category)
  5327. (if (listp (cadr entry))
  5328. (return (cadr entry))
  5329. (return (apply 'create-image (cdr entry)))))))
  5330. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5331. remove-re habitp)
  5332. "Format TXT to be inserted into the agenda buffer.
  5333. In particular, it adds the prefix and corresponding text properties. EXTRA
  5334. must be a string and replaces the `%s' specifier in the prefix format.
  5335. CATEGORY (string, symbol or nil) may be used to overrule the default
  5336. category taken from local variable or file name. It will replace the `%c'
  5337. specifier in the format. DOTIME, when non-nil, indicates that a
  5338. time-of-day should be extracted from TXT for sorting of this entry, and for
  5339. the `%t' specifier in the format. When DOTIME is a string, this string is
  5340. searched for a time before TXT is. TAGS can be the tags of the headline.
  5341. Any match of REMOVE-RE will be removed from TXT."
  5342. ;; We keep the org-prefix-* variable values along with a compiled
  5343. ;; formatter, so that multiple agendas existing at the same time, do
  5344. ;; not step on each other toes.
  5345. ;;
  5346. ;; It was inconvenient to make these variables buffer local in
  5347. ;; Agenda buffers, because this function expects to be called with
  5348. ;; the buffer where item comes from being current, and not agenda
  5349. ;; buffer
  5350. (let* ((bindings (car org-prefix-format-compiled))
  5351. (formatter (cadr org-prefix-format-compiled)))
  5352. (loop for (var value) in bindings
  5353. do (set var value))
  5354. (save-match-data
  5355. ;; Diary entries sometimes have extra whitespace at the beginning
  5356. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5357. ;; Fix the tags part in txt
  5358. (setq txt (org-agenda-fix-displayed-tags
  5359. txt tags
  5360. org-agenda-show-inherited-tags
  5361. org-agenda-hide-tags-regexp))
  5362. (let* ((category (or category
  5363. (if (stringp org-category)
  5364. org-category
  5365. (and org-category (symbol-name org-category)))
  5366. (if buffer-file-name
  5367. (file-name-sans-extension
  5368. (file-name-nondirectory buffer-file-name))
  5369. "")))
  5370. (category-icon (org-agenda-get-category-icon category))
  5371. (category-icon (if category-icon
  5372. (propertize " " 'display category-icon)
  5373. ""))
  5374. ;; time, tag, effort are needed for the eval of the prefix format
  5375. (tag (if tags (nth (1- (length tags)) tags) ""))
  5376. time effort neffort
  5377. (ts (if dotime (concat
  5378. (if (stringp dotime) dotime "")
  5379. (and org-agenda-search-headline-for-time txt))))
  5380. (time-of-day (and dotime (org-get-time-of-day ts)))
  5381. stamp plain s0 s1 s2 rtn srp l
  5382. duration thecategory)
  5383. (and (derived-mode-p 'org-mode) buffer-file-name
  5384. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5385. (when (and dotime time-of-day)
  5386. ;; Extract starting and ending time and move them to prefix
  5387. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5388. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5389. (setq s0 (match-string 0 ts)
  5390. srp (and stamp (match-end 3))
  5391. s1 (match-string (if plain 1 2) ts)
  5392. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5393. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5394. ;; them, we might want to remove them there to avoid duplication.
  5395. ;; The user can turn this off with a variable.
  5396. (if (and org-prefix-has-time
  5397. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5398. (string-match (concat (regexp-quote s0) " *") txt)
  5399. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5400. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5401. (= (match-beginning 0) 0)
  5402. t))
  5403. (setq txt (replace-match "" nil nil txt))))
  5404. ;; Normalize the time(s) to 24 hour
  5405. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5406. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5407. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5408. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5409. (setq s2
  5410. (org-minutes-to-hh:mm-string
  5411. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5412. ;; Compute the duration
  5413. (when s2
  5414. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5415. (org-hh:mm-string-to-minutes s1)))))
  5416. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5417. txt)
  5418. ;; Tags are in the string
  5419. (if (or (eq org-agenda-remove-tags t)
  5420. (and org-agenda-remove-tags
  5421. org-prefix-has-tag))
  5422. (setq txt (replace-match "" t t txt))
  5423. (setq txt (replace-match
  5424. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5425. (match-string 2 txt))
  5426. t t txt))))
  5427. (when (derived-mode-p 'org-mode)
  5428. (setq effort
  5429. (condition-case nil
  5430. (org-get-effort
  5431. (or (get-text-property 0 'org-hd-marker txt)
  5432. (get-text-property 0 'org-marker txt)))
  5433. (error nil)))
  5434. (when effort
  5435. (setq neffort (org-duration-string-to-minutes effort)
  5436. effort (setq effort (concat "[" effort "]")))))
  5437. ;; prevent erroring out with %e format when there is no effort
  5438. (or effort (setq effort ""))
  5439. (when remove-re
  5440. (while (string-match remove-re txt)
  5441. (setq txt (replace-match "" t t txt))))
  5442. ;; Set org-heading property on `txt' to mark the start of the
  5443. ;; heading.
  5444. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5445. ;; Prepare the variables needed in the eval of the compiled format
  5446. (setq time (cond (s2 (concat
  5447. (org-agenda-time-of-day-to-ampm-maybe s1)
  5448. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5449. (if org-agenda-timegrid-use-ampm " ")))
  5450. (s1 (concat
  5451. (org-agenda-time-of-day-to-ampm-maybe s1)
  5452. (if org-agenda-timegrid-use-ampm
  5453. "........ "
  5454. "......")))
  5455. (t ""))
  5456. extra (or (and (not habitp) extra) "")
  5457. category (if (symbolp category) (symbol-name category) category)
  5458. thecategory (copy-sequence category))
  5459. (if (string-match org-bracket-link-regexp category)
  5460. (progn
  5461. (setq l (if (match-end 3)
  5462. (- (match-end 3) (match-beginning 3))
  5463. (- (match-end 1) (match-beginning 1))))
  5464. (when (< l (or org-prefix-category-length 0))
  5465. (setq category (copy-sequence category))
  5466. (org-add-props category nil
  5467. 'extra-space (make-string
  5468. (- org-prefix-category-length l 1) ?\ ))))
  5469. (if (and org-prefix-category-max-length
  5470. (>= (length category) org-prefix-category-max-length))
  5471. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5472. ;; Evaluate the compiled format
  5473. (setq rtn (concat (eval formatter) txt))
  5474. ;; And finally add the text properties
  5475. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5476. (org-add-props rtn nil
  5477. 'org-category (if thecategory (downcase thecategory) category)
  5478. 'tags (mapcar 'org-downcase-keep-props tags)
  5479. 'org-highest-priority org-highest-priority
  5480. 'org-lowest-priority org-lowest-priority
  5481. 'time-of-day time-of-day
  5482. 'duration duration
  5483. 'effort effort
  5484. 'effort-minutes neffort
  5485. 'txt txt
  5486. 'time time
  5487. 'extra extra
  5488. 'format org-prefix-format-compiled
  5489. 'dotime dotime)))))
  5490. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5491. "Remove tags string from TXT, and add a modified list of tags.
  5492. The modified list may contain inherited tags, and tags matched by
  5493. `org-agenda-hide-tags-regexp' will be removed."
  5494. (when (or add-inherited hide-re)
  5495. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5496. (setq txt (substring txt 0 (match-beginning 0))))
  5497. (setq tags
  5498. (delq nil
  5499. (mapcar (lambda (tg)
  5500. (if (or (and hide-re (string-match hide-re tg))
  5501. (and (not add-inherited)
  5502. (get-text-property 0 'inherited tg)))
  5503. nil
  5504. tg))
  5505. tags)))
  5506. (when tags
  5507. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5508. i)
  5509. (setq txt (concat txt " :"
  5510. (mapconcat
  5511. (lambda (x)
  5512. (setq i (get-text-property 0 'inherited x))
  5513. (if (and have-i (not i))
  5514. (progn
  5515. (setq have-i nil)
  5516. (concat ":" x))
  5517. x))
  5518. tags ":")
  5519. (if have-i "::" ":"))))))
  5520. txt)
  5521. (defun org-downcase-keep-props (s)
  5522. (let ((props (text-properties-at 0 s)))
  5523. (setq s (downcase s))
  5524. (add-text-properties 0 (length s) props s)
  5525. s))
  5526. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5527. (defvar org-agenda-sorting-strategy-selected nil)
  5528. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5529. (catch 'exit
  5530. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5531. ((and todayp (member 'today (car org-agenda-time-grid))))
  5532. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5533. ((member 'weekly (car org-agenda-time-grid)))
  5534. (t (throw 'exit list)))
  5535. (let* ((have (delq nil (mapcar
  5536. (lambda (x) (get-text-property 1 'time-of-day x))
  5537. list)))
  5538. (string (nth 1 org-agenda-time-grid))
  5539. (gridtimes (nth 2 org-agenda-time-grid))
  5540. (req (car org-agenda-time-grid))
  5541. (remove (member 'remove-match req))
  5542. new time)
  5543. (if (and (member 'require-timed req) (not have))
  5544. ;; don't show empty grid
  5545. (throw 'exit list))
  5546. (while (setq time (pop gridtimes))
  5547. (unless (and remove (member time have))
  5548. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5549. (push (org-agenda-format-item
  5550. nil string "" nil
  5551. (concat (substring time 0 -2) ":" (substring time -2)))
  5552. new)
  5553. (put-text-property
  5554. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5555. (when (and todayp org-agenda-show-current-time-in-grid)
  5556. (push (org-agenda-format-item
  5557. nil
  5558. org-agenda-current-time-string
  5559. "" nil
  5560. (format-time-string "%H:%M "))
  5561. new)
  5562. (put-text-property
  5563. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5564. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5565. (append new list)
  5566. (append list new)))))
  5567. (defun org-compile-prefix-format (key)
  5568. "Compile the prefix format into a Lisp form that can be evaluated.
  5569. The resulting form and associated variable bindings is returned
  5570. and stored in the variable `org-prefix-format-compiled'."
  5571. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5572. org-prefix-category-length nil
  5573. org-prefix-has-effort nil)
  5574. (let ((s (cond
  5575. ((stringp org-agenda-prefix-format)
  5576. org-agenda-prefix-format)
  5577. ((assq key org-agenda-prefix-format)
  5578. (cdr (assq key org-agenda-prefix-format)))
  5579. (t " %-12:c%?-12t% s")))
  5580. (start 0)
  5581. varform vars var e c f opt)
  5582. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5583. s start)
  5584. (setq var (or (cdr (assoc (match-string 4 s)
  5585. '(("c" . category) ("t" . time) ("s" . extra)
  5586. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5587. 'eval)
  5588. c (or (match-string 3 s) "")
  5589. opt (match-beginning 1)
  5590. start (1+ (match-beginning 0)))
  5591. (if (equal var 'time) (setq org-prefix-has-time t))
  5592. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5593. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5594. (setq f (concat "%" (match-string 2 s) "s"))
  5595. (when (equal var 'category)
  5596. (setq org-prefix-category-length
  5597. (floor (abs (string-to-number (match-string 2 s)))))
  5598. (setq org-prefix-category-max-length
  5599. (let ((x (match-string 2 s)))
  5600. (save-match-data
  5601. (if (string-match "\\.[0-9]+" x)
  5602. (string-to-number (substring (match-string 0 x) 1)))))))
  5603. (if (eq var 'eval)
  5604. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5605. (if opt
  5606. (setq varform
  5607. `(if (equal "" ,var)
  5608. ""
  5609. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5610. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5611. (setq s (replace-match "%s" t nil s))
  5612. (push varform vars))
  5613. (setq vars (nreverse vars))
  5614. (with-current-buffer org-agenda-buffer
  5615. (setq org-prefix-format-compiled
  5616. (list
  5617. `((org-prefix-has-time ,org-prefix-has-time)
  5618. (org-prefix-has-tag ,org-prefix-has-tag)
  5619. (org-prefix-category-length ,org-prefix-category-length)
  5620. (org-prefix-has-effort ,org-prefix-has-effort))
  5621. `(format ,s ,@vars))))))
  5622. (defun org-set-sorting-strategy (key)
  5623. (if (symbolp (car org-agenda-sorting-strategy))
  5624. ;; the old format
  5625. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5626. (setq org-agenda-sorting-strategy-selected
  5627. (or (cdr (assq key org-agenda-sorting-strategy))
  5628. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5629. '(time-up category-keep priority-down)))))
  5630. (defun org-get-time-of-day (s &optional string mod24)
  5631. "Check string S for a time of day.
  5632. If found, return it as a military time number between 0 and 2400.
  5633. If not found, return nil.
  5634. The optional STRING argument forces conversion into a 5 character wide string
  5635. HH:MM."
  5636. (save-match-data
  5637. (when
  5638. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5639. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5640. (let* ((h (string-to-number (match-string 1 s)))
  5641. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5642. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5643. (am-p (equal ampm "am"))
  5644. (h1 (cond ((not ampm) h)
  5645. ((= h 12) (if am-p 0 12))
  5646. (t (+ h (if am-p 0 12)))))
  5647. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5648. (mod h1 24) h1))
  5649. (t0 (+ (* 100 h2) m))
  5650. (t1 (concat (if (>= h1 24) "+" " ")
  5651. (if (and org-agenda-time-leading-zero
  5652. (< t0 1000)) "0" "")
  5653. (if (< t0 100) "0" "")
  5654. (if (< t0 10) "0" "")
  5655. (int-to-string t0))))
  5656. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5657. (defvar org-agenda-before-sorting-filter-function nil
  5658. "Function to be applied to agenda items prior to sorting.
  5659. Prior to sorting also means just before they are inserted into the agenda.
  5660. To aid sorting, you may revisit the original entries and add more text
  5661. properties which will later be used by the sorting functions.
  5662. The function should take a string argument, an agenda line.
  5663. It has access to the text properties in that line, which contain among
  5664. other things, the property `org-hd-marker' that points to the entry
  5665. where the line comes from. Note that not all lines going into the agenda
  5666. have this property, only most.
  5667. The function should return the modified string. It is probably best
  5668. to ONLY change text properties.
  5669. You can also use this function as a filter, by returning nil for lines
  5670. you don't want to have in the agenda at all. For this application, you
  5671. could bind the variable in the options section of a custom command.")
  5672. (defun org-finalize-agenda-entries (list &optional nosort)
  5673. "Sort and concatenate the agenda items."
  5674. (setq list (mapcar 'org-agenda-highlight-todo list))
  5675. (if nosort
  5676. list
  5677. (when org-agenda-before-sorting-filter-function
  5678. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5679. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5680. (defun org-agenda-highlight-todo (x)
  5681. (let ((org-done-keywords org-done-keywords-for-agenda)
  5682. (case-fold-search nil)
  5683. re)
  5684. (if (eq x 'line)
  5685. (save-excursion
  5686. (beginning-of-line 1)
  5687. (setq re (org-get-at-bol 'org-todo-regexp))
  5688. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5689. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5690. (add-text-properties (match-beginning 0) (match-end 1)
  5691. (list 'face (org-get-todo-face 1)))
  5692. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5693. (delete-region (match-beginning 1) (1- (match-end 0)))
  5694. (goto-char (match-beginning 1))
  5695. (insert (format org-agenda-todo-keyword-format s)))))
  5696. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5697. (setq re (get-text-property 0 'org-todo-regexp x))
  5698. (when (and re
  5699. ;; Test `pl' because if there's no heading content,
  5700. ;; there's no point matching to highlight. Note
  5701. ;; that if we didn't test `pl' first, and there
  5702. ;; happened to be no keyword from `org-todo-regexp'
  5703. ;; on this heading line, then the `equal' comparison
  5704. ;; afterwards would spuriously succeed in the case
  5705. ;; where `pl' is nil -- causing an args-out-of-range
  5706. ;; error when we try to add text properties to text
  5707. ;; that isn't there.
  5708. pl
  5709. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5710. x pl) pl))
  5711. (add-text-properties
  5712. (or (match-end 1) (match-end 0)) (match-end 0)
  5713. (list 'face (org-get-todo-face (match-string 2 x)))
  5714. x)
  5715. (when (match-end 1)
  5716. (setq x (concat (substring x 0 (match-end 1))
  5717. (format org-agenda-todo-keyword-format
  5718. (match-string 2 x))
  5719. (org-add-props " " (text-properties-at 0 x))
  5720. (substring x (match-end 3)))))))
  5721. x)))
  5722. (defsubst org-cmp-priority (a b)
  5723. "Compare the priorities of string A and B."
  5724. (let ((pa (or (get-text-property 1 'priority a) 0))
  5725. (pb (or (get-text-property 1 'priority b) 0)))
  5726. (cond ((> pa pb) +1)
  5727. ((< pa pb) -1)
  5728. (t nil))))
  5729. (defsubst org-cmp-effort (a b)
  5730. "Compare the effort values of string A and B."
  5731. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5732. (ea (or (get-text-property 1 'effort-minutes a) def))
  5733. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5734. (cond ((> ea eb) +1)
  5735. ((< ea eb) -1)
  5736. (t nil))))
  5737. (defsubst org-cmp-category (a b)
  5738. "Compare the string values of categories of strings A and B."
  5739. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5740. (cb (or (get-text-property 1 'org-category b) "")))
  5741. (cond ((string-lessp ca cb) -1)
  5742. ((string-lessp cb ca) +1)
  5743. (t nil))))
  5744. (defsubst org-cmp-todo-state (a b)
  5745. "Compare the todo states of strings A and B."
  5746. (let* ((ma (or (get-text-property 1 'org-marker a)
  5747. (get-text-property 1 'org-hd-marker a)))
  5748. (mb (or (get-text-property 1 'org-marker b)
  5749. (get-text-property 1 'org-hd-marker b)))
  5750. (fa (and ma (marker-buffer ma)))
  5751. (fb (and mb (marker-buffer mb)))
  5752. (todo-kwds
  5753. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5754. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5755. (ta (or (get-text-property 1 'todo-state a) ""))
  5756. (tb (or (get-text-property 1 'todo-state b) ""))
  5757. (la (- (length (member ta todo-kwds))))
  5758. (lb (- (length (member tb todo-kwds))))
  5759. (donepa (member ta org-done-keywords-for-agenda))
  5760. (donepb (member tb org-done-keywords-for-agenda)))
  5761. (cond ((and donepa (not donepb)) -1)
  5762. ((and (not donepa) donepb) +1)
  5763. ((< la lb) -1)
  5764. ((< lb la) +1)
  5765. (t nil))))
  5766. (defsubst org-cmp-alpha (a b)
  5767. "Compare the headlines, alphabetically."
  5768. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5769. (plb (text-property-any 0 (length b) 'org-heading t b))
  5770. (ta (and pla (substring a pla)))
  5771. (tb (and plb (substring b plb))))
  5772. (when pla
  5773. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5774. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5775. (setq ta (substring ta (match-end 0))))
  5776. (setq ta (downcase ta)))
  5777. (when plb
  5778. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5779. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5780. (setq tb (substring tb (match-end 0))))
  5781. (setq tb (downcase tb)))
  5782. (cond ((not ta) +1)
  5783. ((not tb) -1)
  5784. ((string-lessp ta tb) -1)
  5785. ((string-lessp tb ta) +1)
  5786. (t nil))))
  5787. (defsubst org-cmp-tag (a b)
  5788. "Compare the string values of the first tags of A and B."
  5789. (let ((ta (car (last (get-text-property 1 'tags a))))
  5790. (tb (car (last (get-text-property 1 'tags b)))))
  5791. (cond ((not ta) +1)
  5792. ((not tb) -1)
  5793. ((string-lessp ta tb) -1)
  5794. ((string-lessp tb ta) +1)
  5795. (t nil))))
  5796. (defsubst org-cmp-time (a b)
  5797. "Compare the time-of-day values of strings A and B."
  5798. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5799. (ta (or (get-text-property 1 'time-of-day a) def))
  5800. (tb (or (get-text-property 1 'time-of-day b) def)))
  5801. (cond ((< ta tb) -1)
  5802. ((< tb ta) +1)
  5803. (t nil))))
  5804. (defsubst org-cmp-habit-p (a b)
  5805. "Compare the todo states of strings A and B."
  5806. (let ((ha (get-text-property 1 'org-habit-p a))
  5807. (hb (get-text-property 1 'org-habit-p b)))
  5808. (cond ((and ha (not hb)) -1)
  5809. ((and (not ha) hb) +1)
  5810. (t nil))))
  5811. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5812. (defun org-entries-lessp (a b)
  5813. "Predicate for sorting agenda entries."
  5814. ;; The following variables will be used when the form is evaluated.
  5815. ;; So even though the compiler complains, keep them.
  5816. (let* ((ss org-agenda-sorting-strategy-selected)
  5817. (time-up (and (org-em 'time-up 'time-down ss)
  5818. (org-cmp-time a b)))
  5819. (time-down (if time-up (- time-up) nil))
  5820. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5821. (org-cmp-priority a b)))
  5822. (priority-down (if priority-up (- priority-up) nil))
  5823. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5824. (org-cmp-effort a b)))
  5825. (effort-down (if effort-up (- effort-up) nil))
  5826. (category-up (and (or (org-em 'category-up 'category-down ss)
  5827. (memq 'category-keep ss))
  5828. (org-cmp-category a b)))
  5829. (category-down (if category-up (- category-up) nil))
  5830. (category-keep (if category-up +1 nil))
  5831. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5832. (org-cmp-tag a b)))
  5833. (tag-down (if tag-up (- tag-up) nil))
  5834. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5835. (org-cmp-todo-state a b)))
  5836. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5837. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5838. (org-cmp-habit-p a b)))
  5839. (habit-down (if habit-up (- habit-up) nil))
  5840. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5841. (org-cmp-alpha a b)))
  5842. (alpha-down (if alpha-up (- alpha-up) nil))
  5843. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5844. user-defined-up user-defined-down)
  5845. (if (and need-user-cmp org-agenda-cmp-user-defined
  5846. (functionp org-agenda-cmp-user-defined))
  5847. (setq user-defined-up
  5848. (funcall org-agenda-cmp-user-defined a b)
  5849. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5850. (cdr (assoc
  5851. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5852. '((-1 . t) (1 . nil) (nil . nil))))))
  5853. ;;; Agenda restriction lock
  5854. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5855. "Overlay to mark the headline to which agenda commands are restricted.")
  5856. (overlay-put org-agenda-restriction-lock-overlay
  5857. 'face 'org-agenda-restriction-lock)
  5858. (overlay-put org-agenda-restriction-lock-overlay
  5859. 'help-echo "Agendas are currently limited to this subtree.")
  5860. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5861. (defun org-agenda-set-restriction-lock (&optional type)
  5862. "Set restriction lock for agenda, to current subtree or file.
  5863. Restriction will be the file if TYPE is `file', or if type is the
  5864. universal prefix '(4), or if the cursor is before the first headline
  5865. in the file. Otherwise, restriction will be to the current subtree."
  5866. (interactive "P")
  5867. (and (equal type '(4)) (setq type 'file))
  5868. (setq type (cond
  5869. (type type)
  5870. ((org-at-heading-p) 'subtree)
  5871. ((condition-case nil (org-back-to-heading t) (error nil))
  5872. 'subtree)
  5873. (t 'file)))
  5874. (if (eq type 'subtree)
  5875. (progn
  5876. (setq org-agenda-restrict t)
  5877. (setq org-agenda-overriding-restriction 'subtree)
  5878. (put 'org-agenda-files 'org-restrict
  5879. (list (buffer-file-name (buffer-base-buffer))))
  5880. (org-back-to-heading t)
  5881. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5882. (move-marker org-agenda-restrict-begin (point))
  5883. (move-marker org-agenda-restrict-end
  5884. (save-excursion (org-end-of-subtree t)))
  5885. (message "Locking agenda restriction to subtree"))
  5886. (put 'org-agenda-files 'org-restrict
  5887. (list (buffer-file-name (buffer-base-buffer))))
  5888. (setq org-agenda-restrict nil)
  5889. (setq org-agenda-overriding-restriction 'file)
  5890. (move-marker org-agenda-restrict-begin nil)
  5891. (move-marker org-agenda-restrict-end nil)
  5892. (message "Locking agenda restriction to file"))
  5893. (setq current-prefix-arg nil)
  5894. (org-agenda-maybe-redo))
  5895. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5896. "Remove the agenda restriction lock."
  5897. (interactive "P")
  5898. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5899. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5900. (setq org-agenda-overriding-restriction nil)
  5901. (setq org-agenda-restrict nil)
  5902. (put 'org-agenda-files 'org-restrict nil)
  5903. (move-marker org-agenda-restrict-begin nil)
  5904. (move-marker org-agenda-restrict-end nil)
  5905. (setq current-prefix-arg nil)
  5906. (message "Agenda restriction lock removed")
  5907. (or noupdate (org-agenda-maybe-redo)))
  5908. (defun org-agenda-maybe-redo ()
  5909. "If there is any window showing the agenda view, update it."
  5910. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5911. (w0 (selected-window)))
  5912. (when w
  5913. (select-window w)
  5914. (org-agenda-redo)
  5915. (select-window w0)
  5916. (if org-agenda-overriding-restriction
  5917. (message "Agenda view shifted to new %s restriction"
  5918. org-agenda-overriding-restriction)
  5919. (message "Agenda restriction lock removed")))))
  5920. ;;; Agenda commands
  5921. (defun org-agenda-check-type (error &rest types)
  5922. "Check if agenda buffer is of allowed type.
  5923. If ERROR is non-nil, throw an error, otherwise just return nil."
  5924. (if (memq org-agenda-type types)
  5925. t
  5926. (if error
  5927. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5928. nil)))
  5929. (defun org-agenda-Quit (&optional arg)
  5930. "Exit agenda by removing the window or the buffer"
  5931. (interactive)
  5932. (if org-agenda-columns-active
  5933. (org-columns-quit)
  5934. (let ((buf (current-buffer)))
  5935. (if (eq org-agenda-window-setup 'other-frame)
  5936. (progn
  5937. (org-agenda-reset-markers)
  5938. (kill-buffer buf)
  5939. (org-columns-remove-overlays)
  5940. (setq org-agenda-archives-mode nil)
  5941. (delete-frame))
  5942. (and (not (eq org-agenda-window-setup 'current-window))
  5943. (not (one-window-p))
  5944. (delete-window))
  5945. (org-agenda-reset-markers)
  5946. (kill-buffer buf)
  5947. (org-columns-remove-overlays)
  5948. (setq org-agenda-archives-mode nil)))
  5949. ;; Maybe restore the pre-agenda window configuration.
  5950. (and org-agenda-restore-windows-after-quit
  5951. (not (eq org-agenda-window-setup 'other-frame))
  5952. org-pre-agenda-window-conf
  5953. (set-window-configuration org-pre-agenda-window-conf))))
  5954. (defun org-agenda-quit ()
  5955. "Exit agenda by killing agenda buffer or burying it when
  5956. `org-agenda-sticky' is non-NIL"
  5957. (interactive)
  5958. (if org-agenda-columns-active
  5959. (org-columns-quit)
  5960. (if org-agenda-sticky
  5961. (let ((buf (current-buffer)))
  5962. (if (eq org-agenda-window-setup 'other-frame)
  5963. (progn
  5964. (delete-frame))
  5965. (and (not (eq org-agenda-window-setup 'current-window))
  5966. (not (one-window-p))
  5967. (delete-window)))
  5968. (with-current-buffer buf
  5969. (bury-buffer)
  5970. ;; Maybe restore the pre-agenda window configuration.
  5971. (and org-agenda-restore-windows-after-quit
  5972. (not (eq org-agenda-window-setup 'other-frame))
  5973. org-pre-agenda-window-conf
  5974. (set-window-configuration org-pre-agenda-window-conf))))
  5975. (org-agenda-Quit))))
  5976. (defun org-agenda-exit ()
  5977. "Exit agenda by removing the window or the buffer.
  5978. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5979. Org-mode buffers visited directly by the user will not be touched."
  5980. (interactive)
  5981. (org-release-buffers org-agenda-new-buffers)
  5982. (setq org-agenda-new-buffers nil)
  5983. (org-agenda-Quit))
  5984. (defun org-agenda-kill-all-agenda-buffers ()
  5985. "Kill all buffers in `org-agena-mode'.
  5986. This is used when toggling sticky agendas. You can also explicitly invoke it
  5987. with `C-c a C-k'."
  5988. (interactive)
  5989. (let (blist)
  5990. (dolist (buf (buffer-list))
  5991. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  5992. (push buf blist)))
  5993. (mapc 'kill-buffer blist)))
  5994. (defun org-agenda-execute (arg)
  5995. "Execute another agenda command, keeping same window.
  5996. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5997. in the agenda."
  5998. (interactive "P")
  5999. (let ((org-agenda-window-setup 'current-window))
  6000. (org-agenda arg)))
  6001. (defun org-agenda-redo ()
  6002. "Rebuild Agenda.
  6003. When this is the global TODO list, a prefix argument will be interpreted."
  6004. (interactive)
  6005. (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
  6006. (org-agenda-sticky nil)
  6007. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6008. org-agenda-buffer-name))
  6009. (org-agenda-keep-modes t)
  6010. (tag-filter org-agenda-tag-filter)
  6011. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6012. (top-cat-filter org-agenda-top-category-filter)
  6013. (cat-filter org-agenda-category-filter)
  6014. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6015. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6016. (cols org-agenda-columns-active)
  6017. (line (org-current-line))
  6018. (window-line (- line (org-current-line (window-start))))
  6019. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  6020. (put 'org-agenda-tag-filter :preset-filter nil)
  6021. (put 'org-agenda-category-filter :preset-filter nil)
  6022. (and cols (org-columns-quit))
  6023. (message "Rebuilding agenda buffer...")
  6024. (org-let lprops '(eval org-agenda-redo-command))
  6025. (setq org-agenda-undo-list nil
  6026. org-agenda-pending-undo-list nil)
  6027. (message "Rebuilding agenda buffer...done")
  6028. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6029. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6030. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6031. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6032. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6033. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6034. (org-goto-line line)
  6035. (recenter window-line)))
  6036. (defvar org-global-tags-completion-table nil)
  6037. (defvar org-agenda-filter-form nil)
  6038. (defvar org-agenda-filtered-by-category nil)
  6039. (defun org-agenda-filter-by-category (strip)
  6040. "Keep only those lines in the agenda buffer that have a specific category.
  6041. The category is that of the current line."
  6042. (interactive "P")
  6043. (if org-agenda-filtered-by-category
  6044. (org-agenda-filter-show-all-cat)
  6045. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6046. (if cat (org-agenda-filter-apply
  6047. (list (concat (if strip "-" "+") cat)) 'category)
  6048. (error "No category at point")))))
  6049. (defun org-find-top-category (&optional pos)
  6050. (save-excursion
  6051. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6052. (if pos (goto-char pos))
  6053. ;; Skip up to the topmost parent
  6054. (while (ignore-errors (outline-up-heading 1) t))
  6055. (ignore-errors
  6056. (nth 4 (org-heading-components))))))
  6057. (defvar org-agenda-filtered-by-top-category nil)
  6058. (defun org-agenda-filter-by-top-category (strip)
  6059. "Keep only those lines in the agenda buffer that have a specific category.
  6060. The category is that of the current line."
  6061. (interactive "P")
  6062. (if org-agenda-filtered-by-top-category
  6063. (progn
  6064. (setq org-agenda-filtered-by-top-category nil
  6065. org-agenda-top-category-filter nil)
  6066. (org-agenda-filter-show-all-cat))
  6067. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6068. (if cat (org-agenda-filter-top-category-apply cat strip)
  6069. (error "No top-level category at point")))))
  6070. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6071. "Keep only those lines in the agenda buffer that have a specific tag.
  6072. The tag is selected with its fast selection letter, as configured.
  6073. With prefix argument STRIP, remove all lines that do have the tag.
  6074. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6075. used to narrow the search - the interactive user can also press `-' or `+'
  6076. to switch to narrowing."
  6077. (interactive "P")
  6078. (let* ((alist org-tag-alist-for-agenda)
  6079. (tag-chars (mapconcat
  6080. (lambda (x) (if (and (not (symbolp (car x)))
  6081. (cdr x))
  6082. (char-to-string (cdr x))
  6083. ""))
  6084. alist ""))
  6085. (efforts (org-split-string
  6086. (or (cdr (assoc (concat org-effort-property "_ALL")
  6087. org-global-properties))
  6088. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6089. "")))
  6090. (effort-op org-agenda-filter-effort-default-operator)
  6091. (effort-prompt "")
  6092. (inhibit-read-only t)
  6093. (current org-agenda-tag-filter)
  6094. maybe-refresh a n tag)
  6095. (unless char
  6096. (message
  6097. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6098. (if narrow "Narrow" "Filter") tag-chars
  6099. (if org-agenda-auto-exclude-function "[RET], " ""))
  6100. (setq char (read-char-exclusive)))
  6101. (when (member char '(?+ ?-))
  6102. ;; Narrowing down
  6103. (cond ((equal char ?-) (setq strip t narrow t))
  6104. ((equal char ?+) (setq strip nil narrow t)))
  6105. (message
  6106. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6107. (setq char (read-char-exclusive)))
  6108. (when (member char '(?< ?> ?= ??))
  6109. ;; An effort operator
  6110. (setq effort-op (char-to-string char))
  6111. (setq alist nil) ; to make sure it will be interpreted as effort.
  6112. (unless (equal char ??)
  6113. (loop for i from 0 to 9 do
  6114. (setq effort-prompt
  6115. (concat
  6116. effort-prompt " ["
  6117. (if (= i 9) "0" (int-to-string (1+ i)))
  6118. "]" (nth i efforts))))
  6119. (message "Effort%s: %s " effort-op effort-prompt)
  6120. (setq char (read-char-exclusive))
  6121. (when (or (< char ?0) (> char ?9))
  6122. (error "Need 1-9,0 to select effort"))))
  6123. (when (equal char ?\t)
  6124. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6125. (org-set-local 'org-global-tags-completion-table
  6126. (org-global-tags-completion-table)))
  6127. (let ((completion-ignore-case t))
  6128. (setq tag (org-icompleting-read
  6129. "Tag: " org-global-tags-completion-table))))
  6130. (cond
  6131. ((equal char ?\r)
  6132. (org-agenda-filter-show-all-tag)
  6133. (when org-agenda-auto-exclude-function
  6134. (setq org-agenda-tag-filter '())
  6135. (dolist (tag (org-agenda-get-represented-tags))
  6136. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6137. (if modifier
  6138. (push modifier org-agenda-tag-filter))))
  6139. (if (not (null org-agenda-tag-filter))
  6140. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6141. (setq maybe-refresh t))
  6142. ((equal char ?/)
  6143. (org-agenda-filter-show-all-tag)
  6144. (when (get 'org-agenda-tag-filter :preset-filter)
  6145. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6146. (setq maybe-refresh t))
  6147. ((equal char ?. )
  6148. (setq org-agenda-tag-filter
  6149. (mapcar (lambda(tag) (concat "+" tag))
  6150. (org-get-at-bol 'tags)))
  6151. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6152. (setq maybe-refresh t))
  6153. ((or (equal char ?\ )
  6154. (setq a (rassoc char alist))
  6155. (and (>= char ?0) (<= char ?9)
  6156. (setq n (if (= char ?0) 9 (- char ?0 1))
  6157. tag (concat effort-op (nth n efforts))
  6158. a (cons tag nil)))
  6159. (and (= char ??)
  6160. (setq tag "?eff")
  6161. a (cons tag nil))
  6162. (and tag (setq a (cons tag nil))))
  6163. (org-agenda-filter-show-all-tag)
  6164. (setq tag (car a))
  6165. (setq org-agenda-tag-filter
  6166. (cons (concat (if strip "-" "+") tag)
  6167. (if narrow current nil)))
  6168. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6169. (setq maybe-refresh t))
  6170. (t (error "Invalid tag selection character %c" char)))
  6171. (when (and maybe-refresh
  6172. (eq org-agenda-clockreport-mode 'with-filter))
  6173. (org-agenda-redo))))
  6174. (defun org-agenda-get-represented-tags ()
  6175. "Get a list of all tags currently represented in the agenda."
  6176. (let (p tags)
  6177. (save-excursion
  6178. (goto-char (point-min))
  6179. (while (setq p (next-single-property-change (point) 'tags))
  6180. (goto-char p)
  6181. (mapc (lambda (x) (add-to-list 'tags x))
  6182. (get-text-property (point) 'tags))))
  6183. tags))
  6184. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6185. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6186. (interactive "P")
  6187. (org-agenda-filter-by-tag strip char 'refine))
  6188. (defun org-agenda-filter-make-matcher ()
  6189. "Create the form that tests a line for agenda filter."
  6190. (let (f f1)
  6191. ;; first compute the tag-filter matcher
  6192. (dolist (x (delete-dups
  6193. (append (get 'org-agenda-tag-filter
  6194. :preset-filter) org-agenda-tag-filter)))
  6195. (if (member x '("-" "+"))
  6196. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6197. (if (string-match "[<=>?]" x)
  6198. (setq f1 (org-agenda-filter-effort-form x))
  6199. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6200. (if (equal (string-to-char x) ?-)
  6201. (setq f1 (list 'not f1))))
  6202. (push f1 f))
  6203. ;; then compute the category-filter matcher
  6204. (dolist (x (delete-dups
  6205. (append (get 'org-agenda-category-filter
  6206. :preset-filter) org-agenda-category-filter)))
  6207. (if (equal "-" (substring x 0 1))
  6208. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6209. (setq f1 (list 'equal (substring x 1) 'cat)))
  6210. (push f1 f))
  6211. (cons 'and (nreverse f))))
  6212. (defun org-agenda-filter-effort-form (e)
  6213. "Return the form to compare the effort of the current line with what E says.
  6214. E looks like \"+<2:25\"."
  6215. (let (op)
  6216. (setq e (substring e 1))
  6217. (setq op (string-to-char e) e (substring e 1))
  6218. (setq op (cond ((equal op ?<) '<=)
  6219. ((equal op ?>) '>=)
  6220. ((equal op ??) op)
  6221. (t '=)))
  6222. (list 'org-agenda-compare-effort (list 'quote op)
  6223. (org-duration-string-to-minutes e))))
  6224. (defun org-agenda-compare-effort (op value)
  6225. "Compare the effort of the current line with VALUE, using OP.
  6226. If the line does not have an effort defined, return nil."
  6227. (let ((eff (org-get-at-bol 'effort-minutes)))
  6228. (if (equal op ??)
  6229. (not eff)
  6230. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6231. value))))
  6232. (defun org-agenda-filter-apply (filter type)
  6233. "Set FILTER as the new agenda filter and apply it."
  6234. (let (tags cat)
  6235. (if (eq type 'tag)
  6236. (setq org-agenda-tag-filter filter)
  6237. (setq org-agenda-category-filter filter))
  6238. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6239. (if (and (eq type 'category)
  6240. (not (equal (substring (car filter) 0 1) "-")))
  6241. ;; Only set `org-agenda-filtered-by-category' to t
  6242. ;; when a unique category is used as the filter
  6243. (setq org-agenda-filtered-by-category t))
  6244. (org-agenda-set-mode-name)
  6245. (save-excursion
  6246. (goto-char (point-min))
  6247. (while (not (eobp))
  6248. (if (org-get-at-bol 'org-marker)
  6249. (progn
  6250. (setq tags (org-get-at-bol 'tags) ; used in eval
  6251. cat (get-text-property (point) 'org-category))
  6252. (if (not (eval org-agenda-filter-form))
  6253. (org-agenda-filter-hide-line type))
  6254. (beginning-of-line 2))
  6255. (beginning-of-line 2))))
  6256. (if (get-char-property (point) 'invisible)
  6257. (ignore-errors (org-agenda-previous-line)))))
  6258. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6259. "Set FILTER as the new agenda filter and apply it."
  6260. (org-agenda-set-mode-name)
  6261. (save-excursion
  6262. (goto-char (point-min))
  6263. (while (not (eobp))
  6264. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6265. (topcat (and pos (org-find-top-category pos))))
  6266. (if (and topcat (funcall (if negative 'identity 'not)
  6267. (string= category topcat)))
  6268. (org-agenda-filter-hide-line 'category)))
  6269. (beginning-of-line 2)))
  6270. (if (get-char-property (point) 'invisible)
  6271. (org-agenda-previous-line))
  6272. (setq org-agenda-top-category-filter category
  6273. org-agenda-filtered-by-top-category t))
  6274. (defun org-agenda-filter-hide-line (type)
  6275. (let (ov)
  6276. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6277. (point-at-eol)))
  6278. (overlay-put ov 'invisible t)
  6279. (overlay-put ov 'type type)
  6280. (if (eq type 'tag)
  6281. (push ov org-agenda-tag-filter-overlays)
  6282. (push ov org-agenda-cat-filter-overlays))))
  6283. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6284. (setq pos (or pos (point)))
  6285. (save-excursion
  6286. (dolist (ov (overlays-at pos))
  6287. (when (and (overlay-get ov 'invisible)
  6288. (eq (overlay-get ov 'type) 'tag))
  6289. (goto-char pos)
  6290. (if (< (overlay-start ov) (point-at-eol))
  6291. (move-overlay ov (point-at-eol)
  6292. (overlay-end ov)))))))
  6293. (defun org-agenda-filter-show-all-tag nil
  6294. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6295. (setq org-agenda-tag-filter-overlays nil
  6296. org-agenda-tag-filter nil
  6297. org-agenda-filter-form nil)
  6298. (org-agenda-set-mode-name))
  6299. (defun org-agenda-filter-show-all-cat nil
  6300. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6301. (setq org-agenda-cat-filter-overlays nil
  6302. org-agenda-filtered-by-category nil
  6303. org-agenda-category-filter nil
  6304. org-agenda-filter-form nil)
  6305. (org-agenda-set-mode-name))
  6306. (defun org-agenda-manipulate-query-add ()
  6307. "Manipulate the query by adding a search term with positive selection.
  6308. Positive selection means the term must be matched for selection of an entry."
  6309. (interactive)
  6310. (org-agenda-manipulate-query ?\[))
  6311. (defun org-agenda-manipulate-query-subtract ()
  6312. "Manipulate the query by adding a search term with negative selection.
  6313. Negative selection means term must not be matched for selection of an entry."
  6314. (interactive)
  6315. (org-agenda-manipulate-query ?\]))
  6316. (defun org-agenda-manipulate-query-add-re ()
  6317. "Manipulate the query by adding a search regexp with positive selection.
  6318. Positive selection means the regexp must match for selection of an entry."
  6319. (interactive)
  6320. (org-agenda-manipulate-query ?\{))
  6321. (defun org-agenda-manipulate-query-subtract-re ()
  6322. "Manipulate the query by adding a search regexp with negative selection.
  6323. Negative selection means regexp must not match for selection of an entry."
  6324. (interactive)
  6325. (org-agenda-manipulate-query ?\}))
  6326. (defun org-agenda-manipulate-query (char)
  6327. (cond
  6328. ((memq org-agenda-type '(timeline agenda))
  6329. (let ((org-agenda-include-inactive-timestamps t))
  6330. (org-agenda-redo))
  6331. (message "Display now includes inactive timestamps as well"))
  6332. ((eq org-agenda-type 'search)
  6333. (org-add-to-string
  6334. 'org-agenda-query-string
  6335. (if org-agenda-last-search-view-search-was-boolean
  6336. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6337. (?\{ . " +{}") (?\} . " -{}"))))
  6338. " "))
  6339. (setq org-agenda-redo-command
  6340. (list 'org-search-view
  6341. org-todo-only
  6342. org-agenda-query-string
  6343. (+ (length org-agenda-query-string)
  6344. (if (member char '(?\{ ?\})) 0 1))))
  6345. (set-register org-agenda-query-register org-agenda-query-string)
  6346. (org-agenda-redo))
  6347. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6348. org-agenda-type))))
  6349. (defun org-add-to-string (var string)
  6350. (set var (concat (symbol-value var) string)))
  6351. (defun org-agenda-goto-date (date)
  6352. "Jump to DATE in agenda."
  6353. (interactive (list (let ((org-read-date-prefer-future
  6354. (eval org-agenda-jump-prefer-future)))
  6355. (org-read-date))))
  6356. (org-agenda-list nil date))
  6357. (defun org-agenda-goto-today ()
  6358. "Go to today."
  6359. (interactive)
  6360. (org-agenda-check-type t 'timeline 'agenda)
  6361. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6362. (cond
  6363. (tdpos (goto-char tdpos))
  6364. ((eq org-agenda-type 'agenda)
  6365. (let* ((sd (org-agenda-compute-starting-span
  6366. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6367. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6368. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6369. (org-agenda-redo)
  6370. (org-agenda-find-same-or-today-or-agenda)))
  6371. (t (error "Cannot find today")))))
  6372. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6373. (goto-char
  6374. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6375. (text-property-any (point-min) (point-max) 'org-today t)
  6376. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6377. (point-min))))
  6378. (defun org-agenda-later (arg)
  6379. "Go forward in time by thee current span.
  6380. With prefix ARG, go forward that many times the current span."
  6381. (interactive "p")
  6382. (org-agenda-check-type t 'agenda)
  6383. (let* ((span org-agenda-current-span)
  6384. (sd org-starting-day)
  6385. (greg (calendar-gregorian-from-absolute sd))
  6386. (cnt (org-get-at-bol 'org-day-cnt))
  6387. greg2)
  6388. (cond
  6389. ((eq span 'day)
  6390. (setq sd (+ arg sd)))
  6391. ((eq span 'week)
  6392. (setq sd (+ (* 7 arg) sd)))
  6393. ((eq span 'month)
  6394. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6395. sd (calendar-absolute-from-gregorian greg2))
  6396. (setcar greg2 (1+ (car greg2))))
  6397. ((eq span 'year)
  6398. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6399. sd (calendar-absolute-from-gregorian greg2))
  6400. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6401. (t
  6402. (setq sd (+ (* span arg) sd))))
  6403. (let ((org-agenda-overriding-arguments
  6404. (list (car org-agenda-last-arguments) sd span t)))
  6405. (org-agenda-redo)
  6406. (org-agenda-find-same-or-today-or-agenda cnt))))
  6407. (defun org-agenda-earlier (arg)
  6408. "Go backward in time by the current span.
  6409. With prefix ARG, go backward that many times the current span."
  6410. (interactive "p")
  6411. (org-agenda-later (- arg)))
  6412. (defun org-agenda-view-mode-dispatch ()
  6413. "Call one of the view mode commands."
  6414. (interactive)
  6415. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6416. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6417. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6418. (let ((a (read-char-exclusive)))
  6419. (case a
  6420. (?\ (call-interactively 'org-agenda-reset-view))
  6421. (?d (call-interactively 'org-agenda-day-view))
  6422. (?w (call-interactively 'org-agenda-week-view))
  6423. (?m (call-interactively 'org-agenda-month-view))
  6424. (?y (call-interactively 'org-agenda-year-view))
  6425. (?l (call-interactively 'org-agenda-log-mode))
  6426. (?L (org-agenda-log-mode '(4)))
  6427. (?c (org-agenda-log-mode 'clockcheck))
  6428. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6429. (?a (call-interactively 'org-agenda-archives-mode))
  6430. (?A (org-agenda-archives-mode 'files))
  6431. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6432. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6433. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6434. (?D (call-interactively 'org-agenda-toggle-diary))
  6435. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6436. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6437. (org-agenda-check-type t 'timeline 'agenda)
  6438. (org-agenda-redo))
  6439. (message "Display now includes inactive timestamps as well"))
  6440. (?q (message "Abort"))
  6441. (otherwise (error "Invalid key" )))))
  6442. (defun org-agenda-reset-view ()
  6443. "Switch to default view for agenda."
  6444. (interactive)
  6445. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6446. (defun org-agenda-day-view (&optional day-of-year)
  6447. "Switch to daily view for agenda.
  6448. With argument DAY-OF-YEAR, switch to that day of the year."
  6449. (interactive "P")
  6450. (org-agenda-change-time-span 'day day-of-year))
  6451. (defun org-agenda-week-view (&optional iso-week)
  6452. "Switch to daily view for agenda.
  6453. With argument ISO-WEEK, switch to the corresponding ISO week.
  6454. If ISO-WEEK has more then 2 digits, only the last two encode the
  6455. week. Any digits before this encode a year. So 200712 means
  6456. week 12 of year 2007. Years in the range 1938-2037 can also be
  6457. written as 2-digit years."
  6458. (interactive "P")
  6459. (org-agenda-change-time-span 'week iso-week))
  6460. (defun org-agenda-month-view (&optional month)
  6461. "Switch to monthly view for agenda.
  6462. With argument MONTH, switch to that month."
  6463. (interactive "P")
  6464. (org-agenda-change-time-span 'month month))
  6465. (defun org-agenda-year-view (&optional year)
  6466. "Switch to yearly view for agenda.
  6467. With argument YEAR, switch to that year.
  6468. If MONTH has more then 2 digits, only the last two encode the
  6469. month. Any digits before this encode a year. So 200712 means
  6470. December year 2007. Years in the range 1938-2037 can also be
  6471. written as 2-digit years."
  6472. (interactive "P")
  6473. (when year
  6474. (setq year (org-small-year-to-year year)))
  6475. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6476. (org-agenda-change-time-span 'year year)
  6477. (error "Abort")))
  6478. (defun org-agenda-change-time-span (span &optional n)
  6479. "Change the agenda view to SPAN.
  6480. SPAN may be `day', `week', `month', `year'."
  6481. (org-agenda-check-type t 'agenda)
  6482. (if (and (not n) (equal org-agenda-current-span span))
  6483. (error "Viewing span is already \"%s\"" span))
  6484. (let* ((sd (or (org-get-at-bol 'day)
  6485. org-starting-day))
  6486. (sd (org-agenda-compute-starting-span sd span n))
  6487. (org-agenda-overriding-arguments
  6488. (or org-agenda-overriding-arguments
  6489. (list (car org-agenda-last-arguments) sd span t))))
  6490. (org-agenda-redo)
  6491. (org-agenda-find-same-or-today-or-agenda))
  6492. (org-agenda-set-mode-name)
  6493. (message "Switched to %s view" span))
  6494. (defun org-agenda-compute-starting-span (sd span &optional n)
  6495. "Compute starting date for agenda.
  6496. SPAN may be `day', `week', `month', `year'. The return value
  6497. is a cons cell with the starting date and the number of days,
  6498. so that the date SD will be in that range."
  6499. (let* ((greg (calendar-gregorian-from-absolute sd))
  6500. (dg (nth 1 greg))
  6501. (mg (car greg))
  6502. (yg (nth 2 greg)))
  6503. (cond
  6504. ((eq span 'day)
  6505. (when n
  6506. (setq sd (+ (calendar-absolute-from-gregorian
  6507. (list mg 1 yg))
  6508. n -1))))
  6509. ((eq span 'week)
  6510. (let* ((nt (calendar-day-of-week
  6511. (calendar-gregorian-from-absolute sd)))
  6512. (d (if org-agenda-start-on-weekday
  6513. (- nt org-agenda-start-on-weekday)
  6514. 0))
  6515. y1)
  6516. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6517. (when n
  6518. (require 'cal-iso)
  6519. (when (> n 99)
  6520. (setq y1 (org-small-year-to-year (/ n 100))
  6521. n (mod n 100)))
  6522. (setq sd
  6523. (calendar-absolute-from-iso
  6524. (list n 1
  6525. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6526. ((eq span 'month)
  6527. (let (y1)
  6528. (when (and n (> n 99))
  6529. (setq y1 (org-small-year-to-year (/ n 100))
  6530. n (mod n 100)))
  6531. (setq sd (calendar-absolute-from-gregorian
  6532. (list (or n mg) 1 (or y1 yg))))))
  6533. ((eq span 'year)
  6534. (setq sd (calendar-absolute-from-gregorian
  6535. (list 1 1 (or n yg))))))
  6536. sd))
  6537. (defun org-agenda-next-date-line (&optional arg)
  6538. "Jump to the next line indicating a date in agenda buffer."
  6539. (interactive "p")
  6540. (org-agenda-check-type t 'agenda 'timeline)
  6541. (beginning-of-line 1)
  6542. ;; This does not work if user makes date format that starts with a blank
  6543. (if (looking-at "^\\S-") (forward-char 1))
  6544. (if (not (re-search-forward "^\\S-" nil t arg))
  6545. (progn
  6546. (backward-char 1)
  6547. (error "No next date after this line in this buffer")))
  6548. (goto-char (match-beginning 0)))
  6549. (defun org-agenda-previous-date-line (&optional arg)
  6550. "Jump to the previous line indicating a date in agenda buffer."
  6551. (interactive "p")
  6552. (org-agenda-check-type t 'agenda 'timeline)
  6553. (beginning-of-line 1)
  6554. (if (not (re-search-backward "^\\S-" nil t arg))
  6555. (error "No previous date before this line in this buffer")))
  6556. ;; Initialize the highlight
  6557. (defvar org-hl (make-overlay 1 1))
  6558. (overlay-put org-hl 'face 'highlight)
  6559. (defun org-highlight (begin end &optional buffer)
  6560. "Highlight a region with overlay."
  6561. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6562. (defun org-unhighlight ()
  6563. "Detach overlay INDEX."
  6564. (org-detach-overlay org-hl))
  6565. ;; FIXME this is currently not used.
  6566. (defun org-highlight-until-next-command (beg end &optional buffer)
  6567. "Move the highlight overlay to BEG/END, remove it before the next command."
  6568. (org-highlight beg end buffer)
  6569. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6570. (defun org-unhighlight-once ()
  6571. "Remove the highlight from its position, and this function from the hook."
  6572. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6573. (org-unhighlight))
  6574. (defun org-agenda-follow-mode ()
  6575. "Toggle follow mode in an agenda buffer."
  6576. (interactive)
  6577. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6578. (org-agenda-set-mode-name)
  6579. (org-agenda-do-context-action)
  6580. (message "Follow mode is %s"
  6581. (if org-agenda-follow-mode "on" "off")))
  6582. (defun org-agenda-entry-text-mode (&optional arg)
  6583. "Toggle entry text mode in an agenda buffer."
  6584. (interactive "P")
  6585. (setq org-agenda-entry-text-mode (or (integerp arg)
  6586. (not org-agenda-entry-text-mode)))
  6587. (org-agenda-entry-text-hide)
  6588. (and org-agenda-entry-text-mode
  6589. (let ((org-agenda-entry-text-maxlines
  6590. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6591. (org-agenda-entry-text-show)))
  6592. (org-agenda-set-mode-name)
  6593. (message "Entry text mode is %s. Maximum number of lines is %d"
  6594. (if org-agenda-entry-text-mode "on" "off")
  6595. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6596. (defun org-agenda-clockreport-mode (&optional with-filter)
  6597. "Toggle clocktable mode in an agenda buffer.
  6598. With prefix arg WITH-FILTER, make the clocktable respect the current
  6599. agenda filter."
  6600. (interactive "P")
  6601. (org-agenda-check-type t 'agenda)
  6602. (if with-filter
  6603. (setq org-agenda-clockreport-mode 'with-filter)
  6604. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6605. (org-agenda-set-mode-name)
  6606. (org-agenda-redo)
  6607. (message "Clocktable mode is %s"
  6608. (if org-agenda-clockreport-mode "on" "off")))
  6609. (defun org-agenda-log-mode (&optional special)
  6610. "Toggle log mode in an agenda buffer.
  6611. With argument SPECIAL, show all possible log items, not only the ones
  6612. configured in `org-agenda-log-mode-items'.
  6613. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6614. (interactive "P")
  6615. (org-agenda-check-type t 'agenda 'timeline)
  6616. (setq org-agenda-show-log
  6617. (cond
  6618. ((equal special '(16)) 'only)
  6619. ((eq special 'clockcheck)
  6620. (if (eq org-agenda-show-log 'clockcheck)
  6621. nil 'clockcheck))
  6622. (special '(closed clock state))
  6623. (t (not org-agenda-show-log))))
  6624. (org-agenda-set-mode-name)
  6625. (org-agenda-redo)
  6626. (message "Log mode is %s"
  6627. (if org-agenda-show-log "on" "off")))
  6628. (defun org-agenda-archives-mode (&optional with-files)
  6629. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6630. When called with a prefix argument, include all archive files as well."
  6631. (interactive "P")
  6632. (setq org-agenda-archives-mode
  6633. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6634. (org-agenda-set-mode-name)
  6635. (org-agenda-redo)
  6636. (message
  6637. "%s"
  6638. (cond
  6639. ((eq org-agenda-archives-mode nil)
  6640. "No archives are included")
  6641. ((eq org-agenda-archives-mode 'trees)
  6642. (format "Trees with :%s: tag are included" org-archive-tag))
  6643. ((eq org-agenda-archives-mode t)
  6644. (format "Trees with :%s: tag and all active archive files are included"
  6645. org-archive-tag)))))
  6646. (defun org-agenda-toggle-diary ()
  6647. "Toggle diary inclusion in an agenda buffer."
  6648. (interactive)
  6649. (org-agenda-check-type t 'agenda)
  6650. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6651. (org-agenda-redo)
  6652. (org-agenda-set-mode-name)
  6653. (message "Diary inclusion turned %s"
  6654. (if org-agenda-include-diary "on" "off")))
  6655. (defun org-agenda-toggle-deadlines ()
  6656. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6657. (interactive)
  6658. (org-agenda-check-type t 'agenda)
  6659. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6660. (org-agenda-redo)
  6661. (org-agenda-set-mode-name)
  6662. (message "Deadlines inclusion turned %s"
  6663. (if org-agenda-include-deadlines "on" "off")))
  6664. (defun org-agenda-toggle-time-grid ()
  6665. "Toggle time grid in an agenda buffer."
  6666. (interactive)
  6667. (org-agenda-check-type t 'agenda)
  6668. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6669. (org-agenda-redo)
  6670. (org-agenda-set-mode-name)
  6671. (message "Time-grid turned %s"
  6672. (if org-agenda-use-time-grid "on" "off")))
  6673. (defun org-agenda-set-mode-name ()
  6674. "Set the mode name to indicate all the small mode settings."
  6675. (setq mode-name
  6676. (list "Org-Agenda"
  6677. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6678. " "
  6679. '(:eval (org-agenda-span-name org-agenda-current-span))
  6680. (if org-agenda-follow-mode " Follow" "")
  6681. (if org-agenda-entry-text-mode " ETxt" "")
  6682. (if org-agenda-include-diary " Diary" "")
  6683. (if org-agenda-include-deadlines " Ddl" "")
  6684. (if org-agenda-use-time-grid " Grid" "")
  6685. (if (and (boundp 'org-habit-show-habits)
  6686. org-habit-show-habits) " Habit" "")
  6687. (cond
  6688. ((consp org-agenda-show-log) " LogAll")
  6689. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6690. (org-agenda-show-log " Log")
  6691. (t ""))
  6692. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6693. :preset-filter))
  6694. '(:eval (org-propertize
  6695. (concat " <"
  6696. (mapconcat
  6697. 'identity
  6698. (append
  6699. (get 'org-agenda-category-filter :preset-filter)
  6700. org-agenda-category-filter)
  6701. "")
  6702. ">")
  6703. 'face 'org-agenda-filter-category
  6704. 'help-echo "Category used in filtering"))
  6705. "")
  6706. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6707. :preset-filter))
  6708. '(:eval (org-propertize
  6709. (concat " {"
  6710. (mapconcat
  6711. 'identity
  6712. (append
  6713. (get 'org-agenda-tag-filter :preset-filter)
  6714. org-agenda-tag-filter)
  6715. "")
  6716. "}")
  6717. 'face 'org-agenda-filter-tags
  6718. 'help-echo "Tags used in filtering"))
  6719. "")
  6720. (if org-agenda-archives-mode
  6721. (if (eq org-agenda-archives-mode t)
  6722. " Archives"
  6723. (format " :%s:" org-archive-tag))
  6724. "")
  6725. (if org-agenda-clockreport-mode
  6726. (if (eq org-agenda-clockreport-mode 'with-filter)
  6727. " Clock{}" " Clock")
  6728. "")))
  6729. (force-mode-line-update))
  6730. (defun org-agenda-post-command-hook ()
  6731. (setq org-agenda-type
  6732. (or (get-text-property (point) 'org-agenda-type)
  6733. (get-text-property (max (point-min) (1- (point)))
  6734. 'org-agenda-type))))
  6735. (defun org-agenda-next-line ()
  6736. "Move cursor to the next line, and show if follow mode is active."
  6737. (interactive)
  6738. (call-interactively 'next-line)
  6739. (org-agenda-do-context-action))
  6740. (defun org-agenda-previous-line ()
  6741. "Move cursor to the previous line, and show if follow-mode is active."
  6742. (interactive)
  6743. (call-interactively 'previous-line)
  6744. (org-agenda-do-context-action))
  6745. (defun org-agenda-do-context-action ()
  6746. "Show outline path and, maybe, follow mode window."
  6747. (let ((m (org-get-at-bol 'org-marker)))
  6748. (when (and (markerp m) (marker-buffer m))
  6749. (and org-agenda-follow-mode
  6750. (if org-agenda-follow-indirect
  6751. (org-agenda-tree-to-indirect-buffer)
  6752. (org-agenda-show)))
  6753. (and org-agenda-show-outline-path
  6754. (org-with-point-at m (org-display-outline-path t))))))
  6755. (defun org-agenda-show-priority ()
  6756. "Show the priority of the current item.
  6757. This priority is composed of the main priority given with the [#A] cookies,
  6758. and by additional input from the age of a schedules or deadline entry."
  6759. (interactive)
  6760. (let* ((pri (org-get-at-bol 'priority)))
  6761. (message "Priority is %d" (if pri pri -1000))))
  6762. (defun org-agenda-show-tags ()
  6763. "Show the tags applicable to the current item."
  6764. (interactive)
  6765. (let* ((tags (org-get-at-bol 'tags)))
  6766. (if tags
  6767. (message "Tags are :%s:"
  6768. (org-no-properties (mapconcat 'identity tags ":")))
  6769. (message "No tags associated with this line"))))
  6770. (defun org-agenda-goto (&optional highlight)
  6771. "Go to the Org-mode file which contains the item at point."
  6772. (interactive)
  6773. (let* ((marker (or (org-get-at-bol 'org-marker)
  6774. (org-agenda-error)))
  6775. (buffer (marker-buffer marker))
  6776. (pos (marker-position marker)))
  6777. (switch-to-buffer-other-window buffer)
  6778. (widen)
  6779. (push-mark)
  6780. (goto-char pos)
  6781. (when (derived-mode-p 'org-mode)
  6782. (org-show-context 'agenda)
  6783. (save-excursion
  6784. (and (outline-next-heading)
  6785. (org-flag-heading nil)))) ; show the next heading
  6786. (when (outline-invisible-p)
  6787. (show-entry)) ; display invisible text
  6788. (recenter (/ (window-height) 2))
  6789. (run-hooks 'org-agenda-after-show-hook)
  6790. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6791. (defvar org-agenda-after-show-hook nil
  6792. "Normal hook run after an item has been shown from the agenda.
  6793. Point is in the buffer where the item originated.")
  6794. (defun org-agenda-kill ()
  6795. "Kill the entry or subtree belonging to the current agenda entry."
  6796. (interactive)
  6797. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6798. (let* ((marker (or (org-get-at-bol 'org-marker)
  6799. (org-agenda-error)))
  6800. (buffer (marker-buffer marker))
  6801. (pos (marker-position marker))
  6802. (type (org-get-at-bol 'type))
  6803. dbeg dend (n 0) conf)
  6804. (org-with-remote-undo buffer
  6805. (with-current-buffer buffer
  6806. (save-excursion
  6807. (goto-char pos)
  6808. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  6809. (setq dbeg (progn (org-back-to-heading t) (point))
  6810. dend (org-end-of-subtree t t))
  6811. (setq dbeg (point-at-bol)
  6812. dend (min (point-max) (1+ (point-at-eol)))))
  6813. (goto-char dbeg)
  6814. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6815. (setq conf (or (eq t org-agenda-confirm-kill)
  6816. (and (numberp org-agenda-confirm-kill)
  6817. (> n org-agenda-confirm-kill))))
  6818. (and conf
  6819. (not (y-or-n-p
  6820. (format "Delete entry with %d lines in buffer \"%s\"? "
  6821. n (buffer-name buffer))))
  6822. (error "Abort"))
  6823. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6824. (with-current-buffer buffer (delete-region dbeg dend))
  6825. (message "Agenda item and source killed"))))
  6826. (defvar org-archive-default-command)
  6827. (defun org-agenda-archive-default ()
  6828. "Archive the entry or subtree belonging to the current agenda entry."
  6829. (interactive)
  6830. (require 'org-archive)
  6831. (org-agenda-archive-with org-archive-default-command))
  6832. (defun org-agenda-archive-default-with-confirmation ()
  6833. "Archive the entry or subtree belonging to the current agenda entry."
  6834. (interactive)
  6835. (require 'org-archive)
  6836. (org-agenda-archive-with org-archive-default-command 'confirm))
  6837. (defun org-agenda-archive ()
  6838. "Archive the entry or subtree belonging to the current agenda entry."
  6839. (interactive)
  6840. (org-agenda-archive-with 'org-archive-subtree))
  6841. (defun org-agenda-archive-to-archive-sibling ()
  6842. "Move the entry to the archive sibling."
  6843. (interactive)
  6844. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6845. (defun org-agenda-archive-with (cmd &optional confirm)
  6846. "Move the entry to the archive sibling."
  6847. (interactive)
  6848. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6849. (let* ((marker (or (org-get-at-bol 'org-marker)
  6850. (org-agenda-error)))
  6851. (buffer (marker-buffer marker))
  6852. (pos (marker-position marker)))
  6853. (org-with-remote-undo buffer
  6854. (with-current-buffer buffer
  6855. (if (derived-mode-p 'org-mode)
  6856. (if (and confirm
  6857. (not (y-or-n-p "Archive this subtree or entry? ")))
  6858. (error "Abort")
  6859. (save-excursion
  6860. (goto-char pos)
  6861. (org-remove-subtree-entries-from-agenda)
  6862. (org-back-to-heading t)
  6863. (funcall cmd)))
  6864. (error "Archiving works only in Org-mode files"))))))
  6865. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6866. "Remove all lines in the agenda that correspond to a given subtree.
  6867. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6868. If this information is not given, the function uses the tree at point."
  6869. (let ((buf (or buf (current-buffer))) m p)
  6870. (save-excursion
  6871. (unless (and beg end)
  6872. (org-back-to-heading t)
  6873. (setq beg (point))
  6874. (org-end-of-subtree t)
  6875. (setq end (point)))
  6876. (set-buffer (get-buffer org-agenda-buffer-name))
  6877. (save-excursion
  6878. (goto-char (point-max))
  6879. (beginning-of-line 1)
  6880. (while (not (bobp))
  6881. (when (and (setq m (org-get-at-bol 'org-marker))
  6882. (equal buf (marker-buffer m))
  6883. (setq p (marker-position m))
  6884. (>= p beg)
  6885. (< p end))
  6886. (let ((inhibit-read-only t))
  6887. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6888. (beginning-of-line 0))))))
  6889. (defun org-agenda-refile (&optional goto rfloc no-update)
  6890. "Refile the item at point."
  6891. (interactive "P")
  6892. (if (equal goto '(16))
  6893. (org-refile-goto-last-stored)
  6894. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6895. (org-agenda-error)))
  6896. (buffer (marker-buffer marker))
  6897. (pos (marker-position marker))
  6898. (rfloc (or rfloc
  6899. (org-refile-get-location
  6900. (if goto "Goto" "Refile to") buffer
  6901. org-refile-allow-creating-parent-nodes))))
  6902. (with-current-buffer buffer
  6903. (save-excursion
  6904. (save-restriction
  6905. (widen)
  6906. (goto-char marker)
  6907. (org-remove-subtree-entries-from-agenda)
  6908. (org-refile goto buffer rfloc)))))
  6909. (unless no-update (org-agenda-redo))))
  6910. (defun org-agenda-open-link (&optional arg)
  6911. "Follow the link in the current line, if any.
  6912. This looks for a link in the displayed line in the agenda. It also looks
  6913. at the text of the entry itself."
  6914. (interactive "P")
  6915. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6916. (org-get-at-bol 'org-marker)))
  6917. (buffer (and marker (marker-buffer marker)))
  6918. (prefix (buffer-substring
  6919. (point-at-bol) (point-at-eol))))
  6920. (cond
  6921. (buffer
  6922. (with-current-buffer buffer
  6923. (save-excursion
  6924. (save-restriction
  6925. (widen)
  6926. (goto-char marker)
  6927. (org-offer-links-in-entry arg prefix)))))
  6928. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6929. (save-excursion
  6930. (beginning-of-line 1)
  6931. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6932. (org-open-link-from-string (match-string 1)))
  6933. (t (error "No link to open here")))))
  6934. (defun org-agenda-copy-local-variable (var)
  6935. "Get a variable from a referenced buffer and install it here."
  6936. (let ((m (org-get-at-bol 'org-marker)))
  6937. (when (and m (buffer-live-p (marker-buffer m)))
  6938. (org-set-local var (with-current-buffer (marker-buffer m)
  6939. (symbol-value var))))))
  6940. (defun org-agenda-switch-to (&optional delete-other-windows)
  6941. "Go to the Org-mode file which contains the item at point."
  6942. (interactive)
  6943. (if (and org-return-follows-link
  6944. (not (org-get-at-bol 'org-marker))
  6945. (org-in-regexp org-bracket-link-regexp))
  6946. (org-open-link-from-string (match-string 0))
  6947. (let* ((marker (or (org-get-at-bol 'org-marker)
  6948. (org-agenda-error)))
  6949. (buffer (marker-buffer marker))
  6950. (pos (marker-position marker)))
  6951. (org-pop-to-buffer-same-window buffer)
  6952. (and delete-other-windows (delete-other-windows))
  6953. (widen)
  6954. (goto-char pos)
  6955. (when (derived-mode-p 'org-mode)
  6956. (org-show-context 'agenda)
  6957. (save-excursion
  6958. (and (outline-next-heading)
  6959. (org-flag-heading nil))) ; show the next heading
  6960. (when (outline-invisible-p)
  6961. (show-entry)))))) ; display invisible text
  6962. (defun org-agenda-goto-mouse (ev)
  6963. "Go to the Org-mode file which contains the item at the mouse click."
  6964. (interactive "e")
  6965. (mouse-set-point ev)
  6966. (org-agenda-goto))
  6967. (defun org-agenda-show (&optional full-entry)
  6968. "Display the Org-mode file which contains the item at point.
  6969. With prefix argument FULL-ENTRY, make the entire entry visible
  6970. if it was hidden in the outline."
  6971. (interactive "P")
  6972. (let ((win (selected-window)))
  6973. (if full-entry
  6974. (let ((org-show-entry-below t))
  6975. (org-agenda-goto t))
  6976. (org-agenda-goto t))
  6977. (select-window win)))
  6978. (defvar org-agenda-show-window nil)
  6979. (defun org-agenda-show-and-scroll-up (&optional arg)
  6980. "Display the Org-mode file which contains the item at point.
  6981. When called repeatedly, scroll the window that is displaying the buffer.
  6982. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6983. `show-subtree' to display the item, so that drawers and logbooks stay
  6984. folded."
  6985. (interactive "P")
  6986. (let ((win (selected-window)))
  6987. (if (and (window-live-p org-agenda-show-window)
  6988. (eq this-command last-command))
  6989. (progn
  6990. (select-window org-agenda-show-window)
  6991. (ignore-errors (scroll-up)))
  6992. (org-agenda-goto t)
  6993. (if arg (org-show-entry) (show-subtree))
  6994. (setq org-agenda-show-window (selected-window)))
  6995. (select-window win)))
  6996. (defun org-agenda-show-scroll-down ()
  6997. "Scroll down the window showing the agenda."
  6998. (interactive)
  6999. (let ((win (selected-window)))
  7000. (when (window-live-p org-agenda-show-window)
  7001. (select-window org-agenda-show-window)
  7002. (ignore-errors (scroll-down))
  7003. (select-window win))))
  7004. (defun org-agenda-show-1 (&optional more)
  7005. "Display the Org-mode file which contains the item at point.
  7006. The prefix arg selects the amount of information to display:
  7007. 0 hide the subtree
  7008. 1 just show the entry according to defaults.
  7009. 2 show the children view
  7010. 3 show the subtree view
  7011. 4 show the entire subtree and any LOGBOOK drawers
  7012. 5 show the entire subtree and any drawers
  7013. With prefix argument FULL-ENTRY, make the entire entry visible
  7014. if it was hidden in the outline."
  7015. (interactive "p")
  7016. (let ((win (selected-window)))
  7017. (org-agenda-goto t)
  7018. (org-recenter-heading 1)
  7019. (cond
  7020. ((= more 0)
  7021. (hide-subtree)
  7022. (save-excursion
  7023. (org-back-to-heading)
  7024. (run-hook-with-args 'org-cycle-hook 'folded))
  7025. (message "Remote: FOLDED"))
  7026. ((and (org-called-interactively-p 'any) (= more 1))
  7027. (message "Remote: show with default settings"))
  7028. ((= more 2)
  7029. (show-entry)
  7030. (show-children)
  7031. (save-excursion
  7032. (org-back-to-heading)
  7033. (run-hook-with-args 'org-cycle-hook 'children))
  7034. (message "Remote: CHILDREN"))
  7035. ((= more 3)
  7036. (show-subtree)
  7037. (save-excursion
  7038. (org-back-to-heading)
  7039. (run-hook-with-args 'org-cycle-hook 'subtree))
  7040. (message "Remote: SUBTREE"))
  7041. ((= more 4)
  7042. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7043. (org-drawer-regexp
  7044. (concat "^[ \t]*:\\("
  7045. (mapconcat 'regexp-quote org-drawers "\\|")
  7046. "\\):[ \t]*$")))
  7047. (show-subtree)
  7048. (save-excursion
  7049. (org-back-to-heading)
  7050. (org-cycle-hide-drawers 'subtree)))
  7051. (message "Remote: SUBTREE AND LOGBOOK"))
  7052. ((> more 4)
  7053. (show-subtree)
  7054. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7055. (select-window win)))
  7056. (defun org-recenter-heading (n)
  7057. (save-excursion
  7058. (org-back-to-heading)
  7059. (recenter n)))
  7060. (defvar org-agenda-cycle-counter nil)
  7061. (defun org-agenda-cycle-show (&optional n)
  7062. "Show the current entry in another window, with default settings.
  7063. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7064. When use repeatedly in immediate succession, the remote entry will cycle
  7065. through visibility
  7066. children -> subtree -> folded
  7067. When called with a numeric prefix arg, that arg will be passed through to
  7068. `org-agenda-show-1'. For the interpretation of that argument, see the
  7069. docstring of `org-agenda-show-1'."
  7070. (interactive "P")
  7071. (if (integerp n)
  7072. (setq org-agenda-cycle-counter n)
  7073. (if (not (eq last-command this-command))
  7074. (setq org-agenda-cycle-counter 1)
  7075. (if (equal org-agenda-cycle-counter 0)
  7076. (setq org-agenda-cycle-counter 2)
  7077. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7078. (if (> org-agenda-cycle-counter 3)
  7079. (setq org-agenda-cycle-counter 0)))))
  7080. (org-agenda-show-1 org-agenda-cycle-counter))
  7081. (defun org-agenda-recenter (arg)
  7082. "Display the Org-mode file which contains the item at point and recenter."
  7083. (interactive "P")
  7084. (let ((win (selected-window)))
  7085. (org-agenda-goto t)
  7086. (recenter arg)
  7087. (select-window win)))
  7088. (defun org-agenda-show-mouse (ev)
  7089. "Display the Org-mode file which contains the item at the mouse click."
  7090. (interactive "e")
  7091. (mouse-set-point ev)
  7092. (org-agenda-show))
  7093. (defun org-agenda-check-no-diary ()
  7094. "Check if the entry is a diary link and abort if yes."
  7095. (if (org-get-at-bol 'org-agenda-diary-link)
  7096. (org-agenda-error)))
  7097. (defun org-agenda-error ()
  7098. (error "Command not allowed in this line"))
  7099. (defun org-agenda-tree-to-indirect-buffer ()
  7100. "Show the subtree corresponding to the current entry in an indirect buffer.
  7101. This calls the command `org-tree-to-indirect-buffer' from the original
  7102. Org-mode buffer.
  7103. With numerical prefix arg ARG, go up to this level and then take that tree.
  7104. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7105. use the dedicated frame)."
  7106. (interactive)
  7107. (if (and current-prefix-arg (listp current-prefix-arg))
  7108. (org-agenda-do-tree-to-indirect-buffer)
  7109. (let ((agenda-window (selected-window))
  7110. (indirect-window
  7111. (and org-last-indirect-buffer
  7112. (get-buffer-window org-last-indirect-buffer))))
  7113. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7114. (unwind-protect
  7115. (progn
  7116. (unless (and indirect-window (window-live-p indirect-window))
  7117. (setq indirect-window (split-window agenda-window)))
  7118. (select-window indirect-window)
  7119. (switch-to-buffer org-last-indirect-buffer :norecord)
  7120. (fit-window-to-buffer indirect-window))
  7121. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7122. (defun org-agenda-do-tree-to-indirect-buffer ()
  7123. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7124. (org-agenda-check-no-diary)
  7125. (let* ((marker (or (org-get-at-bol 'org-marker)
  7126. (org-agenda-error)))
  7127. (buffer (marker-buffer marker))
  7128. (pos (marker-position marker)))
  7129. (with-current-buffer buffer
  7130. (save-excursion
  7131. (goto-char pos)
  7132. (call-interactively 'org-tree-to-indirect-buffer)))))
  7133. (defvar org-last-heading-marker (make-marker)
  7134. "Marker pointing to the headline that last changed its TODO state
  7135. by a remote command from the agenda.")
  7136. (defun org-agenda-todo-nextset ()
  7137. "Switch TODO entry to next sequence."
  7138. (interactive)
  7139. (org-agenda-todo 'nextset))
  7140. (defun org-agenda-todo-previousset ()
  7141. "Switch TODO entry to previous sequence."
  7142. (interactive)
  7143. (org-agenda-todo 'previousset))
  7144. (defun org-agenda-todo (&optional arg)
  7145. "Cycle TODO state of line at point, also in Org-mode file.
  7146. This changes the line at point, all other lines in the agenda referring to
  7147. the same tree node, and the headline of the tree node in the Org-mode file."
  7148. (interactive "P")
  7149. (org-agenda-check-no-diary)
  7150. (let* ((col (current-column))
  7151. (marker (or (org-get-at-bol 'org-marker)
  7152. (org-agenda-error)))
  7153. (buffer (marker-buffer marker))
  7154. (pos (marker-position marker))
  7155. (hdmarker (org-get-at-bol 'org-hd-marker))
  7156. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7157. (inhibit-read-only t)
  7158. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7159. (org-with-remote-undo buffer
  7160. (with-current-buffer buffer
  7161. (widen)
  7162. (goto-char pos)
  7163. (org-show-context 'agenda)
  7164. (save-excursion
  7165. (and (outline-next-heading)
  7166. (org-flag-heading nil))) ; show the next heading
  7167. (let ((current-prefix-arg arg))
  7168. (call-interactively 'org-todo))
  7169. (and (bolp) (forward-char 1))
  7170. (setq newhead (org-get-heading))
  7171. (when (and (org-bound-and-true-p
  7172. org-agenda-headline-snapshot-before-repeat)
  7173. (not (equal org-agenda-headline-snapshot-before-repeat
  7174. newhead))
  7175. todayp)
  7176. (setq newhead org-agenda-headline-snapshot-before-repeat
  7177. just-one t))
  7178. (save-excursion
  7179. (org-back-to-heading)
  7180. (move-marker org-last-heading-marker (point))))
  7181. (beginning-of-line 1)
  7182. (save-excursion
  7183. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7184. (org-move-to-column col))))
  7185. (defun org-agenda-add-note (&optional arg)
  7186. "Add a time-stamped note to the entry at point."
  7187. (interactive "P")
  7188. (org-agenda-check-no-diary)
  7189. (let* ((marker (or (org-get-at-bol 'org-marker)
  7190. (org-agenda-error)))
  7191. (buffer (marker-buffer marker))
  7192. (pos (marker-position marker))
  7193. (hdmarker (org-get-at-bol 'org-hd-marker))
  7194. (inhibit-read-only t))
  7195. (with-current-buffer buffer
  7196. (widen)
  7197. (goto-char pos)
  7198. (org-show-context 'agenda)
  7199. (save-excursion
  7200. (and (outline-next-heading)
  7201. (org-flag-heading nil))) ; show the next heading
  7202. (org-add-note))))
  7203. (defun org-agenda-change-all-lines (newhead hdmarker
  7204. &optional fixface just-this)
  7205. "Change all lines in the agenda buffer which match HDMARKER.
  7206. The new content of the line will be NEWHEAD (as modified by
  7207. `org-agenda-format-item'). HDMARKER is checked with
  7208. `equal' against all `org-hd-marker' text properties in the file.
  7209. If FIXFACE is non-nil, the face of each item is modified according to
  7210. the new TODO state.
  7211. If JUST-THIS is non-nil, change just the current line, not all.
  7212. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7213. (let* ((inhibit-read-only t)
  7214. (line (org-current-line))
  7215. (org-agenda-buffer (current-buffer))
  7216. (thetags (with-current-buffer (marker-buffer hdmarker)
  7217. (save-excursion (save-restriction (widen)
  7218. (goto-char hdmarker)
  7219. (org-get-tags-at)))))
  7220. props m pl undone-face done-face finish new dotime cat tags)
  7221. (save-excursion
  7222. (goto-char (point-max))
  7223. (beginning-of-line 1)
  7224. (while (not finish)
  7225. (setq finish (bobp))
  7226. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7227. (or (not just-this) (= (org-current-line) line))
  7228. (equal m hdmarker))
  7229. (setq props (text-properties-at (point))
  7230. dotime (org-get-at-bol 'dotime)
  7231. cat (org-get-at-bol 'org-category)
  7232. tags thetags
  7233. new
  7234. (let ((org-prefix-format-compiled
  7235. (or (get-text-property (point) 'format)
  7236. org-prefix-format-compiled))
  7237. (extra (org-get-at-bol 'extra)))
  7238. (with-current-buffer (marker-buffer hdmarker)
  7239. (save-excursion
  7240. (save-restriction
  7241. (widen)
  7242. (org-agenda-format-item extra newhead cat tags dotime)))))
  7243. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7244. undone-face (org-get-at-bol 'undone-face)
  7245. done-face (org-get-at-bol 'done-face))
  7246. (beginning-of-line 1)
  7247. (cond
  7248. ((equal new "")
  7249. (and (looking-at ".*\n?") (replace-match "")))
  7250. ((looking-at ".*")
  7251. (replace-match new t t)
  7252. (beginning-of-line 1)
  7253. (add-text-properties (point-at-bol) (point-at-eol) props)
  7254. (when fixface
  7255. (add-text-properties
  7256. (point-at-bol) (point-at-eol)
  7257. (list 'face
  7258. (if org-last-todo-state-is-todo
  7259. undone-face done-face))))
  7260. (org-agenda-highlight-todo 'line)
  7261. (beginning-of-line 1))
  7262. (t (error "Line update did not work"))))
  7263. (beginning-of-line 0)))
  7264. (org-finalize-agenda)))
  7265. (defun org-agenda-align-tags (&optional line)
  7266. "Align all tags in agenda items to `org-agenda-tags-column'."
  7267. (let ((inhibit-read-only t) l c)
  7268. (save-excursion
  7269. (goto-char (if line (point-at-bol) (point-min)))
  7270. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7271. (if line (point-at-eol) nil) t)
  7272. (add-text-properties
  7273. (match-beginning 2) (match-end 2)
  7274. (list 'face (delq nil (let ((prop (get-text-property
  7275. (match-beginning 2) 'face)))
  7276. (or (listp prop) (setq prop (list prop)))
  7277. (if (memq 'org-tag prop)
  7278. prop
  7279. (cons 'org-tag prop))))))
  7280. (setq l (- (match-end 2) (match-beginning 2))
  7281. c (if (< org-agenda-tags-column 0)
  7282. (- (abs org-agenda-tags-column) l)
  7283. org-agenda-tags-column))
  7284. (delete-region (match-beginning 1) (match-end 1))
  7285. (goto-char (match-beginning 1))
  7286. (insert (org-add-props
  7287. (make-string (max 1 (- c (current-column))) ?\ )
  7288. (plist-put (copy-sequence (text-properties-at (point)))
  7289. 'face nil))))
  7290. (goto-char (point-min))
  7291. (org-font-lock-add-tag-faces (point-max)))))
  7292. (defun org-agenda-priority-up ()
  7293. "Increase the priority of line at point, also in Org-mode file."
  7294. (interactive)
  7295. (org-agenda-priority 'up))
  7296. (defun org-agenda-priority-down ()
  7297. "Decrease the priority of line at point, also in Org-mode file."
  7298. (interactive)
  7299. (org-agenda-priority 'down))
  7300. (defun org-agenda-priority (&optional force-direction)
  7301. "Set the priority of line at point, also in Org-mode file.
  7302. This changes the line at point, all other lines in the agenda referring to
  7303. the same tree node, and the headline of the tree node in the Org-mode file."
  7304. (interactive)
  7305. (unless org-enable-priority-commands
  7306. (error "Priority commands are disabled"))
  7307. (org-agenda-check-no-diary)
  7308. (let* ((marker (or (org-get-at-bol 'org-marker)
  7309. (org-agenda-error)))
  7310. (hdmarker (org-get-at-bol 'org-hd-marker))
  7311. (buffer (marker-buffer hdmarker))
  7312. (pos (marker-position hdmarker))
  7313. (inhibit-read-only t)
  7314. newhead)
  7315. (org-with-remote-undo buffer
  7316. (with-current-buffer buffer
  7317. (widen)
  7318. (goto-char pos)
  7319. (org-show-context 'agenda)
  7320. (save-excursion
  7321. (and (outline-next-heading)
  7322. (org-flag-heading nil))) ; show the next heading
  7323. (funcall 'org-priority force-direction)
  7324. (end-of-line 1)
  7325. (setq newhead (org-get-heading)))
  7326. (org-agenda-change-all-lines newhead hdmarker)
  7327. (beginning-of-line 1))))
  7328. ;; FIXME: should fix the tags property of the agenda line.
  7329. (defun org-agenda-set-tags (&optional tag onoff)
  7330. "Set tags for the current headline."
  7331. (interactive)
  7332. (org-agenda-check-no-diary)
  7333. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7334. (call-interactively 'org-change-tag-in-region)
  7335. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7336. (org-agenda-error)))
  7337. (buffer (marker-buffer hdmarker))
  7338. (pos (marker-position hdmarker))
  7339. (inhibit-read-only t)
  7340. newhead)
  7341. (org-with-remote-undo buffer
  7342. (with-current-buffer buffer
  7343. (widen)
  7344. (goto-char pos)
  7345. (save-excursion
  7346. (org-show-context 'agenda))
  7347. (save-excursion
  7348. (and (outline-next-heading)
  7349. (org-flag-heading nil))) ; show the next heading
  7350. (goto-char pos)
  7351. (if tag
  7352. (org-toggle-tag tag onoff)
  7353. (call-interactively 'org-set-tags))
  7354. (end-of-line 1)
  7355. (setq newhead (org-get-heading)))
  7356. (org-agenda-change-all-lines newhead hdmarker)
  7357. (beginning-of-line 1)))))
  7358. (defun org-agenda-set-property ()
  7359. "Set a property for the current headline."
  7360. (interactive)
  7361. (org-agenda-check-no-diary)
  7362. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7363. (org-agenda-error)))
  7364. (buffer (marker-buffer hdmarker))
  7365. (pos (marker-position hdmarker))
  7366. (inhibit-read-only t)
  7367. newhead)
  7368. (org-with-remote-undo buffer
  7369. (with-current-buffer buffer
  7370. (widen)
  7371. (goto-char pos)
  7372. (save-excursion
  7373. (org-show-context 'agenda))
  7374. (save-excursion
  7375. (and (outline-next-heading)
  7376. (org-flag-heading nil))) ; show the next heading
  7377. (goto-char pos)
  7378. (call-interactively 'org-set-property)))))
  7379. (defun org-agenda-set-effort ()
  7380. "Set the effort property for the current headline."
  7381. (interactive)
  7382. (org-agenda-check-no-diary)
  7383. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7384. (org-agenda-error)))
  7385. (buffer (marker-buffer hdmarker))
  7386. (pos (marker-position hdmarker))
  7387. (inhibit-read-only t)
  7388. newhead)
  7389. (org-with-remote-undo buffer
  7390. (with-current-buffer buffer
  7391. (widen)
  7392. (goto-char pos)
  7393. (save-excursion
  7394. (org-show-context 'agenda))
  7395. (save-excursion
  7396. (and (outline-next-heading)
  7397. (org-flag-heading nil))) ; show the next heading
  7398. (goto-char pos)
  7399. (call-interactively 'org-set-effort)
  7400. (end-of-line 1)
  7401. (setq newhead (org-get-heading)))
  7402. (org-agenda-change-all-lines newhead hdmarker))))
  7403. (defun org-agenda-toggle-archive-tag ()
  7404. "Toggle the archive tag for the current entry."
  7405. (interactive)
  7406. (org-agenda-check-no-diary)
  7407. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7408. (org-agenda-error)))
  7409. (buffer (marker-buffer hdmarker))
  7410. (pos (marker-position hdmarker))
  7411. (inhibit-read-only t)
  7412. newhead)
  7413. (org-with-remote-undo buffer
  7414. (with-current-buffer buffer
  7415. (widen)
  7416. (goto-char pos)
  7417. (org-show-context 'agenda)
  7418. (save-excursion
  7419. (and (outline-next-heading)
  7420. (org-flag-heading nil))) ; show the next heading
  7421. (call-interactively 'org-toggle-archive-tag)
  7422. (end-of-line 1)
  7423. (setq newhead (org-get-heading)))
  7424. (org-agenda-change-all-lines newhead hdmarker)
  7425. (beginning-of-line 1))))
  7426. (defun org-agenda-do-date-later (arg)
  7427. (interactive "P")
  7428. (cond
  7429. ((or (equal arg '(16))
  7430. (memq last-command
  7431. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7432. (setq this-command 'org-agenda-date-later-minutes)
  7433. (org-agenda-date-later-minutes 1))
  7434. ((or (equal arg '(4))
  7435. (memq last-command
  7436. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7437. (setq this-command 'org-agenda-date-later-hours)
  7438. (org-agenda-date-later-hours 1))
  7439. (t
  7440. (org-agenda-date-later (prefix-numeric-value arg)))))
  7441. (defun org-agenda-do-date-earlier (arg)
  7442. (interactive "P")
  7443. (cond
  7444. ((or (equal arg '(16))
  7445. (memq last-command
  7446. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7447. (setq this-command 'org-agenda-date-earlier-minutes)
  7448. (org-agenda-date-earlier-minutes 1))
  7449. ((or (equal arg '(4))
  7450. (memq last-command
  7451. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7452. (setq this-command 'org-agenda-date-earlier-hours)
  7453. (org-agenda-date-earlier-hours 1))
  7454. (t
  7455. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7456. (defun org-agenda-date-later (arg &optional what)
  7457. "Change the date of this item to ARG day(s) later."
  7458. (interactive "p")
  7459. (org-agenda-check-type t 'agenda 'timeline)
  7460. (org-agenda-check-no-diary)
  7461. (let* ((marker (or (org-get-at-bol 'org-marker)
  7462. (org-agenda-error)))
  7463. (buffer (marker-buffer marker))
  7464. (pos (marker-position marker))
  7465. cdate today)
  7466. (org-with-remote-undo buffer
  7467. (with-current-buffer buffer
  7468. (widen)
  7469. (goto-char pos)
  7470. (if (not (org-at-timestamp-p))
  7471. (error "Cannot find time stamp"))
  7472. (when (and org-agenda-move-date-from-past-immediately-to-today
  7473. (equal arg 1)
  7474. (or (not what) (eq what 'day))
  7475. (not (save-match-data (org-at-date-range-p))))
  7476. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7477. cdate (calendar-absolute-from-gregorian
  7478. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7479. today (org-today))
  7480. (if (> today cdate)
  7481. ;; immediately shift to today
  7482. (setq arg (- today cdate))))
  7483. (org-timestamp-change arg (or what 'day))
  7484. (when (and (org-at-date-range-p)
  7485. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7486. (let ((end org-last-changed-timestamp))
  7487. (org-timestamp-change arg (or what 'day))
  7488. (setq org-last-changed-timestamp
  7489. (concat org-last-changed-timestamp "--" end)))))
  7490. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7491. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7492. (defun org-agenda-date-earlier (arg &optional what)
  7493. "Change the date of this item to ARG day(s) earlier."
  7494. (interactive "p")
  7495. (org-agenda-date-later (- arg) what))
  7496. (defun org-agenda-date-later-minutes (arg)
  7497. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7498. (interactive "p")
  7499. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7500. (org-agenda-date-later arg 'minute))
  7501. (defun org-agenda-date-earlier-minutes (arg)
  7502. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7503. (interactive "p")
  7504. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7505. (org-agenda-date-earlier arg 'minute))
  7506. (defun org-agenda-date-later-hours (arg)
  7507. "Change the time of this item, in hour steps."
  7508. (interactive "p")
  7509. (org-agenda-date-later arg 'hour))
  7510. (defun org-agenda-date-earlier-hours (arg)
  7511. "Change the time of this item, in hour steps."
  7512. (interactive "p")
  7513. (org-agenda-date-earlier arg 'hour))
  7514. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7515. "Show new date stamp via text properties."
  7516. ;; We use text properties to make this undoable
  7517. (let ((inhibit-read-only t)
  7518. (buffer-invisibility-spec))
  7519. (setq stamp (concat " " prefix " => " stamp))
  7520. (save-excursion
  7521. (goto-char (point-max))
  7522. (while (not (bobp))
  7523. (when (equal marker (org-get-at-bol 'org-marker))
  7524. (org-move-to-column (- (window-width) (length stamp)) t)
  7525. (org-agenda-fix-tags-filter-overlays-at (point))
  7526. (if (featurep 'xemacs)
  7527. ;; Use `duplicable' property to trigger undo recording
  7528. (let ((ex (make-extent nil nil))
  7529. (gl (make-glyph stamp)))
  7530. (set-glyph-face gl 'secondary-selection)
  7531. (set-extent-properties
  7532. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7533. (insert-extent ex (1- (point)) (point-at-eol)))
  7534. (add-text-properties
  7535. (1- (point)) (point-at-eol)
  7536. (list 'display (org-add-props stamp nil
  7537. 'face 'secondary-selection))))
  7538. (beginning-of-line 1))
  7539. (beginning-of-line 0)))))
  7540. (defun org-agenda-date-prompt (arg)
  7541. "Change the date of this item. Date is prompted for, with default today.
  7542. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7543. be used to request time specification in the time stamp."
  7544. (interactive "P")
  7545. (org-agenda-check-type t 'agenda 'timeline)
  7546. (org-agenda-check-no-diary)
  7547. (let* ((marker (or (org-get-at-bol 'org-marker)
  7548. (org-agenda-error)))
  7549. (buffer (marker-buffer marker))
  7550. (pos (marker-position marker)))
  7551. (org-with-remote-undo buffer
  7552. (with-current-buffer buffer
  7553. (widen)
  7554. (goto-char pos)
  7555. (if (not (org-at-timestamp-p t))
  7556. (error "Cannot find time stamp"))
  7557. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7558. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7559. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7560. (defun org-agenda-schedule (arg &optional time)
  7561. "Schedule the item at point.
  7562. ARG is passed through to `org-schedule'."
  7563. (interactive "P")
  7564. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7565. (org-agenda-check-no-diary)
  7566. (let* ((marker (or (org-get-at-bol 'org-marker)
  7567. (org-agenda-error)))
  7568. (type (marker-insertion-type marker))
  7569. (buffer (marker-buffer marker))
  7570. (pos (marker-position marker))
  7571. (org-insert-labeled-timestamps-at-point nil)
  7572. ts)
  7573. (set-marker-insertion-type marker t)
  7574. (org-with-remote-undo buffer
  7575. (with-current-buffer buffer
  7576. (widen)
  7577. (goto-char pos)
  7578. (setq ts (org-schedule arg time)))
  7579. (org-agenda-show-new-time marker ts "S"))
  7580. (message "Item scheduled for %s" ts)))
  7581. (defun org-agenda-deadline (arg &optional time)
  7582. "Schedule the item at point.
  7583. ARG is passed through to `org-deadline'."
  7584. (interactive "P")
  7585. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7586. (org-agenda-check-no-diary)
  7587. (let* ((marker (or (org-get-at-bol 'org-marker)
  7588. (org-agenda-error)))
  7589. (buffer (marker-buffer marker))
  7590. (pos (marker-position marker))
  7591. (org-insert-labeled-timestamps-at-point nil)
  7592. ts)
  7593. (org-with-remote-undo buffer
  7594. (with-current-buffer buffer
  7595. (widen)
  7596. (goto-char pos)
  7597. (setq ts (org-deadline arg time)))
  7598. (org-agenda-show-new-time marker ts "D"))
  7599. (message "Deadline for this item set to %s" ts)))
  7600. (defun org-agenda-action ()
  7601. "Select entry for agenda action, or execute an agenda action.
  7602. This command prompts for another letter. Valid inputs are:
  7603. m Mark the entry at point for an agenda action
  7604. s Schedule the marked entry to the date at the cursor
  7605. d Set the deadline of the marked entry to the date at the cursor
  7606. r Call `org-remember' with cursor date as the default date
  7607. c Call `org-capture' with cursor date as the default date
  7608. SPC Show marked entry in other window
  7609. TAB Visit marked entry in other window
  7610. The cursor may be at a date in the calendar, or in the Org agenda."
  7611. (interactive)
  7612. (let (ans)
  7613. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7614. (setq ans (read-char-exclusive))
  7615. (cond
  7616. ((equal ans ?m)
  7617. ;; Mark this entry
  7618. (if (eq major-mode 'org-agenda-mode)
  7619. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7620. (org-get-at-bol 'org-marker))))
  7621. (if m
  7622. (progn
  7623. (move-marker org-agenda-action-marker
  7624. (marker-position m) (marker-buffer m))
  7625. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7626. (error "Don't know which entry to mark")))
  7627. (error "This command works only in the agenda")))
  7628. ((equal ans ?s)
  7629. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7630. ((equal ans ?d)
  7631. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7632. ((equal ans ?r)
  7633. (org-agenda-do-action '(org-remember) t))
  7634. ((equal ans ?c)
  7635. (org-agenda-do-action '(org-capture) t))
  7636. ((equal ans ?\ )
  7637. (let ((cw (selected-window)))
  7638. (org-switch-to-buffer-other-window
  7639. (marker-buffer org-agenda-action-marker))
  7640. (goto-char org-agenda-action-marker)
  7641. (org-show-context 'agenda)
  7642. (select-window cw)))
  7643. ((equal ans ?\C-i)
  7644. (org-switch-to-buffer-other-window
  7645. (marker-buffer org-agenda-action-marker))
  7646. (goto-char org-agenda-action-marker)
  7647. (org-show-context 'agenda))
  7648. (t (error "Invalid agenda action %c" ans)))))
  7649. (defun org-agenda-do-action (form &optional current-buffer)
  7650. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7651. (let ((org-overriding-default-time (org-get-cursor-date)))
  7652. (if current-buffer
  7653. (eval form)
  7654. (if (not (marker-buffer org-agenda-action-marker))
  7655. (error "No entry has been selected for agenda action")
  7656. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7657. (save-excursion
  7658. (save-restriction
  7659. (widen)
  7660. (goto-char org-agenda-action-marker)
  7661. (eval form))))))))
  7662. (defun org-agenda-clock-in (&optional arg)
  7663. "Start the clock on the currently selected item."
  7664. (interactive "P")
  7665. (org-agenda-check-no-diary)
  7666. (if (equal arg '(4))
  7667. (org-clock-in arg)
  7668. (let* ((marker (or (org-get-at-bol 'org-marker)
  7669. (org-agenda-error)))
  7670. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7671. marker))
  7672. (pos (marker-position marker))
  7673. newhead)
  7674. (org-with-remote-undo (marker-buffer marker)
  7675. (with-current-buffer (marker-buffer marker)
  7676. (widen)
  7677. (goto-char pos)
  7678. (org-show-context 'agenda)
  7679. (org-show-entry)
  7680. (org-cycle-hide-drawers 'children)
  7681. (org-clock-in arg)
  7682. (setq newhead (org-get-heading)))
  7683. (org-agenda-change-all-lines newhead hdmarker)))))
  7684. (defun org-agenda-clock-out ()
  7685. "Stop the currently running clock."
  7686. (interactive)
  7687. (unless (marker-buffer org-clock-marker)
  7688. (error "No running clock"))
  7689. (let ((marker (make-marker)) newhead)
  7690. (org-with-remote-undo (marker-buffer org-clock-marker)
  7691. (with-current-buffer (marker-buffer org-clock-marker)
  7692. (save-excursion
  7693. (save-restriction
  7694. (widen)
  7695. (goto-char org-clock-marker)
  7696. (org-back-to-heading t)
  7697. (move-marker marker (point))
  7698. (org-clock-out)
  7699. (setq newhead (org-get-heading))))))
  7700. (org-agenda-change-all-lines newhead marker)
  7701. (move-marker marker nil)))
  7702. (defun org-agenda-clock-cancel (&optional arg)
  7703. "Cancel the currently running clock."
  7704. (interactive "P")
  7705. (unless (marker-buffer org-clock-marker)
  7706. (error "No running clock"))
  7707. (org-with-remote-undo (marker-buffer org-clock-marker)
  7708. (org-clock-cancel)))
  7709. (defun org-agenda-clock-goto ()
  7710. "Jump to the currently clocked in task within the agenda.
  7711. If the currently clocked in task is not listed in the agenda
  7712. buffer, display it in another window."
  7713. (interactive)
  7714. (let (pos)
  7715. (mapc (lambda (o)
  7716. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7717. (setq pos (overlay-start o))))
  7718. (overlays-in (point-min) (point-max)))
  7719. (cond (pos (goto-char pos))
  7720. ;; If the currently clocked entry is not in the agenda
  7721. ;; buffer, we visit it in another window:
  7722. (org-clock-current-task
  7723. (org-switch-to-buffer-other-window (org-clock-goto)))
  7724. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7725. (defun org-agenda-diary-entry-in-org-file ()
  7726. "Make a diary entry in the file `org-agenda-diary-file'."
  7727. (let (d1 d2 char (text "") dp1 dp2)
  7728. (if (equal (buffer-name) "*Calendar*")
  7729. (setq d1 (calendar-cursor-to-date t)
  7730. d2 (car calendar-mark-ring))
  7731. (setq dp1 (get-text-property (point-at-bol) 'day))
  7732. (unless dp1 (error "No date defined in current line"))
  7733. (setq d1 (calendar-gregorian-from-absolute dp1)
  7734. d2 (and (ignore-errors (mark))
  7735. (save-excursion
  7736. (goto-char (mark))
  7737. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7738. (calendar-gregorian-from-absolute dp2))))
  7739. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7740. (setq char (read-char-exclusive))
  7741. (cond
  7742. ((equal char ?d)
  7743. (setq text (read-string "Day entry: "))
  7744. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7745. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7746. ((equal char ?a)
  7747. (setq d1 (list (car d1) (nth 1 d1)
  7748. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7749. (nth 2 d1))))
  7750. (setq text (read-string "Anniversary (use %d to show years): "))
  7751. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7752. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7753. ((equal char ?b)
  7754. (setq text (read-string "Block entry: "))
  7755. (unless (and d1 d2 (not (equal d1 d2)))
  7756. (error "No block of days selected"))
  7757. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7758. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7759. ((equal char ?j)
  7760. (org-switch-to-buffer-other-window
  7761. (find-file-noselect org-agenda-diary-file))
  7762. (require 'org-datetree)
  7763. (org-datetree-find-date-create d1)
  7764. (org-reveal t))
  7765. (t (error "Invalid selection character `%c'" char)))))
  7766. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7767. "Where in `org-agenda-diary-file' should new entries be added?
  7768. Valid values:
  7769. date-tree in the date tree, as child of the date
  7770. top-level as top-level entries at the end of the file."
  7771. :group 'org-agenda
  7772. :type '(choice
  7773. (const :tag "in a date tree" date-tree)
  7774. (const :tag "as top level at end of file" top-level)))
  7775. (defcustom org-agenda-insert-diary-extract-time nil
  7776. "Non-nil means extract any time specification from the diary entry."
  7777. :group 'org-agenda
  7778. :version "24.1"
  7779. :type 'boolean)
  7780. (defcustom org-agenda-bulk-mark-char ">"
  7781. "A single-character string to be used as the bulk mark."
  7782. :group 'org-agenda
  7783. :version "24.1"
  7784. :type 'string)
  7785. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7786. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7787. If TEXT is not empty, it will become the headline of the new entry, and
  7788. the resulting entry will not be shown. When TEXT is empty, switch to
  7789. `org-agenda-diary-file' and let the user finish the entry there."
  7790. (let ((cw (current-window-configuration)))
  7791. (org-switch-to-buffer-other-window
  7792. (find-file-noselect org-agenda-diary-file))
  7793. (widen)
  7794. (goto-char (point-min))
  7795. (cond
  7796. ((eq type 'anniversary)
  7797. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7798. (progn
  7799. (or (org-at-heading-p t)
  7800. (progn
  7801. (outline-next-heading)
  7802. (insert "* Anniversaries\n\n")
  7803. (beginning-of-line -1)))))
  7804. (outline-next-heading)
  7805. (org-back-over-empty-lines)
  7806. (backward-char 1)
  7807. (insert "\n")
  7808. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7809. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7810. ((eq type 'day)
  7811. (let ((org-prefix-has-time t)
  7812. (org-agenda-time-leading-zero t)
  7813. fmt time time2)
  7814. (if org-agenda-insert-diary-extract-time
  7815. ;; Use org-agenda-format-item to parse text for a time-range and
  7816. ;; remove it. FIXME: This is a hack, we should refactor
  7817. ;; that function to make time extraction available separately
  7818. (setq fmt (org-agenda-format-item nil text nil nil t)
  7819. time (get-text-property 0 'time fmt)
  7820. time2 (if (> (length time) 0)
  7821. ;; split-string removes trailing ...... if
  7822. ;; no end time given. First space
  7823. ;; separates time from date.
  7824. (concat " " (car (split-string time "\\.")))
  7825. nil)
  7826. text (get-text-property 0 'txt fmt)))
  7827. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7828. (org-agenda-insert-diary-as-top-level text)
  7829. (require 'org-datetree)
  7830. (org-datetree-find-date-create d1)
  7831. (org-agenda-insert-diary-make-new-entry text))
  7832. (org-insert-time-stamp (org-time-from-absolute
  7833. (calendar-absolute-from-gregorian d1))
  7834. nil nil nil nil time2))
  7835. (end-of-line 0))
  7836. ((eq type 'block)
  7837. (if (> (calendar-absolute-from-gregorian d1)
  7838. (calendar-absolute-from-gregorian d2))
  7839. (setq d1 (prog1 d2 (setq d2 d1))))
  7840. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7841. (org-agenda-insert-diary-as-top-level text)
  7842. (require 'org-datetree)
  7843. (org-datetree-find-date-create d1)
  7844. (org-agenda-insert-diary-make-new-entry text))
  7845. (org-insert-time-stamp (org-time-from-absolute
  7846. (calendar-absolute-from-gregorian d1)))
  7847. (insert "--")
  7848. (org-insert-time-stamp (org-time-from-absolute
  7849. (calendar-absolute-from-gregorian d2)))
  7850. (end-of-line 0)))
  7851. (if (string-match "\\S-" text)
  7852. (progn
  7853. (set-window-configuration cw)
  7854. (message "%s entry added to %s"
  7855. (capitalize (symbol-name type))
  7856. (abbreviate-file-name org-agenda-diary-file)))
  7857. (org-reveal t)
  7858. (message "Please finish entry here"))))
  7859. (defun org-agenda-insert-diary-as-top-level (text)
  7860. "Make new entry as a top-level entry at the end of the file.
  7861. Add TEXT as headline, and position the cursor in the second line so that
  7862. a timestamp can be added there."
  7863. (widen)
  7864. (goto-char (point-max))
  7865. (or (bolp) (insert "\n"))
  7866. (insert "* " text "\n")
  7867. (if org-adapt-indentation (org-indent-to-column 2)))
  7868. (defun org-agenda-insert-diary-make-new-entry (text)
  7869. "Make new entry as last child of current entry.
  7870. Add TEXT as headline, and position the cursor in the second line so that
  7871. a timestamp can be added there."
  7872. (let ((org-show-following-heading t)
  7873. (org-show-siblings t)
  7874. (org-show-hierarchy-above t)
  7875. (org-show-entry-below t)
  7876. col)
  7877. (outline-next-heading)
  7878. (org-back-over-empty-lines)
  7879. (or (looking-at "[ \t]*$")
  7880. (progn (insert "\n") (backward-char 1)))
  7881. (org-insert-heading nil t)
  7882. (org-do-demote)
  7883. (setq col (current-column))
  7884. (insert text "\n")
  7885. (if org-adapt-indentation (org-indent-to-column col))
  7886. (let ((org-show-following-heading t)
  7887. (org-show-siblings t)
  7888. (org-show-hierarchy-above t)
  7889. (org-show-entry-below t))
  7890. (org-show-context))))
  7891. (defun org-agenda-diary-entry ()
  7892. "Make a diary entry, like the `i' command from the calendar.
  7893. All the standard commands work: block, weekly etc.
  7894. When `org-agenda-diary-file' points to a file,
  7895. `org-agenda-diary-entry-in-org-file' is called instead to create
  7896. entries in that Org-mode file."
  7897. (interactive)
  7898. (org-agenda-check-type t 'agenda 'timeline)
  7899. (if (not (eq org-agenda-diary-file 'diary-file))
  7900. (org-agenda-diary-entry-in-org-file)
  7901. (require 'diary-lib)
  7902. (let* ((char (progn
  7903. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7904. (read-char-exclusive)))
  7905. (cmd (cdr (assoc char
  7906. '((?d . insert-diary-entry)
  7907. (?w . insert-weekly-diary-entry)
  7908. (?m . insert-monthly-diary-entry)
  7909. (?y . insert-yearly-diary-entry)
  7910. (?a . insert-anniversary-diary-entry)
  7911. (?b . insert-block-diary-entry)
  7912. (?c . insert-cyclic-diary-entry)))))
  7913. (oldf (symbol-function 'calendar-cursor-to-date))
  7914. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7915. (point (point))
  7916. (mark (or (mark t) (point))))
  7917. (unless cmd
  7918. (error "No command associated with <%c>" char))
  7919. (unless (and (get-text-property point 'day)
  7920. (or (not (equal ?b char))
  7921. (get-text-property mark 'day)))
  7922. (error "Don't know which date to use for diary entry"))
  7923. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7924. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7925. (let ((calendar-mark-ring
  7926. (list (calendar-gregorian-from-absolute
  7927. (or (get-text-property mark 'day)
  7928. (get-text-property point 'day))))))
  7929. (unwind-protect
  7930. (progn
  7931. (fset 'calendar-cursor-to-date
  7932. (lambda (&optional error dummy)
  7933. (calendar-gregorian-from-absolute
  7934. (get-text-property point 'day))))
  7935. (call-interactively cmd))
  7936. (fset 'calendar-cursor-to-date oldf))))))
  7937. (defun org-agenda-execute-calendar-command (cmd)
  7938. "Execute a calendar command from the agenda, with the date associated to
  7939. the cursor position."
  7940. (org-agenda-check-type t 'agenda 'timeline)
  7941. (require 'diary-lib)
  7942. (unless (get-text-property (point) 'day)
  7943. (error "Don't know which date to use for calendar command"))
  7944. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7945. (point (point))
  7946. (date (calendar-gregorian-from-absolute
  7947. (get-text-property point 'day)))
  7948. ;; the following 2 vars are needed in the calendar
  7949. (displayed-month (car date))
  7950. (displayed-year (nth 2 date)))
  7951. (unwind-protect
  7952. (progn
  7953. (fset 'calendar-cursor-to-date
  7954. (lambda (&optional error dummy)
  7955. (calendar-gregorian-from-absolute
  7956. (get-text-property point 'day))))
  7957. (call-interactively cmd))
  7958. (fset 'calendar-cursor-to-date oldf))))
  7959. (defun org-agenda-phases-of-moon ()
  7960. "Display the phases of the moon for the 3 months around the cursor date."
  7961. (interactive)
  7962. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7963. (defun org-agenda-holidays ()
  7964. "Display the holidays for the 3 months around the cursor date."
  7965. (interactive)
  7966. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7967. (defvar calendar-longitude)
  7968. (defvar calendar-latitude)
  7969. (defvar calendar-location-name)
  7970. (defun org-agenda-sunrise-sunset (arg)
  7971. "Display sunrise and sunset for the cursor date.
  7972. Latitude and longitude can be specified with the variables
  7973. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7974. argument, latitude and longitude will be prompted for."
  7975. (interactive "P")
  7976. (require 'solar)
  7977. (let ((calendar-longitude (if arg nil calendar-longitude))
  7978. (calendar-latitude (if arg nil calendar-latitude))
  7979. (calendar-location-name
  7980. (if arg "the given coordinates" calendar-location-name)))
  7981. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7982. (defun org-agenda-goto-calendar ()
  7983. "Open the Emacs calendar with the date at the cursor."
  7984. (interactive)
  7985. (org-agenda-check-type t 'agenda 'timeline)
  7986. (let* ((day (or (get-text-property (point) 'day)
  7987. (error "Don't know which date to open in calendar")))
  7988. (date (calendar-gregorian-from-absolute day))
  7989. (calendar-move-hook nil)
  7990. (calendar-view-holidays-initially-flag nil)
  7991. (calendar-view-diary-initially-flag nil))
  7992. (calendar)
  7993. (calendar-goto-date date)))
  7994. ;;;###autoload
  7995. (defun org-calendar-goto-agenda ()
  7996. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7997. This is a command that has to be installed in `calendar-mode-map'."
  7998. (interactive)
  7999. (org-agenda-list nil (calendar-absolute-from-gregorian
  8000. (calendar-cursor-to-date))
  8001. nil))
  8002. (defun org-agenda-convert-date ()
  8003. (interactive)
  8004. (org-agenda-check-type t 'agenda 'timeline)
  8005. (let ((day (get-text-property (point) 'day))
  8006. date s)
  8007. (unless day
  8008. (error "Don't know which date to convert"))
  8009. (setq date (calendar-gregorian-from-absolute day))
  8010. (setq s (concat
  8011. "Gregorian: " (calendar-date-string date) "\n"
  8012. "ISO: " (calendar-iso-date-string date) "\n"
  8013. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8014. "Julian: " (calendar-julian-date-string date) "\n"
  8015. "Astron. JD: " (calendar-astro-date-string date)
  8016. " (Julian date number at noon UTC)\n"
  8017. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8018. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8019. "French: " (calendar-french-date-string date) "\n"
  8020. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8021. "Mayan: " (calendar-mayan-date-string date) "\n"
  8022. "Coptic: " (calendar-coptic-date-string date) "\n"
  8023. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8024. "Persian: " (calendar-persian-date-string date) "\n"
  8025. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8026. (with-output-to-temp-buffer "*Dates*"
  8027. (princ s))
  8028. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8029. ;;; Bulk commands
  8030. (defvar org-agenda-bulk-marked-entries nil
  8031. "List of markers that refer to marked entries in the agenda.")
  8032. (defun org-agenda-bulk-marked-p ()
  8033. (eq (get-char-property (point-at-bol) 'type)
  8034. 'org-marked-entry-overlay))
  8035. (defun org-agenda-bulk-mark (&optional arg)
  8036. "Mark the entry at point for future bulk action."
  8037. (interactive "p")
  8038. (dotimes (i (or arg 1))
  8039. (unless (org-get-at-bol 'org-agenda-diary-link)
  8040. (let* ((m (org-get-at-bol 'org-hd-marker))
  8041. ov)
  8042. (unless (org-agenda-bulk-marked-p)
  8043. (unless m (error "Nothing to mark at point"))
  8044. (push m org-agenda-bulk-marked-entries)
  8045. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8046. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8047. (org-get-todo-face "TODO")
  8048. 'evaporate)
  8049. (overlay-put ov 'type 'org-marked-entry-overlay))
  8050. (beginning-of-line 2)
  8051. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8052. (beginning-of-line 2))
  8053. (message "%d entries marked for bulk action"
  8054. (length org-agenda-bulk-marked-entries))))))
  8055. (defun org-agenda-bulk-mark-all ()
  8056. "Mark all entries for future agenda bulk action."
  8057. (interactive)
  8058. (org-agenda-bulk-mark-regexp "."))
  8059. (defun org-agenda-bulk-mark-regexp (regexp)
  8060. "Mark entries matching REGEXP for future agenda bulk action."
  8061. (interactive "sMark entries matching regexp: ")
  8062. (let ((entries-marked 0))
  8063. (save-excursion
  8064. (goto-char (point-min))
  8065. (goto-char (next-single-property-change (point) 'txt))
  8066. (while (re-search-forward regexp nil t)
  8067. (when (string-match regexp (get-text-property (point) 'txt))
  8068. (setq entries-marked (1+ entries-marked))
  8069. (call-interactively 'org-agenda-bulk-mark))))
  8070. (if (not entries-marked)
  8071. (message "No entry matching this regexp."))))
  8072. (defun org-agenda-bulk-unmark (&optional arg)
  8073. "Unmark the entry at point for future bulk action."
  8074. (interactive "P")
  8075. (if arg
  8076. (org-agenda-bulk-unmark-all)
  8077. (cond ((org-agenda-bulk-marked-p)
  8078. (org-agenda-bulk-remove-overlays
  8079. (point-at-bol) (+ 2 (point-at-bol)))
  8080. (setq org-agenda-bulk-marked-entries
  8081. (delete (org-get-at-bol 'org-hd-marker)
  8082. org-agenda-bulk-marked-entries))
  8083. (beginning-of-line 2)
  8084. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8085. (beginning-of-line 2))
  8086. (message "%d entries left marked for bulk action"
  8087. (length org-agenda-bulk-marked-entries)))
  8088. (t (message "No entry to unmark here")))))
  8089. (defun org-agenda-bulk-toggle ()
  8090. "Toggle marking the entry at point for bulk action."
  8091. (interactive)
  8092. (if (org-agenda-bulk-marked-p)
  8093. (org-agenda-bulk-unmark)
  8094. (org-agenda-bulk-mark)))
  8095. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8096. "Remove the mark overlays between BEG and END in the agenda buffer.
  8097. BEG and END default to the buffer limits.
  8098. This only removes the overlays, it does not remove the markers
  8099. from the list in `org-agenda-bulk-marked-entries'."
  8100. (interactive)
  8101. (mapc (lambda (ov)
  8102. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8103. (delete-overlay ov)))
  8104. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8105. (defun org-agenda-bulk-unmark-all ()
  8106. "Remove all marks in the agenda buffer.
  8107. This will remove the markers and the overlays."
  8108. (interactive)
  8109. (if (null org-agenda-bulk-marked-entries)
  8110. (message "No entry to unmark")
  8111. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8112. (setq org-agenda-bulk-marked-entries nil)
  8113. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8114. (defcustom org-agenda-persistent-marks nil
  8115. "Non-nil means marked items will stay marked after a bulk action.
  8116. You can interactively and temporarily toggle by typing `p' when you
  8117. are prompted for a bulk action."
  8118. :group 'org-agenda
  8119. :version "24.1"
  8120. :type 'boolean)
  8121. (defun org-agenda-bulk-action (&optional arg)
  8122. "Execute an remote-editing action on all marked entries.
  8123. The prefix arg is passed through to the command if possible."
  8124. (interactive "P")
  8125. ;; Make sure we have markers, and only valid ones
  8126. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8127. (mapc
  8128. (lambda (m)
  8129. (unless (and (markerp m)
  8130. (marker-buffer m)
  8131. (buffer-live-p (marker-buffer m))
  8132. (marker-position m))
  8133. (error "Marker %s for bulk command is invalid" m)))
  8134. org-agenda-bulk-marked-entries)
  8135. ;; Prompt for the bulk command
  8136. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8137. (message (concat msg "[r]efile [$]arch [A]rch->sib [t]odo"
  8138. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction "
  8139. (when org-agenda-bulk-custom-functions
  8140. (concat " Custom: ["
  8141. (mapconcat (lambda(f) (char-to-string (car f)))
  8142. org-agenda-bulk-custom-functions "")
  8143. "]"))))
  8144. (catch 'exit
  8145. (let* ((action (read-char-exclusive))
  8146. (org-log-refile (if org-log-refile 'time nil))
  8147. (entries (reverse org-agenda-bulk-marked-entries))
  8148. redo-at-end
  8149. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8150. (cond
  8151. ((equal action ?p)
  8152. (let ((org-agenda-persistent-marks
  8153. (not org-agenda-persistent-marks)))
  8154. (org-agenda-bulk-action)
  8155. (throw 'exit nil)))
  8156. ((equal action ?$)
  8157. (setq cmd '(org-agenda-archive)))
  8158. ((equal action ?A)
  8159. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8160. ((member action '(?r ?w))
  8161. (setq rfloc (org-refile-get-location
  8162. "Refile to"
  8163. (marker-buffer (car org-agenda-bulk-marked-entries))
  8164. org-refile-allow-creating-parent-nodes))
  8165. (if (nth 3 rfloc)
  8166. (setcar (nthcdr 3 rfloc)
  8167. (move-marker (make-marker) (nth 3 rfloc)
  8168. (or (get-file-buffer (nth 1 rfloc))
  8169. (find-buffer-visiting (nth 1 rfloc))
  8170. (error "This should not happen")))))
  8171. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8172. redo-at-end t))
  8173. ((equal action ?t)
  8174. (setq state (org-icompleting-read
  8175. "Todo state: "
  8176. (with-current-buffer (marker-buffer (car entries))
  8177. (mapcar 'list org-todo-keywords-1))))
  8178. (setq cmd `(let ((org-inhibit-blocking t)
  8179. (org-inhibit-logging 'note))
  8180. (org-agenda-todo ,state))))
  8181. ((memq action '(?- ?+))
  8182. (setq tag (org-icompleting-read
  8183. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8184. (with-current-buffer (marker-buffer (car entries))
  8185. (delq nil
  8186. (mapcar (lambda (x)
  8187. (if (stringp (car x)) x)) org-tag-alist)))))
  8188. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8189. ((memq action '(?s ?d))
  8190. (let* ((date (unless arg
  8191. (org-read-date
  8192. nil nil nil
  8193. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8194. (ans (if arg nil org-read-date-final-answer))
  8195. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8196. (setq cmd `(let* ((bound (fboundp 'read-string))
  8197. (old (and bound (symbol-function 'read-string))))
  8198. (unwind-protect
  8199. (progn
  8200. (fset 'read-string (lambda (&rest ignore) ,ans))
  8201. (eval '(,c1 arg)))
  8202. (if bound
  8203. (fset 'read-string old)
  8204. (fmakunbound 'read-string)))))))
  8205. ((equal action ?S)
  8206. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8207. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8208. (let ((days (read-number
  8209. (format "Scatter tasks across how many %sdays: "
  8210. (if arg "week" "")) 7)))
  8211. (setq cmd
  8212. `(let ((distance (1+ (random ,days))))
  8213. (if arg
  8214. (let ((dist distance)
  8215. (day-of-week
  8216. (calendar-day-of-week
  8217. (calendar-gregorian-from-absolute (org-today)))))
  8218. (dotimes (i (1+ dist))
  8219. (while (member day-of-week org-agenda-weekend-days)
  8220. (incf distance)
  8221. (incf day-of-week)
  8222. (if (= day-of-week 7)
  8223. (setq day-of-week 0)))
  8224. (incf day-of-week)
  8225. (if (= day-of-week 7)
  8226. (setq day-of-week 0)))))
  8227. ;; silently fail when try to replan a sexp entry
  8228. (condition-case nil
  8229. (let* ((date (calendar-gregorian-from-absolute
  8230. (+ (org-today) distance)))
  8231. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8232. (nth 2 date))))
  8233. (org-agenda-schedule nil time))
  8234. (error nil)))))))
  8235. ((assoc action org-agenda-bulk-custom-functions)
  8236. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8237. redo-at-end t))
  8238. ((equal action ?f)
  8239. (setq cmd (list (intern
  8240. (org-icompleting-read "Function: "
  8241. obarray 'fboundp t nil nil)))))
  8242. (t (error "Invalid bulk action")))
  8243. ;; Sort the markers, to make sure that parents are handled before children
  8244. (setq entries (sort entries
  8245. (lambda (a b)
  8246. (cond
  8247. ((equal (marker-buffer a) (marker-buffer b))
  8248. (< (marker-position a) (marker-position b)))
  8249. (t
  8250. (string< (buffer-name (marker-buffer a))
  8251. (buffer-name (marker-buffer b))))))))
  8252. ;; Now loop over all markers and apply cmd
  8253. (while (setq e (pop entries))
  8254. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8255. (if (not pos)
  8256. (progn (message "Skipping removed entry at %s" e)
  8257. (setq cntskip (1+ cntskip)))
  8258. (goto-char pos)
  8259. (let (org-loop-over-headlines-in-active-region)
  8260. (eval cmd))
  8261. (when (not org-agenda-persistent-marks)
  8262. (setq org-agenda-bulk-marked-entries
  8263. (delete e org-agenda-bulk-marked-entries)))
  8264. (setq cnt (1+ cnt))))
  8265. (when (not org-agenda-persistent-marks)
  8266. (org-agenda-bulk-unmark-all))
  8267. (when redo-at-end (org-agenda-redo))
  8268. (message "Acted on %d entries%s%s"
  8269. cnt
  8270. (if (= cntskip 0)
  8271. ""
  8272. (format ", skipped %d (disappeared before their turn)"
  8273. cntskip))
  8274. (if (not org-agenda-persistent-marks)
  8275. "" " (kept marked)"))))))
  8276. ;;; Flagging notes
  8277. (defun org-agenda-show-the-flagging-note ()
  8278. "Display the flagging note in the other window.
  8279. When called a second time in direct sequence, offer to remove the FLAGGING
  8280. tag and (if present) the flagging note."
  8281. (interactive)
  8282. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8283. (win (selected-window))
  8284. note heading newhead)
  8285. (unless hdmarker
  8286. (error "No linked entry at point"))
  8287. (if (and (eq this-command last-command)
  8288. (y-or-n-p "Unflag and remove any flagging note? "))
  8289. (progn
  8290. (org-agenda-remove-flag hdmarker)
  8291. (let ((win (get-buffer-window "*Flagging Note*")))
  8292. (and win (delete-window win)))
  8293. (message "Entry unflagged"))
  8294. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8295. (unless note
  8296. (error "No flagging note"))
  8297. (org-kill-new note)
  8298. (org-switch-to-buffer-other-window "*Flagging Note*")
  8299. (erase-buffer)
  8300. (insert note)
  8301. (goto-char (point-min))
  8302. (while (re-search-forward "\\\\n" nil t)
  8303. (replace-match "\n" t t))
  8304. (goto-char (point-min))
  8305. (select-window win)
  8306. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8307. (defun org-agenda-remove-flag (marker)
  8308. "Remove the FLAGGED tag and any flagging note in the entry."
  8309. (let (newhead)
  8310. (org-with-point-at marker
  8311. (org-toggle-tag "FLAGGED" 'off)
  8312. (org-entry-delete nil "THEFLAGGINGNOTE")
  8313. (setq newhead (org-get-heading)))
  8314. (org-agenda-change-all-lines newhead marker)
  8315. (message "Entry unflagged")))
  8316. (defun org-agenda-get-any-marker (&optional pos)
  8317. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8318. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8319. ;;; Appointment reminders
  8320. (defvar appt-time-msg-list)
  8321. ;;;###autoload
  8322. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8323. "Activate appointments found in `org-agenda-files'.
  8324. With a \\[universal-argument] prefix, refresh the list of
  8325. appointments.
  8326. If FILTER is t, interactively prompt the user for a regular
  8327. expression, and filter out entries that don't match it.
  8328. If FILTER is a string, use this string as a regular expression
  8329. for filtering entries out.
  8330. If FILTER is a function, filter out entries against which
  8331. calling the function returns nil. This function takes one
  8332. argument: an entry from `org-agenda-get-day-entries'.
  8333. FILTER can also be an alist with the car of each cell being
  8334. either 'headline or 'category. For example:
  8335. '((headline \"IMPORTANT\")
  8336. (category \"Work\"))
  8337. will only add headlines containing IMPORTANT or headlines
  8338. belonging to the \"Work\" category.
  8339. ARGS are symbols indicating what kind of entries to consider.
  8340. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8341. and :timestamp entries. See the docstring of `org-diary' for
  8342. details and examples."
  8343. (interactive "P")
  8344. (if refresh (setq appt-time-msg-list nil))
  8345. (if (eq filter t)
  8346. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8347. (let* ((cnt 0) ; count added events
  8348. (scope (or args '(:deadline :scheduled :timestamp)))
  8349. (org-agenda-new-buffers nil)
  8350. (org-deadline-warning-days 0)
  8351. ;; Do not use `org-today' here because appt only takes
  8352. ;; time and without date as argument, so it may pass wrong
  8353. ;; information otherwise
  8354. (today (org-date-to-gregorian
  8355. (time-to-days (current-time))))
  8356. (org-agenda-restrict nil)
  8357. (files (org-agenda-files 'unrestricted)) entries file
  8358. (org-agenda-buffer nil))
  8359. ;; Get all entries which may contain an appt
  8360. (org-prepare-agenda-buffers files)
  8361. (while (setq file (pop files))
  8362. (setq entries
  8363. (delq nil
  8364. (append entries
  8365. (apply 'org-agenda-get-day-entries
  8366. file today scope)))))
  8367. ;; Map thru entries and find if we should filter them out
  8368. (mapc
  8369. (lambda(x)
  8370. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8371. (cat (get-text-property 1 'org-category x))
  8372. (tod (get-text-property 1 'time-of-day x))
  8373. (ok (or (null filter)
  8374. (and (stringp filter) (string-match filter evt))
  8375. (and (functionp filter) (funcall filter x))
  8376. (and (listp filter)
  8377. (let ((cat-filter (cadr (assoc 'category filter)))
  8378. (evt-filter (cadr (assoc 'headline filter))))
  8379. (or (and (stringp cat-filter)
  8380. (string-match cat-filter cat))
  8381. (and (stringp evt-filter)
  8382. (string-match evt-filter evt))))))))
  8383. ;; FIXME: Shall we remove text-properties for the appt text?
  8384. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8385. (when (and ok tod)
  8386. (setq tod (concat "00" (number-to-string tod))
  8387. tod (when (string-match
  8388. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8389. (concat (match-string 1 tod) ":"
  8390. (match-string 2 tod))))
  8391. (appt-add tod evt)
  8392. (setq cnt (1+ cnt))))) entries)
  8393. (org-release-buffers org-agenda-new-buffers)
  8394. (if (eq cnt 0)
  8395. (message "No event to add")
  8396. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8397. (defun org-agenda-todayp (date)
  8398. "Does DATE mean today, when considering `org-extend-today-until'?"
  8399. (let ((today (org-today))
  8400. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8401. date)))
  8402. (eq date today)))
  8403. (defun org-agenda-todo-yesterday (&optional arg)
  8404. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8405. (interactive "P")
  8406. (let* ((hour (third (decode-time
  8407. (org-current-time))))
  8408. (org-extend-today-until (1+ hour)))
  8409. (org-agenda-todo arg)))
  8410. (provide 'org-agenda)
  8411. ;;; org-agenda.el ends here