]> code.delx.au - gnu-emacs/blobdiff - lisp/tutorial.el
Some hi-lock doc
[gnu-emacs] / lisp / tutorial.el
index 456fe5f401e8b277c10c44e8790117ccde5e65ab..9b58b563729e5005cb8b4291c792ab6e2902fbee 100644 (file)
@@ -1,9 +1,10 @@
 ;;; tutorial.el --- tutorial for Emacs
 
-;; Copyright (C) 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2006-2014 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: help, internal
+;; Package: emacs
 
 ;; This file is part of GNU Emacs.
 
@@ -74,7 +75,7 @@ Where
               for the function it is remapped to)"
   (with-output-to-temp-buffer (help-buffer)
     (help-setup-xref (list #'tutorial--describe-nonstandard-key value)
-                     (interactive-p))
+                     (called-interactively-p 'interactive))
     (with-current-buffer (help-buffer)
       (insert
        "Your Emacs customizations override the default binding for this key:"
@@ -138,9 +139,11 @@ options:
                     " is the command `")
             (insert (format "%s" db))
             (insert "'.  "
-                    "However, your customizations have rebound it to the command `")
-            (insert (format "%s" cb))
-            (insert "'.")
+                    "However, your customizations have "
+                    (if cb
+                        (format "rebound it to the command `%s'" cb)
+                      "unbound it"))
+            (insert ".")
             (when mapsym
               (insert "  (For the more advanced user:"
                       " This binding is in the keymap `"
@@ -153,7 +156,7 @@ options:
                           " RET instead."))
               (insert "\n\nWith your current key bindings"
                       " you can use "
-                      (if (string-match "^the .*menus?$" where)
+                      (if (string-match-p "^the .*menus?$" where)
                           ""
                         "the key")
                       where
@@ -161,7 +164,7 @@ options:
                       (format "%s" db)
                       "'.")))
           (fill-region (point-min) (point)))))
-      (print-help-return-message))))
+      (help-print-return-message))))
 
 (defun tutorial--sort-keys (left right)
   "Sort predicate for use with `tutorial--default-keys'.
@@ -179,7 +182,7 @@ LEFT and RIGHT are the elements to compare."
                 (equal (car x) (car y)))
       (setq x (cdr x))
       (setq y (cdr y)))
