]> git.eshelyaron.com Git - emacs.git/commitdiff
Jump-to-definition support for error types
authorEshel Yaron <me@eshelyaron.com>
Mon, 17 Feb 2025 08:17:53 +0000 (09:17 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 17 Feb 2025 08:18:26 +0000 (09:18 +0100)
lisp/emacs-lisp/find-func.el
lisp/loadhist.el
lisp/progmodes/elisp-mode.el
lisp/subr.el

index 5bce63048ee4e3ea2508d6f75f73f450574409cb..326232028e76960370898c8c17cff31994aee933 100644 (file)
@@ -76,6 +76,9 @@ Please send improvements and fixes to the maintainer."
   :group 'find-function
   :version "21.1")
 
+(defvar find-error-regexp
+  (concat "^\\s-*(define-error" find-function-space-re "%s\\(\\s-\\|$\\)"))
+
 (defvar find-widget-regexp
   (concat "^\\s-*(define-widget" find-function-space-re "%s\\(\\s-\\|$\\)"))
 
@@ -136,7 +139,8 @@ should insert the feature name."
     (feature . find-feature-regexp)
     (defalias . find-alias-regexp)
     (ert-deftest . find-ert-deftest-regexp)
-    (define-widget . find-widget-regexp))
+    (define-widget . find-widget-regexp)
+    (define-error . find-error-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 5cbb2e1f2902c85f066843eafcd96288e7231caf..2298ae73736585528e1513f97bb5e20ee33fadb1 100644 (file)
@@ -230,6 +230,11 @@ unloading."
     (put name 'widget-type nil)
     (put name 'widget-documentation nil)))
 
+(cl-defmethod loadhist-unload-element ((x (head define-error)))
+  (let ((name (cdr x)))
+    (put name 'error-conditions nil)
+    (put name 'error-message nil)))
+
 ;;;###autoload
 (defun unload-feature (feature &optional force)
   "Unload the library that provided FEATURE.
index 6c9c0f829ecc5a95008b9b6a27dfab03743d20cd..f4d444b9982cad0d44f16dda76ab970c76cac839 100644 (file)
@@ -813,6 +813,7 @@ in `completion-at-point-functions' (which see)."
                              (lambda (sym) (or (alist-get sym macro-declarations-alist)
                                                (alist-get sym defun-declarations-alist))))
                             ((group) (lambda (sym) (get sym 'group-documentation)))
+                            ((condition) (lambda (sym) (get sym 'error-conditions)))
                             ((face) #'facep)
                             ((theme) #'custom-theme-p)
                             ((thing) (lambda (sym)
@@ -1063,6 +1064,7 @@ confidence."
       ((defface face) 'face)
       ((feature) 'feature)
       ((widget-type) 'widget-type)
+      ((condition) 'condition)
       ((defvar variable constant) 'variable)
       ((defun function macro special-form top-level major-mode) 'function))))
 
@@ -1162,6 +1164,7 @@ confidence."
              ('variable '(defvar))
              ('face '(defface))
              ('feature '(feature))
+             ('condition '(define-error))
              ('widget-type '(define-widget)))))
       (cl-loop for d in definitions
                when (memq
@@ -1206,10 +1209,14 @@ confidence."
           (when file
             (push (elisp--xref-make-xref 'defface symbol file) xrefs))))
 
-      (when (get 'symbol 'widget-type)
+      (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 (get symbol 'error-conditions)
+        (when-let ((file (find-lisp-object-file-name symbol 'define-error)))
+          (push (elisp--xref-make-xref 'define-error symbol file) xrefs)))
+
       (when (fboundp symbol)
         (let ((file (find-lisp-object-file-name symbol (symbol-function symbol)))
               generic doc)
index 19725c60293edf98ceb95167bf56a78b3886f8eb..5eea614f6d60b9383068f15efb7e439628f70734 100644 (file)
@@ -519,6 +519,7 @@ Defaults to `error'."
            (cons parent (get parent 'error-conditions)))))
     (put name 'error-conditions
          (delete-dups (copy-sequence (cons name conditions))))
+    (add-to-list 'current-load-list `(define-error . ,name))
     (when message (put name 'error-message message))))
 
 ;; We put this here instead of in frame.el so that it's defined even on