emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: James TD Smith <ahktenzero@mohorovi.cc>
To: emacs-orgmode@gnu.org
Subject: [PATCH 2/3] Add clock resuming.
Date: Thu, 23 Oct 2008 11:27:41 +0100	[thread overview]
Message-ID: <1224757662-32103-3-git-send-email-ahktenzero@mohorovi.cc> (raw)
In-Reply-To: <1224757662-32103-2-git-send-email-ahktenzero@mohorovi.cc>

If the option `org-clock-resume' is t, and the first clock line in an entry is is
open, clocking into that task resumes the clock from that time.
---
 lisp/ChangeLog    |    8 ++++++++
 lisp/org-clock.el |   28 +++++++++++++++++++++-------
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e4ffc88..438296d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -3,6 +3,14 @@
 	* org.el (org-insert-todo-heading): Fix bug with force-heading
 	argument.
 
+2008-10-23  James TD Smith  <ahktenzero@mohorovi.cc>
+
+	* org-clock.el (org-clock-in-resume): Add a custom option to
+	toggle starting the clock from an open clock line.
+	(org-clock-in): When clocking in to an entry, if
+	`org-clock-in-resume' is set, check if the first clock line is
+	open and if so, start the clock from the time in the clock line.
+
 2008-10-22  Carsten Dominik  <dominik@science.uva.nl>
 
 	* org-exp.el (org-export-as-ascii): Handle the case that we are
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index da86b0d..40272d4 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -95,6 +95,12 @@ The function is called with point at the beginning of the headline."
   :group 'org-clock
   :type 'integer)
 
+(defcustom org-clock-in-resume nil
+  "If non-nil, when clocking into a task with a clock entry which
+has not been closed, resume the clock from that point"
+  :group 'org-clock
+  :type 'boolean)
+
 ;;; The clock for measuring work time.
 
 (defvar org-mode-line-string "")
@@ -291,12 +297,21 @@ the clocking selection, associated with the letter `d'."
 		      (t "???")))
 	  (setq org-clock-heading (org-propertize org-clock-heading 'face nil))
 	  (org-clock-find-position)
-
-	  (insert "\n") (backward-char 1)
-	  (org-indent-line-function)
-	  (insert org-clock-string " ")
-	  (setq org-clock-start-time (current-time))
-	  (setq ts (org-insert-time-stamp (current-time) 'with-hm 'inactive))
+	  (if (and org-clock-in-resume
+		   (looking-at (concat "^[ \\t]* " org-clock-string
+				       " \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"
+				       " +\\sw+ +[012][0-9]:[0-5][0-9]\\)\\]$")))
+	      (progn (message "Matched %s" (match-string 1))
+		     (setq ts (concat "[" (match-string 1) "]"))
+		     (goto-char (match-end 1))
+		     (setq org-clock-start-time
+			   (apply 'encode-time (org-parse-time-string (match-string 1)))))
+	    (progn
+	      (insert "\n") (backward-char 1)
+	      (org-indent-line-function)
+	      (insert org-clock-string " ")
+	      (setq org-clock-start-time (current-time))
+	      (setq ts (org-insert-time-stamp org-clock-start-time 'with-hm 'inactive))))
 	  (move-marker org-clock-marker (point) (buffer-base-buffer))
 	  (or global-mode-string (setq global-mode-string '("")))
 	  (or (memq 'org-mode-line-string global-mode-string)
@@ -962,7 +977,6 @@ the currently selected interval size."
       (re-search-forward "#\\+END:")
       (end-of-line 0))))
 
-
 (defun org-clocktable-add-file (file table)
   (if table
       (let ((lines (org-split-string table "\n"))
-- 
1.5.6.5

  reply	other threads:[~2008-10-23 10:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-19 16:22 [PATCH] Bugfix in org-add-log-setup James TD Smith
2008-10-19 16:22 ` [PATCH] Allow storing clock status between emacs sessions James TD Smith
2008-10-20 15:42   ` Helge Gudmundsen
2008-10-22  8:45     ` Helge Gudmundsen
2008-10-22  9:18       ` Carsten Dominik
2008-10-22  9:25         ` Helge Gudmundsen
2008-10-22  9:42         ` James TD Smith
2008-10-22 15:23           ` Carsten Dominik
2008-10-23 10:27             ` [PATCH 0/3] Split my clock resume/clock persistence patch James TD Smith
2008-10-23 10:27               ` [PATCH 1/3] Fix some typos and duplication in the ChangeLog James TD Smith
2008-10-23 10:27                 ` James TD Smith [this message]
2008-10-23 10:27                   ` [PATCH 2/3] Add clock resuming James TD Smith
2008-10-23 10:28                   ` [PATCH 3/3] Add clock persistence James TD Smith
2008-10-28  7:33                     ` Carsten Dominik
2008-10-28 11:10                       ` Helge Gudmundsen
2008-10-24  4:55                 ` [PATCH 1/3] Fix some typos and duplication in the ChangeLog Carsten Dominik
2008-10-20  5:46 ` [PATCH] Bugfix in org-add-log-setup Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1224757662-32103-3-git-send-email-ahktenzero@mohorovi.cc \
    --to=ahktenzero@mohorovi.cc \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).