-4

When I enter a function I get indentation like so:

function bla {
    if []; then
        echo
        fi

The first line after the function header is indented 4 literal spaces, then after the if line, I get a literal tab that is 8 spaces long. The real kicker is, that when I try to delete the tab before fi, Emacs converts the tab into spaces and only deletes the first space.

Btw, I press Tab at the beginning of every indented line, because somehow Enter does not indent automatically.

EDIT: I guess I have to accept that indentation in Emacs is a little "special".

bug
  • 515
  • 1
  • 5
  • 17
  • 2
    Not sure which part you think is wrong. W.r.t space-vs-tab, Emacs simply uses TAB chars when it can (as an optimisation). If you don't like that optimization, then set `indent-tabs-mode` accordingly. But really, there are better things to do in life than to worry about tabs-vs-spaces. – Stefan Aug 16 '13 at 01:47

1 Answers1

3

You can press Tab just after typing fi, with cursor still at the end of line. It should fix the indentation of the current line. So, learn to press Tab at the end of each line, not at the beginning.

choroba
  • 231,213
  • 25
  • 204
  • 289
  • Is that your solution? Why does Emacs insert a tab character that is 8 spaces long in the first place? – bug Aug 15 '13 at 17:48
  • 1
    @bug: You can configure what `tab` does. You can make it insert spaces and customize its width. – choroba Aug 15 '13 at 18:46
  • Has this already been files as a bug? How exactly do I solve the issue? – bug Aug 15 '13 at 18:51
  • 1
    @bug: What behaviour do you expect? – choroba Aug 15 '13 at 19:33
  • 4
    @bug: that's a feature, not a bug! This question belongs on superuser.com, but good luck! – shellter Aug 15 '13 at 23:49
  • 1
    @choroba: Two possible solutions: 1) Emacs handles all indentation automatically (I do not need to press tab at all) and consistently (no retarded mix-ups of tabs and spaces) or 2) Emacs doesn't handle indentation at all. I would only want to settle for the second option as a last resort though. – bug Aug 16 '13 at 13:53
  • @bug: The second option is true. It is probably the `shell-script-mode` that handles indentation in this case. – choroba Aug 16 '13 at 13:56
  • @choroba: The 2nd option is not true. As I've written, Emacs inserts different indentation characters depending on the preceding line (spaces after a function header and a tab after an `if`). – bug Aug 16 '13 at 14:25
  • 2
    @bug Emacs has millions of users. They all use Emacs' indentation fine. Do you think there's a chance the problem here is not really the editor? – Thomas Aug 16 '13 at 14:51
  • @Thomas: No, but feel free to convince me otherwise, for example by providing an explanation on the rationale behind this indentation behavior. Also where did you get that statistic from? ("Emacs has millions of users.") – bug Aug 16 '13 at 15:08
  • 3
    @bug Stackoverflow is not a place for extended discussions. I suggest, though, to reword your question along the lines of "How can I achieve the following behavior?", describing what you would like Emacs to do. I suppose that that way you will have a higher chance of getting a satisfactory answer. – Thomas Aug 16 '13 at 16:38
  • I do not want to change the standard indentation behavior of Emacs until I understand the reasoning behind it. I want to know why a mix of tabs and spaces, something which I thought was universally panned by most coders, is the default. – bug Aug 16 '13 at 16:50
  • 1
    bug: Because it's *been* the default for far longer than most editors (and many coders) have existed. Emacs defaults have a lot of inertia, but that's fine because you can configure it to your liking. – phils Aug 20 '13 at 21:48