From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [PATCH] Auto resume clock-in fails Date: Tue, 14 Apr 2009 10:18:00 +0200 Message-ID: References: <49DE52BF.2010406@hgn.ca> Mime-Version: 1.0 (Apple Message framework v930.3) Content-Type: multipart/mixed; boundary="===============1732928931==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LtdqP-000376-KZ for emacs-orgmode@gnu.org; Tue, 14 Apr 2009 04:18:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LtdqL-00035f-8D for emacs-orgmode@gnu.org; Tue, 14 Apr 2009 04:18:13 -0400 Received: from [199.232.76.173] (port=44814 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LtdqK-00035U-5s for emacs-orgmode@gnu.org; Tue, 14 Apr 2009 04:18:08 -0400 Received: from yx-out-1718.google.com ([74.125.44.156]:14126) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LtdqJ-0002tH-Lr for emacs-orgmode@gnu.org; Tue, 14 Apr 2009 04:18:08 -0400 Received: by yx-out-1718.google.com with SMTP id 3so1833888yxi.66 for ; Tue, 14 Apr 2009 01:18:05 -0700 (PDT) In-Reply-To: <49DE52BF.2010406@hgn.ca> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Adam Elliott Cc: emacs-orgmode@gnu.org --===============1732928931== Content-Type: multipart/alternative; boundary=Apple-Mail-1--603124532 --Apple-Mail-1--603124532 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Hi Adam, this is now fixed, thank you very much for your report and the additional details your provided. That helped a lot. The fix I implemented is different. I have not tested it extensively, and I would be very much obliged if you could give it a thorough test. Thanks! - Carsten On Apr 9, 2009, at 9:55 PM, Adam Elliott wrote: > Using org 6.25e: > > Automatically resuming the clock after an Emacs restart fails under > the following cases: > > 1. If org-log-states-order-reversed set to t (default), and a state > change line precedes the clock line to resume. Error message is > "Cannot restart clock because task does not contain unfinished clock". > > Example: > > *** STARTED test > :LOGBOOK: > - State "STARTED" from "TODO" [2009-04-09 Thu 13:50] > CLOCK: [2009-04-09 Thu 13:50] > :END: > > Reason: point is placed at start of state change line and so fails > looking-at test (org-clock.el:345). > > Possible solution appears to be to use the existing function org- > skip-over-state-notes when looking for the clock line to resume at > org-clock.el:343. > > 2. If org-log-states-order-reversed set to nil. Error message is > the same. Reason: point is placed *after* last clock line and so > fails looking-at test. > > Possible solution: test order-reversed and back up one clock entry > before looking-at test. > > I have combined these two ideas into a new function (patch > attached). I don't imagine I've handled all of the possible > configurations of state change entries, log entries, and clock > lines, in and out of drawers, so this will probably serve more as a > basis for a solution than a solution itself. > > (If nothing else, on org-clock.el:346 there's "\\t" where it should > be "\t".) > > Adam > --- /usr/local/src/org-6.25e/lisp/org-clock.el 2009-04-09 > 10:27:00.000000000 -0400 > +++ org-clock.el 2009-04-09 15:52:12.437500000 -0400 > @@ -280,7 +280,7 @@ > (interactive "P") > (catch 'abort > (let ((interrupting (marker-buffer org-clock-marker)) > - ts selected-task target-pos) > + ts selected-task target-pos resume-clock) > (when (equal select '(4)) > (setq selected-task (org-clock-select-task "Clock-in on task: ")) > (if selected-task > @@ -342,16 +342,14 @@ > (org-clock-find-position) > (cond > ((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]\\)\\][ \t]*$"))) > - (message "Matched %s" (match-string 1)) > - (setq ts (concat "[" (match-string 1) "]")) > - (goto-char (match-end 1)) > + (setq resume-clock > + (org-clock-find-last-clock-from-new-clock-position))) > + (message "Matched %s" (car resume-clock)) > + (setq ts (concat "[" (car resume-clock) "]")) > + (goto-char (+ (length (car resume-clock)) (cdr resume-clock))) > (setq org-clock-start-time > (apply 'encode-time > - (org-parse-time-string (match-string 1))))) > + (org-parse-time-string (car resume-clock))))) > ((eq org-clock-in-resume 'auto-restart) > ;; called from org-clock-load during startup, > ;; do not interrupt, but warn! > @@ -455,6 +453,29 @@ > (and (re-search-forward org-property-end-re nil t) > (goto-char (match-beginning 0)))))))) > > +(defun org-clock-find-last-clock-from-new-clock-position () > + "Attempts to locate last clock line, assuming point is at new > +clock line position (see `org-clock-find-position'). If found, > +moves point to beginning of last clock line and returns a cons > +pair of the starting timestamp of the clock and the position of > +the match; and otherwise restores point and returns nil." > + (let ((saved-point (point)) heading-bound) > + (save-match-data > + (if org-log-states-order-reversed > + (org-skip-over-state-notes) > + (save-excursion > + (org-back-to-heading t) > + (beginning-of-line 2) > + (setq heading-bound (point))) > + (re-search-backward (concat "^[ \t]*" org-clock-string) heading- > bound t)) > + (if (looking-at > + (concat "^[ \t]* " org-clock-string > + " \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}" > + " +\\sw+ +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$")) > + (cons (match-string 1) (match-beginning 1)) > + (goto-char saved-point) > + nil)))) > + > (defun org-clock-out (&optional fail-quietly) > "Stop the currently running clock. > If there is no running clock, throw an error, unless FAIL-QUIETLY is > set." > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode --Apple-Mail-1--603124532 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi = Adam,

this is now fixed, thank you very much for your = report and the additional
details your provided.  That = helped a lot.

The fix I implemented is = different.  I have not tested it extensively,
and I would = be very much obliged if you could give it = a thorough
test.

Thanks!

- Carsten

On Apr 9, 2009, at = 9:55 PM, Adam Elliott wrote:

Using= org 6.25e:

Automatically resuming the clock after an Emacs = restart fails under the following cases:

1. If = org-log-states-order-reversed set to t (default), and a state change = line precedes the clock line to resume.  Error message is "Cannot = restart clock because task does not contain unfinished = clock".

Example:

*** STARTED test
=    :LOGBOOK:
   - State "STARTED" =    from "TODO" =       [2009-04-09 Thu 13:50]
=    CLOCK: [2009-04-09 Thu 13:50]
=    :END:

Reason: point is placed at start of state = change line and so fails looking-at test = (org-clock.el:345).

Possible solution appears to be to use the = existing function org-skip-over-state-notes when looking for the clock = line to resume at org-clock.el:343.

2. If = org-log-states-order-reversed set to nil.  Error message is the = same.  Reason: point is placed *after* last clock line and so fails = looking-at test.

Possible solution: test order-reversed and back = up one clock entry before looking-at test.

I have combined these = two ideas into a new function (patch attached).  I don't imagine = I've handled all of the possible configurations of state change entries, = log entries, and clock lines, in and out of drawers, so this will = probably serve more as a basis for a solution than a solution = itself.

(If nothing else, on org-clock.el:346 there's "\\t" where = it should be "\t".)

Adam
--- = /usr/local/src/org-6.25e/lisp/org-clock.el 2009-04-09 10:27:00.000000000 = -0400
+++ org-clock.el 2009-04-09 15:52:12.437500000 = -0400
@@ -280,7 +280,7 @@
  (interactive "P")
=   (catch 'abort
    (let = ((interrupting (marker-buffer org-clock-marker))
-  ts = selected-task target-pos)
+  ts selected-task = target-pos resume-clock)
      (when = (equal select '(4))
(setq selected-task = (org-clock-select-task "Clock-in on task: "))
(if = selected-task
@@ -342,16 +342,14 @@
=    (org-clock-find-position)
=    (cond
    ((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]\\)\\][ = \t]*$")))
- =      (message "Matched %s" = (match-string 1))
- =      (setq ts (concat "[" (match-string 1) = "]"))
- =      (goto-char (match-end = 1))
+ = =   (setq resume-clock
+ = (org-clock-find-last-clock-from-new-clock-position)))
+ =      (message "Matched %s" (car = resume-clock))
+ =      (setq ts (concat "[" (car resume-clock) = "]"))
+ =      (goto-char (+ (length (car = resume-clock)) (cdr resume-clock)))
=      (setq org-clock-start-time
=    (apply 'encode-time
- =   (org-parse-time-string (match-string 1)))))
+ =   (org-parse-time-string (car resume-clock)))))
=     ((eq org-clock-in-resume 'auto-restart)
= =      ;; called from org-clock-load during = startup,
=      ;; do not interrupt, but = warn!
@@ -455,6 +453,29 @@
   (and = (re-search-forward org-property-end-re nil t)
= (goto-char (match-beginning 0))))))))

