aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cmdline.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-01-30 19:47:06 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-02-03 18:48:04 +0100
commit8816b7c7aded7ef8defca0bc6a78b2f5887faea6 (patch)
treef125e81fa8433da2f3ebd5af7b0d17d2a540cb67 /src/cmdline.cpp
parent1d768b53295d71705fd1618f936240ed5428cb87 (diff)
downloadsciteco-8816b7c7aded7ef8defca0bc6a78b2f5887faea6.tar.gz
first draft of commandline-editing commands ({ and } as in VideoTECO)
* simplified traditional commandline editing. no need to extend cmdline string one character at a time when inserting multiple. instead there's a marker (cmdline_pos) specifying the macro length to execute in a "step" and also the anchor for generating undo tokens * implementation does not yet work in macro calls * while editing the commandline, other buffers/registers may not be edited (need push-down-list and auxiliary q-register)
Diffstat (limited to 'src/cmdline.cpp')
-rw-r--r--src/cmdline.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/cmdline.cpp b/src/cmdline.cpp
index 4d9cfd6..6e4c9d3 100644
--- a/src/cmdline.cpp
+++ b/src/cmdline.cpp
@@ -49,6 +49,7 @@ static const gchar *last_occurrence(const gchar *str,
static inline gboolean filename_is_dir(const gchar *filename);
gchar *cmdline = NULL;
+gint cmdline_pos = 0;
static gchar *last_cmdline = NULL;
bool quit_requested = false;
@@ -60,7 +61,6 @@ namespace States {
void
cmdline_keypress(gchar key)
{
- gchar *cmdline_p;
const gchar *insert;
gchar *echo;
@@ -76,28 +76,15 @@ cmdline_keypress(gchar key)
insert = process_edit_cmd(key);
/*
- * Parse/execute characters
- */
- if (cmdline) {
- gint len = strlen(cmdline);
- cmdline = (gchar *)g_realloc(cmdline, len + strlen(insert) + 1);
- cmdline_p = cmdline + len;
- } else {
- cmdline = (gchar *)g_malloc(strlen(insert) + 1);
- *cmdline = '\0';
- cmdline_p = cmdline;
- }
-
- /*
- * Execute one insertion character, extending cmdline, at a time so
+ * Parse/execute characters, one at a time so
* undo tokens get emitted for the corresponding characters.
*/
- for (const gchar *p = insert; *p; p++) {
- *cmdline_p++ = *p;
- *cmdline_p = '\0';
+ cmdline_pos = cmdline ? strlen(cmdline)+1 : 1;
+ String::append(cmdline, insert);
+ while (cmdline_pos <= (gint)strlen(cmdline)) {
try {
- Execute::step(cmdline);
+ Execute::step((const gchar *&)cmdline, cmdline_pos);
} catch (...) {
/*
* Undo tokens may have been emitted (or had to be)
@@ -105,12 +92,14 @@ cmdline_keypress(gchar key)
* executed so as if the character had never been
* inserted.
*/
- undo.pop(cmdline_p - cmdline);
- cmdline_p[-1] = '\0';
+ undo.pop(cmdline_pos);
+ cmdline[cmdline_pos-1] = '\0';
/* program counter could be messed up */
- macro_pc = cmdline_p - cmdline - 1;
+ macro_pc = cmdline_pos - 1;
break;
}
+
+ cmdline_pos++;
}
/*