mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
doc: file-change-detect [ci skip]
This commit is contained in:
committed by
Justin M. Keyes
parent
3e21d49836
commit
c66297452c
@ -416,20 +416,46 @@ Example: repeating timer
|
||||
print('sleeping');
|
||||
|
||||
|
||||
Example: File-change detection *file-change-detect*
|
||||
1. Save this code to a file.
|
||||
2. Execute it with ":luafile %".
|
||||
3. Use ":Watch %" to watch any file.
|
||||
4. Try editing the file from another text editor.
|
||||
5. Observe that the file reloads in Nvim (because on_change() calls
|
||||
|:checktime|). >
|
||||
|
||||
local w = vim.loop.new_fs_event()
|
||||
local function on_change(err, fname, status)
|
||||
-- Do work...
|
||||
vim.api.nvim_command('checktime')
|
||||
-- Debounce: stop/start.
|
||||
w:stop()
|
||||
watch_file(fname)
|
||||
end
|
||||
function watch_file(fname)
|
||||
local fullpath = vim.api.nvim_call_function(
|
||||
'fnamemodify', {fname, ':p'})
|
||||
w:start(fullpath, {}, vim.schedule_wrap(function(...)
|
||||
on_change(...) end))
|
||||
end
|
||||
vim.api.nvim_command(
|
||||
"command! -nargs=1 Watch call luaeval('watch_file(_A)', expand('<args>'))")
|
||||
|
||||
|
||||
Example: TCP echo-server *tcp-server*
|
||||
1. Save this code to a file.
|
||||
2. Execute it with ":luafile %".
|
||||
3. Note the port number.
|
||||
4. Connect from any TCP client (e.g. "nc 0.0.0.0 36795"): >
|
||||
|
||||
local function create_server(host, port, on_connection)
|
||||
local function create_server(host, port, on_connect)
|
||||
local server = vim.loop.new_tcp()
|
||||
server:bind(host, port)
|
||||
server:listen(128, function(err)
|
||||
assert(not err, err) -- Check for errors.
|
||||
local sock = vim.loop.new_tcp()
|
||||
server:accept(sock) -- Accept client connection.
|
||||
on_connection(sock) -- Start reading messages.
|
||||
on_connect(sock) -- Start reading messages.
|
||||
end)
|
||||
return server
|
||||
end
|
||||
|
@ -6159,14 +6159,14 @@ A jump table for the options with a short description can be found at |Q_op|.
|
||||
match Match case
|
||||
smart Ignore case unless an upper case letter is used
|
||||
|
||||
*'tagfunc'* *'tfu'*
|
||||
'tagfunc' 'tfu' string (default: empty)
|
||||
local to buffer
|
||||
This option specifies a function to be used to perform tag searches.
|
||||
The function gets the tag pattern and should return a List of matching
|
||||
tags. See |tag-function| for an explanation of how to write the
|
||||
function and an example.
|
||||
|
||||
*'tagfunc'* *'tfu'*
|
||||
'tagfunc' 'tfu' string (default: empty)
|
||||
local to buffer
|
||||
This option specifies a function to be used to perform tag searches.
|
||||
The function gets the tag pattern and should return a List of matching
|
||||
tags. See |tag-function| for an explanation of how to write the
|
||||
function and an example.
|
||||
|
||||
*'taglength'* *'tl'*
|
||||
'taglength' 'tl' number (default 0)
|
||||
global
|
||||
|
Reference in New Issue
Block a user