Skip to content

Commit 19f3aea

Browse files
committed
generalize start/stop env per command
used for \ExplSyntaxOn/off
1 parent a0291b7 commit 19f3aea

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

completion/latex-dev.cwl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
\EndModuleRelease#*
146146
\ExecuteOptions{optionlist}#*
147147
\ExpandArgs{spec}#*
148-
\ExplSyntaxOff#*
149-
\ExplSyntaxOn#*
148+
\ExplSyntaxOff#endEnv*#expl3
149+
\ExplSyntaxOn#beginEnv*#expl3
150150
\FirstMark[region]{class%plain}#*
151151
\FirstMark{class%plain}#*
152152
\GenericError{continuation}{message%text}{help location%text}{help info%text}#*
@@ -383,9 +383,9 @@ ypos
383383
# expl3 commands
384384
\ExplFileDate#S
385385
\ExplLoaderFileDate#*
386-
\ProvidesExplFile{name}{date}{version}{description}#*
387-
\ProvidesExplClass{name}{date}{version}{description}#*
388-
\ProvidesExplPackage{name}{date}{version}{description}#*
386+
\ProvidesExplFile{name}{date}{version}{description}#beginEnv*#expl3
387+
\ProvidesExplClass{name}{date}{version}{description}#beginEnv*#expl3
388+
\ProvidesExplPackage{name}{date}{version}{description}#beginEnv*#expl3
389389
\GetIdInfo $Id: %<SVN info field%> $ {%<description%>}#*
390390

391391
# document metadata

src/latexpackage.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@ LatexPackage loadCwlFile(const QString fileName, LatexCompleterConfig *config, Q
219219

220220
// get commandDefinition
221221
CommandDescription cd = extractCommandDef(line, valid);
222+
if(valid.startsWith("beginEnv")){
223+
package.possibleCommands["%beginEnv"]<<line;
224+
package.environmentAliases.insert(line, definition);
225+
valid=valid.mid(8); // maintain additional classifiers
226+
}
227+
if(valid.startsWith("endEnv")){
228+
package.possibleCommands["%endEnv"]<<line;
229+
package.environmentAliases.insert(line, definition);
230+
valid=valid.mid(6); // maintain additional classifiers
231+
}
222232
if(valid.contains('K')){
223233
// bracket command like \left etc
224234
cd.bracketCommand=true;

src/syntaxcheck.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,21 @@ void SyntaxCheck::checkLine(const QString &line, Ranges &newRanges, StackEnviron
578578
if(!activeEnv.isEmpty() && activeEnv.top().endingColumn>=0 && tk.start>activeEnv.top().endingColumn){
579579
Environment env=activeEnv.pop();
580580
}
581+
// handle single command env stop e.g. \ExplSyntaxOff
582+
if(tk.type==Token::command){
583+
const QString word=tk.getText();
584+
if(ltxCommands->possibleCommands["%endEnv"].contains(word)){
585+
const QString envName=ltxCommands->environmentAliases.value(word);
586+
if(activeEnv.top().name == envName){
587+
activeEnv.pop();
588+
continue;
589+
}
590+
}
591+
}
592+
581593
// special treatment for ExplSyntaxOff
582594
// it is used to toggle expl3 mode off
583595
if(!activeEnv.isEmpty() && activeEnv.top().name == "expl3"){
584-
const QString word=tk.getText();
585-
if( word == "\\ExplSyntaxOff"){
586-
activeEnv.pop();
587-
continue;
588-
}
589596
if(tk.type==Token::commandUnknown || tk.type==Token::command){
590597
// collect next parts
591598
// e.g. \cs_new:Npn is split into \cs _ new : Npn
@@ -1042,9 +1049,10 @@ void SyntaxCheck::checkLine(const QString &line, Ranges &newRanges, StackEnviron
10421049
// special treatment for \ExplSyntaxOn, \ExplSyntaxOff
10431050
// \ProvidesExplPackage, \ProvidesExplClass and \ProvidesExplFile
10441051
// activate latex3 mode which ignores _ in commandnames
1045-
if(word=="\\ExplSyntaxOn" || word=="\\ProvidesExplPackage" || word=="\\ProvidesExplClass" || word=="\\ProvidesExplFile"){
1052+
if(ltxCommands->possibleCommands["%beginEnv"].contains(word)){
1053+
const QString envName=ltxCommands->environmentAliases.value(word);
10461054
Environment env;
1047-
env.name = "expl3";
1055+
env.name = envName;
10481056
env.id = 1; // to be changed
10491057
env.dlh = dlh;
10501058
env.ticket = ticket;

0 commit comments

Comments
 (0)