Question

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.)

Was it helpful?

Solution

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. :)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top