Subject: Re: bug#76603: 30.1; multi-file-replace-regexp-as-diff won't end prompting with icomplete-show-matches-on-no-input

From: Juri Linkov <[email-masked]>
Date: Thu, 13 Mar 2025 19:50:58 +0200

>> I vaguely remember there exists such a function that reads a glob pattern,
>> but can't find it right away.
>
> Neither did I :(

Now I remembered the name of this function: 'file-expand-wildcards'.
Like is used in 'multi-isearch-read-matching-files'.

> Do you think two more functions with extended
> functionality are worth a patch?

A patch would be nice later, when you will get a working version
with using more core functions.

>   (defun glob-to-regexp (glob)
>     "Convert a GLOB pattern (e.g., '*.el') to a regexp that `directory-files-recursively` can use."
>     (concat "^" (replace-regexp-in-string
>                  (rx (any "*?."))
>                  (lambda (match)
>                    (pcase match
>                      ("*" ".*")
>                      ("?" ".")
>                      ("." "\\\\.") ; Properly escape the dot
>                      (_ match)))
>                  glob)
>             "$"))

There is already the core function 'wildcard-to-regexp'
and its duplicate 'dired-glob-regexp'.

>   (defun expand-directories (items)
>     "Expand ITEMS to include all files within directories (recursively).
> Directories themselves are excluded from the final list."
>     (cl-loop for item in items
>              if (file-directory-p item)
>              append (let ((files (directory-files-recursively item ".*" t)))
>                       (cl-remove-if #'file-directory-p files))
>              else if (file-regular-p item) ; Ensure only regular files are included
>              collect item))

I don't remember such a core function, so maybe the function above could be added.