summaryrefslogtreecommitdiff
path: root/bookmark-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-06-18 17:06:03 +0800
committerJSDurand <mmemmew@gmail.com>2023-06-18 17:06:03 +0800
commit409afb58f365d609c80c598a5de687213c027065 (patch)
tree4b41bddb6449f2eab5662dc90f992cbde71db4cb /bookmark-conf.el
parent3d8fffd03f44e5734e96cb76ea5b29b544955697 (diff)
desktop and bookmark: proper save mechanism
* bookmark-conf.el (durand-saving-bookmarks): This variable indicates whether or not we are saving bookmarks already. (#'bookmark-write-file): Just a formating change. (durand-save-bookmark-or-desktop): Save bookmarks and/or the desktop file, depending on its argument. (ctl-x-r-map): Bind 'C-x r s' to `durand-save-bookmark-or-desktop`. * desktop-conf.el (durand-saving-bookmarks): In case this variable is not defined, silence the errors. (desktop-also-save-bookmarks): If we are not already saving bookmarks, save the bookmarks as well. (desktop-save-hook): Add `desktop-also-save-bookmarks` to this hook, so that when saving desktop and not already saving bookmarks, Emacs can automatically save bookmarks as well.
Diffstat (limited to 'bookmark-conf.el')
-rw-r--r--bookmark-conf.el30
1 files changed, 29 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