comparison lisp/help.el @ 21491:7a8169a735f5

(describe-function-1): New function. (describe-function): Use describe-function-1. (describe-key): Likewise.
author Karl Heuer <kwzh@gnu.org>
date Mon, 13 Apr 1998 06:56:24 +0000
parents 4718a738947a
children a89b6f48c73d
comparison
equal deleted inserted replaced
21490:366a1d025c6c 21491:7a8169a735f5
329 (princ (key-description key)) 329 (princ (key-description key))
330 (if (windowp window) 330 (if (windowp window)
331 (princ " at that spot")) 331 (princ " at that spot"))
332 (princ " runs the command ") 332 (princ " runs the command ")
333 (prin1 defn) 333 (prin1 defn)
334 (princ "\n") 334 (princ "\n which is ")
335 (let ((doc (documentation defn))) 335 (describe-function-1 defn nil)
336 (if doc
337 (progn (terpri)
338 (princ doc)
339 (help-setup-xref (cons #'describe-key key) (interactive-p)))
340 (princ "not documented")))
341 (print-help-return-message))))))) 336 (print-help-return-message)))))))
342 337
343 (defun describe-mode () 338 (defun describe-mode ()
344 "Display documentation of current major mode and minor modes. 339 "Display documentation of current major mode and minor modes.
345 For this to work correctly for a minor mode, the mode's indicator variable 340 For this to work correctly for a minor mode, the mode's indicator variable
577 (with-output-to-temp-buffer "*Help*" 572 (with-output-to-temp-buffer "*Help*"
578 (prin1 function) 573 (prin1 function)
579 ;; Use " is " instead of a colon so that 574 ;; Use " is " instead of a colon so that
580 ;; it is easier to get out the function name using forward-sexp. 575 ;; it is easier to get out the function name using forward-sexp.
581 (princ " is ") 576 (princ " is ")
582 (let* ((def (symbol-function function)) 577 (describe-function-1 function nil)
583 file-name
584 (beg (if (commandp def) "an interactive " "a ")))
585 (princ (cond ((or (stringp def)
586 (vectorp def))
587 "a keyboard macro")
588 ((subrp def)
589 (concat beg "built-in function"))
590 ((byte-code-function-p def)
591 (concat beg "compiled Lisp function"))
592 ((symbolp def)
593 (format "alias for `%s'" def))
594 ((eq (car-safe def) 'lambda)
595 (concat beg "Lisp function"))
596 ((eq (car-safe def) 'macro)
597 "a Lisp macro")
598 ((eq (car-safe def) 'mocklisp)
599 "a mocklisp function")
600 ((eq (car-safe def) 'autoload)
601 (setq file-name (nth 1 def))
602 (format "%s autoloaded Lisp %s"
603 (if (commandp def) "an interactive" "an")
604 (if (nth 4 def) "macro" "function")
605 ))
606 (t "")))
607 (or file-name
608 (setq file-name (describe-function-find-file function)))
609 (if file-name
610 (progn
611 (princ " in `")
612 ;; We used to add .el to the file name,
613 ;; but that's completely wrong when the user used load-file.
614 (princ file-name)
615 (princ "'")))
616 (princ ".")
617 (terpri)
618 (let* ((inner-function (if (and (listp def) 'macro)
619 (cdr def)
620 def))
621 (arglist (cond ((byte-code-function-p inner-function)
622 (car (append inner-function nil)))
623 ((eq (car-safe inner-function) 'lambda)
624 (nth 1 inner-function))
625 (t t))))
626 (if (listp arglist)
627 (progn
628 (princ (cons function
629 (mapcar (lambda (arg)
630 (if (memq arg '(&optional &rest))
631 arg
632 (intern (upcase (symbol-name arg)))))
633 arglist)))
634 (terpri))))
635 (let ((doc (documentation function)))
636 (if doc
637 (progn (terpri)
638 (princ doc)
639 (help-setup-xref (cons #'describe-function function) (interactive-p)))
640 (princ "not documented"))))
641 (print-help-return-message) 578 (print-help-return-message)
642 (save-excursion 579 (save-excursion
643 (set-buffer standard-output) 580 (set-buffer standard-output)
644 ;; Return the text we displayed. 581 ;; Return the text we displayed.
645 (buffer-string))) 582 (buffer-string)))
646 (message "You didn't specify a function"))) 583 (message "You didn't specify a function")))
584
585 (defun describe-function-1 (function parens)
586 (let* ((def (symbol-function function))
587 file-name string need-close
588 (beg (if (commandp def) "an interactive " "a ")))
589 (setq string
590 (cond ((or (stringp def)
591 (vectorp def))
592 "a keyboard macro")
593 ((subrp def)
594 (concat beg "built-in function"))
595 ((byte-code-function-p def)
596 (concat beg "compiled Lisp function"))
597 ((symbolp def)
598 (format "alias for `%s'" def))
599 ((eq (car-safe def) 'lambda)
600 (concat beg "Lisp function"))
601 ((eq (car-safe def) 'macro)
602 "a Lisp macro")
603 ((eq (car-safe def) 'mocklisp)
604 "a mocklisp function")
605 ((eq (car-safe def) 'autoload)
606 (setq file-name (nth 1 def))
607 (format "%s autoloaded Lisp %s"
608 (if (commandp def) "an interactive" "an")
609 (if (nth 4 def) "macro" "function")
610 ))
611 (t "")))
612 (when (and parens (not (equal string "")))
613 (setq need-close t)
614 (princ "("))
615 (princ string)
616 (or file-name
617 (setq file-name (describe-function-find-file function)))
618 (if file-name
619 (progn
620 (princ " in `")
621 ;; We used to add .el to the file name,
622 ;; but that's completely wrong when the user used load-file.
623 (princ file-name)
624 (princ "'")))
625 (if need-close (princ ")"))
626 (princ ".")
627 (terpri)
628 (let* ((inner-function (if (and (listp def) 'macro)
629 (cdr def)
630 def))
631 (arglist (cond ((byte-code-function-p inner-function)
632 (car (append inner-function nil)))
633 ((eq (car-safe inner-function) 'lambda)
634 (nth 1 inner-function))
635 (t t))))
636 (if (listp arglist)
637 (progn
638 (princ (cons function
639 (mapcar (lambda (arg)
640 (if (memq arg '(&optional &rest))
641 arg
642 (intern (upcase (symbol-name arg)))))
643 arglist)))
644 (terpri))))
645 (let ((doc (documentation function)))
646 (if doc
647 (progn (terpri)
648 (princ doc)
649 (help-setup-xref (cons #'describe-function function) (interactive-p)))
650 (princ "not documented")))))
647 651
648 ;; We return 0 if we can't find a variable to return. 652 ;; We return 0 if we can't find a variable to return.
649 (defun variable-at-point () 653 (defun variable-at-point ()
650 (condition-case () 654 (condition-case ()
651 (let ((stab (syntax-table))) 655 (let ((stab (syntax-table)))