emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-27 0636431 3/3: * lisp/net/tramp.el (tramp-file-local-name): New d


From: Michael Albinus
Subject: emacs-27 0636431 3/3: * lisp/net/tramp.el (tramp-file-local-name): New defun. (Bug#34343)
Date: Fri, 3 Jan 2020 07:20:43 -0500 (EST)

branch: emacs-27
commit 06364316e0998d6906b8a42d54102c5de4a54990
Author: Michael Albinus <address@hidden>
Commit: Michael Albinus <address@hidden>

    * lisp/net/tramp.el (tramp-file-local-name): New defun.  (Bug#34343)
---
 lisp/net/tramp.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 1e52fae..85330e9 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1329,6 +1329,25 @@ entry does not exist, return nil."
        (string-match-p tramp-file-name-regexp name)
        t))
 
+;; This function bypasses the file name handler approach.  It is NOT
+;; recommended to use it in any package if not absolutely necessary,
+;; because it won't work for remote file names not supported by Tramp.
+;; However, it is more performant than `file-local-name', and might be
+;; useful where performance matters, like in operations over a bulk
+;; list of file names.
+(defun tramp-file-local-name (name)
+  "Return the local name component of NAME.
+This function removes from NAME the specification of the remote
+host and the method of accessing the host, leaving only the part
+that identifies NAME locally on the remote system.  NAME must be
+a string that matches `tramp-file-name-regexp'.  The returned
+file name can be used directly as argument of ‘process-file’,
+‘start-file-process’, or ‘shell-command’."
+  (save-match-data
+    (and (tramp-tramp-file-p name)
+         (string-match (nth 0 tramp-file-name-structure) name)
+         (match-string (nth 4 tramp-file-name-structure) name))))
+
 (defun tramp-find-method (method user host)
   "Return the right method string to use depending on USER and HOST.
 This is METHOD, if non-nil.  Otherwise, do a lookup in



reply via email to

[Prev in Thread] Current Thread [Next in Thread]