unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Globbing file name match function?
@ 2022-06-05 11:11 Lars Ingebrigtsen
  2022-06-05 11:23 ` Eli Zaretskii
  2022-06-05 11:39 ` Andreas Schwab
  0 siblings, 2 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-05 11:11 UTC (permalink / raw)
  To: emacs-devel

I've been poking around for a couple of minutes to see whether we have a
function to list files matching a regexp a la how a shell matches them.
That is:

$ ls ~/src/emacs/*/lisp/abbrev.el
/home/larsi/src/emacs/27.1/lisp/abbrev.el
/home/larsi/src/emacs/bisect/lisp/abbrev.el
/home/larsi/src/emacs/emacs-28/lisp/abbrev.el
/home/larsi/src/emacs/foo/lisp/abbrev.el
...

This is with a glob, but ideally you'd be able to drop in a regexp
anywhere in the file name.  Do we have that anywhere in Emacs?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 11:11 Globbing file name match function? Lars Ingebrigtsen
@ 2022-06-05 11:23 ` Eli Zaretskii
  2022-06-05 11:25   ` Lars Ingebrigtsen
  2022-06-05 11:39 ` Andreas Schwab
  1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2022-06-05 11:23 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Sun, 05 Jun 2022 13:11:04 +0200
> 
> I've been poking around for a couple of minutes to see whether we have a
> function to list files matching a regexp a la how a shell matches them.
> That is:
> 
> $ ls ~/src/emacs/*/lisp/abbrev.el
> /home/larsi/src/emacs/27.1/lisp/abbrev.el
> /home/larsi/src/emacs/bisect/lisp/abbrev.el
> /home/larsi/src/emacs/emacs-28/lisp/abbrev.el
> /home/larsi/src/emacs/foo/lisp/abbrev.el
> ...
> 
> This is with a glob, but ideally you'd be able to drop in a regexp
> anywhere in the file name.  Do we have that anywhere in Emacs?

ls-lisp.el does.  It converts a wildcard to regexp, and then uses
directory-files with MATCH set to the regexp.

Do you mean specifically a wildcard in the middle of a file name,
which stands for matching subdirectories?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 11:23 ` Eli Zaretskii
@ 2022-06-05 11:25   ` Lars Ingebrigtsen
  2022-06-05 11:29     ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-05 11:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Do you mean specifically a wildcard in the middle of a file name,
> which stands for matching subdirectories?

Yes.  The leaf part matching is covered by directory-files well enough.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 11:25   ` Lars Ingebrigtsen
@ 2022-06-05 11:29     ` Eli Zaretskii
  2022-06-05 11:59       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2022-06-05 11:29 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: emacs-devel@gnu.org
> Date: Sun, 05 Jun 2022 13:25:33 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Do you mean specifically a wildcard in the middle of a file name,
> > which stands for matching subdirectories?
> 
> Yes.  The leaf part matching is covered by directory-files well enough.

But what glob does is recursively find each wildcard, expand it, then
go deeper and repeat.  So it should be possible to do the same based
on directory-files, I think?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 11:11 Globbing file name match function? Lars Ingebrigtsen
  2022-06-05 11:23 ` Eli Zaretskii
@ 2022-06-05 11:39 ` Andreas Schwab
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2022-06-05 11:39 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: emacs-devel

On Jun 05 2022, Lars Ingebrigtsen wrote:

> I've been poking around for a couple of minutes to see whether we have a
> function to list files matching a regexp a la how a shell matches them.
> That is:
>
> $ ls ~/src/emacs/*/lisp/abbrev.el
> /home/larsi/src/emacs/27.1/lisp/abbrev.el
> /home/larsi/src/emacs/bisect/lisp/abbrev.el
> /home/larsi/src/emacs/emacs-28/lisp/abbrev.el
> /home/larsi/src/emacs/foo/lisp/abbrev.el
> ...
>
> This is with a glob, but ideally you'd be able to drop in a regexp
> anywhere in the file name.  Do we have that anywhere in Emacs?

There is file-expand-wildcards.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 11:29     ` Eli Zaretskii
@ 2022-06-05 11:59       ` Lars Ingebrigtsen
  2022-06-05 13:29         ` Stefan Monnier
  2022-06-05 20:34         ` Philip Kaludercic
  0 siblings, 2 replies; 10+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-05 11:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> But what glob does is recursively find each wildcard, expand it, then
> go deeper and repeat.  So it should be possible to do the same based
> on directory-files, I think?

Yes, and I wondered if we had that already.

Andreas Schwab <schwab@linux-m68k.org> writes:

> There is file-expand-wildcards.

Ah, thanks, just what I was looking for.  (Not under the name I was
looking for, though.)  Hm...  it takes globs, but it looks trivial to
expand to regexps.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 11:59       ` Lars Ingebrigtsen
@ 2022-06-05 13:29         ` Stefan Monnier
  2022-06-05 20:34         ` Philip Kaludercic
  1 sibling, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2022-06-05 13:29 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel

>> There is file-expand-wildcards.
> Ah, thanks, just what I was looking for.  (Not under the name I was
> looking for, though.)

FWIW it recently took me a while to find it as well (I first looked for
something with "glob" in its name).  Luckily I knew we had such
a function (and I remembered it's used by `find-file`).


        Stefan




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 11:59       ` Lars Ingebrigtsen
  2022-06-05 13:29         ` Stefan Monnier
@ 2022-06-05 20:34         ` Philip Kaludercic
  2022-06-05 20:42           ` Lars Ingebrigtsen
  1 sibling, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2022-06-05 20:34 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Eli Zaretskii, emacs-devel

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>> But what glob does is recursively find each wildcard, expand it, then
>> go deeper and repeat.  So it should be possible to do the same based
>> on directory-files, I think?
>
> Yes, and I wondered if we had that already.
>
> Andreas Schwab <schwab@linux-m68k.org> writes:
>
>> There is file-expand-wildcards.
>
> Ah, thanks, just what I was looking for.  (Not under the name I was
> looking for, though.)  Hm...  it takes globs, but it looks trivial to
> expand to regexps.

Should an alias be added with "glob" in the name, something like
"glob-expand" or just "glob", like the libc function?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 20:34         ` Philip Kaludercic
@ 2022-06-05 20:42           ` Lars Ingebrigtsen
  2022-06-06  8:02             ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-05 20:42 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Eli Zaretskii, emacs-devel

Philip Kaludercic <philipk@posteo.net> writes:

> Should an alias be added with "glob" in the name, something like
> "glob-expand" or just "glob", like the libc function?

If we're bikeshedding, I think both "expand" and "wildcard" are
misleading here.  😀  I think of "$HOME" -> "/home/larsi" as an
expansion.  What this function does is search for files that match a
pattern.

So `file-find-<something>' would be natural, but we call visiting a file
`find-file', so that's confusing, too.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Globbing file name match function?
  2022-06-05 20:42           ` Lars Ingebrigtsen
@ 2022-06-06  8:02             ` Andreas Schwab
  0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2022-06-06  8:02 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Philip Kaludercic, Eli Zaretskii, emacs-devel

On Jun 05 2022, Lars Ingebrigtsen wrote:

> If we're bikeshedding, I think both "expand" and "wildcard" are
> misleading here.

The standard term is filename expansion.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-06-06  8:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-05 11:11 Globbing file name match function? Lars Ingebrigtsen
2022-06-05 11:23 ` Eli Zaretskii
2022-06-05 11:25   ` Lars Ingebrigtsen
2022-06-05 11:29     ` Eli Zaretskii
2022-06-05 11:59       ` Lars Ingebrigtsen
2022-06-05 13:29         ` Stefan Monnier
2022-06-05 20:34         ` Philip Kaludercic
2022-06-05 20:42           ` Lars Ingebrigtsen
2022-06-06  8:02             ` Andreas Schwab
2022-06-05 11:39 ` Andreas Schwab

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).