[gtksourceview/wip/chergert/vim] add sorted command list so we can parse/filter them
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] add sorted command list so we can parse/filter them
- Date: Fri, 5 Nov 2021 16:41:08 +0000 (UTC)
commit d536b5deaa8462031e5d31cb67254e5b67e62a62
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 5 09:41:02 2021 -0700
add sorted command list so we can parse/filter them
gtksourceview/vim/gtk-source-vim-command.c | 35 +++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index 3e1bdb31..967d69e0 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -58,6 +58,7 @@ enum {
static GParamSpec *properties[N_PROPS];
static GHashTable *commands;
+static GPtrArray *commands_sorted;
static void
gtk_source_vim_command_format (GtkSourceVimCommand *self)
@@ -660,6 +661,22 @@ gtk_source_vim_command_resume (GtkSourceVimState *state,
}
}
+static int
+sort_longest_first (gconstpointer a,
+ gconstpointer b)
+{
+ const char * const *astr = a;
+ const char * const *bstr = b;
+ int lena = strlen (*astr);
+ int lenb = strlen (*bstr);
+
+ if (lena > lenb)
+ return -1;
+ else if (lena < lenb)
+ return 1;
+ return 0;
+}
+
static void
gtk_source_vim_command_dispose (GObject *object)
{
@@ -767,9 +784,13 @@ gtk_source_vim_command_class_init (GtkSourceVimCommandClass *klass)
g_object_class_install_properties (object_class, N_PROPS, properties);
commands = g_hash_table_new (g_str_hash, g_str_equal);
+ commands_sorted = g_ptr_array_new ();
#define ADD_COMMAND(name, func) \
- g_hash_table_insert(commands, (char*)name, (gpointer)func)
+ G_STMT_START { \
+ g_hash_table_insert(commands, (char*)name, (gpointer)func); \
+ g_ptr_array_add (commands_sorted, (char *)name); \
+ } G_STMT_END
ADD_COMMAND (":delete", gtk_source_vim_command_delete);
ADD_COMMAND (":join", gtk_source_vim_command_join);
ADD_COMMAND (":j", gtk_source_vim_command_join);
@@ -789,6 +810,8 @@ gtk_source_vim_command_class_init (GtkSourceVimCommandClass *klass)
ADD_COMMAND ("unindent", gtk_source_vim_command_unindent);
ADD_COMMAND ("format", gtk_source_vim_command_format);
#undef ADD_COMMAND
+
+ g_ptr_array_sort (commands_sorted, sort_longest_first);
}
static void
@@ -860,3 +883,13 @@ gtk_source_vim_command_set_text_object (GtkSourceVimCommand *self,
g_set_object (&self->text_object, text_object);
}
+
+GtkSourceVimState *
+gtk_source_vim_command_new_parsed (const char *command_line)
+{
+ GtkSourceVimCommand *ret = NULL;
+
+ g_return_val_if_fail (command_line != NULL, NULL);
+
+ return GTK_SOURCE_VIM_STATE (ret);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]