org-colview-xemacs.el 60 KB

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