aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/symbols.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/symbols.c')
-rw-r--r--src/symbols.c81
1 files changed, 46 insertions, 35 deletions
diff --git a/src/symbols.c b/src/symbols.c
index 4028b7e..dd5856e 100644
--- a/src/symbols.c
+++ b/src/symbols.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012-2025 Robin Haberkorn
+ * Copyright (C) 2012-2026 Robin Haberkorn
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,6 +38,7 @@
#include "undo.h"
#include "expressions.h"
#include "interface.h"
+#include "cmdline.h"
#include "symbols.h"
teco_symbol_list_t teco_symbol_list_scintilla = {NULL, 0};
@@ -138,7 +139,7 @@ teco_symbol_list_auto_complete(teco_symbol_list_t *ctx, const gchar *symbol, tec
glist_str.data = (gchar *)glist->data + symbol_len;
glist_str.len = strlen(glist_str.data);
- gsize len = teco_string_casediff(&glist_str, (gchar *)entry->data + symbol_len,
+ gsize len = teco_string_casediff(glist_str, (gchar *)entry->data + symbol_len,
strlen(entry->data) - symbol_len);
if (!prefix_len || len < prefix_len)
prefix_len = len;
@@ -166,13 +167,17 @@ teco_symbol_list_auto_complete(teco_symbol_list_t *ctx, const gchar *symbol, tec
* Command states
*/
-/*
- * FIXME: This state could be static.
- */
-TECO_DECLARE_STATE(teco_state_scintilla_lparam);
+static inline sptr_t
+teco_scintilla_ssm(unsigned int iMessage, uptr_t wParam, sptr_t lParam)
+{
+ return teco_view_ssm(teco_ed & TECO_ED_MINIBUF_SSM ? teco_cmdline.view : teco_interface_current_view,
+ iMessage, wParam, lParam);
+}
+
+static teco_state_t teco_state_scintilla_lparam;
static gboolean
-teco_scintilla_parse_symbols(teco_machine_scintilla_t *scintilla, const teco_string_t *str, GError **error)
+teco_scintilla_parse_symbols(teco_machine_scintilla_t *scintilla, teco_string_t str, GError **error)
{
if (teco_string_contains(str, '\0')) {
g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
@@ -180,7 +185,7 @@ teco_scintilla_parse_symbols(teco_machine_scintilla_t *scintilla, const teco_str
return FALSE;
}
- g_auto(GStrv) symbols = g_strsplit(str->data, ",", -1);
+ g_auto(GStrv) symbols = g_strsplit(str.data, ",", -1);
if (!symbols[0])
return TRUE;
@@ -212,7 +217,7 @@ teco_scintilla_parse_symbols(teco_machine_scintilla_t *scintilla, const teco_str
}
static teco_state_t *
-teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_scintilla_lparam;
@@ -226,12 +231,10 @@ teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, const teco_string_t
teco_undo_scintilla_message(ctx->scintilla);
memset(&ctx->scintilla, 0, sizeof(ctx->scintilla));
- if ((str->len > 0 && !teco_scintilla_parse_symbols(&ctx->scintilla, str, error)) ||
+ if ((str.len > 0 && !teco_scintilla_parse_symbols(&ctx->scintilla, str, error)) ||
!teco_expressions_eval(FALSE, error))
return NULL;
- teco_int_t value;
-
if (!ctx->scintilla.iMessage) {
if (!teco_expressions_args()) {
g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
@@ -239,9 +242,7 @@ teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, const teco_string_t
return NULL;
}
- if (!teco_expressions_pop_num_calc(&value, 0, error))
- return NULL;
- ctx->scintilla.iMessage = value;
+ ctx->scintilla.iMessage = teco_expressions_pop_num(0);
}
return &teco_state_scintilla_lparam;
@@ -250,7 +251,7 @@ teco_state_scintilla_symbols_done(teco_machine_main_t *ctx, const teco_string_t
/* in cmdline.c */
gboolean teco_state_scintilla_symbols_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx,
gunichar key, GError **error);
-gboolean teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str,
+gboolean teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx, teco_string_t str,
GError **error);
/*$ ES scintilla message
@@ -320,6 +321,13 @@ gboolean teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx
* second string argument of \fBES\fP, i.e. it allows you
* to look up style ids by name.
*
+ * By default Scintilla messages are sent to the current buffer's
+ * view or the Q-register view \(em there is only one view for
+ * all Q-registers.
+ * If bit 11 is set in the \fBED\fP flags, the messages will be
+ * sent to the command-line view instead, which allows you to
+ * set up \*(ST syntax highlighting and other styles.
+ *
* .BR Warning :
* Almost all Scintilla messages may be dispatched using
* this command.
@@ -344,17 +352,18 @@ gboolean teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx
TECO_DEFINE_STATE_EXPECTSTRING(teco_state_scintilla_symbols,
.process_edit_cmd_cb = (teco_state_process_edit_cmd_cb_t)teco_state_scintilla_symbols_process_edit_cmd,
.insert_completion_cb = (teco_state_insert_completion_cb_t)teco_state_scintilla_symbols_insert_completion,
- .expectstring.last = FALSE
+ .expectstring.last = FALSE,
+ .expectstring.done_cb = teco_state_scintilla_symbols_done
);
#ifdef HAVE_LEXILLA
static gpointer
-teco_create_lexer(const teco_string_t *str, GError **error)
+teco_create_lexer(teco_string_t str, GError **error)
{
CreateLexerFn CreateLexerFn = CreateLexer;
- const gchar *lexer = memchr(str->data ? : "", '\0', str->len);
+ const gchar *lexer = memchr(str.data ? : "", '\0', str.len);
if (lexer) {
/* external lexer */
lexer++;
@@ -363,7 +372,7 @@ teco_create_lexer(const teco_string_t *str, GError **error)
* NOTE: The same module can be opened multiple times.
* They are internally reference counted.
*/
- GModule *module = g_module_open(str->data, G_MODULE_BIND_LAZY);
+ GModule *module = g_module_open(str.data, G_MODULE_BIND_LAZY);
if (!module) {
teco_error_module_set(error, "Error opening lexer module");
return NULL;
@@ -385,7 +394,7 @@ teco_create_lexer(const teco_string_t *str, GError **error)
*
* FIXME: In Scintillua distributions, the lexers are usually contained in the
* same directory as the prebuilt shared libraries.
- * Perhaps we should default scintillua.lexers to the dirname in str->data?
+ * Perhaps we should default scintillua.lexers to the dirname in str.data?
*/
teco_qreg_t *reg = teco_qreg_table_find(&teco_qreg_table_globals, "$SCITECO_SCINTILLUA_LEXERS", 26);
if (reg) {
@@ -397,7 +406,7 @@ teco_create_lexer(const teco_string_t *str, GError **error)
}
} else {
/* Lexilla lexer */
- lexer = str->data ? : "";
+ lexer = str.data ? : "";
}
ILexer5 *ret = CreateLexerFn(lexer);
@@ -413,9 +422,9 @@ teco_create_lexer(const teco_string_t *str, GError **error)
#else /* !HAVE_LEXILLA */
static gpointer
-teco_create_lexer(const teco_string_t *str, GError **error)
+teco_create_lexer(teco_string_t str, GError **error)
{
- g_autofree gchar *str_printable = teco_string_echo(str->data, str->len);
+ g_autofree gchar *str_printable = teco_string_echo(str.data, str.len);
g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
"Cannot load lexer \"%s\": Lexilla disabled", str_printable);
return NULL;
@@ -424,7 +433,7 @@ teco_create_lexer(const teco_string_t *str, GError **error)
#endif
static teco_state_t *
-teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_start;
@@ -446,10 +455,10 @@ teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, const teco_string_t *
/*
* FIXME: Should we cache the name to style id?
*/
- guint count = teco_interface_ssm(SCI_GETNAMEDSTYLES, 0, 0);
+ guint count = teco_scintilla_ssm(SCI_GETNAMEDSTYLES, 0, 0);
for (guint id = 0; id < count; id++) {
gchar style[128] = "";
- teco_interface_ssm(SCI_NAMEOFSTYLE, id, (sptr_t)style);
+ teco_scintilla_ssm(SCI_NAMEOFSTYLE, id, (sptr_t)style);
if (!teco_string_cmp(str, style, strlen(style))) {
teco_expressions_push(id);
return &teco_state_start;
@@ -457,13 +466,13 @@ teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, const teco_string_t *
}
g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
- "Style name \"%s\" not found.", str->data ? : "");
+ "Style name \"%s\" not found.", str.data ? : "");
return NULL;
} else if (ctx->scintilla.iMessage == SCI_SETILEXER) {
lParam = (sptr_t)teco_create_lexer(str, error);
if (!lParam)
return NULL;
- } else if (str->len > 0) {
+ } else if (str.len > 0) {
/*
* Theoretically, Scintilla could use null bytes from the string specified.
* This could only be the case for messages where the string length is
@@ -473,13 +482,13 @@ teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, const teco_string_t *
* which unlocks useful messages like
* SCI_SETREPRESENTATIONS and SCI_SETPROPERTY.
*/
- const gchar *p = memchr(str->data, '\0', str->len);
+ const gchar *p = memchr(str.data, '\0', str.len);
if (p) {
- ctx->scintilla.wParam = (uptr_t)str->data;
- if (str->len > p - str->data + 1)
+ ctx->scintilla.wParam = (uptr_t)str.data;
+ if (str.len > p - str.data + 1)
lParam = (sptr_t)(p+1);
} else {
- lParam = (sptr_t)str->data;
+ lParam = (sptr_t)str.data;
}
}
@@ -495,10 +504,12 @@ teco_state_scintilla_lparam_done(teco_machine_main_t *ctx, const teco_string_t *
lParam = v;
}
- teco_expressions_push(teco_interface_ssm(ctx->scintilla.iMessage,
+ teco_expressions_push(teco_scintilla_ssm(ctx->scintilla.iMessage,
ctx->scintilla.wParam, lParam));
return &teco_state_start;
}
-TECO_DEFINE_STATE_EXPECTSTRING(teco_state_scintilla_lparam);
+static TECO_DEFINE_STATE_EXPECTSTRING(teco_state_scintilla_lparam,
+ .expectstring.done_cb = teco_state_scintilla_lparam_done
+);