(rmail-summary-forward): Accept prefix arg
[bpt/emacs.git] / lisp / help.el
index 95d0829..8fab40e 100644 (file)
@@ -1,6 +1,6 @@
 ;;; help.el --- help commands for Emacs
 
-;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: help, internal
 ;; along with GNU Emacs; see the file COPYING.  If not, write to
 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
+;;; Commentary:
+
+;; This code implements GNU Emac's on-line help system, the one invoked by
+;;`M-x help-for-help'.
+
 ;;; Code:
 
+;; Get the macro make-help-screen when this is compiled,
+;; or run interpreted, but not when the compiled code is loaded.
+(eval-when-compile (require 'help-macro))
+
 (defvar help-map (make-sparse-keymap)
   "Keymap for characters following the Help key.")
 
@@ -56,6 +65,9 @@
 (define-key help-map "\C-n" 'view-emacs-news)
 (define-key help-map "n" 'view-emacs-news)
 
+(define-key help-map "p" 'finder-by-keyword)
+(autoload 'finder-by-keyword "finder")
+
 (define-key help-map "s" 'describe-syntax)
 
 (define-key help-map "t" 'help-with-tutorial)
 (defun describe-key-briefly (key)
   "Print the name of the function KEY invokes.  KEY is a string."
   (interactive "kDescribe key briefly: ")
+  ;; If this key seq ends with a down event, discard the
+  ;; following click or drag event.  Otherwise that would
+  ;; erase the message.
+  (let ((type (aref key (1- (length key)))))
+    (if (listp type) (setq type (car type)))
+    (and (symbolp type)
+        (memq 'down (event-modifiers type))
+        (read-event)))
   (let ((defn (key-binding key)))
     (if (or (null defn) (integerp defn))
         (message "%s is undefined" (key-description key))
@@ -115,6 +135,14 @@ If FUNCTION is nil, applies `message' to it, thus printing it."
 (defun describe-key (key)
   "Display documentation of the function invoked by KEY.  KEY is a string."
   (interactive "kDescribe key: ")
+  ;; If this key seq ends with a down event, discard the
+  ;; following click or drag event.  Otherwise that would
+  ;; erase the message.
+  (let ((type (aref key (1- (length key)))))
+    (if (listp type) (setq type (car type)))
+    (and (symbolp type)
+        (memq 'down (event-modifiers type))
+        (read-event)))
   (let ((defn (key-binding key)))
     (if (or (null defn) (integerp defn))
         (message "%s is undefined" (key-description key))
@@ -131,7 +159,7 @@ If FUNCTION is nil, applies `message' to it, thus printing it."
 If optional MINOR is non-nil (or prefix argument is given if interactive),
 display documentation of active minor modes as well.
 For this to work correctly for a minor mode, the mode's indicator variable
-(listed in `minor-mode-alist') must also be a function whose documentation
+\(listed in `minor-mode-alist') must also be a function whose documentation
 describes the minor mode."
   (interactive)
   (with-output-to-temp-buffer "*Help*"
@@ -181,6 +209,23 @@ describes the minor mode."
     (search-forward "NO WARRANTY")
     (recenter 0)))
 
+(defun describe-prefix-bindings ()
+  "Describe the bindings of the prefix used to reach this command.
+The prefix described consists of all but the last event
+of the key sequence that ran this command."
+  (interactive)
+  (let* ((key (this-command-keys))
+        (prefix (make-vector (1- (length key)) nil))
+        i)
+    (setq i 0)
+    (while (< i (length prefix))
+      (aset prefix i (aref key i))
+      (setq i (1+ i)))
+    (describe-bindings prefix)))
+;; Make C-h after a prefix, when not specifically bound, 
+;; run describe-prefix-bindings.
+(setq prefix-help-command 'describe-prefix-bindings)
+
 (defun view-emacs-news ()
   "Display info on recent changes to Emacs."
   (interactive)
@@ -199,57 +244,40 @@ describes the minor mode."
        (insert "\n")))
     (print-help-return-message)))
 
-(defun help-for-help ()
+(make-help-screen help-for-help
+  "a b c f C-f i k C-k l m n p s t v w C-c C-d C-n C-w.  Type \\[help-for-help] again for more help: "
   "You have typed \\[help-for-help], the help character.  Type a Help option:
 
-A  command-apropos.   Give a substring, and see a list of commands
-              (functions interactively callable) that contain
-             that substring.  See also the  apropos  command.
-B  describe-bindings.  Display table of all key bindings.
-C  describe-key-briefly.  Type a command key sequence;
-             it prints the function name that sequence runs.
-F  describe-function.  Type a function name and get documentation of it.
-I  info. The  info  documentation reader.
-K  describe-key.  Type a command key sequence;
-             it displays the full documentation.
-L  view-lossage.  Shows last 100 characters you typed.
-M  describe-mode.  Print documentation of current major mode,
-             which describes the commands peculiar to it.
-N  view-emacs-news.  Shows emacs news file.
-S  describe-syntax.  Display contents of syntax table, plus explanations
-T  help-with-tutorial.  Select the Emacs learn-by-doing tutorial.
-V  describe-variable.  Type name of a variable;
-             it displays the variable's documentation and value.
-W  where-is.  Type command name; it prints which keystrokes
-             invoke that command.
+a  command-apropos.  Give a substring, and see a list of commands
+       (functions interactively callable) that contain
+       that substring.  See also the  apropos  command.
+b  describe-bindings.  Display table of all key bindings.
+c  describe-key-briefly.  Type a command key sequence;
+       it prints the function name that sequence runs.
+f  describe-function.  Type a function name and get documentation of it.
+C-f Info-goto-emacs-command-node.  Type a function name;
+       it takes you to the Info node for that command.
+i  info. The  info  documentation reader.
+k  describe-key.  Type a command key sequence;
+       it displays the full documentation.
+C-k Info-goto-emacs-key-command-node.  Type a command key sequence;
+       it takes you to the Info node for the command bound to that key.
+l  view-lossage.  Shows last 100 characters you typed.
+m  describe-mode.  Print documentation of current major mode,
+       which describes the commands peculiar to it.
+n  view-emacs-news.  Shows emacs news file.
+p  finder-by-keyword. Find packages matching a given topic keyword.
+s  describe-syntax.  Display contents of syntax table, plus explanations
+t  help-with-tutorial.  Select the Emacs learn-by-doing tutorial.
+v  describe-variable.  Type name of a variable;
+       it displays the variable's documentation and value.
+w  where-is.  Type command name; it prints which keystrokes
+       invoke that command.
 C-c print Emacs copying permission (General Public License).
 C-d print Emacs ordering information.
 C-n print news of recent Emacs changes.
 C-w print information on absence of warranty for GNU Emacs."
-  (interactive)
-  (message (substitute-command-keys
- "A B C F I K L M N S T V W C-c C-d C-n C-w.  Type \\[help-for-help] again for more help: "))
-  (let ((char (read-char)))
-    (if (or (= char help-char) (= char ??))
-       (save-window-excursion
-         (switch-to-buffer "*Help*")
-         (delete-other-windows)
-         (erase-buffer)
-         (insert (documentation 'help-for-help))
-         (goto-char (point-min))
-         (while (memq char (cons help-char '(?? ?\C-v ?\  ?\177 ?\M-v)))
-           (if (memq char '(?\C-v ?\ ))
-               (scroll-up))
-           (if (memq char '(?\177 ?\M-v))
-               (scroll-down))
-           (message "A B C F I K L M N S T V W C-c C-d C-n C-w%s: "
-                    (if (pos-visible-in-window-p (point-max))
-                        "" " or Space to scroll"))
-           (let ((cursor-in-echo-area t))
-             (setq char (read-char))))))
-    (let ((defn (cdr (assq (downcase char) (cdr help-map)))))
-      (if defn (call-interactively defn) (ding)))))
-
+  help-map)
 
 ;; Return a function which is called by the list containing point.
 ;; If that gives no function, return a function whose name is around point.
@@ -290,7 +318,9 @@ C-w print information on absence of warranty for GNU Emacs."
     (princ ": ")
     (let* ((def (symbol-function function))
           (beg (if (commandp def) "an interactive " "a ")))
-      (princ (cond ((stringp def) "a keyboard macro.")
+      (princ (cond ((or (stringp def)
+                       (vectorp def))
+                   "a keyboard macro.")
                   ((subrp def)
                    (concat beg "built-in function."))
                   ((byte-code-function-p def)
@@ -312,23 +342,25 @@ C-w print information on absence of warranty for GNU Emacs."
                            ))
                   (t "")))
       (terpri)
+      (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))))
       (if (documentation function)
-         (princ (documentation function))
+         (progn (terpri)
+                (princ (documentation function)))
        (princ "not documented"))
-      (cond ((byte-code-function-p def)
-            (save-excursion
-              (set-buffer standard-output)
-              (or (eq (char-after (1- (point-max))) ?\n)
-                  (terpri)))
-            (terpri)
-            (princ (car (append def nil))))
-           ((eq (car-safe def) 'lambda)
-            (save-excursion
-              (set-buffer standard-output)
-              (or (eq (char-after (1- (point-max))) ?\n)
-                  (terpri)))
-            (terpri)
-            (princ (nth 1 def)))))
+      )
     (print-help-return-message)
     ;; Return the text we displayed.
     (save-excursion (set-buffer standard-output) (buffer-string))))
@@ -381,8 +413,8 @@ documentation found."
   (let ((message
         (let ((standard-output (get-buffer-create "*Help*")))
           (print-help-return-message 'identity))))
-    (apropos string t 'commandp)
-    (and message (message message))))
+    (if (apropos string t 'commandp)
+       (and message (message message)))))
 
 (defun locate-library (library &optional nosuffix)
   "Show the full path name of Emacs library LIBRARY.