Tuesday, March 14, 2017

Re: Is there any way to update a buffer in the background?

Hi Bram,

Thanks for your reply.

> I have been wondering about these "no autocommands" operations, since it
> makes a cleaner interface to just manipulate the text without side
> effects.  And we don't need to switch buffers/windows, which also has
> lots of side effects.

Can't agree more. I found my self fighting with side effects quite often.

> Would you need more than setline() and getline()?

Now that you asked, I examined my code again, and found myself doing these things to background buffers:

1) Read text
2) Append text
3) Delete text
4) Search text
5) Get the number of lines in a buffer
6) Define <buffer> key mappings

These operations, except 1), have no API or command for background buffers. I think 6) can be achieved by using custom filetype plugins, so it's 2), 3), 4) and 5) that truly matters.

It would be really nice if Vim can support all these operations for all buffers. But now I'm wondering, since the current buffer has quite a complete API, and Vim has closures and lambdas now, will it be easier and less intrusive to provide side-effect-free buffer/window switching operations? For example:

:call withbuffer(42, function('UpdateBuffer'))

The withbuffer() function temporarily switches to buffer 42, calls the passed function, then restores the old buffer before it returns, and doesn't do redraws or trigger autocmds or update the jump list etc.

I'm sorry if there are false optimism/assumptions. I'm not quite familiar with the Vim source code.

Regards,

Kay Z.

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

No comments: