[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 1292b64216f: Add auto save timer to save-place (bug#75837)
From: |
Eli Zaretskii |
Subject: |
master 1292b64216f: Add auto save timer to save-place (bug#75837) |
Date: |
Sat, 1 Feb 2025 15:02:11 -0500 (EST) |
branch: master
commit 1292b64216f636bacea7fedf578b373f03affdd8
Author: shipmints <shipmints@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>
Add auto save timer to save-place (bug#75837)
* lisp/saveplace.el (save-place-autosave-interval):
New user option 'save-place-autosave-interval' which defaults to nil,
and has a custom :set to manage the timer. Add
'save-place--manage-timer' to enable or cancel the timer if the mode is
enabled and 'save-place-autosave-interval' is non-nil. Amend
'save-place-mode' to invoke save-place--manage-timer. Add
'save-place--cancel-timer'. Add 'save-place--autosave'.
---
etc/NEWS | 19 +++++++++++++++++++
lisp/saveplace.el | 45 +++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 93e2d0ebc65..259b6e03549 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -465,6 +465,25 @@ This user option controls the width of the type column on
the bookmark
menu 'bookmark-bmenu-list'. The default value is 8 which is backwards
compatible.
+** Saveplace
+
+---
+*** You can now regularly auto-save places.
+Customize 'save-place-autosave-interval' to the number of seconds
+between auto saving places. For example, to save places every 5
+minutes:
+
+ M-x customize-option RET save-place-autosave-interval RET and set to
+ 300 seconds.
+
+Or in elisp:
+
+ (setopt save-place-autosave-interval (* 60 5))
+
+If 'save-place-autosave-interval' is nil, auto saving is disabled; this
+is the default. As before, saved places are scheduled to be saved at
+Emacs exit.
+
** Gnus
---
diff --git a/lisp/saveplace.el b/lisp/saveplace.el
index c2e68f39730..37b657073cc 100644
--- a/lisp/saveplace.el
+++ b/lisp/saveplace.el
@@ -208,6 +208,45 @@ disabled, i.e., no files are excluded."
(declare-function dired-current-directory "dired" (&optional localp))
+(defvar save-place--autosave-timer nil)
+
+(defun save-place--cancel-timer ()
+ "Cancel `save-place-autosave' timer, if set."
+ (when (timerp save-place--autosave-timer)
+ (cancel-timer save-place--autosave-timer))
+ (setq save-place--autosave-timer nil))
+
+(defvar save-place-autosave-interval)
+
+(defun save-place--manage-timer ()
+ "Set or cancel an invocation of `save-place--autosave' on a timer.
+If `save-place-mode' is enabled, set the timer, otherwise cancel the timer."
+ (if (and save-place-mode
+ save-place-autosave-interval
+ (null save-place--autosave-timer))
+ (setq save-place--autosave-timer
+ (run-with-timer
+ save-place-autosave-interval
+ save-place-autosave-interval #'save-place--autosave))
+ (save-place--cancel-timer)))
+
+(defcustom save-place-autosave-interval nil
+ "The interval between auto saves of buffer places.
+If set to nil, disables timer-based auto saving.
+Use `setopt' or Customize commands to set this option."
+ :type '(choice (const :tag "Disabled" nil)
+ (integer :tag "Seconds"))
+ :version "31.1"
+ :set (lambda (sym val)
+ (set-default sym val)
+ (save-place--cancel-timer)
+ (save-place--manage-timer)))
+
+(defun save-place--autosave ()
+ "Called by `save-place--autosave-timer'."
+ (save-places-to-alist)
+ (save-place-alist-to-file))
+
(defun save-place--setup-hooks (add)
(cond
(add
@@ -235,7 +274,8 @@ This means when you visit a file, point goes to the last
place
where it was when you previously visited the same file."
:global t
:group 'save-place
- (save-place--setup-hooks save-place-mode))
+ (save-place--setup-hooks save-place-mode)
+ (save-place--manage-timer))
(make-variable-buffer-local 'save-place-mode)
@@ -258,7 +298,8 @@ file:
dired-subdir-alist
(dired-current-directory))))
(message "Buffer `%s' not visiting a file or directory" (buffer-name))
- (save-place--setup-hooks save-place-mode)))
+ (save-place--setup-hooks save-place-mode)
+ (save-place--manage-timer)))
(declare-function dired-get-filename "dired" (&optional localp
no-error-if-not-filep))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 1292b64216f: Add auto save timer to save-place (bug#75837),
Eli Zaretskii <=