aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cmdline.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmdline.c')
-rw-r--r--src/cmdline.c344
1 files changed, 227 insertions, 117 deletions
diff --git a/src/cmdline.c b/src/cmdline.c
index b03f72a..fa69d91 100644
--- a/src/cmdline.c
+++ b/src/cmdline.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
@@ -61,17 +61,49 @@ int malloc_trim(size_t pad);
#define TECO_DEFAULT_BREAK_CHARS " \t\v\r\n\f<>,;@"
-teco_cmdline_t teco_cmdline = {};
+/** Style used for the asterisk at the beginning of the command line */
+#define STYLE_ASTERISK 64
-/*
- * FIXME: Should this be here?
- * Should perhaps rather be in teco_machine_main_t or teco_cmdline_t.
- */
-gboolean teco_quit_requested = FALSE;
+teco_cmdline_t teco_cmdline = {
+ .height = 1
+};
-/** Last terminated command line */
+/**
+ * Last terminated command line.
+ * This is not a teco_doc_scintilla_t since we have to return it as a string
+ * at the end of the day.
+ */
static teco_string_t teco_last_cmdline = {NULL, 0};
+void
+teco_cmdline_init(void)
+{
+ teco_cmdline.view = teco_view_new();
+ teco_view_setup(teco_cmdline.view);
+
+ teco_cmdline_ssm(SCI_SETUNDOCOLLECTION, FALSE, 0);
+ teco_cmdline_ssm(SCI_SETVSCROLLBAR, FALSE, 0);
+ teco_cmdline_ssm(SCI_STYLESETBOLD, STYLE_ASTERISK, TRUE);
+ teco_cmdline_ssm(SCI_SETMARGINTYPEN, 1, SC_MARGIN_TEXT);
+ teco_cmdline_ssm(SCI_MARGINSETSTYLE, 0, STYLE_ASTERISK);
+ teco_cmdline_ssm(SCI_SETMARGINWIDTHN, 1,
+ teco_cmdline_ssm(SCI_TEXTWIDTH, STYLE_ASTERISK, (sptr_t)"*"));
+ /* NOTE: might not work on all UIs */
+ teco_cmdline_ssm(SCI_INDICSETSTYLE, INDICATOR_RUBBEDOUT, INDIC_STRIKE);
+ teco_cmdline_ssm(SCI_INDICSETFORE, INDICATOR_RUBBEDOUT,
+ teco_cmdline_ssm(SCI_STYLEGETFORE, STYLE_DEFAULT, 0));
+
+ /* single line mode - EOL characters won't break the line */
+ teco_cmdline_ssm(SCI_SETLINEENDTYPESALLOWED, SC_LINE_END_TYPE_NONE, 0);
+ /* render tabs as "TAB" without indentation */
+ teco_cmdline_ssm(SCI_SETTABDRAWMODE, SCTD_CONTROLCHAR, 0);
+
+ /*
+ * FIXME: Something resets the margin text, so we have to set it last.
+ */
+ teco_cmdline_ssm(SCI_MARGINSETTEXT, 0, (sptr_t)"*");
+}
+
/**
* Insert string into command line and execute
* it immediately.
@@ -89,40 +121,49 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error)
g_auto(teco_string_t) old_cmdline = {NULL, 0};
gsize repl_pc = 0;
- teco_cmdline.machine.macro_pc = teco_cmdline.pc = teco_cmdline.effective_len;
+ gsize effective_len = teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0);
+ teco_cmdline.machine.macro_pc = teco_cmdline.pc = effective_len;
+
+ const gchar *macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0);
+ gsize macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
- if (len <= teco_cmdline.str.len - teco_cmdline.effective_len &&
- !teco_string_cmp(&src, teco_cmdline.str.data + teco_cmdline.effective_len, len)) {
- teco_cmdline.effective_len += len;
+ if (len <= macro_len - effective_len &&
+ !teco_string_cmp(src, macro + effective_len, len)) {
+ /* extend effective command line from rubbed out part */
+ teco_cmdline_ssm(SCI_GOTOPOS, effective_len+len, 0);
} else {
- if (teco_cmdline.effective_len < teco_cmdline.str.len)
+ /* discard rubbed out part of the command line */
+ if (effective_len < macro_len)
/*
* Automatically disable immediate editing modifier.
* FIXME: Should we show a message as when pressing ^G?
*/
teco_cmdline.modifier_enabled = FALSE;
- teco_cmdline.str.len = teco_cmdline.effective_len;
- teco_string_append(&teco_cmdline.str, data, len);
- teco_cmdline.effective_len = teco_cmdline.str.len;
+ teco_cmdline_ssm(SCI_DELETERANGE, effective_len, macro_len - effective_len);
+ teco_cmdline_ssm(SCI_ADDTEXT, len, (sptr_t)data);
+
+ /* the pointer shouldn't have changed... */
+ macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0);
+ macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
}
+ effective_len += len;
/*
* Parse/execute characters, one at a time so
* undo tokens get emitted for the corresponding characters.
*/
- while (teco_cmdline.pc < teco_cmdline.effective_len) {
+ while (teco_cmdline.pc < effective_len) {
g_autoptr(GError) tmp_error = NULL;
- if (!teco_machine_main_step(&teco_cmdline.machine, teco_cmdline.str.data,
- teco_cmdline.pc+1, &tmp_error)) {
+ if (!teco_machine_main_step(&teco_cmdline.machine, macro, teco_cmdline.pc+1, &tmp_error)) {
if (g_error_matches(tmp_error, TECO_ERROR, TECO_ERROR_CMDLINE)) {
/*
* Result of command line replacement (}):
- * Exchange command lines, avoiding deep copying
+ * Exchange command lines
*/
teco_qreg_t *cmdline_reg = teco_qreg_table_find(&teco_qreg_table_globals, "\e", 1);
- teco_string_t new_cmdline;
+ g_auto(teco_string_t) new_cmdline = {NULL, 0};
if (!cmdline_reg->vtable->get_string(cmdline_reg, &new_cmdline.data, &new_cmdline.len,
NULL, error))
@@ -133,16 +174,26 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error)
* new command line. This avoids unnecessary rubouts
* and insertions when the command line is updated.
*/
- teco_cmdline.pc = teco_string_diff(&teco_cmdline.str, new_cmdline.data, new_cmdline.len);
+ teco_cmdline.pc = teco_string_diff(new_cmdline, macro, effective_len);
teco_undo_pop(teco_cmdline.pc);
+ /*
+ * We don't replace the command line's document, since that would
+ * reset the line end type and other configurable settings.
+ * Also, we don't clear the document to avoid unnecessary restylings
+ * if syntax highlighting is enabled on the command line.
+ */
g_assert(old_cmdline.len == 0);
- old_cmdline = teco_cmdline.str;
- teco_cmdline.str = new_cmdline;
- teco_cmdline.effective_len = new_cmdline.len;
+ teco_string_init(&old_cmdline, macro, effective_len);
+ teco_cmdline_ssm(SCI_DELETERANGE, teco_cmdline.pc,
+ old_cmdline.len-teco_cmdline.pc);
+ teco_cmdline_ssm(SCI_ADDTEXT, new_cmdline.len-teco_cmdline.pc,
+ (sptr_t)new_cmdline.data+teco_cmdline.pc);
+
+ macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0);
+ macro_len = effective_len = new_cmdline.len;
teco_cmdline.machine.macro_pc = repl_pc = teco_cmdline.pc;
-
continue;
}
@@ -154,17 +205,26 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error)
/*
* Error during command-line replacement.
* Replay previous command-line.
- * This avoids deep copying.
+ * The commands leading up to the failed replacement
+ * will be left rubbed out.
*/
teco_undo_pop(repl_pc);
- teco_string_clear(&teco_cmdline.str);
- teco_cmdline.str = old_cmdline;
+ /*
+ * May cause restyling of the command lines,
+ * but that's probably okay - it's just a fallback.
+ */
+ teco_cmdline_ssm(SCI_CLEARALL, 0, 0);
+ teco_cmdline_ssm(SCI_ADDTEXT, old_cmdline.len, (sptr_t)old_cmdline.data);
+ teco_string_clear(&old_cmdline);
memset(&old_cmdline, 0, sizeof(old_cmdline));
teco_cmdline.machine.macro_pc = teco_cmdline.pc = repl_pc;
- /* rubout cmdline replacement command */
- teco_cmdline.effective_len--;
+ /* rub out cmdline replacement command */
+ teco_cmdline_ssm(SCI_GOTOPOS, --effective_len, 0);
+
+ macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0);
+ macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
continue;
}
}
@@ -183,14 +243,18 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error)
static gboolean
teco_cmdline_rubin(GError **error)
{
- if (!teco_cmdline.str.len)
- return TRUE;
-
- const gchar *start, *end, *next;
- start = teco_cmdline.str.data+teco_cmdline.effective_len;
- end = teco_cmdline.str.data+teco_cmdline.str.len;
- next = g_utf8_find_next_char(start, end) ? : end;
- return teco_cmdline_insert(start, next-start, error);
+ gsize macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
+ gsize pos = teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0);
+ gchar buf[4+1];
+ struct Sci_TextRangeFull range = {
+ .chrg = {pos, MIN(macro_len, pos+sizeof(buf)-1)},
+ .lpstrText = buf
+ };
+ gsize len = teco_cmdline_ssm(SCI_GETTEXTRANGEFULL, 0, (sptr_t)&range);
+
+ const gchar *end = buf+len;
+ const gchar *next = g_utf8_find_next_char(buf, end) ? : end;
+ return teco_cmdline_insert(buf, next-buf, error);
}
/**
@@ -211,10 +275,9 @@ teco_cmdline_rubin(GError **error)
gboolean
teco_cmdline_keypress(const gchar *data, gsize len, GError **error)
{
- const teco_string_t str = {(gchar *)data, len};
teco_machine_t *machine = &teco_cmdline.machine.parent;
- if (!teco_string_validate_utf8(&str)) {
+ if (!teco_string_validate_utf8((teco_string_t){(gchar *)data, len})) {
g_set_error_literal(error, TECO_ERROR, TECO_ERROR_CODEPOINT,
"Invalid UTF-8 sequence");
return FALSE;
@@ -225,7 +288,7 @@ teco_cmdline_keypress(const gchar *data, gsize len, GError **error)
*/
teco_interface_msg_clear();
- gsize start_pc = teco_cmdline.effective_len;
+ gsize start_pc = teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0);
for (guint i = 0; i < len; i = g_utf8_next_char(data+i) - data) {
gunichar chr = g_utf8_get_char(data+i);
@@ -252,9 +315,9 @@ teco_cmdline_keypress(const gchar *data, gsize len, GError **error)
* up until the insertion point.
*/
teco_undo_pop(start_pc);
- teco_cmdline.effective_len = start_pc;
+ teco_cmdline_ssm(SCI_GOTOPOS, start_pc, 0);
/* program counter could be messed up */
- teco_cmdline.machine.macro_pc = teco_cmdline.effective_len;
+ teco_cmdline.machine.macro_pc = start_pc;
#ifdef HAVE_MALLOC_TRIM
/*
@@ -285,7 +348,7 @@ teco_cmdline_keypress(const gchar *data, gsize len, GError **error)
teco_interface_popup_clear();
- if (teco_quit_requested) {
+ if (teco_ed & TECO_ED_EXIT) {
/* caught by user interface */
g_set_error_literal(error, TECO_ERROR, TECO_ERROR_QUIT, "");
return FALSE;
@@ -303,9 +366,16 @@ teco_cmdline_keypress(const gchar *data, gsize len, GError **error)
g_array_remove_range(teco_loop_stack, 0, teco_loop_stack->len);
teco_string_clear(&teco_last_cmdline);
- teco_last_cmdline = teco_cmdline.str;
- memset(&teco_cmdline.str, 0, sizeof(teco_cmdline.str));
- teco_cmdline.effective_len = 0;
+ teco_last_cmdline.len = teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0);
+ teco_last_cmdline.data = g_malloc(teco_last_cmdline.len + 1);
+ teco_cmdline_ssm(SCI_GETTEXT, teco_last_cmdline.len,
+ (sptr_t)teco_last_cmdline.data);
+ /*
+ * FIXME: Preserve the command line after the $$.
+ * This would be useful for command line editing macros.
+ * Perhaps just call teco_cmdline_insert().
+ */
+ teco_cmdline_ssm(SCI_CLEARALL, 0, 0);
#ifdef HAVE_MALLOC_TRIM
/* see above */
@@ -320,10 +390,8 @@ teco_cmdline_keypress(const gchar *data, gsize len, GError **error)
start_pc = 0;
}
- /*
- * Echo command line
- */
- teco_interface_cmdline_update(&teco_cmdline);
+ teco_cmdline_update();
+
return TRUE;
}
@@ -380,20 +448,48 @@ teco_cmdline_keymacro(const gchar *name, gssize name_len, GError **error)
static void
teco_cmdline_rubout(void)
{
- const gchar *p;
- p = g_utf8_find_prev_char(teco_cmdline.str.data,
- teco_cmdline.str.data+teco_cmdline.effective_len);
- if (p) {
- teco_cmdline.effective_len = p - teco_cmdline.str.data;
- teco_undo_pop(teco_cmdline.effective_len);
+ gsize effective_len = teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0);
+ gssize p = teco_view_glyphs2bytes_relative(teco_cmdline.view, effective_len, -1);
+ if (p >= 0) {
+ teco_cmdline_ssm(SCI_GOTOPOS, p, 0);
+ teco_undo_pop(p);
}
}
-static void TECO_DEBUG_CLEANUP
+/**
+ * Update the command line, i.e. prepare it for displaying.
+ *
+ * This updates the indicators and scrolls the caret, which isn't done every time
+ * we touch the command line itself.
+ */
+void
+teco_cmdline_update(void)
+{
+ /*
+ * FIXME: Perhaps this can be avoided completely by updating the
+ * indicators in teco_cmdline_insert().
+ */
+ gsize effective_len = teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0);
+ gsize macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
+ teco_cmdline_ssm(SCI_SETINDICATORCURRENT, INDICATOR_RUBBEDOUT, 0);
+ teco_cmdline_ssm(SCI_INDICATORCLEARRANGE, 0, macro_len);
+ teco_cmdline_ssm(SCI_INDICATORFILLRANGE, effective_len, macro_len - effective_len);
+
+ teco_cmdline_ssm(SCI_SCROLLCARET, 0, 0);
+
+ /*
+ * FIXME: This gets reset repeatedly.
+ * Setting it once per keypress however means you can no longer customize
+ * the margin text.
+ */
+ teco_cmdline_ssm(SCI_MARGINSETTEXT, 0, (sptr_t)"*");
+}
+
+void
teco_cmdline_cleanup(void)
{
teco_machine_main_clear(&teco_cmdline.machine);
- teco_string_clear(&teco_cmdline.str);
+ teco_view_free(teco_cmdline.view);
teco_string_clear(&teco_last_cmdline);
}
@@ -451,11 +547,12 @@ teco_state_process_edit_cmd(teco_machine_t *ctx, teco_machine_t *parent_ctx, gun
if (teco_cmdline.modifier_enabled) {
/* reinsert construct */
+ gsize macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
do {
if (!teco_cmdline_rubin(error))
return FALSE;
} while (!ctx->current->is_start &&
- teco_cmdline.effective_len < teco_cmdline.str.len);
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len);
} else {
/* rubout construct */
do
@@ -475,6 +572,11 @@ teco_state_process_edit_cmd(teco_machine_t *ctx, teco_machine_t *parent_ctx, gun
raise(SIGTSTP);
return TRUE;
#endif
+
+ case TECO_CTL_KEY('L'):
+ /* causes a complete screen redraw */
+ teco_interface_refresh(TRUE);
+ return TRUE;
}
teco_interface_popup_clear();
@@ -506,6 +608,9 @@ teco_state_command_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *pa
case TECO_CTL_KEY('W'): /* rubout/reinsert command */
teco_interface_popup_clear();
+ const gchar *macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0);
+ gsize macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
+
/*
* This mimics the behavior of the `Y` command,
* so it also rubs out no-op commands.
@@ -515,9 +620,8 @@ teco_state_command_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *pa
/* reinsert command */
/* @ and : are not separate states, but practically belong to the command */
while (ctx->parent.current->is_start &&
- teco_cmdline.effective_len < teco_cmdline.str.len &&
- (teco_cmdline.str.data[teco_cmdline.effective_len] == ':' ||
- teco_cmdline.str.data[teco_cmdline.effective_len] == '@'))
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len &&
+ strchr(":@", macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)]) != NULL)
if (!teco_cmdline_rubin(error))
return FALSE;
@@ -525,11 +629,11 @@ teco_state_command_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *pa
if (!teco_cmdline_rubin(error))
return FALSE;
} while (!ctx->parent.current->is_start &&
- teco_cmdline.effective_len < teco_cmdline.str.len);
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len);
while (ctx->parent.current->is_start &&
- teco_cmdline.effective_len < teco_cmdline.str.len &&
- strchr(TECO_NOOPS, teco_cmdline.str.data[teco_cmdline.effective_len]))
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len &&
+ teco_is_noop(macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)]))
if (!teco_cmdline_rubin(error))
return FALSE;
@@ -538,8 +642,8 @@ teco_state_command_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *pa
/* rubout command */
while (ctx->parent.current->is_start &&
- teco_cmdline.effective_len > 0 &&
- strchr(TECO_NOOPS, teco_cmdline.str.data[teco_cmdline.effective_len-1]))
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) > 0 &&
+ teco_is_noop(macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1]))
teco_cmdline_rubout();
do
@@ -553,7 +657,7 @@ teco_state_command_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *pa
*/
while (ctx->parent.current->is_start &&
(ctx->flags.modifier_at || ctx->flags.modifier_colon) &&
- teco_cmdline.effective_len > 0)
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) > 0)
teco_cmdline_rubout();
return TRUE;
@@ -568,6 +672,9 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t *
{
teco_state_t *current = ctx->parent.current;
+ const gchar *macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0);
+ gsize macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
+
switch (key) {
case TECO_CTL_KEY('W'): { /* rubout/reinsert word */
teco_interface_popup_clear();
@@ -585,15 +692,15 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t *
if (teco_cmdline.modifier_enabled) {
/* reinsert word chars */
while (ctx->parent.current == current &&
- teco_cmdline.effective_len < teco_cmdline.str.len &&
- teco_string_contains(&wchars, teco_cmdline.str.data[teco_cmdline.effective_len]))
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len &&
+ teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)]))
if (!teco_cmdline_rubin(error))
return FALSE;
/* reinsert non-word chars */
while (ctx->parent.current == current &&
- teco_cmdline.effective_len < teco_cmdline.str.len &&
- !teco_string_contains(&wchars, teco_cmdline.str.data[teco_cmdline.effective_len]))
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len &&
+ !teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)]))
if (!teco_cmdline_rubin(error))
return FALSE;
@@ -607,7 +714,7 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t *
* a result string even in parse-only mode.
*/
if (ctx->result && ctx->result->len > 0) {
- gboolean is_wordchar = teco_string_contains(&wchars, teco_cmdline.str.data[teco_cmdline.effective_len-1]);
+ gboolean is_wordchar = teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1]);
teco_cmdline_rubout();
if (ctx->parent.current != current) {
/* rub out string building command */
@@ -623,13 +730,13 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t *
*/
if (!is_wordchar) {
while (ctx->result->len > 0 &&
- !teco_string_contains(&wchars, teco_cmdline.str.data[teco_cmdline.effective_len-1]))
+ !teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1]))
teco_cmdline_rubout();
}
/* rubout word chars */
while (ctx->result->len > 0 &&
- teco_string_contains(&wchars, teco_cmdline.str.data[teco_cmdline.effective_len-1]))
+ teco_string_contains(wchars, macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1]))
teco_cmdline_rubout();
return TRUE;
@@ -646,8 +753,7 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t *
if (teco_cmdline.modifier_enabled) {
/* reinsert string */
- while (ctx->parent.current == current &&
- teco_cmdline.effective_len < teco_cmdline.str.len)
+ while (ctx->parent.current == current && teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len)
if (!teco_cmdline_rubin(error))
return FALSE;
@@ -685,7 +791,7 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t *
return TRUE;
}
- const gchar *filename = teco_string_last_occurrence(ctx->result,
+ const gchar *filename = teco_string_last_occurrence(*ctx->result,
TECO_DEFAULT_BREAK_CHARS);
g_auto(teco_string_t) new_chars, new_chars_escaped;
gboolean unambiguous = teco_file_auto_complete(filename, G_FILE_TEST_EXISTS, &new_chars);
@@ -716,11 +822,11 @@ teco_state_stringbuilding_start_process_edit_cmd(teco_machine_stringbuilding_t *
}
gboolean
-teco_state_stringbuilding_insert_completion(teco_machine_stringbuilding_t *ctx, const teco_string_t *str, GError **error)
+teco_state_stringbuilding_insert_completion(teco_machine_stringbuilding_t *ctx, teco_string_t str, GError **error)
{
g_auto(teco_string_t) str_escaped;
- teco_machine_stringbuilding_escape(ctx, str->data, str->len, &str_escaped);
- if (!str->len || !G_IS_DIR_SEPARATOR(str->data[str->len-1]))
+ teco_machine_stringbuilding_escape(ctx, str.data, str.len, &str_escaped);
+ if (!str.len || !G_IS_DIR_SEPARATOR(str.data[str.len-1]))
teco_string_append_c(&str_escaped, ' ');
return teco_cmdline_insert(str_escaped.data, str_escaped.len, error);
}
@@ -765,7 +871,7 @@ teco_state_expectstring_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_
}
gboolean
-teco_state_expectstring_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_expectstring_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine;
teco_state_t *stringbuilding_current = stringbuilding_ctx->parent.current;
@@ -825,18 +931,21 @@ teco_state_expectfile_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t
case TECO_CTL_KEY('W'): /* rubout/reinsert file names including directories */
teco_interface_popup_clear();
+ const gchar *macro = (const gchar *)teco_cmdline_ssm(SCI_GETCHARACTERPOINTER, 0, 0);
+ gsize macro_len = teco_cmdline_ssm(SCI_GETLENGTH, 0, 0);
+
if (teco_cmdline.modifier_enabled) {
/* reinsert one level of file name */
while (stringbuilding_ctx->parent.current == stringbuilding_current &&
- teco_cmdline.effective_len < teco_cmdline.str.len &&
- !G_IS_DIR_SEPARATOR(teco_cmdline.str.data[teco_cmdline.effective_len]))
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len &&
+ !G_IS_DIR_SEPARATOR(macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)]))
if (!teco_cmdline_rubin(error))
return FALSE;
/* reinsert final directory separator */
if (stringbuilding_ctx->parent.current == stringbuilding_current &&
- teco_cmdline.effective_len < teco_cmdline.str.len &&
- G_IS_DIR_SEPARATOR(teco_cmdline.str.data[teco_cmdline.effective_len]) &&
+ teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0) < macro_len &&
+ G_IS_DIR_SEPARATOR(macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)]) &&
!teco_cmdline_rubin(error))
return FALSE;
@@ -845,12 +954,12 @@ teco_state_expectfile_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t
if (ctx->expectstring.string.len > 0) {
/* rubout directory separator */
- if (G_IS_DIR_SEPARATOR(teco_cmdline.str.data[teco_cmdline.effective_len-1]))
+ if (G_IS_DIR_SEPARATOR(macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1]))
teco_cmdline_rubout();
/* rubout one level of file name */
while (ctx->expectstring.string.len > 0 &&
- !G_IS_DIR_SEPARATOR(teco_cmdline.str.data[teco_cmdline.effective_len-1]))
+ !G_IS_DIR_SEPARATOR(macro[teco_cmdline_ssm(SCI_GETCURRENTPOS, 0, 0)-1]))
teco_cmdline_rubout();
return TRUE;
@@ -871,7 +980,7 @@ teco_state_expectfile_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t
return TRUE;
}
- if (teco_string_contains(&ctx->expectstring.string, '\0'))
+ if (teco_string_contains(ctx->expectstring.string, '\0'))
/* null-byte not allowed in file names */
return TRUE;
@@ -890,13 +999,13 @@ teco_state_expectfile_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t
}
gboolean
-teco_state_expectfile_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_expectfile_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine;
g_auto(teco_string_t) str_escaped;
- teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped);
- if ((!str->len || !G_IS_DIR_SEPARATOR(str->data[str->len-1])) &&
+ teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped);
+ if ((!str.len || !G_IS_DIR_SEPARATOR(str.data[str.len-1])) &&
ctx->expectstring.nesting == 1)
teco_string_append_wc(&str_escaped,
ctx->expectstring.machine.escape_char == '{' ? '}' : ctx->expectstring.machine.escape_char);
@@ -927,7 +1036,7 @@ teco_state_expectglob_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t
return TRUE;
}
- if (teco_string_contains(&ctx->expectstring.string, '\0'))
+ if (teco_string_contains(ctx->expectstring.string, '\0'))
/* null-byte not allowed in file names */
return TRUE;
@@ -958,14 +1067,14 @@ teco_state_expectglob_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t
}
gboolean
-teco_state_expectglob_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_expectglob_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine;
- g_autofree gchar *pattern_escaped = teco_globber_escape_pattern(str->data);
+ g_autofree gchar *pattern_escaped = teco_globber_escape_pattern(str.data);
g_auto(teco_string_t) str_escaped;
teco_machine_stringbuilding_escape(stringbuilding_ctx, pattern_escaped, strlen(pattern_escaped), &str_escaped);
- if ((!str->len || !G_IS_DIR_SEPARATOR(str->data[str->len-1])) &&
+ if ((!str.len || !G_IS_DIR_SEPARATOR(str.data[str.len-1])) &&
ctx->expectstring.nesting == 1)
teco_string_append_wc(&str_escaped,
ctx->expectstring.machine.escape_char == '{' ? '}' : ctx->expectstring.machine.escape_char);
@@ -996,7 +1105,7 @@ teco_state_expectdir_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *
return TRUE;
}
- if (teco_string_contains(&ctx->expectstring.string, '\0'))
+ if (teco_string_contains(ctx->expectstring.string, '\0'))
/* null-byte not allowed in file names */
return TRUE;
@@ -1016,7 +1125,7 @@ teco_state_expectdir_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *
}
gboolean
-teco_state_expectdir_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_expectdir_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine;
@@ -1024,7 +1133,7 @@ teco_state_expectdir_insert_completion(teco_machine_main_t *ctx, const teco_stri
* FIXME: We might terminate the command in case of leaf directories.
*/
g_auto(teco_string_t) str_escaped;
- teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped);
+ teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped);
return teco_cmdline_insert(str_escaped.data, str_escaped.len, error);
}
@@ -1041,7 +1150,7 @@ teco_state_expectqreg_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t
}
gboolean
-teco_state_expectqreg_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_expectqreg_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
g_assert(ctx->expectqreg != NULL);
/*
@@ -1092,9 +1201,9 @@ teco_state_qregspec_process_edit_cmd(teco_machine_qregspec_t *ctx, teco_machine_
}
gboolean
-teco_state_qregspec_insert_completion(teco_machine_qregspec_t *ctx, const teco_string_t *str, GError **error)
+teco_state_qregspec_insert_completion(teco_machine_qregspec_t *ctx, teco_string_t str, GError **error)
{
- return teco_cmdline_insert(str->data, str->len, error);
+ return teco_cmdline_insert(str.data, str.len, error);
}
gboolean
@@ -1138,12 +1247,12 @@ teco_state_qregspec_string_process_edit_cmd(teco_machine_qregspec_t *ctx, teco_m
}
gboolean
-teco_state_qregspec_string_insert_completion(teco_machine_qregspec_t *ctx, const teco_string_t *str, GError **error)
+teco_state_qregspec_string_insert_completion(teco_machine_qregspec_t *ctx, teco_string_t str, GError **error)
{
teco_machine_stringbuilding_t *stringbuilding_ctx = teco_machine_qregspec_get_stringbuilding(ctx);
g_auto(teco_string_t) str_escaped;
- teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped);
+ teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped);
teco_string_append_c(&str_escaped, ']');
return teco_cmdline_insert(str_escaped.data, str_escaped.len, error);
}
@@ -1178,7 +1287,7 @@ teco_state_execute_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *pa
return TRUE;
}
- const gchar *filename = teco_string_last_occurrence(&ctx->expectstring.string,
+ const gchar *filename = teco_string_last_occurrence(ctx->expectstring.string,
TECO_DEFAULT_BREAK_CHARS);
g_auto(teco_string_t) new_chars, new_chars_escaped;
gboolean unambiguous = teco_file_auto_complete(filename, G_FILE_TEST_EXISTS, &new_chars);
@@ -1217,7 +1326,7 @@ teco_state_scintilla_symbols_process_edit_cmd(teco_machine_main_t *ctx, teco_mac
return TRUE;
}
- const gchar *symbol = teco_string_last_occurrence(&ctx->expectstring.string, ",");
+ const gchar *symbol = teco_string_last_occurrence(ctx->expectstring.string, ",");
teco_symbol_list_t *list = symbol == ctx->expectstring.string.data
? &teco_symbol_list_scintilla
: &teco_symbol_list_scilexer;
@@ -1239,12 +1348,12 @@ teco_state_scintilla_symbols_process_edit_cmd(teco_machine_main_t *ctx, teco_mac
}
gboolean
-teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_scintilla_symbols_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine;
g_auto(teco_string_t) str_escaped;
- teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped);
+ teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped);
teco_string_append_c(&str_escaped, ',');
return teco_cmdline_insert(str_escaped.data, str_escaped.len, error);
}
@@ -1274,7 +1383,7 @@ teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *paren
}
teco_string_t label = ctx->expectstring.string;
- gint i = teco_string_rindex(&label, ',');
+ gint i = teco_string_rindex(label, ',');
if (i >= 0) {
label.data += i+1;
label.len -= i+1;
@@ -1297,12 +1406,12 @@ teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *paren
}
gboolean
-teco_state_goto_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_goto_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine;
g_auto(teco_string_t) str_escaped;
- teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped);
+ teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped);
/*
* FIXME: This does not escape `,`. Cannot be escaped via ^Q currently?
*/
@@ -1334,7 +1443,7 @@ teco_state_help_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *paren
return TRUE;
}
- if (teco_string_contains(&ctx->expectstring.string, '\0'))
+ if (teco_string_contains(ctx->expectstring.string, '\0'))
/* help term must not contain null-byte */
return TRUE;
@@ -1353,12 +1462,12 @@ teco_state_help_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *paren
}
gboolean
-teco_state_help_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_help_insert_completion(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
teco_machine_stringbuilding_t *stringbuilding_ctx = &ctx->expectstring.machine;
g_auto(teco_string_t) str_escaped;
- teco_machine_stringbuilding_escape(stringbuilding_ctx, str->data, str->len, &str_escaped);
+ teco_machine_stringbuilding_escape(stringbuilding_ctx, str.data, str.len, &str_escaped);
if (ctx->expectstring.nesting == 1)
teco_string_append_wc(&str_escaped,
ctx->expectstring.machine.escape_char == '{' ? '}' : ctx->expectstring.machine.escape_char);
@@ -1394,5 +1503,6 @@ teco_state_save_cmdline_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg
* Q-Register <q>.
*/
TECO_DEFINE_STATE_EXPECTQREG(teco_state_save_cmdline,
- .expectqreg.type = TECO_QREG_OPTIONAL_INIT
+ .expectqreg.type = TECO_QREG_OPTIONAL_INIT,
+ .expectqreg.got_register_cb = teco_state_save_cmdline_got_register
);