org-colview.el 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  1. ;;; org-colview.el --- Column View in Org-mode
  2. ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;;
  7. ;; This file is part of GNU Emacs.
  8. ;;
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;;; Commentary:
  22. ;; This file contains the column view for Org.
  23. ;;; Code:
  24. (eval-when-compile (require 'cl))
  25. (require 'org)
  26. (declare-function org-agenda-redo "org-agenda" ())
  27. (declare-function org-agenda-do-context-action "org-agenda" ())
  28. (when (featurep 'xemacs)
  29. (error "Do not load this file into XEmacs, use 'org-colview-xemacs.el'."))
  30. ;;; Column View
  31. (defvar org-columns-overlays nil
  32. "Holds the list of current column overlays.")
  33. (defvar org-columns-current-fmt nil
  34. "Local variable, holds the currently active column format.")
  35. (make-variable-buffer-local 'org-columns-current-fmt)
  36. (defvar org-columns-current-fmt-compiled nil
  37. "Local variable, holds the currently active column format.
  38. This is the compiled version of the format.")
  39. (make-variable-buffer-local 'org-columns-current-fmt-compiled)
  40. (defvar org-columns-current-widths nil
  41. "Loval variable, holds the currently widths of fields.")
  42. (make-variable-buffer-local 'org-columns-current-widths)
  43. (defvar org-columns-current-maxwidths nil
  44. "Loval variable, holds the currently active maximum column widths.")
  45. (make-variable-buffer-local 'org-columns-current-maxwidths)
  46. (defvar org-columns-begin-marker (make-marker)
  47. "Points to the position where last a column creation command was called.")
  48. (defvar org-columns-top-level-marker (make-marker)
  49. "Points to the position where current columns region starts.")
  50. (defvar org-columns-map (make-sparse-keymap)
  51. "The keymap valid in column display.")
  52. (defun org-columns-content ()
  53. "Switch to contents view while in columns view."
  54. (interactive)
  55. (org-overview)
  56. (org-content))
  57. (org-defkey org-columns-map "c" 'org-columns-content)
  58. (org-defkey org-columns-map "o" 'org-overview)
  59. (org-defkey org-columns-map "e" 'org-columns-edit-value)
  60. (org-defkey org-columns-map "\C-c\C-t" 'org-columns-todo)
  61. (org-defkey org-columns-map "\C-c\C-c" 'org-columns-set-tags-or-toggle)
  62. (org-defkey org-columns-map "\C-c\C-o" 'org-columns-open-link)
  63. (org-defkey org-columns-map "v" 'org-columns-show-value)
  64. (org-defkey org-columns-map "q" 'org-columns-quit)
  65. (org-defkey org-columns-map "r" 'org-columns-redo)
  66. (org-defkey org-columns-map "g" 'org-columns-redo)
  67. (org-defkey org-columns-map [left] 'backward-char)
  68. (org-defkey org-columns-map "\M-b" 'backward-char)
  69. (org-defkey org-columns-map "a" 'org-columns-edit-allowed)
  70. (org-defkey org-columns-map "s" 'org-columns-edit-attributes)
  71. (org-defkey org-columns-map "\M-f"
  72. (lambda () (interactive) (goto-char (1+ (point)))))
  73. (org-defkey org-columns-map [right]
  74. (lambda () (interactive) (goto-char (1+ (point)))))
  75. (org-defkey org-columns-map [down]
  76. (lambda () (interactive)
  77. (let ((col (current-column)))
  78. (beginning-of-line 2)
  79. (while (and (org-invisible-p2) (not (eobp)))
  80. (beginning-of-line 2))
  81. (move-to-column col)
  82. (if (eq major-mode 'org-agenda-mode)
  83. (org-agenda-do-context-action)))))
  84. (org-defkey org-columns-map [up]
  85. (lambda () (interactive)
  86. (let ((col (current-column)))
  87. (beginning-of-line 0)
  88. (while (and (org-invisible-p2) (not (bobp)))
  89. (beginning-of-line 0))
  90. (move-to-column col)
  91. (if (eq major-mode 'org-agenda-mode)
  92. (org-agenda-do-context-action)))))
  93. (org-defkey org-columns-map [(shift right)] 'org-columns-next-allowed-value)
  94. (org-defkey org-columns-map "n" 'org-columns-next-allowed-value)
  95. (org-defkey org-columns-map [(shift left)] 'org-columns-previous-allowed-value)
  96. (org-defkey org-columns-map "p" 'org-columns-previous-allowed-value)
  97. (org-defkey org-columns-map "<" 'org-columns-narrow)
  98. (org-defkey org-columns-map ">" 'org-columns-widen)
  99. (org-defkey org-columns-map [(meta right)] 'org-columns-move-right)
  100. (org-defkey org-columns-map [(meta left)] 'org-columns-move-left)
  101. (org-defkey org-columns-map [(shift meta right)] 'org-columns-new)
  102. (org-defkey org-columns-map [(shift meta left)] 'org-columns-delete)
  103. (dotimes (i 10)
  104. (org-defkey org-columns-map (number-to-string i)
  105. `(lambda () (interactive)
  106. (org-columns-next-allowed-value nil ,i))))
  107. (easy-menu-define org-columns-menu org-columns-map "Org Column Menu"
  108. '("Column"
  109. ["Edit property" org-columns-edit-value t]
  110. ["Next allowed value" org-columns-next-allowed-value t]
  111. ["Previous allowed value" org-columns-previous-allowed-value t]
  112. ["Show full value" org-columns-show-value t]
  113. ["Edit allowed values" org-columns-edit-allowed t]
  114. "--"
  115. ["Edit column attributes" org-columns-edit-attributes t]
  116. ["Increase column width" org-columns-widen t]
  117. ["Decrease column width" org-columns-narrow t]
  118. "--"
  119. ["Move column right" org-columns-move-right t]
  120. ["Move column left" org-columns-move-left t]
  121. ["Add column" org-columns-new t]
  122. ["Delete column" org-columns-delete t]
  123. "--"
  124. ["CONTENTS" org-columns-content t]
  125. ["OVERVIEW" org-overview t]
  126. ["Refresh columns display" org-columns-redo t]
  127. "--"
  128. ["Open link" org-columns-open-link t]
  129. "--"
  130. ["Quit" org-columns-quit t]))
  131. (defun org-columns-new-overlay (beg end &optional string face)
  132. "Create a new column overlay and add it to the list."
  133. (let ((ov (make-overlay beg end)))
  134. (overlay-put ov 'face (or face 'secondary-selection))
  135. (org-overlay-display ov string face)
  136. (push ov org-columns-overlays)
  137. ov))
  138. (defun org-columns-display-here (&optional props dateline)
  139. "Overlay the current line with column display."
  140. (interactive)
  141. (let* ((fmt org-columns-current-fmt-compiled)
  142. (beg (point-at-bol))
  143. (level-face (save-excursion
  144. (beginning-of-line 1)
  145. (and (looking-at "\\(\\**\\)\\(\\* \\)")
  146. (org-get-level-face 2))))
  147. (ref-face (or level-face
  148. (and (eq major-mode 'org-agenda-mode)
  149. (get-text-property (point-at-bol) 'face))
  150. 'default))
  151. (color (list :foreground (face-attribute ref-face :foreground)))
  152. (face (list color 'org-column ref-face))
  153. (face1 (list color 'org-agenda-column-dateline ref-face))
  154. (cphr (get-text-property (point-at-bol) 'org-complex-heading-regexp))
  155. pom property ass width f string ov column val modval s2 title calc)
  156. ;; Check if the entry is in another buffer.
  157. (unless props
  158. (if (eq major-mode 'org-agenda-mode)
  159. (setq pom (or (org-get-at-bol 'org-hd-marker)
  160. (org-get-at-bol 'org-marker))
  161. props (if pom (org-entry-properties pom) nil))
  162. (setq props (org-entry-properties nil))))
  163. ;; Walk the format
  164. (while (setq column (pop fmt))
  165. (setq property (car column)
  166. title (nth 1 column)
  167. ass (if (equal property "ITEM")
  168. (cons "ITEM"
  169. ;; When in a buffer, get the whole line,
  170. ;; we'll clean it later…
  171. (if (eq major-mode 'org-mode)
  172. (save-match-data
  173. (org-no-properties
  174. (org-remove-tabs
  175. (buffer-substring-no-properties
  176. (point-at-bol) (point-at-eol)))))
  177. ;; In agenda, just get the `txt' property
  178. (org-no-properties
  179. (or (org-get-at-bol 'txt)
  180. (buffer-substring
  181. (point) (progn (end-of-line) (point)))))))
  182. (assoc property props))
  183. width (or (cdr (assoc property org-columns-current-maxwidths))
  184. (nth 2 column)
  185. (length property))
  186. f (format "%%-%d.%ds | " width width)
  187. calc (nth 7 column)
  188. val (or (cdr ass) "")
  189. modval (cond ((and org-columns-modify-value-for-display-function
  190. (functionp
  191. org-columns-modify-value-for-display-function))
  192. (funcall org-columns-modify-value-for-display-function
  193. title val))
  194. ((equal property "ITEM")
  195. (org-columns-cleanup-item
  196. val org-columns-current-fmt-compiled
  197. (or org-complex-heading-regexp cphr)))
  198. ((and calc (functionp calc)
  199. (not (string= val ""))
  200. (not (get-text-property 0 'org-computed val)))
  201. (org-columns-number-to-string
  202. (funcall calc (org-columns-string-to-number
  203. val (nth 4 column)))
  204. (nth 4 column)))))
  205. (setq s2 (org-columns-add-ellipses (or modval val) width))
  206. (setq string (format f s2))
  207. ;; Create the overlay
  208. (org-unmodified
  209. (setq ov (org-columns-new-overlay
  210. beg (setq beg (1+ beg)) string (if dateline face1 face)))
  211. (overlay-put ov 'keymap org-columns-map)
  212. (overlay-put ov 'org-columns-key property)
  213. (overlay-put ov 'org-columns-value (cdr ass))
  214. (overlay-put ov 'org-columns-value-modified modval)
  215. (overlay-put ov 'org-columns-pom pom)
  216. (overlay-put ov 'org-columns-format f)
  217. (overlay-put ov 'line-prefix "")
  218. (overlay-put ov 'wrap-prefix ""))
  219. (if (or (not (char-after beg))
  220. (equal (char-after beg) ?\n))
  221. (let ((inhibit-read-only t))
  222. (save-excursion
  223. (goto-char beg)
  224. (org-unmodified (insert " ")))))) ;; FIXME: add props and remove later?
  225. ;; Make the rest of the line disappear.
  226. (org-unmodified
  227. (setq ov (org-columns-new-overlay beg (point-at-eol)))
  228. (overlay-put ov 'invisible t)
  229. (overlay-put ov 'keymap org-columns-map)
  230. (overlay-put ov 'intangible t)
  231. (overlay-put ov 'line-prefix "")
  232. (overlay-put ov 'wrap-prefix "")
  233. (push ov org-columns-overlays)
  234. (setq ov (make-overlay (1- (point-at-eol)) (1+ (point-at-eol))))
  235. (overlay-put ov 'keymap org-columns-map)
  236. (push ov org-columns-overlays)
  237. (let ((inhibit-read-only t))
  238. (put-text-property (max (point-min) (1- (point-at-bol)))
  239. (min (point-max) (1+ (point-at-eol)))
  240. 'read-only "Type `e' to edit property")))))
  241. (defun org-columns-add-ellipses (string width)
  242. "Truncate STRING with WIDTH characters, with ellipses."
  243. (cond
  244. ((<= (length string) width) string)
  245. ((<= width (length org-columns-ellipses))
  246. (substring org-columns-ellipses 0 width))
  247. (t (concat (substring string 0 (- width (length org-columns-ellipses)))
  248. org-columns-ellipses))))
  249. (defvar org-columns-full-header-line-format nil
  250. "The full header line format, will be shifted by horizontal scrolling." )
  251. (defvar org-previous-header-line-format nil
  252. "The header line format before column view was turned on.")
  253. (defvar org-columns-inhibit-recalculation nil
  254. "Inhibit recomputing of columns on column view startup.")
  255. (defvar org-columns-flyspell-was-active nil
  256. "Remember the state of `flyspell-mode' before column view.
  257. Flyspell-mode can cause problems in columns view, so it is turned off
  258. for the duration of the command.")
  259. (defvar header-line-format)
  260. (defvar org-columns-previous-hscroll 0)
  261. (defun org-columns-display-here-title ()
  262. "Overlay the newline before the current line with the table title."
  263. (interactive)
  264. (let ((fmt org-columns-current-fmt-compiled)
  265. string (title "")
  266. property width f column str widths)
  267. (while (setq column (pop fmt))
  268. (setq property (car column)
  269. str (or (nth 1 column) property)
  270. width (or (cdr (assoc property org-columns-current-maxwidths))
  271. (nth 2 column)
  272. (length str))
  273. widths (push width widths)
  274. f (format "%%-%d.%ds | " width width)
  275. string (format f str)
  276. title (concat title string)))
  277. (setq title (concat
  278. (org-add-props " " nil 'display '(space :align-to 0))
  279. ;;(org-add-props title nil 'face '(:weight bold :underline t :inherit default))))
  280. (org-add-props title nil 'face 'org-column-title)))
  281. (org-set-local 'org-previous-header-line-format header-line-format)
  282. (org-set-local 'org-columns-current-widths (nreverse widths))
  283. (setq org-columns-full-header-line-format title)
  284. (setq org-columns-previous-hscroll -1)
  285. ; (org-columns-hscoll-title)
  286. (org-add-hook 'post-command-hook 'org-columns-hscoll-title nil 'local)))
  287. (defun org-columns-hscoll-title ()
  288. "Set the `header-line-format' so that it scrolls along with the table."
  289. (sit-for .0001) ; need to force a redisplay to update window-hscroll
  290. (when (not (= (window-hscroll) org-columns-previous-hscroll))
  291. (setq header-line-format
  292. (concat (substring org-columns-full-header-line-format 0 1)
  293. (substring org-columns-full-header-line-format
  294. (1+ (window-hscroll))))
  295. org-columns-previous-hscroll (window-hscroll))
  296. (force-mode-line-update)))
  297. (defvar org-colview-initial-truncate-line-value nil
  298. "Remember the value of `truncate-lines' across colview.")
  299. (defun org-columns-remove-overlays ()
  300. "Remove all currently active column overlays."
  301. (interactive)
  302. (when (marker-buffer org-columns-begin-marker)
  303. (with-current-buffer (marker-buffer org-columns-begin-marker)
  304. (when (local-variable-p 'org-previous-header-line-format)
  305. (setq header-line-format org-previous-header-line-format)
  306. (kill-local-variable 'org-previous-header-line-format)
  307. (remove-hook 'post-command-hook 'org-columns-hscoll-title 'local))
  308. (move-marker org-columns-begin-marker nil)
  309. (move-marker org-columns-top-level-marker nil)
  310. (org-unmodified
  311. (mapc 'delete-overlay org-columns-overlays)
  312. (setq org-columns-overlays nil)
  313. (let ((inhibit-read-only t))
  314. (remove-text-properties (point-min) (point-max) '(read-only t))))
  315. (when org-columns-flyspell-was-active
  316. (flyspell-mode 1))
  317. (when (local-variable-p 'org-colview-initial-truncate-line-value)
  318. (setq truncate-lines org-colview-initial-truncate-line-value)))))
  319. (defun org-columns-cleanup-item (item fmt cphr)
  320. "Remove from ITEM what is a column in the format FMT.
  321. CPHR is the complex heading regexp to use for parsing ITEM."
  322. (let (fixitem)
  323. (if (not cphr)
  324. item
  325. (unless (string-match "^\*+ " item)
  326. (setq item (concat "* " item) fixitem t))
  327. (if (string-match cphr item)
  328. (setq item
  329. (concat
  330. (org-add-props (match-string 1 item) nil
  331. 'org-whitespace (* 2 (1- (org-reduced-level (- (match-end 1) (match-beginning 1))))))
  332. (and (match-end 2) (not (assoc "TODO" fmt)) (concat " " (match-string 2 item)))
  333. (and (match-end 3) (not (assoc "PRIORITY" fmt)) (concat " " (match-string 3 item)))
  334. " " (save-match-data (org-columns-compact-links (or (match-string 4 item) "")))
  335. (and (match-end 5) (not (assoc "TAGS" fmt)) (concat " " (match-string 5 item)))))
  336. (add-text-properties
  337. 0 (1+ (match-end 1))
  338. (list 'org-whitespace (* 2 (1- (org-reduced-level (- (match-end 1) (match-beginning 1))))))
  339. item))
  340. (if fixitem (replace-regexp-in-string "^\*+ " "" item) item))))
  341. (defun org-columns-compact-links (s)
  342. "Replace [[link][desc]] with [desc] or [link]."
  343. (while (string-match org-bracket-link-regexp s)
  344. (setq s (replace-match
  345. (concat "[" (match-string (if (match-end 3) 3 1) s) "]")
  346. t t s)))
  347. s)
  348. (defun org-columns-show-value ()
  349. "Show the full value of the property."
  350. (interactive)
  351. (let ((value (get-char-property (point) 'org-columns-value)))
  352. (message "Value is: %s" (or value ""))))
  353. (defvar org-agenda-columns-active) ;; defined in org-agenda.el
  354. (defun org-columns-quit ()
  355. "Remove the column overlays and in this way exit column editing."
  356. (interactive)
  357. (org-unmodified
  358. (org-columns-remove-overlays)
  359. (let ((inhibit-read-only t))
  360. (remove-text-properties (point-min) (point-max) '(read-only t))))
  361. (when (eq major-mode 'org-agenda-mode)
  362. (setq org-agenda-columns-active nil)
  363. (message
  364. "Modification not yet reflected in Agenda buffer, use `r' to refresh")))
  365. (defun org-columns-check-computed ()
  366. "Check if this column value is computed.
  367. If yes, throw an error indicating that changing it does not make sense."
  368. (let ((val (get-char-property (point) 'org-columns-value)))
  369. (when (and (stringp val)
  370. (get-char-property 0 'org-computed val))
  371. (error "This value is computed from the entry's children"))))
  372. (defun org-columns-todo (&optional arg)
  373. "Change the TODO state during column view."
  374. (interactive "P")
  375. (org-columns-edit-value "TODO"))
  376. (defun org-columns-set-tags-or-toggle (&optional arg)
  377. "Toggle checkbox at point, or set tags for current headline."
  378. (interactive "P")
  379. (if (string-match "\\`\\[[ xX-]\\]\\'"
  380. (get-char-property (point) 'org-columns-value))
  381. (org-columns-next-allowed-value)
  382. (org-columns-edit-value "TAGS")))
  383. (defun org-columns-edit-value (&optional key)
  384. "Edit the value of the property at point in column view.
  385. Where possible, use the standard interface for changing this line."
  386. (interactive)
  387. (org-columns-check-computed)
  388. (let* ((col (current-column))
  389. (key (or key (get-char-property (point) 'org-columns-key)))
  390. (value (get-char-property (point) 'org-columns-value))
  391. (bol (point-at-bol)) (eol (point-at-eol))
  392. (pom (or (get-text-property bol 'org-hd-marker)
  393. (point))) ; keep despite of compiler waring
  394. (line-overlays
  395. (delq nil (mapcar (lambda (x)
  396. (and (eq (overlay-buffer x) (current-buffer))
  397. (>= (overlay-start x) bol)
  398. (<= (overlay-start x) eol)
  399. x))
  400. org-columns-overlays)))
  401. (org-columns-time (time-to-number-of-days (current-time)))
  402. nval eval allowed)
  403. (cond
  404. ((equal key "CLOCKSUM")
  405. (error "This special column cannot be edited"))
  406. ((equal key "ITEM")
  407. (setq eval '(org-with-point-at pom
  408. (org-edit-headline))))
  409. ((equal key "TODO")
  410. (setq eval '(org-with-point-at
  411. pom
  412. (call-interactively 'org-todo))))
  413. ((equal key "PRIORITY")
  414. (setq eval '(org-with-point-at pom
  415. (call-interactively 'org-priority))))
  416. ((equal key "TAGS")
  417. (setq eval '(org-with-point-at pom
  418. (let ((org-fast-tag-selection-single-key
  419. (if (eq org-fast-tag-selection-single-key 'expert)
  420. t org-fast-tag-selection-single-key)))
  421. (call-interactively 'org-set-tags)))))
  422. ((equal key "DEADLINE")
  423. (setq eval '(org-with-point-at pom
  424. (call-interactively 'org-deadline))))
  425. ((equal key "SCHEDULED")
  426. (setq eval '(org-with-point-at pom
  427. (call-interactively 'org-schedule))))
  428. ((equal key "BEAMER_env")
  429. (setq eval '(org-with-point-at pom
  430. (call-interactively 'org-beamer-select-environment))))
  431. (t
  432. (setq allowed (org-property-get-allowed-values pom key 'table))
  433. (if allowed
  434. (setq nval (org-icompleting-read
  435. "Value: " allowed nil
  436. (not (get-text-property 0 'org-unrestricted
  437. (caar allowed)))))
  438. (setq nval (read-string "Edit: " value)))
  439. (setq nval (org-trim nval))
  440. (when (not (equal nval value))
  441. (setq eval '(org-entry-put pom key nval)))))
  442. (when eval
  443. (cond
  444. ((equal major-mode 'org-agenda-mode)
  445. (org-columns-eval eval)
  446. ;; The following let preserves the current format, and makes sure
  447. ;; that in only a single file things need to be updated.
  448. (let* ((org-agenda-overriding-columns-format org-columns-current-fmt)
  449. (buffer (marker-buffer pom))
  450. (org-agenda-contributing-files
  451. (list (with-current-buffer buffer
  452. (buffer-file-name (buffer-base-buffer))))))
  453. (org-agenda-columns)))
  454. (t
  455. (let ((inhibit-read-only t))
  456. (org-unmodified
  457. (remove-text-properties
  458. (max (point-min) (1- bol)) eol '(read-only t)))
  459. (unwind-protect
  460. (progn
  461. (setq org-columns-overlays
  462. (org-delete-all line-overlays org-columns-overlays))
  463. (mapc 'delete-overlay line-overlays)
  464. (org-columns-eval eval))
  465. (org-columns-display-here)))
  466. (org-move-to-column col)
  467. (if (and (eq major-mode 'org-mode)
  468. (nth 3 (assoc key org-columns-current-fmt-compiled)))
  469. (org-columns-update key)))))))
  470. (defun org-edit-headline () ; FIXME: this is not columns specific. Make interactive????? Use from agenda????
  471. "Edit the current headline, the part without TODO keyword, TAGS."
  472. (org-back-to-heading)
  473. (when (looking-at org-todo-line-regexp)
  474. (let ((pos (point))
  475. (pre (buffer-substring (match-beginning 0) (match-beginning 3)))
  476. (txt (match-string 3))
  477. (post "")
  478. txt2)
  479. (if (string-match (org-re "[ \t]+:[[:alnum:]:_@#%]+:[ \t]*$") txt)
  480. (setq post (match-string 0 txt)
  481. txt (substring txt 0 (match-beginning 0))))
  482. (setq txt2 (read-string "Edit: " txt))
  483. (when (not (equal txt txt2))
  484. (goto-char pos)
  485. (insert pre txt2 post)
  486. (delete-region (point) (point-at-eol))
  487. (org-set-tags nil t)))))
  488. (defun org-columns-edit-allowed ()
  489. "Edit the list of allowed values for the current property."
  490. (interactive)
  491. (let* ((pom (or (org-get-at-bol 'org-marker)
  492. (org-get-at-bol 'org-hd-marker)
  493. (point)))
  494. (key (get-char-property (point) 'org-columns-key))
  495. (key1 (concat key "_ALL"))
  496. (allowed (org-entry-get pom key1 t))
  497. nval)
  498. ;; FIXME: Cover editing TODO, TAGS etc in-buffer settings.????
  499. ;; FIXME: Write back to #+PROPERTY setting if that is needed.
  500. (setq nval (read-string "Allowed: " allowed))
  501. (org-entry-put
  502. (cond ((marker-position org-entry-property-inherited-from)
  503. org-entry-property-inherited-from)
  504. ((marker-position org-columns-top-level-marker)
  505. org-columns-top-level-marker)
  506. (t pom))
  507. key1 nval)))
  508. (defun org-columns-eval (form)
  509. (let (hidep)
  510. (save-excursion
  511. (beginning-of-line 1)
  512. ;; `next-line' is needed here, because it skips invisible line.
  513. (condition-case nil (org-no-warnings (next-line 1)) (error nil))
  514. (setq hidep (org-at-heading-p 1)))
  515. (eval form)
  516. (and hidep (hide-entry))))
  517. (defun org-columns-previous-allowed-value ()
  518. "Switch to the previous allowed value for this column."
  519. (interactive)
  520. (org-columns-next-allowed-value t))
  521. (defun org-columns-next-allowed-value (&optional previous nth)
  522. "Switch to the next allowed value for this column.
  523. When PREVIOUS is set, go to the previous value. When NTH is
  524. an integer, select that value."
  525. (interactive)
  526. (org-columns-check-computed)
  527. (let* ((col (current-column))
  528. (key (get-char-property (point) 'org-columns-key))
  529. (value (get-char-property (point) 'org-columns-value))
  530. (bol (point-at-bol)) (eol (point-at-eol))
  531. (pom (or (get-text-property bol 'org-hd-marker)
  532. (point))) ; keep despite of compiler waring
  533. (line-overlays
  534. (delq nil (mapcar (lambda (x)
  535. (and (eq (overlay-buffer x) (current-buffer))
  536. (>= (overlay-start x) bol)
  537. (<= (overlay-start x) eol)
  538. x))
  539. org-columns-overlays)))
  540. (allowed (or (org-property-get-allowed-values pom key)
  541. (and (memq
  542. (nth 4 (assoc key org-columns-current-fmt-compiled))
  543. '(checkbox checkbox-n-of-m checkbox-percent))
  544. '("[ ]" "[X]"))
  545. (org-colview-construct-allowed-dates value)))
  546. nval)
  547. (when (integerp nth)
  548. (setq nth (1- nth))
  549. (if (= nth -1) (setq nth 9)))
  550. (when (equal key "ITEM")
  551. (error "Cannot edit item headline from here"))
  552. (unless (or allowed (member key '("SCHEDULED" "DEADLINE")))
  553. (error "Allowed values for this property have not been defined"))
  554. (if (member key '("SCHEDULED" "DEADLINE"))
  555. (setq nval (if previous 'earlier 'later))
  556. (if previous (setq allowed (reverse allowed)))
  557. (cond
  558. (nth
  559. (setq nval (nth nth allowed))
  560. (if (not nval)
  561. (error "There are only %d allowed values for property `%s'"
  562. (length allowed) key)))
  563. ((member value allowed)
  564. (setq nval (or (car (cdr (member value allowed)))
  565. (car allowed)))
  566. (if (equal nval value)
  567. (error "Only one allowed value for this property")))
  568. (t (setq nval (car allowed)))))
  569. (cond
  570. ((equal major-mode 'org-agenda-mode)
  571. (org-columns-eval '(org-entry-put pom key nval))
  572. ;; The following let preserves the current format, and makes sure
  573. ;; that in only a single file things need to be updated.
  574. (let* ((org-agenda-overriding-columns-format org-columns-current-fmt)
  575. (buffer (marker-buffer pom))
  576. (org-agenda-contributing-files
  577. (list (with-current-buffer buffer
  578. (buffer-file-name (buffer-base-buffer))))))
  579. (org-agenda-columns)))
  580. (t
  581. (let ((inhibit-read-only t))
  582. (remove-text-properties (1- bol) eol '(read-only t))
  583. (unwind-protect
  584. (progn
  585. (setq org-columns-overlays
  586. (org-delete-all line-overlays org-columns-overlays))
  587. (mapc 'delete-overlay line-overlays)
  588. (org-columns-eval '(org-entry-put pom key nval)))
  589. (org-columns-display-here)))
  590. (org-move-to-column col)
  591. (and (nth 3 (assoc key org-columns-current-fmt-compiled))
  592. (org-columns-update key))))))
  593. (defun org-colview-construct-allowed-dates (s)
  594. "Construct a list of three dates around the date in S.
  595. This respects the format of the time stamp in S, active or non-active,
  596. and also including time or not. S must be just a time stamp, no text
  597. around it."
  598. (when (and s (string-match (concat "^" org-ts-regexp3 "$") s))
  599. (let* ((time (org-parse-time-string s 'nodefaults))
  600. (active (equal (string-to-char s) ?<))
  601. (fmt (funcall (if (nth 1 time) 'cdr 'car) org-time-stamp-formats))
  602. time-before time-after)
  603. (unless active (setq fmt (concat "[" (substring fmt 1 -1) "]")))
  604. (setf (car time) (or (car time) 0))
  605. (setf (nth 1 time) (or (nth 1 time) 0))
  606. (setf (nth 2 time) (or (nth 2 time) 0))
  607. (setq time-before (copy-sequence time))
  608. (setq time-after (copy-sequence time))
  609. (setf (nth 3 time-before) (1- (nth 3 time)))
  610. (setf (nth 3 time-after) (1+ (nth 3 time)))
  611. (mapcar (lambda (x) (format-time-string fmt (apply 'encode-time x)))
  612. (list time-before time time-after)))))
  613. (defun org-verify-version (task)
  614. (cond
  615. ((eq task 'columns)
  616. (if (or (featurep 'xemacs)
  617. (< emacs-major-version 22))
  618. (error "Emacs 22 is required for the columns feature")))))
  619. (defun org-columns-open-link (&optional arg)
  620. (interactive "P")
  621. (let ((value (get-char-property (point) 'org-columns-value)))
  622. (org-open-link-from-string value arg)))
  623. (defun org-columns-get-format-and-top-level ()
  624. (let (fmt)
  625. (when (condition-case nil (org-back-to-heading) (error nil))
  626. (setq fmt (org-entry-get nil "COLUMNS" t)))
  627. (setq fmt (or fmt org-columns-default-format))
  628. (org-set-local 'org-columns-current-fmt fmt)
  629. (org-columns-compile-format fmt)
  630. (if (marker-position org-entry-property-inherited-from)
  631. (move-marker org-columns-top-level-marker
  632. org-entry-property-inherited-from)
  633. (move-marker org-columns-top-level-marker (point)))
  634. fmt))
  635. (defun org-columns ()
  636. "Turn on column view on an org-mode file."
  637. (interactive)
  638. (org-verify-version 'columns)
  639. (org-columns-remove-overlays)
  640. (move-marker org-columns-begin-marker (point))
  641. (let ((org-columns-time (time-to-number-of-days (current-time)))
  642. beg end fmt cache maxwidths)
  643. (setq fmt (org-columns-get-format-and-top-level))
  644. (save-excursion
  645. (goto-char org-columns-top-level-marker)
  646. (setq beg (point))
  647. (unless org-columns-inhibit-recalculation
  648. (org-columns-compute-all))
  649. (setq end (or (condition-case nil (org-end-of-subtree t t) (error nil))
  650. (point-max)))
  651. ;; Get and cache the properties
  652. (goto-char beg)
  653. (when (assoc "CLOCKSUM" org-columns-current-fmt-compiled)
  654. (save-excursion
  655. (save-restriction
  656. (narrow-to-region beg end)
  657. (org-clock-sum))))
  658. (while (re-search-forward org-outline-regexp-bol end t)
  659. (if (and org-columns-skip-archived-trees
  660. (looking-at (concat ".*:" org-archive-tag ":")))
  661. (org-end-of-subtree t)
  662. (push (cons (org-current-line) (org-entry-properties)) cache)))
  663. (when cache
  664. (setq maxwidths (org-columns-get-autowidth-alist fmt cache))
  665. (org-set-local 'org-columns-current-maxwidths maxwidths)
  666. (org-columns-display-here-title)
  667. (when (org-set-local 'org-columns-flyspell-was-active
  668. (org-bound-and-true-p flyspell-mode))
  669. (flyspell-mode 0))
  670. (unless (local-variable-p 'org-colview-initial-truncate-line-value)
  671. (org-set-local 'org-colview-initial-truncate-line-value
  672. truncate-lines))
  673. (setq truncate-lines t)
  674. (mapc (lambda (x)
  675. (org-goto-line (car x))
  676. (org-columns-display-here (cdr x)))
  677. cache)))))
  678. (eval-when-compile (defvar org-columns-time))
  679. (defvar org-columns-compile-map
  680. '(("none" none +)
  681. (":" add_times +)
  682. ("+" add_numbers +)
  683. ("$" currency +)
  684. ("X" checkbox +)
  685. ("X/" checkbox-n-of-m +)
  686. ("X%" checkbox-percent +)
  687. ("max" max_numbers max)
  688. ("min" min_numbers min)
  689. ("mean" mean_numbers
  690. (lambda (&rest x) (/ (apply '+ x) (float (length x)))))
  691. (":max" max_times max)
  692. (":min" min_times min)
  693. (":mean" mean_times
  694. (lambda (&rest x) (/ (apply '+ x) (float (length x)))))
  695. ("@min" min_age min (lambda (x) (- org-columns-time x)))
  696. ("@max" max_age max (lambda (x) (- org-columns-time x)))
  697. ("@mean" mean_age
  698. (lambda (&rest x) (/ (apply '+ x) (float (length x))))
  699. (lambda (x) (- org-columns-time x)))
  700. ("est+" estimate org-estimate-combine))
  701. "Operator <-> format,function,calc map.
  702. Used to compile/uncompile columns format and completing read in
  703. interactive function `org-columns-new'.
  704. operator string used in #+COLUMNS definition describing the
  705. summary type
  706. format symbol describing summary type selected interactively in
  707. `org-columns-new' and internally in
  708. `org-columns-number-to-string' and
  709. `org-columns-string-to-number'
  710. function called with a list of values as argument to calculate
  711. the summary value
  712. calc function called on every element before summarizing. This is
  713. optional and should only be specified if needed")
  714. (defun org-columns-new (&optional prop title width op fmt fun &rest rest)
  715. "Insert a new column, to the left of the current column."
  716. (interactive)
  717. (let ((editp (and prop (assoc prop org-columns-current-fmt-compiled)))
  718. cell)
  719. (setq prop (org-icompleting-read
  720. "Property: " (mapcar 'list (org-buffer-property-keys t nil t))
  721. nil nil prop))
  722. (setq title (read-string (concat "Column title [" prop "]: ") (or title prop)))
  723. (setq width (read-string "Column width: " (if width (number-to-string width))))
  724. (if (string-match "\\S-" width)
  725. (setq width (string-to-number width))
  726. (setq width nil))
  727. (setq fmt (org-icompleting-read
  728. "Summary [none]: "
  729. (mapcar (lambda (x) (list (symbol-name (cadr x))))
  730. org-columns-compile-map)
  731. nil t))
  732. (setq fmt (intern fmt)
  733. fun (cdr (assoc fmt (mapcar 'cdr org-columns-compile-map))))
  734. (if (eq fmt 'none) (setq fmt nil))
  735. (if editp
  736. (progn
  737. (setcar editp prop)
  738. (setcdr editp (list title width nil fmt nil fun)))
  739. (setq cell (nthcdr (1- (current-column))
  740. org-columns-current-fmt-compiled))
  741. (setcdr cell (cons (list prop title width nil fmt nil
  742. (car fun) (cadr fun))
  743. (cdr cell))))
  744. (org-columns-store-format)
  745. (org-columns-redo)))
  746. (defun org-columns-delete ()
  747. "Delete the column at point from columns view."
  748. (interactive)
  749. (let* ((n (current-column))
  750. (title (nth 1 (nth n org-columns-current-fmt-compiled))))
  751. (when (y-or-n-p
  752. (format "Are you sure you want to remove column \"%s\"? " title))
  753. (setq org-columns-current-fmt-compiled
  754. (delq (nth n org-columns-current-fmt-compiled)
  755. org-columns-current-fmt-compiled))
  756. (org-columns-store-format)
  757. (org-columns-redo)
  758. (if (>= (current-column) (length org-columns-current-fmt-compiled))
  759. (backward-char 1)))))
  760. (defun org-columns-edit-attributes ()
  761. "Edit the attributes of the current column."
  762. (interactive)
  763. (let* ((n (current-column))
  764. (info (nth n org-columns-current-fmt-compiled)))
  765. (apply 'org-columns-new info)))
  766. (defun org-columns-widen (arg)
  767. "Make the column wider by ARG characters."
  768. (interactive "p")
  769. (let* ((n (current-column))
  770. (entry (nth n org-columns-current-fmt-compiled))
  771. (width (or (nth 2 entry)
  772. (cdr (assoc (car entry) org-columns-current-maxwidths)))))
  773. (setq width (max 1 (+ width arg)))
  774. (setcar (nthcdr 2 entry) width)
  775. (org-columns-store-format)
  776. (org-columns-redo)))
  777. (defun org-columns-narrow (arg)
  778. "Make the column narrower by ARG characters."
  779. (interactive "p")
  780. (org-columns-widen (- arg)))
  781. (defun org-columns-move-right ()
  782. "Swap this column with the one to the right."
  783. (interactive)
  784. (let* ((n (current-column))
  785. (cell (nthcdr n org-columns-current-fmt-compiled))
  786. e)
  787. (when (>= n (1- (length org-columns-current-fmt-compiled)))
  788. (error "Cannot shift this column further to the right"))
  789. (setq e (car cell))
  790. (setcar cell (car (cdr cell)))
  791. (setcdr cell (cons e (cdr (cdr cell))))
  792. (org-columns-store-format)
  793. (org-columns-redo)
  794. (forward-char 1)))
  795. (defun org-columns-move-left ()
  796. "Swap this column with the one to the left."
  797. (interactive)
  798. (let* ((n (current-column)))
  799. (when (= n 0)
  800. (error "Cannot shift this column further to the left"))
  801. (backward-char 1)
  802. (org-columns-move-right)
  803. (backward-char 1)))
  804. (defun org-columns-store-format ()
  805. "Store the text version of the current columns format in appropriate place.
  806. This is either in the COLUMNS property of the node starting the current column
  807. display, or in the #+COLUMNS line of the current buffer."
  808. (let (fmt (cnt 0))
  809. (setq fmt (org-columns-uncompile-format org-columns-current-fmt-compiled))
  810. (org-set-local 'org-columns-current-fmt fmt)
  811. (if (marker-position org-columns-top-level-marker)
  812. (save-excursion
  813. (goto-char org-columns-top-level-marker)
  814. (if (and (org-at-heading-p)
  815. (org-entry-get nil "COLUMNS"))
  816. (org-entry-put nil "COLUMNS" fmt)
  817. (goto-char (point-min))
  818. ;; Overwrite all #+COLUMNS lines....
  819. (while (re-search-forward "^#\\+COLUMNS:.*" nil t)
  820. (setq cnt (1+ cnt))
  821. (replace-match (concat "#+COLUMNS: " fmt) t t))
  822. (unless (> cnt 0)
  823. (goto-char (point-min))
  824. (or (org-at-heading-p t) (outline-next-heading))
  825. (let ((inhibit-read-only t))
  826. (insert-before-markers "#+COLUMNS: " fmt "\n")))
  827. (org-set-local 'org-columns-default-format fmt))))))
  828. (defvar org-agenda-overriding-columns-format nil
  829. "When set, overrides any other format definition for the agenda.
  830. Don't set this, this is meant for dynamic scoping.")
  831. (defun org-columns-get-autowidth-alist (s cache)
  832. "Derive the maximum column widths from the format and the cache."
  833. (let ((start 0) rtn)
  834. (while (string-match (org-re "%\\([[:alpha:]][[:alnum:]_-]*\\)") s start)
  835. (push (cons (match-string 1 s) 1) rtn)
  836. (setq start (match-end 0)))
  837. (mapc (lambda (x)
  838. (setcdr x (apply 'max
  839. (mapcar
  840. (lambda (y)
  841. (length (or (cdr (assoc (car x) (cdr y))) " ")))
  842. cache))))
  843. rtn)
  844. rtn))
  845. (defun org-columns-compute-all ()
  846. "Compute all columns that have operators defined."
  847. (org-unmodified
  848. (remove-text-properties (point-min) (point-max) '(org-summaries t)))
  849. (let ((columns org-columns-current-fmt-compiled)
  850. (org-columns-time (time-to-number-of-days (current-time)))
  851. col)
  852. (while (setq col (pop columns))
  853. (when (nth 3 col)
  854. (save-excursion
  855. (org-columns-compute (car col)))))))
  856. (defun org-columns-update (property)
  857. "Recompute PROPERTY, and update the columns display for it."
  858. (org-columns-compute property)
  859. (let (fmt val pos)
  860. (save-excursion
  861. (mapc (lambda (ov)
  862. (when (equal (overlay-get ov 'org-columns-key) property)
  863. (setq pos (overlay-start ov))
  864. (goto-char pos)
  865. (when (setq val (cdr (assoc property
  866. (get-text-property
  867. (point-at-bol) 'org-summaries))))
  868. (setq fmt (overlay-get ov 'org-columns-format))
  869. (overlay-put ov 'org-columns-value val)
  870. (overlay-put ov 'display (format fmt val)))))
  871. org-columns-overlays))))
  872. (defvar org-inlinetask-min-level
  873. (if (featurep 'org-inlinetask) org-inlinetask-min-level 15))
  874. (defun org-columns-compute (property)
  875. "Sum the values of property PROPERTY hierarchically, for the entire buffer."
  876. (interactive)
  877. (let* ((re org-outline-regexp-bol)
  878. (lmax 30) ; Does anyone use deeper levels???
  879. (lvals (make-vector lmax nil))
  880. (lflag (make-vector lmax nil))
  881. (level 0)
  882. (ass (assoc property org-columns-current-fmt-compiled))
  883. (format (nth 4 ass))
  884. (printf (nth 5 ass))
  885. (fun (nth 6 ass))
  886. (calc (or (nth 7 ass) 'identity))
  887. (beg org-columns-top-level-marker)
  888. (inminlevel org-inlinetask-min-level)
  889. (last-level org-inlinetask-min-level)
  890. val valflag flag end sumpos sum-alist sum str str1 useval)
  891. (save-excursion
  892. ;; Find the region to compute
  893. (goto-char beg)
  894. (setq end (condition-case nil (org-end-of-subtree t) (error (point-max))))
  895. (goto-char end)
  896. ;; Walk the tree from the back and do the computations
  897. (while (re-search-backward re beg t)
  898. (setq sumpos (match-beginning 0)
  899. last-level (if (not (or (zerop level) (eq level inminlevel)))
  900. level last-level)
  901. level (org-outline-level)
  902. val (org-entry-get nil property)
  903. valflag (and val (string-match "\\S-" val)))
  904. (cond
  905. ((< level last-level)
  906. ;; put the sum of lower levels here as a property
  907. (setq sum (+ (if (and (/= last-level inminlevel)
  908. (aref lvals last-level))
  909. (apply fun (aref lvals last-level)) 0)
  910. (if (aref lvals inminlevel)
  911. (apply fun (aref lvals inminlevel)) 0))
  912. flag (or (aref lflag last-level) ; any valid entries from children?
  913. (aref lflag inminlevel)) ; or inline tasks?
  914. str (org-columns-number-to-string sum format printf)
  915. str1 (org-add-props (copy-sequence str) nil 'org-computed t 'face 'bold)
  916. useval (if flag str1 (if valflag val ""))
  917. sum-alist (get-text-property sumpos 'org-summaries))
  918. (if (assoc property sum-alist)
  919. (setcdr (assoc property sum-alist) useval)
  920. (push (cons property useval) sum-alist)
  921. (org-unmodified
  922. (add-text-properties sumpos (1+ sumpos)
  923. (list 'org-summaries sum-alist))))
  924. (when (and val (not (equal val (if flag str val))))
  925. (org-entry-put nil property (if flag str val)))
  926. ;; add current to current level accumulator
  927. (when (or flag valflag)
  928. (push (if flag
  929. sum
  930. (funcall calc (org-columns-string-to-number
  931. (if flag str val) format)))
  932. (aref lvals level))
  933. (aset lflag level t))
  934. ;; clear accumulators for deeper levels
  935. (loop for l from (1+ level) to (1- lmax) do
  936. (aset lvals l nil)
  937. (aset lflag l nil)))
  938. ((>= level last-level)
  939. ;; add what we have here to the accumulator for this level
  940. (when valflag
  941. (push (funcall calc (org-columns-string-to-number val format))
  942. (aref lvals level))
  943. (aset lflag level t)))
  944. (t (error "This should not happen")))))))
  945. (defun org-columns-redo ()
  946. "Construct the column display again."
  947. (interactive)
  948. (message "Recomputing columns...")
  949. (let ((line (org-current-line))
  950. (col (current-column)))
  951. (save-excursion
  952. (if (marker-position org-columns-begin-marker)
  953. (goto-char org-columns-begin-marker))
  954. (org-columns-remove-overlays)
  955. (if (eq major-mode 'org-mode)
  956. (call-interactively 'org-columns)
  957. (org-agenda-redo)
  958. (call-interactively 'org-agenda-columns)))
  959. (org-goto-line line)
  960. (move-to-column col))
  961. (message "Recomputing columns...done"))
  962. (defun org-columns-not-in-agenda ()
  963. (if (eq major-mode 'org-agenda-mode)
  964. (error "This command is only allowed in Org-mode buffers")))
  965. (defun org-string-to-number (s)
  966. "Convert string to number, and interpret hh:mm:ss."
  967. (if (not (string-match ":" s))
  968. (string-to-number s)
  969. (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
  970. (while l
  971. (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
  972. sum)))
  973. (defun org-columns-number-to-string (n fmt &optional printf)
  974. "Convert a computed column number to a string value, according to FMT."
  975. (cond
  976. ((memq fmt '(estimate)) (org-estimate-print n printf))
  977. ((not (numberp n)) "")
  978. ((memq fmt '(add_times max_times min_times mean_times))
  979. (let* ((h (floor n)) (m (floor (+ 0.5 (* 60 (- n h))))))
  980. (format org-time-clocksum-format h m)))
  981. ((eq fmt 'checkbox)
  982. (cond ((= n (floor n)) "[X]")
  983. ((> n 1.) "[-]")
  984. (t "[ ]")))
  985. ((memq fmt '(checkbox-n-of-m checkbox-percent))
  986. (let* ((n1 (floor n)) (n2 (floor (+ .5 (* 1000000 (- n n1))))))
  987. (org-nofm-to-completion n1 (+ n2 n1) (eq fmt 'checkbox-percent))))
  988. (printf (format printf n))
  989. ((eq fmt 'currency)
  990. (format "%.2f" n))
  991. ((memq fmt '(min_age max_age mean_age))
  992. (org-format-time-period n))
  993. (t (number-to-string n))))
  994. (defun org-nofm-to-completion (n m &optional percent)
  995. (if (not percent)
  996. (format "[%d/%d]" n m)
  997. (format "[%d%%]"(floor (+ 0.5 (* 100. (/ (* 1.0 n) m)))))))
  998. (defun org-columns-string-to-number (s fmt)
  999. "Convert a column value to a number that can be used for column computing."
  1000. (if s
  1001. (cond
  1002. ((memq fmt '(min_age max_age mean_age))
  1003. (cond ((string= s "") org-columns-time)
  1004. ((string-match
  1005. "\\([0-9]+\\)d \\([0-9]+\\)h \\([0-9]+\\)m \\([0-9]+\\)s"
  1006. s)
  1007. (+ (* 60 (+ (* 60 (+ (* 24 (string-to-number (match-string 1 s)))
  1008. (string-to-number (match-string 2 s))))
  1009. (string-to-number (match-string 3 s))))
  1010. (string-to-number (match-string 4 s))))
  1011. (t (time-to-number-of-days (apply 'encode-time
  1012. (org-parse-time-string s t))))))
  1013. ((string-match ":" s)
  1014. (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
  1015. (while l
  1016. (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
  1017. sum))
  1018. ((memq fmt '(checkbox checkbox-n-of-m checkbox-percent))
  1019. (if (equal s "[X]") 1. 0.000001))
  1020. ((memq fmt '(estimate)) (org-string-to-estimate s))
  1021. (t (string-to-number s)))))
  1022. (defun org-columns-uncompile-format (cfmt)
  1023. "Turn the compiled columns format back into a string representation."
  1024. (let ((rtn "") e s prop title op op-match width fmt printf fun calc)
  1025. (while (setq e (pop cfmt))
  1026. (setq prop (car e)
  1027. title (nth 1 e)
  1028. width (nth 2 e)
  1029. op (nth 3 e)
  1030. fmt (nth 4 e)
  1031. printf (nth 5 e)
  1032. fun (nth 6 e)
  1033. calc (nth 7 e))
  1034. (when (setq op-match (rassoc (list fmt fun calc) org-columns-compile-map))
  1035. (setq op (car op-match)))
  1036. (if (and op printf) (setq op (concat op ";" printf)))
  1037. (if (equal title prop) (setq title nil))
  1038. (setq s (concat "%" (if width (number-to-string width))
  1039. prop
  1040. (if title (concat "(" title ")"))
  1041. (if op (concat "{" op "}"))))
  1042. (setq rtn (concat rtn " " s)))
  1043. (org-trim rtn)))
  1044. (defun org-columns-compile-format (fmt)
  1045. "Turn a column format string into an alist of specifications.
  1046. The alist has one entry for each column in the format. The elements of
  1047. that list are:
  1048. property the property
  1049. title the title field for the columns
  1050. width the column width in characters, can be nil for automatic
  1051. operator the operator if any
  1052. format the output format for computed results, derived from operator
  1053. printf a printf format for computed values
  1054. fun the lisp function to compute summary values, derived from operator
  1055. calc function to get values from base elements"
  1056. (let ((start 0) width prop title op op-match f printf fun calc)
  1057. (setq org-columns-current-fmt-compiled nil)
  1058. (while (string-match
  1059. (org-re "%\\([0-9]+\\)?\\([[:alnum:]_-]+\\)\\(?:(\\([^)]+\\))\\)?\\(?:{\\([^}]+\\)}\\)?\\s-*")
  1060. fmt start)
  1061. (setq start (match-end 0)
  1062. width (match-string 1 fmt)
  1063. prop (match-string 2 fmt)
  1064. title (or (match-string 3 fmt) prop)
  1065. op (match-string 4 fmt)
  1066. f nil
  1067. printf nil
  1068. fun '+
  1069. calc nil)
  1070. (if width (setq width (string-to-number width)))
  1071. (when (and op (string-match ";" op))
  1072. (setq printf (substring op (match-end 0))
  1073. op (substring op 0 (match-beginning 0))))
  1074. (when (setq op-match (assoc op org-columns-compile-map))
  1075. (setq f (cadr op-match)
  1076. fun (caddr op-match)
  1077. calc (cadddr op-match)))
  1078. (push (list prop title width op f printf fun calc)
  1079. org-columns-current-fmt-compiled))
  1080. (setq org-columns-current-fmt-compiled
  1081. (nreverse org-columns-current-fmt-compiled))))
  1082. ;;; Dynamic block for Column view
  1083. (defvar org-heading-regexp) ; defined in org.el
  1084. (defvar org-heading-keyword-regexp-format) ; defined in org.el
  1085. (defun org-columns-capture-view (&optional maxlevel skip-empty-rows)
  1086. "Get the column view of the current buffer or subtree.
  1087. The first optional argument MAXLEVEL sets the level limit. A
  1088. second optional argument SKIP-EMPTY-ROWS tells whether to skip
  1089. empty rows, an empty row being one where all the column view
  1090. specifiers except ITEM are empty. This function returns a list
  1091. containing the title row and all other rows. Each row is a list
  1092. of fields."
  1093. (save-excursion
  1094. (let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
  1095. (re-comment (format org-heading-keyword-regexp-format
  1096. org-comment-string))
  1097. (re-archive (concat ".*:" org-archive-tag ":"))
  1098. (n (length title)) row tbl)
  1099. (goto-char (point-min))
  1100. (while (re-search-forward org-heading-regexp nil t)
  1101. (catch 'next
  1102. (when (and (or (null maxlevel)
  1103. (>= maxlevel
  1104. (if org-odd-levels-only
  1105. (/ (1+ (length (match-string 1))) 2)
  1106. (length (match-string 1)))))
  1107. (get-char-property (match-beginning 0) 'org-columns-key))
  1108. (when (save-excursion
  1109. (goto-char (point-at-bol))
  1110. (or (looking-at re-comment)
  1111. (looking-at re-archive)))
  1112. (org-end-of-subtree t)
  1113. (throw 'next t))
  1114. (setq row nil)
  1115. (loop for i from 0 to (1- n) do
  1116. (push
  1117. (org-quote-vert
  1118. (or (get-char-property (+ (match-beginning 0) i) 'org-columns-value-modified)
  1119. (get-char-property (+ (match-beginning 0) i) 'org-columns-value)
  1120. ""))
  1121. row))
  1122. (setq row (nreverse row))
  1123. (unless (and skip-empty-rows
  1124. (eq 1 (length (delete "" (delete-dups (copy-sequence row))))))
  1125. (push row tbl)))))
  1126. (append (list title 'hline) (nreverse tbl)))))
  1127. (defun org-dblock-write:columnview (params)
  1128. "Write the column view table.
  1129. PARAMS is a property list of parameters:
  1130. :width enforce same column widths with <N> specifiers.
  1131. :id the :ID: property of the entry where the columns view
  1132. should be built. When the symbol `local', call locally.
  1133. When `global' call column view with the cursor at the beginning
  1134. of the buffer (usually this means that the whole buffer switches
  1135. to column view). When \"file:path/to/file.org\", invoke column
  1136. view at the start of that file. Otherwise, the ID is located
  1137. using `org-id-find'.
  1138. :hlines When t, insert a hline before each item. When a number, insert
  1139. a hline before each level <= that number.
  1140. :vlines When t, make each column a colgroup to enforce vertical lines.
  1141. :maxlevel When set to a number, don't capture headlines below this level.
  1142. :skip-empty-rows
  1143. When t, skip rows where all specifiers other than ITEM are empty."
  1144. (let ((pos (move-marker (make-marker) (point)))
  1145. (hlines (plist-get params :hlines))
  1146. (vlines (plist-get params :vlines))
  1147. (maxlevel (plist-get params :maxlevel))
  1148. (content-lines (org-split-string (plist-get params :content) "\n"))
  1149. (skip-empty-rows (plist-get params :skip-empty-rows))
  1150. tbl id idpos nfields tmp recalc line
  1151. id-as-string view-file view-pos)
  1152. (when (setq id (plist-get params :id))
  1153. (setq id-as-string (cond ((numberp id) (number-to-string id))
  1154. ((symbolp id) (symbol-name id))
  1155. ((stringp id) id)
  1156. (t "")))
  1157. (cond ((not id) nil)
  1158. ((eq id 'global) (setq view-pos (point-min)))
  1159. ((eq id 'local))
  1160. ((string-match "^file:\\(.*\\)" id-as-string)
  1161. (setq view-file (match-string 1 id-as-string)
  1162. view-pos 1)
  1163. (unless (file-exists-p view-file)
  1164. (error "No such file: \"%s\"" id-as-string)))
  1165. ((setq idpos (org-find-entry-with-id id))
  1166. (setq view-pos idpos))
  1167. ((setq idpos (org-id-find id))
  1168. (setq view-file (car idpos))
  1169. (setq view-pos (cdr idpos)))
  1170. (t (error "Cannot find entry with :ID: %s" id))))
  1171. (with-current-buffer (if view-file
  1172. (get-file-buffer view-file)
  1173. (current-buffer))
  1174. (save-excursion
  1175. (save-restriction
  1176. (widen)
  1177. (goto-char (or view-pos (point)))
  1178. (org-columns)
  1179. (setq tbl (org-columns-capture-view maxlevel skip-empty-rows))
  1180. (setq nfields (length (car tbl)))
  1181. (org-columns-quit))))
  1182. (goto-char pos)
  1183. (move-marker pos nil)
  1184. (when tbl
  1185. (when (plist-get params :hlines)
  1186. (setq tmp nil)
  1187. (while tbl
  1188. (if (eq (car tbl) 'hline)
  1189. (push (pop tbl) tmp)
  1190. (if (string-match "\\` *\\(\\*+\\)" (caar tbl))
  1191. (if (and (not (eq (car tmp) 'hline))
  1192. (or (eq hlines t)
  1193. (and (numberp hlines)
  1194. (<= (- (match-end 1) (match-beginning 1))
  1195. hlines))))
  1196. (push 'hline tmp)))
  1197. (push (pop tbl) tmp)))
  1198. (setq tbl (nreverse tmp)))
  1199. (when vlines
  1200. (setq tbl (mapcar (lambda (x)
  1201. (if (eq 'hline x) x (cons "" x)))
  1202. tbl))
  1203. (setq tbl (append tbl (list (cons "/" (make-list nfields "<>"))))))
  1204. (setq pos (point))
  1205. (when content-lines
  1206. (while (string-match "^#" (car content-lines))
  1207. (insert (pop content-lines) "\n")))
  1208. (insert (org-listtable-to-string tbl))
  1209. (when (plist-get params :width)
  1210. (insert "\n|" (mapconcat (lambda (x) (format "<%d>" (max 3 x)))
  1211. org-columns-current-widths "|")))
  1212. (while (setq line (pop content-lines))
  1213. (when (string-match "^#" line)
  1214. (insert "\n" line)
  1215. (when (string-match "^[ \t]*#\\+TBLFM" line)
  1216. (setq recalc t))))
  1217. (if recalc
  1218. (progn (goto-char pos) (org-table-recalculate 'all))
  1219. (goto-char pos)
  1220. (org-table-align)))))
  1221. (defun org-listtable-to-string (tbl)
  1222. "Convert a listtable TBL to a string that contains the Org-mode table.
  1223. The table still need to be aligned. The resulting string has no leading
  1224. and tailing newline characters."
  1225. (mapconcat
  1226. (lambda (x)
  1227. (cond
  1228. ((listp x)
  1229. (concat "|" (mapconcat 'identity x "|") "|"))
  1230. ((eq x 'hline) "|-|")
  1231. (t (error "Garbage in listtable: %s" x))))
  1232. tbl "\n"))
  1233. (defun org-insert-columns-dblock ()
  1234. "Create a dynamic block capturing a column view table."
  1235. (interactive)
  1236. (let ((defaults '(:name "columnview" :hlines 1))
  1237. (id (org-icompleting-read
  1238. "Capture columns (local, global, entry with :ID: property) [local]: "
  1239. (append '(("global") ("local"))
  1240. (mapcar 'list (org-property-values "ID"))))))
  1241. (if (equal id "") (setq id 'local))
  1242. (if (equal id "global") (setq id 'global))
  1243. (setq defaults (append defaults (list :id id)))
  1244. (org-create-dblock defaults)
  1245. (org-update-dblock)))
  1246. ;;; Column view in the agenda
  1247. (defvar org-agenda-view-columns-initially nil
  1248. "When set, switch to columns view immediately after creating the agenda.")
  1249. (defvar org-agenda-columns-show-summaries) ; defined in org-agenda.el
  1250. (defvar org-agenda-columns-compute-summary-properties); defined in org-agenda.el
  1251. (defvar org-agenda-columns-add-appointments-to-effort-sum); as well
  1252. (defun org-agenda-columns ()
  1253. "Turn on or update column view in the agenda."
  1254. (interactive)
  1255. (org-verify-version 'columns)
  1256. (org-columns-remove-overlays)
  1257. (move-marker org-columns-begin-marker (point))
  1258. (let ((org-columns-time (time-to-number-of-days (current-time)))
  1259. cache maxwidths m p a d fmt)
  1260. (cond
  1261. ((and (boundp 'org-agenda-overriding-columns-format)
  1262. org-agenda-overriding-columns-format)
  1263. (setq fmt org-agenda-overriding-columns-format)
  1264. (org-set-local 'org-agenda-overriding-columns-format fmt))
  1265. ((setq m (org-get-at-bol 'org-hd-marker))
  1266. (setq fmt (or (org-entry-get m "COLUMNS" t)
  1267. (with-current-buffer (marker-buffer m)
  1268. org-columns-default-format))))
  1269. ((and (boundp 'org-columns-current-fmt)
  1270. (local-variable-p 'org-columns-current-fmt)
  1271. org-columns-current-fmt)
  1272. (setq fmt org-columns-current-fmt))
  1273. ((setq m (next-single-property-change (point-min) 'org-hd-marker))
  1274. (setq m (get-text-property m 'org-hd-marker))
  1275. (setq fmt (or (org-entry-get m "COLUMNS" t)
  1276. (with-current-buffer (marker-buffer m)
  1277. org-columns-default-format)))))
  1278. (setq fmt (or fmt org-columns-default-format))
  1279. (org-set-local 'org-columns-current-fmt fmt)
  1280. (org-columns-compile-format fmt)
  1281. (when org-agenda-columns-compute-summary-properties
  1282. (org-agenda-colview-compute org-columns-current-fmt-compiled))
  1283. (save-excursion
  1284. ;; Get and cache the properties
  1285. (goto-char (point-min))
  1286. (while (not (eobp))
  1287. (when (setq m (or (org-get-at-bol 'org-hd-marker)
  1288. (org-get-at-bol 'org-marker)))
  1289. (setq p (org-entry-properties m))
  1290. (when (or (not (setq a (assoc org-effort-property p)))
  1291. (not (string-match "\\S-" (or (cdr a) ""))))
  1292. ;; OK, the property is not defined. Use appointment duration?
  1293. (when (and org-agenda-columns-add-appointments-to-effort-sum
  1294. (setq d (get-text-property (point) 'duration)))
  1295. (setq d (org-minutes-to-hh:mm-string d))
  1296. (put-text-property 0 (length d) 'face 'org-warning d)
  1297. (push (cons org-effort-property d) p)))
  1298. (push (cons (org-current-line) p) cache))
  1299. (beginning-of-line 2))
  1300. (when cache
  1301. (setq maxwidths (org-columns-get-autowidth-alist fmt cache))
  1302. (org-set-local 'org-columns-current-maxwidths maxwidths)
  1303. (org-columns-display-here-title)
  1304. (when (org-set-local 'org-columns-flyspell-was-active
  1305. (org-bound-and-true-p flyspell-mode))
  1306. (flyspell-mode 0))
  1307. (mapc (lambda (x)
  1308. (org-goto-line (car x))
  1309. (org-columns-display-here (cdr x)))
  1310. cache)
  1311. (when org-agenda-columns-show-summaries
  1312. (org-agenda-colview-summarize cache))))))
  1313. (defun org-agenda-colview-summarize (cache)
  1314. "Summarize the summarizable columns in column view in the agenda.
  1315. This will add overlays to the date lines, to show the summary for each day."
  1316. (let* ((fmt (mapcar (lambda (x)
  1317. (if (equal (car x) "CLOCKSUM")
  1318. (list "CLOCKSUM" (nth 1 x) (nth 2 x) ":" 'add_times
  1319. nil '+ nil)
  1320. x))
  1321. org-columns-current-fmt-compiled))
  1322. line c c1 stype calc sumfunc props lsum entries prop v title)
  1323. (catch 'exit
  1324. (when (delq nil (mapcar 'cadr fmt))
  1325. ;; OK, at least one summation column, it makes sense to try this
  1326. (goto-char (point-max))
  1327. (while t
  1328. (when (or (get-text-property (point) 'org-date-line)
  1329. (eq (get-text-property (point) 'face)
  1330. 'org-agenda-structure))
  1331. ;; OK, this is a date line that should be used
  1332. (setq line (org-current-line))
  1333. (setq entries nil c cache cache nil)
  1334. (while (setq c1 (pop c))
  1335. (if (> (car c1) line)
  1336. (push c1 entries)
  1337. (push c1 cache)))
  1338. ;; now ENTRIES are the ones we want to use, CACHE is the rest
  1339. ;; Compute the summaries for the properties we want,
  1340. ;; set nil properties for the rest.
  1341. (when (setq entries (mapcar 'cdr entries))
  1342. (setq props
  1343. (mapcar
  1344. (lambda (f)
  1345. (setq prop (car f)
  1346. title (nth 1 f)
  1347. stype (nth 4 f)
  1348. sumfunc (nth 6 f)
  1349. calc (or (nth 7 f) 'identity))
  1350. (cond
  1351. ((equal prop "ITEM")
  1352. (cons prop (buffer-substring (point-at-bol)
  1353. (point-at-eol))))
  1354. ((not stype) (cons prop ""))
  1355. (t ;; do the summary
  1356. (setq lsum nil)
  1357. (dolist (x entries)
  1358. (setq v (cdr (assoc prop x)))
  1359. (if v
  1360. (push
  1361. (funcall
  1362. (if (not (get-text-property 0 'org-computed v))
  1363. calc
  1364. 'identity)
  1365. (org-columns-string-to-number
  1366. v stype))
  1367. lsum)))
  1368. (setq lsum (remove nil lsum))
  1369. (setq lsum
  1370. (cond ((> (length lsum) 1)
  1371. (org-columns-number-to-string
  1372. (apply sumfunc lsum) stype))
  1373. ((eq (length lsum) 1)
  1374. (org-columns-number-to-string
  1375. (car lsum) stype))
  1376. (t "")))
  1377. (put-text-property 0 (length lsum) 'face 'bold lsum)
  1378. (unless (eq calc 'identity)
  1379. (put-text-property 0 (length lsum) 'org-computed t lsum))
  1380. (cons prop lsum))))
  1381. fmt))
  1382. (org-columns-display-here props 'dateline)
  1383. (org-set-local 'org-agenda-columns-active t)))
  1384. (if (bobp) (throw 'exit t))
  1385. (beginning-of-line 0))))))
  1386. (defun org-agenda-colview-compute (fmt)
  1387. "Compute the relevant columns in the contributing source buffers."
  1388. (let ((files org-agenda-contributing-files)
  1389. (org-columns-begin-marker (make-marker))
  1390. (org-columns-top-level-marker (make-marker))
  1391. f fm a b)
  1392. (while (setq f (pop files))
  1393. (setq b (find-buffer-visiting f))
  1394. (with-current-buffer (or (buffer-base-buffer b) b)
  1395. (save-excursion
  1396. (save-restriction
  1397. (widen)
  1398. (org-unmodified
  1399. (remove-text-properties (point-min) (point-max)
  1400. '(org-summaries t)))
  1401. (goto-char (point-min))
  1402. (org-columns-get-format-and-top-level)
  1403. (while (setq fm (pop fmt))
  1404. (if (equal (car fm) "CLOCKSUM")
  1405. (org-clock-sum)
  1406. (when (and (nth 4 fm)
  1407. (setq a (assoc (car fm)
  1408. org-columns-current-fmt-compiled))
  1409. (equal (nth 4 a) (nth 4 fm)))
  1410. (org-columns-compute (car fm)))))))))))
  1411. (defun org-format-time-period (interval)
  1412. "Convert time in fractional days to days/hours/minutes/seconds."
  1413. (if (numberp interval)
  1414. (let* ((days (floor interval))
  1415. (frac-hours (* 24 (- interval days)))
  1416. (hours (floor frac-hours))
  1417. (minutes (floor (* 60 (- frac-hours hours))))
  1418. (seconds (floor (* 60 (- (* 60 (- frac-hours hours)) minutes)))))
  1419. (format "%dd %02dh %02dm %02ds" days hours minutes seconds))
  1420. ""))
  1421. (defun org-estimate-mean-and-var (v)
  1422. "Return the mean and variance of an estimate."
  1423. (let* ((low (float (car v)))
  1424. (high (float (cadr v)))
  1425. (mean (/ (+ low high) 2.0))
  1426. (var (/ (+ (expt (- mean low) 2.0) (expt (- high mean) 2.0)) 2.0)))
  1427. (list mean var)))
  1428. (defun org-estimate-combine (&rest el)
  1429. "Combine a list of estimates, using mean and variance.
  1430. The mean and variance of the result will be the sum of the means
  1431. and variances (respectively) of the individual estimates."
  1432. (let ((mean 0)
  1433. (var 0))
  1434. (mapc (lambda (e)
  1435. (let ((stats (org-estimate-mean-and-var e)))
  1436. (setq mean (+ mean (car stats)))
  1437. (setq var (+ var (cadr stats)))))
  1438. el)
  1439. (let ((stdev (sqrt var)))
  1440. (list (- mean stdev) (+ mean stdev)))))
  1441. (defun org-estimate-print (e &optional fmt)
  1442. "Prepare a string representation of an estimate.
  1443. This formats these numbers as two numbers with a \"-\" between them."
  1444. (if (null fmt) (set 'fmt "%.0f"))
  1445. (format "%s" (mapconcat (lambda (n) (format fmt n)) e "-")))
  1446. (defun org-string-to-estimate (s)
  1447. "Convert a string to an estimate.
  1448. The string should be two numbers joined with a \"-\"."
  1449. (if (string-match "\\(.*\\)-\\(.*\\)" s)
  1450. (list (string-to-number (match-string 1 s))
  1451. (string-to-number(match-string 2 s)))
  1452. (list (string-to-number s) (string-to-number s))))
  1453. (provide 'org-colview)
  1454. ;;; org-colview.el ends here