aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-11-09 13:05:34 +0100
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2025-11-09 13:05:34 +0100
commit6e9e09b7d23fcc300dc469c1f410e53d0a111bfa (patch)
tree8c02524cb967fabb103897f39ef01dce42fc65d0 /src
parentc80a29ba487e7767af0a4ee00d8e42c3c737283b (diff)
the SciTECO lexer now tries to avoid unnecessary restylings by styling from the current line as well
* This optimization is unnecessary for regular TECO scripts unless you write stupendously long lines. On the command line macro however, we were always restyling the entire command line with every insertion or rubout since the command line view uses single line mode by default. Even if you enable a multi-line command line with regular line breaks, it's unlikely that you would insert many line breaks except when inserting text into the buffer. * We will now during insertion into the command line view style from the beginning of the last regular command. * During rub out from the command line, we still won't have enough information about where the previous valid start state was, so we will frequently have to restyle the entire command line. This might be worked around by adding a cmdline-view-specific hack if it turns out to be relevant on very long command lines and slow computers.
Diffstat (limited to 'src')
-rw-r--r--src/lexer.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 2f43b76..840596a 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -212,22 +212,35 @@ teco_lexer_style(teco_view_t *view, gsize end)
gsize start = teco_view_ssm(view, SCI_GETENDSTYLED, 0, 0);
guint start_line = teco_view_ssm(view, SCI_LINEFROMPOSITION, start, 0);
- gint start_col = 0;
/*
* The line state stores the laster character (column) in bytes,
* that starts from a fresh parser state.
* It's -1 if the line does not have a clean parser state.
- * Therefore we search for the first line before `start` that has a
- * known clean parser state.
+ * If the cached position on start_line does not fit our needs,
+ * we backtrack and search in previous lines
+ * for a known clean parser state.
+ *
+ * NOTE: It's crucial to consider the line state of the first possible
+ * line since we might be styling for a single-line command line view.
+ *
+ * FIXME: During rubout of regular commands we will frequently have the
+ * situation that the cached line state points after the last styled position
+ * forcing us to restyle the entire command line macro.
+ * If this turns out to be problematic, we might detect that
+ * view == teco_cmdline.view and inspect teco_cmdline.machine.
*/
- if (start_line > 0) {
+ gint start_col = teco_view_ssm(view, SCI_GETLINESTATE, start_line, 0);
+ if (start_col > start - teco_view_ssm(view, SCI_POSITIONFROMLINE, start_line, 0))
+ /* we are asked to style __before__ the last known start state */
+ start_col = -1;
+ if (start_col < 0 && start_line > 0) {
do
start_line--;
while ((start_col = teco_view_ssm(view, SCI_GETLINESTATE, start_line, 0)) < 0 &&
start_line > 0);
- start_col = MAX(start_col, 0);
}
+ start_col = MAX(start_col, 0);
start = teco_view_ssm(view, SCI_POSITIONFROMLINE, start_line, 0) + start_col;
g_assert(end > start);