org-agenda.el 206 KB

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