comparison lisp/files.el @ 30689:194b7f43b959

(auto-mode-interpreter-regexp): New variable. (set-auto-mode): Use it.
author Gerd Moellmann <gerd@gnu.org>
date Tue, 08 Aug 2000 18:32:10 +0000
parents 5c09c89349f4
children b0c302c3b209
comparison
equal deleted inserted replaced
30688:f0a91dd9685b 30689:194b7f43b959
1511 (defvar inhibit-first-line-modes-suffixes nil 1511 (defvar inhibit-first-line-modes-suffixes nil
1512 "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'. 1512 "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'.
1513 When checking `inhibit-first-line-modes-regexps', we first discard 1513 When checking `inhibit-first-line-modes-regexps', we first discard
1514 from the end of the file name anything that matches one of these regexps.") 1514 from the end of the file name anything that matches one of these regexps.")
1515 1515
1516 (defvar auto-mode-interpreter-regexp
1517 "#![ \t]?\\([^ \t\n]*\
1518 /bin/env[ \t]\\)?\\([^ \t\n]+\\)"
1519 "Regular expression matching interpreters, for file mode determination.
1520 This regular expression is matched against the first line of a file
1521 to determine the file's mode in `set-auto-mode' when Emacs can't deduce
1522 a mode from the file's name. If it matches, the file is assumed to
1523 be interpreted by the interpreter matched by the second group of the
1524 regular expression. The mode is then determined as the mode associated
1525 with that interpreter in `interpreter-mode-alist'.")
1526
1516 (defun set-auto-mode (&optional just-from-file-name) 1527 (defun set-auto-mode (&optional just-from-file-name)
1517 "Select major mode appropriate for current buffer. 1528 "Select major mode appropriate for current buffer.
1518 This checks for a -*- mode tag in the buffer's text, 1529 This checks for a -*- mode tag in the buffer's text,
1519 compares the filename against the entries in `auto-mode-alist', 1530 compares the filename against the entries in `auto-mode-alist',
1520 or checks the interpreter that runs this file against 1531 or checks the interpreter that runs this file against
1632 ;; As a special case, allow for things like "#!/bin/env perl", 1643 ;; As a special case, allow for things like "#!/bin/env perl",
1633 ;; which finds the interpreter anywhere in $PATH. 1644 ;; which finds the interpreter anywhere in $PATH.
1634 (let ((interpreter 1645 (let ((interpreter
1635 (save-excursion 1646 (save-excursion
1636 (goto-char (point-min)) 1647 (goto-char (point-min))
1637 (if (looking-at "#![ \t]?\\([^ \t\n]*\ 1648 (if (looking-at auto-mode-interpreter-regexp)
1638 /bin/env[ \t]\\)?\\([^ \t\n]+\\)")
1639 (match-string 2) 1649 (match-string 2)
1640 ""))) 1650 "")))
1641 elt) 1651 elt)
1642 ;; Map interpreter name to a mode. 1652 ;; Map interpreter name to a mode.
1643 (setq elt (assoc (file-name-nondirectory interpreter) 1653 (setq elt (assoc (file-name-nondirectory interpreter)