vim buffer viewport changed

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

vim buffer viewport changed

Paul Jolly
Hi all,

I've searched high and low for answers to my question, but I'm probably using the wrong term/concept so please bear with me in what follows!

As a spare-time experiment, I've pulled together a proof-of-concept Go based host/driver for Vim8 channel-based plugins (the channel implementation works really well BTW):

https://github.com/myitcv/govim

I'm using that as the basis for a channel-based plugin to support Go development in Vim:

https://github.com/myitcv/govim/tree/master/cmd/govim

Part of my experiment involves looking into whether using Go's standard library parser and AST (https://godoc.org/go) in combination with matchaddpos is a more efficient/effective way of syntax highlighting *.go files (particularly large ones).

I have a proof of concept of this working, but what I'm now looking to do is make the approach more efficient.

I'm using the TextChanged and TextChangedI events to trigger a re-parse; no problems there.

But I'm struggling to find the right combination of events/whatever to fire when the visible part (viewport?) of a buffer changes. For example, as a result of a page down, normal mode G jumping to the end of the buffer, gg to go to the top, etc. I want to use such an event to call matchaddpos to highlight the now-visible part of the buffer (which keeps the number of calls to matchaddpos down).

My searching thus far hasn't turned up much. Am I simply using the wrong search terms?

Any help/pointers much appreciated; please ask if you anything above needs to be clarified.

Thanks,


Paul

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: vim buffer viewport changed

Paul Jolly
> But I'm struggling to find the right combination of events/whatever to fire when the visible part (viewport?) of a buffer changes. For example, as a result of a page down, normal mode G jumping to the end of the buffer, gg to go to the top, etc. I want to use such an event to call matchaddpos to highlight the now-visible part of the buffer (which keeps the number of calls to matchaddpos down).

Apologies - it seems I've been making a basic error in my use of winsaveview(); using that in combination with CusorMoved, CusorMovedI, winheight() and winwidth() gets me a lot of the way there.

The one remaining case I can't currently handle is when the size of a split changes: I need to somehow trigger the change in viewport for all buffers affected by, for example, moving the horizontal/vertical split point.

Again, any pointers much appreciated.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: vim buffer viewport changed

Paul Jolly
Replying to self one further time.

For anyone interested I went with a timer-based approach for now

let s:timer = timer_start(100, function('s:updateViewport'), {'repeat': -1})
au CursorMoved,CursorMovedI * call s:updateViewport(0)

with updateViewport defined as follows:

https://github.com/myitcv/govim/blob/87595cdf02ece5531d739e080b696d4847c387fc/plugin/govim.vim#L51-L73

This way, only deltas in the viewport are announced to my plugin.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.