[gtksourceview/wip/chergert/vim: 289/363] allow checking for boundary before advancing
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 289/363] allow checking for boundary before advancing
- Date: Mon, 8 Nov 2021 19:53:54 +0000 (UTC)
commit ca1b0a200791f3dead7c9c4456dfaa51dde679f9
Author: Christian Hergert <chergert redhat com>
Date: Thu Nov 4 22:29:22 2021 -0700
allow checking for boundary before advancing
gtksourceview/vim/gtk-source-vim-text-object.c | 82 +++++++++++++++-----------
1 file changed, 48 insertions(+), 34 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-text-object.c b/gtksourceview/vim/gtk-source-vim-text-object.c
index 502e8a65..a0d10744 100644
--- a/gtksourceview/vim/gtk-source-vim-text-object.c
+++ b/gtksourceview/vim/gtk-source-vim-text-object.c
@@ -39,6 +39,8 @@ enum {
struct _GtkSourceVimTextObject
{
GtkSourceVimState parent_instance;
+ TextObjectMotion ends;
+ TextObjectMotion starts;
TextObjectMotion forward_end;
TextObjectMotion backward_start;
TextObjectExtend extend;
@@ -47,6 +49,12 @@ struct _GtkSourceVimTextObject
G_DEFINE_TYPE (GtkSourceVimTextObject, gtk_source_vim_text_object, GTK_SOURCE_TYPE_VIM_STATE)
+static gboolean
+gtk_source_vim_iter_always_false (GtkTextIter *iter)
+{
+ return FALSE;
+}
+
static inline gboolean
iter_isspace (const GtkTextIter *iter)
{
@@ -139,7 +147,9 @@ text_object_extend_sentence (const GtkTextIter *origin,
}
static GtkSourceVimState *
-gtk_source_vim_text_object_new (TextObjectMotion forward_end,
+gtk_source_vim_text_object_new (TextObjectMotion ends,
+ TextObjectMotion starts,
+ TextObjectMotion forward_end,
TextObjectMotion backward_start,
TextObjectExtend extend,
guint inner_or_a)
@@ -147,6 +157,8 @@ gtk_source_vim_text_object_new (TextObjectMotion forward_end,
GtkSourceVimTextObject *self;
self = g_object_new (GTK_SOURCE_TYPE_VIM_TEXT_OBJECT, NULL);
+ self->ends = ends;
+ self->starts = starts;
self->forward_end = forward_end;
self->backward_start = backward_start;
self->extend = extend;
@@ -155,39 +167,41 @@ gtk_source_vim_text_object_new (TextObjectMotion forward_end,
return GTK_SOURCE_VIM_STATE (self);
}
-#define TEXT_OBJECT_CTOR(name, forward, backward, extend, inner_or_a) \
-GtkSourceVimState * \
-gtk_source_vim_text_object_new_##name (void) \
-{ \
- return gtk_source_vim_text_object_new (gtk_source_vim_iter_##forward, \
- gtk_source_vim_iter_##backward, \
- text_object_extend_##extend, \
- TEXT_OBJECT_##inner_or_a); \
+#define TEXT_OBJECT_CTOR(name, ends, starts, forward, backward, extend, inner_or_a) \
+GtkSourceVimState * \
+gtk_source_vim_text_object_new_##name (void) \
+{ \
+ return gtk_source_vim_text_object_new (gtk_source_vim_iter_##ends, \
+ gtk_source_vim_iter_##starts, \
+ gtk_source_vim_iter_##forward, \
+ gtk_source_vim_iter_##backward, \
+ text_object_extend_##extend, \
+ TEXT_OBJECT_##inner_or_a); \
}
-TEXT_OBJECT_CTOR (inner_word, forward_word_end, backward_word_start, word, INNER);
-TEXT_OBJECT_CTOR (inner_WORD, forward_WORD_end, backward_WORD_start, word, INNER);
-TEXT_OBJECT_CTOR (inner_sentence, forward_sentence_end, backward_sentence_start, sentence, INNER);
-TEXT_OBJECT_CTOR (inner_paragraph, forward_paragraph_end, backward_paragraph_start, paragraph, INNER);
-TEXT_OBJECT_CTOR (inner_block_paren, forward_block_paren_end, backward_block_paren_start, one, INNER);
-TEXT_OBJECT_CTOR (inner_block_brace, forward_block_brace_end, backward_block_brace_start, one, INNER);
-TEXT_OBJECT_CTOR (inner_block_bracket, forward_block_bracket_end, backward_block_bracket_start, one, INNER);
-TEXT_OBJECT_CTOR (inner_block_lt_gt, forward_block_lt_gt_end, backward_block_lt_gt_start, one, INNER);
-TEXT_OBJECT_CTOR (inner_quote_double, forward_quote_double, backward_quote_double, one, INNER);
-TEXT_OBJECT_CTOR (inner_quote_single, forward_quote_single, backward_quote_single, one, INNER);
-TEXT_OBJECT_CTOR (inner_quote_grave, forward_quote_grave, backward_quote_grave, one, INNER);
-
-TEXT_OBJECT_CTOR (a_word, forward_word_end, backward_word_start, word, A);
-TEXT_OBJECT_CTOR (a_WORD, forward_WORD_end, backward_WORD_start, word, A);
-TEXT_OBJECT_CTOR (a_sentence, forward_sentence_end, backward_sentence_start, sentence, A);
-TEXT_OBJECT_CTOR (a_paragraph, forward_paragraph_end, backward_paragraph_start, paragraph, A);
-TEXT_OBJECT_CTOR (a_block_paren, forward_block_paren_end, backward_block_paren_start, one, A);
-TEXT_OBJECT_CTOR (a_block_brace, forward_block_brace_end, backward_block_brace_start, one, A);
-TEXT_OBJECT_CTOR (a_block_bracket, forward_block_bracket_end, backward_block_bracket_start, one, A);
-TEXT_OBJECT_CTOR (a_block_lt_gt, forward_block_lt_gt_end, backward_block_lt_gt_start, one, A);
-TEXT_OBJECT_CTOR (a_quote_double, forward_quote_double, backward_quote_double, one, A);
-TEXT_OBJECT_CTOR (a_quote_single, forward_quote_single, backward_quote_single, one, A);
-TEXT_OBJECT_CTOR (a_quote_grave, forward_quote_grave, backward_quote_grave, one, A);
+TEXT_OBJECT_CTOR (inner_word, ends_word, starts_word, forward_word_end, backward_word_start, word, INNER);
+TEXT_OBJECT_CTOR (inner_WORD, always_false, starts_WORD, forward_WORD_end, backward_WORD_start, word, INNER);
+TEXT_OBJECT_CTOR (inner_sentence, always_false, always_false, forward_sentence_end, backward_sentence_start,
sentence, INNER);
+TEXT_OBJECT_CTOR (inner_paragraph, always_false, always_false, forward_paragraph_end,
backward_paragraph_start, paragraph, INNER);
+TEXT_OBJECT_CTOR (inner_block_paren, always_false, always_false, forward_block_paren_end,
backward_block_paren_start, one, INNER);
+TEXT_OBJECT_CTOR (inner_block_brace, always_false, always_false, forward_block_brace_end,
backward_block_brace_start, one, INNER);
+TEXT_OBJECT_CTOR (inner_block_bracket, always_false, always_false, forward_block_bracket_end,
backward_block_bracket_start, one, INNER);
+TEXT_OBJECT_CTOR (inner_block_lt_gt, always_false, always_false, forward_block_lt_gt_end,
backward_block_lt_gt_start, one, INNER);
+TEXT_OBJECT_CTOR (inner_quote_double, always_false, always_false, forward_quote_double,
backward_quote_double, one, INNER);
+TEXT_OBJECT_CTOR (inner_quote_single, always_false, always_false, forward_quote_single,
backward_quote_single, one, INNER);
+TEXT_OBJECT_CTOR (inner_quote_grave, always_false, always_false, forward_quote_grave, backward_quote_grave,
one, INNER);
+
+TEXT_OBJECT_CTOR (a_word, ends_word, starts_word, forward_word_end, backward_word_start, word, A);
+TEXT_OBJECT_CTOR (a_WORD, ends_WORD, starts_WORD, forward_WORD_end, backward_WORD_start, word, A);
+TEXT_OBJECT_CTOR (a_sentence, always_false, always_false, forward_sentence_end, backward_sentence_start,
sentence, A);
+TEXT_OBJECT_CTOR (a_paragraph, always_false, always_false, forward_paragraph_end, backward_paragraph_start,
paragraph, A);
+TEXT_OBJECT_CTOR (a_block_paren, always_false, always_false, forward_block_paren_end,
backward_block_paren_start, one, A);
+TEXT_OBJECT_CTOR (a_block_brace, always_false, always_false, forward_block_brace_end,
backward_block_brace_start, one, A);
+TEXT_OBJECT_CTOR (a_block_bracket, always_false, always_false, forward_block_bracket_end,
backward_block_bracket_start, one, A);
+TEXT_OBJECT_CTOR (a_block_lt_gt, always_false, always_false, forward_block_lt_gt_end,
backward_block_lt_gt_start, one, A);
+TEXT_OBJECT_CTOR (a_quote_double, always_false, always_false, forward_quote_double, backward_quote_double,
one, A);
+TEXT_OBJECT_CTOR (a_quote_single, always_false, always_false, forward_quote_single, backward_quote_single,
one, A);
+TEXT_OBJECT_CTOR (a_quote_grave, always_false, always_false, forward_quote_grave, backward_quote_grave, one,
A);
#undef TEXT_OBJECT_CTOR
@@ -229,11 +243,11 @@ gtk_source_vim_text_object_select (GtkSourceVimTextObject *self,
g_return_val_if_fail (self->extend != NULL, FALSE);
inner_end = *begin;
- if (!self->forward_end (&inner_end))
+ if (!self->ends (&inner_end) && !self->forward_end (&inner_end))
return FALSE;
inner_begin = inner_end;
- if (!self->backward_start (&inner_begin))
+ if (!self->starts (&inner_begin) && !self->backward_start (&inner_begin))
return FALSE;
a_begin = inner_begin;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]