aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/man.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
commit9be89f131f87608f224f0ee06d199fcd09d32176 (patch)
tree11022dcfa9e08cb4ac5581b16734196128688d48 /runtime/lua/man.lua
parentff7ed8f586589d620a806c3758fac4a47a8e7e15 (diff)
parent88085c2e80a7e3ac29aabb6b5420377eed99b8b6 (diff)
downloadrneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.gz
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.bz2
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'runtime/lua/man.lua')
-rw-r--r--runtime/lua/man.lua29
1 files changed, 23 insertions, 6 deletions
diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua
index 02e841030f..fce8f89be8 100644
--- a/runtime/lua/man.lua
+++ b/runtime/lua/man.lua
@@ -35,7 +35,7 @@ local function highlight_line(line, linenr)
---@type string[]
local chars = {}
local prev_char = ''
- local overstrike, escape = false, false
+ local overstrike, escape, osc8 = false, false, false
---@type table<integer,{attr:integer,start:integer,final:integer}>
local hls = {} -- Store highlight groups as { attr, start, final }
@@ -139,6 +139,12 @@ local function highlight_line(line, linenr)
prev_char = ''
byte = byte + #char
chars[#chars + 1] = char
+ elseif osc8 then
+ -- eat characters until String Terminator or bell
+ if (prev_char == '\027' and char == '\\') or char == '\a' then
+ osc8 = false
+ end
+ prev_char = char
elseif escape then
-- Use prev_char to store the escape sequence
prev_char = prev_char .. char
@@ -157,8 +163,11 @@ local function highlight_line(line, linenr)
add_attr_hl(match + 0) -- coerce to number
end
escape = false
- elseif not prev_char:match('^%[[\032-\063]*$') then
- -- Stop looking if this isn't a partial CSI sequence
+ elseif prev_char == ']8;' then
+ osc8 = true
+ escape = false
+ elseif not prev_char:match('^[][][\032-\063]*$') then
+ -- Stop looking if this isn't a partial CSI or OSC sequence
escape = false
end
elseif char == '\027' then
@@ -470,7 +479,13 @@ local function put_page(page)
-- XXX: nroff justifies text by filling it with whitespace. That interacts
-- badly with our use of $MANWIDTH=999. Hack around this by using a fixed
-- size for those whitespace regions.
- vim.cmd([[silent! keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g]])
+ -- Use try/catch to avoid setting v:errmsg.
+ vim.cmd([[
+ try
+ keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g
+ catch
+ endtry
+ ]])
vim.cmd('1') -- Move cursor to first line
highlight_man_page()
set_options()
@@ -708,7 +723,7 @@ function M.open_page(count, smods, args)
end
sect, name = extract_sect_and_name_path(path)
- local buf = fn.bufnr()
+ local buf = api.nvim_get_current_buf()
local save_tfu = vim.bo[buf].tagfunc
vim.bo[buf].tagfunc = "v:lua.require'man'.goto_tag"
@@ -724,7 +739,9 @@ function M.open_page(count, smods, args)
end
end)
- vim.bo[buf].tagfunc = save_tfu
+ if api.nvim_buf_is_valid(buf) then
+ vim.bo[buf].tagfunc = save_tfu
+ end
if not ok then
error(ret)