branch: externals/tramp
commit 01e7adaa09d78fcf038e54f701127369dace6634
Author: Michael Albinus <[email protected]>
Commit: Michael Albinus <[email protected]>

    Some few Tramp changes
---
 tramp-cmds.el | 43 +++++++++++++++++++++++++++++++++++++++++++
 tramp.el      |  7 ++++---
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/tramp-cmds.el b/tramp-cmds.el
index d208f0e..a3cf6f3 100644
--- a/tramp-cmds.el
+++ b/tramp-cmds.el
@@ -472,6 +472,49 @@ For details, see `tramp-rename-files'."
 (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.
+  (and (assq 'tramp (bound-and-true-p package-alist))
+       (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
diff --git a/tramp.el b/tramp.el
index f509afc..d578cb4 100644
--- a/tramp.el
+++ b/tramp.el
@@ -2588,9 +2588,10 @@ Falls back to normal file name handler if no Tramp file 
name handler exists."
 ;;;###autoload
 (progn (defun tramp-register-autoload-file-name-handlers ()
   "Add Tramp file name handlers to `file-name-handler-alist' during autoload."
-  (add-to-list 'file-name-handler-alist
-              (cons tramp-autoload-file-name-regexp
-                    'tramp-autoload-file-name-handler))
+  (unless (rassq 'tramp-file-name-handler file-name-handler-alist)
+    (add-to-list 'file-name-handler-alist
+                (cons tramp-autoload-file-name-regexp
+                      'tramp-autoload-file-name-handler)))
   (put #'tramp-autoload-file-name-handler 'safe-magic t)))
 
 ;;;###autoload (tramp-register-autoload-file-name-handlers)

Reply via email to