@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

org-clockで今日の作業時間の合計のみをmode-lineに表示する

デフォルトだとその見出し全体の作業時間の合計がmode-lineに表示される。

毎日繰り返す作業も計時しているので、今日その作業にどれくらい時間をかけているのかを見たかった。

見出し毎の設定

CLOCK_MODELINE_TOTALというプロパティにtodayを設定すれば良い。各見出しに下記のように設定すれば、その見出しは今日の作業分だけ合計される。

* 毎日する作業
  :PROPERTIES:
  :CLOCK_MODELINE_TOTAL: today
  :END:
  :LOGBOOK:
  CLOCK: [2016-02-09 Tue 20:30]--[2016-02-09 Tue 20:45] =>  0:15
  :END:

サブツリー全体の設定

サブツリー丸ごと今日の分の合計にするのであれば関数の上書きが必要。 org-clock.elのorg-clock-get-sum-start関数が継承したプロパティを見てくれていない。init.elなどに下記の内容を貼り付ける。 (org-entry-get nil "CLOCK_MODELINE_TOTAL" t)の最後のtがないと継承してくれない。

(defun org-clock-get-sum-start ()
  "Return the time from which clock times should be counted.
This is for the currently running clock as it is displayed
in the mode line.  This function looks at the properties
LAST_REPEAT and in particular CLOCK_MODELINE_TOTAL and the
corresponding variable `org-clock-mode-line-total' and then
decides which time to use."
  (let ((cmt (or (org-entry-get nil "CLOCK_MODELINE_TOTAL" t)
                 (symbol-name org-clock-mode-line-total)))
        (lr (org-entry-get nil "LAST_REPEAT")))
    (cond
     ((equal cmt "current")
      (setq org--msg-extra "showing time in current clock instance")
      (current-time))
     ((equal cmt "today")
      (setq org--msg-extra "showing today's task time.")
      (let* ((dt (decode-time))
             (hour (nth 2 dt))
             (day (nth 3 dt)))
        (if (< hour org-extend-today-until) (setf (nth 3 dt) (1- day)))
        (setf (nth 2 dt) org-extend-today-until)
        (setq dt (append (list 0 0) (nthcdr 2 dt)))
        (apply 'encode-time dt)))
     ((or (equal cmt "all")
          (and (or (not cmt) (equal cmt "auto"))
               (not lr)))
      (setq org--msg-extra "showing entire task time.")
      nil)
     ((or (equal cmt "repeat")
          (and (or (not cmt) (equal cmt "auto"))
               lr))
      (setq org--msg-extra "showing task time since last repeat.")
      (if (not lr)
          nil
        (org-time-string-to-time lr)))
     (t nil))))

参考

[O] Bug: CLOCK_MODELINE_TOTAL and org-todo-yesterday

2012年にバグ報告されているみたいだけど、誰も反応していない。