0
votes

Emacs n00b here, I've fiddled a bit with it in graphical mode and so far I've found it great. I wanted to give the terminal version a try and found out that there's a few annoying behaviour differences, in particular with shift-selection.

In graphical mode I can combine shift selection (ie holding shift to set a mark) with the arrow keys, the control key (to select whole words) or the origin or end keys (to select the whole/a large part of a line).

In terminal mode the keys work fine on their own (I can select regions while holding shift and moving with the arrow keys*, C-left/right allows me to jump whole words, origin and end bring me where I want to go) but I can't combine them (can't select whole words by holding shift and C-arrowing, or select the remaining part of a line with shift-end or shift-origin).

I also found that C-backspace didn't work (ie didn't erase the whole word) in console while it does in window mode, though I read about M-backspace after looking for a solution.

I searched as thoroughly as I could but could not find how to get the terminal version to behave like the graphical version... Lots of people seem to ask questions about Emacs's shift selection but none of them have quite the same problem... Can someone explain where those behaviour differences come from?

Thanks in advance.

*Though, holding shift, if I go down (with the arrow key) to select whole lines, I can't go up again to unselect them (" is undefined").

[edit /] Okay, so obviously this comes from the fact that my terminal doesn't have the same shortcuts as graphical Emacs does. Fair enough. I see a couple of solutions here:

  • getting used to default Emacs shortcuts
  • filling my .emacs with global-set-key's. Although I tried
    (fset 'select-to-end
    [(kbd "C-<spc> <end>")])
    (global-set-key (kbd "S-<end>") 'select-to-end)
    
    but it doesn't work as I intend it to -_-
1
You're likely running afoul of bad terminal/termcap settings. What OS are you on, and what's $TERM?Craig Citro
My OS is Crunchbang Statler (Debian-based), and $TERM is xterm. I just figured out that actually, since I'm running Emacs in console, the problem's simply that my console doesn't have the same shortcuts for moving around in text... I just found out that I can also move to the beginning/end of the line with C-a/C-e, and select until the beginning/end of the buffer holding shift with M-a/M-e. Now I just need to select until the beginning/end of the line... And (hold shift) C-a/C-e doesn't work (C-s-e is bound to split vertically in my terminal, and C-s-a just doesn't do anything visible).Peniblec

1 Answers

1
votes

The short answer is "if you're happy using different keystrokes, that might be easier". Personally, I'm a little neurotic about my keybindings and configuration, so I rarely go with this one; in particular, it's frustrating when emacs modes override your bindings. (I don't know if you've yet discovered that global-set-key really means "let anyone in the universe stamp on my keybinding".)

The longer answer to your question is "someone along the chain is ignoring your control characters, so you need to figure out who it is, fix it, and then repeat". For the keybindings you're talking about here -- C-S-<arrows> -- you can definitely get this to work; if you want something like \C-~, you're going to have a much harder time. (The issue is that some bindings didn't make sense in legacy terminals, so you basically have to use a nonstandard set of control codes to transmit the key combination, and then teach each program to recognize it. This is usually where a termcap comes in, since it's a common language for teaching programs about key events.)

Here are the steps I usually take:

  • Start with your terminal. You can use \C-v and then hit a key to insert the literal keystroke (at least in bash) -- start by doing this with C-left, S-left, and C-S-left. Confirm that you're getting three different control codes.
  • If you're not, you need to investigate either (1) your readline settings, (2) your terminal program settings or (3) your termcap settings. Since TERM is xterm, the termcap should be fine. I don't know what terminal program you're using, but it may have its own key configuration. (For instance, I use a mac and use iTerm2, which is usually my first stop.) If you're going to be spending time at a terminal anyway, you should definitely take the time to read the readline manual and play with your .inputrc a bit.
  • This chain is short: next is emacs. You can use \C-q in emacs to do the same thing \C-v does in bash, or use \C-h k to find out what the default bindings are. Again, start by making sure emacs sees distinct key events for the combinations you're interested in. If not, you'll probably want to start by looking at term/xterm.el in your site-lisp directory and modifying it to your liking.

If you're using tmux or screen, they also get a hand in this, and can usually be tamed. The process for finding those problems is the same as bash -- use \C-v and man tmux to figure out how to get your extra keybindings.