Created
May 3, 2014 05:17
-
-
Save Pitometsu/34a5ae0b9998113e1c67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; hack that enable major mode for newly created buffer according to `auto-mode-alist' | |
(defadvice set-buffer-major-mode (after new-buffer-auto-mode activate compile) | |
"Select major mode for newly created buffer. | |
Compare the `buffer-name' the entries in `auto-mode-alist'." | |
(with-current-buffer (ad-get-arg 0) | |
(if (and (buffer-name) (not buffer-file-name)) | |
(let ((name (buffer-name))) | |
;; Remove backup-suffixes from file name. | |
(setq name (file-name-sans-versions name)) | |
;; Do not handle service buffers | |
(while (and name (not (string-match "^\\*.+\\*$" name))) | |
;; Find first matching alist entry. | |
(setq mode | |
(if (memq system-type '(windows-nt cygwin)) | |
;; System is case-insensitive. | |
(let ((case-fold-search t)) | |
(assoc-default name auto-mode-alist | |
'string-match)) | |
;; System is case-sensitive. | |
(or | |
;; First match case-sensitively. | |
(let ((case-fold-search nil)) | |
(assoc-default name auto-mode-alist | |
'string-match)) | |
;; Fallback to case-insensitive match. | |
(and auto-mode-case-fold | |
(let ((case-fold-search t)) | |
(assoc-default name auto-mode-alist | |
'string-match)))))) | |
(if (and mode | |
(consp mode) | |
(cadr mode)) | |
(setq mode (car mode) | |
name (substring name 0 (match-beginning 0))) | |
(setq name nil)) | |
(when mode | |
(set-auto-mode-0 mode t))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment