[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Prompt for files with given extensions
From: |
Michael Heerdegen |
Subject: |
Re: Prompt for files with given extensions |
Date: |
Wed, 11 Feb 2015 16:35:53 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
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.