-    ;; Try to make a comparision that is useful for presentation (this
+    ;; Try to make a comparison that is useful for presentation (this
     ;; could be made nicer perhaps):
     (let ((cx (car x))
           (cy (car y)))
@@ -216,8 +219,8 @@ LEFT and RIGHT are the elements to compare."
              (save-buffers-kill-terminal [?\C-x ?\C-c])
 
              ;; * SUMMARY
-             (scroll-up [?\C-v])
-             (scroll-down [?\M-v])
+             (scroll-up-command [?\C-v])
+             (scroll-down-command [?\M-v])
              (recenter-top-bottom [?\C-l])
 
              ;; * BASIC CURSOR CONTROL
@@ -262,8 +265,7 @@ LEFT and RIGHT are the elements to compare."
              (yank-pop [?\M-y])
 
              ;; * UNDO
-             (advertised-undo [?\C-x ?u])
-             (advertised-undo [?\C-x ?u])
+             (undo [?\C-x ?u])
 
              ;; * FILES
              (find-file [?\C-x ?\C-f])
@@ -296,7 +298,7 @@ LEFT and RIGHT are the elements to compare."
              (isearch-backward [?\C-r])
 
              ;; * MULTIPLE WINDOWS
-             (split-window-vertically [?\C-x ?2])
+             (split-window-below [?\C-x ?2])
              (scroll-other-window [?\C-\M-v])
              (other-window [?\C-x ?o])
              (find-file-other-window [?\C-x ?4 ?\C-f])
@@ -322,7 +324,7 @@ LEFT and RIGHT are the elements to compare."
   "Give detailed help about changed keys."
   (with-output-to-temp-buffer (help-buffer)
     (help-setup-xref (list #'tutorial--detailed-help button)
-                     (interactive-p))
+                     (called-interactively-p 'interactive))
     (with-current-buffer (help-buffer)
       (let* ((tutorial-buffer  (button-get button 'tutorial-buffer))
              (explain-key-desc (button-get button 'explain-key-desc))
@@ -344,10 +346,8 @@ from the Emacs default:\n\n" )
                    (def-fun-txt (nth 2 tk))
                    (where       (nth 3 tk))
                    (remark      (nth 4 tk))
-                   (rem-fun (command-remapping def-fun))
                    (key-txt (key-description key))
-                   (key-fun (with-current-buffer tutorial-buffer (key-binding key)))
-                   tot-len)
+                   (key-fun (with-current-buffer tutorial-buffer (key-binding key))))
               (unless (eq def-fun key-fun)
                 ;; Insert key binding description:
                 (when (string= key-txt explain-key-desc)
@@ -386,7 +386,7 @@ from the Emacs default:\n\n" )
         (insert "
 It is OK to change key bindings, but changed bindings do not
 correspond to what the tutorial says.\n\n")
-        (print-help-return-message)))))
+        (help-print-return-message)))))
 
 (defun tutorial--find-changed-keys (default-keys)
   "Find the key bindings used in the tutorial that have changed.
@@ -583,7 +583,6 @@ with some explanatory links."
           (not (get-text-property (match-beginning 1) 'tutorial-remark))
           (let* ((desc    (car changed-key))
                  (ck      (cdr changed-key))
-                 (key     (nth 0 ck))
                  (def-fun (nth 1 ck))
                  (where   (nth 3 ck))
                  s1 s2 help-string)
@@ -722,9 +721,7 @@ See `tutorial--save-tutorial' for more information."
                            saved-file
                            (error-message-string err))))
             ;; An error is raised here?? Is this a bug?
-            (condition-case err
-                (undo-only)
-              (error nil))
+            (ignore-errors (undo-only))
             ;; Restore point
             (goto-char old-point)
             (if save-err
@@ -764,18 +761,15 @@ Run the Viper tutorial? "))
                       (funcall 'viper-tutorial 0))
              (message "Tutorial aborted by user"))
          (message prompt1)))
-    (let* ((lang (if arg
-                     (let ((minibuffer-setup-hook minibuffer-setup-hook))
-                       (add-hook 'minibuffer-setup-hook
-                                 'minibuffer-completion-help)
-                       (read-language-name 'tutorial "Language: " "English"))
-                   (if (get-language-info current-language-environment 'tutorial)
-                       current-language-environment
-                     "English")))
+    (let* ((lang (cond
+                  (arg
+                   (minibuffer-with-setup-hook #'minibuffer-completion-help
+                     (read-language-name 'tutorial "Language: " "English")))
+                  ((get-language-info current-language-environment 'tutorial)
+                   current-language-environment)
+                  (t "English")))
            (filename (get-language-info lang 'tutorial))
-           ;; Choose a buffer name including the language so that
-           ;; several languages can be tested simultaneously:
-           (tut-buf-name (concat "TUTORIAL (" lang ")"))
+           (tut-buf-name filename)
            (old-tut-buf (get-buffer tut-buf-name))
            (old-tut-win (when old-tut-buf (get-buffer-window old-tut-buf t)))
            (old-tut-is-ok (when old-tut-buf
@@ -807,7 +801,7 @@ Run the Viper tutorial? "))
       ;; (Re)build the tutorial buffer if it is not ok
       (unless old-tut-is-ok
         (switch-to-buffer (get-buffer-create tut-buf-name))
-        (unless old-tut-buf (text-mode))
+        ;; (unless old-tut-buf (text-mode))
         (unless lang (error "Variable lang is nil"))
         (setq tutorial--lang lang)
         (setq old-tut-file (file-exists-p (tutorial--saved-file)))
@@ -830,6 +824,10 @@ Run the Viper tutorial? "))
         (if old-tut-file
             (progn
               (insert-file-contents (tutorial--saved-file))
+             (let ((enable-local-variables :safe)
+                    (enable-local-eval nil)
+                    (enable-dir-local-variables nil)) ; bug#11127
+               (hack-local-variables))
               (goto-char (point-min))
               (setq old-tut-point
                     (string-to-number
@@ -845,6 +843,10 @@ Run the Viper tutorial? "))
               (goto-char tutorial--point-before-chkeys)
               (setq tutorial--point-before-chkeys (point-marker)))
           (insert-file-contents (expand-file-name filename tutorial-directory))
+         (let ((enable-local-variables :safe)
+                (enable-local-eval nil)
+                (enable-dir-local-variables nil)) ; bug#11127
+           (hack-local-variables))
           (forward-line)
           (setq tutorial--point-before-chkeys (point-marker)))
 
@@ -864,6 +866,10 @@ Run the Viper tutorial? "))
               (when (< old-point 1)
                 (setq old-point 1))
               (goto-char old-point))
+          ;; Delete the arch-tag line, so as not to confuse readers.
+          (goto-char (point-max))
+          (if (search-backward ";;; arch-tag: " nil t)
+              (delete-region (point) (point-max)))
           (goto-char (point-min))
           (search-forward "\n<<")
           (beginning-of-line)
@@ -871,7 +877,7 @@ Run the Viper tutorial? "))
           ;; or just delete the <<...>> line if a [...] line follows.
           (cond ((save-excursion
                    (forward-line 1)
-                   (looking-at "\\["))
+                   (looking-at-p "\\["))
                  (delete-region (point) (progn (forward-line 1) (point))))
                 ((looking-at "<<Blank lines inserted.*>>")
                  (replace-match "[Middle of page left blank for didactic purposes.   Text continues below]"))
@@ -881,7 +887,12 @@ Run the Viper tutorial? "))
                  (search-forward ">>")
                  (replace-match "]")))
           (beginning-of-line)
-          (let ((n (- (window-height (selected-window))
+          ;; FIXME: if the window is not tall, and especially if the
+          ;; big red "NOTICE: The main purpose..." text has been
+          ;; inserted at the start of the buffer, the "type C-v to
+          ;; move to the next screen" might not be visible on the
+          ;; first screen (n < 0).  How will the novice know what to do?
+          (let ((n (- (window-height)
                       (count-lines (point-min) (point))
                       6)))
             (if (< n 8)
@@ -889,7 +900,7 @@ Run the Viper tutorial? "))
                   ;; For a short gap, we don't need the [...] line,
                   ;; so delete it.
                   (delete-region (point) (progn (end-of-line) (point)))
-                  (newline n))
+                  (if (> n 0) (newline n)))
               ;; Some people get confused by the large gap.
               (newline (/ n 2))
 
@@ -929,7 +940,7 @@ See `get-lang-string' for more information.")
 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
+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.
 
@@ -955,5 +966,4 @@ Currently this feature is only used in `help-with-tutorial'."
 
 (provide 'tutorial)
 
-;; arch-tag: c8e80aef-c3bb-4ffb-8af6-22171bf0c100
 ;;; tutorial.el ends here