(function-documentation): Make it work for the remaining cases

* lisp/simple.el (function-documentation):
Use `internal-subr-documentation` and make it work also with symbols
and macros.

* src/doc.c (Fsubr_documentation): New function, extracted
from Fdocumentation.
(syms_of_doc): defsubr it.
(Fdocumentation): Don't handle subrs and module functions here.
This commit is contained in:
Stefan Monnier 2023-01-13 17:56:04 -05:00
parent f56fea2fcc
commit f5d8aa6eda
2 changed files with 31 additions and 14 deletions

View file

@ -2709,7 +2709,16 @@ function as needed."
(let ((doc (car body)))
(when (funcall docstring-p doc)
doc)))
(_ (signal 'invalid-function (list function))))))
((pred symbolp)
(let ((f (indirect-function function)))
(if f (function-documentation f)
(signal 'void-function (list function)))))
(`(macro . ,f) (function-documentation f))
(_
(let ((doc (internal-subr-documentation function)))
(if (eq t doc)
(signal 'invalid-function (list function))
doc))))))
(cl-defmethod function-documentation ((function accessor))
(oclosure--accessor-docstring function)) ;; FIXME: η-reduce!

View file

@ -330,19 +330,7 @@ string is passed through `substitute-command-keys'. */)
xsignal1 (Qvoid_function, function);
if (CONSP (fun) && EQ (XCAR (fun), Qmacro))
fun = XCDR (fun);
#ifdef HAVE_NATIVE_COMP
if (!NILP (Fsubr_native_elisp_p (fun)))
doc = native_function_doc (fun);
else
#endif
if (SUBRP (fun))
doc = make_fixnum (XSUBR (fun)->doc);
#ifdef HAVE_MODULES
else if (MODULE_FUNCTIONP (fun))
doc = module_function_documentation (XMODULE_FUNCTION (fun));
#endif
else
doc = call1 (Qfunction_documentation, fun);
doc = call1 (Qfunction_documentation, fun);
/* If DOC is 0, it's typically because of a dumped file missing
from the DOC file (bug in src/Makefile.in). */
@ -371,6 +359,25 @@ string is passed through `substitute-command-keys'. */)
return doc;
}
DEFUN ("internal-subr-documentation", Fsubr_documentation, Ssubr_documentation, 1, 1, 0,
doc: /* Return the raw documentation info of a C primitive. */)
(Lisp_Object function)
{
#ifdef HAVE_NATIVE_COMP
if (!NILP (Fsubr_native_elisp_p (function)))
return native_function_doc (function);
else
#endif
if (SUBRP (function))
return make_fixnum (XSUBR (function)->doc);
#ifdef HAVE_MODULES
else if (MODULE_FUNCTIONP (function))
return module_function_documentation (XMODULE_FUNCTION (function));
#endif
else
return Qt;
}
DEFUN ("documentation-property", Fdocumentation_property,
Sdocumentation_property, 2, 3, 0,
doc: /* Return the documentation string that is SYMBOL's PROP property.
@ -713,6 +720,7 @@ compute the correct value for the current terminal in the nil case. */);
/* Initialized by main. */
defsubr (&Sdocumentation);
defsubr (&Ssubr_documentation);
defsubr (&Sdocumentation_property);
defsubr (&Ssnarf_documentation);
defsubr (&Stext_quoting_style);