aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/files.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/files.el')
-rw-r--r--lisp/files.el220
1 files changed, 105 insertions, 115 deletions
diff --git a/lisp/files.el b/lisp/files.el
index ee6793bec7..d14c462535 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1646,40 +1646,33 @@ in that case, this function acts as if `enable-local-variables' were t."
(lambda (elt)
(cons (purecopy (car elt)) (cdr elt)))
'(("\\.te?xt\\'" . text-mode)
- ("\\.tex\\'" . tex-mode)
+ ("\\.[tT]e[xX]\\'" . tex-mode)
("\\.ins\\'" . tex-mode) ;Installation files for TeX packages.
("\\.ltx\\'" . latex-mode)
("\\.dtx\\'" . doctex-mode)
("\\.el\\'" . emacs-lisp-mode)
("\\.\\(scm\\|stk\\|ss\\|sch\\)\\'" . scheme-mode)
("\\.l\\'" . lisp-mode)
- ("\\.lisp\\'" . lisp-mode)
- ("\\.f\\'" . fortran-mode)
- ("\\.F\\'" . fortran-mode)
+ ("\\.li?sp\\'" . lisp-mode)
+ ("\\.[fF]\\'" . fortran-mode)
("\\.for\\'" . fortran-mode)
("\\.p\\'" . pascal-mode)
("\\.pas\\'" . pascal-mode)
("\\.ad[abs]\\'" . ada-mode)
("\\.ad[bs].dg\\'" . ada-mode)
- ("\\.\\([pP]\\([Llm]\\|erl\\)\\|al\\)\\'" . perl-mode)
+ ("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode)
("\\.s?html?\\'" . html-mode)
("\\.mk\\'" . makefile-mode)
- ("\\(M\\|m\\|GNUm\\)akefile\\'" . makefile-mode)
+ ("\\([Mm]\\|GNUm\\)akep*file\\'" . makefile-mode)
("\\.am\\'" . makefile-mode) ;For Automake.
;; Less common extensions come here
;; so more common ones above are found faster.
("\\.texinfo\\'" . texinfo-mode)
("\\.te?xi\\'" . texinfo-mode)
- ("\\.s\\'" . asm-mode)
- ("\\.S\\'" . asm-mode)
+ ("\\.[sS]\\'" . asm-mode)
("\\.asm\\'" . asm-mode)
- ("ChangeLog\\'" . change-log-mode)
- ("change\\.log\\'" . change-log-mode)
- ("changelo\\'" . change-log-mode)
- ("ChangeLog\\.[0-9]+\\'" . change-log-mode)
- ;; for MSDOS and MS-Windows (which are case-insensitive)
- ("changelog\\'" . change-log-mode)
- ("changelog\\.[0-9]+\\'" . change-log-mode)
+ ("[cC]hange\\.?[lL]og?\\'" . change-log-mode)
+ ("[cC]hange[lL]og\\.[0-9]+\\'" . change-log-mode)
("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode)
("\\.scm\\.[0-9]*\\'" . scheme-mode)
("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode)
@@ -1688,36 +1681,27 @@ in that case, this function acts as if `enable-local-variables' were t."
("\\(/\\|\\`\\)\\.\\(bash_logout\\|shrc\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode)
("\\(/\\|\\`\\)\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode)
("\\.m?spec\\'" . sh-mode)
- ("\\.mm\\'" . nroff-mode)
- ("\\.me\\'" . nroff-mode)
- ("\\.ms\\'" . nroff-mode)
+ ("\\.m[mes]\\'" . nroff-mode)
("\\.man\\'" . nroff-mode)
- ("\\.TeX\\'" . tex-mode)
("\\.sty\\'" . latex-mode)
- ("\\.cls\\'" . latex-mode) ;LaTeX 2e class
- ("\\.clo\\'" . latex-mode) ;LaTeX 2e class option
+ ("\\.cl[so]\\'" . latex-mode) ;LaTeX 2e class option
("\\.bbl\\'" . latex-mode)
("\\.bib\\'" . bibtex-mode)
("\\.sql\\'" . sql-mode)
- ("\\.m4\\'" . m4-mode)
- ("\\.mc\\'" . m4-mode)
- ("\\.mf\\'" . metafont-mode)
- ("\\.mp\\'" . metapost-mode)
+ ("\\.m[4c]\\'" . m4-mode)
+ ("\\.m[fp]\\'" . metapost-mode)
("\\.vhdl?\\'" . vhdl-mode)
("\\.article\\'" . text-mode)
("\\.letter\\'" . text-mode)
- ("\\.tcl\\'" . tcl-mode)
+ ("\\.i?tcl\\'" . tcl-mode)
("\\.exp\\'" . tcl-mode)
- ("\\.itcl\\'" . tcl-mode)
("\\.itk\\'" . tcl-mode)
("\\.icn\\'" . icon-mode)
("\\.sim\\'" . simula-mode)
("\\.mss\\'" . scribe-mode)
- ("\\.f90\\'" . f90-mode)
- ("\\.f95\\'" . f90-mode)
+ ("\\.f9[05]\\'" . f90-mode)
("\\.indent\\.pro\\'" . fundamental-mode) ; to avoid idlwave-mode
("\\.pro\\'" . idlwave-mode)
- ("\\.lsp\\'" . lisp-mode)
("\\.prolog\\'" . prolog-mode)
("\\.tar\\'" . tar-mode)
("\\.\\(arc\\|zip\\|lzh\\|zoo\\|ear\\|jar\\|war\\)\\'" . archive-mode)
@@ -1733,10 +1717,11 @@ in that case, this function acts as if `enable-local-variables' were t."
("\\`/tmp/fol/" . text-mode)
("\\.oak\\'" . scheme-mode)
("\\.sgml?\\'" . sgml-mode)
- ("\\.xml\\'" . sgml-mode)
- ("\\.xsl\\'" . sgml-mode)
+ ("\\.x[ms]l\\'" . xml-mode)
("\\.dtd\\'" . sgml-mode)
("\\.ds\\(ss\\)?l\\'" . dsssl-mode)
+ ("\\.js\\'" . java-mode) ; javascript-mode would be better
+ ("\\.x[bp]m\\'" . c-mode)
;; .emacs or .gnus or .viper following a directory delimiter in
;; Unix, MSDOG or VMS syntax.
("[]>:/\\]\\..*\\(emacs\\|gnus\\|viper\\)\\'" . emacs-lisp-mode)
@@ -1760,7 +1745,7 @@ in that case, this function acts as if `enable-local-variables' were t."
;; or .#<file>.<rev>-<rev> or VC's <file>.~<rev>~.
;; Using mode nil rather than `ignore' would let the search continue
;; through this list (with the shortened name) rather than start over.
- ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" ignore t)
+ ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" nil t)
;; The following should come after the ChangeLog pattern
;; for the sake of ChangeLog.1, etc.
;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too.
@@ -1849,12 +1834,20 @@ be interpreted by the interpreter matched by the second group of the
regular expression. The mode is then determined as the mode associated
with that interpreter in `interpreter-mode-alist'.")
+(defvar xml-based-modes '(html-mode)
+ "Modes that override an XML declaration.
+When `set-auto-mode' sees an <?xml or <!DOCTYPE declaration, that
+buffer will be in some XML mode. If `auto-mode-alist' associates
+the file with one of the modes in this list, that mode will be
+used. Else `xml-mode' or `sgml-mode' is used.")
+
(defun set-auto-mode (&optional just-from-file-name)
"Select major mode appropriate for current buffer.
-This checks for a -*- mode tag in the buffer's text,
-compares the filename against the entries in `auto-mode-alist',
-or checks the interpreter that runs this file against
-`interpreter-mode-alist'.
+This checks for a -*- mode tag in the buffer's text, checks the
+interpreter that runs this file against `interpreter-mode-alist',
+looks for an <?xml or <!DOCTYPE declaration (see
+`xml-based-modes'), or compares the filename against the entries
+in `auto-mode-alist'.
It does not check for the `mode:' local variable in the
Local Variables section of the file; for that, use `hack-local-variables'.
@@ -1866,87 +1859,84 @@ If the optional argument JUST-FROM-FILE-NAME is non-nil,
then we do not set anything but the major mode,
and we don't even do that unless it would come from the file name."
;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
- (let (end done modes)
- (save-excursion
- (goto-char (point-min))
- (skip-chars-forward " \t\n")
- (and enable-local-variables
- (setq end (set-auto-mode-1))
- (if (save-excursion (search-forward ":" end t))
- ;; Find all specifications for the `mode:' variable
- ;; and execute them left to right.
- (while (let ((case-fold-search t))
- (or (and (looking-at "mode:")
- (goto-char (match-end 0)))
- (re-search-forward "[ \t;]mode:" end t)))
- (skip-chars-forward " \t")
- (let ((beg (point)))
- (if (search-forward ";" end t)
- (forward-char -1)
- (goto-char end))
- (skip-chars-backward " \t")
- (push (intern (concat (downcase (buffer-substring beg (point))) "-mode"))
- modes)))
- ;; Simple -*-MODE-*- case.
- (push (intern (concat (downcase (buffer-substring (point) end))
- "-mode"))
- modes))))
- ;; If we found modes to use, invoke them now,
- ;; outside the save-excursion.
+ (let (end done mode modes xml)
(unless just-from-file-name
- (dolist (mode (nreverse modes))
- (if (not (functionp mode))
- (message "Ignoring unknown mode `%s'" mode)
- (setq done t)
- (funcall mode))))
- ;; If we didn't find a mode from a -*- line, try using the file name.
+ ;; Find a -*- mode tag
+ (save-excursion
+ (goto-char (point-min))
+ (skip-chars-forward " \t\n")
+ ;; While we're at this point, check xml for later.
+ (setq xml (looking-at "<\\?xml \\|<!DOCTYPE"))
+ (and enable-local-variables
+ (setq end (set-auto-mode-1))
+ (if (save-excursion (search-forward ":" end t))
+ ;; Find all specifications for the `mode:' variable
+ ;; and execute them left to right.
+ (while (let ((case-fold-search t))
+ (or (and (looking-at "mode:")
+ (goto-char (match-end 0)))
+ (re-search-forward "[ \t;]mode:" end t)))
+ (skip-chars-forward " \t")
+ (let ((beg (point)))
+ (if (search-forward ";" end t)
+ (forward-char -1)
+ (goto-char end))
+ (skip-chars-backward " \t")
+ (push (intern (concat (downcase (buffer-substring beg (point))) "-mode"))
+ modes)))
+ ;; Simple -*-MODE-*- case.
+ (push (intern (concat (downcase (buffer-substring (point) end))
+ "-mode"))
+ modes))))
+ ;; If we found modes to use, invoke them now, outside the save-excursion.
+ (if modes
+ (dolist (mode (nreverse modes))
+ (if (not (functionp mode))
+ (message "Ignoring unknown mode `%s'" mode)
+ (setq done t)
+ (funcall mode)))
+ ;; If we didn't, look for an interpreter specified in the first line.
+ ;; As a special case, allow for things like "#!/bin/env perl", which
+ ;; finds the interpreter anywhere in $PATH.
+ (setq mode (save-excursion
+ (goto-char (point-min))
+ (if (looking-at auto-mode-interpreter-regexp)
+ (match-string 2)
+ ""))
+ ;; Map interpreter name to a mode, signalling we're done at the
+ ;; same time.
+ done (assoc (file-name-nondirectory mode)
+ interpreter-mode-alist))
+ ;; If we found an interpreter mode to use, invoke it now.
+ (if done (funcall (cdr done)))))
(if (and (not done) buffer-file-name)
- (let ((name buffer-file-name)
- (keep-going t))
+ (let ((name buffer-file-name))
;; Remove backup-suffixes from file name.
(setq name (file-name-sans-versions name))
- (while keep-going
- (setq keep-going nil)
- (let ((alist auto-mode-alist)
- (mode nil))
- ;; Find first matching alist entry.
- (let ((case-fold-search
- (memq system-type '(vax-vms windows-nt cygwin))))
- (while (and (not mode) alist)
- (if (string-match (car (car alist)) name)
- (if (and (consp (cdr (car alist)))
- (nth 2 (car alist)))
- (setq mode (car (cdr (car alist)))
- name (substring name 0 (match-beginning 0))
- keep-going t)
- (setq mode (cdr (car alist))
- keep-going nil)))
- (setq alist (cdr alist))))
- (if mode
- ;; When JUST-FROM-FILE-NAME is set,
- ;; we are working on behalf of set-visited-file-name.
- ;; In that case, if the major mode specified is the
- ;; same one we already have, don't actually reset it.
- ;; We don't want to lose minor modes such as Font Lock.
- (unless (and just-from-file-name (eq mode major-mode))
- (funcall mode))
- ;; If we can't deduce a mode from the file name,
- ;; look for an interpreter specified in the first line.
- ;; As a special case, allow for things like "#!/bin/env perl",
- ;; which finds the interpreter anywhere in $PATH.
- (let ((interpreter
- (save-excursion
- (goto-char (point-min))
- (if (looking-at auto-mode-interpreter-regexp)
- (match-string 2)
- "")))
- elt)
- ;; Map interpreter name to a mode.
- (setq elt (assoc (file-name-nondirectory interpreter)
- interpreter-mode-alist))
- (unless just-from-file-name
- (if elt
- (funcall (cdr elt))))))))))))
+ (while (not done)
+ ;; Find first matching alist entry.
+ (let ((case-fold-search
+ (memq system-type '(vax-vms windows-nt cygwin))))
+ (if (and (setq mode (assoc-default name auto-mode-alist
+ 'string-match))
+ (consp mode)
+ (cadr mode))
+ (setq mode (car mode)
+ name (substring name 0 (match-beginning 0)))
+ (setq done t)))
+ (if mode
+ ;; When JUST-FROM-FILE-NAME is set, we are working on behalf
+ ;; of set-visited-file-name. In that case, if the major mode
+ ;; specified is the same one we already have, don't actually
+ ;; reset it. We don't want to lose minor modes such as Font
+ ;; Lock.
+ (unless (and just-from-file-name (eq mode major-mode))
+ (if (if xml (memq mode xml-based-modes) t)
+ (funcall mode)
+ (xml-mode)))))))
+ (and (not done)
+ xml
+ (xml-mode))))
(defun set-auto-mode-1 ()
@@ -2157,7 +2147,7 @@ is specified, returning t if it is specified."
(error "Local variables entry is missing the suffix")))
(forward-line 1))
(goto-char (point-min))
-
+
(while (not (eobp))
;; Find the variable name; strip whitespace.
(skip-chars-forward " \t")