Reputation: 35216
I'm writing a vim plugin based on clang to do auto-completion; I realize there are other plugins out there that do a similar thing, but none of them address my specific need (macro expansion).
Anyhow, the clang api to parse a file takes a bunch of variables, including the unsaved buffer for the currently open file.
ie. You pass in both the saved copy of the file and the current unsaved buffer, so you can (for example) do auto-completion as you type, rather than only after a save operation.
So, my question is:
What's the best way to obtain the raw unsaved buffer in a vim plugin and pass it to an external executable?
Various solution pop to mind, eg.
Write the current buffer to a temporary file and pass a reference to the temporary file to the external exec.
Python plugin and the posix_ipc module to create a shared memory segement.
Open a stream to the executable and pipe the current buffer into it one line at a time.
Stream the buffer to the executable via a socket eclim style.
I have no idea which one of these is the best choice, or if there's some other better way of doing this.
I like the idea of using a shared memory segment, purely because this will make the plugin blazingly fast, but I can't see any way to do that in a portable fashion.
Upvotes: 1
Views: 463
Reputation: 53674
Proposed way of passing buffer into external program is :w
, for example:
%w !cat -v
Be sure that between w
and !
is a space: w!
has a different meaning.
Upvotes: 2