+(defun = org-clock-find-last-clock-from-new-clock-position ()
+ =  "Attempts to locate last clock line, assuming point is at = new
+clock line position (see `org-clock-find-position').  If = found,
+moves point to beginning of last clock line and returns a = cons
+pair of the starting timestamp of the clock and the position = of
+the match; and otherwise restores point and returns nil."
+ =  (let ((saved-point (point)) heading-bound)
+ =    (save-match-data
+ =      (if = org-log-states-order-reversed
+ =  (org-skip-over-state-notes)
+ (save-excursion
+ =  (org-back-to-heading t)
+  (beginning-of-line = 2)
+ =  (setq heading-bound (point)))
+ = (re-search-backward (concat "^[ \t]*" org-clock-string) = heading-bound t))
+      (if = (looking-at
+ =   (concat "^[ \t]* " org-clock-string
+ =   " \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"
+ =   " +\\sw+ +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$"))
+ =  (cons (match-string 1) (match-beginning 1))
+ = (goto-char saved-point)
+ nil))))
+
(defun = org-clock-out (&optional fail-quietly)
  "Stop the = currently running clock.
If there is no running clock, throw an = error, unless FAIL-QUIETLY is = set."
_______________________________________________
Emacs-orgmode = mailing list
Remember: use `Reply All' to send replies to the = list.
Emacs-orgmode@gnu.org
http://= lists.gnu.org/mailman/listinfo/emacs-orgmode
<= br>
= --Apple-Mail-1--603124532-- --===============1732928931== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --===============1732928931==--