[Top][All Lists]
[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, 02 Jul 2006 10:54:06 +0200 |
User-agent: |
Thunderbird 1.5.0.4 (Windows/20060516) |
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))))
- Re: Patch to remove minor modes in tutorial, Richard Stallman, 2006/07/01
- Re: Patch to remove minor modes in tutorial,
Lennart Borgman <=
- Re: Patch to remove minor modes in tutorial, Richard Stallman, 2006/07/02
- Re: Patch to remove minor modes in tutorial, Lennart Borgman, 2006/07/06
- Re: Patch to remove minor modes in tutorial, Richard Stallman, 2006/07/07
- Re: Patch to remove minor modes in tutorial, Giorgos Keramidas, 2006/07/07
- Re: Patch to remove minor modes in tutorial, Richard Stallman, 2006/07/08
- Re: Patch to remove minor modes in tutorial, Lennart Borgman, 2006/07/09
- Re: Patch to remove minor modes in tutorial, Lennart Borgman, 2006/07/17
- Re: Patch to remove minor modes in tutorial, Lennart Borgman, 2006/07/17
- Re: Patch to remove minor modes in tutorial, Richard Stallman, 2006/07/24
- Re: Patch to remove minor modes in tutorial, Lennart Borgman, 2006/07/30