org-colview.el 59 KB

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