org-agenda.el 207 KB

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