mooz / js2-mode

Improved JavaScript editing mode for GNU Emacs
GNU General Public License v3.0
1.33k stars 186 forks source link

js2-indent-switch-body doesn't do anything #277

Closed gsnedders closed 9 years ago

gsnedders commented 9 years ago

Testing with:

switch(true) {
case 'true':
    return 1;
}

Set js2-indent-switch-body to t. Go to case 'true': and press tab. Watch as it stays at column 0. This goes against the documentation ("Otherwise [when not nil], all lines inside switch statement body are indented one additional level"), as I would expect it to get indented by js2-basic-offset.

gsnedders commented 9 years ago

(This is using 20151015.1244 on MELPA.)

dgutov commented 9 years ago

Are you using Emacs 25 snapshot? Then you'll need to customize js-switch-indent-offset, like mentioned (or at least hinted at) in NEWS.

This goes against the documentation ("Otherwise [when not nil], all lines inside switch statement body are indented one additional level")

Could you mention the exact steps you took to read that documentation?

gsnedders commented 9 years ago

It's GNU Emacs 24.5.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21), as packaged by homebrew—so no. The documentation quoted comes from the "customize js2-mode" menu item.

dgutov commented 9 years ago

That works for me in 24.5. Does js2-indent-switch-body actually evaluate to t in the target buffer?

Try M-x describe-variable or M-:.

gsnedders commented 9 years ago

Hmm. Yes, it does. Now I restarted emacs, and it still evaluates to t, yet now it works. o_O

gsnedders commented 9 years ago

And yet in another buffer it doesn't work. This is pretty weird. I wonder if it's just a bug in the indentation caused by something in that buffer?

dgutov commented 9 years ago

What's the value of that variable in the other buffer?

gsnedders commented 9 years ago

t.

OK, so let's try this:

Trying to create a more minimal TC seems to be weirdly difficult. Cutting stuff down in the buffer while indent doesn't do it, killing the buffer, then reopening the file now cut down results in indent then working.

dgutov commented 9 years ago

idlharness.js puts the opening brace on a separate line, which we apparently didn't handle.

Should be fixed now, thanks

cpbotha commented 8 years ago

Just in case you're like me, and you were trying to figure out why js2-mode on Emacs 25 and up lines up case with switch, and how to change it: js2-indent-switch-body is NOT the answer. :)

On Emacs 25, js2-mode uses the js-mode indentation. To have case indented within switch, and also the case contents further indented, add something like (setq js-switch-indent-offset 4) to your js2-mode-hook.