If the goal is to get information about functions and variables already in the environment:
For docstrings of functions and macros, see the
For variable docstrings, use
documentation-property; for example:
For function arity and the argument list, see this Emacs.SE question, the answer, and comments to the question.
(I found this by pressing
C-h k C-h f and skimming the source code of
describe-function (same for variable docstrings, but studying
To analyze an Emacs Lisp source code file, assuming that the goal is to get information about top-level
def.* forms, one can do something similar to the following.
(defun get-defun-info (buffer)
"Get information about all `defun' top-level sexps in a buffer
BUFFER. Returns a list with elements of the form (symbol args docstring)."
;; keep going while reading succeeds
(while (condition-case nil
(let ((form (read (current-buffer))))
((not (listp form)) ; if it's not a list, skip it
((eq (nth 0 form) 'defun) ; if it's a defun, collect info
(let ((sym (nth 1 form))
(args (nth 2 form))
(doc (when (stringp (nth 3 form)) (nth 3 form))))
(push (list sym args doc) result))))))
This can be easily extended to
defun appearing inside top-level forms one would have to descend into these forms, possibly using recursion.