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: Sun, 25 Jun 2006 23:27:23 +0200
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

Richard Stallman wrote:
    +  ;; Check if minor modes may disturb

That is not an accurate description of what the new code does.
It only describes a _part_ of what the code does.
It ought to describe the _overall action_.
Thanks. I will enhance the description.

    +                 (condition-case err
    +                     (progn
    +                       (unless
    +                           (equal '(keymap)
    +                                  (symbol-value
    +                                   (read (concat (symbol-name m) "-map"))))
    +                         t))
    +                   (error nil)))

What is that code supposed to do?  And why?
Some minor modes have no keybindings so they can not disturb the tutorial (recentf-mode for example). Well, at least I hope they can not. I think this is very important!

    +    ;; Default minor modes
    +    (dolist (m '(auto-compression-mode

That comment makes no sense to me.  What was the reason
for choosing which modes to put in this list?
I will change that. The modes I am referring to are those that are on when starting Emacs with -Q.

    +          (insert
    +           ") which can possibly override global 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?"
    +           "(y-or-n)"
    +           )

Why ask?  Why not just do it?
To make the user aware of that Emacs will work differently in the tutorial buffer than in other buffer (if the user answers Y).

    +              (make-local-variable 'emulation-mode-map-alists)
    +              (setq emulation-mode-map-alists nil)
    +              (dolist (m minor-modes-on)
    +                (make-local-variable m)
    +                (set m nil))

Nowadays there are minor modes that can't be turned off this way.
You need to call the function.
I have changed that.


    @@ -325,6 +404,8 @@
                     "a Lisp macro")
                    ((eq (car-safe def) 'autoload)
                     (setq file-name (nth 1 def))
    +            (let ((loc (locate-library file-name)))
    +                   (when loc (setq file-name loc)))
                     (format "%s autoloaded %s"
                             (if (commandp def) "an interactive" "an")

What is that for?
I did not think of that patch. I noticed that in some cases file-name here is not a file name at all but the library name (or was it the file name without the path??). This part of the patch may not be the correct cure for those cases though and unfortunately I do not remember which autoloaded function I saw this for. I should have made a note of course, but I thought I would have had time to finish this earlier.


------------------------
Here is a new patch:

Index: help-fns.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/help-fns.el,v
retrieving revision 1.89
diff -u -r1.89 help-fns.el
--- help-fns.el    11 May 2006 11:10:45 -0000    1.89
+++ help-fns.el    25 Jun 2006 21:16:22 -0000
@@ -98,7 +98,98 @@
      (newline (- n (/ n 2)))))
      (goto-char (point-min))
      (setq buffer-undo-list nil)
-      (set-buffer-modified-p nil))))
+      (set-buffer-modified-p nil)))
+
+  ;; Check if there are 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-on minor-modes unknown)
+    (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-on 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-on (delete m minor-modes-on)))
+
+    ;; Special
+    (when cua-mode
+      (add-to-list 'minor-modes-on 'cua-mode))
+
+    (when minor-modes-on
+      (setq minor-modes-on (sort minor-modes-on 'string<))
+      (let (remove-minor
+            (modes-on (copy-seq minor-modes-on))
+            )
+        ;; 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-on)
+            (insert (format "%s" (car modes-on)))
+            (setq modes-on (cdr modes-on))
+            (if (= 1 (length modes-on))
+                (insert " and ")
+              (when modes-on (insert ", "))))
+          (insert
+           ") which can possibly override global 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?"
+           "(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)))))))
+        (if remove-minor
+            (progn
+              (make-local-variable 'emulation-mode-map-alists)
+              (setq emulation-mode-map-alists nil)
+              (dolist (m minor-modes-on)
+                (make-local-variable m)
+                ;; (set m nil) Better call the minor mode function
+                ;; according to RMS:
+                (funcall m 0)
+                )
+              (message "Removed those bindings for the tutorial only."))
+          (message
+           "Please note that the tutorial may not work with this choice.")
+          )))))


;; Functions
@@ -325,6 +416,8 @@
         "a Lisp macro")
        ((eq (car-safe def) 'autoload)
         (setq file-name (nth 1 def))
+         (let ((loc (locate-library file-name)))
+                   (when loc (setq file-name loc)))
         (format "%s autoloaded %s"
             (if (commandp def) "an interactive" "an")
             (if (eq (nth 4 def) 'keymap) "keymap"





reply via email to

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