[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using a File index
From: |
weber |
Subject: |
Re: Using a File index |
Date: |
9 Feb 2007 09:53:31 -0800 |
User-agent: |
G2/1.0 |
On 9 fev, 14:46, "weber" <hug...@gmail.com> wrote:
> On 9 fev, 14:31, Mathias Dahl <brakjol...@gmail.com> wrote:
>
>
>
> > "weber" <hug...@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!
>
> 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
Oh and I was (am) using a full path for the file name, I just removed
it because I didn't wanted to reveal my path (don't ask me why, i
can't think of a good reason now heh... )
Regards,
weber
- Using a File index, HS, 2007/02/05
- Re: Using a File index, Kevin Rodgers, 2007/02/06
- Message not available
- Re: Using a File index, HS, 2007/02/06
- Re: Using a File index, Kevin Rodgers, 2007/02/07
- Re: Using a File index, Mathias Dahl, 2007/02/08
- Re: Using a File index, weber, 2007/02/08
- Re: Using a File index, Mathias Dahl, 2007/02/09
- Re: Using a File index, weber, 2007/02/09
- Re: Using a File index,
weber <=
- Re: Using a File index, weber, 2007/02/09
- Re: Using a File index, Kevin Rodgers, 2007/02/10