From bc53a7008a2ba1b9f30a6bbfad5d264f11c65fae Mon Sep 17 00:00:00 2001 From: toctan Date: Tue, 1 Jul 2014 20:47:15 +0800 Subject: [PATCH] Set buffer mode according to `auto-mode-alist' With this, after we create a special buffer, the major-mode get set automatically. For example, we create a new buffer named "ruby.rb", `ruby-mode` was automatically enabled. --- core/prelude-editor.el | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/prelude-editor.el b/core/prelude-editor.el index 5cc8e70..4a9b1b4 100644 --- a/core/prelude-editor.el +++ b/core/prelude-editor.el @@ -181,6 +181,12 @@ The body of the advice is in BODY." (when (version<= "24.4" emacs-version) (add-hook 'focus-out-hook 'prelude-save-all-buffers)) +(defadvice set-buffer-major-mode (after set-major-mode activate compile) + "Set buffer major mode according to `auto-mode-alist'." + (let* ((name (buffer-name buffer)) + (mode (assoc-default name auto-mode-alist 'string-match))) + (with-current-buffer buffer (if mode (funcall mode))))) + ;; highlight the current line (global-hl-line-mode +1)