From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Denis Bueno" Newsgroups: gmane.emacs.help Subject: Interactively finding file in a list of directories Date: Fri, 9 Mar 2007 10:52:13 -0500 Message-ID: <6dbd4d000703090752q5067f8e3i69d74d07d9cb51fd@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1173455902 15872 80.91.229.12 (9 Mar 2007 15:58:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 9 Mar 2007 15:58:22 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 09 16:58:17 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HPhTg-0007ma-FI for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Mar 2007 16:58:08 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HPhTj-000620-02 for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Mar 2007 10:57:59 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HPhSj-0005kZ-QS for help-gnu-emacs@gnu.org; Fri, 09 Mar 2007 10:56:57 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HPhSg-0005jU-3T for help-gnu-emacs@gnu.org; Fri, 09 Mar 2007 10:56:57 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HPhSf-0005jM-RE for help-gnu-emacs@gnu.org; Fri, 09 Mar 2007 10:56:53 -0500 Original-Received: from ug-out-1314.google.com ([66.249.92.173]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HPhSB-0007So-6A for help-gnu-emacs@gnu.org; Fri, 09 Mar 2007 10:56:32 -0500 Original-Received: by ug-out-1314.google.com with SMTP id j3so1538054ugf for ; Fri, 09 Mar 2007 07:52:15 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=p0L2sW1Geow5VVzj6OiElLt991/zphyU0HWnSbGs2JsOs8kBUMDe1Wbp0s49/50ga3s3S6cc5eUU0IyiH+lxLwNcoU7IwFLdnB9P+VbxGTTIZU6opd/uvfIKk0ItNh0bvdvIVF50rLp46clq8i1fLp3oA+QvPBcbu7XiCtb3NV4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=D2Gn3hlIlV6B+QkI9z5MdyvwLAc6ViEULUYUUUdZfLgW2xv04xjLMHiAQdpydApMOJeHZR9tMKQLk3dZS57bFw7wCYtugTJjWi2oRv4RLskB88zUt7P4JmVSBeJ4NuXc6fH0VGWsj2p0JcbU9/fODFq7kEqPIxmxPHEYR0UJCKk= Original-Received: by 10.114.79.1 with SMTP id c1mr580413wab.1173455533949; Fri, 09 Mar 2007 07:52:13 -0800 (PST) Original-Received: by 10.114.195.2 with HTTP; Fri, 9 Mar 2007 07:52:13 -0800 (PST) Content-Disposition: inline X-detected-kernel: Linux 2.4-2.6 (Google crawlbot) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:41833 Archived-At: All- I'm seeking advice on how to improve a bit of code I've written. As the subject says, I would like to be able to visit a file by its name but search a set of default directories, rather than having to specify the directory. (This ability exists in Eclipse under the name "Find resource.") For example, assume there are 4 different files all named "find.jsp" in different directories, and I would like to find a particular one. I would do M-x find-resource, type "find", hit TAB, it I would see a list that looks something like: ,---- | foobar/find.jsp | baz/find.jsp | duh/find.jsp | blah/find.jsp `---- I would then C-x o to the completion buffer, hit Return on the file I want, and Emacs will visit it. I have some code that works as a first approximation, but it has a few bugs: 1. (the major problem) The completion folds all results which have the same filename. Assuming the above example, the completion buffer displays "find.jsp" but I have no idea which actual file that corresponds to. There are no other listings of "find.jsp" in the completion buffer. 2. It doesn't handle suffixes properly. Assuming there were a file "baz/find.txt" in the filesystem of previous example, it would be listed. Does anyone have any advice on how I can fix the above bugs? -Denis ;; --- `find-resource' kind of like in Eclipse. ;; BUGS: for some reason the completing buffer shows filenames that have an ;; extension *not* in `find-resource-suffixes'. (defvar find-resource-paths (list "~/") "*List of paths to search when using `find-resource'; format it like `load-path'.") ;(make-variable-buffer-local 'find-resource-paths) (defvar find-resource-suffixes (list "") "*List of file suffixes used when doing completion in `find-resource'.") (defun find-resource-add-path (path) "Add a path used by `find-resource'." (interactive "DPath: ") (add-to-list 'find-resource-paths path)) (defun find-resource (filename) "Find a file `filename' in `find-resource-paths', using `find-resource-suffixes', and visit it. The structure of `find-resource' cribbed from `load-library'." (interactive (list (completing-read "Find resource: " 'locate-file-completion (cons find-resource-paths find-resource-suffixes)))) (let ((f (locate-file filename find-resource-paths (cons "" find-resource-suffixes)))) (if f (find-file f) (message "Could not find `%S' after completing completing-read (bug)" filename))))