Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to bypass comint-mode's completion support completely, instead relying on the subordinate process to do it for me. Specifically, if I'm running:

  • emacs
    • shell-mode
      • bash

Then I want TAB to be passed to the bash process and expanded by it.

If I'm running:

  • emacs
    • shell-mode
      • bash
        • psql

Then I'd want TAB to be handled by psql.

I've tried this in a shell-mode-hook to no avail:

(define-key shell-mode-map "\t" 'self-insert-command)

When this is set, the TAB key inserts a literal tab on the command line, which is not at all useful to me.

I've also tried this, but when I hit TAB nothing happens:

(defun cr/comint-send-tab ()
  "Send a tab character to the current buffer's process"
  (comint-send-input t t)
  (process-send-string (current-buffer) "\t"))

(define-key shell-mode-map "\t" 'cr/comint-send-tab)

How can I do this?

share|improve this question
+1: I had been exploring almost exactly the same use case when I found this question! – SetJmp Sep 27 '11 at 16:12
up vote 4 down vote accepted

Emacs shell-mode buffers are not terminals (i.e., they do not use ptys (pseudo-terminals)), so no program running in such a buffer (the shell, the programs run by the shell, etc.) can perform character-at-a-time input. Each line is typed in full and only sent when ENTER is pressed. To see proof, run the tty command in a shell-mode buffer, and it's output will be not a tty.

share|improve this answer
FYI, while it may seem that this is not true because you can perform command-line editing with Ctrl-B, Ctrl-F, etc., this is only because shell-mode itself simulates the typical command-line editing features of shell's like Bash, Zsh, Korn shell, etc. using Emacs own internal editing capabilities. – Fran Jun 9 '12 at 23:56

How about trying Emacs' terminal (instead of shell).

M-x term

share|improve this answer
Term has its own set of issues, starting with some interesting interactions with my extant set of bashrc tweaks. – Chris R Jan 23 '11 at 3:10

Try quoted-insert which is (by default) bound to C-q. The next character you type will be literally inserted into the buffer.

So C-qTAB will insert a literal tab.

I don't know what this does in comint modes (in regard to bash completion) and am not in a position to test it.

share|improve this answer
That has the same effect as my second attempt, above. No go, sadly. – Chris R Jan 24 '11 at 7:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .