From 49493dc8e006d4e6c6298aedfc39e4c1a9dd74bb Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Thu, 7 Feb 2019 20:21:43 +0200 Subject: [PATCH 1/2] Ticket #3487: mcedit: fixed invalid syntax highlighting ...when both context and keyword end with a newline. To reproduce, create .c or .cxx file and open it in mcedit: \#endif // preprocessor macro with one-line comment int code; /* <-- this line is colorized incorrectly */ int code2; /* <-- next line is colorized properly */ Signed-off-by: Andrew Borodin --- src/editor/syntax.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/editor/syntax.c b/src/editor/syntax.c index 0ef0514fb..b3e255f72 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -446,6 +446,16 @@ apply_rules_going_right (WEdit * edit, off_t i) k->whole_word_chars_right, k->line_start); if (e > 0) { + /* when both context and keyword terminate with a newline, + the context overflows to the next line and colorizes it incorrectly */ + if (_rule._context != 0 && k->keyword[strlen (k->keyword) - 1] == '\n') + { + r = CONTEXT_RULE (g_ptr_array_index (edit->rules, _rule._context)); + if (r->right != NULL && r->right[0] != '\0' + && r->right[strlen (r->right) - 1] == '\n' && e > i + 1) + e--; + } + end = e; _rule.end = e; _rule.keyword = count; From deceefab742a48ad116540baeccb394eab77012e Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Thu, 7 Feb 2019 20:34:46 +0200 Subject: [PATCH 2/2] mcedit: fixed syntax highlighting bug in .c and .cxx syntax scripts To reproduce, open this .c file in mcedit (remove backslashes): /* this preprocessor macro is not colorized, when there is whitespace before '#' and the next line is not empty */ \ #if not_colorized int code; /* this preprocessor macro is colorized properly, the next line is empty */ \ #if colorized int code2; Signed-off-by: Andrew Borodin --- misc/syntax/c.syntax | 2 +- misc/syntax/cxx.syntax | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/syntax/c.syntax b/misc/syntax/c.syntax index 91f070c88..e6fabe997 100644 --- a/misc/syntax/c.syntax +++ b/misc/syntax/c.syntax @@ -36,7 +36,7 @@ context default keyword whole inline yellow keyword whole wchar_t yellow keyword whole ... yellow - keyword whole linestart \{\s\t\}\[\s\t\]#*\n brightmagenta + keyword linestart \{\s\t\}\[\s\t\]#*\n brightmagenta keyword whole \[\s\t\]default yellow keyword whole linestart \[\s\t\]\{ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz\}\[0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz\]: cyan diff --git a/misc/syntax/cxx.syntax b/misc/syntax/cxx.syntax index 3ac9f1fca..08cd444be 100644 --- a/misc/syntax/cxx.syntax +++ b/misc/syntax/cxx.syntax @@ -62,7 +62,7 @@ context default keyword whole using yellow keyword whole wchar_t yellow keyword whole ... yellow - keyword whole linestart \{\s\t\}\[\s\t\]#*\n brightmagenta + keyword linestart \{\s\t\}\[\s\t\]#*\n brightmagenta keyword /\* brown keyword \*/ brown