nvim-config

Log | Files | Refs | Submodules | README

commit 8ec29906d1258c97d7485c62380bd0c2721eca49
parent b37a007cf09e6908c3392d0a1746c1e97bd6bae4
Author: Thomas Vigouroux <thomas.vigouroux@protonmail.com>
Date:   Mon, 10 Oct 2022 07:45:42 +0200

latex: enhance highlights

Diffstat:
Mafter/ftplugin/tex.lua | 15+++++++++------
Mqueries/latex/highlights.scm | 239++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 247 insertions(+), 7 deletions(-)

diff --git a/after/ftplugin/tex.lua b/after/ftplugin/tex.lua @@ -77,8 +77,7 @@ local function correct_position_wrap(ty, spos, epos, func) local text = vim.api.nvim_buf_get_text(curbuf, start_line, start_col, end_line, end_col, {}) local indent = vim.fn.indent(start[2]) - -- TODO(vigoux): the indentation is wrong after inserting, maybe reformat the range too ? - func(ty, curbuf, start_line, start_col, end_line, end_col, text, indent) + func(ty, curbuf, start_line, start_col, end_line, end_col, text, vim.fn['repeat'](' ', indent)) end TexDispatch = function() end @@ -139,16 +138,20 @@ local function preffix_suffix_change(func) local preffix, suffix = func(input) if type == 'char' then - if preffix:sub(#preffix) ~= '{' then - -- Add an articial space here + -- Add an articial spaces when necessary + if preffix:match "%S$" and preffix:sub(#preffix) ~= '{' then preffix = preffix .. ' ' end + if suffix:match "^%S" and suffix:sub(1, 1) ~= '}' then + suffix = ' ' .. suffix + end + text[1] = preffix .. text[1] text[#text] = text[#text] .. suffix elseif type == 'line' then - table.insert(text, 1, vim.fn['repeat'](' ', indent) .. preffix) - text[#text + 1] = vim.fn['repeat'](' ', indent) .. suffix + table.insert(text, 1, indent .. preffix) + text[#text + 1] = indent .. suffix elseif type == 'block' then error "Block type not supported" end diff --git a/queries/latex/highlights.scm b/queries/latex/highlights.scm @@ -1,4 +1,241 @@ -;; extends +;; General syntax +(ERROR) @error + +(command_name) @function +(caption + command: _ @function) + +(key_value_pair + key: (_) @parameter + value: (_)) + +[ + (line_comment) + (block_comment) + (comment_environment) +] @comment + +(generic_command command: (_) @_note arg: (curly_group) @comment (#eq? @_note "\\note")) + +[ + (brack_group) + (brack_group_argc) +] @parameter + +[(operator) "="] @operator + +"\\item" @punctuation.special + +((word) @punctuation.delimiter +(#eq? @punctuation.delimiter "&")) + +["[" "]" "{" "}"] @punctuation.bracket ; "(" ")" has no syntactical meaning in LaTeX + +;; General environments +(begin + command: _ @text.environment + name: (curly_group_text (text) @text.environment.name)) + +(end + command: _ @text.environment + name: (curly_group_text (text) @text.environment.name)) + +;; Definitions and references +(new_command_definition + command: _ @function.macro + declaration: (curly_group_command_name (_) @function)) +(old_command_definition + command: _ @function.macro + declaration: (_) @function) +(let_command_definition + command: _ @function.macro + declaration: (_) @function) + +(environment_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +(theorem_definition + command: _ @function.macro + name: (curly_group_text (_) @text.environment.name)) + +(paired_delimiter_definition + command: _ @function.macro + declaration: (curly_group_command_name (_) @function)) + +(label_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(label_reference_range + command: _ @function.macro + from: (curly_group_text (_) @text.reference) + to: (curly_group_text (_) @text.reference)) +(label_reference + command: _ @function.macro + names: (curly_group_text_list (_) @text.reference)) +(label_number + command: _ @function.macro + name: (curly_group_text (_) @text.reference) + number: (_) @text.reference) + +(citation + command: _ @function.macro + keys: (curly_group_text_list) @text.reference) + +(glossary_entry_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(glossary_entry_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +(acronym_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(acronym_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +(color_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(color_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +;; Math +[ + (displayed_equation) + (inline_formula) +] @text.math + +(math_environment + (begin + command: _ @text.math + name: (curly_group_text (text) @text.math))) + +(math_environment + (text) @text.math) + +(math_environment + (end + command: _ @text.math + name: (curly_group_text (text) @text.math))) + +;; Sectioning +(title_declaration + command: _ @namespace + options: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(author_declaration + command: _ @namespace + authors: (curly_group_author_list + ((author)+ @text.title))) + +(chapter + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(part + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(section + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(subsection + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(subsubsection + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(paragraph + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(subparagraph + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +;; Beamer frames +(generic_environment + (begin + name: (curly_group_text + (text) @text.environment.name) + (#any-of? @text.environment.name "frame")) + . + (curly_group (_) @text.title)) + +((generic_command + command: (command_name) @_name + arg: (curly_group + (text) @text.title)) + (#eq? @_name "\\frametitle")) + +;; Formatting +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.emphasis)) + (#eq? @_name "\\emph")) + +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.emphasis)) + (#match? @_name "^(\\\\textit|\\\\mathit)$")) + +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.strong)) + (#match? @_name "^(\\\\textbf|\\\\mathbf)$")) + +((generic_command + command: (command_name) @_name + . + arg: (curly_group (_) @text.uri)) + (#match? @_name "^(\\\\url|\\\\href)$")) + +;; File inclusion commands +(class_include + command: _ @include + path: (curly_group_path) @string) + +(package_include + command: _ @include + paths: (curly_group_path_list) @string) + +(latex_include + command: _ @include + path: (curly_group_path) @string) +(import_include + command: _ @include + directory: (curly_group_path) @string + file: (curly_group_path) @string) + +(bibtex_include + command: _ @include + path: (curly_group_path) @string) +(biblatex_include + "\\addbibresource" @include + glob: (curly_group_glob_pattern) @string.regex) + +(graphics_include + command: _ @include + path: (curly_group_path) @string) +(tikz_library_import + command: _ @include + paths: (curly_group_path_list) @string) + ( (word) @spell (#not-has-ancestor? @spell