unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lennart Borgman <lennart.borgman.073@student.lu.se>
Cc: ihs_4664@yahoo.com, emacs-devel@gnu.org, storm@cua.dk
Subject: Re: Patch to remove minor modes in tutorial
Date: Sun, 02 Jul 2006 10:54:06 +0200	[thread overview]
Message-ID: <44A789AE.8040104@student.lu.se> (raw)
In-Reply-To: <E1FwpIu-0002Gs-8w@fencepost.gnu.org>

Richard Stallman wrote:
>     - It asks the user if the disturbing key bindings should be removed.
>
> As Kim pointed out, it should not ask.  And it probably should not
> turn off the modes, either.  It should just display a warning.
>   
Here is a new version where the question is still there but it is easy 
to turn off to test wether it feels right with the question or not. Just 
look for ask-user in the code.

I have also tried to take care of remapped functions.



(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")))
    file filename
        (point-after-message 1))
    (setq filename (get-language-info lang 'tutorial))
    (setq file (expand-file-name (concat "~/" filename)))
    (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)
      (setq default-directory (expand-file-name "~/"))
      (setq buffer-auto-save-file-name nil)
      (insert-file-contents (expand-file-name filename data-directory))
      (setq buffer-file-name nil)
      (hack-local-variables)


      ;; Check if there are key bindings or minor modes that may disturb
      ;; the tutorial. If so show them to the user and ask if they should
      ;; be disabled in the tutorial buffer.
      (let (minor-modes-added
            minor-modes
            minor-modes-disturbing
            other-disturbed-keys
            unknown
            (tutorial-keys
             '(
               (save-buffers-kill-emacs [(control ?x)(control ?c)])


               ;; * SUMMARY
               (scroll-up [(control ?v)])
               (scroll-down [(meta ?v)])
               (recenter [(control ?l)])


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

               (forward-word [(meta ?f)])
               (backward-word [(meta ?b)])

               (next-line [(control ?n)])
               (previous-line [(control ?p)])

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

               (backward-sentence [(meta ?a)])
               (forward-sentence [(meta ?e)])


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

               (universal-argument [(control ?u)])


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


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


               ;; * WINDOWS
               (delete-other-windows [(control ?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 [(control ?d)])

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

               (kill-line [(control ?k)])
               (kill-sentence [(meta ?k)])

               ;; You can also kill any part of the text with one 
uniform method.  Move
               (set-mark-command [(control ?@)])
               (set-mark-command [(control ? )])
               (kill-region [(control ?w)])
               (yank [(control ?y)])
               (yank-pop [(meta ?y)])


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


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


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


               ;; * EXTENDING THE COMMAND SET
               ;; C-x    Character eXtend.  Followed by one character.
               (execute-extended-command [(meta ?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 [(control ?h) ?m])

               (set-fill-column [(control ?x) ?f])
               (fill-paragraph [(meta ?q)])


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


               ;; * MULTIPLE WINDOWS
               (split-window-vertically [(control ?x) ?2])
               (scroll-other-window [(control meta ?v)])
               ;; (list "<ESC> C-v" 'scroll-other-window [escape 
(control-v)])
               (other-window [(control ?x) ?o])
               (find-file-other-window [(control ?x) ?4 (control ?f)])


               ;; * RECURSIVE EDITING LEVELS
               ;;(list "<ESC> <ESC> <ESC>" 'keyboard-escape-quit [escape 
escape escape])


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


               ;; * MORE FEATURES
               ;; F10


               ;; * CONCLUSION
               (iconify-or-deiconify-frame [(control ?z)])
               )
             )
            failed-keys
            still-failed-keys
            )

        (dolist (m minor-mode-list)
          (let ((fmode (or (get m :minor-mode-function) m)))
            (when (and (boundp m) (symbol-value m)
                       (fboundp fmode)
                       ;; Some minor modes have no bindings in the keymaps
                       ;; so ignore them:
                       (condition-case err
                           (progn
                             (unless
                                 (equal '(keymap)
                                        (symbol-value
                                         (read (concat (symbol-name m) 
"-map"))))
                               t))
                         (error nil)))
              (add-to-list 'minor-modes m))))
        (dolist (m minor-mode-alist)
          (add-to-list 'minor-modes (car m)))
        (dolist (m minor-modes)
          (when (symbol-value m)
            (add-to-list 'minor-modes-added m)))

        ;; Minor modes that are on by default (ie when starting with
        ;; "emacs -Q"):
        (dolist (m '(auto-compression-mode
                     blink-cursor-mode
                     encoded-kbd-mode
                     file-name-shadow-mode
                     font-lock-mode
                     global-font-lock-mode
                     line-number-mode
                     menu-bar-mode
                     mouse-wheel-mode
                     tool-bar-mode
                     tooltip-mode
                     unify-8859-on-encoding-mode
                     utf-translate-cjk-mode))
          (setq minor-modes-added (delete m minor-modes-added)))

        ;; What default key bindings used in the tutorial are
        ;; disturbed?
        (let ((initial-failing-keys))
          (with-temp-buffer
            (fundamental-mode)
            (dolist (tk tutorial-keys)
              (let* ((key (cadr tk))
                     (def-fun (car tk))
                     (rem-fun (command-remapping def-fun))
                     (key-fun (key-binding key))
                     (cp-tk (copy-sequence tk)))
                (unless (or (eq def-fun key-fun)
                            (eq rem-fun key-fun))
                  (add-to-list 'failed-keys tk)
                  (add-to-list 'initial-failing-keys cp-tk)))))

          ;; Which minor modes are disturbing the key bindings above?
          (dolist (m minor-modes-added)
            (let ((m-failing-keys))
              (with-temp-buffer
                (fundamental-mode)
                (make-local-variable m)
                (funcall m 0)
                (dolist (tk tutorial-keys)
                  (let* ((key (cadr tk))
                         (def-fun (car tk))
                         (rem-fun (command-remapping def-fun))
                         (key-fun (key-binding key))
                         (cp-tk (copy-sequence tk)))
                    (unless (or (eq def-fun key-fun)
                                (eq rem-fun key-fun))
                      ;;(setq cp-tk (cons key-fun cp-tk))
                      (add-to-list 'm-failing-keys cp-tk)))))
              (unless (equal m-failing-keys initial-failing-keys)
                (add-to-list 'minor-modes-disturbing m))))

          ;; Does it help removing all these keys and those in
          ;; emulation-mode-map-alist?
          (with-temp-buffer
            (fundamental-mode)
            (make-local-variable 'emulation-mode-map-alists)
            (setq emulation-mode-map-alists nil)
            (dolist (m minor-modes-disturbing)
              (make-local-variable m)
              (funcall m 0))
            (dolist (tk tutorial-keys)
              (let* ((key (cadr tk))
                     (def-fun (car tk))
                     (rem-fun (command-remapping def-fun))
                     (key-fun (key-binding key)))
                (unless (or (eq def-fun key-fun)
                            (eq rem-fun key-fun))
                  (add-to-list 'still-failed-keys tk)))))

        ;; Those are in emulation-mode-map-alists
        (when cua-mode
          (add-to-list 'minor-modes-disturbing 'cua-mode))
        (when viper-mode
          (add-to-list 'minor-modes-disturbing 'viper-mode))

        (when (or minor-modes-disturbing still-failed-keys)
          (setq minor-modes-disturbing (sort minor-modes-disturbing 
'string<))
          (let (remove-minor
                (ask-user t)
                (modes-disturbing (copy-seq minor-modes-disturbing))
                )
            (when ask-user
              ;; Ask the user if the possibly disturbing minor modes should
              ;; be disabled. This is to avoid confusing the user with the
              ;; different behaviour in the tutorial buffer when those modes
              ;; are disabled:
              (with-temp-buffer
                (insert "\nYou are using some minor modes (")
                (dolist (m modes-disturbing)
                  (insert (format "%s" (car modes-disturbing)))
                  (setq modes-disturbing (cdr modes-disturbing))
                  (if (= 1 (length modes-disturbing))
                      (insert " and ")
                    (when modes-disturbing (insert ", "))))
                (insert
                 ") which are overriding some default key bindings."
                 "  The behavior of Emacs with these modes may"
                 " not match what the tutorial teaches.\n\n"
                 "Do you want to disable these modes when you are in the 
tutorial? ")
                (when still-failed-keys
                  (insert "(Unfortunately in your case some key bindings"
                          " will still be overriden."
                          " You get more information about this 
later.)\n\n"))
                (insert
                 "(y-or-n)"
                 )
                (fill-region (point-min) (point-max))
                (let ((use-dialog-box nil))
                  (setq remove-minor
                        (y-or-n-p (format "%s " (buffer-substring
                                                 (point-min)
                                                 (- (point-max) 8))))))))
            (message "") ;; Shrinks mini-buffer window
            (if remove-minor
                (progn
                  (make-local-variable 'emulation-mode-map-alists)
                  (setq emulation-mode-map-alists nil)
                  (setq minor-modes-disturbing (delete 'cua-mode 
minor-modes-disturbing))
                  (setq minor-modes-disturbing (delete 'viper-mode 
minor-modes-disturbing))
                  (dolist (m minor-modes-disturbing)
                    (make-local-variable m)
                    ;; (set m nil) Better call the minor mode function
                    ;; according to RMS:
                    (funcall m 0)
                    )
                  (message "Disabled those minor modes for the tutorial 
only."))
              (when ask-user
                (message
                 "Please note that the tutorial may not work with this 
choice."))
              )
            (when (or still-failed-keys
                      (not remove-minor))
              (forward-line)
              (let ((start (point)))
                (cond
                 (remove-minor
                  (insert "
 NOTICE: One of the main purposes of the tutorial is that You
 should be able to learn some important Emacs default key
 bindings.  Even though you agreed to turn off minor modes with
 key bindings conflicting with the tutorial there are
 unfortunately still some conflicting key bindings left.  Those
 are probably set in your initialization files (~/.emacs etc).
 The folloing key bindings have still values that are changed
 from Emacs default:\n\n"
                          ))
                 ((not remove-minor)
                  (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 it was found that when you started the
 tutorial the following key bindings had been changed from
 Emacs default:\n\n"
                          ))
                 (t
                  (insert "
 INTERNAL ERROR! There was an internal error when starting the
 tutorial.\n\n"
                          ))
                 )
                (let ((frm "   %-14s %-26s %-18s %s\n")
                      (keys (if remove-minor still-failed-keys 
initial-failing-keys)))
                  (insert (format frm "KEY SEQUENCE" "DEFAULT BINDING" 
"USE NOW" "CURRENT BINDING"))
                  (dolist (tk keys)
                    (let* ((def-fun (car tk))
                           (key (cadr tk))
                           (rem-fun (command-remapping def-fun))
                           (use-key "")
                           (key-txt (key-description key))
                           (key-fun (key-binding key)))
                      (unless (eq def-fun key-fun)
                        (if rem-fun
                          (progn
                            (if (eq (key-binding key) rem-fun)
                                (setq use-key "Use same")
                              (let ((where (where-is-internal rem-fun)))
                                (when where
                                  (setq use-key (key-description (car 
where)))))))
                          (let ((where (where-is-internal def-fun)))
                            (when where
                              (setq use-key (key-description (car 
where))))))
                        (insert (format frm key-txt def-fun use-key 
(format "%s: %s" key-txt key-fun)))))))

                (insert "
 Please understand that it is quite ok to change key bindings in
 Emacs, but the tutorial may not work when you do that.\n\n"
                        )
                (put-text-property start (point)
                                   'face
                                   ;;'font-lock-warning-face
                                   (list :background "yellow"
                                         :foreground "#c00")
                                   )))

              (setq point-after-message (point))

              (goto-char (point-min))
              (set-buffer-modified-p nil)))))



      (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))))

  reply	other threads:[~2006-07-02  8:54 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-24 14:09 Patch to remove minor modes in tutorial Lennart Borgman
2006-06-25 15:34 ` Richard Stallman
2006-06-25 21:27   ` Lennart Borgman
2006-06-26 11:33     ` Richard Stallman
2006-06-26 13:48       ` Lennart Borgman
2006-06-26 16:31         ` Kevin Rodgers
2006-06-26 16:45           ` Lennart Borgman
2006-06-27 15:44             ` Kevin Rodgers
2006-06-27 16:41               ` Lennart Borgman
2006-06-28 17:25               ` Richard Stallman
2006-06-29  8:41                 ` Kim F. Storm
2006-06-29 12:07                   ` Mathias Dahl
2006-06-29 12:27                     ` David Kastrup
2006-06-30 11:06                       ` Richard Stallman
2006-06-29 17:57                   ` Richard Stallman
2006-07-01  0:38                     ` Lennart Borgman
2006-07-01 23:55                       ` Richard Stallman
2006-07-02  8:54                         ` Lennart Borgman [this message]
2006-07-02 22:30                           ` Richard Stallman
2006-07-07  0:01                             ` Lennart Borgman
2006-07-07 19:31                               ` Richard Stallman
2006-07-08  3:14                               ` Giorgos Keramidas
2006-07-08 20:57                               ` Richard Stallman
2006-07-09  8:44                                 ` Lennart Borgman
2006-07-17 16:12                                 ` Lennart Borgman
2006-07-17 17:32                                   ` Lennart Borgman
2006-07-24 14:42                                     ` Richard Stallman
2006-07-30 20:38                                       ` Lennart Borgman
2006-06-27 16:14         ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44A789AE.8040104@student.lu.se \
    --to=lennart.borgman.073@student.lu.se \
    --cc=emacs-devel@gnu.org \
    --cc=ihs_4664@yahoo.com \
    --cc=storm@cua.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).