From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kai Tetzlaff Subject: Re: [PATCH] Avoid losing persisted clock data when exiting emac without loading org-mode Date: Sat, 24 Oct 2009 19:03:48 +0200 Message-ID: <4AE33374.1040400@gmx.de> References: <468CEFF9-A1C3-4888-83B6-066F2129087D@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1k25-0004AE-Mf for emacs-orgmode@gnu.org; Sat, 24 Oct 2009 13:04:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1k21-00049i-8Q for emacs-orgmode@gnu.org; Sat, 24 Oct 2009 13:04:01 -0400 Received: from [199.232.76.173] (port=46782 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1k21-00049f-3V for emacs-orgmode@gnu.org; Sat, 24 Oct 2009 13:03:57 -0400 Received: from moutng.kundenserver.de ([212.227.17.10]:61305) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N1k20-00035Y-8r for emacs-orgmode@gnu.org; Sat, 24 Oct 2009 13:03:56 -0400 In-Reply-To: <468CEFF9-A1C3-4888-83B6-066F2129087D@gmail.com> 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: Carsten Dominik Cc: emacs-orgmode@gnu.org Carsten Dominik wrote: > Hi Kai, >=20 >=20 > On Oct 23, 2009, at 9:01 AM, Kai Tetzlaff wrote: >=20 >> Hi, >> >> i noticed that when using the org-mode clock persistence, the stored >> clock data gets deleted when i start emacs and exit again without >> turning on org-mode in between. >> >> When looking at org-clock-persistence-insinuate it looks like org-cloc= k >> load will only run after org-mode gets started whereas org-clock-save >> will always be called when exiting emacs: >> >> (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)) >> >> Not running org-mode-hook (i.e. not starting org-mode) thus does not >> load clock data but org-clock-save overwrites any prviously saved data >> when exiting emacs. >> >> An easy fix for that would be to just add org-clock-load to e.g. >> emacs-startup-hook. But this will only work if the code in >> org-clock-load does not depend on any org-mode initialization code (or >> would require loading org-mode). >> >> So org-clock-save should probably check if org-clock-load has been >> running during the current emacs session (or if clock persistence was >> just enabled) and only then save clock data when exiting emacs. I trie= d >> to add this to the code in org-clock-save: >> >> diff --git a/lisp/org-clock.el b/lisp/org-clock.el >> index c7ebbf8..c0fe4e6 100644 >> --- a/lisp/org-clock.el >> +++ b/lisp/org-clock.el >> @@ -1803,7 +1803,8 @@ This function is made for clock tables." >> "Persist various clock-related data to disk. >> The details of what will be saved are regulated by the variable >> `org-clock-persist'." >> - (when org-clock-persist >> + (when (and org-clock-persist >> + (or org-clock-loaded (not (file-exists-p >> org-clock-persist-file)))) >> (let (b) >> (with-current-buffer (find-file (expand-file-name >> org-clock-persist-file)) >> (progn >> >> >> /Kai >> >> diff --git a/lisp/org-clock.el b/lisp/org-clock.el >> index c7ebbf8..c0fe4e6 100644 >> --- a/lisp/org-clock.el >> +++ b/lisp/org-clock.el >> @@ -1803,7 +1803,8 @@ This function is made for clock tables." >> "Persist various clock-related data to disk. >> The details of what will be saved are regulated by the variable >> `org-clock-persist'." >> - (when org-clock-persist >> + (when (and org-clock-persist >> + (or org-clock-loaded (not (file-exists-p >> org-clock-persist-file)))) >> (let (b) >> (with-current-buffer (find-file (expand-file-name >> org-clock-persist-file)) >> (progn >=20 >=20 > I see you point, but I am not convinced that you fix is the right one.=20 > What one really wants to do is save the clock and history if and only i= f > the clock has been used in the current session. So I guess it is bette= r > to create a special variable org-clock-used-in-this-session which then > will be set to t each time clock-in starts a clock somewhere. I believ= e > this would be a better insurance policy. You're right - this would be even better. > Would you like to try your hand at a patch in this spirit? I've just started to play with emacs lisp. But this sounds like something not too difficult. So thanks for the offer :-), i'm going to give it a try ... > - Carsten >=20 >> _______________________________________________ >> 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 >=20 > - Carsten >=20 >=20 >=20 >=20