[gtksourceview/wip/chergert/vim] incremental commandbar/command work
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] incremental commandbar/command work
- Date: Sun, 7 Nov 2021 22:00:21 +0000 (UTC)
commit d5e4be99dc61fb692b8da4b6b62b04f963f6acac
Author: Christian Hergert <chergert redhat com>
Date: Sun Nov 7 14:00:16 2021 -0800
incremental commandbar/command work
gtksourceview/vim/gtk-source-vim-command.c | 109 ++++++++++++++++++++++++++---
gtksourceview/vim/gtk-source-vim-command.h | 3 +-
gtksourceview/vim/gtk-source-vim.c | 5 +-
3 files changed, 106 insertions(+), 11 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index d657b6e8..f5368e07 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -951,29 +951,122 @@ gtk_source_vim_command_set_text_object (GtkSourceVimCommand *self,
gtk_source_vim_state_reparent (text_object, self, &self->text_object);
}
+static gboolean
+parse_mark_range (GtkSourceVimState *current,
+ const char **cmdline_inout,
+ GtkTextIter *begin,
+ GtkTextIter *end)
+{
+ GtkSourceBuffer *buffer = gtk_source_vim_state_get_buffer (current, NULL, NULL);
+ const char *cmdline = *cmdline_inout;
+ gunichar mark1 = 0;
+ gunichar mark2 = 0;
+ char str[16];
+
+ if (cmdline[0] == '%')
+ {
+ gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (buffer), begin, end);
+ *cmdline_inout = ++cmdline;
+ return TRUE;
+ }
+
+ /* Look for something like '<,'> */
+ if (*cmdline == '\'')
+ {
+ ++cmdline;
+ mark1 = *cmdline;
+ if (!mark1)
+ return FALSE;
+
+ ++cmdline;
+ if (*cmdline != ',')
+ return FALSE;
+
+ ++cmdline;
+ if (*cmdline != '\'')
+ return FALSE;
+
+ ++cmdline;
+ mark2 = *cmdline;
+ if (!mark2)
+ return FALSE;
+
+ str[g_unichar_to_utf8 (mark1, str)] = 0;
+ gtk_source_vim_state_get_iter_at_mark (current, str, begin);
+
+ str[g_unichar_to_utf8 (mark2, str)] = 0;
+ gtk_source_vim_state_get_iter_at_mark (current, str, end);
+
+ *cmdline_inout = cmdline;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
GtkSourceVimState *
-gtk_source_vim_command_new_parsed (const char *command_line)
+gtk_source_vim_command_new_parsed (GtkSourceVimState *current,
+ const char *command_line)
{
GtkSourceVimCommand *ret = NULL;
GtkSourceVimCommandClass *klass;
+ GtkTextIter begin;
+ GtkTextIter end;
g_return_val_if_fail (command_line != NULL, NULL);
+ g_return_val_if_fail (GTK_SOURCE_IS_VIM_STATE (current), NULL);
- /* ensure class_init called */
klass = g_type_class_ref (GTK_SOURCE_TYPE_VIM_COMMAND);
- /* TODO: create a real parser for this stuff */
+ if (g_hash_table_contains (commands, command_line))
+ {
+ ret = GTK_SOURCE_VIM_COMMAND (gtk_source_vim_command_new (command_line));
+ goto finish;
+ }
- if (g_str_has_prefix (command_line, ":colorscheme "))
+ if (*command_line == ':')
{
- ret = GTK_SOURCE_VIM_COMMAND (gtk_source_vim_command_new (":colorscheme"));
- ret->options = g_strdup (command_line + strlen (":colorscheme"));
+ command_line++;
}
- else if (g_hash_table_contains (commands, command_line))
+
+ if (parse_mark_range (current, &command_line, &begin, &end))
{
- ret = GTK_SOURCE_VIM_COMMAND (gtk_source_vim_command_new (command_line));
+ g_print ("Working within a range\n");
+ }
+
+ if (strchr (command_line, ' '))
+ {
+ char **split = g_strsplit (command_line, " ", 2);
+ char *name = g_strdup_printf (":%s", split[0]);
+
+ if (g_hash_table_contains (commands, name))
+ {
+ ret = GTK_SOURCE_VIM_COMMAND (gtk_source_vim_command_new (name));
+ ret->options = g_strdup (split[1]);
+ }
+
+ g_strfreev (split);
+ g_free (name);
+
+ goto finish;
+ }
+ else if (*command_line == '/')
+ {
+ ret = GTK_SOURCE_VIM_COMMAND (gtk_source_vim_command_new ("search"));
+ ret->options = g_strdup (command_line+1);
+
+ goto finish;
+ }
+ else if (*command_line == 's')
+ {
+ ret = GTK_SOURCE_VIM_COMMAND (gtk_source_vim_command_new ("search-and-replace"));
+ ret->options = g_strdup (command_line+1);
+
+ goto finish;
}
+finish:
g_type_class_unref (klass);
return GTK_SOURCE_VIM_STATE (ret);
diff --git a/gtksourceview/vim/gtk-source-vim-command.h b/gtksourceview/vim/gtk-source-vim-command.h
index 3ba2c86a..038e4a32 100644
--- a/gtksourceview/vim/gtk-source-vim-command.h
+++ b/gtksourceview/vim/gtk-source-vim-command.h
@@ -32,7 +32,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GtkSourceVimCommand, gtk_source_vim_command, GTK_SOURCE, VIM_COMMAND,
GtkSourceVimState)
GtkSourceVimState *gtk_source_vim_command_new (const char *command);
-GtkSourceVimState *gtk_source_vim_command_new_parsed (const char *command_line);
+GtkSourceVimState *gtk_source_vim_command_new_parsed (GtkSourceVimState *current,
+ const char *command_line);
const char *gtk_source_vim_command_get_command (GtkSourceVimCommand *self);
void gtk_source_vim_command_set_motion (GtkSourceVimCommand *self,
GtkSourceVimMotion *motion);
diff --git a/gtksourceview/vim/gtk-source-vim.c b/gtksourceview/vim/gtk-source-vim.c
index 140a4286..0bcc4566 100644
--- a/gtksourceview/vim/gtk-source-vim.c
+++ b/gtksourceview/vim/gtk-source-vim.c
@@ -76,15 +76,16 @@ gtk_source_vim_real_execute_command (GtkSourceVim *self,
const char *command)
{
GtkSourceVimState *new_state;
+ GtkSourceVimState *current;
g_assert (GTK_SOURCE_IS_VIM (self));
g_assert (command != NULL);
- new_state = gtk_source_vim_command_new_parsed (command);
+ current = gtk_source_vim_state_get_current (GTK_SOURCE_VIM_STATE (self));
+ new_state = gtk_source_vim_command_new_parsed (current, command);
if (new_state != NULL)
{
- GtkSourceVimState *current = gtk_source_vim_state_get_current (GTK_SOURCE_VIM_STATE (self));
gtk_source_vim_state_set_parent (new_state, current);
gtk_source_vim_state_repeat (new_state);
gtk_source_vim_state_unparent (new_state);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]