2

I tried to define hotkey as following

(global-set-key [(control shift up)] 'other-window)

but it doesn't work (no error, just doesn't work), neither does

(global-set-key [(control shift down)] 'other-window)

But

(global-set-key [(control shift right)] 'other-window) 

and

(global-set-key [(control shift left)] 'other-window)

work!

But because the last two key combinations are used by emacs (as default), I don't wanna change them for other functions.

So how could I make control-shift-up and control-shift-down work?

I have googled "(control shift up)", it seems that control-shift-up is used by other people, (but not very few results).

Thomas
  • 17,016
  • 4
  • 46
  • 70
user565739
  • 1,302
  • 4
  • 23
  • 46
  • Not an emacs user, but are you sure there is not a mapping taking priority over yours? – leppie Jan 07 '11 at 08:21
  • Keys are often rebind when emacs load mode (for example `C-mode` is the mode used to edit `C` code, it is automatically loaded when you open a .c file) Try `M-x describe-key` and then `C-S up` will provide a short description to the function bound to `C-S up`. If the function is not `other-window` you'll see it. – Ben Jan 07 '11 at 08:57
  • not sure, but I have tried control+shift+up or down without my customized definitions and nothing happened, so I guess no. Furthermore, control+shift+left or right have their functions, but after redefine, I can use them for different tasks. – user565739 Jan 07 '11 at 09:01
  • very weird. without my customzied definition, by describe-key, I get : (a) C up, C down, C right, C left, have their descripitons. (b) C-S right and C-S left give me the descriptions of C right and C left (c) C-S up and C-S down have no description. It seems that whatever I type C-S + anykey, I get C+anykey or nothing. (d) If I definie control+shift+left (or right) for other-window, then C-left and C-S left both work, and have different functions which are as expected. But if I define control+shift+up (or down) for other-window, it just doesn't work. – user565739 Jan 07 '11 at 09:46
  • 1
    Just for clarification: is this emacs in a shell or emacs under X? In the former case, all matters of termcap stuff can happen. (FWIW, it works on my installation under X.) – Ulrich Schwarz Jan 07 '11 at 20:59
  • I use ubuntu 10.04, gnome desktop, I just oepn terminal then type emacs -nw xxx.c – user565739 Jan 08 '11 at 02:18

3 Answers3

6

The reason for this is not an Emacs problem, but comes from the fact that your terminal cannot produce a key sequence for C-S-up.

You can verify this very easily. Open a terminal and then type:

Control-v Control-Shift-right

The Control-v part will make the control sequence for the next key be inserted verbatim into your shell. In our case, it will insert the sequence for Control-Shift right, and that'll look something like this:

^[[1;6C

Now, try the same thing for C-S-up:

Control-v Control-Shift-up

You'll see that no control sequence is entered, which hints at the fact that when you press C-S-up in Emacs, it will actually never receive anything, because the terminal is not able to produce anything to pass on to Emacs.

We can double-verify this if you just start a new emacs -nw and type C-h k to invoke Emacs' describe-key function. You'll get asked in the minibuffer to type a key to see what function it is bound to. If you now type C-S-up nothing happens - of course not, since the terminal in which your Emacs runs doesn't produce anything.

However, if you're just looking for an unused key-combination, how about just Shift-up (or even Shift-right) without Control? That one should work both in a terminal emacs and in the windowed version.

Thomas
  • 17,016
  • 4
  • 46
  • 70
  • 4
    Thank you. But still want to know if there is a way to make my terminal produce a key sequence for C-S-up. – user565739 Jan 09 '11 at 00:19
4

Finally, with the help from grawity on superuser.com, I got it working. Please this thread

https://superuser.com/questions/230852/get-ubuntu-terminal-to-send-an-escape-sequence-controlshiftup

Community
  • 1
  • 1
user565739
  • 1,302
  • 4
  • 23
  • 46
0

This could well be a duplicate of:
Binding M-<up> / M-<down> in emacs 23.1.1

If this is the case, Gilles' answer should sort you out (undoubtedly with different escape sequences, though.)

edit (for better visibility -- see answer below):

It turned out that gnome terminal does not transmit these key combinations, so the solution relies upon the following: https://superuser.com/questions/230852/get-ubuntu-terminal-to-send-an-escape-sequence-controlshiftup

Community
  • 1
  • 1
phils
  • 71,335
  • 11
  • 153
  • 198
  • Thanks. I looked Gilles' answer and found http://www.gnu.org/software/emacs/manual/html_node/viper/Key-Bindings.html. But when I type C-q then C-S-up, I get nothing. But if I type C-q then C-S-right I get ^[[1;6C ; Does this means in my computer, C-S-up has not any function at all, i.e this key combination send no signal to my computer? If this is the case, so sad...... – user565739 Jan 07 '11 at 10:32
  • @user565739: `Ctrl+Shift+Up` does send a signal to your computer, but your terminal emulator is apparently not transmitting any escape sequence for it. So your problem is in two parts. First you must get your terminal emulator to send an escape sequence, which depends on your terminal emulator, and is [Super User](http://superuser.com/) material, or [Unix.SE](http://unix.stackexchange.com/) if you're using a unix system. Then you need to declare the escape sequence in Emacs, and my answer explains that part. – Gilles 'SO- stop being evil' Jan 07 '11 at 21:10
  • @Gilles: Do you have any reference for "get terminal emulator to send an escape sequence"? I use ubuntu 10.04, gnome desktop. I just open terminal and then type emacs -nw xxx.c. Thank you for your help. – user565739 Jan 08 '11 at 02:17
  • I just found a link which said control+shift+up/down don't work on Ubuntu terminal....Is this true? – user565739 Jan 08 '11 at 08:39
  • Under terminal, not open emacs or nano or anything, control+shift+up is used to scroll the drag bar up. ( not sure if this is related to my question....) – user565739 Jan 08 '11 at 08:44
  • I found Gille's explanation here http://stackoverflow.com/questions/4167296/certain-keybindings-dont-work-when-using-emacs-in-a-terminal ; So I guess the terminal intercept control+shift+up. I use ubuntu 10.04 and the built-in terminal program. How to solve this problem? – user565739 Jan 08 '11 at 08:48
  • I also found something maybe related http://www.staldal.nu/tech/2009/01/10/how-to-use-ctrl-tab-in-gnu-screen/ ; This is for control+shift+tab ; But my question is how to I know what should I type in ~/.Xresources for the case "control+shift+up" or in general for any key combinations? – user565739 Jan 08 '11 at 12:32
  • I hate to suggest something which doesn't solve the problem, but perhaps you should just use a different terminal? (`xterm` would be an obvious alternative.) – phils Jan 08 '11 at 13:39
  • Regarding your last comment, are you even using gnu screen? I thought you were running `emacs -nw` direct from the gnome terminal? A google search for "gnome terminal key bindings" seems to provide several useful-looking hits. – phils Jan 08 '11 at 13:53