org-clock.el: New function `org-clock-sum-custom'

* org-clock.el (org-clock-sum-today): Use `headline-filter'.
Remove interactive form.
(org-clock-display): Change the meaning of prefix argument:
one prefix arg shows today's time; two prefix args show clocks
from a custom range; three prefix args show the total time in
the echo area.
(org-clock-sum-custom): New function.
(org-clock-sum): Remove interactive form.
This commit is contained in:
Bastien Guerry 2014-04-20 15:09:32 +02:00
parent cea5ab81ea
commit b5554077cb
1 changed files with 38 additions and 14 deletions

View File

@ -1712,9 +1712,21 @@ With prefix arg SELECT, offer recently clocked tasks for selection."
(defun org-clock-sum-today (&optional headline-filter) (defun org-clock-sum-today (&optional headline-filter)
"Sum the times for each subtree for today." "Sum the times for each subtree for today."
(interactive)
(let ((range (org-clock-special-range 'today))) (let ((range (org-clock-special-range 'today)))
(org-clock-sum (car range) (cadr range) nil :org-clock-minutes-today))) (org-clock-sum (car range) (cadr range)
headline-filter :org-clock-minutes-today)))
(defun org-clock-sum-custom (&optional headline-filter)
"Sum the times for each subtree for today."
(let ((range
(org-clock-special-range
(intern (completing-read
"Range: "
'("today" "yesterday" "thisweek" "lastweek"
"thismonth" "lastmonth" "thisyear" "lastyear")
nil t)))))
(org-clock-sum (car range) (cadr range)
headline-filter :org-clock-minutes-custom)))
;;;###autoload ;;;###autoload
(defun org-clock-sum (&optional tstart tend headline-filter propname) (defun org-clock-sum (&optional tstart tend headline-filter propname)
@ -1725,7 +1737,6 @@ HEADLINE-FILTER is a zero-arg function that, if specified, is called for
each headline in the time range with point at the headline. Headlines for each headline in the time range with point at the headline. Headlines for
which HEADLINE-FILTER returns nil are excluded from the clock summation. which HEADLINE-FILTER returns nil are excluded from the clock summation.
PROPNAME lets you set a custom text property instead of :org-clock-minutes." PROPNAME lets you set a custom text property instead of :org-clock-minutes."
(interactive)
(org-with-silent-modifications (org-with-silent-modifications
(let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*" (let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
org-clock-string org-clock-string
@ -1817,25 +1828,35 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes."
org-clock-file-total-minutes))) org-clock-file-total-minutes)))
;;;###autoload ;;;###autoload
(defun org-clock-display (&optional total-only) (defun org-clock-display (arg)
"Show subtree times in the entire buffer. "Show subtree times in the entire buffer.
If TOTAL-ONLY is non-nil, only show the total time for the entire file
in the echo area. With one universal prefix argument, show the total time for
today. With two universal prefix arguments, show the total time
for a custom range, entered at the prompt. With three universal
prefix arguments, show the total time in the echo area.
Use \\[org-clock-remove-overlays] to remove the subtree times." Use \\[org-clock-remove-overlays] to remove the subtree times."
(interactive) (interactive "P")
(org-clock-remove-overlays) (org-clock-remove-overlays)
(let (time h m p) (let* ((todayp (equal arg '(4)))
(org-clock-sum) (customp (equal arg '(16)))
(unless total-only (prop (cond (todayp :org-clock-minutes-today)
(customp :org-clock-minutes-custom)
(t :org-clock-minutes)))
time h m p)
(cond (todayp (org-clock-sum-today))
(customp (org-clock-sum-custom))
(t (org-clock-sum)))
(unless (eq arg '(64))
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(while (or (and (equal (setq p (point)) (point-min)) (while (or (and (equal (setq p (point)) (point-min))
(get-text-property p :org-clock-minutes)) (get-text-property p prop))
(setq p (next-single-property-change (setq p (next-single-property-change
(point) :org-clock-minutes))) (point) prop)))
(goto-char p) (goto-char p)
(when (setq time (get-text-property p :org-clock-minutes)) (when (setq time (get-text-property p prop))
(org-clock-put-overlay time))) (org-clock-put-overlay time)))
(setq h (/ org-clock-file-total-minutes 60) (setq h (/ org-clock-file-total-minutes 60)
m (- org-clock-file-total-minutes (* 60 h))) m (- org-clock-file-total-minutes (* 60 h)))
@ -1843,7 +1864,10 @@ Use \\[org-clock-remove-overlays] to remove the subtree times."
(when org-remove-highlights-with-change (when org-remove-highlights-with-change
(org-add-hook 'before-change-functions 'org-clock-remove-overlays (org-add-hook 'before-change-functions 'org-clock-remove-overlays
nil 'local)))) nil 'local))))
(message (concat "Total file time: " (message (concat (format "Total file time%s: "
(cond (todayp " for today")
(customp " (custom)")
(t "")))
(org-minutes-to-clocksum-string org-clock-file-total-minutes) (org-minutes-to-clocksum-string org-clock-file-total-minutes)
" (%d hours and %d minutes)") h m))) " (%d hours and %d minutes)") h m)))