I need to be able to set the tab settings for the following file types:
- .rb: 2 soft spaces
- .css, .html.erb: 4 space tabs
I have tried the following, but none of it seems to alter my default tab settings for each of the file types.
;; js-mode-hook has also been tried
(add-hook 'javascript-mode-hook
'(lambda()
(setq tab-width 4)))
(add-hook 'css-mode-hook
'(lambda()
(setq tab-width 4)))
(add-hook 'html-mode-hook
'(lambda()
(setq tab-width 8)))
I am pretty new to emacs so my knowledge of configuration is pretty low.
In emacs each mode has it’s own indentation style. The main command to indent (bound to TAB) is
indent-for-tab-command.This command calls mode specific indentation function found in the variable
indent-line-function. So each mode has it’s own way of doing it.For Ruby (for my emacs 2 is a default):
For CSS (again, default is 4 for me):
Unfortunately SGML mode (on which HTML mode is based) has a very simple indentation mechanism and apparently the level is not configurable.
See the source code of
sgml-calculate-indentfunction.I personally find it weird. I am not writing HTML, but you can try to modify the
sgml-calculate-indentfunction yourself :). Learn some lisp.I am using js2 mode, and it indents perfectly by default. For js you have to search for js-indent-level or something similar.
Cheers.