org-agenda.el 206 KB

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