The minor mode to run format-all only on changed lines instead of whole buffer, this is convenient for large legacy code base that have not conform to formatter yet.
fmo-mode can be installed directly through MELPA via the Emacs built-in package manager. Alternatively, it can also be installed from the development repository.
Here is an example:
(use-package fmo-mode
:vc (:fetcher github :repo "xeechou/fmo-mode.el")
:custom (fmo-ensure-formatters t)
:hook ((prog-mode . fmo-mode)
;;fmo-mode requires give formatter to format-all to work.
(fmo-mode . format-all-ensure-formatter)))
Note that
fmo-ensure-formatters
: an alias toformat-all-ensure-formatter
, default tot
. For setting custom formatters, please refer to settings in format-all. Note thatfmo-mode
relies onformat-all-region
, ensure your formatter can work with this function.
it relies on Diff Hunks to track the changed region of the file, we get a list of change regions. Then we iterative-ly apply format-all-region
on the hunks while maintaining a offset
, this offset tracks the size of changes of format-all-region
for each iteration. Then we shift the hunk accordingly. Note that we apply from top to bottom.
- [X] I It is easier if we apply
fmo-format-lines
bottom-up, that we do not even need to keep track of theoffset
anymore. - [ ] resort to use diff directly referring this-article.
GPL-v3