diff --git a/config.def.h b/config.def.h index f47034bf1..7cd2e105d 100644 --- a/config.def.h +++ b/config.def.h @@ -299,625 +299,3 @@ static KeyBinding vis_mode_replace[] = { { /* empty last element, array terminator */ }, }; -/* Color definitions for use in the sytax highlighting rules below. A fore - * or background color of -1 specifies the default terminal color. */ -enum { - COLOR_NOHILIT, - COLOR_SYNTAX0, - COLOR_SYNTAX1, - COLOR_SYNTAX2, - COLOR_SYNTAX3, - COLOR_SYNTAX4, - COLOR_SYNTAX5, - COLOR_SYNTAX6, - COLOR_SYNTAX7, - COLOR_SYNTAX8, - COLOR_SYNTAX9, - COLOR_SYNTAX_LAST, /* below are only aliases */ - COLOR_KEYWORD = COLOR_SYNTAX1, - COLOR_CONSTANT = COLOR_SYNTAX4, - COLOR_DATATYPE = COLOR_SYNTAX2, - COLOR_OPERATOR = COLOR_SYNTAX2, - COLOR_CONTROL = COLOR_SYNTAX3, - COLOR_PREPROCESSOR = COLOR_SYNTAX4, - COLOR_PRAGMA = COLOR_SYNTAX4, - COLOR_KEYWORD2 = COLOR_SYNTAX4, - COLOR_BRACKETS = COLOR_SYNTAX5, - COLOR_STRING = COLOR_SYNTAX6, - COLOR_LITERAL = COLOR_SYNTAX6, - COLOR_VARIABLE = COLOR_SYNTAX6, - COLOR_TARGET = COLOR_SYNTAX5, - COLOR_COMMENT = COLOR_SYNTAX7, - COLOR_IDENTIFIER = COLOR_SYNTAX8, - COLOR_TYPE = COLOR_SYNTAX9, - COLOR_WHITESPACE = COLOR_COMMENT, - COLOR_SPACES = COLOR_WHITESPACE, - COLOR_TABS = COLOR_WHITESPACE, - COLOR_EOL = COLOR_WHITESPACE, - COLOR_EOF = COLOR_WHITESPACE, -}; - -static const char *styles[] = { - [COLOR_NOHILIT] = "", - [COLOR_SYNTAX0] = "fore:red,bold", - [COLOR_SYNTAX1] = "fore:green,bold", - [COLOR_SYNTAX2] = "fore:green", - [COLOR_SYNTAX3] = "fore:magenta,bold", - [COLOR_SYNTAX4] = "fore:magenta", - [COLOR_SYNTAX5] = "fore:blue,bold", - [COLOR_SYNTAX6] = "fore:red", - [COLOR_SYNTAX7] = "fore:blue", - [COLOR_SYNTAX8] = "fore:cyan", - [COLOR_SYNTAX9] = "fore:yellow", - [COLOR_SYNTAX_LAST] = NULL, -}; - -/* Syntax color definitions per file type. Each rule consists of a regular - * expression, a color to apply in case of a match and boolean flag inidcating - * whether it is a multiline rule. - * - * The syntax rules where initially imported from the sandy editor, written by - * Rafael Garcia - */ -#define B "\\b" -/* Use this if \b is not in your libc's regex implementation */ -// #define B "^| |\t|\\(|\\)|\\[|\\]|\\{|\\}|\\||$" - -/* common rules, used by multiple languages */ - -#define SYNTAX_MULTILINE_COMMENT { \ - "(/\\*([^*]|\\*+[^*/])*\\*+/|/\\*([^*]|\\*+[^*/])*$|^([^/]|/+[^/*])*\\*/)", \ - COLOR_COMMENT, \ - true, /* multiline */ \ -} - -#define SYNTAX_SINGLE_LINE_COMMENT { \ - "(//.*)", \ - COLOR_COMMENT, \ -} - -#define SYNTAX_LITERAL { \ - "('(\\\\.|.)')|"B"(0x[0-9A-Fa-f]+|[0-9]+)"B, \ - COLOR_LITERAL, \ -} - -#define SYNTAX_STRING { \ - "(\"(\\\\.|[^\"])*\")", \ - COLOR_STRING, \ - false, /* multiline */ \ -} - -#define SYNTAX_CONSTANT { \ - B"[A-Z_][0-9A-Z_]+"B, \ - COLOR_CONSTANT, \ -} - -#define SYNTAX_BRACKET { \ - "(\\(|\\)|\\{|\\}|\\[|\\])", \ - COLOR_BRACKETS, \ -} - -#define SYNTAX_C_PREPROCESSOR { \ - "(^#[\\t ]*(define|include(_next)?|(un|ifn?)def|endif|el(if|se)|if|warning|error|pragma)?)", \ - COLOR_PREPROCESSOR, \ -} - -#define SYNTAX_SPACES { "\xC2\xB7", COLOR_SPACES } -#define SYNTAX_TABS { "\xE2\x96\xB6", COLOR_TABS } -#define SYNTAX_TABS_FILL { " ", COLOR_TABS } -#define SYNTAX_EOL { "\xE2\x8F\x8E", COLOR_EOL } -#define SYNTAX_EOF { "~", COLOR_EOF } - -/* these rules are applied top to bottom, first match wins. Therefore more 'greedy' - * rules such as for comments should be the first entries. - * - * The array of syntax definition must be terminated with an empty element. - */ -static Syntax syntaxes[] = {{ - .name = "c", - .file = "\\.(c(pp|xx)?|h(pp|xx)?|cc)$", - .settings = (const char*[]){ - "set number", - "set autoindent", - "set show spaces=0 tabs=1 newlines=1", - NULL - }, - .styles = styles, - .symbols = { - SYNTAX_SPACES, - SYNTAX_TABS, - SYNTAX_TABS_FILL, - SYNTAX_EOL, - SYNTAX_EOF, - }, - .rules = { - SYNTAX_MULTILINE_COMMENT, - SYNTAX_SINGLE_LINE_COMMENT, - SYNTAX_LITERAL, - SYNTAX_STRING, - SYNTAX_CONSTANT, - SYNTAX_BRACKET, - { - "<[a-zA-Z0-9\\.\\-_/]+\\.(c(pp|xx)?|h(pp|xx)?|cc)>", - COLOR_STRING, - }, - SYNTAX_C_PREPROCESSOR, - { - B"(for|if|while|do|else|case|default|switch|try|throw|catch|operator|new|delete)"B, - COLOR_KEYWORD, - },{ - B"(float|double|bool|char|int|short|long|sizeof|enum|void|static|const|struct|union|" - "typedef|extern|(un)?signed|inline|((s?size)|((u_?)?int(8|16|32|64|ptr)))_t|class|" - "namespace|template|public|protected|private|typename|this|friend|virtual|using|" - "mutable|volatile|register|explicit)"B, - COLOR_DATATYPE, - },{ - B"(goto|continue|break|return)"B, - COLOR_CONTROL, - }} -},{ - .name = "sh", - .file = "\\.sh$", - .styles = styles, - .rules = {{ - "#.*$", - COLOR_COMMENT, - }, - SYNTAX_STRING, - { - "^[0-9A-Z_]+\\(\\)", - COLOR_CONSTANT, - },{ - "\\$[?!@#$?*-]", - COLOR_VARIABLE, - },{ - "\\$\\{[A-Za-z_][0-9A-Za-z_]+\\}", - COLOR_VARIABLE, - },{ - "\\$[A-Za-z_][0-9A-Za-z_]+", - COLOR_VARIABLE, - },{ - B"(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)"B, - COLOR_KEYWORD, - },{ - "(\\{|\\}|\\(|\\)|\\;|\\]|\\[|`|\\\\|\\$|<|>|!|=|&|\\|)", - COLOR_BRACKETS, - }} -},{ - .name = "makefile", - .file = "(Makefile[^/]*|\\.mk)$", - .styles = styles, - .rules = {{ - "#.*$", - COLOR_COMMENT, - },{ - "\\$+[{(][a-zA-Z0-9_-]+[})]", - COLOR_VARIABLE, - },{ - B"(if|ifeq|else|endif)"B, - COLOR_CONTROL, - },{ - "^[^ ]+:", - COLOR_TARGET, - },{ - "[:(+?=)]", - COLOR_BRACKETS, - }} -},{ - .name = "man", - .file = "\\.[1-9]x?$", - .styles = styles, - .rules = {{ - "\\.(BR?|I[PR]?).*$", - COLOR_SYNTAX0, - },{ - "\\.(S|T)H.*$", - COLOR_SYNTAX2, - },{ - "\\.(br|DS|RS|RE|PD)", - COLOR_SYNTAX3, - },{ - "(\\.(S|T)H|\\.TP)", - COLOR_SYNTAX4, - },{ - "\\.(BR?|I[PR]?|PP)", - COLOR_SYNTAX5, - },{ - "\\\\f[BIPR]", - COLOR_SYNTAX6, - }} -},{ - .name = "vala", - .file = "\\.(vapi|vala)$", - .styles = styles, - .rules = { - SYNTAX_MULTILINE_COMMENT, - SYNTAX_SINGLE_LINE_COMMENT, - SYNTAX_LITERAL, - SYNTAX_STRING, - SYNTAX_CONSTANT, - SYNTAX_BRACKET, - { - B"(for|if|while|do|else|case|default|switch|get|set|value|out|ref|enum)"B, - COLOR_KEYWORD, - },{ - B"(uint|uint8|uint16|uint32|uint64|bool|byte|ssize_t|size_t|char|double|string|float|int|long|short|this|base|transient|void|true|false|null|unowned|owned)"B, - COLOR_DATATYPE, - },{ - B"(try|catch|throw|finally|continue|break|return|new|sizeof|signal|delegate)"B, - COLOR_CONTROL, - },{ - B"(abstract|class|final|implements|import|instanceof|interface|using|private|public|static|strictfp|super|throws)"B, - COLOR_KEYWORD2, - }} -},{ - .name = "java", - .file = "\\.java$", - .styles = styles, - .rules = { - SYNTAX_MULTILINE_COMMENT, - SYNTAX_SINGLE_LINE_COMMENT, - SYNTAX_LITERAL, - SYNTAX_STRING, - SYNTAX_CONSTANT, - SYNTAX_BRACKET, - { - B"(for|if|while|do|else|case|default|switch)"B, - COLOR_KEYWORD, - },{ - B"(boolean|byte|char|double|float|int|long|short|transient|void|true|false|null)"B, - COLOR_DATATYPE, - },{ - B"(try|catch|throw|finally|continue|break|return|new)"B, - COLOR_CONTROL, - },{ - B"(abstract|class|extends|final|implements|import|instanceof|interface|native|package|private|protected|public|static|strictfp|this|super|synchronized|throws|volatile)"B, - COLOR_KEYWORD2, - }} -},{ - .name = "javascript", - .file = "\\.(js|json)$", - .styles = styles, - .rules = { - SYNTAX_SINGLE_LINE_COMMENT, - SYNTAX_LITERAL, - SYNTAX_STRING, - SYNTAX_BRACKET, - { - B"(true|false|null|undefined)"B, - COLOR_DATATYPE, - },{ - B"(NaN|Infinity)"B, - COLOR_LITERAL, - },{ - "(\"(\\\\.|[^\"])*\"|\'(\\\\.|[^\'])*\')", - COLOR_STRING, - },{ - B"(for|if|while|do|in|else|case|default|switch|try|throw|catch|operator|new|delete)"B, - COLOR_KEYWORD, - },{ - B"(continue|break|return)"B, - COLOR_CONTROL, - },{ - B"(case|class|const|debugger|default|enum|export|extends|finally|function|implements|import|instanceof|let|this|typeof|var|with|yield)"B, - COLOR_KEYWORD2, - }} -},{ - .name = "lua", - .file = "\\.lua$", - .settings = (const char*[]){ - "set number", - "set autoindent", - NULL - }, - .styles = styles, - .rules = {{ - "--\\[(=*)\\[([^]]*)\\](=*)\\]", - COLOR_COMMENT, - true, - },{ - "--.*$", - COLOR_COMMENT, - },{ - "(\\[(=*)\\[([^]]*)\\](=*)\\]|^([^][]*)\\](=*)\\])", - COLOR_STRING, - true, - }, - SYNTAX_STRING, - { - B"([0-9]*\\.)?[0-9]+([eE]([\\+-])?[0-9]+)?"B, - COLOR_LITERAL, - },{ - B"0x[0-9a-fA-F]+"B, - COLOR_LITERAL, - },{ - B"(false|nil|true)"B, - COLOR_CONSTANT, - },{ - "(\\.\\.\\.)", - COLOR_CONSTANT, - },{ - B"(break|do|else|elseif|end|for|function|if|in|local|repeat|return|then|until|while)"B, - COLOR_KEYWORD, - },{ - B"(and|not|or)"B, - COLOR_OPERATOR, - },{ - "(\\+|-|\\*|/|%|\\^|#|[=~<>]=|<|>|\\.\\.)", - COLOR_OPERATOR, - }, - SYNTAX_BRACKET, - } -},{ - .name = "ruby", - .file = "\\.rb$", - .styles = styles, - .rules = {{ - "(#[^{].*$|#$)", - COLOR_COMMENT, - },{ - "(\\$|@|@@)?"B"[A-Z]+[0-9A-Z_a-z]*", - COLOR_VARIABLE, - },{ - B"(__FILE__|__LINE__|BEGIN|END|alias|and|begin|break|case|class|def|defined\?|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)"B, - COLOR_KEYWORD, - },{ - "([ ]|^):[0-9A-Z_]+"B, - COLOR_SYNTAX2, - },{ - "(/([^/]|(\\/))*/[iomx]*|%r\\{([^}]|(\\}))*\\}[iomx]*)", - COLOR_SYNTAX3, - },{ - "(`[^`]*`|%x\\{[^}]*\\})", - COLOR_SYNTAX4, - },{ - "(\"([^\"]|(\\\\\"))*\"|%[QW]?\\{[^}]*\\}|%[QW]?\\([^)]*\\)|%[QW]?<[^>]*>|%[QW]?\\[[^]]*\\]|%[QW]?\\$[^$]*\\$|%[QW]?\\^[^^]*\\^|%[QW]?![^!]*!|\'([^\']|(\\\\\'))*\'|%[qw]\\{[^}]*\\}|%[qw]\\([^)]*\\)|%[qw]<[^>]*>|%[qw]\\[[^]]*\\]|%[qw]\\$[^$]*\\$|%[qw]\\^[^^]*\\^|%[qw]![^!]*!)", - COLOR_SYNTAX5, - },{ - "#\\{[^}]*\\}", - COLOR_SYNTAX6, - }} -},{ - .name = "python", - .file = "\\.py$", - .styles = styles, - .rules = {{ - "(#.*$|#$)", - COLOR_COMMENT, - },{ - "(\"\"\".*\"\"\")", - COLOR_COMMENT, - true, /* multiline */ - },{ - B"(and|class|def|not|or|return|yield|is)"B, - COLOR_KEYWORD2, - },{ - B"(from|import|as)"B, - COLOR_KEYWORD, - },{ - B"(if|elif|else|while|for|in|try|with|except|in|break|continue|finally)"B, - COLOR_CONTROL, - },{ - B"(int|str|float|unicode|int|bool|chr|type|list|dict|tuple)", - COLOR_DATATYPE, - },{ - "(True|False|None)", - COLOR_LITERAL, - },{ - B"[0-9]+\\.[0-9]+([eE][-+]?[0-9]+)?"B, - COLOR_LITERAL, - },{ - B"[0-9]+"B"|"B"0[xX][0-9a-fA-F]+"B"|"B"0[oO][0-7]+"B, - COLOR_LITERAL, - },{ - "(\"(\\\\.|[^\"])*\"|\'(\\\\.|[^\'])*\')", - COLOR_STRING, - false, /* multiline */ - },{ - "(__init__|__str__|__unicode__|__gt__|__lt__|__eq__|__enter__|__exit__|__next__|__getattr__|__getitem__|__setitem__|__call__|__contains__|__iter__|__bool__|__all__|__name__)", - COLOR_SYNTAX2, - }} -},{ - .name = "php", - .file = "\\.php$", - .styles = styles, - .rules = { - SYNTAX_MULTILINE_COMMENT, - SYNTAX_SINGLE_LINE_COMMENT, - SYNTAX_BRACKET, - { - "(#.*$|#$)", - COLOR_COMMENT, - },{ - "(\"\"\".*\"\"\")", - COLOR_COMMENT, - true, /* multiline */ - },{ - B"(class|interface|extends|implements|new|__construct|__destruct|use|namespace|return)"B, - COLOR_KEYWORD2, - },{ - B"(public|private|protected|const|parent|function|->)"B, - COLOR_KEYWORD, - },{ - B"(if|else|while|do|for|foreach|in|try|catch|finally|switch|case|default|break|continue|as|=>)"B, - COLOR_CONTROL, - },{ - B"(array|true|false|null)", - COLOR_DATATYPE, - },{ - B"[0-9]+\\.[0-9]+([eE][-+]?[0-9]+)?"B, - COLOR_LITERAL, - },{ - B"[0-9]+"B"|"B"0[xX][0-9a-fA-F]+"B"|"B"0[oO][0-7]+"B, - COLOR_LITERAL, - },{ - "\\$[a-zA-Z0-9_\\-]+", - COLOR_VARIABLE, - },{ - "(\"(\\\\.|[^\"])*\"|\'(\\\\.|[^\'])*\')", - COLOR_STRING, - false, /* multiline */ - },{ - "(php|echo|print|var_dump|print_r)", - COLOR_SYNTAX2, - }} -},{ - .name = "haskell", - .file = "\\.hs$", - .styles = styles, - .rules = {{ - "\\{-#.*#-\\}", - COLOR_PRAGMA, - },{ - "---*([^-!#$%&\\*\\+./<=>\?@\\^|~].*)?$", - COLOR_COMMENT, - }, { - // These are allowed to be nested, but we can't express that - // with regular expressions - "\\{-.*-\\}", - COLOR_COMMENT, - true - }, - SYNTAX_STRING, - SYNTAX_C_PREPROCESSOR, - { - // as and hiding are only keywords when part of an import, but - // I don't want to highlight the whole import line. - // capture group coloring or similar would be nice - "(^import( qualified)?)|"B"(as|hiding|infix[lr]?)"B, - COLOR_KEYWORD2, - },{ - B"(module|class|data|deriving|instance|default|where|type|newtype)"B, - COLOR_KEYWORD, - },{ - B"(do|case|of|let|in|if|then|else)"B, - COLOR_CONTROL, - },{ - "('(\\\\.|.)')", - COLOR_LITERAL, - },{ - B"[0-9]+\\.[0-9]+([eE][-+]?[0-9]+)?"B, - COLOR_LITERAL, - },{ - B"[0-9]+"B"|"B"0[xX][0-9a-fA-F]+"B"|"B"0[oO][0-7]+"B, - COLOR_LITERAL, - },{ - "("B"[A-Z][a-zA-Z0-9_']*\\.)*"B"[a-zA-Z][a-zA-Z0-9_']*"B, - COLOR_NOHILIT, - },{ - "("B"[A-Z][a-zA-Z0-9_']*\\.)?[-!#$%&\\*\\+/<=>\\?@\\\\^|~:.][-!#$%&\\*\\+/<=>\\?@\\\\^|~:.]*", - COLOR_OPERATOR, - },{ - "`("B"[A-Z][a-zA-Z0-9_']*\\.)?[a-z][a-zA-Z0-9_']*`", - COLOR_OPERATOR, - },{ - "\\(|\\)|\\[|\\]|,|;|_|\\{|\\}", - COLOR_BRACKETS, - }} -},{ - .name = "markdown", - .file = "\\.(md|mdwn)$", - .styles = styles, - .rules = {{ - "(^#{1,6}.*$)", //titles - COLOR_SYNTAX5, - },{ - "((\\* *){3,}|(_ *){3,}|(- *){3,})", // horizontal rules - COLOR_SYNTAX2, - },{ - "(\\*\\*.*\\*\\*)|(__.*__)", // super-bolds - COLOR_SYNTAX4, - },{ - "(\\*.*\\*)|(_.*_)", // bolds - COLOR_SYNTAX3, - },{ - "(\\[.*\\]\\(.*\\))", //links - COLOR_SYNTAX6, - },{ - "(^ *([-\\*\\+]|[0-9]+\\.))", //lists - COLOR_SYNTAX2, - },{ - "(^( {4,}|\t+).*$)", // code blocks - COLOR_SYNTAX7, - },{ - "(`+.*`+)", // inline code - COLOR_SYNTAX7, - },{ - "(^>+.*)", // quotes - COLOR_SYNTAX7, - }} -},{ - .name = "ledger", - .file = "\\.(journal|ledger)$", - .styles = styles, - .rules = { - { /* comment */ - "^[;#].*", - COLOR_COMMENT, - },{ /* value tag */ - "( |\t|^ )*; :([^ ][^:]*:)+[ \\t]*$", - COLOR_DATATYPE, - },{ /* typed tag */ - "( |\t|^ )*; [^:]+::.*", - COLOR_DATATYPE, - },{ /* tag */ - "( |\t|^ )*; [^:]+:.*", - COLOR_TYPE, - },{ /* metadata */ - "( |\t|^ )*;.*", - COLOR_CONSTANT, - },{ /* date */ - "^[0-9][^ \t]+", - COLOR_LITERAL, - },{ /* account */ - "^[ \t]+[a-zA-Z:'!*()%&]+", - COLOR_IDENTIFIER, - },{ /* amount */ - "( |\t)[^;]*", - COLOR_LITERAL, - },{ /* automated transaction */ - "^[=~].*", - COLOR_TYPE, - },{ /* directives */ - "^[!@]?(account|alias|assert|bucket|capture|check|comment|commodity|define|end|fixed|endfixed|include|payee|apply|tag|test|year|[AYNDCIiOobh])"B".*", - COLOR_DATATYPE, - }} -},{ - .name = "apl", - .file = "\\.apl$", - .settings = (const char*[]){ - "set number", - NULL - }, - .styles = styles, - .rules = {{ - "(⍝|#).*$", - COLOR_COMMENT, - },{ - "('([^']|'')*')|(\"([^\"]|\"\")*\")", - COLOR_STRING, - },{ - "^ *(∇|⍫)", - COLOR_SYNTAX9, - },{ - "(⎕[a-zA-Z]*)|[⍞χ⍺⍶⍵⍹]", - COLOR_KEYWORD, - },{ - "[∆⍙_a-zA-Z][∆⍙_¯a-zA-Z0-9]* *:", - COLOR_SYNTAX2, - },{ - "[∆⍙_a-zA-Z][∆⍙_¯a-zA-Z0-9]*", - COLOR_IDENTIFIER, - },{ - "¯?(([0-9]+(\\.[0-9]+)?)|\\.[0-9]+)([eE]¯?[0-9]+)?([jJ]¯?(([0-9]+(\\.[0-9]+)?)|\\.[0-9]+)([eE]¯?[0-9]+)?)?", - COLOR_CONSTANT, - },{ - "[][(){}]", - COLOR_BRACKETS, - },{ - "[←→◊]", - COLOR_SYNTAX3, - }} -},{ - /* empty last element, array terminator */ -}}; diff --git a/main.c b/main.c index 6389c344f..fc3877aec 100644 --- a/main.c +++ b/main.c @@ -1584,9 +1584,6 @@ int main(int argc, char *argv[]) { vis_die(vis, "Could not load default bindings\n"); } - if (!vis_syntax_load(vis, syntaxes)) - vis_die(vis, "Could not load syntax highlighting definitions\n"); - /* install signal handlers etc. */ struct sigaction sa; memset(&sa, 0, sizeof sa); diff --git a/syntax.h b/syntax.h index 8ce623eb4..35be0249b 100644 --- a/syntax.h +++ b/syntax.h @@ -1,15 +1,6 @@ #ifndef SYNTAX_H #define SYNTAX_H -#include - -typedef struct { - char *rule; /* regex to search for */ - int style; /* settings to apply in case of a match */ - bool multiline; /* whether . should match new lines */ - regex_t regex; /* compiled form of the above rule */ -} SyntaxRule; - typedef struct { char *symbol; int style; @@ -24,15 +15,4 @@ enum { SYNTAX_SYMBOL_LAST, }; -typedef struct Syntax Syntax; -struct Syntax { /* a syntax definition */ - char *name; /* syntax name */ - char *file; /* apply to files matching this regex */ - regex_t file_regex; /* compiled file name regex */ - const char **settings;/* settings associated with this file type */ - const char **styles; /* settings associated with this file type */ - SyntaxSymbol symbols[SYNTAX_SYMBOL_LAST]; /* symbols for white space handling */ - SyntaxRule rules[24]; /* all rules for this file type */ -}; - #endif diff --git a/view.c b/view.c index 0491c7842..2f5aa47ab 100644 --- a/view.c +++ b/view.c @@ -67,7 +67,6 @@ struct View { Cursor *cursor; /* main cursor, always placed within the visible viewport */ Line *line; /* used while drawing view content, line where next char will be drawn */ int col; /* used while drawing view content, column where next char will be drawn */ - Syntax *syntax; /* syntax highlighting definitions for this view or NULL */ const SyntaxSymbol *symbols[SYNTAX_SYMBOL_LAST]; /* symbols to use for white spaces etc */ int tabwidth; /* how many spaces should be used to display a tab character */ Cursor *cursors; /* all cursors currently active */ @@ -346,11 +345,6 @@ void view_draw(View *view) { text[rem] = '\0'; /* current position into buffer from which to interpret a character */ char *cur = text; - /* syntax definition to use */ - Syntax *syntax = view->syntax; - /* matched tokens for each syntax rule */ - regmatch_t match[syntax ? LENGTH(syntax->rules) : 1][1], *matched = NULL; - memset(match, 0, sizeof match); /* default and current curses attributes to use */ int default_attrs = 0, attrs = default_attrs; /* start from known multibyte state */ @@ -362,52 +356,6 @@ void view_draw(View *view) { wchar_t wchar; Cell cell; memset(&cell, 0, sizeof cell); - - if (syntax) { - if (matched && cur >= text + matched->rm_eo) { - /* end of current match */ - matched = NULL; - attrs = default_attrs; - for (int i = 0; i < LENGTH(syntax->rules); i++) { - if (match[i][0].rm_so == -1) - continue; /* no match on whole text */ - /* reset matches which overlap with matched */ - if (text + match[i][0].rm_so <= cur && cur < text + match[i][0].rm_eo) { - match[i][0].rm_so = 0; - match[i][0].rm_eo = 0; - } - } - } - - if (!matched) { - size_t off = cur - text; /* number of already processed bytes */ - for (int i = 0; i < LENGTH(syntax->rules); i++) { - SyntaxRule *rule = &syntax->rules[i]; - if (!rule->rule) - break; - if (match[i][0].rm_so == -1) - continue; /* no match on whole text */ - if (off >= (size_t)match[i][0].rm_eo) { - /* past match, continue search from current position */ - if (regexec(&rule->regex, cur, 1, match[i], 0) || - match[i][0].rm_so == match[i][0].rm_eo) { - match[i][0].rm_so = -1; - match[i][0].rm_eo = -1; - continue; - } - match[i][0].rm_so += off; - match[i][0].rm_eo += off; - } - - if (text + match[i][0].rm_so <= cur && cur < text + match[i][0].rm_eo) { - /* within matched expression */ - matched = &match[i][0]; - attrs = rule->style; - break; /* first match views */ - } - } - } - } size_t len = mbrtowc(&wchar, cur, rem, &mbstate); if (len == (size_t)-1 && errno == EILSEQ) { @@ -504,7 +452,7 @@ void view_draw(View *view) { size_t pos = view_cursors_pos(c); if (view_coord_get(view, pos, &c->line, &c->row, &c->col)) { c->line->cells[c->col].cursor = true; - if (view->ui && view->syntax) { + if (view->ui) { Line *line_match; int col_match; size_t pos_match = text_bracket_match_except(view->text, pos, "<>"); if (pos != pos_match && view_coord_get(view, pos_match, &line_match, NULL, &col_match)) { @@ -834,23 +782,12 @@ void view_scroll_to(View *view, size_t pos) { view_cursors_scroll_to(view->cursor, pos); } -void view_syntax_set(View *view, Syntax *syntax) { - view->syntax = syntax; - for (int i = 0; i < LENGTH(view->symbols); i++) { - if (syntax && syntax->symbols[i].symbol) - view->symbols[i] = &syntax->symbols[i]; - else - view->symbols[i] = &symbols_none[i]; - } - if (syntax) { - for (const char **style = syntax->styles; *style; style++) { - view->ui->syntax_style(view->ui, style - syntax->styles, *style); - } - } +bool view_syntax_set(View *view, const char *name) { + return false; } -Syntax *view_syntax_get(View *view) { - return view->syntax; +const char *view_syntax_get(View *view) { + return NULL; } void view_options_set(View *view, enum UiOption options) { @@ -862,14 +799,8 @@ void view_options_set(View *view, enum UiOption options) { [SYNTAX_SYMBOL_EOF] = UI_OPTION_SYMBOL_EOF, }; for (int i = 0; i < LENGTH(mapping); i++) { - if (options & mapping[i]) { - if (view->syntax && view->syntax->symbols[i].symbol) - view->symbols[i] = &view->syntax->symbols[i]; - else - view->symbols[i] = &symbols_default[i]; - } else { - view->symbols[i] = &symbols_none[i]; - } + view->symbols[i] = (options & mapping[i]) ? &symbols_default[i] : + &symbols_none[i]; } if (view->ui) view->ui->options_set(view->ui, options); diff --git a/view.h b/view.h index 70b64d6ec..a9f7ec995 100644 --- a/view.h +++ b/view.h @@ -92,8 +92,8 @@ Filerange view_viewport_get(View*); bool view_viewport_up(View *view, int n); bool view_viewport_down(View *view, int n); /* associate a set of syntax highlighting rules to this window. */ -void view_syntax_set(View*, Syntax*); -Syntax *view_syntax_get(View*); +bool view_syntax_set(View*, const char *name); +const char *view_syntax_get(View*); void view_options_set(View*, enum UiOption options); enum UiOption view_options_get(View*); diff --git a/vis-cmds.c b/vis-cmds.c index a25c5e928..8b4e80536 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -246,25 +246,20 @@ static bool cmd_set(Vis *vis, Filerange *range, enum CmdOpt cmdopt, const char * break; case OPTION_SYNTAX: if (!argv[2]) { - Syntax *syntax = view_syntax_get(vis->win->view); + const char *syntax = view_syntax_get(vis->win->view); if (syntax) - vis_info_show(vis, "Syntax definition in use: `%s'", syntax->name); + vis_info_show(vis, "Syntax definition in use: `%s'", syntax); else vis_info_show(vis, "No syntax definition in use"); return true; } - for (Syntax *syntax = vis->syntaxes; syntax && syntax->name; syntax++) { - if (!strcasecmp(syntax->name, argv[2])) { - view_syntax_set(vis->win->view, syntax); - return true; - } - } - if (parse_bool(argv[2], &arg.b) && !arg.b) - view_syntax_set(vis->win->view, NULL); - else + return view_syntax_set(vis->win->view, NULL); + if (!view_syntax_set(vis->win->view, argv[2])) { vis_info_show(vis, "Unknown syntax definition: `%s'", argv[2]); + return false; + } break; case OPTION_SHOW: if (!argv[2]) { diff --git a/vis-core.h b/vis-core.h index 052222ee4..ceb131113 100644 --- a/vis-core.h +++ b/vis-core.h @@ -128,7 +128,6 @@ struct Vis { File *files; /* all files currently managed by this editor instance */ Win *windows; /* all windows currently managed by this editor instance */ Win *win; /* currently active/focused window */ - Syntax *syntaxes; /* NULL terminated array of syntax definitions */ Register registers[VIS_REG_INVALID]; /* registers used for yank and put */ Macro macros[VIS_MACRO_INVALID]; /* recorded macros */ Macro *recording, *last_recording; /* currently (if non NULL) and least recently recorded macro */ diff --git a/vis-motions.c b/vis-motions.c index bbd509e4c..754b132e6 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -1,3 +1,4 @@ +#include #include "vis-core.h" #include "text-motions.h" #include "text-objects.h" diff --git a/vis.c b/vis.c index b9d664f44..377b6a9a8 100644 --- a/vis.c +++ b/vis.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -124,18 +125,6 @@ void vis_window_name(Win *win, const char *filename) { free((char*)file->name); file->name = filename ? strdup(filename) : NULL; } - - if (filename) { - Vis *vis = win->vis; - for (Syntax *syn = vis->syntaxes; syn && syn->name; syn++) { - if (!regexec(&syn->file_regex, filename, 0, NULL, 0)) { - view_syntax_set(win->view, syn); - for (const char **opt = syn->settings; opt && *opt; opt++) - vis_cmd(vis, *opt); - break; - } - } - } } static void windows_invalidate(Vis *vis, size_t start, size_t end) { @@ -245,42 +234,6 @@ void vis_window_prev(Vis *vis) { vis->ui->window_focus(vis->win->ui); } -bool vis_syntax_load(Vis *vis, Syntax *syntaxes) { - bool success = true; - vis->syntaxes = syntaxes; - - for (Syntax *syn = syntaxes; syn && syn->name; syn++) { - if (regcomp(&syn->file_regex, syn->file, REG_EXTENDED|REG_NOSUB|REG_ICASE|REG_NEWLINE)) - success = false; - for (int j = 0; j < LENGTH(syn->rules); j++) { - SyntaxRule *rule = &syn->rules[j]; - if (!rule->rule) - break; - int cflags = REG_EXTENDED; - if (!rule->multiline) - cflags |= REG_NEWLINE; - if (regcomp(&rule->regex, rule->rule, cflags)) - success = false; - } - } - - return success; -} - -void vis_syntax_unload(Vis *vis) { - for (Syntax *syn = vis->syntaxes; syn && syn->name; syn++) { - regfree(&syn->file_regex); - for (int j = 0; j < LENGTH(syn->rules); j++) { - SyntaxRule *rule = &syn->rules[j]; - if (!rule->rule) - break; - regfree(&rule->regex); - } - } - - vis->syntaxes = NULL; -} - void vis_draw(Vis *vis) { vis->ui->draw(vis->ui); } @@ -374,7 +327,6 @@ void vis_free(Vis *vis) { register_release(&vis->registers[i]); for (int i = 0; i < LENGTH(vis->macros); i++) macro_release(&vis->macros[i]); - vis_syntax_unload(vis); vis->ui->free(vis->ui); map_free(vis->cmds); map_free(vis->options); diff --git a/vis.h b/vis.h index 2834fbd04..058113820 100644 --- a/vis.h +++ b/vis.h @@ -51,14 +51,6 @@ void vis_update(Vis*); /* temporarily supsend the editor process, resumes upon receiving SIGCONT */ void vis_suspend(Vis*); -/* load a set of syntax highlighting definitions which will be associated - * to the underlying window based on the file type loaded. - * - * The parameter `syntaxes' has to point to a NULL terminated array. - */ -bool vis_syntax_load(Vis*, Syntax *syntaxes); -void vis_syntax_unload(Vis*); - /* creates a new window, and loads the given file. if filename is NULL * an unamed / empty buffer is created. If the given file is already opened * in another window, share the underlying text that is changes will be