all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* read-file-name() doesn't care about PREDICATE argument
@ 2010-03-17 11:49 Nordlöw
  2010-03-17 14:24 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Nordlöw @ 2010-03-17 11:49 UTC (permalink / raw)
  To: help-gnu-emacs

Why is the argument PREDICATE not used in read-file-name?

For example
  (read-file-name "Find file: " "~/" nil t nil (lambda (filename)
nil))
incorrectly completes everything for me when it shouldn't complete
anything at all since the PREDICATE function always returns nil.

I have also tried the Icicles version
  (icicle-read-file-name "Find file: " "~/" nil t nil (lambda
(filename) nil))
but it behaves exactly the same.

The following code works as expected, though:
  (let ((icicle-must-pass-predicate (lambda (filename) nil)))
        (icicle-read-file-name "Find file: " "~/" nil t nil (lambda
(filename) nil)))

Why doesn't first two example like the last? And why does the icicle
version provide this extra variable? It smells like a bug or a missing
feature.

/Nordlöw


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

* Re: read-file-name() doesn't care about PREDICATE argument
  2010-03-17 11:49 read-file-name() doesn't care about PREDICATE argument Nordlöw
@ 2010-03-17 14:24 ` Stefan Monnier
  2010-05-04 18:17   ` Drew Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2010-03-17 14:24 UTC (permalink / raw)
  To: help-gnu-emacs

> Why is the argument PREDICATE not used in read-file-name?
> For example
>   (read-file-name "Find file: " "~/" nil t nil (lambda (filename) nil))

Maybe because you're still using Emacs-22?
This part of the code has been changed in Emacs-23, and in my tests it
seems to do what you want.


        Stefan


PS: Note that this `predicate' argument is not handled quite right
currently, because it doesn't distinguish between "intermediate
completions to accept" and "final values to accept".  So if you want to
be able to complete "/u" to "/usr/", then you need to accept "/usr/" as
a valid candidate, even though you only wanted to allow this completion
to let the user complete its way to a .pdf file somewhere underneath
/usr.


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

* RE: read-file-name() doesn't care about PREDICATE argument
  2010-03-17 14:24 ` Stefan Monnier
@ 2010-05-04 18:17   ` Drew Adams
  0 siblings, 0 replies; 3+ messages in thread
From: Drew Adams @ 2010-05-04 18:17 UTC (permalink / raw)
  To: help-gnu-emacs

> > Why is the argument PREDICATE not used in read-file-name?
> >   (read-file-name "Find file: " "~/" nil t nil
> >                   (lambda (filename) nil))
> 
> Maybe because you're still using Emacs-22? This part of
> the code has been changed in Emacs-23, and in my tests it
> seems to do what you want.

(That example works in emacs -Q for Emacs 22 also - there are no possible
completions shown.)

> I have also tried the Icicles version
>   (icicle-read-file-name "Find file: " "~/" nil t nil
>                          (lambda (filename) nil))
> but it behaves exactly the same.

It is intended to act the same as vanilla Emacs wrt PREDICATE.
Both should work (as opposed to neither working ;-)).

> The following code works as expected, though:
>   (let ((icicle-must-pass-predicate (lambda (filename) nil)))
>         (icicle-read-file-name "Find file: " "~/" nil t nil
>                                (lambda (filename) nil)))
> 
> Why doesn't first two example like the last? And why does the icicle
> version provide this extra variable? It smells like a bug or a missing
> feature.

The Icicles variable `icicle-must-pass-predicate' is an _additional_ predicate.
It applies to any kind of completion. A similar but more specific variable
applies to only file-name completion: `icicle-file-predicate'.

These variables can be useful in programming. The latter is also a user option,
in case there is some general file-name filtering that someone always wants to
do. (There is a similar option for buffer names.)

The PREDICATE arg to `read-file-name' is available only for the code that
actually calls `read-file-name' (duh). If your code that wants to impose a
predicate calls existing code that calls `read-file-name' without a PREDICATE,
or if you interactively use an existing command that does that, then you have no
way to filter with your predicate.

That is, if the code that actually calls `read-file-name' did not forsee the
filtering you want, then you're out of luck.

That's the purpose of these Icicles variables: to let you do some global
filtering regardless of whatever filtering, if any, was provided by existing
code that calls `read-file-name' (or `completing-read'). Simply bind the
variable to the predicate you want. It will apply to completion calls within its
scope/extent.

http://www.emacswiki.org/emacs/Icicles_-_Global_Filters





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

end of thread, other threads:[~2010-05-04 18:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-17 11:49 read-file-name() doesn't care about PREDICATE argument Nordlöw
2010-03-17 14:24 ` Stefan Monnier
2010-05-04 18:17   ` Drew Adams

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.