I wrote:

> > Paul Jolly wrote:
> > 
> > > > Yesterday I sent out patch 8.1.1321 which adds listener_add().
> > > > This makes it possible to find out about text changes and possibly
> > > > update text properties or anything else.
> > > 
> > > Hi Bram - this is fantastic, thanks. I look forward to giving this a try 
> > > with https://github.com/myitcv/govim and gopls.
> > > 
> > > > Another thing is that the line numbers in the changes are valid for 
> > > > when 
> > > the change is made. 
> > > 
> > > Understood. One relatively easy way to handle this is to handle the 
> > > changes in reverse, i.e. by iterating through the list backwards. But I 
> > > think this requires that the changes themselves be non-overlapping. 
> > > 
> > > From glancing at the documentation in 
> > > https://github.com/vim/vim/commit/a334772967de25764ed7b11d768e8b977818d0c6
> > >  it appears that's the case, but I did just want to check.
> > > 
> > > Please can you confirm?
> > 
> > Not sure.  In a script it's possible a lot of changes happen in
> > sequence, until the next redraw.  So, give it a try.
> > 
> > I was also wondering if we need a "flush" command for the changes, in
> > case a redraw is undesired but the listeners should be invoked.
> > 
> > Another possibility is to automatically flush before adding a change
> > that is above a previous one AND it changes the line count.  That's when
> > keeping track of line numbers becomes difficult.
> 
> Note that if we go this way, then the text must be locked, since the
> callback would then happen somewhere during making changes.  That
> probably isn't a problem, if the plugin is doing some highlighting or
> async server requests.  If needed, the plugin could use a timer to be
> called back later to do further work.

Thinking about this a bit more, I think we can simplify the work that a
plugin needs to do by doing this:

- Before line numbers in the list of changes become invalid, flush the
  changes.  If changes happen from top to bottom, such as with "%s",
  then it will still be one invocation of the callback.

- If there are multiple changes starting at the same line and column, we
  can merge them into reporting one change.

- Instead of only passing the list, also pass a summary of the changes,
  so that the plugin can use the range of lines, without having to go
  through the whole list.  Useful for something like a syntax checker.

- Add listener_flush() to trigger listeners without a redraw.
  Especially useful when programatically changing the text.

- On a redraw, invoke listeners for all buffers (that's actually a
  bugfix).

I'll make a patch that does this, please check it out.

-- 
DENNIS: Look,  strange women lying on their backs in ponds handing out
        swords ... that's no basis for a system of government.  Supreme
        executive power derives from a mandate from the masses, not from some
        farcical aquatic ceremony.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201905141903.x4EJ31qA020207%40masaka.moolenaar.net.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui