[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Inferred function types in the *Help* buffer
From: |
Andrea Corallo |
Subject: |
Inferred function types in the *Help* buffer |
Date: |
Tue, 23 May 2023 16:44:08 +0000 |
Hello all,
on my Emacs I'm toying with the attached patch. Applied on top of
master it adds the inferred type for native compiled functions into the
help buffer.
So for instance for a function like:
(defun foo (n)
(unless (integerp n)
(error "Panic"))
(if (> n 100)
'too-big
(if (< n 100)
'to-small
n)))
The content of the *Help* buffer becomes:
====
foo is a native-compiled Lisp function in
‘~/.emacs.d/eln-cache/30.0.50-e29d76eb/test-a526a80f-5481bc95.eln’.
Signature: (foo N)
Inferred type: (function (t) (or (member to-small too-big) (integer
100 100)))
...
====
Indeed the native compiler is not capable of predicting precisly the
return type for every compiled function, often can't predict anything
more precise than 't'. But in a -Q Emacs on my system it manages to
predict non trivial results for ~20% of loaded functions at startup.
I feel this would be a nice addition to the self-documenting
capabilities of Emacs, so I wanted to probe what's the general feeling
about this.
If it's considered too invasive we might indeed control it with a
customize, WDYT?
ATM I adds as well "Signature: " in front of the signature to
differentiate it from the type. But looking at it in restrospective it
might be not even necessary.
Thanks
Andrea
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 1966193d1a7..69f5c623f5c 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -710,7 +710,11 @@ help-fns--signature
(high-doc (cdr high)))
(unless (and (symbolp function)
(get function 'reader-construct))
- (insert high-usage "\n"))
+ (insert "Signature: " high-usage "\n\n")
+ (when (and (featurep 'native-compile)
+ (subr-native-elisp-p (symbol-function function))
+ (subr-type (symbol-function function)))
+ (insert (format "Inferred type: %s\n" (subr-type
(symbol-function function))))))
(fill-region fill-begin (point))
high-doc)))))
- Inferred function types in the *Help* buffer,
Andrea Corallo <=
- Re: Inferred function types in the *Help* buffer, Eli Zaretskii, 2023/05/24
- Re: Inferred function types in the *Help* buffer, Andrea Corallo, 2023/05/24
- Re: Inferred function types in the *Help* buffer, Andrea Corallo, 2023/05/30
- Re: Inferred function types in the *Help* buffer, Mattias Engdegård, 2023/05/30
- Re: Inferred function types in the *Help* buffer, Andrea Corallo, 2023/05/30
- Re: Inferred function types in the *Help* buffer, Andrea Corallo, 2023/05/31
- Re: Inferred function types in the *Help* buffer, Eli Zaretskii, 2023/05/31
- Re: Inferred function types in the *Help* buffer, Eli Zaretskii, 2023/05/31