Mac – get ubuntu terminal to send an escape sequence (control+shift+up)

emacsescape-charactersgnome-terminalterminal

This problem starts when I use emacs ( with -nw option).
Let me first explain it.
I tried to define hotkey (for emacs) 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).

In the Stack Overflow forum, Gille answered me as following:

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 material, or Unix.SE if you're using a unix system. Then you need to declare the escape sequence in Emacs, and my answer explains that part

So I come here for this question:

How do I get my terminal (I use ubuntu 10.04, and the built-in terminal) to send an escape sequence for Control+Shift+Up Control+Shift+down

Best Answer

Ubuntu uses GNOME and gnome-terminal. According to its documentation (in version 2.30), CtrlShiftUp and CtrlShiftDown are used for navigating the scrollback buffer, and there doesn't seem to be any way to turn this "feature" off (aside from modifying the source code of vte, the terminal library).


To patch vte on Ubuntu 10.04:

  1. Rebuild vte, the terminal emulation library:

    1. Install software required for compiling:

      sudo apt-get install git-core fakeroot
      sudo apt-get build-dep vte
      
    2. Download vte source code and apply the patch:

      cd /tmp
      git clone git://gist.github.com/771667.git patches
      apt-get source vte
      cd vte-0.23.5
      patch -p1 < ../patches/vte-0.23.5.patch
      
    3. Make a Debian package and install it:

      dpkg-buildpackage -us -uc
      sudo dpkg -i ../libvte9_0.23.5-*.deb
      
  2. Close all gnome-terminal processes.

  3. Enjoy -- until the next vte update...

Patch for 0.23:

diff -ur vte-0.23.5/src/vte.c vte-0.23.5+patched/src/vte.c
--- vte-0.23.5/src/vte.c    2010-01-14 02:46:18.000000000 +0200
+++ vte-0.23.5+patched/src/vte.c    2011-01-09 15:19:01.000000000 +0200
@@ -4948,26 +4948,6 @@
            }
            break;
        /* Keypad/motion keys. */
-       case GDK_KP_Up:
-       case GDK_Up:
-           if (modifiers & GDK_CONTROL_MASK 
-                            && modifiers & GDK_SHIFT_MASK) {
-               vte_terminal_scroll_lines(terminal, -1);
-               scrolled = TRUE;
-               handled = TRUE;
-               suppress_meta_esc = TRUE;
-           }
-           break;
-       case GDK_KP_Down:
-       case GDK_Down:
-           if (modifiers & GDK_CONTROL_MASK
-                            && modifiers & GDK_SHIFT_MASK) {
-               vte_terminal_scroll_lines(terminal, 1);
-               scrolled = TRUE;
-               handled = TRUE;
-               suppress_meta_esc = TRUE;
-           }
-           break;
        case GDK_KP_Page_Up:
        case GDK_Page_Up:
            if (modifiers & GDK_SHIFT_MASK) {

Patch for 0.26:

diff -ur vte-0.26.2/src/vte.c vte-0.26.2+patched/src/vte.c
--- vte-0.26.2/src/vte.c    2010-11-13 14:18:41.000000000 +0200
+++ vte-0.26.2+patched/src/vte.c    2011-01-09 15:06:54.870000002 +0200
@@ -5153,26 +5153,6 @@
            }
            break;
        /* Keypad/motion keys. */
-       case GDK_KEY (KP_Up):
-       case GDK_KEY (Up):
-           if (modifiers & GDK_CONTROL_MASK 
-                            && modifiers & GDK_SHIFT_MASK) {
-               vte_terminal_scroll_lines(terminal, -1);
-               scrolled = TRUE;
-               handled = TRUE;
-               suppress_meta_esc = TRUE;
-           }
-           break;
-       case GDK_KEY (KP_Down):
-       case GDK_KEY (Down):
-           if (modifiers & GDK_CONTROL_MASK
-                            && modifiers & GDK_SHIFT_MASK) {
-               vte_terminal_scroll_lines(terminal, 1);
-               scrolled = TRUE;
-               handled = TRUE;
-               suppress_meta_esc = TRUE;
-           }
-           break;
        case GDK_KEY (KP_Page_Up):
        case GDK_KEY (Page_Up):
            if (modifiers & GDK_SHIFT_MASK) {
Related Question