1

I am using emacs on many machines, and always use C-/ for undo. However, I started working on a Raspberry Pi with Arch Linux recently, using a local text terminal - X is not installed. Here, C-/ has the same effect as Backspace, instead of 'undo. How can I get an 'undo when I press C-/? I'm using emacs-nox-26.2.

Note, this question was also asked on SuperUser, but without a (to me) satisfactory answer. I'd like to reconfigure emacs, not my spinal cord ;-)

3

Ctrl+/ has the same effect as BackSpace because your terminal tells Emacs that you pressed Backspace: it sends DEL for Ctrl+/. There's no character for C-/ and most terminals don't have a control sequence for it, so there's no chance that Emacs would see C-/. You need to reconfigure the terminal to either send a different escape sequence that you bind to undo in Emacs, or send C-_ when you press Ctrl+/. The second approach is a lot easier, but I'll also show the first approach in case you want redo as well.

Follow the steps described in the Arch Wiki to create a custom keymap for the Linux console. (Well, not to the letter — I guess you won't run vim.) Check which keymap is the current one by locating the line KEYMAP=… in /etc/vconsole.conf. Open the file /usr/share/kbd/keymaps/KEYMAP.map.gz where KEYMAP is the keymap name. Save it as /usr/local/share/kbd/keymaps/astrofloyd.map. In /etc/vconsole.conf, replace the line KEYMAP=… by KEYMAP=astrofloyd.

The next time you reboot, you'll be using your own keymap. You can load it immediately with loadkeys astrofloyd. You need to run this command whenever you change the .map file.

In astrofloyd.map, locate the line for the slash key. It's keycode 53, sending slash question … or U+002f U+003f … depending on how the information is presented. If you see

keycode 53 = U+002f U+003f U+0323 U+002e Delete Delete …

then the columns to the right of the equal sign are, respectively: bare key, Shift, AltGr, AltGr+Shift, Ctrl, Ctrl+Shift, Ctrl+AltGr, Ctrl+AltGr+Shift, Meta, etc. So change Delete in the 5th and 6th column after the equal sign to Control_underscore.

If you see a line with

control keycode  53 = Delete

then change Delete to Control_underscore there.

If you want Ctrl+Shift+/ to do redo, you'll need to bind it to a different escape sequence. The Linux console has limited support for escape sequences. You need to use a known keysym name, and the only ones that don't have a conventional meaning are F25, F26, etc. So pick one, e.g.

keycode 53 = U+002f U+003f U+0323 U+002e Control_underscore F25 …
string F23 = "\033[27;6;63~"

and let Emacs know about the control sequence that it sends.

(define-key input-decode-map "\e[27;6;63~" [?\C-\?])
(global-set-key [?\C-\?] 'redo)
  • Thank you very much for your time, and for your explanation that this is not an emacs issue, but a terminal one, as well as describing the solution(s). Perhaps someone ought to move this to SuperUser. I'll try your solution tomorrow, when I have access to the RPi, and then accept (if it works ;-)). However, I fear that with the edited title, people like me who discover that C-/ doesn't work in emacs will not find this solution, unless they already know what the actual issue is... – AstroFloyd Aug 4 at 9:52
  • @AstroFloyd On this site, “in Emacs” in the title is redundant and not useful for search engines (having “Emacs” in the site name is good enough for them). I'm happy to move the question to Unix & Linux if it gets close votes here, but I don't think it's off-topic here: you had a problem with Emacs, even though the cause of the problem was outside Emacs. – Gilles 'SO- stop being evil' Aug 4 at 22:03

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.