comparison lisp/files.el @ 47985:9f3ecf5e3d65

(risky-local-variable-p): New function. (compile-command): Use `stringp' for `safe-local-variable' prop. (hack-one-local-variable): Use `risky-local-variable-p'.
author Richard M. Stallman <rms@gnu.org>
date Wed, 23 Oct 2002 17:38:44 +0000
parents 2bf98e61feaf
children c04620adce24
comparison
equal deleted inserted replaced
47984:ee12f8f7eb12 47985:9f3ecf5e3d65
2055 (put 'mode-line-buffer-identification 'risky-local-variable t) 2055 (put 'mode-line-buffer-identification 'risky-local-variable t)
2056 (put 'mode-line-modes 'risky-local-variable t) 2056 (put 'mode-line-modes 'risky-local-variable t)
2057 (put 'mode-line-position 'risky-local-variable t) 2057 (put 'mode-line-position 'risky-local-variable t)
2058 (put 'display-time-string 'risky-local-variable t) 2058 (put 'display-time-string 'risky-local-variable t)
2059 2059
2060 ;; This one is safe because the user gets to check it before it is used. 2060 ;; This case is safe because the user gets to check it before it is used.
2061 (put 'compile-command 'safe-local-variable t) 2061 (put 'compile-command 'safe-local-variable 'stringp)
2062 2062
2063 (defun risky-local-variable-p (sym) 2063 (defun risky-local-variable-p (sym val)
2064 "Returns non-nil if SYM could be dangerous as a file-local variable." 2064 "Non-nil if SYM could be dangerous as a file-local variable with value VAL."
2065 (or (memq sym ignored-local-variables) 2065 (let ((safep (get sym 'safe-local-variable)))
2066 (get sym 'risky-local-variable) 2066 (or (memq sym ignored-local-variables)
2067 (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$" 2067 (get sym 'risky-local-variable)
2068 (symbol-name sym)) 2068 (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$"
2069 (not (get sym 'safe-local-variable))))) 2069 (symbol-name sym))
2070 (not safep))
2071 ;; If the safe-local-variable property isn't t or nil,
2072 ;; then it must return non-nil on the proposed value to be safe.
2073 (and (not (memq safep '(t nil)))
2074 (not (funcall safep val))))))
2070 2075
2071 (defcustom safe-local-eval-forms nil 2076 (defcustom safe-local-eval-forms nil
2072 "*Expressions that are considered \"safe\" in an `eval:' local variable. 2077 "*Expressions that are considered \"safe\" in an `eval:' local variable.
2073 Add expressions to this list if you want Emacs to evaluate them, when 2078 Add expressions to this list if you want Emacs to evaluate them, when
2074 they appear in an `eval' local variable specification, without first 2079 they appear in an `eval' local variable specification, without first
2132 ((eq var 'coding) 2137 ((eq var 'coding)
2133 ;; We have already handled coding: tag in set-auto-coding. 2138 ;; We have already handled coding: tag in set-auto-coding.
2134 nil) 2139 nil)
2135 ;; "Setting" eval means either eval it or do nothing. 2140 ;; "Setting" eval means either eval it or do nothing.
2136 ;; Likewise for setting hook variables. 2141 ;; Likewise for setting hook variables.
2137 ((risky-local-variable-p var) 2142 ((risky-local-variable-p var val)
2138 ;; Permit evalling a put of a harmless property. 2143 ;; Permit evalling a put of a harmless property.
2139 ;; if the args do nothing tricky. 2144 ;; if the args do nothing tricky.
2140 (if (or (and (eq var 'eval) 2145 (if (or (and (eq var 'eval)
2141 (hack-one-local-variable-eval-safep val)) 2146 (hack-one-local-variable-eval-safep val))
2142 ;; Permit eval if not root and user says ok. 2147 ;; Permit eval if not root and user says ok.
2155 (concat "buffer " (buffer-name))))))))))) 2160 (concat "buffer " (buffer-name)))))))))))
2156 (if (eq var 'eval) 2161 (if (eq var 'eval)
2157 (save-excursion (eval val)) 2162 (save-excursion (eval val))
2158 (make-local-variable var) 2163 (make-local-variable var)
2159 (set var val)) 2164 (set var val))
2160 (message "Ignoring `eval:' in the local variables list"))) 2165 (message "Ignoring risky spec in the local variables list")))
2161 ;; Ordinary variable, really set it. 2166 ;; Ordinary variable, really set it.
2162 (t (make-local-variable var) 2167 (t (make-local-variable var)
2163 ;; Make sure the string has no text properties. 2168 ;; Make sure the string has no text properties.
2164 ;; Some text properties can get evaluated in various ways, 2169 ;; Some text properties can get evaluated in various ways,
2165 ;; so it is risky to put them on with a local variable list. 2170 ;; so it is risky to put them on with a local variable list.