Subject: Re: bug#64124: 29.0.91; Loading ‘tramp’unconditionally loads ‘ls-lisp’

From: Michael Albinus <[email-masked]>
Date: Sat, 17 Jun 2023 12:18:43 +0200

Sebastian Miele <[email-masked]> writes:

Hi Sebastian,

> Feature ‘tramp’ unconditionally requires ‘tramp-compat’, which in turn
> unconditionally requires ‘ls-lisp’.  ‘ls-lisp’ advises ‘dired’ with
> ‘ls-lisp--dired’.  That in particular has the effect that globstar
> patterns do not work as advertised in [[info:emacs#Dired Enter]], even
> though my SHELL does support them out of the box.
>
> So now the situation is: If you use Tramp, then you also use ‘ls-lisp’,
> and cannot use globstar patterns, as advertised in the Emacs manual.

Could you please check whether the appended patch fixes this for you?

Best regards, Michael.

diff --git a/lisp/tramp-compat.el b/lisp/tramp-compat.el
index 1386f301..44a67259 100644
--- a/lisp/tramp-compat.el
+++ b/lisp/tramp-compat.el
@@ -32,11 +32,13 @@
 (require 'ansi-color)
 (require 'auth-source)
 (require 'format-spec)
-(require 'ls-lisp) ;; Due to `tramp-handle-insert-directory'.
 (require 'parse-time)
 (require 'shell)
 (require 'subr-x)

+(when (memq system-type '(ms-dos windows-nt))
+  (require 'ls-lisp)) ;; Due to `tramp-handle-insert-directory'.
+
 (declare-function tramp-compat-rx "tramp")
 (declare-function tramp-error "tramp")
 (declare-function tramp-file-name-handler "tramp")
diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el
index ec28b51c..7915ea9a 100644
--- a/lisp/tramp-sh.el
+++ b/lisp/tramp-sh.el
@@ -38,6 +38,7 @@
 (declare-function dired-compress-file "dired-aux")
 (declare-function dired-remove-file "dired-aux")
 (defvar dired-compress-file-suffixes)
+(defvar ls-lisp-use-insert-directory-program)
 ;; Added in Emacs 28.1.
 (defvar process-file-return-signal-string)
 (defvar vc-handled-backends)
@@ -2634,7 +2635,7 @@ The method used must be an out-of-band method."
     (access-file filename "Reading directory"))
   (with-parsed-tramp-file-name (expand-file-name filename) nil
     (if (and (featurep 'ls-lisp)
-	     (not (symbol-value 'ls-lisp-use-insert-directory-program)))
+	     (not ls-lisp-use-insert-directory-program))
 	(tramp-handle-insert-directory
 	 filename switches wildcard full-directory-p)
       (when (stringp switches)
diff --git a/lisp/tramp.el b/lisp/tramp.el
index c5a82d7b..90fd53b0 100644
--- a/lisp/tramp.el
+++ b/lisp/tramp.el
@@ -63,6 +63,7 @@
 (declare-function file-notify-rm-watch "filenotify")
 (declare-function netrc-parse "netrc")
 (defvar auto-save-file-name-transforms)
+(defvar ls-lisp-use-insert-directory-program)

 ;; Reload `tramp-compat' when we reload `tramp-autoloads' of the GNU
 ;; ELPA package.
@@ -4326,6 +4327,7 @@ Let-bind it when necessary.")
 (defun tramp-handle-insert-directory
   (filename switches &optional wildcard full-directory-p)
   "Like `insert-directory' for Tramp files."
+  (require 'ls-lisp)
   (unless switches (setq switches ""))
   ;; Mark trailing "/".
   (when (and (directory-name-p filename)
@@ -4338,7 +4340,6 @@ Let-bind it when necessary.")
     (with-tramp-progress-reporter v 0 (format "Opening directory %s" filename)
       (let (ls-lisp-use-insert-directory-program start)
 	;; Silence byte compiler.
-	(ignore ls-lisp-use-insert-directory-program)
 	(tramp-run-real-handler
 	 #'insert-directory
 	 (list filename switches wildcard full-directory-p))