Browse Source

Allow relative completion cookies for column view summation.
Requested by Daniel J. Sinder.

Carsten Dominik 17 years ago
parent
commit
0fba6ef10c
2 changed files with 17 additions and 5 deletions
  1. 1 0
      ChangeLog
  2. 16 5
      org.el

+ 1 - 0
ChangeLog

@@ -5,6 +5,7 @@
 	(org-export-as-html): Join unsorted lists when they directly
 	(org-export-as-html): Join unsorted lists when they directly
 	follow each other.  Such lists may be created by headlines that
 	follow each other.  Such lists may be created by headlines that
 	are converted to lists.
 	are converted to lists.
+	(org-nofm-to-completion): New function.
 
 
 2008-02-12  Bastien Guerry  <bzg@altern.org>
 2008-02-12  Bastien Guerry  <bzg@altern.org>
 
 

+ 16 - 5
org.el

@@ -16756,9 +16756,10 @@ Where possible, use the standard interface for changing this line."
 				   x))
 				   x))
 			    org-columns-overlays)))
 			    org-columns-overlays)))
 	 (allowed (or (org-property-get-allowed-values pom key)
 	 (allowed (or (org-property-get-allowed-values pom key)
-		      (and (equal
+		      (and (memq
 			    (nth 4 (assoc key org-columns-current-fmt-compiled))
 			    (nth 4 (assoc key org-columns-current-fmt-compiled))
-			    'checkbox) '("[ ]" "[X]"))))
+			    '(checkbox checkbox-n-of-m checkbox-percent))
+			   '("[ ]" "[X]"))))
 	 nval)
 	 nval)
     (when (equal key "ITEM")
     (when (equal key "ITEM")
       (error "Cannot edit item headline from here"))
       (error "Cannot edit item headline from here"))
@@ -17160,11 +17161,19 @@ display, or in the #+COLUMNS line of the current buffer."
     (cond ((= n (floor n)) "[X]")
     (cond ((= n (floor n)) "[X]")
 	  ((> n 1.) "[-]")
 	  ((> n 1.) "[-]")
 	  (t "[ ]")))
 	  (t "[ ]")))
+   ((memq fmt '(checkbox-n-of-m checkbox-percent))
+    (let* ((n1 (floor n)) (n2 (floor (+ .5 (* 1000000 (- n n1))))))
+      (org-nofm-to-completion n1 (+ n2 n1) (eq fmt 'checkbox-percent))))
    (printf (format printf n))
    (printf (format printf n))
    ((eq fmt 'currency)
    ((eq fmt 'currency)
     (format "%.2f" n))
     (format "%.2f" n))
    (t (number-to-string n))))
    (t (number-to-string n))))
 
 
+(defun org-nofm-to-completion (n m &optional percent)
+  (if (not percent)
+      (format "[%d/%d]" n m)
+    (format "[%d%%]"(floor (+ 0.5 (* 100. (/ (* 1.0 n) m)))))))
+
 (defun org-column-string-to-number (s fmt)
 (defun org-column-string-to-number (s fmt)
   "Convert a column value to a number that can be used for column computing."
   "Convert a column value to a number that can be used for column computing."
   (cond
   (cond
@@ -17173,7 +17182,7 @@ display, or in the #+COLUMNS line of the current buffer."
       (while l
       (while l
 	(setq sum (+ (string-to-number (pop l)) (/ sum 60))))
 	(setq sum (+ (string-to-number (pop l)) (/ sum 60))))
       sum))
       sum))
-   ((eq fmt 'checkbox)
+   ((memq fmt '(checkbox checkbox-n-of-m checkbox-percent))
     (if (equal s "[X]") 1. 0.000001))
     (if (equal s "[X]") 1. 0.000001))
    (t (string-to-number s))))
    (t (string-to-number s))))
 
 
@@ -17190,6 +17199,8 @@ display, or in the #+COLUMNS line of the current buffer."
       (cond
       (cond
        ((eq fmt 'add_times) (setq op ":"))
        ((eq fmt 'add_times) (setq op ":"))
        ((eq fmt 'checkbox) (setq op "X"))
        ((eq fmt 'checkbox) (setq op "X"))
+       ((eq fmt 'checkbox-n-of-m) (setq op "X/"))
+       ((eq fmt 'checkbox-percent) (setq op "X%"))
        ((eq fmt 'add_numbers) (setq op "+"))
        ((eq fmt 'add_numbers) (setq op "+"))
        ((eq fmt 'currency) (setq op "$")))
        ((eq fmt 'currency) (setq op "$")))
       (if (and op printf) (setq op (concat op ";" printf)))
       (if (and op printf) (setq op (concat op ";" printf)))
@@ -17232,8 +17243,8 @@ printf       a printf format for computed values"
        ((equal op "$")  (setq f 'currency))
        ((equal op "$")  (setq f 'currency))
        ((equal op ":")  (setq f 'add_times))
        ((equal op ":")  (setq f 'add_times))
        ((equal op "X")  (setq f 'checkbox))
        ((equal op "X")  (setq f 'checkbox))
-       ((equal op "X/") (setq f 'checkbox))
-       ((equal op "X%") (setq f 'checkbox))
+       ((equal op "X/") (setq f 'checkbox-n-of-m))
+       ((equal op "X%") (setq f 'checkbox-percent))
        )
        )
       (push (list prop title width op f printf) org-columns-current-fmt-compiled))
       (push (list prop title width op f printf) org-columns-current-fmt-compiled))
     (setq org-columns-current-fmt-compiled
     (setq org-columns-current-fmt-compiled