diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-08 02:21:36 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-11-08 02:21:36 +0100 |
commit | 0d01c262c0ed23ef950530c743b023e89ef4a821 (patch) | |
tree | cffd42ba85f3ef7ecf82193ce3302570507adede | |
parent | 075d33912ac88aa288055ce2f4eff4273bce3d63 (diff) | |
download | sciteco-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
-rw-r--r-- | cmdline.cpp | 62 | ||||
-rw-r--r-- | goto.cpp | 6 | ||||
-rw-r--r-- | goto.h | 2 | ||||
-rw-r--r-- | parser.cpp | 2 | ||||
-rw-r--r-- | undo.cpp | 11 | ||||
-rw-r--r-- | undo.h | 2 |
6 files changed, 66 insertions, 19 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) { @@ -160,6 +160,12 @@ public: static GotoTable table; +void +goto_table_clear(void) +{ + table.clear(); +} + StateLabel::StateLabel() : State() { transitions['\0'] = this; @@ -14,4 +14,6 @@ private: State *custom(gchar chr); }; +void goto_table_clear(void); + #endif @@ -460,7 +460,7 @@ StateControl::custom(gchar chr) #endif /* - * Alternatives: ^[, <CTRL/[> (cannot be typed), <ESC> + * Alternatives: ^[, <CTRL/[>, <ESC> */ case '[': BEGIN_EXEC(&states.start); @@ -47,6 +47,17 @@ UndoStack::pop(gint pos) } } +void +UndoStack::clear(void) +{ + UndoToken *cur; + + while ((cur = SLIST_FIRST(&head))) { + SLIST_REMOVE_HEAD(&head, tokens); + delete cur; + } +} + UndoStack::~UndoStack() { UndoToken *token, *next; @@ -124,6 +124,8 @@ public: } void pop(gint pos); + + void clear(void); } undo; #endif
\ No newline at end of file |