浏览代码

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

Carsten Dominik 17 年之前
父节点
当前提交
0fba6ef10c
共有 2 个文件被更改,包括 17 次插入5 次删除
  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
 	follow each other.  Such lists may be created by headlines that
 	are converted to lists.
+	(org-nofm-to-completion): New function.
 
 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))
 			    org-columns-overlays)))
 	 (allowed (or (org-property-get-allowed-values pom key)
-		      (and (equal
+		      (and (memq
 			    (nth 4 (assoc key org-columns-current-fmt-compiled))
-			    'checkbox) '("[ ]" "[X]"))))
+			    '(checkbox checkbox-n-of-m checkbox-percent))
+			   '("[ ]" "[X]"))))
 	 nval)
     (when (equal key "ITEM")
       (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]")
 	  ((> n 1.) "[-]")
 	  (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))
    ((eq fmt 'currency)
     (format "%.2f" 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)
   "Convert a column value to a number that can be used for column computing."
   (cond
@@ -17173,7 +17182,7 @@ display, or in the #+COLUMNS line of the current buffer."
       (while l
 	(setq sum (+ (string-to-number (pop l)) (/ sum 60))))
       sum))
-   ((eq fmt 'checkbox)
+   ((memq fmt '(checkbox checkbox-n-of-m checkbox-percent))
     (if (equal s "[X]") 1. 0.000001))
    (t (string-to-number s))))
 
@@ -17190,6 +17199,8 @@ display, or in the #+COLUMNS line of the current buffer."
       (cond
        ((eq fmt 'add_times) (setq op ":"))
        ((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 'currency) (setq op "$")))
       (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 '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-n-of-m))
+       ((equal op "X%") (setq f 'checkbox-percent))
        )
       (push (list prop title width op f printf) org-columns-current-fmt-compiled))
     (setq org-columns-current-fmt-compiled