org-agenda.el 282 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400
  1. ;;; org-agenda.el --- Dynamic task and appointment lists for Org
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 6.34b
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the code for creating and using the Agenda for Org-mode.
  25. ;;; Code:
  26. (require 'org)
  27. (eval-when-compile
  28. (require 'cl)
  29. (require 'calendar))
  30. (declare-function diary-add-to-list "diary-lib"
  31. (date string specifier &optional marker globcolor literal))
  32. (declare-function calendar-absolute-from-iso "cal-iso" (date))
  33. (declare-function calendar-astro-date-string "cal-julian" (&optional date))
  34. (declare-function calendar-bahai-date-string "cal-bahai" (&optional date))
  35. (declare-function calendar-chinese-date-string "cal-china" (&optional date))
  36. (declare-function calendar-coptic-date-string "cal-coptic" (&optional date))
  37. (declare-function calendar-ethiopic-date-string "cal-coptic" (&optional date))
  38. (declare-function calendar-french-date-string "cal-french" (&optional date))
  39. (declare-function calendar-goto-date "cal-move" (date))
  40. (declare-function calendar-hebrew-date-string "cal-hebrew" (&optional date))
  41. (declare-function calendar-islamic-date-string "cal-islam" (&optional date))
  42. (declare-function calendar-iso-date-string "cal-iso" (&optional date))
  43. (declare-function calendar-iso-from-absolute "cal-iso" (date))
  44. (declare-function calendar-julian-date-string "cal-julian" (&optional date))
  45. (declare-function calendar-mayan-date-string "cal-mayan" (&optional date))
  46. (declare-function calendar-persian-date-string "cal-persia" (&optional date))
  47. (declare-function org-datetree-find-date-create "org-datetree"
  48. (date &optional keep-restriction))
  49. (declare-function org-columns-quit "org-colview" ())
  50. (declare-function diary-date-display-form "diary-lib" (&optional type))
  51. (declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
  52. (declare-function org-habit-insert-consistency-graphs
  53. "org-habit" (&optional line))
  54. (declare-function org-is-habit-p "org-habit" (&optional pom))
  55. (declare-function org-habit-parse-todo "org-habit" (&optional pom))
  56. (declare-function org-habit-get-priority "org-habit" (habit &optional moment))
  57. (defvar calendar-mode-map)
  58. (defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
  59. (defvar org-habit-show-habits)
  60. (defvar org-habit-show-habits-only-for-today)
  61. ;; Defined somewhere in this file, but used before definition.
  62. (defvar org-agenda-buffer-name)
  63. (defvar org-agenda-overriding-header)
  64. (defvar org-agenda-title-append nil)
  65. (defvar entry)
  66. (defvar date)
  67. (defvar org-agenda-undo-list)
  68. (defvar org-agenda-pending-undo-list)
  69. (defvar original-date) ; dynamically scoped, calendar.el does scope this
  70. (defcustom org-agenda-confirm-kill 1
  71. "When set, remote killing from the agenda buffer needs confirmation.
  72. When t, a confirmation is always needed. When a number N, confirmation is
  73. only needed when the text to be killed contains more than N non-white lines."
  74. :group 'org-agenda
  75. :type '(choice
  76. (const :tag "Never" nil)
  77. (const :tag "Always" t)
  78. (integer :tag "When more than N lines")))
  79. (defcustom org-agenda-compact-blocks nil
  80. "Non-nil means, make the block agenda more compact.
  81. This is done by leaving out unnecessary lines."
  82. :group 'org-agenda
  83. :type 'boolean)
  84. (defcustom org-agenda-block-separator ?=
  85. "The separator between blocks in the agenda.
  86. If this is a string, it will be used as the separator, with a newline added.
  87. If it is a character, it will be repeated to fill the window width."
  88. :group 'org-agenda
  89. :type '(choice
  90. (character)
  91. (string)))
  92. (defgroup org-agenda-export nil
  93. "Options concerning exporting agenda views in Org-mode."
  94. :tag "Org Agenda Export"
  95. :group 'org-agenda)
  96. (defcustom org-agenda-with-colors t
  97. "Non-nil means, use colors in agenda views."
  98. :group 'org-agenda-export
  99. :type 'boolean)
  100. (defcustom org-agenda-exporter-settings nil
  101. "Alist of variable/value pairs that should be active during agenda export.
  102. This is a good place to set options for ps-print and for htmlize.
  103. Note that the way this is implemented, the values will be evaluated
  104. before assigned to the variables. So make sure to quote values you do
  105. *not* want evaluated, for example
  106. (setq org-agenda-exporter-settings
  107. '((ps-print-color-p 'black-white)))"
  108. :group 'org-agenda-export
  109. :type '(repeat
  110. (list
  111. (variable)
  112. (sexp :tag "Value"))))
  113. (defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  114. "Hook run in temporary buffer before writing it to an export file.
  115. A useful function is `org-agenda-add-entry-text'."
  116. :group 'org-agenda-export
  117. :type 'hook
  118. :options '(org-agenda-add-entry-text))
  119. (defcustom org-agenda-add-entry-text-maxlines 0
  120. "Maximum number of entry text lines to be added to agenda.
  121. This is only relevant when `org-agenda-add-entry-text' is part of
  122. `org-agenda-before-write-hook', which it is by default.
  123. When this is 0, nothing will happen. When it is greater than 0, it
  124. specifies the maximum number of lines that will be added for each entry
  125. that is listed in the agenda view.
  126. Note that this variable is not used during display, only when exporting
  127. the agenda. For agenda display, see org-agenda-entry-text-mode and the
  128. variable `org-agenda-entry-text-maxlines'."
  129. :group 'org-agenda
  130. :type 'integer)
  131. (defcustom org-agenda-add-entry-text-descriptive-links t
  132. "Non-nil means, export org-links as descriptive links in agenda added text.
  133. This variable applies to the text added to the agenda when
  134. `org-agenda-add-entry-text-maxlines' is larger than 0.
  135. When this variable nil, the URL will (also) be shown."
  136. :group 'org-agenda
  137. :type 'boolean)
  138. (defcustom org-agenda-export-html-style ""
  139. "The style specification for exported HTML Agenda files.
  140. If this variable contains a string, it will replace the default <style>
  141. section as produced by `htmlize'.
  142. Since there are different ways of setting style information, this variable
  143. needs to contain the full HTML structure to provide a style, including the
  144. surrounding HTML tags. The style specifications should include definitions
  145. the fonts used by the agenda, here is an example:
  146. <style type=\"text/css\">
  147. p { font-weight: normal; color: gray; }
  148. .org-agenda-structure {
  149. font-size: 110%;
  150. color: #003399;
  151. font-weight: 600;
  152. }
  153. .org-todo {
  154. color: #cc6666;
  155. font-weight: bold;
  156. }
  157. .org-agenda-done {
  158. color: #339933;
  159. }
  160. .org-done {
  161. color: #339933;
  162. }
  163. .title { text-align: center; }
  164. .todo, .deadline { color: red; }
  165. .done { color: green; }
  166. </style>
  167. or, if you want to keep the style in a file,
  168. <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
  169. As the value of this option simply gets inserted into the HTML <head> header,
  170. you can \"misuse\" it to also add other text to the header. However,
  171. <style>...</style> is required, if not present the variable will be ignored."
  172. :group 'org-agenda-export
  173. :group 'org-export-html
  174. :type 'string)
  175. (defgroup org-agenda-custom-commands nil
  176. "Options concerning agenda views in Org-mode."
  177. :tag "Org Agenda Custom Commands"
  178. :group 'org-agenda)
  179. (defconst org-sorting-choice
  180. '(choice
  181. (const time-up) (const time-down)
  182. (const category-keep) (const category-up) (const category-down)
  183. (const tag-down) (const tag-up)
  184. (const priority-up) (const priority-down)
  185. (const todo-state-up) (const todo-state-down)
  186. (const effort-up) (const effort-down)
  187. (const habit-up) (const habit-down)
  188. (const user-defined-up) (const user-defined-down))
  189. "Sorting choices.")
  190. (defconst org-agenda-custom-commands-local-options
  191. `(repeat :tag "Local settings for this command. Remember to quote values"
  192. (choice :tag "Setting"
  193. (list :tag "Heading for this block"
  194. (const org-agenda-overriding-header)
  195. (string :tag "Headline"))
  196. (list :tag "Files to be searched"
  197. (const org-agenda-files)
  198. (list
  199. (const :format "" quote)
  200. (repeat (file))))
  201. (list :tag "Sorting strategy"
  202. (const org-agenda-sorting-strategy)
  203. (list
  204. (const :format "" quote)
  205. (repeat
  206. ,org-sorting-choice)))
  207. (list :tag "Prefix format"
  208. (const org-agenda-prefix-format :value " %-12:c%?-12t% s")
  209. (string))
  210. (list :tag "Number of days in agenda"
  211. (const org-agenda-ndays)
  212. (integer :value 1))
  213. (list :tag "Fixed starting date"
  214. (const org-agenda-start-day)
  215. (string :value "2007-11-01"))
  216. (list :tag "Start on day of week"
  217. (const org-agenda-start-on-weekday)
  218. (choice :value 1
  219. (const :tag "Today" nil)
  220. (integer :tag "Weekday No.")))
  221. (list :tag "Include data from diary"
  222. (const org-agenda-include-diary)
  223. (boolean))
  224. (list :tag "Deadline Warning days"
  225. (const org-deadline-warning-days)
  226. (integer :value 1))
  227. (list :tag "Tags filter preset"
  228. (const org-agenda-filter-preset)
  229. (list
  230. (const :format "" quote)
  231. (repeat
  232. (string :tag "+tag or -tag"))))
  233. (list :tag "Standard skipping condition"
  234. :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
  235. (const org-agenda-skip-function)
  236. (list
  237. (const :format "" quote)
  238. (list
  239. (choice
  240. :tag "Skipping range"
  241. (const :tag "Skip entry" org-agenda-skip-entry-if)
  242. (const :tag "Skip subtree" org-agenda-skip-subtree-if))
  243. (repeat :inline t :tag "Conditions for skipping"
  244. (choice
  245. :tag "Condition type"
  246. (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
  247. (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
  248. (const :tag "scheduled" 'scheduled)
  249. (const :tag "not scheduled" 'notscheduled)
  250. (const :tag "deadline" 'deadline)
  251. (const :tag "no deadline" 'notdeadline)
  252. (const :tag "timestamp" 'timestamp)
  253. (const :tag "no timestamp" 'nottimestamp))))))
  254. (list :tag "Non-standard skipping condition"
  255. :value (org-agenda-skip-function)
  256. (const org-agenda-skip-function)
  257. (sexp :tag "Function or form (quoted!)"))
  258. (list :tag "Any variable"
  259. (variable :tag "Variable")
  260. (sexp :tag "Value (sexp)"))))
  261. "Selection of examples for agenda command settings.
  262. This will be spliced into the custom type of
  263. `org-agenda-custom-commands'.")
  264. (defcustom org-agenda-custom-commands nil
  265. "Custom commands for the agenda.
  266. These commands will be offered on the splash screen displayed by the
  267. agenda dispatcher \\[org-agenda]. Each entry is a list like this:
  268. (key desc type match settings files)
  269. key The key (one or more characters as a string) to be associated
  270. with the command.
  271. desc A description of the command, when omitted or nil, a default
  272. description is built using MATCH.
  273. type The command type, any of the following symbols:
  274. agenda The daily/weekly agenda.
  275. todo Entries with a specific TODO keyword, in all agenda files.
  276. search Entries containing search words entry or headline.
  277. tags Tags/Property/TODO match in all agenda files.
  278. tags-todo Tags/P/T match in all agenda files, TODO entries only.
  279. todo-tree Sparse tree of specific TODO keyword in *current* file.
  280. tags-tree Sparse tree with all tags matches in *current* file.
  281. occur-tree Occur sparse tree for *current* file.
  282. ... A user-defined function.
  283. match What to search for:
  284. - a single keyword for TODO keyword searches
  285. - a tags match expression for tags searches
  286. - a word search expression for text searches.
  287. - a regular expression for occur searches
  288. For all other commands, this should be the empty string.
  289. settings A list of option settings, similar to that in a let form, so like
  290. this: ((opt1 val1) (opt2 val2) ...). The values will be
  291. evaluated at the moment of execution, so quote them when needed.
  292. files A list of files file to write the produced agenda buffer to
  293. with the command `org-store-agenda-views'.
  294. If a file name ends in \".html\", an HTML version of the buffer
  295. is written out. If it ends in \".ps\", a postscript version is
  296. produced. Otherwise, only the plain text is written to the file.
  297. You can also define a set of commands, to create a composite agenda buffer.
  298. In this case, an entry looks like this:
  299. (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)
  300. where
  301. desc A description string to be displayed in the dispatcher menu.
  302. cmd An agenda command, similar to the above. However, tree commands
  303. are no allowed, but instead you can get agenda and global todo list.
  304. So valid commands for a set are:
  305. (agenda \"\" settings)
  306. (alltodo \"\" settings)
  307. (stuck \"\" settings)
  308. (todo \"match\" settings files)
  309. (search \"match\" settings files)
  310. (tags \"match\" settings files)
  311. (tags-todo \"match\" settings files)
  312. Each command can carry a list of options, and another set of options can be
  313. given for the whole set of commands. Individual command options take
  314. precedence over the general options.
  315. When using several characters as key to a command, the first characters
  316. are prefix commands. For the dispatcher to display useful information, you
  317. should provide a description for the prefix, like
  318. (setq org-agenda-custom-commands
  319. '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
  320. (\"hl\" tags \"+HOME+Lisa\")
  321. (\"hp\" tags \"+HOME+Peter\")
  322. (\"hk\" tags \"+HOME+Kim\")))"
  323. :group 'org-agenda-custom-commands
  324. :type `(repeat
  325. (choice :value ("x" "Describe command here" tags "" nil)
  326. (list :tag "Single command"
  327. (string :tag "Access Key(s) ")
  328. (option (string :tag "Description"))
  329. (choice
  330. (const :tag "Agenda" agenda)
  331. (const :tag "TODO list" alltodo)
  332. (const :tag "Search words" search)
  333. (const :tag "Stuck projects" stuck)
  334. (const :tag "Tags/Property match (all agenda files)" tags)
  335. (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
  336. (const :tag "TODO keyword search (all agenda files)" todo)
  337. (const :tag "Tags sparse tree (current buffer)" tags-tree)
  338. (const :tag "TODO keyword tree (current buffer)" todo-tree)
  339. (const :tag "Occur tree (current buffer)" occur-tree)
  340. (sexp :tag "Other, user-defined function"))
  341. (string :tag "Match (only for some commands)")
  342. ,org-agenda-custom-commands-local-options
  343. (option (repeat :tag "Export" (file :tag "Export to"))))
  344. (list :tag "Command series, all agenda files"
  345. (string :tag "Access Key(s)")
  346. (string :tag "Description ")
  347. (repeat :tag "Component"
  348. (choice
  349. (list :tag "Agenda"
  350. (const :format "" agenda)
  351. (const :tag "" :format "" "")
  352. ,org-agenda-custom-commands-local-options)
  353. (list :tag "TODO list (all keywords)"
  354. (const :format "" alltodo)
  355. (const :tag "" :format "" "")
  356. ,org-agenda-custom-commands-local-options)
  357. (list :tag "Search words"
  358. (const :format "" search)
  359. (string :tag "Match")
  360. ,org-agenda-custom-commands-local-options)
  361. (list :tag "Stuck projects"
  362. (const :format "" stuck)
  363. (const :tag "" :format "" "")
  364. ,org-agenda-custom-commands-local-options)
  365. (list :tag "Tags search"
  366. (const :format "" tags)
  367. (string :tag "Match")
  368. ,org-agenda-custom-commands-local-options)
  369. (list :tag "Tags search, TODO entries only"
  370. (const :format "" tags-todo)
  371. (string :tag "Match")
  372. ,org-agenda-custom-commands-local-options)
  373. (list :tag "TODO keyword search"
  374. (const :format "" todo)
  375. (string :tag "Match")
  376. ,org-agenda-custom-commands-local-options)
  377. (list :tag "Other, user-defined function"
  378. (symbol :tag "function")
  379. (string :tag "Match")
  380. ,org-agenda-custom-commands-local-options)))
  381. (repeat :tag "Settings for entire command set"
  382. (list (variable :tag "Any variable")
  383. (sexp :tag "Value")))
  384. (option (repeat :tag "Export" (file :tag "Export to"))))
  385. (cons :tag "Prefix key documentation"
  386. (string :tag "Access Key(s)")
  387. (string :tag "Description ")))))
  388. (defcustom org-agenda-query-register ?o
  389. "The register holding the current query string.
  390. The purpose of this is that if you construct a query string interactively,
  391. you can then use it to define a custom command."
  392. :group 'org-agenda-custom-commands
  393. :type 'character)
  394. (defcustom org-stuck-projects
  395. '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  396. "How to identify stuck projects.
  397. This is a list of four items:
  398. 1. A tags/todo/property matcher string that is used to identify a project.
  399. See the manual for a description of tag and property searches.
  400. The entire tree below a headline matched by this is considered one project.
  401. 2. A list of TODO keywords identifying non-stuck projects.
  402. If the project subtree contains any headline with one of these todo
  403. keywords, the project is considered to be not stuck. If you specify
  404. \"*\" as a keyword, any TODO keyword will mark the project unstuck.
  405. 3. A list of tags identifying non-stuck projects.
  406. If the project subtree contains any headline with one of these tags,
  407. the project is considered to be not stuck. If you specify \"*\" as
  408. a tag, any tag will mark the project unstuck. Note that this is about
  409. the explicit presence of a tag somewhere in the subtree, inherited
  410. tags to not count here. If inherited tags make a project not stuck,
  411. use \"-TAG\" in the tags part of the matcher under (1.) above.
  412. 4. An arbitrary regular expression matching non-stuck projects.
  413. If the project turns out to be not stuck, search continues also in the
  414. subtree to see if any of the subtasks have project status.
  415. See also the variable `org-tags-match-list-sublevels' which applies
  416. to projects matched by this search as well.
  417. After defining this variable, you may use \\[org-agenda-list-stuck-projects]
  418. or `C-c a #' to produce the list."
  419. :group 'org-agenda-custom-commands
  420. :type '(list
  421. (string :tag "Tags/TODO match to identify a project")
  422. (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
  423. (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
  424. (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))
  425. (defcustom org-agenda-filter-effort-default-operator "<"
  426. "The default operator for effort estimate filtering.
  427. If you select an effort estimate limit without first pressing an operator,
  428. this one will be used."
  429. :group 'org-agenda-custom-commands
  430. :type '(choice (const :tag "less or equal" "<")
  431. (const :tag "greater or equal"">")
  432. (const :tag "equal" "=")))
  433. (defgroup org-agenda-skip nil
  434. "Options concerning skipping parts of agenda files."
  435. :tag "Org Agenda Skip"
  436. :group 'org-agenda)
  437. (defgroup org-agenda-daily/weekly nil
  438. "Options concerning the daily/weekly agenda."
  439. :tag "Org Agenda Daily/Weekly"
  440. :group 'org-agenda)
  441. (defgroup org-agenda-todo-list nil
  442. "Options concerning the global todo list agenda view."
  443. :tag "Org Agenda Todo List"
  444. :group 'org-agenda)
  445. (defgroup org-agenda-match-view nil
  446. "Options concerning the general tags/property/todo match agenda view."
  447. :tag "Org Agenda Match View"
  448. :group 'org-agenda)
  449. (defgroup org-agenda-search-view nil
  450. "Options concerning the general tags/property/todo match agenda view."
  451. :tag "Org Agenda Match View"
  452. :group 'org-agenda)
  453. (defvar org-agenda-archives-mode nil
  454. "Non-nil means, the agenda will include archived items.
  455. If this is the symbol `trees', trees in the selected agenda scope
  456. that are marked with the ARCHIVE tag will be included anyway. When this is
  457. t, also all archive files associated with the current selection of agenda
  458. files will be included.")
  459. (defcustom org-agenda-skip-comment-trees t
  460. "Non-nil means, skip trees that start with the COMMENT keyword.
  461. When nil, these trees are also scanned by agenda commands."
  462. :group 'org-agenda-skip
  463. :type 'boolean)
  464. (defcustom org-agenda-todo-list-sublevels t
  465. "Non-nil means, check also the sublevels of a TODO entry for TODO entries.
  466. When nil, the sublevels of a TODO entry are not checked, resulting in
  467. potentially much shorter TODO lists."
  468. :group 'org-agenda-skip
  469. :group 'org-agenda-todo-list
  470. :type 'boolean)
  471. (defcustom org-agenda-todo-ignore-with-date nil
  472. "Non-nil means, don't show entries with a date in the global todo list.
  473. You can use this if you prefer to mark mere appointments with a TODO keyword,
  474. but don't want them to show up in the TODO list.
  475. When this is set, it also covers deadlines and scheduled items, the settings
  476. of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
  477. will be ignored.
  478. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  479. :group 'org-agenda-skip
  480. :group 'org-agenda-todo-list
  481. :type 'boolean)
  482. (defcustom org-agenda-todo-ignore-scheduled nil
  483. "Non-nil means, don't show scheduled entries in the global todo list.
  484. The idea behind this is that by scheduling it, you have already taken care
  485. of this item.
  486. See also `org-agenda-todo-ignore-with-date'.
  487. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  488. :group 'org-agenda-skip
  489. :group 'org-agenda-todo-list
  490. :type 'boolean)
  491. (defcustom org-agenda-todo-ignore-deadlines nil
  492. "Non-nil means, don't show near deadline entries in the global todo list.
  493. Near means closer than `org-deadline-warning-days' days.
  494. The idea behind this is that such items will appear in the agenda anyway.
  495. See also `org-agenda-todo-ignore-with-date'.
  496. See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  497. :group 'org-agenda-skip
  498. :group 'org-agenda-todo-list
  499. :type 'boolean)
  500. (defcustom org-agenda-tags-todo-honor-ignore-options nil
  501. "Non-nil means, honor todo-list ...ignore options also in tags-todo search.
  502. The variables
  503. `org-agenda-todo-ignore-with-date',
  504. `org-agenda-todo-ignore-scheduled'
  505. `org-agenda-todo-ignore-deadlines'
  506. make the global TODO list skip entries that have time stamps of certain
  507. kinds. If this option is set, the same options will also apply for the
  508. tags-todo search, which is the general tags/property matcher
  509. restricted to unfinished TODO entries only."
  510. :group 'org-agenda-skip
  511. :group 'org-agenda-todo-list
  512. :group 'org-agenda-match-view
  513. :type 'boolean)
  514. (defcustom org-agenda-skip-scheduled-if-done nil
  515. "Non-nil means don't show scheduled items in agenda when they are done.
  516. This is relevant for the daily/weekly agenda, not for the TODO list. And
  517. it applies only to the actual date of the scheduling. Warnings about
  518. an item with a past scheduling dates are always turned off when the item
  519. is DONE."
  520. :group 'org-agenda-skip
  521. :group 'org-agenda-daily/weekly
  522. :type 'boolean)
  523. (defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  524. "Non-nil means skip scheduling line if same entry shows because of deadline.
  525. In the agenda of today, an entry can show up multiple times because
  526. it is both scheduled and has a nearby deadline, and maybe a plain time
  527. stamp as well.
  528. When this variable is t, then only the deadline is shown and the fact that
  529. the entry is scheduled today or was scheduled previously is not shown.
  530. When this variable is nil, the entry will be shown several times. When
  531. the variable is the symbol `not-today', then skip scheduled previously,
  532. but not scheduled today."
  533. :group 'org-agenda-skip
  534. :group 'org-agenda-daily/weekly
  535. :type '(choice
  536. (const :tag "Never" nil)
  537. (const :tag "Always" t)
  538. (const :tag "Not when scheduled today" not-today)))
  539. (defcustom org-agenda-skip-deadline-if-done nil
  540. "Non-nil means don't show deadlines when the corresponding item is done.
  541. When nil, the deadline is still shown and should give you a happy feeling.
  542. This is relevant for the daily/weekly agenda. And it applied only to the
  543. actually date of the deadline. Warnings about approaching and past-due
  544. deadlines are always turned off when the item is DONE."
  545. :group 'org-agenda-skip
  546. :group 'org-agenda-daily/weekly
  547. :type 'boolean)
  548. (defcustom org-agenda-skip-additional-timestamps-same-entry t
  549. "When nil, multiple same-day timestamps in entry make multiple agenda lines.
  550. When non-nil, after the search for timestamps has matched once in an
  551. entry, the rest of the entry will not be searched."
  552. :group 'org-agenda-skip
  553. :type 'boolean)
  554. (defcustom org-agenda-skip-timestamp-if-done nil
  555. "Non-nil means don't select item by timestamp or -range if it is DONE."
  556. :group 'org-agenda-skip
  557. :group 'org-agenda-daily/weekly
  558. :type 'boolean)
  559. (defcustom org-agenda-dim-blocked-tasks t
  560. "Non-nil means, dim blocked tasks in the agenda display.
  561. This causes some overhead during agenda construction, but if you
  562. have turned on `org-enforce-todo-dependencies',
  563. `org-enforce-todo-checkbox-dependencies', or any other blocking
  564. mechanism, this will create useful feedback in the agenda.
  565. Instead of t, this variable can also have the value `invisible'.
  566. Then blocked tasks will be invisible and only become visible when
  567. they become unblocked. An exemption to this behavior is when a task is
  568. blocked because of unchecked checkboxes below it. Since checkboxes do
  569. not show up in the agenda views, making this task invisible you remove any
  570. trace from agenda views that there is something to do. Therefore, a task
  571. that is blocked because of checkboxes will never be made invisible, it
  572. will only be dimmed."
  573. :group 'org-agenda-daily/weekly
  574. :group 'org-agenda-todo-list
  575. :type '(choice
  576. (const :tag "Do not dim" nil)
  577. (const :tag "Dim to a grey face" t)
  578. (const :tag "Make invisible" invisible)))
  579. (defcustom org-timeline-show-empty-dates 3
  580. "Non-nil means, `org-timeline' also shows dates without an entry.
  581. When nil, only the days which actually have entries are shown.
  582. When t, all days between the first and the last date are shown.
  583. When an integer, show also empty dates, but if there is a gap of more than
  584. N days, just insert a special line indicating the size of the gap."
  585. :group 'org-agenda-skip
  586. :type '(choice
  587. (const :tag "None" nil)
  588. (const :tag "All" t)
  589. (integer :tag "at most")))
  590. (defgroup org-agenda-startup nil
  591. "Options concerning initial settings in the Agenda in Org Mode."
  592. :tag "Org Agenda Startup"
  593. :group 'org-agenda)
  594. (defcustom org-finalize-agenda-hook nil
  595. "Hook run just before displaying an agenda buffer."
  596. :group 'org-agenda-startup
  597. :type 'hook)
  598. (defcustom org-agenda-mouse-1-follows-link nil
  599. "Non-nil means, mouse-1 on a link will follow the link in the agenda.
  600. A longer mouse click will still set point. Does not work on XEmacs.
  601. Needs to be set before org.el is loaded."
  602. :group 'org-agenda-startup
  603. :type 'boolean)
  604. (defcustom org-agenda-start-with-follow-mode nil
  605. "The initial value of follow-mode in a newly created agenda window."
  606. :group 'org-agenda-startup
  607. :type 'boolean)
  608. (defcustom org-agenda-show-outline-path t
  609. "Non-il means, show outline path in echo area after line motion."
  610. :group 'org-agenda-startup
  611. :type 'boolean)
  612. (defcustom org-agenda-start-with-entry-text-mode nil
  613. "The initial value of entry-text-mode in a newly created agenda window."
  614. :group 'org-agenda-startup
  615. :type 'boolean)
  616. (defcustom org-agenda-entry-text-maxlines 5
  617. "Number of text lines to be added when `E' is pressed in the agenda.
  618. Note that this variable only used during agenda display. Add add entry text
  619. when exporting the agenda, configure the variable
  620. `org-agenda-add-entry-ext-maxlines'."
  621. :group 'org-agenda
  622. :type 'integer)
  623. (defcustom org-agenda-entry-text-exclude-regexps nil
  624. "List of regular expressions to clean up entry text.
  625. The complete matches of all regular expressions in this list will be
  626. removed from entry text before it is shown in the agenda."
  627. :group 'org-agenda
  628. :type '(repeat (regexp)))
  629. (defvar org-agenda-entry-text-cleanup-hook nil
  630. "Hook that is run after basic cleanup of entry text to be shown in agenda.
  631. This cleanup is done in a temporary buffer, so the function may inspect and
  632. change the entire buffer.
  633. Some default stuff like drawers and scheduling/deadline dates will already
  634. have been removed when this is called, as will any matches for regular
  635. expressions listed in `org-agenda-entry-text-exclude-regexps'.")
  636. (defvar org-agenda-include-inactive-timestamps nil
  637. "Non-nil means, include inactive time stamps in agenda and timeline.")
  638. (defgroup org-agenda-windows nil
  639. "Options concerning the windows used by the Agenda in Org Mode."
  640. :tag "Org Agenda Windows"
  641. :group 'org-agenda)
  642. (defcustom org-agenda-window-setup 'reorganize-frame
  643. "How the agenda buffer should be displayed.
  644. Possible values for this option are:
  645. current-window Show agenda in the current window, keeping all other windows.
  646. other-window Use `switch-to-buffer-other-window' to display agenda.
  647. reorganize-frame Show only two windows on the current frame, the current
  648. window and the agenda.
  649. other-frame Use `switch-to-buffer-other-frame' to display agenda.
  650. Also, when exiting the agenda, kill that frame.
  651. See also the variable `org-agenda-restore-windows-after-quit'."
  652. :group 'org-agenda-windows
  653. :type '(choice
  654. (const current-window)
  655. (const other-frame)
  656. (const other-window)
  657. (const reorganize-frame)))
  658. (defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  659. "The min and max height of the agenda window as a fraction of frame height.
  660. The value of the variable is a cons cell with two numbers between 0 and 1.
  661. It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  662. :group 'org-agenda-windows
  663. :type '(cons (number :tag "Minimum") (number :tag "Maximum")))
  664. (defcustom org-agenda-restore-windows-after-quit nil
  665. "Non-nil means, restore window configuration open exiting agenda.
  666. Before the window configuration is changed for displaying the agenda,
  667. the current status is recorded. When the agenda is exited with
  668. `q' or `x' and this option is set, the old state is restored. If
  669. `org-agenda-window-setup' is `other-frame', the value of this
  670. option will be ignored."
  671. :group 'org-agenda-windows
  672. :type 'boolean)
  673. (defcustom org-agenda-ndays 7
  674. "Number of days to include in overview display.
  675. Should be 1 or 7.
  676. Custom commands can set this variable in the options section."
  677. :group 'org-agenda-daily/weekly
  678. :type 'integer)
  679. (defcustom org-agenda-start-on-weekday 1
  680. "Non-nil means, start the overview always on the specified weekday.
  681. 0 denotes Sunday, 1 denotes Monday etc.
  682. When nil, always start on the current day.
  683. Custom commands can set this variable in the options section."
  684. :group 'org-agenda-daily/weekly
  685. :type '(choice (const :tag "Today" nil)
  686. (integer :tag "Weekday No.")))
  687. (defcustom org-agenda-show-all-dates t
  688. "Non-nil means, `org-agenda' shows every day in the selected range.
  689. When nil, only the days which actually have entries are shown."
  690. :group 'org-agenda-daily/weekly
  691. :type 'boolean)
  692. (defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  693. "Format string for displaying dates in the agenda.
  694. Used by the daily/weekly agenda and by the timeline. This should be
  695. a format string understood by `format-time-string', or a function returning
  696. the formatted date as a string. The function must take a single argument,
  697. a calendar-style date list like (month day year)."
  698. :group 'org-agenda-daily/weekly
  699. :type '(choice
  700. (string :tag "Format string")
  701. (function :tag "Function")))
  702. (defun org-agenda-format-date-aligned (date)
  703. "Format a date string for display in the daily/weekly agenda, or timeline.
  704. This function makes sure that dates are aligned for easy reading."
  705. (require 'cal-iso)
  706. (let* ((dayname (calendar-day-name date))
  707. (day (cadr date))
  708. (day-of-week (calendar-day-of-week date))
  709. (month (car date))
  710. (monthname (calendar-month-name month))
  711. (year (nth 2 date))
  712. (iso-week (org-days-to-iso-week
  713. (calendar-absolute-from-gregorian date)))
  714. (weekyear (cond ((and (= month 1) (>= iso-week 52))
  715. (1- year))
  716. ((and (= month 12) (<= iso-week 1))
  717. (1+ year))
  718. (t year)))
  719. (weekstring (if (= day-of-week 1)
  720. (format " W%02d" iso-week)
  721. "")))
  722. (format "%-10s %2d %s %4d%s"
  723. dayname day monthname year weekstring)))
  724. (defcustom org-agenda-weekend-days '(6 0)
  725. "Which days are weekend?
  726. These days get the special face `org-agenda-date-weekend' in the agenda
  727. and timeline buffers."
  728. :group 'org-agenda-daily/weekly
  729. :type '(set :greedy t
  730. (const :tag "Monday" 1)
  731. (const :tag "Tuesday" 2)
  732. (const :tag "Wednesday" 3)
  733. (const :tag "Thursday" 4)
  734. (const :tag "Friday" 5)
  735. (const :tag "Saturday" 6)
  736. (const :tag "Sunday" 0)))
  737. (defcustom org-agenda-include-diary nil
  738. "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
  739. Custom commands can set this variable in the options section."
  740. :group 'org-agenda-daily/weekly
  741. :type 'boolean)
  742. (defcustom org-agenda-include-all-todo nil
  743. "Set means weekly/daily agenda will always contain all TODO entries.
  744. The TODO entries will be listed at the top of the agenda, before
  745. the entries for specific days.
  746. This option is deprecated, it is better to define a block agenda instead."
  747. :group 'org-agenda-daily/weekly
  748. :type 'boolean)
  749. (defcustom org-agenda-repeating-timestamp-show-all t
  750. "Non-nil means, show all occurrences of a repeating stamp in the agenda.
  751. When nil, only one occurrence is shown, either today or the
  752. nearest into the future."
  753. :group 'org-agenda-daily/weekly
  754. :type 'boolean)
  755. (defcustom org-scheduled-past-days 10000
  756. "No. of days to continue listing scheduled items that are not marked DONE.
  757. When an item is scheduled on a date, it shows up in the agenda on this
  758. day and will be listed until it is marked done for the number of days
  759. given here."
  760. :group 'org-agenda-daily/weekly
  761. :type 'integer)
  762. (defcustom org-agenda-log-mode-items '(closed clock)
  763. "List of items that should be shown in agenda log mode.
  764. This list may contain the following symbols:
  765. closed Show entries that have been closed on that day.
  766. clock Show entries that have received clocked time on that day.
  767. state Show all logged state changes.
  768. Note that instead of changing this variable, you can also press `C-u l' in
  769. the agenda to display all available LOG items temporarily."
  770. :group 'org-agenda-daily/weekly
  771. :type '(set :greedy t (const closed) (const clock) (const state)))
  772. (defcustom org-agenda-log-mode-add-notes t
  773. "Non-nil means, add first line of notes to log entries in agenda views.
  774. If a log item like a state change or a clock entry is associated with
  775. notes, the first line of these notes will be added to the entry in the
  776. agenda display."
  777. :group 'org-agenda-daily/weekly
  778. :type 'boolean)
  779. (defcustom org-agenda-start-with-log-mode nil
  780. "The initial value of log-mode in a newly created agenda window."
  781. :group 'org-agenda-startup
  782. :group 'org-agenda-daily/weekly
  783. :type 'boolean)
  784. (defcustom org-agenda-start-with-clockreport-mode nil
  785. "The initial value of clockreport-mode in a newly created agenda window."
  786. :group 'org-agenda-startup
  787. :group 'org-agenda-daily/weekly
  788. :type 'boolean)
  789. (defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  790. "Property list with parameters for the clocktable in clockreport mode.
  791. This is the display mode that shows a clock table in the daily/weekly
  792. agenda, the properties for this dynamic block can be set here.
  793. The usual clocktable parameters are allowed here, but you cannot set
  794. the properties :name, :tstart, :tend, :block, and :scope - these will
  795. be overwritten to make sure the content accurately reflects the
  796. current display in the agenda."
  797. :group 'org-agenda-daily/weekly
  798. :type 'plist)
  799. (defcustom org-agenda-search-view-always-boolean nil
  800. "Non-nil means, the search string is interpreted as individual parts.
  801. The search string for search view can either be interpreted as a phrase,
  802. or as a list of snippets that define a boolean search for a number of
  803. strings.
  804. When this is non-nil, the string will be split on whitespace, and each
  805. snippet will be searched individually, and all must match in order to
  806. select an entry. A snippet is then a single string of non-white
  807. characters, or a string in double quotes, or a regexp in {} braces.
  808. If a snippet is preceeded by \"-\", the snippet must *not* match.
  809. \"+\" is syntactic sugar for positive selection. Each snippet may
  810. be found as a full word or a partial word, but see the variable
  811. `org-agenda-search-view-force-full-words'.
  812. When this is nil, search will look for the entire search phrase as one,
  813. with each space character matching any amount of whitespace, including
  814. line breaks.
  815. Even when this is nil, you can still switch to Boolean search dynamically
  816. by preceeding the first snippet with \"+\" or \"-\". If the first snippet
  817. is a regexp marked with braces like \"{abc}\", this will also switch to
  818. boolean search."
  819. :group 'org-agenda-search-view
  820. :type 'boolean)
  821. (if (fboundp 'defvaralias)
  822. (defvaralias 'org-agenda-search-view-search-words-only
  823. 'org-agenda-search-view-always-boolean))
  824. (defcustom org-agenda-search-view-force-full-words nil
  825. "Non-nil me
  826. ans, search words must be matches as complete words.
  827. When nil, they may also match part of a word."
  828. :group 'org-agenda-search-view
  829. :type 'boolean)
  830. (defgroup org-agenda-time-grid nil
  831. "Options concerning the time grid in the Org-mode Agenda."
  832. :tag "Org Agenda Time Grid"
  833. :group 'org-agenda)
  834. (defcustom org-agenda-search-headline-for-time t
  835. "Non-nil means, search headline for a time-of-day.
  836. If the headline contains a time-of-day in one format or another, it will
  837. be used to sort the entry into the time sequence of items for a day.
  838. Some people have time stamps in the headline that refer to the creation
  839. time or so, and then this produces an unwanted side effect. If this is
  840. the case for your, use this variable to turn off searching the headline
  841. for a time."
  842. :group 'org-agenda-time-grid
  843. :type 'boolean)
  844. (defcustom org-agenda-use-time-grid t
  845. "Non-nil means, show a time grid in the agenda schedule.
  846. A time grid is a set of lines for specific times (like every two hours between
  847. 8:00 and 20:00). The items scheduled for a day at specific times are
  848. sorted in between these lines.
  849. For details about when the grid will be shown, and what it will look like, see
  850. the variable `org-agenda-time-grid'."
  851. :group 'org-agenda-time-grid
  852. :type 'boolean)
  853. (defcustom org-agenda-time-grid
  854. '((daily today require-timed)
  855. "----------------"
  856. (800 1000 1200 1400 1600 1800 2000))
  857. "The settings for time grid for agenda display.
  858. This is a list of three items. The first item is again a list. It contains
  859. symbols specifying conditions when the grid should be displayed:
  860. daily if the agenda shows a single day
  861. weekly if the agenda shows an entire week
  862. today show grid on current date, independent of daily/weekly display
  863. require-timed show grid only if at least one item has a time specification
  864. The second item is a string which will be placed behind the grid time.
  865. The third item is a list of integers, indicating the times that should have
  866. a grid line."
  867. :group 'org-agenda-time-grid
  868. :type
  869. '(list
  870. (set :greedy t :tag "Grid Display Options"
  871. (const :tag "Show grid in single day agenda display" daily)
  872. (const :tag "Show grid in weekly agenda display" weekly)
  873. (const :tag "Always show grid for today" today)
  874. (const :tag "Show grid only if any timed entries are present"
  875. require-timed)
  876. (const :tag "Skip grid times already present in an entry"
  877. remove-match))
  878. (string :tag "Grid String")
  879. (repeat :tag "Grid Times" (integer :tag "Time"))))
  880. (defgroup org-agenda-sorting nil
  881. "Options concerning sorting in the Org-mode Agenda."
  882. :tag "Org Agenda Sorting"
  883. :group 'org-agenda)
  884. (defcustom org-agenda-sorting-strategy
  885. '((agenda habit-down time-up priority-down category-keep)
  886. (todo priority-down category-keep)
  887. (tags priority-down category-keep)
  888. (search category-keep))
  889. "Sorting structure for the agenda items of a single day.
  890. This is a list of symbols which will be used in sequence to determine
  891. if an entry should be listed before another entry. The following
  892. symbols are recognized:
  893. time-up Put entries with time-of-day indications first, early first
  894. time-down Put entries with time-of-day indications first, late first
  895. category-keep Keep the default order of categories, corresponding to the
  896. sequence in `org-agenda-files'.
  897. category-up Sort alphabetically by category, A-Z.
  898. category-down Sort alphabetically by category, Z-A.
  899. tag-up Sort alphabetically by last tag, A-Z.
  900. tag-down Sort alphabetically by last tag, Z-A.
  901. priority-up Sort numerically by priority, high priority last.
  902. priority-down Sort numerically by priority, high priority first.
  903. todo-state-up Sort by todo state, tasks that are done last.
  904. todo-state-down Sort by todo state, tasks that are done first.
  905. effort-up Sort numerically by estimated effort, high effort last.
  906. effort-down Sort numerically by estimated effort, high effort first.
  907. user-defined-up Sort according to `org-agenda-cmp-user-defined', high last.
  908. user-defined-down Sort according to `org-agenda-cmp-user-defined', high first.
  909. habit-up Put entries that are habits first
  910. habit-down Put entries that are habits last
  911. The different possibilities will be tried in sequence, and testing stops
  912. if one comparison returns a \"not-equal\". For example, the default
  913. '(time-up category-keep priority-down)
  914. means: Pull out all entries having a specified time of day and sort them,
  915. in order to make a time schedule for the current day the first thing in the
  916. agenda listing for the day. Of the entries without a time indication, keep
  917. the grouped in categories, don't sort the categories, but keep them in
  918. the sequence given in `org-agenda-files'. Within each category sort by
  919. priority.
  920. Leaving out `category-keep' would mean that items will be sorted across
  921. categories by priority.
  922. Instead of a single list, this can also be a set of list for specific
  923. contents, with a context symbol in the car of the list, any of
  924. `agenda', `todo', `tags', `search' for the corresponding agenda views.
  925. Custom commands can bind this variable in the options section."
  926. :group 'org-agenda-sorting
  927. :type `(choice
  928. (repeat :tag "General" ,org-sorting-choice)
  929. (list :tag "Individually"
  930. (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
  931. (repeat ,org-sorting-choice))
  932. (cons (const :tag "Strategy for TODO lists" todo)
  933. (repeat ,org-sorting-choice))
  934. (cons (const :tag "Strategy for Tags matches" tags)
  935. (repeat ,org-sorting-choice))
  936. (cons (const :tag "Strategy for search matches" search)
  937. (repeat ,org-sorting-choice)))))
  938. (defcustom org-agenda-cmp-user-defined nil
  939. "A function to define the comparison `user-defined'.
  940. This function must receive two arguments, agenda entry a and b.
  941. If a>b, return +1. If a<b, return -1. If they are equal as seen by
  942. the user comparison, return nil.
  943. When this is defined, you can make `user-defined-up' and `user-defined-down'
  944. part of an agenda sorting strategy."
  945. :group 'org-agenda-sorting
  946. :type 'symbol)
  947. (defcustom org-sort-agenda-notime-is-late t
  948. "Non-nil means, items without time are considered late.
  949. This is only relevant for sorting. When t, items which have no explicit
  950. time like 15:30 will be considered as 99:01, i.e. later than any items which
  951. do have a time. When nil, the default time is before 0:00. You can use this
  952. option to decide if the schedule for today should come before or after timeless
  953. agenda entries."
  954. :group 'org-agenda-sorting
  955. :type 'boolean)
  956. (defcustom org-sort-agenda-noeffort-is-high t
  957. "Non-nil means, items without effort estimate are sorted as high effort.
  958. This also applies when filtering an agenda view with respect to the
  959. < or > effort operator. Then, tasks with no effort defined will be treated
  960. as tasks with high effort.
  961. When nil, such items are sorted as 0 minutes effort."
  962. :group 'org-agenda-sorting
  963. :type 'boolean)
  964. (defgroup org-agenda-line-format nil
  965. "Options concerning the entry prefix in the Org-mode agenda display."
  966. :tag "Org Agenda Line Format"
  967. :group 'org-agenda)
  968. (defcustom org-agenda-prefix-format
  969. '((agenda . " %-12:c%?-12t% s")
  970. (timeline . " % s")
  971. (todo . " %-12:c")
  972. (tags . " %-12:c")
  973. (search . " %-12:c"))
  974. "Format specifications for the prefix of items in the agenda views.
  975. An alist with four entries, for the different agenda types. The keys to the
  976. sublists are `agenda', `timeline', `todo', and `tags'. The values
  977. are format strings.
  978. This format works similar to a printf format, with the following meaning:
  979. %c the category of the item, \"Diary\" for entries from the diary, or
  980. as given by the CATEGORY keyword or derived from the file name.
  981. %T the *last* tag of the item. Last because inherited tags come
  982. first in the list.
  983. %t the time-of-day specification if one applies to the entry, in the
  984. format HH:MM
  985. %s Scheduling/Deadline information, a short string
  986. All specifiers work basically like the standard `%s' of printf, but may
  987. contain two additional characters: A question mark just after the `%' and
  988. a whitespace/punctuation character just before the final letter.
  989. If the first character after `%' is a question mark, the entire field
  990. will only be included if the corresponding value applies to the
  991. current entry. This is useful for fields which should have fixed
  992. width when present, but zero width when absent. For example,
  993. \"%?-12t\" will result in a 12 character time field if a time of the
  994. day is specified, but will completely disappear in entries which do
  995. not contain a time.
  996. If there is punctuation or whitespace character just before the final
  997. format letter, this character will be appended to the field value if
  998. the value is not empty. For example, the format \"%-12:c\" leads to
  999. \"Diary: \" if the category is \"Diary\". If the category were be
  1000. empty, no additional colon would be inserted.
  1001. The default value of this option is \" %-12:c%?-12t% s\", meaning:
  1002. - Indent the line with two space characters
  1003. - Give the category in a 12 chars wide field, padded with whitespace on
  1004. the right (because of `-'). Append a colon if there is a category
  1005. (because of `:').
  1006. - If there is a time-of-day, put it into a 12 chars wide field. If no
  1007. time, don't put in an empty field, just skip it (because of '?').
  1008. - Finally, put the scheduling information and append a whitespace.
  1009. As another example, if you don't want the time-of-day of entries in
  1010. the prefix, you could use:
  1011. (setq org-agenda-prefix-format \" %-11:c% s\")
  1012. See also the variables `org-agenda-remove-times-when-in-prefix' and
  1013. `org-agenda-remove-tags'.
  1014. Custom commands can set this variable in the options section."
  1015. :type '(choice
  1016. (string :tag "General format")
  1017. (list :greedy t :tag "View dependent"
  1018. (cons (const agenda) (string :tag "Format"))
  1019. (cons (const timeline) (string :tag "Format"))
  1020. (cons (const todo) (string :tag "Format"))
  1021. (cons (const tags) (string :tag "Format"))
  1022. (cons (const search) (string :tag "Format"))))
  1023. :group 'org-agenda-line-format)
  1024. (defvar org-prefix-format-compiled nil
  1025. "The compiled version of the most recently used prefix format.
  1026. See the variable `org-agenda-prefix-format'.")
  1027. (defcustom org-agenda-todo-keyword-format "%-1s"
  1028. "Format for the TODO keyword in agenda lines.
  1029. Set this to something like \"%-12s\" if you want all TODO keywords
  1030. to occupy a fixed space in the agenda display."
  1031. :group 'org-agenda-line-format
  1032. :type 'string)
  1033. (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  1034. "Text preceding timerange entries in the agenda view.
  1035. This is a list with two strings. The first applies when the range
  1036. is entirely on one day. The second applies if the range spans several days.
  1037. The strings may have two \"%d\" format specifiers which will be filled
  1038. with the sequence number of the days, and the total number of days in the
  1039. range, respectively."
  1040. :group 'org-agenda-line-format
  1041. :type '(list
  1042. (string :tag "Deadline today ")
  1043. (choice :tag "Deadline relative"
  1044. (string :tag "Format string")
  1045. (function))))
  1046. (defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  1047. "Text preceeding scheduled items in the agenda view.
  1048. This is a list with two strings. The first applies when the item is
  1049. scheduled on the current day. The second applies when it has been scheduled
  1050. previously, it may contain a %d indicating that this is the nth time that
  1051. this item is scheduled, due to automatic rescheduling of unfinished items
  1052. for the following day. So this number is one larger than the number of days
  1053. that passed since this item was scheduled first."
  1054. :group 'org-agenda-line-format
  1055. :type '(list
  1056. (string :tag "Scheduled today ")
  1057. (string :tag "Scheduled previously")))
  1058. (defcustom org-agenda-inactive-leader "["
  1059. "Text preceeding item pulled into the agenda by inactive time stamps.
  1060. These entries are added to the agenda when pressing \"[\"."
  1061. :group 'org-agenda-line-format
  1062. :type '(list
  1063. (string :tag "Scheduled today ")
  1064. (string :tag "Scheduled previously")))
  1065. (defcustom org-agenda-deadline-leaders '("Deadline: " "In %3d d.: ")
  1066. "Text preceeding deadline items in the agenda view.
  1067. This is a list with two strings. The first applies when the item has its
  1068. deadline on the current day. The second applies when it is in the past or
  1069. in the future, it may contain %d to capture how many days away the deadline
  1070. is (was)."
  1071. :group 'org-agenda-line-format
  1072. :type '(list
  1073. (string :tag "Deadline today ")
  1074. (choice :tag "Deadline relative"
  1075. (string :tag "Format string")
  1076. (function))))
  1077. (defcustom org-agenda-remove-times-when-in-prefix t
  1078. "Non-nil means, remove duplicate time specifications in agenda items.
  1079. When the format `org-agenda-prefix-format' contains a `%t' specifier, a
  1080. time-of-day specification in a headline or diary entry is extracted and
  1081. placed into the prefix. If this option is non-nil, the original specification
  1082. \(a timestamp or -range, or just a plain time(range) specification like
  1083. 11:30-4pm) will be removed for agenda display. This makes the agenda less
  1084. cluttered.
  1085. The option can be t or nil. It may also be the symbol `beg', indicating
  1086. that the time should only be removed what it is located at the beginning of
  1087. the headline/diary entry."
  1088. :group 'org-agenda-line-format
  1089. :type '(choice
  1090. (const :tag "Always" t)
  1091. (const :tag "Never" nil)
  1092. (const :tag "When at beginning of entry" beg)))
  1093. (defcustom org-agenda-default-appointment-duration nil
  1094. "Default duration for appointments that only have a starting time.
  1095. When nil, no duration is specified in such cases.
  1096. When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  1097. :group 'org-agenda-line-format
  1098. :type '(choice
  1099. (integer :tag "Minutes")
  1100. (const :tag "No default duration")))
  1101. (defcustom org-agenda-show-inherited-tags t
  1102. "Non-nil means, show inherited tags in each agenda line."
  1103. :group 'org-agenda-line-format
  1104. :type 'boolean)
  1105. (defcustom org-agenda-hide-tags-regexp nil
  1106. "Regular expression used to filter away specific tags in agenda views.
  1107. This means that these tags will be present, but not be shown in the agenda
  1108. line. Secondayt filltering will still work on the hidden tags.
  1109. Nil means don't hide any tags."
  1110. :group 'org-agenda-line-format
  1111. :type '(choice
  1112. (const :tag "Hide none" nil)
  1113. (string :tag "Regexp ")))
  1114. (defcustom org-agenda-remove-tags nil
  1115. "Non-nil means, remove the tags from the headline copy in the agenda.
  1116. When this is the symbol `prefix', only remove tags when
  1117. `org-agenda-prefix-format' contains a `%T' specifier."
  1118. :group 'org-agenda-line-format
  1119. :type '(choice
  1120. (const :tag "Always" t)
  1121. (const :tag "Never" nil)
  1122. (const :tag "When prefix format contains %T" prefix)))
  1123. (if (fboundp 'defvaralias)
  1124. (defvaralias 'org-agenda-remove-tags-when-in-prefix
  1125. 'org-agenda-remove-tags))
  1126. (defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  1127. "Shift tags in agenda items to this column.
  1128. If this number is positive, it specifies the column. If it is negative,
  1129. it means that the tags should be flushright to that column. For example,
  1130. -80 works well for a normal 80 character screen."
  1131. :group 'org-agenda-line-format
  1132. :type 'integer)
  1133. (if (fboundp 'defvaralias)
  1134. (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))
  1135. (defcustom org-agenda-fontify-priorities 'cookies
  1136. "Non-nil means, highlight low and high priorities in agenda.
  1137. When t, the highest priority entries are bold, lowest priority italic.
  1138. However, settings in org-priority-faces will overrule these faces.
  1139. When this variable is the symbol `cookies', only fontify the
  1140. cookies, not the entire task.
  1141. This may also be an association list of priority faces, whose
  1142. keys are the character values of `org-highest-priority',
  1143. `org-default-priority', and `org-lowest-priority' (the default values
  1144. are ?A, ?B, and ?C, respectively). The face may be a named face,
  1145. or a list like `(:background \"Red\")'."
  1146. :group 'org-agenda-line-format
  1147. :type '(choice
  1148. (const :tag "Never" nil)
  1149. (const :tag "Defaults" t)
  1150. (const :tag "Cookies only" cookies)
  1151. (repeat :tag "Specify"
  1152. (list (character :tag "Priority" :value ?A)
  1153. (sexp :tag "face")))))
  1154. (defgroup org-agenda-column-view nil
  1155. "Options concerning column view in the agenda."
  1156. :tag "Org Agenda Column View"
  1157. :group 'org-agenda)
  1158. (defcustom org-agenda-columns-show-summaries t
  1159. "Non-nil means, show summaries for columns displayed in the agenda view."
  1160. :group 'org-agenda-column-view
  1161. :type 'boolean)
  1162. (defcustom org-agenda-columns-remove-prefix-from-item t
  1163. "Non-nil means, remove the prefix from a headline for agenda column view.
  1164. The special ITEM field in the columns format contains the current line, with
  1165. all information shown in other columns (like the TODO state or a tag).
  1166. When this variable is non-nil, also the agenda prefix will be removed from
  1167. the content of the ITEM field, to make sure as much as possible of the
  1168. headline can be shown in the limited width of the field."
  1169. :group 'org-agenda
  1170. :type 'boolean)
  1171. (defcustom org-agenda-columns-compute-summary-properties t
  1172. "Non-nil means, recompute all summary properties before column view.
  1173. When column view in the agenda is listing properties that have a summary
  1174. operator, it can go to all relevant buffers and recompute the summaries
  1175. there. This can mean overhead for the agenda column view, but is necessary
  1176. to have thing up to date.
  1177. As a special case, a CLOCKSUM property also makes sure that the clock
  1178. computations are current."
  1179. :group 'org-agenda-column-view
  1180. :type 'boolean)
  1181. (defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  1182. "Non-nil means, the duration of an appointment will add to day effort.
  1183. The property to which appointment durations will be added is the one given
  1184. in the option `org-effort-property'. If an appointment does not have
  1185. an end time, `org-agenda-default-appointment-duration' will be used. If that
  1186. is not set, an appointment without end time will not contribute to the time
  1187. estimate."
  1188. :group 'org-agenda-column-view
  1189. :type 'boolean)
  1190. (defcustom org-agenda-auto-exclude-function nil
  1191. "A function called with a tag to decide if it is filtered on '/ RET'.
  1192. The sole argument to the function, which is called once for each
  1193. possible tag, is a string giving the name of the tag. The
  1194. function should return either nil if the tag should be included
  1195. as normal, or \"-<TAG>\" to exclude the tag.
  1196. Note that for the purpose of tag filtering, only the lower-case version of
  1197. all tags will be considered, so that this function will only ever see
  1198. the lower-case version of all tags."
  1199. :group 'org-agenda
  1200. :type 'function)
  1201. (eval-when-compile
  1202. (require 'cl))
  1203. (require 'org)
  1204. (defun org-add-agenda-custom-command (entry)
  1205. "Replace or add a command in `org-agenda-custom-commands'.
  1206. This is mostly for hacking and trying a new command - once the command
  1207. works you probably want to add it to `org-agenda-custom-commands' for good."
  1208. (let ((ass (assoc (car entry) org-agenda-custom-commands)))
  1209. (if ass
  1210. (setcdr ass (cdr entry))
  1211. (push entry org-agenda-custom-commands))))
  1212. ;;; Define the Org-agenda-mode
  1213. (defvar org-agenda-mode-map (make-sparse-keymap)
  1214. "Keymap for `org-agenda-mode'.")
  1215. (if (fboundp 'defvaralias)
  1216. (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))
  1217. (defvar org-agenda-menu) ; defined later in this file.
  1218. (defvar org-agenda-restrict) ; defined later in this file.
  1219. (defvar org-agenda-follow-mode nil)
  1220. (defvar org-agenda-entry-text-mode nil)
  1221. (defvar org-agenda-clockreport-mode nil)
  1222. (defvar org-agenda-show-log nil)
  1223. (defvar org-agenda-redo-command nil)
  1224. (defvar org-agenda-query-string nil)
  1225. (defvar org-agenda-mode-hook nil
  1226. "Hook for org-agenda-mode, run after the mode is turned on.")
  1227. (defvar org-agenda-type nil)
  1228. (defvar org-agenda-force-single-file nil)
  1229. (defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file
  1230. (defun org-agenda-mode ()
  1231. "Mode for time-sorted view on action items in Org-mode files.
  1232. The following commands are available:
  1233. \\{org-agenda-mode-map}"
  1234. (interactive)
  1235. (kill-all-local-variables)
  1236. (setq org-agenda-undo-list nil
  1237. org-agenda-pending-undo-list nil
  1238. org-agenda-bulk-marked-entries nil)
  1239. (setq major-mode 'org-agenda-mode)
  1240. ;; Keep global-font-lock-mode from turning on font-lock-mode
  1241. (org-set-local 'font-lock-global-modes (list 'not major-mode))
  1242. (setq mode-name "Org-Agenda")
  1243. (use-local-map org-agenda-mode-map)
  1244. (easy-menu-add org-agenda-menu)
  1245. (if org-startup-truncated (setq truncate-lines t))
  1246. (org-set-local 'line-move-visual nil)
  1247. (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  1248. (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  1249. ;; Make sure properties are removed when copying text
  1250. (when (boundp 'buffer-substring-filters)
  1251. (org-set-local 'buffer-substring-filters
  1252. (cons (lambda (x)
  1253. (set-text-properties 0 (length x) nil x) x)
  1254. buffer-substring-filters)))
  1255. (unless org-agenda-keep-modes
  1256. (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
  1257. org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
  1258. org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
  1259. org-agenda-show-log org-agenda-start-with-log-mode))
  1260. (easy-menu-change
  1261. '("Agenda") "Agenda Files"
  1262. (append
  1263. (list
  1264. (vector
  1265. (if (get 'org-agenda-files 'org-restrict)
  1266. "Restricted to single file"
  1267. "Edit File List")
  1268. '(org-edit-agenda-file-list)
  1269. (not (get 'org-agenda-files 'org-restrict)))
  1270. "--")
  1271. (mapcar 'org-file-menu-entry (org-agenda-files))))
  1272. (org-agenda-set-mode-name)
  1273. (apply
  1274. (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
  1275. (list 'org-agenda-mode-hook)))
  1276. (substitute-key-definition 'undo 'org-agenda-undo
  1277. org-agenda-mode-map global-map)
  1278. (org-defkey org-agenda-mode-map "\C-i" 'org-agenda-goto)
  1279. (org-defkey org-agenda-mode-map [(tab)] 'org-agenda-goto)
  1280. (org-defkey org-agenda-mode-map "\C-m" 'org-agenda-switch-to)
  1281. (org-defkey org-agenda-mode-map "\C-k" 'org-agenda-kill)
  1282. (org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
  1283. (org-defkey org-agenda-mode-map "m" 'org-agenda-bulk-mark)
  1284. (org-defkey org-agenda-mode-map "u" 'org-agenda-bulk-unmark)
  1285. (org-defkey org-agenda-mode-map "U" 'org-agenda-bulk-remove-all-marks)
  1286. (org-defkey org-agenda-mode-map "B" 'org-agenda-bulk-action)
  1287. (org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
  1288. (org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
  1289. (org-defkey org-agenda-mode-map "\C-c\C-xa" 'org-agenda-toggle-archive-tag)
  1290. (org-defkey org-agenda-mode-map "\C-c\C-xA" 'org-agenda-archive-to-archive-sibling)
  1291. (org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
  1292. (org-defkey org-agenda-mode-map "\C-c$" 'org-agenda-archive)
  1293. (org-defkey org-agenda-mode-map "$" 'org-agenda-archive)
  1294. (org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
  1295. (org-defkey org-agenda-mode-map " " 'org-agenda-show-and-scroll-up)
  1296. (org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
  1297. (org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
  1298. (org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
  1299. (org-defkey org-agenda-mode-map [(control shift left)] 'org-agenda-todo-previousset)
  1300. (org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
  1301. (org-defkey org-agenda-mode-map "o" 'delete-other-windows)
  1302. (org-defkey org-agenda-mode-map "L" 'org-agenda-recenter)
  1303. (org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
  1304. (org-defkey org-agenda-mode-map "t" 'org-agenda-todo)
  1305. (org-defkey org-agenda-mode-map "a" 'org-agenda-archive-default-with-confirmation)
  1306. (org-defkey org-agenda-mode-map ":" 'org-agenda-set-tags)
  1307. (org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
  1308. (org-defkey org-agenda-mode-map "." 'org-agenda-goto-today)
  1309. (org-defkey org-agenda-mode-map "j" 'org-agenda-goto-date)
  1310. (org-defkey org-agenda-mode-map "d" 'org-agenda-day-view)
  1311. (org-defkey org-agenda-mode-map "w" 'org-agenda-week-view)
  1312. (org-defkey org-agenda-mode-map "y" 'org-agenda-year-view)
  1313. (org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
  1314. (org-defkey org-agenda-mode-map "z" 'org-agenda-add-note)
  1315. (org-defkey org-agenda-mode-map "k" 'org-agenda-action)
  1316. (org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
  1317. (org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
  1318. (org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
  1319. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
  1320. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)
  1321. (org-defkey org-agenda-mode-map ">" 'org-agenda-date-prompt)
  1322. (org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
  1323. (org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
  1324. (let ((l '(1 2 3 4 5 6 7 8 9 0)))
  1325. (while l (org-defkey org-agenda-mode-map
  1326. (int-to-string (pop l)) 'digit-argument)))
  1327. (org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
  1328. (org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
  1329. (org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
  1330. (org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
  1331. (org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
  1332. (org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
  1333. (org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
  1334. (org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
  1335. (org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
  1336. (org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
  1337. (org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
  1338. (org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
  1339. 'org-clock-modify-effort-estimate)
  1340. (org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
  1341. (org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
  1342. (org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
  1343. (org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
  1344. (org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
  1345. (org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
  1346. (org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
  1347. (org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
  1348. (org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
  1349. (org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
  1350. (substitute-key-definition 'next-line 'org-agenda-next-line
  1351. org-agenda-mode-map global-map)
  1352. (substitute-key-definition 'previous-line 'org-agenda-previous-line
  1353. org-agenda-mode-map global-map)
  1354. (org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
  1355. (org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
  1356. (org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
  1357. (org-defkey org-agenda-mode-map "," 'org-agenda-priority)
  1358. (org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
  1359. (org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
  1360. (org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
  1361. (org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
  1362. (org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
  1363. (org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
  1364. (org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
  1365. (org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
  1366. (org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
  1367. (org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
  1368. (org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
  1369. (org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
  1370. (org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
  1371. (org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
  1372. (org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
  1373. (org-defkey org-agenda-mode-map "J" 'org-clock-goto)
  1374. (org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
  1375. (org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
  1376. (org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
  1377. (org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
  1378. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
  1379. (org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
  1380. (org-defkey org-agenda-mode-map "f" 'org-agenda-later)
  1381. (org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
  1382. (org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
  1383. (org-defkey org-agenda-mode-map "\C-c\C-x>" 'org-agenda-remove-restriction-lock)
  1384. (org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
  1385. (org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
  1386. (org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
  1387. (org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
  1388. (org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
  1389. (org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
  1390. (org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
  1391. (define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
  1392. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mg" 'org-mobile-pull)
  1393. (org-defkey org-agenda-mode-map "\C-c\C-x\C-mp" 'org-mobile-push)
  1394. (org-defkey org-agenda-mode-map
  1395. (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 'org-agenda-goto-mouse)
  1396. (org-defkey org-agenda-mode-map
  1397. (if (featurep 'xemacs) [(button3)] [(mouse-3)]) 'org-agenda-show-mouse)
  1398. (when org-agenda-mouse-1-follows-link
  1399. (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
  1400. (easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  1401. '("Agenda"
  1402. ("Agenda Files")
  1403. "--"
  1404. ("Agenda Dates"
  1405. ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
  1406. ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
  1407. ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
  1408. ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
  1409. "--"
  1410. ("View"
  1411. ["Day View" org-agenda-day-view
  1412. :active (org-agenda-check-type nil 'agenda)
  1413. :style radio :selected (equal org-agenda-ndays 1)
  1414. :keys "v d (or just d)"]
  1415. ["Week View" org-agenda-week-view
  1416. :active (org-agenda-check-type nil 'agenda)
  1417. :style radio :selected (equal org-agenda-ndays 7)
  1418. :keys "v w (or just w)"]
  1419. ["Month View" org-agenda-month-view
  1420. :active (org-agenda-check-type nil 'agenda)
  1421. :style radio :selected (member org-agenda-ndays '(28 29 30 31))
  1422. :keys "v m"]
  1423. ["Year View" org-agenda-year-view
  1424. :active (org-agenda-check-type nil 'agenda)
  1425. :style radio :selected (member org-agenda-ndays '(365 366))
  1426. :keys "v y"]
  1427. "--"
  1428. ["Include Diary" org-agenda-toggle-diary
  1429. :style toggle :selected org-agenda-include-diary
  1430. :active (org-agenda-check-type nil 'agenda)]
  1431. ["Use Time Grid" org-agenda-toggle-time-grid
  1432. :style toggle :selected org-agenda-use-time-grid
  1433. :active (org-agenda-check-type nil 'agenda)]
  1434. "--"
  1435. ["Show clock report" org-agenda-clockreport-mode
  1436. :style toggle :selected org-agenda-clockreport-mode
  1437. :active (org-agenda-check-type nil 'agenda)]
  1438. ["Show some entry text" org-agenda-entry-text-mode
  1439. :style toggle :selected org-agenda-entry-text-mode
  1440. :active t]
  1441. "--"
  1442. ["Show Logbook entries" org-agenda-log-mode
  1443. :style toggle :selected org-agenda-show-log
  1444. :active (org-agenda-check-type nil 'agenda 'timeline)
  1445. :keys "v l (or just l)"]
  1446. ["Include archived trees" org-agenda-archives-mode
  1447. :style toggle :selected org-agenda-archives-mode :active t
  1448. :keys "v a"]
  1449. ["Include archive files" (org-agenda-archives-mode t)
  1450. :style toggle :selected (eq org-agenda-archives-mode t) :active t
  1451. :keys "v A"]
  1452. "--"
  1453. ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
  1454. ["Write view to file" org-write-agenda t]
  1455. ["Rebuild buffer" org-agenda-redo t]
  1456. ["Save all Org-mode Buffers" org-save-all-org-buffers t]
  1457. "--"
  1458. ["Show original entry" org-agenda-show t]
  1459. ["Go To (other window)" org-agenda-goto t]
  1460. ["Go To (this window)" org-agenda-switch-to t]
  1461. ["Follow Mode" org-agenda-follow-mode
  1462. :style toggle :selected org-agenda-follow-mode :active t]
  1463. ; ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
  1464. "--"
  1465. ("TODO"
  1466. ["Cycle TODO" org-agenda-todo t]
  1467. ["Next TODO set" org-agenda-todo-nextset t]
  1468. ["Previous TODO set" org-agenda-todo-previousset t]
  1469. ["Add note" org-agenda-add-note t])
  1470. ("Archive/Refile/Delete"
  1471. ["Archive default" org-agenda-archive-default t]
  1472. ["Archive default" org-agenda-archive-default-with-confirmation t]
  1473. ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
  1474. ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
  1475. ["Archive subtree" org-agenda-archive t]
  1476. "--"
  1477. ["Refile" org-agenda-refile t]
  1478. "--"
  1479. ["Delete subtree" org-agenda-kill t])
  1480. ("Bulk action"
  1481. ["Mark entry" org-agenda-bulk-mark t]
  1482. ["Unmark entry" org-agenda-bulk-unmark t]
  1483. ["Act on all marked" org-agenda-bulk-action t]
  1484. ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
  1485. "--"
  1486. ("Tags and Properties"
  1487. ["Show all Tags" org-agenda-show-tags t]
  1488. ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
  1489. ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
  1490. "--"
  1491. ["Column View" org-columns t])
  1492. ("Deadline/Schedule"
  1493. ["Schedule" org-agenda-schedule t]
  1494. ["Set Deadline" org-agenda-deadline t]
  1495. "--"
  1496. ["Mark item" org-agenda-action :active t :keys "k m"]
  1497. ["Show mark item" org-agenda-action :active t :keys "k v"]
  1498. ["Schedule marked item" org-agenda-action :active t :keys "k s"]
  1499. ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
  1500. "--"
  1501. ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
  1502. ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
  1503. ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
  1504. ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
  1505. ["Change Time + min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
  1506. ["Change Time - min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
  1507. ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
  1508. ("Clock and Effort"
  1509. ["Clock in" org-agenda-clock-in t]
  1510. ["Clock out" org-agenda-clock-out t]
  1511. ["Clock cancel" org-agenda-clock-cancel t]
  1512. ["Goto running clock" org-clock-goto t]
  1513. "--"
  1514. ["Set Effort" org-agenda-set-effort t]
  1515. ["Change clocked effort" org-clock-modify-effort-estimate
  1516. (org-clock-is-active)])
  1517. ("Priority"
  1518. ["Set Priority" org-agenda-priority t]
  1519. ["Increase Priority" org-agenda-priority-up t]
  1520. ["Decrease Priority" org-agenda-priority-down t]
  1521. ["Show Priority" org-agenda-show-priority t])
  1522. ("Calendar/Diary"
  1523. ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
  1524. ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
  1525. ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
  1526. ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
  1527. ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
  1528. ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
  1529. "--"
  1530. ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
  1531. "--"
  1532. ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
  1533. "--"
  1534. ("MobileOrg"
  1535. ["Push Files and Views" org-mobile-push t]
  1536. ["Get Captured and Flagged" org-mobile-pull t]
  1537. ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
  1538. ["Show note / unflag" org-agenda-show-the-flagging-note t]
  1539. "--"
  1540. ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
  1541. "--"
  1542. ["Quit" org-agenda-quit t]
  1543. ["Exit and Release Buffers" org-agenda-exit t]
  1544. ))
  1545. ;;; Agenda undo
  1546. (defvar org-agenda-allow-remote-undo t
  1547. "Non-nil means, allow remote undo from the agenda buffer.")
  1548. (defvar org-agenda-undo-list nil
  1549. "List of undoable operations in the agenda since last refresh.")
  1550. (defvar org-agenda-undo-has-started-in nil
  1551. "Buffers that have already seen `undo-start' in the current undo sequence.")
  1552. (defvar org-agenda-pending-undo-list nil
  1553. "In a series of undo commands, this is the list of remaining undo items.")
  1554. (defun org-agenda-undo ()
  1555. "Undo a remote editing step in the agenda.
  1556. This undoes changes both in the agenda buffer and in the remote buffer
  1557. that have been changed along."
  1558. (interactive)
  1559. (or org-agenda-allow-remote-undo
  1560. (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  1561. (if (not (eq this-command last-command))
  1562. (setq org-agenda-undo-has-started-in nil
  1563. org-agenda-pending-undo-list org-agenda-undo-list))
  1564. (if (not org-agenda-pending-undo-list)
  1565. (error "No further undo information"))
  1566. (let* ((entry (pop org-agenda-pending-undo-list))
  1567. buf line cmd rembuf)
  1568. (setq cmd (pop entry) line (pop entry))
  1569. (setq rembuf (nth 2 entry))
  1570. (org-with-remote-undo rembuf
  1571. (while (bufferp (setq buf (pop entry)))
  1572. (if (pop entry)
  1573. (with-current-buffer buf
  1574. (let ((last-undo-buffer buf)
  1575. (inhibit-read-only t))
  1576. (unless (memq buf org-agenda-undo-has-started-in)
  1577. (push buf org-agenda-undo-has-started-in)
  1578. (make-local-variable 'pending-undo-list)
  1579. (undo-start))
  1580. (while (and pending-undo-list
  1581. (listp pending-undo-list)
  1582. (not (car pending-undo-list)))
  1583. (pop pending-undo-list))
  1584. (undo-more 1))))))
  1585. (org-goto-line line)
  1586. (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
  1587. (defun org-verify-change-for-undo (l1 l2)
  1588. "Verify that a real change occurred between the undo lists L1 and L2."
  1589. (while (and l1 (listp l1) (null (car l1))) (pop l1))
  1590. (while (and l2 (listp l2) (null (car l2))) (pop l2))
  1591. (not (eq l1 l2)))
  1592. ;;; Agenda dispatch
  1593. (defvar org-agenda-restrict nil)
  1594. (defvar org-agenda-restrict-begin (make-marker))
  1595. (defvar org-agenda-restrict-end (make-marker))
  1596. (defvar org-agenda-last-dispatch-buffer nil)
  1597. (defvar org-agenda-overriding-restriction nil)
  1598. ;;;###autoload
  1599. (defun org-agenda (&optional arg keys restriction)
  1600. "Dispatch agenda commands to collect entries to the agenda buffer.
  1601. Prompts for a command to execute. Any prefix arg will be passed
  1602. on to the selected command. The default selections are:
  1603. a Call `org-agenda-list' to display the agenda for current day or week.
  1604. t Call `org-todo-list' to display the global todo list.
  1605. T Call `org-todo-list' to display the global todo list, select only
  1606. entries with a specific TODO keyword (the user gets a prompt).
  1607. m Call `org-tags-view' to display headlines with tags matching
  1608. a condition (the user is prompted for the condition).
  1609. M Like `m', but select only TODO entries, no ordinary headlines.
  1610. L Create a timeline for the current buffer.
  1611. e Export views to associated files.
  1612. s Search entries for keywords.
  1613. / Multi occur across all agenda files and also files listed
  1614. in `org-agenda-text-search-extra-files'.
  1615. < Restrict agenda commands to buffer, subtree, or region.
  1616. Press several times to get the desired effect.
  1617. > Remove a previous restriction.
  1618. # List \"stuck\" projects.
  1619. ! Configure what \"stuck\" means.
  1620. C Configure custom agenda commands.
  1621. More commands can be added by configuring the variable
  1622. `org-agenda-custom-commands'. In particular, specific tags and TODO keyword
  1623. searches can be pre-defined in this way.
  1624. If the current buffer is in Org-mode and visiting a file, you can also
  1625. first press `<' once to indicate that the agenda should be temporarily
  1626. \(until the next use of \\[org-agenda]) restricted to the current file.
  1627. Pressing `<' twice means to restrict to the current subtree or region
  1628. \(if active)."
  1629. (interactive "P")
  1630. (catch 'exit
  1631. (let* ((prefix-descriptions nil)
  1632. (org-agenda-window-setup (if (equal (buffer-name)
  1633. org-agenda-buffer-name)
  1634. 'current-window
  1635. org-agenda-window-setup))
  1636. (org-agenda-custom-commands-orig org-agenda-custom-commands)
  1637. (org-agenda-custom-commands
  1638. ;; normalize different versions
  1639. (delq nil
  1640. (mapcar
  1641. (lambda (x)
  1642. (cond ((stringp (cdr x))
  1643. (push x prefix-descriptions)
  1644. nil)
  1645. ((stringp (nth 1 x)) x)
  1646. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1647. (t (cons (car x) (cons "" (cdr x))))))
  1648. org-agenda-custom-commands)))
  1649. (buf (current-buffer))
  1650. (bfn (buffer-file-name (buffer-base-buffer)))
  1651. entry key type match lprops ans)
  1652. ;; Turn off restriction unless there is an overriding one,
  1653. (unless org-agenda-overriding-restriction
  1654. (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
  1655. ;; There is a request to keep the file list in place
  1656. (put 'org-agenda-files 'org-restrict nil))
  1657. (setq org-agenda-restrict nil)
  1658. (move-marker org-agenda-restrict-begin nil)
  1659. (move-marker org-agenda-restrict-end nil))
  1660. ;; Delete old local properties
  1661. (put 'org-agenda-redo-command 'org-lprops nil)
  1662. ;; Remember where this call originated
  1663. (setq org-agenda-last-dispatch-buffer (current-buffer))
  1664. (unless keys
  1665. (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
  1666. keys (car ans)
  1667. restriction (cdr ans)))
  1668. ;; Establish the restriction, if any
  1669. (when (and (not org-agenda-overriding-restriction) restriction)
  1670. (put 'org-agenda-files 'org-restrict (list bfn))
  1671. (cond
  1672. ((eq restriction 'region)
  1673. (setq org-agenda-restrict t)
  1674. (move-marker org-agenda-restrict-begin (region-beginning))
  1675. (move-marker org-agenda-restrict-end (region-end)))
  1676. ((eq restriction 'subtree)
  1677. (save-excursion
  1678. (setq org-agenda-restrict t)
  1679. (org-back-to-heading t)
  1680. (move-marker org-agenda-restrict-begin (point))
  1681. (move-marker org-agenda-restrict-end
  1682. (progn (org-end-of-subtree t)))))))
  1683. (require 'calendar) ; FIXME: can we avoid this for some commands?
  1684. ;; For example the todo list should not need it (but does...)
  1685. (cond
  1686. ((setq entry (assoc keys org-agenda-custom-commands))
  1687. (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
  1688. (progn
  1689. (setq type (nth 2 entry) match (eval (nth 3 entry))
  1690. lprops (nth 4 entry))
  1691. (put 'org-agenda-redo-command 'org-lprops lprops)
  1692. (cond
  1693. ((eq type 'agenda)
  1694. (org-let lprops '(org-agenda-list current-prefix-arg)))
  1695. ((eq type 'alltodo)
  1696. (org-let lprops '(org-todo-list current-prefix-arg)))
  1697. ((eq type 'search)
  1698. (org-let lprops '(org-search-view current-prefix-arg match nil)))
  1699. ((eq type 'stuck)
  1700. (org-let lprops '(org-agenda-list-stuck-projects
  1701. current-prefix-arg)))
  1702. ((eq type 'tags)
  1703. (org-let lprops '(org-tags-view current-prefix-arg match)))
  1704. ((eq type 'tags-todo)
  1705. (org-let lprops '(org-tags-view '(4) match)))
  1706. ((eq type 'todo)
  1707. (org-let lprops '(org-todo-list match)))
  1708. ((eq type 'tags-tree)
  1709. (org-check-for-org-mode)
  1710. (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
  1711. ((eq type 'todo-tree)
  1712. (org-check-for-org-mode)
  1713. (org-let lprops
  1714. '(org-occur (concat "^" outline-regexp "[ \t]*"
  1715. (regexp-quote match) "\\>"))))
  1716. ((eq type 'occur-tree)
  1717. (org-check-for-org-mode)
  1718. (org-let lprops '(org-occur match)))
  1719. ((functionp type)
  1720. (org-let lprops '(funcall type match)))
  1721. ((fboundp type)
  1722. (org-let lprops '(funcall type match)))
  1723. (t (error "Invalid custom agenda command type %s" type))))
  1724. (org-run-agenda-series (nth 1 entry) (cddr entry))))
  1725. ((equal keys "C")
  1726. (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
  1727. (customize-variable 'org-agenda-custom-commands))
  1728. ((equal keys "a") (call-interactively 'org-agenda-list))
  1729. ((equal keys "s") (call-interactively 'org-search-view))
  1730. ((equal keys "t") (call-interactively 'org-todo-list))
  1731. ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
  1732. ((equal keys "m") (call-interactively 'org-tags-view))
  1733. ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
  1734. ((equal keys "e") (call-interactively 'org-store-agenda-views))
  1735. ((equal keys "?") (org-tags-view nil "+FLAGGED")
  1736. (org-add-hook
  1737. 'post-command-hook
  1738. (lambda ()
  1739. (unless (current-message)
  1740. (let* ((m (org-agenda-get-any-marker))
  1741. (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
  1742. (when note
  1743. (message (concat
  1744. "FLAGGING-NOTE ([?] for more info): "
  1745. (org-add-props
  1746. (replace-regexp-in-string
  1747. "\\\\n" "//"
  1748. (copy-sequence note))
  1749. nil 'face 'org-warning)))))))
  1750. t t))
  1751. ((equal keys "L")
  1752. (unless (org-mode-p)
  1753. (error "This is not an Org-mode file"))
  1754. (unless restriction
  1755. (put 'org-agenda-files 'org-restrict (list bfn))
  1756. (org-call-with-arg 'org-timeline arg)))
  1757. ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
  1758. ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
  1759. ((equal keys "!") (customize-variable 'org-stuck-projects))
  1760. (t (error "Invalid agenda key"))))))
  1761. (defun org-agenda-normalize-custom-commands (cmds)
  1762. (delq nil
  1763. (mapcar
  1764. (lambda (x)
  1765. (cond ((stringp (cdr x)) nil)
  1766. ((stringp (nth 1 x)) x)
  1767. ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
  1768. (t (cons (car x) (cons "" (cdr x))))))
  1769. cmds)))
  1770. (defun org-agenda-get-restriction-and-command (prefix-descriptions)
  1771. "The user interface for selecting an agenda command."
  1772. (catch 'exit
  1773. (let* ((bfn (buffer-file-name (buffer-base-buffer)))
  1774. (restrict-ok (and bfn (org-mode-p)))
  1775. (region-p (org-region-active-p))
  1776. (custom org-agenda-custom-commands)
  1777. (selstring "")
  1778. restriction second-time
  1779. c entry key type match prefixes rmheader header-end custom1 desc)
  1780. (save-window-excursion
  1781. (delete-other-windows)
  1782. (org-switch-to-buffer-other-window " *Agenda Commands*")
  1783. (erase-buffer)
  1784. (insert (eval-when-compile
  1785. (let ((header
  1786. "
  1787. Press key for an agenda command: < Buffer, subtree/region restriction
  1788. -------------------------------- > Remove restriction
  1789. a Agenda for current week or day e Export agenda views
  1790. t List of all TODO entries T Entries with special TODO kwd
  1791. m Match a TAGS/PROP/TODO query M Like m, but only TODO entries
  1792. L Timeline for current buffer # List stuck projects (!=configure)
  1793. s Search for keywords C Configure custom agenda commands
  1794. / Multi-occur ? Find :FLAGGED: entries
  1795. ")
  1796. (start 0))
  1797. (while (string-match
  1798. "\\(^\\| \\|(\\)\\(\\S-\\)\\( \\|=\\)"
  1799. header start)
  1800. (setq start (match-end 0))
  1801. (add-text-properties (match-beginning 2) (match-end 2)
  1802. '(face bold) header))
  1803. header)))
  1804. (setq header-end (move-marker (make-marker) (point)))
  1805. (while t
  1806. (setq custom1 custom)
  1807. (when (eq rmheader t)
  1808. (org-goto-line 1)
  1809. (re-search-forward ":" nil t)
  1810. (delete-region (match-end 0) (point-at-eol))
  1811. (forward-char 1)
  1812. (looking-at "-+")
  1813. (delete-region (match-end 0) (point-at-eol))
  1814. (move-marker header-end (match-end 0)))
  1815. (goto-char header-end)
  1816. (delete-region (point) (point-max))
  1817. (while (setq entry (pop custom1))
  1818. (setq key (car entry) desc (nth 1 entry)
  1819. type (nth 2 entry)
  1820. match (nth 3 entry))
  1821. (if (> (length key) 1)
  1822. (add-to-list 'prefixes (string-to-char key))
  1823. (insert
  1824. (format
  1825. "\n%-4s%-14s: %s"
  1826. (org-add-props (copy-sequence key)
  1827. '(face bold))
  1828. (cond
  1829. ((string-match "\\S-" desc) desc)
  1830. ((eq type 'agenda) "Agenda for current week or day")
  1831. ((eq type 'alltodo) "List of all TODO entries")
  1832. ((eq type 'search) "Word search")
  1833. ((eq type 'stuck) "List of stuck projects")
  1834. ((eq type 'todo) "TODO keyword")
  1835. ((eq type 'tags) "Tags query")
  1836. ((eq type 'tags-todo) "Tags (TODO)")
  1837. ((eq type 'tags-tree) "Tags tree")
  1838. ((eq type 'todo-tree) "TODO kwd tree")
  1839. ((eq type 'occur-tree) "Occur tree")
  1840. ((functionp type) (if (symbolp type)
  1841. (symbol-name type)
  1842. "Lambda expression"))
  1843. (t "???"))
  1844. (cond
  1845. ((stringp match)
  1846. (setq match (copy-sequence match))
  1847. (org-add-props match nil 'face 'org-warning))
  1848. (match
  1849. (format "set of %d commands" (length match)))
  1850. (t ""))))))
  1851. (when prefixes
  1852. (mapc (lambda (x)
  1853. (insert
  1854. (format "\n%s %s"
  1855. (org-add-props (char-to-string x)
  1856. nil 'face 'bold)
  1857. (or (cdr (assoc (concat selstring (char-to-string x))
  1858. prefix-descriptions))
  1859. "Prefix key"))))
  1860. prefixes))
  1861. (goto-char (point-min))
  1862. (if second-time
  1863. (if (not (pos-visible-in-window-p (point-max)))
  1864. (org-fit-window-to-buffer))
  1865. (setq second-time t)
  1866. (org-fit-window-to-buffer))
  1867. (message "Press key for agenda command%s:"
  1868. (if (or restrict-ok org-agenda-overriding-restriction)
  1869. (if org-agenda-overriding-restriction
  1870. " (restriction lock active)"
  1871. (if restriction
  1872. (format " (restricted to %s)" restriction)
  1873. " (unrestricted)"))
  1874. ""))
  1875. (setq c (read-char-exclusive))
  1876. (message "")
  1877. (cond
  1878. ((assoc (char-to-string c) custom)
  1879. (setq selstring (concat selstring (char-to-string c)))
  1880. (throw 'exit (cons selstring restriction)))
  1881. ((memq c prefixes)
  1882. (setq selstring (concat selstring (char-to-string c))
  1883. prefixes nil
  1884. rmheader (or rmheader t)
  1885. custom (delq nil (mapcar
  1886. (lambda (x)
  1887. (if (or (= (length (car x)) 1)
  1888. (/= (string-to-char (car x)) c))
  1889. nil
  1890. (cons (substring (car x) 1) (cdr x))))
  1891. custom))))
  1892. ((and (not restrict-ok) (memq c '(?1 ?0 ?<)))
  1893. (message "Restriction is only possible in Org-mode buffers")
  1894. (ding) (sit-for 1))
  1895. ((eq c ?1)
  1896. (org-agenda-remove-restriction-lock 'noupdate)
  1897. (setq restriction 'buffer))
  1898. ((eq c ?0)
  1899. (org-agenda-remove-restriction-lock 'noupdate)
  1900. (setq restriction (if region-p 'region 'subtree)))
  1901. ((eq c ?<)
  1902. (org-agenda-remove-restriction-lock 'noupdate)
  1903. (setq restriction
  1904. (cond
  1905. ((eq restriction 'buffer)
  1906. (if region-p 'region 'subtree))
  1907. ((memq restriction '(subtree region))
  1908. nil)
  1909. (t 'buffer))))
  1910. ((eq c ?>)
  1911. (org-agenda-remove-restriction-lock 'noupdate)
  1912. (setq restriction nil))
  1913. ((and (equal selstring "") (memq c '(?s ?a ?t ?m ?L ?C ?e ?T ?M ?# ?! ?/ ??)))
  1914. (throw 'exit (cons (setq selstring (char-to-string c)) restriction)))
  1915. ((and (> (length selstring) 0) (eq c ?\d))
  1916. (delete-window)
  1917. (org-agenda-get-restriction-and-command prefix-descriptions))
  1918. ((equal c ?q) (error "Abort"))
  1919. (t (error "Invalid key %c" c))))))))
  1920. (defun org-run-agenda-series (name series)
  1921. (org-let (nth 1 series) '(org-prepare-agenda name))
  1922. (let* ((org-agenda-multi t)
  1923. (redo (list 'org-run-agenda-series name (list 'quote series)))
  1924. (cmds (car series))
  1925. (gprops (nth 1 series))
  1926. match ;; The byte compiler incorrectly complains about this. Keep it!
  1927. cmd type lprops)
  1928. (while (setq cmd (pop cmds))
  1929. (setq type (car cmd) match (eval (nth 1 cmd)) lprops (nth 2 cmd))
  1930. (cond
  1931. ((eq type 'agenda)
  1932. (org-let2 gprops lprops
  1933. '(call-interactively 'org-agenda-list)))
  1934. ((eq type 'alltodo)
  1935. (org-let2 gprops lprops
  1936. '(call-interactively 'org-todo-list)))
  1937. ((eq type 'search)
  1938. (org-let2 gprops lprops
  1939. '(org-search-view current-prefix-arg match nil)))
  1940. ((eq type 'stuck)
  1941. (org-let2 gprops lprops
  1942. '(call-interactively 'org-agenda-list-stuck-projects)))
  1943. ((eq type 'tags)
  1944. (org-let2 gprops lprops
  1945. '(org-tags-view current-prefix-arg match)))
  1946. ((eq type 'tags-todo)
  1947. (org-let2 gprops lprops
  1948. '(org-tags-view '(4) match)))
  1949. ((eq type 'todo)
  1950. (org-let2 gprops lprops
  1951. '(org-todo-list match)))
  1952. ((fboundp type)
  1953. (org-let2 gprops lprops
  1954. '(funcall type match)))
  1955. (t (error "Invalid type in command series"))))
  1956. (widen)
  1957. (setq org-agenda-redo-command redo)
  1958. (goto-char (point-min)))
  1959. (org-fit-agenda-window)
  1960. (org-let (nth 1 series) '(org-finalize-agenda)))
  1961. ;;;###autoload
  1962. (defmacro org-batch-agenda (cmd-key &rest parameters)
  1963. "Run an agenda command in batch mode and send the result to STDOUT.
  1964. If CMD-KEY is a string of length 1, it is used as a key in
  1965. `org-agenda-custom-commands' and triggers this command. If it is a
  1966. longer string it is used as a tags/todo match string.
  1967. Paramters are alternating variable names and values that will be bound
  1968. before running the agenda command."
  1969. (let (pars)
  1970. (while parameters
  1971. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  1972. (if (> (length cmd-key) 2)
  1973. (eval (list 'let (nreverse pars)
  1974. (list 'org-tags-view nil cmd-key)))
  1975. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  1976. (set-buffer org-agenda-buffer-name)
  1977. (princ (org-encode-for-stdout (buffer-string)))))
  1978. ;(defun org-encode-for-stdout (string)
  1979. ; (if (fboundp 'encode-coding-string)
  1980. ; (encode-coding-string string buffer-file-coding-system)
  1981. ; string))
  1982. (defun org-encode-for-stdout (string)
  1983. string)
  1984. (defvar org-agenda-info nil)
  1985. ;;;###autoload
  1986. (defmacro org-batch-agenda-csv (cmd-key &rest parameters)
  1987. "Run an agenda command in batch mode and send the result to STDOUT.
  1988. If CMD-KEY is a string of length 1, it is used as a key in
  1989. `org-agenda-custom-commands' and triggers this command. If it is a
  1990. longer string it is used as a tags/todo match string.
  1991. Paramters are alternating variable names and values that will be bound
  1992. before running the agenda command.
  1993. The output gives a line for each selected agenda item. Each
  1994. item is a list of comma-separated values, like this:
  1995. category,head,type,todo,tags,date,time,extra,priority-l,priority-n
  1996. category The category of the item
  1997. head The headline, without TODO kwd, TAGS and PRIORITY
  1998. type The type of the agenda entry, can be
  1999. todo selected in TODO match
  2000. tagsmatch selected in tags match
  2001. diary imported from diary
  2002. deadline a deadline on given date
  2003. scheduled scheduled on given date
  2004. timestamp entry has timestamp on given date
  2005. closed entry was closed on given date
  2006. upcoming-deadline warning about deadline
  2007. past-scheduled forwarded scheduled item
  2008. block entry has date block including g. date
  2009. todo The todo keyword, if any
  2010. tags All tags including inherited ones, separated by colons
  2011. date The relevant date, like 2007-2-14
  2012. time The time, like 15:00-16:50
  2013. extra Sting with extra planning info
  2014. priority-l The priority letter if any was given
  2015. priority-n The computed numerical priority
  2016. agenda-day The day in the agenda where this is listed"
  2017. (let (pars)
  2018. (while parameters
  2019. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2020. (push (list 'org-agenda-remove-tags t) pars)
  2021. (if (> (length cmd-key) 2)
  2022. (eval (list 'let (nreverse pars)
  2023. (list 'org-tags-view nil cmd-key)))
  2024. (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
  2025. (set-buffer org-agenda-buffer-name)
  2026. (let* ((lines (org-split-string (buffer-string) "\n"))
  2027. line)
  2028. (while (setq line (pop lines))
  2029. (catch 'next
  2030. (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
  2031. (setq org-agenda-info
  2032. (org-fix-agenda-info (text-properties-at 0 line)))
  2033. (princ
  2034. (org-encode-for-stdout
  2035. (mapconcat 'org-agenda-export-csv-mapper
  2036. '(org-category txt type todo tags date time-of-day extra
  2037. priority-letter priority agenda-day)
  2038. ",")))
  2039. (princ "\n"))))))
  2040. (defun org-fix-agenda-info (props)
  2041. "Make sure all properties on an agenda item have a canonical form,
  2042. so the export commands can easily use it."
  2043. (let (tmp re)
  2044. (when (setq tmp (plist-get props 'tags))
  2045. (setq props (plist-put props 'tags (mapconcat 'identity tmp ":"))))
  2046. (when (setq tmp (plist-get props 'date))
  2047. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2048. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2049. '((format "%4d, %9s %2s, %4s" dayname monthname day year))
  2050. (setq tmp (calendar-date-string tmp)))
  2051. (setq props (plist-put props 'date tmp)))
  2052. (when (setq tmp (plist-get props 'day))
  2053. (if (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
  2054. (let ((calendar-date-display-form '(year "-" month "-" day)))
  2055. (setq tmp (calendar-date-string tmp)))
  2056. (setq props (plist-put props 'day tmp))
  2057. (setq props (plist-put props 'agenda-day tmp)))
  2058. (when (setq tmp (plist-get props 'txt))
  2059. (when (string-match "\\[#\\([A-Z0-9]\\)\\] ?" tmp)
  2060. (plist-put props 'priority-letter (match-string 1 tmp))
  2061. (setq tmp (replace-match "" t t tmp)))
  2062. (when (and (setq re (plist-get props 'org-todo-regexp))
  2063. (setq re (concat "\\`\\.*" re " ?"))
  2064. (string-match re tmp))
  2065. (plist-put props 'todo (match-string 1 tmp))
  2066. (setq tmp (replace-match "" t t tmp)))
  2067. (plist-put props 'txt tmp)))
  2068. props)
  2069. (defun org-agenda-export-csv-mapper (prop)
  2070. (let ((res (plist-get org-agenda-info prop)))
  2071. (setq res
  2072. (cond
  2073. ((not res) "")
  2074. ((stringp res) res)
  2075. (t (prin1-to-string res))))
  2076. (while (string-match "," res)
  2077. (setq res (replace-match ";" t t res)))
  2078. (org-trim res)))
  2079. ;;;###autoload
  2080. (defun org-store-agenda-views (&rest parameters)
  2081. (interactive)
  2082. (eval (list 'org-batch-store-agenda-views)))
  2083. ;; FIXME, why is this a macro?????
  2084. ;;;###autoload
  2085. (defmacro org-batch-store-agenda-views (&rest parameters)
  2086. "Run all custom agenda commands that have a file argument."
  2087. (let ((cmds (org-agenda-normalize-custom-commands org-agenda-custom-commands))
  2088. (pop-up-frames nil)
  2089. (dir default-directory)
  2090. pars cmd thiscmdkey files opts cmd-or-set)
  2091. (while parameters
  2092. (push (list (pop parameters) (if parameters (pop parameters))) pars))
  2093. (setq pars (reverse pars))
  2094. (save-window-excursion
  2095. (while cmds
  2096. (setq cmd (pop cmds)
  2097. thiscmdkey (car cmd)
  2098. cmd-or-set (nth 2 cmd)
  2099. opts (nth (if (listp cmd-or-set) 3 4) cmd)
  2100. files (nth (if (listp cmd-or-set) 4 5) cmd))
  2101. (if (stringp files) (setq files (list files)))
  2102. (when files
  2103. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2104. (list 'org-agenda nil thiscmdkey)))
  2105. (set-buffer org-agenda-buffer-name)
  2106. (while files
  2107. (eval (list 'let (append org-agenda-exporter-settings opts pars)
  2108. (list 'org-write-agenda
  2109. (expand-file-name (pop files) dir) nil t))))
  2110. (and (get-buffer org-agenda-buffer-name)
  2111. (kill-buffer org-agenda-buffer-name)))))))
  2112. (defun org-agenda-mark-header-line (pos)
  2113. "Mark the line at POS as an agenda structure header."
  2114. (save-excursion
  2115. (goto-char pos)
  2116. (put-text-property (point-at-bol) (point-at-eol)
  2117. 'org-agenda-structural-header t)
  2118. (when org-agenda-title-append
  2119. (put-text-property (point-at-bol) (point-at-eol)
  2120. 'org-agenda-title-append org-agenda-title-append))))
  2121. (defvar org-mobile-creating-agendas)
  2122. (defun org-write-agenda (file &optional open nosettings)
  2123. "Write the current buffer (an agenda view) as a file.
  2124. Depending on the extension of the file name, plain text (.txt),
  2125. HTML (.html or .htm) or Postscript (.ps) is produced.
  2126. If the extension is .ics, run icalendar export over all files used
  2127. to construct the agenda and limit the export to entries listed in the
  2128. agenda now.
  2129. With prefix argument OPEN, open the new file immediately.
  2130. If NOSETTINGS is given, do not scope the settings of
  2131. `org-agenda-exporter-settings' into the export commands. This is used when
  2132. the settings have already been scoped and we do not wish to overrule other,
  2133. higher priority settings."
  2134. (interactive "FWrite agenda to file: \nP")
  2135. (if (not (file-writable-p file))
  2136. (error "Cannot write agenda to file %s" file))
  2137. (cond
  2138. ((string-match "\\.html?\\'" file) (require 'htmlize))
  2139. ((string-match "\\.ps\\'" file) (require 'ps-print)))
  2140. (org-let (if nosettings nil org-agenda-exporter-settings)
  2141. '(save-excursion
  2142. (save-window-excursion
  2143. (org-agenda-mark-filtered-text)
  2144. (let ((bs (copy-sequence (buffer-string))) beg)
  2145. (org-agenda-unmark-filtered-text)
  2146. (with-temp-buffer
  2147. (insert bs)
  2148. (org-agenda-remove-marked-text 'org-filtered)
  2149. (while (setq beg (text-property-any (point-min) (point-max)
  2150. 'org-filtered t))
  2151. (delete-region
  2152. beg (or (next-single-property-change beg 'org-filtered)
  2153. (point-max))))
  2154. (run-hooks 'org-agenda-before-write-hook)
  2155. (cond
  2156. ((org-bound-and-true-p org-mobile-creating-agendas)
  2157. (org-mobile-write-agenda-for-mobile file))
  2158. ((string-match "\\.html?\\'" file)
  2159. (set-buffer (htmlize-buffer (current-buffer)))
  2160. (when (and org-agenda-export-html-style
  2161. (string-match "<style>" org-agenda-export-html-style))
  2162. ;; replace <style> section with org-agenda-export-html-style
  2163. (goto-char (point-min))
  2164. (kill-region (- (search-forward "<style") 6)
  2165. (search-forward "</style>"))
  2166. (insert org-agenda-export-html-style))
  2167. (write-file file)
  2168. (kill-buffer (current-buffer))
  2169. (message "HTML written to %s" file))
  2170. ((string-match "\\.ps\\'" file)
  2171. (require 'ps-print)
  2172. (flet ((ps-get-buffer-name () "Agenda View"))
  2173. (ps-print-buffer-with-faces file))
  2174. (message "Postscript written to %s" file))
  2175. ((string-match "\\.pdf\\'" file)
  2176. (require 'ps-print)
  2177. (flet ((ps-get-buffer-name () "Agenda View"))
  2178. (ps-print-buffer-with-faces
  2179. (concat (file-name-sans-extension file) ".ps")))
  2180. (call-process "ps2pdf" nil nil nil
  2181. (expand-file-name
  2182. (concat (file-name-sans-extension file) ".ps"))
  2183. (expand-file-name file))
  2184. (message "PDF written to %s" file))
  2185. ((string-match "\\.ics\\'" file)
  2186. (require 'org-icalendar)
  2187. (let ((org-agenda-marker-table
  2188. (org-create-marker-find-array
  2189. (org-agenda-collect-markers)))
  2190. (org-icalendar-verify-function 'org-check-agenda-marker-table)
  2191. (org-combined-agenda-icalendar-file file))
  2192. (apply 'org-export-icalendar 'combine
  2193. (org-agenda-files nil 'ifmode))))
  2194. (t
  2195. (let ((bs (buffer-string)))
  2196. (find-file file)
  2197. (erase-buffer)
  2198. (insert bs)
  2199. (save-buffer 0)
  2200. (kill-buffer (current-buffer))
  2201. (message "Plain text written to %s" file))))))))
  2202. (set-buffer org-agenda-buffer-name))
  2203. (when open (org-open-file file)))
  2204. (defvar org-agenda-filter-overlays nil)
  2205. (defun org-agenda-mark-filtered-text ()
  2206. "Mark all text hidden by filtering with a text property."
  2207. (let ((inhibit-read-only t))
  2208. (mapc
  2209. (lambda (o)
  2210. (when (equal (org-overlay-buffer o) (current-buffer))
  2211. (put-text-property
  2212. (org-overlay-start o) (org-overlay-end o)
  2213. 'org-filtered t)))
  2214. org-agenda-filter-overlays)))
  2215. (defun org-agenda-unmark-filtered-text ()
  2216. "Remove the filtering text property."
  2217. (let ((inhibit-read-only t))
  2218. (remove-text-properties (point-min) (point-max) '(org-filtered t))))
  2219. (defun org-agenda-remove-marked-text (property &optional value)
  2220. "Delete all text marked with VALUE of PROPERTY.
  2221. VALUE defaults to t."
  2222. (let (beg)
  2223. (setq value (or value t))
  2224. (while (setq beg (text-property-any (point-min) (point-max)
  2225. property value))
  2226. (delete-region
  2227. beg (or (next-single-property-change beg 'org-filtered)
  2228. (point-max))))))
  2229. (defun org-agenda-add-entry-text ()
  2230. "Add entry text to agenda lines.
  2231. This will add a maximum of `org-agenda-add-entry-text-maxlines' lines of the
  2232. entry text following headings shown in the agenda.
  2233. Drawers will be excluded, also the line with scheduling/deadline info."
  2234. (when (and (> org-agenda-add-entry-text-maxlines 0)
  2235. (not (org-bound-and-true-p org-mobile-creating-agendas)))
  2236. (let (m txt)
  2237. (goto-char (point-min))
  2238. (while (not (eobp))
  2239. (if (not (setq m (org-get-at-bol 'org-hd-marker)))
  2240. (beginning-of-line 2)
  2241. (setq txt (org-agenda-get-some-entry-text
  2242. m org-agenda-add-entry-text-maxlines " > "))
  2243. (end-of-line 1)
  2244. (if (string-match "\\S-" txt) (insert "\n" txt)))))))
  2245. (defun org-agenda-get-some-entry-text (marker n-lines &optional indent
  2246. &rest keep)
  2247. "Extract entry text from MARKER, at most N-LINES lines.
  2248. This will ignore drawers etc, just get the text.
  2249. If INDENT is given, prefix every line with this string. If KEEP is
  2250. given, it is a list of symbols, defining stuff that should not be
  2251. removed from the entry content. Currently only `planning' is allowed here."
  2252. (let (txt drawer-re kwd-time-re ind)
  2253. (save-excursion
  2254. (with-current-buffer (marker-buffer marker)
  2255. (if (not (org-mode-p))
  2256. (setq txt "")
  2257. (save-excursion
  2258. (save-restriction
  2259. (widen)
  2260. (goto-char marker)
  2261. (end-of-line 1)
  2262. (setq txt (buffer-substring
  2263. (min (1+ (point)) (point-max))
  2264. (progn (outline-next-heading) (point)))
  2265. drawer-re org-drawer-regexp
  2266. kwd-time-re (concat "^[ \t]*" org-keyword-time-regexp
  2267. ".*\n?"))
  2268. (with-temp-buffer
  2269. (insert txt)
  2270. (when org-agenda-add-entry-text-descriptive-links
  2271. (goto-char (point-min))
  2272. (while (org-activate-bracket-links (point-max))
  2273. (add-text-properties (match-beginning 0) (match-end 0)
  2274. '(face org-link))))
  2275. (goto-char (point-min))
  2276. (while (re-search-forward org-bracket-link-regexp (point-max) t)
  2277. (set-text-properties (match-beginning 0) (match-end 0)
  2278. nil))
  2279. (goto-char (point-min))
  2280. (while (re-search-forward drawer-re nil t)
  2281. (delete-region
  2282. (match-beginning 0)
  2283. (progn (re-search-forward
  2284. "^[ \t]*:END:.*\n?" nil 'move)
  2285. (point))))
  2286. (unless (member 'planning keep)
  2287. (goto-char (point-min))
  2288. (while (re-search-forward kwd-time-re nil t)
  2289. (replace-match "")))
  2290. (goto-char (point-min))
  2291. (when org-agenda-entry-text-exclude-regexps
  2292. (let ((re-list org-agenda-entry-text-exclude-regexps) re)
  2293. (while (setq re (pop re-list))
  2294. (goto-char (point-min))
  2295. (while (re-search-forward re nil t)
  2296. (replace-match "")))))
  2297. (goto-char (point-max))
  2298. (skip-chars-backward " \t\n")
  2299. (if (looking-at "[ \t\n]+\\'") (replace-match ""))
  2300. ;; find and remove min common indentation
  2301. (goto-char (point-min))
  2302. (untabify (point-min) (point-max))
  2303. (setq ind (org-get-indentation))
  2304. (while (not (eobp))
  2305. (unless (looking-at "[ \t]*$")
  2306. (setq ind (min ind (org-get-indentation))))
  2307. (beginning-of-line 2))
  2308. (goto-char (point-min))
  2309. (while (not (eobp))
  2310. (unless (looking-at "[ \t]*$")
  2311. (move-to-column ind)
  2312. (delete-region (point-at-bol) (point)))
  2313. (beginning-of-line 2))
  2314. (run-hooks 'org-agenda-entry-text-cleanup-hook)
  2315. (goto-char (point-min))
  2316. (when indent
  2317. (while (and (not (eobp)) (re-search-forward "^" nil t))
  2318. (replace-match indent t t)))
  2319. (goto-char (point-min))
  2320. (while (looking-at "[ \t]*\n") (replace-match ""))
  2321. (goto-char (point-max))
  2322. (when (> (org-current-line)
  2323. n-lines)
  2324. (org-goto-line (1+ n-lines))
  2325. (backward-char 1))
  2326. (setq txt (buffer-substring (point-min) (point)))))))))
  2327. txt))
  2328. (defun org-agenda-collect-markers ()
  2329. "Collect the markers pointing to entries in the agenda buffer."
  2330. (let (m markers)
  2331. (save-excursion
  2332. (goto-char (point-min))
  2333. (while (not (eobp))
  2334. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  2335. (org-get-at-bol 'org-marker)))
  2336. (push m markers))
  2337. (beginning-of-line 2)))
  2338. (nreverse markers)))
  2339. (defun org-create-marker-find-array (marker-list)
  2340. "Create a alist of files names with all marker positions in that file."
  2341. (let (f tbl m a p)
  2342. (while (setq m (pop marker-list))
  2343. (setq p (marker-position m)
  2344. f (buffer-file-name (or (buffer-base-buffer
  2345. (marker-buffer m))
  2346. (marker-buffer m))))
  2347. (if (setq a (assoc f tbl))
  2348. (push (marker-position m) (cdr a))
  2349. (push (list f p) tbl)))
  2350. (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
  2351. tbl)))
  2352. (defvar org-agenda-marker-table nil) ; dynamically scoped parameter
  2353. (defun org-check-agenda-marker-table ()
  2354. "Check of the current entry is on the marker list."
  2355. (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
  2356. a)
  2357. (and (setq a (assoc file org-agenda-marker-table))
  2358. (save-match-data
  2359. (save-excursion
  2360. (org-back-to-heading t)
  2361. (member (point) (cdr a)))))))
  2362. (defun org-check-for-org-mode ()
  2363. "Make sure current buffer is in org-mode. Error if not."
  2364. (or (org-mode-p)
  2365. (error "Cannot execute org-mode agenda command on buffer in %s"
  2366. major-mode)))
  2367. (defun org-fit-agenda-window ()
  2368. "Fit the window to the buffer size."
  2369. (and (memq org-agenda-window-setup '(reorganize-frame))
  2370. (fboundp 'fit-window-to-buffer)
  2371. (org-fit-window-to-buffer
  2372. nil
  2373. (floor (* (frame-height) (cdr org-agenda-window-frame-fractions)))
  2374. (floor (* (frame-height) (car org-agenda-window-frame-fractions))))))
  2375. ;;; Agenda prepare and finalize
  2376. (defvar org-agenda-multi nil) ; dynamically scoped
  2377. (defvar org-agenda-buffer-name "*Org Agenda*")
  2378. (defvar org-pre-agenda-window-conf nil)
  2379. (defvar org-agenda-columns-active nil)
  2380. (defvar org-agenda-name nil)
  2381. (defvar org-agenda-filter nil)
  2382. (defvar org-agenda-filter-preset nil
  2383. "A preset of the tags filter used for secondary agenda filtering.
  2384. This must be a list of strings, each string must be a single tag preceeded
  2385. by \"+\" or \"-\".
  2386. This variable should not be set directly, but agenda custom commands can
  2387. bind it in the options section.")
  2388. (defun org-prepare-agenda (&optional name)
  2389. (setq org-todo-keywords-for-agenda nil)
  2390. (setq org-done-keywords-for-agenda nil)
  2391. (setq org-drawers-for-agenda nil)
  2392. (setq org-agenda-filter nil)
  2393. (put 'org-agenda-filter :preset-filter org-agenda-filter-preset)
  2394. (if org-agenda-multi
  2395. (progn
  2396. (setq buffer-read-only nil)
  2397. (goto-char (point-max))
  2398. (unless (or (bobp) org-agenda-compact-blocks)
  2399. (insert "\n"
  2400. (if (stringp org-agenda-block-separator)
  2401. org-agenda-block-separator
  2402. (make-string (window-width) org-agenda-block-separator))
  2403. "\n"))
  2404. (narrow-to-region (point) (point-max)))
  2405. (org-agenda-reset-markers)
  2406. (setq org-agenda-contributing-files nil)
  2407. (setq org-agenda-columns-active nil)
  2408. (org-prepare-agenda-buffers (org-agenda-files nil 'ifmode))
  2409. (setq org-todo-keywords-for-agenda
  2410. (org-uniquify org-todo-keywords-for-agenda))
  2411. (setq org-done-keywords-for-agenda
  2412. (org-uniquify org-done-keywords-for-agenda))
  2413. (setq org-drawers-for-agenda (org-uniquify org-drawers-for-agenda))
  2414. (let* ((abuf (get-buffer-create org-agenda-buffer-name))
  2415. (awin (get-buffer-window abuf)))
  2416. (cond
  2417. ((equal (current-buffer) abuf) nil)
  2418. (awin (select-window awin))
  2419. ((not (setq org-pre-agenda-window-conf (current-window-configuration))))
  2420. ((equal org-agenda-window-setup 'current-window)
  2421. (switch-to-buffer abuf))
  2422. ((equal org-agenda-window-setup 'other-window)
  2423. (org-switch-to-buffer-other-window abuf))
  2424. ((equal org-agenda-window-setup 'other-frame)
  2425. (switch-to-buffer-other-frame abuf))
  2426. ((equal org-agenda-window-setup 'reorganize-frame)
  2427. (delete-other-windows)
  2428. (org-switch-to-buffer-other-window abuf))))
  2429. (setq buffer-read-only nil)
  2430. (let ((inhibit-read-only t)) (erase-buffer))
  2431. (org-agenda-mode)
  2432. (and name (not org-agenda-name)
  2433. (org-set-local 'org-agenda-name name)))
  2434. (setq buffer-read-only nil))
  2435. (defun org-finalize-agenda ()
  2436. "Finishing touch for the agenda buffer, called just before displaying it."
  2437. (unless org-agenda-multi
  2438. (save-excursion
  2439. (let ((inhibit-read-only t))
  2440. (goto-char (point-min))
  2441. (while (org-activate-bracket-links (point-max))
  2442. (add-text-properties (match-beginning 0) (match-end 0)
  2443. '(face org-link)))
  2444. (org-agenda-align-tags)
  2445. (unless org-agenda-with-colors
  2446. (remove-text-properties (point-min) (point-max) '(face nil))))
  2447. (if (and (boundp 'org-agenda-overriding-columns-format)
  2448. org-agenda-overriding-columns-format)
  2449. (org-set-local 'org-agenda-overriding-columns-format
  2450. org-agenda-overriding-columns-format))
  2451. (if (and (boundp 'org-agenda-view-columns-initially)
  2452. org-agenda-view-columns-initially)
  2453. (org-agenda-columns))
  2454. (when org-agenda-fontify-priorities
  2455. (org-agenda-fontify-priorities))
  2456. (when (and org-agenda-dim-blocked-tasks org-blocker-hook)
  2457. (org-agenda-dim-blocked-tasks))
  2458. (org-agenda-mark-clocking-task)
  2459. (when org-agenda-entry-text-mode
  2460. (org-agenda-entry-text-hide)
  2461. (org-agenda-entry-text-show))
  2462. (if (functionp 'org-habit-insert-consistency-graphs)
  2463. (org-habit-insert-consistency-graphs))
  2464. (run-hooks 'org-finalize-agenda-hook)
  2465. (setq org-agenda-type (org-get-at-bol 'org-agenda-type))
  2466. (when (get 'org-agenda-filter :preset-filter)
  2467. (org-agenda-filter-apply org-agenda-filter))
  2468. )))
  2469. (defun org-agenda-mark-clocking-task ()
  2470. "Mark the current clock entry in the agenda if it is present."
  2471. (mapc (lambda (o)
  2472. (if (eq (org-overlay-get o 'type) 'org-agenda-clocking)
  2473. (org-delete-overlay o)))
  2474. (org-overlays-in (point-min) (point-max)))
  2475. (when (marker-buffer org-clock-hd-marker)
  2476. (save-excursion
  2477. (goto-char (point-min))
  2478. (let (s ov)
  2479. (while (setq s (next-single-property-change (point) 'org-hd-marker))
  2480. (goto-char s)
  2481. (when (equal (org-get-at-bol 'org-hd-marker)
  2482. org-clock-hd-marker)
  2483. (setq ov (org-make-overlay (point-at-bol) (1+ (point-at-eol))))
  2484. (org-overlay-put ov 'type 'org-agenda-clocking)
  2485. (org-overlay-put ov 'face 'org-agenda-clocking)
  2486. (org-overlay-put ov 'help-echo
  2487. "The clock is running in this item")))))))
  2488. (defun org-agenda-fontify-priorities ()
  2489. "Make highest priority lines bold, and lowest italic."
  2490. (interactive)
  2491. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-priority)
  2492. (org-delete-overlay o)))
  2493. (org-overlays-in (point-min) (point-max)))
  2494. (save-excursion
  2495. (let ((inhibit-read-only t)
  2496. b e p ov h l)
  2497. (goto-char (point-min))
  2498. (while (re-search-forward "\\[#\\(.\\)\\]" nil t)
  2499. (setq h (or (get-char-property (point) 'org-highest-priority)
  2500. org-highest-priority)
  2501. l (or (get-char-property (point) 'org-lowest-priority)
  2502. org-lowest-priority)
  2503. p (string-to-char (match-string 1))
  2504. b (match-beginning 0)
  2505. e (if (eq org-agenda-fontify-priorities 'cookies)
  2506. (match-end 0)
  2507. (point-at-eol))
  2508. ov (org-make-overlay b e))
  2509. (org-overlay-put
  2510. ov 'face
  2511. (cond ((cdr (assoc p org-priority-faces)))
  2512. ((and (listp org-agenda-fontify-priorities)
  2513. (cdr (assoc p org-agenda-fontify-priorities))))
  2514. ((equal p l) 'italic)
  2515. ((equal p h) 'bold)))
  2516. (org-overlay-put ov 'org-type 'org-priority)))))
  2517. (defun org-agenda-dim-blocked-tasks ()
  2518. "Dim currently blocked TODO's in the agenda display."
  2519. (mapc (lambda (o) (if (eq (org-overlay-get o 'org-type) 'org-blocked-todo)
  2520. (org-delete-overlay o)))
  2521. (org-overlays-in (point-min) (point-max)))
  2522. (save-excursion
  2523. (let ((inhibit-read-only t)
  2524. (org-depend-tag-blocked nil)
  2525. (invis (eq org-agenda-dim-blocked-tasks 'invisible))
  2526. org-blocked-by-checkboxes
  2527. invis1 b e p ov h l)
  2528. (goto-char (point-min))
  2529. (while (let ((pos (next-single-property-change (point) 'todo-state)))
  2530. (and pos (goto-char (1+ pos))))
  2531. (setq org-blocked-by-checkboxes nil invis1 invis)
  2532. (let ((marker (org-get-at-bol 'org-hd-marker)))
  2533. (when (and marker
  2534. (not (with-current-buffer (marker-buffer marker)
  2535. (save-excursion
  2536. (goto-char marker)
  2537. (if (org-entry-get nil "NOBLOCKING")
  2538. t ;; Never block this entry
  2539. (run-hook-with-args-until-failure
  2540. 'org-blocker-hook
  2541. (list :type 'todo-state-change
  2542. :position marker
  2543. :from 'todo
  2544. :to 'done)))))))
  2545. (if org-blocked-by-checkboxes (setq invis1 nil))
  2546. (setq b (if invis1
  2547. (max (point-min) (1- (point-at-bol)))
  2548. (point-at-bol))
  2549. e (point-at-eol)
  2550. ov (org-make-overlay b e))
  2551. (if invis1
  2552. (org-overlay-put ov 'invisible t)
  2553. (org-overlay-put ov 'face 'org-agenda-dimmed-todo-face))
  2554. (org-overlay-put ov 'org-type 'org-blocked-todo)))))))
  2555. (defvar org-agenda-skip-function nil
  2556. "Function to be called at each match during agenda construction.
  2557. If this function returns nil, the current match should not be skipped.
  2558. Otherwise, the function must return a position from where the search
  2559. should be continued.
  2560. This may also be a Lisp form, it will be evaluated.
  2561. Never set this variable using `setq' or so, because then it will apply
  2562. to all future agenda commands. Instead, bind it with `let' to scope
  2563. it dynamically into the agenda-constructing command. A good way to set
  2564. it is through options in org-agenda-custom-commands.")
  2565. (defun org-agenda-skip ()
  2566. "Throw to `:skip' in places that should be skipped.
  2567. Also moves point to the end of the skipped region, so that search can
  2568. continue from there."
  2569. (let ((p (point-at-bol)) to fp)
  2570. (and org-agenda-skip-archived-trees (not org-agenda-archives-mode)
  2571. (get-text-property p :org-archived)
  2572. (org-end-of-subtree t)
  2573. (throw :skip t))
  2574. (and org-agenda-skip-comment-trees
  2575. (get-text-property p :org-comment)
  2576. (org-end-of-subtree t)
  2577. (throw :skip t))
  2578. (if (equal (char-after p) ?#) (throw :skip t))
  2579. (when (and (or (setq fp (functionp org-agenda-skip-function))
  2580. (consp org-agenda-skip-function))
  2581. (setq to (save-excursion
  2582. (save-match-data
  2583. (if fp
  2584. (funcall org-agenda-skip-function)
  2585. (eval org-agenda-skip-function))))))
  2586. (goto-char to)
  2587. (throw :skip t))))
  2588. (defvar org-agenda-markers nil
  2589. "List of all currently active markers created by `org-agenda'.")
  2590. (defvar org-agenda-last-marker-time (org-float-time)
  2591. "Creation time of the last agenda marker.")
  2592. (defun org-agenda-new-marker (&optional pos)
  2593. "Return a new agenda marker.
  2594. Org-mode keeps a list of these markers and resets them when they are
  2595. no longer in use."
  2596. (let ((m (copy-marker (or pos (point)))))
  2597. (setq org-agenda-last-marker-time (org-float-time))
  2598. (push m org-agenda-markers)
  2599. m))
  2600. (defun org-agenda-reset-markers ()
  2601. "Reset markers created by `org-agenda'."
  2602. (while org-agenda-markers
  2603. (move-marker (pop org-agenda-markers) nil)))
  2604. (defun org-agenda-save-markers-for-cut-and-paste (beg end)
  2605. "Save relative positions of markers in region."
  2606. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  2607. org-agenda-markers))
  2608. ;;; Entry text mode
  2609. (defun org-agenda-entry-text-show-here ()
  2610. "Add some text from the entry as context to the current line."
  2611. (let (m txt o)
  2612. (setq m (org-get-at-bol 'org-hd-marker))
  2613. (unless (marker-buffer m)
  2614. (error "No marker points to an entry here"))
  2615. (setq txt (concat "\n" (org-no-properties
  2616. (org-agenda-get-some-entry-text
  2617. m org-agenda-entry-text-maxlines " > "))))
  2618. (when (string-match "\\S-" txt)
  2619. (setq o (org-make-overlay (point-at-bol) (point-at-eol)))
  2620. (org-overlay-put o 'evaporate t)
  2621. (org-overlay-put o 'org-overlay-type 'agenda-entry-content)
  2622. (org-overlay-put o 'after-string txt))))
  2623. (defun org-agenda-entry-text-show ()
  2624. "Add entry context for all agenda lines."
  2625. (interactive)
  2626. (save-excursion
  2627. (goto-char (point-max))
  2628. (beginning-of-line 1)
  2629. (while (not (bobp))
  2630. (when (org-get-at-bol 'org-hd-marker)
  2631. (org-agenda-entry-text-show-here))
  2632. (beginning-of-line 0))))
  2633. (defun org-agenda-entry-text-hide ()
  2634. "Remove any shown entry context."
  2635. (delq nil
  2636. (mapcar (lambda (o)
  2637. (if (eq (org-overlay-get o 'org-overlay-type)
  2638. 'agenda-entry-content)
  2639. (progn (org-delete-overlay o) t)))
  2640. (org-overlays-in (point-min) (point-max)))))
  2641. ;;; Agenda timeline
  2642. (defvar org-agenda-only-exact-dates nil) ; dynamically scoped
  2643. (defun org-timeline (&optional include-all)
  2644. "Show a time-sorted view of the entries in the current org file.
  2645. Only entries with a time stamp of today or later will be listed. With
  2646. \\[universal-argument] prefix, all unfinished TODO items will also be shown,
  2647. under the current date.
  2648. If the buffer contains an active region, only check the region for
  2649. dates."
  2650. (interactive "P")
  2651. (require 'calendar)
  2652. (org-compile-prefix-format 'timeline)
  2653. (org-set-sorting-strategy 'timeline)
  2654. (let* ((dopast t)
  2655. (dotodo include-all)
  2656. (doclosed org-agenda-show-log)
  2657. (entry buffer-file-name)
  2658. (date (calendar-current-date))
  2659. (beg (if (org-region-active-p) (region-beginning) (point-min)))
  2660. (end (if (org-region-active-p) (region-end) (point-max)))
  2661. (day-numbers (org-get-all-dates beg end 'no-ranges
  2662. t doclosed ; always include today
  2663. org-timeline-show-empty-dates))
  2664. (org-deadline-warning-days 0)
  2665. (org-agenda-only-exact-dates t)
  2666. (today (time-to-days (current-time)))
  2667. (past t)
  2668. args
  2669. s e rtn d emptyp wd)
  2670. (setq org-agenda-redo-command
  2671. (list 'progn
  2672. (list 'org-switch-to-buffer-other-window (current-buffer))
  2673. (list 'org-timeline (list 'quote include-all))))
  2674. (if (not dopast)
  2675. ;; Remove past dates from the list of dates.
  2676. (setq day-numbers (delq nil (mapcar (lambda(x)
  2677. (if (>= x today) x nil))
  2678. day-numbers))))
  2679. (org-prepare-agenda (concat "Timeline "
  2680. (file-name-nondirectory buffer-file-name)))
  2681. (if doclosed (push :closed args))
  2682. (push :timestamp args)
  2683. (push :deadline args)
  2684. (push :scheduled args)
  2685. (push :sexp args)
  2686. (if dotodo (push :todo args))
  2687. (insert "Timeline of file " entry "\n")
  2688. (add-text-properties (point-min) (point)
  2689. (list 'face 'org-agenda-structure))
  2690. (org-agenda-mark-header-line (point-min))
  2691. (while (setq d (pop day-numbers))
  2692. (if (and (listp d) (eq (car d) :omitted))
  2693. (progn
  2694. (setq s (point))
  2695. (insert (format "\n[... %d empty days omitted]\n\n" (cdr d)))
  2696. (put-text-property s (1- (point)) 'face 'org-agenda-structure))
  2697. (if (listp d) (setq d (car d) emptyp t) (setq emptyp nil))
  2698. (if (and (>= d today)
  2699. dopast
  2700. past)
  2701. (progn
  2702. (setq past nil)
  2703. (insert (make-string 79 ?-) "\n")))
  2704. (setq date (calendar-gregorian-from-absolute d)
  2705. wd (calendar-day-of-week date))
  2706. (setq s (point))
  2707. (setq rtn (and (not emptyp)
  2708. (apply 'org-agenda-get-day-entries entry
  2709. date args)))
  2710. (if (or rtn (equal d today) org-timeline-show-empty-dates)
  2711. (progn
  2712. (insert
  2713. (if (stringp org-agenda-format-date)
  2714. (format-time-string org-agenda-format-date
  2715. (org-time-from-absolute date))
  2716. (funcall org-agenda-format-date date))
  2717. "\n")
  2718. (put-text-property s (1- (point)) 'face
  2719. (if (member wd org-agenda-weekend-days)
  2720. 'org-agenda-date-weekend
  2721. 'org-agenda-date))
  2722. (put-text-property s (1- (point)) 'org-date-line t)
  2723. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2724. (if (equal d today)
  2725. (put-text-property s (1- (point)) 'org-today t))
  2726. (and rtn (insert (org-finalize-agenda-entries rtn) "\n"))
  2727. (put-text-property s (1- (point)) 'day d)))))
  2728. (goto-char (point-min))
  2729. (goto-char (or (text-property-any (point-min) (point-max) 'org-today t)
  2730. (point-min)))
  2731. (add-text-properties (point-min) (point-max) '(org-agenda-type timeline))
  2732. (org-finalize-agenda)
  2733. (setq buffer-read-only t)))
  2734. (defun org-get-all-dates (beg end &optional no-ranges force-today inactive empty pre-re)
  2735. "Return a list of all relevant day numbers from BEG to END buffer positions.
  2736. If NO-RANGES is non-nil, include only the start and end dates of a range,
  2737. not every single day in the range. If FORCE-TODAY is non-nil, make
  2738. sure that TODAY is included in the list. If INACTIVE is non-nil, also
  2739. inactive time stamps (those in square brackets) are included.
  2740. When EMPTY is non-nil, also include days without any entries."
  2741. (let ((re (concat
  2742. (if pre-re pre-re "")
  2743. (if inactive org-ts-regexp-both org-ts-regexp)))
  2744. dates dates1 date day day1 day2 ts1 ts2)
  2745. (if force-today
  2746. (setq dates (list (time-to-days (current-time)))))
  2747. (save-excursion
  2748. (goto-char beg)
  2749. (while (re-search-forward re end t)
  2750. (setq day (time-to-days (org-time-string-to-time
  2751. (substring (match-string 1) 0 10))))
  2752. (or (memq day dates) (push day dates)))
  2753. (unless no-ranges
  2754. (goto-char beg)
  2755. (while (re-search-forward org-tr-regexp end t)
  2756. (setq ts1 (substring (match-string 1) 0 10)
  2757. ts2 (substring (match-string 2) 0 10)
  2758. day1 (time-to-days (org-time-string-to-time ts1))
  2759. day2 (time-to-days (org-time-string-to-time ts2)))
  2760. (while (< (setq day1 (1+ day1)) day2)
  2761. (or (memq day1 dates) (push day1 dates)))))
  2762. (setq dates (sort dates '<))
  2763. (when empty
  2764. (while (setq day (pop dates))
  2765. (setq day2 (car dates))
  2766. (push day dates1)
  2767. (when (and day2 empty)
  2768. (if (or (eq empty t)
  2769. (and (numberp empty) (<= (- day2 day) empty)))
  2770. (while (< (setq day (1+ day)) day2)
  2771. (push (list day) dates1))
  2772. (push (cons :omitted (- day2 day)) dates1))))
  2773. (setq dates (nreverse dates1)))
  2774. dates)))
  2775. ;;; Agenda Daily/Weekly
  2776. (defvar org-agenda-overriding-arguments nil) ; dynamically scoped parameter
  2777. (defvar org-agenda-start-day nil ; dynamically scoped parameter
  2778. "Custom commands can set this variable in the options section.")
  2779. (defvar org-agenda-last-arguments nil
  2780. "The arguments of the previous call to org-agenda")
  2781. (defvar org-starting-day nil) ; local variable in the agenda buffer
  2782. (defvar org-agenda-span nil) ; local variable in the agenda buffer
  2783. (defvar org-include-all-loc nil) ; local variable
  2784. ;;;###autoload
  2785. (defun org-agenda-list (&optional include-all start-day ndays)
  2786. "Produce a daily/weekly view from all files in variable `org-agenda-files'.
  2787. The view will be for the current day or week, but from the overview buffer
  2788. you will be able to go to other days/weeks.
  2789. With one \\[universal-argument] prefix argument INCLUDE-ALL,
  2790. all unfinished TODO items will also be shown, before the agenda.
  2791. This feature is considered obsolete, please use the TODO list or a block
  2792. agenda instead.
  2793. With a numeric prefix argument in an interactive call, the agenda will
  2794. span INCLUDE-ALL days. Lisp programs should instead specify NDAYS to change
  2795. the number of days. NDAYS defaults to `org-agenda-ndays'.
  2796. START-DAY defaults to TODAY, or to the most recent match for the weekday
  2797. given in `org-agenda-start-on-weekday'."
  2798. (interactive "P")
  2799. (if (and (integerp include-all) (> include-all 0))
  2800. (setq ndays include-all include-all nil))
  2801. (setq ndays (or ndays org-agenda-ndays)
  2802. start-day (or start-day org-agenda-start-day))
  2803. (if org-agenda-overriding-arguments
  2804. (setq include-all (car org-agenda-overriding-arguments)
  2805. start-day (nth 1 org-agenda-overriding-arguments)
  2806. ndays (nth 2 org-agenda-overriding-arguments)))
  2807. (if (stringp start-day)
  2808. ;; Convert to an absolute day number
  2809. (setq start-day (time-to-days (org-read-date nil t start-day))))
  2810. (setq org-agenda-last-arguments (list include-all start-day ndays))
  2811. (org-compile-prefix-format 'agenda)
  2812. (org-set-sorting-strategy 'agenda)
  2813. (require 'calendar)
  2814. (let* ((org-agenda-start-on-weekday
  2815. (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
  2816. org-agenda-start-on-weekday nil))
  2817. (thefiles (org-agenda-files nil 'ifmode))
  2818. (files thefiles)
  2819. (today (time-to-days
  2820. (time-subtract (current-time)
  2821. (list 0 (* 3600 org-extend-today-until) 0))))
  2822. (sd (or start-day today))
  2823. (start (if (or (null org-agenda-start-on-weekday)
  2824. (< org-agenda-ndays 7))
  2825. sd
  2826. (let* ((nt (calendar-day-of-week
  2827. (calendar-gregorian-from-absolute sd)))
  2828. (n1 org-agenda-start-on-weekday)
  2829. (d (- nt n1)))
  2830. (- sd (+ (if (< d 0) 7 0) d)))))
  2831. (day-numbers (list start))
  2832. (day-cnt 0)
  2833. (inhibit-redisplay (not debug-on-error))
  2834. s e rtn rtnall file date d start-pos end-pos todayp nd wd
  2835. clocktable-start clocktable-end)
  2836. (setq org-agenda-redo-command
  2837. (list 'org-agenda-list (list 'quote include-all) start-day ndays))
  2838. ;; Make the list of days
  2839. (setq ndays (or ndays org-agenda-ndays)
  2840. nd ndays)
  2841. (while (> ndays 1)
  2842. (push (1+ (car day-numbers)) day-numbers)
  2843. (setq ndays (1- ndays)))
  2844. (setq day-numbers (nreverse day-numbers))
  2845. (setq clocktable-start (car day-numbers)
  2846. clocktable-end (1+ (or (org-last day-numbers) 0)))
  2847. (org-prepare-agenda "Day/Week")
  2848. (org-set-local 'org-starting-day (car day-numbers))
  2849. (org-set-local 'org-include-all-loc include-all)
  2850. (org-set-local 'org-agenda-span
  2851. (org-agenda-ndays-to-span nd))
  2852. (when (and (or include-all org-agenda-include-all-todo)
  2853. (member today day-numbers))
  2854. (setq files thefiles
  2855. rtnall nil)
  2856. (while (setq file (pop files))
  2857. (catch 'nextfile
  2858. (org-check-agenda-file file)
  2859. (setq date (calendar-gregorian-from-absolute today)
  2860. rtn (org-agenda-get-day-entries
  2861. file date :todo))
  2862. (setq rtnall (append rtnall rtn))))
  2863. (when rtnall
  2864. (insert "All currently open TODO items:\n")
  2865. (add-text-properties (point-min) (1- (point))
  2866. (list 'face 'org-agenda-structure
  2867. 'short-heading "All TODO items"))
  2868. (org-agenda-mark-header-line (point-min))
  2869. (insert (org-finalize-agenda-entries rtnall) "\n")))
  2870. (unless org-agenda-compact-blocks
  2871. (let* ((d1 (car day-numbers))
  2872. (d2 (org-last day-numbers))
  2873. (w1 (org-days-to-iso-week d1))
  2874. (w2 (org-days-to-iso-week d2)))
  2875. (setq s (point))
  2876. (if org-agenda-overriding-header
  2877. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  2878. nil 'face 'org-agenda-structure) "\n")
  2879. (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
  2880. "-agenda"
  2881. (if (< (- d2 d1) 350)
  2882. (if (= w1 w2)
  2883. (format " (W%02d)" w1)
  2884. (format " (W%02d-W%02d)" w1 w2))
  2885. "")
  2886. ":\n")))
  2887. (add-text-properties s (1- (point)) (list 'face 'org-agenda-structure
  2888. 'org-date-line t))
  2889. (org-agenda-mark-header-line s))
  2890. (while (setq d (pop day-numbers))
  2891. (setq date (calendar-gregorian-from-absolute d)
  2892. wd (calendar-day-of-week date)
  2893. s (point))
  2894. (if (or (setq todayp (= d today))
  2895. (and (not start-pos) (= d sd)))
  2896. (setq start-pos (point))
  2897. (if (and start-pos (not end-pos))
  2898. (setq end-pos (point))))
  2899. (setq files thefiles
  2900. rtnall nil)
  2901. (while (setq file (pop files))
  2902. (catch 'nextfile
  2903. (org-check-agenda-file file)
  2904. (cond
  2905. ((eq org-agenda-show-log 'only)
  2906. (setq rtn (org-agenda-get-day-entries
  2907. file date :closed)))
  2908. (org-agenda-show-log
  2909. (setq rtn (org-agenda-get-day-entries
  2910. file date
  2911. :deadline :scheduled :timestamp :sexp :closed)))
  2912. (t
  2913. (setq rtn (org-agenda-get-day-entries
  2914. file date
  2915. :deadline :scheduled :sexp :timestamp))))
  2916. (setq rtnall (append rtnall rtn))))
  2917. (if org-agenda-include-diary
  2918. (let ((org-agenda-search-headline-for-time t))
  2919. (require 'diary-lib)
  2920. (setq rtn (org-get-entries-from-diary date))
  2921. (setq rtnall (append rtnall rtn))))
  2922. (if (or rtnall org-agenda-show-all-dates)
  2923. (progn
  2924. (setq day-cnt (1+ day-cnt))
  2925. (insert
  2926. (if (stringp org-agenda-format-date)
  2927. (format-time-string org-agenda-format-date
  2928. (org-time-from-absolute date))
  2929. (funcall org-agenda-format-date date))
  2930. "\n")
  2931. (put-text-property s (1- (point)) 'face
  2932. (if (member wd org-agenda-weekend-days)
  2933. 'org-agenda-date-weekend
  2934. 'org-agenda-date))
  2935. (put-text-property s (1- (point)) 'org-date-line t)
  2936. (put-text-property s (1- (point)) 'org-agenda-date-header t)
  2937. (put-text-property s (1- (point)) 'org-day-cnt day-cnt)
  2938. (when todayp
  2939. (put-text-property s (1- (point)) 'org-today t)
  2940. (put-text-property s (1- (point)) 'face 'org-agenda-date-today))
  2941. (if rtnall (insert
  2942. (org-finalize-agenda-entries
  2943. (org-agenda-add-time-grid-maybe
  2944. rtnall nd todayp))
  2945. "\n"))
  2946. (put-text-property s (1- (point)) 'day d)
  2947. (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
  2948. (when (and org-agenda-clockreport-mode clocktable-start)
  2949. (let ((org-agenda-files (org-agenda-files nil 'ifmode))
  2950. ;; the above line is to ensure the restricted range!
  2951. (p org-agenda-clockreport-parameter-plist)
  2952. tbl)
  2953. (setq p (org-plist-delete p :block))
  2954. (setq p (plist-put p :tstart clocktable-start))
  2955. (setq p (plist-put p :tend clocktable-end))
  2956. (setq p (plist-put p :scope 'agenda))
  2957. (setq tbl (apply 'org-get-clocktable p))
  2958. (insert tbl)))
  2959. (goto-char (point-min))
  2960. (or org-agenda-multi (org-fit-agenda-window))
  2961. (unless (and (pos-visible-in-window-p (point-min))
  2962. (pos-visible-in-window-p (point-max)))
  2963. (goto-char (1- (point-max)))
  2964. (recenter -1)
  2965. (if (not (pos-visible-in-window-p (or start-pos 1)))
  2966. (progn
  2967. (goto-char (or start-pos 1))
  2968. (recenter 1))))
  2969. (goto-char (or start-pos 1))
  2970. (add-text-properties (point-min) (point-max) '(org-agenda-type agenda))
  2971. (org-finalize-agenda)
  2972. (setq buffer-read-only t)
  2973. (message "")))
  2974. (defun org-agenda-ndays-to-span (n)
  2975. (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
  2976. ;;; Agenda word search
  2977. (defvar org-agenda-search-history nil)
  2978. (defvar org-todo-only nil)
  2979. (defvar org-search-syntax-table nil
  2980. "Special syntax table for org-mode search.
  2981. In this table, we have single quotes not as word constituents, to
  2982. that when \"+Ameli\" is searched as a work, it will also match \"Ameli's\"")
  2983. (defun org-search-syntax-table ()
  2984. (unless org-search-syntax-table
  2985. (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
  2986. (modify-syntax-entry ?' "." org-search-syntax-table)
  2987. (modify-syntax-entry ?` "." org-search-syntax-table))
  2988. org-search-syntax-table)
  2989. (defvar org-agenda-last-search-view-search-was-boolean nil)
  2990. ;;;###autoload
  2991. (defun org-search-view (&optional todo-only string edit-at)
  2992. "Show all entries that contain a phrase or words or regular expressions.
  2993. With optional prefix argument TODO-ONLY, only consider entries that are
  2994. TODO entries. The argument STRING can be used to pass a default search
  2995. string into this function. If EDIT-AT is non-nil, it means that the
  2996. user should get a chance to edit this string, with cursor at position
  2997. EDIT-AT.
  2998. The search string can be viewed either as a phrase that should be found as
  2999. is, or it can be broken into a number of snippets, each of which must match
  3000. in a Boolean way to select an entry. The default depends on the variable
  3001. `org-agenda-search-view-always-boolean'.
  3002. Even if this is turned off (the default) you can always switch to
  3003. Boolean search dynamically by preceeding the first word with \"+\" or \"-\".
  3004. The default is a direct search of the whole phrase, where each space in
  3005. the search string can expand to an arbitrary amount of whitespace,
  3006. including newlines.
  3007. If using a Boolean search, the search string is split on whitespace and
  3008. each snippet is searched separately, with logical AND to select an entry.
  3009. Words prefixed with a minus must *not* occur in the entry. Words without
  3010. a prefix or prefixed with a plus must occur in the entry. Matching is
  3011. case-insensitive. Words are enclosed by word delimiters (i.e. they must
  3012. match whole words, not parts of a word) if
  3013. `org-agenda-search-view-force-full-words' is set (default is nil).
  3014. Boolean search snippets enclosed by curly braces are interpreted as
  3015. regular expressions that must or (when preceeded with \"-\") must not
  3016. match in the entry. Snippets enclosed into double quotes will be taken
  3017. as a whole, to incude whitespace.
  3018. - If the search string starts with an asterisk, search only in headlines.
  3019. - If (possibly after the leading star) the search string starts with an
  3020. exclamation mark, this also means to look at TODO entries only, an effect
  3021. that can also be achieved with a prefix argument.
  3022. - If (possibly after star and exclamation mark) the search string starts
  3023. with a colon, this will mean that the (non-regexp) snippets of the
  3024. Boolean search must match as full words.
  3025. This command searches the agenda files, and in addition the files listed
  3026. in `org-agenda-text-search-extra-files'."
  3027. (interactive "P")
  3028. (org-compile-prefix-format 'search)
  3029. (org-set-sorting-strategy 'search)
  3030. (org-prepare-agenda "SEARCH")
  3031. (let* ((props (list 'face nil
  3032. 'done-face 'org-agenda-done
  3033. 'org-not-done-regexp org-not-done-regexp
  3034. 'org-todo-regexp org-todo-regexp
  3035. 'org-complex-heading-regexp org-complex-heading-regexp
  3036. 'mouse-face 'highlight
  3037. 'help-echo (format "mouse-2 or RET jump to location")))
  3038. (full-words org-agenda-search-view-force-full-words)
  3039. regexp rtn rtnall files file pos
  3040. marker category tags c neg re boolean
  3041. ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
  3042. (unless (and (not edit-at)
  3043. (stringp string)
  3044. (string-match "\\S-" string))
  3045. (setq string (read-string
  3046. (if org-agenda-search-view-always-boolean
  3047. "[+-]Word/{Regexp} ...: "
  3048. "Phrase, or [+-]Word/{Regexp} ...: ")
  3049. (cond
  3050. ((integerp edit-at) (cons string edit-at))
  3051. (edit-at string))
  3052. 'org-agenda-search-history)))
  3053. (org-set-local 'org-todo-only todo-only)
  3054. (setq org-agenda-redo-command
  3055. (list 'org-search-view (if todo-only t nil) string
  3056. '(if current-prefix-arg 1 nil)))
  3057. (setq org-agenda-query-string string)
  3058. (if (equal (string-to-char string) ?*)
  3059. (setq hdl-only t
  3060. words (substring string 1))
  3061. (setq words string))
  3062. (when (equal (string-to-char words) ?!)
  3063. (setq todo-only t
  3064. words (substring words 1)))
  3065. (when (equal (string-to-char words) ?:)
  3066. (setq full-words t
  3067. words (substring words 1)))
  3068. (if (or org-agenda-search-view-always-boolean
  3069. (member (string-to-char string) '(?- ?+ ?\{)))
  3070. (setq boolean t))
  3071. (setq words (org-split-string words))
  3072. (setq org-agenda-last-search-view-search-was-boolean boolean)
  3073. (when boolean
  3074. (let (wds w)
  3075. (while (setq w (pop words))
  3076. (if (or (equal (substring w 0 1) "\"")
  3077. (and (> (length w) 1)
  3078. (member (substring w 0 1) '("+" "-"))
  3079. (equal (substring w 1 2) "\"")))
  3080. (while (and words (not (equal (substring w -1) "\"")))
  3081. (setq w (concat w " " (pop words)))))
  3082. (and (string-match "\\`\\([-+]?\\)\"" w)
  3083. (setq w (replace-match "\\1" nil nil w)))
  3084. (and (equal (substring w -1) "\"") (setq w (substring w 0 -1)))
  3085. (push w wds))
  3086. (setq words (nreverse wds))))
  3087. (if boolean
  3088. (mapc (lambda (w)
  3089. (setq c (string-to-char w))
  3090. (if (equal c ?-)
  3091. (setq neg t w (substring w 1))
  3092. (if (equal c ?+)
  3093. (setq neg nil w (substring w 1))
  3094. (setq neg nil)))
  3095. (if (string-match "\\`{.*}\\'" w)
  3096. (setq re (substring w 1 -1))
  3097. (if full-words
  3098. (setq re (concat "\\<" (regexp-quote (downcase w)) "\\>"))
  3099. (setq re (regexp-quote (downcase w)))))
  3100. (if neg (push re regexps-) (push re regexps+)))
  3101. words)
  3102. (push (mapconcat (lambda (w) (regexp-quote w)) words "\\s-+")
  3103. regexps+))
  3104. (setq regexps+ (sort regexps+ (lambda (a b) (> (length a) (length b)))))
  3105. (if (not regexps+)
  3106. (setq regexp (concat "^" org-outline-regexp))
  3107. (setq regexp (pop regexps+))
  3108. (if hdl-only (setq regexp (concat "^" org-outline-regexp ".*?"
  3109. regexp))))
  3110. (setq files (org-agenda-files nil 'ifmode))
  3111. (when (eq (car org-agenda-text-search-extra-files) 'agenda-archives)
  3112. (pop org-agenda-text-search-extra-files)
  3113. (setq files (org-add-archive-files files)))
  3114. (setq files (append files org-agenda-text-search-extra-files)
  3115. rtnall nil)
  3116. (while (setq file (pop files))
  3117. (setq ee nil)
  3118. (catch 'nextfile
  3119. (org-check-agenda-file file)
  3120. (setq buffer (if (file-exists-p file)
  3121. (org-get-agenda-file-buffer file)
  3122. (error "No such file %s" file)))
  3123. (if (not buffer)
  3124. ;; If file does not exist, make sure an error message is sent
  3125. (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
  3126. file))))
  3127. (with-current-buffer buffer
  3128. (with-syntax-table (org-search-syntax-table)
  3129. (unless (org-mode-p)
  3130. (error "Agenda file %s is not in `org-mode'" file))
  3131. (let ((case-fold-search t))
  3132. (save-excursion
  3133. (save-restriction
  3134. (if org-agenda-restrict
  3135. (narrow-to-region org-agenda-restrict-begin
  3136. org-agenda-restrict-end)
  3137. (widen))
  3138. (goto-char (point-min))
  3139. (unless (or (org-on-heading-p)
  3140. (outline-next-heading))
  3141. (throw 'nextfile t))
  3142. (goto-char (max (point-min) (1- (point))))
  3143. (while (re-search-forward regexp nil t)
  3144. (org-back-to-heading t)
  3145. (skip-chars-forward "* ")
  3146. (setq beg (point-at-bol)
  3147. beg1 (point)
  3148. end (progn (outline-next-heading) (point)))
  3149. (catch :skip
  3150. (goto-char beg)
  3151. (org-agenda-skip)
  3152. (setq str (buffer-substring-no-properties
  3153. (point-at-bol)
  3154. (if hdl-only (point-at-eol) end)))
  3155. (mapc (lambda (wr) (when (string-match wr str)
  3156. (goto-char (1- end))
  3157. (throw :skip t)))
  3158. regexps-)
  3159. (mapc (lambda (wr) (unless (string-match wr str)
  3160. (goto-char (1- end))
  3161. (throw :skip t)))
  3162. (if todo-only
  3163. (cons (concat "^\*+[ \t]+" org-not-done-regexp)
  3164. regexps+)
  3165. regexps+))
  3166. (goto-char beg)
  3167. (setq marker (org-agenda-new-marker (point))
  3168. category (org-get-category)
  3169. tags (org-get-tags-at (point))
  3170. txt (org-format-agenda-item
  3171. ""
  3172. (buffer-substring-no-properties
  3173. beg1 (point-at-eol))
  3174. category tags))
  3175. (org-add-props txt props
  3176. 'org-marker marker 'org-hd-marker marker
  3177. 'org-todo-regexp org-todo-regexp
  3178. 'org-complex-heading-regexp org-complex-heading-regexp
  3179. 'priority 1000 'org-category category
  3180. 'type "search")
  3181. (push txt ee)
  3182. (goto-char (1- end))))))))))
  3183. (setq rtn (nreverse ee))
  3184. (setq rtnall (append rtnall rtn)))
  3185. (if org-agenda-overriding-header
  3186. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3187. nil 'face 'org-agenda-structure) "\n")
  3188. (insert "Search words: ")
  3189. (add-text-properties (point-min) (1- (point))
  3190. (list 'face 'org-agenda-structure))
  3191. (setq pos (point))
  3192. (insert string "\n")
  3193. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3194. (setq pos (point))
  3195. (unless org-agenda-multi
  3196. (insert "Press `[', `]' to add/sub word, `{', `}' to add/sub regexp, `C-u r' to edit\n")
  3197. (add-text-properties pos (1- (point))
  3198. (list 'face 'org-agenda-structure))))
  3199. (org-agenda-mark-header-line (point-min))
  3200. (when rtnall
  3201. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3202. (goto-char (point-min))
  3203. (or org-agenda-multi (org-fit-agenda-window))
  3204. (add-text-properties (point-min) (point-max) '(org-agenda-type search))
  3205. (org-finalize-agenda)
  3206. (setq buffer-read-only t)))
  3207. ;;; Agenda TODO list
  3208. (defvar org-select-this-todo-keyword nil)
  3209. (defvar org-last-arg nil)
  3210. ;;;###autoload
  3211. (defun org-todo-list (arg)
  3212. "Show all TODO entries from all agenda file in a single list.
  3213. The prefix arg can be used to select a specific TODO keyword and limit
  3214. the list to these. When using \\[universal-argument], you will be prompted
  3215. for a keyword. A numeric prefix directly selects the Nth keyword in
  3216. `org-todo-keywords-1'."
  3217. (interactive "P")
  3218. (require 'calendar)
  3219. (org-compile-prefix-format 'todo)
  3220. (org-set-sorting-strategy 'todo)
  3221. (org-prepare-agenda "TODO")
  3222. (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
  3223. (let* ((today (time-to-days (current-time)))
  3224. (date (calendar-gregorian-from-absolute today))
  3225. (kwds org-todo-keywords-for-agenda)
  3226. (completion-ignore-case t)
  3227. (org-select-this-todo-keyword
  3228. (if (stringp arg) arg
  3229. (and arg (integerp arg) (> arg 0)
  3230. (nth (1- arg) kwds))))
  3231. rtn rtnall files file pos)
  3232. (when (equal arg '(4))
  3233. (setq org-select-this-todo-keyword
  3234. (org-icompleting-read "Keyword (or KWD1|K2D2|...): "
  3235. (mapcar 'list kwds) nil nil)))
  3236. (and (equal 0 arg) (setq org-select-this-todo-keyword nil))
  3237. (org-set-local 'org-last-arg arg)
  3238. (setq org-agenda-redo-command
  3239. '(org-todo-list (or current-prefix-arg org-last-arg)))
  3240. (setq files (org-agenda-files nil 'ifmode)
  3241. rtnall nil)
  3242. (while (setq file (pop files))
  3243. (catch 'nextfile
  3244. (org-check-agenda-file file)
  3245. (setq rtn (org-agenda-get-day-entries file date :todo))
  3246. (setq rtnall (append rtnall rtn))))
  3247. (if org-agenda-overriding-header
  3248. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3249. nil 'face 'org-agenda-structure) "\n")
  3250. (insert "Global list of TODO items of type: ")
  3251. (add-text-properties (point-min) (1- (point))
  3252. (list 'face 'org-agenda-structure
  3253. 'short-heading
  3254. (concat "ToDo: "
  3255. (or org-select-this-todo-keyword "ALL"))))
  3256. (org-agenda-mark-header-line (point-min))
  3257. (setq pos (point))
  3258. (insert (or org-select-this-todo-keyword "ALL") "\n")
  3259. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3260. (setq pos (point))
  3261. (unless org-agenda-multi
  3262. (insert "Available with `N r': (0)ALL")
  3263. (let ((n 0) s)
  3264. (mapc (lambda (x)
  3265. (setq s (format "(%d)%s" (setq n (1+ n)) x))
  3266. (if (> (+ (current-column) (string-width s) 1) (frame-width))
  3267. (insert "\n "))
  3268. (insert " " s))
  3269. kwds))
  3270. (insert "\n"))
  3271. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3272. (org-agenda-mark-header-line (point-min))
  3273. (when rtnall
  3274. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3275. (goto-char (point-min))
  3276. (or org-agenda-multi (org-fit-agenda-window))
  3277. (add-text-properties (point-min) (point-max) '(org-agenda-type todo))
  3278. (org-finalize-agenda)
  3279. (setq buffer-read-only t)))
  3280. ;;; Agenda tags match
  3281. ;;;###autoload
  3282. (defun org-tags-view (&optional todo-only match)
  3283. "Show all headlines for all `org-agenda-files' matching a TAGS criterion.
  3284. The prefix arg TODO-ONLY limits the search to TODO entries."
  3285. (interactive "P")
  3286. (org-compile-prefix-format 'tags)
  3287. (org-set-sorting-strategy 'tags)
  3288. (let* ((org-tags-match-list-sublevels
  3289. org-tags-match-list-sublevels)
  3290. (completion-ignore-case t)
  3291. rtn rtnall files file pos matcher
  3292. buffer)
  3293. (when (and (stringp match) (not (string-match "\\S-" match)))
  3294. (setq match nil))
  3295. (setq matcher (org-make-tags-matcher match)
  3296. match (car matcher) matcher (cdr matcher))
  3297. (org-prepare-agenda (concat "TAGS " match))
  3298. (setq org-agenda-query-string match)
  3299. (setq org-agenda-redo-command
  3300. (list 'org-tags-view (list 'quote todo-only)
  3301. (list 'if 'current-prefix-arg nil 'org-agenda-query-string)))
  3302. (setq files (org-agenda-files nil 'ifmode)
  3303. rtnall nil)
  3304. (while (setq file (pop files))
  3305. (catch 'nextfile
  3306. (org-check-agenda-file file)
  3307. (setq buffer (if (file-exists-p file)
  3308. (org-get-agenda-file-buffer file)
  3309. (error "No such file %s" file)))
  3310. (if (not buffer)
  3311. ;; If file does not exist, error message to agenda
  3312. (setq rtn (list
  3313. (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3314. rtnall (append rtnall rtn))
  3315. (with-current-buffer buffer
  3316. (unless (org-mode-p)
  3317. (error "Agenda file %s is not in `org-mode'" file))
  3318. (save-excursion
  3319. (save-restriction
  3320. (if org-agenda-restrict
  3321. (narrow-to-region org-agenda-restrict-begin
  3322. org-agenda-restrict-end)
  3323. (widen))
  3324. (setq rtn (org-scan-tags 'agenda matcher todo-only))
  3325. (setq rtnall (append rtnall rtn))))))))
  3326. (if org-agenda-overriding-header
  3327. (insert (org-add-props (copy-sequence org-agenda-overriding-header)
  3328. nil 'face 'org-agenda-structure) "\n")
  3329. (insert "Headlines with TAGS match: ")
  3330. (add-text-properties (point-min) (1- (point))
  3331. (list 'face 'org-agenda-structure
  3332. 'short-heading
  3333. (concat "Match: " match)))
  3334. (setq pos (point))
  3335. (insert match "\n")
  3336. (add-text-properties pos (1- (point)) (list 'face 'org-warning))
  3337. (setq pos (point))
  3338. (unless org-agenda-multi
  3339. (insert "Press `C-u r' to search again with new search string\n"))
  3340. (add-text-properties pos (1- (point)) (list 'face 'org-agenda-structure)))
  3341. (org-agenda-mark-header-line (point-min))
  3342. (when rtnall
  3343. (insert (org-finalize-agenda-entries rtnall) "\n"))
  3344. (goto-char (point-min))
  3345. (or org-agenda-multi (org-fit-agenda-window))
  3346. (add-text-properties (point-min) (point-max) '(org-agenda-type tags))
  3347. (org-finalize-agenda)
  3348. (setq buffer-read-only t)))
  3349. ;;; Agenda Finding stuck projects
  3350. (defvar org-agenda-skip-regexp nil
  3351. "Regular expression used in skipping subtrees for the agenda.
  3352. This is basically a temporary global variable that can be set and then
  3353. used by user-defined selections using `org-agenda-skip-function'.")
  3354. (defvar org-agenda-overriding-header nil
  3355. "When this is set during todo and tags searches, will replace header.
  3356. This variable should not be set directly, but custom commands can bind it
  3357. in the options section.")
  3358. (defun org-agenda-skip-entry-when-regexp-matches ()
  3359. "Checks if the current entry contains match for `org-agenda-skip-regexp'.
  3360. If yes, it returns the end position of this entry, causing agenda commands
  3361. to skip the entry but continuing the search in the subtree. This is a
  3362. function that can be put into `org-agenda-skip-function' for the duration
  3363. of a command."
  3364. (let ((end (save-excursion (org-end-of-subtree t)))
  3365. skip)
  3366. (save-excursion
  3367. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3368. (and skip end)))
  3369. (defun org-agenda-skip-subtree-when-regexp-matches ()
  3370. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3371. If yes, it returns the end position of this tree, causing agenda commands
  3372. to skip this subtree. This is a function that can be put into
  3373. `org-agenda-skip-function' for the duration of a command."
  3374. (let ((end (save-excursion (org-end-of-subtree t)))
  3375. skip)
  3376. (save-excursion
  3377. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3378. (and skip end)))
  3379. (defun org-agenda-skip-entry-when-regexp-matches-in-subtree ()
  3380. "Checks if the current subtree contains match for `org-agenda-skip-regexp'.
  3381. If yes, it returns the end position of the current entry (NOT the tree),
  3382. causing agenda commands to skip the entry but continuing the search in
  3383. the subtree. This is a function that can be put into
  3384. `org-agenda-skip-function' for the duration of a command. An important
  3385. use of this function is for the stuck project list."
  3386. (let ((end (save-excursion (org-end-of-subtree t)))
  3387. (entry-end (save-excursion (outline-next-heading) (1- (point))))
  3388. skip)
  3389. (save-excursion
  3390. (setq skip (re-search-forward org-agenda-skip-regexp end t)))
  3391. (and skip entry-end)))
  3392. (defun org-agenda-skip-entry-if (&rest conditions)
  3393. "Skip entry if any of CONDITIONS is true.
  3394. See `org-agenda-skip-if' for details."
  3395. (org-agenda-skip-if nil conditions))
  3396. (defun org-agenda-skip-subtree-if (&rest conditions)
  3397. "Skip entry if any of CONDITIONS is true.
  3398. See `org-agenda-skip-if' for details."
  3399. (org-agenda-skip-if t conditions))
  3400. (defun org-agenda-skip-if (subtree conditions)
  3401. "Checks current entity for CONDITIONS.
  3402. If SUBTREE is non-nil, the entire subtree is checked. Otherwise, only
  3403. the entry, i.e. the text before the next heading is checked.
  3404. CONDITIONS is a list of symbols, boolean OR is used to combine the results
  3405. from different tests. Valid conditions are:
  3406. scheduled Check if there is a scheduled cookie
  3407. notscheduled Check if there is no scheduled cookie
  3408. deadline Check if there is a deadline
  3409. notdeadline Check if there is no deadline
  3410. timestamp Check if there is a timestamp (also deadline or scheduled)
  3411. nottimestamp Check if there is no timestamp (also deadline or scheduled)
  3412. regexp Check if regexp matches
  3413. notregexp Check if regexp does not match.
  3414. The regexp is taken from the conditions list, it must come right after
  3415. the `regexp' or `notregexp' element.
  3416. If any of these conditions is met, this function returns the end point of
  3417. the entity, causing the search to continue from there. This is a function
  3418. that can be put into `org-agenda-skip-function' for the duration of a command."
  3419. (let (beg end m)
  3420. (org-back-to-heading t)
  3421. (setq beg (point)
  3422. end (if subtree
  3423. (progn (org-end-of-subtree t) (point))
  3424. (progn (outline-next-heading) (1- (point)))))
  3425. (goto-char beg)
  3426. (and
  3427. (or
  3428. (and (memq 'scheduled conditions)
  3429. (re-search-forward org-scheduled-time-regexp end t))
  3430. (and (memq 'notscheduled conditions)
  3431. (not (re-search-forward org-scheduled-time-regexp end t)))
  3432. (and (memq 'deadline conditions)
  3433. (re-search-forward org-deadline-time-regexp end t))
  3434. (and (memq 'notdeadline conditions)
  3435. (not (re-search-forward org-deadline-time-regexp end t)))
  3436. (and (memq 'timestamp conditions)
  3437. (re-search-forward org-ts-regexp end t))
  3438. (and (memq 'nottimestamp conditions)
  3439. (not (re-search-forward org-ts-regexp end t)))
  3440. (and (setq m (memq 'regexp conditions))
  3441. (stringp (nth 1 m))
  3442. (re-search-forward (nth 1 m) end t))
  3443. (and (setq m (memq 'notregexp conditions))
  3444. (stringp (nth 1 m))
  3445. (not (re-search-forward (nth 1 m) end t))))
  3446. end)))
  3447. ;;;###autoload
  3448. (defun org-agenda-list-stuck-projects (&rest ignore)
  3449. "Create agenda view for projects that are stuck.
  3450. Stuck projects are project that have no next actions. For the definitions
  3451. of what a project is and how to check if it stuck, customize the variable
  3452. `org-stuck-projects'.
  3453. MATCH is being ignored."
  3454. (interactive)
  3455. (let* ((org-agenda-skip-function
  3456. 'org-agenda-skip-entry-when-regexp-matches-in-subtree)
  3457. ;; We could have used org-agenda-skip-if here.
  3458. (org-agenda-overriding-header
  3459. (or org-agenda-overriding-header "List of stuck projects: "))
  3460. (matcher (nth 0 org-stuck-projects))
  3461. (todo (nth 1 org-stuck-projects))
  3462. (todo-wds (if (member "*" todo)
  3463. (progn
  3464. (org-prepare-agenda-buffers (org-agenda-files
  3465. nil 'ifmode))
  3466. (org-delete-all
  3467. org-done-keywords-for-agenda
  3468. (copy-sequence org-todo-keywords-for-agenda)))
  3469. todo))
  3470. (todo-re (concat "^\\*+[ \t]+\\("
  3471. (mapconcat 'identity todo-wds "\\|")
  3472. "\\)\\>"))
  3473. (tags (nth 2 org-stuck-projects))
  3474. (tags-re (if (member "*" tags)
  3475. (org-re "^\\*+ .*:[[:alnum:]_@]+:[ \t]*$")
  3476. (if tags
  3477. (concat "^\\*+ .*:\\("
  3478. (mapconcat 'identity tags "\\|")
  3479. (org-re "\\):[[:alnum:]_@:]*[ \t]*$")))))
  3480. (gen-re (nth 3 org-stuck-projects))
  3481. (re-list
  3482. (delq nil
  3483. (list
  3484. (if todo todo-re)
  3485. (if tags tags-re)
  3486. (and gen-re (stringp gen-re) (string-match "\\S-" gen-re)
  3487. gen-re)))))
  3488. (setq org-agenda-skip-regexp
  3489. (if re-list
  3490. (mapconcat 'identity re-list "\\|")
  3491. (error "No information how to identify unstuck projects")))
  3492. (org-tags-view nil matcher)
  3493. (with-current-buffer org-agenda-buffer-name
  3494. (setq org-agenda-redo-command
  3495. '(org-agenda-list-stuck-projects
  3496. (or current-prefix-arg org-last-arg))))))
  3497. ;;; Diary integration
  3498. (defvar org-disable-agenda-to-diary nil) ;Dynamically-scoped param.
  3499. (defvar list-diary-entries-hook)
  3500. (defun org-get-entries-from-diary (date)
  3501. "Get the (Emacs Calendar) diary entries for DATE."
  3502. (require 'diary-lib)
  3503. (let* ((diary-fancy-buffer "*temporary-fancy-diary-buffer*")
  3504. (fancy-diary-buffer diary-fancy-buffer)
  3505. (diary-display-hook '(fancy-diary-display))
  3506. (diary-display-function 'fancy-diary-display)
  3507. (pop-up-frames nil)
  3508. (list-diary-entries-hook
  3509. (cons 'org-diary-default-entry list-diary-entries-hook))
  3510. (diary-file-name-prefix-function nil) ; turn this feature off
  3511. (diary-modify-entry-list-string-function 'org-modify-diary-entry-string)
  3512. entries
  3513. (org-disable-agenda-to-diary t))
  3514. (save-excursion
  3515. (save-window-excursion
  3516. (funcall (if (fboundp 'diary-list-entries)
  3517. 'diary-list-entries 'list-diary-entries)
  3518. date 1)))
  3519. (if (not (get-buffer diary-fancy-buffer))
  3520. (setq entries nil)
  3521. (with-current-buffer diary-fancy-buffer
  3522. (setq buffer-read-only nil)
  3523. (if (zerop (buffer-size))
  3524. ;; No entries
  3525. (setq entries nil)
  3526. ;; Omit the date and other unnecessary stuff
  3527. (org-agenda-cleanup-fancy-diary)
  3528. ;; Add prefix to each line and extend the text properties
  3529. (if (zerop (buffer-size))
  3530. (setq entries nil)
  3531. (setq entries (buffer-substring (point-min) (- (point-max) 1)))))
  3532. (set-buffer-modified-p nil)
  3533. (kill-buffer diary-fancy-buffer)))
  3534. (when entries
  3535. (setq entries (org-split-string entries "\n"))
  3536. (setq entries
  3537. (mapcar
  3538. (lambda (x)
  3539. (setq x (org-format-agenda-item "" x "Diary" nil 'time))
  3540. ;; Extend the text properties to the beginning of the line
  3541. (org-add-props x (text-properties-at (1- (length x)) x)
  3542. 'type "diary" 'date date 'face 'org-agenda-diary))
  3543. entries)))))
  3544. (defvar org-agenda-cleanup-fancy-diary-hook nil
  3545. "Hook run when the fancy diary buffer is cleaned up.")
  3546. (defun org-agenda-cleanup-fancy-diary ()
  3547. "Remove unwanted stuff in buffer created by `fancy-diary-display'.
  3548. This gets rid of the date, the underline under the date, and
  3549. the dummy entry installed by `org-mode' to ensure non-empty diary for each
  3550. date. It also removes lines that contain only whitespace."
  3551. (goto-char (point-min))
  3552. (if (looking-at ".*?:[ \t]*")
  3553. (progn
  3554. (replace-match "")
  3555. (re-search-forward "\n=+$" nil t)
  3556. (replace-match "")
  3557. (while (re-search-backward "^ +\n?" nil t) (replace-match "")))
  3558. (re-search-forward "\n=+$" nil t)
  3559. (delete-region (point-min) (min (point-max) (1+ (match-end 0)))))
  3560. (goto-char (point-min))
  3561. (while (re-search-forward "^ +\n" nil t)
  3562. (replace-match ""))
  3563. (goto-char (point-min))
  3564. (if (re-search-forward "^Org-mode dummy\n?" nil t)
  3565. (replace-match ""))
  3566. (run-hooks 'org-agenda-cleanup-fancy-diary-hook))
  3567. ;; Make sure entries from the diary have the right text properties.
  3568. (eval-after-load "diary-lib"
  3569. '(if (boundp 'diary-modify-entry-list-string-function)
  3570. ;; We can rely on the hook, nothing to do
  3571. nil
  3572. ;; Hook not available, must use advice to make this work
  3573. (defadvice add-to-diary-list (before org-mark-diary-entry activate)
  3574. "Make the position visible."
  3575. (if (and org-disable-agenda-to-diary ;; called from org-agenda
  3576. (stringp string)
  3577. buffer-file-name)
  3578. (setq string (org-modify-diary-entry-string string))))))
  3579. (defun org-modify-diary-entry-string (string)
  3580. "Add text properties to string, allowing org-mode to act on it."
  3581. (org-add-props string nil
  3582. 'mouse-face 'highlight
  3583. 'help-echo (if buffer-file-name
  3584. (format "mouse-2 or RET jump to diary file %s"
  3585. (abbreviate-file-name buffer-file-name))
  3586. "")
  3587. 'org-agenda-diary-link t
  3588. 'org-marker (org-agenda-new-marker (point-at-bol))))
  3589. (defun org-diary-default-entry ()
  3590. "Add a dummy entry to the diary.
  3591. Needed to avoid empty dates which mess up holiday display."
  3592. ;; Catch the error if dealing with the new add-to-diary-alist
  3593. (when org-disable-agenda-to-diary
  3594. (condition-case nil
  3595. (org-add-to-diary-list original-date "Org-mode dummy" "")
  3596. (error
  3597. (org-add-to-diary-list original-date "Org-mode dummy" "" nil)))))
  3598. (defun org-add-to-diary-list (&rest args)
  3599. (if (fboundp 'diary-add-to-list)
  3600. (apply 'diary-add-to-list args)
  3601. (apply 'add-to-diary-list args)))
  3602. ;;;###autoload
  3603. (defun org-diary (&rest args)
  3604. "Return diary information from org-files.
  3605. This function can be used in a \"sexp\" diary entry in the Emacs calendar.
  3606. It accesses org files and extracts information from those files to be
  3607. listed in the diary. The function accepts arguments specifying what
  3608. items should be listed. The following arguments are allowed:
  3609. :timestamp List the headlines of items containing a date stamp or
  3610. date range matching the selected date. Deadlines will
  3611. also be listed, on the expiration day.
  3612. :sexp List entries resulting from diary-like sexps.
  3613. :deadline List any deadlines past due, or due within
  3614. `org-deadline-warning-days'. The listing occurs only
  3615. in the diary for *today*, not at any other date. If
  3616. an entry is marked DONE, it is no longer listed.
  3617. :scheduled List all items which are scheduled for the given date.
  3618. The diary for *today* also contains items which were
  3619. scheduled earlier and are not yet marked DONE.
  3620. :todo List all TODO items from the org-file. This may be a
  3621. long list - so this is not turned on by default.
  3622. Like deadlines, these entries only show up in the
  3623. diary for *today*, not at any other date.
  3624. The call in the diary file should look like this:
  3625. &%%(org-diary) ~/path/to/some/orgfile.org
  3626. Use a separate line for each org file to check. Or, if you omit the file name,
  3627. all files listed in `org-agenda-files' will be checked automatically:
  3628. &%%(org-diary)
  3629. If you don't give any arguments (as in the example above), the default
  3630. arguments (:deadline :scheduled :timestamp :sexp) are used.
  3631. So the example above may also be written as
  3632. &%%(org-diary :deadline :timestamp :sexp :scheduled)
  3633. The function expects the lisp variables `entry' and `date' to be provided
  3634. by the caller, because this is how the calendar works. Don't use this
  3635. function from a program - use `org-agenda-get-day-entries' instead."
  3636. (when (> (- (org-float-time)
  3637. org-agenda-last-marker-time)
  3638. 5)
  3639. (org-agenda-reset-markers))
  3640. (org-compile-prefix-format 'agenda)
  3641. (org-set-sorting-strategy 'agenda)
  3642. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3643. (let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
  3644. (list entry)
  3645. (org-agenda-files t)))
  3646. file rtn results)
  3647. (org-prepare-agenda-buffers files)
  3648. ;; If this is called during org-agenda, don't return any entries to
  3649. ;; the calendar. Org Agenda will list these entries itself.
  3650. (if org-disable-agenda-to-diary (setq files nil))
  3651. (while (setq file (pop files))
  3652. (setq rtn (apply 'org-agenda-get-day-entries file date args))
  3653. (setq results (append results rtn)))
  3654. (if results
  3655. (concat (org-finalize-agenda-entries results) "\n"))))
  3656. ;;; Agenda entry finders
  3657. (defun org-agenda-get-day-entries (file date &rest args)
  3658. "Does the work for `org-diary' and `org-agenda'.
  3659. FILE is the path to a file to be checked for entries. DATE is date like
  3660. the one returned by `calendar-current-date'. ARGS are symbols indicating
  3661. which kind of entries should be extracted. For details about these, see
  3662. the documentation of `org-diary'."
  3663. (setq args (or args '(:deadline :scheduled :timestamp :sexp)))
  3664. (let* ((org-startup-folded nil)
  3665. (org-startup-align-all-tables nil)
  3666. (buffer (if (file-exists-p file)
  3667. (org-get-agenda-file-buffer file)
  3668. (error "No such file %s" file)))
  3669. arg results rtn deadline-results)
  3670. (if (not buffer)
  3671. ;; If file does not exist, make sure an error message ends up in diary
  3672. (list (format "ORG-AGENDA-ERROR: No such org-file %s" file))
  3673. (with-current-buffer buffer
  3674. (unless (org-mode-p)
  3675. (error "Agenda file %s is not in `org-mode'" file))
  3676. (let ((case-fold-search nil))
  3677. (save-excursion
  3678. (save-restriction
  3679. (if org-agenda-restrict
  3680. (narrow-to-region org-agenda-restrict-begin
  3681. org-agenda-restrict-end)
  3682. (widen))
  3683. ;; The way we repeatedly append to `results' makes it O(n^2) :-(
  3684. (while (setq arg (pop args))
  3685. (cond
  3686. ((and (eq arg :todo)
  3687. (equal date (calendar-current-date)))
  3688. (setq rtn (org-agenda-get-todos))
  3689. (setq results (append results rtn)))
  3690. ((eq arg :timestamp)
  3691. (setq rtn (org-agenda-get-blocks))
  3692. (setq results (append results rtn))
  3693. (setq rtn (org-agenda-get-timestamps))
  3694. (setq results (append results rtn)))
  3695. ((eq arg :sexp)
  3696. (setq rtn (org-agenda-get-sexps))
  3697. (setq results (append results rtn)))
  3698. ((eq arg :scheduled)
  3699. (setq rtn (org-agenda-get-scheduled deadline-results))
  3700. (setq results (append results rtn)))
  3701. ((eq arg :closed)
  3702. (setq rtn (org-agenda-get-progress))
  3703. (setq results (append results rtn)))
  3704. ((eq arg :deadline)
  3705. (setq rtn (org-agenda-get-deadlines))
  3706. (setq deadline-results (copy-sequence rtn))
  3707. (setq results (append results rtn))))))))
  3708. results))))
  3709. (defun org-agenda-get-todos ()
  3710. "Return the TODO information for agenda display."
  3711. (let* ((props (list 'face nil
  3712. 'done-face 'org-agenda-done
  3713. 'org-not-done-regexp org-not-done-regexp
  3714. 'org-todo-regexp org-todo-regexp
  3715. 'org-complex-heading-regexp org-complex-heading-regexp
  3716. 'mouse-face 'highlight
  3717. 'help-echo
  3718. (format "mouse-2 or RET jump to org file %s"
  3719. (abbreviate-file-name buffer-file-name))))
  3720. (regexp (concat "^\\*+[ \t]+\\("
  3721. (if org-select-this-todo-keyword
  3722. (if (equal org-select-this-todo-keyword "*")
  3723. org-todo-regexp
  3724. (concat "\\<\\("
  3725. (mapconcat 'identity (org-split-string org-select-this-todo-keyword "|") "\\|")
  3726. "\\)\\>"))
  3727. org-not-done-regexp)
  3728. "[^\n\r]*\\)"))
  3729. marker priority category tags todo-state
  3730. ee txt beg end)
  3731. (goto-char (point-min))
  3732. (while (re-search-forward regexp nil t)
  3733. (catch :skip
  3734. (save-match-data
  3735. (beginning-of-line)
  3736. (setq beg (point) end (save-excursion (outline-next-heading) (point)))
  3737. (when (org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item end)
  3738. (goto-char (1+ beg))
  3739. (or org-agenda-todo-list-sublevels (org-end-of-subtree 'invisible))
  3740. (throw :skip nil)))
  3741. (goto-char beg)
  3742. (org-agenda-skip)
  3743. (goto-char (match-beginning 1))
  3744. (setq marker (org-agenda-new-marker (match-beginning 0))
  3745. category (org-get-category)
  3746. txt (match-string 1)
  3747. tags (org-get-tags-at (point))
  3748. txt (org-format-agenda-item "" txt category tags)
  3749. priority (1+ (org-get-priority txt))
  3750. todo-state (org-get-todo-state))
  3751. (org-add-props txt props
  3752. 'org-marker marker 'org-hd-marker marker
  3753. 'priority priority 'org-category category
  3754. 'type "todo" 'todo-state todo-state)
  3755. (push txt ee)
  3756. (if org-agenda-todo-list-sublevels
  3757. (goto-char (match-end 1))
  3758. (org-end-of-subtree 'invisible))))
  3759. (nreverse ee)))
  3760. ;;;###autoload
  3761. (defun org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item (&optional end)
  3762. "Do we have a reason to ignore this todo entry because it has a time stamp?"
  3763. (when (or org-agenda-todo-ignore-with-date
  3764. org-agenda-todo-ignore-scheduled
  3765. org-agenda-todo-ignore-deadlines)
  3766. (setq end (or end (save-excursion (outline-next-heading) (point))))
  3767. (save-excursion
  3768. (or (and org-agenda-todo-ignore-with-date
  3769. (re-search-forward org-ts-regexp end t))
  3770. (and org-agenda-todo-ignore-scheduled
  3771. (re-search-forward org-scheduled-time-regexp end t))
  3772. (and org-agenda-todo-ignore-deadlines
  3773. (re-search-forward org-deadline-time-regexp end t)
  3774. (org-deadline-close (match-string 1)))))))
  3775. (defconst org-agenda-no-heading-message
  3776. "No heading for this item in buffer or region.")
  3777. (defun org-agenda-get-timestamps ()
  3778. "Return the date stamp information for agenda display."
  3779. (let* ((props (list 'face nil
  3780. 'org-not-done-regexp org-not-done-regexp
  3781. 'org-todo-regexp org-todo-regexp
  3782. 'org-complex-heading-regexp org-complex-heading-regexp
  3783. 'mouse-face 'highlight
  3784. 'help-echo
  3785. (format "mouse-2 or RET jump to org file %s"
  3786. (abbreviate-file-name buffer-file-name))))
  3787. (d1 (calendar-absolute-from-gregorian date))
  3788. (remove-re
  3789. (concat
  3790. (regexp-quote
  3791. (format-time-string
  3792. "<%Y-%m-%d"
  3793. (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))
  3794. ".*?>"))
  3795. (regexp
  3796. (concat
  3797. (if org-agenda-include-inactive-timestamps "[[<]" "<")
  3798. (regexp-quote
  3799. (substring
  3800. (format-time-string
  3801. (car org-time-stamp-formats)
  3802. (apply 'encode-time ; DATE bound by calendar
  3803. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3804. 1 11))
  3805. "\\|\\(<[0-9]+-[0-9]+-[0-9]+[^>\n]+?\\+[0-9]+[dwmy]>\\)"
  3806. "\\|\\(<%%\\(([^>\n]+)\\)>\\)"))
  3807. marker hdmarker deadlinep scheduledp clockp closedp inactivep
  3808. donep tmp priority category ee txt timestr tags b0 b3 e3 head
  3809. todo-state end-of-match)
  3810. (goto-char (point-min))
  3811. (while (setq end-of-match (re-search-forward regexp nil t))
  3812. (setq b0 (match-beginning 0)
  3813. b3 (match-beginning 3) e3 (match-end 3))
  3814. (catch :skip
  3815. (and (org-at-date-range-p) (throw :skip nil))
  3816. (org-agenda-skip)
  3817. (if (and (match-end 1)
  3818. (not (= d1 (org-time-string-to-absolute
  3819. (match-string 1) d1 nil
  3820. org-agenda-repeating-timestamp-show-all))))
  3821. (throw :skip nil))
  3822. (if (and e3
  3823. (not (org-diary-sexp-entry (buffer-substring b3 e3) "" date)))
  3824. (throw :skip nil))
  3825. (setq tmp (buffer-substring (max (point-min)
  3826. (- b0 org-ds-keyword-length))
  3827. b0)
  3828. timestr (if b3 "" (buffer-substring b0 (point-at-eol)))
  3829. inactivep (= (char-after b0) ?\[)
  3830. deadlinep (string-match org-deadline-regexp tmp)
  3831. scheduledp (string-match org-scheduled-regexp tmp)
  3832. closedp (and org-agenda-include-inactive-timestamps
  3833. (string-match org-closed-string tmp))
  3834. clockp (and org-agenda-include-inactive-timestamps
  3835. (or (string-match org-clock-string tmp)
  3836. (string-match "]-+\\'" tmp)))
  3837. todo-state (org-get-todo-state)
  3838. donep (member todo-state org-done-keywords))
  3839. (if (or scheduledp deadlinep closedp clockp
  3840. (and donep org-agenda-skip-timestamp-if-done))
  3841. (throw :skip t))
  3842. (if (string-match ">" timestr)
  3843. ;; substring should only run to end of time stamp
  3844. (setq timestr (substring timestr 0 (match-end 0))))
  3845. (setq marker (org-agenda-new-marker b0)
  3846. category (org-get-category b0))
  3847. (save-excursion
  3848. (if (not (re-search-backward "^\\*+ " nil t))
  3849. (setq txt org-agenda-no-heading-message)
  3850. (goto-char (match-beginning 0))
  3851. (setq hdmarker (org-agenda-new-marker)
  3852. tags (org-get-tags-at))
  3853. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  3854. (setq head (match-string 1))
  3855. (setq txt (org-format-agenda-item
  3856. (if inactivep org-agenda-inactive-leader nil)
  3857. head category tags timestr nil
  3858. remove-re)))
  3859. (setq priority (org-get-priority txt))
  3860. (org-add-props txt props
  3861. 'org-marker marker 'org-hd-marker hdmarker)
  3862. (org-add-props txt nil 'priority priority
  3863. 'org-category category 'date date
  3864. 'todo-state todo-state
  3865. 'type "timestamp")
  3866. (push txt ee))
  3867. (if org-agenda-skip-additional-timestamps-same-entry
  3868. (outline-next-heading)
  3869. (goto-char end-of-match))))
  3870. (nreverse ee)))
  3871. (defun org-agenda-get-sexps ()
  3872. "Return the sexp information for agenda display."
  3873. (require 'diary-lib)
  3874. (let* ((props (list 'face nil
  3875. 'mouse-face 'highlight
  3876. 'help-echo
  3877. (format "mouse-2 or RET jump to org file %s"
  3878. (abbreviate-file-name buffer-file-name))))
  3879. (regexp "^&?%%(")
  3880. marker category ee txt tags entry result beg b sexp sexp-entry
  3881. todo-state)
  3882. (goto-char (point-min))
  3883. (while (re-search-forward regexp nil t)
  3884. (catch :skip
  3885. (org-agenda-skip)
  3886. (setq beg (match-beginning 0))
  3887. (goto-char (1- (match-end 0)))
  3888. (setq b (point))
  3889. (forward-sexp 1)
  3890. (setq sexp (buffer-substring b (point)))
  3891. (setq sexp-entry (if (looking-at "[ \t]*\\(\\S-.*\\)")
  3892. (org-trim (match-string 1))
  3893. ""))
  3894. (setq result (org-diary-sexp-entry sexp sexp-entry date))
  3895. (when result
  3896. (setq marker (org-agenda-new-marker beg)
  3897. category (org-get-category beg)
  3898. todo-state (org-get-todo-state))
  3899. (if (string-match "\\S-" result)
  3900. (setq txt result)
  3901. (setq txt "SEXP entry returned empty string"))
  3902. (setq txt (org-format-agenda-item
  3903. "" txt category tags 'time))
  3904. (org-add-props txt props 'org-marker marker)
  3905. (org-add-props txt nil
  3906. 'org-category category 'date date 'todo-state todo-state
  3907. 'type "sexp")
  3908. (push txt ee))))
  3909. (nreverse ee)))
  3910. (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
  3911. "Entry applies if date is between dates on DAYNAME, but skips SKIP-WEEKS.
  3912. The order of the first 2 times 3 arguments depends on the variable
  3913. `calendar-date-style' or, if that is not defined, on `european-calendar-style'.
  3914. So for american calendars, give this as MONTH DAY YEAR, for european as
  3915. DAY MONTH YEAR, and for ISO as YEAR MONTH DAY.
  3916. DAYNAME is a number between 0 (Sunday) and 6 (Saturday). SKIP-WEEKS
  3917. is any number of ISO weeks in the block period for which the item should
  3918. be skipped."
  3919. (let* ((date1 (calendar-absolute-from-gregorian
  3920. (org-order-calendar-date-args m1 d1 y1)))
  3921. (date2 (calendar-absolute-from-gregorian
  3922. (org-order-calendar-date-args m2 d2 y2)))
  3923. (d (calendar-absolute-from-gregorian date)))
  3924. (and
  3925. (<= date1 d)
  3926. (<= d date2)
  3927. (= (calendar-day-of-week date) dayname)
  3928. (or (not skip-weeks)
  3929. (progn
  3930. (require 'cal-iso)
  3931. (not (member (car (calendar-iso-from-absolute d)) skip-weeks))))
  3932. entry)))
  3933. (defalias 'org-get-closed 'org-agenda-get-progress)
  3934. (defun org-agenda-get-progress ()
  3935. "Return the logged TODO entries for agenda display."
  3936. (let* ((props (list 'mouse-face 'highlight
  3937. 'org-not-done-regexp org-not-done-regexp
  3938. 'org-todo-regexp org-todo-regexp
  3939. 'org-complex-heading-regexp org-complex-heading-regexp
  3940. 'help-echo
  3941. (format "mouse-2 or RET jump to org file %s"
  3942. (abbreviate-file-name buffer-file-name))))
  3943. (items (if (consp org-agenda-show-log)
  3944. org-agenda-show-log
  3945. org-agenda-log-mode-items))
  3946. (parts
  3947. (delq nil
  3948. (list
  3949. (if (memq 'closed items) (concat "\\<" org-closed-string))
  3950. (if (memq 'clock items) (concat "\\<" org-clock-string))
  3951. (if (memq 'state items) "- State \"\\([a-zA-Z0-9]+\\)\".*?"))))
  3952. (parts-re (if parts (mapconcat 'identity parts "\\|")
  3953. (error "`org-agenda-log-mode-items' is empty")))
  3954. (regexp (concat
  3955. "\\(" parts-re "\\)"
  3956. " *\\["
  3957. (regexp-quote
  3958. (substring
  3959. (format-time-string
  3960. (car org-time-stamp-formats)
  3961. (apply 'encode-time ; DATE bound by calendar
  3962. (list 0 0 0 (nth 1 date) (car date) (nth 2 date))))
  3963. 1 11))))
  3964. (org-agenda-search-headline-for-time nil)
  3965. marker hdmarker priority category tags closedp statep clockp state
  3966. ee txt extra timestr rest clocked)
  3967. (goto-char (point-min))
  3968. (while (re-search-forward regexp nil t)
  3969. (catch :skip
  3970. (org-agenda-skip)
  3971. (setq marker (org-agenda-new-marker (match-beginning 0))
  3972. closedp (equal (match-string 1) org-closed-string)
  3973. statep (equal (string-to-char (match-string 1)) ?-)
  3974. clockp (not (or closedp statep))
  3975. state (and statep (match-string 2))
  3976. category (org-get-category (match-beginning 0))
  3977. timestr (buffer-substring (match-beginning 0) (point-at-eol))
  3978. )
  3979. (when (string-match "\\]" timestr)
  3980. ;; substring should only run to end of time stamp
  3981. (setq rest (substring timestr (match-end 0))
  3982. timestr (substring timestr 0 (match-end 0)))
  3983. (if (and (not closedp) (not statep)
  3984. (string-match "\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)\\].*?\\([0-9]\\{1,2\\}:[0-9]\\{2\\}\\)" rest))
  3985. (progn (setq timestr (concat (substring timestr 0 -1)
  3986. "-" (match-string 1 rest) "]"))
  3987. (setq clocked (match-string 2 rest)))
  3988. (setq clocked "-")))
  3989. (save-excursion
  3990. (cond
  3991. ((not org-agenda-log-mode-add-notes) (setq extra nil))
  3992. (statep
  3993. (and (looking-at ".*\n[ \t]*\\([^-\n \t].*?\\)[ \t]*$")
  3994. (setq extra (match-string 1))))
  3995. (clockp
  3996. (and (looking-at ".*\n[ \t]*-[ \t]+\\([^-\n \t].*?\\)[ \t]*$")
  3997. (setq extra (match-string 1))))
  3998. (t (setq extra nil)))
  3999. (if (not (re-search-backward "^\\*+ " nil t))
  4000. (setq txt org-agenda-no-heading-message)
  4001. (goto-char (match-beginning 0))
  4002. (setq hdmarker (org-agenda-new-marker)
  4003. tags (org-get-tags-at))
  4004. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4005. (setq txt (match-string 1))
  4006. (when extra
  4007. (if (string-match "\\([ \t]+\\)\\(:[^ \n\t]*?:\\)[ \t]*$" txt)
  4008. (setq txt (concat (substring txt 0 (match-beginning 1))
  4009. " - " extra " " (match-string 2 txt)))
  4010. (setq txt (concat txt " - " extra))))
  4011. (setq txt (org-format-agenda-item
  4012. (cond
  4013. (closedp "Closed: ")
  4014. (statep (concat "State: (" state ")"))
  4015. (t (concat "Clocked: (" clocked ")")))
  4016. txt category tags timestr)))
  4017. (setq priority 100000)
  4018. (org-add-props txt props
  4019. 'org-marker marker 'org-hd-marker hdmarker 'face 'org-agenda-done
  4020. 'priority priority 'org-category category
  4021. 'type "closed" 'date date
  4022. 'undone-face 'org-warning 'done-face 'org-agenda-done)
  4023. (push txt ee))
  4024. (goto-char (point-at-eol))))
  4025. (nreverse ee)))
  4026. (defun org-agenda-get-deadlines ()
  4027. "Return the deadline information for agenda display."
  4028. (let* ((props (list 'mouse-face 'highlight
  4029. 'org-not-done-regexp org-not-done-regexp
  4030. 'org-todo-regexp org-todo-regexp
  4031. 'org-complex-heading-regexp org-complex-heading-regexp
  4032. 'help-echo
  4033. (format "mouse-2 or RET jump to org file %s"
  4034. (abbreviate-file-name buffer-file-name))))
  4035. (regexp org-deadline-time-regexp)
  4036. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4037. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4038. d2 diff dfrac wdays pos pos1 category tags
  4039. ee txt head face s todo-state upcomingp donep timestr)
  4040. (goto-char (point-min))
  4041. (while (re-search-forward regexp nil t)
  4042. (catch :skip
  4043. (org-agenda-skip)
  4044. (setq s (match-string 1)
  4045. txt nil
  4046. pos (1- (match-beginning 1))
  4047. d2 (org-time-string-to-absolute
  4048. (match-string 1) d1 'past
  4049. org-agenda-repeating-timestamp-show-all)
  4050. diff (- d2 d1)
  4051. wdays (org-get-wdays s)
  4052. dfrac (/ (* 1.0 (- wdays diff)) (max wdays 1))
  4053. upcomingp (and todayp (> diff 0)))
  4054. ;; When to show a deadline in the calendar:
  4055. ;; If the expiration is within wdays warning time.
  4056. ;; Past-due deadlines are only shown on the current date
  4057. (if (and (or (and (<= diff wdays)
  4058. (and todayp (not org-agenda-only-exact-dates)))
  4059. (= diff 0)))
  4060. (save-excursion
  4061. (setq todo-state (org-get-todo-state))
  4062. (setq donep (member todo-state org-done-keywords))
  4063. (if (and donep
  4064. (or org-agenda-skip-deadline-if-done
  4065. (not (= diff 0))))
  4066. (setq txt nil)
  4067. (setq category (org-get-category))
  4068. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4069. (setq txt org-agenda-no-heading-message)
  4070. (goto-char (match-end 0))
  4071. (setq pos1 (match-beginning 0))
  4072. (setq tags (org-get-tags-at pos1))
  4073. (setq head (buffer-substring-no-properties
  4074. (point)
  4075. (progn (skip-chars-forward "^\r\n")
  4076. (point))))
  4077. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4078. (setq timestr
  4079. (concat (substring s (match-beginning 1)) " "))
  4080. (setq timestr 'time))
  4081. (setq txt (org-format-agenda-item
  4082. (if (= diff 0)
  4083. (car org-agenda-deadline-leaders)
  4084. (if (functionp
  4085. (nth 1 org-agenda-deadline-leaders))
  4086. (funcall
  4087. (nth 1 org-agenda-deadline-leaders)
  4088. diff date)
  4089. (format (nth 1 org-agenda-deadline-leaders)
  4090. diff)))
  4091. head category tags
  4092. (if (not (= diff 0)) nil timestr)))))
  4093. (when txt
  4094. (setq face (org-agenda-deadline-face dfrac wdays))
  4095. (org-add-props txt props
  4096. 'org-marker (org-agenda-new-marker pos)
  4097. 'org-hd-marker (org-agenda-new-marker pos1)
  4098. 'priority (+ (- diff)
  4099. (org-get-priority txt))
  4100. 'org-category category
  4101. 'todo-state todo-state
  4102. 'type (if upcomingp "upcoming-deadline" "deadline")
  4103. 'date (if upcomingp date d2)
  4104. 'face (if donep 'org-agenda-done face)
  4105. 'undone-face face 'done-face 'org-agenda-done)
  4106. (push txt ee))))))
  4107. (nreverse ee)))
  4108. (defun org-agenda-deadline-face (fraction &optional wdays)
  4109. "Return the face to displaying a deadline item.
  4110. FRACTION is what fraction of the head-warning time has passed."
  4111. (if (equal wdays 0) (setq fraction 1.))
  4112. (let ((faces org-agenda-deadline-faces) f)
  4113. (catch 'exit
  4114. (while (setq f (pop faces))
  4115. (if (>= fraction (car f)) (throw 'exit (cdr f)))))))
  4116. (defun org-agenda-get-scheduled (&optional deadline-results)
  4117. "Return the scheduled information for agenda display."
  4118. (let* ((props (list 'org-not-done-regexp org-not-done-regexp
  4119. 'org-todo-regexp org-todo-regexp
  4120. 'org-complex-heading-regexp org-complex-heading-regexp
  4121. 'done-face 'org-agenda-done
  4122. 'mouse-face 'highlight
  4123. 'help-echo
  4124. (format "mouse-2 or RET jump to org file %s"
  4125. (abbreviate-file-name buffer-file-name))))
  4126. (regexp org-scheduled-time-regexp)
  4127. (todayp (org-agenda-todayp date)) ; DATE bound by calendar
  4128. (d1 (calendar-absolute-from-gregorian date)) ; DATE bound by calendar
  4129. mm
  4130. (deadline-position-alist
  4131. (mapcar (lambda (a) (and (setq mm (get-text-property
  4132. 0 'org-hd-marker a))
  4133. (cons (marker-position mm) a)))
  4134. deadline-results))
  4135. d2 diff pos pos1 category tags donep
  4136. ee txt head pastschedp todo-state face timestr s habitp)
  4137. (goto-char (point-min))
  4138. (while (re-search-forward regexp nil t)
  4139. (catch :skip
  4140. (org-agenda-skip)
  4141. (setq s (match-string 1)
  4142. txt nil
  4143. pos (1- (match-beginning 1))
  4144. d2 (org-time-string-to-absolute
  4145. (match-string 1) d1 'past
  4146. org-agenda-repeating-timestamp-show-all)
  4147. diff (- d2 d1))
  4148. (setq pastschedp (and todayp (< diff 0)))
  4149. ;; When to show a scheduled item in the calendar:
  4150. ;; If it is on or past the date.
  4151. (when (or (and (< diff 0)
  4152. (< (abs diff) org-scheduled-past-days)
  4153. (and todayp (not org-agenda-only-exact-dates)))
  4154. (= diff 0))
  4155. (save-excursion
  4156. (setq todo-state (org-get-todo-state))
  4157. (setq donep (member todo-state org-done-keywords))
  4158. (setq habitp (and (functionp 'org-is-habit-p)
  4159. (org-is-habit-p)))
  4160. (if (and donep
  4161. (or habitp org-agenda-skip-scheduled-if-done
  4162. (not (= diff 0))))
  4163. (setq txt nil)
  4164. (setq category (org-get-category))
  4165. (if (not (re-search-backward "^\\*+[ \t]+" nil t))
  4166. (setq txt org-agenda-no-heading-message)
  4167. (goto-char (match-end 0))
  4168. (setq pos1 (match-beginning 0))
  4169. (if habitp
  4170. (if (or (not org-habit-show-habits)
  4171. (and (not todayp)
  4172. org-habit-show-habits-only-for-today))
  4173. (throw :skip nil))
  4174. (if (and
  4175. (or (eq t org-agenda-skip-scheduled-if-deadline-is-shown)
  4176. (and org-agenda-skip-scheduled-if-deadline-is-shown
  4177. pastschedp))
  4178. (setq mm (assoc pos1 deadline-position-alist)))
  4179. (throw :skip nil)))
  4180. (setq tags (org-get-tags-at))
  4181. (setq head (buffer-substring-no-properties
  4182. (point)
  4183. (progn (skip-chars-forward "^\r\n") (point))))
  4184. (if (string-match " \\([012]?[0-9]:[0-9][0-9]\\)" s)
  4185. (setq timestr
  4186. (concat (substring s (match-beginning 1)) " "))
  4187. (setq timestr 'time))
  4188. (setq txt (org-format-agenda-item
  4189. (if (= diff 0)
  4190. (car org-agenda-scheduled-leaders)
  4191. (format (nth 1 org-agenda-scheduled-leaders)
  4192. (- 1 diff)))
  4193. head category tags
  4194. (if (not (= diff 0)) nil timestr)
  4195. nil nil habitp))))
  4196. (when txt
  4197. (setq face
  4198. (cond
  4199. ((and (not habitp) pastschedp)
  4200. 'org-scheduled-previously)
  4201. (todayp 'org-scheduled-today)
  4202. (t 'org-scheduled))
  4203. habitp (and habitp (org-habit-parse-todo)))
  4204. (org-add-props txt props
  4205. 'undone-face face
  4206. 'face (if donep 'org-agenda-done face)
  4207. 'org-marker (org-agenda-new-marker pos)
  4208. 'org-hd-marker (org-agenda-new-marker pos1)
  4209. 'type (if pastschedp "past-scheduled" "scheduled")
  4210. 'date (if pastschedp d2 date)
  4211. 'priority (if habitp
  4212. (org-habit-get-priority habitp)
  4213. (+ 94 (- 5 diff) (org-get-priority txt)))
  4214. 'org-category category
  4215. 'org-habit-p habitp
  4216. 'todo-state todo-state)
  4217. (push txt ee))))))
  4218. (nreverse ee)))
  4219. (defun org-agenda-get-blocks ()
  4220. "Return the date-range information for agenda display."
  4221. (let* ((props (list 'face nil
  4222. 'org-not-done-regexp org-not-done-regexp
  4223. 'org-todo-regexp org-todo-regexp
  4224. 'org-complex-heading-regexp org-complex-heading-regexp
  4225. 'mouse-face 'highlight
  4226. 'help-echo
  4227. (format "mouse-2 or RET jump to org file %s"
  4228. (abbreviate-file-name buffer-file-name))))
  4229. (regexp org-tr-regexp)
  4230. (d0 (calendar-absolute-from-gregorian date))
  4231. marker hdmarker ee txt d1 d2 s1 s2 timestr category todo-state tags pos
  4232. head donep)
  4233. (goto-char (point-min))
  4234. (while (re-search-forward regexp nil t)
  4235. (catch :skip
  4236. (org-agenda-skip)
  4237. (setq pos (point))
  4238. (setq timestr (match-string 0)
  4239. s1 (match-string 1)
  4240. s2 (match-string 2)
  4241. d1 (time-to-days (org-time-string-to-time s1))
  4242. d2 (time-to-days (org-time-string-to-time s2)))
  4243. (if (and (> (- d0 d1) -1) (> (- d2 d0) -1))
  4244. ;; Only allow days between the limits, because the normal
  4245. ;; date stamps will catch the limits.
  4246. (save-excursion
  4247. (setq todo-state (org-get-todo-state))
  4248. (setq donep (member todo-state org-done-keywords))
  4249. (if (and donep org-agenda-skip-timestamp-if-done)
  4250. (throw :skip t))
  4251. (setq marker (org-agenda-new-marker (point)))
  4252. (setq category (org-get-category))
  4253. (if (not (re-search-backward "^\\*+ " nil t))
  4254. (setq txt org-agenda-no-heading-message)
  4255. (goto-char (match-beginning 0))
  4256. (setq hdmarker (org-agenda-new-marker (point)))
  4257. (setq tags (org-get-tags-at))
  4258. (looking-at "\\*+[ \t]+\\([^\r\n]+\\)")
  4259. (setq head (match-string 1))
  4260. (setq txt (org-format-agenda-item
  4261. (format
  4262. (nth (if (= d1 d2) 0 1)
  4263. org-agenda-timerange-leaders)
  4264. (1+ (- d0 d1)) (1+ (- d2 d1)))
  4265. head category tags
  4266. timestr)))
  4267. (org-add-props txt props
  4268. 'org-marker marker 'org-hd-marker hdmarker
  4269. 'type "block" 'date date
  4270. 'todo-state todo-state
  4271. 'priority (org-get-priority txt) 'org-category category)
  4272. (push txt ee)))
  4273. (goto-char pos)))
  4274. ;; Sort the entries by expiration date.
  4275. (nreverse ee)))
  4276. ;;; Agenda presentation and sorting
  4277. (defvar org-prefix-has-time nil
  4278. "A flag, set by `org-compile-prefix-format'.
  4279. The flag is set if the currently compiled format contains a `%t'.")
  4280. (defvar org-prefix-has-tag nil
  4281. "A flag, set by `org-compile-prefix-format'.
  4282. The flag is set if the currently compiled format contains a `%T'.")
  4283. (defvar org-prefix-has-effort nil
  4284. "A flag, set by `org-compile-prefix-format'.
  4285. The flag is set if the currently compiled format contains a `%e'.")
  4286. (defvar org-prefix-category-length nil
  4287. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4288. (defvar org-prefix-category-max-length nil
  4289. "Used by `org-compile-prefix-format' to remember the category field widh.")
  4290. (defun org-format-agenda-item (extra txt &optional category tags dotime
  4291. noprefix remove-re habitp)
  4292. "Format TXT to be inserted into the agenda buffer.
  4293. In particular, it adds the prefix and corresponding text properties. EXTRA
  4294. must be a string and replaces the `%s' specifier in the prefix format.
  4295. CATEGORY (string, symbol or nil) may be used to overrule the default
  4296. category taken from local variable or file name. It will replace the `%c'
  4297. specifier in the format. DOTIME, when non-nil, indicates that a
  4298. time-of-day should be extracted from TXT for sorting of this entry, and for
  4299. the `%t' specifier in the format. When DOTIME is a string, this string is
  4300. searched for a time before TXT is. NOPREFIX is a flag and indicates that
  4301. only the correctly processes TXT should be returned - this is used by
  4302. `org-agenda-change-all-lines'. TAGS can be the tags of the headline.
  4303. Any match of REMOVE-RE will be removed from TXT."
  4304. (save-match-data
  4305. ;; Diary entries sometimes have extra whitespace at the beginning
  4306. (if (string-match "^ +" txt) (setq txt (replace-match "" nil nil txt)))
  4307. ;; Fix the tags part in txt
  4308. (setq txt (org-agenda-fix-displayed-tags
  4309. txt tags
  4310. org-agenda-show-inherited-tags
  4311. org-agenda-hide-tags-regexp))
  4312. (let* ((category (or category
  4313. org-category
  4314. (if buffer-file-name
  4315. (file-name-sans-extension
  4316. (file-name-nondirectory buffer-file-name))
  4317. "")))
  4318. ;; time, tag, effort are needed for the eval of the prefix format
  4319. (tag (if tags (nth (1- (length tags)) tags) ""))
  4320. time effort neffort
  4321. (ts (if dotime (concat
  4322. (if (stringp dotime) dotime "")
  4323. (and org-agenda-search-headline-for-time txt))))
  4324. (time-of-day (and dotime (org-get-time-of-day ts)))
  4325. stamp plain s0 s1 s2 t1 t2 rtn srp l
  4326. duration thecategory)
  4327. (and (org-mode-p) buffer-file-name
  4328. (add-to-list 'org-agenda-contributing-files buffer-file-name))
  4329. (when (and dotime time-of-day)
  4330. ;; Extract starting and ending time and move them to prefix
  4331. (when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
  4332. (setq plain (string-match org-plain-time-of-day-regexp ts)))
  4333. (setq s0 (match-string 0 ts)
  4334. srp (and stamp (match-end 3))
  4335. s1 (match-string (if plain 1 2) ts)
  4336. s2 (match-string (if plain 8 (if srp 4 6)) ts))
  4337. ;; If the times are in TXT (not in DOTIMES), and the prefix will list
  4338. ;; them, we might want to remove them there to avoid duplication.
  4339. ;; The user can turn this off with a variable.
  4340. (if (and org-prefix-has-time
  4341. org-agenda-remove-times-when-in-prefix (or stamp plain)
  4342. (string-match (concat (regexp-quote s0) " *") txt)
  4343. (not (equal ?\] (string-to-char (substring txt (match-end 0)))))
  4344. (if (eq org-agenda-remove-times-when-in-prefix 'beg)
  4345. (= (match-beginning 0) 0)
  4346. t))
  4347. (setq txt (replace-match "" nil nil txt))))
  4348. ;; Normalize the time(s) to 24 hour
  4349. (if s1 (setq s1 (org-get-time-of-day s1 'string t)))
  4350. (if s2 (setq s2 (org-get-time-of-day s2 'string t)))
  4351. ;; Compute the duration
  4352. (when s1
  4353. (setq t1 (+ (* 60 (string-to-number (substring s1 0 2)))
  4354. (string-to-number (substring s1 3)))
  4355. t2 (cond
  4356. (s2 (+ (* 60 (string-to-number (substring s2 0 2)))
  4357. (string-to-number (substring s2 3))))
  4358. (org-agenda-default-appointment-duration
  4359. (+ t1 org-agenda-default-appointment-duration))
  4360. (t nil)))
  4361. (setq duration (if t2 (- t2 t1)))))
  4362. (when (and s1 (not s2) org-agenda-default-appointment-duration
  4363. (string-match "\\([0-9]+\\):\\([0-9]+\\)" s1))
  4364. (let ((m (+ (string-to-number (match-string 2 s1))
  4365. (* 60 (string-to-number (match-string 1 s1)))
  4366. org-agenda-default-appointment-duration))
  4367. h)
  4368. (setq h (/ m 60) m (- m (* h 60)))
  4369. (setq s2 (format "%02d:%02d" h m))))
  4370. (when (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  4371. txt)
  4372. ;; Tags are in the string
  4373. (if (or (eq org-agenda-remove-tags t)
  4374. (and org-agenda-remove-tags
  4375. org-prefix-has-tag))
  4376. (setq txt (replace-match "" t t txt))
  4377. (setq txt (replace-match
  4378. (concat (make-string (max (- 50 (length txt)) 1) ?\ )
  4379. (match-string 2 txt))
  4380. t t txt))))
  4381. (when (org-mode-p)
  4382. (setq effort
  4383. (condition-case nil
  4384. (org-get-effort
  4385. (or (get-text-property 0 'org-hd-marker txt)
  4386. (get-text-property 0 'org-marker txt)))
  4387. (error nil)))
  4388. (when effort
  4389. (setq neffort (org-hh:mm-string-to-minutes effort)
  4390. effort (setq effort (concat "[" effort "]" )))))
  4391. (when remove-re
  4392. (while (string-match remove-re txt)
  4393. (setq txt (replace-match "" t t txt))))
  4394. ;; Create the final string
  4395. (if noprefix
  4396. (setq rtn txt)
  4397. ;; Prepare the variables needed in the eval of the compiled format
  4398. (setq time (cond (s2 (concat s1 "-" s2))
  4399. (s1 (concat s1 "......"))
  4400. (t ""))
  4401. extra (or (and (not habitp) extra) "")
  4402. category (if (symbolp category) (symbol-name category) category)
  4403. thecategory (copy-sequence category))
  4404. (if (string-match org-bracket-link-regexp category)
  4405. (progn
  4406. (setq l (if (match-end 3)
  4407. (- (match-end 3) (match-beginning 3))
  4408. (- (match-end 1) (match-beginning 1))))
  4409. (when (< l (or org-prefix-category-length 0))
  4410. (setq category (copy-sequence category))
  4411. (org-add-props category nil
  4412. 'extra-space (make-string
  4413. (- org-prefix-category-length l 1) ?\ ))))
  4414. (if (and org-prefix-category-max-length
  4415. (>= (length category) org-prefix-category-max-length))
  4416. (setq category (substring category 0 (1- org-prefix-category-max-length)))))
  4417. ;; Evaluate the compiled format
  4418. (setq rtn (concat (eval org-prefix-format-compiled) txt)))
  4419. ;; And finally add the text properties
  4420. (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
  4421. (org-add-props rtn nil
  4422. 'org-category (if thecategory (downcase thecategory) category)
  4423. 'tags (mapcar 'org-downcase-keep-props tags)
  4424. 'org-highest-priority org-highest-priority
  4425. 'org-lowest-priority org-lowest-priority
  4426. 'prefix-length (- (length rtn) (length txt))
  4427. 'time-of-day time-of-day
  4428. 'duration duration
  4429. 'effort effort
  4430. 'effort-minutes neffort
  4431. 'txt txt
  4432. 'time time
  4433. 'extra extra
  4434. 'dotime dotime))))
  4435. (defun org-agenda-fix-displayed-tags (txt tags add-inherited hide-re)
  4436. "Remove tags string from TXT, and add a modified list of tags.
  4437. The modified list may contain inherited tags, and tags matched by
  4438. `org-agenda-hide-tags-regexp' will be removed."
  4439. (when (or add-inherited hide-re)
  4440. (if (string-match (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$") txt)
  4441. (setq txt (substring txt 0 (match-beginning 0))))
  4442. (setq tags
  4443. (delq nil
  4444. (mapcar (lambda (tg)
  4445. (if (or (and hide-re (string-match hide-re tg))
  4446. (and (not add-inherited)
  4447. (get-text-property 0 'inherited tg)))
  4448. nil
  4449. tg))
  4450. tags)))
  4451. (when tags
  4452. (let ((have-i (get-text-property 0 'inherited (car tags)))
  4453. i)
  4454. (setq txt (concat txt " :"
  4455. (mapconcat
  4456. (lambda (x)
  4457. (setq i (get-text-property 0 'inherited x))
  4458. (if (and have-i (not i))
  4459. (progn
  4460. (setq have-i nil)
  4461. (concat ":" x))
  4462. x))
  4463. tags ":")
  4464. (if have-i "::" ":"))))))
  4465. txt)
  4466. (defun org-downcase-keep-props (s)
  4467. (let ((props (text-properties-at 0 s)))
  4468. (setq s (downcase s))
  4469. (add-text-properties 0 (length s) props s)
  4470. s))
  4471. (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
  4472. (defvar org-agenda-sorting-strategy-selected nil)
  4473. (defun org-agenda-add-time-grid-maybe (list ndays todayp)
  4474. (catch 'exit
  4475. (cond ((not org-agenda-use-time-grid) (throw 'exit list))
  4476. ((and todayp (member 'today (car org-agenda-time-grid))))
  4477. ((and (= ndays 1) (member 'daily (car org-agenda-time-grid))))
  4478. ((member 'weekly (car org-agenda-time-grid)))
  4479. (t (throw 'exit list)))
  4480. (let* ((have (delq nil (mapcar
  4481. (lambda (x) (get-text-property 1 'time-of-day x))
  4482. list)))
  4483. (string (nth 1 org-agenda-time-grid))
  4484. (gridtimes (nth 2 org-agenda-time-grid))
  4485. (req (car org-agenda-time-grid))
  4486. (remove (member 'remove-match req))
  4487. new time)
  4488. (if (and (member 'require-timed req) (not have))
  4489. ;; don't show empty grid
  4490. (throw 'exit list))
  4491. (while (setq time (pop gridtimes))
  4492. (unless (and remove (member time have))
  4493. (setq time (int-to-string time))
  4494. (push (org-format-agenda-item
  4495. nil string "" nil
  4496. (concat (substring time 0 -2) ":" (substring time -2)))
  4497. new)
  4498. (put-text-property
  4499. 1 (length (car new)) 'face 'org-time-grid (car new))))
  4500. (if (member 'time-up org-agenda-sorting-strategy-selected)
  4501. (append new list)
  4502. (append list new)))))
  4503. (defun org-compile-prefix-format (key)
  4504. "Compile the prefix format into a Lisp form that can be evaluated.
  4505. The resulting form is returned and stored in the variable
  4506. `org-prefix-format-compiled'."
  4507. (setq org-prefix-has-time nil org-prefix-has-tag nil
  4508. org-prefix-category-length nil org-prefix-has-effort nil)
  4509. (let ((s (cond
  4510. ((stringp org-agenda-prefix-format)
  4511. org-agenda-prefix-format)
  4512. ((assq key org-agenda-prefix-format)
  4513. (cdr (assq key org-agenda-prefix-format)))
  4514. (t " %-12:c%?-12t% s")))
  4515. (start 0)
  4516. varform vars var e c f opt)
  4517. (while (string-match "%\\(\\?\\)?\\([-+]?[0-9.]*\\)\\([ .;,:!?=|/<>]?\\)\\([ctse]\\)"
  4518. s start)
  4519. (setq var (cdr (assoc (match-string 4 s)
  4520. '(("c" . category) ("t" . time) ("s" . extra)
  4521. ("T" . tag) ("e" . effort))))
  4522. c (or (match-string 3 s) "")
  4523. opt (match-beginning 1)
  4524. start (1+ (match-beginning 0)))
  4525. (if (equal var 'time) (setq org-prefix-has-time t))
  4526. (if (equal var 'tag) (setq org-prefix-has-tag t))
  4527. (if (equal var 'effort) (setq org-prefix-has-effort t))
  4528. (setq f (concat "%" (match-string 2 s) "s"))
  4529. (when (equal var 'category)
  4530. (setq org-prefix-category-length
  4531. (floor (abs (string-to-number (match-string 2 s)))))
  4532. (setq org-prefix-category-max-length
  4533. (let ((x (match-string 2 s)))
  4534. (save-match-data
  4535. (if (string-match "\\.[0-9]+" x)
  4536. (string-to-number (substring (match-string 0 x) 1)))))))
  4537. (if opt
  4538. (setq varform
  4539. `(if (equal "" ,var)
  4540. ""
  4541. (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
  4542. (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var))))))
  4543. (setq s (replace-match "%s" t nil s))
  4544. (push varform vars))
  4545. (setq vars (nreverse vars))
  4546. (setq org-prefix-format-compiled `(format ,s ,@vars))))
  4547. (defun org-set-sorting-strategy (key)
  4548. (if (symbolp (car org-agenda-sorting-strategy))
  4549. ;; the old format
  4550. (setq org-agenda-sorting-strategy-selected org-agenda-sorting-strategy)
  4551. (setq org-agenda-sorting-strategy-selected
  4552. (or (cdr (assq key org-agenda-sorting-strategy))
  4553. (cdr (assq 'agenda org-agenda-sorting-strategy))
  4554. '(time-up category-keep priority-down)))))
  4555. (defun org-get-time-of-day (s &optional string mod24)
  4556. "Check string S for a time of day.
  4557. If found, return it as a military time number between 0 and 2400.
  4558. If not found, return nil.
  4559. The optional STRING argument forces conversion into a 5 character wide string
  4560. HH:MM."
  4561. (save-match-data
  4562. (when
  4563. (or (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)\\([AaPp][Mm]\\)?\\> *" s)
  4564. (string-match "\\<\\([012]?[0-9]\\)\\(:\\([0-5][0-9]\\)\\)?\\([AaPp][Mm]\\)\\> *" s))
  4565. (let* ((h (string-to-number (match-string 1 s)))
  4566. (m (if (match-end 3) (string-to-number (match-string 3 s)) 0))
  4567. (ampm (if (match-end 4) (downcase (match-string 4 s))))
  4568. (am-p (equal ampm "am"))
  4569. (h1 (cond ((not ampm) h)
  4570. ((= h 12) (if am-p 0 12))
  4571. (t (+ h (if am-p 0 12)))))
  4572. (h2 (if (and string mod24 (not (and (= m 0) (= h1 24))))
  4573. (mod h1 24) h1))
  4574. (t0 (+ (* 100 h2) m))
  4575. (t1 (concat (if (>= h1 24) "+" " ")
  4576. (if (< t0 100) "0" "")
  4577. (if (< t0 10) "0" "")
  4578. (int-to-string t0))))
  4579. (if string (concat (substring t1 -4 -2) ":" (substring t1 -2)) t0)))))
  4580. (defun org-finalize-agenda-entries (list &optional nosort)
  4581. "Sort and concatenate the agenda items."
  4582. (setq list (mapcar 'org-agenda-highlight-todo list))
  4583. (if nosort
  4584. list
  4585. (mapconcat 'identity (sort list 'org-entries-lessp) "\n")))
  4586. (defun org-agenda-highlight-todo (x)
  4587. (let ((org-done-keywords org-done-keywords-for-agenda)
  4588. (case-fold-search nil)
  4589. re pl)
  4590. (if (eq x 'line)
  4591. (save-excursion
  4592. (beginning-of-line 1)
  4593. (setq re (org-get-at-bol 'org-todo-regexp))
  4594. (goto-char (+ (point) (or (org-get-at-bol 'prefix-length) 0)))
  4595. (when (looking-at (concat "[ \t]*\\.*\\(" re "\\) +"))
  4596. (add-text-properties (match-beginning 0) (match-end 1)
  4597. (list 'face (org-get-todo-face 1)))
  4598. (let ((s (buffer-substring (match-beginning 1) (match-end 1))))
  4599. (delete-region (match-beginning 1) (1- (match-end 0)))
  4600. (goto-char (match-beginning 1))
  4601. (insert (format org-agenda-todo-keyword-format s)))))
  4602. (setq re (concat (get-text-property 0 'org-todo-regexp x))
  4603. pl (get-text-property 0 'prefix-length x))
  4604. (when (and re
  4605. (equal (string-match (concat "\\(\\.*\\)" re "\\( +\\)")
  4606. x (or pl 0)) pl))
  4607. (add-text-properties
  4608. (or (match-end 1) (match-end 0)) (match-end 0)
  4609. (list 'face (org-get-todo-face (match-string 2 x)))
  4610. x)
  4611. (setq x (concat (substring x 0 (match-end 1))
  4612. (format org-agenda-todo-keyword-format
  4613. (match-string 2 x))
  4614. (org-add-props " " (text-properties-at 0 x))
  4615. (substring x (match-end 3)))))
  4616. x)))
  4617. (defsubst org-cmp-priority (a b)
  4618. "Compare the priorities of string A and B."
  4619. (let ((pa (or (get-text-property 1 'priority a) 0))
  4620. (pb (or (get-text-property 1 'priority b) 0)))
  4621. (cond ((> pa pb) +1)
  4622. ((< pa pb) -1)
  4623. (t nil))))
  4624. (defsubst org-cmp-effort (a b)
  4625. "Compare the priorities of string A and B."
  4626. (let* ((def (if org-sort-agenda-noeffort-is-high 32767 -1))
  4627. (ea (or (get-text-property 1 'effort-minutes a) def))
  4628. (eb (or (get-text-property 1 'effort-minutes b) def)))
  4629. (cond ((> ea eb) +1)
  4630. ((< ea eb) -1)
  4631. (t nil))))
  4632. (defsubst org-cmp-category (a b)
  4633. "Compare the string values of categories of strings A and B."
  4634. (let ((ca (or (get-text-property 1 'org-category a) ""))
  4635. (cb (or (get-text-property 1 'org-category b) "")))
  4636. (cond ((string-lessp ca cb) -1)
  4637. ((string-lessp cb ca) +1)
  4638. (t nil))))
  4639. (defsubst org-cmp-todo-state (a b)
  4640. "Compare the todo states of strings A and B."
  4641. (let* ((ma (or (get-text-property 1 'org-marker a)
  4642. (get-text-property 1 'org-hd-marker a)))
  4643. (mb (or (get-text-property 1 'org-marker b)
  4644. (get-text-property 1 'org-hd-marker b)))
  4645. (fa (and ma (marker-buffer ma)))
  4646. (fb (and mb (marker-buffer mb)))
  4647. (todo-kwds
  4648. (or (and fa (with-current-buffer fa org-todo-keywords-1))
  4649. (and fb (with-current-buffer fb org-todo-keywords-1))))
  4650. (ta (or (get-text-property 1 'todo-state a) ""))
  4651. (tb (or (get-text-property 1 'todo-state b) ""))
  4652. (la (- (length (member ta todo-kwds))))
  4653. (lb (- (length (member tb todo-kwds))))
  4654. (donepa (member ta org-done-keywords-for-agenda))
  4655. (donepb (member tb org-done-keywords-for-agenda)))
  4656. (cond ((and donepa (not donepb)) -1)
  4657. ((and (not donepa) donepb) +1)
  4658. ((< la lb) -1)
  4659. ((< lb la) +1)
  4660. (t nil))))
  4661. (defsubst org-cmp-tag (a b)
  4662. "Compare the string values of the first tags of A and B."
  4663. (let ((ta (car (last (get-text-property 1 'tags a))))
  4664. (tb (car (last (get-text-property 1 'tags b)))))
  4665. (cond ((not ta) +1)
  4666. ((not tb) -1)
  4667. ((string-lessp ta tb) -1)
  4668. ((string-lessp tb ta) +1)
  4669. (t nil))))
  4670. (defsubst org-cmp-time (a b)
  4671. "Compare the time-of-day values of strings A and B."
  4672. (let* ((def (if org-sort-agenda-notime-is-late 9901 -1))
  4673. (ta (or (get-text-property 1 'time-of-day a) def))
  4674. (tb (or (get-text-property 1 'time-of-day b) def)))
  4675. (cond ((< ta tb) -1)
  4676. ((< tb ta) +1)
  4677. (t nil))))
  4678. (defsubst org-cmp-habit-p (a b)
  4679. "Compare the todo states of strings A and B."
  4680. (let ((ha (get-text-property 1 'org-habit-p a))
  4681. (hb (get-text-property 1 'org-habit-p b)))
  4682. (cond ((and ha (not hb)) -1)
  4683. ((and (not ha) hb) +1)
  4684. (t nil))))
  4685. (defun org-entries-lessp (a b)
  4686. "Predicate for sorting agenda entries."
  4687. ;; The following variables will be used when the form is evaluated.
  4688. ;; So even though the compiler complains, keep them.
  4689. (let* ((time-up (org-cmp-time a b))
  4690. (time-down (if time-up (- time-up) nil))
  4691. (priority-up (org-cmp-priority a b))
  4692. (priority-down (if priority-up (- priority-up) nil))
  4693. (effort-up (org-cmp-effort a b))
  4694. (effort-down (if effort-up (- effort-up) nil))
  4695. (category-up (org-cmp-category a b))
  4696. (category-down (if category-up (- category-up) nil))
  4697. (category-keep (if category-up +1 nil))
  4698. (tag-up (org-cmp-tag a b))
  4699. (tag-down (if tag-up (- tag-up) nil))
  4700. (todo-state-up (org-cmp-todo-state a b))
  4701. (todo-state-down (if todo-state-up (- todo-state-up) nil))
  4702. (habit-up (org-cmp-habit-p a b))
  4703. (habit-down (if habit-up (- habit-up) nil))
  4704. user-defined-up user-defined-down)
  4705. (if (and org-agenda-cmp-user-defined
  4706. (functionp org-agenda-cmp-user-defined))
  4707. (setq user-defined-up
  4708. (funcall org-agenda-cmp-user-defined a b)
  4709. user-defined-down (if user-defined-up (- user-defined-up) nil)))
  4710. (cdr (assoc
  4711. (eval (cons 'or org-agenda-sorting-strategy-selected))
  4712. '((-1 . t) (1 . nil) (nil . nil))))))
  4713. ;;; Agenda restriction lock
  4714. (defvar org-agenda-restriction-lock-overlay (org-make-overlay 1 1)
  4715. "Overlay to mark the headline to which agenda commands are restricted.")
  4716. (org-overlay-put org-agenda-restriction-lock-overlay
  4717. 'face 'org-agenda-restriction-lock)
  4718. (org-overlay-put org-agenda-restriction-lock-overlay
  4719. 'help-echo "Agendas are currently limited to this subtree.")
  4720. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4721. (defun org-agenda-set-restriction-lock (&optional type)
  4722. "Set restriction lock for agenda, to current subtree or file.
  4723. Restriction will be the file if TYPE is `file', or if type is the
  4724. universal prefix '(4), or if the cursor is before the first headline
  4725. in the file. Otherwise, restriction will be to the current subtree."
  4726. (interactive "P")
  4727. (and (equal type '(4)) (setq type 'file))
  4728. (setq type (cond
  4729. (type type)
  4730. ((org-at-heading-p) 'subtree)
  4731. ((condition-case nil (org-back-to-heading t) (error nil))
  4732. 'subtree)
  4733. (t 'file)))
  4734. (if (eq type 'subtree)
  4735. (progn
  4736. (setq org-agenda-restrict t)
  4737. (setq org-agenda-overriding-restriction 'subtree)
  4738. (put 'org-agenda-files 'org-restrict
  4739. (list (buffer-file-name (buffer-base-buffer))))
  4740. (org-back-to-heading t)
  4741. (org-move-overlay org-agenda-restriction-lock-overlay (point) (point-at-eol))
  4742. (move-marker org-agenda-restrict-begin (point))
  4743. (move-marker org-agenda-restrict-end
  4744. (save-excursion (org-end-of-subtree t)))
  4745. (message "Locking agenda restriction to subtree"))
  4746. (put 'org-agenda-files 'org-restrict
  4747. (list (buffer-file-name (buffer-base-buffer))))
  4748. (setq org-agenda-restrict nil)
  4749. (setq org-agenda-overriding-restriction 'file)
  4750. (move-marker org-agenda-restrict-begin nil)
  4751. (move-marker org-agenda-restrict-end nil)
  4752. (message "Locking agenda restriction to file"))
  4753. (setq current-prefix-arg nil)
  4754. (org-agenda-maybe-redo))
  4755. (defun org-agenda-remove-restriction-lock (&optional noupdate)
  4756. "Remove the agenda restriction lock."
  4757. (interactive "P")
  4758. (org-detach-overlay org-agenda-restriction-lock-overlay)
  4759. (org-detach-overlay org-speedbar-restriction-lock-overlay)
  4760. (setq org-agenda-overriding-restriction nil)
  4761. (setq org-agenda-restrict nil)
  4762. (put 'org-agenda-files 'org-restrict nil)
  4763. (move-marker org-agenda-restrict-begin nil)
  4764. (move-marker org-agenda-restrict-end nil)
  4765. (setq current-prefix-arg nil)
  4766. (message "Agenda restriction lock removed")
  4767. (or noupdate (org-agenda-maybe-redo)))
  4768. (defun org-agenda-maybe-redo ()
  4769. "If there is any window showing the agenda view, update it."
  4770. (let ((w (get-buffer-window org-agenda-buffer-name t))
  4771. (w0 (selected-window)))
  4772. (when w
  4773. (select-window w)
  4774. (org-agenda-redo)
  4775. (select-window w0)
  4776. (if org-agenda-overriding-restriction
  4777. (message "Agenda view shifted to new %s restriction"
  4778. org-agenda-overriding-restriction)
  4779. (message "Agenda restriction lock removed")))))
  4780. ;;; Agenda commands
  4781. (defun org-agenda-check-type (error &rest types)
  4782. "Check if agenda buffer is of allowed type.
  4783. If ERROR is non-nil, throw an error, otherwise just return nil."
  4784. (if (memq org-agenda-type types)
  4785. t
  4786. (if error
  4787. (error "Not allowed in %s-type agenda buffers" org-agenda-type)
  4788. nil)))
  4789. (defun org-agenda-quit ()
  4790. "Exit agenda by removing the window or the buffer."
  4791. (interactive)
  4792. (if org-agenda-columns-active
  4793. (org-columns-quit)
  4794. (let ((buf (current-buffer)))
  4795. (if (eq org-agenda-window-setup 'other-frame)
  4796. (progn
  4797. (kill-buffer buf)
  4798. (org-agenda-reset-markers)
  4799. (org-columns-remove-overlays)
  4800. (setq org-agenda-archives-mode nil)
  4801. (delete-frame))
  4802. (and (not (eq org-agenda-window-setup 'current-window))
  4803. (not (one-window-p))
  4804. (delete-window))
  4805. (kill-buffer buf)
  4806. (org-agenda-reset-markers)
  4807. (org-columns-remove-overlays)
  4808. (setq org-agenda-archives-mode nil)))
  4809. ;; Maybe restore the pre-agenda window configuration.
  4810. (and org-agenda-restore-windows-after-quit
  4811. (not (eq org-agenda-window-setup 'other-frame))
  4812. org-pre-agenda-window-conf
  4813. (set-window-configuration org-pre-agenda-window-conf))))
  4814. (defun org-agenda-exit ()
  4815. "Exit agenda by removing the window or the buffer.
  4816. Also kill all Org-mode buffers which have been loaded by `org-agenda'.
  4817. Org-mode buffers visited directly by the user will not be touched."
  4818. (interactive)
  4819. (org-release-buffers org-agenda-new-buffers)
  4820. (setq org-agenda-new-buffers nil)
  4821. (org-agenda-quit))
  4822. (defun org-agenda-execute (arg)
  4823. "Execute another agenda command, keeping same window.\\<global-map>
  4824. So this is just a shortcut for `\\[org-agenda]', available in the agenda."
  4825. (interactive "P")
  4826. (let ((org-agenda-window-setup 'current-window))
  4827. (org-agenda arg)))
  4828. (defun org-agenda-redo ()
  4829. "Rebuild Agenda.
  4830. When this is the global TODO list, a prefix argument will be interpreted."
  4831. (interactive)
  4832. (let* ((org-agenda-keep-modes t)
  4833. (filter org-agenda-filter)
  4834. (preset (get 'org-agenda-filter :preset-filter))
  4835. (cols org-agenda-columns-active)
  4836. (line (org-current-line))
  4837. (window-line (- line (org-current-line (window-start))))
  4838. (lprops (get 'org-agenda-redo-command 'org-lprops)))
  4839. (put 'org-agenda-filter :preset-filter nil)
  4840. (and cols (org-columns-quit))
  4841. (message "Rebuilding agenda buffer...")
  4842. (org-let lprops '(eval org-agenda-redo-command))
  4843. (setq org-agenda-undo-list nil
  4844. org-agenda-pending-undo-list nil)
  4845. (message "Rebuilding agenda buffer...done")
  4846. (put 'org-agenda-filter :preset-filter preset)
  4847. (and (or filter preset) (org-agenda-filter-apply filter))
  4848. (and cols (interactive-p) (org-agenda-columns))
  4849. (org-goto-line line)
  4850. (recenter window-line)))
  4851. (defvar org-global-tags-completion-table nil)
  4852. (defvar org-agenda-filter-form nil)
  4853. (defun org-agenda-filter-by-tag (strip &optional char narrow)
  4854. "Keep only those lines in the agenda buffer that have a specific tag.
  4855. The tag is selected with its fast selection letter, as configured.
  4856. With prefix argument STRIP, remove all lines that do have the tag.
  4857. A lisp caller can specify CHAR. NARROW means that the new tag should be
  4858. used to narrow the search - the interactive user can also press `-' or `+'
  4859. to switch to narrowing."
  4860. (interactive "P")
  4861. (let* ((alist org-tag-alist-for-agenda)
  4862. (tag-chars (mapconcat
  4863. (lambda (x) (if (and (not (symbolp (car x)))
  4864. (cdr x))
  4865. (char-to-string (cdr x))
  4866. ""))
  4867. alist ""))
  4868. (efforts (org-split-string
  4869. (or (cdr (assoc (concat org-effort-property "_ALL")
  4870. org-global-properties))
  4871. "0 0:10 0:30 1:00 2:00 3:00 4:00 5:00 6:00 7:00 8:00" "")))
  4872. (effort-op org-agenda-filter-effort-default-operator)
  4873. (effort-prompt "")
  4874. (inhibit-read-only t)
  4875. (current org-agenda-filter)
  4876. a n tag)
  4877. (unless char
  4878. (message
  4879. "%s by tag [%s ], [TAB], %s[/]:off, [+-]:narrow, [>=<?]:effort: "
  4880. (if narrow "Narrow" "Filter") tag-chars
  4881. (if org-agenda-auto-exclude-function "[RET], " ""))
  4882. (setq char (read-char)))
  4883. (when (member char '(?+ ?-))
  4884. ;; Narrowing down
  4885. (cond ((equal char ?-) (setq strip t narrow t))
  4886. ((equal char ?+) (setq strip nil narrow t)))
  4887. (message
  4888. "Narrow by tag [%s ], [TAB], [/]:off, [>=<]:effort: " tag-chars)
  4889. (setq char (read-char)))
  4890. (when (member char '(?< ?> ?= ??))
  4891. ;; An effort operator
  4892. (setq effort-op (char-to-string char))
  4893. (setq alist nil) ; to make sure it will be interpreted as effort.
  4894. (unless (equal char ??)
  4895. (loop for i from 0 to 9 do
  4896. (setq effort-prompt
  4897. (concat
  4898. effort-prompt " ["
  4899. (if (= i 9) "0" (int-to-string (1+ i)))
  4900. "]" (nth i efforts))))
  4901. (message "Effort%s: %s " effort-op effort-prompt)
  4902. (setq char (read-char))
  4903. (when (or (< char ?0) (> char ?9))
  4904. (error "Need 1-9,0 to select effort" ))))
  4905. (when (equal char ?\t)
  4906. (unless (local-variable-p 'org-global-tags-completion-table (current-buffer))
  4907. (org-set-local 'org-global-tags-completion-table
  4908. (org-global-tags-completion-table)))
  4909. (let ((completion-ignore-case t))
  4910. (setq tag (org-icompleting-read
  4911. "Tag: " org-global-tags-completion-table))))
  4912. (cond
  4913. ((equal char ?\r)
  4914. (org-agenda-filter-by-tag-show-all)
  4915. (when org-agenda-auto-exclude-function
  4916. (setq org-agenda-filter '())
  4917. (dolist (tag (org-agenda-get-represented-tags))
  4918. (let ((modifier (funcall org-agenda-auto-exclude-function tag)))
  4919. (if modifier
  4920. (push modifier org-agenda-filter))))
  4921. (if (not (null org-agenda-filter))
  4922. (org-agenda-filter-apply org-agenda-filter))))
  4923. ((equal char ?/)
  4924. (org-agenda-filter-by-tag-show-all)
  4925. (when (get 'org-agenda-filter :preset-filter)
  4926. (org-agenda-filter-apply org-agenda-filter)))
  4927. ((or (equal char ?\ )
  4928. (setq a (rassoc char alist))
  4929. (and (>= char ?0) (<= char ?9)
  4930. (setq n (if (= char ?0) 9 (- char ?0 1))
  4931. tag (concat effort-op (nth n efforts))
  4932. a (cons tag nil)))
  4933. (and (= char ??)
  4934. (setq tag "?eff")
  4935. a (cons tag nil))
  4936. (and tag (setq a (cons tag nil))))
  4937. (org-agenda-filter-by-tag-show-all)
  4938. (setq tag (car a))
  4939. (setq org-agenda-filter
  4940. (cons (concat (if strip "-" "+") tag)
  4941. (if narrow current nil)))
  4942. (org-agenda-filter-apply org-agenda-filter))
  4943. (t (error "Invalid tag selection character %c" char)))))
  4944. (defun org-agenda-get-represented-tags ()
  4945. "Get a list of all tags currently represented in the agenda."
  4946. (let (p tags)
  4947. (save-excursion
  4948. (goto-char (point-min))
  4949. (while (setq p (next-single-property-change (point) 'tags))
  4950. (goto-char p)
  4951. (mapc (lambda (x) (add-to-list 'tags x))
  4952. (get-text-property (point) 'tags))))
  4953. tags))
  4954. (defun org-agenda-filter-by-tag-refine (strip &optional char)
  4955. "Refine the current filter. See `org-agenda-filter-by-tag."
  4956. (interactive "P")
  4957. (org-agenda-filter-by-tag strip char 'refine))
  4958. (defun org-agenda-filter-make-matcher ()
  4959. "Create the form that tests a line for the agenda filter."
  4960. (let (f f1)
  4961. (dolist (x (append (get 'org-agenda-filter :preset-filter)
  4962. org-agenda-filter))
  4963. (if (member x '("-" "+"))
  4964. (setq f1 (if (equal x "-") 'tags '(not tags)))
  4965. (if (string-match "[<=>?]" x)
  4966. (setq f1 (org-agenda-filter-effort-form x))
  4967. (setq f1 (list 'member (downcase (substring x 1)) 'tags)))
  4968. (if (equal (string-to-char x) ?-)
  4969. (setq f1 (list 'not f1))))
  4970. (push f1 f))
  4971. (cons 'and (nreverse f))))
  4972. (defun org-agenda-filter-effort-form (e)
  4973. "Return the form to compare the effort of the current line with what E says.
  4974. E looks line \"+<2:25\"."
  4975. (let (op)
  4976. (setq e (substring e 1))
  4977. (setq op (string-to-char e) e (substring e 1))
  4978. (setq op (cond ((equal op ?<) '<=)
  4979. ((equal op ?>) '>=)
  4980. ((equal op ??) op)
  4981. (t '=)))
  4982. (list 'org-agenda-compare-effort (list 'quote op)
  4983. (org-hh:mm-string-to-minutes e))))
  4984. (defun org-agenda-compare-effort (op value)
  4985. "Compare the effort of the current line with VALUE, using OP.
  4986. If the line does not have an effort defined, return nil."
  4987. (let ((eff (org-get-at-bol 'effort-minutes)))
  4988. (if (equal op ??)
  4989. (not eff)
  4990. (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))
  4991. value))))
  4992. (defun org-agenda-filter-apply (filter)
  4993. "Set FILTER as the new agenda filter and apply it."
  4994. (let (tags)
  4995. (setq org-agenda-filter filter
  4996. org-agenda-filter-form (org-agenda-filter-make-matcher))
  4997. (org-agenda-set-mode-name)
  4998. (save-excursion
  4999. (goto-char (point-min))
  5000. (while (not (eobp))
  5001. (if (org-get-at-bol 'org-marker)
  5002. (progn
  5003. (setq tags (org-get-at-bol 'tags)) ; used in eval
  5004. (if (not (eval org-agenda-filter-form))
  5005. (org-agenda-filter-by-tag-hide-line))
  5006. (beginning-of-line 2))
  5007. (beginning-of-line 2))))))
  5008. (defun org-agenda-filter-by-tag-hide-line ()
  5009. (let (ov)
  5010. (setq ov (org-make-overlay (max (point-min) (1- (point-at-bol)))
  5011. (point-at-eol)))
  5012. (org-overlay-put ov 'invisible t)
  5013. (org-overlay-put ov 'type 'tags-filter)
  5014. (push ov org-agenda-filter-overlays)))
  5015. (defun org-agenda-fix-tags-filter-overlays-at (&optional pos)
  5016. (setq pos (or pos (point)))
  5017. (save-excursion
  5018. (dolist (ov (org-overlays-at pos))
  5019. (when (and (org-overlay-get ov 'invisible)
  5020. (eq (org-overlay-get ov 'type) 'tags-filter))
  5021. (goto-char pos)
  5022. (if (< (org-overlay-start ov) (point-at-eol))
  5023. (org-move-overlay ov (point-at-eol)
  5024. (org-overlay-end ov)))))))
  5025. (defun org-agenda-filter-by-tag-show-all ()
  5026. (mapc 'org-delete-overlay org-agenda-filter-overlays)
  5027. (setq org-agenda-filter-overlays nil)
  5028. (setq org-agenda-filter nil)
  5029. (setq org-agenda-filter-form nil)
  5030. (org-agenda-set-mode-name))
  5031. (defun org-agenda-manipulate-query-add ()
  5032. "Manipulate the query by adding a search term with positive selection.
  5033. Positive selection means, the term must be matched for selection of an entry."
  5034. (interactive)
  5035. (org-agenda-manipulate-query ?\[))
  5036. (defun org-agenda-manipulate-query-subtract ()
  5037. "Manipulate the query by adding a search term with negative selection.
  5038. Negative selection means, term must not be matched for selection of an entry."
  5039. (interactive)
  5040. (org-agenda-manipulate-query ?\]))
  5041. (defun org-agenda-manipulate-query-add-re ()
  5042. "Manipulate the query by adding a search regexp with positive selection.
  5043. Positive selection means, the regexp must match for selection of an entry."
  5044. (interactive)
  5045. (org-agenda-manipulate-query ?\{))
  5046. (defun org-agenda-manipulate-query-subtract-re ()
  5047. "Manipulate the query by adding a search regexp with negative selection.
  5048. Negative selection means, regexp must not match for selection of an entry."
  5049. (interactive)
  5050. (org-agenda-manipulate-query ?\}))
  5051. (defun org-agenda-manipulate-query (char)
  5052. (cond
  5053. ((memq org-agenda-type '(timeline agenda))
  5054. (let ((org-agenda-include-inactive-timestamps t))
  5055. (org-agenda-redo))
  5056. (message "Display now includes inactive timestamps as well"))
  5057. ((eq org-agenda-type 'search)
  5058. (org-add-to-string
  5059. 'org-agenda-query-string
  5060. (if org-agenda-last-search-view-search-was-boolean
  5061. (cdr (assoc char '((?\[ . " +") (?\] . " -")
  5062. (?\{ . " +{}") (?\} . " -{}"))))
  5063. " "))
  5064. (setq org-agenda-redo-command
  5065. (list 'org-search-view
  5066. org-todo-only
  5067. org-agenda-query-string
  5068. (+ (length org-agenda-query-string)
  5069. (if (member char '(?\{ ?\})) 0 1))))
  5070. (set-register org-agenda-query-register org-agenda-query-string)
  5071. (org-agenda-redo))
  5072. (t (error "Cannot manipulate query for %s-type agenda buffers"
  5073. org-agenda-type))))
  5074. (defun org-add-to-string (var string)
  5075. (set var (concat (symbol-value var) string)))
  5076. (defun org-agenda-goto-date (date)
  5077. "Jump to DATE in agenda."
  5078. (interactive (list (org-read-date)))
  5079. (org-agenda-list nil date))
  5080. (defun org-agenda-goto-today ()
  5081. "Go to today."
  5082. (interactive)
  5083. (org-agenda-check-type t 'timeline 'agenda)
  5084. (let ((tdpos (text-property-any (point-min) (point-max) 'org-today t)))
  5085. (cond
  5086. (tdpos (goto-char tdpos))
  5087. ((eq org-agenda-type 'agenda)
  5088. (let* ((sd (time-to-days
  5089. (time-subtract (current-time)
  5090. (list 0 (* 3600 org-extend-today-until) 0))))
  5091. (comp (org-agenda-compute-time-span sd org-agenda-span))
  5092. (org-agenda-overriding-arguments org-agenda-last-arguments))
  5093. (setf (nth 1 org-agenda-overriding-arguments) (car comp))
  5094. (setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
  5095. (org-agenda-redo)
  5096. (org-agenda-find-same-or-today-or-agenda)))
  5097. (t (error "Cannot find today")))))
  5098. (defun org-agenda-find-same-or-today-or-agenda (&optional cnt)
  5099. (goto-char
  5100. (or (and cnt (text-property-any (point-min) (point-max) 'org-day-cnt cnt))
  5101. (text-property-any (point-min) (point-max) 'org-today t)
  5102. (text-property-any (point-min) (point-max) 'org-agenda-type 'agenda)
  5103. (point-min))))
  5104. (defun org-agenda-later (arg)
  5105. "Go forward in time by thee current span.
  5106. With prefix ARG, go forward that many times the current span."
  5107. (interactive "p")
  5108. (org-agenda-check-type t 'agenda)
  5109. (let* ((span org-agenda-span)
  5110. (sd org-starting-day)
  5111. (greg (calendar-gregorian-from-absolute sd))
  5112. (cnt (org-get-at-bol 'org-day-cnt))
  5113. greg2 nd)
  5114. (cond
  5115. ((eq span 'day)
  5116. (setq sd (+ arg sd) nd 1))
  5117. ((eq span 'week)
  5118. (setq sd (+ (* 7 arg) sd) nd 7))
  5119. ((eq span 'month)
  5120. (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
  5121. sd (calendar-absolute-from-gregorian greg2))
  5122. (setcar greg2 (1+ (car greg2)))
  5123. (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
  5124. ((eq span 'year)
  5125. (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
  5126. sd (calendar-absolute-from-gregorian greg2))
  5127. (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
  5128. (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
  5129. (let ((org-agenda-overriding-arguments
  5130. (list (car org-agenda-last-arguments) sd nd t)))
  5131. (org-agenda-redo)
  5132. (org-agenda-find-same-or-today-or-agenda cnt))))
  5133. (defun org-agenda-earlier (arg)
  5134. "Go backward in time by the current span.
  5135. With prefix ARG, go backward that many times the current span."
  5136. (interactive "p")
  5137. (org-agenda-later (- arg)))
  5138. (defun org-agenda-view-mode-dispatch ()
  5139. "Call one of the view mode commands."
  5140. (interactive)
  5141. (message "View: [d]ay [w]eek [m]onth [y]ear [l]og [L]og-all [a]rch-trees [A]rch-files
  5142. clock[R]eport time[G]rid [[]inactive [E]ntryText include[D]iary")
  5143. (let ((a (read-char-exclusive)))
  5144. (case a
  5145. (?d (call-interactively 'org-agenda-day-view))
  5146. (?w (call-interactively 'org-agenda-week-view))
  5147. (?m (call-interactively 'org-agenda-month-view))
  5148. (?y (call-interactively 'org-agenda-year-view))
  5149. (?l (call-interactively 'org-agenda-log-mode))
  5150. (?L (org-agenda-log-mode '(4)))
  5151. ((?F ?f) (call-interactively 'org-agenda-follow-mode))
  5152. (?a (call-interactively 'org-agenda-archives-mode))
  5153. (?A (org-agenda-archives-mode 'files))
  5154. ((?R ?r) (call-interactively 'org-agenda-clockreport-mode))
  5155. ((?E ?e) (call-interactively 'org-agenda-entry-text-mode))
  5156. (?G (call-interactively 'org-agenda-toggle-time-grid))
  5157. (?D (call-interactively 'org-agenda-toggle-diary))
  5158. (?\[ (let ((org-agenda-include-inactive-timestamps t))
  5159. (org-agenda-check-type t 'timeline 'agenda)
  5160. (org-agenda-redo))
  5161. (message "Display now includes inactive timestamps as well"))
  5162. (?q (message "Abort"))
  5163. (otherwise (error "Invalid key" )))))
  5164. (defun org-agenda-day-view (&optional day-of-year)
  5165. "Switch to daily view for agenda.
  5166. With argument DAY-OF-YEAR, switch to that day of the year."
  5167. (interactive "P")
  5168. (setq org-agenda-ndays 1)
  5169. (org-agenda-change-time-span 'day day-of-year))
  5170. (defun org-agenda-week-view (&optional iso-week)
  5171. "Switch to daily view for agenda.
  5172. With argument ISO-WEEK, switch to the corresponding ISO week.
  5173. If ISO-WEEK has more then 2 digits, only the last two encode the
  5174. week. Any digits before this encode a year. So 200712 means
  5175. week 12 of year 2007. Years in the range 1938-2037 can also be
  5176. written as 2-digit years."
  5177. (interactive "P")
  5178. (setq org-agenda-ndays 7)
  5179. (org-agenda-change-time-span 'week iso-week))
  5180. (defun org-agenda-month-view (&optional month)
  5181. "Switch to monthly view for agenda.
  5182. With argument MONTH, switch to that month."
  5183. (interactive "P")
  5184. (org-agenda-change-time-span 'month month))
  5185. (defun org-agenda-year-view (&optional year)
  5186. "Switch to yearly view for agenda.
  5187. With argument YEAR, switch to that year.
  5188. If MONTH has more then 2 digits, only the last two encode the
  5189. month. Any digits before this encode a year. So 200712 means
  5190. December year 2007. Years in the range 1938-2037 can also be
  5191. written as 2-digit years."
  5192. (interactive "P")
  5193. (when year
  5194. (setq year (org-small-year-to-year year)))
  5195. (if (y-or-n-p "Are you sure you want to compute the agenda for an entire year? ")
  5196. (org-agenda-change-time-span 'year year)
  5197. (error "Abort")))
  5198. (defun org-agenda-change-time-span (span &optional n)
  5199. "Change the agenda view to SPAN.
  5200. SPAN may be `day', `week', `month', `year'."
  5201. (org-agenda-check-type t 'agenda)
  5202. (if (and (not n) (equal org-agenda-span span))
  5203. (error "Viewing span is already \"%s\"" span))
  5204. (let* ((sd (or (org-get-at-bol 'day)
  5205. org-starting-day))
  5206. (computed (org-agenda-compute-time-span sd span n))
  5207. (org-agenda-overriding-arguments
  5208. (list (car org-agenda-last-arguments)
  5209. (car computed) (cdr computed) t)))
  5210. (org-agenda-redo)
  5211. (org-agenda-find-same-or-today-or-agenda))
  5212. (org-agenda-set-mode-name)
  5213. (message "Switched to %s view" span))
  5214. (defun org-agenda-compute-time-span (sd span &optional n)
  5215. "Compute starting date and number of days for agenda.
  5216. SPAN may be `day', `week', `month', `year'. The return value
  5217. is a cons cell with the starting date and the number of days,
  5218. so that the date SD will be in that range."
  5219. (let* ((greg (calendar-gregorian-from-absolute sd))
  5220. (dg (nth 1 greg))
  5221. (mg (car greg))
  5222. (yg (nth 2 greg))
  5223. nd w1 y1 m1 thisweek)
  5224. (cond
  5225. ((eq span 'day)
  5226. (when n
  5227. (setq sd (+ (calendar-absolute-from-gregorian
  5228. (list mg 1 yg))
  5229. n -1)))
  5230. (setq nd 1))
  5231. ((eq span 'week)
  5232. (let* ((nt (calendar-day-of-week
  5233. (calendar-gregorian-from-absolute sd)))
  5234. (d (if org-agenda-start-on-weekday
  5235. (- nt org-agenda-start-on-weekday)
  5236. 0)))
  5237. (setq sd (- sd (+ (if (< d 0) 7 0) d)))
  5238. (when n
  5239. (require 'cal-iso)
  5240. (setq thisweek (car (calendar-iso-from-absolute sd)))
  5241. (when (> n 99)
  5242. (setq y1 (org-small-year-to-year (/ n 100))
  5243. n (mod n 100)))
  5244. (setq sd
  5245. (calendar-absolute-from-iso
  5246. (list n 1
  5247. (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
  5248. (setq nd 7)))
  5249. ((eq span 'month)
  5250. (when (and n (> n 99))
  5251. (setq y1 (org-small-year-to-year (/ n 100))
  5252. n (mod n 100)))
  5253. (setq sd (calendar-absolute-from-gregorian
  5254. (list (or n mg) 1 (or y1 yg)))
  5255. nd (- (calendar-absolute-from-gregorian
  5256. (list (1+ (or n mg)) 1 (or y1 yg)))
  5257. sd)))
  5258. ((eq span 'year)
  5259. (setq sd (calendar-absolute-from-gregorian
  5260. (list 1 1 (or n yg)))
  5261. nd (- (calendar-absolute-from-gregorian
  5262. (list 1 1 (1+ (or n yg))))
  5263. sd))))
  5264. (cons sd nd)))
  5265. (defun org-agenda-next-date-line (&optional arg)
  5266. "Jump to the next line indicating a date in agenda buffer."
  5267. (interactive "p")
  5268. (org-agenda-check-type t 'agenda 'timeline)
  5269. (beginning-of-line 1)
  5270. ;; This does not work if user makes date format that starts with a blank
  5271. (if (looking-at "^\\S-") (forward-char 1))
  5272. (if (not (re-search-forward "^\\S-" nil t arg))
  5273. (progn
  5274. (backward-char 1)
  5275. (error "No next date after this line in this buffer")))
  5276. (goto-char (match-beginning 0)))
  5277. (defun org-agenda-previous-date-line (&optional arg)
  5278. "Jump to the previous line indicating a date in agenda buffer."
  5279. (interactive "p")
  5280. (org-agenda-check-type t 'agenda 'timeline)
  5281. (beginning-of-line 1)
  5282. (if (not (re-search-backward "^\\S-" nil t arg))
  5283. (error "No previous date before this line in this buffer")))
  5284. ;; Initialize the highlight
  5285. (defvar org-hl (org-make-overlay 1 1))
  5286. (org-overlay-put org-hl 'face 'highlight)
  5287. (defun org-highlight (begin end &optional buffer)
  5288. "Highlight a region with overlay."
  5289. (funcall (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)
  5290. org-hl begin end (or buffer (current-buffer))))
  5291. (defun org-unhighlight ()
  5292. "Detach overlay INDEX."
  5293. (funcall (if (featurep 'xemacs) 'detach-extent 'delete-overlay) org-hl))
  5294. ;; FIXME this is currently not used.
  5295. (defun org-highlight-until-next-command (beg end &optional buffer)
  5296. "Move the highlight overlay to BEG/END, remove it before the next command."
  5297. (org-highlight beg end buffer)
  5298. (add-hook 'pre-command-hook 'org-unhighlight-once))
  5299. (defun org-unhighlight-once ()
  5300. "Remove the highlight from its position, and this function from the hook."
  5301. (remove-hook 'pre-command-hook 'org-unhighlight-once)
  5302. (org-unhighlight))
  5303. (defun org-agenda-follow-mode ()
  5304. "Toggle follow mode in an agenda buffer."
  5305. (interactive)
  5306. (setq org-agenda-follow-mode (not org-agenda-follow-mode))
  5307. (org-agenda-set-mode-name)
  5308. (if (and org-agenda-follow-mode (org-get-at-bol 'org-marker))
  5309. (org-agenda-show))
  5310. (message "Follow mode is %s"
  5311. (if org-agenda-follow-mode "on" "off")))
  5312. (defun org-agenda-entry-text-mode (&optional arg)
  5313. "Toggle entry text mode in an agenda buffer."
  5314. (interactive "P")
  5315. (if (integerp arg)
  5316. (setq org-agenda-entry-text-mode t)
  5317. (setq org-agenda-entry-text-mode (not org-agenda-entry-text-mode)))
  5318. (org-agenda-entry-text-hide)
  5319. (and org-agenda-entry-text-mode
  5320. (let ((org-agenda-entry-text-maxlines
  5321. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5322. (org-agenda-entry-text-show)))
  5323. (org-agenda-set-mode-name)
  5324. (message "Entry text mode is %s. Maximum number of lines is %d"
  5325. (if org-agenda-entry-text-mode "on" "off")
  5326. (if (integerp arg) arg org-agenda-entry-text-maxlines)))
  5327. (defun org-agenda-clockreport-mode ()
  5328. "Toggle clocktable mode in an agenda buffer."
  5329. (interactive)
  5330. (org-agenda-check-type t 'agenda)
  5331. (setq org-agenda-clockreport-mode (not org-agenda-clockreport-mode))
  5332. (org-agenda-set-mode-name)
  5333. (org-agenda-redo)
  5334. (message "Clocktable mode is %s"
  5335. (if org-agenda-clockreport-mode "on" "off")))
  5336. (defun org-agenda-log-mode (&optional special)
  5337. "Toggle log mode in an agenda buffer.
  5338. With argument SPECIAL, show all possible log items, not only the ones
  5339. configured in `org-agenda-log-mode-items'.
  5340. With a double `C-u' prefix arg, show *only* log items, nothing else."
  5341. (interactive "P")
  5342. (org-agenda-check-type t 'agenda 'timeline)
  5343. (setq org-agenda-show-log
  5344. (if (equal special '(16))
  5345. 'only
  5346. (if special '(closed clock state)
  5347. (not org-agenda-show-log))))
  5348. (org-agenda-set-mode-name)
  5349. (org-agenda-redo)
  5350. (message "Log mode is %s"
  5351. (if org-agenda-show-log "on" "off")))
  5352. (defun org-agenda-archives-mode (&optional with-files)
  5353. "Toggle inclusion of items in trees marked with :ARCHIVE:.
  5354. When called with a prefix argument, include all archive files as well."
  5355. (interactive "P")
  5356. (setq org-agenda-archives-mode
  5357. (if with-files t (if org-agenda-archives-mode nil 'trees)))
  5358. (org-agenda-set-mode-name)
  5359. (org-agenda-redo)
  5360. (message
  5361. "%s"
  5362. (cond
  5363. ((eq org-agenda-archives-mode nil)
  5364. "No archives are included")
  5365. ((eq org-agenda-archives-mode 'trees)
  5366. (format "Trees with :%s: tag are included" org-archive-tag))
  5367. ((eq org-agenda-archives-mode t)
  5368. (format "Trees with :%s: tag and all active archive files are included"
  5369. org-archive-tag)))))
  5370. (defun org-agenda-toggle-diary ()
  5371. "Toggle diary inclusion in an agenda buffer."
  5372. (interactive)
  5373. (org-agenda-check-type t 'agenda)
  5374. (setq org-agenda-include-diary (not org-agenda-include-diary))
  5375. (org-agenda-redo)
  5376. (org-agenda-set-mode-name)
  5377. (message "Diary inclusion turned %s"
  5378. (if org-agenda-include-diary "on" "off")))
  5379. (defun org-agenda-toggle-time-grid ()
  5380. "Toggle time grid in an agenda buffer."
  5381. (interactive)
  5382. (org-agenda-check-type t 'agenda)
  5383. (setq org-agenda-use-time-grid (not org-agenda-use-time-grid))
  5384. (org-agenda-redo)
  5385. (org-agenda-set-mode-name)
  5386. (message "Time-grid turned %s"
  5387. (if org-agenda-use-time-grid "on" "off")))
  5388. (defun org-agenda-set-mode-name ()
  5389. "Set the mode name to indicate all the small mode settings."
  5390. (setq mode-name
  5391. (concat "Org-Agenda"
  5392. (if (equal org-agenda-ndays 1) " Day" "")
  5393. (if (equal org-agenda-ndays 7) " Week" "")
  5394. (if org-agenda-follow-mode " Follow" "")
  5395. (if org-agenda-entry-text-mode " ETxt" "")
  5396. (if org-agenda-include-diary " Diary" "")
  5397. (if org-agenda-use-time-grid " Grid" "")
  5398. (if (and (boundp 'org-habit-show-habits)
  5399. org-habit-show-habits) " Habit" "")
  5400. (if (consp org-agenda-show-log) " LogAll"
  5401. (if org-agenda-show-log " Log" ""))
  5402. (if (or org-agenda-filter (get 'org-agenda-filter
  5403. :preset-filter))
  5404. (concat " {" (mapconcat
  5405. 'identity
  5406. (append (get 'org-agenda-filter
  5407. :preset-filter)
  5408. org-agenda-filter) "") "}")
  5409. "")
  5410. (if org-agenda-archives-mode
  5411. (if (eq org-agenda-archives-mode t)
  5412. " Archives"
  5413. (format " :%s:" org-archive-tag))
  5414. "")
  5415. (if org-agenda-clockreport-mode " Clock" "")))
  5416. (force-mode-line-update))
  5417. (defun org-agenda-post-command-hook ()
  5418. (setq org-agenda-type
  5419. (or (get-text-property (point) 'org-agenda-type)
  5420. (get-text-property (max (point-min) (1- (point)))
  5421. 'org-agenda-type))))
  5422. (defun org-agenda-next-line ()
  5423. "Move cursor to the next line, and show if follow-mode is active."
  5424. (interactive)
  5425. (call-interactively 'next-line)
  5426. (org-agenda-do-context-action))
  5427. (defun org-agenda-previous-line ()
  5428. "Move cursor to the previous line, and show if follow-mode is active."
  5429. (interactive)
  5430. (call-interactively 'previous-line)
  5431. (org-agenda-do-context-action))
  5432. (defun org-agenda-do-context-action ()
  5433. "Show outline path and, maybe, follow-mode window."
  5434. (let ((m (org-get-at-bol 'org-marker)))
  5435. (if (and org-agenda-follow-mode m)
  5436. (org-agenda-show))
  5437. (if (and m org-agenda-show-outline-path)
  5438. (org-with-point-at m
  5439. (org-display-outline-path t)))))
  5440. (defun org-agenda-show-priority ()
  5441. "Show the priority of the current item.
  5442. This priority is composed of the main priority given with the [#A] cookies,
  5443. and by additional input from the age of a schedules or deadline entry."
  5444. (interactive)
  5445. (let* ((pri (org-get-at-bol 'priority)))
  5446. (message "Priority is %d" (if pri pri -1000))))
  5447. (defun org-agenda-show-tags ()
  5448. "Show the tags applicable to the current item."
  5449. (interactive)
  5450. (let* ((tags (org-get-at-bol 'tags)))
  5451. (if tags
  5452. (message "Tags are :%s:"
  5453. (org-no-properties (mapconcat 'identity tags ":")))
  5454. (message "No tags associated with this line"))))
  5455. (defun org-agenda-goto (&optional highlight)
  5456. "Go to the Org-mode file which contains the item at point."
  5457. (interactive)
  5458. (let* ((marker (or (org-get-at-bol 'org-marker)
  5459. (org-agenda-error)))
  5460. (buffer (marker-buffer marker))
  5461. (pos (marker-position marker)))
  5462. (switch-to-buffer-other-window buffer)
  5463. (widen)
  5464. (goto-char pos)
  5465. (when (org-mode-p)
  5466. (org-show-context 'agenda)
  5467. (save-excursion
  5468. (and (outline-next-heading)
  5469. (org-flag-heading nil)))) ; show the next heading
  5470. (recenter (/ (window-height) 2))
  5471. (run-hooks 'org-agenda-after-show-hook)
  5472. (and highlight (org-highlight (point-at-bol) (point-at-eol)))))
  5473. (defvar org-agenda-after-show-hook nil
  5474. "Normal hook run after an item has been shown from the agenda.
  5475. Point is in the buffer where the item originated.")
  5476. (defun org-agenda-kill ()
  5477. "Kill the entry or subtree belonging to the current agenda entry."
  5478. (interactive)
  5479. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5480. (let* ((marker (or (org-get-at-bol 'org-marker)
  5481. (org-agenda-error)))
  5482. (buffer (marker-buffer marker))
  5483. (pos (marker-position marker))
  5484. (type (org-get-at-bol 'type))
  5485. dbeg dend (n 0) conf)
  5486. (org-with-remote-undo buffer
  5487. (with-current-buffer buffer
  5488. (save-excursion
  5489. (goto-char pos)
  5490. (if (and (org-mode-p) (not (member type '("sexp"))))
  5491. (setq dbeg (progn (org-back-to-heading t) (point))
  5492. dend (org-end-of-subtree t t))
  5493. (setq dbeg (point-at-bol)
  5494. dend (min (point-max) (1+ (point-at-eol)))))
  5495. (goto-char dbeg)
  5496. (while (re-search-forward "^[ \t]*\\S-" dend t) (setq n (1+ n)))))
  5497. (setq conf (or (eq t org-agenda-confirm-kill)
  5498. (and (numberp org-agenda-confirm-kill)
  5499. (> n org-agenda-confirm-kill))))
  5500. (and conf
  5501. (not (y-or-n-p
  5502. (format "Delete entry with %d lines in buffer \"%s\"? "
  5503. n (buffer-name buffer))))
  5504. (error "Abort"))
  5505. (org-remove-subtree-entries-from-agenda buffer dbeg dend)
  5506. (with-current-buffer buffer (delete-region dbeg dend))
  5507. (message "Agenda item and source killed"))))
  5508. (defvar org-archive-default-command)
  5509. (defun org-agenda-archive-default ()
  5510. "Archive the entry or subtree belonging to the current agenda entry."
  5511. (interactive)
  5512. (require 'org-archive)
  5513. (org-agenda-archive-with org-archive-default-command))
  5514. (defun org-agenda-archive-default-with-confirmation ()
  5515. "Archive the entry or subtree belonging to the current agenda entry."
  5516. (interactive)
  5517. (require 'org-archive)
  5518. (org-agenda-archive-with org-archive-default-command 'confirm))
  5519. (defun org-agenda-archive ()
  5520. "Archive the entry or subtree belonging to the current agenda entry."
  5521. (interactive)
  5522. (org-agenda-archive-with 'org-archive-subtree))
  5523. (defun org-agenda-archive-to-archive-sibling ()
  5524. "Move the entry to the archive sibling."
  5525. (interactive)
  5526. (org-agenda-archive-with 'org-archive-to-archive-sibling))
  5527. (defun org-agenda-archive-with (cmd &optional confirm)
  5528. "Move the entry to the archive sibling."
  5529. (interactive)
  5530. (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  5531. (let* ((marker (or (org-get-at-bol 'org-marker)
  5532. (org-agenda-error)))
  5533. (buffer (marker-buffer marker))
  5534. (pos (marker-position marker)))
  5535. (org-with-remote-undo buffer
  5536. (with-current-buffer buffer
  5537. (if (org-mode-p)
  5538. (if (and confirm
  5539. (not (y-or-n-p "Archive this subtree or entry? ")))
  5540. (error "Abort")
  5541. (save-excursion
  5542. (goto-char pos)
  5543. (org-remove-subtree-entries-from-agenda)
  5544. (org-back-to-heading t)
  5545. (funcall cmd)))
  5546. (error "Archiving works only in Org-mode files"))))))
  5547. (defun org-remove-subtree-entries-from-agenda (&optional buf beg end)
  5548. "Remove all lines in the agenda that correspond to a given subtree.
  5549. The subtree is the one in buffer BUF, starting at BEG and ending at END.
  5550. If this information is not given, the function uses the tree at point."
  5551. (let ((buf (or buf (current-buffer))) m p)
  5552. (save-excursion
  5553. (unless (and beg end)
  5554. (org-back-to-heading t)
  5555. (setq beg (point))
  5556. (org-end-of-subtree t)
  5557. (setq end (point)))
  5558. (set-buffer (get-buffer org-agenda-buffer-name))
  5559. (save-excursion
  5560. (goto-char (point-max))
  5561. (beginning-of-line 1)
  5562. (while (not (bobp))
  5563. (when (and (setq m (org-get-at-bol 'org-marker))
  5564. (equal buf (marker-buffer m))
  5565. (setq p (marker-position m))
  5566. (>= p beg)
  5567. (< p end))
  5568. (let ((inhibit-read-only t))
  5569. (delete-region (point-at-bol) (1+ (point-at-eol)))))
  5570. (beginning-of-line 0))))))
  5571. (defun org-agenda-refile (&optional goto rfloc)
  5572. "Refile the item at point."
  5573. (interactive "P")
  5574. (if (equal goto '(16))
  5575. (org-refile-goto-last-stored)
  5576. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5577. (org-agenda-error)))
  5578. (buffer (marker-buffer marker))
  5579. (pos (marker-position marker))
  5580. (rfloc (or rfloc
  5581. (org-refile-get-location
  5582. (if goto "Goto: " "Refile to: ") buffer
  5583. org-refile-allow-creating-parent-nodes))))
  5584. (with-current-buffer buffer
  5585. (save-excursion
  5586. (save-restriction
  5587. (widen)
  5588. (goto-char marker)
  5589. (org-remove-subtree-entries-from-agenda)
  5590. (org-refile goto buffer rfloc)))))))
  5591. (defun org-agenda-open-link (&optional arg)
  5592. "Follow the link in the current line, if any.
  5593. This looks for a link in the displayed line in the agenda. It also looks
  5594. at the text of the entry itself."
  5595. (interactive "P")
  5596. (let* ((marker (or (org-get-at-bol 'org-hd-marker)
  5597. (org-get-at-bol 'org-marker)))
  5598. (buffer (and marker (marker-buffer marker)))
  5599. (prefix (buffer-substring
  5600. (point-at-bol)
  5601. (+ (point-at-bol)
  5602. (or (org-get-at-bol 'prefix-length) 0)))))
  5603. (cond
  5604. (buffer
  5605. (with-current-buffer buffer
  5606. (save-excursion
  5607. (save-restriction
  5608. (widen)
  5609. (goto-char marker)
  5610. (org-offer-links-in-entry arg prefix)))))
  5611. ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
  5612. (save-excursion
  5613. (beginning-of-line 1)
  5614. (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
  5615. (org-open-link-from-string (match-string 1)))
  5616. (t (error "No link to open here")))))
  5617. (defun org-agenda-copy-local-variable (var)
  5618. "Get a variable from a referenced buffer and install it here."
  5619. (let ((m (org-get-at-bol 'org-marker)))
  5620. (when (and m (buffer-live-p (marker-buffer m)))
  5621. (org-set-local var (with-current-buffer (marker-buffer m)
  5622. (symbol-value var))))))
  5623. (defun org-agenda-switch-to (&optional delete-other-windows)
  5624. "Go to the Org-mode file which contains the item at point."
  5625. (interactive)
  5626. (if (and org-return-follows-link
  5627. (not (org-get-at-bol 'org-marker))
  5628. (org-in-regexp org-bracket-link-regexp))
  5629. (org-open-link-from-string (match-string 0))
  5630. (let* ((marker (or (org-get-at-bol 'org-marker)
  5631. (org-agenda-error)))
  5632. (buffer (marker-buffer marker))
  5633. (pos (marker-position marker)))
  5634. (switch-to-buffer buffer)
  5635. (and delete-other-windows (delete-other-windows))
  5636. (widen)
  5637. (goto-char pos)
  5638. (when (org-mode-p)
  5639. (org-show-context 'agenda)
  5640. (save-excursion
  5641. (and (outline-next-heading)
  5642. (org-flag-heading nil))))))) ; show the next heading
  5643. (defun org-agenda-goto-mouse (ev)
  5644. "Go to the Org-mode file which contains the item at the mouse click."
  5645. (interactive "e")
  5646. (mouse-set-point ev)
  5647. (org-agenda-goto))
  5648. (defun org-agenda-show (&optional full-entry)
  5649. "Display the Org-mode file which contains the item at point.
  5650. With prefix argument FULL-ENTRY, make the entire entry visible
  5651. if it was hidden in the outline."
  5652. (interactive "P")
  5653. (let ((win (selected-window)))
  5654. (if full-entry
  5655. (let ((org-show-entry-below t))
  5656. (org-agenda-goto t))
  5657. (org-agenda-goto t))
  5658. (select-window win)))
  5659. (defvar org-agenda-show-window nil)
  5660. (defun org-agenda-show-and-scroll-up ()
  5661. "Display the Org-mode file which contains the item at point.
  5662. When called repeatedly, scroll the window that is displaying the buffer."
  5663. (interactive)
  5664. (let ((win (selected-window)))
  5665. (if (and (window-live-p org-agenda-show-window)
  5666. (eq this-command last-command))
  5667. (progn
  5668. (select-window org-agenda-show-window)
  5669. (ignore-errors (scroll-up)))
  5670. (org-agenda-goto t)
  5671. (show-subtree)
  5672. (setq org-agenda-show-window (selected-window)))
  5673. (select-window win)))
  5674. (defun org-agenda-show-scroll-down ()
  5675. "Scroll down the window showing the agenda."
  5676. (interactive)
  5677. (let ((win (selected-window)))
  5678. (when (window-live-p org-agenda-show-window)
  5679. (select-window org-agenda-show-window)
  5680. (ignore-errors (scroll-down))
  5681. (select-window win))))
  5682. (defun org-agenda-show-1 (&optional more)
  5683. "Display the Org-mode file which contains the item at point.
  5684. The prefix arg selects the amount of information to display:
  5685. 0 hide the subtree
  5686. 1 just show the entry according to defaults.
  5687. 2 show the children view
  5688. 3 show the subtree view
  5689. 4 show the entire subtree and any LOGBOOK drawers
  5690. 5 show the entire subtree and any drawers
  5691. With prefix argument FULL-ENTRY, make the entire entry visible
  5692. if it was hidden in the outline."
  5693. (interactive "p")
  5694. (let ((win (selected-window)))
  5695. (org-agenda-goto t)
  5696. (org-recenter-heading 1)
  5697. (cond
  5698. ((= more 0)
  5699. (hide-subtree)
  5700. (save-excursion
  5701. (org-back-to-heading)
  5702. (run-hook-with-args 'org-cycle-hook 'folded))
  5703. (message "Remote: FOLDED"))
  5704. ((and (interactive-p) (= more 1))
  5705. (message "Remote: show with default settings"))
  5706. ((= more 2)
  5707. (show-entry)
  5708. (show-children)
  5709. (save-excursion
  5710. (org-back-to-heading)
  5711. (run-hook-with-args 'org-cycle-hook 'children))
  5712. (message "Remote: CHILDREN"))
  5713. ((= more 3)
  5714. (show-subtree)
  5715. (save-excursion
  5716. (org-back-to-heading)
  5717. (run-hook-with-args 'org-cycle-hook 'subtree))
  5718. (message "Remote: SUBTREE"))
  5719. ((= more 4)
  5720. (let* ((org-drawers (delete "LOGBOOK" (copy-sequence org-drawers)))
  5721. (org-drawer-regexp
  5722. (concat "^[ \t]*:\\("
  5723. (mapconcat 'regexp-quote org-drawers "\\|")
  5724. "\\):[ \t]*$")))
  5725. (show-subtree)
  5726. (save-excursion
  5727. (org-back-to-heading)
  5728. (org-cycle-hide-drawers 'subtree)))
  5729. (message "Remote: SUBTREE AND LOGBOOK"))
  5730. ((> more 4)
  5731. (show-subtree)
  5732. (message "Remote: SUBTREE AND ALL DRAWERS")))
  5733. (select-window win)))
  5734. (defun org-recenter-heading (n)
  5735. (save-excursion
  5736. (org-back-to-heading)
  5737. (recenter n)))
  5738. (defvar org-agenda-cycle-counter nil)
  5739. (defun org-agenda-cycle-show (&optional n)
  5740. "Show the current entry in another window, with default settings.
  5741. Default settings are taken from `org-show-hierarchy-above' and siblings.
  5742. When use repeatedly in immediate succession, the remote entry will cycle
  5743. through visibility
  5744. children -> subtree -> folded
  5745. When called with a numeric prefix arg, that arg will be passed through to
  5746. `org-agenda-show-1'. For the interpretation of that argument, see the
  5747. docstring of `org-agenda-show-1'."
  5748. (interactive "P")
  5749. (if (integerp n)
  5750. (setq org-agenda-cycle-counter n)
  5751. (if (not (eq last-command this-command))
  5752. (setq org-agenda-cycle-counter 1)
  5753. (if (equal org-agenda-cycle-counter 0)
  5754. (setq org-agenda-cycle-counter 2)
  5755. (setq org-agenda-cycle-counter (1+ org-agenda-cycle-counter))
  5756. (if (> org-agenda-cycle-counter 3)
  5757. (setq org-agenda-cycle-counter 0)))))
  5758. (org-agenda-show-1 org-agenda-cycle-counter))
  5759. (defun org-agenda-recenter (arg)
  5760. "Display the Org-mode file which contains the item at point and recenter."
  5761. (interactive "P")
  5762. (let ((win (selected-window)))
  5763. (org-agenda-goto t)
  5764. (recenter arg)
  5765. (select-window win)))
  5766. (defun org-agenda-show-mouse (ev)
  5767. "Display the Org-mode file which contains the item at the mouse click."
  5768. (interactive "e")
  5769. (mouse-set-point ev)
  5770. (org-agenda-show))
  5771. (defun org-agenda-check-no-diary ()
  5772. "Check if the entry is a diary link and abort if yes."
  5773. (if (org-get-at-bol 'org-agenda-diary-link)
  5774. (org-agenda-error)))
  5775. (defun org-agenda-error ()
  5776. (error "Command not allowed in this line"))
  5777. (defun org-agenda-tree-to-indirect-buffer ()
  5778. "Show the subtree corresponding to the current entry in an indirect buffer.
  5779. This calls the command `org-tree-to-indirect-buffer' from the original
  5780. Org-mode buffer.
  5781. With numerical prefix arg ARG, go up to this level and then take that tree.
  5782. With a C-u prefix, make a separate frame for this tree (i.e. don't use the
  5783. dedicated frame)."
  5784. (interactive)
  5785. (org-agenda-check-no-diary)
  5786. (let* ((marker (or (org-get-at-bol 'org-marker)
  5787. (org-agenda-error)))
  5788. (buffer (marker-buffer marker))
  5789. (pos (marker-position marker)))
  5790. (with-current-buffer buffer
  5791. (save-excursion
  5792. (goto-char pos)
  5793. (call-interactively 'org-tree-to-indirect-buffer)))))
  5794. (defvar org-last-heading-marker (make-marker)
  5795. "Marker pointing to the headline that last changed its TODO state
  5796. by a remote command from the agenda.")
  5797. (defun org-agenda-todo-nextset ()
  5798. "Switch TODO entry to next sequence."
  5799. (interactive)
  5800. (org-agenda-todo 'nextset))
  5801. (defun org-agenda-todo-previousset ()
  5802. "Switch TODO entry to previous sequence."
  5803. (interactive)
  5804. (org-agenda-todo 'previousset))
  5805. (defun org-agenda-todo (&optional arg)
  5806. "Cycle TODO state of line at point, also in Org-mode file.
  5807. This changes the line at point, all other lines in the agenda referring to
  5808. the same tree node, and the headline of the tree node in the Org-mode file."
  5809. (interactive "P")
  5810. (org-agenda-check-no-diary)
  5811. (let* ((col (current-column))
  5812. (marker (or (org-get-at-bol 'org-marker)
  5813. (org-agenda-error)))
  5814. (buffer (marker-buffer marker))
  5815. (pos (marker-position marker))
  5816. (hdmarker (org-get-at-bol 'org-hd-marker))
  5817. (todayp (equal (org-get-at-bol 'day)
  5818. (time-to-days (current-time))))
  5819. (inhibit-read-only t)
  5820. org-agenda-headline-snapshot-before-repeat newhead just-one)
  5821. (org-with-remote-undo buffer
  5822. (with-current-buffer buffer
  5823. (widen)
  5824. (goto-char pos)
  5825. (org-show-context 'agenda)
  5826. (save-excursion
  5827. (and (outline-next-heading)
  5828. (org-flag-heading nil))) ; show the next heading
  5829. (let ((current-prefix-arg arg))
  5830. (call-interactively 'org-todo))
  5831. (and (bolp) (forward-char 1))
  5832. (setq newhead (org-get-heading))
  5833. (when (and (org-bound-and-true-p
  5834. org-agenda-headline-snapshot-before-repeat)
  5835. (not (equal org-agenda-headline-snapshot-before-repeat
  5836. newhead))
  5837. todayp)
  5838. (setq newhead org-agenda-headline-snapshot-before-repeat
  5839. just-one t))
  5840. (save-excursion
  5841. (org-back-to-heading)
  5842. (move-marker org-last-heading-marker (point))))
  5843. (beginning-of-line 1)
  5844. (save-excursion
  5845. (org-agenda-change-all-lines newhead hdmarker 'fixface just-one))
  5846. (org-move-to-column col))))
  5847. (defun org-agenda-add-note (&optional arg)
  5848. "Add a time-stamped note to the entry at point."
  5849. (interactive "P")
  5850. (org-agenda-check-no-diary)
  5851. (let* ((marker (or (org-get-at-bol 'org-marker)
  5852. (org-agenda-error)))
  5853. (buffer (marker-buffer marker))
  5854. (pos (marker-position marker))
  5855. (hdmarker (org-get-at-bol 'org-hd-marker))
  5856. (inhibit-read-only t))
  5857. (with-current-buffer buffer
  5858. (widen)
  5859. (goto-char pos)
  5860. (org-show-context 'agenda)
  5861. (save-excursion
  5862. (and (outline-next-heading)
  5863. (org-flag-heading nil))) ; show the next heading
  5864. (org-add-note))))
  5865. (defun org-agenda-change-all-lines (newhead hdmarker
  5866. &optional fixface just-this)
  5867. "Change all lines in the agenda buffer which match HDMARKER.
  5868. The new content of the line will be NEWHEAD (as modified by
  5869. `org-format-agenda-item'). HDMARKER is checked with
  5870. `equal' against all `org-hd-marker' text properties in the file.
  5871. If FIXFACE is non-nil, the face of each item is modified according to
  5872. the new TODO state.
  5873. If JUST-THIS is non-nil, change just the current line, not all.
  5874. If FORCE-TAGS is non nil, the car of it returns the new tags."
  5875. (let* ((inhibit-read-only t)
  5876. (line (org-current-line))
  5877. (thetags (with-current-buffer (marker-buffer hdmarker)
  5878. (save-excursion (save-restriction (widen)
  5879. (goto-char hdmarker)
  5880. (org-get-tags-at)))))
  5881. props m pl undone-face done-face finish new dotime cat tags)
  5882. (save-excursion
  5883. (goto-char (point-max))
  5884. (beginning-of-line 1)
  5885. (while (not finish)
  5886. (setq finish (bobp))
  5887. (when (and (setq m (org-get-at-bol 'org-hd-marker))
  5888. (or (not just-this) (= (org-current-line) line))
  5889. (equal m hdmarker))
  5890. (setq props (text-properties-at (point))
  5891. dotime (org-get-at-bol 'dotime)
  5892. cat (org-get-at-bol 'org-category)
  5893. tags thetags
  5894. new (org-format-agenda-item "x" newhead cat tags dotime 'noprefix)
  5895. pl (org-get-at-bol 'prefix-length)
  5896. undone-face (org-get-at-bol 'undone-face)
  5897. done-face (org-get-at-bol 'done-face))
  5898. (goto-char (+ (point) pl))
  5899. ;; (org-move-to-column pl) FIXME: does the above line work correctly?
  5900. (cond
  5901. ((equal new "")
  5902. (beginning-of-line 1)
  5903. (and (looking-at ".*\n?") (replace-match "")))
  5904. ((looking-at ".*")
  5905. (replace-match new t t)
  5906. (beginning-of-line 1)
  5907. (add-text-properties (point-at-bol) (point-at-eol) props)
  5908. (when fixface
  5909. (add-text-properties
  5910. (point-at-bol) (point-at-eol)
  5911. (list 'face
  5912. (if org-last-todo-state-is-todo
  5913. undone-face done-face))))
  5914. (org-agenda-highlight-todo 'line)
  5915. (beginning-of-line 1))
  5916. (t (error "Line update did not work"))))
  5917. (beginning-of-line 0)))
  5918. (org-finalize-agenda)))
  5919. (defun org-agenda-align-tags (&optional line)
  5920. "Align all tags in agenda items to `org-agenda-tags-column'."
  5921. (let ((inhibit-read-only t) l c)
  5922. (save-excursion
  5923. (goto-char (if line (point-at-bol) (point-min)))
  5924. (while (re-search-forward (org-re "\\([ \t]+\\)\\(:[[:alnum:]_@:]+:\\)[ \t]*$")
  5925. (if line (point-at-eol) nil) t)
  5926. (add-text-properties
  5927. (match-beginning 2) (match-end 2)
  5928. (list 'face (delq nil (let ((prop (get-text-property
  5929. (match-beginning 2) 'face)))
  5930. (or (listp prop) (setq prop (list prop)))
  5931. (if (memq 'org-tag prop)
  5932. prop
  5933. (cons 'org-tag prop))))))
  5934. (setq l (- (match-end 2) (match-beginning 2))
  5935. c (if (< org-agenda-tags-column 0)
  5936. (- (abs org-agenda-tags-column) l)
  5937. org-agenda-tags-column))
  5938. (delete-region (match-beginning 1) (match-end 1))
  5939. (goto-char (match-beginning 1))
  5940. (insert (org-add-props
  5941. (make-string (max 1 (- c (current-column))) ?\ )
  5942. (text-properties-at (point)))))
  5943. (goto-char (point-min))
  5944. (org-font-lock-add-tag-faces (point-max)))))
  5945. (defun org-agenda-priority-up ()
  5946. "Increase the priority of line at point, also in Org-mode file."
  5947. (interactive)
  5948. (org-agenda-priority 'up))
  5949. (defun org-agenda-priority-down ()
  5950. "Decrease the priority of line at point, also in Org-mode file."
  5951. (interactive)
  5952. (org-agenda-priority 'down))
  5953. (defun org-agenda-priority (&optional force-direction)
  5954. "Set the priority of line at point, also in Org-mode file.
  5955. This changes the line at point, all other lines in the agenda referring to
  5956. the same tree node, and the headline of the tree node in the Org-mode file."
  5957. (interactive)
  5958. (unless org-enable-priority-commands
  5959. (error "Priority commands are disabled"))
  5960. (org-agenda-check-no-diary)
  5961. (let* ((marker (or (org-get-at-bol 'org-marker)
  5962. (org-agenda-error)))
  5963. (hdmarker (org-get-at-bol 'org-hd-marker))
  5964. (buffer (marker-buffer hdmarker))
  5965. (pos (marker-position hdmarker))
  5966. (inhibit-read-only t)
  5967. newhead)
  5968. (org-with-remote-undo buffer
  5969. (with-current-buffer buffer
  5970. (widen)
  5971. (goto-char pos)
  5972. (org-show-context 'agenda)
  5973. (save-excursion
  5974. (and (outline-next-heading)
  5975. (org-flag-heading nil))) ; show the next heading
  5976. (funcall 'org-priority force-direction)
  5977. (end-of-line 1)
  5978. (setq newhead (org-get-heading)))
  5979. (org-agenda-change-all-lines newhead hdmarker)
  5980. (beginning-of-line 1))))
  5981. ;; FIXME: should fix the tags property of the agenda line.
  5982. (defun org-agenda-set-tags (&optional tag onoff)
  5983. "Set tags for the current headline."
  5984. (interactive)
  5985. (org-agenda-check-no-diary)
  5986. (if (and (org-region-active-p) (interactive-p))
  5987. (call-interactively 'org-change-tag-in-region)
  5988. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  5989. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  5990. (org-agenda-error)))
  5991. (buffer (marker-buffer hdmarker))
  5992. (pos (marker-position hdmarker))
  5993. (inhibit-read-only t)
  5994. newhead)
  5995. (org-with-remote-undo buffer
  5996. (with-current-buffer buffer
  5997. (widen)
  5998. (goto-char pos)
  5999. (save-excursion
  6000. (org-show-context 'agenda))
  6001. (save-excursion
  6002. (and (outline-next-heading)
  6003. (org-flag-heading nil))) ; show the next heading
  6004. (goto-char pos)
  6005. (if tag
  6006. (org-toggle-tag tag onoff)
  6007. (call-interactively 'org-set-tags))
  6008. (end-of-line 1)
  6009. (setq newhead (org-get-heading)))
  6010. (org-agenda-change-all-lines newhead hdmarker)
  6011. (beginning-of-line 1)))))
  6012. (defun org-agenda-set-property ()
  6013. "Set a property for the current headline."
  6014. (interactive)
  6015. (org-agenda-check-no-diary)
  6016. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6017. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6018. (org-agenda-error)))
  6019. (buffer (marker-buffer hdmarker))
  6020. (pos (marker-position hdmarker))
  6021. (inhibit-read-only t)
  6022. newhead)
  6023. (org-with-remote-undo buffer
  6024. (with-current-buffer buffer
  6025. (widen)
  6026. (goto-char pos)
  6027. (save-excursion
  6028. (org-show-context 'agenda))
  6029. (save-excursion
  6030. (and (outline-next-heading)
  6031. (org-flag-heading nil))) ; show the next heading
  6032. (goto-char pos)
  6033. (call-interactively 'org-set-property)))))
  6034. (defun org-agenda-set-effort ()
  6035. "Set the effort property for the current headline."
  6036. (interactive)
  6037. (org-agenda-check-no-diary)
  6038. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6039. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6040. (org-agenda-error)))
  6041. (buffer (marker-buffer hdmarker))
  6042. (pos (marker-position hdmarker))
  6043. (inhibit-read-only t)
  6044. newhead)
  6045. (org-with-remote-undo buffer
  6046. (with-current-buffer buffer
  6047. (widen)
  6048. (goto-char pos)
  6049. (save-excursion
  6050. (org-show-context 'agenda))
  6051. (save-excursion
  6052. (and (outline-next-heading)
  6053. (org-flag-heading nil))) ; show the next heading
  6054. (goto-char pos)
  6055. (call-interactively 'org-set-effort)
  6056. (end-of-line 1)))))
  6057. (defun org-agenda-toggle-archive-tag ()
  6058. "Toggle the archive tag for the current entry."
  6059. (interactive)
  6060. (org-agenda-check-no-diary)
  6061. (org-agenda-show) ;;; FIXME This is a stupid hack and should not be needed
  6062. (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
  6063. (org-agenda-error)))
  6064. (buffer (marker-buffer hdmarker))
  6065. (pos (marker-position hdmarker))
  6066. (inhibit-read-only t)
  6067. newhead)
  6068. (org-with-remote-undo buffer
  6069. (with-current-buffer buffer
  6070. (widen)
  6071. (goto-char pos)
  6072. (org-show-context 'agenda)
  6073. (save-excursion
  6074. (and (outline-next-heading)
  6075. (org-flag-heading nil))) ; show the next heading
  6076. (call-interactively 'org-toggle-archive-tag)
  6077. (end-of-line 1)
  6078. (setq newhead (org-get-heading)))
  6079. (org-agenda-change-all-lines newhead hdmarker)
  6080. (beginning-of-line 1))))
  6081. (defun org-agenda-do-date-later (arg)
  6082. (interactive "P")
  6083. (cond
  6084. ((or (equal arg '(16))
  6085. (memq last-command
  6086. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6087. (setq this-command 'org-agenda-date-later-minutes)
  6088. (org-agenda-date-later-minutes 1))
  6089. ((or (equal arg '(4))
  6090. (memq last-command
  6091. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6092. (setq this-command 'org-agenda-date-later-hours)
  6093. (org-agenda-date-later-hours 1))
  6094. (t
  6095. (org-agenda-date-later (prefix-numeric-value arg)))))
  6096. (defun org-agenda-do-date-earlier (arg)
  6097. (interactive "P")
  6098. (cond
  6099. ((or (equal arg '(16))
  6100. (memq last-command
  6101. '(org-agenda-date-later-minutes org-agenda-date-earlier-minutes)))
  6102. (setq this-command 'org-agenda-date-earlier-minutes)
  6103. (org-agenda-date-earlier-minutes 1))
  6104. ((or (equal arg '(4))
  6105. (memq last-command
  6106. '(org-agenda-date-later-hours org-agenda-date-earlier-hours)))
  6107. (setq this-command 'org-agenda-date-earlier-hours)
  6108. (org-agenda-date-earlier-hours 1))
  6109. (t
  6110. (org-agenda-date-earlier (prefix-numeric-value arg)))))
  6111. (defun org-agenda-date-later (arg &optional what)
  6112. "Change the date of this item to one day later."
  6113. (interactive "p")
  6114. (org-agenda-check-type t 'agenda 'timeline)
  6115. (org-agenda-check-no-diary)
  6116. (let* ((marker (or (org-get-at-bol 'org-marker)
  6117. (org-agenda-error)))
  6118. (buffer (marker-buffer marker))
  6119. (pos (marker-position marker)))
  6120. (org-with-remote-undo buffer
  6121. (with-current-buffer buffer
  6122. (widen)
  6123. (goto-char pos)
  6124. (if (not (org-at-timestamp-p))
  6125. (error "Cannot find time stamp"))
  6126. (org-timestamp-change arg (or what 'day)))
  6127. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6128. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6129. (defun org-agenda-date-earlier (arg &optional what)
  6130. "Change the date of this item to one day earlier."
  6131. (interactive "p")
  6132. (org-agenda-date-later (- arg) what))
  6133. (defun org-agenda-date-later-minutes (arg)
  6134. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6135. (interactive "p")
  6136. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6137. (org-agenda-date-later arg 'minute))
  6138. (defun org-agenda-date-earlier-minutes (arg)
  6139. "Change the time of this item, in units of `org-time-stamp-rounding-minutes'."
  6140. (interactive "p")
  6141. (setq arg (* arg (cadr org-time-stamp-rounding-minutes)))
  6142. (org-agenda-date-earlier arg 'minute))
  6143. (defun org-agenda-date-later-hours (arg)
  6144. "Change the time of this item, in hour steps."
  6145. (interactive "p")
  6146. (org-agenda-date-later arg 'hour))
  6147. (defun org-agenda-date-earlier-hours (arg)
  6148. "Change the time of this item, in hour steps."
  6149. (interactive "p")
  6150. (org-agenda-date-earlier arg 'hour))
  6151. (defun org-agenda-show-new-time (marker stamp &optional prefix)
  6152. "Show new date stamp via text properties."
  6153. ;; We use text properties to make this undoable
  6154. (let ((inhibit-read-only t)
  6155. (buffer-invisibility-spec))
  6156. (setq stamp (concat " " prefix " => " stamp))
  6157. (save-excursion
  6158. (goto-char (point-max))
  6159. (while (not (bobp))
  6160. (when (equal marker (org-get-at-bol 'org-marker))
  6161. (org-move-to-column (- (window-width) (length stamp)) t)
  6162. (org-agenda-fix-tags-filter-overlays-at (point))
  6163. (if (featurep 'xemacs)
  6164. ;; Use `duplicable' property to trigger undo recording
  6165. (let ((ex (make-extent nil nil))
  6166. (gl (make-glyph stamp)))
  6167. (set-glyph-face gl 'secondary-selection)
  6168. (set-extent-properties
  6169. ex (list 'invisible t 'end-glyph gl 'duplicable t))
  6170. (insert-extent ex (1- (point)) (point-at-eol)))
  6171. (add-text-properties
  6172. (1- (point)) (point-at-eol)
  6173. (list 'display (org-add-props stamp nil
  6174. 'face 'secondary-selection))))
  6175. (beginning-of-line 1))
  6176. (beginning-of-line 0)))))
  6177. (defun org-agenda-date-prompt (arg)
  6178. "Change the date of this item. Date is prompted for, with default today.
  6179. The prefix ARG is passed to the `org-time-stamp' command and can therefore
  6180. be used to request time specification in the time stamp."
  6181. (interactive "P")
  6182. (org-agenda-check-type t 'agenda 'timeline)
  6183. (org-agenda-check-no-diary)
  6184. (let* ((marker (or (org-get-at-bol 'org-marker)
  6185. (org-agenda-error)))
  6186. (buffer (marker-buffer marker))
  6187. (pos (marker-position marker)))
  6188. (org-with-remote-undo buffer
  6189. (with-current-buffer buffer
  6190. (widen)
  6191. (goto-char pos)
  6192. (if (not (org-at-timestamp-p t))
  6193. (error "Cannot find time stamp"))
  6194. (org-time-stamp arg (equal (char-after (match-beginning 0)) ?\[)))
  6195. (org-agenda-show-new-time marker org-last-changed-timestamp))
  6196. (message "Time stamp changed to %s" org-last-changed-timestamp)))
  6197. (defun org-agenda-schedule (arg)
  6198. "Schedule the item at point.
  6199. Arg is passed through to `org-schedule'."
  6200. (interactive "P")
  6201. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6202. (org-agenda-check-no-diary)
  6203. (let* ((marker (or (org-get-at-bol 'org-marker)
  6204. (org-agenda-error)))
  6205. (type (marker-insertion-type marker))
  6206. (buffer (marker-buffer marker))
  6207. (pos (marker-position marker))
  6208. (org-insert-labeled-timestamps-at-point nil)
  6209. ts)
  6210. (set-marker-insertion-type marker t)
  6211. (org-with-remote-undo buffer
  6212. (with-current-buffer buffer
  6213. (widen)
  6214. (goto-char pos)
  6215. (setq ts (org-schedule arg)))
  6216. (org-agenda-show-new-time marker ts "S"))
  6217. (message "Item scheduled for %s" ts)))
  6218. (defun org-agenda-deadline (arg)
  6219. "Schedule the item at point.
  6220. Arg is passed through to `org-deadline'."
  6221. (interactive "P")
  6222. (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
  6223. (org-agenda-check-no-diary)
  6224. (let* ((marker (or (org-get-at-bol 'org-marker)
  6225. (org-agenda-error)))
  6226. (buffer (marker-buffer marker))
  6227. (pos (marker-position marker))
  6228. (org-insert-labeled-timestamps-at-point nil)
  6229. ts)
  6230. (org-with-remote-undo buffer
  6231. (with-current-buffer buffer
  6232. (widen)
  6233. (goto-char pos)
  6234. (setq ts (org-deadline arg)))
  6235. (org-agenda-show-new-time marker ts "D"))
  6236. (message "Deadline for this item set to %s" ts)))
  6237. (defun org-agenda-action ()
  6238. "Select entry for agenda action, or execute an agenda action.
  6239. This command prompts for another letter. Valid inputs are:
  6240. m Mark the entry at point for an agenda action
  6241. s Schedule the marked entry to the date at the cursor
  6242. d Set the deadline of the marked entry to the date at the cursor
  6243. r Call `org-remember' with cursor date as the default date
  6244. SPC Show marked entry in other window
  6245. TAB Visit marked entry in other window
  6246. The cursor may be at a date in the calendar, or in the Org agenda."
  6247. (interactive)
  6248. (let (ans)
  6249. (message "Select action: [m]ark | [s]chedule [d]eadline [r]emember [ ]show")
  6250. (setq ans (read-char-exclusive))
  6251. (cond
  6252. ((equal ans ?m)
  6253. ;; Mark this entry
  6254. (if (eq major-mode 'org-agenda-mode)
  6255. (let ((m (or (org-get-at-bol 'org-hd-marker)
  6256. (org-get-at-bol 'org-marker))))
  6257. (if m
  6258. (progn
  6259. (move-marker org-agenda-action-marker
  6260. (marker-position m) (marker-buffer m))
  6261. (message "Entry marked for action; press `k' at desired date in agenda or calendar"))
  6262. (error "Don't know which entry to mark")))
  6263. (error "This command works only in the agenda")))
  6264. ((equal ans ?s)
  6265. (org-agenda-do-action '(org-schedule nil org-overriding-default-time)))
  6266. ((equal ans ?d)
  6267. (org-agenda-do-action '(org-deadline nil org-overriding-default-time)))
  6268. ((equal ans ?r)
  6269. (org-agenda-do-action '(org-remember) t))
  6270. ((equal ans ?\ )
  6271. (let ((cw (selected-window)))
  6272. (org-switch-to-buffer-other-window
  6273. (marker-buffer org-agenda-action-marker))
  6274. (goto-char org-agenda-action-marker)
  6275. (org-show-context 'agenda)
  6276. (select-window cw)))
  6277. ((equal ans ?\C-i)
  6278. (org-switch-to-buffer-other-window
  6279. (marker-buffer org-agenda-action-marker))
  6280. (goto-char org-agenda-action-marker)
  6281. (org-show-context 'agenda))
  6282. (t (error "Invalid agenda action %c" ans)))))
  6283. (defun org-agenda-do-action (form &optional current-buffer)
  6284. "Evaluate FORM at the entry pointed to by `org-agenda-action-marker'."
  6285. (let ((org-overriding-default-time (org-get-cursor-date)))
  6286. (if current-buffer
  6287. (eval form)
  6288. (if (not (marker-buffer org-agenda-action-marker))
  6289. (error "No entry has been selected for agenda action")
  6290. (with-current-buffer (marker-buffer org-agenda-action-marker)
  6291. (save-excursion
  6292. (save-restriction
  6293. (widen)
  6294. (goto-char org-agenda-action-marker)
  6295. (eval form))))))))
  6296. (defun org-agenda-clock-in (&optional arg)
  6297. "Start the clock on the currently selected item."
  6298. (interactive "P")
  6299. (org-agenda-check-no-diary)
  6300. (if (equal arg '(4))
  6301. (org-clock-in arg)
  6302. (let* ((marker (or (org-get-at-bol 'org-marker)
  6303. (org-agenda-error)))
  6304. (hdmarker (or (org-get-at-bol 'org-hd-marker)
  6305. marker))
  6306. (pos (marker-position marker))
  6307. newhead)
  6308. (org-with-remote-undo (marker-buffer marker)
  6309. (with-current-buffer (marker-buffer marker)
  6310. (widen)
  6311. (goto-char pos)
  6312. (org-show-context 'agenda)
  6313. (org-show-entry)
  6314. (org-cycle-hide-drawers 'children)
  6315. (org-clock-in arg)
  6316. (setq newhead (org-get-heading)))
  6317. (org-agenda-change-all-lines newhead hdmarker)))))
  6318. (defun org-agenda-clock-out (&optional arg)
  6319. "Stop the currently running clock."
  6320. (interactive "P")
  6321. (unless (marker-buffer org-clock-marker)
  6322. (error "No running clock"))
  6323. (let ((marker (make-marker)) newhead)
  6324. (org-with-remote-undo (marker-buffer org-clock-marker)
  6325. (with-current-buffer (marker-buffer org-clock-marker)
  6326. (save-excursion
  6327. (save-restriction
  6328. (widen)
  6329. (goto-char org-clock-marker)
  6330. (org-back-to-heading t)
  6331. (move-marker marker (point))
  6332. (org-clock-out)
  6333. (setq newhead (org-get-heading))))))
  6334. (org-agenda-change-all-lines newhead marker)
  6335. (move-marker marker nil)))
  6336. (defun org-agenda-clock-cancel (&optional arg)
  6337. "Cancel the currently running clock."
  6338. (interactive "P")
  6339. (unless (marker-buffer org-clock-marker)
  6340. (error "No running clock"))
  6341. (org-with-remote-undo (marker-buffer org-clock-marker)
  6342. (org-clock-cancel)))
  6343. (defun org-agenda-diary-entry-in-org-file ()
  6344. "Make a diary entry in the file `org-agenda-diary-file'."
  6345. (let (d1 d2 char (text "") dp1 dp2)
  6346. (if (equal (buffer-name) "*Calendar*")
  6347. (setq d1 (calendar-cursor-to-date t)
  6348. d2 (car calendar-mark-ring))
  6349. (setq dp1 (get-text-property (point-at-bol) 'day))
  6350. (unless dp1 (error "No date defined in current line"))
  6351. (setq d1 (calendar-gregorian-from-absolute dp1)
  6352. d2 (and (ignore-errors (mark))
  6353. (save-excursion
  6354. (goto-char (mark))
  6355. (setq dp2 (get-text-property (point-at-bol) 'day)))
  6356. (calendar-gregorian-from-absolute dp2))))
  6357. (message "Diary entry: [d]ay [a]nniversary [b]lock [j]ump to date tree")
  6358. (setq char (read-char-exclusive))
  6359. (cond
  6360. ((equal char ?d)
  6361. (setq text (read-string "Day entry: "))
  6362. (org-agenda-add-entry-to-org-agenda-diary-file 'day text d1)
  6363. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6364. ((equal char ?a)
  6365. (setq d1 (list (car d1) (nth 1 d1)
  6366. (read-number (format "Reference year [%d]: " (nth 2 d1))
  6367. (nth 2 d1))))
  6368. (setq text (read-string "Anniversary (use %d to show years): "))
  6369. (org-agenda-add-entry-to-org-agenda-diary-file 'anniversary text d1)
  6370. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6371. ((equal char ?b)
  6372. (setq text (read-string "Block entry: "))
  6373. (unless (and d1 d2 (not (equal d1 d2)))
  6374. (error "No block of days selected"))
  6375. (org-agenda-add-entry-to-org-agenda-diary-file 'block text d1 d2)
  6376. (and (equal (buffer-name) org-agenda-buffer-name) (org-agenda-redo)))
  6377. ((equal char ?j)
  6378. (org-switch-to-buffer-other-window
  6379. (find-file-noselect org-agenda-diary-file))
  6380. (org-datetree-find-date-create d1)
  6381. (org-reveal t))
  6382. (t (error "Invalid selection character `%c'" char)))))
  6383. (defcustom org-agenda-insert-diary-strategy 'date-tree
  6384. "Where in `org-agenda-diary-file' should new entries be added?
  6385. Valid values:
  6386. date-tree in the date tree, as child of the date
  6387. top-level as top-level entries at the end of the file."
  6388. :group 'org-agenda
  6389. :type '(choice
  6390. (const :tag "in a date tree" date-tree)
  6391. (const :tag "as top level at end of file" top-level)))
  6392. (defun org-agenda-add-entry-to-org-agenda-diary-file (type text &optional d1 d2)
  6393. "Add a diary entry with TYPE to `org-agenda-diary-file'.
  6394. If TEXT is not empty, it will become the headline of the new entry, and
  6395. the resulting entry will not be shown. When TEXT is empty, switch to
  6396. `org-agenda-diary-file' and let the user finish the entry there."
  6397. (let ((cw (current-window-configuration)))
  6398. (org-switch-to-buffer-other-window
  6399. (find-file-noselect org-agenda-diary-file))
  6400. (widen)
  6401. (goto-char (point-min))
  6402. (cond
  6403. ((eq type 'anniversary)
  6404. (or (re-search-forward "^*[ \t]+Anniversaries" nil t)
  6405. (progn
  6406. (or (org-on-heading-p t)
  6407. (progn
  6408. (outline-next-heading)
  6409. (insert "* Anniversaries\n\n")
  6410. (beginning-of-line -1)))))
  6411. (outline-next-heading)
  6412. (org-back-over-empty-lines)
  6413. (backward-char 1)
  6414. (insert "\n")
  6415. (require 'diary-lib)
  6416. (let ((calendar-date-display-form
  6417. (if (if (boundp 'calendar-date-style)
  6418. (eq calendar-date-style 'european)
  6419. (org-bound-and-true-p european-calendar-style)) ; Emacs 22
  6420. '(day " " month " " year)
  6421. '(month " " day " " year))))
  6422. (insert (format "%%%%(diary-anniversary %s) %s"
  6423. (calendar-date-string d1 nil t) text))))
  6424. ((eq type 'day)
  6425. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6426. (org-agenda-insert-diary-as-top-level text)
  6427. (require 'org-datetree)
  6428. (org-datetree-find-date-create d1)
  6429. (org-agenda-insert-diary-make-new-entry text))
  6430. (org-insert-time-stamp (org-time-from-absolute
  6431. (calendar-absolute-from-gregorian d1)))
  6432. (end-of-line 0))
  6433. ((eq type 'block)
  6434. (if (> (calendar-absolute-from-gregorian d1)
  6435. (calendar-absolute-from-gregorian d2))
  6436. (setq d1 (prog1 d2 (setq d2 d1))))
  6437. (if (eq org-agenda-insert-diary-strategy 'top-level)
  6438. (org-agenda-insert-diary-as-top-level text)
  6439. (require 'org-datetree)
  6440. (org-datetree-find-date-create d1)
  6441. (org-agenda-insert-diary-make-new-entry text))
  6442. (org-insert-time-stamp (org-time-from-absolute
  6443. (calendar-absolute-from-gregorian d1)))
  6444. (insert "--")
  6445. (org-insert-time-stamp (org-time-from-absolute
  6446. (calendar-absolute-from-gregorian d2)))
  6447. (end-of-line 0)))
  6448. (if (string-match "\\S-" text)
  6449. (progn
  6450. (set-window-configuration cw)
  6451. (message "%s entry added to %s"
  6452. (capitalize (symbol-name type))
  6453. (abbreviate-file-name org-agenda-diary-file)))
  6454. (org-reveal t)
  6455. (message "Please finish entry here"))))
  6456. (defun org-agenda-insert-diary-as-top-level (text)
  6457. "Make new entry as a top-level entry at the end of the file.
  6458. Add TEXT as headline, and position the cursor in the second line so that
  6459. a timestamp can be added there."
  6460. (widen)
  6461. (goto-char (point-max))
  6462. (or (bolp) (insert "\n"))
  6463. (insert "* " text "\n")
  6464. (if org-adapt-indentation (org-indent-to-column 2)))
  6465. (defun org-agenda-insert-diary-make-new-entry (text)
  6466. "Make new entry as last child of current entry.
  6467. Add TEXT as headline, and position the cursor in the second line so that
  6468. a timestamp can be added there."
  6469. (let ((org-show-following-heading t)
  6470. (org-show-siblings t)
  6471. (org-show-hierarchy-above t)
  6472. (org-show-entry-below t)
  6473. col)
  6474. (outline-next-heading)
  6475. (org-back-over-empty-lines)
  6476. (or (looking-at "[ \t]*$")
  6477. (progn (insert "\n") (backward-char 1)))
  6478. (org-insert-heading)
  6479. (org-do-demote)
  6480. (setq col (current-column))
  6481. (insert text "\n")
  6482. (if org-adapt-indentation (org-indent-to-column col))
  6483. (let ((org-show-following-heading t)
  6484. (org-show-siblings t)
  6485. (org-show-hierarchy-above t)
  6486. (org-show-entry-below t))
  6487. (org-show-context))))
  6488. (defun org-agenda-diary-entry ()
  6489. "Make a diary entry, like the `i' command from the calendar.
  6490. All the standard commands work: block, weekly etc.
  6491. When `org-agenda-diary-file' points to a file,
  6492. `org-agenda-diary-entry-in-org-file' is called instead to create
  6493. entries in that Org-mode file."
  6494. (interactive)
  6495. (org-agenda-check-type t 'agenda 'timeline)
  6496. (if (not (eq org-agenda-diary-file 'diary-file))
  6497. (org-agenda-diary-entry-in-org-file)
  6498. (require 'diary-lib)
  6499. (let* ((char (progn
  6500. (message "Diary entry: [d]ay [w]eekly [m]onthly [y]early [a]nniversary [b]lock [c]yclic")
  6501. (read-char-exclusive)))
  6502. (cmd (cdr (assoc char
  6503. '((?d . insert-diary-entry)
  6504. (?w . insert-weekly-diary-entry)
  6505. (?m . insert-monthly-diary-entry)
  6506. (?y . insert-yearly-diary-entry)
  6507. (?a . insert-anniversary-diary-entry)
  6508. (?b . insert-block-diary-entry)
  6509. (?c . insert-cyclic-diary-entry)))))
  6510. (oldf (symbol-function 'calendar-cursor-to-date))
  6511. ;; (buf (get-file-buffer (substitute-in-file-name diary-file)))
  6512. (point (point))
  6513. (mark (or (mark t) (point))))
  6514. (unless cmd
  6515. (error "No command associated with <%c>" char))
  6516. (unless (and (get-text-property point 'day)
  6517. (or (not (equal ?b char))
  6518. (get-text-property mark 'day)))
  6519. (error "Don't know which date to use for diary entry"))
  6520. ;; We implement this by hacking the `calendar-cursor-to-date' function
  6521. ;; and the `calendar-mark-ring' variable. Saves a lot of code.
  6522. (let ((calendar-mark-ring
  6523. (list (calendar-gregorian-from-absolute
  6524. (or (get-text-property mark 'day)
  6525. (get-text-property point 'day))))))
  6526. (unwind-protect
  6527. (progn
  6528. (fset 'calendar-cursor-to-date
  6529. (lambda (&optional error dummy)
  6530. (calendar-gregorian-from-absolute
  6531. (get-text-property point 'day))))
  6532. (call-interactively cmd))
  6533. (fset 'calendar-cursor-to-date oldf))))))
  6534. (defun org-agenda-execute-calendar-command (cmd)
  6535. "Execute a calendar command from the agenda, with the date associated to
  6536. the cursor position."
  6537. (org-agenda-check-type t 'agenda 'timeline)
  6538. (require 'diary-lib)
  6539. (unless (get-text-property (point) 'day)
  6540. (error "Don't know which date to use for calendar command"))
  6541. (let* ((oldf (symbol-function 'calendar-cursor-to-date))
  6542. (point (point))
  6543. (date (calendar-gregorian-from-absolute
  6544. (get-text-property point 'day)))
  6545. ;; the following 2 vars are needed in the calendar
  6546. (displayed-month (car date))
  6547. (displayed-year (nth 2 date)))
  6548. (unwind-protect
  6549. (progn
  6550. (fset 'calendar-cursor-to-date
  6551. (lambda (&optional error dummy)
  6552. (calendar-gregorian-from-absolute
  6553. (get-text-property point 'day))))
  6554. (call-interactively cmd))
  6555. (fset 'calendar-cursor-to-date oldf))))
  6556. (defun org-agenda-phases-of-moon ()
  6557. "Display the phases of the moon for the 3 months around the cursor date."
  6558. (interactive)
  6559. (org-agenda-execute-calendar-command 'calendar-phases-of-moon))
  6560. (defun org-agenda-holidays ()
  6561. "Display the holidays for the 3 months around the cursor date."
  6562. (interactive)
  6563. (org-agenda-execute-calendar-command 'list-calendar-holidays))
  6564. (defvar calendar-longitude)
  6565. (defvar calendar-latitude)
  6566. (defvar calendar-location-name)
  6567. (defun org-agenda-sunrise-sunset (arg)
  6568. "Display sunrise and sunset for the cursor date.
  6569. Latitude and longitude can be specified with the variables
  6570. `calendar-latitude' and `calendar-longitude'. When called with prefix
  6571. argument, latitude and longitude will be prompted for."
  6572. (interactive "P")
  6573. (require 'solar)
  6574. (let ((calendar-longitude (if arg nil calendar-longitude))
  6575. (calendar-latitude (if arg nil calendar-latitude))
  6576. (calendar-location-name
  6577. (if arg "the given coordinates" calendar-location-name)))
  6578. (org-agenda-execute-calendar-command 'calendar-sunrise-sunset)))
  6579. (defun org-agenda-goto-calendar ()
  6580. "Open the Emacs calendar with the date at the cursor."
  6581. (interactive)
  6582. (org-agenda-check-type t 'agenda 'timeline)
  6583. (let* ((day (or (get-text-property (point) 'day)
  6584. (error "Don't know which date to open in calendar")))
  6585. (date (calendar-gregorian-from-absolute day))
  6586. (calendar-move-hook nil)
  6587. (calendar-view-holidays-initially-flag nil)
  6588. (calendar-view-diary-initially-flag nil)
  6589. (view-calendar-holidays-initially nil)
  6590. (view-diary-entries-initially nil))
  6591. (calendar)
  6592. (calendar-goto-date date)))
  6593. ;;;###autoload
  6594. (defun org-calendar-goto-agenda ()
  6595. "Compute the Org-mode agenda for the calendar date displayed at the cursor.
  6596. This is a command that has to be installed in `calendar-mode-map'."
  6597. (interactive)
  6598. (org-agenda-list nil (calendar-absolute-from-gregorian
  6599. (calendar-cursor-to-date))
  6600. nil))
  6601. (defun org-agenda-convert-date ()
  6602. (interactive)
  6603. (org-agenda-check-type t 'agenda 'timeline)
  6604. (let ((day (get-text-property (point) 'day))
  6605. date s)
  6606. (unless day
  6607. (error "Don't know which date to convert"))
  6608. (setq date (calendar-gregorian-from-absolute day))
  6609. (setq s (concat
  6610. "Gregorian: " (calendar-date-string date) "\n"
  6611. "ISO: " (calendar-iso-date-string date) "\n"
  6612. "Day of Yr: " (calendar-day-of-year-string date) "\n"
  6613. "Julian: " (calendar-julian-date-string date) "\n"
  6614. "Astron. JD: " (calendar-astro-date-string date)
  6615. " (Julian date number at noon UTC)\n"
  6616. "Hebrew: " (calendar-hebrew-date-string date) " (until sunset)\n"
  6617. "Islamic: " (calendar-islamic-date-string date) " (until sunset)\n"
  6618. "French: " (calendar-french-date-string date) "\n"
  6619. "Baha'i: " (calendar-bahai-date-string date) " (until sunset)\n"
  6620. "Mayan: " (calendar-mayan-date-string date) "\n"
  6621. "Coptic: " (calendar-coptic-date-string date) "\n"
  6622. "Ethiopic: " (calendar-ethiopic-date-string date) "\n"
  6623. "Persian: " (calendar-persian-date-string date) "\n"
  6624. "Chinese: " (calendar-chinese-date-string date) "\n"))
  6625. (with-output-to-temp-buffer "*Dates*"
  6626. (princ s))
  6627. (org-fit-window-to-buffer (get-buffer-window "*Dates*"))))
  6628. ;;; Bulk commands
  6629. (defvar org-agenda-bulk-marked-entries nil
  6630. "List of markers that refer to marked entries in the agenda.")
  6631. (defun org-agenda-bulk-marked-p ()
  6632. (eq (get-char-property (point-at-bol) 'type)
  6633. 'org-marked-entry-overlay))
  6634. (defun org-agenda-bulk-mark ()
  6635. "Mark the entry at point for future bulk action."
  6636. (interactive)
  6637. (org-agenda-check-no-diary)
  6638. (let* ((m (org-get-at-bol 'org-hd-marker))
  6639. ov)
  6640. (unless (org-agenda-bulk-marked-p)
  6641. (unless m (error "Nothing to mark at point"))
  6642. (push m org-agenda-bulk-marked-entries)
  6643. (setq ov (org-make-overlay (point-at-bol) (+ 2 (point-at-bol))))
  6644. (org-overlay-display ov "> "
  6645. (org-get-todo-face "TODO")
  6646. 'evaporate)
  6647. (org-overlay-put ov 'type 'org-marked-entry-overlay))
  6648. (beginning-of-line 2)
  6649. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6650. (beginning-of-line 2))
  6651. (message "%d entries marked for bulk action"
  6652. (length org-agenda-bulk-marked-entries))))
  6653. (defun org-agenda-bulk-unmark ()
  6654. "Unmark the entry at point for future bulk action."
  6655. (interactive)
  6656. (when (org-agenda-bulk-marked-p)
  6657. (org-agenda-bulk-remove-overlays
  6658. (point-at-bol) (+ 2 (point-at-bol)))
  6659. (setq org-agenda-bulk-marked-entries
  6660. (delete (org-get-at-bol 'org-hd-marker)
  6661. org-agenda-bulk-marked-entries)))
  6662. (beginning-of-line 2)
  6663. (while (and (get-char-property (point) 'invisible) (not (eobp)))
  6664. (beginning-of-line 2))
  6665. (message "%d entries marked for bulk action"
  6666. (length org-agenda-bulk-marked-entries)))
  6667. (defun org-agenda-bulk-toggle ()
  6668. "Toggle marking the entry at point for bulk action."
  6669. (interactive)
  6670. (if (org-agenda-bulk-marked-p)
  6671. (org-agenda-bulk-unmark)
  6672. (org-agenda-bulk-mark)))
  6673. (defun org-agenda-bulk-remove-overlays (&optional beg end)
  6674. "Remove the mark overlays between BEG and END in the agenda buffer.
  6675. BEG and END default to the buffer limits.
  6676. This only removes the overlays, it does not remove the markers
  6677. from the list in `org-agenda-bulk-marked-entries'."
  6678. (interactive)
  6679. (mapc (lambda (ov)
  6680. (and (eq (org-overlay-get ov 'type) 'org-marked-entry-overlay)
  6681. (org-delete-overlay ov)))
  6682. (org-overlays-in (or beg (point-min)) (or end (point-max)))))
  6683. (defun org-agenda-bulk-remove-all-marks ()
  6684. "Remove all marks in the agenda buffer.
  6685. This will remove the markers, and the overlays."
  6686. (interactive)
  6687. (mapc (lambda (m) (move-marker m nil)) org-agenda-bulk-marked-entries)
  6688. (setq org-agenda-bulk-marked-entries nil)
  6689. (org-agenda-bulk-remove-overlays (point-min) (point-max)))
  6690. (defun org-agenda-bulk-action (&optional arg)
  6691. "Execute an remote-editing action on all marked entries.
  6692. The prefix arg is passed through to the command if possible."
  6693. (interactive "P")
  6694. (unless org-agenda-bulk-marked-entries
  6695. (error "No entries are marked"))
  6696. (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
  6697. (let* ((action (read-char-exclusive))
  6698. (entries (reverse org-agenda-bulk-marked-entries))
  6699. cmd rfloc state e tag pos (cnt 0) (cntskip 0))
  6700. (cond
  6701. ((equal action ?$)
  6702. (setq cmd '(org-agenda-archive)))
  6703. ((equal action ?A)
  6704. (setq cmd '(org-agenda-archive-to-archive-sibling)))
  6705. ((member action '(?r ?w))
  6706. (setq rfloc (org-refile-get-location
  6707. "Refile to: "
  6708. (marker-buffer (car org-agenda-bulk-marked-entries))
  6709. org-refile-allow-creating-parent-nodes))
  6710. (setcar (nthcdr 3 rfloc)
  6711. (move-marker (make-marker) (nth 3 rfloc)
  6712. (or (get-file-buffer (nth 1 rfloc))
  6713. (find-buffer-visiting (nth 1 rfloc))
  6714. (error "This should not happen"))))
  6715. (setq cmd (list 'org-agenda-refile nil (list 'quote rfloc))))
  6716. ((equal action ?t)
  6717. (setq state (org-icompleting-read
  6718. "Todo state: "
  6719. (with-current-buffer (marker-buffer (car entries))
  6720. (mapcar 'list org-todo-keywords-1))))
  6721. (setq cmd `(let ((org-inhibit-blocking t)
  6722. (org-inhibit-logging 'note))
  6723. (org-agenda-todo ,state))))
  6724. ((memq action '(?- ?+))
  6725. (setq tag (org-icompleting-read
  6726. (format "Tag to %s: " (if (eq action ?+) "add" "remove"))
  6727. (with-current-buffer (marker-buffer (car entries))
  6728. (delq nil
  6729. (mapcar (lambda (x)
  6730. (if (stringp (car x)) x)) org-tag-alist)))))
  6731. (setq cmd `(org-agenda-set-tags ,tag ,(if (eq action ?+) ''on ''off))))
  6732. ((memq action '(?s ?d))
  6733. (let* ((date (unless arg
  6734. (org-read-date
  6735. nil nil nil
  6736. (if (eq action ?s) "(Re)Schedule to" "Set Deadline to"))))
  6737. (ans (if arg nil org-read-date-final-answer))
  6738. (c1 (if (eq action ?s) 'org-agenda-schedule 'org-agenda-deadline)))
  6739. (setq cmd `(let* ((bound (fboundp 'read-string))
  6740. (old (and bound (symbol-function 'read-string))))
  6741. (unwind-protect
  6742. (progn
  6743. (fset 'read-string (lambda (&rest ignore) ,ans))
  6744. (eval '(,c1 arg)))
  6745. (if bound
  6746. (fset 'read-string old)
  6747. (fmakunbound 'read-string)))))))
  6748. (t (error "Invalid bulk action")))
  6749. ;; Sort the markers, to make sure that parents are handled before children
  6750. (setq entries (sort entries
  6751. (lambda (a b)
  6752. (cond
  6753. ((equal (marker-buffer a) (marker-buffer b))
  6754. (< (marker-position a) (marker-position b)))
  6755. (t
  6756. (string< (buffer-name (marker-buffer a))
  6757. (buffer-name (marker-buffer b))))))))
  6758. ;; Now loop over all markers and apply cmd
  6759. (while (setq e (pop entries))
  6760. (setq pos (text-property-any (point-min) (point-max) 'org-hd-marker e))
  6761. (if (not pos)
  6762. (progn (message "Skipping removed entry at %s" e)
  6763. (setq cntskip (1+ cntskip)))
  6764. (goto-char pos)
  6765. (eval cmd)
  6766. (setq org-agenda-bulk-marked-entries
  6767. (delete e org-agenda-bulk-marked-entries))
  6768. (setq cnt (1+ cnt))))
  6769. (setq org-agenda-bulk-marked-entries nil)
  6770. (org-agenda-bulk-remove-all-marks)
  6771. (message "Acted on %d entries%s"
  6772. cnt
  6773. (if (= cntskip 0)
  6774. ""
  6775. (format ", skipped %d (disappeared before their turn)"
  6776. cntskip)))))
  6777. ;;; Flagging notes
  6778. (defun org-agenda-show-the-flagging-note ()
  6779. "Display the flagging note in the other window.
  6780. When called a second time in direct sequence, offer to remove the FLAGGING
  6781. tag and (if present) the flagging note."
  6782. (interactive)
  6783. (let ((hdmarker (org-get-at-bol 'org-hd-marker))
  6784. (win (selected-window))
  6785. note heading newhead)
  6786. (unless hdmarker
  6787. (error "No linked entry at point"))
  6788. (if (and (eq this-command last-command)
  6789. (y-or-n-p "Unflag and remove any flagging note? "))
  6790. (progn
  6791. (org-agenda-remove-flag hdmarker)
  6792. (let ((win (get-buffer-window "*Flagging Note*")))
  6793. (and win (delete-window win)))
  6794. (message "Entry unflaged"))
  6795. (setq note (org-entry-get hdmarker "THEFLAGGINGNOTE"))
  6796. (unless note
  6797. (error "No flagging note"))
  6798. (org-kill-new note)
  6799. (org-switch-to-buffer-other-window "*Flagging Note*")
  6800. (erase-buffer)
  6801. (insert note)
  6802. (goto-char (point-min))
  6803. (while (re-search-forward "\\\\n" nil t)
  6804. (replace-match "\n" t t))
  6805. (goto-char (point-min))
  6806. (select-window win)
  6807. (message "Flagging note pushed to kill ring. Press [?] again to remove tag and note"))))
  6808. (defun org-agenda-remove-flag (marker)
  6809. "Remove the FLAGGED tag and any flagging note in the entry."
  6810. (let (newhead)
  6811. (org-with-point-at marker
  6812. (org-toggle-tag "FLAGGED" 'off)
  6813. (org-entry-delete nil "THEFLAGGINGNOTE")
  6814. (setq newhead (org-get-heading)))
  6815. (org-agenda-change-all-lines newhead marker)
  6816. (message "Entry unflaged")))
  6817. (defun org-agenda-get-any-marker (&optional pos)
  6818. (or (get-text-property (or pos (point-at-bol)) 'org-hd-marker)
  6819. (get-text-property (or pos (point-at-bol)) 'org-marker)))
  6820. ;;; Appointment reminders
  6821. (defvar appt-time-msg-list)
  6822. ;;;###autoload
  6823. (defun org-agenda-to-appt (&optional refresh filter)
  6824. "Activate appointments found in `org-agenda-files'.
  6825. With a \\[universal-argument] prefix, refresh the list of
  6826. appointments.
  6827. If FILTER is t, interactively prompt the user for a regular
  6828. expression, and filter out entries that don't match it.
  6829. If FILTER is a string, use this string as a regular expression
  6830. for filtering entries out.
  6831. FILTER can also be an alist with the car of each cell being
  6832. either 'headline or 'category. For example:
  6833. '((headline \"IMPORTANT\")
  6834. (category \"Work\"))
  6835. will only add headlines containing IMPORTANT or headlines
  6836. belonging to the \"Work\" category."
  6837. (interactive "P")
  6838. (require 'calendar)
  6839. (if refresh (setq appt-time-msg-list nil))
  6840. (if (eq filter t)
  6841. (setq filter (read-from-minibuffer "Regexp filter: ")))
  6842. (let* ((cnt 0) ; count added events
  6843. (org-agenda-new-buffers nil)
  6844. (org-deadline-warning-days 0)
  6845. (today (org-date-to-gregorian
  6846. (time-to-days (current-time))))
  6847. (org-agenda-restrict nil)
  6848. (files (org-agenda-files 'unrestricted)) entries file)
  6849. ;; Get all entries which may contain an appt
  6850. (org-prepare-agenda-buffers files)
  6851. (while (setq file (pop files))
  6852. (setq entries
  6853. (append entries
  6854. (org-agenda-get-day-entries
  6855. file today :timestamp :scheduled :deadline))))
  6856. (setq entries (delq nil entries))
  6857. ;; Map thru entries and find if we should filter them out
  6858. (mapc
  6859. (lambda(x)
  6860. (let* ((evt (org-trim (or (get-text-property 1 'txt x) "")))
  6861. (cat (get-text-property 1 'org-category x))
  6862. (tod (get-text-property 1 'time-of-day x))
  6863. (ok (or (null filter)
  6864. (and (stringp filter) (string-match filter evt))
  6865. (and (listp filter)
  6866. (or (string-match
  6867. (cadr (assoc 'category filter)) cat)
  6868. (string-match
  6869. (cadr (assoc 'headline filter)) evt))))))
  6870. ;; FIXME: Shall we remove text-properties for the appt text?
  6871. ;; (setq evt (set-text-properties 0 (length evt) nil evt))
  6872. (when (and ok tod)
  6873. (setq tod (concat "00" (number-to-string tod))
  6874. tod (when (string-match
  6875. "\\([0-9]\\{1,2\\}\\)\\([0-9]\\{2\\}\\)\\'" tod)
  6876. (concat (match-string 1 tod) ":"
  6877. (match-string 2 tod))))
  6878. (appt-add tod evt)
  6879. (setq cnt (1+ cnt))))) entries)
  6880. (org-release-buffers org-agenda-new-buffers)
  6881. (if (eq cnt 0)
  6882. (message "No event to add")
  6883. (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
  6884. (defun org-agenda-todayp (date)
  6885. "Does DATE mean today, when considering `org-extend-today-until'?"
  6886. (let (today h)
  6887. (if (listp date) (setq date (calendar-absolute-from-gregorian date)))
  6888. (setq today (calendar-absolute-from-gregorian (calendar-current-date)))
  6889. (setq h (nth 2 (decode-time (current-time))))
  6890. (or (and (>= h org-extend-today-until)
  6891. (= date today))
  6892. (and (< h org-extend-today-until)
  6893. (= date (1- today))))))
  6894. (provide 'org-agenda)
  6895. ;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1
  6896. ;;; org-agenda.el ends here