+(defun describe-function-1 (function parens)
+ (let* ((def (symbol-function function))
+ file-name string need-close
+ (beg (if (commandp def) "an interactive " "a ")))
+ (setq string
+ (cond ((or (stringp def)
+ (vectorp def))
+ "a keyboard macro")
+ ((subrp def)
+ (concat beg "built-in function"))
+ ((byte-code-function-p def)
+ (concat beg "compiled Lisp function"))
+ ((symbolp def)
+ (while (symbolp (symbol-function def))
+ (setq def (symbol-function def)))
+ (format "alias for `%s'" def))
+ ((eq (car-safe def) 'lambda)
+ (concat beg "Lisp function"))
+ ((eq (car-safe def) 'macro)
+ "a Lisp macro")
+ ((eq (car-safe def) 'mocklisp)
+ "a mocklisp function")
+ ((eq (car-safe def) 'autoload)
+ (setq file-name (nth 1 def))
+ (format "%s autoloaded Lisp %s"
+ (if (commandp def) "an interactive" "an")
+ (if (nth 4 def) "macro" "function")
+ ))
+ (t "")))
+ (when (and parens (not (equal string "")))
+ (setq need-close t)
+ (princ "("))
+ (princ string)
+ (or file-name
+ (setq file-name (describe-function-find-file function)))
+ (if file-name
+ (progn
+ (princ " in `")
+ ;; We used to add .el to the file name,
+ ;; but that's completely wrong when the user used load-file.
+ (princ file-name)
+ (princ "'")
+ ;; Make a hyperlink to the library.
+ (with-current-buffer "*Help*"
+ (save-excursion
+ (re-search-backward "`\\([^`']+\\)'" nil t)
+ (help-xref-button 1 #'(lambda (arg)
+ (let ((location
+ (find-function-noselect arg)))
+ (pop-to-buffer (car location))
+ (goto-char (cdr location))))
+ function)))))
+ (if need-close (princ ")"))
+ (princ ".")
+ (terpri)
+ ;; Handle symbols aliased to other symbols.
+ (setq def (indirect-function def))
+ ;; If definition is a macro, find the function inside it.
+ (if (eq (car-safe def) 'macro)
+ (setq def (cdr def)))
+ (let ((arglist (cond ((byte-code-function-p def)
+ (car (append def nil)))
+ ((eq (car-safe def) 'lambda)
+ (nth 1 def))
+ (t t))))
+ (if (listp arglist)
+ (progn
+ (princ (cons function
+ (mapcar (lambda (arg)
+ (if (memq arg '(&optional &rest))
+ arg
+ (intern (upcase (symbol-name arg)))))
+ arglist)))
+ (terpri))))
+ (let ((doc (documentation function)))
+ (if doc
+ (progn (terpri)
+ (princ doc)
+ (help-setup-xref (list #'describe-function function) (interactive-p)))
+ (princ "not documented")))))
+