org-agenda.el 287 KB

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