org-colview.el 60 KB

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