[comp.emacs] How to find 'defuns' in GNU Emacs source

weiner@novavax.UUCP (Bob Weiner) (07/28/88)

To find the defun associated with any GNU Emacs function follow these
steps at the shell level:

  1.  cd <EMACS-DIR>/lisp

  2.  <EMACS-DIR>/etc/etags *.el ../src/*.[ch]

	This gets all function definitions written in lisp or C.

  3.  From within emacs:

	M-x visit-tags-file <RTN> <EMACS-DIR>/lisp/TAGS <RTN>

	M-. <FUNCTION-NAME> <RTN>   ;; M-. = find-tag

	emacs will find the file that the function is defined in and
	bring it up in a buffer.

  4.  See the GNU Emacs manual section on Tags for more help.



			Bob Weiner
			novavax!mopdsrmc!weiner 

mesard@bbn.com (Wayne Mesard) (07/29/88)

From article <638@novavax.UUCP>, by weiner@novavax.UUCP (Bob Weiner):
> 
> To find the defun associated with any GNU Emacs function follow these
> steps at the shell level:
> 
>   1.  cd <EMACS-DIR>/lisp
> 
>   2.  <EMACS-DIR>/etc/etags *.el ../src/*.[ch]
> 
> 	This gets all function definitions written in lisp or C.

To add to Bob's excellent idea, I've whipped up the enclosed function.
It does tag searches on Emacs source while preserving the current tags
environment.  (So you can interleave tags searches on GNU code and your
own code.)

Note that the path to the Emacs tags table is hard-wired (in the first
setq).  You may need to change that.

I have this bound to C-c . in my .emacs.

Enjoy.

===============================SNIP==========================

(autoload 'find-tag-tag "tags"
	  "This hack is here because there's no provide in tags.el!")

(defvar last-emacs-tag nil
  "Tag found by the last find-emacs-tag.")

(defun find-emacs-tag (emacs-tagname &optional next other-window)
  "Invoke find-tag on EMACS-TAGNAME using the Emacs tag
table.  The state of the tags variables (tags-file-name and
last-tag) are preserved so that a user can interleave calls
to find-tag and find-emacs-tag.
 If second arg NEXT is non-nil (interactively, with prefix
arg), searches for the next tag in the tag table that
matches the tagname used in the previous find-emacs-tag."
  (interactive (if current-prefix-arg
		   '(nil t)
		 (find-tag-tag "Find Emacs tag: ")))
  (let ((old-tags-file-name tags-file-name)
	(old-last-tag last-tag))
    (setq tags-file-name "/usr/local/emacs/lisp/TAGS"
	  last-tag last-emacs-tag)
    (unwind-protect
	(find-tag emacs-tagname next other-window)
      (setq last-emacs-tag last-tag
	    last-tag old-last-tag
	    tags-file-name old-tags-file-name)
      )
))


-- 
unsigned *Wayne_Mesard();        MESARD@BBN.COM           BBN, Cambridge, MA

   [B]oth [Democratic] candidates are fluent in Spanish; it remains to be
   seen if one of the Republican candidates will be fluent in English.

					-George Will

Ram-Ashwin@cs.yale.edu (Ashwin Ram) (07/29/88)

In article <27626@bbn.COM>, mesard@bbn (Wayne Mesard) writes:
> It does tag searches on Emacs source while preserving the current tags
> environment.  (So you can interleave tags searches on GNU code and your
> own code.)
>
> (defun find-emacs-tag (emacs-tagname &optional next other-window)
>   (interactive ...)
>   (let ((old-tags-file-name tags-file-name)
> 	(old-last-tag last-tag))
>     (setq tags-file-name "/usr/local/emacs/lisp/TAGS"
> 	  last-tag last-emacs-tag)
>     (unwind-protect
> 	(find-tag emacs-tagname next other-window)
>       (setq last-emacs-tag last-tag
> 	    last-tag old-last-tag
> 	    tags-file-name old-tags-file-name)
>       )
> ))

I like the idea; I use something similar myself but I hadn't thought of the
last-tag idea.  However, to improve on this code, one could do:

        (interactive ...)
        (let ((tags-file-name "/usr/local/emacs/lisp/TAGS")
              (last-tag last-emacs-tag))
           (find-tag emacs-tagname next other-window)
           (setq last-emacs-tag last-tag))

This is a lot simpler, doesn't require the old-* variables, and will do the same
thing.  There is no need to do the setq's explicitly since that's part of LET's job.

-- Ashwin.

ARPA:    Ram-Ashwin@cs.yale.edu
UUCP:    {decvax,ucbvax,harvard,cmcl2,...}!yale!Ram-Ashwin
BITNET:  Ram@yalecs