From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: Using a File index Date: Sat, 10 Feb 2007 01:09:08 -0700 Message-ID: References: <1170695630.175468.143090@p10g2000cwp.googlegroups.com> <1170769489.721366.107320@a34g2000cwb.googlegroups.com> <1170937572.049993.63340@h3g2000cwc.googlegroups.com> <1171043207.265891.146330@k78g2000cwa.googlegroups.com> <1171043912.164215.315170@l53g2000cwa.googlegroups.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 1171094995 22293 80.91.229.12 (10 Feb 2007 08:09:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 10 Feb 2007 08:09:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 10 09:09:52 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 1HFnIu-0006UM-CC for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Feb 2007 09:09:52 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HFnIt-0000J1-Og for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Feb 2007 03:09:51 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HFnIe-0000Iw-RD for help-gnu-emacs@gnu.org; Sat, 10 Feb 2007 03:09:36 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HFnIc-0000Ik-AC for help-gnu-emacs@gnu.org; Sat, 10 Feb 2007 03:09:35 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HFnIc-0000Ih-30 for help-gnu-emacs@gnu.org; Sat, 10 Feb 2007 03:09:34 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HFnIb-0006jT-GA for help-gnu-emacs@gnu.org; Sat, 10 Feb 2007 03:09:33 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HFnIV-0000Rz-VG for help-gnu-emacs@gnu.org; Sat, 10 Feb 2007 09:09:27 +0100 Original-Received: from c-24-9-156-178.hsd1.co.comcast.net ([24.9.156.178]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 10 Feb 2007 09:09:27 +0100 Original-Received: from kevin.d.rodgers by c-24-9-156-178.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 10 Feb 2007 09:09:27 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 89 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: c-24-9-156-178.hsd1.co.comcast.net User-Agent: Thunderbird 1.5.0.9 (Macintosh/20061207) In-Reply-To: <1171043912.164215.315170@l53g2000cwa.googlegroups.com> X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) 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:41052 Archived-At: weber wrote: > On 9 fev, 14:46, "weber" wrote: >> On 9 fev, 14:31, Mathias Dahl wrote: >> >> >> >>> "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! >> Oh, that functionality was already implemented! Why that doesn't >> surprise me ? :) >> Hey Mathias tks for the alternatives, I'll switch to one of those!! >> Cheers, >> weber > > Hmm, thinking about it... those versions without ARG are less > interesting because I can't use them in a function like this, right? > > (defun indexed-find-current-word () > " Find file under cursor " > (interactive) > (indexed-find-3 (current-word))) > > (for example if I wanted to follow files by putting the cursor over an > #include and hitting some key combination.. just an example) Right: the call to completing-read should be moved within the interactive form, to provide the value of the FILE argument _when called interactively_. -- Kevin Rodgers Denver, Colorado, USA