0

I'm editing JSX files with web-mode and our project doesn't use semicolons at the end of the line.

Whenever I press enter at the end of the line, web-mode is auto-indenting two spaces because the semicolon is missing. How can I prevent this?

I've seen that this question has the same problem, but it didn't help me solve this.

As far as I know, there aren't any web-mode specific indentation rules in my emacs init.el, but to be on the safe side, here are all my web-mode settings:

(add-hook 'web-mode-hook
      (lambda ()
        (if (or (equal web-mode-content-type "jsx") (equal web-mode-content-type "javascript"))
            (flymake-jslint-load))))

(add-hook 'web-mode-hook
      (lambda ()
        ;; short circuit js mode and just do everything in jsx-mode
        (if (equal web-mode-content-type "javascript")
            (web-mode-set-content-type "jsx")
          (message "now set to: %s" web-mode-content-type))

        (setq web-mode-markup-indent-offset 2)
        (setq web-mode-css-indent-offset 2)
        (setq web-mode-code-indent-offset 2)))

(require 'flycheck)
(flycheck-add-mode 'javascript-eslint 'web-mode)
(setq-default flycheck-disabled-checkers
  (append flycheck-disabled-checkers
          '(javascript-jshint)))

Update! I just realized that this happens in lines ending with functions, but not with lines that only have variable assignments. Here's a sample:

console.log()
  cursor is here when I press enter
var blub = 2
cursor is here when I press enter.

Now I'm really confused.

Thanks! --chris

  • web-mode author here. As web-mode does not embed a complete js engine, it requires semilicons at the end of lines. – fxbois Mar 10 '16 at 17:40
  • First off, thanks for developing web-mode. Until I joined this project it served me very well. I suppose this would also be a non-trivial enhancement to web-mode? I've taken a look at the source code, but don't have any experience creating major modes in emacs. Would you consider a pull request for this? – flooose Mar 11 '16 at 7:00
  • The best way would be perhaps to write alternative web-mode-javascript-indendation|call,statement,srting,args-beginning (etc.) functions. This way, it would be easier for me to review and we could image to add a flag to use your functions or mines. – fxbois Mar 11 '16 at 8:31

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.