help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: read-file-name() doesn't care about PREDICATE argument


From: Drew Adams
Subject: RE: read-file-name() doesn't care about PREDICATE argument
Date: Tue, 4 May 2010 11:17:33 -0700

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]