diff options
| author | Michael Albinus | 2016-12-08 18:00:10 +0100 |
|---|---|---|
| committer | Michael Albinus | 2016-12-08 18:00:10 +0100 |
| commit | b67fdee18b07d55c44f3513d3d8a15d3b34ab4b6 (patch) | |
| tree | afed065d28e3d5f712511690d973151a3184c6f3 | |
| parent | e63c489dd496e53b68b942d0b76e13b62117fae9 (diff) | |
| download | emacs-b67fdee18b07d55c44f3513d3d8a15d3b34ab4b6.tar.gz emacs-b67fdee18b07d55c44f3513d3d8a15d3b34ab4b6.zip | |
Add file-name-quoted-p, file-name-quote, file-name-unquote
* lisp/files.el (file-name-quoted-p, file-name-quote)
(file-name-unquote): New defsubst.
(find-file--read-only, find-file-noselect)
(file-name-non-special): Use them.
| -rw-r--r-- | lisp/files.el | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/lisp/files.el b/lisp/files.el index 54e8495abc7..ba6004686e7 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -1605,7 +1605,7 @@ file names with wildcards." | |||
| 1605 | 1605 | ||
| 1606 | (defun find-file--read-only (fun filename wildcards) | 1606 | (defun find-file--read-only (fun filename wildcards) |
| 1607 | (unless (or (and wildcards find-file-wildcards | 1607 | (unless (or (and wildcards find-file-wildcards |
| 1608 | (not (string-match "\\`/:" filename)) | 1608 | (not (file-name-quoted-p filename)) |
| 1609 | (string-match "[[*?]" filename)) | 1609 | (string-match "[[*?]" filename)) |
| 1610 | (file-exists-p filename)) | 1610 | (file-exists-p filename)) |
| 1611 | (error "%s does not exist" filename)) | 1611 | (error "%s does not exist" filename)) |
| @@ -1985,7 +1985,7 @@ the various files." | |||
| 1985 | (error "%s is a directory" filename)) | 1985 | (error "%s is a directory" filename)) |
| 1986 | (if (and wildcards | 1986 | (if (and wildcards |
| 1987 | find-file-wildcards | 1987 | find-file-wildcards |
| 1988 | (not (string-match "\\`/:" filename)) | 1988 | (not (file-name-quoted-p filename)) |
| 1989 | (string-match "[[*?]" filename)) | 1989 | (string-match "[[*?]" filename)) |
| 1990 | (let ((files (condition-case nil | 1990 | (let ((files (condition-case nil |
| 1991 | (file-expand-wildcards filename t) | 1991 | (file-expand-wildcards filename t) |
| @@ -6923,27 +6923,44 @@ only these files will be asked to be saved." | |||
| 6923 | (save-match-data | 6923 | (save-match-data |
| 6924 | (while (consp file-arg-indices) | 6924 | (while (consp file-arg-indices) |
| 6925 | (let ((pair (nthcdr (car file-arg-indices) arguments))) | 6925 | (let ((pair (nthcdr (car file-arg-indices) arguments))) |
| 6926 | (and (car pair) | 6926 | (and (car pair) (setcar pair (file-name-unquote 2)))) |
| 6927 | (string-match "\\`/:" (car pair)) | ||
| 6928 | (setcar pair | ||
| 6929 | (if (= (length (car pair)) 2) | ||
| 6930 | "/" | ||
| 6931 | (substring (car pair) 2))))) | ||
| 6932 | (setq file-arg-indices (cdr file-arg-indices)))) | 6927 | (setq file-arg-indices (cdr file-arg-indices)))) |
| 6933 | (pcase method | 6928 | (pcase method |
| 6934 | (`identity (car arguments)) | 6929 | (`identity (car arguments)) |
| 6935 | (`add (concat "/:" (apply operation arguments))) | 6930 | (`add (file-name-quote (apply operation arguments))) |
| 6936 | (`insert-file-contents | 6931 | (`insert-file-contents |
| 6937 | (let ((visit (nth 1 arguments))) | 6932 | (let ((visit (nth 1 arguments))) |
| 6938 | (unwind-protect | 6933 | (unwind-protect |
| 6939 | (apply operation arguments) | 6934 | (apply operation arguments) |
| 6940 | (when (and visit buffer-file-name) | 6935 | (when (and visit buffer-file-name) |
| 6941 | (setq buffer-file-name (concat "/:" buffer-file-name)))))) | 6936 | (setq buffer-file-name (file-name-quote buffer-file-name)))))) |
| 6942 | (`unquote-then-quote | 6937 | (`unquote-then-quote |
| 6943 | (let ((buffer-file-name (substring buffer-file-name 2))) | 6938 | (let ((buffer-file-name (substring buffer-file-name 2))) |
| 6944 | (apply operation arguments))) | 6939 | (apply operation arguments))) |
| 6945 | (_ | 6940 | (_ |
| 6946 | (apply operation arguments))))) | 6941 | (apply operation arguments))))) |
| 6942 | |||
| 6943 | (defsubst file-name-quoted-p (name) | ||
| 6944 | "Whether NAME is quoted with prefix \"/:\". | ||
| 6945 | If NAME is a remote file name, check the local part of NAME." | ||
| 6946 | (string-prefix-p "/:" (file-local-name name))) | ||
| 6947 | |||
| 6948 | (defsubst file-name-quote (name) | ||
| 6949 | "Add the quotation prefix \"/:\" to file NAME. | ||
| 6950 | If NAME is a remote file name, the local part of NAME is quoted. | ||
| 6951 | If NAME is already a quoted file name, NAME is returned unchanged." | ||
| 6952 | (if (file-name-quoted-p name) | ||
| 6953 | name | ||
| 6954 | (concat (file-remote-p name) "/:" (file-local-name name)))) | ||
| 6955 | |||
| 6956 | (defsubst file-name-unquote (name) | ||
| 6957 | "Remove quotation prefix \"/:\" from file NAME, if any. | ||
| 6958 | If NAME is a remote file name, the local part of NAME is unquoted." | ||
| 6959 | (let ((localname (file-local-name name))) | ||
| 6960 | (when (file-name-quoted-p localname) | ||
| 6961 | (setq | ||
| 6962 | localname (if (= (length localname) 2) "/" (substring localname 2)))) | ||
| 6963 | (concat (file-remote-p name) localname))) | ||
| 6947 | 6964 | ||
| 6948 | ;; Symbolic modes and read-file-modes. | 6965 | ;; Symbolic modes and read-file-modes. |
| 6949 | 6966 | ||