org-colview: Fix summary computation in agenda

* lisp/org-colview.el (org-agenda-colview-summarize): Do not include
  already summarized values in current summary.
This commit is contained in:
Nicolas Goaziou 2017-01-17 12:00:49 +01:00
parent b223c099f0
commit d2af251077
1 changed files with 46 additions and 42 deletions

View File

@ -1566,55 +1566,59 @@ This will add overlays to the date lines, to show the summary for each day."
(if (member property '("CLOCKSUM" "CLOCKSUM_T"))
(list property title width ":" nil)
spec))))
org-columns-current-fmt-compiled))
entries)
org-columns-current-fmt-compiled)))
;; Ensure there's at least one summation column.
(when (cl-some (lambda (spec) (nth 3 spec)) fmt)
(goto-char (point-max))
(catch :complete
(while t
(when (or (get-text-property (point) 'org-date-line)
(eq (get-text-property (point) 'face) 'org-agenda-structure))
(eq (get-text-property (point) 'face)
'org-agenda-structure))
;; OK, this is a date line that should be used.
(let (rest)
(dolist (c cache (setq cache rest))
(if (> (car c) (point))
(push c entries)
(push c rest))))
;; Now ENTRIES contains entries below the current one.
;; CACHE is the rest. Compute the summaries for the
;; properties we want, set nil properties for the rest.
(when (setq entries (mapcar #'cdr entries))
(org-columns--display-here
(mapcar
(lambda (spec)
(pcase spec
(`("ITEM" . ,_)
;; Replace ITEM with current date. Preserve
;; properties for fontification.
(let ((date (buffer-substring
(line-beginning-position)
(line-end-position))))
(list spec date date)))
(`(,_ ,_ ,_ nil ,_) (list spec "" ""))
(`(,_ ,_ ,_ ,operator ,printf)
(let* ((summarize (org-columns--summarize operator))
(values
;; Use real values for summary, not those
;; prepared for display.
(delq nil
(mapcar
(lambda (e)
(org-string-nw-p (nth 1 (assoc spec e))))
entries)))
(final (if values (funcall summarize values printf)
"")))
(unless (equal final "")
(put-text-property 0 (length final) 'face 'bold final))
(list spec final final)))))
fmt)
'dateline)
(setq-local org-agenda-columns-active t)))
(let (entries)
(let (rest)
(dolist (c cache)
(if (> (car c) (point))
(push c entries)
(push c rest)))
(setq cache rest))
;; ENTRIES contains entries below the current one.
;; CACHE is the rest. Compute the summaries for the
;; properties we want, set nil properties for the rest.
(when (setq entries (mapcar #'cdr entries))
(org-columns--display-here
(mapcar
(lambda (spec)
(pcase spec
(`("ITEM" . ,_)
;; Replace ITEM with current date. Preserve
;; properties for fontification.
(let ((date (buffer-substring
(line-beginning-position)
(line-end-position))))
(list spec date date)))
(`(,_ ,_ ,_ nil ,_) (list spec "" ""))
(`(,_ ,_ ,_ ,operator ,printf)
(let* ((summarize (org-columns--summarize operator))
(values
;; Use real values for summary, not
;; those prepared for display.
(delq nil
(mapcar
(lambda (e) (org-string-nw-p
(nth 1 (assoc spec e))))
entries)))
(final (if values
(funcall summarize values printf)
"")))
(unless (equal final "")
(put-text-property 0 (length final)
'face 'bold final))
(list spec final final)))))
fmt)
'dateline)
(setq-local org-agenda-columns-active t))))
(if (bobp) (throw :complete t) (forward-line -1)))))))
(defun org-agenda-colview-compute (fmt)