Friday, December 2, 2022

Re: List of changed lines

1) Vim can diff contents of buffers that are not associated with physical files. On detecting a save, from the change list get the lines of interest in the previous and current version; then appendingly-yank the regions of interest in the current buffer and likewise appendingly-yank the corresponding regions in the saved file; and then open a new buffer that compares the yanked stuff. (I don't mean do these steps manually, but via a script.)

Suresh, when you say 'from the change list', do you mean the output of :changes or something else? If you do mean :changes, does it go far enough back to the previous save where it's possible many lines have changed since the last save?
 

2) I came late to this thread and do not know if comparing an entire file but restricting the display via folds meets your needs. If so, one could detect a save command and write a script that opens a new buffer that visually compares the previous and current versions with unchanged regions folded and the ability to jump to changes via ]c and [c.

--Suresh

So, some editors/IDEs such as Eclipse have an option, when saving Java files, to only reformat/reindent lines that were actually modified, leaving the rest of the file alone. I'm trying to do something similar: find all lines that have been added or modified (looks pretty much like an add to diff) and execute commands on only those lines. The commands could be anything from removing trailing whitespace to reformatting the lines, anything. However, I don't want to do this in a diff window: I want it to be part of a save action, such as on BufWrite.

At this point, I have it pretty much working with regards to pointing out the lines and being able to execute commands on them, but I am running into the whole thing being slow once I've got a file around 1500 lines (I wrote a pure Vim9 diff routine, but am debating involving Python's difflib and parsing its output).

One optimization I've put in is the observation that most editing changes usually happen to a small part of a source file, so I skip over any common lines at the top and bottom of the file, so the range I actually compare both starts and stops at an actual diff, making it faster, but that's easily thwarted by simply making changes at the top and bottom of a file.

I'm now debating generating a hash code for the lines and comparing those, instead. To make that quick, I'll generate a relatively quick hash code and will then compare the actual strings themselves if I get a hash code match.

Once I have it working with a degree of speed, I'll hook into it by writing a 'SaveActions' plugin or some such that can take a list of commands and will run them on the changed lines.

Thanks very much for the suggestions.

--
 
Salman

I, too, shall something make and glory in the making.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEfFNiwB5ZCGbt49U67dp5_pvULyr%3DHnhx02ML%3D8BscfsA%40mail.gmail.com.

No comments: