comparison lisp/files.el @ 50423:e1c7e157854c

(hack-local-variables-prop-line): New arg MODE-ONLY. (hack-local-variables): When MODE-ONLY is set, pass it along to hack-local-variables-prop-line.
author Richard M. Stallman <rms@gnu.org>
date Thu, 03 Apr 2003 23:00:22 +0000
parents 8e666b72c381
children b4cb33eddbaa
comparison
equal deleted inserted replaced
50422:b03765d292c2 50423:e1c7e157854c
1915 (skip-chars-backward " \t") 1915 (skip-chars-backward " \t")
1916 (setq end (point)) 1916 (setq end (point))
1917 (goto-char beg) 1917 (goto-char beg)
1918 end)))) 1918 end))))
1919 1919
1920 (defun hack-local-variables-prop-line () 1920 (defun hack-local-variables-prop-line (&optional mode-only)
1921 "Set local variables specified in the -*- line. 1921 "Set local variables specified in the -*- line.
1922 Ignore any specification for `mode:' and `coding:'; 1922 Ignore any specification for `mode:' and `coding:';
1923 `set-auto-mode' should already have handled `mode:', 1923 `set-auto-mode' should already have handled `mode:',
1924 `set-auto-coding' should already have handled `coding:'." 1924 `set-auto-coding' should already have handled `coding:'.
1925 If MODE-ONLY is non-nil, all we do is check whether the major mode
1926 is specified, returning t if it is specified."
1925 (save-excursion 1927 (save-excursion
1926 (goto-char (point-min)) 1928 (goto-char (point-min))
1927 (let ((result nil) 1929 (let ((result nil)
1928 (end (set-auto-mode-1)) 1930 (end (set-auto-mode-1))
1931 mode-specified
1929 (enable-local-variables 1932 (enable-local-variables
1930 (and local-enable-local-variables enable-local-variables))) 1933 (and local-enable-local-variables enable-local-variables)))
1931 ;; Parse the -*- line into the `result' alist. 1934 ;; Parse the -*- line into the RESULT alist.
1935 ;; Also set MODE-SPECIFIED if we see a spec or `mode'.
1932 (cond ((not end) 1936 (cond ((not end)
1933 nil) 1937 nil)
1934 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") 1938 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
1935 ;; Simple form: "-*- MODENAME -*-". Already handled. 1939 ;; Simple form: "-*- MODENAME -*-". Already handled.
1940 (setq mode-specified t)
1936 nil) 1941 nil)
1937 (t 1942 (t
1938 ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' 1943 ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
1939 ;; (last ";" is optional). 1944 ;; (last ";" is optional).
1940 (while (< (point) end) 1945 (while (< (point) end)
1956 ;; That is inconsistent, but we're stuck with it. 1961 ;; That is inconsistent, but we're stuck with it.
1957 ;; The same can be said for `coding' in set-auto-coding. 1962 ;; The same can be said for `coding' in set-auto-coding.
1958 (or (equal (downcase (symbol-name key)) "mode") 1963 (or (equal (downcase (symbol-name key)) "mode")
1959 (equal (downcase (symbol-name key)) "coding") 1964 (equal (downcase (symbol-name key)) "coding")
1960 (setq result (cons (cons key val) result))) 1965 (setq result (cons (cons key val) result)))
1966 (if (equal (downcase (symbol-name key)) "mode")
1967 (setq mode-specified t))
1961 (skip-chars-forward " \t;"))) 1968 (skip-chars-forward " \t;")))
1962 (setq result (nreverse result)))) 1969 (setq result (nreverse result))))
1963 1970
1964 (if (and result 1971 (if mode-only mode-specified
1965 (or (eq enable-local-variables t) 1972 (if (and result
1966 (and enable-local-variables 1973 (or mode-only
1967 (save-window-excursion 1974 (eq enable-local-variables t)
1968 (condition-case nil 1975 (and enable-local-variables
1969 (switch-to-buffer (current-buffer)) 1976 (save-window-excursion
1970 (error 1977 (condition-case nil
1971 ;; If we fail to switch in the selected window, 1978 (switch-to-buffer (current-buffer))
1972 ;; it is probably a minibuffer. 1979 (error
1973 ;; So try another window. 1980 ;; If we fail to switch in the selected window,
1974 (condition-case nil 1981 ;; it is probably a minibuffer.
1975 (switch-to-buffer-other-window (current-buffer)) 1982 ;; So try another window.
1976 (error 1983 (condition-case nil
1977 (switch-to-buffer-other-frame (current-buffer)))))) 1984 (switch-to-buffer-other-window (current-buffer))
1978 (y-or-n-p (format "Set local variables as specified in -*- line of %s? " 1985 (error
1979 (file-name-nondirectory buffer-file-name))))))) 1986 (switch-to-buffer-other-frame (current-buffer))))))
1980 (let ((enable-local-eval enable-local-eval)) 1987 (y-or-n-p (format "Set local variables as specified in -*- line of %s? "
1981 (while result 1988 (file-name-nondirectory buffer-file-name)))))))
1982 (hack-one-local-variable (car (car result)) (cdr (car result))) 1989 (let ((enable-local-eval enable-local-eval))
1983 (setq result (cdr result)))))))) 1990 (while result
1991 (hack-one-local-variable (car (car result)) (cdr (car result)))
1992 (setq result (cdr result)))))
1993 nil))))
1984 1994
1985 (defvar hack-local-variables-hook nil 1995 (defvar hack-local-variables-hook nil
1986 "Normal hook run after processing a file's local variables specs. 1996 "Normal hook run after processing a file's local variables specs.
1987 Major modes can use this to examine user-specified local variables 1997 Major modes can use this to examine user-specified local variables
1988 in order to initialize other data structure based on them.") 1998 in order to initialize other data structure based on them.")
1989 1999
1990 (defun hack-local-variables (&optional mode-only) 2000 (defun hack-local-variables (&optional mode-only)
1991 "Parse and put into effect this buffer's local variables spec. 2001 "Parse and put into effect this buffer's local variables spec.
1992 If MODE-ONLY is non-nil, all we do is check whether the major mode 2002 If MODE-ONLY is non-nil, all we do is check whether the major mode
1993 is specified, returning t if it is specified." 2003 is specified, returning t if it is specified."
1994 (unless mode-only 2004 (let ((mode-specified
1995 (hack-local-variables-prop-line)) 2005 ;; If MODE-ONLY is t, we check here for specifying the mode
1996 ;; Look for "Local variables:" line in last page. 2006 ;; in the -*- line. If MODE-ONLY is nil, we process
1997 (let (mode-specified 2007 ;; the -*- line here.
2008 (hack-local-variables-prop-line mode-only))
1998 (enable-local-variables 2009 (enable-local-variables
1999 (and local-enable-local-variables enable-local-variables))) 2010 (and local-enable-local-variables enable-local-variables)))
2011 ;; Look for "Local variables:" line in last page.
2000 (save-excursion 2012 (save-excursion
2001 (goto-char (point-max)) 2013 (goto-char (point-max))
2002 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) 2014 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
2003 (if (let ((case-fold-search t)) 2015 (if (let ((case-fold-search t))
2004 (and (search-forward "Local Variables:" nil t) 2016 (and (search-forward "Local Variables:" nil t)