org-agenda.el 303 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 7.3
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl))
  29. (declare-function diary-add-to-list "diary-lib"
  30. (date string specifier &optional marker globcolor literal))
  31. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  32. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  33. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  34. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  35. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  36. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-french-date-string "cal-french" (&optional date))
  38. (declare-function calendar-goto-date "cal-move" (date))
  39. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  40. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  41. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  42. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  43. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  44. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  45. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  46. (declare-function org-datetree-find-date-create "org-datetree"
  47. (date &optional keep-restriction))
  48. (declare-function org-columns-quit "org-colview" ())
  49. (declare-function diary-date-display-form "diary-lib" (&optional type))
  50. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  51. (declare-function org-habit-insert-consistency-graphs
  52. "org-habit" (&optional line))
  53. (declare-function org-is-habit-p "org-habit" (&optional pom))
  54. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  55. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  56. (defvar calendar-mode-map)
  57. (defvar org-clock-current-task) ; defined in org-clock.el
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  128. and `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defcustom org-agenda-persistent-filter nil
  176. "When set, keep filters from one agenda view to the next."
  177. :group 'org-agenda
  178. :type 'boolean)
  179. (defgroup org-agenda-custom-commands nil
  180. "Options concerning agenda views in Org-mode."
  181. :tag "Org Agenda Custom Commands"
  182. :group 'org-agenda)
  183. (defconst org-sorting-choice
  184. '(choice
  185. (const time-up) (const time-down)
  186. (const category-keep) (const category-up) (const category-down)
  187. (const tag-down) (const tag-up)
  188. (const priority-up) (const priority-down)
  189. (const todo-state-up) (const todo-state-down)
  190. (const effort-up) (const effort-down)
  191. (const habit-up) (const habit-down)
  192. (const alpha-up) (const alpha-down)
  193. (const user-defined-up) (const user-defined-down))
  194. "Sorting choices.")
  195. (defconst org-agenda-custom-commands-local-options
  196. `(repeat :tag "Local settings for this command. Remember to quote values"
  197. (choice :tag "Setting"
  198. (list :tag "Heading for this block"
  199. (const org-agenda-overriding-header)
  200. (string :tag "Headline"))
  201. (list :tag "Files to be searched"
  202. (const org-agenda-files)
  203. (list
  204. (const :format "" quote)
  205. (repeat (file))))
  206. (list :tag "Sorting strategy"
  207. (const org-agenda-sorting-strategy)
  208. (list
  209. (const :format "" quote)
  210. (repeat
  211. ,org-sorting-choice)))
  212. (list :tag "Prefix format"
  213. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  214. (string))
  215. (list :tag "Number of days in agenda"
  216. (const org-agenda-ndays)
  217. (integer :value 1))
  218. (list :tag "Fixed starting date"
  219. (const org-agenda-start-day)
  220. (string :value "2007-11-01"))
  221. (list :tag "Start on day of week"
  222. (const org-agenda-start-on-weekday)
  223. (choice :value 1
  224. (const :tag "Today" nil)
  225. (integer :tag "Weekday No.")))
  226. (list :tag "Include data from diary"
  227. (const org-agenda-include-diary)
  228. (boolean))
  229. (list :tag "Deadline Warning days"
  230. (const org-deadline-warning-days)
  231. (integer :value 1))
  232. (list :tag "Tags filter preset"
  233. (const org-agenda-filter-preset)
  234. (list
  235. (const :format "" quote)
  236. (repeat
  237. (string :tag "+tag or -tag"))))
  238. (list :tag "Set daily/weekly entry types"
  239. (const org-agenda-entry-types)
  240. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  241. (const :deadline)
  242. (const :scheduled)
  243. (const :timestamp)
  244. (const :sexp)))
  245. (list :tag "Standard skipping condition"
  246. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  247. (const org-agenda-skip-function)
  248. (list
  249. (const :format "" quote)
  250. (list
  251. (choice
  252. :tag "Skipping range"
  253. (const :tag "Skip entry" org-agenda-skip-entry-if)
  254. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  255. (repeat :inline t :tag "Conditions for skipping"
  256. (choice
  257. :tag "Condition type"
  258. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  259. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  260. (list :tag "TODO state is" :inline t
  261. (const 'todo)
  262. (choice
  263. (const :tag "any not-done state" 'todo)
  264. (const :tag "any done state" 'done)
  265. (const :tag "any state" 'any)
  266. (list :tag "Keyword list"
  267. (const :format "" quote)
  268. (repeat (string :tag "Keyword")))))
  269. (list :tag "TODO state is not" :inline t
  270. (const 'nottodo)
  271. (choice
  272. (const :tag "any not-done state" 'todo)
  273. (const :tag "any done state" 'done)
  274. (const :tag "any state" 'any)
  275. (list :tag "Keyword list"
  276. (const :format "" quote)
  277. (repeat (string :tag "Keyword")))))
  278. (const :tag "scheduled" 'scheduled)
  279. (const :tag "not scheduled" 'notscheduled)
  280. (const :tag "deadline" 'deadline)
  281. (const :tag "no deadline" 'notdeadline)
  282. (const :tag "timestamp" 'timestamp)
  283. (const :tag "no timestamp" 'nottimestamp))))))
  284. (list :tag "Non-standard skipping condition"
  285. :value (org-agenda-skip-function)
  286. (const org-agenda-skip-function)
  287. (sexp :tag "Function or form (quoted!)"))
  288. (list :tag "Any variable"
  289. (variable :tag "Variable")
  290. (sexp :tag "Value (sexp)"))))
  291. "Selection of examples for agenda command settings.
  292. This will be spliced into the custom type of
  293. `org-agenda-custom-commands'.")
  294. (defcustom org-agenda-custom-commands nil
  295. "Custom commands for the agenda.
  296. These commands will be offered on the splash screen displayed by the
  297. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  298. (key desc type match settings files)
  299. key The key (one or more characters as a string) to be associated
  300. with the command.
  301. desc A description of the command, when omitted or nil, a default
  302. description is built using MATCH.
  303. type The command type, any of the following symbols:
  304. agenda The daily/weekly agenda.
  305. todo Entries with a specific TODO keyword, in all agenda files.
  306. search Entries containing search words entry or headline.
  307. tags Tags/Property/TODO match in all agenda files.
  308. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  309. todo-tree Sparse tree of specific TODO keyword in *current* file.
  310. tags-tree Sparse tree with all tags matches in *current* file.
  311. occur-tree Occur sparse tree for *current* file.
  312. ... A user-defined function.
  313. match What to search for:
  314. - a single keyword for TODO keyword searches
  315. - a tags match expression for tags searches
  316. - a word search expression for text searches.
  317. - a regular expression for occur searches
  318. For all other commands, this should be the empty string.
  319. settings A list of option settings, similar to that in a let form, so like
  320. this: ((opt1 val1) (opt2 val2) ...). The values will be
  321. evaluated at the moment of execution, so quote them when needed.
  322. files A list of files file to write the produced agenda buffer to
  323. with the command `org-store-agenda-views'.
  324. If a file name ends in \".html\", an HTML version of the buffer
  325. is written out. If it ends in \".ps\", a postscript version is
  326. produced. Otherwise, only the plain text is written to the file.
  327. You can also define a set of commands, to create a composite agenda buffer.
  328. In this case, an entry looks like this:
  329. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  330. where
  331. desc A description string to be displayed in the dispatcher menu.
  332. cmd An agenda command, similar to the above. However, tree commands
  333. are no allowed, but instead you can get agenda and global todo list.
  334. So valid commands for a set are:
  335. (agenda \"\" settings)
  336. (alltodo \"\" settings)
  337. (stuck \"\" settings)
  338. (todo \"match\" settings files)
  339. (search \"match\" settings files)
  340. (tags \"match\" settings files)
  341. (tags-todo \"match\" settings files)
  342. Each command can carry a list of options, and another set of options can be
  343. given for the whole set of commands. Individual command options take
  344. precedence over the general options.
  345. When using several characters as key to a command, the first characters
  346. are prefix commands. For the dispatcher to display useful information, you
  347. should provide a description for the prefix, like
  348. (setq org-agenda-custom-commands
  349. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  350. (\"hl\" tags \"+HOME+Lisa\")
  351. (\"hp\" tags \"+HOME+Peter\")
  352. (\"hk\" tags \"+HOME+Kim\")))"
  353. :group 'org-agenda-custom-commands
  354. :type `(repeat
  355. (choice :value ("x" "Describe command here" tags "" nil)
  356. (list :tag "Single command"
  357. (string :tag "Access Key(s) ")
  358. (option (string :tag "Description"))
  359. (choice
  360. (const :tag "Agenda" agenda)
  361. (const :tag "TODO list" alltodo)
  362. (const :tag "Search words" search)
  363. (const :tag "Stuck projects" stuck)
  364. (const :tag "Tags/Property match (all agenda files)" tags)
  365. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  366. (const :tag "TODO keyword search (all agenda files)" todo)
  367. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  368. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  369. (const :tag "Occur tree (current buffer)" occur-tree)
  370. (sexp :tag "Other, user-defined function"))
  371. (string :tag "Match (only for some commands)")
  372. ,org-agenda-custom-commands-local-options
  373. (option (repeat :tag "Export" (file :tag "Export to"))))
  374. (list :tag "Command series, all agenda files"
  375. (string :tag "Access Key(s)")
  376. (string :tag "Description ")
  377. (repeat :tag "Component"
  378. (choice
  379. (list :tag "Agenda"
  380. (const :format "" agenda)
  381. (const :tag "" :format "" "")
  382. ,org-agenda-custom-commands-local-options)
  383. (list :tag "TODO list (all keywords)"
  384. (const :format "" alltodo)
  385. (const :tag "" :format "" "")
  386. ,org-agenda-custom-commands-local-options)
  387. (list :tag "Search words"
  388. (const :format "" search)
  389. (string :tag "Match")
  390. ,org-agenda-custom-commands-local-options)
  391. (list :tag "Stuck projects"
  392. (const :format "" stuck)
  393. (const :tag "" :format "" "")
  394. ,org-agenda-custom-commands-local-options)
  395. (list :tag "Tags search"
  396. (const :format "" tags)
  397. (string :tag "Match")
  398. ,org-agenda-custom-commands-local-options)
  399. (list :tag "Tags search, TODO entries only"
  400. (const :format "" tags-todo)
  401. (string :tag "Match")
  402. ,org-agenda-custom-commands-local-options)
  403. (list :tag "TODO keyword search"
  404. (const :format "" todo)
  405. (string :tag "Match")
  406. ,org-agenda-custom-commands-local-options)
  407. (list :tag "Other, user-defined function"
  408. (symbol :tag "function")
  409. (string :tag "Match")
  410. ,org-agenda-custom-commands-local-options)))
  411. (repeat :tag "Settings for entire command set"
  412. (list (variable :tag "Any variable")
  413. (sexp :tag "Value")))
  414. (option (repeat :tag "Export" (file :tag "Export to"))))
  415. (cons :tag "Prefix key documentation"
  416. (string :tag "Access Key(s)")
  417. (string :tag "Description ")))))
  418. (defcustom org-agenda-query-register ?o
  419. "The register holding the current query string.
  420. The purpose of this is that if you construct a query string interactively,
  421. you can then use it to define a custom command."
  422. :group 'org-agenda-custom-commands
  423. :type 'character)
  424. (defcustom org-stuck-projects
  425. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  426. "How to identify stuck projects.
  427. This is a list of four items:
  428. 1. A tags/todo/property matcher string that is used to identify a project.
  429. See the manual for a description of tag and property searches.
  430. The entire tree below a headline matched by this is considered one project.
  431. 2. A list of TODO keywords identifying non-stuck projects.
  432. If the project subtree contains any headline with one of these todo
  433. keywords, the project is considered to be not stuck. If you specify
  434. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  435. 3. A list of tags identifying non-stuck projects.
  436. If the project subtree contains any headline with one of these tags,
  437. the project is considered to be not stuck. If you specify \"*\" as
  438. a tag, any tag will mark the project unstuck. Note that this is about
  439. the explicit presence of a tag somewhere in the subtree, inherited
  440. tags to not count here. If inherited tags make a project not stuck,
  441. use \"-TAG\" in the tags part of the matcher under (1.) above.
  442. 4. An arbitrary regular expression matching non-stuck projects.
  443. If the project turns out to be not stuck, search continues also in the
  444. subtree to see if any of the subtasks have project status.
  445. See also the variable `org-tags-match-list-sublevels' which applies
  446. to projects matched by this search as well.
  447. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  448. or `C-c a #' to produce the list."
  449. :group 'org-agenda-custom-commands
  450. :type '(list
  451. (string :tag "Tags/TODO match to identify a project")
  452. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  453. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  454. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  455. (defcustom org-agenda-filter-effort-default-operator "<"
  456. "The default operator for effort estimate filtering.
  457. If you select an effort estimate limit without first pressing an operator,
  458. this one will be used."
  459. :group 'org-agenda-custom-commands
  460. :type '(choice (const :tag "less or equal" "<")
  461. (const :tag "greater or equal"">")
  462. (const :tag "equal" "=")))
  463. (defgroup org-agenda-skip nil
  464. "Options concerning skipping parts of agenda files."
  465. :tag "Org Agenda Skip"
  466. :group 'org-agenda)
  467. (defgroup org-agenda-daily/weekly nil
  468. "Options concerning the daily/weekly agenda."
  469. :tag "Org Agenda Daily/Weekly"
  470. :group 'org-agenda)
  471. (defgroup org-agenda-todo-list nil
  472. "Options concerning the global todo list agenda view."
  473. :tag "Org Agenda Todo List"
  474. :group 'org-agenda)
  475. (defgroup org-agenda-match-view nil
  476. "Options concerning the general tags/property/todo match agenda view."
  477. :tag "Org Agenda Match View"
  478. :group 'org-agenda)
  479. (defgroup org-agenda-search-view nil
  480. "Options concerning the general tags/property/todo match agenda view."
  481. :tag "Org Agenda Match View"
  482. :group 'org-agenda)
  483. (defvar org-agenda-archives-mode nil
  484. "Non-nil means the agenda will include archived items.
  485. If this is the symbol `trees', trees in the selected agenda scope
  486. that are marked with the ARCHIVE tag will be included anyway. When this is
  487. t, also all archive files associated with the current selection of agenda
  488. files will be included.")
  489. (defcustom org-agenda-skip-comment-trees t
  490. "Non-nil means skip trees that start with the COMMENT keyword.
  491. When nil, these trees are also scanned by agenda commands."
  492. :group 'org-agenda-skip
  493. :type 'boolean)
  494. (defcustom org-agenda-todo-list-sublevels t
  495. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  496. When nil, the sublevels of a TODO entry are not checked, resulting in
  497. potentially much shorter TODO lists."
  498. :group 'org-agenda-skip
  499. :group 'org-agenda-todo-list
  500. :type 'boolean)
  501. (defcustom org-agenda-todo-ignore-with-date nil
  502. "Non-nil means don't show entries with a date in the global todo list.
  503. You can use this if you prefer to mark mere appointments with a TODO keyword,
  504. but don't want them to show up in the TODO list.
  505. When this is set, it also covers deadlines and scheduled items, the settings
  506. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  507. will be ignored.
  508. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  509. :group 'org-agenda-skip
  510. :group 'org-agenda-todo-list
  511. :type 'boolean)
  512. (defcustom org-agenda-todo-ignore-scheduled nil
  513. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  514. This applies when creating the global todo list.
  515. Valid values are:
  516. past Don't show entries scheduled today or in the past.
  517. future Don't show entries scheduled in the future.
  518. The idea behind this is that by scheduling it, you don't want to
  519. think about it until the scheduled date.
  520. all Don't show any scheduled entries in the global todo list.
  521. The idea behind this is that by scheduling it, you have already
  522. \"taken care\" of this item.
  523. t Same as `all', for backward compatibility.
  524. See also `org-agenda-todo-ignore-with-date'.
  525. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  526. to make his option also apply to the tags-todo list."
  527. :group 'org-agenda-skip
  528. :group 'org-agenda-todo-list
  529. :type '(choice
  530. (const :tag "Ignore future-scheduled todos" future)
  531. (const :tag "Ignore past- or present-scheduled todos" past)
  532. (const :tag "Ignore all scheduled todos" all)
  533. (const :tag "Ignore all scheduled todos (compatibility)" t)
  534. (const :tag "Show scheduled todos" nil)))
  535. (defcustom org-agenda-todo-ignore-deadlines nil
  536. "Non-nil means ignore some deadlined TODO items when making TODO list.
  537. There are different motivations for using different values, please think
  538. carefully when configuring this variable.
  539. This applies when creating the global todo list.
  540. Valid values are:
  541. near Don't show near deadline entries. A deadline is near when it is
  542. closer than `org-deadline-warning-days' days. The idea behind this
  543. is that such items will appear in the agenda anyway.
  544. far Don't show TODO entries where a deadline has been defined, but
  545. the deadline is not near. This is useful if you don't want to
  546. use the todo list to figure out what to do now.
  547. past Don't show entries with a deadline timestamp for today or in the past.
  548. future Don't show entries with a deadline timestamp in the future, not even
  549. when they become `near' ones. Use it with caution.
  550. all Ignore all TODO entries that do have a deadline.
  551. t Same as `near', for backward compatibility.
  552. See also `org-agenda-todo-ignore-with-date'.
  553. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  554. to make his option also apply to the tags-todo list."
  555. :group 'org-agenda-skip
  556. :group 'org-agenda-todo-list
  557. :type '(choice
  558. (const :tag "Ignore near deadlines" near)
  559. (const :tag "Ignore near deadlines (compatibility)" t)
  560. (const :tag "Ignore far deadlines" far)
  561. (const :tag "Ignore all TODOs with a deadlines" all)
  562. (const :tag "Show all TODOs, even if they have a deadline" nil)))
  563. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  564. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  565. The variables
  566. `org-agenda-todo-ignore-with-date',
  567. `org-agenda-todo-ignore-scheduled'
  568. `org-agenda-todo-ignore-deadlines'
  569. make the global TODO list skip entries that have time stamps of certain
  570. kinds. If this option is set, the same options will also apply for the
  571. tags-todo search, which is the general tags/property matcher
  572. restricted to unfinished TODO entries only."
  573. :group 'org-agenda-skip
  574. :group 'org-agenda-todo-list
  575. :group 'org-agenda-match-view
  576. :type 'boolean)
  577. (defcustom org-agenda-skip-scheduled-if-done nil
  578. "Non-nil means don't show scheduled items in agenda when they are done.
  579. This is relevant for the daily/weekly agenda, not for the TODO list. And
  580. it applies only to the actual date of the scheduling. Warnings about
  581. an item with a past scheduling dates are always turned off when the item
  582. is DONE."
  583. :group 'org-agenda-skip
  584. :group 'org-agenda-daily/weekly
  585. :type 'boolean)
  586. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  587. "Non-nil means skip scheduling line if same entry shows because of deadline.
  588. In the agenda of today, an entry can show up multiple times because
  589. it is both scheduled and has a nearby deadline, and maybe a plain time
  590. stamp as well.
  591. When this variable is t, then only the deadline is shown and the fact that
  592. the entry is scheduled today or was scheduled previously is not shown.
  593. When this variable is nil, the entry will be shown several times. When
  594. the variable is the symbol `not-today', then skip scheduled previously,
  595. but not scheduled today."
  596. :group 'org-agenda-skip
  597. :group 'org-agenda-daily/weekly
  598. :type '(choice
  599. (const :tag "Never" nil)
  600. (const :tag "Always" t)
  601. (const :tag "Not when scheduled today" not-today)))
  602. (defcustom org-agenda-skip-deadline-if-done nil
  603. "Non-nil means don't show deadlines when the corresponding item is done.
  604. When nil, the deadline is still shown and should give you a happy feeling.
  605. This is relevant for the daily/weekly agenda. And it applied only to the
  606. actually date of the deadline. Warnings about approaching and past-due
  607. deadlines are always turned off when the item is DONE."
  608. :group 'org-agenda-skip
  609. :group 'org-agenda-daily/weekly
  610. :type 'boolean)
  611. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  612. "Non-nil means skip deadline prewarning when entry is also scheduled.
  613. This will apply on all days where a prewarning for the deadline would
  614. be shown, but not at the day when the entry is actually due. On that day,
  615. the deadline will be shown anyway.
  616. This variable may be set to nil, t, or a number which will then give
  617. the number of days before the actual deadline when the prewarnings
  618. should resume.
  619. This can be used in a workflow where the first showing of the deadline will
  620. trigger you to schedule it, and then you don't want to be reminded of it
  621. because you will take care of it on the day when scheduled."
  622. :group 'org-agenda-skip
  623. :group 'org-agenda-daily/weekly
  624. :type '(choice
  625. (const :tag "Alwas show prewarning" nil)
  626. (const :tag "Remove prewarning if entry is scheduled" t)
  627. (integer :tag "Restart prewarning N days before deadline")))
  628. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  629. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  630. When non-nil, after the search for timestamps has matched once in an
  631. entry, the rest of the entry will not be searched."
  632. :group 'org-agenda-skip
  633. :type 'boolean)
  634. (defcustom org-agenda-skip-timestamp-if-done nil
  635. "Non-nil means don't select item by timestamp or -range if it is DONE."
  636. :group 'org-agenda-skip
  637. :group 'org-agenda-daily/weekly
  638. :type 'boolean)
  639. (defcustom org-agenda-dim-blocked-tasks t
  640. "Non-nil means dim blocked tasks in the agenda display.
  641. This causes some overhead during agenda construction, but if you
  642. have turned on `org-enforce-todo-dependencies',
  643. `org-enforce-todo-checkbox-dependencies', or any other blocking
  644. mechanism, this will create useful feedback in the agenda.
  645. Instead of t, this variable can also have the value `invisible'.
  646. Then blocked tasks will be invisible and only become visible when
  647. they become unblocked. An exemption to this behavior is when a task is
  648. blocked because of unchecked checkboxes below it. Since checkboxes do
  649. not show up in the agenda views, making this task invisible you remove any
  650. trace from agenda views that there is something to do. Therefore, a task
  651. that is blocked because of checkboxes will never be made invisible, it
  652. will only be dimmed."
  653. :group 'org-agenda-daily/weekly
  654. :group 'org-agenda-todo-list
  655. :type '(choice
  656. (const :tag "Do not dim" nil)
  657. (const :tag "Dim to a grey face" t)
  658. (const :tag "Make invisible" invisible)))
  659. (defcustom org-timeline-show-empty-dates 3
  660. "Non-nil means `org-timeline' also shows dates without an entry.
  661. When nil, only the days which actually have entries are shown.
  662. When t, all days between the first and the last date are shown.
  663. When an integer, show also empty dates, but if there is a gap of more than
  664. N days, just insert a special line indicating the size of the gap."
  665. :group 'org-agenda-skip
  666. :type '(choice
  667. (const :tag "None" nil)
  668. (const :tag "All" t)
  669. (integer :tag "at most")))
  670. (defgroup org-agenda-startup nil
  671. "Options concerning initial settings in the Agenda in Org Mode."
  672. :tag "Org Agenda Startup"
  673. :group 'org-agenda)
  674. (defcustom org-agenda-menu-show-matcher t
  675. "Non-nil menas show the match string in the agenda dispatcher menu.
  676. When nil, the matcher string is not shown, but is put into the help-echo
  677. property so than moving the mouse over the command shows it.
  678. Setting it to nil is good if matcher strings are very long and/or if
  679. you wnat to use two-column display (see `org-agenda-menu-two-column')."
  680. :group 'org-agenda
  681. :type 'boolean)
  682. (defcustom org-agenda-menu-two-column nil
  683. "Non-nil means, use two columns to show custom commands in the dispatcher.
  684. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  685. to nil."
  686. :group 'org-agenda
  687. :type 'boolean)
  688. (defcustom org-finalize-agenda-hook nil
  689. "Hook run just before displaying an agenda buffer."
  690. :group 'org-agenda-startup
  691. :type 'hook)
  692. (defcustom org-agenda-mouse-1-follows-link nil
  693. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  694. A longer mouse click will still set point. Does not work on XEmacs.
  695. Needs to be set before org.el is loaded."
  696. :group 'org-agenda-startup
  697. :type 'boolean)
  698. (defcustom org-agenda-start-with-follow-mode nil
  699. "The initial value of follow mode in a newly created agenda window."
  700. :group 'org-agenda-startup
  701. :type 'boolean)
  702. (defcustom org-agenda-show-outline-path t
  703. "Non-nil means show outline path in echo area after line motion."
  704. :group 'org-agenda-startup
  705. :type 'boolean)
  706. (defcustom org-agenda-start-with-entry-text-mode nil
  707. "The initial value of entry-text-mode in a newly created agenda window."
  708. :group 'org-agenda-startup
  709. :type 'boolean)
  710. (defcustom org-agenda-entry-text-maxlines 5
  711. "Number of text lines to be added when `E' is pressed in the agenda.
  712. Note that this variable only used during agenda display. Add add entry text
  713. when exporting the agenda, configure the variable
  714. `org-agenda-add-entry-ext-maxlines'."
  715. :group 'org-agenda
  716. :type 'integer)
  717. (defcustom org-agenda-entry-text-exclude-regexps nil
  718. "List of regular expressions to clean up entry text.
  719. The complete matches of all regular expressions in this list will be
  720. removed from entry text before it is shown in the agenda."
  721. :group 'org-agenda
  722. :type '(repeat (regexp)))
  723. (defvar org-agenda-entry-text-cleanup-hook nil
  724. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  725. This cleanup is done in a temporary buffer, so the function may inspect and
  726. change the entire buffer.
  727. Some default stuff like drawers and scheduling/deadline dates will already
  728. have been removed when this is called, as will any matches for regular
  729. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  730. (defvar org-agenda-include-inactive-timestamps nil
  731. "Non-nil means include inactive time stamps in agenda and timeline.")
  732. (defgroup org-agenda-windows nil
  733. "Options concerning the windows used by the Agenda in Org Mode."
  734. :tag "Org Agenda Windows"
  735. :group 'org-agenda)
  736. (defcustom org-agenda-window-setup 'reorganize-frame
  737. "How the agenda buffer should be displayed.
  738. Possible values for this option are:
  739. current-window Show agenda in the current window, keeping all other windows.
  740. other-window Use `switch-to-buffer-other-window' to display agenda.
  741. reorganize-frame Show only two windows on the current frame, the current
  742. window and the agenda.
  743. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  744. Also, when exiting the agenda, kill that frame.
  745. See also the variable `org-agenda-restore-windows-after-quit'."
  746. :group 'org-agenda-windows
  747. :type '(choice
  748. (const current-window)
  749. (const other-frame)
  750. (const other-window)
  751. (const reorganize-frame)))
  752. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  753. "The min and max height of the agenda window as a fraction of frame height.
  754. The value of the variable is a cons cell with two numbers between 0 and 1.
  755. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  756. :group 'org-agenda-windows
  757. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  758. (defcustom org-agenda-restore-windows-after-quit nil
  759. "Non-nil means restore window configuration open exiting agenda.
  760. Before the window configuration is changed for displaying the agenda,
  761. the current status is recorded. When the agenda is exited with
  762. `q' or `x' and this option is set, the old state is restored. If
  763. `org-agenda-window-setup' is `other-frame', the value of this
  764. option will be ignored."
  765. :group 'org-agenda-windows
  766. :type 'boolean)
  767. (defcustom org-agenda-ndays 7
  768. "Number of days to include in overview display.
  769. Should be 1 or 7.
  770. Custom commands can set this variable in the options section."
  771. :group 'org-agenda-daily/weekly
  772. :type 'integer)
  773. (defcustom org-agenda-start-on-weekday 1
  774. "Non-nil means start the overview always on the specified weekday.
  775. 0 denotes Sunday, 1 denotes Monday etc.
  776. When nil, always start on the current day.
  777. Custom commands can set this variable in the options section."
  778. :group 'org-agenda-daily/weekly
  779. :type '(choice (const :tag "Today" nil)
  780. (integer :tag "Weekday No.")))
  781. (defcustom org-agenda-show-all-dates t
  782. "Non-nil means `org-agenda' shows every day in the selected range.
  783. When nil, only the days which actually have entries are shown."
  784. :group 'org-agenda-daily/weekly
  785. :type 'boolean)
  786. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  787. "Format string for displaying dates in the agenda.
  788. Used by the daily/weekly agenda and by the timeline. This should be
  789. a format string understood by `format-time-string', or a function returning
  790. the formatted date as a string. The function must take a single argument,
  791. a calendar-style date list like (month day year)."
  792. :group 'org-agenda-daily/weekly
  793. :type '(choice
  794. (string :tag "Format string")
  795. (function :tag "Function")))
  796. (defun org-agenda-format-date-aligned (date)
  797. "Format a date string for display in the daily/weekly agenda, or timeline.
  798. This function makes sure that dates are aligned for easy reading."
  799. (require 'cal-iso)
  800. (let* ((dayname (calendar-day-name date))
  801. (day (cadr date))
  802. (day-of-week (calendar-day-of-week date))
  803. (month (car date))
  804. (monthname (calendar-month-name month))
  805. (year (nth 2 date))
  806. (iso-week (org-days-to-iso-week
  807. (calendar-absolute-from-gregorian date)))
  808. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  809. (1- year))
  810. ((and (= month 12) (<= iso-week 1))
  811. (1+ year))
  812. (t year)))
  813. (weekstring (if (= day-of-week 1)
  814. (format " W%02d" iso-week)
  815. "")))
  816. (format "%-10s %2d %s %4d%s"
  817. dayname day monthname year weekstring)))
  818. (defcustom org-agenda-timegrid-use-ampm nil
  819. "When set, show AM/PM style timestamps on the timegrid."
  820. :group 'org-agenda
  821. :type 'boolean)
  822. (defun org-agenda-time-of-day-to-ampm (time)
  823. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  824. (let* ((hour-number (string-to-number (substring time 0 -3)))
  825. (minute (substring time -2))
  826. (ampm "am"))
  827. (cond
  828. ((equal hour-number 12)
  829. (setq ampm "pm"))
  830. ((> hour-number 12)
  831. (setq ampm "pm")
  832. (setq hour-number (- hour-number 12))))
  833. (concat
  834. (if org-agenda-time-leading-zero
  835. (format "%02d" hour-number)
  836. (format "%02s" (number-to-string hour-number)))
  837. ":" minute ampm)))
  838. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  839. "Conditionally convert TIME to AM/PM format
  840. based on `org-agenda-timegrid-use-ampm'"
  841. (if org-agenda-timegrid-use-ampm
  842. (org-agenda-time-of-day-to-ampm time)
  843. time))
  844. (defcustom org-agenda-time-leading-zero nil
  845. "Non-nil means use leading zero for military times in agenda.
  846. For example, 9:30am would become 09:30 rather than 9:30."
  847. :group 'org-agenda-daily/weekly
  848. :type 'boolean)
  849. (defcustom org-agenda-weekend-days '(6 0)
  850. "Which days are weekend?
  851. These days get the special face `org-agenda-date-weekend' in the agenda
  852. and timeline buffers."
  853. :group 'org-agenda-daily/weekly
  854. :type '(set :greedy t
  855. (const :tag "Monday" 1)
  856. (const :tag "Tuesday" 2)
  857. (const :tag "Wednesday" 3)
  858. (const :tag "Thursday" 4)
  859. (const :tag "Friday" 5)
  860. (const :tag "Saturday" 6)
  861. (const :tag "Sunday" 0)))
  862. (defcustom org-agenda-include-diary nil
  863. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  864. Custom commands can set this variable in the options section."
  865. :group 'org-agenda-daily/weekly
  866. :type 'boolean)
  867. (defcustom org-agenda-include-deadlines t
  868. "If non-nil, include entries within their deadline warning period.
  869. Custom commands can set this variable in the options section."
  870. :group 'org-agenda-daily/weekly
  871. :type 'boolean)
  872. (defcustom org-agenda-include-all-todo nil
  873. "Set means weekly/daily agenda will always contain all TODO entries.
  874. The TODO entries will be listed at the top of the agenda, before
  875. the entries for specific days.
  876. This option is deprecated, it is better to define a block agenda instead."
  877. :group 'org-agenda-daily/weekly
  878. :type 'boolean)
  879. (defcustom org-agenda-repeating-timestamp-show-all t
  880. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  881. When nil, only one occurrence is shown, either today or the
  882. nearest into the future."
  883. :group 'org-agenda-daily/weekly
  884. :type 'boolean)
  885. (defcustom org-scheduled-past-days 10000
  886. "No. of days to continue listing scheduled items that are not marked DONE.
  887. When an item is scheduled on a date, it shows up in the agenda on this
  888. day and will be listed until it is marked done for the number of days
  889. given here."
  890. :group 'org-agenda-daily/weekly
  891. :type 'integer)
  892. (defcustom org-agenda-log-mode-items '(closed clock)
  893. "List of items that should be shown in agenda log mode.
  894. This list may contain the following symbols:
  895. closed Show entries that have been closed on that day.
  896. clock Show entries that have received clocked time on that day.
  897. state Show all logged state changes.
  898. Note that instead of changing this variable, you can also press `C-u l' in
  899. the agenda to display all available LOG items temporarily."
  900. :group 'org-agenda-daily/weekly
  901. :type '(set :greedy t (const closed) (const clock) (const state)))
  902. (defcustom org-agenda-log-mode-add-notes t
  903. "Non-nil means add first line of notes to log entries in agenda views.
  904. If a log item like a state change or a clock entry is associated with
  905. notes, the first line of these notes will be added to the entry in the
  906. agenda display."
  907. :group 'org-agenda-daily/weekly
  908. :type 'boolean)
  909. (defcustom org-agenda-start-with-log-mode nil
  910. "The initial value of log-mode in a newly created agenda window."
  911. :group 'org-agenda-startup
  912. :group 'org-agenda-daily/weekly
  913. :type 'boolean)
  914. (defcustom org-agenda-start-with-clockreport-mode nil
  915. "The initial value of clockreport-mode in a newly created agenda window."
  916. :group 'org-agenda-startup
  917. :group 'org-agenda-daily/weekly
  918. :type 'boolean)
  919. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  920. "Property list with parameters for the clocktable in clockreport mode.
  921. This is the display mode that shows a clock table in the daily/weekly
  922. agenda, the properties for this dynamic block can be set here.
  923. The usual clocktable parameters are allowed here, but you cannot set
  924. the properties :name, :tstart, :tend, :block, and :scope - these will
  925. be overwritten to make sure the content accurately reflects the
  926. current display in the agenda."
  927. :group 'org-agenda-daily/weekly
  928. :type 'plist)
  929. (defcustom org-agenda-search-view-always-boolean nil
  930. "Non-nil means the search string is interpreted as individual parts.
  931. The search string for search view can either be interpreted as a phrase,
  932. or as a list of snippets that define a boolean search for a number of
  933. strings.
  934. When this is non-nil, the string will be split on whitespace, and each
  935. snippet will be searched individually, and all must match in order to
  936. select an entry. A snippet is then a single string of non-white
  937. characters, or a string in double quotes, or a regexp in {} braces.
  938. If a snippet is preceded by \"-\", the snippet must *not* match.
  939. \"+\" is syntactic sugar for positive selection. Each snippet may
  940. be found as a full word or a partial word, but see the variable
  941. `org-agenda-search-view-force-full-words'.
  942. When this is nil, search will look for the entire search phrase as one,
  943. with each space character matching any amount of whitespace, including
  944. line breaks.
  945. Even when this is nil, you can still switch to Boolean search dynamically
  946. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  947. is a regexp marked with braces like \"{abc}\", this will also switch to
  948. boolean search."
  949. :group 'org-agenda-search-view
  950. :type 'boolean)
  951. (if (fboundp 'defvaralias)
  952. (defvaralias 'org-agenda-search-view-search-words-only
  953. 'org-agenda-search-view-always-boolean))
  954. (defcustom org-agenda-search-view-force-full-words nil
  955. "Non-nil means, search words must be matches as complete words.
  956. When nil, they may also match part of a word."
  957. :group 'org-agenda-search-view
  958. :type 'boolean)
  959. (defgroup org-agenda-time-grid nil
  960. "Options concerning the time grid in the Org-mode Agenda."
  961. :tag "Org Agenda Time Grid"
  962. :group 'org-agenda)
  963. (defcustom org-agenda-search-headline-for-time t
  964. "Non-nil means search headline for a time-of-day.
  965. If the headline contains a time-of-day in one format or another, it will
  966. be used to sort the entry into the time sequence of items for a day.
  967. Some people have time stamps in the headline that refer to the creation
  968. time or so, and then this produces an unwanted side effect. If this is
  969. the case for your, use this variable to turn off searching the headline
  970. for a time."
  971. :group 'org-agenda-time-grid
  972. :type 'boolean)
  973. (defcustom org-agenda-use-time-grid t
  974. "Non-nil means show a time grid in the agenda schedule.
  975. A time grid is a set of lines for specific times (like every two hours between
  976. 8:00 and 20:00). The items scheduled for a day at specific times are
  977. sorted in between these lines.
  978. For details about when the grid will be shown, and what it will look like, see
  979. the variable `org-agenda-time-grid'."
  980. :group 'org-agenda-time-grid
  981. :type 'boolean)
  982. (defcustom org-agenda-time-grid
  983. '((daily today require-timed)
  984. "----------------"
  985. (800 1000 1200 1400 1600 1800 2000))
  986. "The settings for time grid for agenda display.
  987. This is a list of three items. The first item is again a list. It contains
  988. symbols specifying conditions when the grid should be displayed:
  989. daily if the agenda shows a single day
  990. weekly if the agenda shows an entire week
  991. today show grid on current date, independent of daily/weekly display
  992. require-timed show grid only if at least one item has a time specification
  993. The second item is a string which will be placed behind the grid time.
  994. The third item is a list of integers, indicating the times that should have
  995. a grid line."
  996. :group 'org-agenda-time-grid
  997. :type
  998. '(list
  999. (set :greedy t :tag "Grid Display Options"
  1000. (const :tag "Show grid in single day agenda display" daily)
  1001. (const :tag "Show grid in weekly agenda display" weekly)
  1002. (const :tag "Always show grid for today" today)
  1003. (const :tag "Show grid only if any timed entries are present"
  1004. require-timed)
  1005. (const :tag "Skip grid times already present in an entry"
  1006. remove-match))
  1007. (string :tag "Grid String")
  1008. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1009. (defgroup org-agenda-sorting nil
  1010. "Options concerning sorting in the Org-mode Agenda."
  1011. :tag "Org Agenda Sorting"
  1012. :group 'org-agenda)
  1013. (defcustom org-agenda-sorting-strategy
  1014. '((agenda habit-down time-up priority-down category-keep)
  1015. (todo priority-down category-keep)
  1016. (tags priority-down category-keep)
  1017. (search category-keep))
  1018. "Sorting structure for the agenda items of a single day.
  1019. This is a list of symbols which will be used in sequence to determine
  1020. if an entry should be listed before another entry. The following
  1021. symbols are recognized:
  1022. time-up Put entries with time-of-day indications first, early first
  1023. time-down Put entries with time-of-day indications first, late first
  1024. category-keep Keep the default order of categories, corresponding to the
  1025. sequence in `org-agenda-files'.
  1026. category-up Sort alphabetically by category, A-Z.
  1027. category-down Sort alphabetically by category, Z-A.
  1028. tag-up Sort alphabetically by last tag, A-Z.
  1029. tag-down Sort alphabetically by last tag, Z-A.
  1030. priority-up Sort numerically by priority, high priority last.
  1031. priority-down Sort numerically by priority, high priority first.
  1032. todo-state-up Sort by todo state, tasks that are done last.
  1033. todo-state-down Sort by todo state, tasks that are done first.
  1034. effort-up Sort numerically by estimated effort, high effort last.
  1035. effort-down Sort numerically by estimated effort, high effort first.
  1036. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1037. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1038. habit-up Put entries that are habits first
  1039. habit-down Put entries that are habits last
  1040. alpha-up Sort headlines alphabetically
  1041. alpha-down Sort headlines alphabetically, reversed
  1042. The different possibilities will be tried in sequence, and testing stops
  1043. if one comparison returns a \"not-equal\". For example, the default
  1044. '(time-up category-keep priority-down)
  1045. means: Pull out all entries having a specified time of day and sort them,
  1046. in order to make a time schedule for the current day the first thing in the
  1047. agenda listing for the day. Of the entries without a time indication, keep
  1048. the grouped in categories, don't sort the categories, but keep them in
  1049. the sequence given in `org-agenda-files'. Within each category sort by
  1050. priority.
  1051. Leaving out `category-keep' would mean that items will be sorted across
  1052. categories by priority.
  1053. Instead of a single list, this can also be a set of list for specific
  1054. contents, with a context symbol in the car of the list, any of
  1055. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1056. Custom commands can bind this variable in the options section."
  1057. :group 'org-agenda-sorting
  1058. :type `(choice
  1059. (repeat :tag "General" ,org-sorting-choice)
  1060. (list :tag "Individually"
  1061. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1062. (repeat ,org-sorting-choice))
  1063. (cons (const :tag "Strategy for TODO lists" todo)
  1064. (repeat ,org-sorting-choice))
  1065. (cons (const :tag "Strategy for Tags matches" tags)
  1066. (repeat ,org-sorting-choice))
  1067. (cons (const :tag "Strategy for search matches" search)
  1068. (repeat ,org-sorting-choice)))))
  1069. (defcustom org-agenda-cmp-user-defined nil
  1070. "A function to define the comparison `user-defined'.
  1071. This function must receive two arguments, agenda entry a and b.
  1072. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1073. the user comparison, return nil.
  1074. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1075. part of an agenda sorting strategy."
  1076. :group 'org-agenda-sorting
  1077. :type 'symbol)
  1078. (defcustom org-sort-agenda-notime-is-late t
  1079. "Non-nil means items without time are considered late.
  1080. This is only relevant for sorting. When t, items which have no explicit
  1081. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1082. do have a time. When nil, the default time is before 0:00. You can use this
  1083. option to decide if the schedule for today should come before or after timeless
  1084. agenda entries."
  1085. :group 'org-agenda-sorting
  1086. :type 'boolean)
  1087. (defcustom org-sort-agenda-noeffort-is-high t
  1088. "Non-nil means items without effort estimate are sorted as high effort.
  1089. This also applies when filtering an agenda view with respect to the
  1090. < or > effort operator. Then, tasks with no effort defined will be treated
  1091. as tasks with high effort.
  1092. When nil, such items are sorted as 0 minutes effort."
  1093. :group 'org-agenda-sorting
  1094. :type 'boolean)
  1095. (defgroup org-agenda-line-format nil
  1096. "Options concerning the entry prefix in the Org-mode agenda display."
  1097. :tag "Org Agenda Line Format"
  1098. :group 'org-agenda)
  1099. (defcustom org-agenda-prefix-format
  1100. '((agenda . " %i %-12:c%?-12t% s")
  1101. (timeline . " % s")
  1102. (todo . " %i %-12:c")
  1103. (tags . " %i %-12:c")
  1104. (search . " %i %-12:c"))
  1105. "Format specifications for the prefix of items in the agenda views.
  1106. An alist with four entries, for the different agenda types. The keys to the
  1107. sublists are `agenda', `timeline', `todo', and `tags'. The values
  1108. are format strings.
  1109. This format works similar to a printf format, with the following meaning:
  1110. %c the category of the item, \"Diary\" for entries from the diary, or
  1111. as given by the CATEGORY keyword or derived from the file name.
  1112. %i the icon category of the item, as give in
  1113. `org-agenda-category-icon-alist'.
  1114. %T the *last* tag of the item. Last because inherited tags come
  1115. first in the list.
  1116. %t the time-of-day specification if one applies to the entry, in the
  1117. format HH:MM
  1118. %s Scheduling/Deadline information, a short string
  1119. All specifiers work basically like the standard `%s' of printf, but may
  1120. contain two additional characters: A question mark just after the `%' and
  1121. a whitespace/punctuation character just before the final letter.
  1122. If the first character after `%' is a question mark, the entire field
  1123. will only be included if the corresponding value applies to the
  1124. current entry. This is useful for fields which should have fixed
  1125. width when present, but zero width when absent. For example,
  1126. \"%?-12t\" will result in a 12 character time field if a time of the
  1127. day is specified, but will completely disappear in entries which do
  1128. not contain a time.
  1129. If there is punctuation or whitespace character just before the final
  1130. format letter, this character will be appended to the field value if
  1131. the value is not empty. For example, the format \"%-12:c\" leads to
  1132. \"Diary: \" if the category is \"Diary\". If the category were be
  1133. empty, no additional colon would be inserted.
  1134. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1135. - Indent the line with two space characters
  1136. - Give the category in a 12 chars wide field, padded with whitespace on
  1137. the right (because of `-'). Append a colon if there is a category
  1138. (because of `:').
  1139. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1140. time, don't put in an empty field, just skip it (because of '?').
  1141. - Finally, put the scheduling information and append a whitespace.
  1142. As another example, if you don't want the time-of-day of entries in
  1143. the prefix, you could use:
  1144. (setq org-agenda-prefix-format \" %-11:c% s\")
  1145. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1146. `org-agenda-remove-tags'.
  1147. Custom commands can set this variable in the options section."
  1148. :type '(choice
  1149. (string :tag "General format")
  1150. (list :greedy t :tag "View dependent"
  1151. (cons (const agenda) (string :tag "Format"))
  1152. (cons (const timeline) (string :tag "Format"))
  1153. (cons (const todo) (string :tag "Format"))
  1154. (cons (const tags) (string :tag "Format"))
  1155. (cons (const search) (string :tag "Format"))))
  1156. :group 'org-agenda-line-format)
  1157. (defvar org-prefix-format-compiled nil
  1158. "The compiled version of the most recently used prefix format.
  1159. See the variable `org-agenda-prefix-format'.")
  1160. (defcustom org-agenda-todo-keyword-format "%-1s"
  1161. "Format for the TODO keyword in agenda lines.
  1162. Set this to something like \"%-12s\" if you want all TODO keywords
  1163. to occupy a fixed space in the agenda display."
  1164. :group 'org-agenda-line-format
  1165. :type 'string)
  1166. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1167. "Text preceding timerange entries in the agenda view.
  1168. This is a list with two strings. The first applies when the range
  1169. is entirely on one day. The second applies if the range spans several days.
  1170. The strings may have two \"%d\" format specifiers which will be filled
  1171. with the sequence number of the days, and the total number of days in the
  1172. range, respectively."
  1173. :group 'org-agenda-line-format
  1174. :type '(list
  1175. (string :tag "Deadline today ")
  1176. (choice :tag "Deadline relative"
  1177. (string :tag "Format string")
  1178. (function))))
  1179. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1180. "Text preceding scheduled items in the agenda view.
  1181. This is a list with two strings. The first applies when the item is
  1182. scheduled on the current day. The second applies when it has been scheduled
  1183. previously, it may contain a %d indicating that this is the nth time that
  1184. this item is scheduled, due to automatic rescheduling of unfinished items
  1185. for the following day. So this number is one larger than the number of days
  1186. that passed since this item was scheduled first."
  1187. :group 'org-agenda-line-format
  1188. :type '(list
  1189. (string :tag "Scheduled today ")
  1190. (string :tag "Scheduled previously")))
  1191. (defcustom org-agenda-inactive-leader "["
  1192. "Text preceding item pulled into the agenda by inactive time stamps.
  1193. These entries are added to the agenda when pressing \"[\"."
  1194. :group 'org-agenda-line-format
  1195. :type '(list
  1196. (string :tag "Scheduled today ")
  1197. (string :tag "Scheduled previously")))
  1198. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1199. "Text preceding deadline items in the agenda view.
  1200. This is a list with two strings. The first applies when the item has its
  1201. deadline on the current day. The second applies when it is in the past or
  1202. in the future, it may contain %d to capture how many days away the deadline
  1203. is (was)."
  1204. :group 'org-agenda-line-format
  1205. :type '(list
  1206. (string :tag "Deadline today ")
  1207. (choice :tag "Deadline relative"
  1208. (string :tag "Format string")
  1209. (function))))
  1210. (defcustom org-agenda-remove-times-when-in-prefix t
  1211. "Non-nil means remove duplicate time specifications in agenda items.
  1212. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1213. time-of-day specification in a headline or diary entry is extracted and
  1214. placed into the prefix. If this option is non-nil, the original specification
  1215. \(a timestamp or -range, or just a plain time(range) specification like
  1216. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1217. cluttered.
  1218. The option can be t or nil. It may also be the symbol `beg', indicating
  1219. that the time should only be removed when it is located at the beginning of
  1220. the headline/diary entry."
  1221. :group 'org-agenda-line-format
  1222. :type '(choice
  1223. (const :tag "Always" t)
  1224. (const :tag "Never" nil)
  1225. (const :tag "When at beginning of entry" beg)))
  1226. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1227. "Non-nil means remove time ranges specifications in agenda
  1228. items that span on several days."
  1229. :group 'org-agenda-line-format
  1230. :type 'boolean)
  1231. (defcustom org-agenda-default-appointment-duration nil
  1232. "Default duration for appointments that only have a starting time.
  1233. When nil, no duration is specified in such cases.
  1234. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1235. :group 'org-agenda-line-format
  1236. :type '(choice
  1237. (integer :tag "Minutes")
  1238. (const :tag "No default duration")))
  1239. (defcustom org-agenda-show-inherited-tags t
  1240. "Non-nil means show inherited tags in each agenda line."
  1241. :group 'org-agenda-line-format
  1242. :type 'boolean)
  1243. (defcustom org-agenda-hide-tags-regexp nil
  1244. "Regular expression used to filter away specific tags in agenda views.
  1245. This means that these tags will be present, but not be shown in the agenda
  1246. line. Secondary filtering will still work on the hidden tags.
  1247. Nil means don't hide any tags."
  1248. :group 'org-agenda-line-format
  1249. :type '(choice
  1250. (const :tag "Hide none" nil)
  1251. (string :tag "Regexp ")))
  1252. (defcustom org-agenda-remove-tags nil
  1253. "Non-nil means remove the tags from the headline copy in the agenda.
  1254. When this is the symbol `prefix', only remove tags when
  1255. `org-agenda-prefix-format' contains a `%T' specifier."
  1256. :group 'org-agenda-line-format
  1257. :type '(choice
  1258. (const :tag "Always" t)
  1259. (const :tag "Never" nil)
  1260. (const :tag "When prefix format contains %T" prefix)))
  1261. (if (fboundp 'defvaralias)
  1262. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1263. 'org-agenda-remove-tags))
  1264. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1265. "Shift tags in agenda items to this column.
  1266. If this number is positive, it specifies the column. If it is negative,
  1267. it means that the tags should be flushright to that column. For example,
  1268. -80 works well for a normal 80 character screen."
  1269. :group 'org-agenda-line-format
  1270. :type 'integer)
  1271. (if (fboundp 'defvaralias)
  1272. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1273. (defcustom org-agenda-fontify-priorities 'cookies
  1274. "Non-nil means highlight low and high priorities in agenda.
  1275. When t, the highest priority entries are bold, lowest priority italic.
  1276. However, settings in `org-priority-faces' will overrule these faces.
  1277. When this variable is the symbol `cookies', only fontify the
  1278. cookies, not the entire task.
  1279. This may also be an association list of priority faces, whose
  1280. keys are the character values of `org-highest-priority',
  1281. `org-default-priority', and `org-lowest-priority' (the default values
  1282. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1283. color as a string, or a list like `(:background \"Red\")'.
  1284. If it is a color, the variable `org-faces-easy-properties'
  1285. determines if it is a foreground or a background color."
  1286. :group 'org-agenda-line-format
  1287. :type '(choice
  1288. (const :tag "Never" nil)
  1289. (const :tag "Defaults" t)
  1290. (const :tag "Cookies only" cookies)
  1291. (repeat :tag "Specify"
  1292. (list (character :tag "Priority" :value ?A)
  1293. (choice :tag "Face "
  1294. (string :tag "Color")
  1295. (sexp :tag "Face"))))))
  1296. (defcustom org-agenda-day-face-function nil
  1297. "Function called to determine what face should be used to display a day.
  1298. The only argument passed to that function is the day. It should
  1299. returns a face, or nil if does not want to specify a face and let
  1300. the normal rules apply."
  1301. :group 'org-agenda-line-format
  1302. :type 'function)
  1303. (defcustom org-agenda-category-icon-alist nil
  1304. "Alist of category icon to be displayed in agenda views.
  1305. Each entry should have the following format:
  1306. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1307. Where CATEGORY-REGEXP is a regexp matching the categories where
  1308. the icon should be displayed.
  1309. FILE-OR-DATA either a file path or a string containing image data.
  1310. The other fields can be ommited safely if not needed:
  1311. TYPE indicates the image type.
  1312. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1313. image data.
  1314. PROPS are additional image attributes to assign to the image,
  1315. like, e.g. `:ascent center'.
  1316. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1317. If you want to set the display properties yourself, just put a
  1318. list as second element:
  1319. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1320. For example, to display a 16px horizontal space for Emacs
  1321. category, you can use:
  1322. (\"Emacs\" '(space . (:width (16))))"
  1323. :group 'org-agenda-line-format
  1324. :type '(alist :key-type (string :tag "Regexp matching category")
  1325. :value-type (choice (list :tag "Icon"
  1326. (string :tag "File or data")
  1327. (symbol :tag "Type")
  1328. (boolean :tag "Data?")
  1329. (repeat :tag "Extra image properties" :inline t symbol))
  1330. (list :tag "Display properties" sexp))))
  1331. (defgroup org-agenda-column-view nil
  1332. "Options concerning column view in the agenda."
  1333. :tag "Org Agenda Column View"
  1334. :group 'org-agenda)
  1335. (defcustom org-agenda-columns-show-summaries t
  1336. "Non-nil means show summaries for columns displayed in the agenda view."
  1337. :group 'org-agenda-column-view
  1338. :type 'boolean)
  1339. (defcustom org-agenda-columns-remove-prefix-from-item t
  1340. "Non-nil means remove the prefix from a headline for agenda column view.
  1341. The special ITEM field in the columns format contains the current line, with
  1342. all information shown in other columns (like the TODO state or a tag).
  1343. When this variable is non-nil, also the agenda prefix will be removed from
  1344. the content of the ITEM field, to make sure as much as possible of the
  1345. headline can be shown in the limited width of the field."
  1346. :group 'org-agenda
  1347. :type 'boolean)
  1348. (defcustom org-agenda-columns-compute-summary-properties t
  1349. "Non-nil means recompute all summary properties before column view.
  1350. When column view in the agenda is listing properties that have a summary
  1351. operator, it can go to all relevant buffers and recompute the summaries
  1352. there. This can mean overhead for the agenda column view, but is necessary
  1353. to have thing up to date.
  1354. As a special case, a CLOCKSUM property also makes sure that the clock
  1355. computations are current."
  1356. :group 'org-agenda-column-view
  1357. :type 'boolean)
  1358. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1359. "Non-nil means the duration of an appointment will add to day effort.
  1360. The property to which appointment durations will be added is the one given
  1361. in the option `org-effort-property'. If an appointment does not have
  1362. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1363. is not set, an appointment without end time will not contribute to the time
  1364. estimate."
  1365. :group 'org-agenda-column-view
  1366. :type 'boolean)
  1367. (defcustom org-agenda-auto-exclude-function nil
  1368. "A function called with a tag to decide if it is filtered on '/ RET'.
  1369. The sole argument to the function, which is called once for each
  1370. possible tag, is a string giving the name of the tag. The
  1371. function should return either nil if the tag should be included
  1372. as normal, or \"-<TAG>\" to exclude the tag.
  1373. Note that for the purpose of tag filtering, only the lower-case version of
  1374. all tags will be considered, so that this function will only ever see
  1375. the lower-case version of all tags."
  1376. :group 'org-agenda
  1377. :type 'function)
  1378. (eval-when-compile
  1379. (require 'cl))
  1380. (require 'org)
  1381. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1382. "Execute BODY with point at location given by `org-hd-marker' property.
  1383. If STRING is non-nil, the text property will be fetched from position 0
  1384. in that string. If STRING is nil, it will be fetched from the beginning
  1385. of the current line."
  1386. `(let ((marker (get-text-property (if string 0 (point-at-bol))
  1387. 'org-hd-marker string)))
  1388. (with-current-buffer (marker-buffer marker)
  1389. (save-excursion
  1390. (goto-char marker)
  1391. ,@body))))
  1392. (defun org-add-agenda-custom-command (entry)
  1393. "Replace or add a command in `org-agenda-custom-commands'.
  1394. This is mostly for hacking and trying a new command - once the command
  1395. works you probably want to add it to `org-agenda-custom-commands' for good."
  1396. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1397. (if ass
  1398. (setcdr ass (cdr entry))
  1399. (push entry org-agenda-custom-commands))))
  1400. ;;; Define the Org-agenda-mode
  1401. (defvar org-agenda-mode-map (make-sparse-keymap)
  1402. "Keymap for `org-agenda-mode'.")
  1403. (if (fboundp 'defvaralias)
  1404. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1405. (defvar org-agenda-menu) ; defined later in this file.
  1406. (defvar org-agenda-restrict) ; defined later in this file.
  1407. (defvar org-agenda-follow-mode nil)
  1408. (defvar org-agenda-entry-text-mode nil)
  1409. (defvar org-agenda-clockreport-mode nil)
  1410. (defvar org-agenda-show-log nil)
  1411. (defvar org-agenda-redo-command nil)
  1412. (defvar org-agenda-query-string nil)
  1413. (defvar org-agenda-mode-hook nil
  1414. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1415. (defvar org-agenda-type nil)
  1416. (defvar org-agenda-force-single-file nil)
  1417. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1418. (defun org-agenda-mode ()
  1419. "Mode for time-sorted view on action items in Org-mode files.
  1420. The following commands are available:
  1421. \\{org-agenda-mode-map}"
  1422. (interactive)
  1423. (kill-all-local-variables)
  1424. (setq org-agenda-undo-list nil
  1425. org-agenda-pending-undo-list nil
  1426. org-agenda-bulk-marked-entries nil)
  1427. (setq major-mode 'org-agenda-mode)
  1428. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1429. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1430. (setq mode-name "Org-Agenda")
  1431. (use-local-map org-agenda-mode-map)
  1432. (easy-menu-add org-agenda-menu)
  1433. (if org-startup-truncated (setq truncate-lines t))
  1434. (org-set-local 'line-move-visual nil)
  1435. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1436. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1437. ;; Make sure properties are removed when copying text
  1438. (when (boundp 'buffer-substring-filters)
  1439. (org-set-local 'buffer-substring-filters
  1440. (cons (lambda (x)
  1441. (set-text-properties 0 (length x) nil x) x)
  1442. buffer-substring-filters)))
  1443. (unless org-agenda-keep-modes
  1444. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1445. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1446. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1447. org-agenda-show-log org-agenda-start-with-log-mode))
  1448. (easy-menu-change
  1449. '("Agenda") "Agenda Files"
  1450. (append
  1451. (list
  1452. (vector
  1453. (if (get 'org-agenda-files 'org-restrict)
  1454. "Restricted to single file"
  1455. "Edit File List")
  1456. '(org-edit-agenda-file-list)
  1457. (not (get 'org-agenda-files 'org-restrict)))
  1458. "--")
  1459. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1460. (org-agenda-set-mode-name)
  1461. (apply
  1462. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1463. (list 'org-agenda-mode-hook)))
  1464. (substitute-key-definition 'undo 'org-agenda-undo
  1465. org-agenda-mode-map global-map)
  1466. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1467. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1468. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1469. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1470. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1471. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1472. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1473. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1474. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1475. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1476. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1477. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1478. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1479. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1480. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1481. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1482. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1483. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1484. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1485. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1486. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1487. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1488. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1489. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1490. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1491. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1492. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1493. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1494. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1495. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1496. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1497. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1498. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1499. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1500. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1501. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1502. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1503. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1504. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1505. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1506. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1507. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1508. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1509. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1510. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1511. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1512. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1513. (while l (org-defkey org-agenda-mode-map
  1514. (int-to-string (pop l)) 'digit-argument)))
  1515. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1516. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1517. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1518. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1519. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1520. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1521. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1522. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1523. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1524. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1525. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1526. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1527. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1528. 'org-clock-modify-effort-estimate)
  1529. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1530. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1531. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1532. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1533. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1534. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1535. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1536. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1537. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1538. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1539. (substitute-key-definition 'next-line 'org-agenda-next-line
  1540. org-agenda-mode-map global-map)
  1541. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1542. org-agenda-mode-map global-map)
  1543. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1544. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1545. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1546. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1547. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1548. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1549. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1550. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1551. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1552. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1553. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1554. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1555. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1556. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1557. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1558. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1559. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1560. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1561. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1562. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1563. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1564. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1565. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1566. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1567. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1568. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1569. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1570. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1571. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1572. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1573. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1574. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1575. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1576. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1577. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1578. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1579. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1580. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1581. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1582. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1583. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1584. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1585. (when org-agenda-mouse-1-follows-link
  1586. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1587. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1588. '("Agenda"
  1589. ("Agenda Files")
  1590. "--"
  1591. ("Agenda Dates"
  1592. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1593. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1594. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1595. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1596. "--"
  1597. ("View"
  1598. ["Day View" org-agenda-day-view
  1599. :active (org-agenda-check-type nil 'agenda)
  1600. :style radio :selected (equal org-agenda-ndays 1)
  1601. :keys "v d (or just d)"]
  1602. ["Week View" org-agenda-week-view
  1603. :active (org-agenda-check-type nil 'agenda)
  1604. :style radio :selected (equal org-agenda-ndays 7)
  1605. :keys "v w (or just w)"]
  1606. ["Month View" org-agenda-month-view
  1607. :active (org-agenda-check-type nil 'agenda)
  1608. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1609. :keys "v m"]
  1610. ["Year View" org-agenda-year-view
  1611. :active (org-agenda-check-type nil 'agenda)
  1612. :style radio :selected (member org-agenda-ndays '(365 366))
  1613. :keys "v y"]
  1614. "--"
  1615. ["Include Diary" org-agenda-toggle-diary
  1616. :style toggle :selected org-agenda-include-diary
  1617. :active (org-agenda-check-type nil 'agenda)]
  1618. ["Include Deadlines" org-agenda-toggle-deadlines
  1619. :style toggle :selected org-agenda-include-deadlines
  1620. :active (org-agenda-check-type nil 'agenda)]
  1621. ["Use Time Grid" org-agenda-toggle-time-grid
  1622. :style toggle :selected org-agenda-use-time-grid
  1623. :active (org-agenda-check-type nil 'agenda)]
  1624. "--"
  1625. ["Show clock report" org-agenda-clockreport-mode
  1626. :style toggle :selected org-agenda-clockreport-mode
  1627. :active (org-agenda-check-type nil 'agenda)]
  1628. ["Show some entry text" org-agenda-entry-text-mode
  1629. :style toggle :selected org-agenda-entry-text-mode
  1630. :active t]
  1631. "--"
  1632. ["Show Logbook entries" org-agenda-log-mode
  1633. :style toggle :selected org-agenda-show-log
  1634. :active (org-agenda-check-type nil 'agenda 'timeline)
  1635. :keys "v l (or just l)"]
  1636. ["Include archived trees" org-agenda-archives-mode
  1637. :style toggle :selected org-agenda-archives-mode :active t
  1638. :keys "v a"]
  1639. ["Include archive files" (org-agenda-archives-mode t)
  1640. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1641. :keys "v A"]
  1642. "--"
  1643. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1644. ["Write view to file" org-write-agenda t]
  1645. ["Rebuild buffer" org-agenda-redo t]
  1646. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1647. "--"
  1648. ["Show original entry" org-agenda-show t]
  1649. ["Go To (other window)" org-agenda-goto t]
  1650. ["Go To (this window)" org-agenda-switch-to t]
  1651. ["Follow Mode" org-agenda-follow-mode
  1652. :style toggle :selected org-agenda-follow-mode :active t]
  1653. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1654. "--"
  1655. ("TODO"
  1656. ["Cycle TODO" org-agenda-todo t]
  1657. ["Next TODO set" org-agenda-todo-nextset t]
  1658. ["Previous TODO set" org-agenda-todo-previousset t]
  1659. ["Add note" org-agenda-add-note t])
  1660. ("Archive/Refile/Delete"
  1661. ["Archive default" org-agenda-archive-default t]
  1662. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1663. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1664. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1665. ["Archive subtree" org-agenda-archive t]
  1666. "--"
  1667. ["Refile" org-agenda-refile t]
  1668. "--"
  1669. ["Delete subtree" org-agenda-kill t])
  1670. ("Bulk action"
  1671. ["Mark entry" org-agenda-bulk-mark t]
  1672. ["Unmark entry" org-agenda-bulk-unmark t]
  1673. ["Act on all marked" org-agenda-bulk-action t]
  1674. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1675. "--"
  1676. ("Tags and Properties"
  1677. ["Show all Tags" org-agenda-show-tags t]
  1678. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1679. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1680. "--"
  1681. ["Column View" org-columns t])
  1682. ("Deadline/Schedule"
  1683. ["Schedule" org-agenda-schedule t]
  1684. ["Set Deadline" org-agenda-deadline t]
  1685. "--"
  1686. ["Mark item" org-agenda-action :active t :keys "k m"]
  1687. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1688. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1689. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1690. "--"
  1691. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1692. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1693. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1694. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1695. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1696. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1697. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1698. ("Clock and Effort"
  1699. ["Clock in" org-agenda-clock-in t]
  1700. ["Clock out" org-agenda-clock-out t]
  1701. ["Clock cancel" org-agenda-clock-cancel t]
  1702. ["Goto running clock" org-clock-goto t]
  1703. "--"
  1704. ["Set Effort" org-agenda-set-effort t]
  1705. ["Change clocked effort" org-clock-modify-effort-estimate
  1706. (org-clock-is-active)])
  1707. ("Priority"
  1708. ["Set Priority" org-agenda-priority t]
  1709. ["Increase Priority" org-agenda-priority-up t]
  1710. ["Decrease Priority" org-agenda-priority-down t]
  1711. ["Show Priority" org-agenda-show-priority t])
  1712. ("Calendar/Diary"
  1713. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1714. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1715. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1716. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1717. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1718. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1719. "--"
  1720. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1721. "--"
  1722. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1723. "--"
  1724. ("MobileOrg"
  1725. ["Push Files and Views" org-mobile-push t]
  1726. ["Get Captured and Flagged" org-mobile-pull t]
  1727. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1728. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1729. "--"
  1730. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1731. "--"
  1732. ["Quit" org-agenda-quit t]
  1733. ["Exit and Release Buffers" org-agenda-exit t]
  1734. ))
  1735. ;;; Agenda undo
  1736. (defvar org-agenda-allow-remote-undo t
  1737. "Non-nil means allow remote undo from the agenda buffer.")
  1738. (defvar org-agenda-undo-list nil
  1739. "List of undoable operations in the agenda since last refresh.")
  1740. (defvar org-agenda-undo-has-started-in nil
  1741. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1742. (defvar org-agenda-pending-undo-list nil
  1743. "In a series of undo commands, this is the list of remaining undo items.")
  1744. (defun org-agenda-undo ()
  1745. "Undo a remote editing step in the agenda.
  1746. This undoes changes both in the agenda buffer and in the remote buffer
  1747. that have been changed along."
  1748. (interactive)
  1749. (or org-agenda-allow-remote-undo
  1750. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1751. (if (not (eq this-command last-command))
  1752. (setq org-agenda-undo-has-started-in nil
  1753. org-agenda-pending-undo-list org-agenda-undo-list))
  1754. (if (not org-agenda-pending-undo-list)
  1755. (error "No further undo information"))
  1756. (let* ((entry (pop org-agenda-pending-undo-list))
  1757. buf line cmd rembuf)
  1758. (setq cmd (pop entry) line (pop entry))
  1759. (setq rembuf (nth 2 entry))
  1760. (org-with-remote-undo rembuf
  1761. (while (bufferp (setq buf (pop entry)))
  1762. (if (pop entry)
  1763. (with-current-buffer buf
  1764. (let ((last-undo-buffer buf)
  1765. (inhibit-read-only t))
  1766. (unless (memq buf org-agenda-undo-has-started-in)
  1767. (push buf org-agenda-undo-has-started-in)
  1768. (make-local-variable 'pending-undo-list)
  1769. (undo-start))
  1770. (while (and pending-undo-list
  1771. (listp pending-undo-list)
  1772. (not (car pending-undo-list)))
  1773. (pop pending-undo-list))
  1774. (undo-more 1))))))
  1775. (org-goto-line line)
  1776. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1777. (defun org-verify-change-for-undo (l1 l2)
  1778. "Verify that a real change occurred between the undo lists L1 and L2."
  1779. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1780. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1781. (not (eq l1 l2)))
  1782. ;;; Agenda dispatch
  1783. (defvar org-agenda-restrict nil)
  1784. (defvar org-agenda-restrict-begin (make-marker))
  1785. (defvar org-agenda-restrict-end (make-marker))
  1786. (defvar org-agenda-last-dispatch-buffer nil)
  1787. (defvar org-agenda-overriding-restriction nil)
  1788. ;;;###autoload
  1789. (defun org-agenda (&optional arg keys restriction)
  1790. "Dispatch agenda commands to collect entries to the agenda buffer.
  1791. Prompts for a command to execute. Any prefix arg will be passed
  1792. on to the selected command. The default selections are:
  1793. a Call `org-agenda-list' to display the agenda for current day or week.
  1794. t Call `org-todo-list' to display the global todo list.
  1795. T Call `org-todo-list' to display the global todo list, select only
  1796. entries with a specific TODO keyword (the user gets a prompt).
  1797. m Call `org-tags-view' to display headlines with tags matching
  1798. a condition (the user is prompted for the condition).
  1799. M Like `m', but select only TODO entries, no ordinary headlines.
  1800. L Create a timeline for the current buffer.
  1801. e Export views to associated files.
  1802. s Search entries for keywords.
  1803. / Multi occur across all agenda files and also files listed
  1804. in `org-agenda-text-search-extra-files'.
  1805. < Restrict agenda commands to buffer, subtree, or region.
  1806. Press several times to get the desired effect.
  1807. > Remove a previous restriction.
  1808. # List \"stuck\" projects.
  1809. ! Configure what \"stuck\" means.
  1810. C Configure custom agenda commands.
  1811. More commands can be added by configuring the variable
  1812. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1813. searches can be pre-defined in this way.
  1814. If the current buffer is in Org-mode and visiting a file, you can also
  1815. first press `<' once to indicate that the agenda should be temporarily
  1816. \(until the next use of \\[org-agenda]) restricted to the current file.
  1817. Pressing `<' twice means to restrict to the current subtree or region
  1818. \(if active)."
  1819. (interactive "P")
  1820. (catch 'exit
  1821. (let* ((prefix-descriptions nil)
  1822. (org-agenda-window-setup (if (equal (buffer-name)
  1823. org-agenda-buffer-name)
  1824. 'current-window
  1825. org-agenda-window-setup))
  1826. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1827. (org-agenda-custom-commands
  1828. ;; normalize different versions
  1829. (delq nil
  1830. (mapcar
  1831. (lambda (x)
  1832. (cond ((stringp (cdr x))
  1833. (push x prefix-descriptions)
  1834. nil)
  1835. ((stringp (nth 1 x)) x)
  1836. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1837. (t (cons (car x) (cons "" (cdr x))))))
  1838. org-agenda-custom-commands)))
  1839. (buf (current-buffer))
  1840. (bfn (buffer-file-name (buffer-base-buffer)))
  1841. entry key type match lprops ans)
  1842. ;; Turn off restriction unless there is an overriding one,
  1843. (unless org-agenda-overriding-restriction
  1844. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1845. ;; There is a request to keep the file list in place
  1846. (put 'org-agenda-files 'org-restrict nil))
  1847. (setq org-agenda-restrict nil)
  1848. (move-marker org-agenda-restrict-begin nil)
  1849. (move-marker org-agenda-restrict-end nil))
  1850. ;; Delete old local properties
  1851. (put 'org-agenda-redo-command 'org-lprops nil)
  1852. ;; Remember where this call originated
  1853. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1854. (unless keys
  1855. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1856. keys (car ans)
  1857. restriction (cdr ans)))
  1858. ;; Establish the restriction, if any
  1859. (when (and (not org-agenda-overriding-restriction) restriction)
  1860. (put 'org-agenda-files 'org-restrict (list bfn))
  1861. (cond
  1862. ((eq restriction 'region)
  1863. (setq org-agenda-restrict t)
  1864. (move-marker org-agenda-restrict-begin (region-beginning))
  1865. (move-marker org-agenda-restrict-end (region-end)))
  1866. ((eq restriction 'subtree)
  1867. (save-excursion
  1868. (setq org-agenda-restrict t)
  1869. (org-back-to-heading t)
  1870. (move-marker org-agenda-restrict-begin (point))
  1871. (move-marker org-agenda-restrict-end
  1872. (progn (org-end-of-subtree t)))))))
  1873. ;; For example the todo list should not need it (but does...)
  1874. (cond
  1875. ((setq entry (assoc keys org-agenda-custom-commands))
  1876. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1877. (progn
  1878. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1879. lprops (nth 4 entry))
  1880. (put 'org-agenda-redo-command 'org-lprops lprops)
  1881. (cond
  1882. ((eq type 'agenda)
  1883. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1884. ((eq type 'alltodo)
  1885. (org-let lprops '(org-todo-list current-prefix-arg)))
  1886. ((eq type 'search)
  1887. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1888. ((eq type 'stuck)
  1889. (org-let lprops '(org-agenda-list-stuck-projects
  1890. current-prefix-arg)))
  1891. ((eq type 'tags)
  1892. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1893. ((eq type 'tags-todo)
  1894. (org-let lprops '(org-tags-view '(4) match)))
  1895. ((eq type 'todo)
  1896. (org-let lprops '(org-todo-list match)))
  1897. ((eq type 'tags-tree)
  1898. (org-check-for-org-mode)
  1899. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1900. ((eq type 'todo-tree)
  1901. (org-check-for-org-mode)
  1902. (org-let lprops
  1903. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1904. (regexp-quote match) "\\>"))))
  1905. ((eq type 'occur-tree)
  1906. (org-check-for-org-mode)
  1907. (org-let lprops '(org-occur match)))
  1908. ((functionp type)
  1909. (org-let lprops '(funcall type match)))
  1910. ((fboundp type)
  1911. (org-let lprops '(funcall type match)))
  1912. (t (error "Invalid custom agenda command type %s" type))))
  1913. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1914. ((equal keys "C")
  1915. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1916. (customize-variable 'org-agenda-custom-commands))
  1917. ((equal keys "a") (call-interactively 'org-agenda-list))
  1918. ((equal keys "s") (call-interactively 'org-search-view))
  1919. ((equal keys "t") (call-interactively 'org-todo-list))
  1920. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1921. ((equal keys "m") (call-interactively 'org-tags-view))
  1922. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1923. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1924. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1925. (org-add-hook
  1926. 'post-command-hook
  1927. (lambda ()
  1928. (unless (current-message)
  1929. (let* ((m (org-agenda-get-any-marker))
  1930. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1931. (when note
  1932. (message (concat
  1933. "FLAGGING-NOTE ([?] for more info): "
  1934. (org-add-props
  1935. (replace-regexp-in-string
  1936. "\\\\n" "//"
  1937. (copy-sequence note))
  1938. nil 'face 'org-warning)))))))
  1939. t t))
  1940. ((equal keys "L")
  1941. (unless (org-mode-p)
  1942. (error "This is not an Org-mode file"))
  1943. (unless restriction
  1944. (put 'org-agenda-files 'org-restrict (list bfn))
  1945. (org-call-with-arg 'org-timeline arg)))
  1946. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1947. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1948. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1949. (t (error "Invalid agenda key"))))))
  1950. (defun org-agenda-normalize-custom-commands (cmds)
  1951. (delq nil
  1952. (mapcar
  1953. (lambda (x)
  1954. (cond ((stringp (cdr x)) nil)
  1955. ((stringp (nth 1 x)) x)
  1956. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1957. (t (cons (car x) (cons "" (cdr x))))))
  1958. cmds)))
  1959. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1960. "The user interface for selecting an agenda command."
  1961. (catch 'exit
  1962. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1963. (restrict-ok (and bfn (org-mode-p)))
  1964. (region-p (org-region-active-p))
  1965. (custom org-agenda-custom-commands)
  1966. (selstring "")
  1967. restriction second-time
  1968. c entry key type match prefixes rmheader header-end custom1 desc
  1969. line lines left right n n1)
  1970. (save-window-excursion
  1971. (delete-other-windows)
  1972. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1973. (erase-buffer)
  1974. (insert (eval-when-compile
  1975. (let ((header
  1976. "
  1977. Press key for an agenda command: < Buffer, subtree/region restriction
  1978. -------------------------------- > Remove restriction
  1979. a Agenda for current week or day e Export agenda views
  1980. t List of all TODO entries T Entries with special TODO kwd
  1981. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1982. L Timeline for current buffer # List stuck projects (!=configure)
  1983. s Search for keywords C Configure custom agenda commands
  1984. / Multi-occur ? Find :FLAGGED: entries
  1985. ")
  1986. (start 0))
  1987. (while (string-match
  1988. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1989. header start)
  1990. (setq start (match-end 0))
  1991. (add-text-properties (match-beginning 2) (match-end 2)
  1992. '(face bold) header))
  1993. header)))
  1994. (setq header-end (move-marker (make-marker) (point)))
  1995. (while t
  1996. (setq custom1 custom)
  1997. (when (eq rmheader t)
  1998. (org-goto-line 1)
  1999. (re-search-forward ":" nil t)
  2000. (delete-region (match-end 0) (point-at-eol))
  2001. (forward-char 1)
  2002. (looking-at "-+")
  2003. (delete-region (match-end 0) (point-at-eol))
  2004. (move-marker header-end (match-end 0)))
  2005. (goto-char header-end)
  2006. (delete-region (point) (point-max))
  2007. ;; Produce all the lines that describe custom commands and prefixes
  2008. (setq lines nil)
  2009. (while (setq entry (pop custom1))
  2010. (setq key (car entry) desc (nth 1 entry)
  2011. type (nth 2 entry)
  2012. match (nth 3 entry))
  2013. (if (> (length key) 1)
  2014. (add-to-list 'prefixes (string-to-char key))
  2015. (setq line
  2016. (format
  2017. "%-4s%-14s"
  2018. (org-add-props (copy-sequence key)
  2019. '(face bold))
  2020. (cond
  2021. ((string-match "\\S-" desc) desc)
  2022. ((eq type 'agenda) "Agenda for current week or day")
  2023. ((eq type 'alltodo) "List of all TODO entries")
  2024. ((eq type 'search) "Word search")
  2025. ((eq type 'stuck) "List of stuck projects")
  2026. ((eq type 'todo) "TODO keyword")
  2027. ((eq type 'tags) "Tags query")
  2028. ((eq type 'tags-todo) "Tags (TODO)")
  2029. ((eq type 'tags-tree) "Tags tree")
  2030. ((eq type 'todo-tree) "TODO kwd tree")
  2031. ((eq type 'occur-tree) "Occur tree")
  2032. ((functionp type) (if (symbolp type)
  2033. (symbol-name type)
  2034. "Lambda expression"))
  2035. (t "???"))))
  2036. (if org-agenda-menu-show-matcher
  2037. (setq line
  2038. (concat line ": "
  2039. (cond
  2040. ((stringp match)
  2041. (setq match (copy-sequence match))
  2042. (org-add-props match nil 'face 'org-warning))
  2043. (match
  2044. (format "set of %d commands" (length match)))
  2045. (t ""))))
  2046. (if (org-string-nw-p match)
  2047. (add-text-properties
  2048. 0 (length line) (list 'help-echo
  2049. (concat "Matcher: "match)) line)))
  2050. (push line lines)))
  2051. (setq lines (nreverse lines))
  2052. (when prefixes
  2053. (mapc (lambda (x)
  2054. (push
  2055. (format "%s %s"
  2056. (org-add-props (char-to-string x)
  2057. nil 'face 'bold)
  2058. (or (cdr (assoc (concat selstring
  2059. (char-to-string x))
  2060. prefix-descriptions))
  2061. "Prefix key"))
  2062. lines))
  2063. prefixes))
  2064. ;; Check if we should display in two columns
  2065. (if org-agenda-menu-two-column
  2066. (progn
  2067. (setq n (length lines)
  2068. n1 (+ (/ n 2) (mod n 2))
  2069. right (nthcdr n1 lines)
  2070. left (copy-sequence lines))
  2071. (setcdr (nthcdr (1- n1) left) nil))
  2072. (setq left lines right nil))
  2073. (while left
  2074. (insert "\n" (pop left))
  2075. (when right
  2076. (if (< (current-column) 40)
  2077. (move-to-column 40 t)
  2078. (insert " "))
  2079. (insert (pop right))))
  2080. ;; Make the window the right size
  2081. (goto-char (point-min))
  2082. (if second-time
  2083. (if (not (pos-visible-in-window-p (point-max)))
  2084. (org-fit-window-to-buffer))
  2085. (setq second-time t)
  2086. (org-fit-window-to-buffer))
  2087. ;; Ask for selection
  2088. (message "Press key for agenda command%s:"
  2089. (if (or restrict-ok org-agenda-overriding-restriction)
  2090. (if org-agenda-overriding-restriction
  2091. " (restriction lock active)"
  2092. (if restriction
  2093. (format " (restricted to %s)" restriction)
  2094. " (unrestricted)"))
  2095. ""))
  2096. (setq c (read-char-exclusive))
  2097. (message "")
  2098. (cond
  2099. ((assoc (char-to-string c) custom)
  2100. (setq selstring (concat selstring (char-to-string c)))
  2101. (throw 'exit (cons selstring restriction)))
  2102. ((memq c prefixes)
  2103. (setq selstring (concat selstring (char-to-string c))
  2104. prefixes nil
  2105. rmheader (or rmheader t)
  2106. custom (delq nil (mapcar
  2107. (lambda (x)
  2108. (if (or (= (length (car x)) 1)
  2109. (/= (string-to-char (car x)) c))
  2110. nil
  2111. (cons (substring (car x) 1) (cdr x))))
  2112. custom))))
  2113. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2114. (message "Restriction is only possible in Org-mode buffers")
  2115. (ding) (sit-for 1))
  2116. ((eq c ?1)
  2117. (org-agenda-remove-restriction-lock 'noupdate)
  2118. (setq restriction 'buffer))
  2119. ((eq c ?0)
  2120. (org-agenda-remove-restriction-lock 'noupdate)
  2121. (setq restriction (if region-p 'region 'subtree)))
  2122. ((eq c ?<)
  2123. (org-agenda-remove-restriction-lock 'noupdate)
  2124. (setq restriction
  2125. (cond
  2126. ((eq restriction 'buffer)
  2127. (if region-p 'region 'subtree))
  2128. ((memq restriction '(subtree region))
  2129. nil)
  2130. (t 'buffer))))
  2131. ((eq c ?>)
  2132. (org-agenda-remove-restriction-lock 'noupdate)
  2133. (setq restriction nil))
  2134. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2135. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2136. ((and (> (length selstring) 0) (eq c ?\d))
  2137. (delete-window)
  2138. (org-agenda-get-restriction-and-command prefix-descriptions))
  2139. ((equal c ?q) (error "Abort"))
  2140. (t (error "Invalid key %c" c))))))))
  2141. (defun org-run-agenda-series (name series)
  2142. (org-let (nth 1 series) '(org-prepare-agenda name))
  2143. (let* ((org-agenda-multi t)
  2144. (redo (list 'org-run-agenda-series name (list 'quote series)))
  2145. (cmds (car series))
  2146. (gprops (nth 1 series))
  2147. match ;; The byte compiler incorrectly complains about this. Keep it!
  2148. cmd type lprops)
  2149. (while (setq cmd (pop cmds))
  2150. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2151. (cond
  2152. ((eq type 'agenda)
  2153. (org-let2 gprops lprops
  2154. '(call-interactively 'org-agenda-list)))
  2155. ((eq type 'alltodo)
  2156. (org-let2 gprops lprops
  2157. '(call-interactively 'org-todo-list)))
  2158. ((eq type 'search)
  2159. (org-let2 gprops lprops
  2160. '(org-search-view current-prefix-arg match nil)))
  2161. ((eq type 'stuck)
  2162. (org-let2 gprops lprops
  2163. '(call-interactively 'org-agenda-list-stuck-projects)))
  2164. ((eq type 'tags)
  2165. (org-let2 gprops lprops
  2166. '(org-tags-view current-prefix-arg match)))
  2167. ((eq type 'tags-todo)
  2168. (org-let2 gprops lprops
  2169. '(org-tags-view '(4) match)))
  2170. ((eq type 'todo)
  2171. (org-let2 gprops lprops
  2172. '(org-todo-list match)))
  2173. ((fboundp type)
  2174. (org-let2 gprops lprops
  2175. '(funcall type match)))
  2176. (t (error "Invalid type in command series"))))
  2177. (widen)
  2178. (setq org-agenda-redo-command redo)
  2179. (goto-char (point-min)))
  2180. (org-fit-agenda-window)
  2181. (org-let (nth 1 series) '(org-finalize-agenda)))
  2182. ;;;###autoload
  2183. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2184. "Run an agenda command in batch mode and send the result to STDOUT.
  2185. If CMD-KEY is a string of length 1, it is used as a key in
  2186. `org-agenda-custom-commands' and triggers this command. If it is a
  2187. longer string it is used as a tags/todo match string.
  2188. Parameters are alternating variable names and values that will be bound
  2189. before running the agenda command."
  2190. (let (pars)
  2191. (while parameters
  2192. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2193. (if (> (length cmd-key) 2)
  2194. (eval (list 'let (nreverse pars)
  2195. (list 'org-tags-view nil cmd-key)))
  2196. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2197. (set-buffer org-agenda-buffer-name)
  2198. (princ (org-encode-for-stdout (buffer-string)))))
  2199. ;(defun org-encode-for-stdout (string)
  2200. ; (if (fboundp 'encode-coding-string)
  2201. ; (encode-coding-string string buffer-file-coding-system)
  2202. ; string))
  2203. (defun org-encode-for-stdout (string)
  2204. string)
  2205. (defvar org-agenda-info nil)
  2206. ;;;###autoload
  2207. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2208. "Run an agenda command in batch mode and send the result to STDOUT.
  2209. If CMD-KEY is a string of length 1, it is used as a key in
  2210. `org-agenda-custom-commands' and triggers this command. If it is a
  2211. longer string it is used as a tags/todo match string.
  2212. Parameters are alternating variable names and values that will be bound
  2213. before running the agenda command.
  2214. The output gives a line for each selected agenda item. Each
  2215. item is a list of comma-separated values, like this:
  2216. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2217. category The category of the item
  2218. head The headline, without TODO kwd, TAGS and PRIORITY
  2219. type The type of the agenda entry, can be
  2220. todo selected in TODO match
  2221. tagsmatch selected in tags match
  2222. diary imported from diary
  2223. deadline a deadline on given date
  2224. scheduled scheduled on given date
  2225. timestamp entry has timestamp on given date
  2226. closed entry was closed on given date
  2227. upcoming-deadline warning about deadline
  2228. past-scheduled forwarded scheduled item
  2229. block entry has date block including g. date
  2230. todo The todo keyword, if any
  2231. tags All tags including inherited ones, separated by colons
  2232. date The relevant date, like 2007-2-14
  2233. time The time, like 15:00-16:50
  2234. extra Sting with extra planning info
  2235. priority-l The priority letter if any was given
  2236. priority-n The computed numerical priority
  2237. agenda-day The day in the agenda where this is listed"
  2238. (let (pars)
  2239. (while parameters
  2240. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2241. (push (list 'org-agenda-remove-tags t) pars)
  2242. (if (> (length cmd-key) 2)
  2243. (eval (list 'let (nreverse pars)
  2244. (list 'org-tags-view nil cmd-key)))
  2245. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2246. (set-buffer org-agenda-buffer-name)
  2247. (let* ((lines (org-split-string (buffer-string) "\n"))
  2248. line)
  2249. (while (setq line (pop lines))
  2250. (catch 'next
  2251. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2252. (setq org-agenda-info
  2253. (org-fix-agenda-info (text-properties-at 0 line)))
  2254. (princ
  2255. (org-encode-for-stdout
  2256. (mapconcat 'org-agenda-export-csv-mapper
  2257. '(org-category txt type todo tags date time extra
  2258. priority-letter priority agenda-day)
  2259. ",")))
  2260. (princ "\n"))))))
  2261. (defun org-fix-agenda-info (props)
  2262. "Make sure all properties on an agenda item have a canonical form.
  2263. This ensures the export commands can easily use it."
  2264. (let (tmp re)
  2265. (when (setq tmp (plist-get props 'tags))
  2266. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2267. (when (setq tmp (plist-get props 'date))
  2268. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2269. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2270. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2271. (setq tmp (calendar-date-string tmp)))
  2272. (setq props (plist-put props 'date tmp)))
  2273. (when (setq tmp (plist-get props 'day))
  2274. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2275. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2276. (setq tmp (calendar-date-string tmp)))
  2277. (setq props (plist-put props 'day tmp))
  2278. (setq props (plist-put props 'agenda-day tmp)))
  2279. (when (setq tmp (plist-get props 'txt))
  2280. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2281. (plist-put props 'priority-letter (match-string 1 tmp))
  2282. (setq tmp (replace-match "" t t tmp)))
  2283. (when (and (setq re (plist-get props 'org-todo-regexp))
  2284. (setq re (concat "\\`\\.*" re " ?"))
  2285. (string-match re tmp))
  2286. (plist-put props 'todo (match-string 1 tmp))
  2287. (setq tmp (replace-match "" t t tmp)))
  2288. (plist-put props 'txt tmp)))
  2289. props)
  2290. (defun org-agenda-export-csv-mapper (prop)
  2291. (let ((res (plist-get org-agenda-info prop)))
  2292. (setq res
  2293. (cond
  2294. ((not res) "")
  2295. ((stringp res) res)
  2296. (t (prin1-to-string res))))
  2297. (while (string-match "," res)
  2298. (setq res (replace-match ";" t t res)))
  2299. (org-trim res)))
  2300. ;;;###autoload
  2301. (defun org-store-agenda-views (&rest parameters)
  2302. (interactive)
  2303. (eval (list 'org-batch-store-agenda-views)))
  2304. ;; FIXME, why is this a macro?????
  2305. ;;;###autoload
  2306. (defmacro org-batch-store-agenda-views (&rest parameters)
  2307. "Run all custom agenda commands that have a file argument."
  2308. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2309. (pop-up-frames nil)
  2310. (dir default-directory)
  2311. pars cmd thiscmdkey files opts cmd-or-set)
  2312. (while parameters
  2313. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2314. (setq pars (reverse pars))
  2315. (save-window-excursion
  2316. (while cmds
  2317. (setq cmd (pop cmds)
  2318. thiscmdkey (car cmd)
  2319. cmd-or-set (nth 2 cmd)
  2320. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2321. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2322. (if (stringp files) (setq files (list files)))
  2323. (when files
  2324. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2325. (list 'org-agenda nil thiscmdkey)))
  2326. (set-buffer org-agenda-buffer-name)
  2327. (while files
  2328. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2329. (list 'org-write-agenda
  2330. (expand-file-name (pop files) dir) nil t))))
  2331. (and (get-buffer org-agenda-buffer-name)
  2332. (kill-buffer org-agenda-buffer-name)))))))
  2333. (defun org-agenda-mark-header-line (pos)
  2334. "Mark the line at POS as an agenda structure header."
  2335. (save-excursion
  2336. (goto-char pos)
  2337. (put-text-property (point-at-bol) (point-at-eol)
  2338. 'org-agenda-structural-header t)
  2339. (when org-agenda-title-append
  2340. (put-text-property (point-at-bol) (point-at-eol)
  2341. 'org-agenda-title-append org-agenda-title-append))))
  2342. (defvar org-mobile-creating-agendas)
  2343. (defun org-write-agenda (file &optional open nosettings)
  2344. "Write the current buffer (an agenda view) as a file.
  2345. Depending on the extension of the file name, plain text (.txt),
  2346. HTML (.html or .htm) or Postscript (.ps) is produced.
  2347. If the extension is .ics, run icalendar export over all files used
  2348. to construct the agenda and limit the export to entries listed in the
  2349. agenda now.
  2350. With prefix argument OPEN, open the new file immediately.
  2351. If NOSETTINGS is given, do not scope the settings of
  2352. `org-agenda-exporter-settings' into the export commands. This is used when
  2353. the settings have already been scoped and we do not wish to overrule other,
  2354. higher priority settings."
  2355. (interactive "FWrite agenda to file: \nP")
  2356. (if (not (file-writable-p file))
  2357. (error "Cannot write agenda to file %s" file))
  2358. (org-let (if nosettings nil org-agenda-exporter-settings)
  2359. '(save-excursion
  2360. (save-window-excursion
  2361. (org-agenda-mark-filtered-text)
  2362. (let ((bs (copy-sequence (buffer-string))) beg)
  2363. (org-agenda-unmark-filtered-text)
  2364. (with-temp-buffer
  2365. (rename-buffer "Agenda View" t)
  2366. (set-buffer-modified-p nil)
  2367. (insert bs)
  2368. (org-agenda-remove-marked-text 'org-filtered)
  2369. (while (setq beg (text-property-any (point-min) (point-max)
  2370. 'org-filtered t))
  2371. (delete-region
  2372. beg (or (next-single-property-change beg 'org-filtered)
  2373. (point-max))))
  2374. (run-hooks 'org-agenda-before-write-hook)
  2375. (cond
  2376. ((org-bound-and-true-p org-mobile-creating-agendas)
  2377. (org-mobile-write-agenda-for-mobile file))
  2378. ((string-match "\\.html?\\'" file)
  2379. (require 'htmlize)
  2380. (set-buffer (htmlize-buffer (current-buffer)))
  2381. (when (and org-agenda-export-html-style
  2382. (string-match "<style>" org-agenda-export-html-style))
  2383. ;; replace <style> section with org-agenda-export-html-style
  2384. (goto-char (point-min))
  2385. (kill-region (- (search-forward "<style") 6)
  2386. (search-forward "</style>"))
  2387. (insert org-agenda-export-html-style))
  2388. (write-file file)
  2389. (kill-buffer (current-buffer))
  2390. (message "HTML written to %s" file))
  2391. ((string-match "\\.ps\\'" file)
  2392. (require 'ps-print)
  2393. (ps-print-buffer-with-faces file)
  2394. (message "Postscript written to %s" file))
  2395. ((string-match "\\.pdf\\'" file)
  2396. (require 'ps-print)
  2397. (ps-print-buffer-with-faces
  2398. (concat (file-name-sans-extension file) ".ps"))
  2399. (call-process "ps2pdf" nil nil nil
  2400. (expand-file-name
  2401. (concat (file-name-sans-extension file) ".ps"))
  2402. (expand-file-name file))
  2403. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2404. (message "PDF written to %s" file))
  2405. ((string-match "\\.ics\\'" file)
  2406. (require 'org-icalendar)
  2407. (let ((org-agenda-marker-table
  2408. (org-create-marker-find-array
  2409. (org-agenda-collect-markers)))
  2410. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2411. (org-combined-agenda-icalendar-file file))
  2412. (apply 'org-export-icalendar 'combine
  2413. (org-agenda-files nil 'ifmode))))
  2414. (t
  2415. (let ((bs (buffer-string)))
  2416. (find-file file)
  2417. (erase-buffer)
  2418. (insert bs)
  2419. (save-buffer 0)
  2420. (kill-buffer (current-buffer))
  2421. (message "Plain text written to %s" file))))))))
  2422. (set-buffer org-agenda-buffer-name))
  2423. (when open (org-open-file file)))
  2424. (defvar org-agenda-filter-overlays nil)
  2425. (defun org-agenda-mark-filtered-text ()
  2426. "Mark all text hidden by filtering with a text property."
  2427. (let ((inhibit-read-only t))
  2428. (mapc
  2429. (lambda (o)
  2430. (when (equal (overlay-buffer o) (current-buffer))
  2431. (put-text-property
  2432. (overlay-start o) (overlay-end o)
  2433. 'org-filtered t)))
  2434. org-agenda-filter-overlays)))
  2435. (defun org-agenda-unmark-filtered-text ()
  2436. "Remove the filtering text property."
  2437. (let ((inhibit-read-only t))
  2438. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2439. (defun org-agenda-remove-marked-text (property &optional value)
  2440. "Delete all text marked with VALUE of PROPERTY.
  2441. VALUE defaults to t."
  2442. (let (beg)
  2443. (setq value (or value t))
  2444. (while (setq beg (text-property-any (point-min) (point-max)
  2445. property value))
  2446. (delete-region
  2447. beg (or (next-single-property-change beg 'org-filtered)
  2448. (point-max))))))
  2449. (defun org-agenda-add-entry-text ()
  2450. "Add entry text to agenda lines.
  2451. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2452. entry text following headings shown in the agenda.
  2453. Drawers will be excluded, also the line with scheduling/deadline info."
  2454. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2455. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2456. (let (m txt)
  2457. (goto-char (point-min))
  2458. (while (not (eobp))
  2459. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2460. (beginning-of-line 2)
  2461. (setq txt (org-agenda-get-some-entry-text
  2462. m org-agenda-add-entry-text-maxlines " > "))
  2463. (end-of-line 1)
  2464. (if (string-match "\\S-" txt)
  2465. (insert "\n" txt)
  2466. (or (eobp) (forward-char 1))))))))
  2467. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2468. &rest keep)
  2469. "Extract entry text from MARKER, at most N-LINES lines.
  2470. This will ignore drawers etc, just get the text.
  2471. If INDENT is given, prefix every line with this string. If KEEP is
  2472. given, it is a list of symbols, defining stuff that should not be
  2473. removed from the entry content. Currently only `planning' is allowed here."
  2474. (let (txt drawer-re kwd-time-re ind)
  2475. (save-excursion
  2476. (with-current-buffer (marker-buffer marker)
  2477. (if (not (org-mode-p))
  2478. (setq txt "")
  2479. (save-excursion
  2480. (save-restriction
  2481. (widen)
  2482. (goto-char marker)
  2483. (end-of-line 1)
  2484. (setq txt (buffer-substring
  2485. (min (1+ (point)) (point-max))
  2486. (progn (outline-next-heading) (point)))
  2487. drawer-re org-drawer-regexp
  2488. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2489. ".*\n?"))
  2490. (with-temp-buffer
  2491. (insert txt)
  2492. (when org-agenda-add-entry-text-descriptive-links
  2493. (goto-char (point-min))
  2494. (while (org-activate-bracket-links (point-max))
  2495. (add-text-properties (match-beginning 0) (match-end 0)
  2496. '(face org-link))))
  2497. (goto-char (point-min))
  2498. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2499. (set-text-properties (match-beginning 0) (match-end 0)
  2500. nil))
  2501. (goto-char (point-min))
  2502. (while (re-search-forward drawer-re nil t)
  2503. (delete-region
  2504. (match-beginning 0)
  2505. (progn (re-search-forward
  2506. "^[ \t]*:END:.*\n?" nil 'move)
  2507. (point))))
  2508. (unless (member 'planning keep)
  2509. (goto-char (point-min))
  2510. (while (re-search-forward kwd-time-re nil t)
  2511. (replace-match "")))
  2512. (goto-char (point-min))
  2513. (when org-agenda-entry-text-exclude-regexps
  2514. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2515. (while (setq re (pop re-list))
  2516. (goto-char (point-min))
  2517. (while (re-search-forward re nil t)
  2518. (replace-match "")))))
  2519. (goto-char (point-max))
  2520. (skip-chars-backward " \t\n")
  2521. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2522. ;; find and remove min common indentation
  2523. (goto-char (point-min))
  2524. (untabify (point-min) (point-max))
  2525. (setq ind (org-get-indentation))
  2526. (while (not (eobp))
  2527. (unless (looking-at "[ \t]*$")
  2528. (setq ind (min ind (org-get-indentation))))
  2529. (beginning-of-line 2))
  2530. (goto-char (point-min))
  2531. (while (not (eobp))
  2532. (unless (looking-at "[ \t]*$")
  2533. (move-to-column ind)
  2534. (delete-region (point-at-bol) (point)))
  2535. (beginning-of-line 2))
  2536. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2537. (goto-char (point-min))
  2538. (when indent
  2539. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2540. (replace-match indent t t)))
  2541. (goto-char (point-min))
  2542. (while (looking-at "[ \t]*\n") (replace-match ""))
  2543. (goto-char (point-max))
  2544. (when (> (org-current-line)
  2545. n-lines)
  2546. (org-goto-line (1+ n-lines))
  2547. (backward-char 1))
  2548. (setq txt (buffer-substring (point-min) (point)))))))))
  2549. txt))
  2550. (defun org-agenda-collect-markers ()
  2551. "Collect the markers pointing to entries in the agenda buffer."
  2552. (let (m markers)
  2553. (save-excursion
  2554. (goto-char (point-min))
  2555. (while (not (eobp))
  2556. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2557. (org-get-at-bol 'org-marker)))
  2558. (push m markers))
  2559. (beginning-of-line 2)))
  2560. (nreverse markers)))
  2561. (defun org-create-marker-find-array (marker-list)
  2562. "Create a alist of files names with all marker positions in that file."
  2563. (let (f tbl m a p)
  2564. (while (setq m (pop marker-list))
  2565. (setq p (marker-position m)
  2566. f (buffer-file-name (or (buffer-base-buffer
  2567. (marker-buffer m))
  2568. (marker-buffer m))))
  2569. (if (setq a (assoc f tbl))
  2570. (push (marker-position m) (cdr a))
  2571. (push (list f p) tbl)))
  2572. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2573. tbl)))
  2574. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2575. (defun org-check-agenda-marker-table ()
  2576. "Check of the current entry is on the marker list."
  2577. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2578. a)
  2579. (and (setq a (assoc file org-agenda-marker-table))
  2580. (save-match-data
  2581. (save-excursion
  2582. (org-back-to-heading t)
  2583. (member (point) (cdr a)))))))
  2584. (defun org-check-for-org-mode ()
  2585. "Make sure current buffer is in org-mode. Error if not."
  2586. (or (org-mode-p)
  2587. (error "Cannot execute org-mode agenda command on buffer in %s"
  2588. major-mode)))
  2589. (defun org-fit-agenda-window ()
  2590. "Fit the window to the buffer size."
  2591. (and (memq org-agenda-window-setup '(reorganize-frame))
  2592. (fboundp 'fit-window-to-buffer)
  2593. (org-fit-window-to-buffer
  2594. nil
  2595. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2596. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2597. ;;; Agenda prepare and finalize
  2598. (defvar org-agenda-multi nil) ; dynamically scoped
  2599. (defvar org-agenda-buffer-name "*Org Agenda*")
  2600. (defvar org-pre-agenda-window-conf nil)
  2601. (defvar org-agenda-columns-active nil)
  2602. (defvar org-agenda-name nil)
  2603. (defvar org-agenda-filter nil)
  2604. (defvar org-agenda-filter-while-redo nil)
  2605. (defvar org-agenda-filter-preset nil
  2606. "A preset of the tags filter used for secondary agenda filtering.
  2607. This must be a list of strings, each string must be a single tag preceded
  2608. by \"+\" or \"-\".
  2609. This variable should not be set directly, but agenda custom commands can
  2610. bind it in the options section. The preset filter is a global property of
  2611. the entire agenda view. In a block agenda, it will not work reliably to
  2612. define a filter for one of the individual blocks. You need to set it in
  2613. the global options and expect it to be applied to the entire view.")
  2614. (defun org-prepare-agenda (&optional name)
  2615. (setq org-todo-keywords-for-agenda nil)
  2616. (setq org-done-keywords-for-agenda nil)
  2617. (setq org-drawers-for-agenda nil)
  2618. (unless org-agenda-persistent-filter
  2619. (setq org-agenda-filter nil))
  2620. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2621. (if org-agenda-multi
  2622. (progn
  2623. (setq buffer-read-only nil)
  2624. (goto-char (point-max))
  2625. (unless (or (bobp) org-agenda-compact-blocks)
  2626. (insert "\n"
  2627. (if (stringp org-agenda-block-separator)
  2628. org-agenda-block-separator
  2629. (make-string (window-width) org-agenda-block-separator))
  2630. "\n"))
  2631. (narrow-to-region (point) (point-max)))
  2632. (org-agenda-reset-markers)
  2633. (setq org-agenda-contributing-files nil)
  2634. (setq org-agenda-columns-active nil)
  2635. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2636. (setq org-todo-keywords-for-agenda
  2637. (org-uniquify org-todo-keywords-for-agenda))
  2638. (setq org-done-keywords-for-agenda
  2639. (org-uniquify org-done-keywords-for-agenda))
  2640. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2641. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2642. (awin (get-buffer-window abuf)))
  2643. (cond
  2644. ((equal (current-buffer) abuf) nil)
  2645. (awin (select-window awin))
  2646. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2647. ((equal org-agenda-window-setup 'current-window)
  2648. (switch-to-buffer abuf))
  2649. ((equal org-agenda-window-setup 'other-window)
  2650. (org-switch-to-buffer-other-window abuf))
  2651. ((equal org-agenda-window-setup 'other-frame)
  2652. (switch-to-buffer-other-frame abuf))
  2653. ((equal org-agenda-window-setup 'reorganize-frame)
  2654. (delete-other-windows)
  2655. (org-switch-to-buffer-other-window abuf)))
  2656. ;; additional test in case agenda is invoked from within agenda
  2657. ;; buffer via elisp link
  2658. (unless (equal (current-buffer) abuf)
  2659. (switch-to-buffer abuf)))
  2660. (setq buffer-read-only nil)
  2661. (let ((inhibit-read-only t)) (erase-buffer))
  2662. (org-agenda-mode)
  2663. (and name (not org-agenda-name)
  2664. (org-set-local 'org-agenda-name name)))
  2665. (setq buffer-read-only nil))
  2666. (defun org-finalize-agenda ()
  2667. "Finishing touch for the agenda buffer, called just before displaying it."
  2668. (unless org-agenda-multi
  2669. (save-excursion
  2670. (let ((inhibit-read-only t))
  2671. (goto-char (point-min))
  2672. (while (org-activate-bracket-links (point-max))
  2673. (add-text-properties (match-beginning 0) (match-end 0)
  2674. '(face org-link)))
  2675. (org-agenda-align-tags)
  2676. (unless org-agenda-with-colors
  2677. (remove-text-properties (point-min) (point-max) '(face nil))))
  2678. (if (and (boundp 'org-agenda-overriding-columns-format)
  2679. org-agenda-overriding-columns-format)
  2680. (org-set-local 'org-agenda-overriding-columns-format
  2681. org-agenda-overriding-columns-format))
  2682. (if (and (boundp 'org-agenda-view-columns-initially)
  2683. org-agenda-view-columns-initially)
  2684. (org-agenda-columns))
  2685. (when org-agenda-fontify-priorities
  2686. (org-agenda-fontify-priorities))
  2687. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2688. (org-agenda-dim-blocked-tasks))
  2689. (org-agenda-mark-clocking-task)
  2690. (when org-agenda-entry-text-mode
  2691. (org-agenda-entry-text-hide)
  2692. (org-agenda-entry-text-show))
  2693. (if (functionp 'org-habit-insert-consistency-graphs)
  2694. (org-habit-insert-consistency-graphs))
  2695. (run-hooks 'org-finalize-agenda-hook)
  2696. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2697. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2698. (org-agenda-filter-apply org-agenda-filter))
  2699. )))
  2700. (defun org-agenda-mark-clocking-task ()
  2701. "Mark the current clock entry in the agenda if it is present."
  2702. (mapc (lambda (o)
  2703. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2704. (delete-overlay o)))
  2705. (overlays-in (point-min) (point-max)))
  2706. (when (marker-buffer org-clock-hd-marker)
  2707. (save-excursion
  2708. (goto-char (point-min))
  2709. (let (s ov)
  2710. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2711. (goto-char s)
  2712. (when (equal (org-get-at-bol 'org-hd-marker)
  2713. org-clock-hd-marker)
  2714. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2715. (overlay-put ov 'type 'org-agenda-clocking)
  2716. (overlay-put ov 'face 'org-agenda-clocking)
  2717. (overlay-put ov 'help-echo
  2718. "The clock is running in this item")))))))
  2719. (defun org-agenda-fontify-priorities ()
  2720. "Make highest priority lines bold, and lowest italic."
  2721. (interactive)
  2722. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2723. (delete-overlay o)))
  2724. (overlays-in (point-min) (point-max)))
  2725. (save-excursion
  2726. (let ((inhibit-read-only t)
  2727. b e p ov h l)
  2728. (goto-char (point-min))
  2729. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2730. (setq h (or (get-char-property (point) 'org-highest-priority)
  2731. org-highest-priority)
  2732. l (or (get-char-property (point) 'org-lowest-priority)
  2733. org-lowest-priority)
  2734. p (string-to-char (match-string 1))
  2735. b (match-beginning 0)
  2736. e (if (eq org-agenda-fontify-priorities 'cookies)
  2737. (match-end 0)
  2738. (point-at-eol))
  2739. ov (make-overlay b e))
  2740. (overlay-put
  2741. ov 'face
  2742. (cond ((org-face-from-face-or-color
  2743. 'priority nil
  2744. (cdr (assoc p org-priority-faces))))
  2745. ((and (listp org-agenda-fontify-priorities)
  2746. (org-face-from-face-or-color
  2747. 'priority nil
  2748. (cdr (assoc p org-agenda-fontify-priorities)))))
  2749. ((equal p l) 'italic)
  2750. ((equal p h) 'bold)))
  2751. (overlay-put ov 'org-type 'org-priority)))))
  2752. (defun org-agenda-dim-blocked-tasks ()
  2753. "Dim currently blocked TODO's in the agenda display."
  2754. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2755. (delete-overlay o)))
  2756. (overlays-in (point-min) (point-max)))
  2757. (save-excursion
  2758. (let ((inhibit-read-only t)
  2759. (org-depend-tag-blocked nil)
  2760. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2761. org-blocked-by-checkboxes
  2762. invis1 b e p ov h l)
  2763. (goto-char (point-min))
  2764. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2765. (and pos (goto-char (1+ pos))))
  2766. (setq org-blocked-by-checkboxes nil invis1 invis)
  2767. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2768. (when (and marker
  2769. (not (with-current-buffer (marker-buffer marker)
  2770. (save-excursion
  2771. (goto-char marker)
  2772. (if (org-entry-get nil "NOBLOCKING")
  2773. t ;; Never block this entry
  2774. (run-hook-with-args-until-failure
  2775. 'org-blocker-hook
  2776. (list :type 'todo-state-change
  2777. :position marker
  2778. :from 'todo
  2779. :to 'done)))))))
  2780. (if org-blocked-by-checkboxes (setq invis1 nil))
  2781. (setq b (if invis1
  2782. (max (point-min) (1- (point-at-bol)))
  2783. (point-at-bol))
  2784. e (point-at-eol)
  2785. ov (make-overlay b e))
  2786. (if invis1
  2787. (overlay-put ov 'invisible t)
  2788. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2789. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2790. (defvar org-agenda-skip-function nil
  2791. "Function to be called at each match during agenda construction.
  2792. If this function returns nil, the current match should not be skipped.
  2793. Otherwise, the function must return a position from where the search
  2794. should be continued.
  2795. This may also be a Lisp form, it will be evaluated.
  2796. Never set this variable using `setq' or so, because then it will apply
  2797. to all future agenda commands. Instead, bind it with `let' to scope
  2798. it dynamically into the agenda-constructing command. A good way to set
  2799. it is through options in `org-agenda-custom-commands'.")
  2800. (defun org-agenda-skip ()
  2801. "Throw to `:skip' in places that should be skipped.
  2802. Also moves point to the end of the skipped region, so that search can
  2803. continue from there."
  2804. (let ((p (point-at-bol)) to fp)
  2805. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2806. (get-text-property p :org-archived)
  2807. (org-end-of-subtree t)
  2808. (throw :skip t))
  2809. (and org-agenda-skip-comment-trees
  2810. (get-text-property p :org-comment)
  2811. (org-end-of-subtree t)
  2812. (throw :skip t))
  2813. (if (equal (char-after p) ?#) (throw :skip t))
  2814. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2815. (consp org-agenda-skip-function))
  2816. (setq to (save-excursion
  2817. (save-match-data
  2818. (if fp
  2819. (funcall org-agenda-skip-function)
  2820. (eval org-agenda-skip-function))))))
  2821. (goto-char to)
  2822. (throw :skip t))))
  2823. (defvar org-agenda-markers nil
  2824. "List of all currently active markers created by `org-agenda'.")
  2825. (defvar org-agenda-last-marker-time (org-float-time)
  2826. "Creation time of the last agenda marker.")
  2827. (defun org-agenda-new-marker (&optional pos)
  2828. "Return a new agenda marker.
  2829. Org-mode keeps a list of these markers and resets them when they are
  2830. no longer in use."
  2831. (let ((m (copy-marker (or pos (point)))))
  2832. (setq org-agenda-last-marker-time (org-float-time))
  2833. (push m org-agenda-markers)
  2834. m))
  2835. (defun org-agenda-reset-markers ()
  2836. "Reset markers created by `org-agenda'."
  2837. (while org-agenda-markers
  2838. (move-marker (pop org-agenda-markers) nil)))
  2839. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2840. "Save relative positions of markers in region."
  2841. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2842. org-agenda-markers))
  2843. ;;; Entry text mode
  2844. (defun org-agenda-entry-text-show-here ()
  2845. "Add some text from the entry as context to the current line."
  2846. (let (m txt o)
  2847. (setq m (org-get-at-bol 'org-hd-marker))
  2848. (unless (marker-buffer m)
  2849. (error "No marker points to an entry here"))
  2850. (setq txt (concat "\n" (org-no-properties
  2851. (org-agenda-get-some-entry-text
  2852. m org-agenda-entry-text-maxlines " > "))))
  2853. (when (string-match "\\S-" txt)
  2854. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  2855. (overlay-put o 'evaporate t)
  2856. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  2857. (overlay-put o 'after-string txt))))
  2858. (defun org-agenda-entry-text-show ()
  2859. "Add entry context for all agenda lines."
  2860. (interactive)
  2861. (save-excursion
  2862. (goto-char (point-max))
  2863. (beginning-of-line 1)
  2864. (while (not (bobp))
  2865. (when (org-get-at-bol 'org-hd-marker)
  2866. (org-agenda-entry-text-show-here))
  2867. (beginning-of-line 0))))
  2868. (defun org-agenda-entry-text-hide ()
  2869. "Remove any shown entry context."
  2870. (delq nil
  2871. (mapcar (lambda (o)
  2872. (if (eq (overlay-get o 'org-overlay-type)
  2873. 'agenda-entry-content)
  2874. (progn (delete-overlay o) t)))
  2875. (overlays-in (point-min) (point-max)))))
  2876. (defun org-agenda-get-day-face (date)
  2877. "Return the face DATE should be displayed with."
  2878. (or (and (functionp org-agenda-day-face-function)
  2879. (funcall org-agenda-day-face-function date))
  2880. (cond ((org-agenda-todayp date)
  2881. 'org-agenda-date-today)
  2882. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  2883. 'org-agenda-date-weekend)
  2884. (t 'org-agenda-date))))
  2885. ;;; Agenda timeline
  2886. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2887. (defun org-timeline (&optional include-all)
  2888. "Show a time-sorted view of the entries in the current org file.
  2889. Only entries with a time stamp of today or later will be listed. With
  2890. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2891. under the current date.
  2892. If the buffer contains an active region, only check the region for
  2893. dates."
  2894. (interactive "P")
  2895. (org-compile-prefix-format 'timeline)
  2896. (org-set-sorting-strategy 'timeline)
  2897. (let* ((dopast t)
  2898. (dotodo include-all)
  2899. (doclosed org-agenda-show-log)
  2900. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  2901. (current-buffer))))
  2902. (date (calendar-current-date))
  2903. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2904. (end (if (org-region-active-p) (region-end) (point-max)))
  2905. (day-numbers (org-get-all-dates beg end 'no-ranges
  2906. t doclosed ; always include today
  2907. org-timeline-show-empty-dates))
  2908. (org-deadline-warning-days 0)
  2909. (org-agenda-only-exact-dates t)
  2910. (today (org-agenda-today))
  2911. (past t)
  2912. args
  2913. s e rtn d emptyp)
  2914. (setq org-agenda-redo-command
  2915. (list 'progn
  2916. (list 'org-switch-to-buffer-other-window (current-buffer))
  2917. (list 'org-timeline (list 'quote include-all))))
  2918. (if (not dopast)
  2919. ;; Remove past dates from the list of dates.
  2920. (setq day-numbers (delq nil (mapcar (lambda(x)
  2921. (if (>= x today) x nil))
  2922. day-numbers))))
  2923. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  2924. (if doclosed (push :closed args))
  2925. (push :timestamp args)
  2926. (push :deadline args)
  2927. (push :scheduled args)
  2928. (push :sexp args)
  2929. (if dotodo (push :todo args))
  2930. (insert "Timeline of file " entry "\n")
  2931. (add-text-properties (point-min) (point)
  2932. (list 'face 'org-agenda-structure))
  2933. (org-agenda-mark-header-line (point-min))
  2934. (while (setq d (pop day-numbers))
  2935. (if (and (listp d) (eq (car d) :omitted))
  2936. (progn
  2937. (setq s (point))
  2938. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2939. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2940. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2941. (if (and (>= d today)
  2942. dopast
  2943. past)
  2944. (progn
  2945. (setq past nil)
  2946. (insert (make-string 79 ?-) "\n")))
  2947. (setq date (calendar-gregorian-from-absolute d))
  2948. (setq s (point))
  2949. (setq rtn (and (not emptyp)
  2950. (apply 'org-agenda-get-day-entries entry
  2951. date args)))
  2952. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2953. (progn
  2954. (insert
  2955. (if (stringp org-agenda-format-date)
  2956. (format-time-string org-agenda-format-date
  2957. (org-time-from-absolute date))
  2958. (funcall org-agenda-format-date date))
  2959. "\n")
  2960. (put-text-property s (1- (point)) 'face
  2961. (org-agenda-get-day-face date))
  2962. (put-text-property s (1- (point)) 'org-date-line t)
  2963. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2964. (if (equal d today)
  2965. (put-text-property s (1- (point)) 'org-today t))
  2966. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2967. (put-text-property s (1- (point)) 'day d)))))
  2968. (goto-char (point-min))
  2969. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2970. (point-min)))
  2971. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2972. (org-finalize-agenda)
  2973. (setq buffer-read-only t)))
  2974. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2975. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2976. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2977. not every single day in the range. If FORCE-TODAY is non-nil, make
  2978. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2979. inactive time stamps (those in square brackets) are included.
  2980. When EMPTY is non-nil, also include days without any entries."
  2981. (let ((re (concat
  2982. (if pre-re pre-re "")
  2983. (if inactive org-ts-regexp-both org-ts-regexp)))
  2984. dates dates1 date day day1 day2 ts1 ts2)
  2985. (if force-today
  2986. (setq dates (list (org-agenda-today))))
  2987. (save-excursion
  2988. (goto-char beg)
  2989. (while (re-search-forward re end t)
  2990. (setq day (time-to-days (org-time-string-to-time
  2991. (substring (match-string 1) 0 10))))
  2992. (or (memq day dates) (push day dates)))
  2993. (unless no-ranges
  2994. (goto-char beg)
  2995. (while (re-search-forward org-tr-regexp end t)
  2996. (setq ts1 (substring (match-string 1) 0 10)
  2997. ts2 (substring (match-string 2) 0 10)
  2998. day1 (time-to-days (org-time-string-to-time ts1))
  2999. day2 (time-to-days (org-time-string-to-time ts2)))
  3000. (while (< (setq day1 (1+ day1)) day2)
  3001. (or (memq day1 dates) (push day1 dates)))))
  3002. (setq dates (sort dates '<))
  3003. (when empty
  3004. (while (setq day (pop dates))
  3005. (setq day2 (car dates))
  3006. (push day dates1)
  3007. (when (and day2 empty)
  3008. (if (or (eq empty t)
  3009. (and (numberp empty) (<= (- day2 day) empty)))
  3010. (while (< (setq day (1+ day)) day2)
  3011. (push (list day) dates1))
  3012. (push (cons :omitted (- day2 day)) dates1))))
  3013. (setq dates (nreverse dates1)))
  3014. dates)))
  3015. ;;; Agenda Daily/Weekly
  3016. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  3017. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3018. "Custom commands can set this variable in the options section.")
  3019. (defvar org-agenda-last-arguments nil
  3020. "The arguments of the previous call to `org-agenda'.")
  3021. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3022. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  3023. (defvar org-include-all-loc nil) ; local variable
  3024. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3025. "List of types searched for when creating the daily/weekly agenda.
  3026. This variable is a list of symbols that controls the types of
  3027. items that appear in the daily/weekly agenda. Allowed symbols in this
  3028. list are are
  3029. :timestamp List items containing a date stamp or date range matching
  3030. the selected date. This includes sexp entries in
  3031. angular brackets.
  3032. :sexp List entries resulting from plain diary-like sexps.
  3033. :deadline List deadline due on that date. When the date is today,
  3034. also list any deadlines past due, or due within
  3035. `org-deadline-warning-days'. `:deadline' must appear before
  3036. `:scheduled' if the setting of
  3037. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3038. any effect.
  3039. :scheduled List all items which are scheduled for the given date.
  3040. The diary for *today* also contains items which were
  3041. scheduled earlier and are not yet marked DONE.
  3042. By default, all four types are turned on.
  3043. Never set this variable globally using `setq', because then it
  3044. will apply to all future agenda commands. Instead, bind it with
  3045. `let' to scope it dynamically into the the agenda-constructing
  3046. command. A good way to set it is through options in
  3047. `org-agenda-custom-commands'. For a more flexible (though
  3048. somewhat less efficient) way of determining what is included in
  3049. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3050. ;;;###autoload
  3051. (defun org-agenda-list (&optional include-all start-day ndays)
  3052. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3053. The view will be for the current day or week, but from the overview buffer
  3054. you will be able to go to other days/weeks.
  3055. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  3056. all unfinished TODO items will also be shown, before the agenda.
  3057. This feature is considered obsolete, please use the TODO list or a block
  3058. agenda instead.
  3059. With a numeric prefix argument in an interactive call, the agenda will
  3060. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  3061. the number of days. NDAYS defaults to `org-agenda-ndays'.
  3062. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3063. given in `org-agenda-start-on-weekday'."
  3064. (interactive "P")
  3065. (if (and (integerp include-all) (> include-all 0))
  3066. (setq ndays include-all include-all nil))
  3067. (setq ndays (or ndays org-agenda-ndays)
  3068. start-day (or start-day org-agenda-start-day))
  3069. (if org-agenda-overriding-arguments
  3070. (setq include-all (car org-agenda-overriding-arguments)
  3071. start-day (nth 1 org-agenda-overriding-arguments)
  3072. ndays (nth 2 org-agenda-overriding-arguments)))
  3073. (if (stringp start-day)
  3074. ;; Convert to an absolute day number
  3075. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3076. (setq org-agenda-last-arguments (list include-all start-day ndays))
  3077. (org-compile-prefix-format 'agenda)
  3078. (org-set-sorting-strategy 'agenda)
  3079. (let* ((org-agenda-start-on-weekday
  3080. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  3081. org-agenda-start-on-weekday nil))
  3082. (thefiles (org-agenda-files nil 'ifmode))
  3083. (files thefiles)
  3084. (today (org-agenda-today))
  3085. (sd (or start-day today))
  3086. (start (if (or (null org-agenda-start-on-weekday)
  3087. (< org-agenda-ndays 7))
  3088. sd
  3089. (let* ((nt (calendar-day-of-week
  3090. (calendar-gregorian-from-absolute sd)))
  3091. (n1 org-agenda-start-on-weekday)
  3092. (d (- nt n1)))
  3093. (- sd (+ (if (< d 0) 7 0) d)))))
  3094. (day-numbers (list start))
  3095. (day-cnt 0)
  3096. (inhibit-redisplay (not debug-on-error))
  3097. s e rtn rtnall file date d start-pos end-pos todayp nd
  3098. clocktable-start clocktable-end filter)
  3099. (setq org-agenda-redo-command
  3100. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  3101. ;; Make the list of days
  3102. (setq ndays (or ndays org-agenda-ndays)
  3103. nd ndays)
  3104. (while (> ndays 1)
  3105. (push (1+ (car day-numbers)) day-numbers)
  3106. (setq ndays (1- ndays)))
  3107. (setq day-numbers (nreverse day-numbers))
  3108. (setq clocktable-start (car day-numbers)
  3109. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3110. (org-prepare-agenda "Day/Week")
  3111. (org-set-local 'org-starting-day (car day-numbers))
  3112. (org-set-local 'org-include-all-loc include-all)
  3113. (org-set-local 'org-agenda-span
  3114. (org-agenda-ndays-to-span nd))
  3115. (when (and (or include-all org-agenda-include-all-todo)
  3116. (member today day-numbers))
  3117. (setq files thefiles
  3118. rtnall nil)
  3119. (while (setq file (pop files))
  3120. (catch 'nextfile
  3121. (org-check-agenda-file file)
  3122. (setq date (calendar-gregorian-from-absolute today)
  3123. rtn (org-agenda-get-day-entries
  3124. file date :todo))
  3125. (setq rtnall (append rtnall rtn))))
  3126. (when rtnall
  3127. (insert "All currently open TODO items:\n")
  3128. (add-text-properties (point-min) (1- (point))
  3129. (list 'face 'org-agenda-structure
  3130. 'short-heading "All TODO items"))
  3131. (org-agenda-mark-header-line (point-min))
  3132. (insert (org-finalize-agenda-entries rtnall) "\n")))
  3133. (unless org-agenda-compact-blocks
  3134. (let* ((d1 (car day-numbers))
  3135. (d2 (org-last day-numbers))
  3136. (w1 (org-days-to-iso-week d1))
  3137. (w2 (org-days-to-iso-week d2)))
  3138. (setq s (point))
  3139. (if org-agenda-overriding-header
  3140. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3141. nil 'face 'org-agenda-structure) "\n")
  3142. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  3143. "-agenda"
  3144. (if (< (- d2 d1) 350)
  3145. (if (= w1 w2)
  3146. (format " (W%02d)" w1)
  3147. (format " (W%02d-W%02d)" w1 w2))
  3148. "")
  3149. ":\n")))
  3150. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3151. 'org-date-line t))
  3152. (org-agenda-mark-header-line s))
  3153. (while (setq d (pop day-numbers))
  3154. (setq date (calendar-gregorian-from-absolute d)
  3155. s (point))
  3156. (if (or (setq todayp (= d today))
  3157. (and (not start-pos) (= d sd)))
  3158. (setq start-pos (point))
  3159. (if (and start-pos (not end-pos))
  3160. (setq end-pos (point))))
  3161. (setq files thefiles
  3162. rtnall nil)
  3163. (while (setq file (pop files))
  3164. (catch 'nextfile
  3165. (org-check-agenda-file file)
  3166. (let ((org-agenda-entry-types org-agenda-entry-types))
  3167. (unless org-agenda-include-deadlines
  3168. (setq org-agenda-entry-types
  3169. (delq :deadline org-agenda-entry-types)))
  3170. (cond
  3171. ((eq org-agenda-show-log 'only)
  3172. (setq rtn (org-agenda-get-day-entries
  3173. file date :closed)))
  3174. (org-agenda-show-log
  3175. (setq rtn (apply 'org-agenda-get-day-entries
  3176. file date
  3177. (append '(:closed) org-agenda-entry-types))))
  3178. (t
  3179. (setq rtn (apply 'org-agenda-get-day-entries
  3180. file date
  3181. org-agenda-entry-types)))))
  3182. (setq rtnall (append rtnall rtn))))
  3183. (if org-agenda-include-diary
  3184. (let ((org-agenda-search-headline-for-time t))
  3185. (require 'diary-lib)
  3186. (setq rtn (org-get-entries-from-diary date))
  3187. (setq rtnall (append rtnall rtn))))
  3188. (if (or rtnall org-agenda-show-all-dates)
  3189. (progn
  3190. (setq day-cnt (1+ day-cnt))
  3191. (insert
  3192. (if (stringp org-agenda-format-date)
  3193. (format-time-string org-agenda-format-date
  3194. (org-time-from-absolute date))
  3195. (funcall org-agenda-format-date date))
  3196. "\n")
  3197. (put-text-property s (1- (point)) 'face
  3198. (org-agenda-get-day-face date))
  3199. (put-text-property s (1- (point)) 'org-date-line t)
  3200. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3201. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3202. (when todayp
  3203. (put-text-property s (1- (point)) 'org-today t))
  3204. (if rtnall (insert
  3205. (org-finalize-agenda-entries
  3206. (org-agenda-add-time-grid-maybe
  3207. rtnall nd todayp))
  3208. "\n"))
  3209. (put-text-property s (1- (point)) 'day d)
  3210. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3211. (when (and org-agenda-clockreport-mode clocktable-start)
  3212. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3213. ;; the above line is to ensure the restricted range!
  3214. (p org-agenda-clockreport-parameter-plist)
  3215. tbl)
  3216. (setq p (org-plist-delete p :block))
  3217. (setq p (plist-put p :tstart clocktable-start))
  3218. (setq p (plist-put p :tend clocktable-end))
  3219. (setq p (plist-put p :scope 'agenda))
  3220. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3221. (setq filter (or org-agenda-filter-while-redo
  3222. (get 'org-agenda-filter :preset-filter))))
  3223. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3224. (if (string-match "[<>=]" x)
  3225. ""
  3226. x))
  3227. filter ""))))
  3228. (message "%s" (plist-get p :tags)) (sit-for 2)
  3229. (setq tbl (apply 'org-get-clocktable p))
  3230. (insert tbl)))
  3231. (goto-char (point-min))
  3232. (or org-agenda-multi (org-fit-agenda-window))
  3233. (unless (and (pos-visible-in-window-p (point-min))
  3234. (pos-visible-in-window-p (point-max)))
  3235. (goto-char (1- (point-max)))
  3236. (recenter -1)
  3237. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3238. (progn
  3239. (goto-char (or start-pos 1))
  3240. (recenter 1))))
  3241. (goto-char (or start-pos 1))
  3242. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3243. (org-finalize-agenda)
  3244. (setq buffer-read-only t)
  3245. (message "")))
  3246. (defun org-agenda-ndays-to-span (n)
  3247. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  3248. ;;; Agenda word search
  3249. (defvar org-agenda-search-history nil)
  3250. (defvar org-todo-only nil)
  3251. (defvar org-search-syntax-table nil
  3252. "Special syntax table for org-mode search.
  3253. In this table, we have single quotes not as word constituents, to
  3254. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3255. (defun org-search-syntax-table ()
  3256. (unless org-search-syntax-table
  3257. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3258. (modify-syntax-entry ?' "." org-search-syntax-table)
  3259. (modify-syntax-entry ?` "." org-search-syntax-table))
  3260. org-search-syntax-table)
  3261. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3262. ;;;###autoload
  3263. (defun org-search-view (&optional todo-only string edit-at)
  3264. "Show all entries that contain a phrase or words or regular expressions.
  3265. With optional prefix argument TODO-ONLY, only consider entries that are
  3266. TODO entries. The argument STRING can be used to pass a default search
  3267. string into this function. If EDIT-AT is non-nil, it means that the
  3268. user should get a chance to edit this string, with cursor at position
  3269. EDIT-AT.
  3270. The search string can be viewed either as a phrase that should be found as
  3271. is, or it can be broken into a number of snippets, each of which must match
  3272. in a Boolean way to select an entry. The default depends on the variable
  3273. `org-agenda-search-view-always-boolean'.
  3274. Even if this is turned off (the default) you can always switch to
  3275. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3276. The default is a direct search of the whole phrase, where each space in
  3277. the search string can expand to an arbitrary amount of whitespace,
  3278. including newlines.
  3279. If using a Boolean search, the search string is split on whitespace and
  3280. each snippet is searched separately, with logical AND to select an entry.
  3281. Words prefixed with a minus must *not* occur in the entry. Words without
  3282. a prefix or prefixed with a plus must occur in the entry. Matching is
  3283. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3284. match whole words, not parts of a word) if
  3285. `org-agenda-search-view-force-full-words' is set (default is nil).
  3286. Boolean search snippets enclosed by curly braces are interpreted as
  3287. regular expressions that must or (when preceded with \"-\") must not
  3288. match in the entry. Snippets enclosed into double quotes will be taken
  3289. as a whole, to include whitespace.
  3290. - If the search string starts with an asterisk, search only in headlines.
  3291. - If (possibly after the leading star) the search string starts with an
  3292. exclamation mark, this also means to look at TODO entries only, an effect
  3293. that can also be achieved with a prefix argument.
  3294. - If (possibly after star and exclamation mark) the search string starts
  3295. with a colon, this will mean that the (non-regexp) snippets of the
  3296. Boolean search must match as full words.
  3297. This command searches the agenda files, and in addition the files listed
  3298. in `org-agenda-text-search-extra-files'."
  3299. (interactive "P")
  3300. (org-compile-prefix-format 'search)
  3301. (org-set-sorting-strategy 'search)
  3302. (org-prepare-agenda "SEARCH")
  3303. (let* ((props (list 'face nil
  3304. 'done-face 'org-agenda-done
  3305. 'org-not-done-regexp org-not-done-regexp
  3306. 'org-todo-regexp org-todo-regexp
  3307. 'org-complex-heading-regexp org-complex-heading-regexp
  3308. 'mouse-face 'highlight
  3309. 'help-echo (format "mouse-2 or RET jump to location")))
  3310. (full-words org-agenda-search-view-force-full-words)
  3311. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3312. regexp rtn rtnall files file pos
  3313. marker category tags c neg re boolean
  3314. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3315. (unless (and (not edit-at)
  3316. (stringp string)
  3317. (string-match "\\S-" string))
  3318. (setq string (read-string
  3319. (if org-agenda-search-view-always-boolean
  3320. "[+-]Word/{Regexp} ...: "
  3321. "Phrase, or [+-]Word/{Regexp} ...: ")
  3322. (cond
  3323. ((integerp edit-at) (cons string edit-at))
  3324. (edit-at string))
  3325. 'org-agenda-search-history)))
  3326. (org-set-local 'org-todo-only todo-only)
  3327. (setq org-agenda-redo-command
  3328. (list 'org-search-view (if todo-only t nil) string
  3329. '(if current-prefix-arg 1 nil)))
  3330. (setq org-agenda-query-string string)
  3331. (if (equal (string-to-char string) ?*)
  3332. (setq hdl-only t
  3333. words (substring string 1))
  3334. (setq words string))
  3335. (when (equal (string-to-char words) ?!)
  3336. (setq todo-only t
  3337. words (substring words 1)))
  3338. (when (equal (string-to-char words) ?:)
  3339. (setq full-words t
  3340. words (substring words 1)))
  3341. (if (or org-agenda-search-view-always-boolean
  3342. (member (string-to-char words) '(?- ?+ ?\{)))
  3343. (setq boolean t))
  3344. (setq words (org-split-string words))
  3345. (let (www w)
  3346. (while (setq w (pop words))
  3347. (while (and (string-match "\\\\\\'" w) words)
  3348. (setq w (concat (substring w 0 -1) " " (pop words))))
  3349. (push w www))
  3350. (setq words (nreverse www) www nil)
  3351. (while (setq w (pop words))
  3352. (when (and (string-match "\\`[-+]?{" w)
  3353. (not (string-match "}\\'" w)))
  3354. (while (and words (not (string-match "}\\'" (car words))))
  3355. (setq w (concat w " " (pop words))))
  3356. (setq w (concat w " " (pop words))))
  3357. (push w www))
  3358. (setq words (nreverse www)))
  3359. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3360. (when boolean
  3361. (let (wds w)
  3362. (while (setq w (pop words))
  3363. (if (or (equal (substring w 0 1) "\"")
  3364. (and (> (length w) 1)
  3365. (member (substring w 0 1) '("+" "-"))
  3366. (equal (substring w 1 2) "\"")))
  3367. (while (and words (not (equal (substring w -1) "\"")))
  3368. (setq w (concat w " " (pop words)))))
  3369. (and (string-match "\\`\\([-+]?\\)\"" w)
  3370. (setq w (replace-match "\\1" nil nil w)))
  3371. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3372. (push w wds))
  3373. (setq words (nreverse wds))))
  3374. (if boolean
  3375. (mapc (lambda (w)
  3376. (setq c (string-to-char w))
  3377. (if (equal c ?-)
  3378. (setq neg t w (substring w 1))
  3379. (if (equal c ?+)
  3380. (setq neg nil w (substring w 1))
  3381. (setq neg nil)))
  3382. (if (string-match "\\`{.*}\\'" w)
  3383. (setq re (substring w 1 -1))
  3384. (if full-words
  3385. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3386. (setq re (regexp-quote (downcase w)))))
  3387. (if neg (push re regexps-) (push re regexps+)))
  3388. words)
  3389. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3390. regexps+))
  3391. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3392. (if (not regexps+)
  3393. (setq regexp (concat "^" org-outline-regexp))
  3394. (setq regexp (pop regexps+))
  3395. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3396. regexp))))
  3397. (setq files (org-agenda-files nil 'ifmode))
  3398. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3399. (pop org-agenda-text-search-extra-files)
  3400. (setq files (org-add-archive-files files)))
  3401. (setq files (append files org-agenda-text-search-extra-files)
  3402. rtnall nil)
  3403. (while (setq file (pop files))
  3404. (setq ee nil)
  3405. (catch 'nextfile
  3406. (org-check-agenda-file file)
  3407. (setq buffer (if (file-exists-p file)
  3408. (org-get-agenda-file-buffer file)
  3409. (error "No such file %s" file)))
  3410. (if (not buffer)
  3411. ;; If file does not exist, make sure an error message is sent
  3412. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3413. file))))
  3414. (with-current-buffer buffer
  3415. (with-syntax-table (org-search-syntax-table)
  3416. (unless (org-mode-p)
  3417. (error "Agenda file %s is not in `org-mode'" file))
  3418. (let ((case-fold-search t))
  3419. (save-excursion
  3420. (save-restriction
  3421. (if org-agenda-restrict
  3422. (narrow-to-region org-agenda-restrict-begin
  3423. org-agenda-restrict-end)
  3424. (widen))
  3425. (goto-char (point-min))
  3426. (unless (or (org-on-heading-p)
  3427. (outline-next-heading))
  3428. (throw 'nextfile t))
  3429. (goto-char (max (point-min) (1- (point))))
  3430. (while (re-search-forward regexp nil t)
  3431. (org-back-to-heading t)
  3432. (skip-chars-forward "* ")
  3433. (setq beg (point-at-bol)
  3434. beg1 (point)
  3435. end (progn (outline-next-heading) (point)))
  3436. (catch :skip
  3437. (goto-char beg)
  3438. (org-agenda-skip)
  3439. (setq str (buffer-substring-no-properties
  3440. (point-at-bol)
  3441. (if hdl-only (point-at-eol) end)))
  3442. (mapc (lambda (wr) (when (string-match wr str)
  3443. (goto-char (1- end))
  3444. (throw :skip t)))
  3445. regexps-)
  3446. (mapc (lambda (wr) (unless (string-match wr str)
  3447. (goto-char (1- end))
  3448. (throw :skip t)))
  3449. (if todo-only
  3450. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3451. regexps+)
  3452. regexps+))
  3453. (goto-char beg)
  3454. (setq marker (org-agenda-new-marker (point))
  3455. category (org-get-category)
  3456. tags (org-get-tags-at (point))
  3457. txt (org-format-agenda-item
  3458. ""
  3459. (buffer-substring-no-properties
  3460. beg1 (point-at-eol))
  3461. category tags))
  3462. (org-add-props txt props
  3463. 'org-marker marker 'org-hd-marker marker
  3464. 'org-todo-regexp org-todo-regexp
  3465. 'org-complex-heading-regexp org-complex-heading-regexp
  3466. 'priority 1000 'org-category category
  3467. 'type "search")
  3468. (push txt ee)
  3469. (goto-char (1- end))))))))))
  3470. (setq rtn (nreverse ee))
  3471. (setq rtnall (append rtnall rtn)))
  3472. (if org-agenda-overriding-header
  3473. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3474. nil 'face 'org-agenda-structure) "\n")
  3475. (insert "Search words: ")
  3476. (add-text-properties (point-min) (1- (point))
  3477. (list 'face 'org-agenda-structure))
  3478. (setq pos (point))
  3479. (insert string "\n")
  3480. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3481. (setq pos (point))
  3482. (unless org-agenda-multi
  3483. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3484. (add-text-properties pos (1- (point))
  3485. (list 'face 'org-agenda-structure))))
  3486. (org-agenda-mark-header-line (point-min))
  3487. (when rtnall
  3488. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3489. (goto-char (point-min))
  3490. (or org-agenda-multi (org-fit-agenda-window))
  3491. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3492. (org-finalize-agenda)
  3493. (setq buffer-read-only t)))
  3494. ;;; Agenda TODO list
  3495. (defvar org-select-this-todo-keyword nil)
  3496. (defvar org-last-arg nil)
  3497. ;;;###autoload
  3498. (defun org-todo-list (arg)
  3499. "Show all (not done) TODO entries from all agenda file in a single list.
  3500. The prefix arg can be used to select a specific TODO keyword and limit
  3501. the list to these. When using \\[universal-argument], you will be prompted
  3502. for a keyword. A numeric prefix directly selects the Nth keyword in
  3503. `org-todo-keywords-1'."
  3504. (interactive "P")
  3505. (org-compile-prefix-format 'todo)
  3506. (org-set-sorting-strategy 'todo)
  3507. (org-prepare-agenda "TODO")
  3508. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3509. (let* ((today (org-agenda-today))
  3510. (date (calendar-gregorian-from-absolute today))
  3511. (kwds org-todo-keywords-for-agenda)
  3512. (completion-ignore-case t)
  3513. (org-select-this-todo-keyword
  3514. (if (stringp arg) arg
  3515. (and arg (integerp arg) (> arg 0)
  3516. (nth (1- arg) kwds))))
  3517. rtn rtnall files file pos)
  3518. (when (equal arg '(4))
  3519. (setq org-select-this-todo-keyword
  3520. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3521. (mapcar 'list kwds) nil nil)))
  3522. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3523. (org-set-local 'org-last-arg arg)
  3524. (setq org-agenda-redo-command
  3525. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3526. (setq files (org-agenda-files nil 'ifmode)
  3527. rtnall nil)
  3528. (while (setq file (pop files))
  3529. (catch 'nextfile
  3530. (org-check-agenda-file file)
  3531. (setq rtn (org-agenda-get-day-entries file date :todo))
  3532. (setq rtnall (append rtnall rtn))))
  3533. (if org-agenda-overriding-header
  3534. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3535. nil 'face 'org-agenda-structure) "\n")
  3536. (insert "Global list of TODO items of type: ")
  3537. (add-text-properties (point-min) (1- (point))
  3538. (list 'face 'org-agenda-structure
  3539. 'short-heading
  3540. (concat "ToDo: "
  3541. (or org-select-this-todo-keyword "ALL"))))
  3542. (org-agenda-mark-header-line (point-min))
  3543. (setq pos (point))
  3544. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3545. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3546. (setq pos (point))
  3547. (unless org-agenda-multi
  3548. (insert "Available with `N r': (0)ALL")
  3549. (let ((n 0) s)
  3550. (mapc (lambda (x)
  3551. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3552. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3553. (insert "\n "))
  3554. (insert " " s))
  3555. kwds))
  3556. (insert "\n"))
  3557. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3558. (org-agenda-mark-header-line (point-min))
  3559. (when rtnall
  3560. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3561. (goto-char (point-min))
  3562. (or org-agenda-multi (org-fit-agenda-window))
  3563. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3564. (org-finalize-agenda)
  3565. (setq buffer-read-only t)))
  3566. ;;; Agenda tags match
  3567. ;;;###autoload
  3568. (defun org-tags-view (&optional todo-only match)
  3569. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3570. The prefix arg TODO-ONLY limits the search to TODO entries."
  3571. (interactive "P")
  3572. (org-compile-prefix-format 'tags)
  3573. (org-set-sorting-strategy 'tags)
  3574. (let* ((org-tags-match-list-sublevels
  3575. org-tags-match-list-sublevels)
  3576. (completion-ignore-case t)
  3577. rtn rtnall files file pos matcher
  3578. buffer)
  3579. (when (and (stringp match) (not (string-match "\\S-" match)))
  3580. (setq match nil))
  3581. (setq matcher (org-make-tags-matcher match)
  3582. match (car matcher) matcher (cdr matcher))
  3583. (org-prepare-agenda (concat "TAGS " match))
  3584. (setq org-agenda-query-string match)
  3585. (setq org-agenda-redo-command
  3586. (list 'org-tags-view (list 'quote todo-only)
  3587. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3588. (setq files (org-agenda-files nil 'ifmode)
  3589. rtnall nil)
  3590. (while (setq file (pop files))
  3591. (catch 'nextfile
  3592. (org-check-agenda-file file)
  3593. (setq buffer (if (file-exists-p file)
  3594. (org-get-agenda-file-buffer file)
  3595. (error "No such file %s" file)))
  3596. (if (not buffer)
  3597. ;; If file does not exist, error message to agenda
  3598. (setq rtn (list
  3599. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3600. rtnall (append rtnall rtn))
  3601. (with-current-buffer buffer
  3602. (unless (org-mode-p)
  3603. (error "Agenda file %s is not in `org-mode'" file))
  3604. (save-excursion
  3605. (save-restriction
  3606. (if org-agenda-restrict
  3607. (narrow-to-region org-agenda-restrict-begin
  3608. org-agenda-restrict-end)
  3609. (widen))
  3610. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3611. (setq rtnall (append rtnall rtn))))))))
  3612. (if org-agenda-overriding-header
  3613. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3614. nil 'face 'org-agenda-structure) "\n")
  3615. (insert "Headlines with TAGS match: ")
  3616. (add-text-properties (point-min) (1- (point))
  3617. (list 'face 'org-agenda-structure
  3618. 'short-heading
  3619. (concat "Match: " match)))
  3620. (setq pos (point))
  3621. (insert match "\n")
  3622. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3623. (setq pos (point))
  3624. (unless org-agenda-multi
  3625. (insert "Press `C-u r' to search again with new search string\n"))
  3626. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3627. (org-agenda-mark-header-line (point-min))
  3628. (when rtnall
  3629. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3630. (goto-char (point-min))
  3631. (or org-agenda-multi (org-fit-agenda-window))
  3632. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3633. (org-finalize-agenda)
  3634. (setq buffer-read-only t)))
  3635. ;;; Agenda Finding stuck projects
  3636. (defvar org-agenda-skip-regexp nil
  3637. "Regular expression used in skipping subtrees for the agenda.
  3638. This is basically a temporary global variable that can be set and then
  3639. used by user-defined selections using `org-agenda-skip-function'.")
  3640. (defvar org-agenda-overriding-header nil
  3641. "When this is set during todo and tags searches, will replace header.
  3642. This variable should not be set directly, but custom commands can bind it
  3643. in the options section.")
  3644. (defun org-agenda-skip-entry-when-regexp-matches ()
  3645. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3646. If yes, it returns the end position of this entry, causing agenda commands
  3647. to skip the entry but continuing the search in the subtree. This is a
  3648. function that can be put into `org-agenda-skip-function' for the duration
  3649. of a command."
  3650. (let ((end (save-excursion (org-end-of-subtree t)))
  3651. skip)
  3652. (save-excursion
  3653. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3654. (and skip end)))
  3655. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3656. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3657. If yes, it returns the end position of this tree, causing agenda commands
  3658. to skip this subtree. This is a function that can be put into
  3659. `org-agenda-skip-function' for the duration of a command."
  3660. (let ((end (save-excursion (org-end-of-subtree t)))
  3661. skip)
  3662. (save-excursion
  3663. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3664. (and skip end)))
  3665. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3666. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3667. If yes, it returns the end position of the current entry (NOT the tree),
  3668. causing agenda commands to skip the entry but continuing the search in
  3669. the subtree. This is a function that can be put into
  3670. `org-agenda-skip-function' for the duration of a command. An important
  3671. use of this function is for the stuck project list."
  3672. (let ((end (save-excursion (org-end-of-subtree t)))
  3673. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3674. skip)
  3675. (save-excursion
  3676. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3677. (and skip entry-end)))
  3678. (defun org-agenda-skip-entry-if (&rest conditions)
  3679. "Skip entry if any of CONDITIONS is true.
  3680. See `org-agenda-skip-if' for details."
  3681. (org-agenda-skip-if nil conditions))
  3682. (defun org-agenda-skip-subtree-if (&rest conditions)
  3683. "Skip entry if any of CONDITIONS is true.
  3684. See `org-agenda-skip-if' for details."
  3685. (org-agenda-skip-if t conditions))
  3686. (defun org-agenda-skip-if (subtree conditions)
  3687. "Checks current entity for CONDITIONS.
  3688. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3689. the entry, i.e. the text before the next heading is checked.
  3690. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3691. from different tests. Valid conditions are:
  3692. scheduled Check if there is a scheduled cookie
  3693. notscheduled Check if there is no scheduled cookie
  3694. deadline Check if there is a deadline
  3695. notdeadline Check if there is no deadline
  3696. timestamp Check if there is a timestamp (also deadline or scheduled)
  3697. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3698. regexp Check if regexp matches
  3699. notregexp Check if regexp does not match.
  3700. todo Check if TODO keyword matches
  3701. nottodo Check if TODO keyword does not match
  3702. The regexp is taken from the conditions list, it must come right after
  3703. the `regexp' or `notregexp' element.
  3704. `todo' and `nottodo' accept as an argument a list of todo
  3705. keywords, which may include \"*\" to match any todo keyword.
  3706. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3707. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3708. Instead of a list a keyword class may be given
  3709. (org-agenda-skip-entry-if 'nottodo 'done)
  3710. would skip entries that haven't been marked with any of \"DONE\"
  3711. keywords. Possible classes are: `todo', `done', `any'.
  3712. If any of these conditions is met, this function returns the end point of
  3713. the entity, causing the search to continue from there. This is a function
  3714. that can be put into `org-agenda-skip-function' for the duration of a command."
  3715. (let (beg end m)
  3716. (org-back-to-heading t)
  3717. (setq beg (point)
  3718. end (if subtree
  3719. (progn (org-end-of-subtree t) (point))
  3720. (progn (outline-next-heading) (1- (point)))))
  3721. (goto-char beg)
  3722. (and
  3723. (or
  3724. (and (memq 'scheduled conditions)
  3725. (re-search-forward org-scheduled-time-regexp end t))
  3726. (and (memq 'notscheduled conditions)
  3727. (not (re-search-forward org-scheduled-time-regexp end t)))
  3728. (and (memq 'deadline conditions)
  3729. (re-search-forward org-deadline-time-regexp end t))
  3730. (and (memq 'notdeadline conditions)
  3731. (not (re-search-forward org-deadline-time-regexp end t)))
  3732. (and (memq 'timestamp conditions)
  3733. (re-search-forward org-ts-regexp end t))
  3734. (and (memq 'nottimestamp conditions)
  3735. (not (re-search-forward org-ts-regexp end t)))
  3736. (and (setq m (memq 'regexp conditions))
  3737. (stringp (nth 1 m))
  3738. (re-search-forward (nth 1 m) end t))
  3739. (and (setq m (memq 'notregexp conditions))
  3740. (stringp (nth 1 m))
  3741. (not (re-search-forward (nth 1 m) end t)))
  3742. (and (or
  3743. (setq m (memq 'todo conditions))
  3744. (setq m (memq 'nottodo conditions)))
  3745. (org-agenda-skip-if-todo m end)))
  3746. end)))
  3747. (defun org-agenda-skip-if-todo (args end)
  3748. "Helper function for `org-agenda-skip-if', do not use it directly.
  3749. ARGS is a list with first element either `todo' or `nottodo'.
  3750. The remainder is either a list of TODO keywords, or a state symbol
  3751. `todo' or `done' or `any'."
  3752. (let ((kw (car args))
  3753. (arg (cadr args))
  3754. todo-wds todo-re)
  3755. (setq todo-wds
  3756. (org-uniquify
  3757. (cond
  3758. ((listp arg) ;; list of keywords
  3759. (if (member "*" arg)
  3760. (mapcar 'substring-no-properties org-todo-keywords-1)
  3761. arg))
  3762. ((symbolp arg) ;; keyword class name
  3763. (cond
  3764. ((eq arg 'todo)
  3765. (org-delete-all org-done-keywords
  3766. (mapcar 'substring-no-properties
  3767. org-todo-keywords-1)))
  3768. ((eq arg 'done) org-done-keywords)
  3769. ((eq arg 'any)
  3770. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3771. (setq todo-re
  3772. (concat "^\\*+[ \t]+\\<\\("
  3773. (mapconcat 'identity todo-wds "\\|")
  3774. "\\)\\>"))
  3775. (if (eq kw 'todo)
  3776. (re-search-forward todo-re end t)
  3777. (not (re-search-forward todo-re end t)))))
  3778. ;;;###autoload
  3779. (defun org-agenda-list-stuck-projects (&rest ignore)
  3780. "Create agenda view for projects that are stuck.
  3781. Stuck projects are project that have no next actions. For the definitions
  3782. of what a project is and how to check if it stuck, customize the variable
  3783. `org-stuck-projects'."
  3784. (interactive)
  3785. (let* ((org-agenda-skip-function
  3786. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3787. ;; We could have used org-agenda-skip-if here.
  3788. (org-agenda-overriding-header
  3789. (or org-agenda-overriding-header "List of stuck projects: "))
  3790. (matcher (nth 0 org-stuck-projects))
  3791. (todo (nth 1 org-stuck-projects))
  3792. (todo-wds (if (member "*" todo)
  3793. (progn
  3794. (org-prepare-agenda-buffers (org-agenda-files
  3795. nil 'ifmode))
  3796. (org-delete-all
  3797. org-done-keywords-for-agenda
  3798. (copy-sequence org-todo-keywords-for-agenda)))
  3799. todo))
  3800. (todo-re (concat "^\\*+[ \t]+\\("
  3801. (mapconcat 'identity todo-wds "\\|")
  3802. "\\)\\>"))
  3803. (tags (nth 2 org-stuck-projects))
  3804. (tags-re (if (member "*" tags)
  3805. (org-re "^\\*+ .*:[[:alnum:]_@#%]+:[ \t]*$")
  3806. (if tags
  3807. (concat "^\\*+ .*:\\("
  3808. (mapconcat 'identity tags "\\|")
  3809. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3810. (gen-re (nth 3 org-stuck-projects))
  3811. (re-list
  3812. (delq nil
  3813. (list
  3814. (if todo todo-re)
  3815. (if tags tags-re)
  3816. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3817. gen-re)))))
  3818. (setq org-agenda-skip-regexp
  3819. (if re-list
  3820. (mapconcat 'identity re-list "\\|")
  3821. (error "No information how to identify unstuck projects")))
  3822. (org-tags-view nil matcher)
  3823. (with-current-buffer org-agenda-buffer-name
  3824. (setq org-agenda-redo-command
  3825. '(org-agenda-list-stuck-projects
  3826. (or current-prefix-arg org-last-arg))))))
  3827. ;;; Diary integration
  3828. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3829. (defvar list-diary-entries-hook)
  3830. (defun org-get-entries-from-diary (date)
  3831. "Get the (Emacs Calendar) diary entries for DATE."
  3832. (require 'diary-lib)
  3833. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3834. (diary-display-hook '(fancy-diary-display))
  3835. (diary-display-function 'fancy-diary-display)
  3836. (pop-up-frames nil)
  3837. (list-diary-entries-hook
  3838. (cons 'org-diary-default-entry list-diary-entries-hook))
  3839. (diary-file-name-prefix-function nil) ; turn this feature off
  3840. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3841. entries
  3842. (org-disable-agenda-to-diary t))
  3843. (save-excursion
  3844. (save-window-excursion
  3845. (funcall (if (fboundp 'diary-list-entries)
  3846. 'diary-list-entries 'list-diary-entries)
  3847. date 1)))
  3848. (if (not (get-buffer diary-fancy-buffer))
  3849. (setq entries nil)
  3850. (with-current-buffer diary-fancy-buffer
  3851. (setq buffer-read-only nil)
  3852. (if (zerop (buffer-size))
  3853. ;; No entries
  3854. (setq entries nil)
  3855. ;; Omit the date and other unnecessary stuff
  3856. (org-agenda-cleanup-fancy-diary)
  3857. ;; Add prefix to each line and extend the text properties
  3858. (if (zerop (buffer-size))
  3859. (setq entries nil)
  3860. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3861. (set-buffer-modified-p nil)
  3862. (kill-buffer diary-fancy-buffer)))
  3863. (when entries
  3864. (setq entries (org-split-string entries "\n"))
  3865. (setq entries
  3866. (mapcar
  3867. (lambda (x)
  3868. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3869. ;; Extend the text properties to the beginning of the line
  3870. (org-add-props x (text-properties-at (1- (length x)) x)
  3871. 'type "diary" 'date date 'face 'org-agenda-diary))
  3872. entries)))))
  3873. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3874. "Hook run when the fancy diary buffer is cleaned up.")
  3875. (defun org-agenda-cleanup-fancy-diary ()
  3876. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3877. This gets rid of the date, the underline under the date, and
  3878. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3879. date. It also removes lines that contain only whitespace."
  3880. (goto-char (point-min))
  3881. (if (looking-at ".*?:[ \t]*")
  3882. (progn
  3883. (replace-match "")
  3884. (re-search-forward "\n=+$" nil t)
  3885. (replace-match "")
  3886. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3887. (re-search-forward "\n=+$" nil t)
  3888. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3889. (goto-char (point-min))
  3890. (while (re-search-forward "^ +\n" nil t)
  3891. (replace-match ""))
  3892. (goto-char (point-min))
  3893. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3894. (replace-match ""))
  3895. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3896. ;; Make sure entries from the diary have the right text properties.
  3897. (eval-after-load "diary-lib"
  3898. '(if (boundp 'diary-modify-entry-list-string-function)
  3899. ;; We can rely on the hook, nothing to do
  3900. nil
  3901. ;; Hook not available, must use advice to make this work
  3902. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3903. "Make the position visible."
  3904. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3905. (stringp string)
  3906. buffer-file-name)
  3907. (setq string (org-modify-diary-entry-string string))))))
  3908. (defun org-modify-diary-entry-string (string)
  3909. "Add text properties to string, allowing org-mode to act on it."
  3910. (org-add-props string nil
  3911. 'mouse-face 'highlight
  3912. 'help-echo (if buffer-file-name
  3913. (format "mouse-2 or RET jump to diary file %s"
  3914. (abbreviate-file-name buffer-file-name))
  3915. "")
  3916. 'org-agenda-diary-link t
  3917. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3918. (defun org-diary-default-entry ()
  3919. "Add a dummy entry to the diary.
  3920. Needed to avoid empty dates which mess up holiday display."
  3921. ;; Catch the error if dealing with the new add-to-diary-alist
  3922. (when org-disable-agenda-to-diary
  3923. (condition-case nil
  3924. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3925. (error
  3926. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3927. (defun org-add-to-diary-list (&rest args)
  3928. (if (fboundp 'diary-add-to-list)
  3929. (apply 'diary-add-to-list args)
  3930. (apply 'add-to-diary-list args)))
  3931. (defvar org-diary-last-run-time nil)
  3932. ;;;###autoload
  3933. (defun org-diary (&rest args)
  3934. "Return diary information from org-files.
  3935. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3936. It accesses org files and extracts information from those files to be
  3937. listed in the diary. The function accepts arguments specifying what
  3938. items should be listed. For a list of arguments allowed here, see the
  3939. variable `org-agenda-entry-types'.
  3940. The call in the diary file should look like this:
  3941. &%%(org-diary) ~/path/to/some/orgfile.org
  3942. Use a separate line for each org file to check. Or, if you omit the file name,
  3943. all files listed in `org-agenda-files' will be checked automatically:
  3944. &%%(org-diary)
  3945. If you don't give any arguments (as in the example above), the default
  3946. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3947. So the example above may also be written as
  3948. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3949. The function expects the lisp variables `entry' and `date' to be provided
  3950. by the caller, because this is how the calendar works. Don't use this
  3951. function from a program - use `org-agenda-get-day-entries' instead."
  3952. (when (> (- (org-float-time)
  3953. org-agenda-last-marker-time)
  3954. 5)
  3955. (org-agenda-reset-markers))
  3956. (org-compile-prefix-format 'agenda)
  3957. (org-set-sorting-strategy 'agenda)
  3958. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3959. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3960. (list entry)
  3961. (org-agenda-files t)))
  3962. (time (org-float-time))
  3963. file rtn results)
  3964. (when (or (not org-diary-last-run-time)
  3965. (> (- time
  3966. org-diary-last-run-time)
  3967. 3))
  3968. (org-prepare-agenda-buffers files))
  3969. (setq org-diary-last-run-time time)
  3970. ;; If this is called during org-agenda, don't return any entries to
  3971. ;; the calendar. Org Agenda will list these entries itself.
  3972. (if org-disable-agenda-to-diary (setq files nil))
  3973. (while (setq file (pop files))
  3974. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3975. (setq results (append results rtn)))
  3976. (if results
  3977. (concat (org-finalize-agenda-entries results) "\n"))))
  3978. ;;; Agenda entry finders
  3979. (defun org-agenda-get-day-entries (file date &rest args)
  3980. "Does the work for `org-diary' and `org-agenda'.
  3981. FILE is the path to a file to be checked for entries. DATE is date like
  3982. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3983. which kind of entries should be extracted. For details about these, see
  3984. the documentation of `org-diary'."
  3985. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3986. (let* ((org-startup-folded nil)
  3987. (org-startup-align-all-tables nil)
  3988. (buffer (if (file-exists-p file)
  3989. (org-get-agenda-file-buffer file)
  3990. (error "No such file %s" file)))
  3991. arg results rtn deadline-results)
  3992. (if (not buffer)
  3993. ;; If file does not exist, make sure an error message ends up in diary
  3994. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3995. (with-current-buffer buffer
  3996. (unless (org-mode-p)
  3997. (error "Agenda file %s is not in `org-mode'" file))
  3998. (let ((case-fold-search nil))
  3999. (save-excursion
  4000. (save-restriction
  4001. (if org-agenda-restrict
  4002. (narrow-to-region org-agenda-restrict-begin
  4003. org-agenda-restrict-end)
  4004. (widen))
  4005. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4006. (while (setq arg (pop args))
  4007. (cond
  4008. ((and (eq arg :todo)
  4009. (equal date (calendar-current-date)))
  4010. (setq rtn (org-agenda-get-todos))
  4011. (setq results (append results rtn)))
  4012. ((eq arg :timestamp)
  4013. (setq rtn (org-agenda-get-blocks))
  4014. (setq results (append results rtn))
  4015. (setq rtn (org-agenda-get-timestamps))
  4016. (setq results (append results rtn)))
  4017. ((eq arg :sexp)
  4018. (setq rtn (org-agenda-get-sexps))
  4019. (setq results (append results rtn)))
  4020. ((eq arg :scheduled)
  4021. (setq rtn (org-agenda-get-scheduled deadline-results))
  4022. (setq results (append results rtn)))
  4023. ((eq arg :closed)
  4024. (setq rtn (org-agenda-get-progress))
  4025. (setq results (append results rtn)))
  4026. ((eq arg :deadline)
  4027. (setq rtn (org-agenda-get-deadlines))
  4028. (setq deadline-results (copy-sequence rtn))
  4029. (setq results (append results rtn))))))))
  4030. results))))
  4031. (defun org-agenda-get-todos ()
  4032. "Return the TODO information for agenda display."
  4033. (let* ((props (list 'face nil
  4034. 'done-face 'org-agenda-done
  4035. 'org-not-done-regexp org-not-done-regexp
  4036. 'org-todo-regexp org-todo-regexp
  4037. 'org-complex-heading-regexp org-complex-heading-regexp
  4038. 'mouse-face 'highlight
  4039. 'help-echo
  4040. (format "mouse-2 or RET jump to org file %s"
  4041. (abbreviate-file-name buffer-file-name))))
  4042. (regexp (concat "^\\*+[ \t]+\\("
  4043. (if org-select-this-todo-keyword
  4044. (if (equal org-select-this-todo-keyword "*")
  4045. org-todo-regexp
  4046. (concat "\\<\\("
  4047. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  4048. "\\)\\>"))
  4049. org-not-done-regexp)
  4050. "[^\n\r]*\\)"))
  4051. marker priority category tags todo-state
  4052. ee txt beg end)
  4053. (goto-char (point-min))
  4054. (while (re-search-forward regexp nil t)
  4055. (catch :skip
  4056. (save-match-data
  4057. (beginning-of-line)
  4058. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4059. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4060. (goto-char (1+ beg))
  4061. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4062. (throw :skip nil)))
  4063. (goto-char beg)
  4064. (org-agenda-skip)
  4065. (goto-char (match-beginning 1))
  4066. (setq marker (org-agenda-new-marker (match-beginning 0))
  4067. category (org-get-category)
  4068. txt (match-string 1)
  4069. tags (org-get-tags-at (point))
  4070. txt (org-format-agenda-item "" txt category tags)
  4071. priority (1+ (org-get-priority txt))
  4072. todo-state (org-get-todo-state))
  4073. (org-add-props txt props
  4074. 'org-marker marker 'org-hd-marker marker
  4075. 'priority priority 'org-category category
  4076. 'type "todo" 'todo-state todo-state)
  4077. (push txt ee)
  4078. (if org-agenda-todo-list-sublevels
  4079. (goto-char (match-end 1))
  4080. (org-end-of-subtree 'invisible))))
  4081. (nreverse ee)))
  4082. ;;;###autoload
  4083. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4084. (&optional end)
  4085. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4086. (when (or org-agenda-todo-ignore-with-date
  4087. org-agenda-todo-ignore-scheduled
  4088. org-agenda-todo-ignore-deadlines)
  4089. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4090. (save-excursion
  4091. (or (and org-agenda-todo-ignore-with-date
  4092. (re-search-forward org-ts-regexp end t))
  4093. (and org-agenda-todo-ignore-scheduled
  4094. (re-search-forward org-scheduled-time-regexp end t)
  4095. (cond
  4096. ((eq org-agenda-todo-ignore-scheduled 'future)
  4097. (> (org-days-to-time (match-string 1)) 0))
  4098. ((eq org-agenda-todo-ignore-scheduled 'past)
  4099. (<= (org-days-to-time (match-string 1)) 0))
  4100. (t)))
  4101. (and org-agenda-todo-ignore-deadlines
  4102. (re-search-forward org-deadline-time-regexp end t)
  4103. (cond
  4104. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4105. ((eq org-agenda-todo-ignore-deadlines 'far)
  4106. (not (org-deadline-close (match-string 1))))
  4107. ((eq org-agenda-todo-ignore-deadlines 'future)
  4108. (> (org-days-to-time (match-string 1)) 0))
  4109. ((eq org-agenda-todo-ignore-deadlines 'past)
  4110. (<= (org-days-to-time (match-string 1)) 0))
  4111. (t (org-deadline-close (match-string 1)))))))))
  4112. (defconst org-agenda-no-heading-message
  4113. "No heading for this item in buffer or region.")
  4114. (defun org-agenda-get-timestamps ()
  4115. "Return the date stamp information for agenda display."
  4116. (let* ((props (list 'face nil
  4117. 'org-not-done-regexp org-not-done-regexp
  4118. 'org-todo-regexp org-todo-regexp
  4119. 'org-complex-heading-regexp org-complex-heading-regexp
  4120. 'mouse-face 'highlight
  4121. 'help-echo
  4122. (format "mouse-2 or RET jump to org file %s"
  4123. (abbreviate-file-name buffer-file-name))))
  4124. (d1 (calendar-absolute-from-gregorian date))
  4125. (remove-re
  4126. (concat
  4127. (regexp-quote
  4128. (format-time-string
  4129. "<%Y-%m-%d"
  4130. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4131. ".*?>"))
  4132. (regexp
  4133. (concat
  4134. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4135. (regexp-quote
  4136. (substring
  4137. (format-time-string
  4138. (car org-time-stamp-formats)
  4139. (apply 'encode-time ; DATE bound by calendar
  4140. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4141. 1 11))
  4142. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4143. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4144. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4145. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  4146. todo-state end-of-match)
  4147. (goto-char (point-min))
  4148. (while (setq end-of-match (re-search-forward regexp nil t))
  4149. (setq b0 (match-beginning 0)
  4150. b3 (match-beginning 3) e3 (match-end 3))
  4151. (catch :skip
  4152. (and (org-at-date-range-p) (throw :skip nil))
  4153. (org-agenda-skip)
  4154. (if (and (match-end 1)
  4155. (not (= d1 (org-time-string-to-absolute
  4156. (match-string 1) d1 nil
  4157. org-agenda-repeating-timestamp-show-all))))
  4158. (throw :skip nil))
  4159. (if (and e3
  4160. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4161. (throw :skip nil))
  4162. (setq tmp (buffer-substring (max (point-min)
  4163. (- b0 org-ds-keyword-length))
  4164. b0)
  4165. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4166. inactivep (= (char-after b0) ?\[)
  4167. deadlinep (string-match org-deadline-regexp tmp)
  4168. scheduledp (string-match org-scheduled-regexp tmp)
  4169. closedp (and org-agenda-include-inactive-timestamps
  4170. (string-match org-closed-string tmp))
  4171. clockp (and org-agenda-include-inactive-timestamps
  4172. (or (string-match org-clock-string tmp)
  4173. (string-match "]-+\\'" tmp)))
  4174. todo-state (ignore-errors (org-get-todo-state))
  4175. donep (member todo-state org-done-keywords))
  4176. (if (or scheduledp deadlinep closedp clockp
  4177. (and donep org-agenda-skip-timestamp-if-done))
  4178. (throw :skip t))
  4179. (if (string-match ">" timestr)
  4180. ;; substring should only run to end of time stamp
  4181. (setq timestr (substring timestr 0 (match-end 0))))
  4182. (setq marker (org-agenda-new-marker b0)
  4183. category (org-get-category b0))
  4184. (save-excursion
  4185. (if (not (re-search-backward "^\\*+ " nil t))
  4186. (setq txt org-agenda-no-heading-message)
  4187. (goto-char (match-beginning 0))
  4188. (setq hdmarker (org-agenda-new-marker)
  4189. tags (org-get-tags-at))
  4190. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4191. (setq head (match-string 1))
  4192. (setq txt (org-format-agenda-item
  4193. (if inactivep org-agenda-inactive-leader nil)
  4194. head category tags timestr nil
  4195. remove-re)))
  4196. (setq priority (org-get-priority txt))
  4197. (org-add-props txt props
  4198. 'org-marker marker 'org-hd-marker hdmarker)
  4199. (org-add-props txt nil 'priority priority
  4200. 'org-category category 'date date
  4201. 'todo-state todo-state
  4202. 'type "timestamp")
  4203. (push txt ee))
  4204. (if org-agenda-skip-additional-timestamps-same-entry
  4205. (outline-next-heading)
  4206. (goto-char end-of-match))))
  4207. (nreverse ee)))
  4208. (defun org-agenda-get-sexps ()
  4209. "Return the sexp information for agenda display."
  4210. (require 'diary-lib)
  4211. (let* ((props (list 'face nil
  4212. 'mouse-face 'highlight
  4213. 'help-echo
  4214. (format "mouse-2 or RET jump to org file %s"
  4215. (abbreviate-file-name buffer-file-name))))
  4216. (regexp "^&?%%(")
  4217. marker category ee txt tags entry result beg b sexp sexp-entry
  4218. todo-state)
  4219. (goto-char (point-min))
  4220. (while (re-search-forward regexp nil t)
  4221. (catch :skip
  4222. (org-agenda-skip)
  4223. (setq beg (match-beginning 0))
  4224. (goto-char (1- (match-end 0)))
  4225. (setq b (point))
  4226. (forward-sexp 1)
  4227. (setq sexp (buffer-substring b (point)))
  4228. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4229. (org-trim (match-string 1))
  4230. ""))
  4231. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4232. (when result
  4233. (setq marker (org-agenda-new-marker beg)
  4234. category (org-get-category beg)
  4235. todo-state (org-get-todo-state))
  4236. (dolist (r (if (stringp result)
  4237. (list result)
  4238. result)) ;; we expect a list here
  4239. (if (string-match "\\S-" r)
  4240. (setq txt r)
  4241. (setq txt "SEXP entry returned empty string"))
  4242. (setq txt (org-format-agenda-item
  4243. "" txt category tags 'time))
  4244. (org-add-props txt props 'org-marker marker)
  4245. (org-add-props txt nil
  4246. 'org-category category 'date date 'todo-state todo-state
  4247. 'type "sexp")
  4248. (push txt ee)))))
  4249. (nreverse ee)))
  4250. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4251. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4252. The order of the first 2 times 3 arguments depends on the variable
  4253. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4254. So for American calendars, give this as MONTH DAY YEAR, for European as
  4255. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4256. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4257. is any number of ISO weeks in the block period for which the item should
  4258. be skipped."
  4259. (let* ((date1 (calendar-absolute-from-gregorian
  4260. (org-order-calendar-date-args m1 d1 y1)))
  4261. (date2 (calendar-absolute-from-gregorian
  4262. (org-order-calendar-date-args m2 d2 y2)))
  4263. (d (calendar-absolute-from-gregorian date)))
  4264. (and
  4265. (<= date1 d)
  4266. (<= d date2)
  4267. (= (calendar-day-of-week date) dayname)
  4268. (or (not skip-weeks)
  4269. (progn
  4270. (require 'cal-iso)
  4271. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4272. entry)))
  4273. (defalias 'org-get-closed 'org-agenda-get-progress)
  4274. (defun org-agenda-get-progress ()
  4275. "Return the logged TODO entries for agenda display."
  4276. (let* ((props (list 'mouse-face 'highlight
  4277. 'org-not-done-regexp org-not-done-regexp
  4278. 'org-todo-regexp org-todo-regexp
  4279. 'org-complex-heading-regexp org-complex-heading-regexp
  4280. 'help-echo
  4281. (format "mouse-2 or RET jump to org file %s"
  4282. (abbreviate-file-name buffer-file-name))))
  4283. (items (if (consp org-agenda-show-log)
  4284. org-agenda-show-log
  4285. org-agenda-log-mode-items))
  4286. (parts
  4287. (delq nil
  4288. (list
  4289. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4290. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4291. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4292. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4293. (error "`org-agenda-log-mode-items' is empty")))
  4294. (regexp (concat
  4295. "\\(" parts-re "\\)"
  4296. " *\\["
  4297. (regexp-quote
  4298. (substring
  4299. (format-time-string
  4300. (car org-time-stamp-formats)
  4301. (apply 'encode-time ; DATE bound by calendar
  4302. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4303. 1 11))))
  4304. (org-agenda-search-headline-for-time nil)
  4305. marker hdmarker priority category tags closedp statep clockp state
  4306. ee txt extra timestr rest clocked)
  4307. (goto-char (point-min))
  4308. (while (re-search-forward regexp nil t)
  4309. (catch :skip
  4310. (org-agenda-skip)
  4311. (setq marker (org-agenda-new-marker (match-beginning 0))
  4312. closedp (equal (match-string 1) org-closed-string)
  4313. statep (equal (string-to-char (match-string 1)) ?-)
  4314. clockp (not (or closedp statep))
  4315. state (and statep (match-string 2))
  4316. category (org-get-category (match-beginning 0))
  4317. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  4318. )
  4319. (when (string-match "\\]" timestr)
  4320. ;; substring should only run to end of time stamp
  4321. (setq rest (substring timestr (match-end 0))
  4322. timestr (substring timestr 0 (match-end 0)))
  4323. (if (and (not closedp) (not statep)
  4324. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  4325. (progn (setq timestr (concat (substring timestr 0 -1)
  4326. "-" (match-string 1 rest) "]"))
  4327. (setq clocked (match-string 2 rest)))
  4328. (setq clocked "-")))
  4329. (save-excursion
  4330. (setq extra nil)
  4331. (cond
  4332. ((not org-agenda-log-mode-add-notes))
  4333. (statep
  4334. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4335. (setq extra (match-string 1))))
  4336. (clockp
  4337. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4338. (setq extra (match-string 1)))))
  4339. (if (not (re-search-backward "^\\*+ " nil t))
  4340. (setq txt org-agenda-no-heading-message)
  4341. (goto-char (match-beginning 0))
  4342. (setq hdmarker (org-agenda-new-marker)
  4343. tags (org-get-tags-at))
  4344. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4345. (setq txt (match-string 1))
  4346. (when extra
  4347. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4348. (setq txt (concat (substring txt 0 (match-beginning 1))
  4349. " - " extra " " (match-string 2 txt)))
  4350. (setq txt (concat txt " - " extra))))
  4351. (setq txt (org-format-agenda-item
  4352. (cond
  4353. (closedp "Closed: ")
  4354. (statep (concat "State: (" state ")"))
  4355. (t (concat "Clocked: (" clocked ")")))
  4356. txt category tags timestr)))
  4357. (setq priority 100000)
  4358. (org-add-props txt props
  4359. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4360. 'priority priority 'org-category category
  4361. 'type "closed" 'date date
  4362. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4363. (push txt ee))
  4364. (goto-char (point-at-eol))))
  4365. (nreverse ee)))
  4366. (defun org-agenda-get-deadlines ()
  4367. "Return the deadline information for agenda display."
  4368. (let* ((props (list 'mouse-face 'highlight
  4369. 'org-not-done-regexp org-not-done-regexp
  4370. 'org-todo-regexp org-todo-regexp
  4371. 'org-complex-heading-regexp org-complex-heading-regexp
  4372. 'help-echo
  4373. (format "mouse-2 or RET jump to org file %s"
  4374. (abbreviate-file-name buffer-file-name))))
  4375. (regexp org-deadline-time-regexp)
  4376. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4377. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4378. d2 diff dfrac wdays pos pos1 category tags
  4379. suppress-prewarning
  4380. ee txt head face s todo-state upcomingp donep timestr)
  4381. (goto-char (point-min))
  4382. (while (re-search-forward regexp nil t)
  4383. (setq suppress-prewarning nil)
  4384. (catch :skip
  4385. (org-agenda-skip)
  4386. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4387. (save-match-data
  4388. (string-match org-scheduled-time-regexp
  4389. (buffer-substring (point-at-bol)
  4390. (point-at-eol)))))
  4391. (setq suppress-prewarning
  4392. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4393. org-agenda-skip-deadline-prewarning-if-scheduled
  4394. 0)))
  4395. (setq s (match-string 1)
  4396. txt nil
  4397. pos (1- (match-beginning 1))
  4398. d2 (org-time-string-to-absolute
  4399. (match-string 1) d1 'past
  4400. org-agenda-repeating-timestamp-show-all)
  4401. diff (- d2 d1)
  4402. wdays (if suppress-prewarning
  4403. (let ((org-deadline-warning-days suppress-prewarning))
  4404. (org-get-wdays s))
  4405. (org-get-wdays s))
  4406. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4407. upcomingp (and todayp (> diff 0)))
  4408. ;; When to show a deadline in the calendar:
  4409. ;; If the expiration is within wdays warning time.
  4410. ;; Past-due deadlines are only shown on the current date
  4411. (if (and (or (and (<= diff wdays)
  4412. (and todayp (not org-agenda-only-exact-dates)))
  4413. (= diff 0)))
  4414. (save-excursion
  4415. (setq todo-state (org-get-todo-state))
  4416. (setq donep (member todo-state org-done-keywords))
  4417. (if (and donep
  4418. (or org-agenda-skip-deadline-if-done
  4419. (not (= diff 0))))
  4420. (setq txt nil)
  4421. (setq category (org-get-category))
  4422. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4423. (setq txt org-agenda-no-heading-message)
  4424. (goto-char (match-end 0))
  4425. (setq pos1 (match-beginning 0))
  4426. (setq tags (org-get-tags-at pos1))
  4427. (setq head (buffer-substring-no-properties
  4428. (point)
  4429. (progn (skip-chars-forward "^\r\n")
  4430. (point))))
  4431. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4432. (setq timestr
  4433. (concat (substring s (match-beginning 1)) " "))
  4434. (setq timestr 'time))
  4435. (setq txt (org-format-agenda-item
  4436. (if (= diff 0)
  4437. (car org-agenda-deadline-leaders)
  4438. (if (functionp
  4439. (nth 1 org-agenda-deadline-leaders))
  4440. (funcall
  4441. (nth 1 org-agenda-deadline-leaders)
  4442. diff date)
  4443. (format (nth 1 org-agenda-deadline-leaders)
  4444. diff)))
  4445. head category tags
  4446. (if (not (= diff 0)) nil timestr)))))
  4447. (when txt
  4448. (setq face (org-agenda-deadline-face dfrac wdays))
  4449. (org-add-props txt props
  4450. 'org-marker (org-agenda-new-marker pos)
  4451. 'org-hd-marker (org-agenda-new-marker pos1)
  4452. 'priority (+ (- diff)
  4453. (org-get-priority txt))
  4454. 'org-category category
  4455. 'todo-state todo-state
  4456. 'type (if upcomingp "upcoming-deadline" "deadline")
  4457. 'date (if upcomingp date d2)
  4458. 'face (if donep 'org-agenda-done face)
  4459. 'undone-face face 'done-face 'org-agenda-done)
  4460. (push txt ee))))))
  4461. (nreverse ee)))
  4462. (defun org-agenda-deadline-face (fraction &optional wdays)
  4463. "Return the face to displaying a deadline item.
  4464. FRACTION is what fraction of the head-warning time has passed."
  4465. (if (equal wdays 0) (setq fraction 1.))
  4466. (let ((faces org-agenda-deadline-faces) f)
  4467. (catch 'exit
  4468. (while (setq f (pop faces))
  4469. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4470. (defun org-agenda-get-scheduled (&optional deadline-results)
  4471. "Return the scheduled information for agenda display."
  4472. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4473. 'org-todo-regexp org-todo-regexp
  4474. 'org-complex-heading-regexp org-complex-heading-regexp
  4475. 'done-face 'org-agenda-done
  4476. 'mouse-face 'highlight
  4477. 'help-echo
  4478. (format "mouse-2 or RET jump to org file %s"
  4479. (abbreviate-file-name buffer-file-name))))
  4480. (regexp org-scheduled-time-regexp)
  4481. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4482. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4483. mm
  4484. (deadline-position-alist
  4485. (mapcar (lambda (a) (and (setq mm (get-text-property
  4486. 0 'org-hd-marker a))
  4487. (cons (marker-position mm) a)))
  4488. deadline-results))
  4489. d2 diff pos pos1 category tags donep
  4490. ee txt head pastschedp todo-state face timestr s habitp)
  4491. (goto-char (point-min))
  4492. (while (re-search-forward regexp nil t)
  4493. (catch :skip
  4494. (org-agenda-skip)
  4495. (setq s (match-string 1)
  4496. txt nil
  4497. pos (1- (match-beginning 1))
  4498. d2 (org-time-string-to-absolute
  4499. (match-string 1) d1 'past
  4500. org-agenda-repeating-timestamp-show-all)
  4501. diff (- d2 d1))
  4502. (setq pastschedp (and todayp (< diff 0)))
  4503. ;; When to show a scheduled item in the calendar:
  4504. ;; If it is on or past the date.
  4505. (when (or (and (< diff 0)
  4506. (< (abs diff) org-scheduled-past-days)
  4507. (and todayp (not org-agenda-only-exact-dates)))
  4508. (= diff 0))
  4509. (save-excursion
  4510. (setq todo-state (org-get-todo-state))
  4511. (setq donep (member todo-state org-done-keywords))
  4512. (setq habitp (and (functionp 'org-is-habit-p)
  4513. (org-is-habit-p)))
  4514. (if (and donep
  4515. (or habitp org-agenda-skip-scheduled-if-done
  4516. (not (= diff 0))))
  4517. (setq txt nil)
  4518. (setq category (org-get-category))
  4519. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4520. (setq txt org-agenda-no-heading-message)
  4521. (goto-char (match-end 0))
  4522. (setq pos1 (match-beginning 0))
  4523. (if habitp
  4524. (if (or (not org-habit-show-habits)
  4525. (and (not todayp)
  4526. org-habit-show-habits-only-for-today))
  4527. (throw :skip nil))
  4528. (if (and
  4529. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4530. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4531. pastschedp))
  4532. (setq mm (assoc pos1 deadline-position-alist)))
  4533. (throw :skip nil)))
  4534. (setq tags (org-get-tags-at))
  4535. (setq head (buffer-substring-no-properties
  4536. (point)
  4537. (progn (skip-chars-forward "^\r\n") (point))))
  4538. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4539. (setq timestr
  4540. (concat (substring s (match-beginning 1)) " "))
  4541. (setq timestr 'time))
  4542. (setq txt (org-format-agenda-item
  4543. (if (= diff 0)
  4544. (car org-agenda-scheduled-leaders)
  4545. (format (nth 1 org-agenda-scheduled-leaders)
  4546. (- 1 diff)))
  4547. head category tags
  4548. (if (not (= diff 0)) nil timestr)
  4549. nil nil habitp))))
  4550. (when txt
  4551. (setq face
  4552. (cond
  4553. ((and (not habitp) pastschedp)
  4554. 'org-scheduled-previously)
  4555. (todayp 'org-scheduled-today)
  4556. (t 'org-scheduled))
  4557. habitp (and habitp (org-habit-parse-todo)))
  4558. (org-add-props txt props
  4559. 'undone-face face
  4560. 'face (if donep 'org-agenda-done face)
  4561. 'org-marker (org-agenda-new-marker pos)
  4562. 'org-hd-marker (org-agenda-new-marker pos1)
  4563. 'type (if pastschedp "past-scheduled" "scheduled")
  4564. 'date (if pastschedp d2 date)
  4565. 'priority (if habitp
  4566. (org-habit-get-priority habitp)
  4567. (+ 94 (- 5 diff) (org-get-priority txt)))
  4568. 'org-category category
  4569. 'org-habit-p habitp
  4570. 'todo-state todo-state)
  4571. (push txt ee))))))
  4572. (nreverse ee)))
  4573. (defun org-agenda-get-blocks ()
  4574. "Return the date-range information for agenda display."
  4575. (let* ((props (list 'face nil
  4576. 'org-not-done-regexp org-not-done-regexp
  4577. 'org-todo-regexp org-todo-regexp
  4578. 'org-complex-heading-regexp org-complex-heading-regexp
  4579. 'mouse-face 'highlight
  4580. 'help-echo
  4581. (format "mouse-2 or RET jump to org file %s"
  4582. (abbreviate-file-name buffer-file-name))))
  4583. (regexp org-tr-regexp)
  4584. (d0 (calendar-absolute-from-gregorian date))
  4585. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4586. head donep)
  4587. (goto-char (point-min))
  4588. (while (re-search-forward regexp nil t)
  4589. (catch :skip
  4590. (org-agenda-skip)
  4591. (setq pos (point))
  4592. (setq timestr (match-string 0)
  4593. s1 (match-string 1)
  4594. s2 (match-string 2)
  4595. d1 (time-to-days (org-time-string-to-time s1))
  4596. d2 (time-to-days (org-time-string-to-time s2)))
  4597. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4598. ;; Only allow days between the limits, because the normal
  4599. ;; date stamps will catch the limits.
  4600. (save-excursion
  4601. (setq todo-state (org-get-todo-state))
  4602. (setq donep (member todo-state org-done-keywords))
  4603. (if (and donep org-agenda-skip-timestamp-if-done)
  4604. (throw :skip t))
  4605. (setq marker (org-agenda-new-marker (point)))
  4606. (setq category (org-get-category))
  4607. (if (not (re-search-backward "^\\*+ " nil t))
  4608. (setq txt org-agenda-no-heading-message)
  4609. (goto-char (match-beginning 0))
  4610. (setq hdmarker (org-agenda-new-marker (point)))
  4611. (setq tags (org-get-tags-at))
  4612. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4613. (setq head (match-string 1))
  4614. (let ((remove-re
  4615. (if org-agenda-remove-timeranges-from-blocks
  4616. (concat
  4617. "<" (regexp-quote s1) ".*?>"
  4618. "--"
  4619. "<" (regexp-quote s2) ".*?>")
  4620. nil)))
  4621. (setq txt (org-format-agenda-item
  4622. (format
  4623. (nth (if (= d1 d2) 0 1)
  4624. org-agenda-timerange-leaders)
  4625. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4626. head category tags
  4627. timestr nil remove-re))))
  4628. (org-add-props txt props
  4629. 'org-marker marker 'org-hd-marker hdmarker
  4630. 'type "block" 'date date
  4631. 'todo-state todo-state
  4632. 'priority (org-get-priority txt) 'org-category category)
  4633. (push txt ee)))
  4634. (goto-char pos)))
  4635. ;; Sort the entries by expiration date.
  4636. (nreverse ee)))
  4637. ;;; Agenda presentation and sorting
  4638. (defvar org-prefix-has-time nil
  4639. "A flag, set by `org-compile-prefix-format'.
  4640. The flag is set if the currently compiled format contains a `%t'.")
  4641. (defvar org-prefix-has-tag nil
  4642. "A flag, set by `org-compile-prefix-format'.
  4643. The flag is set if the currently compiled format contains a `%T'.")
  4644. (defvar org-prefix-has-effort nil
  4645. "A flag, set by `org-compile-prefix-format'.
  4646. The flag is set if the currently compiled format contains a `%e'.")
  4647. (defvar org-prefix-category-length nil
  4648. "Used by `org-compile-prefix-format' to remember the category field width.")
  4649. (defvar org-prefix-category-max-length nil
  4650. "Used by `org-compile-prefix-format' to remember the category field width.")
  4651. (defun org-agenda-get-category-icon (category)
  4652. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  4653. (dolist (entry org-agenda-category-icon-alist)
  4654. (when (org-string-match-p (car entry) category)
  4655. (if (listp (cadr entry))
  4656. (return (cadr entry))
  4657. (return (apply 'create-image (cdr entry)))))))
  4658. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4659. noprefix remove-re habitp)
  4660. "Format TXT to be inserted into the agenda buffer.
  4661. In particular, it adds the prefix and corresponding text properties. EXTRA
  4662. must be a string and replaces the `%s' specifier in the prefix format.
  4663. CATEGORY (string, symbol or nil) may be used to overrule the default
  4664. category taken from local variable or file name. It will replace the `%c'
  4665. specifier in the format. DOTIME, when non-nil, indicates that a
  4666. time-of-day should be extracted from TXT for sorting of this entry, and for
  4667. the `%t' specifier in the format. When DOTIME is a string, this string is
  4668. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4669. only the correctly processes TXT should be returned - this is used by
  4670. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4671. Any match of REMOVE-RE will be removed from TXT."
  4672. (save-match-data
  4673. ;; Diary entries sometimes have extra whitespace at the beginning
  4674. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4675. ;; Fix the tags part in txt
  4676. (setq txt (org-agenda-fix-displayed-tags
  4677. txt tags
  4678. org-agenda-show-inherited-tags
  4679. org-agenda-hide-tags-regexp))
  4680. (let* ((category (or category
  4681. org-category
  4682. (if buffer-file-name
  4683. (file-name-sans-extension
  4684. (file-name-nondirectory buffer-file-name))
  4685. "")))
  4686. (category-icon (org-agenda-get-category-icon category))
  4687. (category-icon (if category-icon
  4688. (propertize " " 'display category-icon)
  4689. ""))
  4690. ;; time, tag, effort are needed for the eval of the prefix format
  4691. (tag (if tags (nth (1- (length tags)) tags) ""))
  4692. time effort neffort
  4693. (ts (if dotime (concat
  4694. (if (stringp dotime) dotime "")
  4695. (and org-agenda-search-headline-for-time txt))))
  4696. (time-of-day (and dotime (org-get-time-of-day ts)))
  4697. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4698. duration thecategory)
  4699. (and (org-mode-p) buffer-file-name
  4700. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4701. (when (and dotime time-of-day)
  4702. ;; Extract starting and ending time and move them to prefix
  4703. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4704. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4705. (setq s0 (match-string 0 ts)
  4706. srp (and stamp (match-end 3))
  4707. s1 (match-string (if plain 1 2) ts)
  4708. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4709. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4710. ;; them, we might want to remove them there to avoid duplication.
  4711. ;; The user can turn this off with a variable.
  4712. (if (and org-prefix-has-time
  4713. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4714. (string-match (concat (regexp-quote s0) " *") txt)
  4715. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4716. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4717. (= (match-beginning 0) 0)
  4718. t))
  4719. (setq txt (replace-match "" nil nil txt))))
  4720. ;; Normalize the time(s) to 24 hour
  4721. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4722. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4723. ;; Compute the duration
  4724. (when s1
  4725. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4726. (string-to-number (substring s1 3)))
  4727. t2 (cond
  4728. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4729. (string-to-number (substring s2 3))))
  4730. (org-agenda-default-appointment-duration
  4731. (+ t1 org-agenda-default-appointment-duration))
  4732. (t nil)))
  4733. (setq duration (if t2 (- t2 t1)))))
  4734. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4735. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4736. (let ((m (+ (string-to-number (match-string 2 s1))
  4737. (* 60 (string-to-number (match-string 1 s1)))
  4738. org-agenda-default-appointment-duration))
  4739. h)
  4740. (setq h (/ m 60) m (- m (* h 60)))
  4741. (setq s2 (format "%02d:%02d" h m))))
  4742. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  4743. txt)
  4744. ;; Tags are in the string
  4745. (if (or (eq org-agenda-remove-tags t)
  4746. (and org-agenda-remove-tags
  4747. org-prefix-has-tag))
  4748. (setq txt (replace-match "" t t txt))
  4749. (setq txt (replace-match
  4750. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4751. (match-string 2 txt))
  4752. t t txt))))
  4753. (when (org-mode-p)
  4754. (setq effort
  4755. (condition-case nil
  4756. (org-get-effort
  4757. (or (get-text-property 0 'org-hd-marker txt)
  4758. (get-text-property 0 'org-marker txt)))
  4759. (error nil)))
  4760. (when effort
  4761. (setq neffort (org-hh:mm-string-to-minutes effort)
  4762. effort (setq effort (concat "[" effort "]" )))))
  4763. (when remove-re
  4764. (while (string-match remove-re txt)
  4765. (setq txt (replace-match "" t t txt))))
  4766. ;; Create the final string
  4767. (if noprefix
  4768. (setq rtn txt)
  4769. ;; Prepare the variables needed in the eval of the compiled format
  4770. (setq time (cond (s2 (concat
  4771. (org-agenda-time-of-day-to-ampm-maybe s1)
  4772. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  4773. (if org-agenda-timegrid-use-ampm " ")))
  4774. (s1 (concat
  4775. (org-agenda-time-of-day-to-ampm-maybe s1)
  4776. (if org-agenda-timegrid-use-ampm
  4777. "........ "
  4778. "......")))
  4779. (t ""))
  4780. extra (or (and (not habitp) extra) "")
  4781. category (if (symbolp category) (symbol-name category) category)
  4782. thecategory (copy-sequence category))
  4783. (if (string-match org-bracket-link-regexp category)
  4784. (progn
  4785. (setq l (if (match-end 3)
  4786. (- (match-end 3) (match-beginning 3))
  4787. (- (match-end 1) (match-beginning 1))))
  4788. (when (< l (or org-prefix-category-length 0))
  4789. (setq category (copy-sequence category))
  4790. (org-add-props category nil
  4791. 'extra-space (make-string
  4792. (- org-prefix-category-length l 1) ?\ ))))
  4793. (if (and org-prefix-category-max-length
  4794. (>= (length category) org-prefix-category-max-length))
  4795. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4796. ;; Evaluate the compiled format
  4797. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4798. ;; And finally add the text properties
  4799. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4800. (org-add-props rtn nil
  4801. 'org-category (if thecategory (downcase thecategory) category)
  4802. 'tags (mapcar 'org-downcase-keep-props tags)
  4803. 'org-highest-priority org-highest-priority
  4804. 'org-lowest-priority org-lowest-priority
  4805. 'prefix-length (- (length rtn) (length txt))
  4806. 'time-of-day time-of-day
  4807. 'duration duration
  4808. 'effort effort
  4809. 'effort-minutes neffort
  4810. 'txt txt
  4811. 'time time
  4812. 'extra extra
  4813. 'dotime dotime))))
  4814. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4815. "Remove tags string from TXT, and add a modified list of tags.
  4816. The modified list may contain inherited tags, and tags matched by
  4817. `org-agenda-hide-tags-regexp' will be removed."
  4818. (when (or add-inherited hide-re)
  4819. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  4820. (setq txt (substring txt 0 (match-beginning 0))))
  4821. (setq tags
  4822. (delq nil
  4823. (mapcar (lambda (tg)
  4824. (if (or (and hide-re (string-match hide-re tg))
  4825. (and (not add-inherited)
  4826. (get-text-property 0 'inherited tg)))
  4827. nil
  4828. tg))
  4829. tags)))
  4830. (when tags
  4831. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4832. i)
  4833. (setq txt (concat txt " :"
  4834. (mapconcat
  4835. (lambda (x)
  4836. (setq i (get-text-property 0 'inherited x))
  4837. (if (and have-i (not i))
  4838. (progn
  4839. (setq have-i nil)
  4840. (concat ":" x))
  4841. x))
  4842. tags ":")
  4843. (if have-i "::" ":"))))))
  4844. txt)
  4845. (defun org-downcase-keep-props (s)
  4846. (let ((props (text-properties-at 0 s)))
  4847. (setq s (downcase s))
  4848. (add-text-properties 0 (length s) props s)
  4849. s))
  4850. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4851. (defvar org-agenda-sorting-strategy-selected nil)
  4852. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4853. (catch 'exit
  4854. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4855. ((and todayp (member 'today (car org-agenda-time-grid))))
  4856. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4857. ((member 'weekly (car org-agenda-time-grid)))
  4858. (t (throw 'exit list)))
  4859. (let* ((have (delq nil (mapcar
  4860. (lambda (x) (get-text-property 1 'time-of-day x))
  4861. list)))
  4862. (string (nth 1 org-agenda-time-grid))
  4863. (gridtimes (nth 2 org-agenda-time-grid))
  4864. (req (car org-agenda-time-grid))
  4865. (remove (member 'remove-match req))
  4866. new time)
  4867. (if (and (member 'require-timed req) (not have))
  4868. ;; don't show empty grid
  4869. (throw 'exit list))
  4870. (while (setq time (pop gridtimes))
  4871. (unless (and remove (member time have))
  4872. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  4873. (push (org-format-agenda-item
  4874. nil string "" nil
  4875. (concat (substring time 0 -2) ":" (substring time -2)))
  4876. new)
  4877. (put-text-property
  4878. 2 (length (car new)) 'face 'org-time-grid (car new))))
  4879. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4880. (append new list)
  4881. (append list new)))))
  4882. (defun org-compile-prefix-format (key)
  4883. "Compile the prefix format into a Lisp form that can be evaluated.
  4884. The resulting form is returned and stored in the variable
  4885. `org-prefix-format-compiled'."
  4886. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4887. org-prefix-category-length nil org-prefix-has-effort nil)
  4888. (let ((s (cond
  4889. ((stringp org-agenda-prefix-format)
  4890. org-agenda-prefix-format)
  4891. ((assq key org-agenda-prefix-format)
  4892. (cdr (assq key org-agenda-prefix-format)))
  4893. (t " %-12:c%?-12t% s")))
  4894. (start 0)
  4895. varform vars var e c f opt)
  4896. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\)"
  4897. s start)
  4898. (setq var (cdr (assoc (match-string 4 s)
  4899. '(("c" . category) ("t" . time) ("s" . extra)
  4900. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  4901. c (or (match-string 3 s) "")
  4902. opt (match-beginning 1)
  4903. start (1+ (match-beginning 0)))
  4904. (if (equal var 'time) (setq org-prefix-has-time t))
  4905. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4906. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4907. (setq f (concat "%" (match-string 2 s) "s"))
  4908. (when (equal var 'category)
  4909. (setq org-prefix-category-length
  4910. (floor (abs (string-to-number (match-string 2 s)))))
  4911. (setq org-prefix-category-max-length
  4912. (let ((x (match-string 2 s)))
  4913. (save-match-data
  4914. (if (string-match "\\.[0-9]+" x)
  4915. (string-to-number (substring (match-string 0 x) 1)))))))
  4916. (if opt
  4917. (setq varform
  4918. `(if (equal "" ,var)
  4919. ""
  4920. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4921. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4922. (setq s (replace-match "%s" t nil s))
  4923. (push varform vars))
  4924. (setq vars (nreverse vars))
  4925. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4926. (defun org-set-sorting-strategy (key)
  4927. (if (symbolp (car org-agenda-sorting-strategy))
  4928. ;; the old format
  4929. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4930. (setq org-agenda-sorting-strategy-selected
  4931. (or (cdr (assq key org-agenda-sorting-strategy))
  4932. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4933. '(time-up category-keep priority-down)))))
  4934. (defun org-get-time-of-day (s &optional string mod24)
  4935. "Check string S for a time of day.
  4936. If found, return it as a military time number between 0 and 2400.
  4937. If not found, return nil.
  4938. The optional STRING argument forces conversion into a 5 character wide string
  4939. HH:MM."
  4940. (save-match-data
  4941. (when
  4942. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4943. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4944. (let* ((h (string-to-number (match-string 1 s)))
  4945. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4946. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4947. (am-p (equal ampm "am"))
  4948. (h1 (cond ((not ampm) h)
  4949. ((= h 12) (if am-p 0 12))
  4950. (t (+ h (if am-p 0 12)))))
  4951. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4952. (mod h1 24) h1))
  4953. (t0 (+ (* 100 h2) m))
  4954. (t1 (concat (if (>= h1 24) "+" " ")
  4955. (if (and org-agenda-time-leading-zero
  4956. (< t0 1000)) "0" "")
  4957. (if (< t0 100) "0" "")
  4958. (if (< t0 10) "0" "")
  4959. (int-to-string t0))))
  4960. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4961. (defvar org-agenda-before-sorting-filter-function nil
  4962. "Function to be applied to agenda items prior to sorting.
  4963. Prior to sorting also means just before they are inserted into the agenda.
  4964. To aid sorting, you may revisit the original entries and add more text
  4965. properties which will later be used by the sorting functions.
  4966. The function should take a string argument, an agenda line.
  4967. It has access to the text properties in that line, which contain among
  4968. other things, the property `org-hd-marker' that points to the entry
  4969. where the line comes from. Note that not all lines going into the agenda
  4970. have this property, only most.
  4971. The function should return the modified string. It is probably best
  4972. to ONLY change text properties.
  4973. You can also use this function as a filter, by returning nil for lines
  4974. you don't want to have in the agenda at all. For this application, you
  4975. could bind the variable in the options section of a custom command.")
  4976. (defun org-finalize-agenda-entries (list &optional nosort)
  4977. "Sort and concatenate the agenda items."
  4978. (setq list (mapcar 'org-agenda-highlight-todo list))
  4979. (if nosort
  4980. list
  4981. (when org-agenda-before-sorting-filter-function
  4982. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  4983. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4984. (defun org-agenda-highlight-todo (x)
  4985. (let ((org-done-keywords org-done-keywords-for-agenda)
  4986. (case-fold-search nil)
  4987. re pl)
  4988. (if (eq x 'line)
  4989. (save-excursion
  4990. (beginning-of-line 1)
  4991. (setq re (org-get-at-bol 'org-todo-regexp))
  4992. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4993. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4994. (add-text-properties (match-beginning 0) (match-end 1)
  4995. (list 'face (org-get-todo-face 1)))
  4996. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4997. (delete-region (match-beginning 1) (1- (match-end 0)))
  4998. (goto-char (match-beginning 1))
  4999. (insert (format org-agenda-todo-keyword-format s)))))
  5000. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  5001. pl (get-text-property 0 'prefix-length x))
  5002. (when (and re
  5003. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5004. x (or pl 0)) pl))
  5005. (add-text-properties
  5006. (or (match-end 1) (match-end 0)) (match-end 0)
  5007. (list 'face (org-get-todo-face (match-string 2 x)))
  5008. x)
  5009. (when (match-end 1)
  5010. (setq x (concat (substring x 0 (match-end 1))
  5011. (format org-agenda-todo-keyword-format
  5012. (match-string 2 x))
  5013. (org-add-props " " (text-properties-at 0 x))
  5014. (substring x (match-end 3))))))
  5015. x)))
  5016. (defsubst org-cmp-priority (a b)
  5017. "Compare the priorities of string A and B."
  5018. (let ((pa (or (get-text-property 1 'priority a) 0))
  5019. (pb (or (get-text-property 1 'priority b) 0)))
  5020. (cond ((> pa pb) +1)
  5021. ((< pa pb) -1)
  5022. (t nil))))
  5023. (defsubst org-cmp-effort (a b)
  5024. "Compare the priorities of string A and B."
  5025. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5026. (ea (or (get-text-property 1 'effort-minutes a) def))
  5027. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5028. (cond ((> ea eb) +1)
  5029. ((< ea eb) -1)
  5030. (t nil))))
  5031. (defsubst org-cmp-category (a b)
  5032. "Compare the string values of categories of strings A and B."
  5033. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5034. (cb (or (get-text-property 1 'org-category b) "")))
  5035. (cond ((string-lessp ca cb) -1)
  5036. ((string-lessp cb ca) +1)
  5037. (t nil))))
  5038. (defsubst org-cmp-todo-state (a b)
  5039. "Compare the todo states of strings A and B."
  5040. (let* ((ma (or (get-text-property 1 'org-marker a)
  5041. (get-text-property 1 'org-hd-marker a)))
  5042. (mb (or (get-text-property 1 'org-marker b)
  5043. (get-text-property 1 'org-hd-marker b)))
  5044. (fa (and ma (marker-buffer ma)))
  5045. (fb (and mb (marker-buffer mb)))
  5046. (todo-kwds
  5047. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5048. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5049. (ta (or (get-text-property 1 'todo-state a) ""))
  5050. (tb (or (get-text-property 1 'todo-state b) ""))
  5051. (la (- (length (member ta todo-kwds))))
  5052. (lb (- (length (member tb todo-kwds))))
  5053. (donepa (member ta org-done-keywords-for-agenda))
  5054. (donepb (member tb org-done-keywords-for-agenda)))
  5055. (cond ((and donepa (not donepb)) -1)
  5056. ((and (not donepa) donepb) +1)
  5057. ((< la lb) -1)
  5058. ((< lb la) +1)
  5059. (t nil))))
  5060. (defsubst org-cmp-alpha (a b)
  5061. "Compare the headlines, alphabetically."
  5062. (let* ((pla (get-text-property 0 'prefix-length a))
  5063. (plb (get-text-property 0 'prefix-length b))
  5064. (ta (and pla (substring a pla)))
  5065. (tb (and plb (substring b plb))))
  5066. (when pla
  5067. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5068. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5069. (setq ta (substring ta (match-end 0))))
  5070. (setq ta (downcase ta)))
  5071. (when plb
  5072. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5073. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5074. (setq tb (substring tb (match-end 0))))
  5075. (setq tb (downcase tb)))
  5076. (cond ((not ta) +1)
  5077. ((not tb) -1)
  5078. ((string-lessp ta tb) -1)
  5079. ((string-lessp tb ta) +1)
  5080. (t nil))))
  5081. (defsubst org-cmp-tag (a b)
  5082. "Compare the string values of the first tags of A and B."
  5083. (let ((ta (car (last (get-text-property 1 'tags a))))
  5084. (tb (car (last (get-text-property 1 'tags b)))))
  5085. (cond ((not ta) +1)
  5086. ((not tb) -1)
  5087. ((string-lessp ta tb) -1)
  5088. ((string-lessp tb ta) +1)
  5089. (t nil))))
  5090. (defsubst org-cmp-time (a b)
  5091. "Compare the time-of-day values of strings A and B."
  5092. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5093. (ta (or (get-text-property 1 'time-of-day a) def))
  5094. (tb (or (get-text-property 1 'time-of-day b) def)))
  5095. (cond ((< ta tb) -1)
  5096. ((< tb ta) +1)
  5097. (t nil))))
  5098. (defsubst org-cmp-habit-p (a b)
  5099. "Compare the todo states of strings A and B."
  5100. (let ((ha (get-text-property 1 'org-habit-p a))
  5101. (hb (get-text-property 1 'org-habit-p b)))
  5102. (cond ((and ha (not hb)) -1)
  5103. ((and (not ha) hb) +1)
  5104. (t nil))))
  5105. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5106. (defun org-entries-lessp (a b)
  5107. "Predicate for sorting agenda entries."
  5108. ;; The following variables will be used when the form is evaluated.
  5109. ;; So even though the compiler complains, keep them.
  5110. (let* ((ss org-agenda-sorting-strategy-selected)
  5111. (time-up (and (org-em 'time-up 'time-down ss)
  5112. (org-cmp-time a b)))
  5113. (time-down (if time-up (- time-up) nil))
  5114. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5115. (org-cmp-priority a b)))
  5116. (priority-down (if priority-up (- priority-up) nil))
  5117. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5118. (org-cmp-effort a b)))
  5119. (effort-down (if effort-up (- effort-up) nil))
  5120. (category-up (and (or (org-em 'category-up 'category-down ss)
  5121. (memq 'category-keep ss))
  5122. (org-cmp-category a b)))
  5123. (category-down (if category-up (- category-up) nil))
  5124. (category-keep (if category-up +1 nil))
  5125. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5126. (org-cmp-tag a b)))
  5127. (tag-down (if tag-up (- tag-up) nil))
  5128. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5129. (org-cmp-todo-state a b)))
  5130. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5131. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5132. (org-cmp-habit-p a b)))
  5133. (habit-down (if habit-up (- habit-up) nil))
  5134. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5135. (org-cmp-alpha a b)))
  5136. (alpha-down (if alpha-up (- alpha-up) nil))
  5137. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5138. user-defined-up user-defined-down)
  5139. (if (and need-user-cmp org-agenda-cmp-user-defined
  5140. (functionp org-agenda-cmp-user-defined))
  5141. (setq user-defined-up
  5142. (funcall org-agenda-cmp-user-defined a b)
  5143. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5144. (cdr (assoc
  5145. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5146. '((-1 . t) (1 . nil) (nil . nil))))))
  5147. ;;; Agenda restriction lock
  5148. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5149. "Overlay to mark the headline to which agenda commands are restricted.")
  5150. (overlay-put org-agenda-restriction-lock-overlay
  5151. 'face 'org-agenda-restriction-lock)
  5152. (overlay-put org-agenda-restriction-lock-overlay
  5153. 'help-echo "Agendas are currently limited to this subtree.")
  5154. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5155. (defun org-agenda-set-restriction-lock (&optional type)
  5156. "Set restriction lock for agenda, to current subtree or file.
  5157. Restriction will be the file if TYPE is `file', or if type is the
  5158. universal prefix '(4), or if the cursor is before the first headline
  5159. in the file. Otherwise, restriction will be to the current subtree."
  5160. (interactive "P")
  5161. (and (equal type '(4)) (setq type 'file))
  5162. (setq type (cond
  5163. (type type)
  5164. ((org-at-heading-p) 'subtree)
  5165. ((condition-case nil (org-back-to-heading t) (error nil))
  5166. 'subtree)
  5167. (t 'file)))
  5168. (if (eq type 'subtree)
  5169. (progn
  5170. (setq org-agenda-restrict t)
  5171. (setq org-agenda-overriding-restriction 'subtree)
  5172. (put 'org-agenda-files 'org-restrict
  5173. (list (buffer-file-name (buffer-base-buffer))))
  5174. (org-back-to-heading t)
  5175. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5176. (move-marker org-agenda-restrict-begin (point))
  5177. (move-marker org-agenda-restrict-end
  5178. (save-excursion (org-end-of-subtree t)))
  5179. (message "Locking agenda restriction to subtree"))
  5180. (put 'org-agenda-files 'org-restrict
  5181. (list (buffer-file-name (buffer-base-buffer))))
  5182. (setq org-agenda-restrict nil)
  5183. (setq org-agenda-overriding-restriction 'file)
  5184. (move-marker org-agenda-restrict-begin nil)
  5185. (move-marker org-agenda-restrict-end nil)
  5186. (message "Locking agenda restriction to file"))
  5187. (setq current-prefix-arg nil)
  5188. (org-agenda-maybe-redo))
  5189. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5190. "Remove the agenda restriction lock."
  5191. (interactive "P")
  5192. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5193. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5194. (setq org-agenda-overriding-restriction nil)
  5195. (setq org-agenda-restrict nil)
  5196. (put 'org-agenda-files 'org-restrict nil)
  5197. (move-marker org-agenda-restrict-begin nil)
  5198. (move-marker org-agenda-restrict-end nil)
  5199. (setq current-prefix-arg nil)
  5200. (message "Agenda restriction lock removed")
  5201. (or noupdate (org-agenda-maybe-redo)))
  5202. (defun org-agenda-maybe-redo ()
  5203. "If there is any window showing the agenda view, update it."
  5204. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5205. (w0 (selected-window)))
  5206. (when w
  5207. (select-window w)
  5208. (org-agenda-redo)
  5209. (select-window w0)
  5210. (if org-agenda-overriding-restriction
  5211. (message "Agenda view shifted to new %s restriction"
  5212. org-agenda-overriding-restriction)
  5213. (message "Agenda restriction lock removed")))))
  5214. ;;; Agenda commands
  5215. (defun org-agenda-check-type (error &rest types)
  5216. "Check if agenda buffer is of allowed type.
  5217. If ERROR is non-nil, throw an error, otherwise just return nil."
  5218. (if (memq org-agenda-type types)
  5219. t
  5220. (if error
  5221. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5222. nil)))
  5223. (defun org-agenda-quit ()
  5224. "Exit agenda by removing the window or the buffer."
  5225. (interactive)
  5226. (if org-agenda-columns-active
  5227. (org-columns-quit)
  5228. (let ((buf (current-buffer)))
  5229. (if (eq org-agenda-window-setup 'other-frame)
  5230. (progn
  5231. (kill-buffer buf)
  5232. (org-agenda-reset-markers)
  5233. (org-columns-remove-overlays)
  5234. (setq org-agenda-archives-mode nil)
  5235. (delete-frame))
  5236. (and (not (eq org-agenda-window-setup 'current-window))
  5237. (not (one-window-p))
  5238. (delete-window))
  5239. (kill-buffer buf)
  5240. (org-agenda-reset-markers)
  5241. (org-columns-remove-overlays)
  5242. (setq org-agenda-archives-mode nil)))
  5243. ;; Maybe restore the pre-agenda window configuration.
  5244. (and org-agenda-restore-windows-after-quit
  5245. (not (eq org-agenda-window-setup 'other-frame))
  5246. org-pre-agenda-window-conf
  5247. (set-window-configuration org-pre-agenda-window-conf))))
  5248. (defun org-agenda-exit ()
  5249. "Exit agenda by removing the window or the buffer.
  5250. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5251. Org-mode buffers visited directly by the user will not be touched."
  5252. (interactive)
  5253. (org-release-buffers org-agenda-new-buffers)
  5254. (setq org-agenda-new-buffers nil)
  5255. (org-agenda-quit))
  5256. (defun org-agenda-execute (arg)
  5257. "Execute another agenda command, keeping same window.
  5258. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5259. in the agenda."
  5260. (interactive "P")
  5261. (let ((org-agenda-window-setup 'current-window))
  5262. (org-agenda arg)))
  5263. (defun org-agenda-redo ()
  5264. "Rebuild Agenda.
  5265. When this is the global TODO list, a prefix argument will be interpreted."
  5266. (interactive)
  5267. (let* ((org-agenda-keep-modes t)
  5268. (filter org-agenda-filter)
  5269. (preset (get 'org-agenda-filter :preset-filter))
  5270. (org-agenda-filter-while-redo (or filter preset))
  5271. (cols org-agenda-columns-active)
  5272. (line (org-current-line))
  5273. (window-line (- line (org-current-line (window-start))))
  5274. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5275. (put 'org-agenda-filter :preset-filter nil)
  5276. (and cols (org-columns-quit))
  5277. (message "Rebuilding agenda buffer...")
  5278. (org-let lprops '(eval org-agenda-redo-command))
  5279. (setq org-agenda-undo-list nil
  5280. org-agenda-pending-undo-list nil)
  5281. (message "Rebuilding agenda buffer...done")
  5282. (put 'org-agenda-filter :preset-filter preset)
  5283. (and (or filter preset) (org-agenda-filter-apply filter))
  5284. (and cols (interactive-p) (org-agenda-columns))
  5285. (org-goto-line line)
  5286. (recenter window-line)))
  5287. (defvar org-global-tags-completion-table nil)
  5288. (defvar org-agenda-filter-form nil)
  5289. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5290. "Keep only those lines in the agenda buffer that have a specific tag.
  5291. The tag is selected with its fast selection letter, as configured.
  5292. With prefix argument STRIP, remove all lines that do have the tag.
  5293. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5294. used to narrow the search - the interactive user can also press `-' or `+'
  5295. to switch to narrowing."
  5296. (interactive "P")
  5297. (let* ((alist org-tag-alist-for-agenda)
  5298. (tag-chars (mapconcat
  5299. (lambda (x) (if (and (not (symbolp (car x)))
  5300. (cdr x))
  5301. (char-to-string (cdr x))
  5302. ""))
  5303. alist ""))
  5304. (efforts (org-split-string
  5305. (or (cdr (assoc (concat org-effort-property "_ALL")
  5306. org-global-properties))
  5307. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  5308. (effort-op org-agenda-filter-effort-default-operator)
  5309. (effort-prompt "")
  5310. (inhibit-read-only t)
  5311. (current org-agenda-filter)
  5312. a n tag)
  5313. (unless char
  5314. (message
  5315. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5316. (if narrow "Narrow" "Filter") tag-chars
  5317. (if org-agenda-auto-exclude-function "[RET], " ""))
  5318. (setq char (read-char)))
  5319. (when (member char '(?+ ?-))
  5320. ;; Narrowing down
  5321. (cond ((equal char ?-) (setq strip t narrow t))
  5322. ((equal char ?+) (setq strip nil narrow t)))
  5323. (message
  5324. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5325. (setq char (read-char)))
  5326. (when (member char '(?< ?> ?= ??))
  5327. ;; An effort operator
  5328. (setq effort-op (char-to-string char))
  5329. (setq alist nil) ; to make sure it will be interpreted as effort.
  5330. (unless (equal char ??)
  5331. (loop for i from 0 to 9 do
  5332. (setq effort-prompt
  5333. (concat
  5334. effort-prompt " ["
  5335. (if (= i 9) "0" (int-to-string (1+ i)))
  5336. "]" (nth i efforts))))
  5337. (message "Effort%s: %s " effort-op effort-prompt)
  5338. (setq char (read-char))
  5339. (when (or (< char ?0) (> char ?9))
  5340. (error "Need 1-9,0 to select effort" ))))
  5341. (when (equal char ?\t)
  5342. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5343. (org-set-local 'org-global-tags-completion-table
  5344. (org-global-tags-completion-table)))
  5345. (let ((completion-ignore-case t))
  5346. (setq tag (org-icompleting-read
  5347. "Tag: " org-global-tags-completion-table))))
  5348. (cond
  5349. ((equal char ?\r)
  5350. (org-agenda-filter-by-tag-show-all)
  5351. (when org-agenda-auto-exclude-function
  5352. (setq org-agenda-filter '())
  5353. (dolist (tag (org-agenda-get-represented-tags))
  5354. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5355. (if modifier
  5356. (push modifier org-agenda-filter))))
  5357. (if (not (null org-agenda-filter))
  5358. (org-agenda-filter-apply org-agenda-filter))))
  5359. ((equal char ?/)
  5360. (org-agenda-filter-by-tag-show-all)
  5361. (when (get 'org-agenda-filter :preset-filter)
  5362. (org-agenda-filter-apply org-agenda-filter)))
  5363. ((or (equal char ?\ )
  5364. (setq a (rassoc char alist))
  5365. (and (>= char ?0) (<= char ?9)
  5366. (setq n (if (= char ?0) 9 (- char ?0 1))
  5367. tag (concat effort-op (nth n efforts))
  5368. a (cons tag nil)))
  5369. (and (= char ??)
  5370. (setq tag "?eff")
  5371. a (cons tag nil))
  5372. (and tag (setq a (cons tag nil))))
  5373. (org-agenda-filter-by-tag-show-all)
  5374. (setq tag (car a))
  5375. (setq org-agenda-filter
  5376. (cons (concat (if strip "-" "+") tag)
  5377. (if narrow current nil)))
  5378. (org-agenda-filter-apply org-agenda-filter))
  5379. (t (error "Invalid tag selection character %c" char)))))
  5380. (defun org-agenda-get-represented-tags ()
  5381. "Get a list of all tags currently represented in the agenda."
  5382. (let (p tags)
  5383. (save-excursion
  5384. (goto-char (point-min))
  5385. (while (setq p (next-single-property-change (point) 'tags))
  5386. (goto-char p)
  5387. (mapc (lambda (x) (add-to-list 'tags x))
  5388. (get-text-property (point) 'tags))))
  5389. tags))
  5390. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5391. "Refine the current filter. See `org-agenda-filter-by-tag."
  5392. (interactive "P")
  5393. (org-agenda-filter-by-tag strip char 'refine))
  5394. (defun org-agenda-filter-make-matcher ()
  5395. "Create the form that tests a line for the agenda filter."
  5396. (let (f f1)
  5397. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5398. org-agenda-filter))
  5399. (if (member x '("-" "+"))
  5400. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5401. (if (string-match "[<=>?]" x)
  5402. (setq f1 (org-agenda-filter-effort-form x))
  5403. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5404. (if (equal (string-to-char x) ?-)
  5405. (setq f1 (list 'not f1))))
  5406. (push f1 f))
  5407. (cons 'and (nreverse f))))
  5408. (defun org-agenda-filter-effort-form (e)
  5409. "Return the form to compare the effort of the current line with what E says.
  5410. E looks like \"+<2:25\"."
  5411. (let (op)
  5412. (setq e (substring e 1))
  5413. (setq op (string-to-char e) e (substring e 1))
  5414. (setq op (cond ((equal op ?<) '<=)
  5415. ((equal op ?>) '>=)
  5416. ((equal op ??) op)
  5417. (t '=)))
  5418. (list 'org-agenda-compare-effort (list 'quote op)
  5419. (org-hh:mm-string-to-minutes e))))
  5420. (defun org-agenda-compare-effort (op value)
  5421. "Compare the effort of the current line with VALUE, using OP.
  5422. If the line does not have an effort defined, return nil."
  5423. (let ((eff (org-get-at-bol 'effort-minutes)))
  5424. (if (equal op ??)
  5425. (not eff)
  5426. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5427. value))))
  5428. (defun org-agenda-filter-apply (filter)
  5429. "Set FILTER as the new agenda filter and apply it."
  5430. (let (tags)
  5431. (setq org-agenda-filter filter
  5432. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5433. (org-agenda-set-mode-name)
  5434. (save-excursion
  5435. (goto-char (point-min))
  5436. (while (not (eobp))
  5437. (if (org-get-at-bol 'org-marker)
  5438. (progn
  5439. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5440. (if (not (eval org-agenda-filter-form))
  5441. (org-agenda-filter-by-tag-hide-line))
  5442. (beginning-of-line 2))
  5443. (beginning-of-line 2))))
  5444. (if (get-char-property (point) 'invisible)
  5445. (org-agenda-previous-line))))
  5446. (defun org-agenda-filter-by-tag-hide-line ()
  5447. (let (ov)
  5448. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5449. (point-at-eol)))
  5450. (overlay-put ov 'invisible t)
  5451. (overlay-put ov 'type 'tags-filter)
  5452. (push ov org-agenda-filter-overlays)))
  5453. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5454. (setq pos (or pos (point)))
  5455. (save-excursion
  5456. (dolist (ov (overlays-at pos))
  5457. (when (and (overlay-get ov 'invisible)
  5458. (eq (overlay-get ov 'type) 'tags-filter))
  5459. (goto-char pos)
  5460. (if (< (overlay-start ov) (point-at-eol))
  5461. (move-overlay ov (point-at-eol)
  5462. (overlay-end ov)))))))
  5463. (defun org-agenda-filter-by-tag-show-all ()
  5464. (mapc 'delete-overlay org-agenda-filter-overlays)
  5465. (setq org-agenda-filter-overlays nil)
  5466. (setq org-agenda-filter nil)
  5467. (setq org-agenda-filter-form nil)
  5468. (org-agenda-set-mode-name))
  5469. (defun org-agenda-manipulate-query-add ()
  5470. "Manipulate the query by adding a search term with positive selection.
  5471. Positive selection means the term must be matched for selection of an entry."
  5472. (interactive)
  5473. (org-agenda-manipulate-query ?\[))
  5474. (defun org-agenda-manipulate-query-subtract ()
  5475. "Manipulate the query by adding a search term with negative selection.
  5476. Negative selection means term must not be matched for selection of an entry."
  5477. (interactive)
  5478. (org-agenda-manipulate-query ?\]))
  5479. (defun org-agenda-manipulate-query-add-re ()
  5480. "Manipulate the query by adding a search regexp with positive selection.
  5481. Positive selection means the regexp must match for selection of an entry."
  5482. (interactive)
  5483. (org-agenda-manipulate-query ?\{))
  5484. (defun org-agenda-manipulate-query-subtract-re ()
  5485. "Manipulate the query by adding a search regexp with negative selection.
  5486. Negative selection means regexp must not match for selection of an entry."
  5487. (interactive)
  5488. (org-agenda-manipulate-query ?\}))
  5489. (defun org-agenda-manipulate-query (char)
  5490. (cond
  5491. ((memq org-agenda-type '(timeline agenda))
  5492. (let ((org-agenda-include-inactive-timestamps t))
  5493. (org-agenda-redo))
  5494. (message "Display now includes inactive timestamps as well"))
  5495. ((eq org-agenda-type 'search)
  5496. (org-add-to-string
  5497. 'org-agenda-query-string
  5498. (if org-agenda-last-search-view-search-was-boolean
  5499. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5500. (?\{ . " +{}") (?\} . " -{}"))))
  5501. " "))
  5502. (setq org-agenda-redo-command
  5503. (list 'org-search-view
  5504. org-todo-only
  5505. org-agenda-query-string
  5506. (+ (length org-agenda-query-string)
  5507. (if (member char '(?\{ ?\})) 0 1))))
  5508. (set-register org-agenda-query-register org-agenda-query-string)
  5509. (org-agenda-redo))
  5510. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5511. org-agenda-type))))
  5512. (defun org-add-to-string (var string)
  5513. (set var (concat (symbol-value var) string)))
  5514. (defun org-agenda-goto-date (date)
  5515. "Jump to DATE in agenda."
  5516. (interactive (list (let ((org-read-date-prefer-future
  5517. (eval org-agenda-jump-prefer-future)))
  5518. (org-read-date))))
  5519. (org-agenda-list nil date))
  5520. (defun org-agenda-goto-today ()
  5521. "Go to today."
  5522. (interactive)
  5523. (org-agenda-check-type t 'timeline 'agenda)
  5524. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5525. (cond
  5526. (tdpos (goto-char tdpos))
  5527. ((eq org-agenda-type 'agenda)
  5528. (let* ((sd (org-agenda-today))
  5529. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5530. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5531. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5532. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5533. (org-agenda-redo)
  5534. (org-agenda-find-same-or-today-or-agenda)))
  5535. (t (error "Cannot find today")))))
  5536. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5537. (goto-char
  5538. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5539. (text-property-any (point-min) (point-max) 'org-today t)
  5540. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5541. (point-min))))
  5542. (defun org-agenda-later (arg)
  5543. "Go forward in time by thee current span.
  5544. With prefix ARG, go forward that many times the current span."
  5545. (interactive "p")
  5546. (org-agenda-check-type t 'agenda)
  5547. (let* ((span org-agenda-span)
  5548. (sd org-starting-day)
  5549. (greg (calendar-gregorian-from-absolute sd))
  5550. (cnt (org-get-at-bol 'org-day-cnt))
  5551. greg2 nd)
  5552. (cond
  5553. ((eq span 'day)
  5554. (setq sd (+ arg sd) nd 1))
  5555. ((eq span 'week)
  5556. (setq sd (+ (* 7 arg) sd) nd 7))
  5557. ((eq span 'month)
  5558. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5559. sd (calendar-absolute-from-gregorian greg2))
  5560. (setcar greg2 (1+ (car greg2)))
  5561. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5562. ((eq span 'year)
  5563. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5564. sd (calendar-absolute-from-gregorian greg2))
  5565. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5566. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5567. (let ((org-agenda-overriding-arguments
  5568. (list (car org-agenda-last-arguments) sd nd t)))
  5569. (org-agenda-redo)
  5570. (org-agenda-find-same-or-today-or-agenda cnt))))
  5571. (defun org-agenda-earlier (arg)
  5572. "Go backward in time by the current span.
  5573. With prefix ARG, go backward that many times the current span."
  5574. (interactive "p")
  5575. (org-agenda-later (- arg)))
  5576. (defun org-agenda-view-mode-dispatch ()
  5577. "Call one of the view mode commands."
  5578. (interactive)
  5579. (message "View: [d]ay [w]eek [m]onth [y]ear [q]uit/abort
  5580. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [E]ntryText
  5581. [a]rch-trees [A]rch-files clock[R]eport include[D]iary")
  5582. (let ((a (read-char-exclusive)))
  5583. (case a
  5584. (?d (call-interactively 'org-agenda-day-view))
  5585. (?w (call-interactively 'org-agenda-week-view))
  5586. (?m (call-interactively 'org-agenda-month-view))
  5587. (?y (call-interactively 'org-agenda-year-view))
  5588. (?l (call-interactively 'org-agenda-log-mode))
  5589. (?L (org-agenda-log-mode '(4)))
  5590. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5591. (?a (call-interactively 'org-agenda-archives-mode))
  5592. (?A (org-agenda-archives-mode 'files))
  5593. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5594. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5595. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5596. (?D (call-interactively 'org-agenda-toggle-diary))
  5597. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  5598. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5599. (org-agenda-check-type t 'timeline 'agenda)
  5600. (org-agenda-redo))
  5601. (message "Display now includes inactive timestamps as well"))
  5602. (?q (message "Abort"))
  5603. (otherwise (error "Invalid key" )))))
  5604. (defun org-agenda-day-view (&optional day-of-year)
  5605. "Switch to daily view for agenda.
  5606. With argument DAY-OF-YEAR, switch to that day of the year."
  5607. (interactive "P")
  5608. (setq org-agenda-ndays 1)
  5609. (org-agenda-change-time-span 'day day-of-year))
  5610. (defun org-agenda-week-view (&optional iso-week)
  5611. "Switch to daily view for agenda.
  5612. With argument ISO-WEEK, switch to the corresponding ISO week.
  5613. If ISO-WEEK has more then 2 digits, only the last two encode the
  5614. week. Any digits before this encode a year. So 200712 means
  5615. week 12 of year 2007. Years in the range 1938-2037 can also be
  5616. written as 2-digit years."
  5617. (interactive "P")
  5618. (setq org-agenda-ndays 7)
  5619. (org-agenda-change-time-span 'week iso-week))
  5620. (defun org-agenda-month-view (&optional month)
  5621. "Switch to monthly view for agenda.
  5622. With argument MONTH, switch to that month."
  5623. (interactive "P")
  5624. (org-agenda-change-time-span 'month month))
  5625. (defun org-agenda-year-view (&optional year)
  5626. "Switch to yearly view for agenda.
  5627. With argument YEAR, switch to that year.
  5628. If MONTH has more then 2 digits, only the last two encode the
  5629. month. Any digits before this encode a year. So 200712 means
  5630. December year 2007. Years in the range 1938-2037 can also be
  5631. written as 2-digit years."
  5632. (interactive "P")
  5633. (when year
  5634. (setq year (org-small-year-to-year year)))
  5635. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5636. (org-agenda-change-time-span 'year year)
  5637. (error "Abort")))
  5638. (defun org-agenda-change-time-span (span &optional n)
  5639. "Change the agenda view to SPAN.
  5640. SPAN may be `day', `week', `month', `year'."
  5641. (org-agenda-check-type t 'agenda)
  5642. (if (and (not n) (equal org-agenda-span span))
  5643. (error "Viewing span is already \"%s\"" span))
  5644. (let* ((sd (or (org-get-at-bol 'day)
  5645. org-starting-day))
  5646. (computed (org-agenda-compute-time-span sd span n))
  5647. (org-agenda-overriding-arguments
  5648. (list (car org-agenda-last-arguments)
  5649. (car computed) (cdr computed) t)))
  5650. (org-agenda-redo)
  5651. (org-agenda-find-same-or-today-or-agenda))
  5652. (org-agenda-set-mode-name)
  5653. (message "Switched to %s view" span))
  5654. (defun org-agenda-compute-time-span (sd span &optional n)
  5655. "Compute starting date and number of days for agenda.
  5656. SPAN may be `day', `week', `month', `year'. The return value
  5657. is a cons cell with the starting date and the number of days,
  5658. so that the date SD will be in that range."
  5659. (let* ((greg (calendar-gregorian-from-absolute sd))
  5660. (dg (nth 1 greg))
  5661. (mg (car greg))
  5662. (yg (nth 2 greg))
  5663. nd w1 y1 m1 thisweek)
  5664. (cond
  5665. ((eq span 'day)
  5666. (when n
  5667. (setq sd (+ (calendar-absolute-from-gregorian
  5668. (list mg 1 yg))
  5669. n -1)))
  5670. (setq nd 1))
  5671. ((eq span 'week)
  5672. (let* ((nt (calendar-day-of-week
  5673. (calendar-gregorian-from-absolute sd)))
  5674. (d (if org-agenda-start-on-weekday
  5675. (- nt org-agenda-start-on-weekday)
  5676. 0)))
  5677. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5678. (when n
  5679. (require 'cal-iso)
  5680. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5681. (when (> n 99)
  5682. (setq y1 (org-small-year-to-year (/ n 100))
  5683. n (mod n 100)))
  5684. (setq sd
  5685. (calendar-absolute-from-iso
  5686. (list n 1
  5687. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5688. (setq nd 7)))
  5689. ((eq span 'month)
  5690. (when (and n (> n 99))
  5691. (setq y1 (org-small-year-to-year (/ n 100))
  5692. n (mod n 100)))
  5693. (setq sd (calendar-absolute-from-gregorian
  5694. (list (or n mg) 1 (or y1 yg)))
  5695. nd (- (calendar-absolute-from-gregorian
  5696. (list (1+ (or n mg)) 1 (or y1 yg)))
  5697. sd)))
  5698. ((eq span 'year)
  5699. (setq sd (calendar-absolute-from-gregorian
  5700. (list 1 1 (or n yg)))
  5701. nd (- (calendar-absolute-from-gregorian
  5702. (list 1 1 (1+ (or n yg))))
  5703. sd))))
  5704. (cons sd nd)))
  5705. (defun org-agenda-next-date-line (&optional arg)
  5706. "Jump to the next line indicating a date in agenda buffer."
  5707. (interactive "p")
  5708. (org-agenda-check-type t 'agenda 'timeline)
  5709. (beginning-of-line 1)
  5710. ;; This does not work if user makes date format that starts with a blank
  5711. (if (looking-at "^\\S-") (forward-char 1))
  5712. (if (not (re-search-forward "^\\S-" nil t arg))
  5713. (progn
  5714. (backward-char 1)
  5715. (error "No next date after this line in this buffer")))
  5716. (goto-char (match-beginning 0)))
  5717. (defun org-agenda-previous-date-line (&optional arg)
  5718. "Jump to the previous line indicating a date in agenda buffer."
  5719. (interactive "p")
  5720. (org-agenda-check-type t 'agenda 'timeline)
  5721. (beginning-of-line 1)
  5722. (if (not (re-search-backward "^\\S-" nil t arg))
  5723. (error "No previous date before this line in this buffer")))
  5724. ;; Initialize the highlight
  5725. (defvar org-hl (make-overlay 1 1))
  5726. (overlay-put org-hl 'face 'highlight)
  5727. (defun org-highlight (begin end &optional buffer)
  5728. "Highlight a region with overlay."
  5729. (move-overlay org-hl begin end (or buffer (current-buffer))))
  5730. (defun org-unhighlight ()
  5731. "Detach overlay INDEX."
  5732. (org-detach-overlay org-hl))
  5733. ;; FIXME this is currently not used.
  5734. (defun org-highlight-until-next-command (beg end &optional buffer)
  5735. "Move the highlight overlay to BEG/END, remove it before the next command."
  5736. (org-highlight beg end buffer)
  5737. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5738. (defun org-unhighlight-once ()
  5739. "Remove the highlight from its position, and this function from the hook."
  5740. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5741. (org-unhighlight))
  5742. (defun org-agenda-follow-mode ()
  5743. "Toggle follow mode in an agenda buffer."
  5744. (interactive)
  5745. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5746. (org-agenda-set-mode-name)
  5747. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5748. (org-agenda-show))
  5749. (message "Follow mode is %s"
  5750. (if org-agenda-follow-mode "on" "off")))
  5751. (defun org-agenda-entry-text-mode (&optional arg)
  5752. "Toggle entry text mode in an agenda buffer."
  5753. (interactive "P")
  5754. (setq org-agenda-entry-text-mode (or (integerp arg)
  5755. (not org-agenda-entry-text-mode)))
  5756. (org-agenda-entry-text-hide)
  5757. (and org-agenda-entry-text-mode
  5758. (let ((org-agenda-entry-text-maxlines
  5759. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5760. (org-agenda-entry-text-show)))
  5761. (org-agenda-set-mode-name)
  5762. (message "Entry text mode is %s. Maximum number of lines is %d"
  5763. (if org-agenda-entry-text-mode "on" "off")
  5764. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5765. (defun org-agenda-clockreport-mode (&optional with-filter)
  5766. "Toggle clocktable mode in an agenda buffer.
  5767. With prefix arg WITH-FILTER, make the clocktable respect the current
  5768. agenda filter."
  5769. (interactive "P")
  5770. (org-agenda-check-type t 'agenda)
  5771. (if with-filter
  5772. (setq org-agenda-clockreport-mode 'with-filter)
  5773. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  5774. (org-agenda-set-mode-name)
  5775. (org-agenda-redo)
  5776. (message "Clocktable mode is %s"
  5777. (if org-agenda-clockreport-mode "on" "off")))
  5778. (defun org-agenda-log-mode (&optional special)
  5779. "Toggle log mode in an agenda buffer.
  5780. With argument SPECIAL, show all possible log items, not only the ones
  5781. configured in `org-agenda-log-mode-items'.
  5782. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5783. (interactive "P")
  5784. (org-agenda-check-type t 'agenda 'timeline)
  5785. (setq org-agenda-show-log
  5786. (if (equal special '(16))
  5787. 'only
  5788. (if special '(closed clock state)
  5789. (not org-agenda-show-log))))
  5790. (org-agenda-set-mode-name)
  5791. (org-agenda-redo)
  5792. (message "Log mode is %s"
  5793. (if org-agenda-show-log "on" "off")))
  5794. (defun org-agenda-archives-mode (&optional with-files)
  5795. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5796. When called with a prefix argument, include all archive files as well."
  5797. (interactive "P")
  5798. (setq org-agenda-archives-mode
  5799. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5800. (org-agenda-set-mode-name)
  5801. (org-agenda-redo)
  5802. (message
  5803. "%s"
  5804. (cond
  5805. ((eq org-agenda-archives-mode nil)
  5806. "No archives are included")
  5807. ((eq org-agenda-archives-mode 'trees)
  5808. (format "Trees with :%s: tag are included" org-archive-tag))
  5809. ((eq org-agenda-archives-mode t)
  5810. (format "Trees with :%s: tag and all active archive files are included"
  5811. org-archive-tag)))))
  5812. (defun org-agenda-toggle-diary ()
  5813. "Toggle diary inclusion in an agenda buffer."
  5814. (interactive)
  5815. (org-agenda-check-type t 'agenda)
  5816. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5817. (org-agenda-redo)
  5818. (org-agenda-set-mode-name)
  5819. (message "Diary inclusion turned %s"
  5820. (if org-agenda-include-diary "on" "off")))
  5821. (defun org-agenda-toggle-deadlines ()
  5822. "Toggle diary inclusion in an agenda buffer."
  5823. (interactive)
  5824. (org-agenda-check-type t 'agenda)
  5825. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  5826. (org-agenda-redo)
  5827. (org-agenda-set-mode-name)
  5828. (message "Deadlines inclusion turned %s"
  5829. (if org-agenda-include-deadlines "on" "off")))
  5830. (defun org-agenda-toggle-time-grid ()
  5831. "Toggle time grid in an agenda buffer."
  5832. (interactive)
  5833. (org-agenda-check-type t 'agenda)
  5834. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5835. (org-agenda-redo)
  5836. (org-agenda-set-mode-name)
  5837. (message "Time-grid turned %s"
  5838. (if org-agenda-use-time-grid "on" "off")))
  5839. (defun org-agenda-set-mode-name ()
  5840. "Set the mode name to indicate all the small mode settings."
  5841. (setq mode-name
  5842. (concat "Org-Agenda"
  5843. (if (get 'org-agenda-files 'org-restrict) " []" "")
  5844. (if (equal org-agenda-ndays 1) " Day" "")
  5845. (if (equal org-agenda-ndays 7) " Week" "")
  5846. (if org-agenda-follow-mode " Follow" "")
  5847. (if org-agenda-entry-text-mode " ETxt" "")
  5848. (if org-agenda-include-diary " Diary" "")
  5849. (if org-agenda-include-deadlines " Ddl" "")
  5850. (if org-agenda-use-time-grid " Grid" "")
  5851. (if (and (boundp 'org-habit-show-habits)
  5852. org-habit-show-habits) " Habit" "")
  5853. (if (consp org-agenda-show-log) " LogAll"
  5854. (if org-agenda-show-log " Log" ""))
  5855. (if (or org-agenda-filter (get 'org-agenda-filter
  5856. :preset-filter))
  5857. (concat " {" (mapconcat
  5858. 'identity
  5859. (append (get 'org-agenda-filter
  5860. :preset-filter)
  5861. org-agenda-filter) "") "}")
  5862. "")
  5863. (if org-agenda-archives-mode
  5864. (if (eq org-agenda-archives-mode t)
  5865. " Archives"
  5866. (format " :%s:" org-archive-tag))
  5867. "")
  5868. (if org-agenda-clockreport-mode
  5869. (if (eq org-agenda-clockreport-mode 'with-filter)
  5870. " Clock{}" " Clock")
  5871. "")))
  5872. (force-mode-line-update))
  5873. (defun org-agenda-post-command-hook ()
  5874. (setq org-agenda-type
  5875. (or (get-text-property (point) 'org-agenda-type)
  5876. (get-text-property (max (point-min) (1- (point)))
  5877. 'org-agenda-type))))
  5878. (defun org-agenda-next-line ()
  5879. "Move cursor to the next line, and show if follow mode is active."
  5880. (interactive)
  5881. (call-interactively 'next-line)
  5882. (org-agenda-do-context-action))
  5883. (defun org-agenda-previous-line ()
  5884. "Move cursor to the previous line, and show if follow-mode is active."
  5885. (interactive)
  5886. (call-interactively 'previous-line)
  5887. (org-agenda-do-context-action))
  5888. (defun org-agenda-do-context-action ()
  5889. "Show outline path and, maybe, follow mode window."
  5890. (let ((m (org-get-at-bol 'org-marker)))
  5891. (if (and org-agenda-follow-mode m)
  5892. (org-agenda-show))
  5893. (if (and m org-agenda-show-outline-path)
  5894. (org-with-point-at m
  5895. (org-display-outline-path t)))))
  5896. (defun org-agenda-show-priority ()
  5897. "Show the priority of the current item.
  5898. This priority is composed of the main priority given with the [#A] cookies,
  5899. and by additional input from the age of a schedules or deadline entry."
  5900. (interactive)
  5901. (let* ((pri (org-get-at-bol 'priority)))
  5902. (message "Priority is %d" (if pri pri -1000))))
  5903. (defun org-agenda-show-tags ()
  5904. "Show the tags applicable to the current item."
  5905. (interactive)
  5906. (let* ((tags (org-get-at-bol 'tags)))
  5907. (if tags
  5908. (message "Tags are :%s:"
  5909. (org-no-properties (mapconcat 'identity tags ":")))
  5910. (message "No tags associated with this line"))))
  5911. (defun org-agenda-goto (&optional highlight)
  5912. "Go to the Org-mode file which contains the item at point."
  5913. (interactive)
  5914. (let* ((marker (or (org-get-at-bol 'org-marker)
  5915. (org-agenda-error)))
  5916. (buffer (marker-buffer marker))
  5917. (pos (marker-position marker)))
  5918. (switch-to-buffer-other-window buffer)
  5919. (widen)
  5920. (push-mark)
  5921. (goto-char pos)
  5922. (when (org-mode-p)
  5923. (org-show-context 'agenda)
  5924. (save-excursion
  5925. (and (outline-next-heading)
  5926. (org-flag-heading nil)))) ; show the next heading
  5927. (recenter (/ (window-height) 2))
  5928. (run-hooks 'org-agenda-after-show-hook)
  5929. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5930. (defvar org-agenda-after-show-hook nil
  5931. "Normal hook run after an item has been shown from the agenda.
  5932. Point is in the buffer where the item originated.")
  5933. (defun org-agenda-kill ()
  5934. "Kill the entry or subtree belonging to the current agenda entry."
  5935. (interactive)
  5936. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5937. (let* ((marker (or (org-get-at-bol 'org-marker)
  5938. (org-agenda-error)))
  5939. (buffer (marker-buffer marker))
  5940. (pos (marker-position marker))
  5941. (type (org-get-at-bol 'type))
  5942. dbeg dend (n 0) conf)
  5943. (org-with-remote-undo buffer
  5944. (with-current-buffer buffer
  5945. (save-excursion
  5946. (goto-char pos)
  5947. (if (and (org-mode-p) (not (member type '("sexp"))))
  5948. (setq dbeg (progn (org-back-to-heading t) (point))
  5949. dend (org-end-of-subtree t t))
  5950. (setq dbeg (point-at-bol)
  5951. dend (min (point-max) (1+ (point-at-eol)))))
  5952. (goto-char dbeg)
  5953. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5954. (setq conf (or (eq t org-agenda-confirm-kill)
  5955. (and (numberp org-agenda-confirm-kill)
  5956. (> n org-agenda-confirm-kill))))
  5957. (and conf
  5958. (not (y-or-n-p
  5959. (format "Delete entry with %d lines in buffer \"%s\"? "
  5960. n (buffer-name buffer))))
  5961. (error "Abort"))
  5962. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5963. (with-current-buffer buffer (delete-region dbeg dend))
  5964. (message "Agenda item and source killed"))))
  5965. (defvar org-archive-default-command)
  5966. (defun org-agenda-archive-default ()
  5967. "Archive the entry or subtree belonging to the current agenda entry."
  5968. (interactive)
  5969. (require 'org-archive)
  5970. (org-agenda-archive-with org-archive-default-command))
  5971. (defun org-agenda-archive-default-with-confirmation ()
  5972. "Archive the entry or subtree belonging to the current agenda entry."
  5973. (interactive)
  5974. (require 'org-archive)
  5975. (org-agenda-archive-with org-archive-default-command 'confirm))
  5976. (defun org-agenda-archive ()
  5977. "Archive the entry or subtree belonging to the current agenda entry."
  5978. (interactive)
  5979. (org-agenda-archive-with 'org-archive-subtree))
  5980. (defun org-agenda-archive-to-archive-sibling ()
  5981. "Move the entry to the archive sibling."
  5982. (interactive)
  5983. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5984. (defun org-agenda-archive-with (cmd &optional confirm)
  5985. "Move the entry to the archive sibling."
  5986. (interactive)
  5987. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5988. (let* ((marker (or (org-get-at-bol 'org-marker)
  5989. (org-agenda-error)))
  5990. (buffer (marker-buffer marker))
  5991. (pos (marker-position marker)))
  5992. (org-with-remote-undo buffer
  5993. (with-current-buffer buffer
  5994. (if (org-mode-p)
  5995. (if (and confirm
  5996. (not (y-or-n-p "Archive this subtree or entry? ")))
  5997. (error "Abort")
  5998. (save-excursion
  5999. (goto-char pos)
  6000. (org-remove-subtree-entries-from-agenda)
  6001. (org-back-to-heading t)
  6002. (funcall cmd)))
  6003. (error "Archiving works only in Org-mode files"))))))
  6004. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6005. "Remove all lines in the agenda that correspond to a given subtree.
  6006. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6007. If this information is not given, the function uses the tree at point."
  6008. (let ((buf (or buf (current-buffer))) m p)
  6009. (save-excursion
  6010. (unless (and beg end)
  6011. (org-back-to-heading t)
  6012. (setq beg (point))
  6013. (org-end-of-subtree t)
  6014. (setq end (point)))
  6015. (set-buffer (get-buffer org-agenda-buffer-name))
  6016. (save-excursion
  6017. (goto-char (point-max))
  6018. (beginning-of-line 1)
  6019. (while (not (bobp))
  6020. (when (and (setq m (org-get-at-bol 'org-marker))
  6021. (equal buf (marker-buffer m))
  6022. (setq p (marker-position m))
  6023. (>= p beg)
  6024. (< p end))
  6025. (let ((inhibit-read-only t))
  6026. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6027. (beginning-of-line 0))))))
  6028. (defun org-agenda-refile (&optional goto rfloc no-update)
  6029. "Refile the item at point."
  6030. (interactive "P")
  6031. (if (equal goto '(16))
  6032. (org-refile-goto-last-stored)
  6033. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6034. (org-agenda-error)))
  6035. (buffer (marker-buffer marker))
  6036. (pos (marker-position marker))
  6037. (rfloc (or rfloc
  6038. (org-refile-get-location
  6039. (if goto "Goto: " "Refile to: ") buffer
  6040. org-refile-allow-creating-parent-nodes))))
  6041. (with-current-buffer buffer
  6042. (save-excursion
  6043. (save-restriction
  6044. (widen)
  6045. (goto-char marker)
  6046. (org-remove-subtree-entries-from-agenda)
  6047. (org-refile goto buffer rfloc)))))
  6048. (unless no-update (org-agenda-redo))))
  6049. (defun org-agenda-open-link (&optional arg)
  6050. "Follow the link in the current line, if any.
  6051. This looks for a link in the displayed line in the agenda. It also looks
  6052. at the text of the entry itself."
  6053. (interactive "P")
  6054. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6055. (org-get-at-bol 'org-marker)))
  6056. (buffer (and marker (marker-buffer marker)))
  6057. (prefix (buffer-substring
  6058. (point-at-bol)
  6059. (+ (point-at-bol)
  6060. (or (org-get-at-bol 'prefix-length) 0)))))
  6061. (cond
  6062. (buffer
  6063. (with-current-buffer buffer
  6064. (save-excursion
  6065. (save-restriction
  6066. (widen)
  6067. (goto-char marker)
  6068. (org-offer-links-in-entry arg prefix)))))
  6069. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6070. (save-excursion
  6071. (beginning-of-line 1)
  6072. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6073. (org-open-link-from-string (match-string 1)))
  6074. (t (error "No link to open here")))))
  6075. (defun org-agenda-copy-local-variable (var)
  6076. "Get a variable from a referenced buffer and install it here."
  6077. (let ((m (org-get-at-bol 'org-marker)))
  6078. (when (and m (buffer-live-p (marker-buffer m)))
  6079. (org-set-local var (with-current-buffer (marker-buffer m)
  6080. (symbol-value var))))))
  6081. (defun org-agenda-switch-to (&optional delete-other-windows)
  6082. "Go to the Org-mode file which contains the item at point."
  6083. (interactive)
  6084. (if (and org-return-follows-link
  6085. (not (org-get-at-bol 'org-marker))
  6086. (org-in-regexp org-bracket-link-regexp))
  6087. (org-open-link-from-string (match-string 0))
  6088. (let* ((marker (or (org-get-at-bol 'org-marker)
  6089. (org-agenda-error)))
  6090. (buffer (marker-buffer marker))
  6091. (pos (marker-position marker)))
  6092. (switch-to-buffer buffer)
  6093. (and delete-other-windows (delete-other-windows))
  6094. (widen)
  6095. (goto-char pos)
  6096. (when (org-mode-p)
  6097. (org-show-context 'agenda)
  6098. (save-excursion
  6099. (and (outline-next-heading)
  6100. (org-flag-heading nil))))))) ; show the next heading
  6101. (defun org-agenda-goto-mouse (ev)
  6102. "Go to the Org-mode file which contains the item at the mouse click."
  6103. (interactive "e")
  6104. (mouse-set-point ev)
  6105. (org-agenda-goto))
  6106. (defun org-agenda-show (&optional full-entry)
  6107. "Display the Org-mode file which contains the item at point.
  6108. With prefix argument FULL-ENTRY, make the entire entry visible
  6109. if it was hidden in the outline."
  6110. (interactive "P")
  6111. (let ((win (selected-window)))
  6112. (if full-entry
  6113. (let ((org-show-entry-below t))
  6114. (org-agenda-goto t))
  6115. (org-agenda-goto t))
  6116. (select-window win)))
  6117. (defvar org-agenda-show-window nil)
  6118. (defun org-agenda-show-and-scroll-up ()
  6119. "Display the Org-mode file which contains the item at point.
  6120. When called repeatedly, scroll the window that is displaying the buffer."
  6121. (interactive)
  6122. (let ((win (selected-window)))
  6123. (if (and (window-live-p org-agenda-show-window)
  6124. (eq this-command last-command))
  6125. (progn
  6126. (select-window org-agenda-show-window)
  6127. (ignore-errors (scroll-up)))
  6128. (org-agenda-goto t)
  6129. (show-subtree)
  6130. (setq org-agenda-show-window (selected-window)))
  6131. (select-window win)))
  6132. (defun org-agenda-show-scroll-down ()
  6133. "Scroll down the window showing the agenda."
  6134. (interactive)
  6135. (let ((win (selected-window)))
  6136. (when (window-live-p org-agenda-show-window)
  6137. (select-window org-agenda-show-window)
  6138. (ignore-errors (scroll-down))
  6139. (select-window win))))
  6140. (defun org-agenda-show-1 (&optional more)
  6141. "Display the Org-mode file which contains the item at point.
  6142. The prefix arg selects the amount of information to display:
  6143. 0 hide the subtree
  6144. 1 just show the entry according to defaults.
  6145. 2 show the children view
  6146. 3 show the subtree view
  6147. 4 show the entire subtree and any LOGBOOK drawers
  6148. 5 show the entire subtree and any drawers
  6149. With prefix argument FULL-ENTRY, make the entire entry visible
  6150. if it was hidden in the outline."
  6151. (interactive "p")
  6152. (let ((win (selected-window)))
  6153. (org-agenda-goto t)
  6154. (org-recenter-heading 1)
  6155. (cond
  6156. ((= more 0)
  6157. (hide-subtree)
  6158. (save-excursion
  6159. (org-back-to-heading)
  6160. (run-hook-with-args 'org-cycle-hook 'folded))
  6161. (message "Remote: FOLDED"))
  6162. ((and (interactive-p) (= more 1))
  6163. (message "Remote: show with default settings"))
  6164. ((= more 2)
  6165. (show-entry)
  6166. (show-children)
  6167. (save-excursion
  6168. (org-back-to-heading)
  6169. (run-hook-with-args 'org-cycle-hook 'children))
  6170. (message "Remote: CHILDREN"))
  6171. ((= more 3)
  6172. (show-subtree)
  6173. (save-excursion
  6174. (org-back-to-heading)
  6175. (run-hook-with-args 'org-cycle-hook 'subtree))
  6176. (message "Remote: SUBTREE"))
  6177. ((= more 4)
  6178. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6179. (org-drawer-regexp
  6180. (concat "^[ \t]*:\\("
  6181. (mapconcat 'regexp-quote org-drawers "\\|")
  6182. "\\):[ \t]*$")))
  6183. (show-subtree)
  6184. (save-excursion
  6185. (org-back-to-heading)
  6186. (org-cycle-hide-drawers 'subtree)))
  6187. (message "Remote: SUBTREE AND LOGBOOK"))
  6188. ((> more 4)
  6189. (show-subtree)
  6190. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6191. (select-window win)))
  6192. (defun org-recenter-heading (n)
  6193. (save-excursion
  6194. (org-back-to-heading)
  6195. (recenter n)))
  6196. (defvar org-agenda-cycle-counter nil)
  6197. (defun org-agenda-cycle-show (&optional n)
  6198. "Show the current entry in another window, with default settings.
  6199. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6200. When use repeatedly in immediate succession, the remote entry will cycle
  6201. through visibility
  6202. children -> subtree -> folded
  6203. When called with a numeric prefix arg, that arg will be passed through to
  6204. `org-agenda-show-1'. For the interpretation of that argument, see the
  6205. docstring of `org-agenda-show-1'."
  6206. (interactive "P")
  6207. (if (integerp n)
  6208. (setq org-agenda-cycle-counter n)
  6209. (if (not (eq last-command this-command))
  6210. (setq org-agenda-cycle-counter 1)
  6211. (if (equal org-agenda-cycle-counter 0)
  6212. (setq org-agenda-cycle-counter 2)
  6213. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6214. (if (> org-agenda-cycle-counter 3)
  6215. (setq org-agenda-cycle-counter 0)))))
  6216. (org-agenda-show-1 org-agenda-cycle-counter))
  6217. (defun org-agenda-recenter (arg)
  6218. "Display the Org-mode file which contains the item at point and recenter."
  6219. (interactive "P")
  6220. (let ((win (selected-window)))
  6221. (org-agenda-goto t)
  6222. (recenter arg)
  6223. (select-window win)))
  6224. (defun org-agenda-show-mouse (ev)
  6225. "Display the Org-mode file which contains the item at the mouse click."
  6226. (interactive "e")
  6227. (mouse-set-point ev)
  6228. (org-agenda-show))
  6229. (defun org-agenda-check-no-diary ()
  6230. "Check if the entry is a diary link and abort if yes."
  6231. (if (org-get-at-bol 'org-agenda-diary-link)
  6232. (org-agenda-error)))
  6233. (defun org-agenda-error ()
  6234. (error "Command not allowed in this line"))
  6235. (defun org-agenda-tree-to-indirect-buffer ()
  6236. "Show the subtree corresponding to the current entry in an indirect buffer.
  6237. This calls the command `org-tree-to-indirect-buffer' from the original
  6238. Org-mode buffer.
  6239. With numerical prefix arg ARG, go up to this level and then take that tree.
  6240. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6241. use the dedicated frame)."
  6242. (interactive)
  6243. (org-agenda-check-no-diary)
  6244. (let* ((marker (or (org-get-at-bol 'org-marker)
  6245. (org-agenda-error)))
  6246. (buffer (marker-buffer marker))
  6247. (pos (marker-position marker)))
  6248. (with-current-buffer buffer
  6249. (save-excursion
  6250. (goto-char pos)
  6251. (call-interactively 'org-tree-to-indirect-buffer)))))
  6252. (defvar org-last-heading-marker (make-marker)
  6253. "Marker pointing to the headline that last changed its TODO state
  6254. by a remote command from the agenda.")
  6255. (defun org-agenda-todo-nextset ()
  6256. "Switch TODO entry to next sequence."
  6257. (interactive)
  6258. (org-agenda-todo 'nextset))
  6259. (defun org-agenda-todo-previousset ()
  6260. "Switch TODO entry to previous sequence."
  6261. (interactive)
  6262. (org-agenda-todo 'previousset))
  6263. (defun org-agenda-todo (&optional arg)
  6264. "Cycle TODO state of line at point, also in Org-mode file.
  6265. This changes the line at point, all other lines in the agenda referring to
  6266. the same tree node, and the headline of the tree node in the Org-mode file."
  6267. (interactive "P")
  6268. (org-agenda-check-no-diary)
  6269. (let* ((col (current-column))
  6270. (marker (or (org-get-at-bol 'org-marker)
  6271. (org-agenda-error)))
  6272. (buffer (marker-buffer marker))
  6273. (pos (marker-position marker))
  6274. (hdmarker (org-get-at-bol 'org-hd-marker))
  6275. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6276. (inhibit-read-only t)
  6277. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6278. (org-with-remote-undo buffer
  6279. (with-current-buffer buffer
  6280. (widen)
  6281. (goto-char pos)
  6282. (org-show-context 'agenda)
  6283. (save-excursion
  6284. (and (outline-next-heading)
  6285. (org-flag-heading nil))) ; show the next heading
  6286. (let ((current-prefix-arg arg))
  6287. (call-interactively 'org-todo))
  6288. (and (bolp) (forward-char 1))
  6289. (setq newhead (org-get-heading))
  6290. (when (and (org-bound-and-true-p
  6291. org-agenda-headline-snapshot-before-repeat)
  6292. (not (equal org-agenda-headline-snapshot-before-repeat
  6293. newhead))
  6294. todayp)
  6295. (setq newhead org-agenda-headline-snapshot-before-repeat
  6296. just-one t))
  6297. (save-excursion
  6298. (org-back-to-heading)
  6299. (move-marker org-last-heading-marker (point))))
  6300. (beginning-of-line 1)
  6301. (save-excursion
  6302. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6303. (org-move-to-column col))))
  6304. (defun org-agenda-add-note (&optional arg)
  6305. "Add a time-stamped note to the entry at point."
  6306. (interactive "P")
  6307. (org-agenda-check-no-diary)
  6308. (let* ((marker (or (org-get-at-bol 'org-marker)
  6309. (org-agenda-error)))
  6310. (buffer (marker-buffer marker))
  6311. (pos (marker-position marker))
  6312. (hdmarker (org-get-at-bol 'org-hd-marker))
  6313. (inhibit-read-only t))
  6314. (with-current-buffer buffer
  6315. (widen)
  6316. (goto-char pos)
  6317. (org-show-context 'agenda)
  6318. (save-excursion
  6319. (and (outline-next-heading)
  6320. (org-flag-heading nil))) ; show the next heading
  6321. (org-add-note))))
  6322. (defun org-agenda-change-all-lines (newhead hdmarker
  6323. &optional fixface just-this)
  6324. "Change all lines in the agenda buffer which match HDMARKER.
  6325. The new content of the line will be NEWHEAD (as modified by
  6326. `org-format-agenda-item'). HDMARKER is checked with
  6327. `equal' against all `org-hd-marker' text properties in the file.
  6328. If FIXFACE is non-nil, the face of each item is modified according to
  6329. the new TODO state.
  6330. If JUST-THIS is non-nil, change just the current line, not all.
  6331. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6332. (let* ((inhibit-read-only t)
  6333. (line (org-current-line))
  6334. (thetags (with-current-buffer (marker-buffer hdmarker)
  6335. (save-excursion (save-restriction (widen)
  6336. (goto-char hdmarker)
  6337. (org-get-tags-at)))))
  6338. props m pl undone-face done-face finish new dotime cat tags)
  6339. (save-excursion
  6340. (goto-char (point-max))
  6341. (beginning-of-line 1)
  6342. (while (not finish)
  6343. (setq finish (bobp))
  6344. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6345. (or (not just-this) (= (org-current-line) line))
  6346. (equal m hdmarker))
  6347. (setq props (text-properties-at (point))
  6348. dotime (org-get-at-bol 'dotime)
  6349. cat (org-get-at-bol 'org-category)
  6350. tags thetags
  6351. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  6352. pl (org-get-at-bol 'prefix-length)
  6353. undone-face (org-get-at-bol 'undone-face)
  6354. done-face (org-get-at-bol 'done-face))
  6355. (goto-char (+ (point) pl))
  6356. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  6357. (cond
  6358. ((equal new "")
  6359. (beginning-of-line 1)
  6360. (and (looking-at ".*\n?") (replace-match "")))
  6361. ((looking-at ".*")
  6362. (replace-match new t t)
  6363. (beginning-of-line 1)
  6364. (add-text-properties (point-at-bol) (point-at-eol) props)
  6365. (when fixface
  6366. (add-text-properties
  6367. (point-at-bol) (point-at-eol)
  6368. (list 'face
  6369. (if org-last-todo-state-is-todo
  6370. undone-face done-face))))
  6371. (org-agenda-highlight-todo 'line)
  6372. (beginning-of-line 1))
  6373. (t (error "Line update did not work"))))
  6374. (beginning-of-line 0)))
  6375. (org-finalize-agenda)))
  6376. (defun org-agenda-align-tags (&optional line)
  6377. "Align all tags in agenda items to `org-agenda-tags-column'."
  6378. (let ((inhibit-read-only t) l c)
  6379. (save-excursion
  6380. (goto-char (if line (point-at-bol) (point-min)))
  6381. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6382. (if line (point-at-eol) nil) t)
  6383. (add-text-properties
  6384. (match-beginning 2) (match-end 2)
  6385. (list 'face (delq nil (let ((prop (get-text-property
  6386. (match-beginning 2) 'face)))
  6387. (or (listp prop) (setq prop (list prop)))
  6388. (if (memq 'org-tag prop)
  6389. prop
  6390. (cons 'org-tag prop))))))
  6391. (setq l (- (match-end 2) (match-beginning 2))
  6392. c (if (< org-agenda-tags-column 0)
  6393. (- (abs org-agenda-tags-column) l)
  6394. org-agenda-tags-column))
  6395. (delete-region (match-beginning 1) (match-end 1))
  6396. (goto-char (match-beginning 1))
  6397. (insert (org-add-props
  6398. (make-string (max 1 (- c (current-column))) ?\ )
  6399. (plist-put (copy-sequence (text-properties-at (point)))
  6400. 'face nil))))
  6401. (goto-char (point-min))
  6402. (org-font-lock-add-tag-faces (point-max)))))
  6403. (defun org-agenda-priority-up ()
  6404. "Increase the priority of line at point, also in Org-mode file."
  6405. (interactive)
  6406. (org-agenda-priority 'up))
  6407. (defun org-agenda-priority-down ()
  6408. "Decrease the priority of line at point, also in Org-mode file."
  6409. (interactive)
  6410. (org-agenda-priority 'down))
  6411. (defun org-agenda-priority (&optional force-direction)
  6412. "Set the priority of line at point, also in Org-mode file.
  6413. This changes the line at point, all other lines in the agenda referring to
  6414. the same tree node, and the headline of the tree node in the Org-mode file."
  6415. (interactive)
  6416. (unless org-enable-priority-commands
  6417. (error "Priority commands are disabled"))
  6418. (org-agenda-check-no-diary)
  6419. (let* ((marker (or (org-get-at-bol 'org-marker)
  6420. (org-agenda-error)))
  6421. (hdmarker (org-get-at-bol 'org-hd-marker))
  6422. (buffer (marker-buffer hdmarker))
  6423. (pos (marker-position hdmarker))
  6424. (inhibit-read-only t)
  6425. newhead)
  6426. (org-with-remote-undo buffer
  6427. (with-current-buffer buffer
  6428. (widen)
  6429. (goto-char pos)
  6430. (org-show-context 'agenda)
  6431. (save-excursion
  6432. (and (outline-next-heading)
  6433. (org-flag-heading nil))) ; show the next heading
  6434. (funcall 'org-priority force-direction)
  6435. (end-of-line 1)
  6436. (setq newhead (org-get-heading)))
  6437. (org-agenda-change-all-lines newhead hdmarker)
  6438. (beginning-of-line 1))))
  6439. ;; FIXME: should fix the tags property of the agenda line.
  6440. (defun org-agenda-set-tags (&optional tag onoff)
  6441. "Set tags for the current headline."
  6442. (interactive)
  6443. (org-agenda-check-no-diary)
  6444. (if (and (org-region-active-p) (interactive-p))
  6445. (call-interactively 'org-change-tag-in-region)
  6446. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6447. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6448. (org-agenda-error)))
  6449. (buffer (marker-buffer hdmarker))
  6450. (pos (marker-position hdmarker))
  6451. (inhibit-read-only t)
  6452. newhead)
  6453. (org-with-remote-undo buffer
  6454. (with-current-buffer buffer
  6455. (widen)
  6456. (goto-char pos)
  6457. (save-excursion
  6458. (org-show-context 'agenda))
  6459. (save-excursion
  6460. (and (outline-next-heading)
  6461. (org-flag-heading nil))) ; show the next heading
  6462. (goto-char pos)
  6463. (if tag
  6464. (org-toggle-tag tag onoff)
  6465. (call-interactively 'org-set-tags))
  6466. (end-of-line 1)
  6467. (setq newhead (org-get-heading)))
  6468. (org-agenda-change-all-lines newhead hdmarker)
  6469. (beginning-of-line 1)))))
  6470. (defun org-agenda-set-property ()
  6471. "Set a property for the current headline."
  6472. (interactive)
  6473. (org-agenda-check-no-diary)
  6474. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6475. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6476. (org-agenda-error)))
  6477. (buffer (marker-buffer hdmarker))
  6478. (pos (marker-position hdmarker))
  6479. (inhibit-read-only t)
  6480. newhead)
  6481. (org-with-remote-undo buffer
  6482. (with-current-buffer buffer
  6483. (widen)
  6484. (goto-char pos)
  6485. (save-excursion
  6486. (org-show-context 'agenda))
  6487. (save-excursion
  6488. (and (outline-next-heading)
  6489. (org-flag-heading nil))) ; show the next heading
  6490. (goto-char pos)
  6491. (call-interactively 'org-set-property)))))
  6492. (defun org-agenda-set-effort ()
  6493. "Set the effort property for the current headline."
  6494. (interactive)
  6495. (org-agenda-check-no-diary)
  6496. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6497. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6498. (org-agenda-error)))
  6499. (buffer (marker-buffer hdmarker))
  6500. (pos (marker-position hdmarker))
  6501. (inhibit-read-only t)
  6502. newhead)
  6503. (org-with-remote-undo buffer
  6504. (with-current-buffer buffer
  6505. (widen)
  6506. (goto-char pos)
  6507. (save-excursion
  6508. (org-show-context 'agenda))
  6509. (save-excursion
  6510. (and (outline-next-heading)
  6511. (org-flag-heading nil))) ; show the next heading
  6512. (goto-char pos)
  6513. (call-interactively 'org-set-effort)
  6514. (end-of-line 1)))))
  6515. (defun org-agenda-toggle-archive-tag ()
  6516. "Toggle the archive tag for the current entry."
  6517. (interactive)
  6518. (org-agenda-check-no-diary)
  6519. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6520. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6521. (org-agenda-error)))
  6522. (buffer (marker-buffer hdmarker))
  6523. (pos (marker-position hdmarker))
  6524. (inhibit-read-only t)
  6525. newhead)
  6526. (org-with-remote-undo buffer
  6527. (with-current-buffer buffer
  6528. (widen)
  6529. (goto-char pos)
  6530. (org-show-context 'agenda)
  6531. (save-excursion
  6532. (and (outline-next-heading)
  6533. (org-flag-heading nil))) ; show the next heading
  6534. (call-interactively 'org-toggle-archive-tag)
  6535. (end-of-line 1)
  6536. (setq newhead (org-get-heading)))
  6537. (org-agenda-change-all-lines newhead hdmarker)
  6538. (beginning-of-line 1))))
  6539. (defun org-agenda-do-date-later (arg)
  6540. (interactive "P")
  6541. (cond
  6542. ((or (equal arg '(16))
  6543. (memq last-command
  6544. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6545. (setq this-command 'org-agenda-date-later-minutes)
  6546. (org-agenda-date-later-minutes 1))
  6547. ((or (equal arg '(4))
  6548. (memq last-command
  6549. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6550. (setq this-command 'org-agenda-date-later-hours)
  6551. (org-agenda-date-later-hours 1))
  6552. (t
  6553. (org-agenda-date-later (prefix-numeric-value arg)))))
  6554. (defun org-agenda-do-date-earlier (arg)
  6555. (interactive "P")
  6556. (cond
  6557. ((or (equal arg '(16))
  6558. (memq last-command
  6559. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6560. (setq this-command 'org-agenda-date-earlier-minutes)
  6561. (org-agenda-date-earlier-minutes 1))
  6562. ((or (equal arg '(4))
  6563. (memq last-command
  6564. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6565. (setq this-command 'org-agenda-date-earlier-hours)
  6566. (org-agenda-date-earlier-hours 1))
  6567. (t
  6568. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6569. (defun org-agenda-date-later (arg &optional what)
  6570. "Change the date of this item to one day later."
  6571. (interactive "p")
  6572. (org-agenda-check-type t 'agenda 'timeline)
  6573. (org-agenda-check-no-diary)
  6574. (let* ((marker (or (org-get-at-bol 'org-marker)
  6575. (org-agenda-error)))
  6576. (buffer (marker-buffer marker))
  6577. (pos (marker-position marker)))
  6578. (org-with-remote-undo buffer
  6579. (with-current-buffer buffer
  6580. (widen)
  6581. (goto-char pos)
  6582. (if (not (org-at-timestamp-p))
  6583. (error "Cannot find time stamp"))
  6584. (org-timestamp-change arg (or what 'day)))
  6585. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6586. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6587. (defun org-agenda-date-earlier (arg &optional what)
  6588. "Change the date of this item to one day earlier."
  6589. (interactive "p")
  6590. (org-agenda-date-later (- arg) what))
  6591. (defun org-agenda-date-later-minutes (arg)
  6592. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6593. (interactive "p")
  6594. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6595. (org-agenda-date-later arg 'minute))
  6596. (defun org-agenda-date-earlier-minutes (arg)
  6597. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6598. (interactive "p")
  6599. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6600. (org-agenda-date-earlier arg 'minute))
  6601. (defun org-agenda-date-later-hours (arg)
  6602. "Change the time of this item, in hour steps."
  6603. (interactive "p")
  6604. (org-agenda-date-later arg 'hour))
  6605. (defun org-agenda-date-earlier-hours (arg)
  6606. "Change the time of this item, in hour steps."
  6607. (interactive "p")
  6608. (org-agenda-date-earlier arg 'hour))
  6609. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6610. "Show new date stamp via text properties."
  6611. ;; We use text properties to make this undoable
  6612. (let ((inhibit-read-only t)
  6613. (buffer-invisibility-spec))
  6614. (setq stamp (concat " " prefix " => " stamp))
  6615. (save-excursion
  6616. (goto-char (point-max))
  6617. (while (not (bobp))
  6618. (when (equal marker (org-get-at-bol 'org-marker))
  6619. (org-move-to-column (- (window-width) (length stamp)) t)
  6620. (org-agenda-fix-tags-filter-overlays-at (point))
  6621. (if (featurep 'xemacs)
  6622. ;; Use `duplicable' property to trigger undo recording
  6623. (let ((ex (make-extent nil nil))
  6624. (gl (make-glyph stamp)))
  6625. (set-glyph-face gl 'secondary-selection)
  6626. (set-extent-properties
  6627. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6628. (insert-extent ex (1- (point)) (point-at-eol)))
  6629. (add-text-properties
  6630. (1- (point)) (point-at-eol)
  6631. (list 'display (org-add-props stamp nil
  6632. 'face 'secondary-selection))))
  6633. (beginning-of-line 1))
  6634. (beginning-of-line 0)))))
  6635. (defun org-agenda-date-prompt (arg)
  6636. "Change the date of this item. Date is prompted for, with default today.
  6637. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6638. be used to request time specification in the time stamp."
  6639. (interactive "P")
  6640. (org-agenda-check-type t 'agenda 'timeline)
  6641. (org-agenda-check-no-diary)
  6642. (let* ((marker (or (org-get-at-bol 'org-marker)
  6643. (org-agenda-error)))
  6644. (buffer (marker-buffer marker))
  6645. (pos (marker-position marker)))
  6646. (org-with-remote-undo buffer
  6647. (with-current-buffer buffer
  6648. (widen)
  6649. (goto-char pos)
  6650. (if (not (org-at-timestamp-p t))
  6651. (error "Cannot find time stamp"))
  6652. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6653. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6654. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6655. (defun org-agenda-schedule (arg)
  6656. "Schedule the item at point.
  6657. Arg is passed through to `org-schedule'."
  6658. (interactive "P")
  6659. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6660. (org-agenda-check-no-diary)
  6661. (let* ((marker (or (org-get-at-bol 'org-marker)
  6662. (org-agenda-error)))
  6663. (type (marker-insertion-type marker))
  6664. (buffer (marker-buffer marker))
  6665. (pos (marker-position marker))
  6666. (org-insert-labeled-timestamps-at-point nil)
  6667. ts)
  6668. (set-marker-insertion-type marker t)
  6669. (org-with-remote-undo buffer
  6670. (with-current-buffer buffer
  6671. (widen)
  6672. (goto-char pos)
  6673. (setq ts (org-schedule arg)))
  6674. (org-agenda-show-new-time marker ts "S"))
  6675. (message "Item scheduled for %s" ts)))
  6676. (defun org-agenda-deadline (arg)
  6677. "Schedule the item at point.
  6678. Arg is passed through to `org-deadline'."
  6679. (interactive "P")
  6680. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6681. (org-agenda-check-no-diary)
  6682. (let* ((marker (or (org-get-at-bol 'org-marker)
  6683. (org-agenda-error)))
  6684. (buffer (marker-buffer marker))
  6685. (pos (marker-position marker))
  6686. (org-insert-labeled-timestamps-at-point nil)
  6687. ts)
  6688. (org-with-remote-undo buffer
  6689. (with-current-buffer buffer
  6690. (widen)
  6691. (goto-char pos)
  6692. (setq ts (org-deadline arg)))
  6693. (org-agenda-show-new-time marker ts "D"))
  6694. (message "Deadline for this item set to %s" ts)))
  6695. (defun org-agenda-action ()
  6696. "Select entry for agenda action, or execute an agenda action.
  6697. This command prompts for another letter. Valid inputs are:
  6698. m Mark the entry at point for an agenda action
  6699. s Schedule the marked entry to the date at the cursor
  6700. d Set the deadline of the marked entry to the date at the cursor
  6701. r Call `org-remember' with cursor date as the default date
  6702. c Call `org-capture' with cursor date as the default date
  6703. SPC Show marked entry in other window
  6704. TAB Visit marked entry in other window
  6705. The cursor may be at a date in the calendar, or in the Org agenda."
  6706. (interactive)
  6707. (let (ans)
  6708. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  6709. (setq ans (read-char-exclusive))
  6710. (cond
  6711. ((equal ans ?m)
  6712. ;; Mark this entry
  6713. (if (eq major-mode 'org-agenda-mode)
  6714. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6715. (org-get-at-bol 'org-marker))))
  6716. (if m
  6717. (progn
  6718. (move-marker org-agenda-action-marker
  6719. (marker-position m) (marker-buffer m))
  6720. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6721. (error "Don't know which entry to mark")))
  6722. (error "This command works only in the agenda")))
  6723. ((equal ans ?s)
  6724. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6725. ((equal ans ?d)
  6726. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6727. ((equal ans ?r)
  6728. (org-agenda-do-action '(org-remember) t))
  6729. ((equal ans ?c)
  6730. (org-agenda-do-action '(org-capture) t))
  6731. ((equal ans ?\ )
  6732. (let ((cw (selected-window)))
  6733. (org-switch-to-buffer-other-window
  6734. (marker-buffer org-agenda-action-marker))
  6735. (goto-char org-agenda-action-marker)
  6736. (org-show-context 'agenda)
  6737. (select-window cw)))
  6738. ((equal ans ?\C-i)
  6739. (org-switch-to-buffer-other-window
  6740. (marker-buffer org-agenda-action-marker))
  6741. (goto-char org-agenda-action-marker)
  6742. (org-show-context 'agenda))
  6743. (t (error "Invalid agenda action %c" ans)))))
  6744. (defun org-agenda-do-action (form &optional current-buffer)
  6745. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6746. (let ((org-overriding-default-time (org-get-cursor-date)))
  6747. (if current-buffer
  6748. (eval form)
  6749. (if (not (marker-buffer org-agenda-action-marker))
  6750. (error "No entry has been selected for agenda action")
  6751. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6752. (save-excursion
  6753. (save-restriction
  6754. (widen)
  6755. (goto-char org-agenda-action-marker)
  6756. (eval form))))))))
  6757. (defun org-agenda-clock-in (&optional arg)
  6758. "Start the clock on the currently selected item."
  6759. (interactive "P")
  6760. (org-agenda-check-no-diary)
  6761. (if (equal arg '(4))
  6762. (org-clock-in arg)
  6763. (let* ((marker (or (org-get-at-bol 'org-marker)
  6764. (org-agenda-error)))
  6765. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6766. marker))
  6767. (pos (marker-position marker))
  6768. newhead)
  6769. (org-with-remote-undo (marker-buffer marker)
  6770. (with-current-buffer (marker-buffer marker)
  6771. (widen)
  6772. (goto-char pos)
  6773. (org-show-context 'agenda)
  6774. (org-show-entry)
  6775. (org-cycle-hide-drawers 'children)
  6776. (org-clock-in arg)
  6777. (setq newhead (org-get-heading)))
  6778. (org-agenda-change-all-lines newhead hdmarker)))))
  6779. (defun org-agenda-clock-out ()
  6780. "Stop the currently running clock."
  6781. (interactive)
  6782. (unless (marker-buffer org-clock-marker)
  6783. (error "No running clock"))
  6784. (let ((marker (make-marker)) newhead)
  6785. (org-with-remote-undo (marker-buffer org-clock-marker)
  6786. (with-current-buffer (marker-buffer org-clock-marker)
  6787. (save-excursion
  6788. (save-restriction
  6789. (widen)
  6790. (goto-char org-clock-marker)
  6791. (org-back-to-heading t)
  6792. (move-marker marker (point))
  6793. (org-clock-out)
  6794. (setq newhead (org-get-heading))))))
  6795. (org-agenda-change-all-lines newhead marker)
  6796. (move-marker marker nil)))
  6797. (defun org-agenda-clock-cancel (&optional arg)
  6798. "Cancel the currently running clock."
  6799. (interactive "P")
  6800. (unless (marker-buffer org-clock-marker)
  6801. (error "No running clock"))
  6802. (org-with-remote-undo (marker-buffer org-clock-marker)
  6803. (org-clock-cancel)))
  6804. (defun org-agenda-clock-goto ()
  6805. "Jump to the currently clocked in task within the agenda.
  6806. If the currently clocked in task is not listed in the agenda
  6807. buffer, display it in another window."
  6808. (interactive)
  6809. (let (pos)
  6810. (mapc (lambda (o)
  6811. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  6812. (setq pos (overlay-start o))))
  6813. (overlays-in (point-min) (point-max)))
  6814. (cond (pos (goto-char pos))
  6815. ;; If the currently clocked entry is not in the agenda
  6816. ;; buffer, we visit it in another window:
  6817. (org-clock-current-task
  6818. (org-switch-to-buffer-other-window (org-clock-goto)))
  6819. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  6820. (defun org-agenda-diary-entry-in-org-file ()
  6821. "Make a diary entry in the file `org-agenda-diary-file'."
  6822. (let (d1 d2 char (text "") dp1 dp2)
  6823. (if (equal (buffer-name) "*Calendar*")
  6824. (setq d1 (calendar-cursor-to-date t)
  6825. d2 (car calendar-mark-ring))
  6826. (setq dp1 (get-text-property (point-at-bol) 'day))
  6827. (unless dp1 (error "No date defined in current line"))
  6828. (setq d1 (calendar-gregorian-from-absolute dp1)
  6829. d2 (and (ignore-errors (mark))
  6830. (save-excursion
  6831. (goto-char (mark))
  6832. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6833. (calendar-gregorian-from-absolute dp2))))
  6834. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6835. (setq char (read-char-exclusive))
  6836. (cond
  6837. ((equal char ?d)
  6838. (setq text (read-string "Day entry: "))
  6839. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6840. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6841. ((equal char ?a)
  6842. (setq d1 (list (car d1) (nth 1 d1)
  6843. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6844. (nth 2 d1))))
  6845. (setq text (read-string "Anniversary (use %d to show years): "))
  6846. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6847. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6848. ((equal char ?b)
  6849. (setq text (read-string "Block entry: "))
  6850. (unless (and d1 d2 (not (equal d1 d2)))
  6851. (error "No block of days selected"))
  6852. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6853. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6854. ((equal char ?j)
  6855. (org-switch-to-buffer-other-window
  6856. (find-file-noselect org-agenda-diary-file))
  6857. (require 'org-datetree)
  6858. (org-datetree-find-date-create d1)
  6859. (org-reveal t))
  6860. (t (error "Invalid selection character `%c'" char)))))
  6861. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6862. "Where in `org-agenda-diary-file' should new entries be added?
  6863. Valid values:
  6864. date-tree in the date tree, as child of the date
  6865. top-level as top-level entries at the end of the file."
  6866. :group 'org-agenda
  6867. :type '(choice
  6868. (const :tag "in a date tree" date-tree)
  6869. (const :tag "as top level at end of file" top-level)))
  6870. (defcustom org-agenda-insert-diary-extract-time nil
  6871. "Non-nil means extract any time specification from the diary entry."
  6872. :group 'org-agenda
  6873. :type 'boolean)
  6874. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6875. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6876. If TEXT is not empty, it will become the headline of the new entry, and
  6877. the resulting entry will not be shown. When TEXT is empty, switch to
  6878. `org-agenda-diary-file' and let the user finish the entry there."
  6879. (let ((cw (current-window-configuration)))
  6880. (org-switch-to-buffer-other-window
  6881. (find-file-noselect org-agenda-diary-file))
  6882. (widen)
  6883. (goto-char (point-min))
  6884. (cond
  6885. ((eq type 'anniversary)
  6886. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6887. (progn
  6888. (or (org-on-heading-p t)
  6889. (progn
  6890. (outline-next-heading)
  6891. (insert "* Anniversaries\n\n")
  6892. (beginning-of-line -1)))))
  6893. (outline-next-heading)
  6894. (org-back-over-empty-lines)
  6895. (backward-char 1)
  6896. (insert "\n")
  6897. (require 'diary-lib)
  6898. (let ((calendar-date-display-form
  6899. (if (if (boundp 'calendar-date-style)
  6900. (eq calendar-date-style 'european)
  6901. (with-no-warnings ;; european-calendar-style is obsolete as of version 23.1
  6902. (org-bound-and-true-p european-calendar-style))) ; Emacs 22
  6903. '(day " " month " " year)
  6904. '(month " " day " " year))))
  6905. (insert (format "%%%%(diary-anniversary %s) %s"
  6906. (calendar-date-string d1 nil t) text))))
  6907. ((eq type 'day)
  6908. (let ((org-prefix-has-time t)
  6909. (org-agenda-time-leading-zero t)
  6910. fmt time time2)
  6911. (if org-agenda-insert-diary-extract-time
  6912. ;; Use org-format-agenda-item to parse text for a time-range and
  6913. ;; remove it. FIXME: This is a hack, we should refactor
  6914. ;; that function to make time extraction available separately
  6915. (setq fmt (org-format-agenda-item nil text nil nil t)
  6916. time (get-text-property 0 'time fmt)
  6917. time2 (if (> (length time) 0)
  6918. ;; split-string removes trailing ...... if
  6919. ;; no end time given. First space
  6920. ;; separates time from date.
  6921. (concat " " (car (split-string time "\\.")))
  6922. nil)
  6923. text (get-text-property 0 'txt fmt)))
  6924. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6925. (org-agenda-insert-diary-as-top-level text)
  6926. (require 'org-datetree)
  6927. (org-datetree-find-date-create d1)
  6928. (org-agenda-insert-diary-make-new-entry text))
  6929. (org-insert-time-stamp (org-time-from-absolute
  6930. (calendar-absolute-from-gregorian d1))
  6931. nil nil nil nil time2))
  6932. (end-of-line 0))
  6933. ((eq type 'block)
  6934. (if (> (calendar-absolute-from-gregorian d1)
  6935. (calendar-absolute-from-gregorian d2))
  6936. (setq d1 (prog1 d2 (setq d2 d1))))
  6937. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6938. (org-agenda-insert-diary-as-top-level text)
  6939. (require 'org-datetree)
  6940. (org-datetree-find-date-create d1)
  6941. (org-agenda-insert-diary-make-new-entry text))
  6942. (org-insert-time-stamp (org-time-from-absolute
  6943. (calendar-absolute-from-gregorian d1)))
  6944. (insert "--")
  6945. (org-insert-time-stamp (org-time-from-absolute
  6946. (calendar-absolute-from-gregorian d2)))
  6947. (end-of-line 0)))
  6948. (if (string-match "\\S-" text)
  6949. (progn
  6950. (set-window-configuration cw)
  6951. (message "%s entry added to %s"
  6952. (capitalize (symbol-name type))
  6953. (abbreviate-file-name org-agenda-diary-file)))
  6954. (org-reveal t)
  6955. (message "Please finish entry here"))))
  6956. (defun org-agenda-insert-diary-as-top-level (text)
  6957. "Make new entry as a top-level entry at the end of the file.
  6958. Add TEXT as headline, and position the cursor in the second line so that
  6959. a timestamp can be added there."
  6960. (widen)
  6961. (goto-char (point-max))
  6962. (or (bolp) (insert "\n"))
  6963. (insert "* " text "\n")
  6964. (if org-adapt-indentation (org-indent-to-column 2)))
  6965. (defun org-agenda-insert-diary-make-new-entry (text)
  6966. "Make new entry as last child of current entry.
  6967. Add TEXT as headline, and position the cursor in the second line so that
  6968. a timestamp can be added there."
  6969. (let ((org-show-following-heading t)
  6970. (org-show-siblings t)
  6971. (org-show-hierarchy-above t)
  6972. (org-show-entry-below t)
  6973. col)
  6974. (outline-next-heading)
  6975. (org-back-over-empty-lines)
  6976. (or (looking-at "[ \t]*$")
  6977. (progn (insert "\n") (backward-char 1)))
  6978. (org-insert-heading nil t)
  6979. (org-do-demote)
  6980. (setq col (current-column))
  6981. (insert text "\n")
  6982. (if org-adapt-indentation (org-indent-to-column col))
  6983. (let ((org-show-following-heading t)
  6984. (org-show-siblings t)
  6985. (org-show-hierarchy-above t)
  6986. (org-show-entry-below t))
  6987. (org-show-context))))
  6988. (defun org-agenda-diary-entry ()
  6989. "Make a diary entry, like the `i' command from the calendar.
  6990. All the standard commands work: block, weekly etc.
  6991. When `org-agenda-diary-file' points to a file,
  6992. `org-agenda-diary-entry-in-org-file' is called instead to create
  6993. entries in that Org-mode file."
  6994. (interactive)
  6995. (org-agenda-check-type t 'agenda 'timeline)
  6996. (if (not (eq org-agenda-diary-file 'diary-file))
  6997. (org-agenda-diary-entry-in-org-file)
  6998. (require 'diary-lib)
  6999. (let* ((char (progn
  7000. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7001. (read-char-exclusive)))
  7002. (cmd (cdr (assoc char
  7003. '((?d . insert-diary-entry)
  7004. (?w . insert-weekly-diary-entry)
  7005. (?m . insert-monthly-diary-entry)
  7006. (?y . insert-yearly-diary-entry)
  7007. (?a . insert-anniversary-diary-entry)
  7008. (?b . insert-block-diary-entry)
  7009. (?c . insert-cyclic-diary-entry)))))
  7010. (oldf (symbol-function 'calendar-cursor-to-date))
  7011. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7012. (point (point))
  7013. (mark (or (mark t) (point))))
  7014. (unless cmd
  7015. (error "No command associated with <%c>" char))
  7016. (unless (and (get-text-property point 'day)
  7017. (or (not (equal ?b char))
  7018. (get-text-property mark 'day)))
  7019. (error "Don't know which date to use for diary entry"))
  7020. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7021. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7022. (let ((calendar-mark-ring
  7023. (list (calendar-gregorian-from-absolute
  7024. (or (get-text-property mark 'day)
  7025. (get-text-property point 'day))))))
  7026. (unwind-protect
  7027. (progn
  7028. (fset 'calendar-cursor-to-date
  7029. (lambda (&optional error dummy)
  7030. (calendar-gregorian-from-absolute
  7031. (get-text-property point 'day))))
  7032. (call-interactively cmd))
  7033. (fset 'calendar-cursor-to-date oldf))))))
  7034. (defun org-agenda-execute-calendar-command (cmd)
  7035. "Execute a calendar command from the agenda, with the date associated to
  7036. the cursor position."
  7037. (org-agenda-check-type t 'agenda 'timeline)
  7038. (require 'diary-lib)
  7039. (unless (get-text-property (point) 'day)
  7040. (error "Don't know which date to use for calendar command"))
  7041. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7042. (point (point))
  7043. (date (calendar-gregorian-from-absolute
  7044. (get-text-property point 'day)))
  7045. ;; the following 2 vars are needed in the calendar
  7046. (displayed-month (car date))
  7047. (displayed-year (nth 2 date)))
  7048. (unwind-protect
  7049. (progn
  7050. (fset 'calendar-cursor-to-date
  7051. (lambda (&optional error dummy)
  7052. (calendar-gregorian-from-absolute
  7053. (get-text-property point 'day))))
  7054. (call-interactively cmd))
  7055. (fset 'calendar-cursor-to-date oldf))))
  7056. (defun org-agenda-phases-of-moon ()
  7057. "Display the phases of the moon for the 3 months around the cursor date."
  7058. (interactive)
  7059. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7060. (defun org-agenda-holidays ()
  7061. "Display the holidays for the 3 months around the cursor date."
  7062. (interactive)
  7063. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7064. (defvar calendar-longitude)
  7065. (defvar calendar-latitude)
  7066. (defvar calendar-location-name)
  7067. (defun org-agenda-sunrise-sunset (arg)
  7068. "Display sunrise and sunset for the cursor date.
  7069. Latitude and longitude can be specified with the variables
  7070. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7071. argument, latitude and longitude will be prompted for."
  7072. (interactive "P")
  7073. (require 'solar)
  7074. (let ((calendar-longitude (if arg nil calendar-longitude))
  7075. (calendar-latitude (if arg nil calendar-latitude))
  7076. (calendar-location-name
  7077. (if arg "the given coordinates" calendar-location-name)))
  7078. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7079. (defun org-agenda-goto-calendar ()
  7080. "Open the Emacs calendar with the date at the cursor."
  7081. (interactive)
  7082. (org-agenda-check-type t 'agenda 'timeline)
  7083. (let* ((day (or (get-text-property (point) 'day)
  7084. (error "Don't know which date to open in calendar")))
  7085. (date (calendar-gregorian-from-absolute day))
  7086. (calendar-move-hook nil)
  7087. (calendar-view-holidays-initially-flag nil)
  7088. (calendar-view-diary-initially-flag nil))
  7089. (calendar)
  7090. (calendar-goto-date date)))
  7091. ;;;###autoload
  7092. (defun org-calendar-goto-agenda ()
  7093. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7094. This is a command that has to be installed in `calendar-mode-map'."
  7095. (interactive)
  7096. (org-agenda-list nil (calendar-absolute-from-gregorian
  7097. (calendar-cursor-to-date))
  7098. nil))
  7099. (defun org-agenda-convert-date ()
  7100. (interactive)
  7101. (org-agenda-check-type t 'agenda 'timeline)
  7102. (let ((day (get-text-property (point) 'day))
  7103. date s)
  7104. (unless day
  7105. (error "Don't know which date to convert"))
  7106. (setq date (calendar-gregorian-from-absolute day))
  7107. (setq s (concat
  7108. "Gregorian: " (calendar-date-string date) "\n"
  7109. "ISO: " (calendar-iso-date-string date) "\n"
  7110. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7111. "Julian: " (calendar-julian-date-string date) "\n"
  7112. "Astron. JD: " (calendar-astro-date-string date)
  7113. " (Julian date number at noon UTC)\n"
  7114. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7115. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7116. "French: " (calendar-french-date-string date) "\n"
  7117. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7118. "Mayan: " (calendar-mayan-date-string date) "\n"
  7119. "Coptic: " (calendar-coptic-date-string date) "\n"
  7120. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7121. "Persian: " (calendar-persian-date-string date) "\n"
  7122. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7123. (with-output-to-temp-buffer "*Dates*"
  7124. (princ s))
  7125. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7126. ;;; Bulk commands
  7127. (defvar org-agenda-bulk-marked-entries nil
  7128. "List of markers that refer to marked entries in the agenda.")
  7129. (defun org-agenda-bulk-marked-p ()
  7130. (eq (get-char-property (point-at-bol) 'type)
  7131. 'org-marked-entry-overlay))
  7132. (defun org-agenda-bulk-mark ()
  7133. "Mark the entry at point for future bulk action."
  7134. (interactive)
  7135. (org-agenda-check-no-diary)
  7136. (let* ((m (org-get-at-bol 'org-hd-marker))
  7137. ov)
  7138. (unless (org-agenda-bulk-marked-p)
  7139. (unless m (error "Nothing to mark at point"))
  7140. (push m org-agenda-bulk-marked-entries)
  7141. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7142. (org-overlay-display ov "> "
  7143. (org-get-todo-face "TODO")
  7144. 'evaporate)
  7145. (overlay-put ov 'type 'org-marked-entry-overlay))
  7146. (beginning-of-line 2)
  7147. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7148. (beginning-of-line 2))
  7149. (message "%d entries marked for bulk action"
  7150. (length org-agenda-bulk-marked-entries))))
  7151. (defun org-agenda-bulk-unmark ()
  7152. "Unmark the entry at point for future bulk action."
  7153. (interactive)
  7154. (when (org-agenda-bulk-marked-p)
  7155. (org-agenda-bulk-remove-overlays
  7156. (point-at-bol) (+ 2 (point-at-bol)))
  7157. (setq org-agenda-bulk-marked-entries
  7158. (delete (org-get-at-bol 'org-hd-marker)
  7159. org-agenda-bulk-marked-entries)))
  7160. (beginning-of-line 2)
  7161. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7162. (beginning-of-line 2))
  7163. (message "%d entries marked for bulk action"
  7164. (length org-agenda-bulk-marked-entries)))
  7165. (defun org-agenda-bulk-toggle ()
  7166. "Toggle marking the entry at point for bulk action."
  7167. (interactive)
  7168. (if (org-agenda-bulk-marked-p)
  7169. (org-agenda-bulk-unmark)
  7170. (org-agenda-bulk-mark)))
  7171. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7172. "Remove the mark overlays between BEG and END in the agenda buffer.
  7173. BEG and END default to the buffer limits.
  7174. This only removes the overlays, it does not remove the markers
  7175. from the list in `org-agenda-bulk-marked-entries'."
  7176. (interactive)
  7177. (mapc (lambda (ov)
  7178. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7179. (delete-overlay ov)))
  7180. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7181. (defun org-agenda-bulk-remove-all-marks ()
  7182. "Remove all marks in the agenda buffer.
  7183. This will remove the markers, and the overlays."
  7184. (interactive)
  7185. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7186. (setq org-agenda-bulk-marked-entries nil)
  7187. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7188. (defun org-agenda-bulk-action (&optional arg)
  7189. "Execute an remote-editing action on all marked entries.
  7190. The prefix arg is passed through to the command if possible."
  7191. (interactive "P")
  7192. (unless org-agenda-bulk-marked-entries
  7193. (error "No entries are marked"))
  7194. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  7195. (let* ((action (read-char-exclusive))
  7196. (org-log-refile (if org-log-refile 'time nil))
  7197. (entries (reverse org-agenda-bulk-marked-entries))
  7198. redo-at-end
  7199. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7200. (cond
  7201. ((equal action ?$)
  7202. (setq cmd '(org-agenda-archive)))
  7203. ((equal action ?A)
  7204. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7205. ((member action '(?r ?w))
  7206. (setq rfloc (org-refile-get-location
  7207. "Refile to: "
  7208. (marker-buffer (car org-agenda-bulk-marked-entries))
  7209. org-refile-allow-creating-parent-nodes))
  7210. (if (nth 3 rfloc)
  7211. (setcar (nthcdr 3 rfloc)
  7212. (move-marker (make-marker) (nth 3 rfloc)
  7213. (or (get-file-buffer (nth 1 rfloc))
  7214. (find-buffer-visiting (nth 1 rfloc))
  7215. (error "This should not happen")))))
  7216. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7217. redo-at-end t))
  7218. ((equal action ?t)
  7219. (setq state (org-icompleting-read
  7220. "Todo state: "
  7221. (with-current-buffer (marker-buffer (car entries))
  7222. (mapcar 'list org-todo-keywords-1))))
  7223. (setq cmd `(let ((org-inhibit-blocking t)
  7224. (org-inhibit-logging 'note))
  7225. (org-agenda-todo ,state))))
  7226. ((memq action '(?- ?+))
  7227. (setq tag (org-icompleting-read
  7228. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7229. (with-current-buffer (marker-buffer (car entries))
  7230. (delq nil
  7231. (mapcar (lambda (x)
  7232. (if (stringp (car x)) x)) org-tag-alist)))))
  7233. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7234. ((memq action '(?s ?d))
  7235. (let* ((date (unless arg
  7236. (org-read-date
  7237. nil nil nil
  7238. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7239. (ans (if arg nil org-read-date-final-answer))
  7240. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7241. (setq cmd `(let* ((bound (fboundp 'read-string))
  7242. (old (and bound (symbol-function 'read-string))))
  7243. (unwind-protect
  7244. (progn
  7245. (fset 'read-string (lambda (&rest ignore) ,ans))
  7246. (eval '(,c1 arg)))
  7247. (if bound
  7248. (fset 'read-string old)
  7249. (fmakunbound 'read-string)))))))
  7250. (t (error "Invalid bulk action")))
  7251. ;; Sort the markers, to make sure that parents are handled before children
  7252. (setq entries (sort entries
  7253. (lambda (a b)
  7254. (cond
  7255. ((equal (marker-buffer a) (marker-buffer b))
  7256. (< (marker-position a) (marker-position b)))
  7257. (t
  7258. (string< (buffer-name (marker-buffer a))
  7259. (buffer-name (marker-buffer b))))))))
  7260. ;; Now loop over all markers and apply cmd
  7261. (while (setq e (pop entries))
  7262. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7263. (if (not pos)
  7264. (progn (message "Skipping removed entry at %s" e)
  7265. (setq cntskip (1+ cntskip)))
  7266. (goto-char pos)
  7267. (eval cmd)
  7268. (setq org-agenda-bulk-marked-entries
  7269. (delete e org-agenda-bulk-marked-entries))
  7270. (setq cnt (1+ cnt))))
  7271. (setq org-agenda-bulk-marked-entries nil)
  7272. (org-agenda-bulk-remove-all-marks)
  7273. (when redo-at-end (org-agenda-redo))
  7274. (message "Acted on %d entries%s"
  7275. cnt
  7276. (if (= cntskip 0)
  7277. ""
  7278. (format ", skipped %d (disappeared before their turn)"
  7279. cntskip)))))
  7280. ;;; Flagging notes
  7281. (defun org-agenda-show-the-flagging-note ()
  7282. "Display the flagging note in the other window.
  7283. When called a second time in direct sequence, offer to remove the FLAGGING
  7284. tag and (if present) the flagging note."
  7285. (interactive)
  7286. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7287. (win (selected-window))
  7288. note heading newhead)
  7289. (unless hdmarker
  7290. (error "No linked entry at point"))
  7291. (if (and (eq this-command last-command)
  7292. (y-or-n-p "Unflag and remove any flagging note? "))
  7293. (progn
  7294. (org-agenda-remove-flag hdmarker)
  7295. (let ((win (get-buffer-window "*Flagging Note*")))
  7296. (and win (delete-window win)))
  7297. (message "Entry unflaged"))
  7298. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7299. (unless note
  7300. (error "No flagging note"))
  7301. (org-kill-new note)
  7302. (org-switch-to-buffer-other-window "*Flagging Note*")
  7303. (erase-buffer)
  7304. (insert note)
  7305. (goto-char (point-min))
  7306. (while (re-search-forward "\\\\n" nil t)
  7307. (replace-match "\n" t t))
  7308. (goto-char (point-min))
  7309. (select-window win)
  7310. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7311. (defun org-agenda-remove-flag (marker)
  7312. "Remove the FLAGGED tag and any flagging note in the entry."
  7313. (let (newhead)
  7314. (org-with-point-at marker
  7315. (org-toggle-tag "FLAGGED" 'off)
  7316. (org-entry-delete nil "THEFLAGGINGNOTE")
  7317. (setq newhead (org-get-heading)))
  7318. (org-agenda-change-all-lines newhead marker)
  7319. (message "Entry unflaged")))
  7320. (defun org-agenda-get-any-marker (&optional pos)
  7321. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7322. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7323. ;;; Appointment reminders
  7324. (defvar appt-time-msg-list)
  7325. ;;;###autoload
  7326. (defun org-agenda-to-appt (&optional refresh filter)
  7327. "Activate appointments found in `org-agenda-files'.
  7328. With a \\[universal-argument] prefix, refresh the list of
  7329. appointments.
  7330. If FILTER is t, interactively prompt the user for a regular
  7331. expression, and filter out entries that don't match it.
  7332. If FILTER is a string, use this string as a regular expression
  7333. for filtering entries out.
  7334. FILTER can also be an alist with the car of each cell being
  7335. either 'headline or 'category. For example:
  7336. '((headline \"IMPORTANT\")
  7337. (category \"Work\"))
  7338. will only add headlines containing IMPORTANT or headlines
  7339. belonging to the \"Work\" category."
  7340. (interactive "P")
  7341. (if refresh (setq appt-time-msg-list nil))
  7342. (if (eq filter t)
  7343. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7344. (let* ((cnt 0) ; count added events
  7345. (org-agenda-new-buffers nil)
  7346. (org-deadline-warning-days 0)
  7347. ;; Do not use `org-agenda-today' here because appt only takes
  7348. ;; time and without date as argument, so it may pass wrong
  7349. ;; information otherwise
  7350. (today (org-date-to-gregorian
  7351. (time-to-days (current-time))))
  7352. (org-agenda-restrict nil)
  7353. (files (org-agenda-files 'unrestricted)) entries file)
  7354. ;; Get all entries which may contain an appt
  7355. (org-prepare-agenda-buffers files)
  7356. (while (setq file (pop files))
  7357. (setq entries
  7358. (append entries
  7359. (org-agenda-get-day-entries
  7360. file today :timestamp :scheduled :deadline))))
  7361. (setq entries (delq nil entries))
  7362. ;; Map thru entries and find if we should filter them out
  7363. (mapc
  7364. (lambda(x)
  7365. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7366. (cat (get-text-property 1 'org-category x))
  7367. (tod (get-text-property 1 'time-of-day x))
  7368. (ok (or (null filter)
  7369. (and (stringp filter) (string-match filter evt))
  7370. (and (listp filter)
  7371. (or (string-match
  7372. (cadr (assoc 'category filter)) cat)
  7373. (string-match
  7374. (cadr (assoc 'headline filter)) evt))))))
  7375. ;; FIXME: Shall we remove text-properties for the appt text?
  7376. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7377. (when (and ok tod)
  7378. (setq tod (concat "00" (number-to-string tod))
  7379. tod (when (string-match
  7380. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7381. (concat (match-string 1 tod) ":"
  7382. (match-string 2 tod))))
  7383. (appt-add tod evt)
  7384. (setq cnt (1+ cnt))))) entries)
  7385. (org-release-buffers org-agenda-new-buffers)
  7386. (if (eq cnt 0)
  7387. (message "No event to add")
  7388. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7389. (defun org-agenda-today ()
  7390. "Return today date, considering `org-extend-today-until'."
  7391. (time-to-days
  7392. (time-subtract (current-time)
  7393. (list 0 (* 3600 org-extend-today-until) 0))))
  7394. (defun org-agenda-todayp (date)
  7395. "Does DATE mean today, when considering `org-extend-today-until'?"
  7396. (let ((today (org-agenda-today))
  7397. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7398. date)))
  7399. (eq date today)))
  7400. (provide 'org-agenda)
  7401. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  7402. ;;; org-agenda.el ends here