Doom-emacs: How do I disable (format +onsave) when on js2-mode

Created on 30 Apr 2020  路  4Comments  路  Source: hlissner/doom-emacs

What are you trying to achieve?
To disable (format +onsave) when working with Javascript (js2-mode)

What have you tried?
Below are the things I tried to put in the config.el file

; while deleting the .prettierrc based on issue #2027
(add-hook! 'js2-mode-hook
  (unless (locate-dominating-file default-directory ".prettierrc")
    (format-all-mode -1)))

; trying to force the (unless)
(add-hook! 'js2-mode-hook
  (unless nil (format-all-mode -1)))

;;
(add-hook 'js2-mode-hook 'format-all-mode)

;;
(add-hook 'js2-mode-hook
    (lambda () format-all-mode -1))

And many more variations of the same thing and all I got was either a broken configuration (due to wrong Elisp) or nothing to happen at all

:editor format question elisp resolved

Most helpful comment

You can do it by adding js2-mode to +format-on-save-enabled-modes list (defined in modules/editor/format/config.el) which contrary to its name serves as a black list when first item in the list is not.

(add-to-list '+format-on-save-enabled-modes 'js2-mode t)

All 4 comments

You can do it by adding js2-mode to +format-on-save-enabled-modes list (defined in modules/editor/format/config.el) which contrary to its name serves as a black list when first item in the list is not.

(add-to-list '+format-on-save-enabled-modes 'js2-mode t)

Thanks for the response @AloisJanicek

I tried your solution, but it does not seem to work :/

I put the line in my ~/.doom.d/config.el and executed doom refresh (not sure if its needed in this case) but it still formats "using prettier".

Probably a "dump" of my configs would help to see if I messed up on something

Oh, my bad!
We must ensure that we are appending to the list by adding t as 3rd argument to the add-to-list, otherwise we would override the not at the beginning of the +format-on-save-enabled-modes.

Thank you! It worked :smile:

Was this page helpful?
0 / 5 - 0 ratings