fenollp / erlang-formatter

Format Erlang code using Emacs' erlang-mode
Apache License 2.0
45 stars 5 forks source link

Enable font-lock for correct indentation #47

Closed bjosv closed 2 years ago

bjosv commented 2 years ago

The Font Lock mode is involved in erlang-mode's indentation rules and is normally enabled by default for all modes. But when emacs is running without a display, as in batch mode, Font Lock mode is never enabled. See https://github.com/emacs-mirror/emacs/blob/f188b0185e7ace193b1c5501c5520578b4216ea0/lisp/font-core.el#L131-L132

By calling font-lock-fontify-buffer we will get correct indentation for the parts of the code handled by font-lock, even when running in batch mode. See comments at https://github.com/emacs-mirror/emacs/blob/master/lisp/font-core.el#L116-L117

The involvement of font-lock can be seen by disabling the font-lock mode in an erlang buffer and running: M-x font-lock-mode and M-x erlang-indent-current-buffer ..to get the few differences.

Fixes #45

bjosv commented 2 years ago

I don't know if its common or not to have font-lock involved in the indentation-machinery. Maybe the root-cause is the behavior of erlang-mode?

bjosv commented 2 years ago

This part was the hint for looking into font-lock: https://github.com/fenollp/erlang-formatter/blob/252cb19f13aa078be852e4dc1ec868a9d9999484/priv/erlang.el#L1607-L1624

fenollp commented 2 years ago

Thank you so much!