Closed vjohansen closed 1 year ago
The package currently gets enabled only for certain major modes. It's something I want to change but haven't time to do yet. That seems like the likely culprit. Can you check if prettier-mode
is enabled in the buffer and what major mode the buffer uses?
I am using https://github.com/orzechowskid/tsx-mode.el which does weird stuff with multiple modes behind the scenes
I added a message call
(define-minor-mode prettier-mode
"Runs prettier on file save when this mode is turned on."
:lighter prettier-lighter
(if prettier-mode
(progn
(message "prettier-mode TRUE '%s' '%s'" major-mode (buffer-name))
Calling global-prettier-mode in two places in a tsx-file (mode is tsx-mode) gives different messages
prettier-mode TRUE ’scss-mode’ ’ tsx-mode css’ prettier-mode TRUE ’graphql-mode’ ’ tsx-mode gql’
tsx-mode is creating hidden buffers which probably is the reason that prettier is not working for this file.
My workaround is this
(add-hook 'before-save-hook #'vj-prettier-on-save)
(defun vj-prettier-on-save ()
(when (and global-prettier-mode (equal major-mode 'tsx-mode))
(prettier--maybe-prettify-on-save)))
Feel free to close this. I do not know enough about minor modes to give advice. The only thing could be to always remove 'local from (add-hook 'before-save-hook func) and the in fnuc do the check if prettier should run.
OK I might close this then, a future version of this package will do something simpler not based on major modes. Glad it's working for you now.
A installed prettier a few days and so it working.
I added
(add-hook 'after-init-hook #'global-prettier-mode)
to my config.
A few days later I use it again and nothing happens when saving a changed file (tsx-mode).
Note the missing prettier--maybe-prettify-on-save
If i call prettier-prettify manually it works
Maybe it is related to 'local when calling add-hook
Note when i disable the minor mode the whole file is printed to Messages with an error at the first line
GNU Emacs 28.2 (build 2, x86_64-w64-mingw32) of 2022-09-13