Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve highlight of commented code #2319

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion autoload/vimtex/syntax/core.vim
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,27 @@ function! vimtex#syntax#core#init() abort " {{{1

" Highlight \iffalse ... \fi blocks as comments
syntax region texComment matchgroup=texCmd
\ start="^\s*\\iffalse\>" end="\\fi\>"
\ start="^\s*\\iffalse\>" end="\\\(fi\|else\)\>"
\ contains=texCommentConditionals

syntax cluster texIftrueCluster contains=TOP
syntax cluster texIftrueClusterCommon contains=@texIftrueCluster,texIftrueConditionals

syntax region texIftrue matchgroup=texCmd
\ start="^\s*\\iftrue\>" end="\(\\\(fi\|else\)\>\)\@="
\ transparent contains=@texIftrueClusterCommon
\ nextgroup=texIftrueElseComment

syntax region texIftrueElseComment matchgroup=texCmd
\ start="\(\(\\fi\>\)@=\|\\else\>\)" end="\\fi\>"
\ contained contains=texCommentConditionals

highlight def link texIftrueElseComment texComment

syntax region texIftrueConditionals matchgroup=texCmd
\ start="\\if\w\+" end="\\fi\>"
\ contained contains=@texIftrueClusterCommon

syntax region texCommentConditionals matchgroup=texComment
\ start="\\if\w\+" end="\\fi\>"
\ contained transparent
Expand Down
13 changes: 13 additions & 0 deletions test/test-syntax/test-iffalse.tex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
\iffalse
Commented stuff
Another \ifstuff here \fi
\ifaa \else \fi
\ifasd \fi \f \fii

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
Expand All @@ -19,4 +20,16 @@
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\fi

\iffalse
Commented stuff
Another \ifstuff here \fi
\ifaa \else \fi
\ifasd \fi \f \fii
\else
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\fi

\end{document}
38 changes: 38 additions & 0 deletions test/test-syntax/test-iftrue.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}

\begin{document}

\iftrue
\section{asd}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\ifasd \fi
\ifaa asd \else asd \fi
\fi

\section{qwe}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\iftrue
\section{asd}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\ifasd \fi
\ifaa asd \else asd \fi
\else
Commented stuff
Another \ifstuff here \fi
\ifaa \else \fi
\ifasd \fi \f \fii
\fi

\end{document}