9

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"
  (interactive)
  (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?

1
  • +1: I had been exploring almost exactly the same use case when I found this question!
    – Setjmp
    Sep 27, 2011 at 16:12

4 Answers 4

7

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.

1
  • 1
    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, 2012 at 23:56
3

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.

1
  • 1
    That has the same effect as my second attempt, above. No go, sadly.
    – Chris R
    Jan 24, 2011 at 7:36
2

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

M-x term

1
  • 1
    Term has its own set of issues, starting with some interesting interactions with my extant set of bashrc tweaks.
    – Chris R
    Jan 23, 2011 at 3:10
1

You can use bash's quote character, which is Ctrl-V. To insert a literal TAB into bash running in Emacs' shell buffer, do

C-q C-v C-q TAB

You must log in to answer this question.

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