开发者

Launching Vim via Lua

开发者 https://www.devze.com 2022-12-29 01:11 出处:网络
I\'m writing a 开发者_StackOverflow社区simple little Lua commandline app that will build a static website. I\'m storing my fragments in a sqlite database. Retrieving the data from the db is straightfo

I'm writing a 开发者_StackOverflow社区simple little Lua commandline app that will build a static website. I'm storing my fragments in a sqlite database. Retrieving the data from the db is straightforward as is saving it; my question comes from editing the data.

Is there an elegant way to pipe the data from Lua to vim? Can vim edit a memory buffer and return it? I was planning on launching the editor via os.execute('vim') but only after grabbing a temporary file handle and dumping the database output into that. I would like to have to avoid touching the filesystem that way but that is my contingency plan.


The only way I know of to achieve what you want is to allocate a temporary file and edit it. I actually wouldn't worry about touching the filesystem: If your data is small, you can hope that the operating system keeps it in memory cache, and will write the bits out to disk only during otherwise idle cycles.

Some systems offer parts of a filesystem that are guaranteed to be kept in RAM, but it's very unportable.


You can pipe text into vim using stdin (e.g. echo 'Hello, world!' | vim -), but I'm not sure how to feed the edited results to stdout. So, the first part of the solution in lua would be:

local vim = io.popen('vim -', 'w')
vim:write('Hello, world!')

Perhaps you can achieve the results you want using a memory-mapped file?


io.tmpfile; os.getenv (to grab EDITOR, not everyone likes vi(m) ); and an io.popen are what you need...

0

精彩评论

暂无评论...
验证码 换一张
取 消