server.mk: implement ELPA
[org-mode/org-tableheadings.git] / lisp / org-colview-xemacs.el
blobbfea40de94a404997566e7dbe2124a5ddcd4daa8
1 ;;; org-colview-xemacs.el --- Column View in Org-mode, XEmacs-specific version
3 ;; Copyright (C) 2004-2012
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-remove-tabs
309 (buffer-substring-no-properties
310 (point-at-bol) (point-at-eol)))))
311 (color (if (featurep 'xemacs)
312 (save-excursion
313 (beginning-of-line 1)
314 (and (looking-at "\\(\\**\\)\\(\\* \\)")
315 (org-get-columns-level-face 2)))
316 (list :foreground
317 (face-attribute
318 (or level-face
319 (and (eq major-mode 'org-agenda-mode)
320 (get-text-property (point-at-bol) 'face))
321 'default) :foreground))))
322 (face (if (featurep 'xemacs) color (list color 'org-column)))
323 (pl (- (point)
324 (or (text-property-any (point-at-bol) (point-at-eol) 'org-heading t)
325 (point))))
326 (cphr (get-text-property (point-at-bol) 'org-complex-heading-regexp))
327 pom property ass width f string ov column val modval s2 title calc)
328 ;; Check if the entry is in another buffer.
329 (unless props
330 (if (eq major-mode 'org-agenda-mode)
331 (setq pom (or (org-get-at-bol 'org-hd-marker)
332 (org-get-at-bol 'org-marker))
333 props (if pom (org-entry-properties pom) nil))
334 (setq props (org-entry-properties nil))))
335 ;; Walk the format
336 (while (setq column (pop fmt))
337 (setq property (car column)
338 title (nth 1 column)
339 ass (if (equal property "ITEM")
340 (cons "ITEM" item)
341 (assoc property props))
342 width (or (cdr (assoc property org-columns-current-maxwidths))
343 (nth 2 column)
344 (length property))
345 f (format (if (featurep 'xemacs) "%%-%d.%ds |" "%%-%d.%ds | ")
346 width width)
347 val (or (cdr ass) "")
348 calc (nth 7 column)
349 modval (cond ((and org-columns-modify-value-for-display-function
350 (functionp
351 org-columns-modify-value-for-display-function))
352 (funcall org-columns-modify-value-for-display-function
353 title val))
354 ((equal property "ITEM")
355 (if (derived-mode-p 'org-mode)
356 (org-columns-cleanup-item
357 val org-columns-current-fmt-compiled)))
358 ((and calc (functionp calc)
359 (not (string= val ""))
360 (not (get-text-property 0 'org-computed val)))
361 (org-columns-number-to-string
362 (funcall calc (org-columns-string-to-number
363 val (nth 4 column)))
364 (nth 4 column)))))
365 (setq s2 (org-columns-add-ellipses (or modval val) width))
366 (setq string (format f s2))
367 ;; Create the overlay
368 (org-unmodified
369 (setq ov (org-columns-new-overlay
370 beg (setq beg (1+ beg)) string face))
371 (overlay-put ov 'keymap org-columns-map)
372 (overlay-put ov 'org-columns-key property)
373 (overlay-put ov 'org-columns-value (cdr ass))
374 (overlay-put ov 'org-columns-value-modified modval)
375 (overlay-put ov 'org-columns-pom pom)
376 (overlay-put ov 'org-columns-format f)
377 (when (featurep 'xemacs)
378 (if (or (not (char-after beg))
379 (equal (char-after beg) ?\n))
380 (let ((inhibit-read-only t))
381 (save-excursion
382 (goto-char beg)
383 (org-unmodified (insert " "))
384 ;; FIXME: add props and remove later?
386 (goto-char beg)
387 (org-columns-new-overlay
388 beg (1+ beg) nil 'org-columns-space)
389 (setq beg (1+ beg))))
391 (if (or (not (char-after beg))
392 (equal (char-after beg) ?\n))
393 (let ((inhibit-read-only t))
394 (save-excursion
395 (goto-char beg)
396 ;; FIXME: add props and remove later?
397 (org-unmodified (insert " "))))))
398 ;; Make the rest of the line disappear.
399 (org-unmodified
400 (setq ov (org-columns-new-overlay beg (point-at-eol)))
401 (overlay-put ov 'invisible t)
402 (overlay-put ov 'keymap org-columns-map)
403 (overlay-put ov 'intangible t)
404 (push ov org-columns-overlays)
405 (setq ov (make-overlay (1- (point-at-eol)) (1+ (point-at-eol))))
406 (overlay-put ov 'keymap org-columns-map)
407 (push ov org-columns-overlays)
408 (let ((inhibit-read-only t))
409 (put-text-property (max (point-min) (1- (point-at-bol)))
410 (min (point-max) (1+ (point-at-eol)))
411 'read-only "Type `e' to edit property")))))
413 (defun org-columns-add-ellipses (string width)
414 "Truncate STRING with WIDTH characters, with ellipses."
415 (cond
416 ((<= (length string) width) string)
417 ((<= width (length org-columns-ellipses))
418 (substring org-columns-ellipses 0 width))
419 (t (concat (substring string 0 (- width (length org-columns-ellipses)))
420 org-columns-ellipses))))
422 (defvar org-columns-full-header-line-format nil
423 "The full header line format, will be shifted by horizontal scrolling." )
424 (defvar org-previous-header-line-format nil
425 "The header line format before column view was turned on.")
426 (defvar org-columns-inhibit-recalculation nil
427 "Inhibit recomputing of columns on column view startup.")
430 (defvar header-line-format)
431 (defvar org-columns-previous-hscroll 0)
433 (defun org-columns-display-here-title ()
434 "Overlay the newline before the current line with the table title."
435 (interactive)
436 (let ((fmt org-columns-current-fmt-compiled)
437 string (title "")
438 property width f column str widths)
439 (while (setq column (pop fmt))
440 (setq property (car column)
441 str (or (nth 1 column) property)
442 width (or (cdr (assoc property org-columns-current-maxwidths))
443 (nth 2 column)
444 (length str))
445 widths (push width widths)
446 f (format "%%-%d.%ds | " width width)
447 string (format f str)
448 title (concat title string)))
449 (if (featurep 'xemacs)
450 (let ((ext (make-extent nil nil)))
451 (set-extent-endpoints ext 0 (length title) title)
452 (set-extent-face ext (list 'bold 'underline 'org-columns-space1))
453 (org-set-local 'org-previous-header-line-format
454 (specifier-specs top-gutter))
455 (org-set-local 'org-columns-current-widths (nreverse widths))
456 (set-specifier top-gutter (make-gutter-specifier
457 (cons (current-buffer) title))))
458 (setq title (concat
459 (org-add-props " " nil 'display '(space :align-to 0))
460 (org-add-props title nil 'face '(:weight bold :underline t))))
461 (org-set-local 'org-previous-header-line-format header-line-format)
462 (org-set-local 'org-columns-current-widths (nreverse widths))
463 (setq org-columns-full-header-line-format title)
464 (setq org-columns-previous-hscroll -1)
465 (org-add-hook 'post-command-hook 'org-columns-hscoll-title nil 'local))))
467 (defun org-columns-hscoll-title ()
468 "Set the `header-line-format' so that it scrolls along with the table."
469 (sit-for .0001) ; need to force a redisplay to update window-hscroll
470 (when (not (= (window-hscroll) org-columns-previous-hscroll))
471 (setq header-line-format
472 (concat (substring org-columns-full-header-line-format 0 1)
473 (substring org-columns-full-header-line-format
474 (1+ (window-hscroll))))
475 org-columns-previous-hscroll (window-hscroll))
476 (force-mode-line-update)))
478 (defvar org-colview-initial-truncate-line-value nil
479 "Remember the value of `truncate-lines' across colview.")
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 (defun org-columns-get-format-and-top-level ()
825 (let (fmt)
826 (when (condition-case nil (org-back-to-heading) (error nil))
827 (setq fmt (org-entry-get nil "COLUMNS" t)))
828 (setq fmt (or fmt org-columns-default-format))
829 (org-set-local 'org-columns-current-fmt fmt)
830 (org-columns-compile-format fmt)
831 (if (marker-position org-entry-property-inherited-from)
832 (move-marker org-columns-top-level-marker
833 org-entry-property-inherited-from)
834 (move-marker org-columns-top-level-marker (point)))
835 fmt))
837 (defun org-columns ()
838 "Turn on column view on an org-mode file."
839 (interactive)
840 (org-verify-version 'columns)
841 (when (featurep 'xemacs)
842 (set-face-foreground 'org-columns-space
843 (face-background 'org-columns-space)))
844 (org-columns-remove-overlays)
845 (move-marker org-columns-begin-marker (point))
846 (let ((org-columns-time (time-to-number-of-days (current-time)))
847 beg end fmt cache maxwidths)
848 (setq fmt (org-columns-get-format-and-top-level))
849 (save-excursion
850 (goto-char org-columns-top-level-marker)
851 (setq beg (point))
852 (unless org-columns-inhibit-recalculation
853 (org-columns-compute-all))
854 (setq end (or (condition-case nil (org-end-of-subtree t t) (error nil))
855 (point-max)))
856 ;; Get and cache the properties
857 (goto-char beg)
858 (when (assoc "CLOCKSUM" org-columns-current-fmt-compiled)
859 (save-excursion
860 (save-restriction
861 (narrow-to-region beg end)
862 (org-clock-sum))))
863 (while (re-search-forward org-outline-regexp-bol end t)
864 (if (and org-columns-skip-archived-trees
865 (looking-at (concat ".*:" org-archive-tag ":")))
866 (org-end-of-subtree t)
867 (push (cons (org-current-line) (org-entry-properties)) cache)))
868 (when cache
869 (setq maxwidths (org-columns-get-autowidth-alist fmt cache))
870 (org-set-local 'org-columns-current-maxwidths maxwidths)
871 (org-columns-display-here-title)
872 (unless (local-variable-p 'org-colview-initial-truncate-line-value
873 (current-buffer))
874 (org-set-local 'org-colview-initial-truncate-line-value
875 truncate-lines))
876 (setq truncate-lines t)
877 (mapc (lambda (x)
878 (org-goto-line (car x))
879 (org-columns-display-here (cdr x)))
880 cache)))))
882 (eval-when-compile (defvar org-columns-time))
884 (defvar org-columns-compile-map
885 '(("none" none +)
886 (":" add_times +)
887 ("+" add_numbers +)
888 ("$" currency +)
889 ("X" checkbox +)
890 ("X/" checkbox-n-of-m +)
891 ("X%" checkbox-percent +)
892 ("max" max_numbers max)
893 ("min" min_numbers min)
894 ("mean" mean_numbers
895 (lambda (&rest x) (/ (apply '+ x) (float (length x)))))
896 (":max" max_times max)
897 (":min" min_times min)
898 (":mean" mean_times
899 (lambda (&rest x) (/ (apply '+ x) (float (length x)))))
900 ("@min" min_age min (lambda (x) (- org-columns-time x)))
901 ("@max" max_age max (lambda (x) (- org-columns-time x)))
902 ("@mean" mean_age
903 (lambda (&rest x) (/ (apply '+ x) (float (length x))))
904 (lambda (x) (- org-columns-time x)))
905 ("est+" estimate org-estimate-combine))
906 "Operator <-> format,function,calc map.
907 Used to compile/uncompile columns format and completing read in
908 interactive function `org-columns-new'.
910 operator string used in #+COLUMNS definition describing the
911 summary type
912 format symbol describing summary type selected interactively in
913 `org-columns-new' and internally in
914 `org-columns-number-to-string' and
915 `org-columns-string-to-number'
916 function called with a list of values as argument to calculate
917 the summary value
918 calc function called on every element before summarizing. This is
919 optional and should only be specified if needed")
922 (defun org-columns-new (&optional prop title width op fmt fun &rest rest)
923 "Insert a new column, to the left of the current column."
924 (interactive)
925 (let ((n (org-columns-current-column))
926 (editp (and prop (assoc prop org-columns-current-fmt-compiled)))
927 cell)
928 (setq prop (org-icompleting-read
929 "Property: " (mapcar 'list (org-buffer-property-keys t nil t))
930 nil nil prop))
931 (setq title (read-string (concat "Column title [" prop "]: ") (or title prop)))
932 (setq width (read-string "Column width: " (if width (number-to-string width))))
933 (if (string-match "\\S-" width)
934 (setq width (string-to-number width))
935 (setq width nil))
936 (setq fmt (org-icompleting-read "Summary [none]: "
937 (mapcar (lambda (x) (list (symbol-name (cadr x)))) org-columns-compile-map)
938 nil t))
939 (setq fmt (intern fmt)
940 fun (cdr (assoc fmt (mapcar 'cdr org-columns-compile-map))))
941 (if (eq fmt 'none) (setq fmt nil))
942 (if editp
943 (progn
944 (setcar editp prop)
945 (setcdr editp (list title width nil fmt nil fun)))
946 (setq cell (nthcdr (1- n) org-columns-current-fmt-compiled))
947 (setcdr cell (cons (list prop title width nil fmt nil
948 (car fun) (cadr fun))
949 (cdr cell))))
950 (org-columns-store-format)
951 (org-columns-redo)))
953 (defun org-columns-delete ()
954 "Delete the column at point from columns view."
955 (interactive)
956 (let* ((n (org-columns-current-column))
957 (title (nth 1 (nth n org-columns-current-fmt-compiled))))
958 (when (y-or-n-p
959 (format "Are you sure you want to remove column \"%s\"? " title))
960 (setq org-columns-current-fmt-compiled
961 (delq (nth n org-columns-current-fmt-compiled)
962 org-columns-current-fmt-compiled))
963 (org-columns-store-format)
964 (org-columns-redo)
965 (if (>= (org-columns-current-column)
966 (length org-columns-current-fmt-compiled))
967 (org-columns-backward-char)))))
969 (defun org-columns-edit-attributes ()
970 "Edit the attributes of the current column."
971 (interactive)
972 (let* ((n (org-columns-current-column))
973 (info (nth n org-columns-current-fmt-compiled)))
974 (apply 'org-columns-new info)))
976 (defun org-columns-widen (arg)
977 "Make the column wider by ARG characters."
978 (interactive "p")
979 (let* ((n (org-columns-current-column))
980 (entry (nth n org-columns-current-fmt-compiled))
981 (width (or (nth 2 entry)
982 (cdr (assoc (car entry) org-columns-current-maxwidths)))))
983 (setq width (max 1 (+ width arg)))
984 (setcar (nthcdr 2 entry) width)
985 (org-columns-store-format)
986 (org-columns-redo)))
988 (defun org-columns-narrow (arg)
989 "Make the column narrower by ARG characters."
990 (interactive "p")
991 (org-columns-widen (- arg)))
993 (defun org-columns-move-right ()
994 "Swap this column with the one to the right."
995 (interactive)
996 (let* ((n (org-columns-current-column))
997 (cell (nthcdr n org-columns-current-fmt-compiled))
999 (when (>= n (1- (length org-columns-current-fmt-compiled)))
1000 (error "Cannot shift this column further to the right"))
1001 (setq e (car cell))
1002 (setcar cell (car (cdr cell)))
1003 (setcdr cell (cons e (cdr (cdr cell))))
1004 (org-columns-store-format)
1005 (org-columns-redo)
1006 (org-columns-forward-char)))
1008 (defun org-columns-move-left ()
1009 "Swap this column with the one to the left."
1010 (interactive)
1011 (let* ((n (org-columns-current-column)))
1012 (when (= n 0)
1013 (error "Cannot shift this column further to the left"))
1014 (org-columns-backward-char)
1015 (org-columns-move-right)
1016 (org-columns-backward-char)))
1018 (defun org-columns-store-format ()
1019 "Store the text version of the current columns format in appropriate place.
1020 This is either in the COLUMNS property of the node starting the current column
1021 display, or in the #+COLUMNS line of the current buffer."
1022 (let (fmt (cnt 0))
1023 (setq fmt (org-columns-uncompile-format org-columns-current-fmt-compiled))
1024 (org-set-local 'org-columns-current-fmt fmt)
1025 (if (marker-position org-columns-top-level-marker)
1026 (save-excursion
1027 (goto-char org-columns-top-level-marker)
1028 (if (and (org-at-heading-p)
1029 (org-entry-get nil "COLUMNS"))
1030 (org-entry-put nil "COLUMNS" fmt)
1031 (goto-char (point-min))
1032 ;; Overwrite all #+COLUMNS lines....
1033 (while (re-search-forward "^#\\+COLUMNS:.*" nil t)
1034 (setq cnt (1+ cnt))
1035 (replace-match (concat "#+COLUMNS: " fmt) t t))
1036 (unless (> cnt 0)
1037 (goto-char (point-min))
1038 (or (org-at-heading-p t) (outline-next-heading))
1039 (let ((inhibit-read-only t))
1040 (insert-before-markers "#+COLUMNS: " fmt "\n")))
1041 (org-set-local 'org-columns-default-format fmt))))))
1043 (defvar org-agenda-overriding-columns-format nil
1044 "When set, overrides any other format definition for the agenda.
1045 Don't set this, this is meant for dynamic scoping.")
1047 (defun org-columns-get-autowidth-alist (s cache)
1048 "Derive the maximum column widths from the format and the cache."
1049 (let ((start 0) rtn)
1050 (while (string-match (org-re "%\\([[:alpha:]][[:alnum:]_-]*\\)") s start)
1051 (push (cons (match-string 1 s) 1) rtn)
1052 (setq start (match-end 0)))
1053 (mapc (lambda (x)
1054 (setcdr x (apply 'max
1055 (mapcar
1056 (lambda (y)
1057 (length (or (cdr (assoc (car x) (cdr y))) " ")))
1058 cache))))
1059 rtn)
1060 rtn))
1062 (defun org-columns-compute-all ()
1063 "Compute all columns that have operators defined."
1064 (org-unmodified
1065 (remove-text-properties (point-min) (point-max) '(org-summaries t)))
1066 (let ((columns org-columns-current-fmt-compiled)
1067 (org-columns-time (time-to-number-of-days (current-time)))
1068 col)
1069 (while (setq col (pop columns))
1070 (when (nth 3 col)
1071 (save-excursion
1072 (org-columns-compute (car col)))))))
1074 (defun org-columns-update (property)
1075 "Recompute PROPERTY, and update the columns display for it."
1076 (org-columns-compute property)
1077 (let (fmt val pos face)
1078 (save-excursion
1079 (mapc (lambda (ov)
1080 (when (equal (overlay-get ov 'org-columns-key) property)
1081 (setq pos (overlay-start ov))
1082 (goto-char pos)
1083 (when (setq val (cdr (assoc property
1084 (get-text-property
1085 (point-at-bol) 'org-summaries))))
1086 (setq fmt (overlay-get ov 'org-columns-format))
1087 (overlay-put ov 'org-columns-value val)
1088 (if (featurep 'xemacs)
1089 (progn
1090 (setq face (glyph-face (extent-end-glyph ov)))
1091 (org-overlay-display ov (format fmt val) face))
1092 (org-overlay-display ov (format fmt val))))))
1093 org-columns-overlays))))
1095 (defun org-columns-compute (property)
1096 "Sum the values of property PROPERTY hierarchically, for the entire buffer."
1097 (interactive)
1098 (let* ((re org-outline-regexp-bol)
1099 (lmax 30) ; Does anyone use deeper levels???
1100 (lvals (make-vector lmax nil))
1101 (lflag (make-vector lmax nil))
1102 (level 0)
1103 (ass (assoc property org-columns-current-fmt-compiled))
1104 (format (nth 4 ass))
1105 (printf (nth 5 ass))
1106 (fun (nth 6 ass))
1107 (calc (or (nth 7 ass) 'identity))
1108 (beg org-columns-top-level-marker)
1109 last-level val valflag flag end sumpos sum-alist sum str str1 useval)
1110 (save-excursion
1111 ;; Find the region to compute
1112 (goto-char beg)
1113 (setq end (condition-case nil (org-end-of-subtree t) (error (point-max))))
1114 (goto-char end)
1115 ;; Walk the tree from the back and do the computations
1116 (while (re-search-backward re beg t)
1117 (setq sumpos (match-beginning 0)
1118 last-level level
1119 level (org-outline-level)
1120 val (org-entry-get nil property)
1121 valflag (and val (string-match "\\S-" val)))
1122 (cond
1123 ((< level last-level)
1124 ;; put the sum of lower levels here as a property
1125 (setq sum (when (aref lvals last-level)
1126 (apply fun (aref lvals last-level)))
1127 flag (aref lflag last-level) ; any valid entries from children?
1128 str (org-columns-number-to-string sum format printf)
1129 str1 (org-add-props (copy-sequence str) nil 'org-computed t 'face 'bold)
1130 useval (if flag str1 (if valflag val ""))
1131 sum-alist (get-text-property sumpos 'org-summaries))
1132 (if (assoc property sum-alist)
1133 (setcdr (assoc property sum-alist) useval)
1134 (push (cons property useval) sum-alist)
1135 (org-unmodified
1136 (add-text-properties sumpos (1+ sumpos)
1137 (list 'org-summaries sum-alist))))
1138 (when (and val (not (equal val (if flag str val))))
1139 (org-entry-put nil property (if flag str val)))
1140 ;; add current to current level accumulator
1141 (when (or flag valflag)
1142 (push (if flag
1144 (funcall calc (org-columns-string-to-number
1145 (if flag str val) format)))
1146 (aref lvals level))
1147 (aset lflag level t))
1148 ;; clear accumulators for deeper levels
1149 (loop for l from (1+ level) to (1- lmax) do
1150 (aset lvals l nil)
1151 (aset lflag l nil)))
1152 ((>= level last-level)
1153 ;; add what we have here to the accumulator for this level
1154 (when valflag
1155 (push (funcall calc (org-columns-string-to-number val format))
1156 (aref lvals level))
1157 (aset lflag level t)))
1158 (t (error "This should not happen")))))))
1160 (defun org-columns-redo ()
1161 "Construct the column display again."
1162 (interactive)
1163 (message "Recomputing columns...")
1164 (save-excursion
1165 (if (marker-position org-columns-begin-marker)
1166 (goto-char org-columns-begin-marker))
1167 (org-columns-remove-overlays)
1168 (if (derived-mode-p 'org-mode)
1169 (call-interactively 'org-columns)
1170 (org-agenda-redo)
1171 (call-interactively 'org-agenda-columns)))
1172 (when (featurep 'xemacs)
1173 (while (not (or (eolp)
1174 (member (extent-at (point)) org-columns-overlays)))
1175 (forward-char)))
1176 (message "Recomputing columns...done"))
1178 (defun org-columns-not-in-agenda ()
1179 (if (eq major-mode 'org-agenda-mode)
1180 (error "This command is only allowed in Org-mode buffers")))
1182 (defun org-string-to-number (s)
1183 "Convert string to number, and interpret hh:mm:ss."
1184 (if (not (string-match ":" s))
1185 (string-to-number s)
1186 (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
1187 (while l
1188 (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
1189 sum)))
1191 (defun org-columns-number-to-string (n fmt &optional printf)
1192 "Convert a computed column number to a string value, according to FMT."
1193 (cond
1194 ((memq fmt '(estimate)) (org-estimate-print n printf))
1195 ((not (numberp n)) "")
1196 ((memq fmt '(add_times max_times min_times mean_times))
1197 (let* ((h (floor n)) (m (floor (+ 0.5 (* 60 (- n h))))))
1198 (format org-time-clocksum-format h m)))
1199 ((eq fmt 'checkbox)
1200 (cond ((= n (floor n)) "[X]")
1201 ((> n 1.) "[-]")
1202 (t "[ ]")))
1203 ((memq fmt '(checkbox-n-of-m checkbox-percent))
1204 (let* ((n1 (floor n)) (n2 (floor (+ .5 (* 1000000 (- n n1))))))
1205 (org-nofm-to-completion n1 (+ n2 n1) (eq fmt 'checkbox-percent))))
1206 (printf (format printf n))
1207 ((eq fmt 'currency)
1208 (format "%.2f" n))
1209 ((memq fmt '(min_age max_age mean_age))
1210 (org-format-time-period n))
1211 (t (number-to-string n))))
1213 (defun org-nofm-to-completion (n m &optional percent)
1214 (if (not percent)
1215 (format "[%d/%d]" n m)
1216 (format "[%d%%]"(floor (+ 0.5 (* 100. (/ (* 1.0 n) m)))))))
1218 (defun org-columns-string-to-number (s fmt)
1219 "Convert a column value to a number that can be used for column computing."
1220 (if s
1221 (cond
1222 ((memq fmt '(min_age max_age mean_age))
1223 (cond ((string= s "") org-columns-time)
1224 ((string-match
1225 "\\([0-9]+\\)d \\([0-9]+\\)h \\([0-9]+\\)m \\([0-9]+\\)s"
1227 (+ (* 60 (+ (* 60 (+ (* 24 (string-to-number (match-string 1 s)))
1228 (string-to-number (match-string 2 s))))
1229 (string-to-number (match-string 3 s))))
1230 (string-to-number (match-string 4 s))))
1231 (t (time-to-number-of-days (apply 'encode-time
1232 (org-parse-time-string s t))))))
1233 ((string-match ":" s)
1234 (let ((l (nreverse (org-split-string s ":"))) (sum 0.0))
1235 (while l
1236 (setq sum (+ (string-to-number (pop l)) (/ sum 60))))
1237 sum))
1238 ((memq fmt '(checkbox checkbox-n-of-m checkbox-percent))
1239 (if (equal s "[X]") 1. 0.000001))
1240 ((memq fmt '(estimate)) (org-string-to-estimate s))
1241 (t (string-to-number s)))))
1243 (defun org-columns-uncompile-format (cfmt)
1244 "Turn the compiled columns format back into a string representation."
1245 (let ((rtn "") e s prop title op op-match width fmt printf fun calc)
1246 (while (setq e (pop cfmt))
1247 (setq prop (car e)
1248 title (nth 1 e)
1249 width (nth 2 e)
1250 op (nth 3 e)
1251 fmt (nth 4 e)
1252 printf (nth 5 e)
1253 fun (nth 6 e)
1254 calc (nth 7 e))
1255 (when (setq op-match (rassoc (list fmt fun calc) org-columns-compile-map))
1256 (setq op (car op-match)))
1257 (if (and op printf) (setq op (concat op ";" printf)))
1258 (if (equal title prop) (setq title nil))
1259 (setq s (concat "%" (if width (number-to-string width))
1260 prop
1261 (if title (concat "(" title ")"))
1262 (if op (concat "{" op "}"))))
1263 (setq rtn (concat rtn " " s)))
1264 (org-trim rtn)))
1266 (defun org-columns-compile-format (fmt)
1267 "Turn a column format string into an alist of specifications.
1268 The alist has one entry for each column in the format. The elements of
1269 that list are:
1270 property the property
1271 title the title field for the columns
1272 width the column width in characters, can be nil for automatic
1273 operator the operator if any
1274 format the output format for computed results, derived from operator
1275 printf a printf format for computed values
1276 fun the lisp function to compute summary values, derived from operator
1277 calc function to get values from base elements"
1278 (let ((start 0) width prop title op op-match f printf fun calc)
1279 (setq org-columns-current-fmt-compiled nil)
1280 (while (string-match
1281 (org-re "%\\([0-9]+\\)?\\([[:alnum:]_-]+\\)\\(?:(\\([^)]+\\))\\)?\\(?:{\\([^}]+\\)}\\)?\\s-*")
1282 fmt start)
1283 (setq start (match-end 0)
1284 width (match-string 1 fmt)
1285 prop (match-string 2 fmt)
1286 title (or (match-string 3 fmt) prop)
1287 op (match-string 4 fmt)
1288 f nil
1289 printf nil
1290 fun '+
1291 calc nil)
1292 (if width (setq width (string-to-number width)))
1293 (when (and op (string-match ";" op))
1294 (setq printf (substring op (match-end 0))
1295 op (substring op 0 (match-beginning 0))))
1296 (when (setq op-match (assoc op org-columns-compile-map))
1297 (setq f (cadr op-match)
1298 fun (caddr op-match)
1299 calc (cadddr op-match)))
1300 (push (list prop title width op f printf fun calc)
1301 org-columns-current-fmt-compiled))
1302 (setq org-columns-current-fmt-compiled
1303 (nreverse org-columns-current-fmt-compiled))))
1306 ;;; Dynamic block for Column view
1308 (defun org-columns-capture-view (&optional maxlevel skip-empty-rows)
1309 "Get the column view of the current buffer or subtree.
1310 The first optional argument MAXLEVEL sets the level limit. A
1311 second optional argument SKIP-EMPTY-ROWS tells whether to skip
1312 empty rows, an empty row being one where all the column view
1313 specifiers except ITEM are empty. This function returns a list
1314 containing the title row and all other rows. Each row is a list
1315 of fields."
1316 (if (featurep 'xemacs)
1317 (save-excursion
1318 (let* ((title (mapcar 'cadr org-columns-current-fmt-compiled))
1319 (re-comment (format org-heading-keyword-regexp-format
1320 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 org-heading-regexp 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 (case-fold-search t)
1405 tbl id idpos nfields tmp recalc line
1406 id-as-string view-file view-pos)
1407 (when (setq id (plist-get params :id))
1408 (setq id-as-string (cond ((numberp id) (number-to-string id))
1409 ((symbolp id) (symbol-name id))
1410 ((stringp id) id)
1411 (t "")))
1412 (cond ((not id) nil)
1413 ((eq id 'global) (setq view-pos (point-min)))
1414 ((eq id 'local))
1415 ((string-match "^file:\\(.*\\)" id-as-string)
1416 (setq view-file (match-string 1 id-as-string)
1417 view-pos 1)
1418 (unless (file-exists-p view-file)
1419 (error "No such file: \"%s\"" id-as-string)))
1420 ((setq idpos (org-find-entry-with-id id))
1421 (setq view-pos idpos))
1422 ((setq idpos (org-id-find id))
1423 (setq view-file (car idpos))
1424 (setq view-pos (cdr idpos)))
1425 (t (error "Cannot find entry with :ID: %s" id))))
1426 (with-current-buffer (if view-file
1427 (get-file-buffer view-file)
1428 (current-buffer))
1429 (save-excursion
1430 (save-restriction
1431 (widen)
1432 (goto-char (or view-pos (point)))
1433 (org-columns)
1434 (setq tbl (org-columns-capture-view maxlevel skip-empty-rows))
1435 (setq nfields (length (car tbl)))
1436 (org-columns-quit))))
1437 (goto-char pos)
1438 (move-marker pos nil)
1439 (when tbl
1440 (when (plist-get params :hlines)
1441 (setq tmp nil)
1442 (while tbl
1443 (if (eq (car tbl) 'hline)
1444 (push (pop tbl) tmp)
1445 (if (string-match "\\` *\\(\\*+\\)" (caar tbl))
1446 (if (and (not (eq (car tmp) 'hline))
1447 (or (eq hlines t)
1448 (and (numberp hlines)
1449 (<= (- (match-end 1) (match-beginning 1))
1450 hlines))))
1451 (push 'hline tmp)))
1452 (push (pop tbl) tmp)))
1453 (setq tbl (nreverse tmp)))
1454 (when vlines
1455 (setq tbl (mapcar (lambda (x)
1456 (if (eq 'hline x) x (cons "" x)))
1457 tbl))
1458 (setq tbl (append tbl (list (cons "/" (make-list nfields "<>"))))))
1459 (setq pos (point))
1460 (when content-lines
1461 (while (string-match "^#" (car content-lines))
1462 (insert (pop content-lines) "\n")))
1463 (insert (org-listtable-to-string tbl))
1464 (when (plist-get params :width)
1465 (insert "\n|" (mapconcat (lambda (x) (format "<%d>" (max 3 x)))
1466 org-columns-current-widths "|")))
1467 (while (setq line (pop content-lines))
1468 (when (string-match "^#" line)
1469 (insert "\n" line)
1470 (when (string-match "^[ \t]*#\\+tblfm" line)
1471 (setq recalc t))))
1472 (if recalc
1473 (progn (goto-char pos) (org-table-recalculate 'all))
1474 (goto-char pos)
1475 (org-table-align)))))
1477 (defun org-listtable-to-string (tbl)
1478 "Convert a listtable TBL to a string that contains the Org-mode table.
1479 The table still need to be aligned. The resulting string has no leading
1480 and tailing newline characters."
1481 (mapconcat
1482 (lambda (x)
1483 (cond
1484 ((listp x)
1485 (concat "|" (mapconcat 'identity x "|") "|"))
1486 ((eq x 'hline) "|-|")
1487 (t (error "Garbage in listtable: %s" x))))
1488 tbl "\n"))
1490 (defun org-insert-columns-dblock ()
1491 "Create a dynamic block capturing a column view table."
1492 (interactive)
1493 (when (featurep 'xemacs) (org-columns-quit))
1494 (let ((defaults '(:name "columnview" :hlines 1))
1495 (id (org-icompleting-read
1496 "Capture columns (local, global, entry with :ID: property) [local]: "
1497 (append '(("global") ("local"))
1498 (mapcar 'list (org-property-values "ID"))))))
1499 (if (equal id "") (setq id 'local))
1500 (if (equal id "global") (setq id 'global))
1501 (setq defaults (append defaults (list :id id)))
1502 (org-create-dblock defaults)
1503 (org-update-dblock)))
1505 ;;; Column view in the agenda
1507 (defvar org-agenda-view-columns-initially nil
1508 "When set, switch to columns view immediately after creating the agenda.")
1510 (defvar org-agenda-columns-show-summaries) ; defined in org-agenda.el
1511 (defvar org-agenda-columns-compute-summary-properties); defined in org-agenda.el
1512 (defvar org-agenda-columns-add-appointments-to-effort-sum); as well
1514 (defun org-agenda-columns ()
1515 "Turn on or update column view in the agenda."
1516 (interactive)
1517 (org-verify-version 'columns)
1518 (org-columns-remove-overlays)
1519 (move-marker org-columns-begin-marker (point))
1520 (let ((org-columns-time (time-to-number-of-days (current-time)))
1521 cache maxwidths m p a d fmt)
1522 (cond
1523 ((and (boundp 'org-agenda-overriding-columns-format)
1524 org-agenda-overriding-columns-format)
1525 (setq fmt org-agenda-overriding-columns-format)
1526 (org-set-local 'org-agenda-overriding-columns-format fmt))
1527 ((setq m (org-get-at-bol 'org-hd-marker))
1528 (setq fmt (or (org-entry-get m "COLUMNS" t)
1529 (with-current-buffer (marker-buffer m)
1530 org-columns-default-format))))
1531 ((and (boundp 'org-columns-current-fmt)
1532 (local-variable-p 'org-columns-current-fmt (current-buffer))
1533 org-columns-current-fmt)
1534 (setq fmt org-columns-current-fmt))
1535 ((setq m (next-single-property-change (point-min) 'org-hd-marker))
1536 (setq m (get-text-property m 'org-hd-marker))
1537 (setq fmt (or (org-entry-get m "COLUMNS" t)
1538 (with-current-buffer (marker-buffer m)
1539 org-columns-default-format)))))
1540 (setq fmt (or fmt org-columns-default-format))
1541 (org-set-local 'org-columns-current-fmt fmt)
1542 (org-columns-compile-format fmt)
1543 (when org-agenda-columns-compute-summary-properties
1544 (org-agenda-colview-compute org-columns-current-fmt-compiled))
1545 (save-excursion
1546 ;; Get and cache the properties
1547 (goto-char (point-min))
1548 (while (not (eobp))
1549 (when (setq m (or (org-get-at-bol 'org-hd-marker)
1550 (org-get-at-bol 'org-marker)))
1551 (setq p (org-entry-properties m))
1553 (when (or (not (setq a (assoc org-effort-property p)))
1554 (not (string-match "\\S-" (or (cdr a) ""))))
1555 ;; OK, the property is not defined. Use appointment duration?
1556 (when (and org-agenda-columns-add-appointments-to-effort-sum
1557 (setq d (get-text-property (point) 'duration)))
1558 (setq d (org-minutes-to-hh:mm-string d))
1559 (put-text-property 0 (length d) 'face 'org-warning d)
1560 (push (cons org-effort-property d) p)))
1561 (push (cons (org-current-line) p) cache))
1562 (beginning-of-line 2))
1563 (when cache
1564 (setq maxwidths (org-columns-get-autowidth-alist fmt cache))
1565 (org-set-local 'org-columns-current-maxwidths maxwidths)
1566 (org-columns-display-here-title)
1567 (mapc (lambda (x)
1568 (org-goto-line (car x))
1569 (org-columns-display-here (cdr x)))
1570 cache)
1571 (when org-agenda-columns-show-summaries
1572 (org-agenda-colview-summarize cache))))))
1574 (defun org-agenda-colview-summarize (cache)
1575 "Summarize the summarizable columns in column view in the agenda.
1576 This will add overlays to the date lines, to show the summary for each day."
1577 (let* ((fmt (mapcar (lambda (x)
1578 (if (equal (car x) "CLOCKSUM")
1579 (list "CLOCKSUM" (nth 2 x) nil 'add_times nil '+ 'identity)
1580 (cdr x)))
1581 org-columns-current-fmt-compiled))
1582 line c c1 stype calc sumfunc props lsum entries prop v)
1583 (catch 'exit
1584 (when (delq nil (mapcar 'cadr fmt))
1585 ;; OK, at least one summation column, it makes sense to try this
1586 (goto-char (point-max))
1587 (while t
1588 (when (or (get-text-property (point) 'org-date-line)
1589 (eq (get-text-property (point) 'face)
1590 'org-agenda-structure))
1591 ;; OK, this is a date line that should be used
1592 (setq line (org-current-line))
1593 (setq entries nil c cache cache nil)
1594 (while (setq c1 (pop c))
1595 (if (> (car c1) line)
1596 (push c1 entries)
1597 (push c1 cache)))
1598 ;; now ENTRIES are the ones we want to use, CACHE is the rest
1599 ;; Compute the summaries for the properties we want,
1600 ;; set nil properties for the rest.
1601 (when (setq entries (mapcar 'cdr entries))
1602 (setq props
1603 (mapcar
1604 (lambda (f)
1605 (setq prop (car f)
1606 stype (nth 3 f)
1607 sumfunc (nth 5 f)
1608 calc (or (nth 6 f) 'identity))
1609 (cond
1610 ((equal prop "ITEM")
1611 (cons prop (buffer-substring (point-at-bol)
1612 (point-at-eol))))
1613 ((not stype) (cons prop ""))
1614 (t ;; do the summary
1615 (setq lsum nil)
1616 (dolist (x entries)
1617 (setq v (cdr (assoc prop x)))
1618 (if v
1619 (push
1620 (funcall
1621 (if (not (get-text-property 0 'org-computed v))
1622 calc
1623 'identity)
1624 (org-columns-string-to-number
1625 v stype))
1626 lsum)))
1627 (setq lsum (remove nil lsum))
1628 (setq lsum
1629 (cond ((> (length lsum) 1)
1630 (org-columns-number-to-string
1631 (apply sumfunc lsum) stype))
1632 ((eq (length lsum) 1)
1633 (org-columns-number-to-string
1634 (car lsum) stype))
1635 (t "")))
1636 (put-text-property 0 (length lsum) 'face 'bold lsum)
1637 (unless (eq calc 'identity)
1638 (put-text-property 0 (length lsum) 'org-computed t lsum))
1639 (cons prop lsum))))
1640 fmt))
1641 (org-columns-display-here props)
1642 (org-set-local 'org-agenda-columns-active t)))
1643 (if (bobp) (throw 'exit t))
1644 (beginning-of-line 0))))))
1646 (defun org-agenda-colview-compute (fmt)
1647 "Compute the relevant columns in the contributing source buffers."
1648 (let ((files org-agenda-contributing-files)
1649 (org-columns-begin-marker (make-marker))
1650 (org-columns-top-level-marker (make-marker))
1651 f fm a b)
1652 (while (setq f (pop files))
1653 (setq b (find-buffer-visiting f))
1654 (with-current-buffer (or (buffer-base-buffer b) b)
1655 (save-excursion
1656 (save-restriction
1657 (widen)
1658 (org-unmodified
1659 (remove-text-properties (point-min) (point-max)
1660 '(org-summaries t)))
1661 (goto-char (point-min))
1662 (org-columns-get-format-and-top-level)
1663 (while (setq fm (pop fmt))
1664 (if (equal (car fm) "CLOCKSUM")
1665 (org-clock-sum)
1666 (when (and (nth 4 fm)
1667 (setq a (assoc (car fm)
1668 org-columns-current-fmt-compiled))
1669 (equal (nth 4 a) (nth 4 fm)))
1670 (org-columns-compute (car fm)))))))))))
1672 (defun org-format-time-period (interval)
1673 "Convert time in fractional days to days/hours/minutes/seconds."
1674 (if (numberp interval)
1675 (let* ((days (floor interval))
1676 (frac-hours (* 24 (- interval days)))
1677 (hours (floor frac-hours))
1678 (minutes (floor (* 60 (- frac-hours hours))))
1679 (seconds (floor (* 60 (- (* 60 (- frac-hours hours)) minutes)))))
1680 (format "%dd %02dh %02dm %02ds" days hours minutes seconds))
1681 ""))
1683 (defun org-estimate-mean-and-var (v)
1684 "Return the mean and variance of an estimate."
1685 (let* ((low (float (car v)))
1686 (high (float (cadr v)))
1687 (mean (/ (+ low high) 2.0))
1688 (var (/ (+ (expt (- mean low) 2.0) (expt (- high mean) 2.0)) 2.0)))
1689 (list mean var)))
1691 (defun org-estimate-combine (&rest el)
1692 "Combine a list of estimates, using mean and variance.
1693 The mean and variance of the result will be the sum of the means
1694 and variances (respectively) of the individual estimates."
1695 (let ((mean 0)
1696 (var 0))
1697 (mapc (lambda (e)
1698 (let ((stats (org-estimate-mean-and-var e)))
1699 (setq mean (+ mean (car stats)))
1700 (setq var (+ var (cadr stats)))))
1702 (let ((stdev (sqrt var)))
1703 (list (- mean stdev) (+ mean stdev)))))
1705 (defun org-estimate-print (e &optional fmt)
1706 "Prepare a string representation of an estimate.
1707 This formats these numbers as two numbers with a \"-\" between them."
1708 (if (null fmt) (set 'fmt "%.0f"))
1709 (format "%s" (mapconcat (lambda (n) (format fmt n)) e "-")))
1711 (defun org-string-to-estimate (s)
1712 "Convert a string to an estimate.
1713 The string should be two numbers joined with a \"-\"."
1714 (if (string-match "\\(.*\\)-\\(.*\\)" s)
1715 (list (string-to-number (match-string 1 s))
1716 (string-to-number(match-string 2 s)))
1717 (list (string-to-number s) (string-to-number s))))
1719 (provide 'org-colview)
1720 (provide 'org-colview-xemacs)
1722 ;;; org-colview-xemacs.el ends here