Skip to content

Commit cd3a7f3

Browse files
committed
Fix tramp-compat-file-name-quoted-p
* lisp/net/tramp-compat.el (tramp-compat-file-local-name) (tramp-compat-file-name-quoted-p): Declare them. (top): Do not use `eval-and-compile'. (tramp-compat-file-name-quoted-p): Check also func-arity of `file-name-quoted-p'.
1 parent 4299e5e commit cd3a7f3

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

lisp/net/tramp-compat.el

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
(require 'timer)
4646
(require 'ucs-normalize)
4747

48+
(declare-function tramp-compat-file-local-name 'tramp-compat)
49+
(declare-function tramp-compat-file-name-quoted-p 'tramp-compat)
50+
4851
;; For not existing functions, obsolete functions, or functions with a
4952
;; changed argument list, there are compiler warnings. We want to
5053
;; avoid them in cases we know what we do.
@@ -187,43 +190,45 @@ This is a string of ten letters or dashes as in ls -l."
187190

188191
;; `file-local-name', `file-name-quoted-p', `file-name-quote' and
189192
;; `file-name-unquote' are introduced in Emacs 26.
190-
(eval-and-compile
191-
(if (fboundp 'file-local-name)
192-
(defalias 'tramp-compat-file-local-name #'file-local-name)
193-
(defsubst tramp-compat-file-local-name (name)
194-
"Return the local name component of NAME.
193+
(if (fboundp 'file-local-name)
194+
(defalias 'tramp-compat-file-local-name #'file-local-name)
195+
(defsubst tramp-compat-file-local-name (name)
196+
"Return the local name component of NAME.
195197
It returns a file name which can be used directly as argument of
196198
`process-file', `start-file-process', or `shell-command'."
197-
(or (file-remote-p name 'localname) name)))
198-
199-
(if (fboundp 'file-name-quoted-p)
200-
(defalias 'tramp-compat-file-name-quoted-p #'file-name-quoted-p)
201-
(defsubst tramp-compat-file-name-quoted-p (name &optional top)
202-
"Whether NAME is quoted with prefix \"/:\".
199+
(or (file-remote-p name 'localname) name)))
200+
201+
;; `file-name-quoted-p' got a second argument in Emacs 27.1.
202+
(if (and
203+
(fboundp 'file-name-quoted-p)
204+
(equal (tramp-compat-funcall 'func-arity #'file-name-quoted-p) '(1 . 2)))
205+
(defalias 'tramp-compat-file-name-quoted-p #'file-name-quoted-p)
206+
(defsubst tramp-compat-file-name-quoted-p (name &optional top)
207+
"Whether NAME is quoted with prefix \"/:\".
203208
If NAME is a remote file name and TOP is nil, check the local part of NAME."
204-
(let ((file-name-handler-alist (unless top file-name-handler-alist)))
205-
(string-prefix-p "/:" (tramp-compat-file-local-name name)))))
209+
(let ((file-name-handler-alist (unless top file-name-handler-alist)))
210+
(string-prefix-p "/:" (tramp-compat-file-local-name name)))))
206211

207-
(if (fboundp 'file-name-quote)
208-
(defalias 'tramp-compat-file-name-quote #'file-name-quote)
209-
(defsubst tramp-compat-file-name-quote (name)
210-
"Add the quotation prefix \"/:\" to file NAME.
212+
(if (fboundp 'file-name-quote)
213+
(defalias 'tramp-compat-file-name-quote #'file-name-quote)
214+
(defsubst tramp-compat-file-name-quote (name)
215+
"Add the quotation prefix \"/:\" to file NAME.
211216
If NAME is a remote file name, the local part of NAME is quoted."
212-
(if (tramp-compat-file-name-quoted-p name)
213-
name
214-
(concat
215-
(file-remote-p name) "/:" (tramp-compat-file-local-name name)))))
216-
217-
(if (fboundp 'file-name-unquote)
218-
(defalias 'tramp-compat-file-name-unquote #'file-name-unquote)
219-
(defsubst tramp-compat-file-name-unquote (name)
220-
"Remove quotation prefix \"/:\" from file NAME.
217+
(if (tramp-compat-file-name-quoted-p name)
218+
name
219+
(concat
220+
(file-remote-p name) "/:" (tramp-compat-file-local-name name)))))
221+
222+
(if (fboundp 'file-name-unquote)
223+
(defalias 'tramp-compat-file-name-unquote #'file-name-unquote)
224+
(defsubst tramp-compat-file-name-unquote (name)
225+
"Remove quotation prefix \"/:\" from file NAME.
221226
If NAME is a remote file name, the local part of NAME is unquoted."
222-
(let ((localname (tramp-compat-file-local-name name)))
223-
(when (tramp-compat-file-name-quoted-p localname)
224-
(setq
225-
localname (if (= (length localname) 2) "/" (substring localname 2))))
226-
(concat (file-remote-p name) localname)))))
227+
(let ((localname (tramp-compat-file-local-name name)))
228+
(when (tramp-compat-file-name-quoted-p localname)
229+
(setq
230+
localname (if (= (length localname) 2) "/" (substring localname 2))))
231+
(concat (file-remote-p name) localname))))
227232

228233
;; `tramp-syntax' has changed its meaning in Emacs 26. We still
229234
;; support old settings.
@@ -241,7 +246,7 @@ If NAME is a remote file name, the local part of NAME is unquoted."
241246
'(cdr (mapcar #'car (get 'tramp-file-name 'cl-struct-slots)))))
242247

243248
;; The signature of `tramp-make-tramp-file-name' has been changed.
244-
;; Therefore, we cannot us `url-tramp-convert-url-to-tramp' prior
249+
;; Therefore, we cannot use `url-tramp-convert-url-to-tramp' prior
245250
;; Emacs 26.1. We use `temporary-file-directory' as indicator.
246251
(defconst tramp-compat-use-url-tramp-p (fboundp 'temporary-file-directory)
247252
"Whether to use url-tramp.el.")

0 commit comments

Comments
 (0)