[gtksourceview/wip/chergert/vim] track linewise text objects



commit c06023ff4496c94a583d7d64c570ffbb32349a87
Author: Christian Hergert <chergert redhat com>
Date:   Sat Nov 6 18:26:47 2021 -0700

    track linewise text objects

 gtksourceview/vim/gtk-source-vim-text-object.c | 82 +++++++++++++++-----------
 gtksourceview/vim/gtk-source-vim-text-object.h |  1 +
 2 files changed, 49 insertions(+), 34 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-text-object.c b/gtksourceview/vim/gtk-source-vim-text-object.c
index 590dd138..b5fa00fc 100644
--- a/gtksourceview/vim/gtk-source-vim-text-object.c
+++ b/gtksourceview/vim/gtk-source-vim-text-object.c
@@ -41,12 +41,15 @@ enum {
 struct _GtkSourceVimTextObject
 {
        GtkSourceVimState parent_instance;
+
        TextObjectCheck   ends;
        TextObjectCheck   starts;
        TextObjectMotion  forward_end;
        TextObjectMotion  backward_start;
        TextObjectExtend  extend;
+
        guint             inner_or_a : 1;
+       guint             is_linewise : 1;
 };
 
 G_DEFINE_TYPE (GtkSourceVimTextObject, gtk_source_vim_text_object, GTK_SOURCE_TYPE_VIM_STATE)
@@ -414,7 +417,8 @@ gtk_source_vim_text_object_new (TextObjectCheck  ends,
                                 TextObjectMotion forward_end,
                                 TextObjectMotion backward_start,
                                 TextObjectExtend extend,
-                                guint            inner_or_a)
+                                guint            inner_or_a,
+                                gboolean         is_linewise)
 {
        GtkSourceVimTextObject *self;
 
@@ -425,45 +429,47 @@ gtk_source_vim_text_object_new (TextObjectCheck  ends,
        self->backward_start = backward_start;
        self->extend = extend;
        self->inner_or_a = inner_or_a;
+       self->is_linewise = !!is_linewise;
 
        return GTK_SOURCE_VIM_STATE (self);
 }
 
-#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);           \
+#define TEXT_OBJECT_CTOR(name, ends, starts, forward, backward, extend, inner_or_a, linewise) \
+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,                      \
+                                              linewise);                                     \
 }
 
