unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Q: read-file-name: Descend into subdirs while using a predicate?
@ 2022-09-26 14:45 T.V Raman
  2022-09-26 16:41 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: T.V Raman @ 2022-09-26 14:45 UTC (permalink / raw)
  To: emacs-devel

This feels like a puzzle that should have an easy answer, but I've not
found it:-)

You want to:

1. Use read-file-name with completion.
2. You want to only return filenames with a given extension -- and
   that extension is a regex 
3. You also want to descend into  subdirs of the current directory if
   the user's input matches a subdir that exists 

So you provide 'must-match  and a predicate -- and in that predicate I
tested for the regexp --- but then the descend into subdirs fails, and
if you check for either the   pattern or file-directory-p, then the
read call just returns the directory.

one heavy-weight solution might be to call directory-files with a
pattern,  and pass that as a list to completing-read but that feels
heaviy-weight in that you could end up descending deeper into the
directory tree than you need to ...

-- 

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
♉ Id: kg:/m/0285kf1  🦮

-- 

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
♉ Id: kg:/m/0285kf1  🦮



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

* Re: Q: read-file-name: Descend into subdirs while using a predicate?
  2022-09-26 14:45 Q: read-file-name: Descend into subdirs while using a predicate? T.V Raman
@ 2022-09-26 16:41 ` Stefan Monnier
  2022-09-26 17:05   ` T.V Raman
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2022-09-26 16:41 UTC (permalink / raw)
  To: T.V Raman; +Cc: emacs-devel

T.V Raman [2022-09-26 07:45:08] wrote:
> This feels like a puzzle that should have an easy answer, but I've not
> found it:-)

It's a long standing "todo" :-(

Basically, we need to change the notion of "predicate" during completion
so as to distinguish the "predicate to filter completions" from the
"predicate to check if a value is fit to be returned from
`completing-read`" (AKA the distinguish the predicate passed to
`test-completion` from the predicate passed to `all/try/completions`).

I've been toying with the idea of letting the predicate return a third
option (beside nil and t) to say "it's acceptable for completions but
not for `test-completion`".


        Stefan




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

* Re: Q: read-file-name: Descend into subdirs while using a predicate?
  2022-09-26 16:41 ` Stefan Monnier
@ 2022-09-26 17:05   ` T.V Raman
  0 siblings, 0 replies; 3+ messages in thread
From: T.V Raman @ 2022-09-26 17:05 UTC (permalink / raw)
  To: monnier; +Cc: raman, emacs-devel

Thanks Stefan for the clear answer, and happy to know I wasn't
overlooking something simple.
Also, on  my laptop with an SSD, using 
directory-files-recursively appears to be blazingly fast for
relatively large directories --- so that "heavy hammer" is a good
intermediate solution for my usecase which was to filter media files,
epub books and the like.
Stefan Monnier writes:
 > T.V Raman [2022-09-26 07:45:08] wrote:
 > > This feels like a puzzle that should have an easy answer, but I've not
 > > found it:-)
 > 
 > It's a long standing "todo" :-(
 > 
 > Basically, we need to change the notion of "predicate" during completion
 > so as to distinguish the "predicate to filter completions" from the
 > "predicate to check if a value is fit to be returned from
 > `completing-read`" (AKA the distinguish the predicate passed to
 > `test-completion` from the predicate passed to `all/try/completions`).
 > 
 > I've been toying with the idea of letting the predicate return a third
 > option (beside nil and t) to say "it's acceptable for completions but
 > not for `test-completion`".
 > 
 > 
 >         Stefan

-- 

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
♉ Id: kg:/m/0285kf1  🦮

--

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
♉ Id: kg:/m/0285kf1  🦮

--

Thanks,

--Raman(I Search, I Find, I Misplace, I Research)
♉ Id: kg:/m/0285kf1  🦮



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

end of thread, other threads:[~2022-09-26 17:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 14:45 Q: read-file-name: Descend into subdirs while using a predicate? T.V Raman
2022-09-26 16:41 ` Stefan Monnier
2022-09-26 17:05   ` T.V Raman

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).