From da6f68ee6966ebf434eee840b22a4f45e61d77dd Mon Sep 17 00:00:00 2001 From: Lennard Hofmann Date: Fri, 7 Jun 2024 21:43:17 +0200 Subject: fix(man): filter OSC 8 hyperlink markup #29171 Problem: `man cmake` shows "8;;https://cmake.orghttps://cmake.org8;;" Solution: Remove noise so that it shows as "https://cmake.org". See also: https://en.wikipedia.org/wiki/ANSI_escape_code#OSC --- runtime/lua/man.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'runtime/lua/man.lua') diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index 02e841030f..348e502f34 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 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 -- cgit From ee5aaba21560c3836f46d347c216832864f85668 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 15 Aug 2024 22:02:20 +0800 Subject: fix(man): avoid setting v:errmsg (#30052) --- runtime/lua/man.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'runtime/lua/man.lua') diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index 348e502f34..b9213c8259 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -479,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() -- cgit From 7588ff2d8986e343d440dc8e025b1b5d4d8974b5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 29 Aug 2024 19:53:48 +0800 Subject: fix(man): check if buffer is valid before restoring 'tagfunc' (#30180) --- runtime/lua/man.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'runtime/lua/man.lua') diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua index b9213c8259..fce8f89be8 100644 --- a/runtime/lua/man.lua +++ b/runtime/lua/man.lua @@ -723,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" @@ -739,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) -- cgit