소스 검색

TODO statistics: Fix bug with counting and hook calling

When there were multiple cookies in a headline, the counting would be
double.  Also the hook got called always, even if no cookie was
present.
Fixed now.
Carsten Dominik 16 년 전
부모
커밋
0edabb9408
2개의 변경된 파일7개의 추가작업 그리고 3개의 파일을 삭제
  1. 2 0
      lisp/ChangeLog
  2. 5 3
      lisp/org.el

+ 2 - 0
lisp/ChangeLog

@@ -1,6 +1,8 @@
 2009-02-02  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-02-02  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org.el (org-mode): Make dependence stuff work more reliably.
 	* org.el (org-mode): Make dependence stuff work more reliably.
+	(org-update-parent-todo-statistics): Fix bug with updating
+	statistics cookie.
 
 
 	* org-export-latex.el (org-export-latex-emphasis-alist): Use = and
 	* org-export-latex.el (org-export-latex-emphasis-alist): Use = and
 	~ as verbatim delimiters.
 	~ as verbatim delimiters.

+ 5 - 3
lisp/org.el

@@ -8645,13 +8645,14 @@ changes because there are uncheckd boxes in this entry."
   "Update any statistics cookie in the parent of the current headline."
   "Update any statistics cookie in the parent of the current headline."
   (interactive)
   (interactive)
   (let ((box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
   (let ((box-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)")
-	level (cnt-all 0) (cnt-done 0) is-percent kwd)
+	level (cnt-all 0) (cnt-done 0) is-percent kwd cookie-present)
     (catch 'exit
     (catch 'exit
       (save-excursion
       (save-excursion
 	(setq level (org-up-heading-safe))
 	(setq level (org-up-heading-safe))
 	(unless level
 	(unless level
 	  (throw 'exit nil))
 	  (throw 'exit nil))
 	(while (re-search-forward box-re (point-at-eol) t)
 	(while (re-search-forward box-re (point-at-eol) t)
+	  (setq cnt-all 0 cnt-done 0 cookie-present t)
 	  (setq is-percent (match-end 2))
 	  (setq is-percent (match-end 2))
 	  (save-match-data
 	  (save-match-data
 	    (unless (outline-next-heading) (throw 'exit nil))
 	    (unless (outline-next-heading) (throw 'exit nil))
@@ -8667,8 +8668,9 @@ changes because there are uncheckd boxes in this entry."
 	   (if is-percent
 	   (if is-percent
 	       (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
 	       (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all)))
 	     (format "[%d/%d]" cnt-done cnt-all))))
 	     (format "[%d/%d]" cnt-done cnt-all))))
-	(run-hook-with-args 'org-after-todo-statistics-hook
-			    cnt-done (- cnt-all cnt-done))))))
+	(when cookie-present
+	  (run-hook-with-args 'org-after-todo-statistics-hook
+			      cnt-done (- cnt-all cnt-done)))))))
 
 
 (defvar org-after-todo-statistics-hook nil
 (defvar org-after-todo-statistics-hook nil
   "Hook that is called after a TODO statistics cookie has been updated.
   "Hook that is called after a TODO statistics cookie has been updated.