org-agenda.el 265 KB

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