* iso-transl pach (bug#6527: C-h b alters key-translation-map (in a bad way))
[not found] ` <handler.6527.B.12777361181855.ack@debbugs.gnu.org>
@ 2010-07-18 11:06 ` David Reitter
2010-07-20 11:00 ` Stefan Monnier
0 siblings, 1 reply; 2+ messages in thread
From: David Reitter @ 2010-07-18 11:06 UTC (permalink / raw)
To: Emacs-Devel devel
I reported bug 6527 a while ago.
> 6527: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6527
The problem was that iso-trans.el is autoloaded (e.g., when doing C-h b) and unconditionally binds Alt key combinations, overriding any user/package defined A- keys. Once loaded, there is no obvious way to undo those bindings.
Here's a fix for this. It defines a new minor mode, `iso-transl-mode', which controls those A-... key bindings.
I chose to automatically define the C-x 8 prefix key combinations when the package is loaded, so that the C-x 8 autoloading mechanism remains in place for the comfort of the occasional user.
I don't know how much iso-transl is used by people, so I can't gauge the impact of this. Please advise.
diff --combined lisp/international/iso-transl.el
index 8a88b50,b11a7a2..0000000
--- a/lisp/international/iso-transl.el
+++ b/lisp/international/iso-transl.el
@@@ -25,21 -25,16 +25,21 @@@
;;; Commentary:
;; Loading this package defines three ways of entering the non-ASCII
-;; printable characters with codes above 127: the prefix C-x 8, or the
-;; Alt key, or a dead accent key. For example, you can enter uppercase
-;; A-umlaut as `C-x 8 " A' or `Alt-" A' (if you have an Alt key) or
-;; `umlaut A' (if you have an umlaut/diaeresis key).
+;; printable characters with codes above 127: the prefix C-x 8, and,
+;; with `iso-transl-mode' enabled, also the Alt key, and a dead accent
+;; key. For example, you can enter uppercase A-umlaut as `C-x 8 " A'
+;; or, `iso-transl-mode' is enabled, `Alt-" A' (if you have an Alt
+;; key) or `umlaut A' (if you have an umlaut/diaeresis key).
-;; C-x 8 is set up to autoload this package,
-;; but Alt keys and dead accent keys are only defined
-;; once you have loaded the package. It is nontrivial
-;; to make all of the Alt keys autoload, and it is not clear
-;; that the dead accent keys SHOULD autoload this package.
+;; C-x 8 is set up to autoload this package, but Alt keys and dead
+;; accent keys are only defined once you have loaded the package and
+;; enabled `iso-transl-mode'. It is nontrivial to make all of the Alt
+;; keys autoload, and it is not clear that the dead accent keys SHOULD
+;; autoload this package.
+
+;; Note that C-h b will autoload this package, which is one reason
+;; why the more destructive key sequences (without C-x 8 prefix) are
+;; only defined in `iso-transl-mode', and are thus reversible.
;;; Code:
@@@ -252,41 -247,29 +252,41 @@@ sequence VECTOR. (VECTOR is normally o
(setq key-translation-map (make-sparse-keymap)))
(define-key key-translation-map "\C-x8" iso-transl-ctl-x-8-map)
+(defmacro iso-transl-define-key (keymap key def)
+ "Back up definition of KEY in KEYMAP, then `define-key'."
+ `(progn
+ (push (cons ,key (or (lookup-key ,keymap ,key) 'none))
+ (get ',keymap 'iso-transl-backup))
+ (define-key ,keymap ,key ,def)))
+
;; For each entry in the alist, we'll make up to three ways to generate
;; the character in question: the prefix `C-x 8'; the ALT modifier on
;; the first key of the sequence; and (if applicable) replacing the first
;; key of the sequence with the corresponding dead key. For example, a
;; character associated with the string "~n" can be input with `C-x 8 ~ n'
;; or `Alt-~ n' or `mute-asciitilde n'.
+(defun iso-transl-define-prefix-keys (alist)
+ (while alist
+ (let ((translated-vec (cdr (car alist))))
+ (iso-transl-define-key iso-transl-ctl-x-8-map (car (car alist)) translated-vec))
+ (setq alist (cdr alist))))
(defun iso-transl-define-keys (alist)
(while alist
(let ((translated-vec (cdr (car alist))))
- (define-key iso-transl-ctl-x-8-map (car (car alist)) translated-vec)
+ ;(iso-transl-define-key iso-transl-ctl-x-8-map (car (car alist)) translated-vec)
(let ((inchar (aref (car (car alist)) 0))
(vec (vconcat (car (car alist))))
(tail iso-transl-dead-key-alist))
(aset vec 0 (logior (aref vec 0) ?\A-\^@))
- (define-key key-translation-map vec translated-vec)
- (define-key isearch-mode-map (vector (aref vec 0)) nil)
+ (iso-transl-define-key key-translation-map vec translated-vec)
+ (iso-transl-define-key isearch-mode-map (vector (aref vec 0)) nil)
(while tail
(if (eq (car (car tail)) inchar)
(let ((deadvec (copy-sequence vec))
(deadkey (cdr (car tail))))
(aset deadvec 0 deadkey)
- (define-key isearch-mode-map (vector deadkey) nil)
- (define-key key-translation-map deadvec translated-vec)))
+ (iso-transl-define-key isearch-mode-map (vector deadkey) nil)
+ (iso-transl-define-key key-translation-map deadvec translated-vec)))
(setq tail (cdr tail)))))
(setq alist (cdr alist))))
@@@ -297,45 -280,14 +297,45 @@@
(iso-transl-define-keys (cdr (assoc lang iso-transl-language-alist))))
-;; The standard mapping comes automatically. You can partially overlay it
-;; with a language-specific mapping by using `M-x iso-transl-set-language'.
-(iso-transl-define-keys iso-transl-char-map)
-
+;; unconditional definitions
+(iso-transl-define-prefix-keys iso-transl-char-map)
(define-key isearch-mode-map "\C-x" nil)
(define-key isearch-mode-map [?\C-x t] 'isearch-other-control-char)
(define-key isearch-mode-map "\C-x8" nil)
+(define-minor-mode iso-transl-mode
+ "ISO Key translation mode.
+This mode defines two ways of entering the non-ASCII printable
+characters with codes above 127: the Alt key and
+a dead accent key. For example, you can enter uppercase A-umlaut as
+`Alt-\" A' (if you have an Alt key) or `umlaut A' (if
+you have an umlaut/diaeresis key).
+
+This character can always be entered as `C-x 8 \" A' regardless of
+this mode."
+ :group 'i18n
+ :lighter " ISO"
+
+ (if iso-transl-mode
+ ;; The standard mapping comes automatically. You can partially overlay it
+ ;; with a language-specific mapping by using `M-x iso-transl-set-language'.
+ (iso-transl-define-keys iso-transl-char-map)
+ (mapc
+ (lambda (key-def)
+ (define-key key-translation-map (car key-def)
+ (and (not (eq (cdr key-def) 'none)) (cdr key-def))))
+ (nreverse (get 'key-translation-map 'iso-transl-backup)))
+ (put 'key-translation-map 'iso-transl-backup nil)
+ (mapc
+ (lambda (key-def)
+ (condition-case nil
+ (define-key isearch-mode-map (car key-def)
+ (and (not (eq (cdr key-def) 'none)) (cdr key-def)))
+ ;; if some of the unconditional definitions above are instead made conditional
+ ;; restoring the default keys fails.
+ (error nil)))
+ (nreverse (get 'isearch-mode-map 'iso-transl-backup)))
+ (put 'isearch-mode-map 'iso-transl-backup nil)))
(provide 'iso-transl)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: iso-transl pach (bug#6527: C-h b alters key-translation-map (in a bad way))
2010-07-18 11:06 ` iso-transl pach (bug#6527: C-h b alters key-translation-map (in a bad way)) David Reitter
@ 2010-07-20 11:00 ` Stefan Monnier
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2010-07-20 11:00 UTC (permalink / raw)
To: David Reitter; +Cc: Emacs-Devel devel
> I chose to automatically define the C-x 8 prefix key combinations when
> the package is loaded, so that the C-x 8 autoloading mechanism remains
> in place for the comfort of the occasional user.
I agree we need to decouple the 3 parts:
- the C-x 8 should stay, and could be extended to cover many more cases
(e.g. C-x 8 r ' could insert ŕ, etc...)
- the Alt- bindings (could be under the control of a minor mode, like
your patch does).
- the deadkey handling, which IIUC should be handled automatically by
other parts of the code.
So, I think your patch goes in the right direction, except that the
deadkey handling should be either removed (because it doesn't do
anything any way) or always enabled.
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-07-20 11:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <D91D370B-1D6F-4D58-B5AE-DB1159F7229E@gmail.com>
[not found] ` <handler.6527.B.12777361181855.ack@debbugs.gnu.org>
2010-07-18 11:06 ` iso-transl pach (bug#6527: C-h b alters key-translation-map (in a bad way)) David Reitter
2010-07-20 11:00 ` Stefan Monnier
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).