8000 GitHub - emacsmirror/fmo-mode: Format only changed lines
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

emacsmirror/fmo-mode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

fmo-mode.el

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.

Usage

simply add fmo-mode to your desired major mode or globally in prog-mode.

(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)))

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

  • [ ] I think it is probably 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 changed lines

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published

Languages

  • Emacs Lisp 100.0%
0