Merge from emacs--rel--22
[bpt/emacs.git] / lisp / tutorial.el
index c446400..df71ea9 100644 (file)
@@ -9,7 +9,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -154,7 +154,10 @@ options:
                           (format "%s" db)
                           " RET instead."))
               (insert "\n\nWith your current key bindings"
-                      " you can use the key "
+                      " you can use "
+                      (if (string-match "^the .*menus?$" where)
+                          ""
+                        "the key")
                       where
                       " to get the function `"
                       (format "%s" db)
@@ -334,10 +337,11 @@ LEFT and RIGHT are the elements to compare."
                                tutorial--default-keys)))))
         (when changed-keys
           (insert
-           "The following key bindings used in the tutorial had been changed
-from the Emacs default in the " (buffer-name tutorial-buffer) " buffer:\n\n" )
-          (let ((frm "   %-9s %-27s %-11s %s\n"))
-            (insert (format frm "Key" "Standard Binding" "Is Now On" "Remark")))
+           "The following key bindings used in the tutorial have been changed
+from the Emacs default:\n\n" )
+          (let ((frm "   %-14s %-27s %-16s\n"))
+            (insert (format frm
+                           "Standard Key" "Command" "In Your Emacs")))
           (dolist (tk changed-keys)
             (let* ((def-fun     (nth 1 tk))
                    (key         (nth 0 tk))
@@ -354,25 +358,20 @@ from the Emacs default in the " (buffer-name tutorial-buffer) " buffer:\n\n" )
                   (put-text-property 0 (length key-txt)
                                     'face 'tutorial-warning-face key-txt))
                 (insert "   " key-txt " ")
-                (setq tot-len (length key-txt))
-                (when (> 9 tot-len)
-                  (insert (make-string (- 9 tot-len) ?\s))
-                  (setq tot-len 9))
+               (indent-to 18)
                 ;; Insert a link describing the old binding:
                 (insert-button def-fun-txt
                                'value def-fun
                                'action
-                               (lambda(button) (interactive)
+                               (lambda (button) (interactive)
                                  (describe-function
                                   (button-get button 'value)))
                                'follow-link t)
-                (setq tot-len (+ tot-len (length def-fun-txt)))
-                (when (> 36 tot-len)
-                  (insert (make-string (- 36 tot-len) ?\s)))
+               (indent-to 45)
                 (when (listp where)
                   (setq where "list"))
                 ;; Tell where the old binding is now:
-                (insert (format " %-11s "
+                (insert (format " %-16s "
                                 (if (string= "" where)
                                     (format "M-x %s" def-fun-txt)
                                   where)))
@@ -381,7 +380,7 @@ from the Emacs default in the " (buffer-name tutorial-buffer) " buffer:\n\n" )
                 ;; cua-mode replacements:
                 (insert-button (car remark)
                                'action
-                               (lambda(b) (interactive)
+                               (lambda (b) (interactive)
                                  (let ((value (button-get b 'value)))
                                    (tutorial--describe-nonstandard-key value)))
                                'value (cdr remark)
@@ -407,8 +406,8 @@ where
   WHERE       is a text describing the key sequences to which DEF-FUN is
               bound now (or, if it is remapped, a key sequence
               for the function it is remapped to)
-  REMARK      is a list with info about rebinding. It has either of these
-              formats:
+  REMARK      is a list with info about rebinding. It has either of
+              these formats:
 
                 \(TEXT cua-mode)
                 \(TEXT current-binding KEY-FUN DEF-FUN KEY WHERE)
@@ -432,17 +431,35 @@ where
               (def-fun (nth 0 kdf))
               (def-fun-txt (format "%s" def-fun))
               (rem-fun (command-remapping def-fun))
+              ;; Handle prefix definitions specially
+              ;; so that a mode that rebinds some subcommands
+              ;; won't make it appear that the whole prefix is gone.
               (key-fun (if (eq def-fun 'ESC-prefix)
                            (lookup-key global-map [27])
-                         (key-binding key)))
-              (where (where-is-internal (if rem-fun rem-fun def-fun))))
+                         (if (eq def-fun 'Control-X-prefix)
+                             (lookup-key global-map [24])
+                           (key-binding key))))
+              (where (where-is-internal (if rem-fun rem-fun def-fun)))
+              cwhere)
+
          (if where
              (progn
-               (setq where (key-description (car where)))
+               (setq cwhere (car where)
+                     where (key-description cwhere))
                (when (and (< 10 (length where))
                           (string= (substring where 0 (length "<menu-bar>"))
                                    "<menu-bar>"))
-                 (setq where "the menus")))
+                 (setq where
+                       (if (and (vectorp cwhere)
+                                (setq cwhere (elt cwhere 1))
+                                (setq cwhere
+                                      (cadr
+                                       (assoc cwhere
+                                              (lookup-key global-map
+                                                          [menu-bar]))))
+                                (stringp cwhere))
+                           (format "the `%s' menu" cwhere)
+                         "the menus"))))
            (setq where ""))
          (setq remark nil)
          (unless
@@ -612,8 +629,7 @@ with some explanatory links."
 
 (defun tutorial--saved-dir ()
   "Directory to which tutorials are saved."
-  (expand-file-name "tutorial"
-                   (if (eq system-type 'ms-dos) "~/_emacs.d/" "~/.emacs.d/")))
+  (expand-file-name "tutorial" user-emacs-directory))
 
 (defun tutorial--saved-file ()
   "File name in which to save tutorials."
@@ -913,14 +929,14 @@ See `get-lang-string' for more information.")
 
 (defun get-lang-string (lang stringid &optional no-eng-fallback)
   "Get a language specific string for Emacs.
-In certain places Emacs can replace a string showed to the user with a language specific string.
-This function retrieves such strings.
+In certain places Emacs can replace a string shown to the user with
+a language specific string.  This function retrieves such strings.
 
 LANG is the language specification. It should be one of those
 strings that can be returned by `read-language-name'.  STRINGID
 is a symbol that specifies the string to retrieve.
 
-If no string is found for STRINGID in the choosen language then
+If no string is found for STRINGID in the chosen language then
 the English string is returned unless NO-ENG-FALLBACK is non-nil.
 
 See `lang-strings' for more information.