Skip to content

Instantly share code, notes, and snippets.

@rossabaker
Created September 29, 2020 14:30
Show Gist options
  • Save rossabaker/00e44a811c2021054bc4789c5d6837f7 to your computer and use it in GitHub Desktop.
Save rossabaker/00e44a811c2021054bc4789c5d6837f7 to your computer and use it in GitHub Desktop.
(defun ross/xref-find-definitions-etags-fallback (identifier)
"Find the definition of the identifier at point.
With prefix argument or when there's no identifier at point,
prompt for it.
If the primary xref-backend fails, fall back to the etags backend."
(interactive (list (xref--read-identifier "Find definitions of: ")))
(condition-case nil
(xref-find-definitions identifier)
(user-error
(let ((xref-backend-functions '(etags--xref-backend t)))
(xref--find-definitions identifier nil)))))
;; Without this, we get an interactive prompt
(add-to-list 'xref-prompt-for-identifier 'ross/xref-find-definitions-etags-fallback t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment