I use xref-find-definition
to look up the definition of a symbol name. When I call xref-find-definition
, I want to Emacs to automatically find and load an appropriately named etags file. For this purpose, I have a function, open-tags-file
:
(defadvice xref-find-definitions (before before-xref-find-definitions activate)
(open-tags-file))
(defun open-tags-file ()
(interactive)
(if (booleanp tags-file-name)
(when (file-exists-p "my_tag_file")
(visit-tags-table "my_tag_file"))))
)
)
This works fine when I run xref-find-definitions
with the cursor already over an existing symbol name. It also works if I do not have the cursor over a symbol name -- Emacs will prompt me to enter a symbol name, such as "CreateFood". Either way, The tags file is automatically loaded, and then the symbol is looked up.
However, when Emacs prompts me to enter a symbol name, I want to be able to type a partial symbol name, such as "Cre", and then press Tab and have "CreateFood" be auto-completed. If I do that, Emacs will prompt me to load the tag file, and it will expect it to have the name TAGS. This means that my defadvice xref-find-definitions
is not being run before Emacs prompts me to enter the symbol name, it is only run after that symbol name is entered.
Is there a way to run open-tags-file
before the symbol name is entered, so that I can auto-complete "Cre" into "CreateFood" when entering the symbol name to find the definition of?