diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/api.txt | 15 | ||||
-rw-r--r-- | runtime/doc/autocmd.txt | 25 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 43 | ||||
-rw-r--r-- | runtime/doc/news.txt | 6 | ||||
-rw-r--r-- | runtime/doc/pi_gzip.txt | 10 | ||||
-rw-r--r-- | runtime/doc/pi_zip.txt | 7 | ||||
-rw-r--r-- | runtime/doc/provider.txt | 30 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 2 | ||||
-rw-r--r-- | runtime/lua/vim/_editor.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/_meta/api.lua | 11 | ||||
-rw-r--r-- | runtime/lua/vim/clipboard/osc52.lua | 38 | ||||
-rw-r--r-- | runtime/plugin/man.lua | 1 |
12 files changed, 169 insertions, 21 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index 2f9e8228d2..b38524bd55 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -3597,6 +3597,21 @@ nvim_ui_set_option({name}, {value}) *nvim_ui_set_option()* Attributes: ~ |RPC| only +nvim_ui_term_event({event}, {value}) *nvim_ui_term_event()* + Tells Nvim when a terminal event has occurred. + + The following terminal events are supported: + + • "osc_response": The terminal sent a OSC response sequence to Nvim. The + payload is the received OSC sequence. + + Attributes: ~ + |RPC| only + + Parameters: ~ + • {event} Event name + • {payload} Event payload + nvim_ui_try_resize({width}, {height}) *nvim_ui_try_resize()* TODO: Documentation diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 4b36a7d4ec..6b698b0868 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -987,12 +987,25 @@ TermClose When a |terminal| job ends. Sets these |v:event| keys: status *TermResponse* -TermResponse After the response to t_RV is received from - the terminal. The value of |v:termresponse| - can be used to do things depending on the - terminal version. May be triggered halfway - through another event (file I/O, a shell - command, or anything else that takes time). +TermResponse When Nvim receives a OSC response from the + terminal. Sets |v:termresponse|. When used + from Lua, the response string is included in + the "data" field of the autocommand callback. + May be triggered halfway through another event + (file I/O, a shell command, or anything else + that takes time). Example: >lua + + -- Query the terminal palette for the RGB value of color 1 + -- (red) using OSC 4 + vim.api.nvim_create_autocmd('TermResponse', { + once = true, + callback = function(args) + local resp = args.data + local r, g, b = resp:match("\x1b%]4;1;rgb:(%w+)/(%w+)/(%w+)") + end, + }) + io.stdout:write("\x1b]4;1;?\x1b\\") +< *TextChanged* TextChanged After a change was made to the text in the current buffer in Normal mode. That is after diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index c41237b862..2223829548 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2318,18 +2318,10 @@ v:t_string Value of |String| type. Read-only. See: |type()| v:t_blob Value of |Blob| type. Read-only. See: |type()| *v:termresponse* *termresponse-variable* -v:termresponse The escape sequence returned by the terminal for the DA - (request primary device attributes) control sequence. It is - set when Vim receives an escape sequence that starts with ESC - [ or CSI and ends in a 'c', with only digits, ';' and '.' in - between. - When this option is set, the TermResponse autocommand event is - fired, so that you can react to the response from the - terminal. - The response from a new xterm is: "<Esc>[ Pp ; Pv ; Pc c". Pp - is the terminal type: 0 for vt100 and 1 for vt220. Pv is the - patch level (since this was introduced in patch 95, it's - always 95 or bigger). Pc is always zero. +v:termresponse The value of the most recent OSC escape sequence received by + Nvim from the terminal. This can be read in a |TermResponse| + event handler after querying the terminal using another escape + sequence. *v:testing* *testing-variable* v:testing Must be set before using `test_garbagecollect_now()`. @@ -4354,6 +4346,33 @@ This is not allowed when the textlock is active: - etc. ============================================================================== +Vim script library *vim-script-library* + +Vim comes bundled with a Vim script library, that can be used by runtime, +script authors. Currently, it only includes very few functions, but it may +grow over time. + + *dist#vim* +The functions make use of the autoloaded prefix "dist#vim". + +The following functions are available: + +dist#vim#IsSafeExecutable(filetype, executable) ~ + +This function takes a filetype and an executable and checks whether it is safe +to execute the given executable. For security reasons users may not want to +have Vim execute random executables or may have forbidden to do so for +specific filetypes by setting the "<filetype>_exec" variable (|plugin_exec|). + +It returns |TRUE| or |FALSE| to indicate whether the plugin should run the given +exectuable. It takes the following arguments: + + argument type ~ + + filetype string + executable string + +============================================================================== Command-line expressions highlighting *expr-highlight* Expressions entered by the user in |i_CTRL-R_=|, |c_CTRL-\_e|, |quote=| are diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 9ddb1e91b7..ac84f59308 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -205,6 +205,12 @@ The following new APIs and features were added. • Added |vim.base64.encode()| and |vim.base64.decode()| for encoding and decoding strings using Base64 encoding. +• The |TermResponse| autocommand event can be used with |v:termresponse| to + read escape sequence responses from the terminal. + +• A clipboard provider which uses OSC 52 to copy the selection to the system + clipboard is now bundled by default. |clipboard-osc52| + ============================================================================== CHANGED FEATURES *news-changed* diff --git a/runtime/doc/pi_gzip.txt b/runtime/doc/pi_gzip.txt index a709b34180..1aadc103fd 100644 --- a/runtime/doc/pi_gzip.txt +++ b/runtime/doc/pi_gzip.txt @@ -12,9 +12,17 @@ The functionality mentioned here is a |standard-plugin|. This plugin is only available if 'compatible' is not set. You can avoid loading this plugin by setting the "loaded_gzip" variable: > :let loaded_gzip = 1 +< + *g:gzip_exec* + +For security reasons, one may prevent that Vim runs executables automatically +when opening a buffer. This option (default: "1") can be used to prevent +executing the executables command when set to "0": > + :let g:gzip_exec = 0 +< ============================================================================== -1. Autocommands *gzip-autocmd* +2. Autocommands *gzip-autocmd* The plugin installs autocommands to intercept reading and writing of files with these extensions: diff --git a/runtime/doc/pi_zip.txt b/runtime/doc/pi_zip.txt index 343c73839b..a8e1b8df10 100644 --- a/runtime/doc/pi_zip.txt +++ b/runtime/doc/pi_zip.txt @@ -70,6 +70,13 @@ Copyright: Copyright (C) 2005-2015 Charles E Campbell *zip-copyright* extract a file from a zip archive. By default, > let g:zip_extractcmd= g:zip_unzipcmd < + *g:zip_exec* + For security reasons, one may prevent that Vim runs executables + automatically when opening a buffer. This option (default: "1") + can be used to prevent executing the "unzip" command when set to + "0": > + let g:zip_exec=0 +< PREVENTING LOADING~ If for some reason you do not wish to use vim to examine zipped files, diff --git a/runtime/doc/provider.txt b/runtime/doc/provider.txt index 9e70ff8945..1b49ee3a3d 100644 --- a/runtime/doc/provider.txt +++ b/runtime/doc/provider.txt @@ -253,7 +253,35 @@ For Windows WSL, try this g:clipboard definition: \ }, \ 'cache_enabled': 0, \ } - +< + *clipboard-osc52* +Nvim bundles a clipboard provider that allows copying to the system clipboard +using OSC 52. OSC 52 is an Operating System Command control sequence that +writes the copied text to the terminal emulator. If the terminal emulator +supports OSC 52 then it will write the copied text into the system clipboard. + +This is most useful when using Nvim remotely (e.g. via ssh) as Nvim does not +have direct access to the system clipboard in that case. + +Because not all terminal emulators support OSC 52, this provider must be opted +into explicitly by setting the following |g:clipboard| definition: >lua + + vim.g.clipboard = { + name = 'OSC 52', + copy = { + ['+'] = require('vim.clipboard.osc52').copy, + ['*'] = require('vim.clipboard.osc52').copy, + }, + paste = { + ['+'] = require('vim.clipboard.osc52').paste, + ['*'] = require('vim.clipboard.osc52').paste, + }, + } +< +Note that not all terminal emulators support reading from the system clipboard +(and even for those that do, users should be aware of the security +implications), so using OSC 52 for pasting may not be possible. +< ============================================================================== Paste *provider-paste* *paste* diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 8249179187..efebf46d85 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -567,6 +567,8 @@ Working directory (Vim implemented some of these after Nvim): Autocommands: - Fixed inconsistent behavior in execution of nested autocommands: https://github.com/neovim/neovim/issues/23368 +- |TermResponse| is fired for any OSC sequence received from the terminal, + instead of the Primary Device Attributes response. |v:termresponse| ============================================================================== Missing features *nvim-missing* diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 0da127b18f..0bdf0c90a5 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -650,7 +650,7 @@ local on_key_cbs = {} ---if on_key() is called without arguments. function vim.on_key(fn, ns_id) if fn == nil and ns_id == nil then - return #on_key_cbs + return vim.tbl_count(on_key_cbs) end vim.validate({ diff --git a/runtime/lua/vim/_meta/api.lua b/runtime/lua/vim/_meta/api.lua index 6c6e11a0d3..2142a429a2 100644 --- a/runtime/lua/vim/_meta/api.lua +++ b/runtime/lua/vim/_meta/api.lua @@ -2065,6 +2065,17 @@ function vim.api.nvim_ui_set_focus(gained) end --- @param value any function vim.api.nvim_ui_set_option(name, value) end +--- Tells Nvim when a terminal event has occurred. +--- The following terminal events are supported: +--- +--- • "osc_response": The terminal sent a OSC response sequence to Nvim. The +--- payload is the received OSC sequence. +--- +--- +--- @param event string Event name +--- @param value any +function vim.api.nvim_ui_term_event(event, value) end + --- @param width integer --- @param height integer function vim.api.nvim_ui_try_resize(width, height) end diff --git a/runtime/lua/vim/clipboard/osc52.lua b/runtime/lua/vim/clipboard/osc52.lua new file mode 100644 index 0000000000..0e8f9d378f --- /dev/null +++ b/runtime/lua/vim/clipboard/osc52.lua @@ -0,0 +1,38 @@ +local M = {} + +function M.copy(lines) + local s = table.concat(lines, '\n') + io.stdout:write(string.format('\x1b]52;;%s\x1b\\', vim.base64.encode(s))) +end + +function M.paste() + local contents = nil + local id = vim.api.nvim_create_autocmd('TermResponse', { + callback = function(args) + local resp = args.data ---@type string + local encoded = resp:match('\x1b%]52;%w?;([A-Za-z0-9+/=]*)') + if encoded then + contents = vim.base64.decode(encoded) + return true + end + end, + }) + + io.stdout:write('\x1b]52;;?\x1b\\') + + vim.wait(1000, function() + return contents ~= nil + end) + + -- Delete the autocommand if it didn't already delete itself + pcall(vim.api.nvim_del_autocmd, id) + + if contents then + return vim.split(contents, '\n') + end + + vim.notify('Timed out waiting for a clipboard response from the terminal', vim.log.levels.WARN) + return 0 +end + +return M diff --git a/runtime/plugin/man.lua b/runtime/plugin/man.lua index 4b1528b0cb..50a48fe7f2 100644 --- a/runtime/plugin/man.lua +++ b/runtime/plugin/man.lua @@ -16,6 +16,7 @@ vim.api.nvim_create_user_command('Man', function(params) end, { bang = true, bar = true, + range = true, addr = 'other', nargs = '*', complete = function(...) |