您可以在下面找到更新的解決方案。
(defun org-set-clock()
"One-off function for `org-mode' task clocking.
Behaviour:
* When there is no running clock, start
the clock for the item at point.
* When there is already a running clock and
`point' is at the item which is being clocked
stop the corresponding clock.
* When there is already a running clock but `point'
is not at the item which is being clocked,
stop the clock and restart it for item at `point'."
(interactive)
(let ((interrupting (and (not org-clock-resolving-clocks-due-to-idleness)
(org-clocking-p))))
(if interrupting
(if (save-excursion
(org-back-to-heading t)
(and (equal (marker-buffer org-clock-hd-marker)
(current-buffer))
(= (marker-position org-clock-hd-marker)
(point))
(equal org-clock-current-task (nth 4 (org-heading-components)))))
(org-clock-out)
(org-clock-in))
(org-clock-in))))
編輯:如果無法更新org-mode
到足夠最新版本,你可以使用
(defun org-set-clock()
"One-off function for `org-mode' task clocking.
Behaviour:
* When there is no running clock, start
the clock for the item at point.
* When there is already a running clock and
`point' is at the item which is being clocked
stop the corresponding clock.
* When there is already a running clock but `point'
is not at the item which is being clocked,
stop the clock and restart it for item at `point'."
(interactive)
(if (org-clocking-p)
(if (save-excursion
(org-back-to-heading t)
(and (equal (marker-buffer org-clock-hd-marker)
(current-buffer))
(= (marker-position org-clock-hd-marker)
(point))
(equal org-clock-current-task (nth 4 (org-heading-components)))))
(org-clock-out)
(org-clock-in))
(org-clock-in)))
不過,我建議你使用org-mode
elpa
which'll讓你總是最新。
似乎,'org-clock-resolving-clocks-due-to-idleness'在我的組織模式中是未定義的。我會盡力更新它。我不明白你的問題。你能詳細解釋一下嗎? – user4035 2014-10-05 19:35:23
@ user4035我正在使用版本爲'8.2.8'的最新'org-mode'。好的,假設你已經在計劃一些任務。現在你去一些'org-mode'緩衝區,並在其他任務上移動光標('point')並執行該函數。它不檢查光標是否在當前正在計時的任務上。它將停止任何**正在運行的任務。如果沒有正在運行的任務,它將開始計時,光標結束。 – elemakil 2014-10-05 19:39:23
如果檢查,當前任務是否計時,會更好。 – user4035 2014-10-06 04:41:41