help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replacing find-tag with xref


From: R. Diez
Subject: Re: Replacing find-tag with xref
Date: Thu, 2 May 2019 11:34:40 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1


This deprecation has now become a more serious issue, because etags.el is no 
longer present in a convenient package repository, like Emacs'
default one or MELPA.

Um, isn't it still in master?

Sorry, in the meantime I have realised that it was actually package 
etags-select, which was removed from MELPA.


I have managed to come up with alternative implementations for find-tag and etags-select-find-tag-at-point . In case it helps anybody, the code is at the bottom.

Incidentally, I think I found a small bug: when xref-find-definitions prompts, and you press Enter (provide an empty string to look for), it hangs with 100 % CPU usage.



; find-tag has been deprecated in emacs 25.1, and package etags-select has been 
removed from MELPA,
; so I am switching now to xref-find-definitions.
;   (global-set-key [M-f11] 'etags-select-find-tag-at-point)
;
; Alternatively, we could use jump-to-definition-at-point-only-from-tags-file.
(global-set-key [M-f11] 'jump-to-definition-at-point)


(defun jump-to-definition-at-point () ""
  (interactive)

  (let* ((thing (xref-backend-identifier-at-point 'etags)))

    (unless thing
      (error "No identifier found at point."))

      ; Alternatively, we could use xref-find-definitions-other-window.
      (xref-find-definitions thing)
  )
)

; This routine makes xref-find-definitions use only the TAGS file. Otherwise, 
in Lisp mode,
; it would not use the TAGS file at all, but another backend that uses dynamic 
information to find symbols.
; That would also be the case for other modes in any future if new xref 
backends are added to Emacs.
;
; An alternative to this routine would be to turn the xref-etags-mode on 
globally.
; But then we may want to use other backends in other scenarios.
;
; Yet another way would be (add-hook 'emacs-lisp-mode-hook #'xref-etags-mode),
; because the lisp mode is the only thing as of Emacs 26 that uses another 
backend.
; But again, that can change in the future.

(defun jump-to-definition-at-point-only-from-tags-file () ""
  (interactive)

  (let ((xref-backend-functions '(etags--xref-backend)))
    (jump-to-definition-at-point))
)


(defun jump-to-definition () ""
  (interactive)
  (let ((current-prefix-arg '(1))) ; With a prefix argument, 
xref-find-definitions will always prompt.
    (call-interactively 'xref-find-definitions)
  )
)


(defun jump-to-definition-only-from-tags-file () ""
  (interactive)

  (let ((xref-backend-functions '(etags--xref-backend)))
    (jump-to-definition))
)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]