gboolean gb_vim_execute (GtkWidget *active_widget, const gchar *line, GError **error) { g_autofree gchar *name_slice = NULL; const GbVimCommand *command; const gchar *command_name = line; const gchar *options; g_autofree gchar *all_options = NULL; gboolean result; g_return_val_if_fail (GTK_IS_WIDGET (active_widget), FALSE); g_return_val_if_fail (line, FALSE); for (options = line; *options; options = g_utf8_next_char (options)) { gunichar ch; ch = g_utf8_get_char (options); if (g_unichar_isspace (ch)) break; } if (g_unichar_isspace (g_utf8_get_char (options))) { command_name = name_slice = g_strndup (line, options - line); options = g_utf8_next_char (options); } command = lookup_command (command_name); if (command == NULL) { if (looks_like_search_and_replace (line)) return gb_vim_command_search (active_widget, line, "", error); g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_FOUND, _("Not a command: %s"), command_name); return FALSE; } if (command->options_sup) all_options = g_strconcat (options, " ", command->options_sup, NULL); else all_options = g_strdup (options); result = command->func (active_widget, command_name, all_options, error); g_free (command->options_sup); return result; }
gboolean gb_vim_execute (GtkSourceView *source_view, const gchar *line, GError **error) { GtkTextBuffer *buffer; g_autofree gchar *name_slice = NULL; const GbVimCommand *command; const gchar *command_name = line; const gchar *options; g_autofree gchar *all_options = NULL; gboolean result; g_return_val_if_fail (GTK_SOURCE_IS_VIEW (source_view), FALSE); g_return_val_if_fail (line, FALSE); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view)); if (!GTK_SOURCE_IS_BUFFER (buffer)) { g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_SOURCE_VIEW, _("vim mode requires GtkSourceView")); return FALSE; } for (options = line; *options; options = g_utf8_next_char (options)) { gunichar ch; ch = g_utf8_get_char (options); if (g_unichar_isspace (ch)) break; } if (g_unichar_isspace (g_utf8_get_char (options))) { command_name = name_slice = g_strndup (line, options - line); options = g_utf8_next_char (options); } command = lookup_command (command_name); if (command == NULL) { if (looks_like_search_and_replace (line)) return gb_vim_command_search (source_view, line, "", error); g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_FOUND, _("Not an editor command: %s"), command_name); return FALSE; } if (command->options_sup) all_options = g_strconcat (options, " ", command->options_sup, NULL); else all_options = g_strdup (options); result = command->func (source_view, command_name, all_options, error); g_free (command->options_sup); return result; }