Subject: Re: bug#27844: 26.0.50; Dired w/ eshell-ls doesn't support wildcards in file name

From: Tino Calancha <[email-masked]>
Date: Thu, 27 Jul 2017 18:23:08 +0900

Tino Calancha <[email-masked]> writes:

> Dired with eshell-ls doesn't handle wildcards in file names.
>  
>  ;;; Functions:
>  
> +(declare-function eshell-extended-glob "em-glob" (glob))
> +
>  (defun eshell-ls--insert-directory
>    (orig-fun file switches &optional wildcard full-directory-p)
>    "Insert directory listing for FILE, formatted according to SWITCHES.
> @@ -273,11 +275,18 @@ eshell-ls--insert-directory
>                  (set 'font-lock-buffers
>                       (delq (current-buffer)
>                             (symbol-value 'font-lock-buffers)))))
> +          (require 'em-glob)
>            (let ((insert-func 'insert)
>                  (error-func 'insert)
>                  (flush-func 'ignore)
> +                (target ; Expand the shell wildcards if any.
> +                 (if (and (atom file)
> +                          (string-match "[[?*]" file)
> +                          (not (file-exists-p file)))
> +                     (mapcar #'file-relative-name (eshell-extended-glob file))
> +                   (file-relative-name file)))
>                  eshell-ls-dired-initial-args)
`eshell-extended-glob' returns a list of matches on success, otherwise
it returns FILE;  if no match i think we should signal an error.

--8<-----------------------------cut here---------------start------------->8---
commit 22f4516a6081c57363790694a11e5f9fe3f84c70
Author: Tino Calancha <[email-masked]>
Date:   Thu Jul 27 18:08:17 2017 +0900

    Dired w/ eshell-ls: Handle shell wildcards in file name
    
    * lisp/eshell/em-ls.el (eshell-ls--insert-directory):
    Use eshell-extended-glob (Bug#27844).
    * test/lisp/dired-tests.el (dired-test-bug27844): Add test.

diff --git a/lisp/eshell/em-ls.el b/lisp/eshell/em-ls.el
index 79799db30b..2e0b16db75 100644
--- a/lisp/eshell/em-ls.el
+++ b/lisp/eshell/em-ls.el
@@ -241,6 +241,8 @@ dired-flag
 
 ;;; Functions:
 
+(declare-function eshell-extended-glob "em-glob" (glob))
+
 (defun eshell-ls--insert-directory
   (orig-fun file switches &optional wildcard full-directory-p)
   "Insert directory listing for FILE, formatted according to SWITCHES.
@@ -273,11 +275,21 @@ eshell-ls--insert-directory
                 (set 'font-lock-buffers
                      (delq (current-buffer)
                            (symbol-value 'font-lock-buffers)))))
+          (require 'em-glob)
           (let ((insert-func 'insert)
                 (error-func 'insert)
                 (flush-func 'ignore)
+                (target ; Expand the shell wildcards if any.
+                 (if (and (atom file)
+                          (string-match "[[?*]" file)
+                          (not (file-exists-p file)))
+                     (let ((matches (eshell-extended-glob file)))
+                       (if (consp matches)
+                           (mapcar #'file-relative-name matches)
+                         (user-error (format "%s: No files matching wildcard" file))))
+                   (file-relative-name file)))
                 eshell-ls-dired-initial-args)
-            (eshell-do-ls (append switches (list file)))))))))
+            (eshell-do-ls (append switches (list target)))))))))
 
 (defsubst eshell/ls (&rest args)
   "An alias version of `eshell-do-ls'."

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-07-27
Repository revision: 28faa94f1c423091bb34c2776eabe9ae83e5b4fc