diff options
| author | Michael Albinus | 2016-12-09 10:03:05 +0100 |
|---|---|---|
| committer | Michael Albinus | 2016-12-09 10:03:05 +0100 |
| commit | 57a77f833e37abe2f7936585e9915b6947e3564a (patch) | |
| tree | 0dd014b26b8ca07167ace7cb051c37f07434ae44 | |
| parent | 8f611e5e2309ae3f7f1753f0d2f7a60ca6fc2657 (diff) | |
| download | emacs-57a77f833e37abe2f7936585e9915b6947e3564a.tar.gz emacs-57a77f833e37abe2f7936585e9915b6947e3564a.zip | |
Document file-name-quote, file-name-unquote and file-name-quoted-p
* doc/lispref/files.texi (File Name Expansion):
* etc/NEWS: Mention file-name-quote, file-name-unquote and
file-name-quoted-p.
* lisp/files.el (file-name-non-special): Revert using
file-name-quote, file-name-unquote and file-name-quoted-p.
| -rw-r--r-- | doc/lispref/files.texi | 41 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/files.el | 13 |
3 files changed, 55 insertions, 4 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 26db93cd8fd..906cd562612 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi | |||
| @@ -2402,6 +2402,47 @@ through the immediately preceding @samp{/}). | |||
| 2402 | 2402 | ||
| 2403 | @end defun | 2403 | @end defun |
| 2404 | 2404 | ||
| 2405 | Sometimes, it is not desired to expand file names. In such cases, | ||
| 2406 | the file name can be quoted to suppress the expansion, and to handle | ||
| 2407 | the file name literally. Quoting happens by prefixing the file name | ||
| 2408 | with @samp{/:}. | ||
| 2409 | |||
| 2410 | @defmac file-name-quote name | ||
| 2411 | This macro adds the quotation prefix @samp{/:} to the file @var{name}. | ||
| 2412 | For a local file @var{name}, it prefixes @var{name} with @samp{/:}. | ||
| 2413 | If @var{name} is a remote file name, the local part of @var{name} is | ||
| 2414 | quoted. If @var{name} is already a quoted file name, @var{name} is | ||
| 2415 | returned unchanged. | ||
| 2416 | |||
| 2417 | @example | ||
| 2418 | @group | ||
| 2419 | (substitute-in-file-name (file-name-quote "bar/~/foo")) | ||
| 2420 | @result{} "/:bar/~/foo" | ||
| 2421 | @end group | ||
| 2422 | |||
| 2423 | @group | ||
| 2424 | (substitute-in-file-name (file-name-quote "/ssh:host:bar/~/foo")) | ||
| 2425 | @result{} "/ssh:host:/:bar/~/foo" | ||
| 2426 | @end group | ||
| 2427 | @end example | ||
| 2428 | |||
| 2429 | The macro cannot be used to suppress file name handlers from magic | ||
| 2430 | file names (@pxref{Magic File Names}). | ||
| 2431 | @end defmac | ||
| 2432 | |||
| 2433 | @defmac file-name-unquote name | ||
| 2434 | This macro removes the quotation prefix @samp{/:} from the file | ||
| 2435 | @var{name}, if any. If @var{name} is a remote file name, the local | ||
| 2436 | part of @var{name} is unquoted. | ||
| 2437 | @end defmac | ||
| 2438 | |||
| 2439 | @defmac file-name-quoted-p name | ||
| 2440 | This macro returns non-@code{nil}, when @var{name} is quoted with the | ||
| 2441 | prefix @samp{/:}. If @var{name} is a remote file name, the local part | ||
| 2442 | of @var{name} is checked. | ||
| 2443 | @end defmac | ||
| 2444 | |||
| 2445 | |||
| 2405 | @node Unique File Names | 2446 | @node Unique File Names |
| 2406 | @subsection Generating Unique File Names | 2447 | @subsection Generating Unique File Names |
| 2407 | @cindex unique file names | 2448 | @cindex unique file names |
| @@ -749,6 +749,11 @@ can be used for creation of temporary files of remote or mounted directories. | |||
| 749 | of remote processes. | 749 | of remote processes. |
| 750 | 750 | ||
| 751 | +++ | 751 | +++ |
| 752 | ** The new functions 'file-name-quote', 'file-name-unquote' and | ||
| 753 | 'file-name-quoted-p' can be used to quote / unquote file names with | ||
| 754 | the prefix "/:". | ||
| 755 | |||
| 756 | +++ | ||
| 752 | ** The new error 'file-missing', a subcategory of 'file-error', is now | 757 | ** The new error 'file-missing', a subcategory of 'file-error', is now |
| 753 | signaled instead of 'file-error' if a file operation acts on a file | 758 | signaled instead of 'file-error' if a file operation acts on a file |
| 754 | that does not exist. | 759 | that does not exist. |
diff --git a/lisp/files.el b/lisp/files.el index 6f6e8687f52..790f6cedfd6 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -6923,19 +6923,24 @@ 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) (setcar pair (file-name-unquote (car pair))))) | 6926 | (and (car pair) |
| 6927 | (string-match "\\`/:" (car pair)) | ||
| 6928 | (setcar pair | ||
| 6929 | (if (= (length (car pair)) 2) | ||
| 6930 | "/" | ||
| 6931 | (substring (car pair) 2))))) | ||
| 6927 | (setq file-arg-indices (cdr file-arg-indices)))) | 6932 | (setq file-arg-indices (cdr file-arg-indices)))) |
| 6928 | (pcase method | 6933 | (pcase method |
| 6929 | (`identity (car arguments)) | 6934 | (`identity (car arguments)) |
| 6930 | (`add (file-name-quote (apply operation arguments))) | 6935 | (`add (concat "/:" (apply operation arguments))) |
| 6931 | (`insert-file-contents | 6936 | (`insert-file-contents |
| 6932 | (let ((visit (nth 1 arguments))) | 6937 | (let ((visit (nth 1 arguments))) |
| 6933 | (unwind-protect | 6938 | (unwind-protect |
| 6934 | (apply operation arguments) | 6939 | (apply operation arguments) |
| 6935 | (when (and visit buffer-file-name) | 6940 | (when (and visit buffer-file-name) |
| 6936 | (setq buffer-file-name (file-name-quote buffer-file-name)))))) | 6941 | (setq buffer-file-name (concat "/:" buffer-file-name)))))) |
| 6937 | (`unquote-then-quote | 6942 | (`unquote-then-quote |
| 6938 | (let ((buffer-file-name (file-name-unquote buffer-file-name))) | 6943 | (let ((buffer-file-name (substring buffer-file-name 2))) |
| 6939 | (apply operation arguments))) | 6944 | (apply operation arguments))) |
| 6940 | (_ | 6945 | (_ |
| 6941 | (apply operation arguments))))) | 6946 | (apply operation arguments))))) |