Subject: bug#73952: closed (Re: bug#73952: 30.0.91; [PATCH] Fix error when an Eshell glob has no results and 'eshell-glob-splice-results' is t)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 22 Oct 2024 21:34:02 +0000

Your bug report

#73952: 30.0.91; [PATCH] Fix error when an Eshell glob has no results and 'eshell-glob-splice-results' is t

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
73952: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=73952
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#73952: 30.0.91; [PATCH] Fix error when an Eshell glob has no results and 'eshell-glob-splice-results' is t
From: Jim Porter <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: [email-masked]
Date: Tue, 22 Oct 2024 14:31:58 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On 10/22/2024 10:43 AM, Eli Zaretskii wrote:
>> Cc: [email-masked]
>> Date: Tue, 22 Oct 2024 09:57:42 -0700
>> From: Jim Porter <[email-masked]>
>>
>> This is a bug in a new Eshell feature in Emacs 30 and thankfully has an
>> easy fix (see attached). Eli, is this ok for the release branch?
> 
> Yes, thanks.

Thanks. Merged to the release branch as b7a375f5c49, and closing this now.

Subject: 30.0.91; [PATCH] Fix error when an Eshell glob has no results and 'eshell-glob-splice-results' is t
From: Jim Porter <[email-masked]>
To: [email-masked]
Date: Tue, 22 Oct 2024 09:57:42 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

X-Debbugs-CC: [email-masked]

Starting from "emacs -Q -f eshell":

   ~ $ (setq eshell-glob-splice-results t)
   t
   ~ $ echo /ssh:localhost:~/file.txt
   /ssh:localhost:~/file.txt
   ~ $ echo /ssh:localhost:~/file.txt
   Wrong type argument: listp, "/ssh:localhost:~/file.txt"

The third command should have the same result as the second (the second 
works because Tramp isn't loaded yet at the time).

This is a bug in a new Eshell feature in Emacs 30 and thankfully has an 
easy fix (see attached). Eli, is this ok for the release branch? I added 
a regression test for this too.

From b7a375f5c49ac86399b9af7a6a74720ed294abd7 Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Tue, 22 Oct 2024 09:43:00 -0700
Subject: [PATCH] Fix error when splicing Eshell globs and a glob expands to
 itself

This could happen when 'eshell-extended-glob' determines that a "glob"
is not really a glob.  This mainly happens for remote file names with a
"~" in them, like "/ssh:remote:~/file.txt".

* lisp/eshell/em-glob.el (eshell-extended-glob): Return a list when
'eshell-glob-splice-results' is non-nil.
* test/lisp/eshell/em-glob-tests.el
(em-glob-test/expand/splice-results)
em-glob-test/expand/no-splice-results): Extend tests.
---
 lisp/eshell/em-glob.el            |  2 +-
 test/lisp/eshell/em-glob-tests.el | 16 +++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/lisp/eshell/em-glob.el b/lisp/eshell/em-glob.el
index 36e4f90aed2..2aceaf188f3 100644
--- a/lisp/eshell/em-glob.el
+++ b/lisp/eshell/em-glob.el
@@ -348,7 +348,7 @@ eshell-extended-glob
         ;; always be sure if the "~" is a home directory reference or
         ;; part of a glob (e.g. if the argument was assembled from
         ;; variables).
-        glob
+        (if eshell-glob-splice-results (list glob) glob)
       (unwind-protect
           (apply #'eshell-glob-entries globs)
         (if message-shown
diff --git a/test/lisp/eshell/em-glob-tests.el b/test/lisp/eshell/em-glob-tests.el
index 2efb3a9df69..88e9cc73bbd 100644
--- a/test/lisp/eshell/em-glob-tests.el
+++ b/test/lisp/eshell/em-glob-tests.el
@@ -74,7 +74,13 @@ em-glob-test/expand/splice-results
       ;; Ensure the default expansion splices the glob.
       (eshell-command-result-equal "funcall list *.el" '("a.el" "b.el"))
       (eshell-command-result-equal "funcall list *.txt" '("c.txt"))
-      (eshell-command-result-equal "funcall list *.no" '("*.no")))))
+      ;; When spliting, no-matches cases also return a list containing
+      ;; the original non-matching glob.
+      (eshell-command-result-equal "funcall list *.no" '("*.no"))
+      (when (eshell-tests-remote-accessible-p)
+        (let ((remote (file-remote-p ert-remote-temporary-file-directory)))
+          (eshell-command-result-equal (format "funcall list %s~/a.el" remote)
+                                       `(,(format "%s~/a.el" remote))))))))
 
 (ert-deftest em-glob-test/expand/no-splice-results ()
   "Test that globs are treated as lists when
@@ -85,9 +91,13 @@ em-glob-test/expand/no-splice-results
       ;; Ensure the default expansion splices the glob.
       (eshell-command-result-equal "funcall list *.el" '(("a.el" "b.el")))
       (eshell-command-result-equal "funcall list *.txt" '(("c.txt")))
-      ;; The no-matches case is special here: the glob is just the
+      ;; The no-matches cases are special here: the glob is just the
       ;; string, not the list of results.
-      (eshell-command-result-equal "funcall list *.no" '("*.no")))))
+      (eshell-command-result-equal "funcall list *.no" '("*.no"))
+      (when (eshell-tests-remote-accessible-p)
+        (let ((remote (file-remote-p ert-remote-temporary-file-directory)))
+          (eshell-command-result-equal (format "funcall list %s~/a.el" remote)
+                                       `(,(format "%s~/a.el" remote))))))))
 
 (ert-deftest em-glob-test/expand/explicitly-splice-results ()
   "Test explicitly splicing globs works the same no matter the
-- 
2.25.1