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