From: Mathias Dahl <brakjoller@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Using a File index
Date: Fri, 09 Feb 2007 18:31:12 +0100 [thread overview]
Message-ID: <u1wkzme5b.fsf@gmail.com> (raw)
In-Reply-To: 1170937572.049993.63340@h3g2000cwc.googlegroups.com
"weber" <hugows@gmail.com> 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!
next prev parent reply other threads:[~2007-02-09 17:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-05 17:13 Using a File index HS
2007-02-06 7:47 ` Kevin Rodgers
[not found] ` <mailman.4082.1170748050.2155.help-gnu-emacs@gnu.org>
2007-02-06 13:44 ` HS
2007-02-07 9:16 ` Kevin Rodgers
2007-02-08 6:44 ` Mathias Dahl
2007-02-08 12:26 ` weber
2007-02-09 17:31 ` Mathias Dahl [this message]
2007-02-09 17:46 ` weber
2007-02-09 17:53 ` weber
2007-02-09 17:58 ` weber
2007-02-10 8:09 ` Kevin Rodgers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=u1wkzme5b.fsf@gmail.com \
--to=brakjoller@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).