all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Reitter <david.reitter@gmail.com>
To: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: iso-transl pach (bug#6527: C-h b alters key-translation-map (in a bad way))
Date: Sun, 18 Jul 2010 12:06:03 +0100	[thread overview]
Message-ID: <A958808B-205E-455F-8B64-2DC4FCA95959@gmail.com> (raw)
In-Reply-To: <handler.6527.B.12777361181855.ack@debbugs.gnu.org>

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)
  



  parent reply	other threads:[~2010-07-18 11:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-28 14:41 bug#6527: C-h b alters key-translation-map (in a bad way) David Reitter
     [not found] ` <handler.6527.B.12777361181855.ack@debbugs.gnu.org>
2010-06-28 19:48   ` David Reitter
2010-07-18 11:06   ` David Reitter [this message]
2010-07-20 11:00     ` iso-transl pach (bug#6527: C-h b alters key-translation-map (in a bad way)) Stefan Monnier
2021-11-02 15:37 ` bug#6527: C-h b alters key-translation-map (in a bad way) Lars Ingebrigtsen

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

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

  git send-email \
    --in-reply-to=A958808B-205E-455F-8B64-2DC4FCA95959@gmail.com \
    --to=david.reitter@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.