2014-10-05 49 views
1

假設,我們有一個組織文件是這樣的:Emacs的組織模式:如何確定,當前節點被計時了在

* TODO Write function x 

我想時鐘上工作的時間。有2個功能組織模式:

  1. ORG-時鐘在
  2. ORG-時鐘輸出

,我決定給他們以這種方式結合起來:

(defun org-set-clock() 
    "Clock current node in/out" 
    (if (<current node is not clocked in>)) 
    (org-clock-in) 
    (org-clock-out) 
) 

而且將此功能附加到一個簡單的快捷方式:

(add-hook 'dired-mode-hook 
      (lambda() 
      (define-key dired-mode-map (kbd "M-q") 'org-set-clock))) 

如何編寫此代碼:<current node is not clocked in>

回答

1

您可以在下面找到更新的解決方案。

(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-modeelpa which'll讓你總是最新。

+0

似乎,'org-clock-resolving-clocks-due-to-idleness'在我的組織模式中是未定義的。我會盡力更新它。我不明白你的問題。你能詳細解釋一下嗎? – user4035 2014-10-05 19:35:23

+1

@ user4035我正在使用版本爲'8.2.8'的最新'org-mode'。好的,假設你已經在計劃一些任務。現在你去一些'org-mode'緩衝區,並在其他任務上移動光標('point')並執行該函數。它不檢查光標是否在當前正在計時的任務上。它將停止任何**正在運行的任務。如果沒有正在運行的任務,它將開始計時,光標結束。 – elemakil 2014-10-05 19:39:23

+0

如果檢查,當前任務是否計時,會更好。 – user4035 2014-10-06 04:41:41