branch: externals/compat
commit ced04469166bdc1b8c95c77cbc0bd1faac71a1a1
Author: Philip Kaludercic <[email protected]>
Commit: Philip Kaludercic <[email protected]>

    Add missing function file-local-name
---
 MANUAL          |  1 +
 compat-26.el    |  9 +++++++++
 compat-tests.el | 11 +++++++++++
 3 files changed, 21 insertions(+)

diff --git a/MANUAL b/MANUAL
index 5420efd3f0..471e882181 100644
--- a/MANUAL
+++ b/MANUAL
@@ -229,6 +229,7 @@ provided by Compat by default:
 - Variable: mounted-file-systems ::  Defined in ~files.el~.
 - Function: temporary-file-directory :: See [[info:elisp#Unique File 
Names][(elisp) Unique File Names]].
 - Macro: and-let* :: Defined in ~subr-x.el~.
+- Function: file-local-name :: See [[info:elisp#Magic File Names][(elisp) 
Magic File Names]].
 
 These functions are prefixed with ~compat~ prefix, and are only loaded
 when ~compat-26~ is required:
diff --git a/compat-26.el b/compat-26.el
index f3e65b6318..bf8e1ceef6 100644
--- a/compat-26.el
+++ b/compat-26.el
@@ -345,6 +345,15 @@ same meaning as in `make-temp-file'."
          "^" (regexp-opt '("/afs/" "/media/" "/mnt" "/net/" "/tmp_mnt/")))))
   "File systems that ought to be mounted.")
 
+(compat-defun file-local-name (file)
+  "Return the local name component of FILE.
+This function removes from FILE the specification of the remote host
+and the method of accessing the host, leaving only the part that
+identifies FILE locally on the remote system.
+The returned file name can be used directly as argument of
+`process-file', `start-file-process', or `shell-command'."
+  (or (file-remote-p file 'localname) file))
+
 ;;* UNTESTED
 (compat-defun temporary-file-directory ()
   "The directory for writing temporary files.
diff --git a/compat-tests.el b/compat-tests.el
index f89235708f..5e0ece15bc 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1567,5 +1567,16 @@ being compared against."
   (ought "prwx------" #o10700)
   (ought "-rwx------" #o30700))
 
+(compat-deftest file-local-name
+  (ought "" "")
+  (ought "foo" "foo")
+  (ought "/bar/foo" "/bar/foo")
+  (ought "/ssh:foo" "/ssh:foo")
+  (ought "/ssh:/bar/foo" "/ssh:/bar/foo")
+  (ought "foo" "/ssh::foo")
+  (ought "/bar/foo" "/ssh::/bar/foo")
+  (ought ":foo" "/ssh:::foo")
+  (ought ":/bar/foo" "/ssh:::/bar/foo"))
+
 (provide 'compat-tests)
 ;;; compat-tests.el ends here

Reply via email to