Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid auto-save nonwritable buffers. #1072

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions lisp/init-misc.el
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@

(setq auto-save-visited-interval 2)

(defun my-auto-save-visited-mode-setup ()
"Auto save setup."
;; turn off `auto-save-visited-mode' in certain scenarios
(message "my-auto-save-visited-mode-setup called")
(when (or (not (buffer-file-name))
(file-remote-p (buffer-file-name))
(my-file-too-big-p (buffer-file-name))
(memq major-mode my-auto-save-exclude-major-mode-list))
(setq-local auto-save-visited-mode nil)))
(defun my-auto-save-visited-predicate ()
"Predicate to control which buffers are auto-saved."
(and (buffer-file-name)
(not (file-remote-p (buffer-file-name)))
(not (my-file-too-big-p (buffer-file-name)))
(file-writable-p (buffer-file-name))
(not (memq major-mode my-auto-save-exclude-major-mode-list))))

(setq auto-save-visited-predicate #'my-auto-save-visited-predicate)

(my-run-with-idle-timer 2 #'auto-save-visited-mode)
(add-hook 'auto-save-visited-mode-hook #'my-auto-save-visited-mode-setup)
;; (add-hook 'text-mode-hook #'my-auto-save-visited-mode-setup)
;; (add-hook 'prog-mode-hook #'my-auto-save-visited-mode-setup)
;; }}

;; {{ auto-yasnippet
Expand Down
Loading