Skip to content

Commit

Permalink
Make sure that line numbering when lines are split
Browse files Browse the repository at this point in the history
The default line numbering mechanism numbers all the lines in the output. For
source code, a line can be split into multiple lines because of its length. In
that case, we only want the first line to be numbered.

ConTeXt already has this mechanism for \starttyping and \stoptyping. So, we just
hook into that mechanism.
  • Loading branch information
adityam committed Jun 8, 2012
1 parent ab30884 commit 5a6e89c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions 2context.vim
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ while s:lnum <= s:lstop
let s:new = '\HGL{' . s:new . '}'
endif

" Add begin and end line markers
let s:new = "\\SYNBOL{}" . s:new . "\\SYNEOL{}"

call add(s:lines, s:new)

" Increment line numbers
Expand Down
22 changes: 19 additions & 3 deletions t-syntax-highlight.mkiv
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
\appendtoks
\defineexternalfilter[\currentsyntaxhighlighting]
[\s!parent=\????syntaxhighlighting\currentexternalfilter,\c!taglabel=\vimtyping@id]%
\definelinenumbering [\currentsyntaxhighlighting]%
\normalexpanded{\definelinenumbering [\currentsyntaxhighlighting]}%
\setevalue{type\currentsyntaxhighlighting file}{\getvalue{process\currentsyntaxhighlighting file}}%
\to\everydefinesyntaxhighlighting

Expand Down Expand Up @@ -77,6 +77,8 @@
\let\\\textbackslash
\let\{\textbraceleft
\let\}\textbraceright
\let\SYNBOL\donothing
\let\SYNEOL\donothing

\setupbar[syntaxhighlightline][color=\externalfilterparameter\c!highlightcolor]

Expand Down Expand Up @@ -104,9 +106,12 @@

\starttexdefinition syntaxhighlighting@linenumbering_start
\doifinset{\externalfilterparameter\c!numbering}\syntaxhighlighting@yes
{\startlinenumbering
{\let\SYNBOL=\syntaxhighlighting_begin_number_lines
\let\SYNEOL=\syntaxhighlighting_end_number_lines
\startlinenumbering
[\currentsyntaxhighlighting]
[
\c!method=\v!type,
\c!start=\externalfilterparameter{\c!number\c!start},
\c!step=\externalfilterparameter{\c!number\c!step},
\c!continue=\externalfilterparameter{\c!number\c!continue},
Expand All @@ -120,6 +125,17 @@
{\stoplinenumbering}
\stoptexdefinition

\newcount\nofsyntaxhighlightinglines

\starttexdefinition syntaxhighlighting_begin_number_lines
\global\advance\nofsyntaxhighlightinglines\plusone
\attribute\verbatimlineattribute\nofsyntaxhighlightinglines
\stoptexdefinition

\starttexdefinition syntaxhighlighting_end_number_lines
\attribute\verbatimlineattribute\attributeunsetvalue
\stoptexdefinition


\setupsyntaxhighlighting
[\c!tab=4,
Expand Down Expand Up @@ -151,7 +167,7 @@
\c!number\c!step=1,
\c!number\c!continue=\v!no,
\c!numberconversion=\v!numbers,
\c!number\c!method=\v!first,
\c!number\c!method=\v!type, Not used
\c!number\c!location=\v!left,
\c!numberstyle=\ttx,
\c!numbercolor=,
Expand Down
33 changes: 33 additions & 0 deletions tests/vim/19-linenumber-break.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
\usemodule[vim]
\definevimtyping[MATLAB][syntax=matlab, lines=split, numbering=yes, escape=on,
cache=force]

\showframe

\starttext
\startMATLAB
fprintf('random text random text random text random text random text random text= %f.\n', x)
fprintf('random text random text random text random text random text random text= %f.\n', x)
fprintf('random text random text random text random text random text random text= %f.\n', x)
\stopMATLAB

\starttyping[lines=yes, numbering=line]
fprintf('random text random text random text random text random text random text= %f.\n', x)
fprintf('random text random text random text random text random text random text= %f.\n', x)
fprintf('random text random text random text random text random text random text= %f.\n', x)
\stoptyping

\startMATLAB[numbercontinue=yes]
fprintf('random text random text random text random text random text random text= %f.\n', x)
fprintf('random text random text random text random text random text random text= %f.\n', x)
fprintf('random text random text random text random text random text random text= %f.\n', x)
\stopMATLAB

\starttyping[lines=yes, numbering=line, continue=yes]
fprintf('random text random text random text random text random text random text= %f.\n', x)
fprintf('random text random text random text random text random text random text= %f.\n', x)
fprintf('random text random text random text random text random text random text= %f.\n', x)
\stoptyping


\stoptext

0 comments on commit 5a6e89c

Please sign in to comment.