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.

5
  • @lawlist Okay, thanks for the advice. I'll vote to move this to emacs.stackexange.com.
    – Vortico
    Dec 21, 2014 at 8: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, as these sites should grow organically, and not be fed by pulling questions off other sites where they would've been equally on topic.
    – slhck
    Dec 21, 2014 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.
    – slhck
    Dec 21, 2014 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, 2014 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, 2014 at 23:45

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.