2

Current with C, Javascript, Ruby, etc. when inserting a block with { <RETURN>, Emacs automatically indents the next line, but it does so with spaces. How do I change this behavior to tab characters? The follow is my configuration.

(setq-default tab-width 2)
(setq-default c-basic-offset 2)
(setq-default indent-tabs-mode t)

This sets the indention level to 2 (for C and Ruby, but strangely 4 for Javascript), but it still inserts spaces rather than tabs.

  • @lawlist Okay, thanks for the advice. I'll vote to move this to emacs.stackexange.com. –  Dec 21 '14 at 08:53
  • @lawlist If we drive all Emacs questions away, we'll never have people answering them either. That's not a good long-term solution to that problem. Emacs as computer software is absolutely on topic here. In fact, migrating to Beta sites is [typically not done](http://meta.stackexchange.com/questions/169983/are-there-precedents-to-migrate-a-post-to-a-beta-site), as these sites should grow organically, and not be fed by pulling questions off other sites where they would've been equally on topic. –  Dec 21 '14 at 10:21
  • 1
    I migrated this one as an exception for now, but let's not make this the default procedure. In fact, @lawlist, when mentioning other sites, you should at least mention that the question should not be just posted there *again*, but rather that the OP should *flag it for migration* if they didn't get an answer within, say, two days. –  Dec 21 '14 at 10:24
  • 5
    I'm guessing you have something overriding the default values either later in your init file or in a mode hook. – Dan Dec 21 '14 at 15:23
  • 4
    Use `C-h v` `indent-tabs-mode` from one of the buffers in question to check its *actual* value in that buffer. As Dan says, presumably some other config is overriding your default. – phils Dec 21 '14 at 23:45

1 Answers1

2

The Ruby editing mode defines ruby-indent-tabs-mode and sets indent-tabs-mode to that value when the mode is invoked. The default for this is nil. To fix your problem, set this variable instead.

This seems like a bug to me. There's no reason Ruby needs its own special setting for this.

Note also that c-basic-offset doesn't affect Ruby. Ruby has ruby-indent-level. It's a bit of an Emacs oddity that modes must provide their own variables for basic indentation.

Tom Tromey
  • 759
  • 4
  • 8