Reputation: 22566
Is there a way in Emacs to find out which other places in the code call a specific function? With my current setup (GNU emacs 23.1.1, C codebase), I normally have to search the whole codebase for the function name to see which other functions call it. It would be nice if I could efficiently display all the names of the functions that call this specific function that I'm looking at.
Upvotes: 15
Views: 6105
Reputation: 87214
You can use semantic-symref
function (C-c , G
) from CEDET package. It can use GNU Global or CTags databases to find callers if they exist. It could also parse sources to find occurrences.
Upvotes: 12
Reputation: 6070
here is a snippet from my old .emacs file
it does: ask for thing to find from etags-tagfile (find-tag-tag) grep for it according to mode
(defun find-caller (tagname)
"Find occurences of tagname in files in the current directory
matching extension of current file."
(interactive (list (find-tag-tag "Find caller: ")))
(let ((cmd "grep -n "))
(cond
((member major-mode '(lisp-mode cmulisp-mode))
(grep (concat cmd "-i '" tagname "' *.lisp")))
((eq major-mode 'c-mode)
(grep (concat cmd "'" tagname "' *.[ch]")))
((member major-mode '(latex-mode tex-mode))
(grep (concat cmd "-i '" tagname "' *.tex")))
((eq major-mode 'emacs-lisp-mode)
(grep (concat cmd "'" tagname "' *.el")))
(t (grep (concat cmd "'" tagname "' *"))))))
Upvotes: 1
Reputation: 5230
I use xcscope
for this. It's a library that makes Emacs interact with the external cscope
tool.
After setup, you can use cscope-find-functions-calling-this-function
to get a list of source code destinations that call a certain function.
http://www-inst.eecs.berkeley.edu/~cs186/fa05/debugging/xcscope.el http://www.emacswiki.org/emacs/CScopeAndEmacs
Upvotes: 2