I am using GNU Emacs 26.3 on Ubuntu 19.10.
I have a directory full of Emacs Lisp files with the .el
file extension. All of them are loaded into the currently running Emacs. I can open up one of those files, put point on a function that is being called, and then use M-.
to go to that definition. That works. But when I use M-?
(which is bound to xref-find-references
) I get an error of the form:
user-error: No references found for: xxx
where xxx
was the symbol at point.
I thought this was due to not using a TAGS file, so I generated one using:
cd ~/my_emacs_lisp_dir1
etags -l lisp ../my_emacs_lisp_dir1/*.el ../my_emacs_lisp_dir2/*.el
And that did work as it produced a TAGS
file where I expected it to be which is in ~/my_emacs_lisp_dir1/TAGS
.
In Emacs, I visited that TAGS file using visit-tags-table
. And then tried M-?
on the symbol again, and it still failed with the above error.
I then executed xref-etags-mode
from within that same .el
buffer and tried again. Still I got the same error.
Opening up the TAGS file and searching for the symbol only turns up what I believe to be an indication of which file a symbol is defined in, but I don't see how it could record references to where that symbol is referenced from. So that may be the problem, and if so, how do I make it tell me which functions and files refer to the symbol at point?
Update 1: It works for standalone files, but not in my Git-controlled HOME directory
I noticed that it does work if I do something silly like this:
rm -rf /tmp/xref-test-dir
mkdir -p /tmp/xref-test-dir
cd /tmp/xref-test-dir
cat > func-1.el <<'EOF'
(defun xxx-func-1 ()
(xxx-func-2))
EOF
cat > func-2.el <<'EOF'
(defun xxx-func-2 ()
(message "xxx-func-2 called"))
EOF
etags -l lisp *.el
Then go to each of the two .el files, and run eval-buffer
on them and then point point on the call to xxx-func-2
and it at least did something that I think is correct: It showed a buffer with this info:
/tmp/xref-test-dir/func-1.el
2: (xxx-func-2))
/tmp/xref-test-dir/func-2.el
1: (defun xxx-func-2 ()
2: (message "xxx-func-2 called"))
I noticed that somewhere along the way I was prompted for a project directory and I supplied it /tmp/xref-test-dir
.
But I got no such prompting from when I did it inside my ~/my_emacs_lisp_dir1
directory.
I dug even deeper into the xref-backend-references
function, and found some code dealing with projects. So I went back to the .el file inside ~/my_emacs_lisp_dir1
directory, and ran this via eval-expression
:
(project--find-in-directory ".")
and it returned this:
(vc . "~/")
that sort of makes sense because both ~/my_emacs_lisp_dir1
and ~/my_emacs_lisp_dir2
are within a Git repo.
But I'm still stuck because I don't know how to tell "it" to just look into those two directories, or even look into the files in that same directory.
load-path
?xref-backend-references
searches the "current project" and the external roots, which in this case are the list returned byelisp-load-path-roots
, which see.