aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-12-09 10:03:05 +0100
committerMichael Albinus2016-12-09 10:03:05 +0100
commit57a77f833e37abe2f7936585e9915b6947e3564a (patch)
tree0dd014b26b8ca07167ace7cb051c37f07434ae44
parent8f611e5e2309ae3f7f1753f0d2f7a60ca6fc2657 (diff)
downloademacs-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.texi41
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/files.el13
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,
2406the file name can be quoted to suppress the expansion, and to handle
2407the file name literally. Quoting happens by prefixing the file name
2408with @samp{/:}.
2409
2410@defmac file-name-quote name
2411This macro adds the quotation prefix @samp{/:} to the file @var{name}.
2412For a local file @var{name}, it prefixes @var{name} with @samp{/:}.
2413If @var{name} is a remote file name, the local part of @var{name} is
2414quoted. If @var{name} is already a quoted file name, @var{name} is
2415returned 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
2429The macro cannot be used to suppress file name handlers from magic
2430file names (@pxref{Magic File Names}).
2431@end defmac
2432
2433@defmac file-name-unquote name
2434This macro removes the quotation prefix @samp{/:} from the file
2435@var{name}, if any. If @var{name} is a remote file name, the local
2436part of @var{name} is unquoted.
2437@end defmac
2438
2439@defmac file-name-quoted-p name
2440This macro returns non-@code{nil}, when @var{name} is quoted with the
2441prefix @samp{/:}. If @var{name} is a remote file name, the local part
2442of @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
diff --git a/etc/NEWS b/etc/NEWS
index a62668a2625..614b6144308 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -749,6 +749,11 @@ can be used for creation of temporary files of remote or mounted directories.
749of remote processes. 749of 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
754the 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
753signaled instead of 'file-error' if a file operation acts on a file 758signaled instead of 'file-error' if a file operation acts on a file
754that does not exist. 759that 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)))))