org-agenda.el 206 KB

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