org-agenda.el 257 KB

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