11

I use GNU Emacs, usually like emacs -nw which launches the terminal version (as opposed to the windowed GUI version).

I write school papers in LaTeX so I use flyspell-mode for spell-checking within emacs. This works fine in the GUI version, but in a terminal, I run into issues with the keystroke C-. (Ctrl-.). In a tty, this does nothing, and in terminator or gnome-terminal, this simply inputs a ".".

What can I do to make it do what it does in the windowed version (show spelling suggestions for a misspelled word)?

EDIT: In case this matters, I am using Ubuntu 12.04 with Emacs 23.3.1 (which I believe is default from the 12.04 repo).

  • 1
    Same here. Did you try Esc-x flyspell-mode? This works for me. – Masroor Feb 18 '13 at 4:55
  • Well, yes. I always start flyspell-mode with M-x, but ESC x does not seem to make a difference. – cg505 Feb 18 '13 at 13:40
  • 1
    Same here. However I found a default keybinding that works for both versions ESC-TAB. – McNisse Mar 20 '13 at 20:36
  • Yeah, ESC TAB or M-TAB both work for me. Thanks for the tip @McNisse. – cg505 Mar 20 '13 at 23:42
4

It looks like the important part of this question was already answered in the comments, but to address the root cause in case you're curious, I think ctrl-. doesn't work in a terminal because of some limitations of terminal emulators. In a standard terminal, ctrl is defined to send the ASCII code of the key you press minus 64 (this is why ctrl-J (74) sends newline (10) and ctrl-I (73) sends tab (9), for example). Since the period's ASCII code is 46, subtracting 64 would give -18, which is invalid because it's negative and there are no negative ASCII codes and therefore nothing for emacs to receive and understand.

When you run emacs in windowed mode, the terminal emulator mechanism is bypassed and instead the more robust keyboard handling of X11 is used, which can handle more obscure keystrokes (rather than reducing each keystroke down to one ASCII character, the program receives the original key plus all applicable modifiers, separately). So it's probably impossible to make tty-based emacs handle ctrl-. unless you make custom modifications to your terminal emulator (and probably also emacs).

  • 1
    This answer is really interesting. I dug into deeper, and found out DEC VT100 works similar but differently, strictly speaking. Here is what it does when control key and other key are pressed together: 1) lookup ASCII table by keyboard scan code 2) lookup the table of valid control codes by the ASCII 3) if it's valid, mask bit5 and bit6 of the ASCII 4) send out. So ctrl-J, ctrl-j, and ctrl-* could all send out LF but the validity check limited the combinations. See DEC VT100 technical manual section 4-43 (PDF page 93). – Kenji Noguchi Feb 12 '16 at 20:12
  • I can capture 'C-.' just fine with emacs in xterm but not with urxvt or st. Any idea why that might be the case? – stewSquared Dec 31 '17 at 12:49
0

While the above answer gives a good explanation on why it doesn't work, it doesn't really address how to make it work. For iTerm2 you can solve this by adding a key mapping for the escape sequence. I imagine there would be something similar in terminator or gnome-terminal

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.