Fix doom-guess-mode-h being too aggressive

It would trigger set-auto-mode whenever files are written to (e.g. when
persp-mode writes its workspace/session files, which have unsafe local
variables, so the user is inundated with prompts to accept them).

Now, doom-guess-mode-h will only work on files with shebang lines.
This commit is contained in:
Henrik Lissner 2019-10-19 13:50:42 -04:00
parent 22ae9cca15
commit 9b003e0516
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395

View File

@ -80,9 +80,13 @@ possible."
(add-hook! 'after-save-hook (add-hook! 'after-save-hook
(defun doom-guess-mode-h () (defun doom-guess-mode-h ()
"Guess mode when saving a file in `fundamental-mode'." "Guess mode when saving a file in `fundamental-mode'."
(when (and (eq major-mode 'fundamental-mode) (and (eq major-mode 'fundamental-mode)
(buffer-file-name (buffer-base-buffer))) (buffer-file-name (buffer-base-buffer))
(set-auto-mode)))) (>= (buffer-size) 2)
(save-restriction
(widen)
(string= "#!" (buffer-substring (point-min) (+ 2 (point-min)))))
(set-auto-mode))))
;; ;;