org-colview-xemacs.el 61 KB

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