Skip to content

expl3 syntax highlighting wrongly marks underscores as errors in csname-style arguments #3163

@cfr42

Description

@cfr42

Description

Thanks for providing support for expl3 syntax highlighting (and for vimtex generally, obviously). Although the result is much better than my previous editor, there are a couple of irritating bugs and I'm not really good enough with vim (yet?!) to address them myself.

The main problem is that underscores are highlighted as errors when they should not be, to the point that the huge number of mistaken red flags is a significant distraction. At best, it makes it impossible to spot any genuine errors. At worst, it makes it very difficult to read the code at all (at least for me).

This is a noticeable problem in at least 3 situations:

  1. when a c type argument specifier is used;
  2. when a v type argument specifier is used;
  3. when defining keys (l3keys).

Steps to reproduce

c type argument specifier

\documentclass{article}
\ExplSyntaxOn
\use:c { __mymod_somefn:Nnn } \l__mymod_mytl_tl { a } { b } 
\ExplSyntaxOff
\begin{document}
a
\end{document}

vimtex incorrectly highlights the underscores in __mymod_somefn:Nnn as errors, even though they are not. The c in \use:c means that the argument will first be turned into a control sequence. \use:c {<stuff>} is equivalent to \csname <stuff>\endcsname. This bug makes it really hard to see what is going on as I sometimes have dozens of 'erroneous' underscores in half a screen of code.

v type argument specifier

Similar to c, but gets the value of the control sequence constructed from the argument and passes that value to the base function rather than the control sequence itself.

\documentclass{article}
\ExplSyntaxOn
\cs_new_protected:Npn \__mymod_description:nnn #1#2#3
{
  \prop_new:c { g__mymod_#1_list_prop }
  \prop_gput:cve { g__mymod_#1_list_prop }
  { l__mymod_#2_tl }
  { \clist_use:c { l__mymod_#3_clist } }
}
\tl_new:N \l__mymod_tryme_tl
\tl_set:Nn \l__mymod_tryme_tl {token_list}
\clist_new:N \l__mymod_tryme_clist
\clist_set:Nn \l__mymod_tryme_clist { aardvark, bonobo, catalyst }
\__mymod_description:nnn { tryme } { tryme } { tryme }
\prop_show:N \g__mymod_tryme_list_prop
\ExplSyntaxOff
\begin{document}
a
\end{document}

The top lines of this trigger lots of red flags from the highlighter. The lower lines are just there to demonstrate the syntax is nonetheless valid by showing the contents of \g__mymod_tryme_list_prop on the console.

Key definitions

\documentclass{article}
\ExplSyntaxOn
\keys_define:nn { fixtounicode }
{
  default .tl_set:N = \l__fixtounicode_default_tl,
  default .initial:n = 2FFFF,
  default .default:V = \c_empty_tl,
  glyphs .clist_set:N = \l__fixtounicode_glyphs_clist,
  glyphs .value_required:n = true,
  pfb .tl_set:N = \l__fixtounicode_pfb_tl,
  pfb .initial:V = \c_empty_tl,
  tfm .tl_set:N = \l__fixtounicode_tfm_tl,
  tfm .initial:V = \c_empty_tl,
  unicodes .clist_set:N = \l__fixtounicode_unicodes_clist,
  unicodes .value_required:n = true,
}
\ExplSyntaxOff
\begin{document}
a
\end{document}

Here, the underscores before the = are all marked as erroneous, though those after the = are not. The markup on the left is standard syntax for defining keys in the l3keys module.

mymod (and fixtounicode) could also be @@ or @ etc. inside a .dtx.

minimal.vim

I'm actually mostly using nvim, but I assume a vim basis is better for reproduction, since the issue isn't nvim specific. I used the v example above to test reproducibiblity with minimal config.

set nocompatible
let &runtimepath  = '~/.vim/plugged/vimtex,' . &runtimepath
let &runtimepath .= ',~/.vim/plugged/vimtex/after'
filetype plugin indent on
syntax enable
" Add relevant options and VimTeX configuration below.

[Incidentally, VimtexInfo reports the use of packages even if \usepackage follows \end{document}. I don't know if this is a feature, a necessary evil or a bug? For example, it claimed my minimal example loaded tikz until I put the document in a clean file, even though tikz followed \end{document}.]

Expected behavior

Valid uses of underscores in these situations should not be highlighted as errors.

Actual behavior

Valid uses of underscores in these situations are highlighted as errors.

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Arch Linux
  Vim version: VIM 9.1 (1-1236)
  Has clientserver: false

VimTeX project: p2
  base: p2.tex
  root: /home/dienw/profion
  tex: /home/dienw/profion/p2.tex
  main parser: current file verified
  document class: article
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
  qf method: LaTeX logfile
~
~

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions