浏览代码

Option to remove clock lines that result into 0 minutes.

Proposed by Bernt Hansen.
Carsten Dominik 17 年之前
父节点
当前提交
6237667df0
共有 2 个文件被更改,包括 58 次插入37 次删除
  1. 7 0
      ChangeLog
  2. 51 37
      lisp/org-clock.el

+ 7 - 0
ChangeLog

@@ -1,5 +1,12 @@
 2008-04-18  Carsten Dominik  <dominik@science.uva.nl>
 2008-04-18  Carsten Dominik  <dominik@science.uva.nl>
 
 
+	* lisp/org-clock.el (org-clock): New customization group.
+	(org-clock-into-drawer, org-clock-out-when-done)
+	(org-clock-in-switch-to-state, org-clock-heading-function): Moved
+	into the new group.
+	(org-clock-out-remove-zero-time-clocks): New option.
+	(org-clock-out): Use `org-clock-out-remove-zero-time-clocks'.
+
 	* lisp/org-colview.el (org-columns-next-allowed-value)
 	* lisp/org-colview.el (org-columns-next-allowed-value)
 	(org-columns-edit-value): Limit the effort for updatig in the
 	(org-columns-edit-value): Limit the effort for updatig in the
 	agenda to recomputing a single file.
 	agenda to recomputing a single file.

+ 51 - 37
lisp/org-clock.el

@@ -36,6 +36,11 @@
 
 
 (declare-function calendar-absolute-from-iso    "cal-iso"    (&optional date))
 (declare-function calendar-absolute-from-iso    "cal-iso"    (&optional date))
 
 
+(defgroup org-clock nil
+  "Options concerning clocking working time in Org-mode."
+  :tag "Org Clock"
+  :group 'org-progress)
+
 (defcustom org-clock-into-drawer 2
 (defcustom org-clock-into-drawer 2
   "Should clocking info be wrapped into a drawer?
   "Should clocking info be wrapped into a drawer?
 When t, clocking info will always be inserted into a :CLOCK: drawer.
 When t, clocking info will always be inserted into a :CLOCK: drawer.
@@ -44,7 +49,7 @@ When nil, the drawer will not be created, but used when present.
 When an integer and the number of clocking entries in an item
 When an integer and the number of clocking entries in an item
 reaches or exceeds this number, a drawer will be created."
 reaches or exceeds this number, a drawer will be created."
   :group 'org-todo
   :group 'org-todo
-  :group 'org-progress
+  :group 'org-clock
   :type '(choice
   :type '(choice
 	  (const :tag "Always" t)
 	  (const :tag "Always" t)
 	  (const :tag "Only when drawer exists" nil)
 	  (const :tag "Only when drawer exists" nil)
@@ -54,13 +59,18 @@ reaches or exceeds this number, a drawer will be created."
   "When t, the clock will be stopped when the relevant entry is marked DONE.
   "When t, the clock will be stopped when the relevant entry is marked DONE.
 Nil means, clock will keep running until stopped explicitly with
 Nil means, clock will keep running until stopped explicitly with
 `C-c C-x C-o', or until the clock is started in a different item."
 `C-c C-x C-o', or until the clock is started in a different item."
-  :group 'org-progress
+  :group 'org-clock
+  :type 'boolean)
+
+(defcustom org-clock-out-remove-zero-time-clocks nil
+  "Non-nil means, remove the clock line when the resulting time is zero."
+  :group 'org-clock
   :type 'boolean)
   :type 'boolean)
 
 
 (defcustom org-clock-in-switch-to-state nil
 (defcustom org-clock-in-switch-to-state nil
   "Set task to a special todo state while clocking it.
   "Set task to a special todo state while clocking it.
 The value should be the state to which the entry should be switched."
 The value should be the state to which the entry should be switched."
-  :group 'org-progress
+  :group 'org-clock
   :group 'org-todo
   :group 'org-todo
   :type '(choice
   :type '(choice
 	  (const :tag "Don't force a state" nil)
 	  (const :tag "Don't force a state" nil)
@@ -70,15 +80,10 @@ The value should be the state to which the entry should be switched."
   "When non-nil, should be a function to create `org-clock-heading'.
   "When non-nil, should be a function to create `org-clock-heading'.
 This is the string shown in the mode line when a clock is running.
 This is the string shown in the mode line when a clock is running.
 The function is called with point at the beginning of the headline."
 The function is called with point at the beginning of the headline."
