Skip to content

xeechou/fmo-mode.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

fmo-mode.el - Format modified only mode

GNU Emacs MELPA

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.

Installing

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

Customization

  • fmo-ensure-formatters : an alias to format-all-ensure-formatter, default to t. For setting custom formatters, please refer to settings in format-all. Note that fmo-mode relies on format-all-region, ensure your formatter can work with this function.

How it works

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.

Next steps

  • [X] I It is easier if we apply fmo-format-lines bottom-up, that we do not even need to keep track of the offset anymore.
  • [ ] resort to use diff directly referring this-article.

License

GPL-v3

About

Format only modified code in Emacs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published