diff options
| author | Richard M. Stallman | 2002-07-07 09:21:52 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-07-07 09:21:52 +0000 |
| commit | 8fd9c1745e9d76b93593464d7290d7beb9be192d (patch) | |
| tree | 26de35c19bafd592418552e708f57e283dc72293 | |
| parent | 9ae4c9259cf20ec600cdc3292a2957a11ed118e0 (diff) | |
| download | emacs-8fd9c1745e9d76b93593464d7290d7beb9be192d.tar.gz emacs-8fd9c1745e9d76b93593464d7290d7beb9be192d.zip | |
(safe-local-eval-forms): New user option.
(hack-one-local-variable-eval-safep): Support it.
Also allow `safe-local-eval-function' property to be a function
or a list of functions.
(c-add-style): Delete `safe-local-eval-function' property.
(after-find-file): Make buffer read-only if file is
marked that way, even for root.
(save-some-buffers): Doc fix.
| -rw-r--r-- | lisp/files.el | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/lisp/files.el b/lisp/files.el index df2e640aed4..a93759298c3 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1422,6 +1422,10 @@ unless NOMODES is non-nil." | |||
| 1422 | ;; before altering a backup file. | 1422 | ;; before altering a backup file. |
| 1423 | (when (backup-file-name-p buffer-file-name) | 1423 | (when (backup-file-name-p buffer-file-name) |
| 1424 | (setq buffer-read-only t)) | 1424 | (setq buffer-read-only t)) |
| 1425 | ;; When a file is marked read-only, | ||
| 1426 | ;; make the buffer read-only even if root is looking at it. | ||
| 1427 | (when (zerop (logand (file-modes (buffer-file-name)) #o222)) | ||
| 1428 | (setq buffer-read-only t)) | ||
| 1425 | (unless nomodes | 1429 | (unless nomodes |
| 1426 | (when (and view-read-only view-mode) | 1430 | (when (and view-read-only view-mode) |
| 1427 | (view-mode-disable)) | 1431 | (view-mode-disable)) |
| @@ -2041,7 +2045,15 @@ is specified, returning t if it is specified." | |||
| 2041 | ;; This one is safe because the user gets to check it before it is used. | 2045 | ;; This one is safe because the user gets to check it before it is used. |
| 2042 | (put 'compile-command 'safe-local-variable t) | 2046 | (put 'compile-command 'safe-local-variable t) |
| 2043 | 2047 | ||
| 2044 | (put 'c-add-style 'safe-local-eval-function t) | 2048 | (defcustom safe-local-eval-forms nil |
| 2049 | "*Expressions that are considered \"safe\" in an `eval:' local variable. | ||
| 2050 | Add expressions to this list if you want Emacs to evaluate them, when | ||
| 2051 | they appear in an `eval' local variable specification, without first | ||
| 2052 | asking you for confirmation." | ||
| 2053 | :group 'find-file | ||
| 2054 | :version "21.4" | ||
| 2055 | :type '(repeat sexp)) | ||
| 2056 | |||
| 2045 | (put 'c-set-style 'safe-local-eval-function t) | 2057 | (put 'c-set-style 'safe-local-eval-function t) |
| 2046 | 2058 | ||
| 2047 | (defun hack-one-local-variable-quotep (exp) | 2059 | (defun hack-one-local-variable-quotep (exp) |
| @@ -2055,23 +2067,37 @@ is specified, returning t if it is specified." | |||
| 2055 | 2067 | ||
| 2056 | (defun hack-one-local-variable-eval-safep (exp) | 2068 | (defun hack-one-local-variable-eval-safep (exp) |
| 2057 | "Return t if it is safe to eval EXP when it is found in a file." | 2069 | "Return t if it is safe to eval EXP when it is found in a file." |
| 2058 | (and (consp exp) | 2070 | (or (not (consp exp)) |
| 2059 | (or (and (eq (car exp) 'put) | 2071 | ;; Detect certain `put' expressions. |
| 2060 | (hack-one-local-variable-quotep (nth 1 exp)) | 2072 | (and (eq (car exp) 'put) |
| 2061 | (hack-one-local-variable-quotep (nth 2 exp)) | 2073 | (hack-one-local-variable-quotep (nth 1 exp)) |
| 2062 | (memq (nth 1 (nth 2 exp)) | 2074 | (hack-one-local-variable-quotep (nth 2 exp)) |
| 2063 | '(lisp-indent-hook)) | 2075 | (memq (nth 1 (nth 2 exp)) |
| 2064 | ;; Only allow safe values of lisp-indent-hook; | 2076 | '(lisp-indent-hook)) |
| 2065 | ;; not functions. | 2077 | ;; Only allow safe values of lisp-indent-hook; |
| 2066 | (or (numberp (nth 3 exp)) | 2078 | ;; not functions. |
| 2067 | (equal (nth 3 exp) ''defun))) | 2079 | (or (numberp (nth 3 exp)) |
| 2068 | (and (symbolp (car exp)) | 2080 | (equal (nth 3 exp) ''defun))) |
| 2069 | (get (car exp) 'safe-local-eval-function) | 2081 | ;; Allow expressions that the user requested. |
| 2070 | (let ((ok t)) | 2082 | (member exp safe-local-eval-forms) |
| 2071 | (dolist (arg (cdr exp)) | 2083 | ;; Certain functions can be allowed with safe arguments |
| 2072 | (unless (hack-one-local-variable-constantp arg) | 2084 | ;; or can specify verification functions to try. |
| 2073 | (setq ok nil))) | 2085 | (and (symbolp (car exp)) |
| 2074 | ok))))) | 2086 | (let ((prop (get (car exp) 'safe-local-eval-function))) |
| 2087 | (cond ((eq prop t) | ||
| 2088 | (let ((ok t)) | ||
| 2089 | (dolist (arg (cdr exp)) | ||
| 2090 | (unless (hack-one-local-variable-constantp arg) | ||
| 2091 | (setq ok nil))) | ||
| 2092 | ok)) | ||
| 2093 | ((functionp prop) | ||
| 2094 | (funcall prop exp)) | ||
| 2095 | ((listp prop) | ||
| 2096 | (let ((ok nil)) | ||
| 2097 | (dolist (function prop) | ||
| 2098 | (if (funcall function exp) | ||
| 2099 | (setq ok t))) | ||
| 2100 | ok))))))) | ||
| 2075 | 2101 | ||
| 2076 | (defun hack-one-local-variable (var val) | 2102 | (defun hack-one-local-variable (var val) |
| 2077 | "\"Set\" one variable in a local variables spec. | 2103 | "\"Set\" one variable in a local variables spec. |
| @@ -2942,6 +2968,9 @@ After saving the buffer, this function runs `after-save-hook'." | |||
| 2942 | 2968 | ||
| 2943 | (defun save-some-buffers (&optional arg pred) | 2969 | (defun save-some-buffers (&optional arg pred) |
| 2944 | "Save some modified file-visiting buffers. Asks user about each one. | 2970 | "Save some modified file-visiting buffers. Asks user about each one. |
| 2971 | You can answer `y' to save, `n' not to save, or `C-r' to look at the | ||
| 2972 | buffer in question with `view-buffer' before deciding. | ||
| 2973 | |||
| 2945 | Optional argument (the prefix) non-nil means save all with no questions. | 2974 | Optional argument (the prefix) non-nil means save all with no questions. |
| 2946 | Optional second argument PRED determines which buffers are considered: | 2975 | Optional second argument PRED determines which buffers are considered: |
| 2947 | If PRED is nil, all the file-visiting buffers are considered. | 2976 | If PRED is nil, all the file-visiting buffers are considered. |