aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmdline.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-08 02:21:36 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-11-08 02:21:36 +0100
commit0d01c262c0ed23ef950530c743b023e89ef4a821 (patch)
treecffd42ba85f3ef7ecf82193ce3302570507adede /cmdline.cpp
parent075d33912ac88aa288055ce2f4eff4273bce3d63 (diff)
downloadsciteco-0d01c262c0ed23ef950530c743b023e89ef4a821.tar.gz
support line termination ($$) as immediate editing command + some fixes
* separate function for immediate editing command processing * undo.clear() to remove and free all undo tokens without executing them * goto_table_clear() to remove and free all goto table entries
Diffstat (limited to 'cmdline.cpp')
-rw-r--r--cmdline.cpp62
1 files changed, 44 insertions, 18 deletions
diff --git a/cmdline.cpp b/cmdline.cpp
index e0159ec..b9c58a0 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -5,8 +5,10 @@
#include "sciteco.h"
#include "parser.h"
+#include "goto.h"
#include "undo.h"
+static inline const gchar *process_edit_cmd(gchar key);
static gchar *macro_echo(const gchar *macro, const gchar *prefix = "");
gchar *cmdline = NULL;
@@ -14,27 +16,14 @@ gchar *cmdline = NULL;
void
cmdline_keypress(gchar key)
{
- gchar insert[255] = "";
+ const gchar *insert;
gint old_cmdline_len = 0;
gchar *echo;
/*
* Process immediate editing commands
*/
- switch (key) {
- case '\b':
- if (!cmdline || !*cmdline)
- break;
- old_cmdline_len = strlen(cmdline);
-
- undo.pop(old_cmdline_len);
- cmdline[old_cmdline_len-1] = '\0';
- macro_pc--;
- break;
- default:
- insert[0] = key;
- insert[1] = '\0';
- }
+ insert = process_edit_cmd(key);
/*
* Parse/execute characters
@@ -44,12 +33,12 @@ cmdline_keypress(gchar key)
cmdline = (gchar *)g_realloc(cmdline, old_cmdline_len +
strlen(insert) + 1);
} else {
- cmdline = (gchar *)g_malloc(2);
+ cmdline = (gchar *)g_malloc(strlen(insert) + 1);
*cmdline = '\0';
}
- for (gchar *p = insert; *p; p++) {
- strcat(cmdline, (gchar[]){key, '\0'});
+ for (const gchar *p = insert; *p; p++) {
+ strcat(cmdline, (gchar[]){*p, '\0'});
if (!macro_execute(cmdline)) {
cmdline[old_cmdline_len] = '\0';
@@ -65,6 +54,43 @@ cmdline_keypress(gchar key)
g_free(echo);
}
+static inline const gchar *
+process_edit_cmd(gchar key)
+{
+ static gchar insert[255];
+ gint cmdline_len = cmdline ? strlen(cmdline) : 0;
+
+ insert[0] = '\0';
+
+ switch (key) {
+ case '\b':
+ if (cmdline_len) {
+ undo.pop(cmdline_len);
+ cmdline[cmdline_len - 1] = '\0';
+ macro_pc--;
+ }
+ break;
+
+ case '\x1B':
+ if (cmdline && cmdline[cmdline_len - 1] == '\x1B') {
+ /* TODO: exit if previously requested */
+
+ undo.clear();
+ goto_table_clear();
+
+ *cmdline = '\0';
+ macro_pc = 0;
+ break;
+ }
+ /* fall through */
+ default:
+ insert[0] = key;
+ insert[1] = '\0';
+ }
+
+ return insert;
+}
+
static gchar *
macro_echo(const gchar *macro, const gchar *prefix)
{