]> git.eshelyaron.com Git - emacs.git/commitdiff
Teach elisp-mode.el to find widget definitions
authorEshel Yaron <me@eshelyaron.com>
Sat, 18 Jan 2025 19:52:48 +0000 (20:52 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sat, 18 Jan 2025 19:52:48 +0000 (20:52 +0100)
lisp/emacs-lisp/find-func.el
lisp/progmodes/elisp-mode.el
lisp/widget.el

index d51d3c87deabbe09e0ed47ec296065d9b4ec9692..e0c713a422313b87ca996a27700dced487c5e4b0 100644 (file)
@@ -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.
index f2fd5722413d44c7067013e6a445c6d04ad9446f..6fd9141e27be056aca88a9ff00b551527236d17a 100644 (file)
@@ -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)
index 58455cba24fefe656de67b58bf9a751891014b91..a8a6748aa4f4643f42aa496f912331479534b477 100644 (file)
@@ -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")