* Prompt for files with given extensions
@ 2015-02-11 10:17 Robin Neatherway
2015-02-11 15:00 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Robin Neatherway @ 2015-02-11 10:17 UTC (permalink / raw)
To: help-gnu-emacs
I would like my function to prompt only for files with a given
extension. I have a source file, say foo.c, and would like to load the
corresponding test results file, say foo.results. However, if there
are multiple tests for foo.c, then they may have different filenames.
At the moment I use `read-file-name` with `foo.results` as a default,
but I would like to filter the possible completions by file extension.
Is this possible?
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Prompt for files with given extensions
2015-02-11 10:17 Prompt for files with given extensions Robin Neatherway
@ 2015-02-11 15:00 ` Drew Adams
2015-02-11 15:35 ` Michael Heerdegen
2015-02-12 2:41 ` Robert Thorpe
2 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2015-02-11 15:00 UTC (permalink / raw)
To: Robin Neatherway, help-gnu-emacs
> I would like my function to prompt only for files with a given
> extension.
If you use Icicles, you can bind one of these variables in your
function, to control which file-name candidates are presented:
`icicle-file-match-regexp'
`icicle-file-no-match-regexp'
`icicle-file-predicate'
http://www.emacswiki.org/emacs/Icicles_-_Global_Filters#icicle-file-match-regexp
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Prompt for files with given extensions
2015-02-11 10:17 Prompt for files with given extensions Robin Neatherway
2015-02-11 15:00 ` Drew Adams
@ 2015-02-11 15:35 ` Michael Heerdegen
2015-02-16 10:47 ` Robin Neatherway
2015-02-12 2:41 ` Robert Thorpe
2 siblings, 1 reply; 5+ messages in thread
From: Michael Heerdegen @ 2015-02-11 15:35 UTC (permalink / raw)
To: help-gnu-emacs
Robin Neatherway <robin.neatherway@gmail.com> writes:
> At the moment I use `read-file-name` with `foo.results` as a default,
> but I would like to filter the possible completions by file extension.
> Is this possible?
You can just use the PREDICATE arg of `read-file-name' for that:
--8<---------------cut here---------------start------------->8---
;; -*- lexical-binding: t -*-
(defun my-filter-file-by-extension (extension)
(lambda (file) (let ((file-extension (file-name-extension file)))
(and (stringp file-extension)
(string= file-extension extension)))))
;; Use like this:
(read-file-name
"File: " "~/" nil t nil
(my-filter-file-by-extension "txt"))
--8<---------------cut here---------------end--------------->8---
Michael.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Prompt for files with given extensions
2015-02-11 10:17 Prompt for files with given extensions Robin Neatherway
2015-02-11 15:00 ` Drew Adams
2015-02-11 15:35 ` Michael Heerdegen
@ 2015-02-12 2:41 ` Robert Thorpe
2 siblings, 0 replies; 5+ messages in thread
From: Robert Thorpe @ 2015-02-12 2:41 UTC (permalink / raw)
To: Robin Neatherway; +Cc: help-gnu-emacs
Robin Neatherway <robin.neatherway@gmail.com> writes:
> I would like my function to prompt only for files with a given
> extension. I have a source file, say foo.c, and would like to load the
> corresponding test results file, say foo.results. However, if there
> are multiple tests for foo.c, then they may have different filenames.
>
> At the moment I use `read-file-name` with `foo.results` as a default,
> but I would like to filter the possible completions by file extension.
> Is this possible?
Another possibility is to get the user to choose using a dired buffer.
E.g. (dired "~/foo/*.txt")
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Prompt for files with given extensions
2015-02-11 15:35 ` Michael Heerdegen
@ 2015-02-16 10:47 ` Robin Neatherway
0 siblings, 0 replies; 5+ messages in thread
From: Robin Neatherway @ 2015-02-16 10:47 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
Great, thanks a lot! I missed that option in the documentation.
On Wed, Feb 11, 2015 at 3:35 PM, Michael Heerdegen
<michael_heerdegen@web.de> wrote:
> Robin Neatherway <robin.neatherway@gmail.com> writes:
>
>> At the moment I use `read-file-name` with `foo.results` as a default,
>> but I would like to filter the possible completions by file extension.
>> Is this possible?
>
> You can just use the PREDICATE arg of `read-file-name' for that:
>
> --8<---------------cut here---------------start------------->8---
> ;; -*- lexical-binding: t -*-
>
> (defun my-filter-file-by-extension (extension)
> (lambda (file) (let ((file-extension (file-name-extension file)))
> (and (stringp file-extension)
> (string= file-extension extension)))))
>
> ;; Use like this:
> (read-file-name
> "File: " "~/" nil t nil
> (my-filter-file-by-extension "txt"))
>
> --8<---------------cut here---------------end--------------->8---
>
>
> Michael.
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-02-16 10:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-11 10:17 Prompt for files with given extensions Robin Neatherway
2015-02-11 15:00 ` Drew Adams
2015-02-11 15:35 ` Michael Heerdegen
2015-02-16 10:47 ` Robin Neatherway
2015-02-12 2:41 ` Robert Thorpe
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).