sh-mode won't care if indent-tabs-mode is on, it will still insert spaces instead of tabs! Can this be fixed?
1 Answer
I'm going to guess that tab-width
and sh-basic-offset
are not aligned.
indent-tabs-mode
will only use tabs to indent up to multiples of tab-width
, as otherwise it would indent too much.
That said, I find tabs bad for shell script indentation, as copying and pasting code from a script into a shell running in a terminal can be problematic. I would recommend using spaces for shell scripts for this reason.
Edit: In this instance it was the backspace behaviour which was causing confusion.
C-hkDEL tells me:
DEL (translated from <backspace>) runs the command
backward-delete-char-untabify (found in sh-mode-map), which is an
interactive compiled Lisp function in ‘simple.el’.
It is bound to DEL.
(backward-delete-char-untabify ARG &optional KILLP)
Delete characters backward, changing tabs into spaces.
The exact behavior depends on ‘backward-delete-char-untabify-method’.
Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
Interactively, ARG is the prefix arg (default 1)
and KILLP is t if a prefix arg was specified.
Follow the link provided there and set backward-delete-char-untabify-method
to nil
so that it deletes a single character (which should be a tab) each time.
-
-
In that case, I can't reproduce your problem.
indent-tabs-mode
works fine for me insh-mode
(and I used to use tabs in shell scripts a long time ago, so it was working in versions of Emacs as far back as I recall).– philsCommented Oct 3, 2018 at 1:52 -
-
good looking out. Should I change the title? If so any suggestions?– SuppboiCommented Oct 3, 2018 at 13:29
-
1Your warning against tabs seems ok in general, but if the script uses a heredoc input with the
<<-
operator tabs MUST be used for it to function correctly.– nolanddaCommented May 16, 2019 at 3:59
emacs -Q
?