浏览代码

Column View: Handle empty fields when computing

Carsten Dominik 16 年之前
父节点
当前提交
f49cee2cc4
共有 3 个文件被更改,包括 18 次插入6 次删除
  1. 6 0
      lisp/ChangeLog
  2. 6 3
      lisp/org-colview-xemacs.el
  3. 6 3
      lisp/org-colview.el

+ 6 - 0
lisp/ChangeLog

@@ -1,5 +1,11 @@
 2009-05-21  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-colview-xemacs.el (org-columns-compute)
+	(org-columns-number-to-string): Fix problems with empty fields.
+
+	* org-colview.el (org-columns-compute)
+	(org-columns-number-to-string): Fix problems with empty fields.
+
 	* org-exp.el (org-export-push-to-kill-ring): New function.
 	(org-export-copy-to-kill-ring): New option.
 

+ 6 - 3
lisp/org-colview-xemacs.el

@@ -1097,7 +1097,8 @@ Don't set this, this is meant for dynamic scoping.")
 	(cond
 	 ((< level last-level)
 	  ;; put the sum of lower levels here as a property
-	  (setq sum (apply fun (aref lvals last-level))
+	  (setq sum (when (aref lvals last-level)
+		      (apply fun (aref lvals last-level)))
 		flag (aref lflag last-level) ; any valid entries from children?
 		str (org-columns-number-to-string sum format printf)
 		str1 (org-add-props (copy-sequence str) nil 'org-computed t 'face 'bold)
@@ -1123,9 +1124,10 @@ Don't set this, this is meant for dynamic scoping.")
 		(aset lflag l nil)))
 	 ((>= level last-level)
 	  ;; add what we have here to the accumulator for this level
-	  (push (org-column-string-to-number (or val "0") format)
+	  (when valflag
+	    (push (org-column-string-to-number val format)
 		(aref lvals level))
-	  (and valflag (aset lflag level t)))
+	    (aset lflag level t)))
 	 (t (error "This should not happen")))))))
 
 (defun org-columns-redo ()
@@ -1163,6 +1165,7 @@ Don't set this, this is meant for dynamic scoping.")
 (defun org-columns-number-to-string (n fmt &optional printf)
   "Convert a computed column number to a string value, according to FMT."
   (cond
+   ((not (numberp n)) "")
    ((memq fmt '(add_times max_times min_times mean_times))
     (let* ((h (floor n)) (m (floor (+ 0.5 (* 60 (- n h))))))
       (format org-time-clocksum-format h m)))

+ 6 - 3
lisp/org-colview.el

@@ -910,7 +910,8 @@ Don't set this, this is meant for dynamic scoping.")
 	(cond
 	 ((< level last-level)
 	  ;; put the sum of lower levels here as a property
-	  (setq sum (apply fun (aref lvals last-level))
+	  (setq sum (when (aref lvals last-level)
+		      (apply fun (aref lvals last-level)))
 		flag (aref lflag last-level) ; any valid entries from children?
 		str (org-columns-number-to-string sum format printf)
 		str1 (org-add-props (copy-sequence str) nil 'org-computed t 'face 'bold)
@@ -936,9 +937,10 @@ Don't set this, this is meant for dynamic scoping.")
 		(aset lflag l nil)))
 	 ((>= level last-level)
 	  ;; add what we have here to the accumulator for this level
-	  (push (org-column-string-to-number (or val "0") format)
+	  (when valflag
+	    (push (org-column-string-to-number val format)
 		(aref lvals level))
-	  (and valflag (aset lflag level t)))
+	    (aset lflag level t)))
 	 (t (error "This should not happen")))))))
 
 (defun org-columns-redo ()
@@ -976,6 +978,7 @@ Don't set this, this is meant for dynamic scoping.")
 (defun org-columns-number-to-string (n fmt &optional printf)
   "Convert a computed column number to a string value, according to FMT."
   (cond
+   ((not (numberp n)) "")
    ((memq fmt '(add_times max_times min_times mean_times))
     (let* ((h (floor n)) (m (floor (+ 0.5 (* 60 (- n h))))))
       (format org-time-clocksum-format h m)))