summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2009-10-25 07:48:05 +0100
committerCarsten Dominik <carsten.dominik@gmail.com>2009-10-25 07:48:05 +0100
commit4c3bc6482dce9d9e7398ffabc79c0b7a8a9b970e (patch)
tree725a508ccb9380d96b4ee7b94985d4bf869dd73e
parentf74f8ca2abce88ec3a6fec77c1449ad853f898d0 (diff)
downloadorg-mode-4c3bc6482dce9d9e7398ffabc79c0b7a8a9b970e.tar.gz
Only save clock stuff if it has been loaded as well
Kai Tetzlaff writes: > 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:
-rwxr-xr-xlisp/ChangeLog7
-rw-r--r--lisp/org-clock.el8
2 files changed, 14 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6159e8c..1b5848e 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2009-10-25 Carsten Dominik <carsten.dominik@gmail.com>
+
+ * org-clock.el (org-clock-has-been-used): New variable.
+ (org-clock-in): Set `org-clock-has-been-used'.
+ (org-clock-save): Save only if clock data has been used or created
+ during this session.
+
2009-10-24 Carsten Dominik <carsten.dominik@gmail.com>
* org-clock.el (org-clock-persist): New value, to store only the
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index b1041e2..d7d1ff7 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -233,6 +233,8 @@ to add an effort property.")
"Hook run when cancelling the current clock.")
(defvar org-clock-goto-hook nil
"Hook run when selecting the currently clocked-in entry.")
+(defvar org-clock-has-been-used nil
+ "Has the clock been used during the current Emacs session?")
;;; The clock for measuring work time.
@@ -937,6 +939,7 @@ the clocking selection, associated with the letter `d'."
(move-marker org-clock-hd-marker
(save-excursion (org-back-to-heading t) (point))
(buffer-base-buffer))
+ (setq org-clock-has-been-used t)
(or global-mode-string (setq global-mode-string '("")))
(or (memq 'org-mode-line-string global-mode-string)
(setq global-mode-string
@@ -1824,7 +1827,10 @@ 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
+ org-clock-has-been-used
+ (not (file-exists-p org-clock-persist-file))))
(let (b)
(with-current-buffer (find-file (expand-file-name org-clock-persist-file))
(progn