Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform a less invasive buffer content replacement operation #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on May 23, 2020

  1. feat: Perform a less invasive buffer content replacement operation

    Borrowed from go-mode's gofmt and releated functions:
    https://github.com/dominikh/go-mode.el/blob/734d5232455ffde088021ea5908849ac570e890f/go-mode.el#L1850-L1956
    
    Hence I'm not the original author of most this code, but I have used a
    number of borrowed variations of it over the years for hand-rolled
    formatting solutions.
    
    It works by passing the current buffer content to `diff` via STDIN to
    compare it against the target file on disk producing a RCS formatted
    diff that is easy to parse. It then iterates through the said diff only
    modifying relevant lines to make the buffer be identical to the target
    file.
    
    In my experience it does a much better job of maintaining cursor
    position compared to `insert-file-contents`, as it only modifies lines
    that got corrected, and leaves all other lines in the buffer untouched.
    
    Performance is also excellent and near instant. On my late-2016 13-inch
    MacBook Pro with a Dual-Core i7 at 3.3Ghz, I can't really tell the
    difference between this solution and `insert-file-contents`.
    
    I did also test it against the Haskell example from:
    purcell#19
    
    Replacing buffer content of `Req.hs` with that of `Req-reformatted.hs`
    is most of the time just as fast as `insert-file-contents` (around
    50ms), and only sometimes a little slower of around 100-150ms based on
    my totally unscientific measurement technique of guesstimating it. I
    find that rather impressive as the RCS-formatted diff itself is 17KB.
    
    I also tested the old `replace-buffer-contents`-based variant to see how
    it performs on my machine. It took around 15 seconds.
    jimeh committed May 23, 2020
    Configuration menu
    Copy the full SHA
    6186783 View commit details
    Browse the repository at this point in the history