Make Tramp aware of completion-regexp-list (don't merge)
* lisp/net/tramp.el (tramp-skeleton-file-name-all-completions): New defmacro. (tramp-completion-handle-file-name-all-completions): * lisp/net/tramp-adb.el (tramp-adb-handle-file-name-all-completions): * lisp/net/tramp-crypt.el (tramp-crypt-handle-file-name-all-completions): * lisp/net/tramp-fuse.el (tramp-fuse-handle-file-name-all-completions): * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-file-name-all-completions): * lisp/net/tramp-sh.el (tramp-sh-handle-file-name-all-completions): * lisp/net/tramp-smb.el (tramp-smb-handle-file-name-all-completions): * lisp/net/tramp-sudoedit.el (tramp-sudoedit-handle-file-name-all-completions): Use it.
This commit is contained in:
parent
232a57a3e3
commit
7b0e07c41a
8 changed files with 159 additions and 150 deletions
|
@ -449,7 +449,7 @@ Emacs dired can't find files."
|
|||
|
||||
(defun tramp-adb-handle-file-name-all-completions (filename directory)
|
||||
"Like `file-name-all-completions' for Tramp files."
|
||||
(tramp-compat-ignore-error file-missing
|
||||
(tramp-skeleton-file-name-all-completions filename directory
|
||||
(all-completions
|
||||
filename
|
||||
(with-parsed-tramp-file-name (expand-file-name directory) nil
|
||||
|
@ -464,17 +464,14 @@ Emacs dired can't find files."
|
|||
(file-name-as-directory f)
|
||||
f))
|
||||
(with-current-buffer (tramp-get-buffer v)
|
||||
(delete-dups
|
||||
(append
|
||||
;; On some file systems like "sdcard", "." and ".." are
|
||||
;; not included. We fix this by `delete-dups'.
|
||||
;; not included.
|
||||
'("." "..")
|
||||
(delq
|
||||
nil
|
||||
(mapcar
|
||||
(lambda (l)
|
||||
(and (not (string-match-p (rx bol (* blank) eol) l)) l))
|
||||
(split-string (buffer-string) "\n"))))))))))))
|
||||
(split-string (buffer-string) "\n" 'omit))))))))))
|
||||
|
||||
(defun tramp-adb-handle-file-local-copy (filename)
|
||||
"Like `file-local-copy' for Tramp files."
|
||||
|
|
|
@ -735,7 +735,7 @@ absolute file names."
|
|||
|
||||
(defun tramp-crypt-handle-file-name-all-completions (filename directory)
|
||||
"Like `file-name-all-completions' for Tramp files."
|
||||
(tramp-compat-ignore-error file-missing
|
||||
(tramp-skeleton-file-name-all-completions filename directory
|
||||
(all-completions
|
||||
filename
|
||||
(let* (completion-regexp-list
|
||||
|
|
|
@ -104,11 +104,10 @@
|
|||
|
||||
(defun tramp-fuse-handle-file-name-all-completions (filename directory)
|
||||
"Like `file-name-all-completions' for Tramp files."
|
||||
(tramp-skeleton-file-name-all-completions filename directory
|
||||
(tramp-fuse-remove-hidden-files
|
||||
(tramp-compat-ignore-error file-missing
|
||||
(all-completions
|
||||
filename
|
||||
(delete-dups
|
||||
(append
|
||||
(file-name-all-completions
|
||||
filename (tramp-fuse-local-file-name directory))
|
||||
|
@ -119,7 +118,7 @@
|
|||
(catch 'match
|
||||
(dolist (elt completion-regexp-list)
|
||||
(unless (string-match-p elt item) (throw 'match nil)))
|
||||
(setq result (cons (concat item "/") result))))))))))))
|
||||
(setq result (cons (concat item "/") result)))))))))))
|
||||
|
||||
;; This function isn't used.
|
||||
(defun tramp-fuse-handle-insert-directory
|
||||
|
|
|
@ -1434,8 +1434,8 @@ If FILE-SYSTEM is non-nil, return file system attributes."
|
|||
|
||||
(defun tramp-gvfs-handle-file-name-all-completions (filename directory)
|
||||
"Like `file-name-all-completions' for Tramp files."
|
||||
(tramp-skeleton-file-name-all-completions filename directory
|
||||
(unless (tramp-compat-string-search "/" filename)
|
||||
(tramp-compat-ignore-error file-missing
|
||||
(all-completions
|
||||
filename
|
||||
(with-parsed-tramp-file-name (expand-file-name directory) nil
|
||||
|
|
|
@ -1831,11 +1831,11 @@ ID-FORMAT valid values are `string' and `integer'."
|
|||
;; files.
|
||||
(defun tramp-sh-handle-file-name-all-completions (filename directory)
|
||||
"Like `file-name-all-completions' for Tramp files."
|
||||
(tramp-skeleton-file-name-all-completions filename directory
|
||||
(with-parsed-tramp-file-name (expand-file-name directory) nil
|
||||
(when (and (not (tramp-compat-string-search "/" filename))
|
||||
(tramp-connectable-p v))
|
||||
(unless (tramp-compat-string-search "/" filename)
|
||||
(tramp-compat-ignore-error file-missing
|
||||
(all-completions
|
||||
filename
|
||||
(with-tramp-file-property v localname "file-name-all-completions"
|
||||
|
@ -1869,7 +1869,8 @@ ID-FORMAT valid values are `string' and `integer'."
|
|||
(with-current-buffer (tramp-get-buffer v)
|
||||
(goto-char (point-max))
|
||||
(while (zerop (forward-line -1))
|
||||
(push (buffer-substring (point) (line-end-position)) result)))
|
||||
(push
|
||||
(buffer-substring (point) (line-end-position)) result)))
|
||||
result)))))))))
|
||||
|
||||
;; cp, mv and ln
|
||||
|
|
|
@ -987,20 +987,19 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
|
|||
;; files.
|
||||
(defun tramp-smb-handle-file-name-all-completions (filename directory)
|
||||
"Like `file-name-all-completions' for Tramp files."
|
||||
(tramp-compat-ignore-error file-missing
|
||||
(tramp-skeleton-file-name-all-completions filename directory
|
||||
(all-completions
|
||||
filename
|
||||
(when (file-directory-p directory)
|
||||
(with-parsed-tramp-file-name (expand-file-name directory) nil
|
||||
(with-tramp-file-property v localname "file-name-all-completions"
|
||||
(delete-dups
|
||||
(mapcar
|
||||
(lambda (x)
|
||||
(list
|
||||
(if (tramp-compat-string-search "d" (nth 1 x))
|
||||
(file-name-as-directory (nth 0 x))
|
||||
(nth 0 x))))
|
||||
(tramp-smb-get-file-entries directory)))))))))
|
||||
(tramp-smb-get-file-entries directory))))))))
|
||||
|
||||
(defun tramp-smb-handle-file-system-info (filename)
|
||||
"Like `file-system-info' for Tramp files."
|
||||
|
|
|
@ -467,7 +467,7 @@ the result will be a local, non-Tramp, file name."
|
|||
|
||||
(defun tramp-sudoedit-handle-file-name-all-completions (filename directory)
|
||||
"Like `file-name-all-completions' for Tramp files."
|
||||
(tramp-compat-ignore-error file-missing
|
||||
(tramp-skeleton-file-name-all-completions filename directory
|
||||
(all-completions
|
||||
filename
|
||||
(with-parsed-tramp-file-name (expand-file-name directory) nil
|
||||
|
@ -481,13 +481,11 @@ the result will be a local, non-Tramp, file name."
|
|||
(if (ignore-errors (file-directory-p (expand-file-name f directory)))
|
||||
(file-name-as-directory f)
|
||||
f))
|
||||
(delq
|
||||
nil
|
||||
(mapcar
|
||||
(lambda (l) (and (not (string-match-p (rx bol (* blank) eol) l)) l))
|
||||
(split-string
|
||||
(tramp-get-buffer-string (tramp-get-connection-buffer v))
|
||||
"\n" 'omit)))))))))
|
||||
"\n" 'omit))))))))
|
||||
|
||||
(defun tramp-sudoedit-handle-file-readable-p (filename)
|
||||
"Like `file-readable-p' for Tramp files."
|
||||
|
|
|
@ -3069,12 +3069,30 @@ not in completion mode."
|
|||
|
||||
(tramp-run-real-handler #'file-exists-p (list filename))))
|
||||
|
||||
(defmacro tramp-skeleton-file-name-all-completions
|
||||
(_filename _directory &rest body)
|
||||
"Skeleton for `tramp-*-handle-filename-all-completions'.
|
||||
BODY is the backend specific code."
|
||||
(declare (indent 2) (debug t))
|
||||
`(tramp-compat-ignore-error file-missing
|
||||
(delete-dups (delq nil
|
||||
(let* ((case-fold-search read-file-name-completion-ignore-case)
|
||||
(regexp (mapconcat #'identity completion-regexp-list "\\|"))
|
||||
(result ,@body))
|
||||
(if (consp completion-regexp-list)
|
||||
;; Discriminate over `completion-regexp-list'.
|
||||
(mapcar
|
||||
(lambda (x) (and (stringp x) (string-match-p regexp x) x))
|
||||
result)
|
||||
result))))))
|
||||
|
||||
;; Method, host name and user name completion.
|
||||
;; `tramp-completion-dissect-file-name' returns a list of
|
||||
;; `tramp-file-name' structures. For all of them we return possible
|
||||
;; completions.
|
||||
(defun tramp-completion-handle-file-name-all-completions (filename directory)
|
||||
"Like `file-name-all-completions' for partial Tramp files."
|
||||
(tramp-skeleton-file-name-all-completions filename directory
|
||||
(let ((fullname
|
||||
(tramp-drop-volume-letter (expand-file-name filename directory)))
|
||||
;; When `tramp-syntax' is `simplified', we need a default method.
|
||||
|
@ -3108,9 +3126,7 @@ not in completion mode."
|
|||
all-user-hosts)
|
||||
|
||||
(unless localname ;; Nothing to complete.
|
||||
|
||||
(if (or user host)
|
||||
|
||||
;; Method dependent user / host combinations.
|
||||
(progn
|
||||
(mapc
|
||||
|
@ -3132,7 +3148,7 @@ not in completion mode."
|
|||
(setq result
|
||||
(append result (tramp-get-completion-methods m)))))))
|
||||
|
||||
;; Unify list, add hop, remove nil elements.
|
||||
;; Add hop.
|
||||
(dolist (elt result)
|
||||
(when elt
|
||||
(string-match tramp-prefix-regexp elt)
|
||||
|
@ -3142,7 +3158,6 @@ not in completion mode."
|
|||
result1)))
|
||||
|
||||
;; Complete local parts.
|
||||
(delete-dups
|
||||
(append
|
||||
result1
|
||||
(ignore-errors
|
||||
|
|
Loading…
Add table
Reference in a new issue