Skip to content

Commit

Permalink
fix: never use comments to highlight quickfix buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 15, 2021
1 parent 3b086ac commit 7a5e9c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 3 additions & 4 deletions lua/todo-comments/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local defaults = {
before = "", -- "fg" or "bg" or empty
keyword = "wide", -- "fg", "bg", "wide" or empty. (wide is the same as bg, but will also highlight surrounding characters)
after = "fg", -- "fg" or "bg" or empty
pattern = "<(KEYWORDS)>:", -- vim regex
pattern = [[<(KEYWORDS)>:]], -- pattern used for highlightng (vim regex)
comments_only = true, -- this applies the pattern only inside comments using `commentstring` option
},
-- list of named colors where we try to extract the guifg from the
Expand All @@ -59,9 +59,8 @@ local defaults = {
},
-- regex that will be used to match keywords.
-- don't replace the (KEYWORDS) placeholder
pattern = "\\b(KEYWORDS):", -- ripgrep regex
-- pattern = "(KEYWORDS)", -- match without the extra colon. You'll likely get false positives
-- pattern = "-- (KEYWORDS):", -- only match in lua comments
pattern = [[\b(KEYWORDS):]], -- ripgrep regex
-- pattern = [[\b(KEYWORDS)\b]], -- match without the extra colon. You'll likely get false positives
},
}

Expand Down
14 changes: 9 additions & 5 deletions lua/todo-comments/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ function M.highlight(buf, first, last)
local lines = vim.api.nvim_buf_get_lines(buf, first, last + 1, false)

local pattern
if Config.options.highlight.comments_only then
local comment_str = vim.bo.commentstring:gsub('%s+', '')
comment_str = vim.fn.escape(comment_str, '*+?')
pattern = comment_str:gsub('%%s', [[\s*]]..Config.hl_regex..'.*')
pattern = vim.fn.escape(pattern, '%')
if Config.options.highlight.comments_only and not M.is_quickfix(buf) then
local comment_str = vim.bo.commentstring:gsub("%s+", "")
comment_str = vim.fn.escape(comment_str, "*+?")
pattern = comment_str:gsub("%%s", [[\s*]] .. Config.hl_regex .. ".*")
pattern = vim.fn.escape(pattern, "%")
end

for l, line in ipairs(lines) do
Expand Down Expand Up @@ -136,6 +136,10 @@ function M.is_valid_win(win)
return M.is_valid_buf(buf)
end

function M.is_quickfix(buf)
return vim.api.nvim_buf_get_option(buf, "buftype") == "quickfix"
end

function M.is_valid_buf(buf)
-- Skip special buffers
local buftype = vim.api.nvim_buf_get_option(buf, "buftype")
Expand Down

0 comments on commit 7a5e9c9

Please sign in to comment.