0

Is there a way to configure emacs so that a key binding will just issue another one? In particular, I want to configure it so that C-t replicates (or even better replaces) backspace. I couldn't find a way to do it in my Window Manager (I am not even sure if it is at all possible in any Window Manger) so I have to do it in Emacs.

At the moment, I am just mapping C-t to backward-delete-char but this is not ideal, because many packages map backspace and I would have to go over all keymaps and replace backspace with C-t.

Drew
  • 75,699
  • 9
  • 109
  • 225
Tohiko
  • 1,589
  • 1
  • 10
  • 22

1 Answers1

1

A key sequence is just one possible form of a command. So you can just use the following form (if I understand your question right):

(global-set-key (kbd "C-t") (kbd "<backspace>"))

You can replace backspace with C-t by translating it in input-decode-map:

(define-key input-decode-map (kbd "C-t") (kbd "<backspace>"))
(define-key input-decode-map (kbd "<backspace>") [7])

The second form replaces backspace with the ASCII bell character. The harmless keyboard-quit command is bound to that character.


Note that there is already a duplicate of this question but the following statement in that question is wrong:

I also tried this:

 (global-set-key (kbd "\C-d") (kbd "<DEL>"))

But it obviously turns every C-d key into , so keybindings such C-c C-d stop working, making this not a suitable solution either.

See also the corresponding comment of VanLaser:

You say "it obviously turns every C-d key into , so keybindings such as C-c C-d stop working" - are you sure about that? When you press C-c (or C-x, or C-h) another keymap becomes active, in which C-d should NOT be overwritten. As per this doc: https://gnu.org/software/emacs/manual/html_node/elisp/Prefix-Keys.html

Tobias
  • 32,569
  • 1
  • 34
  • 75
  • That's exactly it. Thanks for this. Is there a way to replace the backspace rather than replicate it? So somehow map `` to `'ignore` and map `C-t` to whatever `` was mapped to. – Tohiko Mar 05 '20 at 14:35
  • @Tohiko See `C-h i g (elisp)Remapping Commands` – phils Mar 05 '20 at 17:51
  • @phils He does not want to remap the `delete-backward-char` command since depending on the major mode many other commands are bound to the `DEL` key. – Tobias Mar 05 '20 at 18:03