From: Eshel Yaron Date: Sat, 18 Jan 2025 19:52:48 +0000 (+0100) Subject: Teach elisp-mode.el to find widget definitions X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a04defca0ae3eae7f83a7a1717d5593b3977c21e;p=emacs.git Teach elisp-mode.el to find widget definitions --- diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index d51d3c87dea..e0c713a4223 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el @@ -76,6 +76,9 @@ Please send improvements and fixes to the maintainer." :group 'find-function :version "21.1") +(defvar find-widget-regexp + (concat "^\\s-*(define-widget" find-function-space-re "%s\\(\\s-\\|$\\)")) + (defcustom find-face-regexp (concat"^\\s-*(defface" find-function-space-re "%s\\(\\s-\\|$\\)") "The regexp used by `find-face' to search for a face definition. @@ -132,7 +135,8 @@ should insert the feature name." (defface . find-function--defface) (feature . find-feature-regexp) (defalias . find-alias-regexp) - (ert-deftest . find-ert-deftest-regexp)) + (ert-deftest . find-ert-deftest-regexp) + (define-widget . find-widget-regexp)) "Alist mapping definition types into regexp variables. Each regexp variable's value should actually be a format string to be used to substitute the desired symbol name into the regexp. diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index f2fd5722413..6fd9141e27b 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -990,9 +990,10 @@ If the buffer start was reached, return nil." (defun elisp--xref-infer-namespace (pos) "Find the likely namespace of the identifier at POS. -Return one of `function', `variable' `maybe-variable', `feature', `face', or -`any' (indicating any namespace). `maybe-variable' indicates a variable -namespace but with lower confidence." +Return one of `function', `variable' `maybe-variable', `feature', +`face', `widget-type', or `any' (indicating any namespace). +`maybe-variable' indicates a variable namespace but with lower +confidence." (save-excursion (goto-char pos) (cl-flet ((looking-at-sym () @@ -1143,6 +1144,7 @@ namespace but with lower confidence." nil) ((defface face) 'face) ((feature) 'feature) + ((widget-type) 'widget-type) ((defvar variable constant) 'variable) ((defun function macro special-form top-level major-mode) 'function)))) @@ -1244,7 +1246,8 @@ namespace but with lower confidence." cl-defgeneric cl-defmethod)) ('variable '(defvar)) ('face '(defface)) - ('feature '(feature))))) + ('feature '(feature)) + ('widget-type '(define-widget))))) (cl-loop for d in definitions when (memq (xref-elisp-location-type (xref-item-location d)) @@ -1288,6 +1291,10 @@ namespace but with lower confidence." (when file (push (elisp--xref-make-xref 'defface symbol file) xrefs)))) + (when (get 'symbol 'widget-type) + (when-let ((file (find-lisp-object-file-name symbol 'define-widget))) + (push (elisp--xref-make-xref 'define-widget symbol file) xrefs))) + (when (fboundp symbol) (let ((file (find-lisp-object-file-name symbol (symbol-function symbol))) generic doc) diff --git a/lisp/widget.el b/lisp/widget.el index 58455cba24f..a8a6748aa4f 100644 --- a/lisp/widget.el +++ b/lisp/widget.el @@ -55,6 +55,7 @@ The third argument DOC is a documentation string for the widget." (error "Widget documentation must be nil or a string")) (put name 'widget-type (cons class args)) (put name 'widget-documentation (purecopy doc)) + (add-to-list 'current-load-list `(define-widget . ,name)) name) (define-obsolete-function-alias 'widget-plist-member #'plist-member "26.1")