Try adding the following to your init.el
(below the customizations you already have):
(setq-default indent-tabs-mode t)
From the documentation for indent-tabs-mode
:
Indentation can insert tabs if this is non-nil.
I don't use ruby-mode
so I don't know about possible interactions between indent-tabs-mode
and ruby-indent-tabs-mode
. It might just be enough to set indent-tabs-mode
to t
(and erase the customizations you made to ruby-indent-tabs-mode
). But when you add the snippet above to your configuration, the default behavior for Emacs will be to insert tabs for indentation.
EDIT
As can be seen here, enh-ruby-mode
defines a customizable variable called enh-ruby-indent-tabs-mode
with a default value of nil
. Later on the value of this variable is used to override the value of indent-tabs-mode
, which is why setting indent-tabs-mode
to t
has no effect on buffers with enh-ruby-mode
enabled.
So unless you enable any other modes besides ruby-mode
and enh-ruby-mode
that might be modifying the indent-tabs-mode
variable, adding
(setq enh-ruby-indent-tabs-mode t)
to your init.el
should fix your problem.
Another EDIT (working solution)
(Credits: This answer put me on the right track.)
Using
Emacs 24.3.1
ruby-mode
version 1.2 (built-in)enh-ruby-mode
version 20140406.252 (installed via M-xpackage-install
...)
I was able to make it work by adding the following to an otherwise completely empty init.el
file:
(package-initialize)
(setq-default tab-width 2)
(setq enh-ruby-indent-tabs-mode t)
(defvaralias 'enh-ruby-indent-level 'tab-width)
(defvaralias 'enh-ruby-hanging-indent-level 'tab-width)
This solution works for both the GUI and the console version of Emacs. It will probably integrate fine with your other customizations but you will need to remove the custom-set-variables
section and everything below it from the version of your init.el
you posted above.
Note also that if you do come across a situation in which Emacs inserts a space instead of a tab you can always delete it and force insertion of a tab by quoting it via C-q TAB.
Wrapping up
Turns out there is a bug in enh-ruby-mode
which causes indentation to fail for blocks starting from the second level when enh-ruby-indent-tabs-mode
is set to t
. The author/maintainer of enh-ruby-mode
has no plans of fixing it, but the bug report includes a patch that supposedly fixes the issue.