aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2023-04-13 12:06:06 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2023-04-13 12:06:06 +0300
commita105a8a0875224ecf8fa9ec0f337d1a4f30de76c (patch)
tree6223cd11094a102305013444fe4e55f17b980c98
parent9395b90c2bd441285651464818d69781682dd298 (diff)
downloadsciteco-a105a8a0875224ecf8fa9ec0f337d1a4f30de76c.tar.gz
cmdline.c: simplified the rubin-case
* We no longer need special NULL-values for teco_cmdline_insert(), as teco_cmdline_rubin() will simply take a character from the rubbed-out command line and is equivalent to typing a character from the rubbed-out command-line.
-rw-r--r--src/cmdline.c16
-rw-r--r--src/cmdline.h3
2 files changed, 6 insertions, 13 deletions
diff --git a/src/cmdline.c b/src/cmdline.c
index f8bcefd..1cdaa40 100644
--- a/src/cmdline.c
+++ b/src/cmdline.c
@@ -77,17 +77,10 @@ static teco_string_t teco_last_cmdline = {NULL, 0};
* It already handles command line replacement (TECO_ERROR_CMDLINE).
*
* @param data String to insert.
- * NULL inserts a character from the previously
- * rubbed out command line (rubin).
* @param len Length of string to insert.
* @param error A GError.
* @return FALSE to throw a GError
*/
-/*
- * FIXME: Passing data == NULL to perform a rubin is inelegant.
- * Better make teco_cmdline_rubin() a proper function.
- * FIXME: The inner loop should be factored out.
- */
gboolean
teco_cmdline_insert(const gchar *data, gsize len, GError **error)
{
@@ -97,11 +90,8 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error)
teco_cmdline.machine.macro_pc = teco_cmdline.pc = teco_cmdline.effective_len;
- if (!data) {
- if (teco_cmdline.effective_len < teco_cmdline.str.len)
- teco_cmdline.effective_len++;
- } else if (len <= teco_cmdline.str.len - teco_cmdline.effective_len &&
- !teco_string_cmp(&src, teco_cmdline.str.data + teco_cmdline.effective_len, len)) {
+ 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;
} else {
if (teco_cmdline.effective_len < teco_cmdline.str.len)
@@ -119,6 +109,8 @@ teco_cmdline_insert(const gchar *data, gsize len, GError **error)
/*
* Parse/execute characters, one at a time so
* undo tokens get emitted for the corresponding characters.
+ *
+ * FIXME: The inner loop should be factored out.
*/
while (teco_cmdline.pc < teco_cmdline.effective_len) {
g_autoptr(GError) tmp_error = NULL;
diff --git a/src/cmdline.h b/src/cmdline.h
index b0be0de..85e657a 100644
--- a/src/cmdline.h
+++ b/src/cmdline.h
@@ -65,7 +65,8 @@ gboolean teco_cmdline_insert(const gchar *data, gsize len, GError **error);
static inline gboolean
teco_cmdline_rubin(GError **error)
{
- return teco_cmdline_insert(NULL, 0, error);
+ return teco_cmdline.effective_len >= teco_cmdline.str.len ||
+ teco_cmdline_insert(teco_cmdline.str.data + teco_cmdline.effective_len, 1, error);
}
gboolean teco_cmdline_keypress_c(gchar key, GError **error);