comparison lisp/files.el @ 83209:c06211125947

Merged in changes from CVS trunk. Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-558 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-559 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-560 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-561 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-562 Update from CVS: lisp/subr.el (after-change-major-mode-hook): Doc fix. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-563 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-564 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-565 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-30 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-249
author Karoly Lorentey <lorentey@elte.hu>
date Thu, 23 Sep 2004 10:32:54 +0000
parents b5dee7c1d483 996392344f62
children b85b19b8eb65
comparison
equal deleted inserted replaced
83208:e318dfc2edc6 83209:c06211125947
437 437
438 (defcustom enable-local-eval 'maybe 438 (defcustom enable-local-eval 'maybe
439 "*Control processing of the \"variable\" `eval' in a file's local variables. 439 "*Control processing of the \"variable\" `eval' in a file's local variables.
440 The value can be t, nil or something else. 440 The value can be t, nil or something else.
441 A value of t means obey `eval' variables; 441 A value of t means obey `eval' variables;
442 nil means ignore them; anything else means query. 442 nil means ignore them; anything else means query."
443
444 The command \\[normal-mode] always obeys local-variables lists
445 and ignores this variable."
446 :type '(choice (const :tag "Obey" t) 443 :type '(choice (const :tag "Obey" t)
447 (const :tag "Ignore" nil) 444 (const :tag "Ignore" nil)
448 (other :tag "Query" other)) 445 (other :tag "Query" other))
449 :group 'find-file) 446 :group 'find-file)
450 447
2108 (if buffer-file-name 2105 (if buffer-file-name
2109 (file-name-nondirectory 2106 (file-name-nondirectory
2110 buffer-file-name) 2107 buffer-file-name)
2111 (concat "buffer " 2108 (concat "buffer "
2112 (buffer-name)))))))))) 2109 (buffer-name))))))))))
2113 (let ((continue t) 2110 (let (prefix prefixlen suffix beg
2114 prefix prefixlen suffix beg
2115 mode-specified
2116 (enable-local-eval enable-local-eval)) 2111 (enable-local-eval enable-local-eval))
2117 ;; The prefix is what comes before "local variables:" in its line. 2112 ;; The prefix is what comes before "local variables:" in its line.
2118 ;; The suffix is what comes after "local variables:" in its line. 2113 ;; The suffix is what comes after "local variables:" in its line.
2119 (skip-chars-forward " \t") 2114 (skip-chars-forward " \t")
2120 (or (eolp) 2115 (or (eolp)
2127 (progn (beginning-of-line) (point))))) 2122 (progn (beginning-of-line) (point)))))
2128 2123
2129 (if prefix (setq prefixlen (length prefix) 2124 (if prefix (setq prefixlen (length prefix)
2130 prefix (regexp-quote prefix))) 2125 prefix (regexp-quote prefix)))
2131 (if suffix (setq suffix (concat (regexp-quote suffix) "$"))) 2126 (if suffix (setq suffix (concat (regexp-quote suffix) "$")))
2132 (while continue 2127 (forward-line 1)
2133 ;; Look at next local variable spec. 2128 (let ((startpos (point))
2134 (if selective-display (re-search-forward "[\n\C-m]") 2129 endpos
2135 (forward-line 1)) 2130 (thisbuf (current-buffer)))
2136 ;; Skip the prefix, if any. 2131 (save-excursion
2137 (if prefix 2132 (if (not (re-search-forward
2138 (if (looking-at prefix) 2133 (concat (or prefix "")
2139 (forward-char prefixlen) 2134 "[ \t]*End:[ \t]*"
2140 (error "Local variables entry is missing the prefix"))) 2135 (or suffix ""))
2141 ;; Find the variable name; strip whitespace. 2136 nil t))
2142 (skip-chars-forward " \t") 2137 (error "Local variables list is not properly terminated"))
2143 (setq beg (point)) 2138 (beginning-of-line)
2144 (skip-chars-forward "^:\n") 2139 (setq endpos (point)))
2145 (if (eolp) (error "Missing colon in local variables entry")) 2140
2146 (skip-chars-backward " \t") 2141 (with-temp-buffer
2147 (let* ((str (buffer-substring beg (point))) 2142 (insert-buffer-substring thisbuf startpos endpos)
2148 (var (read str)) 2143 (goto-char (point-min))
2149 val) 2144 (subst-char-in-region (point) (point-max)
2150 ;; Setting variable named "end" means end of list. 2145 ?\^m ?\n)
2151 (if (string-equal (downcase str) "end") 2146 (while (not (eobp))
2152 (setq continue nil) 2147 ;; Discard the prefix, if any.
2153 ;; Otherwise read the variable value. 2148 (if prefix
2154 (skip-chars-forward "^:") 2149 (if (looking-at prefix)
2155 (forward-char 1) 2150 (delete-region (point) (match-end 0))
2156 (setq val (read (current-buffer))) 2151 (error "Local variables entry is missing the prefix")))
2157 (skip-chars-backward "\n") 2152 (end-of-line)
2153 ;; Discard the suffix, if any.
2154 (if suffix
2155 (if (looking-back suffix)
2156 (delete-region (match-beginning 0) (point))
2157 (error "Local variables entry is missing the suffix")))
2158 (forward-line 1))
2159 (goto-char (point-min))
2160
2161 (while (not (eobp))
2162 ;; Find the variable name; strip whitespace.
2158 (skip-chars-forward " \t") 2163 (skip-chars-forward " \t")
2159 (or (if suffix (looking-at suffix) (eolp)) 2164 (setq beg (point))
2160 (error "Local variables entry is terminated incorrectly")) 2165 (skip-chars-forward "^:\n")
2161 (if mode-only 2166 (if (eolp) (error "Missing colon in local variables entry"))
2162 (if (eq var 'mode) 2167 (skip-chars-backward " \t")
2163 (setq mode-specified t)) 2168 (let* ((str (buffer-substring beg (point)))
2164 ;; Set the variable. "Variables" mode and eval are funny. 2169 (var (read str))
2165 (hack-one-local-variable var val)))))))) 2170 val)
2171 ;; Read the variable value.
2172 (skip-chars-forward "^:")
2173 (forward-char 1)
2174 (setq val (read (current-buffer)))
2175 (if mode-only
2176 (if (eq var 'mode)
2177 (setq mode-specified t))
2178 ;; Set the variable. "Variables" mode and eval are funny.
2179 (with-current-buffer thisbuf
2180 (hack-one-local-variable var val))))
2181 (forward-line 1)))))))
2166 (unless mode-only 2182 (unless mode-only
2167 (run-hooks 'hack-local-variables-hook)) 2183 (run-hooks 'hack-local-variables-hook))
2168 mode-specified)) 2184 mode-specified))
2169 2185
2170 (defvar ignored-local-variables 2186 (defvar ignored-local-variables ()
2171 '(enable-local-eval)
2172 "Variables to be ignored in a file's local variable spec.") 2187 "Variables to be ignored in a file's local variable spec.")
2173 2188
2174 ;; Get confirmation before setting these variables as locals in a file. 2189 ;; Get confirmation before setting these variables as locals in a file.
2175 (put 'debugger 'risky-local-variable t) 2190 (put 'debugger 'risky-local-variable t)
2176 (put 'enable-local-eval 'risky-local-variable t) 2191 (put 'enable-local-eval 'risky-local-variable t)
2232 (defun risky-local-variable-p (sym &optional val) 2247 (defun risky-local-variable-p (sym &optional val)
2233 "Non-nil if SYM could be dangerous as a file-local variable with value VAL. 2248 "Non-nil if SYM could be dangerous as a file-local variable with value VAL.
2234 If VAL is nil or omitted, the question is whether any value might be 2249 If VAL is nil or omitted, the question is whether any value might be
2235 dangerous." 2250 dangerous."
2236 (let ((safep (get sym 'safe-local-variable))) 2251 (let ((safep (get sym 'safe-local-variable)))
2237 (or (memq sym ignored-local-variables) 2252 (or (get sym 'risky-local-variable)
2238 (get sym 'risky-local-variable)
2239 (and (string-match "-hooks?$\\|-functions?$\\|-forms?$\\|-program$\\|-command$\\|-predicate$\\|font-lock-keywords$\\|font-lock-keywords-[0-9]+$\\|font-lock-syntactic-keywords$\\|-frame-alist$\\|-mode-alist$\\|-map$\\|-map-alist$" 2253 (and (string-match "-hooks?$\\|-functions?$\\|-forms?$\\|-program$\\|-command$\\|-predicate$\\|font-lock-keywords$\\|font-lock-keywords-[0-9]+$\\|font-lock-syntactic-keywords$\\|-frame-alist$\\|-mode-alist$\\|-map$\\|-map-alist$"
2240 (symbol-name sym)) 2254 (symbol-name sym))
2241 (not safep)) 2255 (not safep))
2242 ;; If the safe-local-variable property isn't t or nil, 2256 ;; If the safe-local-variable property isn't t or nil,
2243 ;; then it must return non-nil on the proposed value to be safe. 2257 ;; then it must return non-nil on the proposed value to be safe.
2306 (cond ((eq var 'mode) 2320 (cond ((eq var 'mode)
2307 (funcall (intern (concat (downcase (symbol-name val)) 2321 (funcall (intern (concat (downcase (symbol-name val))
2308 "-mode")))) 2322 "-mode"))))
2309 ((eq var 'coding) 2323 ((eq var 'coding)
2310 ;; We have already handled coding: tag in set-auto-coding. 2324 ;; We have already handled coding: tag in set-auto-coding.
2325 nil)
2326 ((memq var ignored-local-variables)
2311 nil) 2327 nil)
2312 ;; "Setting" eval means either eval it or do nothing. 2328 ;; "Setting" eval means either eval it or do nothing.
2313 ;; Likewise for setting hook variables. 2329 ;; Likewise for setting hook variables.
2314 ((risky-local-variable-p var val) 2330 ((risky-local-variable-p var val)
2315 ;; Permit evalling a put of a harmless property. 2331 ;; Permit evalling a put of a harmless property.