-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, ends_sentence, always_false, _forward_sentence_end, 
backward_sentence_start, sentence, INNER);
-TEXT_OBJECT_CTOR (inner_paragraph, is_paragraph_break, is_paragraph_break, _forward_paragraph_end, 
_backward_paragraph_start, paragraph, INNER);
-TEXT_OBJECT_CTOR (inner_block_paren, ends_paren, starts_paren, forward_block_paren_end, 
backward_block_paren_start, one, INNER);
-TEXT_OBJECT_CTOR (inner_block_brace, ends_brace, starts_brace, forward_block_brace_end, 
backward_block_brace_start, one, INNER);
-TEXT_OBJECT_CTOR (inner_block_bracket, ends_bracket, starts_bracket, forward_block_bracket_end, 
backward_block_bracket_start, one, INNER);
-TEXT_OBJECT_CTOR (inner_block_lt_gt, ends_lt_gt, starts_lt_gt, forward_block_lt_gt_end, 
backward_block_lt_gt_start, one, INNER);
-TEXT_OBJECT_CTOR (inner_quote_double, ends_quote_double, always_false, forward_quote_double, 
backward_quote_double, one, INNER);
-TEXT_OBJECT_CTOR (inner_quote_single, ends_quote_single, always_false, forward_quote_single, 
backward_quote_single, one, INNER);
-TEXT_OBJECT_CTOR (inner_quote_grave, ends_quote_grave, 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, ends_sentence, always_false, _forward_sentence_end, backward_sentence_start, 
sentence, A);
-TEXT_OBJECT_CTOR (a_paragraph, is_paragraph_break, is_paragraph_break, _forward_paragraph_end, 
_backward_paragraph_start, paragraph, A);
-TEXT_OBJECT_CTOR (a_block_paren, ends_paren, starts_paren, forward_block_paren_end, 
backward_block_paren_start, one, A);
-TEXT_OBJECT_CTOR (a_block_brace, ends_brace, starts_brace, forward_block_brace_end, 
backward_block_brace_start, one, A);
-TEXT_OBJECT_CTOR (a_block_bracket, ends_bracket, starts_bracket, forward_block_bracket_end, 
backward_block_bracket_start, one, A);
-TEXT_OBJECT_CTOR (a_block_lt_gt, ends_lt_gt, starts_lt_gt, forward_block_lt_gt_end, 
backward_block_lt_gt_start, one, A);
-TEXT_OBJECT_CTOR (a_quote_double, ends_quote_double, always_false, forward_quote_double, 
backward_quote_double, one, A);
-TEXT_OBJECT_CTOR (a_quote_single, ends_quote_single, always_false, forward_quote_single, 
backward_quote_single, one, A);
-TEXT_OBJECT_CTOR (a_quote_grave, ends_quote_grave, always_false, 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, 
FALSE);
+TEXT_OBJECT_CTOR (inner_WORD, always_false, starts_WORD, forward_WORD_end, backward_WORD_start, word, INNER, 
FALSE);
+TEXT_OBJECT_CTOR (inner_sentence, ends_sentence, always_false, _forward_sentence_end, 
backward_sentence_start, sentence, INNER, FALSE);
+TEXT_OBJECT_CTOR (inner_paragraph, is_paragraph_break, is_paragraph_break, _forward_paragraph_end, 
_backward_paragraph_start, paragraph, INNER, TRUE);
+TEXT_OBJECT_CTOR (inner_block_paren, ends_paren, starts_paren, forward_block_paren_end, 
backward_block_paren_start, one, INNER, FALSE);
+TEXT_OBJECT_CTOR (inner_block_brace, ends_brace, starts_brace, forward_block_brace_end, 
backward_block_brace_start, one, INNER, FALSE);
+TEXT_OBJECT_CTOR (inner_block_bracket, ends_bracket, starts_bracket, forward_block_bracket_end, 
backward_block_bracket_start, one, INNER, FALSE);
+TEXT_OBJECT_CTOR (inner_block_lt_gt, ends_lt_gt, starts_lt_gt, forward_block_lt_gt_end, 
backward_block_lt_gt_start, one, INNER, FALSE);
+TEXT_OBJECT_CTOR (inner_quote_double, ends_quote_double, always_false, forward_quote_double, 
backward_quote_double, one, INNER, FALSE);
+TEXT_OBJECT_CTOR (inner_quote_single, ends_quote_single, always_false, forward_quote_single, 
backward_quote_single, one, INNER, FALSE);
+TEXT_OBJECT_CTOR (inner_quote_grave, ends_quote_grave, always_false, forward_quote_grave, 
backward_quote_grave, one, INNER, FALSE);
+
+TEXT_OBJECT_CTOR (a_word, ends_word, starts_word, forward_word_end, backward_word_start, word, A, FALSE);
+TEXT_OBJECT_CTOR (a_WORD, ends_WORD, starts_WORD, forward_WORD_end, backward_WORD_start, word, A, FALSE);
+TEXT_OBJECT_CTOR (a_sentence, ends_sentence, always_false, _forward_sentence_end, backward_sentence_start, 
sentence, A, FALSE);
+TEXT_OBJECT_CTOR (a_paragraph, is_paragraph_break, is_paragraph_break, _forward_paragraph_end, 
_backward_paragraph_start, paragraph, A, TRUE);
+TEXT_OBJECT_CTOR (a_block_paren, ends_paren, starts_paren, forward_block_paren_end, 
backward_block_paren_start, one, A, FALSE);
+TEXT_OBJECT_CTOR (a_block_brace, ends_brace, starts_brace, forward_block_brace_end, 
backward_block_brace_start, one, A, FALSE);
+TEXT_OBJECT_CTOR (a_block_bracket, ends_bracket, starts_bracket, forward_block_bracket_end, 
backward_block_bracket_start, one, A, FALSE);
+TEXT_OBJECT_CTOR (a_block_lt_gt, ends_lt_gt, starts_lt_gt, forward_block_lt_gt_end, 
backward_block_lt_gt_start, one, A, FALSE);
+TEXT_OBJECT_CTOR (a_quote_double, ends_quote_double, always_false, forward_quote_double, 
backward_quote_double, one, A, FALSE);
+TEXT_OBJECT_CTOR (a_quote_single, ends_quote_single, always_false, forward_quote_single, 
backward_quote_single, one, A, FALSE);
+TEXT_OBJECT_CTOR (a_quote_grave, ends_quote_grave, always_false, forward_quote_grave, backward_quote_grave, 
one, A, FALSE);
 
 #undef TEXT_OBJECT_CTOR
 
@@ -541,3 +547,11 @@ gtk_source_vim_text_object_select (GtkSourceVimTextObject *self,
 
        return TRUE;
 }
+
+gboolean
+gtk_source_vim_text_object_is_linewise (GtkSourceVimTextObject *self)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_VIM_TEXT_OBJECT (self), FALSE);
+
+       return self->is_linewise;
+}
diff --git a/gtksourceview/vim/gtk-source-vim-text-object.h b/gtksourceview/vim/gtk-source-vim-text-object.h
index ef4a74be..817891a5 100644
--- a/gtksourceview/vim/gtk-source-vim-text-object.h
+++ b/gtksourceview/vim/gtk-source-vim-text-object.h
@@ -51,6 +51,7 @@ GtkSourceVimState *gtk_source_vim_text_object_new_a_block_lt_gt       (void);
 GtkSourceVimState *gtk_source_vim_text_object_new_a_quote_double      (void);
 GtkSourceVimState *gtk_source_vim_text_object_new_a_quote_single      (void);
 GtkSourceVimState *gtk_source_vim_text_object_new_a_quote_grave       (void);
+gboolean           gtk_source_vim_text_object_is_linewise             (GtkSourceVimTextObject *self);
 gboolean           gtk_source_vim_text_object_select                  (GtkSourceVimTextObject *self,
                                                                        GtkTextIter            *begin,
                                                                        GtkTextIter            *end);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]