1581 |
(goto-char (point-min)) |
(goto-char (point-min)) |
1582 |
(skip-chars-forward " \t\n") |
(skip-chars-forward " \t\n") |
1583 |
(and enable-local-variables |
(and enable-local-variables |
1584 |
;; Don't look for -*- if this file name matches any |
(setq end (set-auto-mode-1)) |
|
;; of the regexps in inhibit-first-line-modes-regexps. |
|
|
(let ((temp inhibit-first-line-modes-regexps) |
|
|
(name (if buffer-file-name |
|
|
(file-name-sans-versions buffer-file-name) |
|
|
(buffer-name)))) |
|
|
(while (let ((sufs inhibit-first-line-modes-suffixes)) |
|
|
(while (and sufs (not (string-match (car sufs) name))) |
|
|
(setq sufs (cdr sufs))) |
|
|
sufs) |
|
|
(setq name (substring name 0 (match-beginning 0)))) |
|
|
(while (and temp |
|
|
(not (string-match (car temp) name))) |
|
|
(setq temp (cdr temp))) |
|
|
(not temp)) |
|
|
(search-forward "-*-" (save-excursion |
|
|
;; If the file begins with "#!" |
|
|
;; (exec interpreter magic), look |
|
|
;; for mode frobs in the first two |
|
|
;; lines. You cannot necessarily |
|
|
;; put them in the first line of |
|
|
;; such a file without screwing up |
|
|
;; the interpreter invocation. |
|
|
(end-of-line (and (looking-at "^#!") 2)) |
|
|
(point)) t) |
|
1585 |
(progn |
(progn |
|
(skip-chars-forward " \t") |
|
|
(setq beg (point)) |
|
|
(search-forward "-*-" |
|
|
(save-excursion (end-of-line) (point)) |
|
|
t)) |
|
|
(progn |
|
|
(forward-char -3) |
|
|
(skip-chars-backward " \t") |
|
|
(setq end (point)) |
|
|
(goto-char beg) |
|
1586 |
(if (save-excursion (search-forward ":" end t)) |
(if (save-excursion (search-forward ":" end t)) |
1587 |
;; Find all specifications for the `mode:' variable |
;; Find all specifications for the `mode:' variable |
1588 |
;; and execute them left to right. |
;; and execute them left to right. |
1659 |
(if elt |
(if elt |
1660 |
(funcall (cdr elt)))))))))))) |
(funcall (cdr elt)))))))))))) |
1661 |
|
|
1662 |
|
|
1663 |
|
(defun set-auto-mode-1 () |
1664 |
|
"Find the -*- spec in the buffer. |
1665 |
|
Call with point at the place to start searching from. |
1666 |
|
If one is found, set point to the beginning |
1667 |
|
and return the position of the end. |
1668 |
|
Otherwise, return nil; point may be changed." |
1669 |
|
(let (beg end) |
1670 |
|
(and |
1671 |
|
;; Don't look for -*- if this file name matches any |
1672 |
|
;; of the regexps in inhibit-first-line-modes-regexps. |
1673 |
|
(let ((temp inhibit-first-line-modes-regexps) |
1674 |
|
(name (if buffer-file-name |
1675 |
|
(file-name-sans-versions buffer-file-name) |
1676 |
|
(buffer-name)))) |
1677 |
|
(while (let ((sufs inhibit-first-line-modes-suffixes)) |
1678 |
|
(while (and sufs (not (string-match (car sufs) name))) |
1679 |
|
(setq sufs (cdr sufs))) |
1680 |
|
sufs) |
1681 |
|
(setq name (substring name 0 (match-beginning 0)))) |
1682 |
|
(while (and temp |
1683 |
|
(not (string-match (car temp) name))) |
1684 |
|
(setq temp (cdr temp))) |
1685 |
|
(not temp)) |
1686 |
|
|
1687 |
|
(search-forward "-*-" (save-excursion |
1688 |
|
;; If the file begins with "#!" |
1689 |
|
;; (exec interpreter magic), look |
1690 |
|
;; for mode frobs in the first two |
1691 |
|
;; lines. You cannot necessarily |
1692 |
|
;; put them in the first line of |
1693 |
|
;; such a file without screwing up |
1694 |
|
;; the interpreter invocation. |
1695 |
|
(end-of-line (and (looking-at "^#!") 2)) |
1696 |
|
(point)) t) |
1697 |
|
(progn |
1698 |
|
(skip-chars-forward " \t") |
1699 |
|
(setq beg (point)) |
1700 |
|
(search-forward "-*-" |
1701 |
|
(save-excursion (end-of-line) (point)) |
1702 |
|
t)) |
1703 |
|
(progn |
1704 |
|
(forward-char -3) |
1705 |
|
(skip-chars-backward " \t") |
1706 |
|
(setq end (point)) |
1707 |
|
(goto-char beg) |
1708 |
|
end)))) |
1709 |
|
|
1710 |
(defun hack-local-variables-prop-line () |
(defun hack-local-variables-prop-line () |
1711 |
"Set local variables specified in the -*- line. |
"Set local variables specified in the -*- line. |
1712 |
Ignore any specification for `mode:' and `coding:'; |
Ignore any specification for `mode:' and `coding:'; |
1715 |
(save-excursion |
(save-excursion |
1716 |
(goto-char (point-min)) |
(goto-char (point-min)) |
1717 |
(let ((result nil) |
(let ((result nil) |
1718 |
(end (save-excursion (end-of-line (and (looking-at "^#!") 2)) (point))) |
(end (set-auto-mode-1)) |
1719 |
(enable-local-variables |
(enable-local-variables |
1720 |
(and local-enable-local-variables enable-local-variables))) |
(and local-enable-local-variables enable-local-variables))) |
1721 |
;; Parse the -*- line into the `result' alist. |
;; Parse the -*- line into the `result' alist. |
1722 |
(cond ((not (search-forward "-*-" end t)) |
(cond ((not end) |
|
;; doesn't have one. |
|
1723 |
nil) |
nil) |
1724 |
((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") |
((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") |
1725 |
;; Simple form: "-*- MODENAME -*-". Already handled. |
;; Simple form: "-*- MODENAME -*-". Already handled. |
1727 |
(t |
(t |
1728 |
;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' |
;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' |
1729 |
;; (last ";" is optional). |
;; (last ";" is optional). |
|
(save-excursion |
|
|
(if (search-forward "-*-" end t) |
|
|
(setq end (- (point) 3)) |
|
|
(error "-*- not terminated before end of line"))) |
|
1730 |
(while (< (point) end) |
(while (< (point) end) |
1731 |
(or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*") |
(or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*") |
1732 |
(error "Malformed -*- line")) |
(error "Malformed -*- line")) |