unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Using a File index
@ 2007-02-05 17:13 HS
  2007-02-06  7:47 ` Kevin Rodgers
       [not found] ` <mailman.4082.1170748050.2155.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: HS @ 2007-02-05 17:13 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all
I use to open files using recursive find.
Now I just did a ruby script to generate a list of all sources on some
given folder.
My problem now is to parse this file and use it to open the file I'm
looking for.

file1.c = c:\blabla\prj1\file1.c
file2.c = c:\blabla\prj2\file2.c
file3.c = c:\srcs\file3.c

Anyone could give me a hint?
Thanks in advance!
HS

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  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>
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2007-02-06  7:47 UTC (permalink / raw)
  To: help-gnu-emacs

HS wrote:
> I use to open files using recursive find.
> Now I just did a ruby script to generate a list of all sources on some
> given folder.
> My problem now is to parse this file and use it to open the file I'm
> looking for.
> 
> file1.c = c:\blabla\prj1\file1.c
> file2.c = c:\blabla\prj2\file2.c
> file3.c = c:\srcs\file3.c
> 
> Anyone could give me a hint?

I think the answer is in the shell, not Emacs:

emacs $(ruby SCRIPT FOLDER | awk -F= '{print $2}')


-- 
Kevin Rodgers
Denver, Colorado, USA

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
       [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
  0 siblings, 2 replies; 11+ messages in thread
From: HS @ 2007-02-06 13:44 UTC (permalink / raw)
  To: help-gnu-emacs

On 6 fev, 04:47, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
> HS wrote:
> > I use to open files using recursive find.
> > Now I just did a ruby script to generate a list of all sources on some
> > given folder.
> > My problem now is to parse this file and use it to open the file I'm
> > looking for.
>
> > file1.c = c:\blabla\prj1\file1.c
> > file2.c = c:\blabla\prj2\file2.c
> > file3.c = c:\srcs\file3.c
>
> > Anyone could give me a hint?
>
> I think the answer is in the shell, not Emacs:
>
> emacs $(ruby SCRIPT FOLDER | awk -F= '{print $2}')
>
> --
> Kevin Rodgers
> Denver, Colorado, USA

That's nice, but it's solved now.
That solution of yours wouldn't open a new emacs?
And also I don't have awk here :) (winxp)
Tks anyway
Cheers
HS

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  2007-02-06 13:44   ` HS
@ 2007-02-07  9:16     ` Kevin Rodgers
  2007-02-08  6:44     ` Mathias Dahl
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2007-02-07  9:16 UTC (permalink / raw)
  To: help-gnu-emacs

HS wrote:
> On 6 fev, 04:47, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
>> I think the answer is in the shell, not Emacs:
>>
>> emacs $(ruby SCRIPT FOLDER | awk -F= '{print $2}')
> 
> That's nice, but it's solved now.
> That solution of yours wouldn't open a new emacs?

So use emacsclient instead of emacs.

> And also I don't have awk here :) (winxp)

http://gnuwin32.sourceforge.net/

-- 
Kevin Rodgers
Denver, Colorado, USA

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Mathias Dahl @ 2007-02-08  6:44 UTC (permalink / raw)
  To: help-gnu-emacs

"HS" <hugows@gmail.com> writes:

> That's nice, but it's solved now.

How was it solved?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  2007-02-08  6:44     ` Mathias Dahl
@ 2007-02-08 12:26       ` weber
  2007-02-09 17:31         ` Mathias Dahl
  0 siblings, 1 reply; 11+ messages in thread
From: weber @ 2007-02-08 12:26 UTC (permalink / raw)
  To: help-gnu-emacs

On 8 fev, 03:44, Mathias Dahl <brakjol...@gmail.com> wrote:
> "HS" <hug...@gmail.com> writes:
> > That's nice, but it's solved now.
>
> 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"))

The index file was made with a ruby script, and I update it manually
when there are some new files...
Cheers,
HS

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  2007-02-08 12:26       ` weber
@ 2007-02-09 17:31         ` Mathias Dahl
  2007-02-09 17:46           ` weber
  0 siblings, 1 reply; 11+ messages in thread
From: Mathias Dahl @ 2007-02-09 17:31 UTC (permalink / raw)
  To: help-gnu-emacs

"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!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  2007-02-09 17:31         ` Mathias Dahl
@ 2007-02-09 17:46           ` weber
  2007-02-09 17:53             ` weber
  2007-02-09 17:58             ` weber
  0 siblings, 2 replies; 11+ messages in thread
From: weber @ 2007-02-09 17:46 UTC (permalink / raw)
  To: help-gnu-emacs

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  2007-02-09 17:46           ` weber
@ 2007-02-09 17:53             ` weber
  2007-02-09 17:58             ` weber
  1 sibling, 0 replies; 11+ messages in thread
From: weber @ 2007-02-09 17:53 UTC (permalink / raw)
  To: help-gnu-emacs

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  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
  1 sibling, 1 reply; 11+ messages in thread
From: weber @ 2007-02-09 17:58 UTC (permalink / raw)
  To: help-gnu-emacs

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

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 <file.h> and hitting some key combination.. just an example)

-weber

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Using a File index
  2007-02-09 17:58             ` weber
@ 2007-02-10  8:09               ` Kevin Rodgers
  0 siblings, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2007-02-10  8:09 UTC (permalink / raw)
  To: help-gnu-emacs

weber wrote:
> 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
> 
> 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 <file.h> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-02-10  8:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).