Improve command completion in tramp-crypt.el

* lisp/net/tramp-crypt.el (tramp-crypt-command-completion-p):
Rename from `tramp-crypt-enabled-p'.  Handle
`tramp-crypt-remove-directory' special.
This commit is contained in:
Michael Albinus 2021-03-15 09:49:20 +01:00
parent f2b0cfff93
commit 5120b612f8

View file

@ -115,10 +115,14 @@ initializing a new crypted remote directory."
;; This function takes action since Emacs 28.1, when
;; `read-extended-command-predicate' is set to
;; `command-completion-default-include-p'.
(defun tramp-crypt-enabled-p (_symbol _buffer)
(defun tramp-crypt-command-completion-p (symbol _buffer)
"A predicate for Tramp interactive commands.
They are completed by \"M-x TAB\" only when encryption support is enabled."
tramp-crypt-enabled)
(and tramp-crypt-enabled
;; `tramp-crypt-remove-directory' needs to be completed only in
;; case we have already crypted directories.
(or (not (eq symbol #'tramp-crypt-remove-directory))
tramp-crypt-directories)))
;;;###tramp-autoload
(defconst tramp-crypt-encfs-config ".encfs6.xml"
@ -489,15 +493,17 @@ directory. File names will be also encrypted."
(setq tramp-crypt-directories (cons name tramp-crypt-directories)))
(tramp-register-file-name-handlers))
;; `tramp-crypt-enabled-p' is not autoloaded, and this setting isn't either.
;; `tramp-crypt-command-completion-p' is not autoloaded, and this
;; setting isn't either.
(function-put
#'tramp-crypt-add-directory 'completion-predicate #'tramp-crypt-enabled-p)
#'tramp-crypt-add-directory 'completion-predicate
#'tramp-crypt-command-completion-p)
(defun tramp-crypt-remove-directory (name)
"Unmark remote directory NAME for encryption.
Existing files in that directory and its subdirectories will be
kept in their encrypted form."
;; (declare (completion tramp-crypt-enabled-p))
;; (declare (completion tramp-crypt-command-completion-p))
(interactive "DRemote directory name: ")
(unless tramp-crypt-enabled
(tramp-user-error nil "Feature is not enabled."))
@ -513,7 +519,8 @@ kept in their encrypted form."
;; Starting with Emacs 28.1, this can be replaced by the "(declare ...)" form.
(function-put
#'tramp-crypt-remove-directory 'completion-predicate #'tramp-crypt-enabled-p)
#'tramp-crypt-remove-directory 'completion-predicate
#'tramp-crypt-command-completion-p)
;; `auth-source' requires a user.
(defun tramp-crypt-dissect-file-name (name)