[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: searching file from emacs
From: |
Jonathan Rockway |
Subject: |
Re: searching file from emacs |
Date: |
Thu, 14 Feb 2008 23:25:36 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
* On Thu, Feb 14 2008, marcmj wrote:
> So if I have the source example.f where I have the following line:
> call other_routine(a, b)
>
> I would like to place the cursor on "other_routine" (anywhere in this
> routine name) then hit a key and the code will search for other_routine.f in
> a set of pre-defined directories, then open other_routine.f in the emacs
> window.
This sounds a lot like `find-tag' in `etags.el'. You might want to read
that first. In fact, I'm pretty sure find-tag can do what you want to
do, as long as you run some code before find-tag that sets up the tags
table correctly and then visits it.
Someone on #emacs provided me with the following code the other day:
;;; Järneström Jonas <Jonas.Jarnestrom AT ki.ericsson.se>
;;; A smarter find-tag that automagically reruns etags when it cant
;;; find a requested item and then makes a new try to locate it.
(defadvice find-tag (around refresh-etags activate)
"Rerun etags and reload tags if tag not found and redo find-tag.
If buffer is modified, ask about save before running etags."
(let* ((extension (file-name-extension (buffer-file-name))))
(condition-case err
ad-do-it
(error (and (buffer-modified-p)
(not (ding))
(y-or-n-p "Buffer is modified, save it? ")
(save-buffer))
(er-refresh-etags extension)
ad-do-it))))
(defun er-refresh-etags (extension)
"Run etags on all peer files in current dir and reload them silently."
(interactive)
(when (not found-perl-tags)
(shell-command (format "etags *.%s" extension))
(let ((tags-revert-without-query t)) ; don't query, revert silently
(visit-tags-table default-directory nil))))
This tries to find a tag normally, then if that fails, it builds a tags
table and tries again. Basically, you'll probably want to modify this
to run a different command based on the major mode that you want this to
work in. I do this for cperl-mode buffers:
(shell-command (format "find %s | grep pm$ | etags - -o %s" root
tags))
`root' is the root of my project, `tags' is root/TAGS basically. I can
provide more detail if you need it.
Regards,
Jonathan Rockway