diff options
| author | Richard M. Stallman | 2002-07-02 18:58:29 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-07-02 18:58:29 +0000 |
| commit | ff7affeb8bed6ef830c18ad4c5637f5dccabc9c1 (patch) | |
| tree | 8854086eedc087252f4704f9b88bf5ff4d3b0378 | |
| parent | 89fd3098d88e6e2f41bd56a0629f609f02b6c42f (diff) | |
| download | emacs-ff7affeb8bed6ef830c18ad4c5637f5dccabc9c1.tar.gz emacs-ff7affeb8bed6ef830c18ad4c5637f5dccabc9c1.zip | |
(hack-one-local-variable-constantp): New function.
(hack-one-local-variable-eval-safep): New function.
Check for `eval:' calling fn with `safe-local-eval-function' property.
(hack-one-local-variable): Use hack-one-local-variable-eval-safep.
(c-add-style, c-set-style): Add safe-local-eval-function property.
(insert-directory): Handle --dired option to ls.
(file-remote-p): New function.
| -rw-r--r-- | lisp/files.el | 67 |
1 files changed, 53 insertions, 14 deletions
diff --git a/lisp/files.el b/lisp/files.el index 0488c7a9847..3602452e485 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -613,6 +613,12 @@ This is an interface to the function `load'." | |||
| 613 | (cons load-path load-suffixes)))) | 613 | (cons load-path load-suffixes)))) |
| 614 | (load library)) | 614 | (load library)) |
| 615 | 615 | ||
| 616 | (defun file-remote-p (file) | ||
| 617 | "Test whether FILE specifies a location on a remote system." | ||
| 618 | (let ((handler (find-file-name-handler file 'file-local-copy))) | ||
| 619 | (if handler | ||
| 620 | (get handler 'file-remote-p)))) | ||
| 621 | |||
| 616 | (defun file-local-copy (file) | 622 | (defun file-local-copy (file) |
| 617 | "Copy the file FILE into a temporary file on this machine. | 623 | "Copy the file FILE into a temporary file on this machine. |
| 618 | Returns the name of the local copy, or nil, if FILE is directly | 624 | Returns the name of the local copy, or nil, if FILE is directly |
| @@ -2034,9 +2040,38 @@ is specified, returning t if it is specified." | |||
| 2034 | ;; This one is safe because the user gets to check it before it is used. | 2040 | ;; This one is safe because the user gets to check it before it is used. |
| 2035 | (put 'compile-command 'safe-local-variable t) | 2041 | (put 'compile-command 'safe-local-variable t) |
| 2036 | 2042 | ||
| 2043 | (put 'c-add-style 'safe-local-eval-function t) | ||
| 2044 | (put 'c-set-style 'safe-local-eval-function t) | ||
| 2045 | |||
| 2037 | (defun hack-one-local-variable-quotep (exp) | 2046 | (defun hack-one-local-variable-quotep (exp) |
| 2038 | (and (consp exp) (eq (car exp) 'quote) (consp (cdr exp)))) | 2047 | (and (consp exp) (eq (car exp) 'quote) (consp (cdr exp)))) |
| 2039 | 2048 | ||
| 2049 | (defun hack-one-local-variable-constantp (exp) | ||
| 2050 | (or (and (not (symbolp exp)) (not (consp exp))) | ||
| 2051 | (memq exp '(t nil)) | ||
| 2052 | (keywordp exp) | ||
| 2053 | (hack-one-local-variable-quotep exp))) | ||
| 2054 | |||
| 2055 | (defun hack-one-local-variable-eval-safep (exp) | ||
| 2056 | "Return t if it is safe to eval EXP when it is found in a file." | ||
| 2057 | (and (consp exp) | ||
| 2058 | (or (and (eq (car exp) 'put) | ||
| 2059 | (hack-one-local-variable-quotep (nth 1 exp)) | ||
| 2060 | (hack-one-local-variable-quotep (nth 2 exp)) | ||
| 2061 | (memq (nth 1 (nth 2 exp)) | ||
| 2062 | '(lisp-indent-hook)) | ||
| 2063 | ;; Only allow safe values of lisp-indent-hook; | ||
| 2064 | ;; not functions. | ||
| 2065 | (or (numberp (nth 3 exp)) | ||
| 2066 | (equal (nth 3 exp) ''defun))) | ||
| 2067 | (and (symbolp (car exp)) | ||
| 2068 | (get (car exp) 'safe-local-eval-function) | ||
| 2069 | (let ((ok t)) | ||
| 2070 | (dolist (arg (cdr exp)) | ||
| 2071 | (unless (hack-one-local-variable-constantp arg) | ||
| 2072 | (setq ok nil))) | ||
| 2073 | ok))))) | ||
| 2074 | |||
| 2040 | (defun hack-one-local-variable (var val) | 2075 | (defun hack-one-local-variable (var val) |
| 2041 | "\"Set\" one variable in a local variables spec. | 2076 | "\"Set\" one variable in a local variables spec. |
| 2042 | A few patterns are specified so that any name which matches one | 2077 | A few patterns are specified so that any name which matches one |
| @@ -2059,16 +2094,7 @@ is considered risky." | |||
| 2059 | ;; Permit evalling a put of a harmless property. | 2094 | ;; Permit evalling a put of a harmless property. |
| 2060 | ;; if the args do nothing tricky. | 2095 | ;; if the args do nothing tricky. |
| 2061 | (if (or (and (eq var 'eval) | 2096 | (if (or (and (eq var 'eval) |
| 2062 | (consp val) | 2097 | (hack-one-local-variable-eval-safep val)) |
| 2063 | (eq (car val) 'put) | ||
| 2064 | (hack-one-local-variable-quotep (nth 1 val)) | ||
| 2065 | (hack-one-local-variable-quotep (nth 2 val)) | ||
| 2066 | ;; Only allow safe values of lisp-indent-hook; | ||
| 2067 | ;; not functions. | ||
| 2068 | (or (numberp (nth 3 val)) | ||
| 2069 | (equal (nth 3 val) ''defun)) | ||
| 2070 | (memq (nth 1 (nth 2 val)) | ||
| 2071 | '(lisp-indent-hook))) | ||
| 2072 | ;; Permit eval if not root and user says ok. | 2098 | ;; Permit eval if not root and user says ok. |
| 2073 | (and (not (zerop (user-uid))) | 2099 | (and (not (zerop (user-uid))) |
| 2074 | (or (eq enable-local-eval t) | 2100 | (or (eq enable-local-eval t) |
| @@ -3849,7 +3875,7 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'." | |||
| 3849 | wildcard full-directory-p) | 3875 | wildcard full-directory-p) |
| 3850 | (if (eq system-type 'vax-vms) | 3876 | (if (eq system-type 'vax-vms) |
| 3851 | (vms-read-directory file switches (current-buffer)) | 3877 | (vms-read-directory file switches (current-buffer)) |
| 3852 | (let (result available) | 3878 | (let (result available (beg (point))) |
| 3853 | 3879 | ||
| 3854 | ;; Read the actual directory using `insert-directory-program'. | 3880 | ;; Read the actual directory using `insert-directory-program'. |
| 3855 | ;; RESULT gets the status code. | 3881 | ;; RESULT gets the status code. |
| @@ -3926,15 +3952,28 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'." | |||
| 3926 | (access-file file "Reading directory") | 3952 | (access-file file "Reading directory") |
| 3927 | (error "Listing directory failed but `access-file' worked"))) | 3953 | (error "Listing directory failed but `access-file' worked"))) |
| 3928 | 3954 | ||
| 3955 | (when (string-match "--dired\\>" switches) | ||
| 3956 | (forward-line -2) | ||
| 3957 | (let ((end (line-end-position))) | ||
| 3958 | (forward-word 1) | ||
| 3959 | (forward-char 3) | ||
| 3960 | (while (< (point) end) | ||
| 3961 | (let ((start (+ beg (read (current-buffer)))) | ||
| 3962 | (end (+ beg (read (current-buffer))))) | ||
| 3963 | (put-text-property start end 'dired-filename t))) | ||
| 3964 | (goto-char end) | ||
| 3965 | (beginning-of-line) | ||
| 3966 | (delete-region (point) (progn (forward-line 2) (point))))) | ||
| 3967 | |||
| 3929 | ;; Try to insert the amount of free space. | 3968 | ;; Try to insert the amount of free space. |
| 3930 | (save-excursion | 3969 | (save-excursion |
| 3931 | (goto-char (point-min)) | 3970 | (goto-char beg) |
| 3932 | ;; First find the line to put it on. | 3971 | ;; First find the line to put it on. |
| 3933 | (when (re-search-forward "^total" nil t) | 3972 | (when (re-search-forward "^ *\\(total\\)" nil t) |
| 3934 | (let ((available (get-free-disk-space "."))) | 3973 | (let ((available (get-free-disk-space "."))) |
| 3935 | (when available | 3974 | (when available |
| 3936 | ;; Replace "total" with "used", to avoid confusion. | 3975 | ;; Replace "total" with "used", to avoid confusion. |
| 3937 | (replace-match "total used in directory") | 3976 | (replace-match "total used in directory" nil nil nil 1) |
| 3938 | (end-of-line) | 3977 | (end-of-line) |
| 3939 | (insert " available " available)))))))))) | 3978 | (insert " available " available)))))))))) |
| 3940 | 3979 | ||