5

By default, when using a PC keyboard attached to a Mac, OS X treats presses of the Insert key as presses of the Help key that appears on the extended Mac keyboard.

How do I map that keypress to have the same result in GNU Emacs that it does when running in, say, Windows or Linux: toggling overwrite-mode on and off? (https://www.gnu.org/software/emacs/manual/html_node/efaq/Overwrite-mode.html)

In a GUI window, Emacs treats Insert presses as Help key presses and shows the help, which is logical. Googling, I can't find anywhere that discusses remapping the Help key.

In OS X's Terminal.app, as far as I can tell, the key presses aren't passed to the terminal itself at all. At a Bash prompt, Ctrl-v Insert results in no output. Pressing another key behaves as if typing Ctrl-v <key> with no intervening press of Insert.

EDIT: I've gotten closer. I think.

I used Karabiner [1] to map Insert to something more useful than Help, since Terminal.app doesn't see Help. I picked F13.

[1] pqrs.org/osx/karabiner/

<item>
    <name>Map Insert to F13</name>
    <identifier>private.map_insert_to_f13</identifier>
    <autogen>__KeyToKey__ KeyCode::PC_INSERT, KeyCode::F13</autogen>
</item>

Ctrl+v Insert in Bash then shows ^[[25~.

Taking inspiration from http://www.emacswiki.org/emacs/LinuxConsoleKeys I added the following to my .emacs:

(define-key input-decode-map "\e[25~" [(f13)])
(define-key key-translation-map (kbd "<f13>") (kbd "<Insert>"))

Now pressing Insert once doesn't do anything. Pressing it twice shows

<f1> <Insert> is undefined.

Pressing Insert Down shows

<f1> <down> is undefined.

I don't know where to go from here.

WalterGR
  • 203
  • 1
  • 11

1 Answers1

2

Placing the following snippet in user-init-file (~/.emacs.d/init.el in my case) worked for me. I also set ctrl-insert and shift-insert to copy/paste.

(when (eq system-type 'darwin)
  ;; when using Windows keyboard on Mac, the insert key is mapped to <help>
  ;; copy ctrl-insert, paste shift-insert on windows keyboard
  (global-set-key [C-help] #'clipboard-kill-ring-save)
  (global-set-key [S-help] #'clipboard-yank)
  ;; insert to toggle `overwrite-mode'
  (global-set-key [help] #'overwrite-mode))
ebpa
  • 7,319
  • 26
  • 53
ValG
  • 21
  • 2
  • This answers the question for GUI Emacs - thanks. But I still don't know how to solve this for console Emacs. – WalterGR Jun 25 '18 at 04:37