org-agenda.el 327 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2011 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 conveniant way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-datetree-find-date-create "org-datetree"
  63. (date &optional keep-restriction))
  64. (declare-function org-columns-quit "org-colview" ())
  65. (declare-function diary-date-display-form "diary-lib" (&optional type))
  66. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  67. (declare-function org-habit-insert-consistency-graphs
  68. "org-habit" (&optional line))
  69. (declare-function org-is-habit-p "org-habit" (&optional pom))
  70. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  71. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  72. (declare-function org-pop-to-buffer-same-window "org-compat"
  73. (&optional buffer-or-name norecord label))
  74. (defvar calendar-mode-map)
  75. (defvar org-clock-current-task) ; defined in org-clock.el
  76. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  77. (defvar org-habit-show-habits)
  78. (defvar org-habit-show-habits-only-for-today)
  79. ;; Defined somewhere in this file, but used before definition.
  80. (defvar org-agenda-buffer-name)
  81. (defvar org-agenda-overriding-header)
  82. (defvar org-agenda-title-append nil)
  83. (defvar entry)
  84. (defvar date)
  85. (defvar org-agenda-undo-list)
  86. (defvar org-agenda-pending-undo-list)
  87. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  88. (defcustom org-agenda-confirm-kill 1
  89. "When set, remote killing from the agenda buffer needs confirmation.
  90. When t, a confirmation is always needed. When a number N, confirmation is
  91. only needed when the text to be killed contains more than N non-white lines."
  92. :group 'org-agenda
  93. :type '(choice
  94. (const :tag "Never" nil)
  95. (const :tag "Always" t)
  96. (integer :tag "When more than N lines")))
  97. (defcustom org-agenda-compact-blocks nil
  98. "Non-nil means make the block agenda more compact.
  99. This is done globally by leaving out lines like the agenda span
  100. name and week number or the separator lines."
  101. :group 'org-agenda
  102. :type 'boolean)
  103. (defcustom org-agenda-block-separator ?=
  104. "The separator between blocks in the agenda.
  105. If this is a string, it will be used as the separator, with a newline added.
  106. If it is a character, it will be repeated to fill the window width.
  107. If nil the separator is disabled. In `org-agenda-custom-commands' this
  108. addresses the separator between the current and the previous block."
  109. :group 'org-agenda
  110. :type '(choice
  111. (const :tag "Disabled" nil)
  112. (character)
  113. (string)))
  114. (defgroup org-agenda-export nil
  115. "Options concerning exporting agenda views in Org-mode."
  116. :tag "Org Agenda Export"
  117. :group 'org-agenda)
  118. (defcustom org-agenda-with-colors t
  119. "Non-nil means use colors in agenda views."
  120. :group 'org-agenda-export
  121. :type 'boolean)
  122. (defcustom org-agenda-exporter-settings nil
  123. "Alist of variable/value pairs that should be active during agenda export.
  124. This is a good place to set options for ps-print and for htmlize.
  125. Note that the way this is implemented, the values will be evaluated
  126. before assigned to the variables. So make sure to quote values you do
  127. *not* want evaluated, for example
  128. (setq org-agenda-exporter-settings
  129. '((ps-print-color-p 'black-white)))"
  130. :group 'org-agenda-export
  131. :type '(repeat
  132. (list
  133. (variable)
  134. (sexp :tag "Value"))))
  135. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  136. "Hook run in temporary buffer before writing it to an export file.
  137. A useful function is `org-agenda-add-entry-text'."
  138. :group 'org-agenda-export
  139. :type 'hook
  140. :options '(org-agenda-add-entry-text))
  141. (defcustom org-agenda-add-entry-text-maxlines 0
  142. "Maximum number of entry text lines to be added to agenda.
  143. This is only relevant when `org-agenda-add-entry-text' is part of
  144. `org-agenda-before-write-hook', which it is by default.
  145. When this is 0, nothing will happen. When it is greater than 0, it
  146. specifies the maximum number of lines that will be added for each entry
  147. that is listed in the agenda view.
  148. Note that this variable is not used during display, only when exporting
  149. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  150. and `org-agenda-entry-text-maxlines'."
  151. :group 'org-agenda
  152. :type 'integer)
  153. (defcustom org-agenda-add-entry-text-descriptive-links t
  154. "Non-nil means export org-links as descriptive links in agenda added text.
  155. This variable applies to the text added to the agenda when
  156. `org-agenda-add-entry-text-maxlines' is larger than 0.
  157. When this variable nil, the URL will (also) be shown."
  158. :group 'org-agenda
  159. :type 'boolean)
  160. (defcustom org-agenda-export-html-style ""
  161. "The style specification for exported HTML Agenda files.
  162. If this variable contains a string, it will replace the default <style>
  163. section as produced by `htmlize'.
  164. Since there are different ways of setting style information, this variable
  165. needs to contain the full HTML structure to provide a style, including the
  166. surrounding HTML tags. The style specifications should include definitions
  167. the fonts used by the agenda, here is an example:
  168. <style type=\"text/css\">
  169. p { font-weight: normal; color: gray; }
  170. .org-agenda-structure {
  171. font-size: 110%;
  172. color: #003399;
  173. font-weight: 600;
  174. }
  175. .org-todo {
  176. color: #cc6666;
  177. font-weight: bold;
  178. }
  179. .org-agenda-done {
  180. color: #339933;
  181. }
  182. .org-done {
  183. color: #339933;
  184. }
  185. .title { text-align: center; }
  186. .todo, .deadline { color: red; }
  187. .done { color: green; }
  188. </style>
  189. or, if you want to keep the style in a file,
  190. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  191. As the value of this option simply gets inserted into the HTML <head> header,
  192. you can \"misuse\" it to also add other text to the header. However,
  193. <style>...</style> is required, if not present the variable will be ignored."
  194. :group 'org-agenda-export
  195. :group 'org-export-html
  196. :type 'string)
  197. (defcustom org-agenda-persistent-filter nil
  198. "When set, keep filters from one agenda view to the next."
  199. :group 'org-agenda
  200. :type 'boolean)
  201. (defgroup org-agenda-custom-commands nil
  202. "Options concerning agenda views in Org-mode."
  203. :tag "Org Agenda Custom Commands"
  204. :group 'org-agenda)
  205. (defconst org-sorting-choice
  206. '(choice
  207. (const time-up) (const time-down)
  208. (const category-keep) (const category-up) (const category-down)
  209. (const tag-down) (const tag-up)
  210. (const priority-up) (const priority-down)
  211. (const todo-state-up) (const todo-state-down)
  212. (const effort-up) (const effort-down)
  213. (const habit-up) (const habit-down)
  214. (const alpha-up) (const alpha-down)
  215. (const user-defined-up) (const user-defined-down))
  216. "Sorting choices.")
  217. (defconst org-agenda-custom-commands-local-options
  218. `(repeat :tag "Local settings for this command. Remember to quote values"
  219. (choice :tag "Setting"
  220. (list :tag "Heading for this block"
  221. (const org-agenda-overriding-header)
  222. (string :tag "Headline"))
  223. (list :tag "Files to be searched"
  224. (const org-agenda-files)
  225. (list
  226. (const :format "" quote)
  227. (repeat (file))))
  228. (list :tag "Sorting strategy"
  229. (const org-agenda-sorting-strategy)
  230. (list
  231. (const :format "" quote)
  232. (repeat
  233. ,org-sorting-choice)))
  234. (list :tag "Prefix format"
  235. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  236. (string))
  237. (list :tag "Number of days in agenda"
  238. (const org-agenda-span)
  239. (choice (const :tag "Day" 'day)
  240. (const :tag "Week" 'week)
  241. (const :tag "Month" 'month)
  242. (const :tag "Year" 'year)
  243. (integer :tag "Custom")))
  244. (list :tag "Fixed starting date"
  245. (const org-agenda-start-day)
  246. (string :value "2007-11-01"))
  247. (list :tag "Start on day of week"
  248. (const org-agenda-start-on-weekday)
  249. (choice :value 1
  250. (const :tag "Today" nil)
  251. (integer :tag "Weekday No.")))
  252. (list :tag "Include data from diary"
  253. (const org-agenda-include-diary)
  254. (boolean))
  255. (list :tag "Deadline Warning days"
  256. (const org-deadline-warning-days)
  257. (integer :value 1))
  258. (list :tag "Tags filter preset"
  259. (const org-agenda-filter-preset)
  260. (list
  261. (const :format "" quote)
  262. (repeat
  263. (string :tag "+tag or -tag"))))
  264. (list :tag "Set daily/weekly entry types"
  265. (const org-agenda-entry-types)
  266. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  267. (const :deadline)
  268. (const :scheduled)
  269. (const :timestamp)
  270. (const :sexp)))
  271. (list :tag "Standard skipping condition"
  272. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  273. (const org-agenda-skip-function)
  274. (list
  275. (const :format "" quote)
  276. (list
  277. (choice
  278. :tag "Skipping range"
  279. (const :tag "Skip entry" org-agenda-skip-entry-if)
  280. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  281. (repeat :inline t :tag "Conditions for skipping"
  282. (choice
  283. :tag "Condition type"
  284. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  285. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  286. (list :tag "TODO state is" :inline t
  287. (const 'todo)
  288. (choice
  289. (const :tag "any not-done state" 'todo)
  290. (const :tag "any done state" 'done)
  291. (const :tag "any state" 'any)
  292. (list :tag "Keyword list"
  293. (const :format "" quote)
  294. (repeat (string :tag "Keyword")))))
  295. (list :tag "TODO state is not" :inline t
  296. (const 'nottodo)
  297. (choice
  298. (const :tag "any not-done state" 'todo)
  299. (const :tag "any done state" 'done)
  300. (const :tag "any state" 'any)
  301. (list :tag "Keyword list"
  302. (const :format "" quote)
  303. (repeat (string :tag "Keyword")))))
  304. (const :tag "scheduled" 'scheduled)
  305. (const :tag "not scheduled" 'notscheduled)
  306. (const :tag "deadline" 'deadline)
  307. (const :tag "no deadline" 'notdeadline)
  308. (const :tag "timestamp" 'timestamp)
  309. (const :tag "no timestamp" 'nottimestamp))))))
  310. (list :tag "Non-standard skipping condition"
  311. :value (org-agenda-skip-function)
  312. (const org-agenda-skip-function)
  313. (sexp :tag "Function or form (quoted!)"))
  314. (list :tag "Any variable"
  315. (variable :tag "Variable")
  316. (sexp :tag "Value (sexp)"))))
  317. "Selection of examples for agenda command settings.
  318. This will be spliced into the custom type of
  319. `org-agenda-custom-commands'.")
  320. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  321. ((agenda "") (alltodo))))
  322. "Custom commands for the agenda.
  323. These commands will be offered on the splash screen displayed by the
  324. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  325. (key desc type match settings files)
  326. key The key (one or more characters as a string) to be associated
  327. with the command.
  328. desc A description of the command, when omitted or nil, a default
  329. description is built using MATCH.
  330. type The command type, any of the following symbols:
  331. agenda The daily/weekly agenda.
  332. todo Entries with a specific TODO keyword, in all agenda files.
  333. search Entries containing search words entry or headline.
  334. tags Tags/Property/TODO match in all agenda files.
  335. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  336. todo-tree Sparse tree of specific TODO keyword in *current* file.
  337. tags-tree Sparse tree with all tags matches in *current* file.
  338. occur-tree Occur sparse tree for *current* file.
  339. ... A user-defined function.
  340. match What to search for:
  341. - a single keyword for TODO keyword searches
  342. - a tags match expression for tags searches
  343. - a word search expression for text searches.
  344. - a regular expression for occur searches
  345. For all other commands, this should be the empty string.
  346. settings A list of option settings, similar to that in a let form, so like
  347. this: ((opt1 val1) (opt2 val2) ...). The values will be
  348. evaluated at the moment of execution, so quote them when needed.
  349. files A list of files file to write the produced agenda buffer to
  350. with the command `org-store-agenda-views'.
  351. If a file name ends in \".html\", an HTML version of the buffer
  352. is written out. If it ends in \".ps\", a postscript version is
  353. produced. Otherwise, only the plain text is written to the file.
  354. You can also define a set of commands, to create a composite agenda buffer.
  355. In this case, an entry looks like this:
  356. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  357. where
  358. desc A description string to be displayed in the dispatcher menu.
  359. cmd An agenda command, similar to the above. However, tree commands
  360. are no allowed, but instead you can get agenda and global todo list.
  361. So valid commands for a set are:
  362. (agenda \"\" settings)
  363. (alltodo \"\" settings)
  364. (stuck \"\" settings)
  365. (todo \"match\" settings files)
  366. (search \"match\" settings files)
  367. (tags \"match\" settings files)
  368. (tags-todo \"match\" settings files)
  369. Each command can carry a list of options, and another set of options can be
  370. given for the whole set of commands. Individual command options take
  371. precedence over the general options.
  372. When using several characters as key to a command, the first characters
  373. are prefix commands. For the dispatcher to display useful information, you
  374. should provide a description for the prefix, like
  375. (setq org-agenda-custom-commands
  376. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  377. (\"hl\" tags \"+HOME+Lisa\")
  378. (\"hp\" tags \"+HOME+Peter\")
  379. (\"hk\" tags \"+HOME+Kim\")))"
  380. :group 'org-agenda-custom-commands
  381. :type `(repeat
  382. (choice :value ("x" "Describe command here" tags "" nil)
  383. (list :tag "Single command"
  384. (string :tag "Access Key(s) ")
  385. (option (string :tag "Description"))
  386. (choice
  387. (const :tag "Agenda" agenda)
  388. (const :tag "TODO list" alltodo)
  389. (const :tag "Search words" search)
  390. (const :tag "Stuck projects" stuck)
  391. (const :tag "Tags/Property match (all agenda files)" tags)
  392. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  393. (const :tag "TODO keyword search (all agenda files)" todo)
  394. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  395. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  396. (const :tag "Occur tree (current buffer)" occur-tree)
  397. (sexp :tag "Other, user-defined function"))
  398. (string :tag "Match (only for some commands)")
  399. ,org-agenda-custom-commands-local-options
  400. (option (repeat :tag "Export" (file :tag "Export to"))))
  401. (list :tag "Command series, all agenda files"
  402. (string :tag "Access Key(s)")
  403. (string :tag "Description ")
  404. (repeat :tag "Component"
  405. (choice
  406. (list :tag "Agenda"
  407. (const :format "" agenda)
  408. (const :tag "" :format "" "")
  409. ,org-agenda-custom-commands-local-options)
  410. (list :tag "TODO list (all keywords)"
  411. (const :format "" alltodo)
  412. (const :tag "" :format "" "")
  413. ,org-agenda-custom-commands-local-options)
  414. (list :tag "Search words"
  415. (const :format "" search)
  416. (string :tag "Match")
  417. ,org-agenda-custom-commands-local-options)
  418. (list :tag "Stuck projects"
  419. (const :format "" stuck)
  420. (const :tag "" :format "" "")
  421. ,org-agenda-custom-commands-local-options)
  422. (list :tag "Tags search"
  423. (const :format "" tags)
  424. (string :tag "Match")
  425. ,org-agenda-custom-commands-local-options)
  426. (list :tag "Tags search, TODO entries only"
  427. (const :format "" tags-todo)
  428. (string :tag "Match")
  429. ,org-agenda-custom-commands-local-options)
  430. (list :tag "TODO keyword search"
  431. (const :format "" todo)
  432. (string :tag "Match")
  433. ,org-agenda-custom-commands-local-options)
  434. (list :tag "Other, user-defined function"
  435. (symbol :tag "function")
  436. (string :tag "Match")
  437. ,org-agenda-custom-commands-local-options)))
  438. (repeat :tag "Settings for entire command set"
  439. (list (variable :tag "Any variable")
  440. (sexp :tag "Value")))
  441. (option (repeat :tag "Export" (file :tag "Export to"))))
  442. (cons :tag "Prefix key documentation"
  443. (string :tag "Access Key(s)")
  444. (string :tag "Description ")))))
  445. (defcustom org-agenda-query-register ?o
  446. "The register holding the current query string.
  447. The purpose of this is that if you construct a query string interactively,
  448. you can then use it to define a custom command."
  449. :group 'org-agenda-custom-commands
  450. :type 'character)
  451. (defcustom org-stuck-projects
  452. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  453. "How to identify stuck projects.
  454. This is a list of four items:
  455. 1. A tags/todo/property matcher string that is used to identify a project.
  456. See the manual for a description of tag and property searches.
  457. The entire tree below a headline matched by this is considered one project.
  458. 2. A list of TODO keywords identifying non-stuck projects.
  459. If the project subtree contains any headline with one of these todo
  460. keywords, the project is considered to be not stuck. If you specify
  461. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  462. 3. A list of tags identifying non-stuck projects.
  463. If the project subtree contains any headline with one of these tags,
  464. the project is considered to be not stuck. If you specify \"*\" as
  465. a tag, any tag will mark the project unstuck. Note that this is about
  466. the explicit presence of a tag somewhere in the subtree, inherited
  467. tags to not count here. If inherited tags make a project not stuck,
  468. use \"-TAG\" in the tags part of the matcher under (1.) above.
  469. 4. An arbitrary regular expression matching non-stuck projects.
  470. If the project turns out to be not stuck, search continues also in the
  471. subtree to see if any of the subtasks have project status.
  472. See also the variable `org-tags-match-list-sublevels' which applies
  473. to projects matched by this search as well.
  474. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  475. or `C-c a #' to produce the list."
  476. :group 'org-agenda-custom-commands
  477. :type '(list
  478. (string :tag "Tags/TODO match to identify a project")
  479. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  480. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  481. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  482. (defcustom org-agenda-filter-effort-default-operator "<"
  483. "The default operator for effort estimate filtering.
  484. If you select an effort estimate limit without first pressing an operator,
  485. this one will be used."
  486. :group 'org-agenda-custom-commands
  487. :type '(choice (const :tag "less or equal" "<")
  488. (const :tag "greater or equal"">")
  489. (const :tag "equal" "=")))
  490. (defgroup org-agenda-skip nil
  491. "Options concerning skipping parts of agenda files."
  492. :tag "Org Agenda Skip"
  493. :group 'org-agenda)
  494. (defcustom org-agenda-skip-function-global nil
  495. "Function to be called at each match during agenda construction.
  496. If this function returns nil, the current match should not be skipped.
  497. If the function decided to skip an agenda match, is must return the
  498. buffer position from which the search should be continued.
  499. This may also be a Lisp form, which will be evaluated.
  500. This variable will be applied to every agenda match, including
  501. tags/property searches and TODO lists. So try to make the test function
  502. do its checking as efficiently as possible. To implement a skipping
  503. condition just for specific agenda commands, use the variable
  504. `org-agenda-skip-function' which can be set in the options section
  505. of custom agenda commands."
  506. :group 'org-agenda-skip
  507. :type 'sexp)
  508. (defgroup org-agenda-daily/weekly nil
  509. "Options concerning the daily/weekly agenda."
  510. :tag "Org Agenda Daily/Weekly"
  511. :group 'org-agenda)
  512. (defgroup org-agenda-todo-list nil
  513. "Options concerning the global todo list agenda view."
  514. :tag "Org Agenda Todo List"
  515. :group 'org-agenda)
  516. (defgroup org-agenda-match-view nil
  517. "Options concerning the general tags/property/todo match agenda view."
  518. :tag "Org Agenda Match View"
  519. :group 'org-agenda)
  520. (defgroup org-agenda-search-view nil
  521. "Options concerning the general tags/property/todo match agenda view."
  522. :tag "Org Agenda Match View"
  523. :group 'org-agenda)
  524. (defvar org-agenda-archives-mode nil
  525. "Non-nil means the agenda will include archived items.
  526. If this is the symbol `trees', trees in the selected agenda scope
  527. that are marked with the ARCHIVE tag will be included anyway. When this is
  528. t, also all archive files associated with the current selection of agenda
  529. files will be included.")
  530. (defcustom org-agenda-skip-comment-trees t
  531. "Non-nil means skip trees that start with the COMMENT keyword.
  532. When nil, these trees are also scanned by agenda commands."
  533. :group 'org-agenda-skip
  534. :type 'boolean)
  535. (defcustom org-agenda-todo-list-sublevels t
  536. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  537. When nil, the sublevels of a TODO entry are not checked, resulting in
  538. potentially much shorter TODO lists."
  539. :group 'org-agenda-skip
  540. :group 'org-agenda-todo-list
  541. :type 'boolean)
  542. (defcustom org-agenda-todo-ignore-with-date nil
  543. "Non-nil means don't show entries with a date in the global todo list.
  544. You can use this if you prefer to mark mere appointments with a TODO keyword,
  545. but don't want them to show up in the TODO list.
  546. When this is set, it also covers deadlines and scheduled items, the settings
  547. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  548. will be ignored.
  549. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  550. :group 'org-agenda-skip
  551. :group 'org-agenda-todo-list
  552. :type 'boolean)
  553. (defcustom org-agenda-todo-ignore-timestamp nil
  554. "Non-nil means don't show entries with a timestamp.
  555. This applies when creating the global todo list.
  556. Valid values are:
  557. past Don't show entries for today or in the past.
  558. future Don't show entries with a timestamp in the future.
  559. The idea behind this is that if it has a future
  560. timestamp, you don't want to think about it until the
  561. date.
  562. all Don't show any entries with a timestamp in the global todo list.
  563. The idea behind this is that by setting a timestamp, you
  564. have already \"taken care\" of this item.
  565. This variable can also have an integer as a value. If positive (N),
  566. todos with a timestamp N or more days in the future will be ignored. If
  567. negative (-N), todos with a timestamp N or more days in the past will be
  568. ignored. If 0, todos with a timestamp either today or in the future will
  569. be ignored. For example, a value of -1 will exclude todos with a
  570. timestamp in the past (yesterday or earlier), while a value of 7 will
  571. exclude todos with a timestamp a week or more in the future.
  572. See also `org-agenda-todo-ignore-with-date'.
  573. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  574. to make his option also apply to the tags-todo list."
  575. :group 'org-agenda-skip
  576. :group 'org-agenda-todo-list
  577. :type '(choice
  578. (const :tag "Ignore future timestamp todos" future)
  579. (const :tag "Ignore past or present timestamp todos" past)
  580. (const :tag "Ignore all timestamp todos" all)
  581. (const :tag "Show timestamp todos" nil)
  582. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  583. (defcustom org-agenda-todo-ignore-scheduled nil
  584. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  585. This applies when creating the global todo list.
  586. Valid values are:
  587. past Don't show entries scheduled today or in the past.
  588. future Don't show entries scheduled in the future.
  589. The idea behind this is that by scheduling it, you don't want to
  590. think about it until the scheduled date.
  591. all Don't show any scheduled entries in the global todo list.
  592. The idea behind this is that by scheduling it, you have already
  593. \"taken care\" of this item.
  594. t Same as `all', for backward compatibility.
  595. This variable can also have an integer as a value. See
  596. `org-agenda-todo-ignore-timestamp' for more details.
  597. See also `org-agenda-todo-ignore-with-date'.
  598. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  599. to make his option also apply to the tags-todo list."
  600. :group 'org-agenda-skip
  601. :group 'org-agenda-todo-list
  602. :type '(choice
  603. (const :tag "Ignore future-scheduled todos" future)
  604. (const :tag "Ignore past- or present-scheduled todos" past)
  605. (const :tag "Ignore all scheduled todos" all)
  606. (const :tag "Ignore all scheduled todos (compatibility)" t)
  607. (const :tag "Show scheduled todos" nil)
  608. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  609. (defcustom org-agenda-todo-ignore-deadlines nil
  610. "Non-nil means ignore some deadlined TODO items when making TODO list.
  611. There are different motivations for using different values, please think
  612. carefully when configuring this variable.
  613. This applies when creating the global todo list.
  614. Valid values are:
  615. near Don't show near deadline entries. A deadline is near when it is
  616. closer than `org-deadline-warning-days' days. The idea behind this
  617. is that such items will appear in the agenda anyway.
  618. far Don't show TODO entries where a deadline has been defined, but
  619. the deadline is not near. This is useful if you don't want to
  620. use the todo list to figure out what to do now.
  621. past Don't show entries with a deadline timestamp for today or in the past.
  622. future Don't show entries with a deadline timestamp in the future, not even
  623. when they become `near' ones. Use it with caution.
  624. all Ignore all TODO entries that do have a deadline.
  625. t Same as `near', for backward compatibility.
  626. This variable can also have an integer as a value. See
  627. `org-agenda-todo-ignore-timestamp' for more details.
  628. See also `org-agenda-todo-ignore-with-date'.
  629. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  630. to make his option also apply to the tags-todo list."
  631. :group 'org-agenda-skip
  632. :group 'org-agenda-todo-list
  633. :type '(choice
  634. (const :tag "Ignore near deadlines" near)
  635. (const :tag "Ignore near deadlines (compatibility)" t)
  636. (const :tag "Ignore far deadlines" far)
  637. (const :tag "Ignore all TODOs with a deadlines" all)
  638. (const :tag "Show all TODOs, even if they have a deadline" nil)
  639. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  640. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  641. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  642. The variables
  643. `org-agenda-todo-ignore-with-date',
  644. `org-agenda-todo-ignore-timestamp',
  645. `org-agenda-todo-ignore-scheduled',
  646. `org-agenda-todo-ignore-deadlines'
  647. make the global TODO list skip entries that have time stamps of certain
  648. kinds. If this option is set, the same options will also apply for the
  649. tags-todo search, which is the general tags/property matcher
  650. restricted to unfinished TODO entries only."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :group 'org-agenda-match-view
  654. :type 'boolean)
  655. (defcustom org-agenda-skip-scheduled-if-done nil
  656. "Non-nil means don't show scheduled items in agenda when they are done.
  657. This is relevant for the daily/weekly agenda, not for the TODO list. And
  658. it applies only to the actual date of the scheduling. Warnings about
  659. an item with a past scheduling dates are always turned off when the item
  660. is DONE."
  661. :group 'org-agenda-skip
  662. :group 'org-agenda-daily/weekly
  663. :type 'boolean)
  664. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  665. "Non-nil means skip scheduling line if same entry shows because of deadline.
  666. In the agenda of today, an entry can show up multiple times because
  667. it is both scheduled and has a nearby deadline, and maybe a plain time
  668. stamp as well.
  669. When this variable is t, then only the deadline is shown and the fact that
  670. the entry is scheduled today or was scheduled previously is not shown.
  671. When this variable is nil, the entry will be shown several times. When
  672. the variable is the symbol `not-today', then skip scheduled previously,
  673. but not scheduled today."
  674. :group 'org-agenda-skip
  675. :group 'org-agenda-daily/weekly
  676. :type '(choice
  677. (const :tag "Never" nil)
  678. (const :tag "Always" t)
  679. (const :tag "Not when scheduled today" not-today)))
  680. (defcustom org-agenda-skip-deadline-if-done nil
  681. "Non-nil means don't show deadlines when the corresponding item is done.
  682. When nil, the deadline is still shown and should give you a happy feeling.
  683. This is relevant for the daily/weekly agenda. And it applied only to the
  684. actually date of the deadline. Warnings about approaching and past-due
  685. deadlines are always turned off when the item is DONE."
  686. :group 'org-agenda-skip
  687. :group 'org-agenda-daily/weekly
  688. :type 'boolean)
  689. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  690. "Non-nil means skip deadline prewarning when entry is also scheduled.
  691. This will apply on all days where a prewarning for the deadline would
  692. be shown, but not at the day when the entry is actually due. On that day,
  693. the deadline will be shown anyway.
  694. This variable may be set to nil, t, or a number which will then give
  695. the number of days before the actual deadline when the prewarnings
  696. should resume.
  697. This can be used in a workflow where the first showing of the deadline will
  698. trigger you to schedule it, and then you don't want to be reminded of it
  699. because you will take care of it on the day when scheduled."
  700. :group 'org-agenda-skip
  701. :group 'org-agenda-daily/weekly
  702. :type '(choice
  703. (const :tag "Alwas show prewarning" nil)
  704. (const :tag "Remove prewarning if entry is scheduled" t)
  705. (integer :tag "Restart prewarning N days before deadline")))
  706. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  707. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  708. When non-nil, after the search for timestamps has matched once in an
  709. entry, the rest of the entry will not be searched."
  710. :group 'org-agenda-skip
  711. :type 'boolean)
  712. (defcustom org-agenda-skip-timestamp-if-done nil
  713. "Non-nil means don't select item by timestamp or -range if it is DONE."
  714. :group 'org-agenda-skip
  715. :group 'org-agenda-daily/weekly
  716. :type 'boolean)
  717. (defcustom org-agenda-dim-blocked-tasks t
  718. "Non-nil means dim blocked tasks in the agenda display.
  719. This causes some overhead during agenda construction, but if you
  720. have turned on `org-enforce-todo-dependencies',
  721. `org-enforce-todo-checkbox-dependencies', or any other blocking
  722. mechanism, this will create useful feedback in the agenda.
  723. Instead of t, this variable can also have the value `invisible'.
  724. Then blocked tasks will be invisible and only become visible when
  725. they become unblocked. An exemption to this behavior is when a task is
  726. blocked because of unchecked checkboxes below it. Since checkboxes do
  727. not show up in the agenda views, making this task invisible you remove any
  728. trace from agenda views that there is something to do. Therefore, a task
  729. that is blocked because of checkboxes will never be made invisible, it
  730. will only be dimmed."
  731. :group 'org-agenda-daily/weekly
  732. :group 'org-agenda-todo-list
  733. :type '(choice
  734. (const :tag "Do not dim" nil)
  735. (const :tag "Dim to a gray face" t)
  736. (const :tag "Make invisible" invisible)))
  737. (defcustom org-timeline-show-empty-dates 3
  738. "Non-nil means `org-timeline' also shows dates without an entry.
  739. When nil, only the days which actually have entries are shown.
  740. When t, all days between the first and the last date are shown.
  741. When an integer, show also empty dates, but if there is a gap of more than
  742. N days, just insert a special line indicating the size of the gap."
  743. :group 'org-agenda-skip
  744. :type '(choice
  745. (const :tag "None" nil)
  746. (const :tag "All" t)
  747. (integer :tag "at most")))
  748. (defgroup org-agenda-startup nil
  749. "Options concerning initial settings in the Agenda in Org Mode."
  750. :tag "Org Agenda Startup"
  751. :group 'org-agenda)
  752. (defcustom org-agenda-menu-show-matcher t
  753. "Non-nil means show the match string in the agenda dispatcher menu.
  754. When nil, the matcher string is not shown, but is put into the help-echo
  755. property so than moving the mouse over the command shows it.
  756. Setting it to nil is good if matcher strings are very long and/or if
  757. you want to use two-column display (see `org-agenda-menu-two-column')."
  758. :group 'org-agenda
  759. :type 'boolean)
  760. (defcustom org-agenda-menu-two-column nil
  761. "Non-nil means, use two columns to show custom commands in the dispatcher.
  762. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  763. to nil."
  764. :group 'org-agenda
  765. :type 'boolean)
  766. (defcustom org-finalize-agenda-hook nil
  767. "Hook run just before displaying an agenda buffer."
  768. :group 'org-agenda-startup
  769. :type 'hook)
  770. (defcustom org-agenda-mouse-1-follows-link nil
  771. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  772. A longer mouse click will still set point. Does not work on XEmacs.
  773. Needs to be set before org.el is loaded."
  774. :group 'org-agenda-startup
  775. :type 'boolean)
  776. (defcustom org-agenda-start-with-follow-mode nil
  777. "The initial value of follow mode in a newly created agenda window."
  778. :group 'org-agenda-startup
  779. :type 'boolean)
  780. (defcustom org-agenda-follow-indirect nil
  781. "Non-nil means `org-agenda-follow-mode' displays only the
  782. current item's tree, in an indirect buffer."
  783. :group 'org-agenda
  784. :type 'boolean)
  785. (defcustom org-agenda-show-outline-path t
  786. "Non-nil means show outline path in echo area after line motion."
  787. :group 'org-agenda-startup
  788. :type 'boolean)
  789. (defcustom org-agenda-start-with-entry-text-mode nil
  790. "The initial value of entry-text-mode in a newly created agenda window."
  791. :group 'org-agenda-startup
  792. :type 'boolean)
  793. (defcustom org-agenda-entry-text-maxlines 5
  794. "Number of text lines to be added when `E' is pressed in the agenda.
  795. Note that this variable only used during agenda display. Add add entry text
  796. when exporting the agenda, configure the variable
  797. `org-agenda-add-entry-ext-maxlines'."
  798. :group 'org-agenda
  799. :type 'integer)
  800. (defcustom org-agenda-entry-text-exclude-regexps nil
  801. "List of regular expressions to clean up entry text.
  802. The complete matches of all regular expressions in this list will be
  803. removed from entry text before it is shown in the agenda."
  804. :group 'org-agenda
  805. :type '(repeat (regexp)))
  806. (defvar org-agenda-entry-text-cleanup-hook nil
  807. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  808. This cleanup is done in a temporary buffer, so the function may inspect and
  809. change the entire buffer.
  810. Some default stuff like drawers and scheduling/deadline dates will already
  811. have been removed when this is called, as will any matches for regular
  812. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  813. (defvar org-agenda-include-inactive-timestamps nil
  814. "Non-nil means include inactive time stamps in agenda and timeline.")
  815. (defgroup org-agenda-windows nil
  816. "Options concerning the windows used by the Agenda in Org Mode."
  817. :tag "Org Agenda Windows"
  818. :group 'org-agenda)
  819. (defcustom org-agenda-window-setup 'reorganize-frame
  820. "How the agenda buffer should be displayed.
  821. Possible values for this option are:
  822. current-window Show agenda in the current window, keeping all other windows.
  823. other-window Use `switch-to-buffer-other-window' to display agenda.
  824. reorganize-frame Show only two windows on the current frame, the current
  825. window and the agenda.
  826. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  827. Also, when exiting the agenda, kill that frame.
  828. See also the variable `org-agenda-restore-windows-after-quit'."
  829. :group 'org-agenda-windows
  830. :type '(choice
  831. (const current-window)
  832. (const other-frame)
  833. (const other-window)
  834. (const reorganize-frame)))
  835. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  836. "The min and max height of the agenda window as a fraction of frame height.
  837. The value of the variable is a cons cell with two numbers between 0 and 1.
  838. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  839. :group 'org-agenda-windows
  840. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  841. (defcustom org-agenda-restore-windows-after-quit nil
  842. "Non-nil means restore window configuration upon exiting agenda.
  843. Before the window configuration is changed for displaying the agenda,
  844. the current status is recorded. When the agenda is exited with
  845. `q' or `x' and this option is set, the old state is restored. If
  846. `org-agenda-window-setup' is `other-frame', the value of this
  847. option will be ignored."
  848. :group 'org-agenda-windows
  849. :type 'boolean)
  850. (defcustom org-agenda-ndays nil
  851. "Number of days to include in overview display.
  852. Should be 1 or 7.
  853. Obsolete, see `org-agenda-span'."
  854. :group 'org-agenda-daily/weekly
  855. :type 'integer)
  856. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  857. (defcustom org-agenda-span 'week
  858. "Number of days to include in overview display.
  859. Can be day, week, month, year, or any number of days.
  860. Custom commands can set this variable in the options section."
  861. :group 'org-agenda-daily/weekly
  862. :type '(choice (const :tag "Day" day)
  863. (const :tag "Week" week)
  864. (const :tag "Month" month)
  865. (const :tag "Year" year)
  866. (integer :tag "Custom")))
  867. (defcustom org-agenda-start-on-weekday 1
  868. "Non-nil means start the overview always on the specified weekday.
  869. 0 denotes Sunday, 1 denotes Monday etc.
  870. When nil, always start on the current day.
  871. Custom commands can set this variable in the options section."
  872. :group 'org-agenda-daily/weekly
  873. :type '(choice (const :tag "Today" nil)
  874. (integer :tag "Weekday No.")))
  875. (defcustom org-agenda-show-all-dates t
  876. "Non-nil means `org-agenda' shows every day in the selected range.
  877. When nil, only the days which actually have entries are shown."
  878. :group 'org-agenda-daily/weekly
  879. :type 'boolean)
  880. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  881. "Format string for displaying dates in the agenda.
  882. Used by the daily/weekly agenda and by the timeline. This should be
  883. a format string understood by `format-time-string', or a function returning
  884. the formatted date as a string. The function must take a single argument,
  885. a calendar-style date list like (month day year)."
  886. :group 'org-agenda-daily/weekly
  887. :type '(choice
  888. (string :tag "Format string")
  889. (function :tag "Function")))
  890. (defun org-agenda-format-date-aligned (date)
  891. "Format a date string for display in the daily/weekly agenda, or timeline.
  892. This function makes sure that dates are aligned for easy reading."
  893. (require 'cal-iso)
  894. (let* ((dayname (calendar-day-name date))
  895. (day (cadr date))
  896. (day-of-week (calendar-day-of-week date))
  897. (month (car date))
  898. (monthname (calendar-month-name month))
  899. (year (nth 2 date))
  900. (iso-week (org-days-to-iso-week
  901. (calendar-absolute-from-gregorian date)))
  902. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  903. (1- year))
  904. ((and (= month 12) (<= iso-week 1))
  905. (1+ year))
  906. (t year)))
  907. (weekstring (if (= day-of-week 1)
  908. (format " W%02d" iso-week)
  909. "")))
  910. (format "%-10s %2d %s %4d%s"
  911. dayname day monthname year weekstring)))
  912. (defcustom org-agenda-time-leading-zero nil
  913. "Non-nil means use leading zero for military times in agenda.
  914. For example, 9:30am would become 09:30 rather than 9:30."
  915. :group 'org-agenda-daily/weekly
  916. :type 'boolean)
  917. (defcustom org-agenda-timegrid-use-ampm nil
  918. "When set, show AM/PM style timestamps on the timegrid."
  919. :group 'org-agenda
  920. :type 'boolean)
  921. (defun org-agenda-time-of-day-to-ampm (time)
  922. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  923. (let* ((hour-number (string-to-number (substring time 0 -3)))
  924. (minute (substring time -2))
  925. (ampm "am"))
  926. (cond
  927. ((equal hour-number 12)
  928. (setq ampm "pm"))
  929. ((> hour-number 12)
  930. (setq ampm "pm")
  931. (setq hour-number (- hour-number 12))))
  932. (concat
  933. (if org-agenda-time-leading-zero
  934. (format "%02d" hour-number)
  935. (format "%02s" (number-to-string hour-number)))
  936. ":" minute ampm)))
  937. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  938. "Conditionally convert TIME to AM/PM format
  939. based on `org-agenda-timegrid-use-ampm'"
  940. (if org-agenda-timegrid-use-ampm
  941. (org-agenda-time-of-day-to-ampm time)
  942. time))
  943. (defcustom org-agenda-weekend-days '(6 0)
  944. "Which days are weekend?
  945. These days get the special face `org-agenda-date-weekend' in the agenda
  946. and timeline buffers."
  947. :group 'org-agenda-daily/weekly
  948. :type '(set :greedy t
  949. (const :tag "Monday" 1)
  950. (const :tag "Tuesday" 2)
  951. (const :tag "Wednesday" 3)
  952. (const :tag "Thursday" 4)
  953. (const :tag "Friday" 5)
  954. (const :tag "Saturday" 6)
  955. (const :tag "Sunday" 0)))
  956. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  957. "Non-nil means jumpt to today when moving a past date forward in time.
  958. When using S-right in the agenda to move a a date forward, and the date
  959. stamp currently points to the past, the first key press will move it
  960. to today. WHen nil, just move one day forward even if the date stays
  961. in the past."
  962. :group 'org-agenda-daily/weekly
  963. :type 'boolean)
  964. (defcustom org-agenda-include-diary nil
  965. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  966. Custom commands can set this variable in the options section."
  967. :group 'org-agenda-daily/weekly
  968. :type 'boolean)
  969. (defcustom org-agenda-include-deadlines t
  970. "If non-nil, include entries within their deadline warning period.
  971. Custom commands can set this variable in the options section."
  972. :group 'org-agenda-daily/weekly
  973. :type 'boolean)
  974. (defcustom org-agenda-repeating-timestamp-show-all t
  975. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  976. When set to a list of strings, only show occurrences of repeating
  977. stamps for these TODO keywords. When nil, only one occurrence is
  978. shown, either today or the nearest into the future."
  979. :group 'org-agenda-daily/weekly
  980. :type '(choice
  981. (const :tag "Show repeating stamps" t)
  982. (repeat :tag "Show repeating stamps for these TODO keywords"
  983. (string :tag "TODO Keyword"))
  984. (const :tag "Don't show repeating stamps" nil)))
  985. (defcustom org-scheduled-past-days 10000
  986. "No. of days to continue listing scheduled items that are not marked DONE.
  987. When an item is scheduled on a date, it shows up in the agenda on this
  988. day and will be listed until it is marked done for the number of days
  989. given here."
  990. :group 'org-agenda-daily/weekly
  991. :type 'integer)
  992. (defcustom org-agenda-log-mode-items '(closed clock)
  993. "List of items that should be shown in agenda log mode.
  994. This list may contain the following symbols:
  995. closed Show entries that have been closed on that day.
  996. clock Show entries that have received clocked time on that day.
  997. state Show all logged state changes.
  998. Note that instead of changing this variable, you can also press `C-u l' in
  999. the agenda to display all available LOG items temporarily."
  1000. :group 'org-agenda-daily/weekly
  1001. :type '(set :greedy t (const closed) (const clock) (const state)))
  1002. (defcustom org-agenda-clock-consistency-checks
  1003. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1004. :gap-ok-around ("4:00")
  1005. :default-face ((:background "DarkRed") (:foreground "white"))
  1006. :overlap-face nil :gap-face nil :no-end-time-face nil
  1007. :long-face nil :short-face nil)
  1008. "This is a property list, with the following keys:
  1009. :max-duration Mark clocking chunks that are longer than this time.
  1010. This is a time string like \"HH:MM\", or the number
  1011. of minutes as an integer.
  1012. :min-duration Mark clocking chunks that are shorter that this.
  1013. This is a time string like \"HH:MM\", or the number
  1014. of minutes as an integer.
  1015. :max-gap Mark gaps between clocking chunks that are longer than
  1016. this duration. A number of minutes, or a string
  1017. like \"HH:MM\".
  1018. :gap-ok-around List of times during the day which are usually not working
  1019. times. When a gap is detected, but the gap contains any
  1020. of these times, the gap is *not* reported. For example,
  1021. if this is (\"4:00\" \"13:00\") then gaps that contain
  1022. 4:00 in the morning (i.e. the night) and 13:00
  1023. (i.e. a typical lunch time) do not cause a warning.
  1024. You should have at least one time during the night in this
  1025. list, or otherwise the first task each morning will trigger
  1026. a warning because it follows a long gap.
  1027. Furthermore, the following properties can be used to define faces for
  1028. issue display.
  1029. :default-face the default face, if the specific face is undefined
  1030. :overlap-face face for overlapping clocks
  1031. :gap-face face for gaps between clocks
  1032. :no-end-time-face face for incomplete clocks
  1033. :long-face face for clock intervals that are too long
  1034. :short-face face for clock intervals that are too short"
  1035. :group 'org-agenda-daily/weekly
  1036. :group 'org-clock
  1037. :type 'plist)
  1038. (defcustom org-agenda-log-mode-add-notes t
  1039. "Non-nil means add first line of notes to log entries in agenda views.
  1040. If a log item like a state change or a clock entry is associated with
  1041. notes, the first line of these notes will be added to the entry in the
  1042. agenda display."
  1043. :group 'org-agenda-daily/weekly
  1044. :type 'boolean)
  1045. (defcustom org-agenda-start-with-log-mode nil
  1046. "The initial value of log-mode in a newly created agenda window."
  1047. :group 'org-agenda-startup
  1048. :group 'org-agenda-daily/weekly
  1049. :type 'boolean)
  1050. (defcustom org-agenda-start-with-clockreport-mode nil
  1051. "The initial value of clockreport-mode in a newly created agenda window."
  1052. :group 'org-agenda-startup
  1053. :group 'org-agenda-daily/weekly
  1054. :type 'boolean)
  1055. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1056. "Property list with parameters for the clocktable in clockreport mode.
  1057. This is the display mode that shows a clock table in the daily/weekly
  1058. agenda, the properties for this dynamic block can be set here.
  1059. The usual clocktable parameters are allowed here, but you cannot set
  1060. the properties :name, :tstart, :tend, :block, and :scope - these will
  1061. be overwritten to make sure the content accurately reflects the
  1062. current display in the agenda."
  1063. :group 'org-agenda-daily/weekly
  1064. :type 'plist)
  1065. (defcustom org-agenda-search-view-always-boolean nil
  1066. "Non-nil means the search string is interpreted as individual parts.
  1067. The search string for search view can either be interpreted as a phrase,
  1068. or as a list of snippets that define a boolean search for a number of
  1069. strings.
  1070. When this is non-nil, the string will be split on whitespace, and each
  1071. snippet will be searched individually, and all must match in order to
  1072. select an entry. A snippet is then a single string of non-white
  1073. characters, or a string in double quotes, or a regexp in {} braces.
  1074. If a snippet is preceded by \"-\", the snippet must *not* match.
  1075. \"+\" is syntactic sugar for positive selection. Each snippet may
  1076. be found as a full word or a partial word, but see the variable
  1077. `org-agenda-search-view-force-full-words'.
  1078. When this is nil, search will look for the entire search phrase as one,
  1079. with each space character matching any amount of whitespace, including
  1080. line breaks.
  1081. Even when this is nil, you can still switch to Boolean search dynamically
  1082. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1083. is a regexp marked with braces like \"{abc}\", this will also switch to
  1084. boolean search."
  1085. :group 'org-agenda-search-view
  1086. :type 'boolean)
  1087. (if (fboundp 'defvaralias)
  1088. (defvaralias 'org-agenda-search-view-search-words-only
  1089. 'org-agenda-search-view-always-boolean))
  1090. (defcustom org-agenda-search-view-force-full-words nil
  1091. "Non-nil means, search words must be matches as complete words.
  1092. When nil, they may also match part of a word."
  1093. :group 'org-agenda-search-view
  1094. :type 'boolean)
  1095. (defgroup org-agenda-time-grid nil
  1096. "Options concerning the time grid in the Org-mode Agenda."
  1097. :tag "Org Agenda Time Grid"
  1098. :group 'org-agenda)
  1099. (defcustom org-agenda-search-headline-for-time t
  1100. "Non-nil means search headline for a time-of-day.
  1101. If the headline contains a time-of-day in one format or another, it will
  1102. be used to sort the entry into the time sequence of items for a day.
  1103. Some people have time stamps in the headline that refer to the creation
  1104. time or so, and then this produces an unwanted side effect. If this is
  1105. the case for your, use this variable to turn off searching the headline
  1106. for a time."
  1107. :group 'org-agenda-time-grid
  1108. :type 'boolean)
  1109. (defcustom org-agenda-use-time-grid t
  1110. "Non-nil means show a time grid in the agenda schedule.
  1111. A time grid is a set of lines for specific times (like every two hours between
  1112. 8:00 and 20:00). The items scheduled for a day at specific times are
  1113. sorted in between these lines.
  1114. For details about when the grid will be shown, and what it will look like, see
  1115. the variable `org-agenda-time-grid'."
  1116. :group 'org-agenda-time-grid
  1117. :type 'boolean)
  1118. (defcustom org-agenda-time-grid
  1119. '((daily today require-timed)
  1120. "----------------"
  1121. (800 1000 1200 1400 1600 1800 2000))
  1122. "The settings for time grid for agenda display.
  1123. This is a list of three items. The first item is again a list. It contains
  1124. symbols specifying conditions when the grid should be displayed:
  1125. daily if the agenda shows a single day
  1126. weekly if the agenda shows an entire week
  1127. today show grid on current date, independent of daily/weekly display
  1128. require-timed show grid only if at least one item has a time specification
  1129. The second item is a string which will be placed behind the grid time.
  1130. The third item is a list of integers, indicating the times that should have
  1131. a grid line."
  1132. :group 'org-agenda-time-grid
  1133. :type
  1134. '(list
  1135. (set :greedy t :tag "Grid Display Options"
  1136. (const :tag "Show grid in single day agenda display" daily)
  1137. (const :tag "Show grid in weekly agenda display" weekly)
  1138. (const :tag "Always show grid for today" today)
  1139. (const :tag "Show grid only if any timed entries are present"
  1140. require-timed)
  1141. (const :tag "Skip grid times already present in an entry"
  1142. remove-match))
  1143. (string :tag "Grid String")
  1144. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1145. (defcustom org-agenda-show-current-time-in-grid t
  1146. "Non-nil means show the current time in the time grid."
  1147. :group 'org-agenda-time-grid
  1148. :type 'boolean)
  1149. (defcustom org-agenda-current-time-string
  1150. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1151. "The string for the current time marker in the agenda."
  1152. :group 'org-agenda-time-grid
  1153. :type 'string)
  1154. (defgroup org-agenda-sorting nil
  1155. "Options concerning sorting in the Org-mode Agenda."
  1156. :tag "Org Agenda Sorting"
  1157. :group 'org-agenda)
  1158. (defcustom org-agenda-sorting-strategy
  1159. '((agenda habit-down time-up priority-down category-keep)
  1160. (todo priority-down category-keep)
  1161. (tags priority-down category-keep)
  1162. (search category-keep))
  1163. "Sorting structure for the agenda items of a single day.
  1164. This is a list of symbols which will be used in sequence to determine
  1165. if an entry should be listed before another entry. The following
  1166. symbols are recognized:
  1167. time-up Put entries with time-of-day indications first, early first
  1168. time-down Put entries with time-of-day indications first, late first
  1169. category-keep Keep the default order of categories, corresponding to the
  1170. sequence in `org-agenda-files'.
  1171. category-up Sort alphabetically by category, A-Z.
  1172. category-down Sort alphabetically by category, Z-A.
  1173. tag-up Sort alphabetically by last tag, A-Z.
  1174. tag-down Sort alphabetically by last tag, Z-A.
  1175. priority-up Sort numerically by priority, high priority last.
  1176. priority-down Sort numerically by priority, high priority first.
  1177. todo-state-up Sort by todo state, tasks that are done last.
  1178. todo-state-down Sort by todo state, tasks that are done first.
  1179. effort-up Sort numerically by estimated effort, high effort last.
  1180. effort-down Sort numerically by estimated effort, high effort first.
  1181. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1182. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1183. habit-up Put entries that are habits first
  1184. habit-down Put entries that are habits last
  1185. alpha-up Sort headlines alphabetically
  1186. alpha-down Sort headlines alphabetically, reversed
  1187. The different possibilities will be tried in sequence, and testing stops
  1188. if one comparison returns a \"not-equal\". For example, the default
  1189. '(time-up category-keep priority-down)
  1190. means: Pull out all entries having a specified time of day and sort them,
  1191. in order to make a time schedule for the current day the first thing in the
  1192. agenda listing for the day. Of the entries without a time indication, keep
  1193. the grouped in categories, don't sort the categories, but keep them in
  1194. the sequence given in `org-agenda-files'. Within each category sort by
  1195. priority.
  1196. Leaving out `category-keep' would mean that items will be sorted across
  1197. categories by priority.
  1198. Instead of a single list, this can also be a set of list for specific
  1199. contents, with a context symbol in the car of the list, any of
  1200. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1201. Custom commands can bind this variable in the options section."
  1202. :group 'org-agenda-sorting
  1203. :type `(choice
  1204. (repeat :tag "General" ,org-sorting-choice)
  1205. (list :tag "Individually"
  1206. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1207. (repeat ,org-sorting-choice))
  1208. (cons (const :tag "Strategy for TODO lists" todo)
  1209. (repeat ,org-sorting-choice))
  1210. (cons (const :tag "Strategy for Tags matches" tags)
  1211. (repeat ,org-sorting-choice))
  1212. (cons (const :tag "Strategy for search matches" search)
  1213. (repeat ,org-sorting-choice)))))
  1214. (defcustom org-agenda-cmp-user-defined nil
  1215. "A function to define the comparison `user-defined'.
  1216. This function must receive two arguments, agenda entry a and b.
  1217. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1218. the user comparison, return nil.
  1219. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1220. part of an agenda sorting strategy."
  1221. :group 'org-agenda-sorting
  1222. :type 'symbol)
  1223. (defcustom org-sort-agenda-notime-is-late t
  1224. "Non-nil means items without time are considered late.
  1225. This is only relevant for sorting. When t, items which have no explicit
  1226. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1227. do have a time. When nil, the default time is before 0:00. You can use this
  1228. option to decide if the schedule for today should come before or after timeless
  1229. agenda entries."
  1230. :group 'org-agenda-sorting
  1231. :type 'boolean)
  1232. (defcustom org-sort-agenda-noeffort-is-high t
  1233. "Non-nil means items without effort estimate are sorted as high effort.
  1234. This also applies when filtering an agenda view with respect to the
  1235. < or > effort operator. Then, tasks with no effort defined will be treated
  1236. as tasks with high effort.
  1237. When nil, such items are sorted as 0 minutes effort."
  1238. :group 'org-agenda-sorting
  1239. :type 'boolean)
  1240. (defgroup org-agenda-line-format nil
  1241. "Options concerning the entry prefix in the Org-mode agenda display."
  1242. :tag "Org Agenda Line Format"
  1243. :group 'org-agenda)
  1244. (defcustom org-agenda-prefix-format
  1245. '((agenda . " %i %-12:c%?-12t% s")
  1246. (timeline . " % s")
  1247. (todo . " %i %-12:c")
  1248. (tags . " %i %-12:c")
  1249. (search . " %i %-12:c"))
  1250. "Format specifications for the prefix of items in the agenda views.
  1251. An alist with five entries, each for the different agenda types. The
  1252. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1253. The values are format strings.
  1254. This format works similar to a printf format, with the following meaning:
  1255. %c the category of the item, \"Diary\" for entries from the diary,
  1256. or as given by the CATEGORY keyword or derived from the file name
  1257. %e the effort required by the item
  1258. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1259. %T the last tag of the item (ignore inherited tags, which come first)
  1260. %t the HH:MM time-of-day specification if one applies to the entry
  1261. %s Scheduling/Deadline information, a short string
  1262. %(expression) Eval EXPRESSION and replace the control string
  1263. by the result
  1264. All specifiers work basically like the standard `%s' of printf, but may
  1265. contain two additional characters: a question mark just after the `%'
  1266. and a whitespace/punctuation character just before the final letter.
  1267. If the first character after `%' is a question mark, the entire field
  1268. will only be included if the corresponding value applies to the current
  1269. entry. This is useful for fields which should have fixed width when
  1270. present, but zero width when absent. For example, \"%?-12t\" will
  1271. result in a 12 character time field if a time of the day is specified,
  1272. but will completely disappear in entries which do not contain a time.
  1273. If there is punctuation or whitespace character just before the final
  1274. format letter, this character will be appended to the field value if
  1275. the value is not empty. For example, the format \"%-12:c\" leads to
  1276. \"Diary: \" if the category is \"Diary\". If the category were be
  1277. empty, no additional colon would be inserted.
  1278. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1279. which means:
  1280. - Indent the line with two space characters
  1281. - Give the category a 12 chars wide field, padded with whitespace on
  1282. the right (because of `-'). Append a colon if there is a category
  1283. (because of `:').
  1284. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1285. time, don't put in an empty field, just skip it (because of '?').
  1286. - Finally, put the scheduling information.
  1287. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1288. `org-agenda-remove-tags'.
  1289. Custom commands can set this variable in the options section."
  1290. :type '(choice
  1291. (string :tag "General format")
  1292. (list :greedy t :tag "View dependent"
  1293. (cons (const agenda) (string :tag "Format"))
  1294. (cons (const timeline) (string :tag "Format"))
  1295. (cons (const todo) (string :tag "Format"))
  1296. (cons (const tags) (string :tag "Format"))
  1297. (cons (const search) (string :tag "Format"))))
  1298. :group 'org-agenda-line-format)
  1299. (defvar org-prefix-format-compiled nil
  1300. "The compiled version of the most recently used prefix format.
  1301. See the variable `org-agenda-prefix-format'.")
  1302. (defcustom org-agenda-todo-keyword-format "%-1s"
  1303. "Format for the TODO keyword in agenda lines.
  1304. Set this to something like \"%-12s\" if you want all TODO keywords
  1305. to occupy a fixed space in the agenda display."
  1306. :group 'org-agenda-line-format
  1307. :type 'string)
  1308. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1309. "Text preceding timerange entries in the agenda view.
  1310. This is a list with two strings. The first applies when the range
  1311. is entirely on one day. The second applies if the range spans several days.
  1312. The strings may have two \"%d\" format specifiers which will be filled
  1313. with the sequence number of the days, and the total number of days in the
  1314. range, respectively."
  1315. :group 'org-agenda-line-format
  1316. :type '(list
  1317. (string :tag "Deadline today ")
  1318. (choice :tag "Deadline relative"
  1319. (string :tag "Format string")
  1320. (function))))
  1321. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1322. "Text preceding scheduled items in the agenda view.
  1323. This is a list with two strings. The first applies when the item is
  1324. scheduled on the current day. The second applies when it has been scheduled
  1325. previously, it may contain a %d indicating that this is the nth time that
  1326. this item is scheduled, due to automatic rescheduling of unfinished items
  1327. for the following day. So this number is one larger than the number of days
  1328. that passed since this item was scheduled first."
  1329. :group 'org-agenda-line-format
  1330. :type '(list
  1331. (string :tag "Scheduled today ")
  1332. (string :tag "Scheduled previously")))
  1333. (defcustom org-agenda-inactive-leader "["
  1334. "Text preceding item pulled into the agenda by inactive time stamps.
  1335. These entries are added to the agenda when pressing \"[\"."
  1336. :group 'org-agenda-line-format
  1337. :type '(list
  1338. (string :tag "Scheduled today ")
  1339. (string :tag "Scheduled previously")))
  1340. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1341. "Text preceding deadline items in the agenda view.
  1342. This is a list with two strings. The first applies when the item has its
  1343. deadline on the current day. The second applies when it is in the past or
  1344. in the future, it may contain %d to capture how many days away the deadline
  1345. is (was)."
  1346. :group 'org-agenda-line-format
  1347. :type '(list
  1348. (string :tag "Deadline today ")
  1349. (choice :tag "Deadline relative"
  1350. (string :tag "Format string")
  1351. (function))))
  1352. (defcustom org-agenda-remove-times-when-in-prefix t
  1353. "Non-nil means remove duplicate time specifications in agenda items.
  1354. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1355. time-of-day specification in a headline or diary entry is extracted and
  1356. placed into the prefix. If this option is non-nil, the original specification
  1357. \(a timestamp or -range, or just a plain time(range) specification like
  1358. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1359. cluttered.
  1360. The option can be t or nil. It may also be the symbol `beg', indicating
  1361. that the time should only be removed when it is located at the beginning of
  1362. the headline/diary entry."
  1363. :group 'org-agenda-line-format
  1364. :type '(choice
  1365. (const :tag "Always" t)
  1366. (const :tag "Never" nil)
  1367. (const :tag "When at beginning of entry" beg)))
  1368. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1369. "Non-nil means remove time ranges specifications in agenda
  1370. items that span on several days."
  1371. :group 'org-agenda-line-format
  1372. :type 'boolean)
  1373. (defcustom org-agenda-default-appointment-duration nil
  1374. "Default duration for appointments that only have a starting time.
  1375. When nil, no duration is specified in such cases.
  1376. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1377. :group 'org-agenda-line-format
  1378. :type '(choice
  1379. (integer :tag "Minutes")
  1380. (const :tag "No default duration")))
  1381. (defcustom org-agenda-show-inherited-tags t
  1382. "Non-nil means show inherited tags in each agenda line."
  1383. :group 'org-agenda-line-format
  1384. :type 'boolean)
  1385. (defcustom org-agenda-hide-tags-regexp nil
  1386. "Regular expression used to filter away specific tags in agenda views.
  1387. This means that these tags will be present, but not be shown in the agenda
  1388. line. Secondary filtering will still work on the hidden tags.
  1389. Nil means don't hide any tags."
  1390. :group 'org-agenda-line-format
  1391. :type '(choice
  1392. (const :tag "Hide none" nil)
  1393. (string :tag "Regexp ")))
  1394. (defcustom org-agenda-remove-tags nil
  1395. "Non-nil means remove the tags from the headline copy in the agenda.
  1396. When this is the symbol `prefix', only remove tags when
  1397. `org-agenda-prefix-format' contains a `%T' specifier."
  1398. :group 'org-agenda-line-format
  1399. :type '(choice
  1400. (const :tag "Always" t)
  1401. (const :tag "Never" nil)
  1402. (const :tag "When prefix format contains %T" prefix)))
  1403. (if (fboundp 'defvaralias)
  1404. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1405. 'org-agenda-remove-tags))
  1406. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1407. "Shift tags in agenda items to this column.
  1408. If this number is positive, it specifies the column. If it is negative,
  1409. it means that the tags should be flushright to that column. For example,
  1410. -80 works well for a normal 80 character screen."
  1411. :group 'org-agenda-line-format
  1412. :type 'integer)
  1413. (if (fboundp 'defvaralias)
  1414. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1415. (defcustom org-agenda-fontify-priorities 'cookies
  1416. "Non-nil means highlight low and high priorities in agenda.
  1417. When t, the highest priority entries are bold, lowest priority italic.
  1418. However, settings in `org-priority-faces' will overrule these faces.
  1419. When this variable is the symbol `cookies', only fontify the
  1420. cookies, not the entire task.
  1421. This may also be an association list of priority faces, whose
  1422. keys are the character values of `org-highest-priority',
  1423. `org-default-priority', and `org-lowest-priority' (the default values
  1424. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1425. color as a string, or a list like `(:background \"Red\")'.
  1426. If it is a color, the variable `org-faces-easy-properties'
  1427. determines if it is a foreground or a background color."
  1428. :group 'org-agenda-line-format
  1429. :type '(choice
  1430. (const :tag "Never" nil)
  1431. (const :tag "Defaults" t)
  1432. (const :tag "Cookies only" cookies)
  1433. (repeat :tag "Specify"
  1434. (list (character :tag "Priority" :value ?A)
  1435. (choice :tag "Face "
  1436. (string :tag "Color")
  1437. (sexp :tag "Face"))))))
  1438. (defcustom org-agenda-day-face-function nil
  1439. "Function called to determine what face should be used to display a day.
  1440. The only argument passed to that function is the day. It should
  1441. returns a face, or nil if does not want to specify a face and let
  1442. the normal rules apply."
  1443. :group 'org-agenda-line-format
  1444. :type 'function)
  1445. (defcustom org-agenda-category-icon-alist nil
  1446. "Alist of category icon to be displayed in agenda views.
  1447. Each entry should have the following format:
  1448. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1449. Where CATEGORY-REGEXP is a regexp matching the categories where
  1450. the icon should be displayed.
  1451. FILE-OR-DATA either a file path or a string containing image data.
  1452. The other fields can be omited safely if not needed:
  1453. TYPE indicates the image type.
  1454. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1455. image data.
  1456. PROPS are additional image attributes to assign to the image,
  1457. like, e.g. `:ascent center'.
  1458. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1459. If you want to set the display properties yourself, just put a
  1460. list as second element:
  1461. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1462. For example, to display a 16px horizontal space for Emacs
  1463. category, you can use:
  1464. (\"Emacs\" '(space . (:width (16))))"
  1465. :group 'org-agenda-line-format
  1466. :type '(alist :key-type (string :tag "Regexp matching category")
  1467. :value-type (choice (list :tag "Icon"
  1468. (string :tag "File or data")
  1469. (symbol :tag "Type")
  1470. (boolean :tag "Data?")
  1471. (repeat :tag "Extra image properties" :inline t symbol))
  1472. (list :tag "Display properties" sexp))))
  1473. (defgroup org-agenda-column-view nil
  1474. "Options concerning column view in the agenda."
  1475. :tag "Org Agenda Column View"
  1476. :group 'org-agenda)
  1477. (defcustom org-agenda-columns-show-summaries t
  1478. "Non-nil means show summaries for columns displayed in the agenda view."
  1479. :group 'org-agenda-column-view
  1480. :type 'boolean)
  1481. (defcustom org-agenda-columns-compute-summary-properties t
  1482. "Non-nil means recompute all summary properties before column view.
  1483. When column view in the agenda is listing properties that have a summary
  1484. operator, it can go to all relevant buffers and recompute the summaries
  1485. there. This can mean overhead for the agenda column view, but is necessary
  1486. to have thing up to date.
  1487. As a special case, a CLOCKSUM property also makes sure that the clock
  1488. computations are current."
  1489. :group 'org-agenda-column-view
  1490. :type 'boolean)
  1491. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1492. "Non-nil means the duration of an appointment will add to day effort.
  1493. The property to which appointment durations will be added is the one given
  1494. in the option `org-effort-property'. If an appointment does not have
  1495. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1496. is not set, an appointment without end time will not contribute to the time
  1497. estimate."
  1498. :group 'org-agenda-column-view
  1499. :type 'boolean)
  1500. (defcustom org-agenda-auto-exclude-function nil
  1501. "A function called with a tag to decide if it is filtered on '/ RET'.
  1502. The sole argument to the function, which is called once for each
  1503. possible tag, is a string giving the name of the tag. The
  1504. function should return either nil if the tag should be included
  1505. as normal, or \"-<TAG>\" to exclude the tag.
  1506. Note that for the purpose of tag filtering, only the lower-case version of
  1507. all tags will be considered, so that this function will only ever see
  1508. the lower-case version of all tags."
  1509. :group 'org-agenda
  1510. :type 'function)
  1511. (defcustom org-agenda-bulk-custom-functions nil
  1512. "Alist of characters and custom functions for bulk actions.
  1513. For example, this value makes those two functions available:
  1514. '((?R set-category)
  1515. (?C bulk-cut))
  1516. With selected entries in an agenda buffer, `B R' will call
  1517. the custom function `set-category' on the selected entries.
  1518. Note that functions in this alist don't need to be quoted."
  1519. :type 'alist
  1520. :group 'org-agenda)
  1521. (eval-when-compile
  1522. (require 'cl))
  1523. (require 'org)
  1524. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1525. "Execute BODY with point at location given by `org-hd-marker' property.
  1526. If STRING is non-nil, the text property will be fetched from position 0
  1527. in that string. If STRING is nil, it will be fetched from the beginning
  1528. of the current line."
  1529. (org-with-gensyms (marker)
  1530. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1531. 'org-hd-marker string)))
  1532. (with-current-buffer (marker-buffer ,marker)
  1533. (save-excursion
  1534. (goto-char ,marker)
  1535. ,@body)))))
  1536. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1537. (defun org-add-agenda-custom-command (entry)
  1538. "Replace or add a command in `org-agenda-custom-commands'.
  1539. This is mostly for hacking and trying a new command - once the command
  1540. works you probably want to add it to `org-agenda-custom-commands' for good."
  1541. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1542. (if ass
  1543. (setcdr ass (cdr entry))
  1544. (push entry org-agenda-custom-commands))))
  1545. ;;; Define the Org-agenda-mode
  1546. (defvar org-agenda-mode-map (make-sparse-keymap)
  1547. "Keymap for `org-agenda-mode'.")
  1548. (if (fboundp 'defvaralias)
  1549. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1550. (defvar org-agenda-menu) ; defined later in this file.
  1551. (defvar org-agenda-restrict) ; defined later in this file.
  1552. (defvar org-agenda-follow-mode nil)
  1553. (defvar org-agenda-entry-text-mode nil)
  1554. (defvar org-agenda-clockreport-mode nil)
  1555. (defvar org-agenda-show-log nil)
  1556. (defvar org-agenda-redo-command nil)
  1557. (defvar org-agenda-query-string nil)
  1558. (defvar org-agenda-mode-hook nil
  1559. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1560. (defvar org-agenda-type nil)
  1561. (defvar org-agenda-force-single-file nil)
  1562. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1563. (defun org-agenda-mode ()
  1564. "Mode for time-sorted view on action items in Org-mode files.
  1565. The following commands are available:
  1566. \\{org-agenda-mode-map}"
  1567. (interactive)
  1568. (kill-all-local-variables)
  1569. (setq org-agenda-undo-list nil
  1570. org-agenda-pending-undo-list nil
  1571. org-agenda-bulk-marked-entries nil)
  1572. (setq major-mode 'org-agenda-mode)
  1573. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1574. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1575. (setq mode-name "Org-Agenda")
  1576. (use-local-map org-agenda-mode-map)
  1577. (easy-menu-add org-agenda-menu)
  1578. (if org-startup-truncated (setq truncate-lines t))
  1579. (org-set-local 'line-move-visual nil)
  1580. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1581. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1582. ;; Make sure properties are removed when copying text
  1583. (when (boundp 'buffer-substring-filters)
  1584. (org-set-local 'buffer-substring-filters
  1585. (cons (lambda (x)
  1586. (set-text-properties 0 (length x) nil x) x)
  1587. buffer-substring-filters)))
  1588. (unless org-agenda-keep-modes
  1589. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1590. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1591. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1592. org-agenda-show-log org-agenda-start-with-log-mode))
  1593. (easy-menu-change
  1594. '("Agenda") "Agenda Files"
  1595. (append
  1596. (list
  1597. (vector
  1598. (if (get 'org-agenda-files 'org-restrict)
  1599. "Restricted to single file"
  1600. "Edit File List")
  1601. '(org-edit-agenda-file-list)
  1602. (not (get 'org-agenda-files 'org-restrict)))
  1603. "--")
  1604. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1605. (org-agenda-set-mode-name)
  1606. (apply
  1607. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1608. (list 'org-agenda-mode-hook)))
  1609. (substitute-key-definition 'undo 'org-agenda-undo
  1610. org-agenda-mode-map global-map)
  1611. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1612. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1613. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1614. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1615. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1616. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1617. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1618. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1619. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1620. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1621. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1622. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1623. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1624. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1625. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1626. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1627. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1628. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1629. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1630. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1631. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1632. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1633. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1634. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1635. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1636. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1637. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1638. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1639. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1640. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1641. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1642. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1643. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1644. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1645. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1646. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1647. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1648. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1649. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1650. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1651. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1652. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1653. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1654. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1655. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1656. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1657. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1658. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1659. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1660. (while l (org-defkey org-agenda-mode-map
  1661. (int-to-string (pop l)) 'digit-argument)))
  1662. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1663. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1664. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1665. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1666. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1667. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1668. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1669. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1670. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1671. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1672. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1673. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1674. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1675. 'org-clock-modify-effort-estimate)
  1676. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1677. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1678. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1679. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1680. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1681. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1682. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1683. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1684. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1685. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1686. (substitute-key-definition 'next-line 'org-agenda-next-line
  1687. org-agenda-mode-map global-map)
  1688. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1689. org-agenda-mode-map global-map)
  1690. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1691. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1692. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1693. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1694. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1695. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1696. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1697. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1698. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1699. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1700. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1701. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1702. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1703. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1704. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1705. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1706. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1707. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1708. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1709. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1710. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1711. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1712. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1713. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1714. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1715. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1716. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1717. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1718. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1719. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1720. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1721. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1722. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1723. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1724. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1725. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1726. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1727. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1728. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1729. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1730. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1731. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1732. (when org-agenda-mouse-1-follows-link
  1733. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1734. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1735. '("Agenda"
  1736. ("Agenda Files")
  1737. "--"
  1738. ("Agenda Dates"
  1739. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1740. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1741. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1742. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1743. "--"
  1744. ("View"
  1745. ["Day View" org-agenda-day-view
  1746. :active (org-agenda-check-type nil 'agenda)
  1747. :style radio :selected (eq org-agenda-current-span 'day)
  1748. :keys "v d (or just d)"]
  1749. ["Week View" org-agenda-week-view
  1750. :active (org-agenda-check-type nil 'agenda)
  1751. :style radio :selected (eq org-agenda-current-span 'week)
  1752. :keys "v w (or just w)"]
  1753. ["Month View" org-agenda-month-view
  1754. :active (org-agenda-check-type nil 'agenda)
  1755. :style radio :selected (eq org-agenda-current-span 'month)
  1756. :keys "v m"]
  1757. ["Year View" org-agenda-year-view
  1758. :active (org-agenda-check-type nil 'agenda)
  1759. :style radio :selected (eq org-agenda-current-span 'year)
  1760. :keys "v y"]
  1761. "--"
  1762. ["Include Diary" org-agenda-toggle-diary
  1763. :style toggle :selected org-agenda-include-diary
  1764. :active (org-agenda-check-type nil 'agenda)]
  1765. ["Include Deadlines" org-agenda-toggle-deadlines
  1766. :style toggle :selected org-agenda-include-deadlines
  1767. :active (org-agenda-check-type nil 'agenda)]
  1768. ["Use Time Grid" org-agenda-toggle-time-grid
  1769. :style toggle :selected org-agenda-use-time-grid
  1770. :active (org-agenda-check-type nil 'agenda)]
  1771. "--"
  1772. ["Show clock report" org-agenda-clockreport-mode
  1773. :style toggle :selected org-agenda-clockreport-mode
  1774. :active (org-agenda-check-type nil 'agenda)]
  1775. ["Show some entry text" org-agenda-entry-text-mode
  1776. :style toggle :selected org-agenda-entry-text-mode
  1777. :active t]
  1778. "--"
  1779. ["Show Logbook entries" org-agenda-log-mode
  1780. :style toggle :selected org-agenda-show-log
  1781. :active (org-agenda-check-type nil 'agenda 'timeline)
  1782. :keys "v l (or just l)"]
  1783. ["Include archived trees" org-agenda-archives-mode
  1784. :style toggle :selected org-agenda-archives-mode :active t
  1785. :keys "v a"]
  1786. ["Include archive files" (org-agenda-archives-mode t)
  1787. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1788. :keys "v A"]
  1789. "--"
  1790. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1791. ["Write view to file" org-write-agenda t]
  1792. ["Rebuild buffer" org-agenda-redo t]
  1793. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1794. "--"
  1795. ["Show original entry" org-agenda-show t]
  1796. ["Go To (other window)" org-agenda-goto t]
  1797. ["Go To (this window)" org-agenda-switch-to t]
  1798. ["Follow Mode" org-agenda-follow-mode
  1799. :style toggle :selected org-agenda-follow-mode :active t]
  1800. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1801. "--"
  1802. ("TODO"
  1803. ["Cycle TODO" org-agenda-todo t]
  1804. ["Next TODO set" org-agenda-todo-nextset t]
  1805. ["Previous TODO set" org-agenda-todo-previousset t]
  1806. ["Add note" org-agenda-add-note t])
  1807. ("Archive/Refile/Delete"
  1808. ["Archive default" org-agenda-archive-default t]
  1809. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1810. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1811. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1812. ["Archive subtree" org-agenda-archive t]
  1813. "--"
  1814. ["Refile" org-agenda-refile t]
  1815. "--"
  1816. ["Delete subtree" org-agenda-kill t])
  1817. ("Bulk action"
  1818. ["Mark entry" org-agenda-bulk-mark t]
  1819. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1820. ["Unmark entry" org-agenda-bulk-unmark t]
  1821. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1822. ["Act on all marked" org-agenda-bulk-action t]
  1823. "--"
  1824. ("Tags and Properties"
  1825. ["Show all Tags" org-agenda-show-tags t]
  1826. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1827. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1828. "--"
  1829. ["Column View" org-columns t])
  1830. ("Deadline/Schedule"
  1831. ["Schedule" org-agenda-schedule t]
  1832. ["Set Deadline" org-agenda-deadline t]
  1833. "--"
  1834. ["Mark item" org-agenda-action :active t :keys "k m"]
  1835. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1836. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1837. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1838. "--"
  1839. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1840. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1841. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1842. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1843. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1844. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1845. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1846. ("Clock and Effort"
  1847. ["Clock in" org-agenda-clock-in t]
  1848. ["Clock out" org-agenda-clock-out t]
  1849. ["Clock cancel" org-agenda-clock-cancel t]
  1850. ["Goto running clock" org-clock-goto t]
  1851. "--"
  1852. ["Set Effort" org-agenda-set-effort t]
  1853. ["Change clocked effort" org-clock-modify-effort-estimate
  1854. (org-clock-is-active)])
  1855. ("Priority"
  1856. ["Set Priority" org-agenda-priority t]
  1857. ["Increase Priority" org-agenda-priority-up t]
  1858. ["Decrease Priority" org-agenda-priority-down t]
  1859. ["Show Priority" org-agenda-show-priority t])
  1860. ("Calendar/Diary"
  1861. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1862. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1863. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1864. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1865. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1866. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1867. "--"
  1868. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1869. "--"
  1870. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1871. "--"
  1872. ("MobileOrg"
  1873. ["Push Files and Views" org-mobile-push t]
  1874. ["Get Captured and Flagged" org-mobile-pull t]
  1875. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1876. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1877. "--"
  1878. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1879. "--"
  1880. ["Quit" org-agenda-quit t]
  1881. ["Exit and Release Buffers" org-agenda-exit t]
  1882. ))
  1883. ;;; Agenda undo
  1884. (defvar org-agenda-allow-remote-undo t
  1885. "Non-nil means allow remote undo from the agenda buffer.")
  1886. (defvar org-agenda-undo-list nil
  1887. "List of undoable operations in the agenda since last refresh.")
  1888. (defvar org-agenda-undo-has-started-in nil
  1889. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1890. (defvar org-agenda-pending-undo-list nil
  1891. "In a series of undo commands, this is the list of remaining undo items.")
  1892. (defun org-agenda-undo ()
  1893. "Undo a remote editing step in the agenda.
  1894. This undoes changes both in the agenda buffer and in the remote buffer
  1895. that have been changed along."
  1896. (interactive)
  1897. (or org-agenda-allow-remote-undo
  1898. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1899. (if (not (eq this-command last-command))
  1900. (setq org-agenda-undo-has-started-in nil
  1901. org-agenda-pending-undo-list org-agenda-undo-list))
  1902. (if (not org-agenda-pending-undo-list)
  1903. (error "No further undo information"))
  1904. (let* ((entry (pop org-agenda-pending-undo-list))
  1905. buf line cmd rembuf)
  1906. (setq cmd (pop entry) line (pop entry))
  1907. (setq rembuf (nth 2 entry))
  1908. (org-with-remote-undo rembuf
  1909. (while (bufferp (setq buf (pop entry)))
  1910. (if (pop entry)
  1911. (with-current-buffer buf
  1912. (let ((last-undo-buffer buf)
  1913. (inhibit-read-only t))
  1914. (unless (memq buf org-agenda-undo-has-started-in)
  1915. (push buf org-agenda-undo-has-started-in)
  1916. (make-local-variable 'pending-undo-list)
  1917. (undo-start))
  1918. (while (and pending-undo-list
  1919. (listp pending-undo-list)
  1920. (not (car pending-undo-list)))
  1921. (pop pending-undo-list))
  1922. (undo-more 1))))))
  1923. (org-goto-line line)
  1924. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1925. (defun org-verify-change-for-undo (l1 l2)
  1926. "Verify that a real change occurred between the undo lists L1 and L2."
  1927. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1928. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1929. (not (eq l1 l2)))
  1930. ;;; Agenda dispatch
  1931. (defvar org-agenda-restrict nil)
  1932. (defvar org-agenda-restrict-begin (make-marker))
  1933. (defvar org-agenda-restrict-end (make-marker))
  1934. (defvar org-agenda-last-dispatch-buffer nil)
  1935. (defvar org-agenda-overriding-restriction nil)
  1936. ;;;###autoload
  1937. (defun org-agenda (&optional arg keys restriction)
  1938. "Dispatch agenda commands to collect entries to the agenda buffer.
  1939. Prompts for a command to execute. Any prefix arg will be passed
  1940. on to the selected command. The default selections are:
  1941. a Call `org-agenda-list' to display the agenda for current day or week.
  1942. t Call `org-todo-list' to display the global todo list.
  1943. T Call `org-todo-list' to display the global todo list, select only
  1944. entries with a specific TODO keyword (the user gets a prompt).
  1945. m Call `org-tags-view' to display headlines with tags matching
  1946. a condition (the user is prompted for the condition).
  1947. M Like `m', but select only TODO entries, no ordinary headlines.
  1948. L Create a timeline for the current buffer.
  1949. e Export views to associated files.
  1950. s Search entries for keywords.
  1951. / Multi occur across all agenda files and also files listed
  1952. in `org-agenda-text-search-extra-files'.
  1953. < Restrict agenda commands to buffer, subtree, or region.
  1954. Press several times to get the desired effect.
  1955. > Remove a previous restriction.
  1956. # List \"stuck\" projects.
  1957. ! Configure what \"stuck\" means.
  1958. C Configure custom agenda commands.
  1959. More commands can be added by configuring the variable
  1960. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1961. searches can be pre-defined in this way.
  1962. If the current buffer is in Org-mode and visiting a file, you can also
  1963. first press `<' once to indicate that the agenda should be temporarily
  1964. \(until the next use of \\[org-agenda]) restricted to the current file.
  1965. Pressing `<' twice means to restrict to the current subtree or region
  1966. \(if active)."
  1967. (interactive "P")
  1968. (catch 'exit
  1969. (let* ((prefix-descriptions nil)
  1970. (org-agenda-window-setup (if (equal (buffer-name)
  1971. org-agenda-buffer-name)
  1972. 'current-window
  1973. org-agenda-window-setup))
  1974. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1975. (org-agenda-custom-commands
  1976. ;; normalize different versions
  1977. (delq nil
  1978. (mapcar
  1979. (lambda (x)
  1980. (cond ((stringp (cdr x))
  1981. (push x prefix-descriptions)
  1982. nil)
  1983. ((stringp (nth 1 x)) x)
  1984. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1985. (t (cons (car x) (cons "" (cdr x))))))
  1986. org-agenda-custom-commands)))
  1987. (buf (current-buffer))
  1988. (bfn (buffer-file-name (buffer-base-buffer)))
  1989. entry key type match lprops ans)
  1990. ;; Turn off restriction unless there is an overriding one,
  1991. (unless org-agenda-overriding-restriction
  1992. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1993. ;; There is a request to keep the file list in place
  1994. (put 'org-agenda-files 'org-restrict nil))
  1995. (setq org-agenda-restrict nil)
  1996. (move-marker org-agenda-restrict-begin nil)
  1997. (move-marker org-agenda-restrict-end nil))
  1998. ;; Delete old local properties
  1999. (put 'org-agenda-redo-command 'org-lprops nil)
  2000. ;; Delete previously set last-arguments
  2001. (put 'org-agenda-redo-command 'last-args nil)
  2002. ;; Remember where this call originated
  2003. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2004. (unless keys
  2005. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2006. keys (car ans)
  2007. restriction (cdr ans)))
  2008. ;; Establish the restriction, if any
  2009. (when (and (not org-agenda-overriding-restriction) restriction)
  2010. (put 'org-agenda-files 'org-restrict (list bfn))
  2011. (cond
  2012. ((eq restriction 'region)
  2013. (setq org-agenda-restrict t)
  2014. (move-marker org-agenda-restrict-begin (region-beginning))
  2015. (move-marker org-agenda-restrict-end (region-end)))
  2016. ((eq restriction 'subtree)
  2017. (save-excursion
  2018. (setq org-agenda-restrict t)
  2019. (org-back-to-heading t)
  2020. (move-marker org-agenda-restrict-begin (point))
  2021. (move-marker org-agenda-restrict-end
  2022. (progn (org-end-of-subtree t)))))))
  2023. ;; For example the todo list should not need it (but does...)
  2024. (cond
  2025. ((setq entry (assoc keys org-agenda-custom-commands))
  2026. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2027. (progn
  2028. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2029. lprops (nth 4 entry))
  2030. (put 'org-agenda-redo-command 'org-lprops lprops)
  2031. (cond
  2032. ((eq type 'agenda)
  2033. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2034. ((eq type 'alltodo)
  2035. (org-let lprops '(org-todo-list current-prefix-arg)))
  2036. ((eq type 'search)
  2037. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2038. ((eq type 'stuck)
  2039. (org-let lprops '(org-agenda-list-stuck-projects
  2040. current-prefix-arg)))
  2041. ((eq type 'tags)
  2042. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2043. ((eq type 'tags-todo)
  2044. (org-let lprops '(org-tags-view '(4) match)))
  2045. ((eq type 'todo)
  2046. (org-let lprops '(org-todo-list match)))
  2047. ((eq type 'tags-tree)
  2048. (org-check-for-org-mode)
  2049. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2050. ((eq type 'todo-tree)
  2051. (org-check-for-org-mode)
  2052. (org-let lprops
  2053. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2054. (regexp-quote match) "\\>"))))
  2055. ((eq type 'occur-tree)
  2056. (org-check-for-org-mode)
  2057. (org-let lprops '(org-occur match)))
  2058. ((functionp type)
  2059. (org-let lprops '(funcall type match)))
  2060. ((fboundp type)
  2061. (org-let lprops '(funcall type match)))
  2062. (t (error "Invalid custom agenda command type %s" type))))
  2063. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2064. ((equal keys "C")
  2065. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2066. (customize-variable 'org-agenda-custom-commands))
  2067. ((equal keys "a") (call-interactively 'org-agenda-list))
  2068. ((equal keys "s") (call-interactively 'org-search-view))
  2069. ((equal keys "t") (call-interactively 'org-todo-list))
  2070. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2071. ((equal keys "m") (call-interactively 'org-tags-view))
  2072. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2073. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2074. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2075. (org-add-hook
  2076. 'post-command-hook
  2077. (lambda ()
  2078. (unless (current-message)
  2079. (let* ((m (org-agenda-get-any-marker))
  2080. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2081. (when note
  2082. (message (concat
  2083. "FLAGGING-NOTE ([?] for more info): "
  2084. (org-add-props
  2085. (replace-regexp-in-string
  2086. "\\\\n" "//"
  2087. (copy-sequence note))
  2088. nil 'face 'org-warning)))))))
  2089. t t))
  2090. ((equal keys "L")
  2091. (unless (eq major-mode 'org-mode)
  2092. (error "This is not an Org-mode file"))
  2093. (unless restriction
  2094. (put 'org-agenda-files 'org-restrict (list bfn))
  2095. (org-call-with-arg 'org-timeline arg)))
  2096. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2097. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2098. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2099. (t (error "Invalid agenda key"))))))
  2100. (defun org-agenda-append-agenda ()
  2101. "Append another agenda view to the current one.
  2102. This function allows interactive building of block agendas.
  2103. Agenda views are separated by `org-agenda-block-separator'."
  2104. (interactive)
  2105. (unless (string= (buffer-name) org-agenda-buffer-name)
  2106. (error "Can only append from within agenda buffer"))
  2107. (let ((org-agenda-multi t))
  2108. (org-agenda)
  2109. (widen)))
  2110. (defun org-agenda-normalize-custom-commands (cmds)
  2111. (delq nil
  2112. (mapcar
  2113. (lambda (x)
  2114. (cond ((stringp (cdr x)) nil)
  2115. ((stringp (nth 1 x)) x)
  2116. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2117. (t (cons (car x) (cons "" (cdr x))))))
  2118. cmds)))
  2119. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2120. "The user interface for selecting an agenda command."
  2121. (catch 'exit
  2122. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2123. (restrict-ok (and bfn (eq major-mode 'org-mode)))
  2124. (region-p (org-region-active-p))
  2125. (custom org-agenda-custom-commands)
  2126. (selstring "")
  2127. restriction second-time
  2128. c entry key type match prefixes rmheader header-end custom1 desc
  2129. line lines left right n n1)
  2130. (save-window-excursion
  2131. (delete-other-windows)
  2132. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2133. (erase-buffer)
  2134. (insert (eval-when-compile
  2135. (let ((header
  2136. "
  2137. Press key for an agenda command: < Buffer, subtree/region restriction
  2138. -------------------------------- > Remove restriction
  2139. a Agenda for current week or day e Export agenda views
  2140. t List of all TODO entries T Entries with special TODO kwd
  2141. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2142. L Timeline for current buffer # List stuck projects (!=configure)
  2143. s Search for keywords C Configure custom agenda commands
  2144. / Multi-occur ? Find :FLAGGED: entries
  2145. ")
  2146. (start 0))
  2147. (while (string-match
  2148. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2149. header start)
  2150. (setq start (match-end 0))
  2151. (add-text-properties (match-beginning 2) (match-end 2)
  2152. '(face bold) header))
  2153. header)))
  2154. (setq header-end (move-marker (make-marker) (point)))
  2155. (while t
  2156. (setq custom1 custom)
  2157. (when (eq rmheader t)
  2158. (org-goto-line 1)
  2159. (re-search-forward ":" nil t)
  2160. (delete-region (match-end 0) (point-at-eol))
  2161. (forward-char 1)
  2162. (looking-at "-+")
  2163. (delete-region (match-end 0) (point-at-eol))
  2164. (move-marker header-end (match-end 0)))
  2165. (goto-char header-end)
  2166. (delete-region (point) (point-max))
  2167. ;; Produce all the lines that describe custom commands and prefixes
  2168. (setq lines nil)
  2169. (while (setq entry (pop custom1))
  2170. (setq key (car entry) desc (nth 1 entry)
  2171. type (nth 2 entry)
  2172. match (nth 3 entry))
  2173. (if (> (length key) 1)
  2174. (add-to-list 'prefixes (string-to-char key))
  2175. (setq line
  2176. (format
  2177. "%-4s%-14s"
  2178. (org-add-props (copy-sequence key)
  2179. '(face bold))
  2180. (cond
  2181. ((string-match "\\S-" desc) desc)
  2182. ((eq type 'agenda) "Agenda for current week or day")
  2183. ((eq type 'alltodo) "List of all TODO entries")
  2184. ((eq type 'search) "Word search")
  2185. ((eq type 'stuck) "List of stuck projects")
  2186. ((eq type 'todo) "TODO keyword")
  2187. ((eq type 'tags) "Tags query")
  2188. ((eq type 'tags-todo) "Tags (TODO)")
  2189. ((eq type 'tags-tree) "Tags tree")
  2190. ((eq type 'todo-tree) "TODO kwd tree")
  2191. ((eq type 'occur-tree) "Occur tree")
  2192. ((functionp type) (if (symbolp type)
  2193. (symbol-name type)
  2194. "Lambda expression"))
  2195. (t "???"))))
  2196. (if org-agenda-menu-show-matcher
  2197. (setq line
  2198. (concat line ": "
  2199. (cond
  2200. ((stringp match)
  2201. (setq match (copy-sequence match))
  2202. (org-add-props match nil 'face 'org-warning))
  2203. (match
  2204. (format "set of %d commands" (length match)))
  2205. (t ""))))
  2206. (if (org-string-nw-p match)
  2207. (add-text-properties
  2208. 0 (length line) (list 'help-echo
  2209. (concat "Matcher: "match)) line)))
  2210. (push line lines)))
  2211. (setq lines (nreverse lines))
  2212. (when prefixes
  2213. (mapc (lambda (x)
  2214. (push
  2215. (format "%s %s"
  2216. (org-add-props (char-to-string x)
  2217. nil 'face 'bold)
  2218. (or (cdr (assoc (concat selstring
  2219. (char-to-string x))
  2220. prefix-descriptions))
  2221. "Prefix key"))
  2222. lines))
  2223. prefixes))
  2224. ;; Check if we should display in two columns
  2225. (if org-agenda-menu-two-column
  2226. (progn
  2227. (setq n (length lines)
  2228. n1 (+ (/ n 2) (mod n 2))
  2229. right (nthcdr n1 lines)
  2230. left (copy-sequence lines))
  2231. (setcdr (nthcdr (1- n1) left) nil))
  2232. (setq left lines right nil))
  2233. (while left
  2234. (insert "\n" (pop left))
  2235. (when right
  2236. (if (< (current-column) 40)
  2237. (move-to-column 40 t)
  2238. (insert " "))
  2239. (insert (pop right))))
  2240. ;; Make the window the right size
  2241. (goto-char (point-min))
  2242. (if second-time
  2243. (if (not (pos-visible-in-window-p (point-max)))
  2244. (org-fit-window-to-buffer))
  2245. (setq second-time t)
  2246. (org-fit-window-to-buffer))
  2247. ;; Ask for selection
  2248. (message "Press key for agenda command%s:"
  2249. (if (or restrict-ok org-agenda-overriding-restriction)
  2250. (if org-agenda-overriding-restriction
  2251. " (restriction lock active)"
  2252. (if restriction
  2253. (format " (restricted to %s)" restriction)
  2254. " (unrestricted)"))
  2255. ""))
  2256. (setq c (read-char-exclusive))
  2257. (message "")
  2258. (cond
  2259. ((assoc (char-to-string c) custom)
  2260. (setq selstring (concat selstring (char-to-string c)))
  2261. (throw 'exit (cons selstring restriction)))
  2262. ((memq c prefixes)
  2263. (setq selstring (concat selstring (char-to-string c))
  2264. prefixes nil
  2265. rmheader (or rmheader t)
  2266. custom (delq nil (mapcar
  2267. (lambda (x)
  2268. (if (or (= (length (car x)) 1)
  2269. (/= (string-to-char (car x)) c))
  2270. nil
  2271. (cons (substring (car x) 1) (cdr x))))
  2272. custom))))
  2273. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2274. (message "Restriction is only possible in Org-mode buffers")
  2275. (ding) (sit-for 1))
  2276. ((eq c ?1)
  2277. (org-agenda-remove-restriction-lock 'noupdate)
  2278. (setq restriction 'buffer))
  2279. ((eq c ?0)
  2280. (org-agenda-remove-restriction-lock 'noupdate)
  2281. (setq restriction (if region-p 'region 'subtree)))
  2282. ((eq c ?<)
  2283. (org-agenda-remove-restriction-lock 'noupdate)
  2284. (setq restriction
  2285. (cond
  2286. ((eq restriction 'buffer)
  2287. (if region-p 'region 'subtree))
  2288. ((memq restriction '(subtree region))
  2289. nil)
  2290. (t 'buffer))))
  2291. ((eq c ?>)
  2292. (org-agenda-remove-restriction-lock 'noupdate)
  2293. (setq restriction nil))
  2294. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2295. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2296. ((and (> (length selstring) 0) (eq c ?\d))
  2297. (delete-window)
  2298. (org-agenda-get-restriction-and-command prefix-descriptions))
  2299. ((equal c ?q) (error "Abort"))
  2300. (t (error "Invalid key %c" c))))))))
  2301. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2302. (defvar org-agenda-last-arguments nil
  2303. "The arguments of the previous call to `org-agenda'.")
  2304. (defun org-agenda-run-series (name series)
  2305. (org-let (nth 1 series) '(org-prepare-agenda name))
  2306. (let* ((org-agenda-multi t)
  2307. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2308. (org-agenda-overriding-arguments
  2309. (or org-agenda-overriding-arguments
  2310. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2311. (get 'org-agenda-redo-command 'last-args))))
  2312. (cmds (car series))
  2313. (gprops (nth 1 series))
  2314. match ;; The byte compiler incorrectly complains about this. Keep it!
  2315. cmd type lprops)
  2316. (while (setq cmd (pop cmds))
  2317. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2318. (cond
  2319. ((eq type 'agenda)
  2320. (org-let2 gprops lprops
  2321. '(call-interactively 'org-agenda-list)))
  2322. ((eq type 'alltodo)
  2323. (org-let2 gprops lprops
  2324. '(call-interactively 'org-todo-list)))
  2325. ((eq type 'search)
  2326. (org-let2 gprops lprops
  2327. '(org-search-view current-prefix-arg match nil)))
  2328. ((eq type 'stuck)
  2329. (org-let2 gprops lprops
  2330. '(call-interactively 'org-agenda-list-stuck-projects)))
  2331. ((eq type 'tags)
  2332. (org-let2 gprops lprops
  2333. '(org-tags-view current-prefix-arg match)))
  2334. ((eq type 'tags-todo)
  2335. (org-let2 gprops lprops
  2336. '(org-tags-view '(4) match)))
  2337. ((eq type 'todo)
  2338. (org-let2 gprops lprops
  2339. '(org-todo-list match)))
  2340. ((fboundp type)
  2341. (org-let2 gprops lprops
  2342. '(funcall type match)))
  2343. (t (error "Invalid type in command series"))))
  2344. (widen)
  2345. (setq org-agenda-redo-command redo)
  2346. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2347. (goto-char (point-min)))
  2348. (org-fit-agenda-window)
  2349. (org-let (nth 1 series) '(org-finalize-agenda)))
  2350. ;;;###autoload
  2351. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2352. "Run an agenda command in batch mode and send the result to STDOUT.
  2353. If CMD-KEY is a string of length 1, it is used as a key in
  2354. `org-agenda-custom-commands' and triggers this command. If it is a
  2355. longer string it is used as a tags/todo match string.
  2356. Parameters are alternating variable names and values that will be bound
  2357. before running the agenda command."
  2358. (org-eval-in-environment (org-make-parameter-alist parameters)
  2359. (if (> (length cmd-key) 2)
  2360. (org-tags-view nil cmd-key)
  2361. (org-agenda nil cmd-key)))
  2362. (set-buffer org-agenda-buffer-name)
  2363. (princ (org-encode-for-stdout (buffer-string))))
  2364. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2365. ;(defun org-encode-for-stdout (string)
  2366. ; (if (fboundp 'encode-coding-string)
  2367. ; (encode-coding-string string buffer-file-coding-system)
  2368. ; string))
  2369. (defun org-encode-for-stdout (string)
  2370. string)
  2371. (defvar org-agenda-info nil)
  2372. ;;;###autoload
  2373. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2374. "Run an agenda command in batch mode and send the result to STDOUT.
  2375. If CMD-KEY is a string of length 1, it is used as a key in
  2376. `org-agenda-custom-commands' and triggers this command. If it is a
  2377. longer string it is used as a tags/todo match string.
  2378. Parameters are alternating variable names and values that will be bound
  2379. before running the agenda command.
  2380. The output gives a line for each selected agenda item. Each
  2381. item is a list of comma-separated values, like this:
  2382. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2383. category The category of the item
  2384. head The headline, without TODO kwd, TAGS and PRIORITY
  2385. type The type of the agenda entry, can be
  2386. todo selected in TODO match
  2387. tagsmatch selected in tags match
  2388. diary imported from diary
  2389. deadline a deadline on given date
  2390. scheduled scheduled on given date
  2391. timestamp entry has timestamp on given date
  2392. closed entry was closed on given date
  2393. upcoming-deadline warning about deadline
  2394. past-scheduled forwarded scheduled item
  2395. block entry has date block including g. date
  2396. todo The todo keyword, if any
  2397. tags All tags including inherited ones, separated by colons
  2398. date The relevant date, like 2007-2-14
  2399. time The time, like 15:00-16:50
  2400. extra Sting with extra planning info
  2401. priority-l The priority letter if any was given
  2402. priority-n The computed numerical priority
  2403. agenda-day The day in the agenda where this is listed"
  2404. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2405. (org-make-parameter-alist parameters))
  2406. (if (> (length cmd-key) 2)
  2407. (org-tags-view nil cmd-key)
  2408. (org-agenda nil cmd-key)))
  2409. (set-buffer org-agenda-buffer-name)
  2410. (let* ((lines (org-split-string (buffer-string) "\n"))
  2411. line)
  2412. (while (setq line (pop lines))
  2413. (catch 'next
  2414. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2415. (setq org-agenda-info
  2416. (org-fix-agenda-info (text-properties-at 0 line)))
  2417. (princ
  2418. (org-encode-for-stdout
  2419. (mapconcat 'org-agenda-export-csv-mapper
  2420. '(org-category txt type todo tags date time extra
  2421. priority-letter priority agenda-day)
  2422. ",")))
  2423. (princ "\n")))))
  2424. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2425. (defun org-fix-agenda-info (props)
  2426. "Make sure all properties on an agenda item have a canonical form.
  2427. This ensures the export commands can easily use it."
  2428. (let (tmp re)
  2429. (when (setq tmp (plist-get props 'tags))
  2430. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2431. (when (setq tmp (plist-get props 'date))
  2432. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2433. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2434. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2435. (setq tmp (calendar-date-string tmp)))
  2436. (setq props (plist-put props 'date tmp)))
  2437. (when (setq tmp (plist-get props 'day))
  2438. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2439. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2440. (setq tmp (calendar-date-string tmp)))
  2441. (setq props (plist-put props 'day tmp))
  2442. (setq props (plist-put props 'agenda-day tmp)))
  2443. (when (setq tmp (plist-get props 'txt))
  2444. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2445. (plist-put props 'priority-letter (match-string 1 tmp))
  2446. (setq tmp (replace-match "" t t tmp)))
  2447. (when (and (setq re (plist-get props 'org-todo-regexp))
  2448. (setq re (concat "\\`\\.*" re " ?"))
  2449. (string-match re tmp))
  2450. (plist-put props 'todo (match-string 1 tmp))
  2451. (setq tmp (replace-match "" t t tmp)))
  2452. (plist-put props 'txt tmp)))
  2453. props)
  2454. (defun org-agenda-export-csv-mapper (prop)
  2455. (let ((res (plist-get org-agenda-info prop)))
  2456. (setq res
  2457. (cond
  2458. ((not res) "")
  2459. ((stringp res) res)
  2460. (t (prin1-to-string res))))
  2461. (while (string-match "," res)
  2462. (setq res (replace-match ";" t t res)))
  2463. (org-trim res)))
  2464. ;;;###autoload
  2465. (defun org-store-agenda-views (&rest parameters)
  2466. (interactive)
  2467. (eval (list 'org-batch-store-agenda-views)))
  2468. ;;;###autoload
  2469. (defmacro org-batch-store-agenda-views (&rest parameters)
  2470. "Run all custom agenda commands that have a file argument."
  2471. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2472. (pop-up-frames nil)
  2473. (dir default-directory)
  2474. (pars (org-make-parameter-alist parameters))
  2475. cmd thiscmdkey files opts cmd-or-set)
  2476. (save-window-excursion
  2477. (while cmds
  2478. (setq cmd (pop cmds)
  2479. thiscmdkey (car cmd)
  2480. cmd-or-set (nth 2 cmd)
  2481. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2482. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2483. (if (stringp files) (setq files (list files)))
  2484. (when files
  2485. (org-eval-in-environment (append org-agenda-exporter-settings
  2486. opts pars)
  2487. (org-agenda nil thiscmdkey))
  2488. (set-buffer org-agenda-buffer-name)
  2489. (while files
  2490. (org-eval-in-environment (append org-agenda-exporter-settings
  2491. opts pars)
  2492. (org-write-agenda (expand-file-name (pop files) dir) nil t)))
  2493. (and (get-buffer org-agenda-buffer-name)
  2494. (kill-buffer org-agenda-buffer-name)))))))
  2495. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2496. (defun org-agenda-mark-header-line (pos)
  2497. "Mark the line at POS as an agenda structure header."
  2498. (save-excursion
  2499. (goto-char pos)
  2500. (put-text-property (point-at-bol) (point-at-eol)
  2501. 'org-agenda-structural-header t)
  2502. (when org-agenda-title-append
  2503. (put-text-property (point-at-bol) (point-at-eol)
  2504. 'org-agenda-title-append org-agenda-title-append))))
  2505. (defvar org-mobile-creating-agendas)
  2506. (defun org-write-agenda (file &optional open nosettings)
  2507. "Write the current buffer (an agenda view) as a file.
  2508. Depending on the extension of the file name, plain text (.txt),
  2509. HTML (.html or .htm) or Postscript (.ps) is produced.
  2510. If the extension is .ics, run icalendar export over all files used
  2511. to construct the agenda and limit the export to entries listed in the
  2512. agenda now.
  2513. With prefix argument OPEN, open the new file immediately.
  2514. If NOSETTINGS is given, do not scope the settings of
  2515. `org-agenda-exporter-settings' into the export commands. This is used when
  2516. the settings have already been scoped and we do not wish to overrule other,
  2517. higher priority settings."
  2518. (interactive "FWrite agenda to file: \nP")
  2519. (if (not (file-writable-p file))
  2520. (error "Cannot write agenda to file %s" file))
  2521. (org-let (if nosettings nil org-agenda-exporter-settings)
  2522. '(save-excursion
  2523. (save-window-excursion
  2524. (org-agenda-mark-filtered-text)
  2525. (let ((bs (copy-sequence (buffer-string))) beg)
  2526. (org-agenda-unmark-filtered-text)
  2527. (with-temp-buffer
  2528. (rename-buffer "Agenda View" t)
  2529. (set-buffer-modified-p nil)
  2530. (insert bs)
  2531. (org-agenda-remove-marked-text 'org-filtered)
  2532. (while (setq beg (text-property-any (point-min) (point-max)
  2533. 'org-filtered t))
  2534. (delete-region
  2535. beg (or (next-single-property-change beg 'org-filtered)
  2536. (point-max))))
  2537. (run-hooks 'org-agenda-before-write-hook)
  2538. (cond
  2539. ((org-bound-and-true-p org-mobile-creating-agendas)
  2540. (org-mobile-write-agenda-for-mobile file))
  2541. ((string-match "\\.html?\\'" file)
  2542. (require 'htmlize)
  2543. (set-buffer (htmlize-buffer (current-buffer)))
  2544. (when (and org-agenda-export-html-style
  2545. (string-match "<style>" org-agenda-export-html-style))
  2546. ;; replace <style> section with org-agenda-export-html-style
  2547. (goto-char (point-min))
  2548. (kill-region (- (search-forward "<style") 6)
  2549. (search-forward "</style>"))
  2550. (insert org-agenda-export-html-style))
  2551. (write-file file)
  2552. (kill-buffer (current-buffer))
  2553. (message "HTML written to %s" file))
  2554. ((string-match "\\.ps\\'" file)
  2555. (require 'ps-print)
  2556. (ps-print-buffer-with-faces file)
  2557. (message "Postscript written to %s" file))
  2558. ((string-match "\\.pdf\\'" file)
  2559. (require 'ps-print)
  2560. (ps-print-buffer-with-faces
  2561. (concat (file-name-sans-extension file) ".ps"))
  2562. (call-process "ps2pdf" nil nil nil
  2563. (expand-file-name
  2564. (concat (file-name-sans-extension file) ".ps"))
  2565. (expand-file-name file))
  2566. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2567. (message "PDF written to %s" file))
  2568. ((string-match "\\.ics\\'" file)
  2569. (require 'org-icalendar)
  2570. (let ((org-agenda-marker-table
  2571. (org-create-marker-find-array
  2572. (org-agenda-collect-markers)))
  2573. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2574. (org-combined-agenda-icalendar-file file))
  2575. (apply 'org-export-icalendar 'combine
  2576. (org-agenda-files nil 'ifmode))))
  2577. (t
  2578. (let ((bs (buffer-string)))
  2579. (find-file file)
  2580. (erase-buffer)
  2581. (insert bs)
  2582. (save-buffer 0)
  2583. (kill-buffer (current-buffer))
  2584. (message "Plain text written to %s" file))))))))
  2585. (set-buffer org-agenda-buffer-name))
  2586. (when open (org-open-file file)))
  2587. (defvar org-agenda-filter-overlays nil)
  2588. (defun org-agenda-mark-filtered-text ()
  2589. "Mark all text hidden by filtering with a text property."
  2590. (let ((inhibit-read-only t))
  2591. (mapc
  2592. (lambda (o)
  2593. (when (equal (overlay-buffer o) (current-buffer))
  2594. (put-text-property
  2595. (overlay-start o) (overlay-end o)
  2596. 'org-filtered t)))
  2597. org-agenda-filter-overlays)))
  2598. (defun org-agenda-unmark-filtered-text ()
  2599. "Remove the filtering text property."
  2600. (let ((inhibit-read-only t))
  2601. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2602. (defun org-agenda-remove-marked-text (property &optional value)
  2603. "Delete all text marked with VALUE of PROPERTY.
  2604. VALUE defaults to t."
  2605. (let (beg)
  2606. (setq value (or value t))
  2607. (while (setq beg (text-property-any (point-min) (point-max)
  2608. property value))
  2609. (delete-region
  2610. beg (or (next-single-property-change beg 'org-filtered)
  2611. (point-max))))))
  2612. (defun org-agenda-add-entry-text ()
  2613. "Add entry text to agenda lines.
  2614. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2615. entry text following headings shown in the agenda.
  2616. Drawers will be excluded, also the line with scheduling/deadline info."
  2617. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2618. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2619. (let (m txt)
  2620. (goto-char (point-min))
  2621. (while (not (eobp))
  2622. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2623. (beginning-of-line 2)
  2624. (setq txt (org-agenda-get-some-entry-text
  2625. m org-agenda-add-entry-text-maxlines " > "))
  2626. (end-of-line 1)
  2627. (if (string-match "\\S-" txt)
  2628. (insert "\n" txt)
  2629. (or (eobp) (forward-char 1))))))))
  2630. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2631. &rest keep)
  2632. "Extract entry text from MARKER, at most N-LINES lines.
  2633. This will ignore drawers etc, just get the text.
  2634. If INDENT is given, prefix every line with this string. If KEEP is
  2635. given, it is a list of symbols, defining stuff that should not be
  2636. removed from the entry content. Currently only `planning' is allowed here."
  2637. (let (txt drawer-re kwd-time-re ind)
  2638. (save-excursion
  2639. (with-current-buffer (marker-buffer marker)
  2640. (if (not (eq major-mode 'org-mode))
  2641. (setq txt "")
  2642. (save-excursion
  2643. (save-restriction
  2644. (widen)
  2645. (goto-char marker)
  2646. (end-of-line 1)
  2647. (setq txt (buffer-substring
  2648. (min (1+ (point)) (point-max))
  2649. (progn (outline-next-heading) (point)))
  2650. drawer-re org-drawer-regexp
  2651. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2652. ".*\n?"))
  2653. (with-temp-buffer
  2654. (insert txt)
  2655. (when org-agenda-add-entry-text-descriptive-links
  2656. (goto-char (point-min))
  2657. (while (org-activate-bracket-links (point-max))
  2658. (add-text-properties (match-beginning 0) (match-end 0)
  2659. '(face org-link))))
  2660. (goto-char (point-min))
  2661. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2662. (set-text-properties (match-beginning 0) (match-end 0)
  2663. nil))
  2664. (goto-char (point-min))
  2665. (while (re-search-forward drawer-re nil t)
  2666. (delete-region
  2667. (match-beginning 0)
  2668. (progn (re-search-forward
  2669. "^[ \t]*:END:.*\n?" nil 'move)
  2670. (point))))
  2671. (unless (member 'planning keep)
  2672. (goto-char (point-min))
  2673. (while (re-search-forward kwd-time-re nil t)
  2674. (replace-match "")))
  2675. (goto-char (point-min))
  2676. (when org-agenda-entry-text-exclude-regexps
  2677. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2678. (while (setq re (pop re-list))
  2679. (goto-char (point-min))
  2680. (while (re-search-forward re nil t)
  2681. (replace-match "")))))
  2682. (goto-char (point-max))
  2683. (skip-chars-backward " \t\n")
  2684. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2685. ;; find and remove min common indentation
  2686. (goto-char (point-min))
  2687. (untabify (point-min) (point-max))
  2688. (setq ind (org-get-indentation))
  2689. (while (not (eobp))
  2690. (unless (looking-at "[ \t]*$")
  2691. (setq ind (min ind (org-get-indentation))))
  2692. (beginning-of-line 2))
  2693. (goto-char (point-min))
  2694. (while (not (eobp))
  2695. (unless (looking-at "[ \t]*$")
  2696. (move-to-column ind)
  2697. (delete-region (point-at-bol) (point)))
  2698. (beginning-of-line 2))
  2699. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2700. (goto-char (point-min))
  2701. (when indent
  2702. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2703. (replace-match indent t t)))
  2704. (goto-char (point-min))
  2705. (while (looking-at "[ \t]*\n") (replace-match ""))
  2706. (goto-char (point-max))
  2707. (when (> (org-current-line)
  2708. n-lines)
  2709. (org-goto-line (1+ n-lines))
  2710. (backward-char 1))
  2711. (setq txt (buffer-substring (point-min) (point)))))))))
  2712. txt))
  2713. (defun org-agenda-collect-markers ()
  2714. "Collect the markers pointing to entries in the agenda buffer."
  2715. (let (m markers)
  2716. (save-excursion
  2717. (goto-char (point-min))
  2718. (while (not (eobp))
  2719. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2720. (org-get-at-bol 'org-marker)))
  2721. (push m markers))
  2722. (beginning-of-line 2)))
  2723. (nreverse markers)))
  2724. (defun org-create-marker-find-array (marker-list)
  2725. "Create a alist of files names with all marker positions in that file."
  2726. (let (f tbl m a p)
  2727. (while (setq m (pop marker-list))
  2728. (setq p (marker-position m)
  2729. f (buffer-file-name (or (buffer-base-buffer
  2730. (marker-buffer m))
  2731. (marker-buffer m))))
  2732. (if (setq a (assoc f tbl))
  2733. (push (marker-position m) (cdr a))
  2734. (push (list f p) tbl)))
  2735. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2736. tbl)))
  2737. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2738. (defun org-check-agenda-marker-table ()
  2739. "Check of the current entry is on the marker list."
  2740. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2741. a)
  2742. (and (setq a (assoc file org-agenda-marker-table))
  2743. (save-match-data
  2744. (save-excursion
  2745. (org-back-to-heading t)
  2746. (member (point) (cdr a)))))))
  2747. (defun org-check-for-org-mode ()
  2748. "Make sure current buffer is in org-mode. Error if not."
  2749. (or (eq major-mode 'org-mode)
  2750. (error "Cannot execute org-mode agenda command on buffer in %s"
  2751. major-mode)))
  2752. (defun org-fit-agenda-window ()
  2753. "Fit the window to the buffer size."
  2754. (and (memq org-agenda-window-setup '(reorganize-frame))
  2755. (fboundp 'fit-window-to-buffer)
  2756. (org-fit-window-to-buffer
  2757. nil
  2758. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2759. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2760. ;;; Agenda prepare and finalize
  2761. (defvar org-agenda-multi nil) ; dynamically scoped
  2762. (defvar org-agenda-buffer-name "*Org Agenda*")
  2763. (defvar org-pre-agenda-window-conf nil)
  2764. (defvar org-agenda-columns-active nil)
  2765. (defvar org-agenda-name nil)
  2766. (defvar org-agenda-filter nil)
  2767. (defvar org-agenda-filter-while-redo nil)
  2768. (defvar org-agenda-filter-preset nil
  2769. "A preset of the tags filter used for secondary agenda filtering.
  2770. This must be a list of strings, each string must be a single tag preceded
  2771. by \"+\" or \"-\".
  2772. This variable should not be set directly, but agenda custom commands can
  2773. bind it in the options section. The preset filter is a global property of
  2774. the entire agenda view. In a block agenda, it will not work reliably to
  2775. define a filter for one of the individual blocks. You need to set it in
  2776. the global options and expect it to be applied to the entire view.")
  2777. (defun org-prepare-agenda (&optional name)
  2778. (setq org-todo-keywords-for-agenda nil)
  2779. (setq org-done-keywords-for-agenda nil)
  2780. (setq org-drawers-for-agenda nil)
  2781. (unless org-agenda-persistent-filter
  2782. (setq org-agenda-filter nil))
  2783. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2784. (if org-agenda-multi
  2785. (progn
  2786. (setq buffer-read-only nil)
  2787. (goto-char (point-max))
  2788. (unless (or (bobp) org-agenda-compact-blocks
  2789. (not org-agenda-block-separator))
  2790. (insert "\n"
  2791. (if (stringp org-agenda-block-separator)
  2792. org-agenda-block-separator
  2793. (make-string (window-width) org-agenda-block-separator))
  2794. "\n"))
  2795. (narrow-to-region (point) (point-max)))
  2796. (org-agenda-reset-markers)
  2797. (setq org-agenda-contributing-files nil)
  2798. (setq org-agenda-columns-active nil)
  2799. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2800. (setq org-todo-keywords-for-agenda
  2801. (org-uniquify org-todo-keywords-for-agenda))
  2802. (setq org-done-keywords-for-agenda
  2803. (org-uniquify org-done-keywords-for-agenda))
  2804. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2805. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2806. (awin (get-buffer-window abuf)))
  2807. (cond
  2808. ((equal (current-buffer) abuf) nil)
  2809. (awin (select-window awin))
  2810. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2811. ((equal org-agenda-window-setup 'current-window)
  2812. (org-pop-to-buffer-same-window abuf))
  2813. ((equal org-agenda-window-setup 'other-window)
  2814. (org-switch-to-buffer-other-window abuf))
  2815. ((equal org-agenda-window-setup 'other-frame)
  2816. (switch-to-buffer-other-frame abuf))
  2817. ((equal org-agenda-window-setup 'reorganize-frame)
  2818. (delete-other-windows)
  2819. (org-switch-to-buffer-other-window abuf)))
  2820. ;; additional test in case agenda is invoked from within agenda
  2821. ;; buffer via elisp link
  2822. (unless (equal (current-buffer) abuf)
  2823. (org-pop-to-buffer-same-window abuf)))
  2824. (setq buffer-read-only nil)
  2825. (let ((inhibit-read-only t)) (erase-buffer))
  2826. (org-agenda-mode)
  2827. (and name (not org-agenda-name)
  2828. (org-set-local 'org-agenda-name name)))
  2829. (setq buffer-read-only nil))
  2830. (defun org-finalize-agenda ()
  2831. "Finishing touch for the agenda buffer, called just before displaying it."
  2832. (unless org-agenda-multi
  2833. (save-excursion
  2834. (let ((inhibit-read-only t))
  2835. (goto-char (point-min))
  2836. (while (org-activate-bracket-links (point-max))
  2837. (add-text-properties (match-beginning 0) (match-end 0)
  2838. '(face org-link)))
  2839. (org-agenda-align-tags)
  2840. (unless org-agenda-with-colors
  2841. (remove-text-properties (point-min) (point-max) '(face nil))))
  2842. (if (and (boundp 'org-agenda-overriding-columns-format)
  2843. org-agenda-overriding-columns-format)
  2844. (org-set-local 'org-agenda-overriding-columns-format
  2845. org-agenda-overriding-columns-format))
  2846. (if (and (boundp 'org-agenda-view-columns-initially)
  2847. org-agenda-view-columns-initially)
  2848. (org-agenda-columns))
  2849. (when org-agenda-fontify-priorities
  2850. (org-agenda-fontify-priorities))
  2851. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2852. (org-agenda-dim-blocked-tasks))
  2853. (org-agenda-mark-clocking-task)
  2854. (when org-agenda-entry-text-mode
  2855. (org-agenda-entry-text-hide)
  2856. (org-agenda-entry-text-show))
  2857. (if (functionp 'org-habit-insert-consistency-graphs)
  2858. (org-habit-insert-consistency-graphs))
  2859. (run-hooks 'org-finalize-agenda-hook)
  2860. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2861. (when (or org-agenda-filter (get 'org-agenda-filter :preset-filter))
  2862. (org-agenda-filter-apply org-agenda-filter))
  2863. )))
  2864. (defun org-agenda-mark-clocking-task ()
  2865. "Mark the current clock entry in the agenda if it is present."
  2866. (mapc (lambda (o)
  2867. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  2868. (delete-overlay o)))
  2869. (overlays-in (point-min) (point-max)))
  2870. (when (marker-buffer org-clock-hd-marker)
  2871. (save-excursion
  2872. (goto-char (point-min))
  2873. (let (s ov)
  2874. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2875. (goto-char s)
  2876. (when (equal (org-get-at-bol 'org-hd-marker)
  2877. org-clock-hd-marker)
  2878. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  2879. (overlay-put ov 'type 'org-agenda-clocking)
  2880. (overlay-put ov 'face 'org-agenda-clocking)
  2881. (overlay-put ov 'help-echo
  2882. "The clock is running in this item")))))))
  2883. (defun org-agenda-fontify-priorities ()
  2884. "Make highest priority lines bold, and lowest italic."
  2885. (interactive)
  2886. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  2887. (delete-overlay o)))
  2888. (overlays-in (point-min) (point-max)))
  2889. (save-excursion
  2890. (let ((inhibit-read-only t)
  2891. b e p ov h l)
  2892. (goto-char (point-min))
  2893. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2894. (setq h (or (get-char-property (point) 'org-highest-priority)
  2895. org-highest-priority)
  2896. l (or (get-char-property (point) 'org-lowest-priority)
  2897. org-lowest-priority)
  2898. p (string-to-char (match-string 1))
  2899. b (match-beginning 0)
  2900. e (if (eq org-agenda-fontify-priorities 'cookies)
  2901. (match-end 0)
  2902. (point-at-eol))
  2903. ov (make-overlay b e))
  2904. (overlay-put
  2905. ov 'face
  2906. (cond ((org-face-from-face-or-color
  2907. 'priority nil
  2908. (cdr (assoc p org-priority-faces))))
  2909. ((and (listp org-agenda-fontify-priorities)
  2910. (org-face-from-face-or-color
  2911. 'priority nil
  2912. (cdr (assoc p org-agenda-fontify-priorities)))))
  2913. ((equal p l) 'italic)
  2914. ((equal p h) 'bold)))
  2915. (overlay-put ov 'org-type 'org-priority)))))
  2916. (defun org-agenda-dim-blocked-tasks ()
  2917. "Dim currently blocked TODO's in the agenda display."
  2918. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  2919. (delete-overlay o)))
  2920. (overlays-in (point-min) (point-max)))
  2921. (save-excursion
  2922. (let ((inhibit-read-only t)
  2923. (org-depend-tag-blocked nil)
  2924. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2925. org-blocked-by-checkboxes
  2926. invis1 b e p ov h l)
  2927. (goto-char (point-min))
  2928. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2929. (and pos (goto-char (1+ pos))))
  2930. (setq org-blocked-by-checkboxes nil invis1 invis)
  2931. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2932. (when (and marker
  2933. (with-current-buffer (marker-buffer marker)
  2934. (save-excursion (goto-char marker)
  2935. (org-entry-blocked-p))))
  2936. (if org-blocked-by-checkboxes (setq invis1 nil))
  2937. (setq b (if invis1
  2938. (max (point-min) (1- (point-at-bol)))
  2939. (point-at-bol))
  2940. e (point-at-eol)
  2941. ov (make-overlay b e))
  2942. (if invis1
  2943. (overlay-put ov 'invisible t)
  2944. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2945. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  2946. (defvar org-agenda-skip-function nil
  2947. "Function to be called at each match during agenda construction.
  2948. If this function returns nil, the current match should not be skipped.
  2949. Otherwise, the function must return a position from where the search
  2950. should be continued.
  2951. This may also be a Lisp form, it will be evaluated.
  2952. Never set this variable using `setq' or so, because then it will apply
  2953. to all future agenda commands. If you do want a global skipping condition,
  2954. use the option `org-agenda-skip-function-global' instead.
  2955. The correct usage for `org-agenda-skip-function' is to bind it with
  2956. `let' to scope it dynamically into the agenda-constructing command.
  2957. A good way to set it is through options in `org-agenda-custom-commands'.")
  2958. (defun org-agenda-skip ()
  2959. "Throw to `:skip' in places that should be skipped.
  2960. Also moves point to the end of the skipped region, so that search can
  2961. continue from there."
  2962. (let ((p (point-at-bol)) to)
  2963. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2964. (get-text-property p :org-archived)
  2965. (org-end-of-subtree t)
  2966. (throw :skip t))
  2967. (and org-agenda-skip-comment-trees
  2968. (get-text-property p :org-comment)
  2969. (org-end-of-subtree t)
  2970. (throw :skip t))
  2971. (if (equal (char-after p) ?#) (throw :skip t))
  2972. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  2973. (org-agenda-skip-eval org-agenda-skip-function)))
  2974. (goto-char to)
  2975. (throw :skip t))))
  2976. (defun org-agenda-skip-eval (form)
  2977. "If FORM is a function or a list, call (or eval) is and return result.
  2978. `save-excursion' and `save-match-data' are wrapped around the call, so point
  2979. and match data are returned to the previous state no matter what these
  2980. functions do."
  2981. (let (fp)
  2982. (and form
  2983. (or (setq fp (functionp form))
  2984. (consp form))
  2985. (save-excursion
  2986. (save-match-data
  2987. (if fp
  2988. (funcall form)
  2989. (eval form)))))))
  2990. (defvar org-agenda-markers nil
  2991. "List of all currently active markers created by `org-agenda'.")
  2992. (defvar org-agenda-last-marker-time (org-float-time)
  2993. "Creation time of the last agenda marker.")
  2994. (defun org-agenda-new-marker (&optional pos)
  2995. "Return a new agenda marker.
  2996. Org-mode keeps a list of these markers and resets them when they are
  2997. no longer in use."
  2998. (let ((m (copy-marker (or pos (point)))))
  2999. (setq org-agenda-last-marker-time (org-float-time))
  3000. (push m org-agenda-markers)
  3001. m))
  3002. (defun org-agenda-reset-markers ()
  3003. "Reset markers created by `org-agenda'."
  3004. (while org-agenda-markers
  3005. (move-marker (pop org-agenda-markers) nil)))
  3006. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3007. "Save relative positions of markers in region."
  3008. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3009. org-agenda-markers))
  3010. ;;; Entry text mode
  3011. (defun org-agenda-entry-text-show-here ()
  3012. "Add some text from the entry as context to the current line."
  3013. (let (m txt o)
  3014. (setq m (org-get-at-bol 'org-hd-marker))
  3015. (unless (marker-buffer m)
  3016. (error "No marker points to an entry here"))
  3017. (setq txt (concat "\n" (org-no-properties
  3018. (org-agenda-get-some-entry-text
  3019. m org-agenda-entry-text-maxlines " > "))))
  3020. (when (string-match "\\S-" txt)
  3021. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3022. (overlay-put o 'evaporate t)
  3023. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3024. (overlay-put o 'after-string txt))))
  3025. (defun org-agenda-entry-text-show ()
  3026. "Add entry context for all agenda lines."
  3027. (interactive)
  3028. (save-excursion
  3029. (goto-char (point-max))
  3030. (beginning-of-line 1)
  3031. (while (not (bobp))
  3032. (when (org-get-at-bol 'org-hd-marker)
  3033. (org-agenda-entry-text-show-here))
  3034. (beginning-of-line 0))))
  3035. (defun org-agenda-entry-text-hide ()
  3036. "Remove any shown entry context."
  3037. (delq nil
  3038. (mapcar (lambda (o)
  3039. (if (eq (overlay-get o 'org-overlay-type)
  3040. 'agenda-entry-content)
  3041. (progn (delete-overlay o) t)))
  3042. (overlays-in (point-min) (point-max)))))
  3043. (defun org-agenda-get-day-face (date)
  3044. "Return the face DATE should be displayed with."
  3045. (or (and (functionp org-agenda-day-face-function)
  3046. (funcall org-agenda-day-face-function date))
  3047. (cond ((org-agenda-todayp date)
  3048. 'org-agenda-date-today)
  3049. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3050. 'org-agenda-date-weekend)
  3051. (t 'org-agenda-date))))
  3052. ;;; Agenda timeline
  3053. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3054. (defun org-timeline (&optional dotodo)
  3055. "Show a time-sorted view of the entries in the current org file.
  3056. Only entries with a time stamp of today or later will be listed. With
  3057. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3058. under the current date.
  3059. If the buffer contains an active region, only check the region for
  3060. dates."
  3061. (interactive "P")
  3062. (org-compile-prefix-format 'timeline)
  3063. (org-set-sorting-strategy 'timeline)
  3064. (let* ((dopast t)
  3065. (doclosed org-agenda-show-log)
  3066. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3067. (current-buffer))))
  3068. (date (calendar-current-date))
  3069. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3070. (end (if (org-region-active-p) (region-end) (point-max)))
  3071. (day-numbers (org-get-all-dates beg end 'no-ranges
  3072. t doclosed ; always include today
  3073. org-timeline-show-empty-dates))
  3074. (org-deadline-warning-days 0)
  3075. (org-agenda-only-exact-dates t)
  3076. (today (org-today))
  3077. (past t)
  3078. args
  3079. s e rtn d emptyp)
  3080. (setq org-agenda-redo-command
  3081. (list 'progn
  3082. (list 'org-switch-to-buffer-other-window (current-buffer))
  3083. (list 'org-timeline (list 'quote dotodo))))
  3084. (if (not dopast)
  3085. ;; Remove past dates from the list of dates.
  3086. (setq day-numbers (delq nil (mapcar (lambda(x)
  3087. (if (>= x today) x nil))
  3088. day-numbers))))
  3089. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3090. (if doclosed (push :closed args))
  3091. (push :timestamp args)
  3092. (push :deadline args)
  3093. (push :scheduled args)
  3094. (push :sexp args)
  3095. (if dotodo (push :todo args))
  3096. (insert "Timeline of file " entry "\n")
  3097. (add-text-properties (point-min) (point)
  3098. (list 'face 'org-agenda-structure))
  3099. (org-agenda-mark-header-line (point-min))
  3100. (while (setq d (pop day-numbers))
  3101. (if (and (listp d) (eq (car d) :omitted))
  3102. (progn
  3103. (setq s (point))
  3104. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3105. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3106. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3107. (if (and (>= d today)
  3108. dopast
  3109. past)
  3110. (progn
  3111. (setq past nil)
  3112. (insert (make-string 79 ?-) "\n")))
  3113. (setq date (calendar-gregorian-from-absolute d))
  3114. (setq s (point))
  3115. (setq rtn (and (not emptyp)
  3116. (apply 'org-agenda-get-day-entries entry
  3117. date args)))
  3118. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3119. (progn
  3120. (insert
  3121. (if (stringp org-agenda-format-date)
  3122. (format-time-string org-agenda-format-date
  3123. (org-time-from-absolute date))
  3124. (funcall org-agenda-format-date date))
  3125. "\n")
  3126. (put-text-property s (1- (point)) 'face
  3127. (org-agenda-get-day-face date))
  3128. (put-text-property s (1- (point)) 'org-date-line t)
  3129. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3130. (if (equal d today)
  3131. (put-text-property s (1- (point)) 'org-today t))
  3132. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3133. (put-text-property s (1- (point)) 'day d)))))
  3134. (goto-char (point-min))
  3135. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3136. (point-min)))
  3137. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3138. (org-finalize-agenda)
  3139. (setq buffer-read-only t)))
  3140. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3141. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3142. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3143. not every single day in the range. If FORCE-TODAY is non-nil, make
  3144. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3145. inactive time stamps (those in square brackets) are included.
  3146. When EMPTY is non-nil, also include days without any entries."
  3147. (let ((re (concat
  3148. (if pre-re pre-re "")
  3149. (if inactive org-ts-regexp-both org-ts-regexp)))
  3150. dates dates1 date day day1 day2 ts1 ts2 pos)
  3151. (if force-today
  3152. (setq dates (list (org-today))))
  3153. (save-excursion
  3154. (goto-char beg)
  3155. (while (re-search-forward re end t)
  3156. (setq day (time-to-days (org-time-string-to-time
  3157. (substring (match-string 1) 0 10)
  3158. (current-buffer) (match-beginning 0))))
  3159. (or (memq day dates) (push day dates)))
  3160. (unless no-ranges
  3161. (goto-char beg)
  3162. (while (re-search-forward org-tr-regexp end t)
  3163. (setq pos (match-beginning 0))
  3164. (setq ts1 (substring (match-string 1) 0 10)
  3165. ts2 (substring (match-string 2) 0 10)
  3166. day1 (time-to-days (org-time-string-to-time
  3167. ts1 (current-buffer) pos))
  3168. day2 (time-to-days (org-time-string-to-time
  3169. ts2 (current-buffer) pos)))
  3170. (while (< (setq day1 (1+ day1)) day2)
  3171. (or (memq day1 dates) (push day1 dates)))))
  3172. (setq dates (sort dates '<))
  3173. (when empty
  3174. (while (setq day (pop dates))
  3175. (setq day2 (car dates))
  3176. (push day dates1)
  3177. (when (and day2 empty)
  3178. (if (or (eq empty t)
  3179. (and (numberp empty) (<= (- day2 day) empty)))
  3180. (while (< (setq day (1+ day)) day2)
  3181. (push (list day) dates1))
  3182. (push (cons :omitted (- day2 day)) dates1))))
  3183. (setq dates (nreverse dates1)))
  3184. dates)))
  3185. ;;; Agenda Daily/Weekly
  3186. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3187. "Start day for the agenda view.
  3188. Custom commands can set this variable in the options section.")
  3189. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3190. (defvar org-agenda-current-span nil
  3191. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3192. (defvar org-arg-loc nil) ; local variable
  3193. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3194. "List of types searched for when creating the daily/weekly agenda.
  3195. This variable is a list of symbols that controls the types of
  3196. items that appear in the daily/weekly agenda. Allowed symbols in this
  3197. list are are
  3198. :timestamp List items containing a date stamp or date range matching
  3199. the selected date. This includes sexp entries in
  3200. angular brackets.
  3201. :sexp List entries resulting from plain diary-like sexps.
  3202. :deadline List deadline due on that date. When the date is today,
  3203. also list any deadlines past due, or due within
  3204. `org-deadline-warning-days'. `:deadline' must appear before
  3205. `:scheduled' if the setting of
  3206. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3207. any effect.
  3208. :scheduled List all items which are scheduled for the given date.
  3209. The diary for *today* also contains items which were
  3210. scheduled earlier and are not yet marked DONE.
  3211. By default, all four types are turned on.
  3212. Never set this variable globally using `setq', because then it
  3213. will apply to all future agenda commands. Instead, bind it with
  3214. `let' to scope it dynamically into the agenda-constructing
  3215. command. A good way to set it is through options in
  3216. `org-agenda-custom-commands'. For a more flexible (though
  3217. somewhat less efficient) way of determining what is included in
  3218. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3219. ;;;###autoload
  3220. (defun org-agenda-list (&optional arg start-day span)
  3221. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3222. The view will be for the current day or week, but from the overview buffer
  3223. you will be able to go to other days/weeks.
  3224. With a numeric prefix argument in an interactive call, the agenda will
  3225. span ARG days. Lisp programs should instead specify SPAN to change
  3226. the number of days. SPAN defaults to `org-agenda-span'.
  3227. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3228. given in `org-agenda-start-on-weekday'."
  3229. (interactive "P")
  3230. (if (and (integerp arg) (> arg 0))
  3231. (setq span arg arg nil))
  3232. (setq start-day (or start-day org-agenda-start-day))
  3233. (if org-agenda-overriding-arguments
  3234. (setq arg (car org-agenda-overriding-arguments)
  3235. start-day (nth 1 org-agenda-overriding-arguments)
  3236. span (nth 2 org-agenda-overriding-arguments)))
  3237. (if (stringp start-day)
  3238. ;; Convert to an absolute day number
  3239. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3240. (setq org-agenda-last-arguments (list arg start-day span))
  3241. (org-compile-prefix-format 'agenda)
  3242. (org-set-sorting-strategy 'agenda)
  3243. (let* ((span (org-agenda-ndays-to-span
  3244. (or span org-agenda-ndays org-agenda-span)))
  3245. (today (org-today))
  3246. (sd (or start-day today))
  3247. (ndays (org-agenda-span-to-ndays span sd))
  3248. (org-agenda-start-on-weekday
  3249. (if (eq ndays 7)
  3250. org-agenda-start-on-weekday))
  3251. (thefiles (org-agenda-files nil 'ifmode))
  3252. (files thefiles)
  3253. (start (if (or (null org-agenda-start-on-weekday)
  3254. (< ndays 7))
  3255. sd
  3256. (let* ((nt (calendar-day-of-week
  3257. (calendar-gregorian-from-absolute sd)))
  3258. (n1 org-agenda-start-on-weekday)
  3259. (d (- nt n1)))
  3260. (- sd (+ (if (< d 0) 7 0) d)))))
  3261. (day-numbers (list start))
  3262. (day-cnt 0)
  3263. (inhibit-redisplay (not debug-on-error))
  3264. s e rtn rtnall file date d start-pos end-pos todayp
  3265. clocktable-start clocktable-end filter)
  3266. (setq org-agenda-redo-command
  3267. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3268. (dotimes (n (1- ndays))
  3269. (push (1+ (car day-numbers)) day-numbers))
  3270. (setq day-numbers (nreverse day-numbers))
  3271. (setq clocktable-start (car day-numbers)
  3272. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3273. (org-prepare-agenda "Day/Week")
  3274. (org-set-local 'org-starting-day (car day-numbers))
  3275. (org-set-local 'org-arg-loc arg)
  3276. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3277. (unless org-agenda-compact-blocks
  3278. (let* ((d1 (car day-numbers))
  3279. (d2 (org-last day-numbers))
  3280. (w1 (org-days-to-iso-week d1))
  3281. (w2 (org-days-to-iso-week d2)))
  3282. (setq s (point))
  3283. (if org-agenda-overriding-header
  3284. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3285. nil 'face 'org-agenda-structure) "\n")
  3286. (insert (org-agenda-span-name span)
  3287. "-agenda"
  3288. (if (< (- d2 d1) 350)
  3289. (if (= w1 w2)
  3290. (format " (W%02d)" w1)
  3291. (format " (W%02d-W%02d)" w1 w2))
  3292. "")
  3293. ":\n")))
  3294. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3295. 'org-date-line t))
  3296. (org-agenda-mark-header-line s))
  3297. (while (setq d (pop day-numbers))
  3298. (setq date (calendar-gregorian-from-absolute d)
  3299. s (point))
  3300. (if (or (setq todayp (= d today))
  3301. (and (not start-pos) (= d sd)))
  3302. (setq start-pos (point))
  3303. (if (and start-pos (not end-pos))
  3304. (setq end-pos (point))))
  3305. (setq files thefiles
  3306. rtnall nil)
  3307. (while (setq file (pop files))
  3308. (catch 'nextfile
  3309. (org-check-agenda-file file)
  3310. (let ((org-agenda-entry-types org-agenda-entry-types))
  3311. (unless org-agenda-include-deadlines
  3312. (setq org-agenda-entry-types
  3313. (delq :deadline org-agenda-entry-types)))
  3314. (cond
  3315. ((memq org-agenda-show-log '(only clockcheck))
  3316. (setq rtn (org-agenda-get-day-entries
  3317. file date :closed)))
  3318. (org-agenda-show-log
  3319. (setq rtn (apply 'org-agenda-get-day-entries
  3320. file date
  3321. (append '(:closed) org-agenda-entry-types))))
  3322. (t
  3323. (setq rtn (apply 'org-agenda-get-day-entries
  3324. file date
  3325. org-agenda-entry-types)))))
  3326. (setq rtnall (append rtnall rtn))))
  3327. (if org-agenda-include-diary
  3328. (let ((org-agenda-search-headline-for-time t))
  3329. (require 'diary-lib)
  3330. (setq rtn (org-get-entries-from-diary date))
  3331. (setq rtnall (append rtnall rtn))))
  3332. (if (or rtnall org-agenda-show-all-dates)
  3333. (progn
  3334. (setq day-cnt (1+ day-cnt))
  3335. (insert
  3336. (if (stringp org-agenda-format-date)
  3337. (format-time-string org-agenda-format-date
  3338. (org-time-from-absolute date))
  3339. (funcall org-agenda-format-date date))
  3340. "\n")
  3341. (put-text-property s (1- (point)) 'face
  3342. (org-agenda-get-day-face date))
  3343. (put-text-property s (1- (point)) 'org-date-line t)
  3344. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3345. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3346. (when todayp
  3347. (put-text-property s (1- (point)) 'org-today t))
  3348. (if rtnall (insert
  3349. (org-finalize-agenda-entries
  3350. (org-agenda-add-time-grid-maybe
  3351. rtnall ndays todayp))
  3352. "\n"))
  3353. (put-text-property s (1- (point)) 'day d)
  3354. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3355. (when (and org-agenda-clockreport-mode clocktable-start)
  3356. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3357. ;; the above line is to ensure the restricted range!
  3358. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3359. tbl)
  3360. (setq p (org-plist-delete p :block))
  3361. (setq p (plist-put p :tstart clocktable-start))
  3362. (setq p (plist-put p :tend clocktable-end))
  3363. (setq p (plist-put p :scope 'agenda))
  3364. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3365. (setq filter (or org-agenda-filter-while-redo
  3366. (get 'org-agenda-filter :preset-filter))))
  3367. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3368. (if (string-match "[<>=]" x)
  3369. ""
  3370. x))
  3371. filter ""))))
  3372. (setq tbl (apply 'org-get-clocktable p))
  3373. (insert tbl)))
  3374. (goto-char (point-min))
  3375. (or org-agenda-multi (org-fit-agenda-window))
  3376. (unless (and (pos-visible-in-window-p (point-min))
  3377. (pos-visible-in-window-p (point-max)))
  3378. (goto-char (1- (point-max)))
  3379. (recenter -1)
  3380. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3381. (progn
  3382. (goto-char (or start-pos 1))
  3383. (recenter 1))))
  3384. (goto-char (or start-pos 1))
  3385. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3386. (if (eq org-agenda-show-log 'clockcheck)
  3387. (org-agenda-show-clocking-issues))
  3388. (org-finalize-agenda)
  3389. (setq buffer-read-only t)
  3390. (message "")))
  3391. (defun org-agenda-ndays-to-span (n)
  3392. "Return a span symbol for a span of N days, or N if none matches."
  3393. (cond ((symbolp n) n)
  3394. ((= n 1) 'day)
  3395. ((= n 7) 'week)
  3396. (t n)))
  3397. (defun org-agenda-span-to-ndays (span start-day)
  3398. "Return ndays from SPAN starting at START-DAY."
  3399. (cond ((numberp span) span)
  3400. ((eq span 'day) 1)
  3401. ((eq span 'week) 7)
  3402. ((eq span 'month)
  3403. (let ((date (calendar-gregorian-from-absolute start-day)))
  3404. (calendar-last-day-of-month (car date) (caddr date))))
  3405. ((eq span 'year)
  3406. (let ((date (calendar-gregorian-from-absolute start-day)))
  3407. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3408. (defun org-agenda-span-name (span)
  3409. "Return a SPAN name."
  3410. (if (null span)
  3411. ""
  3412. (if (symbolp span)
  3413. (capitalize (symbol-name span))
  3414. (format "%d days" span))))
  3415. ;;; Agenda word search
  3416. (defvar org-agenda-search-history nil)
  3417. (defvar org-todo-only nil)
  3418. (defvar org-search-syntax-table nil
  3419. "Special syntax table for org-mode search.
  3420. In this table, we have single quotes not as word constituents, to
  3421. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3422. (defun org-search-syntax-table ()
  3423. (unless org-search-syntax-table
  3424. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3425. (modify-syntax-entry ?' "." org-search-syntax-table)
  3426. (modify-syntax-entry ?` "." org-search-syntax-table))
  3427. org-search-syntax-table)
  3428. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3429. ;;;###autoload
  3430. (defun org-search-view (&optional todo-only string edit-at)
  3431. "Show all entries that contain a phrase or words or regular expressions.
  3432. With optional prefix argument TODO-ONLY, only consider entries that are
  3433. TODO entries. The argument STRING can be used to pass a default search
  3434. string into this function. If EDIT-AT is non-nil, it means that the
  3435. user should get a chance to edit this string, with cursor at position
  3436. EDIT-AT.
  3437. The search string can be viewed either as a phrase that should be found as
  3438. is, or it can be broken into a number of snippets, each of which must match
  3439. in a Boolean way to select an entry. The default depends on the variable
  3440. `org-agenda-search-view-always-boolean'.
  3441. Even if this is turned off (the default) you can always switch to
  3442. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3443. The default is a direct search of the whole phrase, where each space in
  3444. the search string can expand to an arbitrary amount of whitespace,
  3445. including newlines.
  3446. If using a Boolean search, the search string is split on whitespace and
  3447. each snippet is searched separately, with logical AND to select an entry.
  3448. Words prefixed with a minus must *not* occur in the entry. Words without
  3449. a prefix or prefixed with a plus must occur in the entry. Matching is
  3450. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3451. match whole words, not parts of a word) if
  3452. `org-agenda-search-view-force-full-words' is set (default is nil).
  3453. Boolean search snippets enclosed by curly braces are interpreted as
  3454. regular expressions that must or (when preceded with \"-\") must not
  3455. match in the entry. Snippets enclosed into double quotes will be taken
  3456. as a whole, to include whitespace.
  3457. - If the search string starts with an asterisk, search only in headlines.
  3458. - If (possibly after the leading star) the search string starts with an
  3459. exclamation mark, this also means to look at TODO entries only, an effect
  3460. that can also be achieved with a prefix argument.
  3461. - If (possibly after star and exclamation mark) the search string starts
  3462. with a colon, this will mean that the (non-regexp) snippets of the
  3463. Boolean search must match as full words.
  3464. This command searches the agenda files, and in addition the files listed
  3465. in `org-agenda-text-search-extra-files'."
  3466. (interactive "P")
  3467. (org-compile-prefix-format 'search)
  3468. (org-set-sorting-strategy 'search)
  3469. (org-prepare-agenda "SEARCH")
  3470. (let* ((props (list 'face nil
  3471. 'done-face 'org-agenda-done
  3472. 'org-not-done-regexp org-not-done-regexp
  3473. 'org-todo-regexp org-todo-regexp
  3474. 'org-complex-heading-regexp org-complex-heading-regexp
  3475. 'mouse-face 'highlight
  3476. 'help-echo (format "mouse-2 or RET jump to location")))
  3477. (full-words org-agenda-search-view-force-full-words)
  3478. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3479. regexp rtn rtnall files file pos
  3480. marker category org-category-pos tags c neg re boolean
  3481. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3482. (unless (and (not edit-at)
  3483. (stringp string)
  3484. (string-match "\\S-" string))
  3485. (setq string (read-string
  3486. (if org-agenda-search-view-always-boolean
  3487. "[+-]Word/{Regexp} ...: "
  3488. "Phrase, or [+-]Word/{Regexp} ...: ")
  3489. (cond
  3490. ((integerp edit-at) (cons string edit-at))
  3491. (edit-at string))
  3492. 'org-agenda-search-history)))
  3493. (org-set-local 'org-todo-only todo-only)
  3494. (setq org-agenda-redo-command
  3495. (list 'org-search-view (if todo-only t nil) string
  3496. '(if current-prefix-arg 1 nil)))
  3497. (setq org-agenda-query-string string)
  3498. (if (equal (string-to-char string) ?*)
  3499. (setq hdl-only t
  3500. words (substring string 1))
  3501. (setq words string))
  3502. (when (equal (string-to-char words) ?!)
  3503. (setq todo-only t
  3504. words (substring words 1)))
  3505. (when (equal (string-to-char words) ?:)
  3506. (setq full-words t
  3507. words (substring words 1)))
  3508. (if (or org-agenda-search-view-always-boolean
  3509. (member (string-to-char words) '(?- ?+ ?\{)))
  3510. (setq boolean t))
  3511. (setq words (org-split-string words))
  3512. (let (www w)
  3513. (while (setq w (pop words))
  3514. (while (and (string-match "\\\\\\'" w) words)
  3515. (setq w (concat (substring w 0 -1) " " (pop words))))
  3516. (push w www))
  3517. (setq words (nreverse www) www nil)
  3518. (while (setq w (pop words))
  3519. (when (and (string-match "\\`[-+]?{" w)
  3520. (not (string-match "}\\'" w)))
  3521. (while (and words (not (string-match "}\\'" (car words))))
  3522. (setq w (concat w " " (pop words))))
  3523. (setq w (concat w " " (pop words))))
  3524. (push w www))
  3525. (setq words (nreverse www)))
  3526. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3527. (when boolean
  3528. (let (wds w)
  3529. (while (setq w (pop words))
  3530. (if (or (equal (substring w 0 1) "\"")
  3531. (and (> (length w) 1)
  3532. (member (substring w 0 1) '("+" "-"))
  3533. (equal (substring w 1 2) "\"")))
  3534. (while (and words (not (equal (substring w -1) "\"")))
  3535. (setq w (concat w " " (pop words)))))
  3536. (and (string-match "\\`\\([-+]?\\)\"" w)
  3537. (setq w (replace-match "\\1" nil nil w)))
  3538. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3539. (push w wds))
  3540. (setq words (nreverse wds))))
  3541. (if boolean
  3542. (mapc (lambda (w)
  3543. (setq c (string-to-char w))
  3544. (if (equal c ?-)
  3545. (setq neg t w (substring w 1))
  3546. (if (equal c ?+)
  3547. (setq neg nil w (substring w 1))
  3548. (setq neg nil)))
  3549. (if (string-match "\\`{.*}\\'" w)
  3550. (setq re (substring w 1 -1))
  3551. (if full-words
  3552. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3553. (setq re (regexp-quote (downcase w)))))
  3554. (if neg (push re regexps-) (push re regexps+)))
  3555. words)
  3556. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3557. regexps+))
  3558. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3559. (if (not regexps+)
  3560. (setq regexp org-outline-regexp-bol)
  3561. (setq regexp (pop regexps+))
  3562. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3563. regexp))))
  3564. (setq files (org-agenda-files nil 'ifmode))
  3565. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3566. (pop org-agenda-text-search-extra-files)
  3567. (setq files (org-add-archive-files files)))
  3568. (setq files (append files org-agenda-text-search-extra-files)
  3569. rtnall nil)
  3570. (while (setq file (pop files))
  3571. (setq ee nil)
  3572. (catch 'nextfile
  3573. (org-check-agenda-file file)
  3574. (setq buffer (if (file-exists-p file)
  3575. (org-get-agenda-file-buffer file)
  3576. (error "No such file %s" file)))
  3577. (if (not buffer)
  3578. ;; If file does not exist, make sure an error message is sent
  3579. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3580. file))))
  3581. (with-current-buffer buffer
  3582. (with-syntax-table (org-search-syntax-table)
  3583. (unless (eq major-mode 'org-mode)
  3584. (error "Agenda file %s is not in `org-mode'" file))
  3585. (let ((case-fold-search t))
  3586. (save-excursion
  3587. (save-restriction
  3588. (if org-agenda-restrict
  3589. (narrow-to-region org-agenda-restrict-begin
  3590. org-agenda-restrict-end)
  3591. (widen))
  3592. (goto-char (point-min))
  3593. (unless (or (org-on-heading-p)
  3594. (outline-next-heading))
  3595. (throw 'nextfile t))
  3596. (goto-char (max (point-min) (1- (point))))
  3597. (while (re-search-forward regexp nil t)
  3598. (org-back-to-heading t)
  3599. (skip-chars-forward "* ")
  3600. (setq beg (point-at-bol)
  3601. beg1 (point)
  3602. end (progn (outline-next-heading) (point)))
  3603. (catch :skip
  3604. (goto-char beg)
  3605. (org-agenda-skip)
  3606. (setq str (buffer-substring-no-properties
  3607. (point-at-bol)
  3608. (if hdl-only (point-at-eol) end)))
  3609. (mapc (lambda (wr) (when (string-match wr str)
  3610. (goto-char (1- end))
  3611. (throw :skip t)))
  3612. regexps-)
  3613. (mapc (lambda (wr) (unless (string-match wr str)
  3614. (goto-char (1- end))
  3615. (throw :skip t)))
  3616. (if todo-only
  3617. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3618. regexps+)
  3619. regexps+))
  3620. (goto-char beg)
  3621. (setq marker (org-agenda-new-marker (point))
  3622. category (org-get-category)
  3623. org-category-pos (get-text-property (point) 'org-category-position)
  3624. tags (org-get-tags-at (point))
  3625. txt (org-agenda-format-item
  3626. ""
  3627. (buffer-substring-no-properties
  3628. beg1 (point-at-eol))
  3629. category tags))
  3630. (org-add-props txt props
  3631. 'org-marker marker 'org-hd-marker marker
  3632. 'org-todo-regexp org-todo-regexp
  3633. 'org-complex-heading-regexp org-complex-heading-regexp
  3634. 'priority 1000 'org-category category
  3635. 'org-category-position org-category-pos
  3636. 'type "search")
  3637. (push txt ee)
  3638. (goto-char (1- end))))))))))
  3639. (setq rtn (nreverse ee))
  3640. (setq rtnall (append rtnall rtn)))
  3641. (if org-agenda-overriding-header
  3642. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3643. nil 'face 'org-agenda-structure) "\n")
  3644. (insert "Search words: ")
  3645. (add-text-properties (point-min) (1- (point))
  3646. (list 'face 'org-agenda-structure))
  3647. (setq pos (point))
  3648. (insert string "\n")
  3649. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3650. (setq pos (point))
  3651. (unless org-agenda-multi
  3652. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3653. (add-text-properties pos (1- (point))
  3654. (list 'face 'org-agenda-structure))))
  3655. (org-agenda-mark-header-line (point-min))
  3656. (when rtnall
  3657. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3658. (goto-char (point-min))
  3659. (or org-agenda-multi (org-fit-agenda-window))
  3660. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3661. (org-finalize-agenda)
  3662. (setq buffer-read-only t)))
  3663. ;;; Agenda TODO list
  3664. (defvar org-select-this-todo-keyword nil)
  3665. (defvar org-last-arg nil)
  3666. ;;;###autoload
  3667. (defun org-todo-list (arg)
  3668. "Show all (not done) TODO entries from all agenda file in a single list.
  3669. The prefix arg can be used to select a specific TODO keyword and limit
  3670. the list to these. When using \\[universal-argument], you will be prompted
  3671. for a keyword. A numeric prefix directly selects the Nth keyword in
  3672. `org-todo-keywords-1'."
  3673. (interactive "P")
  3674. (org-compile-prefix-format 'todo)
  3675. (org-set-sorting-strategy 'todo)
  3676. (org-prepare-agenda "TODO")
  3677. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3678. (let* ((today (org-today))
  3679. (date (calendar-gregorian-from-absolute today))
  3680. (kwds org-todo-keywords-for-agenda)
  3681. (completion-ignore-case t)
  3682. (org-select-this-todo-keyword
  3683. (if (stringp arg) arg
  3684. (and arg (integerp arg) (> arg 0)
  3685. (nth (1- arg) kwds))))
  3686. rtn rtnall files file pos)
  3687. (when (equal arg '(4))
  3688. (setq org-select-this-todo-keyword
  3689. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3690. (mapcar 'list kwds) nil nil)))
  3691. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3692. (org-set-local 'org-last-arg arg)
  3693. (setq org-agenda-redo-command
  3694. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3695. (setq files (org-agenda-files nil 'ifmode)
  3696. rtnall nil)
  3697. (while (setq file (pop files))
  3698. (catch 'nextfile
  3699. (org-check-agenda-file file)
  3700. (setq rtn (org-agenda-get-day-entries file date :todo))
  3701. (setq rtnall (append rtnall rtn))))
  3702. (if org-agenda-overriding-header
  3703. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3704. nil 'face 'org-agenda-structure) "\n")
  3705. (insert "Global list of TODO items of type: ")
  3706. (add-text-properties (point-min) (1- (point))
  3707. (list 'face 'org-agenda-structure
  3708. 'short-heading
  3709. (concat "ToDo: "
  3710. (or org-select-this-todo-keyword "ALL"))))
  3711. (org-agenda-mark-header-line (point-min))
  3712. (setq pos (point))
  3713. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3714. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3715. (setq pos (point))
  3716. (unless org-agenda-multi
  3717. (insert "Available with `N r': (0)ALL")
  3718. (let ((n 0) s)
  3719. (mapc (lambda (x)
  3720. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3721. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3722. (insert "\n "))
  3723. (insert " " s))
  3724. kwds))
  3725. (insert "\n"))
  3726. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3727. (org-agenda-mark-header-line (point-min))
  3728. (when rtnall
  3729. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3730. (goto-char (point-min))
  3731. (or org-agenda-multi (org-fit-agenda-window))
  3732. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3733. (org-finalize-agenda)
  3734. (setq buffer-read-only t)))
  3735. ;;; Agenda tags match
  3736. ;;;###autoload
  3737. (defun org-tags-view (&optional todo-only match)
  3738. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3739. The prefix arg TODO-ONLY limits the search to TODO entries."
  3740. (interactive "P")
  3741. (org-compile-prefix-format 'tags)
  3742. (org-set-sorting-strategy 'tags)
  3743. (let* ((org-tags-match-list-sublevels
  3744. org-tags-match-list-sublevels)
  3745. (completion-ignore-case t)
  3746. rtn rtnall files file pos matcher
  3747. buffer)
  3748. (when (and (stringp match) (not (string-match "\\S-" match)))
  3749. (setq match nil))
  3750. (setq matcher (org-make-tags-matcher match)
  3751. match (car matcher) matcher (cdr matcher))
  3752. (org-prepare-agenda (concat "TAGS " match))
  3753. (setq org-agenda-query-string match)
  3754. (setq org-agenda-redo-command
  3755. (list 'org-tags-view (list 'quote todo-only)
  3756. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3757. (setq files (org-agenda-files nil 'ifmode)
  3758. rtnall nil)
  3759. (while (setq file (pop files))
  3760. (catch 'nextfile
  3761. (org-check-agenda-file file)
  3762. (setq buffer (if (file-exists-p file)
  3763. (org-get-agenda-file-buffer file)
  3764. (error "No such file %s" file)))
  3765. (if (not buffer)
  3766. ;; If file does not exist, error message to agenda
  3767. (setq rtn (list
  3768. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3769. rtnall (append rtnall rtn))
  3770. (with-current-buffer buffer
  3771. (unless (eq major-mode 'org-mode)
  3772. (error "Agenda file %s is not in `org-mode'" file))
  3773. (save-excursion
  3774. (save-restriction
  3775. (if org-agenda-restrict
  3776. (narrow-to-region org-agenda-restrict-begin
  3777. org-agenda-restrict-end)
  3778. (widen))
  3779. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3780. (setq rtnall (append rtnall rtn))))))))
  3781. (if org-agenda-overriding-header
  3782. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3783. nil 'face 'org-agenda-structure) "\n")
  3784. (insert "Headlines with TAGS match: ")
  3785. (add-text-properties (point-min) (1- (point))
  3786. (list 'face 'org-agenda-structure
  3787. 'short-heading
  3788. (concat "Match: " match)))
  3789. (setq pos (point))
  3790. (insert match "\n")
  3791. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3792. (setq pos (point))
  3793. (unless org-agenda-multi
  3794. (insert "Press `C-u r' to search again with new search string\n"))
  3795. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3796. (org-agenda-mark-header-line (point-min))
  3797. (when rtnall
  3798. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3799. (goto-char (point-min))
  3800. (or org-agenda-multi (org-fit-agenda-window))
  3801. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3802. (org-finalize-agenda)
  3803. (setq buffer-read-only t)))
  3804. ;;; Agenda Finding stuck projects
  3805. (defvar org-agenda-skip-regexp nil
  3806. "Regular expression used in skipping subtrees for the agenda.
  3807. This is basically a temporary global variable that can be set and then
  3808. used by user-defined selections using `org-agenda-skip-function'.")
  3809. (defvar org-agenda-overriding-header nil
  3810. "When set during agenda, todo and tags searches it replaces the header.
  3811. This variable should not be set directly, but custom commands can bind it
  3812. in the options section.")
  3813. (defun org-agenda-skip-entry-when-regexp-matches ()
  3814. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3815. If yes, it returns the end position of this entry, causing agenda commands
  3816. to skip the entry but continuing the search in the subtree. This is a
  3817. function that can be put into `org-agenda-skip-function' for the duration
  3818. of a command."
  3819. (let ((end (save-excursion (org-end-of-subtree t)))
  3820. skip)
  3821. (save-excursion
  3822. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3823. (and skip end)))
  3824. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3825. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3826. If yes, it returns the end position of this tree, causing agenda commands
  3827. to skip this subtree. This is a function that can be put into
  3828. `org-agenda-skip-function' for the duration of a command."
  3829. (let ((end (save-excursion (org-end-of-subtree t)))
  3830. skip)
  3831. (save-excursion
  3832. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3833. (and skip end)))
  3834. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3835. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3836. If yes, it returns the end position of the current entry (NOT the tree),
  3837. causing agenda commands to skip the entry but continuing the search in
  3838. the subtree. This is a function that can be put into
  3839. `org-agenda-skip-function' for the duration of a command. An important
  3840. use of this function is for the stuck project list."
  3841. (let ((end (save-excursion (org-end-of-subtree t)))
  3842. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3843. skip)
  3844. (save-excursion
  3845. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3846. (and skip entry-end)))
  3847. (defun org-agenda-skip-entry-if (&rest conditions)
  3848. "Skip entry if any of CONDITIONS is true.
  3849. See `org-agenda-skip-if' for details."
  3850. (org-agenda-skip-if nil conditions))
  3851. (defun org-agenda-skip-subtree-if (&rest conditions)
  3852. "Skip entry if any of CONDITIONS is true.
  3853. See `org-agenda-skip-if' for details."
  3854. (org-agenda-skip-if t conditions))
  3855. (defun org-agenda-skip-if (subtree conditions)
  3856. "Checks current entity for CONDITIONS.
  3857. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3858. the entry, i.e. the text before the next heading is checked.
  3859. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3860. from different tests. Valid conditions are:
  3861. scheduled Check if there is a scheduled cookie
  3862. notscheduled Check if there is no scheduled cookie
  3863. deadline Check if there is a deadline
  3864. notdeadline Check if there is no deadline
  3865. timestamp Check if there is a timestamp (also deadline or scheduled)
  3866. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3867. regexp Check if regexp matches
  3868. notregexp Check if regexp does not match.
  3869. todo Check if TODO keyword matches
  3870. nottodo Check if TODO keyword does not match
  3871. The regexp is taken from the conditions list, it must come right after
  3872. the `regexp' or `notregexp' element.
  3873. `todo' and `nottodo' accept as an argument a list of todo
  3874. keywords, which may include \"*\" to match any todo keyword.
  3875. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  3876. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  3877. Instead of a list a keyword class may be given
  3878. (org-agenda-skip-entry-if 'nottodo 'done)
  3879. would skip entries that haven't been marked with any of \"DONE\"
  3880. keywords. Possible classes are: `todo', `done', `any'.
  3881. If any of these conditions is met, this function returns the end point of
  3882. the entity, causing the search to continue from there. This is a function
  3883. that can be put into `org-agenda-skip-function' for the duration of a command."
  3884. (let (beg end m)
  3885. (org-back-to-heading t)
  3886. (setq beg (point)
  3887. end (if subtree
  3888. (progn (org-end-of-subtree t) (point))
  3889. (progn (outline-next-heading) (1- (point)))))
  3890. (goto-char beg)
  3891. (and
  3892. (or
  3893. (and (memq 'scheduled conditions)
  3894. (re-search-forward org-scheduled-time-regexp end t))
  3895. (and (memq 'notscheduled conditions)
  3896. (not (re-search-forward org-scheduled-time-regexp end t)))
  3897. (and (memq 'deadline conditions)
  3898. (re-search-forward org-deadline-time-regexp end t))
  3899. (and (memq 'notdeadline conditions)
  3900. (not (re-search-forward org-deadline-time-regexp end t)))
  3901. (and (memq 'timestamp conditions)
  3902. (re-search-forward org-ts-regexp end t))
  3903. (and (memq 'nottimestamp conditions)
  3904. (not (re-search-forward org-ts-regexp end t)))
  3905. (and (setq m (memq 'regexp conditions))
  3906. (stringp (nth 1 m))
  3907. (re-search-forward (nth 1 m) end t))
  3908. (and (setq m (memq 'notregexp conditions))
  3909. (stringp (nth 1 m))
  3910. (not (re-search-forward (nth 1 m) end t)))
  3911. (and (or
  3912. (setq m (memq 'todo conditions))
  3913. (setq m (memq 'nottodo conditions)))
  3914. (org-agenda-skip-if-todo m end)))
  3915. end)))
  3916. (defun org-agenda-skip-if-todo (args end)
  3917. "Helper function for `org-agenda-skip-if', do not use it directly.
  3918. ARGS is a list with first element either `todo' or `nottodo'.
  3919. The remainder is either a list of TODO keywords, or a state symbol
  3920. `todo' or `done' or `any'."
  3921. (let ((kw (car args))
  3922. (arg (cadr args))
  3923. todo-wds todo-re)
  3924. (setq todo-wds
  3925. (org-uniquify
  3926. (cond
  3927. ((listp arg) ;; list of keywords
  3928. (if (member "*" arg)
  3929. (mapcar 'substring-no-properties org-todo-keywords-1)
  3930. arg))
  3931. ((symbolp arg) ;; keyword class name
  3932. (cond
  3933. ((eq arg 'todo)
  3934. (org-delete-all org-done-keywords
  3935. (mapcar 'substring-no-properties
  3936. org-todo-keywords-1)))
  3937. ((eq arg 'done) org-done-keywords)
  3938. ((eq arg 'any)
  3939. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  3940. (setq todo-re
  3941. (concat "^\\*+[ \t]+\\<\\("
  3942. (mapconcat 'identity todo-wds "\\|")
  3943. "\\)\\>"))
  3944. (if (eq kw 'todo)
  3945. (re-search-forward todo-re end t)
  3946. (not (re-search-forward todo-re end t)))))
  3947. ;;;###autoload
  3948. (defun org-agenda-list-stuck-projects (&rest ignore)
  3949. "Create agenda view for projects that are stuck.
  3950. Stuck projects are project that have no next actions. For the definitions
  3951. of what a project is and how to check if it stuck, customize the variable
  3952. `org-stuck-projects'."
  3953. (interactive)
  3954. (let* ((org-agenda-skip-function
  3955. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3956. ;; We could have used org-agenda-skip-if here.
  3957. (org-agenda-overriding-header
  3958. (or org-agenda-overriding-header "List of stuck projects: "))
  3959. (matcher (nth 0 org-stuck-projects))
  3960. (todo (nth 1 org-stuck-projects))
  3961. (todo-wds (if (member "*" todo)
  3962. (progn
  3963. (org-prepare-agenda-buffers (org-agenda-files
  3964. nil 'ifmode))
  3965. (org-delete-all
  3966. org-done-keywords-for-agenda
  3967. (copy-sequence org-todo-keywords-for-agenda)))
  3968. todo))
  3969. (todo-re (concat "^\\*+[ \t]+\\("
  3970. (mapconcat 'identity todo-wds "\\|")
  3971. "\\)\\>"))
  3972. (tags (nth 2 org-stuck-projects))
  3973. (tags-re (if (member "*" tags)
  3974. (concat org-outline-regexp-bol
  3975. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  3976. (if tags
  3977. (concat org-outline-regexp-bol
  3978. ".*:\\("
  3979. (mapconcat 'identity tags "\\|")
  3980. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  3981. (gen-re (nth 3 org-stuck-projects))
  3982. (re-list
  3983. (delq nil
  3984. (list
  3985. (if todo todo-re)
  3986. (if tags tags-re)
  3987. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3988. gen-re)))))
  3989. (setq org-agenda-skip-regexp
  3990. (if re-list
  3991. (mapconcat 'identity re-list "\\|")
  3992. (error "No information how to identify unstuck projects")))
  3993. (org-tags-view nil matcher)
  3994. (with-current-buffer org-agenda-buffer-name
  3995. (setq org-agenda-redo-command
  3996. '(org-agenda-list-stuck-projects
  3997. (or current-prefix-arg org-last-arg))))))
  3998. ;;; Diary integration
  3999. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4000. (defvar list-diary-entries-hook)
  4001. (defvar diary-time-regexp)
  4002. (defun org-get-entries-from-diary (date)
  4003. "Get the (Emacs Calendar) diary entries for DATE."
  4004. (require 'diary-lib)
  4005. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4006. (diary-display-hook '(fancy-diary-display))
  4007. (diary-display-function 'fancy-diary-display)
  4008. (pop-up-frames nil)
  4009. (list-diary-entries-hook
  4010. (cons 'org-diary-default-entry list-diary-entries-hook))
  4011. (diary-file-name-prefix-function nil) ; turn this feature off
  4012. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4013. entries
  4014. (org-disable-agenda-to-diary t))
  4015. (save-excursion
  4016. (save-window-excursion
  4017. (funcall (if (fboundp 'diary-list-entries)
  4018. 'diary-list-entries 'list-diary-entries)
  4019. date 1)))
  4020. (if (not (get-buffer diary-fancy-buffer))
  4021. (setq entries nil)
  4022. (with-current-buffer diary-fancy-buffer
  4023. (setq buffer-read-only nil)
  4024. (if (zerop (buffer-size))
  4025. ;; No entries
  4026. (setq entries nil)
  4027. ;; Omit the date and other unnecessary stuff
  4028. (org-agenda-cleanup-fancy-diary)
  4029. ;; Add prefix to each line and extend the text properties
  4030. (if (zerop (buffer-size))
  4031. (setq entries nil)
  4032. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4033. (setq entries
  4034. (with-temp-buffer
  4035. (insert entries) (goto-char (point-min))
  4036. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4037. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4038. (replace-match (concat "; " (match-string 1)))))
  4039. (buffer-string)))))
  4040. (set-buffer-modified-p nil)
  4041. (kill-buffer diary-fancy-buffer)))
  4042. (when entries
  4043. (setq entries (org-split-string entries "\n"))
  4044. (setq entries
  4045. (mapcar
  4046. (lambda (x)
  4047. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4048. ;; Extend the text properties to the beginning of the line
  4049. (org-add-props x (text-properties-at (1- (length x)) x)
  4050. 'type "diary" 'date date 'face 'org-agenda-diary))
  4051. entries)))))
  4052. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4053. "Hook run when the fancy diary buffer is cleaned up.")
  4054. (defun org-agenda-cleanup-fancy-diary ()
  4055. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4056. This gets rid of the date, the underline under the date, and
  4057. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4058. date. It also removes lines that contain only whitespace."
  4059. (goto-char (point-min))
  4060. (if (looking-at ".*?:[ \t]*")
  4061. (progn
  4062. (replace-match "")
  4063. (re-search-forward "\n=+$" nil t)
  4064. (replace-match "")
  4065. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4066. (re-search-forward "\n=+$" nil t)
  4067. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4068. (goto-char (point-min))
  4069. (while (re-search-forward "^ +\n" nil t)
  4070. (replace-match ""))
  4071. (goto-char (point-min))
  4072. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4073. (replace-match ""))
  4074. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4075. ;; Make sure entries from the diary have the right text properties.
  4076. (eval-after-load "diary-lib"
  4077. '(if (boundp 'diary-modify-entry-list-string-function)
  4078. ;; We can rely on the hook, nothing to do
  4079. nil
  4080. ;; Hook not available, must use advice to make this work
  4081. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4082. "Make the position visible."
  4083. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4084. (stringp string)
  4085. buffer-file-name)
  4086. (setq string (org-modify-diary-entry-string string))))))
  4087. (defun org-modify-diary-entry-string (string)
  4088. "Add text properties to string, allowing org-mode to act on it."
  4089. (org-add-props string nil
  4090. 'mouse-face 'highlight
  4091. 'help-echo (if buffer-file-name
  4092. (format "mouse-2 or RET jump to diary file %s"
  4093. (abbreviate-file-name buffer-file-name))
  4094. "")
  4095. 'org-agenda-diary-link t
  4096. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4097. (defun org-diary-default-entry ()
  4098. "Add a dummy entry to the diary.
  4099. Needed to avoid empty dates which mess up holiday display."
  4100. ;; Catch the error if dealing with the new add-to-diary-alist
  4101. (when org-disable-agenda-to-diary
  4102. (condition-case nil
  4103. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4104. (error
  4105. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4106. (defun org-add-to-diary-list (&rest args)
  4107. (if (fboundp 'diary-add-to-list)
  4108. (apply 'diary-add-to-list args)
  4109. (apply 'add-to-diary-list args)))
  4110. (defvar org-diary-last-run-time nil)
  4111. ;;;###autoload
  4112. (defun org-diary (&rest args)
  4113. "Return diary information from org-files.
  4114. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4115. It accesses org files and extracts information from those files to be
  4116. listed in the diary. The function accepts arguments specifying what
  4117. items should be listed. For a list of arguments allowed here, see the
  4118. variable `org-agenda-entry-types'.
  4119. The call in the diary file should look like this:
  4120. &%%(org-diary) ~/path/to/some/orgfile.org
  4121. Use a separate line for each org file to check. Or, if you omit the file name,
  4122. all files listed in `org-agenda-files' will be checked automatically:
  4123. &%%(org-diary)
  4124. If you don't give any arguments (as in the example above), the default
  4125. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4126. So the example above may also be written as
  4127. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4128. The function expects the lisp variables `entry' and `date' to be provided
  4129. by the caller, because this is how the calendar works. Don't use this
  4130. function from a program - use `org-agenda-get-day-entries' instead."
  4131. (when (> (- (org-float-time)
  4132. org-agenda-last-marker-time)
  4133. 5)
  4134. (org-agenda-reset-markers))
  4135. (org-compile-prefix-format 'agenda)
  4136. (org-set-sorting-strategy 'agenda)
  4137. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4138. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4139. (list entry)
  4140. (org-agenda-files t)))
  4141. (time (org-float-time))
  4142. file rtn results)
  4143. (when (or (not org-diary-last-run-time)
  4144. (> (- time
  4145. org-diary-last-run-time)
  4146. 3))
  4147. (org-prepare-agenda-buffers files))
  4148. (setq org-diary-last-run-time time)
  4149. ;; If this is called during org-agenda, don't return any entries to
  4150. ;; the calendar. Org Agenda will list these entries itself.
  4151. (if org-disable-agenda-to-diary (setq files nil))
  4152. (while (setq file (pop files))
  4153. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4154. (setq results (append results rtn)))
  4155. (if results
  4156. (concat (org-finalize-agenda-entries results) "\n"))))
  4157. ;;; Agenda entry finders
  4158. (defun org-agenda-get-day-entries (file date &rest args)
  4159. "Does the work for `org-diary' and `org-agenda'.
  4160. FILE is the path to a file to be checked for entries. DATE is date like
  4161. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4162. which kind of entries should be extracted. For details about these, see
  4163. the documentation of `org-diary'."
  4164. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4165. (let* ((org-startup-folded nil)
  4166. (org-startup-align-all-tables nil)
  4167. (buffer (if (file-exists-p file)
  4168. (org-get-agenda-file-buffer file)
  4169. (error "No such file %s" file)))
  4170. arg results rtn deadline-results)
  4171. (if (not buffer)
  4172. ;; If file does not exist, make sure an error message ends up in diary
  4173. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4174. (with-current-buffer buffer
  4175. (unless (eq major-mode 'org-mode)
  4176. (error "Agenda file %s is not in `org-mode'" file))
  4177. (let ((case-fold-search nil))
  4178. (save-excursion
  4179. (save-restriction
  4180. (if org-agenda-restrict
  4181. (narrow-to-region org-agenda-restrict-begin
  4182. org-agenda-restrict-end)
  4183. (widen))
  4184. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4185. (while (setq arg (pop args))
  4186. (cond
  4187. ((and (eq arg :todo)
  4188. (equal date (calendar-gregorian-from-absolute
  4189. (org-today))))
  4190. (setq rtn (org-agenda-get-todos))
  4191. (setq results (append results rtn)))
  4192. ((eq arg :timestamp)
  4193. (setq rtn (org-agenda-get-blocks))
  4194. (setq results (append results rtn))
  4195. (setq rtn (org-agenda-get-timestamps))
  4196. (setq results (append results rtn)))
  4197. ((eq arg :sexp)
  4198. (setq rtn (org-agenda-get-sexps))
  4199. (setq results (append results rtn)))
  4200. ((eq arg :scheduled)
  4201. (setq rtn (org-agenda-get-scheduled deadline-results))
  4202. (setq results (append results rtn)))
  4203. ((eq arg :closed)
  4204. (setq rtn (org-agenda-get-progress))
  4205. (setq results (append results rtn)))
  4206. ((eq arg :deadline)
  4207. (setq rtn (org-agenda-get-deadlines))
  4208. (setq deadline-results (copy-sequence rtn))
  4209. (setq results (append results rtn))))))))
  4210. results))))
  4211. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4212. (defun org-agenda-get-todos ()
  4213. "Return the TODO information for agenda display."
  4214. (let* ((props (list 'face nil
  4215. 'done-face 'org-agenda-done
  4216. 'org-not-done-regexp org-not-done-regexp
  4217. 'org-todo-regexp org-todo-regexp
  4218. 'org-complex-heading-regexp org-complex-heading-regexp
  4219. 'mouse-face 'highlight
  4220. 'help-echo
  4221. (format "mouse-2 or RET jump to org file %s"
  4222. (abbreviate-file-name buffer-file-name))))
  4223. (regexp (format org-heading-keyword-regexp-format
  4224. (cond
  4225. ((and org-select-this-todo-keyword
  4226. (equal org-select-this-todo-keyword "*"))
  4227. org-todo-regexp)
  4228. (org-select-this-todo-keyword
  4229. (concat "\\("
  4230. (mapconcat 'identity
  4231. (org-split-string
  4232. org-select-this-todo-keyword
  4233. "|")
  4234. "\\|") "\\)"))
  4235. (t org-not-done-regexp))))
  4236. marker priority category org-category-pos tags todo-state
  4237. ee txt beg end)
  4238. (goto-char (point-min))
  4239. (while (re-search-forward regexp nil t)
  4240. (catch :skip
  4241. (save-match-data
  4242. (beginning-of-line)
  4243. (org-agenda-skip)
  4244. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4245. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4246. (goto-char (1+ beg))
  4247. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4248. (throw :skip nil)))
  4249. (goto-char (match-beginning 2))
  4250. (setq marker (org-agenda-new-marker (match-beginning 0))
  4251. category (org-get-category)
  4252. org-category-pos (get-text-property (point) 'org-category-position)
  4253. txt (org-trim
  4254. (buffer-substring (match-beginning 2) (match-end 0)))
  4255. tags (org-get-tags-at (point))
  4256. txt (org-agenda-format-item "" txt category tags)
  4257. priority (1+ (org-get-priority txt))
  4258. todo-state (org-get-todo-state))
  4259. (org-add-props txt props
  4260. 'org-marker marker 'org-hd-marker marker
  4261. 'priority priority 'org-category category
  4262. 'org-category-position org-category-pos
  4263. 'type "todo" 'todo-state todo-state)
  4264. (push txt ee)
  4265. (if org-agenda-todo-list-sublevels
  4266. (goto-char (match-end 2))
  4267. (org-end-of-subtree 'invisible))))
  4268. (nreverse ee)))
  4269. (defun org-agenda-todo-custom-ignore-p (time n)
  4270. "Check whether timestamp is farther away then n number of days.
  4271. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4272. `org-agenda-todo-ignore-scheduled' or
  4273. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4274. (let ((days (org-days-to-time time)))
  4275. (if (>= n 0)
  4276. (>= days n)
  4277. (<= days n))))
  4278. ;;;###autoload
  4279. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4280. (&optional end)
  4281. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4282. (when (or org-agenda-todo-ignore-with-date
  4283. org-agenda-todo-ignore-scheduled
  4284. org-agenda-todo-ignore-deadlines
  4285. org-agenda-todo-ignore-timestamp)
  4286. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4287. (save-excursion
  4288. (or (and org-agenda-todo-ignore-with-date
  4289. (re-search-forward org-ts-regexp end t))
  4290. (and org-agenda-todo-ignore-scheduled
  4291. (re-search-forward org-scheduled-time-regexp end t)
  4292. (cond
  4293. ((eq org-agenda-todo-ignore-scheduled 'future)
  4294. (> (org-days-to-time (match-string 1)) 0))
  4295. ((eq org-agenda-todo-ignore-scheduled 'past)
  4296. (<= (org-days-to-time (match-string 1)) 0))
  4297. ((numberp org-agenda-todo-ignore-scheduled)
  4298. (org-agenda-todo-custom-ignore-p
  4299. (match-string 1) org-agenda-todo-ignore-scheduled))
  4300. (t)))
  4301. (and org-agenda-todo-ignore-deadlines
  4302. (re-search-forward org-deadline-time-regexp end t)
  4303. (cond
  4304. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4305. ((eq org-agenda-todo-ignore-deadlines 'far)
  4306. (not (org-deadline-close (match-string 1))))
  4307. ((eq org-agenda-todo-ignore-deadlines 'future)
  4308. (> (org-days-to-time (match-string 1)) 0))
  4309. ((eq org-agenda-todo-ignore-deadlines 'past)
  4310. (<= (org-days-to-time (match-string 1)) 0))
  4311. ((numberp org-agenda-todo-ignore-deadlines)
  4312. (org-agenda-todo-custom-ignore-p
  4313. (match-string 1) org-agenda-todo-ignore-deadlines))
  4314. (t (org-deadline-close (match-string 1)))))
  4315. (and org-agenda-todo-ignore-timestamp
  4316. (let ((buffer (current-buffer))
  4317. (regexp
  4318. (concat
  4319. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4320. (start (point)))
  4321. ;; Copy current buffer into a temporary one
  4322. (with-temp-buffer
  4323. (insert-buffer-substring buffer start end)
  4324. (goto-char (point-min))
  4325. ;; Delete SCHEDULED and DEADLINE items
  4326. (while (re-search-forward regexp end t)
  4327. (delete-region (match-beginning 0) (match-end 0)))
  4328. (goto-char (point-min))
  4329. ;; No search for timestamp left
  4330. (when (re-search-forward org-ts-regexp nil t)
  4331. (cond
  4332. ((eq org-agenda-todo-ignore-timestamp 'future)
  4333. (> (org-days-to-time (match-string 1)) 0))
  4334. ((eq org-agenda-todo-ignore-timestamp 'past)
  4335. (<= (org-days-to-time (match-string 1)) 0))
  4336. ((numberp org-agenda-todo-ignore-timestamp)
  4337. (org-agenda-todo-custom-ignore-p
  4338. (match-string 1) org-agenda-todo-ignore-timestamp))
  4339. (t))))))))))
  4340. (defconst org-agenda-no-heading-message
  4341. "No heading for this item in buffer or region.")
  4342. (defun org-agenda-get-timestamps ()
  4343. "Return the date stamp information for agenda display."
  4344. (let* ((props (list 'face nil
  4345. 'org-not-done-regexp org-not-done-regexp
  4346. 'org-todo-regexp org-todo-regexp
  4347. 'org-complex-heading-regexp org-complex-heading-regexp
  4348. 'mouse-face 'highlight
  4349. 'help-echo
  4350. (format "mouse-2 or RET jump to org file %s"
  4351. (abbreviate-file-name buffer-file-name))))
  4352. (d1 (calendar-absolute-from-gregorian date))
  4353. (remove-re
  4354. (concat
  4355. (regexp-quote
  4356. (format-time-string
  4357. "<%Y-%m-%d"
  4358. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4359. ".*?>"))
  4360. (regexp
  4361. (concat
  4362. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4363. (regexp-quote
  4364. (substring
  4365. (format-time-string
  4366. (car org-time-stamp-formats)
  4367. (apply 'encode-time ; DATE bound by calendar
  4368. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4369. 1 11))
  4370. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4371. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4372. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4373. donep tmp priority category org-category-pos ee txt timestr tags
  4374. b0 b3 e3 head todo-state end-of-match show-all)
  4375. (goto-char (point-min))
  4376. (while (setq end-of-match (re-search-forward regexp nil t))
  4377. (setq b0 (match-beginning 0)
  4378. b3 (match-beginning 3) e3 (match-end 3)
  4379. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4380. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4381. (member todo-state
  4382. org-agenda-repeating-timestamp-show-all)))
  4383. (catch :skip
  4384. (and (org-at-date-range-p) (throw :skip nil))
  4385. (org-agenda-skip)
  4386. (if (and (match-end 1)
  4387. (not (= d1 (org-time-string-to-absolute
  4388. (match-string 1) d1 nil show-all
  4389. (current-buffer) b0))))
  4390. (throw :skip nil))
  4391. (if (and e3
  4392. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4393. (throw :skip nil))
  4394. (setq tmp (buffer-substring (max (point-min)
  4395. (- b0 org-ds-keyword-length))
  4396. b0)
  4397. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4398. inactivep (= (char-after b0) ?\[)
  4399. deadlinep (string-match org-deadline-regexp tmp)
  4400. scheduledp (string-match org-scheduled-regexp tmp)
  4401. closedp (and org-agenda-include-inactive-timestamps
  4402. (string-match org-closed-string tmp))
  4403. clockp (and org-agenda-include-inactive-timestamps
  4404. (or (string-match org-clock-string tmp)
  4405. (string-match "]-+\\'" tmp)))
  4406. donep (member todo-state org-done-keywords))
  4407. (if (or scheduledp deadlinep closedp clockp
  4408. (and donep org-agenda-skip-timestamp-if-done))
  4409. (throw :skip t))
  4410. (if (string-match ">" timestr)
  4411. ;; substring should only run to end of time stamp
  4412. (setq timestr (substring timestr 0 (match-end 0))))
  4413. (setq marker (org-agenda-new-marker b0)
  4414. category (org-get-category b0)
  4415. org-category-pos (get-text-property b0 'org-category-position))
  4416. (save-excursion
  4417. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4418. (setq txt org-agenda-no-heading-message)
  4419. (goto-char (match-beginning 0))
  4420. (setq hdmarker (org-agenda-new-marker)
  4421. tags (org-get-tags-at))
  4422. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4423. (setq head (or (match-string 1) ""))
  4424. (setq txt (org-agenda-format-item
  4425. (if inactivep org-agenda-inactive-leader nil)
  4426. head category tags timestr
  4427. remove-re)))
  4428. (setq priority (org-get-priority txt))
  4429. (org-add-props txt props
  4430. 'org-marker marker 'org-hd-marker hdmarker)
  4431. (org-add-props txt nil 'priority priority
  4432. 'org-category category 'date date
  4433. 'org-category-position org-category-pos
  4434. 'todo-state todo-state
  4435. 'type "timestamp")
  4436. (push txt ee))
  4437. (if org-agenda-skip-additional-timestamps-same-entry
  4438. (outline-next-heading)
  4439. (goto-char end-of-match))))
  4440. (nreverse ee)))
  4441. (defun org-agenda-get-sexps ()
  4442. "Return the sexp information for agenda display."
  4443. (require 'diary-lib)
  4444. (let* ((props (list 'mouse-face 'highlight
  4445. 'help-echo
  4446. (format "mouse-2 or RET jump to org file %s"
  4447. (abbreviate-file-name buffer-file-name))))
  4448. (regexp "^&?%%(")
  4449. marker category org-category-pos ee txt tags entry
  4450. result beg b sexp sexp-entry todo-state)
  4451. (goto-char (point-min))
  4452. (while (re-search-forward regexp nil t)
  4453. (catch :skip
  4454. (org-agenda-skip)
  4455. (setq beg (match-beginning 0))
  4456. (goto-char (1- (match-end 0)))
  4457. (setq b (point))
  4458. (forward-sexp 1)
  4459. (setq sexp (buffer-substring b (point)))
  4460. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4461. (org-trim (match-string 1))
  4462. ""))
  4463. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4464. (when result
  4465. (setq marker (org-agenda-new-marker beg)
  4466. category (org-get-category beg)
  4467. org-category-pos (get-text-property beg 'org-category-position)
  4468. todo-state (org-get-todo-state))
  4469. (dolist (r (if (stringp result)
  4470. (list result)
  4471. result)) ;; we expect a list here
  4472. (if (string-match "\\S-" r)
  4473. (setq txt r)
  4474. (setq txt "SEXP entry returned empty string"))
  4475. (setq txt (org-agenda-format-item
  4476. "" txt category tags 'time))
  4477. (org-add-props txt props 'org-marker marker)
  4478. (org-add-props txt nil
  4479. 'org-category category 'date date 'todo-state todo-state
  4480. 'org-category-position org-category-pos
  4481. 'type "sexp")
  4482. (push txt ee)))))
  4483. (nreverse ee)))
  4484. ;; Calendar sanity: define some functions that are independent of
  4485. ;; `calendar-date-style'.
  4486. ;; Normally I would like to use ISO format when calling the diary functions,
  4487. ;; but to make sure we still have Emacs 22 compatibility we bind
  4488. ;; also `european-calendar-style' and use european format
  4489. (defun org-anniversary (year month day &optional mark)
  4490. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4491. (org-no-warnings
  4492. (let ((calendar-date-style 'european) (european-calendar-style t))
  4493. (diary-anniversary day month year mark))))
  4494. (defun org-cyclic (N year month day &optional mark)
  4495. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4496. (org-no-warnings
  4497. (let ((calendar-date-style 'european) (european-calendar-style t))
  4498. (diary-cyclic N day month year mark))))
  4499. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4500. "Like `diary-block', but with fixed (ISO) order of arguments."
  4501. (org-no-warnings
  4502. (let ((calendar-date-style 'european) (european-calendar-style t))
  4503. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4504. (defun org-date (year month day &optional mark)
  4505. "Like `diary-date', but with fixed (ISO) order of arguments."
  4506. (org-no-warnings
  4507. (let ((calendar-date-style 'european) (european-calendar-style t))
  4508. (diary-date day month year mark))))
  4509. (defalias 'org-float 'diary-float)
  4510. ;; Define the` org-class' function
  4511. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4512. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4513. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4514. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4515. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4516. `holidays', then any date that is known by the Emacs calendar to be a
  4517. holidy will also be skipped."
  4518. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4519. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4520. (d (calendar-absolute-from-gregorian date)))
  4521. (and
  4522. (<= date1 d)
  4523. (<= d date2)
  4524. (= (calendar-day-of-week date) dayname)
  4525. (or (not skip-weeks)
  4526. (progn
  4527. (require 'cal-iso)
  4528. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4529. (not (and (memq 'holidays skip-weeks)
  4530. (calendar-check-holidays date)))
  4531. entry)))
  4532. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4533. "Like `org-class', but honor `calendar-date-style'.
  4534. The order of the first 2 times 3 arguments depends on the variable
  4535. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4536. So for American calendars, give this as MONTH DAY YEAR, for European as
  4537. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4538. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4539. is any number of ISO weeks in the block period for which the item should
  4540. be skipped.
  4541. This function is here only for backward compatibility and it is deprecated,
  4542. please use `org-class' instead."
  4543. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4544. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4545. (org-class
  4546. (nth 2 date1) (car date1) (nth 1 date1)
  4547. (nth 2 date2) (car date2) (nth 1 date2)
  4548. dayname skip-weeks)))
  4549. (make-obsolete 'org-diary-class 'org-class "")
  4550. (defalias 'org-get-closed 'org-agenda-get-progress)
  4551. (defun org-agenda-get-progress ()
  4552. "Return the logged TODO entries for agenda display."
  4553. (let* ((props (list 'mouse-face 'highlight
  4554. 'org-not-done-regexp org-not-done-regexp
  4555. 'org-todo-regexp org-todo-regexp
  4556. 'org-complex-heading-regexp org-complex-heading-regexp
  4557. 'help-echo
  4558. (format "mouse-2 or RET jump to org file %s"
  4559. (abbreviate-file-name buffer-file-name))))
  4560. (items (if (consp org-agenda-show-log)
  4561. org-agenda-show-log
  4562. (if (eq org-agenda-show-log 'clockcheck)
  4563. '(clock)
  4564. org-agenda-log-mode-items)))
  4565. (parts
  4566. (delq nil
  4567. (list
  4568. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4569. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4570. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4571. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4572. (error "`org-agenda-log-mode-items' is empty")))
  4573. (regexp (concat
  4574. "\\(" parts-re "\\)"
  4575. " *\\["
  4576. (regexp-quote
  4577. (substring
  4578. (format-time-string
  4579. (car org-time-stamp-formats)
  4580. (apply 'encode-time ; DATE bound by calendar
  4581. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4582. 1 11))))
  4583. (org-agenda-search-headline-for-time nil)
  4584. marker hdmarker priority category org-category-pos tags closedp
  4585. statep clockp state ee txt extra timestr rest clocked)
  4586. (goto-char (point-min))
  4587. (while (re-search-forward regexp nil t)
  4588. (catch :skip
  4589. (org-agenda-skip)
  4590. (setq marker (org-agenda-new-marker (match-beginning 0))
  4591. closedp (equal (match-string 1) org-closed-string)
  4592. statep (equal (string-to-char (match-string 1)) ?-)
  4593. clockp (not (or closedp statep))
  4594. state (and statep (match-string 2))
  4595. category (org-get-category (match-beginning 0))
  4596. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4597. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4598. (when (string-match "\\]" timestr)
  4599. ;; substring should only run to end of time stamp
  4600. (setq rest (substring timestr (match-end 0))
  4601. timestr (substring timestr 0 (match-end 0)))
  4602. (if (and (not closedp) (not statep)
  4603. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4604. rest))
  4605. (progn (setq timestr (concat (substring timestr 0 -1)
  4606. "-" (match-string 1 rest) "]"))
  4607. (setq clocked (match-string 2 rest)))
  4608. (setq clocked "-")))
  4609. (save-excursion
  4610. (setq extra
  4611. (cond
  4612. ((not org-agenda-log-mode-add-notes) nil)
  4613. (statep
  4614. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4615. (match-string 1)))
  4616. (clockp
  4617. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4618. (match-string 1)))))
  4619. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4620. (setq txt org-agenda-no-heading-message)
  4621. (goto-char (match-beginning 0))
  4622. (setq hdmarker (org-agenda-new-marker)
  4623. tags (org-get-tags-at))
  4624. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4625. (setq txt (match-string 1))
  4626. (when extra
  4627. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4628. (setq txt (concat (substring txt 0 (match-beginning 1))
  4629. " - " extra " " (match-string 2 txt)))
  4630. (setq txt (concat txt " - " extra))))
  4631. (setq txt (org-agenda-format-item
  4632. (cond
  4633. (closedp "Closed: ")
  4634. (statep (concat "State: (" state ")"))
  4635. (t (concat "Clocked: (" clocked ")")))
  4636. txt category tags timestr)))
  4637. (setq priority 100000)
  4638. (org-add-props txt props
  4639. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4640. 'priority priority 'org-category category
  4641. 'org-category-position org-category-pos
  4642. 'type "closed" 'date date
  4643. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4644. (push txt ee))
  4645. (goto-char (point-at-eol))))
  4646. (nreverse ee)))
  4647. (defun org-agenda-show-clocking-issues ()
  4648. "Add overlays, showing issues with clocking.
  4649. See also the user option `org-agenda-clock-consistency-checks'."
  4650. (interactive)
  4651. (let* ((pl org-agenda-clock-consistency-checks)
  4652. (re (concat "^[ \t]*"
  4653. org-clock-string
  4654. "[ \t]+"
  4655. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4656. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4657. (tlstart 0.)
  4658. (tlend 0.)
  4659. (maxtime (org-hh:mm-string-to-minutes
  4660. (or (plist-get pl :max-duration) "24:00")))
  4661. (mintime (org-hh:mm-string-to-minutes
  4662. (or (plist-get pl :min-duration) 0)))
  4663. (maxgap (org-hh:mm-string-to-minutes
  4664. ;; default 30:00 means never complain
  4665. (or (plist-get pl :max-gap) "30:00")))
  4666. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4667. (plist-get pl :gap-ok-around)))
  4668. (def-face (or (plist-get pl :default-face)
  4669. '((:background "DarkRed") (:foreground "white"))))
  4670. issue face m te ts dt ov)
  4671. (goto-char (point-min))
  4672. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4673. (setq issue nil face def-face)
  4674. (catch 'next
  4675. (setq m (org-get-at-bol 'org-marker)
  4676. te nil ts nil)
  4677. (unless (and m (markerp m))
  4678. (setq issue "No valid clock line") (throw 'next t))
  4679. (org-with-point-at m
  4680. (save-excursion
  4681. (goto-char (point-at-bol))
  4682. (unless (looking-at re)
  4683. (error "No valid Clock line")
  4684. (throw 'next t))
  4685. (unless (match-end 3)
  4686. (setq issue "No end time"
  4687. face (or (plist-get pl :no-end-time-face) face))
  4688. (throw 'next t))
  4689. (setq ts (match-string 1)
  4690. te (match-string 3)
  4691. ts (org-float-time
  4692. (apply 'encode-time (org-parse-time-string ts)))
  4693. te (org-float-time
  4694. (apply 'encode-time (org-parse-time-string te)))
  4695. dt (- te ts))))
  4696. (cond
  4697. ((> dt (* 60 maxtime))
  4698. ;; a very long clocking chunk
  4699. (setq issue (format "Clocking interval is very long: %s"
  4700. (org-minutes-to-hh:mm-string
  4701. (floor (/ (float dt) 60.))))
  4702. face (or (plist-get pl :long-face) face)))
  4703. ((< dt (* 60 mintime))
  4704. ;; a very short clocking chunk
  4705. (setq issue (format "Clocking interval is very short: %s"
  4706. (org-minutes-to-hh:mm-string
  4707. (floor (/ (float dt) 60.))))
  4708. face (or (plist-get pl :short-face) face)))
  4709. ((and (> tlend 0) (< ts tlend))
  4710. ;; Two clock entries are overlapping
  4711. (setq issue (format "Clocking overlap: %d minutes"
  4712. (/ (- tlend ts) 60))
  4713. face (or (plist-get pl :overlap-face) face)))
  4714. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4715. ;; There is a gap, lets see if we need to report it
  4716. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4717. (setq issue (format "Clocking gap: %d minutes"
  4718. (/ (- ts tlend) 60))
  4719. face (or (plist-get pl :gap-face) face))))
  4720. (t nil)))
  4721. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4722. (when issue
  4723. ;; OK, there was some issue, add an overlay to show the issue
  4724. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4725. (overlay-put ov 'before-string
  4726. (concat
  4727. (org-add-props
  4728. (format "%-43s" (concat " " issue))
  4729. nil
  4730. 'face face)
  4731. "\n"))
  4732. (overlay-put ov 'evaporate t)))))
  4733. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4734. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4735. (catch 'exit
  4736. (unless ok-list
  4737. ;; there are no OK times for gaps...
  4738. (throw 'exit nil))
  4739. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4740. ;; This is more than 24 hours, so it is OK.
  4741. ;; because we have at least one OK time, that must be in the
  4742. ;; 24 hour interval.
  4743. (throw 'exit t))
  4744. ;; We have a shorter gap.
  4745. ;; Now we have to get the minute of the day when these times are
  4746. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4747. (t2dec (decode-time (seconds-to-time t2)))
  4748. ;; compute the minute on the day
  4749. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4750. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4751. (when (< min2 min1)
  4752. ;; if min2 is smaller than min1, this means it is on the next day.
  4753. ;; Wrap it to after midnight.
  4754. (setq min2 (+ min2 1440)))
  4755. ;; Now check if any of the OK times is in the gap
  4756. (mapc (lambda (x)
  4757. ;; Wrap the time to after midnight if necessary
  4758. (if (< x min1) (setq x (+ x 1440)))
  4759. ;; Check if in interval
  4760. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4761. ok-list)
  4762. ;; Nope, this gap is not OK
  4763. nil)))
  4764. (defun org-agenda-get-deadlines ()
  4765. "Return the deadline information for agenda display."
  4766. (let* ((props (list 'mouse-face 'highlight
  4767. 'org-not-done-regexp org-not-done-regexp
  4768. 'org-todo-regexp org-todo-regexp
  4769. 'org-complex-heading-regexp org-complex-heading-regexp
  4770. 'help-echo
  4771. (format "mouse-2 or RET jump to org file %s"
  4772. (abbreviate-file-name buffer-file-name))))
  4773. (regexp org-deadline-time-regexp)
  4774. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4775. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4776. d2 diff dfrac wdays pos pos1 category org-category-pos
  4777. tags suppress-prewarning ee txt head face s todo-state
  4778. show-all upcomingp donep timestr)
  4779. (goto-char (point-min))
  4780. (while (re-search-forward regexp nil t)
  4781. (setq suppress-prewarning nil)
  4782. (catch :skip
  4783. (org-agenda-skip)
  4784. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4785. (save-match-data
  4786. (string-match org-scheduled-time-regexp
  4787. (buffer-substring (point-at-bol)
  4788. (point-at-eol)))))
  4789. (setq suppress-prewarning
  4790. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4791. org-agenda-skip-deadline-prewarning-if-scheduled
  4792. 0)))
  4793. (setq s (match-string 1)
  4794. txt nil
  4795. pos (1- (match-beginning 1))
  4796. todo-state (save-match-data (org-get-todo-state))
  4797. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4798. (member todo-state
  4799. org-agenda-repeating-timestamp-show-all))
  4800. d2 (org-time-string-to-absolute
  4801. (match-string 1) d1 'past show-all
  4802. (current-buffer) pos)
  4803. diff (- d2 d1)
  4804. wdays (if suppress-prewarning
  4805. (let ((org-deadline-warning-days suppress-prewarning))
  4806. (org-get-wdays s))
  4807. (org-get-wdays s))
  4808. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4809. upcomingp (and todayp (> diff 0)))
  4810. ;; When to show a deadline in the calendar:
  4811. ;; If the expiration is within wdays warning time.
  4812. ;; Past-due deadlines are only shown on the current date
  4813. (if (and (or (and (<= diff wdays)
  4814. (and todayp (not org-agenda-only-exact-dates)))
  4815. (= diff 0)))
  4816. (save-excursion
  4817. ;; (setq todo-state (org-get-todo-state))
  4818. (setq donep (member todo-state org-done-keywords))
  4819. (if (and donep
  4820. (or org-agenda-skip-deadline-if-done
  4821. (not (= diff 0))))
  4822. (setq txt nil)
  4823. (setq category (org-get-category)
  4824. org-category-pos (get-text-property (point) 'org-category-position))
  4825. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4826. (setq txt org-agenda-no-heading-message)
  4827. (goto-char (match-end 0))
  4828. (setq pos1 (match-beginning 0))
  4829. (setq tags (org-get-tags-at pos1))
  4830. (setq head (buffer-substring-no-properties
  4831. (point)
  4832. (progn (skip-chars-forward "^\r\n")
  4833. (point))))
  4834. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4835. (setq timestr
  4836. (concat (substring s (match-beginning 1)) " "))
  4837. (setq timestr 'time))
  4838. (setq txt (org-agenda-format-item
  4839. (if (= diff 0)
  4840. (car org-agenda-deadline-leaders)
  4841. (if (functionp
  4842. (nth 1 org-agenda-deadline-leaders))
  4843. (funcall
  4844. (nth 1 org-agenda-deadline-leaders)
  4845. diff date)
  4846. (format (nth 1 org-agenda-deadline-leaders)
  4847. diff)))
  4848. head category tags
  4849. (if (not (= diff 0)) nil timestr)))))
  4850. (when txt
  4851. (setq face (org-agenda-deadline-face dfrac))
  4852. (org-add-props txt props
  4853. 'org-marker (org-agenda-new-marker pos)
  4854. 'org-hd-marker (org-agenda-new-marker pos1)
  4855. 'priority (+ (- diff)
  4856. (org-get-priority txt))
  4857. 'org-category category
  4858. 'org-category-position org-category-pos
  4859. 'todo-state todo-state
  4860. 'type (if upcomingp "upcoming-deadline" "deadline")
  4861. 'date (if upcomingp date d2)
  4862. 'face (if donep 'org-agenda-done face)
  4863. 'undone-face face 'done-face 'org-agenda-done)
  4864. (push txt ee))))))
  4865. (nreverse ee)))
  4866. (defun org-agenda-deadline-face (fraction)
  4867. "Return the face to displaying a deadline item.
  4868. FRACTION is what fraction of the head-warning time has passed."
  4869. (let ((faces org-agenda-deadline-faces) f)
  4870. (catch 'exit
  4871. (while (setq f (pop faces))
  4872. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4873. (defun org-agenda-get-scheduled (&optional deadline-results)
  4874. "Return the scheduled information for agenda display."
  4875. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4876. 'org-todo-regexp org-todo-regexp
  4877. 'org-complex-heading-regexp org-complex-heading-regexp
  4878. 'done-face 'org-agenda-done
  4879. 'mouse-face 'highlight
  4880. 'help-echo
  4881. (format "mouse-2 or RET jump to org file %s"
  4882. (abbreviate-file-name buffer-file-name))))
  4883. (regexp org-scheduled-time-regexp)
  4884. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4885. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4886. mm
  4887. (deadline-position-alist
  4888. (mapcar (lambda (a) (and (setq mm (get-text-property
  4889. 0 'org-hd-marker a))
  4890. (cons (marker-position mm) a)))
  4891. deadline-results))
  4892. d2 diff pos pos1 category org-category-pos tags donep
  4893. ee txt head pastschedp todo-state face timestr s habitp show-all)
  4894. (goto-char (point-min))
  4895. (while (re-search-forward regexp nil t)
  4896. (catch :skip
  4897. (org-agenda-skip)
  4898. (setq s (match-string 1)
  4899. txt nil
  4900. pos (1- (match-beginning 1))
  4901. todo-state (save-match-data (org-get-todo-state))
  4902. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4903. (member todo-state
  4904. org-agenda-repeating-timestamp-show-all))
  4905. d2 (org-time-string-to-absolute
  4906. (match-string 1) d1 'past show-all
  4907. (current-buffer) pos)
  4908. diff (- d2 d1))
  4909. (setq pastschedp (and todayp (< diff 0)))
  4910. ;; When to show a scheduled item in the calendar:
  4911. ;; If it is on or past the date.
  4912. (when (or (and (< diff 0)
  4913. (< (abs diff) org-scheduled-past-days)
  4914. (and todayp (not org-agenda-only-exact-dates)))
  4915. (= diff 0))
  4916. (save-excursion
  4917. (setq donep (member todo-state org-done-keywords))
  4918. (if (and donep
  4919. (or org-agenda-skip-scheduled-if-done
  4920. (not (= diff 0))
  4921. (and (functionp 'org-is-habit-p)
  4922. (org-is-habit-p))))
  4923. (setq txt nil)
  4924. (setq habitp (and (functionp 'org-is-habit-p)
  4925. (org-is-habit-p)))
  4926. (setq category (org-get-category)
  4927. org-category-pos (get-text-property (point) 'org-category-position))
  4928. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4929. (setq txt org-agenda-no-heading-message)
  4930. (goto-char (match-end 0))
  4931. (setq pos1 (match-beginning 0))
  4932. (if habitp
  4933. (if (or (not org-habit-show-habits)
  4934. (and (not todayp)
  4935. org-habit-show-habits-only-for-today))
  4936. (throw :skip nil))
  4937. (if (and
  4938. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4939. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4940. pastschedp))
  4941. (setq mm (assoc pos1 deadline-position-alist)))
  4942. (throw :skip nil)))
  4943. (setq tags (org-get-tags-at))
  4944. (setq head (buffer-substring-no-properties
  4945. (point)
  4946. (progn (skip-chars-forward "^\r\n") (point))))
  4947. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4948. (setq timestr
  4949. (concat (substring s (match-beginning 1)) " "))
  4950. (setq timestr 'time))
  4951. (setq txt (org-agenda-format-item
  4952. (if (= diff 0)
  4953. (car org-agenda-scheduled-leaders)
  4954. (format (nth 1 org-agenda-scheduled-leaders)
  4955. (- 1 diff)))
  4956. head category tags
  4957. (if (not (= diff 0)) nil timestr)
  4958. nil habitp))))
  4959. (when txt
  4960. (setq face
  4961. (cond
  4962. ((and (not habitp) pastschedp)
  4963. 'org-scheduled-previously)
  4964. (todayp 'org-scheduled-today)
  4965. (t 'org-scheduled))
  4966. habitp (and habitp (org-habit-parse-todo)))
  4967. (org-add-props txt props
  4968. 'undone-face face
  4969. 'face (if donep 'org-agenda-done face)
  4970. 'org-marker (org-agenda-new-marker pos)
  4971. 'org-hd-marker (org-agenda-new-marker pos1)
  4972. 'type (if pastschedp "past-scheduled" "scheduled")
  4973. 'date (if pastschedp d2 date)
  4974. 'priority (if habitp
  4975. (org-habit-get-priority habitp)
  4976. (+ 94 (- 5 diff) (org-get-priority txt)))
  4977. 'org-category category
  4978. 'org-category-position org-category-pos
  4979. 'org-habit-p habitp
  4980. 'todo-state todo-state)
  4981. (push txt ee))))))
  4982. (nreverse ee)))
  4983. (defun org-agenda-get-blocks ()
  4984. "Return the date-range information for agenda display."
  4985. (let* ((props (list 'face nil
  4986. 'org-not-done-regexp org-not-done-regexp
  4987. 'org-todo-regexp org-todo-regexp
  4988. 'org-complex-heading-regexp org-complex-heading-regexp
  4989. 'mouse-face 'highlight
  4990. 'help-echo
  4991. (format "mouse-2 or RET jump to org file %s"
  4992. (abbreviate-file-name buffer-file-name))))
  4993. (regexp org-tr-regexp)
  4994. (d0 (calendar-absolute-from-gregorian date))
  4995. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  4996. todo-state tags pos head donep)
  4997. (goto-char (point-min))
  4998. (while (re-search-forward regexp nil t)
  4999. (catch :skip
  5000. (org-agenda-skip)
  5001. (setq pos (point))
  5002. (let ((start-time (match-string 1))
  5003. (end-time (match-string 2)))
  5004. (setq s1 (match-string 1)
  5005. s2 (match-string 2)
  5006. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5007. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5008. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5009. ;; Only allow days between the limits, because the normal
  5010. ;; date stamps will catch the limits.
  5011. (save-excursion
  5012. (setq todo-state (org-get-todo-state))
  5013. (setq donep (member todo-state org-done-keywords))
  5014. (if (and donep org-agenda-skip-timestamp-if-done)
  5015. (throw :skip t))
  5016. (setq marker (org-agenda-new-marker (point)))
  5017. (setq category (org-get-category)
  5018. org-category-pos (get-text-property (point) 'org-category-position))
  5019. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5020. (setq txt org-agenda-no-heading-message)
  5021. (goto-char (match-beginning 0))
  5022. (setq hdmarker (org-agenda-new-marker (point)))
  5023. (setq tags (org-get-tags-at))
  5024. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5025. (setq head (match-string 1))
  5026. (let ((remove-re
  5027. (if org-agenda-remove-timeranges-from-blocks
  5028. (concat
  5029. "<" (regexp-quote s1) ".*?>"
  5030. "--"
  5031. "<" (regexp-quote s2) ".*?>")
  5032. nil)))
  5033. (setq txt (org-agenda-format-item
  5034. (format
  5035. (nth (if (= d1 d2) 0 1)
  5036. org-agenda-timerange-leaders)
  5037. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5038. head category tags
  5039. (cond ((and (= d1 d0) (= d2 d0))
  5040. (concat "<" start-time ">--<" end-time ">"))
  5041. ((= d1 d0)
  5042. (concat "<" start-time ">"))
  5043. ((= d2 d0)
  5044. (concat "<" end-time ">"))
  5045. (t nil))
  5046. remove-re))))
  5047. (org-add-props txt props
  5048. 'org-marker marker 'org-hd-marker hdmarker
  5049. 'type "block" 'date date
  5050. 'todo-state todo-state
  5051. 'priority (org-get-priority txt) 'org-category category
  5052. 'org-category-position org-category-pos)
  5053. (push txt ee))))
  5054. (goto-char pos)))
  5055. ;; Sort the entries by expiration date.
  5056. (nreverse ee)))
  5057. ;;; Agenda presentation and sorting
  5058. (defvar org-prefix-has-time nil
  5059. "A flag, set by `org-compile-prefix-format'.
  5060. The flag is set if the currently compiled format contains a `%t'.")
  5061. (defvar org-prefix-has-tag nil
  5062. "A flag, set by `org-compile-prefix-format'.
  5063. The flag is set if the currently compiled format contains a `%T'.")
  5064. (defvar org-prefix-has-effort nil
  5065. "A flag, set by `org-compile-prefix-format'.
  5066. The flag is set if the currently compiled format contains a `%e'.")
  5067. (defvar org-prefix-category-length nil
  5068. "Used by `org-compile-prefix-format' to remember the category field width.")
  5069. (defvar org-prefix-category-max-length nil
  5070. "Used by `org-compile-prefix-format' to remember the category field width.")
  5071. (defun org-agenda-get-category-icon (category)
  5072. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5073. (dolist (entry org-agenda-category-icon-alist)
  5074. (when (org-string-match-p (car entry) category)
  5075. (if (listp (cadr entry))
  5076. (return (cadr entry))
  5077. (return (apply 'create-image (cdr entry)))))))
  5078. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5079. remove-re habitp)
  5080. "Format TXT to be inserted into the agenda buffer.
  5081. In particular, it adds the prefix and corresponding text properties. EXTRA
  5082. must be a string and replaces the `%s' specifier in the prefix format.
  5083. CATEGORY (string, symbol or nil) may be used to overrule the default
  5084. category taken from local variable or file name. It will replace the `%c'
  5085. specifier in the format. DOTIME, when non-nil, indicates that a
  5086. time-of-day should be extracted from TXT for sorting of this entry, and for
  5087. the `%t' specifier in the format. When DOTIME is a string, this string is
  5088. searched for a time before TXT is. TAGS can be the tags of the headline.
  5089. Any match of REMOVE-RE will be removed from TXT."
  5090. (save-match-data
  5091. ;; Diary entries sometimes have extra whitespace at the beginning
  5092. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5093. ;; Fix the tags part in txt
  5094. (setq txt (org-agenda-fix-displayed-tags
  5095. txt tags
  5096. org-agenda-show-inherited-tags
  5097. org-agenda-hide-tags-regexp))
  5098. (let* ((category (or category
  5099. (if (stringp org-category)
  5100. org-category
  5101. (and org-category (symbol-name org-category)))
  5102. (if buffer-file-name
  5103. (file-name-sans-extension
  5104. (file-name-nondirectory buffer-file-name))
  5105. "")))
  5106. (category-icon (org-agenda-get-category-icon category))
  5107. (category-icon (if category-icon
  5108. (propertize " " 'display category-icon)
  5109. ""))
  5110. ;; time, tag, effort are needed for the eval of the prefix format
  5111. (tag (if tags (nth (1- (length tags)) tags) ""))
  5112. time effort neffort
  5113. (ts (if dotime (concat
  5114. (if (stringp dotime) dotime "")
  5115. (and org-agenda-search-headline-for-time txt))))
  5116. (time-of-day (and dotime (org-get-time-of-day ts)))
  5117. stamp plain s0 s1 s2 rtn srp l
  5118. duration thecategory)
  5119. (and (eq major-mode 'org-mode) buffer-file-name
  5120. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5121. (when (and dotime time-of-day)
  5122. ;; Extract starting and ending time and move them to prefix
  5123. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5124. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5125. (setq s0 (match-string 0 ts)
  5126. srp (and stamp (match-end 3))
  5127. s1 (match-string (if plain 1 2) ts)
  5128. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5129. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5130. ;; them, we might want to remove them there to avoid duplication.
  5131. ;; The user can turn this off with a variable.
  5132. (if (and org-prefix-has-time
  5133. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5134. (string-match (concat (regexp-quote s0) " *") txt)
  5135. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5136. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5137. (= (match-beginning 0) 0)
  5138. t))
  5139. (setq txt (replace-match "" nil nil txt))))
  5140. ;; Normalize the time(s) to 24 hour
  5141. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5142. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5143. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5144. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5145. (setq s2
  5146. (org-minutes-to-hh:mm-string
  5147. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5148. ;; Compute the duration
  5149. (when s2
  5150. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5151. (org-hh:mm-string-to-minutes s1)))))
  5152. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5153. txt)
  5154. ;; Tags are in the string
  5155. (if (or (eq org-agenda-remove-tags t)
  5156. (and org-agenda-remove-tags
  5157. org-prefix-has-tag))
  5158. (setq txt (replace-match "" t t txt))
  5159. (setq txt (replace-match
  5160. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5161. (match-string 2 txt))
  5162. t t txt))))
  5163. (when (eq major-mode 'org-mode)
  5164. (setq effort
  5165. (condition-case nil
  5166. (org-get-effort
  5167. (or (get-text-property 0 'org-hd-marker txt)
  5168. (get-text-property 0 'org-marker txt)))
  5169. (error nil)))
  5170. (when effort
  5171. (setq neffort (org-duration-string-to-minutes effort)
  5172. effort (setq effort (concat "[" effort "]")))))
  5173. ;; prevent erroring out with %e format when there is no effort
  5174. (or effort (setq effort ""))
  5175. (when remove-re
  5176. (while (string-match remove-re txt)
  5177. (setq txt (replace-match "" t t txt))))
  5178. ;; Set org-heading property on `txt' to mark the start of the
  5179. ;; heading.
  5180. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5181. ;; Prepare the variables needed in the eval of the compiled format
  5182. (setq time (cond (s2 (concat
  5183. (org-agenda-time-of-day-to-ampm-maybe s1)
  5184. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5185. (if org-agenda-timegrid-use-ampm " ")))
  5186. (s1 (concat
  5187. (org-agenda-time-of-day-to-ampm-maybe s1)
  5188. (if org-agenda-timegrid-use-ampm
  5189. "........ "
  5190. "......")))
  5191. (t ""))
  5192. extra (or (and (not habitp) extra) "")
  5193. category (if (symbolp category) (symbol-name category) category)
  5194. thecategory (copy-sequence category))
  5195. (if (string-match org-bracket-link-regexp category)
  5196. (progn
  5197. (setq l (if (match-end 3)
  5198. (- (match-end 3) (match-beginning 3))
  5199. (- (match-end 1) (match-beginning 1))))
  5200. (when (< l (or org-prefix-category-length 0))
  5201. (setq category (copy-sequence category))
  5202. (org-add-props category nil
  5203. 'extra-space (make-string
  5204. (- org-prefix-category-length l 1) ?\ ))))
  5205. (if (and org-prefix-category-max-length
  5206. (>= (length category) org-prefix-category-max-length))
  5207. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5208. ;; Evaluate the compiled format
  5209. (setq rtn (concat (eval org-prefix-format-compiled) txt))
  5210. ;; And finally add the text properties
  5211. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5212. (org-add-props rtn nil
  5213. 'org-category (if thecategory (downcase thecategory) category)
  5214. 'tags (mapcar 'org-downcase-keep-props tags)
  5215. 'org-highest-priority org-highest-priority
  5216. 'org-lowest-priority org-lowest-priority
  5217. 'time-of-day time-of-day
  5218. 'duration duration
  5219. 'effort effort
  5220. 'effort-minutes neffort
  5221. 'txt txt
  5222. 'time time
  5223. 'extra extra
  5224. 'format org-prefix-format-compiled
  5225. 'dotime dotime))))
  5226. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5227. "Remove tags string from TXT, and add a modified list of tags.
  5228. The modified list may contain inherited tags, and tags matched by
  5229. `org-agenda-hide-tags-regexp' will be removed."
  5230. (when (or add-inherited hide-re)
  5231. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5232. (setq txt (substring txt 0 (match-beginning 0))))
  5233. (setq tags
  5234. (delq nil
  5235. (mapcar (lambda (tg)
  5236. (if (or (and hide-re (string-match hide-re tg))
  5237. (and (not add-inherited)
  5238. (get-text-property 0 'inherited tg)))
  5239. nil
  5240. tg))
  5241. tags)))
  5242. (when tags
  5243. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5244. i)
  5245. (setq txt (concat txt " :"
  5246. (mapconcat
  5247. (lambda (x)
  5248. (setq i (get-text-property 0 'inherited x))
  5249. (if (and have-i (not i))
  5250. (progn
  5251. (setq have-i nil)
  5252. (concat ":" x))
  5253. x))
  5254. tags ":")
  5255. (if have-i "::" ":"))))))
  5256. txt)
  5257. (defun org-downcase-keep-props (s)
  5258. (let ((props (text-properties-at 0 s)))
  5259. (setq s (downcase s))
  5260. (add-text-properties 0 (length s) props s)
  5261. s))
  5262. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5263. (defvar org-agenda-sorting-strategy-selected nil)
  5264. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5265. (catch 'exit
  5266. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5267. ((and todayp (member 'today (car org-agenda-time-grid))))
  5268. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5269. ((member 'weekly (car org-agenda-time-grid)))
  5270. (t (throw 'exit list)))
  5271. (let* ((have (delq nil (mapcar
  5272. (lambda (x) (get-text-property 1 'time-of-day x))
  5273. list)))
  5274. (string (nth 1 org-agenda-time-grid))
  5275. (gridtimes (nth 2 org-agenda-time-grid))
  5276. (req (car org-agenda-time-grid))
  5277. (remove (member 'remove-match req))
  5278. new time)
  5279. (if (and (member 'require-timed req) (not have))
  5280. ;; don't show empty grid
  5281. (throw 'exit list))
  5282. (while (setq time (pop gridtimes))
  5283. (unless (and remove (member time have))
  5284. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5285. (push (org-agenda-format-item
  5286. nil string "" nil
  5287. (concat (substring time 0 -2) ":" (substring time -2)))
  5288. new)
  5289. (put-text-property
  5290. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5291. (when (and todayp org-agenda-show-current-time-in-grid)
  5292. (push (org-agenda-format-item
  5293. nil
  5294. org-agenda-current-time-string
  5295. "" nil
  5296. (format-time-string "%H:%M "))
  5297. new)
  5298. (put-text-property
  5299. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5300. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5301. (append new list)
  5302. (append list new)))))
  5303. (defun org-compile-prefix-format (key)
  5304. "Compile the prefix format into a Lisp form that can be evaluated.
  5305. The resulting form is returned and stored in the variable
  5306. `org-prefix-format-compiled'."
  5307. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5308. org-prefix-category-length nil
  5309. org-prefix-has-effort nil)
  5310. (let ((s (cond
  5311. ((stringp org-agenda-prefix-format)
  5312. org-agenda-prefix-format)
  5313. ((assq key org-agenda-prefix-format)
  5314. (cdr (assq key org-agenda-prefix-format)))
  5315. (t " %-12:c%?-12t% s")))
  5316. (start 0)
  5317. varform vars var e c f opt)
  5318. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5319. s start)
  5320. (setq var (or (cdr (assoc (match-string 4 s)
  5321. '(("c" . category) ("t" . time) ("s" . extra)
  5322. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5323. 'eval)
  5324. c (or (match-string 3 s) "")
  5325. opt (match-beginning 1)
  5326. start (1+ (match-beginning 0)))
  5327. (if (equal var 'time) (setq org-prefix-has-time t))
  5328. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5329. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5330. (setq f (concat "%" (match-string 2 s) "s"))
  5331. (when (equal var 'category)
  5332. (setq org-prefix-category-length
  5333. (floor (abs (string-to-number (match-string 2 s)))))
  5334. (setq org-prefix-category-max-length
  5335. (let ((x (match-string 2 s)))
  5336. (save-match-data
  5337. (if (string-match "\\.[0-9]+" x)
  5338. (string-to-number (substring (match-string 0 x) 1)))))))
  5339. (if (eq var 'eval)
  5340. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5341. (if opt
  5342. (setq varform
  5343. `(if (equal "" ,var)
  5344. ""
  5345. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5346. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5347. (setq s (replace-match "%s" t nil s))
  5348. (push varform vars))
  5349. (setq vars (nreverse vars))
  5350. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  5351. (defun org-set-sorting-strategy (key)
  5352. (if (symbolp (car org-agenda-sorting-strategy))
  5353. ;; the old format
  5354. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5355. (setq org-agenda-sorting-strategy-selected
  5356. (or (cdr (assq key org-agenda-sorting-strategy))
  5357. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5358. '(time-up category-keep priority-down)))))
  5359. (defun org-get-time-of-day (s &optional string mod24)
  5360. "Check string S for a time of day.
  5361. If found, return it as a military time number between 0 and 2400.
  5362. If not found, return nil.
  5363. The optional STRING argument forces conversion into a 5 character wide string
  5364. HH:MM."
  5365. (save-match-data
  5366. (when
  5367. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5368. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5369. (let* ((h (string-to-number (match-string 1 s)))
  5370. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5371. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5372. (am-p (equal ampm "am"))
  5373. (h1 (cond ((not ampm) h)
  5374. ((= h 12) (if am-p 0 12))
  5375. (t (+ h (if am-p 0 12)))))
  5376. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5377. (mod h1 24) h1))
  5378. (t0 (+ (* 100 h2) m))
  5379. (t1 (concat (if (>= h1 24) "+" " ")
  5380. (if (and org-agenda-time-leading-zero
  5381. (< t0 1000)) "0" "")
  5382. (if (< t0 100) "0" "")
  5383. (if (< t0 10) "0" "")
  5384. (int-to-string t0))))
  5385. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5386. (defvar org-agenda-before-sorting-filter-function nil
  5387. "Function to be applied to agenda items prior to sorting.
  5388. Prior to sorting also means just before they are inserted into the agenda.
  5389. To aid sorting, you may revisit the original entries and add more text
  5390. properties which will later be used by the sorting functions.
  5391. The function should take a string argument, an agenda line.
  5392. It has access to the text properties in that line, which contain among
  5393. other things, the property `org-hd-marker' that points to the entry
  5394. where the line comes from. Note that not all lines going into the agenda
  5395. have this property, only most.
  5396. The function should return the modified string. It is probably best
  5397. to ONLY change text properties.
  5398. You can also use this function as a filter, by returning nil for lines
  5399. you don't want to have in the agenda at all. For this application, you
  5400. could bind the variable in the options section of a custom command.")
  5401. (defun org-finalize-agenda-entries (list &optional nosort)
  5402. "Sort and concatenate the agenda items."
  5403. (setq list (mapcar 'org-agenda-highlight-todo list))
  5404. (if nosort
  5405. list
  5406. (when org-agenda-before-sorting-filter-function
  5407. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5408. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5409. (defun org-agenda-highlight-todo (x)
  5410. (let ((org-done-keywords org-done-keywords-for-agenda)
  5411. (case-fold-search nil)
  5412. re)
  5413. (if (eq x 'line)
  5414. (save-excursion
  5415. (beginning-of-line 1)
  5416. (setq re (org-get-at-bol 'org-todo-regexp))
  5417. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5418. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5419. (add-text-properties (match-beginning 0) (match-end 1)
  5420. (list 'face (org-get-todo-face 1)))
  5421. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5422. (delete-region (match-beginning 1) (1- (match-end 0)))
  5423. (goto-char (match-beginning 1))
  5424. (insert (format org-agenda-todo-keyword-format s)))))
  5425. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5426. (setq re (get-text-property 0 'org-todo-regexp x))
  5427. (when (and re
  5428. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5429. x (or pl 0)) pl))
  5430. (add-text-properties
  5431. (or (match-end 1) (match-end 0)) (match-end 0)
  5432. (list 'face (org-get-todo-face (match-string 2 x)))
  5433. x)
  5434. (when (match-end 1)
  5435. (setq x (concat (substring x 0 (match-end 1))
  5436. (format org-agenda-todo-keyword-format
  5437. (match-string 2 x))
  5438. (org-add-props " " (text-properties-at 0 x))
  5439. (substring x (match-end 3)))))))
  5440. x)))
  5441. (defsubst org-cmp-priority (a b)
  5442. "Compare the priorities of string A and B."
  5443. (let ((pa (or (get-text-property 1 'priority a) 0))
  5444. (pb (or (get-text-property 1 'priority b) 0)))
  5445. (cond ((> pa pb) +1)
  5446. ((< pa pb) -1)
  5447. (t nil))))
  5448. (defsubst org-cmp-effort (a b)
  5449. "Compare the effort values of string A and B."
  5450. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5451. (ea (or (get-text-property 1 'effort-minutes a) def))
  5452. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5453. (cond ((> ea eb) +1)
  5454. ((< ea eb) -1)
  5455. (t nil))))
  5456. (defsubst org-cmp-category (a b)
  5457. "Compare the string values of categories of strings A and B."
  5458. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5459. (cb (or (get-text-property 1 'org-category b) "")))
  5460. (cond ((string-lessp ca cb) -1)
  5461. ((string-lessp cb ca) +1)
  5462. (t nil))))
  5463. (defsubst org-cmp-todo-state (a b)
  5464. "Compare the todo states of strings A and B."
  5465. (let* ((ma (or (get-text-property 1 'org-marker a)
  5466. (get-text-property 1 'org-hd-marker a)))
  5467. (mb (or (get-text-property 1 'org-marker b)
  5468. (get-text-property 1 'org-hd-marker b)))
  5469. (fa (and ma (marker-buffer ma)))
  5470. (fb (and mb (marker-buffer mb)))
  5471. (todo-kwds
  5472. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5473. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5474. (ta (or (get-text-property 1 'todo-state a) ""))
  5475. (tb (or (get-text-property 1 'todo-state b) ""))
  5476. (la (- (length (member ta todo-kwds))))
  5477. (lb (- (length (member tb todo-kwds))))
  5478. (donepa (member ta org-done-keywords-for-agenda))
  5479. (donepb (member tb org-done-keywords-for-agenda)))
  5480. (cond ((and donepa (not donepb)) -1)
  5481. ((and (not donepa) donepb) +1)
  5482. ((< la lb) -1)
  5483. ((< lb la) +1)
  5484. (t nil))))
  5485. (defsubst org-cmp-alpha (a b)
  5486. "Compare the headlines, alphabetically."
  5487. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5488. (plb (text-property-any 0 (length b) 'org-heading t b))
  5489. (ta (and pla (substring a pla)))
  5490. (tb (and plb (substring b plb))))
  5491. (when pla
  5492. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5493. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5494. (setq ta (substring ta (match-end 0))))
  5495. (setq ta (downcase ta)))
  5496. (when plb
  5497. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5498. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5499. (setq tb (substring tb (match-end 0))))
  5500. (setq tb (downcase tb)))
  5501. (cond ((not ta) +1)
  5502. ((not tb) -1)
  5503. ((string-lessp ta tb) -1)
  5504. ((string-lessp tb ta) +1)
  5505. (t nil))))
  5506. (defsubst org-cmp-tag (a b)
  5507. "Compare the string values of the first tags of A and B."
  5508. (let ((ta (car (last (get-text-property 1 'tags a))))
  5509. (tb (car (last (get-text-property 1 'tags b)))))
  5510. (cond ((not ta) +1)
  5511. ((not tb) -1)
  5512. ((string-lessp ta tb) -1)
  5513. ((string-lessp tb ta) +1)
  5514. (t nil))))
  5515. (defsubst org-cmp-time (a b)
  5516. "Compare the time-of-day values of strings A and B."
  5517. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5518. (ta (or (get-text-property 1 'time-of-day a) def))
  5519. (tb (or (get-text-property 1 'time-of-day b) def)))
  5520. (cond ((< ta tb) -1)
  5521. ((< tb ta) +1)
  5522. (t nil))))
  5523. (defsubst org-cmp-habit-p (a b)
  5524. "Compare the todo states of strings A and B."
  5525. (let ((ha (get-text-property 1 'org-habit-p a))
  5526. (hb (get-text-property 1 'org-habit-p b)))
  5527. (cond ((and ha (not hb)) -1)
  5528. ((and (not ha) hb) +1)
  5529. (t nil))))
  5530. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5531. (defun org-entries-lessp (a b)
  5532. "Predicate for sorting agenda entries."
  5533. ;; The following variables will be used when the form is evaluated.
  5534. ;; So even though the compiler complains, keep them.
  5535. (let* ((ss org-agenda-sorting-strategy-selected)
  5536. (time-up (and (org-em 'time-up 'time-down ss)
  5537. (org-cmp-time a b)))
  5538. (time-down (if time-up (- time-up) nil))
  5539. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5540. (org-cmp-priority a b)))
  5541. (priority-down (if priority-up (- priority-up) nil))
  5542. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5543. (org-cmp-effort a b)))
  5544. (effort-down (if effort-up (- effort-up) nil))
  5545. (category-up (and (or (org-em 'category-up 'category-down ss)
  5546. (memq 'category-keep ss))
  5547. (org-cmp-category a b)))
  5548. (category-down (if category-up (- category-up) nil))
  5549. (category-keep (if category-up +1 nil))
  5550. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5551. (org-cmp-tag a b)))
  5552. (tag-down (if tag-up (- tag-up) nil))
  5553. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5554. (org-cmp-todo-state a b)))
  5555. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5556. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5557. (org-cmp-habit-p a b)))
  5558. (habit-down (if habit-up (- habit-up) nil))
  5559. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5560. (org-cmp-alpha a b)))
  5561. (alpha-down (if alpha-up (- alpha-up) nil))
  5562. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5563. user-defined-up user-defined-down)
  5564. (if (and need-user-cmp org-agenda-cmp-user-defined
  5565. (functionp org-agenda-cmp-user-defined))
  5566. (setq user-defined-up
  5567. (funcall org-agenda-cmp-user-defined a b)
  5568. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5569. (cdr (assoc
  5570. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5571. '((-1 . t) (1 . nil) (nil . nil))))))
  5572. ;;; Agenda restriction lock
  5573. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5574. "Overlay to mark the headline to which agenda commands are restricted.")
  5575. (overlay-put org-agenda-restriction-lock-overlay
  5576. 'face 'org-agenda-restriction-lock)
  5577. (overlay-put org-agenda-restriction-lock-overlay
  5578. 'help-echo "Agendas are currently limited to this subtree.")
  5579. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5580. (defun org-agenda-set-restriction-lock (&optional type)
  5581. "Set restriction lock for agenda, to current subtree or file.
  5582. Restriction will be the file if TYPE is `file', or if type is the
  5583. universal prefix '(4), or if the cursor is before the first headline
  5584. in the file. Otherwise, restriction will be to the current subtree."
  5585. (interactive "P")
  5586. (and (equal type '(4)) (setq type 'file))
  5587. (setq type (cond
  5588. (type type)
  5589. ((org-at-heading-p) 'subtree)
  5590. ((condition-case nil (org-back-to-heading t) (error nil))
  5591. 'subtree)
  5592. (t 'file)))
  5593. (if (eq type 'subtree)
  5594. (progn
  5595. (setq org-agenda-restrict t)
  5596. (setq org-agenda-overriding-restriction 'subtree)
  5597. (put 'org-agenda-files 'org-restrict
  5598. (list (buffer-file-name (buffer-base-buffer))))
  5599. (org-back-to-heading t)
  5600. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5601. (move-marker org-agenda-restrict-begin (point))
  5602. (move-marker org-agenda-restrict-end
  5603. (save-excursion (org-end-of-subtree t)))
  5604. (message "Locking agenda restriction to subtree"))
  5605. (put 'org-agenda-files 'org-restrict
  5606. (list (buffer-file-name (buffer-base-buffer))))
  5607. (setq org-agenda-restrict nil)
  5608. (setq org-agenda-overriding-restriction 'file)
  5609. (move-marker org-agenda-restrict-begin nil)
  5610. (move-marker org-agenda-restrict-end nil)
  5611. (message "Locking agenda restriction to file"))
  5612. (setq current-prefix-arg nil)
  5613. (org-agenda-maybe-redo))
  5614. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5615. "Remove the agenda restriction lock."
  5616. (interactive "P")
  5617. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5618. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5619. (setq org-agenda-overriding-restriction nil)
  5620. (setq org-agenda-restrict nil)
  5621. (put 'org-agenda-files 'org-restrict nil)
  5622. (move-marker org-agenda-restrict-begin nil)
  5623. (move-marker org-agenda-restrict-end nil)
  5624. (setq current-prefix-arg nil)
  5625. (message "Agenda restriction lock removed")
  5626. (or noupdate (org-agenda-maybe-redo)))
  5627. (defun org-agenda-maybe-redo ()
  5628. "If there is any window showing the agenda view, update it."
  5629. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5630. (w0 (selected-window)))
  5631. (when w
  5632. (select-window w)
  5633. (org-agenda-redo)
  5634. (select-window w0)
  5635. (if org-agenda-overriding-restriction
  5636. (message "Agenda view shifted to new %s restriction"
  5637. org-agenda-overriding-restriction)
  5638. (message "Agenda restriction lock removed")))))
  5639. ;;; Agenda commands
  5640. (defun org-agenda-check-type (error &rest types)
  5641. "Check if agenda buffer is of allowed type.
  5642. If ERROR is non-nil, throw an error, otherwise just return nil."
  5643. (if (memq org-agenda-type types)
  5644. t
  5645. (if error
  5646. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5647. nil)))
  5648. (defun org-agenda-quit ()
  5649. "Exit agenda by removing the window or the buffer."
  5650. (interactive)
  5651. (if org-agenda-columns-active
  5652. (org-columns-quit)
  5653. (let ((buf (current-buffer)))
  5654. (if (eq org-agenda-window-setup 'other-frame)
  5655. (progn
  5656. (kill-buffer buf)
  5657. (org-agenda-reset-markers)
  5658. (org-columns-remove-overlays)
  5659. (setq org-agenda-archives-mode nil)
  5660. (delete-frame))
  5661. (and (not (eq org-agenda-window-setup 'current-window))
  5662. (not (one-window-p))
  5663. (delete-window))
  5664. (kill-buffer buf)
  5665. (org-agenda-reset-markers)
  5666. (org-columns-remove-overlays)
  5667. (setq org-agenda-archives-mode nil)))
  5668. ;; Maybe restore the pre-agenda window configuration.
  5669. (and org-agenda-restore-windows-after-quit
  5670. (not (eq org-agenda-window-setup 'other-frame))
  5671. org-pre-agenda-window-conf
  5672. (set-window-configuration org-pre-agenda-window-conf))))
  5673. (defun org-agenda-exit ()
  5674. "Exit agenda by removing the window or the buffer.
  5675. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5676. Org-mode buffers visited directly by the user will not be touched."
  5677. (interactive)
  5678. (org-release-buffers org-agenda-new-buffers)
  5679. (setq org-agenda-new-buffers nil)
  5680. (org-agenda-quit))
  5681. (defun org-agenda-execute (arg)
  5682. "Execute another agenda command, keeping same window.
  5683. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5684. in the agenda."
  5685. (interactive "P")
  5686. (let ((org-agenda-window-setup 'current-window))
  5687. (org-agenda arg)))
  5688. (defun org-agenda-redo ()
  5689. "Rebuild Agenda.
  5690. When this is the global TODO list, a prefix argument will be interpreted."
  5691. (interactive)
  5692. (let* ((org-agenda-keep-modes t)
  5693. (filter org-agenda-filter)
  5694. (preset (get 'org-agenda-filter :preset-filter))
  5695. (org-agenda-filter-while-redo (or filter preset))
  5696. (cols org-agenda-columns-active)
  5697. (line (org-current-line))
  5698. (window-line (- line (org-current-line (window-start))))
  5699. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5700. (put 'org-agenda-filter :preset-filter nil)
  5701. (and cols (org-columns-quit))
  5702. (message "Rebuilding agenda buffer...")
  5703. (org-let lprops '(eval org-agenda-redo-command))
  5704. (setq org-agenda-undo-list nil
  5705. org-agenda-pending-undo-list nil)
  5706. (message "Rebuilding agenda buffer...done")
  5707. (put 'org-agenda-filter :preset-filter preset)
  5708. (and (or filter preset) (org-agenda-filter-apply filter))
  5709. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5710. (org-goto-line line)
  5711. (recenter window-line)))
  5712. (defvar org-global-tags-completion-table nil)
  5713. (defvar org-agenda-filter-form nil)
  5714. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5715. "Keep only those lines in the agenda buffer that have a specific tag.
  5716. The tag is selected with its fast selection letter, as configured.
  5717. With prefix argument STRIP, remove all lines that do have the tag.
  5718. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5719. used to narrow the search - the interactive user can also press `-' or `+'
  5720. to switch to narrowing."
  5721. (interactive "P")
  5722. (let* ((alist org-tag-alist-for-agenda)
  5723. (tag-chars (mapconcat
  5724. (lambda (x) (if (and (not (symbolp (car x)))
  5725. (cdr x))
  5726. (char-to-string (cdr x))
  5727. ""))
  5728. alist ""))
  5729. (efforts (org-split-string
  5730. (or (cdr (assoc (concat org-effort-property "_ALL")
  5731. org-global-properties))
  5732. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5733. "")))
  5734. (effort-op org-agenda-filter-effort-default-operator)
  5735. (effort-prompt "")
  5736. (inhibit-read-only t)
  5737. (current org-agenda-filter)
  5738. maybe-refresh a n tag)
  5739. (unless char
  5740. (message
  5741. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5742. (if narrow "Narrow" "Filter") tag-chars
  5743. (if org-agenda-auto-exclude-function "[RET], " ""))
  5744. (setq char (read-char)))
  5745. (when (member char '(?+ ?-))
  5746. ;; Narrowing down
  5747. (cond ((equal char ?-) (setq strip t narrow t))
  5748. ((equal char ?+) (setq strip nil narrow t)))
  5749. (message
  5750. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  5751. (setq char (read-char)))
  5752. (when (member char '(?< ?> ?= ??))
  5753. ;; An effort operator
  5754. (setq effort-op (char-to-string char))
  5755. (setq alist nil) ; to make sure it will be interpreted as effort.
  5756. (unless (equal char ??)
  5757. (loop for i from 0 to 9 do
  5758. (setq effort-prompt
  5759. (concat
  5760. effort-prompt " ["
  5761. (if (= i 9) "0" (int-to-string (1+ i)))
  5762. "]" (nth i efforts))))
  5763. (message "Effort%s: %s " effort-op effort-prompt)
  5764. (setq char (read-char))
  5765. (when (or (< char ?0) (> char ?9))
  5766. (error "Need 1-9,0 to select effort" ))))
  5767. (when (equal char ?\t)
  5768. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  5769. (org-set-local 'org-global-tags-completion-table
  5770. (org-global-tags-completion-table)))
  5771. (let ((completion-ignore-case t))
  5772. (setq tag (org-icompleting-read
  5773. "Tag: " org-global-tags-completion-table))))
  5774. (cond
  5775. ((equal char ?\r)
  5776. (org-agenda-filter-by-tag-show-all)
  5777. (when org-agenda-auto-exclude-function
  5778. (setq org-agenda-filter '())
  5779. (dolist (tag (org-agenda-get-represented-tags))
  5780. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  5781. (if modifier
  5782. (push modifier org-agenda-filter))))
  5783. (if (not (null org-agenda-filter))
  5784. (org-agenda-filter-apply org-agenda-filter)))
  5785. (setq maybe-refresh t))
  5786. ((equal char ?/)
  5787. (org-agenda-filter-by-tag-show-all)
  5788. (when (get 'org-agenda-filter :preset-filter)
  5789. (org-agenda-filter-apply org-agenda-filter))
  5790. (setq maybe-refresh t))
  5791. ((or (equal char ?\ )
  5792. (setq a (rassoc char alist))
  5793. (and (>= char ?0) (<= char ?9)
  5794. (setq n (if (= char ?0) 9 (- char ?0 1))
  5795. tag (concat effort-op (nth n efforts))
  5796. a (cons tag nil)))
  5797. (and (= char ??)
  5798. (setq tag "?eff")
  5799. a (cons tag nil))
  5800. (and tag (setq a (cons tag nil))))
  5801. (org-agenda-filter-by-tag-show-all)
  5802. (setq tag (car a))
  5803. (setq org-agenda-filter
  5804. (cons (concat (if strip "-" "+") tag)
  5805. (if narrow current nil)))
  5806. (org-agenda-filter-apply org-agenda-filter)
  5807. (setq maybe-refresh t))
  5808. (t (error "Invalid tag selection character %c" char)))
  5809. (when (and maybe-refresh
  5810. (eq org-agenda-clockreport-mode 'with-filter))
  5811. (org-agenda-redo))))
  5812. (defun org-agenda-get-represented-tags ()
  5813. "Get a list of all tags currently represented in the agenda."
  5814. (let (p tags)
  5815. (save-excursion
  5816. (goto-char (point-min))
  5817. (while (setq p (next-single-property-change (point) 'tags))
  5818. (goto-char p)
  5819. (mapc (lambda (x) (add-to-list 'tags x))
  5820. (get-text-property (point) 'tags))))
  5821. tags))
  5822. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  5823. "Refine the current filter. See `org-agenda-filter-by-tag'."
  5824. (interactive "P")
  5825. (org-agenda-filter-by-tag strip char 'refine))
  5826. (defun org-agenda-filter-make-matcher ()
  5827. "Create the form that tests a line for the agenda filter."
  5828. (let (f f1)
  5829. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  5830. org-agenda-filter))
  5831. (if (member x '("-" "+"))
  5832. (setq f1 (if (equal x "-") 'tags '(not tags)))
  5833. (if (string-match "[<=>?]" x)
  5834. (setq f1 (org-agenda-filter-effort-form x))
  5835. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  5836. (if (equal (string-to-char x) ?-)
  5837. (setq f1 (list 'not f1))))
  5838. (push f1 f))
  5839. (cons 'and (nreverse f))))
  5840. (defun org-agenda-filter-effort-form (e)
  5841. "Return the form to compare the effort of the current line with what E says.
  5842. E looks like \"+<2:25\"."
  5843. (let (op)
  5844. (setq e (substring e 1))
  5845. (setq op (string-to-char e) e (substring e 1))
  5846. (setq op (cond ((equal op ?<) '<=)
  5847. ((equal op ?>) '>=)
  5848. ((equal op ??) op)
  5849. (t '=)))
  5850. (list 'org-agenda-compare-effort (list 'quote op)
  5851. (org-duration-string-to-minutes e))))
  5852. (defun org-agenda-compare-effort (op value)
  5853. "Compare the effort of the current line with VALUE, using OP.
  5854. If the line does not have an effort defined, return nil."
  5855. (let ((eff (org-get-at-bol 'effort-minutes)))
  5856. (if (equal op ??)
  5857. (not eff)
  5858. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  5859. value))))
  5860. (defun org-agenda-filter-apply (filter)
  5861. "Set FILTER as the new agenda filter and apply it."
  5862. (let (tags)
  5863. (setq org-agenda-filter filter
  5864. org-agenda-filter-form (org-agenda-filter-make-matcher))
  5865. (org-agenda-set-mode-name)
  5866. (save-excursion
  5867. (goto-char (point-min))
  5868. (while (not (eobp))
  5869. (if (org-get-at-bol 'org-marker)
  5870. (progn
  5871. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5872. (if (not (eval org-agenda-filter-form))
  5873. (org-agenda-filter-by-tag-hide-line))
  5874. (beginning-of-line 2))
  5875. (beginning-of-line 2))))
  5876. (if (get-char-property (point) 'invisible)
  5877. (org-agenda-previous-line))))
  5878. (defun org-agenda-filter-by-tag-hide-line ()
  5879. (let (ov)
  5880. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  5881. (point-at-eol)))
  5882. (overlay-put ov 'invisible t)
  5883. (overlay-put ov 'type 'tags-filter)
  5884. (push ov org-agenda-filter-overlays)))
  5885. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5886. (setq pos (or pos (point)))
  5887. (save-excursion
  5888. (dolist (ov (overlays-at pos))
  5889. (when (and (overlay-get ov 'invisible)
  5890. (eq (overlay-get ov 'type) 'tags-filter))
  5891. (goto-char pos)
  5892. (if (< (overlay-start ov) (point-at-eol))
  5893. (move-overlay ov (point-at-eol)
  5894. (overlay-end ov)))))))
  5895. (defun org-agenda-filter-by-tag-show-all ()
  5896. (mapc 'delete-overlay org-agenda-filter-overlays)
  5897. (setq org-agenda-filter-overlays nil)
  5898. (setq org-agenda-filter nil)
  5899. (setq org-agenda-filter-form nil)
  5900. (org-agenda-set-mode-name))
  5901. (defun org-agenda-manipulate-query-add ()
  5902. "Manipulate the query by adding a search term with positive selection.
  5903. Positive selection means the term must be matched for selection of an entry."
  5904. (interactive)
  5905. (org-agenda-manipulate-query ?\[))
  5906. (defun org-agenda-manipulate-query-subtract ()
  5907. "Manipulate the query by adding a search term with negative selection.
  5908. Negative selection means term must not be matched for selection of an entry."
  5909. (interactive)
  5910. (org-agenda-manipulate-query ?\]))
  5911. (defun org-agenda-manipulate-query-add-re ()
  5912. "Manipulate the query by adding a search regexp with positive selection.
  5913. Positive selection means the regexp must match for selection of an entry."
  5914. (interactive)
  5915. (org-agenda-manipulate-query ?\{))
  5916. (defun org-agenda-manipulate-query-subtract-re ()
  5917. "Manipulate the query by adding a search regexp with negative selection.
  5918. Negative selection means regexp must not match for selection of an entry."
  5919. (interactive)
  5920. (org-agenda-manipulate-query ?\}))
  5921. (defun org-agenda-manipulate-query (char)
  5922. (cond
  5923. ((memq org-agenda-type '(timeline agenda))
  5924. (let ((org-agenda-include-inactive-timestamps t))
  5925. (org-agenda-redo))
  5926. (message "Display now includes inactive timestamps as well"))
  5927. ((eq org-agenda-type 'search)
  5928. (org-add-to-string
  5929. 'org-agenda-query-string
  5930. (if org-agenda-last-search-view-search-was-boolean
  5931. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5932. (?\{ . " +{}") (?\} . " -{}"))))
  5933. " "))
  5934. (setq org-agenda-redo-command
  5935. (list 'org-search-view
  5936. org-todo-only
  5937. org-agenda-query-string
  5938. (+ (length org-agenda-query-string)
  5939. (if (member char '(?\{ ?\})) 0 1))))
  5940. (set-register org-agenda-query-register org-agenda-query-string)
  5941. (org-agenda-redo))
  5942. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5943. org-agenda-type))))
  5944. (defun org-add-to-string (var string)
  5945. (set var (concat (symbol-value var) string)))
  5946. (defun org-agenda-goto-date (date)
  5947. "Jump to DATE in agenda."
  5948. (interactive (list (let ((org-read-date-prefer-future
  5949. (eval org-agenda-jump-prefer-future)))
  5950. (org-read-date))))
  5951. (org-agenda-list nil date))
  5952. (defun org-agenda-goto-today ()
  5953. "Go to today."
  5954. (interactive)
  5955. (org-agenda-check-type t 'timeline 'agenda)
  5956. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5957. (cond
  5958. (tdpos (goto-char tdpos))
  5959. ((eq org-agenda-type 'agenda)
  5960. (let* ((sd (org-agenda-compute-starting-span
  5961. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  5962. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5963. (setf (nth 1 org-agenda-overriding-arguments) sd)
  5964. (org-agenda-redo)
  5965. (org-agenda-find-same-or-today-or-agenda)))
  5966. (t (error "Cannot find today")))))
  5967. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5968. (goto-char
  5969. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5970. (text-property-any (point-min) (point-max) 'org-today t)
  5971. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5972. (point-min))))
  5973. (defun org-agenda-later (arg)
  5974. "Go forward in time by thee current span.
  5975. With prefix ARG, go forward that many times the current span."
  5976. (interactive "p")
  5977. (org-agenda-check-type t 'agenda)
  5978. (let* ((span org-agenda-current-span)
  5979. (sd org-starting-day)
  5980. (greg (calendar-gregorian-from-absolute sd))
  5981. (cnt (org-get-at-bol 'org-day-cnt))
  5982. greg2)
  5983. (cond
  5984. ((eq span 'day)
  5985. (setq sd (+ arg sd)))
  5986. ((eq span 'week)
  5987. (setq sd (+ (* 7 arg) sd)))
  5988. ((eq span 'month)
  5989. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5990. sd (calendar-absolute-from-gregorian greg2))
  5991. (setcar greg2 (1+ (car greg2))))
  5992. ((eq span 'year)
  5993. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5994. sd (calendar-absolute-from-gregorian greg2))
  5995. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  5996. (t
  5997. (setq sd (+ (* span arg) sd))))
  5998. (let ((org-agenda-overriding-arguments
  5999. (list (car org-agenda-last-arguments) sd span t)))
  6000. (org-agenda-redo)
  6001. (org-agenda-find-same-or-today-or-agenda cnt))))
  6002. (defun org-agenda-earlier (arg)
  6003. "Go backward in time by the current span.
  6004. With prefix ARG, go backward that many times the current span."
  6005. (interactive "p")
  6006. (org-agenda-later (- arg)))
  6007. (defun org-agenda-view-mode-dispatch ()
  6008. "Call one of the view mode commands."
  6009. (interactive)
  6010. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6011. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6012. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6013. [E]ntryText")
  6014. (let ((a (read-char-exclusive)))
  6015. (case a
  6016. (?\ (call-interactively 'org-agenda-reset-view))
  6017. (?d (call-interactively 'org-agenda-day-view))
  6018. (?w (call-interactively 'org-agenda-week-view))
  6019. (?m (call-interactively 'org-agenda-month-view))
  6020. (?y (call-interactively 'org-agenda-year-view))
  6021. (?l (call-interactively 'org-agenda-log-mode))
  6022. (?L (org-agenda-log-mode '(4)))
  6023. (?c (org-agenda-log-mode 'clockcheck))
  6024. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6025. (?a (call-interactively 'org-agenda-archives-mode))
  6026. (?A (org-agenda-archives-mode 'files))
  6027. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6028. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6029. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6030. (?D (call-interactively 'org-agenda-toggle-diary))
  6031. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6032. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6033. (org-agenda-check-type t 'timeline 'agenda)
  6034. (org-agenda-redo))
  6035. (message "Display now includes inactive timestamps as well"))
  6036. (?q (message "Abort"))
  6037. (otherwise (error "Invalid key" )))))
  6038. (defun org-agenda-reset-view ()
  6039. "Switch to default view for agenda."
  6040. (interactive)
  6041. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6042. (defun org-agenda-day-view (&optional day-of-year)
  6043. "Switch to daily view for agenda.
  6044. With argument DAY-OF-YEAR, switch to that day of the year."
  6045. (interactive "P")
  6046. (org-agenda-change-time-span 'day day-of-year))
  6047. (defun org-agenda-week-view (&optional iso-week)
  6048. "Switch to daily view for agenda.
  6049. With argument ISO-WEEK, switch to the corresponding ISO week.
  6050. If ISO-WEEK has more then 2 digits, only the last two encode the
  6051. week. Any digits before this encode a year. So 200712 means
  6052. week 12 of year 2007. Years in the range 1938-2037 can also be
  6053. written as 2-digit years."
  6054. (interactive "P")
  6055. (org-agenda-change-time-span 'week iso-week))
  6056. (defun org-agenda-month-view (&optional month)
  6057. "Switch to monthly view for agenda.
  6058. With argument MONTH, switch to that month."
  6059. (interactive "P")
  6060. (org-agenda-change-time-span 'month month))
  6061. (defun org-agenda-year-view (&optional year)
  6062. "Switch to yearly view for agenda.
  6063. With argument YEAR, switch to that year.
  6064. If MONTH has more then 2 digits, only the last two encode the
  6065. month. Any digits before this encode a year. So 200712 means
  6066. December year 2007. Years in the range 1938-2037 can also be
  6067. written as 2-digit years."
  6068. (interactive "P")
  6069. (when year
  6070. (setq year (org-small-year-to-year year)))
  6071. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6072. (org-agenda-change-time-span 'year year)
  6073. (error "Abort")))
  6074. (defun org-agenda-change-time-span (span &optional n)
  6075. "Change the agenda view to SPAN.
  6076. SPAN may be `day', `week', `month', `year'."
  6077. (org-agenda-check-type t 'agenda)
  6078. (if (and (not n) (equal org-agenda-current-span span))
  6079. (error "Viewing span is already \"%s\"" span))
  6080. (let* ((sd (or (org-get-at-bol 'day)
  6081. org-starting-day))
  6082. (sd (org-agenda-compute-starting-span sd span n))
  6083. (org-agenda-overriding-arguments
  6084. (or org-agenda-overriding-arguments
  6085. (list (car org-agenda-last-arguments) sd span t))))
  6086. (org-agenda-redo)
  6087. (org-agenda-find-same-or-today-or-agenda))
  6088. (org-agenda-set-mode-name)
  6089. (message "Switched to %s view" span))
  6090. (defun org-agenda-compute-starting-span (sd span &optional n)
  6091. "Compute starting date for agenda.
  6092. SPAN may be `day', `week', `month', `year'. The return value
  6093. is a cons cell with the starting date and the number of days,
  6094. so that the date SD will be in that range."
  6095. (let* ((greg (calendar-gregorian-from-absolute sd))
  6096. (dg (nth 1 greg))
  6097. (mg (car greg))
  6098. (yg (nth 2 greg)))
  6099. (cond
  6100. ((eq span 'day)
  6101. (when n
  6102. (setq sd (+ (calendar-absolute-from-gregorian
  6103. (list mg 1 yg))
  6104. n -1))))
  6105. ((eq span 'week)
  6106. (let* ((nt (calendar-day-of-week
  6107. (calendar-gregorian-from-absolute sd)))
  6108. (d (if org-agenda-start-on-weekday
  6109. (- nt org-agenda-start-on-weekday)
  6110. 0))
  6111. y1)
  6112. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6113. (when n
  6114. (require 'cal-iso)
  6115. (when (> n 99)
  6116. (setq y1 (org-small-year-to-year (/ n 100))
  6117. n (mod n 100)))
  6118. (setq sd
  6119. (calendar-absolute-from-iso
  6120. (list n 1
  6121. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6122. ((eq span 'month)
  6123. (let (y1)
  6124. (when (and n (> n 99))
  6125. (setq y1 (org-small-year-to-year (/ n 100))
  6126. n (mod n 100)))
  6127. (setq sd (calendar-absolute-from-gregorian
  6128. (list (or n mg) 1 (or y1 yg))))))
  6129. ((eq span 'year)
  6130. (setq sd (calendar-absolute-from-gregorian
  6131. (list 1 1 (or n yg))))))
  6132. sd))
  6133. (defun org-agenda-next-date-line (&optional arg)
  6134. "Jump to the next line indicating a date in agenda buffer."
  6135. (interactive "p")
  6136. (org-agenda-check-type t 'agenda 'timeline)
  6137. (beginning-of-line 1)
  6138. ;; This does not work if user makes date format that starts with a blank
  6139. (if (looking-at "^\\S-") (forward-char 1))
  6140. (if (not (re-search-forward "^\\S-" nil t arg))
  6141. (progn
  6142. (backward-char 1)
  6143. (error "No next date after this line in this buffer")))
  6144. (goto-char (match-beginning 0)))
  6145. (defun org-agenda-previous-date-line (&optional arg)
  6146. "Jump to the previous line indicating a date in agenda buffer."
  6147. (interactive "p")
  6148. (org-agenda-check-type t 'agenda 'timeline)
  6149. (beginning-of-line 1)
  6150. (if (not (re-search-backward "^\\S-" nil t arg))
  6151. (error "No previous date before this line in this buffer")))
  6152. ;; Initialize the highlight
  6153. (defvar org-hl (make-overlay 1 1))
  6154. (overlay-put org-hl 'face 'highlight)
  6155. (defun org-highlight (begin end &optional buffer)
  6156. "Highlight a region with overlay."
  6157. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6158. (defun org-unhighlight ()
  6159. "Detach overlay INDEX."
  6160. (org-detach-overlay org-hl))
  6161. ;; FIXME this is currently not used.
  6162. (defun org-highlight-until-next-command (beg end &optional buffer)
  6163. "Move the highlight overlay to BEG/END, remove it before the next command."
  6164. (org-highlight beg end buffer)
  6165. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6166. (defun org-unhighlight-once ()
  6167. "Remove the highlight from its position, and this function from the hook."
  6168. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6169. (org-unhighlight))
  6170. (defun org-agenda-follow-mode ()
  6171. "Toggle follow mode in an agenda buffer."
  6172. (interactive)
  6173. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6174. (org-agenda-set-mode-name)
  6175. (org-agenda-do-context-action)
  6176. (message "Follow mode is %s"
  6177. (if org-agenda-follow-mode "on" "off")))
  6178. (defun org-agenda-entry-text-mode (&optional arg)
  6179. "Toggle entry text mode in an agenda buffer."
  6180. (interactive "P")
  6181. (setq org-agenda-entry-text-mode (or (integerp arg)
  6182. (not org-agenda-entry-text-mode)))
  6183. (org-agenda-entry-text-hide)
  6184. (and org-agenda-entry-text-mode
  6185. (let ((org-agenda-entry-text-maxlines
  6186. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6187. (org-agenda-entry-text-show)))
  6188. (org-agenda-set-mode-name)
  6189. (message "Entry text mode is %s. Maximum number of lines is %d"
  6190. (if org-agenda-entry-text-mode "on" "off")
  6191. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6192. (defun org-agenda-clockreport-mode (&optional with-filter)
  6193. "Toggle clocktable mode in an agenda buffer.
  6194. With prefix arg WITH-FILTER, make the clocktable respect the current
  6195. agenda filter."
  6196. (interactive "P")
  6197. (org-agenda-check-type t 'agenda)
  6198. (if with-filter
  6199. (setq org-agenda-clockreport-mode 'with-filter)
  6200. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6201. (org-agenda-set-mode-name)
  6202. (org-agenda-redo)
  6203. (message "Clocktable mode is %s"
  6204. (if org-agenda-clockreport-mode "on" "off")))
  6205. (defun org-agenda-log-mode (&optional special)
  6206. "Toggle log mode in an agenda buffer.
  6207. With argument SPECIAL, show all possible log items, not only the ones
  6208. configured in `org-agenda-log-mode-items'.
  6209. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6210. (interactive "P")
  6211. (org-agenda-check-type t 'agenda 'timeline)
  6212. (setq org-agenda-show-log
  6213. (cond
  6214. ((equal special '(16)) 'only)
  6215. ((eq special 'clockcheck)
  6216. (if (eq org-agenda-show-log 'clockcheck)
  6217. nil 'clockcheck))
  6218. (special '(closed clock state))
  6219. (t (not org-agenda-show-log))))
  6220. (org-agenda-set-mode-name)
  6221. (org-agenda-redo)
  6222. (message "Log mode is %s"
  6223. (if org-agenda-show-log "on" "off")))
  6224. (defun org-agenda-archives-mode (&optional with-files)
  6225. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6226. When called with a prefix argument, include all archive files as well."
  6227. (interactive "P")
  6228. (setq org-agenda-archives-mode
  6229. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6230. (org-agenda-set-mode-name)
  6231. (org-agenda-redo)
  6232. (message
  6233. "%s"
  6234. (cond
  6235. ((eq org-agenda-archives-mode nil)
  6236. "No archives are included")
  6237. ((eq org-agenda-archives-mode 'trees)
  6238. (format "Trees with :%s: tag are included" org-archive-tag))
  6239. ((eq org-agenda-archives-mode t)
  6240. (format "Trees with :%s: tag and all active archive files are included"
  6241. org-archive-tag)))))
  6242. (defun org-agenda-toggle-diary ()
  6243. "Toggle diary inclusion in an agenda buffer."
  6244. (interactive)
  6245. (org-agenda-check-type t 'agenda)
  6246. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6247. (org-agenda-redo)
  6248. (org-agenda-set-mode-name)
  6249. (message "Diary inclusion turned %s"
  6250. (if org-agenda-include-diary "on" "off")))
  6251. (defun org-agenda-toggle-deadlines ()
  6252. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6253. (interactive)
  6254. (org-agenda-check-type t 'agenda)
  6255. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6256. (org-agenda-redo)
  6257. (org-agenda-set-mode-name)
  6258. (message "Deadlines inclusion turned %s"
  6259. (if org-agenda-include-deadlines "on" "off")))
  6260. (defun org-agenda-toggle-time-grid ()
  6261. "Toggle time grid in an agenda buffer."
  6262. (interactive)
  6263. (org-agenda-check-type t 'agenda)
  6264. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6265. (org-agenda-redo)
  6266. (org-agenda-set-mode-name)
  6267. (message "Time-grid turned %s"
  6268. (if org-agenda-use-time-grid "on" "off")))
  6269. (defun org-agenda-set-mode-name ()
  6270. "Set the mode name to indicate all the small mode settings."
  6271. (setq mode-name
  6272. (list "Org-Agenda"
  6273. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6274. " "
  6275. '(:eval (org-agenda-span-name org-agenda-current-span))
  6276. (if org-agenda-follow-mode " Follow" "")
  6277. (if org-agenda-entry-text-mode " ETxt" "")
  6278. (if org-agenda-include-diary " Diary" "")
  6279. (if org-agenda-include-deadlines " Ddl" "")
  6280. (if org-agenda-use-time-grid " Grid" "")
  6281. (if (and (boundp 'org-habit-show-habits)
  6282. org-habit-show-habits) " Habit" "")
  6283. (cond
  6284. ((consp org-agenda-show-log) " LogAll")
  6285. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6286. (org-agenda-show-log " Log")
  6287. (t ""))
  6288. ;; show tags used for filtering in a custom face
  6289. (if (or org-agenda-filter (get 'org-agenda-filter
  6290. :preset-filter))
  6291. '(:eval (org-propertize
  6292. (concat " {"
  6293. (mapconcat
  6294. 'identity
  6295. (append
  6296. (get 'org-agenda-filter :preset-filter)
  6297. org-agenda-filter)
  6298. "")
  6299. "}")
  6300. 'face 'org-agenda-filter-tags
  6301. 'help-echo "Tags used in filtering"))
  6302. "")
  6303. (if org-agenda-archives-mode
  6304. (if (eq org-agenda-archives-mode t)
  6305. " Archives"
  6306. (format " :%s:" org-archive-tag))
  6307. "")
  6308. (if org-agenda-clockreport-mode
  6309. (if (eq org-agenda-clockreport-mode 'with-filter)
  6310. " Clock{}" " Clock")
  6311. "")))
  6312. (force-mode-line-update))
  6313. (defun org-agenda-post-command-hook ()
  6314. (setq org-agenda-type
  6315. (or (get-text-property (point) 'org-agenda-type)
  6316. (get-text-property (max (point-min) (1- (point)))
  6317. 'org-agenda-type))))
  6318. (defun org-agenda-next-line ()
  6319. "Move cursor to the next line, and show if follow mode is active."
  6320. (interactive)
  6321. (call-interactively 'next-line)
  6322. (org-agenda-do-context-action))
  6323. (defun org-agenda-previous-line ()
  6324. "Move cursor to the previous line, and show if follow-mode is active."
  6325. (interactive)
  6326. (call-interactively 'previous-line)
  6327. (org-agenda-do-context-action))
  6328. (defun org-agenda-do-context-action ()
  6329. "Show outline path and, maybe, follow mode window."
  6330. (let ((m (org-get-at-bol 'org-marker)))
  6331. (when (and (markerp m) (marker-buffer m))
  6332. (and org-agenda-follow-mode
  6333. (if org-agenda-follow-indirect
  6334. (org-agenda-tree-to-indirect-buffer)
  6335. (org-agenda-show)))
  6336. (and org-agenda-show-outline-path
  6337. (org-with-point-at m (org-display-outline-path t))))))
  6338. (defun org-agenda-show-priority ()
  6339. "Show the priority of the current item.
  6340. This priority is composed of the main priority given with the [#A] cookies,
  6341. and by additional input from the age of a schedules or deadline entry."
  6342. (interactive)
  6343. (let* ((pri (org-get-at-bol 'priority)))
  6344. (message "Priority is %d" (if pri pri -1000))))
  6345. (defun org-agenda-show-tags ()
  6346. "Show the tags applicable to the current item."
  6347. (interactive)
  6348. (let* ((tags (org-get-at-bol 'tags)))
  6349. (if tags
  6350. (message "Tags are :%s:"
  6351. (org-no-properties (mapconcat 'identity tags ":")))
  6352. (message "No tags associated with this line"))))
  6353. (defun org-agenda-goto (&optional highlight)
  6354. "Go to the Org-mode file which contains the item at point."
  6355. (interactive)
  6356. (let* ((marker (or (org-get-at-bol 'org-marker)
  6357. (org-agenda-error)))
  6358. (buffer (marker-buffer marker))
  6359. (pos (marker-position marker)))
  6360. (switch-to-buffer-other-window buffer)
  6361. (widen)
  6362. (push-mark)
  6363. (goto-char pos)
  6364. (when (eq major-mode 'org-mode)
  6365. (org-show-context 'agenda)
  6366. (save-excursion
  6367. (and (outline-next-heading)
  6368. (org-flag-heading nil)))) ; show the next heading
  6369. (when (outline-invisible-p)
  6370. (show-entry)) ; display invisible text
  6371. (recenter (/ (window-height) 2))
  6372. (run-hooks 'org-agenda-after-show-hook)
  6373. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6374. (defvar org-agenda-after-show-hook nil
  6375. "Normal hook run after an item has been shown from the agenda.
  6376. Point is in the buffer where the item originated.")
  6377. (defun org-agenda-kill ()
  6378. "Kill the entry or subtree belonging to the current agenda entry."
  6379. (interactive)
  6380. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6381. (let* ((marker (or (org-get-at-bol 'org-marker)
  6382. (org-agenda-error)))
  6383. (buffer (marker-buffer marker))
  6384. (pos (marker-position marker))
  6385. (type (org-get-at-bol 'type))
  6386. dbeg dend (n 0) conf)
  6387. (org-with-remote-undo buffer
  6388. (with-current-buffer buffer
  6389. (save-excursion
  6390. (goto-char pos)
  6391. (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
  6392. (setq dbeg (progn (org-back-to-heading t) (point))
  6393. dend (org-end-of-subtree t t))
  6394. (setq dbeg (point-at-bol)
  6395. dend (min (point-max) (1+ (point-at-eol)))))
  6396. (goto-char dbeg)
  6397. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6398. (setq conf (or (eq t org-agenda-confirm-kill)
  6399. (and (numberp org-agenda-confirm-kill)
  6400. (> n org-agenda-confirm-kill))))
  6401. (and conf
  6402. (not (y-or-n-p
  6403. (format "Delete entry with %d lines in buffer \"%s\"? "
  6404. n (buffer-name buffer))))
  6405. (error "Abort"))
  6406. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6407. (with-current-buffer buffer (delete-region dbeg dend))
  6408. (message "Agenda item and source killed"))))
  6409. (defvar org-archive-default-command)
  6410. (defun org-agenda-archive-default ()
  6411. "Archive the entry or subtree belonging to the current agenda entry."
  6412. (interactive)
  6413. (require 'org-archive)
  6414. (org-agenda-archive-with org-archive-default-command))
  6415. (defun org-agenda-archive-default-with-confirmation ()
  6416. "Archive the entry or subtree belonging to the current agenda entry."
  6417. (interactive)
  6418. (require 'org-archive)
  6419. (org-agenda-archive-with org-archive-default-command 'confirm))
  6420. (defun org-agenda-archive ()
  6421. "Archive the entry or subtree belonging to the current agenda entry."
  6422. (interactive)
  6423. (org-agenda-archive-with 'org-archive-subtree))
  6424. (defun org-agenda-archive-to-archive-sibling ()
  6425. "Move the entry to the archive sibling."
  6426. (interactive)
  6427. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6428. (defun org-agenda-archive-with (cmd &optional confirm)
  6429. "Move the entry to the archive sibling."
  6430. (interactive)
  6431. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6432. (let* ((marker (or (org-get-at-bol 'org-marker)
  6433. (org-agenda-error)))
  6434. (buffer (marker-buffer marker))
  6435. (pos (marker-position marker)))
  6436. (org-with-remote-undo buffer
  6437. (with-current-buffer buffer
  6438. (if (eq major-mode 'org-mode)
  6439. (if (and confirm
  6440. (not (y-or-n-p "Archive this subtree or entry? ")))
  6441. (error "Abort")
  6442. (save-excursion
  6443. (goto-char pos)
  6444. (org-remove-subtree-entries-from-agenda)
  6445. (org-back-to-heading t)
  6446. (funcall cmd)))
  6447. (error "Archiving works only in Org-mode files"))))))
  6448. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6449. "Remove all lines in the agenda that correspond to a given subtree.
  6450. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6451. If this information is not given, the function uses the tree at point."
  6452. (let ((buf (or buf (current-buffer))) m p)
  6453. (save-excursion
  6454. (unless (and beg end)
  6455. (org-back-to-heading t)
  6456. (setq beg (point))
  6457. (org-end-of-subtree t)
  6458. (setq end (point)))
  6459. (set-buffer (get-buffer org-agenda-buffer-name))
  6460. (save-excursion
  6461. (goto-char (point-max))
  6462. (beginning-of-line 1)
  6463. (while (not (bobp))
  6464. (when (and (setq m (org-get-at-bol 'org-marker))
  6465. (equal buf (marker-buffer m))
  6466. (setq p (marker-position m))
  6467. (>= p beg)
  6468. (< p end))
  6469. (let ((inhibit-read-only t))
  6470. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6471. (beginning-of-line 0))))))
  6472. (defun org-agenda-refile (&optional goto rfloc no-update)
  6473. "Refile the item at point."
  6474. (interactive "P")
  6475. (if (equal goto '(16))
  6476. (org-refile-goto-last-stored)
  6477. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6478. (org-agenda-error)))
  6479. (buffer (marker-buffer marker))
  6480. (pos (marker-position marker))
  6481. (rfloc (or rfloc
  6482. (org-refile-get-location
  6483. (if goto "Goto" "Refile to") buffer
  6484. org-refile-allow-creating-parent-nodes))))
  6485. (with-current-buffer buffer
  6486. (save-excursion
  6487. (save-restriction
  6488. (widen)
  6489. (goto-char marker)
  6490. (org-remove-subtree-entries-from-agenda)
  6491. (org-refile goto buffer rfloc)))))
  6492. (unless no-update (org-agenda-redo))))
  6493. (defun org-agenda-open-link (&optional arg)
  6494. "Follow the link in the current line, if any.
  6495. This looks for a link in the displayed line in the agenda. It also looks
  6496. at the text of the entry itself."
  6497. (interactive "P")
  6498. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6499. (org-get-at-bol 'org-marker)))
  6500. (buffer (and marker (marker-buffer marker)))
  6501. (prefix (buffer-substring
  6502. (point-at-bol) (point-at-eol))))
  6503. (cond
  6504. (buffer
  6505. (with-current-buffer buffer
  6506. (save-excursion
  6507. (save-restriction
  6508. (widen)
  6509. (goto-char marker)
  6510. (org-offer-links-in-entry arg prefix)))))
  6511. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6512. (save-excursion
  6513. (beginning-of-line 1)
  6514. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6515. (org-open-link-from-string (match-string 1)))
  6516. (t (error "No link to open here")))))
  6517. (defun org-agenda-copy-local-variable (var)
  6518. "Get a variable from a referenced buffer and install it here."
  6519. (let ((m (org-get-at-bol 'org-marker)))
  6520. (when (and m (buffer-live-p (marker-buffer m)))
  6521. (org-set-local var (with-current-buffer (marker-buffer m)
  6522. (symbol-value var))))))
  6523. (defun org-agenda-switch-to (&optional delete-other-windows)
  6524. "Go to the Org-mode file which contains the item at point."
  6525. (interactive)
  6526. (if (and org-return-follows-link
  6527. (not (org-get-at-bol 'org-marker))
  6528. (org-in-regexp org-bracket-link-regexp))
  6529. (org-open-link-from-string (match-string 0))
  6530. (let* ((marker (or (org-get-at-bol 'org-marker)
  6531. (org-agenda-error)))
  6532. (buffer (marker-buffer marker))
  6533. (pos (marker-position marker)))
  6534. (org-pop-to-buffer-same-window buffer)
  6535. (and delete-other-windows (delete-other-windows))
  6536. (widen)
  6537. (goto-char pos)
  6538. (when (eq major-mode 'org-mode)
  6539. (org-show-context 'agenda)
  6540. (save-excursion
  6541. (and (outline-next-heading)
  6542. (org-flag-heading nil))) ; show the next heading
  6543. (when (outline-invisible-p)
  6544. (show-entry)))))) ; display invisible text
  6545. (defun org-agenda-goto-mouse (ev)
  6546. "Go to the Org-mode file which contains the item at the mouse click."
  6547. (interactive "e")
  6548. (mouse-set-point ev)
  6549. (org-agenda-goto))
  6550. (defun org-agenda-show (&optional full-entry)
  6551. "Display the Org-mode file which contains the item at point.
  6552. With prefix argument FULL-ENTRY, make the entire entry visible
  6553. if it was hidden in the outline."
  6554. (interactive "P")
  6555. (let ((win (selected-window)))
  6556. (if full-entry
  6557. (let ((org-show-entry-below t))
  6558. (org-agenda-goto t))
  6559. (org-agenda-goto t))
  6560. (select-window win)))
  6561. (defvar org-agenda-show-window nil)
  6562. (defun org-agenda-show-and-scroll-up ()
  6563. "Display the Org-mode file which contains the item at point.
  6564. When called repeatedly, scroll the window that is displaying the buffer."
  6565. (interactive)
  6566. (let ((win (selected-window)))
  6567. (if (and (window-live-p org-agenda-show-window)
  6568. (eq this-command last-command))
  6569. (progn
  6570. (select-window org-agenda-show-window)
  6571. (ignore-errors (scroll-up)))
  6572. (org-agenda-goto t)
  6573. (show-subtree)
  6574. (setq org-agenda-show-window (selected-window)))
  6575. (select-window win)))
  6576. (defun org-agenda-show-scroll-down ()
  6577. "Scroll down the window showing the agenda."
  6578. (interactive)
  6579. (let ((win (selected-window)))
  6580. (when (window-live-p org-agenda-show-window)
  6581. (select-window org-agenda-show-window)
  6582. (ignore-errors (scroll-down))
  6583. (select-window win))))
  6584. (defun org-agenda-show-1 (&optional more)
  6585. "Display the Org-mode file which contains the item at point.
  6586. The prefix arg selects the amount of information to display:
  6587. 0 hide the subtree
  6588. 1 just show the entry according to defaults.
  6589. 2 show the children view
  6590. 3 show the subtree view
  6591. 4 show the entire subtree and any LOGBOOK drawers
  6592. 5 show the entire subtree and any drawers
  6593. With prefix argument FULL-ENTRY, make the entire entry visible
  6594. if it was hidden in the outline."
  6595. (interactive "p")
  6596. (let ((win (selected-window)))
  6597. (org-agenda-goto t)
  6598. (org-recenter-heading 1)
  6599. (cond
  6600. ((= more 0)
  6601. (hide-subtree)
  6602. (save-excursion
  6603. (org-back-to-heading)
  6604. (run-hook-with-args 'org-cycle-hook 'folded))
  6605. (message "Remote: FOLDED"))
  6606. ((and (org-called-interactively-p 'any) (= more 1))
  6607. (message "Remote: show with default settings"))
  6608. ((= more 2)
  6609. (show-entry)
  6610. (show-children)
  6611. (save-excursion
  6612. (org-back-to-heading)
  6613. (run-hook-with-args 'org-cycle-hook 'children))
  6614. (message "Remote: CHILDREN"))
  6615. ((= more 3)
  6616. (show-subtree)
  6617. (save-excursion
  6618. (org-back-to-heading)
  6619. (run-hook-with-args 'org-cycle-hook 'subtree))
  6620. (message "Remote: SUBTREE"))
  6621. ((= more 4)
  6622. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6623. (org-drawer-regexp
  6624. (concat "^[ \t]*:\\("
  6625. (mapconcat 'regexp-quote org-drawers "\\|")
  6626. "\\):[ \t]*$")))
  6627. (show-subtree)
  6628. (save-excursion
  6629. (org-back-to-heading)
  6630. (org-cycle-hide-drawers 'subtree)))
  6631. (message "Remote: SUBTREE AND LOGBOOK"))
  6632. ((> more 4)
  6633. (show-subtree)
  6634. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6635. (select-window win)))
  6636. (defun org-recenter-heading (n)
  6637. (save-excursion
  6638. (org-back-to-heading)
  6639. (recenter n)))
  6640. (defvar org-agenda-cycle-counter nil)
  6641. (defun org-agenda-cycle-show (&optional n)
  6642. "Show the current entry in another window, with default settings.
  6643. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6644. When use repeatedly in immediate succession, the remote entry will cycle
  6645. through visibility
  6646. children -> subtree -> folded
  6647. When called with a numeric prefix arg, that arg will be passed through to
  6648. `org-agenda-show-1'. For the interpretation of that argument, see the
  6649. docstring of `org-agenda-show-1'."
  6650. (interactive "P")
  6651. (if (integerp n)
  6652. (setq org-agenda-cycle-counter n)
  6653. (if (not (eq last-command this-command))
  6654. (setq org-agenda-cycle-counter 1)
  6655. (if (equal org-agenda-cycle-counter 0)
  6656. (setq org-agenda-cycle-counter 2)
  6657. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6658. (if (> org-agenda-cycle-counter 3)
  6659. (setq org-agenda-cycle-counter 0)))))
  6660. (org-agenda-show-1 org-agenda-cycle-counter))
  6661. (defun org-agenda-recenter (arg)
  6662. "Display the Org-mode file which contains the item at point and recenter."
  6663. (interactive "P")
  6664. (let ((win (selected-window)))
  6665. (org-agenda-goto t)
  6666. (recenter arg)
  6667. (select-window win)))
  6668. (defun org-agenda-show-mouse (ev)
  6669. "Display the Org-mode file which contains the item at the mouse click."
  6670. (interactive "e")
  6671. (mouse-set-point ev)
  6672. (org-agenda-show))
  6673. (defun org-agenda-check-no-diary ()
  6674. "Check if the entry is a diary link and abort if yes."
  6675. (if (org-get-at-bol 'org-agenda-diary-link)
  6676. (org-agenda-error)))
  6677. (defun org-agenda-error ()
  6678. (error "Command not allowed in this line"))
  6679. (defun org-agenda-tree-to-indirect-buffer ()
  6680. "Show the subtree corresponding to the current entry in an indirect buffer.
  6681. This calls the command `org-tree-to-indirect-buffer' from the original
  6682. Org-mode buffer.
  6683. With numerical prefix arg ARG, go up to this level and then take that tree.
  6684. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6685. use the dedicated frame)."
  6686. (interactive)
  6687. (org-agenda-check-no-diary)
  6688. (let* ((marker (or (org-get-at-bol 'org-marker)
  6689. (org-agenda-error)))
  6690. (buffer (marker-buffer marker))
  6691. (pos (marker-position marker)))
  6692. (with-current-buffer buffer
  6693. (save-excursion
  6694. (goto-char pos)
  6695. (call-interactively 'org-tree-to-indirect-buffer)))))
  6696. (defvar org-last-heading-marker (make-marker)
  6697. "Marker pointing to the headline that last changed its TODO state
  6698. by a remote command from the agenda.")
  6699. (defun org-agenda-todo-nextset ()
  6700. "Switch TODO entry to next sequence."
  6701. (interactive)
  6702. (org-agenda-todo 'nextset))
  6703. (defun org-agenda-todo-previousset ()
  6704. "Switch TODO entry to previous sequence."
  6705. (interactive)
  6706. (org-agenda-todo 'previousset))
  6707. (defun org-agenda-todo (&optional arg)
  6708. "Cycle TODO state of line at point, also in Org-mode file.
  6709. This changes the line at point, all other lines in the agenda referring to
  6710. the same tree node, and the headline of the tree node in the Org-mode file."
  6711. (interactive "P")
  6712. (org-agenda-check-no-diary)
  6713. (let* ((col (current-column))
  6714. (marker (or (org-get-at-bol 'org-marker)
  6715. (org-agenda-error)))
  6716. (buffer (marker-buffer marker))
  6717. (pos (marker-position marker))
  6718. (hdmarker (org-get-at-bol 'org-hd-marker))
  6719. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  6720. (inhibit-read-only t)
  6721. org-agenda-headline-snapshot-before-repeat newhead just-one)
  6722. (org-with-remote-undo buffer
  6723. (with-current-buffer buffer
  6724. (widen)
  6725. (goto-char pos)
  6726. (org-show-context 'agenda)
  6727. (save-excursion
  6728. (and (outline-next-heading)
  6729. (org-flag-heading nil))) ; show the next heading
  6730. (let ((current-prefix-arg arg))
  6731. (call-interactively 'org-todo))
  6732. (and (bolp) (forward-char 1))
  6733. (setq newhead (org-get-heading))
  6734. (when (and (org-bound-and-true-p
  6735. org-agenda-headline-snapshot-before-repeat)
  6736. (not (equal org-agenda-headline-snapshot-before-repeat
  6737. newhead))
  6738. todayp)
  6739. (setq newhead org-agenda-headline-snapshot-before-repeat
  6740. just-one t))
  6741. (save-excursion
  6742. (org-back-to-heading)
  6743. (move-marker org-last-heading-marker (point))))
  6744. (beginning-of-line 1)
  6745. (save-excursion
  6746. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  6747. (org-move-to-column col))))
  6748. (defun org-agenda-add-note (&optional arg)
  6749. "Add a time-stamped note to the entry at point."
  6750. (interactive "P")
  6751. (org-agenda-check-no-diary)
  6752. (let* ((marker (or (org-get-at-bol 'org-marker)
  6753. (org-agenda-error)))
  6754. (buffer (marker-buffer marker))
  6755. (pos (marker-position marker))
  6756. (hdmarker (org-get-at-bol 'org-hd-marker))
  6757. (inhibit-read-only t))
  6758. (with-current-buffer buffer
  6759. (widen)
  6760. (goto-char pos)
  6761. (org-show-context 'agenda)
  6762. (save-excursion
  6763. (and (outline-next-heading)
  6764. (org-flag-heading nil))) ; show the next heading
  6765. (org-add-note))))
  6766. (defun org-agenda-change-all-lines (newhead hdmarker
  6767. &optional fixface just-this)
  6768. "Change all lines in the agenda buffer which match HDMARKER.
  6769. The new content of the line will be NEWHEAD (as modified by
  6770. `org-agenda-format-item'). HDMARKER is checked with
  6771. `equal' against all `org-hd-marker' text properties in the file.
  6772. If FIXFACE is non-nil, the face of each item is modified according to
  6773. the new TODO state.
  6774. If JUST-THIS is non-nil, change just the current line, not all.
  6775. If FORCE-TAGS is non nil, the car of it returns the new tags."
  6776. (let* ((inhibit-read-only t)
  6777. (line (org-current-line))
  6778. (thetags (with-current-buffer (marker-buffer hdmarker)
  6779. (save-excursion (save-restriction (widen)
  6780. (goto-char hdmarker)
  6781. (org-get-tags-at)))))
  6782. props m pl undone-face done-face finish new dotime cat tags)
  6783. (save-excursion
  6784. (goto-char (point-max))
  6785. (beginning-of-line 1)
  6786. (while (not finish)
  6787. (setq finish (bobp))
  6788. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  6789. (or (not just-this) (= (org-current-line) line))
  6790. (equal m hdmarker))
  6791. (setq props (text-properties-at (point))
  6792. dotime (org-get-at-bol 'dotime)
  6793. cat (org-get-at-bol 'org-category)
  6794. tags thetags
  6795. new
  6796. (let ((org-prefix-format-compiled
  6797. (or (get-text-property (point) 'format)
  6798. org-prefix-format-compiled)))
  6799. (with-current-buffer (marker-buffer hdmarker)
  6800. (save-excursion
  6801. (save-restriction
  6802. (widen)
  6803. (org-agenda-format-item (org-get-at-bol 'extra)
  6804. newhead cat tags dotime)))))
  6805. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  6806. undone-face (org-get-at-bol 'undone-face)
  6807. done-face (org-get-at-bol 'done-face))
  6808. (beginning-of-line 1)
  6809. (cond
  6810. ((equal new "")
  6811. (and (looking-at ".*\n?") (replace-match "")))
  6812. ((looking-at ".*")
  6813. (replace-match new t t)
  6814. (beginning-of-line 1)
  6815. (add-text-properties (point-at-bol) (point-at-eol) props)
  6816. (when fixface
  6817. (add-text-properties
  6818. (point-at-bol) (point-at-eol)
  6819. (list 'face
  6820. (if org-last-todo-state-is-todo
  6821. undone-face done-face))))
  6822. (org-agenda-highlight-todo 'line)
  6823. (beginning-of-line 1))
  6824. (t (error "Line update did not work"))))
  6825. (beginning-of-line 0)))
  6826. (org-finalize-agenda)))
  6827. (defun org-agenda-align-tags (&optional line)
  6828. "Align all tags in agenda items to `org-agenda-tags-column'."
  6829. (let ((inhibit-read-only t) l c)
  6830. (save-excursion
  6831. (goto-char (if line (point-at-bol) (point-min)))
  6832. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  6833. (if line (point-at-eol) nil) t)
  6834. (add-text-properties
  6835. (match-beginning 2) (match-end 2)
  6836. (list 'face (delq nil (let ((prop (get-text-property
  6837. (match-beginning 2) 'face)))
  6838. (or (listp prop) (setq prop (list prop)))
  6839. (if (memq 'org-tag prop)
  6840. prop
  6841. (cons 'org-tag prop))))))
  6842. (setq l (- (match-end 2) (match-beginning 2))
  6843. c (if (< org-agenda-tags-column 0)
  6844. (- (abs org-agenda-tags-column) l)
  6845. org-agenda-tags-column))
  6846. (delete-region (match-beginning 1) (match-end 1))
  6847. (goto-char (match-beginning 1))
  6848. (insert (org-add-props
  6849. (make-string (max 1 (- c (current-column))) ?\ )
  6850. (plist-put (copy-sequence (text-properties-at (point)))
  6851. 'face nil))))
  6852. (goto-char (point-min))
  6853. (org-font-lock-add-tag-faces (point-max)))))
  6854. (defun org-agenda-priority-up ()
  6855. "Increase the priority of line at point, also in Org-mode file."
  6856. (interactive)
  6857. (org-agenda-priority 'up))
  6858. (defun org-agenda-priority-down ()
  6859. "Decrease the priority of line at point, also in Org-mode file."
  6860. (interactive)
  6861. (org-agenda-priority 'down))
  6862. (defun org-agenda-priority (&optional force-direction)
  6863. "Set the priority of line at point, also in Org-mode file.
  6864. This changes the line at point, all other lines in the agenda referring to
  6865. the same tree node, and the headline of the tree node in the Org-mode file."
  6866. (interactive)
  6867. (unless org-enable-priority-commands
  6868. (error "Priority commands are disabled"))
  6869. (org-agenda-check-no-diary)
  6870. (let* ((marker (or (org-get-at-bol 'org-marker)
  6871. (org-agenda-error)))
  6872. (hdmarker (org-get-at-bol 'org-hd-marker))
  6873. (buffer (marker-buffer hdmarker))
  6874. (pos (marker-position hdmarker))
  6875. (inhibit-read-only t)
  6876. newhead)
  6877. (org-with-remote-undo buffer
  6878. (with-current-buffer buffer
  6879. (widen)
  6880. (goto-char pos)
  6881. (org-show-context 'agenda)
  6882. (save-excursion
  6883. (and (outline-next-heading)
  6884. (org-flag-heading nil))) ; show the next heading
  6885. (funcall 'org-priority force-direction)
  6886. (end-of-line 1)
  6887. (setq newhead (org-get-heading)))
  6888. (org-agenda-change-all-lines newhead hdmarker)
  6889. (beginning-of-line 1))))
  6890. ;; FIXME: should fix the tags property of the agenda line.
  6891. (defun org-agenda-set-tags (&optional tag onoff)
  6892. "Set tags for the current headline."
  6893. (interactive)
  6894. (org-agenda-check-no-diary)
  6895. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  6896. (call-interactively 'org-change-tag-in-region)
  6897. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6898. (org-agenda-error)))
  6899. (buffer (marker-buffer hdmarker))
  6900. (pos (marker-position hdmarker))
  6901. (inhibit-read-only t)
  6902. newhead)
  6903. (org-with-remote-undo buffer
  6904. (with-current-buffer buffer
  6905. (widen)
  6906. (goto-char pos)
  6907. (save-excursion
  6908. (org-show-context 'agenda))
  6909. (save-excursion
  6910. (and (outline-next-heading)
  6911. (org-flag-heading nil))) ; show the next heading
  6912. (goto-char pos)
  6913. (if tag
  6914. (org-toggle-tag tag onoff)
  6915. (call-interactively 'org-set-tags))
  6916. (end-of-line 1)
  6917. (setq newhead (org-get-heading)))
  6918. (org-agenda-change-all-lines newhead hdmarker)
  6919. (beginning-of-line 1)))))
  6920. (defun org-agenda-set-property ()
  6921. "Set a property for the current headline."
  6922. (interactive)
  6923. (org-agenda-check-no-diary)
  6924. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6925. (org-agenda-error)))
  6926. (buffer (marker-buffer hdmarker))
  6927. (pos (marker-position hdmarker))
  6928. (inhibit-read-only t)
  6929. newhead)
  6930. (org-with-remote-undo buffer
  6931. (with-current-buffer buffer
  6932. (widen)
  6933. (goto-char pos)
  6934. (save-excursion
  6935. (org-show-context 'agenda))
  6936. (save-excursion
  6937. (and (outline-next-heading)
  6938. (org-flag-heading nil))) ; show the next heading
  6939. (goto-char pos)
  6940. (call-interactively 'org-set-property)))))
  6941. (defun org-agenda-set-effort ()
  6942. "Set the effort property for the current headline."
  6943. (interactive)
  6944. (org-agenda-check-no-diary)
  6945. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6946. (org-agenda-error)))
  6947. (buffer (marker-buffer hdmarker))
  6948. (pos (marker-position hdmarker))
  6949. (inhibit-read-only t)
  6950. newhead)
  6951. (org-with-remote-undo buffer
  6952. (with-current-buffer buffer
  6953. (widen)
  6954. (goto-char pos)
  6955. (save-excursion
  6956. (org-show-context 'agenda))
  6957. (save-excursion
  6958. (and (outline-next-heading)
  6959. (org-flag-heading nil))) ; show the next heading
  6960. (goto-char pos)
  6961. (call-interactively 'org-set-effort)
  6962. (end-of-line 1)
  6963. (setq newhead (org-get-heading)))
  6964. (org-agenda-change-all-lines newhead hdmarker))))
  6965. (defun org-agenda-toggle-archive-tag ()
  6966. "Toggle the archive tag for the current entry."
  6967. (interactive)
  6968. (org-agenda-check-no-diary)
  6969. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6970. (org-agenda-error)))
  6971. (buffer (marker-buffer hdmarker))
  6972. (pos (marker-position hdmarker))
  6973. (inhibit-read-only t)
  6974. newhead)
  6975. (org-with-remote-undo buffer
  6976. (with-current-buffer buffer
  6977. (widen)
  6978. (goto-char pos)
  6979. (org-show-context 'agenda)
  6980. (save-excursion
  6981. (and (outline-next-heading)
  6982. (org-flag-heading nil))) ; show the next heading
  6983. (call-interactively 'org-toggle-archive-tag)
  6984. (end-of-line 1)
  6985. (setq newhead (org-get-heading)))
  6986. (org-agenda-change-all-lines newhead hdmarker)
  6987. (beginning-of-line 1))))
  6988. (defun org-agenda-do-date-later (arg)
  6989. (interactive "P")
  6990. (cond
  6991. ((or (equal arg '(16))
  6992. (memq last-command
  6993. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6994. (setq this-command 'org-agenda-date-later-minutes)
  6995. (org-agenda-date-later-minutes 1))
  6996. ((or (equal arg '(4))
  6997. (memq last-command
  6998. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6999. (setq this-command 'org-agenda-date-later-hours)
  7000. (org-agenda-date-later-hours 1))
  7001. (t
  7002. (org-agenda-date-later (prefix-numeric-value arg)))))
  7003. (defun org-agenda-do-date-earlier (arg)
  7004. (interactive "P")
  7005. (cond
  7006. ((or (equal arg '(16))
  7007. (memq last-command
  7008. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7009. (setq this-command 'org-agenda-date-earlier-minutes)
  7010. (org-agenda-date-earlier-minutes 1))
  7011. ((or (equal arg '(4))
  7012. (memq last-command
  7013. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7014. (setq this-command 'org-agenda-date-earlier-hours)
  7015. (org-agenda-date-earlier-hours 1))
  7016. (t
  7017. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7018. (defun org-agenda-date-later (arg &optional what)
  7019. "Change the date of this item to ARG day(s) later."
  7020. (interactive "p")
  7021. (org-agenda-check-type t 'agenda 'timeline)
  7022. (org-agenda-check-no-diary)
  7023. (let* ((marker (or (org-get-at-bol 'org-marker)
  7024. (org-agenda-error)))
  7025. (buffer (marker-buffer marker))
  7026. (pos (marker-position marker))
  7027. cdate today)
  7028. (org-with-remote-undo buffer
  7029. (with-current-buffer buffer
  7030. (widen)
  7031. (goto-char pos)
  7032. (if (not (org-at-timestamp-p))
  7033. (error "Cannot find time stamp"))
  7034. (when (and org-agenda-move-date-from-past-immediately-to-today
  7035. (equal arg 1)
  7036. (or (not what) (eq what 'day))
  7037. (not (save-match-data (org-at-date-range-p))))
  7038. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7039. cdate (calendar-absolute-from-gregorian
  7040. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7041. today (org-today))
  7042. (if (> today cdate)
  7043. ;; immediately shift to today
  7044. (setq arg (- today cdate))))
  7045. (org-timestamp-change arg (or what 'day))
  7046. (when (and (org-at-date-range-p)
  7047. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7048. (let ((end org-last-changed-timestamp))
  7049. (org-timestamp-change arg (or what 'day))
  7050. (setq org-last-changed-timestamp
  7051. (concat org-last-changed-timestamp "--" end)))))
  7052. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7053. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7054. (defun org-agenda-date-earlier (arg &optional what)
  7055. "Change the date of this item to ARG day(s) earlier."
  7056. (interactive "p")
  7057. (org-agenda-date-later (- arg) what))
  7058. (defun org-agenda-date-later-minutes (arg)
  7059. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7060. (interactive "p")
  7061. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7062. (org-agenda-date-later arg 'minute))
  7063. (defun org-agenda-date-earlier-minutes (arg)
  7064. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7065. (interactive "p")
  7066. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7067. (org-agenda-date-earlier arg 'minute))
  7068. (defun org-agenda-date-later-hours (arg)
  7069. "Change the time of this item, in hour steps."
  7070. (interactive "p")
  7071. (org-agenda-date-later arg 'hour))
  7072. (defun org-agenda-date-earlier-hours (arg)
  7073. "Change the time of this item, in hour steps."
  7074. (interactive "p")
  7075. (org-agenda-date-earlier arg 'hour))
  7076. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7077. "Show new date stamp via text properties."
  7078. ;; We use text properties to make this undoable
  7079. (let ((inhibit-read-only t)
  7080. (buffer-invisibility-spec))
  7081. (setq stamp (concat " " prefix " => " stamp))
  7082. (save-excursion
  7083. (goto-char (point-max))
  7084. (while (not (bobp))
  7085. (when (equal marker (org-get-at-bol 'org-marker))
  7086. (org-move-to-column (- (window-width) (length stamp)) t)
  7087. (org-agenda-fix-tags-filter-overlays-at (point))
  7088. (if (featurep 'xemacs)
  7089. ;; Use `duplicable' property to trigger undo recording
  7090. (let ((ex (make-extent nil nil))
  7091. (gl (make-glyph stamp)))
  7092. (set-glyph-face gl 'secondary-selection)
  7093. (set-extent-properties
  7094. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7095. (insert-extent ex (1- (point)) (point-at-eol)))
  7096. (add-text-properties
  7097. (1- (point)) (point-at-eol)
  7098. (list 'display (org-add-props stamp nil
  7099. 'face 'secondary-selection))))
  7100. (beginning-of-line 1))
  7101. (beginning-of-line 0)))))
  7102. (defun org-agenda-date-prompt (arg)
  7103. "Change the date of this item. Date is prompted for, with default today.
  7104. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7105. be used to request time specification in the time stamp."
  7106. (interactive "P")
  7107. (org-agenda-check-type t 'agenda 'timeline)
  7108. (org-agenda-check-no-diary)
  7109. (let* ((marker (or (org-get-at-bol 'org-marker)
  7110. (org-agenda-error)))
  7111. (buffer (marker-buffer marker))
  7112. (pos (marker-position marker)))
  7113. (org-with-remote-undo buffer
  7114. (with-current-buffer buffer
  7115. (widen)
  7116. (goto-char pos)
  7117. (if (not (org-at-timestamp-p t))
  7118. (error "Cannot find time stamp"))
  7119. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7120. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7121. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7122. (defun org-agenda-schedule (arg &optional time)
  7123. "Schedule the item at point.
  7124. ARG is passed through to `org-schedule'."
  7125. (interactive "P")
  7126. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7127. (org-agenda-check-no-diary)
  7128. (let* ((marker (or (org-get-at-bol 'org-marker)
  7129. (org-agenda-error)))
  7130. (type (marker-insertion-type marker))
  7131. (buffer (marker-buffer marker))
  7132. (pos (marker-position marker))
  7133. (org-insert-labeled-timestamps-at-point nil)
  7134. ts)
  7135. (set-marker-insertion-type marker t)
  7136. (org-with-remote-undo buffer
  7137. (with-current-buffer buffer
  7138. (widen)
  7139. (goto-char pos)
  7140. (setq ts (org-schedule arg time)))
  7141. (org-agenda-show-new-time marker ts "S"))
  7142. (message "Item scheduled for %s" ts)))
  7143. (defun org-agenda-deadline (arg &optional time)
  7144. "Schedule the item at point.
  7145. ARG is passed through to `org-deadline'."
  7146. (interactive "P")
  7147. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7148. (org-agenda-check-no-diary)
  7149. (let* ((marker (or (org-get-at-bol 'org-marker)
  7150. (org-agenda-error)))
  7151. (buffer (marker-buffer marker))
  7152. (pos (marker-position marker))
  7153. (org-insert-labeled-timestamps-at-point nil)
  7154. ts)
  7155. (org-with-remote-undo buffer
  7156. (with-current-buffer buffer
  7157. (widen)
  7158. (goto-char pos)
  7159. (setq ts (org-deadline arg time)))
  7160. (org-agenda-show-new-time marker ts "D"))
  7161. (message "Deadline for this item set to %s" ts)))
  7162. (defun org-agenda-action ()
  7163. "Select entry for agenda action, or execute an agenda action.
  7164. This command prompts for another letter. Valid inputs are:
  7165. m Mark the entry at point for an agenda action
  7166. s Schedule the marked entry to the date at the cursor
  7167. d Set the deadline of the marked entry to the date at the cursor
  7168. r Call `org-remember' with cursor date as the default date
  7169. c Call `org-capture' with cursor date as the default date
  7170. SPC Show marked entry in other window
  7171. TAB Visit marked entry in other window
  7172. The cursor may be at a date in the calendar, or in the Org agenda."
  7173. (interactive)
  7174. (let (ans)
  7175. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7176. (setq ans (read-char-exclusive))
  7177. (cond
  7178. ((equal ans ?m)
  7179. ;; Mark this entry
  7180. (if (eq major-mode 'org-agenda-mode)
  7181. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7182. (org-get-at-bol 'org-marker))))
  7183. (if m
  7184. (progn
  7185. (move-marker org-agenda-action-marker
  7186. (marker-position m) (marker-buffer m))
  7187. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7188. (error "Don't know which entry to mark")))
  7189. (error "This command works only in the agenda")))
  7190. ((equal ans ?s)
  7191. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7192. ((equal ans ?d)
  7193. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7194. ((equal ans ?r)
  7195. (org-agenda-do-action '(org-remember) t))
  7196. ((equal ans ?c)
  7197. (org-agenda-do-action '(org-capture) t))
  7198. ((equal ans ?\ )
  7199. (let ((cw (selected-window)))
  7200. (org-switch-to-buffer-other-window
  7201. (marker-buffer org-agenda-action-marker))
  7202. (goto-char org-agenda-action-marker)
  7203. (org-show-context 'agenda)
  7204. (select-window cw)))
  7205. ((equal ans ?\C-i)
  7206. (org-switch-to-buffer-other-window
  7207. (marker-buffer org-agenda-action-marker))
  7208. (goto-char org-agenda-action-marker)
  7209. (org-show-context 'agenda))
  7210. (t (error "Invalid agenda action %c" ans)))))
  7211. (defun org-agenda-do-action (form &optional current-buffer)
  7212. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7213. (let ((org-overriding-default-time (org-get-cursor-date)))
  7214. (if current-buffer
  7215. (eval form)
  7216. (if (not (marker-buffer org-agenda-action-marker))
  7217. (error "No entry has been selected for agenda action")
  7218. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7219. (save-excursion
  7220. (save-restriction
  7221. (widen)
  7222. (goto-char org-agenda-action-marker)
  7223. (eval form))))))))
  7224. (defun org-agenda-clock-in (&optional arg)
  7225. "Start the clock on the currently selected item."
  7226. (interactive "P")
  7227. (org-agenda-check-no-diary)
  7228. (if (equal arg '(4))
  7229. (org-clock-in arg)
  7230. (let* ((marker (or (org-get-at-bol 'org-marker)
  7231. (org-agenda-error)))
  7232. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7233. marker))
  7234. (pos (marker-position marker))
  7235. newhead)
  7236. (org-with-remote-undo (marker-buffer marker)
  7237. (with-current-buffer (marker-buffer marker)
  7238. (widen)
  7239. (goto-char pos)
  7240. (org-show-context 'agenda)
  7241. (org-show-entry)
  7242. (org-cycle-hide-drawers 'children)
  7243. (org-clock-in arg)
  7244. (setq newhead (org-get-heading)))
  7245. (org-agenda-change-all-lines newhead hdmarker)))))
  7246. (defun org-agenda-clock-out ()
  7247. "Stop the currently running clock."
  7248. (interactive)
  7249. (unless (marker-buffer org-clock-marker)
  7250. (error "No running clock"))
  7251. (let ((marker (make-marker)) newhead)
  7252. (org-with-remote-undo (marker-buffer org-clock-marker)
  7253. (with-current-buffer (marker-buffer org-clock-marker)
  7254. (save-excursion
  7255. (save-restriction
  7256. (widen)
  7257. (goto-char org-clock-marker)
  7258. (org-back-to-heading t)
  7259. (move-marker marker (point))
  7260. (org-clock-out)
  7261. (setq newhead (org-get-heading))))))
  7262. (org-agenda-change-all-lines newhead marker)
  7263. (move-marker marker nil)))
  7264. (defun org-agenda-clock-cancel (&optional arg)
  7265. "Cancel the currently running clock."
  7266. (interactive "P")
  7267. (unless (marker-buffer org-clock-marker)
  7268. (error "No running clock"))
  7269. (org-with-remote-undo (marker-buffer org-clock-marker)
  7270. (org-clock-cancel)))
  7271. (defun org-agenda-clock-goto ()
  7272. "Jump to the currently clocked in task within the agenda.
  7273. If the currently clocked in task is not listed in the agenda
  7274. buffer, display it in another window."
  7275. (interactive)
  7276. (let (pos)
  7277. (mapc (lambda (o)
  7278. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7279. (setq pos (overlay-start o))))
  7280. (overlays-in (point-min) (point-max)))
  7281. (cond (pos (goto-char pos))
  7282. ;; If the currently clocked entry is not in the agenda
  7283. ;; buffer, we visit it in another window:
  7284. (org-clock-current-task
  7285. (org-switch-to-buffer-other-window (org-clock-goto)))
  7286. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7287. (defun org-agenda-diary-entry-in-org-file ()
  7288. "Make a diary entry in the file `org-agenda-diary-file'."
  7289. (let (d1 d2 char (text "") dp1 dp2)
  7290. (if (equal (buffer-name) "*Calendar*")
  7291. (setq d1 (calendar-cursor-to-date t)
  7292. d2 (car calendar-mark-ring))
  7293. (setq dp1 (get-text-property (point-at-bol) 'day))
  7294. (unless dp1 (error "No date defined in current line"))
  7295. (setq d1 (calendar-gregorian-from-absolute dp1)
  7296. d2 (and (ignore-errors (mark))
  7297. (save-excursion
  7298. (goto-char (mark))
  7299. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7300. (calendar-gregorian-from-absolute dp2))))
  7301. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7302. (setq char (read-char-exclusive))
  7303. (cond
  7304. ((equal char ?d)
  7305. (setq text (read-string "Day entry: "))
  7306. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7307. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7308. ((equal char ?a)
  7309. (setq d1 (list (car d1) (nth 1 d1)
  7310. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7311. (nth 2 d1))))
  7312. (setq text (read-string "Anniversary (use %d to show years): "))
  7313. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7314. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7315. ((equal char ?b)
  7316. (setq text (read-string "Block entry: "))
  7317. (unless (and d1 d2 (not (equal d1 d2)))
  7318. (error "No block of days selected"))
  7319. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7320. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7321. ((equal char ?j)
  7322. (org-switch-to-buffer-other-window
  7323. (find-file-noselect org-agenda-diary-file))
  7324. (require 'org-datetree)
  7325. (org-datetree-find-date-create d1)
  7326. (org-reveal t))
  7327. (t (error "Invalid selection character `%c'" char)))))
  7328. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7329. "Where in `org-agenda-diary-file' should new entries be added?
  7330. Valid values:
  7331. date-tree in the date tree, as child of the date
  7332. top-level as top-level entries at the end of the file."
  7333. :group 'org-agenda
  7334. :type '(choice
  7335. (const :tag "in a date tree" date-tree)
  7336. (const :tag "as top level at end of file" top-level)))
  7337. (defcustom org-agenda-insert-diary-extract-time nil
  7338. "Non-nil means extract any time specification from the diary entry."
  7339. :group 'org-agenda
  7340. :type 'boolean)
  7341. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7342. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7343. If TEXT is not empty, it will become the headline of the new entry, and
  7344. the resulting entry will not be shown. When TEXT is empty, switch to
  7345. `org-agenda-diary-file' and let the user finish the entry there."
  7346. (let ((cw (current-window-configuration)))
  7347. (org-switch-to-buffer-other-window
  7348. (find-file-noselect org-agenda-diary-file))
  7349. (widen)
  7350. (goto-char (point-min))
  7351. (cond
  7352. ((eq type 'anniversary)
  7353. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7354. (progn
  7355. (or (org-on-heading-p t)
  7356. (progn
  7357. (outline-next-heading)
  7358. (insert "* Anniversaries\n\n")
  7359. (beginning-of-line -1)))))
  7360. (outline-next-heading)
  7361. (org-back-over-empty-lines)
  7362. (backward-char 1)
  7363. (insert "\n")
  7364. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7365. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7366. ((eq type 'day)
  7367. (let ((org-prefix-has-time t)
  7368. (org-agenda-time-leading-zero t)
  7369. fmt time time2)
  7370. (if org-agenda-insert-diary-extract-time
  7371. ;; Use org-agenda-format-item to parse text for a time-range and
  7372. ;; remove it. FIXME: This is a hack, we should refactor
  7373. ;; that function to make time extraction available separately
  7374. (setq fmt (org-agenda-format-item nil text nil nil t)
  7375. time (get-text-property 0 'time fmt)
  7376. time2 (if (> (length time) 0)
  7377. ;; split-string removes trailing ...... if
  7378. ;; no end time given. First space
  7379. ;; separates time from date.
  7380. (concat " " (car (split-string time "\\.")))
  7381. nil)
  7382. text (get-text-property 0 'txt fmt)))
  7383. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7384. (org-agenda-insert-diary-as-top-level text)
  7385. (require 'org-datetree)
  7386. (org-datetree-find-date-create d1)
  7387. (org-agenda-insert-diary-make-new-entry text))
  7388. (org-insert-time-stamp (org-time-from-absolute
  7389. (calendar-absolute-from-gregorian d1))
  7390. nil nil nil nil time2))
  7391. (end-of-line 0))
  7392. ((eq type 'block)
  7393. (if (> (calendar-absolute-from-gregorian d1)
  7394. (calendar-absolute-from-gregorian d2))
  7395. (setq d1 (prog1 d2 (setq d2 d1))))
  7396. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7397. (org-agenda-insert-diary-as-top-level text)
  7398. (require 'org-datetree)
  7399. (org-datetree-find-date-create d1)
  7400. (org-agenda-insert-diary-make-new-entry text))
  7401. (org-insert-time-stamp (org-time-from-absolute
  7402. (calendar-absolute-from-gregorian d1)))
  7403. (insert "--")
  7404. (org-insert-time-stamp (org-time-from-absolute
  7405. (calendar-absolute-from-gregorian d2)))
  7406. (end-of-line 0)))
  7407. (if (string-match "\\S-" text)
  7408. (progn
  7409. (set-window-configuration cw)
  7410. (message "%s entry added to %s"
  7411. (capitalize (symbol-name type))
  7412. (abbreviate-file-name org-agenda-diary-file)))
  7413. (org-reveal t)
  7414. (message "Please finish entry here"))))
  7415. (defun org-agenda-insert-diary-as-top-level (text)
  7416. "Make new entry as a top-level entry at the end of the file.
  7417. Add TEXT as headline, and position the cursor in the second line so that
  7418. a timestamp can be added there."
  7419. (widen)
  7420. (goto-char (point-max))
  7421. (or (bolp) (insert "\n"))
  7422. (insert "* " text "\n")
  7423. (if org-adapt-indentation (org-indent-to-column 2)))
  7424. (defun org-agenda-insert-diary-make-new-entry (text)
  7425. "Make new entry as last child of current entry.
  7426. Add TEXT as headline, and position the cursor in the second line so that
  7427. a timestamp can be added there."
  7428. (let ((org-show-following-heading t)
  7429. (org-show-siblings t)
  7430. (org-show-hierarchy-above t)
  7431. (org-show-entry-below t)
  7432. col)
  7433. (outline-next-heading)
  7434. (org-back-over-empty-lines)
  7435. (or (looking-at "[ \t]*$")
  7436. (progn (insert "\n") (backward-char 1)))
  7437. (org-insert-heading nil t)
  7438. (org-do-demote)
  7439. (setq col (current-column))
  7440. (insert text "\n")
  7441. (if org-adapt-indentation (org-indent-to-column col))
  7442. (let ((org-show-following-heading t)
  7443. (org-show-siblings t)
  7444. (org-show-hierarchy-above t)
  7445. (org-show-entry-below t))
  7446. (org-show-context))))
  7447. (defun org-agenda-diary-entry ()
  7448. "Make a diary entry, like the `i' command from the calendar.
  7449. All the standard commands work: block, weekly etc.
  7450. When `org-agenda-diary-file' points to a file,
  7451. `org-agenda-diary-entry-in-org-file' is called instead to create
  7452. entries in that Org-mode file."
  7453. (interactive)
  7454. (org-agenda-check-type t 'agenda 'timeline)
  7455. (if (not (eq org-agenda-diary-file 'diary-file))
  7456. (org-agenda-diary-entry-in-org-file)
  7457. (require 'diary-lib)
  7458. (let* ((char (progn
  7459. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7460. (read-char-exclusive)))
  7461. (cmd (cdr (assoc char
  7462. '((?d . insert-diary-entry)
  7463. (?w . insert-weekly-diary-entry)
  7464. (?m . insert-monthly-diary-entry)
  7465. (?y . insert-yearly-diary-entry)
  7466. (?a . insert-anniversary-diary-entry)
  7467. (?b . insert-block-diary-entry)
  7468. (?c . insert-cyclic-diary-entry)))))
  7469. (oldf (symbol-function 'calendar-cursor-to-date))
  7470. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7471. (point (point))
  7472. (mark (or (mark t) (point))))
  7473. (unless cmd
  7474. (error "No command associated with <%c>" char))
  7475. (unless (and (get-text-property point 'day)
  7476. (or (not (equal ?b char))
  7477. (get-text-property mark 'day)))
  7478. (error "Don't know which date to use for diary entry"))
  7479. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7480. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7481. (let ((calendar-mark-ring
  7482. (list (calendar-gregorian-from-absolute
  7483. (or (get-text-property mark 'day)
  7484. (get-text-property point 'day))))))
  7485. (unwind-protect
  7486. (progn
  7487. (fset 'calendar-cursor-to-date
  7488. (lambda (&optional error dummy)
  7489. (calendar-gregorian-from-absolute
  7490. (get-text-property point 'day))))
  7491. (call-interactively cmd))
  7492. (fset 'calendar-cursor-to-date oldf))))))
  7493. (defun org-agenda-execute-calendar-command (cmd)
  7494. "Execute a calendar command from the agenda, with the date associated to
  7495. the cursor position."
  7496. (org-agenda-check-type t 'agenda 'timeline)
  7497. (require 'diary-lib)
  7498. (unless (get-text-property (point) 'day)
  7499. (error "Don't know which date to use for calendar command"))
  7500. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7501. (point (point))
  7502. (date (calendar-gregorian-from-absolute
  7503. (get-text-property point 'day)))
  7504. ;; the following 2 vars are needed in the calendar
  7505. (displayed-month (car date))
  7506. (displayed-year (nth 2 date)))
  7507. (unwind-protect
  7508. (progn
  7509. (fset 'calendar-cursor-to-date
  7510. (lambda (&optional error dummy)
  7511. (calendar-gregorian-from-absolute
  7512. (get-text-property point 'day))))
  7513. (call-interactively cmd))
  7514. (fset 'calendar-cursor-to-date oldf))))
  7515. (defun org-agenda-phases-of-moon ()
  7516. "Display the phases of the moon for the 3 months around the cursor date."
  7517. (interactive)
  7518. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7519. (defun org-agenda-holidays ()
  7520. "Display the holidays for the 3 months around the cursor date."
  7521. (interactive)
  7522. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7523. (defvar calendar-longitude)
  7524. (defvar calendar-latitude)
  7525. (defvar calendar-location-name)
  7526. (defun org-agenda-sunrise-sunset (arg)
  7527. "Display sunrise and sunset for the cursor date.
  7528. Latitude and longitude can be specified with the variables
  7529. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7530. argument, latitude and longitude will be prompted for."
  7531. (interactive "P")
  7532. (require 'solar)
  7533. (let ((calendar-longitude (if arg nil calendar-longitude))
  7534. (calendar-latitude (if arg nil calendar-latitude))
  7535. (calendar-location-name
  7536. (if arg "the given coordinates" calendar-location-name)))
  7537. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7538. (defun org-agenda-goto-calendar ()
  7539. "Open the Emacs calendar with the date at the cursor."
  7540. (interactive)
  7541. (org-agenda-check-type t 'agenda 'timeline)
  7542. (let* ((day (or (get-text-property (point) 'day)
  7543. (error "Don't know which date to open in calendar")))
  7544. (date (calendar-gregorian-from-absolute day))
  7545. (calendar-move-hook nil)
  7546. (calendar-view-holidays-initially-flag nil)
  7547. (calendar-view-diary-initially-flag nil))
  7548. (calendar)
  7549. (calendar-goto-date date)))
  7550. ;;;###autoload
  7551. (defun org-calendar-goto-agenda ()
  7552. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7553. This is a command that has to be installed in `calendar-mode-map'."
  7554. (interactive)
  7555. (org-agenda-list nil (calendar-absolute-from-gregorian
  7556. (calendar-cursor-to-date))
  7557. nil))
  7558. (defun org-agenda-convert-date ()
  7559. (interactive)
  7560. (org-agenda-check-type t 'agenda 'timeline)
  7561. (let ((day (get-text-property (point) 'day))
  7562. date s)
  7563. (unless day
  7564. (error "Don't know which date to convert"))
  7565. (setq date (calendar-gregorian-from-absolute day))
  7566. (setq s (concat
  7567. "Gregorian: " (calendar-date-string date) "\n"
  7568. "ISO: " (calendar-iso-date-string date) "\n"
  7569. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7570. "Julian: " (calendar-julian-date-string date) "\n"
  7571. "Astron. JD: " (calendar-astro-date-string date)
  7572. " (Julian date number at noon UTC)\n"
  7573. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7574. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7575. "French: " (calendar-french-date-string date) "\n"
  7576. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7577. "Mayan: " (calendar-mayan-date-string date) "\n"
  7578. "Coptic: " (calendar-coptic-date-string date) "\n"
  7579. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7580. "Persian: " (calendar-persian-date-string date) "\n"
  7581. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7582. (with-output-to-temp-buffer "*Dates*"
  7583. (princ s))
  7584. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7585. ;;; Bulk commands
  7586. (defvar org-agenda-bulk-marked-entries nil
  7587. "List of markers that refer to marked entries in the agenda.")
  7588. (defun org-agenda-bulk-marked-p ()
  7589. (eq (get-char-property (point-at-bol) 'type)
  7590. 'org-marked-entry-overlay))
  7591. (defun org-agenda-bulk-mark (&optional arg)
  7592. "Mark the entry at point for future bulk action."
  7593. (interactive "p")
  7594. (dotimes (i (max arg 1))
  7595. (unless (org-get-at-bol 'org-agenda-diary-link)
  7596. (let* ((m (org-get-at-bol 'org-hd-marker))
  7597. ov)
  7598. (unless (org-agenda-bulk-marked-p)
  7599. (unless m (error "Nothing to mark at point"))
  7600. (push m org-agenda-bulk-marked-entries)
  7601. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7602. (org-overlay-display ov "> "
  7603. (org-get-todo-face "TODO")
  7604. 'evaporate)
  7605. (overlay-put ov 'type 'org-marked-entry-overlay))
  7606. (beginning-of-line 2)
  7607. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7608. (beginning-of-line 2))
  7609. (message "%d entries marked for bulk action"
  7610. (length org-agenda-bulk-marked-entries))))))
  7611. (defun org-agenda-bulk-mark-regexp (regexp)
  7612. "Mark entries match REGEXP."
  7613. (interactive "sMark entries matching regexp: ")
  7614. (let (entries-marked)
  7615. (save-excursion
  7616. (goto-char (point-min))
  7617. (goto-char (next-single-property-change (point) 'txt))
  7618. (while (re-search-forward regexp nil t)
  7619. (when (string-match regexp (get-text-property (point) 'txt))
  7620. (setq entries-marked (+ entries-marked 1))
  7621. (call-interactively 'org-agenda-bulk-mark))))
  7622. (if (not entries-marked)
  7623. (message "No entry matching this regexp."))))
  7624. (defun org-agenda-bulk-unmark ()
  7625. "Unmark the entry at point for future bulk action."
  7626. (interactive)
  7627. (when (org-agenda-bulk-marked-p)
  7628. (org-agenda-bulk-remove-overlays
  7629. (point-at-bol) (+ 2 (point-at-bol)))
  7630. (setq org-agenda-bulk-marked-entries
  7631. (delete (org-get-at-bol 'org-hd-marker)
  7632. org-agenda-bulk-marked-entries)))
  7633. (beginning-of-line 2)
  7634. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7635. (beginning-of-line 2))
  7636. (message "%d entries marked for bulk action"
  7637. (length org-agenda-bulk-marked-entries)))
  7638. (defun org-agenda-bulk-toggle ()
  7639. "Toggle marking the entry at point for bulk action."
  7640. (interactive)
  7641. (if (org-agenda-bulk-marked-p)
  7642. (org-agenda-bulk-unmark)
  7643. (org-agenda-bulk-mark)))
  7644. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7645. "Remove the mark overlays between BEG and END in the agenda buffer.
  7646. BEG and END default to the buffer limits.
  7647. This only removes the overlays, it does not remove the markers
  7648. from the list in `org-agenda-bulk-marked-entries'."
  7649. (interactive)
  7650. (mapc (lambda (ov)
  7651. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7652. (delete-overlay ov)))
  7653. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7654. (defun org-agenda-bulk-remove-all-marks ()
  7655. "Remove all marks in the agenda buffer.
  7656. This will remove the markers, and the overlays."
  7657. (interactive)
  7658. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7659. (setq org-agenda-bulk-marked-entries nil)
  7660. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7661. (defun org-agenda-bulk-action (&optional arg)
  7662. "Execute an remote-editing action on all marked entries.
  7663. The prefix arg is passed through to the command if possible."
  7664. (interactive "P")
  7665. ;; Make sure we have markers, and only valid ones
  7666. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7667. (mapc
  7668. (lambda (m)
  7669. (unless (and (markerp m)
  7670. (marker-buffer m)
  7671. (buffer-live-p (marker-buffer m))
  7672. (marker-position m))
  7673. (error "Marker %s for bulk command is invalid" m)))
  7674. org-agenda-bulk-marked-entries)
  7675. ;; Prompt for the bulk command
  7676. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7677. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7678. (when org-agenda-bulk-custom-functions
  7679. (concat " Custom: ["
  7680. (mapconcat (lambda(f) (char-to-string (car f)))
  7681. org-agenda-bulk-custom-functions "")
  7682. "]"))))
  7683. (let* ((action (read-char-exclusive))
  7684. (org-log-refile (if org-log-refile 'time nil))
  7685. (entries (reverse org-agenda-bulk-marked-entries))
  7686. redo-at-end
  7687. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7688. (cond
  7689. ((equal action ?$)
  7690. (setq cmd '(org-agenda-archive)))
  7691. ((equal action ?A)
  7692. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  7693. ((member action '(?r ?w))
  7694. (setq rfloc (org-refile-get-location
  7695. "Refile to"
  7696. (marker-buffer (car org-agenda-bulk-marked-entries))
  7697. org-refile-allow-creating-parent-nodes))
  7698. (if (nth 3 rfloc)
  7699. (setcar (nthcdr 3 rfloc)
  7700. (move-marker (make-marker) (nth 3 rfloc)
  7701. (or (get-file-buffer (nth 1 rfloc))
  7702. (find-buffer-visiting (nth 1 rfloc))
  7703. (error "This should not happen")))))
  7704. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  7705. redo-at-end t))
  7706. ((equal action ?t)
  7707. (setq state (org-icompleting-read
  7708. "Todo state: "
  7709. (with-current-buffer (marker-buffer (car entries))
  7710. (mapcar 'list org-todo-keywords-1))))
  7711. (setq cmd `(let ((org-inhibit-blocking t)
  7712. (org-inhibit-logging 'note))
  7713. (org-agenda-todo ,state))))
  7714. ((memq action '(?- ?+))
  7715. (setq tag (org-icompleting-read
  7716. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  7717. (with-current-buffer (marker-buffer (car entries))
  7718. (delq nil
  7719. (mapcar (lambda (x)
  7720. (if (stringp (car x)) x)) org-tag-alist)))))
  7721. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  7722. ((memq action '(?s ?d))
  7723. (let* ((date (unless arg
  7724. (org-read-date
  7725. nil nil nil
  7726. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  7727. (ans (if arg nil org-read-date-final-answer))
  7728. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  7729. (setq cmd `(let* ((bound (fboundp 'read-string))
  7730. (old (and bound (symbol-function 'read-string))))
  7731. (unwind-protect
  7732. (progn
  7733. (fset 'read-string (lambda (&rest ignore) ,ans))
  7734. (eval '(,c1 arg)))
  7735. (if bound
  7736. (fset 'read-string old)
  7737. (fmakunbound 'read-string)))))))
  7738. ((equal action ?S)
  7739. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  7740. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  7741. (let ((days (read-number
  7742. (format "Scatter tasks across how many %sdays: "
  7743. (if arg "week" "")) 7)))
  7744. (setq cmd
  7745. `(let ((distance (1+ (random ,days))))
  7746. (if arg
  7747. (let ((dist distance)
  7748. (day-of-week
  7749. (calendar-day-of-week
  7750. (calendar-gregorian-from-absolute (org-today)))))
  7751. (dotimes (i (1+ dist))
  7752. (while (member day-of-week org-agenda-weekend-days)
  7753. (incf distance)
  7754. (incf day-of-week)
  7755. (if (= day-of-week 7)
  7756. (setq day-of-week 0)))
  7757. (incf day-of-week)
  7758. (if (= day-of-week 7)
  7759. (setq day-of-week 0)))))
  7760. ;; silently fail when try to replan a sexp entry
  7761. (condition-case nil
  7762. (let* ((date (calendar-gregorian-from-absolute
  7763. (+ (org-today) distance)))
  7764. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  7765. (nth 2 date))))
  7766. (org-agenda-schedule nil time))
  7767. (error nil)))))))
  7768. ((assoc action org-agenda-bulk-custom-functions)
  7769. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  7770. redo-at-end t))
  7771. ((equal action ?f)
  7772. (setq cmd (list (intern
  7773. (org-icompleting-read "Function: "
  7774. obarray 'fboundp t nil nil)))))
  7775. (t (error "Invalid bulk action")))
  7776. ;; Sort the markers, to make sure that parents are handled before children
  7777. (setq entries (sort entries
  7778. (lambda (a b)
  7779. (cond
  7780. ((equal (marker-buffer a) (marker-buffer b))
  7781. (< (marker-position a) (marker-position b)))
  7782. (t
  7783. (string< (buffer-name (marker-buffer a))
  7784. (buffer-name (marker-buffer b))))))))
  7785. ;; Now loop over all markers and apply cmd
  7786. (while (setq e (pop entries))
  7787. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  7788. (if (not pos)
  7789. (progn (message "Skipping removed entry at %s" e)
  7790. (setq cntskip (1+ cntskip)))
  7791. (goto-char pos)
  7792. (let (org-loop-over-headlines-in-active-region)
  7793. (eval cmd))
  7794. (setq org-agenda-bulk-marked-entries
  7795. (delete e org-agenda-bulk-marked-entries))
  7796. (setq cnt (1+ cnt))))
  7797. (setq org-agenda-bulk-marked-entries nil)
  7798. (org-agenda-bulk-remove-all-marks)
  7799. (when redo-at-end (org-agenda-redo))
  7800. (message "Acted on %d entries%s"
  7801. cnt
  7802. (if (= cntskip 0)
  7803. ""
  7804. (format ", skipped %d (disappeared before their turn)"
  7805. cntskip)))))
  7806. ;;; Flagging notes
  7807. (defun org-agenda-show-the-flagging-note ()
  7808. "Display the flagging note in the other window.
  7809. When called a second time in direct sequence, offer to remove the FLAGGING
  7810. tag and (if present) the flagging note."
  7811. (interactive)
  7812. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  7813. (win (selected-window))
  7814. note heading newhead)
  7815. (unless hdmarker
  7816. (error "No linked entry at point"))
  7817. (if (and (eq this-command last-command)
  7818. (y-or-n-p "Unflag and remove any flagging note? "))
  7819. (progn
  7820. (org-agenda-remove-flag hdmarker)
  7821. (let ((win (get-buffer-window "*Flagging Note*")))
  7822. (and win (delete-window win)))
  7823. (message "Entry unflaged"))
  7824. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  7825. (unless note
  7826. (error "No flagging note"))
  7827. (org-kill-new note)
  7828. (org-switch-to-buffer-other-window "*Flagging Note*")
  7829. (erase-buffer)
  7830. (insert note)
  7831. (goto-char (point-min))
  7832. (while (re-search-forward "\\\\n" nil t)
  7833. (replace-match "\n" t t))
  7834. (goto-char (point-min))
  7835. (select-window win)
  7836. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  7837. (defun org-agenda-remove-flag (marker)
  7838. "Remove the FLAGGED tag and any flagging note in the entry."
  7839. (let (newhead)
  7840. (org-with-point-at marker
  7841. (org-toggle-tag "FLAGGED" 'off)
  7842. (org-entry-delete nil "THEFLAGGINGNOTE")
  7843. (setq newhead (org-get-heading)))
  7844. (org-agenda-change-all-lines newhead marker)
  7845. (message "Entry unflaged")))
  7846. (defun org-agenda-get-any-marker (&optional pos)
  7847. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  7848. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  7849. ;;; Appointment reminders
  7850. (defvar appt-time-msg-list)
  7851. ;;;###autoload
  7852. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  7853. "Activate appointments found in `org-agenda-files'.
  7854. With a \\[universal-argument] prefix, refresh the list of
  7855. appointments.
  7856. If FILTER is t, interactively prompt the user for a regular
  7857. expression, and filter out entries that don't match it.
  7858. If FILTER is a string, use this string as a regular expression
  7859. for filtering entries out.
  7860. If FILTER is a function, filter out entries against which
  7861. calling the function returns nil. This function takes one
  7862. argument: an entry from `org-agenda-get-day-entries'.
  7863. FILTER can also be an alist with the car of each cell being
  7864. either 'headline or 'category. For example:
  7865. '((headline \"IMPORTANT\")
  7866. (category \"Work\"))
  7867. will only add headlines containing IMPORTANT or headlines
  7868. belonging to the \"Work\" category.
  7869. ARGS are symbols indicating what kind of entries to consider.
  7870. By default `org-agenda-to-appt' will use :deadline, :scheduled
  7871. and :timestamp entries. See the docstring of `org-diary' for
  7872. details and examples."
  7873. (interactive "P")
  7874. (if refresh (setq appt-time-msg-list nil))
  7875. (if (eq filter t)
  7876. (setq filter (read-from-minibuffer "Regexp filter: ")))
  7877. (let* ((cnt 0) ; count added events
  7878. (scope (or args '(:deadline :scheduled :timestamp)))
  7879. (org-agenda-new-buffers nil)
  7880. (org-deadline-warning-days 0)
  7881. ;; Do not use `org-today' here because appt only takes
  7882. ;; time and without date as argument, so it may pass wrong
  7883. ;; information otherwise
  7884. (today (org-date-to-gregorian
  7885. (time-to-days (current-time))))
  7886. (org-agenda-restrict nil)
  7887. (files (org-agenda-files 'unrestricted)) entries file)
  7888. ;; Get all entries which may contain an appt
  7889. (org-prepare-agenda-buffers files)
  7890. (while (setq file (pop files))
  7891. (setq entries
  7892. (delq nil
  7893. (append entries
  7894. (apply 'org-agenda-get-day-entries
  7895. file today scope)))))
  7896. ;; Map thru entries and find if we should filter them out
  7897. (mapc
  7898. (lambda(x)
  7899. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  7900. (cat (get-text-property 1 'org-category x))
  7901. (tod (get-text-property 1 'time-of-day x))
  7902. (ok (or (null filter)
  7903. (and (stringp filter) (string-match filter evt))
  7904. (and (functionp filter) (funcall filter x))
  7905. (and (listp filter)
  7906. (let ((cat-filter (cadr (assoc 'category filter)))
  7907. (evt-filter (cadr (assoc 'headline filter))))
  7908. (or (and (stringp cat-filter)
  7909. (string-match cat-filter cat))
  7910. (and (stringp evt-filter)
  7911. (string-match evt-filter evt))))))))
  7912. ;; FIXME: Shall we remove text-properties for the appt text?
  7913. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  7914. (when (and ok tod)
  7915. (setq tod (concat "00" (number-to-string tod))
  7916. tod (when (string-match
  7917. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  7918. (concat (match-string 1 tod) ":"
  7919. (match-string 2 tod))))
  7920. (appt-add tod evt)
  7921. (setq cnt (1+ cnt))))) entries)
  7922. (org-release-buffers org-agenda-new-buffers)
  7923. (if (eq cnt 0)
  7924. (message "No event to add")
  7925. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  7926. (defun org-agenda-todayp (date)
  7927. "Does DATE mean today, when considering `org-extend-today-until'?"
  7928. (let ((today (org-today))
  7929. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  7930. date)))
  7931. (eq date today)))
  7932. (defun org-agenda-todo-yesterday (&optional arg)
  7933. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  7934. (interactive "P")
  7935. (let* ((hour (third (decode-time
  7936. (org-current-time))))
  7937. (org-extend-today-until (1+ hour)))
  7938. (org-agenda-todo arg)))
  7939. (provide 'org-agenda)
  7940. ;;; org-agenda.el ends here