org-agenda.el 224 KB

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