diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-23 15:20:25 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-01-23 15:28:59 +0100 |
| commit | e4e564bdf1e8664665e626e4c65146f7207c5a56 (patch) | |
| tree | 0e5045fc1ba01ecb1abe8cd4b23b6a8a9d33c10f | |
| parent | ac471b9ccf821a421f61945c262c53a7a02006cd (diff) | |
compat-27: Add file-name-unquote
| -rw-r--r-- | NEWS.org | 1 | ||||
| -rw-r--r-- | compat-27.el | 16 | ||||
| -rw-r--r-- | compat-tests.el | 7 | ||||
| -rw-r--r-- | compat.texi | 9 |
4 files changed, 28 insertions, 5 deletions
@@ -2,6 +2,7 @@ * Development +- compat-27: Add ~file-name-unquote~. - compat-29: Replace ~string-lines~ with version from Emacs 29, support optional KEEP-NEWLINES argument. diff --git a/compat-27.el b/compat-27.el index 102abf1..793c98e 100644 --- a/compat-27.el +++ b/compat-27.el @@ -427,10 +427,20 @@ the minibuffer was activated, and execute the forms." (compat-defun file-name-quote (name &optional top) ;; <compat-tests:file-name-quote> "Handle optional argument TOP." :extended "26.1" - (let ((file-name-handler-alist (unless top file-name-handler-alist))) - (if (string-prefix-p "/:" (file-local-name name)) + (let* ((file-name-handler-alist (unless top file-name-handler-alist)) + (localname (file-local-name name))) + (if (string-prefix-p "/:" localname) name - (concat (file-remote-p name) "/:" (file-local-name name))))) + (concat (file-remote-p name) "/:" localname)))) + +(compat-defun file-name-unquote (name &optional top) ;; <compat-tests:file-name-unquote> + "Handle optional argument TOP." + :extended "26.1" + (let* ((file-name-handler-alist (unless top file-name-handler-alist)) + (localname (file-local-name name))) + (when (string-prefix-p "/:" localname) + (setq localname (if (= (length localname) 2) "/" (substring localname 2)))) + (concat (file-remote-p name) localname))) (compat-defun file-size-human-readable (file-size &optional flavor space unit) ;; <compat-tests:file-size-human-readable> "Handle the optional arguments SPACE and UNIT." diff --git a/compat-tests.el b/compat-tests.el index c26c294..9724314 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -1592,6 +1592,13 @@ (when (>= emacs-major-version 26) (should-not (file-name-quoted-p "/ssh:/:a")))) +(ert-deftest file-name-unquote () + (should-equal "/" (compat-call file-name-unquote "/:" t)) ;; top argument + (should-equal ":"(compat-call file-name-unquote "/::" t)) ;; top argument + (should-equal "/" (file-name-unquote "/:/")) + (should-equal "/" (file-name-unquote "/:")) + (should-equal ":" (file-name-unquote "/::"))) + (ert-deftest file-name-quote () (should-equal "/:" (compat-call file-name-quote "" t)) ;; top argument (should-equal "/::"(compat-call file-name-quote ":" t)) ;; top argument diff --git a/compat.texi b/compat.texi index b4880ae..d4535bc 100644 --- a/compat.texi +++ b/compat.texi @@ -658,6 +658,13 @@ It should be somewhat more efficient on larger buffers than @end defun @c copied from lispref/files.texi +@defmac file-name-unquote name +This macro removes the quotation prefix @samp{/:} from the file +@var{name}, if any. If @var{name} is a remote file name, the local +part of @var{name} is unquoted. +@end defmac + +@c copied from lispref/files.texi @defun file-name-quoted-p name This macro returns non-@code{nil}, when @var{name} is quoted with the prefix @samp{/:}. If @var{name} is a remote file name, the local part @@ -968,8 +975,6 @@ implemented in 26.1: @itemize @item -The function @code{file-name-unquote}. -@item The function @code{func-arity}. @item The function @code{secure-hash-algorithms}. |
