(describe-bindings): New command (formerly in keymap.c).
[bpt/emacs.git] / lisp / help.el
index 867ab33..12b8834 100644 (file)
@@ -127,23 +127,40 @@ Commands:
   (setq view-no-disable-on-exit t)
   (run-hooks 'help-mode-hook))
 
+(defun help-mode-maybe ()
+  (if (eq major-mode 'fundamental-mode)
+      (help-mode)))
+
+(add-hook 'temp-buffer-show-hook 'help-mode-maybe)
+
 (defun help-quit ()
   (interactive)
   nil)
 
+(defvar help-with-tutorial-alist
+  '(("German" . "TUTORIAL.de")
+    ("Korean" . "TUTORIAL.kr")
+    ("Japanese" . "TUTORIAL.jp")
+    ("Thai" . "TUTORIAL.th")
+    ("English" . "TUTORIAL"))
+  "Alist mapping language names to their translated Emacs tutorial files.")
+
 (defun help-with-tutorial (&optional arg)
   "Select the Emacs learn-by-doing tutorial.
 If there is a tutorial version written in the language
 of the selected language environment, that version is used.
 If there's no tutorial in that language, `TUTORIAL' is selected.
-With arg, you are asked to select which language."
+With arg, you are asked to choose which language."
   (interactive "P")
   (let (lang filename file)
     (if arg
-       (or (setq lang (read-language-name 'tutorial "Language: "))
-           (error "No tutorial file of the specified language"))
+       (or (setq lang
+                 (let* ((completion-ignore-case t))
+                   (completing-read "Language: " help-with-tutorial-alist
+                                    nil t)))
+           (error "No tutorial file in language"))
       (setq lang current-language-environment))
-    (setq filename (or (get-language-info lang 'tutorial)
+    (setq filename (or (cdr (assoc lang help-with-tutorial-alist))
                       "TUTORIAL"))
     (setq file (expand-file-name (concat "~/" filename)))
     (delete-other-windows)
@@ -289,9 +306,6 @@ If FUNCTION is nil, applies `message' to it, thus printing it."
                  (progn (terpri)
                         (princ doc))
                (princ "not documented")))
-           (save-excursion
-             (set-buffer standard-output)
-             (help-mode))
            (print-help-return-message)))))))
 
 (defun describe-mode ()
@@ -334,9 +348,6 @@ followed by the major mode, which is described on the last page.\n\f\n"))
     (princ mode-name)
     (princ " mode:\n")
     (princ (documentation major-mode))
-    (save-excursion
-      (set-buffer standard-output)
-      (help-mode))
     (print-help-return-message)))
 
 ;; So keyboard macro definitions are documented correctly
@@ -416,8 +427,7 @@ of the key sequence that ran this command."
       (goto-char (point-min))
       (while (progn (move-to-column 50) (not (eobp)))
        (search-forward " " nil t)
-       (insert "\n"))
-      (help-mode))
+       (insert "\n")))
     (print-help-return-message)))
 
 (defalias 'help 'help-for-help)
@@ -449,8 +459,8 @@ l  view-lossage.  Shows last 100 characters you typed.
 L  describe-language-environment.  This describes either the a
        specific language environment (if you type its name)
        or the current language environment (if you type just RET).
-m  describe-mode.  Print documentation of current major mode,
-       which describes the commands peculiar to it.
+m  describe-mode.  Print documentation of current minor modes,
+       and the current major mode, including their special commands.
 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
@@ -473,21 +483,26 @@ C-w Display information on absence of warranty for GNU Emacs."
 ;; If that gives no function, return a function whose name is around point.
 ;; If that doesn't give a function, return nil.
 (defun function-called-at-point ()
-  (or (condition-case ()
-         (save-excursion
-           (save-restriction
-             (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
-             (backward-up-list 1)
-             (forward-char 1)
-             (let (obj)
-               (setq obj (read (current-buffer)))
-               (and (symbolp obj) (fboundp obj) obj))))
-       (error nil))
-      (condition-case ()
-         (let ((stab (syntax-table)))
-           (unwind-protect
+  (let ((stab (syntax-table)))
+    (set-syntax-table emacs-lisp-mode-syntax-table)
+    (unwind-protect
+       (or (condition-case ()
+               (save-excursion
+                 (save-restriction
+                   (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
+                   ;; Move up to surrounding paren, then after the open.
+                   (backward-up-list 1)
+                   (forward-char 1)
+                   ;; If there is space here, this is probably something
+                   ;; other than a real Lisp function call, so ignore it.
+                   (if (looking-at "[ \t]")
+                       (error "Probably not a Lisp function call"))
+                   (let (obj)
+                     (setq obj (read (current-buffer)))
+                     (and (symbolp obj) (fboundp obj) obj))))
+             (error nil))
+           (condition-case ()
                (save-excursion
-                 (set-syntax-table emacs-lisp-mode-syntax-table)
                  (or (not (zerop (skip-syntax-backward "_w")))
                      (eq (char-syntax (following-char)) ?w)
                      (eq (char-syntax (following-char)) ?_)
@@ -495,8 +510,8 @@ C-w Display information on absence of warranty for GNU Emacs."
                  (skip-chars-forward "'")
                  (let ((obj (read (current-buffer))))
                    (and (symbolp obj) (fboundp obj) obj)))
-             (set-syntax-table stab)))
-       (error nil))))
+             (error nil)))
+      (set-syntax-table stab))))
 
 (defun describe-function-find-file (function)
   (let ((files load-history)
@@ -516,7 +531,7 @@ C-w Display information on absence of warranty for GNU Emacs."
      (setq val (completing-read (if fn
                                    (format "Describe function (default %s): " fn)
                                  "Describe function: ")
-                               obarray 'fboundp t))
+                               obarray 'fboundp t nil nil (symbol-name fn)))
      (list (if (equal val "")
               fn (intern val)))))
   (if function
@@ -561,10 +576,13 @@ C-w Display information on absence of warranty for GNU Emacs."
                (princ "'")))
          (princ ".")
          (terpri)
-         (let ((arglist (cond ((byte-code-function-p def)
-                               (car (append def nil)))
-                              ((eq (car-safe def) 'lambda)
-                               (nth 1 def))
+         (let* ((inner-function (if (and (listp def) 'macro)
+                                    (cdr def)
+                                  def))
+                (arglist (cond ((byte-code-function-p inner-function)
+                               (car (append inner-function nil)))
+                              ((eq (car-safe inner-function) 'lambda)
+                               (nth 1 inner-function))
                               (t t))))
            (if (listp arglist)
                (progn
@@ -583,7 +601,6 @@ C-w Display information on absence of warranty for GNU Emacs."
        (print-help-return-message)
        (save-excursion
          (set-buffer standard-output)
-         (help-mode)
          ;; Return the text we displayed.
          (buffer-string)))
     (message "You didn't specify a function")))
@@ -616,7 +633,8 @@ Returns the documentation as a string, also."
      (setq val (completing-read (if (symbolp v)
                                    (format "Describe variable (default %s): " v)
                                  "Describe variable: ")
-                               obarray 'boundp t))
+                               obarray 'boundp t nil nil
+                               (if (symbolp v) (symbol-name v))))
      (list (if (equal val "")
               v (intern val)))))
   (if (symbolp variable)
@@ -661,11 +679,19 @@ Returns the documentation as a string, also."
          (print-help-return-message)
          (save-excursion
            (set-buffer standard-output)
-           (help-mode)
            ;; Return the text we displayed.
            (buffer-string))))
     (message "You did not specify a variable")))
 
+(defun describe-bindings (&optional prefix)
+  "Show a list of all defined keys, and their definitions.
+We put that list in a buffer, and display the buffer.
+
+The optional argument PREFIX, if non-nil, should be a key sequence;
+then we display only bindings that start with that prefix."
+  (interactive "p")
+  (describe-bindings-internal nil prefix))
+
 (defun where-is (definition &optional insert)
   "Print message listing key sequences that invoke specified command.
 Argument is a command definition, usually a symbol with a function definition.
@@ -719,19 +745,22 @@ is used instead of `load-path'."
                     (throw 'answer try)))))
          (if nosuffix
              '("")
-           (let ((basic '(".elc" ".el" ""))
-                 (compressed '(".Z" ".gz" "")))
-             ;; If autocompression mode is on,
-             ;; consider all combinations of library suffixes
-             ;; and compression suffixes.
-             (if (rassq 'jka-compr-handler file-name-handler-alist)
-                 (apply 'nconc
-                        (mapcar (lambda (compelt)
-                                  (mapcar (lambda (baselt)
-                                            (concat baselt compelt))
-                                          basic))
-                                compressed))
-               basic)))))
+           '(".elc" ".el" "")
+;;; load doesn't handle this yet.
+;;;        (let ((basic '(".elc" ".el" ""))
+;;;              (compressed '(".Z" ".gz" "")))
+;;;          ;; If autocompression mode is on,
+;;;          ;; consider all combinations of library suffixes
+;;;          ;; and compression suffixes.
+;;;          (if (rassq 'jka-compr-handler file-name-handler-alist)
+;;;              (apply 'nconc
+;;;                     (mapcar (lambda (compelt)
+;;;                               (mapcar (lambda (baselt)
+;;;                                         (concat baselt compelt))
+;;;                                       basic))
+;;;                             compressed))
+;;;            basic))
+           )))
        (or path load-path)))
     (and interactive-call
         (if result