(help-fns-function-description-header): Print functions' type

Instead of choosing English words to describe the kind of function,
use the actual type of the function object (from `cl-type-of`)
directly, and make it a button to display info about that type.

* lisp/help-fns.el (help-fns-function-description-header): Use the
function's type name in the description instead of "prose".
Use `insert` instead of `princ`, so as to preserve the text-properties
of the button.

* lisp/emacs-lisp/cl-extra.el (cl-help-type): Move to `help-mode.el`
and rename to `help-type`.
(cl--describe-class): Adjust accordingly.

* lisp/help-mode.el (help-type): New type, moved and renamed from
`cl-extra.el`.
This commit is contained in:
Stefan Monnier 2024-03-21 21:08:58 -04:00
parent c1530a2e49
commit accd79c939
3 changed files with 22 additions and 25 deletions

View file

@ -720,11 +720,6 @@ PROPLIST is a list of the sort returned by `symbol-plist'.
(add-to-list 'find-function-regexp-alist (add-to-list 'find-function-regexp-alist
'(define-type . cl--typedef-regexp))) '(define-type . cl--typedef-regexp)))
(define-button-type 'cl-help-type
:supertype 'help-function-def
'help-function #'cl-describe-type
'help-echo (purecopy "mouse-2, RET: describe this type"))
(define-button-type 'cl-type-definition (define-button-type 'cl-type-definition
:supertype 'help-function-def :supertype 'help-function-def
'help-echo (purecopy "mouse-2, RET: find type definition")) 'help-echo (purecopy "mouse-2, RET: find type definition"))
@ -777,7 +772,7 @@ Call `cl--find-class' to get TYPE's propname `cl--class'"
(insert (symbol-name type) (insert (symbol-name type)
(substitute-command-keys " is a type (of kind `")) (substitute-command-keys " is a type (of kind `"))
(help-insert-xref-button (symbol-name metatype) (help-insert-xref-button (symbol-name metatype)
'cl-help-type metatype) 'help-type metatype)
(insert (substitute-command-keys "')")) (insert (substitute-command-keys "')"))
(when location (when location
(insert (substitute-command-keys " in `")) (insert (substitute-command-keys " in `"))
@ -796,7 +791,7 @@ Call `cl--find-class' to get TYPE's propname `cl--class'"
(setq cur (cl--class-name cur)) (setq cur (cl--class-name cur))
(insert (substitute-quotes "`")) (insert (substitute-quotes "`"))
(help-insert-xref-button (symbol-name cur) (help-insert-xref-button (symbol-name cur)
'cl-help-type cur) 'help-type cur)
(insert (substitute-command-keys (if pl "', " "'")))) (insert (substitute-command-keys (if pl "', " "'"))))
(insert ".\n"))) (insert ".\n")))
@ -808,7 +803,7 @@ Call `cl--find-class' to get TYPE's propname `cl--class'"
(while (setq cur (pop ch)) (while (setq cur (pop ch))
(insert (substitute-quotes "`")) (insert (substitute-quotes "`"))
(help-insert-xref-button (symbol-name cur) (help-insert-xref-button (symbol-name cur)
'cl-help-type cur) 'help-type cur)
(insert (substitute-command-keys (if ch "', " "'")))) (insert (substitute-command-keys (if ch "', " "'"))))
(insert ".\n"))) (insert ".\n")))

View file

@ -1061,10 +1061,10 @@ Returns a list of the form (REAL-FUNCTION DEF ALIASED REAL-DEF)."
(concat (concat
"an autoloaded " (if (commandp def) "an autoloaded " (if (commandp def)
"interactive ")) "interactive "))
(if (commandp def) "an interactive " "a ")))) (if (commandp def) "an interactive " "a ")))
;; Print what kind of function-like object FUNCTION is.
;; Print what kind of function-like object FUNCTION is. (description
(princ (cond ((or (stringp def) (vectorp def)) (cond ((or (stringp def) (vectorp def))
"a keyboard macro") "a keyboard macro")
((and (symbolp function) ((and (symbolp function)
(get function 'reader-construct)) (get function 'reader-construct))
@ -1073,12 +1073,6 @@ Returns a list of the form (REAL-FUNCTION DEF ALIASED REAL-DEF)."
;; aliases before functions. ;; aliases before functions.
(aliased (aliased
(format-message "an alias for `%s'" real-def)) (format-message "an alias for `%s'" real-def))
((subr-native-elisp-p def)
(concat beg "native-compiled Lisp function"))
((subrp def)
(concat beg (if (eq 'unevalled (cdr (subr-arity def)))
"special form"
"built-in function")))
((autoloadp def) ((autoloadp def)
(format "an autoloaded %s" (format "an autoloaded %s"
(cond (cond
@ -1092,12 +1086,13 @@ Returns a list of the form (REAL-FUNCTION DEF ALIASED REAL-DEF)."
;; need to check macros before functions. ;; need to check macros before functions.
(macrop function)) (macrop function))
(concat beg "Lisp macro")) (concat beg "Lisp macro"))
((byte-code-function-p def) ((atom def)
(concat beg "byte-compiled Lisp function")) (let ((type (or (oclosure-type def) (cl-type-of def))))
((module-function-p def) (concat beg (format "%s"
(concat beg "module function")) (make-text-button
((memq (car-safe def) '(lambda closure)) (symbol-name type) nil
(concat beg "Lisp function")) 'type 'help-type
'help-args (list type))))))
((keymapp def) ((keymapp def)
(let ((is-full nil) (let ((is-full nil)
(elts (cdr-safe def))) (elts (cdr-safe def)))
@ -1107,7 +1102,9 @@ Returns a list of the form (REAL-FUNCTION DEF ALIASED REAL-DEF)."
elts nil)) elts nil))
(setq elts (cdr-safe elts))) (setq elts (cdr-safe elts)))
(concat beg (if is-full "keymap" "sparse keymap")))) (concat beg (if is-full "keymap" "sparse keymap"))))
(t ""))) (t ""))))
(with-current-buffer standard-output
(insert description))
(if (and aliased (not (fboundp real-def))) (if (and aliased (not (fboundp real-def)))
(princ ",\nwhich is not defined.") (princ ",\nwhich is not defined.")

View file

@ -177,6 +177,11 @@ The format is (FUNCTION ARGS...).")
'help-function 'describe-variable 'help-function 'describe-variable
'help-echo (purecopy "mouse-2, RET: describe this variable")) 'help-echo (purecopy "mouse-2, RET: describe this variable"))
(define-button-type 'help-type
:supertype 'help-xref
'help-function #'cl-describe-type
'help-echo (purecopy "mouse-2, RET: describe this type"))
(define-button-type 'help-face (define-button-type 'help-face
:supertype 'help-xref :supertype 'help-xref
'help-function 'describe-face 'help-function 'describe-face