fixed author information
[org-mode.git] / lisp / org-colview-xemacs.el
blobb32e741e79d114f02ae83be361ed01074020fabb
1 ;;; org-colview-xemacs.el --- Column View in Org-mode, XEmacs-specific version
3 ;; Copyright (C) 2004-2011
4 ;; Free Software Foundation, Inc.
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 GNU Emacs.
12 ;; GNU Emacs 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, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 ;; This file contains the column view for Org.
32 ;;; Code:
34 (eval-when-compile (require 'cl))
35 (require 'org)
37 (declare-function org-agenda-redo "org-agenda" ())
40 ;;; Define additional faces for column view
42 (when (featurep 'xemacs)
44 (defface org-columns-level-1;; font-lock-function-name-face
45 (org-compatible-face
46 'outline-1
47 '((((class color) (min-colors 88) (background light)) (:foreground "Blue1" :background "grey90"))
48 (((class color) (min-colors 88) (background dark)) (:foreground "LightSkyBlue" :background "grey30"))
49 (((class color) (min-colors 16) (background light)) (:foreground "Blue" :background "grey90"))
50 (((class color) (min-colors 16) (background dark)) (:foreground "LightSkyBlue" :background "grey30"))
51 (((class color) (min-colors 8)) (:foreground "blue" :bold t))
52 (t (:bold t))))
53 "Face used for columns-level 1 headlines."
54 :group 'org-faces)
56 (defface org-columns-level-2;; font-lock-variable-name-face
57 (org-compatible-face
58 'outline-2
59 '((((class color) (min-colors 16) (background light)) (:foreground "DarkGoldenrod" :background "grey90"))
60 (((class color) (min-colors 16) (background dark)) (:foreground "LightGoldenrod" :background "grey30"))
61 (((class color) (min-colors 8) (background light)) (:foreground "yellow" :background "grey90"))
62 (((class color) (min-colors 8) (background dark)) (:foreground "yellow" :bold t))
63 (t (:bold t))))
64 "Face used for columns-level 2 headlines."
65 :group 'org-faces)
67 (defface org-columns-level-3;; font-lock-keyword-face
68 (org-compatible-face
69 'outline-3
70 '((((class color) (min-colors 88) (background light)) (:foreground "Purple" :background "grey90"))
71 (((class color) (min-colors 88) (background dark)) (:foreground "Cyan1" :background "grey30"))
72 (((class color) (min-colors 16) (background light)) (:foreground "Purple" :background "grey90"))
73 (((class color) (min-colors 16) (background dark)) (:foreground "Cyan" :background "grey30"))
74 (((class color) (min-colors 8) (background light)) (:foreground "purple" :bold t))
75 (((class color) (min-colors 8) (background dark)) (:foreground "cyan" :bold t))
76 (t (:bold t))))
77 "Face used for columns-level 3 headlines."
78 :group 'org-faces)
80 (defface org-columns-level-4;; font-lock-comment-face
81 (org-compatible-face
82 'outline-4
83 '((((class color) (min-colors 88) (background light)) (:foreground "Firebrick" :background "grey90"))
84 (((class color) (min-colors 88) (background dark)) (:foreground "chocolate1" :background "grey30"))
85 (((class color) (min-colors 16) (background light)) (:foreground "red"))
86 (((class color) (min-colors 16) (background dark)) (:foreground "red1"))
87 (((class color) (min-colors 8) (background light)) (:foreground "red" :bold t))
88 (((class color) (min-colors 8) (background dark)) (:foreground "red" :bold t))
89 (t (:bold t))))
90 "Face used for columns-level 4 headlines."
91 :group 'org-faces)
93 (defface org-columns-level-5;; font-lock-type-face
94 (org-compatible-face
95 'outline-5
96 '((((class color) (min-colors 16) (background light)) (:foreground "ForestGreen" :background "grey90"))
97 (((class color) (min-colors 16) (background dark)) (:foreground "PaleGreen" :background "grey30"))
98 (((class color) (min-colors 8)) (:foreground "green"))))
99 "Face used for columns-level 5 headlines."
100 :group 'org-faces)
102 (defface org-columns-level-6;; font-lock-constant-face
103 (org-compatible-face
104 'outline-6
105 '((((class color) (min-colors 16) (background light)) (:foreground "CadetBlue" :background "grey90"))
106 (((class color) (min-colors 16) (background dark)) (:foreground "Aquamarine" :background "grey30"))
107 (((class color) (min-colors 8)) (:foreground "magenta"))))
108 "Face used for columns-level 6 headlines."
109 :group 'org-faces)
111 (defface org-columns-level-7;; font-lock-builtin-face
112 (org-compatible-face
113 'outline-7
114 '((((class color) (min-colors 16) (background light)) (:foreground "Orchid" :background "grey90"))
115 (((class color) (min-colors 16) (background dark)) (:foreground "LightSteelBlue" :background "grey30"))
116 (((class color) (min-colors 8)) (:foreground "blue"))))
117 "Face used for columns-level 7 headlines."
118 :group 'org-faces)
120 (defface org-columns-level-8;; font-lock-string-face
121 (org-compatible-face
122 'outline-8
123 '((((class color) (min-colors 16) (background light)) (:foreground "RosyBrown" :background "grey90"))
124 (((class color) (min-colors 16) (background dark)) (:foreground "LightSalmon" :background "grey30"))
125 (((class color) (min-colors 8)) (:foreground "green"))))
126 "Face used for columns-level 8 headlines."
127 :group 'org-faces)
130 (defface org-columns-space;; font-lock-function-name-face
131 (org-compatible-face
132 'outline-1
133 '((((class color) (min-colors 88) (background light)) (:background "grey90"))
134 (((class color) (min-colors 88) (background dark)) (:background "grey30"))
135 (((class color) (min-colors 16) (background light)) (:background "grey90"))
136 (((class color) (min-colors 16) (background dark)) (:background "grey30"))
137 (((class color) (min-colors 8)) (:bold t :underline t))))
138 "Face used for columns space headlines."
139 :group 'org-faces)
141 (defface org-columns-space1;; font-lock-function-name-face
142 (org-compatible-face
143 'outline-1
144 '((((class color) (min-colors 88) (background light)) (:background "grey90"))
145 (((class color) (min-colors 88) (background dark)) (:background "grey30"))
146 (((class color) (min-colors 16) (background light)) (:background "grey90"))
147 (((class color) (min-colors 16) (background dark)) (:background "grey30"))
148 (((class color) (min-colors 8)) (:bold t :underline t))))
149 "Face used for columns space headlines."
150 :group 'org-faces)
153 (when (featurep 'xemacs)
154 (defconst org-columns-level-faces
155 '(org-columns-level-1
156 org-columns-level-2 org-columns-level-3
157 org-columns-level-4 org-columns-level-5 org-columns-level-6
158 org-columns-level-7 org-columns-level-8
161 (defun org-get-columns-level-face (n)
162 "Get the right face for match N in font-lock matching of headlines."
163 (setq org-l (- (match-end 2) (match-beginning 1) 1))
164 (if org-odd-levels-only (setq org-l (1+ (/ org-l 2))))
165 (setq org-f (nth (% (1- org-l) org-n-level-faces) org-columns-level-faces))
166 (cond
167 ((eq n 1) (if org-hide-leading-stars 'org-hide org-f))
168 ((eq n 2) org-f)
169 (t (if org-level-color-stars-only nil org-f))))
173 ;;; Column View
175 (defvar org-columns-overlays nil
176 "Holds the list of current column overlays.")
178 (defvar org-columns-current-fmt nil
179 "Local variable, holds the currently active column format.")
180 (make-variable-buffer-local 'org-columns-current-fmt)
181 (defvar org-columns-current-fmt-compiled nil
182 "Local variable, holds the currently active column format.
183 This is the compiled version of the format.")
184 (make-variable-buffer-local 'org-columns-current-fmt-compiled)
185 (defvar org-columns-current-widths nil
186 "Local variable, holds the currently widths of fields.")
187 (make-variable-buffer-local 'org-columns-current-widths)
188 (defvar org-columns-current-maxwidths nil
189 "Local variable, holds the currently active maximum column widths.")
190 (make-variable-buffer-local 'org-columns-current-maxwidths)
191 (defvar org-columns-begin-marker (make-marker)
192 "Points to the position where last a column creation command was called.")
193 (defvar org-columns-top-level-marker (make-marker)
194 "Points to the position where current columns region starts.")
196 (defvar org-columns-map (make-sparse-keymap)
197 "The keymap valid in column display.")
199 (defun org-columns-content ()
200 "Switch to contents view while in columns view."
201 (interactive)
202 (org-overview)
203 (org-content))
205 (org-defkey org-columns-map "c" 'org-columns-content)
206 (org-defkey org-columns-map "o" 'org-overview)
207 (org-defkey org-columns-map "e" 'org-columns-edit-value)
208 (org-defkey org-columns-map "\C-c\C-t" 'org-columns-todo)
209 (org-defkey org-columns-map "\C-c\C-c" 'org-columns-set-tags-or-toggle)
210 (org-defkey org-columns-map "\C-c\C-o" 'org-columns-open-link)
211 (org-defkey org-columns-map "v" 'org-columns-show-value)
212 (org-defkey org-columns-map "q" 'org-columns-quit)
213 (org-defkey org-columns-map "r" 'org-columns-redo)
214 (org-defkey org-columns-map "g" 'org-columns-redo)
215 (org-defkey org-columns-map [left] 'org-columns-backward-char)
216 (org-defkey org-columns-map "\M-b" 'org-columns-backward-char)
217 (org-defkey org-columns-map "a" 'org-columns-edit-allowed)
218 (org-defkey org-columns-map "s" 'org-columns-edit-attributes)
219 (org-defkey org-columns-map "\M-f" 'org-columns-forward-char)
220 (org-defkey org-columns-map [right] 'org-columns-forward-char)
221 (org-defkey org-columns-map [(shift right)] 'org-columns-next-allowed-value)
222 (org-defkey org-columns-map "n" 'org-columns-next-allowed-value)
223 (org-defkey org-columns-map [(shift left)] 'org-columns-previous-allowed-value)
224 (org-defkey org-columns-map "p" 'org-columns-previous-allowed-value)
225 (org-defkey org-columns-map "<" 'org-columns-narrow)
226 (org-defkey org-columns-map ">" 'org-columns-widen)
227 (org-defkey org-columns-map [(meta right)] 'org-columns-move-right)
228 (org-defkey org-columns-map [(meta left)] 'org-columns-move-left)
229 (org-defkey org-columns-map [(shift meta right)] 'org-columns-new)
230 (org-defkey org-columns-map [(shift meta left)] 'org-columns-delete)
231 (dotimes (i 10)
232 (org-defkey org-columns-map (number-to-string i)
233 `(lambda () (interactive)
234 (org-columns-next-allowed-value nil ,i))))
236 (easy-menu-define org-columns-menu org-columns-map "Org Column Menu"
237 '("Column"
238 ["Edit property" org-columns-edit-value t]
239 ["Next allowed value" org-columns-next-allowed-value t]
240 ["Previous allowed value" org-columns-previous-allowed-value t]
241 ["Show full value" org-columns-show-value t]
242 ["Edit allowed values" org-columns-edit-allowed t]
243 "--"
244 ["Edit column attributes" org-columns-edit-attributes t]
245 ["Increase column width" org-columns-widen t]
246 ["Decrease column width" org-columns-narrow t]
247 "--"
248 ["Move column right" org-columns-move-right t]
249 ["Move column left" org-columns-move-left t]
250 ["Add column" org-columns-new t]
251 ["Delete column" org-columns-delete t]
252 "--"
253 ["CONTENTS" org-columns-content t]
254 ["OVERVIEW" org-overview t]
255 ["Refresh columns display" org-columns-redo t]
256 "--"
257 ["Open link" org-columns-open-link t]
258 "--"
259 ["Quit" org-columns-quit t]))
261 (defun org-columns-current-column ()
262 (if (featurep 'xemacs)
263 (/ (current-column) 2)
264 (current-column)))
266 (defun org-columns-forward-char ()
267 (interactive)
268 (forward-char)
269 (if (featurep 'xemacs)
270 (while (not (or (eolp)
271 (member (extent-at
272 (point) (current-buffer)
273 'org-columns-key) org-columns-overlays)))
274 (forward-char))))
276 (defun org-columns-backward-char ()
277 (interactive)
278 (backward-char)
279 (if (featurep 'xemacs)
280 (while (not (or (bolp)
281 (member (extent-at (point) (current-buffer) 'org-columns-key) org-columns-overlays)))
282 (backward-char))))
284 (defun org-columns-new-overlay (beg end &optional string face)
285 "Create a new column overlay and add it to the list."
286 (let ((ov (make-overlay beg end)))
287 (if (featurep 'xemacs)
288 (progn
289 (overlay-put ov 'face (or face 'org-columns-space1))
290 (overlay-put ov 'start-open t)
291 (if string
292 (org-overlay-display ov string (or face 'org-columns-space1))))
293 (overlay-put ov 'face (or face 'secondary-selection))
294 (org-overlay-display ov string face))
295 (push ov org-columns-overlays)
296 ov))
298 (defun org-columns-display-here (&optional props)
299 "Overlay the current line with column display."
300 (interactive)
301 (let* ((fmt org-columns-current-fmt-compiled)
302 (beg (point-at-bol))
303 (level-face (save-excursion
304 (beginning-of-line 1)
305 (and (looking-at "\\(\\**\\)\\(\\* \\)")
306 (org-get-level-face 2))))
307 (item (save-match-data
308 (org-no-properties
309 (org-remove-tabs
310 (buffer-substring-no-properties
311 (point-at-bol) (point-at-eol))))))
312 (color (if (featurep 'xemacs)
313 (save-excursion
314 (beginning-of-line 1)
315 (and (looking-at "\\(\\**\\)\\(\\* \\)")
316 (org-get-columns-level-face 2)))
317 (list :foreground
318 (face-attribute
319 (or level-face
320 (and (eq major-mode 'org-agenda-mode)
321 (get-text-property (point-at-bol) 'face))
322 'default) :foreground))))
323 (face (if (featurep 'xemacs) color (list color 'org-column)))
324 (pl (- (point)
325 (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
326 (point))))
327 (cphr (get-text-property (point-at-bol) 'org-complex-heading-regexp))
328 pom property ass width f string ov column val modval s2 title calc)
329 ;; Check if the entry is in another buffer.
330 (unless props
331 (if (eq major-mode 'org-agenda-mode)
332 (setq pom (or (org-get-at-bol 'org-hd-marker)
333 (org-get-at-bol 'org-marker))
334 props (if pom (org-entry-properties pom) nil))
335 (setq props (org-entry-properties nil))))
336 ;; Walk the format
337 (while (setq column (pop fmt))
338 (setq property (car column)
339 title (nth 1 column)
340 ass (if (equal property "ITEM")
341 (cons "ITEM" item)
342 (assoc property props))
343 width (or (cdr (assoc property org-columns-current-maxwidths))
344 (nth 2 column)
345 (length property))
346 f (format (if (featurep 'xemacs) "%%-%d.%ds |" "%%-%d.%ds | ")
347 width width)
348 val (or (cdr ass) "")
349 calc (nth 7 column)
350 modval (cond ((and org-columns-modify-value-for-display-function
351 (functionp
352 org-columns-modify-value-for-display-function))
353 (funcall org-columns-modify-value-for-display-function
354 title val))
355 ((equal property "ITEM")
356 (if (org-mode-p)
357 (org-columns-cleanup-item
358 val org-columns-current-fmt-compiled)))
359 ((and calc (functionp calc)
360 (not (string= val ""))
361 (not (get-text-property 0 'org-computed val)))
362 (org-columns-number-to-string
363 (funcall calc (org-columns-string-to-number
364 val (nth 4 column)))
365 (nth 4 column)))))
366 (setq s2 (org-columns-add-ellipses (or modval val) width))
367 (setq string (format f s2))
368 ;; Create the overlay
369 (org-unmodified
370 (setq ov (org-columns-new-overlay
371 beg (setq beg (1+ beg)) string face))
372 (overlay-put ov 'keymap org-columns-map)
373 (overlay-put ov 'org-columns-key property)
374 (overlay-put ov 'org-columns-value (cdr ass))
375 (overlay-put ov 'org-columns-value-modified modval)
376 (overlay-put ov 'org-columns-pom pom)
377 (overlay-put ov 'org-columns-format f)
378 (when (featurep 'xemacs)
379 (if (or (not (char-after beg))
380 (equal (char-after beg) ?\n))
381 (let ((inhibit-read-only t))
382 (save-excursion
383 (goto-char beg)
384 (org-unmodified (insert " "))
385 ;; FIXME: add props and remove later?
387 (goto-char beg)
388 (org-columns-new-overlay
389 beg (1+ beg) nil 'org-columns-space)
390 (setq beg (1+ beg))))
392 (if (or (not (char-after beg))
393 (equal (char-after beg) ?\n))
394 (let ((inhibit-read-only t))
395 (save-excursion
396 (goto-char beg)
397 ;; FIXME: add props and remove later?
398 (org-unmodified (insert " "))))))
399 ;; Make the rest of the line disappear.
400 (org-unmodified
401 (setq ov (org-columns-new-overlay beg (point-at-eol)))
402 (overlay-put ov 'invisible t)
403 (overlay-put ov 'keymap org-columns-map)
404 (overlay-put ov 'intangible t)
405 (push ov org-columns-overlays)
406 (setq ov (make-overlay (1- (point-at-eol)) (1+ (point-at-eol))))
407 (overlay-put ov 'keymap org-columns-map)
408 (push ov org-columns-overlays)
409 (let ((inhibit-read-only t))
410 (put-text-property (max (point-min) (1- (point-at-bol)))
411 (min (point-max) (1+ (point-at-eol)))
412 'read-only "Type `e' to edit property")))))
414 (defun org-columns-add-ellipses (string width)
415 "Truncate STRING with WIDTH characters, with ellipses."
416 (cond
417 ((<= (length string) width) string)
418 ((<= width (length org-columns-ellipses))
419 (substring org-columns-ellipses 0 width))
420 (t (concat (substring string 0 (- width (length org-columns-ellipses)))
421 org-columns-ellipses))))
423 (defvar org-columns-full-header-line-format nil
424 "The full header line format, will be shifted by horizontal scrolling." )
425 (defvar org-previous-header-line-format nil
426 "The header line format before column view was turned on.")
427 (defvar org-columns-inhibit-recalculation nil
428 "Inhibit recomputing of columns on column view startup.")
431 (defvar header-line-format)
432 (defvar org-columns-previous-hscroll 0)
434 (defun org-columns-display-here-title ()
435 "Overlay the newline before the current line with the table title."
436 (interactive)
437 (let ((fmt org-columns-current-fmt-compiled)
438 string (title "")
439 property width f column str widths)
440 (while (setq column (pop fmt))
441 (setq property (car column)
442 str (or (nth 1 column) property)
443 width (or (cdr (assoc property org-columns-current-maxwidths))
444 (nth 2 column)
445 (length str))
446 widths (push width widths)
447 f (format "%%-%d.%ds | " width width)
448 string (format f str)
449 title (concat title string)))
450 (if (featurep 'xemacs)
451 (let ((ext (make-extent nil nil)))
452 (set-extent-endpoints ext 0 (length title) title)
453 (set-extent-face ext (list 'bold 'underline 'org-columns-space1))
454 (org-set-local 'org-previous-header-line-format
455 (specifier-specs top-gutter))
456 (org-set-local 'org-columns-current-widths (nreverse widths))
457 (set-specifier top-gutter (make-gutter-specifier
458 (cons (current-buffer) title))))
459 (setq title (concat
460 (org-add-props " " nil 'display '(space :align-to 0))
461 (org-add-props title nil 'face '(:weight bold :underline t))))
462 (org-set-local 'org-previous-header-line-format header-line-format)
463 (org-set-local 'org-columns-current-widths (nreverse widths))
464 (setq org-columns-full-header-line-format title)
465 (setq org-columns-previous-hscroll -1)
466 (org-add-hook 'post-command-hook 'org-columns-hscoll-title nil 'local))))
468 (defun org-columns-hscoll-title ()
469 "Set the `header-line-format' so that it scrolls along with the table."
470 (sit-for .0001) ; need to force a redisplay to update window-hscroll
471 (when (not (= (window-hscroll) org-columns-previous-hscroll))
472 (setq header-line-format
473 (concat (substring org-columns-full-header-line-format 0 1)
474 (substring org-columns-full-header-line-format
475 (1+ (window-hscroll))))
476 org-columns-previous-hscroll (window-hscroll))
477 (force-mode-line-update)))
479 (defvar org-colview-initial-truncate-line-value nil
480 "Remember the value of `truncate-lines' across colview.")
482 (defun org-columns-remove-overlays ()
483 "Remove all currently active column overlays."
484 (interactive)
485 (when (marker-buffer org-columns-begin-marker)
486 (with-current-buffer (marker-buffer org-columns-begin-marker)
487 (when (local-variable-p 'org-previous-header-line-format (current-buffer))
488 (if (featurep 'xemacs)
489 (set-specifier top-gutter
490 (make-gutter-specifier
491 (cons (current-buffer)
492 (cdar org-previous-header-line-format))))
493 (setq header-line-format org-previous-header-line-format)
494 (remove-hook 'post-command-hook 'org-columns-hscoll-title 'local))
495 (kill-local-variable 'org-previous-header-line-format))
496 (move-marker org-columns-begin-marker nil)
497 (move-marker org-columns-top-level-marker nil)
498 (org-unmodified
499 (mapc 'delete-overlay org-columns-overlays)
500 (setq org-columns-overlays nil)
501 (let ((inhibit-read-only t))
502 (remove-text-properties (point-min) (point-max) '(read-only t))))
503 (when (local-variable-p 'org-colview-initial-truncate-line-value
504 (current-buffer))
505 (setq truncate-lines org-colview-initial-truncate-line-value)))))
508 (defun org-columns-cleanup-item (item fmt)
509 "Remove from ITEM what is a column in the format FMT."
510 (if (not org-complex-heading-regexp)
511 item
512 (when (string-match org-complex-heading-regexp item)
513 (setq item
514 (concat
515 (org-add-props (match-string 1 item) nil
516 'org-whitespace (* 2 (1- (org-reduced-level (- (match-end 1) (match-beginning 1))))))
517 (and (match-end 2) (not (assoc "TODO" fmt)) (concat " " (match-string 2 item)))
518 (and (match-end 3) (not (assoc "PRIORITY" fmt)) (concat " " (match-string 3 item)))
519 " " (save-match-data (org-columns-compact-links (match-string 4 item)))
520 (and (match-end 5) (not (assoc "TAGS" fmt)) (concat " " (match-string 5 item)))))
521 (add-text-properties
522 0 (1+ (match-end 1))
523 (list 'org-whitespace (* 2 (1- (org-reduced-level (- (match-end 1) (match-beginning 1))))))
524 item)
525 item)))
527 (defun org-columns-compact-links (s)
528 "Replace [[link][desc]] with [desc] or [link]."
529 (while (string-match org-bracket-link-regexp s)
530 (setq s (replace-match
531 (concat "[" (match-string (if (match-end 3) 3 1) s) "]")
532 t t s)))
535 (defun org-columns-show-value ()
536 "Show the full value of the property."
537 (interactive)
538 (let ((value (get-char-property (point) 'org-columns-value)))
539 (message "Value is: %s" (or value ""))))
541 (defvar org-agenda-columns-active) ;; defined in org-agenda.el
543 (defun org-columns-quit ()
544 "Remove the column overlays and in this way exit column editing."
545 (interactive)
546 (org-unmodified
547 (org-columns-remove-overlays)
548 (let ((inhibit-read-only t))
549 (remove-text-properties (point-min) (point-max) '(read-only t))))
550 (when (eq major-mode 'org-agenda-mode)
551 (setq org-agenda-columns-active nil)
552 (message
553 "Modification not yet reflected in Agenda buffer, use `r' to refresh")))
555 (defun org-columns-check-computed ()
556 "Check if this column value is computed.
557 If yes, throw an error indicating that changing it does not make sense."
558 (let ((val (get-char-property (point) 'org-columns-value)))
559 (when (and (stringp val)
560 (get-char-property 0 'org-computed val))
561 (error "This value is computed from the entry's children"))))
563 (defun org-columns-todo (&optional arg)
564 "Change the TODO state during column view."
565 (interactive "P")
566 (org-columns-edit-value "TODO"))
568 (defun org-columns-set-tags-or-toggle (&optional arg)
569 "Toggle checkbox at point, or set tags for current headline."
570 (interactive "P")
571 (if (string-match "\\`\\[[ xX-]\\]\\'"
572 (get-char-property (point) 'org-columns-value))
573 (org-columns-next-allowed-value)
574 (org-columns-edit-value "TAGS")))
576 (defun org-columns-edit-value (&optional key)
577 "Edit the value of the property at point in column view.
578 Where possible, use the standard interface for changing this line."
579 (interactive)
580 (org-columns-check-computed)
581 (let* ((col (current-column))
582 (key (or key (get-char-property (point) 'org-columns-key)))
583 (value (get-char-property (point) 'org-columns-value))
584 (bol (point-at-bol)) (eol (point-at-eol))
585 (pom (or (get-text-property bol 'org-hd-marker)
586 (point))) ; keep despite of compiler warning
587 (line-overlays
588 (delq nil (mapcar (lambda (x)
589 (and (eq (overlay-buffer x) (current-buffer))
590 (>= (overlay-start x) bol)
591 (<= (overlay-start x) eol)
593 org-columns-overlays)))
594 (org-columns-time (time-to-number-of-days (current-time)))
595 nval eval allowed)
596 (cond
597 ((equal key "CLOCKSUM")
598 (error "This special column cannot be edited"))
599 ((equal key "ITEM")
600 (setq eval '(org-with-point-at pom (org-edit-headline))))
601 ((equal key "TODO")
602 (setq eval '(org-with-point-at
604 (call-interactively 'org-todo))))
605 ((equal key "PRIORITY")
606 (setq eval '(org-with-point-at pom
607 (call-interactively 'org-priority))))
608 ((equal key "TAGS")
609 (setq eval '(org-with-point-at
611 (let ((org-fast-tag-selection-single-key
612 (if (eq org-fast-tag-selection-single-key 'expert)
613 t org-fast-tag-selection-single-key)))
614 (call-interactively 'org-set-tags)))))
615 ((equal key "DEADLINE")
616 (setq eval '(org-with-point-at
618 (call-interactively 'org-deadline))))
619 ((equal key "SCHEDULED")
620 (setq eval '(org-with-point-at
622 (call-interactively 'org-schedule))))
624 (setq allowed (org-property-get-allowed-values pom key 'table))
625 (if allowed
626 (setq nval (org-icompleting-read
627 "Value: " allowed nil
628 (not (get-text-property 0 'org-unrestricted
629 (caar allowed)))))
630 (setq nval (read-string "Edit: " value)))
631 (setq nval (org-trim nval))
632 (when (not (equal nval value))
633 (setq eval '(org-entry-put pom key nval)))))
634 (when eval
636 (cond
637 ((equal major-mode 'org-agenda-mode)
638 (org-columns-eval eval)
639 ;; The following let preserves the current format, and makes sure
640 ;; that in only a single file things need to be upated.
641 (let* ((org-agenda-overriding-columns-format org-columns-current-fmt)
642 (buffer (marker-buffer pom))
643 (org-agenda-contributing-files
644 (list (with-current-buffer buffer
645 (buffer-file-name (buffer-base-buffer))))))
646 (org-agenda-columns)))
648 (let ((inhibit-read-only t))
649 (org-unmodified
650 (remove-text-properties
651 (max (point-min) (1- bol)) eol '(read-only t)))
652 (unwind-protect
653 (progn
654 (setq org-columns-overlays
655 (org-delete-all line-overlays org-columns-overlays))
656 (mapc 'delete-overlay line-overlays)
657 (org-columns-eval eval))
658 (org-columns-display-here)))
659 (org-move-to-column col)
660 (if (and (org-mode-p)
661 (nth 3 (assoc key org-columns-current-fmt-compiled)))
662 (org-columns-update key)))))))
664 (defun org-edit-headline () ; FIXME: this is not columns specific. Make interactive????? Use from agenda????
665 "Edit the current headline, the part without TODO keyword, TAGS."
666 (org-back-to-heading)
667 (when (looking-at org-todo-line-regexp)
668 (let ((pos (point))
669 (pre (buffer-substring (match-beginning 0) (match-beginning 3)))
670 (txt (match-string 3))
671 (post "")
672 txt2)
673 (if (string-match (org-re "[ \t]+:[[:alnum:]:_@#%]+:[ \t]*$") txt)
674 (setq post (match-string 0 txt)
675 txt (substring txt 0 (match-beginning 0))))
676 (setq txt2 (read-string "Edit: " txt))
677 (when (not (equal txt txt2))
678 (goto-char pos)
679 (insert pre txt2 post)
680 (delete-region (point) (point-at-eol))
681 (org-set-tags nil t)))))
683 (defun org-columns-edit-allowed ()
684 "Edit the list of allowed values for the current property."
685 (interactive)
686 (let* ((pom (or (org-get-at-bol 'org-marker)
687 (org-get-at-bol 'org-hd-marker)
688 (point)))
689 (key (get-char-property (point) 'org-columns-key))
690 (key1 (concat key "_ALL"))
691 (allowed (org-entry-get pom key1 t))
692 nval)
693 ;; FIXME: Cover editing TODO, TAGS etc in-buffer settings.????
694 ;; FIXME: Write back to #+PROPERTY setting if that is needed.
695 (setq nval (read-string "Allowed: " allowed))
696 (org-entry-put
697 (cond ((marker-position org-entry-property-inherited-from)
698 org-entry-property-inherited-from)
699 ((marker-position org-columns-top-level-marker)
700 org-columns-top-level-marker)
701 (t pom))
702 key1 nval)))
704 (defun org-columns-eval (form)
705 (let (hidep)
706 (save-excursion
707 (beginning-of-line 1)
708 ;; `next-line' is needed here, because it skips invisible line.
709 (condition-case nil (org-no-warnings (next-line 1)) (error nil))
710 (setq hidep (org-on-heading-p 1)))
711 (eval form)
712 (and hidep (hide-entry))))
714 (defun org-columns-previous-allowed-value ()
715 "Switch to the previous allowed value for this column."
716 (interactive)
717 (org-columns-next-allowed-value t))
719 (defun org-columns-next-allowed-value (&optional previous nth)
720 "Switch to the next allowed value for this column.
721 When PREVIOUS is set, go to the previous value. When NTH is
722 an integer, select that value."
723 (interactive)
724 (org-columns-check-computed)
725 (let* ((col (current-column))
726 (key (get-char-property (point) 'org-columns-key))
727 (value (get-char-property (point) 'org-columns-value))
728 (bol (point-at-bol)) (eol (point-at-eol))
729 (pom (or (get-text-property bol 'org-hd-marker)
730 (point))) ; keep despite of compiler waring
731 (line-overlays
732 (delq nil (mapcar (lambda (x)
733 (and (eq (overlay-buffer x) (current-buffer))
734 (>= (overlay-start x) bol)
735 (<= (overlay-start x) eol)
737 org-columns-overlays)))
738 (allowed (or (org-property-get-allowed-values pom key)
739 (and (memq
740 (nth 4 (assoc key org-columns-current-fmt-compiled))
741 '(checkbox checkbox-n-of-m checkbox-percent))
742 '("[ ]" "[X]"))
743 (org-colview-construct-allowed-dates value)))
744 nval)
745 (when (integerp nth)
746 (setq nth (1- nth))
747 (if (= nth -1) (setq nth 9)))
748 (when (equal key "ITEM")
749 (error "Cannot edit item headline from here"))
750 (unless (or allowed (member key '("SCHEDULED" "DEADLINE")))
751 (error "Allowed values for this property have not been defined"))
752 (if (member key '("SCHEDULED" "DEADLINE"))
753 (setq nval (if previous 'earlier 'later))
754 (if previous (setq allowed (reverse allowed)))
755 (cond
756 (nth
757 (setq nval (nth nth allowed))
758 (if (not nval)
759 (error "There are only %d allowed values for property `%s'"
760 (length allowed) key)))
761 ((member value allowed)
762 (setq nval (or (car (cdr (member value allowed)))
763 (car allowed)))
764 (if (equal nval value)
765 (error "Only one allowed value for this property")))
766 (t (setq nval (car allowed)))))
767 (cond
768 ((equal major-mode 'org-agenda-mode)
769 (org-columns-eval '(org-entry-put pom key nval))
770 ;; The following let preserves the current format, and makes sure
771 ;; that in only a single file things need to be upated.
772 (let* ((org-agenda-overriding-columns-format org-columns-current-fmt)
773 (buffer (marker-buffer pom))
774 (org-agenda-contributing-files
775 (list (with-current-buffer buffer
776 (buffer-file-name (buffer-base-buffer))))))
777 (org-agenda-columns)))
779 (let ((inhibit-read-only t))
780 (remove-text-properties (1- bol) eol '(read-only t))
781 (unwind-protect
782 (progn
783 (setq org-columns-overlays
784 (org-delete-all line-overlays org-columns-overlays))
785 (mapc 'delete-overlay line-overlays)
786 (org-columns-eval '(org-entry-put pom key nval)))
787 (org-columns-display-here)))
788 (org-move-to-column col)
789 (and (nth 3 (assoc key org-columns-current-fmt-compiled))
790 (org-columns-update key))))))
792 (defun org-colview-construct-allowed-dates (s)
793 "Construct a list of three dates around the date in S.
794 This respects the format of the time stamp in S, active or non-active,
795 and also including time or not. S must be just a time stamp, no text
796 around it."
797 (when (and s (string-match (concat "^" org-ts-regexp3 "$") s))
798 (let* ((time (org-parse-time-string s 'nodefaults))
799 (active (equal (string-to-char s) ?<))
800 (fmt (funcall (if (nth 1 time) 'cdr 'car) org-time-stamp-formats))
801 time-before time-after)
802 (unless active (setq fmt (concat "[" (substring fmt 1 -1) "]")))
803 (setf (car time) (or (car time) 0))
804 (setf (nth 1 time) (or (nth 1 time) 0))
805 (setf (nth 2 time) (or (nth 2 time) 0))
806 (setq time-before (copy-sequence time))
807 (setq time-after (copy-sequence time))
808 (setf (nth 3 time-before) (1- (nth 3 time)))
809 (setf (nth 3 time-after) (1+ (nth 3 time)))
810 (mapcar (lambda (x) (format-time-string fmt (apply 'encode-time x)))
811 (list time-before time time-after)))))
813 (defun org-verify-version (task)
814 (cond
815 ((eq task 'columns)
816 (if (or (and (featurep 'xemacs) (not (featurep 'org-colview-xemacs)))
817 (and (not (featurep 'xemacs)) (< emacs-major-version 22)))
818 (error "This version of Emacs cannot run Column View")))))
820 (defun org-columns-open-link (&optional arg)
821 (interactive "P")
822 (let ((value (get-char-property (point) 'org-columns-value)))
823 (org-open-link-from-string value arg)))
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-on-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 (defun org-columns-compute (property)
1097 "Sum the values of property PROPERTY hierarchically, for the entire buffer."
1098 (interactive)
1099 (let* ((re org-outline-regexp-bol)
1100 (lmax 30) ; Does anyone use deeper levels???
1101 (lvals (make-vector lmax nil))
1102 (lflag (make-vector lmax nil))
1103 (level 0)
1104 (ass (assoc property org-columns-current-fmt-compiled))
1105 (format (nth 4 ass))
1106 (printf (nth 5 ass))
1107 (fun (nth 6 ass))
1108 (calc (or (nth 7 ass) 'identity))
1109 (beg org-columns-top-level-marker)
1110 last-level val valflag flag end sumpos sum-alist sum str str1 useval)
1111 (save-excursion
1112 ;; Find the region to compute
1113 (goto-char beg)
1114 (setq end (condition-case nil (org-end-of-subtree t) (error (point-max))))
1115 (goto-char end)
1116 ;; Walk the tree from the back and do the computations
1117 (while (re-search-backward re beg t)
1118 (setq sumpos (match-beginning 0)
1119 last-level level
1120 level (org-outline-level)
1121 val (org-entry-get nil property)
1122 valflag (and val (string-match "\\S-" val)))
1123 (cond
1124 ((< level last-level)
1125 ;; put the sum of lower levels here as a property
1126 (setq sum (when (aref lvals last-level)
1127 (apply fun (aref lvals last-level)))
1128 flag (aref lflag last-level) ; any valid entries from children?
1129 str (org-columns-number-to-string sum format printf)
1130 str1 (org-add-props (copy-sequence str) nil 'org-computed t 'face 'bold)
1131 useval (if flag str1 (if valflag val ""))
1132 sum-alist (get-text-property sumpos 'org-summaries))
1133 (if (assoc property sum-alist)
1134 (setcdr (assoc property sum-alist) useval)
1135 (push (cons property useval) sum-alist)
1136 (org-unmodified
1137 (add-text-properties sumpos (1+ sumpos)
1138 (list 'org-summaries sum-alist))))
1139 (when (and val (not (equal val (if flag str val))))
1140 (org-entry-put nil property (if flag str val)))
1141 ;; add current to current level accumulator
1142 (when (or flag valflag)
1143 (push (if flag
1145 (funcall calc (org-columns-string-to-number
1146 (if flag str val) format)))
1147 (aref lvals level))
1148 (aset lflag level t))
1149 ;; clear accumulators for deeper levels
1150 (loop for l from (1+ level) to (1- lmax) do
1151 (aset lvals l nil)
1152 (aset lflag l nil)))
1153 ((>= level last-level)
1154 ;; add what we have here to the accumulator for this level
1155 (when valflag
1156 (push (funcall calc (org-columns-string-to-number val format))
1157 (aref lvals level))
1158 (aset lflag level t)))
1159 (t (error "This should not happen")))))))
1161 (defun org-columns-redo ()
1162 "Construct the column display again."
1163 (interactive)
1164 (message "Recomputing columns...")
1165 (save-excursion
1166 (if (marker-position org-columns-begin-marker)
1167 (goto-char org-columns-begin-marker))
1168 (org-columns-remove-overlays)
1169 (if (org-mode-p)
1170 (call-interactively 'org-columns)
1171 (org-agenda-redo)
1172 (call-interactively 'org-agenda-columns)))
1173 (when (featurep 'xemacs)
1174 (while (not (or (eolp)
1175 (member (extent-at (point)) org-columns-overlays)))
1176 (forward-char)))
1177 (message "Recomputing columns...done"))
1179 (defun org-columns-not-in-agenda ()
1180 (if (eq major-mode 'org-agenda-mode)
1181 (error "This command is only allowed in Org-mode buffers")))
1183 (defun org-string-to-number (s)
1184 "Convert string to number, and interpret hh:mm:ss."
1185 (if (not (string-match ":" s))
1186 (string-to-number s)
1187 (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
1188 (while l
1189 (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
1190 sum)))
1192 (defun org-columns-number-to-string (n fmt &optional printf)
1193 "Convert a computed column number to a string value, according to FMT."
1194 (cond
1195 ((memq fmt '(estimate)) (org-estimate-print n printf))
1196 ((not (numberp n)) "")
1197 ((memq fmt '(add_times max_times min_times mean_times))
1198 (let* ((h (floor n)) (m (floor (+ 0.5 (* 60 (- n h))))))
1199 (format org-time-clocksum-format h m)))
1200 ((eq fmt 'checkbox)
1201 (cond ((= n (floor n)) "[X]")
1202 ((> n 1.) "[-]")
1203 (t "[ ]")))
1204 ((memq fmt '(checkbox-n-of-m checkbox-percent))
1205 (let* ((n1 (floor n)) (n2 (floor (+ .5 (* 1000000 (- n n1))))))
1206 (org-nofm-to-completion n1 (+ n2 n1) (eq fmt 'checkbox-percent))))
1207 (printf (format printf n))
1208 ((eq fmt 'currency)
1209 (format "%.2f" n))
1210 ((memq fmt '(min_age max_age mean_age))
1211 (org-format-time-period n))
1212 (t (number-to-string n))))
1214 (defun org-nofm-to-completion (n m &optional percent)
1215 (if (not percent)
1216 (format "[%d/%d]" n m)
1217 (format "[%d%%]"(floor (+ 0.5 (* 100. (/ (* 1.0 n) m)))))))
1219 (defun org-columns-string-to-number (s fmt)
1220 "Convert a column value to a number that can be used for column computing."
1221 (if s
1222 (cond
1223 ((memq fmt '(min_age max_age mean_age))
1224 (cond ((string= s "") org-columns-time)
1225 ((string-match
1226 "\\([0-9]+\\)d \\([0-9]+\\)h \\([0-9]+\\)m \\([0-9]+\\)s"
1228 (+ (* 60 (+ (* 60 (+ (* 24 (string-to-number (match-string 1 s)))
1229 (string-to-number (match-string 2 s))))
1230 (string-to-number (match-string 3 s))))
1231 (string-to-number (match-string 4 s))))
1232 (t (time-to-number-of-days (apply 'encode-time
1233 (org-parse-time-string s t))))))
1234 ((string-match ":" s)
1235 (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
1236 (while l
1237 (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
1238 sum))
1239 ((memq fmt '(checkbox checkbox-n-of-m checkbox-percent))
1240 (if (equal s "[X]") 1. 0.000001))
1241 ((memq fmt '(estimate)) (org-string-to-estimate s))
1242 (t (string-to-number s)))))
1244 (defun org-columns-uncompile-format (cfmt)
1245 "Turn the compiled columns format back into a string representation."
1246 (let ((rtn "") e s prop title op op-match width fmt printf fun calc)
1247 (while (setq e (pop cfmt))
1248 (setq prop (car e)
1249 title (nth 1 e)
1250 width (nth 2 e)
1251 op (nth 3 e)
1252 fmt (nth 4 e)
1253 printf (nth 5 e)
1254 fun (nth 6 e)
1255 calc (nth 7 e))
1256 (when (setq op-match (rassoc (list fmt fun calc) org-columns-compile-map))
1257 (setq op (car op-match)))
1258 (if (and op printf) (setq op (concat op ";" printf)))
1259 (if (equal title prop) (setq title nil))
1260 (setq s (concat "%" (if width (number-to-string width))
1261 prop
1262 (if title (concat "(" title ")"))
1263 (if op (concat "{" op "}"))))
1264 (setq rtn (concat rtn " " s)))
1265 (org-trim rtn)))
1267 (defun org-columns-compile-format (fmt)
1268 "Turn a column format string into an alist of specifications.
1269 The alist has one entry for each column in the format. The elements of
1270 that list are:
1271 property the property
1272 title the title field for the columns
1273 width the column width in characters, can be nil for automatic
1274 operator the operator if any
1275 format the output format for computed results, derived from operator
1276 printf a printf format for computed values
1277 fun the lisp function to compute summary values, derived from operator
1278 calc function to get values from base elements"
1279 (let ((start 0) width prop title op op-match f printf fun calc)
1280 (setq org-columns-current-fmt-compiled nil)
1281 (while (string-match
1282 (org-re "%\\([0-9]+\\)?\\([[:alnum:]_-]+\\)\\(?:(\\([^)]+\\))\\)?\\(?:{\\([^}]+\\)}\\)?\\s-*")
1283 fmt start)
1284 (setq start (match-end 0)
1285 width (match-string 1 fmt)
1286 prop (match-string 2 fmt)
1287 title (or (match-string 3 fmt) prop)
1288 op (match-string 4 fmt)
1289 f nil
1290 printf nil
1291 fun '+
1292 calc nil)
1293 (if width (setq width (string-to-number width)))
1294 (when (and op (string-match ";" op))
1295 (setq printf (substring op (match-end 0))
1296 op (substring op 0 (match-beginning 0))))
1297 (when (setq op-match (assoc op org-columns-compile-map))
1298 (setq f (cadr op-match)
1299 fun (caddr op-match)
1300 calc (cadddr op-match)))
1301 (push (list prop title width op f printf fun calc)
1302 org-columns-current-fmt-compiled))
1303 (setq org-columns-current-fmt-compiled
1304 (nreverse org-columns-current-fmt-compiled))))
1307 ;;; Dynamic block for Column view
1309 (defun org-columns-capture-view (&optional maxlevel skip-empty-rows)
1310 "Get the column view of the current buffer or subtree.
1311 The first optional argument MAXLEVEL sets the level limit. A
1312 second optional argument SKIP-EMPTY-ROWS tells whether to skip
1313 empty rows, an empty row being one where all the column view
1314 specifiers except ITEM are empty. This function returns a list
1315 containing the title row and all other rows. Each row is a list
1316 of fields."
1317 (if (featurep 'xemacs)
1318 (save-excursion
1319 (let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
1320 (re-comment (concat "\\*+[ \t]+" org-comment-string "\\>"))
1321 (re-archive (concat ".*:" org-archive-tag ":"))
1322 (n (length title)) row tbl)
1323 (goto-char (point-min))
1325 (while (re-search-forward "^\\(\\*+\\) " nil t)
1326 (catch 'next
1327 (when (and (or (null maxlevel)
1328 (>= maxlevel
1329 (if org-odd-levels-only
1330 (/ (1+ (length (match-string 1))) 2)
1331 (length (match-string 1)))))
1332 (get-char-property (match-beginning 0) 'org-columns-key))
1333 (goto-char (match-beginning 0))
1334 (when (save-excursion
1335 (goto-char (point-at-bol))
1336 (or (looking-at re-comment)
1337 (looking-at re-archive)))
1338 (org-end-of-subtree t)
1339 (throw 'next t))
1340 (setq row nil)
1341 (loop for i from 0 to (1- n) do
1342 (push
1343 (org-quote-vert
1344 (or (get-char-property (point)
1345 'org-columns-value-modified)
1346 (get-char-property (point) 'org-columns-value)
1347 ""))
1348 row)
1349 (org-columns-forward-char))
1350 (setq row (nreverse row))
1351 (unless (and skip-empty-rows
1352 (eq 1 (length (delete "" (delete-dups (copy-sequence row))))))
1353 (push row tbl)))))
1354 (append (list title 'hline) (nreverse tbl))))
1355 (save-excursion
1356 (let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
1357 (n (length title)) row tbl)
1358 (goto-char (point-min))
1359 (while (and (re-search-forward "^\\(\\*+\\) " nil t)
1360 (or (null maxlevel)
1361 (>= maxlevel
1362 (if org-odd-levels-only
1363 (/ (1+ (length (match-string 1))) 2)
1364 (length (match-string 1))))))
1365 (when (get-char-property (match-beginning 0) 'org-columns-key)
1366 (setq row nil)
1367 (loop for i from 0 to (1- n) do
1368 (push (or (get-char-property (+ (match-beginning 0) i)
1369 'org-columns-value-modified)
1370 (get-char-property (+ (match-beginning 0) i)
1371 'org-columns-value)
1373 row))
1374 (setq row (nreverse row))
1375 (unless (and skip-empty-rows
1376 (eq 1 (length (delete "" (delete-dups row)))))
1377 (push row tbl))))
1378 (append (list title 'hline) (nreverse tbl))))))
1380 (defun org-dblock-write:columnview (params)
1381 "Write the column view table.
1382 PARAMS is a property list of parameters:
1384 :width enforce same column widths with <N> specifiers.
1385 :id the :ID: property of the entry where the columns view
1386 should be built. When the symbol `local', call locally.
1387 When `global' call column view with the cursor at the beginning
1388 of the buffer (usually this means that the whole buffer switches
1389 to column view). When \"file:path/to/file.org\", invoke column
1390 view at the start of that file. Otherwise, the ID is located
1391 using `org-id-find'.
1392 :hlines When t, insert a hline before each item. When a number, insert
1393 a hline before each level <= that number.
1394 :vlines When t, make each column a colgroup to enforce vertical lines.
1395 :maxlevel When set to a number, don't capture headlines below this level.
1396 :skip-empty-rows
1397 When t, skip rows where all specifiers other than ITEM are empty."
1398 (let ((pos (move-marker (make-marker) (point)))
1399 (hlines (plist-get params :hlines))
1400 (vlines (plist-get params :vlines))
1401 (maxlevel (plist-get params :maxlevel))
1402 (content-lines (org-split-string (plist-get params :content) "\n"))
1403 (skip-empty-rows (plist-get params :skip-empty-rows))
1404 tbl id idpos nfields tmp recalc line
1405 id-as-string view-file view-pos)
1406 (when (setq id (plist-get params :id))
1407 (setq id-as-string (cond ((numberp id) (number-to-string id))
1408 ((symbolp id) (symbol-name id))
1409 ((stringp id) id)
1410 (t "")))
1411 (cond ((not id) nil)
1412 ((eq id 'global) (setq view-pos (point-min)))
1413 ((eq id 'local))
1414 ((string-match "^file:\\(.*\\)" id-as-string)
1415 (setq view-file (match-string 1 id-as-string)
1416 view-pos 1)
1417 (unless (file-exists-p view-file)
1418 (error "No such file: \"%s\"" id-as-string)))
1419 ((setq idpos (org-find-entry-with-id id))
1420 (setq view-pos idpos))
1421 ((setq idpos (org-id-find id))
1422 (setq view-file (car idpos))
1423 (setq view-pos (cdr idpos)))
1424 (t (error "Cannot find entry with :ID: %s" id))))
1425 (with-current-buffer (if view-file
1426 (get-file-buffer view-file)
1427 (current-buffer))
1428 (save-excursion
1429 (save-restriction
1430 (widen)
1431 (goto-char (or view-pos (point)))
1432 (org-columns)
1433 (setq tbl (org-columns-capture-view maxlevel skip-empty-rows))
1434 (setq nfields (length (car tbl)))
1435 (org-columns-quit))))
1436 (goto-char pos)
1437 (move-marker pos nil)
1438 (when tbl
1439 (when (plist-get params :hlines)
1440 (setq tmp nil)
1441 (while tbl
1442 (if (eq (car tbl) 'hline)
1443 (push (pop tbl) tmp)
1444 (if (string-match "\\` *\\(\\*+\\)" (caar tbl))
1445 (if (and (not (eq (car tmp) 'hline))
1446 (or (eq hlines t)
1447 (and (numberp hlines)
1448 (<= (- (match-end 1) (match-beginning 1))
1449 hlines))))
1450 (push 'hline tmp)))
1451 (push (pop tbl) tmp)))
1452 (setq tbl (nreverse tmp)))
1453 (when vlines
1454 (setq tbl (mapcar (lambda (x)
1455 (if (eq 'hline x) x (cons "" x)))
1456 tbl))
1457 (setq tbl (append tbl (list (cons "/" (make-list nfields "<>"))))))
1458 (setq pos (point))
1459 (when content-lines
1460 (while (string-match "^#" (car content-lines))
1461 (insert (pop content-lines) "\n")))
1462 (insert (org-listtable-to-string tbl))
1463 (when (plist-get params :width)
1464 (insert "\n|" (mapconcat (lambda (x) (format "<%d>" (max 3 x)))
1465 org-columns-current-widths "|")))
1466 (while (setq line (pop content-lines))
1467 (when (string-match "^#" line)
1468 (insert "\n" line)
1469 (when (string-match "^[ \t]*#\\+TBLFM" line)
1470 (setq recalc t))))
1471 (if recalc
1472 (progn (goto-char pos) (org-table-recalculate 'all))
1473 (goto-char pos)
1474 (org-table-align)))))
1476 (defun org-listtable-to-string (tbl)
1477 "Convert a listtable TBL to a string that contains the Org-mode table.
1478 The table still need to be aligned. The resulting string has no leading
1479 and tailing newline characters."
1480 (mapconcat
1481 (lambda (x)
1482 (cond
1483 ((listp x)
1484 (concat "|" (mapconcat 'identity x "|") "|"))
1485 ((eq x 'hline) "|-|")
1486 (t (error "Garbage in listtable: %s" x))))
1487 tbl "\n"))
1489 (defun org-insert-columns-dblock ()
1490 "Create a dynamic block capturing a column view table."
1491 (interactive)
1492 (when (featurep 'xemacs) (org-columns-quit))
1493 (let ((defaults '(:name "columnview" :hlines 1))
1494 (id (org-icompleting-read
1495 "Capture columns (local, global, entry with :ID: property) [local]: "
1496 (append '(("global") ("local"))
1497 (mapcar 'list (org-property-values "ID"))))))
1498 (if (equal id "") (setq id 'local))
1499 (if (equal id "global") (setq id 'global))
1500 (setq defaults (append defaults (list :id id)))
1501 (org-create-dblock defaults)
1502 (org-update-dblock)))
1504 ;;; Column view in the agenda
1506 (defvar org-agenda-view-columns-initially nil
1507 "When set, switch to columns view immediately after creating the agenda.")
1509 (defvar org-agenda-columns-show-summaries) ; defined in org-agenda.el
1510 (defvar org-agenda-columns-compute-summary-properties); defined in org-agenda.el
1511 (defvar org-agenda-columns-add-appointments-to-effort-sum); as well
1513 (defun org-agenda-columns ()
1514 "Turn on or update column view in the agenda."
1515 (interactive)
1516 (org-verify-version 'columns)
1517 (org-columns-remove-overlays)
1518 (move-marker org-columns-begin-marker (point))
1519 (let ((org-columns-time (time-to-number-of-days (current-time)))
1520 cache maxwidths m p a d fmt)
1521 (cond
1522 ((and (boundp 'org-agenda-overriding-columns-format)
1523 org-agenda-overriding-columns-format)
1524 (setq fmt org-agenda-overriding-columns-format)
1525 (org-set-local 'org-agenda-overriding-columns-format fmt))
1526 ((setq m (org-get-at-bol 'org-hd-marker))
1527 (setq fmt (or (org-entry-get m "COLUMNS" t)
1528 (with-current-buffer (marker-buffer m)
1529 org-columns-default-format))))
1530 ((and (boundp 'org-columns-current-fmt)
1531 (local-variable-p 'org-columns-current-fmt (current-buffer))
1532 org-columns-current-fmt)
1533 (setq fmt org-columns-current-fmt))
1534 ((setq m (next-single-property-change (point-min) 'org-hd-marker))
1535 (setq m (get-text-property m 'org-hd-marker))
1536 (setq fmt (or (org-entry-get m "COLUMNS" t)
1537 (with-current-buffer (marker-buffer m)
1538 org-columns-default-format)))))
1539 (setq fmt (or fmt org-columns-default-format))
1540 (org-set-local 'org-columns-current-fmt fmt)
1541 (org-columns-compile-format fmt)
1542 (when org-agenda-columns-compute-summary-properties
1543 (org-agenda-colview-compute org-columns-current-fmt-compiled))
1544 (save-excursion
1545 ;; Get and cache the properties
1546 (goto-char (point-min))
1547 (while (not (eobp))
1548 (when (setq m (or (org-get-at-bol 'org-hd-marker)
1549 (org-get-at-bol 'org-marker)))
1550 (setq p (org-entry-properties m))
1552 (when (or (not (setq a (assoc org-effort-property p)))
1553 (not (string-match "\\S-" (or (cdr a) ""))))
1554 ;; OK, the property is not defined. Use appointment duration?
1555 (when (and org-agenda-columns-add-appointments-to-effort-sum
1556 (setq d (get-text-property (point) 'duration)))
1557 (setq d (org-minutes-to-hh:mm-string d))
1558 (put-text-property 0 (length d) 'face 'org-warning d)
1559 (push (cons org-effort-property d) p)))
1560 (push (cons (org-current-line) p) cache))
1561 (beginning-of-line 2))
1562 (when cache
1563 (setq maxwidths (org-columns-get-autowidth-alist fmt cache))
1564 (org-set-local 'org-columns-current-maxwidths maxwidths)
1565 (org-columns-display-here-title)
1566 (mapc (lambda (x)
1567 (org-goto-line (car x))
1568 (org-columns-display-here (cdr x)))
1569 cache)
1570 (when org-agenda-columns-show-summaries
1571 (org-agenda-colview-summarize cache))))))
1573 (defun org-agenda-colview-summarize (cache)
1574 "Summarize the summarizable columns in column view in the agenda.
1575 This will add overlays to the date lines, to show the summary for each day."
1576 (let* ((fmt (mapcar (lambda (x)
1577 (if (equal (car x) "CLOCKSUM")
1578 (list "CLOCKSUM" (nth 2 x) nil 'add_times nil '+ 'identity)
1579 (cdr x)))
1580 org-columns-current-fmt-compiled))
1581 line c c1 stype calc sumfunc props lsum entries prop v)
1582 (catch 'exit
1583 (when (delq nil (mapcar 'cadr fmt))
1584 ;; OK, at least one summation column, it makes sense to try this
1585 (goto-char (point-max))
1586 (while t
1587 (when (or (get-text-property (point) 'org-date-line)
1588 (eq (get-text-property (point) 'face)
1589 'org-agenda-structure))
1590 ;; OK, this is a date line that should be used
1591 (setq line (org-current-line))
1592 (setq entries nil c cache cache nil)
1593 (while (setq c1 (pop c))
1594 (if (> (car c1) line)
1595 (push c1 entries)
1596 (push c1 cache)))
1597 ;; now ENTRIES are the ones we want to use, CACHE is the rest
1598 ;; Compute the summaries for the properties we want,
1599 ;; set nil properties for the rest.
1600 (when (setq entries (mapcar 'cdr entries))
1601 (setq props
1602 (mapcar
1603 (lambda (f)
1604 (setq prop (car f)
1605 stype (nth 3 f)
1606 sumfunc (nth 5 f)
1607 calc (or (nth 6 f) 'identity))
1608 (cond
1609 ((equal prop "ITEM")
1610 (cons prop (buffer-substring (point-at-bol)
1611 (point-at-eol))))
1612 ((not stype) (cons prop ""))
1613 (t ;; do the summary
1614 (setq lsum nil)
1615 (dolist (x entries)
1616 (setq v (cdr (assoc prop x)))
1617 (if v
1618 (push
1619 (funcall
1620 (if (not (get-text-property 0 'org-computed v))
1621 calc
1622 'identity)
1623 (org-columns-string-to-number
1624 v stype))
1625 lsum)))
1626 (setq lsum (remove nil lsum))
1627 (setq lsum
1628 (cond ((> (length lsum) 1)
1629 (org-columns-number-to-string
1630 (apply sumfunc lsum) stype))
1631 ((eq (length lsum) 1)
1632 (org-columns-number-to-string
1633 (car lsum) stype))
1634 (t "")))
1635 (put-text-property 0 (length lsum) 'face 'bold lsum)
1636 (unless (eq calc 'identity)
1637 (put-text-property 0 (length lsum) 'org-computed t lsum))
1638 (cons prop lsum))))
1639 fmt))
1640 (org-columns-display-here props)
1641 (org-set-local 'org-agenda-columns-active t)))
1642 (if (bobp) (throw 'exit t))
1643 (beginning-of-line 0))))))
1645 (defun org-agenda-colview-compute (fmt)
1646 "Compute the relevant columns in the contributing source buffers."
1647 (let ((files org-agenda-contributing-files)
1648 (org-columns-begin-marker (make-marker))
1649 (org-columns-top-level-marker (make-marker))
1650 f fm a b)
1651 (while (setq f (pop files))
1652 (setq b (find-buffer-visiting f))
1653 (with-current-buffer (or (buffer-base-buffer b) b)
1654 (save-excursion
1655 (save-restriction
1656 (widen)
1657 (org-unmodified
1658 (remove-text-properties (point-min) (point-max)
1659 '(org-summaries t)))
1660 (goto-char (point-min))
1661 (org-columns-get-format-and-top-level)
1662 (while (setq fm (pop fmt))
1663 (if (equal (car fm) "CLOCKSUM")
1664 (org-clock-sum)
1665 (when (and (nth 4 fm)
1666 (setq a (assoc (car fm)
1667 org-columns-current-fmt-compiled))
1668 (equal (nth 4 a) (nth 4 fm)))
1669 (org-columns-compute (car fm)))))))))))
1671 (defun org-format-time-period (interval)
1672 "Convert time in fractional days to days/hours/minutes/seconds."
1673 (if (numberp interval)
1674 (let* ((days (floor interval))
1675 (frac-hours (* 24 (- interval days)))
1676 (hours (floor frac-hours))
1677 (minutes (floor (* 60 (- frac-hours hours))))
1678 (seconds (floor (* 60 (- (* 60 (- frac-hours hours)) minutes)))))
1679 (format "%dd %02dh %02dm %02ds" days hours minutes seconds))
1680 ""))
1682 (defun org-estimate-mean-and-var (v)
1683 "Return the mean and variance of an estimate."
1684 (let* ((low (float (car v)))
1685 (high (float (cadr v)))
1686 (mean (/ (+ low high) 2.0))
1687 (var (/ (+ (expt (- mean low) 2.0) (expt (- high mean) 2.0)) 2.0)))
1688 (list mean var)))
1690 (defun org-estimate-combine (&rest el)
1691 "Combine a list of estimates, using mean and variance.
1692 The mean and variance of the result will be the sum of the means
1693 and variances (respectively) of the individual estimates."
1694 (let ((mean 0)
1695 (var 0))
1696 (mapc (lambda (e)
1697 (let ((stats (org-estimate-mean-and-var e)))
1698 (setq mean (+ mean (car stats)))
1699 (setq var (+ var (cadr stats)))))
1701 (let ((stdev (sqrt var)))
1702 (list (- mean stdev) (+ mean stdev)))))
1704 (defun org-estimate-print (e &optional fmt)
1705 "Prepare a string representation of an estimate.
1706 This formats these numbers as two numbers with a \"-\" between them."
1707 (if (null fmt) (set 'fmt "%.0f"))
1708 (format "%s" (mapconcat (lambda (n) (format fmt n)) e "-")))
1710 (defun org-string-to-estimate (s)
1711 "Convert a string to an estimate.
1712 The string should be two numbers joined with a \"-\"."
1713 (if (string-match "\\(.*\\)-\\(.*\\)" s)
1714 (list (string-to-number (match-string 1 s))
1715 (string-to-number(match-string 2 s)))
1716 (list (string-to-number s) (string-to-number s))))
1718 (provide 'org-colview)
1719 (provide 'org-colview-xemacs)
1721 ;;; org-colview-xemacs.el ends here