From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kai Tetzlaff Subject: [PATCH] Avoid losing persisted clock data when exiting emac without loading org-mode Date: Fri, 23 Oct 2009 09:01:01 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040602030504070106090802" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1E9T-0006KA-TU for emacs-orgmode@gnu.org; Fri, 23 Oct 2009 03:01:31 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1E9P-0006JD-8d for emacs-orgmode@gnu.org; Fri, 23 Oct 2009 03:01:31 -0400 Received: from [199.232.76.173] (port=58273 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1E9P-0006J6-1T for emacs-orgmode@gnu.org; Fri, 23 Oct 2009 03:01:27 -0400 Received: from lo.gmane.org ([80.91.229.12]:38615) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N1E9O-0004ka-FZ for emacs-orgmode@gnu.org; Fri, 23 Oct 2009 03:01:26 -0400 Received: from list by lo.gmane.org with local (Exim 4.50) id 1N1E9M-0002PE-Gt for emacs-orgmode@gnu.org; Fri, 23 Oct 2009 09:01:24 +0200 Received: from ppp-88-217-20-136.dynamic.mnet-online.de ([88.217.20.136]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 23 Oct 2009 09:01:24 +0200 Received: from kai.tetzlaff by ppp-88-217-20-136.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 23 Oct 2009 09:01:24 +0200 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: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------040602030504070106090802 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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-clock 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 tried 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 --------------040602030504070106090802 Content-Type: text/plain; name="clock-save.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="clock-save.patch" 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 --------------040602030504070106090802 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 --------------040602030504070106090802--