When writing Javascript, I always put curly brackets after if in a new line, like this:

if(a == 0)

But when I do that in web-mode, the default is like this:

if(a == 0)

Is there a way to fix this?

BTW the same goes with for, but not with function definition. Version information:

versions: emacs(25.1) web-mode("14.0.13”)

I don’t have this problem in the plain javascript-mode.

Here’s a minimal example:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />
   var a = 0;
   if(a == 0)
           a = 1;


As @Scott Weldon in the comments suggested, I tried several things:

  • I updated web-mode to 14.0.19. Same problem.
  • I tried using web-mode in a clean Emacs. Same problem. What I did was:
    1. I ran emacs -Q.
    2. Then I M-x load-library RET ~/.emacs.d/elpa/web-mode-20160717.1201/web-mode.el to load web-mode.
    3. I then tried the minimal example.
  • Does this issue still occur when you start Emacs with emacs -Q? If not, please try to bisect your init file. Also, what version of web-mode are you using? (Post the output of M-x web-mode-debug.) – Scott Weldon Jul 19 '16 at 21:03
  • @ScottWeldon, if I use emacs -Q, it would not find web-mode package. Versions: versions: emacs(25.1) web-mode("14.0.13”). Does the indentation for cc-mode affect web-mode javascript? The only configuration I have for web-mode is a (setq web-mode-markup-indent-offset 2). Also if I just use plain javascript-mode, it doesn’t have this problem. – MetroWind Jul 19 '16 at 21:12
  • I should have clarified: start with emacs -Q and then do M-x load-library RET /path/to/web-mode.el RET. – Scott Weldon Jul 19 '16 at 21:18
  • Also, please edit any new details into your post so that other users can easily see the information without digging through the comments. – Scott Weldon Jul 19 '16 at 21:19
  • 1
    @ScottWeldon, thank you for all the suggestions. Sadly they didn’t work on me. Please see my update for details. – MetroWind Jul 20 '16 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.