1

The TAB key in emacs is bound to indent-for-tab-command, but the indent itself converts all the tabs into spaces, which I didn't like because it's harder to locate character in the code and the code gets bigger.

I tried to use (setq-default indent-tabs-mode t), (setq tab-width 4) or (setq default-tab-width 4), none of the above works. Neither the width of \t character changes, nor the indent uses tabs instead of spaces. And 'M-x tabify' does not work either.

I searched for a long time but got nearly nothing. Any ideas?

JB.
  • 40,344
  • 12
  • 79
  • 106
Shiva Wu
  • 1,074
  • 1
  • 8
  • 20
  • actaully there're different situation in different mode, I mainly tested on cc-mode and java-mode. Got it work already. – Shiva Wu Dec 30 '10 at 16:30

1 Answers1

3

It's your .emacs settings, if you don't have any special settings in your .emacs file, tab should be inserted by default.

;; This will force emacs to insert spaces instead of tabs
(setq-default indent-tabs-mode t)

This other two settings are not related.

Check emacswiki.org for any Emacs related questions.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Spike
  • 302
  • 2
  • 4
  • Seems working now. But a strange thing is that when pressing backspace on the tab, the tab will be converted into spaces. But when using arrows to move or , the tab is treated as tab as normal. Why is this? – Shiva Wu Dec 30 '10 at 15:34
  • Check what's your backspace key is mapped with Ctrl-h K "Backspace". It should be "backward-delete-char", if it's something with "tabify" fix it in your .emacs like this "(gloabl-set-key [backspace] ‘backward-delete-char)" – Spike Dec 30 '10 at 16:09
  • That's exactly it. And in cc-mode, it's c-electric-backspace which uses backward-delete-char-untabify by default. Finally got it work. Thanks a lot! – Shiva Wu Dec 30 '10 at 16:29