Skip to content

Commit

Permalink
Add escape_punctuation lexer configuration property.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Apr 4, 2023
1 parent a0f162d commit 17f2fdc
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/EditAutoC.c
Expand Up @@ -1466,7 +1466,7 @@ static bool EditCompleteWordCore(int iCondition, bool autoInsert) {
chPrev2 = SciCall_GetCharAt(before2);
}
// word after escape character or format specifier
if (pLexCurrent->iLexer != SCLEX_TEXINFO && (chPrev == '%' || chPrev == pLexCurrent->escapeCharacterStart)) {
if (chPrev == '%' || (chPrev == pLexCurrent->escapeCharacterStart && (pLexCurrent->lexerAttr & LexerAttr_EscapePunctuation) == 0)) {
const int style = SciCall_GetStyleIndexAt(iStartWordPos);
if (IsEscapeCharOrFormatSpecifier(before, ch, chPrev, style, false)) {
++iStartWordPos;
Expand Down
1 change: 1 addition & 0 deletions src/EditLexer.h
Expand Up @@ -39,6 +39,7 @@ enum {
LexerAttr_AngleBracketGeneric = 1 << 7,
LexerAttr_CppPreprocessor = 1 << 8,
LexerAttr_CharacterPrefix = 1 << 9,
LexerAttr_EscapePunctuation = 1 << 10,
};

enum {
Expand Down
3 changes: 2 additions & 1 deletion src/EditLexers/stlBatch.c
Expand Up @@ -127,7 +127,8 @@ EDITLEXER lexBatch = {
SCLEX_BATCH, NP2LEX_BATCH,
//Settings++Autogenerated -- start of section automatically generated
{
LexerAttr_NoBlockComment,
LexerAttr_NoBlockComment |
LexerAttr_EscapePunctuation,
TAB_WIDTH_4, INDENT_WIDTH_4,
(1 << 0) | (1 << 1), // level1, level2
0,
Expand Down
3 changes: 2 additions & 1 deletion src/EditLexers/stlCMake.c
Expand Up @@ -165,7 +165,8 @@ EDITLEXER lexCMake = {
SCLEX_CMAKE, NP2LEX_CMAKE,
//Settings++Autogenerated -- start of section automatically generated
{
LexerAttr_AngleBracketGeneric,
LexerAttr_AngleBracketGeneric |
LexerAttr_EscapePunctuation,
TAB_WIDTH_4, INDENT_WIDTH_4,
(1 << 0) | (1 << 1), // level1, level2
0,
Expand Down
3 changes: 2 additions & 1 deletion src/EditLexers/stlGN.c
Expand Up @@ -60,7 +60,8 @@ EDITLEXER lexGN = {
SCLEX_GN, NP2LEX_GN,
//Settings++Autogenerated -- start of section automatically generated
{
LexerAttr_NoBlockComment,
LexerAttr_NoBlockComment |
LexerAttr_EscapePunctuation,
TAB_WIDTH_4, INDENT_WIDTH_4,
(1 << 0) | (1 << 1), // level1, level2
0,
Expand Down
2 changes: 1 addition & 1 deletion src/EditLexers/stlLaTeX.c
Expand Up @@ -31,7 +31,7 @@ EDITLEXER lexLaTeX = {
SCLEX_LATEX, NP2LEX_LATEX,
//Settings++Autogenerated -- start of section automatically generated
{
LexerAttr_Default,
LexerAttr_EscapePunctuation,
TAB_WIDTH_4, INDENT_WIDTH_4,
(1 << 0) | (1 << 1), // level1, level2
0,
Expand Down
3 changes: 2 additions & 1 deletion src/EditLexers/stlMarkdown.c
Expand Up @@ -51,7 +51,8 @@ EDITLEXER lexMarkdown = {
SCLEX_MARKDOWN, NP2LEX_MARKDOWN,
//Settings++Autogenerated -- start of section automatically generated
{
LexerAttr_NoLineComment,
LexerAttr_NoLineComment |
LexerAttr_EscapePunctuation,
TAB_WIDTH_4, INDENT_WIDTH_4,
(1 << 0) | (1 << 1), // header1, header2
0,
Expand Down
2 changes: 1 addition & 1 deletion src/EditLexers/stlTexinfo.c
Expand Up @@ -76,7 +76,7 @@ EDITLEXER lexTexinfo = {
SCLEX_TEXINFO, NP2LEX_TEXINFO,
//Settings++Autogenerated -- start of section automatically generated
{
LexerAttr_Default,
LexerAttr_EscapePunctuation,
TAB_WIDTH_4, INDENT_WIDTH_4,
(1 << 0) | (1 << 1) | (1 << 2), // chapter, section, subsection
0,
Expand Down
10 changes: 10 additions & 0 deletions tools/LexerConfig.py
Expand Up @@ -28,6 +28,7 @@
format_specifier_style: style for format specifier.
escape_char_start: character used to escape special characters, default is backslash.
escape_char_style: style for escape character.
escape_punctuation: only escape with punctuation.
raw_string_style: styles where backslash is treated literally.
character_style: styles for character literal.
character_prefix: prefix for character literal or single quoted string.
Expand Down Expand Up @@ -58,6 +59,7 @@ class LexerAttr(IntFlag):
AngleBracketGeneric = 1 << 7 # angle_bracket_generic
CppPreprocessor = 1 << 8 # cpp_preprocessor
CharacterPrefix = 1 << 9 # character_prefix
EscapePunctuation = 1 << 10 # escape_punctuation

class KeywordAttr(IntFlag):
Default = 0
Expand Down Expand Up @@ -207,6 +209,7 @@ class KeywordAttr(IntFlag):
'line_comment_at_line_start': True,
'escape_char_start': '^',
'escape_char_style': 'SCE_BAT_ESCAPECHAR',
'escape_punctuation': True,
'operator_style': ['SCE_BAT_OPERATOR'],
'extra_word_char': '-$',
},
Expand All @@ -230,6 +233,7 @@ class KeywordAttr(IntFlag):
'line_comment_string': '#',
'block_comment_string': ('#[[', ']]'),
'escape_char_style': 'SCE_CMAKE_ESCAPECHAR',
'escape_punctuation': True,
'angle_bracket_generic': True, # for bracket argument $<>
'operator_style': ['SCE_CMAKE_OPERATOR'],
'auto_ident_word_style': ['SCE_CMAKE_WORD'],
Expand Down Expand Up @@ -353,6 +357,7 @@ class KeywordAttr(IntFlag):
'NP2LEX_GN': {
'line_comment_string': '#',
'escape_char_style': 'SCE_GN_ESCAPECHAR',
'escape_punctuation': True,
'operator_style': ['SCE_GN_OPERATOR', 'SCE_GN_OPERATOR2'],
'extra_word_char': '-$',
#'ignore_word_style': ['SCE_GN_KEYWORD', 'SCE_GN_BUILTIN_FUNCTION', 'SCE_GN_BUILTIN_VARIABLE'],
Expand Down Expand Up @@ -515,6 +520,7 @@ class KeywordAttr(IntFlag):
'block_comment_on_new_line': True,
'escape_char_start': '^',
'escape_char_style': 'SCE_L_SPECIAL',
'escape_punctuation': True,
'operator_style': ['SCE_L_OPERATOR'],
},
'NP2LEX_LISP': {
Expand Down Expand Up @@ -553,6 +559,7 @@ class KeywordAttr(IntFlag):
'block_comment_string': ('<!--', '-->'),
'default_fold_level': ['header1', 'header2'],
'escape_char_style': 'SCE_MARKDOWN_ESCAPECHAR',
'escape_punctuation': True,
},
'NP2LEX_MATLAB': {
'line_comment_string': ['%', '//'],
Expand Down Expand Up @@ -770,6 +777,7 @@ class KeywordAttr(IntFlag):
'default_fold_level': ['chapter', 'section', 'subsection'],
'escape_char_start': '@',
'escape_char_style': 'SCE_TEXINFO_SPECIAL',
'escape_punctuation': True,
'operator_style': ['SCE_TEXINFO_OPERATOR'],
},
'NP2LEX_TOML': {
Expand Down Expand Up @@ -978,6 +986,8 @@ def BuildLexerConfigContent(rid, keywordAttr):
flag |= LexerAttr.CppPreprocessor
if config.get('character_prefix', None):
flag |= LexerAttr.CharacterPrefix
if config.get('escape_punctuation', None):
flag |= LexerAttr.EscapePunctuation

output = ['\t{']
indent = '\t\t'
Expand Down

0 comments on commit 17f2fdc

Please sign in to comment.