org-agenda.el 340 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873
  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. (eval-when-compile
  43. (require 'cl))
  44. (declare-function diary-add-to-list "diary-lib"
  45. (date string specifier &optional marker globcolor literal))
  46. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  47. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  48. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  49. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  50. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  51. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  52. (declare-function calendar-french-date-string "cal-french" (&optional date))
  53. (declare-function calendar-goto-date "cal-move" (date))
  54. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  55. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  56. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  57. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  58. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  59. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  60. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  61. (declare-function calendar-check-holidays "holidays" (date))
  62. (declare-function org-datetree-find-date-create "org-datetree"
  63. (date &optional keep-restriction))
  64. (declare-function org-columns-quit "org-colview" ())
  65. (declare-function diary-date-display-form "diary-lib" (&optional type))
  66. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  67. (declare-function org-habit-insert-consistency-graphs
  68. "org-habit" (&optional line))
  69. (declare-function org-is-habit-p "org-habit" (&optional pom))
  70. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  71. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  72. (declare-function org-pop-to-buffer-same-window "org-compat"
  73. (&optional buffer-or-name norecord label))
  74. (defvar calendar-mode-map)
  75. (defvar org-clock-current-task) ; defined in org-clock.el
  76. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  77. (defvar org-habit-show-habits)
  78. (defvar org-habit-show-habits-only-for-today)
  79. ;; Defined somewhere in this file, but used before definition.
  80. (defvar org-agenda-buffer-name)
  81. (defvar org-agenda-overriding-header)
  82. (defvar org-agenda-title-append nil)
  83. (defvar entry)
  84. (defvar date)
  85. (defvar org-agenda-undo-list)
  86. (defvar org-agenda-pending-undo-list)
  87. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  88. (defcustom org-agenda-confirm-kill 1
  89. "When set, remote killing from the agenda buffer needs confirmation.
  90. When t, a confirmation is always needed. When a number N, confirmation is
  91. only needed when the text to be killed contains more than N non-white lines."
  92. :group 'org-agenda
  93. :type '(choice
  94. (const :tag "Never" nil)
  95. (const :tag "Always" t)
  96. (integer :tag "When more than N lines")))
  97. (defcustom org-agenda-compact-blocks nil
  98. "Non-nil means make the block agenda more compact.
  99. This is done globally by leaving out lines like the agenda span
  100. name and week number or the separator lines."
  101. :group 'org-agenda
  102. :type 'boolean)
  103. (defcustom org-agenda-block-separator ?=
  104. "The separator between blocks in the agenda.
  105. If this is a string, it will be used as the separator, with a newline added.
  106. If it is a character, it will be repeated to fill the window width.
  107. If nil the separator is disabled. In `org-agenda-custom-commands' this
  108. addresses the separator between the current and the previous block."
  109. :group 'org-agenda
  110. :type '(choice
  111. (const :tag "Disabled" nil)
  112. (character)
  113. (string)))
  114. (defgroup org-agenda-export nil
  115. "Options concerning exporting agenda views in Org-mode."
  116. :tag "Org Agenda Export"
  117. :group 'org-agenda)
  118. (defcustom org-agenda-with-colors t
  119. "Non-nil means use colors in agenda views."
  120. :group 'org-agenda-export
  121. :type 'boolean)
  122. (defcustom org-agenda-exporter-settings nil
  123. "Alist of variable/value pairs that should be active during agenda export.
  124. This is a good place to set options for ps-print and for htmlize.
  125. Note that the way this is implemented, the values will be evaluated
  126. before assigned to the variables. So make sure to quote values you do
  127. *not* want evaluated, for example
  128. (setq org-agenda-exporter-settings
  129. '((ps-print-color-p 'black-white)))"
  130. :group 'org-agenda-export
  131. :type '(repeat
  132. (list
  133. (variable)
  134. (sexp :tag "Value"))))
  135. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  136. "Hook run in temporary buffer before writing it to an export file.
  137. A useful function is `org-agenda-add-entry-text'."
  138. :group 'org-agenda-export
  139. :type 'hook
  140. :options '(org-agenda-add-entry-text))
  141. (defcustom org-agenda-add-entry-text-maxlines 0
  142. "Maximum number of entry text lines to be added to agenda.
  143. This is only relevant when `org-agenda-add-entry-text' is part of
  144. `org-agenda-before-write-hook', which it is by default.
  145. When this is 0, nothing will happen. When it is greater than 0, it
  146. specifies the maximum number of lines that will be added for each entry
  147. that is listed in the agenda view.
  148. Note that this variable is not used during display, only when exporting
  149. the agenda. For agenda display, see the variables `org-agenda-entry-text-mode'
  150. and `org-agenda-entry-text-maxlines'."
  151. :group 'org-agenda
  152. :type 'integer)
  153. (defcustom org-agenda-add-entry-text-descriptive-links t
  154. "Non-nil means export org-links as descriptive links in agenda added text.
  155. This variable applies to the text added to the agenda when
  156. `org-agenda-add-entry-text-maxlines' is larger than 0.
  157. When this variable nil, the URL will (also) be shown."
  158. :group 'org-agenda
  159. :type 'boolean)
  160. (defcustom org-agenda-export-html-style ""
  161. "The style specification for exported HTML Agenda files.
  162. If this variable contains a string, it will replace the default <style>
  163. section as produced by `htmlize'.
  164. Since there are different ways of setting style information, this variable
  165. needs to contain the full HTML structure to provide a style, including the
  166. surrounding HTML tags. The style specifications should include definitions
  167. the fonts used by the agenda, here is an example:
  168. <style type=\"text/css\">
  169. p { font-weight: normal; color: gray; }
  170. .org-agenda-structure {
  171. font-size: 110%;
  172. color: #003399;
  173. font-weight: 600;
  174. }
  175. .org-todo {
  176. color: #cc6666;
  177. font-weight: bold;
  178. }
  179. .org-agenda-done {
  180. color: #339933;
  181. }
  182. .org-done {
  183. color: #339933;
  184. }
  185. .title { text-align: center; }
  186. .todo, .deadline { color: red; }
  187. .done { color: green; }
  188. </style>
  189. or, if you want to keep the style in a file,
  190. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  191. As the value of this option simply gets inserted into the HTML <head> header,
  192. you can \"misuse\" it to also add other text to the header. However,
  193. <style>...</style> is required, if not present the variable will be ignored."
  194. :group 'org-agenda-export
  195. :group 'org-export-html
  196. :type 'string)
  197. (defcustom org-agenda-persistent-filter nil
  198. "When set, keep filters from one agenda view to the next."
  199. :group 'org-agenda
  200. :type 'boolean)
  201. (defgroup org-agenda-custom-commands nil
  202. "Options concerning agenda views in Org-mode."
  203. :tag "Org Agenda Custom Commands"
  204. :group 'org-agenda)
  205. (defconst org-sorting-choice
  206. '(choice
  207. (const time-up) (const time-down)
  208. (const category-keep) (const category-up) (const category-down)
  209. (const tag-down) (const tag-up)
  210. (const priority-up) (const priority-down)
  211. (const todo-state-up) (const todo-state-down)
  212. (const effort-up) (const effort-down)
  213. (const habit-up) (const habit-down)
  214. (const alpha-up) (const alpha-down)
  215. (const user-defined-up) (const user-defined-down))
  216. "Sorting choices.")
  217. ;; Keep custom values for `org-agenda-filter-preset' compatible with
  218. ;; the new variable `org-agenda-tag-filter-preset'.
  219. (if (fboundp 'defvaralias)
  220. (defvaralias 'org-agenda-filter-preset 'org-agenda-tag-filter-preset)
  221. (defvaralias 'org-agenda-filter 'org-agenda-tag-filter))
  222. (defconst org-agenda-custom-commands-local-options
  223. `(repeat :tag "Local settings for this command. Remember to quote values"
  224. (choice :tag "Setting"
  225. (list :tag "Heading for this block"
  226. (const org-agenda-overriding-header)
  227. (string :tag "Headline"))
  228. (list :tag "Files to be searched"
  229. (const org-agenda-files)
  230. (list
  231. (const :format "" quote)
  232. (repeat (file))))
  233. (list :tag "Sorting strategy"
  234. (const org-agenda-sorting-strategy)
  235. (list
  236. (const :format "" quote)
  237. (repeat
  238. ,org-sorting-choice)))
  239. (list :tag "Prefix format"
  240. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  241. (string))
  242. (list :tag "Number of days in agenda"
  243. (const org-agenda-span)
  244. (choice (const :tag "Day" 'day)
  245. (const :tag "Week" 'week)
  246. (const :tag "Month" 'month)
  247. (const :tag "Year" 'year)
  248. (integer :tag "Custom")))
  249. (list :tag "Fixed starting date"
  250. (const org-agenda-start-day)
  251. (string :value "2007-11-01"))
  252. (list :tag "Start on day of week"
  253. (const org-agenda-start-on-weekday)
  254. (choice :value 1
  255. (const :tag "Today" nil)
  256. (integer :tag "Weekday No.")))
  257. (list :tag "Include data from diary"
  258. (const org-agenda-include-diary)
  259. (boolean))
  260. (list :tag "Deadline Warning days"
  261. (const org-deadline-warning-days)
  262. (integer :value 1))
  263. (list :tag "Category filter preset"
  264. (const org-agenda-category-filter-preset)
  265. (list
  266. (const :format "" quote)
  267. (repeat
  268. (string :tag "+category or -category"))))
  269. (list :tag "Tags filter preset"
  270. (const org-agenda-tag-filter-preset)
  271. (list
  272. (const :format "" quote)
  273. (repeat
  274. (string :tag "+tag or -tag"))))
  275. (list :tag "Set daily/weekly entry types"
  276. (const org-agenda-entry-types)
  277. (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
  278. (const :deadline)
  279. (const :scheduled)
  280. (const :timestamp)
  281. (const :sexp)))
  282. (list :tag "Standard skipping condition"
  283. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  284. (const org-agenda-skip-function)
  285. (list
  286. (const :format "" quote)
  287. (list
  288. (choice
  289. :tag "Skipping range"
  290. (const :tag "Skip entry" org-agenda-skip-entry-if)
  291. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  292. (repeat :inline t :tag "Conditions for skipping"
  293. (choice
  294. :tag "Condition type"
  295. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  296. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  297. (list :tag "TODO state is" :inline t
  298. (const 'todo)
  299. (choice
  300. (const :tag "any not-done state" 'todo)
  301. (const :tag "any done state" 'done)
  302. (const :tag "any state" 'any)
  303. (list :tag "Keyword list"
  304. (const :format "" quote)
  305. (repeat (string :tag "Keyword")))))
  306. (list :tag "TODO state is not" :inline t
  307. (const 'nottodo)
  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. (const :tag "scheduled" 'scheduled)
  316. (const :tag "not scheduled" 'notscheduled)
  317. (const :tag "deadline" 'deadline)
  318. (const :tag "no deadline" 'notdeadline)
  319. (const :tag "timestamp" 'timestamp)
  320. (const :tag "no timestamp" 'nottimestamp))))))
  321. (list :tag "Non-standard skipping condition"
  322. :value (org-agenda-skip-function)
  323. (const org-agenda-skip-function)
  324. (sexp :tag "Function or form (quoted!)"))
  325. (list :tag "Any variable"
  326. (variable :tag "Variable")
  327. (sexp :tag "Value (sexp)"))))
  328. "Selection of examples for agenda command settings.
  329. This will be spliced into the custom type of
  330. `org-agenda-custom-commands'.")
  331. (defcustom org-agenda-custom-commands '(("n" "Agenda and all TODO's"
  332. ((agenda "") (alltodo))))
  333. "Custom commands for the agenda.
  334. These commands will be offered on the splash screen displayed by the
  335. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  336. (key desc type match settings files)
  337. key The key (one or more characters as a string) to be associated
  338. with the command.
  339. desc A description of the command, when omitted or nil, a default
  340. description is built using MATCH.
  341. type The command type, any of the following symbols:
  342. agenda The daily/weekly agenda.
  343. todo Entries with a specific TODO keyword, in all agenda files.
  344. search Entries containing search words entry or headline.
  345. tags Tags/Property/TODO match in all agenda files.
  346. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  347. todo-tree Sparse tree of specific TODO keyword in *current* file.
  348. tags-tree Sparse tree with all tags matches in *current* file.
  349. occur-tree Occur sparse tree for *current* file.
  350. ... A user-defined function.
  351. match What to search for:
  352. - a single keyword for TODO keyword searches
  353. - a tags match expression for tags searches
  354. - a word search expression for text searches.
  355. - a regular expression for occur searches
  356. For all other commands, this should be the empty string.
  357. settings A list of option settings, similar to that in a let form, so like
  358. this: ((opt1 val1) (opt2 val2) ...). The values will be
  359. evaluated at the moment of execution, so quote them when needed.
  360. files A list of files file to write the produced agenda buffer to
  361. with the command `org-store-agenda-views'.
  362. If a file name ends in \".html\", an HTML version of the buffer
  363. is written out. If it ends in \".ps\", a postscript version is
  364. produced. Otherwise, only the plain text is written to the file.
  365. You can also define a set of commands, to create a composite agenda buffer.
  366. In this case, an entry looks like this:
  367. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  368. where
  369. desc A description string to be displayed in the dispatcher menu.
  370. cmd An agenda command, similar to the above. However, tree commands
  371. are not allowed, but instead you can get agenda and global todo list.
  372. So valid commands for a set are:
  373. (agenda \"\" settings)
  374. (alltodo \"\" settings)
  375. (stuck \"\" settings)
  376. (todo \"match\" settings files)
  377. (search \"match\" settings files)
  378. (tags \"match\" settings files)
  379. (tags-todo \"match\" settings files)
  380. Each command can carry a list of options, and another set of options can be
  381. given for the whole set of commands. Individual command options take
  382. precedence over the general options.
  383. When using several characters as key to a command, the first characters
  384. are prefix commands. For the dispatcher to display useful information, you
  385. should provide a description for the prefix, like
  386. (setq org-agenda-custom-commands
  387. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  388. (\"hl\" tags \"+HOME+Lisa\")
  389. (\"hp\" tags \"+HOME+Peter\")
  390. (\"hk\" tags \"+HOME+Kim\")))"
  391. :group 'org-agenda-custom-commands
  392. :type `(repeat
  393. (choice :value ("x" "Describe command here" tags "" nil)
  394. (list :tag "Single command"
  395. (string :tag "Access Key(s) ")
  396. (option (string :tag "Description"))
  397. (choice
  398. (const :tag "Agenda" agenda)
  399. (const :tag "TODO list" alltodo)
  400. (const :tag "Search words" search)
  401. (const :tag "Stuck projects" stuck)
  402. (const :tag "Tags/Property match (all agenda files)" tags)
  403. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  404. (const :tag "TODO keyword search (all agenda files)" todo)
  405. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  406. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  407. (const :tag "Occur tree (current buffer)" occur-tree)
  408. (sexp :tag "Other, user-defined function"))
  409. (string :tag "Match (only for some commands)")
  410. ,org-agenda-custom-commands-local-options
  411. (option (repeat :tag "Export" (file :tag "Export to"))))
  412. (list :tag "Command series, all agenda files"
  413. (string :tag "Access Key(s)")
  414. (string :tag "Description ")
  415. (repeat :tag "Component"
  416. (choice
  417. (list :tag "Agenda"
  418. (const :format "" agenda)
  419. (const :tag "" :format "" "")
  420. ,org-agenda-custom-commands-local-options)
  421. (list :tag "TODO list (all keywords)"
  422. (const :format "" alltodo)
  423. (const :tag "" :format "" "")
  424. ,org-agenda-custom-commands-local-options)
  425. (list :tag "Search words"
  426. (const :format "" search)
  427. (string :tag "Match")
  428. ,org-agenda-custom-commands-local-options)
  429. (list :tag "Stuck projects"
  430. (const :format "" stuck)
  431. (const :tag "" :format "" "")
  432. ,org-agenda-custom-commands-local-options)
  433. (list :tag "Tags search"
  434. (const :format "" tags)
  435. (string :tag "Match")
  436. ,org-agenda-custom-commands-local-options)
  437. (list :tag "Tags search, TODO entries only"
  438. (const :format "" tags-todo)
  439. (string :tag "Match")
  440. ,org-agenda-custom-commands-local-options)
  441. (list :tag "TODO keyword search"
  442. (const :format "" todo)
  443. (string :tag "Match")
  444. ,org-agenda-custom-commands-local-options)
  445. (list :tag "Other, user-defined function"
  446. (symbol :tag "function")
  447. (string :tag "Match")
  448. ,org-agenda-custom-commands-local-options)))
  449. (repeat :tag "Settings for entire command set"
  450. (list (variable :tag "Any variable")
  451. (sexp :tag "Value")))
  452. (option (repeat :tag "Export" (file :tag "Export to"))))
  453. (cons :tag "Prefix key documentation"
  454. (string :tag "Access Key(s)")
  455. (string :tag "Description ")))))
  456. (defcustom org-agenda-query-register ?o
  457. "The register holding the current query string.
  458. The purpose of this is that if you construct a query string interactively,
  459. you can then use it to define a custom command."
  460. :group 'org-agenda-custom-commands
  461. :type 'character)
  462. (defcustom org-stuck-projects
  463. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  464. "How to identify stuck projects.
  465. This is a list of four items:
  466. 1. A tags/todo/property matcher string that is used to identify a project.
  467. See the manual for a description of tag and property searches.
  468. The entire tree below a headline matched by this is considered one project.
  469. 2. A list of TODO keywords identifying non-stuck projects.
  470. If the project subtree contains any headline with one of these todo
  471. keywords, the project is considered to be not stuck. If you specify
  472. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  473. 3. A list of tags identifying non-stuck projects.
  474. If the project subtree contains any headline with one of these tags,
  475. the project is considered to be not stuck. If you specify \"*\" as
  476. a tag, any tag will mark the project unstuck. Note that this is about
  477. the explicit presence of a tag somewhere in the subtree, inherited
  478. tags to not count here. If inherited tags make a project not stuck,
  479. use \"-TAG\" in the tags part of the matcher under (1.) above.
  480. 4. An arbitrary regular expression matching non-stuck projects.
  481. If the project turns out to be not stuck, search continues also in the
  482. subtree to see if any of the subtasks have project status.
  483. See also the variable `org-tags-match-list-sublevels' which applies
  484. to projects matched by this search as well.
  485. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  486. or `C-c a #' to produce the list."
  487. :group 'org-agenda-custom-commands
  488. :type '(list
  489. (string :tag "Tags/TODO match to identify a project")
  490. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  491. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  492. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  493. (defcustom org-agenda-filter-effort-default-operator "<"
  494. "The default operator for effort estimate filtering.
  495. If you select an effort estimate limit without first pressing an operator,
  496. this one will be used."
  497. :group 'org-agenda-custom-commands
  498. :type '(choice (const :tag "less or equal" "<")
  499. (const :tag "greater or equal"">")
  500. (const :tag "equal" "=")))
  501. (defgroup org-agenda-skip nil
  502. "Options concerning skipping parts of agenda files."
  503. :tag "Org Agenda Skip"
  504. :group 'org-agenda)
  505. (defcustom org-agenda-skip-function-global nil
  506. "Function to be called at each match during agenda construction.
  507. If this function returns nil, the current match should not be skipped.
  508. If the function decided to skip an agenda match, is must return the
  509. buffer position from which the search should be continued.
  510. This may also be a Lisp form, which will be evaluated.
  511. This variable will be applied to every agenda match, including
  512. tags/property searches and TODO lists. So try to make the test function
  513. do its checking as efficiently as possible. To implement a skipping
  514. condition just for specific agenda commands, use the variable
  515. `org-agenda-skip-function' which can be set in the options section
  516. of custom agenda commands."
  517. :group 'org-agenda-skip
  518. :type 'sexp)
  519. (defgroup org-agenda-daily/weekly nil
  520. "Options concerning the daily/weekly agenda."
  521. :tag "Org Agenda Daily/Weekly"
  522. :group 'org-agenda)
  523. (defgroup org-agenda-todo-list nil
  524. "Options concerning the global todo list agenda view."
  525. :tag "Org Agenda Todo List"
  526. :group 'org-agenda)
  527. (defgroup org-agenda-match-view nil
  528. "Options concerning the general tags/property/todo match agenda view."
  529. :tag "Org Agenda Match View"
  530. :group 'org-agenda)
  531. (defgroup org-agenda-search-view nil
  532. "Options concerning the general tags/property/todo match agenda view."
  533. :tag "Org Agenda Match View"
  534. :group 'org-agenda)
  535. (defvar org-agenda-archives-mode nil
  536. "Non-nil means the agenda will include archived items.
  537. If this is the symbol `trees', trees in the selected agenda scope
  538. that are marked with the ARCHIVE tag will be included anyway. When this is
  539. t, also all archive files associated with the current selection of agenda
  540. files will be included.")
  541. (defcustom org-agenda-skip-comment-trees t
  542. "Non-nil means skip trees that start with the COMMENT keyword.
  543. When nil, these trees are also scanned by agenda commands."
  544. :group 'org-agenda-skip
  545. :type 'boolean)
  546. (defcustom org-agenda-todo-list-sublevels t
  547. "Non-nil means check also the sublevels of a TODO entry for TODO entries.
  548. When nil, the sublevels of a TODO entry are not checked, resulting in
  549. potentially much shorter TODO lists."
  550. :group 'org-agenda-skip
  551. :group 'org-agenda-todo-list
  552. :type 'boolean)
  553. (defcustom org-agenda-todo-ignore-with-date nil
  554. "Non-nil means don't show entries with a date in the global todo list.
  555. You can use this if you prefer to mark mere appointments with a TODO keyword,
  556. but don't want them to show up in the TODO list.
  557. When this is set, it also covers deadlines and scheduled items, the settings
  558. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  559. will be ignored.
  560. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  561. :group 'org-agenda-skip
  562. :group 'org-agenda-todo-list
  563. :type 'boolean)
  564. (defcustom org-agenda-todo-ignore-timestamp nil
  565. "Non-nil means don't show entries with a timestamp.
  566. This applies when creating the global todo list.
  567. Valid values are:
  568. past Don't show entries for today or in the past.
  569. future Don't show entries with a timestamp in the future.
  570. The idea behind this is that if it has a future
  571. timestamp, you don't want to think about it until the
  572. date.
  573. all Don't show any entries with a timestamp in the global todo list.
  574. The idea behind this is that by setting a timestamp, you
  575. have already \"taken care\" of this item.
  576. This variable can also have an integer as a value. If positive (N),
  577. todos with a timestamp N or more days in the future will be ignored. If
  578. negative (-N), todos with a timestamp N or more days in the past will be
  579. ignored. If 0, todos with a timestamp either today or in the future will
  580. be ignored. For example, a value of -1 will exclude todos with a
  581. timestamp in the past (yesterday or earlier), while a value of 7 will
  582. exclude todos with a timestamp a week or more in the future.
  583. See also `org-agenda-todo-ignore-with-date'.
  584. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  585. to make his option also apply to the tags-todo list."
  586. :group 'org-agenda-skip
  587. :group 'org-agenda-todo-list
  588. :version "24.1"
  589. :type '(choice
  590. (const :tag "Ignore future timestamp todos" future)
  591. (const :tag "Ignore past or present timestamp todos" past)
  592. (const :tag "Ignore all timestamp todos" all)
  593. (const :tag "Show timestamp todos" nil)
  594. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  595. (defcustom org-agenda-todo-ignore-scheduled nil
  596. "Non-nil means, ignore some scheduled TODO items when making TODO list.
  597. This applies when creating the global todo list.
  598. Valid values are:
  599. past Don't show entries scheduled today or in the past.
  600. future Don't show entries scheduled in the future.
  601. The idea behind this is that by scheduling it, you don't want to
  602. think about it until the scheduled date.
  603. all Don't show any scheduled entries in the global todo list.
  604. The idea behind this is that by scheduling it, you have already
  605. \"taken care\" of this item.
  606. t Same as `all', for backward compatibility.
  607. This variable can also have an integer as a value. See
  608. `org-agenda-todo-ignore-timestamp' for more details.
  609. See also `org-agenda-todo-ignore-with-date'.
  610. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  611. to make his option also apply to the tags-todo list."
  612. :group 'org-agenda-skip
  613. :group 'org-agenda-todo-list
  614. :type '(choice
  615. (const :tag "Ignore future-scheduled todos" future)
  616. (const :tag "Ignore past- or present-scheduled todos" past)
  617. (const :tag "Ignore all scheduled todos" all)
  618. (const :tag "Ignore all scheduled todos (compatibility)" t)
  619. (const :tag "Show scheduled todos" nil)
  620. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  621. (defcustom org-agenda-todo-ignore-deadlines nil
  622. "Non-nil means ignore some deadlined TODO items when making TODO list.
  623. There are different motivations for using different values, please think
  624. carefully when configuring this variable.
  625. This applies when creating the global todo list.
  626. Valid values are:
  627. near Don't show near deadline entries. A deadline is near when it is
  628. closer than `org-deadline-warning-days' days. The idea behind this
  629. is that such items will appear in the agenda anyway.
  630. far Don't show TODO entries where a deadline has been defined, but
  631. the deadline is not near. This is useful if you don't want to
  632. use the todo list to figure out what to do now.
  633. past Don't show entries with a deadline timestamp for today or in the past.
  634. future Don't show entries with a deadline timestamp in the future, not even
  635. when they become `near' ones. Use it with caution.
  636. all Ignore all TODO entries that do have a deadline.
  637. t Same as `near', for backward compatibility.
  638. This variable can also have an integer as a value. See
  639. `org-agenda-todo-ignore-timestamp' for more details.
  640. See also `org-agenda-todo-ignore-with-date'.
  641. See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
  642. to make his option also apply to the tags-todo list."
  643. :group 'org-agenda-skip
  644. :group 'org-agenda-todo-list
  645. :type '(choice
  646. (const :tag "Ignore near deadlines" near)
  647. (const :tag "Ignore near deadlines (compatibility)" t)
  648. (const :tag "Ignore far deadlines" far)
  649. (const :tag "Ignore all TODOs with a deadlines" all)
  650. (const :tag "Show all TODOs, even if they have a deadline" nil)
  651. (integer :tag "Ignore if N or more days in past(-) or future(+).")))
  652. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  653. "Non-nil means honor todo-list ...ignore options also in tags-todo search.
  654. The variables
  655. `org-agenda-todo-ignore-with-date',
  656. `org-agenda-todo-ignore-timestamp',
  657. `org-agenda-todo-ignore-scheduled',
  658. `org-agenda-todo-ignore-deadlines'
  659. make the global TODO list skip entries that have time stamps of certain
  660. kinds. If this option is set, the same options will also apply for the
  661. tags-todo search, which is the general tags/property matcher
  662. restricted to unfinished TODO entries only."
  663. :group 'org-agenda-skip
  664. :group 'org-agenda-todo-list
  665. :group 'org-agenda-match-view
  666. :type 'boolean)
  667. (defcustom org-agenda-skip-scheduled-if-done nil
  668. "Non-nil means don't show scheduled items in agenda when they are done.
  669. This is relevant for the daily/weekly agenda, not for the TODO list. And
  670. it applies only to the actual date of the scheduling. Warnings about
  671. an item with a past scheduling dates are always turned off when the item
  672. is DONE."
  673. :group 'org-agenda-skip
  674. :group 'org-agenda-daily/weekly
  675. :type 'boolean)
  676. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  677. "Non-nil means skip scheduling line if same entry shows because of deadline.
  678. In the agenda of today, an entry can show up multiple times because
  679. it is both scheduled and has a nearby deadline, and maybe a plain time
  680. stamp as well.
  681. When this variable is t, then only the deadline is shown and the fact that
  682. the entry is scheduled today or was scheduled previously is not shown.
  683. When this variable is nil, the entry will be shown several times. When
  684. the variable is the symbol `not-today', then skip scheduled previously,
  685. but not scheduled today."
  686. :group 'org-agenda-skip
  687. :group 'org-agenda-daily/weekly
  688. :type '(choice
  689. (const :tag "Never" nil)
  690. (const :tag "Always" t)
  691. (const :tag "Not when scheduled today" not-today)))
  692. (defcustom org-agenda-skip-deadline-if-done nil
  693. "Non-nil means don't show deadlines when the corresponding item is done.
  694. When nil, the deadline is still shown and should give you a happy feeling.
  695. This is relevant for the daily/weekly agenda. And it applied only to the
  696. actually date of the deadline. Warnings about approaching and past-due
  697. deadlines are always turned off when the item is DONE."
  698. :group 'org-agenda-skip
  699. :group 'org-agenda-daily/weekly
  700. :type 'boolean)
  701. (defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  702. "Non-nil means skip deadline prewarning when entry is also scheduled.
  703. This will apply on all days where a prewarning for the deadline would
  704. be shown, but not at the day when the entry is actually due. On that day,
  705. the deadline will be shown anyway.
  706. This variable may be set to nil, t, or a number which will then give
  707. the number of days before the actual deadline when the prewarnings
  708. should resume.
  709. This can be used in a workflow where the first showing of the deadline will
  710. trigger you to schedule it, and then you don't want to be reminded of it
  711. because you will take care of it on the day when scheduled."
  712. :group 'org-agenda-skip
  713. :group 'org-agenda-daily/weekly
  714. :version "24.1"
  715. :type '(choice
  716. (const :tag "Alwas show prewarning" nil)
  717. (const :tag "Remove prewarning if entry is scheduled" t)
  718. (integer :tag "Restart prewarning N days before deadline")))
  719. (defcustom org-agenda-skip-additional-timestamps-same-entry nil
  720. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  721. When non-nil, after the search for timestamps has matched once in an
  722. entry, the rest of the entry will not be searched."
  723. :group 'org-agenda-skip
  724. :type 'boolean)
  725. (defcustom org-agenda-skip-timestamp-if-done nil
  726. "Non-nil means don't select item by timestamp or -range if it is DONE."
  727. :group 'org-agenda-skip
  728. :group 'org-agenda-daily/weekly
  729. :type 'boolean)
  730. (defcustom org-agenda-dim-blocked-tasks t
  731. "Non-nil means dim blocked tasks in the agenda display.
  732. This causes some overhead during agenda construction, but if you
  733. have turned on `org-enforce-todo-dependencies',
  734. `org-enforce-todo-checkbox-dependencies', or any other blocking
  735. mechanism, this will create useful feedback in the agenda.
  736. Instead of t, this variable can also have the value `invisible'.
  737. Then blocked tasks will be invisible and only become visible when
  738. they become unblocked. An exemption to this behavior is when a task is
  739. blocked because of unchecked checkboxes below it. Since checkboxes do
  740. not show up in the agenda views, making this task invisible you remove any
  741. trace from agenda views that there is something to do. Therefore, a task
  742. that is blocked because of checkboxes will never be made invisible, it
  743. will only be dimmed."
  744. :group 'org-agenda-daily/weekly
  745. :group 'org-agenda-todo-list
  746. :type '(choice
  747. (const :tag "Do not dim" nil)
  748. (const :tag "Dim to a gray face" t)
  749. (const :tag "Make invisible" invisible)))
  750. (defcustom org-timeline-show-empty-dates 3
  751. "Non-nil means `org-timeline' also shows dates without an entry.
  752. When nil, only the days which actually have entries are shown.
  753. When t, all days between the first and the last date are shown.
  754. When an integer, show also empty dates, but if there is a gap of more than
  755. N days, just insert a special line indicating the size of the gap."
  756. :group 'org-agenda-skip
  757. :type '(choice
  758. (const :tag "None" nil)
  759. (const :tag "All" t)
  760. (integer :tag "at most")))
  761. (defgroup org-agenda-startup nil
  762. "Options concerning initial settings in the Agenda in Org Mode."
  763. :tag "Org Agenda Startup"
  764. :group 'org-agenda)
  765. (defcustom org-agenda-menu-show-matcher t
  766. "Non-nil means show the match string in the agenda dispatcher menu.
  767. When nil, the matcher string is not shown, but is put into the help-echo
  768. property so than moving the mouse over the command shows it.
  769. Setting it to nil is good if matcher strings are very long and/or if
  770. you want to use two-column display (see `org-agenda-menu-two-column')."
  771. :group 'org-agenda
  772. :version "24.1"
  773. :type 'boolean)
  774. (defcustom org-agenda-menu-two-column nil
  775. "Non-nil means, use two columns to show custom commands in the dispatcher.
  776. If you use this, you probably want to set `org-agenda-menu-show-matcher'
  777. to nil."
  778. :group 'org-agenda
  779. :version "24.1"
  780. :type 'boolean)
  781. (defcustom org-finalize-agenda-hook nil
  782. "Hook run just before displaying an agenda buffer."
  783. :group 'org-agenda-startup
  784. :type 'hook)
  785. (defcustom org-agenda-mouse-1-follows-link nil
  786. "Non-nil means mouse-1 on a link will follow the link in the agenda.
  787. A longer mouse click will still set point. Does not work on XEmacs.
  788. Needs to be set before org.el is loaded."
  789. :group 'org-agenda-startup
  790. :type 'boolean)
  791. (defcustom org-agenda-start-with-follow-mode nil
  792. "The initial value of follow mode in a newly created agenda window."
  793. :group 'org-agenda-startup
  794. :type 'boolean)
  795. (defcustom org-agenda-follow-indirect nil
  796. "Non-nil means `org-agenda-follow-mode' displays only the
  797. current item's tree, in an indirect buffer."
  798. :group 'org-agenda
  799. :version "24.1"
  800. :type 'boolean)
  801. (defcustom org-agenda-show-outline-path t
  802. "Non-nil means show outline path in echo area after line motion."
  803. :group 'org-agenda-startup
  804. :type 'boolean)
  805. (defcustom org-agenda-start-with-entry-text-mode nil
  806. "The initial value of entry-text-mode in a newly created agenda window."
  807. :group 'org-agenda-startup
  808. :type 'boolean)
  809. (defcustom org-agenda-entry-text-maxlines 5
  810. "Number of text lines to be added when `E' is pressed in the agenda.
  811. Note that this variable only used during agenda display. Add add entry text
  812. when exporting the agenda, configure the variable
  813. `org-agenda-add-entry-ext-maxlines'."
  814. :group 'org-agenda
  815. :type 'integer)
  816. (defcustom org-agenda-entry-text-exclude-regexps nil
  817. "List of regular expressions to clean up entry text.
  818. The complete matches of all regular expressions in this list will be
  819. removed from entry text before it is shown in the agenda."
  820. :group 'org-agenda
  821. :type '(repeat (regexp)))
  822. (defvar org-agenda-entry-text-cleanup-hook nil
  823. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  824. This cleanup is done in a temporary buffer, so the function may inspect and
  825. change the entire buffer.
  826. Some default stuff like drawers and scheduling/deadline dates will already
  827. have been removed when this is called, as will any matches for regular
  828. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  829. (defvar org-agenda-include-inactive-timestamps nil
  830. "Non-nil means include inactive time stamps in agenda and timeline.
  831. Dynamically scoped.")
  832. (defgroup org-agenda-windows nil
  833. "Options concerning the windows used by the Agenda in Org Mode."
  834. :tag "Org Agenda Windows"
  835. :group 'org-agenda)
  836. (defcustom org-agenda-window-setup 'reorganize-frame
  837. "How the agenda buffer should be displayed.
  838. Possible values for this option are:
  839. current-window Show agenda in the current window, keeping all other windows.
  840. other-window Use `switch-to-buffer-other-window' to display agenda.
  841. reorganize-frame Show only two windows on the current frame, the current
  842. window and the agenda.
  843. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  844. Also, when exiting the agenda, kill that frame.
  845. See also the variable `org-agenda-restore-windows-after-quit'."
  846. :group 'org-agenda-windows
  847. :type '(choice
  848. (const current-window)
  849. (const other-frame)
  850. (const other-window)
  851. (const reorganize-frame)))
  852. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  853. "The min and max height of the agenda window as a fraction of frame height.
  854. The value of the variable is a cons cell with two numbers between 0 and 1.
  855. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  856. :group 'org-agenda-windows
  857. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  858. (defcustom org-agenda-restore-windows-after-quit nil
  859. "Non-nil means restore window configuration upon exiting agenda.
  860. Before the window configuration is changed for displaying the agenda,
  861. the current status is recorded. When the agenda is exited with
  862. `q' or `x' and this option is set, the old state is restored. If
  863. `org-agenda-window-setup' is `other-frame', the value of this
  864. option will be ignored."
  865. :group 'org-agenda-windows
  866. :type 'boolean)
  867. (defcustom org-agenda-ndays nil
  868. "Number of days to include in overview display.
  869. Should be 1 or 7.
  870. Obsolete, see `org-agenda-span'."
  871. :group 'org-agenda-daily/weekly
  872. :type 'integer)
  873. (make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
  874. (defcustom org-agenda-span 'week
  875. "Number of days to include in overview display.
  876. Can be day, week, month, year, or any number of days.
  877. Custom commands can set this variable in the options section."
  878. :group 'org-agenda-daily/weekly
  879. :type '(choice (const :tag "Day" day)
  880. (const :tag "Week" week)
  881. (const :tag "Month" month)
  882. (const :tag "Year" year)
  883. (integer :tag "Custom")))
  884. (defcustom org-agenda-start-on-weekday 1
  885. "Non-nil means start the overview always on the specified weekday.
  886. 0 denotes Sunday, 1 denotes Monday etc.
  887. When nil, always start on the current day.
  888. Custom commands can set this variable in the options section."
  889. :group 'org-agenda-daily/weekly
  890. :type '(choice (const :tag "Today" nil)
  891. (integer :tag "Weekday No.")))
  892. (defcustom org-agenda-show-all-dates t
  893. "Non-nil means `org-agenda' shows every day in the selected range.
  894. When nil, only the days which actually have entries are shown."
  895. :group 'org-agenda-daily/weekly
  896. :type 'boolean)
  897. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  898. "Format string for displaying dates in the agenda.
  899. Used by the daily/weekly agenda and by the timeline. This should be
  900. a format string understood by `format-time-string', or a function returning
  901. the formatted date as a string. The function must take a single argument,
  902. a calendar-style date list like (month day year)."
  903. :group 'org-agenda-daily/weekly
  904. :type '(choice
  905. (string :tag "Format string")
  906. (function :tag "Function")))
  907. (defun org-agenda-format-date-aligned (date)
  908. "Format a date string for display in the daily/weekly agenda, or timeline.
  909. This function makes sure that dates are aligned for easy reading."
  910. (require 'cal-iso)
  911. (let* ((dayname (calendar-day-name date))
  912. (day (cadr date))
  913. (day-of-week (calendar-day-of-week date))
  914. (month (car date))
  915. (monthname (calendar-month-name month))
  916. (year (nth 2 date))
  917. (iso-week (org-days-to-iso-week
  918. (calendar-absolute-from-gregorian date)))
  919. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  920. (1- year))
  921. ((and (= month 12) (<= iso-week 1))
  922. (1+ year))
  923. (t year)))
  924. (weekstring (if (= day-of-week 1)
  925. (format " W%02d" iso-week)
  926. "")))
  927. (format "%-10s %2d %s %4d%s"
  928. dayname day monthname year weekstring)))
  929. (defcustom org-agenda-time-leading-zero nil
  930. "Non-nil means use leading zero for military times in agenda.
  931. For example, 9:30am would become 09:30 rather than 9:30."
  932. :group 'org-agenda-daily/weekly
  933. :version "24.1"
  934. :type 'boolean)
  935. (defcustom org-agenda-timegrid-use-ampm nil
  936. "When set, show AM/PM style timestamps on the timegrid."
  937. :group 'org-agenda
  938. :version "24.1"
  939. :type 'boolean)
  940. (defun org-agenda-time-of-day-to-ampm (time)
  941. "Convert TIME of a string like '13:45' to an AM/PM style time string."
  942. (let* ((hour-number (string-to-number (substring time 0 -3)))
  943. (minute (substring time -2))
  944. (ampm "am"))
  945. (cond
  946. ((equal hour-number 12)
  947. (setq ampm "pm"))
  948. ((> hour-number 12)
  949. (setq ampm "pm")
  950. (setq hour-number (- hour-number 12))))
  951. (concat
  952. (if org-agenda-time-leading-zero
  953. (format "%02d" hour-number)
  954. (format "%02s" (number-to-string hour-number)))
  955. ":" minute ampm)))
  956. (defun org-agenda-time-of-day-to-ampm-maybe (time)
  957. "Conditionally convert TIME to AM/PM format
  958. based on `org-agenda-timegrid-use-ampm'"
  959. (if org-agenda-timegrid-use-ampm
  960. (org-agenda-time-of-day-to-ampm time)
  961. time))
  962. (defcustom org-agenda-weekend-days '(6 0)
  963. "Which days are weekend?
  964. These days get the special face `org-agenda-date-weekend' in the agenda
  965. and timeline buffers."
  966. :group 'org-agenda-daily/weekly
  967. :type '(set :greedy t
  968. (const :tag "Monday" 1)
  969. (const :tag "Tuesday" 2)
  970. (const :tag "Wednesday" 3)
  971. (const :tag "Thursday" 4)
  972. (const :tag "Friday" 5)
  973. (const :tag "Saturday" 6)
  974. (const :tag "Sunday" 0)))
  975. (defcustom org-agenda-move-date-from-past-immediately-to-today t
  976. "Non-nil means jump to today when moving a past date forward in time.
  977. When using S-right in the agenda to move a a date forward, and the date
  978. stamp currently points to the past, the first key press will move it
  979. to today. WHen nil, just move one day forward even if the date stays
  980. in the past."
  981. :group 'org-agenda-daily/weekly
  982. :version "24.1"
  983. :type 'boolean)
  984. (defcustom org-agenda-include-diary nil
  985. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  986. Custom commands can set this variable in the options section."
  987. :group 'org-agenda-daily/weekly
  988. :type 'boolean)
  989. (defcustom org-agenda-include-deadlines t
  990. "If non-nil, include entries within their deadline warning period.
  991. Custom commands can set this variable in the options section."
  992. :group 'org-agenda-daily/weekly
  993. :version "24.1"
  994. :type 'boolean)
  995. (defcustom org-agenda-repeating-timestamp-show-all t
  996. "Non-nil means show all occurrences of a repeating stamp in the agenda.
  997. When set to a list of strings, only show occurrences of repeating
  998. stamps for these TODO keywords. When nil, only one occurrence is
  999. shown, either today or the nearest into the future."
  1000. :group 'org-agenda-daily/weekly
  1001. :type '(choice
  1002. (const :tag "Show repeating stamps" t)
  1003. (repeat :tag "Show repeating stamps for these TODO keywords"
  1004. (string :tag "TODO Keyword"))
  1005. (const :tag "Don't show repeating stamps" nil)))
  1006. (defcustom org-scheduled-past-days 10000
  1007. "No. of days to continue listing scheduled items that are not marked DONE.
  1008. When an item is scheduled on a date, it shows up in the agenda on this
  1009. day and will be listed until it is marked done for the number of days
  1010. given here."
  1011. :group 'org-agenda-daily/weekly
  1012. :type 'integer)
  1013. (defcustom org-agenda-log-mode-items '(closed clock)
  1014. "List of items that should be shown in agenda log mode.
  1015. This list may contain the following symbols:
  1016. closed Show entries that have been closed on that day.
  1017. clock Show entries that have received clocked time on that day.
  1018. state Show all logged state changes.
  1019. Note that instead of changing this variable, you can also press `C-u l' in
  1020. the agenda to display all available LOG items temporarily."
  1021. :group 'org-agenda-daily/weekly
  1022. :type '(set :greedy t (const closed) (const clock) (const state)))
  1023. (defcustom org-agenda-clock-consistency-checks
  1024. '(:max-duration "10:00" :min-duration 0 :max-gap "0:05"
  1025. :gap-ok-around ("4:00")
  1026. :default-face ((:background "DarkRed") (:foreground "white"))
  1027. :overlap-face nil :gap-face nil :no-end-time-face nil
  1028. :long-face nil :short-face nil)
  1029. "This is a property list, with the following keys:
  1030. :max-duration Mark clocking chunks that are longer than this time.
  1031. This is a time string like \"HH:MM\", or the number
  1032. of minutes as an integer.
  1033. :min-duration Mark clocking chunks that are shorter that this.
  1034. This is a time string like \"HH:MM\", or the number
  1035. of minutes as an integer.
  1036. :max-gap Mark gaps between clocking chunks that are longer than
  1037. this duration. A number of minutes, or a string
  1038. like \"HH:MM\".
  1039. :gap-ok-around List of times during the day which are usually not working
  1040. times. When a gap is detected, but the gap contains any
  1041. of these times, the gap is *not* reported. For example,
  1042. if this is (\"4:00\" \"13:00\") then gaps that contain
  1043. 4:00 in the morning (i.e. the night) and 13:00
  1044. (i.e. a typical lunch time) do not cause a warning.
  1045. You should have at least one time during the night in this
  1046. list, or otherwise the first task each morning will trigger
  1047. a warning because it follows a long gap.
  1048. Furthermore, the following properties can be used to define faces for
  1049. issue display.
  1050. :default-face the default face, if the specific face is undefined
  1051. :overlap-face face for overlapping clocks
  1052. :gap-face face for gaps between clocks
  1053. :no-end-time-face face for incomplete clocks
  1054. :long-face face for clock intervals that are too long
  1055. :short-face face for clock intervals that are too short"
  1056. :group 'org-agenda-daily/weekly
  1057. :group 'org-clock
  1058. :version "24.1"
  1059. :type 'plist)
  1060. (defcustom org-agenda-log-mode-add-notes t
  1061. "Non-nil means add first line of notes to log entries in agenda views.
  1062. If a log item like a state change or a clock entry is associated with
  1063. notes, the first line of these notes will be added to the entry in the
  1064. agenda display."
  1065. :group 'org-agenda-daily/weekly
  1066. :type 'boolean)
  1067. (defcustom org-agenda-start-with-log-mode nil
  1068. "The initial value of log-mode in a newly created agenda window."
  1069. :group 'org-agenda-startup
  1070. :group 'org-agenda-daily/weekly
  1071. :type 'boolean)
  1072. (defcustom org-agenda-start-with-clockreport-mode nil
  1073. "The initial value of clockreport-mode in a newly created agenda window."
  1074. :group 'org-agenda-startup
  1075. :group 'org-agenda-daily/weekly
  1076. :type 'boolean)
  1077. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  1078. "Property list with parameters for the clocktable in clockreport mode.
  1079. This is the display mode that shows a clock table in the daily/weekly
  1080. agenda, the properties for this dynamic block can be set here.
  1081. The usual clocktable parameters are allowed here, but you cannot set
  1082. the properties :name, :tstart, :tend, :block, and :scope - these will
  1083. be overwritten to make sure the content accurately reflects the
  1084. current display in the agenda."
  1085. :group 'org-agenda-daily/weekly
  1086. :type 'plist)
  1087. (defcustom org-agenda-search-view-always-boolean nil
  1088. "Non-nil means the search string is interpreted as individual parts.
  1089. The search string for search view can either be interpreted as a phrase,
  1090. or as a list of snippets that define a boolean search for a number of
  1091. strings.
  1092. When this is non-nil, the string will be split on whitespace, and each
  1093. snippet will be searched individually, and all must match in order to
  1094. select an entry. A snippet is then a single string of non-white
  1095. characters, or a string in double quotes, or a regexp in {} braces.
  1096. If a snippet is preceded by \"-\", the snippet must *not* match.
  1097. \"+\" is syntactic sugar for positive selection. Each snippet may
  1098. be found as a full word or a partial word, but see the variable
  1099. `org-agenda-search-view-force-full-words'.
  1100. When this is nil, search will look for the entire search phrase as one,
  1101. with each space character matching any amount of whitespace, including
  1102. line breaks.
  1103. Even when this is nil, you can still switch to Boolean search dynamically
  1104. by preceding the first snippet with \"+\" or \"-\". If the first snippet
  1105. is a regexp marked with braces like \"{abc}\", this will also switch to
  1106. boolean search."
  1107. :group 'org-agenda-search-view
  1108. :version "24.1"
  1109. :type 'boolean)
  1110. (if (fboundp 'defvaralias)
  1111. (defvaralias 'org-agenda-search-view-search-words-only
  1112. 'org-agenda-search-view-always-boolean))
  1113. (defcustom org-agenda-search-view-force-full-words nil
  1114. "Non-nil means, search words must be matches as complete words.
  1115. When nil, they may also match part of a word."
  1116. :group 'org-agenda-search-view
  1117. :version "24.1"
  1118. :type 'boolean)
  1119. (defgroup org-agenda-time-grid nil
  1120. "Options concerning the time grid in the Org-mode Agenda."
  1121. :tag "Org Agenda Time Grid"
  1122. :group 'org-agenda)
  1123. (defcustom org-agenda-search-headline-for-time t
  1124. "Non-nil means search headline for a time-of-day.
  1125. If the headline contains a time-of-day in one format or another, it will
  1126. be used to sort the entry into the time sequence of items for a day.
  1127. Some people have time stamps in the headline that refer to the creation
  1128. time or so, and then this produces an unwanted side effect. If this is
  1129. the case for your, use this variable to turn off searching the headline
  1130. for a time."
  1131. :group 'org-agenda-time-grid
  1132. :type 'boolean)
  1133. (defcustom org-agenda-use-time-grid t
  1134. "Non-nil means show a time grid in the agenda schedule.
  1135. A time grid is a set of lines for specific times (like every two hours between
  1136. 8:00 and 20:00). The items scheduled for a day at specific times are
  1137. sorted in between these lines.
  1138. For details about when the grid will be shown, and what it will look like, see
  1139. the variable `org-agenda-time-grid'."
  1140. :group 'org-agenda-time-grid
  1141. :type 'boolean)
  1142. (defcustom org-agenda-time-grid
  1143. '((daily today require-timed)
  1144. "----------------"
  1145. (800 1000 1200 1400 1600 1800 2000))
  1146. "The settings for time grid for agenda display.
  1147. This is a list of three items. The first item is again a list. It contains
  1148. symbols specifying conditions when the grid should be displayed:
  1149. daily if the agenda shows a single day
  1150. weekly if the agenda shows an entire week
  1151. today show grid on current date, independent of daily/weekly display
  1152. require-timed show grid only if at least one item has a time specification
  1153. The second item is a string which will be placed behind the grid time.
  1154. The third item is a list of integers, indicating the times that should have
  1155. a grid line."
  1156. :group 'org-agenda-time-grid
  1157. :type
  1158. '(list
  1159. (set :greedy t :tag "Grid Display Options"
  1160. (const :tag "Show grid in single day agenda display" daily)
  1161. (const :tag "Show grid in weekly agenda display" weekly)
  1162. (const :tag "Always show grid for today" today)
  1163. (const :tag "Show grid only if any timed entries are present"
  1164. require-timed)
  1165. (const :tag "Skip grid times already present in an entry"
  1166. remove-match))
  1167. (string :tag "Grid String")
  1168. (repeat :tag "Grid Times" (integer :tag "Time"))))
  1169. (defcustom org-agenda-show-current-time-in-grid t
  1170. "Non-nil means show the current time in the time grid."
  1171. :group 'org-agenda-time-grid
  1172. :version "24.1"
  1173. :type 'boolean)
  1174. (defcustom org-agenda-current-time-string
  1175. "now - - - - - - - - - - - - - - - - - - - - - - - - -"
  1176. "The string for the current time marker in the agenda."
  1177. :group 'org-agenda-time-grid
  1178. :version "24.1"
  1179. :type 'string)
  1180. (defgroup org-agenda-sorting nil
  1181. "Options concerning sorting in the Org-mode Agenda."
  1182. :tag "Org Agenda Sorting"
  1183. :group 'org-agenda)
  1184. (defcustom org-agenda-sorting-strategy
  1185. '((agenda habit-down time-up priority-down category-keep)
  1186. (todo priority-down category-keep)
  1187. (tags priority-down category-keep)
  1188. (search category-keep))
  1189. "Sorting structure for the agenda items of a single day.
  1190. This is a list of symbols which will be used in sequence to determine
  1191. if an entry should be listed before another entry. The following
  1192. symbols are recognized:
  1193. time-up Put entries with time-of-day indications first, early first
  1194. time-down Put entries with time-of-day indications first, late first
  1195. category-keep Keep the default order of categories, corresponding to the
  1196. sequence in `org-agenda-files'.
  1197. category-up Sort alphabetically by category, A-Z.
  1198. category-down Sort alphabetically by category, Z-A.
  1199. tag-up Sort alphabetically by last tag, A-Z.
  1200. tag-down Sort alphabetically by last tag, Z-A.
  1201. priority-up Sort numerically by priority, high priority last.
  1202. priority-down Sort numerically by priority, high priority first.
  1203. todo-state-up Sort by todo state, tasks that are done last.
  1204. todo-state-down Sort by todo state, tasks that are done first.
  1205. effort-up Sort numerically by estimated effort, high effort last.
  1206. effort-down Sort numerically by estimated effort, high effort first.
  1207. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  1208. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  1209. habit-up Put entries that are habits first
  1210. habit-down Put entries that are habits last
  1211. alpha-up Sort headlines alphabetically
  1212. alpha-down Sort headlines alphabetically, reversed
  1213. The different possibilities will be tried in sequence, and testing stops
  1214. if one comparison returns a \"not-equal\". For example, the default
  1215. '(time-up category-keep priority-down)
  1216. means: Pull out all entries having a specified time of day and sort them,
  1217. in order to make a time schedule for the current day the first thing in the
  1218. agenda listing for the day. Of the entries without a time indication, keep
  1219. the grouped in categories, don't sort the categories, but keep them in
  1220. the sequence given in `org-agenda-files'. Within each category sort by
  1221. priority.
  1222. Leaving out `category-keep' would mean that items will be sorted across
  1223. categories by priority.
  1224. Instead of a single list, this can also be a set of list for specific
  1225. contents, with a context symbol in the car of the list, any of
  1226. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  1227. Custom commands can bind this variable in the options section."
  1228. :group 'org-agenda-sorting
  1229. :type `(choice
  1230. (repeat :tag "General" ,org-sorting-choice)
  1231. (list :tag "Individually"
  1232. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  1233. (repeat ,org-sorting-choice))
  1234. (cons (const :tag "Strategy for TODO lists" todo)
  1235. (repeat ,org-sorting-choice))
  1236. (cons (const :tag "Strategy for Tags matches" tags)
  1237. (repeat ,org-sorting-choice))
  1238. (cons (const :tag "Strategy for search matches" search)
  1239. (repeat ,org-sorting-choice)))))
  1240. (defcustom org-agenda-cmp-user-defined nil
  1241. "A function to define the comparison `user-defined'.
  1242. This function must receive two arguments, agenda entry a and b.
  1243. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  1244. the user comparison, return nil.
  1245. When this is defined, you can make `user-defined-up' and `user-defined-down'
  1246. part of an agenda sorting strategy."
  1247. :group 'org-agenda-sorting
  1248. :type 'symbol)
  1249. (defcustom org-sort-agenda-notime-is-late t
  1250. "Non-nil means items without time are considered late.
  1251. This is only relevant for sorting. When t, items which have no explicit
  1252. time like 15:30 will be considered as 99:01, i.e. later than any items which
  1253. do have a time. When nil, the default time is before 0:00. You can use this
  1254. option to decide if the schedule for today should come before or after timeless
  1255. agenda entries."
  1256. :group 'org-agenda-sorting
  1257. :type 'boolean)
  1258. (defcustom org-sort-agenda-noeffort-is-high t
  1259. "Non-nil means items without effort estimate are sorted as high effort.
  1260. This also applies when filtering an agenda view with respect to the
  1261. < or > effort operator. Then, tasks with no effort defined will be treated
  1262. as tasks with high effort.
  1263. When nil, such items are sorted as 0 minutes effort."
  1264. :group 'org-agenda-sorting
  1265. :type 'boolean)
  1266. (defgroup org-agenda-line-format nil
  1267. "Options concerning the entry prefix in the Org-mode agenda display."
  1268. :tag "Org Agenda Line Format"
  1269. :group 'org-agenda)
  1270. (defcustom org-agenda-prefix-format
  1271. '((agenda . " %i %-12:c%?-12t% s")
  1272. (timeline . " % s")
  1273. (todo . " %i %-12:c")
  1274. (tags . " %i %-12:c")
  1275. (search . " %i %-12:c"))
  1276. "Format specifications for the prefix of items in the agenda views.
  1277. An alist with five entries, each for the different agenda types. The
  1278. keys of the sublists are `agenda', `timeline', `todo', `search' and `tags'.
  1279. The values are format strings.
  1280. This format works similar to a printf format, with the following meaning:
  1281. %c the category of the item, \"Diary\" for entries from the diary,
  1282. or as given by the CATEGORY keyword or derived from the file name
  1283. %e the effort required by the item
  1284. %i the icon category of the item, see `org-agenda-category-icon-alist'
  1285. %T the last tag of the item (ignore inherited tags, which come first)
  1286. %t the HH:MM time-of-day specification if one applies to the entry
  1287. %s Scheduling/Deadline information, a short string
  1288. %(expression) Eval EXPRESSION and replace the control string
  1289. by the result
  1290. All specifiers work basically like the standard `%s' of printf, but may
  1291. contain two additional characters: a question mark just after the `%'
  1292. and a whitespace/punctuation character just before the final letter.
  1293. If the first character after `%' is a question mark, the entire field
  1294. will only be included if the corresponding value applies to the current
  1295. entry. This is useful for fields which should have fixed width when
  1296. present, but zero width when absent. For example, \"%?-12t\" will
  1297. result in a 12 character time field if a time of the day is specified,
  1298. but will completely disappear in entries which do not contain a time.
  1299. If there is punctuation or whitespace character just before the final
  1300. format letter, this character will be appended to the field value if
  1301. the value is not empty. For example, the format \"%-12:c\" leads to
  1302. \"Diary: \" if the category is \"Diary\". If the category were be
  1303. empty, no additional colon would be inserted.
  1304. The default value for the agenda sublist is \" %-12:c%?-12t% s\",
  1305. which means:
  1306. - Indent the line with two space characters
  1307. - Give the category a 12 chars wide field, padded with whitespace on
  1308. the right (because of `-'). Append a colon if there is a category
  1309. (because of `:').
  1310. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1311. time, don't put in an empty field, just skip it (because of '?').
  1312. - Finally, put the scheduling information.
  1313. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1314. `org-agenda-remove-tags'.
  1315. Custom commands can set this variable in the options section."
  1316. :type '(choice
  1317. (string :tag "General format")
  1318. (list :greedy t :tag "View dependent"
  1319. (cons (const agenda) (string :tag "Format"))
  1320. (cons (const timeline) (string :tag "Format"))
  1321. (cons (const todo) (string :tag "Format"))
  1322. (cons (const tags) (string :tag "Format"))
  1323. (cons (const search) (string :tag "Format"))))
  1324. :group 'org-agenda-line-format)
  1325. (defvar org-prefix-format-compiled nil
  1326. "The compiled prefix format and associated variables.
  1327. This is a list where first element is a list of variable bindings, and second
  1328. element is the compiled format expression. See the variable
  1329. `org-agenda-prefix-format'.")
  1330. (defcustom org-agenda-todo-keyword-format "%-1s"
  1331. "Format for the TODO keyword in agenda lines.
  1332. Set this to something like \"%-12s\" if you want all TODO keywords
  1333. to occupy a fixed space in the agenda display."
  1334. :group 'org-agenda-line-format
  1335. :type 'string)
  1336. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1337. "Text preceding timerange entries in the agenda view.
  1338. This is a list with two strings. The first applies when the range
  1339. is entirely on one day. The second applies if the range spans several days.
  1340. The strings may have two \"%d\" format specifiers which will be filled
  1341. with the sequence number of the days, and the total number of days in the
  1342. range, respectively."
  1343. :group 'org-agenda-line-format
  1344. :type '(list
  1345. (string :tag "Deadline today ")
  1346. (choice :tag "Deadline relative"
  1347. (string :tag "Format string")
  1348. (function))))
  1349. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1350. "Text preceding scheduled items in the agenda view.
  1351. This is a list with two strings. The first applies when the item is
  1352. scheduled on the current day. The second applies when it has been scheduled
  1353. previously, it may contain a %d indicating that this is the nth time that
  1354. this item is scheduled, due to automatic rescheduling of unfinished items
  1355. for the following day. So this number is one larger than the number of days
  1356. that passed since this item was scheduled first."
  1357. :group 'org-agenda-line-format
  1358. :type '(list
  1359. (string :tag "Scheduled today ")
  1360. (string :tag "Scheduled previously")))
  1361. (defcustom org-agenda-inactive-leader "["
  1362. "Text preceding item pulled into the agenda by inactive time stamps.
  1363. These entries are added to the agenda when pressing \"[\"."
  1364. :group 'org-agenda-line-format
  1365. :version "24.1"
  1366. :type '(list
  1367. (string :tag "Scheduled today ")
  1368. (string :tag "Scheduled previously")))
  1369. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1370. "Text preceding deadline items in the agenda view.
  1371. This is a list with two strings. The first applies when the item has its
  1372. deadline on the current day. The second applies when it is in the past or
  1373. in the future, it may contain %d to capture how many days away the deadline
  1374. is (was)."
  1375. :group 'org-agenda-line-format
  1376. :type '(list
  1377. (string :tag "Deadline today ")
  1378. (choice :tag "Deadline relative"
  1379. (string :tag "Format string")
  1380. (function))))
  1381. (defcustom org-agenda-remove-times-when-in-prefix t
  1382. "Non-nil means remove duplicate time specifications in agenda items.
  1383. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1384. time-of-day specification in a headline or diary entry is extracted and
  1385. placed into the prefix. If this option is non-nil, the original specification
  1386. \(a timestamp or -range, or just a plain time(range) specification like
  1387. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1388. cluttered.
  1389. The option can be t or nil. It may also be the symbol `beg', indicating
  1390. that the time should only be removed when it is located at the beginning of
  1391. the headline/diary entry."
  1392. :group 'org-agenda-line-format
  1393. :type '(choice
  1394. (const :tag "Always" t)
  1395. (const :tag "Never" nil)
  1396. (const :tag "When at beginning of entry" beg)))
  1397. (defcustom org-agenda-remove-timeranges-from-blocks nil
  1398. "Non-nil means remove time ranges specifications in agenda
  1399. items that span on several days."
  1400. :group 'org-agenda-line-format
  1401. :version "24.1"
  1402. :type 'boolean)
  1403. (defcustom org-agenda-default-appointment-duration nil
  1404. "Default duration for appointments that only have a starting time.
  1405. When nil, no duration is specified in such cases.
  1406. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1407. :group 'org-agenda-line-format
  1408. :type '(choice
  1409. (integer :tag "Minutes")
  1410. (const :tag "No default duration")))
  1411. (defcustom org-agenda-show-inherited-tags t
  1412. "Non-nil means show inherited tags in each agenda line."
  1413. :group 'org-agenda-line-format
  1414. :type 'boolean)
  1415. (defcustom org-agenda-hide-tags-regexp nil
  1416. "Regular expression used to filter away specific tags in agenda views.
  1417. This means that these tags will be present, but not be shown in the agenda
  1418. line. Secondary filtering will still work on the hidden tags.
  1419. Nil means don't hide any tags."
  1420. :group 'org-agenda-line-format
  1421. :type '(choice
  1422. (const :tag "Hide none" nil)
  1423. (string :tag "Regexp ")))
  1424. (defcustom org-agenda-remove-tags nil
  1425. "Non-nil means remove the tags from the headline copy in the agenda.
  1426. When this is the symbol `prefix', only remove tags when
  1427. `org-agenda-prefix-format' contains a `%T' specifier."
  1428. :group 'org-agenda-line-format
  1429. :type '(choice
  1430. (const :tag "Always" t)
  1431. (const :tag "Never" nil)
  1432. (const :tag "When prefix format contains %T" prefix)))
  1433. (if (fboundp 'defvaralias)
  1434. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1435. 'org-agenda-remove-tags))
  1436. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1437. "Shift tags in agenda items to this column.
  1438. If this number is positive, it specifies the column. If it is negative,
  1439. it means that the tags should be flushright to that column. For example,
  1440. -80 works well for a normal 80 character screen."
  1441. :group 'org-agenda-line-format
  1442. :type 'integer)
  1443. (if (fboundp 'defvaralias)
  1444. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1445. (defcustom org-agenda-fontify-priorities 'cookies
  1446. "Non-nil means highlight low and high priorities in agenda.
  1447. When t, the highest priority entries are bold, lowest priority italic.
  1448. However, settings in `org-priority-faces' will overrule these faces.
  1449. When this variable is the symbol `cookies', only fontify the
  1450. cookies, not the entire task.
  1451. This may also be an association list of priority faces, whose
  1452. keys are the character values of `org-highest-priority',
  1453. `org-default-priority', and `org-lowest-priority' (the default values
  1454. are ?A, ?B, and ?C, respectively). The face may be a named face, a
  1455. color as a string, or a list like `(:background \"Red\")'.
  1456. If it is a color, the variable `org-faces-easy-properties'
  1457. determines if it is a foreground or a background color."
  1458. :group 'org-agenda-line-format
  1459. :type '(choice
  1460. (const :tag "Never" nil)
  1461. (const :tag "Defaults" t)
  1462. (const :tag "Cookies only" cookies)
  1463. (repeat :tag "Specify"
  1464. (list (character :tag "Priority" :value ?A)
  1465. (choice :tag "Face "
  1466. (string :tag "Color")
  1467. (sexp :tag "Face"))))))
  1468. (defcustom org-agenda-day-face-function nil
  1469. "Function called to determine what face should be used to display a day.
  1470. The only argument passed to that function is the day. It should
  1471. returns a face, or nil if does not want to specify a face and let
  1472. the normal rules apply."
  1473. :group 'org-agenda-line-format
  1474. :version "24.1"
  1475. :type 'function)
  1476. (defcustom org-agenda-category-icon-alist nil
  1477. "Alist of category icon to be displayed in agenda views.
  1478. Each entry should have the following format:
  1479. (CATEGORY-REGEXP FILE-OR-DATA TYPE DATA-P PROPS)
  1480. Where CATEGORY-REGEXP is a regexp matching the categories where
  1481. the icon should be displayed.
  1482. FILE-OR-DATA either a file path or a string containing image data.
  1483. The other fields can be omitted safely if not needed:
  1484. TYPE indicates the image type.
  1485. DATA-P is a boolean indicating whether the FILE-OR-DATA string is
  1486. image data.
  1487. PROPS are additional image attributes to assign to the image,
  1488. like, e.g. `:ascent center'.
  1489. (\"Org\" \"/path/to/icon.png\" nil nil :ascent center)
  1490. If you want to set the display properties yourself, just put a
  1491. list as second element:
  1492. (CATEGORY-REGEXP (MY PROPERTY LIST))
  1493. For example, to display a 16px horizontal space for Emacs
  1494. category, you can use:
  1495. (\"Emacs\" '(space . (:width (16))))"
  1496. :group 'org-agenda-line-format
  1497. :version "24.1"
  1498. :type '(alist :key-type (string :tag "Regexp matching category")
  1499. :value-type (choice (list :tag "Icon"
  1500. (string :tag "File or data")
  1501. (symbol :tag "Type")
  1502. (boolean :tag "Data?")
  1503. (repeat :tag "Extra image properties" :inline t symbol))
  1504. (list :tag "Display properties" sexp))))
  1505. (defgroup org-agenda-column-view nil
  1506. "Options concerning column view in the agenda."
  1507. :tag "Org Agenda Column View"
  1508. :group 'org-agenda)
  1509. (defcustom org-agenda-columns-show-summaries t
  1510. "Non-nil means show summaries for columns displayed in the agenda view."
  1511. :group 'org-agenda-column-view
  1512. :type 'boolean)
  1513. (defcustom org-agenda-columns-compute-summary-properties t
  1514. "Non-nil means recompute all summary properties before column view.
  1515. When column view in the agenda is listing properties that have a summary
  1516. operator, it can go to all relevant buffers and recompute the summaries
  1517. there. This can mean overhead for the agenda column view, but is necessary
  1518. to have thing up to date.
  1519. As a special case, a CLOCKSUM property also makes sure that the clock
  1520. computations are current."
  1521. :group 'org-agenda-column-view
  1522. :type 'boolean)
  1523. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1524. "Non-nil means the duration of an appointment will add to day effort.
  1525. The property to which appointment durations will be added is the one given
  1526. in the option `org-effort-property'. If an appointment does not have
  1527. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1528. is not set, an appointment without end time will not contribute to the time
  1529. estimate."
  1530. :group 'org-agenda-column-view
  1531. :type 'boolean)
  1532. (defcustom org-agenda-auto-exclude-function nil
  1533. "A function called with a tag to decide if it is filtered on '/ RET'.
  1534. The sole argument to the function, which is called once for each
  1535. possible tag, is a string giving the name of the tag. The
  1536. function should return either nil if the tag should be included
  1537. as normal, or \"-<TAG>\" to exclude the tag.
  1538. Note that for the purpose of tag filtering, only the lower-case version of
  1539. all tags will be considered, so that this function will only ever see
  1540. the lower-case version of all tags."
  1541. :group 'org-agenda
  1542. :type 'function)
  1543. (defcustom org-agenda-bulk-custom-functions nil
  1544. "Alist of characters and custom functions for bulk actions.
  1545. For example, this value makes those two functions available:
  1546. '((?R set-category)
  1547. (?C bulk-cut))
  1548. With selected entries in an agenda buffer, `B R' will call
  1549. the custom function `set-category' on the selected entries.
  1550. Note that functions in this alist don't need to be quoted."
  1551. :type 'alist
  1552. :version "24.1"
  1553. :group 'org-agenda)
  1554. (eval-when-compile
  1555. (require 'cl))
  1556. (require 'org)
  1557. (defmacro org-agenda-with-point-at-orig-entry (string &rest body)
  1558. "Execute BODY with point at location given by `org-hd-marker' property.
  1559. If STRING is non-nil, the text property will be fetched from position 0
  1560. in that string. If STRING is nil, it will be fetched from the beginning
  1561. of the current line."
  1562. (org-with-gensyms (marker)
  1563. `(let ((,marker (get-text-property (if string 0 (point-at-bol))
  1564. 'org-hd-marker ,string)))
  1565. (with-current-buffer (marker-buffer ,marker)
  1566. (save-excursion
  1567. (goto-char ,marker)
  1568. ,@body)))))
  1569. (def-edebug-spec org-agenda-with-point-at-orig-entry (form body))
  1570. (defun org-add-agenda-custom-command (entry)
  1571. "Replace or add a command in `org-agenda-custom-commands'.
  1572. This is mostly for hacking and trying a new command - once the command
  1573. works you probably want to add it to `org-agenda-custom-commands' for good."
  1574. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1575. (if ass
  1576. (setcdr ass (cdr entry))
  1577. (push entry org-agenda-custom-commands))))
  1578. ;;; Define the org-agenda-mode
  1579. (defvar org-agenda-mode-map (make-sparse-keymap)
  1580. "Keymap for `org-agenda-mode'.")
  1581. (if (fboundp 'defvaralias)
  1582. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1583. (defvar org-agenda-menu) ; defined later in this file.
  1584. (defvar org-agenda-restrict) ; defined later in this file.
  1585. (defvar org-agenda-follow-mode nil)
  1586. (defvar org-agenda-entry-text-mode nil)
  1587. (defvar org-agenda-clockreport-mode nil)
  1588. (defvar org-agenda-show-log nil)
  1589. (defvar org-agenda-show-scoped nil) ; Used for dynamically scoping
  1590. (defvar org-agenda-redo-command nil)
  1591. (defvar org-agenda-query-string nil)
  1592. (defvar org-agenda-mode-hook nil
  1593. "Hook for `org-agenda-mode', run after the mode is turned on.")
  1594. (defvar org-agenda-type nil)
  1595. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1596. ;;; Multiple agenda buffers support
  1597. (defcustom org-agenda-sticky nil
  1598. "Non-nil means agenda q key will bury agenda buffers.
  1599. Agenda commands will then show existing buffer instead of generating new ones.
  1600. When nil, `q' will kill the single agenda buffer."
  1601. :group 'org-agenda
  1602. :type 'boolean)
  1603. (defvar org-agenda-buffer nil
  1604. "Agenda buffer currently being generated.")
  1605. (defun org-toggle-sticky-agenda (&optional arg)
  1606. "Toggle `org-agenda-sticky'."
  1607. (interactive)
  1608. (setq org-agenda-sticky (or arg (not org-agenda-sticky)))
  1609. (org-agenda-kill-all-agenda-buffers)
  1610. (message "Sticky agenda was %s" (if org-agenda-sticky "enabled" "disabled")))
  1611. (defvar org-agenda-last-prefix-arg nil)
  1612. (defvar org-agenda-this-buffer-name nil)
  1613. (defvar org-agenda-doing-sticky-redo nil)
  1614. (defvar org-agenda-this-buffer-is-sticky nil)
  1615. (defconst org-agenda-local-vars
  1616. '(org-agenda-this-buffer-name
  1617. org-agenda-undo-list
  1618. org-agenda-pending-undo-list
  1619. org-agenda-follow-mode
  1620. org-agenda-entry-text-mode
  1621. org-agenda-clockreport-mode
  1622. org-agenda-show-log
  1623. org-agenda-redo-command
  1624. org-agenda-query-string
  1625. org-agenda-type
  1626. org-agenda-bulk-marked-entries
  1627. org-agenda-undo-has-started-in
  1628. org-agenda-last-arguments
  1629. org-agenda-info
  1630. org-agenda-tag-filter-overlays
  1631. org-agenda-cat-filter-overlays
  1632. org-pre-agenda-window-conf
  1633. org-agenda-columns-active
  1634. org-agenda-tag-filter
  1635. org-agenda-category-filter
  1636. org-agenda-markers
  1637. org-agenda-last-search-view-search-was-boolean
  1638. org-agenda-filtered-by-category
  1639. org-agenda-filter-form
  1640. org-agenda-show-window
  1641. org-agenda-cycle-counter
  1642. org-agenda-last-prefix-arg)
  1643. "Variables that must be local in agenda buffers to allow multiple buffers.")
  1644. (defun org-agenda-mode ()
  1645. "Mode for time-sorted view on action items in Org-mode files.
  1646. The following commands are available:
  1647. \\{org-agenda-mode-map}"
  1648. (interactive)
  1649. (cond (org-agenda-doing-sticky-redo
  1650. ;; Refreshing sticky agenda-buffer
  1651. ;;
  1652. ;; Preserve the value of `org-agenda-local-vars' variables,
  1653. ;; while letting `kill-all-local-variables' kill the rest
  1654. (let ((save (buffer-local-variables)))
  1655. (kill-all-local-variables)
  1656. (mapc 'make-local-variable org-agenda-local-vars)
  1657. (dolist (elem save)
  1658. (let ((var (car elem))
  1659. (val (cdr elem)))
  1660. (when (and val
  1661. (member var org-agenda-local-vars))
  1662. (set var val)))))
  1663. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1664. (org-agenda-sticky
  1665. ;; Creating a sticky Agenda buffer for the first time
  1666. (kill-all-local-variables)
  1667. (mapc 'make-local-variable org-agenda-local-vars)
  1668. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) t))
  1669. (t
  1670. ;; Creating a non-sticky agenda buffer
  1671. (kill-all-local-variables)
  1672. (set (make-local-variable 'org-agenda-this-buffer-is-sticky) nil)))
  1673. (setq org-agenda-undo-list nil
  1674. org-agenda-pending-undo-list nil
  1675. org-agenda-bulk-marked-entries nil)
  1676. (setq major-mode 'org-agenda-mode)
  1677. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1678. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1679. (setq mode-name "Org-Agenda")
  1680. (use-local-map org-agenda-mode-map)
  1681. (easy-menu-add org-agenda-menu)
  1682. (if org-startup-truncated (setq truncate-lines t))
  1683. (org-set-local 'line-move-visual nil)
  1684. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1685. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1686. ;; Make sure properties are removed when copying text
  1687. (when (boundp 'buffer-substring-filters)
  1688. (org-set-local 'buffer-substring-filters
  1689. (cons (lambda (x)
  1690. (set-text-properties 0 (length x) nil x) x)
  1691. buffer-substring-filters)))
  1692. (unless org-agenda-keep-modes
  1693. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1694. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1695. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1696. org-agenda-show-log org-agenda-start-with-log-mode))
  1697. (easy-menu-change
  1698. '("Agenda") "Agenda Files"
  1699. (append
  1700. (list
  1701. (vector
  1702. (if (get 'org-agenda-files 'org-restrict)
  1703. "Restricted to single file"
  1704. "Edit File List")
  1705. '(org-edit-agenda-file-list)
  1706. (not (get 'org-agenda-files 'org-restrict)))
  1707. "--")
  1708. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1709. (org-agenda-set-mode-name)
  1710. (apply
  1711. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1712. (list 'org-agenda-mode-hook)))
  1713. (substitute-key-definition 'undo 'org-agenda-undo
  1714. org-agenda-mode-map global-map)
  1715. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1716. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1717. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1718. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1719. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1720. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1721. (org-defkey org-agenda-mode-map "%" 'org-agenda-bulk-mark-regexp)
  1722. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1723. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1724. (org-defkey org-agenda-mode-map "A" 'org-agenda-append-agenda)
  1725. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1726. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1727. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1728. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1729. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1730. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1731. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1732. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1733. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1734. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1735. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1736. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1737. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1738. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1739. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1740. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1741. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1742. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1743. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1744. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1745. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1746. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1747. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1748. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1749. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1750. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1751. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1752. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1753. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1754. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1755. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1756. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1757. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1758. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1759. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1760. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1761. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1762. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1763. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1764. (while l (org-defkey org-agenda-mode-map
  1765. (int-to-string (pop l)) 'digit-argument)))
  1766. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1767. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1768. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1769. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1770. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1771. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1772. (org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
  1773. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1774. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1775. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1776. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1777. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1778. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1779. 'org-clock-modify-effort-estimate)
  1780. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1781. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1782. (org-defkey org-agenda-mode-map "Q" 'org-agenda-Quit)
  1783. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1784. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-agenda-write)
  1785. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1786. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1787. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1788. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1789. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1790. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1791. (substitute-key-definition 'next-line 'org-agenda-next-line
  1792. org-agenda-mode-map global-map)
  1793. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1794. org-agenda-mode-map global-map)
  1795. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1796. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1797. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1798. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1799. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1800. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1801. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1802. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1803. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1804. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1805. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1806. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1807. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1808. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1809. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1810. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1811. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1812. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1813. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1814. (org-defkey org-agenda-mode-map "J" 'org-agenda-clock-goto)
  1815. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1816. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1817. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1818. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1819. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1820. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1821. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1822. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1823. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1824. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1825. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1826. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1827. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1828. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1829. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1830. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1831. (org-defkey org-agenda-mode-map "<" 'org-agenda-filter-by-category)
  1832. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1833. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1834. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1835. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1836. (org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
  1837. (org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
  1838. (when org-agenda-mouse-1-follows-link
  1839. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1840. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1841. '("Agenda"
  1842. ("Agenda Files")
  1843. "--"
  1844. ("Agenda Dates"
  1845. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1846. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1847. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1848. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1849. "--"
  1850. ("View"
  1851. ["Day View" org-agenda-day-view
  1852. :active (org-agenda-check-type nil 'agenda)
  1853. :style radio :selected (eq org-agenda-current-span 'day)
  1854. :keys "v d (or just d)"]
  1855. ["Week View" org-agenda-week-view
  1856. :active (org-agenda-check-type nil 'agenda)
  1857. :style radio :selected (eq org-agenda-current-span 'week)
  1858. :keys "v w (or just w)"]
  1859. ["Month View" org-agenda-month-view
  1860. :active (org-agenda-check-type nil 'agenda)
  1861. :style radio :selected (eq org-agenda-current-span 'month)
  1862. :keys "v m"]
  1863. ["Year View" org-agenda-year-view
  1864. :active (org-agenda-check-type nil 'agenda)
  1865. :style radio :selected (eq org-agenda-current-span 'year)
  1866. :keys "v y"]
  1867. "--"
  1868. ["Include Diary" org-agenda-toggle-diary
  1869. :style toggle :selected org-agenda-include-diary
  1870. :active (org-agenda-check-type nil 'agenda)]
  1871. ["Include Deadlines" org-agenda-toggle-deadlines
  1872. :style toggle :selected org-agenda-include-deadlines
  1873. :active (org-agenda-check-type nil 'agenda)]
  1874. ["Use Time Grid" org-agenda-toggle-time-grid
  1875. :style toggle :selected org-agenda-use-time-grid
  1876. :active (org-agenda-check-type nil 'agenda)]
  1877. "--"
  1878. ["Show clock report" org-agenda-clockreport-mode
  1879. :style toggle :selected org-agenda-clockreport-mode
  1880. :active (org-agenda-check-type nil 'agenda)]
  1881. ["Show some entry text" org-agenda-entry-text-mode
  1882. :style toggle :selected org-agenda-entry-text-mode
  1883. :active t]
  1884. "--"
  1885. ["Show Logbook entries" org-agenda-log-mode
  1886. :style toggle :selected org-agenda-show-log
  1887. :active (org-agenda-check-type nil 'agenda 'timeline)
  1888. :keys "v l (or just l)"]
  1889. ["Include archived trees" org-agenda-archives-mode
  1890. :style toggle :selected org-agenda-archives-mode :active t
  1891. :keys "v a"]
  1892. ["Include archive files" (org-agenda-archives-mode t)
  1893. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1894. :keys "v A"]
  1895. "--"
  1896. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1897. ["Write view to file" org-agenda-write t]
  1898. ["Rebuild buffer" org-agenda-redo t]
  1899. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1900. "--"
  1901. ["Show original entry" org-agenda-show t]
  1902. ["Go To (other window)" org-agenda-goto t]
  1903. ["Go To (this window)" org-agenda-switch-to t]
  1904. ["Follow Mode" org-agenda-follow-mode
  1905. :style toggle :selected org-agenda-follow-mode :active t]
  1906. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1907. "--"
  1908. ("TODO"
  1909. ["Cycle TODO" org-agenda-todo t]
  1910. ["Next TODO set" org-agenda-todo-nextset t]
  1911. ["Previous TODO set" org-agenda-todo-previousset t]
  1912. ["Add note" org-agenda-add-note t])
  1913. ("Archive/Refile/Delete"
  1914. ["Archive default" org-agenda-archive-default t]
  1915. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1916. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1917. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1918. ["Archive subtree" org-agenda-archive t]
  1919. "--"
  1920. ["Refile" org-agenda-refile t]
  1921. "--"
  1922. ["Delete subtree" org-agenda-kill t])
  1923. ("Bulk action"
  1924. ["Mark entry" org-agenda-bulk-mark t]
  1925. ["Mark matching regexp" org-agenda-bulk-mark-regexp t]
  1926. ["Unmark entry" org-agenda-bulk-unmark t]
  1927. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1928. ["Act on all marked" org-agenda-bulk-action t]
  1929. "--"
  1930. ("Tags and Properties"
  1931. ["Show all Tags" org-agenda-show-tags t]
  1932. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1933. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1934. "--"
  1935. ["Column View" org-columns t])
  1936. ("Deadline/Schedule"
  1937. ["Schedule" org-agenda-schedule t]
  1938. ["Set Deadline" org-agenda-deadline t]
  1939. "--"
  1940. ["Mark item" org-agenda-action :active t :keys "k m"]
  1941. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1942. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1943. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1944. "--"
  1945. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1946. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1947. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1948. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1949. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1950. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1951. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1952. ("Clock and Effort"
  1953. ["Clock in" org-agenda-clock-in t]
  1954. ["Clock out" org-agenda-clock-out t]
  1955. ["Clock cancel" org-agenda-clock-cancel t]
  1956. ["Goto running clock" org-clock-goto t]
  1957. "--"
  1958. ["Set Effort" org-agenda-set-effort t]
  1959. ["Change clocked effort" org-clock-modify-effort-estimate
  1960. (org-clock-is-active)])
  1961. ("Priority"
  1962. ["Set Priority" org-agenda-priority t]
  1963. ["Increase Priority" org-agenda-priority-up t]
  1964. ["Decrease Priority" org-agenda-priority-down t]
  1965. ["Show Priority" org-agenda-show-priority t])
  1966. ("Calendar/Diary"
  1967. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1968. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1969. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1970. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1971. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1972. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1973. "--"
  1974. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1975. "--"
  1976. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1977. "--"
  1978. ("MobileOrg"
  1979. ["Push Files and Views" org-mobile-push t]
  1980. ["Get Captured and Flagged" org-mobile-pull t]
  1981. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1982. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1983. "--"
  1984. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1985. "--"
  1986. ["Quit" org-agenda-quit t]
  1987. ["Exit and Release Buffers" org-agenda-exit t]
  1988. ))
  1989. ;;; Agenda undo
  1990. (defvar org-agenda-allow-remote-undo t
  1991. "Non-nil means allow remote undo from the agenda buffer.")
  1992. (defvar org-agenda-undo-list nil
  1993. "List of undoable operations in the agenda since last refresh.")
  1994. (defvar org-agenda-undo-has-started-in nil
  1995. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1996. (defvar org-agenda-pending-undo-list nil
  1997. "In a series of undo commands, this is the list of remaining undo items.")
  1998. (defun org-agenda-undo ()
  1999. "Undo a remote editing step in the agenda.
  2000. This undoes changes both in the agenda buffer and in the remote buffer
  2001. that have been changed along."
  2002. (interactive)
  2003. (or org-agenda-allow-remote-undo
  2004. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  2005. (if (not (eq this-command last-command))
  2006. (setq org-agenda-undo-has-started-in nil
  2007. org-agenda-pending-undo-list org-agenda-undo-list))
  2008. (if (not org-agenda-pending-undo-list)
  2009. (error "No further undo information"))
  2010. (let* ((entry (pop org-agenda-pending-undo-list))
  2011. buf line cmd rembuf)
  2012. (setq cmd (pop entry) line (pop entry))
  2013. (setq rembuf (nth 2 entry))
  2014. (org-with-remote-undo rembuf
  2015. (while (bufferp (setq buf (pop entry)))
  2016. (if (pop entry)
  2017. (with-current-buffer buf
  2018. (let ((last-undo-buffer buf)
  2019. (inhibit-read-only t))
  2020. (unless (memq buf org-agenda-undo-has-started-in)
  2021. (push buf org-agenda-undo-has-started-in)
  2022. (make-local-variable 'pending-undo-list)
  2023. (undo-start))
  2024. (while (and pending-undo-list
  2025. (listp pending-undo-list)
  2026. (not (car pending-undo-list)))
  2027. (pop pending-undo-list))
  2028. (undo-more 1))))))
  2029. (org-goto-line line)
  2030. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  2031. (defun org-verify-change-for-undo (l1 l2)
  2032. "Verify that a real change occurred between the undo lists L1 and L2."
  2033. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  2034. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  2035. (not (eq l1 l2)))
  2036. ;;; Agenda dispatch
  2037. (defvar org-agenda-restrict nil)
  2038. (defvar org-agenda-restrict-begin (make-marker))
  2039. (defvar org-agenda-restrict-end (make-marker))
  2040. (defvar org-agenda-last-dispatch-buffer nil)
  2041. (defvar org-agenda-overriding-restriction nil)
  2042. ;;;###autoload
  2043. (defun org-agenda (&optional arg keys restriction)
  2044. "Dispatch agenda commands to collect entries to the agenda buffer.
  2045. Prompts for a command to execute. Any prefix arg will be passed
  2046. on to the selected command. The default selections are:
  2047. a Call `org-agenda-list' to display the agenda for current day or week.
  2048. t Call `org-todo-list' to display the global todo list.
  2049. T Call `org-todo-list' to display the global todo list, select only
  2050. entries with a specific TODO keyword (the user gets a prompt).
  2051. m Call `org-tags-view' to display headlines with tags matching
  2052. a condition (the user is prompted for the condition).
  2053. M Like `m', but select only TODO entries, no ordinary headlines.
  2054. L Create a timeline for the current buffer.
  2055. e Export views to associated files.
  2056. s Search entries for keywords.
  2057. / Multi occur across all agenda files and also files listed
  2058. in `org-agenda-text-search-extra-files'.
  2059. < Restrict agenda commands to buffer, subtree, or region.
  2060. Press several times to get the desired effect.
  2061. > Remove a previous restriction.
  2062. # List \"stuck\" projects.
  2063. ! Configure what \"stuck\" means.
  2064. C Configure custom agenda commands.
  2065. More commands can be added by configuring the variable
  2066. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  2067. searches can be pre-defined in this way.
  2068. If the current buffer is in Org-mode and visiting a file, you can also
  2069. first press `<' once to indicate that the agenda should be temporarily
  2070. \(until the next use of \\[org-agenda]) restricted to the current file.
  2071. Pressing `<' twice means to restrict to the current subtree or region
  2072. \(if active)."
  2073. (interactive "P")
  2074. (catch 'exit
  2075. (let* ((prefix-descriptions nil)
  2076. (org-agenda-buffer-name org-agenda-buffer-name)
  2077. (org-agenda-window-setup (if (equal (buffer-name)
  2078. org-agenda-buffer-name)
  2079. 'current-window
  2080. org-agenda-window-setup))
  2081. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  2082. (org-agenda-custom-commands
  2083. ;; normalize different versions
  2084. (delq nil
  2085. (mapcar
  2086. (lambda (x)
  2087. (cond ((stringp (cdr x))
  2088. (push x prefix-descriptions)
  2089. nil)
  2090. ((stringp (nth 1 x)) x)
  2091. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2092. (t (cons (car x) (cons "" (cdr x))))))
  2093. org-agenda-custom-commands)))
  2094. (buf (current-buffer))
  2095. (bfn (buffer-file-name (buffer-base-buffer)))
  2096. entry key type match lprops ans)
  2097. ;; Turn off restriction unless there is an overriding one,
  2098. (unless org-agenda-overriding-restriction
  2099. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  2100. ;; There is a request to keep the file list in place
  2101. (put 'org-agenda-files 'org-restrict nil))
  2102. (setq org-agenda-restrict nil)
  2103. (move-marker org-agenda-restrict-begin nil)
  2104. (move-marker org-agenda-restrict-end nil))
  2105. ;; Delete old local properties
  2106. (put 'org-agenda-redo-command 'org-lprops nil)
  2107. ;; Delete previously set last-arguments
  2108. (put 'org-agenda-redo-command 'last-args nil)
  2109. ;; Remember where this call originated
  2110. (setq org-agenda-last-dispatch-buffer (current-buffer))
  2111. (unless keys
  2112. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  2113. keys (car ans)
  2114. restriction (cdr ans)))
  2115. ;; If we have sticky agenda buffers, set a name for the buffer,
  2116. ;; depending on the invoking keys. The user may still set this
  2117. ;; as a command option, which will overwrite what we do here.
  2118. (if org-agenda-sticky
  2119. (setq org-agenda-buffer-name (format "*Org Agenda(%s)*" keys)))
  2120. ;; Establish the restriction, if any
  2121. (when (and (not org-agenda-overriding-restriction) restriction)
  2122. (put 'org-agenda-files 'org-restrict (list bfn))
  2123. (cond
  2124. ((eq restriction 'region)
  2125. (setq org-agenda-restrict t)
  2126. (move-marker org-agenda-restrict-begin (region-beginning))
  2127. (move-marker org-agenda-restrict-end (region-end)))
  2128. ((eq restriction 'subtree)
  2129. (save-excursion
  2130. (setq org-agenda-restrict t)
  2131. (org-back-to-heading t)
  2132. (move-marker org-agenda-restrict-begin (point))
  2133. (move-marker org-agenda-restrict-end
  2134. (progn (org-end-of-subtree t)))))))
  2135. ;; For example the todo list should not need it (but does...)
  2136. (cond
  2137. ((setq entry (assoc keys org-agenda-custom-commands))
  2138. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  2139. (progn
  2140. (setq type (nth 2 entry) match (eval (nth 3 entry))
  2141. lprops (nth 4 entry))
  2142. (put 'org-agenda-redo-command 'org-lprops lprops)
  2143. (cond
  2144. ((eq type 'agenda)
  2145. (org-let lprops '(org-agenda-list current-prefix-arg)))
  2146. ((eq type 'alltodo)
  2147. (org-let lprops '(org-todo-list current-prefix-arg)))
  2148. ((eq type 'search)
  2149. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  2150. ((eq type 'stuck)
  2151. (org-let lprops '(org-agenda-list-stuck-projects
  2152. current-prefix-arg)))
  2153. ((eq type 'tags)
  2154. (org-let lprops '(org-tags-view current-prefix-arg match)))
  2155. ((eq type 'tags-todo)
  2156. (org-let lprops '(org-tags-view '(4) match)))
  2157. ((eq type 'todo)
  2158. (org-let lprops '(org-todo-list match)))
  2159. ((eq type 'tags-tree)
  2160. (org-check-for-org-mode)
  2161. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  2162. ((eq type 'todo-tree)
  2163. (org-check-for-org-mode)
  2164. (org-let lprops
  2165. '(org-occur (concat "^" org-outline-regexp "[ \t]*"
  2166. (regexp-quote match) "\\>"))))
  2167. ((eq type 'occur-tree)
  2168. (org-check-for-org-mode)
  2169. (org-let lprops '(org-occur match)))
  2170. ((functionp type)
  2171. (org-let lprops '(funcall type match)))
  2172. ((fboundp type)
  2173. (org-let lprops '(funcall type match)))
  2174. (t (error "Invalid custom agenda command type %s" type))))
  2175. (org-agenda-run-series (nth 1 entry) (cddr entry))))
  2176. ((equal keys "C")
  2177. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  2178. (customize-variable 'org-agenda-custom-commands))
  2179. ((equal keys "a") (call-interactively 'org-agenda-list))
  2180. ((equal keys "s") (call-interactively 'org-search-view))
  2181. ((equal keys "t") (call-interactively 'org-todo-list))
  2182. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  2183. ((equal keys "m") (call-interactively 'org-tags-view))
  2184. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  2185. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  2186. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  2187. (org-add-hook
  2188. 'post-command-hook
  2189. (lambda ()
  2190. (unless (current-message)
  2191. (let* ((m (org-agenda-get-any-marker))
  2192. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  2193. (when note
  2194. (message (concat
  2195. "FLAGGING-NOTE ([?] for more info): "
  2196. (org-add-props
  2197. (replace-regexp-in-string
  2198. "\\\\n" "//"
  2199. (copy-sequence note))
  2200. nil 'face 'org-warning)))))))
  2201. t t))
  2202. ((equal keys "L")
  2203. (unless (eq major-mode 'org-mode)
  2204. (error "This is not an Org-mode file"))
  2205. (unless restriction
  2206. (put 'org-agenda-files 'org-restrict (list bfn))
  2207. (org-call-with-arg 'org-timeline arg)))
  2208. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  2209. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  2210. ((equal keys "!") (customize-variable 'org-stuck-projects))
  2211. (t (error "Invalid agenda key"))))))
  2212. (defun org-agenda-append-agenda ()
  2213. "Append another agenda view to the current one.
  2214. This function allows interactive building of block agendas.
  2215. Agenda views are separated by `org-agenda-block-separator'."
  2216. (interactive)
  2217. (unless (string= (buffer-name) org-agenda-buffer-name)
  2218. (error "Can only append from within agenda buffer"))
  2219. (let ((org-agenda-multi t))
  2220. (org-agenda)
  2221. (widen)))
  2222. (defun org-agenda-normalize-custom-commands (cmds)
  2223. (delq nil
  2224. (mapcar
  2225. (lambda (x)
  2226. (cond ((stringp (cdr x)) nil)
  2227. ((stringp (nth 1 x)) x)
  2228. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  2229. (t (cons (car x) (cons "" (cdr x))))))
  2230. cmds)))
  2231. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  2232. "The user interface for selecting an agenda command."
  2233. (catch 'exit
  2234. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  2235. (restrict-ok (and bfn (eq major-mode 'org-mode)))
  2236. (region-p (org-region-active-p))
  2237. (custom org-agenda-custom-commands)
  2238. (selstring "")
  2239. restriction second-time
  2240. c entry key type match prefixes rmheader header-end custom1 desc
  2241. line lines left right n n1)
  2242. (save-window-excursion
  2243. (delete-other-windows)
  2244. (org-switch-to-buffer-other-window " *Agenda Commands*")
  2245. (erase-buffer)
  2246. (insert (eval-when-compile
  2247. (let ((header
  2248. "Press key for an agenda command: < Buffer, subtree/region restriction
  2249. -------------------------------- > Remove restriction
  2250. a Agenda for current week or day e Export agenda views
  2251. t List of all TODO entries T Entries with special TODO kwd
  2252. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  2253. L Timeline for current buffer # List stuck projects (!=configure)
  2254. s Search for keywords * Toggle sticky agenda views
  2255. / Multi-occur ? Find :FLAGGED: entries
  2256. C Configure custom agenda commands
  2257. ")
  2258. (start 0))
  2259. (while (string-match
  2260. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  2261. header start)
  2262. (setq start (match-end 0))
  2263. (add-text-properties (match-beginning 2) (match-end 2)
  2264. '(face bold) header))
  2265. header)))
  2266. (setq header-end (move-marker (make-marker) (point)))
  2267. (while t
  2268. (setq custom1 custom)
  2269. (when (eq rmheader t)
  2270. (org-goto-line 1)
  2271. (re-search-forward ":" nil t)
  2272. (delete-region (match-end 0) (point-at-eol))
  2273. (forward-char 1)
  2274. (looking-at "-+")
  2275. (delete-region (match-end 0) (point-at-eol))
  2276. (move-marker header-end (match-end 0)))
  2277. (goto-char header-end)
  2278. (delete-region (point) (point-max))
  2279. ;; Produce all the lines that describe custom commands and prefixes
  2280. (setq lines nil)
  2281. (while (setq entry (pop custom1))
  2282. (setq key (car entry) desc (nth 1 entry)
  2283. type (nth 2 entry)
  2284. match (nth 3 entry))
  2285. (if (> (length key) 1)
  2286. (add-to-list 'prefixes (string-to-char key))
  2287. (setq line
  2288. (format
  2289. "%-4s%-14s"
  2290. (org-add-props (copy-sequence key)
  2291. '(face bold))
  2292. (cond
  2293. ((string-match "\\S-" desc) desc)
  2294. ((eq type 'agenda) "Agenda for current week or day")
  2295. ((eq type 'alltodo) "List of all TODO entries")
  2296. ((eq type 'search) "Word search")
  2297. ((eq type 'stuck) "List of stuck projects")
  2298. ((eq type 'todo) "TODO keyword")
  2299. ((eq type 'tags) "Tags query")
  2300. ((eq type 'tags-todo) "Tags (TODO)")
  2301. ((eq type 'tags-tree) "Tags tree")
  2302. ((eq type 'todo-tree) "TODO kwd tree")
  2303. ((eq type 'occur-tree) "Occur tree")
  2304. ((functionp type) (if (symbolp type)
  2305. (symbol-name type)
  2306. "Lambda expression"))
  2307. (t "???"))))
  2308. (if org-agenda-menu-show-matcher
  2309. (setq line
  2310. (concat line ": "
  2311. (cond
  2312. ((stringp match)
  2313. (setq match (copy-sequence match))
  2314. (org-add-props match nil 'face 'org-warning))
  2315. (match
  2316. (format "set of %d commands" (length match)))
  2317. (t ""))))
  2318. (if (org-string-nw-p match)
  2319. (add-text-properties
  2320. 0 (length line) (list 'help-echo
  2321. (concat "Matcher: "match)) line)))
  2322. (push line lines)))
  2323. (setq lines (nreverse lines))
  2324. (when prefixes
  2325. (mapc (lambda (x)
  2326. (push
  2327. (format "%s %s"
  2328. (org-add-props (char-to-string x)
  2329. nil 'face 'bold)
  2330. (or (cdr (assoc (concat selstring
  2331. (char-to-string x))
  2332. prefix-descriptions))
  2333. "Prefix key"))
  2334. lines))
  2335. prefixes))
  2336. ;; Check if we should display in two columns
  2337. (if org-agenda-menu-two-column
  2338. (progn
  2339. (setq n (length lines)
  2340. n1 (+ (/ n 2) (mod n 2))
  2341. right (nthcdr n1 lines)
  2342. left (copy-sequence lines))
  2343. (setcdr (nthcdr (1- n1) left) nil))
  2344. (setq left lines right nil))
  2345. (while left
  2346. (insert "\n" (pop left))
  2347. (when right
  2348. (if (< (current-column) 40)
  2349. (move-to-column 40 t)
  2350. (insert " "))
  2351. (insert (pop right))))
  2352. ;; Make the window the right size
  2353. (goto-char (point-min))
  2354. (if second-time
  2355. (if (not (pos-visible-in-window-p (point-max)))
  2356. (org-fit-window-to-buffer))
  2357. (setq second-time t)
  2358. (org-fit-window-to-buffer))
  2359. ;; Ask for selection
  2360. (message "Press key for agenda command%s:"
  2361. (if (or restrict-ok org-agenda-overriding-restriction)
  2362. (if org-agenda-overriding-restriction
  2363. " (restriction lock active)"
  2364. (if restriction
  2365. (format " (restricted to %s)" restriction)
  2366. " (unrestricted)"))
  2367. ""))
  2368. (setq c (read-char-exclusive))
  2369. (message "")
  2370. (cond
  2371. ((assoc (char-to-string c) custom)
  2372. (setq selstring (concat selstring (char-to-string c)))
  2373. (throw 'exit (cons selstring restriction)))
  2374. ((memq c prefixes)
  2375. (setq selstring (concat selstring (char-to-string c))
  2376. prefixes nil
  2377. rmheader (or rmheader t)
  2378. custom (delq nil (mapcar
  2379. (lambda (x)
  2380. (if (or (= (length (car x)) 1)
  2381. (/= (string-to-char (car x)) c))
  2382. nil
  2383. (cons (substring (car x) 1) (cdr x))))
  2384. custom))))
  2385. ((eq c ?*)
  2386. (org-toggle-sticky-agenda)
  2387. (sit-for 2))
  2388. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  2389. (message "Restriction is only possible in Org-mode buffers")
  2390. (ding) (sit-for 1))
  2391. ((eq c ?1)
  2392. (org-agenda-remove-restriction-lock 'noupdate)
  2393. (setq restriction 'buffer))
  2394. ((eq c ?0)
  2395. (org-agenda-remove-restriction-lock 'noupdate)
  2396. (setq restriction (if region-p 'region 'subtree)))
  2397. ((eq c ?<)
  2398. (org-agenda-remove-restriction-lock 'noupdate)
  2399. (setq restriction
  2400. (cond
  2401. ((eq restriction 'buffer)
  2402. (if region-p 'region 'subtree))
  2403. ((memq restriction '(subtree region))
  2404. nil)
  2405. (t 'buffer))))
  2406. ((eq c ?>)
  2407. (org-agenda-remove-restriction-lock 'noupdate)
  2408. (setq restriction nil))
  2409. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  2410. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  2411. ((and (> (length selstring) 0) (eq c ?\d))
  2412. (delete-window)
  2413. (org-agenda-get-restriction-and-command prefix-descriptions))
  2414. ((equal c ?q) (error "Abort"))
  2415. (t (error "Invalid key %c" c))))))))
  2416. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2417. (defvar org-agenda-last-arguments nil
  2418. "The arguments of the previous call to `org-agenda'.")
  2419. (defun org-agenda-run-series (name series)
  2420. (org-let (nth 1 series) '(org-prepare-agenda name))
  2421. ;; We need to reset agenda markers heree, because when constructing a
  2422. ;; block agenda, the individual blocks do not do that.
  2423. (org-agenda-reset-markers)
  2424. (let* ((org-agenda-multi t)
  2425. (redo (list 'org-agenda-run-series name (list 'quote series)))
  2426. (org-agenda-overriding-arguments
  2427. (or org-agenda-overriding-arguments
  2428. (unless (null (delq nil (get 'org-agenda-redo-command 'last-args)))
  2429. (get 'org-agenda-redo-command 'last-args))))
  2430. (cmds (car series))
  2431. (gprops (nth 1 series))
  2432. match ;; The byte compiler incorrectly complains about this. Keep it!
  2433. cmd type lprops)
  2434. (while (setq cmd (pop cmds))
  2435. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  2436. (cond
  2437. ((eq type 'agenda)
  2438. (org-let2 gprops lprops
  2439. '(call-interactively 'org-agenda-list)))
  2440. ((eq type 'alltodo)
  2441. (org-let2 gprops lprops
  2442. '(call-interactively 'org-todo-list)))
  2443. ((eq type 'search)
  2444. (org-let2 gprops lprops
  2445. '(org-search-view current-prefix-arg match nil)))
  2446. ((eq type 'stuck)
  2447. (org-let2 gprops lprops
  2448. '(call-interactively 'org-agenda-list-stuck-projects)))
  2449. ((eq type 'tags)
  2450. (org-let2 gprops lprops
  2451. '(org-tags-view current-prefix-arg match)))
  2452. ((eq type 'tags-todo)
  2453. (org-let2 gprops lprops
  2454. '(org-tags-view '(4) match)))
  2455. ((eq type 'todo)
  2456. (org-let2 gprops lprops
  2457. '(org-todo-list match)))
  2458. ((fboundp type)
  2459. (org-let2 gprops lprops
  2460. '(funcall type match)))
  2461. (t (error "Invalid type in command series"))))
  2462. (widen)
  2463. (setq org-agenda-redo-command redo)
  2464. (put 'org-agenda-redo-command 'last-args org-agenda-last-arguments)
  2465. (goto-char (point-min)))
  2466. (org-fit-agenda-window)
  2467. (org-let (nth 1 series) '(org-finalize-agenda)))
  2468. ;;;###autoload
  2469. (defmacro org-batch-agenda (cmd-key &rest parameters)
  2470. "Run an agenda command in batch mode and send the result to STDOUT.
  2471. If CMD-KEY is a string of length 1, it is used as a key in
  2472. `org-agenda-custom-commands' and triggers this command. If it is a
  2473. longer string it is used as a tags/todo match string.
  2474. Parameters are alternating variable names and values that will be bound
  2475. before running the agenda command."
  2476. (org-eval-in-environment (org-make-parameter-alist parameters)
  2477. (if (> (length cmd-key) 2)
  2478. (org-tags-view nil cmd-key)
  2479. (org-agenda nil cmd-key)))
  2480. (set-buffer org-agenda-buffer-name)
  2481. (princ (buffer-string)))
  2482. (def-edebug-spec org-batch-agenda (form &rest sexp))
  2483. (defvar org-agenda-info nil)
  2484. ;;;###autoload
  2485. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  2486. "Run an agenda command in batch mode and send the result to STDOUT.
  2487. If CMD-KEY is a string of length 1, it is used as a key in
  2488. `org-agenda-custom-commands' and triggers this command. If it is a
  2489. longer string it is used as a tags/todo match string.
  2490. Parameters are alternating variable names and values that will be bound
  2491. before running the agenda command.
  2492. The output gives a line for each selected agenda item. Each
  2493. item is a list of comma-separated values, like this:
  2494. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  2495. category The category of the item
  2496. head The headline, without TODO kwd, TAGS and PRIORITY
  2497. type The type of the agenda entry, can be
  2498. todo selected in TODO match
  2499. tagsmatch selected in tags match
  2500. diary imported from diary
  2501. deadline a deadline on given date
  2502. scheduled scheduled on given date
  2503. timestamp entry has timestamp on given date
  2504. closed entry was closed on given date
  2505. upcoming-deadline warning about deadline
  2506. past-scheduled forwarded scheduled item
  2507. block entry has date block including g. date
  2508. todo The todo keyword, if any
  2509. tags All tags including inherited ones, separated by colons
  2510. date The relevant date, like 2007-2-14
  2511. time The time, like 15:00-16:50
  2512. extra Sting with extra planning info
  2513. priority-l The priority letter if any was given
  2514. priority-n The computed numerical priority
  2515. agenda-day The day in the agenda where this is listed"
  2516. (org-eval-in-environment (append '((org-agenda-remove-tags t))
  2517. (org-make-parameter-alist parameters))
  2518. (if (> (length cmd-key) 2)
  2519. (org-tags-view nil cmd-key)
  2520. (org-agenda nil cmd-key)))
  2521. (set-buffer org-agenda-buffer-name)
  2522. (let* ((lines (org-split-string (buffer-string) "\n"))
  2523. line)
  2524. (while (setq line (pop lines))
  2525. (catch 'next
  2526. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2527. (setq org-agenda-info
  2528. (org-fix-agenda-info (text-properties-at 0 line)))
  2529. (princ
  2530. (mapconcat 'org-agenda-export-csv-mapper
  2531. '(org-category txt type todo tags date time extra
  2532. priority-letter priority agenda-day)
  2533. ","))
  2534. (princ "\n")))))
  2535. (def-edebug-spec org-batch-agenda-csv (form &rest sexp))
  2536. (defun org-fix-agenda-info (props)
  2537. "Make sure all properties on an agenda item have a canonical form.
  2538. This ensures the export commands can easily use it."
  2539. (let (tmp re)
  2540. (when (setq tmp (plist-get props 'tags))
  2541. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2542. (when (setq tmp (plist-get props 'date))
  2543. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2544. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2545. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2546. (setq tmp (calendar-date-string tmp)))
  2547. (setq props (plist-put props 'date tmp)))
  2548. (when (setq tmp (plist-get props 'day))
  2549. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2550. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2551. (setq tmp (calendar-date-string tmp)))
  2552. (setq props (plist-put props 'day tmp))
  2553. (setq props (plist-put props 'agenda-day tmp)))
  2554. (when (setq tmp (plist-get props 'txt))
  2555. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2556. (plist-put props 'priority-letter (match-string 1 tmp))
  2557. (setq tmp (replace-match "" t t tmp)))
  2558. (when (and (setq re (plist-get props 'org-todo-regexp))
  2559. (setq re (concat "\\`\\.*" re " ?"))
  2560. (string-match re tmp))
  2561. (plist-put props 'todo (match-string 1 tmp))
  2562. (setq tmp (replace-match "" t t tmp)))
  2563. (plist-put props 'txt tmp)))
  2564. props)
  2565. (defun org-agenda-export-csv-mapper (prop)
  2566. (let ((res (plist-get org-agenda-info prop)))
  2567. (setq res
  2568. (cond
  2569. ((not res) "")
  2570. ((stringp res) res)
  2571. (t (prin1-to-string res))))
  2572. (while (string-match "," res)
  2573. (setq res (replace-match ";" t t res))) ;
  2574. (org-trim res)))
  2575. ;;;###autoload
  2576. (defun org-store-agenda-views (&rest parameters)
  2577. (interactive)
  2578. (eval (list 'org-batch-store-agenda-views)))
  2579. ;;;###autoload
  2580. (defmacro org-batch-store-agenda-views (&rest parameters)
  2581. "Run all custom agenda commands that have a file argument."
  2582. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2583. (pop-up-frames nil)
  2584. (dir default-directory)
  2585. (pars (org-make-parameter-alist parameters))
  2586. cmd thiscmdkey files opts cmd-or-set)
  2587. (save-window-excursion
  2588. (while cmds
  2589. (setq cmd (pop cmds)
  2590. thiscmdkey (car cmd)
  2591. cmd-or-set (nth 2 cmd)
  2592. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2593. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2594. (if (stringp files) (setq files (list files)))
  2595. (when files
  2596. (org-eval-in-environment (append org-agenda-exporter-settings
  2597. opts pars)
  2598. (org-agenda nil thiscmdkey))
  2599. (set-buffer org-agenda-buffer-name)
  2600. (while files
  2601. (org-eval-in-environment (append org-agenda-exporter-settings
  2602. opts pars)
  2603. (org-agenda-write (expand-file-name (pop files) dir) nil t)))
  2604. (and (get-buffer org-agenda-buffer-name)
  2605. (kill-buffer org-agenda-buffer-name)))))))
  2606. (def-edebug-spec org-batch-store-agenda-views (&rest sexp))
  2607. (defun org-agenda-mark-header-line (pos)
  2608. "Mark the line at POS as an agenda structure header."
  2609. (save-excursion
  2610. (goto-char pos)
  2611. (put-text-property (point-at-bol) (point-at-eol)
  2612. 'org-agenda-structural-header t)
  2613. (when org-agenda-title-append
  2614. (put-text-property (point-at-bol) (point-at-eol)
  2615. 'org-agenda-title-append org-agenda-title-append))))
  2616. (defvar org-mobile-creating-agendas)
  2617. (defvar org-agenda-write-buffer-name "Agenda View")
  2618. (defun org-agenda-write (file &optional open nosettings)
  2619. "Write the current buffer (an agenda view) as a file.
  2620. Depending on the extension of the file name, plain text (.txt),
  2621. HTML (.html or .htm) or Postscript (.ps) is produced.
  2622. If the extension is .ics, run icalendar export over all files used
  2623. to construct the agenda and limit the export to entries listed in the
  2624. agenda now.
  2625. With prefix argument OPEN, open the new file immediately.
  2626. If NOSETTINGS is given, do not scope the settings of
  2627. `org-agenda-exporter-settings' into the export commands. This is used when
  2628. the settings have already been scoped and we do not wish to overrule other,
  2629. higher priority settings."
  2630. (interactive "FWrite agenda to file: \nP")
  2631. (if (not (file-writable-p file))
  2632. (error "Cannot write agenda to file %s" file))
  2633. (org-let (if nosettings nil org-agenda-exporter-settings)
  2634. '(save-excursion
  2635. (save-window-excursion
  2636. (org-agenda-mark-filtered-text)
  2637. (let ((bs (copy-sequence (buffer-string))) beg)
  2638. (org-agenda-unmark-filtered-text)
  2639. (with-temp-buffer
  2640. (rename-buffer org-agenda-write-buffer-name t)
  2641. (set-buffer-modified-p nil)
  2642. (insert bs)
  2643. (org-agenda-remove-marked-text 'org-filtered)
  2644. (while (setq beg (text-property-any (point-min) (point-max)
  2645. 'org-filtered t))
  2646. (delete-region
  2647. beg (or (next-single-property-change beg 'org-filtered)
  2648. (point-max))))
  2649. (run-hooks 'org-agenda-before-write-hook)
  2650. (cond
  2651. ((org-bound-and-true-p org-mobile-creating-agendas)
  2652. (org-mobile-write-agenda-for-mobile file))
  2653. ((string-match "\\.html?\\'" file)
  2654. (require 'htmlize)
  2655. (set-buffer (htmlize-buffer (current-buffer)))
  2656. (when (and org-agenda-export-html-style
  2657. (string-match "<style>" org-agenda-export-html-style))
  2658. ;; replace <style> section with org-agenda-export-html-style
  2659. (goto-char (point-min))
  2660. (kill-region (- (search-forward "<style") 6)
  2661. (search-forward "</style>"))
  2662. (insert org-agenda-export-html-style))
  2663. (write-file file)
  2664. (kill-buffer (current-buffer))
  2665. (message "HTML written to %s" file))
  2666. ((string-match "\\.ps\\'" file)
  2667. (require 'ps-print)
  2668. (ps-print-buffer-with-faces file)
  2669. (message "Postscript written to %s" file))
  2670. ((string-match "\\.pdf\\'" file)
  2671. (require 'ps-print)
  2672. (ps-print-buffer-with-faces
  2673. (concat (file-name-sans-extension file) ".ps"))
  2674. (call-process "ps2pdf" nil nil nil
  2675. (expand-file-name
  2676. (concat (file-name-sans-extension file) ".ps"))
  2677. (expand-file-name file))
  2678. (delete-file (concat (file-name-sans-extension file) ".ps"))
  2679. (message "PDF written to %s" file))
  2680. ((string-match "\\.ics\\'" file)
  2681. (require 'org-icalendar)
  2682. (let ((org-agenda-marker-table
  2683. (org-create-marker-find-array
  2684. (org-agenda-collect-markers)))
  2685. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2686. (org-combined-agenda-icalendar-file file))
  2687. (apply 'org-export-icalendar 'combine
  2688. (org-agenda-files nil 'ifmode))))
  2689. (t
  2690. (let ((bs (buffer-string)))
  2691. (find-file file)
  2692. (erase-buffer)
  2693. (insert bs)
  2694. (save-buffer 0)
  2695. (kill-buffer (current-buffer))
  2696. (message "Plain text written to %s" file))))))))
  2697. (set-buffer org-agenda-buffer-name))
  2698. (when open (org-open-file file)))
  2699. (defvar org-agenda-tag-filter-overlays nil)
  2700. (defvar org-agenda-cat-filter-overlays nil)
  2701. (defun org-agenda-mark-filtered-text ()
  2702. "Mark all text hidden by filtering with a text property."
  2703. (let ((inhibit-read-only t))
  2704. (mapc
  2705. (lambda (o)
  2706. (when (equal (overlay-buffer o) (current-buffer))
  2707. (put-text-property
  2708. (overlay-start o) (overlay-end o)
  2709. 'org-filtered t)))
  2710. (append org-agenda-tag-filter-overlays
  2711. org-agenda-cat-filter-overlays))))
  2712. (defun org-agenda-unmark-filtered-text ()
  2713. "Remove the filtering text property."
  2714. (let ((inhibit-read-only t))
  2715. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2716. (defun org-agenda-remove-marked-text (property &optional value)
  2717. "Delete all text marked with VALUE of PROPERTY.
  2718. VALUE defaults to t."
  2719. (let (beg)
  2720. (setq value (or value t))
  2721. (while (setq beg (text-property-any (point-min) (point-max)
  2722. property value))
  2723. (delete-region
  2724. beg (or (next-single-property-change beg 'org-filtered)
  2725. (point-max))))))
  2726. (defun org-agenda-add-entry-text ()
  2727. "Add entry text to agenda lines.
  2728. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2729. entry text following headings shown in the agenda.
  2730. Drawers will be excluded, also the line with scheduling/deadline info."
  2731. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2732. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2733. (let (m txt)
  2734. (goto-char (point-min))
  2735. (while (not (eobp))
  2736. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2737. (beginning-of-line 2)
  2738. (setq txt (org-agenda-get-some-entry-text
  2739. m org-agenda-add-entry-text-maxlines " > "))
  2740. (end-of-line 1)
  2741. (if (string-match "\\S-" txt)
  2742. (insert "\n" txt)
  2743. (or (eobp) (forward-char 1))))))))
  2744. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2745. &rest keep)
  2746. "Extract entry text from MARKER, at most N-LINES lines.
  2747. This will ignore drawers etc, just get the text.
  2748. If INDENT is given, prefix every line with this string. If KEEP is
  2749. given, it is a list of symbols, defining stuff that should not be
  2750. removed from the entry content. Currently only `planning' is allowed here."
  2751. (let (txt drawer-re kwd-time-re ind)
  2752. (save-excursion
  2753. (with-current-buffer (marker-buffer marker)
  2754. (if (not (eq major-mode 'org-mode))
  2755. (setq txt "")
  2756. (save-excursion
  2757. (save-restriction
  2758. (widen)
  2759. (goto-char marker)
  2760. (end-of-line 1)
  2761. (setq txt (buffer-substring
  2762. (min (1+ (point)) (point-max))
  2763. (progn (outline-next-heading) (point)))
  2764. drawer-re org-drawer-regexp
  2765. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2766. ".*\n?"))
  2767. (with-temp-buffer
  2768. (insert txt)
  2769. (when org-agenda-add-entry-text-descriptive-links
  2770. (goto-char (point-min))
  2771. (while (org-activate-bracket-links (point-max))
  2772. (add-text-properties (match-beginning 0) (match-end 0)
  2773. '(face org-link))))
  2774. (goto-char (point-min))
  2775. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2776. (set-text-properties (match-beginning 0) (match-end 0)
  2777. nil))
  2778. (goto-char (point-min))
  2779. (while (re-search-forward drawer-re nil t)
  2780. (delete-region
  2781. (match-beginning 0)
  2782. (progn (re-search-forward
  2783. "^[ \t]*:END:.*\n?" nil 'move)
  2784. (point))))
  2785. (unless (member 'planning keep)
  2786. (goto-char (point-min))
  2787. (while (re-search-forward kwd-time-re nil t)
  2788. (replace-match "")))
  2789. (goto-char (point-min))
  2790. (when org-agenda-entry-text-exclude-regexps
  2791. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2792. (while (setq re (pop re-list))
  2793. (goto-char (point-min))
  2794. (while (re-search-forward re nil t)
  2795. (replace-match "")))))
  2796. (goto-char (point-max))
  2797. (skip-chars-backward " \t\n")
  2798. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2799. ;; find and remove min common indentation
  2800. (goto-char (point-min))
  2801. (untabify (point-min) (point-max))
  2802. (setq ind (org-get-indentation))
  2803. (while (not (eobp))
  2804. (unless (looking-at "[ \t]*$")
  2805. (setq ind (min ind (org-get-indentation))))
  2806. (beginning-of-line 2))
  2807. (goto-char (point-min))
  2808. (while (not (eobp))
  2809. (unless (looking-at "[ \t]*$")
  2810. (move-to-column ind)
  2811. (delete-region (point-at-bol) (point)))
  2812. (beginning-of-line 2))
  2813. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2814. (goto-char (point-min))
  2815. (when indent
  2816. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2817. (replace-match indent t t)))
  2818. (goto-char (point-min))
  2819. (while (looking-at "[ \t]*\n") (replace-match ""))
  2820. (goto-char (point-max))
  2821. (when (> (org-current-line)
  2822. n-lines)
  2823. (org-goto-line (1+ n-lines))
  2824. (backward-char 1))
  2825. (setq txt (buffer-substring (point-min) (point)))))))))
  2826. txt))
  2827. (defun org-agenda-collect-markers ()
  2828. "Collect the markers pointing to entries in the agenda buffer."
  2829. (let (m markers)
  2830. (save-excursion
  2831. (goto-char (point-min))
  2832. (while (not (eobp))
  2833. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2834. (org-get-at-bol 'org-marker)))
  2835. (push m markers))
  2836. (beginning-of-line 2)))
  2837. (nreverse markers)))
  2838. (defun org-create-marker-find-array (marker-list)
  2839. "Create a alist of files names with all marker positions in that file."
  2840. (let (f tbl m a p)
  2841. (while (setq m (pop marker-list))
  2842. (setq p (marker-position m)
  2843. f (buffer-file-name (or (buffer-base-buffer
  2844. (marker-buffer m))
  2845. (marker-buffer m))))
  2846. (if (setq a (assoc f tbl))
  2847. (push (marker-position m) (cdr a))
  2848. (push (list f p) tbl)))
  2849. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2850. tbl)))
  2851. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2852. (defun org-check-agenda-marker-table ()
  2853. "Check of the current entry is on the marker list."
  2854. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2855. a)
  2856. (and (setq a (assoc file org-agenda-marker-table))
  2857. (save-match-data
  2858. (save-excursion
  2859. (org-back-to-heading t)
  2860. (member (point) (cdr a)))))))
  2861. (defun org-check-for-org-mode ()
  2862. "Make sure current buffer is in org-mode. Error if not."
  2863. (or (eq major-mode 'org-mode)
  2864. (error "Cannot execute org-mode agenda command on buffer in %s"
  2865. major-mode)))
  2866. (defun org-fit-agenda-window ()
  2867. "Fit the window to the buffer size."
  2868. (and (memq org-agenda-window-setup '(reorganize-frame))
  2869. (fboundp 'fit-window-to-buffer)
  2870. (org-fit-window-to-buffer
  2871. nil
  2872. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2873. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2874. ;;; Agenda prepare and finalize
  2875. (defvar org-agenda-multi nil) ; dynamically scoped
  2876. (defvar org-agenda-buffer-name "*Org Agenda*")
  2877. (defvar org-pre-agenda-window-conf nil)
  2878. (defvar org-agenda-columns-active nil)
  2879. (defvar org-agenda-name nil)
  2880. (defvar org-agenda-tag-filter nil)
  2881. (defvar org-agenda-category-filter nil)
  2882. (defvar org-agenda-tag-filter-while-redo nil) ; dynamically scoped
  2883. (defvar org-agenda-tag-filter-preset nil
  2884. "A preset of the tags filter used for secondary agenda filtering.
  2885. This must be a list of strings, each string must be a single tag preceded
  2886. by \"+\" or \"-\".
  2887. This variable should not be set directly, but agenda custom commands can
  2888. bind it in the options section. The preset filter is a global property of
  2889. the entire agenda view. In a block agenda, it will not work reliably to
  2890. define a filter for one of the individual blocks. You need to set it in
  2891. the global options and expect it to be applied to the entire view.")
  2892. (defvar org-agenda-category-filter-preset nil
  2893. "A preset of the category filter used for secondary agenda filtering.
  2894. This must be a list of strings, each string must be a single category
  2895. preceded by \"+\" or \"-\".
  2896. This variable should not be set directly, but agenda custom commands can
  2897. bind it in the options section. The preset filter is a global property of
  2898. the entire agenda view. In a block agenda, it will not work reliably to
  2899. define a filter for one of the individual blocks. You need to set it in
  2900. the global options and expect it to be applied to the entire view.")
  2901. (defun org-agenda-use-sticky-p ()
  2902. "Return non-NIL if existing agenda buffer named
  2903. `org-agenda-buffer-name' exists, and should be shown instead of
  2904. generating a new one"
  2905. (and
  2906. ;; turned off by user
  2907. org-agenda-sticky
  2908. ;; For multi-agenda buffer already exists
  2909. (not org-agenda-multi)
  2910. ;; buffer found
  2911. (get-buffer org-agenda-buffer-name)
  2912. ;; C-u parameter is same as last call
  2913. (with-current-buffer (get-buffer org-agenda-buffer-name)
  2914. (and
  2915. (equal current-prefix-arg
  2916. org-agenda-last-prefix-arg)
  2917. ;; In case user turned stickiness on, while having existing
  2918. ;; Agenda buffer active, don't reuse that buffer, because it
  2919. ;; does not have org variables local
  2920. org-agenda-this-buffer-is-sticky))))
  2921. (defun org-prepare-agenda-window (abuf)
  2922. "Setup agenda buffer in the window"
  2923. (let* ((awin (get-buffer-window abuf))
  2924. wconf)
  2925. (cond
  2926. ((equal (current-buffer) abuf) nil)
  2927. (awin (select-window awin))
  2928. ((not (setq wconf (current-window-configuration))))
  2929. ((equal org-agenda-window-setup 'current-window)
  2930. (org-pop-to-buffer-same-window abuf))
  2931. ((equal org-agenda-window-setup 'other-window)
  2932. (org-switch-to-buffer-other-window abuf))
  2933. ((equal org-agenda-window-setup 'other-frame)
  2934. (switch-to-buffer-other-frame abuf))
  2935. ((equal org-agenda-window-setup 'reorganize-frame)
  2936. (delete-other-windows)
  2937. (org-switch-to-buffer-other-window abuf)))
  2938. ;; additional test in case agenda is invoked from within agenda
  2939. ;; buffer via elisp link
  2940. (unless (equal (current-buffer) abuf)
  2941. (org-pop-to-buffer-same-window abuf))
  2942. (setq org-pre-agenda-window-conf wconf)))
  2943. (defun org-prepare-agenda (&optional name)
  2944. (if (org-agenda-use-sticky-p)
  2945. (progn
  2946. ;; Popup existing buffer
  2947. (org-prepare-agenda-window (get-buffer org-agenda-buffer-name))
  2948. (message "Sticky Agenda buffer, use `r' to refresh")
  2949. (throw 'exit nil))
  2950. (setq org-todo-keywords-for-agenda nil)
  2951. (setq org-done-keywords-for-agenda nil)
  2952. (setq org-drawers-for-agenda nil)
  2953. (unless org-agenda-persistent-filter
  2954. (setq org-agenda-tag-filter nil
  2955. org-agenda-category-filter nil))
  2956. (put 'org-agenda-tag-filter :preset-filter org-agenda-tag-filter-preset)
  2957. (put 'org-agenda-category-filter :preset-filter
  2958. org-agenda-category-filter-preset)
  2959. (if org-agenda-multi
  2960. (progn
  2961. (setq buffer-read-only nil)
  2962. (goto-char (point-max))
  2963. (unless (or (bobp) org-agenda-compact-blocks
  2964. (not org-agenda-block-separator))
  2965. (insert "\n"
  2966. (if (stringp org-agenda-block-separator)
  2967. org-agenda-block-separator
  2968. (make-string (window-width) org-agenda-block-separator))
  2969. "\n"))
  2970. (narrow-to-region (point) (point-max)))
  2971. ;; any org variables need to be set after being in agenda buffer
  2972. ;; since they are now buffer local
  2973. (org-prepare-agenda-window (get-buffer-create org-agenda-buffer-name))
  2974. (setq buffer-read-only nil)
  2975. (org-agenda-reset-markers)
  2976. (let ((inhibit-read-only t)) (erase-buffer))
  2977. (org-agenda-mode)
  2978. (setq org-agenda-buffer (current-buffer))
  2979. (setq org-agenda-contributing-files nil)
  2980. (setq org-agenda-columns-active nil)
  2981. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2982. (setq org-todo-keywords-for-agenda
  2983. (org-uniquify org-todo-keywords-for-agenda))
  2984. (setq org-done-keywords-for-agenda
  2985. (org-uniquify org-done-keywords-for-agenda))
  2986. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2987. (setq org-agenda-last-prefix-arg current-prefix-arg)
  2988. (setq org-agenda-this-buffer-name org-agenda-buffer-name)
  2989. (and name (not org-agenda-name)
  2990. (org-set-local 'org-agenda-name name)))
  2991. (setq buffer-read-only nil)))
  2992. (defun org-finalize-agenda ()
  2993. "Finishing touch for the agenda buffer, called just before displaying it."
  2994. (unless org-agenda-multi
  2995. (save-excursion
  2996. (let ((inhibit-read-only t))
  2997. (goto-char (point-min))
  2998. (while (org-activate-bracket-links (point-max))
  2999. (add-text-properties (match-beginning 0) (match-end 0)
  3000. '(face org-link)))
  3001. (org-agenda-align-tags)
  3002. (unless org-agenda-with-colors
  3003. (remove-text-properties (point-min) (point-max) '(face nil))))
  3004. (if (and (boundp 'org-agenda-overriding-columns-format)
  3005. org-agenda-overriding-columns-format)
  3006. (org-set-local 'org-agenda-overriding-columns-format
  3007. org-agenda-overriding-columns-format))
  3008. (if (and (boundp 'org-agenda-view-columns-initially)
  3009. org-agenda-view-columns-initially)
  3010. (org-agenda-columns))
  3011. (when org-agenda-fontify-priorities
  3012. (org-agenda-fontify-priorities))
  3013. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  3014. (org-agenda-dim-blocked-tasks))
  3015. (org-agenda-mark-clocking-task)
  3016. (when org-agenda-entry-text-mode
  3017. (org-agenda-entry-text-hide)
  3018. (org-agenda-entry-text-show))
  3019. (if (functionp 'org-habit-insert-consistency-graphs)
  3020. (org-habit-insert-consistency-graphs))
  3021. (run-hooks 'org-finalize-agenda-hook)
  3022. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  3023. (when (or org-agenda-tag-filter (get 'org-agenda-tag-filter :preset-filter))
  3024. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  3025. (when (or org-agenda-category-filter (get 'org-agenda-category-filter :preset-filter))
  3026. (org-agenda-filter-apply org-agenda-category-filter 'category))
  3027. (org-add-hook 'kill-buffer-hook 'org-agenda-reset-markers 'append 'local)
  3028. )))
  3029. (defun org-agenda-mark-clocking-task ()
  3030. "Mark the current clock entry in the agenda if it is present."
  3031. (mapc (lambda (o)
  3032. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  3033. (delete-overlay o)))
  3034. (overlays-in (point-min) (point-max)))
  3035. (when (marker-buffer org-clock-hd-marker)
  3036. (save-excursion
  3037. (goto-char (point-min))
  3038. (let (s ov)
  3039. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  3040. (goto-char s)
  3041. (when (equal (org-get-at-bol 'org-hd-marker)
  3042. org-clock-hd-marker)
  3043. (setq ov (make-overlay (point-at-bol) (1+ (point-at-eol))))
  3044. (overlay-put ov 'type 'org-agenda-clocking)
  3045. (overlay-put ov 'face 'org-agenda-clocking)
  3046. (overlay-put ov 'help-echo
  3047. "The clock is running in this item")))))))
  3048. (defun org-agenda-fontify-priorities ()
  3049. "Make highest priority lines bold, and lowest italic."
  3050. (interactive)
  3051. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-priority)
  3052. (delete-overlay o)))
  3053. (overlays-in (point-min) (point-max)))
  3054. (save-excursion
  3055. (let ((inhibit-read-only t)
  3056. b e p ov h l)
  3057. (goto-char (point-min))
  3058. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  3059. (setq h (or (get-char-property (point) 'org-highest-priority)
  3060. org-highest-priority)
  3061. l (or (get-char-property (point) 'org-lowest-priority)
  3062. org-lowest-priority)
  3063. p (string-to-char (match-string 1))
  3064. b (match-beginning 0)
  3065. e (if (eq org-agenda-fontify-priorities 'cookies)
  3066. (match-end 0)
  3067. (point-at-eol))
  3068. ov (make-overlay b e))
  3069. (overlay-put
  3070. ov 'face
  3071. (cond ((org-face-from-face-or-color
  3072. 'priority nil
  3073. (cdr (assoc p org-priority-faces))))
  3074. ((and (listp org-agenda-fontify-priorities)
  3075. (org-face-from-face-or-color
  3076. 'priority nil
  3077. (cdr (assoc p org-agenda-fontify-priorities)))))
  3078. ((equal p l) 'italic)
  3079. ((equal p h) 'bold)))
  3080. (overlay-put ov 'org-type 'org-priority)))))
  3081. (defun org-agenda-dim-blocked-tasks ()
  3082. "Dim currently blocked TODO's in the agenda display."
  3083. (mapc (lambda (o) (if (eq (overlay-get o 'org-type) 'org-blocked-todo)
  3084. (delete-overlay o)))
  3085. (overlays-in (point-min) (point-max)))
  3086. (save-excursion
  3087. (let ((inhibit-read-only t)
  3088. (org-depend-tag-blocked nil)
  3089. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  3090. org-blocked-by-checkboxes
  3091. invis1 b e p ov h l)
  3092. (goto-char (point-min))
  3093. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  3094. (and pos (goto-char (1+ pos))))
  3095. (setq org-blocked-by-checkboxes nil invis1 invis)
  3096. (let ((marker (org-get-at-bol 'org-hd-marker)))
  3097. (when (and marker
  3098. (with-current-buffer (marker-buffer marker)
  3099. (save-excursion (goto-char marker)
  3100. (org-entry-blocked-p))))
  3101. (if org-blocked-by-checkboxes (setq invis1 nil))
  3102. (setq b (if invis1
  3103. (max (point-min) (1- (point-at-bol)))
  3104. (point-at-bol))
  3105. e (point-at-eol)
  3106. ov (make-overlay b e))
  3107. (if invis1
  3108. (overlay-put ov 'invisible t)
  3109. (overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  3110. (overlay-put ov 'org-type 'org-blocked-todo)))))))
  3111. (defvar org-agenda-skip-function nil
  3112. "Function to be called at each match during agenda construction.
  3113. If this function returns nil, the current match should not be skipped.
  3114. Otherwise, the function must return a position from where the search
  3115. should be continued.
  3116. This may also be a Lisp form, it will be evaluated.
  3117. Never set this variable using `setq' or so, because then it will apply
  3118. to all future agenda commands. If you do want a global skipping condition,
  3119. use the option `org-agenda-skip-function-global' instead.
  3120. The correct usage for `org-agenda-skip-function' is to bind it with
  3121. `let' to scope it dynamically into the agenda-constructing command.
  3122. A good way to set it is through options in `org-agenda-custom-commands'.")
  3123. (defun org-agenda-skip ()
  3124. "Throw to `:skip' in places that should be skipped.
  3125. Also moves point to the end of the skipped region, so that search can
  3126. continue from there."
  3127. (let ((p (point-at-bol)) to)
  3128. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  3129. (get-text-property p :org-archived)
  3130. (org-end-of-subtree t)
  3131. (throw :skip t))
  3132. (and org-agenda-skip-comment-trees
  3133. (get-text-property p :org-comment)
  3134. (org-end-of-subtree t)
  3135. (throw :skip t))
  3136. (if (equal (char-after p) ?#) (throw :skip t))
  3137. (when (setq to (or (org-agenda-skip-eval org-agenda-skip-function-global)
  3138. (org-agenda-skip-eval org-agenda-skip-function)))
  3139. (goto-char to)
  3140. (throw :skip t))))
  3141. (defun org-agenda-skip-eval (form)
  3142. "If FORM is a function or a list, call (or eval) is and return result.
  3143. `save-excursion' and `save-match-data' are wrapped around the call, so point
  3144. and match data are returned to the previous state no matter what these
  3145. functions do."
  3146. (let (fp)
  3147. (and form
  3148. (or (setq fp (functionp form))
  3149. (consp form))
  3150. (save-excursion
  3151. (save-match-data
  3152. (if fp
  3153. (funcall form)
  3154. (eval form)))))))
  3155. (defvar org-agenda-markers nil
  3156. "List of all currently active markers created by `org-agenda'.")
  3157. (defvar org-agenda-last-marker-time (org-float-time)
  3158. "Creation time of the last agenda marker.")
  3159. (defun org-agenda-new-marker (&optional pos)
  3160. "Return a new agenda marker.
  3161. Org-mode keeps a list of these markers and resets them when they are
  3162. no longer in use."
  3163. (let ((m (copy-marker (or pos (point)))))
  3164. (setq org-agenda-last-marker-time (org-float-time))
  3165. (with-current-buffer org-agenda-buffer
  3166. (push m org-agenda-markers))
  3167. m))
  3168. (defun org-agenda-reset-markers ()
  3169. "Reset markers created by `org-agenda'."
  3170. (while org-agenda-markers
  3171. (move-marker (pop org-agenda-markers) nil)))
  3172. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  3173. "Save relative positions of markers in region.
  3174. This check for agenda markers in all agenda buffers currently active."
  3175. (dolist (buf (buffer-list))
  3176. (with-current-buffer buf
  3177. (when (eq major-mode 'org-agenda-mode)
  3178. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  3179. org-agenda-markers)))))
  3180. ;;; Entry text mode
  3181. (defun org-agenda-entry-text-show-here ()
  3182. "Add some text from the entry as context to the current line."
  3183. (let (m txt o)
  3184. (setq m (org-get-at-bol 'org-hd-marker))
  3185. (unless (marker-buffer m)
  3186. (error "No marker points to an entry here"))
  3187. (setq txt (concat "\n" (org-no-properties
  3188. (org-agenda-get-some-entry-text
  3189. m org-agenda-entry-text-maxlines " > "))))
  3190. (when (string-match "\\S-" txt)
  3191. (setq o (make-overlay (point-at-bol) (point-at-eol)))
  3192. (overlay-put o 'evaporate t)
  3193. (overlay-put o 'org-overlay-type 'agenda-entry-content)
  3194. (overlay-put o 'after-string txt))))
  3195. (defun org-agenda-entry-text-show ()
  3196. "Add entry context for all agenda lines."
  3197. (interactive)
  3198. (save-excursion
  3199. (goto-char (point-max))
  3200. (beginning-of-line 1)
  3201. (while (not (bobp))
  3202. (when (org-get-at-bol 'org-hd-marker)
  3203. (org-agenda-entry-text-show-here))
  3204. (beginning-of-line 0))))
  3205. (defun org-agenda-entry-text-hide ()
  3206. "Remove any shown entry context."
  3207. (delq nil
  3208. (mapcar (lambda (o)
  3209. (if (eq (overlay-get o 'org-overlay-type)
  3210. 'agenda-entry-content)
  3211. (progn (delete-overlay o) t)))
  3212. (overlays-in (point-min) (point-max)))))
  3213. (defun org-agenda-get-day-face (date)
  3214. "Return the face DATE should be displayed with."
  3215. (or (and (functionp org-agenda-day-face-function)
  3216. (funcall org-agenda-day-face-function date))
  3217. (cond ((org-agenda-todayp date)
  3218. 'org-agenda-date-today)
  3219. ((member (calendar-day-of-week date) org-agenda-weekend-days)
  3220. 'org-agenda-date-weekend)
  3221. (t 'org-agenda-date))))
  3222. ;;; Agenda timeline
  3223. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  3224. (defun org-timeline (&optional dotodo)
  3225. "Show a time-sorted view of the entries in the current org file.
  3226. Only entries with a time stamp of today or later will be listed. With
  3227. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  3228. under the current date.
  3229. If the buffer contains an active region, only check the region for
  3230. dates."
  3231. (interactive "P")
  3232. (let* ((dopast t)
  3233. (org-agenda-show-log-scoped org-agenda-show-log)
  3234. (entry (buffer-file-name (or (buffer-base-buffer (current-buffer))
  3235. (current-buffer))))
  3236. (date (calendar-current-date))
  3237. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  3238. (end (if (org-region-active-p) (region-end) (point-max)))
  3239. (day-numbers (org-get-all-dates
  3240. beg end 'no-ranges
  3241. t org-agenda-show-log-scoped ; always include today
  3242. org-timeline-show-empty-dates))
  3243. (org-deadline-warning-days 0)
  3244. (org-agenda-only-exact-dates t)
  3245. (today (org-today))
  3246. (past t)
  3247. args
  3248. s e rtn d emptyp)
  3249. (setq org-agenda-redo-command
  3250. (list 'progn
  3251. (list 'org-switch-to-buffer-other-window (current-buffer))
  3252. (list 'org-timeline (list 'quote dotodo))))
  3253. (if (not dopast)
  3254. ;; Remove past dates from the list of dates.
  3255. (setq day-numbers (delq nil (mapcar (lambda(x)
  3256. (if (>= x today) x nil))
  3257. day-numbers))))
  3258. (org-prepare-agenda (concat "Timeline " (file-name-nondirectory entry)))
  3259. (org-compile-prefix-format 'timeline)
  3260. (org-set-sorting-strategy 'timeline)
  3261. (if org-agenda-show-log-scoped (push :closed args))
  3262. (push :timestamp args)
  3263. (push :deadline args)
  3264. (push :scheduled args)
  3265. (push :sexp args)
  3266. (if dotodo (push :todo args))
  3267. (insert "Timeline of file " entry "\n")
  3268. (add-text-properties (point-min) (point)
  3269. (list 'face 'org-agenda-structure))
  3270. (org-agenda-mark-header-line (point-min))
  3271. (while (setq d (pop day-numbers))
  3272. (if (and (listp d) (eq (car d) :omitted))
  3273. (progn
  3274. (setq s (point))
  3275. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  3276. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  3277. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  3278. (if (and (>= d today)
  3279. dopast
  3280. past)
  3281. (progn
  3282. (setq past nil)
  3283. (insert (make-string 79 ?-) "\n")))
  3284. (setq date (calendar-gregorian-from-absolute d))
  3285. (setq s (point))
  3286. (setq rtn (and (not emptyp)
  3287. (apply 'org-agenda-get-day-entries entry
  3288. date args)))
  3289. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  3290. (progn
  3291. (insert
  3292. (if (stringp org-agenda-format-date)
  3293. (format-time-string org-agenda-format-date
  3294. (org-time-from-absolute date))
  3295. (funcall org-agenda-format-date date))
  3296. "\n")
  3297. (put-text-property s (1- (point)) 'face
  3298. (org-agenda-get-day-face date))
  3299. (put-text-property s (1- (point)) 'org-date-line t)
  3300. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3301. (if (equal d today)
  3302. (put-text-property s (1- (point)) 'org-today t))
  3303. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  3304. (put-text-property s (1- (point)) 'day d)))))
  3305. (goto-char (point-min))
  3306. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  3307. (point-min)))
  3308. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  3309. (org-finalize-agenda)
  3310. (setq buffer-read-only t)))
  3311. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  3312. "Return a list of all relevant day numbers from BEG to END buffer positions.
  3313. If NO-RANGES is non-nil, include only the start and end dates of a range,
  3314. not every single day in the range. If FORCE-TODAY is non-nil, make
  3315. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  3316. inactive time stamps (those in square brackets) are included.
  3317. When EMPTY is non-nil, also include days without any entries."
  3318. (let ((re (concat
  3319. (if pre-re pre-re "")
  3320. (if inactive org-ts-regexp-both org-ts-regexp)))
  3321. dates dates1 date day day1 day2 ts1 ts2 pos)
  3322. (if force-today
  3323. (setq dates (list (org-today))))
  3324. (save-excursion
  3325. (goto-char beg)
  3326. (while (re-search-forward re end t)
  3327. (setq day (time-to-days (org-time-string-to-time
  3328. (substring (match-string 1) 0 10)
  3329. (current-buffer) (match-beginning 0))))
  3330. (or (memq day dates) (push day dates)))
  3331. (unless no-ranges
  3332. (goto-char beg)
  3333. (while (re-search-forward org-tr-regexp end t)
  3334. (setq pos (match-beginning 0))
  3335. (setq ts1 (substring (match-string 1) 0 10)
  3336. ts2 (substring (match-string 2) 0 10)
  3337. day1 (time-to-days (org-time-string-to-time
  3338. ts1 (current-buffer) pos))
  3339. day2 (time-to-days (org-time-string-to-time
  3340. ts2 (current-buffer) pos)))
  3341. (while (< (setq day1 (1+ day1)) day2)
  3342. (or (memq day1 dates) (push day1 dates)))))
  3343. (setq dates (sort dates '<))
  3344. (when empty
  3345. (while (setq day (pop dates))
  3346. (setq day2 (car dates))
  3347. (push day dates1)
  3348. (when (and day2 empty)
  3349. (if (or (eq empty t)
  3350. (and (numberp empty) (<= (- day2 day) empty)))
  3351. (while (< (setq day (1+ day)) day2)
  3352. (push (list day) dates1))
  3353. (push (cons :omitted (- day2 day)) dates1))))
  3354. (setq dates (nreverse dates1)))
  3355. dates)))
  3356. ;;; Agenda Daily/Weekly
  3357. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  3358. "Start day for the agenda view.
  3359. Custom commands can set this variable in the options section.")
  3360. (defvar org-starting-day nil) ; local variable in the agenda buffer
  3361. (defvar org-agenda-current-span nil
  3362. "The current span used in the agenda view.") ; local variable in the agenda buffer
  3363. (defvar org-arg-loc nil) ; local variable
  3364. (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
  3365. "List of types searched for when creating the daily/weekly agenda.
  3366. This variable is a list of symbols that controls the types of
  3367. items that appear in the daily/weekly agenda. Allowed symbols in this
  3368. list are are
  3369. :timestamp List items containing a date stamp or date range matching
  3370. the selected date. This includes sexp entries in
  3371. angular brackets.
  3372. :sexp List entries resulting from plain diary-like sexps.
  3373. :deadline List deadline due on that date. When the date is today,
  3374. also list any deadlines past due, or due within
  3375. `org-deadline-warning-days'. `:deadline' must appear before
  3376. `:scheduled' if the setting of
  3377. `org-agenda-skip-scheduled-if-deadline-is-shown' is to have
  3378. any effect.
  3379. :scheduled List all items which are scheduled for the given date.
  3380. The diary for *today* also contains items which were
  3381. scheduled earlier and are not yet marked DONE.
  3382. By default, all four types are turned on.
  3383. Never set this variable globally using `setq', because then it
  3384. will apply to all future agenda commands. Instead, bind it with
  3385. `let' to scope it dynamically into the agenda-constructing
  3386. command. A good way to set it is through options in
  3387. `org-agenda-custom-commands'. For a more flexible (though
  3388. somewhat less efficient) way of determining what is included in
  3389. the daily/weekly agenda, see `org-agenda-skip-function'.")
  3390. ;;;###autoload
  3391. (defun org-agenda-list (&optional arg start-day span)
  3392. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  3393. The view will be for the current day or week, but from the overview buffer
  3394. you will be able to go to other days/weeks.
  3395. With a numeric prefix argument in an interactive call, the agenda will
  3396. span ARG days. Lisp programs should instead specify SPAN to change
  3397. the number of days. SPAN defaults to `org-agenda-span'.
  3398. START-DAY defaults to TODAY, or to the most recent match for the weekday
  3399. given in `org-agenda-start-on-weekday'."
  3400. (interactive "P")
  3401. (if (and (integerp arg) (> arg 0))
  3402. (setq span arg arg nil))
  3403. (org-prepare-agenda "Day/Week")
  3404. (setq start-day (or start-day org-agenda-start-day))
  3405. (if org-agenda-overriding-arguments
  3406. (setq arg (car org-agenda-overriding-arguments)
  3407. start-day (nth 1 org-agenda-overriding-arguments)
  3408. span (nth 2 org-agenda-overriding-arguments)))
  3409. (if (stringp start-day)
  3410. ;; Convert to an absolute day number
  3411. (setq start-day (time-to-days (org-read-date nil t start-day))))
  3412. (setq org-agenda-last-arguments (list arg start-day span))
  3413. (org-compile-prefix-format 'agenda)
  3414. (org-set-sorting-strategy 'agenda)
  3415. (let* ((span (org-agenda-ndays-to-span
  3416. (or span org-agenda-ndays org-agenda-span)))
  3417. (today (org-today))
  3418. (sd (or start-day today))
  3419. (ndays (org-agenda-span-to-ndays span sd))
  3420. (org-agenda-start-on-weekday
  3421. (if (eq ndays 7)
  3422. org-agenda-start-on-weekday))
  3423. (thefiles (org-agenda-files nil 'ifmode))
  3424. (files thefiles)
  3425. (start (if (or (null org-agenda-start-on-weekday)
  3426. (< ndays 7))
  3427. sd
  3428. (let* ((nt (calendar-day-of-week
  3429. (calendar-gregorian-from-absolute sd)))
  3430. (n1 org-agenda-start-on-weekday)
  3431. (d (- nt n1)))
  3432. (- sd (+ (if (< d 0) 7 0) d)))))
  3433. (day-numbers (list start))
  3434. (day-cnt 0)
  3435. (inhibit-redisplay (not debug-on-error))
  3436. (org-agenda-show-log-scoped org-agenda-show-log)
  3437. s e rtn rtnall file date d start-pos end-pos todayp
  3438. clocktable-start clocktable-end filter)
  3439. (setq org-agenda-redo-command
  3440. (list 'org-agenda-list (list 'quote arg) start-day (list 'quote span)))
  3441. (dotimes (n (1- ndays))
  3442. (push (1+ (car day-numbers)) day-numbers))
  3443. (setq day-numbers (nreverse day-numbers))
  3444. (setq clocktable-start (car day-numbers)
  3445. clocktable-end (1+ (or (org-last day-numbers) 0)))
  3446. (org-set-local 'org-starting-day (car day-numbers))
  3447. (org-set-local 'org-arg-loc arg)
  3448. (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
  3449. (unless org-agenda-compact-blocks
  3450. (let* ((d1 (car day-numbers))
  3451. (d2 (org-last day-numbers))
  3452. (w1 (org-days-to-iso-week d1))
  3453. (w2 (org-days-to-iso-week d2)))
  3454. (setq s (point))
  3455. (if org-agenda-overriding-header
  3456. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3457. nil 'face 'org-agenda-structure) "\n")
  3458. (insert (org-agenda-span-name span)
  3459. "-agenda"
  3460. (if (< (- d2 d1) 350)
  3461. (if (= w1 w2)
  3462. (format " (W%02d)" w1)
  3463. (format " (W%02d-W%02d)" w1 w2))
  3464. "")
  3465. ":\n")))
  3466. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  3467. 'org-date-line t))
  3468. (org-agenda-mark-header-line s))
  3469. (while (setq d (pop day-numbers))
  3470. (setq date (calendar-gregorian-from-absolute d)
  3471. s (point))
  3472. (if (or (setq todayp (= d today))
  3473. (and (not start-pos) (= d sd)))
  3474. (setq start-pos (point))
  3475. (if (and start-pos (not end-pos))
  3476. (setq end-pos (point))))
  3477. (setq files thefiles
  3478. rtnall nil)
  3479. (while (setq file (pop files))
  3480. (catch 'nextfile
  3481. (org-check-agenda-file file)
  3482. (let ((org-agenda-entry-types org-agenda-entry-types))
  3483. (unless org-agenda-include-deadlines
  3484. (setq org-agenda-entry-types
  3485. (delq :deadline org-agenda-entry-types)))
  3486. (cond
  3487. ((memq org-agenda-show-log-scoped '(only clockcheck))
  3488. (setq rtn (org-agenda-get-day-entries
  3489. file date :closed)))
  3490. (org-agenda-show-log-scoped
  3491. (setq rtn (apply 'org-agenda-get-day-entries
  3492. file date
  3493. (append '(:closed) org-agenda-entry-types))))
  3494. (t
  3495. (setq rtn (apply 'org-agenda-get-day-entries
  3496. file date
  3497. org-agenda-entry-types)))))
  3498. (setq rtnall (append rtnall rtn)))) ;; all entries
  3499. (if org-agenda-include-diary
  3500. (let ((org-agenda-search-headline-for-time t))
  3501. (require 'diary-lib)
  3502. (setq rtn (org-get-entries-from-diary date))
  3503. (setq rtnall (append rtnall rtn))))
  3504. (if (or rtnall org-agenda-show-all-dates)
  3505. (progn
  3506. (setq day-cnt (1+ day-cnt))
  3507. (insert
  3508. (if (stringp org-agenda-format-date)
  3509. (format-time-string org-agenda-format-date
  3510. (org-time-from-absolute date))
  3511. (funcall org-agenda-format-date date))
  3512. "\n")
  3513. (put-text-property s (1- (point)) 'face
  3514. (org-agenda-get-day-face date))
  3515. (put-text-property s (1- (point)) 'org-date-line t)
  3516. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  3517. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  3518. (when todayp
  3519. (put-text-property s (1- (point)) 'org-today t))
  3520. (if rtnall (insert ;; all entries
  3521. (org-finalize-agenda-entries
  3522. (org-agenda-add-time-grid-maybe
  3523. rtnall ndays todayp))
  3524. "\n"))
  3525. (put-text-property s (1- (point)) 'day d)
  3526. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  3527. (when (and org-agenda-clockreport-mode clocktable-start)
  3528. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  3529. ;; the above line is to ensure the restricted range!
  3530. (p (copy-sequence org-agenda-clockreport-parameter-plist))
  3531. tbl)
  3532. (setq p (org-plist-delete p :block))
  3533. (setq p (plist-put p :tstart clocktable-start))
  3534. (setq p (plist-put p :tend clocktable-end))
  3535. (setq p (plist-put p :scope 'agenda))
  3536. (when (and (eq org-agenda-clockreport-mode 'with-filter)
  3537. (setq filter (or org-agenda-tag-filter-while-redo
  3538. (get 'org-agenda-tag-filter :preset-filter))))
  3539. (setq p (plist-put p :tags (mapconcat (lambda (x)
  3540. (if (string-match "[<>=]" x)
  3541. ""
  3542. x))
  3543. filter ""))))
  3544. (setq tbl (apply 'org-get-clocktable p))
  3545. (insert tbl)))
  3546. (goto-char (point-min))
  3547. (or org-agenda-multi (org-fit-agenda-window))
  3548. (unless (and (pos-visible-in-window-p (point-min))
  3549. (pos-visible-in-window-p (point-max)))
  3550. (goto-char (1- (point-max)))
  3551. (recenter -1)
  3552. (if (not (pos-visible-in-window-p (or start-pos 1)))
  3553. (progn
  3554. (goto-char (or start-pos 1))
  3555. (recenter 1))))
  3556. (goto-char (or start-pos 1))
  3557. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  3558. (if (eq org-agenda-show-log-scoped 'clockcheck)
  3559. (org-agenda-show-clocking-issues))
  3560. (org-finalize-agenda)
  3561. (setq buffer-read-only t)
  3562. (message "")))
  3563. (defun org-agenda-ndays-to-span (n)
  3564. "Return a span symbol for a span of N days, or N if none matches."
  3565. (cond ((symbolp n) n)
  3566. ((= n 1) 'day)
  3567. ((= n 7) 'week)
  3568. (t n)))
  3569. (defun org-agenda-span-to-ndays (span start-day)
  3570. "Return ndays from SPAN starting at START-DAY."
  3571. (cond ((numberp span) span)
  3572. ((eq span 'day) 1)
  3573. ((eq span 'week) 7)
  3574. ((eq span 'month)
  3575. (let ((date (calendar-gregorian-from-absolute start-day)))
  3576. (calendar-last-day-of-month (car date) (caddr date))))
  3577. ((eq span 'year)
  3578. (let ((date (calendar-gregorian-from-absolute start-day)))
  3579. (if (calendar-leap-year-p (caddr date)) 366 365)))))
  3580. (defun org-agenda-span-name (span)
  3581. "Return a SPAN name."
  3582. (if (null span)
  3583. ""
  3584. (if (symbolp span)
  3585. (capitalize (symbol-name span))
  3586. (format "%d days" span))))
  3587. ;;; Agenda word search
  3588. (defvar org-agenda-search-history nil)
  3589. (defvar org-todo-only nil)
  3590. (defvar org-search-syntax-table nil
  3591. "Special syntax table for org-mode search.
  3592. In this table, we have single quotes not as word constituents, to
  3593. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  3594. (defun org-search-syntax-table ()
  3595. (unless org-search-syntax-table
  3596. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  3597. (modify-syntax-entry ?' "." org-search-syntax-table)
  3598. (modify-syntax-entry ?` "." org-search-syntax-table))
  3599. org-search-syntax-table)
  3600. (defvar org-agenda-last-search-view-search-was-boolean nil)
  3601. ;;;###autoload
  3602. (defun org-search-view (&optional todo-only string edit-at)
  3603. "Show all entries that contain a phrase or words or regular expressions.
  3604. With optional prefix argument TODO-ONLY, only consider entries that are
  3605. TODO entries. The argument STRING can be used to pass a default search
  3606. string into this function. If EDIT-AT is non-nil, it means that the
  3607. user should get a chance to edit this string, with cursor at position
  3608. EDIT-AT.
  3609. The search string can be viewed either as a phrase that should be found as
  3610. is, or it can be broken into a number of snippets, each of which must match
  3611. in a Boolean way to select an entry. The default depends on the variable
  3612. `org-agenda-search-view-always-boolean'.
  3613. Even if this is turned off (the default) you can always switch to
  3614. Boolean search dynamically by preceding the first word with \"+\" or \"-\".
  3615. The default is a direct search of the whole phrase, where each space in
  3616. the search string can expand to an arbitrary amount of whitespace,
  3617. including newlines.
  3618. If using a Boolean search, the search string is split on whitespace and
  3619. each snippet is searched separately, with logical AND to select an entry.
  3620. Words prefixed with a minus must *not* occur in the entry. Words without
  3621. a prefix or prefixed with a plus must occur in the entry. Matching is
  3622. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3623. match whole words, not parts of a word) if
  3624. `org-agenda-search-view-force-full-words' is set (default is nil).
  3625. Boolean search snippets enclosed by curly braces are interpreted as
  3626. regular expressions that must or (when preceded with \"-\") must not
  3627. match in the entry. Snippets enclosed into double quotes will be taken
  3628. as a whole, to include whitespace.
  3629. - If the search string starts with an asterisk, search only in headlines.
  3630. - If (possibly after the leading star) the search string starts with an
  3631. exclamation mark, this also means to look at TODO entries only, an effect
  3632. that can also be achieved with a prefix argument.
  3633. - If (possibly after star and exclamation mark) the search string starts
  3634. with a colon, this will mean that the (non-regexp) snippets of the
  3635. Boolean search must match as full words.
  3636. This command searches the agenda files, and in addition the files listed
  3637. in `org-agenda-text-search-extra-files'."
  3638. (interactive "P")
  3639. (org-prepare-agenda "SEARCH")
  3640. (org-compile-prefix-format 'search)
  3641. (org-set-sorting-strategy 'search)
  3642. (let* ((props (list 'face nil
  3643. 'done-face 'org-agenda-done
  3644. 'org-not-done-regexp org-not-done-regexp
  3645. 'org-todo-regexp org-todo-regexp
  3646. 'org-complex-heading-regexp org-complex-heading-regexp
  3647. 'mouse-face 'highlight
  3648. 'help-echo (format "mouse-2 or RET jump to location")))
  3649. (full-words org-agenda-search-view-force-full-words)
  3650. (org-agenda-text-search-extra-files org-agenda-text-search-extra-files)
  3651. regexp rtn rtnall files file pos
  3652. marker category org-category-pos tags c neg re boolean
  3653. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3654. (unless (and (not edit-at)
  3655. (stringp string)
  3656. (string-match "\\S-" string))
  3657. (setq string (read-string
  3658. (if org-agenda-search-view-always-boolean
  3659. "[+-]Word/{Regexp} ...: "
  3660. "Phrase, or [+-]Word/{Regexp} ...: ")
  3661. (cond
  3662. ((integerp edit-at) (cons string edit-at))
  3663. (edit-at string))
  3664. 'org-agenda-search-history)))
  3665. (org-set-local 'org-todo-only todo-only)
  3666. (setq org-agenda-redo-command
  3667. (list 'org-search-view (if todo-only t nil) string
  3668. '(if current-prefix-arg 1 nil)))
  3669. (setq org-agenda-query-string string)
  3670. (if (equal (string-to-char string) ?*)
  3671. (setq hdl-only t
  3672. words (substring string 1))
  3673. (setq words string))
  3674. (when (equal (string-to-char words) ?!)
  3675. (setq todo-only t
  3676. words (substring words 1)))
  3677. (when (equal (string-to-char words) ?:)
  3678. (setq full-words t
  3679. words (substring words 1)))
  3680. (if (or org-agenda-search-view-always-boolean
  3681. (member (string-to-char words) '(?- ?+ ?\{)))
  3682. (setq boolean t))
  3683. (setq words (org-split-string words))
  3684. (let (www w)
  3685. (while (setq w (pop words))
  3686. (while (and (string-match "\\\\\\'" w) words)
  3687. (setq w (concat (substring w 0 -1) " " (pop words))))
  3688. (push w www))
  3689. (setq words (nreverse www) www nil)
  3690. (while (setq w (pop words))
  3691. (when (and (string-match "\\`[-+]?{" w)
  3692. (not (string-match "}\\'" w)))
  3693. (while (and words (not (string-match "}\\'" (car words))))
  3694. (setq w (concat w " " (pop words))))
  3695. (setq w (concat w " " (pop words))))
  3696. (push w www))
  3697. (setq words (nreverse www)))
  3698. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3699. (when boolean
  3700. (let (wds w)
  3701. (while (setq w (pop words))
  3702. (if (or (equal (substring w 0 1) "\"")
  3703. (and (> (length w) 1)
  3704. (member (substring w 0 1) '("+" "-"))
  3705. (equal (substring w 1 2) "\"")))
  3706. (while (and words (not (equal (substring w -1) "\"")))
  3707. (setq w (concat w " " (pop words)))))
  3708. (and (string-match "\\`\\([-+]?\\)\"" w)
  3709. (setq w (replace-match "\\1" nil nil w)))
  3710. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3711. (push w wds))
  3712. (setq words (nreverse wds))))
  3713. (if boolean
  3714. (mapc (lambda (w)
  3715. (setq c (string-to-char w))
  3716. (if (equal c ?-)
  3717. (setq neg t w (substring w 1))
  3718. (if (equal c ?+)
  3719. (setq neg nil w (substring w 1))
  3720. (setq neg nil)))
  3721. (if (string-match "\\`{.*}\\'" w)
  3722. (setq re (substring w 1 -1))
  3723. (if full-words
  3724. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3725. (setq re (regexp-quote (downcase w)))))
  3726. (if neg (push re regexps-) (push re regexps+)))
  3727. words)
  3728. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3729. regexps+))
  3730. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3731. (if (not regexps+)
  3732. (setq regexp org-outline-regexp-bol)
  3733. (setq regexp (pop regexps+))
  3734. (if hdl-only (setq regexp (concat org-outline-regexp-bol ".*?"
  3735. regexp))))
  3736. (setq files (org-agenda-files nil 'ifmode))
  3737. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3738. (pop org-agenda-text-search-extra-files)
  3739. (setq files (org-add-archive-files files)))
  3740. (setq files (append files org-agenda-text-search-extra-files)
  3741. rtnall nil)
  3742. (while (setq file (pop files))
  3743. (setq ee nil)
  3744. (catch 'nextfile
  3745. (org-check-agenda-file file)
  3746. (setq buffer (if (file-exists-p file)
  3747. (org-get-agenda-file-buffer file)
  3748. (error "No such file %s" file)))
  3749. (if (not buffer)
  3750. ;; If file does not exist, make sure an error message is sent
  3751. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3752. file))))
  3753. (with-current-buffer buffer
  3754. (with-syntax-table (org-search-syntax-table)
  3755. (unless (eq major-mode 'org-mode)
  3756. (error "Agenda file %s is not in `org-mode'" file))
  3757. (let ((case-fold-search t))
  3758. (save-excursion
  3759. (save-restriction
  3760. (if org-agenda-restrict
  3761. (narrow-to-region org-agenda-restrict-begin
  3762. org-agenda-restrict-end)
  3763. (widen))
  3764. (goto-char (point-min))
  3765. (unless (or (org-at-heading-p)
  3766. (outline-next-heading))
  3767. (throw 'nextfile t))
  3768. (goto-char (max (point-min) (1- (point))))
  3769. (while (re-search-forward regexp nil t)
  3770. (org-back-to-heading t)
  3771. (skip-chars-forward "* ")
  3772. (setq beg (point-at-bol)
  3773. beg1 (point)
  3774. end (progn (outline-next-heading) (point)))
  3775. (catch :skip
  3776. (goto-char beg)
  3777. (org-agenda-skip)
  3778. (setq str (buffer-substring-no-properties
  3779. (point-at-bol)
  3780. (if hdl-only (point-at-eol) end)))
  3781. (mapc (lambda (wr) (when (string-match wr str)
  3782. (goto-char (1- end))
  3783. (throw :skip t)))
  3784. regexps-)
  3785. (mapc (lambda (wr) (unless (string-match wr str)
  3786. (goto-char (1- end))
  3787. (throw :skip t)))
  3788. (if todo-only
  3789. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3790. regexps+)
  3791. regexps+))
  3792. (goto-char beg)
  3793. (setq marker (org-agenda-new-marker (point))
  3794. category (org-get-category)
  3795. org-category-pos (get-text-property (point) 'org-category-position)
  3796. tags (org-get-tags-at (point))
  3797. txt (org-agenda-format-item
  3798. ""
  3799. (buffer-substring-no-properties
  3800. beg1 (point-at-eol))
  3801. category tags))
  3802. (org-add-props txt props
  3803. 'org-marker marker 'org-hd-marker marker
  3804. 'org-todo-regexp org-todo-regexp
  3805. 'org-complex-heading-regexp org-complex-heading-regexp
  3806. 'priority 1000 'org-category category
  3807. 'org-category-position org-category-pos
  3808. 'type "search")
  3809. (push txt ee)
  3810. (goto-char (1- end))))))))))
  3811. (setq rtn (nreverse ee))
  3812. (setq rtnall (append rtnall rtn)))
  3813. (if org-agenda-overriding-header
  3814. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3815. nil 'face 'org-agenda-structure) "\n")
  3816. (insert "Search words: ")
  3817. (add-text-properties (point-min) (1- (point))
  3818. (list 'face 'org-agenda-structure))
  3819. (setq pos (point))
  3820. (insert string "\n")
  3821. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3822. (setq pos (point))
  3823. (unless org-agenda-multi
  3824. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3825. (add-text-properties pos (1- (point))
  3826. (list 'face 'org-agenda-structure))))
  3827. (org-agenda-mark-header-line (point-min))
  3828. (when rtnall
  3829. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3830. (goto-char (point-min))
  3831. (or org-agenda-multi (org-fit-agenda-window))
  3832. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3833. (org-finalize-agenda)
  3834. (setq buffer-read-only t)))
  3835. ;;; Agenda TODO list
  3836. (defvar org-select-this-todo-keyword nil)
  3837. (defvar org-last-arg nil)
  3838. ;;;###autoload
  3839. (defun org-todo-list (arg)
  3840. "Show all (not done) TODO entries from all agenda file in a single list.
  3841. The prefix arg can be used to select a specific TODO keyword and limit
  3842. the list to these. When using \\[universal-argument], you will be prompted
  3843. for a keyword. A numeric prefix directly selects the Nth keyword in
  3844. `org-todo-keywords-1'."
  3845. (interactive "P")
  3846. (org-prepare-agenda "TODO")
  3847. (org-compile-prefix-format 'todo)
  3848. (org-set-sorting-strategy 'todo)
  3849. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3850. (let* ((today (org-today))
  3851. (date (calendar-gregorian-from-absolute today))
  3852. (kwds org-todo-keywords-for-agenda)
  3853. (completion-ignore-case t)
  3854. (org-select-this-todo-keyword
  3855. (if (stringp arg) arg
  3856. (and arg (integerp arg) (> arg 0)
  3857. (nth (1- arg) kwds))))
  3858. rtn rtnall files file pos)
  3859. (when (equal arg '(4))
  3860. (setq org-select-this-todo-keyword
  3861. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3862. (mapcar 'list kwds) nil nil)))
  3863. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3864. (org-set-local 'org-last-arg arg)
  3865. (setq org-agenda-redo-command
  3866. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3867. (setq files (org-agenda-files nil 'ifmode)
  3868. rtnall nil)
  3869. (while (setq file (pop files))
  3870. (catch 'nextfile
  3871. (org-check-agenda-file file)
  3872. (setq rtn (org-agenda-get-day-entries file date :todo))
  3873. (setq rtnall (append rtnall rtn))))
  3874. (if org-agenda-overriding-header
  3875. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3876. nil 'face 'org-agenda-structure) "\n")
  3877. (insert "Global list of TODO items of type: ")
  3878. (add-text-properties (point-min) (1- (point))
  3879. (list 'face 'org-agenda-structure
  3880. 'short-heading
  3881. (concat "ToDo: "
  3882. (or org-select-this-todo-keyword "ALL"))))
  3883. (org-agenda-mark-header-line (point-min))
  3884. (setq pos (point))
  3885. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3886. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3887. (setq pos (point))
  3888. (unless org-agenda-multi
  3889. (insert "Available with `N r': (0)ALL")
  3890. (let ((n 0) s)
  3891. (mapc (lambda (x)
  3892. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3893. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3894. (insert "\n "))
  3895. (insert " " s))
  3896. kwds))
  3897. (insert "\n"))
  3898. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3899. (org-agenda-mark-header-line (point-min))
  3900. (when rtnall
  3901. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3902. (goto-char (point-min))
  3903. (or org-agenda-multi (org-fit-agenda-window))
  3904. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3905. (org-finalize-agenda)
  3906. (setq buffer-read-only t)))
  3907. ;;; Agenda tags match
  3908. ;;;###autoload
  3909. (defun org-tags-view (&optional todo-only match)
  3910. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3911. The prefix arg TODO-ONLY limits the search to TODO entries."
  3912. (interactive "P")
  3913. (let* ((org-tags-match-list-sublevels
  3914. org-tags-match-list-sublevels)
  3915. (completion-ignore-case t)
  3916. rtn rtnall files file pos matcher
  3917. buffer)
  3918. (when (and (stringp match) (not (string-match "\\S-" match)))
  3919. (setq match nil))
  3920. (setq matcher (org-make-tags-matcher match)
  3921. match (car matcher) matcher (cdr matcher))
  3922. (org-prepare-agenda (concat "TAGS " match))
  3923. (org-compile-prefix-format 'tags)
  3924. (org-set-sorting-strategy 'tags)
  3925. (setq org-agenda-query-string match)
  3926. (setq org-agenda-redo-command
  3927. (list 'org-tags-view (list 'quote todo-only)
  3928. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3929. (setq files (org-agenda-files nil 'ifmode)
  3930. rtnall nil)
  3931. (while (setq file (pop files))
  3932. (catch 'nextfile
  3933. (org-check-agenda-file file)
  3934. (setq buffer (if (file-exists-p file)
  3935. (org-get-agenda-file-buffer file)
  3936. (error "No such file %s" file)))
  3937. (if (not buffer)
  3938. ;; If file does not exist, error message to agenda
  3939. (setq rtn (list
  3940. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3941. rtnall (append rtnall rtn))
  3942. (with-current-buffer buffer
  3943. (unless (eq major-mode 'org-mode)
  3944. (error "Agenda file %s is not in `org-mode'" file))
  3945. (save-excursion
  3946. (save-restriction
  3947. (if org-agenda-restrict
  3948. (narrow-to-region org-agenda-restrict-begin
  3949. org-agenda-restrict-end)
  3950. (widen))
  3951. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3952. (setq rtnall (append rtnall rtn))))))))
  3953. (if org-agenda-overriding-header
  3954. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3955. nil 'face 'org-agenda-structure) "\n")
  3956. (insert "Headlines with TAGS match: ")
  3957. (add-text-properties (point-min) (1- (point))
  3958. (list 'face 'org-agenda-structure
  3959. 'short-heading
  3960. (concat "Match: " match)))
  3961. (setq pos (point))
  3962. (insert match "\n")
  3963. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3964. (setq pos (point))
  3965. (unless org-agenda-multi
  3966. (insert "Press `C-u r' to search again with new search string\n"))
  3967. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3968. (org-agenda-mark-header-line (point-min))
  3969. (when rtnall
  3970. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3971. (goto-char (point-min))
  3972. (or org-agenda-multi (org-fit-agenda-window))
  3973. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3974. (org-finalize-agenda)
  3975. (setq buffer-read-only t)))
  3976. ;;; Agenda Finding stuck projects
  3977. (defvar org-agenda-skip-regexp nil
  3978. "Regular expression used in skipping subtrees for the agenda.
  3979. This is basically a temporary global variable that can be set and then
  3980. used by user-defined selections using `org-agenda-skip-function'.")
  3981. (defvar org-agenda-overriding-header nil
  3982. "When set during agenda, todo and tags searches it replaces the header.
  3983. This variable should not be set directly, but custom commands can bind it
  3984. in the options section.")
  3985. (defun org-agenda-skip-entry-when-regexp-matches ()
  3986. "Check if the current entry contains match for `org-agenda-skip-regexp'.
  3987. If yes, it returns the end position of this entry, causing agenda commands
  3988. to skip the entry but continuing the search in the subtree. This is a
  3989. function that can be put into `org-agenda-skip-function' for the duration
  3990. of a command."
  3991. (let ((end (save-excursion (org-end-of-subtree t)))
  3992. skip)
  3993. (save-excursion
  3994. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3995. (and skip end)))
  3996. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3997. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  3998. If yes, it returns the end position of this tree, causing agenda commands
  3999. to skip this subtree. This is a function that can be put into
  4000. `org-agenda-skip-function' for the duration of a command."
  4001. (let ((end (save-excursion (org-end-of-subtree t)))
  4002. skip)
  4003. (save-excursion
  4004. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4005. (and skip end)))
  4006. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  4007. "Check if the current subtree contains match for `org-agenda-skip-regexp'.
  4008. If yes, it returns the end position of the current entry (NOT the tree),
  4009. causing agenda commands to skip the entry but continuing the search in
  4010. the subtree. This is a function that can be put into
  4011. `org-agenda-skip-function' for the duration of a command. An important
  4012. use of this function is for the stuck project list."
  4013. (let ((end (save-excursion (org-end-of-subtree t)))
  4014. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  4015. skip)
  4016. (save-excursion
  4017. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  4018. (and skip entry-end)))
  4019. (defun org-agenda-skip-entry-if (&rest conditions)
  4020. "Skip entry if any of CONDITIONS is true.
  4021. See `org-agenda-skip-if' for details."
  4022. (org-agenda-skip-if nil conditions))
  4023. (defun org-agenda-skip-subtree-if (&rest conditions)
  4024. "Skip entry if any of CONDITIONS is true.
  4025. See `org-agenda-skip-if' for details."
  4026. (org-agenda-skip-if t conditions))
  4027. (defun org-agenda-skip-if (subtree conditions)
  4028. "Checks current entity for CONDITIONS.
  4029. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  4030. the entry, i.e. the text before the next heading is checked.
  4031. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  4032. from different tests. Valid conditions are:
  4033. scheduled Check if there is a scheduled cookie
  4034. notscheduled Check if there is no scheduled cookie
  4035. deadline Check if there is a deadline
  4036. notdeadline Check if there is no deadline
  4037. timestamp Check if there is a timestamp (also deadline or scheduled)
  4038. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  4039. regexp Check if regexp matches
  4040. notregexp Check if regexp does not match.
  4041. todo Check if TODO keyword matches
  4042. nottodo Check if TODO keyword does not match
  4043. The regexp is taken from the conditions list, it must come right after
  4044. the `regexp' or `notregexp' element.
  4045. `todo' and `nottodo' accept as an argument a list of todo
  4046. keywords, which may include \"*\" to match any todo keyword.
  4047. (org-agenda-skip-entry-if 'todo '(\"TODO\" \"WAITING\"))
  4048. would skip all entries with \"TODO\" or \"WAITING\" keywords.
  4049. Instead of a list a keyword class may be given
  4050. (org-agenda-skip-entry-if 'nottodo 'done)
  4051. would skip entries that haven't been marked with any of \"DONE\"
  4052. keywords. Possible classes are: `todo', `done', `any'.
  4053. If any of these conditions is met, this function returns the end point of
  4054. the entity, causing the search to continue from there. This is a function
  4055. that can be put into `org-agenda-skip-function' for the duration of a command."
  4056. (let (beg end m)
  4057. (org-back-to-heading t)
  4058. (setq beg (point)
  4059. end (if subtree
  4060. (progn (org-end-of-subtree t) (point))
  4061. (progn (outline-next-heading) (1- (point)))))
  4062. (goto-char beg)
  4063. (and
  4064. (or
  4065. (and (memq 'scheduled conditions)
  4066. (re-search-forward org-scheduled-time-regexp end t))
  4067. (and (memq 'notscheduled conditions)
  4068. (not (re-search-forward org-scheduled-time-regexp end t)))
  4069. (and (memq 'deadline conditions)
  4070. (re-search-forward org-deadline-time-regexp end t))
  4071. (and (memq 'notdeadline conditions)
  4072. (not (re-search-forward org-deadline-time-regexp end t)))
  4073. (and (memq 'timestamp conditions)
  4074. (re-search-forward org-ts-regexp end t))
  4075. (and (memq 'nottimestamp conditions)
  4076. (not (re-search-forward org-ts-regexp end t)))
  4077. (and (setq m (memq 'regexp conditions))
  4078. (stringp (nth 1 m))
  4079. (re-search-forward (nth 1 m) end t))
  4080. (and (setq m (memq 'notregexp conditions))
  4081. (stringp (nth 1 m))
  4082. (not (re-search-forward (nth 1 m) end t)))
  4083. (and (or
  4084. (setq m (memq 'todo conditions))
  4085. (setq m (memq 'nottodo conditions)))
  4086. (org-agenda-skip-if-todo m end)))
  4087. end)))
  4088. (defun org-agenda-skip-if-todo (args end)
  4089. "Helper function for `org-agenda-skip-if', do not use it directly.
  4090. ARGS is a list with first element either `todo' or `nottodo'.
  4091. The remainder is either a list of TODO keywords, or a state symbol
  4092. `todo' or `done' or `any'."
  4093. (let ((kw (car args))
  4094. (arg (cadr args))
  4095. todo-wds todo-re)
  4096. (setq todo-wds
  4097. (org-uniquify
  4098. (cond
  4099. ((listp arg) ;; list of keywords
  4100. (if (member "*" arg)
  4101. (mapcar 'substring-no-properties org-todo-keywords-1)
  4102. arg))
  4103. ((symbolp arg) ;; keyword class name
  4104. (cond
  4105. ((eq arg 'todo)
  4106. (org-delete-all org-done-keywords
  4107. (mapcar 'substring-no-properties
  4108. org-todo-keywords-1)))
  4109. ((eq arg 'done) org-done-keywords)
  4110. ((eq arg 'any)
  4111. (mapcar 'substring-no-properties org-todo-keywords-1)))))))
  4112. (setq todo-re
  4113. (concat "^\\*+[ \t]+\\<\\("
  4114. (mapconcat 'identity todo-wds "\\|")
  4115. "\\)\\>"))
  4116. (if (eq kw 'todo)
  4117. (re-search-forward todo-re end t)
  4118. (not (re-search-forward todo-re end t)))))
  4119. ;;;###autoload
  4120. (defun org-agenda-list-stuck-projects (&rest ignore)
  4121. "Create agenda view for projects that are stuck.
  4122. Stuck projects are project that have no next actions. For the definitions
  4123. of what a project is and how to check if it stuck, customize the variable
  4124. `org-stuck-projects'."
  4125. (interactive)
  4126. (let* ((org-agenda-skip-function
  4127. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  4128. ;; We could have used org-agenda-skip-if here.
  4129. (org-agenda-overriding-header
  4130. (or org-agenda-overriding-header "List of stuck projects: "))
  4131. (matcher (nth 0 org-stuck-projects))
  4132. (todo (nth 1 org-stuck-projects))
  4133. (todo-wds (if (member "*" todo)
  4134. (progn
  4135. (org-prepare-agenda-buffers (org-agenda-files
  4136. nil 'ifmode))
  4137. (org-delete-all
  4138. org-done-keywords-for-agenda
  4139. (copy-sequence org-todo-keywords-for-agenda)))
  4140. todo))
  4141. (todo-re (concat "^\\*+[ \t]+\\("
  4142. (mapconcat 'identity todo-wds "\\|")
  4143. "\\)\\>"))
  4144. (tags (nth 2 org-stuck-projects))
  4145. (tags-re (if (member "*" tags)
  4146. (concat org-outline-regexp-bol
  4147. (org-re ".*:[[:alnum:]_@#%]+:[ \t]*$"))
  4148. (if tags
  4149. (concat org-outline-regexp-bol
  4150. ".*:\\("
  4151. (mapconcat 'identity tags "\\|")
  4152. (org-re "\\):[[:alnum:]_@#%:]*[ \t]*$")))))
  4153. (gen-re (nth 3 org-stuck-projects))
  4154. (re-list
  4155. (delq nil
  4156. (list
  4157. (if todo todo-re)
  4158. (if tags tags-re)
  4159. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  4160. gen-re)))))
  4161. (setq org-agenda-skip-regexp
  4162. (if re-list
  4163. (mapconcat 'identity re-list "\\|")
  4164. (error "No information how to identify unstuck projects")))
  4165. (org-tags-view nil matcher)
  4166. (with-current-buffer org-agenda-buffer-name
  4167. (setq org-agenda-redo-command
  4168. '(org-agenda-list-stuck-projects
  4169. (or current-prefix-arg org-last-arg))))))
  4170. ;;; Diary integration
  4171. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  4172. (defvar diary-list-entries-hook)
  4173. (defvar diary-time-regexp)
  4174. (defun org-get-entries-from-diary (date)
  4175. "Get the (Emacs Calendar) diary entries for DATE."
  4176. (require 'diary-lib)
  4177. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  4178. (diary-display-hook '(fancy-diary-display))
  4179. (diary-display-function 'fancy-diary-display)
  4180. (pop-up-frames nil)
  4181. (diary-list-entries-hook
  4182. (cons 'org-diary-default-entry diary-list-entries-hook))
  4183. (diary-file-name-prefix-function nil) ; turn this feature off
  4184. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  4185. entries
  4186. (org-disable-agenda-to-diary t))
  4187. (save-excursion
  4188. (save-window-excursion
  4189. (funcall (if (fboundp 'diary-list-entries)
  4190. 'diary-list-entries 'list-diary-entries)
  4191. date 1)))
  4192. (if (not (get-buffer diary-fancy-buffer))
  4193. (setq entries nil)
  4194. (with-current-buffer diary-fancy-buffer
  4195. (setq buffer-read-only nil)
  4196. (if (zerop (buffer-size))
  4197. ;; No entries
  4198. (setq entries nil)
  4199. ;; Omit the date and other unnecessary stuff
  4200. (org-agenda-cleanup-fancy-diary)
  4201. ;; Add prefix to each line and extend the text properties
  4202. (if (zerop (buffer-size))
  4203. (setq entries nil)
  4204. (setq entries (buffer-substring (point-min) (- (point-max) 1)))
  4205. (setq entries
  4206. (with-temp-buffer
  4207. (insert entries) (goto-char (point-min))
  4208. (while (re-search-forward "\n[ \t]+\\(.+\\)$" nil t)
  4209. (unless (save-match-data (string-match diary-time-regexp (match-string 1)))
  4210. (replace-match (concat "; " (match-string 1)))))
  4211. (buffer-string)))))
  4212. (set-buffer-modified-p nil)
  4213. (kill-buffer diary-fancy-buffer)))
  4214. (when entries
  4215. (setq entries (org-split-string entries "\n"))
  4216. (setq entries
  4217. (mapcar
  4218. (lambda (x)
  4219. (setq x (org-agenda-format-item "" x "Diary" nil 'time))
  4220. ;; Extend the text properties to the beginning of the line
  4221. (org-add-props x (text-properties-at (1- (length x)) x)
  4222. 'type "diary" 'date date 'face 'org-agenda-diary))
  4223. entries)))))
  4224. (defvar org-agenda-cleanup-fancy-diary-hook nil
  4225. "Hook run when the fancy diary buffer is cleaned up.")
  4226. (defun org-agenda-cleanup-fancy-diary ()
  4227. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  4228. This gets rid of the date, the underline under the date, and
  4229. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  4230. date. It also removes lines that contain only whitespace."
  4231. (goto-char (point-min))
  4232. (if (looking-at ".*?:[ \t]*")
  4233. (progn
  4234. (replace-match "")
  4235. (re-search-forward "\n=+$" nil t)
  4236. (replace-match "")
  4237. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  4238. (re-search-forward "\n=+$" nil t)
  4239. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  4240. (goto-char (point-min))
  4241. (while (re-search-forward "^ +\n" nil t)
  4242. (replace-match ""))
  4243. (goto-char (point-min))
  4244. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  4245. (replace-match ""))
  4246. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  4247. ;; Make sure entries from the diary have the right text properties.
  4248. (eval-after-load "diary-lib"
  4249. '(if (boundp 'diary-modify-entry-list-string-function)
  4250. ;; We can rely on the hook, nothing to do
  4251. nil
  4252. ;; Hook not available, must use advice to make this work
  4253. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  4254. "Make the position visible."
  4255. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  4256. (stringp string)
  4257. buffer-file-name)
  4258. (setq string (org-modify-diary-entry-string string))))))
  4259. (defun org-modify-diary-entry-string (string)
  4260. "Add text properties to string, allowing org-mode to act on it."
  4261. (org-add-props string nil
  4262. 'mouse-face 'highlight
  4263. 'help-echo (if buffer-file-name
  4264. (format "mouse-2 or RET jump to diary file %s"
  4265. (abbreviate-file-name buffer-file-name))
  4266. "")
  4267. 'org-agenda-diary-link t
  4268. 'org-marker (org-agenda-new-marker (point-at-bol))))
  4269. (defun org-diary-default-entry ()
  4270. "Add a dummy entry to the diary.
  4271. Needed to avoid empty dates which mess up holiday display."
  4272. ;; Catch the error if dealing with the new add-to-diary-alist
  4273. (when org-disable-agenda-to-diary
  4274. (condition-case nil
  4275. (org-add-to-diary-list original-date "Org-mode dummy" "")
  4276. (error
  4277. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  4278. (defun org-add-to-diary-list (&rest args)
  4279. (if (fboundp 'diary-add-to-list)
  4280. (apply 'diary-add-to-list args)
  4281. (apply 'add-to-diary-list args)))
  4282. (defvar org-diary-last-run-time nil)
  4283. ;;;###autoload
  4284. (defun org-diary (&rest args)
  4285. "Return diary information from org-files.
  4286. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  4287. It accesses org files and extracts information from those files to be
  4288. listed in the diary. The function accepts arguments specifying what
  4289. items should be listed. For a list of arguments allowed here, see the
  4290. variable `org-agenda-entry-types'.
  4291. The call in the diary file should look like this:
  4292. &%%(org-diary) ~/path/to/some/orgfile.org
  4293. Use a separate line for each org file to check. Or, if you omit the file name,
  4294. all files listed in `org-agenda-files' will be checked automatically:
  4295. &%%(org-diary)
  4296. If you don't give any arguments (as in the example above), the default
  4297. arguments (:deadline :scheduled :timestamp :sexp) are used.
  4298. So the example above may also be written as
  4299. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  4300. The function expects the lisp variables `entry' and `date' to be provided
  4301. by the caller, because this is how the calendar works. Don't use this
  4302. function from a program - use `org-agenda-get-day-entries' instead."
  4303. (when (> (- (org-float-time)
  4304. org-agenda-last-marker-time)
  4305. 5)
  4306. ;; I am not sure if this works with sticky agendas, because the marker
  4307. ;; list is then no longer a global variable.
  4308. (org-agenda-reset-markers))
  4309. (org-compile-prefix-format 'agenda)
  4310. (org-set-sorting-strategy 'agenda)
  4311. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4312. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  4313. (list entry)
  4314. (org-agenda-files t)))
  4315. (time (org-float-time))
  4316. file rtn results)
  4317. (when (or (not org-diary-last-run-time)
  4318. (> (- time
  4319. org-diary-last-run-time)
  4320. 3))
  4321. (org-prepare-agenda-buffers files))
  4322. (setq org-diary-last-run-time time)
  4323. ;; If this is called during org-agenda, don't return any entries to
  4324. ;; the calendar. Org Agenda will list these entries itself.
  4325. (if org-disable-agenda-to-diary (setq files nil))
  4326. (while (setq file (pop files))
  4327. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  4328. (setq results (append results rtn)))
  4329. (if results
  4330. (concat (org-finalize-agenda-entries results) "\n"))))
  4331. ;;; Agenda entry finders
  4332. (defun org-agenda-get-day-entries (file date &rest args)
  4333. "Does the work for `org-diary' and `org-agenda'.
  4334. FILE is the path to a file to be checked for entries. DATE is date like
  4335. the one returned by `calendar-current-date'. ARGS are symbols indicating
  4336. which kind of entries should be extracted. For details about these, see
  4337. the documentation of `org-diary'."
  4338. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  4339. (let* ((org-startup-folded nil)
  4340. (org-startup-align-all-tables nil)
  4341. (buffer (if (file-exists-p file)
  4342. (org-get-agenda-file-buffer file)
  4343. (error "No such file %s" file)))
  4344. arg results rtn deadline-results)
  4345. (if (not buffer)
  4346. ;; If file does not exist, make sure an error message ends up in diary
  4347. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  4348. (with-current-buffer buffer
  4349. (unless (eq major-mode 'org-mode)
  4350. (error "Agenda file %s is not in `org-mode'" file))
  4351. (let ((case-fold-search nil))
  4352. (save-excursion
  4353. (save-restriction
  4354. (if org-agenda-restrict
  4355. (narrow-to-region org-agenda-restrict-begin
  4356. org-agenda-restrict-end)
  4357. (widen))
  4358. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  4359. (while (setq arg (pop args))
  4360. (cond
  4361. ((and (eq arg :todo)
  4362. (equal date (calendar-gregorian-from-absolute
  4363. (org-today))))
  4364. (setq rtn (org-agenda-get-todos))
  4365. (setq results (append results rtn)))
  4366. ((eq arg :timestamp)
  4367. (setq rtn (org-agenda-get-blocks))
  4368. (setq results (append results rtn))
  4369. (setq rtn (org-agenda-get-timestamps))
  4370. (setq results (append results rtn)))
  4371. ((eq arg :sexp)
  4372. (setq rtn (org-agenda-get-sexps))
  4373. (setq results (append results rtn)))
  4374. ((eq arg :scheduled)
  4375. (setq rtn (org-agenda-get-scheduled deadline-results))
  4376. (setq results (append results rtn)))
  4377. ((eq arg :closed)
  4378. (setq rtn (org-agenda-get-progress))
  4379. (setq results (append results rtn)))
  4380. ((eq arg :deadline)
  4381. (setq rtn (org-agenda-get-deadlines))
  4382. (setq deadline-results (copy-sequence rtn))
  4383. (setq results (append results rtn))))))))
  4384. results))))
  4385. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  4386. (defun org-agenda-get-todos ()
  4387. "Return the TODO information for agenda display."
  4388. (let* ((props (list 'face nil
  4389. 'done-face 'org-agenda-done
  4390. 'org-not-done-regexp org-not-done-regexp
  4391. 'org-todo-regexp org-todo-regexp
  4392. 'org-complex-heading-regexp org-complex-heading-regexp
  4393. 'mouse-face 'highlight
  4394. 'help-echo
  4395. (format "mouse-2 or RET jump to org file %s"
  4396. (abbreviate-file-name buffer-file-name))))
  4397. (regexp (format org-heading-keyword-regexp-format
  4398. (cond
  4399. ((and org-select-this-todo-keyword
  4400. (equal org-select-this-todo-keyword "*"))
  4401. org-todo-regexp)
  4402. (org-select-this-todo-keyword
  4403. (concat "\\("
  4404. (mapconcat 'identity
  4405. (org-split-string
  4406. org-select-this-todo-keyword
  4407. "|")
  4408. "\\|") "\\)"))
  4409. (t org-not-done-regexp))))
  4410. marker priority category org-category-pos tags todo-state
  4411. ee txt beg end)
  4412. (goto-char (point-min))
  4413. (while (re-search-forward regexp nil t)
  4414. (catch :skip
  4415. (save-match-data
  4416. (beginning-of-line)
  4417. (org-agenda-skip)
  4418. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  4419. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  4420. (goto-char (1+ beg))
  4421. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  4422. (throw :skip nil)))
  4423. (goto-char (match-beginning 2))
  4424. (setq marker (org-agenda-new-marker (match-beginning 0))
  4425. category (org-get-category)
  4426. org-category-pos (get-text-property (point) 'org-category-position)
  4427. txt (org-trim
  4428. (buffer-substring (match-beginning 2) (match-end 0)))
  4429. tags (org-get-tags-at (point))
  4430. txt (org-agenda-format-item "" txt category tags)
  4431. priority (1+ (org-get-priority txt))
  4432. todo-state (org-get-todo-state))
  4433. (org-add-props txt props
  4434. 'org-marker marker 'org-hd-marker marker
  4435. 'priority priority 'org-category category
  4436. 'org-category-position org-category-pos
  4437. 'type "todo" 'todo-state todo-state)
  4438. (push txt ee)
  4439. (if org-agenda-todo-list-sublevels
  4440. (goto-char (match-end 2))
  4441. (org-end-of-subtree 'invisible))))
  4442. (nreverse ee)))
  4443. (defun org-agenda-todo-custom-ignore-p (time n)
  4444. "Check whether timestamp is farther away then n number of days.
  4445. This function is invoked if `org-agenda-todo-ignore-deadlines',
  4446. `org-agenda-todo-ignore-scheduled' or
  4447. `org-agenda-todo-ignore-timestamp' is set to an integer."
  4448. (let ((days (org-days-to-time time)))
  4449. (if (>= n 0)
  4450. (>= days n)
  4451. (<= days n))))
  4452. ;;;###autoload
  4453. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item
  4454. (&optional end)
  4455. "Do we have a reason to ignore this TODO entry because it has a time stamp?"
  4456. (when (or org-agenda-todo-ignore-with-date
  4457. org-agenda-todo-ignore-scheduled
  4458. org-agenda-todo-ignore-deadlines
  4459. org-agenda-todo-ignore-timestamp)
  4460. (setq end (or end (save-excursion (outline-next-heading) (point))))
  4461. (save-excursion
  4462. (or (and org-agenda-todo-ignore-with-date
  4463. (re-search-forward org-ts-regexp end t))
  4464. (and org-agenda-todo-ignore-scheduled
  4465. (re-search-forward org-scheduled-time-regexp end t)
  4466. (cond
  4467. ((eq org-agenda-todo-ignore-scheduled 'future)
  4468. (> (org-days-to-time (match-string 1)) 0))
  4469. ((eq org-agenda-todo-ignore-scheduled 'past)
  4470. (<= (org-days-to-time (match-string 1)) 0))
  4471. ((numberp org-agenda-todo-ignore-scheduled)
  4472. (org-agenda-todo-custom-ignore-p
  4473. (match-string 1) org-agenda-todo-ignore-scheduled))
  4474. (t)))
  4475. (and org-agenda-todo-ignore-deadlines
  4476. (re-search-forward org-deadline-time-regexp end t)
  4477. (cond
  4478. ((memq org-agenda-todo-ignore-deadlines '(t all)) t)
  4479. ((eq org-agenda-todo-ignore-deadlines 'far)
  4480. (not (org-deadline-close (match-string 1))))
  4481. ((eq org-agenda-todo-ignore-deadlines 'future)
  4482. (> (org-days-to-time (match-string 1)) 0))
  4483. ((eq org-agenda-todo-ignore-deadlines 'past)
  4484. (<= (org-days-to-time (match-string 1)) 0))
  4485. ((numberp org-agenda-todo-ignore-deadlines)
  4486. (org-agenda-todo-custom-ignore-p
  4487. (match-string 1) org-agenda-todo-ignore-deadlines))
  4488. (t (org-deadline-close (match-string 1)))))
  4489. (and org-agenda-todo-ignore-timestamp
  4490. (let ((buffer (current-buffer))
  4491. (regexp
  4492. (concat
  4493. org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
  4494. (start (point)))
  4495. ;; Copy current buffer into a temporary one
  4496. (with-temp-buffer
  4497. (insert-buffer-substring buffer start end)
  4498. (goto-char (point-min))
  4499. ;; Delete SCHEDULED and DEADLINE items
  4500. (while (re-search-forward regexp end t)
  4501. (delete-region (match-beginning 0) (match-end 0)))
  4502. (goto-char (point-min))
  4503. ;; No search for timestamp left
  4504. (when (re-search-forward org-ts-regexp nil t)
  4505. (cond
  4506. ((eq org-agenda-todo-ignore-timestamp 'future)
  4507. (> (org-days-to-time (match-string 1)) 0))
  4508. ((eq org-agenda-todo-ignore-timestamp 'past)
  4509. (<= (org-days-to-time (match-string 1)) 0))
  4510. ((numberp org-agenda-todo-ignore-timestamp)
  4511. (org-agenda-todo-custom-ignore-p
  4512. (match-string 1) org-agenda-todo-ignore-timestamp))
  4513. (t))))))))))
  4514. (defconst org-agenda-no-heading-message
  4515. "No heading for this item in buffer or region.")
  4516. (defun org-agenda-get-timestamps ()
  4517. "Return the date stamp information for agenda display."
  4518. (let* ((props (list 'face 'org-agenda-calendar-event
  4519. 'org-not-done-regexp org-not-done-regexp
  4520. 'org-todo-regexp org-todo-regexp
  4521. 'org-complex-heading-regexp org-complex-heading-regexp
  4522. 'mouse-face 'highlight
  4523. 'help-echo
  4524. (format "mouse-2 or RET jump to org file %s"
  4525. (abbreviate-file-name buffer-file-name))))
  4526. (d1 (calendar-absolute-from-gregorian date))
  4527. (remove-re
  4528. (concat
  4529. (regexp-quote
  4530. (format-time-string
  4531. "<%Y-%m-%d"
  4532. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  4533. ".*?>"))
  4534. (regexp
  4535. (concat
  4536. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  4537. (regexp-quote
  4538. (substring
  4539. (format-time-string
  4540. (car org-time-stamp-formats)
  4541. (apply 'encode-time ; DATE bound by calendar
  4542. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4543. 1 11))
  4544. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  4545. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  4546. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  4547. donep tmp priority category org-category-pos ee txt timestr tags
  4548. b0 b3 e3 head todo-state end-of-match show-all)
  4549. (goto-char (point-min))
  4550. (while (setq end-of-match (re-search-forward regexp nil t))
  4551. (setq b0 (match-beginning 0)
  4552. b3 (match-beginning 3) e3 (match-end 3)
  4553. todo-state (save-match-data (ignore-errors (org-get-todo-state)))
  4554. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4555. (member todo-state
  4556. org-agenda-repeating-timestamp-show-all)))
  4557. (catch :skip
  4558. (and (org-at-date-range-p) (throw :skip nil))
  4559. (org-agenda-skip)
  4560. (if (and (match-end 1)
  4561. (not (= d1 (org-time-string-to-absolute
  4562. (match-string 1) d1 nil show-all
  4563. (current-buffer) b0))))
  4564. (throw :skip nil))
  4565. (if (and e3
  4566. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  4567. (throw :skip nil))
  4568. (setq tmp (buffer-substring (max (point-min)
  4569. (- b0 org-ds-keyword-length))
  4570. b0)
  4571. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  4572. inactivep (= (char-after b0) ?\[)
  4573. deadlinep (string-match org-deadline-regexp tmp)
  4574. scheduledp (string-match org-scheduled-regexp tmp)
  4575. closedp (and org-agenda-include-inactive-timestamps
  4576. (string-match org-closed-string tmp))
  4577. clockp (and org-agenda-include-inactive-timestamps
  4578. (or (string-match org-clock-string tmp)
  4579. (string-match "]-+\\'" tmp)))
  4580. donep (member todo-state org-done-keywords))
  4581. (if (or scheduledp deadlinep closedp clockp
  4582. (and donep org-agenda-skip-timestamp-if-done))
  4583. (throw :skip t))
  4584. (if (string-match ">" timestr)
  4585. ;; substring should only run to end of time stamp
  4586. (setq timestr (substring timestr 0 (match-end 0))))
  4587. (setq marker (org-agenda-new-marker b0)
  4588. category (org-get-category b0)
  4589. org-category-pos (get-text-property b0 'org-category-position))
  4590. (save-excursion
  4591. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4592. (setq txt org-agenda-no-heading-message)
  4593. (goto-char (match-beginning 0))
  4594. (setq hdmarker (org-agenda-new-marker)
  4595. tags (org-get-tags-at))
  4596. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4597. (setq head (or (match-string 1) ""))
  4598. (setq txt (org-agenda-format-item
  4599. (if inactivep org-agenda-inactive-leader nil)
  4600. head category tags timestr
  4601. remove-re)))
  4602. (setq priority (org-get-priority txt))
  4603. (org-add-props txt props
  4604. 'org-marker marker 'org-hd-marker hdmarker)
  4605. (org-add-props txt nil 'priority priority
  4606. 'org-category category 'date date
  4607. 'org-category-position org-category-pos
  4608. 'todo-state todo-state
  4609. 'type "timestamp")
  4610. (push txt ee))
  4611. (if org-agenda-skip-additional-timestamps-same-entry
  4612. (outline-next-heading)
  4613. (goto-char end-of-match))))
  4614. (nreverse ee)))
  4615. (defun org-agenda-get-sexps ()
  4616. "Return the sexp information for agenda display."
  4617. (require 'diary-lib)
  4618. (let* ((props (list 'face 'org-agenda-calendar-sexp
  4619. 'mouse-face 'highlight
  4620. 'help-echo
  4621. (format "mouse-2 or RET jump to org file %s"
  4622. (abbreviate-file-name buffer-file-name))))
  4623. (regexp "^&?%%(")
  4624. marker category org-category-pos ee txt tags entry
  4625. result beg b sexp sexp-entry todo-state)
  4626. (goto-char (point-min))
  4627. (while (re-search-forward regexp nil t)
  4628. (catch :skip
  4629. (org-agenda-skip)
  4630. (setq beg (match-beginning 0))
  4631. (goto-char (1- (match-end 0)))
  4632. (setq b (point))
  4633. (forward-sexp 1)
  4634. (setq sexp (buffer-substring b (point)))
  4635. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  4636. (org-trim (match-string 1))
  4637. ""))
  4638. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  4639. (when result
  4640. (setq marker (org-agenda-new-marker beg)
  4641. category (org-get-category beg)
  4642. org-category-pos (get-text-property beg 'org-category-position)
  4643. todo-state (org-get-todo-state))
  4644. (dolist (r (if (stringp result)
  4645. (list result)
  4646. result)) ;; we expect a list here
  4647. (if (string-match "\\S-" r)
  4648. (setq txt r)
  4649. (setq txt "SEXP entry returned empty string"))
  4650. (setq txt (org-agenda-format-item
  4651. "" txt category tags 'time))
  4652. (org-add-props txt props 'org-marker marker)
  4653. (org-add-props txt nil
  4654. 'org-category category 'date date 'todo-state todo-state
  4655. 'org-category-position org-category-pos
  4656. 'type "sexp")
  4657. (push txt ee)))))
  4658. (nreverse ee)))
  4659. ;; Calendar sanity: define some functions that are independent of
  4660. ;; `calendar-date-style'.
  4661. ;; Normally I would like to use ISO format when calling the diary functions,
  4662. ;; but to make sure we still have Emacs 22 compatibility we bind
  4663. ;; also `european-calendar-style' and use european format
  4664. (defun org-anniversary (year month day &optional mark)
  4665. "Like `diary-anniversary', but with fixed (ISO) order of arguments."
  4666. (org-no-warnings
  4667. (let ((calendar-date-style 'european) (european-calendar-style t))
  4668. (diary-anniversary day month year mark))))
  4669. (defun org-cyclic (N year month day &optional mark)
  4670. "Like `diary-cyclic', but with fixed (ISO) order of arguments."
  4671. (org-no-warnings
  4672. (let ((calendar-date-style 'european) (european-calendar-style t))
  4673. (diary-cyclic N day month year mark))))
  4674. (defun org-block (Y1 M1 D1 Y2 M2 D2 &optional mark)
  4675. "Like `diary-block', but with fixed (ISO) order of arguments."
  4676. (org-no-warnings
  4677. (let ((calendar-date-style 'european) (european-calendar-style t))
  4678. (diary-block D1 M1 Y1 D2 M2 Y2 mark))))
  4679. (defun org-date (year month day &optional mark)
  4680. "Like `diary-date', but with fixed (ISO) order of arguments."
  4681. (org-no-warnings
  4682. (let ((calendar-date-style 'european) (european-calendar-style t))
  4683. (diary-date day month year mark))))
  4684. (defalias 'org-float 'diary-float)
  4685. ;; Define the` org-class' function
  4686. (defun org-class (y1 m1 d1 y2 m2 d2 dayname &rest skip-weeks)
  4687. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  4688. DAYNAME is a number between 0 (Sunday) and 6 (Saturday).
  4689. SKIP-WEEKS is any number of ISO weeks in the block period for which the
  4690. item should be skipped. If any of the SKIP-WEEKS arguments is the symbol
  4691. `holidays', then any date that is known by the Emacs calendar to be a
  4692. holiday will also be skipped."
  4693. (let* ((date1 (calendar-absolute-from-gregorian (list m1 d1 y1)))
  4694. (date2 (calendar-absolute-from-gregorian (list m2 d2 y2)))
  4695. (d (calendar-absolute-from-gregorian date)))
  4696. (and
  4697. (<= date1 d)
  4698. (<= d date2)
  4699. (= (calendar-day-of-week date) dayname)
  4700. (or (not skip-weeks)
  4701. (progn
  4702. (require 'cal-iso)
  4703. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  4704. (not (and (memq 'holidays skip-weeks)
  4705. (calendar-check-holidays date)))
  4706. entry)))
  4707. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  4708. "Like `org-class', but honor `calendar-date-style'.
  4709. The order of the first 2 times 3 arguments depends on the variable
  4710. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  4711. So for American calendars, give this as MONTH DAY YEAR, for European as
  4712. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  4713. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  4714. is any number of ISO weeks in the block period for which the item should
  4715. be skipped.
  4716. This function is here only for backward compatibility and it is deprecated,
  4717. please use `org-class' instead."
  4718. (let* ((date1 (org-order-calendar-date-args m1 d1 y1))
  4719. (date2 (org-order-calendar-date-args m2 d2 y2)))
  4720. (org-class
  4721. (nth 2 date1) (car date1) (nth 1 date1)
  4722. (nth 2 date2) (car date2) (nth 1 date2)
  4723. dayname skip-weeks)))
  4724. (make-obsolete 'org-diary-class 'org-class "")
  4725. (defalias 'org-get-closed 'org-agenda-get-progress)
  4726. (defun org-agenda-get-progress ()
  4727. "Return the logged TODO entries for agenda display."
  4728. (let* ((props (list 'mouse-face 'highlight
  4729. 'org-not-done-regexp org-not-done-regexp
  4730. 'org-todo-regexp org-todo-regexp
  4731. 'org-complex-heading-regexp org-complex-heading-regexp
  4732. 'help-echo
  4733. (format "mouse-2 or RET jump to org file %s"
  4734. (abbreviate-file-name buffer-file-name))))
  4735. (items (if (consp org-agenda-show-log-scoped)
  4736. org-agenda-show-log-scoped
  4737. (if (eq org-agenda-show-log-scoped 'clockcheck)
  4738. '(clock)
  4739. org-agenda-log-mode-items)))
  4740. (parts
  4741. (delq nil
  4742. (list
  4743. (if (memq 'closed items) (concat "\\<" org-closed-string))
  4744. (if (memq 'clock items) (concat "\\<" org-clock-string))
  4745. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  4746. (parts-re (if parts (mapconcat 'identity parts "\\|")
  4747. (error "`org-agenda-log-mode-items' is empty")))
  4748. (regexp (concat
  4749. "\\(" parts-re "\\)"
  4750. " *\\["
  4751. (regexp-quote
  4752. (substring
  4753. (format-time-string
  4754. (car org-time-stamp-formats)
  4755. (apply 'encode-time ; DATE bound by calendar
  4756. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  4757. 1 11))))
  4758. (org-agenda-search-headline-for-time nil)
  4759. marker hdmarker priority category org-category-pos tags closedp
  4760. statep clockp state ee txt extra timestr rest clocked)
  4761. (goto-char (point-min))
  4762. (while (re-search-forward regexp nil t)
  4763. (catch :skip
  4764. (org-agenda-skip)
  4765. (setq marker (org-agenda-new-marker (match-beginning 0))
  4766. closedp (equal (match-string 1) org-closed-string)
  4767. statep (equal (string-to-char (match-string 1)) ?-)
  4768. clockp (not (or closedp statep))
  4769. state (and statep (match-string 2))
  4770. category (org-get-category (match-beginning 0))
  4771. org-category-pos (get-text-property (match-beginning 0) 'org-category-position)
  4772. timestr (buffer-substring (match-beginning 0) (point-at-eol)))
  4773. (when (string-match "\\]" timestr)
  4774. ;; substring should only run to end of time stamp
  4775. (setq rest (substring timestr (match-end 0))
  4776. timestr (substring timestr 0 (match-end 0)))
  4777. (if (and (not closedp) (not statep)
  4778. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)"
  4779. rest))
  4780. (progn (setq timestr (concat (substring timestr 0 -1)
  4781. "-" (match-string 1 rest) "]"))
  4782. (setq clocked (match-string 2 rest)))
  4783. (setq clocked "-")))
  4784. (save-excursion
  4785. (setq extra
  4786. (cond
  4787. ((not org-agenda-log-mode-add-notes) nil)
  4788. (statep
  4789. (and (looking-at ".*\\\\\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  4790. (match-string 1)))
  4791. (clockp
  4792. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  4793. (match-string 1)))))
  4794. (if (not (re-search-backward org-outline-regexp-bol nil t))
  4795. (setq txt org-agenda-no-heading-message)
  4796. (goto-char (match-beginning 0))
  4797. (setq hdmarker (org-agenda-new-marker)
  4798. tags (org-get-tags-at))
  4799. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4800. (setq txt (match-string 1))
  4801. (when extra
  4802. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4803. (setq txt (concat (substring txt 0 (match-beginning 1))
  4804. " - " extra " " (match-string 2 txt)))
  4805. (setq txt (concat txt " - " extra))))
  4806. (setq txt (org-agenda-format-item
  4807. (cond
  4808. (closedp "Closed: ")
  4809. (statep (concat "State: (" state ")"))
  4810. (t (concat "Clocked: (" clocked ")")))
  4811. txt category tags timestr)))
  4812. (setq priority 100000)
  4813. (org-add-props txt props
  4814. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4815. 'priority priority 'org-category category
  4816. 'org-category-position org-category-pos
  4817. 'type "closed" 'date date
  4818. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4819. (push txt ee))
  4820. (goto-char (point-at-eol))))
  4821. (nreverse ee)))
  4822. (defun org-agenda-show-clocking-issues ()
  4823. "Add overlays, showing issues with clocking.
  4824. See also the user option `org-agenda-clock-consistency-checks'."
  4825. (interactive)
  4826. (let* ((pl org-agenda-clock-consistency-checks)
  4827. (re (concat "^[ \t]*"
  4828. org-clock-string
  4829. "[ \t]+"
  4830. "\\(\\[.*?\\]\\)" ; group 1 is first stamp
  4831. "\\(-\\{1,3\\}\\(\\[.*?\\]\\)\\)?")) ; group 3 is second
  4832. (tlstart 0.)
  4833. (tlend 0.)
  4834. (maxtime (org-hh:mm-string-to-minutes
  4835. (or (plist-get pl :max-duration) "24:00")))
  4836. (mintime (org-hh:mm-string-to-minutes
  4837. (or (plist-get pl :min-duration) 0)))
  4838. (maxgap (org-hh:mm-string-to-minutes
  4839. ;; default 30:00 means never complain
  4840. (or (plist-get pl :max-gap) "30:00")))
  4841. (gapok (mapcar 'org-hh:mm-string-to-minutes
  4842. (plist-get pl :gap-ok-around)))
  4843. (def-face (or (plist-get pl :default-face)
  4844. '((:background "DarkRed") (:foreground "white"))))
  4845. issue face m te ts dt ov)
  4846. (goto-char (point-min))
  4847. (while (re-search-forward " Clocked: +(-\\|\\([0-9]+:[0-9]+\\))" nil t)
  4848. (setq issue nil face def-face)
  4849. (catch 'next
  4850. (setq m (org-get-at-bol 'org-marker)
  4851. te nil ts nil)
  4852. (unless (and m (markerp m))
  4853. (setq issue "No valid clock line") (throw 'next t))
  4854. (org-with-point-at m
  4855. (save-excursion
  4856. (goto-char (point-at-bol))
  4857. (unless (looking-at re)
  4858. (error "No valid Clock line")
  4859. (throw 'next t))
  4860. (unless (match-end 3)
  4861. (setq issue "No end time"
  4862. face (or (plist-get pl :no-end-time-face) face))
  4863. (throw 'next t))
  4864. (setq ts (match-string 1)
  4865. te (match-string 3)
  4866. ts (org-float-time
  4867. (apply 'encode-time (org-parse-time-string ts)))
  4868. te (org-float-time
  4869. (apply 'encode-time (org-parse-time-string te)))
  4870. dt (- te ts))))
  4871. (cond
  4872. ((> dt (* 60 maxtime))
  4873. ;; a very long clocking chunk
  4874. (setq issue (format "Clocking interval is very long: %s"
  4875. (org-minutes-to-hh:mm-string
  4876. (floor (/ (float dt) 60.))))
  4877. face (or (plist-get pl :long-face) face)))
  4878. ((< dt (* 60 mintime))
  4879. ;; a very short clocking chunk
  4880. (setq issue (format "Clocking interval is very short: %s"
  4881. (org-minutes-to-hh:mm-string
  4882. (floor (/ (float dt) 60.))))
  4883. face (or (plist-get pl :short-face) face)))
  4884. ((and (> tlend 0) (< ts tlend))
  4885. ;; Two clock entries are overlapping
  4886. (setq issue (format "Clocking overlap: %d minutes"
  4887. (/ (- tlend ts) 60))
  4888. face (or (plist-get pl :overlap-face) face)))
  4889. ((and (> tlend 0) (> ts (+ tlend (* 60 maxgap))))
  4890. ;; There is a gap, lets see if we need to report it
  4891. (unless (org-agenda-check-clock-gap tlend ts gapok)
  4892. (setq issue (format "Clocking gap: %d minutes"
  4893. (/ (- ts tlend) 60))
  4894. face (or (plist-get pl :gap-face) face))))
  4895. (t nil)))
  4896. (setq tlend (or te tlend) tlstart (or ts tlstart))
  4897. (when issue
  4898. ;; OK, there was some issue, add an overlay to show the issue
  4899. (setq ov (make-overlay (point-at-bol) (point-at-eol)))
  4900. (overlay-put ov 'before-string
  4901. (concat
  4902. (org-add-props
  4903. (format "%-43s" (concat " " issue))
  4904. nil
  4905. 'face face)
  4906. "\n"))
  4907. (overlay-put ov 'evaporate t)))))
  4908. (defun org-agenda-check-clock-gap (t1 t2 ok-list)
  4909. "Check if gap T1 -> T2 contains one of the OK-LIST time-of-day values."
  4910. (catch 'exit
  4911. (unless ok-list
  4912. ;; there are no OK times for gaps...
  4913. (throw 'exit nil))
  4914. (if (> (- (/ t2 36000) (/ t1 36000)) 24)
  4915. ;; This is more than 24 hours, so it is OK.
  4916. ;; because we have at least one OK time, that must be in the
  4917. ;; 24 hour interval.
  4918. (throw 'exit t))
  4919. ;; We have a shorter gap.
  4920. ;; Now we have to get the minute of the day when these times are
  4921. (let* ((t1dec (decode-time (seconds-to-time t1)))
  4922. (t2dec (decode-time (seconds-to-time t2)))
  4923. ;; compute the minute on the day
  4924. (min1 (+ (nth 1 t1dec) (* 60 (nth 2 t1dec))))
  4925. (min2 (+ (nth 1 t2dec) (* 60 (nth 2 t2dec)))))
  4926. (when (< min2 min1)
  4927. ;; if min2 is smaller than min1, this means it is on the next day.
  4928. ;; Wrap it to after midnight.
  4929. (setq min2 (+ min2 1440)))
  4930. ;; Now check if any of the OK times is in the gap
  4931. (mapc (lambda (x)
  4932. ;; Wrap the time to after midnight if necessary
  4933. (if (< x min1) (setq x (+ x 1440)))
  4934. ;; Check if in interval
  4935. (and (<= min1 x) (>= min2 x) (throw 'exit t)))
  4936. ok-list)
  4937. ;; Nope, this gap is not OK
  4938. nil)))
  4939. (defun org-agenda-get-deadlines ()
  4940. "Return the deadline information for agenda display."
  4941. (let* ((props (list 'mouse-face 'highlight
  4942. 'org-not-done-regexp org-not-done-regexp
  4943. 'org-todo-regexp org-todo-regexp
  4944. 'org-complex-heading-regexp org-complex-heading-regexp
  4945. 'help-echo
  4946. (format "mouse-2 or RET jump to org file %s"
  4947. (abbreviate-file-name buffer-file-name))))
  4948. (regexp org-deadline-time-regexp)
  4949. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4950. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4951. d2 diff dfrac wdays pos pos1 category org-category-pos
  4952. tags suppress-prewarning ee txt head face s todo-state
  4953. show-all upcomingp donep timestr)
  4954. (goto-char (point-min))
  4955. (while (re-search-forward regexp nil t)
  4956. (setq suppress-prewarning nil)
  4957. (catch :skip
  4958. (org-agenda-skip)
  4959. (when (and org-agenda-skip-deadline-prewarning-if-scheduled
  4960. (save-match-data
  4961. (string-match org-scheduled-time-regexp
  4962. (buffer-substring (point-at-bol)
  4963. (point-at-eol)))))
  4964. (setq suppress-prewarning
  4965. (if (integerp org-agenda-skip-deadline-prewarning-if-scheduled)
  4966. org-agenda-skip-deadline-prewarning-if-scheduled
  4967. 0)))
  4968. (setq s (match-string 1)
  4969. txt nil
  4970. pos (1- (match-beginning 1))
  4971. todo-state (save-match-data (org-get-todo-state))
  4972. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  4973. (member todo-state
  4974. org-agenda-repeating-timestamp-show-all))
  4975. d2 (org-time-string-to-absolute
  4976. (match-string 1) d1 'past show-all
  4977. (current-buffer) pos)
  4978. diff (- d2 d1)
  4979. wdays (if suppress-prewarning
  4980. (let ((org-deadline-warning-days suppress-prewarning))
  4981. (org-get-wdays s))
  4982. (org-get-wdays s))
  4983. dfrac (- 1 (/ (* 1.0 diff) (max wdays 1)))
  4984. upcomingp (and todayp (> diff 0)))
  4985. ;; When to show a deadline in the calendar:
  4986. ;; If the expiration is within wdays warning time.
  4987. ;; Past-due deadlines are only shown on the current date
  4988. (if (and (or (and (<= diff wdays)
  4989. (and todayp (not org-agenda-only-exact-dates)))
  4990. (= diff 0)))
  4991. (save-excursion
  4992. ;; (setq todo-state (org-get-todo-state))
  4993. (setq donep (member todo-state org-done-keywords))
  4994. (if (and donep
  4995. (or org-agenda-skip-deadline-if-done
  4996. (not (= diff 0))))
  4997. (setq txt nil)
  4998. (setq category (org-get-category)
  4999. org-category-pos (get-text-property (point) 'org-category-position))
  5000. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5001. (setq txt org-agenda-no-heading-message)
  5002. (goto-char (match-end 0))
  5003. (setq pos1 (match-beginning 0))
  5004. (setq tags (org-get-tags-at pos1))
  5005. (setq head (buffer-substring-no-properties
  5006. (point)
  5007. (progn (skip-chars-forward "^\r\n")
  5008. (point))))
  5009. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5010. (setq timestr
  5011. (concat (substring s (match-beginning 1)) " "))
  5012. (setq timestr 'time))
  5013. (setq txt (org-agenda-format-item
  5014. (if (= diff 0)
  5015. (car org-agenda-deadline-leaders)
  5016. (if (functionp
  5017. (nth 1 org-agenda-deadline-leaders))
  5018. (funcall
  5019. (nth 1 org-agenda-deadline-leaders)
  5020. diff date)
  5021. (format (nth 1 org-agenda-deadline-leaders)
  5022. diff)))
  5023. head category tags
  5024. (if (not (= diff 0)) nil timestr)))))
  5025. (when txt
  5026. (setq face (org-agenda-deadline-face dfrac))
  5027. (org-add-props txt props
  5028. 'org-marker (org-agenda-new-marker pos)
  5029. 'org-hd-marker (org-agenda-new-marker pos1)
  5030. 'priority (+ (- diff)
  5031. (org-get-priority txt))
  5032. 'org-category category
  5033. 'org-category-position org-category-pos
  5034. 'todo-state todo-state
  5035. 'type (if upcomingp "upcoming-deadline" "deadline")
  5036. 'date (if upcomingp date d2)
  5037. 'face (if donep 'org-agenda-done face)
  5038. 'undone-face face 'done-face 'org-agenda-done)
  5039. (push txt ee))))))
  5040. (nreverse ee)))
  5041. (defun org-agenda-deadline-face (fraction)
  5042. "Return the face to displaying a deadline item.
  5043. FRACTION is what fraction of the head-warning time has passed."
  5044. (let ((faces org-agenda-deadline-faces) f)
  5045. (catch 'exit
  5046. (while (setq f (pop faces))
  5047. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  5048. (defun org-agenda-get-scheduled (&optional deadline-results)
  5049. "Return the scheduled information for agenda display."
  5050. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  5051. 'org-todo-regexp org-todo-regexp
  5052. 'org-complex-heading-regexp org-complex-heading-regexp
  5053. 'done-face 'org-agenda-done
  5054. 'mouse-face 'highlight
  5055. 'help-echo
  5056. (format "mouse-2 or RET jump to org file %s"
  5057. (abbreviate-file-name buffer-file-name))))
  5058. (regexp org-scheduled-time-regexp)
  5059. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  5060. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  5061. mm
  5062. (deadline-position-alist
  5063. (mapcar (lambda (a) (and (setq mm (get-text-property
  5064. 0 'org-hd-marker a))
  5065. (cons (marker-position mm) a)))
  5066. deadline-results))
  5067. d2 diff pos pos1 category org-category-pos tags donep
  5068. ee txt head pastschedp todo-state face timestr s habitp show-all)
  5069. (goto-char (point-min))
  5070. (while (re-search-forward regexp nil t)
  5071. (catch :skip
  5072. (org-agenda-skip)
  5073. (setq s (match-string 1)
  5074. txt nil
  5075. pos (1- (match-beginning 1))
  5076. todo-state (save-match-data (org-get-todo-state))
  5077. show-all (or (eq org-agenda-repeating-timestamp-show-all t)
  5078. (member todo-state
  5079. org-agenda-repeating-timestamp-show-all))
  5080. d2 (org-time-string-to-absolute
  5081. (match-string 1) d1 'past show-all
  5082. (current-buffer) pos)
  5083. diff (- d2 d1))
  5084. (setq pastschedp (and todayp (< diff 0)))
  5085. ;; When to show a scheduled item in the calendar:
  5086. ;; If it is on or past the date.
  5087. (when (or (and (< diff 0)
  5088. (< (abs diff) org-scheduled-past-days)
  5089. (and todayp (not org-agenda-only-exact-dates)))
  5090. (= diff 0))
  5091. (save-excursion
  5092. (setq donep (member todo-state org-done-keywords))
  5093. (if (and donep
  5094. (or org-agenda-skip-scheduled-if-done
  5095. (not (= diff 0))
  5096. (and (functionp 'org-is-habit-p)
  5097. (org-is-habit-p))))
  5098. (setq txt nil)
  5099. (setq habitp (and (functionp 'org-is-habit-p)
  5100. (org-is-habit-p)))
  5101. (setq category (org-get-category)
  5102. org-category-pos (get-text-property (point) 'org-category-position))
  5103. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  5104. (setq txt org-agenda-no-heading-message)
  5105. (goto-char (match-end 0))
  5106. (setq pos1 (match-beginning 0))
  5107. (if habitp
  5108. (if (or (not org-habit-show-habits)
  5109. (and (not todayp)
  5110. org-habit-show-habits-only-for-today))
  5111. (throw :skip nil))
  5112. (if (and
  5113. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  5114. (and org-agenda-skip-scheduled-if-deadline-is-shown
  5115. pastschedp))
  5116. (setq mm (assoc pos1 deadline-position-alist)))
  5117. (throw :skip nil)))
  5118. (setq tags (org-get-tags-at))
  5119. (setq head (buffer-substring-no-properties
  5120. (point)
  5121. (progn (skip-chars-forward "^\r\n") (point))))
  5122. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  5123. (setq timestr
  5124. (concat (substring s (match-beginning 1)) " "))
  5125. (setq timestr 'time))
  5126. (setq txt (org-agenda-format-item
  5127. (if (= diff 0)
  5128. (car org-agenda-scheduled-leaders)
  5129. (format (nth 1 org-agenda-scheduled-leaders)
  5130. (- 1 diff)))
  5131. head category tags
  5132. (if (not (= diff 0)) nil timestr)
  5133. nil habitp))))
  5134. (when txt
  5135. (setq face
  5136. (cond
  5137. ((and (not habitp) pastschedp)
  5138. 'org-scheduled-previously)
  5139. (todayp 'org-scheduled-today)
  5140. (t 'org-scheduled))
  5141. habitp (and habitp (org-habit-parse-todo)))
  5142. (org-add-props txt props
  5143. 'undone-face face
  5144. 'face (if donep 'org-agenda-done face)
  5145. 'org-marker (org-agenda-new-marker pos)
  5146. 'org-hd-marker (org-agenda-new-marker pos1)
  5147. 'type (if pastschedp "past-scheduled" "scheduled")
  5148. 'date (if pastschedp d2 date)
  5149. 'priority (if habitp
  5150. (org-habit-get-priority habitp)
  5151. (+ 94 (- 5 diff) (org-get-priority txt)))
  5152. 'org-category category
  5153. 'org-category-position org-category-pos
  5154. 'org-habit-p habitp
  5155. 'todo-state todo-state)
  5156. (push txt ee))))))
  5157. (nreverse ee)))
  5158. (defun org-agenda-get-blocks ()
  5159. "Return the date-range information for agenda display."
  5160. (let* ((props (list 'face nil
  5161. 'org-not-done-regexp org-not-done-regexp
  5162. 'org-todo-regexp org-todo-regexp
  5163. 'org-complex-heading-regexp org-complex-heading-regexp
  5164. 'mouse-face 'highlight
  5165. 'help-echo
  5166. (format "mouse-2 or RET jump to org file %s"
  5167. (abbreviate-file-name buffer-file-name))))
  5168. (regexp org-tr-regexp)
  5169. (d0 (calendar-absolute-from-gregorian date))
  5170. marker hdmarker ee txt d1 d2 s1 s2 category org-category-pos
  5171. todo-state tags pos head donep)
  5172. (goto-char (point-min))
  5173. (while (re-search-forward regexp nil t)
  5174. (catch :skip
  5175. (org-agenda-skip)
  5176. (setq pos (point))
  5177. (let ((start-time (match-string 1))
  5178. (end-time (match-string 2)))
  5179. (setq s1 (match-string 1)
  5180. s2 (match-string 2)
  5181. d1 (time-to-days (org-time-string-to-time s1 (current-buffer) pos))
  5182. d2 (time-to-days (org-time-string-to-time s2 (current-buffer) pos)))
  5183. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  5184. ;; Only allow days between the limits, because the normal
  5185. ;; date stamps will catch the limits.
  5186. (save-excursion
  5187. (setq todo-state (org-get-todo-state))
  5188. (setq donep (member todo-state org-done-keywords))
  5189. (if (and donep org-agenda-skip-timestamp-if-done)
  5190. (throw :skip t))
  5191. (setq marker (org-agenda-new-marker (point)))
  5192. (setq category (org-get-category)
  5193. org-category-pos (get-text-property (point) 'org-category-position))
  5194. (if (not (re-search-backward org-outline-regexp-bol nil t))
  5195. (setq txt org-agenda-no-heading-message)
  5196. (goto-char (match-beginning 0))
  5197. (setq hdmarker (org-agenda-new-marker (point)))
  5198. (setq tags (org-get-tags-at))
  5199. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  5200. (setq head (match-string 1))
  5201. (let ((remove-re
  5202. (if org-agenda-remove-timeranges-from-blocks
  5203. (concat
  5204. "<" (regexp-quote s1) ".*?>"
  5205. "--"
  5206. "<" (regexp-quote s2) ".*?>")
  5207. nil)))
  5208. (setq txt (org-agenda-format-item
  5209. (format
  5210. (nth (if (= d1 d2) 0 1)
  5211. org-agenda-timerange-leaders)
  5212. (1+ (- d0 d1)) (1+ (- d2 d1)))
  5213. head category tags
  5214. (cond ((and (= d1 d0) (= d2 d0))
  5215. (concat "<" start-time ">--<" end-time ">"))
  5216. ((= d1 d0)
  5217. (concat "<" start-time ">"))
  5218. ((= d2 d0)
  5219. (concat "<" end-time ">"))
  5220. (t nil))
  5221. remove-re))))
  5222. (org-add-props txt props
  5223. 'org-marker marker 'org-hd-marker hdmarker
  5224. 'type "block" 'date date
  5225. 'todo-state todo-state
  5226. 'priority (org-get-priority txt) 'org-category category
  5227. 'org-category-position org-category-pos)
  5228. (push txt ee))))
  5229. (goto-char pos)))
  5230. ;; Sort the entries by expiration date.
  5231. (nreverse ee)))
  5232. ;;; Agenda presentation and sorting
  5233. (defvar org-prefix-has-time nil
  5234. "A flag, set by `org-compile-prefix-format'.
  5235. The flag is set if the currently compiled format contains a `%t'.")
  5236. (defvar org-prefix-has-tag nil
  5237. "A flag, set by `org-compile-prefix-format'.
  5238. The flag is set if the currently compiled format contains a `%T'.")
  5239. (defvar org-prefix-has-effort nil
  5240. "A flag, set by `org-compile-prefix-format'.
  5241. The flag is set if the currently compiled format contains a `%e'.")
  5242. (defvar org-prefix-category-length nil
  5243. "Used by `org-compile-prefix-format' to remember the category field width.")
  5244. (defvar org-prefix-category-max-length nil
  5245. "Used by `org-compile-prefix-format' to remember the category field width.")
  5246. (defun org-agenda-get-category-icon (category)
  5247. "Return an image for CATEGORY according to `org-agenda-category-icon-alist'."
  5248. (dolist (entry org-agenda-category-icon-alist)
  5249. (when (org-string-match-p (car entry) category)
  5250. (if (listp (cadr entry))
  5251. (return (cadr entry))
  5252. (return (apply 'create-image (cdr entry)))))))
  5253. (defun org-agenda-format-item (extra txt &optional category tags dotime
  5254. remove-re habitp)
  5255. "Format TXT to be inserted into the agenda buffer.
  5256. In particular, it adds the prefix and corresponding text properties. EXTRA
  5257. must be a string and replaces the `%s' specifier in the prefix format.
  5258. CATEGORY (string, symbol or nil) may be used to overrule the default
  5259. category taken from local variable or file name. It will replace the `%c'
  5260. specifier in the format. DOTIME, when non-nil, indicates that a
  5261. time-of-day should be extracted from TXT for sorting of this entry, and for
  5262. the `%t' specifier in the format. When DOTIME is a string, this string is
  5263. searched for a time before TXT is. TAGS can be the tags of the headline.
  5264. Any match of REMOVE-RE will be removed from TXT."
  5265. ;; We keep the org-prefix-* variable values along with a compiled
  5266. ;; formatter, so that multiple agendas existing at the same time, do
  5267. ;; not step on each other toes.
  5268. ;;
  5269. ;; It was inconvenient to make these variables buffer local in
  5270. ;; Agenda buffers, because this function expects to be called with
  5271. ;; the buffer where item comes from being current, and not agenda
  5272. ;; buffer
  5273. (let* ((bindings (car org-prefix-format-compiled))
  5274. (formatter (cadr org-prefix-format-compiled)))
  5275. (loop for (var value) in bindings
  5276. do (set var value))
  5277. (save-match-data
  5278. ;; Diary entries sometimes have extra whitespace at the beginning
  5279. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  5280. ;; Fix the tags part in txt
  5281. (setq txt (org-agenda-fix-displayed-tags
  5282. txt tags
  5283. org-agenda-show-inherited-tags
  5284. org-agenda-hide-tags-regexp))
  5285. (let* ((category (or category
  5286. (if (stringp org-category)
  5287. org-category
  5288. (and org-category (symbol-name org-category)))
  5289. (if buffer-file-name
  5290. (file-name-sans-extension
  5291. (file-name-nondirectory buffer-file-name))
  5292. "")))
  5293. (category-icon (org-agenda-get-category-icon category))
  5294. (category-icon (if category-icon
  5295. (propertize " " 'display category-icon)
  5296. ""))
  5297. ;; time, tag, effort are needed for the eval of the prefix format
  5298. (tag (if tags (nth (1- (length tags)) tags) ""))
  5299. time effort neffort
  5300. (ts (if dotime (concat
  5301. (if (stringp dotime) dotime "")
  5302. (and org-agenda-search-headline-for-time txt))))
  5303. (time-of-day (and dotime (org-get-time-of-day ts)))
  5304. stamp plain s0 s1 s2 rtn srp l
  5305. duration thecategory)
  5306. (and (eq major-mode 'org-mode) buffer-file-name
  5307. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  5308. (when (and dotime time-of-day)
  5309. ;; Extract starting and ending time and move them to prefix
  5310. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  5311. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  5312. (setq s0 (match-string 0 ts)
  5313. srp (and stamp (match-end 3))
  5314. s1 (match-string (if plain 1 2) ts)
  5315. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  5316. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  5317. ;; them, we might want to remove them there to avoid duplication.
  5318. ;; The user can turn this off with a variable.
  5319. (if (and org-prefix-has-time
  5320. org-agenda-remove-times-when-in-prefix (or stamp plain)
  5321. (string-match (concat (regexp-quote s0) " *") txt)
  5322. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  5323. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  5324. (= (match-beginning 0) 0)
  5325. t))
  5326. (setq txt (replace-match "" nil nil txt))))
  5327. ;; Normalize the time(s) to 24 hour
  5328. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  5329. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  5330. ;; Try to set s2 if s1 and `org-agenda-default-appointment-duration' are set
  5331. (when (and s1 (not s2) org-agenda-default-appointment-duration)
  5332. (setq s2
  5333. (org-minutes-to-hh:mm-string
  5334. (+ (org-hh:mm-string-to-minutes s1) org-agenda-default-appointment-duration))))
  5335. ;; Compute the duration
  5336. (when s2
  5337. (setq duration (- (org-hh:mm-string-to-minutes s2)
  5338. (org-hh:mm-string-to-minutes s1)))))
  5339. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  5340. txt)
  5341. ;; Tags are in the string
  5342. (if (or (eq org-agenda-remove-tags t)
  5343. (and org-agenda-remove-tags
  5344. org-prefix-has-tag))
  5345. (setq txt (replace-match "" t t txt))
  5346. (setq txt (replace-match
  5347. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  5348. (match-string 2 txt))
  5349. t t txt))))
  5350. (when (eq major-mode 'org-mode)
  5351. (setq effort
  5352. (condition-case nil
  5353. (org-get-effort
  5354. (or (get-text-property 0 'org-hd-marker txt)
  5355. (get-text-property 0 'org-marker txt)))
  5356. (error nil)))
  5357. (when effort
  5358. (setq neffort (org-duration-string-to-minutes effort)
  5359. effort (setq effort (concat "[" effort "]")))))
  5360. ;; prevent erroring out with %e format when there is no effort
  5361. (or effort (setq effort ""))
  5362. (when remove-re
  5363. (while (string-match remove-re txt)
  5364. (setq txt (replace-match "" t t txt))))
  5365. ;; Set org-heading property on `txt' to mark the start of the
  5366. ;; heading.
  5367. (add-text-properties 0 (length txt) '(org-heading t) txt)
  5368. ;; Prepare the variables needed in the eval of the compiled format
  5369. (setq time (cond (s2 (concat
  5370. (org-agenda-time-of-day-to-ampm-maybe s1)
  5371. "-" (org-agenda-time-of-day-to-ampm-maybe s2)
  5372. (if org-agenda-timegrid-use-ampm " ")))
  5373. (s1 (concat
  5374. (org-agenda-time-of-day-to-ampm-maybe s1)
  5375. (if org-agenda-timegrid-use-ampm
  5376. "........ "
  5377. "......")))
  5378. (t ""))
  5379. extra (or (and (not habitp) extra) "")
  5380. category (if (symbolp category) (symbol-name category) category)
  5381. thecategory (copy-sequence category))
  5382. (if (string-match org-bracket-link-regexp category)
  5383. (progn
  5384. (setq l (if (match-end 3)
  5385. (- (match-end 3) (match-beginning 3))
  5386. (- (match-end 1) (match-beginning 1))))
  5387. (when (< l (or org-prefix-category-length 0))
  5388. (setq category (copy-sequence category))
  5389. (org-add-props category nil
  5390. 'extra-space (make-string
  5391. (- org-prefix-category-length l 1) ?\ ))))
  5392. (if (and org-prefix-category-max-length
  5393. (>= (length category) org-prefix-category-max-length))
  5394. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  5395. ;; Evaluate the compiled format
  5396. (setq rtn (concat (eval formatter) txt))
  5397. ;; And finally add the text properties
  5398. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  5399. (org-add-props rtn nil
  5400. 'org-category (if thecategory (downcase thecategory) category)
  5401. 'tags (mapcar 'org-downcase-keep-props tags)
  5402. 'org-highest-priority org-highest-priority
  5403. 'org-lowest-priority org-lowest-priority
  5404. 'time-of-day time-of-day
  5405. 'duration duration
  5406. 'effort effort
  5407. 'effort-minutes neffort
  5408. 'txt txt
  5409. 'time time
  5410. 'extra extra
  5411. 'format org-prefix-format-compiled
  5412. 'dotime dotime)))))
  5413. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  5414. "Remove tags string from TXT, and add a modified list of tags.
  5415. The modified list may contain inherited tags, and tags matched by
  5416. `org-agenda-hide-tags-regexp' will be removed."
  5417. (when (or add-inherited hide-re)
  5418. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") txt)
  5419. (setq txt (substring txt 0 (match-beginning 0))))
  5420. (setq tags
  5421. (delq nil
  5422. (mapcar (lambda (tg)
  5423. (if (or (and hide-re (string-match hide-re tg))
  5424. (and (not add-inherited)
  5425. (get-text-property 0 'inherited tg)))
  5426. nil
  5427. tg))
  5428. tags)))
  5429. (when tags
  5430. (let ((have-i (get-text-property 0 'inherited (car tags)))
  5431. i)
  5432. (setq txt (concat txt " :"
  5433. (mapconcat
  5434. (lambda (x)
  5435. (setq i (get-text-property 0 'inherited x))
  5436. (if (and have-i (not i))
  5437. (progn
  5438. (setq have-i nil)
  5439. (concat ":" x))
  5440. x))
  5441. tags ":")
  5442. (if have-i "::" ":"))))))
  5443. txt)
  5444. (defun org-downcase-keep-props (s)
  5445. (let ((props (text-properties-at 0 s)))
  5446. (setq s (downcase s))
  5447. (add-text-properties 0 (length s) props s)
  5448. s))
  5449. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  5450. (defvar org-agenda-sorting-strategy-selected nil)
  5451. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  5452. (catch 'exit
  5453. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  5454. ((and todayp (member 'today (car org-agenda-time-grid))))
  5455. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  5456. ((member 'weekly (car org-agenda-time-grid)))
  5457. (t (throw 'exit list)))
  5458. (let* ((have (delq nil (mapcar
  5459. (lambda (x) (get-text-property 1 'time-of-day x))
  5460. list)))
  5461. (string (nth 1 org-agenda-time-grid))
  5462. (gridtimes (nth 2 org-agenda-time-grid))
  5463. (req (car org-agenda-time-grid))
  5464. (remove (member 'remove-match req))
  5465. new time)
  5466. (if (and (member 'require-timed req) (not have))
  5467. ;; don't show empty grid
  5468. (throw 'exit list))
  5469. (while (setq time (pop gridtimes))
  5470. (unless (and remove (member time have))
  5471. (setq time (replace-regexp-in-string " " "0" (format "%04s" time)))
  5472. (push (org-agenda-format-item
  5473. nil string "" nil
  5474. (concat (substring time 0 -2) ":" (substring time -2)))
  5475. new)
  5476. (put-text-property
  5477. 2 (length (car new)) 'face 'org-time-grid (car new))))
  5478. (when (and todayp org-agenda-show-current-time-in-grid)
  5479. (push (org-agenda-format-item
  5480. nil
  5481. org-agenda-current-time-string
  5482. "" nil
  5483. (format-time-string "%H:%M "))
  5484. new)
  5485. (put-text-property
  5486. 2 (length (car new)) 'face 'org-agenda-current-time (car new)))
  5487. (if (member 'time-up org-agenda-sorting-strategy-selected)
  5488. (append new list)
  5489. (append list new)))))
  5490. (defun org-compile-prefix-format (key)
  5491. "Compile the prefix format into a Lisp form that can be evaluated.
  5492. The resulting form and associated variable bindings is returned
  5493. and stored in the variable `org-prefix-format-compiled'."
  5494. (setq org-prefix-has-time nil org-prefix-has-tag nil
  5495. org-prefix-category-length nil
  5496. org-prefix-has-effort nil)
  5497. (let ((s (cond
  5498. ((stringp org-agenda-prefix-format)
  5499. org-agenda-prefix-format)
  5500. ((assq key org-agenda-prefix-format)
  5501. (cdr (assq key org-agenda-prefix-format)))
  5502. (t " %-12:c%?-12t% s")))
  5503. (start 0)
  5504. varform vars var e c f opt)
  5505. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctsei]\\|(.+)\\)"
  5506. s start)
  5507. (setq var (or (cdr (assoc (match-string 4 s)
  5508. '(("c" . category) ("t" . time) ("s" . extra)
  5509. ("i" . category-icon) ("T" . tag) ("e" . effort))))
  5510. 'eval)
  5511. c (or (match-string 3 s) "")
  5512. opt (match-beginning 1)
  5513. start (1+ (match-beginning 0)))
  5514. (if (equal var 'time) (setq org-prefix-has-time t))
  5515. (if (equal var 'tag) (setq org-prefix-has-tag t))
  5516. (if (equal var 'effort) (setq org-prefix-has-effort t))
  5517. (setq f (concat "%" (match-string 2 s) "s"))
  5518. (when (equal var 'category)
  5519. (setq org-prefix-category-length
  5520. (floor (abs (string-to-number (match-string 2 s)))))
  5521. (setq org-prefix-category-max-length
  5522. (let ((x (match-string 2 s)))
  5523. (save-match-data
  5524. (if (string-match "\\.[0-9]+" x)
  5525. (string-to-number (substring (match-string 0 x) 1)))))))
  5526. (if (eq var 'eval)
  5527. (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
  5528. (if opt
  5529. (setq varform
  5530. `(if (equal "" ,var)
  5531. ""
  5532. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  5533. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
  5534. (setq s (replace-match "%s" t nil s))
  5535. (push varform vars))
  5536. (setq vars (nreverse vars))
  5537. (with-current-buffer org-agenda-buffer
  5538. (setq org-prefix-format-compiled
  5539. (list
  5540. `((org-prefix-has-time ,org-prefix-has-time)
  5541. (org-prefix-has-tag ,org-prefix-has-tag)
  5542. (org-prefix-category-length ,org-prefix-category-length)
  5543. (org-prefix-has-effort ,org-prefix-has-effort))
  5544. `(format ,s ,@vars))))))
  5545. (defun org-set-sorting-strategy (key)
  5546. (if (symbolp (car org-agenda-sorting-strategy))
  5547. ;; the old format
  5548. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  5549. (setq org-agenda-sorting-strategy-selected
  5550. (or (cdr (assq key org-agenda-sorting-strategy))
  5551. (cdr (assq 'agenda org-agenda-sorting-strategy))
  5552. '(time-up category-keep priority-down)))))
  5553. (defun org-get-time-of-day (s &optional string mod24)
  5554. "Check string S for a time of day.
  5555. If found, return it as a military time number between 0 and 2400.
  5556. If not found, return nil.
  5557. The optional STRING argument forces conversion into a 5 character wide string
  5558. HH:MM."
  5559. (save-match-data
  5560. (when
  5561. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  5562. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  5563. (let* ((h (string-to-number (match-string 1 s)))
  5564. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  5565. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  5566. (am-p (equal ampm "am"))
  5567. (h1 (cond ((not ampm) h)
  5568. ((= h 12) (if am-p 0 12))
  5569. (t (+ h (if am-p 0 12)))))
  5570. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  5571. (mod h1 24) h1))
  5572. (t0 (+ (* 100 h2) m))
  5573. (t1 (concat (if (>= h1 24) "+" " ")
  5574. (if (and org-agenda-time-leading-zero
  5575. (< t0 1000)) "0" "")
  5576. (if (< t0 100) "0" "")
  5577. (if (< t0 10) "0" "")
  5578. (int-to-string t0))))
  5579. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  5580. (defvar org-agenda-before-sorting-filter-function nil
  5581. "Function to be applied to agenda items prior to sorting.
  5582. Prior to sorting also means just before they are inserted into the agenda.
  5583. To aid sorting, you may revisit the original entries and add more text
  5584. properties which will later be used by the sorting functions.
  5585. The function should take a string argument, an agenda line.
  5586. It has access to the text properties in that line, which contain among
  5587. other things, the property `org-hd-marker' that points to the entry
  5588. where the line comes from. Note that not all lines going into the agenda
  5589. have this property, only most.
  5590. The function should return the modified string. It is probably best
  5591. to ONLY change text properties.
  5592. You can also use this function as a filter, by returning nil for lines
  5593. you don't want to have in the agenda at all. For this application, you
  5594. could bind the variable in the options section of a custom command.")
  5595. (defun org-finalize-agenda-entries (list &optional nosort)
  5596. "Sort and concatenate the agenda items."
  5597. (setq list (mapcar 'org-agenda-highlight-todo list))
  5598. (if nosort
  5599. list
  5600. (when org-agenda-before-sorting-filter-function
  5601. (setq list (delq nil (mapcar org-agenda-before-sorting-filter-function list))))
  5602. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  5603. (defun org-agenda-highlight-todo (x)
  5604. (let ((org-done-keywords org-done-keywords-for-agenda)
  5605. (case-fold-search nil)
  5606. re)
  5607. (if (eq x 'line)
  5608. (save-excursion
  5609. (beginning-of-line 1)
  5610. (setq re (org-get-at-bol 'org-todo-regexp))
  5611. (goto-char (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t) (point)))
  5612. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  5613. (add-text-properties (match-beginning 0) (match-end 1)
  5614. (list 'face (org-get-todo-face 1)))
  5615. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  5616. (delete-region (match-beginning 1) (1- (match-end 0)))
  5617. (goto-char (match-beginning 1))
  5618. (insert (format org-agenda-todo-keyword-format s)))))
  5619. (let ((pl (text-property-any 0 (length x) 'org-heading t x)))
  5620. (setq re (get-text-property 0 'org-todo-regexp x))
  5621. (when (and re
  5622. ;; Test `pl' because if there's no heading content,
  5623. ;; there's no point matching to highlight. Note
  5624. ;; that if we didn't test `pl' first, and there
  5625. ;; happened to be no keyword from `org-todo-regexp'
  5626. ;; on this heading line, then the `equal' comparison
  5627. ;; afterwards would spuriously succeed in the case
  5628. ;; where `pl' is nil -- causing an args-out-of-range
  5629. ;; error when we try to add text properties to text
  5630. ;; that isn't there.
  5631. pl
  5632. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  5633. x pl) pl))
  5634. (add-text-properties
  5635. (or (match-end 1) (match-end 0)) (match-end 0)
  5636. (list 'face (org-get-todo-face (match-string 2 x)))
  5637. x)
  5638. (when (match-end 1)
  5639. (setq x (concat (substring x 0 (match-end 1))
  5640. (format org-agenda-todo-keyword-format
  5641. (match-string 2 x))
  5642. (org-add-props " " (text-properties-at 0 x))
  5643. (substring x (match-end 3)))))))
  5644. x)))
  5645. (defsubst org-cmp-priority (a b)
  5646. "Compare the priorities of string A and B."
  5647. (let ((pa (or (get-text-property 1 'priority a) 0))
  5648. (pb (or (get-text-property 1 'priority b) 0)))
  5649. (cond ((> pa pb) +1)
  5650. ((< pa pb) -1)
  5651. (t nil))))
  5652. (defsubst org-cmp-effort (a b)
  5653. "Compare the effort values of string A and B."
  5654. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  5655. (ea (or (get-text-property 1 'effort-minutes a) def))
  5656. (eb (or (get-text-property 1 'effort-minutes b) def)))
  5657. (cond ((> ea eb) +1)
  5658. ((< ea eb) -1)
  5659. (t nil))))
  5660. (defsubst org-cmp-category (a b)
  5661. "Compare the string values of categories of strings A and B."
  5662. (let ((ca (or (get-text-property 1 'org-category a) ""))
  5663. (cb (or (get-text-property 1 'org-category b) "")))
  5664. (cond ((string-lessp ca cb) -1)
  5665. ((string-lessp cb ca) +1)
  5666. (t nil))))
  5667. (defsubst org-cmp-todo-state (a b)
  5668. "Compare the todo states of strings A and B."
  5669. (let* ((ma (or (get-text-property 1 'org-marker a)
  5670. (get-text-property 1 'org-hd-marker a)))
  5671. (mb (or (get-text-property 1 'org-marker b)
  5672. (get-text-property 1 'org-hd-marker b)))
  5673. (fa (and ma (marker-buffer ma)))
  5674. (fb (and mb (marker-buffer mb)))
  5675. (todo-kwds
  5676. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  5677. (and fb (with-current-buffer fb org-todo-keywords-1))))
  5678. (ta (or (get-text-property 1 'todo-state a) ""))
  5679. (tb (or (get-text-property 1 'todo-state b) ""))
  5680. (la (- (length (member ta todo-kwds))))
  5681. (lb (- (length (member tb todo-kwds))))
  5682. (donepa (member ta org-done-keywords-for-agenda))
  5683. (donepb (member tb org-done-keywords-for-agenda)))
  5684. (cond ((and donepa (not donepb)) -1)
  5685. ((and (not donepa) donepb) +1)
  5686. ((< la lb) -1)
  5687. ((< lb la) +1)
  5688. (t nil))))
  5689. (defsubst org-cmp-alpha (a b)
  5690. "Compare the headlines, alphabetically."
  5691. (let* ((pla (text-property-any 0 (length a) 'org-heading t a))
  5692. (plb (text-property-any 0 (length b) 'org-heading t b))
  5693. (ta (and pla (substring a pla)))
  5694. (tb (and plb (substring b plb))))
  5695. (when pla
  5696. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp a) "")
  5697. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") ta)
  5698. (setq ta (substring ta (match-end 0))))
  5699. (setq ta (downcase ta)))
  5700. (when plb
  5701. (if (string-match (concat "\\`[ \t]*" (or (get-text-property 0 'org-todo-regexp b) "")
  5702. "\\([ \t]*\\[[a-zA-Z0-9]\\]\\)? *") tb)
  5703. (setq tb (substring tb (match-end 0))))
  5704. (setq tb (downcase tb)))
  5705. (cond ((not ta) +1)
  5706. ((not tb) -1)
  5707. ((string-lessp ta tb) -1)
  5708. ((string-lessp tb ta) +1)
  5709. (t nil))))
  5710. (defsubst org-cmp-tag (a b)
  5711. "Compare the string values of the first tags of A and B."
  5712. (let ((ta (car (last (get-text-property 1 'tags a))))
  5713. (tb (car (last (get-text-property 1 'tags b)))))
  5714. (cond ((not ta) +1)
  5715. ((not tb) -1)
  5716. ((string-lessp ta tb) -1)
  5717. ((string-lessp tb ta) +1)
  5718. (t nil))))
  5719. (defsubst org-cmp-time (a b)
  5720. "Compare the time-of-day values of strings A and B."
  5721. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  5722. (ta (or (get-text-property 1 'time-of-day a) def))
  5723. (tb (or (get-text-property 1 'time-of-day b) def)))
  5724. (cond ((< ta tb) -1)
  5725. ((< tb ta) +1)
  5726. (t nil))))
  5727. (defsubst org-cmp-habit-p (a b)
  5728. "Compare the todo states of strings A and B."
  5729. (let ((ha (get-text-property 1 'org-habit-p a))
  5730. (hb (get-text-property 1 'org-habit-p b)))
  5731. (cond ((and ha (not hb)) -1)
  5732. ((and (not ha) hb) +1)
  5733. (t nil))))
  5734. (defsubst org-em (x y list) (or (memq x list) (memq y list)))
  5735. (defun org-entries-lessp (a b)
  5736. "Predicate for sorting agenda entries."
  5737. ;; The following variables will be used when the form is evaluated.
  5738. ;; So even though the compiler complains, keep them.
  5739. (let* ((ss org-agenda-sorting-strategy-selected)
  5740. (time-up (and (org-em 'time-up 'time-down ss)
  5741. (org-cmp-time a b)))
  5742. (time-down (if time-up (- time-up) nil))
  5743. (priority-up (and (org-em 'priority-up 'priority-down ss)
  5744. (org-cmp-priority a b)))
  5745. (priority-down (if priority-up (- priority-up) nil))
  5746. (effort-up (and (org-em 'effort-up 'effort-down ss)
  5747. (org-cmp-effort a b)))
  5748. (effort-down (if effort-up (- effort-up) nil))
  5749. (category-up (and (or (org-em 'category-up 'category-down ss)
  5750. (memq 'category-keep ss))
  5751. (org-cmp-category a b)))
  5752. (category-down (if category-up (- category-up) nil))
  5753. (category-keep (if category-up +1 nil))
  5754. (tag-up (and (org-em 'tag-up 'tag-down ss)
  5755. (org-cmp-tag a b)))
  5756. (tag-down (if tag-up (- tag-up) nil))
  5757. (todo-state-up (and (org-em 'todo-state-up 'todo-state-down ss)
  5758. (org-cmp-todo-state a b)))
  5759. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  5760. (habit-up (and (org-em 'habit-up 'habit-down ss)
  5761. (org-cmp-habit-p a b)))
  5762. (habit-down (if habit-up (- habit-up) nil))
  5763. (alpha-up (and (org-em 'alpha-up 'alpha-down ss)
  5764. (org-cmp-alpha a b)))
  5765. (alpha-down (if alpha-up (- alpha-up) nil))
  5766. (need-user-cmp (org-em 'user-defined-up 'user-defined-down ss))
  5767. user-defined-up user-defined-down)
  5768. (if (and need-user-cmp org-agenda-cmp-user-defined
  5769. (functionp org-agenda-cmp-user-defined))
  5770. (setq user-defined-up
  5771. (funcall org-agenda-cmp-user-defined a b)
  5772. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  5773. (cdr (assoc
  5774. (eval (cons 'or org-agenda-sorting-strategy-selected))
  5775. '((-1 . t) (1 . nil) (nil . nil))))))
  5776. ;;; Agenda restriction lock
  5777. (defvar org-agenda-restriction-lock-overlay (make-overlay 1 1)
  5778. "Overlay to mark the headline to which agenda commands are restricted.")
  5779. (overlay-put org-agenda-restriction-lock-overlay
  5780. 'face 'org-agenda-restriction-lock)
  5781. (overlay-put org-agenda-restriction-lock-overlay
  5782. 'help-echo "Agendas are currently limited to this subtree.")
  5783. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5784. (defun org-agenda-set-restriction-lock (&optional type)
  5785. "Set restriction lock for agenda, to current subtree or file.
  5786. Restriction will be the file if TYPE is `file', or if type is the
  5787. universal prefix '(4), or if the cursor is before the first headline
  5788. in the file. Otherwise, restriction will be to the current subtree."
  5789. (interactive "P")
  5790. (and (equal type '(4)) (setq type 'file))
  5791. (setq type (cond
  5792. (type type)
  5793. ((org-at-heading-p) 'subtree)
  5794. ((condition-case nil (org-back-to-heading t) (error nil))
  5795. 'subtree)
  5796. (t 'file)))
  5797. (if (eq type 'subtree)
  5798. (progn
  5799. (setq org-agenda-restrict t)
  5800. (setq org-agenda-overriding-restriction 'subtree)
  5801. (put 'org-agenda-files 'org-restrict
  5802. (list (buffer-file-name (buffer-base-buffer))))
  5803. (org-back-to-heading t)
  5804. (move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  5805. (move-marker org-agenda-restrict-begin (point))
  5806. (move-marker org-agenda-restrict-end
  5807. (save-excursion (org-end-of-subtree t)))
  5808. (message "Locking agenda restriction to subtree"))
  5809. (put 'org-agenda-files 'org-restrict
  5810. (list (buffer-file-name (buffer-base-buffer))))
  5811. (setq org-agenda-restrict nil)
  5812. (setq org-agenda-overriding-restriction 'file)
  5813. (move-marker org-agenda-restrict-begin nil)
  5814. (move-marker org-agenda-restrict-end nil)
  5815. (message "Locking agenda restriction to file"))
  5816. (setq current-prefix-arg nil)
  5817. (org-agenda-maybe-redo))
  5818. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  5819. "Remove the agenda restriction lock."
  5820. (interactive "P")
  5821. (org-detach-overlay org-agenda-restriction-lock-overlay)
  5822. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  5823. (setq org-agenda-overriding-restriction nil)
  5824. (setq org-agenda-restrict nil)
  5825. (put 'org-agenda-files 'org-restrict nil)
  5826. (move-marker org-agenda-restrict-begin nil)
  5827. (move-marker org-agenda-restrict-end nil)
  5828. (setq current-prefix-arg nil)
  5829. (message "Agenda restriction lock removed")
  5830. (or noupdate (org-agenda-maybe-redo)))
  5831. (defun org-agenda-maybe-redo ()
  5832. "If there is any window showing the agenda view, update it."
  5833. (let ((w (get-buffer-window org-agenda-buffer-name t))
  5834. (w0 (selected-window)))
  5835. (when w
  5836. (select-window w)
  5837. (org-agenda-redo)
  5838. (select-window w0)
  5839. (if org-agenda-overriding-restriction
  5840. (message "Agenda view shifted to new %s restriction"
  5841. org-agenda-overriding-restriction)
  5842. (message "Agenda restriction lock removed")))))
  5843. ;;; Agenda commands
  5844. (defun org-agenda-check-type (error &rest types)
  5845. "Check if agenda buffer is of allowed type.
  5846. If ERROR is non-nil, throw an error, otherwise just return nil."
  5847. (if (memq org-agenda-type types)
  5848. t
  5849. (if error
  5850. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  5851. nil)))
  5852. (defun org-agenda-Quit (&optional arg)
  5853. "Exit agenda by removing the window or the buffer"
  5854. (interactive)
  5855. (if org-agenda-columns-active
  5856. (org-columns-quit)
  5857. (let ((buf (current-buffer)))
  5858. (if (eq org-agenda-window-setup 'other-frame)
  5859. (progn
  5860. (org-agenda-reset-markers)
  5861. (kill-buffer buf)
  5862. (org-columns-remove-overlays)
  5863. (setq org-agenda-archives-mode nil)
  5864. (delete-frame))
  5865. (and (not (eq org-agenda-window-setup 'current-window))
  5866. (not (one-window-p))
  5867. (delete-window))
  5868. (org-agenda-reset-markers)
  5869. (kill-buffer buf)
  5870. (org-columns-remove-overlays)
  5871. (setq org-agenda-archives-mode nil)))
  5872. ;; Maybe restore the pre-agenda window configuration.
  5873. (and org-agenda-restore-windows-after-quit
  5874. (not (eq org-agenda-window-setup 'other-frame))
  5875. org-pre-agenda-window-conf
  5876. (set-window-configuration org-pre-agenda-window-conf))))
  5877. (defun org-agenda-quit ()
  5878. "Exit agenda by killing agenda buffer or burying it when
  5879. `org-agenda-sticky' is non-NIL"
  5880. (interactive)
  5881. (if org-agenda-columns-active
  5882. (org-columns-quit)
  5883. (if org-agenda-sticky
  5884. (let ((buf (current-buffer)))
  5885. (if (eq org-agenda-window-setup 'other-frame)
  5886. (progn
  5887. (delete-frame))
  5888. (and (not (eq org-agenda-window-setup 'current-window))
  5889. (not (one-window-p))
  5890. (delete-window)))
  5891. (with-current-buffer buf
  5892. (bury-buffer)))
  5893. (org-agenda-Quit))))
  5894. (defun org-agenda-exit ()
  5895. "Exit agenda by removing the window or the buffer.
  5896. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  5897. Org-mode buffers visited directly by the user will not be touched."
  5898. (interactive)
  5899. (org-release-buffers org-agenda-new-buffers)
  5900. (setq org-agenda-new-buffers nil)
  5901. (org-agenda-Quit))
  5902. (defun org-agenda-kill-all-agenda-buffers ()
  5903. "Kill all buffers in `org-agena-mode'.
  5904. This is used when toggling sticky agendas. You can also explicitly invoke it
  5905. with `C-c a C-k'."
  5906. (interactive)
  5907. (let (blist)
  5908. (dolist (buf (buffer-list))
  5909. (when (with-current-buffer buf (eq major-mode 'org-agenda-mode))
  5910. (push buf blist)))
  5911. (mapc 'kill-buffer blist)))
  5912. (defun org-agenda-execute (arg)
  5913. "Execute another agenda command, keeping same window.
  5914. So this is just a shortcut for \\<global-map>`\\[org-agenda]', available
  5915. in the agenda."
  5916. (interactive "P")
  5917. (let ((org-agenda-window-setup 'current-window))
  5918. (org-agenda arg)))
  5919. (defun org-agenda-redo ()
  5920. "Rebuild Agenda.
  5921. When this is the global TODO list, a prefix argument will be interpreted."
  5922. (interactive)
  5923. (let* ((org-agenda-doing-sticky-redo org-agenda-sticky)
  5924. (org-agenda-sticky nil)
  5925. (org-agenda-buffer-name (or org-agenda-this-buffer-name
  5926. org-agenda-buffer-name))
  5927. (org-agenda-keep-modes t)
  5928. (tag-filter org-agenda-tag-filter)
  5929. (tag-preset (get 'org-agenda-tag-filter :preset-filter))
  5930. (cat-filter org-agenda-category-filter)
  5931. (cat-preset (get 'org-agenda-category-filter :preset-filter))
  5932. (org-agenda-tag-filter-while-redo (or tag-filter tag-preset))
  5933. (cols org-agenda-columns-active)
  5934. (line (org-current-line))
  5935. (window-line (- line (org-current-line (window-start))))
  5936. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  5937. (put 'org-agenda-tag-filter :preset-filter nil)
  5938. (put 'org-agenda-category-filter :preset-filter nil)
  5939. (and cols (org-columns-quit))
  5940. (message "Rebuilding agenda buffer...")
  5941. (org-let lprops '(eval org-agenda-redo-command))
  5942. (setq org-agenda-undo-list nil
  5943. org-agenda-pending-undo-list nil)
  5944. (message "Rebuilding agenda buffer...done")
  5945. (put 'org-agenda-tag-filter :preset-filter tag-preset)
  5946. (put 'org-agenda-category-filter :preset-filter cat-preset)
  5947. (and (or tag-filter tag-preset) (org-agenda-filter-apply tag-filter 'tag))
  5948. (and (or cat-filter cat-preset) (org-agenda-filter-apply cat-filter 'category))
  5949. (and cols (org-called-interactively-p 'any) (org-agenda-columns))
  5950. (org-goto-line line)
  5951. (recenter window-line)))
  5952. (defvar org-global-tags-completion-table nil)
  5953. (defvar org-agenda-filtered-by-category nil)
  5954. (defvar org-agenda-filter-form nil)
  5955. (defun org-agenda-filter-by-category (strip)
  5956. "Keep only those lines in the agenda buffer that have a specific category.
  5957. The category is that of the current line."
  5958. (interactive "P")
  5959. (if org-agenda-filtered-by-category
  5960. (org-agenda-filter-show-all-cat)
  5961. (let ((cat (org-no-properties (get-text-property (point) 'org-category))))
  5962. (if cat (org-agenda-filter-apply
  5963. (list (concat (if strip "-" "+") cat)) 'category)
  5964. (error "No category at point")))))
  5965. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  5966. "Keep only those lines in the agenda buffer that have a specific tag.
  5967. The tag is selected with its fast selection letter, as configured.
  5968. With prefix argument STRIP, remove all lines that do have the tag.
  5969. A lisp caller can specify CHAR. NARROW means that the new tag should be
  5970. used to narrow the search - the interactive user can also press `-' or `+'
  5971. to switch to narrowing."
  5972. (interactive "P")
  5973. (let* ((alist org-tag-alist-for-agenda)
  5974. (tag-chars (mapconcat
  5975. (lambda (x) (if (and (not (symbolp (car x)))
  5976. (cdr x))
  5977. (char-to-string (cdr x))
  5978. ""))
  5979. alist ""))
  5980. (efforts (org-split-string
  5981. (or (cdr (assoc (concat org-effort-property "_ALL")
  5982. org-global-properties))
  5983. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00"
  5984. "")))
  5985. (effort-op org-agenda-filter-effort-default-operator)
  5986. (effort-prompt "")
  5987. (inhibit-read-only t)
  5988. (current org-agenda-tag-filter)
  5989. maybe-refresh a n tag)
  5990. (unless char
  5991. (message
  5992. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  5993. (if narrow "Narrow" "Filter") tag-chars
  5994. (if org-agenda-auto-exclude-function "[RET], " ""))
  5995. (setq char (read-char-exclusive)))
  5996. (when (member char '(?+ ?-))
  5997. ;; Narrowing down
  5998. (cond ((equal char ?-) (setq strip t narrow t))
  5999. ((equal char ?+) (setq strip nil narrow t)))
  6000. (message
  6001. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  6002. (setq char (read-char-exclusive)))
  6003. (when (member char '(?< ?> ?= ??))
  6004. ;; An effort operator
  6005. (setq effort-op (char-to-string char))
  6006. (setq alist nil) ; to make sure it will be interpreted as effort.
  6007. (unless (equal char ??)
  6008. (loop for i from 0 to 9 do
  6009. (setq effort-prompt
  6010. (concat
  6011. effort-prompt " ["
  6012. (if (= i 9) "0" (int-to-string (1+ i)))
  6013. "]" (nth i efforts))))
  6014. (message "Effort%s: %s " effort-op effort-prompt)
  6015. (setq char (read-char-exclusive))
  6016. (when (or (< char ?0) (> char ?9))
  6017. (error "Need 1-9,0 to select effort"))))
  6018. (when (equal char ?\t)
  6019. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  6020. (org-set-local 'org-global-tags-completion-table
  6021. (org-global-tags-completion-table)))
  6022. (let ((completion-ignore-case t))
  6023. (setq tag (org-icompleting-read
  6024. "Tag: " org-global-tags-completion-table))))
  6025. (cond
  6026. ((equal char ?\r)
  6027. (org-agenda-filter-show-all-tag)
  6028. (when org-agenda-auto-exclude-function
  6029. (setq org-agenda-tag-filter '())
  6030. (dolist (tag (org-agenda-get-represented-tags))
  6031. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  6032. (if modifier
  6033. (push modifier org-agenda-tag-filter))))
  6034. (if (not (null org-agenda-tag-filter))
  6035. (org-agenda-filter-apply org-agenda-tag-filter 'tag)))
  6036. (setq maybe-refresh t))
  6037. ((equal char ?/)
  6038. (org-agenda-filter-show-all-tag)
  6039. (when (get 'org-agenda-tag-filter :preset-filter)
  6040. (org-agenda-filter-apply org-agenda-tag-filter 'tag))
  6041. (setq maybe-refresh t))
  6042. ((equal char ?. )
  6043. (setq org-agenda-tag-filter
  6044. (mapcar (lambda(tag) (concat "+" tag))
  6045. (org-get-at-bol 'tags)))
  6046. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6047. (setq maybe-refresh t))
  6048. ((or (equal char ?\ )
  6049. (setq a (rassoc char alist))
  6050. (and (>= char ?0) (<= char ?9)
  6051. (setq n (if (= char ?0) 9 (- char ?0 1))
  6052. tag (concat effort-op (nth n efforts))
  6053. a (cons tag nil)))
  6054. (and (= char ??)
  6055. (setq tag "?eff")
  6056. a (cons tag nil))
  6057. (and tag (setq a (cons tag nil))))
  6058. (org-agenda-filter-show-all-tag)
  6059. (setq tag (car a))
  6060. (setq org-agenda-tag-filter
  6061. (cons (concat (if strip "-" "+") tag)
  6062. (if narrow current nil)))
  6063. (org-agenda-filter-apply org-agenda-tag-filter 'tag)
  6064. (setq maybe-refresh t))
  6065. (t (error "Invalid tag selection character %c" char)))
  6066. (when (and maybe-refresh
  6067. (eq org-agenda-clockreport-mode 'with-filter))
  6068. (org-agenda-redo))))
  6069. (defun org-agenda-get-represented-tags ()
  6070. "Get a list of all tags currently represented in the agenda."
  6071. (let (p tags)
  6072. (save-excursion
  6073. (goto-char (point-min))
  6074. (while (setq p (next-single-property-change (point) 'tags))
  6075. (goto-char p)
  6076. (mapc (lambda (x) (add-to-list 'tags x))
  6077. (get-text-property (point) 'tags))))
  6078. tags))
  6079. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  6080. "Refine the current filter. See `org-agenda-filter-by-tag'."
  6081. (interactive "P")
  6082. (org-agenda-filter-by-tag strip char 'refine))
  6083. (defun org-agenda-filter-make-matcher ()
  6084. "Create the form that tests a line for agenda filter."
  6085. (let (f f1)
  6086. ;; first compute the tag-filter matcher
  6087. (dolist (x (delete-dups
  6088. (append (get 'org-agenda-tag-filter
  6089. :preset-filter) org-agenda-tag-filter)))
  6090. (if (member x '("-" "+"))
  6091. (setq f1 (if (equal x "-") 'tags '(not tags)))
  6092. (if (string-match "[<=>?]" x)
  6093. (setq f1 (org-agenda-filter-effort-form x))
  6094. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  6095. (if (equal (string-to-char x) ?-)
  6096. (setq f1 (list 'not f1))))
  6097. (push f1 f))
  6098. ;; then compute the category-filter matcher
  6099. (dolist (x (delete-dups
  6100. (append (get 'org-agenda-category-filter
  6101. :preset-filter) org-agenda-category-filter)))
  6102. (setq f1 (list 'equal (substring x 1) 'cat))
  6103. (push f1 f))
  6104. (cons 'and (nreverse f))))
  6105. (defun org-agenda-filter-effort-form (e)
  6106. "Return the form to compare the effort of the current line with what E says.
  6107. E looks like \"+<2:25\"."
  6108. (let (op)
  6109. (setq e (substring e 1))
  6110. (setq op (string-to-char e) e (substring e 1))
  6111. (setq op (cond ((equal op ?<) '<=)
  6112. ((equal op ?>) '>=)
  6113. ((equal op ??) op)
  6114. (t '=)))
  6115. (list 'org-agenda-compare-effort (list 'quote op)
  6116. (org-duration-string-to-minutes e))))
  6117. (defun org-agenda-compare-effort (op value)
  6118. "Compare the effort of the current line with VALUE, using OP.
  6119. If the line does not have an effort defined, return nil."
  6120. (let ((eff (org-get-at-bol 'effort-minutes)))
  6121. (if (equal op ??)
  6122. (not eff)
  6123. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  6124. value))))
  6125. (defun org-agenda-filter-apply (filter type)
  6126. "Set FILTER as the new agenda filter and apply it."
  6127. (let (tags cat)
  6128. (if (eq type 'tag)
  6129. (setq org-agenda-tag-filter filter)
  6130. (setq org-agenda-category-filter filter
  6131. org-agenda-filtered-by-category t))
  6132. (setq org-agenda-filter-form (org-agenda-filter-make-matcher))
  6133. (org-agenda-set-mode-name)
  6134. (save-excursion
  6135. (goto-char (point-min))
  6136. (while (not (eobp))
  6137. (if (org-get-at-bol 'org-marker)
  6138. (progn
  6139. (setq tags (org-get-at-bol 'tags) ; used in eval
  6140. cat (get-text-property (point) 'org-category))
  6141. (if (not (eval org-agenda-filter-form))
  6142. (org-agenda-filter-hide-line type))
  6143. (beginning-of-line 2))
  6144. (beginning-of-line 2))))
  6145. (if (get-char-property (point) 'invisible)
  6146. (org-agenda-previous-line))))
  6147. (defun org-agenda-filter-hide-line (type)
  6148. (let (ov)
  6149. (setq ov (make-overlay (max (point-min) (1- (point-at-bol)))
  6150. (point-at-eol)))
  6151. (overlay-put ov 'invisible t)
  6152. (overlay-put ov 'type type)
  6153. (if (eq type 'tag)
  6154. (push ov org-agenda-tag-filter-overlays)
  6155. (push ov org-agenda-cat-filter-overlays))))
  6156. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  6157. (setq pos (or pos (point)))
  6158. (save-excursion
  6159. (dolist (ov (overlays-at pos))
  6160. (when (and (overlay-get ov 'invisible)
  6161. (eq (overlay-get ov 'type) 'tag))
  6162. (goto-char pos)
  6163. (if (< (overlay-start ov) (point-at-eol))
  6164. (move-overlay ov (point-at-eol)
  6165. (overlay-end ov)))))))
  6166. (defun org-agenda-filter-show-all-tag nil
  6167. (mapc 'delete-overlay org-agenda-tag-filter-overlays)
  6168. (setq org-agenda-tag-filter-overlays nil
  6169. org-agenda-tag-filter nil
  6170. org-agenda-filter-form nil)
  6171. (org-agenda-set-mode-name))
  6172. (defun org-agenda-filter-show-all-cat nil
  6173. (mapc 'delete-overlay org-agenda-cat-filter-overlays)
  6174. (setq org-agenda-cat-filter-overlays nil
  6175. org-agenda-filtered-by-category nil
  6176. org-agenda-category-filter nil
  6177. org-agenda-filter-form nil)
  6178. (org-agenda-set-mode-name))
  6179. (defun org-agenda-manipulate-query-add ()
  6180. "Manipulate the query by adding a search term with positive selection.
  6181. Positive selection means the term must be matched for selection of an entry."
  6182. (interactive)
  6183. (org-agenda-manipulate-query ?\[))
  6184. (defun org-agenda-manipulate-query-subtract ()
  6185. "Manipulate the query by adding a search term with negative selection.
  6186. Negative selection means term must not be matched for selection of an entry."
  6187. (interactive)
  6188. (org-agenda-manipulate-query ?\]))
  6189. (defun org-agenda-manipulate-query-add-re ()
  6190. "Manipulate the query by adding a search regexp with positive selection.
  6191. Positive selection means the regexp must match for selection of an entry."
  6192. (interactive)
  6193. (org-agenda-manipulate-query ?\{))
  6194. (defun org-agenda-manipulate-query-subtract-re ()
  6195. "Manipulate the query by adding a search regexp with negative selection.
  6196. Negative selection means regexp must not match for selection of an entry."
  6197. (interactive)
  6198. (org-agenda-manipulate-query ?\}))
  6199. (defun org-agenda-manipulate-query (char)
  6200. (cond
  6201. ((memq org-agenda-type '(timeline agenda))
  6202. (let ((org-agenda-include-inactive-timestamps t))
  6203. (org-agenda-redo))
  6204. (message "Display now includes inactive timestamps as well"))
  6205. ((eq org-agenda-type 'search)
  6206. (org-add-to-string
  6207. 'org-agenda-query-string
  6208. (if org-agenda-last-search-view-search-was-boolean
  6209. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  6210. (?\{ . " +{}") (?\} . " -{}"))))
  6211. " "))
  6212. (setq org-agenda-redo-command
  6213. (list 'org-search-view
  6214. org-todo-only
  6215. org-agenda-query-string
  6216. (+ (length org-agenda-query-string)
  6217. (if (member char '(?\{ ?\})) 0 1))))
  6218. (set-register org-agenda-query-register org-agenda-query-string)
  6219. (org-agenda-redo))
  6220. (t (error "Cannot manipulate query for %s-type agenda buffers"
  6221. org-agenda-type))))
  6222. (defun org-add-to-string (var string)
  6223. (set var (concat (symbol-value var) string)))
  6224. (defun org-agenda-goto-date (date)
  6225. "Jump to DATE in agenda."
  6226. (interactive (list (let ((org-read-date-prefer-future
  6227. (eval org-agenda-jump-prefer-future)))
  6228. (org-read-date))))
  6229. (org-agenda-list nil date))
  6230. (defun org-agenda-goto-today ()
  6231. "Go to today."
  6232. (interactive)
  6233. (org-agenda-check-type t 'timeline 'agenda)
  6234. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  6235. (cond
  6236. (tdpos (goto-char tdpos))
  6237. ((eq org-agenda-type 'agenda)
  6238. (let* ((sd (org-agenda-compute-starting-span
  6239. (org-today) (or org-agenda-current-span org-agenda-ndays org-agenda-span)))
  6240. (org-agenda-overriding-arguments org-agenda-last-arguments))
  6241. (setf (nth 1 org-agenda-overriding-arguments) sd)
  6242. (org-agenda-redo)
  6243. (org-agenda-find-same-or-today-or-agenda)))
  6244. (t (error "Cannot find today")))))
  6245. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  6246. (goto-char
  6247. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  6248. (text-property-any (point-min) (point-max) 'org-today t)
  6249. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  6250. (point-min))))
  6251. (defun org-agenda-later (arg)
  6252. "Go forward in time by thee current span.
  6253. With prefix ARG, go forward that many times the current span."
  6254. (interactive "p")
  6255. (org-agenda-check-type t 'agenda)
  6256. (let* ((span org-agenda-current-span)
  6257. (sd org-starting-day)
  6258. (greg (calendar-gregorian-from-absolute sd))
  6259. (cnt (org-get-at-bol 'org-day-cnt))
  6260. greg2)
  6261. (cond
  6262. ((eq span 'day)
  6263. (setq sd (+ arg sd)))
  6264. ((eq span 'week)
  6265. (setq sd (+ (* 7 arg) sd)))
  6266. ((eq span 'month)
  6267. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  6268. sd (calendar-absolute-from-gregorian greg2))
  6269. (setcar greg2 (1+ (car greg2))))
  6270. ((eq span 'year)
  6271. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  6272. sd (calendar-absolute-from-gregorian greg2))
  6273. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
  6274. (t
  6275. (setq sd (+ (* span arg) sd))))
  6276. (let ((org-agenda-overriding-arguments
  6277. (list (car org-agenda-last-arguments) sd span t)))
  6278. (org-agenda-redo)
  6279. (org-agenda-find-same-or-today-or-agenda cnt))))
  6280. (defun org-agenda-earlier (arg)
  6281. "Go backward in time by the current span.
  6282. With prefix ARG, go backward that many times the current span."
  6283. (interactive "p")
  6284. (org-agenda-later (- arg)))
  6285. (defun org-agenda-view-mode-dispatch ()
  6286. "Call one of the view mode commands."
  6287. (interactive)
  6288. (message "View: [d]ay [w]eek [m]onth [y]ear [SPC]reset [q]uit/abort
  6289. time[G]rid [[]inactive [f]ollow [l]og [L]og-all [c]lockcheck
  6290. [a]rch-trees [A]rch-files clock[R]eport include[D]iary
  6291. [E]ntryText")
  6292. (let ((a (read-char-exclusive)))
  6293. (case a
  6294. (?\ (call-interactively 'org-agenda-reset-view))
  6295. (?d (call-interactively 'org-agenda-day-view))
  6296. (?w (call-interactively 'org-agenda-week-view))
  6297. (?m (call-interactively 'org-agenda-month-view))
  6298. (?y (call-interactively 'org-agenda-year-view))
  6299. (?l (call-interactively 'org-agenda-log-mode))
  6300. (?L (org-agenda-log-mode '(4)))
  6301. (?c (org-agenda-log-mode 'clockcheck))
  6302. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  6303. (?a (call-interactively 'org-agenda-archives-mode))
  6304. (?A (org-agenda-archives-mode 'files))
  6305. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  6306. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  6307. (?G (call-interactively 'org-agenda-toggle-time-grid))
  6308. (?D (call-interactively 'org-agenda-toggle-diary))
  6309. (?\! (call-interactively 'org-agenda-toggle-deadlines))
  6310. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  6311. (org-agenda-check-type t 'timeline 'agenda)
  6312. (org-agenda-redo))
  6313. (message "Display now includes inactive timestamps as well"))
  6314. (?q (message "Abort"))
  6315. (otherwise (error "Invalid key" )))))
  6316. (defun org-agenda-reset-view ()
  6317. "Switch to default view for agenda."
  6318. (interactive)
  6319. (org-agenda-change-time-span (or org-agenda-ndays org-agenda-span)))
  6320. (defun org-agenda-day-view (&optional day-of-year)
  6321. "Switch to daily view for agenda.
  6322. With argument DAY-OF-YEAR, switch to that day of the year."
  6323. (interactive "P")
  6324. (org-agenda-change-time-span 'day day-of-year))
  6325. (defun org-agenda-week-view (&optional iso-week)
  6326. "Switch to daily view for agenda.
  6327. With argument ISO-WEEK, switch to the corresponding ISO week.
  6328. If ISO-WEEK has more then 2 digits, only the last two encode the
  6329. week. Any digits before this encode a year. So 200712 means
  6330. week 12 of year 2007. Years in the range 1938-2037 can also be
  6331. written as 2-digit years."
  6332. (interactive "P")
  6333. (org-agenda-change-time-span 'week iso-week))
  6334. (defun org-agenda-month-view (&optional month)
  6335. "Switch to monthly view for agenda.
  6336. With argument MONTH, switch to that month."
  6337. (interactive "P")
  6338. (org-agenda-change-time-span 'month month))
  6339. (defun org-agenda-year-view (&optional year)
  6340. "Switch to yearly view for agenda.
  6341. With argument YEAR, switch to that year.
  6342. If MONTH has more then 2 digits, only the last two encode the
  6343. month. Any digits before this encode a year. So 200712 means
  6344. December year 2007. Years in the range 1938-2037 can also be
  6345. written as 2-digit years."
  6346. (interactive "P")
  6347. (when year
  6348. (setq year (org-small-year-to-year year)))
  6349. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  6350. (org-agenda-change-time-span 'year year)
  6351. (error "Abort")))
  6352. (defun org-agenda-change-time-span (span &optional n)
  6353. "Change the agenda view to SPAN.
  6354. SPAN may be `day', `week', `month', `year'."
  6355. (org-agenda-check-type t 'agenda)
  6356. (if (and (not n) (equal org-agenda-current-span span))
  6357. (error "Viewing span is already \"%s\"" span))
  6358. (let* ((sd (or (org-get-at-bol 'day)
  6359. org-starting-day))
  6360. (sd (org-agenda-compute-starting-span sd span n))
  6361. (org-agenda-overriding-arguments
  6362. (or org-agenda-overriding-arguments
  6363. (list (car org-agenda-last-arguments) sd span t))))
  6364. (org-agenda-redo)
  6365. (org-agenda-find-same-or-today-or-agenda))
  6366. (org-agenda-set-mode-name)
  6367. (message "Switched to %s view" span))
  6368. (defun org-agenda-compute-starting-span (sd span &optional n)
  6369. "Compute starting date for agenda.
  6370. SPAN may be `day', `week', `month', `year'. The return value
  6371. is a cons cell with the starting date and the number of days,
  6372. so that the date SD will be in that range."
  6373. (let* ((greg (calendar-gregorian-from-absolute sd))
  6374. (dg (nth 1 greg))
  6375. (mg (car greg))
  6376. (yg (nth 2 greg)))
  6377. (cond
  6378. ((eq span 'day)
  6379. (when n
  6380. (setq sd (+ (calendar-absolute-from-gregorian
  6381. (list mg 1 yg))
  6382. n -1))))
  6383. ((eq span 'week)
  6384. (let* ((nt (calendar-day-of-week
  6385. (calendar-gregorian-from-absolute sd)))
  6386. (d (if org-agenda-start-on-weekday
  6387. (- nt org-agenda-start-on-weekday)
  6388. 0))
  6389. y1)
  6390. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  6391. (when n
  6392. (require 'cal-iso)
  6393. (when (> n 99)
  6394. (setq y1 (org-small-year-to-year (/ n 100))
  6395. n (mod n 100)))
  6396. (setq sd
  6397. (calendar-absolute-from-iso
  6398. (list n 1
  6399. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
  6400. ((eq span 'month)
  6401. (let (y1)
  6402. (when (and n (> n 99))
  6403. (setq y1 (org-small-year-to-year (/ n 100))
  6404. n (mod n 100)))
  6405. (setq sd (calendar-absolute-from-gregorian
  6406. (list (or n mg) 1 (or y1 yg))))))
  6407. ((eq span 'year)
  6408. (setq sd (calendar-absolute-from-gregorian
  6409. (list 1 1 (or n yg))))))
  6410. sd))
  6411. (defun org-agenda-next-date-line (&optional arg)
  6412. "Jump to the next line indicating a date in agenda buffer."
  6413. (interactive "p")
  6414. (org-agenda-check-type t 'agenda 'timeline)
  6415. (beginning-of-line 1)
  6416. ;; This does not work if user makes date format that starts with a blank
  6417. (if (looking-at "^\\S-") (forward-char 1))
  6418. (if (not (re-search-forward "^\\S-" nil t arg))
  6419. (progn
  6420. (backward-char 1)
  6421. (error "No next date after this line in this buffer")))
  6422. (goto-char (match-beginning 0)))
  6423. (defun org-agenda-previous-date-line (&optional arg)
  6424. "Jump to the previous line indicating a date in agenda buffer."
  6425. (interactive "p")
  6426. (org-agenda-check-type t 'agenda 'timeline)
  6427. (beginning-of-line 1)
  6428. (if (not (re-search-backward "^\\S-" nil t arg))
  6429. (error "No previous date before this line in this buffer")))
  6430. ;; Initialize the highlight
  6431. (defvar org-hl (make-overlay 1 1))
  6432. (overlay-put org-hl 'face 'highlight)
  6433. (defun org-highlight (begin end &optional buffer)
  6434. "Highlight a region with overlay."
  6435. (move-overlay org-hl begin end (or buffer (current-buffer))))
  6436. (defun org-unhighlight ()
  6437. "Detach overlay INDEX."
  6438. (org-detach-overlay org-hl))
  6439. ;; FIXME this is currently not used.
  6440. (defun org-highlight-until-next-command (beg end &optional buffer)
  6441. "Move the highlight overlay to BEG/END, remove it before the next command."
  6442. (org-highlight beg end buffer)
  6443. (add-hook 'pre-command-hook 'org-unhighlight-once))
  6444. (defun org-unhighlight-once ()
  6445. "Remove the highlight from its position, and this function from the hook."
  6446. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  6447. (org-unhighlight))
  6448. (defun org-agenda-follow-mode ()
  6449. "Toggle follow mode in an agenda buffer."
  6450. (interactive)
  6451. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  6452. (org-agenda-set-mode-name)
  6453. (org-agenda-do-context-action)
  6454. (message "Follow mode is %s"
  6455. (if org-agenda-follow-mode "on" "off")))
  6456. (defun org-agenda-entry-text-mode (&optional arg)
  6457. "Toggle entry text mode in an agenda buffer."
  6458. (interactive "P")
  6459. (setq org-agenda-entry-text-mode (or (integerp arg)
  6460. (not org-agenda-entry-text-mode)))
  6461. (org-agenda-entry-text-hide)
  6462. (and org-agenda-entry-text-mode
  6463. (let ((org-agenda-entry-text-maxlines
  6464. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6465. (org-agenda-entry-text-show)))
  6466. (org-agenda-set-mode-name)
  6467. (message "Entry text mode is %s. Maximum number of lines is %d"
  6468. (if org-agenda-entry-text-mode "on" "off")
  6469. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  6470. (defun org-agenda-clockreport-mode (&optional with-filter)
  6471. "Toggle clocktable mode in an agenda buffer.
  6472. With prefix arg WITH-FILTER, make the clocktable respect the current
  6473. agenda filter."
  6474. (interactive "P")
  6475. (org-agenda-check-type t 'agenda)
  6476. (if with-filter
  6477. (setq org-agenda-clockreport-mode 'with-filter)
  6478. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode)))
  6479. (org-agenda-set-mode-name)
  6480. (org-agenda-redo)
  6481. (message "Clocktable mode is %s"
  6482. (if org-agenda-clockreport-mode "on" "off")))
  6483. (defun org-agenda-log-mode (&optional special)
  6484. "Toggle log mode in an agenda buffer.
  6485. With argument SPECIAL, show all possible log items, not only the ones
  6486. configured in `org-agenda-log-mode-items'.
  6487. With a double `C-u' prefix arg, show *only* log items, nothing else."
  6488. (interactive "P")
  6489. (org-agenda-check-type t 'agenda 'timeline)
  6490. (setq org-agenda-show-log
  6491. (cond
  6492. ((equal special '(16)) 'only)
  6493. ((eq special 'clockcheck)
  6494. (if (eq org-agenda-show-log 'clockcheck)
  6495. nil 'clockcheck))
  6496. (special '(closed clock state))
  6497. (t (not org-agenda-show-log))))
  6498. (org-agenda-set-mode-name)
  6499. (org-agenda-redo)
  6500. (message "Log mode is %s"
  6501. (if org-agenda-show-log "on" "off")))
  6502. (defun org-agenda-archives-mode (&optional with-files)
  6503. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  6504. When called with a prefix argument, include all archive files as well."
  6505. (interactive "P")
  6506. (setq org-agenda-archives-mode
  6507. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  6508. (org-agenda-set-mode-name)
  6509. (org-agenda-redo)
  6510. (message
  6511. "%s"
  6512. (cond
  6513. ((eq org-agenda-archives-mode nil)
  6514. "No archives are included")
  6515. ((eq org-agenda-archives-mode 'trees)
  6516. (format "Trees with :%s: tag are included" org-archive-tag))
  6517. ((eq org-agenda-archives-mode t)
  6518. (format "Trees with :%s: tag and all active archive files are included"
  6519. org-archive-tag)))))
  6520. (defun org-agenda-toggle-diary ()
  6521. "Toggle diary inclusion in an agenda buffer."
  6522. (interactive)
  6523. (org-agenda-check-type t 'agenda)
  6524. (setq org-agenda-include-diary (not org-agenda-include-diary))
  6525. (org-agenda-redo)
  6526. (org-agenda-set-mode-name)
  6527. (message "Diary inclusion turned %s"
  6528. (if org-agenda-include-diary "on" "off")))
  6529. (defun org-agenda-toggle-deadlines ()
  6530. "Toggle inclusion of entries with a deadline in an agenda buffer."
  6531. (interactive)
  6532. (org-agenda-check-type t 'agenda)
  6533. (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
  6534. (org-agenda-redo)
  6535. (org-agenda-set-mode-name)
  6536. (message "Deadlines inclusion turned %s"
  6537. (if org-agenda-include-deadlines "on" "off")))
  6538. (defun org-agenda-toggle-time-grid ()
  6539. "Toggle time grid in an agenda buffer."
  6540. (interactive)
  6541. (org-agenda-check-type t 'agenda)
  6542. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  6543. (org-agenda-redo)
  6544. (org-agenda-set-mode-name)
  6545. (message "Time-grid turned %s"
  6546. (if org-agenda-use-time-grid "on" "off")))
  6547. (defun org-agenda-set-mode-name ()
  6548. "Set the mode name to indicate all the small mode settings."
  6549. (setq mode-name
  6550. (list "Org-Agenda"
  6551. (if (get 'org-agenda-files 'org-restrict) " []" "")
  6552. " "
  6553. '(:eval (org-agenda-span-name org-agenda-current-span))
  6554. (if org-agenda-follow-mode " Follow" "")
  6555. (if org-agenda-entry-text-mode " ETxt" "")
  6556. (if org-agenda-include-diary " Diary" "")
  6557. (if org-agenda-include-deadlines " Ddl" "")
  6558. (if org-agenda-use-time-grid " Grid" "")
  6559. (if (and (boundp 'org-habit-show-habits)
  6560. org-habit-show-habits) " Habit" "")
  6561. (cond
  6562. ((consp org-agenda-show-log) " LogAll")
  6563. ((eq org-agenda-show-log 'clockcheck) " ClkCk")
  6564. (org-agenda-show-log " Log")
  6565. (t ""))
  6566. (if (or org-agenda-category-filter (get 'org-agenda-category-filter
  6567. :preset-filter))
  6568. '(:eval (org-propertize
  6569. (concat " <"
  6570. (mapconcat
  6571. 'identity
  6572. (append
  6573. (get 'org-agenda-category-filter :preset-filter)
  6574. org-agenda-category-filter)
  6575. "")
  6576. ">")
  6577. 'face 'org-agenda-filter-category
  6578. 'help-echo "Category used in filtering"))
  6579. "")
  6580. (if (or org-agenda-tag-filter (get 'org-agenda-tag-filter
  6581. :preset-filter))
  6582. '(:eval (org-propertize
  6583. (concat " {"
  6584. (mapconcat
  6585. 'identity
  6586. (append
  6587. (get 'org-agenda-tag-filter :preset-filter)
  6588. org-agenda-tag-filter)
  6589. "")
  6590. "}")
  6591. 'face 'org-agenda-filter-tags
  6592. 'help-echo "Tags used in filtering"))
  6593. "")
  6594. (if org-agenda-archives-mode
  6595. (if (eq org-agenda-archives-mode t)
  6596. " Archives"
  6597. (format " :%s:" org-archive-tag))
  6598. "")
  6599. (if org-agenda-clockreport-mode
  6600. (if (eq org-agenda-clockreport-mode 'with-filter)
  6601. " Clock{}" " Clock")
  6602. "")))
  6603. (force-mode-line-update))
  6604. (defun org-agenda-post-command-hook ()
  6605. (setq org-agenda-type
  6606. (or (get-text-property (point) 'org-agenda-type)
  6607. (get-text-property (max (point-min) (1- (point)))
  6608. 'org-agenda-type))))
  6609. (defun org-agenda-next-line ()
  6610. "Move cursor to the next line, and show if follow mode is active."
  6611. (interactive)
  6612. (call-interactively 'next-line)
  6613. (org-agenda-do-context-action))
  6614. (defun org-agenda-previous-line ()
  6615. "Move cursor to the previous line, and show if follow-mode is active."
  6616. (interactive)
  6617. (call-interactively 'previous-line)
  6618. (org-agenda-do-context-action))
  6619. (defun org-agenda-do-context-action ()
  6620. "Show outline path and, maybe, follow mode window."
  6621. (let ((m (org-get-at-bol 'org-marker)))
  6622. (when (and (markerp m) (marker-buffer m))
  6623. (and org-agenda-follow-mode
  6624. (if org-agenda-follow-indirect
  6625. (org-agenda-tree-to-indirect-buffer)
  6626. (org-agenda-show)))
  6627. (and org-agenda-show-outline-path
  6628. (org-with-point-at m (org-display-outline-path t))))))
  6629. (defun org-agenda-show-priority ()
  6630. "Show the priority of the current item.
  6631. This priority is composed of the main priority given with the [#A] cookies,
  6632. and by additional input from the age of a schedules or deadline entry."
  6633. (interactive)
  6634. (let* ((pri (org-get-at-bol 'priority)))
  6635. (message "Priority is %d" (if pri pri -1000))))
  6636. (defun org-agenda-show-tags ()
  6637. "Show the tags applicable to the current item."
  6638. (interactive)
  6639. (let* ((tags (org-get-at-bol 'tags)))
  6640. (if tags
  6641. (message "Tags are :%s:"
  6642. (org-no-properties (mapconcat 'identity tags ":")))
  6643. (message "No tags associated with this line"))))
  6644. (defun org-agenda-goto (&optional highlight)
  6645. "Go to the Org-mode file which contains the item at point."
  6646. (interactive)
  6647. (let* ((marker (or (org-get-at-bol 'org-marker)
  6648. (org-agenda-error)))
  6649. (buffer (marker-buffer marker))
  6650. (pos (marker-position marker)))
  6651. (switch-to-buffer-other-window buffer)
  6652. (widen)
  6653. (push-mark)
  6654. (goto-char pos)
  6655. (when (eq major-mode 'org-mode)
  6656. (org-show-context 'agenda)
  6657. (save-excursion
  6658. (and (outline-next-heading)
  6659. (org-flag-heading nil)))) ; show the next heading
  6660. (when (outline-invisible-p)
  6661. (show-entry)) ; display invisible text
  6662. (recenter (/ (window-height) 2))
  6663. (run-hooks 'org-agenda-after-show-hook)
  6664. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  6665. (defvar org-agenda-after-show-hook nil
  6666. "Normal hook run after an item has been shown from the agenda.
  6667. Point is in the buffer where the item originated.")
  6668. (defun org-agenda-kill ()
  6669. "Kill the entry or subtree belonging to the current agenda entry."
  6670. (interactive)
  6671. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6672. (let* ((marker (or (org-get-at-bol 'org-marker)
  6673. (org-agenda-error)))
  6674. (buffer (marker-buffer marker))
  6675. (pos (marker-position marker))
  6676. (type (org-get-at-bol 'type))
  6677. dbeg dend (n 0) conf)
  6678. (org-with-remote-undo buffer
  6679. (with-current-buffer buffer
  6680. (save-excursion
  6681. (goto-char pos)
  6682. (if (and (eq major-mode 'org-mode) (not (member type '("sexp"))))
  6683. (setq dbeg (progn (org-back-to-heading t) (point))
  6684. dend (org-end-of-subtree t t))
  6685. (setq dbeg (point-at-bol)
  6686. dend (min (point-max) (1+ (point-at-eol)))))
  6687. (goto-char dbeg)
  6688. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  6689. (setq conf (or (eq t org-agenda-confirm-kill)
  6690. (and (numberp org-agenda-confirm-kill)
  6691. (> n org-agenda-confirm-kill))))
  6692. (and conf
  6693. (not (y-or-n-p
  6694. (format "Delete entry with %d lines in buffer \"%s\"? "
  6695. n (buffer-name buffer))))
  6696. (error "Abort"))
  6697. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  6698. (with-current-buffer buffer (delete-region dbeg dend))
  6699. (message "Agenda item and source killed"))))
  6700. (defvar org-archive-default-command)
  6701. (defun org-agenda-archive-default ()
  6702. "Archive the entry or subtree belonging to the current agenda entry."
  6703. (interactive)
  6704. (require 'org-archive)
  6705. (org-agenda-archive-with org-archive-default-command))
  6706. (defun org-agenda-archive-default-with-confirmation ()
  6707. "Archive the entry or subtree belonging to the current agenda entry."
  6708. (interactive)
  6709. (require 'org-archive)
  6710. (org-agenda-archive-with org-archive-default-command 'confirm))
  6711. (defun org-agenda-archive ()
  6712. "Archive the entry or subtree belonging to the current agenda entry."
  6713. (interactive)
  6714. (org-agenda-archive-with 'org-archive-subtree))
  6715. (defun org-agenda-archive-to-archive-sibling ()
  6716. "Move the entry to the archive sibling."
  6717. (interactive)
  6718. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  6719. (defun org-agenda-archive-with (cmd &optional confirm)
  6720. "Move the entry to the archive sibling."
  6721. (interactive)
  6722. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  6723. (let* ((marker (or (org-get-at-bol 'org-marker)
  6724. (org-agenda-error)))
  6725. (buffer (marker-buffer marker))
  6726. (pos (marker-position marker)))
  6727. (org-with-remote-undo buffer
  6728. (with-current-buffer buffer
  6729. (if (eq major-mode 'org-mode)
  6730. (if (and confirm
  6731. (not (y-or-n-p "Archive this subtree or entry? ")))
  6732. (error "Abort")
  6733. (save-excursion
  6734. (goto-char pos)
  6735. (org-remove-subtree-entries-from-agenda)
  6736. (org-back-to-heading t)
  6737. (funcall cmd)))
  6738. (error "Archiving works only in Org-mode files"))))))
  6739. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  6740. "Remove all lines in the agenda that correspond to a given subtree.
  6741. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  6742. If this information is not given, the function uses the tree at point."
  6743. (let ((buf (or buf (current-buffer))) m p)
  6744. (save-excursion
  6745. (unless (and beg end)
  6746. (org-back-to-heading t)
  6747. (setq beg (point))
  6748. (org-end-of-subtree t)
  6749. (setq end (point)))
  6750. (set-buffer (get-buffer org-agenda-buffer-name))
  6751. (save-excursion
  6752. (goto-char (point-max))
  6753. (beginning-of-line 1)
  6754. (while (not (bobp))
  6755. (when (and (setq m (org-get-at-bol 'org-marker))
  6756. (equal buf (marker-buffer m))
  6757. (setq p (marker-position m))
  6758. (>= p beg)
  6759. (< p end))
  6760. (let ((inhibit-read-only t))
  6761. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  6762. (beginning-of-line 0))))))
  6763. (defun org-agenda-refile (&optional goto rfloc no-update)
  6764. "Refile the item at point."
  6765. (interactive "P")
  6766. (if (equal goto '(16))
  6767. (org-refile-goto-last-stored)
  6768. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6769. (org-agenda-error)))
  6770. (buffer (marker-buffer marker))
  6771. (pos (marker-position marker))
  6772. (rfloc (or rfloc
  6773. (org-refile-get-location
  6774. (if goto "Goto" "Refile to") buffer
  6775. org-refile-allow-creating-parent-nodes))))
  6776. (with-current-buffer buffer
  6777. (save-excursion
  6778. (save-restriction
  6779. (widen)
  6780. (goto-char marker)
  6781. (org-remove-subtree-entries-from-agenda)
  6782. (org-refile goto buffer rfloc)))))
  6783. (unless no-update (org-agenda-redo))))
  6784. (defun org-agenda-open-link (&optional arg)
  6785. "Follow the link in the current line, if any.
  6786. This looks for a link in the displayed line in the agenda. It also looks
  6787. at the text of the entry itself."
  6788. (interactive "P")
  6789. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  6790. (org-get-at-bol 'org-marker)))
  6791. (buffer (and marker (marker-buffer marker)))
  6792. (prefix (buffer-substring
  6793. (point-at-bol) (point-at-eol))))
  6794. (cond
  6795. (buffer
  6796. (with-current-buffer buffer
  6797. (save-excursion
  6798. (save-restriction
  6799. (widen)
  6800. (goto-char marker)
  6801. (org-offer-links-in-entry arg prefix)))))
  6802. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  6803. (save-excursion
  6804. (beginning-of-line 1)
  6805. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  6806. (org-open-link-from-string (match-string 1)))
  6807. (t (error "No link to open here")))))
  6808. (defun org-agenda-copy-local-variable (var)
  6809. "Get a variable from a referenced buffer and install it here."
  6810. (let ((m (org-get-at-bol 'org-marker)))
  6811. (when (and m (buffer-live-p (marker-buffer m)))
  6812. (org-set-local var (with-current-buffer (marker-buffer m)
  6813. (symbol-value var))))))
  6814. (defun org-agenda-switch-to (&optional delete-other-windows)
  6815. "Go to the Org-mode file which contains the item at point."
  6816. (interactive)
  6817. (if (and org-return-follows-link
  6818. (not (org-get-at-bol 'org-marker))
  6819. (org-in-regexp org-bracket-link-regexp))
  6820. (org-open-link-from-string (match-string 0))
  6821. (let* ((marker (or (org-get-at-bol 'org-marker)
  6822. (org-agenda-error)))
  6823. (buffer (marker-buffer marker))
  6824. (pos (marker-position marker)))
  6825. (org-pop-to-buffer-same-window buffer)
  6826. (and delete-other-windows (delete-other-windows))
  6827. (widen)
  6828. (goto-char pos)
  6829. (when (eq major-mode 'org-mode)
  6830. (org-show-context 'agenda)
  6831. (save-excursion
  6832. (and (outline-next-heading)
  6833. (org-flag-heading nil))) ; show the next heading
  6834. (when (outline-invisible-p)
  6835. (show-entry)))))) ; display invisible text
  6836. (defun org-agenda-goto-mouse (ev)
  6837. "Go to the Org-mode file which contains the item at the mouse click."
  6838. (interactive "e")
  6839. (mouse-set-point ev)
  6840. (org-agenda-goto))
  6841. (defun org-agenda-show (&optional full-entry)
  6842. "Display the Org-mode file which contains the item at point.
  6843. With prefix argument FULL-ENTRY, make the entire entry visible
  6844. if it was hidden in the outline."
  6845. (interactive "P")
  6846. (let ((win (selected-window)))
  6847. (if full-entry
  6848. (let ((org-show-entry-below t))
  6849. (org-agenda-goto t))
  6850. (org-agenda-goto t))
  6851. (select-window win)))
  6852. (defvar org-agenda-show-window nil)
  6853. (defun org-agenda-show-and-scroll-up (&optional arg)
  6854. "Display the Org-mode file which contains the item at point.
  6855. When called repeatedly, scroll the window that is displaying the buffer.
  6856. With a \\[universal-argument] prefix, use `org-show-entry' instead of
  6857. `show-subtree' to display the item, so that drawers and logbooks stay
  6858. folded."
  6859. (interactive "P")
  6860. (let ((win (selected-window)))
  6861. (if (and (window-live-p org-agenda-show-window)
  6862. (eq this-command last-command))
  6863. (progn
  6864. (select-window org-agenda-show-window)
  6865. (ignore-errors (scroll-up)))
  6866. (org-agenda-goto t)
  6867. (if arg (org-show-entry) (show-subtree))
  6868. (setq org-agenda-show-window (selected-window)))
  6869. (select-window win)))
  6870. (defun org-agenda-show-scroll-down ()
  6871. "Scroll down the window showing the agenda."
  6872. (interactive)
  6873. (let ((win (selected-window)))
  6874. (when (window-live-p org-agenda-show-window)
  6875. (select-window org-agenda-show-window)
  6876. (ignore-errors (scroll-down))
  6877. (select-window win))))
  6878. (defun org-agenda-show-1 (&optional more)
  6879. "Display the Org-mode file which contains the item at point.
  6880. The prefix arg selects the amount of information to display:
  6881. 0 hide the subtree
  6882. 1 just show the entry according to defaults.
  6883. 2 show the children view
  6884. 3 show the subtree view
  6885. 4 show the entire subtree and any LOGBOOK drawers
  6886. 5 show the entire subtree and any drawers
  6887. With prefix argument FULL-ENTRY, make the entire entry visible
  6888. if it was hidden in the outline."
  6889. (interactive "p")
  6890. (let ((win (selected-window)))
  6891. (org-agenda-goto t)
  6892. (org-recenter-heading 1)
  6893. (cond
  6894. ((= more 0)
  6895. (hide-subtree)
  6896. (save-excursion
  6897. (org-back-to-heading)
  6898. (run-hook-with-args 'org-cycle-hook 'folded))
  6899. (message "Remote: FOLDED"))
  6900. ((and (org-called-interactively-p 'any) (= more 1))
  6901. (message "Remote: show with default settings"))
  6902. ((= more 2)
  6903. (show-entry)
  6904. (show-children)
  6905. (save-excursion
  6906. (org-back-to-heading)
  6907. (run-hook-with-args 'org-cycle-hook 'children))
  6908. (message "Remote: CHILDREN"))
  6909. ((= more 3)
  6910. (show-subtree)
  6911. (save-excursion
  6912. (org-back-to-heading)
  6913. (run-hook-with-args 'org-cycle-hook 'subtree))
  6914. (message "Remote: SUBTREE"))
  6915. ((= more 4)
  6916. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  6917. (org-drawer-regexp
  6918. (concat "^[ \t]*:\\("
  6919. (mapconcat 'regexp-quote org-drawers "\\|")
  6920. "\\):[ \t]*$")))
  6921. (show-subtree)
  6922. (save-excursion
  6923. (org-back-to-heading)
  6924. (org-cycle-hide-drawers 'subtree)))
  6925. (message "Remote: SUBTREE AND LOGBOOK"))
  6926. ((> more 4)
  6927. (show-subtree)
  6928. (message "Remote: SUBTREE AND ALL DRAWERS")))
  6929. (select-window win)))
  6930. (defun org-recenter-heading (n)
  6931. (save-excursion
  6932. (org-back-to-heading)
  6933. (recenter n)))
  6934. (defvar org-agenda-cycle-counter nil)
  6935. (defun org-agenda-cycle-show (&optional n)
  6936. "Show the current entry in another window, with default settings.
  6937. Default settings are taken from `org-show-hierarchy-above' and siblings.
  6938. When use repeatedly in immediate succession, the remote entry will cycle
  6939. through visibility
  6940. children -> subtree -> folded
  6941. When called with a numeric prefix arg, that arg will be passed through to
  6942. `org-agenda-show-1'. For the interpretation of that argument, see the
  6943. docstring of `org-agenda-show-1'."
  6944. (interactive "P")
  6945. (if (integerp n)
  6946. (setq org-agenda-cycle-counter n)
  6947. (if (not (eq last-command this-command))
  6948. (setq org-agenda-cycle-counter 1)
  6949. (if (equal org-agenda-cycle-counter 0)
  6950. (setq org-agenda-cycle-counter 2)
  6951. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  6952. (if (> org-agenda-cycle-counter 3)
  6953. (setq org-agenda-cycle-counter 0)))))
  6954. (org-agenda-show-1 org-agenda-cycle-counter))
  6955. (defun org-agenda-recenter (arg)
  6956. "Display the Org-mode file which contains the item at point and recenter."
  6957. (interactive "P")
  6958. (let ((win (selected-window)))
  6959. (org-agenda-goto t)
  6960. (recenter arg)
  6961. (select-window win)))
  6962. (defun org-agenda-show-mouse (ev)
  6963. "Display the Org-mode file which contains the item at the mouse click."
  6964. (interactive "e")
  6965. (mouse-set-point ev)
  6966. (org-agenda-show))
  6967. (defun org-agenda-check-no-diary ()
  6968. "Check if the entry is a diary link and abort if yes."
  6969. (if (org-get-at-bol 'org-agenda-diary-link)
  6970. (org-agenda-error)))
  6971. (defun org-agenda-error ()
  6972. (error "Command not allowed in this line"))
  6973. (defun org-agenda-tree-to-indirect-buffer ()
  6974. "Show the subtree corresponding to the current entry in an indirect buffer.
  6975. This calls the command `org-tree-to-indirect-buffer' from the original
  6976. Org-mode buffer.
  6977. With numerical prefix arg ARG, go up to this level and then take that tree.
  6978. With a \\[universal-argument] prefix, make a separate frame for this tree (i.e. don't
  6979. use the dedicated frame)."
  6980. (interactive)
  6981. (if (and current-prefix-arg (listp current-prefix-arg))
  6982. (org-agenda-do-tree-to-indirect-buffer)
  6983. (let ((agenda-window (selected-window))
  6984. (indirect-window (and org-last-indirect-buffer (get-buffer-window org-last-indirect-buffer))))
  6985. (save-window-excursion (org-agenda-do-tree-to-indirect-buffer))
  6986. (unwind-protect
  6987. (progn
  6988. (unless (and indirect-window (window-live-p indirect-window))
  6989. (setq indirect-window (split-window agenda-window)))
  6990. (select-window indirect-window)
  6991. (switch-to-buffer org-last-indirect-buffer :norecord)
  6992. (fit-window-to-buffer indirect-window))
  6993. (select-window agenda-window)))))
  6994. (defun org-agenda-do-tree-to-indirect-buffer ()
  6995. "Same as `org-agenda-tree-to-indirect-buffer' without saving window."
  6996. (org-agenda-check-no-diary)
  6997. (let* ((marker (or (org-get-at-bol 'org-marker)
  6998. (org-agenda-error)))
  6999. (buffer (marker-buffer marker))
  7000. (pos (marker-position marker)))
  7001. (with-current-buffer buffer
  7002. (save-excursion
  7003. (goto-char pos)
  7004. (call-interactively 'org-tree-to-indirect-buffer)))))
  7005. (defvar org-last-heading-marker (make-marker)
  7006. "Marker pointing to the headline that last changed its TODO state
  7007. by a remote command from the agenda.")
  7008. (defun org-agenda-todo-nextset ()
  7009. "Switch TODO entry to next sequence."
  7010. (interactive)
  7011. (org-agenda-todo 'nextset))
  7012. (defun org-agenda-todo-previousset ()
  7013. "Switch TODO entry to previous sequence."
  7014. (interactive)
  7015. (org-agenda-todo 'previousset))
  7016. (defun org-agenda-todo (&optional arg)
  7017. "Cycle TODO state of line at point, also in Org-mode file.
  7018. This changes the line at point, all other lines in the agenda referring to
  7019. the same tree node, and the headline of the tree node in the Org-mode file."
  7020. (interactive "P")
  7021. (org-agenda-check-no-diary)
  7022. (let* ((col (current-column))
  7023. (marker (or (org-get-at-bol 'org-marker)
  7024. (org-agenda-error)))
  7025. (buffer (marker-buffer marker))
  7026. (pos (marker-position marker))
  7027. (hdmarker (org-get-at-bol 'org-hd-marker))
  7028. (todayp (org-agenda-todayp (org-get-at-bol 'day)))
  7029. (inhibit-read-only t)
  7030. org-agenda-headline-snapshot-before-repeat newhead just-one)
  7031. (org-with-remote-undo buffer
  7032. (with-current-buffer buffer
  7033. (widen)
  7034. (goto-char pos)
  7035. (org-show-context 'agenda)
  7036. (save-excursion
  7037. (and (outline-next-heading)
  7038. (org-flag-heading nil))) ; show the next heading
  7039. (let ((current-prefix-arg arg))
  7040. (call-interactively 'org-todo))
  7041. (and (bolp) (forward-char 1))
  7042. (setq newhead (org-get-heading))
  7043. (when (and (org-bound-and-true-p
  7044. org-agenda-headline-snapshot-before-repeat)
  7045. (not (equal org-agenda-headline-snapshot-before-repeat
  7046. newhead))
  7047. todayp)
  7048. (setq newhead org-agenda-headline-snapshot-before-repeat
  7049. just-one t))
  7050. (save-excursion
  7051. (org-back-to-heading)
  7052. (move-marker org-last-heading-marker (point))))
  7053. (beginning-of-line 1)
  7054. (save-excursion
  7055. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  7056. (org-move-to-column col))))
  7057. (defun org-agenda-add-note (&optional arg)
  7058. "Add a time-stamped note to the entry at point."
  7059. (interactive "P")
  7060. (org-agenda-check-no-diary)
  7061. (let* ((marker (or (org-get-at-bol 'org-marker)
  7062. (org-agenda-error)))
  7063. (buffer (marker-buffer marker))
  7064. (pos (marker-position marker))
  7065. (hdmarker (org-get-at-bol 'org-hd-marker))
  7066. (inhibit-read-only t))
  7067. (with-current-buffer buffer
  7068. (widen)
  7069. (goto-char pos)
  7070. (org-show-context 'agenda)
  7071. (save-excursion
  7072. (and (outline-next-heading)
  7073. (org-flag-heading nil))) ; show the next heading
  7074. (org-add-note))))
  7075. (defun org-agenda-change-all-lines (newhead hdmarker
  7076. &optional fixface just-this)
  7077. "Change all lines in the agenda buffer which match HDMARKER.
  7078. The new content of the line will be NEWHEAD (as modified by
  7079. `org-agenda-format-item'). HDMARKER is checked with
  7080. `equal' against all `org-hd-marker' text properties in the file.
  7081. If FIXFACE is non-nil, the face of each item is modified according to
  7082. the new TODO state.
  7083. If JUST-THIS is non-nil, change just the current line, not all.
  7084. If FORCE-TAGS is non nil, the car of it returns the new tags."
  7085. (let* ((inhibit-read-only t)
  7086. (line (org-current-line))
  7087. (org-agenda-buffer (current-buffer))
  7088. (thetags (with-current-buffer (marker-buffer hdmarker)
  7089. (save-excursion (save-restriction (widen)
  7090. (goto-char hdmarker)
  7091. (org-get-tags-at)))))
  7092. props m pl undone-face done-face finish new dotime cat tags)
  7093. (save-excursion
  7094. (goto-char (point-max))
  7095. (beginning-of-line 1)
  7096. (while (not finish)
  7097. (setq finish (bobp))
  7098. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  7099. (or (not just-this) (= (org-current-line) line))
  7100. (equal m hdmarker))
  7101. (setq props (text-properties-at (point))
  7102. dotime (org-get-at-bol 'dotime)
  7103. cat (org-get-at-bol 'org-category)
  7104. tags thetags
  7105. new
  7106. (let ((org-prefix-format-compiled
  7107. (or (get-text-property (point) 'format)
  7108. org-prefix-format-compiled)))
  7109. (with-current-buffer (marker-buffer hdmarker)
  7110. (save-excursion
  7111. (save-restriction
  7112. (widen)
  7113. (org-agenda-format-item (org-get-at-bol 'extra)
  7114. newhead cat tags dotime)))))
  7115. pl (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
  7116. undone-face (org-get-at-bol 'undone-face)
  7117. done-face (org-get-at-bol 'done-face))
  7118. (beginning-of-line 1)
  7119. (cond
  7120. ((equal new "")
  7121. (and (looking-at ".*\n?") (replace-match "")))
  7122. ((looking-at ".*")
  7123. (replace-match new t t)
  7124. (beginning-of-line 1)
  7125. (add-text-properties (point-at-bol) (point-at-eol) props)
  7126. (when fixface
  7127. (add-text-properties
  7128. (point-at-bol) (point-at-eol)
  7129. (list 'face
  7130. (if org-last-todo-state-is-todo
  7131. undone-face done-face))))
  7132. (org-agenda-highlight-todo 'line)
  7133. (beginning-of-line 1))
  7134. (t (error "Line update did not work"))))
  7135. (beginning-of-line 0)))
  7136. (org-finalize-agenda)))
  7137. (defun org-agenda-align-tags (&optional line)
  7138. "Align all tags in agenda items to `org-agenda-tags-column'."
  7139. (let ((inhibit-read-only t) l c)
  7140. (save-excursion
  7141. (goto-char (if line (point-at-bol) (point-min)))
  7142. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")
  7143. (if line (point-at-eol) nil) t)
  7144. (add-text-properties
  7145. (match-beginning 2) (match-end 2)
  7146. (list 'face (delq nil (let ((prop (get-text-property
  7147. (match-beginning 2) 'face)))
  7148. (or (listp prop) (setq prop (list prop)))
  7149. (if (memq 'org-tag prop)
  7150. prop
  7151. (cons 'org-tag prop))))))
  7152. (setq l (- (match-end 2) (match-beginning 2))
  7153. c (if (< org-agenda-tags-column 0)
  7154. (- (abs org-agenda-tags-column) l)
  7155. org-agenda-tags-column))
  7156. (delete-region (match-beginning 1) (match-end 1))
  7157. (goto-char (match-beginning 1))
  7158. (insert (org-add-props
  7159. (make-string (max 1 (- c (current-column))) ?\ )
  7160. (plist-put (copy-sequence (text-properties-at (point)))
  7161. 'face nil))))
  7162. (goto-char (point-min))
  7163. (org-font-lock-add-tag-faces (point-max)))))
  7164. (defun org-agenda-priority-up ()
  7165. "Increase the priority of line at point, also in Org-mode file."
  7166. (interactive)
  7167. (org-agenda-priority 'up))
  7168. (defun org-agenda-priority-down ()
  7169. "Decrease the priority of line at point, also in Org-mode file."
  7170. (interactive)
  7171. (org-agenda-priority 'down))
  7172. (defun org-agenda-priority (&optional force-direction)
  7173. "Set the priority of line at point, also in Org-mode file.
  7174. This changes the line at point, all other lines in the agenda referring to
  7175. the same tree node, and the headline of the tree node in the Org-mode file."
  7176. (interactive)
  7177. (unless org-enable-priority-commands
  7178. (error "Priority commands are disabled"))
  7179. (org-agenda-check-no-diary)
  7180. (let* ((marker (or (org-get-at-bol 'org-marker)
  7181. (org-agenda-error)))
  7182. (hdmarker (org-get-at-bol 'org-hd-marker))
  7183. (buffer (marker-buffer hdmarker))
  7184. (pos (marker-position hdmarker))
  7185. (inhibit-read-only t)
  7186. newhead)
  7187. (org-with-remote-undo buffer
  7188. (with-current-buffer buffer
  7189. (widen)
  7190. (goto-char pos)
  7191. (org-show-context 'agenda)
  7192. (save-excursion
  7193. (and (outline-next-heading)
  7194. (org-flag-heading nil))) ; show the next heading
  7195. (funcall 'org-priority force-direction)
  7196. (end-of-line 1)
  7197. (setq newhead (org-get-heading)))
  7198. (org-agenda-change-all-lines newhead hdmarker)
  7199. (beginning-of-line 1))))
  7200. ;; FIXME: should fix the tags property of the agenda line.
  7201. (defun org-agenda-set-tags (&optional tag onoff)
  7202. "Set tags for the current headline."
  7203. (interactive)
  7204. (org-agenda-check-no-diary)
  7205. (if (and (org-region-active-p) (org-called-interactively-p 'any))
  7206. (call-interactively 'org-change-tag-in-region)
  7207. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7208. (org-agenda-error)))
  7209. (buffer (marker-buffer hdmarker))
  7210. (pos (marker-position hdmarker))
  7211. (inhibit-read-only t)
  7212. newhead)
  7213. (org-with-remote-undo buffer
  7214. (with-current-buffer buffer
  7215. (widen)
  7216. (goto-char pos)
  7217. (save-excursion
  7218. (org-show-context 'agenda))
  7219. (save-excursion
  7220. (and (outline-next-heading)
  7221. (org-flag-heading nil))) ; show the next heading
  7222. (goto-char pos)
  7223. (if tag
  7224. (org-toggle-tag tag onoff)
  7225. (call-interactively 'org-set-tags))
  7226. (end-of-line 1)
  7227. (setq newhead (org-get-heading)))
  7228. (org-agenda-change-all-lines newhead hdmarker)
  7229. (beginning-of-line 1)))))
  7230. (defun org-agenda-set-property ()
  7231. "Set a property for the current headline."
  7232. (interactive)
  7233. (org-agenda-check-no-diary)
  7234. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7235. (org-agenda-error)))
  7236. (buffer (marker-buffer hdmarker))
  7237. (pos (marker-position hdmarker))
  7238. (inhibit-read-only t)
  7239. newhead)
  7240. (org-with-remote-undo buffer
  7241. (with-current-buffer buffer
  7242. (widen)
  7243. (goto-char pos)
  7244. (save-excursion
  7245. (org-show-context 'agenda))
  7246. (save-excursion
  7247. (and (outline-next-heading)
  7248. (org-flag-heading nil))) ; show the next heading
  7249. (goto-char pos)
  7250. (call-interactively 'org-set-property)))))
  7251. (defun org-agenda-set-effort ()
  7252. "Set the effort property for the current headline."
  7253. (interactive)
  7254. (org-agenda-check-no-diary)
  7255. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7256. (org-agenda-error)))
  7257. (buffer (marker-buffer hdmarker))
  7258. (pos (marker-position hdmarker))
  7259. (inhibit-read-only t)
  7260. newhead)
  7261. (org-with-remote-undo buffer
  7262. (with-current-buffer buffer
  7263. (widen)
  7264. (goto-char pos)
  7265. (save-excursion
  7266. (org-show-context 'agenda))
  7267. (save-excursion
  7268. (and (outline-next-heading)
  7269. (org-flag-heading nil))) ; show the next heading
  7270. (goto-char pos)
  7271. (call-interactively 'org-set-effort)
  7272. (end-of-line 1)
  7273. (setq newhead (org-get-heading)))
  7274. (org-agenda-change-all-lines newhead hdmarker))))
  7275. (defun org-agenda-toggle-archive-tag ()
  7276. "Toggle the archive tag for the current entry."
  7277. (interactive)
  7278. (org-agenda-check-no-diary)
  7279. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  7280. (org-agenda-error)))
  7281. (buffer (marker-buffer hdmarker))
  7282. (pos (marker-position hdmarker))
  7283. (inhibit-read-only t)
  7284. newhead)
  7285. (org-with-remote-undo buffer
  7286. (with-current-buffer buffer
  7287. (widen)
  7288. (goto-char pos)
  7289. (org-show-context 'agenda)
  7290. (save-excursion
  7291. (and (outline-next-heading)
  7292. (org-flag-heading nil))) ; show the next heading
  7293. (call-interactively 'org-toggle-archive-tag)
  7294. (end-of-line 1)
  7295. (setq newhead (org-get-heading)))
  7296. (org-agenda-change-all-lines newhead hdmarker)
  7297. (beginning-of-line 1))))
  7298. (defun org-agenda-do-date-later (arg)
  7299. (interactive "P")
  7300. (cond
  7301. ((or (equal arg '(16))
  7302. (memq last-command
  7303. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7304. (setq this-command 'org-agenda-date-later-minutes)
  7305. (org-agenda-date-later-minutes 1))
  7306. ((or (equal arg '(4))
  7307. (memq last-command
  7308. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7309. (setq this-command 'org-agenda-date-later-hours)
  7310. (org-agenda-date-later-hours 1))
  7311. (t
  7312. (org-agenda-date-later (prefix-numeric-value arg)))))
  7313. (defun org-agenda-do-date-earlier (arg)
  7314. (interactive "P")
  7315. (cond
  7316. ((or (equal arg '(16))
  7317. (memq last-command
  7318. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  7319. (setq this-command 'org-agenda-date-earlier-minutes)
  7320. (org-agenda-date-earlier-minutes 1))
  7321. ((or (equal arg '(4))
  7322. (memq last-command
  7323. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  7324. (setq this-command 'org-agenda-date-earlier-hours)
  7325. (org-agenda-date-earlier-hours 1))
  7326. (t
  7327. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  7328. (defun org-agenda-date-later (arg &optional what)
  7329. "Change the date of this item to ARG day(s) later."
  7330. (interactive "p")
  7331. (org-agenda-check-type t 'agenda 'timeline)
  7332. (org-agenda-check-no-diary)
  7333. (let* ((marker (or (org-get-at-bol 'org-marker)
  7334. (org-agenda-error)))
  7335. (buffer (marker-buffer marker))
  7336. (pos (marker-position marker))
  7337. cdate today)
  7338. (org-with-remote-undo buffer
  7339. (with-current-buffer buffer
  7340. (widen)
  7341. (goto-char pos)
  7342. (if (not (org-at-timestamp-p))
  7343. (error "Cannot find time stamp"))
  7344. (when (and org-agenda-move-date-from-past-immediately-to-today
  7345. (equal arg 1)
  7346. (or (not what) (eq what 'day))
  7347. (not (save-match-data (org-at-date-range-p))))
  7348. (setq cdate (org-parse-time-string (match-string 0) 'nodefault)
  7349. cdate (calendar-absolute-from-gregorian
  7350. (list (nth 4 cdate) (nth 3 cdate) (nth 5 cdate)))
  7351. today (org-today))
  7352. (if (> today cdate)
  7353. ;; immediately shift to today
  7354. (setq arg (- today cdate))))
  7355. (org-timestamp-change arg (or what 'day))
  7356. (when (and (org-at-date-range-p)
  7357. (re-search-backward org-tr-regexp-both (point-at-bol)))
  7358. (let ((end org-last-changed-timestamp))
  7359. (org-timestamp-change arg (or what 'day))
  7360. (setq org-last-changed-timestamp
  7361. (concat org-last-changed-timestamp "--" end)))))
  7362. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7363. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7364. (defun org-agenda-date-earlier (arg &optional what)
  7365. "Change the date of this item to ARG day(s) earlier."
  7366. (interactive "p")
  7367. (org-agenda-date-later (- arg) what))
  7368. (defun org-agenda-date-later-minutes (arg)
  7369. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7370. (interactive "p")
  7371. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7372. (org-agenda-date-later arg 'minute))
  7373. (defun org-agenda-date-earlier-minutes (arg)
  7374. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  7375. (interactive "p")
  7376. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  7377. (org-agenda-date-earlier arg 'minute))
  7378. (defun org-agenda-date-later-hours (arg)
  7379. "Change the time of this item, in hour steps."
  7380. (interactive "p")
  7381. (org-agenda-date-later arg 'hour))
  7382. (defun org-agenda-date-earlier-hours (arg)
  7383. "Change the time of this item, in hour steps."
  7384. (interactive "p")
  7385. (org-agenda-date-earlier arg 'hour))
  7386. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  7387. "Show new date stamp via text properties."
  7388. ;; We use text properties to make this undoable
  7389. (let ((inhibit-read-only t)
  7390. (buffer-invisibility-spec))
  7391. (setq stamp (concat " " prefix " => " stamp))
  7392. (save-excursion
  7393. (goto-char (point-max))
  7394. (while (not (bobp))
  7395. (when (equal marker (org-get-at-bol 'org-marker))
  7396. (org-move-to-column (- (window-width) (length stamp)) t)
  7397. (org-agenda-fix-tags-filter-overlays-at (point))
  7398. (if (featurep 'xemacs)
  7399. ;; Use `duplicable' property to trigger undo recording
  7400. (let ((ex (make-extent nil nil))
  7401. (gl (make-glyph stamp)))
  7402. (set-glyph-face gl 'secondary-selection)
  7403. (set-extent-properties
  7404. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  7405. (insert-extent ex (1- (point)) (point-at-eol)))
  7406. (add-text-properties
  7407. (1- (point)) (point-at-eol)
  7408. (list 'display (org-add-props stamp nil
  7409. 'face 'secondary-selection))))
  7410. (beginning-of-line 1))
  7411. (beginning-of-line 0)))))
  7412. (defun org-agenda-date-prompt (arg)
  7413. "Change the date of this item. Date is prompted for, with default today.
  7414. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  7415. be used to request time specification in the time stamp."
  7416. (interactive "P")
  7417. (org-agenda-check-type t 'agenda 'timeline)
  7418. (org-agenda-check-no-diary)
  7419. (let* ((marker (or (org-get-at-bol 'org-marker)
  7420. (org-agenda-error)))
  7421. (buffer (marker-buffer marker))
  7422. (pos (marker-position marker)))
  7423. (org-with-remote-undo buffer
  7424. (with-current-buffer buffer
  7425. (widen)
  7426. (goto-char pos)
  7427. (if (not (org-at-timestamp-p t))
  7428. (error "Cannot find time stamp"))
  7429. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  7430. (org-agenda-show-new-time marker org-last-changed-timestamp))
  7431. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  7432. (defun org-agenda-schedule (arg &optional time)
  7433. "Schedule the item at point.
  7434. ARG is passed through to `org-schedule'."
  7435. (interactive "P")
  7436. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7437. (org-agenda-check-no-diary)
  7438. (let* ((marker (or (org-get-at-bol 'org-marker)
  7439. (org-agenda-error)))
  7440. (type (marker-insertion-type marker))
  7441. (buffer (marker-buffer marker))
  7442. (pos (marker-position marker))
  7443. (org-insert-labeled-timestamps-at-point nil)
  7444. ts)
  7445. (set-marker-insertion-type marker t)
  7446. (org-with-remote-undo buffer
  7447. (with-current-buffer buffer
  7448. (widen)
  7449. (goto-char pos)
  7450. (setq ts (org-schedule arg time)))
  7451. (org-agenda-show-new-time marker ts "S"))
  7452. (message "Item scheduled for %s" ts)))
  7453. (defun org-agenda-deadline (arg &optional time)
  7454. "Schedule the item at point.
  7455. ARG is passed through to `org-deadline'."
  7456. (interactive "P")
  7457. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  7458. (org-agenda-check-no-diary)
  7459. (let* ((marker (or (org-get-at-bol 'org-marker)
  7460. (org-agenda-error)))
  7461. (buffer (marker-buffer marker))
  7462. (pos (marker-position marker))
  7463. (org-insert-labeled-timestamps-at-point nil)
  7464. ts)
  7465. (org-with-remote-undo buffer
  7466. (with-current-buffer buffer
  7467. (widen)
  7468. (goto-char pos)
  7469. (setq ts (org-deadline arg time)))
  7470. (org-agenda-show-new-time marker ts "D"))
  7471. (message "Deadline for this item set to %s" ts)))
  7472. (defun org-agenda-action ()
  7473. "Select entry for agenda action, or execute an agenda action.
  7474. This command prompts for another letter. Valid inputs are:
  7475. m Mark the entry at point for an agenda action
  7476. s Schedule the marked entry to the date at the cursor
  7477. d Set the deadline of the marked entry to the date at the cursor
  7478. r Call `org-remember' with cursor date as the default date
  7479. c Call `org-capture' with cursor date as the default date
  7480. SPC Show marked entry in other window
  7481. TAB Visit marked entry in other window
  7482. The cursor may be at a date in the calendar, or in the Org agenda."
  7483. (interactive)
  7484. (let (ans)
  7485. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [c]apture [ ]show")
  7486. (setq ans (read-char-exclusive))
  7487. (cond
  7488. ((equal ans ?m)
  7489. ;; Mark this entry
  7490. (if (eq major-mode 'org-agenda-mode)
  7491. (let ((m (or (org-get-at-bol 'org-hd-marker)
  7492. (org-get-at-bol 'org-marker))))
  7493. (if m
  7494. (progn
  7495. (move-marker org-agenda-action-marker
  7496. (marker-position m) (marker-buffer m))
  7497. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  7498. (error "Don't know which entry to mark")))
  7499. (error "This command works only in the agenda")))
  7500. ((equal ans ?s)
  7501. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  7502. ((equal ans ?d)
  7503. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  7504. ((equal ans ?r)
  7505. (org-agenda-do-action '(org-remember) t))
  7506. ((equal ans ?c)
  7507. (org-agenda-do-action '(org-capture) t))
  7508. ((equal ans ?\ )
  7509. (let ((cw (selected-window)))
  7510. (org-switch-to-buffer-other-window
  7511. (marker-buffer org-agenda-action-marker))
  7512. (goto-char org-agenda-action-marker)
  7513. (org-show-context 'agenda)
  7514. (select-window cw)))
  7515. ((equal ans ?\C-i)
  7516. (org-switch-to-buffer-other-window
  7517. (marker-buffer org-agenda-action-marker))
  7518. (goto-char org-agenda-action-marker)
  7519. (org-show-context 'agenda))
  7520. (t (error "Invalid agenda action %c" ans)))))
  7521. (defun org-agenda-do-action (form &optional current-buffer)
  7522. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  7523. (let ((org-overriding-default-time (org-get-cursor-date)))
  7524. (if current-buffer
  7525. (eval form)
  7526. (if (not (marker-buffer org-agenda-action-marker))
  7527. (error "No entry has been selected for agenda action")
  7528. (with-current-buffer (marker-buffer org-agenda-action-marker)
  7529. (save-excursion
  7530. (save-restriction
  7531. (widen)
  7532. (goto-char org-agenda-action-marker)
  7533. (eval form))))))))
  7534. (defun org-agenda-clock-in (&optional arg)
  7535. "Start the clock on the currently selected item."
  7536. (interactive "P")
  7537. (org-agenda-check-no-diary)
  7538. (if (equal arg '(4))
  7539. (org-clock-in arg)
  7540. (let* ((marker (or (org-get-at-bol 'org-marker)
  7541. (org-agenda-error)))
  7542. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  7543. marker))
  7544. (pos (marker-position marker))
  7545. newhead)
  7546. (org-with-remote-undo (marker-buffer marker)
  7547. (with-current-buffer (marker-buffer marker)
  7548. (widen)
  7549. (goto-char pos)
  7550. (org-show-context 'agenda)
  7551. (org-show-entry)
  7552. (org-cycle-hide-drawers 'children)
  7553. (org-clock-in arg)
  7554. (setq newhead (org-get-heading)))
  7555. (org-agenda-change-all-lines newhead hdmarker)))))
  7556. (defun org-agenda-clock-out ()
  7557. "Stop the currently running clock."
  7558. (interactive)
  7559. (unless (marker-buffer org-clock-marker)
  7560. (error "No running clock"))
  7561. (let ((marker (make-marker)) newhead)
  7562. (org-with-remote-undo (marker-buffer org-clock-marker)
  7563. (with-current-buffer (marker-buffer org-clock-marker)
  7564. (save-excursion
  7565. (save-restriction
  7566. (widen)
  7567. (goto-char org-clock-marker)
  7568. (org-back-to-heading t)
  7569. (move-marker marker (point))
  7570. (org-clock-out)
  7571. (setq newhead (org-get-heading))))))
  7572. (org-agenda-change-all-lines newhead marker)
  7573. (move-marker marker nil)))
  7574. (defun org-agenda-clock-cancel (&optional arg)
  7575. "Cancel the currently running clock."
  7576. (interactive "P")
  7577. (unless (marker-buffer org-clock-marker)
  7578. (error "No running clock"))
  7579. (org-with-remote-undo (marker-buffer org-clock-marker)
  7580. (org-clock-cancel)))
  7581. (defun org-agenda-clock-goto ()
  7582. "Jump to the currently clocked in task within the agenda.
  7583. If the currently clocked in task is not listed in the agenda
  7584. buffer, display it in another window."
  7585. (interactive)
  7586. (let (pos)
  7587. (mapc (lambda (o)
  7588. (if (eq (overlay-get o 'type) 'org-agenda-clocking)
  7589. (setq pos (overlay-start o))))
  7590. (overlays-in (point-min) (point-max)))
  7591. (cond (pos (goto-char pos))
  7592. ;; If the currently clocked entry is not in the agenda
  7593. ;; buffer, we visit it in another window:
  7594. (org-clock-current-task
  7595. (org-switch-to-buffer-other-window (org-clock-goto)))
  7596. (t (message "No running clock, use `C-c C-x C-j' to jump to the most recent one")))))
  7597. (defun org-agenda-diary-entry-in-org-file ()
  7598. "Make a diary entry in the file `org-agenda-diary-file'."
  7599. (let (d1 d2 char (text "") dp1 dp2)
  7600. (if (equal (buffer-name) "*Calendar*")
  7601. (setq d1 (calendar-cursor-to-date t)
  7602. d2 (car calendar-mark-ring))
  7603. (setq dp1 (get-text-property (point-at-bol) 'day))
  7604. (unless dp1 (error "No date defined in current line"))
  7605. (setq d1 (calendar-gregorian-from-absolute dp1)
  7606. d2 (and (ignore-errors (mark))
  7607. (save-excursion
  7608. (goto-char (mark))
  7609. (setq dp2 (get-text-property (point-at-bol) 'day)))
  7610. (calendar-gregorian-from-absolute dp2))))
  7611. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  7612. (setq char (read-char-exclusive))
  7613. (cond
  7614. ((equal char ?d)
  7615. (setq text (read-string "Day entry: "))
  7616. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  7617. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7618. ((equal char ?a)
  7619. (setq d1 (list (car d1) (nth 1 d1)
  7620. (read-number (format "Reference year [%d]: " (nth 2 d1))
  7621. (nth 2 d1))))
  7622. (setq text (read-string "Anniversary (use %d to show years): "))
  7623. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  7624. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7625. ((equal char ?b)
  7626. (setq text (read-string "Block entry: "))
  7627. (unless (and d1 d2 (not (equal d1 d2)))
  7628. (error "No block of days selected"))
  7629. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  7630. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  7631. ((equal char ?j)
  7632. (org-switch-to-buffer-other-window
  7633. (find-file-noselect org-agenda-diary-file))
  7634. (require 'org-datetree)
  7635. (org-datetree-find-date-create d1)
  7636. (org-reveal t))
  7637. (t (error "Invalid selection character `%c'" char)))))
  7638. (defcustom org-agenda-insert-diary-strategy 'date-tree
  7639. "Where in `org-agenda-diary-file' should new entries be added?
  7640. Valid values:
  7641. date-tree in the date tree, as child of the date
  7642. top-level as top-level entries at the end of the file."
  7643. :group 'org-agenda
  7644. :type '(choice
  7645. (const :tag "in a date tree" date-tree)
  7646. (const :tag "as top level at end of file" top-level)))
  7647. (defcustom org-agenda-insert-diary-extract-time nil
  7648. "Non-nil means extract any time specification from the diary entry."
  7649. :group 'org-agenda
  7650. :version "24.1"
  7651. :type 'boolean)
  7652. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  7653. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  7654. If TEXT is not empty, it will become the headline of the new entry, and
  7655. the resulting entry will not be shown. When TEXT is empty, switch to
  7656. `org-agenda-diary-file' and let the user finish the entry there."
  7657. (let ((cw (current-window-configuration)))
  7658. (org-switch-to-buffer-other-window
  7659. (find-file-noselect org-agenda-diary-file))
  7660. (widen)
  7661. (goto-char (point-min))
  7662. (cond
  7663. ((eq type 'anniversary)
  7664. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  7665. (progn
  7666. (or (org-at-heading-p t)
  7667. (progn
  7668. (outline-next-heading)
  7669. (insert "* Anniversaries\n\n")
  7670. (beginning-of-line -1)))))
  7671. (outline-next-heading)
  7672. (org-back-over-empty-lines)
  7673. (backward-char 1)
  7674. (insert "\n")
  7675. (insert (format "%%%%(org-anniversary %d %2d %2d) %s"
  7676. (nth 2 d1) (car d1) (nth 1 d1) text)))
  7677. ((eq type 'day)
  7678. (let ((org-prefix-has-time t)
  7679. (org-agenda-time-leading-zero t)
  7680. fmt time time2)
  7681. (if org-agenda-insert-diary-extract-time
  7682. ;; Use org-agenda-format-item to parse text for a time-range and
  7683. ;; remove it. FIXME: This is a hack, we should refactor
  7684. ;; that function to make time extraction available separately
  7685. (setq fmt (org-agenda-format-item nil text nil nil t)
  7686. time (get-text-property 0 'time fmt)
  7687. time2 (if (> (length time) 0)
  7688. ;; split-string removes trailing ...... if
  7689. ;; no end time given. First space
  7690. ;; separates time from date.
  7691. (concat " " (car (split-string time "\\.")))
  7692. nil)
  7693. text (get-text-property 0 'txt fmt)))
  7694. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7695. (org-agenda-insert-diary-as-top-level text)
  7696. (require 'org-datetree)
  7697. (org-datetree-find-date-create d1)
  7698. (org-agenda-insert-diary-make-new-entry text))
  7699. (org-insert-time-stamp (org-time-from-absolute
  7700. (calendar-absolute-from-gregorian d1))
  7701. nil nil nil nil time2))
  7702. (end-of-line 0))
  7703. ((eq type 'block)
  7704. (if (> (calendar-absolute-from-gregorian d1)
  7705. (calendar-absolute-from-gregorian d2))
  7706. (setq d1 (prog1 d2 (setq d2 d1))))
  7707. (if (eq org-agenda-insert-diary-strategy 'top-level)
  7708. (org-agenda-insert-diary-as-top-level text)
  7709. (require 'org-datetree)
  7710. (org-datetree-find-date-create d1)
  7711. (org-agenda-insert-diary-make-new-entry text))
  7712. (org-insert-time-stamp (org-time-from-absolute
  7713. (calendar-absolute-from-gregorian d1)))
  7714. (insert "--")
  7715. (org-insert-time-stamp (org-time-from-absolute
  7716. (calendar-absolute-from-gregorian d2)))
  7717. (end-of-line 0)))
  7718. (if (string-match "\\S-" text)
  7719. (progn
  7720. (set-window-configuration cw)
  7721. (message "%s entry added to %s"
  7722. (capitalize (symbol-name type))
  7723. (abbreviate-file-name org-agenda-diary-file)))
  7724. (org-reveal t)
  7725. (message "Please finish entry here"))))
  7726. (defun org-agenda-insert-diary-as-top-level (text)
  7727. "Make new entry as a top-level entry at the end of the file.
  7728. Add TEXT as headline, and position the cursor in the second line so that
  7729. a timestamp can be added there."
  7730. (widen)
  7731. (goto-char (point-max))
  7732. (or (bolp) (insert "\n"))
  7733. (insert "* " text "\n")
  7734. (if org-adapt-indentation (org-indent-to-column 2)))
  7735. (defun org-agenda-insert-diary-make-new-entry (text)
  7736. "Make new entry as last child of current entry.
  7737. Add TEXT as headline, and position the cursor in the second line so that
  7738. a timestamp can be added there."
  7739. (let ((org-show-following-heading t)
  7740. (org-show-siblings t)
  7741. (org-show-hierarchy-above t)
  7742. (org-show-entry-below t)
  7743. col)
  7744. (outline-next-heading)
  7745. (org-back-over-empty-lines)
  7746. (or (looking-at "[ \t]*$")
  7747. (progn (insert "\n") (backward-char 1)))
  7748. (org-insert-heading nil t)
  7749. (org-do-demote)
  7750. (setq col (current-column))
  7751. (insert text "\n")
  7752. (if org-adapt-indentation (org-indent-to-column col))
  7753. (let ((org-show-following-heading t)
  7754. (org-show-siblings t)
  7755. (org-show-hierarchy-above t)
  7756. (org-show-entry-below t))
  7757. (org-show-context))))
  7758. (defun org-agenda-diary-entry ()
  7759. "Make a diary entry, like the `i' command from the calendar.
  7760. All the standard commands work: block, weekly etc.
  7761. When `org-agenda-diary-file' points to a file,
  7762. `org-agenda-diary-entry-in-org-file' is called instead to create
  7763. entries in that Org-mode file."
  7764. (interactive)
  7765. (org-agenda-check-type t 'agenda 'timeline)
  7766. (if (not (eq org-agenda-diary-file 'diary-file))
  7767. (org-agenda-diary-entry-in-org-file)
  7768. (require 'diary-lib)
  7769. (let* ((char (progn
  7770. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  7771. (read-char-exclusive)))
  7772. (cmd (cdr (assoc char
  7773. '((?d . insert-diary-entry)
  7774. (?w . insert-weekly-diary-entry)
  7775. (?m . insert-monthly-diary-entry)
  7776. (?y . insert-yearly-diary-entry)
  7777. (?a . insert-anniversary-diary-entry)
  7778. (?b . insert-block-diary-entry)
  7779. (?c . insert-cyclic-diary-entry)))))
  7780. (oldf (symbol-function 'calendar-cursor-to-date))
  7781. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  7782. (point (point))
  7783. (mark (or (mark t) (point))))
  7784. (unless cmd
  7785. (error "No command associated with <%c>" char))
  7786. (unless (and (get-text-property point 'day)
  7787. (or (not (equal ?b char))
  7788. (get-text-property mark 'day)))
  7789. (error "Don't know which date to use for diary entry"))
  7790. ;; We implement this by hacking the `calendar-cursor-to-date' function
  7791. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  7792. (let ((calendar-mark-ring
  7793. (list (calendar-gregorian-from-absolute
  7794. (or (get-text-property mark 'day)
  7795. (get-text-property point 'day))))))
  7796. (unwind-protect
  7797. (progn
  7798. (fset 'calendar-cursor-to-date
  7799. (lambda (&optional error dummy)
  7800. (calendar-gregorian-from-absolute
  7801. (get-text-property point 'day))))
  7802. (call-interactively cmd))
  7803. (fset 'calendar-cursor-to-date oldf))))))
  7804. (defun org-agenda-execute-calendar-command (cmd)
  7805. "Execute a calendar command from the agenda, with the date associated to
  7806. the cursor position."
  7807. (org-agenda-check-type t 'agenda 'timeline)
  7808. (require 'diary-lib)
  7809. (unless (get-text-property (point) 'day)
  7810. (error "Don't know which date to use for calendar command"))
  7811. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  7812. (point (point))
  7813. (date (calendar-gregorian-from-absolute
  7814. (get-text-property point 'day)))
  7815. ;; the following 2 vars are needed in the calendar
  7816. (displayed-month (car date))
  7817. (displayed-year (nth 2 date)))
  7818. (unwind-protect
  7819. (progn
  7820. (fset 'calendar-cursor-to-date
  7821. (lambda (&optional error dummy)
  7822. (calendar-gregorian-from-absolute
  7823. (get-text-property point 'day))))
  7824. (call-interactively cmd))
  7825. (fset 'calendar-cursor-to-date oldf))))
  7826. (defun org-agenda-phases-of-moon ()
  7827. "Display the phases of the moon for the 3 months around the cursor date."
  7828. (interactive)
  7829. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  7830. (defun org-agenda-holidays ()
  7831. "Display the holidays for the 3 months around the cursor date."
  7832. (interactive)
  7833. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  7834. (defvar calendar-longitude)
  7835. (defvar calendar-latitude)
  7836. (defvar calendar-location-name)
  7837. (defun org-agenda-sunrise-sunset (arg)
  7838. "Display sunrise and sunset for the cursor date.
  7839. Latitude and longitude can be specified with the variables
  7840. `calendar-latitude' and `calendar-longitude'. When called with prefix
  7841. argument, latitude and longitude will be prompted for."
  7842. (interactive "P")
  7843. (require 'solar)
  7844. (let ((calendar-longitude (if arg nil calendar-longitude))
  7845. (calendar-latitude (if arg nil calendar-latitude))
  7846. (calendar-location-name
  7847. (if arg "the given coordinates" calendar-location-name)))
  7848. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  7849. (defun org-agenda-goto-calendar ()
  7850. "Open the Emacs calendar with the date at the cursor."
  7851. (interactive)
  7852. (org-agenda-check-type t 'agenda 'timeline)
  7853. (let* ((day (or (get-text-property (point) 'day)
  7854. (error "Don't know which date to open in calendar")))
  7855. (date (calendar-gregorian-from-absolute day))
  7856. (calendar-move-hook nil)
  7857. (calendar-view-holidays-initially-flag nil)
  7858. (calendar-view-diary-initially-flag nil))
  7859. (calendar)
  7860. (calendar-goto-date date)))
  7861. ;;;###autoload
  7862. (defun org-calendar-goto-agenda ()
  7863. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  7864. This is a command that has to be installed in `calendar-mode-map'."
  7865. (interactive)
  7866. (org-agenda-list nil (calendar-absolute-from-gregorian
  7867. (calendar-cursor-to-date))
  7868. nil))
  7869. (defun org-agenda-convert-date ()
  7870. (interactive)
  7871. (org-agenda-check-type t 'agenda 'timeline)
  7872. (let ((day (get-text-property (point) 'day))
  7873. date s)
  7874. (unless day
  7875. (error "Don't know which date to convert"))
  7876. (setq date (calendar-gregorian-from-absolute day))
  7877. (setq s (concat
  7878. "Gregorian: " (calendar-date-string date) "\n"
  7879. "ISO: " (calendar-iso-date-string date) "\n"
  7880. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  7881. "Julian: " (calendar-julian-date-string date) "\n"
  7882. "Astron. JD: " (calendar-astro-date-string date)
  7883. " (Julian date number at noon UTC)\n"
  7884. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  7885. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  7886. "French: " (calendar-french-date-string date) "\n"
  7887. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  7888. "Mayan: " (calendar-mayan-date-string date) "\n"
  7889. "Coptic: " (calendar-coptic-date-string date) "\n"
  7890. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  7891. "Persian: " (calendar-persian-date-string date) "\n"
  7892. "Chinese: " (calendar-chinese-date-string date) "\n"))
  7893. (with-output-to-temp-buffer "*Dates*"
  7894. (princ s))
  7895. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  7896. ;;; Bulk commands
  7897. (defvar org-agenda-bulk-marked-entries nil
  7898. "List of markers that refer to marked entries in the agenda.")
  7899. (defun org-agenda-bulk-marked-p ()
  7900. (eq (get-char-property (point-at-bol) 'type)
  7901. 'org-marked-entry-overlay))
  7902. (defun org-agenda-bulk-mark (&optional arg)
  7903. "Mark the entry at point for future bulk action."
  7904. (interactive "p")
  7905. (dotimes (i (max arg 1))
  7906. (unless (org-get-at-bol 'org-agenda-diary-link)
  7907. (let* ((m (org-get-at-bol 'org-hd-marker))
  7908. ov)
  7909. (unless (org-agenda-bulk-marked-p)
  7910. (unless m (error "Nothing to mark at point"))
  7911. (push m org-agenda-bulk-marked-entries)
  7912. (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  7913. (org-overlay-display ov "> "
  7914. (org-get-todo-face "TODO")
  7915. 'evaporate)
  7916. (overlay-put ov 'type 'org-marked-entry-overlay))
  7917. (beginning-of-line 2)
  7918. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7919. (beginning-of-line 2))
  7920. (message "%d entries marked for bulk action"
  7921. (length org-agenda-bulk-marked-entries))))))
  7922. (defun org-agenda-bulk-mark-regexp (regexp)
  7923. "Mark entries match REGEXP."
  7924. (interactive "sMark entries matching regexp: ")
  7925. (let (entries-marked)
  7926. (save-excursion
  7927. (goto-char (point-min))
  7928. (goto-char (next-single-property-change (point) 'txt))
  7929. (while (re-search-forward regexp nil t)
  7930. (when (string-match regexp (get-text-property (point) 'txt))
  7931. (setq entries-marked (+ entries-marked 1))
  7932. (call-interactively 'org-agenda-bulk-mark))))
  7933. (if (not entries-marked)
  7934. (message "No entry matching this regexp."))))
  7935. (defun org-agenda-bulk-unmark ()
  7936. "Unmark the entry at point for future bulk action."
  7937. (interactive)
  7938. (when (org-agenda-bulk-marked-p)
  7939. (org-agenda-bulk-remove-overlays
  7940. (point-at-bol) (+ 2 (point-at-bol)))
  7941. (setq org-agenda-bulk-marked-entries
  7942. (delete (org-get-at-bol 'org-hd-marker)
  7943. org-agenda-bulk-marked-entries)))
  7944. (beginning-of-line 2)
  7945. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  7946. (beginning-of-line 2))
  7947. (message "%d entries marked for bulk action"
  7948. (length org-agenda-bulk-marked-entries)))
  7949. (defun org-agenda-bulk-toggle ()
  7950. "Toggle marking the entry at point for bulk action."
  7951. (interactive)
  7952. (if (org-agenda-bulk-marked-p)
  7953. (org-agenda-bulk-unmark)
  7954. (org-agenda-bulk-mark)))
  7955. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  7956. "Remove the mark overlays between BEG and END in the agenda buffer.
  7957. BEG and END default to the buffer limits.
  7958. This only removes the overlays, it does not remove the markers
  7959. from the list in `org-agenda-bulk-marked-entries'."
  7960. (interactive)
  7961. (mapc (lambda (ov)
  7962. (and (eq (overlay-get ov 'type) 'org-marked-entry-overlay)
  7963. (delete-overlay ov)))
  7964. (overlays-in (or beg (point-min)) (or end (point-max)))))
  7965. (defun org-agenda-bulk-remove-all-marks ()
  7966. "Remove all marks in the agenda buffer.
  7967. This will remove the markers, and the overlays."
  7968. (interactive)
  7969. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  7970. (setq org-agenda-bulk-marked-entries nil)
  7971. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  7972. (defun org-agenda-bulk-action (&optional arg)
  7973. "Execute an remote-editing action on all marked entries.
  7974. The prefix arg is passed through to the command if possible."
  7975. (interactive "P")
  7976. ;; Make sure we have markers, and only valid ones
  7977. (unless org-agenda-bulk-marked-entries (error "No entries are marked"))
  7978. (mapc
  7979. (lambda (m)
  7980. (unless (and (markerp m)
  7981. (marker-buffer m)
  7982. (buffer-live-p (marker-buffer m))
  7983. (marker-position m))
  7984. (error "Marker %s for bulk command is invalid" m)))
  7985. org-agenda-bulk-marked-entries)
  7986. ;; Prompt for the bulk command
  7987. (message (concat "Bulk: [r]efile [$]arch [A]rch->sib [t]odo"
  7988. " [+/-]tag [s]chd [S]catter [d]eadline [f]unction"
  7989. (when org-agenda-bulk-custom-functions
  7990. (concat " Custom: ["
  7991. (mapconcat (lambda(f) (char-to-string (car f)))
  7992. org-agenda-bulk-custom-functions "")
  7993. "]"))))
  7994. (let* ((action (read-char-exclusive))
  7995. (org-log-refile (if org-log-refile 'time nil))
  7996. (entries (reverse org-agenda-bulk-marked-entries))
  7997. redo-at-end
  7998. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  7999. (cond
  8000. ((equal action ?$)
  8001. (setq cmd '(org-agenda-archive)))
  8002. ((equal action ?A)
  8003. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  8004. ((member action '(?r ?w))
  8005. (setq rfloc (org-refile-get-location
  8006. "Refile to"
  8007. (marker-buffer (car org-agenda-bulk-marked-entries))
  8008. org-refile-allow-creating-parent-nodes))
  8009. (if (nth 3 rfloc)
  8010. (setcar (nthcdr 3 rfloc)
  8011. (move-marker (make-marker) (nth 3 rfloc)
  8012. (or (get-file-buffer (nth 1 rfloc))
  8013. (find-buffer-visiting (nth 1 rfloc))
  8014. (error "This should not happen")))))
  8015. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc) t)
  8016. redo-at-end t))
  8017. ((equal action ?t)
  8018. (setq state (org-icompleting-read
  8019. "Todo state: "
  8020. (with-current-buffer (marker-buffer (car entries))
  8021. (mapcar 'list org-todo-keywords-1))))
  8022. (setq cmd `(let ((org-inhibit-blocking t)
  8023. (org-inhibit-logging 'note))
  8024. (org-agenda-todo ,state))))
  8025. ((memq action '(?- ?+))
  8026. (setq tag (org-icompleting-read
  8027. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  8028. (with-current-buffer (marker-buffer (car entries))
  8029. (delq nil
  8030. (mapcar (lambda (x)
  8031. (if (stringp (car x)) x)) org-tag-alist)))))
  8032. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  8033. ((memq action '(?s ?d))
  8034. (let* ((date (unless arg
  8035. (org-read-date
  8036. nil nil nil
  8037. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  8038. (ans (if arg nil org-read-date-final-answer))
  8039. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  8040. (setq cmd `(let* ((bound (fboundp 'read-string))
  8041. (old (and bound (symbol-function 'read-string))))
  8042. (unwind-protect
  8043. (progn
  8044. (fset 'read-string (lambda (&rest ignore) ,ans))
  8045. (eval '(,c1 arg)))
  8046. (if bound
  8047. (fset 'read-string old)
  8048. (fmakunbound 'read-string)))))))
  8049. ((equal action ?S)
  8050. (if (not (org-agenda-check-type nil 'agenda 'timeline 'todo))
  8051. (error "Can't scatter tasks in \"%s\" agenda view" org-agenda-type)
  8052. (let ((days (read-number
  8053. (format "Scatter tasks across how many %sdays: "
  8054. (if arg "week" "")) 7)))
  8055. (setq cmd
  8056. `(let ((distance (1+ (random ,days))))
  8057. (if arg
  8058. (let ((dist distance)
  8059. (day-of-week
  8060. (calendar-day-of-week
  8061. (calendar-gregorian-from-absolute (org-today)))))
  8062. (dotimes (i (1+ dist))
  8063. (while (member day-of-week org-agenda-weekend-days)
  8064. (incf distance)
  8065. (incf day-of-week)
  8066. (if (= day-of-week 7)
  8067. (setq day-of-week 0)))
  8068. (incf day-of-week)
  8069. (if (= day-of-week 7)
  8070. (setq day-of-week 0)))))
  8071. ;; silently fail when try to replan a sexp entry
  8072. (condition-case nil
  8073. (let* ((date (calendar-gregorian-from-absolute
  8074. (+ (org-today) distance)))
  8075. (time (encode-time 0 0 0 (nth 1 date) (nth 0 date)
  8076. (nth 2 date))))
  8077. (org-agenda-schedule nil time))
  8078. (error nil)))))))
  8079. ((assoc action org-agenda-bulk-custom-functions)
  8080. (setq cmd (list (cadr (assoc action org-agenda-bulk-custom-functions)))
  8081. redo-at-end t))
  8082. ((equal action ?f)
  8083. (setq cmd (list (intern
  8084. (org-icompleting-read "Function: "
  8085. obarray 'fboundp t nil nil)))))
  8086. (t (error "Invalid bulk action")))
  8087. ;; Sort the markers, to make sure that parents are handled before children
  8088. (setq entries (sort entries
  8089. (lambda (a b)
  8090. (cond
  8091. ((equal (marker-buffer a) (marker-buffer b))
  8092. (< (marker-position a) (marker-position b)))
  8093. (t
  8094. (string< (buffer-name (marker-buffer a))
  8095. (buffer-name (marker-buffer b))))))))
  8096. ;; Now loop over all markers and apply cmd
  8097. (while (setq e (pop entries))
  8098. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  8099. (if (not pos)
  8100. (progn (message "Skipping removed entry at %s" e)
  8101. (setq cntskip (1+ cntskip)))
  8102. (goto-char pos)
  8103. (let (org-loop-over-headlines-in-active-region)
  8104. (eval cmd))
  8105. (setq org-agenda-bulk-marked-entries
  8106. (delete e org-agenda-bulk-marked-entries))
  8107. (setq cnt (1+ cnt))))
  8108. (setq org-agenda-bulk-marked-entries nil)
  8109. (org-agenda-bulk-remove-all-marks)
  8110. (when redo-at-end (org-agenda-redo))
  8111. (message "Acted on %d entries%s"
  8112. cnt
  8113. (if (= cntskip 0)
  8114. ""
  8115. (format ", skipped %d (disappeared before their turn)"
  8116. cntskip)))))
  8117. ;;; Flagging notes
  8118. (defun org-agenda-show-the-flagging-note ()
  8119. "Display the flagging note in the other window.
  8120. When called a second time in direct sequence, offer to remove the FLAGGING
  8121. tag and (if present) the flagging note."
  8122. (interactive)
  8123. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  8124. (win (selected-window))
  8125. note heading newhead)
  8126. (unless hdmarker
  8127. (error "No linked entry at point"))
  8128. (if (and (eq this-command last-command)
  8129. (y-or-n-p "Unflag and remove any flagging note? "))
  8130. (progn
  8131. (org-agenda-remove-flag hdmarker)
  8132. (let ((win (get-buffer-window "*Flagging Note*")))
  8133. (and win (delete-window win)))
  8134. (message "Entry unflagged"))
  8135. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  8136. (unless note
  8137. (error "No flagging note"))
  8138. (org-kill-new note)
  8139. (org-switch-to-buffer-other-window "*Flagging Note*")
  8140. (erase-buffer)
  8141. (insert note)
  8142. (goto-char (point-min))
  8143. (while (re-search-forward "\\\\n" nil t)
  8144. (replace-match "\n" t t))
  8145. (goto-char (point-min))
  8146. (select-window win)
  8147. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  8148. (defun org-agenda-remove-flag (marker)
  8149. "Remove the FLAGGED tag and any flagging note in the entry."
  8150. (let (newhead)
  8151. (org-with-point-at marker
  8152. (org-toggle-tag "FLAGGED" 'off)
  8153. (org-entry-delete nil "THEFLAGGINGNOTE")
  8154. (setq newhead (org-get-heading)))
  8155. (org-agenda-change-all-lines newhead marker)
  8156. (message "Entry unflagged")))
  8157. (defun org-agenda-get-any-marker (&optional pos)
  8158. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  8159. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  8160. ;;; Appointment reminders
  8161. (defvar appt-time-msg-list)
  8162. ;;;###autoload
  8163. (defun org-agenda-to-appt (&optional refresh filter &rest args)
  8164. "Activate appointments found in `org-agenda-files'.
  8165. With a \\[universal-argument] prefix, refresh the list of
  8166. appointments.
  8167. If FILTER is t, interactively prompt the user for a regular
  8168. expression, and filter out entries that don't match it.
  8169. If FILTER is a string, use this string as a regular expression
  8170. for filtering entries out.
  8171. If FILTER is a function, filter out entries against which
  8172. calling the function returns nil. This function takes one
  8173. argument: an entry from `org-agenda-get-day-entries'.
  8174. FILTER can also be an alist with the car of each cell being
  8175. either 'headline or 'category. For example:
  8176. '((headline \"IMPORTANT\")
  8177. (category \"Work\"))
  8178. will only add headlines containing IMPORTANT or headlines
  8179. belonging to the \"Work\" category.
  8180. ARGS are symbols indicating what kind of entries to consider.
  8181. By default `org-agenda-to-appt' will use :deadline, :scheduled
  8182. and :timestamp entries. See the docstring of `org-diary' for
  8183. details and examples."
  8184. (interactive "P")
  8185. (if refresh (setq appt-time-msg-list nil))
  8186. (if (eq filter t)
  8187. (setq filter (read-from-minibuffer "Regexp filter: ")))
  8188. (let* ((cnt 0) ; count added events
  8189. (scope (or args '(:deadline :scheduled :timestamp)))
  8190. (org-agenda-new-buffers nil)
  8191. (org-deadline-warning-days 0)
  8192. ;; Do not use `org-today' here because appt only takes
  8193. ;; time and without date as argument, so it may pass wrong
  8194. ;; information otherwise
  8195. (today (org-date-to-gregorian
  8196. (time-to-days (current-time))))
  8197. (org-agenda-restrict nil)
  8198. (files (org-agenda-files 'unrestricted)) entries file)
  8199. ;; Get all entries which may contain an appt
  8200. (org-prepare-agenda-buffers files)
  8201. (while (setq file (pop files))
  8202. (setq entries
  8203. (delq nil
  8204. (append entries
  8205. (apply 'org-agenda-get-day-entries
  8206. file today scope)))))
  8207. ;; Map thru entries and find if we should filter them out
  8208. (mapc
  8209. (lambda(x)
  8210. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  8211. (cat (get-text-property 1 'org-category x))
  8212. (tod (get-text-property 1 'time-of-day x))
  8213. (ok (or (null filter)
  8214. (and (stringp filter) (string-match filter evt))
  8215. (and (functionp filter) (funcall filter x))
  8216. (and (listp filter)
  8217. (let ((cat-filter (cadr (assoc 'category filter)))
  8218. (evt-filter (cadr (assoc 'headline filter))))
  8219. (or (and (stringp cat-filter)
  8220. (string-match cat-filter cat))
  8221. (and (stringp evt-filter)
  8222. (string-match evt-filter evt))))))))
  8223. ;; FIXME: Shall we remove text-properties for the appt text?
  8224. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  8225. (when (and ok tod)
  8226. (setq tod (concat "00" (number-to-string tod))
  8227. tod (when (string-match
  8228. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  8229. (concat (match-string 1 tod) ":"
  8230. (match-string 2 tod))))
  8231. (appt-add tod evt)
  8232. (setq cnt (1+ cnt))))) entries)
  8233. (org-release-buffers org-agenda-new-buffers)
  8234. (if (eq cnt 0)
  8235. (message "No event to add")
  8236. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  8237. (defun org-agenda-todayp (date)
  8238. "Does DATE mean today, when considering `org-extend-today-until'?"
  8239. (let ((today (org-today))
  8240. (date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
  8241. date)))
  8242. (eq date today)))
  8243. (defun org-agenda-todo-yesterday (&optional arg)
  8244. "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
  8245. (interactive "P")
  8246. (let* ((hour (third (decode-time
  8247. (org-current-time))))
  8248. (org-extend-today-until (1+ hour)))
  8249. (org-agenda-todo arg)))
  8250. (provide 'org-agenda)
  8251. ;;; org-agenda.el ends here