org-agenda.el 275 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  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: 6.33
  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. (require 'calendar))
  30. (declare-function diary-add-to-list "diary-lib"
  31. (date string specifier &optional marker globcolor literal))
  32. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  33. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  34. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  35. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  36. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  38. (declare-function calendar-french-date-string "cal-french" (&optional date))
  39. (declare-function calendar-goto-date "cal-move" (date))
  40. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  41. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  42. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  43. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  44. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  45. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  46. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  47. (declare-function org-datetree-find-date-create "org-datetree" (date))
  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))
  56. (defvar calendar-mode-map)
  57. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  58. (defvar org-habit-show-habits)
  59. (defvar org-habit-show-habits-only-for-today)
  60. ;; Defined somewhere in this file, but used before definition.
  61. (defvar org-agenda-buffer-name)
  62. (defvar org-agenda-overriding-header)
  63. (defvar org-agenda-title-append nil)
  64. (defvar entry)
  65. (defvar date)
  66. (defvar org-agenda-undo-list)
  67. (defvar org-agenda-pending-undo-list)
  68. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  69. (defcustom org-agenda-confirm-kill 1
  70. "When set, remote killing from the agenda buffer needs confirmation.
  71. When t, a confirmation is always needed. When a number N, confirmation is
  72. only needed when the text to be killed contains more than N non-white lines."
  73. :group 'org-agenda
  74. :type '(choice
  75. (const :tag "Never" nil)
  76. (const :tag "Always" t)
  77. (integer :tag "When more than N lines")))
  78. (defcustom org-agenda-compact-blocks nil
  79. "Non-nil means, make the block agenda more compact.
  80. This is done by leaving out unnecessary lines."
  81. :group 'org-agenda
  82. :type 'boolean)
  83. (defcustom org-agenda-block-separator ?=
  84. "The separator between blocks in the agenda.
  85. If this is a string, it will be used as the separator, with a newline added.
  86. If it is a character, it will be repeated to fill the window width."
  87. :group 'org-agenda
  88. :type '(choice
  89. (character)
  90. (string)))
  91. (defgroup org-agenda-export nil
  92. "Options concerning exporting agenda views in Org-mode."
  93. :tag "Org Agenda Export"
  94. :group 'org-agenda)
  95. (defcustom org-agenda-with-colors t
  96. "Non-nil means, use colors in agenda views."
  97. :group 'org-agenda-export
  98. :type 'boolean)
  99. (defcustom org-agenda-exporter-settings nil
  100. "Alist of variable/value pairs that should be active during agenda export.
  101. This is a good place to set options for ps-print and for htmlize.
  102. Note that the way this is implemented, the values will be evaluated
  103. before assigned to the variables. So make sure to quote values you do
  104. *not* want evaluated, for example
  105. (setq org-agenda-exporter-settings
  106. '((ps-print-color-p 'black-white)))"
  107. :group 'org-agenda-export
  108. :type '(repeat
  109. (list
  110. (variable)
  111. (sexp :tag "Value"))))
  112. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  113. "Hook run in temporary buffer before writing it to an export file.
  114. A useful function is `org-agenda-add-entry-text'."
  115. :group 'org-agenda-export
  116. :type 'hook
  117. :options '(org-agenda-add-entry-text))
  118. (defcustom org-agenda-add-entry-text-maxlines 0
  119. "Maximum number of entry text lines to be added to agenda.
  120. This is only relevant when `org-agenda-add-entry-text' is part of
  121. `org-agenda-before-write-hook', which it is by default.
  122. When this is 0, nothing will happen. When it is greater than 0, it
  123. specifies the maximum number of lines that will be added for each entry
  124. that is listed in the agenda view.
  125. Note that this variable is not used during display, only when exporting
  126. the agenda. For agenda display, see org-agenda-entry-text-mode and the
  127. variable `org-agenda-entry-text-maxlines'."
  128. :group 'org-agenda
  129. :type 'integer)
  130. (defcustom org-agenda-add-entry-text-descriptive-links t
  131. "Non-nil means, export org-links as descriptive links in agenda added text.
  132. This variable applies to the text added to the agenda when
  133. `org-agenda-add-entry-text-maxlines' is larger than 0.
  134. When this variable nil, the URL will (also) be shown."
  135. :group 'org-agenda
  136. :type 'boolean)
  137. (defcustom org-agenda-export-html-style ""
  138. "The style specification for exported HTML Agenda files.
  139. If this variable contains a string, it will replace the default <style>
  140. section as produced by `htmlize'.
  141. Since there are different ways of setting style information, this variable
  142. needs to contain the full HTML structure to provide a style, including the
  143. surrounding HTML tags. The style specifications should include definitions
  144. the fonts used by the agenda, here is an example:
  145. <style type=\"text/css\">
  146. p { font-weight: normal; color: gray; }
  147. .org-agenda-structure {
  148. font-size: 110%;
  149. color: #003399;
  150. font-weight: 600;
  151. }
  152. .org-todo {
  153. color: #cc6666;
  154. font-weight: bold;
  155. }
  156. .org-agenda-done {
  157. color: #339933;
  158. }
  159. .org-done {
  160. color: #339933;
  161. }
  162. .title { text-align: center; }
  163. .todo, .deadline { color: red; }
  164. .done { color: green; }
  165. </style>
  166. or, if you want to keep the style in a file,
  167. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  168. As the value of this option simply gets inserted into the HTML <head> header,
  169. you can \"misuse\" it to also add other text to the header. However,
  170. <style>...</style> is required, if not present the variable will be ignored."
  171. :group 'org-agenda-export
  172. :group 'org-export-html
  173. :type 'string)
  174. (defgroup org-agenda-custom-commands nil
  175. "Options concerning agenda views in Org-mode."
  176. :tag "Org Agenda Custom Commands"
  177. :group 'org-agenda)
  178. (defconst org-sorting-choice
  179. '(choice
  180. (const time-up) (const time-down)
  181. (const category-keep) (const category-up) (const category-down)
  182. (const tag-down) (const tag-up)
  183. (const priority-up) (const priority-down)
  184. (const todo-state-up) (const todo-state-down)
  185. (const effort-up) (const effort-down)
  186. (const habit-up) (const habit-down)
  187. (const user-defined-up) (const user-defined-down))
  188. "Sorting choices.")
  189. (defconst org-agenda-custom-commands-local-options
  190. `(repeat :tag "Local settings for this command. Remember to quote values"
  191. (choice :tag "Setting"
  192. (list :tag "Heading for this block"
  193. (const org-agenda-overriding-header)
  194. (string :tag "Headline"))
  195. (list :tag "Files to be searched"
  196. (const org-agenda-files)
  197. (list
  198. (const :format "" quote)
  199. (repeat (file))))
  200. (list :tag "Sorting strategy"
  201. (const org-agenda-sorting-strategy)
  202. (list
  203. (const :format "" quote)
  204. (repeat
  205. ,org-sorting-choice)))
  206. (list :tag "Prefix format"
  207. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  208. (string))
  209. (list :tag "Number of days in agenda"
  210. (const org-agenda-ndays)
  211. (integer :value 1))
  212. (list :tag "Fixed starting date"
  213. (const org-agenda-start-day)
  214. (string :value "2007-11-01"))
  215. (list :tag "Start on day of week"
  216. (const org-agenda-start-on-weekday)
  217. (choice :value 1
  218. (const :tag "Today" nil)
  219. (integer :tag "Weekday No.")))
  220. (list :tag "Include data from diary"
  221. (const org-agenda-include-diary)
  222. (boolean))
  223. (list :tag "Deadline Warning days"
  224. (const org-deadline-warning-days)
  225. (integer :value 1))
  226. (list :tag "Tags filter preset"
  227. (const org-agenda-filter-preset)
  228. (list
  229. (const :format "" quote)
  230. (repeat
  231. (string :tag "+tag or -tag"))))
  232. (list :tag "Standard skipping condition"
  233. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  234. (const org-agenda-skip-function)
  235. (list
  236. (const :format "" quote)
  237. (list
  238. (choice
  239. :tag "Skipping range"
  240. (const :tag "Skip entry" org-agenda-skip-entry-if)
  241. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  242. (repeat :inline t :tag "Conditions for skipping"
  243. (choice
  244. :tag "Condition type"
  245. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  246. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  247. (const :tag "scheduled" 'scheduled)
  248. (const :tag "not scheduled" 'notscheduled)
  249. (const :tag "deadline" 'deadline)
  250. (const :tag "no deadline" 'notdeadline)
  251. (const :tag "timestamp" 'timestamp)
  252. (const :tag "no timestamp" 'nottimestamp))))))
  253. (list :tag "Non-standard skipping condition"
  254. :value (org-agenda-skip-function)
  255. (const org-agenda-skip-function)
  256. (sexp :tag "Function or form (quoted!)"))
  257. (list :tag "Any variable"
  258. (variable :tag "Variable")
  259. (sexp :tag "Value (sexp)"))))
  260. "Selection of examples for agenda command settings.
  261. This will be spliced into the custom type of
  262. `org-agenda-custom-commands'.")
  263. (defcustom org-agenda-custom-commands nil
  264. "Custom commands for the agenda.
  265. These commands will be offered on the splash screen displayed by the
  266. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  267. (key desc type match settings files)
  268. key The key (one or more characters as a string) to be associated
  269. with the command.
  270. desc A description of the command, when omitted or nil, a default
  271. description is built using MATCH.
  272. type The command type, any of the following symbols:
  273. agenda The daily/weekly agenda.
  274. todo Entries with a specific TODO keyword, in all agenda files.
  275. search Entries containing search words entry or headline.
  276. tags Tags/Property/TODO match in all agenda files.
  277. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  278. todo-tree Sparse tree of specific TODO keyword in *current* file.
  279. tags-tree Sparse tree with all tags matches in *current* file.
  280. occur-tree Occur sparse tree for *current* file.
  281. ... A user-defined function.
  282. match What to search for:
  283. - a single keyword for TODO keyword searches
  284. - a tags match expression for tags searches
  285. - a word search expression for text searches.
  286. - a regular expression for occur searches
  287. For all other commands, this should be the empty string.
  288. settings A list of option settings, similar to that in a let form, so like
  289. this: ((opt1 val1) (opt2 val2) ...). The values will be
  290. evaluated at the moment of execution, so quote them when needed.
  291. files A list of files file to write the produced agenda buffer to
  292. with the command `org-store-agenda-views'.
  293. If a file name ends in \".html\", an HTML version of the buffer
  294. is written out. If it ends in \".ps\", a postscript version is
  295. produced. Otherwise, only the plain text is written to the file.
  296. You can also define a set of commands, to create a composite agenda buffer.
  297. In this case, an entry looks like this:
  298. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  299. where
  300. desc A description string to be displayed in the dispatcher menu.
  301. cmd An agenda command, similar to the above. However, tree commands
  302. are no allowed, but instead you can get agenda and global todo list.
  303. So valid commands for a set are:
  304. (agenda \"\" settings)
  305. (alltodo \"\" settings)
  306. (stuck \"\" settings)
  307. (todo \"match\" settings files)
  308. (search \"match\" settings files)
  309. (tags \"match\" settings files)
  310. (tags-todo \"match\" settings files)
  311. Each command can carry a list of options, and another set of options can be
  312. given for the whole set of commands. Individual command options take
  313. precedence over the general options.
  314. When using several characters as key to a command, the first characters
  315. are prefix commands. For the dispatcher to display useful information, you
  316. should provide a description for the prefix, like
  317. (setq org-agenda-custom-commands
  318. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  319. (\"hl\" tags \"+HOME+Lisa\")
  320. (\"hp\" tags \"+HOME+Peter\")
  321. (\"hk\" tags \"+HOME+Kim\")))"
  322. :group 'org-agenda-custom-commands
  323. :type `(repeat
  324. (choice :value ("x" "Describe command here" tags "" nil)
  325. (list :tag "Single command"
  326. (string :tag "Access Key(s) ")
  327. (option (string :tag "Description"))
  328. (choice
  329. (const :tag "Agenda" agenda)
  330. (const :tag "TODO list" alltodo)
  331. (const :tag "Search words" search)
  332. (const :tag "Stuck projects" stuck)
  333. (const :tag "Tags/Property match (all agenda files)" tags)
  334. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  335. (const :tag "TODO keyword search (all agenda files)" todo)
  336. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  337. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  338. (const :tag "Occur tree (current buffer)" occur-tree)
  339. (sexp :tag "Other, user-defined function"))
  340. (string :tag "Match (only for some commands)")
  341. ,org-agenda-custom-commands-local-options
  342. (option (repeat :tag "Export" (file :tag "Export to"))))
  343. (list :tag "Command series, all agenda files"
  344. (string :tag "Access Key(s)")
  345. (string :tag "Description ")
  346. (repeat :tag "Component"
  347. (choice
  348. (list :tag "Agenda"
  349. (const :format "" agenda)
  350. (const :tag "" :format "" "")
  351. ,org-agenda-custom-commands-local-options)
  352. (list :tag "TODO list (all keywords)"
  353. (const :format "" alltodo)
  354. (const :tag "" :format "" "")
  355. ,org-agenda-custom-commands-local-options)
  356. (list :tag "Search words"
  357. (const :format "" search)
  358. (string :tag "Match")
  359. ,org-agenda-custom-commands-local-options)
  360. (list :tag "Stuck projects"
  361. (const :format "" stuck)
  362. (const :tag "" :format "" "")
  363. ,org-agenda-custom-commands-local-options)
  364. (list :tag "Tags search"
  365. (const :format "" tags)
  366. (string :tag "Match")
  367. ,org-agenda-custom-commands-local-options)
  368. (list :tag "Tags search, TODO entries only"
  369. (const :format "" tags-todo)
  370. (string :tag "Match")
  371. ,org-agenda-custom-commands-local-options)
  372. (list :tag "TODO keyword search"
  373. (const :format "" todo)
  374. (string :tag "Match")
  375. ,org-agenda-custom-commands-local-options)
  376. (list :tag "Other, user-defined function"
  377. (symbol :tag "function")
  378. (string :tag "Match")
  379. ,org-agenda-custom-commands-local-options)))
  380. (repeat :tag "Settings for entire command set"
  381. (list (variable :tag "Any variable")
  382. (sexp :tag "Value")))
  383. (option (repeat :tag "Export" (file :tag "Export to"))))
  384. (cons :tag "Prefix key documentation"
  385. (string :tag "Access Key(s)")
  386. (string :tag "Description ")))))
  387. (defcustom org-agenda-query-register ?o
  388. "The register holding the current query string.
  389. The purpose of this is that if you construct a query string interactively,
  390. you can then use it to define a custom command."
  391. :group 'org-agenda-custom-commands
  392. :type 'character)
  393. (defcustom org-stuck-projects
  394. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  395. "How to identify stuck projects.
  396. This is a list of four items:
  397. 1. A tags/todo/property matcher string that is used to identify a project.
  398. See the manual for a description of tag and property searches.
  399. The entire tree below a headline matched by this is considered one project.
  400. 2. A list of TODO keywords identifying non-stuck projects.
  401. If the project subtree contains any headline with one of these todo
  402. keywords, the project is considered to be not stuck. If you specify
  403. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  404. 3. A list of tags identifying non-stuck projects.
  405. If the project subtree contains any headline with one of these tags,
  406. the project is considered to be not stuck. If you specify \"*\" as
  407. a tag, any tag will mark the project unstuck. Note that this is about
  408. the explicit presence of a tag somewhere in the subtree, inherited
  409. tags to not count here. If inherited tags make a project not stuck,
  410. use \"-TAG\" in the tags part of the matcher under (1.) above.
  411. 4. An arbitrary regular expression matching non-stuck projects.
  412. If the project turns out to be not stuck, search continues also in the
  413. subtree to see if any of the subtasks have project status.
  414. See also the variable `org-tags-match-list-sublevels' which applies
  415. to projects matched by this search as well.
  416. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  417. or `C-c a #' to produce the list."
  418. :group 'org-agenda-custom-commands
  419. :type '(list
  420. (string :tag "Tags/TODO match to identify a project")
  421. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  422. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  423. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  424. (defcustom org-agenda-filter-effort-default-operator "<"
  425. "The default operator for effort estimate filtering.
  426. If you select an effort estimate limit without first pressing an operator,
  427. this one will be used."
  428. :group 'org-agenda-custom-commands
  429. :type '(choice (const :tag "less or equal" "<")
  430. (const :tag "greater or equal"">")
  431. (const :tag "equal" "=")))
  432. (defgroup org-agenda-skip nil
  433. "Options concerning skipping parts of agenda files."
  434. :tag "Org Agenda Skip"
  435. :group 'org-agenda)
  436. (defgroup org-agenda-daily/weekly nil
  437. "Options concerning the daily/weekly agenda."
  438. :tag "Org Agenda Daily/Weekly"
  439. :group 'org-agenda)
  440. (defgroup org-agenda-todo-list nil
  441. "Options concerning the global todo list agenda view."
  442. :tag "Org Agenda Todo List"
  443. :group 'org-agenda)
  444. (defgroup org-agenda-match-view nil
  445. "Options concerning the general tags/property/todo match agenda view."
  446. :tag "Org Agenda Match View"
  447. :group 'org-agenda)
  448. (defgroup org-agenda-search-view nil
  449. "Options concerning the general tags/property/todo match agenda view."
  450. :tag "Org Agenda Match View"
  451. :group 'org-agenda)
  452. (defvar org-agenda-archives-mode nil
  453. "Non-nil means, the agenda will include archived items.
  454. If this is the symbol `trees', trees in the selected agenda scope
  455. that are marked with the ARCHIVE tag will be included anyway. When this is
  456. t, also all archive files associated with the current selection of agenda
  457. files will be included.")
  458. (defcustom org-agenda-skip-comment-trees t
  459. "Non-nil means, skip trees that start with the COMMENT keyword.
  460. When nil, these trees are also scanned by agenda commands."
  461. :group 'org-agenda-skip
  462. :type 'boolean)
  463. (defcustom org-agenda-todo-list-sublevels t
  464. "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
  465. When nil, the sublevels of a TODO entry are not checked, resulting in
  466. potentially much shorter TODO lists."
  467. :group 'org-agenda-skip
  468. :group 'org-agenda-todo-list
  469. :type 'boolean)
  470. (defcustom org-agenda-todo-ignore-with-date nil
  471. "Non-nil means, don't show entries with a date in the global todo list.
  472. You can use this if you prefer to mark mere appointments with a TODO keyword,
  473. but don't want them to show up in the TODO list.
  474. When this is set, it also covers deadlines and scheduled items, the settings
  475. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  476. will be ignored.
  477. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  478. :group 'org-agenda-skip
  479. :group 'org-agenda-todo-list
  480. :type 'boolean)
  481. (defcustom org-agenda-todo-ignore-scheduled nil
  482. "Non-nil means, don't show scheduled entries in the global todo list.
  483. The idea behind this is that by scheduling it, you have already taken care
  484. of this item.
  485. See also `org-agenda-todo-ignore-with-date'.
  486. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  487. :group 'org-agenda-skip
  488. :group 'org-agenda-todo-list
  489. :type 'boolean)
  490. (defcustom org-agenda-todo-ignore-deadlines nil
  491. "Non-nil means, don't show near deadline entries in the global todo list.
  492. Near means closer than `org-deadline-warning-days' days.
  493. The idea behind this is that such items will appear in the agenda anyway.
  494. See also `org-agenda-todo-ignore-with-date'.
  495. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  496. :group 'org-agenda-skip
  497. :group 'org-agenda-todo-list
  498. :type 'boolean)
  499. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  500. "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
  501. The variables
  502. `org-agenda-todo-ignore-with-date',
  503. `org-agenda-todo-ignore-scheduled'
  504. `org-agenda-todo-ignore-deadlines'
  505. make the global TODO list skip entries that have time stamps of certain
  506. kinds. If this option is set, the same options will also apply for the
  507. tags-todo search, which is the general tags/property matcher
  508. restricted to unfinished TODO entries only."
  509. :group 'org-agenda-skip
  510. :group 'org-agenda-todo-list
  511. :group 'org-agenda-match-view
  512. :type 'boolean)
  513. (defcustom org-agenda-skip-scheduled-if-done nil
  514. "Non-nil means don't show scheduled items in agenda when they are done.
  515. This is relevant for the daily/weekly agenda, not for the TODO list. And
  516. it applies only to the actual date of the scheduling. Warnings about
  517. an item with a past scheduling dates are always turned off when the item
  518. is DONE."
  519. :group 'org-agenda-skip
  520. :group 'org-agenda-daily/weekly
  521. :type 'boolean)
  522. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  523. "Non-nil means skip scheduling line if same entry shows because of deadline.
  524. In the agenda of today, an entry can show up multiple times because
  525. it is both scheduled and has a nearby deadline, and maybe a plain time
  526. stamp as well.
  527. When this variable is t, then only the deadline is shown and the fact that
  528. the entry is scheduled today or was scheduled previously is not shown.
  529. When this variable is nil, the entry will be shown several times. When
  530. the variable is the symbol `not-today', then skip scheduled previously,
  531. but not scheduled today."
  532. :group 'org-agenda-skip
  533. :group 'org-agenda-daily/weekly
  534. :type '(choice
  535. (const :tag "Never" nil)
  536. (const :tag "Always" t)
  537. (const :tag "Not when scheduled today" not-today)))
  538. (defcustom org-agenda-skip-deadline-if-done nil
  539. "Non-nil means don't show deadlines when the corresponding item is done.
  540. When nil, the deadline is still shown and should give you a happy feeling.
  541. This is relevant for the daily/weekly agenda. And it applied only to the
  542. actually date of the deadline. Warnings about approaching and past-due
  543. deadlines are always turned off when the item is DONE."
  544. :group 'org-agenda-skip
  545. :group 'org-agenda-daily/weekly
  546. :type 'boolean)
  547. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  548. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  549. When non-nil, after the search for timestamps has matched once in an
  550. entry, the rest of the entry will not be searched."
  551. :group 'org-agenda-skip
  552. :type 'boolean)
  553. (defcustom org-agenda-skip-timestamp-if-done nil
  554. "Non-nil means don't select item by timestamp or -range if it is DONE."
  555. :group 'org-agenda-skip
  556. :group 'org-agenda-daily/weekly
  557. :type 'boolean)
  558. (defcustom org-agenda-dim-blocked-tasks t
  559. "Non-nil means, dim blocked tasks in the agenda display.
  560. This causes some overhead during agenda construction, but if you
  561. have turned on `org-enforce-todo-dependencies',
  562. `org-enforce-todo-checkbox-dependencies', or any other blocking
  563. mechanism, this will create useful feedback in the agenda.
  564. Instead of t, this variable can also have the value `invisible'.
  565. Then blocked tasks will be invisible and only become visible when
  566. they become unblocked. An exemption to this behavior is when a task is
  567. blocked because of unchecked checkboxes below it. Since checkboxes do
  568. not show up in the agenda views, making this task invisible you remove any
  569. trace from agenda views that there is something to do. Therefore, a task
  570. that is blocked because of checkboxes will never be made invisible, it
  571. will only be dimmed."
  572. :group 'org-agenda-daily/weekly
  573. :group 'org-agenda-todo-list
  574. :type '(choice
  575. (const :tag "Do not dim" nil)
  576. (const :tag "Dim to a grey face" t)
  577. (const :tag "Make invisible" invisible)))
  578. (defcustom org-timeline-show-empty-dates 3
  579. "Non-nil means, `org-timeline' also shows dates without an entry.
  580. When nil, only the days which actually have entries are shown.
  581. When t, all days between the first and the last date are shown.
  582. When an integer, show also empty dates, but if there is a gap of more than
  583. N days, just insert a special line indicating the size of the gap."
  584. :group 'org-agenda-skip
  585. :type '(choice
  586. (const :tag "None" nil)
  587. (const :tag "All" t)
  588. (integer :tag "at most")))
  589. (defgroup org-agenda-startup nil
  590. "Options concerning initial settings in the Agenda in Org Mode."
  591. :tag "Org Agenda Startup"
  592. :group 'org-agenda)
  593. (defcustom org-finalize-agenda-hook nil
  594. "Hook run just before displaying an agenda buffer."
  595. :group 'org-agenda-startup
  596. :type 'hook)
  597. (defcustom org-agenda-mouse-1-follows-link nil
  598. "Non-nil means, mouse-1 on a link will follow the link in the agenda.
  599. A longer mouse click will still set point. Does not work on XEmacs.
  600. Needs to be set before org.el is loaded."
  601. :group 'org-agenda-startup
  602. :type 'boolean)
  603. (defcustom org-agenda-start-with-follow-mode nil
  604. "The initial value of follow-mode in a newly created agenda window."
  605. :group 'org-agenda-startup
  606. :type 'boolean)
  607. (defcustom org-agenda-start-with-entry-text-mode nil
  608. "The initial value of entry-text-mode in a newly created agenda window."
  609. :group 'org-agenda-startup
  610. :type 'boolean)
  611. (defcustom org-agenda-entry-text-maxlines 5
  612. "Number of text lines to be added when `E' is pressed in the agenda.
  613. Note that this variable only used during agenda display. Add add entry text
  614. when exporting the agenda, configure the variable
  615. `org-agenda-add-entry-ext-maxlines'."
  616. :group 'org-agenda
  617. :type 'integer)
  618. (defcustom org-agenda-entry-text-exclude-regexps nil
  619. "List of regular expressions to clean up entry text.
  620. The complete matches of all regular expressions in this list will be
  621. removed from entry text before it is shown in the agenda."
  622. :group 'org-agenda
  623. :type '(repeat (regexp)))
  624. (defvar org-agenda-entry-text-cleanup-hook nil
  625. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  626. This cleanup is done in a temporary buffer, so the function may inspect and
  627. change the entire buffer.
  628. Some default stuff like drawers and scheduling/deadline dates will already
  629. have been removed when this is called, as will any matches for regular
  630. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  631. (defvar org-agenda-include-inactive-timestamps nil
  632. "Non-nil means, include inactive time stamps in agenda and timeline.")
  633. (defgroup org-agenda-windows nil
  634. "Options concerning the windows used by the Agenda in Org Mode."
  635. :tag "Org Agenda Windows"
  636. :group 'org-agenda)
  637. (defcustom org-agenda-window-setup 'reorganize-frame
  638. "How the agenda buffer should be displayed.
  639. Possible values for this option are:
  640. current-window Show agenda in the current window, keeping all other windows.
  641. other-window Use `switch-to-buffer-other-window' to display agenda.
  642. reorganize-frame Show only two windows on the current frame, the current
  643. window and the agenda.
  644. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  645. Also, when exiting the agenda, kill that frame.
  646. See also the variable `org-agenda-restore-windows-after-quit'."
  647. :group 'org-agenda-windows
  648. :type '(choice
  649. (const current-window)
  650. (const other-frame)
  651. (const other-window)
  652. (const reorganize-frame)))
  653. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  654. "The min and max height of the agenda window as a fraction of frame height.
  655. The value of the variable is a cons cell with two numbers between 0 and 1.
  656. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  657. :group 'org-agenda-windows
  658. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  659. (defcustom org-agenda-restore-windows-after-quit nil
  660. "Non-nil means, restore window configuration open exiting agenda.
  661. Before the window configuration is changed for displaying the agenda,
  662. the current status is recorded. When the agenda is exited with
  663. `q' or `x' and this option is set, the old state is restored. If
  664. `org-agenda-window-setup' is `other-frame', the value of this
  665. option will be ignored."
  666. :group 'org-agenda-windows
  667. :type 'boolean)
  668. (defcustom org-agenda-ndays 7
  669. "Number of days to include in overview display.
  670. Should be 1 or 7.
  671. Custom commands can set this variable in the options section."
  672. :group 'org-agenda-daily/weekly
  673. :type 'integer)
  674. (defcustom org-agenda-start-on-weekday 1
  675. "Non-nil means, start the overview always on the specified weekday.
  676. 0 denotes Sunday, 1 denotes Monday etc.
  677. When nil, always start on the current day.
  678. Custom commands can set this variable in the options section."
  679. :group 'org-agenda-daily/weekly
  680. :type '(choice (const :tag "Today" nil)
  681. (integer :tag "Weekday No.")))
  682. (defcustom org-agenda-show-all-dates t
  683. "Non-nil means, `org-agenda' shows every day in the selected range.
  684. When nil, only the days which actually have entries are shown."
  685. :group 'org-agenda-daily/weekly
  686. :type 'boolean)
  687. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  688. "Format string for displaying dates in the agenda.
  689. Used by the daily/weekly agenda and by the timeline. This should be
  690. a format string understood by `format-time-string', or a function returning
  691. the formatted date as a string. The function must take a single argument,
  692. a calendar-style date list like (month day year)."
  693. :group 'org-agenda-daily/weekly
  694. :type '(choice
  695. (string :tag "Format string")
  696. (function :tag "Function")))
  697. (defun org-agenda-format-date-aligned (date)
  698. "Format a date string for display in the daily/weekly agenda, or timeline.
  699. This function makes sure that dates are aligned for easy reading."
  700. (require 'cal-iso)
  701. (let* ((dayname (calendar-day-name date))
  702. (day (cadr date))
  703. (day-of-week (calendar-day-of-week date))
  704. (month (car date))
  705. (monthname (calendar-month-name month))
  706. (year (nth 2 date))
  707. (iso-week (org-days-to-iso-week
  708. (calendar-absolute-from-gregorian date)))
  709. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  710. (1- year))
  711. ((and (= month 12) (<= iso-week 1))
  712. (1+ year))
  713. (t year)))
  714. (weekstring (if (= day-of-week 1)
  715. (format " W%02d" iso-week)
  716. "")))
  717. (format "%-10s %2d %s %4d%s"
  718. dayname day monthname year weekstring)))
  719. (defcustom org-agenda-weekend-days '(6 0)
  720. "Which days are weekend?
  721. These days get the special face `org-agenda-date-weekend' in the agenda
  722. and timeline buffers."
  723. :group 'org-agenda-daily/weekly
  724. :type '(set :greedy t
  725. (const :tag "Monday" 1)
  726. (const :tag "Tuesday" 2)
  727. (const :tag "Wednesday" 3)
  728. (const :tag "Thursday" 4)
  729. (const :tag "Friday" 5)
  730. (const :tag "Saturday" 6)
  731. (const :tag "Sunday" 0)))
  732. (defcustom org-agenda-include-diary nil
  733. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  734. Custom commands can set this variable in the options section."
  735. :group 'org-agenda-daily/weekly
  736. :type 'boolean)
  737. (defcustom org-agenda-include-all-todo nil
  738. "Set means weekly/daily agenda will always contain all TODO entries.
  739. The TODO entries will be listed at the top of the agenda, before
  740. the entries for specific days.
  741. This option is deprecated, it is better to define a block agenda instead."
  742. :group 'org-agenda-daily/weekly
  743. :type 'boolean)
  744. (defcustom org-agenda-repeating-timestamp-show-all t
  745. "Non-nil means, show all occurrences of a repeating stamp in the agenda.
  746. When nil, only one occurrence is shown, either today or the
  747. nearest into the future."
  748. :group 'org-agenda-daily/weekly
  749. :type 'boolean)
  750. (defcustom org-scheduled-past-days 10000
  751. "No. of days to continue listing scheduled items that are not marked DONE.
  752. When an item is scheduled on a date, it shows up in the agenda on this
  753. day and will be listed until it is marked done for the number of days
  754. given here."
  755. :group 'org-agenda-daily/weekly
  756. :type 'integer)
  757. (defcustom org-agenda-log-mode-items '(closed clock)
  758. "List of items that should be shown in agenda log mode.
  759. This list may contain the following symbols:
  760. closed Show entries that have been closed on that day.
  761. clock Show entries that have received clocked time on that day.
  762. state Show all logged state changes.
  763. Note that instead of changing this variable, you can also press `C-u l' in
  764. the agenda to display all available LOG items temporarily."
  765. :group 'org-agenda-daily/weekly
  766. :type '(set :greedy t (const closed) (const clock) (const state)))
  767. (defcustom org-agenda-log-mode-add-notes t
  768. "Non-nil means, add first line of notes to log entries in agenda views.
  769. If a log item like a state change or a clock entry is associated with
  770. notes, the first line of these notes will be added to the entry in the
  771. agenda display."
  772. :group 'org-agenda-daily/weekly
  773. :type 'boolean)
  774. (defcustom org-agenda-start-with-log-mode nil
  775. "The initial value of log-mode in a newly created agenda window."
  776. :group 'org-agenda-startup
  777. :group 'org-agenda-daily/weekly
  778. :type 'boolean)
  779. (defcustom org-agenda-start-with-clockreport-mode nil
  780. "The initial value of clockreport-mode in a newly created agenda window."
  781. :group 'org-agenda-startup
  782. :group 'org-agenda-daily/weekly
  783. :type 'boolean)
  784. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  785. "Property list with parameters for the clocktable in clockreport mode.
  786. This is the display mode that shows a clock table in the daily/weekly
  787. agenda, the properties for this dynamic block can be set here.
  788. The usual clocktable parameters are allowed here, but you cannot set
  789. the properties :name, :tstart, :tend, :block, and :scope - these will
  790. be overwritten to make sure the content accurately reflects the
  791. current display in the agenda."
  792. :group 'org-agenda-daily/weekly
  793. :type 'plist)
  794. (defcustom org-agenda-search-view-search-words-only nil
  795. "Non-nil means, the search string is interpreted as individual words
  796. The search then looks for each word separately in each entry and
  797. selects entries that have matches for all words.
  798. When nil, matching as loose words will only take place if the first
  799. word is preceded by + or -. If that is not the case, the search
  800. string will just be matched as a substring in the entry, but with
  801. each space character allowing for any whitespace, including newlines."
  802. :group 'org-agenda-search-view
  803. :type 'boolean)
  804. (defgroup org-agenda-time-grid nil
  805. "Options concerning the time grid in the Org-mode Agenda."
  806. :tag "Org Agenda Time Grid"
  807. :group 'org-agenda)
  808. (defcustom org-agenda-search-headline-for-time t
  809. "Non-nil means, search headline for a time-of-day.
  810. If the headline contains a time-of-day in one format or another, it will
  811. be used to sort the entry into the time sequence of items for a day.
  812. Some people have time stamps in the headline that refer to the creation
  813. time or so, and then this produces an unwanted side effect. If this is
  814. the case for your, use this variable to turn off searching the headline
  815. for a time."
  816. :group 'org-agenda-time-grid
  817. :type 'boolean)
  818. (defcustom org-agenda-use-time-grid t
  819. "Non-nil means, show a time grid in the agenda schedule.
  820. A time grid is a set of lines for specific times (like every two hours between
  821. 8:00 and 20:00). The items scheduled for a day at specific times are
  822. sorted in between these lines.
  823. For details about when the grid will be shown, and what it will look like, see
  824. the variable `org-agenda-time-grid'."
  825. :group 'org-agenda-time-grid
  826. :type 'boolean)
  827. (defcustom org-agenda-time-grid
  828. '((daily today require-timed)
  829. "----------------"
  830. (800 1000 1200 1400 1600 1800 2000))
  831. "The settings for time grid for agenda display.
  832. This is a list of three items. The first item is again a list. It contains
  833. symbols specifying conditions when the grid should be displayed:
  834. daily if the agenda shows a single day
  835. weekly if the agenda shows an entire week
  836. today show grid on current date, independent of daily/weekly display
  837. require-timed show grid only if at least one item has a time specification
  838. The second item is a string which will be placed behind the grid time.
  839. The third item is a list of integers, indicating the times that should have
  840. a grid line."
  841. :group 'org-agenda-time-grid
  842. :type
  843. '(list
  844. (set :greedy t :tag "Grid Display Options"
  845. (const :tag "Show grid in single day agenda display" daily)
  846. (const :tag "Show grid in weekly agenda display" weekly)
  847. (const :tag "Always show grid for today" today)
  848. (const :tag "Show grid only if any timed entries are present"
  849. require-timed)
  850. (const :tag "Skip grid times already present in an entry"
  851. remove-match))
  852. (string :tag "Grid String")
  853. (repeat :tag "Grid Times" (integer :tag "Time"))))
  854. (defgroup org-agenda-sorting nil
  855. "Options concerning sorting in the Org-mode Agenda."
  856. :tag "Org Agenda Sorting"
  857. :group 'org-agenda)
  858. (defcustom org-agenda-sorting-strategy
  859. '((agenda habit-down time-up priority-down category-keep)
  860. (todo priority-down category-keep)
  861. (tags priority-down category-keep)
  862. (search category-keep))
  863. "Sorting structure for the agenda items of a single day.
  864. This is a list of symbols which will be used in sequence to determine
  865. if an entry should be listed before another entry. The following
  866. symbols are recognized:
  867. time-up Put entries with time-of-day indications first, early first
  868. time-down Put entries with time-of-day indications first, late first
  869. category-keep Keep the default order of categories, corresponding to the
  870. sequence in `org-agenda-files'.
  871. category-up Sort alphabetically by category, A-Z.
  872. category-down Sort alphabetically by category, Z-A.
  873. tag-up Sort alphabetically by last tag, A-Z.
  874. tag-down Sort alphabetically by last tag, Z-A.
  875. priority-up Sort numerically by priority, high priority last.
  876. priority-down Sort numerically by priority, high priority first.
  877. todo-state-up Sort by todo state, tasks that are done last.
  878. todo-state-down Sort by todo state, tasks that are done first.
  879. effort-up Sort numerically by estimated effort, high effort last.
  880. effort-down Sort numerically by estimated effort, high effort first.
  881. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  882. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  883. habit-up Put entries that are habits first
  884. habit-down Put entries that are habits last
  885. The different possibilities will be tried in sequence, and testing stops
  886. if one comparison returns a \"not-equal\". For example, the default
  887. '(time-up category-keep priority-down)
  888. means: Pull out all entries having a specified time of day and sort them,
  889. in order to make a time schedule for the current day the first thing in the
  890. agenda listing for the day. Of the entries without a time indication, keep
  891. the grouped in categories, don't sort the categories, but keep them in
  892. the sequence given in `org-agenda-files'. Within each category sort by
  893. priority.
  894. Leaving out `category-keep' would mean that items will be sorted across
  895. categories by priority.
  896. Instead of a single list, this can also be a set of list for specific
  897. contents, with a context symbol in the car of the list, any of
  898. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  899. Custom commands can bind this variable in the options section."
  900. :group 'org-agenda-sorting
  901. :type `(choice
  902. (repeat :tag "General" ,org-sorting-choice)
  903. (list :tag "Individually"
  904. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  905. (repeat ,org-sorting-choice))
  906. (cons (const :tag "Strategy for TODO lists" todo)
  907. (repeat ,org-sorting-choice))
  908. (cons (const :tag "Strategy for Tags matches" tags)
  909. (repeat ,org-sorting-choice))
  910. (cons (const :tag "Strategy for search matches" search)
  911. (repeat ,org-sorting-choice)))))
  912. (defcustom org-agenda-cmp-user-defined nil
  913. "A function to define the comparison `user-defined'.
  914. This function must receive two arguments, agenda entry a and b.
  915. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  916. the user comparison, return nil.
  917. When this is defined, you can make `user-defined-up' and `user-defined-down'
  918. part of an agenda sorting strategy."
  919. :group 'org-agenda-sorting
  920. :type 'symbol)
  921. (defcustom org-sort-agenda-notime-is-late t
  922. "Non-nil means, items without time are considered late.
  923. This is only relevant for sorting. When t, items which have no explicit
  924. time like 15:30 will be considered as 99:01, i.e. later than any items which
  925. do have a time. When nil, the default time is before 0:00. You can use this
  926. option to decide if the schedule for today should come before or after timeless
  927. agenda entries."
  928. :group 'org-agenda-sorting
  929. :type 'boolean)
  930. (defcustom org-sort-agenda-noeffort-is-high t
  931. "Non-nil means, items without effort estimate are sorted as high effort.
  932. This also applies when filtering an agenda view with respect to the
  933. < or > effort operator. Then, tasks with no effort defined will be treated
  934. as tasks with high effort.
  935. When nil, such items are sorted as 0 minutes effort."
  936. :group 'org-agenda-sorting
  937. :type 'boolean)
  938. (defgroup org-agenda-line-format nil
  939. "Options concerning the entry prefix in the Org-mode agenda display."
  940. :tag "Org Agenda Line Format"
  941. :group 'org-agenda)
  942. (defcustom org-agenda-prefix-format
  943. '((agenda . " %-12:c%?-12t% s")
  944. (timeline . " % s")
  945. (todo . " %-12:c")
  946. (tags . " %-12:c")
  947. (search . " %-12:c"))
  948. "Format specifications for the prefix of items in the agenda views.
  949. An alist with four entries, for the different agenda types. The keys to the
  950. sublists are `agenda', `timeline', `todo', and `tags'. The values
  951. are format strings.
  952. This format works similar to a printf format, with the following meaning:
  953. %c the category of the item, \"Diary\" for entries from the diary, or
  954. as given by the CATEGORY keyword or derived from the file name.
  955. %T the *last* tag of the item. Last because inherited tags come
  956. first in the list.
  957. %t the time-of-day specification if one applies to the entry, in the
  958. format HH:MM
  959. %s Scheduling/Deadline information, a short string
  960. All specifiers work basically like the standard `%s' of printf, but may
  961. contain two additional characters: A question mark just after the `%' and
  962. a whitespace/punctuation character just before the final letter.
  963. If the first character after `%' is a question mark, the entire field
  964. will only be included if the corresponding value applies to the
  965. current entry. This is useful for fields which should have fixed
  966. width when present, but zero width when absent. For example,
  967. \"%?-12t\" will result in a 12 character time field if a time of the
  968. day is specified, but will completely disappear in entries which do
  969. not contain a time.
  970. If there is punctuation or whitespace character just before the final
  971. format letter, this character will be appended to the field value if
  972. the value is not empty. For example, the format \"%-12:c\" leads to
  973. \"Diary: \" if the category is \"Diary\". If the category were be
  974. empty, no additional colon would be inserted.
  975. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  976. - Indent the line with two space characters
  977. - Give the category in a 12 chars wide field, padded with whitespace on
  978. the right (because of `-'). Append a colon if there is a category
  979. (because of `:').
  980. - If there is a time-of-day, put it into a 12 chars wide field. If no
  981. time, don't put in an empty field, just skip it (because of '?').
  982. - Finally, put the scheduling information and append a whitespace.
  983. As another example, if you don't want the time-of-day of entries in
  984. the prefix, you could use:
  985. (setq org-agenda-prefix-format \" %-11:c% s\")
  986. See also the variables `org-agenda-remove-times-when-in-prefix' and
  987. `org-agenda-remove-tags'.
  988. Custom commands can set this variable in the options section."
  989. :type '(choice
  990. (string :tag "General format")
  991. (list :greedy t :tag "View dependent"
  992. (cons (const agenda) (string :tag "Format"))
  993. (cons (const timeline) (string :tag "Format"))
  994. (cons (const todo) (string :tag "Format"))
  995. (cons (const tags) (string :tag "Format"))
  996. (cons (const search) (string :tag "Format"))))
  997. :group 'org-agenda-line-format)
  998. (defvar org-prefix-format-compiled nil
  999. "The compiled version of the most recently used prefix format.
  1000. See the variable `org-agenda-prefix-format'.")
  1001. (defcustom org-agenda-todo-keyword-format "%-1s"
  1002. "Format for the TODO keyword in agenda lines.
  1003. Set this to something like \"%-12s\" if you want all TODO keywords
  1004. to occupy a fixed space in the agenda display."
  1005. :group 'org-agenda-line-format
  1006. :type 'string)
  1007. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1008. "Text preceding timerange entries in the agenda view.
  1009. This is a list with two strings. The first applies when the range
  1010. is entirely on one day. The second applies if the range spans several days.
  1011. The strings may have two \"%d\" format specifiers which will be filled
  1012. with the sequence number of the days, and the total number of days in the
  1013. range, respectively."
  1014. :group 'org-agenda-line-format
  1015. :type '(list
  1016. (string :tag "Deadline today ")
  1017. (choice :tag "Deadline relative"
  1018. (string :tag "Format string")
  1019. (function))))
  1020. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1021. "Text preceeding scheduled items in the agenda view.
  1022. This is a list with two strings. The first applies when the item is
  1023. scheduled on the current day. The second applies when it has been scheduled
  1024. previously, it may contain a %d indicating that this is the nth time that
  1025. this item is scheduled, due to automatic rescheduling of unfinished items
  1026. for the following day. So this number is one larger than the number of days
  1027. that passed since this item was scheduled first."
  1028. :group 'org-agenda-line-format
  1029. :type '(list
  1030. (string :tag "Scheduled today ")
  1031. (string :tag "Scheduled previously")))
  1032. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1033. "Text preceeding deadline items in the agenda view.
  1034. This is a list with two strings. The first applies when the item has its
  1035. deadline on the current day. The second applies when it is in the past or
  1036. in the future, it may contain %d to capture how many days away the deadline
  1037. is (was)."
  1038. :group 'org-agenda-line-format
  1039. :type '(list
  1040. (string :tag "Deadline today ")
  1041. (choice :tag "Deadline relative"
  1042. (string :tag "Format string")
  1043. (function))))
  1044. (defcustom org-agenda-remove-times-when-in-prefix t
  1045. "Non-nil means, remove duplicate time specifications in agenda items.
  1046. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1047. time-of-day specification in a headline or diary entry is extracted and
  1048. placed into the prefix. If this option is non-nil, the original specification
  1049. \(a timestamp or -range, or just a plain time(range) specification like
  1050. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1051. cluttered.
  1052. The option can be t or nil. It may also be the symbol `beg', indicating
  1053. that the time should only be removed what it is located at the beginning of
  1054. the headline/diary entry."
  1055. :group 'org-agenda-line-format
  1056. :type '(choice
  1057. (const :tag "Always" t)
  1058. (const :tag "Never" nil)
  1059. (const :tag "When at beginning of entry" beg)))
  1060. (defcustom org-agenda-default-appointment-duration nil
  1061. "Default duration for appointments that only have a starting time.
  1062. When nil, no duration is specified in such cases.
  1063. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1064. :group 'org-agenda-line-format
  1065. :type '(choice
  1066. (integer :tag "Minutes")
  1067. (const :tag "No default duration")))
  1068. (defcustom org-agenda-show-inherited-tags t
  1069. "Non-nil means, show inherited tags in each agenda line."
  1070. :group 'org-agenda-line-format
  1071. :type 'boolean)
  1072. (defcustom org-agenda-remove-tags nil
  1073. "Non-nil means, remove the tags from the headline copy in the agenda.
  1074. When this is the symbol `prefix', only remove tags when
  1075. `org-agenda-prefix-format' contains a `%T' specifier."
  1076. :group 'org-agenda-line-format
  1077. :type '(choice
  1078. (const :tag "Always" t)
  1079. (const :tag "Never" nil)
  1080. (const :tag "When prefix format contains %T" prefix)))
  1081. (if (fboundp 'defvaralias)
  1082. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1083. 'org-agenda-remove-tags))
  1084. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1085. "Shift tags in agenda items to this column.
  1086. If this number is positive, it specifies the column. If it is negative,
  1087. it means that the tags should be flushright to that column. For example,
  1088. -80 works well for a normal 80 character screen."
  1089. :group 'org-agenda-line-format
  1090. :type 'integer)
  1091. (if (fboundp 'defvaralias)
  1092. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1093. (defcustom org-agenda-fontify-priorities 'cookies
  1094. "Non-nil means, highlight low and high priorities in agenda.
  1095. When t, the highest priority entries are bold, lowest priority italic.
  1096. However, settings in org-priority-faces will overrule these faces.
  1097. When this variable is the symbol `cookies', only fontify the
  1098. cookies, not the entire task.
  1099. This may also be an association list of priority faces, whose
  1100. keys are the character values of `org-highest-priority',
  1101. `org-default-priority', and `org-lowest-priority' (the default values
  1102. are ?A, ?B, and ?C, respectively). The face may be a named face,
  1103. or a list like `(:background \"Red\")'."
  1104. :group 'org-agenda-line-format
  1105. :type '(choice
  1106. (const :tag "Never" nil)
  1107. (const :tag "Defaults" t)
  1108. (const :tag "Cookies only" cookies)
  1109. (repeat :tag "Specify"
  1110. (list (character :tag "Priority" :value ?A)
  1111. (sexp :tag "face")))))
  1112. (defgroup org-agenda-column-view nil
  1113. "Options concerning column view in the agenda."
  1114. :tag "Org Agenda Column View"
  1115. :group 'org-agenda)
  1116. (defcustom org-agenda-columns-show-summaries t
  1117. "Non-nil means, show summaries for columns displayed in the agenda view."
  1118. :group 'org-agenda-column-view
  1119. :type 'boolean)
  1120. (defcustom org-agenda-columns-remove-prefix-from-item t
  1121. "Non-nil means, remove the prefix from a headline for agenda column view.
  1122. The special ITEM field in the columns format contains the current line, with
  1123. all information shown in other columns (like the TODO state or a tag).
  1124. When this variable is non-nil, also the agenda prefix will be removed from
  1125. the content of the ITEM field, to make sure as much as possible of the
  1126. headline can be shown in the limited width of the field."
  1127. :group 'org-agenda
  1128. :type 'boolean)
  1129. (defcustom org-agenda-columns-compute-summary-properties t
  1130. "Non-nil means, recompute all summary properties before column view.
  1131. When column view in the agenda is listing properties that have a summary
  1132. operator, it can go to all relevant buffers and recompute the summaries
  1133. there. This can mean overhead for the agenda column view, but is necessary
  1134. to have thing up to date.
  1135. As a special case, a CLOCKSUM property also makes sure that the clock
  1136. computations are current."
  1137. :group 'org-agenda-column-view
  1138. :type 'boolean)
  1139. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1140. "Non-nil means, the duration of an appointment will add to day effort.
  1141. The property to which appointment durations will be added is the one given
  1142. in the option `org-effort-property'. If an appointment does not have
  1143. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1144. is not set, an appointment without end time will not contribute to the time
  1145. estimate."
  1146. :group 'org-agenda-column-view
  1147. :type 'boolean)
  1148. (defcustom org-agenda-auto-exclude-function nil
  1149. "A function called with a tag to decide if it is filtered on '/ RET'.
  1150. The sole argument to the function, which is called once for each
  1151. possible tag, is a string giving the name of the tag. The
  1152. function should return either nil if the tag should be included
  1153. as normal, or \"-<TAG>\" to exclude the tag."
  1154. :group 'org-agenda
  1155. :type 'function)
  1156. (eval-when-compile
  1157. (require 'cl))
  1158. (require 'org)
  1159. (defun org-add-agenda-custom-command (entry)
  1160. "Replace or add a command in `org-agenda-custom-commands'.
  1161. This is mostly for hacking and trying a new command - once the command
  1162. works you probably want to add it to `org-agenda-custom-commands' for good."
  1163. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1164. (if ass
  1165. (setcdr ass (cdr entry))
  1166. (push entry org-agenda-custom-commands))))
  1167. ;;; Define the Org-agenda-mode
  1168. (defvar org-agenda-mode-map (make-sparse-keymap)
  1169. "Keymap for `org-agenda-mode'.")
  1170. (if (fboundp 'defvaralias)
  1171. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1172. (defvar org-agenda-menu) ; defined later in this file.
  1173. (defvar org-agenda-restrict) ; defined later in this file.
  1174. (defvar org-agenda-follow-mode nil)
  1175. (defvar org-agenda-entry-text-mode nil)
  1176. (defvar org-agenda-clockreport-mode nil)
  1177. (defvar org-agenda-show-log nil)
  1178. (defvar org-agenda-redo-command nil)
  1179. (defvar org-agenda-query-string nil)
  1180. (defvar org-agenda-mode-hook nil
  1181. "Hook for org-agenda-mode, run after the mode is turned on.")
  1182. (defvar org-agenda-type nil)
  1183. (defvar org-agenda-force-single-file nil)
  1184. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1185. (defun org-agenda-mode ()
  1186. "Mode for time-sorted view on action items in Org-mode files.
  1187. The following commands are available:
  1188. \\{org-agenda-mode-map}"
  1189. (interactive)
  1190. (kill-all-local-variables)
  1191. (setq org-agenda-undo-list nil
  1192. org-agenda-pending-undo-list nil
  1193. org-agenda-bulk-marked-entries nil)
  1194. (setq major-mode 'org-agenda-mode)
  1195. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1196. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1197. (setq mode-name "Org-Agenda")
  1198. (use-local-map org-agenda-mode-map)
  1199. (easy-menu-add org-agenda-menu)
  1200. (if org-startup-truncated (setq truncate-lines t))
  1201. (org-set-local 'line-move-visual nil)
  1202. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1203. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1204. ;; Make sure properties are removed when copying text
  1205. (when (boundp 'buffer-substring-filters)
  1206. (org-set-local 'buffer-substring-filters
  1207. (cons (lambda (x)
  1208. (set-text-properties 0 (length x) nil x) x)
  1209. buffer-substring-filters)))
  1210. (unless org-agenda-keep-modes
  1211. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1212. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1213. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1214. org-agenda-show-log org-agenda-start-with-log-mode))
  1215. (easy-menu-change
  1216. '("Agenda") "Agenda Files"
  1217. (append
  1218. (list
  1219. (vector
  1220. (if (get 'org-agenda-files 'org-restrict)
  1221. "Restricted to single file"
  1222. "Edit File List")
  1223. '(org-edit-agenda-file-list)
  1224. (not (get 'org-agenda-files 'org-restrict)))
  1225. "--")
  1226. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1227. (org-agenda-set-mode-name)
  1228. (apply
  1229. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1230. (list 'org-agenda-mode-hook)))
  1231. (substitute-key-definition 'undo 'org-agenda-undo
  1232. org-agenda-mode-map global-map)
  1233. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1234. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1235. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1236. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1237. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1238. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1239. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1240. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1241. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1242. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1243. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1244. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1245. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1246. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1247. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1248. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1249. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1250. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1251. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1252. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1253. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1254. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1255. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1256. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1257. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1258. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1259. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1260. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1261. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1262. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1263. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1264. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1265. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1266. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1267. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1268. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1269. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1270. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1271. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1272. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1273. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1274. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1275. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1276. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1277. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1278. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1279. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1280. (while l (org-defkey org-agenda-mode-map
  1281. (int-to-string (pop l)) 'digit-argument)))
  1282. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1283. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1284. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1285. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1286. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1287. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1288. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1289. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1290. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1291. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1292. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1293. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1294. 'org-clock-modify-effort-estimate)
  1295. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1296. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1297. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1298. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1299. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1300. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1301. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1302. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1303. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1304. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1305. (substitute-key-definition 'next-line 'org-agenda-next-line
  1306. org-agenda-mode-map global-map)
  1307. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1308. org-agenda-mode-map global-map)
  1309. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1310. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1311. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1312. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1313. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1314. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1315. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1316. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1317. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1318. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1319. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1320. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1321. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1322. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1323. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1324. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1325. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1326. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1327. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1328. (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
  1329. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1330. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1331. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1332. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1333. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1334. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1335. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1336. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1337. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1338. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1339. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1340. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1341. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1342. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1343. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1344. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1345. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1346. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1347. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1348. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1349. (org-defkey org-agenda-mode-map
  1350. (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
  1351. (org-defkey org-agenda-mode-map
  1352. (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
  1353. (when org-agenda-mouse-1-follows-link
  1354. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1355. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1356. '("Agenda"
  1357. ("Agenda Files")
  1358. "--"
  1359. ("Agenda Dates"
  1360. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1361. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1362. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1363. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1364. "--"
  1365. ("View"
  1366. ["Day View" org-agenda-day-view
  1367. :active (org-agenda-check-type nil 'agenda)
  1368. :style radio :selected (equal org-agenda-ndays 1)
  1369. :keys "v d (or just d)"]
  1370. ["Week View" org-agenda-week-view
  1371. :active (org-agenda-check-type nil 'agenda)
  1372. :style radio :selected (equal org-agenda-ndays 7)
  1373. :keys "v w (or just w)"]
  1374. ["Month View" org-agenda-month-view
  1375. :active (org-agenda-check-type nil 'agenda)
  1376. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1377. :keys "v m"]
  1378. ["Year View" org-agenda-year-view
  1379. :active (org-agenda-check-type nil 'agenda)
  1380. :style radio :selected (member org-agenda-ndays '(365 366))
  1381. :keys "v y"]
  1382. "--"
  1383. ["Include Diary" org-agenda-toggle-diary
  1384. :style toggle :selected org-agenda-include-diary
  1385. :active (org-agenda-check-type nil 'agenda)]
  1386. ["Use Time Grid" org-agenda-toggle-time-grid
  1387. :style toggle :selected org-agenda-use-time-grid
  1388. :active (org-agenda-check-type nil 'agenda)]
  1389. "--"
  1390. ["Show clock report" org-agenda-clockreport-mode
  1391. :style toggle :selected org-agenda-clockreport-mode
  1392. :active (org-agenda-check-type nil 'agenda)]
  1393. ["Show some entry text" org-agenda-entry-text-mode
  1394. :style toggle :selected org-agenda-entry-text-mode
  1395. :active t]
  1396. "--"
  1397. ["Show Logbook entries" org-agenda-log-mode
  1398. :style toggle :selected org-agenda-show-log
  1399. :active (org-agenda-check-type nil 'agenda 'timeline)
  1400. :keys "v l (or just l)"]
  1401. ["Include archived trees" org-agenda-archives-mode
  1402. :style toggle :selected org-agenda-archives-mode :active t
  1403. :keys "v a"]
  1404. ["Include archive files" (org-agenda-archives-mode t)
  1405. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1406. :keys "v A"]
  1407. "--"
  1408. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1409. ["Write view to file" org-write-agenda t]
  1410. ["Rebuild buffer" org-agenda-redo t]
  1411. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1412. "--"
  1413. ["Show original entry" org-agenda-show t]
  1414. ["Go To (other window)" org-agenda-goto t]
  1415. ["Go To (this window)" org-agenda-switch-to t]
  1416. ["Follow Mode" org-agenda-follow-mode
  1417. :style toggle :selected org-agenda-follow-mode :active t]
  1418. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1419. "--"
  1420. ("TODO"
  1421. ["Cycle TODO" org-agenda-todo t]
  1422. ["Next TODO set" org-agenda-todo-nextset t]
  1423. ["Previous TODO set" org-agenda-todo-previousset t]
  1424. ["Add note" org-agenda-add-note t])
  1425. ("Archive/Refile/Delete"
  1426. ["Archive default" org-agenda-archive-default t]
  1427. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1428. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1429. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1430. ["Archive subtree" org-agenda-archive t]
  1431. "--"
  1432. ["Refile" org-agenda-refile t]
  1433. "--"
  1434. ["Delete subtree" org-agenda-kill t])
  1435. ("Bulk action"
  1436. ["Mark entry" org-agenda-bulk-mark t]
  1437. ["Unmark entry" org-agenda-bulk-unmark t]
  1438. ["Act on all marked" org-agenda-bulk-action t]
  1439. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1440. "--"
  1441. ("Tags and Properties"
  1442. ["Show all Tags" org-agenda-show-tags t]
  1443. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1444. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1445. "--"
  1446. ["Column View" org-columns t])
  1447. ("Deadline/Schedule"
  1448. ["Schedule" org-agenda-schedule t]
  1449. ["Set Deadline" org-agenda-deadline t]
  1450. "--"
  1451. ["Mark item" org-agenda-action :active t :keys "k m"]
  1452. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1453. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1454. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1455. "--"
  1456. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1457. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1458. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1459. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1460. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1461. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1462. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1463. ("Clock and Effort"
  1464. ["Clock in" org-agenda-clock-in t]
  1465. ["Clock out" org-agenda-clock-out t]
  1466. ["Clock cancel" org-agenda-clock-cancel t]
  1467. ["Goto running clock" org-clock-goto t]
  1468. "--"
  1469. ["Set Effort" org-agenda-set-effort t]
  1470. ["Change clocked effort" org-clock-modify-effort-estimate
  1471. (org-clock-is-active)])
  1472. ("Priority"
  1473. ["Set Priority" org-agenda-priority t]
  1474. ["Increase Priority" org-agenda-priority-up t]
  1475. ["Decrease Priority" org-agenda-priority-down t]
  1476. ["Show Priority" org-agenda-show-priority t])
  1477. ("Calendar/Diary"
  1478. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1479. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1480. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1481. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1482. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1483. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1484. "--"
  1485. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1486. "--"
  1487. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1488. "--"
  1489. ("MobileOrg"
  1490. ["Push Files and Views" org-mobile-push t]
  1491. ["Get Captured and Flagged" org-mobile-pull t]
  1492. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1493. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1494. "--"
  1495. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1496. "--"
  1497. ["Quit" org-agenda-quit t]
  1498. ["Exit and Release Buffers" org-agenda-exit t]
  1499. ))
  1500. ;;; Agenda undo
  1501. (defvar org-agenda-allow-remote-undo t
  1502. "Non-nil means, allow remote undo from the agenda buffer.")
  1503. (defvar org-agenda-undo-list nil
  1504. "List of undoable operations in the agenda since last refresh.")
  1505. (defvar org-agenda-undo-has-started-in nil
  1506. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1507. (defvar org-agenda-pending-undo-list nil
  1508. "In a series of undo commands, this is the list of remaining undo items.")
  1509. (defun org-agenda-undo ()
  1510. "Undo a remote editing step in the agenda.
  1511. This undoes changes both in the agenda buffer and in the remote buffer
  1512. that have been changed along."
  1513. (interactive)
  1514. (or org-agenda-allow-remote-undo
  1515. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1516. (if (not (eq this-command last-command))
  1517. (setq org-agenda-undo-has-started-in nil
  1518. org-agenda-pending-undo-list org-agenda-undo-list))
  1519. (if (not org-agenda-pending-undo-list)
  1520. (error "No further undo information"))
  1521. (let* ((entry (pop org-agenda-pending-undo-list))
  1522. buf line cmd rembuf)
  1523. (setq cmd (pop entry) line (pop entry))
  1524. (setq rembuf (nth 2 entry))
  1525. (org-with-remote-undo rembuf
  1526. (while (bufferp (setq buf (pop entry)))
  1527. (if (pop entry)
  1528. (with-current-buffer buf
  1529. (let ((last-undo-buffer buf)
  1530. (inhibit-read-only t))
  1531. (unless (memq buf org-agenda-undo-has-started-in)
  1532. (push buf org-agenda-undo-has-started-in)
  1533. (make-local-variable 'pending-undo-list)
  1534. (undo-start))
  1535. (while (and pending-undo-list
  1536. (listp pending-undo-list)
  1537. (not (car pending-undo-list)))
  1538. (pop pending-undo-list))
  1539. (undo-more 1))))))
  1540. (org-goto-line line)
  1541. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1542. (defun org-verify-change-for-undo (l1 l2)
  1543. "Verify that a real change occurred between the undo lists L1 and L2."
  1544. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1545. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1546. (not (eq l1 l2)))
  1547. ;;; Agenda dispatch
  1548. (defvar org-agenda-restrict nil)
  1549. (defvar org-agenda-restrict-begin (make-marker))
  1550. (defvar org-agenda-restrict-end (make-marker))
  1551. (defvar org-agenda-last-dispatch-buffer nil)
  1552. (defvar org-agenda-overriding-restriction nil)
  1553. ;;;###autoload
  1554. (defun org-agenda (&optional arg keys restriction)
  1555. "Dispatch agenda commands to collect entries to the agenda buffer.
  1556. Prompts for a command to execute. Any prefix arg will be passed
  1557. on to the selected command. The default selections are:
  1558. a Call `org-agenda-list' to display the agenda for current day or week.
  1559. t Call `org-todo-list' to display the global todo list.
  1560. T Call `org-todo-list' to display the global todo list, select only
  1561. entries with a specific TODO keyword (the user gets a prompt).
  1562. m Call `org-tags-view' to display headlines with tags matching
  1563. a condition (the user is prompted for the condition).
  1564. M Like `m', but select only TODO entries, no ordinary headlines.
  1565. L Create a timeline for the current buffer.
  1566. e Export views to associated files.
  1567. s Search entries for keywords.
  1568. / Multi occur across all agenda files and also files listed
  1569. in `org-agenda-text-search-extra-files'.
  1570. < Restrict agenda commands to buffer, subtree, or region.
  1571. Press several times to get the desired effect.
  1572. > Remove a previous restriction.
  1573. # List \"stuck\" projects.
  1574. ! Configure what \"stuck\" means.
  1575. C Configure custom agenda commands.
  1576. More commands can be added by configuring the variable
  1577. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1578. searches can be pre-defined in this way.
  1579. If the current buffer is in Org-mode and visiting a file, you can also
  1580. first press `<' once to indicate that the agenda should be temporarily
  1581. \(until the next use of \\[org-agenda]) restricted to the current file.
  1582. Pressing `<' twice means to restrict to the current subtree or region
  1583. \(if active)."
  1584. (interactive "P")
  1585. (catch 'exit
  1586. (let* ((prefix-descriptions nil)
  1587. (org-agenda-window-setup (if (equal (buffer-name)
  1588. org-agenda-buffer-name)
  1589. 'current-window
  1590. org-agenda-window-setup))
  1591. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1592. (org-agenda-custom-commands
  1593. ;; normalize different versions
  1594. (delq nil
  1595. (mapcar
  1596. (lambda (x)
  1597. (cond ((stringp (cdr x))
  1598. (push x prefix-descriptions)
  1599. nil)
  1600. ((stringp (nth 1 x)) x)
  1601. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1602. (t (cons (car x) (cons "" (cdr x))))))
  1603. org-agenda-custom-commands)))
  1604. (buf (current-buffer))
  1605. (bfn (buffer-file-name (buffer-base-buffer)))
  1606. entry key type match lprops ans)
  1607. ;; Turn off restriction unless there is an overriding one,
  1608. (unless org-agenda-overriding-restriction
  1609. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1610. ;; There is a request to keep the file list in place
  1611. (put 'org-agenda-files 'org-restrict nil))
  1612. (setq org-agenda-restrict nil)
  1613. (move-marker org-agenda-restrict-begin nil)
  1614. (move-marker org-agenda-restrict-end nil))
  1615. ;; Delete old local properties
  1616. (put 'org-agenda-redo-command 'org-lprops nil)
  1617. ;; Remember where this call originated
  1618. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1619. (unless keys
  1620. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1621. keys (car ans)
  1622. restriction (cdr ans)))
  1623. ;; Establish the restriction, if any
  1624. (when (and (not org-agenda-overriding-restriction) restriction)
  1625. (put 'org-agenda-files 'org-restrict (list bfn))
  1626. (cond
  1627. ((eq restriction 'region)
  1628. (setq org-agenda-restrict t)
  1629. (move-marker org-agenda-restrict-begin (region-beginning))
  1630. (move-marker org-agenda-restrict-end (region-end)))
  1631. ((eq restriction 'subtree)
  1632. (save-excursion
  1633. (setq org-agenda-restrict t)
  1634. (org-back-to-heading t)
  1635. (move-marker org-agenda-restrict-begin (point))
  1636. (move-marker org-agenda-restrict-end
  1637. (progn (org-end-of-subtree t)))))))
  1638. (require 'calendar) ; FIXME: can we avoid this for some commands?
  1639. ;; For example the todo list should not need it (but does...)
  1640. (cond
  1641. ((setq entry (assoc keys org-agenda-custom-commands))
  1642. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1643. (progn
  1644. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1645. lprops (nth 4 entry))
  1646. (put 'org-agenda-redo-command 'org-lprops lprops)
  1647. (cond
  1648. ((eq type 'agenda)
  1649. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1650. ((eq type 'alltodo)
  1651. (org-let lprops '(org-todo-list current-prefix-arg)))
  1652. ((eq type 'search)
  1653. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1654. ((eq type 'stuck)
  1655. (org-let lprops '(org-agenda-list-stuck-projects
  1656. current-prefix-arg)))
  1657. ((eq type 'tags)
  1658. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1659. ((eq type 'tags-todo)
  1660. (org-let lprops '(org-tags-view '(4) match)))
  1661. ((eq type 'todo)
  1662. (org-let lprops '(org-todo-list match)))
  1663. ((eq type 'tags-tree)
  1664. (org-check-for-org-mode)
  1665. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1666. ((eq type 'todo-tree)
  1667. (org-check-for-org-mode)
  1668. (org-let lprops
  1669. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1670. (regexp-quote match) "\\>"))))
  1671. ((eq type 'occur-tree)
  1672. (org-check-for-org-mode)
  1673. (org-let lprops '(org-occur match)))
  1674. ((functionp type)
  1675. (org-let lprops '(funcall type match)))
  1676. ((fboundp type)
  1677. (org-let lprops '(funcall type match)))
  1678. (t (error "Invalid custom agenda command type %s" type))))
  1679. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1680. ((equal keys "C")
  1681. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1682. (customize-variable 'org-agenda-custom-commands))
  1683. ((equal keys "a") (call-interactively 'org-agenda-list))
  1684. ((equal keys "s") (call-interactively 'org-search-view))
  1685. ((equal keys "t") (call-interactively 'org-todo-list))
  1686. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1687. ((equal keys "m") (call-interactively 'org-tags-view))
  1688. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1689. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1690. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1691. (org-add-hook
  1692. 'post-command-hook
  1693. (lambda ()
  1694. (unless (current-message)
  1695. (let* ((m (org-agenda-get-any-marker))
  1696. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1697. (when note
  1698. (message (concat
  1699. "FLAGGING-NOTE ([?] for more info): "
  1700. (org-add-props
  1701. (replace-regexp-in-string
  1702. "\\\\n" "//"
  1703. (copy-sequence note))
  1704. nil 'face 'org-warning)))))))
  1705. t t))
  1706. ((equal keys "L")
  1707. (unless (org-mode-p)
  1708. (error "This is not an Org-mode file"))
  1709. (unless restriction
  1710. (put 'org-agenda-files 'org-restrict (list bfn))
  1711. (org-call-with-arg 'org-timeline arg)))
  1712. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1713. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1714. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1715. (t (error "Invalid agenda key"))))))
  1716. (defun org-agenda-normalize-custom-commands (cmds)
  1717. (delq nil
  1718. (mapcar
  1719. (lambda (x)
  1720. (cond ((stringp (cdr x)) nil)
  1721. ((stringp (nth 1 x)) x)
  1722. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1723. (t (cons (car x) (cons "" (cdr x))))))
  1724. cmds)))
  1725. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1726. "The user interface for selecting an agenda command."
  1727. (catch 'exit
  1728. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1729. (restrict-ok (and bfn (org-mode-p)))
  1730. (region-p (org-region-active-p))
  1731. (custom org-agenda-custom-commands)
  1732. (selstring "")
  1733. restriction second-time
  1734. c entry key type match prefixes rmheader header-end custom1 desc)
  1735. (save-window-excursion
  1736. (delete-other-windows)
  1737. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1738. (erase-buffer)
  1739. (insert (eval-when-compile
  1740. (let ((header
  1741. "
  1742. Press key for an agenda command: < Buffer, subtree/region restriction
  1743. -------------------------------- > Remove restriction
  1744. a Agenda for current week or day e Export agenda views
  1745. t List of all TODO entries T Entries with special TODO kwd
  1746. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1747. L Timeline for current buffer # List stuck projects (!=configure)
  1748. s Search for keywords C Configure custom agenda commands
  1749. / Multi-occur ? Find :FLAGGED: entries
  1750. ")
  1751. (start 0))
  1752. (while (string-match
  1753. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1754. header start)
  1755. (setq start (match-end 0))
  1756. (add-text-properties (match-beginning 2) (match-end 2)
  1757. '(face bold) header))
  1758. header)))
  1759. (setq header-end (move-marker (make-marker) (point)))
  1760. (while t
  1761. (setq custom1 custom)
  1762. (when (eq rmheader t)
  1763. (org-goto-line 1)
  1764. (re-search-forward ":" nil t)
  1765. (delete-region (match-end 0) (point-at-eol))
  1766. (forward-char 1)
  1767. (looking-at "-+")
  1768. (delete-region (match-end 0) (point-at-eol))
  1769. (move-marker header-end (match-end 0)))
  1770. (goto-char header-end)
  1771. (delete-region (point) (point-max))
  1772. (while (setq entry (pop custom1))
  1773. (setq key (car entry) desc (nth 1 entry)
  1774. type (nth 2 entry)
  1775. match (nth 3 entry))
  1776. (if (> (length key) 1)
  1777. (add-to-list 'prefixes (string-to-char key))
  1778. (insert
  1779. (format
  1780. "\n%-4s%-14s: %s"
  1781. (org-add-props (copy-sequence key)
  1782. '(face bold))
  1783. (cond
  1784. ((string-match "\\S-" desc) desc)
  1785. ((eq type 'agenda) "Agenda for current week or day")
  1786. ((eq type 'alltodo) "List of all TODO entries")
  1787. ((eq type 'search) "Word search")
  1788. ((eq type 'stuck) "List of stuck projects")
  1789. ((eq type 'todo) "TODO keyword")
  1790. ((eq type 'tags) "Tags query")
  1791. ((eq type 'tags-todo) "Tags (TODO)")
  1792. ((eq type 'tags-tree) "Tags tree")
  1793. ((eq type 'todo-tree) "TODO kwd tree")
  1794. ((eq type 'occur-tree) "Occur tree")
  1795. ((functionp type) (if (symbolp type)
  1796. (symbol-name type)
  1797. "Lambda expression"))
  1798. (t "???"))
  1799. (cond
  1800. ((stringp match)
  1801. (setq match (copy-sequence match))
  1802. (org-add-props match nil 'face 'org-warning))
  1803. (match
  1804. (format "set of %d commands" (length match)))
  1805. (t ""))))))
  1806. (when prefixes
  1807. (mapc (lambda (x)
  1808. (insert
  1809. (format "\n%s %s"
  1810. (org-add-props (char-to-string x)
  1811. nil 'face 'bold)
  1812. (or (cdr (assoc (concat selstring (char-to-string x))
  1813. prefix-descriptions))
  1814. "Prefix key"))))
  1815. prefixes))
  1816. (goto-char (point-min))
  1817. (if second-time
  1818. (if (not (pos-visible-in-window-p (point-max)))
  1819. (org-fit-window-to-buffer))
  1820. (setq second-time t)
  1821. (org-fit-window-to-buffer))
  1822. (message "Press key for agenda command%s:"
  1823. (if (or restrict-ok org-agenda-overriding-restriction)
  1824. (if org-agenda-overriding-restriction
  1825. " (restriction lock active)"
  1826. (if restriction
  1827. (format " (restricted to %s)" restriction)
  1828. " (unrestricted)"))
  1829. ""))
  1830. (setq c (read-char-exclusive))
  1831. (message "")
  1832. (cond
  1833. ((assoc (char-to-string c) custom)
  1834. (setq selstring (concat selstring (char-to-string c)))
  1835. (throw 'exit (cons selstring restriction)))
  1836. ((memq c prefixes)
  1837. (setq selstring (concat selstring (char-to-string c))
  1838. prefixes nil
  1839. rmheader (or rmheader t)
  1840. custom (delq nil (mapcar
  1841. (lambda (x)
  1842. (if (or (= (length (car x)) 1)
  1843. (/= (string-to-char (car x)) c))
  1844. nil
  1845. (cons (substring (car x) 1) (cdr x))))
  1846. custom))))
  1847. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  1848. (message "Restriction is only possible in Org-mode buffers")
  1849. (ding) (sit-for 1))
  1850. ((eq c ?1)
  1851. (org-agenda-remove-restriction-lock 'noupdate)
  1852. (setq restriction 'buffer))
  1853. ((eq c ?0)
  1854. (org-agenda-remove-restriction-lock 'noupdate)
  1855. (setq restriction (if region-p 'region 'subtree)))
  1856. ((eq c ?<)
  1857. (org-agenda-remove-restriction-lock 'noupdate)
  1858. (setq restriction
  1859. (cond
  1860. ((eq restriction 'buffer)
  1861. (if region-p 'region 'subtree))
  1862. ((memq restriction '(subtree region))
  1863. nil)
  1864. (t 'buffer))))
  1865. ((eq c ?>)
  1866. (org-agenda-remove-restriction-lock 'noupdate)
  1867. (setq restriction nil))
  1868. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  1869. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  1870. ((and (> (length selstring) 0) (eq c ?\d))
  1871. (delete-window)
  1872. (org-agenda-get-restriction-and-command prefix-descriptions))
  1873. ((equal c ?q) (error "Abort"))
  1874. (t (error "Invalid key %c" c))))))))
  1875. (defun org-run-agenda-series (name series)
  1876. (org-let (nth 1 series) '(org-prepare-agenda name))
  1877. (let* ((org-agenda-multi t)
  1878. (redo (list 'org-run-agenda-series name (list 'quote series)))
  1879. (cmds (car series))
  1880. (gprops (nth 1 series))
  1881. match ;; The byte compiler incorrectly complains about this. Keep it!
  1882. cmd type lprops)
  1883. (while (setq cmd (pop cmds))
  1884. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  1885. (cond
  1886. ((eq type 'agenda)
  1887. (org-let2 gprops lprops
  1888. '(call-interactively 'org-agenda-list)))
  1889. ((eq type 'alltodo)
  1890. (org-let2 gprops lprops
  1891. '(call-interactively 'org-todo-list)))
  1892. ((eq type 'search)
  1893. (org-let2 gprops lprops
  1894. '(org-search-view current-prefix-arg match nil)))
  1895. ((eq type 'stuck)
  1896. (org-let2 gprops lprops
  1897. '(call-interactively 'org-agenda-list-stuck-projects)))
  1898. ((eq type 'tags)
  1899. (org-let2 gprops lprops
  1900. '(org-tags-view current-prefix-arg match)))
  1901. ((eq type 'tags-todo)
  1902. (org-let2 gprops lprops
  1903. '(org-tags-view '(4) match)))
  1904. ((eq type 'todo)
  1905. (org-let2 gprops lprops
  1906. '(org-todo-list match)))
  1907. ((fboundp type)
  1908. (org-let2 gprops lprops
  1909. '(funcall type match)))
  1910. (t (error "Invalid type in command series"))))
  1911. (widen)
  1912. (setq org-agenda-redo-command redo)
  1913. (goto-char (point-min)))
  1914. (org-fit-agenda-window)
  1915. (org-let (nth 1 series) '(org-finalize-agenda)))
  1916. ;;;###autoload
  1917. (defmacro org-batch-agenda (cmd-key &rest parameters)
  1918. "Run an agenda command in batch mode and send the result to STDOUT.
  1919. If CMD-KEY is a string of length 1, it is used as a key in
  1920. `org-agenda-custom-commands' and triggers this command. If it is a
  1921. longer string it is used as a tags/todo match string.
  1922. Paramters are alternating variable names and values that will be bound
  1923. before running the agenda command."
  1924. (let (pars)
  1925. (while parameters
  1926. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1927. (if (> (length cmd-key) 2)
  1928. (eval (list 'let (nreverse pars)
  1929. (list 'org-tags-view nil cmd-key)))
  1930. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1931. (set-buffer org-agenda-buffer-name)
  1932. (princ (org-encode-for-stdout (buffer-string)))))
  1933. ;(defun org-encode-for-stdout (string)
  1934. ; (if (fboundp 'encode-coding-string)
  1935. ; (encode-coding-string string buffer-file-coding-system)
  1936. ; string))
  1937. (defun org-encode-for-stdout (string)
  1938. string)
  1939. (defvar org-agenda-info nil)
  1940. ;;;###autoload
  1941. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  1942. "Run an agenda command in batch mode and send the result to STDOUT.
  1943. If CMD-KEY is a string of length 1, it is used as a key in
  1944. `org-agenda-custom-commands' and triggers this command. If it is a
  1945. longer string it is used as a tags/todo match string.
  1946. Paramters are alternating variable names and values that will be bound
  1947. before running the agenda command.
  1948. The output gives a line for each selected agenda item. Each
  1949. item is a list of comma-separated values, like this:
  1950. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  1951. category The category of the item
  1952. head The headline, without TODO kwd, TAGS and PRIORITY
  1953. type The type of the agenda entry, can be
  1954. todo selected in TODO match
  1955. tagsmatch selected in tags match
  1956. diary imported from diary
  1957. deadline a deadline on given date
  1958. scheduled scheduled on given date
  1959. timestamp entry has timestamp on given date
  1960. closed entry was closed on given date
  1961. upcoming-deadline warning about deadline
  1962. past-scheduled forwarded scheduled item
  1963. block entry has date block including g. date
  1964. todo The todo keyword, if any
  1965. tags All tags including inherited ones, separated by colons
  1966. date The relevant date, like 2007-2-14
  1967. time The time, like 15:00-16:50
  1968. extra Sting with extra planning info
  1969. priority-l The priority letter if any was given
  1970. priority-n The computed numerical priority
  1971. agenda-day The day in the agenda where this is listed"
  1972. (let (pars)
  1973. (while parameters
  1974. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1975. (push (list 'org-agenda-remove-tags t) pars)
  1976. (if (> (length cmd-key) 2)
  1977. (eval (list 'let (nreverse pars)
  1978. (list 'org-tags-view nil cmd-key)))
  1979. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1980. (set-buffer org-agenda-buffer-name)
  1981. (let* ((lines (org-split-string (buffer-string) "\n"))
  1982. line)
  1983. (while (setq line (pop lines))
  1984. (catch 'next
  1985. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  1986. (setq org-agenda-info
  1987. (org-fix-agenda-info (text-properties-at 0 line)))
  1988. (princ
  1989. (org-encode-for-stdout
  1990. (mapconcat 'org-agenda-export-csv-mapper
  1991. '(org-category txt type todo tags date time-of-day extra
  1992. priority-letter priority agenda-day)
  1993. ",")))
  1994. (princ "\n"))))))
  1995. (defun org-fix-agenda-info (props)
  1996. "Make sure all properties on an agenda item have a canonical form,
  1997. so the export commands can easily use it."
  1998. (let (tmp re)
  1999. (when (setq tmp (plist-get props 'tags))
  2000. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2001. (when (setq tmp (plist-get props 'date))
  2002. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2003. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2004. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2005. (setq tmp (calendar-date-string tmp)))
  2006. (setq props (plist-put props 'date tmp)))
  2007. (when (setq tmp (plist-get props 'day))
  2008. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2009. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2010. (setq tmp (calendar-date-string tmp)))
  2011. (setq props (plist-put props 'day tmp))
  2012. (setq props (plist-put props 'agenda-day tmp)))
  2013. (when (setq tmp (plist-get props 'txt))
  2014. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2015. (plist-put props 'priority-letter (match-string 1 tmp))
  2016. (setq tmp (replace-match "" t t tmp)))
  2017. (when (and (setq re (plist-get props 'org-todo-regexp))
  2018. (setq re (concat "\\`\\.*" re " ?"))
  2019. (string-match re tmp))
  2020. (plist-put props 'todo (match-string 1 tmp))
  2021. (setq tmp (replace-match "" t t tmp)))
  2022. (plist-put props 'txt tmp)))
  2023. props)
  2024. (defun org-agenda-export-csv-mapper (prop)
  2025. (let ((res (plist-get org-agenda-info prop)))
  2026. (setq res
  2027. (cond
  2028. ((not res) "")
  2029. ((stringp res) res)
  2030. (t (prin1-to-string res))))
  2031. (while (string-match "," res)
  2032. (setq res (replace-match ";" t t res)))
  2033. (org-trim res)))
  2034. ;;;###autoload
  2035. (defun org-store-agenda-views (&rest parameters)
  2036. (interactive)
  2037. (eval (list 'org-batch-store-agenda-views)))
  2038. ;; FIXME, why is this a macro?????
  2039. ;;;###autoload
  2040. (defmacro org-batch-store-agenda-views (&rest parameters)
  2041. "Run all custom agenda commands that have a file argument."
  2042. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2043. (pop-up-frames nil)
  2044. (dir default-directory)
  2045. pars cmd thiscmdkey files opts cmd-or-set)
  2046. (while parameters
  2047. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2048. (setq pars (reverse pars))
  2049. (save-window-excursion
  2050. (while cmds
  2051. (setq cmd (pop cmds)
  2052. thiscmdkey (car cmd)
  2053. cmd-or-set (nth 2 cmd)
  2054. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2055. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2056. (if (stringp files) (setq files (list files)))
  2057. (when files
  2058. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2059. (list 'org-agenda nil thiscmdkey)))
  2060. (set-buffer org-agenda-buffer-name)
  2061. (while files
  2062. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2063. (list 'org-write-agenda
  2064. (expand-file-name (pop files) dir) nil t))))
  2065. (and (get-buffer org-agenda-buffer-name)
  2066. (kill-buffer org-agenda-buffer-name)))))))
  2067. (defun org-agenda-mark-header-line (pos)
  2068. "Mark the line at POS as an agenda structure header."
  2069. (save-excursion
  2070. (goto-char pos)
  2071. (put-text-property (point-at-bol) (point-at-eol)
  2072. 'org-agenda-structural-header t)
  2073. (when org-agenda-title-append
  2074. (put-text-property (point-at-bol) (point-at-eol)
  2075. 'org-agenda-title-append org-agenda-title-append))))
  2076. (defvar org-mobile-creating-agendas)
  2077. (defun org-write-agenda (file &optional open nosettings)
  2078. "Write the current buffer (an agenda view) as a file.
  2079. Depending on the extension of the file name, plain text (.txt),
  2080. HTML (.html or .htm) or Postscript (.ps) is produced.
  2081. If the extension is .ics, run icalendar export over all files used
  2082. to construct the agenda and limit the export to entries listed in the
  2083. agenda now.
  2084. With prefix argument OPEN, open the new file immediately.
  2085. If NOSETTINGS is given, do not scope the settings of
  2086. `org-agenda-exporter-settings' into the export commands. This is used when
  2087. the settings have already been scoped and we do not wish to overrule other,
  2088. higher priority settings."
  2089. (interactive "FWrite agenda to file: \nP")
  2090. (if (not (file-writable-p file))
  2091. (error "Cannot write agenda to file %s" file))
  2092. (cond
  2093. ((string-match "\\.html?\\'" file) (require 'htmlize))
  2094. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  2095. (org-let (if nosettings nil org-agenda-exporter-settings)
  2096. '(save-excursion
  2097. (save-window-excursion
  2098. (org-agenda-mark-filtered-text)
  2099. (let ((bs (copy-sequence (buffer-string))) beg)
  2100. (org-agenda-unmark-filtered-text)
  2101. (with-temp-buffer
  2102. (insert bs)
  2103. (org-agenda-remove-marked-text 'org-filtered)
  2104. (while (setq beg (text-property-any (point-min) (point-max)
  2105. 'org-filtered t))
  2106. (delete-region
  2107. beg (or (next-single-property-change beg 'org-filtered)
  2108. (point-max))))
  2109. (run-hooks 'org-agenda-before-write-hook)
  2110. (cond
  2111. ((org-bound-and-true-p org-mobile-creating-agendas)
  2112. (org-mobile-write-agenda-for-mobile file))
  2113. ((string-match "\\.html?\\'" file)
  2114. (set-buffer (htmlize-buffer (current-buffer)))
  2115. (when (and org-agenda-export-html-style
  2116. (string-match "<style>" org-agenda-export-html-style))
  2117. ;; replace <style> section with org-agenda-export-html-style
  2118. (goto-char (point-min))
  2119. (kill-region (- (search-forward "<style") 6)
  2120. (search-forward "</style>"))
  2121. (insert org-agenda-export-html-style))
  2122. (write-file file)
  2123. (kill-buffer (current-buffer))
  2124. (message "HTML written to %s" file))
  2125. ((string-match "\\.ps\\'" file)
  2126. (require 'ps-print)
  2127. (flet ((ps-get-buffer-name () "Agenda View"))
  2128. (ps-print-buffer-with-faces file))
  2129. (message "Postscript written to %s" file))
  2130. ((string-match "\\.pdf\\'" file)
  2131. (require 'ps-print)
  2132. (flet ((ps-get-buffer-name () "Agenda View"))
  2133. (ps-print-buffer-with-faces
  2134. (concat (file-name-sans-extension file) ".ps")))
  2135. (call-process "ps2pdf" nil nil nil
  2136. (expand-file-name
  2137. (concat (file-name-sans-extension file) ".ps"))
  2138. (expand-file-name file))
  2139. (message "PDF written to %s" file))
  2140. ((string-match "\\.ics\\'" file)
  2141. (require 'org-icalendar)
  2142. (let ((org-agenda-marker-table
  2143. (org-create-marker-find-array
  2144. (org-agenda-collect-markers)))
  2145. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2146. (org-combined-agenda-icalendar-file file))
  2147. (apply 'org-export-icalendar 'combine
  2148. (org-agenda-files nil 'ifmode))))
  2149. (t
  2150. (let ((bs (buffer-string)))
  2151. (find-file file)
  2152. (erase-buffer)
  2153. (insert bs)
  2154. (save-buffer 0)
  2155. (kill-buffer (current-buffer))
  2156. (message "Plain text written to %s" file))))))))
  2157. (set-buffer org-agenda-buffer-name))
  2158. (when open (org-open-file file)))
  2159. (defvar org-agenda-filter-overlays nil)
  2160. (defun org-agenda-mark-filtered-text ()
  2161. "Mark all text hidden by filtering with a text property."
  2162. (let ((inhibit-read-only t))
  2163. (mapc
  2164. (lambda (o)
  2165. (when (equal (org-overlay-buffer o) (current-buffer))
  2166. (put-text-property
  2167. (org-overlay-start o) (org-overlay-end o)
  2168. 'org-filtered t)))
  2169. org-agenda-filter-overlays)))
  2170. (defun org-agenda-unmark-filtered-text ()
  2171. "Remove the filtering text property."
  2172. (let ((inhibit-read-only t))
  2173. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2174. (defun org-agenda-remove-marked-text (property &optional value)
  2175. "Delete all text marked with VALUE of PROPERTY.
  2176. VALUE defaults to t."
  2177. (let (beg)
  2178. (setq value (or value t))
  2179. (while (setq beg (text-property-any (point-min) (point-max)
  2180. property value))
  2181. (delete-region
  2182. beg (or (next-single-property-change beg 'org-filtered)
  2183. (point-max))))))
  2184. (defun org-agenda-add-entry-text ()
  2185. "Add entry text to agenda lines.
  2186. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2187. entry text following headings shown in the agenda.
  2188. Drawers will be excluded, also the line with scheduling/deadline info."
  2189. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2190. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2191. (let (m txt)
  2192. (goto-char (point-min))
  2193. (while (not (eobp))
  2194. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2195. (beginning-of-line 2)
  2196. (setq txt (org-agenda-get-some-entry-text
  2197. m org-agenda-add-entry-text-maxlines " > "))
  2198. (end-of-line 1)
  2199. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2200. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2201. &rest keep)
  2202. "Extract entry text from MARKER, at most N-LINES lines.
  2203. This will ignore drawers etc, just get the text.
  2204. If INDENT is given, prefix every line with this string. If KEEP is
  2205. given, it is a list of symbols, defining stuff that should not be
  2206. removed from the entry content. Currently only `planning' is allowed here."
  2207. (let (txt drawer-re kwd-time-re ind)
  2208. (save-excursion
  2209. (with-current-buffer (marker-buffer marker)
  2210. (if (not (org-mode-p))
  2211. (setq txt "")
  2212. (save-excursion
  2213. (save-restriction
  2214. (widen)
  2215. (goto-char marker)
  2216. (end-of-line 1)
  2217. (setq txt (buffer-substring
  2218. (min (1+ (point)) (point-max))
  2219. (progn (outline-next-heading) (point)))
  2220. drawer-re org-drawer-regexp
  2221. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2222. ".*\n?"))
  2223. (with-temp-buffer
  2224. (insert txt)
  2225. (when org-agenda-add-entry-text-descriptive-links
  2226. (goto-char (point-min))
  2227. (while (org-activate-bracket-links (point-max))
  2228. (add-text-properties (match-beginning 0) (match-end 0)
  2229. '(face org-link))))
  2230. (goto-char (point-min))
  2231. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2232. (set-text-properties (match-beginning 0) (match-end 0)
  2233. nil))
  2234. (goto-char (point-min))
  2235. (while (re-search-forward drawer-re nil t)
  2236. (delete-region
  2237. (match-beginning 0)
  2238. (progn (re-search-forward
  2239. "^[ \t]*:END:.*\n?" nil 'move)
  2240. (point))))
  2241. (unless (member 'planning keep)
  2242. (goto-char (point-min))
  2243. (while (re-search-forward kwd-time-re nil t)
  2244. (replace-match "")))
  2245. (goto-char (point-min))
  2246. (when org-agenda-entry-text-exclude-regexps
  2247. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2248. (while (setq re (pop re-list))
  2249. (goto-char (point-min))
  2250. (while (re-search-forward re nil t)
  2251. (replace-match "")))))
  2252. (goto-char (point-max))
  2253. (skip-chars-backward " \t\n")
  2254. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2255. ;; find and remove min common indentation
  2256. (goto-char (point-min))
  2257. (untabify (point-min) (point-max))
  2258. (setq ind (org-get-indentation))
  2259. (while (not (eobp))
  2260. (unless (looking-at "[ \t]*$")
  2261. (setq ind (min ind (org-get-indentation))))
  2262. (beginning-of-line 2))
  2263. (goto-char (point-min))
  2264. (while (not (eobp))
  2265. (unless (looking-at "[ \t]*$")
  2266. (move-to-column ind)
  2267. (delete-region (point-at-bol) (point)))
  2268. (beginning-of-line 2))
  2269. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2270. (goto-char (point-min))
  2271. (when indent
  2272. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2273. (replace-match indent t t)))
  2274. (goto-char (point-min))
  2275. (while (looking-at "[ \t]*\n") (replace-match ""))
  2276. (goto-char (point-max))
  2277. (when (> (org-current-line)
  2278. n-lines)
  2279. (org-goto-line (1+ n-lines))
  2280. (backward-char 1))
  2281. (setq txt (buffer-substring (point-min) (point)))))))))
  2282. txt))
  2283. (defun org-agenda-collect-markers ()
  2284. "Collect the markers pointing to entries in the agenda buffer."
  2285. (let (m markers)
  2286. (save-excursion
  2287. (goto-char (point-min))
  2288. (while (not (eobp))
  2289. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2290. (org-get-at-bol 'org-marker)))
  2291. (push m markers))
  2292. (beginning-of-line 2)))
  2293. (nreverse markers)))
  2294. (defun org-create-marker-find-array (marker-list)
  2295. "Create a alist of files names with all marker positions in that file."
  2296. (let (f tbl m a p)
  2297. (while (setq m (pop marker-list))
  2298. (setq p (marker-position m)
  2299. f (buffer-file-name (or (buffer-base-buffer
  2300. (marker-buffer m))
  2301. (marker-buffer m))))
  2302. (if (setq a (assoc f tbl))
  2303. (push (marker-position m) (cdr a))
  2304. (push (list f p) tbl)))
  2305. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2306. tbl)))
  2307. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2308. (defun org-check-agenda-marker-table ()
  2309. "Check of the current entry is on the marker list."
  2310. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2311. a)
  2312. (and (setq a (assoc file org-agenda-marker-table))
  2313. (save-match-data
  2314. (save-excursion
  2315. (org-back-to-heading t)
  2316. (member (point) (cdr a)))))))
  2317. (defun org-check-for-org-mode ()
  2318. "Make sure current buffer is in org-mode. Error if not."
  2319. (or (org-mode-p)
  2320. (error "Cannot execute org-mode agenda command on buffer in %s"
  2321. major-mode)))
  2322. (defun org-fit-agenda-window ()
  2323. "Fit the window to the buffer size."
  2324. (and (memq org-agenda-window-setup '(reorganize-frame))
  2325. (fboundp 'fit-window-to-buffer)
  2326. (org-fit-window-to-buffer
  2327. nil
  2328. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2329. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2330. ;;; Agenda prepare and finalize
  2331. (defvar org-agenda-multi nil) ; dynamically scoped
  2332. (defvar org-agenda-buffer-name "*Org Agenda*")
  2333. (defvar org-pre-agenda-window-conf nil)
  2334. (defvar org-agenda-columns-active nil)
  2335. (defvar org-agenda-name nil)
  2336. (defvar org-agenda-filter nil)
  2337. (defvar org-agenda-filter-preset nil
  2338. "A preset of the tags filter used for secondary agenda filtering.
  2339. This must be a list of strings, each string must be a single tag preceeded
  2340. by \"+\" or \"-\".
  2341. This variable should not be set directly, but agenda custom commands can
  2342. bind it in the options section.")
  2343. (defun org-prepare-agenda (&optional name)
  2344. (setq org-todo-keywords-for-agenda nil)
  2345. (setq org-done-keywords-for-agenda nil)
  2346. (setq org-drawers-for-agenda nil)
  2347. (setq org-agenda-filter nil)
  2348. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2349. (if org-agenda-multi
  2350. (progn
  2351. (setq buffer-read-only nil)
  2352. (goto-char (point-max))
  2353. (unless (or (bobp) org-agenda-compact-blocks)
  2354. (insert "\n"
  2355. (if (stringp org-agenda-block-separator)
  2356. org-agenda-block-separator
  2357. (make-string (window-width) org-agenda-block-separator))
  2358. "\n"))
  2359. (narrow-to-region (point) (point-max)))
  2360. (org-agenda-reset-markers)
  2361. (setq org-agenda-contributing-files nil)
  2362. (setq org-agenda-columns-active nil)
  2363. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2364. (setq org-todo-keywords-for-agenda
  2365. (org-uniquify org-todo-keywords-for-agenda))
  2366. (setq org-done-keywords-for-agenda
  2367. (org-uniquify org-done-keywords-for-agenda))
  2368. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2369. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2370. (awin (get-buffer-window abuf)))
  2371. (cond
  2372. ((equal (current-buffer) abuf) nil)
  2373. (awin (select-window awin))
  2374. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2375. ((equal org-agenda-window-setup 'current-window)
  2376. (switch-to-buffer abuf))
  2377. ((equal org-agenda-window-setup 'other-window)
  2378. (org-switch-to-buffer-other-window abuf))
  2379. ((equal org-agenda-window-setup 'other-frame)
  2380. (switch-to-buffer-other-frame abuf))
  2381. ((equal org-agenda-window-setup 'reorganize-frame)
  2382. (delete-other-windows)
  2383. (org-switch-to-buffer-other-window abuf))))
  2384. (setq buffer-read-only nil)
  2385. (let ((inhibit-read-only t)) (erase-buffer))
  2386. (org-agenda-mode)
  2387. (and name (not org-agenda-name)
  2388. (org-set-local 'org-agenda-name name)))
  2389. (setq buffer-read-only nil))
  2390. (defun org-finalize-agenda ()
  2391. "Finishing touch for the agenda buffer, called just before displaying it."
  2392. (unless org-agenda-multi
  2393. (save-excursion
  2394. (let ((inhibit-read-only t))
  2395. (goto-char (point-min))
  2396. (while (org-activate-bracket-links (point-max))
  2397. (add-text-properties (match-beginning 0) (match-end 0)
  2398. '(face org-link)))
  2399. (org-agenda-align-tags)
  2400. (unless org-agenda-with-colors
  2401. (remove-text-properties (point-min) (point-max) '(face nil))))
  2402. (if (and (boundp 'org-agenda-overriding-columns-format)
  2403. org-agenda-overriding-columns-format)
  2404. (org-set-local 'org-agenda-overriding-columns-format
  2405. org-agenda-overriding-columns-format))
  2406. (if (and (boundp 'org-agenda-view-columns-initially)
  2407. org-agenda-view-columns-initially)
  2408. (org-agenda-columns))
  2409. (when org-agenda-fontify-priorities
  2410. (org-agenda-fontify-priorities))
  2411. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2412. (org-agenda-dim-blocked-tasks))
  2413. (org-agenda-mark-clocking-task)
  2414. (when org-agenda-entry-text-mode
  2415. (org-agenda-entry-text-hide)
  2416. (org-agenda-entry-text-show))
  2417. (if (functionp 'org-habit-insert-consistency-graphs)
  2418. (org-habit-insert-consistency-graphs))
  2419. (run-hooks 'org-finalize-agenda-hook)
  2420. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2421. (when (get 'org-agenda-filter :preset-filter)
  2422. (org-agenda-filter-apply org-agenda-filter))
  2423. )))
  2424. (defun org-agenda-mark-clocking-task ()
  2425. "Mark the current clock entry in the agenda if it is present."
  2426. (mapc (lambda (o)
  2427. (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
  2428. (org-delete-overlay o)))
  2429. (org-overlays-in (point-min) (point-max)))
  2430. (when (marker-buffer org-clock-hd-marker)
  2431. (save-excursion
  2432. (goto-char (point-min))
  2433. (let (s ov)
  2434. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2435. (goto-char s)
  2436. (when (equal (org-get-at-bol 'org-hd-marker)
  2437. org-clock-hd-marker)
  2438. (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
  2439. (org-overlay-put ov 'type 'org-agenda-clocking)
  2440. (org-overlay-put ov 'face 'org-agenda-clocking)
  2441. (org-overlay-put ov 'help-echo
  2442. "The clock is running in this item")))))))
  2443. (defun org-agenda-fontify-priorities ()
  2444. "Make highest priority lines bold, and lowest italic."
  2445. (interactive)
  2446. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
  2447. (org-delete-overlay o)))
  2448. (org-overlays-in (point-min) (point-max)))
  2449. (save-excursion
  2450. (let ((inhibit-read-only t)
  2451. b e p ov h l)
  2452. (goto-char (point-min))
  2453. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2454. (setq h (or (get-char-property (point) 'org-highest-priority)
  2455. org-highest-priority)
  2456. l (or (get-char-property (point) 'org-lowest-priority)
  2457. org-lowest-priority)
  2458. p (string-to-char (match-string 1))
  2459. b (match-beginning 0)
  2460. e (if (eq org-agenda-fontify-priorities 'cookies)
  2461. (match-end 0)
  2462. (point-at-eol))
  2463. ov (org-make-overlay b e))
  2464. (org-overlay-put
  2465. ov 'face
  2466. (cond ((cdr (assoc p org-priority-faces)))
  2467. ((and (listp org-agenda-fontify-priorities)
  2468. (cdr (assoc p org-agenda-fontify-priorities))))
  2469. ((equal p l) 'italic)
  2470. ((equal p h) 'bold)))
  2471. (org-overlay-put ov 'org-type 'org-priority)))))
  2472. (defun org-agenda-dim-blocked-tasks ()
  2473. "Dim currently blocked TODO's in the agenda display."
  2474. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
  2475. (org-delete-overlay o)))
  2476. (org-overlays-in (point-min) (point-max)))
  2477. (save-excursion
  2478. (let ((inhibit-read-only t)
  2479. (org-depend-tag-blocked nil)
  2480. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2481. org-blocked-by-checkboxes
  2482. invis1 b e p ov h l)
  2483. (goto-char (point-min))
  2484. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2485. (and pos (goto-char (1+ pos))))
  2486. (setq org-blocked-by-checkboxes nil invis1 invis)
  2487. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2488. (when (and marker
  2489. (not (with-current-buffer (marker-buffer marker)
  2490. (save-excursion
  2491. (goto-char marker)
  2492. (if (org-entry-get nil "NOBLOCKING")
  2493. t ;; Never block this entry
  2494. (run-hook-with-args-until-failure
  2495. 'org-blocker-hook
  2496. (list :type 'todo-state-change
  2497. :position marker
  2498. :from 'todo
  2499. :to 'done)))))))
  2500. (if org-blocked-by-checkboxes (setq invis1 nil))
  2501. (setq b (if invis1
  2502. (max (point-min) (1- (point-at-bol)))
  2503. (point-at-bol))
  2504. e (point-at-eol)
  2505. ov (org-make-overlay b e))
  2506. (if invis1
  2507. (org-overlay-put ov 'invisible t)
  2508. (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2509. (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
  2510. (defvar org-agenda-skip-function nil
  2511. "Function to be called at each match during agenda construction.
  2512. If this function returns nil, the current match should not be skipped.
  2513. Otherwise, the function must return a position from where the search
  2514. should be continued.
  2515. This may also be a Lisp form, it will be evaluated.
  2516. Never set this variable using `setq' or so, because then it will apply
  2517. to all future agenda commands. Instead, bind it with `let' to scope
  2518. it dynamically into the agenda-constructing command. A good way to set
  2519. it is through options in org-agenda-custom-commands.")
  2520. (defun org-agenda-skip ()
  2521. "Throw to `:skip' in places that should be skipped.
  2522. Also moves point to the end of the skipped region, so that search can
  2523. continue from there."
  2524. (let ((p (point-at-bol)) to fp)
  2525. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2526. (get-text-property p :org-archived)
  2527. (org-end-of-subtree t)
  2528. (throw :skip t))
  2529. (and org-agenda-skip-comment-trees
  2530. (get-text-property p :org-comment)
  2531. (org-end-of-subtree t)
  2532. (throw :skip t))
  2533. (if (equal (char-after p) ?#) (throw :skip t))
  2534. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2535. (consp org-agenda-skip-function))
  2536. (setq to (save-excursion
  2537. (save-match-data
  2538. (if fp
  2539. (funcall org-agenda-skip-function)
  2540. (eval org-agenda-skip-function))))))
  2541. (goto-char to)
  2542. (throw :skip t))))
  2543. (defvar org-agenda-markers nil
  2544. "List of all currently active markers created by `org-agenda'.")
  2545. (defvar org-agenda-last-marker-time (org-float-time)
  2546. "Creation time of the last agenda marker.")
  2547. (defun org-agenda-new-marker (&optional pos)
  2548. "Return a new agenda marker.
  2549. Org-mode keeps a list of these markers and resets them when they are
  2550. no longer in use."
  2551. (let ((m (copy-marker (or pos (point)))))
  2552. (setq org-agenda-last-marker-time (org-float-time))
  2553. (push m org-agenda-markers)
  2554. m))
  2555. (defun org-agenda-reset-markers ()
  2556. "Reset markers created by `org-agenda'."
  2557. (while org-agenda-markers
  2558. (move-marker (pop org-agenda-markers) nil)))
  2559. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2560. "Save relative positions of markers in region."
  2561. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2562. org-agenda-markers))
  2563. ;;; Entry text mode
  2564. (defun org-agenda-entry-text-show-here ()
  2565. "Add some text from the entry as context to the current line."
  2566. (let (m txt o)
  2567. (setq m (org-get-at-bol 'org-hd-marker))
  2568. (unless (marker-buffer m)
  2569. (error "No marker points to an entry here"))
  2570. (setq txt (concat "\n" (org-no-properties
  2571. (org-agenda-get-some-entry-text
  2572. m org-agenda-entry-text-maxlines " > "))))
  2573. (when (string-match "\\S-" txt)
  2574. (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
  2575. (org-overlay-put o 'evaporate t)
  2576. (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
  2577. (org-overlay-put o 'after-string txt))))
  2578. (defun org-agenda-entry-text-show ()
  2579. "Add entry context for all agenda lines."
  2580. (interactive)
  2581. (save-excursion
  2582. (goto-char (point-max))
  2583. (beginning-of-line 1)
  2584. (while (not (bobp))
  2585. (when (org-get-at-bol 'org-hd-marker)
  2586. (org-agenda-entry-text-show-here))
  2587. (beginning-of-line 0))))
  2588. (defun org-agenda-entry-text-hide ()
  2589. "Remove any shown entry context."
  2590. (delq nil
  2591. (mapcar (lambda (o)
  2592. (if (eq (org-overlay-get o 'org-overlay-type)
  2593. 'agenda-entry-content)
  2594. (progn (org-delete-overlay o) t)))
  2595. (org-overlays-in (point-min) (point-max)))))
  2596. ;;; Agenda timeline
  2597. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2598. (defun org-timeline (&optional include-all)
  2599. "Show a time-sorted view of the entries in the current org file.
  2600. Only entries with a time stamp of today or later will be listed. With
  2601. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2602. under the current date.
  2603. If the buffer contains an active region, only check the region for
  2604. dates."
  2605. (interactive "P")
  2606. (require 'calendar)
  2607. (org-compile-prefix-format 'timeline)
  2608. (org-set-sorting-strategy 'timeline)
  2609. (let* ((dopast t)
  2610. (dotodo include-all)
  2611. (doclosed org-agenda-show-log)
  2612. (entry buffer-file-name)
  2613. (date (calendar-current-date))
  2614. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2615. (end (if (org-region-active-p) (region-end) (point-max)))
  2616. (day-numbers (org-get-all-dates beg end 'no-ranges
  2617. t doclosed ; always include today
  2618. org-timeline-show-empty-dates))
  2619. (org-deadline-warning-days 0)
  2620. (org-agenda-only-exact-dates t)
  2621. (today (time-to-days (current-time)))
  2622. (past t)
  2623. args
  2624. s e rtn d emptyp wd)
  2625. (setq org-agenda-redo-command
  2626. (list 'progn
  2627. (list 'org-switch-to-buffer-other-window (current-buffer))
  2628. (list 'org-timeline (list 'quote include-all))))
  2629. (if (not dopast)
  2630. ;; Remove past dates from the list of dates.
  2631. (setq day-numbers (delq nil (mapcar (lambda(x)
  2632. (if (>= x today) x nil))
  2633. day-numbers))))
  2634. (org-prepare-agenda (concat "Timeline "
  2635. (file-name-nondirectory buffer-file-name)))
  2636. (if doclosed (push :closed args))
  2637. (push :timestamp args)
  2638. (push :deadline args)
  2639. (push :scheduled args)
  2640. (push :sexp args)
  2641. (if dotodo (push :todo args))
  2642. (insert "Timeline of file " entry "\n")
  2643. (add-text-properties (point-min) (point)
  2644. (list 'face 'org-agenda-structure))
  2645. (org-agenda-mark-header-line (point-min))
  2646. (while (setq d (pop day-numbers))
  2647. (if (and (listp d) (eq (car d) :omitted))
  2648. (progn
  2649. (setq s (point))
  2650. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2651. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2652. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2653. (if (and (>= d today)
  2654. dopast
  2655. past)
  2656. (progn
  2657. (setq past nil)
  2658. (insert (make-string 79 ?-) "\n")))
  2659. (setq date (calendar-gregorian-from-absolute d)
  2660. wd (calendar-day-of-week date))
  2661. (setq s (point))
  2662. (setq rtn (and (not emptyp)
  2663. (apply 'org-agenda-get-day-entries entry
  2664. date args)))
  2665. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2666. (progn
  2667. (insert
  2668. (if (stringp org-agenda-format-date)
  2669. (format-time-string org-agenda-format-date
  2670. (org-time-from-absolute date))
  2671. (funcall org-agenda-format-date date))
  2672. "\n")
  2673. (put-text-property s (1- (point)) 'face
  2674. (if (member wd org-agenda-weekend-days)
  2675. 'org-agenda-date-weekend
  2676. 'org-agenda-date))
  2677. (put-text-property s (1- (point)) 'org-date-line t)
  2678. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2679. (if (equal d today)
  2680. (put-text-property s (1- (point)) 'org-today t))
  2681. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2682. (put-text-property s (1- (point)) 'day d)))))
  2683. (goto-char (point-min))
  2684. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2685. (point-min)))
  2686. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2687. (org-finalize-agenda)
  2688. (setq buffer-read-only t)))
  2689. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2690. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2691. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2692. not every single day in the range. If FORCE-TODAY is non-nil, make
  2693. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2694. inactive time stamps (those in square brackets) are included.
  2695. When EMPTY is non-nil, also include days without any entries."
  2696. (let ((re (concat
  2697. (if pre-re pre-re "")
  2698. (if inactive org-ts-regexp-both org-ts-regexp)))
  2699. dates dates1 date day day1 day2 ts1 ts2)
  2700. (if force-today
  2701. (setq dates (list (time-to-days (current-time)))))
  2702. (save-excursion
  2703. (goto-char beg)
  2704. (while (re-search-forward re end t)
  2705. (setq day (time-to-days (org-time-string-to-time
  2706. (substring (match-string 1) 0 10))))
  2707. (or (memq day dates) (push day dates)))
  2708. (unless no-ranges
  2709. (goto-char beg)
  2710. (while (re-search-forward org-tr-regexp end t)
  2711. (setq ts1 (substring (match-string 1) 0 10)
  2712. ts2 (substring (match-string 2) 0 10)
  2713. day1 (time-to-days (org-time-string-to-time ts1))
  2714. day2 (time-to-days (org-time-string-to-time ts2)))
  2715. (while (< (setq day1 (1+ day1)) day2)
  2716. (or (memq day1 dates) (push day1 dates)))))
  2717. (setq dates (sort dates '<))
  2718. (when empty
  2719. (while (setq day (pop dates))
  2720. (setq day2 (car dates))
  2721. (push day dates1)
  2722. (when (and day2 empty)
  2723. (if (or (eq empty t)
  2724. (and (numberp empty) (<= (- day2 day) empty)))
  2725. (while (< (setq day (1+ day)) day2)
  2726. (push (list day) dates1))
  2727. (push (cons :omitted (- day2 day)) dates1))))
  2728. (setq dates (nreverse dates1)))
  2729. dates)))
  2730. ;;; Agenda Daily/Weekly
  2731. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2732. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2733. "Custom commands can set this variable in the options section.")
  2734. (defvar org-agenda-last-arguments nil
  2735. "The arguments of the previous call to org-agenda")
  2736. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2737. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2738. (defvar org-include-all-loc nil) ; local variable
  2739. (defvar org-agenda-remove-date nil) ; dynamically scoped FIXME: not used???
  2740. ;;;###autoload
  2741. (defun org-agenda-list (&optional include-all start-day ndays)
  2742. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2743. The view will be for the current day or week, but from the overview buffer
  2744. you will be able to go to other days/weeks.
  2745. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2746. all unfinished TODO items will also be shown, before the agenda.
  2747. This feature is considered obsolete, please use the TODO list or a block
  2748. agenda instead.
  2749. With a numeric prefix argument in an interactive call, the agenda will
  2750. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2751. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2752. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2753. given in `org-agenda-start-on-weekday'."
  2754. (interactive "P")
  2755. (if (and (integerp include-all) (> include-all 0))
  2756. (setq ndays include-all include-all nil))
  2757. (setq ndays (or ndays org-agenda-ndays)
  2758. start-day (or start-day org-agenda-start-day))
  2759. (if org-agenda-overriding-arguments
  2760. (setq include-all (car org-agenda-overriding-arguments)
  2761. start-day (nth 1 org-agenda-overriding-arguments)
  2762. ndays (nth 2 org-agenda-overriding-arguments)))
  2763. (if (stringp start-day)
  2764. ;; Convert to an absolute day number
  2765. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2766. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2767. (org-compile-prefix-format 'agenda)
  2768. (org-set-sorting-strategy 'agenda)
  2769. (require 'calendar)
  2770. (let* ((org-agenda-start-on-weekday
  2771. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2772. org-agenda-start-on-weekday nil))
  2773. (thefiles (org-agenda-files nil 'ifmode))
  2774. (files thefiles)
  2775. (today (time-to-days
  2776. (time-subtract (current-time)
  2777. (list 0 (* 3600 org-extend-today-until) 0))))
  2778. (sd (or start-day today))
  2779. (start (if (or (null org-agenda-start-on-weekday)
  2780. (< org-agenda-ndays 7))
  2781. sd
  2782. (let* ((nt (calendar-day-of-week
  2783. (calendar-gregorian-from-absolute sd)))
  2784. (n1 org-agenda-start-on-weekday)
  2785. (d (- nt n1)))
  2786. (- sd (+ (if (< d 0) 7 0) d)))))
  2787. (day-numbers (list start))
  2788. (day-cnt 0)
  2789. (inhibit-redisplay (not debug-on-error))
  2790. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  2791. clocktable-start clocktable-end)
  2792. (setq org-agenda-redo-command
  2793. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  2794. ;; Make the list of days
  2795. (setq ndays (or ndays org-agenda-ndays)
  2796. nd ndays)
  2797. (while (> ndays 1)
  2798. (push (1+ (car day-numbers)) day-numbers)
  2799. (setq ndays (1- ndays)))
  2800. (setq day-numbers (nreverse day-numbers))
  2801. (setq clocktable-start (car day-numbers)
  2802. clocktable-end (1+ (or (org-last day-numbers) 0)))
  2803. (org-prepare-agenda "Day/Week")
  2804. (org-set-local 'org-starting-day (car day-numbers))
  2805. (org-set-local 'org-include-all-loc include-all)
  2806. (org-set-local 'org-agenda-span
  2807. (org-agenda-ndays-to-span nd))
  2808. (when (and (or include-all org-agenda-include-all-todo)
  2809. (member today day-numbers))
  2810. (setq files thefiles
  2811. rtnall nil)
  2812. (while (setq file (pop files))
  2813. (catch 'nextfile
  2814. (org-check-agenda-file file)
  2815. (setq date (calendar-gregorian-from-absolute today)
  2816. rtn (org-agenda-get-day-entries
  2817. file date :todo))
  2818. (setq rtnall (append rtnall rtn))))
  2819. (when rtnall
  2820. (insert "All currently open TODO items:\n")
  2821. (add-text-properties (point-min) (1- (point))
  2822. (list 'face 'org-agenda-structure
  2823. 'short-heading "All TODO items"))
  2824. (org-agenda-mark-header-line (point-min))
  2825. (insert (org-finalize-agenda-entries rtnall) "\n")))
  2826. (unless org-agenda-compact-blocks
  2827. (let* ((d1 (car day-numbers))
  2828. (d2 (org-last day-numbers))
  2829. (w1 (org-days-to-iso-week d1))
  2830. (w2 (org-days-to-iso-week d2)))
  2831. (setq s (point))
  2832. (if org-agenda-overriding-header
  2833. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2834. nil 'face 'org-agenda-structure) "\n")
  2835. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  2836. "-agenda"
  2837. (if (< (- d2 d1) 350)
  2838. (if (= w1 w2)
  2839. (format " (W%02d)" w1)
  2840. (format " (W%02d-W%02d)" w1 w2))
  2841. "")
  2842. ":\n")))
  2843. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  2844. 'org-date-line t))
  2845. (org-agenda-mark-header-line s))
  2846. (while (setq d (pop day-numbers))
  2847. (setq date (calendar-gregorian-from-absolute d)
  2848. wd (calendar-day-of-week date)
  2849. s (point))
  2850. (if (or (setq todayp (= d today))
  2851. (and (not start-pos) (= d sd)))
  2852. (setq start-pos (point))
  2853. (if (and start-pos (not end-pos))
  2854. (setq end-pos (point))))
  2855. (setq files thefiles
  2856. rtnall nil)
  2857. (while (setq file (pop files))
  2858. (catch 'nextfile
  2859. (org-check-agenda-file file)
  2860. (cond
  2861. ((eq org-agenda-show-log 'only)
  2862. (setq rtn (org-agenda-get-day-entries
  2863. file date :closed)))
  2864. (org-agenda-show-log
  2865. (setq rtn (org-agenda-get-day-entries
  2866. file date
  2867. :deadline :scheduled :timestamp :sexp :closed)))
  2868. (t
  2869. (setq rtn (org-agenda-get-day-entries
  2870. file date
  2871. :deadline :scheduled :sexp :timestamp))))
  2872. (setq rtnall (append rtnall rtn))))
  2873. (if org-agenda-include-diary
  2874. (let ((org-agenda-search-headline-for-time t))
  2875. (require 'diary-lib)
  2876. (setq rtn (org-get-entries-from-diary date))
  2877. (setq rtnall (append rtnall rtn))))
  2878. (if (or rtnall org-agenda-show-all-dates)
  2879. (progn
  2880. (setq day-cnt (1+ day-cnt))
  2881. (insert
  2882. (if (stringp org-agenda-format-date)
  2883. (format-time-string org-agenda-format-date
  2884. (org-time-from-absolute date))
  2885. (funcall org-agenda-format-date date))
  2886. "\n")
  2887. (put-text-property s (1- (point)) 'face
  2888. (if (member wd org-agenda-weekend-days)
  2889. 'org-agenda-date-weekend
  2890. 'org-agenda-date))
  2891. (put-text-property s (1- (point)) 'org-date-line t)
  2892. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2893. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  2894. (when todayp
  2895. (put-text-property s (1- (point)) 'org-today t)
  2896. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  2897. (if rtnall (insert
  2898. (org-finalize-agenda-entries
  2899. (org-agenda-add-time-grid-maybe
  2900. rtnall nd todayp))
  2901. "\n"))
  2902. (put-text-property s (1- (point)) 'day d)
  2903. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  2904. (when (and org-agenda-clockreport-mode clocktable-start)
  2905. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  2906. ;; the above line is to ensure the restricted range!
  2907. (p org-agenda-clockreport-parameter-plist)
  2908. tbl)
  2909. (setq p (org-plist-delete p :block))
  2910. (setq p (plist-put p :tstart clocktable-start))
  2911. (setq p (plist-put p :tend clocktable-end))
  2912. (setq p (plist-put p :scope 'agenda))
  2913. (setq tbl (apply 'org-get-clocktable p))
  2914. (insert tbl)))
  2915. (goto-char (point-min))
  2916. (or org-agenda-multi (org-fit-agenda-window))
  2917. (unless (and (pos-visible-in-window-p (point-min))
  2918. (pos-visible-in-window-p (point-max)))
  2919. (goto-char (1- (point-max)))
  2920. (recenter -1)
  2921. (if (not (pos-visible-in-window-p (or start-pos 1)))
  2922. (progn
  2923. (goto-char (or start-pos 1))
  2924. (recenter 1))))
  2925. (goto-char (or start-pos 1))
  2926. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  2927. (org-finalize-agenda)
  2928. (setq buffer-read-only t)
  2929. (message "")))
  2930. (defun org-agenda-ndays-to-span (n)
  2931. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  2932. ;;; Agenda word search
  2933. (defvar org-agenda-search-history nil)
  2934. (defvar org-todo-only nil)
  2935. (defvar org-search-syntax-table nil
  2936. "Special syntax table for org-mode search.
  2937. In this table, we have single quotes not as word constituents, to
  2938. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  2939. (defun org-search-syntax-table ()
  2940. (unless org-search-syntax-table
  2941. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  2942. (modify-syntax-entry ?' "." org-search-syntax-table)
  2943. (modify-syntax-entry ?` "." org-search-syntax-table))
  2944. org-search-syntax-table)
  2945. ;;;###autoload
  2946. (defun org-search-view (&optional todo-only string edit-at)
  2947. "Show all entries that contain words or regular expressions.
  2948. If the first character of the search string is an asterisks,
  2949. search only the headlines.
  2950. With optional prefix argument TODO-ONLY, only consider entries that are
  2951. TODO entries. The argument STRING can be used to pass a default search
  2952. string into this function. If EDIT-AT is non-nil, it means that the
  2953. user should get a chance to edit this string, with cursor at position
  2954. EDIT-AT.
  2955. The search string is broken into \"words\" by splitting at whitespace.
  2956. Depending on the variable `org-agenda-search-view-search-words-only'
  2957. and on whether the first character in the search string is \"+\" or \"-\",
  2958. The string is then interpreted either as a substring with variable amounts
  2959. of whitespace, or as a list or individual words that should be matched.
  2960. The default is a substring match, where each space in the search string
  2961. can expand to an arbitrary amount of whitespace, including newlines.
  2962. If matching individual words, these words are then interpreted as a
  2963. boolean expression with logical AND. Words prefixed with a minus must
  2964. not occur in the entry. Words without a prefix or prefixed with a plus
  2965. must occur in the entry. Matching is case-insensitive and the words
  2966. are enclosed by word delimiters.
  2967. Words enclosed by curly braces are interpreted as regular expressions
  2968. that must or must not match in the entry.
  2969. If the search string starts with an asterisk, search only in headlines.
  2970. If (possibly after the leading star) the search string starts with an
  2971. exclamation mark, this also means to look at TODO entries only, an effect
  2972. that can also be achieved with a prefix argument.
  2973. This command searches the agenda files, and in addition the files listed
  2974. in `org-agenda-text-search-extra-files'."
  2975. (interactive "P")
  2976. (org-compile-prefix-format 'search)
  2977. (org-set-sorting-strategy 'search)
  2978. (org-prepare-agenda "SEARCH")
  2979. (let* ((props (list 'face nil
  2980. 'done-face 'org-agenda-done
  2981. 'org-not-done-regexp org-not-done-regexp
  2982. 'org-todo-regexp org-todo-regexp
  2983. 'org-complex-heading-regexp org-complex-heading-regexp
  2984. 'mouse-face 'highlight
  2985. 'help-echo (format "mouse-2 or RET jump to location")))
  2986. regexp rtn rtnall files file pos
  2987. marker category tags c neg re as-words
  2988. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  2989. (unless (and (not edit-at)
  2990. (stringp string)
  2991. (string-match "\\S-" string))
  2992. (setq string (read-string "[+-]Word/{Regexp} ...: "
  2993. (cond
  2994. ((integerp edit-at) (cons string edit-at))
  2995. (edit-at string))
  2996. 'org-agenda-search-history)))
  2997. (org-set-local 'org-todo-only todo-only)
  2998. (setq org-agenda-redo-command
  2999. (list 'org-search-view (if todo-only t nil) string
  3000. '(if current-prefix-arg 1 nil)))
  3001. (setq org-agenda-query-string string)
  3002. (if (equal (string-to-char string) ?*)
  3003. (setq hdl-only t
  3004. words (substring string 1))
  3005. (setq words string))
  3006. (when (equal (string-to-char words) ?!)
  3007. (setq todo-only t
  3008. words (substring words 1)))
  3009. (if (or org-agenda-search-view-search-words-only
  3010. (member (string-to-char string) '(?- ?+)))
  3011. (setq as-words t))
  3012. (setq words (org-split-string words))
  3013. (if as-words
  3014. (mapc (lambda (w)
  3015. (setq c (string-to-char w))
  3016. (if (equal c ?-)
  3017. (setq neg t w (substring w 1))
  3018. (if (equal c ?+)
  3019. (setq neg nil w (substring w 1))
  3020. (setq neg nil)))
  3021. (if (string-match "\\`{.*}\\'" w)
  3022. (setq re (substring w 1 -1))
  3023. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>")))
  3024. (if neg (push re regexps-) (push re regexps+)))
  3025. words)
  3026. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3027. regexps+))
  3028. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3029. (if (not regexps+)
  3030. (setq regexp (concat "^" org-outline-regexp))
  3031. (setq regexp (pop regexps+))
  3032. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3033. regexp))))
  3034. (setq files (org-agenda-files nil 'ifmode))
  3035. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3036. (pop org-agenda-text-search-extra-files)
  3037. (setq files (org-add-archive-files files)))
  3038. (setq files (append files org-agenda-text-search-extra-files)
  3039. rtnall nil)
  3040. (while (setq file (pop files))
  3041. (setq ee nil)
  3042. (catch 'nextfile
  3043. (org-check-agenda-file file)
  3044. (setq buffer (if (file-exists-p file)
  3045. (org-get-agenda-file-buffer file)
  3046. (error "No such file %s" file)))
  3047. (if (not buffer)
  3048. ;; If file does not exist, make sure an error message is sent
  3049. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3050. file))))
  3051. (with-current-buffer buffer
  3052. (with-syntax-table (org-search-syntax-table)
  3053. (unless (org-mode-p)
  3054. (error "Agenda file %s is not in `org-mode'" file))
  3055. (let ((case-fold-search t))
  3056. (save-excursion
  3057. (save-restriction
  3058. (if org-agenda-restrict
  3059. (narrow-to-region org-agenda-restrict-begin
  3060. org-agenda-restrict-end)
  3061. (widen))
  3062. (goto-char (point-min))
  3063. (unless (or (org-on-heading-p)
  3064. (outline-next-heading))
  3065. (throw 'nextfile t))
  3066. (goto-char (max (point-min) (1- (point))))
  3067. (while (re-search-forward regexp nil t)
  3068. (org-back-to-heading t)
  3069. (skip-chars-forward "* ")
  3070. (setq beg (point-at-bol)
  3071. beg1 (point)
  3072. end (progn (outline-next-heading) (point)))
  3073. (catch :skip
  3074. (goto-char beg)
  3075. (org-agenda-skip)
  3076. (setq str (buffer-substring-no-properties
  3077. (point-at-bol)
  3078. (if hdl-only (point-at-eol) end)))
  3079. (mapc (lambda (wr) (when (string-match wr str)
  3080. (goto-char (1- end))
  3081. (throw :skip t)))
  3082. regexps-)
  3083. (mapc (lambda (wr) (unless (string-match wr str)
  3084. (goto-char (1- end))
  3085. (throw :skip t)))
  3086. (if todo-only
  3087. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3088. regexps+)
  3089. regexps+))
  3090. (goto-char beg)
  3091. (setq marker (org-agenda-new-marker (point))
  3092. category (org-get-category)
  3093. tags (org-get-tags-at (point))
  3094. txt (org-format-agenda-item
  3095. ""
  3096. (buffer-substring-no-properties
  3097. beg1 (point-at-eol))
  3098. category tags))
  3099. (org-add-props txt props
  3100. 'org-marker marker 'org-hd-marker marker
  3101. 'org-todo-regexp org-todo-regexp
  3102. 'org-complex-heading-regexp org-complex-heading-regexp
  3103. 'priority 1000 'org-category category
  3104. 'type "search")
  3105. (push txt ee)
  3106. (goto-char (1- end))))))))))
  3107. (setq rtn (nreverse ee))
  3108. (setq rtnall (append rtnall rtn)))
  3109. (if org-agenda-overriding-header
  3110. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3111. nil 'face 'org-agenda-structure) "\n")
  3112. (insert "Search words: ")
  3113. (add-text-properties (point-min) (1- (point))
  3114. (list 'face 'org-agenda-structure))
  3115. (setq pos (point))
  3116. (insert string "\n")
  3117. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3118. (setq pos (point))
  3119. (unless org-agenda-multi
  3120. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3121. (add-text-properties pos (1- (point))
  3122. (list 'face 'org-agenda-structure))))
  3123. (org-agenda-mark-header-line (point-min))
  3124. (when rtnall
  3125. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3126. (goto-char (point-min))
  3127. (or org-agenda-multi (org-fit-agenda-window))
  3128. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3129. (org-finalize-agenda)
  3130. (setq buffer-read-only t)))
  3131. ;;; Agenda TODO list
  3132. (defvar org-select-this-todo-keyword nil)
  3133. (defvar org-last-arg nil)
  3134. ;;;###autoload
  3135. (defun org-todo-list (arg)
  3136. "Show all TODO entries from all agenda file in a single list.
  3137. The prefix arg can be used to select a specific TODO keyword and limit
  3138. the list to these. When using \\[universal-argument], you will be prompted
  3139. for a keyword. A numeric prefix directly selects the Nth keyword in
  3140. `org-todo-keywords-1'."
  3141. (interactive "P")
  3142. (require 'calendar)
  3143. (org-compile-prefix-format 'todo)
  3144. (org-set-sorting-strategy 'todo)
  3145. (org-prepare-agenda "TODO")
  3146. (let* ((today (time-to-days (current-time)))
  3147. (date (calendar-gregorian-from-absolute today))
  3148. (kwds org-todo-keywords-for-agenda)
  3149. (completion-ignore-case t)
  3150. (org-select-this-todo-keyword
  3151. (if (stringp arg) arg
  3152. (and arg (integerp arg) (> arg 0)
  3153. (nth (1- arg) kwds))))
  3154. rtn rtnall files file pos)
  3155. (when (equal arg '(4))
  3156. (setq org-select-this-todo-keyword
  3157. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3158. (mapcar 'list kwds) nil nil)))
  3159. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3160. (org-set-local 'org-last-arg arg)
  3161. (setq org-agenda-redo-command
  3162. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3163. (setq files (org-agenda-files nil 'ifmode)
  3164. rtnall nil)
  3165. (while (setq file (pop files))
  3166. (catch 'nextfile
  3167. (org-check-agenda-file file)
  3168. (setq rtn (org-agenda-get-day-entries file date :todo))
  3169. (setq rtnall (append rtnall rtn))))
  3170. (if org-agenda-overriding-header
  3171. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3172. nil 'face 'org-agenda-structure) "\n")
  3173. (insert "Global list of TODO items of type: ")
  3174. (add-text-properties (point-min) (1- (point))
  3175. (list 'face 'org-agenda-structure
  3176. 'short-heading
  3177. (concat "ToDo: "
  3178. (or org-select-this-todo-keyword "ALL"))))
  3179. (org-agenda-mark-header-line (point-min))
  3180. (setq pos (point))
  3181. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3182. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3183. (setq pos (point))
  3184. (unless org-agenda-multi
  3185. (insert "Available with `N r': (0)ALL")
  3186. (let ((n 0) s)
  3187. (mapc (lambda (x)
  3188. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3189. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3190. (insert "\n "))
  3191. (insert " " s))
  3192. kwds))
  3193. (insert "\n"))
  3194. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3195. (org-agenda-mark-header-line (point-min))
  3196. (when rtnall
  3197. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3198. (goto-char (point-min))
  3199. (or org-agenda-multi (org-fit-agenda-window))
  3200. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3201. (org-finalize-agenda)
  3202. (setq buffer-read-only t)))
  3203. ;;; Agenda tags match
  3204. ;;;###autoload
  3205. (defun org-tags-view (&optional todo-only match)
  3206. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3207. The prefix arg TODO-ONLY limits the search to TODO entries."
  3208. (interactive "P")
  3209. (org-compile-prefix-format 'tags)
  3210. (org-set-sorting-strategy 'tags)
  3211. (let* ((org-tags-match-list-sublevels
  3212. ;?????? (if todo-only t org-tags-match-list-sublevels))
  3213. org-tags-match-list-sublevels)
  3214. (completion-ignore-case t)
  3215. rtn rtnall files file pos matcher
  3216. buffer)
  3217. (setq matcher (org-make-tags-matcher match)
  3218. match (car matcher) matcher (cdr matcher))
  3219. (org-prepare-agenda (concat "TAGS " match))
  3220. (setq org-agenda-query-string match)
  3221. (setq org-agenda-redo-command
  3222. (list 'org-tags-view (list 'quote todo-only)
  3223. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3224. (setq files (org-agenda-files nil 'ifmode)
  3225. rtnall nil)
  3226. (while (setq file (pop files))
  3227. (catch 'nextfile
  3228. (org-check-agenda-file file)
  3229. (setq buffer (if (file-exists-p file)
  3230. (org-get-agenda-file-buffer file)
  3231. (error "No such file %s" file)))
  3232. (if (not buffer)
  3233. ;; If file does not exist, error message to agenda
  3234. (setq rtn (list
  3235. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3236. rtnall (append rtnall rtn))
  3237. (with-current-buffer buffer
  3238. (unless (org-mode-p)
  3239. (error "Agenda file %s is not in `org-mode'" file))
  3240. (save-excursion
  3241. (save-restriction
  3242. (if org-agenda-restrict
  3243. (narrow-to-region org-agenda-restrict-begin
  3244. org-agenda-restrict-end)
  3245. (widen))
  3246. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3247. (setq rtnall (append rtnall rtn))))))))
  3248. (if org-agenda-overriding-header
  3249. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3250. nil 'face 'org-agenda-structure) "\n")
  3251. (insert "Headlines with TAGS match: ")
  3252. (add-text-properties (point-min) (1- (point))
  3253. (list 'face 'org-agenda-structure
  3254. 'short-heading
  3255. (concat "Match: " match)))
  3256. (setq pos (point))
  3257. (insert match "\n")
  3258. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3259. (setq pos (point))
  3260. (unless org-agenda-multi
  3261. (insert "Press `C-u r' to search again with new search string\n"))
  3262. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3263. (org-agenda-mark-header-line (point-min))
  3264. (when rtnall
  3265. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3266. (goto-char (point-min))
  3267. (or org-agenda-multi (org-fit-agenda-window))
  3268. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3269. (org-finalize-agenda)
  3270. (setq buffer-read-only t)))
  3271. ;;; Agenda Finding stuck projects
  3272. (defvar org-agenda-skip-regexp nil
  3273. "Regular expression used in skipping subtrees for the agenda.
  3274. This is basically a temporary global variable that can be set and then
  3275. used by user-defined selections using `org-agenda-skip-function'.")
  3276. (defvar org-agenda-overriding-header nil
  3277. "When this is set during todo and tags searches, will replace header.
  3278. This variable should not be set directly, but custom commands can bind it
  3279. in the options section.")
  3280. (defun org-agenda-skip-entry-when-regexp-matches ()
  3281. "Checks if the current entry contains match for `org-agenda-skip-regexp'.
  3282. If yes, it returns the end position of this entry, causing agenda commands
  3283. to skip the entry but continuing the search in the subtree. This is a
  3284. function that can be put into `org-agenda-skip-function' for the duration
  3285. of a command."
  3286. (let ((end (save-excursion (org-end-of-subtree t)))
  3287. skip)
  3288. (save-excursion
  3289. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3290. (and skip end)))
  3291. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3292. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3293. If yes, it returns the end position of this tree, causing agenda commands
  3294. to skip this subtree. This is a function that can be put into
  3295. `org-agenda-skip-function' for the duration of a command."
  3296. (let ((end (save-excursion (org-end-of-subtree t)))
  3297. skip)
  3298. (save-excursion
  3299. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3300. (and skip end)))
  3301. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3302. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3303. If yes, it returns the end position of the current entry (NOT the tree),
  3304. causing agenda commands to skip the entry but continuing the search in
  3305. the subtree. This is a function that can be put into
  3306. `org-agenda-skip-function' for the duration of a command. An important
  3307. use of this function is for the stuck project list."
  3308. (let ((end (save-excursion (org-end-of-subtree t)))
  3309. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3310. skip)
  3311. (save-excursion
  3312. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3313. (and skip entry-end)))
  3314. (defun org-agenda-skip-entry-if (&rest conditions)
  3315. "Skip entry if any of CONDITIONS is true.
  3316. See `org-agenda-skip-if' for details."
  3317. (org-agenda-skip-if nil conditions))
  3318. (defun org-agenda-skip-subtree-if (&rest conditions)
  3319. "Skip entry if any of CONDITIONS is true.
  3320. See `org-agenda-skip-if' for details."
  3321. (org-agenda-skip-if t conditions))
  3322. (defun org-agenda-skip-if (subtree conditions)
  3323. "Checks current entity for CONDITIONS.
  3324. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3325. the entry, i.e. the text before the next heading is checked.
  3326. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3327. from different tests. Valid conditions are:
  3328. scheduled Check if there is a scheduled cookie
  3329. notscheduled Check if there is no scheduled cookie
  3330. deadline Check if there is a deadline
  3331. notdeadline Check if there is no deadline
  3332. timestamp Check if there is a timestamp (also deadline or scheduled)
  3333. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3334. regexp Check if regexp matches
  3335. notregexp Check if regexp does not match.
  3336. The regexp is taken from the conditions list, it must come right after
  3337. the `regexp' or `notregexp' element.
  3338. If any of these conditions is met, this function returns the end point of
  3339. the entity, causing the search to continue from there. This is a function
  3340. that can be put into `org-agenda-skip-function' for the duration of a command."
  3341. (let (beg end m)
  3342. (org-back-to-heading t)
  3343. (setq beg (point)
  3344. end (if subtree
  3345. (progn (org-end-of-subtree t) (point))
  3346. (progn (outline-next-heading) (1- (point)))))
  3347. (goto-char beg)
  3348. (and
  3349. (or
  3350. (and (memq 'scheduled conditions)
  3351. (re-search-forward org-scheduled-time-regexp end t))
  3352. (and (memq 'notscheduled conditions)
  3353. (not (re-search-forward org-scheduled-time-regexp end t)))
  3354. (and (memq 'deadline conditions)
  3355. (re-search-forward org-deadline-time-regexp end t))
  3356. (and (memq 'notdeadline conditions)
  3357. (not (re-search-forward org-deadline-time-regexp end t)))
  3358. (and (memq 'timestamp conditions)
  3359. (re-search-forward org-ts-regexp end t))
  3360. (and (memq 'nottimestamp conditions)
  3361. (not (re-search-forward org-ts-regexp end t)))
  3362. (and (setq m (memq 'regexp conditions))
  3363. (stringp (nth 1 m))
  3364. (re-search-forward (nth 1 m) end t))
  3365. (and (setq m (memq 'notregexp conditions))
  3366. (stringp (nth 1 m))
  3367. (not (re-search-forward (nth 1 m) end t))))
  3368. end)))
  3369. ;;;###autoload
  3370. (defun org-agenda-list-stuck-projects (&rest ignore)
  3371. "Create agenda view for projects that are stuck.
  3372. Stuck projects are project that have no next actions. For the definitions
  3373. of what a project is and how to check if it stuck, customize the variable
  3374. `org-stuck-projects'.
  3375. MATCH is being ignored."
  3376. (interactive)
  3377. (let* ((org-agenda-skip-function
  3378. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3379. ;; We could have used org-agenda-skip-if here.
  3380. (org-agenda-overriding-header
  3381. (or org-agenda-overriding-header "List of stuck projects: "))
  3382. (matcher (nth 0 org-stuck-projects))
  3383. (todo (nth 1 org-stuck-projects))
  3384. (todo-wds (if (member "*" todo)
  3385. (progn
  3386. (org-prepare-agenda-buffers (org-agenda-files
  3387. nil 'ifmode))
  3388. (org-delete-all
  3389. org-done-keywords-for-agenda
  3390. (copy-sequence org-todo-keywords-for-agenda)))
  3391. todo))
  3392. (todo-re (concat "^\\*+[ \t]+\\("
  3393. (mapconcat 'identity todo-wds "\\|")
  3394. "\\)\\>"))
  3395. (tags (nth 2 org-stuck-projects))
  3396. (tags-re (if (member "*" tags)
  3397. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3398. (if tags
  3399. (concat "^\\*+ .*:\\("
  3400. (mapconcat 'identity tags "\\|")
  3401. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3402. (gen-re (nth 3 org-stuck-projects))
  3403. (re-list
  3404. (delq nil
  3405. (list
  3406. (if todo todo-re)
  3407. (if tags tags-re)
  3408. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3409. gen-re)))))
  3410. (setq org-agenda-skip-regexp
  3411. (if re-list
  3412. (mapconcat 'identity re-list "\\|")
  3413. (error "No information how to identify unstuck projects")))
  3414. (org-tags-view nil matcher)
  3415. (with-current-buffer org-agenda-buffer-name
  3416. (setq org-agenda-redo-command
  3417. '(org-agenda-list-stuck-projects
  3418. (or current-prefix-arg org-last-arg))))))
  3419. ;;; Diary integration
  3420. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3421. (defvar list-diary-entries-hook)
  3422. (defun org-get-entries-from-diary (date)
  3423. "Get the (Emacs Calendar) diary entries for DATE."
  3424. (require 'diary-lib)
  3425. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3426. (fancy-diary-buffer diary-fancy-buffer)
  3427. (diary-display-hook '(fancy-diary-display))
  3428. (diary-display-function 'fancy-diary-display)
  3429. (pop-up-frames nil)
  3430. (list-diary-entries-hook
  3431. (cons 'org-diary-default-entry list-diary-entries-hook))
  3432. (diary-file-name-prefix-function nil) ; turn this feature off
  3433. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3434. entries
  3435. (org-disable-agenda-to-diary t))
  3436. (save-excursion
  3437. (save-window-excursion
  3438. (funcall (if (fboundp 'diary-list-entries)
  3439. 'diary-list-entries 'list-diary-entries)
  3440. date 1)))
  3441. (if (not (get-buffer diary-fancy-buffer))
  3442. (setq entries nil)
  3443. (with-current-buffer diary-fancy-buffer
  3444. (setq buffer-read-only nil)
  3445. (if (zerop (buffer-size))
  3446. ;; No entries
  3447. (setq entries nil)
  3448. ;; Omit the date and other unnecessary stuff
  3449. (org-agenda-cleanup-fancy-diary)
  3450. ;; Add prefix to each line and extend the text properties
  3451. (if (zerop (buffer-size))
  3452. (setq entries nil)
  3453. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3454. (set-buffer-modified-p nil)
  3455. (kill-buffer diary-fancy-buffer)))
  3456. (when entries
  3457. (setq entries (org-split-string entries "\n"))
  3458. (setq entries
  3459. (mapcar
  3460. (lambda (x)
  3461. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3462. ;; Extend the text properties to the beginning of the line
  3463. (org-add-props x (text-properties-at (1- (length x)) x)
  3464. 'type "diary" 'date date))
  3465. entries)))))
  3466. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3467. "Hook run when the fancy diary buffer is cleaned up.")
  3468. (defun org-agenda-cleanup-fancy-diary ()
  3469. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3470. This gets rid of the date, the underline under the date, and
  3471. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3472. date. It also removes lines that contain only whitespace."
  3473. (goto-char (point-min))
  3474. (if (looking-at ".*?:[ \t]*")
  3475. (progn
  3476. (replace-match "")
  3477. (re-search-forward "\n=+$" nil t)
  3478. (replace-match "")
  3479. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3480. (re-search-forward "\n=+$" nil t)
  3481. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3482. (goto-char (point-min))
  3483. (while (re-search-forward "^ +\n" nil t)
  3484. (replace-match ""))
  3485. (goto-char (point-min))
  3486. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3487. (replace-match ""))
  3488. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3489. ;; Make sure entries from the diary have the right text properties.
  3490. (eval-after-load "diary-lib"
  3491. '(if (boundp 'diary-modify-entry-list-string-function)
  3492. ;; We can rely on the hook, nothing to do
  3493. nil
  3494. ;; Hook not available, must use advice to make this work
  3495. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3496. "Make the position visible."
  3497. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3498. (stringp string)
  3499. buffer-file-name)
  3500. (setq string (org-modify-diary-entry-string string))))))
  3501. (defun org-modify-diary-entry-string (string)
  3502. "Add text properties to string, allowing org-mode to act on it."
  3503. (org-add-props string nil
  3504. 'mouse-face 'highlight
  3505. 'help-echo (if buffer-file-name
  3506. (format "mouse-2 or RET jump to diary file %s"
  3507. (abbreviate-file-name buffer-file-name))
  3508. "")
  3509. 'org-agenda-diary-link t
  3510. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3511. (defun org-diary-default-entry ()
  3512. "Add a dummy entry to the diary.
  3513. Needed to avoid empty dates which mess up holiday display."
  3514. ;; Catch the error if dealing with the new add-to-diary-alist
  3515. (when org-disable-agenda-to-diary
  3516. (condition-case nil
  3517. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3518. (error
  3519. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3520. (defun org-add-to-diary-list (&rest args)
  3521. (if (fboundp 'diary-add-to-list)
  3522. (apply 'diary-add-to-list args)
  3523. (apply 'add-to-diary-list args)))
  3524. ;;;###autoload
  3525. (defun org-diary (&rest args)
  3526. "Return diary information from org-files.
  3527. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3528. It accesses org files and extracts information from those files to be
  3529. listed in the diary. The function accepts arguments specifying what
  3530. items should be listed. The following arguments are allowed:
  3531. :timestamp List the headlines of items containing a date stamp or
  3532. date range matching the selected date. Deadlines will
  3533. also be listed, on the expiration day.
  3534. :sexp List entries resulting from diary-like sexps.
  3535. :deadline List any deadlines past due, or due within
  3536. `org-deadline-warning-days'. The listing occurs only
  3537. in the diary for *today*, not at any other date. If
  3538. an entry is marked DONE, it is no longer listed.
  3539. :scheduled List all items which are scheduled for the given date.
  3540. The diary for *today* also contains items which were
  3541. scheduled earlier and are not yet marked DONE.
  3542. :todo List all TODO items from the org-file. This may be a
  3543. long list - so this is not turned on by default.
  3544. Like deadlines, these entries only show up in the
  3545. diary for *today*, not at any other date.
  3546. The call in the diary file should look like this:
  3547. &%%(org-diary) ~/path/to/some/orgfile.org
  3548. Use a separate line for each org file to check. Or, if you omit the file name,
  3549. all files listed in `org-agenda-files' will be checked automatically:
  3550. &%%(org-diary)
  3551. If you don't give any arguments (as in the example above), the default
  3552. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3553. So the example above may also be written as
  3554. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3555. The function expects the lisp variables `entry' and `date' to be provided
  3556. by the caller, because this is how the calendar works. Don't use this
  3557. function from a program - use `org-agenda-get-day-entries' instead."
  3558. (when (> (- (org-float-time)
  3559. org-agenda-last-marker-time)
  3560. 5)
  3561. (org-agenda-reset-markers))
  3562. (org-compile-prefix-format 'agenda)
  3563. (org-set-sorting-strategy 'agenda)
  3564. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3565. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3566. (list entry)
  3567. (org-agenda-files t)))
  3568. file rtn results)
  3569. (org-prepare-agenda-buffers files)
  3570. ;; If this is called during org-agenda, don't return any entries to
  3571. ;; the calendar. Org Agenda will list these entries itself.
  3572. (if org-disable-agenda-to-diary (setq files nil))
  3573. (while (setq file (pop files))
  3574. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3575. (setq results (append results rtn)))
  3576. (if results
  3577. (concat (org-finalize-agenda-entries results) "\n"))))
  3578. ;;; Agenda entry finders
  3579. (defun org-agenda-get-day-entries (file date &rest args)
  3580. "Does the work for `org-diary' and `org-agenda'.
  3581. FILE is the path to a file to be checked for entries. DATE is date like
  3582. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3583. which kind of entries should be extracted. For details about these, see
  3584. the documentation of `org-diary'."
  3585. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3586. (let* ((org-startup-folded nil)
  3587. (org-startup-align-all-tables nil)
  3588. (buffer (if (file-exists-p file)
  3589. (org-get-agenda-file-buffer file)
  3590. (error "No such file %s" file)))
  3591. arg results rtn deadline-results)
  3592. (if (not buffer)
  3593. ;; If file does not exist, make sure an error message ends up in diary
  3594. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3595. (with-current-buffer buffer
  3596. (unless (org-mode-p)
  3597. (error "Agenda file %s is not in `org-mode'" file))
  3598. (let ((case-fold-search nil))
  3599. (save-excursion
  3600. (save-restriction
  3601. (if org-agenda-restrict
  3602. (narrow-to-region org-agenda-restrict-begin
  3603. org-agenda-restrict-end)
  3604. (widen))
  3605. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3606. (while (setq arg (pop args))
  3607. (cond
  3608. ((and (eq arg :todo)
  3609. (equal date (calendar-current-date)))
  3610. (setq rtn (org-agenda-get-todos))
  3611. (setq results (append results rtn)))
  3612. ((eq arg :timestamp)
  3613. (setq rtn (org-agenda-get-blocks))
  3614. (setq results (append results rtn))
  3615. (setq rtn (org-agenda-get-timestamps))
  3616. (setq results (append results rtn)))
  3617. ((eq arg :sexp)
  3618. (setq rtn (org-agenda-get-sexps))
  3619. (setq results (append results rtn)))
  3620. ((eq arg :scheduled)
  3621. (setq rtn (org-agenda-get-scheduled deadline-results))
  3622. (setq results (append results rtn)))
  3623. ((eq arg :closed)
  3624. (setq rtn (org-agenda-get-progress))
  3625. (setq results (append results rtn)))
  3626. ((eq arg :deadline)
  3627. (setq rtn (org-agenda-get-deadlines))
  3628. (setq deadline-results (copy-sequence rtn))
  3629. (setq results (append results rtn))))))))
  3630. results))))
  3631. (defun org-agenda-get-todos ()
  3632. "Return the TODO information for agenda display."
  3633. (let* ((props (list 'face nil
  3634. 'done-face 'org-agenda-done
  3635. 'org-not-done-regexp org-not-done-regexp
  3636. 'org-todo-regexp org-todo-regexp
  3637. 'org-complex-heading-regexp org-complex-heading-regexp
  3638. 'mouse-face 'highlight
  3639. 'help-echo
  3640. (format "mouse-2 or RET jump to org file %s"
  3641. (abbreviate-file-name buffer-file-name))))
  3642. (regexp (concat "^\\*+[ \t]+\\("
  3643. (if org-select-this-todo-keyword
  3644. (if (equal org-select-this-todo-keyword "*")
  3645. org-todo-regexp
  3646. (concat "\\<\\("
  3647. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3648. "\\)\\>"))
  3649. org-not-done-regexp)
  3650. "[^\n\r]*\\)"))
  3651. marker priority category tags todo-state
  3652. ee txt beg end)
  3653. (goto-char (point-min))
  3654. (while (re-search-forward regexp nil t)
  3655. (catch :skip
  3656. (save-match-data
  3657. (beginning-of-line)
  3658. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3659. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3660. (goto-char (1+ beg))
  3661. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3662. (throw :skip nil)))
  3663. (goto-char beg)
  3664. (org-agenda-skip)
  3665. (goto-char (match-beginning 1))
  3666. (setq marker (org-agenda-new-marker (match-beginning 0))
  3667. category (org-get-category)
  3668. txt (match-string 1)
  3669. tags (org-get-tags-at (point))
  3670. txt (org-format-agenda-item "" txt category tags)
  3671. priority (1+ (org-get-priority txt))
  3672. todo-state (org-get-todo-state))
  3673. (org-add-props txt props
  3674. 'org-marker marker 'org-hd-marker marker
  3675. 'priority priority 'org-category category
  3676. 'type "todo" 'todo-state todo-state)
  3677. (push txt ee)
  3678. (if org-agenda-todo-list-sublevels
  3679. (goto-char (match-end 1))
  3680. (org-end-of-subtree 'invisible))))
  3681. (nreverse ee)))
  3682. ;;;###autoload
  3683. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
  3684. "Do we have a reason to ignore this todo entry because it has a time stamp?"
  3685. (when (or org-agenda-todo-ignore-with-date
  3686. org-agenda-todo-ignore-scheduled
  3687. org-agenda-todo-ignore-deadlines)
  3688. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3689. (save-excursion
  3690. (or (and org-agenda-todo-ignore-with-date
  3691. (re-search-forward org-ts-regexp end t))
  3692. (and org-agenda-todo-ignore-scheduled
  3693. (re-search-forward org-scheduled-time-regexp end t))
  3694. (and org-agenda-todo-ignore-deadlines
  3695. (re-search-forward org-deadline-time-regexp end t)
  3696. (org-deadline-close (match-string 1)))))))
  3697. (defconst org-agenda-no-heading-message
  3698. "No heading for this item in buffer or region.")
  3699. (defun org-agenda-get-timestamps ()
  3700. "Return the date stamp information for agenda display."
  3701. (let* ((props (list 'face nil
  3702. 'org-not-done-regexp org-not-done-regexp
  3703. 'org-todo-regexp org-todo-regexp
  3704. 'org-complex-heading-regexp org-complex-heading-regexp
  3705. 'mouse-face 'highlight
  3706. 'help-echo
  3707. (format "mouse-2 or RET jump to org file %s"
  3708. (abbreviate-file-name buffer-file-name))))
  3709. (d1 (calendar-absolute-from-gregorian date))
  3710. (remove-re
  3711. (concat
  3712. (regexp-quote
  3713. (format-time-string
  3714. "<%Y-%m-%d"
  3715. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  3716. ".*?>"))
  3717. (regexp
  3718. (concat
  3719. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  3720. (regexp-quote
  3721. (substring
  3722. (format-time-string
  3723. (car org-time-stamp-formats)
  3724. (apply 'encode-time ; DATE bound by calendar
  3725. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3726. 1 11))
  3727. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  3728. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  3729. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  3730. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  3731. todo-state end-of-match)
  3732. (goto-char (point-min))
  3733. (while (setq end-of-match (re-search-forward regexp nil t))
  3734. (setq b0 (match-beginning 0)
  3735. b3 (match-beginning 3) e3 (match-end 3))
  3736. (catch :skip
  3737. (and (org-at-date-range-p) (throw :skip nil))
  3738. (org-agenda-skip)
  3739. (if (and (match-end 1)
  3740. (not (= d1 (org-time-string-to-absolute
  3741. (match-string 1) d1 nil
  3742. org-agenda-repeating-timestamp-show-all))))
  3743. (throw :skip nil))
  3744. (if (and e3
  3745. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  3746. (throw :skip nil))
  3747. (setq tmp (buffer-substring (max (point-min)
  3748. (- b0 org-ds-keyword-length))
  3749. b0)
  3750. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  3751. inactivep (= (char-after b0) ?\[)
  3752. deadlinep (string-match org-deadline-regexp tmp)
  3753. scheduledp (string-match org-scheduled-regexp tmp)
  3754. closedp (and org-agenda-include-inactive-timestamps
  3755. (string-match org-closed-string tmp))
  3756. clockp (and org-agenda-include-inactive-timestamps
  3757. (or (string-match org-clock-string tmp)
  3758. (string-match "]-+\\'" tmp)))
  3759. todo-state (org-get-todo-state)
  3760. donep (member todo-state org-done-keywords))
  3761. (if (or scheduledp deadlinep closedp clockp
  3762. (and donep org-agenda-skip-timestamp-if-done))
  3763. (throw :skip t))
  3764. (if (string-match ">" timestr)
  3765. ;; substring should only run to end of time stamp
  3766. (setq timestr (substring timestr 0 (match-end 0))))
  3767. (setq marker (org-agenda-new-marker b0)
  3768. category (org-get-category b0))
  3769. (save-excursion
  3770. (if (not (re-search-backward "^\\*+ " nil t))
  3771. (setq txt org-agenda-no-heading-message)
  3772. (goto-char (match-beginning 0))
  3773. (setq hdmarker (org-agenda-new-marker)
  3774. tags (org-get-tags-at))
  3775. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3776. (setq head (match-string 1))
  3777. (setq txt (org-format-agenda-item
  3778. (if inactivep "[" nil)
  3779. head category tags timestr nil
  3780. remove-re)))
  3781. (setq priority (org-get-priority txt))
  3782. (org-add-props txt props
  3783. 'org-marker marker 'org-hd-marker hdmarker)
  3784. (org-add-props txt nil 'priority priority
  3785. 'org-category category 'date date
  3786. 'todo-state todo-state
  3787. 'type "timestamp")
  3788. (push txt ee))
  3789. (if org-agenda-skip-additional-timestamps-same-entry
  3790. (outline-next-heading)
  3791. (goto-char end-of-match))))
  3792. (nreverse ee)))
  3793. (defun org-agenda-get-sexps ()
  3794. "Return the sexp information for agenda display."
  3795. (require 'diary-lib)
  3796. (let* ((props (list 'face nil
  3797. 'mouse-face 'highlight
  3798. 'help-echo
  3799. (format "mouse-2 or RET jump to org file %s"
  3800. (abbreviate-file-name buffer-file-name))))
  3801. (regexp "^&?%%(")
  3802. marker category ee txt tags entry result beg b sexp sexp-entry
  3803. todo-state)
  3804. (goto-char (point-min))
  3805. (while (re-search-forward regexp nil t)
  3806. (catch :skip
  3807. (org-agenda-skip)
  3808. (setq beg (match-beginning 0))
  3809. (goto-char (1- (match-end 0)))
  3810. (setq b (point))
  3811. (forward-sexp 1)
  3812. (setq sexp (buffer-substring b (point)))
  3813. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  3814. (org-trim (match-string 1))
  3815. ""))
  3816. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  3817. (when result
  3818. (setq marker (org-agenda-new-marker beg)
  3819. category (org-get-category beg)
  3820. todo-state (org-get-todo-state))
  3821. (if (string-match "\\S-" result)
  3822. (setq txt result)
  3823. (setq txt "SEXP entry returned empty string"))
  3824. (setq txt (org-format-agenda-item
  3825. "" txt category tags 'time))
  3826. (org-add-props txt props 'org-marker marker)
  3827. (org-add-props txt nil
  3828. 'org-category category 'date date 'todo-state todo-state
  3829. 'type "sexp")
  3830. (push txt ee))))
  3831. (nreverse ee)))
  3832. (defalias 'org-get-closed 'org-agenda-get-progress)
  3833. (defun org-agenda-get-progress ()
  3834. "Return the logged TODO entries for agenda display."
  3835. (let* ((props (list 'mouse-face 'highlight
  3836. 'org-not-done-regexp org-not-done-regexp
  3837. 'org-todo-regexp org-todo-regexp
  3838. 'org-complex-heading-regexp org-complex-heading-regexp
  3839. 'help-echo
  3840. (format "mouse-2 or RET jump to org file %s"
  3841. (abbreviate-file-name buffer-file-name))))
  3842. (items (if (consp org-agenda-show-log)
  3843. org-agenda-show-log
  3844. org-agenda-log-mode-items))
  3845. (parts
  3846. (delq nil
  3847. (list
  3848. (if (memq 'closed items) (concat "\\<" org-closed-string))
  3849. (if (memq 'clock items) (concat "\\<" org-clock-string))
  3850. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  3851. (parts-re (if parts (mapconcat 'identity parts "\\|")
  3852. (error "`org-agenda-log-mode-items' is empty")))
  3853. (regexp (concat
  3854. "\\(" parts-re "\\)"
  3855. " *\\["
  3856. (regexp-quote
  3857. (substring
  3858. (format-time-string
  3859. (car org-time-stamp-formats)
  3860. (apply 'encode-time ; DATE bound by calendar
  3861. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3862. 1 11))))
  3863. (org-agenda-search-headline-for-time nil)
  3864. marker hdmarker priority category tags closedp statep clockp state
  3865. ee txt extra timestr rest clocked)
  3866. (goto-char (point-min))
  3867. (while (re-search-forward regexp nil t)
  3868. (catch :skip
  3869. (org-agenda-skip)
  3870. (setq marker (org-agenda-new-marker (match-beginning 0))
  3871. closedp (equal (match-string 1) org-closed-string)
  3872. statep (equal (string-to-char (match-string 1)) ?-)
  3873. clockp (not (or closedp statep))
  3874. state (and statep (match-string 2))
  3875. category (org-get-category (match-beginning 0))
  3876. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  3877. )
  3878. (when (string-match "\\]" timestr)
  3879. ;; substring should only run to end of time stamp
  3880. (setq rest (substring timestr (match-end 0))
  3881. timestr (substring timestr 0 (match-end 0)))
  3882. (if (and (not closedp) (not statep)
  3883. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  3884. (progn (setq timestr (concat (substring timestr 0 -1)
  3885. "-" (match-string 1 rest) "]"))
  3886. (setq clocked (match-string 2 rest)))
  3887. (setq clocked "-")))
  3888. (save-excursion
  3889. (cond
  3890. ((not org-agenda-log-mode-add-notes) (setq extra nil))
  3891. (statep
  3892. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  3893. (setq extra (match-string 1))))
  3894. (clockp
  3895. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  3896. (setq extra (match-string 1))))
  3897. (t (setq extra nil)))
  3898. (if (not (re-search-backward "^\\*+ " nil t))
  3899. (setq txt org-agenda-no-heading-message)
  3900. (goto-char (match-beginning 0))
  3901. (setq hdmarker (org-agenda-new-marker)
  3902. tags (org-get-tags-at))
  3903. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3904. (setq txt (match-string 1))
  3905. (when extra
  3906. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  3907. (setq txt (concat (substring txt 0 (match-beginning 1))
  3908. " - " extra " " (match-string 2 txt)))
  3909. (setq txt (concat txt " - " extra))))
  3910. (setq txt (org-format-agenda-item
  3911. (cond
  3912. (closedp "Closed: ")
  3913. (statep (concat "State: (" state ")"))
  3914. (t (concat "Clocked: (" clocked ")")))
  3915. txt category tags timestr)))
  3916. (setq priority 100000)
  3917. (org-add-props txt props
  3918. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  3919. 'priority priority 'org-category category
  3920. 'type "closed" 'date date
  3921. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  3922. (push txt ee))
  3923. (goto-char (point-at-eol))))
  3924. (nreverse ee)))
  3925. (defun org-agenda-get-deadlines ()
  3926. "Return the deadline information for agenda display."
  3927. (let* ((props (list 'mouse-face 'highlight
  3928. 'org-not-done-regexp org-not-done-regexp
  3929. 'org-todo-regexp org-todo-regexp
  3930. 'org-complex-heading-regexp org-complex-heading-regexp
  3931. 'help-echo
  3932. (format "mouse-2 or RET jump to org file %s"
  3933. (abbreviate-file-name buffer-file-name))))
  3934. (regexp org-deadline-time-regexp)
  3935. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  3936. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  3937. d2 diff dfrac wdays pos pos1 category tags
  3938. ee txt head face s todo-state upcomingp donep timestr)
  3939. (goto-char (point-min))
  3940. (while (re-search-forward regexp nil t)
  3941. (catch :skip
  3942. (org-agenda-skip)
  3943. (setq s (match-string 1)
  3944. txt nil
  3945. pos (1- (match-beginning 1))
  3946. d2 (org-time-string-to-absolute
  3947. (match-string 1) d1 'past
  3948. org-agenda-repeating-timestamp-show-all)
  3949. diff (- d2 d1)
  3950. wdays (org-get-wdays s)
  3951. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  3952. upcomingp (and todayp (> diff 0)))
  3953. ;; When to show a deadline in the calendar:
  3954. ;; If the expiration is within wdays warning time.
  3955. ;; Past-due deadlines are only shown on the current date
  3956. (if (and (or (and (<= diff wdays)
  3957. (and todayp (not org-agenda-only-exact-dates)))
  3958. (= diff 0)))
  3959. (save-excursion
  3960. (setq todo-state (org-get-todo-state))
  3961. (setq donep (member todo-state org-done-keywords))
  3962. (if (and donep
  3963. (or org-agenda-skip-deadline-if-done
  3964. (not (= diff 0))))
  3965. (setq txt nil)
  3966. (setq category (org-get-category))
  3967. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  3968. (setq txt org-agenda-no-heading-message)
  3969. (goto-char (match-end 0))
  3970. (setq pos1 (match-beginning 0))
  3971. (setq tags (org-get-tags-at pos1))
  3972. (setq head (buffer-substring-no-properties
  3973. (point)
  3974. (progn (skip-chars-forward "^\r\n")
  3975. (point))))
  3976. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  3977. (setq timestr
  3978. (concat (substring s (match-beginning 1)) " "))
  3979. (setq timestr 'time))
  3980. (setq txt (org-format-agenda-item
  3981. (if (= diff 0)
  3982. (car org-agenda-deadline-leaders)
  3983. (if (functionp
  3984. (nth 1 org-agenda-deadline-leaders))
  3985. (funcall
  3986. (nth 1 org-agenda-deadline-leaders)
  3987. diff date)
  3988. (format (nth 1 org-agenda-deadline-leaders)
  3989. diff)))
  3990. head category tags
  3991. (if (not (= diff 0)) nil timestr)))))
  3992. (when txt
  3993. (setq face (org-agenda-deadline-face dfrac wdays))
  3994. (org-add-props txt props
  3995. 'org-marker (org-agenda-new-marker pos)
  3996. 'org-hd-marker (org-agenda-new-marker pos1)
  3997. 'priority (+ (- diff)
  3998. (org-get-priority txt))
  3999. 'org-category category
  4000. 'todo-state todo-state
  4001. 'type (if upcomingp "upcoming-deadline" "deadline")
  4002. 'date (if upcomingp date d2)
  4003. 'face (if donep 'org-agenda-done face)
  4004. 'undone-face face 'done-face 'org-agenda-done)
  4005. (push txt ee))))))
  4006. (nreverse ee)))
  4007. (defun org-agenda-deadline-face (fraction &optional wdays)
  4008. "Return the face to displaying a deadline item.
  4009. FRACTION is what fraction of the head-warning time has passed."
  4010. (if (equal wdays 0) (setq fraction 1.))
  4011. (let ((faces org-agenda-deadline-faces) f)
  4012. (catch 'exit
  4013. (while (setq f (pop faces))
  4014. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4015. (defun org-agenda-get-scheduled (&optional deadline-results)
  4016. "Return the scheduled information for agenda display."
  4017. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4018. 'org-todo-regexp org-todo-regexp
  4019. 'org-complex-heading-regexp org-complex-heading-regexp
  4020. 'done-face 'org-agenda-done
  4021. 'mouse-face 'highlight
  4022. 'help-echo
  4023. (format "mouse-2 or RET jump to org file %s"
  4024. (abbreviate-file-name buffer-file-name))))
  4025. (regexp org-scheduled-time-regexp)
  4026. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4027. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4028. mm
  4029. (deadline-position-alist
  4030. (mapcar (lambda (a) (and (setq mm (get-text-property
  4031. 0 'org-hd-marker a))
  4032. (cons (marker-position mm) a)))
  4033. deadline-results))
  4034. d2 diff pos pos1 category tags donep
  4035. ee txt head pastschedp todo-state face timestr s habitp)
  4036. (goto-char (point-min))
  4037. (while (re-search-forward regexp nil t)
  4038. (catch :skip
  4039. (org-agenda-skip)
  4040. (setq s (match-string 1)
  4041. txt nil
  4042. pos (1- (match-beginning 1))
  4043. d2 (org-time-string-to-absolute
  4044. (match-string 1) d1 'past
  4045. org-agenda-repeating-timestamp-show-all)
  4046. diff (- d2 d1))
  4047. (setq pastschedp (and todayp (< diff 0)))
  4048. ;; When to show a scheduled item in the calendar:
  4049. ;; If it is on or past the date.
  4050. (when (or (and (< diff 0)
  4051. (< (abs diff) org-scheduled-past-days)
  4052. (and todayp (not org-agenda-only-exact-dates)))
  4053. (= diff 0))
  4054. (save-excursion
  4055. (setq todo-state (org-get-todo-state))
  4056. (setq donep (member todo-state org-done-keywords))
  4057. (setq habitp (and (functionp 'org-is-habit-p)
  4058. (org-is-habit-p)))
  4059. (if (and donep
  4060. (or habitp org-agenda-skip-scheduled-if-done
  4061. (not (= diff 0))))
  4062. (setq txt nil)
  4063. (setq category (org-get-category))
  4064. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4065. (setq txt org-agenda-no-heading-message)
  4066. (goto-char (match-end 0))
  4067. (setq pos1 (match-beginning 0))
  4068. (if habitp
  4069. (if (or (not org-habit-show-habits)
  4070. (and (not todayp)
  4071. org-habit-show-habits-only-for-today))
  4072. (throw :skip nil))
  4073. (if (and
  4074. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4075. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4076. pastschedp))
  4077. (setq mm (assoc pos1 deadline-position-alist)))
  4078. (throw :skip nil)))
  4079. (setq tags (org-get-tags-at))
  4080. (setq head (buffer-substring-no-properties
  4081. (point)
  4082. (progn (skip-chars-forward "^\r\n") (point))))
  4083. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4084. (setq timestr
  4085. (concat (substring s (match-beginning 1)) " "))
  4086. (setq timestr 'time))
  4087. (setq txt (org-format-agenda-item
  4088. (if (= diff 0)
  4089. (car org-agenda-scheduled-leaders)
  4090. (format (nth 1 org-agenda-scheduled-leaders)
  4091. (- 1 diff)))
  4092. head category tags
  4093. (if (not (= diff 0)) nil timestr)
  4094. nil nil habitp))))
  4095. (when txt
  4096. (setq face
  4097. (cond
  4098. ((and (not habitp) pastschedp)
  4099. 'org-scheduled-previously)
  4100. (todayp 'org-scheduled-today)
  4101. (t 'org-scheduled))
  4102. habitp (and habitp (org-habit-parse-todo)))
  4103. (org-add-props txt props
  4104. 'undone-face face
  4105. 'face (if donep 'org-agenda-done face)
  4106. 'org-marker (org-agenda-new-marker pos)
  4107. 'org-hd-marker (org-agenda-new-marker pos1)
  4108. 'type (if pastschedp "past-scheduled" "scheduled")
  4109. 'date (if pastschedp d2 date)
  4110. 'priority (if habitp
  4111. (org-habit-get-priority habitp)
  4112. (+ 94 (- 5 diff) (org-get-priority txt)))
  4113. 'org-category category
  4114. 'org-habit-p habitp
  4115. 'todo-state todo-state)
  4116. (push txt ee))))))
  4117. (nreverse ee)))
  4118. (defun org-agenda-get-blocks ()
  4119. "Return the date-range information for agenda display."
  4120. (let* ((props (list 'face nil
  4121. 'org-not-done-regexp org-not-done-regexp
  4122. 'org-todo-regexp org-todo-regexp
  4123. 'org-complex-heading-regexp org-complex-heading-regexp
  4124. 'mouse-face 'highlight
  4125. 'help-echo
  4126. (format "mouse-2 or RET jump to org file %s"
  4127. (abbreviate-file-name buffer-file-name))))
  4128. (regexp org-tr-regexp)
  4129. (d0 (calendar-absolute-from-gregorian date))
  4130. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4131. head donep)
  4132. (goto-char (point-min))
  4133. (while (re-search-forward regexp nil t)
  4134. (catch :skip
  4135. (org-agenda-skip)
  4136. (setq pos (point))
  4137. (setq timestr (match-string 0)
  4138. s1 (match-string 1)
  4139. s2 (match-string 2)
  4140. d1 (time-to-days (org-time-string-to-time s1))
  4141. d2 (time-to-days (org-time-string-to-time s2)))
  4142. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4143. ;; Only allow days between the limits, because the normal
  4144. ;; date stamps will catch the limits.
  4145. (save-excursion
  4146. (setq todo-state (org-get-todo-state))
  4147. (setq donep (member todo-state org-done-keywords))
  4148. (if (and donep org-agenda-skip-timestamp-if-done)
  4149. (throw :skip t))
  4150. (setq marker (org-agenda-new-marker (point)))
  4151. (setq category (org-get-category))
  4152. (if (not (re-search-backward "^\\*+ " nil t))
  4153. (setq txt org-agenda-no-heading-message)
  4154. (goto-char (match-beginning 0))
  4155. (setq hdmarker (org-agenda-new-marker (point)))
  4156. (setq tags (org-get-tags-at))
  4157. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4158. (setq head (match-string 1))
  4159. (setq txt (org-format-agenda-item
  4160. (format
  4161. (nth (if (= d1 d2) 0 1)
  4162. org-agenda-timerange-leaders)
  4163. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4164. head category tags
  4165. (if (= d0 d1) timestr))))
  4166. (org-add-props txt props
  4167. 'org-marker marker 'org-hd-marker hdmarker
  4168. 'type "block" 'date date
  4169. 'todo-state todo-state
  4170. 'priority (org-get-priority txt) 'org-category category)
  4171. (push txt ee)))
  4172. (goto-char pos)))
  4173. ;; Sort the entries by expiration date.
  4174. (nreverse ee)))
  4175. ;;; Agenda presentation and sorting
  4176. (defvar org-prefix-has-time nil
  4177. "A flag, set by `org-compile-prefix-format'.
  4178. The flag is set if the currently compiled format contains a `%t'.")
  4179. (defvar org-prefix-has-tag nil
  4180. "A flag, set by `org-compile-prefix-format'.
  4181. The flag is set if the currently compiled format contains a `%T'.")
  4182. (defvar org-prefix-has-effort nil
  4183. "A flag, set by `org-compile-prefix-format'.
  4184. The flag is set if the currently compiled format contains a `%e'.")
  4185. (defvar org-prefix-category-length nil
  4186. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4187. (defvar org-prefix-category-max-length nil
  4188. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4189. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4190. noprefix remove-re habitp)
  4191. "Format TXT to be inserted into the agenda buffer.
  4192. In particular, it adds the prefix and corresponding text properties. EXTRA
  4193. must be a string and replaces the `%s' specifier in the prefix format.
  4194. CATEGORY (string, symbol or nil) may be used to overrule the default
  4195. category taken from local variable or file name. It will replace the `%c'
  4196. specifier in the format. DOTIME, when non-nil, indicates that a
  4197. time-of-day should be extracted from TXT for sorting of this entry, and for
  4198. the `%t' specifier in the format. When DOTIME is a string, this string is
  4199. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4200. only the correctly processes TXT should be returned - this is used by
  4201. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4202. Any match of REMOVE-RE will be removed from TXT."
  4203. (save-match-data
  4204. ;; Diary entries sometimes have extra whitespace at the beginning
  4205. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4206. (when org-agenda-show-inherited-tags
  4207. ;; Fix the tags part in txt
  4208. (setq txt (org-agenda-add-inherited-tags txt tags)))
  4209. (let* ((category (or category
  4210. org-category
  4211. (if buffer-file-name
  4212. (file-name-sans-extension
  4213. (file-name-nondirectory buffer-file-name))
  4214. "")))
  4215. ;; time, tag, effort are needed for the eval of the prefix format
  4216. (tag (if tags (nth (1- (length tags)) tags) ""))
  4217. time effort neffort
  4218. (ts (if dotime (concat
  4219. (if (stringp dotime) dotime "")
  4220. (and org-agenda-search-headline-for-time txt))))
  4221. (time-of-day (and dotime (org-get-time-of-day ts)))
  4222. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4223. duration thecategory)
  4224. (and (org-mode-p) buffer-file-name
  4225. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4226. (when (and dotime time-of-day)
  4227. ;; Extract starting and ending time and move them to prefix
  4228. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4229. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4230. (setq s0 (match-string 0 ts)
  4231. srp (and stamp (match-end 3))
  4232. s1 (match-string (if plain 1 2) ts)
  4233. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4234. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4235. ;; them, we might want to remove them there to avoid duplication.
  4236. ;; The user can turn this off with a variable.
  4237. (if (and org-prefix-has-time
  4238. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4239. (string-match (concat (regexp-quote s0) " *") txt)
  4240. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4241. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4242. (= (match-beginning 0) 0)
  4243. t))
  4244. (setq txt (replace-match "" nil nil txt))))
  4245. ;; Normalize the time(s) to 24 hour
  4246. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4247. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4248. ;; Compute the duration
  4249. (when s1
  4250. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4251. (string-to-number (substring s1 3)))
  4252. t2 (cond
  4253. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4254. (string-to-number (substring s2 3))))
  4255. (org-agenda-default-appointment-duration
  4256. (+ t1 org-agenda-default-appointment-duration))
  4257. (t nil)))
  4258. (setq duration (if t2 (- t2 t1)))))
  4259. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4260. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4261. (let ((m (+ (string-to-number (match-string 2 s1))
  4262. (* 60 (string-to-number (match-string 1 s1)))
  4263. org-agenda-default-appointment-duration))
  4264. h)
  4265. (setq h (/ m 60) m (- m (* h 60)))
  4266. (setq s2 (format "%02d:%02d" h m))))
  4267. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4268. txt)
  4269. ;; Tags are in the string
  4270. (if (or (eq org-agenda-remove-tags t)
  4271. (and org-agenda-remove-tags
  4272. org-prefix-has-tag))
  4273. (setq txt (replace-match "" t t txt))
  4274. (setq txt (replace-match
  4275. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4276. (match-string 2 txt))
  4277. t t txt))))
  4278. (when (org-mode-p)
  4279. (setq effort
  4280. (condition-case nil
  4281. (org-get-effort
  4282. (or (get-text-property 0 'org-hd-marker txt)
  4283. (get-text-property 0 'org-marker txt)))
  4284. (error nil)))
  4285. (when effort
  4286. (setq neffort (org-hh:mm-string-to-minutes effort)
  4287. effort (setq effort (concat "[" effort "]" )))))
  4288. (when remove-re
  4289. (while (string-match remove-re txt)
  4290. (setq txt (replace-match "" t t txt))))
  4291. ;; Create the final string
  4292. (if noprefix
  4293. (setq rtn txt)
  4294. ;; Prepare the variables needed in the eval of the compiled format
  4295. (setq time (cond (s2 (concat s1 "-" s2))
  4296. (s1 (concat s1 "......"))
  4297. (t ""))
  4298. extra (or (and (not habitp) extra) "")
  4299. category (if (symbolp category) (symbol-name category) category)
  4300. thecategory (copy-sequence category))
  4301. (if (string-match org-bracket-link-regexp category)
  4302. (progn
  4303. (setq l (if (match-end 3)
  4304. (- (match-end 3) (match-beginning 3))
  4305. (- (match-end 1) (match-beginning 1))))
  4306. (when (< l (or org-prefix-category-length 0))
  4307. (setq category (copy-sequence category))
  4308. (org-add-props category nil
  4309. 'extra-space (make-string
  4310. (- org-prefix-category-length l 1) ?\ ))))
  4311. (if (and org-prefix-category-max-length
  4312. (>= (length category) org-prefix-category-max-length))
  4313. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4314. ;; Evaluate the compiled format
  4315. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4316. ;; And finally add the text properties
  4317. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4318. (org-add-props rtn nil
  4319. 'org-category (if thecategory (downcase thecategory) category)
  4320. 'tags (mapcar 'org-downcase-keep-props tags)
  4321. 'org-highest-priority org-highest-priority
  4322. 'org-lowest-priority org-lowest-priority
  4323. 'prefix-length (- (length rtn) (length txt))
  4324. 'time-of-day time-of-day
  4325. 'duration duration
  4326. 'effort effort
  4327. 'effort-minutes neffort
  4328. 'txt txt
  4329. 'time time
  4330. 'extra extra
  4331. 'dotime dotime))))
  4332. (defun org-agenda-add-inherited-tags (txt tags)
  4333. "Remove tags string from TXT, and add complete list of tags.
  4334. The new list includes inherited tags. If any inherited tags are present,
  4335. a double colon separates inherited tags from local tags."
  4336. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4337. (setq txt (substring txt 0 (match-beginning 0))))
  4338. (when tags
  4339. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4340. i)
  4341. (setq txt (concat txt " :"
  4342. (mapconcat
  4343. (lambda (x)
  4344. (setq i (get-text-property 0 'inherited x))
  4345. (if (and have-i (not i))
  4346. (progn
  4347. (setq have-i nil)
  4348. (concat ":" x))
  4349. x))
  4350. tags ":")
  4351. (if have-i "::" ":")))))
  4352. txt)
  4353. (defun org-downcase-keep-props (s)
  4354. (let ((props (text-properties-at 0 s)))
  4355. (setq s (downcase s))
  4356. (add-text-properties 0 (length s) props s)
  4357. s))
  4358. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4359. (defvar org-agenda-sorting-strategy-selected nil)
  4360. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4361. (catch 'exit
  4362. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4363. ((and todayp (member 'today (car org-agenda-time-grid))))
  4364. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4365. ((member 'weekly (car org-agenda-time-grid)))
  4366. (t (throw 'exit list)))
  4367. (let* ((have (delq nil (mapcar
  4368. (lambda (x) (get-text-property 1 'time-of-day x))
  4369. list)))
  4370. (string (nth 1 org-agenda-time-grid))
  4371. (gridtimes (nth 2 org-agenda-time-grid))
  4372. (req (car org-agenda-time-grid))
  4373. (remove (member 'remove-match req))
  4374. new time)
  4375. (if (and (member 'require-timed req) (not have))
  4376. ;; don't show empty grid
  4377. (throw 'exit list))
  4378. (while (setq time (pop gridtimes))
  4379. (unless (and remove (member time have))
  4380. (setq time (int-to-string time))
  4381. (push (org-format-agenda-item
  4382. nil string "" nil
  4383. (concat (substring time 0 -2) ":" (substring time -2)))
  4384. new)
  4385. (put-text-property
  4386. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4387. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4388. (append new list)
  4389. (append list new)))))
  4390. (defun org-compile-prefix-format (key)
  4391. "Compile the prefix format into a Lisp form that can be evaluated.
  4392. The resulting form is returned and stored in the variable
  4393. `org-prefix-format-compiled'."
  4394. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4395. org-prefix-category-length nil org-prefix-has-effort nil)
  4396. (let ((s (cond
  4397. ((stringp org-agenda-prefix-format)
  4398. org-agenda-prefix-format)
  4399. ((assq key org-agenda-prefix-format)
  4400. (cdr (assq key org-agenda-prefix-format)))
  4401. (t " %-12:c%?-12t% s")))
  4402. (start 0)
  4403. varform vars var e c f opt)
  4404. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4405. s start)
  4406. (setq var (cdr (assoc (match-string 4 s)
  4407. '(("c" . category) ("t" . time) ("s" . extra)
  4408. ("T" . tag) ("e" . effort))))
  4409. c (or (match-string 3 s) "")
  4410. opt (match-beginning 1)
  4411. start (1+ (match-beginning 0)))
  4412. (if (equal var 'time) (setq org-prefix-has-time t))
  4413. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4414. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4415. (setq f (concat "%" (match-string 2 s) "s"))
  4416. (when (equal var 'category)
  4417. (setq org-prefix-category-length
  4418. (floor (abs (string-to-number (match-string 2 s)))))
  4419. (setq org-prefix-category-max-length
  4420. (let ((x (match-string 2 s)))
  4421. (save-match-data
  4422. (if (string-match "\\.[0-9]+" x)
  4423. (string-to-number (substring (match-string 0 x) 1)))))))
  4424. (if opt
  4425. (setq varform
  4426. `(if (equal "" ,var)
  4427. ""
  4428. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4429. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4430. (setq s (replace-match "%s" t nil s))
  4431. (push varform vars))
  4432. (setq vars (nreverse vars))
  4433. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4434. (defun org-set-sorting-strategy (key)
  4435. (if (symbolp (car org-agenda-sorting-strategy))
  4436. ;; the old format
  4437. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4438. (setq org-agenda-sorting-strategy-selected
  4439. (or (cdr (assq key org-agenda-sorting-strategy))
  4440. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4441. '(time-up category-keep priority-down)))))
  4442. (defun org-get-time-of-day (s &optional string mod24)
  4443. "Check string S for a time of day.
  4444. If found, return it as a military time number between 0 and 2400.
  4445. If not found, return nil.
  4446. The optional STRING argument forces conversion into a 5 character wide string
  4447. HH:MM."
  4448. (save-match-data
  4449. (when
  4450. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4451. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4452. (let* ((h (string-to-number (match-string 1 s)))
  4453. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4454. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4455. (am-p (equal ampm "am"))
  4456. (h1 (cond ((not ampm) h)
  4457. ((= h 12) (if am-p 0 12))
  4458. (t (+ h (if am-p 0 12)))))
  4459. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4460. (mod h1 24) h1))
  4461. (t0 (+ (* 100 h2) m))
  4462. (t1 (concat (if (>= h1 24) "+" " ")
  4463. (if (< t0 100) "0" "")
  4464. (if (< t0 10) "0" "")
  4465. (int-to-string t0))))
  4466. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4467. (defun org-finalize-agenda-entries (list &optional nosort)
  4468. "Sort and concatenate the agenda items."
  4469. (setq list (mapcar 'org-agenda-highlight-todo list))
  4470. (if nosort
  4471. list
  4472. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4473. (defun org-agenda-highlight-todo (x)
  4474. (let ((org-done-keywords org-done-keywords-for-agenda)
  4475. re pl)
  4476. (if (eq x 'line)
  4477. (save-excursion
  4478. (beginning-of-line 1)
  4479. (setq re (org-get-at-bol 'org-todo-regexp))
  4480. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4481. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4482. (add-text-properties (match-beginning 0) (match-end 1)
  4483. (list 'face (org-get-todo-face 1)))
  4484. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4485. (delete-region (match-beginning 1) (1- (match-end 0)))
  4486. (goto-char (match-beginning 1))
  4487. (insert (format org-agenda-todo-keyword-format s)))))
  4488. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4489. pl (get-text-property 0 'prefix-length x))
  4490. (when (and re
  4491. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4492. x (or pl 0)) pl))
  4493. (add-text-properties
  4494. (or (match-end 1) (match-end 0)) (match-end 0)
  4495. (list 'face (org-get-todo-face (match-string 2 x)))
  4496. x)
  4497. (setq x (concat (substring x 0 (match-end 1))
  4498. (format org-agenda-todo-keyword-format
  4499. (match-string 2 x))
  4500. (org-add-props " " (text-properties-at 0 x))
  4501. (substring x (match-end 3)))))
  4502. x)))
  4503. (defsubst org-cmp-priority (a b)
  4504. "Compare the priorities of string A and B."
  4505. (let ((pa (or (get-text-property 1 'priority a) 0))
  4506. (pb (or (get-text-property 1 'priority b) 0)))
  4507. (cond ((> pa pb) +1)
  4508. ((< pa pb) -1)
  4509. (t nil))))
  4510. (defsubst org-cmp-effort (a b)
  4511. "Compare the priorities of string A and B."
  4512. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4513. (ea (or (get-text-property 1 'effort-minutes a) def))
  4514. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4515. (cond ((> ea eb) +1)
  4516. ((< ea eb) -1)
  4517. (t nil))))
  4518. (defsubst org-cmp-category (a b)
  4519. "Compare the string values of categories of strings A and B."
  4520. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4521. (cb (or (get-text-property 1 'org-category b) "")))
  4522. (cond ((string-lessp ca cb) -1)
  4523. ((string-lessp cb ca) +1)
  4524. (t nil))))
  4525. (defsubst org-cmp-todo-state (a b)
  4526. "Compare the todo states of strings A and B."
  4527. (let* ((ma (or (get-text-property 1 'org-marker a)
  4528. (get-text-property 1 'org-hd-marker a)))
  4529. (mb (or (get-text-property 1 'org-marker b)
  4530. (get-text-property 1 'org-hd-marker b)))
  4531. (fa (and ma (marker-buffer ma)))
  4532. (fb (and mb (marker-buffer mb)))
  4533. (todo-kwds
  4534. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4535. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4536. (ta (or (get-text-property 1 'todo-state a) ""))
  4537. (tb (or (get-text-property 1 'todo-state b) ""))
  4538. (la (- (length (member ta todo-kwds))))
  4539. (lb (- (length (member tb todo-kwds))))
  4540. (donepa (member ta org-done-keywords-for-agenda))
  4541. (donepb (member tb org-done-keywords-for-agenda)))
  4542. (cond ((and donepa (not donepb)) -1)
  4543. ((and (not donepa) donepb) +1)
  4544. ((< la lb) -1)
  4545. ((< lb la) +1)
  4546. (t nil))))
  4547. (defsubst org-cmp-tag (a b)
  4548. "Compare the string values of the first tags of A and B."
  4549. (let ((ta (car (last (get-text-property 1 'tags a))))
  4550. (tb (car (last (get-text-property 1 'tags b)))))
  4551. (cond ((not ta) +1)
  4552. ((not tb) -1)
  4553. ((string-lessp ta tb) -1)
  4554. ((string-lessp tb ta) +1)
  4555. (t nil))))
  4556. (defsubst org-cmp-time (a b)
  4557. "Compare the time-of-day values of strings A and B."
  4558. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4559. (ta (or (get-text-property 1 'time-of-day a) def))
  4560. (tb (or (get-text-property 1 'time-of-day b) def)))
  4561. (cond ((< ta tb) -1)
  4562. ((< tb ta) +1)
  4563. (t nil))))
  4564. (defsubst org-cmp-habit-p (a b)
  4565. "Compare the todo states of strings A and B."
  4566. (let ((ha (get-text-property 1 'org-habit-p a))
  4567. (hb (get-text-property 1 'org-habit-p b)))
  4568. (cond ((and ha (not hb)) -1)
  4569. ((and (not ha) hb) +1)
  4570. (t nil))))
  4571. (defun org-entries-lessp (a b)
  4572. "Predicate for sorting agenda entries."
  4573. ;; The following variables will be used when the form is evaluated.
  4574. ;; So even though the compiler complains, keep them.
  4575. (let* ((time-up (org-cmp-time a b))
  4576. (time-down (if time-up (- time-up) nil))
  4577. (priority-up (org-cmp-priority a b))
  4578. (priority-down (if priority-up (- priority-up) nil))
  4579. (effort-up (org-cmp-effort a b))
  4580. (effort-down (if effort-up (- effort-up) nil))
  4581. (category-up (org-cmp-category a b))
  4582. (category-down (if category-up (- category-up) nil))
  4583. (category-keep (if category-up +1 nil))
  4584. (tag-up (org-cmp-tag a b))
  4585. (tag-down (if tag-up (- tag-up) nil))
  4586. (todo-state-up (org-cmp-todo-state a b))
  4587. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  4588. (habit-up (org-cmp-habit-p a b))
  4589. (habit-down (if habit-up (- habit-up) nil))
  4590. user-defined-up user-defined-down)
  4591. (if (and org-agenda-cmp-user-defined
  4592. (functionp org-agenda-cmp-user-defined))
  4593. (setq user-defined-up
  4594. (funcall org-agenda-cmp-user-defined a b)
  4595. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  4596. (cdr (assoc
  4597. (eval (cons 'or org-agenda-sorting-strategy-selected))
  4598. '((-1 . t) (1 . nil) (nil . nil))))))
  4599. ;;; Agenda restriction lock
  4600. (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
  4601. "Overlay to mark the headline to which agenda commands are restricted.")
  4602. (org-overlay-put org-agenda-restriction-lock-overlay
  4603. 'face 'org-agenda-restriction-lock)
  4604. (org-overlay-put org-agenda-restriction-lock-overlay
  4605. 'help-echo "Agendas are currently limited to this subtree.")
  4606. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4607. (defun org-agenda-set-restriction-lock (&optional type)
  4608. "Set restriction lock for agenda, to current subtree or file.
  4609. Restriction will be the file if TYPE is `file', or if type is the
  4610. universal prefix '(4), or if the cursor is before the first headline
  4611. in the file. Otherwise, restriction will be to the current subtree."
  4612. (interactive "P")
  4613. (and (equal type '(4)) (setq type 'file))
  4614. (setq type (cond
  4615. (type type)
  4616. ((org-at-heading-p) 'subtree)
  4617. ((condition-case nil (org-back-to-heading t) (error nil))
  4618. 'subtree)
  4619. (t 'file)))
  4620. (if (eq type 'subtree)
  4621. (progn
  4622. (setq org-agenda-restrict t)
  4623. (setq org-agenda-overriding-restriction 'subtree)
  4624. (put 'org-agenda-files 'org-restrict
  4625. (list (buffer-file-name (buffer-base-buffer))))
  4626. (org-back-to-heading t)
  4627. (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  4628. (move-marker org-agenda-restrict-begin (point))
  4629. (move-marker org-agenda-restrict-end
  4630. (save-excursion (org-end-of-subtree t)))
  4631. (message "Locking agenda restriction to subtree"))
  4632. (put 'org-agenda-files 'org-restrict
  4633. (list (buffer-file-name (buffer-base-buffer))))
  4634. (setq org-agenda-restrict nil)
  4635. (setq org-agenda-overriding-restriction 'file)
  4636. (move-marker org-agenda-restrict-begin nil)
  4637. (move-marker org-agenda-restrict-end nil)
  4638. (message "Locking agenda restriction to file"))
  4639. (setq current-prefix-arg nil)
  4640. (org-agenda-maybe-redo))
  4641. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  4642. "Remove the agenda restriction lock."
  4643. (interactive "P")
  4644. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4645. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  4646. (setq org-agenda-overriding-restriction nil)
  4647. (setq org-agenda-restrict nil)
  4648. (put 'org-agenda-files 'org-restrict nil)
  4649. (move-marker org-agenda-restrict-begin nil)
  4650. (move-marker org-agenda-restrict-end nil)
  4651. (setq current-prefix-arg nil)
  4652. (message "Agenda restriction lock removed")
  4653. (or noupdate (org-agenda-maybe-redo)))
  4654. (defun org-agenda-maybe-redo ()
  4655. "If there is any window showing the agenda view, update it."
  4656. (let ((w (get-buffer-window org-agenda-buffer-name t))
  4657. (w0 (selected-window)))
  4658. (when w
  4659. (select-window w)
  4660. (org-agenda-redo)
  4661. (select-window w0)
  4662. (if org-agenda-overriding-restriction
  4663. (message "Agenda view shifted to new %s restriction"
  4664. org-agenda-overriding-restriction)
  4665. (message "Agenda restriction lock removed")))))
  4666. ;;; Agenda commands
  4667. (defun org-agenda-check-type (error &rest types)
  4668. "Check if agenda buffer is of allowed type.
  4669. If ERROR is non-nil, throw an error, otherwise just return nil."
  4670. (if (memq org-agenda-type types)
  4671. t
  4672. (if error
  4673. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  4674. nil)))
  4675. (defun org-agenda-quit ()
  4676. "Exit agenda by removing the window or the buffer."
  4677. (interactive)
  4678. (if org-agenda-columns-active
  4679. (org-columns-quit)
  4680. (let ((buf (current-buffer)))
  4681. (if (eq org-agenda-window-setup 'other-frame)
  4682. (progn
  4683. (kill-buffer buf)
  4684. (org-agenda-reset-markers)
  4685. (org-columns-remove-overlays)
  4686. (setq org-agenda-archives-mode nil)
  4687. (delete-frame))
  4688. (and (not (eq org-agenda-window-setup 'current-window))
  4689. (not (one-window-p))
  4690. (delete-window))
  4691. (kill-buffer buf)
  4692. (org-agenda-reset-markers)
  4693. (org-columns-remove-overlays)
  4694. (setq org-agenda-archives-mode nil)))
  4695. ;; Maybe restore the pre-agenda window configuration.
  4696. (and org-agenda-restore-windows-after-quit
  4697. (not (eq org-agenda-window-setup 'other-frame))
  4698. org-pre-agenda-window-conf
  4699. (set-window-configuration org-pre-agenda-window-conf))))
  4700. (defun org-agenda-exit ()
  4701. "Exit agenda by removing the window or the buffer.
  4702. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  4703. Org-mode buffers visited directly by the user will not be touched."
  4704. (interactive)
  4705. (org-release-buffers org-agenda-new-buffers)
  4706. (setq org-agenda-new-buffers nil)
  4707. (org-agenda-quit))
  4708. (defun org-agenda-execute (arg)
  4709. "Execute another agenda command, keeping same window.\\<global-map>
  4710. So this is just a shortcut for `\\[org-agenda]', available in the agenda."
  4711. (interactive "P")
  4712. (let ((org-agenda-window-setup 'current-window))
  4713. (org-agenda arg)))
  4714. (defun org-agenda-redo ()
  4715. "Rebuild Agenda.
  4716. When this is the global TODO list, a prefix argument will be interpreted."
  4717. (interactive)
  4718. (let* ((org-agenda-keep-modes t)
  4719. (filter org-agenda-filter)
  4720. (preset (get 'org-agenda-filter :preset-filter))
  4721. (cols org-agenda-columns-active)
  4722. (line (org-current-line))
  4723. (window-line (- line (org-current-line (window-start))))
  4724. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  4725. (put 'org-agenda-filter :preset-filter nil)
  4726. (and cols (org-columns-quit))
  4727. (message "Rebuilding agenda buffer...")
  4728. (org-let lprops '(eval org-agenda-redo-command))
  4729. (setq org-agenda-undo-list nil
  4730. org-agenda-pending-undo-list nil)
  4731. (message "Rebuilding agenda buffer...done")
  4732. (put 'org-agenda-filter :preset-filter preset)
  4733. (and (or filter preset) (org-agenda-filter-apply filter))
  4734. (and cols (interactive-p) (org-agenda-columns))
  4735. (org-goto-line line)
  4736. (recenter window-line)))
  4737. (defvar org-global-tags-completion-table nil)
  4738. (defvar org-agenda-filter-form nil)
  4739. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  4740. "Keep only those lines in the agenda buffer that have a specific tag.
  4741. The tag is selected with its fast selection letter, as configured.
  4742. With prefix argument STRIP, remove all lines that do have the tag.
  4743. A lisp caller can specify CHAR. NARROW means that the new tag should be
  4744. used to narrow the search - the interactive user can also press `-' or `+'
  4745. to switch to narrowing."
  4746. (interactive "P")
  4747. (let* ((alist org-tag-alist-for-agenda)
  4748. (tag-chars (mapconcat
  4749. (lambda (x) (if (and (not (symbolp (car x)))
  4750. (cdr x))
  4751. (char-to-string (cdr x))
  4752. ""))
  4753. alist ""))
  4754. (efforts (org-split-string
  4755. (or (cdr (assoc (concat org-effort-property "_ALL")
  4756. org-global-properties))
  4757. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  4758. (effort-op org-agenda-filter-effort-default-operator)
  4759. (effort-prompt "")
  4760. (inhibit-read-only t)
  4761. (current org-agenda-filter)
  4762. char a n tag)
  4763. (unless char
  4764. (message
  4765. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  4766. (if narrow "Narrow" "Filter") tag-chars
  4767. (if org-agenda-auto-exclude-function "[RET], " ""))
  4768. (setq char (read-char)))
  4769. (when (member char '(?+ ?-))
  4770. ;; Narrowing down
  4771. (cond ((equal char ?-) (setq strip t narrow t))
  4772. ((equal char ?+) (setq strip nil narrow t)))
  4773. (message
  4774. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  4775. (setq char (read-char)))
  4776. (when (member char '(?< ?> ?= ??))
  4777. ;; An effort operator
  4778. (setq effort-op (char-to-string char))
  4779. (setq alist nil) ; to make sure it will be interpreted as effort.
  4780. (unless (equal char ??)
  4781. (loop for i from 0 to 9 do
  4782. (setq effort-prompt
  4783. (concat
  4784. effort-prompt " ["
  4785. (if (= i 9) "0" (int-to-string (1+ i)))
  4786. "]" (nth i efforts))))
  4787. (message "Effort%s: %s " effort-op effort-prompt)
  4788. (setq char (read-char))
  4789. (when (or (< char ?0) (> char ?9))
  4790. (error "Need 1-9,0 to select effort" ))))
  4791. (when (equal char ?\t)
  4792. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  4793. (org-set-local 'org-global-tags-completion-table
  4794. (org-global-tags-completion-table)))
  4795. (let ((completion-ignore-case t))
  4796. (setq tag (org-icompleting-read
  4797. "Tag: " org-global-tags-completion-table))))
  4798. (cond
  4799. ((equal char ?\r)
  4800. (org-agenda-filter-by-tag-show-all)
  4801. (when org-agenda-auto-exclude-function
  4802. (setq org-agenda-filter '())
  4803. (dolist (tag org-tag-alist-for-agenda)
  4804. (let ((modifier (funcall org-agenda-auto-exclude-function
  4805. (car tag))))
  4806. (if modifier
  4807. (push modifier org-agenda-filter))))
  4808. (if (not (null org-agenda-filter))
  4809. (org-agenda-filter-apply org-agenda-filter))))
  4810. ((equal char ?/)
  4811. (org-agenda-filter-by-tag-show-all)
  4812. (when (get 'org-agenda-filter :preset-filter)
  4813. (org-agenda-filter-apply org-agenda-filter)))
  4814. ((or (equal char ?\ )
  4815. (setq a (rassoc char alist))
  4816. (and (>= char ?0) (<= char ?9)
  4817. (setq n (if (= char ?0) 9 (- char ?0 1))
  4818. tag (concat effort-op (nth n efforts))
  4819. a (cons tag nil)))
  4820. (and (= char ??)
  4821. (setq tag "?eff")
  4822. a (cons tag nil))
  4823. (and tag (setq a (cons tag nil))))
  4824. (org-agenda-filter-by-tag-show-all)
  4825. (setq tag (car a))
  4826. (setq org-agenda-filter
  4827. (cons (concat (if strip "-" "+") tag)
  4828. (if narrow current nil)))
  4829. (org-agenda-filter-apply org-agenda-filter))
  4830. (t (error "Invalid tag selection character %c" char)))))
  4831. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  4832. "Refine the current filter. See `org-agenda-filter-by-tag."
  4833. (interactive "P")
  4834. (org-agenda-filter-by-tag strip char 'refine))
  4835. (defun org-agenda-filter-make-matcher ()
  4836. "Create the form that tests a line for the agenda filter."
  4837. (let (f f1)
  4838. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  4839. org-agenda-filter))
  4840. (if (member x '("-" "+"))
  4841. (setq f1 (if (equal x "-") 'tags '(not tags)))
  4842. (if (string-match "[<=>?]" x)
  4843. (setq f1 (org-agenda-filter-effort-form x))
  4844. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  4845. (if (equal (string-to-char x) ?-)
  4846. (setq f1 (list 'not f1))))
  4847. (push f1 f))
  4848. (cons 'and (nreverse f))))
  4849. (defun org-agenda-filter-effort-form (e)
  4850. "Return the form to compare the effort of the current line with what E says.
  4851. E looks line \"+<2:25\"."
  4852. (let (op)
  4853. (setq e (substring e 1))
  4854. (setq op (string-to-char e) e (substring e 1))
  4855. (setq op (cond ((equal op ?<) '<=)
  4856. ((equal op ?>) '>=)
  4857. ((equal op ??) op)
  4858. (t '=)))
  4859. (list 'org-agenda-compare-effort (list 'quote op)
  4860. (org-hh:mm-string-to-minutes e))))
  4861. (defun org-agenda-compare-effort (op value)
  4862. "Compare the effort of the current line with VALUE, using OP.
  4863. If the line does not have an effort defined, return nil."
  4864. (let ((eff (org-get-at-bol 'effort-minutes)))
  4865. (if (equal op ??)
  4866. (not eff)
  4867. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  4868. value))))
  4869. (defun org-agenda-filter-apply (filter)
  4870. "Set FILTER as the new agenda filter and apply it."
  4871. (let (tags)
  4872. (setq org-agenda-filter filter
  4873. org-agenda-filter-form (org-agenda-filter-make-matcher))
  4874. (org-agenda-set-mode-name)
  4875. (save-excursion
  4876. (goto-char (point-min))
  4877. (while (not (eobp))
  4878. (if (org-get-at-bol 'org-marker)
  4879. (progn
  4880. (setq tags (org-get-at-bol 'tags)) ; used in eval
  4881. (if (not (eval org-agenda-filter-form))
  4882. (org-agenda-filter-by-tag-hide-line))
  4883. (beginning-of-line 2))
  4884. (beginning-of-line 2))))))
  4885. (defun org-agenda-filter-by-tag-hide-line ()
  4886. (let (ov)
  4887. (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
  4888. (point-at-eol)))
  4889. (org-overlay-put ov 'invisible t)
  4890. (org-overlay-put ov 'type 'tags-filter)
  4891. (push ov org-agenda-filter-overlays)))
  4892. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  4893. (setq pos (or pos (point)))
  4894. (save-excursion
  4895. (dolist (ov (org-overlays-at pos))
  4896. (when (and (org-overlay-get ov 'invisible)
  4897. (eq (org-overlay-get ov 'type) 'tags-filter))
  4898. (goto-char pos)
  4899. (if (< (org-overlay-start ov) (point-at-eol))
  4900. (org-move-overlay ov (point-at-eol)
  4901. (org-overlay-end ov)))))))
  4902. (defun org-agenda-filter-by-tag-show-all ()
  4903. (mapc 'org-delete-overlay org-agenda-filter-overlays)
  4904. (setq org-agenda-filter-overlays nil)
  4905. (setq org-agenda-filter nil)
  4906. (setq org-agenda-filter-form nil)
  4907. (org-agenda-set-mode-name))
  4908. (defun org-agenda-manipulate-query-add ()
  4909. "Manipulate the query by adding a search term with positive selection.
  4910. Positive selection means, the term must be matched for selection of an entry."
  4911. (interactive)
  4912. (org-agenda-manipulate-query ?\[))
  4913. (defun org-agenda-manipulate-query-subtract ()
  4914. "Manipulate the query by adding a search term with negative selection.
  4915. Negative selection means, term must not be matched for selection of an entry."
  4916. (interactive)
  4917. (org-agenda-manipulate-query ?\]))
  4918. (defun org-agenda-manipulate-query-add-re ()
  4919. "Manipulate the query by adding a search regexp with positive selection.
  4920. Positive selection means, the regexp must match for selection of an entry."
  4921. (interactive)
  4922. (org-agenda-manipulate-query ?\{))
  4923. (defun org-agenda-manipulate-query-subtract-re ()
  4924. "Manipulate the query by adding a search regexp with negative selection.
  4925. Negative selection means, regexp must not match for selection of an entry."
  4926. (interactive)
  4927. (org-agenda-manipulate-query ?\}))
  4928. (defun org-agenda-manipulate-query (char)
  4929. (cond
  4930. ((memq org-agenda-type '(timeline agenda))
  4931. (let ((org-agenda-include-inactive-timestamps t))
  4932. (org-agenda-redo))
  4933. (message "Display now includes inactive timestamps as well"))
  4934. ((eq org-agenda-type 'search)
  4935. (org-add-to-string
  4936. 'org-agenda-query-string
  4937. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  4938. (?\{ . " +{}") (?\} . " -{}")))))
  4939. (setq org-agenda-redo-command
  4940. (list 'org-search-view
  4941. org-todo-only
  4942. org-agenda-query-string
  4943. (+ (length org-agenda-query-string)
  4944. (if (member char '(?\{ ?\})) 0 1))))
  4945. (set-register org-agenda-query-register org-agenda-query-string)
  4946. (org-agenda-redo))
  4947. (t (error "Cannot manipulate query for %s-type agenda buffers"
  4948. org-agenda-type))))
  4949. (defun org-add-to-string (var string)
  4950. (set var (concat (symbol-value var) string)))
  4951. (defun org-agenda-goto-date (date)
  4952. "Jump to DATE in agenda."
  4953. (interactive (list (org-read-date)))
  4954. (org-agenda-list nil date))
  4955. (defun org-agenda-goto-today ()
  4956. "Go to today."
  4957. (interactive)
  4958. (org-agenda-check-type t 'timeline 'agenda)
  4959. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  4960. (cond
  4961. (tdpos (goto-char tdpos))
  4962. ((eq org-agenda-type 'agenda)
  4963. (let* ((sd (time-to-days
  4964. (time-subtract (current-time)
  4965. (list 0 (* 3600 org-extend-today-until) 0))))
  4966. (comp (org-agenda-compute-time-span sd org-agenda-span))
  4967. (org-agenda-overriding-arguments org-agenda-last-arguments))
  4968. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  4969. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  4970. (org-agenda-redo)
  4971. (org-agenda-find-same-or-today-or-agenda)))
  4972. (t (error "Cannot find today")))))
  4973. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  4974. (goto-char
  4975. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  4976. (text-property-any (point-min) (point-max) 'org-today t)
  4977. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  4978. (point-min))))
  4979. (defun org-agenda-later (arg)
  4980. "Go forward in time by thee current span.
  4981. With prefix ARG, go forward that many times the current span."
  4982. (interactive "p")
  4983. (org-agenda-check-type t 'agenda)
  4984. (let* ((span org-agenda-span)
  4985. (sd org-starting-day)
  4986. (greg (calendar-gregorian-from-absolute sd))
  4987. (cnt (org-get-at-bol 'org-day-cnt))
  4988. greg2 nd)
  4989. (cond
  4990. ((eq span 'day)
  4991. (setq sd (+ arg sd) nd 1))
  4992. ((eq span 'week)
  4993. (setq sd (+ (* 7 arg) sd) nd 7))
  4994. ((eq span 'month)
  4995. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  4996. sd (calendar-absolute-from-gregorian greg2))
  4997. (setcar greg2 (1+ (car greg2)))
  4998. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  4999. ((eq span 'year)
  5000. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5001. sd (calendar-absolute-from-gregorian greg2))
  5002. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5003. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5004. (let ((org-agenda-overriding-arguments
  5005. (list (car org-agenda-last-arguments) sd nd t)))
  5006. (org-agenda-redo)
  5007. (org-agenda-find-same-or-today-or-agenda cnt))))
  5008. (defun org-agenda-earlier (arg)
  5009. "Go backward in time by the current span.
  5010. With prefix ARG, go backward that many times the current span."
  5011. (interactive "p")
  5012. (org-agenda-later (- arg)))
  5013. (defun org-agenda-view-mode-dispatch ()
  5014. "Call one of the view mode commands."
  5015. (interactive)
  5016. (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
  5017. clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
  5018. (let ((a (read-char-exclusive)))
  5019. (case a
  5020. (?d (call-interactively 'org-agenda-day-view))
  5021. (?w (call-interactively 'org-agenda-week-view))
  5022. (?m (call-interactively 'org-agenda-month-view))
  5023. (?y (call-interactively 'org-agenda-year-view))
  5024. (?l (call-interactively 'org-agenda-log-mode))
  5025. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5026. (?a (call-interactively 'org-agenda-archives-mode))
  5027. (?A (org-agenda-archives-mode 'files))
  5028. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5029. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5030. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5031. (?D (call-interactively 'org-agenda-toggle-diary))
  5032. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5033. (org-agenda-check-type t 'timeline 'agenda)
  5034. (org-agenda-redo))
  5035. (message "Display now includes inactive timestamps as well"))
  5036. (?q (message "Abort"))
  5037. (otherwise (error "Invalid key" )))))
  5038. (defun org-agenda-day-view (&optional day-of-year)
  5039. "Switch to daily view for agenda.
  5040. With argument DAY-OF-YEAR, switch to that day of the year."
  5041. (interactive "P")
  5042. (setq org-agenda-ndays 1)
  5043. (org-agenda-change-time-span 'day day-of-year))
  5044. (defun org-agenda-week-view (&optional iso-week)
  5045. "Switch to daily view for agenda.
  5046. With argument ISO-WEEK, switch to the corresponding ISO week.
  5047. If ISO-WEEK has more then 2 digits, only the last two encode the
  5048. week. Any digits before this encode a year. So 200712 means
  5049. week 12 of year 2007. Years in the range 1938-2037 can also be
  5050. written as 2-digit years."
  5051. (interactive "P")
  5052. (setq org-agenda-ndays 7)
  5053. (org-agenda-change-time-span 'week iso-week))
  5054. (defun org-agenda-month-view (&optional month)
  5055. "Switch to monthly view for agenda.
  5056. With argument MONTH, switch to that month."
  5057. (interactive "P")
  5058. (org-agenda-change-time-span 'month month))
  5059. (defun org-agenda-year-view (&optional year)
  5060. "Switch to yearly view for agenda.
  5061. With argument YEAR, switch to that year.
  5062. If MONTH has more then 2 digits, only the last two encode the
  5063. month. Any digits before this encode a year. So 200712 means
  5064. December year 2007. Years in the range 1938-2037 can also be
  5065. written as 2-digit years."
  5066. (interactive "P")
  5067. (when year
  5068. (setq year (org-small-year-to-year year)))
  5069. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5070. (org-agenda-change-time-span 'year year)
  5071. (error "Abort")))
  5072. (defun org-agenda-change-time-span (span &optional n)
  5073. "Change the agenda view to SPAN.
  5074. SPAN may be `day', `week', `month', `year'."
  5075. (org-agenda-check-type t 'agenda)
  5076. (if (and (not n) (equal org-agenda-span span))
  5077. (error "Viewing span is already \"%s\"" span))
  5078. (let* ((sd (or (org-get-at-bol 'day)
  5079. org-starting-day))
  5080. (computed (org-agenda-compute-time-span sd span n))
  5081. (org-agenda-overriding-arguments
  5082. (list (car org-agenda-last-arguments)
  5083. (car computed) (cdr computed) t)))
  5084. (org-agenda-redo)
  5085. (org-agenda-find-same-or-today-or-agenda))
  5086. (org-agenda-set-mode-name)
  5087. (message "Switched to %s view" span))
  5088. (defun org-agenda-compute-time-span (sd span &optional n)
  5089. "Compute starting date and number of days for agenda.
  5090. SPAN may be `day', `week', `month', `year'. The return value
  5091. is a cons cell with the starting date and the number of days,
  5092. so that the date SD will be in that range."
  5093. (let* ((greg (calendar-gregorian-from-absolute sd))
  5094. (dg (nth 1 greg))
  5095. (mg (car greg))
  5096. (yg (nth 2 greg))
  5097. nd w1 y1 m1 thisweek)
  5098. (cond
  5099. ((eq span 'day)
  5100. (when n
  5101. (setq sd (+ (calendar-absolute-from-gregorian
  5102. (list mg 1 yg))
  5103. n -1)))
  5104. (setq nd 1))
  5105. ((eq span 'week)
  5106. (let* ((nt (calendar-day-of-week
  5107. (calendar-gregorian-from-absolute sd)))
  5108. (d (if org-agenda-start-on-weekday
  5109. (- nt org-agenda-start-on-weekday)
  5110. 0)))
  5111. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5112. (when n
  5113. (require 'cal-iso)
  5114. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5115. (when (> n 99)
  5116. (setq y1 (org-small-year-to-year (/ n 100))
  5117. n (mod n 100)))
  5118. (setq sd
  5119. (calendar-absolute-from-iso
  5120. (list n 1
  5121. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5122. (setq nd 7)))
  5123. ((eq span 'month)
  5124. (when (and n (> n 99))
  5125. (setq y1 (org-small-year-to-year (/ n 100))
  5126. n (mod n 100)))
  5127. (setq sd (calendar-absolute-from-gregorian
  5128. (list (or n mg) 1 (or y1 yg)))
  5129. nd (- (calendar-absolute-from-gregorian
  5130. (list (1+ (or n mg)) 1 (or y1 yg)))
  5131. sd)))
  5132. ((eq span 'year)
  5133. (setq sd (calendar-absolute-from-gregorian
  5134. (list 1 1 (or n yg)))
  5135. nd (- (calendar-absolute-from-gregorian
  5136. (list 1 1 (1+ (or n yg))))
  5137. sd))))
  5138. (cons sd nd)))
  5139. (defun org-agenda-next-date-line (&optional arg)
  5140. "Jump to the next line indicating a date in agenda buffer."
  5141. (interactive "p")
  5142. (org-agenda-check-type t 'agenda 'timeline)
  5143. (beginning-of-line 1)
  5144. ;; This does not work if user makes date format that starts with a blank
  5145. (if (looking-at "^\\S-") (forward-char 1))
  5146. (if (not (re-search-forward "^\\S-" nil t arg))
  5147. (progn
  5148. (backward-char 1)
  5149. (error "No next date after this line in this buffer")))
  5150. (goto-char (match-beginning 0)))
  5151. (defun org-agenda-previous-date-line (&optional arg)
  5152. "Jump to the previous line indicating a date in agenda buffer."
  5153. (interactive "p")
  5154. (org-agenda-check-type t 'agenda 'timeline)
  5155. (beginning-of-line 1)
  5156. (if (not (re-search-backward "^\\S-" nil t arg))
  5157. (error "No previous date before this line in this buffer")))
  5158. ;; Initialize the highlight
  5159. (defvar org-hl (org-make-overlay 1 1))
  5160. (org-overlay-put org-hl 'face 'highlight)
  5161. (defun org-highlight (begin end &optional buffer)
  5162. "Highlight a region with overlay."
  5163. (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
  5164. org-hl begin end (or buffer (current-buffer))))
  5165. (defun org-unhighlight ()
  5166. "Detach overlay INDEX."
  5167. (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
  5168. ;; FIXME this is currently not used.
  5169. (defun org-highlight-until-next-command (beg end &optional buffer)
  5170. "Move the highlight overlay to BEG/END, remove it before the next command."
  5171. (org-highlight beg end buffer)
  5172. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5173. (defun org-unhighlight-once ()
  5174. "Remove the highlight from its position, and this function from the hook."
  5175. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5176. (org-unhighlight))
  5177. (defun org-agenda-follow-mode ()
  5178. "Toggle follow mode in an agenda buffer."
  5179. (interactive)
  5180. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5181. (org-agenda-set-mode-name)
  5182. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5183. (org-agenda-show))
  5184. (message "Follow mode is %s"
  5185. (if org-agenda-follow-mode "on" "off")))
  5186. (defun org-agenda-entry-text-mode (&optional arg)
  5187. "Toggle entry text mode in an agenda buffer."
  5188. (interactive "P")
  5189. (if (integerp arg)
  5190. (setq org-agenda-entry-text-mode t)
  5191. (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
  5192. (org-agenda-entry-text-hide)
  5193. (and org-agenda-entry-text-mode
  5194. (let ((org-agenda-entry-text-maxlines
  5195. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5196. (org-agenda-entry-text-show)))
  5197. (org-agenda-set-mode-name)
  5198. (message "Entry text mode is %s. Maximum number of lines is %d"
  5199. (if org-agenda-entry-text-mode "on" "off")
  5200. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5201. (defun org-agenda-clockreport-mode ()
  5202. "Toggle clocktable mode in an agenda buffer."
  5203. (interactive)
  5204. (org-agenda-check-type t 'agenda)
  5205. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5206. (org-agenda-set-mode-name)
  5207. (org-agenda-redo)
  5208. (message "Clocktable mode is %s"
  5209. (if org-agenda-clockreport-mode "on" "off")))
  5210. (defun org-agenda-log-mode (&optional special)
  5211. "Toggle log mode in an agenda buffer.
  5212. With argument SPECIAL, show all possible log items, not only the ones
  5213. configured in `org-agenda-log-mode-items'.
  5214. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5215. (interactive "P")
  5216. (org-agenda-check-type t 'agenda 'timeline)
  5217. (setq org-agenda-show-log
  5218. (if (equal special '(16))
  5219. 'only
  5220. (if special '(closed clock state)
  5221. (not org-agenda-show-log))))
  5222. (org-agenda-set-mode-name)
  5223. (org-agenda-redo)
  5224. (message "Log mode is %s"
  5225. (if org-agenda-show-log "on" "off")))
  5226. (defun org-agenda-archives-mode (&optional with-files)
  5227. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5228. When called with a prefix argument, include all archive files as well."
  5229. (interactive "P")
  5230. (setq org-agenda-archives-mode
  5231. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5232. (org-agenda-set-mode-name)
  5233. (org-agenda-redo)
  5234. (message
  5235. "%s"
  5236. (cond
  5237. ((eq org-agenda-archives-mode nil)
  5238. "No archives are included")
  5239. ((eq org-agenda-archives-mode 'trees)
  5240. (format "Trees with :%s: tag are included" org-archive-tag))
  5241. ((eq org-agenda-archives-mode t)
  5242. (format "Trees with :%s: tag and all active archive files are included"
  5243. org-archive-tag)))))
  5244. (defun org-agenda-toggle-diary ()
  5245. "Toggle diary inclusion in an agenda buffer."
  5246. (interactive)
  5247. (org-agenda-check-type t 'agenda)
  5248. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5249. (org-agenda-redo)
  5250. (org-agenda-set-mode-name)
  5251. (message "Diary inclusion turned %s"
  5252. (if org-agenda-include-diary "on" "off")))
  5253. (defun org-agenda-toggle-time-grid ()
  5254. "Toggle time grid in an agenda buffer."
  5255. (interactive)
  5256. (org-agenda-check-type t 'agenda)
  5257. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5258. (org-agenda-redo)
  5259. (org-agenda-set-mode-name)
  5260. (message "Time-grid turned %s"
  5261. (if org-agenda-use-time-grid "on" "off")))
  5262. (defun org-agenda-set-mode-name ()
  5263. "Set the mode name to indicate all the small mode settings."
  5264. (setq mode-name
  5265. (concat "Org-Agenda"
  5266. (if (equal org-agenda-ndays 1) " Day" "")
  5267. (if (equal org-agenda-ndays 7) " Week" "")
  5268. (if org-agenda-follow-mode " Follow" "")
  5269. (if org-agenda-entry-text-mode " ETxt" "")
  5270. (if org-agenda-include-diary " Diary" "")
  5271. (if org-agenda-use-time-grid " Grid" "")
  5272. (if (and (boundp 'org-habit-show-habits)
  5273. org-habit-show-habits) " Habit" "")
  5274. (if (consp org-agenda-show-log) " LogAll"
  5275. (if org-agenda-show-log " Log" ""))
  5276. (if (or org-agenda-filter (get 'org-agenda-filter
  5277. :preset-filter))
  5278. (concat " {" (mapconcat
  5279. 'identity
  5280. (append (get 'org-agenda-filter
  5281. :preset-filter)
  5282. org-agenda-filter) "") "}")
  5283. "")
  5284. (if org-agenda-archives-mode
  5285. (if (eq org-agenda-archives-mode t)
  5286. " Archives"
  5287. (format " :%s:" org-archive-tag))
  5288. "")
  5289. (if org-agenda-clockreport-mode " Clock" "")))
  5290. (force-mode-line-update))
  5291. (defun org-agenda-post-command-hook ()
  5292. (setq org-agenda-type
  5293. (or (get-text-property (point) 'org-agenda-type)
  5294. (get-text-property (max (point-min) (1- (point)))
  5295. 'org-agenda-type))))
  5296. (defun org-agenda-next-line ()
  5297. "Move cursor to the next line, and show if follow-mode is active."
  5298. (interactive)
  5299. (call-interactively 'next-line)
  5300. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5301. (org-agenda-show)))
  5302. (defun org-agenda-previous-line ()
  5303. "Move cursor to the previous line, and show if follow-mode is active."
  5304. (interactive)
  5305. (call-interactively 'previous-line)
  5306. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5307. (org-agenda-show)))
  5308. (defun org-agenda-show-priority ()
  5309. "Show the priority of the current item.
  5310. This priority is composed of the main priority given with the [#A] cookies,
  5311. and by additional input from the age of a schedules or deadline entry."
  5312. (interactive)
  5313. (let* ((pri (org-get-at-bol 'priority)))
  5314. (message "Priority is %d" (if pri pri -1000))))
  5315. (defun org-agenda-show-tags ()
  5316. "Show the tags applicable to the current item."
  5317. (interactive)
  5318. (let* ((tags (org-get-at-bol 'tags)))
  5319. (if tags
  5320. (message "Tags are :%s:"
  5321. (org-no-properties (mapconcat 'identity tags ":")))
  5322. (message "No tags associated with this line"))))
  5323. (defun org-agenda-goto (&optional highlight)
  5324. "Go to the Org-mode file which contains the item at point."
  5325. (interactive)
  5326. (let* ((marker (or (org-get-at-bol 'org-marker)
  5327. (org-agenda-error)))
  5328. (buffer (marker-buffer marker))
  5329. (pos (marker-position marker)))
  5330. (switch-to-buffer-other-window buffer)
  5331. (widen)
  5332. (goto-char pos)
  5333. (when (org-mode-p)
  5334. (org-show-context 'agenda)
  5335. (save-excursion
  5336. (and (outline-next-heading)
  5337. (org-flag-heading nil)))) ; show the next heading
  5338. (recenter (/ (window-height) 2))
  5339. (run-hooks 'org-agenda-after-show-hook)
  5340. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5341. (defvar org-agenda-after-show-hook nil
  5342. "Normal hook run after an item has been shown from the agenda.
  5343. Point is in the buffer where the item originated.")
  5344. (defun org-agenda-kill ()
  5345. "Kill the entry or subtree belonging to the current agenda entry."
  5346. (interactive)
  5347. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5348. (let* ((marker (or (org-get-at-bol 'org-marker)
  5349. (org-agenda-error)))
  5350. (buffer (marker-buffer marker))
  5351. (pos (marker-position marker))
  5352. (type (org-get-at-bol 'type))
  5353. dbeg dend (n 0) conf)
  5354. (org-with-remote-undo buffer
  5355. (with-current-buffer buffer
  5356. (save-excursion
  5357. (goto-char pos)
  5358. (if (and (org-mode-p) (not (member type '("sexp"))))
  5359. (setq dbeg (progn (org-back-to-heading t) (point))
  5360. dend (org-end-of-subtree t t))
  5361. (setq dbeg (point-at-bol)
  5362. dend (min (point-max) (1+ (point-at-eol)))))
  5363. (goto-char dbeg)
  5364. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5365. (setq conf (or (eq t org-agenda-confirm-kill)
  5366. (and (numberp org-agenda-confirm-kill)
  5367. (> n org-agenda-confirm-kill))))
  5368. (and conf
  5369. (not (y-or-n-p
  5370. (format "Delete entry with %d lines in buffer \"%s\"? "
  5371. n (buffer-name buffer))))
  5372. (error "Abort"))
  5373. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5374. (with-current-buffer buffer (delete-region dbeg dend))
  5375. (message "Agenda item and source killed"))))
  5376. (defvar org-archive-default-command)
  5377. (defun org-agenda-archive-default ()
  5378. "Archive the entry or subtree belonging to the current agenda entry."
  5379. (interactive)
  5380. (require 'org-archive)
  5381. (org-agenda-archive-with org-archive-default-command))
  5382. (defun org-agenda-archive-default-with-confirmation ()
  5383. "Archive the entry or subtree belonging to the current agenda entry."
  5384. (interactive)
  5385. (require 'org-archive)
  5386. (org-agenda-archive-with org-archive-default-command 'confirm))
  5387. (defun org-agenda-archive ()
  5388. "Archive the entry or subtree belonging to the current agenda entry."
  5389. (interactive)
  5390. (org-agenda-archive-with 'org-archive-subtree))
  5391. (defun org-agenda-archive-to-archive-sibling ()
  5392. "Move the entry to the archive sibling."
  5393. (interactive)
  5394. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5395. (defun org-agenda-archive-with (cmd &optional confirm)
  5396. "Move the entry to the archive sibling."
  5397. (interactive)
  5398. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5399. (let* ((marker (or (org-get-at-bol 'org-marker)
  5400. (org-agenda-error)))
  5401. (buffer (marker-buffer marker))
  5402. (pos (marker-position marker)))
  5403. (org-with-remote-undo buffer
  5404. (with-current-buffer buffer
  5405. (if (org-mode-p)
  5406. (if (and confirm
  5407. (not (y-or-n-p "Archive this subtree or entry? ")))
  5408. (error "Abort")
  5409. (save-excursion
  5410. (goto-char pos)
  5411. (org-remove-subtree-entries-from-agenda)
  5412. (org-back-to-heading t)
  5413. (funcall cmd)))
  5414. (error "Archiving works only in Org-mode files"))))))
  5415. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5416. "Remove all lines in the agenda that correspond to a given subtree.
  5417. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5418. If this information is not given, the function uses the tree at point."
  5419. (let ((buf (or buf (current-buffer))) m p)
  5420. (save-excursion
  5421. (unless (and beg end)
  5422. (org-back-to-heading t)
  5423. (setq beg (point))
  5424. (org-end-of-subtree t)
  5425. (setq end (point)))
  5426. (set-buffer (get-buffer org-agenda-buffer-name))
  5427. (save-excursion
  5428. (goto-char (point-max))
  5429. (beginning-of-line 1)
  5430. (while (not (bobp))
  5431. (when (and (setq m (org-get-at-bol 'org-marker))
  5432. (equal buf (marker-buffer m))
  5433. (setq p (marker-position m))
  5434. (>= p beg)
  5435. (< p end))
  5436. (let ((inhibit-read-only t))
  5437. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5438. (beginning-of-line 0))))))
  5439. (defun org-agenda-refile (&optional goto rfloc)
  5440. "Refile the item at point."
  5441. (interactive "P")
  5442. (if (equal goto '(16))
  5443. (org-refile-goto-last-stored)
  5444. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5445. (org-agenda-error)))
  5446. (buffer (marker-buffer marker))
  5447. (pos (marker-position marker))
  5448. (rfloc (or rfloc
  5449. (org-refile-get-location
  5450. (if goto "Goto: " "Refile to: ") buffer
  5451. org-refile-allow-creating-parent-nodes))))
  5452. (with-current-buffer buffer
  5453. (save-excursion
  5454. (save-restriction
  5455. (widen)
  5456. (goto-char marker)
  5457. (org-remove-subtree-entries-from-agenda)
  5458. (org-refile goto buffer rfloc)))))))
  5459. (defun org-agenda-open-link (&optional arg)
  5460. "Follow the link in the current line, if any.
  5461. This looks for a link in the displayed line in the agenda. It also looks
  5462. at the text of the entry itself."
  5463. (interactive "P")
  5464. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5465. (org-get-at-bol 'org-marker)))
  5466. (buffer (and marker (marker-buffer marker)))
  5467. (prefix (buffer-substring
  5468. (point-at-bol)
  5469. (+ (point-at-bol)
  5470. (or (org-get-at-bol 'prefix-length) 0)))))
  5471. (cond
  5472. (buffer
  5473. (with-current-buffer buffer
  5474. (save-excursion
  5475. (save-restriction
  5476. (widen)
  5477. (goto-char marker)
  5478. (org-offer-links-in-entry arg prefix)))))
  5479. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5480. (save-excursion
  5481. (beginning-of-line 1)
  5482. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5483. (org-open-link-from-string (match-string 1)))
  5484. (t (error "No link to open here")))))
  5485. (defun org-agenda-copy-local-variable (var)
  5486. "Get a variable from a referenced buffer and install it here."
  5487. (let ((m (org-get-at-bol 'org-marker)))
  5488. (when (and m (buffer-live-p (marker-buffer m)))
  5489. (org-set-local var (with-current-buffer (marker-buffer m)
  5490. (symbol-value var))))))
  5491. (defun org-agenda-switch-to (&optional delete-other-windows)
  5492. "Go to the Org-mode file which contains the item at point."
  5493. (interactive)
  5494. (if (and org-return-follows-link
  5495. (not (org-get-at-bol 'org-marker))
  5496. (org-in-regexp org-bracket-link-regexp))
  5497. (org-open-link-from-string (match-string 0))
  5498. (let* ((marker (or (org-get-at-bol 'org-marker)
  5499. (org-agenda-error)))
  5500. (buffer (marker-buffer marker))
  5501. (pos (marker-position marker)))
  5502. (switch-to-buffer buffer)
  5503. (and delete-other-windows (delete-other-windows))
  5504. (widen)
  5505. (goto-char pos)
  5506. (when (org-mode-p)
  5507. (org-show-context 'agenda)
  5508. (save-excursion
  5509. (and (outline-next-heading)
  5510. (org-flag-heading nil))))))) ; show the next heading
  5511. (defun org-agenda-goto-mouse (ev)
  5512. "Go to the Org-mode file which contains the item at the mouse click."
  5513. (interactive "e")
  5514. (mouse-set-point ev)
  5515. (org-agenda-goto))
  5516. (defun org-agenda-show (&optional full-entry)
  5517. "Display the Org-mode file which contains the item at point.
  5518. With prefix argument FULL-ENTRY, make the entire entry visible
  5519. if it was hidden in the outline."
  5520. (interactive "P")
  5521. (let ((win (selected-window)))
  5522. (if full-entry
  5523. (let ((org-show-entry-below t))
  5524. (org-agenda-goto t))
  5525. (org-agenda-goto t))
  5526. (select-window win)))
  5527. (defvar org-agenda-show-window nil)
  5528. (defun org-agenda-show-and-scroll-up ()
  5529. "Display the Org-mode file which contains the item at point.
  5530. When called repeatedly, scroll the window that is displaying the buffer."
  5531. (interactive)
  5532. (let ((win (selected-window)))
  5533. (if (and (window-live-p org-agenda-show-window)
  5534. (eq this-command last-command))
  5535. (progn
  5536. (select-window org-agenda-show-window)
  5537. (ignore-errors (scroll-up)))
  5538. (org-agenda-goto t)
  5539. (show-subtree)
  5540. (setq org-agenda-show-window (selected-window)))
  5541. (select-window win)))
  5542. (defun org-agenda-show-scroll-down ()
  5543. "Scroll down the window showing the agenda."
  5544. (interactive)
  5545. (let ((win (selected-window)))
  5546. (when (window-live-p org-agenda-show-window)
  5547. (select-window org-agenda-show-window)
  5548. (ignore-errors (scroll-down))
  5549. (select-window win))))
  5550. (defun org-agenda-show-1 (&optional more)
  5551. "Display the Org-mode file which contains the item at point.
  5552. The prefix arg selects the amount of information to display:
  5553. 0 hide the subtree
  5554. 1 just show the entry according to defaults.
  5555. 2 show the children view
  5556. 3 show the subtree view
  5557. 4 show the entire subtree and any LOGBOOK drawers
  5558. 5 show the entire subtree and any drawers
  5559. With prefix argument FULL-ENTRY, make the entire entry visible
  5560. if it was hidden in the outline."
  5561. (interactive "p")
  5562. (let ((win (selected-window)))
  5563. (org-agenda-goto t)
  5564. (org-recenter-heading 1)
  5565. (cond
  5566. ((= more 0)
  5567. (hide-subtree)
  5568. (save-excursion
  5569. (org-back-to-heading)
  5570. (run-hook-with-args 'org-cycle-hook 'folded))
  5571. (message "Remote: FOLDED"))
  5572. ((and (interactive-p) (= more 1))
  5573. (message "Remote: show with default settings"))
  5574. ((= more 2)
  5575. (show-entry)
  5576. (show-children)
  5577. (save-excursion
  5578. (org-back-to-heading)
  5579. (run-hook-with-args 'org-cycle-hook 'children))
  5580. (message "Remote: CHILDREN"))
  5581. ((= more 3)
  5582. (show-subtree)
  5583. (save-excursion
  5584. (org-back-to-heading)
  5585. (run-hook-with-args 'org-cycle-hook 'subtree))
  5586. (message "Remote: SUBTREE"))
  5587. ((= more 4)
  5588. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  5589. (org-drawer-regexp
  5590. (concat "^[ \t]*:\\("
  5591. (mapconcat 'regexp-quote org-drawers "\\|")
  5592. "\\):[ \t]*$")))
  5593. (show-subtree)
  5594. (save-excursion
  5595. (org-back-to-heading)
  5596. (org-cycle-hide-drawers 'subtree)))
  5597. (message "Remote: SUBTREE AND LOGBOOK"))
  5598. ((> more 4)
  5599. (show-subtree)
  5600. (message "Remote: SUBTREE AND ALL DRAWERS")))
  5601. (select-window win)))
  5602. (defun org-recenter-heading (n)
  5603. (save-excursion
  5604. (org-back-to-heading)
  5605. (recenter n)))
  5606. (defvar org-agenda-cycle-counter nil)
  5607. (defun org-agenda-cycle-show (&optional n)
  5608. "Show the current entry in another window, with default settings.
  5609. Default settings are taken from `org-show-hierarchy-above' and siblings.
  5610. When use repeatedly in immediate succession, the remote entry will cycle
  5611. through visibility
  5612. children -> subtree -> folded
  5613. When called with a numeric prefix arg, that arg will be passed through to
  5614. `org-agenda-show-1'. For the interpretation of that argument, see the
  5615. docstring of `org-agenda-show-1'."
  5616. (interactive "P")
  5617. (if (integerp n)
  5618. (setq org-agenda-cycle-counter n)
  5619. (if (not (eq last-command this-command))
  5620. (setq org-agenda-cycle-counter 1)
  5621. (if (equal org-agenda-cycle-counter 0)
  5622. (setq org-agenda-cycle-counter 2)
  5623. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  5624. (if (> org-agenda-cycle-counter 3)
  5625. (setq org-agenda-cycle-counter 0)))))
  5626. (org-agenda-show-1 org-agenda-cycle-counter))
  5627. (defun org-agenda-recenter (arg)
  5628. "Display the Org-mode file which contains the item at point and recenter."
  5629. (interactive "P")
  5630. (let ((win (selected-window)))
  5631. (org-agenda-goto t)
  5632. (recenter arg)
  5633. (select-window win)))
  5634. (defun org-agenda-show-mouse (ev)
  5635. "Display the Org-mode file which contains the item at the mouse click."
  5636. (interactive "e")
  5637. (mouse-set-point ev)
  5638. (org-agenda-show))
  5639. (defun org-agenda-check-no-diary ()
  5640. "Check if the entry is a diary link and abort if yes."
  5641. (if (org-get-at-bol 'org-agenda-diary-link)
  5642. (org-agenda-error)))
  5643. (defun org-agenda-error ()
  5644. (error "Command not allowed in this line"))
  5645. (defun org-agenda-tree-to-indirect-buffer ()
  5646. "Show the subtree corresponding to the current entry in an indirect buffer.
  5647. This calls the command `org-tree-to-indirect-buffer' from the original
  5648. Org-mode buffer.
  5649. With numerical prefix arg ARG, go up to this level and then take that tree.
  5650. With a C-u prefix, make a separate frame for this tree (i.e. don't use the
  5651. dedicated frame)."
  5652. (interactive)
  5653. (org-agenda-check-no-diary)
  5654. (let* ((marker (or (org-get-at-bol 'org-marker)
  5655. (org-agenda-error)))
  5656. (buffer (marker-buffer marker))
  5657. (pos (marker-position marker)))
  5658. (with-current-buffer buffer
  5659. (save-excursion
  5660. (goto-char pos)
  5661. (call-interactively 'org-tree-to-indirect-buffer)))))
  5662. (defvar org-last-heading-marker (make-marker)
  5663. "Marker pointing to the headline that last changed its TODO state
  5664. by a remote command from the agenda.")
  5665. (defun org-agenda-todo-nextset ()
  5666. "Switch TODO entry to next sequence."
  5667. (interactive)
  5668. (org-agenda-todo 'nextset))
  5669. (defun org-agenda-todo-previousset ()
  5670. "Switch TODO entry to previous sequence."
  5671. (interactive)
  5672. (org-agenda-todo 'previousset))
  5673. (defun org-agenda-todo (&optional arg)
  5674. "Cycle TODO state of line at point, also in Org-mode file.
  5675. This changes the line at point, all other lines in the agenda referring to
  5676. the same tree node, and the headline of the tree node in the Org-mode file."
  5677. (interactive "P")
  5678. (org-agenda-check-no-diary)
  5679. (let* ((col (current-column))
  5680. (marker (or (org-get-at-bol 'org-marker)
  5681. (org-agenda-error)))
  5682. (buffer (marker-buffer marker))
  5683. (pos (marker-position marker))
  5684. (hdmarker (org-get-at-bol 'org-hd-marker))
  5685. (todayp (equal (org-get-at-bol 'day)
  5686. (time-to-days (current-time))))
  5687. (inhibit-read-only t)
  5688. org-agenda-headline-snapshot-before-repeat newhead just-one)
  5689. (org-with-remote-undo buffer
  5690. (with-current-buffer buffer
  5691. (widen)
  5692. (goto-char pos)
  5693. (org-show-context 'agenda)
  5694. (save-excursion
  5695. (and (outline-next-heading)
  5696. (org-flag-heading nil))) ; show the next heading
  5697. (let ((current-prefix-arg arg))
  5698. (call-interactively 'org-todo))
  5699. (and (bolp) (forward-char 1))
  5700. (setq newhead (org-get-heading))
  5701. (when (and (org-bound-and-true-p
  5702. org-agenda-headline-snapshot-before-repeat)
  5703. (not (equal org-agenda-headline-snapshot-before-repeat
  5704. newhead))
  5705. todayp)
  5706. (setq newhead org-agenda-headline-snapshot-before-repeat
  5707. just-one t))
  5708. (save-excursion
  5709. (org-back-to-heading)
  5710. (move-marker org-last-heading-marker (point))))
  5711. (beginning-of-line 1)
  5712. (save-excursion
  5713. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  5714. (org-move-to-column col))))
  5715. (defun org-agenda-add-note (&optional arg)
  5716. "Add a time-stamped note to the entry at point."
  5717. (interactive "P")
  5718. (org-agenda-check-no-diary)
  5719. (let* ((marker (or (org-get-at-bol 'org-marker)
  5720. (org-agenda-error)))
  5721. (buffer (marker-buffer marker))
  5722. (pos (marker-position marker))
  5723. (hdmarker (org-get-at-bol 'org-hd-marker))
  5724. (inhibit-read-only t))
  5725. (with-current-buffer buffer
  5726. (widen)
  5727. (goto-char pos)
  5728. (org-show-context 'agenda)
  5729. (save-excursion
  5730. (and (outline-next-heading)
  5731. (org-flag-heading nil))) ; show the next heading
  5732. (org-add-note))))
  5733. (defun org-agenda-change-all-lines (newhead hdmarker
  5734. &optional fixface just-this)
  5735. "Change all lines in the agenda buffer which match HDMARKER.
  5736. The new content of the line will be NEWHEAD (as modified by
  5737. `org-format-agenda-item'). HDMARKER is checked with
  5738. `equal' against all `org-hd-marker' text properties in the file.
  5739. If FIXFACE is non-nil, the face of each item is modified according to
  5740. the new TODO state.
  5741. If JUST-THIS is non-nil, change just the current line, not all.
  5742. If FORCE-TAGS is non nil, the car of it returns the new tags."
  5743. (let* ((inhibit-read-only t)
  5744. (line (org-current-line))
  5745. (thetags (with-current-buffer (marker-buffer hdmarker)
  5746. (save-excursion (save-restriction (widen)
  5747. (goto-char hdmarker)
  5748. (org-get-tags-at)))))
  5749. props m pl undone-face done-face finish new dotime cat tags)
  5750. (save-excursion
  5751. (goto-char (point-max))
  5752. (beginning-of-line 1)
  5753. (while (not finish)
  5754. (setq finish (bobp))
  5755. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  5756. (or (not just-this) (= (org-current-line) line))
  5757. (equal m hdmarker))
  5758. (setq props (text-properties-at (point))
  5759. dotime (org-get-at-bol 'dotime)
  5760. cat (org-get-at-bol 'org-category)
  5761. tags thetags
  5762. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  5763. pl (org-get-at-bol 'prefix-length)
  5764. undone-face (org-get-at-bol 'undone-face)
  5765. done-face (org-get-at-bol 'done-face))
  5766. (goto-char (+ (point) pl))
  5767. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  5768. (cond
  5769. ((equal new "")
  5770. (beginning-of-line 1)
  5771. (and (looking-at ".*\n?") (replace-match "")))
  5772. ((looking-at ".*")
  5773. (replace-match new t t)
  5774. (beginning-of-line 1)
  5775. (add-text-properties (point-at-bol) (point-at-eol) props)
  5776. (when fixface
  5777. (add-text-properties
  5778. (point-at-bol) (point-at-eol)
  5779. (list 'face
  5780. (if org-last-todo-state-is-todo
  5781. undone-face done-face))))
  5782. (org-agenda-highlight-todo 'line)
  5783. (beginning-of-line 1))
  5784. (t (error "Line update did not work"))))
  5785. (beginning-of-line 0)))
  5786. (org-finalize-agenda)))
  5787. (defun org-agenda-align-tags (&optional line)
  5788. "Align all tags in agenda items to `org-agenda-tags-column'."
  5789. (let ((inhibit-read-only t) l c)
  5790. (save-excursion
  5791. (goto-char (if line (point-at-bol) (point-min)))
  5792. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  5793. (if line (point-at-eol) nil) t)
  5794. (add-text-properties
  5795. (match-beginning 2) (match-end 2)
  5796. (list 'face (delq nil (let ((prop (get-text-property
  5797. (match-beginning 2) 'face)))
  5798. (or (listp prop) (setq prop (list prop)))
  5799. (if (memq 'org-tag prop)
  5800. prop
  5801. (cons 'org-tag prop))))))
  5802. (setq l (- (match-end 2) (match-beginning 2))
  5803. c (if (< org-agenda-tags-column 0)
  5804. (- (abs org-agenda-tags-column) l)
  5805. org-agenda-tags-column))
  5806. (delete-region (match-beginning 1) (match-end 1))
  5807. (goto-char (match-beginning 1))
  5808. (insert (org-add-props
  5809. (make-string (max 1 (- c (current-column))) ?\ )
  5810. (text-properties-at (point)))))
  5811. (goto-char (point-min))
  5812. (org-font-lock-add-tag-faces (point-max)))))
  5813. (defun org-agenda-priority-up ()
  5814. "Increase the priority of line at point, also in Org-mode file."
  5815. (interactive)
  5816. (org-agenda-priority 'up))
  5817. (defun org-agenda-priority-down ()
  5818. "Decrease the priority of line at point, also in Org-mode file."
  5819. (interactive)
  5820. (org-agenda-priority 'down))
  5821. (defun org-agenda-priority (&optional force-direction)
  5822. "Set the priority of line at point, also in Org-mode file.
  5823. This changes the line at point, all other lines in the agenda referring to
  5824. the same tree node, and the headline of the tree node in the Org-mode file."
  5825. (interactive)
  5826. (unless org-enable-priority-commands
  5827. (error "Priority commands are disabled"))
  5828. (org-agenda-check-no-diary)
  5829. (let* ((marker (or (org-get-at-bol 'org-marker)
  5830. (org-agenda-error)))
  5831. (hdmarker (org-get-at-bol 'org-hd-marker))
  5832. (buffer (marker-buffer hdmarker))
  5833. (pos (marker-position hdmarker))
  5834. (inhibit-read-only t)
  5835. newhead)
  5836. (org-with-remote-undo buffer
  5837. (with-current-buffer buffer
  5838. (widen)
  5839. (goto-char pos)
  5840. (org-show-context 'agenda)
  5841. (save-excursion
  5842. (and (outline-next-heading)
  5843. (org-flag-heading nil))) ; show the next heading
  5844. (funcall 'org-priority force-direction)
  5845. (end-of-line 1)
  5846. (setq newhead (org-get-heading)))
  5847. (org-agenda-change-all-lines newhead hdmarker)
  5848. (beginning-of-line 1))))
  5849. ;; FIXME: should fix the tags property of the agenda line.
  5850. (defun org-agenda-set-tags (&optional tag onoff)
  5851. "Set tags for the current headline."
  5852. (interactive)
  5853. (org-agenda-check-no-diary)
  5854. (if (and (org-region-active-p) (interactive-p))
  5855. (call-interactively 'org-change-tag-in-region)
  5856. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5857. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5858. (org-agenda-error)))
  5859. (buffer (marker-buffer hdmarker))
  5860. (pos (marker-position hdmarker))
  5861. (inhibit-read-only t)
  5862. newhead)
  5863. (org-with-remote-undo buffer
  5864. (with-current-buffer buffer
  5865. (widen)
  5866. (goto-char pos)
  5867. (save-excursion
  5868. (org-show-context 'agenda))
  5869. (save-excursion
  5870. (and (outline-next-heading)
  5871. (org-flag-heading nil))) ; show the next heading
  5872. (goto-char pos)
  5873. (if tag
  5874. (org-toggle-tag tag onoff)
  5875. (call-interactively 'org-set-tags))
  5876. (end-of-line 1)
  5877. (setq newhead (org-get-heading)))
  5878. (org-agenda-change-all-lines newhead hdmarker)
  5879. (beginning-of-line 1)))))
  5880. (defun org-agenda-set-property ()
  5881. "Set a property for the current headline."
  5882. (interactive)
  5883. (org-agenda-check-no-diary)
  5884. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5885. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5886. (org-agenda-error)))
  5887. (buffer (marker-buffer hdmarker))
  5888. (pos (marker-position hdmarker))
  5889. (inhibit-read-only t)
  5890. newhead)
  5891. (org-with-remote-undo buffer
  5892. (with-current-buffer buffer
  5893. (widen)
  5894. (goto-char pos)
  5895. (save-excursion
  5896. (org-show-context 'agenda))
  5897. (save-excursion
  5898. (and (outline-next-heading)
  5899. (org-flag-heading nil))) ; show the next heading
  5900. (goto-char pos)
  5901. (call-interactively 'org-set-property)))))
  5902. (defun org-agenda-set-effort ()
  5903. "Set the effort property for the current headline."
  5904. (interactive)
  5905. (org-agenda-check-no-diary)
  5906. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5907. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5908. (org-agenda-error)))
  5909. (buffer (marker-buffer hdmarker))
  5910. (pos (marker-position hdmarker))
  5911. (inhibit-read-only t)
  5912. newhead)
  5913. (org-with-remote-undo buffer
  5914. (with-current-buffer buffer
  5915. (widen)
  5916. (goto-char pos)
  5917. (save-excursion
  5918. (org-show-context 'agenda))
  5919. (save-excursion
  5920. (and (outline-next-heading)
  5921. (org-flag-heading nil))) ; show the next heading
  5922. (goto-char pos)
  5923. (call-interactively 'org-set-effort)
  5924. (end-of-line 1)))))
  5925. (defun org-agenda-toggle-archive-tag ()
  5926. "Toggle the archive tag for the current entry."
  5927. (interactive)
  5928. (org-agenda-check-no-diary)
  5929. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5930. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5931. (org-agenda-error)))
  5932. (buffer (marker-buffer hdmarker))
  5933. (pos (marker-position hdmarker))
  5934. (inhibit-read-only t)
  5935. newhead)
  5936. (org-with-remote-undo buffer
  5937. (with-current-buffer buffer
  5938. (widen)
  5939. (goto-char pos)
  5940. (org-show-context 'agenda)
  5941. (save-excursion
  5942. (and (outline-next-heading)
  5943. (org-flag-heading nil))) ; show the next heading
  5944. (call-interactively 'org-toggle-archive-tag)
  5945. (end-of-line 1)
  5946. (setq newhead (org-get-heading)))
  5947. (org-agenda-change-all-lines newhead hdmarker)
  5948. (beginning-of-line 1))))
  5949. (defun org-agenda-do-date-later (arg)
  5950. (interactive "P")
  5951. (cond
  5952. ((or (equal arg '(16))
  5953. (memq last-command
  5954. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  5955. (setq this-command 'org-agenda-date-later-minutes)
  5956. (org-agenda-date-later-minutes 1))
  5957. ((or (equal arg '(4))
  5958. (memq last-command
  5959. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  5960. (setq this-command 'org-agenda-date-later-hours)
  5961. (org-agenda-date-later-hours 1))
  5962. (t
  5963. (org-agenda-date-later (prefix-numeric-value arg)))))
  5964. (defun org-agenda-do-date-earlier (arg)
  5965. (interactive "P")
  5966. (cond
  5967. ((or (equal arg '(16))
  5968. (memq last-command
  5969. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  5970. (setq this-command 'org-agenda-date-earlier-minutes)
  5971. (org-agenda-date-earlier-minutes 1))
  5972. ((or (equal arg '(4))
  5973. (memq last-command
  5974. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  5975. (setq this-command 'org-agenda-date-earlier-hours)
  5976. (org-agenda-date-earlier-hours 1))
  5977. (t
  5978. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  5979. (defun org-agenda-date-later (arg &optional what)
  5980. "Change the date of this item to one day later."
  5981. (interactive "p")
  5982. (org-agenda-check-type t 'agenda 'timeline)
  5983. (org-agenda-check-no-diary)
  5984. (let* ((marker (or (org-get-at-bol 'org-marker)
  5985. (org-agenda-error)))
  5986. (buffer (marker-buffer marker))
  5987. (pos (marker-position marker)))
  5988. (org-with-remote-undo buffer
  5989. (with-current-buffer buffer
  5990. (widen)
  5991. (goto-char pos)
  5992. (if (not (org-at-timestamp-p))
  5993. (error "Cannot find time stamp"))
  5994. (org-timestamp-change arg (or what 'day)))
  5995. (org-agenda-show-new-time marker org-last-changed-timestamp))
  5996. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  5997. (defun org-agenda-date-earlier (arg &optional what)
  5998. "Change the date of this item to one day earlier."
  5999. (interactive "p")
  6000. (org-agenda-date-later (- arg) what))
  6001. (defun org-agenda-date-later-minutes (arg)
  6002. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6003. (interactive "p")
  6004. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6005. (org-agenda-date-later arg 'minute))
  6006. (defun org-agenda-date-earlier-minutes (arg)
  6007. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6008. (interactive "p")
  6009. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6010. (org-agenda-date-earlier arg 'minute))
  6011. (defun org-agenda-date-later-hours (arg)
  6012. "Change the time of this item, in hour steps."
  6013. (interactive "p")
  6014. (org-agenda-date-later arg 'hour))
  6015. (defun org-agenda-date-earlier-hours (arg)
  6016. "Change the time of this item, in hour steps."
  6017. (interactive "p")
  6018. (org-agenda-date-earlier arg 'hour))
  6019. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6020. "Show new date stamp via text properties."
  6021. ;; We use text properties to make this undoable
  6022. (let ((inhibit-read-only t)
  6023. (buffer-invisibility-spec))
  6024. (setq stamp (concat " " prefix " => " stamp))
  6025. (save-excursion
  6026. (goto-char (point-max))
  6027. (while (not (bobp))
  6028. (when (equal marker (org-get-at-bol 'org-marker))
  6029. (org-move-to-column (- (window-width) (length stamp)) t)
  6030. (org-agenda-fix-tags-filter-overlays-at (point))
  6031. (if (featurep 'xemacs)
  6032. ;; Use `duplicable' property to trigger undo recording
  6033. (let ((ex (make-extent nil nil))
  6034. (gl (make-glyph stamp)))
  6035. (set-glyph-face gl 'secondary-selection)
  6036. (set-extent-properties
  6037. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6038. (insert-extent ex (1- (point)) (point-at-eol)))
  6039. (add-text-properties
  6040. (1- (point)) (point-at-eol)
  6041. (list 'display (org-add-props stamp nil
  6042. 'face 'secondary-selection))))
  6043. (beginning-of-line 1))
  6044. (beginning-of-line 0)))))
  6045. (defun org-agenda-date-prompt (arg)
  6046. "Change the date of this item. Date is prompted for, with default today.
  6047. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6048. be used to request time specification in the time stamp."
  6049. (interactive "P")
  6050. (org-agenda-check-type t 'agenda 'timeline)
  6051. (org-agenda-check-no-diary)
  6052. (let* ((marker (or (org-get-at-bol 'org-marker)
  6053. (org-agenda-error)))
  6054. (buffer (marker-buffer marker))
  6055. (pos (marker-position marker)))
  6056. (org-with-remote-undo buffer
  6057. (with-current-buffer buffer
  6058. (widen)
  6059. (goto-char pos)
  6060. (if (not (org-at-timestamp-p))
  6061. (error "Cannot find time stamp"))
  6062. (org-time-stamp arg))
  6063. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6064. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6065. (defun org-agenda-schedule (arg)
  6066. "Schedule the item at point."
  6067. (interactive "P")
  6068. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6069. (org-agenda-check-no-diary)
  6070. (let* ((marker (or (org-get-at-bol 'org-marker)
  6071. (org-agenda-error)))
  6072. (type (marker-insertion-type marker))
  6073. (buffer (marker-buffer marker))
  6074. (pos (marker-position marker))
  6075. (org-insert-labeled-timestamps-at-point nil)
  6076. ts)
  6077. (set-marker-insertion-type marker t)
  6078. (org-with-remote-undo buffer
  6079. (with-current-buffer buffer
  6080. (widen)
  6081. (goto-char pos)
  6082. (setq ts (org-schedule arg)))
  6083. (org-agenda-show-new-time marker ts "S"))
  6084. (message "Item scheduled for %s" ts)))
  6085. (defun org-agenda-deadline (arg)
  6086. "Schedule the item at point."
  6087. (interactive "P")
  6088. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6089. (org-agenda-check-no-diary)
  6090. (let* ((marker (or (org-get-at-bol 'org-marker)
  6091. (org-agenda-error)))
  6092. (buffer (marker-buffer marker))
  6093. (pos (marker-position marker))
  6094. (org-insert-labeled-timestamps-at-point nil)
  6095. ts)
  6096. (org-with-remote-undo buffer
  6097. (with-current-buffer buffer
  6098. (widen)
  6099. (goto-char pos)
  6100. (setq ts (org-deadline arg)))
  6101. (org-agenda-show-new-time marker ts "D"))
  6102. (message "Deadline for this item set to %s" ts)))
  6103. (defun org-agenda-action ()
  6104. "Select entry for agenda action, or execute an agenda action.
  6105. This command prompts for another letter. Valid inputs are:
  6106. m Mark the entry at point for an agenda action
  6107. s Schedule the marked entry to the date at the cursor
  6108. d Set the deadline of the marked entry to the date at the cursor
  6109. r Call `org-remember' with cursor date as the default date
  6110. SPC Show marked entry in other window
  6111. TAB Visit marked entry in other window
  6112. The cursor may be at a date in the calendar, or in the Org agenda."
  6113. (interactive)
  6114. (let (ans)
  6115. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
  6116. (setq ans (read-char-exclusive))
  6117. (cond
  6118. ((equal ans ?m)
  6119. ;; Mark this entry
  6120. (if (eq major-mode 'org-agenda-mode)
  6121. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6122. (org-get-at-bol 'org-marker))))
  6123. (if m
  6124. (progn
  6125. (move-marker org-agenda-action-marker
  6126. (marker-position m) (marker-buffer m))
  6127. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6128. (error "Don't know which entry to mark")))
  6129. (error "This command works only in the agenda")))
  6130. ((equal ans ?s)
  6131. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6132. ((equal ans ?d)
  6133. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6134. ((equal ans ?r)
  6135. (org-agenda-do-action '(org-remember) t))
  6136. ((equal ans ?\ )
  6137. (let ((cw (selected-window)))
  6138. (org-switch-to-buffer-other-window
  6139. (marker-buffer org-agenda-action-marker))
  6140. (goto-char org-agenda-action-marker)
  6141. (org-show-context 'agenda)
  6142. (select-window cw)))
  6143. ((equal ans ?\C-i)
  6144. (org-switch-to-buffer-other-window
  6145. (marker-buffer org-agenda-action-marker))
  6146. (goto-char org-agenda-action-marker)
  6147. (org-show-context 'agenda))
  6148. (t (error "Invalid agenda action %c" ans)))))
  6149. (defun org-agenda-do-action (form &optional current-buffer)
  6150. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6151. (let ((org-overriding-default-time (org-get-cursor-date)))
  6152. (if current-buffer
  6153. (eval form)
  6154. (if (not (marker-buffer org-agenda-action-marker))
  6155. (error "No entry has been selected for agenda action")
  6156. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6157. (save-excursion
  6158. (save-restriction
  6159. (widen)
  6160. (goto-char org-agenda-action-marker)
  6161. (eval form))))))))
  6162. (defun org-agenda-clock-in (&optional arg)
  6163. "Start the clock on the currently selected item."
  6164. (interactive "P")
  6165. (org-agenda-check-no-diary)
  6166. (if (equal arg '(4))
  6167. (org-clock-in arg)
  6168. (let* ((marker (or (org-get-at-bol 'org-marker)
  6169. (org-agenda-error)))
  6170. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6171. marker))
  6172. (pos (marker-position marker))
  6173. newhead)
  6174. (org-with-remote-undo (marker-buffer marker)
  6175. (with-current-buffer (marker-buffer marker)
  6176. (widen)
  6177. (goto-char pos)
  6178. (org-show-context 'agenda)
  6179. (org-show-entry)
  6180. (org-cycle-hide-drawers 'children)
  6181. (org-clock-in arg)
  6182. (setq newhead (org-get-heading)))
  6183. (org-agenda-change-all-lines newhead hdmarker)))))
  6184. (defun org-agenda-clock-out (&optional arg)
  6185. "Stop the currently running clock."
  6186. (interactive "P")
  6187. (unless (marker-buffer org-clock-marker)
  6188. (error "No running clock"))
  6189. (let ((marker (make-marker)) newhead)
  6190. (org-with-remote-undo (marker-buffer org-clock-marker)
  6191. (with-current-buffer (marker-buffer org-clock-marker)
  6192. (save-excursion
  6193. (save-restriction
  6194. (widen)
  6195. (goto-char org-clock-marker)
  6196. (org-back-to-heading t)
  6197. (move-marker marker (point))
  6198. (org-clock-out)
  6199. (setq newhead (org-get-heading))))))
  6200. (org-agenda-change-all-lines newhead marker)
  6201. (move-marker marker nil)))
  6202. (defun org-agenda-clock-cancel (&optional arg)
  6203. "Cancel the currently running clock."
  6204. (interactive "P")
  6205. (unless (marker-buffer org-clock-marker)
  6206. (error "No running clock"))
  6207. (org-with-remote-undo (marker-buffer org-clock-marker)
  6208. (org-clock-cancel)))
  6209. (defun org-agenda-diary-entry-in-org-file ()
  6210. "Make a diary entry in the file `org-agenda-diary-file'."
  6211. (let (d1 d2 char (text ""))
  6212. (if (equal (buffer-name) "*Calendar*")
  6213. (setq d1 (calendar-cursor-to-date t)
  6214. d2 (car calendar-mark-ring))
  6215. (setq d1 (calendar-gregorian-from-absolute
  6216. (get-text-property (point) 'day))
  6217. d2 (and (mark) (get-text-property (mark) 'day)
  6218. (calendar-gregorian-from-absolute
  6219. (get-text-property (mark) 'day)))))
  6220. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6221. (setq char (read-char-exclusive))
  6222. (cond
  6223. ((equal char ?d)
  6224. (setq text (read-string "Day entry: "))
  6225. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1))
  6226. ((equal char ?a)
  6227. (setq d1 (list (car d1) (nth 1 d1)
  6228. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6229. (nth 2 d1))))
  6230. (setq text (read-string "Anniversary (use %d to show years): "))
  6231. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1))
  6232. ((equal char ?b)
  6233. (setq text (read-string "Block entry: "))
  6234. (unless (and d1 d2 (not (equal d1 d2)))
  6235. (error "No block of days selected"))
  6236. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2))
  6237. ((equal char ?j)
  6238. (org-switch-to-buffer-other-window
  6239. (find-file-noselect org-agenda-diary-file))
  6240. (org-datetree-find-date-create d1)
  6241. (org-reveal t))
  6242. (t (error "Invalid selection character `%c'" char)))))
  6243. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6244. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6245. If TEXT is not empty, it will become the headline of the new entry, and
  6246. the resulting entry will not be shown. When TEXT is empty, switch to
  6247. `org-agenda-diary-file' and let the user finish the entry there."
  6248. (let ((cw (current-window-configuration)))
  6249. (org-switch-to-buffer-other-window
  6250. (find-file-noselect org-agenda-diary-file))
  6251. (widen)
  6252. (goto-char (point-min))
  6253. (cond
  6254. ((eq type 'anniversary)
  6255. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6256. (progn
  6257. (or (org-on-heading-p t)
  6258. (progn
  6259. (outline-next-heading)
  6260. (insert "* Anniversaries\n\n")
  6261. (beginning-of-line -1)))))
  6262. (outline-next-heading)
  6263. (org-back-over-empty-lines)
  6264. (backward-char 1)
  6265. (insert "\n")
  6266. (require 'diary-lib)
  6267. (let ((calendar-date-display-form
  6268. (if (if (boundp 'calendar-date-style)
  6269. (eq calendar-date-style 'european)
  6270. european-calendar-style) ; Emacs 22
  6271. '(day " " month " " year)
  6272. '(month " " day " " year))))
  6273. (insert (format "%%%%(diary-anniversary %s) %s"
  6274. (calendar-date-string d1 nil t) text))))
  6275. ((eq type 'day)
  6276. (require 'org-datetree)
  6277. (org-datetree-find-date-create d1)
  6278. (org-agenda-insert-diary-make-new-entry text)
  6279. (org-insert-time-stamp (org-time-from-absolute
  6280. (calendar-absolute-from-gregorian d1)))
  6281. (end-of-line 0))
  6282. ((eq type 'block)
  6283. (if (> (calendar-absolute-from-gregorian d1)
  6284. (calendar-absolute-from-gregorian d2))
  6285. (setq d1 (prog1 d2 (setq d2 d1))))
  6286. (require 'org-datetree)
  6287. (org-datetree-find-date-create d1)
  6288. (org-agenda-insert-diary-make-new-entry text)
  6289. (org-insert-time-stamp (org-time-from-absolute
  6290. (calendar-absolute-from-gregorian d1)))
  6291. (insert "--")
  6292. (org-insert-time-stamp (org-time-from-absolute
  6293. (calendar-absolute-from-gregorian d2)))
  6294. (end-of-line 0)))
  6295. (if (string-match "\\S-" text)
  6296. (progn
  6297. (set-window-configuration cw)
  6298. (message "%s entry added to %s"
  6299. (capitalize (symbol-name type))
  6300. (abbreviate-file-name org-agenda-diary-file)))
  6301. (org-reveal t)
  6302. (message "Please finish entry here"))))
  6303. (defun org-agenda-insert-diary-make-new-entry (text)
  6304. "Make new entry as last child of current entry.
  6305. Add TEXT as headline, and position the cursor in the second line so that
  6306. a timestamp can be added there."
  6307. (let ((org-show-following-heading t)
  6308. (org-show-siblings t)
  6309. (org-show-hierarchy-above t)
  6310. (org-show-entry-below t)
  6311. col)
  6312. (outline-next-heading)
  6313. (org-back-over-empty-lines)
  6314. (or (looking-at "[ \t]*$")
  6315. (progn (insert "\n") (backward-char 1)))
  6316. (org-insert-heading)
  6317. (org-do-demote)
  6318. (setq col (current-column))
  6319. (insert text "\n")
  6320. (if org-adapt-indentation (org-indent-to-column col))
  6321. (let ((org-show-following-heading t)
  6322. (org-show-siblings t)
  6323. (org-show-hierarchy-above t)
  6324. (org-show-entry-below t))
  6325. (org-show-context))))
  6326. (defun org-agenda-diary-entry ()
  6327. "Make a diary entry, like the `i' command from the calendar.
  6328. All the standard commands work: block, weekly etc.
  6329. When `org-agenda-diary-file' points to a file,
  6330. `org-agenda-diary-entry-in-org-file' is called instead to create
  6331. entries in that Org-mode file."
  6332. (interactive)
  6333. (org-agenda-check-type t 'agenda 'timeline)
  6334. (if (not (eq org-agenda-diary-file 'diary-file))
  6335. (org-agenda-diary-entry-in-org-file)
  6336. (require 'diary-lib)
  6337. (let* ((char (progn
  6338. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6339. (read-char-exclusive)))
  6340. (cmd (cdr (assoc char
  6341. '((?d . insert-diary-entry)
  6342. (?w . insert-weekly-diary-entry)
  6343. (?m . insert-monthly-diary-entry)
  6344. (?y . insert-yearly-diary-entry)
  6345. (?a . insert-anniversary-diary-entry)
  6346. (?b . insert-block-diary-entry)
  6347. (?c . insert-cyclic-diary-entry)))))
  6348. (oldf (symbol-function 'calendar-cursor-to-date))
  6349. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6350. (point (point))
  6351. (mark (or (mark t) (point))))
  6352. (unless cmd
  6353. (error "No command associated with <%c>" char))
  6354. (unless (and (get-text-property point 'day)
  6355. (or (not (equal ?b char))
  6356. (get-text-property mark 'day)))
  6357. (error "Don't know which date to use for diary entry"))
  6358. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6359. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6360. (let ((calendar-mark-ring
  6361. (list (calendar-gregorian-from-absolute
  6362. (or (get-text-property mark 'day)
  6363. (get-text-property point 'day))))))
  6364. (unwind-protect
  6365. (progn
  6366. (fset 'calendar-cursor-to-date
  6367. (lambda (&optional error dummy)
  6368. (calendar-gregorian-from-absolute
  6369. (get-text-property point 'day))))
  6370. (call-interactively cmd))
  6371. (fset 'calendar-cursor-to-date oldf))))))
  6372. (defun org-agenda-execute-calendar-command (cmd)
  6373. "Execute a calendar command from the agenda, with the date associated to
  6374. the cursor position."
  6375. (org-agenda-check-type t 'agenda 'timeline)
  6376. (require 'diary-lib)
  6377. (unless (get-text-property (point) 'day)
  6378. (error "Don't know which date to use for calendar command"))
  6379. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6380. (point (point))
  6381. (date (calendar-gregorian-from-absolute
  6382. (get-text-property point 'day)))
  6383. ;; the following 2 vars are needed in the calendar
  6384. (displayed-month (car date))
  6385. (displayed-year (nth 2 date)))
  6386. (unwind-protect
  6387. (progn
  6388. (fset 'calendar-cursor-to-date
  6389. (lambda (&optional error dummy)
  6390. (calendar-gregorian-from-absolute
  6391. (get-text-property point 'day))))
  6392. (call-interactively cmd))
  6393. (fset 'calendar-cursor-to-date oldf))))
  6394. (defun org-agenda-phases-of-moon ()
  6395. "Display the phases of the moon for the 3 months around the cursor date."
  6396. (interactive)
  6397. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6398. (defun org-agenda-holidays ()
  6399. "Display the holidays for the 3 months around the cursor date."
  6400. (interactive)
  6401. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6402. (defvar calendar-longitude)
  6403. (defvar calendar-latitude)
  6404. (defvar calendar-location-name)
  6405. (defun org-agenda-sunrise-sunset (arg)
  6406. "Display sunrise and sunset for the cursor date.
  6407. Latitude and longitude can be specified with the variables
  6408. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6409. argument, latitude and longitude will be prompted for."
  6410. (interactive "P")
  6411. (require 'solar)
  6412. (let ((calendar-longitude (if arg nil calendar-longitude))
  6413. (calendar-latitude (if arg nil calendar-latitude))
  6414. (calendar-location-name
  6415. (if arg "the given coordinates" calendar-location-name)))
  6416. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6417. (defun org-agenda-goto-calendar ()
  6418. "Open the Emacs calendar with the date at the cursor."
  6419. (interactive)
  6420. (org-agenda-check-type t 'agenda 'timeline)
  6421. (let* ((day (or (get-text-property (point) 'day)
  6422. (error "Don't know which date to open in calendar")))
  6423. (date (calendar-gregorian-from-absolute day))
  6424. (calendar-move-hook nil)
  6425. (calendar-view-holidays-initially-flag nil)
  6426. (calendar-view-diary-initially-flag nil)
  6427. (view-calendar-holidays-initially nil)
  6428. (view-diary-entries-initially nil))
  6429. (calendar)
  6430. (calendar-goto-date date)))
  6431. ;;;###autoload
  6432. (defun org-calendar-goto-agenda ()
  6433. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6434. This is a command that has to be installed in `calendar-mode-map'."
  6435. (interactive)
  6436. (org-agenda-list nil (calendar-absolute-from-gregorian
  6437. (calendar-cursor-to-date))
  6438. nil))
  6439. (defun org-agenda-convert-date ()
  6440. (interactive)
  6441. (org-agenda-check-type t 'agenda 'timeline)
  6442. (let ((day (get-text-property (point) 'day))
  6443. date s)
  6444. (unless day
  6445. (error "Don't know which date to convert"))
  6446. (setq date (calendar-gregorian-from-absolute day))
  6447. (setq s (concat
  6448. "Gregorian: " (calendar-date-string date) "\n"
  6449. "ISO: " (calendar-iso-date-string date) "\n"
  6450. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6451. "Julian: " (calendar-julian-date-string date) "\n"
  6452. "Astron. JD: " (calendar-astro-date-string date)
  6453. " (Julian date number at noon UTC)\n"
  6454. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6455. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6456. "French: " (calendar-french-date-string date) "\n"
  6457. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6458. "Mayan: " (calendar-mayan-date-string date) "\n"
  6459. "Coptic: " (calendar-coptic-date-string date) "\n"
  6460. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  6461. "Persian: " (calendar-persian-date-string date) "\n"
  6462. "Chinese: " (calendar-chinese-date-string date) "\n"))
  6463. (with-output-to-temp-buffer "*Dates*"
  6464. (princ s))
  6465. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  6466. ;;; Bulk commands
  6467. (defvar org-agenda-bulk-marked-entries nil
  6468. "List of markers that refer to marked entries in the agenda.")
  6469. (defun org-agenda-bulk-marked-p ()
  6470. (eq (get-char-property (point-at-bol) 'type)
  6471. 'org-marked-entry-overlay))
  6472. (defun org-agenda-bulk-mark ()
  6473. "Mark the entry at point for future bulk action."
  6474. (interactive)
  6475. (org-agenda-check-no-diary)
  6476. (let* ((m (org-get-at-bol 'org-hd-marker))
  6477. ov)
  6478. (unless (org-agenda-bulk-marked-p)
  6479. (unless m (error "Nothing to mark at point"))
  6480. (push m org-agenda-bulk-marked-entries)
  6481. (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  6482. (org-overlay-display ov "> "
  6483. (org-get-todo-face "TODO")
  6484. 'evaporate)
  6485. (org-overlay-put ov 'type 'org-marked-entry-overlay))
  6486. (beginning-of-line 2)
  6487. (message "%d entries marked for bulk action"
  6488. (length org-agenda-bulk-marked-entries))))
  6489. (defun org-agenda-bulk-unmark ()
  6490. "Unmark the entry at point for future bulk action."
  6491. (interactive)
  6492. (when (org-agenda-bulk-marked-p)
  6493. (org-agenda-bulk-remove-overlays
  6494. (point-at-bol) (+ 2 (point-at-bol)))
  6495. (setq org-agenda-bulk-marked-entries
  6496. (delete (org-get-at-bol 'org-hd-marker)
  6497. org-agenda-bulk-marked-entries)))
  6498. (beginning-of-line 2)
  6499. (message "%d entries marked for bulk action"
  6500. (length org-agenda-bulk-marked-entries)))
  6501. (defun org-agenda-bulk-toggle ()
  6502. "Toggle marking the entry at point for bulk action."
  6503. (interactive)
  6504. (if (org-agenda-bulk-marked-p)
  6505. (org-agenda-bulk-unmark)
  6506. (org-agenda-bulk-mark)))
  6507. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  6508. "Remove the mark overlays between BEG and END in the agenda buffer.
  6509. BEG and END default to the buffer limits.
  6510. This only removes the overlays, it does not remove the markers
  6511. from the list in `org-agenda-bulk-marked-entries'."
  6512. (interactive)
  6513. (mapc (lambda (ov)
  6514. (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
  6515. (org-delete-overlay ov)))
  6516. (org-overlays-in (or beg (point-min)) (or end (point-max)))))
  6517. (defun org-agenda-bulk-remove-all-marks ()
  6518. "Remove all marks in the agenda buffer.
  6519. This will remove the markers, and the overlays."
  6520. (interactive)
  6521. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  6522. (setq org-agenda-bulk-marked-entries nil)
  6523. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  6524. (defun org-agenda-bulk-action ()
  6525. "Execute an remote-editing action on all marked entries."
  6526. (interactive)
  6527. (unless org-agenda-bulk-marked-entries
  6528. (error "No entries are marked"))
  6529. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  6530. (let* ((action (read-char-exclusive))
  6531. (entries (reverse org-agenda-bulk-marked-entries))
  6532. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  6533. (cond
  6534. ((equal action ?$)
  6535. (setq cmd '(org-agenda-archive)))
  6536. ((equal action ?A)
  6537. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  6538. ((member action '(?r ?w))
  6539. (setq rfloc (org-refile-get-location
  6540. "Refile to: "
  6541. (marker-buffer (car org-agenda-bulk-marked-entries))
  6542. org-refile-allow-creating-parent-nodes))
  6543. (setcar (nthcdr 3 rfloc)
  6544. (move-marker (make-marker) (nth 3 rfloc)
  6545. (or (get-file-buffer (nth 1 rfloc))
  6546. (find-buffer-visiting (nth 1 rfloc))
  6547. (error "This should not happen"))))
  6548. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
  6549. ((equal action ?t)
  6550. (setq state (org-icompleting-read
  6551. "Todo state: "
  6552. (with-current-buffer (marker-buffer (car entries))
  6553. (mapcar 'list org-todo-keywords-1))))
  6554. (setq cmd `(let ((org-inhibit-blocking t)
  6555. (org-inhibit-logging 'note))
  6556. (org-agenda-todo ,state))))
  6557. ((memq action '(?- ?+))
  6558. (setq tag (org-icompleting-read
  6559. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  6560. (with-current-buffer (marker-buffer (car entries))
  6561. (delq nil
  6562. (mapcar (lambda (x)
  6563. (if (stringp (car x)) x)) org-tag-alist)))))
  6564. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  6565. ((memq action '(?s ?d))
  6566. (let* ((date (org-read-date
  6567. nil nil nil
  6568. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to")))
  6569. (ans org-read-date-final-answer)
  6570. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  6571. (setq cmd `(let* ((bound (fboundp 'read-string))
  6572. (old (and bound (symbol-function 'read-string))))
  6573. (unwind-protect
  6574. (progn
  6575. (fset 'read-string (lambda (&rest ignore) ,ans))
  6576. (call-interactively ',c1))
  6577. (if bound
  6578. (fset 'read-string old)
  6579. (fmakunbound 'read-string)))))))
  6580. (t (error "Invalid bulk action")))
  6581. ;; Sort the markers, to make sure that parents are handled before children
  6582. (setq entries (sort entries
  6583. (lambda (a b)
  6584. (cond
  6585. ((equal (marker-buffer a) (marker-buffer b))
  6586. (< (marker-position a) (marker-position b)))
  6587. (t
  6588. (string< (buffer-name (marker-buffer a))
  6589. (buffer-name (marker-buffer b))))))))
  6590. ;; Now loop over all markers and apply cmd
  6591. (while (setq e (pop entries))
  6592. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  6593. (if (not pos)
  6594. (progn (message "Skipping removed entry at %s" e)
  6595. (setq cntskip (1+ cntskip)))
  6596. (goto-char pos)
  6597. (eval cmd)
  6598. (setq org-agenda-bulk-marked-entries
  6599. (delete e org-agenda-bulk-marked-entries))
  6600. (setq cnt (1+ cnt))))
  6601. (setq org-agenda-bulk-marked-entries nil)
  6602. (org-agenda-bulk-remove-all-marks)
  6603. (message "Acted on %d entries%s"
  6604. cnt
  6605. (if (= cntskip 0)
  6606. ""
  6607. (format ", skipped %d (disappeared before their turn)"
  6608. cntskip)))))
  6609. ;;; Flagging notes
  6610. (defun org-agenda-show-the-flagging-note ()
  6611. "Display the flagging note in the other window.
  6612. When called a second time in direct sequence, offer to remove the FLAGGING
  6613. tag and (if present) the flagging note."
  6614. (interactive)
  6615. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  6616. (win (selected-window))
  6617. note heading newhead)
  6618. (unless hdmarker
  6619. (error "No linked entry at point"))
  6620. (if (and (eq this-command last-command)
  6621. (y-or-n-p "Unflag and remove any flagging note? "))
  6622. (progn
  6623. (org-agenda-remove-flag hdmarker)
  6624. (let ((win (get-buffer-window "*Flagging Note*")))
  6625. (and win (delete-window win)))
  6626. (message "Entry unflaged"))
  6627. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  6628. (unless note
  6629. (error "No flagging note"))
  6630. (org-kill-new note)
  6631. (org-switch-to-buffer-other-window "*Flagging Note*")
  6632. (erase-buffer)
  6633. (insert note)
  6634. (goto-char (point-min))
  6635. (while (re-search-forward "\\\\n" nil t)
  6636. (replace-match "\n" t t))
  6637. (goto-char (point-min))
  6638. (select-window win)
  6639. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  6640. (defun org-agenda-remove-flag (marker)
  6641. "Remove the FLAGGED tag and any flagging note in the entry."
  6642. (let (newhead)
  6643. (org-with-point-at marker
  6644. (org-toggle-tag "FLAGGED" 'off)
  6645. (org-entry-delete nil "THEFLAGGINGNOTE")
  6646. (setq newhead (org-get-heading)))
  6647. (org-agenda-change-all-lines newhead marker)
  6648. (message "Entry unflaged")))
  6649. (defun org-agenda-get-any-marker (&optional pos)
  6650. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  6651. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  6652. ;;; Appointment reminders
  6653. (defvar appt-time-msg-list)
  6654. ;;;###autoload
  6655. (defun org-agenda-to-appt (&optional refresh filter)
  6656. "Activate appointments found in `org-agenda-files'.
  6657. With a \\[universal-argument] prefix, refresh the list of
  6658. appointments.
  6659. If FILTER is t, interactively prompt the user for a regular
  6660. expression, and filter out entries that don't match it.
  6661. If FILTER is a string, use this string as a regular expression
  6662. for filtering entries out.
  6663. FILTER can also be an alist with the car of each cell being
  6664. either 'headline or 'category. For example:
  6665. '((headline \"IMPORTANT\")
  6666. (category \"Work\"))
  6667. will only add headlines containing IMPORTANT or headlines
  6668. belonging to the \"Work\" category."
  6669. (interactive "P")
  6670. (require 'calendar)
  6671. (if refresh (setq appt-time-msg-list nil))
  6672. (if (eq filter t)
  6673. (setq filter (read-from-minibuffer "Regexp filter: ")))
  6674. (let* ((cnt 0) ; count added events
  6675. (org-agenda-new-buffers nil)
  6676. (org-deadline-warning-days 0)
  6677. (today (org-date-to-gregorian
  6678. (time-to-days (current-time))))
  6679. (org-agenda-restrict nil)
  6680. (files (org-agenda-files 'unrestricted)) entries file)
  6681. ;; Get all entries which may contain an appt
  6682. (org-prepare-agenda-buffers files)
  6683. (while (setq file (pop files))
  6684. (setq entries
  6685. (append entries
  6686. (org-agenda-get-day-entries
  6687. file today :timestamp :scheduled :deadline))))
  6688. (setq entries (delq nil entries))
  6689. ;; Map thru entries and find if we should filter them out
  6690. (mapc
  6691. (lambda(x)
  6692. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  6693. (cat (get-text-property 1 'org-category x))
  6694. (tod (get-text-property 1 'time-of-day x))
  6695. (ok (or (null filter)
  6696. (and (stringp filter) (string-match filter evt))
  6697. (and (listp filter)
  6698. (or (string-match
  6699. (cadr (assoc 'category filter)) cat)
  6700. (string-match
  6701. (cadr (assoc 'headline filter)) evt))))))
  6702. ;; FIXME: Shall we remove text-properties for the appt text?
  6703. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  6704. (when (and ok tod)
  6705. (setq tod (concat "00" (number-to-string tod))
  6706. tod (when (string-match
  6707. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  6708. (concat (match-string 1 tod) ":"
  6709. (match-string 2 tod))))
  6710. (appt-add tod evt)
  6711. (setq cnt (1+ cnt))))) entries)
  6712. (org-release-buffers org-agenda-new-buffers)
  6713. (if (eq cnt 0)
  6714. (message "No event to add")
  6715. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  6716. (defun org-agenda-todayp (date)
  6717. "Does DATE mean today, when considering `org-extend-today-until'?"
  6718. (let (today h)
  6719. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  6720. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  6721. (setq h (nth 2 (decode-time (current-time))))
  6722. (or (and (>= h org-extend-today-until)
  6723. (= date today))
  6724. (and (< h org-extend-today-until)
  6725. (= date (1- today))))))
  6726. (provide 'org-agenda)
  6727. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  6728. ;;; org-agenda.el ends here