From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Robin Neatherway Newsgroups: gmane.emacs.help Subject: Re: Prompt for files with given extensions Date: Mon, 16 Feb 2015 10:47:08 +0000 Message-ID: References: <878ug4mpeu.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1424083689 28531 80.91.229.3 (16 Feb 2015 10:48:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Feb 2015 10:48:09 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 16 11:48:09 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YNJDk-0002SP-0L for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Feb 2015 11:48:08 +0100 Original-Received: from localhost ([::1]:38744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNJDe-0004Vo-DB for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Feb 2015 05:48:02 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44103) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNJDT-0004VY-3d for help-gnu-emacs@gnu.org; Mon, 16 Feb 2015 05:47:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNJDS-00064L-3T for help-gnu-emacs@gnu.org; Mon, 16 Feb 2015 05:47:51 -0500 Original-Received: from mail-wg0-x231.google.com ([2a00:1450:400c:c00::231]:48843) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNJDR-00062U-Si for help-gnu-emacs@gnu.org; Mon, 16 Feb 2015 05:47:50 -0500 Original-Received: by mail-wg0-f49.google.com with SMTP id l18so28642058wgh.8 for ; Mon, 16 Feb 2015 02:47:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=MJDZXkDCVL3RCWXqGQJoNbabtd/4kugsiuTbmNQpvs8=; b=bt6qyj756rQAMM/eMmHek0f76vsKaORbKPVM9HoECokqGGAIT6s8bRbRnWRw9xg6pp AbkvrFQv9W6iqSiGE14vaBS31jBCLiFZyuk5t6EEDGEckXzNMXCuO0Jca4Q4LdtLwdEg grTHDTTFG+t4JyHomt55S4tV28ot4rB1dnIdGC3PSuPyqcgsH9/4rj9VOeg6CZ6I2QHF H0ji49xOXx5y38zhhSE3TVNoYV4ZLiLncgVUJAcq3YWiOFWFN1/nj2QbLqQl4ANzqrHM 5+9VE0s+GtwNY4kD7cXSwQd3EMVv6ktUZfbok4GLJtZtZu7V9dC19NpXt9XZhN1x9jHX TlNA== X-Received: by 10.194.178.161 with SMTP id cz1mr31704909wjc.102.1424083668439; Mon, 16 Feb 2015 02:47:48 -0800 (PST) Original-Received: by 10.27.34.9 with HTTP; Mon, 16 Feb 2015 02:47:08 -0800 (PST) In-Reply-To: <878ug4mpeu.fsf@web.de> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::231 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:102744 Archived-At: Great, thanks a lot! I missed that option in the documentation. On Wed, Feb 11, 2015 at 3:35 PM, Michael Heerdegen wrote: > Robin Neatherway 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. > >