@item
I get a warning @samp{Tramp has been compiled with Emacs a.b, this is Emacs c.d}
+@item
+I get an error @samp{tramp-file-name-handler: Invalid function:
+tramp-compat-with-mutex}
@value{tramp} comes with compatibility code for different Emacs
versions. When you see this warning, you don't use the Emacs built-in
version of @value{tramp}. In case you have installed @value{tramp}
-from GNU ELPA, you must delete and reinstall it.
+from GNU ELPA, see the package README file for instructions how to
+recompile it.
@ifset installchapter
In case you have installed it from its Git repository, @ref{Recompilation}.
@end ifset
-@item
-I get an error @samp{tramp-file-name-handler: Invalid function:
-tramp-compat-with-mutex}
-
-Likely, you have a running Emacs session with loaded @value{tramp},
-and you try to upgrade it to another version from GNU ELPA. Since
-@value{tramp} is not forward compatible, you must unload / reload it.
-Try the following steps:
-
-@example
-@kbd{M-x tramp-unload-tramp @key{RET}}
-@kbd{M-x load-library @key{RET} tramp @key{RET}}
-@end example
-
-If this doesn't work, you must restart Emacs with proper
-@code{load-path} for the new @value{tramp} version.
-
-
@item
I get an error @samp{Remote file error: Forbidden reentrant call of Tramp}
(function-put
#'tramp-rename-these-files 'completion-predicate #'tramp-command-completion-p)
+;; This function takes action since Emacs 28.1, when
+;; `read-extended-command-predicate' is set to
+;; `command-completion-default-include-p'.
+;;;###tramp-autoload
+(defun tramp-recompile-elpa-command-completion-p (_symbol _buffer)
+ "A predicate for `tramp-recompile-elpa'.
+It is completed by \"M-x TAB\" only if package.el is loaded, and
+Tramp is an installed ELPA package."
+ ;; We cannot apply `package-installed-p', this would also return the
+ ;; builtin package.
+ (tramp-compat-funcall 'package--user-installed-p 'tramp))
+
+;;;###tramp-autoload
+(defun tramp-recompile-elpa ()
+ "Recompile the installed Tramp ELPA package.
+This is needed if there are compatibility problems."
+ ;; (declare (completion tramp-recompile-elpa-command-completion-p))
+ (interactive)
+ ;; We expect just one Tramp package is installed.
+ (when-let
+ ((dir (tramp-compat-funcall
+ 'package-desc-dir
+ (car (alist-get 'tramp (bound-and-true-p package-alist))))))
+ (dolist (elc (directory-files dir 'full "\\.elc$"))
+ (delete-file elc))
+ (with-current-buffer (get-buffer-create byte-compile-log-buffer)
+ (let ((inhibit-read-only t))
+ (compilation-mode)
+ (goto-char (point-max))
+ (insert "\f\n")
+ (call-process
+ (expand-file-name invocation-name invocation-directory) nil t t
+ "-Q" "-batch" "-L" dir
+ "--eval" (format "(byte-recompile-directory %S 0 t)" dir))
+ (message "Package `tramp' recompiled.")))))
+
+;; Starting with Emacs 28.1, this can be replaced by the "(declare ...)" form.
+;;;###tramp-autoload
+(function-put
+ #'tramp-recompile-elpa 'completion-predicate
+ #'tramp-recompile-elpa-command-completion-p)
+
;; Tramp version is useful in a number of situations.
;;;###tramp-autoload