From 0858e45bacb602f3a8632dbd025911ec9e80ef98 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 25 Sep 2021 13:14:55 -0500 Subject: Set default major mode when visiting a non-file buffer --- init.el | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/init.el b/init.el index 5e20566..1d1ca39 100644 --- a/init.el +++ b/init.el @@ -185,24 +185,12 @@ In short, DO NOT USE THIS FUNCTION!!!" (setup buffers (:global "C-x k" #'acdw/kill-a-buffer) - (defun buffer-list-update@set-major-mode () - "Set `major-mode' from buffer name, even when not visiting a file." - (let ((name (buffer-name))) - (unless (or (active-minibuffer-window) - (string-prefix-p "*" name) - (not (eq major-mode 'fundamental-mode))) - (catch 'done - (dolist (cell auto-mode-alist) - (let ((regexp (car cell)) - (mode (cdr cell))) - (when (string-match regexp name) - (let ((major-mode mode)) - (funcall mode)) - (throw 'done mode)))))))) - - ;; TODO: more testing, just in case. - ;;(add-hook 'buffer-list-update-hook #'buffer-list-update@set-major-mode) - ) + ;; Set the right major mode based on buffer name, if not visiting a file. + ;; http://ruzkuku.com/emacs.d.html#orgeab93c3 + (setq-default major-mode (lambda () + (unless buffer-file-name + (let ((buffer-file-name (buffer-name))) + (set-auto-mode)))))) (setup calendar (:option calendar-week-start-day 1)) -- cgit 1.4.1-21-gabe81