prettier / prettier-emacs

Minor mode to format JS code on file save
http://jlongster.com/A-Prettier-Formatter
372 stars 53 forks source link

Highlighting "flickering" while applying formatting #64

Open jonkri opened 4 years ago

jonkri commented 4 years ago

Under some circumstances, lines lose their syntax highlighting for a while when formatting is applied.

The attached image illustrates it.

demo

I would like for the text not to temporarily turn to the foreground color.

keithgabryelski commented 4 years ago

prettier mode needs to request re-highlighting after changing the buffer. If you execute: M-x web-mode when highlights are broken, it will fix the highlights. To do this automatically after prettier does its thing:

(eval-after-load 'web-mode
    '(progn
       (add-hook 'web-mode-hook #'add-node-modules-path)
       (add-hook 'after-save-hook #'web-mode)
       (add-hook 'web-mode-hook #'prettier-js-mode)))
jonkri commented 4 years ago

@keithgabryelski:

Thanks for your suggestion, but my problem isn't that the highlight becames broken in a way that the code snippet above fixes. My problem is the "flickering". For a fraction of a second, all the text turns to the foreground color (after which the syntax highlighting is restored automatically, with or without the code snippet that you posted). I would like to avoid this "flickering", if possible, so that the code is always rendered using the correct syntax highlighting, during all milliseconds. :slightly_smiling_face:

I hope that clarifies my problem!