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

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

Re: Prompt for files with given extensions


From: Robin Neatherway
Subject: Re: Prompt for files with given extensions
Date: Mon, 16 Feb 2015 10:47:08 +0000

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



reply via email to

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