emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Patch to remove minor modes in tutorial


From: Lennart Borgman
Subject: Re: Patch to remove minor modes in tutorial
Date: Mon, 17 Jul 2006 18:12:45 +0200
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

Richard Stallman wrote:
"You have enabled CUA mode" would be clearer.


Done.
Change that to

It is legitimate to change key bindings, but changed bindings do not correspond to what the tutorial says. (See also " )
Done.
It should simply have a list of those keys and their standard
bindings.  That way it would not need to read bindings.el.
I changed it to that (again).

I send the changes both as a standalone file and a patch this time. I have added this:

- The tutorial buffer is no longer associated with a file. I believe that is better.
- The tutorial can easily be restarted. A check is made for changes.
- The tutorial window is searched for.
- If any of the key bindings mentioned in the tutorial is changed then a list with those changes
 are shown in a special area in the beginning of the tutorial buffer.
- This area is read-only and have a yellow background.
- I have tried to explain what has happened to the key bindings. There are links to the
 explanations.
- I have taken special care of cua-mode (and a little bit of viper-mode too).


(defun help--describe-nonstandard-key(value)
  (let ((maps (current-active-maps t)))
    (with-output-to-temp-buffer (help-buffer)
      (help-setup-xref (list #'help-describe-nonstandard-key value)
                       (interactive-p))
      (with-current-buffer (help-buffer)
        (insert "Emacs default key binding has been changed in your setup:\n\n")
        (let ((inhibit-read-only t))
          (cond
           ((eq (car value) 'cua-mode)
            (insert
             "You have enabled `cua-mode'.

When `cua-mode' is enabled, you can use C-z, C-x, C-c, and C-v to
undo, cut, copy, and paste in addition to the normal Emacs
bindings.  The C-x and C-c keys only do cut and copy when the
region is active, so in most cases, they do not conflict with the
normal function of these prefix keys.

If you really need to perform a command which starts with one of
the prefix keys even when the region is active, you have three
options:
- press the prefix key twice very quickly (within 0.2 seconds),
- press the prefix key and the following key within 0.2 seconds, or
- use the SHIFT key with the prefix key, i.e. C-S-x or C-S-c."))
           ((eq (car value) 'current-binding)
            (let ((cb    (nth 1 value))
                  (db    (nth 2 value))
                  (key   (nth 3 value))
                  (where (nth 4 value))
                  map
                  mapsym)
              ;; Try to find the map where the binding occurs
              (while maps
                (let* ((m (car maps))
                       (mb (lookup-key m key t)))
                  (setq maps (cdr maps))
                  (when (eq mb cb)
                    (setq map m)
                    (setq maps nil))))
              (when map
                (if (eq map global-map)
                    (setq mapsym 'global-map)
                  (mapatoms (lambda (s)
                              (when (and (boundp s)
                                         (keymapp (symbol-value s)))
                                (unless (eq s 'map)
                                  (when (equal map (symbol-value s))
                                    (when (member map (current-active-maps))
                                      (setq mapsym s)))))))))
              (insert "Emacs default binding for the key "
                      (key-description key)
                      " is the function `")
              (insert (format "%s" db))
              (insert "'.  "
                      "This key has however been rebound to the function `")
              (insert (format "%s" cb))
              (insert "'.")
              (when mapsym
                (insert "  This binding is in the keymap variable `")
                (insert (format "%s" mapsym))
                (insert "'."))
              (if (string= where "")
                  (unless (keymapp db)
                    (insert "\n\nYou can use M-x "
                            (format "%s" db)
                            " RET instead."))
                (insert "\n\nWith you current key bindings"
                        " you can use the key "
                        where
                        " to get the function `"
                        (format "%s" db)
                        "'."))
              ))))
        (fill-region (point-min)(point))
        (print-help-return-message)))))

;;;###autoload
(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 choose which language."
  (interactive "P")
  (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")))
         (filename (get-language-info lang 'tutorial))
         (tut-buf-name (concat "TUTORIAL (" lang ")"))
         (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
                          (not (buffer-modified-p old-tut-buf))))
         (point-after-message 1))
    (when old-tut-win
      (raise-frame
       (window-frame
        (select-window (get-buffer-window old-tut-buf t)))))
    (when (and old-tut-buf
               (not old-tut-is-ok))
      (setq old-tut-is-ok
            (not (y-or-n-p
                  "You have changed the Tutorial buffer.  Revert it? "))))
    (delete-other-windows)
    (if old-tut-is-ok
        (switch-to-buffer (get-buffer tut-buf-name))
      (switch-to-buffer (get-buffer-create tut-buf-name))
      (let ((inhibit-read-only t))
        (erase-buffer))
      (message "Preparing tutorial ...")(sit-for 0)

      (setq default-directory (expand-file-name "~/"))
      (setq buffer-auto-save-file-name nil)
      (insert-file-contents (expand-file-name filename data-directory))
      (hack-local-variables)


      ;; Check if there are key bindings that may disturb the
      ;; tutorial.  If so tell the user.
      (let* (changed-keys
             (suspend-emacs (if window-system
                                'iconify-or-deiconify-frame
                              'suspend-emacs))
             (default-keys
               '(
                 ;; These are not mentioned but are basic:
                 (ESC-prefix [27])
                 (Control-X-prefix [?\C-x])
                 (mode-specific-command-prefix [?\C-c])

                 (save-buffers-kill-emacs [?\C-x ?\C-c])


                 ;; * SUMMARY
                 (scroll-up [?\C-v])
                 (scroll-down [?\M-v])
                 (recenter [?\C-l])


                 ;; * BASIC CURSOR CONTROL
                 (forward-char [?\C-f])
                 (backward-char [?\C-b])

                 (forward-word [?\M-f])
                 (backward-word [?\M-b])

                 (next-line [?\C-n])
                 (previous-line [?\C-p])

                 (move-beginning-of-line [?\C-a])
                 (move-end-of-line [?\C-e])

                 (backward-sentence [?\M-a])
                 (forward-sentence [?\M-e])


                 (beginning-of-buffer [?\M-<])
                 (end-of-buffer [?\M->])

                 (universal-argument [?\C-u])


                 ;; * WHEN EMACS IS HUNG
                 (keyboard-quit [?\C-g])


                 ;; * DISABLED COMMANDS
                 (downcase-region [?\C-x ?\C-l])


                 ;; * WINDOWS
                 (delete-other-windows [?\C-x ?1])
                 ;; C-u 0 C-l
                 ;; Type CONTROL-h k CONTROL-f.


                 ;; * INSERTING AND DELETING
                 ;; C-u 8 * to insert ********.

                 (delete-backward-char [backspace])
                 (delete-char [?\C-d])

                 (backward-kill-word [(meta backspace)])
                 (kill-word [?\M-d])

                 (kill-line [?\C-k])
                 (kill-sentence [?\M-k])

                 (set-mark-command address@hidden)
                 (set-mark-command [?\C- ])
                 (kill-region [?\C-w])
                 (yank [?\C-y])
                 (yank-pop [?\M-y])


                 ;; * UNDO
                 (advertised-undo [?\C-x ?u])
                 (advertised-undo [?\C-x ?u])


                 ;; * FILES
                 (find-file [?\C-x ?\C-f])
                 (save-buffer [?\C-x ?\C-s])


                 ;; * BUFFERS
                 (list-buffers [?\C-x ?\C-b])
                 (switch-to-buffer [?\C-x ?b])
                 (save-some-buffers [?\C-x ?s])


                 ;; * EXTENDING THE COMMAND SET
                 ;; C-x Character eXtend.  Followed by one character.
                 (execute-extended-command [?\M-x])

                 ;; C-x C-f             Find file
                 ;; C-x C-s             Save file
                 ;; C-x s               Save some buffers
                 ;; C-x C-b             List buffers
                 ;; C-x b               Switch buffer
                 ;; C-x C-c             Quit Emacs
                 ;; C-x 1               Delete all but one window
                 ;; C-x u               Undo


                 ;; * MODE LINE
                 (describe-mode [?\C-h ?m])

                 (set-fill-column [?\C-x ?f])
                 (fill-paragraph [?\M-q])


                 ;; * SEARCHING
                 (isearch-forward [?\C-s])
                 (isearch-backward [?\C-r])


                 ;; * MULTIPLE WINDOWS
                 (split-window-vertically [?\C-x ?2])
                 (scroll-other-window [?\C-\M-v])
                 (other-window [?\C-x ?o])
                 (find-file-other-window [?\C-x ?4 ?\C-f])


                 ;; * RECURSIVE EDITING LEVELS
                 (keyboard-escape-quit [27 27 27])


                 ;; * GETTING MORE HELP
                 ;; The most basic HELP feature is C-h c
                 (describe-key-briefly [?\C-h ?c])
                 (describe-key [?\C-h ?k])


                 ;; * MORE FEATURES
                 ;; F10


                 ;; * CONCLUSION
                 (iconify-or-deiconify-frame [?\C-z])
                 ))
             (sort-keys
              (lambda(left right)
                (let ((x (append (cadr left)  nil))
                      (y (append (cadr right) nil)))
                  (while (and x y
                              (equal (car x) (car y)))
                    (setq x (cdr x))
                    (setq y (cdr y)))
                  (let ((cx (car x))
                        (cy (car y)))
                    (cond ((and (listp cx)
                                (listp cy))
                           (> (length cx)(length cy)))
                          ((listp cx)
                           nil)
                          ((listp cy)
                           t)
                          ((and (symbolp cx)
                                (symbolp cy))
                           (string< (symbol-name cy)
                                    (symbol-name cx)))
                          ((symbolp cx)
                           nil)
                          ((symbolp cy)
                           t)
                          (t
                           (> (car x)(car y))))))))
             (tab-map (let ((map (make-sparse-keymap)))
                        (define-key map [tab] 'forward-button)
                        (define-key map [(shift tab)] 'backward-button)
                        (define-key map [(meta tab)] 'backward-button)
                        map)))
        (setq default-keys (sort default-keys sort-keys))

        (let (expr
              key
              def-fun
              def-fun-txt
              rem-fun
              key-fun
              where
              remark
              )
          (dolist (kdf default-keys)
            (setq key     (nth 1 kdf))
            (setq def-fun (nth 0 kdf))
            (setq def-fun-txt (format "%s" def-fun))
            (setq rem-fun (command-remapping def-fun))
            (setq key-fun (key-binding key))
            (setq where (where-is-internal (if rem-fun rem-fun def-fun)))
            (if where
                (progn
                  (setq where (key-description (car where)))
                  (when (and (< 10 (length where))
                             (string= (substring where 0 (length "<menu-bar>"))
                                      "<menu-bar>"))
                    (setq where "The menus")))
              (setq where ""))
            (setq remark nil)
            (unless
                (cond ( (eq key-fun def-fun)
                        t)
                      ( (eq key-fun (command-remapping def-fun))
                        (setq remark (list "Remapped" nil))
                        t)
                      ;; cua-mode specials:
                      ( (and cua-mode
                             (or (and
                                  (equal key [?\C-v])
                                  (eq key-fun 'cua-paste))
                                 (and
                                  (equal key [?\C-z])
                                  (eq key-fun 'undo))))
                        (setq remark (list "cua-mode, more info" 'cua-mode))
                        nil)
                      ( (and cua-mode
                             (or
                              (and (eq def-fun 'ESC-prefix)
                                   (equal key-fun
                                          `(keymap
                                            (118 . cua-repeat-replace-region))))
                              (and (eq def-fun 'mode-specific-command-prefix)
                                   (equal key-fun
                                          '(keymap
                                            (timeout . copy-region-as-kill))))
                              (and (eq def-fun 'Control-X-prefix)
                                   (equal key-fun
                                          '(keymap (timeout . kill-region))))))
                        (setq remark (list "cua-mode replacement" 'cua-mode))
                        (cond
                         ((eq def-fun 'mode-specific-command-prefix)
                          (setq def-fun-txt "\"C-c prefix\""))
                         ((eq def-fun 'Control-X-prefix)
                          (setq def-fun-txt "\"C-x prefix\""))
                         ((eq def-fun 'ESC-prefix)
                          (setq def-fun-txt "\"ESC prefix\"")))
                        (setq where "Same key")
                        nil)
                      ;; viper-mode specials:
                      ( (and viper-mode
                             (eq viper-current-state 'vi-state)
                             (or (and (eq def-fun 'isearch-forward)
                                      (eq key-fun 'viper-isearch-forward))
                                 (and (eq def-fun 'isearch-backward)
                                      (eq key-fun 'viper-isearch-backward))))
                        t)
                      ;; The strange handling of C-delete and
                      ;; C-backspace:
                      ( (when normal-erase-is-backspace
                          (or (and (equal key [C-delete])
                                   (equal key-fun 'kill-word))
                              (and (equal key [C-backspace])
                                   (equal key-fun 'backward-kill-word))))
                        t)
                      ( t
                        (setq remark
                              (list "more info" 'current-binding
                                    key-fun def-fun key where))
                        nil))
              (add-to-list 'changed-keys
                           (list key def-fun def-fun-txt where remark)))))

        (message "")(sit-for 0)
        (when changed-keys
          (forward-line)
          (let ((start (point))
                end)
            (insert "
 NOTICE: One of the main purposes of the tutorial is that You should
 be able to learn some important Emacs default key bindings.  However
 when you started the tutorial the following key bindings used in the
 tutorial had been changed from Emacs default:\n\n" )
            (let ((frm "   %-9s %-27s %-11s %s\n"))
              (insert (format frm "KEY" "DEFAULT BINDING" "IS NOW ON" 
"REMARK")))
            (dolist (tk changed-keys)
              (let* ((def-fun     (nth 1 tk))
                     (key         (nth 0 tk))
                     (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 (key-binding key))
                     tot-len)
                (unless (eq def-fun key-fun)
                  (insert "   " key-txt " ")
                  (setq tot-len (length key-txt))
                  (when (> 9 tot-len)
                    (insert (make-string (- 9 tot-len) ? ))
                    (setq tot-len 9))
                  (insert-button def-fun-txt
                                 'value def-fun
                                 'action
                                 (lambda(button) (interactive)
                                   (describe-function
                                    (button-get button 'value)))
                                 'follow-link t
                                 'read-only t
                                 'face '(:inherit link
                                                  :background "yellow"))
                  (setq tot-len (+ tot-len (length def-fun-txt)))
                  (when (> 36 tot-len)
                    (insert (make-string (- 36 tot-len) ? )))
                  (when (listp where)
                    (setq where "list"))
                  (insert (format " %-11s " where))
                  (insert-button (car remark)
                                 'action
                                 (lambda(b) (interactive)
                                   (let ((value (button-get b 'value)))
                                     (help--describe-nonstandard-key value)))
                                 'value (cdr remark)
                                 'follow-link t
                                 'face '(:inherit link
                                                  :background "yellow"))
                  (insert "\n"))))

            (when (and (boundp 'viper-mode)
                       viper-mode)
              (cond
               ((eq viper-current-state 'emacs-state)
                (insert "
   You have enabled viper mode, but in the tutorial buffer viper
   mode is currently turned off."))
               (t
                (insert "
   You have enabled viper mode. Some Emacs default key bindings
   will be unavailable. This is dependent on the state Viper is
   in.")))
              (insert "\n   If you want to learn viper keys please see the ")
              (insert-button "viper manual"
                             'action
                             (lambda(button) (interactive)
                               (info-other-window "(viper)")
                               (message "Type C-x 0 to close the new window"))
                             'follow-link t
                             'read-only t
                             'face '(:inherit link
                                              :background "yellow"))
              (insert ".\n"))

            (insert "
 It is legitimate to change key bindings, but changed bindings do not
 correspond to what the tutorial says.  (See also " )
            (insert-button "Key Binding Conventions"
                           'action
                           (lambda(button) (interactive)
                             (info-other-window
                              "(elisp) Key Binding Conventions")
                             (message "Type C-x 0 to close the new window"))
                           'follow-link t
                           'read-only t
                           'face '(:inherit link
                                            :background "yellow"))
            (insert ".)\n\n")
            (setq end (point))
            (put-text-property start end
                               'face
                               ;;'font-lock-warning-face
                               (list :background "yellow"
                                     :foreground "#c00"))
            (put-text-property start end 'local-map tab-map)
            (let ((inhibit-read-only t))
              (put-text-property start end 'read-only t)))))

      (setq point-after-message (point))

      (goto-char (point-min))

      (goto-char (point-min))
      (search-forward "\n<<")
      (beginning-of-line)
      ;; Convert the <<...>> line to the proper [...] line,
      ;; or just delete the <<...>> line if a [...] line follows.
      (cond ((save-excursion
               (forward-line 1)
               (looking-at "\\["))
             (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]"))
            (t
             (looking-at "<<")
             (replace-match "[")
             (search-forward ">>")
             (replace-match "]")))
      (beginning-of-line)
      (let ((n (- (window-height (selected-window))
                  (count-lines (point-min) (point))
                  6)))
        (if (< n 8)
            (progn
              ;; For a short gap, we don't need the [...] line,
              ;; so delete it.
              (delete-region (point) (progn (end-of-line) (point)))
              (newline n))
          ;; Some people get confused by the large gap.
          (newline (/ n 2))

          ;; Skip the [...] line (don't delete it).
          (forward-line 1)
          (newline (- n (/ n 2)))))
      (goto-char (point-min))
      (setq buffer-undo-list nil)
      (set-buffer-modified-p nil))))
Index: help-fns.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help-fns.el,v
retrieving revision 1.90
diff -u -r1.90 help-fns.el
--- help-fns.el 12 Jul 2006 15:58:10 -0000      1.90
+++ help-fns.el 17 Jul 2006 15:31:08 -0000
@@ -36,6 +36,83 @@
 (require 'help-mode)
 
 
+(defun help--describe-nonstandard-key(value)
+  (let ((maps (current-active-maps t)))
+    (with-output-to-temp-buffer (help-buffer)
+      (help-setup-xref (list #'help-describe-nonstandard-key value)
+                       (interactive-p))
+      (with-current-buffer (help-buffer)
+        (insert "Emacs default key binding has been changed in your 
setup:\n\n")
+        (let ((inhibit-read-only t))
+          (cond
+           ((eq (car value) 'cua-mode)
+            (insert
+             "You have enabled `cua-mode'.
+
+When `cua-mode' is enabled, you can use C-z, C-x, C-c, and C-v to
+undo, cut, copy, and paste in addition to the normal Emacs
+bindings.  The C-x and C-c keys only do cut and copy when the
+region is active, so in most cases, they do not conflict with the
+normal function of these prefix keys.
+
+If you really need to perform a command which starts with one of
+the prefix keys even when the region is active, you have three
+options:
+- press the prefix key twice very quickly (within 0.2 seconds),
+- press the prefix key and the following key within 0.2 seconds, or
+- use the SHIFT key with the prefix key, i.e. C-S-x or C-S-c."))
+           ((eq (car value) 'current-binding)
+            (let ((cb    (nth 1 value))
+                  (db    (nth 2 value))
+                  (key   (nth 3 value))
+                  (where (nth 4 value))
+                  map
+                  mapsym)
+              ;; Try to find the map where the binding occurs
+              (while maps
+                (let* ((m (car maps))
+                       (mb (lookup-key m key t)))
+                  (setq maps (cdr maps))
+                  (when (eq mb cb)
+                    (setq map m)
+                    (setq maps nil))))
+              (when map
+                (if (eq map global-map)
+                    (setq mapsym 'global-map)
+                  (mapatoms (lambda (s)
+                              (when (and (boundp s)
+                                         (keymapp (symbol-value s)))
+                                (unless (eq s 'map)
+                                  (when (equal map (symbol-value s))
+                                    (when (member map (current-active-maps))
+                                      (setq mapsym s)))))))))
+              (insert "Emacs default binding for the key "
+                      (key-description key)
+                      " is the function `")
+              (insert (format "%s" db))
+              (insert "'.  "
+                      "This key has however been rebound to the function `")
+              (insert (format "%s" cb))
+              (insert "'.")
+              (when mapsym
+                (insert "  This binding is in the keymap variable `")
+                (insert (format "%s" mapsym))
+                (insert "'."))
+              (if (string= where "")
+                  (unless (keymapp db)
+                    (insert "\n\nYou can use M-x "
+                            (format "%s" db)
+                            " RET instead."))
+                (insert "\n\nWith you current key bindings"
+                        " you can use the key "
+                        where
+                        " to get the function `"
+                        (format "%s" db)
+                        "'."))
+              ))))
+        (fill-region (point-min)(point))
+        (print-help-return-message)))))
+
 ;;;###autoload
 (defun help-with-tutorial (&optional arg)
   "Select the Emacs learn-by-doing tutorial.
@@ -44,58 +121,449 @@
 If there's no tutorial in that language, `TUTORIAL' is selected.
 With ARG, you are asked to choose which language."
   (interactive "P")
-  (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")))
-       file filename)
-    (setq filename (get-language-info lang 'tutorial))
-    (setq file (expand-file-name (concat "~/" filename)))
+  (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")))
+         (filename (get-language-info lang 'tutorial))
+         (tut-buf-name (concat "TUTORIAL (" lang ")"))
+         (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
+                          (not (buffer-modified-p old-tut-buf))))
+         (point-after-message 1))
+    (when old-tut-win
+      (raise-frame
+       (window-frame
+        (select-window (get-buffer-window old-tut-buf t)))))
+    (when (and old-tut-buf
+               (not old-tut-is-ok))
+      (setq old-tut-is-ok
+            (not (y-or-n-p
+                  "You have changed the Tutorial buffer.  Revert it? "))))
     (delete-other-windows)
-    (if (get-file-buffer file)
-       (switch-to-buffer (get-file-buffer file))
-      (switch-to-buffer (create-file-buffer file))
-      (setq buffer-file-name file)
+    (if old-tut-is-ok
+        (switch-to-buffer (get-buffer tut-buf-name))
+      (switch-to-buffer (get-buffer-create tut-buf-name))
+      (let ((inhibit-read-only t))
+        (erase-buffer))
+      (message "Preparing tutorial ...")(sit-for 0)
+
       (setq default-directory (expand-file-name "~/"))
       (setq buffer-auto-save-file-name nil)
       (insert-file-contents (expand-file-name filename data-directory))
       (hack-local-variables)
+
+
+      ;; Check if there are key bindings that may disturb the
+      ;; tutorial.  If so tell the user.
+      (let* (changed-keys
+             (suspend-emacs (if window-system
+                                'iconify-or-deiconify-frame
+                              'suspend-emacs))
+             (default-keys
+               '(
+                 ;; These are not mentioned but are basic:
+                 (ESC-prefix [27])
+                 (Control-X-prefix [?\C-x])
+                 (mode-specific-command-prefix [?\C-c])
+
+                 (save-buffers-kill-emacs [?\C-x ?\C-c])
+
+
+                 ;; * SUMMARY
+                 (scroll-up [?\C-v])
+                 (scroll-down [?\M-v])
+                 (recenter [?\C-l])
+
+
+                 ;; * BASIC CURSOR CONTROL
+                 (forward-char [?\C-f])
+                 (backward-char [?\C-b])
+
+                 (forward-word [?\M-f])
+                 (backward-word [?\M-b])
+
+                 (next-line [?\C-n])
+                 (previous-line [?\C-p])
+
+                 (move-beginning-of-line [?\C-a])
+                 (move-end-of-line [?\C-e])
+
+                 (backward-sentence [?\M-a])
+                 (forward-sentence [?\M-e])
+
+
+                 (beginning-of-buffer [?\M-<])
+                 (end-of-buffer [?\M->])
+
+                 (universal-argument [?\C-u])
+
+
+                 ;; * WHEN EMACS IS HUNG
+                 (keyboard-quit [?\C-g])
+
+
+                 ;; * DISABLED COMMANDS
+                 (downcase-region [?\C-x ?\C-l])
+
+
+                 ;; * WINDOWS
+                 (delete-other-windows [?\C-x ?1])
+                 ;; C-u 0 C-l
+                 ;; Type CONTROL-h k CONTROL-f.
+
+
+                 ;; * INSERTING AND DELETING
+                 ;; C-u 8 * to insert ********.
+
+                 (delete-backward-char [backspace])
+                 (delete-char [?\C-d])
+
+                 (backward-kill-word [(meta backspace)])
+                 (kill-word [?\M-d])
+
+                 (kill-line [?\C-k])
+                 (kill-sentence [?\M-k])
+
+                 (set-mark-command address@hidden)
+                 (set-mark-command [?\C- ])
+                 (kill-region [?\C-w])
+                 (yank [?\C-y])
+                 (yank-pop [?\M-y])
+
+
+                 ;; * UNDO
+                 (advertised-undo [?\C-x ?u])
+                 (advertised-undo [?\C-x ?u])
+
+
+                 ;; * FILES
+                 (find-file [?\C-x ?\C-f])
+                 (save-buffer [?\C-x ?\C-s])
+
+
+                 ;; * BUFFERS
+                 (list-buffers [?\C-x ?\C-b])
+                 (switch-to-buffer [?\C-x ?b])
+                 (save-some-buffers [?\C-x ?s])
+
+
+                 ;; * EXTENDING THE COMMAND SET
+                 ;; C-x        Character eXtend.  Followed by one character.
+                 (execute-extended-command [?\M-x])
+
+                 ;; C-x C-f            Find file
+                 ;; C-x C-s            Save file
+                 ;; C-x s              Save some buffers
+                 ;; C-x C-b            List buffers
+                 ;; C-x b              Switch buffer
+                 ;; C-x C-c            Quit Emacs
+                 ;; C-x 1              Delete all but one window
+                 ;; C-x u              Undo
+
+
+                 ;; * MODE LINE
+                 (describe-mode [?\C-h ?m])
+
+                 (set-fill-column [?\C-x ?f])
+                 (fill-paragraph [?\M-q])
+
+
+                 ;; * SEARCHING
+                 (isearch-forward [?\C-s])
+                 (isearch-backward [?\C-r])
+
+
+                 ;; * MULTIPLE WINDOWS
+                 (split-window-vertically [?\C-x ?2])
+                 (scroll-other-window [?\C-\M-v])
+                 (other-window [?\C-x ?o])
+                 (find-file-other-window [?\C-x ?4 ?\C-f])
+
+
+                 ;; * RECURSIVE EDITING LEVELS
+                 (keyboard-escape-quit [27 27 27])
+
+
+                 ;; * GETTING MORE HELP
+                 ;; The most basic HELP feature is C-h c
+                 (describe-key-briefly [?\C-h ?c])
+                 (describe-key [?\C-h ?k])
+
+
+                 ;; * MORE FEATURES
+                 ;; F10
+
+
+                 ;; * CONCLUSION
+                 (iconify-or-deiconify-frame [?\C-z])
+                 ))
+             (sort-keys
+              (lambda(left right)
+                (let ((x (append (cadr left)  nil))
+                      (y (append (cadr right) nil)))
+                  (while (and x y
+                              (equal (car x) (car y)))
+                    (setq x (cdr x))
+                    (setq y (cdr y)))
+                  (let ((cx (car x))
+                        (cy (car y)))
+                    (cond ((and (listp cx)
+                                (listp cy))
+                           (> (length cx)(length cy)))
+                          ((listp cx)
+                           nil)
+                          ((listp cy)
+                           t)
+                          ((and (symbolp cx)
+                                (symbolp cy))
+                           (string< (symbol-name cy)
+                                    (symbol-name cx)))
+                          ((symbolp cx)
+                           nil)
+                          ((symbolp cy)
+                           t)
+                          (t
+                           (> (car x)(car y))))))))
+             (tab-map (let ((map (make-sparse-keymap)))
+                        (define-key map [tab] 'forward-button)
+                        (define-key map [(shift tab)] 'backward-button)
+                        (define-key map [(meta tab)] 'backward-button)
+                        map)))
+        (setq default-keys (sort default-keys sort-keys))
+
+        (let (expr
+              key
+              def-fun
+              def-fun-txt
+              rem-fun
+              key-fun
+              where
+              remark
+              )
+          (dolist (kdf default-keys)
+            (setq key     (nth 1 kdf))
+            (setq def-fun (nth 0 kdf))
+            (setq def-fun-txt (format "%s" def-fun))
+            (setq rem-fun (command-remapping def-fun))
+            (setq key-fun (key-binding key))
+            (setq where (where-is-internal (if rem-fun rem-fun def-fun)))
+            (if where
+                (progn
+                  (setq where (key-description (car where)))
+                  (when (and (< 10 (length where))
+                             (string= (substring where 0 (length "<menu-bar>"))
+                                      "<menu-bar>"))
+                    (setq where "The menus")))
+              (setq where ""))
+            (setq remark nil)
+            (unless
+                (cond ( (eq key-fun def-fun)
+                        t)
+                      ( (eq key-fun (command-remapping def-fun))
+                        (setq remark (list "Remapped" nil))
+                        t)
+                      ;; cua-mode specials:
+                      ( (and cua-mode
+                             (or (and
+                                  (equal key [?\C-v])
+                                  (eq key-fun 'cua-paste))
+                                 (and
+                                  (equal key [?\C-z])
+                                  (eq key-fun 'undo))))
+                        (setq remark (list "cua-mode, more info" 'cua-mode))
+                        nil)
+                      ( (and cua-mode
+                             (or
+                              (and (eq def-fun 'ESC-prefix)
+                                   (equal key-fun
+                                          `(keymap
+                                            (118 . 
cua-repeat-replace-region))))
+                              (and (eq def-fun 'mode-specific-command-prefix)
+                                   (equal key-fun
+                                          '(keymap
+                                            (timeout . copy-region-as-kill))))
+                              (and (eq def-fun 'Control-X-prefix)
+                                   (equal key-fun
+                                          '(keymap (timeout . kill-region))))))
+                        (setq remark (list "cua-mode replacement" 'cua-mode))
+                        (cond
+                         ((eq def-fun 'mode-specific-command-prefix)
+                          (setq def-fun-txt "\"C-c prefix\""))
+                         ((eq def-fun 'Control-X-prefix)
+                          (setq def-fun-txt "\"C-x prefix\""))
+                         ((eq def-fun 'ESC-prefix)
+                          (setq def-fun-txt "\"ESC prefix\"")))
+                        (setq where "Same key")
+                        nil)
+                      ;; viper-mode specials:
+                      ( (and viper-mode
+                             (eq viper-current-state 'vi-state)
+                             (or (and (eq def-fun 'isearch-forward)
+                                      (eq key-fun 'viper-isearch-forward))
+                                 (and (eq def-fun 'isearch-backward)
+                                      (eq key-fun 'viper-isearch-backward))))
+                        t)
+                      ;; The strange handling of C-delete and
+                      ;; C-backspace:
+                      ( (when normal-erase-is-backspace
+                          (or (and (equal key [C-delete])
+                                   (equal key-fun 'kill-word))
+                              (and (equal key [C-backspace])
+                                   (equal key-fun 'backward-kill-word))))
+                        t)
+                      ( t
+                        (setq remark
+                              (list "more info" 'current-binding
+                                    key-fun def-fun key where))
+                        nil))
+              (add-to-list 'changed-keys
+                           (list key def-fun def-fun-txt where remark)))))
+
+        (message "")(sit-for 0)
+        (when changed-keys
+          (forward-line)
+          (let ((start (point))
+                end)
+            (insert "
+ NOTICE: One of the main purposes of the tutorial is that You should
+ be able to learn some important Emacs default key bindings.  However
+ when you started the tutorial the following key bindings used in the
+ tutorial had been changed from Emacs default:\n\n" )
+            (let ((frm "   %-9s %-27s %-11s %s\n"))
+              (insert (format frm "KEY" "DEFAULT BINDING" "IS NOW ON" 
"REMARK")))
+            (dolist (tk changed-keys)
+              (let* ((def-fun     (nth 1 tk))
+                     (key         (nth 0 tk))
+                     (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 (key-binding key))
+                     tot-len)
+                (unless (eq def-fun key-fun)
+                  (insert "   " key-txt " ")
+                  (setq tot-len (length key-txt))
+                  (when (> 9 tot-len)
+                    (insert (make-string (- 9 tot-len) ? ))
+                    (setq tot-len 9))
+                  (insert-button def-fun-txt
+                                 'value def-fun
+                                 'action
+                                 (lambda(button) (interactive)
+                                   (describe-function
+                                    (button-get button 'value)))
+                                 'follow-link t
+                                 'read-only t
+                                 'face '(:inherit link
+                                                  :background "yellow"))
+                  (setq tot-len (+ tot-len (length def-fun-txt)))
+                  (when (> 36 tot-len)
+                    (insert (make-string (- 36 tot-len) ? )))
+                  (when (listp where)
+                    (setq where "list"))
+                  (insert (format " %-11s " where))
+                  (insert-button (car remark)
+                                 'action
+                                 (lambda(b) (interactive)
+                                   (let ((value (button-get b 'value)))
+                                     (help--describe-nonstandard-key value)))
+                                 'value (cdr remark)
+                                 'follow-link t
+                                 'face '(:inherit link
+                                                  :background "yellow"))
+                  (insert "\n"))))
+
+            (when (and (boundp 'viper-mode)
+                       viper-mode)
+              (cond
+               ((eq viper-current-state 'emacs-state)
+                (insert "
+   You have enabled viper mode, but in the tutorial buffer viper
+   mode is currently turned off."))
+               (t
+                (insert "
+   You have enabled viper mode. Some Emacs default key bindings
+   will be unavailable. This is dependent on the state Viper is
+   in.")))
+              (insert "\n   If you want to learn viper keys please see the ")
+              (insert-button "viper manual"
+                             'action
+                             (lambda(button) (interactive)
+                               (info-other-window "(viper)")
+                               (message "Type C-x 0 to close the new window"))
+                             'follow-link t
+                             'read-only t
+                             'face '(:inherit link
+                                              :background "yellow"))
+              (insert ".\n"))
+
+            (insert "
+ It is legitimate to change key bindings, but changed bindings do not
+ correspond to what the tutorial says.  (See also " )
+            (insert-button "Key Binding Conventions"
+                           'action
+                           (lambda(button) (interactive)
+                             (info-other-window
+                              "(elisp) Key Binding Conventions")
+                             (message "Type C-x 0 to close the new window"))
+                           'follow-link t
+                           'read-only t
+                           'face '(:inherit link
+                                            :background "yellow"))
+            (insert ".)\n\n")
+            (setq end (point))
+            (put-text-property start end
+                               'face
+                               ;;'font-lock-warning-face
+                               (list :background "yellow"
+                                     :foreground "#c00"))
+            (put-text-property start end 'local-map tab-map)
+            (let ((inhibit-read-only t))
+              (put-text-property start end 'read-only t)))))
+
+      (setq point-after-message (point))
+
+      (goto-char (point-min))
+
       (goto-char (point-min))
       (search-forward "\n<<")
       (beginning-of-line)
       ;; Convert the <<...>> line to the proper [...] line,
       ;; or just delete the <<...>> line if a [...] line follows.
       (cond ((save-excursion
-              (forward-line 1)
-              (looking-at "\\["))
-            (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]"))
-           (t
-            (looking-at "<<")
-            (replace-match "[")
-            (search-forward ">>")
-            (replace-match "]")))
+               (forward-line 1)
+               (looking-at "\\["))
+             (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]"))
+            (t
+             (looking-at "<<")
+             (replace-match "[")
+             (search-forward ">>")
+             (replace-match "]")))
       (beginning-of-line)
       (let ((n (- (window-height (selected-window))
-                 (count-lines (point-min) (point))
-                 6)))
-       (if (< n 8)
-           (progn
-             ;; For a short gap, we don't need the [...] line,
-             ;; so delete it.
-             (delete-region (point) (progn (end-of-line) (point)))
-             (newline n))
-         ;; Some people get confused by the large gap.
-         (newline (/ n 2))
-
-         ;; Skip the [...] line (don't delete it).
-         (forward-line 1)
-         (newline (- n (/ n 2)))))
+                  (count-lines (point-min) (point))
+                  6)))
+        (if (< n 8)
+            (progn
+              ;; For a short gap, we don't need the [...] line,
+              ;; so delete it.
+              (delete-region (point) (progn (end-of-line) (point)))
+              (newline n))
+          ;; Some people get confused by the large gap.
+          (newline (/ n 2))
+
+          ;; Skip the [...] line (don't delete it).
+          (forward-line 1)
+          (newline (- n (/ n 2)))))
       (goto-char (point-min))
       (setq buffer-undo-list nil)
       (set-buffer-modified-p nil))))
@@ -252,8 +720,8 @@
                          "\\)"
                          "\\(?:es\\|s\\|th\\)?"  ; for ARGth, ARGs
                          "\\(?:-[a-z0-9-]+\\)?"  ; for ARG-xxx, ARG-n
-                         "\\(?:-[{([<`\"].*?\\)?"; for ARG-{x}, (x), <x>, [x], 
`x'
-                         "\\>")                  ; end of word
+                         "\\(?:-[{([<`\"].*?\\)?" ; for ARG-{x}, (x), <x>, 
[x], `x'
+                         "\\>")                   ; end of word
                  (help-default-arg-highlight arg)
                  doc t t 1)))))
 
@@ -419,23 +887,23 @@
         ;; If definition is a keymap, skip arglist note.
         (unless (keymapp def)
           (let* ((use (cond
-                        (usage (setq doc (cdr usage)) (car usage))
-                        ((listp arglist)
-                         (format "%S" (help-make-usage function arglist)))
-                        ((stringp arglist) arglist)
-                        ;; Maybe the arglist is in the docstring of the alias.
-                        ((let ((fun function))
-                           (while (and (symbolp fun)
-                                       (setq fun (symbol-function fun))
-                                       (not (setq usage (help-split-fundoc
-                                                         (documentation fun)
-                                                         function)))))
-                           usage)
-                         (car usage))
-                        ((or (stringp def)
-                             (vectorp def))
-                         (format "\nMacro: %s" (format-kbd-macro def)))
-                        (t "[Missing arglist.  Please make a bug report.]")))
+                       (usage (setq doc (cdr usage)) (car usage))
+                       ((listp arglist)
+                        (format "%S" (help-make-usage function arglist)))
+                       ((stringp arglist) arglist)
+                       ;; Maybe the arglist is in the docstring of the alias.
+                       ((let ((fun function))
+                          (while (and (symbolp fun)
+                                      (setq fun (symbol-function fun))
+                                      (not (setq usage (help-split-fundoc
+                                                        (documentation fun)
+                                                        function)))))
+                          usage)
+                        (car usage))
+                       ((or (stringp def)
+                            (vectorp def))
+                        (format "\nMacro: %s" (format-kbd-macro def)))
+                       (t "[Missing arglist.  Please make a bug report.]")))
                  (high (help-highlight-arguments use doc)))
             (let ((fill-begin (point)))
              (insert (car high) "\n")
@@ -628,8 +1096,8 @@
 
            ;; Mention if it's an alias
             (let* ((alias (condition-case nil
-                             (indirect-variable variable)
-                           (error variable)))
+                              (indirect-variable variable)
+                            (error variable)))
                    (obsolete (get variable 'byte-obsolete-variable))
                   (safe-var (get variable 'safe-local-variable))
                    (doc (or (documentation-property variable 
'variable-documentation)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]