org-agenda.el 355 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245
  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 nil)
  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 temporary buffer before writing it to an export file.
  144. A useful function 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 it is by 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 ""
  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. However,
  200. <style>...</style> is required, if not present the variable will be ignored."
  201. :group 'org-agenda-export
  202. :group 'org-export-html
  203. :type 'string)
  204. (defcustom org-agenda-persistent-filter nil
  205. "When set, keep filters from one agenda view to the next."
  206. :group 'org-agenda
  207. :type 'boolean)
  208. (defgroup org-agenda-custom-commands nil
  209. "Options concerning agenda views in Org-mode."
  210. :tag "Org Agenda Custom Commands"
  211. :group 'org-agenda)
  212. (defconst org-sorting-choice
  213. '(choice
  214. (const time-up) (const time-down)
  215. (const category-keep) (const category-up) (const category-down)
  216. (const tag-down) (const tag-up)
  217. (const priority-up) (const priority-down)
  218. (const todo-state-up) (const todo-state-down)
  219. (const effort-up) (const effort-down)
  220. (const habit-up) (const habit-down)
  221. (const alpha-up) (const alpha-down)
  222. (const user-defined-up) (const user-defined-down))
  223. "Sorting choices.")
  224. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  225. ;; the new variable `org-agenda-tag-filter-preset'.
  226. (if (fboundp 'defvaralias)
  227. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  228. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  229. (defconst org-agenda-custom-commands-local-options
  230. `(repeat :tag "Local settings for this command. Remember to quote values"
  231. (choice :tag "Setting"
  232. (list :tag "Heading for this block"
  233. (const org-agenda-overriding-header)
  234. (string :tag "Headline"))
  235. (list :tag "Files to be searched"
  236. (const org-agenda-files)
  237. (list
  238. (const :format "" quote)
  239. (repeat (file))))
  240. (list :tag "Sorting strategy"
  241. (const org-agenda-sorting-strategy)
  242. (list
  243. (const :format "" quote)
  244. (repeat
  245. ,org-sorting-choice)))
  246. (list :tag "Prefix format"
  247. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  248. (string))
  249. (list :tag "Number of days in agenda"
  250. (const org-agenda-span)
  251. (choice (const :tag "Day" 'day)
  252. (const :tag "Week" 'week)
  253. (const :tag "Month" 'month)
  254. (const :tag "Year" 'year)
  255. (integer :tag "Custom")))
  256. (list :tag "Fixed starting date"
  257. (const org-agenda-start-day)
  258. (string :value "2007-11-01"))
  259. (list :tag "Start on day of week"
  260. (const org-agenda-start-on-weekday)
  261. (choice :value 1
  262. (const :tag "Today" nil)
  263. (integer :tag "Weekday No.")))
  264. (list :tag "Include data from diary"
  265. (const org-agenda-include-diary)
  266. (boolean))
  267. (list :tag "Deadline Warning days"
  268. (const org-deadline-warning-days)
  269. (integer :value 1))
  270. (list :tag "Category filter preset"
  271. (const org-agenda-category-filter-preset)
  272. (list
  273. (const :format "" quote)
  274. (repeat
  275. (string :tag "+category or -category"))))
  276. (list :tag "Tags filter preset"
  277. (const org-agenda-tag-filter-preset)
  278. (list
  279. (const :format "" quote)
  280. (repeat
  281. (string :tag "+tag or -tag"))))
  282. (list :tag "Set daily/weekly entry types"
  283. (const org-agenda-entry-types)
  284. (list
  285. (const :format "" quote)
  286. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  287. (const :deadline)
  288. (const :scheduled)
  289. (const :timestamp)
  290. (const :sexp))))
  291. (list :tag "Standard skipping condition"
  292. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  293. (const org-agenda-skip-function)
  294. (list
  295. (const :format "" quote)
  296. (list
  297. (choice
  298. :tag "Skipping range"
  299. (const :tag "Skip entry" org-agenda-skip-entry-if)
  300. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  301. (repeat :inline t :tag "Conditions for skipping"
  302. (choice
  303. :tag "Condition type"
  304. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  305. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  306. (list :tag "TODO state is" :inline t
  307. (const 'todo)
  308. (choice
  309. (const :tag "any not-done state" 'todo)
  310. (const :tag "any done state" 'done)
  311. (const :tag "any state" 'any)
  312. (list :tag "Keyword list"
  313. (const :format "" quote)
  314. (repeat (string :tag "Keyword")))))
  315. (list :tag "TODO state is not" :inline t
  316. (const 'nottodo)
  317. (choice
  318. (const :tag "any not-done state" 'todo)
  319. (const :tag "any done state" 'done)
  320. (const :tag "any state" 'any)
  321. (list :tag "Keyword list"
  322. (const :format "" quote)
  323. (repeat (string :tag "Keyword")))))
  324. (const :tag "scheduled" 'scheduled)
  325. (const :tag "not scheduled" 'notscheduled)
  326. (const :tag "deadline" 'deadline)
  327. (const :tag "no deadline" 'notdeadline)
  328. (const :tag "timestamp" 'timestamp)
  329. (const :tag "no timestamp" 'nottimestamp))))))
  330. (list :tag "Non-standard skipping condition"
  331. :value (org-agenda-skip-function)
  332. (const org-agenda-skip-function)
  333. (sexp :tag "Function or form (quoted!)"))
  334. (list :tag "Any variable"
  335. (variable :tag "Variable")
  336. (sexp :tag "Value (sexp)"))))
  337. "Selection of examples for agenda command settings.
  338. This will be spliced into the custom type of
  339. `org-agenda-custom-commands'.")
  340. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  341. ((agenda "") (alltodo))))
  342. "Custom commands for the agenda.
  343. These commands will be offered on the splash screen displayed by the
  344. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  345. (key desc type match settings files)
  346. key The key (one or more characters as a string) to be associated
  347. with the command.
  348. desc A description of the command, when omitted or nil, a default
  349. description is built using MATCH.
  350. type The command type, any of the following symbols:
  351. agenda The daily/weekly agenda.
  352. todo Entries with a specific TODO keyword, in all agenda files.
  353. search Entries containing search words entry or headline.
  354. tags Tags/Property/TODO match in all agenda files.
  355. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  356. todo-tree Sparse tree of specific TODO keyword in *current* file.
  357. tags-tree Sparse tree with all tags matches in *current* file.
  358. occur-tree Occur sparse tree for *current* file.
  359. ... A user-defined function.
  360. match What to search for:
  361. - a single keyword for TODO keyword searches
  362. - a tags match expression for tags searches
  363. - a word search expression for text searches.
  364. - a regular expression for occur searches
  365. For all other commands, this should be the empty string.
  366. settings A list of option settings, similar to that in a let form, so like
  367. this: ((opt1 val1) (opt2 val2) ...). The values will be
  368. evaluated at the moment of execution, so quote them when needed.
  369. files A list of files file to write the produced agenda buffer to
  370. with the command `org-store-agenda-views'.
  371. If a file name ends in \".html\", an HTML version of the buffer
  372. is written out. If it ends in \".ps\", a postscript version is
  373. produced. Otherwise, only the plain text is written to the file.
  374. You can also define a set of commands, to create a composite agenda buffer.
  375. In this case, an entry looks like this:
  376. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  377. where
  378. desc A description string to be displayed in the dispatcher menu.
  379. cmd An agenda command, similar to the above. However, tree commands
  380. are not allowed, but instead you can get agenda and global todo list.
  381. So valid commands for a set are:
  382. (agenda \"\" settings)
  383. (alltodo \"\" settings)
  384. (stuck \"\" settings)
  385. (todo \"match\" settings files)
  386. (search \"match\" settings files)
  387. (tags \"match\" settings files)
  388. (tags-todo \"match\" settings files)
  389. Each command can carry a list of options, and another set of options can be
  390. given for the whole set of commands. Individual command options take
  391. precedence over the general options.
  392. When using several characters as key to a command, the first characters
  393. are prefix commands. For the dispatcher to display useful information, you
  394. should provide a description for the prefix, like
  395. (setq org-agenda-custom-commands
  396. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  397. (\"hl\" tags \"+HOME+Lisa\")
  398. (\"hp\" tags \"+HOME+Peter\")
  399. (\"hk\" tags \"+HOME+Kim\")))"
  400. :group 'org-agenda-custom-commands
  401. :type `(repeat
  402. (choice :value ("x" "Describe command here" tags "" nil)
  403. (list :tag "Single command"
  404. (string :tag "Access Key(s) ")
  405. (option (string :tag "Description"))
  406. (choice
  407. (const :tag "Agenda" agenda)
  408. (const :tag "TODO list" alltodo)
  409. (const :tag "Search words" search)
  410. (const :tag "Stuck projects" stuck)
  411. (const :tag "Tags/Property match (all agenda files)" tags)
  412. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  413. (const :tag "TODO keyword search (all agenda files)" todo)
  414. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  415. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  416. (const :tag "Occur tree (current buffer)" occur-tree)
  417. (sexp :tag "Other, user-defined function"))
  418. (string :tag "Match (only for some commands)")
  419. ,org-agenda-custom-commands-local-options
  420. (option (repeat :tag "Export" (file :tag "Export to"))))
  421. (list :tag "Command series, all agenda files"
  422. (string :tag "Access Key(s)")
  423. (string :tag "Description ")
  424. (repeat :tag "Component"
  425. (choice
  426. (list :tag "Agenda"
  427. (const :format "" agenda)
  428. (const :tag "" :format "" "")
  429. ,org-agenda-custom-commands-local-options)
  430. (list :tag "TODO list (all keywords)"
  431. (const :format "" alltodo)
  432. (const :tag "" :format "" "")
  433. ,org-agenda-custom-commands-local-options)
  434. (list :tag "Search words"
  435. (const :format "" search)
  436. (string :tag "Match")
  437. ,org-agenda-custom-commands-local-options)
  438. (list :tag "Stuck projects"
  439. (const :format "" stuck)
  440. (const :tag "" :format "" "")
  441. ,org-agenda-custom-commands-local-options)
  442. (list :tag "Tags search"
  443. (const :format "" tags)
  444. (string :tag "Match")
  445. ,org-agenda-custom-commands-local-options)
  446. (list :tag "Tags search, TODO entries only"
  447. (const :format "" tags-todo)
  448. (string :tag "Match")
  449. ,org-agenda-custom-commands-local-options)
  450. (list :tag "TODO keyword search"
  451. (const :format "" todo)
  452. (string :tag "Match")
  453. ,org-agenda-custom-commands-local-options)
  454. (list :tag "Other, user-defined function"
  455. (symbol :tag "function")
  456. (string :tag "Match")
  457. ,org-agenda-custom-commands-local-options)))
  458. (repeat :tag "Settings for entire command set"
  459. (list (variable :tag "Any variable")
  460. (sexp :tag "Value")))
  461. (option (repeat :tag "Export" (file :tag "Export to"))))
  462. (cons :tag "Prefix key documentation"
  463. (string :tag "Access Key(s)")
  464. (string :tag "Description ")))))
  465. (defcustom org-agenda-query-register ?o
  466. "The register holding the current query string.
  467. The purpose of this is that if you construct a query string interactively,
  468. you can then use it to define a custom command."
  469. :group 'org-agenda-custom-commands
  470. :type 'character)
  471. (defcustom org-stuck-projects
  472. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  473. "How to identify stuck projects.
  474. This is a list of four items:
  475. 1. A tags/todo/property matcher string that is used to identify a project.
  476. See the manual for a description of tag and property searches.
  477. The entire tree below a headline matched by this is considered one project.
  478. 2. A list of TODO keywords identifying non-stuck projects.
  479. If the project subtree contains any headline with one of these todo
  480. keywords, the project is considered to be not stuck. If you specify
  481. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  482. 3. A list of tags identifying non-stuck projects.
  483. If the project subtree contains any headline with one of these tags,
  484. the project is considered to be not stuck. If you specify \"*\" as
  485. a tag, any tag will mark the project unstuck. Note that this is about
  486. the explicit presence of a tag somewhere in the subtree, inherited
  487. tags to not count here. If inherited tags make a project not stuck,
  488. use \"-TAG\" in the tags part of the matcher under (1.) above.
  489. 4. An arbitrary regular expression matching non-stuck projects.
  490. If the project turns out to be not stuck, search continues also in the
  491. subtree to see if any of the subtasks have project status.
  492. See also the variable `org-tags-match-list-sublevels' which applies
  493. to projects matched by this search as well.
  494. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  495. or `C-c a #' to produce the list."
  496. :group 'org-agenda-custom-commands
  497. :type '(list
  498. (string :tag "Tags/TODO match to identify a project")
  499. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  500. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  501. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  502. (defcustom org-agenda-filter-effort-default-operator "<"
  503. "The default operator for effort estimate filtering.
  504. If you select an effort estimate limit without first pressing an operator,
  505. this one will be used."
  506. :group 'org-agenda-custom-commands
  507. :type '(choice (const :tag "less or equal" "<")
  508. (const :tag "greater or equal"">")
  509. (const :tag "equal" "=")))
  510. (defgroup org-agenda-skip nil
  511. "Options concerning skipping parts of agenda files."
  512. :tag "Org Agenda Skip"
  513. :group 'org-agenda)
  514. (defcustom org-agenda-skip-function-global nil
  515. "Function to be called at each match during agenda construction.
  516. If this function returns nil, the current match should not be skipped.
  517. If the function decided to skip an agenda match, is must return the
  518. buffer position from which the search should be continued.
  519. This may also be a Lisp form, which will be evaluated.
  520. This variable will be applied to every agenda match, including
  521. tags/property searches and TODO lists. So try to make the test function
  522. do its checking as efficiently as possible. To implement a skipping
  523. condition just for specific agenda commands, use the variable
  524. `org-agenda-skip-function' which can be set in the options section
  525. of custom agenda commands."
  526. :group 'org-agenda-skip
  527. :type 'sexp)
  528. (defgroup org-agenda-daily/weekly nil
  529. "Options concerning the daily/weekly agenda."
  530. :tag "Org Agenda Daily/Weekly"
  531. :group 'org-agenda)
  532. (defgroup org-agenda-todo-list nil
  533. "Options concerning the global todo list agenda view."
  534. :tag "Org Agenda Todo List"
  535. :group 'org-agenda)
  536. (defgroup org-agenda-match-view nil
  537. "Options concerning the general tags/property/todo match agenda view."
  538. :tag "Org Agenda Match View"
  539. :group 'org-agenda)
  540. (defgroup org-agenda-search-view nil
  541. "Options concerning the general tags/property/todo match agenda view."
  542. :tag "Org Agenda Match View"
  543. :group 'org-agenda)
  544. (defvar org-agenda-archives-mode nil
  545. "Non-nil means the agenda will include archived items.
  546. If this is the symbol `trees', trees in the selected agenda scope
  547. that are marked with the ARCHIVE tag will be included anyway. When this is
  548. t, also all archive files associated with the current selection of agenda
  549. files will be included.")
  550. (defcustom org-agenda-skip-comment-trees t
  551. "Non-nil means skip trees that start with the COMMENT keyword.
  552. When nil, these trees are also scanned by agenda commands."
  553. :group 'org-agenda-skip
  554. :type 'boolean)
  555. (defcustom org-agenda-todo-list-sublevels t
  556. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  557. When nil, the sublevels of a TODO entry are not checked, resulting in
  558. potentially much shorter TODO lists."
  559. :group 'org-agenda-skip
  560. :group 'org-agenda-todo-list
  561. :type 'boolean)
  562. (defcustom org-agenda-todo-ignore-with-date nil
  563. "Non-nil means don't show entries with a date in the global todo list.
  564. You can use this if you prefer to mark mere appointments with a TODO keyword,
  565. but don't want them to show up in the TODO list.
  566. When this is set, it also covers deadlines and scheduled items, the settings
  567. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  568. will be ignored.
  569. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  570. :group 'org-agenda-skip
  571. :group 'org-agenda-todo-list
  572. :type 'boolean)
  573. (defcustom org-agenda-todo-ignore-timestamp nil
  574. "Non-nil means don't show entries with a timestamp.
  575. This applies when creating the global todo list.
  576. Valid values are:
  577. past Don't show entries for today or in the past.
  578. future Don't show entries with a timestamp in the future.
  579. The idea behind this is that if it has a future
  580. timestamp, you don't want to think about it until the
  581. date.
  582. all Don't show any entries with a timestamp in the global todo list.
  583. The idea behind this is that by setting a timestamp, you
  584. have already \"taken care\" of this item.
  585. This variable can also have an integer as a value. If positive (N),
  586. todos with a timestamp N or more days in the future will be ignored. If
  587. negative (-N), todos with a timestamp N or more days in the past will be
  588. ignored. If 0, todos with a timestamp either today or in the future will
  589. be ignored. For example, a value of -1 will exclude todos with a
  590. timestamp in the past (yesterday or earlier), while a value of 7 will
  591. exclude todos with a timestamp a week or more in the future.
  592. See also `org-agenda-todo-ignore-with-date'.
  593. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  594. to make his option also apply to the tags-todo list."
  595. :group 'org-agenda-skip
  596. :group 'org-agenda-todo-list
  597. :version "24.1"
  598. :type '(choice
  599. (const :tag "Ignore future timestamp todos" future)
  600. (const :tag "Ignore past or present timestamp todos" past)
  601. (const :tag "Ignore all timestamp todos" all)
  602. (const :tag "Show timestamp todos" nil)
  603. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  604. (defcustom org-agenda-todo-ignore-scheduled nil
  605. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  606. This applies when creating the global todo list.
  607. Valid values are:
  608. past Don't show entries scheduled today or in the past.
  609. future Don't show entries scheduled in the future.
  610. The idea behind this is that by scheduling it, you don't want to
  611. think about it until the scheduled date.
  612. all Don't show any scheduled entries in the global todo list.
  613. The idea behind this is that by scheduling it, you have already
  614. \"taken care\" of this item.
  615. t Same as `all', for backward compatibility.
  616. This variable can also have an integer as a value. See
  617. `org-agenda-todo-ignore-timestamp' for more details.
  618. See also `org-agenda-todo-ignore-with-date'.
  619. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  620. to make his option also apply to the tags-todo list."
  621. :group 'org-agenda-skip
  622. :group 'org-agenda-todo-list
  623. :type '(choice
  624. (const :tag "Ignore future-scheduled todos" future)
  625. (const :tag "Ignore past- or present-scheduled todos" past)
  626. (const :tag "Ignore all scheduled todos" all)
  627. (const :tag "Ignore all scheduled todos (compatibility)" t)
  628. (const :tag "Show scheduled todos" nil)
  629. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  630. (defcustom org-agenda-todo-ignore-deadlines nil
  631. "Non-nil means ignore some deadlined TODO items when making TODO list.
  632. There are different motivations for using different values, please think
  633. carefully when configuring this variable.
  634. This applies when creating the global todo list.
  635. Valid values are:
  636. near Don't show near deadline entries. A deadline is near when it is
  637. closer than `org-deadline-warning-days' days. The idea behind this
  638. is that such items will appear in the agenda anyway.
  639. far Don't show TODO entries where a deadline has been defined, but
  640. the deadline is not near. This is useful if you don't want to
  641. use the todo list to figure out what to do now.
  642. past Don't show entries with a deadline timestamp for today or in the past.
  643. future Don't show entries with a deadline timestamp in the future, not even
  644. when they become `near' ones. Use it with caution.
  645. all Ignore all TODO entries that do have a deadline.
  646. t Same as `near', for backward compatibility.
  647. This variable can also have an integer as a value. See
  648. `org-agenda-todo-ignore-timestamp' for more details.
  649. See also `org-agenda-todo-ignore-with-date'.
  650. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  651. to make his option also apply to the tags-todo list."
  652. :group 'org-agenda-skip
  653. :group 'org-agenda-todo-list
  654. :type '(choice
  655. (const :tag "Ignore near deadlines" near)
  656. (const :tag "Ignore near deadlines (compatibility)" t)
  657. (const :tag "Ignore far deadlines" far)
  658. (const :tag "Ignore all TODOs with a deadlines" all)
  659. (const :tag "Show all TODOs, even if they have a deadline" nil)
  660. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  661. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  662. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  663. The variables
  664. `org-agenda-todo-ignore-with-date',
  665. `org-agenda-todo-ignore-timestamp',
  666. `org-agenda-todo-ignore-scheduled',
  667. `org-agenda-todo-ignore-deadlines'
  668. make the global TODO list skip entries that have time stamps of certain
  669. kinds. If this option is set, the same options will also apply for the
  670. tags-todo search, which is the general tags/property matcher
  671. restricted to unfinished TODO entries only."
  672. :group 'org-agenda-skip
  673. :group 'org-agenda-todo-list
  674. :group 'org-agenda-match-view
  675. :type 'boolean)
  676. (defcustom org-agenda-skip-scheduled-if-done nil
  677. "Non-nil means don't show scheduled items in agenda when they are done.
  678. This is relevant for the daily/weekly agenda, not for the TODO list. And
  679. it applies only to the actual date of the scheduling. Warnings about
  680. an item with a past scheduling dates are always turned off when the item
  681. is DONE."
  682. :group 'org-agenda-skip
  683. :group 'org-agenda-daily/weekly
  684. :type 'boolean)
  685. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  686. "Non-nil means skip scheduling line if same entry shows because of deadline.
  687. In the agenda of today, an entry can show up multiple times because
  688. it is both scheduled and has a nearby deadline, and maybe a plain time
  689. stamp as well.
  690. When this variable is t, then only the deadline is shown and the fact that
  691. the entry is scheduled today or was scheduled previously is not shown.
  692. When this variable is nil, the entry will be shown several times. When
  693. the variable is the symbol `not-today', then skip scheduled previously,
  694. but not scheduled today."
  695. :group 'org-agenda-skip
  696. :group 'org-agenda-daily/weekly
  697. :type '(choice
  698. (const :tag "Never" nil)
  699. (const :tag "Always" t)
  700. (const :tag "Not when scheduled today" not-today)))
  701. (defcustom org-agenda-skip-timestamp-if-deadline-is-shown nil
  702. "Non-nil means skip timestamp line if same entry shows because of deadline.
  703. In the agenda of today, an entry can show up multiple times
  704. because it has both a plain timestamp and has a nearby deadline.
  705. When this variable is t, then only the deadline is shown and the
  706. fact that the entry has a timestamp for or including today is not
  707. shown. When this variable is nil, the entry will be shown
  708. several times."
  709. :group 'org-agenda-skip
  710. :group 'org-agenda-daily/weekly
  711. :version "24.1"
  712. :type '(choice
  713. (const :tag "Never" nil)
  714. (const :tag "Always" t)))
  715. (defcustom org-agenda-skip-deadline-if-done nil
  716. "Non-nil means don't show deadlines when the corresponding item is done.
  717. When nil, the deadline is still shown and should give you a happy feeling.
  718. This is relevant for the daily/weekly agenda. And it applied only to the
  719. actually date of the deadline. Warnings about approaching and past-due
  720. deadlines are always turned off when the item is DONE."
  721. :group 'org-agenda-skip
  722. :group 'org-agenda-daily/weekly
  723. :type 'boolean)
  724. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  725. "Non-nil means skip deadline prewarning when entry is also scheduled.
  726. This will apply on all days where a prewarning for the deadline would
  727. be shown, but not at the day when the entry is actually due. On that day,
  728. the deadline will be shown anyway.
  729. This variable may be set to nil, t, or a number which will then give
  730. the number of days before the actual deadline when the prewarnings
  731. should resume.
  732. This can be used in a workflow where the first showing of the deadline will
  733. trigger you to schedule it, and then you don't want to be reminded of it
  734. because you will take care of it on the day when scheduled."
  735. :group 'org-agenda-skip
  736. :group 'org-agenda-daily/weekly
  737. :version "24.1"
  738. :type '(choice
  739. (const :tag "Alwas show prewarning" nil)
  740. (const :tag "Remove prewarning if entry is scheduled" t)
  741. (integer :tag "Restart prewarning N days before deadline")))
  742. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  743. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  744. When non-nil, after the search for timestamps has matched once in an
  745. entry, the rest of the entry will not be searched."
  746. :group 'org-agenda-skip
  747. :type 'boolean)
  748. (defcustom org-agenda-skip-timestamp-if-done nil
  749. "Non-nil means don't select item by timestamp or -range if it is DONE."
  750. :group 'org-agenda-skip
  751. :group 'org-agenda-daily/weekly
  752. :type 'boolean)
  753. (defcustom org-agenda-dim-blocked-tasks t
  754. "Non-nil means dim blocked tasks in the agenda display.
  755. This causes some overhead during agenda construction, but if you
  756. have turned on `org-enforce-todo-dependencies',
  757. `org-enforce-todo-checkbox-dependencies', or any other blocking
  758. mechanism, this will create useful feedback in the agenda.
  759. Instead of t, this variable can also have the value `invisible'.
  760. Then blocked tasks will be invisible and only become visible when
  761. they become unblocked. An exemption to this behavior is when a task is
  762. blocked because of unchecked checkboxes below it. Since checkboxes do
  763. not show up in the agenda views, making this task invisible you remove any
  764. trace from agenda views that there is something to do. Therefore, a task
  765. that is blocked because of checkboxes will never be made invisible, it
  766. will only be dimmed."
  767. :group 'org-agenda-daily/weekly
  768. :group 'org-agenda-todo-list
  769. :type '(choice
  770. (const :tag "Do not dim" nil)
  771. (const :tag "Dim to a gray face" t)
  772. (const :tag "Make invisible" invisible)))
  773. (defcustom org-timeline-show-empty-dates 3
  774. "Non-nil means `org-timeline' also shows dates without an entry.
  775. When nil, only the days which actually have entries are shown.
  776. When t, all days between the first and the last date are shown.
  777. When an integer, show also empty dates, but if there is a gap of more than
  778. N days, just insert a special line indicating the size of the gap."
  779. :group 'org-agenda-skip
  780. :type '(choice
  781. (const :tag "None" nil)
  782. (const :tag "All" t)
  783. (integer :tag "at most")))
  784. (defgroup org-agenda-startup nil
  785. "Options concerning initial settings in the Agenda in Org Mode."
  786. :tag "Org Agenda Startup"
  787. :group 'org-agenda)
  788. (defcustom org-agenda-menu-show-matcher t
  789. "Non-nil means show the match string in the agenda dispatcher menu.
  790. When nil, the matcher string is not shown, but is put into the help-echo
  791. property so than moving the mouse over the command shows it.
  792. Setting it to nil is good if matcher strings are very long and/or if
  793. you want to use two-columns display (see `org-agenda-menu-two-columns')."
  794. :group 'org-agenda
  795. :version "24.1"
  796. :type 'boolean)
  797. (make-obsolete-variable 'org-agenda-menu-two-column 'org-agenda-menu-two-columns "24.3")
  798. (defcustom org-agenda-menu-two-columns nil
  799. "Non-nil means, use two columns to show custom commands in the dispatcher.
  800. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  801. to nil."
  802. :group 'org-agenda
  803. :version "24.1"
  804. :type 'boolean)
  805. (make-obsolete-variable 'org-finalize-agenda-hook 'org-agenda-finalize-hook "24.3")
  806. (defcustom org-agenda-finalize-hook nil
  807. "Hook run just before displaying an agenda buffer."
  808. :group 'org-agenda-startup
  809. :type 'hook)
  810. (defcustom org-agenda-mouse-1-follows-link nil
  811. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  812. A longer mouse click will still set point. Does not work on XEmacs.
  813. Needs to be set before org.el is loaded."
  814. :group 'org-agenda-startup
  815. :type 'boolean)
  816. (defcustom org-agenda-start-with-follow-mode nil
  817. "The initial value of follow mode in a newly created agenda window."
  818. :group 'org-agenda-startup
  819. :type 'boolean)
  820. (defcustom org-agenda-follow-indirect nil
  821. "Non-nil means `org-agenda-follow-mode' displays only the
  822. current item's tree, in an indirect buffer."
  823. :group 'org-agenda
  824. :version "24.1"
  825. :type 'boolean)
  826. (defcustom org-agenda-show-outline-path t
  827. "Non-nil means show outline path in echo area after line motion."
  828. :group 'org-agenda-startup
  829. :type 'boolean)
  830. (defcustom org-agenda-start-with-entry-text-mode nil
  831. "The initial value of entry-text-mode in a newly created agenda window."
  832. :group 'org-agenda-startup
  833. :type 'boolean)
  834. (defcustom org-agenda-entry-text-maxlines 5
  835. "Number of text lines to be added when `E' is pressed in the agenda.
  836. Note that this variable only used during agenda display. Add add entry text
  837. when exporting the agenda, configure the variable
  838. `org-agenda-add-entry-ext-maxlines'."
  839. :group 'org-agenda
  840. :type 'integer)
  841. (defcustom org-agenda-entry-text-exclude-regexps nil
  842. "List of regular expressions to clean up entry text.
  843. The complete matches of all regular expressions in this list will be
  844. removed from entry text before it is shown in the agenda."
  845. :group 'org-agenda
  846. :type '(repeat (regexp)))
  847. (defvar org-agenda-entry-text-cleanup-hook nil
  848. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  849. This cleanup is done in a temporary buffer, so the function may inspect and
  850. change the entire buffer.
  851. Some default stuff like drawers and scheduling/deadline dates will already
  852. have been removed when this is called, as will any matches for regular
  853. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  854. (defvar org-agenda-include-inactive-timestamps nil
  855. "Non-nil means include inactive time stamps in agenda and timeline.
  856. Dynamically scoped.")
  857. (defgroup org-agenda-windows nil
  858. "Options concerning the windows used by the Agenda in Org Mode."
  859. :tag "Org Agenda Windows"
  860. :group 'org-agenda)
  861. (defcustom org-agenda-window-setup 'reorganize-frame
  862. "How the agenda buffer should be displayed.
  863. Possible values for this option are:
  864. current-window Show agenda in the current window, keeping all other windows.
  865. other-window Use `switch-to-buffer-other-window' to display agenda.
  866. reorganize-frame Show only two windows on the current frame, the current
  867. window and the agenda.
  868. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  869. Also, when exiting the agenda, kill that frame.
  870. See also the variable `org-agenda-restore-windows-after-quit'."
  871. :group 'org-agenda-windows
  872. :type '(choice
  873. (const current-window)
  874. (const other-frame)
  875. (const other-window)
  876. (const reorganize-frame)))
  877. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  878. "The min and max height of the agenda window as a fraction of frame height.
  879. The value of the variable is a cons cell with two numbers between 0 and 1.
  880. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  881. :group 'org-agenda-windows
  882. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  883. (defcustom org-agenda-restore-windows-after-quit nil
  884. "Non-nil means restore window configuration upon exiting agenda.
  885. Before the window configuration is changed for displaying the agenda,
  886. the current status is recorded. When the agenda is exited with
  887. `q' or `x' and this option is set, the old state is restored. If
  888. `org-agenda-window-setup' is `other-frame', the value of this
  889. option will be ignored."
  890. :group 'org-agenda-windows
  891. :type 'boolean)
  892. (defcustom org-agenda-ndays nil
  893. "Number of days to include in overview display.
  894. Should be 1 or 7.
  895. Obsolete, see `org-agenda-span'."
  896. :group 'org-agenda-daily/weekly
  897. :type 'integer)
  898. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  899. (defcustom org-agenda-span 'week
  900. "Number of days to include in overview display.
  901. Can be day, week, month, year, or any number of days.
  902. Custom commands can set this variable in the options section."
  903. :group 'org-agenda-daily/weekly
  904. :type '(choice (const :tag "Day" day)
  905. (const :tag "Week" week)
  906. (const :tag "Month" month)
  907. (const :tag "Year" year)
  908. (integer :tag "Custom")))
  909. (defcustom org-agenda-start-on-weekday 1
  910. "Non-nil means start the overview always on the specified weekday.
  911. 0 denotes Sunday, 1 denotes Monday etc.
  912. When nil, always start on the current day.
  913. Custom commands can set this variable in the options section."
  914. :group 'org-agenda-daily/weekly
  915. :type '(choice (const :tag "Today" nil)
  916. (integer :tag "Weekday No.")))
  917. (defcustom org-agenda-show-all-dates t
  918. "Non-nil means `org-agenda' shows every day in the selected range.
  919. When nil, only the days which actually have entries are shown."
  920. :group 'org-agenda-daily/weekly
  921. :type 'boolean)
  922. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  923. "Format string for displaying dates in the agenda.
  924. Used by the daily/weekly agenda and by the timeline. This should be
  925. a format string understood by `format-time-string', or a function returning
  926. the formatted date as a string. The function must take a single argument,
  927. a calendar-style date list like (month day year)."
  928. :group 'org-agenda-daily/weekly
  929. :type '(choice
  930. (string :tag "Format string")
  931. (function :tag "Function")))
  932. (defun org-agenda-format-date-aligned (date)
  933. "Format a date string for display in the daily/weekly agenda, or timeline.
  934. This function makes sure that dates are aligned for easy reading."
  935. (require 'cal-iso)
  936. (let* ((dayname (calendar-day-name date))
  937. (day (cadr date))
  938. (day-of-week (calendar-day-of-week date))
  939. (month (car date))
  940. (monthname (calendar-month-name month))
  941. (year (nth 2 date))
  942. (iso-week (org-days-to-iso-week
  943. (calendar-absolute-from-gregorian date)))
  944. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  945. (1- year))
  946. ((and (= month 12) (<= iso-week 1))
  947. (1+ year))
  948. (t year)))
  949. (weekstring (if (= day-of-week 1)
  950. (format " W%02d" iso-week)
  951. "")))
  952. (format "%-10s %2d %s %4d%s"
  953. dayname day monthname year weekstring)))
  954. (defcustom org-agenda-time-leading-zero nil
  955. "Non-nil means use leading zero for military times in agenda.
  956. For example, 9:30am would become 09:30 rather than 9:30."
  957. :group 'org-agenda-daily/weekly
  958. :version "24.1"
  959. :type 'boolean)
  960. (defcustom org-agenda-timegrid-use-ampm nil
  961. "When set, show AM/PM style timestamps on the timegrid."
  962. :group 'org-agenda
  963. :version "24.1"
  964. :type 'boolean)
  965. (defun org-agenda-time-of-day-to-ampm (time)
  966. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  967. (let* ((hour-number (string-to-number (substring time 0 -3)))
  968. (minute (substring time -2))
  969. (ampm "am"))
  970. (cond
  971. ((equal hour-number 12)
  972. (setq ampm "pm"))
  973. ((> hour-number 12)
  974. (setq ampm "pm")
  975. (setq hour-number (- hour-number 12))))
  976. (concat
  977. (if org-agenda-time-leading-zero
  978. (format "%02d" hour-number)
  979. (format "%02s" (number-to-string hour-number)))
  980. ":" minute ampm)))
  981. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  982. "Conditionally convert TIME to AM/PM format
  983. based on `org-agenda-timegrid-use-ampm'"
  984. (if org-agenda-timegrid-use-ampm
  985. (org-agenda-time-of-day-to-ampm time)
  986. time))
  987. (defcustom org-agenda-weekend-days '(6 0)
  988. "Which days are weekend?
  989. These days get the special face `org-agenda-date-weekend' in the agenda
  990. and timeline buffers."
  991. :group 'org-agenda-daily/weekly
  992. :type '(set :greedy t
  993. (const :tag "Monday" 1)
  994. (const :tag "Tuesday" 2)
  995. (const :tag "Wednesday" 3)
  996. (const :tag "Thursday" 4)
  997. (const :tag "Friday" 5)
  998. (const :tag "Saturday" 6)
  999. (const :tag "Sunday" 0)))
  1000. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  1001. "Non-nil means jump to today when moving a past date forward in time.
  1002. When using S-right in the agenda to move a a date forward, and the date
  1003. stamp currently points to the past, the first key press will move it
  1004. to today. WHen nil, just move one day forward even if the date stays
  1005. in the past."
  1006. :group 'org-agenda-daily/weekly
  1007. :version "24.1"
  1008. :type 'boolean)
  1009. (defcustom org-agenda-include-diary nil
  1010. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  1011. Custom commands can set this variable in the options section."
  1012. :group 'org-agenda-daily/weekly
  1013. :type 'boolean)
  1014. (defcustom org-agenda-include-deadlines t
  1015. "If non-nil, include entries within their deadline warning period.
  1016. Custom commands can set this variable in the options section."
  1017. :group 'org-agenda-daily/weekly
  1018. :version "24.1"
  1019. :type 'boolean)
  1020. (defcustom org-agenda-repeating-timestamp-show-all t
  1021. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  1022. When set to a list of strings, only show occurrences of repeating
  1023. stamps for these TODO keywords. When nil, only one occurrence is
  1024. shown, either today or the nearest into the future."
  1025. :group 'org-agenda-daily/weekly
  1026. :type '(choice
  1027. (const :tag "Show repeating stamps" t)
  1028. (repeat :tag "Show repeating stamps for these TODO keywords"
  1029. (string :tag "TODO Keyword"))
  1030. (const :tag "Don't show repeating stamps" nil)))
  1031. (defcustom org-scheduled-past-days 10000
  1032. "No. of days to continue listing scheduled items that are not marked DONE.
  1033. When an item is scheduled on a date, it shows up in the agenda on this
  1034. day and will be listed until it is marked done for the number of days
  1035. given here."
  1036. :group 'org-agenda-daily/weekly
  1037. :type 'integer)
  1038. (defcustom org-agenda-log-mode-items '(closed clock)
  1039. "List of items that should be shown in agenda log mode.
  1040. This list may contain the following symbols:
  1041. closed Show entries that have been closed on that day.
  1042. clock Show entries that have received clocked time on that day.
  1043. state Show all logged state changes.
  1044. Note that instead of changing this variable, you can also press `C-u l' in
  1045. the agenda to display all available LOG items temporarily."
  1046. :group 'org-agenda-daily/weekly
  1047. :type '(set :greedy t (const closed) (const clock) (const state)))
  1048. (defcustom org-agenda-clock-consistency-checks
  1049. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1050. :gap-ok-around ("4:00")
  1051. :default-face ((:background "DarkRed") (:foreground "white"))
  1052. :overlap-face nil :gap-face nil :no-end-time-face nil
  1053. :long-face nil :short-face nil)
  1054. "This is a property list, with the following keys:
  1055. :max-duration Mark clocking chunks that are longer than this time.
  1056. This is a time string like \"HH:MM\", or the number
  1057. of minutes as an integer.
  1058. :min-duration Mark clocking chunks that are shorter that this.
  1059. This is a time string like \"HH:MM\", or the number
  1060. of minutes as an integer.
  1061. :max-gap Mark gaps between clocking chunks that are longer than
  1062. this duration. A number of minutes, or a string
  1063. like \"HH:MM\".
  1064. :gap-ok-around List of times during the day which are usually not working
  1065. times. When a gap is detected, but the gap contains any
  1066. of these times, the gap is *not* reported. For example,
  1067. if this is (\"4:00\" \"13:00\") then gaps that contain
  1068. 4:00 in the morning (i.e. the night) and 13:00
  1069. (i.e. a typical lunch time) do not cause a warning.
  1070. You should have at least one time during the night in this
  1071. list, or otherwise the first task each morning will trigger
  1072. a warning because it follows a long gap.
  1073. Furthermore, the following properties can be used to define faces for
  1074. issue display.
  1075. :default-face the default face, if the specific face is undefined
  1076. :overlap-face face for overlapping clocks
  1077. :gap-face face for gaps between clocks
  1078. :no-end-time-face face for incomplete clocks
  1079. :long-face face for clock intervals that are too long
  1080. :short-face face for clock intervals that are too short"
  1081. :group 'org-agenda-daily/weekly
  1082. :group 'org-clock
  1083. :version "24.1"
  1084. :type 'plist)
  1085. (defcustom org-agenda-log-mode-add-notes t
  1086. "Non-nil means add first line of notes to log entries in agenda views.
  1087. If a log item like a state change or a clock entry is associated with
  1088. notes, the first line of these notes will be added to the entry in the
  1089. agenda display."
  1090. :group 'org-agenda-daily/weekly
  1091. :type 'boolean)
  1092. (defcustom org-agenda-start-with-log-mode nil
  1093. "The initial value of log-mode in a newly created agenda window.
  1094. See `org-agenda-log-mode' and `org-agenda-log-mode-items' for further
  1095. explanations on the possible values."
  1096. :group 'org-agenda-startup
  1097. :group 'org-agenda-daily/weekly
  1098. :type '(choice (const :tag "Don't show log items" nil)
  1099. (const :tag "Show only log items" 'only)
  1100. (const :tag "Show all possible log items" 'clockcheck)
  1101. (repeat :tag "Choose among possible values for `org-agenda-log-mode-items'"
  1102. (choice (const :tag "Show closed log items" 'closed)
  1103. (const :tag "Show clocked log items" 'clock)
  1104. (const :tag "Show all logged state changes" 'state)))))
  1105. (defcustom org-agenda-start-with-clockreport-mode nil
  1106. "The initial value of clockreport-mode in a newly created agenda window."
  1107. :group 'org-agenda-startup
  1108. :group 'org-agenda-daily/weekly
  1109. :type 'boolean)
  1110. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1111. "Property list with parameters for the clocktable in clockreport mode.
  1112. This is the display mode that shows a clock table in the daily/weekly
  1113. agenda, the properties for this dynamic block can be set here.
  1114. The usual clocktable parameters are allowed here, but you cannot set
  1115. the properties :name, :tstart, :tend, :block, and :scope - these will
  1116. be overwritten to make sure the content accurately reflects the
  1117. current display in the agenda."
  1118. :group 'org-agenda-daily/weekly
  1119. :type 'plist)
  1120. (defcustom org-agenda-search-view-always-boolean nil
  1121. "Non-nil means the search string is interpreted as individual parts.
  1122. The search string for search view can either be interpreted as a phrase,
  1123. or as a list of snippets that define a boolean search for a number of
  1124. strings.
  1125. When this is non-nil, the string will be split on whitespace, and each
  1126. snippet will be searched individually, and all must match in order to
  1127. select an entry. A snippet is then a single string of non-white
  1128. characters, or a string in double quotes, or a regexp in {} braces.
  1129. If a snippet is preceded by \"-\", the snippet must *not* match.
  1130. \"+\" is syntactic sugar for positive selection. Each snippet may
  1131. be found as a full word or a partial word, but see the variable
  1132. `org-agenda-search-view-force-full-words'.
  1133. When this is nil, search will look for the entire search phrase as one,
  1134. with each space character matching any amount of whitespace, including
  1135. line breaks.
  1136. Even when this is nil, you can still switch to Boolean search dynamically
  1137. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1138. is a regexp marked with braces like \"{abc}\", this will also switch to
  1139. boolean search."
  1140. :group 'org-agenda-search-view
  1141. :version "24.1"
  1142. :type 'boolean)
  1143. (if (fboundp 'defvaralias)
  1144. (defvaralias 'org-agenda-search-view-search-words-only
  1145. 'org-agenda-search-view-always-boolean))
  1146. (defcustom org-agenda-search-view-force-full-words nil
  1147. "Non-nil means, search words must be matches as complete words.
  1148. When nil, they may also match part of a word."
  1149. :group 'org-agenda-search-view
  1150. :version "24.1"
  1151. :type 'boolean)
  1152. (defgroup org-agenda-time-grid nil
  1153. "Options concerning the time grid in the Org-mode Agenda."
  1154. :tag "Org Agenda Time Grid"
  1155. :group 'org-agenda)
  1156. (defcustom org-agenda-search-headline-for-time t
  1157. "Non-nil means search headline for a time-of-day.
  1158. If the headline contains a time-of-day in one format or another, it will
  1159. be used to sort the entry into the time sequence of items for a day.
  1160. Some people have time stamps in the headline that refer to the creation
  1161. time or so, and then this produces an unwanted side effect. If this is
  1162. the case for your, use this variable to turn off searching the headline
  1163. for a time."
  1164. :group 'org-agenda-time-grid
  1165. :type 'boolean)
  1166. (defcustom org-agenda-use-time-grid t
  1167. "Non-nil means show a time grid in the agenda schedule.
  1168. A time grid is a set of lines for specific times (like every two hours between
  1169. 8:00 and 20:00). The items scheduled for a day at specific times are
  1170. sorted in between these lines.
  1171. For details about when the grid will be shown, and what it will look like, see
  1172. the variable `org-agenda-time-grid'."
  1173. :group 'org-agenda-time-grid
  1174. :type 'boolean)
  1175. (defcustom org-agenda-time-grid
  1176. '((daily today require-timed)
  1177. "----------------"
  1178. (800 1000 1200 1400 1600 1800 2000))
  1179. "The settings for time grid for agenda display.
  1180. This is a list of three items. The first item is again a list. It contains
  1181. symbols specifying conditions when the grid should be displayed:
  1182. daily if the agenda shows a single day
  1183. weekly if the agenda shows an entire week
  1184. today show grid on current date, independent of daily/weekly display
  1185. require-timed show grid only if at least one item has a time specification
  1186. The second item is a string which will be placed behind the grid time.
  1187. The third item is a list of integers, indicating the times that should have
  1188. a grid line."
  1189. :group 'org-agenda-time-grid
  1190. :type
  1191. '(list
  1192. (set :greedy t :tag "Grid Display Options"
  1193. (const :tag "Show grid in single day agenda display" daily)
  1194. (const :tag "Show grid in weekly agenda display" weekly)
  1195. (const :tag "Always show grid for today" today)
  1196. (const :tag "Show grid only if any timed entries are present"
  1197. require-timed)
  1198. (const :tag "Skip grid times already present in an entry"
  1199. remove-match))
  1200. (string :tag "Grid String")
  1201. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1202. (defcustom org-agenda-show-current-time-in-grid t
  1203. "Non-nil means show the current time in the time grid."
  1204. :group 'org-agenda-time-grid
  1205. :version "24.1"
  1206. :type 'boolean)
  1207. (defcustom org-agenda-current-time-string
  1208. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1209. "The string for the current time marker in the agenda."
  1210. :group 'org-agenda-time-grid
  1211. :version "24.1"
  1212. :type 'string)
  1213. (defgroup org-agenda-sorting nil
  1214. "Options concerning sorting in the Org-mode Agenda."
  1215. :tag "Org Agenda Sorting"
  1216. :group 'org-agenda)
  1217. (defcustom org-agenda-sorting-strategy
  1218. '((agenda habit-down time-up priority-down category-keep)
  1219. (todo priority-down category-keep)
  1220. (tags priority-down category-keep)
  1221. (search category-keep))
  1222. "Sorting structure for the agenda items of a single day.
  1223. This is a list of symbols which will be used in sequence to determine
  1224. if an entry should be listed before another entry. The following
  1225. symbols are recognized:
  1226. time-up Put entries with time-of-day indications first, early first
  1227. time-down Put entries with time-of-day indications first, late first
  1228. category-keep Keep the default order of categories, corresponding to the
  1229. sequence in `org-agenda-files'.
  1230. category-up Sort alphabetically by category, A-Z.
  1231. category-down Sort alphabetically by category, Z-A.
  1232. tag-up Sort alphabetically by last tag, A-Z.
  1233. tag-down Sort alphabetically by last tag, Z-A.
  1234. priority-up Sort numerically by priority, high priority last.
  1235. priority-down Sort numerically by priority, high priority first.
  1236. todo-state-up Sort by todo state, tasks that are done last.
  1237. todo-state-down Sort by todo state, tasks that are done first.
  1238. effort-up Sort numerically by estimated effort, high effort last.
  1239. effort-down Sort numerically by estimated effort, high effort first.
  1240. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1241. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1242. habit-up Put entries that are habits first
  1243. habit-down Put entries that are habits last
  1244. alpha-up Sort headlines alphabetically
  1245. alpha-down Sort headlines alphabetically, reversed
  1246. The different possibilities will be tried in sequence, and testing stops
  1247. if one comparison returns a \"not-equal\". For example, the default
  1248. '(time-up category-keep priority-down)
  1249. means: Pull out all entries having a specified time of day and sort them,
  1250. in order to make a time schedule for the current day the first thing in the
  1251. agenda listing for the day. Of the entries without a time indication, keep
  1252. the grouped in categories, don't sort the categories, but keep them in
  1253. the sequence given in `org-agenda-files'. Within each category sort by
  1254. priority.
  1255. Leaving out `category-keep' would mean that items will be sorted across
  1256. categories by priority.
  1257. Instead of a single list, this can also be a set of list for specific
  1258. contents, with a context symbol in the car of the list, any of
  1259. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1260. Custom commands can bind this variable in the options section."
  1261. :group 'org-agenda-sorting
  1262. :type `(choice
  1263. (repeat :tag "General" ,org-sorting-choice)
  1264. (list :tag "Individually"
  1265. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1266. (repeat ,org-sorting-choice))
  1267. (cons (const :tag "Strategy for TODO lists" todo)
  1268. (repeat ,org-sorting-choice))
  1269. (cons (const :tag "Strategy for Tags matches" tags)
  1270. (repeat ,org-sorting-choice))
  1271. (cons (const :tag "Strategy for search matches" search)
  1272. (repeat ,org-sorting-choice)))))
  1273. (defcustom org-agenda-cmp-user-defined nil
  1274. "A function to define the comparison `user-defined'.
  1275. This function must receive two arguments, agenda entry a and b.
  1276. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1277. the user comparison, return nil.
  1278. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1279. part of an agenda sorting strategy."
  1280. :group 'org-agenda-sorting
  1281. :type 'symbol)
  1282. (defcustom org-sort-agenda-notime-is-late t
  1283. "Non-nil means items without time are considered late.
  1284. This is only relevant for sorting. When t, items which have no explicit
  1285. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1286. do have a time. When nil, the default time is before 0:00. You can use this
  1287. option to decide if the schedule for today should come before or after timeless
  1288. agenda entries."
  1289. :group 'org-agenda-sorting
  1290. :type 'boolean)
  1291. (defcustom org-sort-agenda-noeffort-is-high t
  1292. "Non-nil means items without effort estimate are sorted as high effort.
  1293. This also applies when filtering an agenda view with respect to the
  1294. < or > effort operator. Then, tasks with no effort defined will be treated
  1295. as tasks with high effort.
  1296. When nil, such items are sorted as 0 minutes effort."
  1297. :group 'org-agenda-sorting
  1298. :type 'boolean)
  1299. (defgroup org-agenda-line-format nil
  1300. "Options concerning the entry prefix in the Org-mode agenda display."
  1301. :tag "Org Agenda Line Format"
  1302. :group 'org-agenda)
  1303. (defcustom org-agenda-prefix-format
  1304. '((agenda . " %i %-12:c%?-12t% s")
  1305. (timeline . " % s")
  1306. (todo . " %i %-12:c")
  1307. (tags . " %i %-12:c")
  1308. (search . " %i %-12:c"))
  1309. "Format specifications for the prefix of items in the agenda views.
  1310. An alist with five entries, each for the different agenda types. The
  1311. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1312. The values are format strings.
  1313. This format works similar to a printf format, with the following meaning:
  1314. %c the category of the item, \"Diary\" for entries from the diary,
  1315. or as given by the CATEGORY keyword or derived from the file name
  1316. %e the effort required by the item
  1317. %l the level of the item (insert X space(s) if item is of level X)
  1318. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1319. %T the last tag of the item (ignore inherited tags, which come first)
  1320. %t the HH:MM time-of-day specification if one applies to the entry
  1321. %s Scheduling/Deadline information, a short string
  1322. %(expression) Eval EXPRESSION and replace the control string
  1323. by the result
  1324. All specifiers work basically like the standard `%s' of printf, but may
  1325. contain two additional characters: a question mark just after the `%'
  1326. and a whitespace/punctuation character just before the final letter.
  1327. If the first character after `%' is a question mark, the entire field
  1328. will only be included if the corresponding value applies to the current
  1329. entry. This is useful for fields which should have fixed width when
  1330. present, but zero width when absent. For example, \"%?-12t\" will
  1331. result in a 12 character time field if a time of the day is specified,
  1332. but will completely disappear in entries which do not contain a time.
  1333. If there is punctuation or whitespace character just before the final
  1334. format letter, this character will be appended to the field value if
  1335. the value is not empty. For example, the format \"%-12:c\" leads to
  1336. \"Diary: \" if the category is \"Diary\". If the category were be
  1337. empty, no additional colon would be inserted.
  1338. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1339. which means:
  1340. - Indent the line with two space characters
  1341. - Give the category a 12 chars wide field, padded with whitespace on
  1342. the right (because of `-'). Append a colon if there is a category
  1343. (because of `:').
  1344. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1345. time, don't put in an empty field, just skip it (because of '?').
  1346. - Finally, put the scheduling information.
  1347. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1348. `org-agenda-remove-tags'.
  1349. Custom commands can set this variable in the options section."
  1350. :type '(choice
  1351. (string :tag "General format")
  1352. (list :greedy t :tag "View dependent"
  1353. (cons (const agenda) (string :tag "Format"))
  1354. (cons (const timeline) (string :tag "Format"))
  1355. (cons (const todo) (string :tag "Format"))
  1356. (cons (const tags) (string :tag "Format"))
  1357. (cons (const search) (string :tag "Format"))))
  1358. :group 'org-agenda-line-format)
  1359. (defvar org-prefix-format-compiled nil
  1360. "The compiled prefix format and associated variables.
  1361. This is a list where first element is a list of variable bindings, and second
  1362. element is the compiled format expression. See the variable
  1363. `org-agenda-prefix-format'.")
  1364. (defcustom org-agenda-todo-keyword-format "%-1s"
  1365. "Format for the TODO keyword in agenda lines.
  1366. Set this to something like \"%-12s\" if you want all TODO keywords
  1367. to occupy a fixed space in the agenda display."
  1368. :group 'org-agenda-line-format
  1369. :type 'string)
  1370. (defcustom org-agenda-diary-sexp-prefix nil
  1371. "A regexp that matches part of a diary sexp entry
  1372. which should be treated as scheduling/deadline information in
  1373. `org-agenda'.
  1374. For example, you can use this to extract the `diary-remind-message' from
  1375. `diary-remind' entries."
  1376. :group 'org-agenda-line-format
  1377. :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
  1378. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1379. "Text preceding timerange entries in the agenda view.
  1380. This is a list with two strings. The first applies when the range
  1381. is entirely on one day. The second applies if the range spans several days.
  1382. The strings may have two \"%d\" format specifiers which will be filled
  1383. with the sequence number of the days, and the total number of days in the
  1384. range, respectively."
  1385. :group 'org-agenda-line-format
  1386. :type '(list
  1387. (string :tag "Deadline today ")
  1388. (choice :tag "Deadline relative"
  1389. (string :tag "Format string")
  1390. (function))))
  1391. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1392. "Text preceding scheduled items in the agenda view.
  1393. This is a list with two strings. The first applies when the item is
  1394. scheduled on the current day. The second applies when it has been scheduled
  1395. previously, it may contain a %d indicating that this is the nth time that
  1396. this item is scheduled, due to automatic rescheduling of unfinished items
  1397. for the following day. So this number is one larger than the number of days
  1398. that passed since this item was scheduled first."
  1399. :group 'org-agenda-line-format
  1400. :type '(list
  1401. (string :tag "Scheduled today ")
  1402. (string :tag "Scheduled previously")))
  1403. (defcustom org-agenda-inactive-leader "["
  1404. "Text preceding item pulled into the agenda by inactive time stamps.
  1405. These entries are added to the agenda when pressing \"[\"."
  1406. :group 'org-agenda-line-format
  1407. :version "24.1"
  1408. :type '(list
  1409. (string :tag "Scheduled today ")
  1410. (string :tag "Scheduled previously")))
  1411. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1412. "Text preceding deadline items in the agenda view.
  1413. This is a list with two strings. The first applies when the item has its
  1414. deadline on the current day. The second applies when it is in the past or
  1415. in the future, it may contain %d to capture how many days away the deadline
  1416. is (was)."
  1417. :group 'org-agenda-line-format
  1418. :type '(list
  1419. (string :tag "Deadline today ")
  1420. (choice :tag "Deadline relative"
  1421. (string :tag "Format string")
  1422. (function))))
  1423. (defcustom org-agenda-remove-times-when-in-prefix t
  1424. "Non-nil means remove duplicate time specifications in agenda items.
  1425. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1426. time-of-day specification in a headline or diary entry is extracted and
  1427. placed into the prefix. If this option is non-nil, the original specification
  1428. \(a timestamp or -range, or just a plain time(range) specification like
  1429. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1430. cluttered.
  1431. The option can be t or nil. It may also be the symbol `beg', indicating
  1432. that the time should only be removed when it is located at the beginning of
  1433. the headline/diary entry."
  1434. :group 'org-agenda-line-format
  1435. :type '(choice
  1436. (const :tag "Always" t)
  1437. (const :tag "Never" nil)
  1438. (const :tag "When at beginning of entry" beg)))
  1439. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1440. "Non-nil means remove time ranges specifications in agenda
  1441. items that span on several days."
  1442. :group 'org-agenda-line-format
  1443. :version "24.1"
  1444. :type 'boolean)
  1445. (defcustom org-agenda-default-appointment-duration nil
  1446. "Default duration for appointments that only have a starting time.
  1447. When nil, no duration is specified in such cases.
  1448. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1449. :group 'org-agenda-line-format
  1450. :type '(choice
  1451. (integer :tag "Minutes")
  1452. (const :tag "No default duration")))
  1453. (defcustom org-agenda-show-inherited-tags t
  1454. "Non-nil means show inherited tags in each agenda line."
  1455. :group 'org-agenda-line-format
  1456. :type 'boolean)
  1457. (defcustom org-agenda-hide-tags-regexp nil
  1458. "Regular expression used to filter away specific tags in agenda views.
  1459. This means that these tags will be present, but not be shown in the agenda
  1460. line. Secondary filtering will still work on the hidden tags.
  1461. Nil means don't hide any tags."
  1462. :group 'org-agenda-line-format
  1463. :type '(choice
  1464. (const :tag "Hide none" nil)
  1465. (string :tag "Regexp ")))
  1466. (defcustom org-agenda-remove-tags nil
  1467. "Non-nil means remove the tags from the headline copy in the agenda.
  1468. When this is the symbol `prefix', only remove tags when
  1469. `org-agenda-prefix-format' contains a `%T' specifier."
  1470. :group 'org-agenda-line-format
  1471. :type '(choice
  1472. (const :tag "Always" t)
  1473. (const :tag "Never" nil)
  1474. (const :tag "When prefix format contains %T" prefix)))
  1475. (if (fboundp 'defvaralias)
  1476. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1477. 'org-agenda-remove-tags))
  1478. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1479. "Shift tags in agenda items to this column.
  1480. If this number is positive, it specifies the column. If it is negative,
  1481. it means that the tags should be flushright to that column. For example,
  1482. -80 works well for a normal 80 character screen."
  1483. :group 'org-agenda-line-format
  1484. :type 'integer)
  1485. (if (fboundp 'defvaralias)
  1486. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1487. (defcustom org-agenda-fontify-priorities 'cookies
  1488. "Non-nil means highlight low and high priorities in agenda.
  1489. When t, the highest priority entries are bold, lowest priority italic.
  1490. However, settings in `org-priority-faces' will overrule these faces.
  1491. When this variable is the symbol `cookies', only fontify the
  1492. cookies, not the entire task.
  1493. This may also be an association list of priority faces, whose
  1494. keys are the character values of `org-highest-priority',
  1495. `org-default-priority', and `org-lowest-priority' (the default values
  1496. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1497. color as a string, or a list like `(:background \"Red\")'.
  1498. If it is a color, the variable `org-faces-easy-properties'
  1499. determines if it is a foreground or a background color."
  1500. :group 'org-agenda-line-format
  1501. :type '(choice
  1502. (const :tag "Never" nil)
  1503. (const :tag "Defaults" t)
  1504. (const :tag "Cookies only" cookies)
  1505. (repeat :tag "Specify"
  1506. (list (character :tag "Priority" :value ?A)
  1507. (choice :tag "Face "
  1508. (string :tag "Color")
  1509. (sexp :tag "Face"))))))
  1510. (defcustom org-agenda-day-face-function nil
  1511. "Function called to determine what face should be used to display a day.
  1512. The only argument passed to that function is the day. It should
  1513. returns a face, or nil if does not want to specify a face and let
  1514. the normal rules apply."
  1515. :group 'org-agenda-line-format
  1516. :version "24.1"
  1517. :type 'function)
  1518. (defcustom org-agenda-category-icon-alist nil
  1519. "Alist of category icon to be displayed in agenda views.
  1520. Each entry should have the following format:
  1521. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1522. Where CATEGORY-REGEXP is a regexp matching the categories where
  1523. the icon should be displayed.
  1524. FILE-OR-DATA either a file path or a string containing image data.
  1525. The other fields can be omitted safely if not needed:
  1526. TYPE indicates the image type.
  1527. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1528. image data.
  1529. PROPS are additional image attributes to assign to the image,
  1530. like, e.g. `:ascent center'.
  1531. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1532. If you want to set the display properties yourself, just put a
  1533. list as second element:
  1534. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1535. For example, to display a 16px horizontal space for Emacs
  1536. category, you can use:
  1537. (\"Emacs\" '(space . (:width (16))))"
  1538. :group 'org-agenda-line-format
  1539. :version "24.1"
  1540. :type '(alist :key-type (string :tag "Regexp matching category")
  1541. :value-type (choice (list :tag "Icon"
  1542. (string :tag "File or data")
  1543. (symbol :tag "Type")
  1544. (boolean :tag "Data?")
  1545. (repeat :tag "Extra image properties" :inline t symbol))
  1546. (list :tag "Display properties" sexp))))
  1547. (defgroup org-agenda-column-view nil
  1548. "Options concerning column view in the agenda."
  1549. :tag "Org Agenda Column View"
  1550. :group 'org-agenda)
  1551. (defcustom org-agenda-columns-show-summaries t
  1552. "Non-nil means show summaries for columns displayed in the agenda view."
  1553. :group 'org-agenda-column-view
  1554. :type 'boolean)
  1555. (defcustom org-agenda-columns-compute-summary-properties t
  1556. "Non-nil means recompute all summary properties before column view.
  1557. When column view in the agenda is listing properties that have a summary
  1558. operator, it can go to all relevant buffers and recompute the summaries
  1559. there. This can mean overhead for the agenda column view, but is necessary
  1560. to have thing up to date.
  1561. As a special case, a CLOCKSUM property also makes sure that the clock
  1562. computations are current."
  1563. :group 'org-agenda-column-view
  1564. :type 'boolean)
  1565. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1566. "Non-nil means the duration of an appointment will add to day effort.
  1567. The property to which appointment durations will be added is the one given
  1568. in the option `org-effort-property'. If an appointment does not have
  1569. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1570. is not set, an appointment without end time will not contribute to the time
  1571. estimate."
  1572. :group 'org-agenda-column-view
  1573. :type 'boolean)
  1574. (defcustom org-agenda-auto-exclude-function nil
  1575. "A function called with a tag to decide if it is filtered on '/ RET'.
  1576. The sole argument to the function, which is called once for each
  1577. possible tag, is a string giving the name of the tag. The
  1578. function should return either nil if the tag should be included
  1579. as normal, or \"-<TAG>\" to exclude the tag.
  1580. Note that for the purpose of tag filtering, only the lower-case version of
  1581. all tags will be considered, so that this function will only ever see
  1582. the lower-case version of all tags."
  1583. :group 'org-agenda
  1584. :type 'function)
  1585. (defcustom org-agenda-bulk-custom-functions nil
  1586. "Alist of characters and custom functions for bulk actions.
  1587. For example, this value makes those two functions available:
  1588. '((?R set-category)
  1589. (?C bulk-cut))
  1590. With selected entries in an agenda buffer, `B R' will call
  1591. the custom function `set-category' on the selected entries.
  1592. Note that functions in this alist don't need to be quoted."
  1593. :type 'alist
  1594. :version "24.1"
  1595. :group 'org-agenda)
  1596. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1597. "Execute BODY with point at location given by `org-hd-marker' property.
  1598. If STRING is non-nil, the text property will be fetched from position 0
  1599. in that string. If STRING is nil, it will be fetched from the beginning
  1600. of the current line."
  1601. (org-with-gensyms (marker)
  1602. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1603. 'org-hd-marker ,string)))
  1604. (with-current-buffer (marker-buffer ,marker)
  1605. (save-excursion
  1606. (goto-char ,marker)
  1607. ,@body)))))
  1608. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1609. (defun org-add-agenda-custom-command (entry)
  1610. "Replace or add a command in `org-agenda-custom-commands'.
  1611. This is mostly for hacking and trying a new command - once the command
  1612. works you probably want to add it to `org-agenda-custom-commands' for good."
  1613. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1614. (if ass
  1615. (setcdr ass (cdr entry))
  1616. (push entry org-agenda-custom-commands))))
  1617. ;;; Define the org-agenda-mode
  1618. (defvar org-agenda-mode-map (make-sparse-keymap)
  1619. "Keymap for `org-agenda-mode'.")
  1620. (if (fboundp 'defvaralias)
  1621. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1622. (defvar org-agenda-menu) ; defined later in this file.
  1623. (defvar org-agenda-restrict nil) ; defined later in this file.
  1624. (defvar org-agenda-follow-mode nil)
  1625. (defvar org-agenda-entry-text-mode nil)
  1626. (defvar org-agenda-clockreport-mode nil)
  1627. (defvar org-agenda-show-log nil)
  1628. (defvar org-agenda-redo-command nil)
  1629. (defvar org-agenda-query-string nil)
  1630. (defvar org-agenda-mode-hook nil
  1631. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1632. (defvar org-agenda-type nil)
  1633. (defvar org-agenda-force-single-file nil)
  1634. (defvar org-agenda-bulk-marked-entries nil
  1635. "List of markers that refer to marked entries in the agenda.")
  1636. ;;; Multiple agenda buffers support
  1637. (defcustom org-agenda-sticky nil
  1638. "Non-nil means agenda q key will bury agenda buffers.
  1639. Agenda commands will then show existing buffer instead of generating new ones.
  1640. When nil, `q' will kill the single agenda buffer."
  1641. :group 'org-agenda
  1642. :type 'boolean
  1643. :set (lambda (var val)
  1644. (if (boundp var)
  1645. (org-toggle-sticky-agenda (if val 1 0))
  1646. (set var val))))
  1647. ;;;###autoload
  1648. (defun org-toggle-sticky-agenda (&optional arg)
  1649. "Toggle `org-agenda-sticky'."
  1650. (interactive "P")
  1651. (let ((new-value (if arg
  1652. (> (prefix-numeric-value arg) 0)
  1653. (not org-agenda-sticky))))
  1654. (if (equal new-value org-agenda-sticky)
  1655. (and (org-called-interactively-p 'interactive)
  1656. (message "Sticky agenda was already %s"
  1657. (if org-agenda-sticky "enabled" "disabled")))
  1658. (setq org-agenda-sticky new-value)
  1659. (org-agenda-kill-all-agenda-buffers)
  1660. (and (org-called-interactively-p 'interactive)
  1661. (message "Sticky agenda was %s"
  1662. (if org-agenda-sticky "enabled" "disabled"))))))
  1663. (defvar org-agenda-buffer nil
  1664. "Agenda buffer currently being generated.")
  1665. (defvar org-agenda-last-prefix-arg nil)
  1666. (defvar org-agenda-this-buffer-name nil)
  1667. (defvar org-agenda-doing-sticky-redo nil)
  1668. (defvar org-agenda-this-buffer-is-sticky nil)
  1669. (defconst org-agenda-local-vars
  1670. '(org-agenda-this-buffer-name
  1671. org-agenda-undo-list
  1672. org-agenda-pending-undo-list
  1673. org-agenda-follow-mode
  1674. org-agenda-entry-text-mode
  1675. org-agenda-clockreport-mode
  1676. org-agenda-show-log
  1677. org-agenda-redo-command
  1678. org-agenda-query-string
  1679. org-agenda-type
  1680. org-agenda-bulk-marked-entries
  1681. org-agenda-undo-has-started-in
  1682. org-agenda-info
  1683. org-agenda-tag-filter-overlays
  1684. org-agenda-cat-filter-overlays
  1685. org-agenda-pre-window-conf
  1686. org-agenda-columns-active
  1687. org-agenda-tag-filter
  1688. org-agenda-category-filter
  1689. org-agenda-markers
  1690. org-agenda-last-search-view-search-was-boolean
  1691. org-agenda-filtered-by-category
  1692. org-agenda-filter-form
  1693. org-agenda-show-window
  1694. org-agenda-cycle-counter
  1695. org-agenda-last-prefix-arg)
  1696. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1697. (defun org-agenda-mode ()
  1698. "Mode for time-sorted view on action items in Org-mode files.
  1699. The following commands are available:
  1700. \\{org-agenda-mode-map}"
  1701. (interactive)
  1702. (cond (org-agenda-doing-sticky-redo
  1703. ;; Refreshing sticky agenda-buffer
  1704. ;;
  1705. ;; Preserve the value of `org-agenda-local-vars' variables,
  1706. ;; while letting `kill-all-local-variables' kill the rest
  1707. (let ((save (buffer-local-variables)))
  1708. (kill-all-local-variables)
  1709. (mapc 'make-local-variable org-agenda-local-vars)
  1710. (dolist (elem save)
  1711. (let ((var (car elem))
  1712. (val (cdr elem)))
  1713. (when (and val
  1714. (member var org-agenda-local-vars))
  1715. (set var val)))))
  1716. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1717. (org-agenda-sticky
  1718. ;; Creating a sticky Agenda buffer for the first time
  1719. (kill-all-local-variables)
  1720. (mapc 'make-local-variable org-agenda-local-vars)
  1721. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1722. (t
  1723. ;; Creating a non-sticky agenda buffer
  1724. (kill-all-local-variables)
  1725. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1726. (setq org-agenda-undo-list nil
  1727. org-agenda-pending-undo-list nil
  1728. org-agenda-bulk-marked-entries nil)
  1729. (setq major-mode 'org-agenda-mode)
  1730. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1731. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1732. (setq mode-name "Org-Agenda")
  1733. (use-local-map org-agenda-mode-map)
  1734. (easy-menu-add org-agenda-menu)
  1735. (if org-startup-truncated (setq truncate-lines t))
  1736. (org-set-local 'line-move-visual nil)
  1737. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1738. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1739. ;; Make sure properties are removed when copying text
  1740. (make-local-variable 'filter-buffer-substring-functions)
  1741. (add-hook 'filter-buffer-substring-functions
  1742. (lambda (fun start end delete)
  1743. (substring-no-properties (funcall fun start end delete))))
  1744. (unless org-agenda-keep-modes
  1745. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1746. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1747. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1748. org-agenda-show-log org-agenda-start-with-log-mode))
  1749. (easy-menu-change
  1750. '("Agenda") "Agenda Files"
  1751. (append
  1752. (list
  1753. (vector
  1754. (if (get 'org-agenda-files 'org-restrict)
  1755. "Restricted to single file"
  1756. "Edit File List")
  1757. '(org-edit-agenda-file-list)
  1758. (not (get 'org-agenda-files 'org-restrict)))
  1759. "--")
  1760. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1761. (org-agenda-set-mode-name)
  1762. (apply
  1763. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1764. (list 'org-agenda-mode-hook)))
  1765. (substitute-key-definition 'undo 'org-agenda-undo
  1766. org-agenda-mode-map global-map)
  1767. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1768. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1769. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1770. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1771. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1772. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1773. (org-defkey org-agenda-mode-map "*" 'org-agenda-bulk-mark-all)
  1774. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1775. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1776. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-unmark-all)
  1777. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1778. (org-defkey org-agenda-mode-map "k" 'org-agenda-capture)
  1779. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1780. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1781. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1782. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1783. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1784. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1785. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1786. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1787. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1788. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1789. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1790. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1791. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1792. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1793. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1794. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1795. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1796. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1797. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1798. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1799. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1800. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1801. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1802. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1803. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1804. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1805. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1806. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1807. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1808. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1809. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1810. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1811. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1812. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1813. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1814. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1815. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1816. (while l (org-defkey org-agenda-mode-map
  1817. (int-to-string (pop l)) 'digit-argument)))
  1818. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1819. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1820. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1821. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1822. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1823. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1824. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1825. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1826. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1827. (org-defkey org-agenda-mode-map "g" (lambda () (interactive) (org-agenda-redo t)))
  1828. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1829. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1830. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1831. 'org-clock-modify-effort-estimate)
  1832. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1833. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1834. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1835. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1836. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1837. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1838. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1839. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1840. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1841. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1842. (org-defkey org-agenda-mode-map "N" 'org-agenda-next-item)
  1843. (org-defkey org-agenda-mode-map "P" 'org-agenda-previous-item)
  1844. (substitute-key-definition 'next-line 'org-agenda-next-line
  1845. org-agenda-mode-map global-map)
  1846. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1847. org-agenda-mode-map global-map)
  1848. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1849. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1850. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1851. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1852. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-show-priority)
  1853. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1854. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1855. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1856. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1857. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1858. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1859. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1860. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1861. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1862. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1863. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1864. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1865. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1866. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1867. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1868. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1869. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1870. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1871. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1872. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1873. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1874. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1875. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1876. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1877. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1878. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1879. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1880. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1881. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1882. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1883. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1884. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1885. (org-defkey org-agenda-mode-map "^" 'org-agenda-filter-by-top-category)
  1886. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1887. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1888. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1889. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1890. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1891. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1892. (when org-agenda-mouse-1-follows-link
  1893. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1894. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1895. '("Agenda"
  1896. ("Agenda Files")
  1897. "--"
  1898. ("Agenda Dates"
  1899. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1900. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1901. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1902. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1903. "--"
  1904. ("View"
  1905. ["Day View" org-agenda-day-view
  1906. :active (org-agenda-check-type nil 'agenda)
  1907. :style radio :selected (eq org-agenda-current-span 'day)
  1908. :keys "v d (or just d)"]
  1909. ["Week View" org-agenda-week-view
  1910. :active (org-agenda-check-type nil 'agenda)
  1911. :style radio :selected (eq org-agenda-current-span 'week)
  1912. :keys "v w (or just w)"]
  1913. ["Month View" org-agenda-month-view
  1914. :active (org-agenda-check-type nil 'agenda)
  1915. :style radio :selected (eq org-agenda-current-span 'month)
  1916. :keys "v m"]
  1917. ["Year View" org-agenda-year-view
  1918. :active (org-agenda-check-type nil 'agenda)
  1919. :style radio :selected (eq org-agenda-current-span 'year)
  1920. :keys "v y"]
  1921. "--"
  1922. ["Include Diary" org-agenda-toggle-diary
  1923. :style toggle :selected org-agenda-include-diary
  1924. :active (org-agenda-check-type nil 'agenda)]
  1925. ["Include Deadlines" org-agenda-toggle-deadlines
  1926. :style toggle :selected org-agenda-include-deadlines
  1927. :active (org-agenda-check-type nil 'agenda)]
  1928. ["Use Time Grid" org-agenda-toggle-time-grid
  1929. :style toggle :selected org-agenda-use-time-grid
  1930. :active (org-agenda-check-type nil 'agenda)]
  1931. "--"
  1932. ["Show clock report" org-agenda-clockreport-mode
  1933. :style toggle :selected org-agenda-clockreport-mode
  1934. :active (org-agenda-check-type nil 'agenda)]
  1935. ["Show some entry text" org-agenda-entry-text-mode
  1936. :style toggle :selected org-agenda-entry-text-mode
  1937. :active t]
  1938. "--"
  1939. ["Show Logbook entries" org-agenda-log-mode
  1940. :style toggle :selected org-agenda-show-log
  1941. :active (org-agenda-check-type nil 'agenda 'timeline)
  1942. :keys "v l (or just l)"]
  1943. ["Include archived trees" org-agenda-archives-mode
  1944. :style toggle :selected org-agenda-archives-mode :active t
  1945. :keys "v a"]
  1946. ["Include archive files" (org-agenda-archives-mode t)
  1947. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1948. :keys "v A"]
  1949. "--"
  1950. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1951. ["Write view to file" org-agenda-write t]
  1952. ["Rebuild buffer" org-agenda-redo t]
  1953. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1954. "--"
  1955. ["Show original entry" org-agenda-show t]
  1956. ["Go To (other window)" org-agenda-goto t]
  1957. ["Go To (this window)" org-agenda-switch-to t]
  1958. ["Capture with cursor date" org-agenda-capture t]
  1959. ["Follow Mode" org-agenda-follow-mode
  1960. :style toggle :selected org-agenda-follow-mode :active t]
  1961. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1962. "--"
  1963. ("TODO"
  1964. ["Cycle TODO" org-agenda-todo t]
  1965. ["Next TODO set" org-agenda-todo-nextset t]
  1966. ["Previous TODO set" org-agenda-todo-previousset t]
  1967. ["Add note" org-agenda-add-note t])
  1968. ("Archive/Refile/Delete"
  1969. ["Archive default" org-agenda-archive-default t]
  1970. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1971. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1972. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1973. ["Archive subtree" org-agenda-archive t]
  1974. "--"
  1975. ["Refile" org-agenda-refile t]
  1976. "--"
  1977. ["Delete subtree" org-agenda-kill t])
  1978. ("Bulk action"
  1979. ["Mark entry" org-agenda-bulk-mark t]
  1980. ["Mark all" org-agenda-bulk-mark-all t]
  1981. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1982. ["Unmark entry" org-agenda-bulk-unmark t]
  1983. ["Unmark all entries" org-agenda-bulk-unmark-all :active t :keys "U"])
  1984. ["Act on all marked" org-agenda-bulk-action t]
  1985. "--"
  1986. ("Tags and Properties"
  1987. ["Show all Tags" org-agenda-show-tags t]
  1988. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1989. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1990. "--"
  1991. ["Column View" org-columns t])
  1992. ("Deadline/Schedule"
  1993. ["Schedule" org-agenda-schedule t]
  1994. ["Set Deadline" org-agenda-deadline t]
  1995. "--"
  1996. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1997. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1998. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1999. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  2000. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  2001. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  2002. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  2003. ("Clock and Effort"
  2004. ["Clock in" org-agenda-clock-in t]
  2005. ["Clock out" org-agenda-clock-out t]
  2006. ["Clock cancel" org-agenda-clock-cancel t]
  2007. ["Goto running clock" org-clock-goto t]
  2008. "--"
  2009. ["Set Effort" org-agenda-set-effort t]
  2010. ["Change clocked effort" org-clock-modify-effort-estimate
  2011. (org-clock-is-active)])
  2012. ("Priority"
  2013. ["Set Priority" org-agenda-priority t]
  2014. ["Increase Priority" org-agenda-priority-up t]
  2015. ["Decrease Priority" org-agenda-priority-down t]
  2016. ["Show Priority" org-agenda-show-priority t])
  2017. ("Calendar/Diary"
  2018. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  2019. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  2020. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  2021. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  2022. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  2023. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  2024. "--"
  2025. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  2026. "--"
  2027. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  2028. "--"
  2029. ("MobileOrg"
  2030. ["Push Files and Views" org-mobile-push t]
  2031. ["Get Captured and Flagged" org-mobile-pull t]
  2032. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  2033. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  2034. "--"
  2035. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  2036. "--"
  2037. ["Quit" org-agenda-quit t]
  2038. ["Exit and Release Buffers" org-agenda-exit t]
  2039. ))
  2040. ;;; Agenda undo
  2041. (defvar org-agenda-allow-remote-undo t
  2042. "Non-nil means allow remote undo from the agenda buffer.")
  2043. (defvar org-agenda-undo-has-started-in nil
  2044. "Buffers that have already seen `undo-start' in the current undo sequence.")
  2045. (defun org-agenda-undo ()
  2046. "Undo a remote editing step in the agenda.
  2047. This undoes changes both in the agenda buffer and in the remote buffer
  2048. that have been changed along."
  2049. (interactive)
  2050. (or org-agenda-allow-remote-undo
  2051. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2052. (if (not (eq this-command last-command))
  2053. (setq org-agenda-undo-has-started-in nil
  2054. org-agenda-pending-undo-list org-agenda-undo-list))
  2055. (if (not org-agenda-pending-undo-list)
  2056. (error "No further undo information"))
  2057. (let* ((entry (pop org-agenda-pending-undo-list))
  2058. buf line cmd rembuf)
  2059. (setq cmd (pop entry) line (pop entry))
  2060. (setq rembuf (nth 2 entry))
  2061. (org-with-remote-undo rembuf
  2062. (while (bufferp (setq buf (pop entry)))
  2063. (if (pop entry)
  2064. (with-current-buffer buf
  2065. (let ((last-undo-buffer buf)
  2066. (inhibit-read-only t))
  2067. (unless (memq buf org-agenda-undo-has-started-in)
  2068. (push buf org-agenda-undo-has-started-in)
  2069. (make-local-variable 'pending-undo-list)
  2070. (undo-start))
  2071. (while (and pending-undo-list
  2072. (listp pending-undo-list)
  2073. (not (car pending-undo-list)))
  2074. (pop pending-undo-list))
  2075. (undo-more 1))))))
  2076. (org-goto-line line)
  2077. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2078. (defun org-verify-change-for-undo (l1 l2)
  2079. "Verify that a real change occurred between the undo lists L1 and L2."
  2080. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2081. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2082. (not (eq l1 l2)))
  2083. ;;; Agenda dispatch
  2084. (defvar org-agenda-restrict-begin (make-marker))
  2085. (defvar org-agenda-restrict-end (make-marker))
  2086. (defvar org-agenda-last-dispatch-buffer nil)
  2087. (defvar org-agenda-overriding-restriction nil)
  2088. (defcustom org-agenda-custom-commands-contexts nil
  2089. "Alist of custom agenda keys and contextual rules.
  2090. For example, if you have a custom agenda command \"p\" and you
  2091. want this command to be accessible only from plain text files,
  2092. use this:
  2093. '((\"p\" (in-file . \"\\.txt\")))
  2094. Here are the available contexts definitions:
  2095. in-file: command displayed only in matching files
  2096. in-mode: command displayed only in matching modes
  2097. not-in-file: command not displayed in matching files
  2098. not-in-mode: command not displayed in matching modes
  2099. [function]: a custom function taking no argument
  2100. If you define several checks, the agenda command will be
  2101. accessible if there is at least one valid check.
  2102. You can also bind a key to another agenda custom command
  2103. depending on contextual rules.
  2104. '((\"p\" \"q\" (in-file . \"\\.txt\")))
  2105. Here it means: in .txt files, use \"p\" as the key for the
  2106. agenda command otherwise associated with \"q\". (The command
  2107. originally associated with \"q\" is not displayed to avoid
  2108. duplicates.)"
  2109. ;; :version "24.3"
  2110. :group 'org-agenda-custom-commands
  2111. :type '(repeat (list :tag "Rule"
  2112. (string :tag " Agenda key")
  2113. (string :tag "Replace by command")
  2114. (repeat :tag "Available when"
  2115. (choice
  2116. (cons :tag "Condition"
  2117. (choice
  2118. (const :tag "In file" in-file)
  2119. (const :tag "Not in file" not-in-file)
  2120. (const :tag "In mode" in-mode)
  2121. (const :tag "Not in mode" not-in-mode))
  2122. (regexp))
  2123. (function :tag "Custom function"))))))
  2124. (defvar org-keys nil)
  2125. (defvar org-match nil)
  2126. ;;;###autoload
  2127. (defun org-agenda (&optional arg org-keys restriction)
  2128. "Dispatch agenda commands to collect entries to the agenda buffer.
  2129. Prompts for a command to execute. Any prefix arg will be passed
  2130. on to the selected command. The default selections are:
  2131. a Call `org-agenda-list' to display the agenda for current day or week.
  2132. t Call `org-todo-list' to display the global todo list.
  2133. T Call `org-todo-list' to display the global todo list, select only
  2134. entries with a specific TODO keyword (the user gets a prompt).
  2135. m Call `org-tags-view' to display headlines with tags matching
  2136. a condition (the user is prompted for the condition).
  2137. M Like `m', but select only TODO entries, no ordinary headlines.
  2138. L Create a timeline for the current buffer.
  2139. e Export views to associated files.
  2140. s Search entries for keywords.
  2141. S Search entries for keywords, only with TODO keywords.
  2142. / Multi occur across all agenda files and also files listed
  2143. in `org-agenda-text-search-extra-files'.
  2144. < Restrict agenda commands to buffer, subtree, or region.
  2145. Press several times to get the desired effect.
  2146. > Remove a previous restriction.
  2147. # List \"stuck\" projects.
  2148. ! Configure what \"stuck\" means.
  2149. C Configure custom agenda commands.
  2150. More commands can be added by configuring the variable
  2151. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2152. searches can be pre-defined in this way.
  2153. If the current buffer is in Org-mode and visiting a file, you can also
  2154. first press `<' once to indicate that the agenda should be temporarily
  2155. \(until the next use of \\[org-agenda]) restricted to the current file.
  2156. Pressing `<' twice means to restrict to the current subtree or region
  2157. \(if active)."
  2158. (interactive "P")
  2159. (catch 'exit
  2160. (let* ((prefix-descriptions nil)
  2161. (org-agenda-buffer-name org-agenda-buffer-name)
  2162. (org-agenda-window-setup (if (equal (buffer-name)
  2163. org-agenda-buffer-name)
  2164. 'current-window
  2165. org-agenda-window-setup))
  2166. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2167. (org-agenda-custom-commands
  2168. ;; normalize different versions
  2169. (delq nil
  2170. (mapcar
  2171. (lambda (x)
  2172. (cond ((stringp (cdr x))
  2173. (push x prefix-descriptions)
  2174. nil)
  2175. ((stringp (nth 1 x)) x)
  2176. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2177. (t (cons (car x) (cons "" (cdr x))))))
  2178. org-agenda-custom-commands)))
  2179. (org-agenda-custom-commands
  2180. (org-contextualize-keys
  2181. org-agenda-custom-commands org-agenda-custom-commands-contexts))
  2182. (buf (current-buffer))
  2183. (bfn (buffer-file-name (buffer-base-buffer)))
  2184. entry key type org-match lprops ans)
  2185. ;; Turn off restriction unless there is an overriding one,
  2186. (unless org-agenda-overriding-restriction
  2187. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2188. ;; There is a request to keep the file list in place
  2189. (put 'org-agenda-files 'org-restrict nil))
  2190. (setq org-agenda-restrict nil)
  2191. (move-marker org-agenda-restrict-begin nil)
  2192. (move-marker org-agenda-restrict-end nil))
  2193. ;; Delete old local properties
  2194. (put 'org-agenda-redo-command 'org-lprops nil)
  2195. ;; Delete previously set last-arguments
  2196. (put 'org-agenda-redo-command 'last-args nil)
  2197. ;; Remember where this call originated
  2198. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2199. (unless org-keys
  2200. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2201. org-keys (car ans)
  2202. restriction (cdr ans)))
  2203. ;; If we have sticky agenda buffers, set a name for the buffer,
  2204. ;; depending on the invoking keys. The user may still set this
  2205. ;; as a command option, which will overwrite what we do here.
  2206. (if org-agenda-sticky
  2207. (setq org-agenda-buffer-name
  2208. (format "*Org Agenda(%s)*" org-keys)))
  2209. ;; Establish the restriction, if any
  2210. (when (and (not org-agenda-overriding-restriction) restriction)
  2211. (put 'org-agenda-files 'org-restrict (list bfn))
  2212. (cond
  2213. ((eq restriction 'region)
  2214. (setq org-agenda-restrict t)
  2215. (move-marker org-agenda-restrict-begin (region-beginning))
  2216. (move-marker org-agenda-restrict-end (region-end)))
  2217. ((eq restriction 'subtree)
  2218. (save-excursion
  2219. (setq org-agenda-restrict t)
  2220. (org-back-to-heading t)
  2221. (move-marker org-agenda-restrict-begin (point))
  2222. (move-marker org-agenda-restrict-end
  2223. (progn (org-end-of-subtree t)))))))
  2224. ;; For example the todo list should not need it (but does...)
  2225. (cond
  2226. ((setq entry (assoc org-keys org-agenda-custom-commands))
  2227. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2228. (progn
  2229. (setq type (nth 2 entry) org-match (eval (nth 3 entry))
  2230. lprops (nth 4 entry))
  2231. (if org-agenda-sticky
  2232. (setq org-agenda-buffer-name
  2233. (or (and (stringp org-match) (format "*Org Agenda(%s:%s)*" org-keys org-match))
  2234. (format "*Org Agenda(%s)*" org-keys))))
  2235. (put 'org-agenda-redo-command 'org-lprops lprops)
  2236. (cond
  2237. ((eq type 'agenda)
  2238. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2239. ((eq type 'alltodo)
  2240. (org-let lprops '(org-todo-list current-prefix-arg)))
  2241. ((eq type 'search)
  2242. (org-let lprops '(org-search-view current-prefix-arg org-match nil)))
  2243. ((eq type 'stuck)
  2244. (org-let lprops '(org-agenda-list-stuck-projects
  2245. current-prefix-arg)))
  2246. ((eq type 'tags)
  2247. (org-let lprops '(org-tags-view current-prefix-arg org-match)))
  2248. ((eq type 'tags-todo)
  2249. (org-let lprops '(org-tags-view '(4) org-match)))
  2250. ((eq type 'todo)
  2251. (org-let lprops '(org-todo-list org-match)))
  2252. ((eq type 'tags-tree)
  2253. (org-check-for-org-mode)
  2254. (org-let lprops '(org-match-sparse-tree current-prefix-arg org-match)))
  2255. ((eq type 'todo-tree)
  2256. (org-check-for-org-mode)
  2257. (org-let lprops
  2258. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2259. (regexp-quote org-match) "\\>"))))
  2260. ((eq type 'occur-tree)
  2261. (org-check-for-org-mode)
  2262. (org-let lprops '(org-occur org-match)))
  2263. ((functionp type)
  2264. (org-let lprops '(funcall type org-match)))
  2265. ((fboundp type)
  2266. (org-let lprops '(funcall type org-match)))
  2267. (t (error "Invalid custom agenda command type %s" type))))
  2268. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2269. ((equal org-keys "C")
  2270. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2271. (customize-variable 'org-agenda-custom-commands))
  2272. ((equal org-keys "a") (call-interactively 'org-agenda-list))
  2273. ((equal org-keys "s") (call-interactively 'org-search-view))
  2274. ((equal org-keys "S") (org-call-with-arg 'org-search-view (or arg '(4))))
  2275. ((equal org-keys "t") (call-interactively 'org-todo-list))
  2276. ((equal org-keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2277. ((equal org-keys "m") (call-interactively 'org-tags-view))
  2278. ((equal org-keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2279. ((equal org-keys "e") (call-interactively 'org-store-agenda-views))
  2280. ((equal org-keys "?") (org-tags-view nil "+FLAGGED")
  2281. (org-add-hook
  2282. 'post-command-hook
  2283. (lambda ()
  2284. (unless (current-message)
  2285. (let* ((m (org-agenda-get-any-marker))
  2286. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2287. (when note
  2288. (message (concat
  2289. "FLAGGING-NOTE ([?] for more info): "
  2290. (org-add-props
  2291. (replace-regexp-in-string
  2292. "\\\\n" "//"
  2293. (copy-sequence note))
  2294. nil 'face 'org-warning)))))))
  2295. t t))
  2296. ((equal org-keys "L")
  2297. (unless (derived-mode-p 'org-mode)
  2298. (error "This is not an Org-mode file"))
  2299. (unless restriction
  2300. (put 'org-agenda-files 'org-restrict (list bfn))
  2301. (org-call-with-arg 'org-timeline arg)))
  2302. ((equal org-keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2303. ((equal org-keys "/") (call-interactively 'org-occur-in-agenda-files))
  2304. ((equal org-keys "!") (customize-variable 'org-stuck-projects))
  2305. (t (error "Invalid agenda key"))))))
  2306. (defun org-agenda-append-agenda ()
  2307. "Append another agenda view to the current one.
  2308. This function allows interactive building of block agendas.
  2309. Agenda views are separated by `org-agenda-block-separator'."
  2310. (interactive)
  2311. (unless (derived-mode-p 'org-agenda-mode)
  2312. (error "Can only append from within agenda buffer"))
  2313. (let ((org-agenda-multi t))
  2314. (org-agenda)
  2315. (widen)
  2316. (org-agenda-finalize)
  2317. (org-agenda-fit-window-to-buffer)))
  2318. (defun org-agenda-normalize-custom-commands (cmds)
  2319. (delq nil
  2320. (mapcar
  2321. (lambda (x)
  2322. (cond ((stringp (cdr x)) nil)
  2323. ((stringp (nth 1 x)) x)
  2324. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2325. (t (cons (car x) (cons "" (cdr x))))))
  2326. cmds)))
  2327. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2328. "The user interface for selecting an agenda command."
  2329. (catch 'exit
  2330. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2331. (restrict-ok (and bfn (derived-mode-p 'org-mode)))
  2332. (region-p (org-region-active-p))
  2333. (custom org-agenda-custom-commands)
  2334. (selstring "")
  2335. restriction second-time
  2336. c entry key type match prefixes rmheader header-end custom1 desc
  2337. line lines left right n n1)
  2338. (save-window-excursion
  2339. (delete-other-windows)
  2340. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2341. (erase-buffer)
  2342. (insert (eval-when-compile
  2343. (let ((header
  2344. "Press key for an agenda command: < Buffer, subtree/region restriction
  2345. -------------------------------- > Remove restriction
  2346. a Agenda for current week or day e Export agenda views
  2347. t List of all TODO entries T Entries with special TODO kwd
  2348. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2349. s Search for keywords S Like s, but only TODO entries
  2350. L Timeline for current buffer # List stuck projects (!=configure)
  2351. / Multi-occur C Configure custom agenda commands
  2352. ? Find :FLAGGED: entries * Toggle sticky agenda views
  2353. ")
  2354. (start 0))
  2355. (while (string-match
  2356. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2357. header start)
  2358. (setq start (match-end 0))
  2359. (add-text-properties (match-beginning 2) (match-end 2)
  2360. '(face bold) header))
  2361. header)))
  2362. (setq header-end (move-marker (make-marker) (point)))
  2363. (while t
  2364. (setq custom1 custom)
  2365. (when (eq rmheader t)
  2366. (org-goto-line 1)
  2367. (re-search-forward ":" nil t)
  2368. (delete-region (match-end 0) (point-at-eol))
  2369. (forward-char 1)
  2370. (looking-at "-+")
  2371. (delete-region (match-end 0) (point-at-eol))
  2372. (move-marker header-end (match-end 0)))
  2373. (goto-char header-end)
  2374. (delete-region (point) (point-max))
  2375. ;; Produce all the lines that describe custom commands and prefixes
  2376. (setq lines nil)
  2377. (while (setq entry (pop custom1))
  2378. (setq key (car entry) desc (nth 1 entry)
  2379. type (nth 2 entry)
  2380. match (nth 3 entry))
  2381. (if (> (length key) 1)
  2382. (add-to-list 'prefixes (string-to-char key))
  2383. (setq line
  2384. (format
  2385. "%-4s%-14s"
  2386. (org-add-props (copy-sequence key)
  2387. '(face bold))
  2388. (cond
  2389. ((string-match "\\S-" desc) desc)
  2390. ((eq type 'agenda) "Agenda for current week or day")
  2391. ((eq type 'alltodo) "List of all TODO entries")
  2392. ((eq type 'search) "Word search")
  2393. ((eq type 'stuck) "List of stuck projects")
  2394. ((eq type 'todo) "TODO keyword")
  2395. ((eq type 'tags) "Tags query")
  2396. ((eq type 'tags-todo) "Tags (TODO)")
  2397. ((eq type 'tags-tree) "Tags tree")
  2398. ((eq type 'todo-tree) "TODO kwd tree")
  2399. ((eq type 'occur-tree) "Occur tree")
  2400. ((functionp type) (if (symbolp type)
  2401. (symbol-name type)
  2402. "Lambda expression"))
  2403. (t "???"))))
  2404. (if org-agenda-menu-show-matcher
  2405. (setq line
  2406. (concat line ": "
  2407. (cond
  2408. ((stringp match)
  2409. (setq match (copy-sequence match))
  2410. (org-add-props match nil 'face 'org-warning))
  2411. (match
  2412. (format "set of %d commands" (length match)))
  2413. (t ""))))
  2414. (if (org-string-nw-p match)
  2415. (add-text-properties
  2416. 0 (length line) (list 'help-echo
  2417. (concat "Matcher: "match)) line)))
  2418. (push line lines)))
  2419. (setq lines (nreverse lines))
  2420. (when prefixes
  2421. (mapc (lambda (x)
  2422. (push
  2423. (format "%s %s"
  2424. (org-add-props (char-to-string x)
  2425. nil 'face 'bold)
  2426. (or (cdr (assoc (concat selstring
  2427. (char-to-string x))
  2428. prefix-descriptions))
  2429. "Prefix key"))
  2430. lines))
  2431. prefixes))
  2432. ;; Check if we should display in two columns
  2433. (if org-agenda-menu-two-columns
  2434. (progn
  2435. (setq n (length lines)
  2436. n1 (+ (/ n 2) (mod n 2))
  2437. right (nthcdr n1 lines)
  2438. left (copy-sequence lines))
  2439. (setcdr (nthcdr (1- n1) left) nil))
  2440. (setq left lines right nil))
  2441. (while left
  2442. (insert "\n" (pop left))
  2443. (when right
  2444. (if (< (current-column) 40)
  2445. (move-to-column 40 t)
  2446. (insert " "))
  2447. (insert (pop right))))
  2448. ;; Make the window the right size
  2449. (goto-char (point-min))
  2450. (if second-time
  2451. (if (not (pos-visible-in-window-p (point-max)))
  2452. (org-fit-window-to-buffer))
  2453. (setq second-time t)
  2454. (org-fit-window-to-buffer))
  2455. ;; Ask for selection
  2456. (message "Press key for agenda command%s:"
  2457. (if (or restrict-ok org-agenda-overriding-restriction)
  2458. (if org-agenda-overriding-restriction
  2459. " (restriction lock active)"
  2460. (if restriction
  2461. (format " (restricted to %s)" restriction)
  2462. " (unrestricted)"))
  2463. ""))
  2464. (setq c (read-char-exclusive))
  2465. (message "")
  2466. (cond
  2467. ((assoc (char-to-string c) custom)
  2468. (setq selstring (concat selstring (char-to-string c)))
  2469. (throw 'exit (cons selstring restriction)))
  2470. ((memq c prefixes)
  2471. (setq selstring (concat selstring (char-to-string c))
  2472. prefixes nil
  2473. rmheader (or rmheader t)
  2474. custom (delq nil (mapcar
  2475. (lambda (x)
  2476. (if (or (= (length (car x)) 1)
  2477. (/= (string-to-char (car x)) c))
  2478. nil
  2479. (cons (substring (car x) 1) (cdr x))))
  2480. custom))))
  2481. ((eq c ?*)
  2482. (call-interactively 'org-toggle-sticky-agenda)
  2483. (sit-for 2))
  2484. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2485. (message "Restriction is only possible in Org-mode buffers")
  2486. (ding) (sit-for 1))
  2487. ((eq c ?1)
  2488. (org-agenda-remove-restriction-lock 'noupdate)
  2489. (setq restriction 'buffer))
  2490. ((eq c ?0)
  2491. (org-agenda-remove-restriction-lock 'noupdate)
  2492. (setq restriction (if region-p 'region 'subtree)))
  2493. ((eq c ?<)
  2494. (org-agenda-remove-restriction-lock 'noupdate)
  2495. (setq restriction
  2496. (cond
  2497. ((eq restriction 'buffer)
  2498. (if region-p 'region 'subtree))
  2499. ((memq restriction '(subtree region))
  2500. nil)
  2501. (t 'buffer))))
  2502. ((eq c ?>)
  2503. (org-agenda-remove-restriction-lock 'noupdate)
  2504. (setq restriction nil))
  2505. ((and (equal selstring "") (memq c '(?s ?S ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2506. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2507. ((and (> (length selstring) 0) (eq c ?\d))
  2508. (delete-window)
  2509. (org-agenda-get-restriction-and-command prefix-descriptions))
  2510. ((equal c ?q) (error "Abort"))
  2511. (t (error "Invalid key %c" c))))))))
  2512. (defun org-agenda-fit-window-to-buffer ()
  2513. "Fit the window to the buffer size."
  2514. (and (memq org-agenda-window-setup '(reorganize-frame))
  2515. (fboundp 'fit-window-to-buffer)
  2516. (org-fit-window-to-buffer
  2517. nil
  2518. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2519. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2520. (defvar org-cmd nil)
  2521. (defvar org-agenda-overriding-cmd nil)
  2522. (defvar org-agenda-overriding-arguments nil)
  2523. (defvar org-agenda-overriding-cmd-arguments nil)
  2524. (defun org-agenda-run-series (name series)
  2525. (org-let (nth 1 series) '(org-agenda-prepare name))
  2526. ;; We need to reset agenda markers here, because when constructing a
  2527. ;; block agenda, the individual blocks do not do that.
  2528. (org-agenda-reset-markers)
  2529. (let* ((org-agenda-multi t)
  2530. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2531. (cmds (car series))
  2532. (gprops (nth 1 series))
  2533. match ;; The byte compiler incorrectly complains about this. Keep it!
  2534. org-cmd type lprops)
  2535. (while (setq org-cmd (pop cmds))
  2536. (setq type (car org-cmd)
  2537. match (eval (nth 1 org-cmd))
  2538. lprops (nth 2 org-cmd))
  2539. (let ((org-agenda-overriding-arguments
  2540. (if (eq org-agenda-overriding-cmd org-cmd)
  2541. (or org-agenda-overriding-arguments
  2542. org-agenda-overriding-cmd-arguments))))
  2543. (cond
  2544. ((eq type 'agenda)
  2545. (org-let2 gprops lprops
  2546. '(call-interactively 'org-agenda-list)))
  2547. ((eq type 'alltodo)
  2548. (org-let2 gprops lprops
  2549. '(call-interactively 'org-todo-list)))
  2550. ((eq type 'search)
  2551. (org-let2 gprops lprops
  2552. '(org-search-view current-prefix-arg match nil)))
  2553. ((eq type 'stuck)
  2554. (org-let2 gprops lprops
  2555. '(call-interactively 'org-agenda-list-stuck-projects)))
  2556. ((eq type 'tags)
  2557. (org-let2 gprops lprops
  2558. '(org-tags-view current-prefix-arg match)))
  2559. ((eq type 'tags-todo)
  2560. (org-let2 gprops lprops
  2561. '(org-tags-view '(4) match)))
  2562. ((eq type 'todo)
  2563. (org-let2 gprops lprops
  2564. '(org-todo-list match)))
  2565. ((fboundp type)
  2566. (org-let2 gprops lprops
  2567. '(funcall type match)))
  2568. (t (error "Invalid type in command series")))))
  2569. (widen)
  2570. (let ((inhibit-read-only t))
  2571. (add-text-properties (point-min) (point-max)
  2572. `(org-serie t org-serie-redo-cmd ,redo)))
  2573. (setq org-agenda-redo-command redo)
  2574. (goto-char (point-min)))
  2575. (org-agenda-fit-window-to-buffer)
  2576. (org-let (nth 1 series) '(org-agenda-finalize)))
  2577. ;;;###autoload
  2578. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2579. "Run an agenda command in batch mode and send the result to STDOUT.
  2580. If CMD-KEY is a string of length 1, it is used as a key in
  2581. `org-agenda-custom-commands' and triggers this command. If it is a
  2582. longer string it is used as a tags/todo match string.
  2583. Parameters are alternating variable names and values that will be bound
  2584. before running the agenda command."
  2585. (org-eval-in-environment (org-make-parameter-alist parameters)
  2586. (if (> (length cmd-key) 2)
  2587. (org-tags-view nil cmd-key)
  2588. (org-agenda nil cmd-key)))
  2589. (set-buffer org-agenda-buffer-name)
  2590. (princ (buffer-string)))
  2591. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2592. (defvar org-agenda-info nil)
  2593. ;;;###autoload
  2594. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2595. "Run an agenda command in batch mode and send the result to STDOUT.
  2596. If CMD-KEY is a string of length 1, it is used as a key in
  2597. `org-agenda-custom-commands' and triggers this command. If it is a
  2598. longer string it is used as a tags/todo match string.
  2599. Parameters are alternating variable names and values that will be bound
  2600. before running the agenda command.
  2601. The output gives a line for each selected agenda item. Each
  2602. item is a list of comma-separated values, like this:
  2603. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2604. category The category of the item
  2605. head The headline, without TODO kwd, TAGS and PRIORITY
  2606. type The type of the agenda entry, can be
  2607. todo selected in TODO match
  2608. tagsmatch selected in tags match
  2609. diary imported from diary
  2610. deadline a deadline on given date
  2611. scheduled scheduled on given date
  2612. timestamp entry has timestamp on given date
  2613. closed entry was closed on given date
  2614. upcoming-deadline warning about deadline
  2615. past-scheduled forwarded scheduled item
  2616. block entry has date block including g. date
  2617. todo The todo keyword, if any
  2618. tags All tags including inherited ones, separated by colons
  2619. date The relevant date, like 2007-2-14
  2620. time The time, like 15:00-16:50
  2621. extra Sting with extra planning info
  2622. priority-l The priority letter if any was given
  2623. priority-n The computed numerical priority
  2624. agenda-day The day in the agenda where this is listed"
  2625. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2626. (org-make-parameter-alist parameters))
  2627. (if (> (length cmd-key) 2)
  2628. (org-tags-view nil cmd-key)
  2629. (org-agenda nil cmd-key)))
  2630. (set-buffer org-agenda-buffer-name)
  2631. (let* ((lines (org-split-string (buffer-string) "\n"))
  2632. line)
  2633. (while (setq line (pop lines))
  2634. (catch 'next
  2635. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2636. (setq org-agenda-info
  2637. (org-fix-agenda-info (text-properties-at 0 line)))
  2638. (princ
  2639. (mapconcat 'org-agenda-export-csv-mapper
  2640. '(org-category txt type todo tags date time extra
  2641. priority-letter priority agenda-day)
  2642. ","))
  2643. (princ "\n")))))
  2644. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2645. (defun org-fix-agenda-info (props)
  2646. "Make sure all properties on an agenda item have a canonical form.
  2647. This ensures the export commands can easily use it."
  2648. (let (tmp re)
  2649. (when (setq tmp (plist-get props 'tags))
  2650. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2651. (when (setq tmp (plist-get props 'date))
  2652. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2653. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2654. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2655. (setq tmp (calendar-date-string tmp)))
  2656. (setq props (plist-put props 'date tmp)))
  2657. (when (setq tmp (plist-get props 'day))
  2658. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2659. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2660. (setq tmp (calendar-date-string tmp)))
  2661. (setq props (plist-put props 'day tmp))
  2662. (setq props (plist-put props 'agenda-day tmp)))
  2663. (when (setq tmp (plist-get props 'txt))
  2664. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2665. (plist-put props 'priority-letter (match-string 1 tmp))
  2666. (setq tmp (replace-match "" t t tmp)))
  2667. (when (and (setq re (plist-get props 'org-todo-regexp))
  2668. (setq re (concat "\\`\\.*" re " ?"))
  2669. (string-match re tmp))
  2670. (plist-put props 'todo (match-string 1 tmp))
  2671. (setq tmp (replace-match "" t t tmp)))
  2672. (plist-put props 'txt tmp)))
  2673. props)
  2674. (defun org-agenda-export-csv-mapper (prop)
  2675. (let ((res (plist-get org-agenda-info prop)))
  2676. (setq res
  2677. (cond
  2678. ((not res) "")
  2679. ((stringp res) res)
  2680. (t (prin1-to-string res))))
  2681. (while (string-match "," res)
  2682. (setq res (replace-match ";" t t res)))
  2683. (org-trim res)))
  2684. ;;;###autoload
  2685. (defun org-store-agenda-views (&rest parameters)
  2686. (interactive)
  2687. (eval (list 'org-batch-store-agenda-views)))
  2688. ;;;###autoload
  2689. (defmacro org-batch-store-agenda-views (&rest parameters)
  2690. "Run all custom agenda commands that have a file argument."
  2691. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2692. (pop-up-frames nil)
  2693. (dir default-directory)
  2694. (pars (org-make-parameter-alist parameters))
  2695. cmd thiscmdkey thiscmdcmd match files opts cmd-or-set bufname)
  2696. (save-window-excursion
  2697. (while cmds
  2698. (setq cmd (pop cmds)
  2699. thiscmdkey (car cmd)
  2700. thiscmdcmd (cdr cmd)
  2701. match (nth 2 thiscmdcmd)
  2702. bufname (if org-agenda-sticky
  2703. (or (and (stringp match)
  2704. (format "*Org Agenda(%s:%s)*" thiscmdkey match))
  2705. (format "*Org Agenda(%s)*" thiscmdkey))
  2706. org-agenda-buffer-name)
  2707. cmd-or-set (nth 2 cmd)
  2708. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2709. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2710. (if (stringp files) (setq files (list files)))
  2711. (when files
  2712. (org-eval-in-environment (append org-agenda-exporter-settings
  2713. opts pars)
  2714. (org-agenda nil thiscmdkey))
  2715. (set-buffer bufname)
  2716. (while files
  2717. (org-eval-in-environment (append org-agenda-exporter-settings
  2718. opts pars)
  2719. (org-agenda-write (expand-file-name (pop files) dir) nil t bufname)))
  2720. (and (get-buffer bufname)
  2721. (kill-buffer bufname)))))))
  2722. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2723. (defvar org-agenda-current-span nil
  2724. "The current span used in the agenda view.") ; local variable in the agenda buffer
  2725. (defun org-agenda-mark-header-line (pos)
  2726. "Mark the line at POS as an agenda structure header."
  2727. (save-excursion
  2728. (goto-char pos)
  2729. (put-text-property (point-at-bol) (point-at-eol)
  2730. 'org-agenda-structural-header t)
  2731. (when org-agenda-title-append
  2732. (put-text-property (point-at-bol) (point-at-eol)
  2733. 'org-agenda-title-append org-agenda-title-append))))
  2734. (defvar org-mobile-creating-agendas) ; defined in org-mobile.el
  2735. (defvar org-agenda-write-buffer-name "Agenda View")
  2736. (defun org-agenda-write (file &optional open nosettings agenda-bufname)
  2737. "Write the current buffer (an agenda view) as a file.
  2738. Depending on the extension of the file name, plain text (.txt),
  2739. HTML (.html or .htm) or Postscript (.ps) is produced.
  2740. If the extension is .ics, run icalendar export over all files used
  2741. to construct the agenda and limit the export to entries listed in the
  2742. agenda now.
  2743. With prefix argument OPEN, open the new file immediately.
  2744. If NOSETTINGS is given, do not scope the settings of
  2745. `org-agenda-exporter-settings' into the export commands. This is used when
  2746. the settings have already been scoped and we do not wish to overrule other,
  2747. higher priority settings.
  2748. If AGENDA-BUFFER-NAME, use this as the buffer name for the agenda to write."
  2749. (interactive "FWrite agenda to file: \nP")
  2750. (if (not (file-writable-p file))
  2751. (error "Cannot write agenda to file %s" file))
  2752. (org-let (if nosettings nil org-agenda-exporter-settings)
  2753. '(save-excursion
  2754. (save-window-excursion
  2755. (org-agenda-mark-filtered-text)
  2756. (let ((bs (copy-sequence (buffer-string))) beg)
  2757. (org-agenda-unmark-filtered-text)
  2758. (with-temp-buffer
  2759. (rename-buffer org-agenda-write-buffer-name t)
  2760. (set-buffer-modified-p nil)
  2761. (insert bs)
  2762. (org-agenda-remove-marked-text 'org-filtered)
  2763. (while (setq beg (text-property-any (point-min) (point-max)
  2764. 'org-filtered t))
  2765. (delete-region
  2766. beg (or (next-single-property-change beg 'org-filtered)
  2767. (point-max))))
  2768. (run-hooks 'org-agenda-before-write-hook)
  2769. (cond
  2770. ((org-bound-and-true-p org-mobile-creating-agendas)
  2771. (org-mobile-write-agenda-for-mobile file))
  2772. ((string-match "\\.html?\\'" file)
  2773. (require 'htmlize)
  2774. (set-buffer (htmlize-buffer (current-buffer)))
  2775. (when (and org-agenda-export-html-style
  2776. (string-match "<style>" org-agenda-export-html-style))
  2777. ;; replace <style> section with org-agenda-export-html-style
  2778. (goto-char (point-min))
  2779. (kill-region (- (search-forward "<style") 6)
  2780. (search-forward "</style>"))
  2781. (insert org-agenda-export-html-style))
  2782. (write-file file)
  2783. (kill-buffer (current-buffer))
  2784. (message "HTML written to %s" file))
  2785. ((string-match "\\.ps\\'" file)
  2786. (require 'ps-print)
  2787. (ps-print-buffer-with-faces file)
  2788. (message "Postscript written to %s" file))
  2789. ((string-match "\\.pdf\\'" file)
  2790. (require 'ps-print)
  2791. (ps-print-buffer-with-faces
  2792. (concat (file-name-sans-extension file) ".ps"))
  2793. (call-process "ps2pdf" nil nil nil
  2794. (expand-file-name
  2795. (concat (file-name-sans-extension file) ".ps"))
  2796. (expand-file-name file))
  2797. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2798. (message "PDF written to %s" file))
  2799. ((string-match "\\.ics\\'" file)
  2800. (require 'org-icalendar)
  2801. (let ((org-agenda-marker-table
  2802. (org-create-marker-find-array
  2803. (org-agenda-collect-markers)))
  2804. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2805. (org-combined-agenda-icalendar-file file))
  2806. (apply 'org-export-icalendar 'combine
  2807. (org-agenda-files nil 'ifmode))))
  2808. (t
  2809. (let ((bs (buffer-string)))
  2810. (find-file file)
  2811. (erase-buffer)
  2812. (insert bs)
  2813. (save-buffer 0)
  2814. (kill-buffer (current-buffer))
  2815. (message "Plain text written to %s" file))))))))
  2816. (set-buffer (or agenda-bufname
  2817. (and (called-interactively-p 'any) (buffer-name))
  2818. org-agenda-buffer-name)))
  2819. (when open (org-open-file file)))
  2820. (defvar org-agenda-tag-filter-overlays nil)
  2821. (defvar org-agenda-cat-filter-overlays nil)
  2822. (defun org-agenda-mark-filtered-text ()
  2823. "Mark all text hidden by filtering with a text property."
  2824. (let ((inhibit-read-only t))
  2825. (mapc
  2826. (lambda (o)
  2827. (when (equal (overlay-buffer o) (current-buffer))
  2828. (put-text-property
  2829. (overlay-start o) (overlay-end o)
  2830. 'org-filtered t)))
  2831. (append org-agenda-tag-filter-overlays
  2832. org-agenda-cat-filter-overlays))))
  2833. (defun org-agenda-unmark-filtered-text ()
  2834. "Remove the filtering text property."
  2835. (let ((inhibit-read-only t))
  2836. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2837. (defun org-agenda-remove-marked-text (property &optional value)
  2838. "Delete all text marked with VALUE of PROPERTY.
  2839. VALUE defaults to t."
  2840. (let (beg)
  2841. (setq value (or value t))
  2842. (while (setq beg (text-property-any (point-min) (point-max)
  2843. property value))
  2844. (delete-region
  2845. beg (or (next-single-property-change beg 'org-filtered)
  2846. (point-max))))))
  2847. (defun org-agenda-add-entry-text ()
  2848. "Add entry text to agenda lines.
  2849. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2850. entry text following headings shown in the agenda.
  2851. Drawers will be excluded, also the line with scheduling/deadline info."
  2852. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2853. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2854. (let (m txt)
  2855. (goto-char (point-min))
  2856. (while (not (eobp))
  2857. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2858. (beginning-of-line 2)
  2859. (setq txt (org-agenda-get-some-entry-text
  2860. m org-agenda-add-entry-text-maxlines " > "))
  2861. (end-of-line 1)
  2862. (if (string-match "\\S-" txt)
  2863. (insert "\n" txt)
  2864. (or (eobp) (forward-char 1))))))))
  2865. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2866. &rest keep)
  2867. "Extract entry text from MARKER, at most N-LINES lines.
  2868. This will ignore drawers etc, just get the text.
  2869. If INDENT is given, prefix every line with this string. If KEEP is
  2870. given, it is a list of symbols, defining stuff that should not be
  2871. removed from the entry content. Currently only `planning' is allowed here."
  2872. (let (txt drawer-re kwd-time-re ind)
  2873. (save-excursion
  2874. (with-current-buffer (marker-buffer marker)
  2875. (if (not (derived-mode-p 'org-mode))
  2876. (setq txt "")
  2877. (save-excursion
  2878. (save-restriction
  2879. (widen)
  2880. (goto-char marker)
  2881. (end-of-line 1)
  2882. (setq txt (buffer-substring
  2883. (min (1+ (point)) (point-max))
  2884. (progn (outline-next-heading) (point)))
  2885. drawer-re org-drawer-regexp
  2886. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2887. ".*\n?"))
  2888. (with-temp-buffer
  2889. (insert txt)
  2890. (when org-agenda-add-entry-text-descriptive-links
  2891. (goto-char (point-min))
  2892. (while (org-activate-bracket-links (point-max))
  2893. (add-text-properties (match-beginning 0) (match-end 0)
  2894. '(face org-link))))
  2895. (goto-char (point-min))
  2896. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2897. (set-text-properties (match-beginning 0) (match-end 0)
  2898. nil))
  2899. (goto-char (point-min))
  2900. (while (re-search-forward drawer-re nil t)
  2901. (delete-region
  2902. (match-beginning 0)
  2903. (progn (re-search-forward
  2904. "^[ \t]*:END:.*\n?" nil 'move)
  2905. (point))))
  2906. (unless (member 'planning keep)
  2907. (goto-char (point-min))
  2908. (while (re-search-forward kwd-time-re nil t)
  2909. (replace-match "")))
  2910. (goto-char (point-min))
  2911. (when org-agenda-entry-text-exclude-regexps
  2912. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2913. (while (setq re (pop re-list))
  2914. (goto-char (point-min))
  2915. (while (re-search-forward re nil t)
  2916. (replace-match "")))))
  2917. (goto-char (point-max))
  2918. (skip-chars-backward " \t\n")
  2919. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2920. ;; find and remove min common indentation
  2921. (goto-char (point-min))
  2922. (untabify (point-min) (point-max))
  2923. (setq ind (org-get-indentation))
  2924. (while (not (eobp))
  2925. (unless (looking-at "[ \t]*$")
  2926. (setq ind (min ind (org-get-indentation))))
  2927. (beginning-of-line 2))
  2928. (goto-char (point-min))
  2929. (while (not (eobp))
  2930. (unless (looking-at "[ \t]*$")
  2931. (move-to-column ind)
  2932. (delete-region (point-at-bol) (point)))
  2933. (beginning-of-line 2))
  2934. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2935. (goto-char (point-min))
  2936. (when indent
  2937. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2938. (replace-match indent t t)))
  2939. (goto-char (point-min))
  2940. (while (looking-at "[ \t]*\n") (replace-match ""))
  2941. (goto-char (point-max))
  2942. (when (> (org-current-line)
  2943. n-lines)
  2944. (org-goto-line (1+ n-lines))
  2945. (backward-char 1))
  2946. (setq txt (buffer-substring (point-min) (point)))))))))
  2947. txt))
  2948. (defun org-agenda-collect-markers ()
  2949. "Collect the markers pointing to entries in the agenda buffer."
  2950. (let (m markers)
  2951. (save-excursion
  2952. (goto-char (point-min))
  2953. (while (not (eobp))
  2954. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2955. (org-get-at-bol 'org-marker)))
  2956. (push m markers))
  2957. (beginning-of-line 2)))
  2958. (nreverse markers)))
  2959. (defun org-create-marker-find-array (marker-list)
  2960. "Create a alist of files names with all marker positions in that file."
  2961. (let (f tbl m a p)
  2962. (while (setq m (pop marker-list))
  2963. (setq p (marker-position m)
  2964. f (buffer-file-name (or (buffer-base-buffer
  2965. (marker-buffer m))
  2966. (marker-buffer m))))
  2967. (if (setq a (assoc f tbl))
  2968. (push (marker-position m) (cdr a))
  2969. (push (list f p) tbl)))
  2970. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2971. tbl)))
  2972. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2973. (defun org-check-agenda-marker-table ()
  2974. "Check of the current entry is on the marker list."
  2975. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2976. a)
  2977. (and (setq a (assoc file org-agenda-marker-table))
  2978. (save-match-data
  2979. (save-excursion
  2980. (org-back-to-heading t)
  2981. (member (point) (cdr a)))))))
  2982. (defun org-check-for-org-mode ()
  2983. "Make sure current buffer is in org-mode. Error if not."
  2984. (or (derived-mode-p 'org-mode)
  2985. (error "Cannot execute org-mode agenda command on buffer in %s"
  2986. major-mode)))
  2987. ;;; Agenda prepare and finalize
  2988. (defvar org-agenda-multi nil) ; dynamically scoped
  2989. (defvar org-agenda-pre-window-conf nil)
  2990. (defvar org-agenda-columns-active nil)
  2991. (defvar org-agenda-name nil)
  2992. (defvar org-agenda-tag-filter nil)
  2993. (defvar org-agenda-category-filter nil)
  2994. (defvar org-agenda-top-category-filter nil)
  2995. (defvar org-agenda-tag-filter-while-redo nil)
  2996. (defvar org-agenda-tag-filter-preset nil
  2997. "A preset of the tags filter used for secondary agenda filtering.
  2998. This must be a list of strings, each string must be a single tag preceded
  2999. by \"+\" or \"-\".
  3000. This variable should not be set directly, but agenda custom commands can
  3001. bind it in the options section. The preset filter is a global property of
  3002. the entire agenda view. In a block agenda, it will not work reliably to
  3003. define a filter for one of the individual blocks. You need to set it in
  3004. the global options and expect it to be applied to the entire view.")
  3005. (defvar org-agenda-category-filter-preset nil
  3006. "A preset of the category filter used for secondary agenda filtering.
  3007. This must be a list of strings, each string must be a single category
  3008. preceded by \"+\" or \"-\".
  3009. This variable should not be set directly, but agenda custom commands can
  3010. bind it in the options section. The preset filter is a global property of
  3011. the entire agenda view. In a block agenda, it will not work reliably to
  3012. define a filter for one of the individual blocks. You need to set it in
  3013. the global options and expect it to be applied to the entire view.")
  3014. (defun org-agenda-use-sticky-p ()
  3015. "Return non-nil if an agenda buffer named
  3016. `org-agenda-buffer-name' exists and should be shown instead of
  3017. generating a new one."
  3018. (and
  3019. ;; turned off by user
  3020. org-agenda-sticky
  3021. ;; For multi-agenda buffer already exists
  3022. (not org-agenda-multi)
  3023. ;; buffer found
  3024. (get-buffer org-agenda-buffer-name)
  3025. ;; C-u parameter is same as last call
  3026. (with-current-buffer (get-buffer org-agenda-buffer-name)
  3027. (and
  3028. (equal current-prefix-arg
  3029. org-agenda-last-prefix-arg)
  3030. ;; In case user turned stickiness on, while having existing
  3031. ;; Agenda buffer active, don't reuse that buffer, because it
  3032. ;; does not have org variables local
  3033. org-agenda-this-buffer-is-sticky))))
  3034. (defun org-agenda-prepare-window (abuf)
  3035. "Setup agenda buffer in the window."
  3036. (let* ((awin (get-buffer-window abuf))
  3037. wconf)
  3038. (cond
  3039. ((equal (current-buffer) abuf) nil)
  3040. (awin (select-window awin))
  3041. ((not (setq wconf (current-window-configuration))))
  3042. ((equal org-agenda-window-setup 'current-window)
  3043. (org-pop-to-buffer-same-window abuf))
  3044. ((equal org-agenda-window-setup 'other-window)
  3045. (org-switch-to-buffer-other-window abuf))
  3046. ((equal org-agenda-window-setup 'other-frame)
  3047. (switch-to-buffer-other-frame abuf))
  3048. ((equal org-agenda-window-setup 'reorganize-frame)
  3049. (delete-other-windows)
  3050. (org-switch-to-buffer-other-window abuf)))
  3051. ;; additional test in case agenda is invoked from within agenda
  3052. ;; buffer via elisp link
  3053. (unless (equal (current-buffer) abuf)
  3054. (org-pop-to-buffer-same-window abuf))
  3055. (setq org-agenda-pre-window-conf
  3056. (or org-agenda-pre-window-conf wconf))))
  3057. (defun org-agenda-prepare (&optional name)
  3058. (if (org-agenda-use-sticky-p)
  3059. (progn
  3060. ;; Popup existing buffer
  3061. (org-agenda-prepare-window (get-buffer org-agenda-buffer-name))
  3062. (message "Sticky Agenda buffer, use `r' to refresh")
  3063. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3064. (throw 'exit "Sticky Agenda buffer, use `r' to refresh"))
  3065. (setq org-todo-keywords-for-agenda nil)
  3066. (setq org-drawers-for-agenda nil)
  3067. (unless org-agenda-persistent-filter
  3068. (setq org-agenda-tag-filter nil
  3069. org-agenda-category-filter nil))
  3070. (put 'org-agenda-tag-filter :preset-filter
  3071. org-agenda-tag-filter-preset)
  3072. (put 'org-agenda-category-filter :preset-filter
  3073. org-agenda-category-filter-preset)
  3074. (if org-agenda-multi
  3075. (progn
  3076. (setq buffer-read-only nil)
  3077. (goto-char (point-max))
  3078. (unless (or (bobp) org-agenda-compact-blocks
  3079. (not org-agenda-block-separator))
  3080. (insert "\n"
  3081. (if (stringp org-agenda-block-separator)
  3082. org-agenda-block-separator
  3083. (make-string (window-width) org-agenda-block-separator))
  3084. "\n"))
  3085. (narrow-to-region (point) (point-max)))
  3086. (setq org-done-keywords-for-agenda nil)
  3087. ;; Setting any org variables that are in org-agenda-local-vars
  3088. ;; list need to be done after the prepare call
  3089. (org-agenda-prepare-window (get-buffer-create org-agenda-buffer-name))
  3090. (setq buffer-read-only nil)
  3091. (org-agenda-reset-markers)
  3092. (let ((inhibit-read-only t)) (erase-buffer))
  3093. (org-agenda-mode)
  3094. (setq org-agenda-buffer (current-buffer))
  3095. (setq org-agenda-contributing-files nil)
  3096. (setq org-agenda-columns-active nil)
  3097. (org-agenda-prepare-buffers (org-agenda-files nil 'ifmode))
  3098. (setq org-todo-keywords-for-agenda
  3099. (org-uniquify org-todo-keywords-for-agenda))
  3100. (setq org-done-keywords-for-agenda
  3101. (org-uniquify org-done-keywords-for-agenda))
  3102. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  3103. (setq org-agenda-last-prefix-arg current-prefix-arg)
  3104. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  3105. (and name (not org-agenda-name)
  3106. (org-set-local 'org-agenda-name name)))
  3107. (setq buffer-read-only nil)))
  3108. (defvar org-agenda-overriding-columns-format) ; From org-colview.el
  3109. (defun org-agenda-finalize ()
  3110. "Finishing touch for the agenda buffer, called just before displaying it."
  3111. (unless org-agenda-multi
  3112. (save-excursion
  3113. (let ((inhibit-read-only t))
  3114. (goto-char (point-min))
  3115. (while (org-activate-bracket-links (point-max))
  3116. (add-text-properties (match-beginning 0) (match-end 0)
  3117. '(face org-link)))
  3118. (org-agenda-align-tags)
  3119. (unless org-agenda-with-colors
  3120. (remove-text-properties (point-min) (point-max) '(face nil))))
  3121. (if (and (boundp 'org-agenda-overriding-columns-format)
  3122. org-agenda-overriding-columns-format)
  3123. (org-set-local 'org-agenda-overriding-columns-format
  3124. org-agenda-overriding-columns-format))
  3125. (if (and (boundp 'org-agenda-view-columns-initially)
  3126. org-agenda-view-columns-initially)
  3127. (org-agenda-columns))
  3128. (when org-agenda-fontify-priorities
  3129. (org-agenda-fontify-priorities))
  3130. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3131. (org-agenda-dim-blocked-tasks))
  3132. (org-agenda-mark-clocking-task)
  3133. (when org-agenda-entry-text-mode
  3134. (org-agenda-entry-text-hide)
  3135. (org-agenda-entry-text-show))
  3136. (if (functionp 'org-habit-insert-consistency-graphs)
  3137. (org-habit-insert-consistency-graphs))
  3138. (run-hooks 'org-agenda-finalize-hook)
  3139. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3140. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3141. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3142. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3143. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3144. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3145. )))
  3146. (defun org-agenda-mark-clocking-task ()
  3147. "Mark the current clock entry in the agenda if it is present."
  3148. (mapc (lambda (o)
  3149. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3150. (delete-overlay o)))
  3151. (overlays-in (point-min) (point-max)))
  3152. (when (marker-buffer org-clock-hd-marker)
  3153. (save-excursion
  3154. (goto-char (point-min))
  3155. (let (s ov)
  3156. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3157. (goto-char s)
  3158. (when (equal (org-get-at-bol 'org-hd-marker)
  3159. org-clock-hd-marker)
  3160. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3161. (overlay-put ov 'type 'org-agenda-clocking)
  3162. (overlay-put ov 'face 'org-agenda-clocking)
  3163. (overlay-put ov 'help-echo
  3164. "The clock is running in this item")))))))
  3165. (defun org-agenda-fontify-priorities ()
  3166. "Make highest priority lines bold, and lowest italic."
  3167. (interactive)
  3168. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3169. (delete-overlay o)))
  3170. (overlays-in (point-min) (point-max)))
  3171. (save-excursion
  3172. (let ((inhibit-read-only t)
  3173. b e p ov h l)
  3174. (goto-char (point-min))
  3175. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3176. (setq h (or (get-char-property (point) 'org-highest-priority)
  3177. org-highest-priority)
  3178. l (or (get-char-property (point) 'org-lowest-priority)
  3179. org-lowest-priority)
  3180. p (string-to-char (match-string 1))
  3181. b (match-beginning 0)
  3182. e (if (eq org-agenda-fontify-priorities 'cookies)
  3183. (match-end 0)
  3184. (point-at-eol))
  3185. ov (make-overlay b e))
  3186. (overlay-put
  3187. ov 'face
  3188. (cond ((org-face-from-face-or-color
  3189. 'priority nil
  3190. (cdr (assoc p org-priority-faces))))
  3191. ((and (listp org-agenda-fontify-priorities)
  3192. (org-face-from-face-or-color
  3193. 'priority nil
  3194. (cdr (assoc p org-agenda-fontify-priorities)))))
  3195. ((equal p l) 'italic)
  3196. ((equal p h) 'bold)))
  3197. (overlay-put ov 'org-type 'org-priority)))))
  3198. (defun org-agenda-dim-blocked-tasks ()
  3199. "Dim currently blocked TODO's in the agenda display."
  3200. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3201. (delete-overlay o)))
  3202. (overlays-in (point-min) (point-max)))
  3203. (save-excursion
  3204. (let ((inhibit-read-only t)
  3205. (org-depend-tag-blocked nil)
  3206. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3207. org-blocked-by-checkboxes
  3208. invis1 b e p ov h l)
  3209. (goto-char (point-min))
  3210. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3211. (and pos (goto-char (1+ pos))))
  3212. (setq org-blocked-by-checkboxes nil invis1 invis)
  3213. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3214. (when (and marker
  3215. (with-current-buffer (marker-buffer marker)
  3216. (save-excursion (goto-char marker)
  3217. (org-entry-blocked-p))))
  3218. (if org-blocked-by-checkboxes (setq invis1 nil))
  3219. (setq b (if invis1
  3220. (max (point-min) (1- (point-at-bol)))
  3221. (point-at-bol))
  3222. e (point-at-eol)
  3223. ov (make-overlay b e))
  3224. (if invis1
  3225. (overlay-put ov 'invisible t)
  3226. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3227. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3228. (defvar org-agenda-skip-function nil
  3229. "Function to be called at each match during agenda construction.
  3230. If this function returns nil, the current match should not be skipped.
  3231. Otherwise, the function must return a position from where the search
  3232. should be continued.
  3233. This may also be a Lisp form, it will be evaluated.
  3234. Never set this variable using `setq' or so, because then it will apply
  3235. to all future agenda commands. If you do want a global skipping condition,
  3236. use the option `org-agenda-skip-function-global' instead.
  3237. The correct usage for `org-agenda-skip-function' is to bind it with
  3238. `let' to scope it dynamically into the agenda-constructing command.
  3239. A good way to set it is through options in `org-agenda-custom-commands'.")
  3240. (defun org-agenda-skip ()
  3241. "Throw to `:skip' in places that should be skipped.
  3242. Also moves point to the end of the skipped region, so that search can
  3243. continue from there."
  3244. (let ((p (point-at-bol)) to)
  3245. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3246. (get-text-property p :org-archived)
  3247. (org-end-of-subtree t)
  3248. (throw :skip t))
  3249. (and org-agenda-skip-comment-trees
  3250. (get-text-property p :org-comment)
  3251. (org-end-of-subtree t)
  3252. (throw :skip t))
  3253. (if (equal (char-after p) ?#) (throw :skip t))
  3254. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3255. (org-agenda-skip-eval org-agenda-skip-function)))
  3256. (goto-char to)
  3257. (throw :skip t))))
  3258. (defun org-agenda-skip-eval (form)
  3259. "If FORM is a function or a list, call (or eval) is and return result.
  3260. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3261. and match data are returned to the previous state no matter what these
  3262. functions do."
  3263. (let (fp)
  3264. (and form
  3265. (or (setq fp (functionp form))
  3266. (consp form))
  3267. (save-excursion
  3268. (save-match-data
  3269. (if fp
  3270. (funcall form)
  3271. (eval form)))))))
  3272. (defvar org-agenda-markers nil
  3273. "List of all currently active markers created by `org-agenda'.")
  3274. (defvar org-agenda-last-marker-time (org-float-time)
  3275. "Creation time of the last agenda marker.")
  3276. (defun org-agenda-new-marker (&optional pos)
  3277. "Return a new agenda marker.
  3278. Org-mode keeps a list of these markers and resets them when they are
  3279. no longer in use."
  3280. (let ((m (copy-marker (or pos (point)))))
  3281. (setq org-agenda-last-marker-time (org-float-time))
  3282. (if org-agenda-buffer
  3283. (with-current-buffer org-agenda-buffer
  3284. (push m org-agenda-markers))
  3285. (push m org-agenda-markers))
  3286. m))
  3287. (defun org-agenda-reset-markers ()
  3288. "Reset markers created by `org-agenda'."
  3289. (while org-agenda-markers
  3290. (move-marker (pop org-agenda-markers) nil)))
  3291. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3292. "Save relative positions of markers in region.
  3293. This check for agenda markers in all agenda buffers currently active."
  3294. (dolist (buf (buffer-list))
  3295. (with-current-buffer buf
  3296. (when (eq major-mode 'org-agenda-mode)
  3297. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3298. org-agenda-markers)))))
  3299. ;;; Entry text mode
  3300. (defun org-agenda-entry-text-show-here ()
  3301. "Add some text from the entry as context to the current line."
  3302. (let (m txt o)
  3303. (setq m (org-get-at-bol 'org-hd-marker))
  3304. (unless (marker-buffer m)
  3305. (error "No marker points to an entry here"))
  3306. (setq txt (concat "\n" (org-no-properties
  3307. (org-agenda-get-some-entry-text
  3308. m org-agenda-entry-text-maxlines " > "))))
  3309. (when (string-match "\\S-" txt)
  3310. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3311. (overlay-put o 'evaporate t)
  3312. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3313. (overlay-put o 'after-string txt))))
  3314. (defun org-agenda-entry-text-show ()
  3315. "Add entry context for all agenda lines."
  3316. (interactive)
  3317. (save-excursion
  3318. (goto-char (point-max))
  3319. (beginning-of-line 1)
  3320. (while (not (bobp))
  3321. (when (org-get-at-bol 'org-hd-marker)
  3322. (org-agenda-entry-text-show-here))
  3323. (beginning-of-line 0))))
  3324. (defun org-agenda-entry-text-hide ()
  3325. "Remove any shown entry context."
  3326. (delq nil
  3327. (mapcar (lambda (o)
  3328. (if (eq (overlay-get o 'org-overlay-type)
  3329. 'agenda-entry-content)
  3330. (progn (delete-overlay o) t)))
  3331. (overlays-in (point-min) (point-max)))))
  3332. (defun org-agenda-get-day-face (date)
  3333. "Return the face DATE should be displayed with."
  3334. (or (and (functionp org-agenda-day-face-function)
  3335. (funcall org-agenda-day-face-function date))
  3336. (cond ((org-agenda-todayp date)
  3337. 'org-agenda-date-today)
  3338. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3339. 'org-agenda-date-weekend)
  3340. (t 'org-agenda-date))))
  3341. ;;; Agenda timeline
  3342. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3343. (defun org-timeline (&optional dotodo)
  3344. "Show a time-sorted view of the entries in the current org file.
  3345. Only entries with a time stamp of today or later will be listed. With
  3346. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3347. under the current date.
  3348. If the buffer contains an active region, only check the region for
  3349. dates."
  3350. (interactive "P")
  3351. (let* ((dopast t)
  3352. (org-agenda-show-log-scoped org-agenda-show-log)
  3353. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3354. (current-buffer))))
  3355. (date (calendar-current-date))
  3356. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3357. (end (if (org-region-active-p) (region-end) (point-max)))
  3358. (day-numbers (org-get-all-dates
  3359. beg end 'no-ranges
  3360. t org-agenda-show-log-scoped ; always include today
  3361. org-timeline-show-empty-dates))
  3362. (org-deadline-warning-days 0)
  3363. (org-agenda-only-exact-dates t)
  3364. (today (org-today))
  3365. (past t)
  3366. args
  3367. s e rtn d emptyp)
  3368. (setq org-agenda-redo-command
  3369. (list 'progn
  3370. (list 'org-switch-to-buffer-other-window (current-buffer))
  3371. (list 'org-timeline (list 'quote dotodo))))
  3372. (if (not dopast)
  3373. ;; Remove past dates from the list of dates.
  3374. (setq day-numbers (delq nil (mapcar (lambda(x)
  3375. (if (>= x today) x nil))
  3376. day-numbers))))
  3377. (org-agenda-prepare (concat "Timeline " (file-name-nondirectory entry)))
  3378. (org-compile-prefix-format 'timeline)
  3379. (org-set-sorting-strategy 'timeline)
  3380. (if org-agenda-show-log-scoped (push :closed args))
  3381. (push :timestamp args)
  3382. (push :deadline args)
  3383. (push :scheduled args)
  3384. (push :sexp args)
  3385. (if dotodo (push :todo args))
  3386. (insert "Timeline of file " entry "\n")
  3387. (add-text-properties (point-min) (point)
  3388. (list 'face 'org-agenda-structure))
  3389. (org-agenda-mark-header-line (point-min))
  3390. (while (setq d (pop day-numbers))
  3391. (if (and (listp d) (eq (car d) :omitted))
  3392. (progn
  3393. (setq s (point))
  3394. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3395. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3396. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3397. (if (and (>= d today)
  3398. dopast
  3399. past)
  3400. (progn
  3401. (setq past nil)
  3402. (insert (make-string 79 ?-) "\n")))
  3403. (setq date (calendar-gregorian-from-absolute d))
  3404. (setq s (point))
  3405. (setq rtn (and (not emptyp)
  3406. (apply 'org-agenda-get-day-entries entry
  3407. date args)))
  3408. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3409. (progn
  3410. (insert
  3411. (if (stringp org-agenda-format-date)
  3412. (format-time-string org-agenda-format-date
  3413. (org-time-from-absolute date))
  3414. (funcall org-agenda-format-date date))
  3415. "\n")
  3416. (put-text-property s (1- (point)) 'face
  3417. (org-agenda-get-day-face date))
  3418. (put-text-property s (1- (point)) 'org-date-line t)
  3419. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3420. (if (equal d today)
  3421. (put-text-property s (1- (point)) 'org-today t))
  3422. (and rtn (insert (org-agenda-finalize-entries rtn) "\n"))
  3423. (put-text-property s (1- (point)) 'day d)))))
  3424. (goto-char (point-min))
  3425. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3426. (point-min)))
  3427. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3428. (org-agenda-finalize)
  3429. (setq buffer-read-only t)))
  3430. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3431. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3432. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3433. not every single day in the range. If FORCE-TODAY is non-nil, make
  3434. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3435. inactive time stamps (those in square brackets) are included.
  3436. When EMPTY is non-nil, also include days without any entries."
  3437. (let ((re (concat
  3438. (if pre-re pre-re "")
  3439. (if inactive org-ts-regexp-both org-ts-regexp)))
  3440. dates dates1 date day day1 day2 ts1 ts2 pos)
  3441. (if force-today
  3442. (setq dates (list (org-today))))
  3443. (save-excursion
  3444. (goto-char beg)
  3445. (while (re-search-forward re end t)
  3446. (setq day (time-to-days (org-time-string-to-time
  3447. (substring (match-string 1) 0 10)
  3448. (current-buffer) (match-beginning 0))))
  3449. (or (memq day dates) (push day dates)))
  3450. (unless no-ranges
  3451. (goto-char beg)
  3452. (while (re-search-forward org-tr-regexp end t)
  3453. (setq pos (match-beginning 0))
  3454. (setq ts1 (substring (match-string 1) 0 10)
  3455. ts2 (substring (match-string 2) 0 10)
  3456. day1 (time-to-days (org-time-string-to-time
  3457. ts1 (current-buffer) pos))
  3458. day2 (time-to-days (org-time-string-to-time
  3459. ts2 (current-buffer) pos)))
  3460. (while (< (setq day1 (1+ day1)) day2)
  3461. (or (memq day1 dates) (push day1 dates)))))
  3462. (setq dates (sort dates '<))
  3463. (when empty
  3464. (while (setq day (pop dates))
  3465. (setq day2 (car dates))
  3466. (push day dates1)
  3467. (when (and day2 empty)
  3468. (if (or (eq empty t)
  3469. (and (numberp empty) (<= (- day2 day) empty)))
  3470. (while (< (setq day (1+ day)) day2)
  3471. (push (list day) dates1))
  3472. (push (cons :omitted (- day2 day)) dates1))))
  3473. (setq dates (nreverse dates1)))
  3474. dates)))
  3475. ;;; Agenda Daily/Weekly
  3476. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3477. "Start day for the agenda view.
  3478. Custom commands can set this variable in the options section.")
  3479. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3480. (defvar org-arg-loc nil) ; local variable
  3481. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3482. "List of types searched for when creating the daily/weekly agenda.
  3483. This variable is a list of symbols that controls the types of
  3484. items that appear in the daily/weekly agenda. Allowed symbols in this
  3485. list are are
  3486. :timestamp List items containing a date stamp or date range matching
  3487. the selected date. This includes sexp entries in
  3488. angular brackets.
  3489. :sexp List entries resulting from plain diary-like sexps.
  3490. :deadline List deadline due on that date. When the date is today,
  3491. also list any deadlines past due, or due within
  3492. `org-deadline-warning-days'. `:deadline' must appear before
  3493. `:scheduled' if the setting of
  3494. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3495. any effect.
  3496. :scheduled List all items which are scheduled for the given date.
  3497. The diary for *today* also contains items which were
  3498. scheduled earlier and are not yet marked DONE.
  3499. By default, all four types are turned on.
  3500. Never set this variable globally using `setq', because then it
  3501. will apply to all future agenda commands. Instead, bind it with
  3502. `let' to scope it dynamically into the agenda-constructing
  3503. command. A good way to set it is through options in
  3504. `org-agenda-custom-commands'. For a more flexible (though
  3505. somewhat less efficient) way of determining what is included in
  3506. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3507. (defvar org-agenda-buffer-tmp-name nil)
  3508. ;;;###autoload
  3509. (defun org-agenda-list (&optional arg start-day span)
  3510. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3511. The view will be for the current day or week, but from the overview buffer
  3512. you will be able to go to other days/weeks.
  3513. With a numeric prefix argument in an interactive call, the agenda will
  3514. span ARG days. Lisp programs should instead specify SPAN to change
  3515. the number of days. SPAN defaults to `org-agenda-span'.
  3516. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3517. given in `org-agenda-start-on-weekday'."
  3518. (interactive "P")
  3519. (if org-agenda-overriding-arguments
  3520. (setq arg (car org-agenda-overriding-arguments)
  3521. start-day (nth 1 org-agenda-overriding-arguments)
  3522. span (nth 2 org-agenda-overriding-arguments)))
  3523. (if (and (integerp arg) (> arg 0))
  3524. (setq span arg arg nil))
  3525. (catch 'exit
  3526. (setq org-agenda-buffer-name
  3527. (or org-agenda-buffer-tmp-name
  3528. (if org-agenda-sticky
  3529. (cond ((and org-keys (stringp org-match))
  3530. (format "*Org Agenda(%s:%s)*" org-keys org-match))
  3531. (org-keys
  3532. (format "*Org Agenda(%s)*" org-keys))
  3533. (t "*Org Agenda(a)*")))
  3534. org-agenda-buffer-name))
  3535. (org-agenda-prepare "Day/Week")
  3536. (setq start-day (or start-day org-agenda-start-day))
  3537. (if (stringp start-day)
  3538. ;; Convert to an absolute day number
  3539. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3540. (org-compile-prefix-format 'agenda)
  3541. (org-set-sorting-strategy 'agenda)
  3542. (let* ((span (org-agenda-ndays-to-span
  3543. (or span org-agenda-ndays org-agenda-span)))
  3544. (today (org-today))
  3545. (sd (or start-day today))
  3546. (ndays (org-agenda-span-to-ndays span sd))
  3547. (org-agenda-start-on-weekday
  3548. (if (eq ndays 7)
  3549. org-agenda-start-on-weekday))
  3550. (thefiles (org-agenda-files nil 'ifmode))
  3551. (files thefiles)
  3552. (start (if (or (null org-agenda-start-on-weekday)
  3553. (< ndays 7))
  3554. sd
  3555. (let* ((nt (calendar-day-of-week
  3556. (calendar-gregorian-from-absolute sd)))
  3557. (n1 org-agenda-start-on-weekday)
  3558. (d (- nt n1)))
  3559. (- sd (+ (if (< d 0) 7 0) d)))))
  3560. (day-numbers (list start))
  3561. (day-cnt 0)
  3562. (inhibit-redisplay (not debug-on-error))
  3563. (org-agenda-show-log-scoped org-agenda-show-log)
  3564. s e rtn rtnall file date d start-pos end-pos todayp
  3565. clocktable-start clocktable-end filter)
  3566. (setq org-agenda-redo-command
  3567. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3568. (dotimes (n (1- ndays))
  3569. (push (1+ (car day-numbers)) day-numbers))
  3570. (setq day-numbers (nreverse day-numbers))
  3571. (setq clocktable-start (car day-numbers)
  3572. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3573. (org-set-local 'org-starting-day (car day-numbers))
  3574. (org-set-local 'org-arg-loc arg)
  3575. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3576. (unless org-agenda-compact-blocks
  3577. (let* ((d1 (car day-numbers))
  3578. (d2 (org-last day-numbers))
  3579. (w1 (org-days-to-iso-week d1))
  3580. (w2 (org-days-to-iso-week d2)))
  3581. (setq s (point))
  3582. (if org-agenda-overriding-header
  3583. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3584. nil 'face 'org-agenda-structure) "\n")
  3585. (insert (org-agenda-span-name span)
  3586. "-agenda"
  3587. (if (< (- d2 d1) 350)
  3588. (if (= w1 w2)
  3589. (format " (W%02d)" w1)
  3590. (format " (W%02d-W%02d)" w1 w2))
  3591. "")
  3592. ":\n")))
  3593. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3594. 'org-date-line t))
  3595. (org-agenda-mark-header-line s))
  3596. (while (setq d (pop day-numbers))
  3597. (setq date (calendar-gregorian-from-absolute d)
  3598. s (point))
  3599. (if (or (setq todayp (= d today))
  3600. (and (not start-pos) (= d sd)))
  3601. (setq start-pos (point))
  3602. (if (and start-pos (not end-pos))
  3603. (setq end-pos (point))))
  3604. (setq files thefiles
  3605. rtnall nil)
  3606. (while (setq file (pop files))
  3607. (catch 'nextfile
  3608. (org-check-agenda-file file)
  3609. (let ((org-agenda-entry-types org-agenda-entry-types))
  3610. (unless org-agenda-include-deadlines
  3611. (setq org-agenda-entry-types
  3612. (delq :deadline org-agenda-entry-types)))
  3613. (cond
  3614. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3615. (setq rtn (org-agenda-get-day-entries
  3616. file date :closed)))
  3617. (org-agenda-show-log-scoped
  3618. (setq rtn (apply 'org-agenda-get-day-entries
  3619. file date
  3620. (append '(:closed) org-agenda-entry-types))))
  3621. (t
  3622. (setq rtn (apply 'org-agenda-get-day-entries
  3623. file date
  3624. org-agenda-entry-types)))))
  3625. (setq rtnall (append rtnall rtn)))) ;; all entries
  3626. (if org-agenda-include-diary
  3627. (let ((org-agenda-search-headline-for-time t))
  3628. (require 'diary-lib)
  3629. (setq rtn (org-get-entries-from-diary date))
  3630. (setq rtnall (append rtnall rtn))))
  3631. (if (or rtnall org-agenda-show-all-dates)
  3632. (progn
  3633. (setq day-cnt (1+ day-cnt))
  3634. (insert
  3635. (if (stringp org-agenda-format-date)
  3636. (format-time-string org-agenda-format-date
  3637. (org-time-from-absolute date))
  3638. (funcall org-agenda-format-date date))
  3639. "\n")
  3640. (put-text-property s (1- (point)) 'face
  3641. (org-agenda-get-day-face date))
  3642. (put-text-property s (1- (point)) 'org-date-line t)
  3643. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3644. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3645. (when todayp
  3646. (put-text-property s (1- (point)) 'org-today t))
  3647. (setq rtnall
  3648. (org-agenda-add-time-grid-maybe rtnall ndays todayp))
  3649. (if rtnall (insert ;; all entries
  3650. (org-agenda-finalize-entries rtnall)
  3651. "\n"))
  3652. (put-text-property s (1- (point)) 'day d)
  3653. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3654. (when (and org-agenda-clockreport-mode clocktable-start)
  3655. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3656. ;; the above line is to ensure the restricted range!
  3657. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3658. tbl)
  3659. (setq p (org-plist-delete p :block))
  3660. (setq p (plist-put p :tstart clocktable-start))
  3661. (setq p (plist-put p :tend clocktable-end))
  3662. (setq p (plist-put p :scope 'agenda))
  3663. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3664. (setq filter (or org-agenda-tag-filter-while-redo
  3665. (get 'org-agenda-tag-filter :preset-filter))))
  3666. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3667. (if (string-match "[<>=]" x)
  3668. ""
  3669. x))
  3670. filter ""))))
  3671. (setq tbl (apply 'org-get-clocktable p))
  3672. (insert tbl)))
  3673. (goto-char (point-min))
  3674. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3675. (unless (and (pos-visible-in-window-p (point-min))
  3676. (pos-visible-in-window-p (point-max)))
  3677. (goto-char (1- (point-max)))
  3678. (recenter -1)
  3679. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3680. (progn
  3681. (goto-char (or start-pos 1))
  3682. (recenter 1))))
  3683. (goto-char (or start-pos 1))
  3684. (add-text-properties (point-min) (point-max)
  3685. `(org-agenda-type agenda
  3686. org-last-args (,arg ,start-day ,span)
  3687. org-redo-cmd ,org-agenda-redo-command
  3688. org-serie-cmd ,org-cmd))
  3689. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3690. (org-agenda-show-clocking-issues))
  3691. (org-agenda-finalize)
  3692. (setq buffer-read-only t)
  3693. (message ""))))
  3694. (defun org-agenda-ndays-to-span (n)
  3695. "Return a span symbol for a span of N days, or N if none matches."
  3696. (cond ((symbolp n) n)
  3697. ((= n 1) 'day)
  3698. ((= n 7) 'week)
  3699. (t n)))
  3700. (defun org-agenda-span-to-ndays (span &optional start-day)
  3701. "Return ndays from SPAN, possibly starting at START-DAY."
  3702. (cond ((numberp span) span)
  3703. ((eq span 'day) 1)
  3704. ((eq span 'week) 7)
  3705. ((eq span 'month)
  3706. (let ((date (calendar-gregorian-from-absolute start-day)))
  3707. (calendar-last-day-of-month (car date) (caddr date))))
  3708. ((eq span 'year)
  3709. (let ((date (calendar-gregorian-from-absolute start-day)))
  3710. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3711. (defun org-agenda-span-name (span)
  3712. "Return a SPAN name."
  3713. (if (null span)
  3714. ""
  3715. (if (symbolp span)
  3716. (capitalize (symbol-name span))
  3717. (format "%d days" span))))
  3718. ;;; Agenda word search
  3719. (defvar org-agenda-search-history nil)
  3720. (defvar org-search-syntax-table nil
  3721. "Special syntax table for org-mode search.
  3722. In this table, we have single quotes not as word constituents, to
  3723. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3724. (defvar org-mode-syntax-table) ; From org.el
  3725. (defun org-search-syntax-table ()
  3726. (unless org-search-syntax-table
  3727. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3728. (modify-syntax-entry ?' "." org-search-syntax-table)
  3729. (modify-syntax-entry ?` "." org-search-syntax-table))
  3730. org-search-syntax-table)
  3731. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3732. ;;;###autoload
  3733. (defun org-search-view (&optional todo-only string edit-at)
  3734. "Show all entries that contain a phrase or words or regular expressions.
  3735. With optional prefix argument TODO-ONLY, only consider entries that are
  3736. TODO entries. The argument STRING can be used to pass a default search
  3737. string into this function. If EDIT-AT is non-nil, it means that the
  3738. user should get a chance to edit this string, with cursor at position
  3739. EDIT-AT.
  3740. The search string can be viewed either as a phrase that should be found as
  3741. is, or it can be broken into a number of snippets, each of which must match
  3742. in a Boolean way to select an entry. The default depends on the variable
  3743. `org-agenda-search-view-always-boolean'.
  3744. Even if this is turned off (the default) you can always switch to
  3745. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3746. The default is a direct search of the whole phrase, where each space in
  3747. the search string can expand to an arbitrary amount of whitespace,
  3748. including newlines.
  3749. If using a Boolean search, the search string is split on whitespace and
  3750. each snippet is searched separately, with logical AND to select an entry.
  3751. Words prefixed with a minus must *not* occur in the entry. Words without
  3752. a prefix or prefixed with a plus must occur in the entry. Matching is
  3753. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3754. match whole words, not parts of a word) if
  3755. `org-agenda-search-view-force-full-words' is set (default is nil).
  3756. Boolean search snippets enclosed by curly braces are interpreted as
  3757. regular expressions that must or (when preceded with \"-\") must not
  3758. match in the entry. Snippets enclosed into double quotes will be taken
  3759. as a whole, to include whitespace.
  3760. - If the search string starts with an asterisk, search only in headlines.
  3761. - If (possibly after the leading star) the search string starts with an
  3762. exclamation mark, this also means to look at TODO entries only, an effect
  3763. that can also be achieved with a prefix argument.
  3764. - If (possibly after star and exclamation mark) the search string starts
  3765. with a colon, this will mean that the (non-regexp) snippets of the
  3766. Boolean search must match as full words.
  3767. This command searches the agenda files, and in addition the files listed
  3768. in `org-agenda-text-search-extra-files'."
  3769. (interactive "P")
  3770. (if org-agenda-overriding-arguments
  3771. (setq todo-only (car org-agenda-overriding-arguments)
  3772. string (nth 1 org-agenda-overriding-arguments)
  3773. edit-at (nth 2 org-agenda-overriding-arguments)))
  3774. (let* ((props (list 'face nil
  3775. 'done-face 'org-agenda-done
  3776. 'org-not-done-regexp org-not-done-regexp
  3777. 'org-todo-regexp org-todo-regexp
  3778. 'org-complex-heading-regexp org-complex-heading-regexp
  3779. 'mouse-face 'highlight
  3780. 'help-echo (format "mouse-2 or RET jump to location")))
  3781. (full-words org-agenda-search-view-force-full-words)
  3782. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3783. regexp rtn rtnall files file pos
  3784. marker category category-pos level tags c neg re boolean
  3785. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3786. (unless (and (not edit-at)
  3787. (stringp string)
  3788. (string-match "\\S-" string))
  3789. (setq string (read-string
  3790. (if org-agenda-search-view-always-boolean
  3791. "[+-]Word/{Regexp} ...: "
  3792. "Phrase or [+-]Word/{Regexp} ...: ")
  3793. (cond
  3794. ((integerp edit-at) (cons string edit-at))
  3795. (edit-at string))
  3796. 'org-agenda-search-history)))
  3797. (catch 'exit
  3798. (if org-agenda-sticky
  3799. (setq org-agenda-buffer-name
  3800. (if (stringp string)
  3801. (format "*Org Agenda(%s:%s)*"
  3802. (or org-keys (or (and todo-only "S") "s")) string)
  3803. (format "*Org Agenda(%s)*" (or (and todo-only "S") "s")))))
  3804. (org-agenda-prepare "SEARCH")
  3805. (org-compile-prefix-format 'search)
  3806. (org-set-sorting-strategy 'search)
  3807. (setq org-agenda-redo-command
  3808. (list 'org-search-view (if todo-only t nil)
  3809. (list 'if 'current-prefix-arg nil string)))
  3810. (setq org-agenda-query-string string)
  3811. (if (equal (string-to-char string) ?*)
  3812. (setq hdl-only t
  3813. words (substring string 1))
  3814. (setq words string))
  3815. (when (equal (string-to-char words) ?!)
  3816. (setq todo-only t
  3817. words (substring words 1)))
  3818. (when (equal (string-to-char words) ?:)
  3819. (setq full-words t
  3820. words (substring words 1)))
  3821. (if (or org-agenda-search-view-always-boolean
  3822. (member (string-to-char words) '(?- ?+ ?\{)))
  3823. (setq boolean t))
  3824. (setq words (org-split-string words))
  3825. (let (www w)
  3826. (while (setq w (pop words))
  3827. (while (and (string-match "\\\\\\'" w) words)
  3828. (setq w (concat (substring w 0 -1) " " (pop words))))
  3829. (push w www))
  3830. (setq words (nreverse www) www nil)
  3831. (while (setq w (pop words))
  3832. (when (and (string-match "\\`[-+]?{" w)
  3833. (not (string-match "}\\'" w)))
  3834. (while (and words (not (string-match "}\\'" (car words))))
  3835. (setq w (concat w " " (pop words))))
  3836. (setq w (concat w " " (pop words))))
  3837. (push w www))
  3838. (setq words (nreverse www)))
  3839. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3840. (when boolean
  3841. (let (wds w)
  3842. (while (setq w (pop words))
  3843. (if (or (equal (substring w 0 1) "\"")
  3844. (and (> (length w) 1)
  3845. (member (substring w 0 1) '("+" "-"))
  3846. (equal (substring w 1 2) "\"")))
  3847. (while (and words (not (equal (substring w -1) "\"")))
  3848. (setq w (concat w " " (pop words)))))
  3849. (and (string-match "\\`\\([-+]?\\)\"" w)
  3850. (setq w (replace-match "\\1" nil nil w)))
  3851. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3852. (push w wds))
  3853. (setq words (nreverse wds))))
  3854. (if boolean
  3855. (mapc (lambda (w)
  3856. (setq c (string-to-char w))
  3857. (if (equal c ?-)
  3858. (setq neg t w (substring w 1))
  3859. (if (equal c ?+)
  3860. (setq neg nil w (substring w 1))
  3861. (setq neg nil)))
  3862. (if (string-match "\\`{.*}\\'" w)
  3863. (setq re (substring w 1 -1))
  3864. (if full-words
  3865. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3866. (setq re (regexp-quote (downcase w)))))
  3867. (if neg (push re regexps-) (push re regexps+)))
  3868. words)
  3869. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3870. regexps+))
  3871. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3872. (if (not regexps+)
  3873. (setq regexp org-outline-regexp-bol)
  3874. (setq regexp (pop regexps+))
  3875. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3876. regexp))))
  3877. (setq files (org-agenda-files nil 'ifmode))
  3878. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3879. (pop org-agenda-text-search-extra-files)
  3880. (setq files (org-add-archive-files files)))
  3881. (setq files (append files org-agenda-text-search-extra-files)
  3882. rtnall nil)
  3883. (while (setq file (pop files))
  3884. (setq ee nil)
  3885. (catch 'nextfile
  3886. (org-check-agenda-file file)
  3887. (setq buffer (if (file-exists-p file)
  3888. (org-get-agenda-file-buffer file)
  3889. (error "No such file %s" file)))
  3890. (if (not buffer)
  3891. ;; If file does not exist, make sure an error message is sent
  3892. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3893. file))))
  3894. (with-current-buffer buffer
  3895. (with-syntax-table (org-search-syntax-table)
  3896. (unless (derived-mode-p 'org-mode)
  3897. (error "Agenda file %s is not in `org-mode'" file))
  3898. (let ((case-fold-search t))
  3899. (save-excursion
  3900. (save-restriction
  3901. (if org-agenda-restrict
  3902. (narrow-to-region org-agenda-restrict-begin
  3903. org-agenda-restrict-end)
  3904. (widen))
  3905. (goto-char (point-min))
  3906. (unless (or (org-at-heading-p)
  3907. (outline-next-heading))
  3908. (throw 'nextfile t))
  3909. (goto-char (max (point-min) (1- (point))))
  3910. (while (re-search-forward regexp nil t)
  3911. (org-back-to-heading t)
  3912. (skip-chars-forward "* ")
  3913. (setq beg (point-at-bol)
  3914. beg1 (point)
  3915. end (progn (outline-next-heading) (point)))
  3916. (catch :skip
  3917. (goto-char beg)
  3918. (org-agenda-skip)
  3919. (setq str (buffer-substring-no-properties
  3920. (point-at-bol)
  3921. (if hdl-only (point-at-eol) end)))
  3922. (mapc (lambda (wr) (when (string-match wr str)
  3923. (goto-char (1- end))
  3924. (throw :skip t)))
  3925. regexps-)
  3926. (mapc (lambda (wr) (unless (string-match wr str)
  3927. (goto-char (1- end))
  3928. (throw :skip t)))
  3929. (if todo-only
  3930. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3931. regexps+)
  3932. regexps+))
  3933. (goto-char beg)
  3934. (setq marker (org-agenda-new-marker (point))
  3935. category (org-get-category)
  3936. level (make-string (org-reduced-level (org-outline-level)) ? )
  3937. category-pos (get-text-property (point) 'org-category-position)
  3938. tags (org-get-tags-at (point))
  3939. txt (org-agenda-format-item
  3940. ""
  3941. (buffer-substring-no-properties
  3942. beg1 (point-at-eol))
  3943. level category tags))
  3944. (org-add-props txt props
  3945. 'org-marker marker 'org-hd-marker marker
  3946. 'org-todo-regexp org-todo-regexp
  3947. 'level level
  3948. 'org-complex-heading-regexp org-complex-heading-regexp
  3949. 'priority 1000 'org-category category
  3950. 'org-category-position category-pos
  3951. 'type "search")
  3952. (push txt ee)
  3953. (goto-char (1- end))))))))))
  3954. (setq rtn (nreverse ee))
  3955. (setq rtnall (append rtnall rtn)))
  3956. (if org-agenda-overriding-header
  3957. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3958. nil 'face 'org-agenda-structure) "\n")
  3959. (insert "Search words: ")
  3960. (add-text-properties (point-min) (1- (point))
  3961. (list 'face 'org-agenda-structure))
  3962. (setq pos (point))
  3963. (insert string "\n")
  3964. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3965. (setq pos (point))
  3966. (unless org-agenda-multi
  3967. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3968. (add-text-properties pos (1- (point))
  3969. (list 'face 'org-agenda-structure))))
  3970. (org-agenda-mark-header-line (point-min))
  3971. (when rtnall
  3972. (insert (org-agenda-finalize-entries rtnall) "\n"))
  3973. (goto-char (point-min))
  3974. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  3975. (add-text-properties (point-min) (point-max)
  3976. `(org-agenda-type search
  3977. org-last-args (,todo-only ,string ,edit-at)
  3978. org-redo-cmd ,org-agenda-redo-command
  3979. org-serie-cmd ,org-cmd))
  3980. (org-agenda-finalize)
  3981. (setq buffer-read-only t))))
  3982. ;;; Agenda TODO list
  3983. (defvar org-select-this-todo-keyword nil)
  3984. (defvar org-last-arg nil)
  3985. ;;;###autoload
  3986. (defun org-todo-list (&optional arg)
  3987. "Show all (not done) TODO entries from all agenda file in a single list.
  3988. The prefix arg can be used to select a specific TODO keyword and limit
  3989. the list to these. When using \\[universal-argument], you will be prompted
  3990. for a keyword. A numeric prefix directly selects the Nth keyword in
  3991. `org-todo-keywords-1'."
  3992. (interactive "P")
  3993. (if org-agenda-overriding-arguments
  3994. (setq arg org-agenda-overriding-arguments))
  3995. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3996. (let* ((today (org-today))
  3997. (date (calendar-gregorian-from-absolute today))
  3998. (kwds org-todo-keywords-for-agenda)
  3999. (completion-ignore-case t)
  4000. (org-select-this-todo-keyword
  4001. (if (stringp arg) arg
  4002. (and arg (integerp arg) (> arg 0)
  4003. (nth (1- arg) kwds))))
  4004. rtn rtnall files file pos)
  4005. (when (equal arg '(4))
  4006. (setq org-select-this-todo-keyword
  4007. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  4008. (mapcar 'list kwds) nil nil)))
  4009. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  4010. (catch 'exit
  4011. (if org-agenda-sticky
  4012. (setq org-agenda-buffer-name
  4013. (if (stringp org-select-this-todo-keyword)
  4014. (format "*Org Agenda(%s:%s)*" (or org-keys "t")
  4015. org-select-this-todo-keyword)
  4016. (format "*Org Agenda(%s)*" (or org-keys "t")))))
  4017. (org-agenda-prepare "TODO")
  4018. (org-compile-prefix-format 'todo)
  4019. (org-set-sorting-strategy 'todo)
  4020. (setq org-agenda-redo-command
  4021. `(org-todo-list (or current-prefix-arg (quote ,arg))))
  4022. (setq files (org-agenda-files nil 'ifmode)
  4023. rtnall nil)
  4024. (while (setq file (pop files))
  4025. (catch 'nextfile
  4026. (org-check-agenda-file file)
  4027. (setq rtn (org-agenda-get-day-entries file date :todo))
  4028. (setq rtnall (append rtnall rtn))))
  4029. (if org-agenda-overriding-header
  4030. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4031. nil 'face 'org-agenda-structure) "\n")
  4032. (insert "Global list of TODO items of type: ")
  4033. (add-text-properties (point-min) (1- (point))
  4034. (list 'face 'org-agenda-structure
  4035. 'short-heading
  4036. (concat "ToDo: "
  4037. (or org-select-this-todo-keyword "ALL"))))
  4038. (org-agenda-mark-header-line (point-min))
  4039. (setq pos (point))
  4040. (insert (or org-select-this-todo-keyword "ALL") "\n")
  4041. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4042. (setq pos (point))
  4043. (unless org-agenda-multi
  4044. (insert "Available with `N r': (0)[ALL]")
  4045. (let ((n 0) s)
  4046. (mapc (lambda (x)
  4047. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  4048. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  4049. (insert "\n "))
  4050. (insert " " s))
  4051. kwds))
  4052. (insert "\n"))
  4053. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4054. (org-agenda-mark-header-line (point-min))
  4055. (when rtnall
  4056. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4057. (goto-char (point-min))
  4058. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4059. (add-text-properties (point-min) (point-max)
  4060. `(org-agenda-type todo
  4061. org-last-args ,arg
  4062. org-redo-cmd ,org-agenda-redo-command
  4063. org-serie-cmd ,org-cmd))
  4064. (org-agenda-finalize)
  4065. (setq buffer-read-only t))))
  4066. ;;; Agenda tags match
  4067. ;;;###autoload
  4068. (defun org-tags-view (&optional todo-only match)
  4069. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  4070. The prefix arg TODO-ONLY limits the search to TODO entries."
  4071. (interactive "P")
  4072. (if org-agenda-overriding-arguments
  4073. (setq todo-only (car org-agenda-overriding-arguments)
  4074. match (nth 1 org-agenda-overriding-arguments)))
  4075. (let* ((org-tags-match-list-sublevels
  4076. org-tags-match-list-sublevels)
  4077. (completion-ignore-case t)
  4078. rtn rtnall files file pos matcher
  4079. buffer)
  4080. (when (and (stringp match) (not (string-match "\\S-" match)))
  4081. (setq match nil))
  4082. (setq matcher (org-make-tags-matcher match)
  4083. match (car matcher) matcher (cdr matcher))
  4084. (catch 'exit
  4085. (if org-agenda-sticky
  4086. (setq org-agenda-buffer-name
  4087. (if (stringp match)
  4088. (format "*Org Agenda(%s:%s)*"
  4089. (or org-keys (or (and todo-only "M") "m")) match)
  4090. (format "*Org Agenda(%s)*" (or (and todo-only "M") "m")))))
  4091. (org-agenda-prepare (concat "TAGS " match))
  4092. (org-compile-prefix-format 'tags)
  4093. (org-set-sorting-strategy 'tags)
  4094. (setq org-agenda-query-string match)
  4095. (setq org-agenda-redo-command
  4096. (list 'org-tags-view `(quote ,todo-only)
  4097. (list 'if 'current-prefix-arg nil `(quote ,org-agenda-query-string))))
  4098. (setq files (org-agenda-files nil 'ifmode)
  4099. rtnall nil)
  4100. (while (setq file (pop files))
  4101. (catch 'nextfile
  4102. (org-check-agenda-file file)
  4103. (setq buffer (if (file-exists-p file)
  4104. (org-get-agenda-file-buffer file)
  4105. (error "No such file %s" file)))
  4106. (if (not buffer)
  4107. ;; If file does not exist, error message to agenda
  4108. (setq rtn (list
  4109. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4110. rtnall (append rtnall rtn))
  4111. (with-current-buffer buffer
  4112. (unless (derived-mode-p 'org-mode)
  4113. (error "Agenda file %s is not in `org-mode'" file))
  4114. (save-excursion
  4115. (save-restriction
  4116. (if org-agenda-restrict
  4117. (narrow-to-region org-agenda-restrict-begin
  4118. org-agenda-restrict-end)
  4119. (widen))
  4120. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  4121. (setq rtnall (append rtnall rtn))))))))
  4122. (if org-agenda-overriding-header
  4123. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  4124. nil 'face 'org-agenda-structure) "\n")
  4125. (insert "Headlines with TAGS match: ")
  4126. (add-text-properties (point-min) (1- (point))
  4127. (list 'face 'org-agenda-structure
  4128. 'short-heading
  4129. (concat "Match: " match)))
  4130. (setq pos (point))
  4131. (insert match "\n")
  4132. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  4133. (setq pos (point))
  4134. (unless org-agenda-multi
  4135. (insert "Press `C-u r' to search again with new search string\n"))
  4136. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  4137. (org-agenda-mark-header-line (point-min))
  4138. (when rtnall
  4139. (insert (org-agenda-finalize-entries rtnall) "\n"))
  4140. (goto-char (point-min))
  4141. (or org-agenda-multi (org-agenda-fit-window-to-buffer))
  4142. (add-text-properties (point-min) (point-max)
  4143. `(org-agenda-type tags
  4144. org-last-args (,todo-only ,match)
  4145. org-redo-cmd ,org-agenda-redo-command
  4146. org-serie-cmd ,org-cmd))
  4147. (org-agenda-finalize)
  4148. (setq buffer-read-only t))))
  4149. ;;; Agenda Finding stuck projects
  4150. (defvar org-agenda-skip-regexp nil
  4151. "Regular expression used in skipping subtrees for the agenda.
  4152. This is basically a temporary global variable that can be set and then
  4153. used by user-defined selections using `org-agenda-skip-function'.")
  4154. (defvar org-agenda-overriding-header nil
  4155. "When set during agenda, todo and tags searches it replaces the header.
  4156. This variable should not be set directly, but custom commands can bind it
  4157. in the options section.")
  4158. (defun org-agenda-skip-entry-when-regexp-matches ()
  4159. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  4160. If yes, it returns the end position of this entry, causing agenda commands
  4161. to skip the entry but continuing the search in the subtree. This is a
  4162. function that can be put into `org-agenda-skip-function' for the duration
  4163. of a command."
  4164. (let ((end (save-excursion (org-end-of-subtree t)))
  4165. skip)
  4166. (save-excursion
  4167. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4168. (and skip end)))
  4169. (defun org-agenda-skip-subtree-when-regexp-matches ()
  4170. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4171. If yes, it returns the end position of this tree, causing agenda commands
  4172. to skip this subtree. This is a function that can be put into
  4173. `org-agenda-skip-function' for the duration of a command."
  4174. (let ((end (save-excursion (org-end-of-subtree t)))
  4175. skip)
  4176. (save-excursion
  4177. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4178. (and skip end)))
  4179. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4180. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4181. If yes, it returns the end position of the current entry (NOT the tree),
  4182. causing agenda commands to skip the entry but continuing the search in
  4183. the subtree. This is a function that can be put into
  4184. `org-agenda-skip-function' for the duration of a command. An important
  4185. use of this function is for the stuck project list."
  4186. (let ((end (save-excursion (org-end-of-subtree t)))
  4187. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4188. skip)
  4189. (save-excursion
  4190. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4191. (and skip entry-end)))
  4192. (defun org-agenda-skip-entry-if (&rest conditions)
  4193. "Skip entry if any of CONDITIONS is true.
  4194. See `org-agenda-skip-if' for details."
  4195. (org-agenda-skip-if nil conditions))
  4196. (defun org-agenda-skip-subtree-if (&rest conditions)
  4197. "Skip entry if any of CONDITIONS is true.
  4198. See `org-agenda-skip-if' for details."
  4199. (org-agenda-skip-if t conditions))
  4200. (defun org-agenda-skip-if (subtree conditions)
  4201. "Checks current entity for CONDITIONS.
  4202. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4203. the entry (i.e. the text before the next heading) is checked.
  4204. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4205. from different tests. Valid conditions are:
  4206. scheduled Check if there is a scheduled cookie
  4207. notscheduled Check if there is no scheduled cookie
  4208. deadline Check if there is a deadline
  4209. notdeadline Check if there is no deadline
  4210. timestamp Check if there is a timestamp (also deadline or scheduled)
  4211. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4212. regexp Check if regexp matches
  4213. notregexp Check if regexp does not match.
  4214. todo Check if TODO keyword matches
  4215. nottodo Check if TODO keyword does not match
  4216. The regexp is taken from the conditions list, it must come right after
  4217. the `regexp' or `notregexp' element.
  4218. `todo' and `nottodo' accept as an argument a list of todo
  4219. keywords, which may include \"*\" to match any todo keyword.
  4220. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4221. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4222. Instead of a list, a keyword class may be given. For example:
  4223. (org-agenda-skip-entry-if 'nottodo 'done)
  4224. would skip entries that haven't been marked with any of \"DONE\"
  4225. keywords. Possible classes are: `todo', `done', `any'.
  4226. If any of these conditions is met, this function returns the end point of
  4227. the entity, causing the search to continue from there. This is a function
  4228. that can be put into `org-agenda-skip-function' for the duration of a command."
  4229. (let (beg end m)
  4230. (org-back-to-heading t)
  4231. (setq beg (point)
  4232. end (if subtree
  4233. (progn (org-end-of-subtree t) (point))
  4234. (progn (outline-next-heading) (1- (point)))))
  4235. (goto-char beg)
  4236. (and
  4237. (or
  4238. (and (memq 'scheduled conditions)
  4239. (re-search-forward org-scheduled-time-regexp end t))
  4240. (and (memq 'notscheduled conditions)
  4241. (not (re-search-forward org-scheduled-time-regexp end t)))
  4242. (and (memq 'deadline conditions)
  4243. (re-search-forward org-deadline-time-regexp end t))
  4244. (and (memq 'notdeadline conditions)
  4245. (not (re-search-forward org-deadline-time-regexp end t)))
  4246. (and (memq 'timestamp conditions)
  4247. (re-search-forward org-ts-regexp end t))
  4248. (and (memq 'nottimestamp conditions)
  4249. (not (re-search-forward org-ts-regexp end t)))
  4250. (and (setq m (memq 'regexp conditions))
  4251. (stringp (nth 1 m))
  4252. (re-search-forward (nth 1 m) end t))
  4253. (and (setq m (memq 'notregexp conditions))
  4254. (stringp (nth 1 m))
  4255. (not (re-search-forward (nth 1 m) end t)))
  4256. (and (or
  4257. (setq m (memq 'nottodo conditions))
  4258. (setq m (memq 'todo-unblocked conditions))
  4259. (setq m (memq 'nottodo-unblocked conditions))
  4260. (setq m (memq 'todo conditions)))
  4261. (org-agenda-skip-if-todo m end)))
  4262. end)))
  4263. (defun org-agenda-skip-if-todo (args end)
  4264. "Helper function for `org-agenda-skip-if', do not use it directly.
  4265. ARGS is a list with first element either `todo', `nottodo',
  4266. `todo-unblocked' or `nottodo-unblocked'. The remainder is either
  4267. a list of TODO keywords, or a state symbol `todo' or `done' or
  4268. `any'."
  4269. (let ((kw (car args))
  4270. (arg (cadr args))
  4271. todo-wds todo-re)
  4272. (setq todo-wds
  4273. (org-uniquify
  4274. (cond
  4275. ((listp arg) ;; list of keywords
  4276. (if (member "*" arg)
  4277. (mapcar 'substring-no-properties org-todo-keywords-1)
  4278. arg))
  4279. ((symbolp arg) ;; keyword class name
  4280. (cond
  4281. ((eq arg 'todo)
  4282. (org-delete-all org-done-keywords
  4283. (mapcar 'substring-no-properties
  4284. org-todo-keywords-1)))
  4285. ((eq arg 'done) org-done-keywords)
  4286. ((eq arg 'any)
  4287. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4288. (setq todo-re
  4289. (concat "^\\*+[ \t]+\\<\\("
  4290. (mapconcat 'identity todo-wds "\\|")
  4291. "\\)\\>"))
  4292. (cond
  4293. ((eq kw 'todo) (re-search-forward todo-re end t))
  4294. ((eq kw 'nottodo) (not (re-search-forward todo-re end t)))
  4295. ((eq kw 'todo-unblocked)
  4296. (catch 'unblocked
  4297. (while (re-search-forward todo-re end t)
  4298. (or (org-entry-blocked-p) (throw 'unblocked t)))
  4299. nil))
  4300. ((eq kw 'nottodo-unblocked)
  4301. (catch 'unblocked
  4302. (while (re-search-forward todo-re end t)
  4303. (or (org-entry-blocked-p) (throw 'unblocked nil)))
  4304. t))
  4305. )))
  4306. ;;;###autoload
  4307. (defun org-agenda-list-stuck-projects (&rest ignore)
  4308. "Create agenda view for projects that are stuck.
  4309. Stuck projects are project that have no next actions. For the definitions
  4310. of what a project is and how to check if it stuck, customize the variable
  4311. `org-stuck-projects'."
  4312. (interactive)
  4313. (let* ((org-agenda-skip-function
  4314. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4315. ;; We could have used org-agenda-skip-if here.
  4316. (org-agenda-overriding-header
  4317. (or org-agenda-overriding-header "List of stuck projects: "))
  4318. (matcher (nth 0 org-stuck-projects))
  4319. (todo (nth 1 org-stuck-projects))
  4320. (todo-wds (if (member "*" todo)
  4321. (progn
  4322. (org-agenda-prepare-buffers (org-agenda-files
  4323. nil 'ifmode))
  4324. (org-delete-all
  4325. org-done-keywords-for-agenda
  4326. (copy-sequence org-todo-keywords-for-agenda)))
  4327. todo))
  4328. (todo-re (concat "^\\*+[ \t]+\\("
  4329. (mapconcat 'identity todo-wds "\\|")
  4330. "\\)\\>"))
  4331. (tags (nth 2 org-stuck-projects))
  4332. (tags-re (if (member "*" tags)
  4333. (concat org-outline-regexp-bol
  4334. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4335. (if tags
  4336. (concat org-outline-regexp-bol
  4337. ".*:\\("
  4338. (mapconcat 'identity tags "\\|")
  4339. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4340. (gen-re (nth 3 org-stuck-projects))
  4341. (re-list
  4342. (delq nil
  4343. (list
  4344. (if todo todo-re)
  4345. (if tags tags-re)
  4346. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4347. gen-re)))))
  4348. (setq org-agenda-skip-regexp
  4349. (if re-list
  4350. (mapconcat 'identity re-list "\\|")
  4351. (error "No information how to identify unstuck projects")))
  4352. (org-tags-view nil matcher)
  4353. (with-current-buffer org-agenda-buffer-name
  4354. (setq org-agenda-redo-command
  4355. `(org-agenda-list-stuck-projects ,current-prefix-arg)))))
  4356. ;;; Diary integration
  4357. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4358. (defvar diary-list-entries-hook)
  4359. (defvar diary-time-regexp)
  4360. (defun org-get-entries-from-diary (date)
  4361. "Get the (Emacs Calendar) diary entries for DATE."
  4362. (require 'diary-lib)
  4363. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4364. (diary-display-hook '(fancy-diary-display))
  4365. (diary-display-function 'fancy-diary-display)
  4366. (pop-up-frames nil)
  4367. (diary-list-entries-hook
  4368. (cons 'org-diary-default-entry diary-list-entries-hook))
  4369. (diary-file-name-prefix-function nil) ; turn this feature off
  4370. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4371. entries
  4372. (org-disable-agenda-to-diary t))
  4373. (save-excursion
  4374. (save-window-excursion
  4375. (funcall (if (fboundp 'diary-list-entries)
  4376. 'diary-list-entries 'list-diary-entries)
  4377. date 1)))
  4378. (if (not (get-buffer diary-fancy-buffer))
  4379. (setq entries nil)
  4380. (with-current-buffer diary-fancy-buffer
  4381. (setq buffer-read-only nil)
  4382. (if (zerop (buffer-size))
  4383. ;; No entries
  4384. (setq entries nil)
  4385. ;; Omit the date and other unnecessary stuff
  4386. (org-agenda-cleanup-fancy-diary)
  4387. ;; Add prefix to each line and extend the text properties
  4388. (if (zerop (buffer-size))
  4389. (setq entries nil)
  4390. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4391. (setq entries
  4392. (with-temp-buffer
  4393. (insert entries) (goto-char (point-min))
  4394. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4395. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4396. (replace-match (concat "; " (match-string 1)))))
  4397. (buffer-string)))))
  4398. (set-buffer-modified-p nil)
  4399. (kill-buffer diary-fancy-buffer)))
  4400. (when entries
  4401. (setq entries (org-split-string entries "\n"))
  4402. (setq entries
  4403. (mapcar
  4404. (lambda (x)
  4405. (setq x (org-agenda-format-item "" x nil "Diary" nil 'time))
  4406. ;; Extend the text properties to the beginning of the line
  4407. (org-add-props x (text-properties-at (1- (length x)) x)
  4408. 'type "diary" 'date date 'face 'org-agenda-diary))
  4409. entries)))))
  4410. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4411. "Hook run when the fancy diary buffer is cleaned up.")
  4412. (defun org-agenda-cleanup-fancy-diary ()
  4413. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4414. This gets rid of the date, the underline under the date, and
  4415. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4416. date. It also removes lines that contain only whitespace."
  4417. (goto-char (point-min))
  4418. (if (looking-at ".*?:[ \t]*")
  4419. (progn
  4420. (replace-match "")
  4421. (re-search-forward "\n=+$" nil t)
  4422. (replace-match "")
  4423. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4424. (re-search-forward "\n=+$" nil t)
  4425. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4426. (goto-char (point-min))
  4427. (while (re-search-forward "^ +\n" nil t)
  4428. (replace-match ""))
  4429. (goto-char (point-min))
  4430. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4431. (replace-match ""))
  4432. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4433. ;; Make sure entries from the diary have the right text properties.
  4434. (eval-after-load "diary-lib"
  4435. '(if (boundp 'diary-modify-entry-list-string-function)
  4436. ;; We can rely on the hook, nothing to do
  4437. nil
  4438. ;; Hook not available, must use advice to make this work
  4439. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4440. "Make the position visible."
  4441. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4442. (stringp string)
  4443. buffer-file-name)
  4444. (setq string (org-modify-diary-entry-string string))))))
  4445. (defun org-modify-diary-entry-string (string)
  4446. "Add text properties to string, allowing org-mode to act on it."
  4447. (org-add-props string nil
  4448. 'mouse-face 'highlight
  4449. 'help-echo (if buffer-file-name
  4450. (format "mouse-2 or RET jump to diary file %s"
  4451. (abbreviate-file-name buffer-file-name))
  4452. "")
  4453. 'org-agenda-diary-link t
  4454. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4455. (defun org-diary-default-entry ()
  4456. "Add a dummy entry to the diary.
  4457. Needed to avoid empty dates which mess up holiday display."
  4458. ;; Catch the error if dealing with the new add-to-diary-alist
  4459. (when org-disable-agenda-to-diary
  4460. (condition-case nil
  4461. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4462. (error
  4463. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4464. (defun org-add-to-diary-list (&rest args)
  4465. (if (fboundp 'diary-add-to-list)
  4466. (apply 'diary-add-to-list args)
  4467. (apply 'add-to-diary-list args)))
  4468. (defvar org-diary-last-run-time nil)
  4469. ;;;###autoload
  4470. (defun org-diary (&rest args)
  4471. "Return diary information from org files.
  4472. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4473. It accesses org files and extracts information from those files to be
  4474. listed in the diary. The function accepts arguments specifying what
  4475. items should be listed. For a list of arguments allowed here, see the
  4476. variable `org-agenda-entry-types'.
  4477. The call in the diary file should look like this:
  4478. &%%(org-diary) ~/path/to/some/orgfile.org
  4479. Use a separate line for each org file to check. Or, if you omit the file name,
  4480. all files listed in `org-agenda-files' will be checked automatically:
  4481. &%%(org-diary)
  4482. If you don't give any arguments (as in the example above), the default
  4483. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4484. So the example above may also be written as
  4485. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4486. The function expects the lisp variables `entry' and `date' to be provided
  4487. by the caller, because this is how the calendar works. Don't use this
  4488. function from a program - use `org-agenda-get-day-entries' instead."
  4489. (when (> (- (org-float-time)
  4490. org-agenda-last-marker-time)
  4491. 5)
  4492. ;; I am not sure if this works with sticky agendas, because the marker
  4493. ;; list is then no longer a global variable.
  4494. (org-agenda-reset-markers))
  4495. (org-compile-prefix-format 'agenda)
  4496. (org-set-sorting-strategy 'agenda)
  4497. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4498. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4499. (list entry)
  4500. (org-agenda-files t)))
  4501. (time (org-float-time))
  4502. file rtn results)
  4503. (when (or (not org-diary-last-run-time)
  4504. (> (- time
  4505. org-diary-last-run-time)
  4506. 3))
  4507. (org-agenda-prepare-buffers files))
  4508. (setq org-diary-last-run-time time)
  4509. ;; If this is called during org-agenda, don't return any entries to
  4510. ;; the calendar. Org Agenda will list these entries itself.
  4511. (if org-disable-agenda-to-diary (setq files nil))
  4512. (while (setq file (pop files))
  4513. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4514. (setq results (append results rtn)))
  4515. (if results
  4516. (concat (org-agenda-finalize-entries results) "\n"))))
  4517. ;;; Agenda entry finders
  4518. (defun org-agenda-get-day-entries (file date &rest args)
  4519. "Does the work for `org-diary' and `org-agenda'.
  4520. FILE is the path to a file to be checked for entries. DATE is date like
  4521. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4522. which kind of entries should be extracted. For details about these, see
  4523. the documentation of `org-diary'."
  4524. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4525. (let* ((org-startup-folded nil)
  4526. (org-startup-align-all-tables nil)
  4527. (buffer (if (file-exists-p file)
  4528. (org-get-agenda-file-buffer file)
  4529. (error "No such file %s" file)))
  4530. arg results rtn deadline-results)
  4531. (if (not buffer)
  4532. ;; If file does not exist, make sure an error message ends up in diary
  4533. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4534. (with-current-buffer buffer
  4535. (unless (derived-mode-p 'org-mode)
  4536. (error "Agenda file %s is not in `org-mode'" file))
  4537. (setq org-agenda-buffer (or org-agenda-buffer buffer))
  4538. (let ((case-fold-search nil))
  4539. (save-excursion
  4540. (save-restriction
  4541. (if org-agenda-restrict
  4542. (narrow-to-region org-agenda-restrict-begin
  4543. org-agenda-restrict-end)
  4544. (widen))
  4545. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4546. (while (setq arg (pop args))
  4547. (cond
  4548. ((and (eq arg :todo)
  4549. (equal date (calendar-gregorian-from-absolute
  4550. (org-today))))
  4551. (setq rtn (org-agenda-get-todos))
  4552. (setq results (append results rtn)))
  4553. ((eq arg :timestamp)
  4554. (setq rtn (org-agenda-get-blocks))
  4555. (setq results (append results rtn))
  4556. (setq rtn (org-agenda-get-timestamps deadline-results))
  4557. (setq results (append results rtn)))
  4558. ((eq arg :sexp)
  4559. (setq rtn (org-agenda-get-sexps))
  4560. (setq results (append results rtn)))
  4561. ((eq arg :scheduled)
  4562. (setq rtn (org-agenda-get-scheduled deadline-results))
  4563. (setq results (append results rtn)))
  4564. ((eq arg :closed)
  4565. (setq rtn (org-agenda-get-progress))
  4566. (setq results (append results rtn)))
  4567. ((eq arg :deadline)
  4568. (setq rtn (org-agenda-get-deadlines))
  4569. (setq deadline-results (copy-sequence rtn))
  4570. (setq results (append results rtn))))))))
  4571. results))))
  4572. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4573. (defun org-agenda-get-todos ()
  4574. "Return the TODO information for agenda display."
  4575. (let* ((props (list 'face nil
  4576. 'done-face 'org-agenda-done
  4577. 'org-not-done-regexp org-not-done-regexp
  4578. 'org-todo-regexp org-todo-regexp
  4579. 'org-complex-heading-regexp org-complex-heading-regexp
  4580. 'mouse-face 'highlight
  4581. 'help-echo
  4582. (format "mouse-2 or RET jump to org file %s"
  4583. (abbreviate-file-name buffer-file-name))))
  4584. (regexp (format org-heading-keyword-regexp-format
  4585. (cond
  4586. ((and org-select-this-todo-keyword
  4587. (equal org-select-this-todo-keyword "*"))
  4588. org-todo-regexp)
  4589. (org-select-this-todo-keyword
  4590. (concat "\\("
  4591. (mapconcat 'identity
  4592. (org-split-string
  4593. org-select-this-todo-keyword
  4594. "|")
  4595. "\\|") "\\)"))
  4596. (t org-not-done-regexp))))
  4597. marker priority category category-pos level tags todo-state
  4598. ee txt beg end)
  4599. (goto-char (point-min))
  4600. (while (re-search-forward regexp nil t)
  4601. (catch :skip
  4602. (save-match-data
  4603. (beginning-of-line)
  4604. (org-agenda-skip)
  4605. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4606. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4607. (goto-char (1+ beg))
  4608. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4609. (throw :skip nil)))
  4610. (goto-char (match-beginning 2))
  4611. (setq marker (org-agenda-new-marker (match-beginning 0))
  4612. category (org-get-category)
  4613. category-pos (get-text-property (point) 'org-category-position)
  4614. txt (org-trim
  4615. (buffer-substring (match-beginning 2) (match-end 0)))
  4616. tags (org-get-tags-at (point))
  4617. level (make-string (org-reduced-level (org-outline-level)) ? )
  4618. txt (org-agenda-format-item "" txt level category tags)
  4619. priority (1+ (org-get-priority txt))
  4620. todo-state (org-get-todo-state))
  4621. (org-add-props txt props
  4622. 'org-marker marker 'org-hd-marker marker
  4623. 'priority priority 'org-category category
  4624. 'level level
  4625. 'org-category-position category-pos
  4626. 'type "todo" 'todo-state todo-state)
  4627. (push txt ee)
  4628. (if org-agenda-todo-list-sublevels
  4629. (goto-char (match-end 2))
  4630. (org-end-of-subtree 'invisible))))
  4631. (nreverse ee)))
  4632. (defun org-agenda-todo-custom-ignore-p (time n)
  4633. "Check whether timestamp is farther away then n number of days.
  4634. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4635. `org-agenda-todo-ignore-scheduled' or
  4636. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4637. (let ((days (org-days-to-time time)))
  4638. (if (>= n 0)
  4639. (>= days n)
  4640. (<= days n))))
  4641. ;;;###autoload
  4642. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4643. (&optional end)
  4644. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4645. (when (or org-agenda-todo-ignore-with-date
  4646. org-agenda-todo-ignore-scheduled
  4647. org-agenda-todo-ignore-deadlines
  4648. org-agenda-todo-ignore-timestamp)
  4649. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4650. (save-excursion
  4651. (or (and org-agenda-todo-ignore-with-date
  4652. (re-search-forward org-ts-regexp end t))
  4653. (and org-agenda-todo-ignore-scheduled
  4654. (re-search-forward org-scheduled-time-regexp end t)
  4655. (cond
  4656. ((eq org-agenda-todo-ignore-scheduled 'future)
  4657. (> (org-days-to-time (match-string 1)) 0))
  4658. ((eq org-agenda-todo-ignore-scheduled 'past)
  4659. (<= (org-days-to-time (match-string 1)) 0))
  4660. ((numberp org-agenda-todo-ignore-scheduled)
  4661. (org-agenda-todo-custom-ignore-p
  4662. (match-string 1) org-agenda-todo-ignore-scheduled))
  4663. (t)))
  4664. (and org-agenda-todo-ignore-deadlines
  4665. (re-search-forward org-deadline-time-regexp end t)
  4666. (cond
  4667. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4668. ((eq org-agenda-todo-ignore-deadlines 'far)
  4669. (not (org-deadline-close (match-string 1))))
  4670. ((eq org-agenda-todo-ignore-deadlines 'future)
  4671. (> (org-days-to-time (match-string 1)) 0))
  4672. ((eq org-agenda-todo-ignore-deadlines 'past)
  4673. (<= (org-days-to-time (match-string 1)) 0))
  4674. ((numberp org-agenda-todo-ignore-deadlines)
  4675. (org-agenda-todo-custom-ignore-p
  4676. (match-string 1) org-agenda-todo-ignore-deadlines))
  4677. (t (org-deadline-close (match-string 1)))))
  4678. (and org-agenda-todo-ignore-timestamp
  4679. (let ((buffer (current-buffer))
  4680. (regexp
  4681. (concat
  4682. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4683. (start (point)))
  4684. ;; Copy current buffer into a temporary one
  4685. (with-temp-buffer
  4686. (insert-buffer-substring buffer start end)
  4687. (goto-char (point-min))
  4688. ;; Delete SCHEDULED and DEADLINE items
  4689. (while (re-search-forward regexp end t)
  4690. (delete-region (match-beginning 0) (match-end 0)))
  4691. (goto-char (point-min))
  4692. ;; No search for timestamp left
  4693. (when (re-search-forward org-ts-regexp nil t)
  4694. (cond
  4695. ((eq org-agenda-todo-ignore-timestamp 'future)
  4696. (> (org-days-to-time (match-string 1)) 0))
  4697. ((eq org-agenda-todo-ignore-timestamp 'past)
  4698. (<= (org-days-to-time (match-string 1)) 0))
  4699. ((numberp org-agenda-todo-ignore-timestamp)
  4700. (org-agenda-todo-custom-ignore-p
  4701. (match-string 1) org-agenda-todo-ignore-timestamp))
  4702. (t))))))))))
  4703. (defconst org-agenda-no-heading-message
  4704. "No heading for this item in buffer or region.")
  4705. (defun org-agenda-get-timestamps (&optional deadline-results)
  4706. "Return the date stamp information for agenda display."
  4707. (let* ((props (list 'face 'org-agenda-calendar-event
  4708. 'org-not-done-regexp org-not-done-regexp
  4709. 'org-todo-regexp org-todo-regexp
  4710. 'org-complex-heading-regexp org-complex-heading-regexp
  4711. 'mouse-face 'highlight
  4712. 'help-echo
  4713. (format "mouse-2 or RET jump to org file %s"
  4714. (abbreviate-file-name buffer-file-name))))
  4715. (d1 (calendar-absolute-from-gregorian date))
  4716. mm
  4717. (deadline-position-alist
  4718. (mapcar (lambda (a) (and (setq mm (get-text-property
  4719. 0 'org-hd-marker a))
  4720. (cons (marker-position mm) a)))
  4721. deadline-results))
  4722. (remove-re org-ts-regexp)
  4723. (regexp
  4724. (concat
  4725. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4726. (regexp-quote
  4727. (substring
  4728. (format-time-string
  4729. (car org-time-stamp-formats)
  4730. (apply 'encode-time ; DATE bound by calendar
  4731. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4732. 1 11))
  4733. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[hdwmy]>\\)"
  4734. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4735. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4736. donep tmp priority category category-pos level ee txt timestr tags
  4737. b0 b3 e3 head todo-state end-of-match show-all warntime)
  4738. (goto-char (point-min))
  4739. (while (setq end-of-match (re-search-forward regexp nil t))
  4740. (setq b0 (match-beginning 0)
  4741. b3 (match-beginning 3) e3 (match-end 3)
  4742. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4743. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4744. (member todo-state
  4745. org-agenda-repeating-timestamp-show-all)))
  4746. (catch :skip
  4747. (and (org-at-date-range-p) (throw :skip nil))
  4748. (org-agenda-skip)
  4749. (if (and (match-end 1)
  4750. (not (= d1 (org-time-string-to-absolute
  4751. (match-string 1) d1 nil show-all
  4752. (current-buffer) b0))))
  4753. (throw :skip nil))
  4754. (if (and e3
  4755. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4756. (throw :skip nil))
  4757. (setq tmp (buffer-substring (max (point-min)
  4758. (- b0 org-ds-keyword-length))
  4759. b0)
  4760. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4761. inactivep (= (char-after b0) ?\[)
  4762. deadlinep (string-match org-deadline-regexp tmp)
  4763. scheduledp (string-match org-scheduled-regexp tmp)
  4764. closedp (and org-agenda-include-inactive-timestamps
  4765. (string-match org-closed-string tmp))
  4766. clockp (and org-agenda-include-inactive-timestamps
  4767. (or (string-match org-clock-string tmp)
  4768. (string-match "]-+\\'" tmp)))
  4769. warntime (org-entry-get (point) "APPT_WARNTIME")
  4770. donep (member todo-state org-done-keywords))
  4771. (if (or scheduledp deadlinep closedp clockp
  4772. (and donep org-agenda-skip-timestamp-if-done))
  4773. (throw :skip t))
  4774. (if (string-match ">" timestr)
  4775. ;; substring should only run to end of time stamp
  4776. (setq timestr (substring timestr 0 (match-end 0))))
  4777. (setq marker (org-agenda-new-marker b0)
  4778. category (org-get-category b0)
  4779. category-pos (get-text-property b0 'org-category-position))
  4780. (save-excursion
  4781. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4782. (setq txt org-agenda-no-heading-message)
  4783. (goto-char (match-beginning 0))
  4784. (if (and (eq t org-agenda-skip-timestamp-if-deadline-is-shown)
  4785. (assoc (point) deadline-position-alist))
  4786. (throw :skip nil))
  4787. (setq hdmarker (org-agenda-new-marker)
  4788. tags (org-get-tags-at)
  4789. level (make-string (org-reduced-level (org-outline-level)) ? ))
  4790. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4791. (setq head (or (match-string 1) ""))
  4792. (setq txt (org-agenda-format-item
  4793. (if inactivep org-agenda-inactive-leader nil)
  4794. head level category tags timestr
  4795. remove-re)))
  4796. (setq priority (org-get-priority txt))
  4797. (org-add-props txt props 'priority priority
  4798. 'org-marker marker 'org-hd-marker hdmarker
  4799. 'org-category category 'date date
  4800. 'level level
  4801. 'org-category-position category-pos
  4802. 'todo-state todo-state
  4803. 'warntime warntime
  4804. 'type "timestamp")
  4805. (push txt ee))
  4806. (if org-agenda-skip-additional-timestamps-same-entry
  4807. (outline-next-heading)
  4808. (goto-char end-of-match))))
  4809. (nreverse ee)))
  4810. (defun org-agenda-get-sexps ()
  4811. "Return the sexp information for agenda display."
  4812. (require 'diary-lib)
  4813. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4814. 'mouse-face 'highlight
  4815. 'help-echo
  4816. (format "mouse-2 or RET jump to org file %s"
  4817. (abbreviate-file-name buffer-file-name))))
  4818. (regexp "^&?%%(")
  4819. marker category extra category-pos level ee txt tags entry
  4820. result beg b sexp sexp-entry todo-state warntime)
  4821. (goto-char (point-min))
  4822. (while (re-search-forward regexp nil t)
  4823. (catch :skip
  4824. (org-agenda-skip)
  4825. (setq beg (match-beginning 0))
  4826. (goto-char (1- (match-end 0)))
  4827. (setq b (point))
  4828. (forward-sexp 1)
  4829. (setq sexp (buffer-substring b (point)))
  4830. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4831. (org-trim (match-string 1))
  4832. ""))
  4833. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4834. (when result
  4835. (setq marker (org-agenda-new-marker beg)
  4836. level (make-string (org-reduced-level (org-outline-level)) ? )
  4837. category (org-get-category beg)
  4838. category-pos (get-text-property beg 'org-category-position)
  4839. tags (save-excursion (org-backward-heading-same-level 0)
  4840. (org-get-tags-at))
  4841. todo-state (org-get-todo-state)
  4842. warntime (org-entry-get (point) "APPT_WARNTIME"))
  4843. (dolist (r (if (stringp result)
  4844. (list result)
  4845. result)) ;; we expect a list here
  4846. (when (and org-agenda-diary-sexp-prefix
  4847. (string-match org-agenda-diary-sexp-prefix r))
  4848. (setq extra (match-string 0 r)
  4849. r (replace-match "" nil nil r)))
  4850. (if (string-match "\\S-" r)
  4851. (setq txt r)
  4852. (setq txt "SEXP entry returned empty string"))
  4853. (setq txt (org-agenda-format-item extra txt level category tags 'time))
  4854. (org-add-props txt props 'org-marker marker
  4855. 'org-category category 'date date 'todo-state todo-state
  4856. 'org-category-position category-pos 'tags tags
  4857. 'level level
  4858. 'type "sexp" 'warntime warntime)
  4859. (push txt ee)))))
  4860. (nreverse ee)))
  4861. ;; Calendar sanity: define some functions that are independent of
  4862. ;; `calendar-date-style'.
  4863. ;; Normally I would like to use ISO format when calling the diary functions,
  4864. ;; but to make sure we still have Emacs 22 compatibility we bind
  4865. ;; also `european-calendar-style' and use european format
  4866. (defun org-anniversary (year month day &optional mark)
  4867. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4868. (org-no-warnings
  4869. (let ((calendar-date-style 'european) (european-calendar-style t))
  4870. (diary-anniversary day month year mark))))
  4871. (defun org-cyclic (N year month day &optional mark)
  4872. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4873. (org-no-warnings
  4874. (let ((calendar-date-style 'european) (european-calendar-style t))
  4875. (diary-cyclic N day month year mark))))
  4876. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4877. "Like `diary-block', but with fixed (ISO) order of arguments."
  4878. (org-no-warnings
  4879. (let ((calendar-date-style 'european) (european-calendar-style t))
  4880. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4881. (defun org-date (year month day &optional mark)
  4882. "Like `diary-date', but with fixed (ISO) order of arguments."
  4883. (org-no-warnings
  4884. (let ((calendar-date-style 'european) (european-calendar-style t))
  4885. (diary-date day month year mark))))
  4886. (defalias 'org-float 'diary-float)
  4887. ;; Define the` org-class' function
  4888. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4889. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4890. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4891. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4892. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4893. `holidays', then any date that is known by the Emacs calendar to be a
  4894. holiday will also be skipped. If SKIP-WEEKS arguments are holiday strings,
  4895. then those holidays will be skipped."
  4896. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4897. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4898. (d (calendar-absolute-from-gregorian date))
  4899. (h (when skip-weeks (calendar-check-holidays date))))
  4900. (and
  4901. (<= date1 d)
  4902. (<= d date2)
  4903. (= (calendar-day-of-week date) dayname)
  4904. (or (not skip-weeks)
  4905. (progn
  4906. (require 'cal-iso)
  4907. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4908. (not (or (and h (memq 'holidays skip-weeks))
  4909. (delq nil (mapcar (lambda(g) (member g skip-weeks)) h))))
  4910. entry)))
  4911. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4912. "Like `org-class', but honor `calendar-date-style'.
  4913. The order of the first 2 times 3 arguments depends on the variable
  4914. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4915. So for American calendars, give this as MONTH DAY YEAR, for European as
  4916. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4917. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4918. is any number of ISO weeks in the block period for which the item should
  4919. be skipped.
  4920. This function is here only for backward compatibility and it is deprecated,
  4921. please use `org-class' instead."
  4922. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4923. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4924. (org-class
  4925. (nth 2 date1) (car date1) (nth 1 date1)
  4926. (nth 2 date2) (car date2) (nth 1 date2)
  4927. dayname skip-weeks)))
  4928. (make-obsolete 'org-diary-class 'org-class "")
  4929. (defvar org-agenda-show-log-scoped) ;; dynamically scope in `org-timeline' or `org-agenda-list'
  4930. (defalias 'org-get-closed 'org-agenda-get-progress)
  4931. (defun org-agenda-get-progress ()
  4932. "Return the logged TODO entries for agenda display."
  4933. (let* ((props (list 'mouse-face 'highlight
  4934. 'org-not-done-regexp org-not-done-regexp
  4935. 'org-todo-regexp org-todo-regexp
  4936. 'org-complex-heading-regexp org-complex-heading-regexp
  4937. 'help-echo
  4938. (format "mouse-2 or RET jump to org file %s"
  4939. (abbreviate-file-name buffer-file-name))))
  4940. (items (if (consp org-agenda-show-log-scoped)
  4941. org-agenda-show-log-scoped
  4942. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4943. '(clock)
  4944. org-agenda-log-mode-items)))
  4945. (parts
  4946. (delq nil
  4947. (list
  4948. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4949. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4950. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4951. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4952. (error "`org-agenda-log-mode-items' is empty")))
  4953. (regexp (concat
  4954. "\\(" parts-re "\\)"
  4955. " *\\["
  4956. (regexp-quote
  4957. (substring
  4958. (format-time-string
  4959. (car org-time-stamp-formats)
  4960. (apply 'encode-time ; DATE bound by calendar
  4961. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4962. 1 11))))
  4963. (org-agenda-search-headline-for-time nil)
  4964. marker hdmarker priority category category-pos level tags closedp
  4965. statep clockp state ee txt extra timestr rest clocked)
  4966. (goto-char (point-min))
  4967. (while (re-search-forward regexp nil t)
  4968. (catch :skip
  4969. (org-agenda-skip)
  4970. (setq marker (org-agenda-new-marker (match-beginning 0))
  4971. closedp (equal (match-string 1) org-closed-string)
  4972. statep (equal (string-to-char (match-string 1)) ?-)
  4973. clockp (not (or closedp statep))
  4974. state (and statep (match-string 2))
  4975. category (org-get-category (match-beginning 0))
  4976. category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4977. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4978. (when (string-match "\\]" timestr)
  4979. ;; substring should only run to end of time stamp
  4980. (setq rest (substring timestr (match-end 0))
  4981. timestr (substring timestr 0 (match-end 0)))
  4982. (if (and (not closedp) (not statep)
  4983. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4984. rest))
  4985. (progn (setq timestr (concat (substring timestr 0 -1)
  4986. "-" (match-string 1 rest) "]"))
  4987. (setq clocked (match-string 2 rest)))
  4988. (setq clocked "-")))
  4989. (save-excursion
  4990. (setq extra
  4991. (cond
  4992. ((not org-agenda-log-mode-add-notes) nil)
  4993. (statep
  4994. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4995. (match-string 1)))
  4996. (clockp
  4997. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4998. (match-string 1)))))
  4999. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5000. (setq txt org-agenda-no-heading-message)
  5001. (goto-char (match-beginning 0))
  5002. (setq hdmarker (org-agenda-new-marker)
  5003. tags (org-get-tags-at)
  5004. level (make-string (org-reduced-level (org-outline-level)) ? ))
  5005. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5006. (setq txt (match-string 1))
  5007. (when extra
  5008. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  5009. (setq txt (concat (substring txt 0 (match-beginning 1))
  5010. " - " extra " " (match-string 2 txt)))
  5011. (setq txt (concat txt " - " extra))))
  5012. (setq txt (org-agenda-format-item
  5013. (cond
  5014. (closedp "Closed: ")
  5015. (statep (concat "State: (" state ")"))
  5016. (t (concat "Clocked: (" clocked ")")))
  5017. txt level category tags timestr)))
  5018. (setq priority 100000)
  5019. (org-add-props txt props
  5020. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  5021. 'priority priority 'org-category category
  5022. 'org-category-position category-pos
  5023. 'level level
  5024. 'type "closed" 'date date
  5025. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  5026. (push txt ee))
  5027. (goto-char (point-at-eol))))
  5028. (nreverse ee)))
  5029. (defun org-agenda-show-clocking-issues ()
  5030. "Add overlays, showing issues with clocking.
  5031. See also the user option `org-agenda-clock-consistency-checks'."
  5032. (interactive)
  5033. (let* ((pl org-agenda-clock-consistency-checks)
  5034. (re (concat "^[ \t]*"
  5035. org-clock-string
  5036. "[ \t]+"
  5037. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  5038. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  5039. (tlstart 0.)
  5040. (tlend 0.)
  5041. (maxtime (org-hh:mm-string-to-minutes
  5042. (or (plist-get pl :max-duration) "24:00")))
  5043. (mintime (org-hh:mm-string-to-minutes
  5044. (or (plist-get pl :min-duration) 0)))
  5045. (maxgap (org-hh:mm-string-to-minutes
  5046. ;; default 30:00 means never complain
  5047. (or (plist-get pl :max-gap) "30:00")))
  5048. (gapok (mapcar 'org-hh:mm-string-to-minutes
  5049. (plist-get pl :gap-ok-around)))
  5050. (def-face (or (plist-get pl :default-face)
  5051. '((:background "DarkRed") (:foreground "white"))))
  5052. issue face m te ts dt ov)
  5053. (goto-char (point-min))
  5054. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  5055. (setq issue nil face def-face)
  5056. (catch 'next
  5057. (setq m (org-get-at-bol 'org-marker)
  5058. te nil ts nil)
  5059. (unless (and m (markerp m))
  5060. (setq issue "No valid clock line") (throw 'next t))
  5061. (org-with-point-at m
  5062. (save-excursion
  5063. (goto-char (point-at-bol))
  5064. (unless (looking-at re)
  5065. (error "No valid Clock line")
  5066. (throw 'next t))
  5067. (unless (match-end 3)
  5068. (setq issue "No end time"
  5069. face (or (plist-get pl :no-end-time-face) face))
  5070. (throw 'next t))
  5071. (setq ts (match-string 1)
  5072. te (match-string 3)
  5073. ts (org-float-time
  5074. (apply 'encode-time (org-parse-time-string ts)))
  5075. te (org-float-time
  5076. (apply 'encode-time (org-parse-time-string te)))
  5077. dt (- te ts))))
  5078. (cond
  5079. ((> dt (* 60 maxtime))
  5080. ;; a very long clocking chunk
  5081. (setq issue (format "Clocking interval is very long: %s"
  5082. (org-minutes-to-hh:mm-string
  5083. (floor (/ (float dt) 60.))))
  5084. face (or (plist-get pl :long-face) face)))
  5085. ((< dt (* 60 mintime))
  5086. ;; a very short clocking chunk
  5087. (setq issue (format "Clocking interval is very short: %s"
  5088. (org-minutes-to-hh:mm-string
  5089. (floor (/ (float dt) 60.))))
  5090. face (or (plist-get pl :short-face) face)))
  5091. ((and (> tlend 0) (< ts tlend))
  5092. ;; Two clock entries are overlapping
  5093. (setq issue (format "Clocking overlap: %d minutes"
  5094. (/ (- tlend ts) 60))
  5095. face (or (plist-get pl :overlap-face) face)))
  5096. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  5097. ;; There is a gap, lets see if we need to report it
  5098. (unless (org-agenda-check-clock-gap tlend ts gapok)
  5099. (setq issue (format "Clocking gap: %d minutes"
  5100. (/ (- ts tlend) 60))
  5101. face (or (plist-get pl :gap-face) face))))
  5102. (t nil)))
  5103. (setq tlend (or te tlend) tlstart (or ts tlstart))
  5104. (when issue
  5105. ;; OK, there was some issue, add an overlay to show the issue
  5106. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  5107. (overlay-put ov 'before-string
  5108. (concat
  5109. (org-add-props
  5110. (format "%-43s" (concat " " issue))
  5111. nil
  5112. 'face face)
  5113. "\n"))
  5114. (overlay-put ov 'evaporate t)))))
  5115. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  5116. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  5117. (catch 'exit
  5118. (unless ok-list
  5119. ;; there are no OK times for gaps...
  5120. (throw 'exit nil))
  5121. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  5122. ;; This is more than 24 hours, so it is OK.
  5123. ;; because we have at least one OK time, that must be in the
  5124. ;; 24 hour interval.
  5125. (throw 'exit t))
  5126. ;; We have a shorter gap.
  5127. ;; Now we have to get the minute of the day when these times are
  5128. (let* ((t1dec (decode-time (seconds-to-time t1)))
  5129. (t2dec (decode-time (seconds-to-time t2)))
  5130. ;; compute the minute on the day
  5131. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  5132. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  5133. (when (< min2 min1)
  5134. ;; if min2 is smaller than min1, this means it is on the next day.
  5135. ;; Wrap it to after midnight.
  5136. (setq min2 (+ min2 1440)))
  5137. ;; Now check if any of the OK times is in the gap
  5138. (mapc (lambda (x)
  5139. ;; Wrap the time to after midnight if necessary
  5140. (if (< x min1) (setq x (+ x 1440)))
  5141. ;; Check if in interval
  5142. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  5143. ok-list)
  5144. ;; Nope, this gap is not OK
  5145. nil)))
  5146. (defun org-agenda-get-deadlines ()
  5147. "Return the deadline information for agenda display."
  5148. (let* ((props (list 'mouse-face 'highlight
  5149. 'org-not-done-regexp org-not-done-regexp
  5150. 'org-todo-regexp org-todo-regexp
  5151. 'org-complex-heading-regexp org-complex-heading-regexp
  5152. 'help-echo
  5153. (format "mouse-2 or RET jump to org file %s"
  5154. (abbreviate-file-name buffer-file-name))))
  5155. (regexp org-deadline-time-regexp)
  5156. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5157. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5158. d2 diff dfrac wdays pos pos1 category category-pos level
  5159. tags suppress-prewarning ee txt head face s todo-state
  5160. show-all upcomingp donep timestr warntime)
  5161. (goto-char (point-min))
  5162. (while (re-search-forward regexp nil t)
  5163. (setq suppress-prewarning nil)
  5164. (catch :skip
  5165. (org-agenda-skip)
  5166. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  5167. (save-match-data
  5168. (string-match org-scheduled-time-regexp
  5169. (buffer-substring (point-at-bol)
  5170. (point-at-eol)))))
  5171. (setq suppress-prewarning
  5172. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  5173. org-agenda-skip-deadline-prewarning-if-scheduled
  5174. 0)))
  5175. (setq s (match-string 1)
  5176. txt nil
  5177. pos (1- (match-beginning 1))
  5178. todo-state (save-match-data (org-get-todo-state))
  5179. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5180. (member todo-state
  5181. org-agenda-repeating-timestamp-show-all))
  5182. d2 (org-time-string-to-absolute
  5183. (match-string 1) d1 'past show-all
  5184. (current-buffer) pos)
  5185. diff (- d2 d1)
  5186. wdays (if suppress-prewarning
  5187. (let ((org-deadline-warning-days suppress-prewarning))
  5188. (org-get-wdays s))
  5189. (org-get-wdays s))
  5190. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  5191. upcomingp (and todayp (> diff 0)))
  5192. ;; When to show a deadline in the calendar:
  5193. ;; If the expiration is within wdays warning time.
  5194. ;; Past-due deadlines are only shown on the current date
  5195. (if (and (or (and (<= diff wdays)
  5196. (and todayp (not org-agenda-only-exact-dates)))
  5197. (= diff 0)))
  5198. (save-excursion
  5199. ;; (setq todo-state (org-get-todo-state))
  5200. (setq donep (member todo-state org-done-keywords))
  5201. (if (and donep
  5202. (or org-agenda-skip-deadline-if-done
  5203. (not (= diff 0))))
  5204. (setq txt nil)
  5205. (setq category (org-get-category)
  5206. warntime (org-entry-get (point) "APPT_WARNTIME")
  5207. category-pos (get-text-property (point) 'org-category-position))
  5208. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5209. (setq txt org-agenda-no-heading-message)
  5210. (goto-char (match-end 0))
  5211. (setq pos1 (match-beginning 0))
  5212. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5213. (setq tags (org-get-tags-at pos1))
  5214. (setq head (buffer-substring-no-properties
  5215. (point)
  5216. (progn (skip-chars-forward "^\r\n")
  5217. (point))))
  5218. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5219. (setq timestr
  5220. (concat (substring s (match-beginning 1)) " "))
  5221. (setq timestr 'time))
  5222. (setq txt (org-agenda-format-item
  5223. (if (= diff 0)
  5224. (car org-agenda-deadline-leaders)
  5225. (if (functionp
  5226. (nth 1 org-agenda-deadline-leaders))
  5227. (funcall
  5228. (nth 1 org-agenda-deadline-leaders)
  5229. diff date)
  5230. (format (nth 1 org-agenda-deadline-leaders)
  5231. diff)))
  5232. head level category tags
  5233. (if (not (= diff 0)) nil timestr)))))
  5234. (when txt
  5235. (setq face (org-agenda-deadline-face dfrac))
  5236. (org-add-props txt props
  5237. 'org-marker (org-agenda-new-marker pos)
  5238. 'warntime warntime
  5239. 'level level
  5240. 'org-hd-marker (org-agenda-new-marker pos1)
  5241. 'priority (+ (- diff)
  5242. (org-get-priority txt))
  5243. 'org-category category
  5244. 'org-category-position category-pos
  5245. 'todo-state todo-state
  5246. 'type (if upcomingp "upcoming-deadline" "deadline")
  5247. 'date (if upcomingp date d2)
  5248. 'face (if donep 'org-agenda-done face)
  5249. 'undone-face face 'done-face 'org-agenda-done)
  5250. (push txt ee))))))
  5251. (nreverse ee)))
  5252. (defun org-agenda-deadline-face (fraction)
  5253. "Return the face to displaying a deadline item.
  5254. FRACTION is what fraction of the head-warning time has passed."
  5255. (let ((faces org-agenda-deadline-faces) f)
  5256. (catch 'exit
  5257. (while (setq f (pop faces))
  5258. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5259. (defun org-agenda-get-scheduled (&optional deadline-results)
  5260. "Return the scheduled information for agenda display."
  5261. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5262. 'org-todo-regexp org-todo-regexp
  5263. 'org-complex-heading-regexp org-complex-heading-regexp
  5264. 'done-face 'org-agenda-done
  5265. 'mouse-face 'highlight
  5266. 'help-echo
  5267. (format "mouse-2 or RET jump to org file %s"
  5268. (abbreviate-file-name buffer-file-name))))
  5269. (regexp org-scheduled-time-regexp)
  5270. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5271. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5272. mm
  5273. (deadline-position-alist
  5274. (mapcar (lambda (a) (and (setq mm (get-text-property
  5275. 0 'org-hd-marker a))
  5276. (cons (marker-position mm) a)))
  5277. deadline-results))
  5278. d2 diff pos pos1 category category-pos level tags donep
  5279. ee txt head pastschedp todo-state face timestr s habitp show-all
  5280. did-habit-check-p warntime)
  5281. (goto-char (point-min))
  5282. (while (re-search-forward regexp nil t)
  5283. (catch :skip
  5284. (org-agenda-skip)
  5285. (setq s (match-string 1)
  5286. txt nil
  5287. pos (1- (match-beginning 1))
  5288. todo-state (save-match-data (org-get-todo-state))
  5289. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5290. (member todo-state
  5291. org-agenda-repeating-timestamp-show-all))
  5292. d2 (org-time-string-to-absolute
  5293. (match-string 1) d1 'past show-all
  5294. (current-buffer) pos)
  5295. diff (- d2 d1)
  5296. warntime (org-entry-get (point) "APPT_WARNTIME"))
  5297. (setq pastschedp (and todayp (< diff 0)))
  5298. (setq did-habit-check-p nil)
  5299. ;; When to show a scheduled item in the calendar:
  5300. ;; If it is on or past the date.
  5301. (when (or (and (< diff 0)
  5302. (< (abs diff) org-scheduled-past-days)
  5303. (and todayp (not org-agenda-only-exact-dates)))
  5304. (= diff 0)
  5305. ;; org-is-habit-p uses org-entry-get, which is expansive
  5306. ;; so we go extra mile to only call it once
  5307. (and todayp
  5308. org-habit-show-all-today
  5309. (setq did-habit-check-p t)
  5310. (setq habitp (and (functionp 'org-is-habit-p)
  5311. (org-is-habit-p)))))
  5312. (save-excursion
  5313. (setq donep (member todo-state org-done-keywords))
  5314. (if (and donep
  5315. (or org-agenda-skip-scheduled-if-done
  5316. (not (= diff 0))
  5317. (and (functionp 'org-is-habit-p)
  5318. (org-is-habit-p))))
  5319. (setq txt nil)
  5320. (setq habitp (if did-habit-check-p habitp
  5321. (and (functionp 'org-is-habit-p)
  5322. (org-is-habit-p))))
  5323. (setq category (org-get-category)
  5324. category-pos (get-text-property (point) 'org-category-position))
  5325. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5326. (setq txt org-agenda-no-heading-message)
  5327. (goto-char (match-end 0))
  5328. (setq pos1 (match-beginning 0))
  5329. (if habitp
  5330. (if (or (not org-habit-show-habits)
  5331. (and (not todayp)
  5332. org-habit-show-habits-only-for-today))
  5333. (throw :skip nil))
  5334. (if (and
  5335. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5336. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5337. pastschedp))
  5338. (setq mm (assoc pos1 deadline-position-alist)))
  5339. (throw :skip nil)))
  5340. (setq tags (org-get-tags-at))
  5341. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5342. (setq head (buffer-substring-no-properties
  5343. (point)
  5344. (progn (skip-chars-forward "^\r\n") (point))))
  5345. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5346. (setq timestr
  5347. (concat (substring s (match-beginning 1)) " "))
  5348. (setq timestr 'time))
  5349. (setq txt (org-agenda-format-item
  5350. (if (= diff 0)
  5351. (car org-agenda-scheduled-leaders)
  5352. (format (nth 1 org-agenda-scheduled-leaders)
  5353. (- 1 diff)))
  5354. head level category tags
  5355. (if (not (= diff 0)) nil timestr)
  5356. nil habitp))))
  5357. (when txt
  5358. (setq face
  5359. (cond
  5360. ((and (not habitp) pastschedp)
  5361. 'org-scheduled-previously)
  5362. (todayp 'org-scheduled-today)
  5363. (t 'org-scheduled))
  5364. habitp (and habitp (org-habit-parse-todo)))
  5365. (org-add-props txt props
  5366. 'undone-face face
  5367. 'face (if donep 'org-agenda-done face)
  5368. 'org-marker (org-agenda-new-marker pos)
  5369. 'org-hd-marker (org-agenda-new-marker pos1)
  5370. 'type (if pastschedp "past-scheduled" "scheduled")
  5371. 'date (if pastschedp d2 date)
  5372. 'warntime warntime
  5373. 'level level
  5374. 'priority (if habitp
  5375. (org-habit-get-priority habitp)
  5376. (+ 94 (- 5 diff) (org-get-priority txt)))
  5377. 'org-category category
  5378. 'category-position category-pos
  5379. 'org-habit-p habitp
  5380. 'todo-state todo-state)
  5381. (push txt ee))))))
  5382. (nreverse ee)))
  5383. (defun org-agenda-get-blocks ()
  5384. "Return the date-range information for agenda display."
  5385. (let* ((props (list 'face nil
  5386. 'org-not-done-regexp org-not-done-regexp
  5387. 'org-todo-regexp org-todo-regexp
  5388. 'org-complex-heading-regexp org-complex-heading-regexp
  5389. 'mouse-face 'highlight
  5390. 'help-echo
  5391. (format "mouse-2 or RET jump to org file %s"
  5392. (abbreviate-file-name buffer-file-name))))
  5393. (regexp org-tr-regexp)
  5394. (d0 (calendar-absolute-from-gregorian date))
  5395. marker hdmarker ee txt d1 d2 s1 s2 category category-pos
  5396. level todo-state tags pos head donep)
  5397. (goto-char (point-min))
  5398. (while (re-search-forward regexp nil t)
  5399. (catch :skip
  5400. (org-agenda-skip)
  5401. (setq pos (point))
  5402. (let ((start-time (match-string 1))
  5403. (end-time (match-string 2)))
  5404. (setq s1 (match-string 1)
  5405. s2 (match-string 2)
  5406. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5407. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5408. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5409. ;; Only allow days between the limits, because the normal
  5410. ;; date stamps will catch the limits.
  5411. (save-excursion
  5412. (setq todo-state (org-get-todo-state))
  5413. (setq donep (member todo-state org-done-keywords))
  5414. (if (and donep org-agenda-skip-timestamp-if-done)
  5415. (throw :skip t))
  5416. (setq marker (org-agenda-new-marker (point)))
  5417. (setq category (org-get-category)
  5418. category-pos (get-text-property (point) 'org-category-position))
  5419. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5420. (setq txt org-agenda-no-heading-message)
  5421. (goto-char (match-beginning 0))
  5422. (setq hdmarker (org-agenda-new-marker (point)))
  5423. (setq tags (org-get-tags-at))
  5424. (setq level (make-string (org-reduced-level (org-outline-level)) ? ))
  5425. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5426. (setq head (match-string 1))
  5427. (let ((remove-re
  5428. (if org-agenda-remove-timeranges-from-blocks
  5429. (concat
  5430. "<" (regexp-quote s1) ".*?>"
  5431. "--"
  5432. "<" (regexp-quote s2) ".*?>")
  5433. nil)))
  5434. (setq txt (org-agenda-format-item
  5435. (format
  5436. (nth (if (= d1 d2) 0 1)
  5437. org-agenda-timerange-leaders)
  5438. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5439. head level category tags
  5440. (cond ((and (= d1 d0) (= d2 d0))
  5441. (concat "<" start-time ">--<" end-time ">"))
  5442. ((= d1 d0)
  5443. (concat "<" start-time ">"))
  5444. ((= d2 d0)
  5445. (concat "<" end-time ">")))
  5446. remove-re))))
  5447. (org-add-props txt props
  5448. 'org-marker marker 'org-hd-marker hdmarker
  5449. 'type "block" 'date date
  5450. 'level level
  5451. 'todo-state todo-state
  5452. 'priority (org-get-priority txt) 'org-category category
  5453. 'org-category-position category-pos)
  5454. (push txt ee))))
  5455. (goto-char pos)))
  5456. ;; Sort the entries by expiration date.
  5457. (nreverse ee)))
  5458. ;;; Agenda presentation and sorting
  5459. (defvar org-prefix-has-time nil
  5460. "A flag, set by `org-compile-prefix-format'.
  5461. The flag is set if the currently compiled format contains a `%t'.")
  5462. (defvar org-prefix-has-tag nil
  5463. "A flag, set by `org-compile-prefix-format'.
  5464. The flag is set if the currently compiled format contains a `%T'.")
  5465. (defvar org-prefix-has-effort nil
  5466. "A flag, set by `org-compile-prefix-format'.
  5467. The flag is set if the currently compiled format contains a `%e'.")
  5468. (defvar org-prefix-category-length nil
  5469. "Used by `org-compile-prefix-format' to remember the category field width.")
  5470. (defvar org-prefix-category-max-length nil
  5471. "Used by `org-compile-prefix-format' to remember the category field width.")
  5472. (defun org-agenda-get-category-icon (category)
  5473. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5474. (dolist (entry org-agenda-category-icon-alist)
  5475. (when (org-string-match-p (car entry) category)
  5476. (if (listp (cadr entry))
  5477. (return (cadr entry))
  5478. (return (apply 'create-image (cdr entry)))))))
  5479. (defun org-agenda-format-item (extra txt &optional level category tags dotime
  5480. remove-re habitp)
  5481. "Format TXT to be inserted into the agenda buffer.
  5482. In particular, add the prefix and corresponding text properties.
  5483. EXTRA must be a string to replace the `%s' specifier in the prefix format.
  5484. LEVEL may be a string to replace the `%l' specifier.
  5485. CATEGORY (a string, a symbol or nil) may be used to overrule the default
  5486. category taken from local variable or file name. It will replace the `%c'
  5487. specifier in the format.
  5488. DOTIME, when non-nil, indicates that a time-of-day should be extracted from
  5489. TXT for sorting of this entry, and for the `%t' specifier in the format.
  5490. When DOTIME is a string, this string is searched for a time before TXT is.
  5491. TAGS can be the tags of the headline.
  5492. Any match of REMOVE-RE will be removed from TXT."
  5493. ;; We keep the org-prefix-* variable values along with a compiled
  5494. ;; formatter, so that multiple agendas existing at the same time do
  5495. ;; not step on each other toes.
  5496. ;;
  5497. ;; It was inconvenient to make these variables buffer local in
  5498. ;; Agenda buffers, because this function expects to be called with
  5499. ;; the buffer where item comes from being current, and not agenda
  5500. ;; buffer
  5501. (let* ((bindings (car org-prefix-format-compiled))
  5502. (formatter (cadr org-prefix-format-compiled)))
  5503. (loop for (var value) in bindings
  5504. do (set var value))
  5505. (save-match-data
  5506. ;; Diary entries sometimes have extra whitespace at the beginning
  5507. (setq txt (org-trim txt))
  5508. ;; Fix the tags part in txt
  5509. (setq txt (org-agenda-fix-displayed-tags
  5510. txt tags
  5511. org-agenda-show-inherited-tags
  5512. org-agenda-hide-tags-regexp))
  5513. (let* ((category (or category
  5514. (if (stringp org-category)
  5515. org-category
  5516. (and org-category (symbol-name org-category)))
  5517. (if buffer-file-name
  5518. (file-name-sans-extension
  5519. (file-name-nondirectory buffer-file-name))
  5520. "")))
  5521. (category-icon (org-agenda-get-category-icon category))
  5522. (category-icon (if category-icon
  5523. (propertize " " 'display category-icon)
  5524. ""))
  5525. ;; time, tag, effort are needed for the eval of the prefix format
  5526. (tag (if tags (nth (1- (length tags)) tags) ""))
  5527. time effort neffort
  5528. (ts (if dotime (concat
  5529. (if (stringp dotime) dotime "")
  5530. (and org-agenda-search-headline-for-time txt))))
  5531. (time-of-day (and dotime (org-get-time-of-day ts)))
  5532. stamp plain s0 s1 s2 rtn srp l
  5533. duration thecategory)
  5534. (and (derived-mode-p 'org-mode) buffer-file-name
  5535. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5536. (when (and dotime time-of-day)
  5537. ;; Extract starting and ending time and move them to prefix
  5538. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5539. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5540. (setq s0 (match-string 0 ts)
  5541. srp (and stamp (match-end 3))
  5542. s1 (match-string (if plain 1 2) ts)
  5543. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5544. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5545. ;; them, we might want to remove them there to avoid duplication.
  5546. ;; The user can turn this off with a variable.
  5547. (if (and org-prefix-has-time
  5548. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5549. (string-match (concat (regexp-quote s0) " *") txt)
  5550. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5551. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5552. (= (match-beginning 0) 0)
  5553. t))
  5554. (setq txt (replace-match "" nil nil txt))))
  5555. ;; Normalize the time(s) to 24 hour
  5556. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5557. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5558. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5559. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5560. (setq s2
  5561. (org-minutes-to-hh:mm-string
  5562. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5563. ;; Compute the duration
  5564. (when s2
  5565. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5566. (org-hh:mm-string-to-minutes s1)))))
  5567. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5568. txt)
  5569. ;; Tags are in the string
  5570. (if (or (eq org-agenda-remove-tags t)
  5571. (and org-agenda-remove-tags
  5572. org-prefix-has-tag))
  5573. (setq txt (replace-match "" t t txt))
  5574. (setq txt (replace-match
  5575. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5576. (match-string 2 txt))
  5577. t t txt))))
  5578. (when (derived-mode-p 'org-mode)
  5579. (setq effort
  5580. (condition-case nil
  5581. (org-get-effort
  5582. (or (get-text-property 0 'org-hd-marker txt)
  5583. (get-text-property 0 'org-marker txt)))
  5584. (error nil)))
  5585. (when effort
  5586. (setq neffort (org-duration-string-to-minutes effort)
  5587. effort (setq effort (concat "[" effort "]")))))
  5588. ;; prevent erroring out with %e format when there is no effort
  5589. (or effort (setq effort ""))
  5590. (when remove-re
  5591. (while (string-match remove-re txt)
  5592. (setq txt (replace-match "" t t txt))))
  5593. ;; Set org-heading property on `txt' to mark the start of the
  5594. ;; heading.
  5595. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5596. ;; Prepare the variables needed in the eval of the compiled format
  5597. (setq time (cond (s2 (concat
  5598. (org-agenda-time-of-day-to-ampm-maybe s1)
  5599. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5600. (if org-agenda-timegrid-use-ampm " ")))
  5601. (s1 (concat
  5602. (org-agenda-time-of-day-to-ampm-maybe s1)
  5603. (if org-agenda-timegrid-use-ampm
  5604. "........ "
  5605. "......")))
  5606. (t ""))
  5607. extra (or (and (not habitp) extra) "")
  5608. category (if (symbolp category) (symbol-name category) category)
  5609. thecategory (copy-sequence category))
  5610. (if (string-match org-bracket-link-regexp category)
  5611. (progn
  5612. (setq l (if (match-end 3)
  5613. (- (match-end 3) (match-beginning 3))
  5614. (- (match-end 1) (match-beginning 1))))
  5615. (when (< l (or org-prefix-category-length 0))
  5616. (setq category (copy-sequence category))
  5617. (org-add-props category nil
  5618. 'extra-space (make-string
  5619. (- org-prefix-category-length l 1) ?\ ))))
  5620. (if (and org-prefix-category-max-length
  5621. (>= (length category) org-prefix-category-max-length))
  5622. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5623. ;; Evaluate the compiled format
  5624. (setq rtn (concat (eval formatter) txt))
  5625. ;; And finally add the text properties
  5626. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5627. (org-add-props rtn nil
  5628. 'org-category (if thecategory (downcase thecategory) category)
  5629. 'tags (mapcar 'org-downcase-keep-props tags)
  5630. 'org-highest-priority org-highest-priority
  5631. 'org-lowest-priority org-lowest-priority
  5632. 'time-of-day time-of-day
  5633. 'duration duration
  5634. 'effort effort
  5635. 'effort-minutes neffort
  5636. 'txt txt
  5637. 'time time
  5638. 'extra extra
  5639. 'format org-prefix-format-compiled
  5640. 'dotime dotime)))))
  5641. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5642. "Remove tags string from TXT, and add a modified list of tags.
  5643. The modified list may contain inherited tags, and tags matched by
  5644. `org-agenda-hide-tags-regexp' will be removed."
  5645. (when (or add-inherited hide-re)
  5646. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5647. (setq txt (substring txt 0 (match-beginning 0))))
  5648. (setq tags
  5649. (delq nil
  5650. (mapcar (lambda (tg)
  5651. (if (or (and hide-re (string-match hide-re tg))
  5652. (and (not add-inherited)
  5653. (get-text-property 0 'inherited tg)))
  5654. nil
  5655. tg))
  5656. tags)))
  5657. (when tags
  5658. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5659. i)
  5660. (setq txt (concat txt " :"
  5661. (mapconcat
  5662. (lambda (x)
  5663. (setq i (get-text-property 0 'inherited x))
  5664. (if (and have-i (not i))
  5665. (progn
  5666. (setq have-i nil)
  5667. (concat ":" x))
  5668. x))
  5669. tags ":")
  5670. (if have-i "::" ":"))))))
  5671. txt)
  5672. (defun org-downcase-keep-props (s)
  5673. (let ((props (text-properties-at 0 s)))
  5674. (setq s (downcase s))
  5675. (add-text-properties 0 (length s) props s)
  5676. s))
  5677. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5678. (defvar org-agenda-sorting-strategy-selected nil)
  5679. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5680. (catch 'exit
  5681. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5682. ((and todayp (member 'today (car org-agenda-time-grid))))
  5683. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5684. ((member 'weekly (car org-agenda-time-grid)))
  5685. (t (throw 'exit list)))
  5686. (let* ((have (delq nil (mapcar
  5687. (lambda (x) (get-text-property 1 'time-of-day x))
  5688. list)))
  5689. (string (nth 1 org-agenda-time-grid))
  5690. (gridtimes (nth 2 org-agenda-time-grid))
  5691. (req (car org-agenda-time-grid))
  5692. (remove (member 'remove-match req))
  5693. new time)
  5694. (if (and (member 'require-timed req) (not have))
  5695. ;; don't show empty grid
  5696. (throw 'exit list))
  5697. (while (setq time (pop gridtimes))
  5698. (unless (and remove (member time have))
  5699. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5700. (push (org-agenda-format-item
  5701. nil string "" nil
  5702. (concat (substring time 0 -2) ":" (substring time -2)))
  5703. new)
  5704. (put-text-property
  5705. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5706. (when (and todayp org-agenda-show-current-time-in-grid)
  5707. (push (org-agenda-format-item
  5708. nil
  5709. org-agenda-current-time-string
  5710. "" nil
  5711. (format-time-string "%H:%M "))
  5712. new)
  5713. (put-text-property
  5714. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5715. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5716. (append new list)
  5717. (append list new)))))
  5718. (defun org-compile-prefix-format (key)
  5719. "Compile the prefix format into a Lisp form that can be evaluated.
  5720. The resulting form and associated variable bindings is returned
  5721. and stored in the variable `org-prefix-format-compiled'."
  5722. (setq org-prefix-has-time nil
  5723. org-prefix-has-tag nil
  5724. org-prefix-category-length nil
  5725. org-prefix-has-effort nil)
  5726. (let ((s (cond
  5727. ((stringp org-agenda-prefix-format)
  5728. org-agenda-prefix-format)
  5729. ((assq key org-agenda-prefix-format)
  5730. (cdr (assq key org-agenda-prefix-format)))
  5731. (t " %-12:c%?-12t% s")))
  5732. (start 0)
  5733. varform vars var e c f opt)
  5734. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([cltsei]\\|(.+)\\)"
  5735. s start)
  5736. (setq var (or (cdr (assoc (match-string 4 s)
  5737. '(("c" . category) ("t" . time) ("l" . level) ("s" . extra)
  5738. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5739. 'eval)
  5740. c (or (match-string 3 s) "")
  5741. opt (match-beginning 1)
  5742. start (1+ (match-beginning 0)))
  5743. (if (equal var 'time) (setq org-prefix-has-time t))
  5744. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5745. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5746. (setq f (concat "%" (match-string 2 s) "s"))
  5747. (when (equal var 'category)
  5748. (setq org-prefix-category-length
  5749. (floor (abs (string-to-number (match-string 2 s)))))
  5750. (setq org-prefix-category-max-length
  5751. (let ((x (match-string 2 s)))
  5752. (save-match-data
  5753. (if (string-match "\\.[0-9]+" x)
  5754. (string-to-number (substring (match-string 0 x) 1)))))))
  5755. (if (eq var 'eval)
  5756. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5757. (if opt
  5758. (setq varform
  5759. `(if (equal "" ,var)
  5760. ""
  5761. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5762. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5763. (setq s (replace-match "%s" t nil s))
  5764. (push varform vars))
  5765. (setq vars (nreverse vars))
  5766. (with-current-buffer (or org-agenda-buffer (current-buffer))
  5767. (setq org-prefix-format-compiled
  5768. (list
  5769. `((org-prefix-has-time ,org-prefix-has-time)
  5770. (org-prefix-has-tag ,org-prefix-has-tag)
  5771. (org-prefix-category-length ,org-prefix-category-length)
  5772. (org-prefix-has-effort ,org-prefix-has-effort))
  5773. `(format ,s ,@vars))))))
  5774. (defun org-set-sorting-strategy (key)
  5775. (if (symbolp (car org-agenda-sorting-strategy))
  5776. ;; the old format
  5777. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5778. (setq org-agenda-sorting-strategy-selected
  5779. (or (cdr (assq key org-agenda-sorting-strategy))
  5780. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5781. '(time-up category-keep priority-down)))))
  5782. (defun org-get-time-of-day (s &optional string mod24)
  5783. "Check string S for a time of day.
  5784. If found, return it as a military time number between 0 and 2400.
  5785. If not found, return nil.
  5786. The optional STRING argument forces conversion into a 5 character wide string
  5787. HH:MM."
  5788. (save-match-data
  5789. (when
  5790. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5791. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5792. (let* ((h (string-to-number (match-string 1 s)))
  5793. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5794. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5795. (am-p (equal ampm "am"))
  5796. (h1 (cond ((not ampm) h)
  5797. ((= h 12) (if am-p 0 12))
  5798. (t (+ h (if am-p 0 12)))))
  5799. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5800. (mod h1 24) h1))
  5801. (t0 (+ (* 100 h2) m))
  5802. (t1 (concat (if (>= h1 24) "+" " ")
  5803. (if (and org-agenda-time-leading-zero
  5804. (< t0 1000)) "0" "")
  5805. (if (< t0 100) "0" "")
  5806. (if (< t0 10) "0" "")
  5807. (int-to-string t0))))
  5808. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5809. (defvar org-agenda-before-sorting-filter-function nil
  5810. "Function to be applied to agenda items prior to sorting.
  5811. Prior to sorting also means just before they are inserted into the agenda.
  5812. To aid sorting, you may revisit the original entries and add more text
  5813. properties which will later be used by the sorting functions.
  5814. The function should take a string argument, an agenda line.
  5815. It has access to the text properties in that line, which contain among
  5816. other things, the property `org-hd-marker' that points to the entry
  5817. where the line comes from. Note that not all lines going into the agenda
  5818. have this property, only most.
  5819. The function should return the modified string. It is probably best
  5820. to ONLY change text properties.
  5821. You can also use this function as a filter, by returning nil for lines
  5822. you don't want to have in the agenda at all. For this application, you
  5823. could bind the variable in the options section of a custom command.")
  5824. (defun org-agenda-finalize-entries (list &optional nosort)
  5825. "Sort and concatenate the agenda items."
  5826. (setq list (mapcar 'org-agenda-highlight-todo list))
  5827. (if nosort
  5828. list
  5829. (when org-agenda-before-sorting-filter-function
  5830. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5831. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5832. (defun org-agenda-highlight-todo (x)
  5833. (let ((org-done-keywords org-done-keywords-for-agenda)
  5834. (case-fold-search nil)
  5835. re)
  5836. (if (eq x 'line)
  5837. (save-excursion
  5838. (beginning-of-line 1)
  5839. (setq re (org-get-at-bol 'org-todo-regexp))
  5840. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5841. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5842. (add-text-properties (match-beginning 0) (match-end 1)
  5843. (list 'face (org-get-todo-face 1)))
  5844. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5845. (delete-region (match-beginning 1) (1- (match-end 0)))
  5846. (goto-char (match-beginning 1))
  5847. (insert (format org-agenda-todo-keyword-format s)))))
  5848. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5849. (setq re (get-text-property 0 'org-todo-regexp x))
  5850. (when (and re
  5851. ;; Test `pl' because if there's no heading content,
  5852. ;; there's no point matching to highlight. Note
  5853. ;; that if we didn't test `pl' first, and there
  5854. ;; happened to be no keyword from `org-todo-regexp'
  5855. ;; on this heading line, then the `equal' comparison
  5856. ;; afterwards would spuriously succeed in the case
  5857. ;; where `pl' is nil -- causing an args-out-of-range
  5858. ;; error when we try to add text properties to text
  5859. ;; that isn't there.
  5860. pl
  5861. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5862. x pl) pl))
  5863. (add-text-properties
  5864. (or (match-end 1) (match-end 0)) (match-end 0)
  5865. (list 'face (org-get-todo-face (match-string 2 x)))
  5866. x)
  5867. (when (match-end 1)
  5868. (setq x (concat (substring x 0 (match-end 1))
  5869. (format org-agenda-todo-keyword-format
  5870. (match-string 2 x))
  5871. (org-add-props " " (text-properties-at 0 x))
  5872. (substring x (match-end 3)))))))
  5873. x)))
  5874. (defsubst org-cmp-priority (a b)
  5875. "Compare the priorities of string A and B."
  5876. (let ((pa (or (get-text-property 1 'priority a) 0))
  5877. (pb (or (get-text-property 1 'priority b) 0)))
  5878. (cond ((> pa pb) +1)
  5879. ((< pa pb) -1))))
  5880. (defsubst org-cmp-effort (a b)
  5881. "Compare the effort values of string A and B."
  5882. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5883. (ea (or (get-text-property 1 'effort-minutes a) def))
  5884. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5885. (cond ((> ea eb) +1)
  5886. ((< ea eb) -1))))
  5887. (defsubst org-cmp-category (a b)
  5888. "Compare the string values of categories of strings A and B."
  5889. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5890. (cb (or (get-text-property 1 'org-category b) "")))
  5891. (cond ((string-lessp ca cb) -1)
  5892. ((string-lessp cb ca) +1))))
  5893. (defsubst org-cmp-todo-state (a b)
  5894. "Compare the todo states of strings A and B."
  5895. (let* ((ma (or (get-text-property 1 'org-marker a)
  5896. (get-text-property 1 'org-hd-marker a)))
  5897. (mb (or (get-text-property 1 'org-marker b)
  5898. (get-text-property 1 'org-hd-marker b)))
  5899. (fa (and ma (marker-buffer ma)))
  5900. (fb (and mb (marker-buffer mb)))
  5901. (todo-kwds
  5902. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5903. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5904. (ta (or (get-text-property 1 'todo-state a) ""))
  5905. (tb (or (get-text-property 1 'todo-state b) ""))
  5906. (la (- (length (member ta todo-kwds))))
  5907. (lb (- (length (member tb todo-kwds))))
  5908. (donepa (member ta org-done-keywords-for-agenda))
  5909. (donepb (member tb org-done-keywords-for-agenda)))
  5910. (cond ((and donepa (not donepb)) -1)
  5911. ((and (not donepa) donepb) +1)
  5912. ((< la lb) -1)
  5913. ((< lb la) +1))))
  5914. (defsubst org-cmp-alpha (a b)
  5915. "Compare the headlines, alphabetically."
  5916. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5917. (plb (text-property-any 0 (length b) 'org-heading t b))
  5918. (ta (and pla (substring a pla)))
  5919. (tb (and plb (substring b plb))))
  5920. (when pla
  5921. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5922. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5923. (setq ta (substring ta (match-end 0))))
  5924. (setq ta (downcase ta)))
  5925. (when plb
  5926. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5927. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5928. (setq tb (substring tb (match-end 0))))
  5929. (setq tb (downcase tb)))
  5930. (cond ((not ta) +1)
  5931. ((not tb) -1)
  5932. ((string-lessp ta tb) -1)
  5933. ((string-lessp tb ta) +1))))
  5934. (defsubst org-cmp-tag (a b)
  5935. "Compare the string values of the first tags of A and B."
  5936. (let ((ta (car (last (get-text-property 1 'tags a))))
  5937. (tb (car (last (get-text-property 1 'tags b)))))
  5938. (cond ((not ta) +1)
  5939. ((not tb) -1)
  5940. ((string-lessp ta tb) -1)
  5941. ((string-lessp tb ta) +1))))
  5942. (defsubst org-cmp-time (a b)
  5943. "Compare the time-of-day values of strings A and B."
  5944. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5945. (ta (or (get-text-property 1 'time-of-day a) def))
  5946. (tb (or (get-text-property 1 'time-of-day b) def)))
  5947. (cond ((< ta tb) -1)
  5948. ((< tb ta) +1))))
  5949. (defsubst org-cmp-habit-p (a b)
  5950. "Compare the todo states of strings A and B."
  5951. (let ((ha (get-text-property 1 'org-habit-p a))
  5952. (hb (get-text-property 1 'org-habit-p b)))
  5953. (cond ((and ha (not hb)) -1)
  5954. ((and (not ha) hb) +1))))
  5955. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5956. (defun org-entries-lessp (a b)
  5957. "Predicate for sorting agenda entries."
  5958. ;; The following variables will be used when the form is evaluated.
  5959. ;; So even though the compiler complains, keep them.
  5960. (let* ((ss org-agenda-sorting-strategy-selected)
  5961. (time-up (and (org-em 'time-up 'time-down ss)
  5962. (org-cmp-time a b)))
  5963. (time-down (if time-up (- time-up) nil))
  5964. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5965. (org-cmp-priority a b)))
  5966. (priority-down (if priority-up (- priority-up) nil))
  5967. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5968. (org-cmp-effort a b)))
  5969. (effort-down (if effort-up (- effort-up) nil))
  5970. (category-up (and (or (org-em 'category-up 'category-down ss)
  5971. (memq 'category-keep ss))
  5972. (org-cmp-category a b)))
  5973. (category-down (if category-up (- category-up) nil))
  5974. (category-keep (if category-up +1 nil))
  5975. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5976. (org-cmp-tag a b)))
  5977. (tag-down (if tag-up (- tag-up) nil))
  5978. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5979. (org-cmp-todo-state a b)))
  5980. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5981. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5982. (org-cmp-habit-p a b)))
  5983. (habit-down (if habit-up (- habit-up) nil))
  5984. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5985. (org-cmp-alpha a b)))
  5986. (alpha-down (if alpha-up (- alpha-up) nil))
  5987. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5988. user-defined-up user-defined-down)
  5989. (if (and need-user-cmp org-agenda-cmp-user-defined
  5990. (functionp org-agenda-cmp-user-defined))
  5991. (setq user-defined-up
  5992. (funcall org-agenda-cmp-user-defined a b)
  5993. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5994. (cdr (assoc
  5995. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5996. '((-1 . t) (1 . nil) (nil . nil))))))
  5997. ;;; Agenda restriction lock
  5998. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5999. "Overlay to mark the headline to which agenda commands are restricted.")
  6000. (overlay-put org-agenda-restriction-lock-overlay
  6001. 'face 'org-agenda-restriction-lock)
  6002. (overlay-put org-agenda-restriction-lock-overlay
  6003. 'help-echo "Agendas are currently limited to this subtree.")
  6004. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6005. (defun org-agenda-set-restriction-lock (&optional type)
  6006. "Set restriction lock for agenda, to current subtree or file.
  6007. Restriction will be the file if TYPE is `file', or if type is the
  6008. universal prefix '(4), or if the cursor is before the first headline
  6009. in the file. Otherwise, restriction will be to the current subtree."
  6010. (interactive "P")
  6011. (and (equal type '(4)) (setq type 'file))
  6012. (setq type (cond
  6013. (type type)
  6014. ((org-at-heading-p) 'subtree)
  6015. ((condition-case nil (org-back-to-heading t) (error nil))
  6016. 'subtree)
  6017. (t 'file)))
  6018. (if (eq type 'subtree)
  6019. (progn
  6020. (setq org-agenda-restrict t)
  6021. (setq org-agenda-overriding-restriction 'subtree)
  6022. (put 'org-agenda-files 'org-restrict
  6023. (list (buffer-file-name (buffer-base-buffer))))
  6024. (org-back-to-heading t)
  6025. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  6026. (move-marker org-agenda-restrict-begin (point))
  6027. (move-marker org-agenda-restrict-end
  6028. (save-excursion (org-end-of-subtree t)))
  6029. (message "Locking agenda restriction to subtree"))
  6030. (put 'org-agenda-files 'org-restrict
  6031. (list (buffer-file-name (buffer-base-buffer))))
  6032. (setq org-agenda-restrict nil)
  6033. (setq org-agenda-overriding-restriction 'file)
  6034. (move-marker org-agenda-restrict-begin nil)
  6035. (move-marker org-agenda-restrict-end nil)
  6036. (message "Locking agenda restriction to file"))
  6037. (setq current-prefix-arg nil)
  6038. (org-agenda-maybe-redo))
  6039. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  6040. "Remove the agenda restriction lock."
  6041. (interactive "P")
  6042. (org-detach-overlay org-agenda-restriction-lock-overlay)
  6043. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  6044. (setq org-agenda-overriding-restriction nil)
  6045. (setq org-agenda-restrict nil)
  6046. (put 'org-agenda-files 'org-restrict nil)
  6047. (move-marker org-agenda-restrict-begin nil)
  6048. (move-marker org-agenda-restrict-end nil)
  6049. (setq current-prefix-arg nil)
  6050. (message "Agenda restriction lock removed")
  6051. (or noupdate (org-agenda-maybe-redo)))
  6052. (defun org-agenda-maybe-redo ()
  6053. "If there is any window showing the agenda view, update it."
  6054. (let ((w (get-buffer-window org-agenda-buffer-name t))
  6055. (w0 (selected-window)))
  6056. (when w
  6057. (select-window w)
  6058. (org-agenda-redo)
  6059. (select-window w0)
  6060. (if org-agenda-overriding-restriction
  6061. (message "Agenda view shifted to new %s restriction"
  6062. org-agenda-overriding-restriction)
  6063. (message "Agenda restriction lock removed")))))
  6064. ;;; Agenda commands
  6065. (defun org-agenda-check-type (error &rest types)
  6066. "Check if agenda buffer is of allowed type.
  6067. If ERROR is non-nil, throw an error, otherwise just return nil."
  6068. (if (not org-agenda-type)
  6069. (error "No Org agenda currently displayed")
  6070. (if (memq org-agenda-type types)
  6071. t
  6072. (if error
  6073. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  6074. nil))))
  6075. (defun org-agenda-Quit (&optional arg)
  6076. "Exit agenda by removing the window or the buffer."
  6077. (interactive)
  6078. (if org-agenda-columns-active
  6079. (org-columns-quit)
  6080. (let ((buf (current-buffer)))
  6081. (if (eq org-agenda-window-setup 'other-frame)
  6082. (progn
  6083. (org-agenda-reset-markers)
  6084. (kill-buffer buf)
  6085. (org-columns-remove-overlays)
  6086. (setq org-agenda-archives-mode nil)
  6087. (delete-frame))
  6088. (and (not (eq org-agenda-window-setup 'current-window))
  6089. (not (one-window-p))
  6090. (delete-window))
  6091. (org-agenda-reset-markers)
  6092. (kill-buffer buf)
  6093. (org-columns-remove-overlays)
  6094. (setq org-agenda-archives-mode nil)))
  6095. ;; Maybe restore the pre-agenda window configuration.
  6096. (and org-agenda-restore-windows-after-quit
  6097. (not (eq org-agenda-window-setup 'other-frame))
  6098. org-agenda-pre-window-conf
  6099. (set-window-configuration org-agenda-pre-window-conf)
  6100. (setq org-agenda-pre-window-conf nil))))
  6101. (defun org-agenda-quit ()
  6102. "Exit agenda by killing agenda buffer or burying it when
  6103. `org-agenda-sticky' is non-NIL"
  6104. (interactive)
  6105. (if org-agenda-columns-active
  6106. (org-columns-quit)
  6107. (if org-agenda-sticky
  6108. (let ((buf (current-buffer)))
  6109. (if (eq org-agenda-window-setup 'other-frame)
  6110. (progn
  6111. (delete-frame))
  6112. (and (not (eq org-agenda-window-setup 'current-window))
  6113. (not (one-window-p))
  6114. (delete-window)))
  6115. (with-current-buffer buf
  6116. (bury-buffer)
  6117. ;; Maybe restore the pre-agenda window configuration.
  6118. (and org-agenda-restore-windows-after-quit
  6119. (not (eq org-agenda-window-setup 'other-frame))
  6120. org-agenda-pre-window-conf
  6121. (set-window-configuration org-agenda-pre-window-conf)
  6122. (setq org-agenda-pre-window-conf nil))))
  6123. (org-agenda-Quit))))
  6124. (defun org-agenda-exit ()
  6125. "Exit agenda by removing the window or the buffer.
  6126. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  6127. Org-mode buffers visited directly by the user will not be touched."
  6128. (interactive)
  6129. (org-release-buffers org-agenda-new-buffers)
  6130. (setq org-agenda-new-buffers nil)
  6131. (org-agenda-Quit))
  6132. (defun org-agenda-kill-all-agenda-buffers ()
  6133. "Kill all buffers in `org-agena-mode'.
  6134. This is used when toggling sticky agendas. You can also explicitly invoke it
  6135. with `C-c a C-k'."
  6136. (interactive)
  6137. (let (blist)
  6138. (dolist (buf (buffer-list))
  6139. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  6140. (push buf blist)))
  6141. (mapc 'kill-buffer blist)))
  6142. (defun org-agenda-execute (arg)
  6143. "Execute another agenda command, keeping same window.
  6144. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  6145. in the agenda."
  6146. (interactive "P")
  6147. (let ((org-agenda-window-setup 'current-window))
  6148. (org-agenda arg)))
  6149. (defun org-agenda-redo (&optional all)
  6150. "Rebuild possibly ALL agenda view(s) in the current buffer."
  6151. (interactive "P")
  6152. (let* ((p (or (and (looking-at "\\'") (1- (point))) (point)))
  6153. (cpa (unless (eq all t) current-prefix-arg))
  6154. (org-agenda-doing-sticky-redo org-agenda-sticky)
  6155. (org-agenda-sticky nil)
  6156. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  6157. org-agenda-buffer-name))
  6158. (org-agenda-keep-modes t)
  6159. (tag-filter org-agenda-tag-filter)
  6160. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  6161. (top-cat-filter org-agenda-top-category-filter)
  6162. (cat-filter org-agenda-category-filter)
  6163. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  6164. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  6165. (cols org-agenda-columns-active)
  6166. (line (org-current-line))
  6167. (window-line (- line (org-current-line (window-start))))
  6168. (lprops (get 'org-agenda-redo-command 'org-lprops))
  6169. (redo-cmd (get-text-property p 'org-redo-cmd))
  6170. (last-args (get-text-property p 'org-last-args))
  6171. (org-agenda-overriding-cmd (get-text-property p 'org-serie-cmd))
  6172. (org-agenda-overriding-cmd-arguments
  6173. (unless (eq all t)
  6174. (cond ((listp last-args)
  6175. (cons (or cpa (car last-args)) (cdr last-args)))
  6176. ((stringp last-args)
  6177. last-args))))
  6178. (serie-redo-cmd (get-text-property p 'org-serie-redo-cmd)))
  6179. (put 'org-agenda-tag-filter :preset-filter nil)
  6180. (put 'org-agenda-category-filter :preset-filter nil)
  6181. (and cols (org-columns-quit))
  6182. (message "Rebuilding agenda buffer...")
  6183. (if serie-redo-cmd
  6184. (eval serie-redo-cmd)
  6185. (org-let lprops '(eval redo-cmd)))
  6186. (setq org-agenda-undo-list nil
  6187. org-agenda-pending-undo-list nil)
  6188. (message "Rebuilding agenda buffer...done")
  6189. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  6190. (put 'org-agenda-category-filter :preset-filter cat-preset)
  6191. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  6192. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  6193. (and top-cat-filter (org-agenda-filter-top-category-apply top-cat-filter))
  6194. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  6195. (org-goto-line line)
  6196. (recenter window-line)))
  6197. (defvar org-global-tags-completion-table nil)
  6198. (defvar org-agenda-filter-form nil)
  6199. (defvar org-agenda-filtered-by-category nil)
  6200. (defun org-agenda-filter-by-category (strip)
  6201. "Keep only those lines in the agenda buffer that have a specific category.
  6202. The category is that of the current line."
  6203. (interactive "P")
  6204. (if (and org-agenda-filtered-by-category
  6205. org-agenda-category-filter)
  6206. (org-agenda-filter-show-all-cat)
  6207. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  6208. (if cat (org-agenda-filter-apply
  6209. (list (concat (if strip "-" "+") cat)) 'category)
  6210. (error "No category at point")))))
  6211. (defun org-find-top-category (&optional pos)
  6212. (save-excursion
  6213. (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
  6214. (if pos (goto-char pos))
  6215. ;; Skip up to the topmost parent
  6216. (while (ignore-errors (outline-up-heading 1) t))
  6217. (ignore-errors
  6218. (nth 4 (org-heading-components))))))
  6219. (defvar org-agenda-filtered-by-top-category nil)
  6220. (defun org-agenda-filter-by-top-category (strip)
  6221. "Keep only those lines in the agenda buffer that have a specific category.
  6222. The category is that of the current line."
  6223. (interactive "P")
  6224. (if org-agenda-filtered-by-top-category
  6225. (progn
  6226. (setq org-agenda-filtered-by-top-category nil
  6227. org-agenda-top-category-filter nil)
  6228. (org-agenda-filter-show-all-cat))
  6229. (let ((cat (org-find-top-category (org-get-at-bol 'org-hd-marker))))
  6230. (if cat (org-agenda-filter-top-category-apply cat strip)
  6231. (error "No top-level category at point")))))
  6232. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  6233. "Keep only those lines in the agenda buffer that have a specific tag.
  6234. The tag is selected with its fast selection letter, as configured.
  6235. With prefix argument STRIP, remove all lines that do have the tag.
  6236. A lisp caller can specify CHAR. NARROW means that the new tag should be
  6237. used to narrow the search - the interactive user can also press `-' or `+'
  6238. to switch to narrowing."
  6239. (interactive "P")
  6240. (let* ((alist org-tag-alist-for-agenda)
  6241. (tag-chars (mapconcat
  6242. (lambda (x) (if (and (not (symbolp (car x)))
  6243. (cdr x))
  6244. (char-to-string (cdr x))
  6245. ""))
  6246. alist ""))
  6247. (efforts (org-split-string
  6248. (or (cdr (assoc (concat org-effort-property "_ALL")
  6249. org-global-properties))
  6250. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  6251. "")))
  6252. (effort-op org-agenda-filter-effort-default-operator)
  6253. (effort-prompt "")
  6254. (inhibit-read-only t)
  6255. (current org-agenda-tag-filter)
  6256. maybe-refresh a n tag)
  6257. (unless char
  6258. (message
  6259. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  6260. (if narrow "Narrow" "Filter") tag-chars
  6261. (if org-agenda-auto-exclude-function "[RET], " ""))
  6262. (setq char (read-char-exclusive)))
  6263. (when (member char '(?+ ?-))
  6264. ;; Narrowing down
  6265. (cond ((equal char ?-) (setq strip t narrow t))
  6266. ((equal char ?+) (setq strip nil narrow t)))
  6267. (message
  6268. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6269. (setq char (read-char-exclusive)))
  6270. (when (member char '(?< ?> ?= ??))
  6271. ;; An effort operator
  6272. (setq effort-op (char-to-string char))
  6273. (setq alist nil) ; to make sure it will be interpreted as effort.
  6274. (unless (equal char ??)
  6275. (loop for i from 0 to 9 do
  6276. (setq effort-prompt
  6277. (concat
  6278. effort-prompt " ["
  6279. (if (= i 9) "0" (int-to-string (1+ i)))
  6280. "]" (nth i efforts))))
  6281. (message "Effort%s: %s " effort-op effort-prompt)
  6282. (setq char (read-char-exclusive))
  6283. (when (or (< char ?0) (> char ?9))
  6284. (error "Need 1-9,0 to select effort"))))
  6285. (when (equal char ?\t)
  6286. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6287. (org-set-local 'org-global-tags-completion-table
  6288. (org-global-tags-completion-table)))
  6289. (let ((completion-ignore-case t))
  6290. (setq tag (org-icompleting-read
  6291. "Tag: " org-global-tags-completion-table))))
  6292. (cond
  6293. ((equal char ?\r)
  6294. (org-agenda-filter-show-all-tag)
  6295. (when org-agenda-auto-exclude-function
  6296. (setq org-agenda-tag-filter '())
  6297. (dolist (tag (org-agenda-get-represented-tags))
  6298. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6299. (if modifier
  6300. (push modifier org-agenda-tag-filter))))
  6301. (if (not (null org-agenda-tag-filter))
  6302. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6303. (setq maybe-refresh t))
  6304. ((equal char ?/)
  6305. (org-agenda-filter-show-all-tag)
  6306. (when (get 'org-agenda-tag-filter :preset-filter)
  6307. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6308. (setq maybe-refresh t))
  6309. ((equal char ?. )
  6310. (setq org-agenda-tag-filter
  6311. (mapcar (lambda(tag) (concat "+" tag))
  6312. (org-get-at-bol 'tags)))
  6313. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6314. (setq maybe-refresh t))
  6315. ((or (equal char ?\ )
  6316. (setq a (rassoc char alist))
  6317. (and (>= char ?0) (<= char ?9)
  6318. (setq n (if (= char ?0) 9 (- char ?0 1))
  6319. tag (concat effort-op (nth n efforts))
  6320. a (cons tag nil)))
  6321. (and (= char ??)
  6322. (setq tag "?eff")
  6323. a (cons tag nil))
  6324. (and tag (setq a (cons tag nil))))
  6325. (org-agenda-filter-show-all-tag)
  6326. (setq tag (car a))
  6327. (setq org-agenda-tag-filter
  6328. (cons (concat (if strip "-" "+") tag)
  6329. (if narrow current nil)))
  6330. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6331. (setq maybe-refresh t))
  6332. (t (error "Invalid tag selection character %c" char)))
  6333. (when (and maybe-refresh
  6334. (eq org-agenda-clockreport-mode 'with-filter))
  6335. (org-agenda-redo))))
  6336. (defun org-agenda-get-represented-tags ()
  6337. "Get a list of all tags currently represented in the agenda."
  6338. (let (p tags)
  6339. (save-excursion
  6340. (goto-char (point-min))
  6341. (while (setq p (next-single-property-change (point) 'tags))
  6342. (goto-char p)
  6343. (mapc (lambda (x) (add-to-list 'tags x))
  6344. (get-text-property (point) 'tags))))
  6345. tags))
  6346. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6347. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6348. (interactive "P")
  6349. (org-agenda-filter-by-tag strip char 'refine))
  6350. (defun org-agenda-filter-make-matcher ()
  6351. "Create the form that tests a line for agenda filter."
  6352. (let (f f1)
  6353. ;; first compute the tag-filter matcher
  6354. (dolist (x (delete-dups
  6355. (append (get 'org-agenda-tag-filter
  6356. :preset-filter) org-agenda-tag-filter)))
  6357. (if (member x '("-" "+"))
  6358. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6359. (if (string-match "[<=>?]" x)
  6360. (setq f1 (org-agenda-filter-effort-form x))
  6361. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6362. (if (equal (string-to-char x) ?-)
  6363. (setq f1 (list 'not f1))))
  6364. (push f1 f))
  6365. ;; then compute the category-filter matcher
  6366. (dolist (x (delete-dups
  6367. (append (get 'org-agenda-category-filter
  6368. :preset-filter) org-agenda-category-filter)))
  6369. (if (equal "-" (substring x 0 1))
  6370. (setq f1 (list 'not (list 'equal (substring x 1) 'cat)))
  6371. (setq f1 (list 'equal (substring x 1) 'cat)))
  6372. (push f1 f))
  6373. (cons 'and (nreverse f))))
  6374. (defun org-agenda-filter-effort-form (e)
  6375. "Return the form to compare the effort of the current line with what E says.
  6376. E looks like \"+<2:25\"."
  6377. (let (op)
  6378. (setq e (substring e 1))
  6379. (setq op (string-to-char e) e (substring e 1))
  6380. (setq op (cond ((equal op ?<) '<=)
  6381. ((equal op ?>) '>=)
  6382. ((equal op ??) op)
  6383. (t '=)))
  6384. (list 'org-agenda-compare-effort (list 'quote op)
  6385. (org-duration-string-to-minutes e))))
  6386. (defun org-agenda-compare-effort (op value)
  6387. "Compare the effort of the current line with VALUE, using OP.
  6388. If the line does not have an effort defined, return nil."
  6389. (let ((eff (org-get-at-bol 'effort-minutes)))
  6390. (if (equal op ??)
  6391. (not eff)
  6392. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6393. value))))
  6394. (defun org-agenda-filter-apply (filter type)
  6395. "Set FILTER as the new agenda filter and apply it."
  6396. (let (tags cat)
  6397. (if (eq type 'tag)
  6398. (setq org-agenda-tag-filter filter)
  6399. (setq org-agenda-category-filter filter))
  6400. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6401. (if (and (eq type 'category)
  6402. (not (equal (substring (car filter) 0 1) "-")))
  6403. ;; Only set `org-agenda-filtered-by-category' to t
  6404. ;; when a unique category is used as the filter
  6405. (setq org-agenda-filtered-by-category t))
  6406. (org-agenda-set-mode-name)
  6407. (save-excursion
  6408. (goto-char (point-min))
  6409. (while (not (eobp))
  6410. (if (org-get-at-bol 'org-marker)
  6411. (progn
  6412. (setq tags (org-get-at-bol 'tags) ; used in eval
  6413. cat (get-text-property (point) 'org-category))
  6414. (if (not (eval org-agenda-filter-form))
  6415. (org-agenda-filter-hide-line type))
  6416. (beginning-of-line 2))
  6417. (beginning-of-line 2))))
  6418. (if (get-char-property (point) 'invisible)
  6419. (ignore-errors (org-agenda-previous-line)))))
  6420. (defun org-agenda-filter-top-category-apply (category &optional negative)
  6421. "Set FILTER as the new agenda filter and apply it."
  6422. (org-agenda-set-mode-name)
  6423. (save-excursion
  6424. (goto-char (point-min))
  6425. (while (not (eobp))
  6426. (let* ((pos (org-get-at-bol 'org-hd-marker))
  6427. (topcat (and pos (org-find-top-category pos))))
  6428. (if (and topcat (funcall (if negative 'identity 'not)
  6429. (string= category topcat)))
  6430. (org-agenda-filter-hide-line 'category)))
  6431. (beginning-of-line 2)))
  6432. (if (get-char-property (point) 'invisible)
  6433. (org-agenda-previous-line))
  6434. (setq org-agenda-top-category-filter category
  6435. org-agenda-filtered-by-top-category t))
  6436. (defun org-agenda-filter-hide-line (type)
  6437. (let (ov)
  6438. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6439. (point-at-eol)))
  6440. (overlay-put ov 'invisible t)
  6441. (overlay-put ov 'type type)
  6442. (if (eq type 'tag)
  6443. (push ov org-agenda-tag-filter-overlays)
  6444. (push ov org-agenda-cat-filter-overlays))))
  6445. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6446. (setq pos (or pos (point)))
  6447. (save-excursion
  6448. (dolist (ov (overlays-at pos))
  6449. (when (and (overlay-get ov 'invisible)
  6450. (eq (overlay-get ov 'type) 'tag))
  6451. (goto-char pos)
  6452. (if (< (overlay-start ov) (point-at-eol))
  6453. (move-overlay ov (point-at-eol)
  6454. (overlay-end ov)))))))
  6455. (defun org-agenda-filter-show-all-tag nil
  6456. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6457. (setq org-agenda-tag-filter-overlays nil
  6458. org-agenda-tag-filter nil
  6459. org-agenda-filter-form nil)
  6460. (org-agenda-set-mode-name))
  6461. (defun org-agenda-filter-show-all-cat nil
  6462. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6463. (setq org-agenda-cat-filter-overlays nil
  6464. org-agenda-filtered-by-category nil
  6465. org-agenda-category-filter nil
  6466. org-agenda-filter-form nil)
  6467. (org-agenda-set-mode-name))
  6468. (defun org-agenda-manipulate-query-add ()
  6469. "Manipulate the query by adding a search term with positive selection.
  6470. Positive selection means the term must be matched for selection of an entry."
  6471. (interactive)
  6472. (org-agenda-manipulate-query ?\[))
  6473. (defun org-agenda-manipulate-query-subtract ()
  6474. "Manipulate the query by adding a search term with negative selection.
  6475. Negative selection means term must not be matched for selection of an entry."
  6476. (interactive)
  6477. (org-agenda-manipulate-query ?\]))
  6478. (defun org-agenda-manipulate-query-add-re ()
  6479. "Manipulate the query by adding a search regexp with positive selection.
  6480. Positive selection means the regexp must match for selection of an entry."
  6481. (interactive)
  6482. (org-agenda-manipulate-query ?\{))
  6483. (defun org-agenda-manipulate-query-subtract-re ()
  6484. "Manipulate the query by adding a search regexp with negative selection.
  6485. Negative selection means regexp must not match for selection of an entry."
  6486. (interactive)
  6487. (org-agenda-manipulate-query ?\}))
  6488. (defun org-agenda-manipulate-query (char)
  6489. (cond
  6490. ((memq org-agenda-type '(timeline agenda))
  6491. (let ((org-agenda-include-inactive-timestamps t))
  6492. (org-agenda-redo))
  6493. (message "Display now includes inactive timestamps as well"))
  6494. ((eq org-agenda-type 'search)
  6495. (org-add-to-string
  6496. 'org-agenda-query-string
  6497. (if org-agenda-last-search-view-search-was-boolean
  6498. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6499. (?\{ . " +{}") (?\} . " -{}"))))
  6500. " "))
  6501. (setq org-agenda-redo-command
  6502. (list 'org-search-view
  6503. (car (get-text-property (point) 'org-last-args))
  6504. org-agenda-query-string
  6505. (+ (length org-agenda-query-string)
  6506. (if (member char '(?\{ ?\})) 0 1))))
  6507. (set-register org-agenda-query-register org-agenda-query-string)
  6508. (let ((org-agenda-overriding-arguments
  6509. (cdr org-agenda-redo-command)))
  6510. (org-agenda-redo)))
  6511. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6512. org-agenda-type))))
  6513. (defun org-add-to-string (var string)
  6514. (set var (concat (symbol-value var) string)))
  6515. (defun org-agenda-goto-date (span)
  6516. "Jump to DATE in agenda."
  6517. (interactive "P")
  6518. (let* ((org-read-date-prefer-future
  6519. (eval org-agenda-jump-prefer-future))
  6520. (date (org-read-date))
  6521. (org-agenda-sticky-orig org-agenda-sticky)
  6522. (org-agenda-buffer-tmp-name (buffer-name))
  6523. (args (get-text-property (point) 'org-last-args))
  6524. (0-arg (or current-prefix-arg (car args)))
  6525. (2-arg (nth 2 args))
  6526. (newcmd (list 'org-agenda-list 0-arg date
  6527. (org-agenda-span-to-ndays 2-arg)))
  6528. (newargs (cdr newcmd))
  6529. (inhibit-read-only t)
  6530. org-agenda-sticky)
  6531. (if (not (org-agenda-check-type t 'agenda))
  6532. (error "Not available in non-agenda blocks")
  6533. (add-text-properties (point-min) (point-max)
  6534. `(org-redo-cmd ,newcmd org-last-args ,newargs))
  6535. (org-agenda-redo)
  6536. (setq org-agenda-sticky org-agenda-sticky-orig
  6537. org-agenda-this-buffer-is-sticky org-agenda-sticky))))
  6538. (defun org-agenda-goto-today ()
  6539. "Go to today."
  6540. (interactive)
  6541. (org-agenda-check-type t 'timeline 'agenda)
  6542. (let* ((args (get-text-property (point) 'org-last-args))
  6543. (curspan (nth 2 args))
  6544. (tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6545. (cond
  6546. (tdpos (goto-char tdpos))
  6547. ((eq org-agenda-type 'agenda)
  6548. (let* ((sd (org-agenda-compute-starting-span
  6549. (org-today) (or curspan org-agenda-ndays org-agenda-span)))
  6550. (org-agenda-overriding-arguments args))
  6551. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6552. (org-agenda-redo)
  6553. (org-agenda-find-same-or-today-or-agenda)))
  6554. (t (error "Cannot find today")))))
  6555. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6556. (goto-char
  6557. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6558. (text-property-any (point-min) (point-max) 'org-today t)
  6559. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6560. (and (get-text-property (point) 'org-serie)
  6561. (org-agenda-goto-block-beginning))
  6562. (point-min))))
  6563. (defun org-agenda-goto-block-beginning ()
  6564. "Go the agenda block beginning."
  6565. (interactive)
  6566. (if (not (derived-mode-p 'org-agenda-mode))
  6567. (error "Cannot execute this command outside of org-agenda-mode buffers")
  6568. (let (dest)
  6569. (save-excursion
  6570. (unless (looking-at "\\'")
  6571. (forward-char))
  6572. (let* ((prop 'org-agenda-structural-header)
  6573. (p (previous-single-property-change (point) prop))
  6574. (n (next-single-property-change (or (and (looking-at "\\`") 1)
  6575. (1- (point))) prop)))
  6576. (setq dest (cond ((eq n (point-at-eol)) (1- n)) (p (1- p))))))
  6577. (if (not dest)
  6578. (error "Cannot find the beginning of the blog")
  6579. (goto-char dest)
  6580. (move-beginning-of-line 1)))))
  6581. (defun org-agenda-later (arg)
  6582. "Go forward in time by thee current span.
  6583. With prefix ARG, go forward that many times the current span."
  6584. (interactive "p")
  6585. (org-agenda-check-type t 'agenda)
  6586. (let* ((args (get-text-property (point) 'org-last-args))
  6587. (span (or (nth 2 args) org-agenda-current-span))
  6588. (sd (or (nth 1 args) (org-get-at-bol 'day) org-starting-day))
  6589. (greg (calendar-gregorian-from-absolute sd))
  6590. (cnt (org-get-at-bol 'org-day-cnt))
  6591. greg2)
  6592. (cond
  6593. ((numberp span)
  6594. (setq sd (+ span sd)))
  6595. ((eq span 'day)
  6596. (setq sd (+ arg sd)))
  6597. ((eq span 'week)
  6598. (setq sd (+ (* 7 arg) sd)))
  6599. ((eq span 'month)
  6600. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6601. sd (calendar-absolute-from-gregorian greg2))
  6602. (setcar greg2 (1+ (car greg2))))
  6603. ((eq span 'year)
  6604. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6605. sd (calendar-absolute-from-gregorian greg2))
  6606. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6607. (t
  6608. (setq sd (+ (* span arg) sd))))
  6609. (let ((org-agenda-overriding-cmd
  6610. ;; `cmd' may have been set by `org-agenda-run-series' which
  6611. ;; uses `org-agenda-overriding-cmd' to decide whether
  6612. ;; overriding is allowed for `cmd'
  6613. (get-text-property (point) 'org-serie-cmd))
  6614. (org-agenda-overriding-arguments
  6615. (list (car args) sd span)))
  6616. (org-agenda-redo)
  6617. (org-agenda-find-same-or-today-or-agenda cnt))))
  6618. (defun org-agenda-earlier (arg)
  6619. "Go backward in time by the current span.
  6620. With prefix ARG, go backward that many times the current span."
  6621. (interactive "p")
  6622. (org-agenda-later (- arg)))
  6623. (defun org-agenda-view-mode-dispatch ()
  6624. "Call one of the view mode commands."
  6625. (interactive)
  6626. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6627. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6628. [a]rch-trees [A]rch-files clock[R]eport include[D]iary [E]ntryText")
  6629. (let ((a (read-char-exclusive)))
  6630. (case a
  6631. (?\ (call-interactively 'org-agenda-reset-view))
  6632. (?d (call-interactively 'org-agenda-day-view))
  6633. (?w (call-interactively 'org-agenda-week-view))
  6634. (?m (call-interactively 'org-agenda-month-view))
  6635. (?y (call-interactively 'org-agenda-year-view))
  6636. (?l (call-interactively 'org-agenda-log-mode))
  6637. (?L (org-agenda-log-mode '(4)))
  6638. (?c (org-agenda-log-mode 'clockcheck))
  6639. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6640. (?a (call-interactively 'org-agenda-archives-mode))
  6641. (?A (org-agenda-archives-mode 'files))
  6642. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6643. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6644. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6645. (?D (call-interactively 'org-agenda-toggle-diary))
  6646. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6647. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6648. (org-agenda-check-type t 'timeline 'agenda)
  6649. (org-agenda-redo))
  6650. (message "Display now includes inactive timestamps as well"))
  6651. (?q (message "Abort"))
  6652. (otherwise (error "Invalid key" )))))
  6653. (defun org-agenda-reset-view ()
  6654. "Switch to default view for agenda."
  6655. (interactive)
  6656. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6657. (defun org-agenda-day-view (&optional day-of-year)
  6658. "Switch to daily view for agenda.
  6659. With argument DAY-OF-YEAR, switch to that day of the year."
  6660. (interactive "P")
  6661. (org-agenda-change-time-span 'day day-of-year))
  6662. (defun org-agenda-week-view (&optional iso-week)
  6663. "Switch to daily view for agenda.
  6664. With argument ISO-WEEK, switch to the corresponding ISO week.
  6665. If ISO-WEEK has more then 2 digits, only the last two encode the
  6666. week. Any digits before this encode a year. So 200712 means
  6667. week 12 of year 2007. Years in the range 1938-2037 can also be
  6668. written as 2-digit years."
  6669. (interactive "P")
  6670. (org-agenda-change-time-span 'week iso-week))
  6671. (defun org-agenda-month-view (&optional month)
  6672. "Switch to monthly view for agenda.
  6673. With argument MONTH, switch to that month."
  6674. (interactive "P")
  6675. (org-agenda-change-time-span 'month month))
  6676. (defun org-agenda-year-view (&optional year)
  6677. "Switch to yearly view for agenda.
  6678. With argument YEAR, switch to that year.
  6679. If MONTH has more then 2 digits, only the last two encode the
  6680. month. Any digits before this encode a year. So 200712 means
  6681. December year 2007. Years in the range 1938-2037 can also be
  6682. written as 2-digit years."
  6683. (interactive "P")
  6684. (when year
  6685. (setq year (org-small-year-to-year year)))
  6686. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6687. (org-agenda-change-time-span 'year year)
  6688. (error "Abort")))
  6689. (defun org-agenda-change-time-span (span &optional n)
  6690. "Change the agenda view to SPAN.
  6691. SPAN may be `day', `week', `month', `year'."
  6692. (org-agenda-check-type t 'agenda)
  6693. (let* ((args (get-text-property (point) 'org-last-args))
  6694. (curspan (nth 2 args)))
  6695. (if (and (not n) (equal curspan span))
  6696. (error "Viewing span is already \"%s\"" span))
  6697. (let* ((sd (or (org-get-at-bol 'day)
  6698. (nth 1 args)
  6699. org-starting-day))
  6700. (sd (org-agenda-compute-starting-span sd span n))
  6701. (org-agenda-overriding-cmd
  6702. (get-text-property (point) 'org-serie-cmd))
  6703. (org-agenda-overriding-arguments
  6704. (list (car args) sd span)))
  6705. (org-agenda-redo)
  6706. (org-agenda-find-same-or-today-or-agenda))
  6707. (org-agenda-set-mode-name)
  6708. (message "Switched to %s view" span)))
  6709. (defun org-agenda-compute-starting-span (sd span &optional n)
  6710. "Compute starting date for agenda.
  6711. SPAN may be `day', `week', `month', `year'. The return value
  6712. is a cons cell with the starting date and the number of days,
  6713. so that the date SD will be in that range."
  6714. (let* ((greg (calendar-gregorian-from-absolute sd))
  6715. (dg (nth 1 greg))
  6716. (mg (car greg))
  6717. (yg (nth 2 greg)))
  6718. (cond
  6719. ((eq span 'day)
  6720. (when n
  6721. (setq sd (+ (calendar-absolute-from-gregorian
  6722. (list mg 1 yg))
  6723. n -1))))
  6724. ((eq span 'week)
  6725. (let* ((nt (calendar-day-of-week
  6726. (calendar-gregorian-from-absolute sd)))
  6727. (d (if org-agenda-start-on-weekday
  6728. (- nt org-agenda-start-on-weekday)
  6729. 0))
  6730. y1)
  6731. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6732. (when n
  6733. (require 'cal-iso)
  6734. (when (> n 99)
  6735. (setq y1 (org-small-year-to-year (/ n 100))
  6736. n (mod n 100)))
  6737. (setq sd
  6738. (calendar-absolute-from-iso
  6739. (list n 1
  6740. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6741. ((eq span 'month)
  6742. (let (y1)
  6743. (when (and n (> n 99))
  6744. (setq y1 (org-small-year-to-year (/ n 100))
  6745. n (mod n 100)))
  6746. (setq sd (calendar-absolute-from-gregorian
  6747. (list (or n mg) 1 (or y1 yg))))))
  6748. ((eq span 'year)
  6749. (setq sd (calendar-absolute-from-gregorian
  6750. (list 1 1 (or n yg))))))
  6751. sd))
  6752. (defun org-agenda-next-date-line (&optional arg)
  6753. "Jump to the next line indicating a date in agenda buffer."
  6754. (interactive "p")
  6755. (org-agenda-check-type t 'agenda 'timeline)
  6756. (beginning-of-line 1)
  6757. ;; This does not work if user makes date format that starts with a blank
  6758. (if (looking-at "^\\S-") (forward-char 1))
  6759. (if (not (re-search-forward "^\\S-" nil t arg))
  6760. (progn
  6761. (backward-char 1)
  6762. (error "No next date after this line in this buffer")))
  6763. (goto-char (match-beginning 0)))
  6764. (defun org-agenda-previous-date-line (&optional arg)
  6765. "Jump to the previous line indicating a date in agenda buffer."
  6766. (interactive "p")
  6767. (org-agenda-check-type t 'agenda 'timeline)
  6768. (beginning-of-line 1)
  6769. (if (not (re-search-backward "^\\S-" nil t arg))
  6770. (error "No previous date before this line in this buffer")))
  6771. ;; Initialize the highlight
  6772. (defvar org-hl (make-overlay 1 1))
  6773. (overlay-put org-hl 'face 'highlight)
  6774. (defun org-highlight (begin end &optional buffer)
  6775. "Highlight a region with overlay."
  6776. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6777. (defun org-unhighlight ()
  6778. "Detach overlay INDEX."
  6779. (org-detach-overlay org-hl))
  6780. (defun org-unhighlight-once ()
  6781. "Remove the highlight from its position, and this function from the hook."
  6782. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6783. (org-unhighlight))
  6784. (defun org-agenda-follow-mode ()
  6785. "Toggle follow mode in an agenda buffer."
  6786. (interactive)
  6787. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6788. (org-agenda-set-mode-name)
  6789. (org-agenda-do-context-action)
  6790. (message "Follow mode is %s"
  6791. (if org-agenda-follow-mode "on" "off")))
  6792. (defun org-agenda-entry-text-mode (&optional arg)
  6793. "Toggle entry text mode in an agenda buffer."
  6794. (interactive "P")
  6795. (setq org-agenda-entry-text-mode (or (integerp arg)
  6796. (not org-agenda-entry-text-mode)))
  6797. (org-agenda-entry-text-hide)
  6798. (and org-agenda-entry-text-mode
  6799. (let ((org-agenda-entry-text-maxlines
  6800. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6801. (org-agenda-entry-text-show)))
  6802. (org-agenda-set-mode-name)
  6803. (message "Entry text mode is %s. Maximum number of lines is %d"
  6804. (if org-agenda-entry-text-mode "on" "off")
  6805. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6806. (defun org-agenda-clockreport-mode (&optional with-filter)
  6807. "Toggle clocktable mode in an agenda buffer.
  6808. With prefix arg WITH-FILTER, make the clocktable respect the current
  6809. agenda filter."
  6810. (interactive "P")
  6811. (org-agenda-check-type t 'agenda)
  6812. (if with-filter
  6813. (setq org-agenda-clockreport-mode 'with-filter)
  6814. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6815. (org-agenda-set-mode-name)
  6816. (org-agenda-redo)
  6817. (message "Clocktable mode is %s"
  6818. (if org-agenda-clockreport-mode "on" "off")))
  6819. (defun org-agenda-log-mode (&optional special)
  6820. "Toggle log mode in an agenda buffer.
  6821. With argument SPECIAL, show all possible log items, not only the ones
  6822. configured in `org-agenda-log-mode-items'.
  6823. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6824. (interactive "P")
  6825. (org-agenda-check-type t 'agenda 'timeline)
  6826. (setq org-agenda-show-log
  6827. (cond
  6828. ((equal special '(16)) 'only)
  6829. ((eq special 'clockcheck)
  6830. (if (eq org-agenda-show-log 'clockcheck)
  6831. nil 'clockcheck))
  6832. (special '(closed clock state))
  6833. (t (not org-agenda-show-log))))
  6834. (org-agenda-set-mode-name)
  6835. (org-agenda-redo)
  6836. (message "Log mode is %s"
  6837. (if org-agenda-show-log "on" "off")))
  6838. (defun org-agenda-archives-mode (&optional with-files)
  6839. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6840. When called with a prefix argument, include all archive files as well."
  6841. (interactive "P")
  6842. (setq org-agenda-archives-mode
  6843. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6844. (org-agenda-set-mode-name)
  6845. (org-agenda-redo)
  6846. (message
  6847. "%s"
  6848. (cond
  6849. ((eq org-agenda-archives-mode nil)
  6850. "No archives are included")
  6851. ((eq org-agenda-archives-mode 'trees)
  6852. (format "Trees with :%s: tag are included" org-archive-tag))
  6853. ((eq org-agenda-archives-mode t)
  6854. (format "Trees with :%s: tag and all active archive files are included"
  6855. org-archive-tag)))))
  6856. (defun org-agenda-toggle-diary ()
  6857. "Toggle diary inclusion in an agenda buffer."
  6858. (interactive)
  6859. (org-agenda-check-type t 'agenda)
  6860. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6861. (org-agenda-redo)
  6862. (org-agenda-set-mode-name)
  6863. (message "Diary inclusion turned %s"
  6864. (if org-agenda-include-diary "on" "off")))
  6865. (defun org-agenda-toggle-deadlines ()
  6866. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6867. (interactive)
  6868. (org-agenda-check-type t 'agenda)
  6869. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6870. (org-agenda-redo)
  6871. (org-agenda-set-mode-name)
  6872. (message "Deadlines inclusion turned %s"
  6873. (if org-agenda-include-deadlines "on" "off")))
  6874. (defun org-agenda-toggle-time-grid ()
  6875. "Toggle time grid in an agenda buffer."
  6876. (interactive)
  6877. (org-agenda-check-type t 'agenda)
  6878. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6879. (org-agenda-redo)
  6880. (org-agenda-set-mode-name)
  6881. (message "Time-grid turned %s"
  6882. (if org-agenda-use-time-grid "on" "off")))
  6883. (defun org-agenda-set-mode-name ()
  6884. "Set the mode name to indicate all the small mode settings."
  6885. (setq mode-name
  6886. (list "Org-Agenda"
  6887. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6888. " "
  6889. '(:eval (org-agenda-span-name org-agenda-current-span))
  6890. (if org-agenda-follow-mode " Follow" "")
  6891. (if org-agenda-entry-text-mode " ETxt" "")
  6892. (if org-agenda-include-diary " Diary" "")
  6893. (if org-agenda-include-deadlines " Ddl" "")
  6894. (if org-agenda-use-time-grid " Grid" "")
  6895. (if (and (boundp 'org-habit-show-habits)
  6896. org-habit-show-habits) " Habit" "")
  6897. (cond
  6898. ((consp org-agenda-show-log) " LogAll")
  6899. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6900. (org-agenda-show-log " Log")
  6901. (t ""))
  6902. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6903. :preset-filter))
  6904. '(:eval (org-propertize
  6905. (concat " <"
  6906. (mapconcat
  6907. 'identity
  6908. (append
  6909. (get 'org-agenda-category-filter :preset-filter)
  6910. org-agenda-category-filter)
  6911. "")
  6912. ">")
  6913. 'face 'org-agenda-filter-category
  6914. 'help-echo "Category used in filtering"))
  6915. "")
  6916. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6917. :preset-filter))
  6918. '(:eval (org-propertize
  6919. (concat " {"
  6920. (mapconcat
  6921. 'identity
  6922. (append
  6923. (get 'org-agenda-tag-filter :preset-filter)
  6924. org-agenda-tag-filter)
  6925. "")
  6926. "}")
  6927. 'face 'org-agenda-filter-tags
  6928. 'help-echo "Tags used in filtering"))
  6929. "")
  6930. (if org-agenda-archives-mode
  6931. (if (eq org-agenda-archives-mode t)
  6932. " Archives"
  6933. (format " :%s:" org-archive-tag))
  6934. "")
  6935. (if org-agenda-clockreport-mode
  6936. (if (eq org-agenda-clockreport-mode 'with-filter)
  6937. " Clock{}" " Clock")
  6938. "")))
  6939. (force-mode-line-update))
  6940. (defun org-agenda-post-command-hook ()
  6941. (setq org-agenda-type
  6942. (or (get-text-property (point) 'org-agenda-type)
  6943. (get-text-property (max (point-min) (1- (point)))
  6944. 'org-agenda-type))))
  6945. (defun org-agenda-next-line ()
  6946. "Move cursor to the next line, and show if follow mode is active."
  6947. (interactive)
  6948. (call-interactively 'next-line)
  6949. (org-agenda-do-context-action))
  6950. (defun org-agenda-previous-line ()
  6951. "Move cursor to the previous line, and show if follow-mode is active."
  6952. (interactive)
  6953. (call-interactively 'previous-line)
  6954. (org-agenda-do-context-action))
  6955. (defun org-agenda-next-item (n)
  6956. "Move cursor to next agenda item."
  6957. (interactive "p")
  6958. (let ((col (current-column)))
  6959. (dotimes (c n)
  6960. (when (next-single-property-change (point-at-eol) 'org-marker)
  6961. (move-end-of-line 1)
  6962. (goto-char (next-single-property-change (point) 'org-marker))))
  6963. (org-move-to-column col))
  6964. (org-agenda-do-context-action))
  6965. (defun org-agenda-previous-item (n)
  6966. "Move cursor to next agenda item."
  6967. (interactive "p")
  6968. (dotimes (c n)
  6969. (let ((col (current-column))
  6970. (goto (save-excursion
  6971. (move-end-of-line 0)
  6972. (previous-single-property-change (point) 'org-marker))))
  6973. (if goto (goto-char goto))
  6974. (org-move-to-column col)))
  6975. (org-agenda-do-context-action))
  6976. (defun org-agenda-do-context-action ()
  6977. "Show outline path and, maybe, follow mode window."
  6978. (let ((m (org-get-at-bol 'org-marker)))
  6979. (when (and (markerp m) (marker-buffer m))
  6980. (and org-agenda-follow-mode
  6981. (if org-agenda-follow-indirect
  6982. (org-agenda-tree-to-indirect-buffer)
  6983. (org-agenda-show)))
  6984. (and org-agenda-show-outline-path
  6985. (org-with-point-at m (org-display-outline-path t))))))
  6986. (defun org-agenda-show-priority ()
  6987. "Show the priority of the current item.
  6988. This priority is composed of the main priority given with the [#A] cookies,
  6989. and by additional input from the age of a schedules or deadline entry."
  6990. (interactive)
  6991. (let* ((pri (org-get-at-bol 'priority)))
  6992. (message "Priority is %d" (if pri pri -1000))))
  6993. (defun org-agenda-show-tags ()
  6994. "Show the tags applicable to the current item."
  6995. (interactive)
  6996. (let* ((tags (org-get-at-bol 'tags)))
  6997. (if tags
  6998. (message "Tags are :%s:"
  6999. (org-no-properties (mapconcat 'identity tags ":")))
  7000. (message "No tags associated with this line"))))
  7001. (defun org-agenda-goto (&optional highlight)
  7002. "Go to the Org-mode file which contains the item at point."
  7003. (interactive)
  7004. (let* ((marker (or (org-get-at-bol 'org-marker)
  7005. (org-agenda-error)))
  7006. (buffer (marker-buffer marker))
  7007. (pos (marker-position marker)))
  7008. (switch-to-buffer-other-window buffer)
  7009. (widen)
  7010. (push-mark)
  7011. (goto-char pos)
  7012. (when (derived-mode-p 'org-mode)
  7013. (org-show-context 'agenda)
  7014. (save-excursion
  7015. (and (outline-next-heading)
  7016. (org-flag-heading nil)))) ; show the next heading
  7017. (when (outline-invisible-p)
  7018. (show-entry)) ; display invisible text
  7019. (recenter (/ (window-height) 2))
  7020. (run-hooks 'org-agenda-after-show-hook)
  7021. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  7022. (defvar org-agenda-after-show-hook nil
  7023. "Normal hook run after an item has been shown from the agenda.
  7024. Point is in the buffer where the item originated.")
  7025. (defun org-agenda-kill ()
  7026. "Kill the entry or subtree belonging to the current agenda entry."
  7027. (interactive)
  7028. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7029. (let* ((bufname-orig (buffer-name))
  7030. (marker (or (org-get-at-bol 'org-marker)
  7031. (org-agenda-error)))
  7032. (buffer (marker-buffer marker))
  7033. (pos (marker-position marker))
  7034. (type (org-get-at-bol 'type))
  7035. dbeg dend (n 0) conf)
  7036. (org-with-remote-undo buffer
  7037. (with-current-buffer buffer
  7038. (save-excursion
  7039. (goto-char pos)
  7040. (if (and (derived-mode-p 'org-mode) (not (member type '("sexp"))))
  7041. (setq dbeg (progn (org-back-to-heading t) (point))
  7042. dend (org-end-of-subtree t t))
  7043. (setq dbeg (point-at-bol)
  7044. dend (min (point-max) (1+ (point-at-eol)))))
  7045. (goto-char dbeg)
  7046. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  7047. (setq conf (or (eq t org-agenda-confirm-kill)
  7048. (and (numberp org-agenda-confirm-kill)
  7049. (> n org-agenda-confirm-kill))))
  7050. (and conf
  7051. (not (y-or-n-p
  7052. (format "Delete entry with %d lines in buffer \"%s\"? "
  7053. n (buffer-name buffer))))
  7054. (error "Abort"))
  7055. (let ((org-agenda-buffer-name bufname-orig))
  7056. (org-remove-subtree-entries-from-agenda buffer dbeg dend))
  7057. (with-current-buffer buffer (delete-region dbeg dend))
  7058. (message "Agenda item and source killed"))))
  7059. (defvar org-archive-default-command) ; defined in org-archive.el
  7060. (defun org-agenda-archive-default ()
  7061. "Archive the entry or subtree belonging to the current agenda entry."
  7062. (interactive)
  7063. (require 'org-archive)
  7064. (org-agenda-archive-with org-archive-default-command))
  7065. (defun org-agenda-archive-default-with-confirmation ()
  7066. "Archive the entry or subtree belonging to the current agenda entry."
  7067. (interactive)
  7068. (require 'org-archive)
  7069. (org-agenda-archive-with org-archive-default-command 'confirm))
  7070. (defun org-agenda-archive ()
  7071. "Archive the entry or subtree belonging to the current agenda entry."
  7072. (interactive)
  7073. (org-agenda-archive-with 'org-archive-subtree))
  7074. (defun org-agenda-archive-to-archive-sibling ()
  7075. "Move the entry to the archive sibling."
  7076. (interactive)
  7077. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  7078. (defun org-agenda-archive-with (cmd &optional confirm)
  7079. "Move the entry to the archive sibling."
  7080. (interactive)
  7081. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  7082. (let* ((bufname-orig (buffer-name))
  7083. (marker (or (org-get-at-bol 'org-marker)
  7084. (org-agenda-error)))
  7085. (buffer (marker-buffer marker))
  7086. (pos (marker-position marker)))
  7087. (org-with-remote-undo buffer
  7088. (with-current-buffer buffer
  7089. (if (derived-mode-p 'org-mode)
  7090. (if (and confirm
  7091. (not (y-or-n-p "Archive this subtree or entry? ")))
  7092. (error "Abort")
  7093. (save-excursion
  7094. (goto-char pos)
  7095. (let ((org-agenda-buffer-name bufname-orig))
  7096. (org-remove-subtree-entries-from-agenda))
  7097. (org-back-to-heading t)
  7098. (funcall cmd)))
  7099. (error "Archiving works only in Org-mode files"))))))
  7100. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  7101. "Remove all lines in the agenda that correspond to a given subtree.
  7102. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  7103. If this information is not given, the function uses the tree at point."
  7104. (let ((buf (or buf (current-buffer))) m p)
  7105. (save-excursion
  7106. (unless (and beg end)
  7107. (org-back-to-heading t)
  7108. (setq beg (point))
  7109. (org-end-of-subtree t)
  7110. (setq end (point)))
  7111. (set-buffer (get-buffer org-agenda-buffer-name))
  7112. (save-excursion
  7113. (goto-char (point-max))
  7114. (beginning-of-line 1)
  7115. (while (not (bobp))
  7116. (when (and (setq m (org-get-at-bol 'org-marker))
  7117. (equal buf (marker-buffer m))
  7118. (setq p (marker-position m))
  7119. (>= p beg)
  7120. (< p end))
  7121. (let ((inhibit-read-only t))
  7122. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  7123. (beginning-of-line 0))))))
  7124. (defun org-agenda-refile (&optional goto rfloc no-update)
  7125. "Refile the item at point."
  7126. (interactive "P")
  7127. (if (equal goto '(16))
  7128. (org-refile-goto-last-stored)
  7129. (let* ((buffer-orig (buffer-name))
  7130. (marker (or (org-get-at-bol 'org-hd-marker)
  7131. (org-agenda-error)))
  7132. (buffer (marker-buffer marker))
  7133. (pos (marker-position marker))
  7134. (rfloc (or rfloc
  7135. (org-refile-get-location
  7136. (if goto "Goto" "Refile to") buffer
  7137. org-refile-allow-creating-parent-nodes))))
  7138. (with-current-buffer buffer
  7139. (save-excursion
  7140. (save-restriction
  7141. (widen)
  7142. (goto-char marker)
  7143. (let ((org-agenda-buffer-name buffer-orig))
  7144. (org-remove-subtree-entries-from-agenda))
  7145. (org-refile goto buffer rfloc)))))
  7146. (unless no-update (org-agenda-redo))))
  7147. (defun org-agenda-open-link (&optional arg)
  7148. "Follow the link in the current line, if any.
  7149. This looks for a link in the displayed line in the agenda. It also looks
  7150. at the text of the entry itself."
  7151. (interactive "P")
  7152. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  7153. (org-get-at-bol 'org-marker)))
  7154. (buffer (and marker (marker-buffer marker)))
  7155. (prefix (buffer-substring
  7156. (point-at-bol) (point-at-eol))))
  7157. (cond
  7158. (buffer
  7159. (with-current-buffer buffer
  7160. (save-excursion
  7161. (save-restriction
  7162. (widen)
  7163. (goto-char marker)
  7164. (org-offer-links-in-entry arg prefix)))))
  7165. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  7166. (save-excursion
  7167. (beginning-of-line 1)
  7168. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  7169. (org-open-link-from-string (match-string 1)))
  7170. (t (error "No link to open here")))))
  7171. (defun org-agenda-copy-local-variable (var)
  7172. "Get a variable from a referenced buffer and install it here."
  7173. (let ((m (org-get-at-bol 'org-marker)))
  7174. (when (and m (buffer-live-p (marker-buffer m)))
  7175. (org-set-local var (with-current-buffer (marker-buffer m)
  7176. (symbol-value var))))))
  7177. (defun org-agenda-switch-to (&optional delete-other-windows)
  7178. "Go to the Org-mode file which contains the item at point."
  7179. (interactive)
  7180. (if (and org-return-follows-link
  7181. (not (org-get-at-bol 'org-marker))
  7182. (org-in-regexp org-bracket-link-regexp))
  7183. (org-open-link-from-string (match-string 0))
  7184. (let* ((marker (or (org-get-at-bol 'org-marker)
  7185. (org-agenda-error)))
  7186. (buffer (marker-buffer marker))
  7187. (pos (marker-position marker)))
  7188. (org-pop-to-buffer-same-window buffer)
  7189. (and delete-other-windows (delete-other-windows))
  7190. (widen)
  7191. (goto-char pos)
  7192. (when (derived-mode-p 'org-mode)
  7193. (org-show-context 'agenda)
  7194. (save-excursion
  7195. (and (outline-next-heading)
  7196. (org-flag-heading nil))) ; show the next heading
  7197. (when (outline-invisible-p)
  7198. (show-entry)) ; display invisible text
  7199. (run-hooks 'org-agenda-after-show-hook)))))
  7200. (defun org-agenda-goto-mouse (ev)
  7201. "Go to the Org-mode file which contains the item at the mouse click."
  7202. (interactive "e")
  7203. (mouse-set-point ev)
  7204. (org-agenda-goto))
  7205. (defun org-agenda-show (&optional full-entry)
  7206. "Display the Org-mode file which contains the item at point.
  7207. With prefix argument FULL-ENTRY, make the entire entry visible
  7208. if it was hidden in the outline."
  7209. (interactive "P")
  7210. (let ((win (selected-window)))
  7211. (if full-entry
  7212. (let ((org-show-entry-below t))
  7213. (org-agenda-goto t))
  7214. (org-agenda-goto t))
  7215. (select-window win)))
  7216. (defvar org-agenda-show-window nil)
  7217. (defun org-agenda-show-and-scroll-up (&optional arg)
  7218. "Display the Org-mode file which contains the item at point.
  7219. When called repeatedly, scroll the window that is displaying the buffer.
  7220. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  7221. `show-subtree' to display the item, so that drawers and logbooks stay
  7222. folded."
  7223. (interactive "P")
  7224. (let ((win (selected-window)))
  7225. (if (and (window-live-p org-agenda-show-window)
  7226. (eq this-command last-command))
  7227. (progn
  7228. (select-window org-agenda-show-window)
  7229. (ignore-errors (scroll-up)))
  7230. (org-agenda-goto t)
  7231. (if arg (org-show-entry) (show-subtree))
  7232. (setq org-agenda-show-window (selected-window)))
  7233. (select-window win)))
  7234. (defun org-agenda-show-scroll-down ()
  7235. "Scroll down the window showing the agenda."
  7236. (interactive)
  7237. (let ((win (selected-window)))
  7238. (when (window-live-p org-agenda-show-window)
  7239. (select-window org-agenda-show-window)
  7240. (ignore-errors (scroll-down))
  7241. (select-window win))))
  7242. (defun org-agenda-show-1 (&optional more)
  7243. "Display the Org-mode file which contains the item at point.
  7244. The prefix arg selects the amount of information to display:
  7245. 0 hide the subtree
  7246. 1 just show the entry according to defaults.
  7247. 2 show the children view
  7248. 3 show the subtree view
  7249. 4 show the entire subtree and any LOGBOOK drawers
  7250. 5 show the entire subtree and any drawers
  7251. With prefix argument FULL-ENTRY, make the entire entry visible
  7252. if it was hidden in the outline."
  7253. (interactive "p")
  7254. (let ((win (selected-window)))
  7255. (org-agenda-goto t)
  7256. (org-recenter-heading 1)
  7257. (cond
  7258. ((= more 0)
  7259. (hide-subtree)
  7260. (save-excursion
  7261. (org-back-to-heading)
  7262. (run-hook-with-args 'org-cycle-hook 'folded))
  7263. (message "Remote: FOLDED"))
  7264. ((and (org-called-interactively-p 'any) (= more 1))
  7265. (message "Remote: show with default settings"))
  7266. ((= more 2)
  7267. (show-entry)
  7268. (show-children)
  7269. (save-excursion
  7270. (org-back-to-heading)
  7271. (run-hook-with-args 'org-cycle-hook 'children))
  7272. (message "Remote: CHILDREN"))
  7273. ((= more 3)
  7274. (show-subtree)
  7275. (save-excursion
  7276. (org-back-to-heading)
  7277. (run-hook-with-args 'org-cycle-hook 'subtree))
  7278. (message "Remote: SUBTREE"))
  7279. ((= more 4)
  7280. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  7281. (org-drawer-regexp
  7282. (concat "^[ \t]*:\\("
  7283. (mapconcat 'regexp-quote org-drawers "\\|")
  7284. "\\):[ \t]*$")))
  7285. (show-subtree)
  7286. (save-excursion
  7287. (org-back-to-heading)
  7288. (org-cycle-hide-drawers 'subtree)))
  7289. (message "Remote: SUBTREE AND LOGBOOK"))
  7290. ((> more 4)
  7291. (show-subtree)
  7292. (message "Remote: SUBTREE AND ALL DRAWERS")))
  7293. (select-window win)))
  7294. (defun org-recenter-heading (n)
  7295. (save-excursion
  7296. (org-back-to-heading)
  7297. (recenter n)))
  7298. (defvar org-agenda-cycle-counter nil)
  7299. (defun org-agenda-cycle-show (&optional n)
  7300. "Show the current entry in another window, with default settings.
  7301. Default settings are taken from `org-show-hierarchy-above' and siblings.
  7302. When use repeatedly in immediate succession, the remote entry will cycle
  7303. through visibility
  7304. children -> subtree -> folded
  7305. When called with a numeric prefix arg, that arg will be passed through to
  7306. `org-agenda-show-1'. For the interpretation of that argument, see the
  7307. docstring of `org-agenda-show-1'."
  7308. (interactive "P")
  7309. (if (integerp n)
  7310. (setq org-agenda-cycle-counter n)
  7311. (if (not (eq last-command this-command))
  7312. (setq org-agenda-cycle-counter 1)
  7313. (if (equal org-agenda-cycle-counter 0)
  7314. (setq org-agenda-cycle-counter 2)
  7315. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  7316. (if (> org-agenda-cycle-counter 3)
  7317. (setq org-agenda-cycle-counter 0)))))
  7318. (org-agenda-show-1 org-agenda-cycle-counter))
  7319. (defun org-agenda-recenter (arg)
  7320. "Display the Org-mode file which contains the item at point and recenter."
  7321. (interactive "P")
  7322. (let ((win (selected-window)))
  7323. (org-agenda-goto t)
  7324. (recenter arg)
  7325. (select-window win)))
  7326. (defun org-agenda-show-mouse (ev)
  7327. "Display the Org-mode file which contains the item at the mouse click."
  7328. (interactive "e")
  7329. (mouse-set-point ev)
  7330. (org-agenda-show))
  7331. (defun org-agenda-check-no-diary ()
  7332. "Check if the entry is a diary link and abort if yes."
  7333. (if (org-get-at-bol 'org-agenda-diary-link)
  7334. (org-agenda-error)))
  7335. (defun org-agenda-error ()
  7336. (error "Command not allowed in this line"))
  7337. (defun org-agenda-tree-to-indirect-buffer ()
  7338. "Show the subtree corresponding to the current entry in an indirect buffer.
  7339. This calls the command `org-tree-to-indirect-buffer' from the original
  7340. Org-mode buffer.
  7341. With numerical prefix arg ARG, go up to this level and then take that tree.
  7342. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  7343. use the dedicated frame)."
  7344. (interactive)
  7345. (if (and current-prefix-arg (listp current-prefix-arg))
  7346. (org-agenda-do-tree-to-indirect-buffer)
  7347. (let ((agenda-window (selected-window))
  7348. (indirect-window
  7349. (and org-last-indirect-buffer
  7350. (get-buffer-window org-last-indirect-buffer))))
  7351. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  7352. (unwind-protect
  7353. (progn
  7354. (unless (and indirect-window (window-live-p indirect-window))
  7355. (setq indirect-window (split-window agenda-window)))
  7356. (select-window indirect-window)
  7357. (switch-to-buffer org-last-indirect-buffer :norecord)
  7358. (fit-window-to-buffer indirect-window))
  7359. (select-window (get-buffer-window org-agenda-buffer-name))))))
  7360. (defun org-agenda-do-tree-to-indirect-buffer ()
  7361. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  7362. (org-agenda-check-no-diary)
  7363. (let* ((marker (or (org-get-at-bol 'org-marker)
  7364. (org-agenda-error)))
  7365. (buffer (marker-buffer marker))
  7366. (pos (marker-position marker)))
  7367. (with-current-buffer buffer
  7368. (save-excursion
  7369. (goto-char pos)
  7370. (call-interactively 'org-tree-to-indirect-buffer)))))
  7371. (defvar org-last-heading-marker (make-marker)
  7372. "Marker pointing to the headline that last changed its TODO state
  7373. by a remote command from the agenda.")
  7374. (defun org-agenda-todo-nextset ()
  7375. "Switch TODO entry to next sequence."
  7376. (interactive)
  7377. (org-agenda-todo 'nextset))
  7378. (defun org-agenda-todo-previousset ()
  7379. "Switch TODO entry to previous sequence."
  7380. (interactive)
  7381. (org-agenda-todo 'previousset))
  7382. (defun org-agenda-todo (&optional arg)
  7383. "Cycle TODO state of line at point, also in Org-mode file.
  7384. This changes the line at point, all other lines in the agenda referring to
  7385. the same tree node, and the headline of the tree node in the Org-mode file."
  7386. (interactive "P")
  7387. (org-agenda-check-no-diary)
  7388. (let* ((col (current-column))
  7389. (marker (or (org-get-at-bol 'org-marker)
  7390. (org-agenda-error)))
  7391. (buffer (marker-buffer marker))
  7392. (pos (marker-position marker))
  7393. (hdmarker (org-get-at-bol 'org-hd-marker))
  7394. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7395. (inhibit-read-only t)
  7396. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7397. (org-with-remote-undo buffer
  7398. (with-current-buffer buffer
  7399. (widen)
  7400. (goto-char pos)
  7401. (org-show-context 'agenda)
  7402. (save-excursion
  7403. (and (outline-next-heading)
  7404. (org-flag-heading nil))) ; show the next heading
  7405. (let ((current-prefix-arg arg))
  7406. (call-interactively 'org-todo))
  7407. (and (bolp) (forward-char 1))
  7408. (setq newhead (org-get-heading))
  7409. (when (and (org-bound-and-true-p
  7410. org-agenda-headline-snapshot-before-repeat)
  7411. (not (equal org-agenda-headline-snapshot-before-repeat
  7412. newhead))
  7413. todayp)
  7414. (setq newhead org-agenda-headline-snapshot-before-repeat
  7415. just-one t))
  7416. (save-excursion
  7417. (org-back-to-heading)
  7418. (move-marker org-last-heading-marker (point))))
  7419. (beginning-of-line 1)
  7420. (save-excursion
  7421. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7422. (org-move-to-column col))))
  7423. (defun org-agenda-add-note (&optional arg)
  7424. "Add a time-stamped note to the entry at point."
  7425. (interactive "P")
  7426. (org-agenda-check-no-diary)
  7427. (let* ((marker (or (org-get-at-bol 'org-marker)
  7428. (org-agenda-error)))
  7429. (buffer (marker-buffer marker))
  7430. (pos (marker-position marker))
  7431. (hdmarker (org-get-at-bol 'org-hd-marker))
  7432. (inhibit-read-only t))
  7433. (with-current-buffer buffer
  7434. (widen)
  7435. (goto-char pos)
  7436. (org-show-context 'agenda)
  7437. (save-excursion
  7438. (and (outline-next-heading)
  7439. (org-flag-heading nil))) ; show the next heading
  7440. (org-add-note))))
  7441. (defun org-agenda-change-all-lines (newhead hdmarker
  7442. &optional fixface just-this)
  7443. "Change all lines in the agenda buffer which match HDMARKER.
  7444. The new content of the line will be NEWHEAD (as modified by
  7445. `org-agenda-format-item'). HDMARKER is checked with
  7446. `equal' against all `org-hd-marker' text properties in the file.
  7447. If FIXFACE is non-nil, the face of each item is modified according to
  7448. the new TODO state.
  7449. If JUST-THIS is non-nil, change just the current line, not all.
  7450. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7451. (let* ((inhibit-read-only t)
  7452. (line (org-current-line))
  7453. (org-agenda-buffer (current-buffer))
  7454. (thetags (with-current-buffer (marker-buffer hdmarker)
  7455. (save-excursion (save-restriction (widen)
  7456. (goto-char hdmarker)
  7457. (org-get-tags-at)))))
  7458. props m pl undone-face done-face finish new dotime level cat tags)
  7459. (save-excursion
  7460. (goto-char (point-max))
  7461. (beginning-of-line 1)
  7462. (while (not finish)
  7463. (setq finish (bobp))
  7464. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7465. (or (not just-this) (= (org-current-line) line))
  7466. (equal m hdmarker))
  7467. (setq props (text-properties-at (point))
  7468. dotime (org-get-at-bol 'dotime)
  7469. cat (org-get-at-bol 'org-category)
  7470. level (org-get-at-bol 'level)
  7471. tags thetags
  7472. new
  7473. (let ((org-prefix-format-compiled
  7474. (or (get-text-property (point) 'format)
  7475. org-prefix-format-compiled))
  7476. (extra (org-get-at-bol 'extra)))
  7477. (with-current-buffer (marker-buffer hdmarker)
  7478. (save-excursion
  7479. (save-restriction
  7480. (widen)
  7481. (org-agenda-format-item extra newhead level cat tags dotime)))))
  7482. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7483. undone-face (org-get-at-bol 'undone-face)
  7484. done-face (org-get-at-bol 'done-face))
  7485. (beginning-of-line 1)
  7486. (cond
  7487. ((equal new "")
  7488. (and (looking-at ".*\n?") (replace-match "")))
  7489. ((looking-at ".*")
  7490. (replace-match new t t)
  7491. (beginning-of-line 1)
  7492. (add-text-properties (point-at-bol) (point-at-eol) props)
  7493. (when fixface
  7494. (add-text-properties
  7495. (point-at-bol) (point-at-eol)
  7496. (list 'face
  7497. (if org-last-todo-state-is-todo
  7498. undone-face done-face))))
  7499. (org-agenda-highlight-todo 'line)
  7500. (beginning-of-line 1))
  7501. (t (error "Line update did not work"))))
  7502. (beginning-of-line 0)))
  7503. (org-agenda-finalize)))
  7504. (defun org-agenda-align-tags (&optional line)
  7505. "Align all tags in agenda items to `org-agenda-tags-column'."
  7506. (let ((inhibit-read-only t) l c)
  7507. (save-excursion
  7508. (goto-char (if line (point-at-bol) (point-min)))
  7509. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7510. (if line (point-at-eol) nil) t)
  7511. (add-text-properties
  7512. (match-beginning 2) (match-end 2)
  7513. (list 'face (delq nil (let ((prop (get-text-property
  7514. (match-beginning 2) 'face)))
  7515. (or (listp prop) (setq prop (list prop)))
  7516. (if (memq 'org-tag prop)
  7517. prop
  7518. (cons 'org-tag prop))))))
  7519. (setq l (- (match-end 2) (match-beginning 2))
  7520. c (if (< org-agenda-tags-column 0)
  7521. (- (abs org-agenda-tags-column) l)
  7522. org-agenda-tags-column))
  7523. (delete-region (match-beginning 1) (match-end 1))
  7524. (goto-char (match-beginning 1))
  7525. (insert (org-add-props
  7526. (make-string (max 1 (- c (current-column))) ?\ )
  7527. (plist-put (copy-sequence (text-properties-at (point)))
  7528. 'face nil))))
  7529. (goto-char (point-min))
  7530. (org-font-lock-add-tag-faces (point-max)))))
  7531. (defun org-agenda-priority-up ()
  7532. "Increase the priority of line at point, also in Org-mode file."
  7533. (interactive)
  7534. (org-agenda-priority 'up))
  7535. (defun org-agenda-priority-down ()
  7536. "Decrease the priority of line at point, also in Org-mode file."
  7537. (interactive)
  7538. (org-agenda-priority 'down))
  7539. (defun org-agenda-priority (&optional force-direction)
  7540. "Set the priority of line at point, also in Org-mode file.
  7541. This changes the line at point, all other lines in the agenda referring to
  7542. the same tree node, and the headline of the tree node in the Org-mode file."
  7543. (interactive)
  7544. (unless org-enable-priority-commands
  7545. (error "Priority commands are disabled"))
  7546. (org-agenda-check-no-diary)
  7547. (let* ((marker (or (org-get-at-bol 'org-marker)
  7548. (org-agenda-error)))
  7549. (hdmarker (org-get-at-bol 'org-hd-marker))
  7550. (buffer (marker-buffer hdmarker))
  7551. (pos (marker-position hdmarker))
  7552. (inhibit-read-only t)
  7553. newhead)
  7554. (org-with-remote-undo buffer
  7555. (with-current-buffer buffer
  7556. (widen)
  7557. (goto-char pos)
  7558. (org-show-context 'agenda)
  7559. (save-excursion
  7560. (and (outline-next-heading)
  7561. (org-flag-heading nil))) ; show the next heading
  7562. (funcall 'org-priority force-direction)
  7563. (end-of-line 1)
  7564. (setq newhead (org-get-heading)))
  7565. (org-agenda-change-all-lines newhead hdmarker)
  7566. (beginning-of-line 1))))
  7567. ;; FIXME: should fix the tags property of the agenda line.
  7568. (defun org-agenda-set-tags (&optional tag onoff)
  7569. "Set tags for the current headline."
  7570. (interactive)
  7571. (org-agenda-check-no-diary)
  7572. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7573. (call-interactively 'org-change-tag-in-region)
  7574. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7575. (org-agenda-error)))
  7576. (buffer (marker-buffer hdmarker))
  7577. (pos (marker-position hdmarker))
  7578. (inhibit-read-only t)
  7579. newhead)
  7580. (org-with-remote-undo buffer
  7581. (with-current-buffer buffer
  7582. (widen)
  7583. (goto-char pos)
  7584. (save-excursion
  7585. (org-show-context 'agenda))
  7586. (save-excursion
  7587. (and (outline-next-heading)
  7588. (org-flag-heading nil))) ; show the next heading
  7589. (goto-char pos)
  7590. (if tag
  7591. (org-toggle-tag tag onoff)
  7592. (call-interactively 'org-set-tags))
  7593. (end-of-line 1)
  7594. (setq newhead (org-get-heading)))
  7595. (org-agenda-change-all-lines newhead hdmarker)
  7596. (beginning-of-line 1)))))
  7597. (defun org-agenda-set-property ()
  7598. "Set a property for the current headline."
  7599. (interactive)
  7600. (org-agenda-check-no-diary)
  7601. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7602. (org-agenda-error)))
  7603. (buffer (marker-buffer hdmarker))
  7604. (pos (marker-position hdmarker))
  7605. (inhibit-read-only t)
  7606. newhead)
  7607. (org-with-remote-undo buffer
  7608. (with-current-buffer buffer
  7609. (widen)
  7610. (goto-char pos)
  7611. (save-excursion
  7612. (org-show-context 'agenda))
  7613. (save-excursion
  7614. (and (outline-next-heading)
  7615. (org-flag-heading nil))) ; show the next heading
  7616. (goto-char pos)
  7617. (call-interactively 'org-set-property)))))
  7618. (defun org-agenda-set-effort ()
  7619. "Set the effort property for the current headline."
  7620. (interactive)
  7621. (org-agenda-check-no-diary)
  7622. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7623. (org-agenda-error)))
  7624. (buffer (marker-buffer hdmarker))
  7625. (pos (marker-position hdmarker))
  7626. (inhibit-read-only t)
  7627. newhead)
  7628. (org-with-remote-undo buffer
  7629. (with-current-buffer buffer
  7630. (widen)
  7631. (goto-char pos)
  7632. (save-excursion
  7633. (org-show-context 'agenda))
  7634. (save-excursion
  7635. (and (outline-next-heading)
  7636. (org-flag-heading nil))) ; show the next heading
  7637. (goto-char pos)
  7638. (call-interactively 'org-set-effort)
  7639. (end-of-line 1)
  7640. (setq newhead (org-get-heading)))
  7641. (org-agenda-change-all-lines newhead hdmarker))))
  7642. (defun org-agenda-toggle-archive-tag ()
  7643. "Toggle the archive tag for the current entry."
  7644. (interactive)
  7645. (org-agenda-check-no-diary)
  7646. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7647. (org-agenda-error)))
  7648. (buffer (marker-buffer hdmarker))
  7649. (pos (marker-position hdmarker))
  7650. (inhibit-read-only t)
  7651. newhead)
  7652. (org-with-remote-undo buffer
  7653. (with-current-buffer buffer
  7654. (widen)
  7655. (goto-char pos)
  7656. (org-show-context 'agenda)
  7657. (save-excursion
  7658. (and (outline-next-heading)
  7659. (org-flag-heading nil))) ; show the next heading
  7660. (call-interactively 'org-toggle-archive-tag)
  7661. (end-of-line 1)
  7662. (setq newhead (org-get-heading)))
  7663. (org-agenda-change-all-lines newhead hdmarker)
  7664. (beginning-of-line 1))))
  7665. (defun org-agenda-do-date-later (arg)
  7666. (interactive "P")
  7667. (cond
  7668. ((or (equal arg '(16))
  7669. (memq last-command
  7670. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7671. (setq this-command 'org-agenda-date-later-minutes)
  7672. (org-agenda-date-later-minutes 1))
  7673. ((or (equal arg '(4))
  7674. (memq last-command
  7675. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7676. (setq this-command 'org-agenda-date-later-hours)
  7677. (org-agenda-date-later-hours 1))
  7678. (t
  7679. (org-agenda-date-later (prefix-numeric-value arg)))))
  7680. (defun org-agenda-do-date-earlier (arg)
  7681. (interactive "P")
  7682. (cond
  7683. ((or (equal arg '(16))
  7684. (memq last-command
  7685. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7686. (setq this-command 'org-agenda-date-earlier-minutes)
  7687. (org-agenda-date-earlier-minutes 1))
  7688. ((or (equal arg '(4))
  7689. (memq last-command
  7690. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7691. (setq this-command 'org-agenda-date-earlier-hours)
  7692. (org-agenda-date-earlier-hours 1))
  7693. (t
  7694. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7695. (defun org-agenda-date-later (arg &optional what)
  7696. "Change the date of this item to ARG day(s) later."
  7697. (interactive "p")
  7698. (org-agenda-check-type t 'agenda 'timeline)
  7699. (org-agenda-check-no-diary)
  7700. (let* ((marker (or (org-get-at-bol 'org-marker)
  7701. (org-agenda-error)))
  7702. (buffer (marker-buffer marker))
  7703. (pos (marker-position marker))
  7704. cdate today)
  7705. (org-with-remote-undo buffer
  7706. (with-current-buffer buffer
  7707. (widen)
  7708. (goto-char pos)
  7709. (if (not (org-at-timestamp-p))
  7710. (error "Cannot find time stamp"))
  7711. (when (and org-agenda-move-date-from-past-immediately-to-today
  7712. (equal arg 1)
  7713. (or (not what) (eq what 'day))
  7714. (not (save-match-data (org-at-date-range-p))))
  7715. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7716. cdate (calendar-absolute-from-gregorian
  7717. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7718. today (org-today))
  7719. (if (> today cdate)
  7720. ;; immediately shift to today
  7721. (setq arg (- today cdate))))
  7722. (org-timestamp-change arg (or what 'day))
  7723. (when (and (org-at-date-range-p)
  7724. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7725. (let ((end org-last-changed-timestamp))
  7726. (org-timestamp-change arg (or what 'day))
  7727. (setq org-last-changed-timestamp
  7728. (concat org-last-changed-timestamp "--" end)))))
  7729. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7730. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7731. (defun org-agenda-date-earlier (arg &optional what)
  7732. "Change the date of this item to ARG day(s) earlier."
  7733. (interactive "p")
  7734. (org-agenda-date-later (- arg) what))
  7735. (defun org-agenda-date-later-minutes (arg)
  7736. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7737. (interactive "p")
  7738. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7739. (org-agenda-date-later arg 'minute))
  7740. (defun org-agenda-date-earlier-minutes (arg)
  7741. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7742. (interactive "p")
  7743. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7744. (org-agenda-date-earlier arg 'minute))
  7745. (defun org-agenda-date-later-hours (arg)
  7746. "Change the time of this item, in hour steps."
  7747. (interactive "p")
  7748. (org-agenda-date-later arg 'hour))
  7749. (defun org-agenda-date-earlier-hours (arg)
  7750. "Change the time of this item, in hour steps."
  7751. (interactive "p")
  7752. (org-agenda-date-earlier arg 'hour))
  7753. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7754. "Show new date stamp via text properties."
  7755. ;; We use text properties to make this undoable
  7756. (let ((inhibit-read-only t)
  7757. (buffer-invisibility-spec))
  7758. (setq stamp (concat " " prefix " => " stamp))
  7759. (save-excursion
  7760. (goto-char (point-max))
  7761. (while (not (bobp))
  7762. (when (equal marker (org-get-at-bol 'org-marker))
  7763. (org-move-to-column (- (window-width) (length stamp)) t)
  7764. (org-agenda-fix-tags-filter-overlays-at (point))
  7765. (if (featurep 'xemacs)
  7766. ;; Use `duplicable' property to trigger undo recording
  7767. (let ((ex (make-extent nil nil))
  7768. (gl (make-glyph stamp)))
  7769. (set-glyph-face gl 'secondary-selection)
  7770. (set-extent-properties
  7771. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7772. (insert-extent ex (1- (point)) (point-at-eol)))
  7773. (add-text-properties
  7774. (1- (point)) (point-at-eol)
  7775. (list 'display (org-add-props stamp nil
  7776. 'face 'secondary-selection))))
  7777. (beginning-of-line 1))
  7778. (beginning-of-line 0)))))
  7779. (defun org-agenda-date-prompt (arg)
  7780. "Change the date of this item. Date is prompted for, with default today.
  7781. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7782. be used to request time specification in the time stamp."
  7783. (interactive "P")
  7784. (org-agenda-check-type t 'agenda 'timeline)
  7785. (org-agenda-check-no-diary)
  7786. (let* ((marker (or (org-get-at-bol 'org-marker)
  7787. (org-agenda-error)))
  7788. (buffer (marker-buffer marker))
  7789. (pos (marker-position marker)))
  7790. (org-with-remote-undo buffer
  7791. (with-current-buffer buffer
  7792. (widen)
  7793. (goto-char pos)
  7794. (if (not (org-at-timestamp-p t))
  7795. (error "Cannot find time stamp"))
  7796. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7797. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7798. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7799. (defun org-agenda-schedule (arg &optional time)
  7800. "Schedule the item at point.
  7801. ARG is passed through to `org-schedule'."
  7802. (interactive "P")
  7803. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7804. (org-agenda-check-no-diary)
  7805. (let* ((marker (or (org-get-at-bol 'org-marker)
  7806. (org-agenda-error)))
  7807. (type (marker-insertion-type marker))
  7808. (buffer (marker-buffer marker))
  7809. (pos (marker-position marker))
  7810. (org-insert-labeled-timestamps-at-point nil)
  7811. ts)
  7812. (set-marker-insertion-type marker t)
  7813. (org-with-remote-undo buffer
  7814. (with-current-buffer buffer
  7815. (widen)
  7816. (goto-char pos)
  7817. (setq ts (org-schedule arg time)))
  7818. (org-agenda-show-new-time marker ts "S"))
  7819. (message "Item scheduled for %s" ts)))
  7820. (defun org-agenda-deadline (arg &optional time)
  7821. "Schedule the item at point.
  7822. ARG is passed through to `org-deadline'."
  7823. (interactive "P")
  7824. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7825. (org-agenda-check-no-diary)
  7826. (let* ((marker (or (org-get-at-bol 'org-marker)
  7827. (org-agenda-error)))
  7828. (buffer (marker-buffer marker))
  7829. (pos (marker-position marker))
  7830. (org-insert-labeled-timestamps-at-point nil)
  7831. ts)
  7832. (org-with-remote-undo buffer
  7833. (with-current-buffer buffer
  7834. (widen)
  7835. (goto-char pos)
  7836. (setq ts (org-deadline arg time)))
  7837. (org-agenda-show-new-time marker ts "D"))
  7838. (message "Deadline for this item set to %s" ts)))
  7839. (defun org-agenda-clock-in (&optional arg)
  7840. "Start the clock on the currently selected item."
  7841. (interactive "P")
  7842. (org-agenda-check-no-diary)
  7843. (if (equal arg '(4))
  7844. (org-clock-in arg)
  7845. (let* ((marker (or (org-get-at-bol 'org-marker)
  7846. (org-agenda-error)))
  7847. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7848. marker))
  7849. (pos (marker-position marker))
  7850. newhead)
  7851. (org-with-remote-undo (marker-buffer marker)
  7852. (with-current-buffer (marker-buffer marker)
  7853. (widen)
  7854. (goto-char pos)
  7855. (org-show-context 'agenda)
  7856. (org-show-entry)
  7857. (org-cycle-hide-drawers 'children)
  7858. (org-clock-in arg)
  7859. (setq newhead (org-get-heading)))
  7860. (org-agenda-change-all-lines newhead hdmarker)))))
  7861. (defun org-agenda-clock-out ()
  7862. "Stop the currently running clock."
  7863. (interactive)
  7864. (unless (marker-buffer org-clock-marker)
  7865. (error "No running clock"))
  7866. (let ((marker (make-marker)) newhead)
  7867. (org-with-remote-undo (marker-buffer org-clock-marker)
  7868. (with-current-buffer (marker-buffer org-clock-marker)
  7869. (save-excursion
  7870. (save-restriction
  7871. (widen)
  7872. (goto-char org-clock-marker)
  7873. (org-back-to-heading t)
  7874. (move-marker marker (point))
  7875. (org-clock-out)
  7876. (setq newhead (org-get-heading))))))
  7877. (org-agenda-change-all-lines newhead marker)
  7878. (move-marker marker nil)))
  7879. (defun org-agenda-clock-cancel (&optional arg)
  7880. "Cancel the currently running clock."
  7881. (interactive "P")
  7882. (unless (marker-buffer org-clock-marker)
  7883. (error "No running clock"))
  7884. (org-with-remote-undo (marker-buffer org-clock-marker)
  7885. (org-clock-cancel)))
  7886. (defun org-agenda-clock-goto ()
  7887. "Jump to the currently clocked in task within the agenda.
  7888. If the currently clocked in task is not listed in the agenda
  7889. buffer, display it in another window."
  7890. (interactive)
  7891. (let (pos)
  7892. (mapc (lambda (o)
  7893. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7894. (setq pos (overlay-start o))))
  7895. (overlays-in (point-min) (point-max)))
  7896. (cond (pos (goto-char pos))
  7897. ;; If the currently clocked entry is not in the agenda
  7898. ;; buffer, we visit it in another window:
  7899. (org-clock-current-task
  7900. (org-switch-to-buffer-other-window (org-clock-goto)))
  7901. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7902. (defun org-agenda-diary-entry-in-org-file ()
  7903. "Make a diary entry in the file `org-agenda-diary-file'."
  7904. (let (d1 d2 char (text "") dp1 dp2)
  7905. (if (equal (buffer-name) "*Calendar*")
  7906. (setq d1 (calendar-cursor-to-date t)
  7907. d2 (car calendar-mark-ring))
  7908. (setq dp1 (get-text-property (point-at-bol) 'day))
  7909. (unless dp1 (error "No date defined in current line"))
  7910. (setq d1 (calendar-gregorian-from-absolute dp1)
  7911. d2 (and (ignore-errors (mark))
  7912. (save-excursion
  7913. (goto-char (mark))
  7914. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7915. (calendar-gregorian-from-absolute dp2))))
  7916. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7917. (setq char (read-char-exclusive))
  7918. (cond
  7919. ((equal char ?d)
  7920. (setq text (read-string "Day entry: "))
  7921. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7922. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7923. ((equal char ?a)
  7924. (setq d1 (list (car d1) (nth 1 d1)
  7925. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7926. (nth 2 d1))))
  7927. (setq text (read-string "Anniversary (use %d to show years): "))
  7928. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7929. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7930. ((equal char ?b)
  7931. (setq text (read-string "Block entry: "))
  7932. (unless (and d1 d2 (not (equal d1 d2)))
  7933. (error "No block of days selected"))
  7934. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7935. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7936. ((equal char ?j)
  7937. (org-switch-to-buffer-other-window
  7938. (find-file-noselect org-agenda-diary-file))
  7939. (require 'org-datetree)
  7940. (org-datetree-find-date-create d1)
  7941. (org-reveal t))
  7942. (t (error "Invalid selection character `%c'" char)))))
  7943. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7944. "Where in `org-agenda-diary-file' should new entries be added?
  7945. Valid values:
  7946. date-tree in the date tree, as child of the date
  7947. top-level as top-level entries at the end of the file."
  7948. :group 'org-agenda
  7949. :type '(choice
  7950. (const :tag "in a date tree" date-tree)
  7951. (const :tag "as top level at end of file" top-level)))
  7952. (defcustom org-agenda-insert-diary-extract-time nil
  7953. "Non-nil means extract any time specification from the diary entry."
  7954. :group 'org-agenda
  7955. :version "24.1"
  7956. :type 'boolean)
  7957. (defcustom org-agenda-bulk-mark-char ">"
  7958. "A single-character string to be used as the bulk mark."
  7959. :group 'org-agenda
  7960. :version "24.1"
  7961. :type 'string)
  7962. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7963. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7964. If TEXT is not empty, it will become the headline of the new entry, and
  7965. the resulting entry will not be shown. When TEXT is empty, switch to
  7966. `org-agenda-diary-file' and let the user finish the entry there."
  7967. (let ((cw (current-window-configuration)))
  7968. (org-switch-to-buffer-other-window
  7969. (find-file-noselect org-agenda-diary-file))
  7970. (widen)
  7971. (goto-char (point-min))
  7972. (cond
  7973. ((eq type 'anniversary)
  7974. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7975. (progn
  7976. (or (org-at-heading-p t)
  7977. (progn
  7978. (outline-next-heading)
  7979. (insert "* Anniversaries\n\n")
  7980. (beginning-of-line -1)))))
  7981. (outline-next-heading)
  7982. (org-back-over-empty-lines)
  7983. (backward-char 1)
  7984. (insert "\n")
  7985. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7986. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7987. ((eq type 'day)
  7988. (let ((org-prefix-has-time t)
  7989. (org-agenda-time-leading-zero t)
  7990. fmt time time2)
  7991. (if org-agenda-insert-diary-extract-time
  7992. ;; Use org-agenda-format-item to parse text for a time-range and
  7993. ;; remove it. FIXME: This is a hack, we should refactor
  7994. ;; that function to make time extraction available separately
  7995. (setq fmt (org-agenda-format-item nil text nil nil nil t)
  7996. time (get-text-property 0 'time fmt)
  7997. time2 (if (> (length time) 0)
  7998. ;; split-string removes trailing ...... if
  7999. ;; no end time given. First space
  8000. ;; separates time from date.
  8001. (concat " " (car (split-string time "\\.")))
  8002. nil)
  8003. text (get-text-property 0 'txt fmt)))
  8004. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8005. (org-agenda-insert-diary-as-top-level text)
  8006. (require 'org-datetree)
  8007. (org-datetree-find-date-create d1)
  8008. (org-agenda-insert-diary-make-new-entry text))
  8009. (org-insert-time-stamp (org-time-from-absolute
  8010. (calendar-absolute-from-gregorian d1))
  8011. nil nil nil nil time2))
  8012. (end-of-line 0))
  8013. ((eq type 'block)
  8014. (if (> (calendar-absolute-from-gregorian d1)
  8015. (calendar-absolute-from-gregorian d2))
  8016. (setq d1 (prog1 d2 (setq d2 d1))))
  8017. (if (eq org-agenda-insert-diary-strategy 'top-level)
  8018. (org-agenda-insert-diary-as-top-level text)
  8019. (require 'org-datetree)
  8020. (org-datetree-find-date-create d1)
  8021. (org-agenda-insert-diary-make-new-entry text))
  8022. (org-insert-time-stamp (org-time-from-absolute
  8023. (calendar-absolute-from-gregorian d1)))
  8024. (insert "--")
  8025. (org-insert-time-stamp (org-time-from-absolute
  8026. (calendar-absolute-from-gregorian d2)))
  8027. (end-of-line 0)))
  8028. (if (string-match "\\S-" text)
  8029. (progn
  8030. (set-window-configuration cw)
  8031. (message "%s entry added to %s"
  8032. (capitalize (symbol-name type))
  8033. (abbreviate-file-name org-agenda-diary-file)))
  8034. (org-reveal t)
  8035. (message "Please finish entry here"))))
  8036. (defun org-agenda-insert-diary-as-top-level (text)
  8037. "Make new entry as a top-level entry at the end of the file.
  8038. Add TEXT as headline, and position the cursor in the second line so that
  8039. a timestamp can be added there."
  8040. (widen)
  8041. (goto-char (point-max))
  8042. (or (bolp) (insert "\n"))
  8043. (insert "* " text "\n")
  8044. (if org-adapt-indentation (org-indent-to-column 2)))
  8045. (defun org-agenda-insert-diary-make-new-entry (text)
  8046. "Make new entry as last child of current entry.
  8047. Add TEXT as headline, and position the cursor in the second line so that
  8048. a timestamp can be added there."
  8049. (let ((org-show-following-heading t)
  8050. (org-show-siblings t)
  8051. (org-show-hierarchy-above t)
  8052. (org-show-entry-below t)
  8053. col)
  8054. (outline-next-heading)
  8055. (org-back-over-empty-lines)
  8056. (or (looking-at "[ \t]*$")
  8057. (progn (insert "\n") (backward-char 1)))
  8058. (org-insert-heading nil t)
  8059. (org-do-demote)
  8060. (setq col (current-column))
  8061. (insert text "\n")
  8062. (if org-adapt-indentation (org-indent-to-column col))
  8063. (let ((org-show-following-heading t)
  8064. (org-show-siblings t)
  8065. (org-show-hierarchy-above t)
  8066. (org-show-entry-below t))
  8067. (org-show-context))))
  8068. (defun org-agenda-diary-entry ()
  8069. "Make a diary entry, like the `i' command from the calendar.
  8070. All the standard commands work: block, weekly etc.
  8071. When `org-agenda-diary-file' points to a file,
  8072. `org-agenda-diary-entry-in-org-file' is called instead to create
  8073. entries in that Org-mode file."
  8074. (interactive)
  8075. (org-agenda-check-type t 'agenda 'timeline)
  8076. (if (not (eq org-agenda-diary-file 'diary-file))
  8077. (org-agenda-diary-entry-in-org-file)
  8078. (require 'diary-lib)
  8079. (let* ((char (progn
  8080. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  8081. (read-char-exclusive)))
  8082. (cmd (cdr (assoc char
  8083. '((?d . insert-diary-entry)
  8084. (?w . insert-weekly-diary-entry)
  8085. (?m . insert-monthly-diary-entry)
  8086. (?y . insert-yearly-diary-entry)
  8087. (?a . insert-anniversary-diary-entry)
  8088. (?b . insert-block-diary-entry)
  8089. (?c . insert-cyclic-diary-entry)))))
  8090. (oldf (symbol-function 'calendar-cursor-to-date))
  8091. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  8092. (point (point))
  8093. (mark (or (mark t) (point))))
  8094. (unless cmd
  8095. (error "No command associated with <%c>" char))
  8096. (unless (and (get-text-property point 'day)
  8097. (or (not (equal ?b char))
  8098. (get-text-property mark 'day)))
  8099. (error "Don't know which date to use for diary entry"))
  8100. ;; We implement this by hacking the `calendar-cursor-to-date' function
  8101. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  8102. (let ((calendar-mark-ring
  8103. (list (calendar-gregorian-from-absolute
  8104. (or (get-text-property mark 'day)
  8105. (get-text-property point 'day))))))
  8106. (unwind-protect
  8107. (progn
  8108. (fset 'calendar-cursor-to-date
  8109. (lambda (&optional error dummy)
  8110. (calendar-gregorian-from-absolute
  8111. (get-text-property point 'day))))
  8112. (call-interactively cmd))
  8113. (fset 'calendar-cursor-to-date oldf))))))
  8114. (defun org-agenda-execute-calendar-command (cmd)
  8115. "Execute a calendar command from the agenda, with the date associated to
  8116. the cursor position."
  8117. (org-agenda-check-type t 'agenda 'timeline)
  8118. (require 'diary-lib)
  8119. (unless (get-text-property (point) 'day)
  8120. (error "Don't know which date to use for calendar command"))
  8121. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  8122. (point (point))
  8123. (date (calendar-gregorian-from-absolute
  8124. (get-text-property point 'day)))
  8125. ;; the following 2 vars are needed in the calendar
  8126. (displayed-month (car date))
  8127. (displayed-year (nth 2 date)))
  8128. (unwind-protect
  8129. (progn
  8130. (fset 'calendar-cursor-to-date
  8131. (lambda (&optional error dummy)
  8132. (calendar-gregorian-from-absolute
  8133. (get-text-property point 'day))))
  8134. (call-interactively cmd))
  8135. (fset 'calendar-cursor-to-date oldf))))
  8136. (defun org-agenda-phases-of-moon ()
  8137. "Display the phases of the moon for the 3 months around the cursor date."
  8138. (interactive)
  8139. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  8140. (defun org-agenda-holidays ()
  8141. "Display the holidays for the 3 months around the cursor date."
  8142. (interactive)
  8143. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  8144. (defvar calendar-longitude) ; defined in calendar.el
  8145. (defvar calendar-latitude) ; defined in calendar.el
  8146. (defvar calendar-location-name) ; defined in calendar.el
  8147. (defun org-agenda-sunrise-sunset (arg)
  8148. "Display sunrise and sunset for the cursor date.
  8149. Latitude and longitude can be specified with the variables
  8150. `calendar-latitude' and `calendar-longitude'. When called with prefix
  8151. argument, latitude and longitude will be prompted for."
  8152. (interactive "P")
  8153. (require 'solar)
  8154. (let ((calendar-longitude (if arg nil calendar-longitude))
  8155. (calendar-latitude (if arg nil calendar-latitude))
  8156. (calendar-location-name
  8157. (if arg "the given coordinates" calendar-location-name)))
  8158. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  8159. (defun org-agenda-goto-calendar ()
  8160. "Open the Emacs calendar with the date at the cursor."
  8161. (interactive)
  8162. (org-agenda-check-type t 'agenda 'timeline)
  8163. (let* ((day (or (get-text-property (point) 'day)
  8164. (error "Don't know which date to open in calendar")))
  8165. (date (calendar-gregorian-from-absolute day))
  8166. (calendar-move-hook nil)
  8167. (calendar-view-holidays-initially-flag nil)
  8168. (calendar-view-diary-initially-flag nil))
  8169. (calendar)
  8170. (calendar-goto-date date)))
  8171. ;;;###autoload
  8172. (defun org-calendar-goto-agenda ()
  8173. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  8174. This is a command that has to be installed in `calendar-mode-map'."
  8175. (interactive)
  8176. (org-agenda-list nil (calendar-absolute-from-gregorian
  8177. (calendar-cursor-to-date))
  8178. nil))
  8179. (defun org-agenda-convert-date ()
  8180. (interactive)
  8181. (org-agenda-check-type t 'agenda 'timeline)
  8182. (let ((day (get-text-property (point) 'day))
  8183. date s)
  8184. (unless day
  8185. (error "Don't know which date to convert"))
  8186. (setq date (calendar-gregorian-from-absolute day))
  8187. (setq s (concat
  8188. "Gregorian: " (calendar-date-string date) "\n"
  8189. "ISO: " (calendar-iso-date-string date) "\n"
  8190. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  8191. "Julian: " (calendar-julian-date-string date) "\n"
  8192. "Astron. JD: " (calendar-astro-date-string date)
  8193. " (Julian date number at noon UTC)\n"
  8194. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  8195. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  8196. "French: " (calendar-french-date-string date) "\n"
  8197. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  8198. "Mayan: " (calendar-mayan-date-string date) "\n"
  8199. "Coptic: " (calendar-coptic-date-string date) "\n"
  8200. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  8201. "Persian: " (calendar-persian-date-string date) "\n"
  8202. "Chinese: " (calendar-chinese-date-string date) "\n"))
  8203. (with-output-to-temp-buffer "*Dates*"
  8204. (princ s))
  8205. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  8206. ;;; Bulk commands
  8207. (defun org-agenda-bulk-marked-p ()
  8208. (eq (get-char-property (point-at-bol) 'type)
  8209. 'org-marked-entry-overlay))
  8210. (defun org-agenda-bulk-mark (&optional arg)
  8211. "Mark the entry at point for future bulk action."
  8212. (interactive "p")
  8213. (dotimes (i (or arg 1))
  8214. (unless (org-get-at-bol 'org-agenda-diary-link)
  8215. (let* ((m (org-get-at-bol 'org-hd-marker))
  8216. ov)
  8217. (unless (org-agenda-bulk-marked-p)
  8218. (unless m (error "Nothing to mark at point"))
  8219. (push m org-agenda-bulk-marked-entries)
  8220. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  8221. (org-overlay-display ov (concat org-agenda-bulk-mark-char " ")
  8222. (org-get-todo-face "TODO")
  8223. 'evaporate)
  8224. (overlay-put ov 'type 'org-marked-entry-overlay))
  8225. (beginning-of-line 2)
  8226. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8227. (beginning-of-line 2))
  8228. (message "%d entries marked for bulk action"
  8229. (length org-agenda-bulk-marked-entries))))))
  8230. (defun org-agenda-bulk-mark-all ()
  8231. "Mark all entries for future agenda bulk action."
  8232. (interactive)
  8233. (org-agenda-bulk-mark-regexp "."))
  8234. (defun org-agenda-bulk-mark-regexp (regexp)
  8235. "Mark entries matching REGEXP for future agenda bulk action."
  8236. (interactive "sMark entries matching regexp: ")
  8237. (let ((entries-marked 0))
  8238. (save-excursion
  8239. (goto-char (point-min))
  8240. (goto-char (next-single-property-change (point) 'txt))
  8241. (while (re-search-forward regexp nil t)
  8242. (when (string-match regexp (get-text-property (point) 'txt))
  8243. (setq entries-marked (1+ entries-marked))
  8244. (call-interactively 'org-agenda-bulk-mark))))
  8245. (if (not entries-marked)
  8246. (message "No entry matching this regexp."))))
  8247. (defun org-agenda-bulk-unmark (&optional arg)
  8248. "Unmark the entry at point for future bulk action."
  8249. (interactive "P")
  8250. (if arg
  8251. (org-agenda-bulk-unmark-all)
  8252. (cond ((org-agenda-bulk-marked-p)
  8253. (org-agenda-bulk-remove-overlays
  8254. (point-at-bol) (+ 2 (point-at-bol)))
  8255. (setq org-agenda-bulk-marked-entries
  8256. (delete (org-get-at-bol 'org-hd-marker)
  8257. org-agenda-bulk-marked-entries))
  8258. (beginning-of-line 2)
  8259. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  8260. (beginning-of-line 2))
  8261. (message "%d entries left marked for bulk action"
  8262. (length org-agenda-bulk-marked-entries)))
  8263. (t (message "No entry to unmark here")))))
  8264. (defun org-agenda-bulk-toggle ()
  8265. "Toggle marking the entry at point for bulk action."
  8266. (interactive)
  8267. (if (org-agenda-bulk-marked-p)
  8268. (org-agenda-bulk-unmark)
  8269. (org-agenda-bulk-mark)))
  8270. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  8271. "Remove the mark overlays between BEG and END in the agenda buffer.
  8272. BEG and END default to the buffer limits.
  8273. This only removes the overlays, it does not remove the markers
  8274. from the list in `org-agenda-bulk-marked-entries'."
  8275. (interactive)
  8276. (mapc (lambda (ov)
  8277. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  8278. (delete-overlay ov)))
  8279. (overlays-in (or beg (point-min)) (or end (point-max)))))
  8280. (defun org-agenda-bulk-unmark-all ()
  8281. "Remove all marks in the agenda buffer.
  8282. This will remove the markers and the overlays."
  8283. (interactive)
  8284. (if (null org-agenda-bulk-marked-entries)
  8285. (message "No entry to unmark")
  8286. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  8287. (setq org-agenda-bulk-marked-entries nil)
  8288. (org-agenda-bulk-remove-overlays (point-min) (point-max))))
  8289. (defcustom org-agenda-persistent-marks nil
  8290. "Non-nil means marked items will stay marked after a bulk action.
  8291. You can toggle this interactively by typing `p' when prompted for a
  8292. bulk action."
  8293. :group 'org-agenda
  8294. :version "24.1"
  8295. :type 'boolean)
  8296. (defun org-agenda-bulk-action (&optional arg)
  8297. "Execute an remote-editing action on all marked entries.
  8298. The prefix arg is passed through to the command if possible."
  8299. (interactive "P")
  8300. ;; Make sure we have markers, and only valid ones
  8301. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  8302. (mapc
  8303. (lambda (m)
  8304. (unless (and (markerp m)
  8305. (marker-buffer m)
  8306. (buffer-live-p (marker-buffer m))
  8307. (marker-position m))
  8308. (error "Marker %s for bulk command is invalid" m)))
  8309. org-agenda-bulk-marked-entries)
  8310. ;; Prompt for the bulk command
  8311. (let* ((msg (if org-agenda-persistent-marks "Bulk (persistent): " "Bulk: ")))
  8312. (message (concat msg "[$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [d]eadline [r]efile "
  8313. "[S]catter [f]unction "
  8314. (when org-agenda-bulk-custom-functions
  8315. (concat " Custom: ["
  8316. (mapconcat (lambda(f) (char-to-string (car f)))
  8317. org-agenda-bulk-custom-functions "")
  8318. "]"))))
  8319. (catch 'exit
  8320. (let* ((action (read-char-exclusive))
  8321. (org-log-refile (if org-log-refile 'time nil))
  8322. (entries (reverse org-agenda-bulk-marked-entries))
  8323. (org-overriding-default-time
  8324. (if (get-text-property (point) 'org-agenda-date-header)
  8325. (org-get-cursor-date)))
  8326. redo-at-end
  8327. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  8328. (cond
  8329. ((equal action ?p)
  8330. (let ((org-agenda-persistent-marks
  8331. (not org-agenda-persistent-marks)))
  8332. (org-agenda-bulk-action)
  8333. (throw 'exit nil)))
  8334. ((equal action ?$)
  8335. (setq cmd '(org-agenda-archive)))
  8336. ((equal action ?A)
  8337. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8338. ((member action '(?r ?w))
  8339. (setq rfloc (org-refile-get-location
  8340. "Refile to"
  8341. (marker-buffer (car entries))
  8342. org-refile-allow-creating-parent-nodes))
  8343. (if (nth 3 rfloc)
  8344. (setcar (nthcdr 3 rfloc)
  8345. (move-marker (make-marker) (nth 3 rfloc)
  8346. (or (get-file-buffer (nth 1 rfloc))
  8347. (find-buffer-visiting (nth 1 rfloc))
  8348. (error "This should not happen")))))
  8349. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8350. redo-at-end t))
  8351. ((equal action ?t)
  8352. (setq state (org-icompleting-read
  8353. "Todo state: "
  8354. (with-current-buffer (marker-buffer (car entries))
  8355. (mapcar 'list org-todo-keywords-1))))
  8356. (setq cmd `(let ((org-inhibit-blocking t)
  8357. (org-inhibit-logging 'note))
  8358. (org-agenda-todo ,state))))
  8359. ((memq action '(?- ?+))
  8360. (setq tag (org-icompleting-read
  8361. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8362. (with-current-buffer (marker-buffer (car entries))
  8363. (delq nil
  8364. (mapcar (lambda (x)
  8365. (if (stringp (car x)) x)) org-tag-alist)))))
  8366. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8367. ((memq action '(?s ?d))
  8368. (let* ((date
  8369. (unless arg
  8370. (or org-overriding-default-time
  8371. (and (org-read-date
  8372. nil nil nil
  8373. (if (eq action ?s) "(Re)Schedule to" "(Re)Set Deadline to"))
  8374. (or (ignore-errors
  8375. (org-time-string-to-time org-read-date-final-answer))
  8376. (current-time))))))
  8377. (date (format-time-string (car org-time-stamp-formats) date))
  8378. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8379. (setq cmd `(let* ((bound (fboundp 'read-string))
  8380. (old (and bound (symbol-function 'read-string))))
  8381. (unwind-protect
  8382. (progn
  8383. (fset 'read-string (lambda (&rest ignore) ,date))
  8384. (eval '(,c1 arg)))
  8385. (if bound
  8386. (fset 'read-string old)
  8387. (fmakunbound 'read-string)))))))
  8388. ((equal action ?S)
  8389. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8390. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8391. (let ((days (read-number
  8392. (format "Scatter tasks across how many %sdays: "
  8393. (if arg "week" "")) 7)))
  8394. (setq cmd
  8395. `(let ((distance (1+ (random ,days))))
  8396. (if arg
  8397. (let ((dist distance)
  8398. (day-of-week
  8399. (calendar-day-of-week
  8400. (calendar-gregorian-from-absolute (org-today)))))
  8401. (dotimes (i (1+ dist))
  8402. (while (member day-of-week org-agenda-weekend-days)
  8403. (incf distance)
  8404. (incf day-of-week)
  8405. (if (= day-of-week 7)
  8406. (setq day-of-week 0)))
  8407. (incf day-of-week)
  8408. (if (= day-of-week 7)
  8409. (setq day-of-week 0)))))
  8410. ;; silently fail when try to replan a sexp entry
  8411. (condition-case nil
  8412. (let* ((date (calendar-gregorian-from-absolute
  8413. (+ (org-today) distance)))
  8414. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8415. (nth 2 date))))
  8416. (org-agenda-schedule nil time))
  8417. (error nil)))))))
  8418. ((assoc action org-agenda-bulk-custom-functions)
  8419. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8420. redo-at-end t))
  8421. ((equal action ?f)
  8422. (setq cmd (list (intern
  8423. (org-icompleting-read "Function: "
  8424. obarray 'fboundp t nil nil)))))
  8425. (t (error "Invalid bulk action")))
  8426. ;; Sort the markers, to make sure that parents are handled before children
  8427. (setq entries (sort entries
  8428. (lambda (a b)
  8429. (cond
  8430. ((equal (marker-buffer a) (marker-buffer b))
  8431. (< (marker-position a) (marker-position b)))
  8432. (t
  8433. (string< (buffer-name (marker-buffer a))
  8434. (buffer-name (marker-buffer b))))))))
  8435. ;; Now loop over all markers and apply cmd
  8436. (while (setq e (pop entries))
  8437. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8438. (if (not pos)
  8439. (progn (message "Skipping removed entry at %s" e)
  8440. (setq cntskip (1+ cntskip)))
  8441. (goto-char pos)
  8442. (let (org-loop-over-headlines-in-active-region)
  8443. (eval cmd))
  8444. (setq cnt (1+ cnt))))
  8445. (when redo-at-end (org-agenda-redo))
  8446. (unless org-agenda-persistent-marks
  8447. (org-agenda-bulk-unmark-all))
  8448. (message "Acted on %d entries%s%s"
  8449. cnt
  8450. (if (= cntskip 0)
  8451. ""
  8452. (format ", skipped %d (disappeared before their turn)"
  8453. cntskip))
  8454. (if (not org-agenda-persistent-marks)
  8455. "" " (kept marked)"))))))
  8456. (defun org-agenda-capture ()
  8457. "Call `org-capture' with the date at point."
  8458. (interactive)
  8459. (if (not (eq major-mode 'org-agenda-mode))
  8460. (error "You cannot do this outside of agenda buffers")
  8461. (let ((org-overriding-default-time
  8462. (org-get-cursor-date)))
  8463. (call-interactively 'org-capture))))
  8464. ;;; Flagging notes
  8465. (defun org-agenda-show-the-flagging-note ()
  8466. "Display the flagging note in the other window.
  8467. When called a second time in direct sequence, offer to remove the FLAGGING
  8468. tag and (if present) the flagging note."
  8469. (interactive)
  8470. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8471. (win (selected-window))
  8472. note heading newhead)
  8473. (unless hdmarker
  8474. (error "No linked entry at point"))
  8475. (if (and (eq this-command last-command)
  8476. (y-or-n-p "Unflag and remove any flagging note? "))
  8477. (progn
  8478. (org-agenda-remove-flag hdmarker)
  8479. (let ((win (get-buffer-window "*Flagging Note*")))
  8480. (and win (delete-window win)))
  8481. (message "Entry unflagged"))
  8482. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8483. (unless note
  8484. (error "No flagging note"))
  8485. (org-kill-new note)
  8486. (org-switch-to-buffer-other-window "*Flagging Note*")
  8487. (erase-buffer)
  8488. (insert note)
  8489. (goto-char (point-min))
  8490. (while (re-search-forward "\\\\n" nil t)
  8491. (replace-match "\n" t t))
  8492. (goto-char (point-min))
  8493. (select-window win)
  8494. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8495. (defun org-agenda-remove-flag (marker)
  8496. "Remove the FLAGGED tag and any flagging note in the entry."
  8497. (let (newhead)
  8498. (org-with-point-at marker
  8499. (org-toggle-tag "FLAGGED" 'off)
  8500. (org-entry-delete nil "THEFLAGGINGNOTE")
  8501. (setq newhead (org-get-heading)))
  8502. (org-agenda-change-all-lines newhead marker)
  8503. (message "Entry unflagged")))
  8504. (defun org-agenda-get-any-marker (&optional pos)
  8505. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8506. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8507. ;;; Appointment reminders
  8508. (defvar appt-time-msg-list) ; defined in appt.el
  8509. ;;;###autoload
  8510. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8511. "Activate appointments found in `org-agenda-files'.
  8512. With a \\[universal-argument] prefix, refresh the list of
  8513. appointments.
  8514. If FILTER is t, interactively prompt the user for a regular
  8515. expression, and filter out entries that don't match it.
  8516. If FILTER is a string, use this string as a regular expression
  8517. for filtering entries out.
  8518. If FILTER is a function, filter out entries against which
  8519. calling the function returns nil. This function takes one
  8520. argument: an entry from `org-agenda-get-day-entries'.
  8521. FILTER can also be an alist with the car of each cell being
  8522. either 'headline or 'category. For example:
  8523. '((headline \"IMPORTANT\")
  8524. (category \"Work\"))
  8525. will only add headlines containing IMPORTANT or headlines
  8526. belonging to the \"Work\" category.
  8527. ARGS are symbols indicating what kind of entries to consider.
  8528. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8529. and :timestamp entries. See the docstring of `org-diary' for
  8530. details and examples.
  8531. If an entry as a APPT_WARNTIME property, its value will be used
  8532. to override `appt-message-warning-time'."
  8533. (interactive "P")
  8534. (if refresh (setq appt-time-msg-list nil))
  8535. (if (eq filter t)
  8536. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8537. (let* ((cnt 0) ; count added events
  8538. (scope (or args '(:deadline :scheduled :timestamp)))
  8539. (org-agenda-new-buffers nil)
  8540. (org-deadline-warning-days 0)
  8541. ;; Do not use `org-today' here because appt only takes
  8542. ;; time and without date as argument, so it may pass wrong
  8543. ;; information otherwise
  8544. (today (org-date-to-gregorian
  8545. (time-to-days (current-time))))
  8546. (org-agenda-restrict nil)
  8547. (files (org-agenda-files 'unrestricted)) entries file
  8548. (org-agenda-buffer nil))
  8549. ;; Get all entries which may contain an appt
  8550. (org-agenda-prepare-buffers files)
  8551. (while (setq file (pop files))
  8552. (setq entries
  8553. (delq nil
  8554. (append entries
  8555. (apply 'org-agenda-get-day-entries
  8556. file today scope)))))
  8557. ;; Map thru entries and find if we should filter them out
  8558. (mapc
  8559. (lambda(x)
  8560. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8561. (cat (get-text-property 1 'org-category x))
  8562. (tod (get-text-property 1 'time-of-day x))
  8563. (ok (or (null filter)
  8564. (and (stringp filter) (string-match filter evt))
  8565. (and (functionp filter) (funcall filter x))
  8566. (and (listp filter)
  8567. (let ((cat-filter (cadr (assoc 'category filter)))
  8568. (evt-filter (cadr (assoc 'headline filter))))
  8569. (or (and (stringp cat-filter)
  8570. (string-match cat-filter cat))
  8571. (and (stringp evt-filter)
  8572. (string-match evt-filter evt)))))))
  8573. (wrn (get-text-property 1 'warntime x)))
  8574. ;; FIXME: Shall we remove text-properties for the appt text?
  8575. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8576. (when (and ok tod)
  8577. (setq tod (concat "00" (number-to-string tod))
  8578. tod (when (string-match
  8579. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8580. (concat (match-string 1 tod) ":"
  8581. (match-string 2 tod))))
  8582. (if (version< emacs-version "23.3")
  8583. (appt-add tod evt)
  8584. (appt-add tod evt wrn))
  8585. (setq cnt (1+ cnt))))) entries)
  8586. (org-release-buffers org-agenda-new-buffers)
  8587. (if (eq cnt 0)
  8588. (message "No event to add")
  8589. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8590. (defun org-agenda-todayp (date)
  8591. "Does DATE mean today, when considering `org-extend-today-until'?"
  8592. (let ((today (org-today))
  8593. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8594. date)))
  8595. (eq date today)))
  8596. (defun org-agenda-todo-yesterday (&optional arg)
  8597. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday."
  8598. (interactive "P")
  8599. (let* ((hour (third (decode-time
  8600. (org-current-time))))
  8601. (org-extend-today-until (1+ hour)))
  8602. (org-agenda-todo arg)))
  8603. (provide 'org-agenda)
  8604. ;;; org-agenda.el ends here