static const GbVimCommand * lookup_command (const gchar *name, gchar **options_sup) { static GbVimCommand line_command = { "__line__", gb_vim_jump_to_line }; gint line; gsize i; g_assert (name); g_assert (options_sup); *options_sup = NULL; for (i = 0; vim_commands [i].name; i++) { if (g_str_has_prefix (vim_commands [i].name, name)) return &vim_commands [i]; } if (g_ascii_isdigit (*name) && int32_parse (&line, name, 0, G_MAXINT32, "line", NULL)) { *options_sup = g_strdup (name); return &line_command; } return NULL; }
static gboolean gb_vim_jump_to_line (GtkSourceView *source_view, const gchar *command, const gchar *options, GError **error) { GtkTextBuffer *buffer; gboolean extend_selection; gint line; if (!IDE_IS_SOURCE_VIEW (source_view)) return TRUE; if (!int32_parse (&line, options, 0, G_MAXINT32, "line number", error)) return FALSE; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view)); extend_selection = gtk_text_buffer_get_has_selection (buffer); ide_source_view_set_count (IDE_SOURCE_VIEW (source_view), line); g_signal_emit_by_name (source_view, "movement", IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE, extend_selection, TRUE, TRUE); g_signal_emit_by_name (source_view, "save-insert-mark"); return TRUE; }
static gboolean gb_vim_jump_to_line (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { g_assert (GTK_IS_WIDGET (active_widget)); if (IDE_IS_EDITOR_VIEW (active_widget)) { GtkSourceView *source_view = GTK_SOURCE_VIEW (IDE_EDITOR_VIEW (active_widget)->frame1->source_view); GtkTextBuffer *buffer; gboolean extend_selection; gint line; if (!int32_parse (&line, options, 0, G_MAXINT32, "line number", error)) return FALSE; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view)); extend_selection = gtk_text_buffer_get_has_selection (buffer); ide_source_view_set_count (IDE_SOURCE_VIEW (source_view), line); if (line == 0) { GtkTextIter iter; /* * Zero is not a valid line number, and IdeSourceView treats * that as a move to the end of the buffer. Instead, we want * line 1 to be like vi/vim. */ gtk_text_buffer_get_start_iter (buffer, &iter); gtk_text_buffer_select_range (buffer, &iter, &iter); gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (source_view), gtk_text_buffer_get_insert (buffer), 0.0, FALSE, 0.0, 0.0); } else { g_signal_emit_by_name (source_view, "movement", IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE, extend_selection, TRUE, TRUE); } ide_source_view_set_count (IDE_SOURCE_VIEW (source_view), 0); g_signal_emit_by_name (source_view, "save-insert-mark"); return TRUE; } else return gb_vim_set_source_view_error (error); }
static gboolean gb_vim_set_tabstop (GtkSourceView *source_view, const gchar *key, const gchar *value, GError **error) { gint tabstop = 0; if (!int32_parse (&tabstop , value, 1, 32, "tab stop", error)) return FALSE; g_object_set (source_view, "tab-width", tabstop, NULL); return TRUE; }
static gboolean gb_vim_set_scrolloff (GtkSourceView *source_view, const gchar *key, const gchar *value, GError **error) { gint scroll_offset = 0; if (!int32_parse (&scroll_offset, value, 0, G_MAXINT32, "scroll size", error)) return FALSE; if (IDE_IS_SOURCE_VIEW (source_view)) g_object_set (source_view, "scroll-offset", scroll_offset, NULL); return TRUE; }
static gboolean gb_vim_set_shiftwidth (GtkSourceView *source_view, const gchar *key, const gchar *value, GError **error) { gint shiftwidth = 0; if (!int32_parse (&shiftwidth, value, 0, G_MAXINT32, "shift width", error)) return FALSE; if (shiftwidth == 0) shiftwidth = -1; g_object_set (source_view, "indent-width", shiftwidth, NULL); return TRUE; }