org-agenda.el 202 KB

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