[gnome-builder] vim: add support for "edit filename"
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: add support for "edit filename"
- Date: Mon, 19 Jan 2015 11:34:46 +0000 (UTC)
commit 5e0ebaaad37a7c00a48d04a493ee93da308a16a5
Author: Christian Hergert <christian hergert me>
Date: Mon Jan 19 03:31:58 2015 -0800
vim: add support for "edit filename"
You can also use the alias 'e'. This open's a new buffer, which is
slightly different than VIM, but reasonable in this case.
https://bugzilla.gnome.org/show_bug.cgi?id=743021
src/commands/gb-command-vim-provider.c | 7 +++--
src/editor/gb-editor-frame.c | 22 +++++++++++++++++++++
src/vim/gb-source-vim.c | 33 ++++++++++++++++++++++++++++++++
src/vim/gb-source-vim.h | 3 +-
4 files changed, 61 insertions(+), 4 deletions(-)
---
diff --git a/src/commands/gb-command-vim-provider.c b/src/commands/gb-command-vim-provider.c
index 9f6ddfe..0cc1b76 100644
--- a/src/commands/gb-command-vim-provider.c
+++ b/src/commands/gb-command-vim-provider.c
@@ -147,11 +147,12 @@ static void
gb_command_vim_provider_init (GbCommandVimProvider *self)
{
static const gchar *commands[] = {
- "set ",
"colorscheme ",
- "syntax ",
- "sort",
+ "edit",
"nohl",
+ "set ",
+ "sort",
+ "syntax ",
NULL
};
GSettings *settings;
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index e9244ce..4feff02 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -1076,6 +1076,23 @@ gb_editor_frame_on_execute_command (GbEditorFrame *self,
}
static void
+gb_editor_frame_on_switch_to_file (GbEditorFrame *self,
+ GFile *file,
+ GbSourceVim *vim)
+{
+ GbWorkspace *workspace;
+ GbWorkbench *workbench;
+
+ g_return_if_fail (GB_IS_EDITOR_FRAME (self));
+ g_return_if_fail (G_IS_FILE (file));
+ g_return_if_fail (GB_IS_SOURCE_VIM (vim));
+
+ workbench = gb_widget_get_workbench (GTK_WIDGET (self));
+ workspace = gb_workbench_get_workspace (workbench, GB_TYPE_EDITOR_WORKSPACE);
+ gb_editor_workspace_open (GB_EDITOR_WORKSPACE (workspace), file);
+}
+
+static void
gb_editor_frame_on_command_toggled (GbEditorFrame *self,
gboolean visible,
GbSourceVim *vim)
@@ -1501,6 +1518,11 @@ gb_editor_frame_constructed (GObject *object)
G_CALLBACK (gb_editor_frame_on_execute_command),
self,
G_CONNECT_SWAPPED | G_CONNECT_AFTER);
+ g_signal_connect_object (vim,
+ "switch-to-file",
+ G_CALLBACK (gb_editor_frame_on_switch_to_file),
+ self,
+ G_CONNECT_SWAPPED);
g_signal_connect_object (priv->source_view,
"display-documentation",
diff --git a/src/vim/gb-source-vim.c b/src/vim/gb-source-vim.c
index 7652632..99e17d3 100644
--- a/src/vim/gb-source-vim.c
+++ b/src/vim/gb-source-vim.c
@@ -198,6 +198,7 @@ enum
COMMAND_VISIBILITY_TOGGLED,
EXECUTE_COMMAND,
JUMP_TO_DOC,
+ SWITCH_TO_FILE,
LAST_SIGNAL
};
@@ -4036,6 +4037,23 @@ gb_source_vim_op_set (GbSourceVim *vim,
g_strfreev (parts);
}
+static void
+gb_source_vim_op_edit (GbSourceVim *vim,
+ const gchar *command_text)
+{
+ const gchar *path;
+ GFile *file;
+
+ g_return_if_fail (GB_IS_SOURCE_VIM (vim));
+ g_return_if_fail (g_str_has_prefix (command_text, "e ") ||
+ g_str_has_prefix (command_text, "edit "));
+
+ path = strstr (command_text, " ") + 1;
+ file = g_file_new_for_path (path);
+ g_signal_emit (vim, gSignals [SWITCH_TO_FILE], 0, file);
+ g_clear_object (&file);
+}
+
static GbSourceVimOperation
gb_source_vim_parse_operation (const gchar *command_text)
{
@@ -4049,6 +4067,9 @@ gb_source_vim_parse_operation (const gchar *command_text)
if (g_str_equal (command_text, "sort"))
ret = gb_source_vim_op_sort;
+ else if (g_str_has_prefix (command_text, "edit ") ||
+ g_str_has_prefix (command_text, "e "))
+ ret = gb_source_vim_op_edit;
else if (g_str_equal (command_text, "nohl"))
ret = gb_source_vim_op_nohl;
else if (g_str_has_prefix (command_text, "set "))
@@ -5262,6 +5283,18 @@ gb_source_vim_class_init (GbSourceVimClass *klass)
1,
G_TYPE_STRING);
+ gSignals [SWITCH_TO_FILE] =
+ g_signal_new ("switch-to-file",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GbSourceVimClass, switch_to_file),
+ NULL,
+ NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_FILE);
+
/*
* Register all of our internal VIM commands. These can be used directly
* or via phrases.
diff --git a/src/vim/gb-source-vim.h b/src/vim/gb-source-vim.h
index 560fbe3..6721225 100644
--- a/src/vim/gb-source-vim.h
+++ b/src/vim/gb-source-vim.h
@@ -63,12 +63,13 @@ struct _GbSourceVimClass
const gchar *command);
void (*jump_to_doc) (GbSourceVim *vim,
const gchar *search_text);
+ void (*switch_to_file) (GbSourceVim *vim,
+ GFile *file);
gpointer _padding1;
gpointer _padding2;
gpointer _padding3;
gpointer _padding4;
- gpointer _padding5;
};
GType gb_source_vim_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]