org-agenda.el 269 KB

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