0

I submitted a bug report about this behavior about a year ago on bug-gnu-emacs, but I got no useful responses and the behavior has gotten worse over time. Perhaps someone here has an explanation or work-around.

I am working on a MacBook Pro laptop running Mac OS 10.5.1. In my init.el, I have the following:

(global-set-key (kbd "A-c") 'kill-ring-save)
(global-set-key (kbd "A-x") 'kill-region)
(setq mac-command-modifier 'alt) ; cmd key -> alt A-
(setq mac-option-modifier 'meta) ; option/alt key -> meta M-
(setq mac-control-modifier 'control) ; control key -> control C-
(setq mac-function-modifier 'super) ; Fn key -> super s-
(setq mac-right-command-modifier 'hyper) ; right cmd key -> hyper H-

with the purpose of being able to use the Apple command key for its standard cua copy and paste functionality, among other things.

The problem is, from time to time, A-c, A-x, and perhaps a few other similar key sequences, stop working and become self-insert-command. This is quite disruptive because it means, for instance, the standard keystroke for copying selected text under macOS instead replaces the selected text with some Unicode character.

At first (last year), this seemed to happen after running the command

C-x 8 <any key>

where "any key" is any key at all, not just c.

More recently, it seems to be happening all the time. For what it's worth, my iso-transl-char-map variable contains pairs like ("*c" . [162]) ("c" . [162]) but I don't know how those get in there.

When I run describe-key on, say, A-c, I get:

¢ (translated from A-c) runs the command self-insert-command (found in global-map), which is an interactive built-in function in
‘src/cmds.c’.

It is bound to many ordinary text characters.

#+begin_src emacs-lisp
  (self-insert-command N &optional C)
#+end_src

Probably introduced at or before Emacs version 22.1.
...

This behavior is unexpected and unwanted. After the sequence changes, re-evaluating (global-set-key (kbd "A-c") 'kill-ring-save) produces no error message, but has no effect. I have not been able to find any way to get the binding to return to normal except by restarting Emacs.

1 Answer 1

1

Try this

;; Add my own A- bindings
(global-set-key (kbd "A-c") 'kill-ring-save)
(global-set-key (kbd "A-x") 'kill-region)

;; Re-instate my own A- bindings after loading of `iso-transl'
(with-eval-after-load 'iso-transl
  (map-keymap
     (lambda (key cmd)
       (let ((key-desc (single-key-description key)))
         (when (string-match-p "^A-" key-desc)
           ;; Nuke all the A- bindings
           (define-key key-translation-map (kbd key-desc) nil))))
     key-translation-map)
  ;; Re-instate my own bindings
  (global-set-key (kbd "A-c") 'kill-ring-save)
  (global-set-key (kbd "A-x") 'kill-region)

  ;; Catch the thief
  (debug-on-entry 'iso-transl-define-keys))

Above snippet will enter debugger whenever someone calls iso-transl-define-keys. In that case, you can look at the stacktrace to identify the thief, and press c to continue.

If you don't care about iso-transl-define-keys, you can optionally add this.

(fset 'iso-transl-define-keys 'ignore)

See Apropos iso-transl-define-keys

1
  • The problem has not recurred since I put this in my init file, so I accepted this answer. However, I never "caught the thief".
    – Addlai
    Sep 10, 2022 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.