Shell script mode does not have any setting that relates to using tabs vs spaces (at least as of Emacs 25.2). It obeys the default Emacs setting which is given by indent-tabs-mode
and tab-width
: 8 spaces of indentation are replaced by a tab character.
To turn this off globally, put this line in your init file:
(setq indent-tabs-mode nil)
This doesn't affect modes that have their own settings. For example Python mode turns off the use of tabs, and Makefile mode turns it on, regardless of the global settings.
To turn off the use of tabs in shell script mode only, put this line in your init file:
(defun turn-off-indent-tabs-mode ()
(setq indent-tabs-mode nil))
(add-hook 'sh-mode-hook #'turn-off-indent-tabs-mode)
If you occasionally work with files that must have tabs or that must not have tabs, you can (and should) set indent-tabs-mode
on a per-file or per-directory basis through file-local variables or directory-local variables. In a file, put something like this near the end of the file; the leading string @@@
can be anything as long as it's the same on all these lines.
@@@ Local Variables:
@@@ indent-tabs-mode: t
@@@ tab-width: 8
@@@ End:
In a directory, create a file called .dir-locals.el
with content like this:
((nil . ((indent-tabs-mode . nil))
(javascript-mode . ((indent-tabs-mode t)
(tab-width 8))
("linux-driver" . ((indent-tabs-mode t)
(tab-width 8)))))
This artificial example specifies not to use tabs, except for files in the linux-driver
subdirectory and files in JavaScript mode which do use tabs.
Instead of (or in addition to) the Emacs-specific file, you can put an .editorconfig
file in your project.
[*]
indent_style = space
indent_size = 4
[{*.js,linux-driver/*}]
indent_style = tab
indent_size = 8
To make Emacs support .editorconfig
, install the editorconfig package.