- You should use the new advice system `nadvice` instead of the old one.
xref-find-definitionsprompts the user already in its `interactive-form`. So you need to run `open-tags-file` in the
interactive-formof your advice for the case that
xref-find-definitionsis called interactively.
- I use the interactive specification of
xref-find-definitionsof emacs 25.3.1 in
my-xref-find-definitions-interactive-spec. It may be that you need to adapt that to your emacs version. See the comment in the code. A variant would be to query the interactive form of
xref-find-definitionswith the help of function
interactive-form. But that would complicate the code.
- The code is untested. Please test it for yourself and comment whether it is working for you or not.
You usage of
tags-file-namelooks a bit strange. I think youyour test should be
(unless (stringp tags-file-name) ...). That would be more descriptive.
(require 'xref) (defun open-tags-file () "Use \"my_tag_file\" as tag file for xref." (interactive) (unless (stringp tags-file-name) (when (file-exists-p "my_tag_file") (visit-tags-table "my_tag_file")))) (defun my-xref-find-definitions-interactive-spec () "Interactive form for `open-tags-file'." (open-tags-file) ;; The following is the interactive specification of `xref-find-definitions' in emacs 25.3.1. ;; It may be that you need to adapt it to your emacs version. (list (xref--read-identifier "Find definitions of: "))) (defun my-xref-find-definitions-before-ad (&rest _args) "Advice for `xref-find-definitions' that handles the \"my_tag_file\"." (interactive (my-xref-find-definitions-interactive-spec)) (open-tags-file)) (advice-add 'xref-find-definitions :before #'my-xref-find-definitions-before-ad)
|2||added 1 character in body|