Skip to content

Commit

Permalink
Merge pull request #1072 from Passky/master
Browse files Browse the repository at this point in the history
Avoid auto-save nonwritable buffers.
  • Loading branch information
redguardtoo authored Nov 21, 2024
2 parents a22347d + 16dfeaf commit 1d43adf
Showing 1 changed file with 10 additions and 12 deletions.
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

0 comments on commit 1d43adf

Please sign in to comment.