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

Update the buffers after creation from original file? #30

Open
unphased opened this issue Nov 7, 2018 · 3 comments
Open

Update the buffers after creation from original file? #30

unphased opened this issue Nov 7, 2018 · 3 comments

Comments

@unphased
Copy link

unphased commented Nov 7, 2018

I know that this might be outside the scope of the plugin but I figured since it has so many nice things (like sign markers and everything) it would be cool if it could detect and sync the changes made in the source buffer.

@AndrewRadev
Copy link
Owner

It's a difficult problem to solve without significant drawbacks.

The way that the proxy buffers and the original keep in sync is that the proxy buffers keep a range of lines from the original that they're affecting. Once you update the proxy buffers, that range gets entirely replaced, and the signs and everything can be updated. But the other way around is not possible, because there's no way to tell if lines have been added or removed.

Say you had this content in the original buffer:

def foo
  puts "bar"
end

Now, if you proxied this buffer and then made this change in the original:

def foo
  puts "bar"
  puts "baz"
end

How would the proxy buffer look now? Well, it'd have to be updated like so:

def foo
  puts "bar"
  puts "baz"

This is probably not what you'd expect, especially if you're using it to diff two pieces of similar code. But there's no way for the proxy to know "the start and/or end line has changed", because the change is logical. There might be a way to guess, if Vim were throwing an event like "line has been added within this range" (although even then it'd be difficult to say what would happen if you add a file after the end of the range).

It might be possible to create a command that manually replaces a particular range. Say, you make some change in the original buffer, and then you select the new area it should be covering, do a :LinediffReplace 1. But even with that, there's the problem that the second buffer might also have moved if it was located below the first one in the original buffer. So you'd likely have to replace that one as well (although maybe the difference between the new and old range can be taken, and the second can be automatically adjusted, so this might be solvable). But I wonder if, in that case, it isn't just as easy to :LinediffReset and just reselect both areas. Maybe it would still be helpful, if the second area is not changed and can be auto-adjusted.

Does that make sense? Am I explaining well enough the problem, and what do you think of a potential :LinediffReplace command (I can't say for sure this would work, I'd need to experiment)?

@xaizek
Copy link
Contributor

xaizek commented Nov 17, 2018

I don't think I need this feature, but I noticed that Vim actually updates signs on changes to the buffer just like it does with the marks (try adding/removing lines and see signs keeping their positions). There is also :sign place command which can accept buffer number and list positions of signs there. And since Vim 7.4 there is getbufinfo('%')[0].signs with the list of signs and where they are.

@AndrewRadev
Copy link
Owner

Oh, that's very interesting. I hadn't realized that Vim actually moves the signs around. Thank you, @xaizek, I'll try to build something using this info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants