From: Dmitry Gutov Date: Thu, 3 Oct 2024 00:04:46 +0000 (+0300) Subject: Use Emacs Lisp xref backend in Lisp Help buffers X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3f634b0e45fa1f7aa82b61ce4c6741a7f92c38d6;p=emacs.git Use Emacs Lisp xref backend in Lisp Help buffers * lisp/help-fns.el (help-fns--setup-xref-backend): New function (bug#69462). (describe-function, describe-variable): Use it here. * lisp/emacs-lisp/cl-extra.el (cl-describe-type): And here. * lisp/progmodes/elisp-mode.el (xref-backend-definitions): Only infer namespace in emacs-lisp-mode (use 'any' otherwise). (cherry picked from commit c8ecd7fa0da8a597250989430ac2b2465419f18e) --- diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index 1b95b272c25..ecd35c9137c 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el @@ -733,6 +733,8 @@ PROPLIST is a list of the sort returned by `symbol-plist'. Call `cl--find-class' to get TYPE's propname `cl--class'" (cl--find-class type)) +(declare-function help-fns--setup-xref-backend "help-fns" ()) + ;;;###autoload (defun cl-describe-type (type &optional _buf _frame) "Display the documentation for type TYPE (a symbol)." @@ -754,6 +756,7 @@ Call `cl--find-class' to get TYPE's propname `cl--class'" ;; cl-deftype). (user-error "Unknown type %S" type)))) (with-current-buffer standard-output + (help-fns--setup-xref-backend) ;; Return the text we displayed. (buffer-string))))) diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 1aa9778da43..32a55e15e63 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -255,6 +255,11 @@ interactive command." fn)) (list fn))) +(defun help-fns--setup-xref-backend () + (add-hook 'xref-backend-functions #'elisp--xref-backend nil t) + (setq-local project-vc-external-roots-function #'elisp-load-path-roots) + (setq-local grep-filepattern-alist '((help-mode "*.el")))) + ;;;###autoload (defun describe-function (function) "Display the full documentation of FUNCTION (a symbol). @@ -289,6 +294,8 @@ handling of autoloaded functions." (princ " is ") (describe-function-1 function) (with-current-buffer standard-output + (help-fns--setup-xref-backend) + ;; Return the text we displayed. (buffer-string)))))) @@ -1516,6 +1523,7 @@ it is displayed along with the global value." (delete-char 1))))) (with-current-buffer standard-output + (help-fns--setup-xref-backend) ;; Return the text we displayed. (buffer-string)))))))) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 0d6d9eac26a..9ac52a21dcd 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -1003,7 +1003,9 @@ namespace but with lower confidence." (let ((sym (intern-soft identifier))) (when sym (let* ((pos (get-text-property 0 'pos identifier)) - (namespace (if pos + (namespace (if (and pos + ;; Reusing it in Help Mode. + (derived-mode-p 'emacs-lisp-mode)) (elisp--xref-infer-namespace pos) 'any)) (defs (elisp--xref-find-definitions sym)))