4

I want to use intelligent tabbing in Emacs in C++ mode, but I also want to be able to insert a tab character when necessary. From other posts, I gather that the easiest way is to bind <Ctrl>-<Tab> to indent. However, it appears that Konsole in KUbuntu won't forward the <Ctrl>?

My current .emacs file contains:

(defun my-c-mode-common-hook ()  
 (setq c++-tab-always-indent t)
 (setq tab-width 4)
 (setq indent-tabs-mode t)
 )

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(global-set-key [C-tab] 'self-insert-command)

So I believe that this will bind <Ctrl>-<Tab> to inserting a tab character. However, when I run:

<Ctrl>-h k <Ctrl>-<Tab>

Emacs only reports that I pressed the tab key. Is there some option to Konsole (which I have searched through to no avail) or global preferences in KUbuntu that I need to set so that the <Ctrl>- is also forwarded? (It certainly forwards all of the other <Ctrl>-blah commands.)

M. Tibbits
  • 8,400
  • 8
  • 44
  • 59
  • Well, it seems that konsole itself treats ctrl-tab as tab (on my box at least). ctrl-tab tab completes exactly like tab does when typing at the command line. It looks like konsole does not recognize ctrl-tab as being different from tab. – Jonathan M Davis Apr 15 '10 at 18:39
  • I tested Konsole, Gnome Terminal, and xterm. Only emacs running in xterm could distinguish TAB from C-TAB – Ryan C. Thompson Apr 16 '10 at 05:06
  • Then it would seem C-TAB is just a silly idea. Which key combination should I bind to? Or does this ability, to add a Tab character, [without disabling the intelligent tabbing], already exist and I simply don't know the correct key combination? – M. Tibbits Apr 16 '10 at 19:48

2 Answers2

3

You can use Control-Q (quote, is what I think of in order to remember this), and then press your Tab key, and you'll insert a tab character. You can use Control-Q to insert any character sequence you need to. Hope this helps. :)

Scott Jones
  • 163
  • 4
2

I had to solve the same problem and I found the answer here: http://www.linux-archive.org/ubuntu-user/189410-equivalent-xterm-vt100-translations-string-gnome-terminal.html

What I did is the followings.

  1. prepare my own konsole key bind customization file ~/.kde/share/apps/konsole/linux-custom.keytab
  2. run konsole by specifying the keytab I customized

    % konsole --keytab linux-custom

  3. bind keys in Emacs

My binding in linux-custom.keytab is

key Tab   +Control       : "\E[4t" # control tab will generate esc [ 4 t
key Backtab              : "\E[4s" # shift tab will generate esc [ 4 s

(I don't know any rule for assigning key code so I chose some code which are not yet used.)

In my Emacs customization file called from .emacs I put the following bindings

(define-prefix-command 'terminal-key-map)
(global-set-key (kbd "\e[") 'terminal-key-map)
(define-key terminal-key-map (kbd "4t") 'other-window) ;control tab
(define-key terminal-key-map (kbd "4s") 'other-window) ;shift tab

I also customized other keys such as control ;, control ', control =, etc. in the same way.

tarok
  • 21
  • 2