Reputation: 65
Hitting TAB key while entering text into scratch buffer does not do anything. I would like TAB key to behave exactly as it would in other normal buffers(move point forward by inserting some X number of spaces or insert a TAB character). Could you please help me achieve that? Thank you.
I have come across below question, but it doesn't have an answer and the link mentioned in its comment is not working. I do not have enough score to add a comment to it.
How to enable tab key in scratch buffer of emacs?
Feel free to close the current question if you could add an answer to above question.
Upvotes: 1
Views: 1022
Reputation: 41618
I posted that comment with the now dead link, so I'll quote from the Wayback Machine copy:
Emacs isn't inserting anything!!
If you feel like I do, you probably are considering this a fault. You keep pressing the TAB key, but nothing happens.
In programming modes, such as when you're editing C or Perl or Lisp source code, the TAB key is bound to special indentation rules. That is, instead of being bound to
indent-relative
as in text-mode, the TAB key is pre-bound tocc-indent-line
orlisp-indent-line
(if editing your.emacs
file), and so on. In c-mode, pressing the TAB key will move the cursor to the first indentation level, and then may not move the cursor forward after that, no matter how many times you press it.If this behavior isn't what you want, you can do one of these things:
- Press
Ctrl-q <TAB>
to insert a TAB character right now- Temporarily reassign the TAB key to
self-insert-command
while staying in the same editing mode- Switch to a different editing mode for this session; the TAB behavior will change with the editing mode
- Change your
.emacs
file to permanently change the editing mode for the filetype you're using now
I'd recommend reading the entire page, as it explains well how Emacs treats the TAB key and tab characters different from pretty much everything else.
Upvotes: 0
Reputation: 1576
If all you're interested in is to insert the TAB
character (i.e. \t
), then you could use the quoted-insert
function. By default it's bound to C-q. It captures the next input character and inserts it verbatim. So in your case that would be C-q TAB.
Upvotes: 3
Reputation: 92077
TAB's behavior in most programming-language modes is not "insert a tab" but "make sure the code on this line is indented correctly according to the current rules". The default mode for the scratch buffer is lisp-interaction-mode
, and since you have not written any Lisp code, there is no indenting to do, so TAB does nothing.
There are a few ways you could change this. You could change the major mode to, say, text-mode
or fundamental-mode
, either for a single session (with M-x text-mode
) or permanently (by putting (setq initial-major-mode 'text-mode)
into your .emacs file).
Or you could leave the mode alone, and rebind the TAB key entirely. One way to do this would be
M-: (global-set-key (kbd "TAB") 'self-insert-command)
I'm sure there are many other alternatives, depending on how exactly you want your scratch buffer to act.
Upvotes: 3