org-colview-xemacs.el 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  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.24c
  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. (defun org-columns-remove-overlays ()
  429. "Remove all currently active column overlays."
  430. (interactive)
  431. (when (marker-buffer org-columns-begin-marker)
  432. (with-current-buffer (marker-buffer org-columns-begin-marker)
  433. (when (local-variable-p 'org-previous-header-line-format (current-buffer))
  434. (if (featurep 'xemacs)
  435. (set-specifier top-gutter
  436. (make-gutter-specifier
  437. (cons (current-buffer)
  438. (cdar org-previous-header-line-format))))
  439. (setq header-line-format org-previous-header-line-format)
  440. (remove-hook 'post-command-hook 'org-columns-hscoll-title 'local))
  441. (kill-local-variable 'org-previous-header-line-format))
  442. (move-marker org-columns-begin-marker nil)
  443. (move-marker org-columns-top-level-marker nil)
  444. (org-unmodified
  445. (mapc 'org-delete-overlay org-columns-overlays)
  446. (setq org-columns-overlays nil)
  447. (let ((inhibit-read-only t))
  448. (remove-text-properties (point-min) (point-max) '(read-only t)))))))
  449. (defun org-columns-cleanup-item (item fmt)
  450. "Remove from ITEM what is a column in the format FMT."
  451. (if (not org-complex-heading-regexp)
  452. item
  453. (when (string-match org-complex-heading-regexp item)
  454. (setq item
  455. (concat
  456. (org-add-props (match-string 1 item) nil
  457. 'org-whitespace (* 2 (1- (org-reduced-level (- (match-end 1) (match-beginning 1))))))
  458. (and (match-end 2) (not (assoc "TODO" fmt)) (concat " " (match-string 2 item)))
  459. (and (match-end 3) (not (assoc "PRIORITY" fmt)) (concat " " (match-string 3 item)))
  460. " " (save-match-data (org-columns-compact-links (match-string 4 item)))
  461. (and (match-end 5) (not (assoc "TAGS" fmt)) (concat " " (match-string 5 item)))))
  462. (add-text-properties
  463. 0 (1+ (match-end 1))
  464. (list 'org-whitespace (* 2 (1- (org-reduced-level (- (match-end 1) (match-beginning 1))))))
  465. item)
  466. item)))
  467. (defun org-columns-compact-links (s)
  468. "Replace [[link][desc]] with [desc] or [link]."
  469. (while (string-match org-bracket-link-regexp s)
  470. (setq s (replace-match
  471. (concat "[" (match-string (if (match-end 3) 3 1) s) "]")
  472. t t s)))
  473. s)
  474. (defvar org-agenda-columns-remove-prefix-from-item)
  475. (defun org-agenda-columns-cleanup-item (item pl cphr fmt)
  476. "Cleanup the time property for agenda column view.
  477. See also the variable `org-agenda-columns-remove-prefix-from-item'."
  478. (let* ((org-complex-heading-regexp cphr)
  479. (prefix (substring item 0 pl))
  480. (rest (substring item pl))
  481. (fake (concat "* " rest))
  482. (cleaned (org-trim (substring (org-columns-cleanup-item fake fmt) 1))))
  483. (if org-agenda-columns-remove-prefix-from-item
  484. cleaned
  485. (concat prefix cleaned))))
  486. (defun org-columns-show-value ()
  487. "Show the full value of the property."
  488. (interactive)
  489. (let ((value (get-char-property (point) 'org-columns-value)))
  490. (message "Value is: %s" (or value ""))))
  491. (defvar org-agenda-columns-active) ;; defined in org-agenda.el
  492. (defun org-columns-quit ()
  493. "Remove the column overlays and in this way exit column editing."
  494. (interactive)
  495. (org-unmodified
  496. (org-columns-remove-overlays)
  497. (let ((inhibit-read-only t))
  498. (remove-text-properties (point-min) (point-max) '(read-only t))))
  499. (when (eq major-mode 'org-agenda-mode)
  500. (setq org-agenda-columns-active nil)
  501. (message
  502. "Modification not yet reflected in Agenda buffer, use `r' to refresh")))
  503. (defun org-columns-check-computed ()
  504. "Check if this column value is computed.
  505. If yes, throw an error indicating that changing it does not make sense."
  506. (let ((val (get-char-property (point) 'org-columns-value)))
  507. (when (and (stringp val)
  508. (get-char-property 0 'org-computed val))
  509. (error "This value is computed from the entry's children"))))
  510. (defun org-columns-todo (&optional arg)
  511. "Change the TODO state during column view."
  512. (interactive "P")
  513. (org-columns-edit-value "TODO"))
  514. (defun org-columns-set-tags-or-toggle (&optional arg)
  515. "Toggle checkbox at point, or set tags for current headline."
  516. (interactive "P")
  517. (if (string-match "\\`\\[[ xX-]\\]\\'"
  518. (get-char-property (point) 'org-columns-value))
  519. (org-columns-next-allowed-value)
  520. (org-columns-edit-value "TAGS")))
  521. (defun org-columns-edit-value (&optional key)
  522. "Edit the value of the property at point in column view.
  523. Where possible, use the standard interface for changing this line."
  524. (interactive)
  525. (org-columns-check-computed)
  526. (let* ((col (current-column))
  527. (key (or key (get-char-property (point) 'org-columns-key)))
  528. (value (get-char-property (point) 'org-columns-value))
  529. (bol (point-at-bol)) (eol (point-at-eol))
  530. (pom (or (get-text-property bol 'org-hd-marker)
  531. (point))) ; keep despite of compiler warning
  532. (line-overlays
  533. (delq nil (mapcar (lambda (x)
  534. (and (eq (org-overlay-buffer x) (current-buffer))
  535. (>= (org-overlay-start x) bol)
  536. (<= (org-overlay-start x) eol)
  537. x))
  538. org-columns-overlays)))
  539. nval eval allowed)
  540. (cond
  541. ((equal key "CLOCKSUM")
  542. (error "This special column cannot be edited"))
  543. ((equal key "ITEM")
  544. (setq eval '(org-with-point-at pom (org-edit-headline))))
  545. ((equal key "TODO")
  546. (setq eval '(org-with-point-at
  547. pom
  548. (call-interactively 'org-todo))))
  549. ((equal key "PRIORITY")
  550. (setq eval '(org-with-point-at pom
  551. (call-interactively 'org-priority))))
  552. ((equal key "TAGS")
  553. (setq eval '(org-with-point-at
  554. pom
  555. (let ((org-fast-tag-selection-single-key
  556. (if (eq org-fast-tag-selection-single-key 'expert)
  557. t org-fast-tag-selection-single-key)))
  558. (call-interactively 'org-set-tags)))))
  559. ((equal key "DEADLINE")
  560. (setq eval '(org-with-point-at
  561. pom
  562. (call-interactively 'org-deadline))))
  563. ((equal key "SCHEDULED")
  564. (setq eval '(org-with-point-at
  565. pom
  566. (call-interactively 'org-schedule))))
  567. (t
  568. (setq allowed (org-property-get-allowed-values pom key 'table))
  569. (if allowed
  570. (setq nval (org-ido-completing-read "Value: " allowed nil t))
  571. (setq nval (read-string "Edit: " value)))
  572. (setq nval (org-trim nval))
  573. (when (not (equal nval value))
  574. (setq eval '(org-entry-put pom key nval)))))
  575. (when eval
  576. (cond
  577. ((equal major-mode 'org-agenda-mode)
  578. (org-columns-eval eval)
  579. ;; The following let preserves the current format, and makes sure
  580. ;; that in only a single file things need to be upated.
  581. (let* ((org-agenda-overriding-columns-format org-columns-current-fmt)
  582. (buffer (marker-buffer pom))
  583. (org-agenda-contributing-files
  584. (list (with-current-buffer buffer
  585. (buffer-file-name (buffer-base-buffer))))))
  586. (org-agenda-columns)))
  587. (t
  588. (let ((inhibit-read-only t))
  589. (org-unmodified
  590. (remove-text-properties
  591. (max (point-min) (1- bol)) eol '(read-only t)))
  592. (unwind-protect
  593. (progn
  594. (setq org-columns-overlays
  595. (org-delete-all line-overlays org-columns-overlays))
  596. (mapc 'org-delete-overlay line-overlays)
  597. (org-columns-eval eval))
  598. (org-columns-display-here)))
  599. (org-move-to-column col)
  600. (if (and (org-mode-p)
  601. (nth 3 (assoc key org-columns-current-fmt-compiled)))
  602. (org-columns-update key)))))))
  603. (defun org-edit-headline () ; FIXME: this is not columns specific. Make interactive????? Use from agenda????
  604. "Edit the current headline, the part without TODO keyword, TAGS."
  605. (org-back-to-heading)
  606. (when (looking-at org-todo-line-regexp)
  607. (let ((pos (point))
  608. (pre (buffer-substring (match-beginning 0) (match-beginning 3)))
  609. (txt (match-string 3))
  610. (post "")
  611. txt2)
  612. (if (string-match (org-re "[ \t]+:[[:alnum:]:_@]+:[ \t]*$") txt)
  613. (setq post (match-string 0 txt)
  614. txt (substring txt 0 (match-beginning 0))))
  615. (setq txt2 (read-string "Edit: " txt))
  616. (when (not (equal txt txt2))
  617. (goto-char pos)
  618. (insert pre txt2 post)
  619. (delete-region (point) (point-at-eol))
  620. (org-set-tags nil t)))))
  621. (defun org-columns-edit-allowed ()
  622. "Edit the list of allowed values for the current property."
  623. (interactive)
  624. (let* ((pom (or (get-text-property (point-at-bol) 'org-marker)
  625. (get-text-property (point-at-bol) 'org-hd-marker)
  626. (point)))
  627. (key (get-char-property (point) 'org-columns-key))
  628. (key1 (concat key "_ALL"))
  629. (allowed (org-entry-get pom key1 t))
  630. nval)
  631. ;; FIXME: Cover editing TODO, TAGS etc in-buffer settings.????
  632. ;; FIXME: Write back to #+PROPERTY setting if that is needed.
  633. (setq nval (read-string "Allowed: " allowed))
  634. (org-entry-put
  635. (cond ((marker-position org-entry-property-inherited-from)
  636. org-entry-property-inherited-from)
  637. ((marker-position org-columns-top-level-marker)
  638. org-columns-top-level-marker)
  639. (t pom))
  640. key1 nval)))
  641. (defun org-columns-eval (form)
  642. (let (hidep)
  643. (save-excursion
  644. (beginning-of-line 1)
  645. ;; `next-line' is needed here, because it skips invisible line.
  646. (condition-case nil (org-no-warnings (next-line 1)) (error nil))
  647. (setq hidep (org-on-heading-p 1)))
  648. (eval form)
  649. (and hidep (hide-entry))))
  650. (defun org-columns-previous-allowed-value ()
  651. "Switch to the previous allowed value for this column."
  652. (interactive)
  653. (org-columns-next-allowed-value t))
  654. (defun org-columns-next-allowed-value (&optional previous nth)
  655. "Switch to the next allowed value for this column.
  656. When PREVIOUS is set, go to the previous value. When NTH is
  657. an integer, select that value."
  658. (interactive)
  659. (org-columns-check-computed)
  660. (let* ((col (current-column))
  661. (key (get-char-property (point) 'org-columns-key))
  662. (value (get-char-property (point) 'org-columns-value))
  663. (bol (point-at-bol)) (eol (point-at-eol))
  664. (pom (or (get-text-property bol 'org-hd-marker)
  665. (point))) ; keep despite of compiler waring
  666. (line-overlays
  667. (delq nil (mapcar (lambda (x)
  668. (and (eq (org-overlay-buffer x) (current-buffer))
  669. (>= (org-overlay-start x) bol)
  670. (<= (org-overlay-start x) eol)
  671. x))
  672. org-columns-overlays)))
  673. (allowed (or (org-property-get-allowed-values pom key)
  674. (and (memq
  675. (nth 4 (assoc key org-columns-current-fmt-compiled))
  676. '(checkbox checkbox-n-of-m checkbox-percent))
  677. '("[ ]" "[X]"))
  678. (org-colview-construct-allowed-dates value)))
  679. nval)
  680. (when (integerp nth)
  681. (setq nth (1- nth))
  682. (if (= nth -1) (setq nth 9)))
  683. (when (equal key "ITEM")
  684. (error "Cannot edit item headline from here"))
  685. (unless (or allowed (member key '("SCHEDULED" "DEADLINE")))
  686. (error "Allowed values for this property have not been defined"))
  687. (if (member key '("SCHEDULED" "DEADLINE"))
  688. (setq nval (if previous 'earlier 'later))
  689. (if previous (setq allowed (reverse allowed)))
  690. (cond
  691. (nth
  692. (setq nval (nth nth allowed))
  693. (if (not nval)
  694. (error "There are only %d allowed values for property `%s'"
  695. (length allowed) key)))
  696. ((member value allowed)
  697. (setq nval (or (car (cdr (member value allowed)))
  698. (car allowed)))
  699. (if (equal nval value)
  700. (error "Only one allowed value for this property")))
  701. (t (setq nval (car allowed)))))
  702. (cond
  703. ((equal major-mode 'org-agenda-mode)
  704. (org-columns-eval '(org-entry-put pom key nval))
  705. ;; The following let preserves the current format, and makes sure
  706. ;; that in only a single file things need to be upated.
  707. (let* ((org-agenda-overriding-columns-format org-columns-current-fmt)
  708. (buffer (marker-buffer pom))
  709. (org-agenda-contributing-files
  710. (list (with-current-buffer buffer
  711. (buffer-file-name (buffer-base-buffer))))))
  712. (org-agenda-columns)))
  713. (t
  714. (let ((inhibit-read-only t))
  715. (remove-text-properties (1- bol) eol '(read-only t))
  716. (unwind-protect
  717. (progn
  718. (setq org-columns-overlays
  719. (org-delete-all line-overlays org-columns-overlays))
  720. (mapc 'org-delete-overlay line-overlays)
  721. (org-columns-eval '(org-entry-put pom key nval)))
  722. (org-columns-display-here)))
  723. (org-move-to-column col)
  724. (and (nth 3 (assoc key org-columns-current-fmt-compiled))
  725. (org-columns-update key))))))
  726. (defun org-colview-construct-allowed-dates (s)
  727. "Construct a list of three dates around the date in S.
  728. This respects the format of the time stamp in S, active or non-active,
  729. and also including time or not. S must be just a time stamp, no text
  730. around it."
  731. (when (and s (string-match (concat "^" org-ts-regexp3 "$") s))
  732. (let* ((time (org-parse-time-string s 'nodefaults))
  733. (active (equal (string-to-char s) ?<))
  734. (fmt (funcall (if (nth 1 time) 'cdr 'car) org-time-stamp-formats))
  735. time-before time-after)
  736. (unless active (setq fmt (concat "[" (substring fmt 1 -1) "]")))
  737. (setf (car time) (or (car time) 0))
  738. (setf (nth 1 time) (or (nth 1 time) 0))
  739. (setf (nth 2 time) (or (nth 2 time) 0))
  740. (setq time-before (copy-sequence time))
  741. (setq time-after (copy-sequence time))
  742. (setf (nth 3 time-before) (1- (nth 3 time)))
  743. (setf (nth 3 time-after) (1+ (nth 3 time)))
  744. (mapcar (lambda (x) (format-time-string fmt (apply 'encode-time x)))
  745. (list time-before time time-after)))))
  746. (defun org-verify-version (task)
  747. (cond
  748. ((eq task 'columns)
  749. (if (or (and (featurep 'xemacs) (not (featurep 'org-colview-xemacs)))
  750. (and (not (featurep 'xemacs)) (< emacs-major-version 22)))
  751. (error "This version of Emacs cannot run Column View")))))
  752. (defun org-columns-open-link (&optional arg)
  753. (interactive "P")
  754. (let ((value (get-char-property (point) 'org-columns-value)))
  755. (org-open-link-from-string value arg)))
  756. (defun org-columns-get-format-and-top-level ()
  757. (let (fmt)
  758. (when (condition-case nil (org-back-to-heading) (error nil))
  759. (setq fmt (org-entry-get nil "COLUMNS" t)))
  760. (setq fmt (or fmt org-columns-default-format))
  761. (org-set-local 'org-columns-current-fmt fmt)
  762. (org-columns-compile-format fmt)
  763. (if (marker-position org-entry-property-inherited-from)
  764. (move-marker org-columns-top-level-marker
  765. org-entry-property-inherited-from)
  766. (move-marker org-columns-top-level-marker (point)))
  767. fmt))
  768. (defun org-columns ()
  769. "Turn on column view on an org-mode file."
  770. (interactive)
  771. (org-verify-version 'columns)
  772. (when (featurep 'xemacs)
  773. (set-face-foreground 'org-columns-space
  774. (face-background 'org-columns-space)))
  775. (org-columns-remove-overlays)
  776. (move-marker org-columns-begin-marker (point))
  777. (let (beg end fmt cache maxwidths)
  778. (setq fmt (org-columns-get-format-and-top-level))
  779. (save-excursion
  780. (goto-char org-columns-top-level-marker)
  781. (setq beg (point))
  782. (unless org-columns-inhibit-recalculation
  783. (org-columns-compute-all))
  784. (setq end (or (condition-case nil (org-end-of-subtree t t) (error nil))
  785. (point-max)))
  786. ;; Get and cache the properties
  787. (goto-char beg)
  788. (when (assoc "CLOCKSUM" org-columns-current-fmt-compiled)
  789. (save-excursion
  790. (save-restriction
  791. (narrow-to-region beg end)
  792. (org-clock-sum))))
  793. (while (re-search-forward (concat "^" outline-regexp) end t)
  794. (push (cons (org-current-line) (org-entry-properties)) cache))
  795. (when cache
  796. (setq maxwidths (org-columns-get-autowidth-alist fmt cache))
  797. (org-set-local 'org-columns-current-maxwidths maxwidths)
  798. (org-columns-display-here-title)
  799. (mapc (lambda (x)
  800. (goto-line (car x))
  801. (org-columns-display-here (cdr x)))
  802. cache)))))
  803. (defun org-columns-new (&optional prop title width op fmt &rest rest)
  804. "Insert a new column, to the left of the current column."
  805. (interactive)
  806. (let ((n (org-columns-current-column))
  807. (editp (and prop (assoc prop org-columns-current-fmt-compiled)))
  808. cell)
  809. (setq prop (org-ido-completing-read
  810. "Property: " (mapcar 'list (org-buffer-property-keys t nil t))
  811. nil nil prop))
  812. (setq title (read-string (concat "Column title [" prop "]: ") (or title prop)))
  813. (setq width (read-string "Column width: " (if width (number-to-string width))))
  814. (if (string-match "\\S-" width)
  815. (setq width (string-to-number width))
  816. (setq width nil))
  817. (setq fmt (org-ido-completing-read "Summary [none]: "
  818. '(("none") ("add_numbers") ("currency") ("add_times") ("checkbox") ("checkbox-n-of-m") ("checkbox-percent"))
  819. nil t))
  820. (if (string-match "\\S-" fmt)
  821. (setq fmt (intern fmt))
  822. (setq fmt nil))
  823. (if (eq fmt 'none) (setq fmt nil))
  824. (if editp
  825. (progn
  826. (setcar editp prop)
  827. (setcdr editp (list title width nil fmt)))
  828. (setq cell (nthcdr (1- n) org-columns-current-fmt-compiled))
  829. (setcdr cell (cons (list prop title width nil fmt)
  830. (cdr cell))))
  831. (org-columns-store-format)
  832. (org-columns-redo)))
  833. (defun org-columns-delete ()
  834. "Delete the column at point from columns view."
  835. (interactive)
  836. (let* ((n (org-columns-current-column))
  837. (title (nth 1 (nth n org-columns-current-fmt-compiled))))
  838. (when (y-or-n-p
  839. (format "Are you sure you want to remove column \"%s\"? " title))
  840. (setq org-columns-current-fmt-compiled
  841. (delq (nth n org-columns-current-fmt-compiled)
  842. org-columns-current-fmt-compiled))
  843. (org-columns-store-format)
  844. (org-columns-redo)
  845. (if (>= (org-columns-current-column)
  846. (length org-columns-current-fmt-compiled))
  847. (org-columns-backward-char)))))
  848. (defun org-columns-edit-attributes ()
  849. "Edit the attributes of the current column."
  850. (interactive)
  851. (let* ((n (org-columns-current-column))
  852. (info (nth n org-columns-current-fmt-compiled)))
  853. (apply 'org-columns-new info)))
  854. (defun org-columns-widen (arg)
  855. "Make the column wider by ARG characters."
  856. (interactive "p")
  857. (let* ((n (org-columns-current-column))
  858. (entry (nth n org-columns-current-fmt-compiled))
  859. (width (or (nth 2 entry)
  860. (cdr (assoc (car entry) org-columns-current-maxwidths)))))
  861. (setq width (max 1 (+ width arg)))
  862. (setcar (nthcdr 2 entry) width)
  863. (org-columns-store-format)
  864. (org-columns-redo)))
  865. (defun org-columns-narrow (arg)
  866. "Make the column narrower by ARG characters."
  867. (interactive "p")
  868. (org-columns-widen (- arg)))
  869. (defun org-columns-move-right ()
  870. "Swap this column with the one to the right."
  871. (interactive)
  872. (let* ((n (org-columns-current-column))
  873. (cell (nthcdr n org-columns-current-fmt-compiled))
  874. e)
  875. (when (>= n (1- (length org-columns-current-fmt-compiled)))
  876. (error "Cannot shift this column further to the right"))
  877. (setq e (car cell))
  878. (setcar cell (car (cdr cell)))
  879. (setcdr cell (cons e (cdr (cdr cell))))
  880. (org-columns-store-format)
  881. (org-columns-redo)
  882. (org-columns-forward-char)))
  883. (defun org-columns-move-left ()
  884. "Swap this column with the one to the left."
  885. (interactive)
  886. (let* ((n (org-columns-current-column)))
  887. (when (= n 0)
  888. (error "Cannot shift this column further to the left"))
  889. (org-columns-backward-char)
  890. (org-columns-move-right)
  891. (org-columns-backward-char)))
  892. (defun org-columns-store-format ()
  893. "Store the text version of the current columns format in appropriate place.
  894. This is either in the COLUMNS property of the node starting the current column
  895. display, or in the #+COLUMNS line of the current buffer."
  896. (let (fmt (cnt 0))
  897. (setq fmt (org-columns-uncompile-format org-columns-current-fmt-compiled))
  898. (org-set-local 'org-columns-current-fmt fmt)
  899. (if (marker-position org-columns-top-level-marker)
  900. (save-excursion
  901. (goto-char org-columns-top-level-marker)
  902. (if (and (org-at-heading-p)
  903. (org-entry-get nil "COLUMNS"))
  904. (org-entry-put nil "COLUMNS" fmt)
  905. (goto-char (point-min))
  906. ;; Overwrite all #+COLUMNS lines....
  907. (while (re-search-forward "^#\\+COLUMNS:.*" nil t)
  908. (setq cnt (1+ cnt))
  909. (replace-match (concat "#+COLUMNS: " fmt) t t))
  910. (unless (> cnt 0)
  911. (goto-char (point-min))
  912. (or (org-on-heading-p t) (outline-next-heading))
  913. (let ((inhibit-read-only t))
  914. (insert-before-markers "#+COLUMNS: " fmt "\n")))
  915. (org-set-local 'org-columns-default-format fmt))))))
  916. (defvar org-agenda-overriding-columns-format nil
  917. "When set, overrides any other format definition for the agenda.
  918. Don't set this, this is meant for dynamic scoping.")
  919. (defun org-columns-get-autowidth-alist (s cache)
  920. "Derive the maximum column widths from the format and the cache."
  921. (let ((start 0) rtn)
  922. (while (string-match (org-re "%\\([[:alpha:]][[:alnum:]_-]*\\)") s start)
  923. (push (cons (match-string 1 s) 1) rtn)
  924. (setq start (match-end 0)))
  925. (mapc (lambda (x)
  926. (setcdr x (apply 'max
  927. (mapcar
  928. (lambda (y)
  929. (length (or (cdr (assoc (car x) (cdr y))) " ")))
  930. cache))))
  931. rtn)
  932. rtn))
  933. (defun org-columns-compute-all ()
  934. "Compute all columns that have operators defined."
  935. (org-unmodified
  936. (remove-text-properties (point-min) (point-max) '(org-summaries t)))
  937. (let ((columns org-columns-current-fmt-compiled) col)
  938. (while (setq col (pop columns))
  939. (when (nth 3 col)
  940. (save-excursion
  941. (org-columns-compute (car col)))))))
  942. (defun org-columns-update (property)
  943. "Recompute PROPERTY, and update the columns display for it."
  944. (org-columns-compute property)
  945. (let (fmt val pos face)
  946. (save-excursion
  947. (mapc (lambda (ov)
  948. (when (equal (org-overlay-get ov 'org-columns-key) property)
  949. (setq pos (org-overlay-start ov))
  950. (goto-char pos)
  951. (when (setq val (cdr (assoc property
  952. (get-text-property
  953. (point-at-bol) 'org-summaries))))
  954. (setq fmt (org-overlay-get ov 'org-columns-format))
  955. (org-overlay-put ov 'org-columns-value val)
  956. (if (featurep 'xemacs)
  957. (progn
  958. (setq face (glyph-face (extent-end-glyph ov)))
  959. (org-overlay-display ov (format fmt val) face))
  960. (org-overlay-display ov (format fmt val))))))
  961. org-columns-overlays))))
  962. (defun org-columns-compute (property)
  963. "Sum the values of property PROPERTY hierarchically, for the entire buffer."
  964. (interactive)
  965. (let* ((re (concat "^" outline-regexp))
  966. (lmax 30) ; Does anyone use deeper levels???
  967. (lsum (make-vector lmax 0))
  968. (lflag (make-vector lmax nil))
  969. (level 0)
  970. (ass (assoc property org-columns-current-fmt-compiled))
  971. (format (nth 4 ass))
  972. (printf (nth 5 ass))
  973. (beg org-columns-top-level-marker)
  974. last-level val valflag flag end sumpos sum-alist sum str str1 useval)
  975. (save-excursion
  976. ;; Find the region to compute
  977. (goto-char beg)
  978. (setq end (condition-case nil (org-end-of-subtree t) (error (point-max))))
  979. (goto-char end)
  980. ;; Walk the tree from the back and do the computations
  981. (while (re-search-backward re beg t)
  982. (setq sumpos (match-beginning 0)
  983. last-level level
  984. level (org-outline-level)
  985. val (org-entry-get nil property)
  986. valflag (and val (string-match "\\S-" val)))
  987. (cond
  988. ((< level last-level)
  989. ;; put the sum of lower levels here as a property
  990. (setq sum (aref lsum last-level) ; current sum
  991. flag (aref lflag last-level) ; any valid entries from children?
  992. str (org-columns-number-to-string sum format printf)
  993. str1 (org-add-props (copy-sequence str) nil 'org-computed t 'face 'bold)
  994. useval (if flag str1 (if valflag val ""))
  995. sum-alist (get-text-property sumpos 'org-summaries))
  996. (if (assoc property sum-alist)
  997. (setcdr (assoc property sum-alist) useval)
  998. (push (cons property useval) sum-alist)
  999. (org-unmodified
  1000. (add-text-properties sumpos (1+ sumpos)
  1001. (list 'org-summaries sum-alist))))
  1002. (when (and val (not (equal val (if flag str val))))
  1003. (org-entry-put nil property (if flag str val)))
  1004. ;; add current to current level accumulator
  1005. (when (or flag valflag)
  1006. (aset lsum level (+ (aref lsum level)
  1007. (if flag sum (org-column-string-to-number
  1008. (if flag str val) format))))
  1009. (aset lflag level t))
  1010. ;; clear accumulators for deeper levels
  1011. (loop for l from (1+ level) to (1- lmax) do
  1012. (aset lsum l 0)
  1013. (aset lflag l nil)))
  1014. ((>= level last-level)
  1015. ;; add what we have here to the accumulator for this level
  1016. (aset lsum level (+ (aref lsum level)
  1017. (org-column-string-to-number (or val "0") format)))
  1018. (and valflag (aset lflag level t)))
  1019. (t (error "This should not happen")))))))
  1020. (defun org-columns-redo ()
  1021. "Construct the column display again."
  1022. (interactive)
  1023. (message "Recomputing columns...")
  1024. (save-excursion
  1025. (if (marker-position org-columns-begin-marker)
  1026. (goto-char org-columns-begin-marker))
  1027. (org-columns-remove-overlays)
  1028. (if (org-mode-p)
  1029. (call-interactively 'org-columns)
  1030. (org-agenda-redo)
  1031. (call-interactively 'org-agenda-columns)))
  1032. (when (featurep 'xemacs)
  1033. (while (not (or (eolp)
  1034. (member (extent-at (point)) org-columns-overlays)))
  1035. (forward-char)))
  1036. (message "Recomputing columns...done"))
  1037. (defun org-columns-not-in-agenda ()
  1038. (if (eq major-mode 'org-agenda-mode)
  1039. (error "This command is only allowed in Org-mode buffers")))
  1040. (defun org-string-to-number (s)
  1041. "Convert string to number, and interpret hh:mm:ss."
  1042. (if (not (string-match ":" s))
  1043. (string-to-number s)
  1044. (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
  1045. (while l
  1046. (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
  1047. sum)))
  1048. (defun org-columns-number-to-string (n fmt &optional printf)
  1049. "Convert a computed column number to a string value, according to FMT."
  1050. (cond
  1051. ((eq fmt 'add_times)
  1052. (let* ((h (floor n)) (m (floor (+ 0.5 (* 60 (- n h))))))
  1053. (format org-time-clocksum-format h m)))
  1054. ((eq fmt 'checkbox)
  1055. (cond ((= n (floor n)) "[X]")
  1056. ((> n 1.) "[-]")
  1057. (t "[ ]")))
  1058. ((memq fmt '(checkbox-n-of-m checkbox-percent))
  1059. (let* ((n1 (floor n)) (n2 (floor (+ .5 (* 1000000 (- n n1))))))
  1060. (org-nofm-to-completion n1 (+ n2 n1) (eq fmt 'checkbox-percent))))
  1061. (printf (format printf n))
  1062. ((eq fmt 'currency)
  1063. (format "%.2f" n))
  1064. (t (number-to-string n))))
  1065. (defun org-nofm-to-completion (n m &optional percent)
  1066. (if (not percent)
  1067. (format "[%d/%d]" n m)
  1068. (format "[%d%%]"(floor (+ 0.5 (* 100. (/ (* 1.0 n) m)))))))
  1069. (defun org-column-string-to-number (s fmt)
  1070. "Convert a column value to a number that can be used for column computing."
  1071. (cond
  1072. ((string-match ":" s)
  1073. (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
  1074. (while l
  1075. (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
  1076. sum))
  1077. ((memq fmt '(checkbox checkbox-n-of-m checkbox-percent))
  1078. (if (equal s "[X]") 1. 0.000001))
  1079. (t (string-to-number s))))
  1080. (defun org-columns-uncompile-format (cfmt)
  1081. "Turn the compiled columns format back into a string representation."
  1082. (let ((rtn "") e s prop title op width fmt printf)
  1083. (while (setq e (pop cfmt))
  1084. (setq prop (car e)
  1085. title (nth 1 e)
  1086. width (nth 2 e)
  1087. op (nth 3 e)
  1088. fmt (nth 4 e)
  1089. printf (nth 5 e))
  1090. (cond
  1091. ((eq fmt 'add_times) (setq op ":"))
  1092. ((eq fmt 'checkbox) (setq op "X"))
  1093. ((eq fmt 'checkbox-n-of-m) (setq op "X/"))
  1094. ((eq fmt 'checkbox-percent) (setq op "X%"))
  1095. ((eq fmt 'add_numbers) (setq op "+"))
  1096. ((eq fmt 'currency) (setq op "$")))
  1097. (if (and op printf) (setq op (concat op ";" printf)))
  1098. (if (equal title prop) (setq title nil))
  1099. (setq s (concat "%" (if width (number-to-string width))
  1100. prop
  1101. (if title (concat "(" title ")"))
  1102. (if op (concat "{" op "}"))))
  1103. (setq rtn (concat rtn " " s)))
  1104. (org-trim rtn)))
  1105. (defun org-columns-compile-format (fmt)
  1106. "Turn a column format string into an alist of specifications.
  1107. The alist has one entry for each column in the format. The elements of
  1108. that list are:
  1109. property the property
  1110. title the title field for the columns
  1111. width the column width in characters, can be nil for automatic
  1112. operator the operator if any
  1113. format the output format for computed results, derived from operator
  1114. printf a printf format for computed values"
  1115. (let ((start 0) width prop title op f printf)
  1116. (setq org-columns-current-fmt-compiled nil)
  1117. (while (string-match
  1118. (org-re "%\\([0-9]+\\)?\\([[:alnum:]_-]+\\)\\(?:(\\([^)]+\\))\\)?\\(?:{\\([^}]+\\)}\\)?\\s-*")
  1119. fmt start)
  1120. (setq start (match-end 0)
  1121. width (match-string 1 fmt)
  1122. prop (match-string 2 fmt)
  1123. title (or (match-string 3 fmt) prop)
  1124. op (match-string 4 fmt)
  1125. f nil
  1126. printf nil)
  1127. (if width (setq width (string-to-number width)))
  1128. (when (and op (string-match ";" op))
  1129. (setq printf (substring op (match-end 0))
  1130. op (substring op 0 (match-beginning 0))))
  1131. (cond
  1132. ((equal op "+") (setq f 'add_numbers))
  1133. ((equal op "$") (setq f 'currency))
  1134. ((equal op ":") (setq f 'add_times))
  1135. ((equal op "X") (setq f 'checkbox))
  1136. ((equal op "X/") (setq f 'checkbox-n-of-m))
  1137. ((equal op "X%") (setq f 'checkbox-percent))
  1138. )
  1139. (push (list prop title width op f printf) org-columns-current-fmt-compiled))
  1140. (setq org-columns-current-fmt-compiled
  1141. (nreverse org-columns-current-fmt-compiled))))
  1142. ;;; Dynamic block for Column view
  1143. (defun org-columns-capture-view (&optional maxlevel skip-empty-rows)
  1144. "Get the column view of the current buffer or subtree.
  1145. The first optional argument MAXLEVEL sets the level limit. A
  1146. second optional argument SKIP-EMPTY-ROWS tells whether to skip
  1147. empty rows, an empty row being one where all the column view
  1148. specifiers except ITEM are empty. This function returns a list
  1149. containing the title row and all other rows. Each row is a list
  1150. of fields."
  1151. (if (featurep 'xemacs)
  1152. (save-excursion
  1153. (let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
  1154. (n (length title)) row tbl)
  1155. (goto-char (point-min))
  1156. (while (re-search-forward "^\\(\\*+\\) " nil t)
  1157. (when (and (or (null maxlevel)
  1158. (>= maxlevel
  1159. (if org-odd-levels-only
  1160. (/ (1+ (length (match-string 1))) 2)
  1161. (length (match-string 1)))))
  1162. (get-char-property (match-beginning 0) 'org-columns-key))
  1163. (goto-char (match-beginning 0))
  1164. (setq row nil)
  1165. (loop for i from 0 to (1- n) do
  1166. (push (or (get-char-property (point)
  1167. 'org-columns-value-modified)
  1168. (get-char-property (point) 'org-columns-value)
  1169. "")
  1170. row)
  1171. (org-columns-forward-char))
  1172. (setq row (nreverse row))
  1173. (unless (and skip-empty-rows
  1174. (eq 1 (length (delete "" (delete-dups (copy-sequence row))))))
  1175. (push row tbl))))
  1176. (append (list title 'hline) (nreverse tbl))))
  1177. (save-excursion
  1178. (let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
  1179. (n (length title)) row tbl)
  1180. (goto-char (point-min))
  1181. (while (and (re-search-forward "^\\(\\*+\\) " nil t)
  1182. (or (null maxlevel)
  1183. (>= maxlevel
  1184. (if org-odd-levels-only
  1185. (/ (1+ (length (match-string 1))) 2)
  1186. (length (match-string 1))))))
  1187. (when (get-char-property (match-beginning 0) 'org-columns-key)
  1188. (setq row nil)
  1189. (loop for i from 0 to (1- n) do
  1190. (push (or (get-char-property (+ (match-beginning 0) i)
  1191. 'org-columns-value-modified)
  1192. (get-char-property (+ (match-beginning 0) i)
  1193. 'org-columns-value)
  1194. "")
  1195. row))
  1196. (setq row (nreverse row))
  1197. (unless (and skip-empty-rows
  1198. (eq 1 (length (delete "" (delete-dups row)))))
  1199. (push row tbl))))
  1200. (append (list title 'hline) (nreverse tbl))))))
  1201. (defun org-dblock-write:columnview (params)
  1202. "Write the column view table.
  1203. PARAMS is a property list of parameters:
  1204. :width enforce same column widths with <N> specifiers.
  1205. :id the :ID: property of the entry where the columns view
  1206. should be built. When the symbol `local', call locally.
  1207. When `global' call column view with the cursor at the beginning
  1208. of the buffer (usually this means that the whole buffer switches
  1209. to column view). When \"file:path/to/file.org\", invoke column
  1210. view at the start of that file. Otherwise, the ID is located
  1211. using `org-id-find'.
  1212. :hlines When t, insert a hline before each item. When a number, insert
  1213. a hline before each level <= that number.
  1214. :vlines When t, make each column a colgroup to enforce vertical lines.
  1215. :maxlevel When set to a number, don't capture headlines below this level.
  1216. :skip-empty-rows
  1217. When t, skip rows where all specifiers other than ITEM are empty."
  1218. (let ((pos (move-marker (make-marker) (point)))
  1219. (hlines (plist-get params :hlines))
  1220. (vlines (plist-get params :vlines))
  1221. (maxlevel (plist-get params :maxlevel))
  1222. (content-lines (org-split-string (plist-get params :content) "\n"))
  1223. (skip-empty-rows (plist-get params :skip-empty-rows))
  1224. tbl id idpos nfields tmp recalc line
  1225. id-as-string view-file view-pos)
  1226. (when (setq id (plist-get params :id))
  1227. (setq id-as-string (cond ((numberp id) (number-to-string id))
  1228. ((symbolp id) (symbol-name id))
  1229. ((stringp id) id)
  1230. (t "")))
  1231. (cond ((not id) nil)
  1232. ((eq id 'global) (setq view-pos (point-min)))
  1233. ((eq id 'local))
  1234. ((string-match "^file:\\(.*\\)" id-as-string)
  1235. (setq view-file (match-string 1 id-as-string)
  1236. view-pos 1)
  1237. (unless (file-exists-p view-file)
  1238. (error "No such file: \"%s\"" id-as-string)))
  1239. ((setq idpos (org-find-entry-with-id id))
  1240. (setq view-pos idpos))
  1241. ((setq idpos (org-id-find id))
  1242. (setq view-file (car idpos))
  1243. (setq view-pos (cdr idpos)))
  1244. (t (error "Cannot find entry with :ID: %s" id))))
  1245. (with-current-buffer (if view-file
  1246. (get-file-buffer view-file)
  1247. (current-buffer))
  1248. (save-excursion
  1249. (save-restriction
  1250. (widen)
  1251. (goto-char (or view-pos (point)))
  1252. (org-columns)
  1253. (setq tbl (org-columns-capture-view maxlevel skip-empty-rows))
  1254. (setq nfields (length (car tbl)))
  1255. (org-columns-quit))))
  1256. (goto-char pos)
  1257. (move-marker pos nil)
  1258. (when tbl
  1259. (when (plist-get params :hlines)
  1260. (setq tmp nil)
  1261. (while tbl
  1262. (if (eq (car tbl) 'hline)
  1263. (push (pop tbl) tmp)
  1264. (if (string-match "\\` *\\(\\*+\\)" (caar tbl))
  1265. (if (and (not (eq (car tmp) 'hline))
  1266. (or (eq hlines t)
  1267. (and (numberp hlines)
  1268. (<= (- (match-end 1) (match-beginning 1))
  1269. hlines))))
  1270. (push 'hline tmp)))
  1271. (push (pop tbl) tmp)))
  1272. (setq tbl (nreverse tmp)))
  1273. (when vlines
  1274. (setq tbl (mapcar (lambda (x)
  1275. (if (eq 'hline x) x (cons "" x)))
  1276. tbl))
  1277. (setq tbl (append tbl (list (cons "/" (make-list nfields "<>"))))))
  1278. (setq pos (point))
  1279. (when content-lines
  1280. (while (string-match "^#" (car content-lines))
  1281. (insert (pop content-lines) "\n")))
  1282. (insert (org-listtable-to-string tbl))
  1283. (when (plist-get params :width)
  1284. (insert "\n|" (mapconcat (lambda (x) (format "<%d>" (max 3 x)))
  1285. org-columns-current-widths "|")))
  1286. (while (setq line (pop content-lines))
  1287. (when (string-match "^#" line)
  1288. (insert "\n" line)
  1289. (when (string-match "^#\\+TBLFM" line)
  1290. (setq recalc t))))
  1291. (if recalc
  1292. (progn (goto-char pos) (org-table-recalculate 'all))
  1293. (goto-char pos)
  1294. (org-table-align)))))
  1295. (defun org-listtable-to-string (tbl)
  1296. "Convert a listtable TBL to a string that contains the Org-mode table.
  1297. The table still need to be aligned. The resulting string has no leading
  1298. and tailing newline characters."
  1299. (mapconcat
  1300. (lambda (x)
  1301. (cond
  1302. ((listp x)
  1303. (concat "|" (mapconcat 'identity x "|") "|"))
  1304. ((eq x 'hline) "|-|")
  1305. (t (error "Garbage in listtable: %s" x))))
  1306. tbl "\n"))
  1307. (defun org-insert-columns-dblock ()
  1308. "Create a dynamic block capturing a column view table."
  1309. (interactive)
  1310. (when (featurep 'xemacs) (org-columns-quit))
  1311. (let ((defaults '(:name "columnview" :hlines 1))
  1312. (id (org-ido-completing-read
  1313. "Capture columns (local, global, entry with :ID: property) [local]: "
  1314. (append '(("global") ("local"))
  1315. (mapcar 'list (org-property-values "ID"))))))
  1316. (if (equal id "") (setq id 'local))
  1317. (if (equal id "global") (setq id 'global))
  1318. (setq defaults (append defaults (list :id id)))
  1319. (org-create-dblock defaults)
  1320. (org-update-dblock)))
  1321. ;;; Column view in the agenda
  1322. (defvar org-agenda-view-columns-initially nil
  1323. "When set, switch to columns view immediately after creating the agenda.")
  1324. (defvar org-agenda-columns-show-summaries) ; defined in org-agenda.el
  1325. (defvar org-agenda-columns-compute-summary-properties); defined in org-agenda.el
  1326. (defvar org-agenda-columns-add-appointments-to-effort-sum); as well
  1327. (defun org-agenda-columns ()
  1328. "Turn on or update column view in the agenda."
  1329. (interactive)
  1330. (org-verify-version 'columns)
  1331. (org-columns-remove-overlays)
  1332. (move-marker org-columns-begin-marker (point))
  1333. (let (fmt cache maxwidths m p a d)
  1334. (cond
  1335. ((and (boundp 'org-agenda-overriding-columns-format)
  1336. org-agenda-overriding-columns-format)
  1337. (setq fmt org-agenda-overriding-columns-format)
  1338. (org-set-local 'org-agenda-overriding-columns-format fmt))
  1339. ((setq m (get-text-property (point-at-bol) 'org-hd-marker))
  1340. (setq fmt (or (org-entry-get m "COLUMNS" t)
  1341. (with-current-buffer (marker-buffer m)
  1342. org-columns-default-format))))
  1343. ((and (boundp 'org-columns-current-fmt)
  1344. (local-variable-p 'org-columns-current-fmt (current-buffer))
  1345. org-columns-current-fmt)
  1346. (setq fmt org-columns-current-fmt))
  1347. ((setq m (next-single-property-change (point-min) 'org-hd-marker))
  1348. (setq m (get-text-property m 'org-hd-marker))
  1349. (setq fmt (or (org-entry-get m "COLUMNS" t)
  1350. (with-current-buffer (marker-buffer m)
  1351. org-columns-default-format)))))
  1352. (setq fmt (or fmt org-columns-default-format))
  1353. (org-set-local 'org-columns-current-fmt fmt)
  1354. (org-columns-compile-format fmt)
  1355. (when org-agenda-columns-compute-summary-properties
  1356. (org-agenda-colview-compute org-columns-current-fmt-compiled))
  1357. (save-excursion
  1358. ;; Get and cache the properties
  1359. (goto-char (point-min))
  1360. (while (not (eobp))
  1361. (when (setq m (or (get-text-property (point) 'org-hd-marker)
  1362. (get-text-property (point) 'org-marker)))
  1363. (setq p (org-entry-properties m))
  1364. (when (or (not (setq a (assoc org-effort-property p)))
  1365. (not (string-match "\\S-" (or (cdr a) ""))))
  1366. ;; OK, the property is not defined. Use appointment duration?
  1367. (when (and org-agenda-columns-add-appointments-to-effort-sum
  1368. (setq d (get-text-property (point) 'duration)))
  1369. (setq d (org-minutes-to-hh:mm-string d))
  1370. (put-text-property 0 (length d) 'face 'org-warning d)
  1371. (push (cons org-effort-property d) p)))
  1372. (push (cons (org-current-line) p) cache))
  1373. (beginning-of-line 2))
  1374. (when cache
  1375. (setq maxwidths (org-columns-get-autowidth-alist fmt cache))
  1376. (org-set-local 'org-columns-current-maxwidths maxwidths)
  1377. (org-columns-display-here-title)
  1378. (mapc (lambda (x)
  1379. (goto-line (car x))
  1380. (org-columns-display-here (cdr x)))
  1381. cache)
  1382. (when org-agenda-columns-show-summaries
  1383. (org-agenda-colview-summarize cache))))))
  1384. (defun org-agenda-colview-summarize (cache)
  1385. "Summarize the summarizable columns in column view in the agenda.
  1386. This will add overlays to the date lines, to show the summary for each day."
  1387. (let* ((fmt (mapcar (lambda (x)
  1388. (list (car x) (if (equal (car x) "CLOCKSUM")
  1389. 'add_times (nth 4 x))))
  1390. org-columns-current-fmt-compiled))
  1391. line c c1 stype props lsum entries prop v)
  1392. (catch 'exit
  1393. (when (delq nil (mapcar 'cadr fmt))
  1394. ;; OK, at least one summation column, it makes sense to try this
  1395. (goto-char (point-max))
  1396. (while t
  1397. (when (or (get-text-property (point) 'org-date-line)
  1398. (eq (get-text-property (point) 'face)
  1399. 'org-agenda-structure))
  1400. ;; OK, this is a date line that should be used
  1401. (setq line (org-current-line))
  1402. (setq entries nil c cache cache nil)
  1403. (while (setq c1 (pop c))
  1404. (if (> (car c1) line)
  1405. (push c1 entries)
  1406. (push c1 cache)))
  1407. ;; now ENTRIES are the ones we want to use, CACHE is the rest
  1408. ;; Compute the summaries for the properties we want,
  1409. ;; set nil properties for the rest.
  1410. (when (setq entries (mapcar 'cdr entries))
  1411. (setq props
  1412. (mapcar
  1413. (lambda (f)
  1414. (setq prop (car f) stype (nth 1 f))
  1415. (cond
  1416. ((equal prop "ITEM")
  1417. (cons prop (buffer-substring (point-at-bol)
  1418. (point-at-eol))))
  1419. ((not stype) (cons prop ""))
  1420. (t
  1421. ;; do the summary
  1422. (setq lsum 0)
  1423. (mapc (lambda (x)
  1424. (setq v (cdr (assoc prop x)))
  1425. (if v (setq lsum (+ lsum
  1426. (org-column-string-to-number
  1427. v stype)))))
  1428. entries)
  1429. (setq lsum (org-columns-number-to-string lsum stype))
  1430. (put-text-property
  1431. 0 (length lsum) 'face 'bold lsum)
  1432. (cons prop lsum))))
  1433. fmt))
  1434. (org-columns-display-here props)
  1435. (org-set-local 'org-agenda-columns-active t)))
  1436. (if (bobp) (throw 'exit t))
  1437. (beginning-of-line 0))))))
  1438. (defun org-agenda-colview-compute (fmt)
  1439. "Compute the relevant columns in the contributing source buffers."
  1440. (let ((files org-agenda-contributing-files)
  1441. (org-columns-begin-marker (make-marker))
  1442. (org-columns-top-level-marker (make-marker))
  1443. f fm a b)
  1444. (while (setq f (pop files))
  1445. (setq b (find-buffer-visiting f))
  1446. (with-current-buffer (or (buffer-base-buffer b) b)
  1447. (save-excursion
  1448. (save-restriction
  1449. (widen)
  1450. (org-unmodified
  1451. (remove-text-properties (point-min) (point-max)
  1452. '(org-summaries t)))
  1453. (goto-char (point-min))
  1454. (org-columns-get-format-and-top-level)
  1455. (while (setq fm (pop fmt))
  1456. (if (equal (car fm) "CLOCKSUM")
  1457. (org-clock-sum)
  1458. (when (and (nth 4 fm)
  1459. (setq a (assoc (car fm)
  1460. org-columns-current-fmt-compiled))
  1461. (equal (nth 4 a) (nth 4 fm)))
  1462. (org-columns-compute (car fm)))))))))))
  1463. (provide 'org-colview)
  1464. (provide 'org-colview-xemacs)
  1465. ;;; org-colview-xemacs.el ends here