From ea123bb012a8356053d24d6b709aeab527023ed1 Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Fri, 19 Jul 2024 18:45:06 +0200 Subject: [PATCH] Simplifications * use `cp_skip_blanks` in language colorizers * simplify signature matching for here documents --- lang/arm.c | 17 ++++++----------- lang/asm.c | 8 +++----- lang/ats.c | 6 ++---- lang/cobol.c | 5 ++--- lang/crystal.c | 26 ++++++++++---------------- lang/fortran.c | 5 ++--- lang/groovy.c | 3 +-- lang/haskell.c | 3 +-- lang/icon.c | 5 +---- lang/inifile.c | 6 ++---- lang/jai.c | 12 ++---------- lang/makemode.c | 4 ++-- lang/ocaml.c | 6 ++---- lang/perl.c | 13 ++++--------- lang/python.c | 5 ++--- lang/rlang.c | 5 ++--- lang/ruby.c | 26 ++++++++++---------------- lang/rust.c | 15 ++++----------- lang/scad.c | 6 ++---- lang/script.c | 6 ++---- lang/vimscript.c | 6 ++---- lang/virgil.c | 3 +-- modes/fractal.c | 5 +---- modes/latex-mode.c | 8 ++------ modes/markdown.c | 3 +-- 25 files changed, 69 insertions(+), 138 deletions(-) diff --git a/lang/arm.c b/lang/arm.c index 7bc4ff7..b61e563 100644 --- a/lang/arm.c +++ b/lang/arm.c @@ -1,7 +1,7 @@ /* * Miscellaneous QEmacs modes for arm development related file formats * - * Copyright (c) 2014-2023 Charlie Gordon. + * Copyright (c) 2014-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -59,8 +59,7 @@ static void arm_asm_colorize_line(QEColorizeContext *cp, if (colstate & IN_ASM_TRAIL) goto comment; - for (; qe_isblank(str[i]); i++) - continue; + i = cp_skip_blanks(str, i, n); for (w = i; i < n;) { start = i; @@ -210,8 +209,7 @@ static void lst_colorize_line(QEColorizeContext *cp, int i, w, start, colstate = cp->colorize_state; char32_t c; - for (w = 0; qe_isblank(str[w]); w++) - continue; + w = cp_skip_blanks(str, 0, n); if (str[0] && str[1] == ':' && str[2] == '\\') { /* has full DOS/Windows pathname */ @@ -238,8 +236,7 @@ static void lst_colorize_line(QEColorizeContext *cp, i += 1; SET_COLOR(str, start, i, LST_STYLE_OFFSET); - for (; qe_isblank(str[i]); i++) - continue; + i = cp_skip_blanks(str, i, n); for (start = i; qe_isxdigit(str[i]); i++) continue; if (str[i] == ' ' && qe_isxdigit(str[i + 1])) { @@ -247,13 +244,11 @@ static void lst_colorize_line(QEColorizeContext *cp, continue; } SET_COLOR(str, start, i, LST_STYLE_DUMP); - for (; qe_isblank(str[i]); i++) - continue; + i = cp_skip_blanks(str, i, n); for (start = i; i < n && !qe_isblank(str[i]); i++) continue; SET_COLOR(str, start, i, LST_STYLE_OPCODE); - for (; qe_isblank(str[i]); i++) - continue; + i = cp_skip_blanks(str, i, n); while (i < n) { start = i; c = str[i++]; diff --git a/lang/asm.c b/lang/asm.c index 830e386..de7b56d 100644 --- a/lang/asm.c +++ b/lang/asm.c @@ -1,7 +1,7 @@ /* * asm language mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -71,8 +71,7 @@ static void asm_colorize_line(QEColorizeContext *cp, if (colstate) goto in_comment; - for (; i < n && qe_isblank(str[i]); i++) - continue; + i = cp_skip_blanks(str, i, n); while (i < n) { start = i; @@ -122,8 +121,7 @@ static void asm_colorize_line(QEColorizeContext *cp, if (++wn == 1) { if (strequal(keyword, "comment") && n > i) { SET_COLOR(str, start, i, ASM_STYLE_PREPROCESS); - for (; i < n && qe_isblank(str[i]); i++) - continue; + i = cp_skip_blanks(str, i, n); start = i; colstate = str[i++]; /* end of comment character */ /* skip characters upto and including separator */ diff --git a/lang/ats.c b/lang/ats.c index 174da93..29ccb90 100644 --- a/lang/ats.c +++ b/lang/ats.c @@ -1,7 +1,7 @@ /* * ATS (Applied Type System) mode for QEmacs. * - * Copyright (c) 2016-2023 Charlie Gordon. + * Copyright (c) 2016-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -199,9 +199,7 @@ static void ats_colorize_line(QEColorizeContext *cp, if (strfind(syn->types, keyword)) { style = ATS_STYLE_TYPE; } else { - k = i; - if (qe_isblank(str[k])) - k++; + k = cp_skip_blanks(str, i, n); if (str[k] == '(' && str[k + 1] != '*') style = ATS_STYLE_FUNCTION; else diff --git a/lang/cobol.c b/lang/cobol.c index 28c3735..83c7d13 100644 --- a/lang/cobol.c +++ b/lang/cobol.c @@ -1,7 +1,7 @@ /* * Cobol language mode for QEmacs. * - * Copyright (c) 2015-2023 Charlie Gordon. + * Copyright (c) 2015-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -93,8 +93,7 @@ static void cobol_colorize_line(QEColorizeContext *cp, char32_t c; int state = cp->colorize_state; - for (; i < n && qe_isblank(str[i]); i++) - continue; + i = cp_skip_blanks(str, i, n); indent = i; if (str[i] == '*' && str[i + 1] == '>') diff --git a/lang/crystal.c b/lang/crystal.c index 968bc85..c6afad0 100644 --- a/lang/crystal.c +++ b/lang/crystal.c @@ -1,7 +1,7 @@ /* * Crystal language mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -104,34 +104,30 @@ static int crystal_get_name(char *buf, int size, const char32_t *str) { static void crystal_colorize_line(QEColorizeContext *cp, char32_t *str, int n, ModeDef *syn) { - int i = 0, j, start = i, style = 0, indent, sig; + int i = 0, j, start = i, style = 0, indent; char32_t c; static char32_t sep, sep0; /* XXX: ugly patch */ static int level; /* XXX: ugly patch */ int state = cp->colorize_state; char kbuf[64]; - for (indent = 0; qe_isblank(str[indent]); indent++) - continue; + indent = cp_skip_blanks(str, 0, n); if (state & IN_CRYSTAL_HEREDOC) { if (state & IN_CRYSTAL_HD_INDENT) { - while (qe_isblank(str[i])) - i++; + i = indent; } - sig = 0; if (qe_isalpha_(str[i])) { - sig = str[i++] % 61; + int sig = str[i++] % 61; for (; qe_isalnum_(str[i]); i++) { sig = ((sig << 6) + str[i]) % 61; } + i = cp_skip_blanks(str, i, n); + if (i == n && (state & IN_CRYSTAL_HD_SIG) == (sig & IN_CRYSTAL_HD_SIG)) + state &= ~(IN_CRYSTAL_HEREDOC | IN_CRYSTAL_HD_INDENT | IN_CRYSTAL_HD_SIG); } - for (; qe_isblank(str[i]); i++) - continue; i = n; SET_COLOR(str, start, i, CRYSTAL_STYLE_HEREDOC); - if (i > 0 && i == n && (state & IN_CRYSTAL_HD_SIG) == (sig & IN_CRYSTAL_HD_SIG)) - state &= ~(IN_CRYSTAL_HEREDOC | IN_CRYSTAL_HD_INDENT | IN_CRYSTAL_HD_SIG); } else { if (state & IN_CRYSTAL_COMMENT) goto parse_c_comment; @@ -166,9 +162,7 @@ static void crystal_colorize_line(QEColorizeContext *cp, } } - while (i < n && qe_isblank(str[i])) - i++; - + i = cp_skip_blanks(str, i, n); indent = i; while (i < n) { @@ -359,7 +353,7 @@ static void crystal_colorize_line(QEColorizeContext *cp, * space. * XXX: should parse full here document syntax. */ - sig = 0; + int sig = 0; j = i + 1; if (str[j] == '-') { j++; diff --git a/lang/fortran.c b/lang/fortran.c index 3320ec8..90c7302 100644 --- a/lang/fortran.c +++ b/lang/fortran.c @@ -1,7 +1,7 @@ /* * Fortran language modes for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -66,8 +66,7 @@ static void fortran_colorize_line(QEColorizeContext *cp, char32_t c; int colstate = cp->colorize_state; - for (w = 0; qe_isblank(str[w]); w++) - continue; + w = cp_skip_blanks(str, 0, n); while (i < n) { start = i; diff --git a/lang/groovy.c b/lang/groovy.c index a36cc81..530b538 100644 --- a/lang/groovy.c +++ b/lang/groovy.c @@ -264,8 +264,7 @@ static void groovy_colorize_line(QEColorizeContext *cp, continue; case '~': - while (qe_isblank(str[i])) - i++; + i = cp_skip_blanks(str, i, n); if (str[i] == '/') { /* parse slashy string as regex */ sep = '/'; diff --git a/lang/haskell.c b/lang/haskell.c index 209c4e4..f7ba472 100644 --- a/lang/haskell.c +++ b/lang/haskell.c @@ -77,8 +77,7 @@ static void haskell_colorize_line(QEColorizeContext *cp, if (state & IN_HASKELL_STRING) { sep = '\"'; state = 0; - while (qe_isblank(str[i])) - i++; + i = cp_skip_blanks(str, i, n); if (str[i] == '\\') i++; goto parse_string; diff --git a/lang/icon.c b/lang/icon.c index b32aa8f..8276194 100644 --- a/lang/icon.c +++ b/lang/icon.c @@ -65,11 +65,8 @@ static void icon_colorize_line(QEColorizeContext *cp, char32_t c, delim; char kbuf[64]; - for (i = 0; qe_isblank(str[i]); i++) - continue; - + i = cp_skip_blanks(str, 0, n); state = cp->colorize_state; - indent = i; start = i; c = 0; diff --git a/lang/inifile.c b/lang/inifile.c index 41c1a5c..34c8ad6 100644 --- a/lang/inifile.c +++ b/lang/inifile.c @@ -1,7 +1,7 @@ /* * ini file mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -42,9 +42,7 @@ static void ini_colorize_line(QEColorizeContext *cp, int i = 0, start, style = 0, indent; char32_t c; - while (qe_isblank(str[i])) - i++; - + i = cp_skip_blanks(str, i, n); indent = i; while (i < n) { diff --git a/lang/jai.c b/lang/jai.c index 506cd77..e9cc268 100644 --- a/lang/jai.c +++ b/lang/jai.c @@ -65,7 +65,7 @@ enum { static void jai_colorize_line(QEColorizeContext *cp, char32_t *str, int n, ModeDef *syn) { - int i = 0, start = i, style = 0, i1, i2, level; + int i = 0, start = i, style = 0, i1, level; char32_t c = 0, delim; int state = cp->colorize_state; char kbuf[64]; @@ -191,25 +191,17 @@ static void jai_colorize_line(QEColorizeContext *cp, } if (qe_isalpha_(c)) { i += ustr_get_identifier(kbuf, countof(kbuf), c, str, i, n); - if (strfind(syn->keywords, kbuf)) { style = JAI_STYLE_KEYWORD; break; } - - i1 = i; - while (qe_isblank(str[i1])) - i1++; - i2 = i1; - while (qe_isblank(str[i2])) - i2++; - if ((start == 0 || str[start - 1] != '.') && !qe_findchar(".(:", str[i]) && strfind(syn->types, kbuf)) { style = JAI_STYLE_TYPE; break; } + i1 = cp_skip_blanks(str, i, n); if (str[i1] == '(') { /* function call */ /* XXX: different styles for call and definition */ diff --git a/lang/makemode.c b/lang/makemode.c index 63d3499..67f7115 100644 --- a/lang/makemode.c +++ b/lang/makemode.c @@ -1,7 +1,7 @@ /* * Makefile mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -232,7 +232,7 @@ static void cmake_colorize_line(QEColorizeContext *cp, if (strfind("if|else|endif|set|true|false|include", buf)) { SET_COLOR(str, start, i, CMAKE_STYLE_KEYWORD); } else - if (str[i] == '(' || (str[i] == ' ' && str[i+1] == '(')) { + if (check_fcall(str, i)) { SET_COLOR(str, start, i, CMAKE_STYLE_FUNCTION); } } diff --git a/lang/ocaml.c b/lang/ocaml.c index e52ee38..964b770 100644 --- a/lang/ocaml.c +++ b/lang/ocaml.c @@ -1,7 +1,7 @@ /* * ML/Ocaml language mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -223,9 +223,7 @@ static void ocaml_colorize_line(QEColorizeContext *cp, style = OCAML_STYLE_KEYWORD; } else { style = OCAML_STYLE_IDENTIFIER; - k = i; - if (qe_isblank(str[k])) - k++; + k = cp_skip_blanks(str, i, n); if (str[k] == '(' && str[k + 1] != '*') style = OCAML_STYLE_FUNCTION; } diff --git a/lang/perl.c b/lang/perl.c index 72e0c49..720fb99 100644 --- a/lang/perl.c +++ b/lang/perl.c @@ -144,10 +144,11 @@ static int perl_string(const char32_t *str, char32_t delim, int j, int n) { static void perl_colorize_line(QEColorizeContext *cp, char32_t *str, int n, ModeDef *syn) { - int i = 0, start = i, j, s1, s2, delim = 0; + int i = 0, start = i, j, s1, s2, delim = 0, indent; char32_t c, c1, c2; int colstate = cp->colorize_state; + indent = cp_skip_blanks(str, 0, n); if (colstate & (IN_PERL_STRING1 | IN_PERL_STRING2)) { delim = (colstate & IN_PERL_STRING1) ? '\'' : '\"'; i = perl_string(str, delim, start, n); @@ -237,9 +238,7 @@ static void perl_colorize_line(QEColorizeContext *cp, case '<': if (c1 == '<') { /* Should check for unary context */ - s1 = i + 1; - while (qe_isblank(str[s1])) - s1++; + s1 = cp_skip_blanks(str, i + 1, n); c2 = str[s1]; if (c2 == '"' || c2 == '\'' || c2 == '`') { s2 = perl_string(str, c2, ++s1, n); @@ -358,11 +357,7 @@ static void perl_colorize_line(QEColorizeContext *cp, } keyword: if (i - start == 6 && ustristart(str + start, "format", NULL)) { - for (s1 = 0; s1 < start; s1++) { - if (!qe_isblank(str[s1])) - break; - } - if (s1 == start) { + if (start == indent) { /* keyword is first on line */ colstate |= IN_PERL_FORMAT; } diff --git a/lang/python.c b/lang/python.c index 732b85c..6c72276 100644 --- a/lang/python.c +++ b/lang/python.c @@ -1,7 +1,7 @@ /* * Python language mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -288,8 +288,7 @@ static void python_colorize_line(QEColorizeContext *cp, break; } if (tag) { - for (i1 = i; i1 < n && qe_isblank(str[i1]); i1++) - continue; + i1 = cp_skip_blanks(str, i, n); if (qe_findchar(",=", str[i1])) { /* tag variable definition */ eb_add_tag(cp->b, cp->offset + start, kbuf); diff --git a/lang/rlang.c b/lang/rlang.c index e13fe29..4fbc400 100644 --- a/lang/rlang.c +++ b/lang/rlang.c @@ -1,7 +1,7 @@ /* * R language mode for QEmacs. * - * Copyright (c) 2015-2023 Charlie Gordon. + * Copyright (c) 2015-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -150,8 +150,6 @@ static void r_colorize_line(QEColorizeContext *cp, } } keyword[len] = '\0'; - for (j = i; qe_isblank(str[j]); j++) - continue; if (strfind(syn->keywords, keyword)) { if (strequal(keyword, "function")) funclevel = level + 1; @@ -166,6 +164,7 @@ static void r_colorize_line(QEColorizeContext *cp, style = R_STYLE_ARGDEF; break; } + j = cp_skip_blanks(str, i, n); if (str[j] == '=' && str[j + 1] != '=') { style = R_STYLE_ARGNAME; break; diff --git a/lang/ruby.c b/lang/ruby.c index 58f944f..715c652 100644 --- a/lang/ruby.c +++ b/lang/ruby.c @@ -1,7 +1,7 @@ /* * Ruby language mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -94,34 +94,30 @@ static int ruby_get_name(char *buf, int size, const char32_t *str) { static void ruby_colorize_line(QEColorizeContext *cp, char32_t *str, int n, ModeDef *syn) { - int i = 0, j, start = i, style = 0, indent, sig; + int i = 0, j, start = i, style = 0, indent; char32_t c; static char32_t sep, sep0; /* XXX: ugly patch */ static int level; /* XXX: ugly patch */ int state = cp->colorize_state; char kbuf[64]; - for (indent = 0; qe_isblank(str[indent]); indent++) - continue; + indent = cp_skip_blanks(str, 0, n); if (state & IN_RUBY_HEREDOC) { if (state & IN_RUBY_HD_INDENT) { - while (qe_isblank(str[i])) - i++; + i = indent; } - sig = 0; if (qe_isalpha_(str[i])) { - sig = str[i++] % 61; + int sig = str[i++] % 61; for (; qe_isalnum_(str[i]); i++) { sig = ((sig << 6) + str[i]) % 61; } + i = cp_skip_blanks(str, i, n); + if (i == n && (state & IN_RUBY_HD_SIG) == (sig & IN_RUBY_HD_SIG)) + state &= ~(IN_RUBY_HEREDOC | IN_RUBY_HD_INDENT | IN_RUBY_HD_SIG); } - for (; qe_isblank(str[i]); i++) - continue; i = n; SET_COLOR(str, start, i, RUBY_STYLE_HEREDOC); - if (i > 0 && i == n && (state & IN_RUBY_HD_SIG) == (sig & IN_RUBY_HD_SIG)) - state &= ~(IN_RUBY_HEREDOC | IN_RUBY_HD_INDENT | IN_RUBY_HD_SIG); } else { if (state & IN_RUBY_COMMENT) goto parse_c_comment; @@ -156,9 +152,7 @@ static void ruby_colorize_line(QEColorizeContext *cp, } } - while (i < n && qe_isblank(str[i])) - i++; - + i = cp_skip_blanks(str, i, n); indent = i; while (i < n) { @@ -349,7 +343,7 @@ static void ruby_colorize_line(QEColorizeContext *cp, * space. * XXX: should parse full here document syntax. */ - sig = 0; + int sig = 0; j = i + 1; if (str[j] == '-') { j++; diff --git a/lang/rust.c b/lang/rust.c index 1c17c42..dfc6f53 100644 --- a/lang/rust.c +++ b/lang/rust.c @@ -1,7 +1,7 @@ /* * Rust mode for QEmacs. * - * Copyright (c) 2015-2023 Charlie Gordon. + * Copyright (c) 2015-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -66,12 +66,11 @@ enum { static void rust_colorize_line(QEColorizeContext *cp, char32_t *str, int n, ModeDef *syn) { - int i = 0, start, i1, i2, indent, state, style, klen; + int i = 0, start, i1, indent, state, style, klen; char32_t c, delim; char kbuf[64]; - for (indent = 0; qe_isblank(str[indent]); indent++) - continue; + indent = cp_skip_blanks(str, 0, n); state = cp->colorize_state; @@ -238,19 +237,13 @@ static void rust_colorize_line(QEColorizeContext *cp, break; } - i1 = i; - while (qe_isblank(str[i1])) - i1++; - i2 = i1; - while (qe_isblank(str[i2])) - i2++; - if ((start == 0 || str[start - 1] != '.') && !qe_findchar(".(:", str[i]) && strfind(syn->types, kbuf)) { style = RUST_STYLE_TYPE; break; } + i1 = cp_skip_blanks(str, i, n); if (str[i1] == '(') { /* function call */ /* XXX: different styles for call and definition */ diff --git a/lang/scad.c b/lang/scad.c index 9bec8d8..68dc79f 100644 --- a/lang/scad.c +++ b/lang/scad.c @@ -1,7 +1,7 @@ /* * OpenSCAD language mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -163,9 +163,7 @@ static void scad_colorize_line(QEColorizeContext *cp, if (strfind(syn->types, keyword)) { style = SCAD_STYLE_TYPE; } else { - k = i; - if (qe_isblank(str[k])) - k++; + k = cp_skip_blanks(str, i, n); if ((level & 2) && str[k] == '=') { style = SCAD_STYLE_ARGNAME; } else diff --git a/lang/script.c b/lang/script.c index 0bd10e3..f14e587 100644 --- a/lang/script.c +++ b/lang/script.c @@ -1,7 +1,7 @@ /* * Shell script mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -100,9 +100,7 @@ static void shell_script_colorize_line(QEColorizeContext *cp, start_cmd: style = SHELL_SCRIPT_STYLE_COMMAND; - while (i < n && qe_isblank(str[i])) { - i++; - } + i = cp_skip_blanks(str, i, n); while (i < n) { start = i; diff --git a/lang/vimscript.c b/lang/vimscript.c index 5afc695..09ee436 100644 --- a/lang/vimscript.c +++ b/lang/vimscript.c @@ -1,7 +1,7 @@ /* * Vim script mode for QEmacs. * - * Copyright (c) 2000-2023 Charlie Gordon. + * Copyright (c) 2000-2024 Charlie Gordon. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -112,9 +112,7 @@ static void vim_colorize_line(QEColorizeContext *cp, int i = 0, j, start, state, comm, level, style; char32_t c; - while (qe_isblank(str[i])) { - i++; - } + i = cp_skip_blanks(str, i, n); if (str[i] == '\\') { i++; level = cp->colorize_state & 15; diff --git a/lang/virgil.c b/lang/virgil.c index 2cdb019..b135c5c 100644 --- a/lang/virgil.c +++ b/lang/virgil.c @@ -264,8 +264,7 @@ static void virgil_colorize_line(QEColorizeContext *cp, continue; case '~': - while (qe_isblank(str[i])) - i++; + i = cp_skip_blanks(str, i, n); if (str[i] == '/') { /* parse slashy string as regex */ sep = '/'; diff --git a/modes/fractal.c b/modes/fractal.c index a3bad39..54cc059 100644 --- a/modes/fractal.c +++ b/modes/fractal.c @@ -67,11 +67,8 @@ static void fractint_colorize_line(QEColorizeContext *cp, char32_t c, delim; char kbuf[64]; - for (indent = 0; qe_isblank(str[indent]); indent++) - continue; - + indent = cp_skip_blanks(str, 0, n); state = cp->colorize_state; - start = i; c = 0; style = FRACTINT_STYLE_DEFAULT; diff --git a/modes/latex-mode.c b/modes/latex-mode.c index c768f1d..f4f3e31 100644 --- a/modes/latex-mode.c +++ b/modes/latex-mode.c @@ -98,9 +98,7 @@ static void latex_colorize_line(QEColorizeContext *cp, } } SET_COLOR(str, start, i, LATEX_STYLE_FUNCTION); - while (qe_isblank(str[i])) { - i++; - } + i = cp_skip_blanks(str, i, n); while (str[i] == '{' || str[i] == '[') { if (str[i++] == '[') { /* handle [keyword] */ @@ -128,9 +126,7 @@ static void latex_colorize_line(QEColorizeContext *cp, if (str[i] == '}') i++; } - while (qe_isblank(str[i])) { - i++; - } + i = cp_skip_blanks(str, i, n); } break; case '%': diff --git a/modes/markdown.c b/modes/markdown.c index 9ca7c65..bd78657 100644 --- a/modes/markdown.c +++ b/modes/markdown.c @@ -262,8 +262,7 @@ static void mkd_colorize_line(QEColorizeContext *cp, int lang = (colstate & IN_MKD_LANG) >> MKD_LANG_SHIFT; colstate &= ~(IN_MKD_BLOCK | IN_MKD_LANG_STATE); - for (i = j + 3; qe_isblank(str[i]); i++) - continue; + i = cp_skip_blanks(str, j + 3, n); /* extract info-string */ for (len = 0; i < n && !qe_isblank(str[i]); i++) { if (len < countof(lang_name) - 1)