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