-  :group 'org-progress
+  :group 'org-clock
   :type 'function)
   :type 'function)
 
 
 
 
-
-
-
-
-
 ;;; The clock for measuring work time.
 ;;; The clock for measuring work time.
 
 
 (defvar org-mode-line-string "")
 (defvar org-mode-line-string "")
@@ -199,36 +204,45 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
   (catch 'exit
   (catch 'exit
   (if (not (marker-buffer org-clock-marker))
   (if (not (marker-buffer org-clock-marker))
       (if fail-quietly (throw 'exit t) (error "No active clock")))
       (if fail-quietly (throw 'exit t) (error "No active clock")))
-  (let (ts te s h m)
+  (let (ts te s h m remove)
     (save-excursion
     (save-excursion
       (set-buffer (marker-buffer org-clock-marker))
       (set-buffer (marker-buffer org-clock-marker))
-      (goto-char org-clock-marker)
-      (beginning-of-line 1)
-      (if (and (looking-at (concat "[ \t]*" org-keyword-time-regexp))
-	       (equal (match-string 1) org-clock-string))
-	  (setq ts (match-string 2))
-	(if fail-quietly (throw 'exit nil) (error "Clock start time is gone")))
-      (goto-char (match-end 0))
-      (delete-region (point) (point-at-eol))
-      (insert "--")
-      (setq te (org-insert-time-stamp (current-time) 'with-hm 'inactive))
-      (setq s (- (time-to-seconds (apply 'encode-time (org-parse-time-string te)))
-		 (time-to-seconds (apply 'encode-time (org-parse-time-string ts))))
-	    h (floor (/ s 3600))
-	    s (- s (* 3600 h))
-	    m (floor (/ s 60))
-	    s (- s (* 60 s)))
-      (insert " => " (format "%2d:%02d" h m))
-      (move-marker org-clock-marker nil)
-      (when org-log-note-clock-out
-	(org-add-log-setup 'clock-out))
-      (when org-mode-line-timer
-	(cancel-timer org-mode-line-timer)
-	(setq org-mode-line-timer nil))
-      (setq global-mode-string
-	    (delq 'org-mode-line-string global-mode-string))
-      (force-mode-line-update)
-      (message "Clock stopped at %s after HH:MM = %d:%02d" te h m)))))
+      (save-restriction
+	(widen)
+	(goto-char org-clock-marker)
+	(beginning-of-line 1)
+	(if (and (looking-at (concat "[ \t]*" org-keyword-time-regexp))
+		 (equal (match-string 1) org-clock-string))
+	    (setq ts (match-string 2))
+	  (if fail-quietly (throw 'exit nil) (error "Clock start time is gone")))
+	(goto-char (match-end 0))
+	(delete-region (point) (point-at-eol))
+	(insert "--")
+	(setq te (org-insert-time-stamp (current-time) 'with-hm 'inactive))
+	(setq s (- (time-to-seconds (apply 'encode-time (org-parse-time-string te)))
+		   (time-to-seconds (apply 'encode-time (org-parse-time-string ts))))
+	      h (floor (/ s 3600))
+	      s (- s (* 3600 h))
+	      m (floor (/ s 60))
+	      s (- s (* 60 s)))
+	(insert " => " (format "%2d:%02d" h m))
+	(setq remove (and (= (+ h m) 0) org-clock-out-remove-zero-time-clocks))
+	(move-marker org-clock-marker nil)
+	(when org-log-note-clock-out
+	  (org-add-log-setup 'clock-out))
+	(when org-mode-line-timer
+	  (cancel-timer org-mode-line-timer)
+	  (setq org-mode-line-timer nil))
+	(setq global-mode-string
+	      (delq 'org-mode-line-string global-mode-string))
+	(force-mode-line-update)
+	(message "Clock stopped at %s after HH:MM = %d:%02d%s" te h m
+		 (if remove " => REMOVING" ""))
+	(when remove
+	  (beginning-of-line 1)
+	  (let ((kill-whole-line t))
+	    (kill-line nil))
+	  (beginning-of-line 0)))))))
 
 
 (defun org-clock-cancel ()
 (defun org-clock-cancel ()
   "Cancel the running clock be removing the start timestamp."
   "Cancel the running clock be removing the start timestamp."