From 0108b5397b8d02a4e0bd7c7bb6f0ef1fdce813d1 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 17 Feb 2025 09:17:53 +0100 Subject: [PATCH] Jump-to-definition support for error types --- lisp/emacs-lisp/find-func.el | 6 +++++- lisp/loadhist.el | 5 +++++ lisp/progmodes/elisp-mode.el | 9 ++++++++- lisp/subr.el | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index 5bce63048ee..326232028e7 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-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. diff --git a/lisp/loadhist.el b/lisp/loadhist.el index 5cbb2e1f290..2298ae73736 100644 --- a/lisp/loadhist.el +++ b/lisp/loadhist.el @@ -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. diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 6c9c0f829ec..f4d444b9982 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -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) diff --git a/lisp/subr.el b/lisp/subr.el index 19725c60293..5eea614f6d6 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -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 -- 2.39.5