summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bookmark-conf.el30
-rw-r--r--desktop-conf.el12
2 files changed, 41 insertions, 1 deletions
diff --git a/bookmark-conf.el b/bookmark-conf.el
index 074628f..eddb3d5 100644
--- a/bookmark-conf.el
+++ b/bookmark-conf.el
@@ -442,8 +442,36 @@ Modified by Durand to use `print' instead of `pp'.
(kill-buffer (current-buffer))
(progress-reporter-done reporter))))))
-(advice-add #'bookmark-write-file :override #'durand-bookmark-write-file)
+(advice-add #'bookmark-write-file :override
+ #'durand-bookmark-write-file)
+;;; Intelligent saving of bookmarks and desktop files
+
+(load-config "desktop-conf.el")
+
+(defvar durand-saving-bookmarks nil
+ "Non-nil if we are saving bookmarks already.")
+
+(defun durand-save-bookmark-or-desktop (&optional arg)
+ "Save bookmarks and/or desktop depending on ARG.
+
+If and only if ARG is non-nil, save the desktop file.
+
+If and only if ARG is an integer, do not save bookmarks.
+
+Below are listed three possible scenarios:
+
+1. ARG = nil: save bookmarks only.
+2. ARG = '(4): save both bookmarks and desktop.
+3. ARG = integer: save desktop only."
+ (interactive "P")
+ (cond (arg
+ (let ((durand-saving-bookmarks t))
+ (desktop-save (car desktop-path))
+ (message "desktop saved"))))
+ (cond ((not (integerp arg)) (bookmark-save))))
+
+(define-key ctl-x-r-map (vector ?s) #'durand-save-bookmark-or-desktop)
(provide 'bookmark-conf)
;;; bookmark-conf.el ends here
diff --git a/desktop-conf.el b/desktop-conf.el
index 462c549..074aad0 100644
--- a/desktop-conf.el
+++ b/desktop-conf.el
@@ -198,5 +198,17 @@ no questions asked."
(desktop-save-mode 1)
+;;; Add a hook to save bookmarks if we are not already saving them.
+
+(defvar durand-saving-bookmarks)
+
+(defun desktop-also-save-bookmarks ()
+ "Save bookmarks if we are not already saving bookmarks."
+ (cond
+ ((and (functionp #'bookmark-save) (not durand-saving-bookmarks))
+ (bookmark-save))))
+
+(add-hook 'desktop-save-hook #'desktop-also-save-bookmarks)
+
(provide 'desktop-conf)
;;; desktop-conf.el ends here