org-agenda.el 368 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the code for creating and using the Agenda for Org-mode.
  23. ;;
  24. ;; The functions `org-batch-agenda', `org-batch-agenda-csv', and
  25. ;; `org-batch-store-agenda-views' are implemented as macros to provide
  26. ;; a convenient way for extracting agenda information from the command
  27. ;; line. The Lisp does not evaluate parameters of a macro call; thus
  28. ;; it is not necessary to quote the parameters passed to one of those
  29. ;; functions. E.g. you can write:
  30. ;;
  31. ;; emacs -batch -l ~/.emacs -eval '(org-batch-agenda "a" org-agenda-span 7)'
  32. ;;
  33. ;; To export an agenda spanning 7 days. If `org-batch-agenda' would
  34. ;; have been implemented as a regular function you'd have to quote the
  35. ;; symbol org-agenda-span. Moreover: To use a symbol as parameter
  36. ;; value you would have to double quote the symbol.
  37. ;;
  38. ;; This is a hack, but it works even when running Org byte-compiled.
  39. ;;
  40. ;;; Code:
  41. (require 'org)
  42. (require 'org-macs)
  43. (eval-when-compile
  44. (require 'cl))
  45. (declare-function diary-add-to-list "diary-lib"
  46. (date string specifier &optional marker globcolor literal))
  47. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  48. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  49. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  50. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  51. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  53. (declare-function calendar-french-date-string "cal-french" (&optional date))
  54. (declare-function calendar-goto-date "cal-move" (date))
  55. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  56. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  57. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  58. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  59. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  60. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  61. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  62. (declare-function calendar-check-holidays "holidays" (date))
  63. (declare-function org-datetree-find-date-create "org-datetree"
  64. (date &optional keep-restriction))
  65. (declare-function org-columns-quit "org-colview" ())
  66. (declare-function diary-date-display-form "diary-lib" (&optional type))
  67. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  68. (declare-function org-habit-insert-consistency-graphs
  69. "org-habit" (&optional line))
  70. (declare-function org-is-habit-p "org-habit" (&optional pom))
  71. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  72. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  73. (declare-function org-pop-to-buffer-same-window "org-compat"
  74. (&optional buffer-or-name norecord label))
  75. (declare-function org-agenda-columns "org-colview" ())
  76. (declare-function org-add-archive-files "org-archive" (files))
  77. (declare-function org-capture "org-capture" (&optional goto keys))
  78. (defvar calendar-mode-map) ; defined in calendar.el
  79. (defvar org-clock-current-task nil) ; defined in org-clock.el
  80. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  81. (defvar org-habit-show-habits) ; defined in org-habit.el
  82. (defvar org-habit-show-habits-only-for-today)
  83. (defvar org-habit-show-all-today)
  84. ;; Defined somewhere in this file, but used before definition.
  85. (defvar org-agenda-buffer-name "*Org Agenda*")
  86. (defvar org-agenda-overriding-header nil)
  87. (defvar org-agenda-title-append nil)
  88. (org-no-warnings (defvar entry)) ;; unprefixed, from calendar.el
  89. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  90. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  91. (defvar org-agenda-undo-list nil
  92. "List of undoable operations in the agenda since last refresh.")
  93. (defvar org-agenda-pending-undo-list nil
  94. "In a series of undo commands, this is the list of remaining undo items.")
  95. (defcustom org-agenda-confirm-kill 1
  96. "When set, remote killing from the agenda buffer needs confirmation.
  97. When t, a confirmation is always needed. When a number N, confirmation is
  98. only needed when the text to be killed contains more than N non-white lines."
  99. :group 'org-agenda
  100. :type '(choice
  101. (const :tag "Never" nil)
  102. (const :tag "Always" t)
  103. (integer :tag "When more than N lines")))
  104. (defcustom org-agenda-compact-blocks nil
  105. "Non-nil means make the block agenda more compact.
  106. This is done globally by leaving out lines like the agenda span
  107. name and week number or the separator lines."
  108. :group 'org-agenda
  109. :type 'boolean)
  110. (defcustom org-agenda-block-separator ?=
  111. "The separator between blocks in the agenda.
  112. If this is a string, it will be used as the separator, with a newline added.
  113. If it is a character, it will be repeated to fill the window width.
  114. If nil the separator is disabled. In `org-agenda-custom-commands' this
  115. addresses the separator between the current and the previous block."
  116. :group 'org-agenda
  117. :type '(choice
  118. (const :tag "Disabled" nil)
  119. (character)
  120. (string)))
  121. (defgroup org-agenda-export nil
  122. "Options concerning exporting agenda views in Org-mode."
  123. :tag "Org Agenda Export"
  124. :group 'org-agenda)
  125. (defcustom org-agenda-with-colors t
  126. "Non-nil means use colors in agenda views."
  127. :group 'org-agenda-export
  128. :type 'boolean)
  129. (defcustom org-agenda-exporter-settings nil
  130. "Alist of variable/value pairs that should be active during agenda export.
  131. This is a good place to set options for ps-print and for htmlize.
  132. Note that the way this is implemented, the values will be evaluated
  133. before assigned to the variables. So make sure to quote values you do
  134. *not* want evaluated, for example
  135. (setq org-agenda-exporter-settings
  136. '((ps-print-color-p 'black-white)))"
  137. :group 'org-agenda-export
  138. :type '(repeat
  139. (list
  140. (variable)
  141. (sexp :tag "Value"))))
  142. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  143. "Hook run in a temporary buffer before writing the agenda to an export file.
  144. A useful function for this hook is `org-agenda-add-entry-text'."
  145. :group 'org-agenda-export
  146. :type 'hook
  147. :options '(org-agenda-add-entry-text))
  148. (defcustom org-agenda-add-entry-text-maxlines 0
  149. "Maximum number of entry text lines to be added to agenda.
  150. This is only relevant when `org-agenda-add-entry-text' is part of
  151. `org-agenda-before-write-hook', which is the default.
  152. When this is 0, nothing will happen. When it is greater than 0, it
  153. specifies the maximum number of lines that will be added for each entry
  154. that is listed in the agenda view.
  155. Note that this variable is not used during display, only when exporting
  156. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  157. and `org-agenda-entry-text-maxlines'."
  158. :group 'org-agenda
  159. :type 'integer)
  160. (defcustom org-agenda-add-entry-text-descriptive-links t
  161. "Non-nil means export org-links as descriptive links in agenda added text.
  162. This variable applies to the text added to the agenda when
  163. `org-agenda-add-entry-text-maxlines' is larger than 0.
  164. When this variable nil, the URL will (also) be shown."
  165. :group 'org-agenda
  166. :type 'boolean)
  167. (defcustom org-agenda-export-html-style nil
  168. "The style specification for exported HTML Agenda files.
  169. If this variable contains a string, it will replace the default <style>
  170. section as produced by `htmlize'.
  171. Since there are different ways of setting style information, this variable
  172. needs to contain the full HTML structure to provide a style, including the
  173. surrounding HTML tags. The style specifications should include definitions
  174. the fonts used by the agenda, here is an example:
  175. <style type=\"text/css\">
  176. p { font-weight: normal; color: gray; }
  177. .org-agenda-structure {
  178. font-size: 110%;
  179. color: #003399;
  180. font-weight: 600;
  181. }
  182. .org-todo {
  183. color: #cc6666;
  184. font-weight: bold;
  185. }
  186. .org-agenda-done {
  187. color: #339933;
  188. }
  189. .org-done {
  190. color: #339933;
  191. }
  192. .title { text-align: center; }
  193. .todo, .deadline { color: red; }
  194. .done { color: green; }
  195. </style>
  196. or, if you want to keep the style in a file,
  197. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  198. As the value of this option simply gets inserted into the HTML <head> header,
  199. you can \"misuse\" it to also add other text to the header."
  200. :group 'org-agenda-export
  201. :group 'org-export-html
  202. :type 'string)
  203. (defcustom org-agenda-persistent-filter nil
  204. "When set, keep filters from one agenda view to the next."
  205. :group 'org-agenda
  206. :type 'boolean)
  207. (defgroup org-agenda-custom-commands nil
  208. "Options concerning agenda views in Org-mode."
  209. :tag "Org Agenda Custom Commands"
  210. :group 'org-agenda)
  211. (defconst org-sorting-choice
  212. '(choice
  213. (const time-up) (const time-down)
  214. (const category-keep) (const category-up) (const category-down)
  215. (const tag-down) (const tag-up)
  216. (const priority-up) (const priority-down)
  217. (const todo-state-up) (const todo-state-down)
  218. (const effort-up) (const effort-down)
  219. (const habit-up) (const habit-down)
  220. (const alpha-up) (const alpha-down)
  221. (const user-defined-up) (const user-defined-down))
  222. "Sorting choices.")
  223. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  224. ;; the new variable `org-agenda-tag-filter-preset'.
  225. (if (fboundp 'defvaralias)
  226. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  227. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  228. (defconst org-agenda-custom-commands-local-options
  229. `(repeat :tag "Local settings for this command. Remember to quote values"
  230. (choice :tag "Setting"
  231. (list :tag "Heading for this block"
  232. (const org-agenda-overriding-header)
  233. (string :tag "Headline"))
  234. (list :tag "Files to be searched"
  235. (const org-agenda-files)
  236. (list
  237. (const :format "" quote)
  238. (repeat (file))))
  239. (list :tag "Sorting strategy"
  240. (const org-agenda-sorting-strategy)
  241. (list
  242. (const :format "" quote)
  243. (repeat
  244. ,org-sorting-choice)))
  245. (list :tag "Prefix format"
  246. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  247. (string))
  248. (list :tag "Number of days in agenda"
  249. (const org-agenda-span)
  250. (choice (const :tag "Day" 'day)
  251. (const :tag "Week" 'week)
  252. (const :tag "Month" 'month)
  253. (const :tag "Year" 'year)
  254. (integer :tag "Custom")))
  255. (list :tag "Fixed starting date"
  256. (const org-agenda-start-day)
  257. (string :value "2007-11-01"))
  258. (list :tag "Start on day of week"
  259. (const org-agenda-start-on-weekday)
  260. (choice :value 1
  261. (const :tag "Today" nil)
  262. (integer :tag "Weekday No.")))
  263. (list :tag "Include data from diary"
  264. (const org-agenda-include-diary)
  265. (boolean))
  266. (list :tag "Deadline Warning days"
  267. (const org-deadline-warning-days)
  268. (integer :value 1))
  269. (list :tag "Category filter preset"
  270. (const org-agenda-category-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+category or -category"))))
  275. (list :tag "Tags filter preset"
  276. (const org-agenda-tag-filter-preset)
  277. (list
  278. (const :format "" quote)
  279. (repeat
  280. (string :tag "+tag or -tag"))))
  281. (list :tag "Set daily/weekly entry types"
  282. (const org-agenda-entry-types)
  283. (list
  284. (const :format "" quote)
  285. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  286. (const :deadline)
  287. (const :scheduled)
  288. (const :timestamp)
  289. (const :sexp))))
  290. (list :tag "Standard skipping condition"
  291. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  292. (const org-agenda-skip-function)
  293. (list
  294. (const :format "" quote)
  295. (list
  296. (choice
  297. :tag "Skipping range"
  298. (const :tag "Skip entry" org-agenda-skip-entry-if)
  299. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  300. (repeat :inline t :tag "Conditions for skipping"
  301. (choice
  302. :tag "Condition type"
  303. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  304. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  305. (list :tag "TODO state is" :inline t
  306. (const 'todo)
  307. (choice
  308. (const :tag "any not-done state" 'todo)
  309. (const :tag "any done state" 'done)
  310. (const :tag "any state" 'any)
  311. (list :tag "Keyword list"
  312. (const :format "" quote)
  313. (repeat (string :tag "Keyword")))))
  314. (list :tag "TODO state is not" :inline t
  315. (const 'nottodo)
  316. (choice
  317. (const :tag "any not-done state" 'todo)
  318. (const :tag "any done state" 'done)
  319. (const :tag "any state" 'any)
  320. (list :tag "Keyword list"
  321. (const :format "" quote)
  322. (repeat (string :tag "Keyword")))))
  323. (const :tag "scheduled" 'scheduled)
  324. (const :tag "not scheduled" 'notscheduled)
  325. (const :tag "deadline" 'deadline)
  326. (const :tag "no deadline" 'notdeadline)
  327. (const :tag "timestamp" 'timestamp)
  328. (const :tag "no timestamp" 'nottimestamp))))))
  329. (list :tag "Non-standard skipping condition"
  330. :value (org-agenda-skip-function)
  331. (const org-agenda-skip-function)
  332. (sexp :tag "Function or form (quoted!)"))
  333. (list :tag "Any variable"
  334. (variable :tag "Variable")
  335. (sexp :tag "Value (sexp)"))))
  336. "Selection of examples for agenda command settings.
  337. This will be spliced into the custom type of
  338. `org-agenda-custom-commands'.")
  339. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  340. ((agenda "") (alltodo))))
  341. "Custom commands for the agenda.
  342. These commands will be offered on the splash screen displayed by the
  343. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  344. (key desc type match settings files)
  345. key The key (one or more characters as a string) to be associated
  346. with the command.
  347. desc A description of the command, when omitted or nil, a default
  348. description is built using MATCH.
  349. type The command type, any of the following symbols:
  350. agenda The daily/weekly agenda.
  351. todo Entries with a specific TODO keyword, in all agenda files.
  352. search Entries containing search words entry or headline.
  353. tags Tags/Property/TODO match in all agenda files.
  354. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  355. todo-tree Sparse tree of specific TODO keyword in *current* file.
  356. tags-tree Sparse tree with all tags matches in *current* file.
  357. occur-tree Occur sparse tree for *current* file.
  358. ... A user-defined function.
  359. match What to search for:
  360. - a single keyword for TODO keyword searches
  361. - a tags match expression for tags searches
  362. - a word search expression for text searches.
  363. - a regular expression for occur searches
  364. For all other commands, this should be the empty string.
  365. settings A list of option settings, similar to that in a let form, so like
  366. this: ((opt1 val1) (opt2 val2) ...). The values will be
  367. evaluated at the moment of execution, so quote them when needed.
  368. files A list of files file to write the produced agenda buffer to
  369. with the command `org-store-agenda-views'.
  370. If a file name ends in \".html\", an HTML version of the buffer
  371. is written out. If it ends in \".ps\", a postscript version is
  372. produced. Otherwise, only the plain text is written to the file.
  373. You can also define a set of commands, to create a composite agenda buffer.
  374. In this case, an entry looks like this:
  375. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  376. where
  377. desc A description string to be displayed in the dispatcher menu.
  378. cmd An agenda command, similar to the above. However, tree commands
  379. are not allowed, but instead you can get agenda and global todo list.
  380. So valid commands for a set are:
  381. (agenda \"\" settings)
  382. (alltodo \"\" settings)
  383. (stuck \"\" settings)
  384. (todo \"match\" settings files)
  385. (search \"match\" settings files)
  386. (tags \"match\" settings files)
  387. (tags-todo \"match\" settings files)
  388. Each command can carry a list of options, and another set of options can be
  389. given for the whole set of commands. Individual command options take
  390. precedence over the general options.
  391. When using several characters as key to a command, the first characters
  392. are prefix commands. For the dispatcher to display useful information, you
  393. should provide a description for the prefix, like
  394. (setq org-agenda-custom-commands
  395. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  396. (\"hl\" tags \"+HOME+Lisa\")
  397. (\"hp\" tags \"+HOME+Peter\")
  398. (\"hk\" tags \"+HOME+Kim\")))"
  399. :group 'org-agenda-custom-commands
  400. :type `(repeat
  401. (choice :value ("x" "Describe command here" tags "" nil)
  402. (list :tag "Single command"
  403. (string :tag "Access Key(s) ")
  404. (option (string :tag "Description"))
  405. (choice
  406. (const :tag "Agenda" agenda)
  407. (const :tag "TODO list" alltodo)
  408. (const :tag "Search words" search)
  409. (const :tag "Stuck projects" stuck)
  410. (const :tag "Tags/Property match (all agenda files)" tags)
  411. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  412. (const :tag "TODO keyword search (all agenda files)" todo)
  413. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  414. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  415. (const :tag "Occur tree (current buffer)" occur-tree)
  416. (sexp :tag "Other, user-defined function"))
  417. (string :tag "Match (only for some commands)")
  418. ,org-agenda-custom-commands-local-options
  419. (option (repeat :tag "Export" (file :tag "Export to"))))
  420. (list :tag "Command series, all agenda files"
  421. (string :tag "Access Key(s)")
  422. (string :tag "Description ")
  423. (repeat :tag "Component"
  424. (choice
  425. (list :tag "Agenda"
  426. (const :format "" agenda)
  427. (const :tag "" :format "" "")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "TODO list (all keywords)"
  430. (const :format "" alltodo)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Search words"
  434. (const :format "" search)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Stuck projects"
  438. (const :format "" stuck)
  439. (const :tag "" :format "" "")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "Tags search"
  442. (const :format "" tags)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Tags search, TODO entries only"
  446. (const :format "" tags-todo)
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)
  449. (list :tag "TODO keyword search"
  450. (const :format "" todo)
  451. (string :tag "Match")
  452. ,org-agenda-custom-commands-local-options)
  453. (list :tag "Other, user-defined function"
  454. (symbol :tag "function")
  455. (string :tag "Match")
  456. ,org-agenda-custom-commands-local-options)))
  457. (repeat :tag "Settings for entire command set"
  458. (list (variable :tag "Any variable")
  459. (sexp :tag "Value")))
  460. (option (repeat :tag "Export" (file :tag "Export to"))))
  461. (cons :tag "Prefix key documentation"
  462. (string :tag "Access Key(s)")
  463. (string :tag "Description ")))))
  464. (defcustom org-agenda-query-register ?o
  465. "The register holding the current query string.
  466. The purpose of this is that if you construct a query string interactively,
  467. you can then use it to define a custom command."
  468. :group 'org-agenda-custom-commands
  469. :type 'character)
  470. (defcustom org-stuck-projects
  471. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  472. "How to identify stuck projects.
  473. This is a list of four items:
  474. 1. A tags/todo/property matcher string that is used to identify a project.
  475. See the manual for a description of tag and property searches.
  476. The entire tree below a headline matched by this is considered one project.
  477. 2. A list of TODO keywords identifying non-stuck projects.
  478. If the project subtree contains any headline with one of these todo
  479. keywords, the project is considered to be not stuck. If you specify
  480. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  481. 3. A list of tags identifying non-stuck projects.
  482. If the project subtree contains any headline with one of these tags,
  483. the project is considered to be not stuck. If you specify \"*\" as
  484. a tag, any tag will mark the project unstuck. Note that this is about
  485. the explicit presence of a tag somewhere in the subtree, inherited
  486. tags to not count here. If inherited tags make a project not stuck,
  487. use \"-TAG\" in the tags part of the matcher under (1.) above.
  488. 4. An arbitrary regular expression matching non-stuck projects.
  489. If the project turns out to be not stuck, search continues also in the
  490. subtree to see if any of the subtasks have project status.
  491. See also the variable `org-tags-match-list-sublevels' which applies
  492. to projects matched by this search as well.
  493. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  494. or `C-c a #' to produce the list."
  495. :group 'org-agenda-custom-commands
  496. :type '(list
  497. (string :tag "Tags/TODO match to identify a project")
  498. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  500. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  501. (defcustom org-agenda-filter-effort-default-operator "<"
  502. "The default operator for effort estimate filtering.
  503. If you select an effort estimate limit without first pressing an operator,
  504. this one will be used."
  505. :group 'org-agenda-custom-commands
  506. :type '(choice (const :tag "less or equal" "<")
  507. (const :tag "greater or equal"">")
  508. (const :tag "equal" "=")))
  509. (defgroup org-agenda-skip nil
  510. "Options concerning skipping parts of agenda files."
  511. :tag "Org Agenda Skip"
  512. :group 'org-agenda)
  513. (defcustom org-agenda-skip-function-global nil
  514. "Function to be called at each match during agenda construction.
  515. If this function returns nil, the current match should not be skipped.
  516. If the function decided to skip an agenda match, is must return the
  517. buffer position from which the search should be continued.
  518. This may also be a Lisp form, which will be evaluated.
  519. This variable will be applied to every agenda match, including
  520. tags/property searches and TODO lists. So try to make the test function
  521. do its checking as efficiently as possible. To implement a skipping
  522. condition just for specific agenda commands, use the variable
  523. `org-agenda-skip-function' which can be set in the options section
  524. of custom agenda commands."
  525. :group 'org-agenda-skip
  526. :type 'sexp)
  527. (defgroup org-agenda-daily/weekly nil
  528. "Options concerning the daily/weekly agenda."
  529. :tag "Org Agenda Daily/Weekly"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-todo-list nil
  532. "Options concerning the global todo list agenda view."
  533. :tag "Org Agenda Todo List"
  534. :group 'org-agenda)
  535. (defgroup org-agenda-match-view nil
  536. "Options concerning the general tags/property/todo match agenda view."
  537. :tag "Org Agenda Match View"
  538. :group 'org-agenda)
  539. (defgroup org-agenda-search-view nil
  540. "Options concerning the general tags/property/todo match agenda view."
  541. :tag "Org Agenda Match View"
  542. :group 'org-agenda)
  543. (defvar org-agenda-archives-mode nil
  544. "Non-nil means the agenda will include archived items.
  545. If this is the symbol `trees', trees in the selected agenda scope
  546. that are marked with the ARCHIVE tag will be included anyway. When this is
  547. t, also all archive files associated with the current selection of agenda
  548. files will be included.")
  549. (defcustom org-agenda-skip-comment-trees t
  550. "Non-nil means skip trees that start with the COMMENT keyword.
  551. When nil, these trees are also scanned by agenda commands."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-todo-list-sublevels t
  555. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  556. When nil, the sublevels of a TODO entry are not checked, resulting in
  557. potentially much shorter TODO lists."
  558. :group 'org-agenda-skip
  559. :group 'org-agenda-todo-list
  560. :type 'boolean)
  561. (defcustom org-agenda-todo-ignore-with-date nil
  562. "Non-nil means don't show entries with a date in the global todo list.
  563. You can use this if you prefer to mark mere appointments with a TODO keyword,
  564. but don't want them to show up in the TODO list.
  565. When this is set, it also covers deadlines and scheduled items, the settings
  566. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  567. will be ignored.
  568. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  569. :group 'org-agenda-skip
  570. :group 'org-agenda-todo-list
  571. :type 'boolean)
  572. (defcustom org-agenda-todo-ignore-timestamp nil
  573. "Non-nil means don't show entries with a timestamp.
  574. This applies when creating the global todo list.
  575. Valid values are:
  576. past Don't show entries for today or in the past.
  577. future Don't show entries with a timestamp in the future.
  578. The idea behind this is that if it has a future
  579. timestamp, you don't want to think about it until the
  580. date.
  581. all Don't show any entries with a timestamp in the global todo list.
  582. The idea behind this is that by setting a timestamp, you
  583. have already \"taken care\" of this item.
  584. This variable can also have an integer as a value. If positive (N),
  585. todos with a timestamp N or more days in the future will be ignored. If
  586. negative (-N), todos with a timestamp N or more days in the past will be
  587. ignored. If 0, todos with a timestamp either today or in the future will
  588. be ignored. For example, a value of -1 will exclude todos with a
  589. timestamp in the past (yesterday or earlier), while a value of 7 will
  590. exclude todos with a timestamp a week or more in the future.
  591. See also `org-agenda-todo-ignore-with-date'.
  592. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  593. to make his option also apply to the tags-todo list."
  594. :group 'org-agenda-skip
  595. :group 'org-agenda-todo-list
  596. :version "24.1"
  597. :type '(choice
  598. (const :tag "Ignore future timestamp todos" future)
  599. (const :tag "Ignore past or present timestamp todos" past)
  600. (const :tag "Ignore all timestamp todos" all)
  601. (const :tag "Show timestamp todos" nil)
  602. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  603. (defcustom org-agenda-todo-ignore-scheduled nil
  604. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  605. This applies when creating the global todo list.
  606. Valid values are:
  607. past Don't show entries scheduled today or in the past.
  608. future Don't show entries scheduled in the future.
  609. The idea behind this is that by scheduling it, you don't want to
  610. think about it until the scheduled date.
  611. all Don't show any scheduled entries in the global todo list.
  612. The idea behind this is that by scheduling it, you have already
  613. \"taken care\" of this item.
  614. t Same as `all', for backward compatibility.
  615. This variable can also have an integer as a value. See
  616. `org-agenda-todo-ignore-timestamp' for more details.
  617. See also `org-agenda-todo-ignore-with-date'.
  618. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  619. to make his option also apply to the tags-todo list."
  620. :group 'org-agenda-skip
  621. :group 'org-agenda-todo-list
  622. :type '(choice
  623. (const :tag "Ignore future-scheduled todos" future)
  624. (const :tag "Ignore past- or present-scheduled todos" past)
  625. (const :tag "Ignore all scheduled todos" all)
  626. (const :tag "Ignore all scheduled todos (compatibility)" t)
  627. (const :tag "Show scheduled todos" nil)
  628. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  629. (defcustom org-agenda-todo-ignore-deadlines nil
  630. "Non-nil means ignore some deadlined TODO items when making TODO list.
  631. There are different motivations for using different values, please think
  632. carefully when configuring this variable.
  633. This applies when creating the global todo list.
  634. Valid values are:
  635. near Don't show near deadline entries. A deadline is near when it is
  636. closer than `org-deadline-warning-days' days. The idea behind this
  637. is that such items will appear in the agenda anyway.
  638. far Don't show TODO entries where a deadline has been defined, but
  639. the deadline is not near. This is useful if you don't want to
  640. use the todo list to figure out what to do now.
  641. past Don't show entries with a deadline timestamp for today or in the past.
  642. future Don't show entries with a deadline timestamp in the future, not even
  643. when they become `near' ones. Use it with caution.
  644. all Ignore all TODO entries that do have a deadline.
  645. t Same as `near', for backward compatibility.
  646. This variable can also have an integer as a value. See
  647. `org-agenda-todo-ignore-timestamp' for more details.
  648. See also `org-agenda-todo-ignore-with-date'.
  649. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  650. to make his option also apply to the tags-todo list."
  651. :group 'org-agenda-skip
  652. :group 'org-agenda-todo-list
  653. :type '(choice
  654. (const :tag "Ignore near deadlines" near)
  655. (const :tag "Ignore near deadlines (compatibility)" t)
  656. (const :tag "Ignore far deadlines" far)
  657. (const :tag "Ignore all TODOs with a deadlines" all)
  658. (const :tag "Show all TODOs, even if they have a deadline" nil)
  659. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  660. (defcustom org-agenda-todo-ignore-time-comparison-use-seconds nil
  661. "Time unit to use when possibly ignoring an agenda item.
  662. See the docstring of various `org-agenda-todo-ignore-*' options.
  663. The default is to compare time stamps using days. An item is thus
  664. considered to be in the future if it is at least one day after today.
  665. Non-nil means to compare time stamps using seconds. An item is then
  666. considered future if it has a time value later than current time."
  667. :group 'org-agenda-skip
  668. :group 'org-agenda-todo-list
  669. :type '(choice
  670. (const :tag "Compare time with days" nil)
  671. (const :tag "Compare time with seconds" t)))
  672. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  673. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  674. The variables
  675. `org-agenda-todo-ignore-with-date',
  676. `org-agenda-todo-ignore-timestamp',
  677. `org-agenda-todo-ignore-scheduled',
  678. `org-agenda-todo-ignore-deadlines'
  679. make the global TODO list skip entries that have time stamps of certain
  680. kinds. If this option is set, the same options will also apply for the
  681. tags-todo search, which is the general tags/property matcher
  682. restricted to unfinished TODO entries only."
  683. :group 'org-agenda-skip
  684. :group 'org-agenda-todo-list
  685. :group 'org-agenda-match-view
  686. :type 'boolean)
  687. (defcustom org-agenda-skip-scheduled-if-done nil
  688. "Non-nil means don't show scheduled items in agenda when they are done.
  689. This is relevant for the daily/weekly agenda, not for the TODO list. And
  690. it applies only to the actual date of the scheduling. Warnings about
  691. an item with a past scheduling dates are always turned off when the item
  692. is DONE."
  693. :group 'org-agenda-skip
  694. :group 'org-agenda-daily/weekly
  695. :type 'boolean)
  696. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  697. "Non-nil means skip scheduling line if same entry shows because of deadline.
  698. In the agenda of today, an entry can show up multiple times because
  699. it is both scheduled and has a nearby deadline, and maybe a plain time
  700. stamp as well.
  701. When this variable is t, then only the deadline is shown and the fact that
  702. the entry is scheduled today or was scheduled previously is not shown.
  703. When this variable is nil, the entry will be shown several times. When
  704. the variable is the symbol `not-today', then skip scheduled previously,
  705. but not scheduled today."
  706. :group 'org-agenda-skip
  707. :group 'org-agenda-daily/weekly
  708. :type '(choice
  709. (const :tag "Never" nil)
  710. (const :tag "Always" t)
  711. (const :tag "Not when scheduled today" not-today)))
  712. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  713. "Non-nil means skip timestamp line if same entry shows because of deadline.
  714. In the agenda of today, an entry can show up multiple times
  715. because it has both a plain timestamp and has a nearby deadline.
  716. When this variable is t, then only the deadline is shown and the
  717. fact that the entry has a timestamp for or including today is not
  718. shown. When this variable is nil, the entry will be shown
  719. several times."
  720. :group 'org-agenda-skip
  721. :group 'org-agenda-daily/weekly
  722. :version "24.1"
  723. :type '(choice
  724. (const :tag "Never" nil)
  725. (const :tag "Always" t)))
  726. (defcustom org-agenda-skip-deadline-if-done nil
  727. "Non-nil means don't show deadlines when the corresponding item is done.
  728. When nil, the deadline is still shown and should give you a happy feeling.
  729. This is relevant for the daily/weekly agenda. And it applied only to the
  730. actually date of the deadline. Warnings about approaching and past-due
  731. deadlines are always turned off when the item is DONE."
  732. :group 'org-agenda-skip
  733. :group 'org-agenda-daily/weekly
  734. :type 'boolean)
  735. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  736. "Non-nil means skip deadline prewarning when entry is also scheduled.
  737. This will apply on all days where a prewarning for the deadline would
  738. be shown, but not at the day when the entry is actually due. On that day,
  739. the deadline will be shown anyway.
  740. This variable may be set to nil, t, or a number which will then give
  741. the number of days before the actual deadline when the prewarnings
  742. should resume.
  743. This can be used in a workflow where the first showing of the deadline will
  744. trigger you to schedule it, and then you don't want to be reminded of it
  745. because you will take care of it on the day when scheduled."
  746. :group 'org-agenda-skip
  747. :group 'org-agenda-daily/weekly
  748. :version "24.1"
  749. :type '(choice
  750. (const :tag "Alwas show prewarning" nil)
  751. (const :tag "Remove prewarning if entry is scheduled" t)
  752. (integer :tag "Restart prewarning N days before deadline")))
  753. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  754. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  755. When non-nil, after the search for timestamps has matched once in an
  756. entry, the rest of the entry will not be searched."
  757. :group 'org-agenda-skip
  758. :type 'boolean)
  759. (defcustom org-agenda-skip-timestamp-if-done nil
  760. "Non-nil means don't select item by timestamp or -range if it is DONE."
  761. :group 'org-agenda-skip
  762. :group 'org-agenda-daily/weekly
  763. :type 'boolean)
  764. (defcustom org-agenda-dim-blocked-tasks t
  765. "Non-nil means dim blocked tasks in the agenda display.
  766. This causes some overhead during agenda construction, but if you
  767. have turned on `org-enforce-todo-dependencies',
  768. `org-enforce-todo-checkbox-dependencies', or any other blocking
  769. mechanism, this will create useful feedback in the agenda.
  770. Instead of t, this variable can also have the value `invisible'.
  771. Then blocked tasks will be invisible and only become visible when
  772. they become unblocked. An exemption to this behavior is when a task is
  773. blocked because of unchecked checkboxes below it. Since checkboxes do
  774. not show up in the agenda views, making this task invisible you remove any
  775. trace from agenda views that there is something to do. Therefore, a task
  776. that is blocked because of checkboxes will never be made invisible, it
  777. will only be dimmed."
  778. :group 'org-agenda-daily/weekly
  779. :group 'org-agenda-todo-list
  780. :type '(choice
  781. (const :tag "Do not dim" nil)
  782. (const :tag "Dim to a gray face" t)
  783. (const :tag "Make invisible" invisible)))
  784. (defcustom org-timeline-show-empty-dates 3
  785. "Non-nil means `org-timeline' also shows dates without an entry.
  786. When nil, only the days which actually have entries are shown.
  787. When t, all days between the first and the last date are shown.
  788. When an integer, show also empty dates, but if there is a gap of more than
  789. N days, just insert a special line indicating the size of the gap."
  790. :group 'org-agenda-skip
  791. :type '(choice
  792. (const :tag "None" nil)
  793. (const :tag "All" t)
  794. (integer :tag "at most")))
  795. (defgroup org-agenda-startup nil
  796. "Options concerning initial settings in the Agenda in Org Mode."
  797. :tag "Org Agenda Startup"
  798. :group 'org-agenda)
  799. (defcustom org-agenda-menu-show-matcher t
  800. "Non-nil means show the match string in the agenda dispatcher menu.
  801. When nil, the matcher string is not shown, but is put into the help-echo
  802. property so than moving the mouse over the command shows it.
  803. Setting it to nil is good if matcher strings are very long and/or if
  804. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  805. :group 'org-agenda
  806. :version "24.1"
  807. :type 'boolean)
  808. (define-obsolete-variable-alias 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  809. (defcustom org-agenda-menu-two-columns nil
  810. "Non-nil means, use two columns to show custom commands in the dispatcher.
  811. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  812. to nil."
  813. :group 'org-agenda
  814. :version "24.1"
  815. :type 'boolean)
  816. (define-obsolete-variable-alias 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  817. (defcustom org-agenda-finalize-hook nil
  818. "Hook run just before displaying an agenda buffer.
  819. The buffer is still writable when the hook is called.
  820. You can modify some of the buffer substrings but you should be
  821. extra careful not to modify the text properties of the agenda
  822. headlines as the agenda display heavily relies on them."
  823. :group 'org-agenda-startup
  824. :type 'hook)
  825. (defcustom org-agenda-mouse-1-follows-link nil
  826. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  827. A longer mouse click will still set point. Does not work on XEmacs.
  828. Needs to be set before org.el is loaded."
  829. :group 'org-agenda-startup
  830. :type 'boolean)
  831. (defcustom org-agenda-start-with-follow-mode nil
  832. "The initial value of follow mode in a newly created agenda window."
  833. :group 'org-agenda-startup
  834. :type 'boolean)
  835. (defcustom org-agenda-follow-indirect nil
  836. "Non-nil means `org-agenda-follow-mode' displays only the
  837. current item's tree, in an indirect buffer."
  838. :group 'org-agenda
  839. :version "24.1"
  840. :type 'boolean)
  841. (defcustom org-agenda-show-outline-path t
  842. "Non-nil means show outline path in echo area after line motion."
  843. :group 'org-agenda-startup
  844. :type 'boolean)
  845. (defcustom org-agenda-start-with-entry-text-mode nil
  846. "The initial value of entry-text-mode in a newly created agenda window."
  847. :group 'org-agenda-startup
  848. :type 'boolean)
  849. (defcustom org-agenda-entry-text-maxlines 5
  850. "Number of text lines to be added when `E' is pressed in the agenda.
  851. Note that this variable only used during agenda display. Add add entry text
  852. when exporting the agenda, configure the variable
  853. `org-agenda-add-entry-ext-maxlines'."
  854. :group 'org-agenda
  855. :type 'integer)
  856. (defcustom org-agenda-entry-text-exclude-regexps nil
  857. "List of regular expressions to clean up entry text.
  858. The complete matches of all regular expressions in this list will be
  859. removed from entry text before it is shown in the agenda."
  860. :group 'org-agenda
  861. :type '(repeat (regexp)))
  862. (defvar org-agenda-entry-text-cleanup-hook nil
  863. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  864. This cleanup is done in a temporary buffer, so the function may inspect and
  865. change the entire buffer.
  866. Some default stuff like drawers and scheduling/deadline dates will already
  867. have been removed when this is called, as will any matches for regular
  868. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  869. (defvar org-agenda-include-inactive-timestamps nil
  870. "Non-nil means include inactive time stamps in agenda and timeline.
  871. Dynamically scoped.")
  872. (defgroup org-agenda-windows nil
  873. "Options concerning the windows used by the Agenda in Org Mode."
  874. :tag "Org Agenda Windows"
  875. :group 'org-agenda)
  876. (defcustom org-agenda-window-setup 'reorganize-frame
  877. "How the agenda buffer should be displayed.
  878. Possible values for this option are:
  879. current-window Show agenda in the current window, keeping all other windows.
  880. other-window Use `switch-to-buffer-other-window' to display agenda.
  881. reorganize-frame Show only two windows on the current frame, the current
  882. window and the agenda.
  883. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  884. Also, when exiting the agenda, kill that frame.
  885. See also the variable `org-agenda-restore-windows-after-quit'."
  886. :group 'org-agenda-windows
  887. :type '(choice
  888. (const current-window)
  889. (const other-frame)
  890. (const other-window)
  891. (const reorganize-frame)))
  892. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  893. "The min and max height of the agenda window as a fraction of frame height.
  894. The value of the variable is a cons cell with two numbers between 0 and 1.
  895. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  896. :group 'org-agenda-windows
  897. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  898. (defcustom org-agenda-restore-windows-after-quit nil
  899. "Non-nil means restore window configuration upon exiting agenda.
  900. Before the window configuration is changed for displaying the agenda,
  901. the current status is recorded. When the agenda is exited with
  902. `q' or `x' and this option is set, the old state is restored. If
  903. `org-agenda-window-setup' is `other-frame', the value of this
  904. option will be ignored."
  905. :group 'org-agenda-windows
  906. :type 'boolean)
  907. (defcustom org-agenda-ndays nil
  908. "Number of days to include in overview display.
  909. Should be 1 or 7.
  910. Obsolete, see `org-agenda-span'."
  911. :group 'org-agenda-daily/weekly
  912. :type 'integer)
  913. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  914. (defcustom org-agenda-span 'week
  915. "Number of days to include in overview display.
  916. Can be day, week, month, year, or any number of days.
  917. Custom commands can set this variable in the options section."
  918. :group 'org-agenda-daily/weekly
  919. :type '(choice (const :tag "Day" day)
  920. (const :tag "Week" week)
  921. (const :tag "Month" month)
  922. (const :tag "Year" year)
  923. (integer :tag "Custom")))
  924. (defcustom org-agenda-start-on-weekday 1
  925. "Non-nil means start the overview always on the specified weekday.
  926. 0 denotes Sunday, 1 denotes Monday etc.
  927. When nil, always start on the current day.
  928. Custom commands can set this variable in the options section."
  929. :group 'org-agenda-daily/weekly
  930. :type '(choice (const :tag "Today" nil)
  931. (integer :tag "Weekday No.")))
  932. (defcustom org-agenda-show-all-dates t
  933. "Non-nil means `org-agenda' shows every day in the selected range.
  934. When nil, only the days which actually have entries are shown."
  935. :group 'org-agenda-daily/weekly
  936. :type 'boolean)
  937. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  938. "Format string for displaying dates in the agenda.
  939. Used by the daily/weekly agenda and by the timeline. This should be
  940. a format string understood by `format-time-string', or a function returning
  941. the formatted date as a string. The function must take a single argument,
  942. a calendar-style date list like (month day year)."
  943. :group 'org-agenda-daily/weekly
  944. :type '(choice
  945. (string :tag "Format string")
  946. (function :tag "Function")))
  947. (defun org-agenda-format-date-aligned (date)
  948. "Format a date string for display in the daily/weekly agenda, or timeline.
  949. This function makes sure that dates are aligned for easy reading."
  950. (require 'cal-iso)
  951. (let* ((dayname (calendar-day-name date))
  952. (day (cadr date))
  953. (day-of-week (calendar-day-of-week date))
  954. (month (car date))
  955. (monthname (calendar-month-name month))
  956. (year (nth 2 date))
  957. (iso-week (org-days-to-iso-week
  958. (calendar-absolute-from-gregorian date)))
  959. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  960. (1- year))
  961. ((and (= month 12) (<= iso-week 1))
  962. (1+ year))
  963. (t year)))
  964. (weekstring (if (= day-of-week 1)
  965. (format " W%02d" iso-week)
  966. "")))
  967. (format "%-10s %2d %s %4d%s"
  968. dayname day monthname year weekstring)))
  969. (defcustom org-agenda-time-leading-zero nil
  970. "Non-nil means use leading zero for military times in agenda.
  971. For example, 9:30am would become 09:30 rather than 9:30."
  972. :group 'org-agenda-daily/weekly
  973. :version "24.1"
  974. :type 'boolean)
  975. (defcustom org-agenda-timegrid-use-ampm nil
  976. "When set, show AM/PM style timestamps on the timegrid."
  977. :group 'org-agenda
  978. :version "24.1"
  979. :type 'boolean)
  980. (defun org-agenda-time-of-day-to-ampm (time)
  981. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  982. (let* ((hour-number (string-to-number (substring time 0 -3)))
  983. (minute (substring time -2))
  984. (ampm "am"))
  985. (cond
  986. ((equal hour-number 12)
  987. (setq ampm "pm"))
  988. ((> hour-number 12)
  989. (setq ampm "pm")
  990. (setq hour-number (- hour-number 12))))
  991. (concat
  992. (if org-agenda-time-leading-zero
  993. (format "%02d" hour-number)
  994. (format "%02s" (number-to-string hour-number)))
  995. ":" minute ampm)))
  996. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  997. "Conditionally convert TIME to AM/PM format
  998. based on `org-agenda-timegrid-use-ampm'"
  999. (if org-agenda-timegrid-use-ampm
  1000. (org-agenda-time-of-day-to-ampm time)
  1001. time))
  1002. (defcustom org-agenda-weekend-days '(6 0)
  1003. "Which days are weekend?
  1004. These days get the special face `org-agenda-date-weekend' in the agenda
  1005. and timeline buffers."
  1006. :group 'org-agenda-daily/weekly
  1007. :type '(set :greedy t
  1008. (const :tag "Monday" 1)
  1009. (const :tag "Tuesday" 2)
  1010. (const :tag "Wednesday" 3)
  1011. (const :tag "Thursday" 4)
  1012. (const :tag "Friday" 5)
  1013. (const :tag "Saturday" 6)
  1014. (const :tag "Sunday" 0)))
  1015. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1016. "Non-nil means jump to today when moving a past date forward in time.
  1017. When using S-right in the agenda to move a a date forward, and the date
  1018. stamp currently points to the past, the first key press will move it
  1019. to today. WHen nil, just move one day forward even if the date stays
  1020. in the past."
  1021. :group 'org-agenda-daily/weekly
  1022. :version "24.1"
  1023. :type 'boolean)
  1024. (defcustom org-agenda-include-diary nil
  1025. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1026. Custom commands can set this variable in the options section."
  1027. :group 'org-agenda-daily/weekly
  1028. :type 'boolean)
  1029. (defcustom org-agenda-include-deadlines t
  1030. "If non-nil, include entries within their deadline warning period.
  1031. Custom commands can set this variable in the options section."
  1032. :group 'org-agenda-daily/weekly
  1033. :version "24.1"
  1034. :type 'boolean)
  1035. (defcustom org-agenda-repeating-timestamp-show-all t
  1036. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1037. When set to a list of strings, only show occurrences of repeating
  1038. stamps for these TODO keywords. When nil, only one occurrence is
  1039. shown, either today or the nearest into the future."
  1040. :group 'org-agenda-daily/weekly
  1041. :type '(choice
  1042. (const :tag "Show repeating stamps" t)
  1043. (repeat :tag "Show repeating stamps for these TODO keywords"
  1044. (string :tag "TODO Keyword"))
  1045. (const :tag "Don't show repeating stamps" nil)))
  1046. (defcustom org-scheduled-past-days 10000
  1047. "No. of days to continue listing scheduled items that are not marked DONE.
  1048. When an item is scheduled on a date, it shows up in the agenda on this
  1049. day and will be listed until it is marked done for the number of days
  1050. given here."
  1051. :group 'org-agenda-daily/weekly
  1052. :type 'integer)
  1053. (defcustom org-agenda-log-mode-items '(closed clock)
  1054. "List of items that should be shown in agenda log mode.
  1055. This list may contain the following symbols:
  1056. closed Show entries that have been closed on that day.
  1057. clock Show entries that have received clocked time on that day.
  1058. state Show all logged state changes.
  1059. Note that instead of changing this variable, you can also press `C-u l' in
  1060. the agenda to display all available LOG items temporarily."
  1061. :group 'org-agenda-daily/weekly
  1062. :type '(set :greedy t (const closed) (const clock) (const state)))
  1063. (defcustom org-agenda-clock-consistency-checks
  1064. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1065. :gap-ok-around ("4:00")
  1066. :default-face ((:background "DarkRed") (:foreground "white"))
  1067. :overlap-face nil :gap-face nil :no-end-time-face nil
  1068. :long-face nil :short-face nil)
  1069. "This is a property list, with the following keys:
  1070. :max-duration Mark clocking chunks that are longer than this time.
  1071. This is a time string like \"HH:MM\", or the number
  1072. of minutes as an integer.
  1073. :min-duration Mark clocking chunks that are shorter that this.
  1074. This is a time string like \"HH:MM\", or the number
  1075. of minutes as an integer.
  1076. :max-gap Mark gaps between clocking chunks that are longer than
  1077. this duration. A number of minutes, or a string
  1078. like \"HH:MM\".
  1079. :gap-ok-around List of times during the day which are usually not working
  1080. times. When a gap is detected, but the gap contains any
  1081. of these times, the gap is *not* reported. For example,
  1082. if this is (\"4:00\" \"13:00\") then gaps that contain
  1083. 4:00 in the morning (i.e. the night) and 13:00
  1084. (i.e. a typical lunch time) do not cause a warning.
  1085. You should have at least one time during the night in this
  1086. list, or otherwise the first task each morning will trigger
  1087. a warning because it follows a long gap.
  1088. Furthermore, the following properties can be used to define faces for
  1089. issue display.
  1090. :default-face the default face, if the specific face is undefined
  1091. :overlap-face face for overlapping clocks
  1092. :gap-face face for gaps between clocks
  1093. :no-end-time-face face for incomplete clocks
  1094. :long-face face for clock intervals that are too long
  1095. :short-face face for clock intervals that are too short"
  1096. :group 'org-agenda-daily/weekly
  1097. :group 'org-clock
  1098. :version "24.1"
  1099. :type 'plist)
  1100. (defcustom org-agenda-log-mode-add-notes t
  1101. "Non-nil means add first line of notes to log entries in agenda views.
  1102. If a log item like a state change or a clock entry is associated with
  1103. notes, the first line of these notes will be added to the entry in the
  1104. agenda display."
  1105. :group 'org-agenda-daily/weekly
  1106. :type 'boolean)
  1107. (defcustom org-agenda-start-with-log-mode nil
  1108. "The initial value of log-mode in a newly created agenda window.
  1109. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1110. explanations on the possible values."
  1111. :group 'org-agenda-startup
  1112. :group 'org-agenda-daily/weekly
  1113. :type '(choice (const :tag "Don't show log items" nil)
  1114. (const :tag "Show only log items" 'only)
  1115. (const :tag "Show all possible log items" 'clockcheck)
  1116. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1117. (choice (const :tag "Show closed log items" 'closed)
  1118. (const :tag "Show clocked log items" 'clock)
  1119. (const :tag "Show all logged state changes" 'state)))))
  1120. (defcustom org-agenda-start-with-clockreport-mode nil
  1121. "The initial value of clockreport-mode in a newly created agenda window."
  1122. :group 'org-agenda-startup
  1123. :group 'org-agenda-daily/weekly
  1124. :type 'boolean)
  1125. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1126. "Property list with parameters for the clocktable in clockreport mode.
  1127. This is the display mode that shows a clock table in the daily/weekly
  1128. agenda, the properties for this dynamic block can be set here.
  1129. The usual clocktable parameters are allowed here, but you cannot set
  1130. the properties :name, :tstart, :tend, :block, and :scope - these will
  1131. be overwritten to make sure the content accurately reflects the
  1132. current display in the agenda."
  1133. :group 'org-agenda-daily/weekly
  1134. :type 'plist)
  1135. (defcustom org-agenda-search-view-always-boolean nil
  1136. "Non-nil means the search string is interpreted as individual parts.
  1137. The search string for search view can either be interpreted as a phrase,
  1138. or as a list of snippets that define a boolean search for a number of
  1139. strings.
  1140. When this is non-nil, the string will be split on whitespace, and each
  1141. snippet will be searched individually, and all must match in order to
  1142. select an entry. A snippet is then a single string of non-white
  1143. characters, or a string in double quotes, or a regexp in {} braces.
  1144. If a snippet is preceded by \"-\", the snippet must *not* match.
  1145. \"+\" is syntactic sugar for positive selection. Each snippet may
  1146. be found as a full word or a partial word, but see the variable
  1147. `org-agenda-search-view-force-full-words'.
  1148. When this is nil, search will look for the entire search phrase as one,
  1149. with each space character matching any amount of whitespace, including
  1150. line breaks.
  1151. Even when this is nil, you can still switch to Boolean search dynamically
  1152. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1153. is a regexp marked with braces like \"{abc}\", this will also switch to
  1154. boolean search."
  1155. :group 'org-agenda-search-view
  1156. :version "24.1"
  1157. :type 'boolean)
  1158. (if (fboundp 'defvaralias)
  1159. (defvaralias 'org-agenda-search-view-search-words-only
  1160. 'org-agenda-search-view-always-boolean))
  1161. (defcustom org-agenda-search-view-force-full-words nil
  1162. "Non-nil means, search words must be matches as complete words.
  1163. When nil, they may also match part of a word."
  1164. :group 'org-agenda-search-view
  1165. :version "24.1"
  1166. :type 'boolean)
  1167. (defgroup org-agenda-time-grid nil
  1168. "Options concerning the time grid in the Org-mode Agenda."
  1169. :tag "Org Agenda Time Grid"
  1170. :group 'org-agenda)
  1171. (defcustom org-agenda-search-headline-for-time t
  1172. "Non-nil means search headline for a time-of-day.
  1173. If the headline contains a time-of-day in one format or another, it will
  1174. be used to sort the entry into the time sequence of items for a day.
  1175. Some people have time stamps in the headline that refer to the creation
  1176. time or so, and then this produces an unwanted side effect. If this is
  1177. the case for your, use this variable to turn off searching the headline
  1178. for a time."
  1179. :group 'org-agenda-time-grid
  1180. :type 'boolean)
  1181. (defcustom org-agenda-use-time-grid t
  1182. "Non-nil means show a time grid in the agenda schedule.
  1183. A time grid is a set of lines for specific times (like every two hours between
  1184. 8:00 and 20:00). The items scheduled for a day at specific times are
  1185. sorted in between these lines.
  1186. For details about when the grid will be shown, and what it will look like, see
  1187. the variable `org-agenda-time-grid'."
  1188. :group 'org-agenda-time-grid
  1189. :type 'boolean)
  1190. (defcustom org-agenda-time-grid
  1191. '((daily today require-timed)
  1192. "----------------"
  1193. (800 1000 1200 1400 1600 1800 2000))
  1194. "The settings for time grid for agenda display.
  1195. This is a list of three items. The first item is again a list. It contains
  1196. symbols specifying conditions when the grid should be displayed:
  1197. daily if the agenda shows a single day
  1198. weekly if the agenda shows an entire week
  1199. today show grid on current date, independent of daily/weekly display
  1200. require-timed show grid only if at least one item has a time specification
  1201. The second item is a string which will be placed behind the grid time.
  1202. The third item is a list of integers, indicating the times that should have
  1203. a grid line."
  1204. :group 'org-agenda-time-grid
  1205. :type
  1206. '(list
  1207. (set :greedy t :tag "Grid Display Options"
  1208. (const :tag "Show grid in single day agenda display" daily)
  1209. (const :tag "Show grid in weekly agenda display" weekly)
  1210. (const :tag "Always show grid for today" today)
  1211. (const :tag "Show grid only if any timed entries are present"
  1212. require-timed)
  1213. (const :tag "Skip grid times already present in an entry"
  1214. remove-match))
  1215. (string :tag "Grid String")
  1216. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1217. (defcustom org-agenda-show-current-time-in-grid t
  1218. "Non-nil means show the current time in the time grid."
  1219. :group 'org-agenda-time-grid
  1220. :version "24.1"
  1221. :type 'boolean)
  1222. (defcustom org-agenda-current-time-string
  1223. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1224. "The string for the current time marker in the agenda."
  1225. :group 'org-agenda-time-grid
  1226. :version "24.1"
  1227. :type 'string)
  1228. (defgroup org-agenda-sorting nil
  1229. "Options concerning sorting in the Org-mode Agenda."
  1230. :tag "Org Agenda Sorting"
  1231. :group 'org-agenda)
  1232. (defcustom org-agenda-sorting-strategy
  1233. '((agenda habit-down time-up priority-down category-keep)
  1234. (todo priority-down category-keep)
  1235. (tags priority-down category-keep)
  1236. (search category-keep))
  1237. "Sorting structure for the agenda items of a single day.
  1238. This is a list of symbols which will be used in sequence to determine
  1239. if an entry should be listed before another entry. The following
  1240. symbols are recognized:
  1241. time-up Put entries with time-of-day indications first, early first
  1242. time-down Put entries with time-of-day indications first, late first
  1243. category-keep Keep the default order of categories, corresponding to the
  1244. sequence in `org-agenda-files'.
  1245. category-up Sort alphabetically by category, A-Z.
  1246. category-down Sort alphabetically by category, Z-A.
  1247. tag-up Sort alphabetically by last tag, A-Z.
  1248. tag-down Sort alphabetically by last tag, Z-A.
  1249. priority-up Sort numerically by priority, high priority last.
  1250. priority-down Sort numerically by priority, high priority first.
  1251. todo-state-up Sort by todo state, tasks that are done last.
  1252. todo-state-down Sort by todo state, tasks that are done first.
  1253. effort-up Sort numerically by estimated effort, high effort last.
  1254. effort-down Sort numerically by estimated effort, high effort first.
  1255. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1256. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1257. habit-up Put entries that are habits first
  1258. habit-down Put entries that are habits last
  1259. alpha-up Sort headlines alphabetically
  1260. alpha-down Sort headlines alphabetically, reversed
  1261. The different possibilities will be tried in sequence, and testing stops
  1262. if one comparison returns a \"not-equal\". For example, the default
  1263. '(time-up category-keep priority-down)
  1264. means: Pull out all entries having a specified time of day and sort them,
  1265. in order to make a time schedule for the current day the first thing in the
  1266. agenda listing for the day. Of the entries without a time indication, keep
  1267. the grouped in categories, don't sort the categories, but keep them in
  1268. the sequence given in `org-agenda-files'. Within each category sort by
  1269. priority.
  1270. Leaving out `category-keep' would mean that items will be sorted across
  1271. categories by priority.
  1272. Instead of a single list, this can also be a set of list for specific
  1273. contents, with a context symbol in the car of the list, any of
  1274. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1275. Custom commands can bind this variable in the options section."
  1276. :group 'org-agenda-sorting
  1277. :type `(choice
  1278. (repeat :tag "General" ,org-sorting-choice)
  1279. (list :tag "Individually"
  1280. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1281. (repeat ,org-sorting-choice))
  1282. (cons (const :tag "Strategy for TODO lists" todo)
  1283. (repeat ,org-sorting-choice))
  1284. (cons (const :tag "Strategy for Tags matches" tags)
  1285. (repeat ,org-sorting-choice))
  1286. (cons (const :tag "Strategy for search matches" search)
  1287. (repeat ,org-sorting-choice)))))
  1288. (defcustom org-agenda-cmp-user-defined nil
  1289. "A function to define the comparison `user-defined'.
  1290. This function must receive two arguments, agenda entry a and b.
  1291. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1292. the user comparison, return nil.
  1293. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1294. part of an agenda sorting strategy."
  1295. :group 'org-agenda-sorting
  1296. :type 'symbol)
  1297. (defcustom org-sort-agenda-notime-is-late t
  1298. "Non-nil means items without time are considered late.
  1299. This is only relevant for sorting. When t, items which have no explicit
  1300. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1301. do have a time. When nil, the default time is before 0:00. You can use this
  1302. option to decide if the schedule for today should come before or after timeless
  1303. agenda entries."
  1304. :group 'org-agenda-sorting
  1305. :type 'boolean)
  1306. (defcustom org-sort-agenda-noeffort-is-high t
  1307. "Non-nil means items without effort estimate are sorted as high effort.
  1308. This also applies when filtering an agenda view with respect to the
  1309. < or > effort operator. Then, tasks with no effort defined will be treated
  1310. as tasks with high effort.
  1311. When nil, such items are sorted as 0 minutes effort."
  1312. :group 'org-agenda-sorting
  1313. :type 'boolean)
  1314. (defgroup org-agenda-line-format nil
  1315. "Options concerning the entry prefix in the Org-mode agenda display."
  1316. :tag "Org Agenda Line Format"
  1317. :group 'org-agenda)
  1318. (defcustom org-agenda-prefix-format
  1319. '((agenda . " %i %-12:c%?-12t% s")
  1320. (timeline . " % s")
  1321. (todo . " %i %-12:c")
  1322. (tags . " %i %-12:c")
  1323. (search . " %i %-12:c"))
  1324. "Format specifications for the prefix of items in the agenda views.
  1325. An alist with five entries, each for the different agenda types. The
  1326. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1327. The values are format strings.
  1328. This format works similar to a printf format, with the following meaning:
  1329. %c the category of the item, \"Diary\" for entries from the diary,
  1330. or as given by the CATEGORY keyword or derived from the file name
  1331. %e the effort required by the item
  1332. %l the level of the item (insert X space(s) if item is of level X)
  1333. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1334. %T the last tag of the item (ignore inherited tags, which come first)
  1335. %t the HH:MM time-of-day specification if one applies to the entry
  1336. %s Scheduling/Deadline information, a short string
  1337. %(expression) Eval EXPRESSION and replace the control string
  1338. by the result
  1339. All specifiers work basically like the standard `%s' of printf, but may
  1340. contain two additional characters: a question mark just after the `%'
  1341. and a whitespace/punctuation character just before the final letter.
  1342. If the first character after `%' is a question mark, the entire field
  1343. will only be included if the corresponding value applies to the current
  1344. entry. This is useful for fields which should have fixed width when
  1345. present, but zero width when absent. For example, \"%?-12t\" will
  1346. result in a 12 character time field if a time of the day is specified,
  1347. but will completely disappear in entries which do not contain a time.
  1348. If there is punctuation or whitespace character just before the final
  1349. format letter, this character will be appended to the field value if
  1350. the value is not empty. For example, the format \"%-12:c\" leads to
  1351. \"Diary: \" if the category is \"Diary\". If the category were be
  1352. empty, no additional colon would be inserted.
  1353. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1354. which means:
  1355. - Indent the line with two space characters
  1356. - Give the category a 12 chars wide field, padded with whitespace on
  1357. the right (because of `-'). Append a colon if there is a category
  1358. (because of `:').
  1359. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1360. time, don't put in an empty field, just skip it (because of '?').
  1361. - Finally, put the scheduling information.
  1362. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1363. `org-agenda-remove-tags'.
  1364. Custom commands can set this variable in the options section."
  1365. :type '(choice
  1366. (string :tag "General format")
  1367. (list :greedy t :tag "View dependent"
  1368. (cons (const agenda) (string :tag "Format"))
  1369. (cons (const timeline) (string :tag "Format"))
  1370. (cons (const todo) (string :tag "Format"))
  1371. (cons (const tags) (string :tag "Format"))
  1372. (cons (const search) (string :tag "Format"))))
  1373. :group 'org-agenda-line-format)
  1374. (defvar org-prefix-format-compiled nil
  1375. "The compiled prefix format and associated variables.
  1376. This is a list where first element is a list of variable bindings, and second
  1377. element is the compiled format expression. See the variable
  1378. `org-agenda-prefix-format'.")
  1379. (defcustom org-agenda-todo-keyword-format "%-1s"
  1380. "Format for the TODO keyword in agenda lines.
  1381. Set this to something like \"%-12s\" if you want all TODO keywords
  1382. to occupy a fixed space in the agenda display."
  1383. :group 'org-agenda-line-format
  1384. :type 'string)
  1385. (defcustom org-agenda-diary-sexp-prefix nil
  1386. "A regexp that matches part of a diary sexp entry
  1387. which should be treated as scheduling/deadline information in
  1388. `org-agenda'.
  1389. For example, you can use this to extract the `diary-remind-message' from
  1390. `diary-remind' entries."
  1391. :group 'org-agenda-line-format
  1392. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1393. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1394. "Text preceding timerange entries in the agenda view.
  1395. This is a list with two strings. The first applies when the range
  1396. is entirely on one day. The second applies if the range spans several days.
  1397. The strings may have two \"%d\" format specifiers which will be filled
  1398. with the sequence number of the days, and the total number of days in the
  1399. range, respectively."
  1400. :group 'org-agenda-line-format
  1401. :type '(list
  1402. (string :tag "Deadline today ")
  1403. (choice :tag "Deadline relative"
  1404. (string :tag "Format string")
  1405. (function))))
  1406. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1407. "Text preceding scheduled items in the agenda view.
  1408. This is a list with two strings. The first applies when the item is
  1409. scheduled on the current day. The second applies when it has been scheduled
  1410. previously, it may contain a %d indicating that this is the nth time that
  1411. this item is scheduled, due to automatic rescheduling of unfinished items
  1412. for the following day. So this number is one larger than the number of days
  1413. that passed since this item was scheduled first."
  1414. :group 'org-agenda-line-format
  1415. :type '(list
  1416. (string :tag "Scheduled today ")
  1417. (string :tag "Scheduled previously")))
  1418. (defcustom org-agenda-inactive-leader "["
  1419. "Text preceding item pulled into the agenda by inactive time stamps.
  1420. These entries are added to the agenda when pressing \"[\"."
  1421. :group 'org-agenda-line-format
  1422. :version "24.1"
  1423. :type '(list
  1424. (string :tag "Scheduled today ")
  1425. (string :tag "Scheduled previously")))
  1426. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1427. "Text preceding deadline items in the agenda view.
  1428. This is a list with two strings. The first applies when the item has its
  1429. deadline on the current day. The second applies when it is in the past or
  1430. in the future, it may contain %d to capture how many days away the deadline
  1431. is (was)."
  1432. :group 'org-agenda-line-format
  1433. :type '(list
  1434. (string :tag "Deadline today ")
  1435. (choice :tag "Deadline relative"
  1436. (string :tag "Format string")
  1437. (function))))
  1438. (defcustom org-agenda-remove-times-when-in-prefix t
  1439. "Non-nil means remove duplicate time specifications in agenda items.
  1440. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1441. time-of-day specification in a headline or diary entry is extracted and
  1442. placed into the prefix. If this option is non-nil, the original specification
  1443. \(a timestamp or -range, or just a plain time(range) specification like
  1444. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1445. cluttered.
  1446. The option can be t or nil. It may also be the symbol `beg', indicating
  1447. that the time should only be removed when it is located at the beginning of
  1448. the headline/diary entry."
  1449. :group 'org-agenda-line-format
  1450. :type '(choice
  1451. (const :tag "Always" t)
  1452. (const :tag "Never" nil)
  1453. (const :tag "When at beginning of entry" beg)))
  1454. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1455. "Non-nil means remove time ranges specifications in agenda
  1456. items that span on several days."
  1457. :group 'org-agenda-line-format
  1458. :version "24.1"
  1459. :type 'boolean)
  1460. (defcustom org-agenda-default-appointment-duration nil
  1461. "Default duration for appointments that only have a starting time.
  1462. When nil, no duration is specified in such cases.
  1463. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1464. :group 'org-agenda-line-format
  1465. :type '(choice
  1466. (integer :tag "Minutes")
  1467. (const :tag "No default duration")))
  1468. (defcustom org-agenda-show-inherited-tags t
  1469. "Non-nil means show inherited tags in each agenda line."
  1470. :group 'org-agenda-line-format
  1471. :type 'boolean)
  1472. (defcustom org-agenda-hide-tags-regexp nil
  1473. "Regular expression used to filter away specific tags in agenda views.
  1474. This means that these tags will be present, but not be shown in the agenda
  1475. line. Secondary filtering will still work on the hidden tags.
  1476. Nil means don't hide any tags."
  1477. :group 'org-agenda-line-format
  1478. :type '(choice
  1479. (const :tag "Hide none" nil)
  1480. (string :tag "Regexp ")))
  1481. (defcustom org-agenda-remove-tags nil
  1482. "Non-nil means remove the tags from the headline copy in the agenda.
  1483. When this is the symbol `prefix', only remove tags when
  1484. `org-agenda-prefix-format' contains a `%T' specifier."
  1485. :group 'org-agenda-line-format
  1486. :type '(choice
  1487. (const :tag "Always" t)
  1488. (const :tag "Never" nil)
  1489. (const :tag "When prefix format contains %T" prefix)))
  1490. (if (fboundp 'defvaralias)
  1491. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1492. 'org-agenda-remove-tags))
  1493. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1494. "Shift tags in agenda items to this column.
  1495. If this number is positive, it specifies the column. If it is negative,
  1496. it means that the tags should be flushright to that column. For example,
  1497. -80 works well for a normal 80 character screen."
  1498. :group 'org-agenda-line-format
  1499. :type 'integer)
  1500. (if (fboundp 'defvaralias)
  1501. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1502. (defcustom org-agenda-fontify-priorities 'cookies
  1503. "Non-nil means highlight low and high priorities in agenda.
  1504. When t, the highest priority entries are bold, lowest priority italic.
  1505. However, settings in `org-priority-faces' will overrule these faces.
  1506. When this variable is the symbol `cookies', only fontify the
  1507. cookies, not the entire task.
  1508. This may also be an association list of priority faces, whose
  1509. keys are the character values of `org-highest-priority',
  1510. `org-default-priority', and `org-lowest-priority' (the default values
  1511. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1512. color as a string, or a list like `(:background \"Red\")'.
  1513. If it is a color, the variable `org-faces-easy-properties'
  1514. determines if it is a foreground or a background color."
  1515. :group 'org-agenda-line-format
  1516. :type '(choice
  1517. (const :tag "Never" nil)
  1518. (const :tag "Defaults" t)
  1519. (const :tag "Cookies only" cookies)
  1520. (repeat :tag "Specify"
  1521. (list (character :tag "Priority" :value ?A)
  1522. (choice :tag "Face "
  1523. (string :tag "Color")
  1524. (sexp :tag "Face"))))))
  1525. (defcustom org-agenda-day-face-function nil
  1526. "Function called to determine what face should be used to display a day.
  1527. The only argument passed to that function is the day. It should
  1528. returns a face, or nil if does not want to specify a face and let
  1529. the normal rules apply."
  1530. :group 'org-agenda-line-format
  1531. :version "24.1"
  1532. :type 'function)
  1533. (defcustom org-agenda-category-icon-alist nil
  1534. "Alist of category icon to be displayed in agenda views.
  1535. Each entry should have the following format:
  1536. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1537. Where CATEGORY-REGEXP is a regexp matching the categories where
  1538. the icon should be displayed.
  1539. FILE-OR-DATA either a file path or a string containing image data.
  1540. The other fields can be omitted safely if not needed:
  1541. TYPE indicates the image type.
  1542. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1543. image data.
  1544. PROPS are additional image attributes to assign to the image,
  1545. like, e.g. `:ascent center'.
  1546. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1547. If you want to set the display properties yourself, just put a
  1548. list as second element:
  1549. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1550. For example, to display a 16px horizontal space for Emacs
  1551. category, you can use:
  1552. (\"Emacs\" '(space . (:width (16))))"
  1553. :group 'org-agenda-line-format
  1554. :version "24.1"
  1555. :type '(alist :key-type (string :tag "Regexp matching category")
  1556. :value-type (choice (list :tag "Icon"
  1557. (string :tag "File or data")
  1558. (symbol :tag "Type")
  1559. (boolean :tag "Data?")
  1560. (repeat :tag "Extra image properties" :inline t symbol))
  1561. (list :tag "Display properties" sexp))))
  1562. (defgroup org-agenda-column-view nil
  1563. "Options concerning column view in the agenda."
  1564. :tag "Org Agenda Column View"
  1565. :group 'org-agenda)
  1566. (defcustom org-agenda-columns-show-summaries t
  1567. "Non-nil means show summaries for columns displayed in the agenda view."
  1568. :group 'org-agenda-column-view
  1569. :type 'boolean)
  1570. (defcustom org-agenda-columns-compute-summary-properties t
  1571. "Non-nil means recompute all summary properties before column view.
  1572. When column view in the agenda is listing properties that have a summary
  1573. operator, it can go to all relevant buffers and recompute the summaries
  1574. there. This can mean overhead for the agenda column view, but is necessary
  1575. to have thing up to date.
  1576. As a special case, a CLOCKSUM property also makes sure that the clock
  1577. computations are current."
  1578. :group 'org-agenda-column-view
  1579. :type 'boolean)
  1580. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1581. "Non-nil means the duration of an appointment will add to day effort.
  1582. The property to which appointment durations will be added is the one given
  1583. in the option `org-effort-property'. If an appointment does not have
  1584. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1585. is not set, an appointment without end time will not contribute to the time
  1586. estimate."
  1587. :group 'org-agenda-column-view
  1588. :type 'boolean)
  1589. (defcustom org-agenda-auto-exclude-function nil
  1590. "A function called with a tag to decide if it is filtered on '/ RET'.
  1591. The sole argument to the function, which is called once for each
  1592. possible tag, is a string giving the name of the tag. The
  1593. function should return either nil if the tag should be included
  1594. as normal, or \"-<TAG>\" to exclude the tag.
  1595. Note that for the purpose of tag filtering, only the lower-case version of
  1596. all tags will be considered, so that this function will only ever see
  1597. the lower-case version of all tags."
  1598. :group 'org-agenda
  1599. :type 'function)
  1600. (defcustom org-agenda-bulk-custom-functions nil
  1601. "Alist of characters and custom functions for bulk actions.
  1602. For example, this value makes those two functions available:
  1603. '((?R set-category)
  1604. (?C bulk-cut))
  1605. With selected entries in an agenda buffer, `B R' will call
  1606. the custom function `set-category' on the selected entries.
  1607. Note that functions in this alist don't need to be quoted."
  1608. :type 'alist
  1609. :version "24.1"
  1610. :group 'org-agenda)
  1611. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1612. "Execute BODY with point at location given by `org-hd-marker' property.
  1613. If STRING is non-nil, the text property will be fetched from position 0
  1614. in that string. If STRING is nil, it will be fetched from the beginning
  1615. of the current line."
  1616. (org-with-gensyms (marker)
  1617. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1618. 'org-hd-marker ,string)))
  1619. (with-current-buffer (marker-buffer ,marker)
  1620. (save-excursion
  1621. (goto-char ,marker)
  1622. ,@body)))))
  1623. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1624. (defun org-add-agenda-custom-command (entry)
  1625. "Replace or add a command in `org-agenda-custom-commands'.
  1626. This is mostly for hacking and trying a new command - once the command
  1627. works you probably want to add it to `org-agenda-custom-commands' for good."
  1628. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1629. (if ass
  1630. (setcdr ass (cdr entry))
  1631. (push entry org-agenda-custom-commands))))
  1632. ;;; Define the org-agenda-mode
  1633. (defvar org-agenda-mode-map (make-sparse-keymap)
  1634. "Keymap for `org-agenda-mode'.")
  1635. (if (fboundp 'defvaralias)
  1636. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1637. (defvar org-agenda-menu) ; defined later in this file.
  1638. (defvar org-agenda-restrict nil) ; defined later in this file.
  1639. (defvar org-agenda-follow-mode nil)
  1640. (defvar org-agenda-entry-text-mode nil)
  1641. (defvar org-agenda-clockreport-mode nil)
  1642. (defvar org-agenda-show-log nil)
  1643. (defvar org-agenda-redo-command nil)
  1644. (defvar org-agenda-query-string nil)
  1645. (defvar org-agenda-mode-hook nil
  1646. "Hook run after `org-agenda-mode' is turned on.
  1647. The buffer is still writable when this hook is called.")
  1648. (defvar org-agenda-type nil)
  1649. (defvar org-agenda-force-single-file nil)
  1650. (defvar org-agenda-bulk-marked-entries nil
  1651. "List of markers that refer to marked entries in the agenda.")
  1652. ;;; Multiple agenda buffers support
  1653. (defcustom org-agenda-sticky nil
  1654. "Non-nil means agenda q key will bury agenda buffers.
  1655. Agenda commands will then show existing buffer instead of generating new ones.
  1656. When nil, `q' will kill the single agenda buffer."
  1657. :group 'org-agenda
  1658. :version "24.3"
  1659. :type 'boolean)
  1660. ;;;###autoload
  1661. (defun org-toggle-sticky-agenda (&optional arg)
  1662. "Toggle `org-agenda-sticky'."
  1663. (interactive "P")
  1664. (let ((new-value (if arg
  1665. (> (prefix-numeric-value arg) 0)
  1666. (not org-agenda-sticky))))
  1667. (if (equal new-value org-agenda-sticky)
  1668. (and (org-called-interactively-p 'interactive)
  1669. (message "Sticky agenda was already %s"
  1670. (if org-agenda-sticky "enabled" "disabled")))
  1671. (setq org-agenda-sticky new-value)
  1672. (org-agenda-kill-all-agenda-buffers)
  1673. (and (org-called-interactively-p 'interactive)
  1674. (message "Sticky agenda was %s"
  1675. (if org-agenda-sticky "enabled" "disabled"))))))
  1676. (autoload 'org-toggle-sticky-agenda "org-agenda" "\
  1677. Toggle `org-agenda-sticky'.
  1678. \(fn &optional ARG)" t nil)
  1679. (defvar org-agenda-buffer nil
  1680. "Agenda buffer currently being generated.")
  1681. (defvar org-agenda-last-prefix-arg nil)
  1682. (defvar org-agenda-this-buffer-name nil)
  1683. (defvar org-agenda-doing-sticky-redo nil)
  1684. (defvar org-agenda-this-buffer-is-sticky nil)
  1685. (defconst org-agenda-local-vars
  1686. '(org-agenda-this-buffer-name
  1687. org-agenda-undo-list
  1688. org-agenda-pending-undo-list
  1689. org-agenda-follow-mode
  1690. org-agenda-entry-text-mode
  1691. org-agenda-clockreport-mode
  1692. org-agenda-show-log
  1693. org-agenda-redo-command
  1694. org-agenda-query-string
  1695. org-agenda-type
  1696. org-agenda-bulk-marked-entries
  1697. org-agenda-undo-has-started-in
  1698. org-agenda-info
  1699. org-agenda-tag-filter-overlays
  1700. org-agenda-cat-filter-overlays
  1701. org-agenda-pre-window-conf
  1702. org-agenda-columns-active
  1703. org-agenda-tag-filter
  1704. org-agenda-category-filter
  1705. org-agenda-markers
  1706. org-agenda-last-search-view-search-was-boolean
  1707. org-agenda-filtered-by-category
  1708. org-agenda-filter-form
  1709. org-agenda-show-window
  1710. org-agenda-cycle-counter
  1711. org-agenda-last-prefix-arg)
  1712. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1713. (defun org-agenda-mode ()
  1714. "Mode for time-sorted view on action items in Org-mode files.
  1715. The following commands are available:
  1716. \\{org-agenda-mode-map}"
  1717. (interactive)
  1718. (cond (org-agenda-doing-sticky-redo
  1719. ;; Refreshing sticky agenda-buffer
  1720. ;;
  1721. ;; Preserve the value of `org-agenda-local-vars' variables,
  1722. ;; while letting `kill-all-local-variables' kill the rest
  1723. (let ((save (buffer-local-variables)))
  1724. (kill-all-local-variables)
  1725. (mapc 'make-local-variable org-agenda-local-vars)
  1726. (dolist (elem save)
  1727. (let ((var (car elem))
  1728. (val (cdr elem)))
  1729. (when (and val
  1730. (member var org-agenda-local-vars))
  1731. (set var val)))))
  1732. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1733. (org-agenda-sticky
  1734. ;; Creating a sticky Agenda buffer for the first time
  1735. (kill-all-local-variables)
  1736. (mapc 'make-local-variable org-agenda-local-vars)
  1737. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1738. (t
  1739. ;; Creating a non-sticky agenda buffer
  1740. (kill-all-local-variables)
  1741. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1742. (setq org-agenda-undo-list nil
  1743. org-agenda-pending-undo-list nil
  1744. org-agenda-bulk-marked-entries nil)
  1745. (setq major-mode 'org-agenda-mode)
  1746. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1747. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1748. (setq mode-name "Org-Agenda")
  1749. (use-local-map org-agenda-mode-map)
  1750. (easy-menu-add org-agenda-menu)
  1751. (if org-startup-truncated (setq truncate-lines t))
  1752. (org-set-local 'line-move-visual nil)
  1753. (org-add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)
  1754. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1755. ;; Make sure properties are removed when copying text
  1756. (make-local-variable 'filter-buffer-substring-functions)
  1757. (add-hook 'filter-buffer-substring-functions
  1758. (lambda (fun start end delete)
  1759. (substring-no-properties (funcall fun start end delete))))
  1760. (unless org-agenda-keep-modes
  1761. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1762. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1763. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1764. org-agenda-show-log org-agenda-start-with-log-mode))
  1765. (easy-menu-change
  1766. '("Agenda") "Agenda Files"
  1767. (append
  1768. (list
  1769. (vector
  1770. (if (get 'org-agenda-files 'org-restrict)
  1771. "Restricted to single file"
  1772. "Edit File List")
  1773. '(org-edit-agenda-file-list)
  1774. (not (get 'org-agenda-files 'org-restrict)))
  1775. "--")
  1776. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1777. (org-agenda-set-mode-name)
  1778. (apply
  1779. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1780. (list 'org-agenda-mode-hook)))
  1781. (substitute-key-definition 'undo 'org-agenda-undo
  1782. org-agenda-mode-map global-map)
  1783. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1784. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1785. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1786. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1787. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1788. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1789. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1790. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1791. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1792. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1793. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1794. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1795. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1796. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1797. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1798. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1799. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1800. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1801. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1802. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1803. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1804. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1805. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1806. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1807. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1808. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1809. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1810. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1811. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1812. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1813. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1814. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1815. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1816. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1817. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1818. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1819. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1820. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1821. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1822. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1823. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1824. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1825. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1826. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1827. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1828. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1829. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1830. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1831. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1832. (while l (org-defkey org-agenda-mode-map
  1833. (int-to-string (pop l)) 'digit-argument)))
  1834. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1835. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1836. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1837. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1838. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1839. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1840. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1841. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1842. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1843. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1844. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1845. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1846. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1847. 'org-clock-modify-effort-estimate)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1849. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1850. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1851. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1852. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1853. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1854. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1855. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1856. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1857. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1858. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1859. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1860. (substitute-key-definition 'next-line 'org-agenda-next-line
  1861. org-agenda-mode-map global-map)
  1862. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1863. org-agenda-mode-map global-map)
  1864. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1865. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1866. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1867. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1868. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1869. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1870. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1871. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1872. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1873. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1874. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1875. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1877. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1878. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1879. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1880. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1881. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1882. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1883. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1884. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1885. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1886. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1887. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1888. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1889. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1890. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1891. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1892. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1893. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1894. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1895. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1896. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1897. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1898. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1899. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1900. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1901. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1902. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1903. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1904. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1905. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1906. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1907. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1908. (when org-agenda-mouse-1-follows-link
  1909. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1910. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1911. '("Agenda"
  1912. ("Agenda Files")
  1913. "--"
  1914. ("Agenda Dates"
  1915. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1916. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1917. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1918. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1919. "--"
  1920. ("View"
  1921. ["Day View" org-agenda-day-view
  1922. :active (org-agenda-check-type nil 'agenda)
  1923. :style radio :selected (eq org-agenda-current-span 'day)
  1924. :keys "v d (or just d)"]
  1925. ["Week View" org-agenda-week-view
  1926. :active (org-agenda-check-type nil 'agenda)
  1927. :style radio :selected (eq org-agenda-current-span 'week)
  1928. :keys "v w (or just w)"]
  1929. ["Month View" org-agenda-month-view
  1930. :active (org-agenda-check-type nil 'agenda)
  1931. :style radio :selected (eq org-agenda-current-span 'month)
  1932. :keys "v m"]
  1933. ["Year View" org-agenda-year-view
  1934. :active (org-agenda-check-type nil 'agenda)
  1935. :style radio :selected (eq org-agenda-current-span 'year)
  1936. :keys "v y"]
  1937. "--"
  1938. ["Include Diary" org-agenda-toggle-diary
  1939. :style toggle :selected org-agenda-include-diary
  1940. :active (org-agenda-check-type nil 'agenda)]
  1941. ["Include Deadlines" org-agenda-toggle-deadlines
  1942. :style toggle :selected org-agenda-include-deadlines
  1943. :active (org-agenda-check-type nil 'agenda)]
  1944. ["Use Time Grid" org-agenda-toggle-time-grid
  1945. :style toggle :selected org-agenda-use-time-grid
  1946. :active (org-agenda-check-type nil 'agenda)]
  1947. "--"
  1948. ["Show clock report" org-agenda-clockreport-mode
  1949. :style toggle :selected org-agenda-clockreport-mode
  1950. :active (org-agenda-check-type nil 'agenda)]
  1951. ["Show some entry text" org-agenda-entry-text-mode
  1952. :style toggle :selected org-agenda-entry-text-mode
  1953. :active t]
  1954. "--"
  1955. ["Show Logbook entries" org-agenda-log-mode
  1956. :style toggle :selected org-agenda-show-log
  1957. :active (org-agenda-check-type nil 'agenda 'timeline)
  1958. :keys "v l (or just l)"]
  1959. ["Include archived trees" org-agenda-archives-mode
  1960. :style toggle :selected org-agenda-archives-mode :active t
  1961. :keys "v a"]
  1962. ["Include archive files" (org-agenda-archives-mode t)
  1963. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1964. :keys "v A"]
  1965. "--"
  1966. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1967. ["Write view to file" org-agenda-write t]
  1968. ["Rebuild buffer" org-agenda-redo t]
  1969. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1970. "--"
  1971. ["Show original entry" org-agenda-show t]
  1972. ["Go To (other window)" org-agenda-goto t]
  1973. ["Go To (this window)" org-agenda-switch-to t]
  1974. ["Capture with cursor date" org-agenda-capture t]
  1975. ["Follow Mode" org-agenda-follow-mode
  1976. :style toggle :selected org-agenda-follow-mode :active t]
  1977. ;; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1978. "--"
  1979. ("TODO"
  1980. ["Cycle TODO" org-agenda-todo t]
  1981. ["Next TODO set" org-agenda-todo-nextset t]
  1982. ["Previous TODO set" org-agenda-todo-previousset t]
  1983. ["Add note" org-agenda-add-note t])
  1984. ("Archive/Refile/Delete"
  1985. ["Archive default" org-agenda-archive-default t]
  1986. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1987. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1988. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1989. ["Archive subtree" org-agenda-archive t]
  1990. "--"
  1991. ["Refile" org-agenda-refile t]
  1992. "--"
  1993. ["Delete subtree" org-agenda-kill t])
  1994. ("Bulk action"
  1995. ["Mark entry" org-agenda-bulk-mark t]
  1996. ["Mark all" org-agenda-bulk-mark-all t]
  1997. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1998. ["Unmark entry" org-agenda-bulk-unmark t]
  1999. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  2000. ["Act on all marked" org-agenda-bulk-action t]
  2001. "--"
  2002. ("Tags and Properties"
  2003. ["Show all Tags" org-agenda-show-tags t]
  2004. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  2005. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  2006. "--"
  2007. ["Column View" org-columns t])
  2008. ("Deadline/Schedule"
  2009. ["Schedule" org-agenda-schedule t]
  2010. ["Set Deadline" org-agenda-deadline t]
  2011. "--"
  2012. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  2013. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  2014. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  2015. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2016. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2017. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2018. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2019. ("Clock and Effort"
  2020. ["Clock in" org-agenda-clock-in t]
  2021. ["Clock out" org-agenda-clock-out t]
  2022. ["Clock cancel" org-agenda-clock-cancel t]
  2023. ["Goto running clock" org-clock-goto t]
  2024. "--"
  2025. ["Set Effort" org-agenda-set-effort t]
  2026. ["Change clocked effort" org-clock-modify-effort-estimate
  2027. (org-clock-is-active)])
  2028. ("Priority"
  2029. ["Set Priority" org-agenda-priority t]
  2030. ["Increase Priority" org-agenda-priority-up t]
  2031. ["Decrease Priority" org-agenda-priority-down t]
  2032. ["Show Priority" org-show-priority t])
  2033. ("Calendar/Diary"
  2034. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2035. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2036. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2037. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2038. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2039. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2040. "--"
  2041. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2042. "--"
  2043. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2044. "--"
  2045. ("MobileOrg"
  2046. ["Push Files and Views" org-mobile-push t]
  2047. ["Get Captured and Flagged" org-mobile-pull t]
  2048. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2049. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2050. "--"
  2051. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2052. "--"
  2053. ["Quit" org-agenda-quit t]
  2054. ["Exit and Release Buffers" org-agenda-exit t]
  2055. ))
  2056. ;;; Agenda undo
  2057. (defvar org-agenda-allow-remote-undo t
  2058. "Non-nil means allow remote undo from the agenda buffer.")
  2059. (defvar org-agenda-undo-has-started-in nil
  2060. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2061. (defun org-agenda-undo ()
  2062. "Undo a remote editing step in the agenda.
  2063. This undoes changes both in the agenda buffer and in the remote buffer
  2064. that have been changed along."
  2065. (interactive)
  2066. (or org-agenda-allow-remote-undo
  2067. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2068. (if (not (eq this-command last-command))
  2069. (setq org-agenda-undo-has-started-in nil
  2070. org-agenda-pending-undo-list org-agenda-undo-list))
  2071. (if (not org-agenda-pending-undo-list)
  2072. (error "No further undo information"))
  2073. (let* ((entry (pop org-agenda-pending-undo-list))
  2074. buf line cmd rembuf)
  2075. (setq cmd (pop entry) line (pop entry))
  2076. (setq rembuf (nth 2 entry))
  2077. (org-with-remote-undo rembuf
  2078. (while (bufferp (setq buf (pop entry)))
  2079. (if (pop entry)
  2080. (with-current-buffer buf
  2081. (let ((last-undo-buffer buf)
  2082. (inhibit-read-only t))
  2083. (unless (memq buf org-agenda-undo-has-started-in)
  2084. (push buf org-agenda-undo-has-started-in)
  2085. (make-local-variable 'pending-undo-list)
  2086. (undo-start))
  2087. (while (and pending-undo-list
  2088. (listp pending-undo-list)
  2089. (not (car pending-undo-list)))
  2090. (pop pending-undo-list))
  2091. (undo-more 1))))))
  2092. (org-goto-line line)
  2093. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2094. (defun org-verify-change-for-undo (l1 l2)
  2095. "Verify that a real change occurred between the undo lists L1 and L2."
  2096. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2097. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2098. (not (eq l1 l2)))
  2099. ;;; Agenda dispatch
  2100. (defvar org-agenda-restrict-begin (make-marker))
  2101. (defvar org-agenda-restrict-end (make-marker))
  2102. (defvar org-agenda-last-dispatch-buffer nil)
  2103. (defvar org-agenda-overriding-restriction nil)
  2104. (defcustom org-agenda-custom-commands-contexts nil
  2105. "Alist of custom agenda keys and contextual rules.
  2106. For example, if you have a custom agenda command \"p\" and you
  2107. want this command to be accessible only from plain text files,
  2108. use this:
  2109. '((\"p\" (in-file . \"\\.txt\")))
  2110. Here are the available contexts definitions:
  2111. in-file: command displayed only in matching files
  2112. in-mode: command displayed only in matching modes
  2113. not-in-file: command not displayed in matching files
  2114. not-in-mode: command not displayed in matching modes
  2115. [function]: a custom function taking no argument
  2116. If you define several checks, the agenda command will be
  2117. accessible if there is at least one valid check.
  2118. You can also bind a key to another agenda custom command
  2119. depending on contextual rules.
  2120. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2121. Here it means: in .txt files, use \"p\" as the key for the
  2122. agenda command otherwise associated with \"q\". (The command
  2123. originally associated with \"q\" is not displayed to avoid
  2124. duplicates.)"
  2125. :version "24.3"
  2126. :group 'org-agenda-custom-commands
  2127. :type '(repeat (list :tag "Rule"
  2128. (string :tag " Agenda key")
  2129. (string :tag "Replace by command")
  2130. (repeat :tag "Available when"
  2131. (choice
  2132. (cons :tag "Condition"
  2133. (choice
  2134. (const :tag "In file" in-file)
  2135. (const :tag "Not in file" not-in-file)
  2136. (const :tag "In mode" in-mode)
  2137. (const :tag "Not in mode" not-in-mode))
  2138. (regexp))
  2139. (function :tag "Custom function"))))))
  2140. (defvar org-keys nil)
  2141. (defvar org-match nil)
  2142. ;;;###autoload
  2143. (defun org-agenda (&optional arg org-keys restriction)
  2144. "Dispatch agenda commands to collect entries to the agenda buffer.
  2145. Prompts for a command to execute. Any prefix arg will be passed
  2146. on to the selected command. The default selections are:
  2147. a Call `org-agenda-list' to display the agenda for current day or week.
  2148. t Call `org-todo-list' to display the global todo list.
  2149. T Call `org-todo-list' to display the global todo list, select only
  2150. entries with a specific TODO keyword (the user gets a prompt).
  2151. m Call `org-tags-view' to display headlines with tags matching
  2152. a condition (the user is prompted for the condition).
  2153. M Like `m', but select only TODO entries, no ordinary headlines.
  2154. L Create a timeline for the current buffer.
  2155. e Export views to associated files.
  2156. s Search entries for keywords.
  2157. S Search entries for keywords, only with TODO keywords.
  2158. / Multi occur across all agenda files and also files listed
  2159. in `org-agenda-text-search-extra-files'.
  2160. < Restrict agenda commands to buffer, subtree, or region.
  2161. Press several times to get the desired effect.
  2162. > Remove a previous restriction.
  2163. # List \"stuck\" projects.
  2164. ! Configure what \"stuck\" means.
  2165. C Configure custom agenda commands.
  2166. More commands can be added by configuring the variable
  2167. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2168. searches can be pre-defined in this way.
  2169. If the current buffer is in Org-mode and visiting a file, you can also
  2170. first press `<' once to indicate that the agenda should be temporarily
  2171. \(until the next use of \\[org-agenda]) restricted to the current file.
  2172. Pressing `<' twice means to restrict to the current subtree or region
  2173. \(if active)."
  2174. (interactive "P")
  2175. (catch 'exit
  2176. (let* ((prefix-descriptions nil)
  2177. (org-agenda-buffer-name org-agenda-buffer-name)
  2178. (org-agenda-window-setup (if (equal (buffer-name)
  2179. org-agenda-buffer-name)
  2180. 'current-window
  2181. org-agenda-window-setup))
  2182. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2183. (org-agenda-custom-commands
  2184. ;; normalize different versions
  2185. (delq nil
  2186. (mapcar
  2187. (lambda (x)
  2188. (cond ((stringp (cdr x))
  2189. (push x prefix-descriptions)
  2190. nil)
  2191. ((stringp (nth 1 x)) x)
  2192. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2193. (t (cons (car x) (cons "" (cdr x))))))
  2194. org-agenda-custom-commands)))
  2195. (org-agenda-custom-commands
  2196. (org-contextualize-keys
  2197. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2198. (buf (current-buffer))
  2199. (bfn (buffer-file-name (buffer-base-buffer)))
  2200. entry key type org-match lprops ans)
  2201. ;; Turn off restriction unless there is an overriding one,
  2202. (unless org-agenda-overriding-restriction
  2203. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2204. ;; There is a request to keep the file list in place
  2205. (put 'org-agenda-files 'org-restrict nil))
  2206. (setq org-agenda-restrict nil)
  2207. (move-marker org-agenda-restrict-begin nil)
  2208. (move-marker org-agenda-restrict-end nil))
  2209. ;; Delete old local properties
  2210. (put 'org-agenda-redo-command 'org-lprops nil)
  2211. ;; Delete previously set last-arguments
  2212. (put 'org-agenda-redo-command 'last-args nil)
  2213. ;; Remember where this call originated
  2214. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2215. (unless org-keys
  2216. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2217. org-keys (car ans)
  2218. restriction (cdr ans)))
  2219. ;; If we have sticky agenda buffers, set a name for the buffer,
  2220. ;; depending on the invoking keys. The user may still set this
  2221. ;; as a command option, which will overwrite what we do here.
  2222. (if org-agenda-sticky
  2223. (setq org-agenda-buffer-name
  2224. (format "*Org Agenda(%s)*" org-keys)))
  2225. ;; Establish the restriction, if any
  2226. (when (and (not org-agenda-overriding-restriction) restriction)
  2227. (put 'org-agenda-files 'org-restrict (list bfn))
  2228. (cond
  2229. ((eq restriction 'region)
  2230. (setq org-agenda-restrict t)
  2231. (move-marker org-agenda-restrict-begin (region-beginning))
  2232. (move-marker org-agenda-restrict-end (region-end)))
  2233. ((eq restriction 'subtree)
  2234. (save-excursion
  2235. (setq org-agenda-restrict t)
  2236. (org-back-to-heading t)
  2237. (move-marker org-agenda-restrict-begin (point))
  2238. (move-marker org-agenda-restrict-end
  2239. (progn (org-end-of-subtree t)))))))
  2240. ;; For example the todo list should not need it (but does...)
  2241. (cond
  2242. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2243. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2244. (progn
  2245. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2246. lprops (nth 4 entry))
  2247. (if org-agenda-sticky
  2248. (setq org-agenda-buffer-name
  2249. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2250. (format "*Org Agenda(%s)*" org-keys))))
  2251. (put 'org-agenda-redo-command 'org-lprops lprops)
  2252. (cond
  2253. ((eq type 'agenda)
  2254. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2255. ((eq type 'alltodo)
  2256. (org-let lprops '(org-todo-list current-prefix-arg)))
  2257. ((eq type 'search)
  2258. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2259. ((eq type 'stuck)
  2260. (org-let lprops '(org-agenda-list-stuck-projects
  2261. current-prefix-arg)))
  2262. ((eq type 'tags)
  2263. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2264. ((eq type 'tags-todo)
  2265. (org-let lprops '(org-tags-view '(4) org-match)))
  2266. ((eq type 'todo)
  2267. (org-let lprops '(org-todo-list org-match)))
  2268. ((eq type 'tags-tree)
  2269. (org-check-for-org-mode)
  2270. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2271. ((eq type 'todo-tree)
  2272. (org-check-for-org-mode)
  2273. (org-let lprops
  2274. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2275. (regexp-quote org-match) "\\>"))))
  2276. ((eq type 'occur-tree)
  2277. (org-check-for-org-mode)
  2278. (org-let lprops '(org-occur org-match)))
  2279. ((functionp type)
  2280. (org-let lprops '(funcall type org-match)))
  2281. ((fboundp type)
  2282. (org-let lprops '(funcall type org-match)))
  2283. (t (error "Invalid custom agenda command type %s" type))))
  2284. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2285. ((equal org-keys "C")
  2286. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2287. (customize-variable 'org-agenda-custom-commands))
  2288. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2289. ((equal org-keys "s") (call-interactively 'org-search-view))
  2290. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2291. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2292. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2293. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2294. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2295. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2296. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2297. (org-add-hook
  2298. 'post-command-hook
  2299. (lambda ()
  2300. (unless (current-message)
  2301. (let* ((m (org-agenda-get-any-marker))
  2302. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2303. (when note
  2304. (message (concat
  2305. "FLAGGING-NOTE ([?] for more info): "
  2306. (org-add-props
  2307. (replace-regexp-in-string
  2308. "\\\\n" "//"
  2309. (copy-sequence note))
  2310. nil 'face 'org-warning)))))))
  2311. t t))
  2312. ((equal org-keys "L")
  2313. (unless (derived-mode-p 'org-mode)
  2314. (error "This is not an Org-mode file"))
  2315. (unless restriction
  2316. (put 'org-agenda-files 'org-restrict (list bfn))
  2317. (org-call-with-arg 'org-timeline arg)))
  2318. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2319. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2320. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2321. (t (error "Invalid agenda key"))))))
  2322. (autoload 'org-agenda "org-agenda" "\
  2323. Dispatch agenda commands to collect entries to the agenda buffer.
  2324. Prompts for a command to execute. Any prefix arg will be passed
  2325. on to the selected command. The default selections are:
  2326. a Call `org-agenda-list' to display the agenda for current day or week.
  2327. t Call `org-todo-list' to display the global todo list.
  2328. T Call `org-todo-list' to display the global todo list, select only
  2329. entries with a specific TODO keyword (the user gets a prompt).
  2330. m Call `org-tags-view' to display headlines with tags matching
  2331. a condition (the user is prompted for the condition).
  2332. M Like `m', but select only TODO entries, no ordinary headlines.
  2333. L Create a timeline for the current buffer.
  2334. e Export views to associated files.
  2335. s Search entries for keywords.
  2336. S Search entries for keywords, only with TODO keywords.
  2337. / Multi occur across all agenda files and also files listed
  2338. in `org-agenda-text-search-extra-files'.
  2339. < Restrict agenda commands to buffer, subtree, or region.
  2340. Press several times to get the desired effect.
  2341. > Remove a previous restriction.
  2342. # List \"stuck\" projects.
  2343. ! Configure what \"stuck\" means.
  2344. C Configure custom agenda commands.
  2345. More commands can be added by configuring the variable
  2346. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2347. searches can be pre-defined in this way.
  2348. If the current buffer is in Org-mode and visiting a file, you can also
  2349. first press `<' once to indicate that the agenda should be temporarily
  2350. \(until the next use of \\[org-agenda]) restricted to the current file.
  2351. Pressing `<' twice means to restrict to the current subtree or region
  2352. \(if active).
  2353. \(fn &optional ARG ORG-KEYS RESTRICTION)" t nil)
  2354. (defun org-agenda-append-agenda ()
  2355. "Append another agenda view to the current one.
  2356. This function allows interactive building of block agendas.
  2357. Agenda views are separated by `org-agenda-block-separator'."
  2358. (interactive)
  2359. (unless (derived-mode-p 'org-agenda-mode)
  2360. (error "Can only append from within agenda buffer"))
  2361. (let ((org-agenda-multi t))
  2362. (org-agenda)
  2363. (widen)
  2364. (org-agenda-finalize)
  2365. (org-agenda-fit-window-to-buffer)))
  2366. (defun org-agenda-normalize-custom-commands (cmds)
  2367. (delq nil
  2368. (mapcar
  2369. (lambda (x)
  2370. (cond ((stringp (cdr x)) nil)
  2371. ((stringp (nth 1 x)) x)
  2372. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2373. (t (cons (car x) (cons "" (cdr x))))))
  2374. cmds)))
  2375. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2376. "The user interface for selecting an agenda command."
  2377. (catch 'exit
  2378. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2379. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2380. (region-p (org-region-active-p))
  2381. (custom org-agenda-custom-commands)
  2382. (selstring "")
  2383. restriction second-time
  2384. c entry key type match prefixes rmheader header-end custom1 desc
  2385. line lines left right n n1)
  2386. (save-window-excursion
  2387. (delete-other-windows)
  2388. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2389. (erase-buffer)
  2390. (insert (eval-when-compile
  2391. (let ((header
  2392. "Press key for an agenda command: < Buffer, subtree/region restriction
  2393. -------------------------------- > Remove restriction
  2394. a Agenda for current week or day e Export agenda views
  2395. t List of all TODO entries T Entries with special TODO kwd
  2396. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2397. s Search for keywords S Like s, but only TODO entries
  2398. L Timeline for current buffer # List stuck projects (!=configure)
  2399. / Multi-occur C Configure custom agenda commands
  2400. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2401. ")
  2402. (start 0))
  2403. (while (string-match
  2404. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2405. header start)
  2406. (setq start (match-end 0))
  2407. (add-text-properties (match-beginning 2) (match-end 2)
  2408. '(face bold) header))
  2409. header)))
  2410. (setq header-end (move-marker (make-marker) (point)))
  2411. (while t
  2412. (setq custom1 custom)
  2413. (when (eq rmheader t)
  2414. (org-goto-line 1)
  2415. (re-search-forward ":" nil t)
  2416. (delete-region (match-end 0) (point-at-eol))
  2417. (forward-char 1)
  2418. (looking-at "-+")
  2419. (delete-region (match-end 0) (point-at-eol))
  2420. (move-marker header-end (match-end 0)))
  2421. (goto-char header-end)
  2422. (delete-region (point) (point-max))
  2423. ;; Produce all the lines that describe custom commands and prefixes
  2424. (setq lines nil)
  2425. (while (setq entry (pop custom1))
  2426. (setq key (car entry) desc (nth 1 entry)
  2427. type (nth 2 entry)
  2428. match (nth 3 entry))
  2429. (if (> (length key) 1)
  2430. (add-to-list 'prefixes (string-to-char key))
  2431. (setq line
  2432. (format
  2433. "%-4s%-14s"
  2434. (org-add-props (copy-sequence key)
  2435. '(face bold))
  2436. (cond
  2437. ((string-match "\\S-" desc) desc)
  2438. ((eq type 'agenda) "Agenda for current week or day")
  2439. ((eq type 'alltodo) "List of all TODO entries")
  2440. ((eq type 'search) "Word search")
  2441. ((eq type 'stuck) "List of stuck projects")
  2442. ((eq type 'todo) "TODO keyword")
  2443. ((eq type 'tags) "Tags query")
  2444. ((eq type 'tags-todo) "Tags (TODO)")
  2445. ((eq type 'tags-tree) "Tags tree")
  2446. ((eq type 'todo-tree) "TODO kwd tree")
  2447. ((eq type 'occur-tree) "Occur tree")
  2448. ((functionp type) (if (symbolp type)
  2449. (symbol-name type)
  2450. "Lambda expression"))
  2451. (t "???"))))
  2452. (if org-agenda-menu-show-matcher
  2453. (setq line
  2454. (concat line ": "
  2455. (cond
  2456. ((stringp match)
  2457. (setq match (copy-sequence match))
  2458. (org-add-props match nil 'face 'org-warning))
  2459. ((listp type)
  2460. (format "set of %d commands" (length type))))))
  2461. (if (org-string-nw-p match)
  2462. (add-text-properties
  2463. 0 (length line) (list 'help-echo
  2464. (concat "Matcher: " match)) line)))
  2465. (push line lines)))
  2466. (setq lines (nreverse lines))
  2467. (when prefixes
  2468. (mapc (lambda (x)
  2469. (push
  2470. (format "%s %s"
  2471. (org-add-props (char-to-string x)
  2472. nil 'face 'bold)
  2473. (or (cdr (assoc (concat selstring
  2474. (char-to-string x))
  2475. prefix-descriptions))
  2476. "Prefix key"))
  2477. lines))
  2478. prefixes))
  2479. ;; Check if we should display in two columns
  2480. (if org-agenda-menu-two-columns
  2481. (progn
  2482. (setq n (length lines)
  2483. n1 (+ (/ n 2) (mod n 2))
  2484. right (nthcdr n1 lines)
  2485. left (copy-sequence lines))
  2486. (setcdr (nthcdr (1- n1) left) nil))
  2487. (setq left lines right nil))
  2488. (while left
  2489. (insert "\n" (pop left))
  2490. (when right
  2491. (if (< (current-column) 40)
  2492. (move-to-column 40 t)
  2493. (insert " "))
  2494. (insert (pop right))))
  2495. ;; Make the window the right size
  2496. (goto-char (point-min))
  2497. (if second-time
  2498. (if (not (pos-visible-in-window-p (point-max)))
  2499. (org-fit-window-to-buffer))
  2500. (setq second-time t)
  2501. (org-fit-window-to-buffer))
  2502. ;; Ask for selection
  2503. (message "Press key for agenda command%s:"
  2504. (if (or restrict-ok org-agenda-overriding-restriction)
  2505. (if org-agenda-overriding-restriction
  2506. " (restriction lock active)"
  2507. (if restriction
  2508. (format " (restricted to %s)" restriction)
  2509. " (unrestricted)"))
  2510. ""))
  2511. (setq c (read-char-exclusive))
  2512. (message "")
  2513. (cond
  2514. ((assoc (char-to-string c) custom)
  2515. (setq selstring (concat selstring (char-to-string c)))
  2516. (throw 'exit (cons selstring restriction)))
  2517. ((memq c prefixes)
  2518. (setq selstring (concat selstring (char-to-string c))
  2519. prefixes nil
  2520. rmheader (or rmheader t)
  2521. custom (delq nil (mapcar
  2522. (lambda (x)
  2523. (if (or (= (length (car x)) 1)
  2524. (/= (string-to-char (car x)) c))
  2525. nil
  2526. (cons (substring (car x) 1) (cdr x))))
  2527. custom))))
  2528. ((eq c ?*)
  2529. (call-interactively 'org-toggle-sticky-agenda)
  2530. (sit-for 2))
  2531. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2532. (message "Restriction is only possible in Org-mode buffers")
  2533. (ding) (sit-for 1))
  2534. ((eq c ?1)
  2535. (org-agenda-remove-restriction-lock 'noupdate)
  2536. (setq restriction 'buffer))
  2537. ((eq c ?0)
  2538. (org-agenda-remove-restriction-lock 'noupdate)
  2539. (setq restriction (if region-p 'region 'subtree)))
  2540. ((eq c ?<)
  2541. (org-agenda-remove-restriction-lock 'noupdate)
  2542. (setq restriction
  2543. (cond
  2544. ((eq restriction 'buffer)
  2545. (if region-p 'region 'subtree))
  2546. ((memq restriction '(subtree region))
  2547. nil)
  2548. (t 'buffer))))
  2549. ((eq c ?>)
  2550. (org-agenda-remove-restriction-lock 'noupdate)
  2551. (setq restriction nil))
  2552. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2553. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2554. ((and (> (length selstring) 0) (eq c ?\d))
  2555. (delete-window)
  2556. (org-agenda-get-restriction-and-command prefix-descriptions))
  2557. ((equal c ?q) (error "Abort"))
  2558. (t (error "Invalid key %c" c))))))))
  2559. (defun org-agenda-fit-window-to-buffer ()
  2560. "Fit the window to the buffer size."
  2561. (and (memq org-agenda-window-setup '(reorganize-frame))
  2562. (fboundp 'fit-window-to-buffer)
  2563. (org-fit-window-to-buffer
  2564. nil
  2565. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2566. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2567. (defvar org-cmd nil)
  2568. (defvar org-agenda-overriding-cmd nil)
  2569. (defvar org-agenda-overriding-arguments nil)
  2570. (defvar org-agenda-overriding-cmd-arguments nil)
  2571. (defun org-agenda-run-series (name series)
  2572. (org-let (nth 1 series) '(org-agenda-prepare name))
  2573. ;; We need to reset agenda markers here, because when constructing a
  2574. ;; block agenda, the individual blocks do not do that.
  2575. (org-agenda-reset-markers)
  2576. (let* ((org-agenda-multi t)
  2577. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2578. (cmds (car series))
  2579. (gprops (nth 1 series))
  2580. match ;; The byte compiler incorrectly complains about this. Keep it!
  2581. org-cmd type lprops)
  2582. (while (setq org-cmd (pop cmds))
  2583. (setq type (car org-cmd)
  2584. match (eval (nth 1 org-cmd))
  2585. lprops (nth 2 org-cmd))
  2586. (let ((org-agenda-overriding-arguments
  2587. (if (eq org-agenda-overriding-cmd org-cmd)
  2588. (or org-agenda-overriding-arguments
  2589. org-agenda-overriding-cmd-arguments))))
  2590. (cond
  2591. ((eq type 'agenda)
  2592. (org-let2 gprops lprops
  2593. '(call-interactively 'org-agenda-list)))
  2594. ((eq type 'alltodo)
  2595. (org-let2 gprops lprops
  2596. '(call-interactively 'org-todo-list)))
  2597. ((eq type 'search)
  2598. (org-let2 gprops lprops
  2599. '(org-search-view current-prefix-arg match nil)))
  2600. ((eq type 'stuck)
  2601. (org-let2 gprops lprops
  2602. '(call-interactively 'org-agenda-list-stuck-projects)))
  2603. ((eq type 'tags)
  2604. (org-let2 gprops lprops
  2605. '(org-tags-view current-prefix-arg match)))
  2606. ((eq type 'tags-todo)
  2607. (org-let2 gprops lprops
  2608. '(org-tags-view '(4) match)))
  2609. ((eq type 'todo)
  2610. (org-let2 gprops lprops
  2611. '(org-todo-list match)))
  2612. ((fboundp type)
  2613. (org-let2 gprops lprops
  2614. '(funcall type match)))
  2615. (t (error "Invalid type in command series")))))
  2616. (widen)
  2617. (let ((inhibit-read-only t))
  2618. (add-text-properties (point-min) (point-max)
  2619. `(org-serie t org-serie-redo-cmd ,redo)))
  2620. (setq org-agenda-redo-command redo)
  2621. (goto-char (point-min)))
  2622. (org-agenda-fit-window-to-buffer)
  2623. (org-let (nth 1 series) '(org-agenda-finalize)))
  2624. ;;;###autoload
  2625. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2626. "Run an agenda command in batch mode and send the result to STDOUT.
  2627. If CMD-KEY is a string of length 1, it is used as a key in
  2628. `org-agenda-custom-commands' and triggers this command. If it is a
  2629. longer string it is used as a tags/todo match string.
  2630. Parameters are alternating variable names and values that will be bound
  2631. before running the agenda command."
  2632. (org-eval-in-environment (org-make-parameter-alist parameters)
  2633. (if (> (length cmd-key) 2)
  2634. (org-tags-view nil cmd-key)
  2635. (org-agenda nil cmd-key)))
  2636. (set-buffer org-agenda-buffer-name)
  2637. (princ (buffer-string)))
  2638. (autoload 'org-batch-agenda "org-agenda" "\
  2639. Run an agenda command in batch mode and send the result to STDOUT.
  2640. If CMD-KEY is a string of length 1, it is used as a key in
  2641. `org-agenda-custom-commands' and triggers this command. If it is a
  2642. longer string it is used as a tags/todo match string.
  2643. Parameters are alternating variable names and values that will be bound
  2644. before running the agenda command.
  2645. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2646. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2647. (defvar org-agenda-info nil)
  2648. ;;;###autoload
  2649. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2650. "Run an agenda command in batch mode and send the result to STDOUT.
  2651. If CMD-KEY is a string of length 1, it is used as a key in
  2652. `org-agenda-custom-commands' and triggers this command. If it is a
  2653. longer string it is used as a tags/todo match string.
  2654. Parameters are alternating variable names and values that will be bound
  2655. before running the agenda command.
  2656. The output gives a line for each selected agenda item. Each
  2657. item is a list of comma-separated values, like this:
  2658. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2659. category The category of the item
  2660. head The headline, without TODO kwd, TAGS and PRIORITY
  2661. type The type of the agenda entry, can be
  2662. todo selected in TODO match
  2663. tagsmatch selected in tags match
  2664. diary imported from diary
  2665. deadline a deadline on given date
  2666. scheduled scheduled on given date
  2667. timestamp entry has timestamp on given date
  2668. closed entry was closed on given date
  2669. upcoming-deadline warning about deadline
  2670. past-scheduled forwarded scheduled item
  2671. block entry has date block including g. date
  2672. todo The todo keyword, if any
  2673. tags All tags including inherited ones, separated by colons
  2674. date The relevant date, like 2007-2-14
  2675. time The time, like 15:00-16:50
  2676. extra Sting with extra planning info
  2677. priority-l The priority letter if any was given
  2678. priority-n The computed numerical priority
  2679. agenda-day The day in the agenda where this is listed"
  2680. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2681. (org-make-parameter-alist parameters))
  2682. (if (> (length cmd-key) 2)
  2683. (org-tags-view nil cmd-key)
  2684. (org-agenda nil cmd-key)))
  2685. (set-buffer org-agenda-buffer-name)
  2686. (let* ((lines (org-split-string (buffer-string) "\n"))
  2687. line)
  2688. (while (setq line (pop lines))
  2689. (catch 'next
  2690. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2691. (setq org-agenda-info
  2692. (org-fix-agenda-info (text-properties-at 0 line)))
  2693. (princ
  2694. (mapconcat 'org-agenda-export-csv-mapper
  2695. '(org-category txt type todo tags date time extra
  2696. priority-letter priority agenda-day)
  2697. ","))
  2698. (princ "\n")))))
  2699. (autoload 'org-batch-agenda-csv "org-agenda" "\
  2700. Run an agenda command in batch mode and send the result to STDOUT.
  2701. If CMD-KEY is a string of length 1, it is used as a key in
  2702. `org-agenda-custom-commands' and triggers this command. If it is a
  2703. longer string it is used as a tags/todo match string.
  2704. Parameters are alternating variable names and values that will be bound
  2705. before running the agenda command.
  2706. The output gives a line for each selected agenda item. Each
  2707. item is a list of comma-separated values, like this:
  2708. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2709. category The category of the item
  2710. head The headline, without TODO kwd, TAGS and PRIORITY
  2711. type The type of the agenda entry, can be
  2712. todo selected in TODO match
  2713. tagsmatch selected in tags match
  2714. diary imported from diary
  2715. deadline a deadline on given date
  2716. scheduled scheduled on given date
  2717. timestamp entry has timestamp on given date
  2718. closed entry was closed on given date
  2719. upcoming-deadline warning about deadline
  2720. past-scheduled forwarded scheduled item
  2721. block entry has date block including g. date
  2722. todo The todo keyword, if any
  2723. tags All tags including inherited ones, separated by colons
  2724. date The relevant date, like 2007-2-14
  2725. time The time, like 15:00-16:50
  2726. extra Sting with extra planning info
  2727. priority-l The priority letter if any was given
  2728. priority-n The computed numerical priority
  2729. agenda-day The day in the agenda where this is listed
  2730. \(fn CMD-KEY &rest PARAMETERS)" nil t)
  2731. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2732. (defun org-fix-agenda-info (props)
  2733. "Make sure all properties on an agenda item have a canonical form.
  2734. This ensures the export commands can easily use it."
  2735. (let (tmp re)
  2736. (when (setq tmp (plist-get props 'tags))
  2737. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2738. (when (setq tmp (plist-get props 'date))
  2739. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2740. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2741. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2742. (setq tmp (calendar-date-string tmp)))
  2743. (setq props (plist-put props 'date tmp)))
  2744. (when (setq tmp (plist-get props 'day))
  2745. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2746. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2747. (setq tmp (calendar-date-string tmp)))
  2748. (setq props (plist-put props 'day tmp))
  2749. (setq props (plist-put props 'agenda-day tmp)))
  2750. (when (setq tmp (plist-get props 'txt))
  2751. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2752. (plist-put props 'priority-letter (match-string 1 tmp))
  2753. (setq tmp (replace-match "" t t tmp)))
  2754. (when (and (setq re (plist-get props 'org-todo-regexp))
  2755. (setq re (concat "\\`\\.*" re " ?"))
  2756. (string-match re tmp))
  2757. (plist-put props 'todo (match-string 1 tmp))
  2758. (setq tmp (replace-match "" t t tmp)))
  2759. (plist-put props 'txt tmp)))
  2760. props)
  2761. (defun org-agenda-export-csv-mapper (prop)
  2762. (let ((res (plist-get org-agenda-info prop)))
  2763. (setq res
  2764. (cond
  2765. ((not res) "")
  2766. ((stringp res) res)
  2767. (t (prin1-to-string res))))
  2768. (while (string-match "," res)
  2769. (setq res (replace-match ";" t t res)))
  2770. (org-trim res)))
  2771. ;;;###autoload
  2772. (defun org-store-agenda-views (&rest parameters)
  2773. (interactive)
  2774. (eval (list 'org-batch-store-agenda-views)))
  2775. (autoload 'org-store-agenda-views "org-agenda" "\
  2776. \(fn &rest PARAMETERS)" t nil)
  2777. ;;;###autoload
  2778. (defmacro org-batch-store-agenda-views (&rest parameters)
  2779. "Run all custom agenda commands that have a file argument."
  2780. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2781. (pop-up-frames nil)
  2782. (dir default-directory)
  2783. (pars (org-make-parameter-alist parameters))
  2784. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2785. (save-window-excursion
  2786. (while cmds
  2787. (setq cmd (pop cmds)
  2788. thiscmdkey (car cmd)
  2789. thiscmdcmd (cdr cmd)
  2790. match (nth 2 thiscmdcmd)
  2791. bufname (if org-agenda-sticky
  2792. (or (and (stringp match)
  2793. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2794. (format "*Org Agenda(%s)*" thiscmdkey))
  2795. org-agenda-buffer-name)
  2796. cmd-or-set (nth 2 cmd)
  2797. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2798. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2799. (if (stringp files) (setq files (list files)))
  2800. (when files
  2801. (org-eval-in-environment (append org-agenda-exporter-settings
  2802. opts pars)
  2803. (org-agenda nil thiscmdkey))
  2804. (set-buffer bufname)
  2805. (while files
  2806. (org-eval-in-environment (append org-agenda-exporter-settings
  2807. opts pars)
  2808. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2809. (and (get-buffer bufname)
  2810. (kill-buffer bufname)))))))
  2811. (autoload 'org-batch-store-agenda-views "org-agenda" "\
  2812. Run all custom agenda commands that have a file argument.
  2813. \(fn &rest PARAMETERS)" nil t)
  2814. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2815. (defvar org-agenda-current-span nil
  2816. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2817. (defun org-agenda-mark-header-line (pos)
  2818. "Mark the line at POS as an agenda structure header."
  2819. (save-excursion
  2820. (goto-char pos)
  2821. (put-text-property (point-at-bol) (point-at-eol)
  2822. 'org-agenda-structural-header t)
  2823. (when org-agenda-title-append
  2824. (put-text-property (point-at-bol) (point-at-eol)
  2825. 'org-agenda-title-append org-agenda-title-append))))
  2826. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2827. (defvar org-agenda-write-buffer-name "Agenda View")
  2828. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2829. "Write the current buffer (an agenda view) as a file.
  2830. Depending on the extension of the file name, plain text (.txt),
  2831. HTML (.html or .htm) or Postscript (.ps) is produced.
  2832. If the extension is .ics, run icalendar export over all files used
  2833. to construct the agenda and limit the export to entries listed in the
  2834. agenda now.
  2835. With prefix argument OPEN, open the new file immediately.
  2836. If NOSETTINGS is given, do not scope the settings of
  2837. `org-agenda-exporter-settings' into the export commands. This is used when
  2838. the settings have already been scoped and we do not wish to overrule other,
  2839. higher priority settings.
  2840. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2841. (interactive "FWrite agenda to file: \nP")
  2842. (if (not (file-writable-p file))
  2843. (error "Cannot write agenda to file %s" file))
  2844. (org-let (if nosettings nil org-agenda-exporter-settings)
  2845. '(save-excursion
  2846. (save-window-excursion
  2847. (org-agenda-mark-filtered-text)
  2848. (let ((bs (copy-sequence (buffer-string))) beg)
  2849. (org-agenda-unmark-filtered-text)
  2850. (with-temp-buffer
  2851. (rename-buffer org-agenda-write-buffer-name t)
  2852. (set-buffer-modified-p nil)
  2853. (insert bs)
  2854. (org-agenda-remove-marked-text 'org-filtered)
  2855. (while (setq beg (text-property-any (point-min) (point-max)
  2856. 'org-filtered t))
  2857. (delete-region
  2858. beg (or (next-single-property-change beg 'org-filtered)
  2859. (point-max))))
  2860. (run-hooks 'org-agenda-before-write-hook)
  2861. (cond
  2862. ((org-bound-and-true-p org-mobile-creating-agendas)
  2863. (org-mobile-write-agenda-for-mobile file))
  2864. ((string-match "\\.html?\\'" file)
  2865. (require 'htmlize)
  2866. (set-buffer (htmlize-buffer (current-buffer)))
  2867. (when org-agenda-export-html-style
  2868. ;; replace <style> section with org-agenda-export-html-style
  2869. (goto-char (point-min))
  2870. (kill-region (- (search-forward "<style") 6)
  2871. (search-forward "</style>"))
  2872. (insert org-agenda-export-html-style))
  2873. (write-file file)
  2874. (kill-buffer (current-buffer))
  2875. (message "HTML written to %s" file))
  2876. ((string-match "\\.ps\\'" file)
  2877. (require 'ps-print)
  2878. (ps-print-buffer-with-faces file)
  2879. (message "Postscript written to %s" file))
  2880. ((string-match "\\.pdf\\'" file)
  2881. (require 'ps-print)
  2882. (ps-print-buffer-with-faces
  2883. (concat (file-name-sans-extension file) ".ps"))
  2884. (call-process "ps2pdf" nil nil nil
  2885. (expand-file-name
  2886. (concat (file-name-sans-extension file) ".ps"))
  2887. (expand-file-name file))
  2888. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2889. (message "PDF written to %s" file))
  2890. ((string-match "\\.ics\\'" file)
  2891. (require 'org-icalendar)
  2892. (let ((org-agenda-marker-table
  2893. (org-create-marker-find-array
  2894. (org-agenda-collect-markers)))
  2895. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2896. (org-combined-agenda-icalendar-file file))
  2897. (apply 'org-export-icalendar 'combine
  2898. (org-agenda-files nil 'ifmode))))
  2899. (t
  2900. (let ((bs (buffer-string)))
  2901. (find-file file)
  2902. (erase-buffer)
  2903. (insert bs)
  2904. (save-buffer 0)
  2905. (kill-buffer (current-buffer))
  2906. (message "Plain text written to %s" file))))))))
  2907. (set-buffer (or agenda-bufname
  2908. (and (called-interactively-p 'any) (buffer-name))
  2909. org-agenda-buffer-name)))
  2910. (when open (org-open-file file)))
  2911. (defvar org-agenda-tag-filter-overlays nil)
  2912. (defvar org-agenda-cat-filter-overlays nil)
  2913. (defun org-agenda-mark-filtered-text ()
  2914. "Mark all text hidden by filtering with a text property."
  2915. (let ((inhibit-read-only t))
  2916. (mapc
  2917. (lambda (o)
  2918. (when (equal (overlay-buffer o) (current-buffer))
  2919. (put-text-property
  2920. (overlay-start o) (overlay-end o)
  2921. 'org-filtered t)))
  2922. (append org-agenda-tag-filter-overlays
  2923. org-agenda-cat-filter-overlays))))
  2924. (defun org-agenda-unmark-filtered-text ()
  2925. "Remove the filtering text property."
  2926. (let ((inhibit-read-only t))
  2927. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2928. (defun org-agenda-remove-marked-text (property &optional value)
  2929. "Delete all text marked with VALUE of PROPERTY.
  2930. VALUE defaults to t."
  2931. (let (beg)
  2932. (setq value (or value t))
  2933. (while (setq beg (text-property-any (point-min) (point-max)
  2934. property value))
  2935. (delete-region
  2936. beg (or (next-single-property-change beg 'org-filtered)
  2937. (point-max))))))
  2938. (defun org-agenda-add-entry-text ()
  2939. "Add entry text to agenda lines.
  2940. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2941. entry text following headings shown in the agenda.
  2942. Drawers will be excluded, also the line with scheduling/deadline info."
  2943. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2944. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2945. (let (m txt)
  2946. (goto-char (point-min))
  2947. (while (not (eobp))
  2948. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2949. (beginning-of-line 2)
  2950. (setq txt (org-agenda-get-some-entry-text
  2951. m org-agenda-add-entry-text-maxlines " > "))
  2952. (end-of-line 1)
  2953. (if (string-match "\\S-" txt)
  2954. (insert "\n" txt)
  2955. (or (eobp) (forward-char 1))))))))
  2956. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2957. &rest keep)
  2958. "Extract entry text from MARKER, at most N-LINES lines.
  2959. This will ignore drawers etc, just get the text.
  2960. If INDENT is given, prefix every line with this string. If KEEP is
  2961. given, it is a list of symbols, defining stuff that should not be
  2962. removed from the entry content. Currently only `planning' is allowed here."
  2963. (let (txt drawer-re kwd-time-re ind)
  2964. (save-excursion
  2965. (with-current-buffer (marker-buffer marker)
  2966. (if (not (derived-mode-p 'org-mode))
  2967. (setq txt "")
  2968. (save-excursion
  2969. (save-restriction
  2970. (widen)
  2971. (goto-char marker)
  2972. (end-of-line 1)
  2973. (setq txt (buffer-substring
  2974. (min (1+ (point)) (point-max))
  2975. (progn (outline-next-heading) (point)))
  2976. drawer-re org-drawer-regexp
  2977. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2978. ".*\n?"))
  2979. (with-temp-buffer
  2980. (insert txt)
  2981. (when org-agenda-add-entry-text-descriptive-links
  2982. (goto-char (point-min))
  2983. (while (org-activate-bracket-links (point-max))
  2984. (add-text-properties (match-beginning 0) (match-end 0)
  2985. '(face org-link))))
  2986. (goto-char (point-min))
  2987. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2988. (set-text-properties (match-beginning 0) (match-end 0)
  2989. nil))
  2990. (goto-char (point-min))
  2991. (while (re-search-forward drawer-re nil t)
  2992. (delete-region
  2993. (match-beginning 0)
  2994. (progn (re-search-forward
  2995. "^[ \t]*:END:.*\n?" nil 'move)
  2996. (point))))
  2997. (unless (member 'planning keep)
  2998. (goto-char (point-min))
  2999. (while (re-search-forward kwd-time-re nil t)
  3000. (replace-match "")))
  3001. (goto-char (point-min))
  3002. (when org-agenda-entry-text-exclude-regexps
  3003. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  3004. (while (setq re (pop re-list))
  3005. (goto-char (point-min))
  3006. (while (re-search-forward re nil t)
  3007. (replace-match "")))))
  3008. (goto-char (point-max))
  3009. (skip-chars-backward " \t\n")
  3010. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  3011. ;; find and remove min common indentation
  3012. (goto-char (point-min))
  3013. (untabify (point-min) (point-max))
  3014. (setq ind (org-get-indentation))
  3015. (while (not (eobp))
  3016. (unless (looking-at "[ \t]*$")
  3017. (setq ind (min ind (org-get-indentation))))
  3018. (beginning-of-line 2))
  3019. (goto-char (point-min))
  3020. (while (not (eobp))
  3021. (unless (looking-at "[ \t]*$")
  3022. (move-to-column ind)
  3023. (delete-region (point-at-bol) (point)))
  3024. (beginning-of-line 2))
  3025. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  3026. (goto-char (point-min))
  3027. (when indent
  3028. (while (and (not (eobp)) (re-search-forward "^" nil t))
  3029. (replace-match indent t t)))
  3030. (goto-char (point-min))
  3031. (while (looking-at "[ \t]*\n") (replace-match ""))
  3032. (goto-char (point-max))
  3033. (when (> (org-current-line)
  3034. n-lines)
  3035. (org-goto-line (1+ n-lines))
  3036. (backward-char 1))
  3037. (setq txt (buffer-substring (point-min) (point)))))))))
  3038. txt))
  3039. (defun org-agenda-collect-markers ()
  3040. "Collect the markers pointing to entries in the agenda buffer."
  3041. (let (m markers)
  3042. (save-excursion
  3043. (goto-char (point-min))
  3044. (while (not (eobp))
  3045. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  3046. (org-get-at-bol 'org-marker)))
  3047. (push m markers))
  3048. (beginning-of-line 2)))
  3049. (nreverse markers)))
  3050. (defun org-create-marker-find-array (marker-list)
  3051. "Create a alist of files names with all marker positions in that file."
  3052. (let (f tbl m a p)
  3053. (while (setq m (pop marker-list))
  3054. (setq p (marker-position m)
  3055. f (buffer-file-name (or (buffer-base-buffer
  3056. (marker-buffer m))
  3057. (marker-buffer m))))
  3058. (if (setq a (assoc f tbl))
  3059. (push (marker-position m) (cdr a))
  3060. (push (list f p) tbl)))
  3061. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  3062. tbl)))
  3063. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  3064. (defun org-check-agenda-marker-table ()
  3065. "Check of the current entry is on the marker list."
  3066. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  3067. a)
  3068. (and (setq a (assoc file org-agenda-marker-table))
  3069. (save-match-data
  3070. (save-excursion
  3071. (org-back-to-heading t)
  3072. (member (point) (cdr a)))))))
  3073. (defun org-check-for-org-mode ()
  3074. "Make sure current buffer is in org-mode. Error if not."
  3075. (or (derived-mode-p 'org-mode)
  3076. (error "Cannot execute org-mode agenda command on buffer in %s"
  3077. major-mode)))
  3078. ;;; Agenda prepare and finalize
  3079. (defvar org-agenda-multi nil) ; dynamically scoped
  3080. (defvar org-agenda-pre-window-conf nil)
  3081. (defvar org-agenda-columns-active nil)
  3082. (defvar org-agenda-name nil)
  3083. (defvar org-agenda-tag-filter nil)
  3084. (defvar org-agenda-category-filter nil)
  3085. (defvar org-agenda-top-category-filter nil)
  3086. (defvar org-agenda-tag-filter-while-redo nil)
  3087. (defvar org-agenda-tag-filter-preset nil
  3088. "A preset of the tags filter used for secondary agenda filtering.
  3089. This must be a list of strings, each string must be a single tag preceded
  3090. by \"+\" or \"-\".
  3091. This variable should not be set directly, but agenda custom commands can
  3092. bind it in the options section. The preset filter is a global property of
  3093. the entire agenda view. In a block agenda, it will not work reliably to
  3094. define a filter for one of the individual blocks. You need to set it in
  3095. the global options and expect it to be applied to the entire view.")
  3096. (defvar org-agenda-category-filter-preset nil
  3097. "A preset of the category filter used for secondary agenda filtering.
  3098. This must be a list of strings, each string must be a single category
  3099. preceded by \"+\" or \"-\".
  3100. This variable should not be set directly, but agenda custom commands can
  3101. bind it in the options section. The preset filter is a global property of
  3102. the entire agenda view. In a block agenda, it will not work reliably to
  3103. define a filter for one of the individual blocks. You need to set it in
  3104. the global options and expect it to be applied to the entire view.")
  3105. (defun org-agenda-use-sticky-p ()
  3106. "Return non-nil if an agenda buffer named
  3107. `org-agenda-buffer-name' exists and should be shown instead of
  3108. generating a new one."
  3109. (and
  3110. ;; turned off by user
  3111. org-agenda-sticky
  3112. ;; For multi-agenda buffer already exists
  3113. (not org-agenda-multi)
  3114. ;; buffer found
  3115. (get-buffer org-agenda-buffer-name)
  3116. ;; C-u parameter is same as last call
  3117. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3118. (and
  3119. (equal current-prefix-arg
  3120. org-agenda-last-prefix-arg)
  3121. ;; In case user turned stickiness on, while having existing
  3122. ;; Agenda buffer active, don't reuse that buffer, because it
  3123. ;; does not have org variables local
  3124. org-agenda-this-buffer-is-sticky))))
  3125. (defun org-agenda-prepare-window (abuf)
  3126. "Setup agenda buffer in the window."
  3127. (let* ((awin (get-buffer-window abuf))
  3128. wconf)
  3129. (cond
  3130. ((equal (current-buffer) abuf) nil)
  3131. (awin (select-window awin))
  3132. ((not (setq wconf (current-window-configuration))))
  3133. ((equal org-agenda-window-setup 'current-window)
  3134. (org-pop-to-buffer-same-window abuf))
  3135. ((equal org-agenda-window-setup 'other-window)
  3136. (org-switch-to-buffer-other-window abuf))
  3137. ((equal org-agenda-window-setup 'other-frame)
  3138. (switch-to-buffer-other-frame abuf))
  3139. ((equal org-agenda-window-setup 'reorganize-frame)
  3140. (delete-other-windows)
  3141. (org-switch-to-buffer-other-window abuf)))
  3142. ;; additional test in case agenda is invoked from within agenda
  3143. ;; buffer via elisp link
  3144. (unless (equal (current-buffer) abuf)
  3145. (org-pop-to-buffer-same-window abuf))
  3146. (setq org-agenda-pre-window-conf
  3147. (or org-agenda-pre-window-conf wconf))))
  3148. (defun org-agenda-prepare (&optional name)
  3149. (if (org-agenda-use-sticky-p)
  3150. (progn
  3151. ;; Popup existing buffer
  3152. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3153. (message "Sticky Agenda buffer, use `r' to refresh")
  3154. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3155. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3156. (setq org-todo-keywords-for-agenda nil)
  3157. (setq org-drawers-for-agenda nil)
  3158. (unless org-agenda-persistent-filter
  3159. (setq org-agenda-tag-filter nil
  3160. org-agenda-category-filter nil))
  3161. (put 'org-agenda-tag-filter :preset-filter
  3162. org-agenda-tag-filter-preset)
  3163. (put 'org-agenda-category-filter :preset-filter
  3164. org-agenda-category-filter-preset)
  3165. (if org-agenda-multi
  3166. (progn
  3167. (setq buffer-read-only nil)
  3168. (goto-char (point-max))
  3169. (unless (or (bobp) org-agenda-compact-blocks
  3170. (not org-agenda-block-separator))
  3171. (insert "\n"
  3172. (if (stringp org-agenda-block-separator)
  3173. org-agenda-block-separator
  3174. (make-string (window-width) org-agenda-block-separator))
  3175. "\n"))
  3176. (narrow-to-region (point) (point-max)))
  3177. (setq org-done-keywords-for-agenda nil)
  3178. ;; Setting any org variables that are in org-agenda-local-vars
  3179. ;; list need to be done after the prepare call
  3180. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3181. (setq buffer-read-only nil)
  3182. (org-agenda-reset-markers)
  3183. (let ((inhibit-read-only t)) (erase-buffer))
  3184. (org-agenda-mode)
  3185. (setq org-agenda-buffer (current-buffer))
  3186. (setq org-agenda-contributing-files nil)
  3187. (setq org-agenda-columns-active nil)
  3188. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3189. (setq org-todo-keywords-for-agenda
  3190. (org-uniquify org-todo-keywords-for-agenda))
  3191. (setq org-done-keywords-for-agenda
  3192. (org-uniquify org-done-keywords-for-agenda))
  3193. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3194. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3195. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3196. (and name (not org-agenda-name)
  3197. (org-set-local 'org-agenda-name name)))
  3198. (setq buffer-read-only nil)))
  3199. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3200. (defun org-agenda-finalize ()
  3201. "Finishing touch for the agenda buffer, called just before displaying it."
  3202. (unless org-agenda-multi
  3203. (save-excursion
  3204. (let ((inhibit-read-only t))
  3205. (goto-char (point-min))
  3206. (while (org-activate-bracket-links (point-max))
  3207. (add-text-properties (match-beginning 0) (match-end 0)
  3208. '(face org-link)))
  3209. (org-agenda-align-tags)
  3210. (unless org-agenda-with-colors
  3211. (remove-text-properties (point-min) (point-max) '(face nil))))
  3212. (if (and (boundp 'org-agenda-overriding-columns-format)
  3213. org-agenda-overriding-columns-format)
  3214. (org-set-local 'org-agenda-overriding-columns-format
  3215. org-agenda-overriding-columns-format))
  3216. (if (and (boundp 'org-agenda-view-columns-initially)
  3217. org-agenda-view-columns-initially)
  3218. (org-agenda-columns))
  3219. (when org-agenda-fontify-priorities
  3220. (org-agenda-fontify-priorities))
  3221. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3222. (org-agenda-dim-blocked-tasks))
  3223. (org-agenda-mark-clocking-task)
  3224. (when org-agenda-entry-text-mode
  3225. (org-agenda-entry-text-hide)
  3226. (org-agenda-entry-text-show))
  3227. (if (functionp 'org-habit-insert-consistency-graphs)
  3228. (org-habit-insert-consistency-graphs))
  3229. (let ((inhibit-read-only t))
  3230. (run-hooks 'org-agenda-finalize-hook))
  3231. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3232. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3233. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3234. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3235. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3236. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local))))
  3237. (defun org-agenda-mark-clocking-task ()
  3238. "Mark the current clock entry in the agenda if it is present."
  3239. (mapc (lambda (o)
  3240. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3241. (delete-overlay o)))
  3242. (overlays-in (point-min) (point-max)))
  3243. (when (marker-buffer org-clock-hd-marker)
  3244. (save-excursion
  3245. (goto-char (point-min))
  3246. (let (s ov)
  3247. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3248. (goto-char s)
  3249. (when (equal (org-get-at-bol 'org-hd-marker)
  3250. org-clock-hd-marker)
  3251. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3252. (overlay-put ov 'type 'org-agenda-clocking)
  3253. (overlay-put ov 'face 'org-agenda-clocking)
  3254. (overlay-put ov 'help-echo
  3255. "The clock is running in this item")))))))
  3256. (defun org-agenda-fontify-priorities ()
  3257. "Make highest priority lines bold, and lowest italic."
  3258. (interactive)
  3259. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3260. (delete-overlay o)))
  3261. (overlays-in (point-min) (point-max)))
  3262. (save-excursion
  3263. (let ((inhibit-read-only t)
  3264. b e p ov h l)
  3265. (goto-char (point-min))
  3266. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3267. (setq h (or (get-char-property (point) 'org-highest-priority)
  3268. org-highest-priority)
  3269. l (or (get-char-property (point) 'org-lowest-priority)
  3270. org-lowest-priority)
  3271. p (string-to-char (match-string 1))
  3272. b (match-beginning 0)
  3273. e (if (eq org-agenda-fontify-priorities 'cookies)
  3274. (match-end 0)
  3275. (point-at-eol))
  3276. ov (make-overlay b e))
  3277. (overlay-put
  3278. ov 'face
  3279. (cond ((org-face-from-face-or-color
  3280. 'priority nil
  3281. (cdr (assoc p org-priority-faces))))
  3282. ((and (listp org-agenda-fontify-priorities)
  3283. (org-face-from-face-or-color
  3284. 'priority nil
  3285. (cdr (assoc p org-agenda-fontify-priorities)))))
  3286. ((equal p l) 'italic)
  3287. ((equal p h) 'bold)))
  3288. (overlay-put ov 'org-type 'org-priority)))))
  3289. (defun org-agenda-dim-blocked-tasks ()
  3290. "Dim currently blocked TODO's in the agenda display."
  3291. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3292. (delete-overlay o)))
  3293. (overlays-in (point-min) (point-max)))
  3294. (save-excursion
  3295. (let ((inhibit-read-only t)
  3296. (org-depend-tag-blocked nil)
  3297. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3298. org-blocked-by-checkboxes
  3299. invis1 b e p ov h l)
  3300. (goto-char (point-min))
  3301. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3302. (and pos (goto-char (1+ pos))))
  3303. (setq org-blocked-by-checkboxes nil invis1 invis)
  3304. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3305. (when (and marker
  3306. (with-current-buffer (marker-buffer marker)
  3307. (save-excursion (goto-char marker)
  3308. (org-entry-blocked-p))))
  3309. (if org-blocked-by-checkboxes (setq invis1 nil))
  3310. (setq b (if invis1
  3311. (max (point-min) (1- (point-at-bol)))
  3312. (point-at-bol))
  3313. e (point-at-eol)
  3314. ov (make-overlay b e))
  3315. (if invis1
  3316. (overlay-put ov 'invisible t)
  3317. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3318. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3319. (defvar org-agenda-skip-function nil
  3320. "Function to be called at each match during agenda construction.
  3321. If this function returns nil, the current match should not be skipped.
  3322. Otherwise, the function must return a position from where the search
  3323. should be continued.
  3324. This may also be a Lisp form, it will be evaluated.
  3325. Never set this variable using `setq' or so, because then it will apply
  3326. to all future agenda commands. If you do want a global skipping condition,
  3327. use the option `org-agenda-skip-function-global' instead.
  3328. The correct usage for `org-agenda-skip-function' is to bind it with
  3329. `let' to scope it dynamically into the agenda-constructing command.
  3330. A good way to set it is through options in `org-agenda-custom-commands'.")
  3331. (defun org-agenda-skip ()
  3332. "Throw to `:skip' in places that should be skipped.
  3333. Also moves point to the end of the skipped region, so that search can
  3334. continue from there."
  3335. (let ((p (point-at-bol)) to)
  3336. (when (org-in-src-block-p) (throw :skip t))
  3337. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3338. (get-text-property p :org-archived)
  3339. (org-end-of-subtree t)
  3340. (throw :skip t))
  3341. (and org-agenda-skip-comment-trees
  3342. (get-text-property p :org-comment)
  3343. (org-end-of-subtree t)
  3344. (throw :skip t))
  3345. (if (equal (char-after p) ?#) (throw :skip t))
  3346. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3347. (org-agenda-skip-eval org-agenda-skip-function)))
  3348. (goto-char to)
  3349. (throw :skip t))))
  3350. (defun org-agenda-skip-eval (form)
  3351. "If FORM is a function or a list, call (or eval) is and return result.
  3352. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3353. and match data are returned to the previous state no matter what these
  3354. functions do."
  3355. (let (fp)
  3356. (and form
  3357. (or (setq fp (functionp form))
  3358. (consp form))
  3359. (save-excursion
  3360. (save-match-data
  3361. (if fp
  3362. (funcall form)
  3363. (eval form)))))))
  3364. (defvar org-agenda-markers nil
  3365. "List of all currently active markers created by `org-agenda'.")
  3366. (defvar org-agenda-last-marker-time (org-float-time)
  3367. "Creation time of the last agenda marker.")
  3368. (defun org-agenda-new-marker (&optional pos)
  3369. "Return a new agenda marker.
  3370. Org-mode keeps a list of these markers and resets them when they are
  3371. no longer in use."
  3372. (let ((m (copy-marker (or pos (point)))))
  3373. (setq org-agenda-last-marker-time (org-float-time))
  3374. (if org-agenda-buffer
  3375. (with-current-buffer org-agenda-buffer
  3376. (push m org-agenda-markers))
  3377. (push m org-agenda-markers))
  3378. m))
  3379. (defun org-agenda-reset-markers ()
  3380. "Reset markers created by `org-agenda'."
  3381. (while org-agenda-markers
  3382. (move-marker (pop org-agenda-markers) nil)))
  3383. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3384. "Save relative positions of markers in region.
  3385. This check for agenda markers in all agenda buffers currently active."
  3386. (dolist (buf (buffer-list))
  3387. (with-current-buffer buf
  3388. (when (eq major-mode 'org-agenda-mode)
  3389. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3390. org-agenda-markers)))))
  3391. ;;; Entry text mode
  3392. (defun org-agenda-entry-text-show-here ()
  3393. "Add some text from the entry as context to the current line."
  3394. (let (m txt o)
  3395. (setq m (org-get-at-bol 'org-hd-marker))
  3396. (unless (marker-buffer m)
  3397. (error "No marker points to an entry here"))
  3398. (setq txt (concat "\n" (org-no-properties
  3399. (org-agenda-get-some-entry-text
  3400. m org-agenda-entry-text-maxlines " > "))))
  3401. (when (string-match "\\S-" txt)
  3402. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3403. (overlay-put o 'evaporate t)
  3404. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3405. (overlay-put o 'after-string txt))))
  3406. (defun org-agenda-entry-text-show ()
  3407. "Add entry context for all agenda lines."
  3408. (interactive)
  3409. (save-excursion
  3410. (goto-char (point-max))
  3411. (beginning-of-line 1)
  3412. (while (not (bobp))
  3413. (when (org-get-at-bol 'org-hd-marker)
  3414. (org-agenda-entry-text-show-here))
  3415. (beginning-of-line 0))))
  3416. (defun org-agenda-entry-text-hide ()
  3417. "Remove any shown entry context."
  3418. (delq nil
  3419. (mapcar (lambda (o)
  3420. (if (eq (overlay-get o 'org-overlay-type)
  3421. 'agenda-entry-content)
  3422. (progn (delete-overlay o) t)))
  3423. (overlays-in (point-min) (point-max)))))
  3424. (defun org-agenda-get-day-face (date)
  3425. "Return the face DATE should be displayed with."
  3426. (or (and (functionp org-agenda-day-face-function)
  3427. (funcall org-agenda-day-face-function date))
  3428. (cond ((org-agenda-todayp date)
  3429. 'org-agenda-date-today)
  3430. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3431. 'org-agenda-date-weekend)
  3432. (t 'org-agenda-date))))
  3433. ;;; Agenda timeline
  3434. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3435. (defun org-timeline (&optional dotodo)
  3436. "Show a time-sorted view of the entries in the current org file.
  3437. Only entries with a time stamp of today or later will be listed. With
  3438. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3439. under the current date.
  3440. If the buffer contains an active region, only check the region for
  3441. dates."
  3442. (interactive "P")
  3443. (let* ((dopast t)
  3444. (org-agenda-show-log-scoped org-agenda-show-log)
  3445. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3446. (current-buffer))))
  3447. (date (calendar-current-date))
  3448. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3449. (end (if (org-region-active-p) (region-end) (point-max)))
  3450. (day-numbers (org-get-all-dates
  3451. beg end 'no-ranges
  3452. t org-agenda-show-log-scoped ; always include today
  3453. org-timeline-show-empty-dates))
  3454. (org-deadline-warning-days 0)
  3455. (org-agenda-only-exact-dates t)
  3456. (today (org-today))
  3457. (past t)
  3458. args
  3459. s e rtn d emptyp)
  3460. (setq org-agenda-redo-command
  3461. (list 'progn
  3462. (list 'org-switch-to-buffer-other-window (current-buffer))
  3463. (list 'org-timeline (list 'quote dotodo))))
  3464. (if (not dopast)
  3465. ;; Remove past dates from the list of dates.
  3466. (setq day-numbers (delq nil (mapcar (lambda(x)
  3467. (if (>= x today) x nil))
  3468. day-numbers))))
  3469. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3470. (org-compile-prefix-format 'timeline)
  3471. (org-set-sorting-strategy 'timeline)
  3472. (if org-agenda-show-log-scoped (push :closed args))
  3473. (push :timestamp args)
  3474. (push :deadline args)
  3475. (push :scheduled args)
  3476. (push :sexp args)
  3477. (if dotodo (push :todo args))
  3478. (insert "Timeline of file " entry "\n")
  3479. (add-text-properties (point-min) (point)
  3480. (list 'face 'org-agenda-structure))
  3481. (org-agenda-mark-header-line (point-min))
  3482. (while (setq d (pop day-numbers))
  3483. (if (and (listp d) (eq (car d) :omitted))
  3484. (progn
  3485. (setq s (point))
  3486. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3487. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3488. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3489. (if (and (>= d today)
  3490. dopast
  3491. past)
  3492. (progn
  3493. (setq past nil)
  3494. (insert (make-string 79 ?-) "\n")))
  3495. (setq date (calendar-gregorian-from-absolute d))
  3496. (setq s (point))
  3497. (setq rtn (and (not emptyp)
  3498. (apply 'org-agenda-get-day-entries entry
  3499. date args)))
  3500. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3501. (progn
  3502. (insert
  3503. (if (stringp org-agenda-format-date)
  3504. (format-time-string org-agenda-format-date
  3505. (org-time-from-absolute date))
  3506. (funcall org-agenda-format-date date))
  3507. "\n")
  3508. (put-text-property s (1- (point)) 'face
  3509. (org-agenda-get-day-face date))
  3510. (put-text-property s (1- (point)) 'org-date-line t)
  3511. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3512. (if (equal d today)
  3513. (put-text-property s (1- (point)) 'org-today t))
  3514. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3515. (put-text-property s (1- (point)) 'day d)))))
  3516. (goto-char (point-min))
  3517. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3518. (point-min)))
  3519. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3520. (org-agenda-finalize)
  3521. (setq buffer-read-only t)))
  3522. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3523. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3524. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3525. not every single day in the range. If FORCE-TODAY is non-nil, make
  3526. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3527. inactive time stamps (those in square brackets) are included.
  3528. When EMPTY is non-nil, also include days without any entries."
  3529. (let ((re (concat
  3530. (if pre-re pre-re "")
  3531. (if inactive org-ts-regexp-both org-ts-regexp)))
  3532. dates dates1 date day day1 day2 ts1 ts2 pos)
  3533. (if force-today
  3534. (setq dates (list (org-today))))
  3535. (save-excursion
  3536. (goto-char beg)
  3537. (while (re-search-forward re end t)
  3538. (setq day (time-to-days (org-time-string-to-time
  3539. (substring (match-string 1) 0 10)
  3540. (current-buffer) (match-beginning 0))))
  3541. (or (memq day dates) (push day dates)))
  3542. (unless no-ranges
  3543. (goto-char beg)
  3544. (while (re-search-forward org-tr-regexp end t)
  3545. (setq pos (match-beginning 0))
  3546. (setq ts1 (substring (match-string 1) 0 10)
  3547. ts2 (substring (match-string 2) 0 10)
  3548. day1 (time-to-days (org-time-string-to-time
  3549. ts1 (current-buffer) pos))
  3550. day2 (time-to-days (org-time-string-to-time
  3551. ts2 (current-buffer) pos)))
  3552. (while (< (setq day1 (1+ day1)) day2)
  3553. (or (memq day1 dates) (push day1 dates)))))
  3554. (setq dates (sort dates '<))
  3555. (when empty
  3556. (while (setq day (pop dates))
  3557. (setq day2 (car dates))
  3558. (push day dates1)
  3559. (when (and day2 empty)
  3560. (if (or (eq empty t)
  3561. (and (numberp empty) (<= (- day2 day) empty)))
  3562. (while (< (setq day (1+ day)) day2)
  3563. (push (list day) dates1))
  3564. (push (cons :omitted (- day2 day)) dates1))))
  3565. (setq dates (nreverse dates1)))
  3566. dates)))
  3567. ;;; Agenda Daily/Weekly
  3568. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3569. "Start day for the agenda view.
  3570. Custom commands can set this variable in the options section.")
  3571. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3572. (defvar org-arg-loc nil) ; local variable
  3573. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3574. "List of types searched for when creating the daily/weekly agenda.
  3575. This variable is a list of symbols that controls the types of
  3576. items that appear in the daily/weekly agenda. Allowed symbols in this
  3577. list are are
  3578. :timestamp List items containing a date stamp or date range matching
  3579. the selected date. This includes sexp entries in
  3580. angular brackets.
  3581. :sexp List entries resulting from plain diary-like sexps.
  3582. :deadline List deadline due on that date. When the date is today,
  3583. also list any deadlines past due, or due within
  3584. `org-deadline-warning-days'. `:deadline' must appear before
  3585. `:scheduled' if the setting of
  3586. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3587. any effect.
  3588. :scheduled List all items which are scheduled for the given date.
  3589. The diary for *today* also contains items which were
  3590. scheduled earlier and are not yet marked DONE.
  3591. By default, all four types are turned on.
  3592. Never set this variable globally using `setq', because then it
  3593. will apply to all future agenda commands. Instead, bind it with
  3594. `let' to scope it dynamically into the agenda-constructing
  3595. command. A good way to set it is through options in
  3596. `org-agenda-custom-commands'. For a more flexible (though
  3597. somewhat less efficient) way of determining what is included in
  3598. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3599. (defvar org-agenda-buffer-tmp-name nil)
  3600. ;;;###autoload
  3601. (defun org-agenda-list (&optional arg start-day span)
  3602. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3603. The view will be for the current day or week, but from the overview buffer
  3604. you will be able to go to other days/weeks.
  3605. With a numeric prefix argument in an interactive call, the agenda will
  3606. span ARG days. Lisp programs should instead specify SPAN to change
  3607. the number of days. SPAN defaults to `org-agenda-span'.
  3608. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3609. given in `org-agenda-start-on-weekday'."
  3610. (interactive "P")
  3611. (if org-agenda-overriding-arguments
  3612. (setq arg (car org-agenda-overriding-arguments)
  3613. start-day (nth 1 org-agenda-overriding-arguments)
  3614. span (nth 2 org-agenda-overriding-arguments)))
  3615. (if (and (integerp arg) (> arg 0))
  3616. (setq span arg arg nil))
  3617. (catch 'exit
  3618. (setq org-agenda-buffer-name
  3619. (or org-agenda-buffer-tmp-name
  3620. (if org-agenda-sticky
  3621. (cond ((and org-keys (stringp org-match))
  3622. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3623. (org-keys
  3624. (format "*Org Agenda(%s)*" org-keys))
  3625. (t "*Org Agenda(a)*")))
  3626. org-agenda-buffer-name))
  3627. (org-agenda-prepare "Day/Week")
  3628. (setq start-day (or start-day org-agenda-start-day))
  3629. (if (stringp start-day)
  3630. ;; Convert to an absolute day number
  3631. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3632. (org-compile-prefix-format 'agenda)
  3633. (org-set-sorting-strategy 'agenda)
  3634. (let* ((span (org-agenda-ndays-to-span
  3635. (or span org-agenda-ndays org-agenda-span)))
  3636. (today (org-today))
  3637. (sd (or start-day today))
  3638. (ndays (org-agenda-span-to-ndays span sd))
  3639. (org-agenda-start-on-weekday
  3640. (if (eq ndays 7)
  3641. org-agenda-start-on-weekday))
  3642. (thefiles (org-agenda-files nil 'ifmode))
  3643. (files thefiles)
  3644. (start (if (or (null org-agenda-start-on-weekday)
  3645. (< ndays 7))
  3646. sd
  3647. (let* ((nt (calendar-day-of-week
  3648. (calendar-gregorian-from-absolute sd)))
  3649. (n1 org-agenda-start-on-weekday)
  3650. (d (- nt n1)))
  3651. (- sd (+ (if (< d 0) 7 0) d)))))
  3652. (day-numbers (list start))
  3653. (day-cnt 0)
  3654. (inhibit-redisplay (not debug-on-error))
  3655. (org-agenda-show-log-scoped org-agenda-show-log)
  3656. s e rtn rtnall file date d start-pos end-pos todayp
  3657. clocktable-start clocktable-end filter)
  3658. (setq org-agenda-redo-command
  3659. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3660. (dotimes (n (1- ndays))
  3661. (push (1+ (car day-numbers)) day-numbers))
  3662. (setq day-numbers (nreverse day-numbers))
  3663. (setq clocktable-start (car day-numbers)
  3664. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3665. (org-set-local 'org-starting-day (car day-numbers))
  3666. (org-set-local 'org-arg-loc arg)
  3667. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3668. (unless org-agenda-compact-blocks
  3669. (let* ((d1 (car day-numbers))
  3670. (d2 (org-last day-numbers))
  3671. (w1 (org-days-to-iso-week d1))
  3672. (w2 (org-days-to-iso-week d2)))
  3673. (setq s (point))
  3674. (if org-agenda-overriding-header
  3675. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3676. nil 'face 'org-agenda-structure) "\n")
  3677. (insert (org-agenda-span-name span)
  3678. "-agenda"
  3679. (if (< (- d2 d1) 350)
  3680. (if (= w1 w2)
  3681. (format " (W%02d)" w1)
  3682. (format " (W%02d-W%02d)" w1 w2))
  3683. "")
  3684. ":\n")))
  3685. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3686. 'org-date-line t))
  3687. (org-agenda-mark-header-line s))
  3688. (while (setq d (pop day-numbers))
  3689. (setq date (calendar-gregorian-from-absolute d)
  3690. s (point))
  3691. (if (or (setq todayp (= d today))
  3692. (and (not start-pos) (= d sd)))
  3693. (setq start-pos (point))
  3694. (if (and start-pos (not end-pos))
  3695. (setq end-pos (point))))
  3696. (setq files thefiles
  3697. rtnall nil)
  3698. (while (setq file (pop files))
  3699. (catch 'nextfile
  3700. (org-check-agenda-file file)
  3701. (let ((org-agenda-entry-types org-agenda-entry-types))
  3702. (unless org-agenda-include-deadlines
  3703. (setq org-agenda-entry-types
  3704. (delq :deadline org-agenda-entry-types)))
  3705. (cond
  3706. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3707. (setq rtn (org-agenda-get-day-entries
  3708. file date :closed)))
  3709. (org-agenda-show-log-scoped
  3710. (setq rtn (apply 'org-agenda-get-day-entries
  3711. file date
  3712. (append '(:closed) org-agenda-entry-types))))
  3713. (t
  3714. (setq rtn (apply 'org-agenda-get-day-entries
  3715. file date
  3716. org-agenda-entry-types)))))
  3717. (setq rtnall (append rtnall rtn)))) ;; all entries
  3718. (if org-agenda-include-diary
  3719. (let ((org-agenda-search-headline-for-time t))
  3720. (require 'diary-lib)
  3721. (setq rtn (org-get-entries-from-diary date))
  3722. (setq rtnall (append rtnall rtn))))
  3723. (if (or rtnall org-agenda-show-all-dates)
  3724. (progn
  3725. (setq day-cnt (1+ day-cnt))
  3726. (insert
  3727. (if (stringp org-agenda-format-date)
  3728. (format-time-string org-agenda-format-date
  3729. (org-time-from-absolute date))
  3730. (funcall org-agenda-format-date date))
  3731. "\n")
  3732. (put-text-property s (1- (point)) 'face
  3733. (org-agenda-get-day-face date))
  3734. (put-text-property s (1- (point)) 'org-date-line t)
  3735. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3736. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3737. (when todayp
  3738. (put-text-property s (1- (point)) 'org-today t))
  3739. (setq rtnall
  3740. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3741. (if rtnall (insert ;; all entries
  3742. (org-agenda-finalize-entries rtnall)
  3743. "\n"))
  3744. (put-text-property s (1- (point)) 'day d)
  3745. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3746. (when (and org-agenda-clockreport-mode clocktable-start)
  3747. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3748. ;; the above line is to ensure the restricted range!
  3749. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3750. tbl)
  3751. (setq p (org-plist-delete p :block))
  3752. (setq p (plist-put p :tstart clocktable-start))
  3753. (setq p (plist-put p :tend clocktable-end))
  3754. (setq p (plist-put p :scope 'agenda))
  3755. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3756. (setq filter (or org-agenda-tag-filter-while-redo
  3757. (get 'org-agenda-tag-filter :preset-filter))))
  3758. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3759. (if (string-match "[<>=]" x)
  3760. ""
  3761. x))
  3762. filter ""))))
  3763. (setq tbl (apply 'org-clock-get-clocktable p))
  3764. (insert tbl)))
  3765. (goto-char (point-min))
  3766. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3767. (unless (and (pos-visible-in-window-p (point-min))
  3768. (pos-visible-in-window-p (point-max)))
  3769. (goto-char (1- (point-max)))
  3770. (recenter -1)
  3771. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3772. (progn
  3773. (goto-char (or start-pos 1))
  3774. (recenter 1))))
  3775. (goto-char (or start-pos 1))
  3776. (add-text-properties (point-min) (point-max)
  3777. `(org-agenda-type agenda
  3778. org-last-args (,arg ,start-day ,span)
  3779. org-redo-cmd ,org-agenda-redo-command
  3780. org-serie-cmd ,org-cmd))
  3781. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3782. (org-agenda-show-clocking-issues))
  3783. (org-agenda-finalize)
  3784. (setq buffer-read-only t)
  3785. (message ""))))
  3786. (autoload 'org-agenda-list "org-agenda" "\
  3787. Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3788. The view will be for the current day or week, but from the overview buffer
  3789. you will be able to go to other days/weeks.
  3790. With a numeric prefix argument in an interactive call, the agenda will
  3791. span ARG days. Lisp programs should instead specify SPAN to change
  3792. the number of days. SPAN defaults to `org-agenda-span'.
  3793. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3794. given in `org-agenda-start-on-weekday'.
  3795. \(fn &optional ARG START-DAY SPAN)" t nil)
  3796. (defun org-agenda-ndays-to-span (n)
  3797. "Return a span symbol for a span of N days, or N if none matches."
  3798. (cond ((symbolp n) n)
  3799. ((= n 1) 'day)
  3800. ((= n 7) 'week)
  3801. (t n)))
  3802. (defun org-agenda-span-to-ndays (span &optional start-day)
  3803. "Return ndays from SPAN, possibly starting at START-DAY."
  3804. (cond ((numberp span) span)
  3805. ((eq span 'day) 1)
  3806. ((eq span 'week) 7)
  3807. ((eq span 'month)
  3808. (let ((date (calendar-gregorian-from-absolute start-day)))
  3809. (calendar-last-day-of-month (car date) (caddr date))))
  3810. ((eq span 'year)
  3811. (let ((date (calendar-gregorian-from-absolute start-day)))
  3812. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3813. (defun org-agenda-span-name (span)
  3814. "Return a SPAN name."
  3815. (if (null span)
  3816. ""
  3817. (if (symbolp span)
  3818. (capitalize (symbol-name span))
  3819. (format "%d days" span))))
  3820. ;;; Agenda word search
  3821. (defvar org-agenda-search-history nil)
  3822. (defvar org-search-syntax-table nil
  3823. "Special syntax table for org-mode search.
  3824. In this table, we have single quotes not as word constituents, to
  3825. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3826. (defvar org-mode-syntax-table) ; From org.el
  3827. (defun org-search-syntax-table ()
  3828. (unless org-search-syntax-table
  3829. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3830. (modify-syntax-entry ?' "." org-search-syntax-table)
  3831. (modify-syntax-entry ?` "." org-search-syntax-table))
  3832. org-search-syntax-table)
  3833. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3834. ;;;###autoload
  3835. (defun org-search-view (&optional todo-only string edit-at)
  3836. "Show all entries that contain a phrase or words or regular expressions.
  3837. With optional prefix argument TODO-ONLY, only consider entries that are
  3838. TODO entries. The argument STRING can be used to pass a default search
  3839. string into this function. If EDIT-AT is non-nil, it means that the
  3840. user should get a chance to edit this string, with cursor at position
  3841. EDIT-AT.
  3842. The search string can be viewed either as a phrase that should be found as
  3843. is, or it can be broken into a number of snippets, each of which must match
  3844. in a Boolean way to select an entry. The default depends on the variable
  3845. `org-agenda-search-view-always-boolean'.
  3846. Even if this is turned off (the default) you can always switch to
  3847. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3848. The default is a direct search of the whole phrase, where each space in
  3849. the search string can expand to an arbitrary amount of whitespace,
  3850. including newlines.
  3851. If using a Boolean search, the search string is split on whitespace and
  3852. each snippet is searched separately, with logical AND to select an entry.
  3853. Words prefixed with a minus must *not* occur in the entry. Words without
  3854. a prefix or prefixed with a plus must occur in the entry. Matching is
  3855. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3856. match whole words, not parts of a word) if
  3857. `org-agenda-search-view-force-full-words' is set (default is nil).
  3858. Boolean search snippets enclosed by curly braces are interpreted as
  3859. regular expressions that must or (when preceded with \"-\") must not
  3860. match in the entry. Snippets enclosed into double quotes will be taken
  3861. as a whole, to include whitespace.
  3862. - If the search string starts with an asterisk, search only in headlines.
  3863. - If (possibly after the leading star) the search string starts with an
  3864. exclamation mark, this also means to look at TODO entries only, an effect
  3865. that can also be achieved with a prefix argument.
  3866. - If (possibly after star and exclamation mark) the search string starts
  3867. with a colon, this will mean that the (non-regexp) snippets of the
  3868. Boolean search must match as full words.
  3869. This command searches the agenda files, and in addition the files listed
  3870. in `org-agenda-text-search-extra-files'."
  3871. (interactive "P")
  3872. (if org-agenda-overriding-arguments
  3873. (setq todo-only (car org-agenda-overriding-arguments)
  3874. string (nth 1 org-agenda-overriding-arguments)
  3875. edit-at (nth 2 org-agenda-overriding-arguments)))
  3876. (let* ((props (list 'face nil
  3877. 'done-face 'org-agenda-done
  3878. 'org-not-done-regexp org-not-done-regexp
  3879. 'org-todo-regexp org-todo-regexp
  3880. 'org-complex-heading-regexp org-complex-heading-regexp
  3881. 'mouse-face 'highlight
  3882. 'help-echo (format "mouse-2 or RET jump to location")))
  3883. (full-words org-agenda-search-view-force-full-words)
  3884. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3885. regexp rtn rtnall files file pos
  3886. marker category category-pos level tags c neg re boolean
  3887. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3888. (unless (and (not edit-at)
  3889. (stringp string)
  3890. (string-match "\\S-" string))
  3891. (setq string (read-string
  3892. (if org-agenda-search-view-always-boolean
  3893. "[+-]Word/{Regexp} ...: "
  3894. "Phrase or [+-]Word/{Regexp} ...: ")
  3895. (cond
  3896. ((integerp edit-at) (cons string edit-at))
  3897. (edit-at string))
  3898. 'org-agenda-search-history)))
  3899. (catch 'exit
  3900. (if org-agenda-sticky
  3901. (setq org-agenda-buffer-name
  3902. (if (stringp string)
  3903. (format "*Org Agenda(%s:%s)*"
  3904. (or org-keys (or (and todo-only "S") "s")) string)
  3905. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3906. (org-agenda-prepare "SEARCH")
  3907. (org-compile-prefix-format 'search)
  3908. (org-set-sorting-strategy 'search)
  3909. (setq org-agenda-redo-command
  3910. (list 'org-search-view (if todo-only t nil)
  3911. (list 'if 'current-prefix-arg nil string)))
  3912. (setq org-agenda-query-string string)
  3913. (if (equal (string-to-char string) ?*)
  3914. (setq hdl-only t
  3915. words (substring string 1))
  3916. (setq words string))
  3917. (when (equal (string-to-char words) ?!)
  3918. (setq todo-only t
  3919. words (substring words 1)))
  3920. (when (equal (string-to-char words) ?:)
  3921. (setq full-words t
  3922. words (substring words 1)))
  3923. (if (or org-agenda-search-view-always-boolean
  3924. (member (string-to-char words) '(?- ?+ ?\{)))
  3925. (setq boolean t))
  3926. (setq words (org-split-string words))
  3927. (let (www w)
  3928. (while (setq w (pop words))
  3929. (while (and (string-match "\\\\\\'" w) words)
  3930. (setq w (concat (substring w 0 -1) " " (pop words))))
  3931. (push w www))
  3932. (setq words (nreverse www) www nil)
  3933. (while (setq w (pop words))
  3934. (when (and (string-match "\\`[-+]?{" w)
  3935. (not (string-match "}\\'" w)))
  3936. (while (and words (not (string-match "}\\'" (car words))))
  3937. (setq w (concat w " " (pop words))))
  3938. (setq w (concat w " " (pop words))))
  3939. (push w www))
  3940. (setq words (nreverse www)))
  3941. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3942. (when boolean
  3943. (let (wds w)
  3944. (while (setq w (pop words))
  3945. (if (or (equal (substring w 0 1) "\"")
  3946. (and (> (length w) 1)
  3947. (member (substring w 0 1) '("+" "-"))
  3948. (equal (substring w 1 2) "\"")))
  3949. (while (and words (not (equal (substring w -1) "\"")))
  3950. (setq w (concat w " " (pop words)))))
  3951. (and (string-match "\\`\\([-+]?\\)\"" w)
  3952. (setq w (replace-match "\\1" nil nil w)))
  3953. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3954. (push w wds))
  3955. (setq words (nreverse wds))))
  3956. (if boolean
  3957. (mapc (lambda (w)
  3958. (setq c (string-to-char w))
  3959. (if (equal c ?-)
  3960. (setq neg t w (substring w 1))
  3961. (if (equal c ?+)
  3962. (setq neg nil w (substring w 1))
  3963. (setq neg nil)))
  3964. (if (string-match "\\`{.*}\\'" w)
  3965. (setq re (substring w 1 -1))
  3966. (if full-words
  3967. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3968. (setq re (regexp-quote (downcase w)))))
  3969. (if neg (push re regexps-) (push re regexps+)))
  3970. words)
  3971. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3972. regexps+))
  3973. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3974. (if (not regexps+)
  3975. (setq regexp org-outline-regexp-bol)
  3976. (setq regexp (pop regexps+))
  3977. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3978. regexp))))
  3979. (setq files (org-agenda-files nil 'ifmode))
  3980. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3981. (pop org-agenda-text-search-extra-files)
  3982. (setq files (org-add-archive-files files)))
  3983. (setq files (append files org-agenda-text-search-extra-files)
  3984. rtnall nil)
  3985. (while (setq file (pop files))
  3986. (setq ee nil)
  3987. (catch 'nextfile
  3988. (org-check-agenda-file file)
  3989. (setq buffer (if (file-exists-p file)
  3990. (org-get-agenda-file-buffer file)
  3991. (error "No such file %s" file)))
  3992. (if (not buffer)
  3993. ;; If file does not exist, make sure an error message is sent
  3994. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3995. file))))
  3996. (with-current-buffer buffer
  3997. (with-syntax-table (org-search-syntax-table)
  3998. (unless (derived-mode-p 'org-mode)
  3999. (error "Agenda file %s is not in `org-mode'" file))
  4000. (let ((case-fold-search t))
  4001. (save-excursion
  4002. (save-restriction
  4003. (if org-agenda-restrict
  4004. (narrow-to-region org-agenda-restrict-begin
  4005. org-agenda-restrict-end)
  4006. (widen))
  4007. (goto-char (point-min))
  4008. (unless (or (org-at-heading-p)
  4009. (outline-next-heading))
  4010. (throw 'nextfile t))
  4011. (goto-char (max (point-min) (1- (point))))
  4012. (while (re-search-forward regexp nil t)
  4013. (org-back-to-heading t)
  4014. (skip-chars-forward "* ")
  4015. (setq beg (point-at-bol)
  4016. beg1 (point)
  4017. end (progn (outline-next-heading) (point)))
  4018. (catch :skip
  4019. (goto-char beg)
  4020. (org-agenda-skip)
  4021. (setq str (buffer-substring-no-properties
  4022. (point-at-bol)
  4023. (if hdl-only (point-at-eol) end)))
  4024. (mapc (lambda (wr) (when (string-match wr str)
  4025. (goto-char (1- end))
  4026. (throw :skip t)))
  4027. regexps-)
  4028. (mapc (lambda (wr) (unless (string-match wr str)
  4029. (goto-char (1- end))
  4030. (throw :skip t)))
  4031. (if todo-only
  4032. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  4033. regexps+)
  4034. regexps+))
  4035. (goto-char beg)
  4036. (setq marker (org-agenda-new-marker (point))
  4037. category (org-get-category)
  4038. level (make-string (org-reduced-level (org-outline-level)) ? )
  4039. category-pos (get-text-property (point) 'org-category-position)
  4040. tags (org-get-tags-at (point))
  4041. txt (org-agenda-format-item
  4042. ""
  4043. (buffer-substring-no-properties
  4044. beg1 (point-at-eol))
  4045. level category tags t))
  4046. (org-add-props txt props
  4047. 'org-marker marker 'org-hd-marker marker
  4048. 'org-todo-regexp org-todo-regexp
  4049. 'level level
  4050. 'org-complex-heading-regexp org-complex-heading-regexp
  4051. 'priority 1000 'org-category category
  4052. 'org-category-position category-pos
  4053. 'type "search")
  4054. (push txt ee)
  4055. (goto-char (1- end))))))))))
  4056. (setq rtn (nreverse ee))
  4057. (setq rtnall (append rtnall rtn)))
  4058. (if org-agenda-overriding-header
  4059. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4060. nil 'face 'org-agenda-structure) "\n")
  4061. (insert "Search words: ")
  4062. (add-text-properties (point-min) (1- (point))
  4063. (list 'face 'org-agenda-structure))
  4064. (setq pos (point))
  4065. (insert string "\n")
  4066. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4067. (setq pos (point))
  4068. (unless org-agenda-multi
  4069. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  4070. (add-text-properties pos (1- (point))
  4071. (list 'face 'org-agenda-structure))))
  4072. (org-agenda-mark-header-line (point-min))
  4073. (when rtnall
  4074. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4075. (goto-char (point-min))
  4076. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4077. (add-text-properties (point-min) (point-max)
  4078. `(org-agenda-type search
  4079. org-last-args (,todo-only ,string ,edit-at)
  4080. org-redo-cmd ,org-agenda-redo-command
  4081. org-serie-cmd ,org-cmd))
  4082. (org-agenda-finalize)
  4083. (setq buffer-read-only t))))
  4084. (autoload 'org-search-view "org-agenda" "\
  4085. Show all entries that contain a phrase or words or regular expressions.
  4086. With optional prefix argument TODO-ONLY, only consider entries that are
  4087. TODO entries. The argument STRING can be used to pass a default search
  4088. string into this function. If EDIT-AT is non-nil, it means that the
  4089. user should get a chance to edit this string, with cursor at position
  4090. EDIT-AT.
  4091. The search string can be viewed either as a phrase that should be found as
  4092. is, or it can be broken into a number of snippets, each of which must match
  4093. in a Boolean way to select an entry. The default depends on the variable
  4094. `org-agenda-search-view-always-boolean'.
  4095. Even if this is turned off (the default) you can always switch to
  4096. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  4097. The default is a direct search of the whole phrase, where each space in
  4098. the search string can expand to an arbitrary amount of whitespace,
  4099. including newlines.
  4100. If using a Boolean search, the search string is split on whitespace and
  4101. each snippet is searched separately, with logical AND to select an entry.
  4102. Words prefixed with a minus must *not* occur in the entry. Words without
  4103. a prefix or prefixed with a plus must occur in the entry. Matching is
  4104. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  4105. match whole words, not parts of a word) if
  4106. `org-agenda-search-view-force-full-words' is set (default is nil).
  4107. Boolean search snippets enclosed by curly braces are interpreted as
  4108. regular expressions that must or (when preceded with \"-\") must not
  4109. match in the entry. Snippets enclosed into double quotes will be taken
  4110. as a whole, to include whitespace.
  4111. - If the search string starts with an asterisk, search only in headlines.
  4112. - If (possibly after the leading star) the search string starts with an
  4113. exclamation mark, this also means to look at TODO entries only, an effect
  4114. that can also be achieved with a prefix argument.
  4115. - If (possibly after star and exclamation mark) the search string starts
  4116. with a colon, this will mean that the (non-regexp) snippets of the
  4117. Boolean search must match as full words.
  4118. This command searches the agenda files, and in addition the files listed
  4119. in `org-agenda-text-search-extra-files'.
  4120. \(fn &optional TODO-ONLY STRING EDIT-AT)" t nil)
  4121. ;;; Agenda TODO list
  4122. (defvar org-select-this-todo-keyword nil)
  4123. (defvar org-last-arg nil)
  4124. ;;;###autoload
  4125. (defun org-todo-list (&optional arg)
  4126. "Show all (not done) TODO entries from all agenda file in a single list.
  4127. The prefix arg can be used to select a specific TODO keyword and limit
  4128. the list to these. When using \\[universal-argument], you will be prompted
  4129. for a keyword. A numeric prefix directly selects the Nth keyword in
  4130. `org-todo-keywords-1'."
  4131. (interactive "P")
  4132. (if org-agenda-overriding-arguments
  4133. (setq arg org-agenda-overriding-arguments))
  4134. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  4135. (let* ((today (org-today))
  4136. (date (calendar-gregorian-from-absolute today))
  4137. (kwds org-todo-keywords-for-agenda)
  4138. (completion-ignore-case t)
  4139. (org-select-this-todo-keyword
  4140. (if (stringp arg) arg
  4141. (and arg (integerp arg) (> arg 0)
  4142. (nth (1- arg) kwds))))
  4143. rtn rtnall files file pos)
  4144. (when (equal arg '(4))
  4145. (setq org-select-this-todo-keyword
  4146. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4147. (mapcar 'list kwds) nil nil)))
  4148. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4149. (catch 'exit
  4150. (if org-agenda-sticky
  4151. (setq org-agenda-buffer-name
  4152. (if (stringp org-select-this-todo-keyword)
  4153. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4154. org-select-this-todo-keyword)
  4155. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4156. (org-agenda-prepare "TODO")
  4157. (org-compile-prefix-format 'todo)
  4158. (org-set-sorting-strategy 'todo)
  4159. (setq org-agenda-redo-command
  4160. `(org-todo-list (or (and (numberp current-prefix-arg)
  4161. current-prefix-arg)
  4162. ,org-select-this-todo-keyword
  4163. current-prefix-arg ,arg)))
  4164. (setq files (org-agenda-files nil 'ifmode)
  4165. rtnall nil)
  4166. (while (setq file (pop files))
  4167. (catch 'nextfile
  4168. (org-check-agenda-file file)
  4169. (setq rtn (org-agenda-get-day-entries file date :todo))
  4170. (setq rtnall (append rtnall rtn))))
  4171. (if org-agenda-overriding-header
  4172. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4173. nil 'face 'org-agenda-structure) "\n")
  4174. (insert "Global list of TODO items of type: ")
  4175. (add-text-properties (point-min) (1- (point))
  4176. (list 'face 'org-agenda-structure
  4177. 'short-heading
  4178. (concat "ToDo: "
  4179. (or org-select-this-todo-keyword "ALL"))))
  4180. (org-agenda-mark-header-line (point-min))
  4181. (setq pos (point))
  4182. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4183. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4184. (setq pos (point))
  4185. (unless org-agenda-multi
  4186. (insert "Available with `N r': (0)[ALL]")
  4187. (let ((n 0) s)
  4188. (mapc (lambda (x)
  4189. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4190. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4191. (insert "\n "))
  4192. (insert " " s))
  4193. kwds))
  4194. (insert "\n"))
  4195. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4196. (org-agenda-mark-header-line (point-min))
  4197. (when rtnall
  4198. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4199. (goto-char (point-min))
  4200. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4201. (add-text-properties (point-min) (point-max)
  4202. `(org-agenda-type todo
  4203. org-last-args ,arg
  4204. org-redo-cmd ,org-agenda-redo-command
  4205. org-serie-cmd ,org-cmd))
  4206. (org-agenda-finalize)
  4207. (setq buffer-read-only t))))
  4208. (autoload 'org-todo-list "org-agenda" "\
  4209. Show all (not done) TODO entries from all agenda file in a single list.
  4210. The prefix arg can be used to select a specific TODO keyword and limit
  4211. the list to these. When using \\[universal-argument], you will be prompted
  4212. for a keyword. A numeric prefix directly selects the Nth keyword in
  4213. `org-todo-keywords-1'.
  4214. \(fn &optional ARG)" t nil)
  4215. ;;; Agenda tags match
  4216. ;;;###autoload
  4217. (defun org-tags-view (&optional todo-only match)
  4218. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4219. The prefix arg TODO-ONLY limits the search to TODO entries."
  4220. (interactive "P")
  4221. (if org-agenda-overriding-arguments
  4222. (setq todo-only (car org-agenda-overriding-arguments)
  4223. match (nth 1 org-agenda-overriding-arguments)))
  4224. (let* ((org-tags-match-list-sublevels
  4225. org-tags-match-list-sublevels)
  4226. (completion-ignore-case t)
  4227. rtn rtnall files file pos matcher
  4228. buffer)
  4229. (when (and (stringp match) (not (string-match "\\S-" match)))
  4230. (setq match nil))
  4231. (setq matcher (org-make-tags-matcher match)
  4232. match (car matcher) matcher (cdr matcher))
  4233. (catch 'exit
  4234. (if org-agenda-sticky
  4235. (setq org-agenda-buffer-name
  4236. (if (stringp match)
  4237. (format "*Org Agenda(%s:%s)*"
  4238. (or org-keys (or (and todo-only "M") "m")) match)
  4239. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4240. (org-agenda-prepare (concat "TAGS " match))
  4241. (org-compile-prefix-format 'tags)
  4242. (org-set-sorting-strategy 'tags)
  4243. (setq org-agenda-query-string match)
  4244. (setq org-agenda-redo-command
  4245. (list 'org-tags-view `(quote ,todo-only)
  4246. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4247. (setq files (org-agenda-files nil 'ifmode)
  4248. rtnall nil)
  4249. (while (setq file (pop files))
  4250. (catch 'nextfile
  4251. (org-check-agenda-file file)
  4252. (setq buffer (if (file-exists-p file)
  4253. (org-get-agenda-file-buffer file)
  4254. (error "No such file %s" file)))
  4255. (if (not buffer)
  4256. ;; If file does not exist, error message to agenda
  4257. (setq rtn (list
  4258. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4259. rtnall (append rtnall rtn))
  4260. (with-current-buffer buffer
  4261. (unless (derived-mode-p 'org-mode)
  4262. (error "Agenda file %s is not in `org-mode'" file))
  4263. (save-excursion
  4264. (save-restriction
  4265. (if org-agenda-restrict
  4266. (narrow-to-region org-agenda-restrict-begin
  4267. org-agenda-restrict-end)
  4268. (widen))
  4269. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4270. (setq rtnall (append rtnall rtn))))))))
  4271. (if org-agenda-overriding-header
  4272. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4273. nil 'face 'org-agenda-structure) "\n")
  4274. (insert "Headlines with TAGS match: ")
  4275. (add-text-properties (point-min) (1- (point))
  4276. (list 'face 'org-agenda-structure
  4277. 'short-heading
  4278. (concat "Match: " match)))
  4279. (setq pos (point))
  4280. (insert match "\n")
  4281. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4282. (setq pos (point))
  4283. (unless org-agenda-multi
  4284. (insert "Press `C-u r' to search again with new search string\n"))
  4285. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4286. (org-agenda-mark-header-line (point-min))
  4287. (when rtnall
  4288. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4289. (goto-char (point-min))
  4290. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4291. (add-text-properties (point-min) (point-max)
  4292. `(org-agenda-type tags
  4293. org-last-args (,todo-only ,match)
  4294. org-redo-cmd ,org-agenda-redo-command
  4295. org-serie-cmd ,org-cmd))
  4296. (org-agenda-finalize)
  4297. (setq buffer-read-only t))))
  4298. (autoload 'org-tags-view "org-agenda" "\
  4299. Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4300. The prefix arg TODO-ONLY limits the search to TODO entries.
  4301. \(fn &optional TODO-ONLY MATCH)" t nil)
  4302. ;;; Agenda Finding stuck projects
  4303. (defvar org-agenda-skip-regexp nil
  4304. "Regular expression used in skipping subtrees for the agenda.
  4305. This is basically a temporary global variable that can be set and then
  4306. used by user-defined selections using `org-agenda-skip-function'.")
  4307. (defvar org-agenda-overriding-header nil
  4308. "When set during agenda, todo and tags searches it replaces the header.
  4309. This variable should not be set directly, but custom commands can bind it
  4310. in the options section.")
  4311. (defun org-agenda-skip-entry-when-regexp-matches ()
  4312. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4313. If yes, it returns the end position of this entry, causing agenda commands
  4314. to skip the entry but continuing the search in the subtree. This is a
  4315. function that can be put into `org-agenda-skip-function' for the duration
  4316. of a command."
  4317. (let ((end (save-excursion (org-end-of-subtree t)))
  4318. skip)
  4319. (save-excursion
  4320. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4321. (and skip end)))
  4322. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4323. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4324. If yes, it returns the end position of this tree, causing agenda commands
  4325. to skip this subtree. This is a function that can be put into
  4326. `org-agenda-skip-function' for the duration of a command."
  4327. (let ((end (save-excursion (org-end-of-subtree t)))
  4328. skip)
  4329. (save-excursion
  4330. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4331. (and skip end)))
  4332. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4333. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4334. If yes, it returns the end position of the current entry (NOT the tree),
  4335. causing agenda commands to skip the entry but continuing the search in
  4336. the subtree. This is a function that can be put into
  4337. `org-agenda-skip-function' for the duration of a command. An important
  4338. use of this function is for the stuck project list."
  4339. (let ((end (save-excursion (org-end-of-subtree t)))
  4340. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4341. skip)
  4342. (save-excursion
  4343. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4344. (and skip entry-end)))
  4345. (defun org-agenda-skip-entry-if (&rest conditions)
  4346. "Skip entry if any of CONDITIONS is true.
  4347. See `org-agenda-skip-if' for details."
  4348. (org-agenda-skip-if nil conditions))
  4349. (defun org-agenda-skip-subtree-if (&rest conditions)
  4350. "Skip entry if any of CONDITIONS is true.
  4351. See `org-agenda-skip-if' for details."
  4352. (org-agenda-skip-if t conditions))
  4353. (defun org-agenda-skip-if (subtree conditions)
  4354. "Checks current entity for CONDITIONS.
  4355. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4356. the entry (i.e. the text before the next heading) is checked.
  4357. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4358. from different tests. Valid conditions are:
  4359. scheduled Check if there is a scheduled cookie
  4360. notscheduled Check if there is no scheduled cookie
  4361. deadline Check if there is a deadline
  4362. notdeadline Check if there is no deadline
  4363. timestamp Check if there is a timestamp (also deadline or scheduled)
  4364. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4365. regexp Check if regexp matches
  4366. notregexp Check if regexp does not match.
  4367. todo Check if TODO keyword matches
  4368. nottodo Check if TODO keyword does not match
  4369. The regexp is taken from the conditions list, it must come right after
  4370. the `regexp' or `notregexp' element.
  4371. `todo' and `nottodo' accept as an argument a list of todo
  4372. keywords, which may include \"*\" to match any todo keyword.
  4373. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4374. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4375. Instead of a list, a keyword class may be given. For example:
  4376. (org-agenda-skip-entry-if 'nottodo 'done)
  4377. would skip entries that haven't been marked with any of \"DONE\"
  4378. keywords. Possible classes are: `todo', `done', `any'.
  4379. If any of these conditions is met, this function returns the end point of
  4380. the entity, causing the search to continue from there. This is a function
  4381. that can be put into `org-agenda-skip-function' for the duration of a command."
  4382. (let (beg end m)
  4383. (org-back-to-heading t)
  4384. (setq beg (point)
  4385. end (if subtree
  4386. (progn (org-end-of-subtree t) (point))
  4387. (progn (outline-next-heading) (1- (point)))))
  4388. (goto-char beg)
  4389. (and
  4390. (or
  4391. (and (memq 'scheduled conditions)
  4392. (re-search-forward org-scheduled-time-regexp end t))
  4393. (and (memq 'notscheduled conditions)
  4394. (not (re-search-forward org-scheduled-time-regexp end t)))
  4395. (and (memq 'deadline conditions)
  4396. (re-search-forward org-deadline-time-regexp end t))
  4397. (and (memq 'notdeadline conditions)
  4398. (not (re-search-forward org-deadline-time-regexp end t)))
  4399. (and (memq 'timestamp conditions)
  4400. (re-search-forward org-ts-regexp end t))
  4401. (and (memq 'nottimestamp conditions)
  4402. (not (re-search-forward org-ts-regexp end t)))
  4403. (and (setq m (memq 'regexp conditions))
  4404. (stringp (nth 1 m))
  4405. (re-search-forward (nth 1 m) end t))
  4406. (and (setq m (memq 'notregexp conditions))
  4407. (stringp (nth 1 m))
  4408. (not (re-search-forward (nth 1 m) end t)))
  4409. (and (or
  4410. (setq m (memq 'nottodo conditions))
  4411. (setq m (memq 'todo-unblocked conditions))
  4412. (setq m (memq 'nottodo-unblocked conditions))
  4413. (setq m (memq 'todo conditions)))
  4414. (org-agenda-skip-if-todo m end)))
  4415. end)))
  4416. (defun org-agenda-skip-if-todo (args end)
  4417. "Helper function for `org-agenda-skip-if', do not use it directly.
  4418. ARGS is a list with first element either `todo', `nottodo',
  4419. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4420. a list of TODO keywords, or a state symbol `todo' or `done' or
  4421. `any'."
  4422. (let ((kw (car args))
  4423. (arg (cadr args))
  4424. todo-wds todo-re)
  4425. (setq todo-wds
  4426. (org-uniquify
  4427. (cond
  4428. ((listp arg) ;; list of keywords
  4429. (if (member "*" arg)
  4430. (mapcar 'substring-no-properties org-todo-keywords-1)
  4431. arg))
  4432. ((symbolp arg) ;; keyword class name
  4433. (cond
  4434. ((eq arg 'todo)
  4435. (org-delete-all org-done-keywords
  4436. (mapcar 'substring-no-properties
  4437. org-todo-keywords-1)))
  4438. ((eq arg 'done) org-done-keywords)
  4439. ((eq arg 'any)
  4440. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4441. (setq todo-re
  4442. (concat "^\\*+[ \t]+\\<\\("
  4443. (mapconcat 'identity todo-wds "\\|")
  4444. "\\)\\>"))
  4445. (cond
  4446. ((eq kw 'todo) (re-search-forward todo-re end t))
  4447. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4448. ((eq kw 'todo-unblocked)
  4449. (catch 'unblocked
  4450. (while (re-search-forward todo-re end t)
  4451. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4452. nil))
  4453. ((eq kw 'nottodo-unblocked)
  4454. (catch 'unblocked
  4455. (while (re-search-forward todo-re end t)
  4456. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4457. t))
  4458. )))
  4459. ;;;###autoload
  4460. (defun org-agenda-list-stuck-projects (&rest ignore)
  4461. "Create agenda view for projects that are stuck.
  4462. Stuck projects are project that have no next actions. For the definitions
  4463. of what a project is and how to check if it stuck, customize the variable
  4464. `org-stuck-projects'."
  4465. (interactive)
  4466. (let* ((org-agenda-skip-function
  4467. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4468. ;; We could have used org-agenda-skip-if here.
  4469. (org-agenda-overriding-header
  4470. (or org-agenda-overriding-header "List of stuck projects: "))
  4471. (matcher (nth 0 org-stuck-projects))
  4472. (todo (nth 1 org-stuck-projects))
  4473. (todo-wds (if (member "*" todo)
  4474. (progn
  4475. (org-agenda-prepare-buffers (org-agenda-files
  4476. nil 'ifmode))
  4477. (org-delete-all
  4478. org-done-keywords-for-agenda
  4479. (copy-sequence org-todo-keywords-for-agenda)))
  4480. todo))
  4481. (todo-re (concat "^\\*+[ \t]+\\("
  4482. (mapconcat 'identity todo-wds "\\|")
  4483. "\\)\\>"))
  4484. (tags (nth 2 org-stuck-projects))
  4485. (tags-re (if (member "*" tags)
  4486. (concat org-outline-regexp-bol
  4487. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4488. (if tags
  4489. (concat org-outline-regexp-bol
  4490. ".*:\\("
  4491. (mapconcat 'identity tags "\\|")
  4492. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4493. (gen-re (nth 3 org-stuck-projects))
  4494. (re-list
  4495. (delq nil
  4496. (list
  4497. (if todo todo-re)
  4498. (if tags tags-re)
  4499. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4500. gen-re)))))
  4501. (setq org-agenda-skip-regexp
  4502. (if re-list
  4503. (mapconcat 'identity re-list "\\|")
  4504. (error "No information how to identify unstuck projects")))
  4505. (org-tags-view nil matcher)
  4506. (with-current-buffer org-agenda-buffer-name
  4507. (setq org-agenda-redo-command
  4508. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4509. (autoload 'org-agenda-list-stuck-projects "org-agenda" "\
  4510. Create agenda view for projects that are stuck.
  4511. Stuck projects are project that have no next actions. For the definitions
  4512. of what a project is and how to check if it stuck, customize the variable
  4513. `org-stuck-projects'.
  4514. \(fn &rest IGNORE)" t nil)
  4515. ;;; Diary integration
  4516. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4517. (defvar diary-list-entries-hook)
  4518. (defvar diary-time-regexp)
  4519. (defun org-get-entries-from-diary (date)
  4520. "Get the (Emacs Calendar) diary entries for DATE."
  4521. (require 'diary-lib)
  4522. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4523. (diary-display-hook '(fancy-diary-display))
  4524. (diary-display-function 'fancy-diary-display)
  4525. (pop-up-frames nil)
  4526. (diary-list-entries-hook
  4527. (cons 'org-diary-default-entry diary-list-entries-hook))
  4528. (diary-file-name-prefix-function nil) ; turn this feature off
  4529. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4530. entries
  4531. (org-disable-agenda-to-diary t))
  4532. (save-excursion
  4533. (save-window-excursion
  4534. (funcall (if (fboundp 'diary-list-entries)
  4535. 'diary-list-entries 'list-diary-entries)
  4536. date 1)))
  4537. (if (not (get-buffer diary-fancy-buffer))
  4538. (setq entries nil)
  4539. (with-current-buffer diary-fancy-buffer
  4540. (setq buffer-read-only nil)
  4541. (if (zerop (buffer-size))
  4542. ;; No entries
  4543. (setq entries nil)
  4544. ;; Omit the date and other unnecessary stuff
  4545. (org-agenda-cleanup-fancy-diary)
  4546. ;; Add prefix to each line and extend the text properties
  4547. (if (zerop (buffer-size))
  4548. (setq entries nil)
  4549. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4550. (setq entries
  4551. (with-temp-buffer
  4552. (insert entries) (goto-char (point-min))
  4553. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4554. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4555. (replace-match (concat "; " (match-string 1)))))
  4556. (buffer-string)))))
  4557. (set-buffer-modified-p nil)
  4558. (kill-buffer diary-fancy-buffer)))
  4559. (when entries
  4560. (setq entries (org-split-string entries "\n"))
  4561. (setq entries
  4562. (mapcar
  4563. (lambda (x)
  4564. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4565. ;; Extend the text properties to the beginning of the line
  4566. (org-add-props x (text-properties-at (1- (length x)) x)
  4567. 'type "diary" 'date date 'face 'org-agenda-diary))
  4568. entries)))))
  4569. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4570. "Hook run when the fancy diary buffer is cleaned up.")
  4571. (defun org-agenda-cleanup-fancy-diary ()
  4572. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4573. This gets rid of the date, the underline under the date, and
  4574. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4575. date. It also removes lines that contain only whitespace."
  4576. (goto-char (point-min))
  4577. (if (looking-at ".*?:[ \t]*")
  4578. (progn
  4579. (replace-match "")
  4580. (re-search-forward "\n=+$" nil t)
  4581. (replace-match "")
  4582. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4583. (re-search-forward "\n=+$" nil t)
  4584. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4585. (goto-char (point-min))
  4586. (while (re-search-forward "^ +\n" nil t)
  4587. (replace-match ""))
  4588. (goto-char (point-min))
  4589. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4590. (replace-match ""))
  4591. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4592. ;; Make sure entries from the diary have the right text properties.
  4593. (eval-after-load "diary-lib"
  4594. '(if (boundp 'diary-modify-entry-list-string-function)
  4595. ;; We can rely on the hook, nothing to do
  4596. nil
  4597. ;; Hook not available, must use advice to make this work
  4598. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4599. "Make the position visible."
  4600. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4601. (stringp string)
  4602. buffer-file-name)
  4603. (setq string (org-modify-diary-entry-string string))))))
  4604. (defun org-modify-diary-entry-string (string)
  4605. "Add text properties to string, allowing org-mode to act on it."
  4606. (org-add-props string nil
  4607. 'mouse-face 'highlight
  4608. 'help-echo (if buffer-file-name
  4609. (format "mouse-2 or RET jump to diary file %s"
  4610. (abbreviate-file-name buffer-file-name))
  4611. "")
  4612. 'org-agenda-diary-link t
  4613. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4614. (defun org-diary-default-entry ()
  4615. "Add a dummy entry to the diary.
  4616. Needed to avoid empty dates which mess up holiday display."
  4617. ;; Catch the error if dealing with the new add-to-diary-alist
  4618. (when org-disable-agenda-to-diary
  4619. (condition-case nil
  4620. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4621. (error
  4622. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4623. (defun org-add-to-diary-list (&rest args)
  4624. (if (fboundp 'diary-add-to-list)
  4625. (apply 'diary-add-to-list args)
  4626. (apply 'add-to-diary-list args)))
  4627. (defvar org-diary-last-run-time nil)
  4628. ;;;###autoload
  4629. (defun org-diary (&rest args)
  4630. "Return diary information from org files.
  4631. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4632. It accesses org files and extracts information from those files to be
  4633. listed in the diary. The function accepts arguments specifying what
  4634. items should be listed. For a list of arguments allowed here, see the
  4635. variable `org-agenda-entry-types'.
  4636. The call in the diary file should look like this:
  4637. &%%(org-diary) ~/path/to/some/orgfile.org
  4638. Use a separate line for each org file to check. Or, if you omit the file name,
  4639. all files listed in `org-agenda-files' will be checked automatically:
  4640. &%%(org-diary)
  4641. If you don't give any arguments (as in the example above), the default
  4642. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4643. So the example above may also be written as
  4644. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4645. The function expects the lisp variables `entry' and `date' to be provided
  4646. by the caller, because this is how the calendar works. Don't use this
  4647. function from a program - use `org-agenda-get-day-entries' instead."
  4648. (when (> (- (org-float-time)
  4649. org-agenda-last-marker-time)
  4650. 5)
  4651. ;; I am not sure if this works with sticky agendas, because the marker
  4652. ;; list is then no longer a global variable.
  4653. (org-agenda-reset-markers))
  4654. (org-compile-prefix-format 'agenda)
  4655. (org-set-sorting-strategy 'agenda)
  4656. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4657. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4658. (list entry)
  4659. (org-agenda-files t)))
  4660. (time (org-float-time))
  4661. file rtn results)
  4662. (when (or (not org-diary-last-run-time)
  4663. (> (- time
  4664. org-diary-last-run-time)
  4665. 3))
  4666. (org-agenda-prepare-buffers files))
  4667. (setq org-diary-last-run-time time)
  4668. ;; If this is called during org-agenda, don't return any entries to
  4669. ;; the calendar. Org Agenda will list these entries itself.
  4670. (if org-disable-agenda-to-diary (setq files nil))
  4671. (while (setq file (pop files))
  4672. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4673. (setq results (append results rtn)))
  4674. (if results
  4675. (concat (org-agenda-finalize-entries results) "\n"))))
  4676. (autoload 'org-diary "org-agenda" "\
  4677. Return diary information from org files.
  4678. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4679. It accesses org files and extracts information from those files to be
  4680. listed in the diary. The function accepts arguments specifying what
  4681. items should be listed. For a list of arguments allowed here, see the
  4682. variable `org-agenda-entry-types'.
  4683. The call in the diary file should look like this:
  4684. &%%(org-diary) ~/path/to/some/orgfile.org
  4685. Use a separate line for each org file to check. Or, if you omit the file name,
  4686. all files listed in `org-agenda-files' will be checked automatically:
  4687. &%%(org-diary)
  4688. If you don't give any arguments (as in the example above), the default
  4689. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4690. So the example above may also be written as
  4691. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4692. The function expects the lisp variables `entry' and `date' to be provided
  4693. by the caller, because this is how the calendar works. Don't use this
  4694. function from a program - use `org-agenda-get-day-entries' instead.
  4695. \(fn &rest ARGS)" nil nil)
  4696. ;;; Agenda entry finders
  4697. (defun org-agenda-get-day-entries (file date &rest args)
  4698. "Does the work for `org-diary' and `org-agenda'.
  4699. FILE is the path to a file to be checked for entries. DATE is date like
  4700. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4701. which kind of entries should be extracted. For details about these, see
  4702. the documentation of `org-diary'."
  4703. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4704. (let* ((org-startup-folded nil)
  4705. (org-startup-align-all-tables nil)
  4706. (buffer (if (file-exists-p file)
  4707. (org-get-agenda-file-buffer file)
  4708. (error "No such file %s" file)))
  4709. arg results rtn deadline-results)
  4710. (if (not buffer)
  4711. ;; If file does not exist, make sure an error message ends up in diary
  4712. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4713. (with-current-buffer buffer
  4714. (unless (derived-mode-p 'org-mode)
  4715. (error "Agenda file %s is not in `org-mode'" file))
  4716. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4717. (let ((case-fold-search nil))
  4718. (save-excursion
  4719. (save-restriction
  4720. (if org-agenda-restrict
  4721. (narrow-to-region org-agenda-restrict-begin
  4722. org-agenda-restrict-end)
  4723. (widen))
  4724. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4725. (while (setq arg (pop args))
  4726. (cond
  4727. ((and (eq arg :todo)
  4728. (equal date (calendar-gregorian-from-absolute
  4729. (org-today))))
  4730. (setq rtn (org-agenda-get-todos))
  4731. (setq results (append results rtn)))
  4732. ((eq arg :timestamp)
  4733. (setq rtn (org-agenda-get-blocks))
  4734. (setq results (append results rtn))
  4735. (setq rtn (org-agenda-get-timestamps deadline-results))
  4736. (setq results (append results rtn)))
  4737. ((eq arg :sexp)
  4738. (setq rtn (org-agenda-get-sexps))
  4739. (setq results (append results rtn)))
  4740. ((eq arg :scheduled)
  4741. (setq rtn (org-agenda-get-scheduled deadline-results))
  4742. (setq results (append results rtn)))
  4743. ((eq arg :closed)
  4744. (setq rtn (org-agenda-get-progress))
  4745. (setq results (append results rtn)))
  4746. ((eq arg :deadline)
  4747. (setq rtn (org-agenda-get-deadlines))
  4748. (setq deadline-results (copy-sequence rtn))
  4749. (setq results (append results rtn))))))))
  4750. results))))
  4751. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4752. (defun org-agenda-get-todos ()
  4753. "Return the TODO information for agenda display."
  4754. (let* ((props (list 'face nil
  4755. 'done-face 'org-agenda-done
  4756. 'org-not-done-regexp org-not-done-regexp
  4757. 'org-todo-regexp org-todo-regexp
  4758. 'org-complex-heading-regexp org-complex-heading-regexp
  4759. 'mouse-face 'highlight
  4760. 'help-echo
  4761. (format "mouse-2 or RET jump to org file %s"
  4762. (abbreviate-file-name buffer-file-name))))
  4763. (regexp (format org-heading-keyword-regexp-format
  4764. (cond
  4765. ((and org-select-this-todo-keyword
  4766. (equal org-select-this-todo-keyword "*"))
  4767. org-todo-regexp)
  4768. (org-select-this-todo-keyword
  4769. (concat "\\("
  4770. (mapconcat 'identity
  4771. (org-split-string
  4772. org-select-this-todo-keyword
  4773. "|")
  4774. "\\|") "\\)"))
  4775. (t org-not-done-regexp))))
  4776. marker priority category category-pos level tags todo-state
  4777. ee txt beg end)
  4778. (goto-char (point-min))
  4779. (while (re-search-forward regexp nil t)
  4780. (catch :skip
  4781. (save-match-data
  4782. (beginning-of-line)
  4783. (org-agenda-skip)
  4784. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4785. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4786. (goto-char (1+ beg))
  4787. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4788. (throw :skip nil)))
  4789. (goto-char (match-beginning 2))
  4790. (setq marker (org-agenda-new-marker (match-beginning 0))
  4791. category (org-get-category)
  4792. category-pos (get-text-property (point) 'org-category-position)
  4793. txt (org-trim
  4794. (buffer-substring (match-beginning 2) (match-end 0)))
  4795. tags (org-get-tags-at (point))
  4796. level (make-string (org-reduced-level (org-outline-level)) ? )
  4797. txt (org-agenda-format-item "" txt level category tags t)
  4798. priority (1+ (org-get-priority txt))
  4799. todo-state (org-get-todo-state))
  4800. (org-add-props txt props
  4801. 'org-marker marker 'org-hd-marker marker
  4802. 'priority priority 'org-category category
  4803. 'level level
  4804. 'org-category-position category-pos
  4805. 'type "todo" 'todo-state todo-state)
  4806. (push txt ee)
  4807. (if org-agenda-todo-list-sublevels
  4808. (goto-char (match-end 2))
  4809. (org-end-of-subtree 'invisible))))
  4810. (nreverse ee)))
  4811. (defun org-agenda-todo-custom-ignore-p (time n)
  4812. "Check whether timestamp is farther away than n number of days.
  4813. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4814. `org-agenda-todo-ignore-scheduled' or
  4815. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4816. (let ((days (org-time-stamp-to-now
  4817. time org-agenda-todo-ignore-time-comparison-use-seconds)))
  4818. (if (>= n 0)
  4819. (>= days n)
  4820. (<= days n))))
  4821. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4822. (&optional end)
  4823. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4824. (when (or org-agenda-todo-ignore-with-date
  4825. org-agenda-todo-ignore-scheduled
  4826. org-agenda-todo-ignore-deadlines
  4827. org-agenda-todo-ignore-timestamp)
  4828. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4829. (save-excursion
  4830. (or (and org-agenda-todo-ignore-with-date
  4831. (re-search-forward org-ts-regexp end t))
  4832. (and org-agenda-todo-ignore-scheduled
  4833. (re-search-forward org-scheduled-time-regexp end t)
  4834. (cond
  4835. ((eq org-agenda-todo-ignore-scheduled 'future)
  4836. (> (org-time-stamp-to-now
  4837. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4838. ((eq org-agenda-todo-ignore-scheduled 'past)
  4839. (<= (org-time-stamp-to-now
  4840. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4841. ((numberp org-agenda-todo-ignore-scheduled)
  4842. (org-agenda-todo-custom-ignore-p
  4843. (match-string 1) org-agenda-todo-ignore-scheduled))
  4844. (t)))
  4845. (and org-agenda-todo-ignore-deadlines
  4846. (re-search-forward org-deadline-time-regexp end t)
  4847. (cond
  4848. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4849. ((eq org-agenda-todo-ignore-deadlines 'far)
  4850. (not (org-deadline-close (match-string 1))))
  4851. ((eq org-agenda-todo-ignore-deadlines 'future)
  4852. (> (org-time-stamp-to-now
  4853. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4854. ((eq org-agenda-todo-ignore-deadlines 'past)
  4855. (<= (org-time-stamp-to-now
  4856. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4857. ((numberp org-agenda-todo-ignore-deadlines)
  4858. (org-agenda-todo-custom-ignore-p
  4859. (match-string 1) org-agenda-todo-ignore-deadlines))
  4860. (t (org-deadline-close (match-string 1)))))
  4861. (and org-agenda-todo-ignore-timestamp
  4862. (let ((buffer (current-buffer))
  4863. (regexp
  4864. (concat
  4865. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4866. (start (point)))
  4867. ;; Copy current buffer into a temporary one
  4868. (with-temp-buffer
  4869. (insert-buffer-substring buffer start end)
  4870. (goto-char (point-min))
  4871. ;; Delete SCHEDULED and DEADLINE items
  4872. (while (re-search-forward regexp end t)
  4873. (delete-region (match-beginning 0) (match-end 0)))
  4874. (goto-char (point-min))
  4875. ;; No search for timestamp left
  4876. (when (re-search-forward org-ts-regexp nil t)
  4877. (cond
  4878. ((eq org-agenda-todo-ignore-timestamp 'future)
  4879. (> (org-time-stamp-to-now
  4880. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4881. ((eq org-agenda-todo-ignore-timestamp 'past)
  4882. (<= (org-time-stamp-to-now
  4883. (match-string 1) org-agenda-todo-ignore-time-comparison-use-seconds) 0))
  4884. ((numberp org-agenda-todo-ignore-timestamp)
  4885. (org-agenda-todo-custom-ignore-p
  4886. (match-string 1) org-agenda-todo-ignore-timestamp))
  4887. (t))))))))))
  4888. (autoload 'org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item "org-agenda" "\
  4889. Do we have a reason to ignore this TODO entry because it has a time stamp?
  4890. \(fn &optional END)" nil nil)
  4891. (defconst org-agenda-no-heading-message
  4892. "No heading for this item in buffer or region.")
  4893. (defun org-agenda-get-timestamps (&optional deadline-results)
  4894. "Return the date stamp information for agenda display."
  4895. (let* ((props (list 'face 'org-agenda-calendar-event
  4896. 'org-not-done-regexp org-not-done-regexp
  4897. 'org-todo-regexp org-todo-regexp
  4898. 'org-complex-heading-regexp org-complex-heading-regexp
  4899. 'mouse-face 'highlight
  4900. 'help-echo
  4901. (format "mouse-2 or RET jump to org file %s"
  4902. (abbreviate-file-name buffer-file-name))))
  4903. (d1 (calendar-absolute-from-gregorian date))
  4904. mm
  4905. (deadline-position-alist
  4906. (mapcar (lambda (a) (and (setq mm (get-text-property
  4907. 0 'org-hd-marker a))
  4908. (cons (marker-position mm) a)))
  4909. deadline-results))
  4910. (remove-re org-ts-regexp)
  4911. (regexp
  4912. (concat
  4913. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4914. (regexp-quote
  4915. (substring
  4916. (format-time-string
  4917. (car org-time-stamp-formats)
  4918. (apply 'encode-time ; DATE bound by calendar
  4919. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4920. 1 11))
  4921. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4922. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4923. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4924. donep tmp priority category category-pos level ee txt timestr tags
  4925. b0 b3 e3 head todo-state end-of-match show-all warntime habitp)
  4926. (goto-char (point-min))
  4927. (while (setq end-of-match (re-search-forward regexp nil t))
  4928. (setq b0 (match-beginning 0)
  4929. b3 (match-beginning 3) e3 (match-end 3)
  4930. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4931. habitp (and (functionp 'org-is-habit-p) (save-match-data (org-is-habit-p)))
  4932. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4933. (member todo-state
  4934. org-agenda-repeating-timestamp-show-all)))
  4935. (catch :skip
  4936. (and (org-at-date-range-p) (throw :skip nil))
  4937. (org-agenda-skip)
  4938. (if (and (match-end 1)
  4939. (not (= d1 (org-time-string-to-absolute
  4940. (match-string 1) d1 nil show-all
  4941. (current-buffer) b0))))
  4942. (throw :skip nil))
  4943. (if (and e3
  4944. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4945. (throw :skip nil))
  4946. (setq tmp (buffer-substring (max (point-min)
  4947. (- b0 org-ds-keyword-length))
  4948. b0)
  4949. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4950. inactivep (= (char-after b0) ?\[)
  4951. deadlinep (string-match org-deadline-regexp tmp)
  4952. scheduledp (string-match org-scheduled-regexp tmp)
  4953. closedp (and org-agenda-include-inactive-timestamps
  4954. (string-match org-closed-string tmp))
  4955. clockp (and org-agenda-include-inactive-timestamps
  4956. (or (string-match org-clock-string tmp)
  4957. (string-match "]-+\\'" tmp)))
  4958. warntime (org-entry-get (point) "APPT_WARNTIME")
  4959. donep (member todo-state org-done-keywords))
  4960. (if (or scheduledp deadlinep closedp clockp
  4961. (and donep org-agenda-skip-timestamp-if-done))
  4962. (throw :skip t))
  4963. (if (string-match ">" timestr)
  4964. ;; substring should only run to end of time stamp
  4965. (setq timestr (substring timestr 0 (match-end 0))))
  4966. (setq marker (org-agenda-new-marker b0)
  4967. category (org-get-category b0)
  4968. category-pos (get-text-property b0 'org-category-position))
  4969. (save-excursion
  4970. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4971. (setq txt org-agenda-no-heading-message)
  4972. (goto-char (match-beginning 0))
  4973. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4974. (assoc (point) deadline-position-alist))
  4975. (throw :skip nil))
  4976. (setq hdmarker (org-agenda-new-marker)
  4977. tags (org-get-tags-at)
  4978. level (make-string (org-reduced-level (org-outline-level)) ? ))
  4979. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4980. (setq head (or (match-string 1) ""))
  4981. (setq txt (org-agenda-format-item
  4982. (if inactivep org-agenda-inactive-leader nil)
  4983. head level category tags timestr
  4984. remove-re habitp)))
  4985. (setq priority (org-get-priority txt))
  4986. (org-add-props txt props 'priority priority
  4987. 'org-marker marker 'org-hd-marker hdmarker
  4988. 'org-category category 'date date
  4989. 'level level
  4990. 'org-category-position category-pos
  4991. 'todo-state todo-state
  4992. 'warntime warntime
  4993. 'type "timestamp")
  4994. (push txt ee))
  4995. (if org-agenda-skip-additional-timestamps-same-entry
  4996. (outline-next-heading)
  4997. (goto-char end-of-match))))
  4998. (nreverse ee)))
  4999. (defun org-agenda-get-sexps ()
  5000. "Return the sexp information for agenda display."
  5001. (require 'diary-lib)
  5002. (let* ((props (list 'face 'org-agenda-calendar-sexp
  5003. 'mouse-face 'highlight
  5004. 'help-echo
  5005. (format "mouse-2 or RET jump to org file %s"
  5006. (abbreviate-file-name buffer-file-name))))
  5007. (regexp "^&?%%(")
  5008. marker category extra category-pos level ee txt tags entry
  5009. result beg b sexp sexp-entry todo-state warntime)
  5010. (goto-char (point-min))
  5011. (while (re-search-forward regexp nil t)
  5012. (catch :skip
  5013. (org-agenda-skip)
  5014. (setq beg (match-beginning 0))
  5015. (goto-char (1- (match-end 0)))
  5016. (setq b (point))
  5017. (forward-sexp 1)
  5018. (setq sexp (buffer-substring b (point)))
  5019. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  5020. (org-trim (match-string 1))
  5021. ""))
  5022. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  5023. (when result
  5024. (setq marker (org-agenda-new-marker beg)
  5025. level (make-string (org-reduced-level (org-outline-level)) ? )
  5026. category (org-get-category beg)
  5027. category-pos (get-text-property beg 'org-category-position)
  5028. tags (save-excursion (org-backward-heading-same-level 0)
  5029. (org-get-tags-at))
  5030. todo-state (org-get-todo-state)
  5031. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5032. (dolist (r (if (stringp result)
  5033. (list result)
  5034. result)) ;; we expect a list here
  5035. (when (and org-agenda-diary-sexp-prefix
  5036. (string-match org-agenda-diary-sexp-prefix r))
  5037. (setq extra (match-string 0 r)
  5038. r (replace-match "" nil nil r)))
  5039. (if (string-match "\\S-" r)
  5040. (setq txt r)
  5041. (setq txt "SEXP entry returned empty string"))
  5042. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  5043. (org-add-props txt props 'org-marker marker
  5044. 'org-category category 'date date 'todo-state todo-state
  5045. 'org-category-position category-pos 'tags tags
  5046. 'level level
  5047. 'type "sexp" 'warntime warntime)
  5048. (push txt ee)))))
  5049. (nreverse ee)))
  5050. ;; Calendar sanity: define some functions that are independent of
  5051. ;; `calendar-date-style'.
  5052. ;; Normally I would like to use ISO format when calling the diary functions,
  5053. ;; but to make sure we still have Emacs 22 compatibility we bind
  5054. ;; also `european-calendar-style' and use european format
  5055. (defun org-anniversary (year month day &optional mark)
  5056. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  5057. (org-no-warnings
  5058. (let ((calendar-date-style 'european) (european-calendar-style t))
  5059. (diary-anniversary day month year mark))))
  5060. (defun org-cyclic (N year month day &optional mark)
  5061. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  5062. (org-no-warnings
  5063. (let ((calendar-date-style 'european) (european-calendar-style t))
  5064. (diary-cyclic N day month year mark))))
  5065. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  5066. "Like `diary-block', but with fixed (ISO) order of arguments."
  5067. (org-no-warnings
  5068. (let ((calendar-date-style 'european) (european-calendar-style t))
  5069. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  5070. (defun org-date (year month day &optional mark)
  5071. "Like `diary-date', but with fixed (ISO) order of arguments."
  5072. (org-no-warnings
  5073. (let ((calendar-date-style 'european) (european-calendar-style t))
  5074. (diary-date day month year mark))))
  5075. (defalias 'org-float 'diary-float)
  5076. ;; Define the` org-class' function
  5077. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  5078. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  5079. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  5080. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  5081. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  5082. `holidays', then any date that is known by the Emacs calendar to be a
  5083. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  5084. then those holidays will be skipped."
  5085. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  5086. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  5087. (d (calendar-absolute-from-gregorian date))
  5088. (h (when skip-weeks (calendar-check-holidays date))))
  5089. (and
  5090. (<= date1 d)
  5091. (<= d date2)
  5092. (= (calendar-day-of-week date) dayname)
  5093. (or (not skip-weeks)
  5094. (progn
  5095. (require 'cal-iso)
  5096. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  5097. (not (or (and h (memq 'holidays skip-weeks))
  5098. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  5099. entry)))
  5100. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  5101. "Like `org-class', but honor `calendar-date-style'.
  5102. The order of the first 2 times 3 arguments depends on the variable
  5103. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  5104. So for American calendars, give this as MONTH DAY YEAR, for European as
  5105. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  5106. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  5107. is any number of ISO weeks in the block period for which the item should
  5108. be skipped.
  5109. This function is here only for backward compatibility and it is deprecated,
  5110. please use `org-class' instead."
  5111. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  5112. (date2 (org-order-calendar-date-args m2 d2 y2)))
  5113. (org-class
  5114. (nth 2 date1) (car date1) (nth 1 date1)
  5115. (nth 2 date2) (car date2) (nth 1 date2)
  5116. dayname skip-weeks)))
  5117. (make-obsolete 'org-diary-class 'org-class "")
  5118. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  5119. (defalias 'org-get-closed 'org-agenda-get-progress)
  5120. (defun org-agenda-get-progress ()
  5121. "Return the logged TODO entries for agenda display."
  5122. (let* ((props (list 'mouse-face 'highlight
  5123. 'org-not-done-regexp org-not-done-regexp
  5124. 'org-todo-regexp org-todo-regexp
  5125. 'org-complex-heading-regexp org-complex-heading-regexp
  5126. 'help-echo
  5127. (format "mouse-2 or RET jump to org file %s"
  5128. (abbreviate-file-name buffer-file-name))))
  5129. (items (if (consp org-agenda-show-log-scoped)
  5130. org-agenda-show-log-scoped
  5131. (if (eq org-agenda-show-log-scoped 'clockcheck)
  5132. '(clock)
  5133. org-agenda-log-mode-items)))
  5134. (parts
  5135. (delq nil
  5136. (list
  5137. (if (memq 'closed items) (concat "\\<" org-closed-string))
  5138. (if (memq 'clock items) (concat "\\<" org-clock-string))
  5139. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  5140. (parts-re (if parts (mapconcat 'identity parts "\\|")
  5141. (error "`org-agenda-log-mode-items' is empty")))
  5142. (regexp (concat
  5143. "\\(" parts-re "\\)"
  5144. " *\\["
  5145. (regexp-quote
  5146. (substring
  5147. (format-time-string
  5148. (car org-time-stamp-formats)
  5149. (apply 'encode-time ; DATE bound by calendar
  5150. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  5151. 1 11))))
  5152. (org-agenda-search-headline-for-time nil)
  5153. marker hdmarker priority category category-pos level tags closedp
  5154. statep clockp state ee txt extra timestr rest clocked)
  5155. (goto-char (point-min))
  5156. (while (re-search-forward regexp nil t)
  5157. (catch :skip
  5158. (org-agenda-skip)
  5159. (setq marker (org-agenda-new-marker (match-beginning 0))
  5160. closedp (equal (match-string 1) org-closed-string)
  5161. statep (equal (string-to-char (match-string 1)) ?-)
  5162. clockp (not (or closedp statep))
  5163. state (and statep (match-string 2))
  5164. category (org-get-category (match-beginning 0))
  5165. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  5166. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  5167. (when (string-match "\\]" timestr)
  5168. ;; substring should only run to end of time stamp
  5169. (setq rest (substring timestr (match-end 0))
  5170. timestr (substring timestr 0 (match-end 0)))
  5171. (if (and (not closedp) (not statep)
  5172. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  5173. rest))
  5174. (progn (setq timestr (concat (substring timestr 0 -1)
  5175. "-" (match-string 1 rest) "]"))
  5176. (setq clocked (match-string 2 rest)))
  5177. (setq clocked "-")))
  5178. (save-excursion
  5179. (setq extra
  5180. (cond
  5181. ((not org-agenda-log-mode-add-notes) nil)
  5182. (statep
  5183. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  5184. (match-string 1)))
  5185. (clockp
  5186. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  5187. (match-string 1)))))
  5188. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5189. (setq txt org-agenda-no-heading-message)
  5190. (goto-char (match-beginning 0))
  5191. (setq hdmarker (org-agenda-new-marker)
  5192. tags (org-get-tags-at)
  5193. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5194. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5195. (setq txt (match-string 1))
  5196. (when extra
  5197. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5198. (setq txt (concat (substring txt 0 (match-beginning 1))
  5199. " - " extra " " (match-string 2 txt)))
  5200. (setq txt (concat txt " - " extra))))
  5201. (setq txt (org-agenda-format-item
  5202. (cond
  5203. (closedp "Closed: ")
  5204. (statep (concat "State: (" state ")"))
  5205. (t (concat "Clocked: (" clocked ")")))
  5206. txt level category tags timestr)))
  5207. (setq priority 100000)
  5208. (org-add-props txt props
  5209. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5210. 'priority priority 'org-category category
  5211. 'org-category-position category-pos
  5212. 'level level
  5213. 'type "closed" 'date date
  5214. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5215. (push txt ee))
  5216. (goto-char (point-at-eol))))
  5217. (nreverse ee)))
  5218. (defun org-agenda-show-clocking-issues ()
  5219. "Add overlays, showing issues with clocking.
  5220. See also the user option `org-agenda-clock-consistency-checks'."
  5221. (interactive)
  5222. (let* ((pl org-agenda-clock-consistency-checks)
  5223. (re (concat "^[ \t]*"
  5224. org-clock-string
  5225. "[ \t]+"
  5226. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5227. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5228. (tlstart 0.)
  5229. (tlend 0.)
  5230. (maxtime (org-hh:mm-string-to-minutes
  5231. (or (plist-get pl :max-duration) "24:00")))
  5232. (mintime (org-hh:mm-string-to-minutes
  5233. (or (plist-get pl :min-duration) 0)))
  5234. (maxgap (org-hh:mm-string-to-minutes
  5235. ;; default 30:00 means never complain
  5236. (or (plist-get pl :max-gap) "30:00")))
  5237. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5238. (plist-get pl :gap-ok-around)))
  5239. (def-face (or (plist-get pl :default-face)
  5240. '((:background "DarkRed") (:foreground "white"))))
  5241. issue face m te ts dt ov)
  5242. (goto-char (point-min))
  5243. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5244. (setq issue nil face def-face)
  5245. (catch 'next
  5246. (setq m (org-get-at-bol 'org-marker)
  5247. te nil ts nil)
  5248. (unless (and m (markerp m))
  5249. (setq issue "No valid clock line") (throw 'next t))
  5250. (org-with-point-at m
  5251. (save-excursion
  5252. (goto-char (point-at-bol))
  5253. (unless (looking-at re)
  5254. (error "No valid Clock line")
  5255. (throw 'next t))
  5256. (unless (match-end 3)
  5257. (setq issue "No end time"
  5258. face (or (plist-get pl :no-end-time-face) face))
  5259. (throw 'next t))
  5260. (setq ts (match-string 1)
  5261. te (match-string 3)
  5262. ts (org-float-time
  5263. (apply 'encode-time (org-parse-time-string ts)))
  5264. te (org-float-time
  5265. (apply 'encode-time (org-parse-time-string te)))
  5266. dt (- te ts))))
  5267. (cond
  5268. ((> dt (* 60 maxtime))
  5269. ;; a very long clocking chunk
  5270. (setq issue (format "Clocking interval is very long: %s"
  5271. (org-minutes-to-hh:mm-string
  5272. (floor (/ (float dt) 60.))))
  5273. face (or (plist-get pl :long-face) face)))
  5274. ((< dt (* 60 mintime))
  5275. ;; a very short clocking chunk
  5276. (setq issue (format "Clocking interval is very short: %s"
  5277. (org-minutes-to-hh:mm-string
  5278. (floor (/ (float dt) 60.))))
  5279. face (or (plist-get pl :short-face) face)))
  5280. ((and (> tlend 0) (< ts tlend))
  5281. ;; Two clock entries are overlapping
  5282. (setq issue (format "Clocking overlap: %d minutes"
  5283. (/ (- tlend ts) 60))
  5284. face (or (plist-get pl :overlap-face) face)))
  5285. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5286. ;; There is a gap, lets see if we need to report it
  5287. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5288. (setq issue (format "Clocking gap: %d minutes"
  5289. (/ (- ts tlend) 60))
  5290. face (or (plist-get pl :gap-face) face))))
  5291. (t nil)))
  5292. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5293. (when issue
  5294. ;; OK, there was some issue, add an overlay to show the issue
  5295. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5296. (overlay-put ov 'before-string
  5297. (concat
  5298. (org-add-props
  5299. (format "%-43s" (concat " " issue))
  5300. nil
  5301. 'face face)
  5302. "\n"))
  5303. (overlay-put ov 'evaporate t)))))
  5304. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5305. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5306. (catch 'exit
  5307. (unless ok-list
  5308. ;; there are no OK times for gaps...
  5309. (throw 'exit nil))
  5310. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5311. ;; This is more than 24 hours, so it is OK.
  5312. ;; because we have at least one OK time, that must be in the
  5313. ;; 24 hour interval.
  5314. (throw 'exit t))
  5315. ;; We have a shorter gap.
  5316. ;; Now we have to get the minute of the day when these times are
  5317. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5318. (t2dec (decode-time (seconds-to-time t2)))
  5319. ;; compute the minute on the day
  5320. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5321. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5322. (when (< min2 min1)
  5323. ;; if min2 is smaller than min1, this means it is on the next day.
  5324. ;; Wrap it to after midnight.
  5325. (setq min2 (+ min2 1440)))
  5326. ;; Now check if any of the OK times is in the gap
  5327. (mapc (lambda (x)
  5328. ;; Wrap the time to after midnight if necessary
  5329. (if (< x min1) (setq x (+ x 1440)))
  5330. ;; Check if in interval
  5331. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5332. ok-list)
  5333. ;; Nope, this gap is not OK
  5334. nil)))
  5335. (defun org-agenda-get-deadlines ()
  5336. "Return the deadline information for agenda display."
  5337. (let* ((props (list 'mouse-face 'highlight
  5338. 'org-not-done-regexp org-not-done-regexp
  5339. 'org-todo-regexp org-todo-regexp
  5340. 'org-complex-heading-regexp org-complex-heading-regexp
  5341. 'help-echo
  5342. (format "mouse-2 or RET jump to org file %s"
  5343. (abbreviate-file-name buffer-file-name))))
  5344. (regexp org-deadline-time-regexp)
  5345. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5346. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5347. d2 diff dfrac wdays pos pos1 category category-pos level
  5348. tags suppress-prewarning ee txt head face s todo-state
  5349. show-all upcomingp donep timestr warntime)
  5350. (goto-char (point-min))
  5351. (while (re-search-forward regexp nil t)
  5352. (setq suppress-prewarning nil)
  5353. (catch :skip
  5354. (org-agenda-skip)
  5355. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5356. (save-match-data
  5357. (string-match org-scheduled-time-regexp
  5358. (buffer-substring (point-at-bol)
  5359. (point-at-eol)))))
  5360. (setq suppress-prewarning
  5361. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5362. org-agenda-skip-deadline-prewarning-if-scheduled
  5363. 0)))
  5364. (setq s (match-string 1)
  5365. txt nil
  5366. pos (1- (match-beginning 1))
  5367. todo-state (save-match-data (org-get-todo-state))
  5368. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5369. (member todo-state
  5370. org-agenda-repeating-timestamp-show-all))
  5371. d2 (org-time-string-to-absolute
  5372. (match-string 1) d1 'past show-all
  5373. (current-buffer) pos)
  5374. diff (- d2 d1)
  5375. wdays (if suppress-prewarning
  5376. (let ((org-deadline-warning-days suppress-prewarning))
  5377. (org-get-wdays s))
  5378. (org-get-wdays s))
  5379. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5380. upcomingp (and todayp (> diff 0)))
  5381. ;; When to show a deadline in the calendar:
  5382. ;; If the expiration is within wdays warning time.
  5383. ;; Past-due deadlines are only shown on the current date
  5384. (if (and (or (and (<= diff wdays)
  5385. (and todayp (not org-agenda-only-exact-dates)))
  5386. (= diff 0)))
  5387. (save-excursion
  5388. ;; (setq todo-state (org-get-todo-state))
  5389. (setq donep (member todo-state org-done-keywords))
  5390. (if (and donep
  5391. (or org-agenda-skip-deadline-if-done
  5392. (not (= diff 0))))
  5393. (setq txt nil)
  5394. (setq category (org-get-category)
  5395. warntime (org-entry-get (point) "APPT_WARNTIME")
  5396. category-pos (get-text-property (point) 'org-category-position))
  5397. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5398. (setq txt org-agenda-no-heading-message)
  5399. (goto-char (match-end 0))
  5400. (setq pos1 (match-beginning 0))
  5401. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5402. (setq tags (org-get-tags-at pos1))
  5403. (setq head (buffer-substring-no-properties
  5404. (point)
  5405. (progn (skip-chars-forward "^\r\n")
  5406. (point))))
  5407. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5408. (setq timestr
  5409. (concat (substring s (match-beginning 1)) " "))
  5410. (setq timestr 'time))
  5411. (setq txt (org-agenda-format-item
  5412. (if (= diff 0)
  5413. (car org-agenda-deadline-leaders)
  5414. (if (functionp
  5415. (nth 1 org-agenda-deadline-leaders))
  5416. (funcall
  5417. (nth 1 org-agenda-deadline-leaders)
  5418. diff date)
  5419. (format (nth 1 org-agenda-deadline-leaders)
  5420. diff)))
  5421. head level category tags
  5422. (if (not (= diff 0)) nil timestr)))))
  5423. (when txt
  5424. (setq face (org-agenda-deadline-face dfrac))
  5425. (org-add-props txt props
  5426. 'org-marker (org-agenda-new-marker pos)
  5427. 'warntime warntime
  5428. 'level level
  5429. 'org-hd-marker (org-agenda-new-marker pos1)
  5430. 'priority (+ (- diff)
  5431. (org-get-priority txt))
  5432. 'org-category category
  5433. 'org-category-position category-pos
  5434. 'todo-state todo-state
  5435. 'type (if upcomingp "upcoming-deadline" "deadline")
  5436. 'date (if upcomingp date d2)
  5437. 'face (if donep 'org-agenda-done face)
  5438. 'undone-face face 'done-face 'org-agenda-done)
  5439. (push txt ee))))))
  5440. (nreverse ee)))
  5441. (defun org-agenda-deadline-face (fraction)
  5442. "Return the face to displaying a deadline item.
  5443. FRACTION is what fraction of the head-warning time has passed."
  5444. (let ((faces org-agenda-deadline-faces) f)
  5445. (catch 'exit
  5446. (while (setq f (pop faces))
  5447. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5448. (defun org-agenda-get-scheduled (&optional deadline-results)
  5449. "Return the scheduled information for agenda display."
  5450. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5451. 'org-todo-regexp org-todo-regexp
  5452. 'org-complex-heading-regexp org-complex-heading-regexp
  5453. 'done-face 'org-agenda-done
  5454. 'mouse-face 'highlight
  5455. 'help-echo
  5456. (format "mouse-2 or RET jump to org file %s"
  5457. (abbreviate-file-name buffer-file-name))))
  5458. (regexp org-scheduled-time-regexp)
  5459. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5460. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5461. mm
  5462. (deadline-position-alist
  5463. (mapcar (lambda (a) (and (setq mm (get-text-property
  5464. 0 'org-hd-marker a))
  5465. (cons (marker-position mm) a)))
  5466. deadline-results))
  5467. d2 diff pos pos1 category category-pos level tags donep
  5468. ee txt head pastschedp todo-state face timestr s habitp show-all
  5469. did-habit-check-p warntime)
  5470. (goto-char (point-min))
  5471. (while (re-search-forward regexp nil t)
  5472. (catch :skip
  5473. (org-agenda-skip)
  5474. (setq s (match-string 1)
  5475. txt nil
  5476. pos (1- (match-beginning 1))
  5477. todo-state (save-match-data (org-get-todo-state))
  5478. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5479. (member todo-state
  5480. org-agenda-repeating-timestamp-show-all))
  5481. d2 (org-time-string-to-absolute
  5482. (match-string 1) d1 'past show-all
  5483. (current-buffer) pos)
  5484. diff (- d2 d1)
  5485. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5486. (setq pastschedp (and todayp (< diff 0)))
  5487. (setq did-habit-check-p nil)
  5488. ;; When to show a scheduled item in the calendar:
  5489. ;; If it is on or past the date.
  5490. (when (or (and (< diff 0)
  5491. (< (abs diff) org-scheduled-past-days)
  5492. (and todayp (not org-agenda-only-exact-dates)))
  5493. (= diff 0)
  5494. ;; org-is-habit-p uses org-entry-get, which is expansive
  5495. ;; so we go extra mile to only call it once
  5496. (and todayp
  5497. (boundp 'org-habit-show-all-today)
  5498. org-habit-show-all-today
  5499. (setq did-habit-check-p t)
  5500. (setq habitp (and (functionp 'org-is-habit-p)
  5501. (org-is-habit-p)))))
  5502. (save-excursion
  5503. (setq donep (member todo-state org-done-keywords))
  5504. (if (and donep
  5505. (or org-agenda-skip-scheduled-if-done
  5506. (not (= diff 0))
  5507. (and (functionp 'org-is-habit-p)
  5508. (org-is-habit-p))))
  5509. (setq txt nil)
  5510. (setq habitp (if did-habit-check-p habitp
  5511. (and (functionp 'org-is-habit-p)
  5512. (org-is-habit-p))))
  5513. (setq category (org-get-category)
  5514. category-pos (get-text-property (point) 'org-category-position))
  5515. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5516. (setq txt org-agenda-no-heading-message)
  5517. (goto-char (match-end 0))
  5518. (setq pos1 (match-beginning 0))
  5519. (if habitp
  5520. (if (or (not org-habit-show-habits)
  5521. (and (not todayp)
  5522. (boundp 'org-habit-show-habits-only-for-today)
  5523. org-habit-show-habits-only-for-today))
  5524. (throw :skip nil))
  5525. (if (and
  5526. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5527. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5528. pastschedp))
  5529. (setq mm (assoc pos1 deadline-position-alist)))
  5530. (throw :skip nil)))
  5531. (setq tags (org-get-tags-at))
  5532. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5533. (setq head (buffer-substring-no-properties
  5534. (point)
  5535. (progn (skip-chars-forward "^\r\n") (point))))
  5536. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5537. (setq timestr
  5538. (concat (substring s (match-beginning 1)) " "))
  5539. (setq timestr 'time))
  5540. (setq txt (org-agenda-format-item
  5541. (if (= diff 0)
  5542. (car org-agenda-scheduled-leaders)
  5543. (format (nth 1 org-agenda-scheduled-leaders)
  5544. (- 1 diff)))
  5545. head level category tags
  5546. (if (not (= diff 0)) nil timestr)
  5547. nil habitp))))
  5548. (when txt
  5549. (setq face
  5550. (cond
  5551. ((and (not habitp) pastschedp)
  5552. 'org-scheduled-previously)
  5553. (todayp 'org-scheduled-today)
  5554. (t 'org-scheduled))
  5555. habitp (and habitp (org-habit-parse-todo)))
  5556. (org-add-props txt props
  5557. 'undone-face face
  5558. 'face (if donep 'org-agenda-done face)
  5559. 'org-marker (org-agenda-new-marker pos)
  5560. 'org-hd-marker (org-agenda-new-marker pos1)
  5561. 'type (if pastschedp "past-scheduled" "scheduled")
  5562. 'date (if pastschedp d2 date)
  5563. 'warntime warntime
  5564. 'level level
  5565. 'priority (if habitp
  5566. (org-habit-get-priority habitp)
  5567. (+ 94 (- 5 diff) (org-get-priority txt)))
  5568. 'org-category category
  5569. 'category-position category-pos
  5570. 'org-habit-p habitp
  5571. 'todo-state todo-state)
  5572. (push txt ee))))))
  5573. (nreverse ee)))
  5574. (defun org-agenda-get-blocks ()
  5575. "Return the date-range information for agenda display."
  5576. (let* ((props (list 'face nil
  5577. 'org-not-done-regexp org-not-done-regexp
  5578. 'org-todo-regexp org-todo-regexp
  5579. 'org-complex-heading-regexp org-complex-heading-regexp
  5580. 'mouse-face 'highlight
  5581. 'help-echo
  5582. (format "mouse-2 or RET jump to org file %s"
  5583. (abbreviate-file-name buffer-file-name))))
  5584. (regexp org-tr-regexp)
  5585. (d0 (calendar-absolute-from-gregorian date))
  5586. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5587. level todo-state tags pos head donep)
  5588. (goto-char (point-min))
  5589. (while (re-search-forward regexp nil t)
  5590. (catch :skip
  5591. (org-agenda-skip)
  5592. (setq pos (point))
  5593. (let ((start-time (match-string 1))
  5594. (end-time (match-string 2)))
  5595. (setq s1 (match-string 1)
  5596. s2 (match-string 2)
  5597. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5598. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5599. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5600. ;; Only allow days between the limits, because the normal
  5601. ;; date stamps will catch the limits.
  5602. (save-excursion
  5603. (setq todo-state (org-get-todo-state))
  5604. (setq donep (member todo-state org-done-keywords))
  5605. (if (and donep org-agenda-skip-timestamp-if-done)
  5606. (throw :skip t))
  5607. (setq marker (org-agenda-new-marker (point)))
  5608. (setq category (org-get-category)
  5609. category-pos (get-text-property (point) 'org-category-position))
  5610. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5611. (setq txt org-agenda-no-heading-message)
  5612. (goto-char (match-beginning 0))
  5613. (setq hdmarker (org-agenda-new-marker (point)))
  5614. (setq tags (org-get-tags-at))
  5615. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5616. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5617. (setq head (match-string 1))
  5618. (let ((remove-re
  5619. (if org-agenda-remove-timeranges-from-blocks
  5620. (concat
  5621. "<" (regexp-quote s1) ".*?>"
  5622. "--"
  5623. "<" (regexp-quote s2) ".*?>")
  5624. nil)))
  5625. (setq txt (org-agenda-format-item
  5626. (format
  5627. (nth (if (= d1 d2) 0 1)
  5628. org-agenda-timerange-leaders)
  5629. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5630. head level category tags
  5631. (cond ((and (= d1 d0) (= d2 d0))
  5632. (concat "<" start-time ">--<" end-time ">"))
  5633. ((= d1 d0)
  5634. (concat "<" start-time ">"))
  5635. ((= d2 d0)
  5636. (concat "<" end-time ">")))
  5637. remove-re))))
  5638. (org-add-props txt props
  5639. 'org-marker marker 'org-hd-marker hdmarker
  5640. 'type "block" 'date date
  5641. 'level level
  5642. 'todo-state todo-state
  5643. 'priority (org-get-priority txt) 'org-category category
  5644. 'org-category-position category-pos)
  5645. (push txt ee))))
  5646. (goto-char pos)))
  5647. ;; Sort the entries by expiration date.
  5648. (nreverse ee)))
  5649. ;;; Agenda presentation and sorting
  5650. (defvar org-prefix-has-time nil
  5651. "A flag, set by `org-compile-prefix-format'.
  5652. The flag is set if the currently compiled format contains a `%t'.")
  5653. (defvar org-prefix-has-tag nil
  5654. "A flag, set by `org-compile-prefix-format'.
  5655. The flag is set if the currently compiled format contains a `%T'.")
  5656. (defvar org-prefix-has-effort nil
  5657. "A flag, set by `org-compile-prefix-format'.
  5658. The flag is set if the currently compiled format contains a `%e'.")
  5659. (defvar org-prefix-category-length nil
  5660. "Used by `org-compile-prefix-format' to remember the category field width.")
  5661. (defvar org-prefix-category-max-length nil
  5662. "Used by `org-compile-prefix-format' to remember the category field width.")
  5663. (defun org-agenda-get-category-icon (category)
  5664. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5665. (dolist (entry org-agenda-category-icon-alist)
  5666. (when (org-string-match-p (car entry) category)
  5667. (if (listp (cadr entry))
  5668. (return (cadr entry))
  5669. (return (apply 'create-image (cdr entry)))))))
  5670. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5671. remove-re habitp)
  5672. "Format TXT to be inserted into the agenda buffer.
  5673. In particular, add the prefix and corresponding text properties.
  5674. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5675. LEVEL may be a string to replace the `%l' specifier.
  5676. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5677. category taken from local variable or file name. It will replace the `%c'
  5678. specifier in the format.
  5679. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5680. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5681. When DOTIME is a string, this string is searched for a time before TXT is.
  5682. TAGS can be the tags of the headline.
  5683. Any match of REMOVE-RE will be removed from TXT."
  5684. ;; We keep the org-prefix-* variable values along with a compiled
  5685. ;; formatter, so that multiple agendas existing at the same time do
  5686. ;; not step on each other toes.
  5687. ;;
  5688. ;; It was inconvenient to make these variables buffer local in
  5689. ;; Agenda buffers, because this function expects to be called with
  5690. ;; the buffer where item comes from being current, and not agenda
  5691. ;; buffer
  5692. (let* ((bindings (car org-prefix-format-compiled))
  5693. (formatter (cadr org-prefix-format-compiled)))
  5694. (loop for (var value) in bindings
  5695. do (set var value))
  5696. (save-match-data
  5697. ;; Diary entries sometimes have extra whitespace at the beginning
  5698. (setq txt (org-trim txt))
  5699. ;; Fix the tags part in txt
  5700. (setq txt (org-agenda-fix-displayed-tags
  5701. txt tags
  5702. org-agenda-show-inherited-tags
  5703. org-agenda-hide-tags-regexp))
  5704. (let* ((category (or category
  5705. (if (stringp org-category)
  5706. org-category
  5707. (and org-category (symbol-name org-category)))
  5708. (if buffer-file-name
  5709. (file-name-sans-extension
  5710. (file-name-nondirectory buffer-file-name))
  5711. "")))
  5712. (category-icon (org-agenda-get-category-icon category))
  5713. (category-icon (if category-icon
  5714. (propertize " " 'display category-icon)
  5715. ""))
  5716. ;; time, tag, effort are needed for the eval of the prefix format
  5717. (tag (if tags (nth (1- (length tags)) tags) ""))
  5718. time effort neffort
  5719. (ts (if dotime (concat
  5720. (if (stringp dotime) dotime "")
  5721. (and org-agenda-search-headline-for-time txt))))
  5722. (time-of-day (and dotime (org-get-time-of-day ts)))
  5723. stamp plain s0 s1 s2 rtn srp l
  5724. duration thecategory)
  5725. (and (derived-mode-p 'org-mode) buffer-file-name
  5726. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5727. (when (and dotime time-of-day)
  5728. ;; Extract starting and ending time and move them to prefix
  5729. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5730. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5731. (setq s0 (match-string 0 ts)
  5732. srp (and stamp (match-end 3))
  5733. s1 (match-string (if plain 1 2) ts)
  5734. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5735. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5736. ;; them, we might want to remove them there to avoid duplication.
  5737. ;; The user can turn this off with a variable.
  5738. (if (and org-prefix-has-time
  5739. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5740. (string-match (concat (regexp-quote s0) " *") txt)
  5741. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5742. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5743. (= (match-beginning 0) 0)
  5744. t))
  5745. (setq txt (replace-match "" nil nil txt))))
  5746. ;; Normalize the time(s) to 24 hour
  5747. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5748. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5749. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5750. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5751. (setq s2
  5752. (org-minutes-to-hh:mm-string
  5753. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5754. ;; Compute the duration
  5755. (when s2
  5756. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5757. (org-hh:mm-string-to-minutes s1)))))
  5758. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5759. txt)
  5760. ;; Tags are in the string
  5761. (if (or (eq org-agenda-remove-tags t)
  5762. (and org-agenda-remove-tags
  5763. org-prefix-has-tag))
  5764. (setq txt (replace-match "" t t txt))
  5765. (setq txt (replace-match
  5766. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5767. (match-string 2 txt))
  5768. t t txt))))
  5769. (when (derived-mode-p 'org-mode)
  5770. (setq effort
  5771. (condition-case nil
  5772. (org-get-effort
  5773. (or (get-text-property 0 'org-hd-marker txt)
  5774. (get-text-property 0 'org-marker txt)))
  5775. (error nil)))
  5776. (when effort
  5777. (setq neffort (org-duration-string-to-minutes effort)
  5778. effort (setq effort (concat "[" effort "]")))))
  5779. ;; prevent erroring out with %e format when there is no effort
  5780. (or effort (setq effort ""))
  5781. (when remove-re
  5782. (while (string-match remove-re txt)
  5783. (setq txt (replace-match "" t t txt))))
  5784. ;; Set org-heading property on `txt' to mark the start of the
  5785. ;; heading.
  5786. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5787. ;; Prepare the variables needed in the eval of the compiled format
  5788. (setq time (cond (s2 (concat
  5789. (org-agenda-time-of-day-to-ampm-maybe s1)
  5790. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5791. (if org-agenda-timegrid-use-ampm " ")))
  5792. (s1 (concat
  5793. (org-agenda-time-of-day-to-ampm-maybe s1)
  5794. (if org-agenda-timegrid-use-ampm
  5795. "........ "
  5796. "......")))
  5797. (t ""))
  5798. extra (or (and (not habitp) extra) "")
  5799. category (if (symbolp category) (symbol-name category) category)
  5800. thecategory (copy-sequence category)
  5801. level (or level ""))
  5802. (if (string-match org-bracket-link-regexp category)
  5803. (progn
  5804. (setq l (if (match-end 3)
  5805. (- (match-end 3) (match-beginning 3))
  5806. (- (match-end 1) (match-beginning 1))))
  5807. (when (< l (or org-prefix-category-length 0))
  5808. (setq category (copy-sequence category))
  5809. (org-add-props category nil
  5810. 'extra-space (make-string
  5811. (- org-prefix-category-length l 1) ?\ ))))
  5812. (if (and org-prefix-category-max-length
  5813. (>= (length category) org-prefix-category-max-length))
  5814. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5815. ;; Evaluate the compiled format
  5816. (setq rtn (concat (eval formatter) txt))
  5817. ;; And finally add the text properties
  5818. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5819. (org-add-props rtn nil
  5820. 'org-category (if thecategory (downcase thecategory) category)
  5821. 'tags (mapcar 'org-downcase-keep-props tags)
  5822. 'org-highest-priority org-highest-priority
  5823. 'org-lowest-priority org-lowest-priority
  5824. 'time-of-day time-of-day
  5825. 'duration duration
  5826. 'effort effort
  5827. 'effort-minutes neffort
  5828. 'txt txt
  5829. 'level level
  5830. 'time time
  5831. 'extra extra
  5832. 'format org-prefix-format-compiled
  5833. 'dotime dotime)))))
  5834. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5835. "Remove tags string from TXT, and add a modified list of tags.
  5836. The modified list may contain inherited tags, and tags matched by
  5837. `org-agenda-hide-tags-regexp' will be removed."
  5838. (when (or add-inherited hide-re)
  5839. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5840. (setq txt (substring txt 0 (match-beginning 0))))
  5841. (setq tags
  5842. (delq nil
  5843. (mapcar (lambda (tg)
  5844. (if (or (and hide-re (string-match hide-re tg))
  5845. (and (not add-inherited)
  5846. (get-text-property 0 'inherited tg)))
  5847. nil
  5848. tg))
  5849. tags)))
  5850. (when tags
  5851. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5852. i)
  5853. (setq txt (concat txt " :"
  5854. (mapconcat
  5855. (lambda (x)
  5856. (setq i (get-text-property 0 'inherited x))
  5857. (if (and have-i (not i))
  5858. (progn
  5859. (setq have-i nil)
  5860. (concat ":" x))
  5861. x))
  5862. tags ":")
  5863. (if have-i "::" ":"))))))
  5864. txt)
  5865. (defun org-downcase-keep-props (s)
  5866. (let ((props (text-properties-at 0 s)))
  5867. (setq s (downcase s))
  5868. (add-text-properties 0 (length s) props s)
  5869. s))
  5870. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5871. (defvar org-agenda-sorting-strategy-selected nil)
  5872. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5873. "Add a time-grid for agenda items which need it.
  5874. LIST is the list of agenda items formatted by `org-agenda-list'.
  5875. NDAYS is the span of the current agenda view.
  5876. TODAYP is `t' when the current agenda view is on today."
  5877. (catch 'exit
  5878. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5879. ((and todayp (member 'today (car org-agenda-time-grid))))
  5880. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5881. ((member 'weekly (car org-agenda-time-grid)))
  5882. (t (throw 'exit list)))
  5883. (let* ((have (delq nil (mapcar
  5884. (lambda (x) (get-text-property 1 'time-of-day x))
  5885. list)))
  5886. (string (nth 1 org-agenda-time-grid))
  5887. (gridtimes (nth 2 org-agenda-time-grid))
  5888. (req (car org-agenda-time-grid))
  5889. (remove (member 'remove-match req))
  5890. new time)
  5891. (if (and (member 'require-timed req) (not have))
  5892. ;; don't show empty grid
  5893. (throw 'exit list))
  5894. (while (setq time (pop gridtimes))
  5895. (unless (and remove (member time have))
  5896. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5897. (push (org-agenda-format-item
  5898. nil string nil "" nil
  5899. (concat (substring time 0 -2) ":" (substring time -2)))
  5900. new)
  5901. (put-text-property
  5902. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5903. (when (and todayp org-agenda-show-current-time-in-grid)
  5904. (push (org-agenda-format-item
  5905. nil org-agenda-current-time-string nil "" nil
  5906. (format-time-string "%H:%M "))
  5907. new)
  5908. (put-text-property
  5909. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5910. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5911. (append new list)
  5912. (append list new)))))
  5913. (defun org-compile-prefix-format (key)
  5914. "Compile the prefix format into a Lisp form that can be evaluated.
  5915. The resulting form and associated variable bindings is returned
  5916. and stored in the variable `org-prefix-format-compiled'."
  5917. (setq org-prefix-has-time nil
  5918. org-prefix-has-tag nil
  5919. org-prefix-category-length nil
  5920. org-prefix-has-effort nil)
  5921. (let ((s (cond
  5922. ((stringp org-agenda-prefix-format)
  5923. org-agenda-prefix-format)
  5924. ((assq key org-agenda-prefix-format)
  5925. (cdr (assq key org-agenda-prefix-format)))
  5926. (t " %-12:c%?-12t% s")))
  5927. (start 0)
  5928. varform vars var e c f opt)
  5929. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
  5930. s start)
  5931. (setq var (or (cdr (assoc (match-string 4 s)
  5932. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  5933. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5934. 'eval)
  5935. c (or (match-string 3 s) "")
  5936. opt (match-beginning 1)
  5937. start (1+ (match-beginning 0)))
  5938. (if (equal var 'time) (setq org-prefix-has-time t))
  5939. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5940. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5941. (setq f (concat "%" (match-string 2 s) "s"))
  5942. (when (equal var 'category)
  5943. (setq org-prefix-category-length
  5944. (floor (abs (string-to-number (match-string 2 s)))))
  5945. (setq org-prefix-category-max-length
  5946. (let ((x (match-string 2 s)))
  5947. (save-match-data
  5948. (if (string-match "\\.[0-9]+" x)
  5949. (string-to-number (substring (match-string 0 x) 1)))))))
  5950. (if (eq var 'eval)
  5951. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5952. (if opt
  5953. (setq varform
  5954. `(if (equal "" ,var)
  5955. ""
  5956. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5957. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5958. (setq s (replace-match "%s" t nil s))
  5959. (push varform vars))
  5960. (setq vars (nreverse vars))
  5961. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5962. (setq org-prefix-format-compiled
  5963. (list
  5964. `((org-prefix-has-time ,org-prefix-has-time)
  5965. (org-prefix-has-tag ,org-prefix-has-tag)
  5966. (org-prefix-category-length ,org-prefix-category-length)
  5967. (org-prefix-has-effort ,org-prefix-has-effort))
  5968. `(format ,s ,@vars))))))
  5969. (defun org-set-sorting-strategy (key)
  5970. (if (symbolp (car org-agenda-sorting-strategy))
  5971. ;; the old format
  5972. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5973. (setq org-agenda-sorting-strategy-selected
  5974. (or (cdr (assq key org-agenda-sorting-strategy))
  5975. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5976. '(time-up category-keep priority-down)))))
  5977. (defun org-get-time-of-day (s &optional string mod24)
  5978. "Check string S for a time of day.
  5979. If found, return it as a military time number between 0 and 2400.
  5980. If not found, return nil.
  5981. The optional STRING argument forces conversion into a 5 character wide string
  5982. HH:MM."
  5983. (save-match-data
  5984. (when
  5985. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5986. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5987. (let* ((h (string-to-number (match-string 1 s)))
  5988. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5989. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5990. (am-p (equal ampm "am"))
  5991. (h1 (cond ((not ampm) h)
  5992. ((= h 12) (if am-p 0 12))
  5993. (t (+ h (if am-p 0 12)))))
  5994. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5995. (mod h1 24) h1))
  5996. (t0 (+ (* 100 h2) m))
  5997. (t1 (concat (if (>= h1 24) "+" " ")
  5998. (if (and org-agenda-time-leading-zero
  5999. (< t0 1000)) "0" "")
  6000. (if (< t0 100) "0" "")
  6001. (if (< t0 10) "0" "")
  6002. (int-to-string t0))))
  6003. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  6004. (defvar org-agenda-before-sorting-filter-function nil
  6005. "Function to be applied to agenda items prior to sorting.
  6006. Prior to sorting also means just before they are inserted into the agenda.
  6007. To aid sorting, you may revisit the original entries and add more text
  6008. properties which will later be used by the sorting functions.
  6009. The function should take a string argument, an agenda line.
  6010. It has access to the text properties in that line, which contain among
  6011. other things, the property `org-hd-marker' that points to the entry
  6012. where the line comes from. Note that not all lines going into the agenda
  6013. have this property, only most.
  6014. The function should return the modified string. It is probably best
  6015. to ONLY change text properties.
  6016. You can also use this function as a filter, by returning nil for lines
  6017. you don't want to have in the agenda at all. For this application, you
  6018. could bind the variable in the options section of a custom command.")
  6019. (defun org-agenda-finalize-entries (list &optional nosort)
  6020. "Sort and concatenate the agenda items."
  6021. (setq list (mapcar 'org-agenda-highlight-todo list))
  6022. (if nosort
  6023. list
  6024. (when org-agenda-before-sorting-filter-function
  6025. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  6026. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  6027. (defun org-agenda-highlight-todo (x)
  6028. (let ((org-done-keywords org-done-keywords-for-agenda)
  6029. (case-fold-search nil)
  6030. re)
  6031. (if (eq x 'line)
  6032. (save-excursion
  6033. (beginning-of-line 1)
  6034. (setq re (org-get-at-bol 'org-todo-regexp))
  6035. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  6036. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  6037. (add-text-properties (match-beginning 0) (match-end 1)
  6038. (list 'face (org-get-todo-face 1)))
  6039. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  6040. (delete-region (match-beginning 1) (1- (match-end 0)))
  6041. (goto-char (match-beginning 1))
  6042. (insert (format org-agenda-todo-keyword-format s)))))
  6043. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  6044. (setq re (get-text-property 0 'org-todo-regexp x))
  6045. (when (and re
  6046. ;; Test `pl' because if there's no heading content,
  6047. ;; there's no point matching to highlight. Note
  6048. ;; that if we didn't test `pl' first, and there
  6049. ;; happened to be no keyword from `org-todo-regexp'
  6050. ;; on this heading line, then the `equal' comparison
  6051. ;; afterwards would spuriously succeed in the case
  6052. ;; where `pl' is nil -- causing an args-out-of-range
  6053. ;; error when we try to add text properties to text
  6054. ;; that isn't there.
  6055. pl
  6056. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  6057. x pl) pl))
  6058. (add-text-properties
  6059. (or (match-end 1) (match-end 0)) (match-end 0)
  6060. (list 'face (org-get-todo-face (match-string 2 x)))
  6061. x)
  6062. (when (match-end 1)
  6063. (setq x (concat (substring x 0 (match-end 1))
  6064. (format org-agenda-todo-keyword-format
  6065. (match-string 2 x))
  6066. (org-add-props " " (text-properties-at 0 x))
  6067. (substring x (match-end 3)))))))
  6068. x)))
  6069. (defsubst org-cmp-priority (a b)
  6070. "Compare the priorities of string A and B."
  6071. (let ((pa (or (get-text-property 1 'priority a) 0))
  6072. (pb (or (get-text-property 1 'priority b) 0)))
  6073. (cond ((> pa pb) +1)
  6074. ((< pa pb) -1))))
  6075. (defsubst org-cmp-effort (a b)
  6076. "Compare the effort values of string A and B."
  6077. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  6078. (ea (or (get-text-property 1 'effort-minutes a) def))
  6079. (eb (or (get-text-property 1 'effort-minutes b) def)))
  6080. (cond ((> ea eb) +1)
  6081. ((< ea eb) -1))))
  6082. (defsubst org-cmp-category (a b)
  6083. "Compare the string values of categories of strings A and B."
  6084. (let ((ca (or (get-text-property 1 'org-category a) ""))
  6085. (cb (or (get-text-property 1 'org-category b) "")))
  6086. (cond ((string-lessp ca cb) -1)
  6087. ((string-lessp cb ca) +1))))
  6088. (defsubst org-cmp-todo-state (a b)
  6089. "Compare the todo states of strings A and B."
  6090. (let* ((ma (or (get-text-property 1 'org-marker a)
  6091. (get-text-property 1 'org-hd-marker a)))
  6092. (mb (or (get-text-property 1 'org-marker b)
  6093. (get-text-property 1 'org-hd-marker b)))
  6094. (fa (and ma (marker-buffer ma)))
  6095. (fb (and mb (marker-buffer mb)))
  6096. (todo-kwds
  6097. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  6098. (and fb (with-current-buffer fb org-todo-keywords-1))))
  6099. (ta (or (get-text-property 1 'todo-state a) ""))
  6100. (tb (or (get-text-property 1 'todo-state b) ""))
  6101. (la (- (length (member ta todo-kwds))))
  6102. (lb (- (length (member tb todo-kwds))))
  6103. (donepa (member ta org-done-keywords-for-agenda))
  6104. (donepb (member tb org-done-keywords-for-agenda)))
  6105. (cond ((and donepa (not donepb)) -1)
  6106. ((and (not donepa) donepb) +1)
  6107. ((< la lb) -1)
  6108. ((< lb la) +1))))
  6109. (defsubst org-cmp-alpha (a b)
  6110. "Compare the headlines, alphabetically."
  6111. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  6112. (plb (text-property-any 0 (length b) 'org-heading t b))
  6113. (ta (and pla (substring a pla)))
  6114. (tb (and plb (substring b plb))))
  6115. (when pla
  6116. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  6117. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  6118. (setq ta (substring ta (match-end 0))))
  6119. (setq ta (downcase ta)))
  6120. (when plb
  6121. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  6122. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  6123. (setq tb (substring tb (match-end 0))))
  6124. (setq tb (downcase tb)))
  6125. (cond ((not ta) +1)
  6126. ((not tb) -1)
  6127. ((string-lessp ta tb) -1)
  6128. ((string-lessp tb ta) +1))))
  6129. (defsubst org-cmp-tag (a b)
  6130. "Compare the string values of the first tags of A and B."
  6131. (let ((ta (car (last (get-text-property 1 'tags a))))
  6132. (tb (car (last (get-text-property 1 'tags b)))))
  6133. (cond ((not ta) +1)
  6134. ((not tb) -1)
  6135. ((string-lessp ta tb) -1)
  6136. ((string-lessp tb ta) +1))))
  6137. (defsubst org-cmp-time (a b)
  6138. "Compare the time-of-day values of strings A and B."
  6139. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  6140. (ta (or (get-text-property 1 'time-of-day a) def))
  6141. (tb (or (get-text-property 1 'time-of-day b) def)))
  6142. (cond ((< ta tb) -1)
  6143. ((< tb ta) +1))))
  6144. (defsubst org-cmp-habit-p (a b)
  6145. "Compare the todo states of strings A and B."
  6146. (let ((ha (get-text-property 1 'org-habit-p a))
  6147. (hb (get-text-property 1 'org-habit-p b)))
  6148. (cond ((and ha (not hb)) -1)
  6149. ((and (not ha) hb) +1))))
  6150. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  6151. (defun org-entries-lessp (a b)
  6152. "Predicate for sorting agenda entries."
  6153. ;; The following variables will be used when the form is evaluated.
  6154. ;; So even though the compiler complains, keep them.
  6155. (let* ((ss org-agenda-sorting-strategy-selected)
  6156. (time-up (and (org-em 'time-up 'time-down ss)
  6157. (org-cmp-time a b)))
  6158. (time-down (if time-up (- time-up) nil))
  6159. (priority-up (and (org-em 'priority-up 'priority-down ss)
  6160. (org-cmp-priority a b)))
  6161. (priority-down (if priority-up (- priority-up) nil))
  6162. (effort-up (and (org-em 'effort-up 'effort-down ss)
  6163. (org-cmp-effort a b)))
  6164. (effort-down (if effort-up (- effort-up) nil))
  6165. (category-up (and (or (org-em 'category-up 'category-down ss)
  6166. (memq 'category-keep ss))
  6167. (org-cmp-category a b)))
  6168. (category-down (if category-up (- category-up) nil))
  6169. (category-keep (if category-up +1 nil))
  6170. (tag-up (and (org-em 'tag-up 'tag-down ss)
  6171. (org-cmp-tag a b)))
  6172. (tag-down (if tag-up (- tag-up) nil))
  6173. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  6174. (org-cmp-todo-state a b)))
  6175. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  6176. (habit-up (and (org-em 'habit-up 'habit-down ss)
  6177. (org-cmp-habit-p a b)))
  6178. (habit-down (if habit-up (- habit-up) nil))
  6179. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  6180. (org-cmp-alpha a b)))
  6181. (alpha-down (if alpha-up (- alpha-up) nil))
  6182. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  6183. user-defined-up user-defined-down)
  6184. (if (and need-user-cmp org-agenda-cmp-user-defined
  6185. (functionp org-agenda-cmp-user-defined))
  6186. (setq user-defined-up
  6187. (funcall org-agenda-cmp-user-defined a b)
  6188. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  6189. (cdr (assoc
  6190. (eval (cons 'or org-agenda-sorting-strategy-selected))
  6191. '((-1 . t) (1 . nil) (nil . nil))))))
  6192. ;;; Agenda restriction lock
  6193. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  6194. "Overlay to mark the headline to which agenda commands are restricted.")
  6195. (overlay-put org-agenda-restriction-lock-overlay
  6196. 'face 'org-agenda-restriction-lock)
  6197. (overlay-put org-agenda-restriction-lock-overlay
  6198. 'help-echo "Agendas are currently limited to this subtree.")
  6199. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6200. (defun org-agenda-set-restriction-lock (&optional type)
  6201. "Set restriction lock for agenda, to current subtree or file.
  6202. Restriction will be the file if TYPE is `file', or if type is the
  6203. universal prefix '(4), or if the cursor is before the first headline
  6204. in the file. Otherwise, restriction will be to the current subtree."
  6205. (interactive "P")
  6206. (and (equal type '(4)) (setq type 'file))
  6207. (setq type (cond
  6208. (type type)
  6209. ((org-at-heading-p) 'subtree)
  6210. ((condition-case nil (org-back-to-heading t) (error nil))
  6211. 'subtree)
  6212. (t 'file)))
  6213. (if (eq type 'subtree)
  6214. (progn
  6215. (setq org-agenda-restrict t)
  6216. (setq org-agenda-overriding-restriction 'subtree)
  6217. (put 'org-agenda-files 'org-restrict
  6218. (list (buffer-file-name (buffer-base-buffer))))
  6219. (org-back-to-heading t)
  6220. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6221. (move-marker org-agenda-restrict-begin (point))
  6222. (move-marker org-agenda-restrict-end
  6223. (save-excursion (org-end-of-subtree t)))
  6224. (message "Locking agenda restriction to subtree"))
  6225. (put 'org-agenda-files 'org-restrict
  6226. (list (buffer-file-name (buffer-base-buffer))))
  6227. (setq org-agenda-restrict nil)
  6228. (setq org-agenda-overriding-restriction 'file)
  6229. (move-marker org-agenda-restrict-begin nil)
  6230. (move-marker org-agenda-restrict-end nil)
  6231. (message "Locking agenda restriction to file"))
  6232. (setq current-prefix-arg nil)
  6233. (org-agenda-maybe-redo))
  6234. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6235. "Remove the agenda restriction lock."
  6236. (interactive "P")
  6237. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6238. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6239. (setq org-agenda-overriding-restriction nil)
  6240. (setq org-agenda-restrict nil)
  6241. (put 'org-agenda-files 'org-restrict nil)
  6242. (move-marker org-agenda-restrict-begin nil)
  6243. (move-marker org-agenda-restrict-end nil)
  6244. (setq current-prefix-arg nil)
  6245. (message "Agenda restriction lock removed")
  6246. (or noupdate (org-agenda-maybe-redo)))
  6247. (defun org-agenda-maybe-redo ()
  6248. "If there is any window showing the agenda view, update it."
  6249. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6250. (w0 (selected-window)))
  6251. (when w
  6252. (select-window w)
  6253. (org-agenda-redo)
  6254. (select-window w0)
  6255. (if org-agenda-overriding-restriction
  6256. (message "Agenda view shifted to new %s restriction"
  6257. org-agenda-overriding-restriction)
  6258. (message "Agenda restriction lock removed")))))
  6259. ;;; Agenda commands
  6260. (defun org-agenda-check-type (error &rest types)
  6261. "Check if agenda buffer is of allowed type.
  6262. If ERROR is non-nil, throw an error, otherwise just return nil."
  6263. (if (not org-agenda-type)
  6264. (error "No Org agenda currently displayed")
  6265. (if (memq org-agenda-type types)
  6266. t
  6267. (if error
  6268. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6269. nil))))
  6270. (defun org-agenda-Quit (&optional arg)
  6271. "Exit agenda by removing the window or the buffer."
  6272. (interactive)
  6273. (if org-agenda-columns-active
  6274. (org-columns-quit)
  6275. (let ((buf (current-buffer)))
  6276. (if (eq org-agenda-window-setup 'other-frame)
  6277. (progn
  6278. (org-agenda-reset-markers)
  6279. (kill-buffer buf)
  6280. (org-columns-remove-overlays)
  6281. (setq org-agenda-archives-mode nil)
  6282. (delete-frame))
  6283. (and (not (eq org-agenda-window-setup 'current-window))
  6284. (not (one-window-p))
  6285. (delete-window))
  6286. (org-agenda-reset-markers)
  6287. (kill-buffer buf)
  6288. (org-columns-remove-overlays)
  6289. (setq org-agenda-archives-mode nil)))
  6290. ;; Maybe restore the pre-agenda window configuration.
  6291. (and org-agenda-restore-windows-after-quit
  6292. (not (eq org-agenda-window-setup 'other-frame))
  6293. org-agenda-pre-window-conf
  6294. (set-window-configuration org-agenda-pre-window-conf)
  6295. (setq org-agenda-pre-window-conf nil))))
  6296. (defun org-agenda-quit ()
  6297. "Exit agenda by killing agenda buffer or burying it when
  6298. `org-agenda-sticky' is non-NIL"
  6299. (interactive)
  6300. (if (and (eq org-indirect-buffer-display 'other-window)
  6301. org-last-indirect-buffer)
  6302. (delete-window (get-buffer-window org-last-indirect-buffer)))
  6303. (if org-agenda-columns-active
  6304. (org-columns-quit)
  6305. (if org-agenda-sticky
  6306. (let ((buf (current-buffer)))
  6307. (if (eq org-agenda-window-setup 'other-frame)
  6308. (progn
  6309. (delete-frame))
  6310. (and (not (eq org-agenda-window-setup 'current-window))
  6311. (not (one-window-p))
  6312. (delete-window)))
  6313. (with-current-buffer buf
  6314. (bury-buffer)
  6315. ;; Maybe restore the pre-agenda window configuration.
  6316. (and org-agenda-restore-windows-after-quit
  6317. (not (eq org-agenda-window-setup 'other-frame))
  6318. org-agenda-pre-window-conf
  6319. (set-window-configuration org-agenda-pre-window-conf)
  6320. (setq org-agenda-pre-window-conf nil))))
  6321. (org-agenda-Quit))))
  6322. (defun org-agenda-exit ()
  6323. "Exit agenda by removing the window or the buffer.
  6324. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6325. Org-mode buffers visited directly by the user will not be touched."
  6326. (interactive)
  6327. (org-release-buffers org-agenda-new-buffers)
  6328. (setq org-agenda-new-buffers nil)
  6329. (org-agenda-Quit))
  6330. (defun org-agenda-kill-all-agenda-buffers ()
  6331. "Kill all buffers in `org-agena-mode'.
  6332. This is used when toggling sticky agendas. You can also explicitly invoke it
  6333. with `C-c a C-k'."
  6334. (interactive)
  6335. (let (blist)
  6336. (dolist (buf (buffer-list))
  6337. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6338. (push buf blist)))
  6339. (mapc 'kill-buffer blist)))
  6340. (defun org-agenda-execute (arg)
  6341. "Execute another agenda command, keeping same window.
  6342. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6343. in the agenda."
  6344. (interactive "P")
  6345. (let ((org-agenda-window-setup 'current-window))
  6346. (org-agenda arg)))
  6347. (defun org-agenda-redo (&optional all)
  6348. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6349. (interactive "P")
  6350. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6351. (cpa (unless (eq all t) current-prefix-arg))
  6352. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6353. (org-agenda-sticky nil)
  6354. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6355. org-agenda-buffer-name))
  6356. (org-agenda-keep-modes t)
  6357. (tag-filter org-agenda-tag-filter)
  6358. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6359. (top-cat-filter org-agenda-top-category-filter)
  6360. (cat-filter org-agenda-category-filter)
  6361. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6362. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6363. (cols org-agenda-columns-active)
  6364. (line (org-current-line))
  6365. (window-line (- line (org-current-line (window-start))))
  6366. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6367. (redo-cmd (get-text-property p 'org-redo-cmd))
  6368. (last-args (get-text-property p 'org-last-args))
  6369. (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
  6370. (org-agenda-overriding-cmd-arguments
  6371. (unless (eq all t)
  6372. (cond ((listp last-args)
  6373. (cons (or cpa (car last-args)) (cdr last-args)))
  6374. ((stringp last-args)
  6375. last-args))))
  6376. (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
  6377. (put 'org-agenda-tag-filter :preset-filter nil)
  6378. (put 'org-agenda-category-filter :preset-filter nil)
  6379. (and cols (org-columns-quit))
  6380. (message "Rebuilding agenda buffer...")
  6381. (if serie-redo-cmd
  6382. (eval serie-redo-cmd)
  6383. (org-let lprops '(eval redo-cmd)))
  6384. (setq org-agenda-undo-list nil
  6385. org-agenda-pending-undo-list nil)
  6386. (message "Rebuilding agenda buffer...done")
  6387. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6388. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6389. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6390. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6391. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6392. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6393. (org-goto-line line)
  6394. (recenter window-line)))
  6395. (defvar org-global-tags-completion-table nil)
  6396. (defvar org-agenda-filter-form nil)
  6397. (defvar org-agenda-filtered-by-category nil)
  6398. (defun org-agenda-filter-by-category (strip)
  6399. "Keep only those lines in the agenda buffer that have a specific category.
  6400. The category is that of the current line."
  6401. (interactive "P")
  6402. (if (and org-agenda-filtered-by-category
  6403. org-agenda-category-filter)
  6404. (org-agenda-filter-show-all-cat)
  6405. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6406. (if cat (org-agenda-filter-apply
  6407. (list (concat (if strip "-" "+") cat)) 'category)
  6408. (error "No category at point")))))
  6409. (defun org-find-top-category (&optional pos)
  6410. (save-excursion
  6411. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6412. (if pos (goto-char pos))
  6413. ;; Skip up to the topmost parent
  6414. (while (ignore-errors (outline-up-heading 1) t))
  6415. (ignore-errors
  6416. (nth 4 (org-heading-components))))))
  6417. (defvar org-agenda-filtered-by-top-category nil)
  6418. (defun org-agenda-filter-by-top-category (strip)
  6419. "Keep only those lines in the agenda buffer that have a specific category.
  6420. The category is that of the current line."
  6421. (interactive "P")
  6422. (if org-agenda-filtered-by-top-category
  6423. (progn
  6424. (setq org-agenda-filtered-by-top-category nil
  6425. org-agenda-top-category-filter nil)
  6426. (org-agenda-filter-show-all-cat))
  6427. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6428. (if cat (org-agenda-filter-top-category-apply cat strip)
  6429. (error "No top-level category at point")))))
  6430. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6431. "Keep only those lines in the agenda buffer that have a specific tag.
  6432. The tag is selected with its fast selection letter, as configured.
  6433. With prefix argument STRIP, remove all lines that do have the tag.
  6434. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6435. used to narrow the search - the interactive user can also press `-' or `+'
  6436. to switch to narrowing."
  6437. (interactive "P")
  6438. (let* ((alist org-tag-alist-for-agenda)
  6439. (tag-chars (mapconcat
  6440. (lambda (x) (if (and (not (symbolp (car x)))
  6441. (cdr x))
  6442. (char-to-string (cdr x))
  6443. ""))
  6444. alist ""))
  6445. (efforts (org-split-string
  6446. (or (cdr (assoc (concat org-effort-property "_ALL")
  6447. org-global-properties))
  6448. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6449. "")))
  6450. (effort-op org-agenda-filter-effort-default-operator)
  6451. (effort-prompt "")
  6452. (inhibit-read-only t)
  6453. (current org-agenda-tag-filter)
  6454. maybe-refresh a n tag)
  6455. (unless char
  6456. (message
  6457. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6458. (if narrow "Narrow" "Filter") tag-chars
  6459. (if org-agenda-auto-exclude-function "[RET], " ""))
  6460. (setq char (read-char-exclusive)))
  6461. (when (member char '(?+ ?-))
  6462. ;; Narrowing down
  6463. (cond ((equal char ?-) (setq strip t narrow t))
  6464. ((equal char ?+) (setq strip nil narrow t)))
  6465. (message
  6466. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6467. (setq char (read-char-exclusive)))
  6468. (when (member char '(?< ?> ?= ??))
  6469. ;; An effort operator
  6470. (setq effort-op (char-to-string char))
  6471. (setq alist nil) ; to make sure it will be interpreted as effort.
  6472. (unless (equal char ??)
  6473. (loop for i from 0 to 9 do
  6474. (setq effort-prompt
  6475. (concat
  6476. effort-prompt " ["
  6477. (if (= i 9) "0" (int-to-string (1+ i)))
  6478. "]" (nth i efforts))))
  6479. (message "Effort%s: %s " effort-op effort-prompt)
  6480. (setq char (read-char-exclusive))
  6481. (when (or (< char ?0) (> char ?9))
  6482. (error "Need 1-9,0 to select effort"))))
  6483. (when (equal char ?\t)
  6484. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6485. (org-set-local 'org-global-tags-completion-table
  6486. (org-global-tags-completion-table)))
  6487. (let ((completion-ignore-case t))
  6488. (setq tag (org-icompleting-read
  6489. "Tag: " org-global-tags-completion-table))))
  6490. (cond
  6491. ((equal char ?\r)
  6492. (org-agenda-filter-show-all-tag)
  6493. (when org-agenda-auto-exclude-function
  6494. (setq org-agenda-tag-filter '())
  6495. (dolist (tag (org-agenda-get-represented-tags))
  6496. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6497. (if modifier
  6498. (push modifier org-agenda-tag-filter))))
  6499. (if (not (null org-agenda-tag-filter))
  6500. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6501. (setq maybe-refresh t))
  6502. ((equal char ?/)
  6503. (org-agenda-filter-show-all-tag)
  6504. (when (get 'org-agenda-tag-filter :preset-filter)
  6505. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6506. (setq maybe-refresh t))
  6507. ((equal char ?. )
  6508. (setq org-agenda-tag-filter
  6509. (mapcar (lambda(tag) (concat "+" tag))
  6510. (org-get-at-bol 'tags)))
  6511. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6512. (setq maybe-refresh t))
  6513. ((or (equal char ?\ )
  6514. (setq a (rassoc char alist))
  6515. (and (>= char ?0) (<= char ?9)
  6516. (setq n (if (= char ?0) 9 (- char ?0 1))
  6517. tag (concat effort-op (nth n efforts))
  6518. a (cons tag nil)))
  6519. (and (= char ??)
  6520. (setq tag "?eff")
  6521. a (cons tag nil))
  6522. (and tag (setq a (cons tag nil))))
  6523. (org-agenda-filter-show-all-tag)
  6524. (setq tag (car a))
  6525. (setq org-agenda-tag-filter
  6526. (cons (concat (if strip "-" "+") tag)
  6527. (if narrow current nil)))
  6528. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6529. (setq maybe-refresh t))
  6530. (t (error "Invalid tag selection character %c" char)))
  6531. (when (and maybe-refresh
  6532. (eq org-agenda-clockreport-mode 'with-filter))
  6533. (org-agenda-redo))))
  6534. (defun org-agenda-get-represented-tags ()
  6535. "Get a list of all tags currently represented in the agenda."
  6536. (let (p tags)
  6537. (save-excursion
  6538. (goto-char (point-min))
  6539. (while (setq p (next-single-property-change (point) 'tags))
  6540. (goto-char p)
  6541. (mapc (lambda (x) (add-to-list 'tags x))
  6542. (get-text-property (point) 'tags))))
  6543. tags))
  6544. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6545. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6546. (interactive "P")
  6547. (org-agenda-filter-by-tag strip char 'refine))
  6548. (defun org-agenda-filter-make-matcher ()
  6549. "Create the form that tests a line for agenda filter."
  6550. (let (f f1)
  6551. ;; first compute the tag-filter matcher
  6552. (dolist (x (delete-dups
  6553. (append (get 'org-agenda-tag-filter
  6554. :preset-filter) org-agenda-tag-filter)))
  6555. (if (member x '("-" "+"))
  6556. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6557. (if (string-match "[<=>?]" x)
  6558. (setq f1 (org-agenda-filter-effort-form x))
  6559. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6560. (if (equal (string-to-char x) ?-)
  6561. (setq f1 (list 'not f1))))
  6562. (push f1 f))
  6563. ;; then compute the category-filter matcher
  6564. (dolist (x (delete-dups
  6565. (append (get 'org-agenda-category-filter
  6566. :preset-filter) org-agenda-category-filter)))
  6567. (if (equal "-" (substring x 0 1))
  6568. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6569. (setq f1 (list 'equal (substring x 1) 'cat)))
  6570. (push f1 f))
  6571. (cons 'and (nreverse f))))
  6572. (defun org-agenda-filter-effort-form (e)
  6573. "Return the form to compare the effort of the current line with what E says.
  6574. E looks like \"+<2:25\"."
  6575. (let (op)
  6576. (setq e (substring e 1))
  6577. (setq op (string-to-char e) e (substring e 1))
  6578. (setq op (cond ((equal op ?<) '<=)
  6579. ((equal op ?>) '>=)
  6580. ((equal op ??) op)
  6581. (t '=)))
  6582. (list 'org-agenda-compare-effort (list 'quote op)
  6583. (org-duration-string-to-minutes e))))
  6584. (defun org-agenda-compare-effort (op value)
  6585. "Compare the effort of the current line with VALUE, using OP.
  6586. If the line does not have an effort defined, return nil."
  6587. (let ((eff (org-get-at-bol 'effort-minutes)))
  6588. (if (equal op ??)
  6589. (not eff)
  6590. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6591. value))))
  6592. (defun org-agenda-filter-apply (filter type)
  6593. "Set FILTER as the new agenda filter and apply it."
  6594. (let (tags cat)
  6595. (if (eq type 'tag)
  6596. (setq org-agenda-tag-filter filter)
  6597. (setq org-agenda-category-filter filter))
  6598. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6599. (if (and (eq type 'category)
  6600. (not (equal (substring (car filter) 0 1) "-")))
  6601. ;; Only set `org-agenda-filtered-by-category' to t
  6602. ;; when a unique category is used as the filter
  6603. (setq org-agenda-filtered-by-category t))
  6604. (org-agenda-set-mode-name)
  6605. (save-excursion
  6606. (goto-char (point-min))
  6607. (while (not (eobp))
  6608. (if (org-get-at-bol 'org-marker)
  6609. (progn
  6610. (setq tags (org-get-at-bol 'tags) ; used in eval
  6611. cat (get-text-property (point) 'org-category))
  6612. (if (not (eval org-agenda-filter-form))
  6613. (org-agenda-filter-hide-line type))
  6614. (beginning-of-line 2))
  6615. (beginning-of-line 2))))
  6616. (if (get-char-property (point) 'invisible)
  6617. (ignore-errors (org-agenda-previous-line)))))
  6618. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6619. "Set FILTER as the new agenda filter and apply it."
  6620. (org-agenda-set-mode-name)
  6621. (save-excursion
  6622. (goto-char (point-min))
  6623. (while (not (eobp))
  6624. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6625. (topcat (and pos (org-find-top-category pos))))
  6626. (if (and topcat (funcall (if negative 'identity 'not)
  6627. (string= category topcat)))
  6628. (org-agenda-filter-hide-line 'category)))
  6629. (beginning-of-line 2)))
  6630. (if (get-char-property (point) 'invisible)
  6631. (org-agenda-previous-line))
  6632. (setq org-agenda-top-category-filter category
  6633. org-agenda-filtered-by-top-category t))
  6634. (defun org-agenda-filter-hide-line (type)
  6635. (let (ov)
  6636. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6637. (point-at-eol)))
  6638. (overlay-put ov 'invisible t)
  6639. (overlay-put ov 'type type)
  6640. (if (eq type 'tag)
  6641. (push ov org-agenda-tag-filter-overlays)
  6642. (push ov org-agenda-cat-filter-overlays))))
  6643. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6644. (setq pos (or pos (point)))
  6645. (save-excursion
  6646. (dolist (ov (overlays-at pos))
  6647. (when (and (overlay-get ov 'invisible)
  6648. (eq (overlay-get ov 'type) 'tag))
  6649. (goto-char pos)
  6650. (if (< (overlay-start ov) (point-at-eol))
  6651. (move-overlay ov (point-at-eol)
  6652. (overlay-end ov)))))))
  6653. (defun org-agenda-filter-show-all-tag nil
  6654. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6655. (setq org-agenda-tag-filter-overlays nil
  6656. org-agenda-tag-filter nil
  6657. org-agenda-filter-form nil)
  6658. (org-agenda-set-mode-name))
  6659. (defun org-agenda-filter-show-all-cat nil
  6660. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6661. (setq org-agenda-cat-filter-overlays nil
  6662. org-agenda-filtered-by-category nil
  6663. org-agenda-category-filter nil
  6664. org-agenda-filter-form nil)
  6665. (org-agenda-set-mode-name))
  6666. (defun org-agenda-manipulate-query-add ()
  6667. "Manipulate the query by adding a search term with positive selection.
  6668. Positive selection means the term must be matched for selection of an entry."
  6669. (interactive)
  6670. (org-agenda-manipulate-query ?\[))
  6671. (defun org-agenda-manipulate-query-subtract ()
  6672. "Manipulate the query by adding a search term with negative selection.
  6673. Negative selection means term must not be matched for selection of an entry."
  6674. (interactive)
  6675. (org-agenda-manipulate-query ?\]))
  6676. (defun org-agenda-manipulate-query-add-re ()
  6677. "Manipulate the query by adding a search regexp with positive selection.
  6678. Positive selection means the regexp must match for selection of an entry."
  6679. (interactive)
  6680. (org-agenda-manipulate-query ?\{))
  6681. (defun org-agenda-manipulate-query-subtract-re ()
  6682. "Manipulate the query by adding a search regexp with negative selection.
  6683. Negative selection means regexp must not match for selection of an entry."
  6684. (interactive)
  6685. (org-agenda-manipulate-query ?\}))
  6686. (defun org-agenda-manipulate-query (char)
  6687. (cond
  6688. ((memq org-agenda-type '(timeline agenda))
  6689. (let ((org-agenda-include-inactive-timestamps t))
  6690. (org-agenda-redo))
  6691. (message "Display now includes inactive timestamps as well"))
  6692. ((eq org-agenda-type 'search)
  6693. (org-add-to-string
  6694. 'org-agenda-query-string
  6695. (if org-agenda-last-search-view-search-was-boolean
  6696. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6697. (?\{ . " +{}") (?\} . " -{}"))))
  6698. " "))
  6699. (setq org-agenda-redo-command
  6700. (list 'org-search-view
  6701. (car (get-text-property (min (1- (point-max)) (point))
  6702. 'org-last-args))
  6703. org-agenda-query-string
  6704. (+ (length org-agenda-query-string)
  6705. (if (member char '(?\{ ?\})) 0 1))))
  6706. (set-register org-agenda-query-register org-agenda-query-string)
  6707. (let ((org-agenda-overriding-arguments
  6708. (cdr org-agenda-redo-command)))
  6709. (org-agenda-redo)))
  6710. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6711. org-agenda-type))))
  6712. (defun org-add-to-string (var string)
  6713. (set var (concat (symbol-value var) string)))
  6714. (defun org-agenda-goto-date (span)
  6715. "Jump to DATE in agenda."
  6716. (interactive "P")
  6717. (let* ((org-read-date-prefer-future
  6718. (eval org-agenda-jump-prefer-future))
  6719. (date (org-read-date))
  6720. (org-agenda-sticky-orig org-agenda-sticky)
  6721. (org-agenda-buffer-tmp-name (buffer-name))
  6722. (args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6723. (0-arg (or current-prefix-arg (car args)))
  6724. (2-arg (nth 2 args))
  6725. (newcmd (list 'org-agenda-list 0-arg date
  6726. (org-agenda-span-to-ndays 2-arg)))
  6727. (newargs (cdr newcmd))
  6728. (inhibit-read-only t)
  6729. org-agenda-sticky)
  6730. (if (not (org-agenda-check-type t 'agenda))
  6731. (error "Not available in non-agenda blocks")
  6732. (add-text-properties (point-min) (point-max)
  6733. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6734. (org-agenda-redo)
  6735. (setq org-agenda-sticky org-agenda-sticky-orig
  6736. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6737. (defun org-agenda-goto-today ()
  6738. "Go to today."
  6739. (interactive)
  6740. (org-agenda-check-type t 'timeline 'agenda)
  6741. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6742. (curspan (nth 2 args))
  6743. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6744. (cond
  6745. (tdpos (goto-char tdpos))
  6746. ((eq org-agenda-type 'agenda)
  6747. (let* ((sd (org-agenda-compute-starting-span
  6748. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6749. (org-agenda-overriding-arguments args))
  6750. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6751. (org-agenda-redo)
  6752. (org-agenda-find-same-or-today-or-agenda)))
  6753. (t (error "Cannot find today")))))
  6754. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6755. (goto-char
  6756. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6757. (text-property-any (point-min) (point-max) 'org-today t)
  6758. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6759. (and (get-text-property (min (1- (point-max)) (point)) 'org-serie)
  6760. (org-agenda-goto-block-beginning))
  6761. (point-min))))
  6762. (defun org-agenda-goto-block-beginning ()
  6763. "Go the agenda block beginning."
  6764. (interactive)
  6765. (if (not (derived-mode-p 'org-agenda-mode))
  6766. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6767. (let (dest)
  6768. (save-excursion
  6769. (unless (looking-at "\\'")
  6770. (forward-char))
  6771. (let* ((prop 'org-agenda-structural-header)
  6772. (p (previous-single-property-change (point) prop))
  6773. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6774. (1- (point))) prop)))
  6775. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6776. (if (not dest)
  6777. (error "Cannot find the beginning of the blog")
  6778. (goto-char dest)
  6779. (move-beginning-of-line 1)))))
  6780. (defun org-agenda-later (arg)
  6781. "Go forward in time by the current span.
  6782. With prefix ARG, go forward that many times the current span."
  6783. (interactive "p")
  6784. (org-agenda-check-type t 'agenda)
  6785. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6786. (span (or (nth 2 args) org-agenda-current-span))
  6787. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6788. (greg (calendar-gregorian-from-absolute sd))
  6789. (cnt (org-get-at-bol 'org-day-cnt))
  6790. greg2)
  6791. (cond
  6792. ((numberp span)
  6793. (setq sd (+ (* span arg) sd)))
  6794. ((eq span 'day)
  6795. (setq sd (+ arg sd)))
  6796. ((eq span 'week)
  6797. (setq sd (+ (* 7 arg) sd)))
  6798. ((eq span 'month)
  6799. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6800. sd (calendar-absolute-from-gregorian greg2))
  6801. (setcar greg2 (1+ (car greg2))))
  6802. ((eq span 'year)
  6803. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6804. sd (calendar-absolute-from-gregorian greg2))
  6805. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6806. (t
  6807. (setq sd (+ (* span arg) sd))))
  6808. (let ((org-agenda-overriding-cmd
  6809. ;; `cmd' may have been set by `org-agenda-run-series' which
  6810. ;; uses `org-agenda-overriding-cmd' to decide whether
  6811. ;; overriding is allowed for `cmd'
  6812. (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
  6813. (org-agenda-overriding-arguments
  6814. (list (car args) sd span)))
  6815. (org-agenda-redo)
  6816. (org-agenda-find-same-or-today-or-agenda cnt))))
  6817. (defun org-agenda-earlier (arg)
  6818. "Go backward in time by the current span.
  6819. With prefix ARG, go backward that many times the current span."
  6820. (interactive "p")
  6821. (org-agenda-later (- arg)))
  6822. (defun org-agenda-view-mode-dispatch ()
  6823. "Call one of the view mode commands."
  6824. (interactive)
  6825. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6826. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6827. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6828. (let ((a (read-char-exclusive)))
  6829. (case a
  6830. (?\ (call-interactively 'org-agenda-reset-view))
  6831. (?d (call-interactively 'org-agenda-day-view))
  6832. (?w (call-interactively 'org-agenda-week-view))
  6833. (?m (call-interactively 'org-agenda-month-view))
  6834. (?y (call-interactively 'org-agenda-year-view))
  6835. (?l (call-interactively 'org-agenda-log-mode))
  6836. (?L (org-agenda-log-mode '(4)))
  6837. (?c (org-agenda-log-mode 'clockcheck))
  6838. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6839. (?a (call-interactively 'org-agenda-archives-mode))
  6840. (?A (org-agenda-archives-mode 'files))
  6841. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6842. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6843. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6844. (?D (call-interactively 'org-agenda-toggle-diary))
  6845. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6846. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6847. (org-agenda-check-type t 'timeline 'agenda)
  6848. (org-agenda-redo))
  6849. (message "Display now includes inactive timestamps as well"))
  6850. (?q (message "Abort"))
  6851. (otherwise (error "Invalid key" )))))
  6852. (defun org-agenda-reset-view ()
  6853. "Switch to default view for agenda."
  6854. (interactive)
  6855. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6856. (defun org-agenda-day-view (&optional day-of-year)
  6857. "Switch to daily view for agenda.
  6858. With argument DAY-OF-YEAR, switch to that day of the year."
  6859. (interactive "P")
  6860. (org-agenda-change-time-span 'day day-of-year))
  6861. (defun org-agenda-week-view (&optional iso-week)
  6862. "Switch to daily view for agenda.
  6863. With argument ISO-WEEK, switch to the corresponding ISO week.
  6864. If ISO-WEEK has more then 2 digits, only the last two encode the
  6865. week. Any digits before this encode a year. So 200712 means
  6866. week 12 of year 2007. Years in the range 1938-2037 can also be
  6867. written as 2-digit years."
  6868. (interactive "P")
  6869. (org-agenda-change-time-span 'week iso-week))
  6870. (defun org-agenda-month-view (&optional month)
  6871. "Switch to monthly view for agenda.
  6872. With argument MONTH, switch to that month."
  6873. (interactive "P")
  6874. (org-agenda-change-time-span 'month month))
  6875. (defun org-agenda-year-view (&optional year)
  6876. "Switch to yearly view for agenda.
  6877. With argument YEAR, switch to that year.
  6878. If MONTH has more then 2 digits, only the last two encode the
  6879. month. Any digits before this encode a year. So 200712 means
  6880. December year 2007. Years in the range 1938-2037 can also be
  6881. written as 2-digit years."
  6882. (interactive "P")
  6883. (when year
  6884. (setq year (org-small-year-to-year year)))
  6885. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6886. (org-agenda-change-time-span 'year year)
  6887. (error "Abort")))
  6888. (defun org-agenda-change-time-span (span &optional n)
  6889. "Change the agenda view to SPAN.
  6890. SPAN may be `day', `week', `month', `year'."
  6891. (org-agenda-check-type t 'agenda)
  6892. (let* ((args (get-text-property (min (1- (point-max)) (point)) 'org-last-args))
  6893. (curspan (nth 2 args)))
  6894. (if (and (not n) (equal curspan span))
  6895. (error "Viewing span is already \"%s\"" span))
  6896. (let* ((sd (or (org-get-at-bol 'day)
  6897. (nth 1 args)
  6898. org-starting-day))
  6899. (sd (org-agenda-compute-starting-span sd span n))
  6900. (org-agenda-overriding-cmd
  6901. (get-text-property (min (1- (point-max)) (point)) 'org-serie-cmd))
  6902. (org-agenda-overriding-arguments
  6903. (list (car args) sd span)))
  6904. (org-agenda-redo)
  6905. (org-agenda-find-same-or-today-or-agenda))
  6906. (org-agenda-set-mode-name)
  6907. (message "Switched to %s view" span)))
  6908. (defun org-agenda-compute-starting-span (sd span &optional n)
  6909. "Compute starting date for agenda.
  6910. SPAN may be `day', `week', `month', `year'. The return value
  6911. is a cons cell with the starting date and the number of days,
  6912. so that the date SD will be in that range."
  6913. (let* ((greg (calendar-gregorian-from-absolute sd))
  6914. (dg (nth 1 greg))
  6915. (mg (car greg))
  6916. (yg (nth 2 greg)))
  6917. (cond
  6918. ((eq span 'day)
  6919. (when n
  6920. (setq sd (+ (calendar-absolute-from-gregorian
  6921. (list mg 1 yg))
  6922. n -1))))
  6923. ((eq span 'week)
  6924. (let* ((nt (calendar-day-of-week
  6925. (calendar-gregorian-from-absolute sd)))
  6926. (d (if org-agenda-start-on-weekday
  6927. (- nt org-agenda-start-on-weekday)
  6928. 0))
  6929. y1)
  6930. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6931. (when n
  6932. (require 'cal-iso)
  6933. (when (> n 99)
  6934. (setq y1 (org-small-year-to-year (/ n 100))
  6935. n (mod n 100)))
  6936. (setq sd
  6937. (calendar-absolute-from-iso
  6938. (list n 1
  6939. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6940. ((eq span 'month)
  6941. (let (y1)
  6942. (when (and n (> n 99))
  6943. (setq y1 (org-small-year-to-year (/ n 100))
  6944. n (mod n 100)))
  6945. (setq sd (calendar-absolute-from-gregorian
  6946. (list (or n mg) 1 (or y1 yg))))))
  6947. ((eq span 'year)
  6948. (setq sd (calendar-absolute-from-gregorian
  6949. (list 1 1 (or n yg))))))
  6950. sd))
  6951. (defun org-agenda-next-date-line (&optional arg)
  6952. "Jump to the next line indicating a date in agenda buffer."
  6953. (interactive "p")
  6954. (org-agenda-check-type t 'agenda 'timeline)
  6955. (beginning-of-line 1)
  6956. ;; This does not work if user makes date format that starts with a blank
  6957. (if (looking-at "^\\S-") (forward-char 1))
  6958. (if (not (re-search-forward "^\\S-" nil t arg))
  6959. (progn
  6960. (backward-char 1)
  6961. (error "No next date after this line in this buffer")))
  6962. (goto-char (match-beginning 0)))
  6963. (defun org-agenda-previous-date-line (&optional arg)
  6964. "Jump to the previous line indicating a date in agenda buffer."
  6965. (interactive "p")
  6966. (org-agenda-check-type t 'agenda 'timeline)
  6967. (beginning-of-line 1)
  6968. (if (not (re-search-backward "^\\S-" nil t arg))
  6969. (error "No previous date before this line in this buffer")))
  6970. ;; Initialize the highlight
  6971. (defvar org-hl (make-overlay 1 1))
  6972. (overlay-put org-hl 'face 'highlight)
  6973. (defun org-highlight (begin end &optional buffer)
  6974. "Highlight a region with overlay."
  6975. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6976. (defun org-unhighlight ()
  6977. "Detach overlay INDEX."
  6978. (org-detach-overlay org-hl))
  6979. (defun org-unhighlight-once ()
  6980. "Remove the highlight from its position, and this function from the hook."
  6981. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6982. (org-unhighlight))
  6983. (defvar org-agenda-pre-follow-window-conf nil)
  6984. (defun org-agenda-follow-mode ()
  6985. "Toggle follow mode in an agenda buffer."
  6986. (interactive)
  6987. (unless org-agenda-follow-mode
  6988. (setq org-agenda-pre-follow-window-conf
  6989. (current-window-configuration)))
  6990. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6991. (unless org-agenda-follow-mode
  6992. (set-window-configuration org-agenda-pre-follow-window-conf))
  6993. (org-agenda-set-mode-name)
  6994. (org-agenda-do-context-action)
  6995. (message "Follow mode is %s"
  6996. (if org-agenda-follow-mode "on" "off")))
  6997. (defun org-agenda-entry-text-mode (&optional arg)
  6998. "Toggle entry text mode in an agenda buffer."
  6999. (interactive "P")
  7000. (setq org-agenda-entry-text-mode (or (integerp arg)
  7001. (not org-agenda-entry-text-mode)))
  7002. (org-agenda-entry-text-hide)
  7003. (and org-agenda-entry-text-mode
  7004. (let ((org-agenda-entry-text-maxlines
  7005. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7006. (org-agenda-entry-text-show)))
  7007. (org-agenda-set-mode-name)
  7008. (message "Entry text mode is %s. Maximum number of lines is %d"
  7009. (if org-agenda-entry-text-mode "on" "off")
  7010. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  7011. (defun org-agenda-clockreport-mode (&optional with-filter)
  7012. "Toggle clocktable mode in an agenda buffer.
  7013. With prefix arg WITH-FILTER, make the clocktable respect the current
  7014. agenda filter."
  7015. (interactive "P")
  7016. (org-agenda-check-type t 'agenda)
  7017. (if with-filter
  7018. (setq org-agenda-clockreport-mode 'with-filter)
  7019. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  7020. (org-agenda-set-mode-name)
  7021. (org-agenda-redo)
  7022. (message "Clocktable mode is %s"
  7023. (if org-agenda-clockreport-mode "on" "off")))
  7024. (defun org-agenda-log-mode (&optional special)
  7025. "Toggle log mode in an agenda buffer.
  7026. With argument SPECIAL, show all possible log items, not only the ones
  7027. configured in `org-agenda-log-mode-items'.
  7028. With a double `C-u' prefix arg, show *only* log items, nothing else."
  7029. (interactive "P")
  7030. (org-agenda-check-type t 'agenda 'timeline)
  7031. (setq org-agenda-show-log
  7032. (cond
  7033. ((equal special '(16)) 'only)
  7034. ((eq special 'clockcheck)
  7035. (if (eq org-agenda-show-log 'clockcheck)
  7036. nil 'clockcheck))
  7037. (special '(closed clock state))
  7038. (t (not org-agenda-show-log))))
  7039. (org-agenda-set-mode-name)
  7040. (org-agenda-redo)
  7041. (message "Log mode is %s"
  7042. (if org-agenda-show-log "on" "off")))
  7043. (defun org-agenda-archives-mode (&optional with-files)
  7044. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  7045. When called with a prefix argument, include all archive files as well."
  7046. (interactive "P")
  7047. (setq org-agenda-archives-mode
  7048. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  7049. (org-agenda-set-mode-name)
  7050. (org-agenda-redo)
  7051. (message
  7052. "%s"
  7053. (cond
  7054. ((eq org-agenda-archives-mode nil)
  7055. "No archives are included")
  7056. ((eq org-agenda-archives-mode 'trees)
  7057. (format "Trees with :%s: tag are included" org-archive-tag))
  7058. ((eq org-agenda-archives-mode t)
  7059. (format "Trees with :%s: tag and all active archive files are included"
  7060. org-archive-tag)))))
  7061. (defun org-agenda-toggle-diary ()
  7062. "Toggle diary inclusion in an agenda buffer."
  7063. (interactive)
  7064. (org-agenda-check-type t 'agenda)
  7065. (setq org-agenda-include-diary (not org-agenda-include-diary))
  7066. (org-agenda-redo)
  7067. (org-agenda-set-mode-name)
  7068. (message "Diary inclusion turned %s"
  7069. (if org-agenda-include-diary "on" "off")))
  7070. (defun org-agenda-toggle-deadlines ()
  7071. "Toggle inclusion of entries with a deadline in an agenda buffer."
  7072. (interactive)
  7073. (org-agenda-check-type t 'agenda)
  7074. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  7075. (org-agenda-redo)
  7076. (org-agenda-set-mode-name)
  7077. (message "Deadlines inclusion turned %s"
  7078. (if org-agenda-include-deadlines "on" "off")))
  7079. (defun org-agenda-toggle-time-grid ()
  7080. "Toggle time grid in an agenda buffer."
  7081. (interactive)
  7082. (org-agenda-check-type t 'agenda)
  7083. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  7084. (org-agenda-redo)
  7085. (org-agenda-set-mode-name)
  7086. (message "Time-grid turned %s"
  7087. (if org-agenda-use-time-grid "on" "off")))
  7088. (defun org-agenda-set-mode-name ()
  7089. "Set the mode name to indicate all the small mode settings."
  7090. (setq mode-name
  7091. (list "Org-Agenda"
  7092. (if (get 'org-agenda-files 'org-restrict) " []" "")
  7093. " "
  7094. '(:eval (org-agenda-span-name org-agenda-current-span))
  7095. (if org-agenda-follow-mode " Follow" "")
  7096. (if org-agenda-entry-text-mode " ETxt" "")
  7097. (if org-agenda-include-diary " Diary" "")
  7098. (if org-agenda-include-deadlines " Ddl" "")
  7099. (if org-agenda-use-time-grid " Grid" "")
  7100. (if (and (boundp 'org-habit-show-habits)
  7101. org-habit-show-habits) " Habit" "")
  7102. (cond
  7103. ((consp org-agenda-show-log) " LogAll")
  7104. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  7105. (org-agenda-show-log " Log")
  7106. (t ""))
  7107. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  7108. :preset-filter))
  7109. '(:eval (org-propertize
  7110. (concat " <"
  7111. (mapconcat
  7112. 'identity
  7113. (append
  7114. (get 'org-agenda-category-filter :preset-filter)
  7115. org-agenda-category-filter)
  7116. "")
  7117. ">")
  7118. 'face 'org-agenda-filter-category
  7119. 'help-echo "Category used in filtering"))
  7120. "")
  7121. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  7122. :preset-filter))
  7123. '(:eval (org-propertize
  7124. (concat " {"
  7125. (mapconcat
  7126. 'identity
  7127. (append
  7128. (get 'org-agenda-tag-filter :preset-filter)
  7129. org-agenda-tag-filter)
  7130. "")
  7131. "}")
  7132. 'face 'org-agenda-filter-tags
  7133. 'help-echo "Tags used in filtering"))
  7134. "")
  7135. (if org-agenda-archives-mode
  7136. (if (eq org-agenda-archives-mode t)
  7137. " Archives"
  7138. (format " :%s:" org-archive-tag))
  7139. "")
  7140. (if org-agenda-clockreport-mode
  7141. (if (eq org-agenda-clockreport-mode 'with-filter)
  7142. " Clock{}" " Clock")
  7143. "")))
  7144. (force-mode-line-update))
  7145. (define-obsolete-function-alias
  7146. 'org-agenda-post-command-hook 'org-agenda-update-agenda-type "24.3")
  7147. (defun org-agenda-update-agenda-type ()
  7148. "Update the agenda type after each command."
  7149. (setq org-agenda-type
  7150. (or (get-text-property (point) 'org-agenda-type)
  7151. (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))
  7152. (defun org-agenda-next-line ()
  7153. "Move cursor to the next line, and show if follow mode is active."
  7154. (interactive)
  7155. (call-interactively 'next-line)
  7156. (org-agenda-do-context-action))
  7157. (defun org-agenda-previous-line ()
  7158. "Move cursor to the previous line, and show if follow-mode is active."
  7159. (interactive)
  7160. (call-interactively 'previous-line)
  7161. (org-agenda-do-context-action))
  7162. (defun org-agenda-next-item (n)
  7163. "Move cursor to next agenda item."
  7164. (interactive "p")
  7165. (let ((col (current-column)))
  7166. (dotimes (c n)
  7167. (when (next-single-property-change (point-at-eol) 'org-marker)
  7168. (move-end-of-line 1)
  7169. (goto-char (next-single-property-change (point) 'org-marker))))
  7170. (org-move-to-column col))
  7171. (org-agenda-do-context-action))
  7172. (defun org-agenda-previous-item (n)
  7173. "Move cursor to next agenda item."
  7174. (interactive "p")
  7175. (dotimes (c n)
  7176. (let ((col (current-column))
  7177. (goto (save-excursion
  7178. (move-end-of-line 0)
  7179. (previous-single-property-change (point) 'org-marker))))
  7180. (if goto (goto-char goto))
  7181. (org-move-to-column col)))
  7182. (org-agenda-do-context-action))
  7183. (defun org-agenda-do-context-action ()
  7184. "Show outline path and, maybe, follow mode window."
  7185. (let ((m (org-get-at-bol 'org-marker)))
  7186. (when (and (markerp m) (marker-buffer m))
  7187. (and org-agenda-follow-mode
  7188. (if org-agenda-follow-indirect
  7189. (org-agenda-tree-to-indirect-buffer nil)
  7190. (org-agenda-show)))
  7191. (and org-agenda-show-outline-path
  7192. (org-with-point-at m (org-display-outline-path t))))))
  7193. (defun org-agenda-show-tags ()
  7194. "Show the tags applicable to the current item."
  7195. (interactive)
  7196. (let* ((tags (org-get-at-bol 'tags)))
  7197. (if tags
  7198. (message "Tags are :%s:"
  7199. (org-no-properties (mapconcat 'identity tags ":")))
  7200. (message "No tags associated with this line"))))
  7201. (defun org-agenda-goto (&optional highlight)
  7202. "Go to the Org-mode file which contains the item at point."
  7203. (interactive)
  7204. (let* ((marker (or (org-get-at-bol 'org-marker)
  7205. (org-agenda-error)))
  7206. (buffer (marker-buffer marker))
  7207. (pos (marker-position marker)))
  7208. (switch-to-buffer-other-window buffer)
  7209. (widen)
  7210. (push-mark)
  7211. (goto-char pos)
  7212. (when (derived-mode-p 'org-mode)
  7213. (org-show-context 'agenda)
  7214. (save-excursion
  7215. (and (outline-next-heading)
  7216. (org-flag-heading nil)))) ; show the next heading
  7217. (when (outline-invisible-p)
  7218. (show-entry)) ; display invisible text
  7219. (recenter (/ (window-height) 2))
  7220. (run-hooks 'org-agenda-after-show-hook)
  7221. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7222. (defvar org-agenda-after-show-hook nil
  7223. "Normal hook run after an item has been shown from the agenda.
  7224. Point is in the buffer where the item originated.")
  7225. (defun org-agenda-kill ()
  7226. "Kill the entry or subtree belonging to the current agenda entry."
  7227. (interactive)
  7228. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7229. (let* ((bufname-orig (buffer-name))
  7230. (marker (or (org-get-at-bol 'org-marker)
  7231. (org-agenda-error)))
  7232. (buffer (marker-buffer marker))
  7233. (pos (marker-position marker))
  7234. (type (org-get-at-bol 'type))
  7235. dbeg dend (n 0) conf)
  7236. (org-with-remote-undo buffer
  7237. (with-current-buffer buffer
  7238. (save-excursion
  7239. (goto-char pos)
  7240. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7241. (setq dbeg (progn (org-back-to-heading t) (point))
  7242. dend (org-end-of-subtree t t))
  7243. (setq dbeg (point-at-bol)
  7244. dend (min (point-max) (1+ (point-at-eol)))))
  7245. (goto-char dbeg)
  7246. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7247. (setq conf (or (eq t org-agenda-confirm-kill)
  7248. (and (numberp org-agenda-confirm-kill)
  7249. (> n org-agenda-confirm-kill))))
  7250. (and conf
  7251. (not (y-or-n-p
  7252. (format "Delete entry with %d lines in buffer \"%s\"? "
  7253. n (buffer-name buffer))))
  7254. (error "Abort"))
  7255. (let ((org-agenda-buffer-name bufname-orig))
  7256. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7257. (with-current-buffer buffer (delete-region dbeg dend))
  7258. (message "Agenda item and source killed"))))
  7259. (defvar org-archive-default-command) ; defined in org-archive.el
  7260. (defun org-agenda-archive-default ()
  7261. "Archive the entry or subtree belonging to the current agenda entry."
  7262. (interactive)
  7263. (require 'org-archive)
  7264. (org-agenda-archive-with org-archive-default-command))
  7265. (defun org-agenda-archive-default-with-confirmation ()
  7266. "Archive the entry or subtree belonging to the current agenda entry."
  7267. (interactive)
  7268. (require 'org-archive)
  7269. (org-agenda-archive-with org-archive-default-command 'confirm))
  7270. (defun org-agenda-archive ()
  7271. "Archive the entry or subtree belonging to the current agenda entry."
  7272. (interactive)
  7273. (org-agenda-archive-with 'org-archive-subtree))
  7274. (defun org-agenda-archive-to-archive-sibling ()
  7275. "Move the entry to the archive sibling."
  7276. (interactive)
  7277. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7278. (defun org-agenda-archive-with (cmd &optional confirm)
  7279. "Move the entry to the archive sibling."
  7280. (interactive)
  7281. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7282. (let* ((bufname-orig (buffer-name))
  7283. (marker (or (org-get-at-bol 'org-marker)
  7284. (org-agenda-error)))
  7285. (buffer (marker-buffer marker))
  7286. (pos (marker-position marker)))
  7287. (org-with-remote-undo buffer
  7288. (with-current-buffer buffer
  7289. (if (derived-mode-p 'org-mode)
  7290. (if (and confirm
  7291. (not (y-or-n-p "Archive this subtree or entry? ")))
  7292. (error "Abort")
  7293. (save-excursion
  7294. (goto-char pos)
  7295. (let ((org-agenda-buffer-name bufname-orig))
  7296. (org-remove-subtree-entries-from-agenda))
  7297. (org-back-to-heading t)
  7298. (funcall cmd)))
  7299. (error "Archiving works only in Org-mode files"))))))
  7300. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7301. "Remove all lines in the agenda that correspond to a given subtree.
  7302. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7303. If this information is not given, the function uses the tree at point."
  7304. (let ((buf (or buf (current-buffer))) m p)
  7305. (save-excursion
  7306. (unless (and beg end)
  7307. (org-back-to-heading t)
  7308. (setq beg (point))
  7309. (org-end-of-subtree t)
  7310. (setq end (point)))
  7311. (set-buffer (get-buffer org-agenda-buffer-name))
  7312. (save-excursion
  7313. (goto-char (point-max))
  7314. (beginning-of-line 1)
  7315. (while (not (bobp))
  7316. (when (and (setq m (org-get-at-bol 'org-marker))
  7317. (equal buf (marker-buffer m))
  7318. (setq p (marker-position m))
  7319. (>= p beg)
  7320. (< p end))
  7321. (let ((inhibit-read-only t))
  7322. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7323. (beginning-of-line 0))))))
  7324. (defun org-agenda-refile (&optional goto rfloc no-update)
  7325. "Refile the item at point."
  7326. (interactive "P")
  7327. (if (equal goto '(16))
  7328. (org-refile-goto-last-stored)
  7329. (let* ((buffer-orig (buffer-name))
  7330. (marker (or (org-get-at-bol 'org-hd-marker)
  7331. (org-agenda-error)))
  7332. (buffer (marker-buffer marker))
  7333. (pos (marker-position marker))
  7334. (rfloc (or rfloc
  7335. (org-refile-get-location
  7336. (if goto "Goto" "Refile to") buffer
  7337. org-refile-allow-creating-parent-nodes))))
  7338. (with-current-buffer buffer
  7339. (save-excursion
  7340. (save-restriction
  7341. (widen)
  7342. (goto-char marker)
  7343. (let ((org-agenda-buffer-name buffer-orig))
  7344. (org-remove-subtree-entries-from-agenda))
  7345. (org-refile goto buffer rfloc)))))
  7346. (unless no-update (org-agenda-redo))))
  7347. (defun org-agenda-open-link (&optional arg)
  7348. "Follow the link in the current line, if any.
  7349. This looks for a link in the displayed line in the agenda. It also looks
  7350. at the text of the entry itself."
  7351. (interactive "P")
  7352. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7353. (org-get-at-bol 'org-marker)))
  7354. (buffer (and marker (marker-buffer marker)))
  7355. (prefix (buffer-substring
  7356. (point-at-bol) (point-at-eol))))
  7357. (cond
  7358. (buffer
  7359. (with-current-buffer buffer
  7360. (save-excursion
  7361. (save-restriction
  7362. (widen)
  7363. (goto-char marker)
  7364. (org-offer-links-in-entry arg prefix)))))
  7365. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7366. (save-excursion
  7367. (beginning-of-line 1)
  7368. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7369. (org-open-link-from-string (match-string 1)))
  7370. (t (error "No link to open here")))))
  7371. (defun org-agenda-copy-local-variable (var)
  7372. "Get a variable from a referenced buffer and install it here."
  7373. (let ((m (org-get-at-bol 'org-marker)))
  7374. (when (and m (buffer-live-p (marker-buffer m)))
  7375. (org-set-local var (with-current-buffer (marker-buffer m)
  7376. (symbol-value var))))))
  7377. (defun org-agenda-switch-to (&optional delete-other-windows)
  7378. "Go to the Org-mode file which contains the item at point."
  7379. (interactive)
  7380. (if (and org-return-follows-link
  7381. (not (org-get-at-bol 'org-marker))
  7382. (org-in-regexp org-bracket-link-regexp))
  7383. (org-open-link-from-string (match-string 0))
  7384. (let* ((marker (or (org-get-at-bol 'org-marker)
  7385. (org-agenda-error)))
  7386. (buffer (marker-buffer marker))
  7387. (pos (marker-position marker)))
  7388. (org-pop-to-buffer-same-window buffer)
  7389. (and delete-other-windows (delete-other-windows))
  7390. (widen)
  7391. (goto-char pos)
  7392. (when (derived-mode-p 'org-mode)
  7393. (org-show-context 'agenda)
  7394. (save-excursion
  7395. (and (outline-next-heading)
  7396. (org-flag-heading nil))) ; show the next heading
  7397. (when (outline-invisible-p)
  7398. (show-entry)) ; display invisible text
  7399. (run-hooks 'org-agenda-after-show-hook)))))
  7400. (defun org-agenda-goto-mouse (ev)
  7401. "Go to the Org-mode file which contains the item at the mouse click."
  7402. (interactive "e")
  7403. (mouse-set-point ev)
  7404. (org-agenda-goto))
  7405. (defun org-agenda-show (&optional full-entry)
  7406. "Display the Org-mode file which contains the item at point.
  7407. With prefix argument FULL-ENTRY, make the entire entry visible
  7408. if it was hidden in the outline."
  7409. (interactive "P")
  7410. (let ((win (selected-window)))
  7411. (if full-entry
  7412. (let ((org-show-entry-below t))
  7413. (org-agenda-goto t))
  7414. (org-agenda-goto t))
  7415. (select-window win)))
  7416. (defvar org-agenda-show-window nil)
  7417. (defun org-agenda-show-and-scroll-up (&optional arg)
  7418. "Display the Org-mode file which contains the item at point.
  7419. When called repeatedly, scroll the window that is displaying the buffer.
  7420. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7421. `show-subtree' to display the item, so that drawers and logbooks stay
  7422. folded."
  7423. (interactive "P")
  7424. (let ((win (selected-window)))
  7425. (if (and (window-live-p org-agenda-show-window)
  7426. (eq this-command last-command))
  7427. (progn
  7428. (select-window org-agenda-show-window)
  7429. (ignore-errors (scroll-up)))
  7430. (org-agenda-goto t)
  7431. (if arg (org-show-entry) (show-subtree))
  7432. (setq org-agenda-show-window (selected-window)))
  7433. (select-window win)))
  7434. (defun org-agenda-show-scroll-down ()
  7435. "Scroll down the window showing the agenda."
  7436. (interactive)
  7437. (let ((win (selected-window)))
  7438. (when (window-live-p org-agenda-show-window)
  7439. (select-window org-agenda-show-window)
  7440. (ignore-errors (scroll-down))
  7441. (select-window win))))
  7442. (defun org-agenda-show-1 (&optional more)
  7443. "Display the Org-mode file which contains the item at point.
  7444. The prefix arg selects the amount of information to display:
  7445. 0 hide the subtree
  7446. 1 just show the entry according to defaults.
  7447. 2 show the children view
  7448. 3 show the subtree view
  7449. 4 show the entire subtree and any LOGBOOK drawers
  7450. 5 show the entire subtree and any drawers
  7451. With prefix argument FULL-ENTRY, make the entire entry visible
  7452. if it was hidden in the outline."
  7453. (interactive "p")
  7454. (let ((win (selected-window)))
  7455. (org-agenda-goto t)
  7456. (org-recenter-heading 1)
  7457. (cond
  7458. ((= more 0)
  7459. (hide-subtree)
  7460. (save-excursion
  7461. (org-back-to-heading)
  7462. (run-hook-with-args 'org-cycle-hook 'folded))
  7463. (message "Remote: FOLDED"))
  7464. ((and (org-called-interactively-p 'any) (= more 1))
  7465. (message "Remote: show with default settings"))
  7466. ((= more 2)
  7467. (show-entry)
  7468. (show-children)
  7469. (save-excursion
  7470. (org-back-to-heading)
  7471. (run-hook-with-args 'org-cycle-hook 'children))
  7472. (message "Remote: CHILDREN"))
  7473. ((= more 3)
  7474. (show-subtree)
  7475. (save-excursion
  7476. (org-back-to-heading)
  7477. (run-hook-with-args 'org-cycle-hook 'subtree))
  7478. (message "Remote: SUBTREE"))
  7479. ((= more 4)
  7480. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7481. (org-drawer-regexp
  7482. (concat "^[ \t]*:\\("
  7483. (mapconcat 'regexp-quote org-drawers "\\|")
  7484. "\\):[ \t]*$")))
  7485. (show-subtree)
  7486. (save-excursion
  7487. (org-back-to-heading)
  7488. (org-cycle-hide-drawers 'subtree)))
  7489. (message "Remote: SUBTREE AND LOGBOOK"))
  7490. ((> more 4)
  7491. (show-subtree)
  7492. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7493. (select-window win)))
  7494. (defun org-recenter-heading (n)
  7495. (save-excursion
  7496. (org-back-to-heading)
  7497. (recenter n)))
  7498. (defvar org-agenda-cycle-counter nil)
  7499. (defun org-agenda-cycle-show (&optional n)
  7500. "Show the current entry in another window, with default settings.
  7501. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7502. When use repeatedly in immediate succession, the remote entry will cycle
  7503. through visibility
  7504. children -> subtree -> folded
  7505. When called with a numeric prefix arg, that arg will be passed through to
  7506. `org-agenda-show-1'. For the interpretation of that argument, see the
  7507. docstring of `org-agenda-show-1'."
  7508. (interactive "P")
  7509. (if (integerp n)
  7510. (setq org-agenda-cycle-counter n)
  7511. (if (not (eq last-command this-command))
  7512. (setq org-agenda-cycle-counter 1)
  7513. (if (equal org-agenda-cycle-counter 0)
  7514. (setq org-agenda-cycle-counter 2)
  7515. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7516. (if (> org-agenda-cycle-counter 3)
  7517. (setq org-agenda-cycle-counter 0)))))
  7518. (org-agenda-show-1 org-agenda-cycle-counter))
  7519. (defun org-agenda-recenter (arg)
  7520. "Display the Org-mode file which contains the item at point and recenter."
  7521. (interactive "P")
  7522. (let ((win (selected-window)))
  7523. (org-agenda-goto t)
  7524. (recenter arg)
  7525. (select-window win)))
  7526. (defun org-agenda-show-mouse (ev)
  7527. "Display the Org-mode file which contains the item at the mouse click."
  7528. (interactive "e")
  7529. (mouse-set-point ev)
  7530. (org-agenda-show))
  7531. (defun org-agenda-check-no-diary ()
  7532. "Check if the entry is a diary link and abort if yes."
  7533. (if (org-get-at-bol 'org-agenda-diary-link)
  7534. (org-agenda-error)))
  7535. (defun org-agenda-error ()
  7536. (error "Command not allowed in this line"))
  7537. (defun org-agenda-tree-to-indirect-buffer (arg)
  7538. "Show the subtree corresponding to the current entry in an indirect buffer.
  7539. This calls the command `org-tree-to-indirect-buffer' from the original buffer.
  7540. With a numerical prefix ARG, go up to this level and then take that tree.
  7541. With a negative numeric ARG, go up by this number of levels.
  7542. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7543. use the dedicated frame)."
  7544. (interactive "P")
  7545. (if current-prefix-arg
  7546. (org-agenda-do-tree-to-indirect-buffer arg)
  7547. (let ((agenda-buffer (buffer-name))
  7548. (agenda-window (selected-window))
  7549. (indirect-window
  7550. (and org-last-indirect-buffer
  7551. (get-buffer-window org-last-indirect-buffer))))
  7552. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer arg))
  7553. (unless (or (eq org-indirect-buffer-display 'new-frame)
  7554. (eq org-indirect-buffer-display 'dedicated-frame))
  7555. (unwind-protect
  7556. (unless (and indirect-window (window-live-p indirect-window))
  7557. (setq indirect-window (split-window agenda-window)))
  7558. (and indirect-window (select-window indirect-window))
  7559. (switch-to-buffer org-last-indirect-buffer :norecord)
  7560. (fit-window-to-buffer indirect-window)))
  7561. (select-window (get-buffer-window agenda-buffer)))))
  7562. (defun org-agenda-do-tree-to-indirect-buffer (arg)
  7563. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7564. (org-agenda-check-no-diary)
  7565. (let* ((marker (or (org-get-at-bol 'org-marker)
  7566. (org-agenda-error)))
  7567. (buffer (marker-buffer marker))
  7568. (pos (marker-position marker)))
  7569. (with-current-buffer buffer
  7570. (save-excursion
  7571. (goto-char pos)
  7572. (funcall 'org-tree-to-indirect-buffer arg)))))
  7573. (defvar org-last-heading-marker (make-marker)
  7574. "Marker pointing to the headline that last changed its TODO state
  7575. by a remote command from the agenda.")
  7576. (defun org-agenda-todo-nextset ()
  7577. "Switch TODO entry to next sequence."
  7578. (interactive)
  7579. (org-agenda-todo 'nextset))
  7580. (defun org-agenda-todo-previousset ()
  7581. "Switch TODO entry to previous sequence."
  7582. (interactive)
  7583. (org-agenda-todo 'previousset))
  7584. (defun org-agenda-todo (&optional arg)
  7585. "Cycle TODO state of line at point, also in Org-mode file.
  7586. This changes the line at point, all other lines in the agenda referring to
  7587. the same tree node, and the headline of the tree node in the Org-mode file."
  7588. (interactive "P")
  7589. (org-agenda-check-no-diary)
  7590. (let* ((col (current-column))
  7591. (marker (or (org-get-at-bol 'org-marker)
  7592. (org-agenda-error)))
  7593. (buffer (marker-buffer marker))
  7594. (pos (marker-position marker))
  7595. (hdmarker (org-get-at-bol 'org-hd-marker))
  7596. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7597. (inhibit-read-only t)
  7598. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7599. (org-with-remote-undo buffer
  7600. (with-current-buffer buffer
  7601. (widen)
  7602. (goto-char pos)
  7603. (org-show-context 'agenda)
  7604. (save-excursion
  7605. (and (outline-next-heading)
  7606. (org-flag-heading nil))) ; show the next heading
  7607. (let ((current-prefix-arg arg))
  7608. (call-interactively 'org-todo))
  7609. (and (bolp) (forward-char 1))
  7610. (setq newhead (org-get-heading))
  7611. (when (and (org-bound-and-true-p
  7612. org-agenda-headline-snapshot-before-repeat)
  7613. (not (equal org-agenda-headline-snapshot-before-repeat
  7614. newhead))
  7615. todayp)
  7616. (setq newhead org-agenda-headline-snapshot-before-repeat
  7617. just-one t))
  7618. (save-excursion
  7619. (org-back-to-heading)
  7620. (move-marker org-last-heading-marker (point))))
  7621. (beginning-of-line 1)
  7622. (save-excursion
  7623. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7624. (org-move-to-column col))))
  7625. (defun org-agenda-add-note (&optional arg)
  7626. "Add a time-stamped note to the entry at point."
  7627. (interactive "P")
  7628. (org-agenda-check-no-diary)
  7629. (let* ((marker (or (org-get-at-bol 'org-marker)
  7630. (org-agenda-error)))
  7631. (buffer (marker-buffer marker))
  7632. (pos (marker-position marker))
  7633. (hdmarker (org-get-at-bol 'org-hd-marker))
  7634. (inhibit-read-only t))
  7635. (with-current-buffer buffer
  7636. (widen)
  7637. (goto-char pos)
  7638. (org-show-context 'agenda)
  7639. (save-excursion
  7640. (and (outline-next-heading)
  7641. (org-flag-heading nil))) ; show the next heading
  7642. (org-add-note))))
  7643. (defun org-agenda-change-all-lines (newhead hdmarker
  7644. &optional fixface just-this)
  7645. "Change all lines in the agenda buffer which match HDMARKER.
  7646. The new content of the line will be NEWHEAD (as modified by
  7647. `org-agenda-format-item'). HDMARKER is checked with
  7648. `equal' against all `org-hd-marker' text properties in the file.
  7649. If FIXFACE is non-nil, the face of each item is modified according to
  7650. the new TODO state.
  7651. If JUST-THIS is non-nil, change just the current line, not all.
  7652. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7653. (let* ((inhibit-read-only t)
  7654. (line (org-current-line))
  7655. (org-agenda-buffer (current-buffer))
  7656. (thetags (with-current-buffer (marker-buffer hdmarker)
  7657. (save-excursion (save-restriction (widen)
  7658. (goto-char hdmarker)
  7659. (org-get-tags-at)))))
  7660. props m pl undone-face done-face finish new dotime level cat tags)
  7661. (save-excursion
  7662. (goto-char (point-max))
  7663. (beginning-of-line 1)
  7664. (while (not finish)
  7665. (setq finish (bobp))
  7666. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7667. (or (not just-this) (= (org-current-line) line))
  7668. (equal m hdmarker))
  7669. (setq props (text-properties-at (point))
  7670. dotime (org-get-at-bol 'dotime)
  7671. cat (org-get-at-bol 'org-category)
  7672. level (org-get-at-bol 'level)
  7673. tags thetags
  7674. new
  7675. (let ((org-prefix-format-compiled
  7676. (or (get-text-property (min (1- (point-max)) (point)) 'format)
  7677. org-prefix-format-compiled))
  7678. (extra (org-get-at-bol 'extra)))
  7679. (with-current-buffer (marker-buffer hdmarker)
  7680. (save-excursion
  7681. (save-restriction
  7682. (widen)
  7683. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7684. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7685. undone-face (org-get-at-bol 'undone-face)
  7686. done-face (org-get-at-bol 'done-face))
  7687. (beginning-of-line 1)
  7688. (cond
  7689. ((equal new "")
  7690. (and (looking-at ".*\n?") (replace-match "")))
  7691. ((looking-at ".*")
  7692. (replace-match new t t)
  7693. (beginning-of-line 1)
  7694. (add-text-properties (point-at-bol) (point-at-eol) props)
  7695. (when fixface
  7696. (add-text-properties
  7697. (point-at-bol) (point-at-eol)
  7698. (list 'face
  7699. (if org-last-todo-state-is-todo
  7700. undone-face done-face))))
  7701. (org-agenda-highlight-todo 'line)
  7702. (beginning-of-line 1))
  7703. (t (error "Line update did not work")))
  7704. (save-restriction
  7705. (narrow-to-region (point-at-bol) (point-at-eol))
  7706. (org-agenda-finalize)))
  7707. (beginning-of-line 0)))))
  7708. (defun org-agenda-align-tags (&optional line)
  7709. "Align all tags in agenda items to `org-agenda-tags-column'."
  7710. (let ((inhibit-read-only t) l c)
  7711. (save-excursion
  7712. (goto-char (if line (point-at-bol) (point-min)))
  7713. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7714. (if line (point-at-eol) nil) t)
  7715. (add-text-properties
  7716. (match-beginning 2) (match-end 2)
  7717. (list 'face (delq nil (let ((prop (get-text-property
  7718. (match-beginning 2) 'face)))
  7719. (or (listp prop) (setq prop (list prop)))
  7720. (if (memq 'org-tag prop)
  7721. prop
  7722. (cons 'org-tag prop))))))
  7723. (setq l (- (match-end 2) (match-beginning 2))
  7724. c (if (< org-agenda-tags-column 0)
  7725. (- (abs org-agenda-tags-column) l)
  7726. org-agenda-tags-column))
  7727. (delete-region (match-beginning 1) (match-end 1))
  7728. (goto-char (match-beginning 1))
  7729. (insert (org-add-props
  7730. (make-string (max 1 (- c (current-column))) ?\ )
  7731. (plist-put (copy-sequence (text-properties-at (point)))
  7732. 'face nil))))
  7733. (goto-char (point-min))
  7734. (org-font-lock-add-tag-faces (point-max)))))
  7735. (defun org-agenda-priority-up ()
  7736. "Increase the priority of line at point, also in Org-mode file."
  7737. (interactive)
  7738. (org-agenda-priority 'up))
  7739. (defun org-agenda-priority-down ()
  7740. "Decrease the priority of line at point, also in Org-mode file."
  7741. (interactive)
  7742. (org-agenda-priority 'down))
  7743. (defun org-agenda-priority (&optional force-direction show)
  7744. "Set the priority of line at point, also in Org-mode file.
  7745. This changes the line at point, all other lines in the agenda referring to
  7746. the same tree node, and the headline of the tree node in the Org-mode file."
  7747. (interactive "P")
  7748. (if (equal force-direction '(4)) (setq show t))
  7749. (unless org-enable-priority-commands
  7750. (error "Priority commands are disabled"))
  7751. (org-agenda-check-no-diary)
  7752. (let* ((marker (or (org-get-at-bol 'org-marker)
  7753. (org-agenda-error)))
  7754. (hdmarker (org-get-at-bol 'org-hd-marker))
  7755. (buffer (marker-buffer hdmarker))
  7756. (pos (marker-position hdmarker))
  7757. (inhibit-read-only t)
  7758. newhead)
  7759. (org-with-remote-undo buffer
  7760. (with-current-buffer buffer
  7761. (widen)
  7762. (goto-char pos)
  7763. (org-show-context 'agenda)
  7764. (save-excursion
  7765. (and (outline-next-heading)
  7766. (org-flag-heading nil))) ; show the next heading
  7767. (funcall 'org-priority force-direction show)
  7768. (end-of-line 1)
  7769. (setq newhead (org-get-heading)))
  7770. (org-agenda-change-all-lines newhead hdmarker)
  7771. (beginning-of-line 1))))
  7772. ;; FIXME: should fix the tags property of the agenda line.
  7773. (defun org-agenda-set-tags (&optional tag onoff)
  7774. "Set tags for the current headline."
  7775. (interactive)
  7776. (org-agenda-check-no-diary)
  7777. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7778. (call-interactively 'org-change-tag-in-region)
  7779. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7780. (org-agenda-error)))
  7781. (buffer (marker-buffer hdmarker))
  7782. (pos (marker-position hdmarker))
  7783. (inhibit-read-only t)
  7784. newhead)
  7785. (org-with-remote-undo buffer
  7786. (with-current-buffer buffer
  7787. (widen)
  7788. (goto-char pos)
  7789. (save-excursion
  7790. (org-show-context 'agenda))
  7791. (save-excursion
  7792. (and (outline-next-heading)
  7793. (org-flag-heading nil))) ; show the next heading
  7794. (goto-char pos)
  7795. (if tag
  7796. (org-toggle-tag tag onoff)
  7797. (call-interactively 'org-set-tags))
  7798. (end-of-line 1)
  7799. (setq newhead (org-get-heading)))
  7800. (org-agenda-change-all-lines newhead hdmarker)
  7801. (beginning-of-line 1)))))
  7802. (defun org-agenda-set-property ()
  7803. "Set a property for the current headline."
  7804. (interactive)
  7805. (org-agenda-check-no-diary)
  7806. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7807. (org-agenda-error)))
  7808. (buffer (marker-buffer hdmarker))
  7809. (pos (marker-position hdmarker))
  7810. (inhibit-read-only t)
  7811. newhead)
  7812. (org-with-remote-undo buffer
  7813. (with-current-buffer buffer
  7814. (widen)
  7815. (goto-char pos)
  7816. (save-excursion
  7817. (org-show-context 'agenda))
  7818. (save-excursion
  7819. (and (outline-next-heading)
  7820. (org-flag-heading nil))) ; show the next heading
  7821. (goto-char pos)
  7822. (call-interactively 'org-set-property)))))
  7823. (defun org-agenda-set-effort ()
  7824. "Set the effort property for the current headline."
  7825. (interactive)
  7826. (org-agenda-check-no-diary)
  7827. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7828. (org-agenda-error)))
  7829. (buffer (marker-buffer hdmarker))
  7830. (pos (marker-position hdmarker))
  7831. (inhibit-read-only t)
  7832. newhead)
  7833. (org-with-remote-undo buffer
  7834. (with-current-buffer buffer
  7835. (widen)
  7836. (goto-char pos)
  7837. (save-excursion
  7838. (org-show-context 'agenda))
  7839. (save-excursion
  7840. (and (outline-next-heading)
  7841. (org-flag-heading nil))) ; show the next heading
  7842. (goto-char pos)
  7843. (call-interactively 'org-set-effort)
  7844. (end-of-line 1)
  7845. (setq newhead (org-get-heading)))
  7846. (org-agenda-change-all-lines newhead hdmarker))))
  7847. (defun org-agenda-toggle-archive-tag ()
  7848. "Toggle the archive tag for the current entry."
  7849. (interactive)
  7850. (org-agenda-check-no-diary)
  7851. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7852. (org-agenda-error)))
  7853. (buffer (marker-buffer hdmarker))
  7854. (pos (marker-position hdmarker))
  7855. (inhibit-read-only t)
  7856. newhead)
  7857. (org-with-remote-undo buffer
  7858. (with-current-buffer buffer
  7859. (widen)
  7860. (goto-char pos)
  7861. (org-show-context 'agenda)
  7862. (save-excursion
  7863. (and (outline-next-heading)
  7864. (org-flag-heading nil))) ; show the next heading
  7865. (call-interactively 'org-toggle-archive-tag)
  7866. (end-of-line 1)
  7867. (setq newhead (org-get-heading)))
  7868. (org-agenda-change-all-lines newhead hdmarker)
  7869. (beginning-of-line 1))))
  7870. (defun org-agenda-do-date-later (arg)
  7871. (interactive "P")
  7872. (cond
  7873. ((or (equal arg '(16))
  7874. (memq last-command
  7875. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7876. (setq this-command 'org-agenda-date-later-minutes)
  7877. (org-agenda-date-later-minutes 1))
  7878. ((or (equal arg '(4))
  7879. (memq last-command
  7880. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7881. (setq this-command 'org-agenda-date-later-hours)
  7882. (org-agenda-date-later-hours 1))
  7883. (t
  7884. (org-agenda-date-later (prefix-numeric-value arg)))))
  7885. (defun org-agenda-do-date-earlier (arg)
  7886. (interactive "P")
  7887. (cond
  7888. ((or (equal arg '(16))
  7889. (memq last-command
  7890. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7891. (setq this-command 'org-agenda-date-earlier-minutes)
  7892. (org-agenda-date-earlier-minutes 1))
  7893. ((or (equal arg '(4))
  7894. (memq last-command
  7895. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7896. (setq this-command 'org-agenda-date-earlier-hours)
  7897. (org-agenda-date-earlier-hours 1))
  7898. (t
  7899. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7900. (defun org-agenda-date-later (arg &optional what)
  7901. "Change the date of this item to ARG day(s) later."
  7902. (interactive "p")
  7903. (org-agenda-check-type t 'agenda 'timeline)
  7904. (org-agenda-check-no-diary)
  7905. (let* ((marker (or (org-get-at-bol 'org-marker)
  7906. (org-agenda-error)))
  7907. (buffer (marker-buffer marker))
  7908. (pos (marker-position marker))
  7909. cdate today)
  7910. (org-with-remote-undo buffer
  7911. (with-current-buffer buffer
  7912. (widen)
  7913. (goto-char pos)
  7914. (if (not (org-at-timestamp-p))
  7915. (error "Cannot find time stamp"))
  7916. (when (and org-agenda-move-date-from-past-immediately-to-today
  7917. (equal arg 1)
  7918. (or (not what) (eq what 'day))
  7919. (not (save-match-data (org-at-date-range-p))))
  7920. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7921. cdate (calendar-absolute-from-gregorian
  7922. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7923. today (org-today))
  7924. (if (> today cdate)
  7925. ;; immediately shift to today
  7926. (setq arg (- today cdate))))
  7927. (org-timestamp-change arg (or what 'day))
  7928. (when (and (org-at-date-range-p)
  7929. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7930. (let ((end org-last-changed-timestamp))
  7931. (org-timestamp-change arg (or what 'day))
  7932. (setq org-last-changed-timestamp
  7933. (concat org-last-changed-timestamp "--" end)))))
  7934. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7935. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7936. (defun org-agenda-date-earlier (arg &optional what)
  7937. "Change the date of this item to ARG day(s) earlier."
  7938. (interactive "p")
  7939. (org-agenda-date-later (- arg) what))
  7940. (defun org-agenda-date-later-minutes (arg)
  7941. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7942. (interactive "p")
  7943. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7944. (org-agenda-date-later arg 'minute))
  7945. (defun org-agenda-date-earlier-minutes (arg)
  7946. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7947. (interactive "p")
  7948. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7949. (org-agenda-date-earlier arg 'minute))
  7950. (defun org-agenda-date-later-hours (arg)
  7951. "Change the time of this item, in hour steps."
  7952. (interactive "p")
  7953. (org-agenda-date-later arg 'hour))
  7954. (defun org-agenda-date-earlier-hours (arg)
  7955. "Change the time of this item, in hour steps."
  7956. (interactive "p")
  7957. (org-agenda-date-earlier arg 'hour))
  7958. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7959. "Show new date stamp via text properties."
  7960. ;; We use text properties to make this undoable
  7961. (let ((inhibit-read-only t)
  7962. (buffer-invisibility-spec))
  7963. (setq stamp (concat " " prefix " => " stamp))
  7964. (save-excursion
  7965. (goto-char (point-max))
  7966. (while (not (bobp))
  7967. (when (equal marker (org-get-at-bol 'org-marker))
  7968. (org-move-to-column (- (window-width) (length stamp)) t)
  7969. (org-agenda-fix-tags-filter-overlays-at (point))
  7970. (if (featurep 'xemacs)
  7971. ;; Use `duplicable' property to trigger undo recording
  7972. (let ((ex (make-extent nil nil))
  7973. (gl (make-glyph stamp)))
  7974. (set-glyph-face gl 'secondary-selection)
  7975. (set-extent-properties
  7976. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7977. (insert-extent ex (1- (point)) (point-at-eol)))
  7978. (add-text-properties
  7979. (1- (point)) (point-at-eol)
  7980. (list 'display (org-add-props stamp nil
  7981. 'face 'secondary-selection))))
  7982. (beginning-of-line 1))
  7983. (beginning-of-line 0)))))
  7984. (defun org-agenda-date-prompt (arg)
  7985. "Change the date of this item. Date is prompted for, with default today.
  7986. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7987. be used to request time specification in the time stamp."
  7988. (interactive "P")
  7989. (org-agenda-check-type t 'agenda 'timeline)
  7990. (org-agenda-check-no-diary)
  7991. (let* ((marker (or (org-get-at-bol 'org-marker)
  7992. (org-agenda-error)))
  7993. (buffer (marker-buffer marker))
  7994. (pos (marker-position marker)))
  7995. (org-with-remote-undo buffer
  7996. (with-current-buffer buffer
  7997. (widen)
  7998. (goto-char pos)
  7999. (if (not (org-at-timestamp-p t))
  8000. (error "Cannot find time stamp"))
  8001. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  8002. (org-agenda-show-new-time marker org-last-changed-timestamp))
  8003. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  8004. (defun org-agenda-schedule (arg &optional time)
  8005. "Schedule the item at point.
  8006. ARG is passed through to `org-schedule'."
  8007. (interactive "P")
  8008. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8009. (org-agenda-check-no-diary)
  8010. (let* ((marker (or (org-get-at-bol 'org-marker)
  8011. (org-agenda-error)))
  8012. (type (marker-insertion-type marker))
  8013. (buffer (marker-buffer marker))
  8014. (pos (marker-position marker))
  8015. (org-insert-labeled-timestamps-at-point nil)
  8016. ts)
  8017. (set-marker-insertion-type marker t)
  8018. (org-with-remote-undo buffer
  8019. (with-current-buffer buffer
  8020. (widen)
  8021. (goto-char pos)
  8022. (setq ts (org-schedule arg time)))
  8023. (org-agenda-show-new-time marker ts "S"))
  8024. (message "Item scheduled for %s" ts)))
  8025. (defun org-agenda-deadline (arg &optional time)
  8026. "Schedule the item at point.
  8027. ARG is passed through to `org-deadline'."
  8028. (interactive "P")
  8029. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  8030. (org-agenda-check-no-diary)
  8031. (let* ((marker (or (org-get-at-bol 'org-marker)
  8032. (org-agenda-error)))
  8033. (buffer (marker-buffer marker))
  8034. (pos (marker-position marker))
  8035. (org-insert-labeled-timestamps-at-point nil)
  8036. ts)
  8037. (org-with-remote-undo buffer
  8038. (with-current-buffer buffer
  8039. (widen)
  8040. (goto-char pos)
  8041. (setq ts (org-deadline arg time)))
  8042. (org-agenda-show-new-time marker ts "D"))
  8043. (message "Deadline for this item set to %s" ts)))
  8044. (defun org-agenda-clock-in (&optional arg)
  8045. "Start the clock on the currently selected item."
  8046. (interactive "P")
  8047. (org-agenda-check-no-diary)
  8048. (if (equal arg '(4))
  8049. (org-clock-in arg)
  8050. (let* ((marker (or (org-get-at-bol 'org-marker)
  8051. (org-agenda-error)))
  8052. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  8053. marker))
  8054. (pos (marker-position marker))
  8055. newhead)
  8056. (org-with-remote-undo (marker-buffer marker)
  8057. (with-current-buffer (marker-buffer marker)
  8058. (widen)
  8059. (goto-char pos)
  8060. (org-show-context 'agenda)
  8061. (org-show-entry)
  8062. (org-cycle-hide-drawers 'children)
  8063. (org-clock-in arg)
  8064. (setq newhead (org-get-heading)))
  8065. (org-agenda-change-all-lines newhead hdmarker)))))
  8066. (defun org-agenda-clock-out ()
  8067. "Stop the currently running clock."
  8068. (interactive)
  8069. (unless (marker-buffer org-clock-marker)
  8070. (error "No running clock"))
  8071. (let ((marker (make-marker)) newhead)
  8072. (org-with-remote-undo (marker-buffer org-clock-marker)
  8073. (with-current-buffer (marker-buffer org-clock-marker)
  8074. (save-excursion
  8075. (save-restriction
  8076. (widen)
  8077. (goto-char org-clock-marker)
  8078. (org-back-to-heading t)
  8079. (move-marker marker (point))
  8080. (org-clock-out)
  8081. (setq newhead (org-get-heading))))))
  8082. (org-agenda-change-all-lines newhead marker)
  8083. (move-marker marker nil)))
  8084. (defun org-agenda-clock-cancel (&optional arg)
  8085. "Cancel the currently running clock."
  8086. (interactive "P")
  8087. (unless (marker-buffer org-clock-marker)
  8088. (error "No running clock"))
  8089. (org-with-remote-undo (marker-buffer org-clock-marker)
  8090. (org-clock-cancel)))
  8091. (defun org-agenda-clock-goto ()
  8092. "Jump to the currently clocked in task within the agenda.
  8093. If the currently clocked in task is not listed in the agenda
  8094. buffer, display it in another window."
  8095. (interactive)
  8096. (let (pos)
  8097. (mapc (lambda (o)
  8098. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  8099. (setq pos (overlay-start o))))
  8100. (overlays-in (point-min) (point-max)))
  8101. (cond (pos (goto-char pos))
  8102. ;; If the currently clocked entry is not in the agenda
  8103. ;; buffer, we visit it in another window:
  8104. (org-clock-current-task
  8105. (org-switch-to-buffer-other-window (org-clock-goto)))
  8106. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  8107. (defun org-agenda-diary-entry-in-org-file ()
  8108. "Make a diary entry in the file `org-agenda-diary-file'."
  8109. (let (d1 d2 char (text "") dp1 dp2)
  8110. (if (equal (buffer-name) "*Calendar*")
  8111. (setq d1 (calendar-cursor-to-date t)
  8112. d2 (car calendar-mark-ring))
  8113. (setq dp1 (get-text-property (point-at-bol) 'day))
  8114. (unless dp1 (error "No date defined in current line"))
  8115. (setq d1 (calendar-gregorian-from-absolute dp1)
  8116. d2 (and (ignore-errors (mark))
  8117. (save-excursion
  8118. (goto-char (mark))
  8119. (setq dp2 (get-text-property (point-at-bol) 'day)))
  8120. (calendar-gregorian-from-absolute dp2))))
  8121. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  8122. (setq char (read-char-exclusive))
  8123. (cond
  8124. ((equal char ?d)
  8125. (setq text (read-string "Day entry: "))
  8126. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  8127. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8128. ((equal char ?a)
  8129. (setq d1 (list (car d1) (nth 1 d1)
  8130. (read-number (format "Reference year [%d]: " (nth 2 d1))
  8131. (nth 2 d1))))
  8132. (setq text (read-string "Anniversary (use %d to show years): "))
  8133. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  8134. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8135. ((equal char ?b)
  8136. (setq text (read-string "Block entry: "))
  8137. (unless (and d1 d2 (not (equal d1 d2)))
  8138. (error "No block of days selected"))
  8139. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  8140. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  8141. ((equal char ?j)
  8142. (org-switch-to-buffer-other-window
  8143. (find-file-noselect org-agenda-diary-file))
  8144. (require 'org-datetree)
  8145. (org-datetree-find-date-create d1)
  8146. (org-reveal t))
  8147. (t (error "Invalid selection character `%c'" char)))))
  8148. (defcustom org-agenda-insert-diary-strategy 'date-tree
  8149. "Where in `org-agenda-diary-file' should new entries be added?
  8150. Valid values:
  8151. date-tree in the date tree, as child of the date
  8152. top-level as top-level entries at the end of the file."
  8153. :group 'org-agenda
  8154. :type '(choice
  8155. (const :tag "in a date tree" date-tree)
  8156. (const :tag "as top level at end of file" top-level)))
  8157. (defcustom org-agenda-insert-diary-extract-time nil
  8158. "Non-nil means extract any time specification from the diary entry."
  8159. :group 'org-agenda
  8160. :version "24.1"
  8161. :type 'boolean)
  8162. (defcustom org-agenda-bulk-mark-char ">"
  8163. "A single-character string to be used as the bulk mark."
  8164. :group 'org-agenda
  8165. :version "24.1"
  8166. :type 'string)
  8167. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  8168. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  8169. If TEXT is not empty, it will become the headline of the new entry, and
  8170. the resulting entry will not be shown. When TEXT is empty, switch to
  8171. `org-agenda-diary-file' and let the user finish the entry there."
  8172. (let ((cw (current-window-configuration)))
  8173. (org-switch-to-buffer-other-window
  8174. (find-file-noselect org-agenda-diary-file))
  8175. (widen)
  8176. (goto-char (point-min))
  8177. (cond
  8178. ((eq type 'anniversary)
  8179. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  8180. (progn
  8181. (or (org-at-heading-p t)
  8182. (progn
  8183. (outline-next-heading)
  8184. (insert "* Anniversaries\n\n")
  8185. (beginning-of-line -1)))))
  8186. (outline-next-heading)
  8187. (org-back-over-empty-lines)
  8188. (backward-char 1)
  8189. (insert "\n")
  8190. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  8191. (nth 2 d1) (car d1) (nth 1 d1) text)))
  8192. ((eq type 'day)
  8193. (let ((org-prefix-has-time t)
  8194. (org-agenda-time-leading-zero t)
  8195. fmt time time2)
  8196. (if org-agenda-insert-diary-extract-time
  8197. ;; Use org-agenda-format-item to parse text for a time-range and
  8198. ;; remove it. FIXME: This is a hack, we should refactor
  8199. ;; that function to make time extraction available separately
  8200. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  8201. time (get-text-property 0 'time fmt)
  8202. time2 (if (> (length time) 0)
  8203. ;; split-string removes trailing ...... if
  8204. ;; no end time given. First space
  8205. ;; separates time from date.
  8206. (concat " " (car (split-string time "\\.")))
  8207. nil)
  8208. text (get-text-property 0 'txt fmt)))
  8209. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8210. (org-agenda-insert-diary-as-top-level text)
  8211. (require 'org-datetree)
  8212. (org-datetree-find-date-create d1)
  8213. (org-agenda-insert-diary-make-new-entry text))
  8214. (org-insert-time-stamp (org-time-from-absolute
  8215. (calendar-absolute-from-gregorian d1))
  8216. nil nil nil nil time2))
  8217. (end-of-line 0))
  8218. ((eq type 'block)
  8219. (if (> (calendar-absolute-from-gregorian d1)
  8220. (calendar-absolute-from-gregorian d2))
  8221. (setq d1 (prog1 d2 (setq d2 d1))))
  8222. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8223. (org-agenda-insert-diary-as-top-level text)
  8224. (require 'org-datetree)
  8225. (org-datetree-find-date-create d1)
  8226. (org-agenda-insert-diary-make-new-entry text))
  8227. (org-insert-time-stamp (org-time-from-absolute
  8228. (calendar-absolute-from-gregorian d1)))
  8229. (insert "--")
  8230. (org-insert-time-stamp (org-time-from-absolute
  8231. (calendar-absolute-from-gregorian d2)))
  8232. (end-of-line 0)))
  8233. (if (string-match "\\S-" text)
  8234. (progn
  8235. (set-window-configuration cw)
  8236. (message "%s entry added to %s"
  8237. (capitalize (symbol-name type))
  8238. (abbreviate-file-name org-agenda-diary-file)))
  8239. (org-reveal t)
  8240. (message "Please finish entry here"))))
  8241. (defun org-agenda-insert-diary-as-top-level (text)
  8242. "Make new entry as a top-level entry at the end of the file.
  8243. Add TEXT as headline, and position the cursor in the second line so that
  8244. a timestamp can be added there."
  8245. (widen)
  8246. (goto-char (point-max))
  8247. (or (bolp) (insert "\n"))
  8248. (insert "* " text "\n")
  8249. (if org-adapt-indentation (org-indent-to-column 2)))
  8250. (defun org-agenda-insert-diary-make-new-entry (text)
  8251. "Make new entry as last child of current entry.
  8252. Add TEXT as headline, and position the cursor in the second line so that
  8253. a timestamp can be added there."
  8254. (let ((org-show-following-heading t)
  8255. (org-show-siblings t)
  8256. (org-show-hierarchy-above t)
  8257. (org-show-entry-below t)
  8258. col)
  8259. (outline-next-heading)
  8260. (org-back-over-empty-lines)
  8261. (or (looking-at "[ \t]*$")
  8262. (progn (insert "\n") (backward-char 1)))
  8263. (org-insert-heading nil t)
  8264. (org-do-demote)
  8265. (setq col (current-column))
  8266. (insert text "\n")
  8267. (if org-adapt-indentation (org-indent-to-column col))
  8268. (let ((org-show-following-heading t)
  8269. (org-show-siblings t)
  8270. (org-show-hierarchy-above t)
  8271. (org-show-entry-below t))
  8272. (org-show-context))))
  8273. (defun org-agenda-diary-entry ()
  8274. "Make a diary entry, like the `i' command from the calendar.
  8275. All the standard commands work: block, weekly etc.
  8276. When `org-agenda-diary-file' points to a file,
  8277. `org-agenda-diary-entry-in-org-file' is called instead to create
  8278. entries in that Org-mode file."
  8279. (interactive)
  8280. (if (not (eq org-agenda-diary-file 'diary-file))
  8281. (org-agenda-diary-entry-in-org-file)
  8282. (require 'diary-lib)
  8283. (let* ((char (progn
  8284. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8285. (read-char-exclusive)))
  8286. (cmd (cdr (assoc char
  8287. '((?d . insert-diary-entry)
  8288. (?w . insert-weekly-diary-entry)
  8289. (?m . insert-monthly-diary-entry)
  8290. (?y . insert-yearly-diary-entry)
  8291. (?a . insert-anniversary-diary-entry)
  8292. (?b . insert-block-diary-entry)
  8293. (?c . insert-cyclic-diary-entry)))))
  8294. (oldf (symbol-function 'calendar-cursor-to-date))
  8295. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8296. (point (point))
  8297. (mark (or (mark t) (point))))
  8298. (unless cmd
  8299. (error "No command associated with <%c>" char))
  8300. (unless (and (get-text-property point 'day)
  8301. (or (not (equal ?b char))
  8302. (get-text-property mark 'day)))
  8303. (error "Don't know which date to use for diary entry"))
  8304. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8305. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8306. (let ((calendar-mark-ring
  8307. (list (calendar-gregorian-from-absolute
  8308. (or (get-text-property mark 'day)
  8309. (get-text-property point 'day))))))
  8310. (unwind-protect
  8311. (progn
  8312. (fset 'calendar-cursor-to-date
  8313. (lambda (&optional error dummy)
  8314. (calendar-gregorian-from-absolute
  8315. (get-text-property point 'day))))
  8316. (call-interactively cmd))
  8317. (fset 'calendar-cursor-to-date oldf))))))
  8318. (defun org-agenda-execute-calendar-command (cmd)
  8319. "Execute a calendar command from the agenda with date from cursor."
  8320. (org-agenda-check-type t 'agenda 'timeline)
  8321. (require 'diary-lib)
  8322. (unless (get-text-property (min (1- (point-max)) (point)) 'day)
  8323. (error "Don't know which date to use for the calendar command"))
  8324. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8325. (point (point))
  8326. (date (calendar-gregorian-from-absolute
  8327. (get-text-property point 'day)))
  8328. ;; the following 2 vars are needed in the calendar
  8329. (displayed-month (car date))
  8330. (displayed-year (nth 2 date)))
  8331. (unwind-protect
  8332. (progn
  8333. (fset 'calendar-cursor-to-date
  8334. (lambda (&optional error dummy)
  8335. (calendar-gregorian-from-absolute
  8336. (get-text-property point 'day))))
  8337. (call-interactively cmd))
  8338. (fset 'calendar-cursor-to-date oldf))))
  8339. (defun org-agenda-phases-of-moon ()
  8340. "Display the phases of the moon for the 3 months around the cursor date."
  8341. (interactive)
  8342. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8343. (defun org-agenda-holidays ()
  8344. "Display the holidays for the 3 months around the cursor date."
  8345. (interactive)
  8346. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8347. (defvar calendar-longitude) ; defined in calendar.el
  8348. (defvar calendar-latitude) ; defined in calendar.el
  8349. (defvar calendar-location-name) ; defined in calendar.el
  8350. (defun org-agenda-sunrise-sunset (arg)
  8351. "Display sunrise and sunset for the cursor date.
  8352. Latitude and longitude can be specified with the variables
  8353. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8354. argument, latitude and longitude will be prompted for."
  8355. (interactive "P")
  8356. (require 'solar)
  8357. (let ((calendar-longitude (if arg nil calendar-longitude))
  8358. (calendar-latitude (if arg nil calendar-latitude))
  8359. (calendar-location-name
  8360. (if arg "the given coordinates" calendar-location-name)))
  8361. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8362. (defun org-agenda-goto-calendar ()
  8363. "Open the Emacs calendar with the date at the cursor."
  8364. (interactive)
  8365. (org-agenda-check-type t 'agenda 'timeline)
  8366. (let* ((day (or (get-text-property (min (1- (point-max)) (point)) 'day)
  8367. (error "Don't know which date to open in calendar")))
  8368. (date (calendar-gregorian-from-absolute day))
  8369. (calendar-move-hook nil)
  8370. (calendar-view-holidays-initially-flag nil)
  8371. (calendar-view-diary-initially-flag nil))
  8372. (calendar)
  8373. (calendar-goto-date date)))
  8374. ;;;###autoload
  8375. (defun org-calendar-goto-agenda ()
  8376. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8377. This is a command that has to be installed in `calendar-mode-map'."
  8378. (interactive)
  8379. (org-agenda-list nil (calendar-absolute-from-gregorian
  8380. (calendar-cursor-to-date))
  8381. nil))
  8382. (autoload 'org-calendar-goto-agenda "org-agenda" "\
  8383. Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8384. This is a command that has to be installed in `calendar-mode-map'.
  8385. \(fn)" t nil)
  8386. (defun org-agenda-convert-date ()
  8387. (interactive)
  8388. (org-agenda-check-type t 'agenda 'timeline)
  8389. (let ((day (get-text-property (min (1- (point-max)) (point)) 'day))
  8390. date s)
  8391. (unless day
  8392. (error "Don't know which date to convert"))
  8393. (setq date (calendar-gregorian-from-absolute day))
  8394. (setq s (concat
  8395. "Gregorian: " (calendar-date-string date) "\n"
  8396. "ISO: " (calendar-iso-date-string date) "\n"
  8397. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8398. "Julian: " (calendar-julian-date-string date) "\n"
  8399. "Astron. JD: " (calendar-astro-date-string date)
  8400. " (Julian date number at noon UTC)\n"
  8401. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8402. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8403. "French: " (calendar-french-date-string date) "\n"
  8404. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8405. "Mayan: " (calendar-mayan-date-string date) "\n"
  8406. "Coptic: " (calendar-coptic-date-string date) "\n"
  8407. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8408. "Persian: " (calendar-persian-date-string date) "\n"
  8409. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8410. (with-output-to-temp-buffer "*Dates*"
  8411. (princ s))
  8412. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8413. ;;; Bulk commands
  8414. (defun org-agenda-bulk-marked-p ()
  8415. (eq (get-char-property (point-at-bol) 'type)
  8416. 'org-marked-entry-overlay))
  8417. (defun org-agenda-bulk-mark (&optional arg)
  8418. "Mark the entry at point for future bulk action."
  8419. (interactive "p")
  8420. (dotimes (i (or arg 1))
  8421. (unless (org-get-at-bol 'org-agenda-diary-link)
  8422. (let* ((m (org-get-at-bol 'org-hd-marker))
  8423. ov)
  8424. (unless (org-agenda-bulk-marked-p)
  8425. (unless m (error "Nothing to mark at point"))
  8426. (push m org-agenda-bulk-marked-entries)
  8427. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8428. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8429. (org-get-todo-face "TODO")
  8430. 'evaporate)
  8431. (overlay-put ov 'type 'org-marked-entry-overlay))
  8432. (beginning-of-line 2)
  8433. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8434. (beginning-of-line 2))
  8435. (message "%d entries marked for bulk action"
  8436. (length org-agenda-bulk-marked-entries))))))
  8437. (defun org-agenda-bulk-mark-all ()
  8438. "Mark all entries for future agenda bulk action."
  8439. (interactive)
  8440. (org-agenda-bulk-mark-regexp "."))
  8441. (defun org-agenda-bulk-mark-regexp (regexp)
  8442. "Mark entries matching REGEXP for future agenda bulk action."
  8443. (interactive "sMark entries matching regexp: ")
  8444. (let ((entries-marked 0))
  8445. (save-excursion
  8446. (goto-char (point-min))
  8447. (goto-char (next-single-property-change (point) 'txt))
  8448. (while (re-search-forward regexp nil t)
  8449. (when (string-match regexp (get-text-property (point) 'txt))
  8450. (setq entries-marked (1+ entries-marked))
  8451. (call-interactively 'org-agenda-bulk-mark))))
  8452. (if (not entries-marked)
  8453. (message "No entry matching this regexp."))))
  8454. (defun org-agenda-bulk-unmark (&optional arg)
  8455. "Unmark the entry at point for future bulk action."
  8456. (interactive "P")
  8457. (if arg
  8458. (org-agenda-bulk-unmark-all)
  8459. (cond ((org-agenda-bulk-marked-p)
  8460. (org-agenda-bulk-remove-overlays
  8461. (point-at-bol) (+ 2 (point-at-bol)))
  8462. (setq org-agenda-bulk-marked-entries
  8463. (delete (org-get-at-bol 'org-hd-marker)
  8464. org-agenda-bulk-marked-entries))
  8465. (beginning-of-line 2)
  8466. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8467. (beginning-of-line 2))
  8468. (message "%d entries left marked for bulk action"
  8469. (length org-agenda-bulk-marked-entries)))
  8470. (t (message "No entry to unmark here")))))
  8471. (defun org-agenda-bulk-toggle ()
  8472. "Toggle marking the entry at point for bulk action."
  8473. (interactive)
  8474. (if (org-agenda-bulk-marked-p)
  8475. (org-agenda-bulk-unmark)
  8476. (org-agenda-bulk-mark)))
  8477. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8478. "Remove the mark overlays between BEG and END in the agenda buffer.
  8479. BEG and END default to the buffer limits.
  8480. This only removes the overlays, it does not remove the markers
  8481. from the list in `org-agenda-bulk-marked-entries'."
  8482. (interactive)
  8483. (mapc (lambda (ov)
  8484. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8485. (delete-overlay ov)))
  8486. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8487. (defun org-agenda-bulk-unmark-all ()
  8488. "Remove all marks in the agenda buffer.
  8489. This will remove the markers and the overlays."
  8490. (interactive)
  8491. (if (null org-agenda-bulk-marked-entries)
  8492. (message "No entry to unmark")
  8493. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8494. (setq org-agenda-bulk-marked-entries nil)
  8495. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8496. (defcustom org-agenda-persistent-marks nil
  8497. "Non-nil means marked items will stay marked after a bulk action.
  8498. You can toggle this interactively by typing `p' when prompted for a
  8499. bulk action."
  8500. :group 'org-agenda
  8501. :version "24.1"
  8502. :type 'boolean)
  8503. (defun org-agenda-bulk-action (&optional arg)
  8504. "Execute an remote-editing action on all marked entries.
  8505. The prefix arg is passed through to the command if possible."
  8506. (interactive "P")
  8507. ;; Make sure we have markers, and only valid ones
  8508. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8509. (mapc
  8510. (lambda (m)
  8511. (unless (and (markerp m)
  8512. (marker-buffer m)
  8513. (buffer-live-p (marker-buffer m))
  8514. (marker-position m))
  8515. (error "Marker %s for bulk command is invalid" m)))
  8516. org-agenda-bulk-marked-entries)
  8517. ;; Prompt for the bulk command
  8518. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8519. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8520. "[S]catter [f]unction "
  8521. (when org-agenda-bulk-custom-functions
  8522. (concat " Custom: ["
  8523. (mapconcat (lambda(f) (char-to-string (car f)))
  8524. org-agenda-bulk-custom-functions "")
  8525. "]"))))
  8526. (catch 'exit
  8527. (let* ((action (read-char-exclusive))
  8528. (org-log-refile (if org-log-refile 'time nil))
  8529. (entries (reverse org-agenda-bulk-marked-entries))
  8530. (org-overriding-default-time
  8531. (if (get-text-property (point) 'org-agenda-date-header)
  8532. (org-get-cursor-date)))
  8533. redo-at-end
  8534. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8535. (cond
  8536. ((equal action ?p)
  8537. (let ((org-agenda-persistent-marks
  8538. (not org-agenda-persistent-marks)))
  8539. (org-agenda-bulk-action)
  8540. (throw 'exit nil)))
  8541. ((equal action ?$)
  8542. (setq cmd '(org-agenda-archive)))
  8543. ((equal action ?A)
  8544. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8545. ((member action '(?r ?w))
  8546. (setq rfloc (org-refile-get-location
  8547. "Refile to"
  8548. (marker-buffer (car entries))
  8549. org-refile-allow-creating-parent-nodes))
  8550. (if (nth 3 rfloc)
  8551. (setcar (nthcdr 3 rfloc)
  8552. (move-marker (make-marker) (nth 3 rfloc)
  8553. (or (get-file-buffer (nth 1 rfloc))
  8554. (find-buffer-visiting (nth 1 rfloc))
  8555. (error "This should not happen")))))
  8556. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8557. redo-at-end t))
  8558. ((equal action ?t)
  8559. (setq state (org-icompleting-read
  8560. "Todo state: "
  8561. (with-current-buffer (marker-buffer (car entries))
  8562. (mapcar 'list org-todo-keywords-1))))
  8563. (setq cmd `(let ((org-inhibit-blocking t)
  8564. (org-inhibit-logging 'note))
  8565. (org-agenda-todo ,state))))
  8566. ((memq action '(?- ?+))
  8567. (setq tag (org-icompleting-read
  8568. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8569. (with-current-buffer (marker-buffer (car entries))
  8570. (delq nil
  8571. (mapcar (lambda (x)
  8572. (if (stringp (car x)) x)) org-tag-alist)))))
  8573. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8574. ((memq action '(?s ?d))
  8575. (let* ((time
  8576. (unless arg
  8577. (org-read-date
  8578. nil nil nil
  8579. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to")
  8580. org-overriding-default-time)))
  8581. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8582. (setq cmd `(eval '(,c1 arg ,time)))))
  8583. ((equal action ?S)
  8584. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8585. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8586. (let ((days (read-number
  8587. (format "Scatter tasks across how many %sdays: "
  8588. (if arg "week" "")) 7)))
  8589. (setq cmd
  8590. `(let ((distance (1+ (random ,days))))
  8591. (if arg
  8592. (let ((dist distance)
  8593. (day-of-week
  8594. (calendar-day-of-week
  8595. (calendar-gregorian-from-absolute (org-today)))))
  8596. (dotimes (i (1+ dist))
  8597. (while (member day-of-week org-agenda-weekend-days)
  8598. (incf distance)
  8599. (incf day-of-week)
  8600. (if (= day-of-week 7)
  8601. (setq day-of-week 0)))
  8602. (incf day-of-week)
  8603. (if (= day-of-week 7)
  8604. (setq day-of-week 0)))))
  8605. ;; silently fail when try to replan a sexp entry
  8606. (condition-case nil
  8607. (let* ((date (calendar-gregorian-from-absolute
  8608. (+ (org-today) distance)))
  8609. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8610. (nth 2 date))))
  8611. (org-agenda-schedule nil time))
  8612. (error nil)))))))
  8613. ((assoc action org-agenda-bulk-custom-functions)
  8614. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8615. redo-at-end t))
  8616. ((equal action ?f)
  8617. (setq cmd (list (intern
  8618. (org-icompleting-read "Function: "
  8619. obarray 'fboundp t nil nil)))))
  8620. (t (error "Invalid bulk action")))
  8621. ;; Sort the markers, to make sure that parents are handled before children
  8622. (setq entries (sort entries
  8623. (lambda (a b)
  8624. (cond
  8625. ((equal (marker-buffer a) (marker-buffer b))
  8626. (< (marker-position a) (marker-position b)))
  8627. (t
  8628. (string< (buffer-name (marker-buffer a))
  8629. (buffer-name (marker-buffer b))))))))
  8630. ;; Now loop over all markers and apply cmd
  8631. (while (setq e (pop entries))
  8632. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8633. (if (not pos)
  8634. (progn (message "Skipping removed entry at %s" e)
  8635. (setq cntskip (1+ cntskip)))
  8636. (goto-char pos)
  8637. (let (org-loop-over-headlines-in-active-region)
  8638. (eval cmd))
  8639. (setq cnt (1+ cnt))))
  8640. (when redo-at-end (org-agenda-redo))
  8641. (unless org-agenda-persistent-marks
  8642. (org-agenda-bulk-unmark-all))
  8643. (message "Acted on %d entries%s%s"
  8644. cnt
  8645. (if (= cntskip 0)
  8646. ""
  8647. (format ", skipped %d (disappeared before their turn)"
  8648. cntskip))
  8649. (if (not org-agenda-persistent-marks)
  8650. "" " (kept marked)"))))))
  8651. (defun org-agenda-capture ()
  8652. "Call `org-capture' with the date at point."
  8653. (interactive)
  8654. (if (not (eq major-mode 'org-agenda-mode))
  8655. (error "You cannot do this outside of agenda buffers")
  8656. (let ((org-overriding-default-time
  8657. (org-get-cursor-date)))
  8658. (call-interactively 'org-capture))))
  8659. ;;; Flagging notes
  8660. (defun org-agenda-show-the-flagging-note ()
  8661. "Display the flagging note in the other window.
  8662. When called a second time in direct sequence, offer to remove the FLAGGING
  8663. tag and (if present) the flagging note."
  8664. (interactive)
  8665. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8666. (win (selected-window))
  8667. note heading newhead)
  8668. (unless hdmarker
  8669. (error "No linked entry at point"))
  8670. (if (and (eq this-command last-command)
  8671. (y-or-n-p "Unflag and remove any flagging note? "))
  8672. (progn
  8673. (org-agenda-remove-flag hdmarker)
  8674. (let ((win (get-buffer-window "*Flagging Note*")))
  8675. (and win (delete-window win)))
  8676. (message "Entry unflagged"))
  8677. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8678. (unless note
  8679. (error "No flagging note"))
  8680. (org-kill-new note)
  8681. (org-switch-to-buffer-other-window "*Flagging Note*")
  8682. (erase-buffer)
  8683. (insert note)
  8684. (goto-char (point-min))
  8685. (while (re-search-forward "\\\\n" nil t)
  8686. (replace-match "\n" t t))
  8687. (goto-char (point-min))
  8688. (select-window win)
  8689. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8690. (defun org-agenda-remove-flag (marker)
  8691. "Remove the FLAGGED tag and any flagging note in the entry."
  8692. (let (newhead)
  8693. (org-with-point-at marker
  8694. (org-toggle-tag "FLAGGED" 'off)
  8695. (org-entry-delete nil "THEFLAGGINGNOTE")
  8696. (setq newhead (org-get-heading)))
  8697. (org-agenda-change-all-lines newhead marker)
  8698. (message "Entry unflagged")))
  8699. (defun org-agenda-get-any-marker (&optional pos)
  8700. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8701. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8702. ;;; Appointment reminders
  8703. (defvar appt-time-msg-list) ; defined in appt.el
  8704. ;;;###autoload
  8705. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8706. "Activate appointments found in `org-agenda-files'.
  8707. With a \\[universal-argument] prefix, refresh the list of
  8708. appointments.
  8709. If FILTER is t, interactively prompt the user for a regular
  8710. expression, and filter out entries that don't match it.
  8711. If FILTER is a string, use this string as a regular expression
  8712. for filtering entries out.
  8713. If FILTER is a function, filter out entries against which
  8714. calling the function returns nil. This function takes one
  8715. argument: an entry from `org-agenda-get-day-entries'.
  8716. FILTER can also be an alist with the car of each cell being
  8717. either 'headline or 'category. For example:
  8718. '((headline \"IMPORTANT\")
  8719. (category \"Work\"))
  8720. will only add headlines containing IMPORTANT or headlines
  8721. belonging to the \"Work\" category.
  8722. ARGS are symbols indicating what kind of entries to consider.
  8723. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8724. and :timestamp entries. See the docstring of `org-diary' for
  8725. details and examples.
  8726. If an entry as a APPT_WARNTIME property, its value will be used
  8727. to override `appt-message-warning-time'."
  8728. (interactive "P")
  8729. (if refresh (setq appt-time-msg-list nil))
  8730. (if (eq filter t)
  8731. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8732. (let* ((cnt 0) ; count added events
  8733. (scope (or args '(:deadline :scheduled :timestamp)))
  8734. (org-agenda-new-buffers nil)
  8735. (org-deadline-warning-days 0)
  8736. ;; Do not use `org-today' here because appt only takes
  8737. ;; time and without date as argument, so it may pass wrong
  8738. ;; information otherwise
  8739. (today (org-date-to-gregorian
  8740. (time-to-days (current-time))))
  8741. (org-agenda-restrict nil)
  8742. (files (org-agenda-files 'unrestricted)) entries file
  8743. (org-agenda-buffer nil))
  8744. ;; Get all entries which may contain an appt
  8745. (org-agenda-prepare-buffers files)
  8746. (while (setq file (pop files))
  8747. (setq entries
  8748. (delq nil
  8749. (append entries
  8750. (apply 'org-agenda-get-day-entries
  8751. file today scope)))))
  8752. ;; Map thru entries and find if we should filter them out
  8753. (mapc
  8754. (lambda(x)
  8755. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8756. (cat (get-text-property 1 'org-category x))
  8757. (tod (get-text-property 1 'time-of-day x))
  8758. (ok (or (null filter)
  8759. (and (stringp filter) (string-match filter evt))
  8760. (and (functionp filter) (funcall filter x))
  8761. (and (listp filter)
  8762. (let ((cat-filter (cadr (assoc 'category filter)))
  8763. (evt-filter (cadr (assoc 'headline filter))))
  8764. (or (and (stringp cat-filter)
  8765. (string-match cat-filter cat))
  8766. (and (stringp evt-filter)
  8767. (string-match evt-filter evt)))))))
  8768. (wrn (get-text-property 1 'warntime x)))
  8769. ;; FIXME: Shall we remove text-properties for the appt text?
  8770. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8771. (when (and ok tod)
  8772. (setq tod (concat "00" (number-to-string tod))
  8773. tod (when (string-match
  8774. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8775. (concat (match-string 1 tod) ":"
  8776. (match-string 2 tod))))
  8777. (if (version< emacs-version "23.3")
  8778. (appt-add tod evt)
  8779. (appt-add tod evt wrn))
  8780. (setq cnt (1+ cnt))))) entries)
  8781. (org-release-buffers org-agenda-new-buffers)
  8782. (if (eq cnt 0)
  8783. (message "No event to add")
  8784. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8785. (autoload 'org-agenda-to-appt "org-agenda" "\
  8786. Activate appointments found in `org-agenda-files'.
  8787. With a \\[universal-argument] prefix, refresh the list of
  8788. appointments.
  8789. If FILTER is t, interactively prompt the user for a regular
  8790. expression, and filter out entries that don't match it.
  8791. If FILTER is a string, use this string as a regular expression
  8792. for filtering entries out.
  8793. If FILTER is a function, filter out entries against which
  8794. calling the function returns nil. This function takes one
  8795. argument: an entry from `org-agenda-get-day-entries'.
  8796. FILTER can also be an alist with the car of each cell being
  8797. either 'headline or 'category. For example:
  8798. '((headline \"IMPORTANT\")
  8799. (category \"Work\"))
  8800. will only add headlines containing IMPORTANT or headlines
  8801. belonging to the \"Work\" category.
  8802. ARGS are symbols indicating what kind of entries to consider.
  8803. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8804. and :timestamp entries. See the docstring of `org-diary' for
  8805. details and examples.
  8806. If an entry as a APPT_WARNTIME property, its value will be used
  8807. to override `appt-message-warning-time'.
  8808. \(fn &optional REFRESH FILTER &rest ARGS)" t nil)
  8809. (defun org-agenda-todayp (date)
  8810. "Does DATE mean today, when considering `org-extend-today-until'?"
  8811. (let ((today (org-today))
  8812. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8813. date)))
  8814. (eq date today)))
  8815. (defun org-agenda-todo-yesterday (&optional arg)
  8816. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8817. (interactive "P")
  8818. (let* ((hour (third (decode-time
  8819. (org-current-time))))
  8820. (org-extend-today-until (1+ hour)))
  8821. (org-agenda-todo arg)))
  8822. (provide 'org-agenda)
  8823. ;;; org-agenda.el ends here