org-agenda.el 367 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags to not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  661. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  662. The variables
  663. `org-agenda-todo-ignore-with-date',
  664. `org-agenda-todo-ignore-timestamp',
  665. `org-agenda-todo-ignore-scheduled',
  666. `org-agenda-todo-ignore-deadlines'
  667. make the global TODO list skip entries that have time stamps of certain
  668. kinds. If this option is set, the same options will also apply for the
  669. tags-todo search, which is the general tags/property matcher
  670. restricted to unfinished TODO entries only."
  671. :group 'org-agenda-skip
  672. :group 'org-agenda-todo-list
  673. :group 'org-agenda-match-view
  674. :type 'boolean)
  675. (defcustom org-agenda-skip-scheduled-if-done nil
  676. "Non-nil means don't show scheduled items in agenda when they are done.
  677. This is relevant for the daily/weekly agenda, not for the TODO list. And
  678. it applies only to the actual date of the scheduling. Warnings about
  679. an item with a past scheduling dates are always turned off when the item
  680. is DONE."
  681. :group 'org-agenda-skip
  682. :group 'org-agenda-daily/weekly
  683. :type 'boolean)
  684. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  685. "Non-nil means skip scheduling line if same entry shows because of deadline.
  686. In the agenda of today, an entry can show up multiple times because
  687. it is both scheduled and has a nearby deadline, and maybe a plain time
  688. stamp as well.
  689. When this variable is t, then only the deadline is shown and the fact that
  690. the entry is scheduled today or was scheduled previously is not shown.
  691. When this variable is nil, the entry will be shown several times. When
  692. the variable is the symbol `not-today', then skip scheduled previously,
  693. but not scheduled today."
  694. :group 'org-agenda-skip
  695. :group 'org-agenda-daily/weekly
  696. :type '(choice
  697. (const :tag "Never" nil)
  698. (const :tag "Always" t)
  699. (const :tag "Not when scheduled today" not-today)))
  700. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  701. "Non-nil means skip timestamp line if same entry shows because of deadline.
  702. In the agenda of today, an entry can show up multiple times
  703. because it has both a plain timestamp and has a nearby deadline.
  704. When this variable is t, then only the deadline is shown and the
  705. fact that the entry has a timestamp for or including today is not
  706. shown. When this variable is nil, the entry will be shown
  707. several times."
  708. :group 'org-agenda-skip
  709. :group 'org-agenda-daily/weekly
  710. :version "24.1"
  711. :type '(choice
  712. (const :tag "Never" nil)
  713. (const :tag "Always" t)))
  714. (defcustom org-agenda-skip-deadline-if-done nil
  715. "Non-nil means don't show deadlines when the corresponding item is done.
  716. When nil, the deadline is still shown and should give you a happy feeling.
  717. This is relevant for the daily/weekly agenda. And it applied only to the
  718. actually date of the deadline. Warnings about approaching and past-due
  719. deadlines are always turned off when the item is DONE."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :type 'boolean)
  723. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  724. "Non-nil means skip deadline prewarning when entry is also scheduled.
  725. This will apply on all days where a prewarning for the deadline would
  726. be shown, but not at the day when the entry is actually due. On that day,
  727. the deadline will be shown anyway.
  728. This variable may be set to nil, t, or a number which will then give
  729. the number of days before the actual deadline when the prewarnings
  730. should resume.
  731. This can be used in a workflow where the first showing of the deadline will
  732. trigger you to schedule it, and then you don't want to be reminded of it
  733. because you will take care of it on the day when scheduled."
  734. :group 'org-agenda-skip
  735. :group 'org-agenda-daily/weekly
  736. :version "24.1"
  737. :type '(choice
  738. (const :tag "Always show prewarning" nil)
  739. (const :tag "Remove prewarning if entry is scheduled" t)
  740. (integer :tag "Restart prewarning N days before deadline")))
  741. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  742. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  743. When non-nil, after the search for timestamps has matched once in an
  744. entry, the rest of the entry will not be searched."
  745. :group 'org-agenda-skip
  746. :type 'boolean)
  747. (defcustom org-agenda-skip-timestamp-if-done nil
  748. "Non-nil means don't select item by timestamp or -range if it is DONE."
  749. :group 'org-agenda-skip
  750. :group 'org-agenda-daily/weekly
  751. :type 'boolean)
  752. (defcustom org-agenda-dim-blocked-tasks t
  753. "Non-nil means dim blocked tasks in the agenda display.
  754. This causes some overhead during agenda construction, but if you
  755. have turned on `org-enforce-todo-dependencies',
  756. `org-enforce-todo-checkbox-dependencies', or any other blocking
  757. mechanism, this will create useful feedback in the agenda.
  758. Instead of t, this variable can also have the value `invisible'.
  759. Then blocked tasks will be invisible and only become visible when
  760. they become unblocked. An exemption to this behavior is when a task is
  761. blocked because of unchecked checkboxes below it. Since checkboxes do
  762. not show up in the agenda views, making this task invisible you remove any
  763. trace from agenda views that there is something to do. Therefore, a task
  764. that is blocked because of checkboxes will never be made invisible, it
  765. will only be dimmed."
  766. :group 'org-agenda-daily/weekly
  767. :group 'org-agenda-todo-list
  768. :type '(choice
  769. (const :tag "Do not dim" nil)
  770. (const :tag "Dim to a gray face" t)
  771. (const :tag "Make invisible" invisible)))
  772. (defcustom org-timeline-show-empty-dates 3
  773. "Non-nil means `org-timeline' also shows dates without an entry.
  774. When nil, only the days which actually have entries are shown.
  775. When t, all days between the first and the last date are shown.
  776. When an integer, show also empty dates, but if there is a gap of more than
  777. N days, just insert a special line indicating the size of the gap."
  778. :group 'org-agenda-skip
  779. :type '(choice
  780. (const :tag "None" nil)
  781. (const :tag "All" t)
  782. (integer :tag "at most")))
  783. (defgroup org-agenda-startup nil
  784. "Options concerning initial settings in the Agenda in Org Mode."
  785. :tag "Org Agenda Startup"
  786. :group 'org-agenda)
  787. (defcustom org-agenda-menu-show-matcher t
  788. "Non-nil means show the match string in the agenda dispatcher menu.
  789. When nil, the matcher string is not shown, but is put into the help-echo
  790. property so than moving the mouse over the command shows it.
  791. Setting it to nil is good if matcher strings are very long and/or if
  792. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  793. :group 'org-agenda
  794. :version "24.1"
  795. :type 'boolean)
  796. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  797. (defcustom org-agenda-menu-two-columns nil
  798. "Non-nil means, use two columns to show custom commands in the dispatcher.
  799. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  800. to nil."
  801. :group 'org-agenda
  802. :version "24.1"
  803. :type 'boolean)
  804. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  805. (defcustom org-agenda-finalize-hook nil
  806. "Hook run just before displaying an agenda buffer.
  807. The buffer is still writable when the hook is called.
  808. You can modify some of the buffer substrings but you should be
  809. extra careful not to modify the text properties of the agenda
  810. headlines as the agenda display heavily relies on them."
  811. :group 'org-agenda-startup
  812. :type 'hook)
  813. (defcustom org-agenda-mouse-1-follows-link nil
  814. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  815. A longer mouse click will still set point. Does not work on XEmacs.
  816. Needs to be set before org.el is loaded."
  817. :group 'org-agenda-startup
  818. :type 'boolean)
  819. (defcustom org-agenda-start-with-follow-mode nil
  820. "The initial value of follow mode in a newly created agenda window."
  821. :group 'org-agenda-startup
  822. :type 'boolean)
  823. (defcustom org-agenda-follow-indirect nil
  824. "Non-nil means `org-agenda-follow-mode' displays only the
  825. current item's tree, in an indirect buffer."
  826. :group 'org-agenda
  827. :version "24.1"
  828. :type 'boolean)
  829. (defcustom org-agenda-show-outline-path t
  830. "Non-nil means show outline path in echo area after line motion."
  831. :group 'org-agenda-startup
  832. :type 'boolean)
  833. (defcustom org-agenda-start-with-entry-text-mode nil
  834. "The initial value of entry-text-mode in a newly created agenda window."
  835. :group 'org-agenda-startup
  836. :type 'boolean)
  837. (defcustom org-agenda-entry-text-maxlines 5
  838. "Number of text lines to be added when `E' is pressed in the agenda.
  839. Note that this variable only used during agenda display. Add add entry text
  840. when exporting the agenda, configure the variable
  841. `org-agenda-add-entry-ext-maxlines'."
  842. :group 'org-agenda
  843. :type 'integer)
  844. (defcustom org-agenda-entry-text-exclude-regexps nil
  845. "List of regular expressions to clean up entry text.
  846. The complete matches of all regular expressions in this list will be
  847. removed from entry text before it is shown in the agenda."
  848. :group 'org-agenda
  849. :type '(repeat (regexp)))
  850. (defvar org-agenda-entry-text-cleanup-hook nil
  851. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  852. This cleanup is done in a temporary buffer, so the function may inspect and
  853. change the entire buffer.
  854. Some default stuff like drawers and scheduling/deadline dates will already
  855. have been removed when this is called, as will any matches for regular
  856. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  857. (defvar org-agenda-include-inactive-timestamps nil
  858. "Non-nil means include inactive time stamps in agenda and timeline.
  859. Dynamically scoped.")
  860. (defgroup org-agenda-windows nil
  861. "Options concerning the windows used by the Agenda in Org Mode."
  862. :tag "Org Agenda Windows"
  863. :group 'org-agenda)
  864. (defcustom org-agenda-window-setup 'reorganize-frame
  865. "How the agenda buffer should be displayed.
  866. Possible values for this option are:
  867. current-window Show agenda in the current window, keeping all other windows.
  868. other-window Use `switch-to-buffer-other-window' to display agenda.
  869. reorganize-frame Show only two windows on the current frame, the current
  870. window and the agenda.
  871. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  872. Also, when exiting the agenda, kill that frame.
  873. See also the variable `org-agenda-restore-windows-after-quit'."
  874. :group 'org-agenda-windows
  875. :type '(choice
  876. (const current-window)
  877. (const other-frame)
  878. (const other-window)
  879. (const reorganize-frame)))
  880. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  881. "The min and max height of the agenda window as a fraction of frame height.
  882. The value of the variable is a cons cell with two numbers between 0 and 1.
  883. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  884. :group 'org-agenda-windows
  885. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  886. (defcustom org-agenda-restore-windows-after-quit nil
  887. "Non-nil means restore window configuration upon exiting agenda.
  888. Before the window configuration is changed for displaying the agenda,
  889. the current status is recorded. When the agenda is exited with
  890. `q' or `x' and this option is set, the old state is restored. If
  891. `org-agenda-window-setup' is `other-frame', the value of this
  892. option will be ignored."
  893. :group 'org-agenda-windows
  894. :type 'boolean)
  895. (defcustom org-agenda-ndays nil
  896. "Number of days to include in overview display.
  897. Should be 1 or 7.
  898. Obsolete, see `org-agenda-span'."
  899. :group 'org-agenda-daily/weekly
  900. :type 'integer)
  901. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  902. (defcustom org-agenda-span 'week
  903. "Number of days to include in overview display.
  904. Can be day, week, month, year, or any number of days.
  905. Custom commands can set this variable in the options section."
  906. :group 'org-agenda-daily/weekly
  907. :type '(choice (const :tag "Day" day)
  908. (const :tag "Week" week)
  909. (const :tag "Month" month)
  910. (const :tag "Year" year)
  911. (integer :tag "Custom")))
  912. (defcustom org-agenda-start-on-weekday 1
  913. "Non-nil means start the overview always on the specified weekday.
  914. 0 denotes Sunday, 1 denotes Monday etc.
  915. When nil, always start on the current day.
  916. Custom commands can set this variable in the options section."
  917. :group 'org-agenda-daily/weekly
  918. :type '(choice (const :tag "Today" nil)
  919. (integer :tag "Weekday No.")))
  920. (defcustom org-agenda-show-all-dates t
  921. "Non-nil means `org-agenda' shows every day in the selected range.
  922. When nil, only the days which actually have entries are shown."
  923. :group 'org-agenda-daily/weekly
  924. :type 'boolean)
  925. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  926. "Format string for displaying dates in the agenda.
  927. Used by the daily/weekly agenda and by the timeline. This should be
  928. a format string understood by `format-time-string', or a function returning
  929. the formatted date as a string. The function must take a single argument,
  930. a calendar-style date list like (month day year)."
  931. :group 'org-agenda-daily/weekly
  932. :type '(choice
  933. (string :tag "Format string")
  934. (function :tag "Function")))
  935. (defun org-agenda-format-date-aligned (date)
  936. "Format a date string for display in the daily/weekly agenda, or timeline.
  937. This function makes sure that dates are aligned for easy reading."
  938. (require 'cal-iso)
  939. (let* ((dayname (calendar-day-name date))
  940. (day (cadr date))
  941. (day-of-week (calendar-day-of-week date))
  942. (month (car date))
  943. (monthname (calendar-month-name month))
  944. (year (nth 2 date))
  945. (iso-week (org-days-to-iso-week
  946. (calendar-absolute-from-gregorian date)))
  947. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  948. (1- year))
  949. ((and (= month 12) (<= iso-week 1))
  950. (1+ year))
  951. (t year)))
  952. (weekstring (if (= day-of-week 1)
  953. (format " W%02d" iso-week)
  954. "")))
  955. (format "%-10s %2d %s %4d%s"
  956. dayname day monthname year weekstring)))
  957. (defcustom org-agenda-time-leading-zero nil
  958. "Non-nil means use leading zero for military times in agenda.
  959. For example, 9:30am would become 09:30 rather than 9:30."
  960. :group 'org-agenda-daily/weekly
  961. :version "24.1"
  962. :type 'boolean)
  963. (defcustom org-agenda-timegrid-use-ampm nil
  964. "When set, show AM/PM style timestamps on the timegrid."
  965. :group 'org-agenda
  966. :version "24.1"
  967. :type 'boolean)
  968. (defun org-agenda-time-of-day-to-ampm (time)
  969. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  970. (let* ((hour-number (string-to-number (substring time 0 -3)))
  971. (minute (substring time -2))
  972. (ampm "am"))
  973. (cond
  974. ((equal hour-number 12)
  975. (setq ampm "pm"))
  976. ((> hour-number 12)
  977. (setq ampm "pm")
  978. (setq hour-number (- hour-number 12))))
  979. (concat
  980. (if org-agenda-time-leading-zero
  981. (format "%02d" hour-number)
  982. (format "%02s" (number-to-string hour-number)))
  983. ":" minute ampm)))
  984. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  985. "Conditionally convert TIME to AM/PM format
  986. based on `org-agenda-timegrid-use-ampm'"
  987. (if org-agenda-timegrid-use-ampm
  988. (org-agenda-time-of-day-to-ampm time)
  989. time))
  990. (defcustom org-agenda-weekend-days '(6 0)
  991. "Which days are weekend?
  992. These days get the special face `org-agenda-date-weekend' in the agenda
  993. and timeline buffers."
  994. :group 'org-agenda-daily/weekly
  995. :type '(set :greedy t
  996. (const :tag "Monday" 1)
  997. (const :tag "Tuesday" 2)
  998. (const :tag "Wednesday" 3)
  999. (const :tag "Thursday" 4)
  1000. (const :tag "Friday" 5)
  1001. (const :tag "Saturday" 6)
  1002. (const :tag "Sunday" 0)))
  1003. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1004. "Non-nil means jump to today when moving a past date forward in time.
  1005. When using S-right in the agenda to move a a date forward, and the date
  1006. stamp currently points to the past, the first key press will move it
  1007. to today. WHen nil, just move one day forward even if the date stays
  1008. in the past."
  1009. :group 'org-agenda-daily/weekly
  1010. :version "24.1"
  1011. :type 'boolean)
  1012. (defcustom org-agenda-include-diary nil
  1013. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1014. Custom commands can set this variable in the options section."
  1015. :group 'org-agenda-daily/weekly
  1016. :type 'boolean)
  1017. (defcustom org-agenda-include-deadlines t
  1018. "If non-nil, include entries within their deadline warning period.
  1019. Custom commands can set this variable in the options section."
  1020. :group 'org-agenda-daily/weekly
  1021. :version "24.1"
  1022. :type 'boolean)
  1023. (defcustom org-agenda-repeating-timestamp-show-all t
  1024. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1025. When set to a list of strings, only show occurrences of repeating
  1026. stamps for these TODO keywords. When nil, only one occurrence is
  1027. shown, either today or the nearest into the future."
  1028. :group 'org-agenda-daily/weekly
  1029. :type '(choice
  1030. (const :tag "Show repeating stamps" t)
  1031. (repeat :tag "Show repeating stamps for these TODO keywords"
  1032. (string :tag "TODO Keyword"))
  1033. (const :tag "Don't show repeating stamps" nil)))
  1034. (defcustom org-scheduled-past-days 10000
  1035. "No. of days to continue listing scheduled items that are not marked DONE.
  1036. When an item is scheduled on a date, it shows up in the agenda on this
  1037. day and will be listed until it is marked done for the number of days
  1038. given here."
  1039. :group 'org-agenda-daily/weekly
  1040. :type 'integer)
  1041. (defcustom org-agenda-log-mode-items '(closed clock)
  1042. "List of items that should be shown in agenda log mode.
  1043. This list may contain the following symbols:
  1044. closed Show entries that have been closed on that day.
  1045. clock Show entries that have received clocked time on that day.
  1046. state Show all logged state changes.
  1047. Note that instead of changing this variable, you can also press `C-u l' in
  1048. the agenda to display all available LOG items temporarily."
  1049. :group 'org-agenda-daily/weekly
  1050. :type '(set :greedy t (const closed) (const clock) (const state)))
  1051. (defcustom org-agenda-clock-consistency-checks
  1052. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1053. :gap-ok-around ("4:00")
  1054. :default-face ((:background "DarkRed") (:foreground "white"))
  1055. :overlap-face nil :gap-face nil :no-end-time-face nil
  1056. :long-face nil :short-face nil)
  1057. "This is a property list, with the following keys:
  1058. :max-duration Mark clocking chunks that are longer than this time.
  1059. This is a time string like \"HH:MM\", or the number
  1060. of minutes as an integer.
  1061. :min-duration Mark clocking chunks that are shorter that this.
  1062. This is a time string like \"HH:MM\", or the number
  1063. of minutes as an integer.
  1064. :max-gap Mark gaps between clocking chunks that are longer than
  1065. this duration. A number of minutes, or a string
  1066. like \"HH:MM\".
  1067. :gap-ok-around List of times during the day which are usually not working
  1068. times. When a gap is detected, but the gap contains any
  1069. of these times, the gap is *not* reported. For example,
  1070. if this is (\"4:00\" \"13:00\") then gaps that contain
  1071. 4:00 in the morning (i.e. the night) and 13:00
  1072. (i.e. a typical lunch time) do not cause a warning.
  1073. You should have at least one time during the night in this
  1074. list, or otherwise the first task each morning will trigger
  1075. a warning because it follows a long gap.
  1076. Furthermore, the following properties can be used to define faces for
  1077. issue display.
  1078. :default-face the default face, if the specific face is undefined
  1079. :overlap-face face for overlapping clocks
  1080. :gap-face face for gaps between clocks
  1081. :no-end-time-face face for incomplete clocks
  1082. :long-face face for clock intervals that are too long
  1083. :short-face face for clock intervals that are too short"
  1084. :group 'org-agenda-daily/weekly
  1085. :group 'org-clock
  1086. :version "24.1"
  1087. :type 'plist)
  1088. (defcustom org-agenda-log-mode-add-notes t
  1089. "Non-nil means add first line of notes to log entries in agenda views.
  1090. If a log item like a state change or a clock entry is associated with
  1091. notes, the first line of these notes will be added to the entry in the
  1092. agenda display."
  1093. :group 'org-agenda-daily/weekly
  1094. :type 'boolean)
  1095. (defcustom org-agenda-start-with-log-mode nil
  1096. "The initial value of log-mode in a newly created agenda window.
  1097. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1098. explanations on the possible values."
  1099. :group 'org-agenda-startup
  1100. :group 'org-agenda-daily/weekly
  1101. :type '(choice (const :tag "Don't show log items" nil)
  1102. (const :tag "Show only log items" 'only)
  1103. (const :tag "Show all possible log items" 'clockcheck)
  1104. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1105. (choice (const :tag "Show closed log items" 'closed)
  1106. (const :tag "Show clocked log items" 'clock)
  1107. (const :tag "Show all logged state changes" 'state)))))
  1108. (defcustom org-agenda-start-with-clockreport-mode nil
  1109. "The initial value of clockreport-mode in a newly created agenda window."
  1110. :group 'org-agenda-startup
  1111. :group 'org-agenda-daily/weekly
  1112. :type 'boolean)
  1113. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1114. "Property list with parameters for the clocktable in clockreport mode.
  1115. This is the display mode that shows a clock table in the daily/weekly
  1116. agenda, the properties for this dynamic block can be set here.
  1117. The usual clocktable parameters are allowed here, but you cannot set
  1118. the properties :name, :tstart, :tend, :block, and :scope - these will
  1119. be overwritten to make sure the content accurately reflects the
  1120. current display in the agenda."
  1121. :group 'org-agenda-daily/weekly
  1122. :type 'plist)
  1123. (defcustom org-agenda-search-view-always-boolean nil
  1124. "Non-nil means the search string is interpreted as individual parts.
  1125. The search string for search view can either be interpreted as a phrase,
  1126. or as a list of snippets that define a boolean search for a number of
  1127. strings.
  1128. When this is non-nil, the string will be split on whitespace, and each
  1129. snippet will be searched individually, and all must match in order to
  1130. select an entry. A snippet is then a single string of non-white
  1131. characters, or a string in double quotes, or a regexp in {} braces.
  1132. If a snippet is preceded by \"-\", the snippet must *not* match.
  1133. \"+\" is syntactic sugar for positive selection. Each snippet may
  1134. be found as a full word or a partial word, but see the variable
  1135. `org-agenda-search-view-force-full-words'.
  1136. When this is nil, search will look for the entire search phrase as one,
  1137. with each space character matching any amount of whitespace, including
  1138. line breaks.
  1139. Even when this is nil, you can still switch to Boolean search dynamically
  1140. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1141. is a regexp marked with braces like \"{abc}\", this will also switch to
  1142. boolean search."
  1143. :group 'org-agenda-search-view
  1144. :version "24.1"
  1145. :type 'boolean)
  1146. (if (fboundp 'defvaralias)
  1147. (defvaralias 'org-agenda-search-view-search-words-only
  1148. 'org-agenda-search-view-always-boolean))
  1149. (defcustom org-agenda-search-view-force-full-words nil
  1150. "Non-nil means, search words must be matches as complete words.
  1151. When nil, they may also match part of a word."
  1152. :group 'org-agenda-search-view
  1153. :version "24.1"
  1154. :type 'boolean)
  1155. (defgroup org-agenda-time-grid nil
  1156. "Options concerning the time grid in the Org-mode Agenda."
  1157. :tag "Org Agenda Time Grid"
  1158. :group 'org-agenda)
  1159. (defcustom org-agenda-search-headline-for-time t
  1160. "Non-nil means search headline for a time-of-day.
  1161. If the headline contains a time-of-day in one format or another, it will
  1162. be used to sort the entry into the time sequence of items for a day.
  1163. Some people have time stamps in the headline that refer to the creation
  1164. time or so, and then this produces an unwanted side effect. If this is
  1165. the case for your, use this variable to turn off searching the headline
  1166. for a time."
  1167. :group 'org-agenda-time-grid
  1168. :type 'boolean)
  1169. (defcustom org-agenda-use-time-grid t
  1170. "Non-nil means show a time grid in the agenda schedule.
  1171. A time grid is a set of lines for specific times (like every two hours between
  1172. 8:00 and 20:00). The items scheduled for a day at specific times are
  1173. sorted in between these lines.
  1174. For details about when the grid will be shown, and what it will look like, see
  1175. the variable `org-agenda-time-grid'."
  1176. :group 'org-agenda-time-grid
  1177. :type 'boolean)
  1178. (defcustom org-agenda-time-grid
  1179. '((daily today require-timed)
  1180. "----------------"
  1181. (800 1000 1200 1400 1600 1800 2000))
  1182. "The settings for time grid for agenda display.
  1183. This is a list of three items. The first item is again a list. It contains
  1184. symbols specifying conditions when the grid should be displayed:
  1185. daily if the agenda shows a single day
  1186. weekly if the agenda shows an entire week
  1187. today show grid on current date, independent of daily/weekly display
  1188. require-timed show grid only if at least one item has a time specification
  1189. The second item is a string which will be placed behind the grid time.
  1190. The third item is a list of integers, indicating the times that should have
  1191. a grid line."
  1192. :group 'org-agenda-time-grid
  1193. :type
  1194. '(list
  1195. (set :greedy t :tag "Grid Display Options"
  1196. (const :tag "Show grid in single day agenda display" daily)
  1197. (const :tag "Show grid in weekly agenda display" weekly)
  1198. (const :tag "Always show grid for today" today)
  1199. (const :tag "Show grid only if any timed entries are present"
  1200. require-timed)
  1201. (const :tag "Skip grid times already present in an entry"
  1202. remove-match))
  1203. (string :tag "Grid String")
  1204. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1205. (defcustom org-agenda-show-current-time-in-grid t
  1206. "Non-nil means show the current time in the time grid."
  1207. :group 'org-agenda-time-grid
  1208. :version "24.1"
  1209. :type 'boolean)
  1210. (defcustom org-agenda-current-time-string
  1211. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1212. "The string for the current time marker in the agenda."
  1213. :group 'org-agenda-time-grid
  1214. :version "24.1"
  1215. :type 'string)
  1216. (defgroup org-agenda-sorting nil
  1217. "Options concerning sorting in the Org-mode Agenda."
  1218. :tag "Org Agenda Sorting"
  1219. :group 'org-agenda)
  1220. (defcustom org-agenda-sorting-strategy
  1221. '((agenda habit-down time-up priority-down category-keep)
  1222. (todo priority-down category-keep)
  1223. (tags priority-down category-keep)
  1224. (search category-keep))
  1225. "Sorting structure for the agenda items of a single day.
  1226. This is a list of symbols which will be used in sequence to determine
  1227. if an entry should be listed before another entry. The following
  1228. symbols are recognized:
  1229. time-up Put entries with time-of-day indications first, early first
  1230. time-down Put entries with time-of-day indications first, late first
  1231. category-keep Keep the default order of categories, corresponding to the
  1232. sequence in `org-agenda-files'.
  1233. category-up Sort alphabetically by category, A-Z.
  1234. category-down Sort alphabetically by category, Z-A.
  1235. tag-up Sort alphabetically by last tag, A-Z.
  1236. tag-down Sort alphabetically by last tag, Z-A.
  1237. priority-up Sort numerically by priority, high priority last.
  1238. priority-down Sort numerically by priority, high priority first.
  1239. todo-state-up Sort by todo state, tasks that are done last.
  1240. todo-state-down Sort by todo state, tasks that are done first.
  1241. effort-up Sort numerically by estimated effort, high effort last.
  1242. effort-down Sort numerically by estimated effort, high effort first.
  1243. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1244. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1245. habit-up Put entries that are habits first
  1246. habit-down Put entries that are habits last
  1247. alpha-up Sort headlines alphabetically
  1248. alpha-down Sort headlines alphabetically, reversed
  1249. The different possibilities will be tried in sequence, and testing stops
  1250. if one comparison returns a \"not-equal\". For example, the default
  1251. '(time-up category-keep priority-down)
  1252. means: Pull out all entries having a specified time of day and sort them,
  1253. in order to make a time schedule for the current day the first thing in the
  1254. agenda listing for the day. Of the entries without a time indication, keep
  1255. the grouped in categories, don't sort the categories, but keep them in
  1256. the sequence given in `org-agenda-files'. Within each category sort by
  1257. priority.
  1258. Leaving out `category-keep' would mean that items will be sorted across
  1259. categories by priority.
  1260. Instead of a single list, this can also be a set of list for specific
  1261. contents, with a context symbol in the car of the list, any of
  1262. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1263. Custom commands can bind this variable in the options section."
  1264. :group 'org-agenda-sorting
  1265. :type `(choice
  1266. (repeat :tag "General" ,org-sorting-choice)
  1267. (list :tag "Individually"
  1268. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1269. (repeat ,org-sorting-choice))
  1270. (cons (const :tag "Strategy for TODO lists" todo)
  1271. (repeat ,org-sorting-choice))
  1272. (cons (const :tag "Strategy for Tags matches" tags)
  1273. (repeat ,org-sorting-choice))
  1274. (cons (const :tag "Strategy for search matches" search)
  1275. (repeat ,org-sorting-choice)))))
  1276. (defcustom org-agenda-cmp-user-defined nil
  1277. "A function to define the comparison `user-defined'.
  1278. This function must receive two arguments, agenda entry a and b.
  1279. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1280. the user comparison, return nil.
  1281. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1282. part of an agenda sorting strategy."
  1283. :group 'org-agenda-sorting
  1284. :type 'symbol)
  1285. (defcustom org-sort-agenda-notime-is-late t
  1286. "Non-nil means items without time are considered late.
  1287. This is only relevant for sorting. When t, items which have no explicit
  1288. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1289. do have a time. When nil, the default time is before 0:00. You can use this
  1290. option to decide if the schedule for today should come before or after timeless
  1291. agenda entries."
  1292. :group 'org-agenda-sorting
  1293. :type 'boolean)
  1294. (defcustom org-sort-agenda-noeffort-is-high t
  1295. "Non-nil means items without effort estimate are sorted as high effort.
  1296. This also applies when filtering an agenda view with respect to the
  1297. < or > effort operator. Then, tasks with no effort defined will be treated
  1298. as tasks with high effort.
  1299. When nil, such items are sorted as 0 minutes effort."
  1300. :group 'org-agenda-sorting
  1301. :type 'boolean)
  1302. (defgroup org-agenda-line-format nil
  1303. "Options concerning the entry prefix in the Org-mode agenda display."
  1304. :tag "Org Agenda Line Format"
  1305. :group 'org-agenda)
  1306. (defcustom org-agenda-prefix-format
  1307. '((agenda . " %i %-12:c%?-12t% s")
  1308. (timeline . " % s")
  1309. (todo . " %i %-12:c")
  1310. (tags . " %i %-12:c")
  1311. (search . " %i %-12:c"))
  1312. "Format specifications for the prefix of items in the agenda views.
  1313. An alist with five entries, each for the different agenda types. The
  1314. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1315. The values are format strings.
  1316. This format works similar to a printf format, with the following meaning:
  1317. %c the category of the item, \"Diary\" for entries from the diary,
  1318. or as given by the CATEGORY keyword or derived from the file name
  1319. %e the effort required by the item
  1320. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1321. %T the last tag of the item (ignore inherited tags, which come first)
  1322. %t the HH:MM time-of-day specification if one applies to the entry
  1323. %s Scheduling/Deadline information, a short string
  1324. %(expression) Eval EXPRESSION and replace the control string
  1325. by the result
  1326. All specifiers work basically like the standard `%s' of printf, but may
  1327. contain two additional characters: a question mark just after the `%'
  1328. and a whitespace/punctuation character just before the final letter.
  1329. If the first character after `%' is a question mark, the entire field
  1330. will only be included if the corresponding value applies to the current
  1331. entry. This is useful for fields which should have fixed width when
  1332. present, but zero width when absent. For example, \"%?-12t\" will
  1333. result in a 12 character time field if a time of the day is specified,
  1334. but will completely disappear in entries which do not contain a time.
  1335. If there is punctuation or whitespace character just before the final
  1336. format letter, this character will be appended to the field value if
  1337. the value is not empty. For example, the format \"%-12:c\" leads to
  1338. \"Diary: \" if the category is \"Diary\". If the category were be
  1339. empty, no additional colon would be inserted.
  1340. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1341. which means:
  1342. - Indent the line with two space characters
  1343. - Give the category a 12 chars wide field, padded with whitespace on
  1344. the right (because of `-'). Append a colon if there is a category
  1345. (because of `:').
  1346. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1347. time, don't put in an empty field, just skip it (because of '?').
  1348. - Finally, put the scheduling information.
  1349. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1350. `org-agenda-remove-tags'.
  1351. Custom commands can set this variable in the options section."
  1352. :type '(choice
  1353. (string :tag "General format")
  1354. (list :greedy t :tag "View dependent"
  1355. (cons (const agenda) (string :tag "Format"))
  1356. (cons (const timeline) (string :tag "Format"))
  1357. (cons (const todo) (string :tag "Format"))
  1358. (cons (const tags) (string :tag "Format"))
  1359. (cons (const search) (string :tag "Format"))))
  1360. :group 'org-agenda-line-format)
  1361. (defvar org-prefix-format-compiled nil
  1362. "The compiled prefix format and associated variables.
  1363. This is a list where first element is a list of variable bindings, and second
  1364. element is the compiled format expression. See the variable
  1365. `org-agenda-prefix-format'.")
  1366. (defcustom org-agenda-todo-keyword-format "%-1s"
  1367. "Format for the TODO keyword in agenda lines.
  1368. Set this to something like \"%-12s\" if you want all TODO keywords
  1369. to occupy a fixed space in the agenda display."
  1370. :group 'org-agenda-line-format
  1371. :type 'string)
  1372. (defcustom org-agenda-diary-sexp-prefix nil
  1373. "A regexp that matches part of a diary sexp entry
  1374. which should be treated as scheduling/deadline information in
  1375. `org-agenda'.
  1376. For example, you can use this to extract the `diary-remind-message' from
  1377. `diary-remind' entries."
  1378. :group 'org-agenda-line-format
  1379. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1380. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1381. "Text preceding timerange entries in the agenda view.
  1382. This is a list with two strings. The first applies when the range
  1383. is entirely on one day. The second applies if the range spans several days.
  1384. The strings may have two \"%d\" format specifiers which will be filled
  1385. with the sequence number of the days, and the total number of days in the
  1386. range, respectively."
  1387. :group 'org-agenda-line-format
  1388. :type '(list
  1389. (string :tag "Deadline today ")
  1390. (choice :tag "Deadline relative"
  1391. (string :tag "Format string")
  1392. (function))))
  1393. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1394. "Text preceding scheduled items in the agenda view.
  1395. This is a list with two strings. The first applies when the item is
  1396. scheduled on the current day. The second applies when it has been scheduled
  1397. previously, it may contain a %d indicating that this is the nth time that
  1398. this item is scheduled, due to automatic rescheduling of unfinished items
  1399. for the following day. So this number is one larger than the number of days
  1400. that passed since this item was scheduled first."
  1401. :group 'org-agenda-line-format
  1402. :type '(list
  1403. (string :tag "Scheduled today ")
  1404. (string :tag "Scheduled previously")))
  1405. (defcustom org-agenda-inactive-leader "["
  1406. "Text preceding item pulled into the agenda by inactive time stamps.
  1407. These entries are added to the agenda when pressing \"[\"."
  1408. :group 'org-agenda-line-format
  1409. :version "24.1"
  1410. :type '(list
  1411. (string :tag "Scheduled today ")
  1412. (string :tag "Scheduled previously")))
  1413. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1414. "Text preceding deadline items in the agenda view.
  1415. This is a list with two strings. The first applies when the item has its
  1416. deadline on the current day. The second applies when it is in the past or
  1417. in the future, it may contain %d to capture how many days away the deadline
  1418. is (was)."
  1419. :group 'org-agenda-line-format
  1420. :type '(list
  1421. (string :tag "Deadline today ")
  1422. (choice :tag "Deadline relative"
  1423. (string :tag "Format string")
  1424. (function))))
  1425. (defcustom org-agenda-remove-times-when-in-prefix t
  1426. "Non-nil means remove duplicate time specifications in agenda items.
  1427. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1428. time-of-day specification in a headline or diary entry is extracted and
  1429. placed into the prefix. If this option is non-nil, the original specification
  1430. \(a timestamp or -range, or just a plain time(range) specification like
  1431. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1432. cluttered.
  1433. The option can be t or nil. It may also be the symbol `beg', indicating
  1434. that the time should only be removed when it is located at the beginning of
  1435. the headline/diary entry."
  1436. :group 'org-agenda-line-format
  1437. :type '(choice
  1438. (const :tag "Always" t)
  1439. (const :tag "Never" nil)
  1440. (const :tag "When at beginning of entry" beg)))
  1441. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1442. "Non-nil means remove time ranges specifications in agenda
  1443. items that span on several days."
  1444. :group 'org-agenda-line-format
  1445. :version "24.1"
  1446. :type 'boolean)
  1447. (defcustom org-agenda-default-appointment-duration nil
  1448. "Default duration for appointments that only have a starting time.
  1449. When nil, no duration is specified in such cases.
  1450. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1451. :group 'org-agenda-line-format
  1452. :type '(choice
  1453. (integer :tag "Minutes")
  1454. (const :tag "No default duration")))
  1455. (defcustom org-agenda-show-inherited-tags t
  1456. "Non-nil means show inherited tags in each agenda line."
  1457. :group 'org-agenda-line-format
  1458. :type 'boolean)
  1459. (defcustom org-agenda-hide-tags-regexp nil
  1460. "Regular expression used to filter away specific tags in agenda views.
  1461. This means that these tags will be present, but not be shown in the agenda
  1462. line. Secondary filtering will still work on the hidden tags.
  1463. Nil means don't hide any tags."
  1464. :group 'org-agenda-line-format
  1465. :type '(choice
  1466. (const :tag "Hide none" nil)
  1467. (string :tag "Regexp ")))
  1468. (defcustom org-agenda-remove-tags nil
  1469. "Non-nil means remove the tags from the headline copy in the agenda.
  1470. When this is the symbol `prefix', only remove tags when
  1471. `org-agenda-prefix-format' contains a `%T' specifier."
  1472. :group 'org-agenda-line-format
  1473. :type '(choice
  1474. (const :tag "Always" t)
  1475. (const :tag "Never" nil)
  1476. (const :tag "When prefix format contains %T" prefix)))
  1477. (if (fboundp 'defvaralias)
  1478. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1479. 'org-agenda-remove-tags))
  1480. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1481. "Shift tags in agenda items to this column.
  1482. If this number is positive, it specifies the column. If it is negative,
  1483. it means that the tags should be flushright to that column. For example,
  1484. -80 works well for a normal 80 character screen."
  1485. :group 'org-agenda-line-format
  1486. :type 'integer)
  1487. (if (fboundp 'defvaralias)
  1488. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1489. (defcustom org-agenda-fontify-priorities 'cookies
  1490. "Non-nil means highlight low and high priorities in agenda.
  1491. When t, the highest priority entries are bold, lowest priority italic.
  1492. However, settings in `org-priority-faces' will overrule these faces.
  1493. When this variable is the symbol `cookies', only fontify the
  1494. cookies, not the entire task.
  1495. This may also be an association list of priority faces, whose
  1496. keys are the character values of `org-highest-priority',
  1497. `org-default-priority', and `org-lowest-priority' (the default values
  1498. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1499. color as a string, or a list like `(:background \"Red\")'.
  1500. If it is a color, the variable `org-faces-easy-properties'
  1501. determines if it is a foreground or a background color."
  1502. :group 'org-agenda-line-format
  1503. :type '(choice
  1504. (const :tag "Never" nil)
  1505. (const :tag "Defaults" t)
  1506. (const :tag "Cookies only" cookies)
  1507. (repeat :tag "Specify"
  1508. (list (character :tag "Priority" :value ?A)
  1509. (choice :tag "Face "
  1510. (string :tag "Color")
  1511. (sexp :tag "Face"))))))
  1512. (defcustom org-agenda-day-face-function nil
  1513. "Function called to determine what face should be used to display a day.
  1514. The only argument passed to that function is the day. It should
  1515. returns a face, or nil if does not want to specify a face and let
  1516. the normal rules apply."
  1517. :group 'org-agenda-line-format
  1518. :version "24.1"
  1519. :type 'function)
  1520. (defcustom org-agenda-category-icon-alist nil
  1521. "Alist of category icon to be displayed in agenda views.
  1522. Each entry should have the following format:
  1523. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1524. Where CATEGORY-REGEXP is a regexp matching the categories where
  1525. the icon should be displayed.
  1526. FILE-OR-DATA either a file path or a string containing image data.
  1527. The other fields can be omitted safely if not needed:
  1528. TYPE indicates the image type.
  1529. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1530. image data.
  1531. PROPS are additional image attributes to assign to the image,
  1532. like, e.g. `:ascent center'.
  1533. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1534. If you want to set the display properties yourself, just put a
  1535. list as second element:
  1536. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1537. For example, to display a 16px horizontal space for Emacs
  1538. category, you can use:
  1539. (\"Emacs\" '(space . (:width (16))))"
  1540. :group 'org-agenda-line-format
  1541. :version "24.1"
  1542. :type '(alist :key-type (string :tag "Regexp matching category")
  1543. :value-type (choice (list :tag "Icon"
  1544. (string :tag "File or data")
  1545. (symbol :tag "Type")
  1546. (boolean :tag "Data?")
  1547. (repeat :tag "Extra image properties" :inline t symbol))
  1548. (list :tag "Display properties" sexp))))
  1549. (defgroup org-agenda-column-view nil
  1550. "Options concerning column view in the agenda."
  1551. :tag "Org Agenda Column View"
  1552. :group 'org-agenda)
  1553. (defcustom org-agenda-columns-show-summaries t
  1554. "Non-nil means show summaries for columns displayed in the agenda view."
  1555. :group 'org-agenda-column-view
  1556. :type 'boolean)
  1557. (defcustom org-agenda-columns-compute-summary-properties t
  1558. "Non-nil means recompute all summary properties before column view.
  1559. When column view in the agenda is listing properties that have a summary
  1560. operator, it can go to all relevant buffers and recompute the summaries
  1561. there. This can mean overhead for the agenda column view, but is necessary
  1562. to have thing up to date.
  1563. As a special case, a CLOCKSUM property also makes sure that the clock
  1564. computations are current."
  1565. :group 'org-agenda-column-view
  1566. :type 'boolean)
  1567. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1568. "Non-nil means the duration of an appointment will add to day effort.
  1569. The property to which appointment durations will be added is the one given
  1570. in the option `org-effort-property'. If an appointment does not have
  1571. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1572. is not set, an appointment without end time will not contribute to the time
  1573. estimate."
  1574. :group 'org-agenda-column-view
  1575. :type 'boolean)
  1576. (defcustom org-agenda-auto-exclude-function nil
  1577. "A function called with a tag to decide if it is filtered on '/ RET'.
  1578. The sole argument to the function, which is called once for each
  1579. possible tag, is a string giving the name of the tag. The
  1580. function should return either nil if the tag should be included
  1581. as normal, or \"-<TAG>\" to exclude the tag.
  1582. Note that for the purpose of tag filtering, only the lower-case version of
  1583. all tags will be considered, so that this function will only ever see
  1584. the lower-case version of all tags."
  1585. :group 'org-agenda
  1586. :type 'function)
  1587. (defcustom org-agenda-bulk-custom-functions nil
  1588. "Alist of characters and custom functions for bulk actions.
  1589. For example, this value makes those two functions available:
  1590. '((?R set-category)
  1591. (?C bulk-cut))
  1592. With selected entries in an agenda buffer, `B R' will call
  1593. the custom function `set-category' on the selected entries.
  1594. Note that functions in this alist don't need to be quoted."
  1595. :type 'alist
  1596. :version "24.1"
  1597. :group 'org-agenda)
  1598. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1599. "Execute BODY with point at location given by `org-hd-marker' property.
  1600. If STRING is non-nil, the text property will be fetched from position 0
  1601. in that string. If STRING is nil, it will be fetched from the beginning
  1602. of the current line."
  1603. (org-with-gensyms (marker)
  1604. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1605. 'org-hd-marker ,string)))
  1606. (with-current-buffer (marker-buffer ,marker)
  1607. (save-excursion
  1608. (goto-char ,marker)
  1609. ,@body)))))
  1610. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1611. (defun org-add-agenda-custom-command (entry)
  1612. "Replace or add a command in `org-agenda-custom-commands'.
  1613. This is mostly for hacking and trying a new command - once the command
  1614. works you probably want to add it to `org-agenda-custom-commands' for good."
  1615. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1616. (if ass
  1617. (setcdr ass (cdr entry))
  1618. (push entry org-agenda-custom-commands))))
  1619. ;;; Define the org-agenda-mode
  1620. (defvar org-agenda-mode-map (make-sparse-keymap)
  1621. "Keymap for `org-agenda-mode'.")
  1622. (if (fboundp 'defvaralias)
  1623. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1624. (defvar org-agenda-menu) ; defined later in this file.
  1625. (defvar org-agenda-restrict nil) ; defined later in this file.
  1626. (defvar org-agenda-follow-mode nil)
  1627. (defvar org-agenda-entry-text-mode nil)
  1628. (defvar org-agenda-clockreport-mode nil)
  1629. (defvar org-agenda-show-log nil)
  1630. (defvar org-agenda-redo-command nil)
  1631. (defvar org-agenda-query-string nil)
  1632. (defvar org-agenda-mode-hook nil
  1633. "Hook run after `org-agenda-mode' is turned on.
  1634. The buffer is still writable when this hook is called.")
  1635. (defvar org-agenda-type nil)
  1636. (defvar org-agenda-force-single-file nil)
  1637. (defvar org-agenda-bulk-marked-entries nil
  1638. "List of markers that refer to marked entries in the agenda.")
  1639. ;;; Multiple agenda buffers support
  1640. (defcustom org-agenda-sticky nil
  1641. "Non-nil means agenda q key will bury agenda buffers.
  1642. Agenda commands will then show existing buffer instead of generating new ones.
  1643. When nil, `q' will kill the single agenda buffer."
  1644. :group 'org-agenda
  1645. :version "24.3"
  1646. :type 'boolean)
  1647. ;;;###autoload
  1648. (defun org-toggle-sticky-agenda (&optional arg)
  1649. "Toggle `org-agenda-sticky'."
  1650. (interactive "P")
  1651. (let ((new-value (if arg
  1652. (> (prefix-numeric-value arg) 0)
  1653. (not org-agenda-sticky))))
  1654. (if (equal new-value org-agenda-sticky)
  1655. (and (org-called-interactively-p 'interactive)
  1656. (message "Sticky agenda was already %s"
  1657. (if org-agenda-sticky "enabled" "disabled")))
  1658. (setq org-agenda-sticky new-value)
  1659. (org-agenda-kill-all-agenda-buffers)
  1660. (and (org-called-interactively-p 'interactive)
  1661. (message "Sticky agenda was %s"
  1662. (if org-agenda-sticky "enabled" "disabled"))))))
  1663. (autoload 'org-toggle-sticky-agenda "org-agenda" "\
  1664. Toggle `org-agenda-sticky'.
  1665. \(fn &optional ARG)" t nil)
  1666. (defvar org-agenda-buffer nil
  1667. "Agenda buffer currently being generated.")
  1668. (defvar org-agenda-last-prefix-arg nil)
  1669. (defvar org-agenda-this-buffer-name nil)
  1670. (defvar org-agenda-doing-sticky-redo nil)
  1671. (defvar org-agenda-this-buffer-is-sticky nil)
  1672. (defconst org-agenda-local-vars
  1673. '(org-agenda-this-buffer-name
  1674. org-agenda-undo-list
  1675. org-agenda-pending-undo-list
  1676. org-agenda-follow-mode
  1677. org-agenda-entry-text-mode
  1678. org-agenda-clockreport-mode
  1679. org-agenda-show-log
  1680. org-agenda-redo-command
  1681. org-agenda-query-string
  1682. org-agenda-type
  1683. org-agenda-bulk-marked-entries
  1684. org-agenda-undo-has-started-in
  1685. org-agenda-info
  1686. org-agenda-tag-filter-overlays
  1687. org-agenda-cat-filter-overlays
  1688. org-agenda-pre-window-conf
  1689. org-agenda-columns-active
  1690. org-agenda-tag-filter
  1691. org-agenda-category-filter
  1692. org-agenda-markers
  1693. org-agenda-last-search-view-search-was-boolean
  1694. org-agenda-filtered-by-category
  1695. org-agenda-filter-form
  1696. org-agenda-show-window
  1697. org-agenda-cycle-counter
  1698. org-agenda-last-prefix-arg)
  1699. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1700. (defun org-agenda-mode ()
  1701. "Mode for time-sorted view on action items in Org-mode files.
  1702. The following commands are available:
  1703. \\{org-agenda-mode-map}"
  1704. (interactive)
  1705. (cond (org-agenda-doing-sticky-redo
  1706. ;; Refreshing sticky agenda-buffer
  1707. ;;
  1708. ;; Preserve the value of `org-agenda-local-vars' variables,
  1709. ;; while letting `kill-all-local-variables' kill the rest
  1710. (let ((save (buffer-local-variables)))
  1711. (kill-all-local-variables)
  1712. (mapc 'make-local-variable org-agenda-local-vars)
  1713. (dolist (elem save)
  1714. (let ((var (car elem))
  1715. (val (cdr elem)))
  1716. (when (and val
  1717. (member var org-agenda-local-vars))
  1718. (set var val)))))
  1719. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1720. (org-agenda-sticky
  1721. ;; Creating a sticky Agenda buffer for the first time
  1722. (kill-all-local-variables)
  1723. (mapc 'make-local-variable org-agenda-local-vars)
  1724. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1725. (t
  1726. ;; Creating a non-sticky agenda buffer
  1727. (kill-all-local-variables)
  1728. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1729. (setq org-agenda-undo-list nil
  1730. org-agenda-pending-undo-list nil
  1731. org-agenda-bulk-marked-entries nil)
  1732. (setq major-mode 'org-agenda-mode)
  1733. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1734. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1735. (setq mode-name "Org-Agenda")
  1736. (use-local-map org-agenda-mode-map)
  1737. (easy-menu-add org-agenda-menu)
  1738. (if org-startup-truncated (setq truncate-lines t))
  1739. (org-set-local 'line-move-visual nil)
  1740. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1741. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1742. ;; Make sure properties are removed when copying text
  1743. (make-local-variable 'filter-buffer-substring-functions)
  1744. (add-hook 'filter-buffer-substring-functions
  1745. (lambda (fun start end delete)
  1746. (substring-no-properties (funcall fun start end delete))))
  1747. (unless org-agenda-keep-modes
  1748. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1749. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1750. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1751. org-agenda-show-log org-agenda-start-with-log-mode))
  1752. (easy-menu-change
  1753. '("Agenda") "Agenda Files"
  1754. (append
  1755. (list
  1756. (vector
  1757. (if (get 'org-agenda-files 'org-restrict)
  1758. "Restricted to single file"
  1759. "Edit File List")
  1760. '(org-edit-agenda-file-list)
  1761. (not (get 'org-agenda-files 'org-restrict)))
  1762. "--")
  1763. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1764. (org-agenda-set-mode-name)
  1765. (apply
  1766. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1767. (list 'org-agenda-mode-hook)))
  1768. (substitute-key-definition 'undo 'org-agenda-undo
  1769. org-agenda-mode-map global-map)
  1770. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1771. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1772. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1773. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1774. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1775. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1776. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1777. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1778. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1779. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1780. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1781. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1782. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1783. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1784. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1785. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1786. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1787. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1788. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1789. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1790. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1791. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1792. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1793. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1794. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1795. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1796. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1797. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1798. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1799. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1800. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1801. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1802. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1803. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1804. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1805. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1806. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1807. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1808. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1809. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1810. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1811. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1812. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1813. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1814. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1815. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1816. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1817. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1818. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1819. (while l (org-defkey org-agenda-mode-map
  1820. (int-to-string (pop l)) 'digit-argument)))
  1821. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1822. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1823. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1824. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1825. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1826. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1827. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1828. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1829. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1830. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1831. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1832. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1833. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1834. 'org-clock-modify-effort-estimate)
  1835. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1836. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1837. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1838. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1839. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1840. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1841. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1842. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1843. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1844. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1845. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1846. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1847. (substitute-key-definition 'next-line 'org-agenda-next-line
  1848. org-agenda-mode-map global-map)
  1849. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1850. org-agenda-mode-map global-map)
  1851. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1852. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1853. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1854. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1855. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1856. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1857. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1858. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1859. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1860. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1861. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1862. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1863. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1864. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1865. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1866. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1867. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1868. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1869. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1870. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1871. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1872. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1873. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1874. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1875. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1876. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1877. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1878. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1879. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1880. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1881. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1882. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1883. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1884. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1885. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1886. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1887. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1888. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1889. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1890. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1891. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1892. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1893. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1894. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1895. (when org-agenda-mouse-1-follows-link
  1896. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1897. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1898. '("Agenda"
  1899. ("Agenda Files")
  1900. "--"
  1901. ("Agenda Dates"
  1902. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1903. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1904. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1905. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1906. "--"
  1907. ("View"
  1908. ["Day View" org-agenda-day-view
  1909. :active (org-agenda-check-type nil 'agenda)
  1910. :style radio :selected (eq org-agenda-current-span 'day)
  1911. :keys "v d (or just d)"]
  1912. ["Week View" org-agenda-week-view
  1913. :active (org-agenda-check-type nil 'agenda)
  1914. :style radio :selected (eq org-agenda-current-span 'week)
  1915. :keys "v w (or just w)"]
  1916. ["Month View" org-agenda-month-view
  1917. :active (org-agenda-check-type nil 'agenda)
  1918. :style radio :selected (eq org-agenda-current-span 'month)
  1919. :keys "v m"]
  1920. ["Year View" org-agenda-year-view
  1921. :active (org-agenda-check-type nil 'agenda)
  1922. :style radio :selected (eq org-agenda-current-span 'year)
  1923. :keys "v y"]
  1924. "--"
  1925. ["Include Diary" org-agenda-toggle-diary
  1926. :style toggle :selected org-agenda-include-diary
  1927. :active (org-agenda-check-type nil 'agenda)]
  1928. ["Include Deadlines" org-agenda-toggle-deadlines
  1929. :style toggle :selected org-agenda-include-deadlines
  1930. :active (org-agenda-check-type nil 'agenda)]
  1931. ["Use Time Grid" org-agenda-toggle-time-grid
  1932. :style toggle :selected org-agenda-use-time-grid
  1933. :active (org-agenda-check-type nil 'agenda)]
  1934. "--"
  1935. ["Show clock report" org-agenda-clockreport-mode
  1936. :style toggle :selected org-agenda-clockreport-mode
  1937. :active (org-agenda-check-type nil 'agenda)]
  1938. ["Show some entry text" org-agenda-entry-text-mode
  1939. :style toggle :selected org-agenda-entry-text-mode
  1940. :active t]
  1941. "--"
  1942. ["Show Logbook entries" org-agenda-log-mode
  1943. :style toggle :selected org-agenda-show-log
  1944. :active (org-agenda-check-type nil 'agenda 'timeline)
  1945. :keys "v l (or just l)"]
  1946. ["Include archived trees" org-agenda-archives-mode
  1947. :style toggle :selected org-agenda-archives-mode :active t
  1948. :keys "v a"]
  1949. ["Include archive files" (org-agenda-archives-mode t)
  1950. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1951. :keys "v A"]
  1952. "--"
  1953. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1954. ["Write view to file" org-agenda-write t]
  1955. ["Rebuild buffer" org-agenda-redo t]
  1956. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1957. "--"
  1958. ["Show original entry" org-agenda-show t]
  1959. ["Go To (other window)" org-agenda-goto t]
  1960. ["Go To (this window)" org-agenda-switch-to t]
  1961. ["Capture with cursor date" org-agenda-capture t]
  1962. ["Follow Mode" org-agenda-follow-mode
  1963. :style toggle :selected org-agenda-follow-mode :active t]
  1964. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1965. "--"
  1966. ("TODO"
  1967. ["Cycle TODO" org-agenda-todo t]
  1968. ["Next TODO set" org-agenda-todo-nextset t]
  1969. ["Previous TODO set" org-agenda-todo-previousset t]
  1970. ["Add note" org-agenda-add-note t])
  1971. ("Archive/Refile/Delete"
  1972. ["Archive default" org-agenda-archive-default t]
  1973. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1974. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1975. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1976. ["Archive subtree" org-agenda-archive t]
  1977. "--"
  1978. ["Refile" org-agenda-refile t]
  1979. "--"
  1980. ["Delete subtree" org-agenda-kill t])
  1981. ("Bulk action"
  1982. ["Mark entry" org-agenda-bulk-mark t]
  1983. ["Mark all" org-agenda-bulk-mark-all t]
  1984. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1985. ["Unmark entry" org-agenda-bulk-unmark t]
  1986. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  1987. ["Act on all marked" org-agenda-bulk-action t]
  1988. "--"
  1989. ("Tags and Properties"
  1990. ["Show all Tags" org-agenda-show-tags t]
  1991. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1992. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1993. "--"
  1994. ["Column View" org-columns t])
  1995. ("Deadline/Schedule"
  1996. ["Schedule" org-agenda-schedule t]
  1997. ["Set Deadline" org-agenda-deadline t]
  1998. "--"
  1999. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2000. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2001. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2002. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2003. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2004. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2005. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2006. ("Clock and Effort"
  2007. ["Clock in" org-agenda-clock-in t]
  2008. ["Clock out" org-agenda-clock-out t]
  2009. ["Clock cancel" org-agenda-clock-cancel t]
  2010. ["Goto running clock" org-clock-goto t]
  2011. "--"
  2012. ["Set Effort" org-agenda-set-effort t]
  2013. ["Change clocked effort" org-clock-modify-effort-estimate
  2014. (org-clock-is-active)])
  2015. ("Priority"
  2016. ["Set Priority" org-agenda-priority t]
  2017. ["Increase Priority" org-agenda-priority-up t]
  2018. ["Decrease Priority" org-agenda-priority-down t]
  2019. ["Show Priority" org-show-priority t])
  2020. ("Calendar/Diary"
  2021. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2022. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2023. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2024. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2025. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2026. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2027. "--"
  2028. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2029. "--"
  2030. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2031. "--"
  2032. ("MobileOrg"
  2033. ["Push Files and Views" org-mobile-push t]
  2034. ["Get Captured and Flagged" org-mobile-pull t]
  2035. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2036. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2037. "--"
  2038. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2039. "--"
  2040. ["Quit" org-agenda-quit t]
  2041. ["Exit and Release Buffers" org-agenda-exit t]
  2042. ))
  2043. ;;; Agenda undo
  2044. (defvar org-agenda-allow-remote-undo t
  2045. "Non-nil means allow remote undo from the agenda buffer.")
  2046. (defvar org-agenda-undo-has-started-in nil
  2047. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2048. (defun org-agenda-undo ()
  2049. "Undo a remote editing step in the agenda.
  2050. This undoes changes both in the agenda buffer and in the remote buffer
  2051. that have been changed along."
  2052. (interactive)
  2053. (or org-agenda-allow-remote-undo
  2054. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2055. (if (not (eq this-command last-command))
  2056. (setq org-agenda-undo-has-started-in nil
  2057. org-agenda-pending-undo-list org-agenda-undo-list))
  2058. (if (not org-agenda-pending-undo-list)
  2059. (error "No further undo information"))
  2060. (let* ((entry (pop org-agenda-pending-undo-list))
  2061. buf line cmd rembuf)
  2062. (setq cmd (pop entry) line (pop entry))
  2063. (setq rembuf (nth 2 entry))
  2064. (org-with-remote-undo rembuf
  2065. (while (bufferp (setq buf (pop entry)))
  2066. (if (pop entry)
  2067. (with-current-buffer buf
  2068. (let ((last-undo-buffer buf)
  2069. (inhibit-read-only t))
  2070. (unless (memq buf org-agenda-undo-has-started-in)
  2071. (push buf org-agenda-undo-has-started-in)
  2072. (make-local-variable 'pending-undo-list)
  2073. (undo-start))
  2074. (while (and pending-undo-list
  2075. (listp pending-undo-list)
  2076. (not (car pending-undo-list)))
  2077. (pop pending-undo-list))
  2078. (undo-more 1))))))
  2079. (org-goto-line line)
  2080. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2081. (defun org-verify-change-for-undo (l1 l2)
  2082. "Verify that a real change occurred between the undo lists L1 and L2."
  2083. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2084. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2085. (not (eq l1 l2)))
  2086. ;;; Agenda dispatch
  2087. (defvar org-agenda-restrict-begin (make-marker))
  2088. (defvar org-agenda-restrict-end (make-marker))
  2089. (defvar org-agenda-last-dispatch-buffer nil)
  2090. (defvar org-agenda-overriding-restriction nil)
  2091. (defcustom org-agenda-custom-commands-contexts nil
  2092. "Alist of custom agenda keys and contextual rules.
  2093. For example, if you have a custom agenda command \"p\" and you
  2094. want this command to be accessible only from plain text files,
  2095. use this:
  2096. '((\"p\" (in-file . \"\\.txt\")))
  2097. Here are the available contexts definitions:
  2098. in-file: command displayed only in matching files
  2099. in-mode: command displayed only in matching modes
  2100. not-in-file: command not displayed in matching files
  2101. not-in-mode: command not displayed in matching modes
  2102. [function]: a custom function taking no argument
  2103. If you define several checks, the agenda command will be
  2104. accessible if there is at least one valid check.
  2105. You can also bind a key to another agenda custom command
  2106. depending on contextual rules.
  2107. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2108. Here it means: in .txt files, use \"p\" as the key for the
  2109. agenda command otherwise associated with \"q\". (The command
  2110. originally associated with \"q\" is not displayed to avoid
  2111. duplicates.)"
  2112. :version "24.3"
  2113. :group 'org-agenda-custom-commands
  2114. :type '(repeat (list :tag "Rule"
  2115. (string :tag " Agenda key")
  2116. (string :tag "Replace by command")
  2117. (repeat :tag "Available when"
  2118. (choice
  2119. (cons :tag "Condition"
  2120. (choice
  2121. (const :tag "In file" in-file)
  2122. (const :tag "Not in file" not-in-file)
  2123. (const :tag "In mode" in-mode)
  2124. (const :tag "Not in mode" not-in-mode))
  2125. (regexp))
  2126. (function :tag "Custom function"))))))
  2127. (defvar org-keys nil)
  2128. (defvar org-match nil)
  2129. ;;;###autoload
  2130. (defun org-agenda (&optional arg org-keys restriction)
  2131. "Dispatch agenda commands to collect entries to the agenda buffer.
  2132. Prompts for a command to execute. Any prefix arg will be passed
  2133. on to the selected command. The default selections are:
  2134. a Call `org-agenda-list' to display the agenda for current day or week.
  2135. t Call `org-todo-list' to display the global todo list.
  2136. T Call `org-todo-list' to display the global todo list, select only
  2137. entries with a specific TODO keyword (the user gets a prompt).
  2138. m Call `org-tags-view' to display headlines with tags matching
  2139. a condition (the user is prompted for the condition).
  2140. M Like `m', but select only TODO entries, no ordinary headlines.
  2141. L Create a timeline for the current buffer.
  2142. e Export views to associated files.
  2143. s Search entries for keywords.
  2144. S Search entries for keywords, only with TODO keywords.
  2145. / Multi occur across all agenda files and also files listed
  2146. in `org-agenda-text-search-extra-files'.
  2147. < Restrict agenda commands to buffer, subtree, or region.
  2148. Press several times to get the desired effect.
  2149. > Remove a previous restriction.
  2150. # List \"stuck\" projects.
  2151. ! Configure what \"stuck\" means.
  2152. C Configure custom agenda commands.
  2153. More commands can be added by configuring the variable
  2154. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2155. searches can be pre-defined in this way.
  2156. If the current buffer is in Org-mode and visiting a file, you can also
  2157. first press `<' once to indicate that the agenda should be temporarily
  2158. \(until the next use of \\[org-agenda]) restricted to the current file.
  2159. Pressing `<' twice means to restrict to the current subtree or region
  2160. \(if active)."
  2161. (interactive "P")
  2162. (catch 'exit
  2163. (let* ((prefix-descriptions nil)
  2164. (org-agenda-buffer-name org-agenda-buffer-name)
  2165. (org-agenda-window-setup (if (equal (buffer-name)
  2166. org-agenda-buffer-name)
  2167. 'current-window
  2168. org-agenda-window-setup))
  2169. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2170. (org-agenda-custom-commands
  2171. ;; normalize different versions
  2172. (delq nil
  2173. (mapcar
  2174. (lambda (x)
  2175. (cond ((stringp (cdr x))
  2176. (push x prefix-descriptions)
  2177. nil)
  2178. ((stringp (nth 1 x)) x)
  2179. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2180. (t (cons (car x) (cons "" (cdr x))))))
  2181. org-agenda-custom-commands)))
  2182. (org-agenda-custom-commands
  2183. (org-contextualize-keys
  2184. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2185. (buf (current-buffer))
  2186. (bfn (buffer-file-name (buffer-base-buffer)))
  2187. entry key type org-match lprops ans)
  2188. ;; Turn off restriction unless there is an overriding one,
  2189. (unless org-agenda-overriding-restriction
  2190. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2191. ;; There is a request to keep the file list in place
  2192. (put 'org-agenda-files 'org-restrict nil))
  2193. (setq org-agenda-restrict nil)
  2194. (move-marker org-agenda-restrict-begin nil)
  2195. (move-marker org-agenda-restrict-end nil))
  2196. ;; Delete old local properties
  2197. (put 'org-agenda-redo-command 'org-lprops nil)
  2198. ;; Delete previously set last-arguments
  2199. (put 'org-agenda-redo-command 'last-args nil)
  2200. ;; Remember where this call originated
  2201. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2202. (unless org-keys
  2203. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2204. org-keys (car ans)
  2205. restriction (cdr ans)))
  2206. ;; If we have sticky agenda buffers, set a name for the buffer,
  2207. ;; depending on the invoking keys. The user may still set this
  2208. ;; as a command option, which will overwrite what we do here.
  2209. (if org-agenda-sticky
  2210. (setq org-agenda-buffer-name
  2211. (format "*Org Agenda(%s)*" org-keys)))
  2212. ;; Establish the restriction, if any
  2213. (when (and (not org-agenda-overriding-restriction) restriction)
  2214. (put 'org-agenda-files 'org-restrict (list bfn))
  2215. (cond
  2216. ((eq restriction 'region)
  2217. (setq org-agenda-restrict t)
  2218. (move-marker org-agenda-restrict-begin (region-beginning))
  2219. (move-marker org-agenda-restrict-end (region-end)))
  2220. ((eq restriction 'subtree)
  2221. (save-excursion
  2222. (setq org-agenda-restrict t)
  2223. (org-back-to-heading t)
  2224. (move-marker org-agenda-restrict-begin (point))
  2225. (move-marker org-agenda-restrict-end
  2226. (progn (org-end-of-subtree t)))))))
  2227. ;; For example the todo list should not need it (but does...)
  2228. (cond
  2229. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2230. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2231. (progn
  2232. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2233. lprops (nth 4 entry))
  2234. (if org-agenda-sticky
  2235. (setq org-agenda-buffer-name
  2236. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2237. (format "*Org Agenda(%s)*" org-keys))))
  2238. (put 'org-agenda-redo-command 'org-lprops lprops)
  2239. (cond
  2240. ((eq type 'agenda)
  2241. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2242. ((eq type 'alltodo)
  2243. (org-let lprops '(org-todo-list current-prefix-arg)))
  2244. ((eq type 'search)
  2245. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2246. ((eq type 'stuck)
  2247. (org-let lprops '(org-agenda-list-stuck-projects
  2248. current-prefix-arg)))
  2249. ((eq type 'tags)
  2250. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2251. ((eq type 'tags-todo)
  2252. (org-let lprops '(org-tags-view '(4) org-match)))
  2253. ((eq type 'todo)
  2254. (org-let lprops '(org-todo-list org-match)))
  2255. ((eq type 'tags-tree)
  2256. (org-check-for-org-mode)
  2257. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2258. ((eq type 'todo-tree)
  2259. (org-check-for-org-mode)
  2260. (org-let lprops
  2261. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2262. (regexp-quote org-match) "\\>"))))
  2263. ((eq type 'occur-tree)
  2264. (org-check-for-org-mode)
  2265. (org-let lprops '(org-occur org-match)))
  2266. ((functionp type)
  2267. (org-let lprops '(funcall type org-match)))
  2268. ((fboundp type)
  2269. (org-let lprops '(funcall type org-match)))
  2270. (t (error "Invalid custom agenda command type %s" type))))
  2271. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2272. ((equal org-keys "C")
  2273. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2274. (customize-variable 'org-agenda-custom-commands))
  2275. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2276. ((equal org-keys "s") (call-interactively 'org-search-view))
  2277. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2278. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2279. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2280. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2281. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2282. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2283. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2284. (org-add-hook
  2285. 'post-command-hook
  2286. (lambda ()
  2287. (unless (current-message)
  2288. (let* ((m (org-agenda-get-any-marker))
  2289. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2290. (when note
  2291. (message (concat
  2292. "FLAGGING-NOTE ([?] for more info): "
  2293. (org-add-props
  2294. (replace-regexp-in-string
  2295. "\\\\n" "//"
  2296. (copy-sequence note))
  2297. nil 'face 'org-warning)))))))
  2298. t t))
  2299. ((equal org-keys "L")
  2300. (unless (derived-mode-p 'org-mode)
  2301. (error "This is not an Org-mode file"))
  2302. (unless restriction
  2303. (put 'org-agenda-files 'org-restrict (list bfn))
  2304. (org-call-with-arg 'org-timeline arg)))
  2305. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2306. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2307. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2308. (t (error "Invalid agenda key"))))))
  2309. (autoload 'org-agenda "org-agenda" "\
  2310. Dispatch agenda commands to collect entries to the agenda buffer.
  2311. Prompts for a command to execute. Any prefix arg will be passed
  2312. on to the selected command. The default selections are:
  2313. a Call `org-agenda-list' to display the agenda for current day or week.
  2314. t Call `org-todo-list' to display the global todo list.
  2315. T Call `org-todo-list' to display the global todo list, select only
  2316. entries with a specific TODO keyword (the user gets a prompt).
  2317. m Call `org-tags-view' to display headlines with tags matching
  2318. a condition (the user is prompted for the condition).
  2319. M Like `m', but select only TODO entries, no ordinary headlines.
  2320. L Create a timeline for the current buffer.
  2321. e Export views to associated files.
  2322. s Search entries for keywords.
  2323. S Search entries for keywords, only with TODO keywords.
  2324. / Multi occur across all agenda files and also files listed
  2325. in `org-agenda-text-search-extra-files'.
  2326. < Restrict agenda commands to buffer, subtree, or region.
  2327. Press several times to get the desired effect.
  2328. > Remove a previous restriction.
  2329. # List \"stuck\" projects.
  2330. ! Configure what \"stuck\" means.
  2331. C Configure custom agenda commands.
  2332. More commands can be added by configuring the variable
  2333. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2334. searches can be pre-defined in this way.
  2335. If the current buffer is in Org-mode and visiting a file, you can also
  2336. first press `<' once to indicate that the agenda should be temporarily
  2337. \(until the next use of \\[org-agenda]) restricted to the current file.
  2338. Pressing `<' twice means to restrict to the current subtree or region
  2339. \(if active).
  2340. \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
  2341. (defun org-agenda-append-agenda ()
  2342. "Append another agenda view to the current one.
  2343. This function allows interactive building of block agendas.
  2344. Agenda views are separated by `org-agenda-block-separator'."
  2345. (interactive)
  2346. (unless (derived-mode-p 'org-agenda-mode)
  2347. (error "Can only append from within agenda buffer"))
  2348. (let ((org-agenda-multi t))
  2349. (org-agenda)
  2350. (widen)
  2351. (org-agenda-finalize)
  2352. (org-agenda-fit-window-to-buffer)))
  2353. (defun org-agenda-normalize-custom-commands (cmds)
  2354. (delq nil
  2355. (mapcar
  2356. (lambda (x)
  2357. (cond ((stringp (cdr x)) nil)
  2358. ((stringp (nth 1 x)) x)
  2359. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2360. (t (cons (car x) (cons "" (cdr x))))))
  2361. cmds)))
  2362. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2363. "The user interface for selecting an agenda command."
  2364. (catch 'exit
  2365. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2366. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2367. (region-p (org-region-active-p))
  2368. (custom org-agenda-custom-commands)
  2369. (selstring "")
  2370. restriction second-time
  2371. c entry key type match prefixes rmheader header-end custom1 desc
  2372. line lines left right n n1)
  2373. (save-window-excursion
  2374. (delete-other-windows)
  2375. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2376. (erase-buffer)
  2377. (insert (eval-when-compile
  2378. (let ((header
  2379. "Press key for an agenda command: < Buffer, subtree/region restriction
  2380. -------------------------------- > Remove restriction
  2381. a Agenda for current week or day e Export agenda views
  2382. t List of all TODO entries T Entries with special TODO kwd
  2383. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2384. s Search for keywords S Like s, but only TODO entries
  2385. L Timeline for current buffer # List stuck projects (!=configure)
  2386. / Multi-occur C Configure custom agenda commands
  2387. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2388. ")
  2389. (start 0))
  2390. (while (string-match
  2391. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2392. header start)
  2393. (setq start (match-end 0))
  2394. (add-text-properties (match-beginning 2) (match-end 2)
  2395. '(face bold) header))
  2396. header)))
  2397. (setq header-end (point-marker))
  2398. (while t
  2399. (setq custom1 custom)
  2400. (when (eq rmheader t)
  2401. (org-goto-line 1)
  2402. (re-search-forward ":" nil t)
  2403. (delete-region (match-end 0) (point-at-eol))
  2404. (forward-char 1)
  2405. (looking-at "-+")
  2406. (delete-region (match-end 0) (point-at-eol))
  2407. (move-marker header-end (match-end 0)))
  2408. (goto-char header-end)
  2409. (delete-region (point) (point-max))
  2410. ;; Produce all the lines that describe custom commands and prefixes
  2411. (setq lines nil)
  2412. (while (setq entry (pop custom1))
  2413. (setq key (car entry) desc (nth 1 entry)
  2414. type (nth 2 entry)
  2415. match (nth 3 entry))
  2416. (if (> (length key) 1)
  2417. (add-to-list 'prefixes (string-to-char key))
  2418. (setq line
  2419. (format
  2420. "%-4s%-14s"
  2421. (org-add-props (copy-sequence key)
  2422. '(face bold))
  2423. (cond
  2424. ((string-match "\\S-" desc) desc)
  2425. ((eq type 'agenda) "Agenda for current week or day")
  2426. ((eq type 'alltodo) "List of all TODO entries")
  2427. ((eq type 'search) "Word search")
  2428. ((eq type 'stuck) "List of stuck projects")
  2429. ((eq type 'todo) "TODO keyword")
  2430. ((eq type 'tags) "Tags query")
  2431. ((eq type 'tags-todo) "Tags (TODO)")
  2432. ((eq type 'tags-tree) "Tags tree")
  2433. ((eq type 'todo-tree) "TODO kwd tree")
  2434. ((eq type 'occur-tree) "Occur tree")
  2435. ((functionp type) (if (symbolp type)
  2436. (symbol-name type)
  2437. "Lambda expression"))
  2438. (t "???"))))
  2439. (if org-agenda-menu-show-matcher
  2440. (setq line
  2441. (concat line ": "
  2442. (cond
  2443. ((stringp match)
  2444. (setq match (copy-sequence match))
  2445. (org-add-props match nil 'face 'org-warning))
  2446. ((listp type)
  2447. (format "set of %d commands" (length type))))))
  2448. (if (org-string-nw-p match)
  2449. (add-text-properties
  2450. 0 (length line) (list 'help-echo
  2451. (concat "Matcher: " match)) line)))
  2452. (push line lines)))
  2453. (setq lines (nreverse lines))
  2454. (when prefixes
  2455. (mapc (lambda (x)
  2456. (push
  2457. (format "%s %s"
  2458. (org-add-props (char-to-string x)
  2459. nil 'face 'bold)
  2460. (or (cdr (assoc (concat selstring
  2461. (char-to-string x))
  2462. prefix-descriptions))
  2463. "Prefix key"))
  2464. lines))
  2465. prefixes))
  2466. ;; Check if we should display in two columns
  2467. (if org-agenda-menu-two-columns
  2468. (progn
  2469. (setq n (length lines)
  2470. n1 (+ (/ n 2) (mod n 2))
  2471. right (nthcdr n1 lines)
  2472. left (copy-sequence lines))
  2473. (setcdr (nthcdr (1- n1) left) nil))
  2474. (setq left lines right nil))
  2475. (while left
  2476. (insert "\n" (pop left))
  2477. (when right
  2478. (if (< (current-column) 40)
  2479. (move-to-column 40 t)
  2480. (insert " "))
  2481. (insert (pop right))))
  2482. ;; Make the window the right size
  2483. (goto-char (point-min))
  2484. (if second-time
  2485. (if (not (pos-visible-in-window-p (point-max)))
  2486. (org-fit-window-to-buffer))
  2487. (setq second-time t)
  2488. (org-fit-window-to-buffer))
  2489. ;; Ask for selection
  2490. (message "Press key for agenda command%s:"
  2491. (if (or restrict-ok org-agenda-overriding-restriction)
  2492. (if org-agenda-overriding-restriction
  2493. " (restriction lock active)"
  2494. (if restriction
  2495. (format " (restricted to %s)" restriction)
  2496. " (unrestricted)"))
  2497. ""))
  2498. (setq c (read-char-exclusive))
  2499. (message "")
  2500. (cond
  2501. ((assoc (char-to-string c) custom)
  2502. (setq selstring (concat selstring (char-to-string c)))
  2503. (throw 'exit (cons selstring restriction)))
  2504. ((memq c prefixes)
  2505. (setq selstring (concat selstring (char-to-string c))
  2506. prefixes nil
  2507. rmheader (or rmheader t)
  2508. custom (delq nil (mapcar
  2509. (lambda (x)
  2510. (if (or (= (length (car x)) 1)
  2511. (/= (string-to-char (car x)) c))
  2512. nil
  2513. (cons (substring (car x) 1) (cdr x))))
  2514. custom))))
  2515. ((eq c ?*)
  2516. (call-interactively 'org-toggle-sticky-agenda)
  2517. (sit-for 2))
  2518. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2519. (message "Restriction is only possible in Org-mode buffers")
  2520. (ding) (sit-for 1))
  2521. ((eq c ?1)
  2522. (org-agenda-remove-restriction-lock 'noupdate)
  2523. (setq restriction 'buffer))
  2524. ((eq c ?0)
  2525. (org-agenda-remove-restriction-lock 'noupdate)
  2526. (setq restriction (if region-p 'region 'subtree)))
  2527. ((eq c ?<)
  2528. (org-agenda-remove-restriction-lock 'noupdate)
  2529. (setq restriction
  2530. (cond
  2531. ((eq restriction 'buffer)
  2532. (if region-p 'region 'subtree))
  2533. ((memq restriction '(subtree region))
  2534. nil)
  2535. (t 'buffer))))
  2536. ((eq c ?>)
  2537. (org-agenda-remove-restriction-lock 'noupdate)
  2538. (setq restriction nil))
  2539. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2540. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2541. ((and (> (length selstring) 0) (eq c ?\d))
  2542. (delete-window)
  2543. (org-agenda-get-restriction-and-command prefix-descriptions))
  2544. ((equal c ?q) (error "Abort"))
  2545. (t (error "Invalid key %c" c))))))))
  2546. (defun org-agenda-fit-window-to-buffer ()
  2547. "Fit the window to the buffer size."
  2548. (and (memq org-agenda-window-setup '(reorganize-frame))
  2549. (fboundp 'fit-window-to-buffer)
  2550. (org-fit-window-to-buffer
  2551. nil
  2552. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2553. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2554. (defvar org-cmd nil)
  2555. (defvar org-agenda-overriding-cmd nil)
  2556. (defvar org-agenda-overriding-arguments nil)
  2557. (defvar org-agenda-overriding-cmd-arguments nil)
  2558. (defun org-agenda-run-series (name series)
  2559. (org-let (nth 1 series) '(org-agenda-prepare name))
  2560. ;; We need to reset agenda markers here, because when constructing a
  2561. ;; block agenda, the individual blocks do not do that.
  2562. (org-agenda-reset-markers)
  2563. (let* ((org-agenda-multi t)
  2564. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2565. (cmds (car series))
  2566. (gprops (nth 1 series))
  2567. match ;; The byte compiler incorrectly complains about this. Keep it!
  2568. org-cmd type lprops)
  2569. (while (setq org-cmd (pop cmds))
  2570. (setq type (car org-cmd)
  2571. match (eval (nth 1 org-cmd))
  2572. lprops (nth 2 org-cmd))
  2573. (let ((org-agenda-overriding-arguments
  2574. (if (eq org-agenda-overriding-cmd org-cmd)
  2575. (or org-agenda-overriding-arguments
  2576. org-agenda-overriding-cmd-arguments))))
  2577. (cond
  2578. ((eq type 'agenda)
  2579. (org-let2 gprops lprops
  2580. '(call-interactively 'org-agenda-list)))
  2581. ((eq type 'alltodo)
  2582. (org-let2 gprops lprops
  2583. '(call-interactively 'org-todo-list)))
  2584. ((eq type 'search)
  2585. (org-let2 gprops lprops
  2586. '(org-search-view current-prefix-arg match nil)))
  2587. ((eq type 'stuck)
  2588. (org-let2 gprops lprops
  2589. '(call-interactively 'org-agenda-list-stuck-projects)))
  2590. ((eq type 'tags)
  2591. (org-let2 gprops lprops
  2592. '(org-tags-view current-prefix-arg match)))
  2593. ((eq type 'tags-todo)
  2594. (org-let2 gprops lprops
  2595. '(org-tags-view '(4) match)))
  2596. ((eq type 'todo)
  2597. (org-let2 gprops lprops
  2598. '(org-todo-list match)))
  2599. ((fboundp type)
  2600. (org-let2 gprops lprops
  2601. '(funcall type match)))
  2602. (t (error "Invalid type in command series")))))
  2603. (widen)
  2604. (let ((inhibit-read-only t))
  2605. (add-text-properties (point-min) (point-max)
  2606. `(org-series t org-series-redo-cmd ,redo)))
  2607. (setq org-agenda-redo-command redo)
  2608. (goto-char (point-min)))
  2609. (org-agenda-fit-window-to-buffer)
  2610. (org-let (nth 1 series) '(org-agenda-finalize)))
  2611. ;;;###autoload
  2612. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2613. "Run an agenda command in batch mode and send the result to STDOUT.
  2614. If CMD-KEY is a string of length 1, it is used as a key in
  2615. `org-agenda-custom-commands' and triggers this command. If it is a
  2616. longer string it is used as a tags/todo match string.
  2617. Parameters are alternating variable names and values that will be bound
  2618. before running the agenda command."
  2619. (org-eval-in-environment (org-make-parameter-alist parameters)
  2620. (if (> (length cmd-key) 2)
  2621. (org-tags-view nil cmd-key)
  2622. (org-agenda nil cmd-key)))
  2623. (set-buffer org-agenda-buffer-name)
  2624. (princ (buffer-string)))
  2625. (autoload 'org-batch-agenda "org-agenda" "\
  2626. Run an agenda command in batch mode and send the result to STDOUT.
  2627. If CMD-KEY is a string of length 1, it is used as a key in
  2628. `org-agenda-custom-commands' and triggers this command. If it is a
  2629. longer string it is used as a tags/todo match string.
  2630. Parameters are alternating variable names and values that will be bound
  2631. before running the agenda command.
  2632. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2633. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2634. (defvar org-agenda-info nil)
  2635. ;;;###autoload
  2636. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2637. "Run an agenda command in batch mode and send the result to STDOUT.
  2638. If CMD-KEY is a string of length 1, it is used as a key in
  2639. `org-agenda-custom-commands' and triggers this command. If it is a
  2640. longer string it is used as a tags/todo match string.
  2641. Parameters are alternating variable names and values that will be bound
  2642. before running the agenda command.
  2643. The output gives a line for each selected agenda item. Each
  2644. item is a list of comma-separated values, like this:
  2645. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2646. category The category of the item
  2647. head The headline, without TODO kwd, TAGS and PRIORITY
  2648. type The type of the agenda entry, can be
  2649. todo selected in TODO match
  2650. tagsmatch selected in tags match
  2651. diary imported from diary
  2652. deadline a deadline on given date
  2653. scheduled scheduled on given date
  2654. timestamp entry has timestamp on given date
  2655. closed entry was closed on given date
  2656. upcoming-deadline warning about deadline
  2657. past-scheduled forwarded scheduled item
  2658. block entry has date block including g. date
  2659. todo The todo keyword, if any
  2660. tags All tags including inherited ones, separated by colons
  2661. date The relevant date, like 2007-2-14
  2662. time The time, like 15:00-16:50
  2663. extra Sting with extra planning info
  2664. priority-l The priority letter if any was given
  2665. priority-n The computed numerical priority
  2666. agenda-day The day in the agenda where this is listed"
  2667. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2668. (org-make-parameter-alist parameters))
  2669. (if (> (length cmd-key) 2)
  2670. (org-tags-view nil cmd-key)
  2671. (org-agenda nil cmd-key)))
  2672. (set-buffer org-agenda-buffer-name)
  2673. (let* ((lines (org-split-string (buffer-string) "\n"))
  2674. line)
  2675. (while (setq line (pop lines))
  2676. (catch 'next
  2677. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2678. (setq org-agenda-info
  2679. (org-fix-agenda-info (text-properties-at 0 line)))
  2680. (princ
  2681. (mapconcat 'org-agenda-export-csv-mapper
  2682. '(org-category txt type todo tags date time extra
  2683. priority-letter priority agenda-day)
  2684. ","))
  2685. (princ "\n")))))
  2686. (autoload 'org-batch-agenda-csv "org-agenda" "\
  2687. Run an agenda command in batch mode and send the result to STDOUT.
  2688. If CMD-KEY is a string of length 1, it is used as a key in
  2689. `org-agenda-custom-commands' and triggers this command. If it is a
  2690. longer string it is used as a tags/todo match string.
  2691. Parameters are alternating variable names and values that will be bound
  2692. before running the agenda command.
  2693. The output gives a line for each selected agenda item. Each
  2694. item is a list of comma-separated values, like this:
  2695. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2696. category The category of the item
  2697. head The headline, without TODO kwd, TAGS and PRIORITY
  2698. type The type of the agenda entry, can be
  2699. todo selected in TODO match
  2700. tagsmatch selected in tags match
  2701. diary imported from diary
  2702. deadline a deadline on given date
  2703. scheduled scheduled on given date
  2704. timestamp entry has timestamp on given date
  2705. closed entry was closed on given date
  2706. upcoming-deadline warning about deadline
  2707. past-scheduled forwarded scheduled item
  2708. block entry has date block including g. date
  2709. todo The todo keyword, if any
  2710. tags All tags including inherited ones, separated by colons
  2711. date The relevant date, like 2007-2-14
  2712. time The time, like 15:00-16:50
  2713. extra Sting with extra planning info
  2714. priority-l The priority letter if any was given
  2715. priority-n The computed numerical priority
  2716. agenda-day The day in the agenda where this is listed
  2717. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2718. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2719. (defun org-fix-agenda-info (props)
  2720. "Make sure all properties on an agenda item have a canonical form.
  2721. This ensures the export commands can easily use it."
  2722. (let (tmp re)
  2723. (when (setq tmp (plist-get props 'tags))
  2724. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2725. (when (setq tmp (plist-get props 'date))
  2726. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2727. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2728. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2729. (setq tmp (calendar-date-string tmp)))
  2730. (setq props (plist-put props 'date tmp)))
  2731. (when (setq tmp (plist-get props 'day))
  2732. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2733. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2734. (setq tmp (calendar-date-string tmp)))
  2735. (setq props (plist-put props 'day tmp))
  2736. (setq props (plist-put props 'agenda-day tmp)))
  2737. (when (setq tmp (plist-get props 'txt))
  2738. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2739. (plist-put props 'priority-letter (match-string 1 tmp))
  2740. (setq tmp (replace-match "" t t tmp)))
  2741. (when (and (setq re (plist-get props 'org-todo-regexp))
  2742. (setq re (concat "\\`\\.*" re " ?"))
  2743. (string-match re tmp))
  2744. (plist-put props 'todo (match-string 1 tmp))
  2745. (setq tmp (replace-match "" t t tmp)))
  2746. (plist-put props 'txt tmp)))
  2747. props)
  2748. (defun org-agenda-export-csv-mapper (prop)
  2749. (let ((res (plist-get org-agenda-info prop)))
  2750. (setq res
  2751. (cond
  2752. ((not res) "")
  2753. ((stringp res) res)
  2754. (t (prin1-to-string res))))
  2755. (while (string-match "," res)
  2756. (setq res (replace-match ";" t t res)))
  2757. (org-trim res)))
  2758. ;;;###autoload
  2759. (defun org-store-agenda-views (&rest parameters)
  2760. (interactive)
  2761. (eval (list 'org-batch-store-agenda-views)))
  2762. (autoload 'org-store-agenda-views "org-agenda" "\
  2763. \(fn &rest PARAMETERS)" t nil)
  2764. ;;;###autoload
  2765. (defmacro org-batch-store-agenda-views (&rest parameters)
  2766. "Run all custom agenda commands that have a file argument."
  2767. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2768. (pop-up-frames nil)
  2769. (dir default-directory)
  2770. (pars (org-make-parameter-alist parameters))
  2771. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2772. (save-window-excursion
  2773. (while cmds
  2774. (setq cmd (pop cmds)
  2775. thiscmdkey (car cmd)
  2776. thiscmdcmd (cdr cmd)
  2777. match (nth 2 thiscmdcmd)
  2778. bufname (if org-agenda-sticky
  2779. (or (and (stringp match)
  2780. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2781. (format "*Org Agenda(%s)*" thiscmdkey))
  2782. org-agenda-buffer-name)
  2783. cmd-or-set (nth 2 cmd)
  2784. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2785. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2786. (if (stringp files) (setq files (list files)))
  2787. (when files
  2788. (org-eval-in-environment (append org-agenda-exporter-settings
  2789. opts pars)
  2790. (org-agenda nil thiscmdkey))
  2791. (set-buffer bufname)
  2792. (while files
  2793. (org-eval-in-environment (append org-agenda-exporter-settings
  2794. opts pars)
  2795. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2796. (and (get-buffer bufname)
  2797. (kill-buffer bufname)))))))
  2798. (autoload 'org-batch-store-agenda-views "org-agenda" "\
  2799. Run all custom agenda commands that have a file argument.
  2800. \(fn &rest PARAMETERS)" nil t)
  2801. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2802. (defvar org-agenda-current-span nil
  2803. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2804. (defun org-agenda-mark-header-line (pos)
  2805. "Mark the line at POS as an agenda structure header."
  2806. (save-excursion
  2807. (goto-char pos)
  2808. (put-text-property (point-at-bol) (point-at-eol)
  2809. 'org-agenda-structural-header t)
  2810. (when org-agenda-title-append
  2811. (put-text-property (point-at-bol) (point-at-eol)
  2812. 'org-agenda-title-append org-agenda-title-append))))
  2813. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2814. (defvar org-agenda-write-buffer-name "Agenda View")
  2815. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2816. "Write the current buffer (an agenda view) as a file.
  2817. Depending on the extension of the file name, plain text (.txt),
  2818. HTML (.html or .htm) or Postscript (.ps) is produced.
  2819. If the extension is .ics, run icalendar export over all files used
  2820. to construct the agenda and limit the export to entries listed in the
  2821. agenda now.
  2822. With prefix argument OPEN, open the new file immediately.
  2823. If NOSETTINGS is given, do not scope the settings of
  2824. `org-agenda-exporter-settings' into the export commands. This is used when
  2825. the settings have already been scoped and we do not wish to overrule other,
  2826. higher priority settings.
  2827. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2828. (interactive "FWrite agenda to file: \nP")
  2829. (if (not (file-writable-p file))
  2830. (error "Cannot write agenda to file %s" file))
  2831. (org-let (if nosettings nil org-agenda-exporter-settings)
  2832. '(save-excursion
  2833. (save-window-excursion
  2834. (org-agenda-mark-filtered-text)
  2835. (let ((bs (copy-sequence (buffer-string))) beg)
  2836. (org-agenda-unmark-filtered-text)
  2837. (with-temp-buffer
  2838. (rename-buffer org-agenda-write-buffer-name t)
  2839. (set-buffer-modified-p nil)
  2840. (insert bs)
  2841. (org-agenda-remove-marked-text 'org-filtered)
  2842. (while (setq beg (text-property-any (point-min) (point-max)
  2843. 'org-filtered t))
  2844. (delete-region
  2845. beg (or (next-single-property-change beg 'org-filtered)
  2846. (point-max))))
  2847. (run-hooks 'org-agenda-before-write-hook)
  2848. (cond
  2849. ((org-bound-and-true-p org-mobile-creating-agendas)
  2850. (org-mobile-write-agenda-for-mobile file))
  2851. ((string-match "\\.html?\\'" file)
  2852. (require 'htmlize)
  2853. (set-buffer (htmlize-buffer (current-buffer)))
  2854. (when org-agenda-export-html-style
  2855. ;; replace <style> section with org-agenda-export-html-style
  2856. (goto-char (point-min))
  2857. (kill-region (- (search-forward "<style") 6)
  2858. (search-forward "</style>"))
  2859. (insert org-agenda-export-html-style))
  2860. (write-file file)
  2861. (kill-buffer (current-buffer))
  2862. (message "HTML written to %s" file))
  2863. ((string-match "\\.ps\\'" file)
  2864. (require 'ps-print)
  2865. (ps-print-buffer-with-faces file)
  2866. (message "Postscript written to %s" file))
  2867. ((string-match "\\.pdf\\'" file)
  2868. (require 'ps-print)
  2869. (ps-print-buffer-with-faces
  2870. (concat (file-name-sans-extension file) ".ps"))
  2871. (call-process "ps2pdf" nil nil nil
  2872. (expand-file-name
  2873. (concat (file-name-sans-extension file) ".ps"))
  2874. (expand-file-name file))
  2875. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2876. (message "PDF written to %s" file))
  2877. ((string-match "\\.ics\\'" file)
  2878. (require 'org-icalendar)
  2879. (let ((org-agenda-marker-table
  2880. (org-create-marker-find-array
  2881. (org-agenda-collect-markers)))
  2882. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2883. (org-combined-agenda-icalendar-file file))
  2884. (apply 'org-export-icalendar 'combine
  2885. (org-agenda-files nil 'ifmode))))
  2886. (t
  2887. (let ((bs (buffer-string)))
  2888. (find-file file)
  2889. (erase-buffer)
  2890. (insert bs)
  2891. (save-buffer 0)
  2892. (kill-buffer (current-buffer))
  2893. (message "Plain text written to %s" file))))))))
  2894. (set-buffer (or agenda-bufname
  2895. (and (org-called-interactively-p 'any) (buffer-name))
  2896. org-agenda-buffer-name)))
  2897. (when open (org-open-file file)))
  2898. (defvar org-agenda-tag-filter-overlays nil)
  2899. (defvar org-agenda-cat-filter-overlays nil)
  2900. (defun org-agenda-mark-filtered-text ()
  2901. "Mark all text hidden by filtering with a text property."
  2902. (let ((inhibit-read-only t))
  2903. (mapc
  2904. (lambda (o)
  2905. (when (equal (overlay-buffer o) (current-buffer))
  2906. (put-text-property
  2907. (overlay-start o) (overlay-end o)
  2908. 'org-filtered t)))
  2909. (append org-agenda-tag-filter-overlays
  2910. org-agenda-cat-filter-overlays))))
  2911. (defun org-agenda-unmark-filtered-text ()
  2912. "Remove the filtering text property."
  2913. (let ((inhibit-read-only t))
  2914. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2915. (defun org-agenda-remove-marked-text (property &optional value)
  2916. "Delete all text marked with VALUE of PROPERTY.
  2917. VALUE defaults to t."
  2918. (let (beg)
  2919. (setq value (or value t))
  2920. (while (setq beg (text-property-any (point-min) (point-max)
  2921. property value))
  2922. (delete-region
  2923. beg (or (next-single-property-change beg 'org-filtered)
  2924. (point-max))))))
  2925. (defun org-agenda-add-entry-text ()
  2926. "Add entry text to agenda lines.
  2927. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2928. entry text following headings shown in the agenda.
  2929. Drawers will be excluded, also the line with scheduling/deadline info."
  2930. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2931. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2932. (let (m txt)
  2933. (goto-char (point-min))
  2934. (while (not (eobp))
  2935. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2936. (beginning-of-line 2)
  2937. (setq txt (org-agenda-get-some-entry-text
  2938. m org-agenda-add-entry-text-maxlines " > "))
  2939. (end-of-line 1)
  2940. (if (string-match "\\S-" txt)
  2941. (insert "\n" txt)
  2942. (or (eobp) (forward-char 1))))))))
  2943. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2944. &rest keep)
  2945. "Extract entry text from MARKER, at most N-LINES lines.
  2946. This will ignore drawers etc, just get the text.
  2947. If INDENT is given, prefix every line with this string. If KEEP is
  2948. given, it is a list of symbols, defining stuff that should not be
  2949. removed from the entry content. Currently only `planning' is allowed here."
  2950. (let (txt drawer-re kwd-time-re ind)
  2951. (save-excursion
  2952. (with-current-buffer (marker-buffer marker)
  2953. (if (not (derived-mode-p 'org-mode))
  2954. (setq txt "")
  2955. (save-excursion
  2956. (save-restriction
  2957. (widen)
  2958. (goto-char marker)
  2959. (end-of-line 1)
  2960. (setq txt (buffer-substring
  2961. (min (1+ (point)) (point-max))
  2962. (progn (outline-next-heading) (point)))
  2963. drawer-re org-drawer-regexp
  2964. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2965. ".*\n?"))
  2966. (with-temp-buffer
  2967. (insert txt)
  2968. (when org-agenda-add-entry-text-descriptive-links
  2969. (goto-char (point-min))
  2970. (while (org-activate-bracket-links (point-max))
  2971. (add-text-properties (match-beginning 0) (match-end 0)
  2972. '(face org-link))))
  2973. (goto-char (point-min))
  2974. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2975. (set-text-properties (match-beginning 0) (match-end 0)
  2976. nil))
  2977. (goto-char (point-min))
  2978. (while (re-search-forward drawer-re nil t)
  2979. (delete-region
  2980. (match-beginning 0)
  2981. (progn (re-search-forward
  2982. "^[ \t]*:END:.*\n?" nil 'move)
  2983. (point))))
  2984. (unless (member 'planning keep)
  2985. (goto-char (point-min))
  2986. (while (re-search-forward kwd-time-re nil t)
  2987. (replace-match "")))
  2988. (goto-char (point-min))
  2989. (when org-agenda-entry-text-exclude-regexps
  2990. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2991. (while (setq re (pop re-list))
  2992. (goto-char (point-min))
  2993. (while (re-search-forward re nil t)
  2994. (replace-match "")))))
  2995. (goto-char (point-max))
  2996. (skip-chars-backward " \t\n")
  2997. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2998. ;; find and remove min common indentation
  2999. (goto-char (point-min))
  3000. (untabify (point-min) (point-max))
  3001. (setq ind (org-get-indentation))
  3002. (while (not (eobp))
  3003. (unless (looking-at "[ \t]*$")
  3004. (setq ind (min ind (org-get-indentation))))
  3005. (beginning-of-line 2))
  3006. (goto-char (point-min))
  3007. (while (not (eobp))
  3008. (unless (looking-at "[ \t]*$")
  3009. (move-to-column ind)
  3010. (delete-region (point-at-bol) (point)))
  3011. (beginning-of-line 2))
  3012. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3013. (goto-char (point-min))
  3014. (when indent
  3015. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3016. (replace-match indent t t)))
  3017. (goto-char (point-min))
  3018. (while (looking-at "[ \t]*\n") (replace-match ""))
  3019. (goto-char (point-max))
  3020. (when (> (org-current-line)
  3021. n-lines)
  3022. (org-goto-line (1+ n-lines))
  3023. (backward-char 1))
  3024. (setq txt (buffer-substring (point-min) (point)))))))))
  3025. txt))
  3026. (defun org-agenda-collect-markers ()
  3027. "Collect the markers pointing to entries in the agenda buffer."
  3028. (let (m markers)
  3029. (save-excursion
  3030. (goto-char (point-min))
  3031. (while (not (eobp))
  3032. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  3033. (org-get-at-bol 'org-marker)))
  3034. (push m markers))
  3035. (beginning-of-line 2)))
  3036. (nreverse markers)))
  3037. (defun org-create-marker-find-array (marker-list)
  3038. "Create a alist of files names with all marker positions in that file."
  3039. (let (f tbl m a p)
  3040. (while (setq m (pop marker-list))
  3041. (setq p (marker-position m)
  3042. f (buffer-file-name (or (buffer-base-buffer
  3043. (marker-buffer m))
  3044. (marker-buffer m))))
  3045. (if (setq a (assoc f tbl))
  3046. (push (marker-position m) (cdr a))
  3047. (push (list f p) tbl)))
  3048. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  3049. tbl)))
  3050. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  3051. (defun org-check-agenda-marker-table ()
  3052. "Check of the current entry is on the marker list."
  3053. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  3054. a)
  3055. (and (setq a (assoc file org-agenda-marker-table))
  3056. (save-match-data
  3057. (save-excursion
  3058. (org-back-to-heading t)
  3059. (member (point) (cdr a)))))))
  3060. (defun org-check-for-org-mode ()
  3061. "Make sure current buffer is in org-mode. Error if not."
  3062. (or (derived-mode-p 'org-mode)
  3063. (error "Cannot execute org-mode agenda command on buffer in %s"
  3064. major-mode)))
  3065. ;;; Agenda prepare and finalize
  3066. (defvar org-agenda-multi nil) ; dynamically scoped
  3067. (defvar org-agenda-pre-window-conf nil)
  3068. (defvar org-agenda-columns-active nil)
  3069. (defvar org-agenda-name nil)
  3070. (defvar org-agenda-tag-filter nil)
  3071. (defvar org-agenda-category-filter nil)
  3072. (defvar org-agenda-top-category-filter nil)
  3073. (defvar org-agenda-tag-filter-while-redo nil)
  3074. (defvar org-agenda-tag-filter-preset nil
  3075. "A preset of the tags filter used for secondary agenda filtering.
  3076. This must be a list of strings, each string must be a single tag preceded
  3077. by \"+\" or \"-\".
  3078. This variable should not be set directly, but agenda custom commands can
  3079. bind it in the options section. The preset filter is a global property of
  3080. the entire agenda view. In a block agenda, it will not work reliably to
  3081. define a filter for one of the individual blocks. You need to set it in
  3082. the global options and expect it to be applied to the entire view.")
  3083. (defvar org-agenda-category-filter-preset nil
  3084. "A preset of the category filter used for secondary agenda filtering.
  3085. This must be a list of strings, each string must be a single category
  3086. preceded by \"+\" or \"-\".
  3087. This variable should not be set directly, but agenda custom commands can
  3088. bind it in the options section. The preset filter is a global property of
  3089. the entire agenda view. In a block agenda, it will not work reliably to
  3090. define a filter for one of the individual blocks. You need to set it in
  3091. the global options and expect it to be applied to the entire view.")
  3092. (defun org-agenda-use-sticky-p ()
  3093. "Return non-nil if an agenda buffer named
  3094. `org-agenda-buffer-name' exists and should be shown instead of
  3095. generating a new one."
  3096. (and
  3097. ;; turned off by user
  3098. org-agenda-sticky
  3099. ;; For multi-agenda buffer already exists
  3100. (not org-agenda-multi)
  3101. ;; buffer found
  3102. (get-buffer org-agenda-buffer-name)
  3103. ;; C-u parameter is same as last call
  3104. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3105. (and
  3106. (equal current-prefix-arg
  3107. org-agenda-last-prefix-arg)
  3108. ;; In case user turned stickiness on, while having existing
  3109. ;; Agenda buffer active, don't reuse that buffer, because it
  3110. ;; does not have org variables local
  3111. org-agenda-this-buffer-is-sticky))))
  3112. (defun org-agenda-prepare-window (abuf)
  3113. "Setup agenda buffer in the window."
  3114. (let* ((awin (get-buffer-window abuf))
  3115. wconf)
  3116. (cond
  3117. ((equal (current-buffer) abuf) nil)
  3118. (awin (select-window awin))
  3119. ((not (setq wconf (current-window-configuration))))
  3120. ((equal org-agenda-window-setup 'current-window)
  3121. (org-pop-to-buffer-same-window abuf))
  3122. ((equal org-agenda-window-setup 'other-window)
  3123. (org-switch-to-buffer-other-window abuf))
  3124. ((equal org-agenda-window-setup 'other-frame)
  3125. (switch-to-buffer-other-frame abuf))
  3126. ((equal org-agenda-window-setup 'reorganize-frame)
  3127. (delete-other-windows)
  3128. (org-switch-to-buffer-other-window abuf)))
  3129. ;; additional test in case agenda is invoked from within agenda
  3130. ;; buffer via elisp link
  3131. (unless (equal (current-buffer) abuf)
  3132. (org-pop-to-buffer-same-window abuf))
  3133. (setq org-agenda-pre-window-conf
  3134. (or org-agenda-pre-window-conf wconf))))
  3135. (defun org-agenda-prepare (&optional name)
  3136. (if (org-agenda-use-sticky-p)
  3137. (progn
  3138. ;; Popup existing buffer
  3139. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3140. (message "Sticky Agenda buffer, use `r' to refresh")
  3141. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3142. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3143. (setq org-todo-keywords-for-agenda nil)
  3144. (setq org-drawers-for-agenda nil)
  3145. (unless org-agenda-persistent-filter
  3146. (setq org-agenda-tag-filter nil
  3147. org-agenda-category-filter nil))
  3148. (put 'org-agenda-tag-filter :preset-filter
  3149. org-agenda-tag-filter-preset)
  3150. (put 'org-agenda-category-filter :preset-filter
  3151. org-agenda-category-filter-preset)
  3152. (if org-agenda-multi
  3153. (progn
  3154. (setq buffer-read-only nil)
  3155. (goto-char (point-max))
  3156. (unless (or (bobp) org-agenda-compact-blocks
  3157. (not org-agenda-block-separator))
  3158. (insert "\n"
  3159. (if (stringp org-agenda-block-separator)
  3160. org-agenda-block-separator
  3161. (make-string (window-width) org-agenda-block-separator))
  3162. "\n"))
  3163. (narrow-to-region (point) (point-max)))
  3164. (setq org-done-keywords-for-agenda nil)
  3165. ;; Setting any org variables that are in org-agenda-local-vars
  3166. ;; list need to be done after the prepare call
  3167. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3168. (setq buffer-read-only nil)
  3169. (org-agenda-reset-markers)
  3170. (let ((inhibit-read-only t)) (erase-buffer))
  3171. (org-agenda-mode)
  3172. (setq org-agenda-buffer (current-buffer))
  3173. (setq org-agenda-contributing-files nil)
  3174. (setq org-agenda-columns-active nil)
  3175. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3176. (setq org-todo-keywords-for-agenda
  3177. (org-uniquify org-todo-keywords-for-agenda))
  3178. (setq org-done-keywords-for-agenda
  3179. (org-uniquify org-done-keywords-for-agenda))
  3180. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3181. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3182. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3183. (and name (not org-agenda-name)
  3184. (org-set-local 'org-agenda-name name)))
  3185. (setq buffer-read-only nil)))
  3186. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3187. (defun org-agenda-finalize ()
  3188. "Finishing touch for the agenda buffer, called just before displaying it."
  3189. (unless org-agenda-multi
  3190. (save-excursion
  3191. (let ((inhibit-read-only t))
  3192. (goto-char (point-min))
  3193. (save-excursion
  3194. (while (org-activate-bracket-links (point-max))
  3195. (add-text-properties (match-beginning 0) (match-end 0)
  3196. '(face org-link))))
  3197. (save-excursion
  3198. (while (org-activate-plain-links (point-max))
  3199. (add-text-properties (match-beginning 0) (match-end 0)
  3200. '(face org-link))))
  3201. (when (cadr (assoc 'org-prefix-has-tag
  3202. (car org-prefix-format-compiled)))
  3203. (org-agenda-align-tags))
  3204. (unless org-agenda-with-colors
  3205. (remove-text-properties (point-min) (point-max) '(face nil))))
  3206. (if (and (boundp 'org-agenda-overriding-columns-format)
  3207. org-agenda-overriding-columns-format)
  3208. (org-set-local 'org-agenda-overriding-columns-format
  3209. org-agenda-overriding-columns-format))
  3210. (if (and (boundp 'org-agenda-view-columns-initially)
  3211. org-agenda-view-columns-initially)
  3212. (org-agenda-columns))
  3213. (when org-agenda-fontify-priorities
  3214. (org-agenda-fontify-priorities))
  3215. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3216. (org-agenda-dim-blocked-tasks))
  3217. ;; We need to widen when `org-agenda-finalize' is called from
  3218. ;; `org-agenda-change-all-lines' (e.g. in `org-agenda-clock-in')
  3219. (when org-clock-current-task
  3220. (save-restriction
  3221. (widen)
  3222. (org-agenda-mark-clocking-task)))
  3223. (when org-agenda-entry-text-mode
  3224. (org-agenda-entry-text-hide)
  3225. (org-agenda-entry-text-show))
  3226. (if (and (functionp 'org-habit-insert-consistency-graphs)
  3227. (save-excursion (next-single-property-change (point-min) 'org-habit-p)))
  3228. (org-habit-insert-consistency-graphs))
  3229. (let ((inhibit-read-only t))
  3230. (run-hooks 'org-agenda-finalize-hook))
  3231. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3232. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3233. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3234. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3235. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3236. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
  3237. (defun org-agenda-mark-clocking-task ()
  3238. "Mark the current clock entry in the agenda if it is present."
  3239. (mapc (lambda (o)
  3240. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3241. (delete-overlay o)))
  3242. (overlays-in (point-min) (point-max)))
  3243. (when (marker-buffer org-clock-hd-marker)
  3244. (save-excursion
  3245. (goto-char (point-min))
  3246. (let (s ov)
  3247. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3248. (goto-char s)
  3249. (when (equal (org-get-at-bol 'org-hd-marker)
  3250. org-clock-hd-marker)
  3251. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3252. (overlay-put ov 'type 'org-agenda-clocking)
  3253. (overlay-put ov 'face 'org-agenda-clocking)
  3254. (overlay-put ov 'help-echo
  3255. "The clock is running in this item")))))))
  3256. (defun org-agenda-fontify-priorities ()
  3257. "Make highest priority lines bold, and lowest italic."
  3258. (interactive)
  3259. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3260. (delete-overlay o)))
  3261. (overlays-in (point-min) (point-max)))
  3262. (save-excursion
  3263. (let ((inhibit-read-only t)
  3264. b e p ov h l)
  3265. (goto-char (point-min))
  3266. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3267. (setq h (or (get-char-property (point) 'org-highest-priority)
  3268. org-highest-priority)
  3269. l (or (get-char-property (point) 'org-lowest-priority)
  3270. org-lowest-priority)
  3271. p (string-to-char (match-string 1))
  3272. b (match-beginning 0)
  3273. e (if (eq org-agenda-fontify-priorities 'cookies)
  3274. (match-end 0)
  3275. (point-at-eol))
  3276. ov (make-overlay b e))
  3277. (overlay-put
  3278. ov 'face
  3279. (cond ((org-face-from-face-or-color
  3280. 'priority nil
  3281. (cdr (assoc p org-priority-faces))))
  3282. ((and (listp org-agenda-fontify-priorities)
  3283. (org-face-from-face-or-color
  3284. 'priority nil
  3285. (cdr (assoc p org-agenda-fontify-priorities)))))
  3286. ((equal p l) 'italic)
  3287. ((equal p h) 'bold)))
  3288. (overlay-put ov 'org-type 'org-priority)))))
  3289. (defun org-agenda-dim-blocked-tasks ()
  3290. "Dim currently blocked TODO's in the agenda display."
  3291. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3292. (delete-overlay o)))
  3293. (overlays-in (point-min) (point-max)))
  3294. (save-excursion
  3295. (let ((inhibit-read-only t)
  3296. (org-depend-tag-blocked nil)
  3297. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3298. org-blocked-by-checkboxes
  3299. invis1 b e p ov h l)
  3300. (goto-char (point-min))
  3301. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3302. (and pos (goto-char (1+ pos))))
  3303. (setq org-blocked-by-checkboxes nil invis1 invis)
  3304. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3305. (when (and marker
  3306. (with-current-buffer (marker-buffer marker)
  3307. (save-excursion (goto-char marker)
  3308. (org-entry-blocked-p))))
  3309. (if org-blocked-by-checkboxes (setq invis1 nil))
  3310. (setq b (if invis1
  3311. (max (point-min) (1- (point-at-bol)))
  3312. (point-at-bol))
  3313. e (point-at-eol)
  3314. ov (make-overlay b e))
  3315. (if invis1
  3316. (overlay-put ov 'invisible t)
  3317. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3318. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3319. (defvar org-agenda-skip-function nil
  3320. "Function to be called at each match during agenda construction.
  3321. If this function returns nil, the current match should not be skipped.
  3322. Otherwise, the function must return a position from where the search
  3323. should be continued.
  3324. This may also be a Lisp form, it will be evaluated.
  3325. Never set this variable using `setq' or so, because then it will apply
  3326. to all future agenda commands. If you do want a global skipping condition,
  3327. use the option `org-agenda-skip-function-global' instead.
  3328. The correct usage for `org-agenda-skip-function' is to bind it with
  3329. `let' to scope it dynamically into the agenda-constructing command.
  3330. A good way to set it is through options in `org-agenda-custom-commands'.")
  3331. (defun org-agenda-skip ()
  3332. "Throw to `:skip' in places that should be skipped.
  3333. Also moves point to the end of the skipped region, so that search can
  3334. continue from there."
  3335. (let ((p (point-at-bol)) to)
  3336. (when (org-in-src-block-p t) (throw :skip t))
  3337. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3338. (get-text-property p :org-archived)
  3339. (org-end-of-subtree t)
  3340. (throw :skip t))
  3341. (and org-agenda-skip-comment-trees
  3342. (get-text-property p :org-comment)
  3343. (org-end-of-subtree t)
  3344. (throw :skip t))
  3345. (if (equal (char-after p) ?#) (throw :skip t))
  3346. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3347. (org-agenda-skip-eval org-agenda-skip-function)))
  3348. (goto-char to)
  3349. (throw :skip t))))
  3350. (defun org-agenda-skip-eval (form)
  3351. "If FORM is a function or a list, call (or eval) is and return result.
  3352. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3353. and match data are returned to the previous state no matter what these
  3354. functions do."
  3355. (let (fp)
  3356. (and form
  3357. (or (setq fp (functionp form))
  3358. (consp form))
  3359. (save-excursion
  3360. (save-match-data
  3361. (if fp
  3362. (funcall form)
  3363. (eval form)))))))
  3364. (defvar org-agenda-markers nil
  3365. "List of all currently active markers created by `org-agenda'.")
  3366. (defvar org-agenda-last-marker-time (org-float-time)
  3367. "Creation time of the last agenda marker.")
  3368. (defun org-agenda-new-marker (&optional pos)
  3369. "Return a new agenda marker.
  3370. Org-mode keeps a list of these markers and resets them when they are
  3371. no longer in use."
  3372. (let ((m (copy-marker (or pos (point)))))
  3373. (setq org-agenda-last-marker-time (org-float-time))
  3374. (if org-agenda-buffer
  3375. (with-current-buffer org-agenda-buffer
  3376. (push m org-agenda-markers))
  3377. (push m org-agenda-markers))
  3378. m))
  3379. (defun org-agenda-reset-markers ()
  3380. "Reset markers created by `org-agenda'."
  3381. (while org-agenda-markers
  3382. (move-marker (pop org-agenda-markers) nil)))
  3383. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3384. "Save relative positions of markers in region.
  3385. This check for agenda markers in all agenda buffers currently active."
  3386. (dolist (buf (buffer-list))
  3387. (with-current-buffer buf
  3388. (when (eq major-mode 'org-agenda-mode)
  3389. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3390. org-agenda-markers)))))
  3391. ;;; Entry text mode
  3392. (defun org-agenda-entry-text-show-here ()
  3393. "Add some text from the entry as context to the current line."
  3394. (let (m txt o)
  3395. (setq m (org-get-at-bol 'org-hd-marker))
  3396. (unless (marker-buffer m)
  3397. (error "No marker points to an entry here"))
  3398. (setq txt (concat "\n" (org-no-properties
  3399. (org-agenda-get-some-entry-text
  3400. m org-agenda-entry-text-maxlines " > "))))
  3401. (when (string-match "\\S-" txt)
  3402. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3403. (overlay-put o 'evaporate t)
  3404. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3405. (overlay-put o 'after-string txt))))
  3406. (defun org-agenda-entry-text-show ()
  3407. "Add entry context for all agenda lines."
  3408. (interactive)
  3409. (save-excursion
  3410. (goto-char (point-max))
  3411. (beginning-of-line 1)
  3412. (while (not (bobp))
  3413. (when (org-get-at-bol 'org-hd-marker)
  3414. (org-agenda-entry-text-show-here))
  3415. (beginning-of-line 0))))
  3416. (defun org-agenda-entry-text-hide ()
  3417. "Remove any shown entry context."
  3418. (delq nil
  3419. (mapcar (lambda (o)
  3420. (if (eq (overlay-get o 'org-overlay-type)
  3421. 'agenda-entry-content)
  3422. (progn (delete-overlay o) t)))
  3423. (overlays-in (point-min) (point-max)))))
  3424. (defun org-agenda-get-day-face (date)
  3425. "Return the face DATE should be displayed with."
  3426. (or (and (functionp org-agenda-day-face-function)
  3427. (funcall org-agenda-day-face-function date))
  3428. (cond ((org-agenda-todayp date)
  3429. 'org-agenda-date-today)
  3430. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3431. 'org-agenda-date-weekend)
  3432. (t 'org-agenda-date))))
  3433. ;;; Agenda timeline
  3434. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3435. (defun org-timeline (&optional dotodo)
  3436. "Show a time-sorted view of the entries in the current org file.
  3437. Only entries with a time stamp of today or later will be listed. With
  3438. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3439. under the current date.
  3440. If the buffer contains an active region, only check the region for
  3441. dates."
  3442. (interactive "P")
  3443. (let* ((dopast t)
  3444. (org-agenda-show-log-scoped org-agenda-show-log)
  3445. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3446. (current-buffer))))
  3447. (date (calendar-current-date))
  3448. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3449. (end (if (org-region-active-p) (region-end) (point-max)))
  3450. (day-numbers (org-get-all-dates
  3451. beg end 'no-ranges
  3452. t org-agenda-show-log-scoped ; always include today
  3453. org-timeline-show-empty-dates))
  3454. (org-deadline-warning-days 0)
  3455. (org-agenda-only-exact-dates t)
  3456. (today (org-today))
  3457. (past t)
  3458. args
  3459. s e rtn d emptyp)
  3460. (setq org-agenda-redo-command
  3461. (list 'progn
  3462. (list 'org-switch-to-buffer-other-window (current-buffer))
  3463. (list 'org-timeline (list 'quote dotodo))))
  3464. (if (not dopast)
  3465. ;; Remove past dates from the list of dates.
  3466. (setq day-numbers (delq nil (mapcar (lambda(x)
  3467. (if (>= x today) x nil))
  3468. day-numbers))))
  3469. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3470. (org-compile-prefix-format 'timeline)
  3471. (org-set-sorting-strategy 'timeline)
  3472. (if org-agenda-show-log-scoped (push :closed args))
  3473. (push :timestamp args)
  3474. (push :deadline args)
  3475. (push :scheduled args)
  3476. (push :sexp args)
  3477. (if dotodo (push :todo args))
  3478. (insert "Timeline of file " entry "\n")
  3479. (add-text-properties (point-min) (point)
  3480. (list 'face 'org-agenda-structure))
  3481. (org-agenda-mark-header-line (point-min))
  3482. (while (setq d (pop day-numbers))
  3483. (if (and (listp d) (eq (car d) :omitted))
  3484. (progn
  3485. (setq s (point))
  3486. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3487. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3488. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3489. (if (and (>= d today)
  3490. dopast
  3491. past)
  3492. (progn
  3493. (setq past nil)
  3494. (insert (make-string 79 ?-) "\n")))
  3495. (setq date (calendar-gregorian-from-absolute d))
  3496. (setq s (point))
  3497. (setq rtn (and (not emptyp)
  3498. (apply 'org-agenda-get-day-entries entry
  3499. date args)))
  3500. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3501. (progn
  3502. (insert
  3503. (if (stringp org-agenda-format-date)
  3504. (format-time-string org-agenda-format-date
  3505. (org-time-from-absolute date))
  3506. (funcall org-agenda-format-date date))
  3507. "\n")
  3508. (put-text-property s (1- (point)) 'face
  3509. (org-agenda-get-day-face date))
  3510. (put-text-property s (1- (point)) 'org-date-line t)
  3511. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3512. (if (equal d today)
  3513. (put-text-property s (1- (point)) 'org-today t))
  3514. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3515. (put-text-property s (1- (point)) 'day d)))))
  3516. (goto-char (point-min))
  3517. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3518. (point-min)))
  3519. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3520. (org-agenda-finalize)
  3521. (setq buffer-read-only t)))
  3522. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3523. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3524. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3525. not every single day in the range. If FORCE-TODAY is non-nil, make
  3526. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3527. inactive time stamps (those in square brackets) are included.
  3528. When EMPTY is non-nil, also include days without any entries."
  3529. (let ((re (concat
  3530. (if pre-re pre-re "")
  3531. (if inactive org-ts-regexp-both org-ts-regexp)))
  3532. dates dates1 date day day1 day2 ts1 ts2 pos)
  3533. (if force-today
  3534. (setq dates (list (org-today))))
  3535. (save-excursion
  3536. (goto-char beg)
  3537. (while (re-search-forward re end t)
  3538. (setq day (time-to-days (org-time-string-to-time
  3539. (substring (match-string 1) 0 10)
  3540. (current-buffer) (match-beginning 0))))
  3541. (or (memq day dates) (push day dates)))
  3542. (unless no-ranges
  3543. (goto-char beg)
  3544. (while (re-search-forward org-tr-regexp end t)
  3545. (setq pos (match-beginning 0))
  3546. (setq ts1 (substring (match-string 1) 0 10)
  3547. ts2 (substring (match-string 2) 0 10)
  3548. day1 (time-to-days (org-time-string-to-time
  3549. ts1 (current-buffer) pos))
  3550. day2 (time-to-days (org-time-string-to-time
  3551. ts2 (current-buffer) pos)))
  3552. (while (< (setq day1 (1+ day1)) day2)
  3553. (or (memq day1 dates) (push day1 dates)))))
  3554. (setq dates (sort dates '<))
  3555. (when empty
  3556. (while (setq day (pop dates))
  3557. (setq day2 (car dates))
  3558. (push day dates1)
  3559. (when (and day2 empty)
  3560. (if (or (eq empty t)
  3561. (and (numberp empty) (<= (- day2 day) empty)))
  3562. (while (< (setq day (1+ day)) day2)
  3563. (push (list day) dates1))
  3564. (push (cons :omitted (- day2 day)) dates1))))
  3565. (setq dates (nreverse dates1)))
  3566. dates)))
  3567. ;;; Agenda Daily/Weekly
  3568. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3569. "Start day for the agenda view.
  3570. Custom commands can set this variable in the options section.")
  3571. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3572. (defvar org-arg-loc nil) ; local variable
  3573. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3574. "List of types searched for when creating the daily/weekly agenda.
  3575. This variable is a list of symbols that controls the types of
  3576. items that appear in the daily/weekly agenda. Allowed symbols in this
  3577. list are are
  3578. :timestamp List items containing a date stamp or date range matching
  3579. the selected date. This includes sexp entries in
  3580. angular brackets.
  3581. :sexp List entries resulting from plain diary-like sexps.
  3582. :deadline List deadline due on that date. When the date is today,
  3583. also list any deadlines past due, or due within
  3584. `org-deadline-warning-days'. `:deadline' must appear before
  3585. `:scheduled' if the setting of
  3586. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3587. any effect.
  3588. :scheduled List all items which are scheduled for the given date.
  3589. The diary for *today* also contains items which were
  3590. scheduled earlier and are not yet marked DONE.
  3591. By default, all four types are turned on.
  3592. Never set this variable globally using `setq', because then it
  3593. will apply to all future agenda commands. Instead, bind it with
  3594. `let' to scope it dynamically into the agenda-constructing
  3595. command. A good way to set it is through options in
  3596. `org-agenda-custom-commands'. For a more flexible (though
  3597. somewhat less efficient) way of determining what is included in
  3598. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3599. (defvar org-agenda-buffer-tmp-name nil)
  3600. ;;;###autoload
  3601. (defun org-agenda-list (&optional arg start-day span)
  3602. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3603. The view will be for the current day or week, but from the overview buffer
  3604. you will be able to go to other days/weeks.
  3605. With a numeric prefix argument in an interactive call, the agenda will
  3606. span ARG days. Lisp programs should instead specify SPAN to change
  3607. the number of days. SPAN defaults to `org-agenda-span'.
  3608. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3609. given in `org-agenda-start-on-weekday'."
  3610. (interactive "P")
  3611. (if org-agenda-overriding-arguments
  3612. (setq arg (car org-agenda-overriding-arguments)
  3613. start-day (nth 1 org-agenda-overriding-arguments)
  3614. span (nth 2 org-agenda-overriding-arguments)))
  3615. (if (and (integerp arg) (> arg 0))
  3616. (setq span arg arg nil))
  3617. (catch 'exit
  3618. (setq org-agenda-buffer-name
  3619. (or org-agenda-buffer-tmp-name
  3620. (if org-agenda-sticky
  3621. (cond ((and org-keys (stringp org-match))
  3622. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3623. (org-keys
  3624. (format "*Org Agenda(%s)*" org-keys))
  3625. (t "*Org Agenda(a)*")))
  3626. org-agenda-buffer-name))
  3627. (org-agenda-prepare "Day/Week")
  3628. (setq start-day (or start-day org-agenda-start-day))
  3629. (if (stringp start-day)
  3630. ;; Convert to an absolute day number
  3631. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3632. (org-compile-prefix-format 'agenda)
  3633. (org-set-sorting-strategy 'agenda)
  3634. (let* ((span (org-agenda-ndays-to-span
  3635. (or span org-agenda-ndays org-agenda-span)))
  3636. (today (org-today))
  3637. (sd (or start-day today))
  3638. (ndays (org-agenda-span-to-ndays span sd))
  3639. (org-agenda-start-on-weekday
  3640. (if (eq ndays 7)
  3641. org-agenda-start-on-weekday))
  3642. (thefiles (org-agenda-files nil 'ifmode))
  3643. (files thefiles)
  3644. (start (if (or (null org-agenda-start-on-weekday)
  3645. (< ndays 7))
  3646. sd
  3647. (let* ((nt (calendar-day-of-week
  3648. (calendar-gregorian-from-absolute sd)))
  3649. (n1 org-agenda-start-on-weekday)
  3650. (d (- nt n1)))
  3651. (- sd (+ (if (< d 0) 7 0) d)))))
  3652. (day-numbers (list start))
  3653. (day-cnt 0)
  3654. (inhibit-redisplay (not debug-on-error))
  3655. (org-agenda-show-log-scoped org-agenda-show-log)
  3656. s e rtn rtnall file date d start-pos end-pos todayp
  3657. clocktable-start clocktable-end filter)
  3658. (setq org-agenda-redo-command
  3659. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3660. (dotimes (n (1- ndays))
  3661. (push (1+ (car day-numbers)) day-numbers))
  3662. (setq day-numbers (nreverse day-numbers))
  3663. (setq clocktable-start (car day-numbers)
  3664. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3665. (org-set-local 'org-starting-day (car day-numbers))
  3666. (org-set-local 'org-arg-loc arg)
  3667. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3668. (unless org-agenda-compact-blocks
  3669. (let* ((d1 (car day-numbers))
  3670. (d2 (org-last day-numbers))
  3671. (w1 (org-days-to-iso-week d1))
  3672. (w2 (org-days-to-iso-week d2)))
  3673. (setq s (point))
  3674. (if org-agenda-overriding-header
  3675. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3676. nil 'face 'org-agenda-structure) "\n")
  3677. (insert (org-agenda-span-name span)
  3678. "-agenda"
  3679. (if (< (- d2 d1) 350)
  3680. (if (= w1 w2)
  3681. (format " (W%02d)" w1)
  3682. (format " (W%02d-W%02d)" w1 w2))
  3683. "")
  3684. ":\n")))
  3685. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3686. 'org-date-line t))
  3687. (org-agenda-mark-header-line s))
  3688. (while (setq d (pop day-numbers))
  3689. (setq date (calendar-gregorian-from-absolute d)
  3690. s (point))
  3691. (if (or (setq todayp (= d today))
  3692. (and (not start-pos) (= d sd)))
  3693. (setq start-pos (point))
  3694. (if (and start-pos (not end-pos))
  3695. (setq end-pos (point))))
  3696. (setq files thefiles
  3697. rtnall nil)
  3698. (while (setq file (pop files))
  3699. (catch 'nextfile
  3700. (org-check-agenda-file file)
  3701. (let ((org-agenda-entry-types org-agenda-entry-types))
  3702. (unless org-agenda-include-deadlines
  3703. (setq org-agenda-entry-types
  3704. (delq :deadline org-agenda-entry-types)))
  3705. (cond
  3706. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3707. (setq rtn (org-agenda-get-day-entries
  3708. file date :closed)))
  3709. (org-agenda-show-log-scoped
  3710. (setq rtn (apply 'org-agenda-get-day-entries
  3711. file date
  3712. (append '(:closed) org-agenda-entry-types))))
  3713. (t
  3714. (setq rtn (apply 'org-agenda-get-day-entries
  3715. file date
  3716. org-agenda-entry-types)))))
  3717. (setq rtnall (append rtnall rtn)))) ;; all entries
  3718. (if org-agenda-include-diary
  3719. (let ((org-agenda-search-headline-for-time t))
  3720. (require 'diary-lib)
  3721. (setq rtn (org-get-entries-from-diary date))
  3722. (setq rtnall (append rtnall rtn))))
  3723. (if (or rtnall org-agenda-show-all-dates)
  3724. (progn
  3725. (setq day-cnt (1+ day-cnt))
  3726. (insert
  3727. (if (stringp org-agenda-format-date)
  3728. (format-time-string org-agenda-format-date
  3729. (org-time-from-absolute date))
  3730. (funcall org-agenda-format-date date))
  3731. "\n")
  3732. (put-text-property s (1- (point)) 'face
  3733. (org-agenda-get-day-face date))
  3734. (put-text-property s (1- (point)) 'org-date-line t)
  3735. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3736. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3737. (when todayp
  3738. (put-text-property s (1- (point)) 'org-today t))
  3739. (setq rtnall
  3740. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3741. (if rtnall (insert ;; all entries
  3742. (org-agenda-finalize-entries rtnall)
  3743. "\n"))
  3744. (put-text-property s (1- (point)) 'day d)
  3745. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3746. (when (and org-agenda-clockreport-mode clocktable-start)
  3747. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3748. ;; the above line is to ensure the restricted range!
  3749. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3750. tbl)
  3751. (setq p (org-plist-delete p :block))
  3752. (setq p (plist-put p :tstart clocktable-start))
  3753. (setq p (plist-put p :tend clocktable-end))
  3754. (setq p (plist-put p :scope 'agenda))
  3755. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3756. (setq filter (or org-agenda-tag-filter-while-redo
  3757. (get 'org-agenda-tag-filter :preset-filter))))
  3758. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3759. (if (string-match "[<>=]" x)
  3760. ""
  3761. x))
  3762. filter ""))))
  3763. (setq tbl (apply 'org-clock-get-clocktable p))
  3764. (insert tbl)))
  3765. (goto-char (point-min))
  3766. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3767. (unless (and (pos-visible-in-window-p (point-min))
  3768. (pos-visible-in-window-p (point-max)))
  3769. (goto-char (1- (point-max)))
  3770. (recenter -1)
  3771. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3772. (progn
  3773. (goto-char (or start-pos 1))
  3774. (recenter 1))))
  3775. (goto-char (or start-pos 1))
  3776. (add-text-properties (point-min) (point-max)
  3777. `(org-agenda-type agenda
  3778. org-last-args (,arg ,start-day ,span)
  3779. org-redo-cmd ,org-agenda-redo-command
  3780. org-series-cmd ,org-cmd))
  3781. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3782. (org-agenda-show-clocking-issues))
  3783. (org-agenda-finalize)
  3784. (setq buffer-read-only t)
  3785. (message ""))))
  3786. (autoload 'org-agenda-list "org-agenda" "\
  3787. Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3788. The view will be for the current day or week, but from the overview buffer
  3789. you will be able to go to other days/weeks.
  3790. With a numeric prefix argument in an interactive call, the agenda will
  3791. span ARG days. Lisp programs should instead specify SPAN to change
  3792. the number of days. SPAN defaults to `org-agenda-span'.
  3793. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3794. given in `org-agenda-start-on-weekday'.
  3795. \(fn &optional ARG START-DAY SPAN)" t nil)
  3796. (defun org-agenda-ndays-to-span (n)
  3797. "Return a span symbol for a span of N days, or N if none matches."
  3798. (cond ((symbolp n) n)
  3799. ((= n 1) 'day)
  3800. ((= n 7) 'week)
  3801. (t n)))
  3802. (defun org-agenda-span-to-ndays (span &optional start-day)
  3803. "Return ndays from SPAN, possibly starting at START-DAY."
  3804. (cond ((numberp span) span)
  3805. ((eq span 'day) 1)
  3806. ((eq span 'week) 7)
  3807. ((eq span 'month)
  3808. (let ((date (calendar-gregorian-from-absolute start-day)))
  3809. (calendar-last-day-of-month (car date) (caddr date))))
  3810. ((eq span 'year)
  3811. (let ((date (calendar-gregorian-from-absolute start-day)))
  3812. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3813. (defun org-agenda-span-name (span)
  3814. "Return a SPAN name."
  3815. (if (null span)
  3816. ""
  3817. (if (symbolp span)
  3818. (capitalize (symbol-name span))
  3819. (format "%d days" span))))
  3820. ;;; Agenda word search
  3821. (defvar org-agenda-search-history nil)
  3822. (defvar org-search-syntax-table nil
  3823. "Special syntax table for org-mode search.
  3824. In this table, we have single quotes not as word constituents, to
  3825. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3826. (defvar org-mode-syntax-table) ; From org.el
  3827. (defun org-search-syntax-table ()
  3828. (unless org-search-syntax-table
  3829. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3830. (modify-syntax-entry ?' "." org-search-syntax-table)
  3831. (modify-syntax-entry ?` "." org-search-syntax-table))
  3832. org-search-syntax-table)
  3833. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3834. ;;;###autoload
  3835. (defun org-search-view (&optional todo-only string edit-at)
  3836. "Show all entries that contain a phrase or words or regular expressions.
  3837. With optional prefix argument TODO-ONLY, only consider entries that are
  3838. TODO entries. The argument STRING can be used to pass a default search
  3839. string into this function. If EDIT-AT is non-nil, it means that the
  3840. user should get a chance to edit this string, with cursor at position
  3841. EDIT-AT.
  3842. The search string can be viewed either as a phrase that should be found as
  3843. is, or it can be broken into a number of snippets, each of which must match
  3844. in a Boolean way to select an entry. The default depends on the variable
  3845. `org-agenda-search-view-always-boolean'.
  3846. Even if this is turned off (the default) you can always switch to
  3847. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3848. The default is a direct search of the whole phrase, where each space in
  3849. the search string can expand to an arbitrary amount of whitespace,
  3850. including newlines.
  3851. If using a Boolean search, the search string is split on whitespace and
  3852. each snippet is searched separately, with logical AND to select an entry.
  3853. Words prefixed with a minus must *not* occur in the entry. Words without
  3854. a prefix or prefixed with a plus must occur in the entry. Matching is
  3855. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3856. match whole words, not parts of a word) if
  3857. `org-agenda-search-view-force-full-words' is set (default is nil).
  3858. Boolean search snippets enclosed by curly braces are interpreted as
  3859. regular expressions that must or (when preceded with \"-\") must not
  3860. match in the entry. Snippets enclosed into double quotes will be taken
  3861. as a whole, to include whitespace.
  3862. - If the search string starts with an asterisk, search only in headlines.
  3863. - If (possibly after the leading star) the search string starts with an
  3864. exclamation mark, this also means to look at TODO entries only, an effect
  3865. that can also be achieved with a prefix argument.
  3866. - If (possibly after star and exclamation mark) the search string starts
  3867. with a colon, this will mean that the (non-regexp) snippets of the
  3868. Boolean search must match as full words.
  3869. This command searches the agenda files, and in addition the files listed
  3870. in `org-agenda-text-search-extra-files'."
  3871. (interactive "P")
  3872. (if org-agenda-overriding-arguments
  3873. (setq todo-only (car org-agenda-overriding-arguments)
  3874. string (nth 1 org-agenda-overriding-arguments)
  3875. edit-at (nth 2 org-agenda-overriding-arguments)))
  3876. (let* ((props (list 'face nil
  3877. 'done-face 'org-agenda-done
  3878. 'org-not-done-regexp org-not-done-regexp
  3879. 'org-todo-regexp org-todo-regexp
  3880. 'org-complex-heading-regexp org-complex-heading-regexp
  3881. 'mouse-face 'highlight
  3882. 'help-echo (format "mouse-2 or RET jump to location")))
  3883. (full-words org-agenda-search-view-force-full-words)
  3884. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3885. regexp rtn rtnall files file pos
  3886. marker category category-pos tags c neg re boolean
  3887. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3888. (unless (and (not edit-at)
  3889. (stringp string)
  3890. (string-match "\\S-" string))
  3891. (setq string (read-string
  3892. (if org-agenda-search-view-always-boolean
  3893. "[+-]Word/{Regexp} ...: "
  3894. "Phrase or [+-]Word/{Regexp} ...: ")
  3895. (cond
  3896. ((integerp edit-at) (cons string edit-at))
  3897. (edit-at string))
  3898. 'org-agenda-search-history)))
  3899. (catch 'exit
  3900. (if org-agenda-sticky
  3901. (setq org-agenda-buffer-name
  3902. (if (stringp string)
  3903. (format "*Org Agenda(%s:%s)*"
  3904. (or org-keys (or (and todo-only "S") "s")) string)
  3905. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3906. (org-agenda-prepare "SEARCH")
  3907. (org-compile-prefix-format 'search)
  3908. (org-set-sorting-strategy 'search)
  3909. (setq org-agenda-redo-command
  3910. (list 'org-search-view (if todo-only t nil)
  3911. (list 'if 'current-prefix-arg nil string)))
  3912. (setq org-agenda-query-string string)
  3913. (if (equal (string-to-char string) ?*)
  3914. (setq hdl-only t
  3915. words (substring string 1))
  3916. (setq words string))
  3917. (when (equal (string-to-char words) ?!)
  3918. (setq todo-only t
  3919. words (substring words 1)))
  3920. (when (equal (string-to-char words) ?:)
  3921. (setq full-words t
  3922. words (substring words 1)))
  3923. (if (or org-agenda-search-view-always-boolean
  3924. (member (string-to-char words) '(?- ?+ ?\{)))
  3925. (setq boolean t))
  3926. (setq words (org-split-string words))
  3927. (let (www w)
  3928. (while (setq w (pop words))
  3929. (while (and (string-match "\\\\\\'" w) words)
  3930. (setq w (concat (substring w 0 -1) " " (pop words))))
  3931. (push w www))
  3932. (setq words (nreverse www) www nil)
  3933. (while (setq w (pop words))
  3934. (when (and (string-match "\\`[-+]?{" w)
  3935. (not (string-match "}\\'" w)))
  3936. (while (and words (not (string-match "}\\'" (car words))))
  3937. (setq w (concat w " " (pop words))))
  3938. (setq w (concat w " " (pop words))))
  3939. (push w www))
  3940. (setq words (nreverse www)))
  3941. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3942. (when boolean
  3943. (let (wds w)
  3944. (while (setq w (pop words))
  3945. (if (or (equal (substring w 0 1) "\"")
  3946. (and (> (length w) 1)
  3947. (member (substring w 0 1) '("+" "-"))
  3948. (equal (substring w 1 2) "\"")))
  3949. (while (and words (not (equal (substring w -1) "\"")))
  3950. (setq w (concat w " " (pop words)))))
  3951. (and (string-match "\\`\\([-+]?\\)\"" w)
  3952. (setq w (replace-match "\\1" nil nil w)))
  3953. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3954. (push w wds))
  3955. (setq words (nreverse wds))))
  3956. (if boolean
  3957. (mapc (lambda (w)
  3958. (setq c (string-to-char w))
  3959. (if (equal c ?-)
  3960. (setq neg t w (substring w 1))
  3961. (if (equal c ?+)
  3962. (setq neg nil w (substring w 1))
  3963. (setq neg nil)))
  3964. (if (string-match "\\`{.*}\\'" w)
  3965. (setq re (substring w 1 -1))
  3966. (if full-words
  3967. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3968. (setq re (regexp-quote (downcase w)))))
  3969. (if neg (push re regexps-) (push re regexps+)))
  3970. words)
  3971. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3972. regexps+))
  3973. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3974. (if (not regexps+)
  3975. (setq regexp org-outline-regexp-bol)
  3976. (setq regexp (pop regexps+))
  3977. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3978. regexp))))
  3979. (setq files (org-agenda-files nil 'ifmode))
  3980. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3981. (pop org-agenda-text-search-extra-files)
  3982. (setq files (org-add-archive-files files)))
  3983. (setq files (append files org-agenda-text-search-extra-files)
  3984. rtnall nil)
  3985. (while (setq file (pop files))
  3986. (setq ee nil)
  3987. (catch 'nextfile
  3988. (org-check-agenda-file file)
  3989. (setq buffer (if (file-exists-p file)
  3990. (org-get-agenda-file-buffer file)
  3991. (error "No such file %s" file)))
  3992. (if (not buffer)
  3993. ;; If file does not exist, make sure an error message is sent
  3994. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3995. file))))
  3996. (with-current-buffer buffer
  3997. (with-syntax-table (org-search-syntax-table)
  3998. (unless (derived-mode-p 'org-mode)
  3999. (error "Agenda file %s is not in `org-mode'" file))
  4000. (let ((case-fold-search t))
  4001. (save-excursion
  4002. (save-restriction
  4003. (if org-agenda-restrict
  4004. (narrow-to-region org-agenda-restrict-begin
  4005. org-agenda-restrict-end)
  4006. (widen))
  4007. (goto-char (point-min))
  4008. (unless (or (org-at-heading-p)
  4009. (outline-next-heading))
  4010. (throw 'nextfile t))
  4011. (goto-char (max (point-min) (1- (point))))
  4012. (while (re-search-forward regexp nil t)
  4013. (org-back-to-heading t)
  4014. (skip-chars-forward "* ")
  4015. (setq beg (point-at-bol)
  4016. beg1 (point)
  4017. end (progn (outline-next-heading) (point)))
  4018. (catch :skip
  4019. (goto-char beg)
  4020. (org-agenda-skip)
  4021. (setq str (buffer-substring-no-properties
  4022. (point-at-bol)
  4023. (if hdl-only (point-at-eol) end)))
  4024. (mapc (lambda (wr) (when (string-match wr str)
  4025. (goto-char (1- end))
  4026. (throw :skip t)))
  4027. regexps-)
  4028. (mapc (lambda (wr) (unless (string-match wr str)
  4029. (goto-char (1- end))
  4030. (throw :skip t)))
  4031. (if todo-only
  4032. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4033. regexps+)
  4034. regexps+))
  4035. (goto-char beg)
  4036. (setq marker (org-agenda-new-marker (point))
  4037. category (org-get-category)
  4038. category-pos (get-text-property (point) 'org-category-position)
  4039. tags (org-get-tags-at (point))
  4040. txt (org-agenda-format-item
  4041. ""
  4042. (buffer-substring-no-properties
  4043. beg1 (point-at-eol))
  4044. category tags t))
  4045. (org-add-props txt props
  4046. 'org-marker marker 'org-hd-marker marker
  4047. 'org-todo-regexp org-todo-regexp
  4048. 'org-complex-heading-regexp org-complex-heading-regexp
  4049. 'priority 1000 'org-category category
  4050. 'org-category-position category-pos
  4051. 'type "search")
  4052. (push txt ee)
  4053. (goto-char (1- end))))))))))
  4054. (setq rtn (nreverse ee))
  4055. (setq rtnall (append rtnall rtn)))
  4056. (if org-agenda-overriding-header
  4057. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4058. nil 'face 'org-agenda-structure) "\n")
  4059. (insert "Search words: ")
  4060. (add-text-properties (point-min) (1- (point))
  4061. (list 'face 'org-agenda-structure))
  4062. (setq pos (point))
  4063. (insert string "\n")
  4064. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4065. (setq pos (point))
  4066. (unless org-agenda-multi
  4067. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4068. (add-text-properties pos (1- (point))
  4069. (list 'face 'org-agenda-structure))))
  4070. (org-agenda-mark-header-line (point-min))
  4071. (when rtnall
  4072. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4073. (goto-char (point-min))
  4074. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4075. (add-text-properties (point-min) (point-max)
  4076. `(org-agenda-type search
  4077. org-last-args (,todo-only ,string ,edit-at)
  4078. org-redo-cmd ,org-agenda-redo-command
  4079. org-series-cmd ,org-cmd))
  4080. (org-agenda-finalize)
  4081. (setq buffer-read-only t))))
  4082. (autoload 'org-search-view "org-agenda" "\
  4083. Show all entries that contain a phrase or words or regular expressions.
  4084. With optional prefix argument TODO-ONLY, only consider entries that are
  4085. TODO entries. The argument STRING can be used to pass a default search
  4086. string into this function. If EDIT-AT is non-nil, it means that the
  4087. user should get a chance to edit this string, with cursor at position
  4088. EDIT-AT.
  4089. The search string can be viewed either as a phrase that should be found as
  4090. is, or it can be broken into a number of snippets, each of which must match
  4091. in a Boolean way to select an entry. The default depends on the variable
  4092. `org-agenda-search-view-always-boolean'.
  4093. Even if this is turned off (the default) you can always switch to
  4094. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4095. The default is a direct search of the whole phrase, where each space in
  4096. the search string can expand to an arbitrary amount of whitespace,
  4097. including newlines.
  4098. If using a Boolean search, the search string is split on whitespace and
  4099. each snippet is searched separately, with logical AND to select an entry.
  4100. Words prefixed with a minus must *not* occur in the entry. Words without
  4101. a prefix or prefixed with a plus must occur in the entry. Matching is
  4102. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4103. match whole words, not parts of a word) if
  4104. `org-agenda-search-view-force-full-words' is set (default is nil).
  4105. Boolean search snippets enclosed by curly braces are interpreted as
  4106. regular expressions that must or (when preceded with \"-\") must not
  4107. match in the entry. Snippets enclosed into double quotes will be taken
  4108. as a whole, to include whitespace.
  4109. - If the search string starts with an asterisk, search only in headlines.
  4110. - If (possibly after the leading star) the search string starts with an
  4111. exclamation mark, this also means to look at TODO entries only, an effect
  4112. that can also be achieved with a prefix argument.
  4113. - If (possibly after star and exclamation mark) the search string starts
  4114. with a colon, this will mean that the (non-regexp) snippets of the
  4115. Boolean search must match as full words.
  4116. This command searches the agenda files, and in addition the files listed
  4117. in `org-agenda-text-search-extra-files'.
  4118. \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
  4119. ;;; Agenda TODO list
  4120. (defvar org-select-this-todo-keyword nil)
  4121. (defvar org-last-arg nil)
  4122. ;;;###autoload
  4123. (defun org-todo-list (&optional arg)
  4124. "Show all (not done) TODO entries from all agenda file in a single list.
  4125. The prefix arg can be used to select a specific TODO keyword and limit
  4126. the list to these. When using \\[universal-argument], you will be prompted
  4127. for a keyword. A numeric prefix directly selects the Nth keyword in
  4128. `org-todo-keywords-1'."
  4129. (interactive "P")
  4130. (if org-agenda-overriding-arguments
  4131. (setq arg org-agenda-overriding-arguments))
  4132. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4133. (let* ((today (org-today))
  4134. (date (calendar-gregorian-from-absolute today))
  4135. (kwds org-todo-keywords-for-agenda)
  4136. (completion-ignore-case t)
  4137. (org-select-this-todo-keyword
  4138. (if (stringp arg) arg
  4139. (and arg (integerp arg) (> arg 0)
  4140. (nth (1- arg) kwds))))
  4141. rtn rtnall files file pos)
  4142. (when (equal arg '(4))
  4143. (setq org-select-this-todo-keyword
  4144. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4145. (mapcar 'list kwds) nil nil)))
  4146. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4147. (catch 'exit
  4148. (if org-agenda-sticky
  4149. (setq org-agenda-buffer-name
  4150. (if (stringp org-select-this-todo-keyword)
  4151. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4152. org-select-this-todo-keyword)
  4153. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4154. (org-agenda-prepare "TODO")
  4155. (org-compile-prefix-format 'todo)
  4156. (org-set-sorting-strategy 'todo)
  4157. (setq org-agenda-redo-command
  4158. `(org-todo-list (or (and (numberp current-prefix-arg)
  4159. current-prefix-arg)
  4160. ,org-select-this-todo-keyword
  4161. current-prefix-arg ,arg)))
  4162. (setq files (org-agenda-files nil 'ifmode)
  4163. rtnall nil)
  4164. (while (setq file (pop files))
  4165. (catch 'nextfile
  4166. (org-check-agenda-file file)
  4167. (setq rtn (org-agenda-get-day-entries file date :todo))
  4168. (setq rtnall (append rtnall rtn))))
  4169. (if org-agenda-overriding-header
  4170. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4171. nil 'face 'org-agenda-structure) "\n")
  4172. (insert "Global list of TODO items of type: ")
  4173. (add-text-properties (point-min) (1- (point))
  4174. (list 'face 'org-agenda-structure
  4175. 'short-heading
  4176. (concat "ToDo: "
  4177. (or org-select-this-todo-keyword "ALL"))))
  4178. (org-agenda-mark-header-line (point-min))
  4179. (setq pos (point))
  4180. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4181. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4182. (setq pos (point))
  4183. (unless org-agenda-multi
  4184. (insert "Available with `N r': (0)[ALL]")
  4185. (let ((n 0) s)
  4186. (mapc (lambda (x)
  4187. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4188. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4189. (insert "\n "))
  4190. (insert " " s))
  4191. kwds))
  4192. (insert "\n"))
  4193. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4194. (org-agenda-mark-header-line (point-min))
  4195. (when rtnall
  4196. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4197. (goto-char (point-min))
  4198. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4199. (add-text-properties (point-min) (point-max)
  4200. `(org-agenda-type todo
  4201. org-last-args ,arg
  4202. org-redo-cmd ,org-agenda-redo-command
  4203. org-series-cmd ,org-cmd))
  4204. (org-agenda-finalize)
  4205. (setq buffer-read-only t))))
  4206. (autoload 'org-todo-list "org-agenda" "\
  4207. Show all (not done) TODO entries from all agenda file in a single list.
  4208. The prefix arg can be used to select a specific TODO keyword and limit
  4209. the list to these. When using \\[universal-argument], you will be prompted
  4210. for a keyword. A numeric prefix directly selects the Nth keyword in
  4211. `org-todo-keywords-1'.
  4212. \(fn &optional ARG)" t nil)
  4213. ;;; Agenda tags match
  4214. ;;;###autoload
  4215. (defun org-tags-view (&optional todo-only match)
  4216. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4217. The prefix arg TODO-ONLY limits the search to TODO entries."
  4218. (interactive "P")
  4219. (if org-agenda-overriding-arguments
  4220. (setq todo-only (car org-agenda-overriding-arguments)
  4221. match (nth 1 org-agenda-overriding-arguments)))
  4222. (let* ((org-tags-match-list-sublevels
  4223. org-tags-match-list-sublevels)
  4224. (completion-ignore-case t)
  4225. rtn rtnall files file pos matcher
  4226. buffer)
  4227. (when (and (stringp match) (not (string-match "\\S-" match)))
  4228. (setq match nil))
  4229. (setq matcher (org-make-tags-matcher match)
  4230. match (car matcher) matcher (cdr matcher))
  4231. (catch 'exit
  4232. (if org-agenda-sticky
  4233. (setq org-agenda-buffer-name
  4234. (if (stringp match)
  4235. (format "*Org Agenda(%s:%s)*"
  4236. (or org-keys (or (and todo-only "M") "m")) match)
  4237. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4238. (org-agenda-prepare (concat "TAGS " match))
  4239. (org-compile-prefix-format 'tags)
  4240. (org-set-sorting-strategy 'tags)
  4241. (setq org-agenda-query-string match)
  4242. (setq org-agenda-redo-command
  4243. (list 'org-tags-view `(quote ,todo-only)
  4244. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4245. (setq files (org-agenda-files nil 'ifmode)
  4246. rtnall nil)
  4247. (while (setq file (pop files))
  4248. (catch 'nextfile
  4249. (org-check-agenda-file file)
  4250. (setq buffer (if (file-exists-p file)
  4251. (org-get-agenda-file-buffer file)
  4252. (error "No such file %s" file)))
  4253. (if (not buffer)
  4254. ;; If file does not exist, error message to agenda
  4255. (setq rtn (list
  4256. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4257. rtnall (append rtnall rtn))
  4258. (with-current-buffer buffer
  4259. (unless (derived-mode-p 'org-mode)
  4260. (error "Agenda file %s is not in `org-mode'" file))
  4261. (save-excursion
  4262. (save-restriction
  4263. (if org-agenda-restrict
  4264. (narrow-to-region org-agenda-restrict-begin
  4265. org-agenda-restrict-end)
  4266. (widen))
  4267. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4268. (setq rtnall (append rtnall rtn))))))))
  4269. (if org-agenda-overriding-header
  4270. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4271. nil 'face 'org-agenda-structure) "\n")
  4272. (insert "Headlines with TAGS match: ")
  4273. (add-text-properties (point-min) (1- (point))
  4274. (list 'face 'org-agenda-structure
  4275. 'short-heading
  4276. (concat "Match: " match)))
  4277. (setq pos (point))
  4278. (insert match "\n")
  4279. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4280. (setq pos (point))
  4281. (unless org-agenda-multi
  4282. (insert "Press `C-u r' to search again with new search string\n"))
  4283. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4284. (org-agenda-mark-header-line (point-min))
  4285. (when rtnall
  4286. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4287. (goto-char (point-min))
  4288. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4289. (add-text-properties (point-min) (point-max)
  4290. `(org-agenda-type tags
  4291. org-last-args (,todo-only ,match)
  4292. org-redo-cmd ,org-agenda-redo-command
  4293. org-series-cmd ,org-cmd))
  4294. (org-agenda-finalize)
  4295. (setq buffer-read-only t))))
  4296. (autoload 'org-tags-view "org-agenda" "\
  4297. Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4298. The prefix arg TODO-ONLY limits the search to TODO entries.
  4299. \(fn &optional TODO-ONLY MATCH)" t nil)
  4300. ;;; Agenda Finding stuck projects
  4301. (defvar org-agenda-skip-regexp nil
  4302. "Regular expression used in skipping subtrees for the agenda.
  4303. This is basically a temporary global variable that can be set and then
  4304. used by user-defined selections using `org-agenda-skip-function'.")
  4305. (defvar org-agenda-overriding-header nil
  4306. "When set during agenda, todo and tags searches it replaces the header.
  4307. This variable should not be set directly, but custom commands can bind it
  4308. in the options section.")
  4309. (defun org-agenda-skip-entry-when-regexp-matches ()
  4310. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4311. If yes, it returns the end position of this entry, causing agenda commands
  4312. to skip the entry but continuing the search in the subtree. This is a
  4313. function that can be put into `org-agenda-skip-function' for the duration
  4314. of a command."
  4315. (let ((end (save-excursion (org-end-of-subtree t)))
  4316. skip)
  4317. (save-excursion
  4318. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4319. (and skip end)))
  4320. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4321. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4322. If yes, it returns the end position of this tree, causing agenda commands
  4323. to skip this subtree. This is a function that can be put into
  4324. `org-agenda-skip-function' for the duration of a command."
  4325. (let ((end (save-excursion (org-end-of-subtree t)))
  4326. skip)
  4327. (save-excursion
  4328. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4329. (and skip end)))
  4330. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4331. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4332. If yes, it returns the end position of the current entry (NOT the tree),
  4333. causing agenda commands to skip the entry but continuing the search in
  4334. the subtree. This is a function that can be put into
  4335. `org-agenda-skip-function' for the duration of a command. An important
  4336. use of this function is for the stuck project list."
  4337. (let ((end (save-excursion (org-end-of-subtree t)))
  4338. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4339. skip)
  4340. (save-excursion
  4341. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4342. (and skip entry-end)))
  4343. (defun org-agenda-skip-entry-if (&rest conditions)
  4344. "Skip entry if any of CONDITIONS is true.
  4345. See `org-agenda-skip-if' for details."
  4346. (org-agenda-skip-if nil conditions))
  4347. (defun org-agenda-skip-subtree-if (&rest conditions)
  4348. "Skip entry if any of CONDITIONS is true.
  4349. See `org-agenda-skip-if' for details."
  4350. (org-agenda-skip-if t conditions))
  4351. (defun org-agenda-skip-if (subtree conditions)
  4352. "Checks current entity for CONDITIONS.
  4353. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4354. the entry (i.e. the text before the next heading) is checked.
  4355. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4356. from different tests. Valid conditions are:
  4357. scheduled Check if there is a scheduled cookie
  4358. notscheduled Check if there is no scheduled cookie
  4359. deadline Check if there is a deadline
  4360. notdeadline Check if there is no deadline
  4361. timestamp Check if there is a timestamp (also deadline or scheduled)
  4362. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4363. regexp Check if regexp matches
  4364. notregexp Check if regexp does not match.
  4365. todo Check if TODO keyword matches
  4366. nottodo Check if TODO keyword does not match
  4367. The regexp is taken from the conditions list, it must come right after
  4368. the `regexp' or `notregexp' element.
  4369. `todo' and `nottodo' accept as an argument a list of todo
  4370. keywords, which may include \"*\" to match any todo keyword.
  4371. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4372. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4373. Instead of a list, a keyword class may be given. For example:
  4374. (org-agenda-skip-entry-if 'nottodo 'done)
  4375. would skip entries that haven't been marked with any of \"DONE\"
  4376. keywords. Possible classes are: `todo', `done', `any'.
  4377. If any of these conditions is met, this function returns the end point of
  4378. the entity, causing the search to continue from there. This is a function
  4379. that can be put into `org-agenda-skip-function' for the duration of a command."
  4380. (let (beg end m)
  4381. (org-back-to-heading t)
  4382. (setq beg (point)
  4383. end (if subtree
  4384. (progn (org-end-of-subtree t) (point))
  4385. (progn (outline-next-heading) (1- (point)))))
  4386. (goto-char beg)
  4387. (and
  4388. (or
  4389. (and (memq 'scheduled conditions)
  4390. (re-search-forward org-scheduled-time-regexp end t))
  4391. (and (memq 'notscheduled conditions)
  4392. (not (re-search-forward org-scheduled-time-regexp end t)))
  4393. (and (memq 'deadline conditions)
  4394. (re-search-forward org-deadline-time-regexp end t))
  4395. (and (memq 'notdeadline conditions)
  4396. (not (re-search-forward org-deadline-time-regexp end t)))
  4397. (and (memq 'timestamp conditions)
  4398. (re-search-forward org-ts-regexp end t))
  4399. (and (memq 'nottimestamp conditions)
  4400. (not (re-search-forward org-ts-regexp end t)))
  4401. (and (setq m (memq 'regexp conditions))
  4402. (stringp (nth 1 m))
  4403. (re-search-forward (nth 1 m) end t))
  4404. (and (setq m (memq 'notregexp conditions))
  4405. (stringp (nth 1 m))
  4406. (not (re-search-forward (nth 1 m) end t)))
  4407. (and (or
  4408. (setq m (memq 'nottodo conditions))
  4409. (setq m (memq 'todo-unblocked conditions))
  4410. (setq m (memq 'nottodo-unblocked conditions))
  4411. (setq m (memq 'todo conditions)))
  4412. (org-agenda-skip-if-todo m end)))
  4413. end)))
  4414. (defun org-agenda-skip-if-todo (args end)
  4415. "Helper function for `org-agenda-skip-if', do not use it directly.
  4416. ARGS is a list with first element either `todo', `nottodo',
  4417. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4418. a list of TODO keywords, or a state symbol `todo' or `done' or
  4419. `any'."
  4420. (let ((kw (car args))
  4421. (arg (cadr args))
  4422. todo-wds todo-re)
  4423. (setq todo-wds
  4424. (org-uniquify
  4425. (cond
  4426. ((listp arg) ;; list of keywords
  4427. (if (member "*" arg)
  4428. (mapcar 'substring-no-properties org-todo-keywords-1)
  4429. arg))
  4430. ((symbolp arg) ;; keyword class name
  4431. (cond
  4432. ((eq arg 'todo)
  4433. (org-delete-all org-done-keywords
  4434. (mapcar 'substring-no-properties
  4435. org-todo-keywords-1)))
  4436. ((eq arg 'done) org-done-keywords)
  4437. ((eq arg 'any)
  4438. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4439. (setq todo-re
  4440. (concat "^\\*+[ \t]+\\<\\("
  4441. (mapconcat 'identity todo-wds "\\|")
  4442. "\\)\\>"))
  4443. (cond
  4444. ((eq kw 'todo) (re-search-forward todo-re end t))
  4445. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4446. ((eq kw 'todo-unblocked)
  4447. (catch 'unblocked
  4448. (while (re-search-forward todo-re end t)
  4449. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4450. nil))
  4451. ((eq kw 'nottodo-unblocked)
  4452. (catch 'unblocked
  4453. (while (re-search-forward todo-re end t)
  4454. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4455. t))
  4456. )))
  4457. ;;;###autoload
  4458. (defun org-agenda-list-stuck-projects (&rest ignore)
  4459. "Create agenda view for projects that are stuck.
  4460. Stuck projects are project that have no next actions. For the definitions
  4461. of what a project is and how to check if it stuck, customize the variable
  4462. `org-stuck-projects'."
  4463. (interactive)
  4464. (let* ((org-agenda-skip-function
  4465. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4466. ;; We could have used org-agenda-skip-if here.
  4467. (org-agenda-overriding-header
  4468. (or org-agenda-overriding-header "List of stuck projects: "))
  4469. (matcher (nth 0 org-stuck-projects))
  4470. (todo (nth 1 org-stuck-projects))
  4471. (todo-wds (if (member "*" todo)
  4472. (progn
  4473. (org-agenda-prepare-buffers (org-agenda-files
  4474. nil 'ifmode))
  4475. (org-delete-all
  4476. org-done-keywords-for-agenda
  4477. (copy-sequence org-todo-keywords-for-agenda)))
  4478. todo))
  4479. (todo-re (concat "^\\*+[ \t]+\\("
  4480. (mapconcat 'identity todo-wds "\\|")
  4481. "\\)\\>"))
  4482. (tags (nth 2 org-stuck-projects))
  4483. (tags-re (if (member "*" tags)
  4484. (concat org-outline-regexp-bol
  4485. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4486. (if tags
  4487. (concat org-outline-regexp-bol
  4488. ".*:\\("
  4489. (mapconcat 'identity tags "\\|")
  4490. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4491. (gen-re (nth 3 org-stuck-projects))
  4492. (re-list
  4493. (delq nil
  4494. (list
  4495. (if todo todo-re)
  4496. (if tags tags-re)
  4497. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4498. gen-re)))))
  4499. (setq org-agenda-skip-regexp
  4500. (if re-list
  4501. (mapconcat 'identity re-list "\\|")
  4502. (error "No information how to identify unstuck projects")))
  4503. (org-tags-view nil matcher)
  4504. (with-current-buffer org-agenda-buffer-name
  4505. (setq org-agenda-redo-command
  4506. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4507. (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
  4508. Create agenda view for projects that are stuck.
  4509. Stuck projects are project that have no next actions. For the definitions
  4510. of what a project is and how to check if it stuck, customize the variable
  4511. `org-stuck-projects'.
  4512. \(fn &rest IGNORE)" t nil)
  4513. ;;; Diary integration
  4514. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4515. (defvar diary-list-entries-hook)
  4516. (defvar diary-time-regexp)
  4517. (defun org-get-entries-from-diary (date)
  4518. "Get the (Emacs Calendar) diary entries for DATE."
  4519. (require 'diary-lib)
  4520. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4521. (diary-display-hook '(fancy-diary-display))
  4522. (diary-display-function 'fancy-diary-display)
  4523. (pop-up-frames nil)
  4524. (diary-list-entries-hook
  4525. (cons 'org-diary-default-entry diary-list-entries-hook))
  4526. (diary-file-name-prefix-function nil) ; turn this feature off
  4527. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4528. entries
  4529. (org-disable-agenda-to-diary t))
  4530. (save-excursion
  4531. (save-window-excursion
  4532. (funcall (if (fboundp 'diary-list-entries)
  4533. 'diary-list-entries 'list-diary-entries)
  4534. date 1)))
  4535. (if (not (get-buffer diary-fancy-buffer))
  4536. (setq entries nil)
  4537. (with-current-buffer diary-fancy-buffer
  4538. (setq buffer-read-only nil)
  4539. (if (zerop (buffer-size))
  4540. ;; No entries
  4541. (setq entries nil)
  4542. ;; Omit the date and other unnecessary stuff
  4543. (org-agenda-cleanup-fancy-diary)
  4544. ;; Add prefix to each line and extend the text properties
  4545. (if (zerop (buffer-size))
  4546. (setq entries nil)
  4547. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4548. (setq entries
  4549. (with-temp-buffer
  4550. (insert entries) (goto-char (point-min))
  4551. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4552. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4553. (replace-match (concat "; " (match-string 1)))))
  4554. (buffer-string)))))
  4555. (set-buffer-modified-p nil)
  4556. (kill-buffer diary-fancy-buffer)))
  4557. (when entries
  4558. (setq entries (org-split-string entries "\n"))
  4559. (setq entries
  4560. (mapcar
  4561. (lambda (x)
  4562. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4563. ;; Extend the text properties to the beginning of the line
  4564. (org-add-props x (text-properties-at (1- (length x)) x)
  4565. 'type "diary" 'date date 'face 'org-agenda-diary))
  4566. entries)))))
  4567. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4568. "Hook run when the fancy diary buffer is cleaned up.")
  4569. (defun org-agenda-cleanup-fancy-diary ()
  4570. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4571. This gets rid of the date, the underline under the date, and
  4572. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4573. date. It also removes lines that contain only whitespace."
  4574. (goto-char (point-min))
  4575. (if (looking-at ".*?:[ \t]*")
  4576. (progn
  4577. (replace-match "")
  4578. (re-search-forward "\n=+$" nil t)
  4579. (replace-match "")
  4580. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4581. (re-search-forward "\n=+$" nil t)
  4582. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4583. (goto-char (point-min))
  4584. (while (re-search-forward "^ +\n" nil t)
  4585. (replace-match ""))
  4586. (goto-char (point-min))
  4587. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4588. (replace-match ""))
  4589. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4590. ;; Make sure entries from the diary have the right text properties.
  4591. (eval-after-load "diary-lib"
  4592. '(if (boundp 'diary-modify-entry-list-string-function)
  4593. ;; We can rely on the hook, nothing to do
  4594. nil
  4595. ;; Hook not available, must use advice to make this work
  4596. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4597. "Make the position visible."
  4598. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4599. (stringp string)
  4600. buffer-file-name)
  4601. (setq string (org-modify-diary-entry-string string))))))
  4602. (defun org-modify-diary-entry-string (string)
  4603. "Add text properties to string, allowing org-mode to act on it."
  4604. (org-add-props string nil
  4605. 'mouse-face 'highlight
  4606. 'help-echo (if buffer-file-name
  4607. (format "mouse-2 or RET jump to diary file %s"
  4608. (abbreviate-file-name buffer-file-name))
  4609. "")
  4610. 'org-agenda-diary-link t
  4611. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4612. (defun org-diary-default-entry ()
  4613. "Add a dummy entry to the diary.
  4614. Needed to avoid empty dates which mess up holiday display."
  4615. ;; Catch the error if dealing with the new add-to-diary-alist
  4616. (when org-disable-agenda-to-diary
  4617. (condition-case nil
  4618. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4619. (error
  4620. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4621. (defun org-add-to-diary-list (&rest args)
  4622. (if (fboundp 'diary-add-to-list)
  4623. (apply 'diary-add-to-list args)
  4624. (apply 'add-to-diary-list args)))
  4625. (defvar org-diary-last-run-time nil)
  4626. ;;;###autoload
  4627. (defun org-diary (&rest args)
  4628. "Return diary information from org files.
  4629. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4630. It accesses org files and extracts information from those files to be
  4631. listed in the diary. The function accepts arguments specifying what
  4632. items should be listed. For a list of arguments allowed here, see the
  4633. variable `org-agenda-entry-types'.
  4634. The call in the diary file should look like this:
  4635. &%%(org-diary) ~/path/to/some/orgfile.org
  4636. Use a separate line for each org file to check. Or, if you omit the file name,
  4637. all files listed in `org-agenda-files' will be checked automatically:
  4638. &%%(org-diary)
  4639. If you don't give any arguments (as in the example above), the default
  4640. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4641. So the example above may also be written as
  4642. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4643. The function expects the lisp variables `entry' and `date' to be provided
  4644. by the caller, because this is how the calendar works. Don't use this
  4645. function from a program - use `org-agenda-get-day-entries' instead."
  4646. (when (> (- (org-float-time)
  4647. org-agenda-last-marker-time)
  4648. 5)
  4649. ;; I am not sure if this works with sticky agendas, because the marker
  4650. ;; list is then no longer a global variable.
  4651. (org-agenda-reset-markers))
  4652. (org-compile-prefix-format 'agenda)
  4653. (org-set-sorting-strategy 'agenda)
  4654. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4655. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4656. (list entry)
  4657. (org-agenda-files t)))
  4658. (time (org-float-time))
  4659. file rtn results)
  4660. (when (or (not org-diary-last-run-time)
  4661. (> (- time
  4662. org-diary-last-run-time)
  4663. 3))
  4664. (org-agenda-prepare-buffers files))
  4665. (setq org-diary-last-run-time time)
  4666. ;; If this is called during org-agenda, don't return any entries to
  4667. ;; the calendar. Org Agenda will list these entries itself.
  4668. (if org-disable-agenda-to-diary (setq files nil))
  4669. (while (setq file (pop files))
  4670. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4671. (setq results (append results rtn)))
  4672. (if results
  4673. (concat (org-agenda-finalize-entries results) "\n"))))
  4674. (autoload 'org-diary "org-agenda" "\
  4675. Return diary information from org files.
  4676. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4677. It accesses org files and extracts information from those files to be
  4678. listed in the diary. The function accepts arguments specifying what
  4679. items should be listed. For a list of arguments allowed here, see the
  4680. variable `org-agenda-entry-types'.
  4681. The call in the diary file should look like this:
  4682. &%%(org-diary) ~/path/to/some/orgfile.org
  4683. Use a separate line for each org file to check. Or, if you omit the file name,
  4684. all files listed in `org-agenda-files' will be checked automatically:
  4685. &%%(org-diary)
  4686. If you don't give any arguments (as in the example above), the default
  4687. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4688. So the example above may also be written as
  4689. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4690. The function expects the lisp variables `entry' and `date' to be provided
  4691. by the caller, because this is how the calendar works. Don't use this
  4692. function from a program - use `org-agenda-get-day-entries' instead.
  4693. \(fn &rest ARGS)" nil nil)
  4694. ;;; Agenda entry finders
  4695. (defun org-agenda-get-day-entries (file date &rest args)
  4696. "Does the work for `org-diary' and `org-agenda'.
  4697. FILE is the path to a file to be checked for entries. DATE is date like
  4698. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4699. which kind of entries should be extracted. For details about these, see
  4700. the documentation of `org-diary'."
  4701. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4702. (let* ((org-startup-folded nil)
  4703. (org-startup-align-all-tables nil)
  4704. (buffer (if (file-exists-p file)
  4705. (org-get-agenda-file-buffer file)
  4706. (error "No such file %s" file)))
  4707. arg results rtn deadline-results)
  4708. (if (not buffer)
  4709. ;; If file does not exist, make sure an error message ends up in diary
  4710. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4711. (with-current-buffer buffer
  4712. (unless (derived-mode-p 'org-mode)
  4713. (error "Agenda file %s is not in `org-mode'" file))
  4714. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4715. (let ((case-fold-search nil))
  4716. (save-excursion
  4717. (save-restriction
  4718. (if org-agenda-restrict
  4719. (narrow-to-region org-agenda-restrict-begin
  4720. org-agenda-restrict-end)
  4721. (widen))
  4722. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4723. (while (setq arg (pop args))
  4724. (cond
  4725. ((and (eq arg :todo)
  4726. (equal date (calendar-gregorian-from-absolute
  4727. (org-today))))
  4728. (setq rtn (org-agenda-get-todos))
  4729. (setq results (append results rtn)))
  4730. ((eq arg :timestamp)
  4731. (setq rtn (org-agenda-get-blocks))
  4732. (setq results (append results rtn))
  4733. (setq rtn (org-agenda-get-timestamps deadline-results))
  4734. (setq results (append results rtn)))
  4735. ((eq arg :sexp)
  4736. (setq rtn (org-agenda-get-sexps))
  4737. (setq results (append results rtn)))
  4738. ((eq arg :scheduled)
  4739. (setq rtn (org-agenda-get-scheduled deadline-results))
  4740. (setq results (append results rtn)))
  4741. ((eq arg :closed)
  4742. (setq rtn (org-agenda-get-progress))
  4743. (setq results (append results rtn)))
  4744. ((eq arg :deadline)
  4745. (setq rtn (org-agenda-get-deadlines))
  4746. (setq deadline-results (copy-sequence rtn))
  4747. (setq results (append results rtn))))))))
  4748. results))))
  4749. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4750. (defun org-agenda-get-todos ()
  4751. "Return the TODO information for agenda display."
  4752. (let* ((props (list 'face nil
  4753. 'done-face 'org-agenda-done
  4754. 'org-not-done-regexp org-not-done-regexp
  4755. 'org-todo-regexp org-todo-regexp
  4756. 'org-complex-heading-regexp org-complex-heading-regexp
  4757. 'mouse-face 'highlight
  4758. 'help-echo
  4759. (format "mouse-2 or RET jump to org file %s"
  4760. (abbreviate-file-name buffer-file-name))))
  4761. (regexp (format org-heading-keyword-regexp-format
  4762. (cond
  4763. ((and org-select-this-todo-keyword
  4764. (equal org-select-this-todo-keyword "*"))
  4765. org-todo-regexp)
  4766. (org-select-this-todo-keyword
  4767. (concat "\\("
  4768. (mapconcat 'identity
  4769. (org-split-string
  4770. org-select-this-todo-keyword
  4771. "|")
  4772. "\\|") "\\)"))
  4773. (t org-not-done-regexp))))
  4774. marker priority category category-pos tags todo-state
  4775. ee txt beg end)
  4776. (goto-char (point-min))
  4777. (while (re-search-forward regexp nil t)
  4778. (catch :skip
  4779. (save-match-data
  4780. (beginning-of-line)
  4781. (org-agenda-skip)
  4782. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4783. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4784. (goto-char (1+ beg))
  4785. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4786. (throw :skip nil)))
  4787. (goto-char (match-beginning 2))
  4788. (setq marker (org-agenda-new-marker (match-beginning 0))
  4789. category (org-get-category)
  4790. category-pos (get-text-property (point) 'org-category-position)
  4791. txt (org-trim
  4792. (buffer-substring (match-beginning 2) (match-end 0)))
  4793. tags (org-get-tags-at (point))
  4794. txt (org-agenda-format-item "" txt category tags t)
  4795. priority (1+ (org-get-priority txt))
  4796. todo-state (org-get-todo-state))
  4797. (org-add-props txt props
  4798. 'org-marker marker 'org-hd-marker marker
  4799. 'priority priority 'org-category category
  4800. 'org-category-position category-pos
  4801. 'type "todo" 'todo-state todo-state)
  4802. (push txt ee)
  4803. (if org-agenda-todo-list-sublevels
  4804. (goto-char (match-end 2))
  4805. (org-end-of-subtree 'invisible))))
  4806. (nreverse ee)))
  4807. (defun org-agenda-todo-custom-ignore-p (time n)
  4808. "Check whether timestamp is farther away than n number of days.
  4809. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4810. `org-agenda-todo-ignore-scheduled' or
  4811. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4812. (let ((days (org-days-to-time time)))
  4813. (if (>= n 0)
  4814. (>= days n)
  4815. (<= days n))))
  4816. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4817. (&optional end)
  4818. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4819. (when (or org-agenda-todo-ignore-with-date
  4820. org-agenda-todo-ignore-scheduled
  4821. org-agenda-todo-ignore-deadlines
  4822. org-agenda-todo-ignore-timestamp)
  4823. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4824. (save-excursion
  4825. (or (and org-agenda-todo-ignore-with-date
  4826. (re-search-forward org-ts-regexp end t))
  4827. (and org-agenda-todo-ignore-scheduled
  4828. (re-search-forward org-scheduled-time-regexp end t)
  4829. (cond
  4830. ((eq org-agenda-todo-ignore-scheduled 'future)
  4831. (> (org-days-to-time (match-string 1)) 0))
  4832. ((eq org-agenda-todo-ignore-scheduled 'past)
  4833. (<= (org-days-to-time (match-string 1)) 0))
  4834. ((numberp org-agenda-todo-ignore-scheduled)
  4835. (org-agenda-todo-custom-ignore-p
  4836. (match-string 1) org-agenda-todo-ignore-scheduled))
  4837. (t)))
  4838. (and org-agenda-todo-ignore-deadlines
  4839. (re-search-forward org-deadline-time-regexp end t)
  4840. (cond
  4841. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4842. ((eq org-agenda-todo-ignore-deadlines 'far)
  4843. (not (org-deadline-close (match-string 1))))
  4844. ((eq org-agenda-todo-ignore-deadlines 'future)
  4845. (> (org-days-to-time (match-string 1)) 0))
  4846. ((eq org-agenda-todo-ignore-deadlines 'past)
  4847. (<= (org-days-to-time (match-string 1)) 0))
  4848. ((numberp org-agenda-todo-ignore-deadlines)
  4849. (org-agenda-todo-custom-ignore-p
  4850. (match-string 1) org-agenda-todo-ignore-deadlines))
  4851. (t (org-deadline-close (match-string 1)))))
  4852. (and org-agenda-todo-ignore-timestamp
  4853. (let ((buffer (current-buffer))
  4854. (regexp
  4855. (concat
  4856. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4857. (start (point)))
  4858. ;; Copy current buffer into a temporary one
  4859. (with-temp-buffer
  4860. (insert-buffer-substring buffer start end)
  4861. (goto-char (point-min))
  4862. ;; Delete SCHEDULED and DEADLINE items
  4863. (while (re-search-forward regexp end t)
  4864. (delete-region (match-beginning 0) (match-end 0)))
  4865. (goto-char (point-min))
  4866. ;; No search for timestamp left
  4867. (when (re-search-forward org-ts-regexp nil t)
  4868. (cond
  4869. ((eq org-agenda-todo-ignore-timestamp 'future)
  4870. (> (org-days-to-time (match-string 1)) 0))
  4871. ((eq org-agenda-todo-ignore-timestamp 'past)
  4872. (<= (org-days-to-time (match-string 1)) 0))
  4873. ((numberp org-agenda-todo-ignore-timestamp)
  4874. (org-agenda-todo-custom-ignore-p
  4875. (match-string 1) org-agenda-todo-ignore-timestamp))
  4876. (t))))))))))
  4877. (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
  4878. Do we have a reason to ignore this TODO entry because it has a time stamp?
  4879. \(fn &optional END)" nil nil)
  4880. (defconst org-agenda-no-heading-message
  4881. "No heading for this item in buffer or region.")
  4882. (defun org-agenda-get-timestamps (&optional deadline-results)
  4883. "Return the date stamp information for agenda display."
  4884. (let* ((props (list 'face 'org-agenda-calendar-event
  4885. 'org-not-done-regexp org-not-done-regexp
  4886. 'org-todo-regexp org-todo-regexp
  4887. 'org-complex-heading-regexp org-complex-heading-regexp
  4888. 'mouse-face 'highlight
  4889. 'help-echo
  4890. (format "mouse-2 or RET jump to org file %s"
  4891. (abbreviate-file-name buffer-file-name))))
  4892. (d1 (calendar-absolute-from-gregorian date))
  4893. mm
  4894. (deadline-position-alist
  4895. (mapcar (lambda (a) (and (setq mm (get-text-property
  4896. 0 'org-hd-marker a))
  4897. (cons (marker-position mm) a)))
  4898. deadline-results))
  4899. (remove-re org-ts-regexp)
  4900. (regexp
  4901. (concat
  4902. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4903. (regexp-quote
  4904. (substring
  4905. (format-time-string
  4906. (car org-time-stamp-formats)
  4907. (apply 'encode-time ; DATE bound by calendar
  4908. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4909. 1 11))
  4910. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4911. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4912. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4913. donep tmp priority category category-pos ee txt timestr tags
  4914. b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
  4915. (goto-char (point-min))
  4916. (while (setq end-of-match (re-search-forward regexp nil t))
  4917. (setq b0 (match-beginning 0)
  4918. b3 (match-beginning 3) e3 (match-end 3)
  4919. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4920. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  4921. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4922. (member todo-state
  4923. org-agenda-repeating-timestamp-show-all)))
  4924. (catch :skip
  4925. (and (org-at-date-range-p) (throw :skip nil))
  4926. (org-agenda-skip)
  4927. (if (and (match-end 1)
  4928. (not (= d1 (org-time-string-to-absolute
  4929. (match-string 1) d1 nil show-all
  4930. (current-buffer) b0))))
  4931. (throw :skip nil))
  4932. (if (and e3
  4933. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4934. (throw :skip nil))
  4935. (setq tmp (buffer-substring (max (point-min)
  4936. (- b0 org-ds-keyword-length))
  4937. b0)
  4938. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4939. inactivep (= (char-after b0) ?\[)
  4940. deadlinep (string-match org-deadline-regexp tmp)
  4941. scheduledp (string-match org-scheduled-regexp tmp)
  4942. closedp (and org-agenda-include-inactive-timestamps
  4943. (string-match org-closed-string tmp))
  4944. clockp (and org-agenda-include-inactive-timestamps
  4945. (or (string-match org-clock-string tmp)
  4946. (string-match "]-+\\'" tmp)))
  4947. warntime (org-entry-get (point) "APPT_WARNTIME")
  4948. donep (member todo-state org-done-keywords))
  4949. (if (or scheduledp deadlinep closedp clockp
  4950. (and donep org-agenda-skip-timestamp-if-done))
  4951. (throw :skip t))
  4952. (if (string-match ">" timestr)
  4953. ;; substring should only run to end of time stamp
  4954. (setq timestr (substring timestr 0 (match-end 0))))
  4955. (setq marker (org-agenda-new-marker b0)
  4956. category (org-get-category b0)
  4957. category-pos (get-text-property b0 'org-category-position))
  4958. (save-excursion
  4959. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4960. (setq txt org-agenda-no-heading-message)
  4961. (goto-char (match-beginning 0))
  4962. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4963. (assoc (point) deadline-position-alist))
  4964. (throw :skip nil))
  4965. (setq hdmarker (org-agenda-new-marker)
  4966. tags (org-get-tags-at))
  4967. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4968. (setq head (or (match-string 1) ""))
  4969. (setq txt (org-agenda-format-item
  4970. (if inactivep org-agenda-inactive-leader nil)
  4971. head category tags timestr
  4972. remove-re habitp)))
  4973. (setq priority (org-get-priority txt))
  4974. (org-add-props txt props
  4975. 'org-marker marker 'org-hd-marker hdmarker)
  4976. (org-add-props txt nil 'priority priority
  4977. 'org-category category 'date date
  4978. 'org-category-position category-pos
  4979. 'todo-state todo-state
  4980. 'warntime warntime
  4981. 'type "timestamp")
  4982. (push txt ee))
  4983. (if org-agenda-skip-additional-timestamps-same-entry
  4984. (outline-next-heading)
  4985. (goto-char end-of-match))))
  4986. (nreverse ee)))
  4987. (defun org-agenda-get-sexps ()
  4988. "Return the sexp information for agenda display."
  4989. (require 'diary-lib)
  4990. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4991. 'mouse-face 'highlight
  4992. 'help-echo
  4993. (format "mouse-2 or RET jump to org file %s"
  4994. (abbreviate-file-name buffer-file-name))))
  4995. (regexp "^&?%%(")
  4996. marker category extra category-pos ee txt tags entry
  4997. result beg b sexp sexp-entry todo-state warntime)
  4998. (goto-char (point-min))
  4999. (while (re-search-forward regexp nil t)
  5000. (catch :skip
  5001. (org-agenda-skip)
  5002. (setq beg (match-beginning 0))
  5003. (goto-char (1- (match-end 0)))
  5004. (setq b (point))
  5005. (forward-sexp 1)
  5006. (setq sexp (buffer-substring b (point)))
  5007. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5008. (org-trim (match-string 1))
  5009. ""))
  5010. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5011. (when result
  5012. (setq marker (org-agenda-new-marker beg)
  5013. category (org-get-category beg)
  5014. category-pos (get-text-property beg 'org-category-position)
  5015. tags (save-excursion (org-backward-heading-same-level 0)
  5016. (org-get-tags-at))
  5017. todo-state (org-get-todo-state)
  5018. warntime (org-entry-get (point) "APPT_WARNTIME")
  5019. extra nil)
  5020. (dolist (r (if (stringp result)
  5021. (list result)
  5022. result)) ;; we expect a list here
  5023. (when (and org-agenda-diary-sexp-prefix
  5024. (string-match org-agenda-diary-sexp-prefix r))
  5025. (setq extra (match-string 0 r)
  5026. r (replace-match "" nil nil r)))
  5027. (if (string-match "\\S-" r)
  5028. (setq txt r)
  5029. (setq txt "SEXP entry returned empty string"))
  5030. (setq txt (org-agenda-format-item
  5031. extra txt category tags 'time))
  5032. (org-add-props txt props 'org-marker marker)
  5033. (org-add-props txt nil
  5034. 'org-category category 'date date 'todo-state todo-state
  5035. 'org-category-position category-pos 'tags tags
  5036. 'type "sexp" 'warntime warntime)
  5037. (push txt ee)))))
  5038. (nreverse ee)))
  5039. ;; Calendar sanity: define some functions that are independent of
  5040. ;; `calendar-date-style'.
  5041. ;; Normally I would like to use ISO format when calling the diary functions,
  5042. ;; but to make sure we still have Emacs 22 compatibility we bind
  5043. ;; also `european-calendar-style' and use european format
  5044. (defun org-anniversary (year month day &optional mark)
  5045. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5046. (org-no-warnings
  5047. (let ((calendar-date-style 'european) (european-calendar-style t))
  5048. (diary-anniversary day month year mark))))
  5049. (defun org-cyclic (N year month day &optional mark)
  5050. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5051. (org-no-warnings
  5052. (let ((calendar-date-style 'european) (european-calendar-style t))
  5053. (diary-cyclic N day month year mark))))
  5054. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5055. "Like `diary-block', but with fixed (ISO) order of arguments."
  5056. (org-no-warnings
  5057. (let ((calendar-date-style 'european) (european-calendar-style t))
  5058. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5059. (defun org-date (year month day &optional mark)
  5060. "Like `diary-date', but with fixed (ISO) order of arguments."
  5061. (org-no-warnings
  5062. (let ((calendar-date-style 'european) (european-calendar-style t))
  5063. (diary-date day month year mark))))
  5064. (defalias 'org-float 'diary-float)
  5065. ;; Define the` org-class' function
  5066. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5067. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5068. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5069. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5070. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5071. `holidays', then any date that is known by the Emacs calendar to be a
  5072. holiday will also be skipped."
  5073. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5074. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5075. (d (calendar-absolute-from-gregorian date)))
  5076. (and
  5077. (<= date1 d)
  5078. (<= d date2)
  5079. (= (calendar-day-of-week date) dayname)
  5080. (or (not skip-weeks)
  5081. (progn
  5082. (require 'cal-iso)
  5083. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5084. (not (and (memq 'holidays skip-weeks)
  5085. (calendar-check-holidays date)))
  5086. entry)))
  5087. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5088. "Like `org-class', but honor `calendar-date-style'.
  5089. The order of the first 2 times 3 arguments depends on the variable
  5090. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5091. So for American calendars, give this as MONTH DAY YEAR, for European as
  5092. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5093. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5094. is any number of ISO weeks in the block period for which the item should
  5095. be skipped.
  5096. This function is here only for backward compatibility and it is deprecated,
  5097. please use `org-class' instead."
  5098. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5099. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5100. (org-class
  5101. (nth 2 date1) (car date1) (nth 1 date1)
  5102. (nth 2 date2) (car date2) (nth 1 date2)
  5103. dayname skip-weeks)))
  5104. (make-obsolete 'org-diary-class 'org-class "")
  5105. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5106. (defalias 'org-get-closed 'org-agenda-get-progress)
  5107. (defun org-agenda-get-progress ()
  5108. "Return the logged TODO entries for agenda display."
  5109. (let* ((props (list 'mouse-face 'highlight
  5110. 'org-not-done-regexp org-not-done-regexp
  5111. 'org-todo-regexp org-todo-regexp
  5112. 'org-complex-heading-regexp org-complex-heading-regexp
  5113. 'help-echo
  5114. (format "mouse-2 or RET jump to org file %s"
  5115. (abbreviate-file-name buffer-file-name))))
  5116. (items (if (consp org-agenda-show-log-scoped)
  5117. org-agenda-show-log-scoped
  5118. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5119. '(clock)
  5120. org-agenda-log-mode-items)))
  5121. (parts
  5122. (delq nil
  5123. (list
  5124. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5125. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5126. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5127. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5128. (error "`org-agenda-log-mode-items' is empty")))
  5129. (regexp (concat
  5130. "\\(" parts-re "\\)"
  5131. " *\\["
  5132. (regexp-quote
  5133. (substring
  5134. (format-time-string
  5135. (car org-time-stamp-formats)
  5136. (apply 'encode-time ; DATE bound by calendar
  5137. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5138. 1 11))))
  5139. (org-agenda-search-headline-for-time nil)
  5140. marker hdmarker priority category category-pos tags closedp
  5141. statep clockp state ee txt extra timestr rest clocked)
  5142. (goto-char (point-min))
  5143. (while (re-search-forward regexp nil t)
  5144. (catch :skip
  5145. (org-agenda-skip)
  5146. (setq marker (org-agenda-new-marker (match-beginning 0))
  5147. closedp (equal (match-string 1) org-closed-string)
  5148. statep (equal (string-to-char (match-string 1)) ?-)
  5149. clockp (not (or closedp statep))
  5150. state (and statep (match-string 2))
  5151. category (org-get-category (match-beginning 0))
  5152. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5153. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5154. (when (string-match "\\]" timestr)
  5155. ;; substring should only run to end of time stamp
  5156. (setq rest (substring timestr (match-end 0))
  5157. timestr (substring timestr 0 (match-end 0)))
  5158. (if (and (not closedp) (not statep)
  5159. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5160. rest))
  5161. (progn (setq timestr (concat (substring timestr 0 -1)
  5162. "-" (match-string 1 rest) "]"))
  5163. (setq clocked (match-string 2 rest)))
  5164. (setq clocked "-")))
  5165. (save-excursion
  5166. (setq extra
  5167. (cond
  5168. ((not org-agenda-log-mode-add-notes) nil)
  5169. (statep
  5170. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5171. (match-string 1)))
  5172. (clockp
  5173. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5174. (match-string 1)))))
  5175. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5176. (setq txt org-agenda-no-heading-message)
  5177. (goto-char (match-beginning 0))
  5178. (setq hdmarker (org-agenda-new-marker)
  5179. tags (org-get-tags-at))
  5180. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5181. (setq txt (match-string 1))
  5182. (when extra
  5183. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5184. (setq txt (concat (substring txt 0 (match-beginning 1))
  5185. " - " extra " " (match-string 2 txt)))
  5186. (setq txt (concat txt " - " extra))))
  5187. (setq txt (org-agenda-format-item
  5188. (cond
  5189. (closedp "Closed: ")
  5190. (statep (concat "State: (" state ")"))
  5191. (t (concat "Clocked: (" clocked ")")))
  5192. txt category tags timestr)))
  5193. (setq priority 100000)
  5194. (org-add-props txt props
  5195. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5196. 'priority priority 'org-category category
  5197. 'org-category-position category-pos
  5198. 'type "closed" 'date date
  5199. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5200. (push txt ee))
  5201. (goto-char (point-at-eol))))
  5202. (nreverse ee)))
  5203. (defun org-agenda-show-clocking-issues ()
  5204. "Add overlays, showing issues with clocking.
  5205. See also the user option `org-agenda-clock-consistency-checks'."
  5206. (interactive)
  5207. (let* ((pl org-agenda-clock-consistency-checks)
  5208. (re (concat "^[ \t]*"
  5209. org-clock-string
  5210. "[ \t]+"
  5211. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5212. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5213. (tlstart 0.)
  5214. (tlend 0.)
  5215. (maxtime (org-hh:mm-string-to-minutes
  5216. (or (plist-get pl :max-duration) "24:00")))
  5217. (mintime (org-hh:mm-string-to-minutes
  5218. (or (plist-get pl :min-duration) 0)))
  5219. (maxgap (org-hh:mm-string-to-minutes
  5220. ;; default 30:00 means never complain
  5221. (or (plist-get pl :max-gap) "30:00")))
  5222. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5223. (plist-get pl :gap-ok-around)))
  5224. (def-face (or (plist-get pl :default-face)
  5225. '((:background "DarkRed") (:foreground "white"))))
  5226. issue face m te ts dt ov)
  5227. (goto-char (point-min))
  5228. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5229. (setq issue nil face def-face)
  5230. (catch 'next
  5231. (setq m (org-get-at-bol 'org-marker)
  5232. te nil ts nil)
  5233. (unless (and m (markerp m))
  5234. (setq issue "No valid clock line") (throw 'next t))
  5235. (org-with-point-at m
  5236. (save-excursion
  5237. (goto-char (point-at-bol))
  5238. (unless (looking-at re)
  5239. (error "No valid Clock line")
  5240. (throw 'next t))
  5241. (unless (match-end 3)
  5242. (setq issue "No end time"
  5243. face (or (plist-get pl :no-end-time-face) face))
  5244. (throw 'next t))
  5245. (setq ts (match-string 1)
  5246. te (match-string 3)
  5247. ts (org-float-time
  5248. (apply 'encode-time (org-parse-time-string ts)))
  5249. te (org-float-time
  5250. (apply 'encode-time (org-parse-time-string te)))
  5251. dt (- te ts))))
  5252. (cond
  5253. ((> dt (* 60 maxtime))
  5254. ;; a very long clocking chunk
  5255. (setq issue (format "Clocking interval is very long: %s"
  5256. (org-minutes-to-hh:mm-string
  5257. (floor (/ (float dt) 60.))))
  5258. face (or (plist-get pl :long-face) face)))
  5259. ((< dt (* 60 mintime))
  5260. ;; a very short clocking chunk
  5261. (setq issue (format "Clocking interval is very short: %s"
  5262. (org-minutes-to-hh:mm-string
  5263. (floor (/ (float dt) 60.))))
  5264. face (or (plist-get pl :short-face) face)))
  5265. ((and (> tlend 0) (< ts tlend))
  5266. ;; Two clock entries are overlapping
  5267. (setq issue (format "Clocking overlap: %d minutes"
  5268. (/ (- tlend ts) 60))
  5269. face (or (plist-get pl :overlap-face) face)))
  5270. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5271. ;; There is a gap, lets see if we need to report it
  5272. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5273. (setq issue (format "Clocking gap: %d minutes"
  5274. (/ (- ts tlend) 60))
  5275. face (or (plist-get pl :gap-face) face))))
  5276. (t nil)))
  5277. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5278. (when issue
  5279. ;; OK, there was some issue, add an overlay to show the issue
  5280. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5281. (overlay-put ov 'before-string
  5282. (concat
  5283. (org-add-props
  5284. (format "%-43s" (concat " " issue))
  5285. nil
  5286. 'face face)
  5287. "\n"))
  5288. (overlay-put ov 'evaporate t)))))
  5289. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5290. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5291. (catch 'exit
  5292. (unless ok-list
  5293. ;; there are no OK times for gaps...
  5294. (throw 'exit nil))
  5295. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5296. ;; This is more than 24 hours, so it is OK.
  5297. ;; because we have at least one OK time, that must be in the
  5298. ;; 24 hour interval.
  5299. (throw 'exit t))
  5300. ;; We have a shorter gap.
  5301. ;; Now we have to get the minute of the day when these times are
  5302. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5303. (t2dec (decode-time (seconds-to-time t2)))
  5304. ;; compute the minute on the day
  5305. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5306. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5307. (when (< min2 min1)
  5308. ;; if min2 is smaller than min1, this means it is on the next day.
  5309. ;; Wrap it to after midnight.
  5310. (setq min2 (+ min2 1440)))
  5311. ;; Now check if any of the OK times is in the gap
  5312. (mapc (lambda (x)
  5313. ;; Wrap the time to after midnight if necessary
  5314. (if (< x min1) (setq x (+ x 1440)))
  5315. ;; Check if in interval
  5316. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5317. ok-list)
  5318. ;; Nope, this gap is not OK
  5319. nil)))
  5320. (defun org-agenda-get-deadlines ()
  5321. "Return the deadline information for agenda display."
  5322. (let* ((props (list 'mouse-face 'highlight
  5323. 'org-not-done-regexp org-not-done-regexp
  5324. 'org-todo-regexp org-todo-regexp
  5325. 'org-complex-heading-regexp org-complex-heading-regexp
  5326. 'help-echo
  5327. (format "mouse-2 or RET jump to org file %s"
  5328. (abbreviate-file-name buffer-file-name))))
  5329. (regexp org-deadline-time-regexp)
  5330. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5331. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5332. d2 diff dfrac wdays pos pos1 category category-pos
  5333. tags suppress-prewarning ee txt head face s todo-state
  5334. show-all upcomingp donep timestr warntime)
  5335. (goto-char (point-min))
  5336. (while (re-search-forward regexp nil t)
  5337. (setq suppress-prewarning nil)
  5338. (catch :skip
  5339. (org-agenda-skip)
  5340. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5341. (save-match-data
  5342. (string-match org-scheduled-time-regexp
  5343. (buffer-substring (point-at-bol)
  5344. (point-at-eol)))))
  5345. (setq suppress-prewarning
  5346. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5347. org-agenda-skip-deadline-prewarning-if-scheduled
  5348. 0)))
  5349. (setq s (match-string 1)
  5350. txt nil
  5351. pos (1- (match-beginning 1))
  5352. todo-state (save-match-data (org-get-todo-state))
  5353. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5354. (member todo-state
  5355. org-agenda-repeating-timestamp-show-all))
  5356. d2 (org-time-string-to-absolute
  5357. (match-string 1) d1 'past show-all
  5358. (current-buffer) pos)
  5359. diff (- d2 d1)
  5360. wdays (if suppress-prewarning
  5361. (let ((org-deadline-warning-days suppress-prewarning))
  5362. (org-get-wdays s))
  5363. (org-get-wdays s))
  5364. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5365. upcomingp (and todayp (> diff 0)))
  5366. ;; When to show a deadline in the calendar:
  5367. ;; If the expiration is within wdays warning time.
  5368. ;; Past-due deadlines are only shown on the current date
  5369. (if (and (or (and (<= diff wdays)
  5370. (and todayp (not org-agenda-only-exact-dates)))
  5371. (= diff 0)))
  5372. (save-excursion
  5373. ;; (setq todo-state (org-get-todo-state))
  5374. (setq donep (member todo-state org-done-keywords))
  5375. (if (and donep
  5376. (or org-agenda-skip-deadline-if-done
  5377. (not (= diff 0))))
  5378. (setq txt nil)
  5379. (setq category (org-get-category)
  5380. warntime (org-entry-get (point) "APPT_WARNTIME")
  5381. category-pos (get-text-property (point) 'org-category-position))
  5382. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5383. (setq txt org-agenda-no-heading-message)
  5384. (goto-char (match-end 0))
  5385. (setq pos1 (match-beginning 0))
  5386. (setq tags (org-get-tags-at pos1))
  5387. (setq head (buffer-substring-no-properties
  5388. (point)
  5389. (progn (skip-chars-forward "^\r\n")
  5390. (point))))
  5391. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5392. (setq timestr
  5393. (concat (substring s (match-beginning 1)) " "))
  5394. (setq timestr 'time))
  5395. (setq txt (org-agenda-format-item
  5396. (if (= diff 0)
  5397. (car org-agenda-deadline-leaders)
  5398. (if (functionp
  5399. (nth 1 org-agenda-deadline-leaders))
  5400. (funcall
  5401. (nth 1 org-agenda-deadline-leaders)
  5402. diff date)
  5403. (format (nth 1 org-agenda-deadline-leaders)
  5404. diff)))
  5405. head category tags
  5406. (if (not (= diff 0)) nil timestr)))))
  5407. (when txt
  5408. (setq face (org-agenda-deadline-face dfrac))
  5409. (org-add-props txt props
  5410. 'org-marker (org-agenda-new-marker pos)
  5411. 'warntime warntime
  5412. 'org-hd-marker (org-agenda-new-marker pos1)
  5413. 'priority (+ (- diff)
  5414. (org-get-priority txt))
  5415. 'org-category category
  5416. 'org-category-position category-pos
  5417. 'todo-state todo-state
  5418. 'type (if upcomingp "upcoming-deadline" "deadline")
  5419. 'date (if upcomingp date d2)
  5420. 'face (if donep 'org-agenda-done face)
  5421. 'undone-face face 'done-face 'org-agenda-done)
  5422. (push txt ee))))))
  5423. (nreverse ee)))
  5424. (defun org-agenda-deadline-face (fraction)
  5425. "Return the face to displaying a deadline item.
  5426. FRACTION is what fraction of the head-warning time has passed."
  5427. (let ((faces org-agenda-deadline-faces) f)
  5428. (catch 'exit
  5429. (while (setq f (pop faces))
  5430. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5431. (defun org-agenda-get-scheduled (&optional deadline-results)
  5432. "Return the scheduled information for agenda display."
  5433. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5434. 'org-todo-regexp org-todo-regexp
  5435. 'org-complex-heading-regexp org-complex-heading-regexp
  5436. 'done-face 'org-agenda-done
  5437. 'mouse-face 'highlight
  5438. 'help-echo
  5439. (format "mouse-2 or RET jump to org file %s"
  5440. (abbreviate-file-name buffer-file-name))))
  5441. (regexp org-scheduled-time-regexp)
  5442. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5443. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5444. mm
  5445. (deadline-position-alist
  5446. (mapcar (lambda (a) (and (setq mm (get-text-property
  5447. 0 'org-hd-marker a))
  5448. (cons (marker-position mm) a)))
  5449. deadline-results))
  5450. d2 diff pos pos1 category category-pos tags donep
  5451. ee txt head pastschedp todo-state face timestr s habitp show-all
  5452. did-habit-check-p warntime)
  5453. (goto-char (point-min))
  5454. (while (re-search-forward regexp nil t)
  5455. (catch :skip
  5456. (org-agenda-skip)
  5457. (setq s (match-string 1)
  5458. txt nil
  5459. pos (1- (match-beginning 1))
  5460. todo-state (save-match-data (org-get-todo-state))
  5461. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5462. (member todo-state
  5463. org-agenda-repeating-timestamp-show-all))
  5464. d2 (org-time-string-to-absolute
  5465. (match-string 1) d1 'past show-all
  5466. (current-buffer) pos)
  5467. diff (- d2 d1)
  5468. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5469. (setq pastschedp (and todayp (< diff 0)))
  5470. (setq did-habit-check-p nil)
  5471. ;; When to show a scheduled item in the calendar:
  5472. ;; If it is on or past the date.
  5473. (when (or (and (< diff 0)
  5474. (< (abs diff) org-scheduled-past-days)
  5475. (and todayp (not org-agenda-only-exact-dates)))
  5476. (= diff 0)
  5477. ;; org-is-habit-p uses org-entry-get, which is expansive
  5478. ;; so we go extra mile to only call it once
  5479. (and todayp
  5480. (boundp 'org-habit-show-all-today)
  5481. org-habit-show-all-today
  5482. (setq did-habit-check-p t)
  5483. (setq habitp (and (functionp 'org-is-habit-p)
  5484. (org-is-habit-p)))))
  5485. (save-excursion
  5486. (setq donep (member todo-state org-done-keywords))
  5487. (if (and donep
  5488. (or org-agenda-skip-scheduled-if-done
  5489. (not (= diff 0))
  5490. (and (functionp 'org-is-habit-p)
  5491. (org-is-habit-p))))
  5492. (setq txt nil)
  5493. (setq habitp (if did-habit-check-p habitp
  5494. (and (functionp 'org-is-habit-p)
  5495. (org-is-habit-p))))
  5496. (setq category (org-get-category)
  5497. category-pos (get-text-property (point) 'org-category-position))
  5498. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5499. (setq txt org-agenda-no-heading-message)
  5500. (goto-char (match-end 0))
  5501. (setq pos1 (match-beginning 0))
  5502. (if habitp
  5503. (if (or (not org-habit-show-habits)
  5504. (and (not todayp)
  5505. (boundp 'org-habit-show-habits-only-for-today)
  5506. org-habit-show-habits-only-for-today))
  5507. (throw :skip nil))
  5508. (if (and
  5509. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5510. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5511. pastschedp))
  5512. (setq mm (assoc pos1 deadline-position-alist)))
  5513. (throw :skip nil)))
  5514. (setq tags (org-get-tags-at))
  5515. (setq head (buffer-substring-no-properties
  5516. (point)
  5517. (progn (skip-chars-forward "^\r\n") (point))))
  5518. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5519. (setq timestr
  5520. (concat (substring s (match-beginning 1)) " "))
  5521. (setq timestr 'time))
  5522. (setq txt (org-agenda-format-item
  5523. (if (= diff 0)
  5524. (car org-agenda-scheduled-leaders)
  5525. (format (nth 1 org-agenda-scheduled-leaders)
  5526. (- 1 diff)))
  5527. head category tags
  5528. (if (not (= diff 0)) nil timestr)
  5529. nil habitp))))
  5530. (when txt
  5531. (setq face
  5532. (cond
  5533. ((and (not habitp) pastschedp)
  5534. 'org-scheduled-previously)
  5535. (todayp 'org-scheduled-today)
  5536. (t 'org-scheduled))
  5537. habitp (and habitp (org-habit-parse-todo)))
  5538. (org-add-props txt props
  5539. 'undone-face face
  5540. 'face (if donep 'org-agenda-done face)
  5541. 'org-marker (org-agenda-new-marker pos)
  5542. 'org-hd-marker (org-agenda-new-marker pos1)
  5543. 'type (if pastschedp "past-scheduled" "scheduled")
  5544. 'date (if pastschedp d2 date)
  5545. 'warntime warntime
  5546. 'priority (if habitp
  5547. (org-habit-get-priority habitp)
  5548. (+ 94 (- 5 diff) (org-get-priority txt)))
  5549. 'org-category category
  5550. 'category-position category-pos
  5551. 'org-habit-p habitp
  5552. 'todo-state todo-state)
  5553. (push txt ee))))))
  5554. (nreverse ee)))
  5555. (defun org-agenda-get-blocks ()
  5556. "Return the date-range information for agenda display."
  5557. (let* ((props (list 'face nil
  5558. 'org-not-done-regexp org-not-done-regexp
  5559. 'org-todo-regexp org-todo-regexp
  5560. 'org-complex-heading-regexp org-complex-heading-regexp
  5561. 'mouse-face 'highlight
  5562. 'help-echo
  5563. (format "mouse-2 or RET jump to org file %s"
  5564. (abbreviate-file-name buffer-file-name))))
  5565. (regexp org-tr-regexp)
  5566. (d0 (calendar-absolute-from-gregorian date))
  5567. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5568. todo-state tags pos head donep)
  5569. (goto-char (point-min))
  5570. (while (re-search-forward regexp nil t)
  5571. (catch :skip
  5572. (org-agenda-skip)
  5573. (setq pos (point))
  5574. (let ((start-time (match-string 1))
  5575. (end-time (match-string 2)))
  5576. (setq s1 (match-string 1)
  5577. s2 (match-string 2)
  5578. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5579. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5580. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5581. ;; Only allow days between the limits, because the normal
  5582. ;; date stamps will catch the limits.
  5583. (save-excursion
  5584. (setq todo-state (org-get-todo-state))
  5585. (setq donep (member todo-state org-done-keywords))
  5586. (if (and donep org-agenda-skip-timestamp-if-done)
  5587. (throw :skip t))
  5588. (setq marker (org-agenda-new-marker (point)))
  5589. (setq category (org-get-category)
  5590. category-pos (get-text-property (point) 'org-category-position))
  5591. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5592. (setq txt org-agenda-no-heading-message)
  5593. (goto-char (match-beginning 0))
  5594. (setq hdmarker (org-agenda-new-marker (point)))
  5595. (setq tags (org-get-tags-at))
  5596. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5597. (setq head (match-string 1))
  5598. (let ((remove-re
  5599. (if org-agenda-remove-timeranges-from-blocks
  5600. (concat
  5601. "<" (regexp-quote s1) ".*?>"
  5602. "--"
  5603. "<" (regexp-quote s2) ".*?>")
  5604. nil)))
  5605. (setq txt (org-agenda-format-item
  5606. (format
  5607. (nth (if (= d1 d2) 0 1)
  5608. org-agenda-timerange-leaders)
  5609. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5610. head category tags
  5611. (cond ((and (= d1 d0) (= d2 d0))
  5612. (concat "<" start-time ">--<" end-time ">"))
  5613. ((= d1 d0)
  5614. (concat "<" start-time ">"))
  5615. ((= d2 d0)
  5616. (concat "<" end-time ">")))
  5617. remove-re))))
  5618. (org-add-props txt props
  5619. 'org-marker marker 'org-hd-marker hdmarker
  5620. 'type "block" 'date date
  5621. 'todo-state todo-state
  5622. 'priority (org-get-priority txt) 'org-category category
  5623. 'org-category-position category-pos)
  5624. (push txt ee))))
  5625. (goto-char pos)))
  5626. ;; Sort the entries by expiration date.
  5627. (nreverse ee)))
  5628. ;;; Agenda presentation and sorting
  5629. (defvar org-prefix-has-time nil
  5630. "A flag, set by `org-compile-prefix-format'.
  5631. The flag is set if the currently compiled format contains a `%t'.")
  5632. (defvar org-prefix-has-tag nil
  5633. "A flag, set by `org-compile-prefix-format'.
  5634. The flag is set if the currently compiled format contains a `%T'.")
  5635. (defvar org-prefix-has-effort nil
  5636. "A flag, set by `org-compile-prefix-format'.
  5637. The flag is set if the currently compiled format contains a `%e'.")
  5638. (defvar org-prefix-category-length nil
  5639. "Used by `org-compile-prefix-format' to remember the category field width.")
  5640. (defvar org-prefix-category-max-length nil
  5641. "Used by `org-compile-prefix-format' to remember the category field width.")
  5642. (defun org-agenda-get-category-icon (category)
  5643. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5644. (dolist (entry org-agenda-category-icon-alist)
  5645. (when (org-string-match-p (car entry) category)
  5646. (if (listp (cadr entry))
  5647. (return (cadr entry))
  5648. (return (apply 'create-image (cdr entry)))))))
  5649. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5650. remove-re habitp)
  5651. "Format TXT to be inserted into the agenda buffer.
  5652. In particular, it adds the prefix and corresponding text properties. EXTRA
  5653. must be a string and replaces the `%s' specifier in the prefix format.
  5654. CATEGORY (string, symbol or nil) may be used to overrule the default
  5655. category taken from local variable or file name. It will replace the `%c'
  5656. specifier in the format. DOTIME, when non-nil, indicates that a
  5657. time-of-day should be extracted from TXT for sorting of this entry, and for
  5658. the `%t' specifier in the format. When DOTIME is a string, this string is
  5659. searched for a time before TXT is. TAGS can be the tags of the headline.
  5660. Any match of REMOVE-RE will be removed from TXT."
  5661. ;; We keep the org-prefix-* variable values along with a compiled
  5662. ;; formatter, so that multiple agendas existing at the same time, do
  5663. ;; not step on each other toes.
  5664. ;;
  5665. ;; It was inconvenient to make these variables buffer local in
  5666. ;; Agenda buffers, because this function expects to be called with
  5667. ;; the buffer where item comes from being current, and not agenda
  5668. ;; buffer
  5669. (let* ((bindings (car org-prefix-format-compiled))
  5670. (formatter (cadr org-prefix-format-compiled)))
  5671. (loop for (var value) in bindings
  5672. do (set var value))
  5673. (save-match-data
  5674. ;; Diary entries sometimes have extra whitespace at the beginning
  5675. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5676. ;; Fix the tags part in txt
  5677. (setq txt (org-agenda-fix-displayed-tags
  5678. txt tags
  5679. org-agenda-show-inherited-tags
  5680. org-agenda-hide-tags-regexp))
  5681. (let* ((category (or category
  5682. (if (stringp org-category)
  5683. org-category
  5684. (and org-category (symbol-name org-category)))
  5685. (if buffer-file-name
  5686. (file-name-sans-extension
  5687. (file-name-nondirectory buffer-file-name))
  5688. "")))
  5689. (category-icon (org-agenda-get-category-icon category))
  5690. (category-icon (if category-icon
  5691. (propertize " " 'display category-icon)
  5692. ""))
  5693. ;; time, tag, effort are needed for the eval of the prefix format
  5694. (tag (if tags (nth (1- (length tags)) tags) ""))
  5695. time effort neffort
  5696. (ts (if dotime (concat
  5697. (if (stringp dotime) dotime "")
  5698. (and org-agenda-search-headline-for-time txt))))
  5699. (time-of-day (and dotime (org-get-time-of-day ts)))
  5700. stamp plain s0 s1 s2 rtn srp l
  5701. duration thecategory)
  5702. (and (derived-mode-p 'org-mode) buffer-file-name
  5703. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5704. (when (and dotime time-of-day)
  5705. ;; Extract starting and ending time and move them to prefix
  5706. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5707. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5708. (setq s0 (match-string 0 ts)
  5709. srp (and stamp (match-end 3))
  5710. s1 (match-string (if plain 1 2) ts)
  5711. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5712. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5713. ;; them, we might want to remove them there to avoid duplication.
  5714. ;; The user can turn this off with a variable.
  5715. (if (and org-prefix-has-time
  5716. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5717. (string-match (concat (regexp-quote s0) " *") txt)
  5718. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5719. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5720. (= (match-beginning 0) 0)
  5721. t))
  5722. (setq txt (replace-match "" nil nil txt))))
  5723. ;; Normalize the time(s) to 24 hour
  5724. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5725. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5726. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5727. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5728. (setq s2
  5729. (org-minutes-to-hh:mm-string
  5730. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5731. ;; Compute the duration
  5732. (when s2
  5733. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5734. (org-hh:mm-string-to-minutes s1)))))
  5735. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5736. txt)
  5737. ;; Tags are in the string
  5738. (if (or (eq org-agenda-remove-tags t)
  5739. (and org-agenda-remove-tags
  5740. org-prefix-has-tag))
  5741. (setq txt (replace-match "" t t txt))
  5742. (setq txt (replace-match
  5743. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5744. (match-string 2 txt))
  5745. t t txt))))
  5746. (when (derived-mode-p 'org-mode)
  5747. (setq effort
  5748. (condition-case nil
  5749. (org-get-effort
  5750. (or (get-text-property 0 'org-hd-marker txt)
  5751. (get-text-property 0 'org-marker txt)))
  5752. (error nil)))
  5753. (when effort
  5754. (setq neffort (org-duration-string-to-minutes effort)
  5755. effort (setq effort (concat "[" effort "]")))))
  5756. ;; prevent erroring out with %e format when there is no effort
  5757. (or effort (setq effort ""))
  5758. (when remove-re
  5759. (while (string-match remove-re txt)
  5760. (setq txt (replace-match "" t t txt))))
  5761. ;; Set org-heading property on `txt' to mark the start of the
  5762. ;; heading.
  5763. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5764. ;; Prepare the variables needed in the eval of the compiled format
  5765. (setq time (cond (s2 (concat
  5766. (org-agenda-time-of-day-to-ampm-maybe s1)
  5767. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5768. (if org-agenda-timegrid-use-ampm " ")))
  5769. (s1 (concat
  5770. (org-agenda-time-of-day-to-ampm-maybe s1)
  5771. (if org-agenda-timegrid-use-ampm
  5772. "........ "
  5773. "......")))
  5774. (t ""))
  5775. extra (or (and (not habitp) extra) "")
  5776. category (if (symbolp category) (symbol-name category) category)
  5777. thecategory (copy-sequence category))
  5778. (if (string-match org-bracket-link-regexp category)
  5779. (progn
  5780. (setq l (if (match-end 3)
  5781. (- (match-end 3) (match-beginning 3))
  5782. (- (match-end 1) (match-beginning 1))))
  5783. (when (< l (or org-prefix-category-length 0))
  5784. (setq category (copy-sequence category))
  5785. (org-add-props category nil
  5786. 'extra-space (make-string
  5787. (- org-prefix-category-length l 1) ?\ ))))
  5788. (if (and org-prefix-category-max-length
  5789. (>= (length category) org-prefix-category-max-length))
  5790. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5791. ;; Evaluate the compiled format
  5792. (setq rtn (concat (eval formatter) txt))
  5793. ;; And finally add the text properties
  5794. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5795. (org-add-props rtn nil
  5796. 'org-category (if thecategory (downcase thecategory) category)
  5797. 'tags (mapcar 'org-downcase-keep-props tags)
  5798. 'org-highest-priority org-highest-priority
  5799. 'org-lowest-priority org-lowest-priority
  5800. 'time-of-day time-of-day
  5801. 'duration duration
  5802. 'effort effort
  5803. 'effort-minutes neffort
  5804. 'txt txt
  5805. 'time time
  5806. 'extra extra
  5807. 'format org-prefix-format-compiled
  5808. 'dotime dotime)))))
  5809. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5810. "Remove tags string from TXT, and add a modified list of tags.
  5811. The modified list may contain inherited tags, and tags matched by
  5812. `org-agenda-hide-tags-regexp' will be removed."
  5813. (when (or add-inherited hide-re)
  5814. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5815. (setq txt (substring txt 0 (match-beginning 0))))
  5816. (setq tags
  5817. (delq nil
  5818. (mapcar (lambda (tg)
  5819. (if (or (and hide-re (string-match hide-re tg))
  5820. (and (not add-inherited)
  5821. (get-text-property 0 'inherited tg)))
  5822. nil
  5823. tg))
  5824. tags)))
  5825. (when tags
  5826. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5827. i)
  5828. (setq txt (concat txt " :"
  5829. (mapconcat
  5830. (lambda (x)
  5831. (setq i (get-text-property 0 'inherited x))
  5832. (if (and have-i (not i))
  5833. (progn
  5834. (setq have-i nil)
  5835. (concat ":" x))
  5836. x))
  5837. tags ":")
  5838. (if have-i "::" ":"))))))
  5839. txt)
  5840. (defun org-downcase-keep-props (s)
  5841. (let ((props (text-properties-at 0 s)))
  5842. (setq s (downcase s))
  5843. (add-text-properties 0 (length s) props s)
  5844. s))
  5845. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5846. (defvar org-agenda-sorting-strategy-selected nil)
  5847. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5848. (catch 'exit
  5849. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5850. ((and todayp (member 'today (car org-agenda-time-grid))))
  5851. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5852. ((member 'weekly (car org-agenda-time-grid)))
  5853. (t (throw 'exit list)))
  5854. (let* ((have (delq nil (mapcar
  5855. (lambda (x) (get-text-property 1 'time-of-day x))
  5856. list)))
  5857. (string (nth 1 org-agenda-time-grid))
  5858. (gridtimes (nth 2 org-agenda-time-grid))
  5859. (req (car org-agenda-time-grid))
  5860. (remove (member 'remove-match req))
  5861. new time)
  5862. (if (and (member 'require-timed req) (not have))
  5863. ;; don't show empty grid
  5864. (throw 'exit list))
  5865. (while (setq time (pop gridtimes))
  5866. (unless (and remove (member time have))
  5867. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5868. (push (org-agenda-format-item
  5869. nil string "" nil
  5870. (concat (substring time 0 -2) ":" (substring time -2)))
  5871. new)
  5872. (put-text-property
  5873. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5874. (when (and todayp org-agenda-show-current-time-in-grid)
  5875. (push (org-agenda-format-item
  5876. nil
  5877. org-agenda-current-time-string
  5878. "" nil
  5879. (format-time-string "%H:%M "))
  5880. new)
  5881. (put-text-property
  5882. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5883. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5884. (append new list)
  5885. (append list new)))))
  5886. (defun org-compile-prefix-format (key)
  5887. "Compile the prefix format into a Lisp form that can be evaluated.
  5888. The resulting form and associated variable bindings is returned
  5889. and stored in the variable `org-prefix-format-compiled'."
  5890. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5891. org-prefix-category-length nil
  5892. org-prefix-has-effort nil)
  5893. (let ((s (cond
  5894. ((stringp org-agenda-prefix-format)
  5895. org-agenda-prefix-format)
  5896. ((assq key org-agenda-prefix-format)
  5897. (cdr (assq key org-agenda-prefix-format)))
  5898. (t " %-12:c%?-12t% s")))
  5899. (start 0)
  5900. varform vars var e c f opt)
  5901. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5902. s start)
  5903. (setq var (or (cdr (assoc (match-string 4 s)
  5904. '(("c" . category) ("t" . time) ("s" . extra)
  5905. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5906. 'eval)
  5907. c (or (match-string 3 s) "")
  5908. opt (match-beginning 1)
  5909. start (1+ (match-beginning 0)))
  5910. (if (equal var 'time) (setq org-prefix-has-time t))
  5911. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5912. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5913. (setq f (concat "%" (match-string 2 s) "s"))
  5914. (when (equal var 'category)
  5915. (setq org-prefix-category-length
  5916. (floor (abs (string-to-number (match-string 2 s)))))
  5917. (setq org-prefix-category-max-length
  5918. (let ((x (match-string 2 s)))
  5919. (save-match-data
  5920. (if (string-match "\\.[0-9]+" x)
  5921. (string-to-number (substring (match-string 0 x) 1)))))))
  5922. (if (eq var 'eval)
  5923. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5924. (if opt
  5925. (setq varform
  5926. `(if (equal "" ,var)
  5927. ""
  5928. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5929. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5930. (setq s (replace-match "%s" t nil s))
  5931. (push varform vars))
  5932. (setq vars (nreverse vars))
  5933. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5934. (setq org-prefix-format-compiled
  5935. (list
  5936. `((org-prefix-has-time ,org-prefix-has-time)
  5937. (org-prefix-has-tag ,org-prefix-has-tag)
  5938. (org-prefix-category-length ,org-prefix-category-length)
  5939. (org-prefix-has-effort ,org-prefix-has-effort))
  5940. `(format ,s ,@vars))))))
  5941. (defun org-set-sorting-strategy (key)
  5942. (if (symbolp (car org-agenda-sorting-strategy))
  5943. ;; the old format
  5944. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5945. (setq org-agenda-sorting-strategy-selected
  5946. (or (cdr (assq key org-agenda-sorting-strategy))
  5947. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5948. '(time-up category-keep priority-down)))))
  5949. (defun org-get-time-of-day (s &optional string mod24)
  5950. "Check string S for a time of day.
  5951. If found, return it as a military time number between 0 and 2400.
  5952. If not found, return nil.
  5953. The optional STRING argument forces conversion into a 5 character wide string
  5954. HH:MM."
  5955. (save-match-data
  5956. (when
  5957. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5958. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5959. (let* ((h (string-to-number (match-string 1 s)))
  5960. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5961. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5962. (am-p (equal ampm "am"))
  5963. (h1 (cond ((not ampm) h)
  5964. ((= h 12) (if am-p 0 12))
  5965. (t (+ h (if am-p 0 12)))))
  5966. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5967. (mod h1 24) h1))
  5968. (t0 (+ (* 100 h2) m))
  5969. (t1 (concat (if (>= h1 24) "+" " ")
  5970. (if (and org-agenda-time-leading-zero
  5971. (< t0 1000)) "0" "")
  5972. (if (< t0 100) "0" "")
  5973. (if (< t0 10) "0" "")
  5974. (int-to-string t0))))
  5975. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5976. (defvar org-agenda-before-sorting-filter-function nil
  5977. "Function to be applied to agenda items prior to sorting.
  5978. Prior to sorting also means just before they are inserted into the agenda.
  5979. To aid sorting, you may revisit the original entries and add more text
  5980. properties which will later be used by the sorting functions.
  5981. The function should take a string argument, an agenda line.
  5982. It has access to the text properties in that line, which contain among
  5983. other things, the property `org-hd-marker' that points to the entry
  5984. where the line comes from. Note that not all lines going into the agenda
  5985. have this property, only most.
  5986. The function should return the modified string. It is probably best
  5987. to ONLY change text properties.
  5988. You can also use this function as a filter, by returning nil for lines
  5989. you don't want to have in the agenda at all. For this application, you
  5990. could bind the variable in the options section of a custom command.")
  5991. (defun org-agenda-finalize-entries (list &optional nosort)
  5992. "Sort and concatenate the agenda items."
  5993. (setq list (mapcar 'org-agenda-highlight-todo list))
  5994. (if nosort
  5995. list
  5996. (when org-agenda-before-sorting-filter-function
  5997. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5998. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5999. (defun org-agenda-highlight-todo (x)
  6000. (let ((org-done-keywords org-done-keywords-for-agenda)
  6001. (case-fold-search nil)
  6002. re)
  6003. (if (eq x 'line)
  6004. (save-excursion
  6005. (beginning-of-line 1)
  6006. (setq re (org-get-at-bol 'org-todo-regexp))
  6007. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6008. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6009. (add-text-properties (match-beginning 0) (match-end 1)
  6010. (list 'face (org-get-todo-face 1)))
  6011. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6012. (delete-region (match-beginning 1) (1- (match-end 0)))
  6013. (goto-char (match-beginning 1))
  6014. (insert (format org-agenda-todo-keyword-format s)))))
  6015. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6016. (setq re (get-text-property 0 'org-todo-regexp x))
  6017. (when (and re
  6018. ;; Test `pl' because if there's no heading content,
  6019. ;; there's no point matching to highlight. Note
  6020. ;; that if we didn't test `pl' first, and there
  6021. ;; happened to be no keyword from `org-todo-regexp'
  6022. ;; on this heading line, then the `equal' comparison
  6023. ;; afterwards would spuriously succeed in the case
  6024. ;; where `pl' is nil -- causing an args-out-of-range
  6025. ;; error when we try to add text properties to text
  6026. ;; that isn't there.
  6027. pl
  6028. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6029. x pl) pl))
  6030. (add-text-properties
  6031. (or (match-end 1) (match-end 0)) (match-end 0)
  6032. (list 'face (org-get-todo-face (match-string 2 x)))
  6033. x)
  6034. (when (match-end 1)
  6035. (setq x (concat (substring x 0 (match-end 1))
  6036. (format org-agenda-todo-keyword-format
  6037. (match-string 2 x))
  6038. (org-add-props " " (text-properties-at 0 x))
  6039. (substring x (match-end 3)))))))
  6040. x)))
  6041. (defsubst org-cmp-priority (a b)
  6042. "Compare the priorities of string A and B."
  6043. (let ((pa (or (get-text-property 1 'priority a) 0))
  6044. (pb (or (get-text-property 1 'priority b) 0)))
  6045. (cond ((> pa pb) +1)
  6046. ((< pa pb) -1))))
  6047. (defsubst org-cmp-effort (a b)
  6048. "Compare the effort values of string A and B."
  6049. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6050. (ea (or (get-text-property 1 'effort-minutes a) def))
  6051. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6052. (cond ((> ea eb) +1)
  6053. ((< ea eb) -1))))
  6054. (defsubst org-cmp-category (a b)
  6055. "Compare the string values of categories of strings A and B."
  6056. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6057. (cb (or (get-text-property 1 'org-category b) "")))
  6058. (cond ((string-lessp ca cb) -1)
  6059. ((string-lessp cb ca) +1))))
  6060. (defsubst org-cmp-todo-state (a b)
  6061. "Compare the todo states of strings A and B."
  6062. (let* ((ma (or (get-text-property 1 'org-marker a)
  6063. (get-text-property 1 'org-hd-marker a)))
  6064. (mb (or (get-text-property 1 'org-marker b)
  6065. (get-text-property 1 'org-hd-marker b)))
  6066. (fa (and ma (marker-buffer ma)))
  6067. (fb (and mb (marker-buffer mb)))
  6068. (todo-kwds
  6069. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6070. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6071. (ta (or (get-text-property 1 'todo-state a) ""))
  6072. (tb (or (get-text-property 1 'todo-state b) ""))
  6073. (la (- (length (member ta todo-kwds))))
  6074. (lb (- (length (member tb todo-kwds))))
  6075. (donepa (member ta org-done-keywords-for-agenda))
  6076. (donepb (member tb org-done-keywords-for-agenda)))
  6077. (cond ((and donepa (not donepb)) -1)
  6078. ((and (not donepa) donepb) +1)
  6079. ((< la lb) -1)
  6080. ((< lb la) +1))))
  6081. (defsubst org-cmp-alpha (a b)
  6082. "Compare the headlines, alphabetically."
  6083. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6084. (plb (text-property-any 0 (length b) 'org-heading t b))
  6085. (ta (and pla (substring a pla)))
  6086. (tb (and plb (substring b plb))))
  6087. (when pla
  6088. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6089. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6090. (setq ta (substring ta (match-end 0))))
  6091. (setq ta (downcase ta)))
  6092. (when plb
  6093. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6094. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6095. (setq tb (substring tb (match-end 0))))
  6096. (setq tb (downcase tb)))
  6097. (cond ((not ta) +1)
  6098. ((not tb) -1)
  6099. ((string-lessp ta tb) -1)
  6100. ((string-lessp tb ta) +1))))
  6101. (defsubst org-cmp-tag (a b)
  6102. "Compare the string values of the first tags of A and B."
  6103. (let ((ta (car (last (get-text-property 1 'tags a))))
  6104. (tb (car (last (get-text-property 1 'tags b)))))
  6105. (cond ((not ta) +1)
  6106. ((not tb) -1)
  6107. ((string-lessp ta tb) -1)
  6108. ((string-lessp tb ta) +1))))
  6109. (defsubst org-cmp-time (a b)
  6110. "Compare the time-of-day values of strings A and B."
  6111. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6112. (ta (or (get-text-property 1 'time-of-day a) def))
  6113. (tb (or (get-text-property 1 'time-of-day b) def)))
  6114. (cond ((< ta tb) -1)
  6115. ((< tb ta) +1))))
  6116. (defsubst org-cmp-habit-p (a b)
  6117. "Compare the todo states of strings A and B."
  6118. (let ((ha (get-text-property 1 'org-habit-p a))
  6119. (hb (get-text-property 1 'org-habit-p b)))
  6120. (cond ((and ha (not hb)) -1)
  6121. ((and (not ha) hb) +1))))
  6122. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  6123. (defun org-entries-lessp (a b)
  6124. "Predicate for sorting agenda entries."
  6125. ;; The following variables will be used when the form is evaluated.
  6126. ;; So even though the compiler complains, keep them.
  6127. (let* ((ss org-agenda-sorting-strategy-selected)
  6128. (time-up (and (org-em 'time-up 'time-down ss)
  6129. (org-cmp-time a b)))
  6130. (time-down (if time-up (- time-up) nil))
  6131. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6132. (org-cmp-priority a b)))
  6133. (priority-down (if priority-up (- priority-up) nil))
  6134. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6135. (org-cmp-effort a b)))
  6136. (effort-down (if effort-up (- effort-up) nil))
  6137. (category-up (and (or (org-em 'category-up 'category-down ss)
  6138. (memq 'category-keep ss))
  6139. (org-cmp-category a b)))
  6140. (category-down (if category-up (- category-up) nil))
  6141. (category-keep (if category-up +1 nil))
  6142. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6143. (org-cmp-tag a b)))
  6144. (tag-down (if tag-up (- tag-up) nil))
  6145. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6146. (org-cmp-todo-state a b)))
  6147. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6148. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6149. (org-cmp-habit-p a b)))
  6150. (habit-down (if habit-up (- habit-up) nil))
  6151. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6152. (org-cmp-alpha a b)))
  6153. (alpha-down (if alpha-up (- alpha-up) nil))
  6154. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6155. user-defined-up user-defined-down)
  6156. (if (and need-user-cmp org-agenda-cmp-user-defined
  6157. (functionp org-agenda-cmp-user-defined))
  6158. (setq user-defined-up
  6159. (funcall org-agenda-cmp-user-defined a b)
  6160. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6161. (cdr (assoc
  6162. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6163. '((-1 . t) (1 . nil) (nil . nil))))))
  6164. ;;; Agenda restriction lock
  6165. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6166. "Overlay to mark the headline to which agenda commands are restricted.")
  6167. (overlay-put org-agenda-restriction-lock-overlay
  6168. 'face 'org-agenda-restriction-lock)
  6169. (overlay-put org-agenda-restriction-lock-overlay
  6170. 'help-echo "Agendas are currently limited to this subtree.")
  6171. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6172. (defun org-agenda-set-restriction-lock (&optional type)
  6173. "Set restriction lock for agenda, to current subtree or file.
  6174. Restriction will be the file if TYPE is `file', or if type is the
  6175. universal prefix '(4), or if the cursor is before the first headline
  6176. in the file. Otherwise, restriction will be to the current subtree."
  6177. (interactive "P")
  6178. (and (equal type '(4)) (setq type 'file))
  6179. (setq type (cond
  6180. (type type)
  6181. ((org-at-heading-p) 'subtree)
  6182. ((condition-case nil (org-back-to-heading t) (error nil))
  6183. 'subtree)
  6184. (t 'file)))
  6185. (if (eq type 'subtree)
  6186. (progn
  6187. (setq org-agenda-restrict t)
  6188. (setq org-agenda-overriding-restriction 'subtree)
  6189. (put 'org-agenda-files 'org-restrict
  6190. (list (buffer-file-name (buffer-base-buffer))))
  6191. (org-back-to-heading t)
  6192. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6193. (move-marker org-agenda-restrict-begin (point))
  6194. (move-marker org-agenda-restrict-end
  6195. (save-excursion (org-end-of-subtree t)))
  6196. (message "Locking agenda restriction to subtree"))
  6197. (put 'org-agenda-files 'org-restrict
  6198. (list (buffer-file-name (buffer-base-buffer))))
  6199. (setq org-agenda-restrict nil)
  6200. (setq org-agenda-overriding-restriction 'file)
  6201. (move-marker org-agenda-restrict-begin nil)
  6202. (move-marker org-agenda-restrict-end nil)
  6203. (message "Locking agenda restriction to file"))
  6204. (setq current-prefix-arg nil)
  6205. (org-agenda-maybe-redo))
  6206. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6207. "Remove the agenda restriction lock."
  6208. (interactive "P")
  6209. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6210. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6211. (setq org-agenda-overriding-restriction nil)
  6212. (setq org-agenda-restrict nil)
  6213. (put 'org-agenda-files 'org-restrict nil)
  6214. (move-marker org-agenda-restrict-begin nil)
  6215. (move-marker org-agenda-restrict-end nil)
  6216. (setq current-prefix-arg nil)
  6217. (message "Agenda restriction lock removed")
  6218. (or noupdate (org-agenda-maybe-redo)))
  6219. (defun org-agenda-maybe-redo ()
  6220. "If there is any window showing the agenda view, update it."
  6221. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6222. (w0 (selected-window)))
  6223. (when w
  6224. (select-window w)
  6225. (org-agenda-redo)
  6226. (select-window w0)
  6227. (if org-agenda-overriding-restriction
  6228. (message "Agenda view shifted to new %s restriction"
  6229. org-agenda-overriding-restriction)
  6230. (message "Agenda restriction lock removed")))))
  6231. ;;; Agenda commands
  6232. (defun org-agenda-check-type (error &rest types)
  6233. "Check if agenda buffer is of allowed type.
  6234. If ERROR is non-nil, throw an error, otherwise just return nil."
  6235. (if (not org-agenda-type)
  6236. (error "No Org agenda currently displayed")
  6237. (if (memq org-agenda-type types)
  6238. t
  6239. (if error
  6240. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6241. nil))))
  6242. (defun org-agenda-Quit (&optional arg)
  6243. "Exit agenda by removing the window or the buffer."
  6244. (interactive)
  6245. (if org-agenda-columns-active
  6246. (org-columns-quit)
  6247. (let ((buf (current-buffer)))
  6248. (if (eq org-agenda-window-setup 'other-frame)
  6249. (progn
  6250. (org-agenda-reset-markers)
  6251. (kill-buffer buf)
  6252. (org-columns-remove-overlays)
  6253. (setq org-agenda-archives-mode nil)
  6254. (delete-frame))
  6255. (and (not (eq org-agenda-window-setup 'current-window))
  6256. (not (one-window-p))
  6257. (delete-window))
  6258. (org-agenda-reset-markers)
  6259. (kill-buffer buf)
  6260. (org-columns-remove-overlays)
  6261. (setq org-agenda-archives-mode nil)))
  6262. ;; Maybe restore the pre-agenda window configuration.
  6263. (and org-agenda-restore-windows-after-quit
  6264. (not (eq org-agenda-window-setup 'other-frame))
  6265. org-agenda-pre-window-conf
  6266. (set-window-configuration org-agenda-pre-window-conf)
  6267. (setq org-agenda-pre-window-conf nil))))
  6268. (defun org-agenda-quit ()
  6269. "Exit agenda by killing agenda buffer or burying it when
  6270. `org-agenda-sticky' is non-NIL"
  6271. (interactive)
  6272. (if (and (eq org-indirect-buffer-display 'other-window)
  6273. org-last-indirect-buffer)
  6274. (delete-window (get-buffer-window org-last-indirect-buffer)))
  6275. (if org-agenda-columns-active
  6276. (org-columns-quit)
  6277. (if org-agenda-sticky
  6278. (let ((buf (current-buffer)))
  6279. (if (eq org-agenda-window-setup 'other-frame)
  6280. (progn
  6281. (delete-frame))
  6282. (and (not (eq org-agenda-window-setup 'current-window))
  6283. (not (one-window-p))
  6284. (delete-window)))
  6285. (with-current-buffer buf
  6286. (bury-buffer)
  6287. ;; Maybe restore the pre-agenda window configuration.
  6288. (and org-agenda-restore-windows-after-quit
  6289. (not (eq org-agenda-window-setup 'other-frame))
  6290. org-agenda-pre-window-conf
  6291. (set-window-configuration org-agenda-pre-window-conf)
  6292. (setq org-agenda-pre-window-conf nil))))
  6293. (org-agenda-Quit))))
  6294. (defun org-agenda-exit ()
  6295. "Exit agenda by removing the window or the buffer.
  6296. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6297. Org-mode buffers visited directly by the user will not be touched."
  6298. (interactive)
  6299. (org-release-buffers org-agenda-new-buffers)
  6300. (setq org-agenda-new-buffers nil)
  6301. (org-agenda-Quit))
  6302. (defun org-agenda-kill-all-agenda-buffers ()
  6303. "Kill all buffers in `org-agenda-mode'.
  6304. This is used when toggling sticky agendas. You can also explicitly invoke it
  6305. with `C-c a C-k'."
  6306. (interactive)
  6307. (let (blist)
  6308. (dolist (buf (buffer-list))
  6309. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6310. (push buf blist)))
  6311. (mapc 'kill-buffer blist)))
  6312. (defun org-agenda-execute (arg)
  6313. "Execute another agenda command, keeping same window.
  6314. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6315. in the agenda."
  6316. (interactive "P")
  6317. (let ((org-agenda-window-setup 'current-window))
  6318. (org-agenda arg)))
  6319. (defun org-agenda-redo (&optional all)
  6320. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6321. (interactive "P")
  6322. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6323. (cpa (unless (eq all t) current-prefix-arg))
  6324. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6325. (org-agenda-sticky nil)
  6326. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6327. org-agenda-buffer-name))
  6328. (org-agenda-keep-modes t)
  6329. (tag-filter org-agenda-tag-filter)
  6330. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6331. (top-cat-filter org-agenda-top-category-filter)
  6332. (cat-filter org-agenda-category-filter)
  6333. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6334. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6335. (cols org-agenda-columns-active)
  6336. (line (org-current-line))
  6337. (window-line (- line (org-current-line (window-start))))
  6338. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6339. (redo-cmd (get-text-property p 'org-redo-cmd))
  6340. (last-args (get-text-property p 'org-last-args))
  6341. (org-agenda-overriding-cmd (get-text-property p 'org-series-cmd))
  6342. (org-agenda-overriding-cmd-arguments
  6343. (unless (eq all t)
  6344. (cond ((listp last-args)
  6345. (cons (or cpa (car last-args)) (cdr last-args)))
  6346. ((stringp last-args)
  6347. last-args))))
  6348. (series-redo-cmd (get-text-property p 'org-series-redo-cmd)))
  6349. (put 'org-agenda-tag-filter :preset-filter nil)
  6350. (put 'org-agenda-category-filter :preset-filter nil)
  6351. (and cols (org-columns-quit))
  6352. (message "Rebuilding agenda buffer...")
  6353. (if series-redo-cmd
  6354. (eval series-redo-cmd)
  6355. (org-let lprops '(eval redo-cmd)))
  6356. (setq org-agenda-undo-list nil
  6357. org-agenda-pending-undo-list nil)
  6358. (message "Rebuilding agenda buffer...done")
  6359. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6360. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6361. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6362. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6363. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6364. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6365. (org-goto-line line)
  6366. (recenter window-line)))
  6367. (defvar org-global-tags-completion-table nil)
  6368. (defvar org-agenda-filter-form nil)
  6369. (defvar org-agenda-filtered-by-category nil)
  6370. (defun org-agenda-filter-by-category (strip)
  6371. "Keep only those lines in the agenda buffer that have a specific category.
  6372. The category is that of the current line."
  6373. (interactive "P")
  6374. (if (and org-agenda-filtered-by-category
  6375. org-agenda-category-filter)
  6376. (org-agenda-filter-show-all-cat)
  6377. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6378. (if cat (org-agenda-filter-apply
  6379. (list (concat (if strip "-" "+") cat)) 'category)
  6380. (error "No category at point")))))
  6381. (defun org-find-top-category (&optional pos)
  6382. (save-excursion
  6383. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6384. (if pos (goto-char pos))
  6385. ;; Skip up to the topmost parent
  6386. (while (ignore-errors (outline-up-heading 1) t))
  6387. (ignore-errors
  6388. (nth 4 (org-heading-components))))))
  6389. (defvar org-agenda-filtered-by-top-category nil)
  6390. (defun org-agenda-filter-by-top-category (strip)
  6391. "Keep only those lines in the agenda buffer that have a specific category.
  6392. The category is that of the current line."
  6393. (interactive "P")
  6394. (if org-agenda-filtered-by-top-category
  6395. (progn
  6396. (setq org-agenda-filtered-by-top-category nil
  6397. org-agenda-top-category-filter nil)
  6398. (org-agenda-filter-show-all-cat))
  6399. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6400. (if cat (org-agenda-filter-top-category-apply cat strip)
  6401. (error "No top-level category at point")))))
  6402. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6403. "Keep only those lines in the agenda buffer that have a specific tag.
  6404. The tag is selected with its fast selection letter, as configured.
  6405. With prefix argument STRIP, remove all lines that do have the tag.
  6406. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6407. used to narrow the search - the interactive user can also press `-' or `+'
  6408. to switch to narrowing."
  6409. (interactive "P")
  6410. (let* ((alist org-tag-alist-for-agenda)
  6411. (tag-chars (mapconcat
  6412. (lambda (x) (if (and (not (symbolp (car x)))
  6413. (cdr x))
  6414. (char-to-string (cdr x))
  6415. ""))
  6416. alist ""))
  6417. (efforts (org-split-string
  6418. (or (cdr (assoc (concat org-effort-property "_ALL")
  6419. org-global-properties))
  6420. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6421. "")))
  6422. (effort-op org-agenda-filter-effort-default-operator)
  6423. (effort-prompt "")
  6424. (inhibit-read-only t)
  6425. (current org-agenda-tag-filter)
  6426. maybe-refresh a n tag)
  6427. (unless char
  6428. (message
  6429. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6430. (if narrow "Narrow" "Filter") tag-chars
  6431. (if org-agenda-auto-exclude-function "[RET], " ""))
  6432. (setq char (read-char-exclusive)))
  6433. (when (member char '(?+ ?-))
  6434. ;; Narrowing down
  6435. (cond ((equal char ?-) (setq strip t narrow t))
  6436. ((equal char ?+) (setq strip nil narrow t)))
  6437. (message
  6438. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6439. (setq char (read-char-exclusive)))
  6440. (when (member char '(?< ?> ?= ??))
  6441. ;; An effort operator
  6442. (setq effort-op (char-to-string char))
  6443. (setq alist nil) ; to make sure it will be interpreted as effort.
  6444. (unless (equal char ??)
  6445. (loop for i from 0 to 9 do
  6446. (setq effort-prompt
  6447. (concat
  6448. effort-prompt " ["
  6449. (if (= i 9) "0" (int-to-string (1+ i)))
  6450. "]" (nth i efforts))))
  6451. (message "Effort%s: %s " effort-op effort-prompt)
  6452. (setq char (read-char-exclusive))
  6453. (when (or (< char ?0) (> char ?9))
  6454. (error "Need 1-9,0 to select effort"))))
  6455. (when (equal char ?\t)
  6456. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6457. (org-set-local 'org-global-tags-completion-table
  6458. (org-global-tags-completion-table)))
  6459. (let ((completion-ignore-case t))
  6460. (setq tag (org-icompleting-read
  6461. "Tag: " org-global-tags-completion-table))))
  6462. (cond
  6463. ((equal char ?\r)
  6464. (org-agenda-filter-show-all-tag)
  6465. (when org-agenda-auto-exclude-function
  6466. (setq org-agenda-tag-filter '())
  6467. (dolist (tag (org-agenda-get-represented-tags))
  6468. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6469. (if modifier
  6470. (push modifier org-agenda-tag-filter))))
  6471. (if (not (null org-agenda-tag-filter))
  6472. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6473. (setq maybe-refresh t))
  6474. ((equal char ?/)
  6475. (org-agenda-filter-show-all-tag)
  6476. (when (get 'org-agenda-tag-filter :preset-filter)
  6477. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6478. (setq maybe-refresh t))
  6479. ((equal char ?. )
  6480. (setq org-agenda-tag-filter
  6481. (mapcar (lambda(tag) (concat "+" tag))
  6482. (org-get-at-bol 'tags)))
  6483. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6484. (setq maybe-refresh t))
  6485. ((or (equal char ?\ )
  6486. (setq a (rassoc char alist))
  6487. (and (>= char ?0) (<= char ?9)
  6488. (setq n (if (= char ?0) 9 (- char ?0 1))
  6489. tag (concat effort-op (nth n efforts))
  6490. a (cons tag nil)))
  6491. (and (= char ??)
  6492. (setq tag "?eff")
  6493. a (cons tag nil))
  6494. (and tag (setq a (cons tag nil))))
  6495. (org-agenda-filter-show-all-tag)
  6496. (setq tag (car a))
  6497. (setq org-agenda-tag-filter
  6498. (cons (concat (if strip "-" "+") tag)
  6499. (if narrow current nil)))
  6500. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6501. (setq maybe-refresh t))
  6502. (t (error "Invalid tag selection character %c" char)))
  6503. (when (and maybe-refresh
  6504. (eq org-agenda-clockreport-mode 'with-filter))
  6505. (org-agenda-redo))))
  6506. (defun org-agenda-get-represented-tags ()
  6507. "Get a list of all tags currently represented in the agenda."
  6508. (let (p tags)
  6509. (save-excursion
  6510. (goto-char (point-min))
  6511. (while (setq p (next-single-property-change (point) 'tags))
  6512. (goto-char p)
  6513. (mapc (lambda (x) (add-to-list 'tags x))
  6514. (get-text-property (point) 'tags))))
  6515. tags))
  6516. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6517. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6518. (interactive "P")
  6519. (org-agenda-filter-by-tag strip char 'refine))
  6520. (defun org-agenda-filter-make-matcher ()
  6521. "Create the form that tests a line for agenda filter."
  6522. (let (f f1)
  6523. ;; first compute the tag-filter matcher
  6524. (dolist (x (delete-dups
  6525. (append (get 'org-agenda-tag-filter
  6526. :preset-filter) org-agenda-tag-filter)))
  6527. (if (member x '("-" "+"))
  6528. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6529. (if (string-match "[<=>?]" x)
  6530. (setq f1 (org-agenda-filter-effort-form x))
  6531. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6532. (if (equal (string-to-char x) ?-)
  6533. (setq f1 (list 'not f1))))
  6534. (push f1 f))
  6535. ;; then compute the category-filter matcher
  6536. (dolist (x (delete-dups
  6537. (append (get 'org-agenda-category-filter
  6538. :preset-filter) org-agenda-category-filter)))
  6539. (if (equal "-" (substring x 0 1))
  6540. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6541. (setq f1 (list 'equal (substring x 1) 'cat)))
  6542. (push f1 f))
  6543. (cons 'and (nreverse f))))
  6544. (defun org-agenda-filter-effort-form (e)
  6545. "Return the form to compare the effort of the current line with what E says.
  6546. E looks like \"+<2:25\"."
  6547. (let (op)
  6548. (setq e (substring e 1))
  6549. (setq op (string-to-char e) e (substring e 1))
  6550. (setq op (cond ((equal op ?<) '<=)
  6551. ((equal op ?>) '>=)
  6552. ((equal op ??) op)
  6553. (t '=)))
  6554. (list 'org-agenda-compare-effort (list 'quote op)
  6555. (org-duration-string-to-minutes e))))
  6556. (defun org-agenda-compare-effort (op value)
  6557. "Compare the effort of the current line with VALUE, using OP.
  6558. If the line does not have an effort defined, return nil."
  6559. (let ((eff (org-get-at-bol 'effort-minutes)))
  6560. (if (equal op ??)
  6561. (not eff)
  6562. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6563. value))))
  6564. (defun org-agenda-filter-apply (filter type)
  6565. "Set FILTER as the new agenda filter and apply it."
  6566. (let (tags cat)
  6567. (if (eq type 'tag)
  6568. (setq org-agenda-tag-filter filter)
  6569. (setq org-agenda-category-filter filter))
  6570. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6571. (if (and (eq type 'category)
  6572. (not (equal (substring (car filter) 0 1) "-")))
  6573. ;; Only set `org-agenda-filtered-by-category' to t
  6574. ;; when a unique category is used as the filter
  6575. (setq org-agenda-filtered-by-category t))
  6576. (org-agenda-set-mode-name)
  6577. (save-excursion
  6578. (goto-char (point-min))
  6579. (while (not (eobp))
  6580. (if (org-get-at-bol 'org-marker)
  6581. (progn
  6582. (setq tags (org-get-at-bol 'tags) ; used in eval
  6583. cat (get-text-property (point) 'org-category))
  6584. (if (not (eval org-agenda-filter-form))
  6585. (org-agenda-filter-hide-line type))
  6586. (beginning-of-line 2))
  6587. (beginning-of-line 2))))
  6588. (if (get-char-property (point) 'invisible)
  6589. (ignore-errors (org-agenda-previous-line)))))
  6590. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6591. "Set FILTER as the new agenda filter and apply it."
  6592. (org-agenda-set-mode-name)
  6593. (save-excursion
  6594. (goto-char (point-min))
  6595. (while (not (eobp))
  6596. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6597. (topcat (and pos (org-find-top-category pos))))
  6598. (if (and topcat (funcall (if negative 'identity 'not)
  6599. (string= category topcat)))
  6600. (org-agenda-filter-hide-line 'category)))
  6601. (beginning-of-line 2)))
  6602. (if (get-char-property (point) 'invisible)
  6603. (org-agenda-previous-line))
  6604. (setq org-agenda-top-category-filter category
  6605. org-agenda-filtered-by-top-category t))
  6606. (defun org-agenda-filter-hide-line (type)
  6607. (let (ov)
  6608. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6609. (point-at-eol)))
  6610. (overlay-put ov 'invisible t)
  6611. (overlay-put ov 'type type)
  6612. (if (eq type 'tag)
  6613. (push ov org-agenda-tag-filter-overlays)
  6614. (push ov org-agenda-cat-filter-overlays))))
  6615. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6616. (setq pos (or pos (point)))
  6617. (save-excursion
  6618. (dolist (ov (overlays-at pos))
  6619. (when (and (overlay-get ov 'invisible)
  6620. (eq (overlay-get ov 'type) 'tag))
  6621. (goto-char pos)
  6622. (if (< (overlay-start ov) (point-at-eol))
  6623. (move-overlay ov (point-at-eol)
  6624. (overlay-end ov)))))))
  6625. (defun org-agenda-filter-show-all-tag nil
  6626. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6627. (setq org-agenda-tag-filter-overlays nil
  6628. org-agenda-tag-filter nil
  6629. org-agenda-filter-form nil)
  6630. (org-agenda-set-mode-name))
  6631. (defun org-agenda-filter-show-all-cat nil
  6632. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6633. (setq org-agenda-cat-filter-overlays nil
  6634. org-agenda-filtered-by-category nil
  6635. org-agenda-category-filter nil
  6636. org-agenda-filter-form nil)
  6637. (org-agenda-set-mode-name))
  6638. (defun org-agenda-manipulate-query-add ()
  6639. "Manipulate the query by adding a search term with positive selection.
  6640. Positive selection means the term must be matched for selection of an entry."
  6641. (interactive)
  6642. (org-agenda-manipulate-query ?\[))
  6643. (defun org-agenda-manipulate-query-subtract ()
  6644. "Manipulate the query by adding a search term with negative selection.
  6645. Negative selection means term must not be matched for selection of an entry."
  6646. (interactive)
  6647. (org-agenda-manipulate-query ?\]))
  6648. (defun org-agenda-manipulate-query-add-re ()
  6649. "Manipulate the query by adding a search regexp with positive selection.
  6650. Positive selection means the regexp must match for selection of an entry."
  6651. (interactive)
  6652. (org-agenda-manipulate-query ?\{))
  6653. (defun org-agenda-manipulate-query-subtract-re ()
  6654. "Manipulate the query by adding a search regexp with negative selection.
  6655. Negative selection means regexp must not match for selection of an entry."
  6656. (interactive)
  6657. (org-agenda-manipulate-query ?\}))
  6658. (defun org-agenda-manipulate-query (char)
  6659. (cond
  6660. ((memq org-agenda-type '(timeline agenda))
  6661. (let ((org-agenda-include-inactive-timestamps t))
  6662. (org-agenda-redo))
  6663. (message "Display now includes inactive timestamps as well"))
  6664. ((eq org-agenda-type 'search)
  6665. (org-add-to-string
  6666. 'org-agenda-query-string
  6667. (if org-agenda-last-search-view-search-was-boolean
  6668. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6669. (?\{ . " +{}") (?\} . " -{}"))))
  6670. " "))
  6671. (setq org-agenda-redo-command
  6672. (list 'org-search-view
  6673. (car (get-text-property (min (1- (point-max)) (point))
  6674. 'org-last-args))
  6675. org-agenda-query-string
  6676. (+ (length org-agenda-query-string)
  6677. (if (member char '(?\{ ?\})) 0 1))))
  6678. (set-register org-agenda-query-register org-agenda-query-string)
  6679. (let ((org-agenda-overriding-arguments
  6680. (cdr org-agenda-redo-command)))
  6681. (org-agenda-redo)))
  6682. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6683. org-agenda-type))))
  6684. (defun org-add-to-string (var string)
  6685. (set var (concat (symbol-value var) string)))
  6686. (defun org-agenda-goto-date (span)
  6687. "Jump to DATE in agenda."
  6688. (interactive "P")
  6689. (let* ((org-read-date-prefer-future
  6690. (eval org-agenda-jump-prefer-future))
  6691. (date (org-read-date))
  6692. (org-agenda-sticky-orig org-agenda-sticky)
  6693. (org-agenda-buffer-tmp-name (buffer-name))
  6694. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6695. (0-arg (or current-prefix-arg (car args)))
  6696. (2-arg (nth 2 args))
  6697. (newcmd (list 'org-agenda-list 0-arg date
  6698. (org-agenda-span-to-ndays 2-arg)))
  6699. (newargs (cdr newcmd))
  6700. (inhibit-read-only t)
  6701. org-agenda-sticky)
  6702. (if (not (org-agenda-check-type t 'agenda))
  6703. (error "Not available in non-agenda blocks")
  6704. (add-text-properties (point-min) (point-max)
  6705. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6706. (org-agenda-redo)
  6707. (setq org-agenda-sticky org-agenda-sticky-orig
  6708. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6709. (defun org-agenda-goto-today ()
  6710. "Go to today."
  6711. (interactive)
  6712. (org-agenda-check-type t 'timeline 'agenda)
  6713. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6714. (curspan (nth 2 args))
  6715. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6716. (cond
  6717. (tdpos (goto-char tdpos))
  6718. ((eq org-agenda-type 'agenda)
  6719. (let* ((sd (org-agenda-compute-starting-span
  6720. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6721. (org-agenda-overriding-arguments args))
  6722. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6723. (org-agenda-redo)
  6724. (org-agenda-find-same-or-today-or-agenda)))
  6725. (t (error "Cannot find today")))))
  6726. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6727. (goto-char
  6728. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6729. (text-property-any (point-min) (point-max) 'org-today t)
  6730. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6731. (and (get-text-property (min (1- (point-max)) (point)) 'org-series)
  6732. (org-agenda-goto-block-beginning))
  6733. (point-min))))
  6734. (defun org-agenda-goto-block-beginning ()
  6735. "Go the agenda block beginning."
  6736. (interactive)
  6737. (if (not (derived-mode-p 'org-agenda-mode))
  6738. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6739. (let (dest)
  6740. (save-excursion
  6741. (unless (looking-at "\\'")
  6742. (forward-char))
  6743. (let* ((prop 'org-agenda-structural-header)
  6744. (p (previous-single-property-change (point) prop))
  6745. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6746. (1- (point))) prop)))
  6747. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6748. (if (not dest)
  6749. (error "Cannot find the beginning of the blog")
  6750. (goto-char dest)
  6751. (move-beginning-of-line 1)))))
  6752. (defun org-agenda-later (arg)
  6753. "Go forward in time by the current span.
  6754. With prefix ARG, go forward that many times the current span."
  6755. (interactive "p")
  6756. (org-agenda-check-type t 'agenda)
  6757. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6758. (span (or (nth 2 args) org-agenda-current-span))
  6759. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6760. (greg (calendar-gregorian-from-absolute sd))
  6761. (cnt (org-get-at-bol 'org-day-cnt))
  6762. greg2)
  6763. (cond
  6764. ((numberp span)
  6765. (setq sd (+ (* span arg) sd)))
  6766. ((eq span 'day)
  6767. (setq sd (+ arg sd)))
  6768. ((eq span 'week)
  6769. (setq sd (+ (* 7 arg) sd)))
  6770. ((eq span 'month)
  6771. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6772. sd (calendar-absolute-from-gregorian greg2))
  6773. (setcar greg2 (1+ (car greg2))))
  6774. ((eq span 'year)
  6775. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6776. sd (calendar-absolute-from-gregorian greg2))
  6777. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6778. (t
  6779. (setq sd (+ (* span arg) sd))))
  6780. (let ((org-agenda-overriding-cmd
  6781. ;; `cmd' may have been set by `org-agenda-run-series' which
  6782. ;; uses `org-agenda-overriding-cmd' to decide whether
  6783. ;; overriding is allowed for `cmd'
  6784. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  6785. (org-agenda-overriding-arguments
  6786. (list (car args) sd span)))
  6787. (org-agenda-redo)
  6788. (org-agenda-find-same-or-today-or-agenda cnt))))
  6789. (defun org-agenda-earlier (arg)
  6790. "Go backward in time by the current span.
  6791. With prefix ARG, go backward that many times the current span."
  6792. (interactive "p")
  6793. (org-agenda-later (- arg)))
  6794. (defun org-agenda-view-mode-dispatch ()
  6795. "Call one of the view mode commands."
  6796. (interactive)
  6797. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6798. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6799. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6800. (let ((a (read-char-exclusive)))
  6801. (case a
  6802. (?\ (call-interactively 'org-agenda-reset-view))
  6803. (?d (call-interactively 'org-agenda-day-view))
  6804. (?w (call-interactively 'org-agenda-week-view))
  6805. (?m (call-interactively 'org-agenda-month-view))
  6806. (?y (call-interactively 'org-agenda-year-view))
  6807. (?l (call-interactively 'org-agenda-log-mode))
  6808. (?L (org-agenda-log-mode '(4)))
  6809. (?c (org-agenda-log-mode 'clockcheck))
  6810. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6811. (?a (call-interactively 'org-agenda-archives-mode))
  6812. (?A (org-agenda-archives-mode 'files))
  6813. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6814. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6815. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6816. (?D (call-interactively 'org-agenda-toggle-diary))
  6817. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6818. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6819. (org-agenda-check-type t 'timeline 'agenda)
  6820. (org-agenda-redo))
  6821. (message "Display now includes inactive timestamps as well"))
  6822. (?q (message "Abort"))
  6823. (otherwise (error "Invalid key" )))))
  6824. (defun org-agenda-reset-view ()
  6825. "Switch to default view for agenda."
  6826. (interactive)
  6827. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6828. (defun org-agenda-day-view (&optional day-of-year)
  6829. "Switch to daily view for agenda.
  6830. With argument DAY-OF-YEAR, switch to that day of the year."
  6831. (interactive "P")
  6832. (org-agenda-change-time-span 'day day-of-year))
  6833. (defun org-agenda-week-view (&optional iso-week)
  6834. "Switch to daily view for agenda.
  6835. With argument ISO-WEEK, switch to the corresponding ISO week.
  6836. If ISO-WEEK has more then 2 digits, only the last two encode the
  6837. week. Any digits before this encode a year. So 200712 means
  6838. week 12 of year 2007. Years in the range 1938-2037 can also be
  6839. written as 2-digit years."
  6840. (interactive "P")
  6841. (org-agenda-change-time-span 'week iso-week))
  6842. (defun org-agenda-month-view (&optional month)
  6843. "Switch to monthly view for agenda.
  6844. With argument MONTH, switch to that month."
  6845. (interactive "P")
  6846. (org-agenda-change-time-span 'month month))
  6847. (defun org-agenda-year-view (&optional year)
  6848. "Switch to yearly view for agenda.
  6849. With argument YEAR, switch to that year.
  6850. If MONTH has more then 2 digits, only the last two encode the
  6851. month. Any digits before this encode a year. So 200712 means
  6852. December year 2007. Years in the range 1938-2037 can also be
  6853. written as 2-digit years."
  6854. (interactive "P")
  6855. (when year
  6856. (setq year (org-small-year-to-year year)))
  6857. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6858. (org-agenda-change-time-span 'year year)
  6859. (error "Abort")))
  6860. (defun org-agenda-change-time-span (span &optional n)
  6861. "Change the agenda view to SPAN.
  6862. SPAN may be `day', `week', `month', `year'."
  6863. (org-agenda-check-type t 'agenda)
  6864. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6865. (curspan (nth 2 args)))
  6866. (if (and (not n) (equal curspan span))
  6867. (error "Viewing span is already \"%s\"" span))
  6868. (let* ((sd (or (org-get-at-bol 'day)
  6869. (nth 1 args)
  6870. org-starting-day))
  6871. (sd (org-agenda-compute-starting-span sd span n))
  6872. (org-agenda-overriding-cmd
  6873. (get-text-property (min (1- (point-max)) (point)) 'org-series-cmd))
  6874. (org-agenda-overriding-arguments
  6875. (list (car args) sd span)))
  6876. (org-agenda-redo)
  6877. (org-agenda-find-same-or-today-or-agenda))
  6878. (org-agenda-set-mode-name)
  6879. (message "Switched to %s view" span)))
  6880. (defun org-agenda-compute-starting-span (sd span &optional n)
  6881. "Compute starting date for agenda.
  6882. SPAN may be `day', `week', `month', `year'. The return value
  6883. is a cons cell with the starting date and the number of days,
  6884. so that the date SD will be in that range."
  6885. (let* ((greg (calendar-gregorian-from-absolute sd))
  6886. (dg (nth 1 greg))
  6887. (mg (car greg))
  6888. (yg (nth 2 greg)))
  6889. (cond
  6890. ((eq span 'day)
  6891. (when n
  6892. (setq sd (+ (calendar-absolute-from-gregorian
  6893. (list mg 1 yg))
  6894. n -1))))
  6895. ((eq span 'week)
  6896. (let* ((nt (calendar-day-of-week
  6897. (calendar-gregorian-from-absolute sd)))
  6898. (d (if org-agenda-start-on-weekday
  6899. (- nt org-agenda-start-on-weekday)
  6900. 0))
  6901. y1)
  6902. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6903. (when n
  6904. (require 'cal-iso)
  6905. (when (> n 99)
  6906. (setq y1 (org-small-year-to-year (/ n 100))
  6907. n (mod n 100)))
  6908. (setq sd
  6909. (calendar-absolute-from-iso
  6910. (list n 1
  6911. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6912. ((eq span 'month)
  6913. (let (y1)
  6914. (when (and n (> n 99))
  6915. (setq y1 (org-small-year-to-year (/ n 100))
  6916. n (mod n 100)))
  6917. (setq sd (calendar-absolute-from-gregorian
  6918. (list (or n mg) 1 (or y1 yg))))))
  6919. ((eq span 'year)
  6920. (setq sd (calendar-absolute-from-gregorian
  6921. (list 1 1 (or n yg))))))
  6922. sd))
  6923. (defun org-agenda-next-date-line (&optional arg)
  6924. "Jump to the next line indicating a date in agenda buffer."
  6925. (interactive "p")
  6926. (org-agenda-check-type t 'agenda 'timeline)
  6927. (beginning-of-line 1)
  6928. ;; This does not work if user makes date format that starts with a blank
  6929. (if (looking-at "^\\S-") (forward-char 1))
  6930. (if (not (re-search-forward "^\\S-" nil t arg))
  6931. (progn
  6932. (backward-char 1)
  6933. (error "No next date after this line in this buffer")))
  6934. (goto-char (match-beginning 0)))
  6935. (defun org-agenda-previous-date-line (&optional arg)
  6936. "Jump to the previous line indicating a date in agenda buffer."
  6937. (interactive "p")
  6938. (org-agenda-check-type t 'agenda 'timeline)
  6939. (beginning-of-line 1)
  6940. (if (not (re-search-backward "^\\S-" nil t arg))
  6941. (error "No previous date before this line in this buffer")))
  6942. ;; Initialize the highlight
  6943. (defvar org-hl (make-overlay 1 1))
  6944. (overlay-put org-hl 'face 'highlight)
  6945. (defun org-highlight (begin end &optional buffer)
  6946. "Highlight a region with overlay."
  6947. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6948. (defun org-unhighlight ()
  6949. "Detach overlay INDEX."
  6950. (org-detach-overlay org-hl))
  6951. (defun org-unhighlight-once ()
  6952. "Remove the highlight from its position, and this function from the hook."
  6953. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6954. (org-unhighlight))
  6955. (defvar org-agenda-pre-follow-window-conf nil)
  6956. (defun org-agenda-follow-mode ()
  6957. "Toggle follow mode in an agenda buffer."
  6958. (interactive)
  6959. (unless org-agenda-follow-mode
  6960. (setq org-agenda-pre-follow-window-conf
  6961. (current-window-configuration)))
  6962. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6963. (unless org-agenda-follow-mode
  6964. (set-window-configuration org-agenda-pre-follow-window-conf))
  6965. (org-agenda-set-mode-name)
  6966. (org-agenda-do-context-action)
  6967. (message "Follow mode is %s"
  6968. (if org-agenda-follow-mode "on" "off")))
  6969. (defun org-agenda-entry-text-mode (&optional arg)
  6970. "Toggle entry text mode in an agenda buffer."
  6971. (interactive "P")
  6972. (setq org-agenda-entry-text-mode (or (integerp arg)
  6973. (not org-agenda-entry-text-mode)))
  6974. (org-agenda-entry-text-hide)
  6975. (and org-agenda-entry-text-mode
  6976. (let ((org-agenda-entry-text-maxlines
  6977. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6978. (org-agenda-entry-text-show)))
  6979. (org-agenda-set-mode-name)
  6980. (message "Entry text mode is %s. Maximum number of lines is %d"
  6981. (if org-agenda-entry-text-mode "on" "off")
  6982. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6983. (defun org-agenda-clockreport-mode (&optional with-filter)
  6984. "Toggle clocktable mode in an agenda buffer.
  6985. With prefix arg WITH-FILTER, make the clocktable respect the current
  6986. agenda filter."
  6987. (interactive "P")
  6988. (org-agenda-check-type t 'agenda)
  6989. (if with-filter
  6990. (setq org-agenda-clockreport-mode 'with-filter)
  6991. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6992. (org-agenda-set-mode-name)
  6993. (org-agenda-redo)
  6994. (message "Clocktable mode is %s"
  6995. (if org-agenda-clockreport-mode "on" "off")))
  6996. (defun org-agenda-log-mode (&optional special)
  6997. "Toggle log mode in an agenda buffer.
  6998. With argument SPECIAL, show all possible log items, not only the ones
  6999. configured in `org-agenda-log-mode-items'.
  7000. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7001. (interactive "P")
  7002. (org-agenda-check-type t 'agenda 'timeline)
  7003. (setq org-agenda-show-log
  7004. (cond
  7005. ((equal special '(16)) 'only)
  7006. ((eq special 'clockcheck)
  7007. (if (eq org-agenda-show-log 'clockcheck)
  7008. nil 'clockcheck))
  7009. (special '(closed clock state))
  7010. (t (not org-agenda-show-log))))
  7011. (org-agenda-set-mode-name)
  7012. (org-agenda-redo)
  7013. (message "Log mode is %s"
  7014. (if org-agenda-show-log "on" "off")))
  7015. (defun org-agenda-archives-mode (&optional with-files)
  7016. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7017. When called with a prefix argument, include all archive files as well."
  7018. (interactive "P")
  7019. (setq org-agenda-archives-mode
  7020. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7021. (org-agenda-set-mode-name)
  7022. (org-agenda-redo)
  7023. (message
  7024. "%s"
  7025. (cond
  7026. ((eq org-agenda-archives-mode nil)
  7027. "No archives are included")
  7028. ((eq org-agenda-archives-mode 'trees)
  7029. (format "Trees with :%s: tag are included" org-archive-tag))
  7030. ((eq org-agenda-archives-mode t)
  7031. (format "Trees with :%s: tag and all active archive files are included"
  7032. org-archive-tag)))))
  7033. (defun org-agenda-toggle-diary ()
  7034. "Toggle diary inclusion in an agenda buffer."
  7035. (interactive)
  7036. (org-agenda-check-type t 'agenda)
  7037. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7038. (org-agenda-redo)
  7039. (org-agenda-set-mode-name)
  7040. (message "Diary inclusion turned %s"
  7041. (if org-agenda-include-diary "on" "off")))
  7042. (defun org-agenda-toggle-deadlines ()
  7043. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7044. (interactive)
  7045. (org-agenda-check-type t 'agenda)
  7046. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7047. (org-agenda-redo)
  7048. (org-agenda-set-mode-name)
  7049. (message "Deadlines inclusion turned %s"
  7050. (if org-agenda-include-deadlines "on" "off")))
  7051. (defun org-agenda-toggle-time-grid ()
  7052. "Toggle time grid in an agenda buffer."
  7053. (interactive)
  7054. (org-agenda-check-type t 'agenda)
  7055. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7056. (org-agenda-redo)
  7057. (org-agenda-set-mode-name)
  7058. (message "Time-grid turned %s"
  7059. (if org-agenda-use-time-grid "on" "off")))
  7060. (defun org-agenda-set-mode-name ()
  7061. "Set the mode name to indicate all the small mode settings."
  7062. (setq mode-name
  7063. (list "Org-Agenda"
  7064. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7065. " "
  7066. '(:eval (org-agenda-span-name org-agenda-current-span))
  7067. (if org-agenda-follow-mode " Follow" "")
  7068. (if org-agenda-entry-text-mode " ETxt" "")
  7069. (if org-agenda-include-diary " Diary" "")
  7070. (if org-agenda-include-deadlines " Ddl" "")
  7071. (if org-agenda-use-time-grid " Grid" "")
  7072. (if (and (boundp 'org-habit-show-habits)
  7073. org-habit-show-habits) " Habit" "")
  7074. (cond
  7075. ((consp org-agenda-show-log) " LogAll")
  7076. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7077. (org-agenda-show-log " Log")
  7078. (t ""))
  7079. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7080. :preset-filter))
  7081. '(:eval (org-propertize
  7082. (concat " <"
  7083. (mapconcat
  7084. 'identity
  7085. (append
  7086. (get 'org-agenda-category-filter :preset-filter)
  7087. org-agenda-category-filter)
  7088. "")
  7089. ">")
  7090. 'face 'org-agenda-filter-category
  7091. 'help-echo "Category used in filtering"))
  7092. "")
  7093. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7094. :preset-filter))
  7095. '(:eval (org-propertize
  7096. (concat " {"
  7097. (mapconcat
  7098. 'identity
  7099. (append
  7100. (get 'org-agenda-tag-filter :preset-filter)
  7101. org-agenda-tag-filter)
  7102. "")
  7103. "}")
  7104. 'face 'org-agenda-filter-tags
  7105. 'help-echo "Tags used in filtering"))
  7106. "")
  7107. (if org-agenda-archives-mode
  7108. (if (eq org-agenda-archives-mode t)
  7109. " Archives"
  7110. (format " :%s:" org-archive-tag))
  7111. "")
  7112. (if org-agenda-clockreport-mode
  7113. (if (eq org-agenda-clockreport-mode 'with-filter)
  7114. " Clock{}" " Clock")
  7115. "")))
  7116. (force-mode-line-update))
  7117. (define-obsolete-function-alias
  7118. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7119. (defun org-agenda-update-agenda-type ()
  7120. "Update the agenda type after each command."
  7121. (setq org-agenda-type
  7122. (or (get-text-property (point) 'org-agenda-type)
  7123. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7124. (defun org-agenda-next-line ()
  7125. "Move cursor to the next line, and show if follow mode is active."
  7126. (interactive)
  7127. (call-interactively 'next-line)
  7128. (org-agenda-do-context-action))
  7129. (defun org-agenda-previous-line ()
  7130. "Move cursor to the previous line, and show if follow-mode is active."
  7131. (interactive)
  7132. (call-interactively 'previous-line)
  7133. (org-agenda-do-context-action))
  7134. (defun org-agenda-next-item (n)
  7135. "Move cursor to next agenda item."
  7136. (interactive "p")
  7137. (let ((col (current-column)))
  7138. (dotimes (c n)
  7139. (when (next-single-property-change (point-at-eol) 'org-marker)
  7140. (move-end-of-line 1)
  7141. (goto-char (next-single-property-change (point) 'org-marker))))
  7142. (org-move-to-column col))
  7143. (org-agenda-do-context-action))
  7144. (defun org-agenda-previous-item (n)
  7145. "Move cursor to next agenda item."
  7146. (interactive "p")
  7147. (dotimes (c n)
  7148. (let ((col (current-column))
  7149. (goto (save-excursion
  7150. (move-end-of-line 0)
  7151. (previous-single-property-change (point) 'org-marker))))
  7152. (if goto (goto-char goto))
  7153. (org-move-to-column col)))
  7154. (org-agenda-do-context-action))
  7155. (defun org-agenda-do-context-action ()
  7156. "Show outline path and, maybe, follow mode window."
  7157. (let ((m (org-get-at-bol 'org-marker)))
  7158. (when (and (markerp m) (marker-buffer m))
  7159. (and org-agenda-follow-mode
  7160. (if org-agenda-follow-indirect
  7161. (org-agenda-tree-to-indirect-buffer nil)
  7162. (org-agenda-show)))
  7163. (and org-agenda-show-outline-path
  7164. (org-with-point-at m (org-display-outline-path t))))))
  7165. (defun org-agenda-show-tags ()
  7166. "Show the tags applicable to the current item."
  7167. (interactive)
  7168. (let* ((tags (org-get-at-bol 'tags)))
  7169. (if tags
  7170. (message "Tags are :%s:"
  7171. (org-no-properties (mapconcat 'identity tags ":")))
  7172. (message "No tags associated with this line"))))
  7173. (defun org-agenda-goto (&optional highlight)
  7174. "Go to the Org-mode file which contains the item at point."
  7175. (interactive)
  7176. (let* ((marker (or (org-get-at-bol 'org-marker)
  7177. (org-agenda-error)))
  7178. (buffer (marker-buffer marker))
  7179. (pos (marker-position marker)))
  7180. (switch-to-buffer-other-window buffer)
  7181. (widen)
  7182. (push-mark)
  7183. (goto-char pos)
  7184. (when (derived-mode-p 'org-mode)
  7185. (org-show-context 'agenda)
  7186. (save-excursion
  7187. (and (outline-next-heading)
  7188. (org-flag-heading nil)))) ; show the next heading
  7189. (when (outline-invisible-p)
  7190. (show-entry)) ; display invisible text
  7191. (recenter (/ (window-height) 2))
  7192. (run-hooks 'org-agenda-after-show-hook)
  7193. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7194. (defvar org-agenda-after-show-hook nil
  7195. "Normal hook run after an item has been shown from the agenda.
  7196. Point is in the buffer where the item originated.")
  7197. (defun org-agenda-kill ()
  7198. "Kill the entry or subtree belonging to the current agenda entry."
  7199. (interactive)
  7200. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7201. (let* ((bufname-orig (buffer-name))
  7202. (marker (or (org-get-at-bol 'org-marker)
  7203. (org-agenda-error)))
  7204. (buffer (marker-buffer marker))
  7205. (pos (marker-position marker))
  7206. (type (org-get-at-bol 'type))
  7207. dbeg dend (n 0) conf)
  7208. (org-with-remote-undo buffer
  7209. (with-current-buffer buffer
  7210. (save-excursion
  7211. (goto-char pos)
  7212. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7213. (setq dbeg (progn (org-back-to-heading t) (point))
  7214. dend (org-end-of-subtree t t))
  7215. (setq dbeg (point-at-bol)
  7216. dend (min (point-max) (1+ (point-at-eol)))))
  7217. (goto-char dbeg)
  7218. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7219. (setq conf (or (eq t org-agenda-confirm-kill)
  7220. (and (numberp org-agenda-confirm-kill)
  7221. (> n org-agenda-confirm-kill))))
  7222. (and conf
  7223. (not (y-or-n-p
  7224. (format "Delete entry with %d lines in buffer \"%s\"? "
  7225. n (buffer-name buffer))))
  7226. (error "Abort"))
  7227. (let ((org-agenda-buffer-name bufname-orig))
  7228. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7229. (with-current-buffer buffer (delete-region dbeg dend))
  7230. (message "Agenda item and source killed"))))
  7231. (defvar org-archive-default-command) ; defined in org-archive.el
  7232. (defun org-agenda-archive-default ()
  7233. "Archive the entry or subtree belonging to the current agenda entry."
  7234. (interactive)
  7235. (require 'org-archive)
  7236. (org-agenda-archive-with org-archive-default-command))
  7237. (defun org-agenda-archive-default-with-confirmation ()
  7238. "Archive the entry or subtree belonging to the current agenda entry."
  7239. (interactive)
  7240. (require 'org-archive)
  7241. (org-agenda-archive-with org-archive-default-command 'confirm))
  7242. (defun org-agenda-archive ()
  7243. "Archive the entry or subtree belonging to the current agenda entry."
  7244. (interactive)
  7245. (org-agenda-archive-with 'org-archive-subtree))
  7246. (defun org-agenda-archive-to-archive-sibling ()
  7247. "Move the entry to the archive sibling."
  7248. (interactive)
  7249. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7250. (defun org-agenda-archive-with (cmd &optional confirm)
  7251. "Move the entry to the archive sibling."
  7252. (interactive)
  7253. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7254. (let* ((bufname-orig (buffer-name))
  7255. (marker (or (org-get-at-bol 'org-marker)
  7256. (org-agenda-error)))
  7257. (buffer (marker-buffer marker))
  7258. (pos (marker-position marker)))
  7259. (org-with-remote-undo buffer
  7260. (with-current-buffer buffer
  7261. (if (derived-mode-p 'org-mode)
  7262. (if (and confirm
  7263. (not (y-or-n-p "Archive this subtree or entry? ")))
  7264. (error "Abort")
  7265. (save-excursion
  7266. (goto-char pos)
  7267. (let ((org-agenda-buffer-name bufname-orig))
  7268. (org-remove-subtree-entries-from-agenda))
  7269. (org-back-to-heading t)
  7270. (funcall cmd)))
  7271. (error "Archiving works only in Org-mode files"))))))
  7272. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7273. "Remove all lines in the agenda that correspond to a given subtree.
  7274. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7275. If this information is not given, the function uses the tree at point."
  7276. (let ((buf (or buf (current-buffer))) m p)
  7277. (save-excursion
  7278. (unless (and beg end)
  7279. (org-back-to-heading t)
  7280. (setq beg (point))
  7281. (org-end-of-subtree t)
  7282. (setq end (point)))
  7283. (set-buffer (get-buffer org-agenda-buffer-name))
  7284. (save-excursion
  7285. (goto-char (point-max))
  7286. (beginning-of-line 1)
  7287. (while (not (bobp))
  7288. (when (and (setq m (org-get-at-bol 'org-marker))
  7289. (equal buf (marker-buffer m))
  7290. (setq p (marker-position m))
  7291. (>= p beg)
  7292. (< p end))
  7293. (let ((inhibit-read-only t))
  7294. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7295. (beginning-of-line 0))))))
  7296. (defun org-agenda-refile (&optional goto rfloc no-update)
  7297. "Refile the item at point."
  7298. (interactive "P")
  7299. (if (equal goto '(16))
  7300. (org-refile-goto-last-stored)
  7301. (let* ((buffer-orig (buffer-name))
  7302. (marker (or (org-get-at-bol 'org-hd-marker)
  7303. (org-agenda-error)))
  7304. (buffer (marker-buffer marker))
  7305. (pos (marker-position marker))
  7306. (rfloc (or rfloc
  7307. (org-refile-get-location
  7308. (if goto "Goto" "Refile to") buffer
  7309. org-refile-allow-creating-parent-nodes))))
  7310. (with-current-buffer buffer
  7311. (save-excursion
  7312. (save-restriction
  7313. (widen)
  7314. (goto-char marker)
  7315. (let ((org-agenda-buffer-name buffer-orig))
  7316. (org-remove-subtree-entries-from-agenda))
  7317. (org-refile goto buffer rfloc)))))
  7318. (unless no-update (org-agenda-redo))))
  7319. (defun org-agenda-open-link (&optional arg)
  7320. "Open the link(s) in the current entry, if any.
  7321. This looks for a link in the displayed line in the agenda.
  7322. It also looks at the text of the entry itself."
  7323. (interactive "P")
  7324. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7325. (org-get-at-bol 'org-marker)))
  7326. (buffer (and marker (marker-buffer marker)))
  7327. (prefix (buffer-substring
  7328. (point-at-bol) (point-at-eol)))
  7329. (lkall (org-offer-links-in-entry buffer marker arg prefix))
  7330. (lk (car lkall))
  7331. (lkend (cdr lkall))
  7332. trg)
  7333. (cond
  7334. ((and buffer (stringp lk))
  7335. (with-current-buffer buffer
  7336. (setq trg (and (string-match org-bracket-link-regexp lk)
  7337. (match-string 1 lk)))
  7338. (if (or (not trg) (string-match org-any-link-re trg))
  7339. (save-excursion
  7340. (save-restriction
  7341. (widen)
  7342. (goto-char marker)
  7343. (when (search-forward lk nil lkend)
  7344. (goto-char (match-beginning 0))
  7345. (org-open-at-point))))
  7346. ;; This is an internal link, widen the buffer
  7347. (switch-to-buffer-other-window buffer)
  7348. (widen)
  7349. (goto-char marker)
  7350. (when (search-forward lk nil lkend)
  7351. (goto-char (match-beginning 0))
  7352. (org-open-at-point)))))
  7353. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7354. (save-excursion
  7355. (beginning-of-line 1)
  7356. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7357. (org-open-link-from-string (match-string 1)))
  7358. (t (message "No link to open here")))))
  7359. (defun org-agenda-copy-local-variable (var)
  7360. "Get a variable from a referenced buffer and install it here."
  7361. (let ((m (org-get-at-bol 'org-marker)))
  7362. (when (and m (buffer-live-p (marker-buffer m)))
  7363. (org-set-local var (with-current-buffer (marker-buffer m)
  7364. (symbol-value var))))))
  7365. (defun org-agenda-switch-to (&optional delete-other-windows)
  7366. "Go to the Org-mode file which contains the item at point."
  7367. (interactive)
  7368. (if (and org-return-follows-link
  7369. (not (org-get-at-bol 'org-marker))
  7370. (org-in-regexp org-bracket-link-regexp))
  7371. (org-open-link-from-string (match-string 0))
  7372. (let* ((marker (or (org-get-at-bol 'org-marker)
  7373. (org-agenda-error)))
  7374. (buffer (marker-buffer marker))
  7375. (pos (marker-position marker)))
  7376. (org-pop-to-buffer-same-window buffer)
  7377. (and delete-other-windows (delete-other-windows))
  7378. (widen)
  7379. (goto-char pos)
  7380. (when (derived-mode-p 'org-mode)
  7381. (org-show-context 'agenda)
  7382. (save-excursion
  7383. (and (outline-next-heading)
  7384. (org-flag-heading nil))) ; show the next heading
  7385. (when (outline-invisible-p)
  7386. (show-entry)) ; display invisible text
  7387. (run-hooks 'org-agenda-after-show-hook)))))
  7388. (defun org-agenda-goto-mouse (ev)
  7389. "Go to the Org-mode file which contains the item at the mouse click."
  7390. (interactive "e")
  7391. (mouse-set-point ev)
  7392. (org-agenda-goto))
  7393. (defun org-agenda-show (&optional full-entry)
  7394. "Display the Org-mode file which contains the item at point.
  7395. With prefix argument FULL-ENTRY, make the entire entry visible
  7396. if it was hidden in the outline."
  7397. (interactive "P")
  7398. (let ((win (selected-window)))
  7399. (if full-entry
  7400. (let ((org-show-entry-below t))
  7401. (org-agenda-goto t))
  7402. (org-agenda-goto t))
  7403. (select-window win)))
  7404. (defvar org-agenda-show-window nil)
  7405. (defun org-agenda-show-and-scroll-up (&optional arg)
  7406. "Display the Org-mode file which contains the item at point.
  7407. When called repeatedly, scroll the window that is displaying the buffer.
  7408. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7409. `show-subtree' to display the item, so that drawers and logbooks stay
  7410. folded."
  7411. (interactive "P")
  7412. (let ((win (selected-window)))
  7413. (if (and (window-live-p org-agenda-show-window)
  7414. (eq this-command last-command))
  7415. (progn
  7416. (select-window org-agenda-show-window)
  7417. (ignore-errors (scroll-up)))
  7418. (org-agenda-goto t)
  7419. (if arg (org-show-entry) (show-subtree))
  7420. (setq org-agenda-show-window (selected-window)))
  7421. (select-window win)))
  7422. (defun org-agenda-show-scroll-down ()
  7423. "Scroll down the window showing the agenda."
  7424. (interactive)
  7425. (let ((win (selected-window)))
  7426. (when (window-live-p org-agenda-show-window)
  7427. (select-window org-agenda-show-window)
  7428. (ignore-errors (scroll-down))
  7429. (select-window win))))
  7430. (defun org-agenda-show-1 (&optional more)
  7431. "Display the Org-mode file which contains the item at point.
  7432. The prefix arg selects the amount of information to display:
  7433. 0 hide the subtree
  7434. 1 just show the entry according to defaults.
  7435. 2 show the children view
  7436. 3 show the subtree view
  7437. 4 show the entire subtree and any LOGBOOK drawers
  7438. 5 show the entire subtree and any drawers
  7439. With prefix argument FULL-ENTRY, make the entire entry visible
  7440. if it was hidden in the outline."
  7441. (interactive "p")
  7442. (let ((win (selected-window)))
  7443. (org-agenda-goto t)
  7444. (org-recenter-heading 1)
  7445. (cond
  7446. ((= more 0)
  7447. (hide-subtree)
  7448. (save-excursion
  7449. (org-back-to-heading)
  7450. (run-hook-with-args 'org-cycle-hook 'folded))
  7451. (message "Remote: FOLDED"))
  7452. ((and (org-called-interactively-p 'any) (= more 1))
  7453. (message "Remote: show with default settings"))
  7454. ((= more 2)
  7455. (show-entry)
  7456. (show-children)
  7457. (save-excursion
  7458. (org-back-to-heading)
  7459. (run-hook-with-args 'org-cycle-hook 'children))
  7460. (message "Remote: CHILDREN"))
  7461. ((= more 3)
  7462. (show-subtree)
  7463. (save-excursion
  7464. (org-back-to-heading)
  7465. (run-hook-with-args 'org-cycle-hook 'subtree))
  7466. (message "Remote: SUBTREE"))
  7467. ((= more 4)
  7468. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7469. (org-drawer-regexp
  7470. (concat "^[ \t]*:\\("
  7471. (mapconcat 'regexp-quote org-drawers "\\|")
  7472. "\\):[ \t]*$")))
  7473. (show-subtree)
  7474. (save-excursion
  7475. (org-back-to-heading)
  7476. (org-cycle-hide-drawers 'subtree)))
  7477. (message "Remote: SUBTREE AND LOGBOOK"))
  7478. ((> more 4)
  7479. (show-subtree)
  7480. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7481. (select-window win)))
  7482. (defun org-recenter-heading (n)
  7483. (save-excursion
  7484. (org-back-to-heading)
  7485. (recenter n)))
  7486. (defvar org-agenda-cycle-counter nil)
  7487. (defun org-agenda-cycle-show (&optional n)
  7488. "Show the current entry in another window, with default settings.
  7489. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7490. When use repeatedly in immediate succession, the remote entry will cycle
  7491. through visibility
  7492. children -> subtree -> folded
  7493. When called with a numeric prefix arg, that arg will be passed through to
  7494. `org-agenda-show-1'. For the interpretation of that argument, see the
  7495. docstring of `org-agenda-show-1'."
  7496. (interactive "P")
  7497. (if (integerp n)
  7498. (setq org-agenda-cycle-counter n)
  7499. (if (not (eq last-command this-command))
  7500. (setq org-agenda-cycle-counter 1)
  7501. (if (equal org-agenda-cycle-counter 0)
  7502. (setq org-agenda-cycle-counter 2)
  7503. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7504. (if (> org-agenda-cycle-counter 3)
  7505. (setq org-agenda-cycle-counter 0)))))
  7506. (org-agenda-show-1 org-agenda-cycle-counter))
  7507. (defun org-agenda-recenter (arg)
  7508. "Display the Org-mode file which contains the item at point and recenter."
  7509. (interactive "P")
  7510. (let ((win (selected-window)))
  7511. (org-agenda-goto t)
  7512. (recenter arg)
  7513. (select-window win)))
  7514. (defun org-agenda-show-mouse (ev)
  7515. "Display the Org-mode file which contains the item at the mouse click."
  7516. (interactive "e")
  7517. (mouse-set-point ev)
  7518. (org-agenda-show))
  7519. (defun org-agenda-check-no-diary ()
  7520. "Check if the entry is a diary link and abort if yes."
  7521. (if (org-get-at-bol 'org-agenda-diary-link)
  7522. (org-agenda-error)))
  7523. (defun org-agenda-error ()
  7524. (error "Command not allowed in this line"))
  7525. (defun org-agenda-tree-to-indirect-buffer (arg)
  7526. "Show the subtree corresponding to the current entry in an indirect buffer.
  7527. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7528. With a numerical prefix ARG, go up to this level and then take that tree.
  7529. With a negative numeric ARG, go up by this number of levels.
  7530. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7531. use the dedicated frame)."
  7532. (interactive "P")
  7533. (if current-prefix-arg
  7534. (org-agenda-do-tree-to-indirect-buffer arg)
  7535. (let ((agenda-buffer (buffer-name))
  7536. (agenda-window (selected-window))
  7537. (indirect-window
  7538. (and org-last-indirect-buffer
  7539. (get-buffer-window org-last-indirect-buffer))))
  7540. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7541. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7542. (eq org-indirect-buffer-display 'dedicated-frame))
  7543. (unwind-protect
  7544. (unless (and indirect-window (window-live-p indirect-window))
  7545. (setq indirect-window (split-window agenda-window)))
  7546. (and indirect-window (select-window indirect-window))
  7547. (switch-to-buffer org-last-indirect-buffer :norecord)
  7548. (fit-window-to-buffer indirect-window)))
  7549. (select-window (get-buffer-window agenda-buffer)))))
  7550. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7551. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7552. (org-agenda-check-no-diary)
  7553. (let* ((marker (or (org-get-at-bol 'org-marker)
  7554. (org-agenda-error)))
  7555. (buffer (marker-buffer marker))
  7556. (pos (marker-position marker)))
  7557. (with-current-buffer buffer
  7558. (save-excursion
  7559. (goto-char pos)
  7560. (funcall 'org-tree-to-indirect-buffer arg)))))
  7561. (defvar org-last-heading-marker (make-marker)
  7562. "Marker pointing to the headline that last changed its TODO state
  7563. by a remote command from the agenda.")
  7564. (defun org-agenda-todo-nextset ()
  7565. "Switch TODO entry to next sequence."
  7566. (interactive)
  7567. (org-agenda-todo 'nextset))
  7568. (defun org-agenda-todo-previousset ()
  7569. "Switch TODO entry to previous sequence."
  7570. (interactive)
  7571. (org-agenda-todo 'previousset))
  7572. (defun org-agenda-todo (&optional arg)
  7573. "Cycle TODO state of line at point, also in Org-mode file.
  7574. This changes the line at point, all other lines in the agenda referring to
  7575. the same tree node, and the headline of the tree node in the Org-mode file."
  7576. (interactive "P")
  7577. (org-agenda-check-no-diary)
  7578. (let* ((col (current-column))
  7579. (marker (or (org-get-at-bol 'org-marker)
  7580. (org-agenda-error)))
  7581. (buffer (marker-buffer marker))
  7582. (pos (marker-position marker))
  7583. (hdmarker (org-get-at-bol 'org-hd-marker))
  7584. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7585. (inhibit-read-only t)
  7586. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7587. (org-with-remote-undo buffer
  7588. (with-current-buffer buffer
  7589. (widen)
  7590. (goto-char pos)
  7591. (org-show-context 'agenda)
  7592. (save-excursion
  7593. (and (outline-next-heading)
  7594. (org-flag-heading nil))) ; show the next heading
  7595. (let ((current-prefix-arg arg))
  7596. (call-interactively 'org-todo))
  7597. (and (bolp) (forward-char 1))
  7598. (setq newhead (org-get-heading))
  7599. (when (and (org-bound-and-true-p
  7600. org-agenda-headline-snapshot-before-repeat)
  7601. (not (equal org-agenda-headline-snapshot-before-repeat
  7602. newhead))
  7603. todayp)
  7604. (setq newhead org-agenda-headline-snapshot-before-repeat
  7605. just-one t))
  7606. (save-excursion
  7607. (org-back-to-heading)
  7608. (move-marker org-last-heading-marker (point))))
  7609. (beginning-of-line 1)
  7610. (save-excursion
  7611. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7612. (org-move-to-column col))))
  7613. (defun org-agenda-add-note (&optional arg)
  7614. "Add a time-stamped note to the entry at point."
  7615. (interactive "P")
  7616. (org-agenda-check-no-diary)
  7617. (let* ((marker (or (org-get-at-bol 'org-marker)
  7618. (org-agenda-error)))
  7619. (buffer (marker-buffer marker))
  7620. (pos (marker-position marker))
  7621. (hdmarker (org-get-at-bol 'org-hd-marker))
  7622. (inhibit-read-only t))
  7623. (with-current-buffer buffer
  7624. (widen)
  7625. (goto-char pos)
  7626. (org-show-context 'agenda)
  7627. (save-excursion
  7628. (and (outline-next-heading)
  7629. (org-flag-heading nil))) ; show the next heading
  7630. (org-add-note))))
  7631. (defun org-agenda-change-all-lines (newhead hdmarker
  7632. &optional fixface just-this)
  7633. "Change all lines in the agenda buffer which match HDMARKER.
  7634. The new content of the line will be NEWHEAD (as modified by
  7635. `org-agenda-format-item'). HDMARKER is checked with
  7636. `equal' against all `org-hd-marker' text properties in the file.
  7637. If FIXFACE is non-nil, the face of each item is modified according to
  7638. the new TODO state.
  7639. If JUST-THIS is non-nil, change just the current line, not all.
  7640. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7641. (let* ((inhibit-read-only t)
  7642. (line (org-current-line))
  7643. (org-agenda-buffer (current-buffer))
  7644. (thetags (with-current-buffer (marker-buffer hdmarker)
  7645. (save-excursion (save-restriction (widen)
  7646. (goto-char hdmarker)
  7647. (org-get-tags-at)))))
  7648. props m pl undone-face done-face finish new dotime cat tags)
  7649. (save-excursion
  7650. (goto-char (point-max))
  7651. (beginning-of-line 1)
  7652. (while (not finish)
  7653. (setq finish (bobp))
  7654. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7655. (or (not just-this) (= (org-current-line) line))
  7656. (equal m hdmarker))
  7657. (setq props (text-properties-at (point))
  7658. dotime (org-get-at-bol 'dotime)
  7659. cat (org-get-at-bol 'org-category)
  7660. tags thetags
  7661. new
  7662. (let ((org-prefix-format-compiled
  7663. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7664. org-prefix-format-compiled))
  7665. (extra (org-get-at-bol 'extra)))
  7666. (with-current-buffer (marker-buffer hdmarker)
  7667. (save-excursion
  7668. (save-restriction
  7669. (widen)
  7670. (org-agenda-format-item extra newhead cat tags dotime)))))
  7671. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7672. undone-face (org-get-at-bol 'undone-face)
  7673. done-face (org-get-at-bol 'done-face))
  7674. (beginning-of-line 1)
  7675. (cond
  7676. ((equal new "")
  7677. (and (looking-at ".*\n?") (replace-match "")))
  7678. ((looking-at ".*")
  7679. (replace-match new t t)
  7680. (beginning-of-line 1)
  7681. (add-text-properties (point-at-bol) (point-at-eol) props)
  7682. (when fixface
  7683. (add-text-properties
  7684. (point-at-bol) (point-at-eol)
  7685. (list 'face
  7686. (if org-last-todo-state-is-todo
  7687. undone-face done-face))))
  7688. (org-agenda-highlight-todo 'line)
  7689. (beginning-of-line 1))
  7690. (t (error "Line update did not work")))
  7691. (save-restriction
  7692. (narrow-to-region (point-at-bol) (point-at-eol))
  7693. (org-agenda-finalize)))
  7694. (beginning-of-line 0)))))
  7695. (defun org-agenda-align-tags (&optional line)
  7696. "Align all tags in agenda items to `org-agenda-tags-column'."
  7697. (let ((inhibit-read-only t) l c)
  7698. (save-excursion
  7699. (goto-char (if line (point-at-bol) (point-min)))
  7700. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7701. (if line (point-at-eol) nil) t)
  7702. (add-text-properties
  7703. (match-beginning 2) (match-end 2)
  7704. (list 'face (delq nil (let ((prop (get-text-property
  7705. (match-beginning 2) 'face)))
  7706. (or (listp prop) (setq prop (list prop)))
  7707. (if (memq 'org-tag prop)
  7708. prop
  7709. (cons 'org-tag prop))))))
  7710. (setq l (- (match-end 2) (match-beginning 2))
  7711. c (if (< org-agenda-tags-column 0)
  7712. (- (abs org-agenda-tags-column) l)
  7713. org-agenda-tags-column))
  7714. (delete-region (match-beginning 1) (match-end 1))
  7715. (goto-char (match-beginning 1))
  7716. (insert (org-add-props
  7717. (make-string (max 1 (- c (current-column))) ?\ )
  7718. (plist-put (copy-sequence (text-properties-at (point)))
  7719. 'face nil))))
  7720. (goto-char (point-min))
  7721. (org-font-lock-add-tag-faces (point-max)))))
  7722. (defun org-agenda-priority-up ()
  7723. "Increase the priority of line at point, also in Org-mode file."
  7724. (interactive)
  7725. (org-agenda-priority 'up))
  7726. (defun org-agenda-priority-down ()
  7727. "Decrease the priority of line at point, also in Org-mode file."
  7728. (interactive)
  7729. (org-agenda-priority 'down))
  7730. (defun org-agenda-priority (&optional force-direction)
  7731. "Set the priority of line at point, also in Org-mode file.
  7732. This changes the line at point, all other lines in the agenda referring to
  7733. the same tree node, and the headline of the tree node in the Org-mode file.
  7734. Called with a universal prefix arg, show the priority instead of setting it."
  7735. (interactive "P")
  7736. (if (equal force-direction '(4))
  7737. (org-show-priority)
  7738. (unless org-enable-priority-commands
  7739. (error "Priority commands are disabled"))
  7740. (org-agenda-check-no-diary)
  7741. (let* ((marker (or (org-get-at-bol 'org-marker)
  7742. (org-agenda-error)))
  7743. (hdmarker (org-get-at-bol 'org-hd-marker))
  7744. (buffer (marker-buffer hdmarker))
  7745. (pos (marker-position hdmarker))
  7746. (inhibit-read-only t)
  7747. newhead)
  7748. (org-with-remote-undo buffer
  7749. (with-current-buffer buffer
  7750. (widen)
  7751. (goto-char pos)
  7752. (org-show-context 'agenda)
  7753. (save-excursion
  7754. (and (outline-next-heading)
  7755. (org-flag-heading nil))) ; show the next heading
  7756. (funcall 'org-priority force-direction)
  7757. (end-of-line 1)
  7758. (setq newhead (org-get-heading)))
  7759. (org-agenda-change-all-lines newhead hdmarker)
  7760. (beginning-of-line 1)))))
  7761. ;; FIXME: should fix the tags property of the agenda line.
  7762. (defun org-agenda-set-tags (&optional tag onoff)
  7763. "Set tags for the current headline."
  7764. (interactive)
  7765. (org-agenda-check-no-diary)
  7766. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7767. (call-interactively 'org-change-tag-in-region)
  7768. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7769. (org-agenda-error)))
  7770. (buffer (marker-buffer hdmarker))
  7771. (pos (marker-position hdmarker))
  7772. (inhibit-read-only t)
  7773. newhead)
  7774. (org-with-remote-undo buffer
  7775. (with-current-buffer buffer
  7776. (widen)
  7777. (goto-char pos)
  7778. (save-excursion
  7779. (org-show-context 'agenda))
  7780. (save-excursion
  7781. (and (outline-next-heading)
  7782. (org-flag-heading nil))) ; show the next heading
  7783. (goto-char pos)
  7784. (if tag
  7785. (org-toggle-tag tag onoff)
  7786. (call-interactively 'org-set-tags))
  7787. (end-of-line 1)
  7788. (setq newhead (org-get-heading)))
  7789. (org-agenda-change-all-lines newhead hdmarker)
  7790. (beginning-of-line 1)))))
  7791. (defun org-agenda-set-property ()
  7792. "Set a property for the current headline."
  7793. (interactive)
  7794. (org-agenda-check-no-diary)
  7795. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7796. (org-agenda-error)))
  7797. (buffer (marker-buffer hdmarker))
  7798. (pos (marker-position hdmarker))
  7799. (inhibit-read-only t)
  7800. newhead)
  7801. (org-with-remote-undo buffer
  7802. (with-current-buffer buffer
  7803. (widen)
  7804. (goto-char pos)
  7805. (save-excursion
  7806. (org-show-context 'agenda))
  7807. (save-excursion
  7808. (and (outline-next-heading)
  7809. (org-flag-heading nil))) ; show the next heading
  7810. (goto-char pos)
  7811. (call-interactively 'org-set-property)))))
  7812. (defun org-agenda-set-effort ()
  7813. "Set the effort property for the current headline."
  7814. (interactive)
  7815. (org-agenda-check-no-diary)
  7816. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7817. (org-agenda-error)))
  7818. (buffer (marker-buffer hdmarker))
  7819. (pos (marker-position hdmarker))
  7820. (inhibit-read-only t)
  7821. newhead)
  7822. (org-with-remote-undo buffer
  7823. (with-current-buffer buffer
  7824. (widen)
  7825. (goto-char pos)
  7826. (save-excursion
  7827. (org-show-context 'agenda))
  7828. (save-excursion
  7829. (and (outline-next-heading)
  7830. (org-flag-heading nil))) ; show the next heading
  7831. (goto-char pos)
  7832. (call-interactively 'org-set-effort)
  7833. (end-of-line 1)
  7834. (setq newhead (org-get-heading)))
  7835. (org-agenda-change-all-lines newhead hdmarker))))
  7836. (defun org-agenda-toggle-archive-tag ()
  7837. "Toggle the archive tag for the current entry."
  7838. (interactive)
  7839. (org-agenda-check-no-diary)
  7840. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7841. (org-agenda-error)))
  7842. (buffer (marker-buffer hdmarker))
  7843. (pos (marker-position hdmarker))
  7844. (inhibit-read-only t)
  7845. newhead)
  7846. (org-with-remote-undo buffer
  7847. (with-current-buffer buffer
  7848. (widen)
  7849. (goto-char pos)
  7850. (org-show-context 'agenda)
  7851. (save-excursion
  7852. (and (outline-next-heading)
  7853. (org-flag-heading nil))) ; show the next heading
  7854. (call-interactively 'org-toggle-archive-tag)
  7855. (end-of-line 1)
  7856. (setq newhead (org-get-heading)))
  7857. (org-agenda-change-all-lines newhead hdmarker)
  7858. (beginning-of-line 1))))
  7859. (defun org-agenda-do-date-later (arg)
  7860. (interactive "P")
  7861. (cond
  7862. ((or (equal arg '(16))
  7863. (memq last-command
  7864. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7865. (setq this-command 'org-agenda-date-later-minutes)
  7866. (org-agenda-date-later-minutes 1))
  7867. ((or (equal arg '(4))
  7868. (memq last-command
  7869. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7870. (setq this-command 'org-agenda-date-later-hours)
  7871. (org-agenda-date-later-hours 1))
  7872. (t
  7873. (org-agenda-date-later (prefix-numeric-value arg)))))
  7874. (defun org-agenda-do-date-earlier (arg)
  7875. (interactive "P")
  7876. (cond
  7877. ((or (equal arg '(16))
  7878. (memq last-command
  7879. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7880. (setq this-command 'org-agenda-date-earlier-minutes)
  7881. (org-agenda-date-earlier-minutes 1))
  7882. ((or (equal arg '(4))
  7883. (memq last-command
  7884. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7885. (setq this-command 'org-agenda-date-earlier-hours)
  7886. (org-agenda-date-earlier-hours 1))
  7887. (t
  7888. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7889. (defun org-agenda-date-later (arg &optional what)
  7890. "Change the date of this item to ARG day(s) later."
  7891. (interactive "p")
  7892. (org-agenda-check-type t 'agenda 'timeline)
  7893. (org-agenda-check-no-diary)
  7894. (let* ((marker (or (org-get-at-bol 'org-marker)
  7895. (org-agenda-error)))
  7896. (buffer (marker-buffer marker))
  7897. (pos (marker-position marker))
  7898. cdate today)
  7899. (org-with-remote-undo buffer
  7900. (with-current-buffer buffer
  7901. (widen)
  7902. (goto-char pos)
  7903. (if (not (org-at-timestamp-p))
  7904. (error "Cannot find time stamp"))
  7905. (when (and org-agenda-move-date-from-past-immediately-to-today
  7906. (equal arg 1)
  7907. (or (not what) (eq what 'day))
  7908. (not (save-match-data (org-at-date-range-p))))
  7909. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7910. cdate (calendar-absolute-from-gregorian
  7911. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7912. today (org-today))
  7913. (if (> today cdate)
  7914. ;; immediately shift to today
  7915. (setq arg (- today cdate))))
  7916. (org-timestamp-change arg (or what 'day))
  7917. (when (and (org-at-date-range-p)
  7918. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7919. (let ((end org-last-changed-timestamp))
  7920. (org-timestamp-change arg (or what 'day))
  7921. (setq org-last-changed-timestamp
  7922. (concat org-last-changed-timestamp "--" end)))))
  7923. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7924. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7925. (defun org-agenda-date-earlier (arg &optional what)
  7926. "Change the date of this item to ARG day(s) earlier."
  7927. (interactive "p")
  7928. (org-agenda-date-later (- arg) what))
  7929. (defun org-agenda-date-later-minutes (arg)
  7930. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7931. (interactive "p")
  7932. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7933. (org-agenda-date-later arg 'minute))
  7934. (defun org-agenda-date-earlier-minutes (arg)
  7935. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7936. (interactive "p")
  7937. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7938. (org-agenda-date-earlier arg 'minute))
  7939. (defun org-agenda-date-later-hours (arg)
  7940. "Change the time of this item, in hour steps."
  7941. (interactive "p")
  7942. (org-agenda-date-later arg 'hour))
  7943. (defun org-agenda-date-earlier-hours (arg)
  7944. "Change the time of this item, in hour steps."
  7945. (interactive "p")
  7946. (org-agenda-date-earlier arg 'hour))
  7947. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7948. "Show new date stamp via text properties."
  7949. ;; We use text properties to make this undoable
  7950. (let ((inhibit-read-only t)
  7951. (buffer-invisibility-spec))
  7952. (setq stamp (concat " " prefix " => " stamp))
  7953. (save-excursion
  7954. (goto-char (point-max))
  7955. (while (not (bobp))
  7956. (when (equal marker (org-get-at-bol 'org-marker))
  7957. (org-move-to-column (- (window-width) (length stamp)) t)
  7958. (org-agenda-fix-tags-filter-overlays-at (point))
  7959. (if (featurep 'xemacs)
  7960. ;; Use `duplicable' property to trigger undo recording
  7961. (let ((ex (make-extent nil nil))
  7962. (gl (make-glyph stamp)))
  7963. (set-glyph-face gl 'secondary-selection)
  7964. (set-extent-properties
  7965. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7966. (insert-extent ex (1- (point)) (point-at-eol)))
  7967. (add-text-properties
  7968. (1- (point)) (point-at-eol)
  7969. (list 'display (org-add-props stamp nil
  7970. 'face 'secondary-selection))))
  7971. (beginning-of-line 1))
  7972. (beginning-of-line 0)))))
  7973. (defun org-agenda-date-prompt (arg)
  7974. "Change the date of this item. Date is prompted for, with default today.
  7975. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7976. be used to request time specification in the time stamp."
  7977. (interactive "P")
  7978. (org-agenda-check-type t 'agenda 'timeline)
  7979. (org-agenda-check-no-diary)
  7980. (let* ((marker (or (org-get-at-bol 'org-marker)
  7981. (org-agenda-error)))
  7982. (buffer (marker-buffer marker))
  7983. (pos (marker-position marker)))
  7984. (org-with-remote-undo buffer
  7985. (with-current-buffer buffer
  7986. (widen)
  7987. (goto-char pos)
  7988. (if (not (org-at-timestamp-p t))
  7989. (error "Cannot find time stamp"))
  7990. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7991. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7992. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7993. (defun org-agenda-schedule (arg &optional time)
  7994. "Schedule the item at point.
  7995. ARG is passed through to `org-schedule'."
  7996. (interactive "P")
  7997. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7998. (org-agenda-check-no-diary)
  7999. (let* ((marker (or (org-get-at-bol 'org-marker)
  8000. (org-agenda-error)))
  8001. (type (marker-insertion-type marker))
  8002. (buffer (marker-buffer marker))
  8003. (pos (marker-position marker))
  8004. (org-insert-labeled-timestamps-at-point nil)
  8005. ts)
  8006. (set-marker-insertion-type marker t)
  8007. (org-with-remote-undo buffer
  8008. (with-current-buffer buffer
  8009. (widen)
  8010. (goto-char pos)
  8011. (setq ts (org-schedule arg time)))
  8012. (org-agenda-show-new-time marker ts "S"))
  8013. (message "%s" ts)))
  8014. (defun org-agenda-deadline (arg &optional time)
  8015. "Schedule the item at point.
  8016. ARG is passed through to `org-deadline'."
  8017. (interactive "P")
  8018. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8019. (org-agenda-check-no-diary)
  8020. (let* ((marker (or (org-get-at-bol 'org-marker)
  8021. (org-agenda-error)))
  8022. (buffer (marker-buffer marker))
  8023. (pos (marker-position marker))
  8024. (org-insert-labeled-timestamps-at-point nil)
  8025. ts)
  8026. (org-with-remote-undo buffer
  8027. (with-current-buffer buffer
  8028. (widen)
  8029. (goto-char pos)
  8030. (setq ts (org-deadline arg time)))
  8031. (org-agenda-show-new-time marker ts "D"))
  8032. (message "%s" ts)))
  8033. (defun org-agenda-clock-in (&optional arg)
  8034. "Start the clock on the currently selected item."
  8035. (interactive "P")
  8036. (org-agenda-check-no-diary)
  8037. (if (equal arg '(4))
  8038. (org-clock-in arg)
  8039. (let* ((marker (or (org-get-at-bol 'org-marker)
  8040. (org-agenda-error)))
  8041. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  8042. marker))
  8043. (pos (marker-position marker))
  8044. newhead)
  8045. (org-with-remote-undo (marker-buffer marker)
  8046. (with-current-buffer (marker-buffer marker)
  8047. (widen)
  8048. (goto-char pos)
  8049. (org-show-context 'agenda)
  8050. (org-show-entry)
  8051. (org-cycle-hide-drawers 'children)
  8052. (org-clock-in arg)
  8053. (setq newhead (org-get-heading)))
  8054. (org-agenda-change-all-lines newhead hdmarker)))))
  8055. (defun org-agenda-clock-out ()
  8056. "Stop the currently running clock."
  8057. (interactive)
  8058. (unless (marker-buffer org-clock-marker)
  8059. (error "No running clock"))
  8060. (let ((marker (make-marker)) newhead)
  8061. (org-with-remote-undo (marker-buffer org-clock-marker)
  8062. (with-current-buffer (marker-buffer org-clock-marker)
  8063. (save-excursion
  8064. (save-restriction
  8065. (widen)
  8066. (goto-char org-clock-marker)
  8067. (org-back-to-heading t)
  8068. (move-marker marker (point))
  8069. (org-clock-out)
  8070. (setq newhead (org-get-heading))))))
  8071. (org-agenda-change-all-lines newhead marker)
  8072. (move-marker marker nil)))
  8073. (defun org-agenda-clock-cancel (&optional arg)
  8074. "Cancel the currently running clock."
  8075. (interactive "P")
  8076. (unless (marker-buffer org-clock-marker)
  8077. (error "No running clock"))
  8078. (org-with-remote-undo (marker-buffer org-clock-marker)
  8079. (org-clock-cancel)))
  8080. (defun org-agenda-clock-goto ()
  8081. "Jump to the currently clocked in task within the agenda.
  8082. If the currently clocked in task is not listed in the agenda
  8083. buffer, display it in another window."
  8084. (interactive)
  8085. (let (pos)
  8086. (mapc (lambda (o)
  8087. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8088. (setq pos (overlay-start o))))
  8089. (overlays-in (point-min) (point-max)))
  8090. (cond (pos (goto-char pos))
  8091. ;; If the currently clocked entry is not in the agenda
  8092. ;; buffer, we visit it in another window:
  8093. (org-clock-current-task
  8094. (org-switch-to-buffer-other-window (org-clock-goto)))
  8095. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8096. (defun org-agenda-diary-entry-in-org-file ()
  8097. "Make a diary entry in the file `org-agenda-diary-file'."
  8098. (let (d1 d2 char (text "") dp1 dp2)
  8099. (if (equal (buffer-name) "*Calendar*")
  8100. (setq d1 (calendar-cursor-to-date t)
  8101. d2 (car calendar-mark-ring))
  8102. (setq dp1 (get-text-property (point-at-bol) 'day))
  8103. (unless dp1 (error "No date defined in current line"))
  8104. (setq d1 (calendar-gregorian-from-absolute dp1)
  8105. d2 (and (ignore-errors (mark))
  8106. (save-excursion
  8107. (goto-char (mark))
  8108. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8109. (calendar-gregorian-from-absolute dp2))))
  8110. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8111. (setq char (read-char-exclusive))
  8112. (cond
  8113. ((equal char ?d)
  8114. (setq text (read-string "Day entry: "))
  8115. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8116. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8117. ((equal char ?a)
  8118. (setq d1 (list (car d1) (nth 1 d1)
  8119. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8120. (nth 2 d1))))
  8121. (setq text (read-string "Anniversary (use %d to show years): "))
  8122. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8123. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8124. ((equal char ?b)
  8125. (setq text (read-string "Block entry: "))
  8126. (unless (and d1 d2 (not (equal d1 d2)))
  8127. (error "No block of days selected"))
  8128. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8129. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8130. ((equal char ?j)
  8131. (org-switch-to-buffer-other-window
  8132. (find-file-noselect org-agenda-diary-file))
  8133. (require 'org-datetree)
  8134. (org-datetree-find-date-create d1)
  8135. (org-reveal t))
  8136. (t (error "Invalid selection character `%c'" char)))))
  8137. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8138. "Where in `org-agenda-diary-file' should new entries be added?
  8139. Valid values:
  8140. date-tree in the date tree, as child of the date
  8141. top-level as top-level entries at the end of the file."
  8142. :group 'org-agenda
  8143. :type '(choice
  8144. (const :tag "in a date tree" date-tree)
  8145. (const :tag "as top level at end of file" top-level)))
  8146. (defcustom org-agenda-insert-diary-extract-time nil
  8147. "Non-nil means extract any time specification from the diary entry."
  8148. :group 'org-agenda
  8149. :version "24.1"
  8150. :type 'boolean)
  8151. (defcustom org-agenda-bulk-mark-char ">"
  8152. "A single-character string to be used as the bulk mark."
  8153. :group 'org-agenda
  8154. :version "24.1"
  8155. :type 'string)
  8156. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8157. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8158. If TEXT is not empty, it will become the headline of the new entry, and
  8159. the resulting entry will not be shown. When TEXT is empty, switch to
  8160. `org-agenda-diary-file' and let the user finish the entry there."
  8161. (let ((cw (current-window-configuration)))
  8162. (org-switch-to-buffer-other-window
  8163. (find-file-noselect org-agenda-diary-file))
  8164. (widen)
  8165. (goto-char (point-min))
  8166. (cond
  8167. ((eq type 'anniversary)
  8168. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8169. (progn
  8170. (or (org-at-heading-p t)
  8171. (progn
  8172. (outline-next-heading)
  8173. (insert "* Anniversaries\n\n")
  8174. (beginning-of-line -1)))))
  8175. (outline-next-heading)
  8176. (org-back-over-empty-lines)
  8177. (backward-char 1)
  8178. (insert "\n")
  8179. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8180. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8181. ((eq type 'day)
  8182. (let ((org-prefix-has-time t)
  8183. (org-agenda-time-leading-zero t)
  8184. fmt time time2)
  8185. (if org-agenda-insert-diary-extract-time
  8186. ;; Use org-agenda-format-item to parse text for a time-range and
  8187. ;; remove it. FIXME: This is a hack, we should refactor
  8188. ;; that function to make time extraction available separately
  8189. (setq fmt (org-agenda-format-item nil text nil nil t)
  8190. time (get-text-property 0 'time fmt)
  8191. time2 (if (> (length time) 0)
  8192. ;; split-string removes trailing ...... if
  8193. ;; no end time given. First space
  8194. ;; separates time from date.
  8195. (concat " " (car (split-string time "\\.")))
  8196. nil)
  8197. text (get-text-property 0 'txt fmt)))
  8198. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8199. (org-agenda-insert-diary-as-top-level text)
  8200. (require 'org-datetree)
  8201. (org-datetree-find-date-create d1)
  8202. (org-agenda-insert-diary-make-new-entry text))
  8203. (org-insert-time-stamp (org-time-from-absolute
  8204. (calendar-absolute-from-gregorian d1))
  8205. nil nil nil nil time2))
  8206. (end-of-line 0))
  8207. ((eq type 'block)
  8208. (if (> (calendar-absolute-from-gregorian d1)
  8209. (calendar-absolute-from-gregorian d2))
  8210. (setq d1 (prog1 d2 (setq d2 d1))))
  8211. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8212. (org-agenda-insert-diary-as-top-level text)
  8213. (require 'org-datetree)
  8214. (org-datetree-find-date-create d1)
  8215. (org-agenda-insert-diary-make-new-entry text))
  8216. (org-insert-time-stamp (org-time-from-absolute
  8217. (calendar-absolute-from-gregorian d1)))
  8218. (insert "--")
  8219. (org-insert-time-stamp (org-time-from-absolute
  8220. (calendar-absolute-from-gregorian d2)))
  8221. (end-of-line 0)))
  8222. (if (string-match "\\S-" text)
  8223. (progn
  8224. (set-window-configuration cw)
  8225. (message "%s entry added to %s"
  8226. (capitalize (symbol-name type))
  8227. (abbreviate-file-name org-agenda-diary-file)))
  8228. (org-reveal t)
  8229. (message "Please finish entry here"))))
  8230. (defun org-agenda-insert-diary-as-top-level (text)
  8231. "Make new entry as a top-level entry at the end of the file.
  8232. Add TEXT as headline, and position the cursor in the second line so that
  8233. a timestamp can be added there."
  8234. (widen)
  8235. (goto-char (point-max))
  8236. (or (bolp) (insert "\n"))
  8237. (insert "* " text "\n")
  8238. (if org-adapt-indentation (org-indent-to-column 2)))
  8239. (defun org-agenda-insert-diary-make-new-entry (text)
  8240. "Make new entry as last child of current entry.
  8241. Add TEXT as headline, and position the cursor in the second line so that
  8242. a timestamp can be added there."
  8243. (let ((org-show-following-heading t)
  8244. (org-show-siblings t)
  8245. (org-show-hierarchy-above t)
  8246. (org-show-entry-below t)
  8247. col)
  8248. (outline-next-heading)
  8249. (org-back-over-empty-lines)
  8250. (or (looking-at "[ \t]*$")
  8251. (progn (insert "\n") (backward-char 1)))
  8252. (org-insert-heading nil t)
  8253. (org-do-demote)
  8254. (setq col (current-column))
  8255. (insert text "\n")
  8256. (if org-adapt-indentation (org-indent-to-column col))
  8257. (let ((org-show-following-heading t)
  8258. (org-show-siblings t)
  8259. (org-show-hierarchy-above t)
  8260. (org-show-entry-below t))
  8261. (org-show-context))))
  8262. (defun org-agenda-diary-entry ()
  8263. "Make a diary entry, like the `i' command from the calendar.
  8264. All the standard commands work: block, weekly etc.
  8265. When `org-agenda-diary-file' points to a file,
  8266. `org-agenda-diary-entry-in-org-file' is called instead to create
  8267. entries in that Org-mode file."
  8268. (interactive)
  8269. (if (not (eq org-agenda-diary-file 'diary-file))
  8270. (org-agenda-diary-entry-in-org-file)
  8271. (require 'diary-lib)
  8272. (let* ((char (progn
  8273. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8274. (read-char-exclusive)))
  8275. (cmd (cdr (assoc char
  8276. '((?d . insert-diary-entry)
  8277. (?w . insert-weekly-diary-entry)
  8278. (?m . insert-monthly-diary-entry)
  8279. (?y . insert-yearly-diary-entry)
  8280. (?a . insert-anniversary-diary-entry)
  8281. (?b . insert-block-diary-entry)
  8282. (?c . insert-cyclic-diary-entry)))))
  8283. (oldf (symbol-function 'calendar-cursor-to-date))
  8284. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8285. (point (point))
  8286. (mark (or (mark t) (point))))
  8287. (unless cmd
  8288. (error "No command associated with <%c>" char))
  8289. (unless (and (get-text-property point 'day)
  8290. (or (not (equal ?b char))
  8291. (get-text-property mark 'day)))
  8292. (error "Don't know which date to use for diary entry"))
  8293. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8294. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8295. (let ((calendar-mark-ring
  8296. (list (calendar-gregorian-from-absolute
  8297. (or (get-text-property mark 'day)
  8298. (get-text-property point 'day))))))
  8299. (unwind-protect
  8300. (progn
  8301. (fset 'calendar-cursor-to-date
  8302. (lambda (&optional error dummy)
  8303. (calendar-gregorian-from-absolute
  8304. (get-text-property point 'day))))
  8305. (call-interactively cmd))
  8306. (fset 'calendar-cursor-to-date oldf))))))
  8307. (defun org-agenda-execute-calendar-command (cmd)
  8308. "Execute a calendar command from the agenda with date from cursor."
  8309. (org-agenda-check-type t 'agenda 'timeline)
  8310. (require 'diary-lib)
  8311. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8312. (error "Don't know which date to use for the calendar command"))
  8313. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8314. (point (point))
  8315. (date (calendar-gregorian-from-absolute
  8316. (get-text-property point 'day)))
  8317. ;; the following 2 vars are needed in the calendar
  8318. (displayed-month (car date))
  8319. (displayed-year (nth 2 date)))
  8320. (unwind-protect
  8321. (progn
  8322. (fset 'calendar-cursor-to-date
  8323. (lambda (&optional error dummy)
  8324. (calendar-gregorian-from-absolute
  8325. (get-text-property point 'day))))
  8326. (call-interactively cmd))
  8327. (fset 'calendar-cursor-to-date oldf))))
  8328. (defun org-agenda-phases-of-moon ()
  8329. "Display the phases of the moon for the 3 months around the cursor date."
  8330. (interactive)
  8331. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8332. (defun org-agenda-holidays ()
  8333. "Display the holidays for the 3 months around the cursor date."
  8334. (interactive)
  8335. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8336. (defvar calendar-longitude) ; defined in calendar.el
  8337. (defvar calendar-latitude) ; defined in calendar.el
  8338. (defvar calendar-location-name) ; defined in calendar.el
  8339. (defun org-agenda-sunrise-sunset (arg)
  8340. "Display sunrise and sunset for the cursor date.
  8341. Latitude and longitude can be specified with the variables
  8342. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8343. argument, latitude and longitude will be prompted for."
  8344. (interactive "P")
  8345. (require 'solar)
  8346. (let ((calendar-longitude (if arg nil calendar-longitude))
  8347. (calendar-latitude (if arg nil calendar-latitude))
  8348. (calendar-location-name
  8349. (if arg "the given coordinates" calendar-location-name)))
  8350. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8351. (defun org-agenda-goto-calendar ()
  8352. "Open the Emacs calendar with the date at the cursor."
  8353. (interactive)
  8354. (org-agenda-check-type t 'agenda 'timeline)
  8355. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8356. (error "Don't know which date to open in calendar")))
  8357. (date (calendar-gregorian-from-absolute day))
  8358. (calendar-move-hook nil)
  8359. (calendar-view-holidays-initially-flag nil)
  8360. (calendar-view-diary-initially-flag nil))
  8361. (calendar)
  8362. (calendar-goto-date date)))
  8363. ;;;###autoload
  8364. (defun org-calendar-goto-agenda ()
  8365. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8366. This is a command that has to be installed in `calendar-mode-map'."
  8367. (interactive)
  8368. (org-agenda-list nil (calendar-absolute-from-gregorian
  8369. (calendar-cursor-to-date))
  8370. nil))
  8371. (autoload 'org-calendar-goto-agenda "org-agenda" "\
  8372. Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8373. This is a command that has to be installed in `calendar-mode-map'.
  8374. \(fn)" t nil)
  8375. (defun org-agenda-convert-date ()
  8376. (interactive)
  8377. (org-agenda-check-type t 'agenda 'timeline)
  8378. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8379. date s)
  8380. (unless day
  8381. (error "Don't know which date to convert"))
  8382. (setq date (calendar-gregorian-from-absolute day))
  8383. (setq s (concat
  8384. "Gregorian: " (calendar-date-string date) "\n"
  8385. "ISO: " (calendar-iso-date-string date) "\n"
  8386. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8387. "Julian: " (calendar-julian-date-string date) "\n"
  8388. "Astron. JD: " (calendar-astro-date-string date)
  8389. " (Julian date number at noon UTC)\n"
  8390. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8391. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8392. "French: " (calendar-french-date-string date) "\n"
  8393. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8394. "Mayan: " (calendar-mayan-date-string date) "\n"
  8395. "Coptic: " (calendar-coptic-date-string date) "\n"
  8396. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8397. "Persian: " (calendar-persian-date-string date) "\n"
  8398. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8399. (with-output-to-temp-buffer "*Dates*"
  8400. (princ s))
  8401. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8402. ;;; Bulk commands
  8403. (defun org-agenda-bulk-marked-p ()
  8404. (eq (get-char-property (point-at-bol) 'type)
  8405. 'org-marked-entry-overlay))
  8406. (defun org-agenda-bulk-mark (&optional arg)
  8407. "Mark the entry at point for future bulk action."
  8408. (interactive "p")
  8409. (dotimes (i (or arg 1))
  8410. (unless (org-get-at-bol 'org-agenda-diary-link)
  8411. (let* ((m (org-get-at-bol 'org-hd-marker))
  8412. ov)
  8413. (unless (org-agenda-bulk-marked-p)
  8414. (unless m (error "Nothing to mark at point"))
  8415. (push m org-agenda-bulk-marked-entries)
  8416. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8417. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8418. (org-get-todo-face "TODO")
  8419. 'evaporate)
  8420. (overlay-put ov 'type 'org-marked-entry-overlay))
  8421. (beginning-of-line 2)
  8422. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8423. (beginning-of-line 2))
  8424. (message "%d entries marked for bulk action"
  8425. (length org-agenda-bulk-marked-entries))))))
  8426. (defun org-agenda-bulk-mark-all ()
  8427. "Mark all entries for future agenda bulk action."
  8428. (interactive)
  8429. (org-agenda-bulk-mark-regexp "."))
  8430. (defun org-agenda-bulk-mark-regexp (regexp)
  8431. "Mark entries matching REGEXP for future agenda bulk action."
  8432. (interactive "sMark entries matching regexp: ")
  8433. (let ((entries-marked 0))
  8434. (save-excursion
  8435. (goto-char (point-min))
  8436. (goto-char (next-single-property-change (point) 'txt))
  8437. (while (re-search-forward regexp nil t)
  8438. (when (string-match regexp (get-text-property (point) 'txt))
  8439. (setq entries-marked (1+ entries-marked))
  8440. (call-interactively 'org-agenda-bulk-mark))))
  8441. (if (not entries-marked)
  8442. (message "No entry matching this regexp."))))
  8443. (defun org-agenda-bulk-unmark (&optional arg)
  8444. "Unmark the entry at point for future bulk action."
  8445. (interactive "P")
  8446. (if arg
  8447. (org-agenda-bulk-unmark-all)
  8448. (cond ((org-agenda-bulk-marked-p)
  8449. (org-agenda-bulk-remove-overlays
  8450. (point-at-bol) (+ 2 (point-at-bol)))
  8451. (setq org-agenda-bulk-marked-entries
  8452. (delete (org-get-at-bol 'org-hd-marker)
  8453. org-agenda-bulk-marked-entries))
  8454. (beginning-of-line 2)
  8455. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8456. (beginning-of-line 2))
  8457. (message "%d entries left marked for bulk action"
  8458. (length org-agenda-bulk-marked-entries)))
  8459. (t (message "No entry to unmark here")))))
  8460. (defun org-agenda-bulk-toggle ()
  8461. "Toggle marking the entry at point for bulk action."
  8462. (interactive)
  8463. (if (org-agenda-bulk-marked-p)
  8464. (org-agenda-bulk-unmark)
  8465. (org-agenda-bulk-mark)))
  8466. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8467. "Remove the mark overlays between BEG and END in the agenda buffer.
  8468. BEG and END default to the buffer limits.
  8469. This only removes the overlays, it does not remove the markers
  8470. from the list in `org-agenda-bulk-marked-entries'."
  8471. (interactive)
  8472. (mapc (lambda (ov)
  8473. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8474. (delete-overlay ov)))
  8475. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8476. (defun org-agenda-bulk-unmark-all ()
  8477. "Remove all marks in the agenda buffer.
  8478. This will remove the markers and the overlays."
  8479. (interactive)
  8480. (if (null org-agenda-bulk-marked-entries)
  8481. (message "No entry to unmark")
  8482. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8483. (setq org-agenda-bulk-marked-entries nil)
  8484. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8485. (defcustom org-agenda-persistent-marks nil
  8486. "Non-nil means marked items will stay marked after a bulk action.
  8487. You can toggle this interactively by typing `p' when prompted for a
  8488. bulk action."
  8489. :group 'org-agenda
  8490. :version "24.1"
  8491. :type 'boolean)
  8492. (defun org-agenda-bulk-action (&optional arg)
  8493. "Execute an remote-editing action on all marked entries.
  8494. The prefix arg is passed through to the command if possible."
  8495. (interactive "P")
  8496. ;; Make sure we have markers, and only valid ones
  8497. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8498. (mapc
  8499. (lambda (m)
  8500. (unless (and (markerp m)
  8501. (marker-buffer m)
  8502. (buffer-live-p (marker-buffer m))
  8503. (marker-position m))
  8504. (error "Marker %s for bulk command is invalid" m)))
  8505. org-agenda-bulk-marked-entries)
  8506. ;; Prompt for the bulk command
  8507. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8508. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8509. "[S]catter [f]unction "
  8510. (when org-agenda-bulk-custom-functions
  8511. (concat " Custom: ["
  8512. (mapconcat (lambda(f) (char-to-string (car f)))
  8513. org-agenda-bulk-custom-functions "")
  8514. "]"))))
  8515. (catch 'exit
  8516. (let* ((action (read-char-exclusive))
  8517. (org-log-refile (if org-log-refile 'time nil))
  8518. (entries (reverse org-agenda-bulk-marked-entries))
  8519. (org-overriding-default-time
  8520. (if (get-text-property (point) 'org-agenda-date-header)
  8521. (org-get-cursor-date)))
  8522. redo-at-end
  8523. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8524. (cond
  8525. ((equal action ?p)
  8526. (let ((org-agenda-persistent-marks
  8527. (not org-agenda-persistent-marks)))
  8528. (org-agenda-bulk-action)
  8529. (throw 'exit nil)))
  8530. ((equal action ?$)
  8531. (setq cmd '(org-agenda-archive)))
  8532. ((equal action ?A)
  8533. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8534. ((member action '(?r ?w))
  8535. (setq rfloc (org-refile-get-location
  8536. "Refile to"
  8537. (marker-buffer (car entries))
  8538. org-refile-allow-creating-parent-nodes))
  8539. (if (nth 3 rfloc)
  8540. (setcar (nthcdr 3 rfloc)
  8541. (move-marker (make-marker) (nth 3 rfloc)
  8542. (or (get-file-buffer (nth 1 rfloc))
  8543. (find-buffer-visiting (nth 1 rfloc))
  8544. (error "This should not happen")))))
  8545. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8546. redo-at-end t))
  8547. ((equal action ?t)
  8548. (setq state (org-icompleting-read
  8549. "Todo state: "
  8550. (with-current-buffer (marker-buffer (car entries))
  8551. (mapcar 'list org-todo-keywords-1))))
  8552. (setq cmd `(let ((org-inhibit-blocking t)
  8553. (org-inhibit-logging 'note))
  8554. (org-agenda-todo ,state))))
  8555. ((memq action '(?- ?+))
  8556. (setq tag (org-icompleting-read
  8557. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8558. (with-current-buffer (marker-buffer (car entries))
  8559. (delq nil
  8560. (mapcar (lambda (x)
  8561. (if (stringp (car x)) x)) org-tag-alist)))))
  8562. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8563. ((memq action '(?s ?d))
  8564. (let* ((time
  8565. (unless arg
  8566. (org-read-date
  8567. nil nil nil
  8568. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8569. org-overriding-default-time)))
  8570. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8571. (setq cmd `(eval '(,c1 arg ,time)))))
  8572. ((equal action ?S)
  8573. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8574. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8575. (let ((days (read-number
  8576. (format "Scatter tasks across how many %sdays: "
  8577. (if arg "week" "")) 7)))
  8578. (setq cmd
  8579. `(let ((distance (1+ (random ,days))))
  8580. (if arg
  8581. (let ((dist distance)
  8582. (day-of-week
  8583. (calendar-day-of-week
  8584. (calendar-gregorian-from-absolute (org-today)))))
  8585. (dotimes (i (1+ dist))
  8586. (while (member day-of-week org-agenda-weekend-days)
  8587. (incf distance)
  8588. (incf day-of-week)
  8589. (if (= day-of-week 7)
  8590. (setq day-of-week 0)))
  8591. (incf day-of-week)
  8592. (if (= day-of-week 7)
  8593. (setq day-of-week 0)))))
  8594. ;; silently fail when try to replan a sexp entry
  8595. (condition-case nil
  8596. (let* ((date (calendar-gregorian-from-absolute
  8597. (+ (org-today) distance)))
  8598. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8599. (nth 2 date))))
  8600. (org-agenda-schedule nil time))
  8601. (error nil)))))))
  8602. ((assoc action org-agenda-bulk-custom-functions)
  8603. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8604. redo-at-end t))
  8605. ((equal action ?f)
  8606. (setq cmd (list (intern
  8607. (org-icompleting-read "Function: "
  8608. obarray 'fboundp t nil nil)))))
  8609. (t (error "Invalid bulk action")))
  8610. ;; Sort the markers, to make sure that parents are handled before children
  8611. (setq entries (sort entries
  8612. (lambda (a b)
  8613. (cond
  8614. ((equal (marker-buffer a) (marker-buffer b))
  8615. (< (marker-position a) (marker-position b)))
  8616. (t
  8617. (string< (buffer-name (marker-buffer a))
  8618. (buffer-name (marker-buffer b))))))))
  8619. ;; Now loop over all markers and apply cmd
  8620. (while (setq e (pop entries))
  8621. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8622. (if (not pos)
  8623. (progn (message "Skipping removed entry at %s" e)
  8624. (setq cntskip (1+ cntskip)))
  8625. (goto-char pos)
  8626. (let (org-loop-over-headlines-in-active-region)
  8627. (eval cmd))
  8628. (setq cnt (1+ cnt))))
  8629. (when redo-at-end (org-agenda-redo))
  8630. (unless org-agenda-persistent-marks
  8631. (org-agenda-bulk-unmark-all))
  8632. (message "Acted on %d entries%s%s"
  8633. cnt
  8634. (if (= cntskip 0)
  8635. ""
  8636. (format ", skipped %d (disappeared before their turn)"
  8637. cntskip))
  8638. (if (not org-agenda-persistent-marks)
  8639. "" " (kept marked)"))))))
  8640. (defun org-agenda-capture ()
  8641. "Call `org-capture' with the date at point."
  8642. (interactive)
  8643. (if (not (eq major-mode 'org-agenda-mode))
  8644. (error "You cannot do this outside of agenda buffers")
  8645. (let ((org-overriding-default-time
  8646. (org-get-cursor-date)))
  8647. (call-interactively 'org-capture))))
  8648. ;;; Flagging notes
  8649. (defun org-agenda-show-the-flagging-note ()
  8650. "Display the flagging note in the other window.
  8651. When called a second time in direct sequence, offer to remove the FLAGGING
  8652. tag and (if present) the flagging note."
  8653. (interactive)
  8654. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8655. (win (selected-window))
  8656. note heading newhead)
  8657. (unless hdmarker
  8658. (error "No linked entry at point"))
  8659. (if (and (eq this-command last-command)
  8660. (y-or-n-p "Unflag and remove any flagging note? "))
  8661. (progn
  8662. (org-agenda-remove-flag hdmarker)
  8663. (let ((win (get-buffer-window "*Flagging Note*")))
  8664. (and win (delete-window win)))
  8665. (message "Entry unflagged"))
  8666. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8667. (unless note
  8668. (error "No flagging note"))
  8669. (org-kill-new note)
  8670. (org-switch-to-buffer-other-window "*Flagging Note*")
  8671. (erase-buffer)
  8672. (insert note)
  8673. (goto-char (point-min))
  8674. (while (re-search-forward "\\\\n" nil t)
  8675. (replace-match "\n" t t))
  8676. (goto-char (point-min))
  8677. (select-window win)
  8678. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8679. (defun org-agenda-remove-flag (marker)
  8680. "Remove the FLAGGED tag and any flagging note in the entry."
  8681. (let (newhead)
  8682. (org-with-point-at marker
  8683. (org-toggle-tag "FLAGGED" 'off)
  8684. (org-entry-delete nil "THEFLAGGINGNOTE")
  8685. (setq newhead (org-get-heading)))
  8686. (org-agenda-change-all-lines newhead marker)
  8687. (message "Entry unflagged")))
  8688. (defun org-agenda-get-any-marker (&optional pos)
  8689. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8690. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8691. ;;; Appointment reminders
  8692. (defvar appt-time-msg-list) ; defined in appt.el
  8693. ;;;###autoload
  8694. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8695. "Activate appointments found in `org-agenda-files'.
  8696. With a \\[universal-argument] prefix, refresh the list of
  8697. appointments.
  8698. If FILTER is t, interactively prompt the user for a regular
  8699. expression, and filter out entries that don't match it.
  8700. If FILTER is a string, use this string as a regular expression
  8701. for filtering entries out.
  8702. If FILTER is a function, filter out entries against which
  8703. calling the function returns nil. This function takes one
  8704. argument: an entry from `org-agenda-get-day-entries'.
  8705. FILTER can also be an alist with the car of each cell being
  8706. either 'headline or 'category. For example:
  8707. '((headline \"IMPORTANT\")
  8708. (category \"Work\"))
  8709. will only add headlines containing IMPORTANT or headlines
  8710. belonging to the \"Work\" category.
  8711. ARGS are symbols indicating what kind of entries to consider.
  8712. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8713. and :timestamp entries. See the docstring of `org-diary' for
  8714. details and examples.
  8715. If an entry as a APPT_WARNTIME property, its value will be used
  8716. to override `appt-message-warning-time'."
  8717. (interactive "P")
  8718. (if refresh (setq appt-time-msg-list nil))
  8719. (if (eq filter t)
  8720. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8721. (let* ((cnt 0) ; count added events
  8722. (scope (or args '(:deadline :scheduled :timestamp)))
  8723. (org-agenda-new-buffers nil)
  8724. (org-deadline-warning-days 0)
  8725. ;; Do not use `org-today' here because appt only takes
  8726. ;; time and without date as argument, so it may pass wrong
  8727. ;; information otherwise
  8728. (today (org-date-to-gregorian
  8729. (time-to-days (current-time))))
  8730. (org-agenda-restrict nil)
  8731. (files (org-agenda-files 'unrestricted)) entries file
  8732. (org-agenda-buffer nil))
  8733. ;; Get all entries which may contain an appt
  8734. (org-agenda-prepare-buffers files)
  8735. (while (setq file (pop files))
  8736. (setq entries
  8737. (delq nil
  8738. (append entries
  8739. (apply 'org-agenda-get-day-entries
  8740. file today scope)))))
  8741. ;; Map thru entries and find if we should filter them out
  8742. (mapc
  8743. (lambda(x)
  8744. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8745. (cat (get-text-property 1 'org-category x))
  8746. (tod (get-text-property 1 'time-of-day x))
  8747. (ok (or (null filter)
  8748. (and (stringp filter) (string-match filter evt))
  8749. (and (functionp filter) (funcall filter x))
  8750. (and (listp filter)
  8751. (let ((cat-filter (cadr (assoc 'category filter)))
  8752. (evt-filter (cadr (assoc 'headline filter))))
  8753. (or (and (stringp cat-filter)
  8754. (string-match cat-filter cat))
  8755. (and (stringp evt-filter)
  8756. (string-match evt-filter evt)))))))
  8757. (wrn (get-text-property 1 'warntime x)))
  8758. ;; FIXME: Shall we remove text-properties for the appt text?
  8759. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8760. (when (and ok tod)
  8761. (setq tod (concat "00" (number-to-string tod))
  8762. tod (when (string-match
  8763. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8764. (concat (match-string 1 tod) ":"
  8765. (match-string 2 tod))))
  8766. (if (version< emacs-version "23.3")
  8767. (appt-add tod evt)
  8768. (appt-add tod evt wrn))
  8769. (setq cnt (1+ cnt))))) entries)
  8770. (org-release-buffers org-agenda-new-buffers)
  8771. (if (eq cnt 0)
  8772. (message "No event to add")
  8773. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8774. (autoload 'org-agenda-to-appt "org-agenda" "\
  8775. Activate appointments found in `org-agenda-files'.
  8776. With a \\[universal-argument] prefix, refresh the list of
  8777. appointments.
  8778. If FILTER is t, interactively prompt the user for a regular
  8779. expression, and filter out entries that don't match it.
  8780. If FILTER is a string, use this string as a regular expression
  8781. for filtering entries out.
  8782. If FILTER is a function, filter out entries against which
  8783. calling the function returns nil. This function takes one
  8784. argument: an entry from `org-agenda-get-day-entries'.
  8785. FILTER can also be an alist with the car of each cell being
  8786. either 'headline or 'category. For example:
  8787. '((headline \"IMPORTANT\")
  8788. (category \"Work\"))
  8789. will only add headlines containing IMPORTANT or headlines
  8790. belonging to the \"Work\" category.
  8791. ARGS are symbols indicating what kind of entries to consider.
  8792. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8793. and :timestamp entries. See the docstring of `org-diary' for
  8794. details and examples.
  8795. If an entry as a APPT_WARNTIME property, its value will be used
  8796. to override `appt-message-warning-time'.
  8797. \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
  8798. (defun org-agenda-todayp (date)
  8799. "Does DATE mean today, when considering `org-extend-today-until'?"
  8800. (let ((today (org-today))
  8801. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8802. date)))
  8803. (eq date today)))
  8804. (defun org-agenda-todo-yesterday (&optional arg)
  8805. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8806. (interactive "P")
  8807. (let* ((hour (third (decode-time
  8808. (org-current-time))))
  8809. (org-extend-today-until (1+ hour)))
  8810. (org-agenda-todo arg)))
  8811. (provide 'org-agenda)
  8812. ;;; org-agenda.el ends here