From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: [PATCH 3/3] Add clock persistence. Date: Tue, 28 Oct 2008 08:33:04 +0100 Message-ID: <8FB9E9DE-F92A-4F6E-B130-FCA6F61D0FF9@uva.nl> References: <1224757662-32103-3-git-send-email-ahktenzero@mohorovi.cc> <1224757723-32352-1-git-send-email-ahktenzero@mohorovi.cc> Mime-Version: 1.0 (Apple Message framework v929.2) Content-Type: multipart/mixed; boundary="===============1095721959==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kuj54-0003RH-P6 for emacs-orgmode@gnu.org; Tue, 28 Oct 2008 03:33:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kuj50-0003R4-Sv for emacs-orgmode@gnu.org; Tue, 28 Oct 2008 03:33:33 -0400 Received: from [199.232.76.173] (port=43293 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kuj50-0003R1-O4 for emacs-orgmode@gnu.org; Tue, 28 Oct 2008 03:33:30 -0400 Received: from mx20.gnu.org ([199.232.41.8]:10299) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kuj4z-0006Zb-T1 for emacs-orgmode@gnu.org; Tue, 28 Oct 2008 03:33:30 -0400 Received: from postduif.ic.uva.nl ([145.18.40.180]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kuj4w-0001MK-9g for emacs-orgmode@gnu.org; Tue, 28 Oct 2008 03:33:26 -0400 In-Reply-To: <1224757723-32352-1-git-send-email-ahktenzero@mohorovi.cc> 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: James TD Smith Cc: emacs-orgmode@gnu.org --===============1095721959== Content-Type: multipart/alternative; boundary=Apple-Mail-1--88634741 --Apple-Mail-1--88634741 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Hi, I have now applied these patches and put some initial documentation into http://orgmode.org/Changes.html. Since I have not yet tested this myself, I would he glad if some of you clocking people could test it and report. Thanks. - Carsten On Oct 23, 2008, at 12:28 PM, James TD Smith wrote: > Clock-related data are saved when exiting emacs ands restored when > emacs > is restarted. The data saved include the contents of `org-clock- > history', > and the running clock, if there is one. > > To use this, you will need to add > > (require 'org-clock) > (org-clock-persistence-insinuate) > > to your .emacs and either add > > (setq org-clock-persist t) > (setq org-clock-in-resume t) > > or set those options to t in custom. > > This patch requires the clock resume patch. > --- > lisp/ChangeLog | 16 +++++++++ > lisp/org-clock.el | 90 ++++++++++++++++++++++++++++++++++++++++++++ > +++++++++ > 2 files changed, 106 insertions(+), 0 deletions(-) > > diff --git a/lisp/ChangeLog b/lisp/ChangeLog > index 438296d..063ae15 100644 > --- a/lisp/ChangeLog > +++ b/lisp/ChangeLog > @@ -10,6 +10,22 @@ > (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. > + (org-clock-persist): Add a custom option to toggle clock > + persistence. > + (org-clock-persist-query-save): Add a custom option to toggle > + asking the user if they want to save the running clock when > + exiting. > + (org-clock-persist-query-resume): Add a custom option to toggle > + asking the user if they want to resume the saved clock when Emacs > + is restarted. > + (org-clock-save): Add a function to save clock data. > + This includes the contents of `org-clock-history' and the buffer > + and position of the currently clocked task, if any. > + (org-clock-load): Add a function to load clock data. > + This populates `org-clock-history', and resumes the saved clocked > + task if there is one. > + (org-clock-persistence-insinuate): Add a method to set up the > + hooks for clock persistence. > > 2008-10-22 Carsten Dominik > > diff --git a/lisp/org-clock.el b/lisp/org-clock.el > index 40272d4..90b2992 100644 > --- a/lisp/org-clock.el > +++ b/lisp/org-clock.el > @@ -101,6 +101,28 @@ has not been closed, resume the clock from that > point" > :group 'org-clock > :type 'boolean) > > +(defcustom org-clock-persist nil > + "When non-nil, save the running clock when emacs is closed, and > + resume it next time emacs is started." > + :group 'org-clock > + :type 'boolean) > + > +(defcustom org-clock-persist-file "~/.emacs.d/org-clock-save.el" > + "File to save clock data to" > + :group 'org-clock > + :type 'string) > + > +(defcustom org-clock-persist-query-save nil > + "When non-nil, ask before saving the current clock on exit" > + :group 'org-clock > + :type 'boolean) > + > +(defcustom org-clock-persist-query-resume t > + "When non-nil, ask before resuming any stored clock during > +load." > + :group 'org-clock > + :type 'boolean) > + > ;;; The clock for measuring work time. > > (defvar org-mode-line-string "") > @@ -989,6 +1011,74 @@ the currently selected interval size." > lines) > "\n")))) > > +(defun org-clock-save () > + "Persist various clock-related data to disk" > + (with-current-buffer (find-file (expand-file-name org-clock- > persist-file)) > + (progn (delete-region (point-min) (point-max)) > + ;;Store clock > + (insert (format ";; org-persist.el - %s at %s\n" system-name > (time-stamp-string))) > + (if (and org-clock-persist (marker-buffer org-clock-marker) > + (or (not org-clock-persist-query-save) > + (y-or-n-p (concat "Save current clock (" > + (substring-no-properties org-clock-heading) > + ")")))) > + (insert "(setq resume-clock '(\"" > + (buffer-file-name (marker-buffer org-clock-marker)) > + "\" . " (int-to-string (marker-position org-clock-marker)) > + "))\n")) > + ;;Store clocked task history. Tasks are stored reversed to make > + ;;reading simpler > + (if org-clock-history > + (insert "(setq stored-clock-history '(" > + (mapconcat > + (lambda (m) > + (when (marker-buffer m) > + (concat "(\"" (buffer-file-name (marker-buffer m)) > + "\" . " (int-to-string (marker-position m)) > + ")"))) > + (reverse org-clock-history) " ") "))\n")) > + (save-buffer) > + (kill-buffer (current-buffer))))) > + > +(defvar org-clock-loaded nil) > + > +(defun org-clock-load () > + "Load various clock-related data from disk, optionally resuming > +a stored clock" > + (if (not org-clock-loaded) > + (let ((filename (expand-file-name org-clock-persist-file)) > + (org-clock-in-resume t)) > + (if (file-readable-p filename) > + (progn > + (message "%s" "Restoring clock data") > + (setq org-clock-loaded t) > + (load-file filename) > + ;; load history > + (if (boundp 'stored-clock-history) > + (save-window-excursion > + (mapc (lambda (task) > + (org-clock-history-push (cdr task) > + (find-file (car task)))) > + stored-clock-history))) > + ;; resume clock > + (if (and (boundp 'resume-clock) org-clock-persist > + (or (not org-clock-persist-query-resume) > + (y-or-n-p "Resume clock (" > + (with-current-buffer (find-file (car resume-clock)) > + (progn (goto-char (cdr resume-clock)) > + (looking-at org-complex-heading-regexp) > + (match-string 4))) ")"))) > + (with-current-buffer (find-file (car resume-clock)) > + (progn (goto-char (cdr resume-clock)) > + (org-clock-in))))) > + (message "Not restoring clock data; %s not found" > + org-clock-persist-file))))) > + > +(defun org-clock-persistence-insinuate () > + "Set up hooks for clock persistence" > + (add-hook 'org-mode-hook 'org-clock-load) > + (add-hook 'kill-emacs-hook 'org-clock-save)) > + > (provide 'org-clock) > > ;; arch-tag: 7b42c5d4-9b36-48be-97c0-66a869daed4c > -- > 1.5.6.5 > > > > _______________________________________________ > 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--88634741 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable
Hi,

I = have now applied these patches and put some initial documentation into = http://orgmode.org/Changes.html.

Since I have not yet tested this myself, I would = he glad if some of you clocking people could test it and = report.

Thanks.

- = Carsten

On Oct 23, 2008, at 12:28 PM, James TD = Smith wrote:

Clock-related data are saved when exiting emacs ands = restored when emacs
is restarted. The data saved include the contents = of `org-clock-history',
and the running clock, if there is = one.

To use this, you will need to add

(require = 'org-clock)
(org-clock-persistence-insinuate)

to your .emacs = and either add

(setq org-clock-persist t)
(setq = org-clock-in-resume t)

or set those options to t in = custom.

This patch requires the clock resume patch.
---
= lisp/ChangeLog    |   16 +++++++++
= lisp/org-clock.el |   90 = +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files = changed, 106 insertions(+), 0 deletions(-)

diff --git = a/lisp/ChangeLog b/lisp/ChangeLog
index 438296d..063ae15 = 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -10,6 = +10,22 @@
= (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.
+ = (org-clock-persist): Add a custom option to toggle = clock
+ = persistence.
+ (org-clock-persist-query-save): = Add a custom option to toggle
+ asking the user if they want to = save the running clock when
+ exiting.
+ = (org-clock-persist-query-resume): Add a custom option to = toggle
+ = asking the user if they want to resume the saved clock when = Emacs
+ = is restarted.
+ (org-clock-save): Add a function = to save clock data.
+ This includes the contents of = `org-clock-history' and the buffer
+ and position of the currently = clocked task, if any.
+ (org-clock-load): Add a function = to load clock data.
+ This populates = `org-clock-history', and resumes the saved clocked
+ task if = there is one.
+ = (org-clock-persistence-insinuate): Add a method to set up = the
+ = hooks for clock persistence.

2008-10-22  Carsten = Dominik  <
dominik@science.uva.nl>

= diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index = 40272d4..90b2992 100644
--- a/lisp/org-clock.el
+++ = b/lisp/org-clock.el
@@ -101,6 +101,28 @@ has not been closed, resume = the clock from that point"
  :group 'org-clock
=   :type 'boolean)

+(defcustom org-clock-persist = nil
+  "When non-nil, save the running clock when emacs is = closed, and
+  resume it next time emacs is started."
+ =  :group 'org-clock
+  :type 'boolean)
+
+(defcustom = org-clock-persist-file "~/.emacs.d/org-clock-save.el"
+  "File = to save clock data to"
+  :group 'org-clock
+  :type = 'string)
+
+(defcustom org-clock-persist-query-save nil
+ =  "When non-nil, ask before saving the current clock on exit"
+ =  :group 'org-clock
+  :type 'boolean)
+
+(defcustom = org-clock-persist-query-resume t
+  "When non-nil, ask before = resuming any stored clock during
+load."
+  :group = 'org-clock
+  :type 'boolean)
+
;;; The clock for = measuring work time.

(defvar org-mode-line-string "")
@@ = -989,6 +1011,74 @@ the currently selected interval size."
=   lines)
=   "\n"))))

+(defun org-clock-save ()
+ =  "Persist various clock-related data to disk"
+ =  (with-current-buffer (find-file (expand-file-name = org-clock-persist-file))
+    (progn (delete-region = (point-min) (point-max))
+   ;;Store = clock
+ =   (insert (format ";; org-persist.el - %s at %s\n" = system-name (time-stamp-string)))
+   (if (and = org-clock-persist (marker-buffer org-clock-marker)
+ =    (or (not org-clock-persist-query-save)
+ (y-or-n-p = (concat "Save current clock ("
+  (substring-no-properties = org-clock-heading)
+  ")"))))
+ =       (insert "(setq resume-clock = '(\""
+ = =       (buffer-file-name = (marker-buffer org-clock-marker))
+ =       "\" . " (int-to-string = (marker-position org-clock-marker))
+ =       "))\n"))
+ =   ;;Store clocked task history. Tasks are stored reversed to = make
+ =   ;;reading simpler
+   (if = org-clock-history
+ =       (insert "(setq stored-clock-history = '("
+ = =       (mapconcat
+ (lambda = (m)
+ = = =  (when (marker-buffer m)
+    (concat "(\"" = (buffer-file-name (marker-buffer m))
+    "\" . " = (int-to-string (marker-position m))
+ ")")))
+ (reverse = org-clock-history) " ") "))\n"))
+ =   (save-buffer)
+   (kill-buffer = (current-buffer)))))
+
+(defvar org-clock-loaded = nil)
+
+(defun org-clock-load ()
+  "Load various = clock-related data from disk, optionally resuming
+a stored = clock"
+  (if (not org-clock-loaded)
+ =      (let ((filename (expand-file-name = org-clock-persist-file))
+ =    (org-clock-in-resume t))
+ (if = (file-readable-p filename)
+ =    (progn
+ =      (message "%s" "Restoring clock = data")
+ =      (setq org-clock-loaded = t)
+ =      (load-file filename)
+ =      ;; load history
+ =      (if (boundp = 'stored-clock-history)
+ =  (save-window-excursion
+    (mapc (lambda = (task)
+ = = =    (org-clock-history-push (cdr task)
+ =    (find-file (car task))))
+ =  stored-clock-history)))
+      ;; = resume clock
+=      (if (and (boundp = 'resume-clock) org-clock-persist
+ =       (or (not = org-clock-persist-query-resume)
+   (y-or-n-p "Resume = clock ("
+ = = = =     (with-current-buffer (find-file (car = resume-clock))
+ =       (progn (goto-char (cdr = resume-clock))
+ =      (looking-at = org-complex-heading-regexp)
+ =      (match-string 4))) ")")))
+ =  (with-current-buffer (find-file (car resume-clock))
+ =    (progn (goto-char (cdr resume-clock))
+ =   (org-clock-in)))))
+  (message "Not restoring = clock data; %s not found"
+ =   org-clock-persist-file)))))
+
+(defun = org-clock-persistence-insinuate ()
+  "Set up hooks for clock = persistence"
+  (add-hook 'org-mode-hook 'org-clock-load)
+ =  (add-hook 'kill-emacs-hook 'org-clock-save))
+
(provide = 'org-clock)

;; arch-tag: = 7b42c5d4-9b36-48be-97c0-66a869daed4c
-- =
1.5.6.5



_______________________________________________=
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--88634741-- --===============1095721959== 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 --===============1095721959==--