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