diff --git a/config/nvim/after/syntax/c.vim b/config/nvim/after/syntax/c.vim new file mode 100644 index 0000000..3a50afb --- /dev/null +++ b/config/nvim/after/syntax/c.vim @@ -0,0 +1,32 @@ +syn clear cTodo +syn clear cType + +" Custom keywords +" +syn keyword cStorageClass function export internal global_var thread_var local_persist +syn keyword cOperator cast + +" Type highlighting +" +" There are inconsistencies around this due to the horrific declaration syntax of C/C++ and +" trying to capture that inside a regexp statement is near impossible. These are made to mostly +" match the way I format my code. +" +syn match cType "\I\i*\ze\s\+\**\I\i*\s*[=;,\)\[]" " Regular declarations +syn match cType "\I\i*\ze\s\+\**\I\i*(" " Function return types + +" Todo notes +" +syn match cTodo "@\I\i*\((\I\i*)\)\=:\?" contained +syn match cNote "\s:\I\i*" contained + +" Functions +" +syn match cFunction "\I\i*\ze(" + +" Contain clusters +" +syn cluster cCommentGroup add=cNote +syn cluster cPreProcGroup add=cFunc,cType + +hi def link cFunction Function diff --git a/config/nvim/after/syntax/qf.vim b/config/nvim/after/syntax/qf.vim new file mode 100644 index 0000000..1cdea1a --- /dev/null +++ b/config/nvim/after/syntax/qf.vim @@ -0,0 +1,28 @@ +syn clear + +" I have completely overriden the formatting for the quickfix and location list buffers so this +" has to be changed to give proper highlighting of the new format +" +syn match qfSignError "\[!\]" contained +syn match qfSignWarn "\[#\]" contained +syn match qfSignSearch "\[\~\]" contained +syn match qfFileName "^[^:]*" contains=@qfSign nextgroup=qfSeparator1 +syn match qfSeparator1 ":" contained nextgroup=qfLineNr +syn match qfLineNr "[^:|]*" contained nextgroup=qfSeparator2,qfSeparator3 +syn match qfSeparator2 ":" contained nextgroup=qfColumnNr +syn match qfColumnNr "[^|]*" contained +syn match qfSeparator3 "|" contained + +syn cluster qfSign contains=qfSignError,qfSignWarn,qfSignSearch + +hi clear qfFileName +hi clear qfLineNr + +hi def link qfSignError DiagnosticSignError +hi def link qfSignWarn DiagnosticSignWarn +hi def link qfSignSearch LineNr +hi def link qfFileName Function +hi def link qfLineNr Number +hi def link qfColumnNr Number + +let b:current_syntax = "qf" diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 63539c6..68a40e5 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -143,6 +143,74 @@ local function PromptBuild() ) end +local function FormatJumpList() + local qf = vim.fn.getqflist( { winid = true, qfbufnr = true }) + local loc = vim.fn.getloclist(0, { winid = true, qfbufnr = true }) + + if qf.winid ~= 0 then + -- This means the quickfix list is open and needs formatting + local ns = vim.api.nvim_create_namespace("__qf.format") + local bufnr = qf.qfbufnr + local entries = vim.fn.getqflist() + local text = {} + local max = { 0, 0, 0 } + + vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1) + vim.api.nvim_buf_set_option(bufnr, "modifiable", true) + + for _, it in ipairs(entries) do + max[1] = math.max(max[1], #tostring(it.lnum)) + max[2] = math.max(max[2], #tostring(it.col)) + max[3] = math.max(max[3], #vim.fn.bufname(it.bufnr)) + end + + -- +2 for the extra colons we put between the filename, line number and column number + local extformat = string.format("[%%s] %%-%ds | %%s", max[1] + max[2] + max[3] + 2) + + for _, it in ipairs(entries) do + local sign = it.type:lower() == "e" and "!" or "#" + local fname = string.format("%s:%d:%d" , vim.fn.bufname(it.bufnr), it.lnum, it.col) + + table.insert(text, extformat:format(sign, fname, it.text)) + end + + vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, text) + + vim.api.nvim_buf_set_option(bufnr, "modifiable", false) + vim.api.nvim_buf_set_option(bufnr, "modified", false) + end + + if loc.winid ~= 0 then + -- This means the location list is open and needs formatting + local ns = vim.api.nvim_create_namespace("__loc.format") + local bufnr = loc.qfbufnr + local entries = vim.fn.getloclist(0) + local text = {} + local max = { 0, 0 } + + vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1) + vim.api.nvim_buf_set_option(bufnr, "modifiable", true) + + for _, it in ipairs(entries) do + max[1] = math.max(max[1], #vim.fn.bufname(it.bufnr)) + max[2] = math.max(max[2], #tostring(it.lnum)) + end + + -- +1 for the extra colon we put between the filename and the line number + local extformat = string.format("[~] %%-%ds | %%s", max[1] + max[2] + 1) + + for _, it in ipairs(entries) do + local fname = string.format("%s:%d", vim.fn.bufname(it.bufnr), it.lnum) + table.insert(text, extformat:format(fname, it.text)) + end + + vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, text) + + vim.api.nvim_buf_set_option(bufnr, "modifiable", false) + vim.api.nvim_buf_set_option(bufnr, "modified", false) + end +end + -- Buffers local function BufferComplete() @@ -238,7 +306,7 @@ local function LayoutHelp(a) if w ~= winid then local bufnr = vim.api.nvim_win_get_buf(w) if _is_help[vim.bo[bufnr].filetype] then - vim.api.nvim_win_close(wi.winid, true) + vim.api.nvim_win_close(w, true) end end end @@ -278,9 +346,10 @@ MAP("n", "m", PromptBuild) AUTOCMD('BufEnter', { command = "let b:man_default_sects=\"2,3\"", pattern = "*.c" }) AUTOCMD('BufReadPost', { command = "setlocal nornu", pattern = "quickfix" }) -AUTOCMD('BufWritePre', { callback = TrimBuffer, pattern = "*" }) -AUTOCMD('VimEnter', { callback = MakeScratch, pattern = "*" }) -AUTOCMD('BufWinEnter', { callback = LayoutHelp, pattern = "*" }) -AUTOCMD('WinEnter', { callback = ExpandHelp, pattern = "*" }) -AUTOCMD('WinLeave', { callback = ExpandHelp, pattern = "*" }) -AUTOCMD('BufRead', { callback = LoadDiagnostics, pattern = "*" }) +AUTOCMD('BufReadPost', { callback = FormatJumpList, pattern = "quickfix" }) +AUTOCMD('BufWritePre', { callback = TrimBuffer, pattern = "*" }) +AUTOCMD('VimEnter', { callback = MakeScratch, pattern = "*" }) +AUTOCMD('BufWinEnter', { callback = LayoutHelp, pattern = "*" }) +AUTOCMD('WinEnter', { callback = ExpandHelp, pattern = "*" }) +AUTOCMD('WinLeave', { callback = ExpandHelp, pattern = "*" }) +AUTOCMD('BufRead', { callback = LoadDiagnostics, pattern = "*" })