Skip to content

Commit 0f22018

Browse files
committed
fix: avoid invalid option '%-100' to 'format' and similar
As described in the related issue, I didn't have a reliable repro, but I have seen this error message on occasion: > Error executing lua callback: > ...command-t/lua/wincent/commandt/private/match_listing.lua:65: > invalid option '%-100' to 'format' I first suspected a bad cached value, and that may be the case, but either way, the arithmetic here seems off, as it will allow a bad format to occur whenever `width` is, say, 103 (`width` usually comes from a `Window` instance, with `vim.o.columns` used as a fallback). I was finally able to repro by setting `margin` to `1` and then adjusting my window size until `'columns'` was (I think) 107. Closes: #415
1 parent 429b6b7 commit 0f22018

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

lua/wincent/commandt/private/match_listing.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ local format_line = function(line, width, selected)
5757
:gsub('\v', '\\v')
5858

5959
-- Right pad so that selection highlighting is shown across full width.
60-
if width < 104 then
61-
if #line > 99 then
62-
-- No padding needed.
63-
line = prefix .. line
64-
else
65-
line = prefix .. string.format('%-' .. (width - #prefix) .. 's', line)
66-
end
60+
if width < 102 and #line > 99 then
61+
-- No padding needed.
62+
line = prefix .. line
63+
elseif width < 102 then
64+
line = prefix .. string.format('%-' .. (width - #prefix) .. 's', line)
6765
else
6866
-- Avoid: "invalid option" caused by format argument > 99.
6967
line = prefix .. string.format('%-99s', line)

0 commit comments

Comments
 (0)