branch: externals/dash commit b9982020fac9e7fe683b88625302a1ded6cc477b Author: Basil L. Contovounesios <ba...@contovou.net> Commit: Basil L. Contovounesios <ba...@contovou.net>
Add find-func support for defexamples * dev/dash-defs.el (dash--find-example-regexp): New variable. (defexamples): Add it to each function's find-function-type-alist property in Emacs 31+, to locate the generated ert-deftest as per the example in Info node "(elisp) Finding Definitions". --- dev/dash-defs.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dev/dash-defs.el b/dev/dash-defs.el index 920d3d0c19..f670378d00 100644 --- a/dev/dash-defs.el +++ b/dev/dash-defs.el @@ -19,6 +19,7 @@ (require 'dash) (require 'ert) +(require 'find-func) ;; Added in Emacs 24.4; wrap in `eval-when-compile' when support is dropped. (require 'subr-x nil t) (declare-function string-remove-prefix "subr-x" (prefix string)) @@ -72,6 +73,14 @@ See `dash--groups'." (push (cons ,name ,doc) dash--groups) ,@examples)) +(defvar dash--find-example-regexp + ;; Could use `rx' directly in Emacs 27+ + ;; (or not rely on `find-function-space-re'). + (let ((re `(: "(defexamples" (regexp ,find-function-space-re) + symbol-start (regexp "%s") symbol-end))) + (rx-to-string re t)) + "Regexp matching `defexamples' for `find-function-regexp-alist'.") + (defmacro defexamples (fn &rest examples) "Define a set of EXAMPLES and corresponding ERT tests for FN. See `dash--groups'." @@ -83,6 +92,10 @@ See `dash--groups'." (setq examples (nthcdr 3 examples)))) `(progn (push (cons ',fn ',(nreverse triples)) dash--groups) + (when (fboundp 'find-function-update-type-alist) + ;; Help `ert-describe-test' locate examples in Emacs 31+. + (find-function-update-type-alist + ',fn 'ert--test 'dash--find-example-regexp)) (ert-deftest ,fn () ,@(nreverse tests))))) ;; Added in Emacs 25.1.