Monday, May 13, 2019

Re: triggering macro on navigation to new line

On 2019-05-13, Ed Peschko wrote:
> Gary,
>
> thanks for this tip, yes it looks like I could use it to do what I
> want but my concern is speed. I don't want to trigger a potentially
> expensive macro each time the cursor moves anytime, just when the line
> number changes.
>
> So perhaps there is a need for CursorLineMoved? I see in vim where I
> might be added, but I haven't contributed patches to vim before, so
> i'm not sure on how to go about it.

I don't think we need Yet Another Event for this special case. The
usual approach to this sort of problem is to make an inexpensive
test early in the process so that you don't spend time considering
cases you don't care about. In this case, you could cache the last
cursor line location and test against that early in the
autocommand command, perhaps something like this:

:let g:prev_line = 0
:au CursorMoved if line('.') != g:prev_line
\ | let g:prev_line = line('.')
\ | " other stuff
\ | endif

Note that you could have just jumped to the same line number in
a different buffer, so you should test the buffer number, too,
perhaps with getcurpos() instead of line() to get both the buffer
number and the line number.

Regards,
Gary

--
--
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/20190513195231.GC12153%40phoenix.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment