From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mathias Dahl Newsgroups: gmane.emacs.help Subject: Re: Using a File index Date: Fri, 09 Feb 2007 18:31:12 +0100 Message-ID: References: <1170695630.175468.143090@p10g2000cwp.googlegroups.com> <1170769489.721366.107320@a34g2000cwb.googlegroups.com> <1170937572.049993.63340@h3g2000cwc.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1171042972 10284 80.91.229.12 (9 Feb 2007 17:42:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 9 Feb 2007 17:42:52 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 09 18:42:47 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 1HFZln-0008El-5s for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Feb 2007 18:42:47 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HFZlm-0007xG-Lj for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Feb 2007 12:42:46 -0500 Original-Path: shelby.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 74 Original-X-Trace: individual.net DO38GCxOaKTke7gLjN46LwWouFhNGcg6Jlimr2q33PGB1wCyKj User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.92 (windows-nt) Cancel-Lock: sha1:/6xgwCFKaJCzObwfRTtw2tfMrqA= Original-Xref: shelby.stanford.edu gnu.emacs.help:145426 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:41031 Archived-At: "weber" writes: >> How was it solved? > > With this code: > (defun indexed-find (file) > (interactive "MFilename: ") > (find-file "my_file_index.txt") > (if (re-search-forward (concat file " = ") nil t 1) > (progn > (setq beg (point)) > (end-of-line) > (setq end (point)) > (find-file (buffer-substring beg end))) > (message "File not found!")) > (kill-buffer "my_file_index.txt")) I had some free time and could not resist trying out some alternatives... :) Alternative 1: This is basically your code, just written a bit differently: (defun indexed-find-2 (file) (interactive "MFilename: ") (with-temp-buffer (insert-file-contents "my_file_index.txt") (if (search-forward-regexp (format "%s = \\(.*\\)" file) nil t) (find-file (match-string 1)) (message "File not found!")))) You might want to use the full path or a variable in the file name above. Alternative 2: Another way to do what you want, using completion. (defun indexed-find-3 () (interactive) (let* ((file-data (with-temp-buffer (insert-file-contents "my_file_index.txt") (buffer-substring (point-min) (point-max)))) (rows (split-string file-data "\n")) (file (completing-read "File: " rows))) (if (string-match "\\(.*\\) = \\(.*\\)$" file) (find-file (match-string 2 file)) (message "Could not find a file on that row")))) Or, same code, but a but harder to read maybe: (defun indexed-find-4 () (interactive) (let ((file (completing-read "File: " (split-string (with-temp-buffer (insert-file-contents "my_file_index.txt") (buffer-substring (point-min) (point-max))) "\n")))) (if (string-match "\\(.*\\) = \\(.*\\)$" file) (find-file (match-string 2 file)) (message "Could not find a file on that row")))) > The index file was made with a ruby script, and I update it manually > when there are some new files... You might also want to have a look at using Emacs file-cache (http://www.emacswiki.org/cgi-bin/wiki/FileNameCache) or similar functionality. Happy hacking!