[gtksourceview/wip/chergert/vim: 288/363] add start/end helpers for word/WORD
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 288/363] add start/end helpers for word/WORD
- Date: Mon, 8 Nov 2021 19:53:54 +0000 (UTC)
commit ecbe678c5386225d30c7ca6eafd8f6c636827506
Author: Christian Hergert <chergert redhat com>
Date: Thu Nov 4 22:28:36 2021 -0700
add start/end helpers for word/WORD
gtksourceview/vim/gtk-source-vim-motion.c | 109 +++++++++++++++++++++++++++++-
gtksourceview/vim/gtk-source-vim-motion.h | 4 ++
2 files changed, 110 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 19d8f571..e11694c6 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -156,9 +156,8 @@ enum
CLASS_WORD,
};
-static int
-classify_word (gunichar ch,
- const GtkTextIter *iter)
+static inline int
+simple_word_classify (gunichar ch)
{
switch (ch)
{
@@ -184,6 +183,13 @@ classify_word (gunichar ch,
}
}
+static int
+classify_word (gunichar ch,
+ const GtkTextIter *iter)
+{
+ return simple_word_classify (ch);
+}
+
static int
classify_word_newline_stop (gunichar ch,
const GtkTextIter *iter)
@@ -2282,3 +2288,100 @@ gtk_source_vim_iter_backward_quote_grave (GtkTextIter *iter)
{
return gtk_source_vim_iter_backward_quote_start (iter, '`');
}
+
+gboolean
+gtk_source_vim_iter_starts_word (GtkTextIter *iter)
+{
+ GtkTextIter prev;
+
+ if (gtk_text_iter_starts_line (iter))
+ {
+ /* A blank line is a word */
+ return gtk_text_iter_ends_line (iter) || !iter_isspace (iter);
+ }
+ else if (gtk_text_iter_ends_line (iter))
+ {
+ return FALSE;
+ }
+
+ if (iter_isspace (iter))
+ return FALSE;
+
+ prev = *iter;
+ gtk_text_iter_backward_char (&prev);
+
+ return simple_word_classify (gtk_text_iter_get_char (iter)) !=
+ simple_word_classify (gtk_text_iter_get_char (&prev));
+}
+
+gboolean
+gtk_source_vim_iter_ends_word (GtkTextIter *iter)
+{
+ GtkTextIter next;
+
+ if (gtk_text_iter_ends_line (iter))
+ {
+ /* A blank line is a word */
+ if (gtk_text_iter_starts_line (iter))
+ return TRUE;
+
+ return FALSE;
+ }
+
+ if (iter_isspace (iter))
+ return FALSE;
+
+ next = *iter;
+ gtk_text_iter_forward_char (&next);
+
+ return simple_word_classify (gtk_text_iter_get_char (iter)) !=
+ simple_word_classify (gtk_text_iter_get_char (&next));
+}
+
+gboolean
+gtk_source_vim_iter_starts_WORD (GtkTextIter *iter)
+{
+ GtkTextIter prev;
+
+ if (gtk_text_iter_starts_line (iter))
+ {
+ /* A blank line is a word */
+ return gtk_text_iter_ends_line (iter) || !iter_isspace (iter);
+ }
+ else if (gtk_text_iter_ends_line (iter))
+ {
+ return FALSE;
+ }
+
+ if (iter_isspace (iter))
+ return FALSE;
+
+ prev = *iter;
+ gtk_text_iter_backward_char (&prev);
+
+ return iter_isspace (&prev);
+}
+
+gboolean
+gtk_source_vim_iter_ends_WORD (GtkTextIter *iter)
+{
+ GtkTextIter next;
+
+ if (gtk_text_iter_ends_line (iter))
+ {
+ /* A blank line is a word */
+ if (gtk_text_iter_starts_line (iter))
+ return TRUE;
+
+ return FALSE;
+ }
+
+ if (iter_isspace (iter))
+ return FALSE;
+
+ next = *iter;
+ if (!gtk_text_iter_forward_char (&next))
+ return TRUE;
+
+ return iter_isspace (&next);
+}
diff --git a/gtksourceview/vim/gtk-source-vim-motion.h b/gtksourceview/vim/gtk-source-vim-motion.h
index 9399c2eb..7edab761 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.h
+++ b/gtksourceview/vim/gtk-source-vim-motion.h
@@ -77,5 +77,9 @@ gboolean gtk_source_vim_iter_forward_quote_single (GtkTextIter *iter);
gboolean gtk_source_vim_iter_forward_sentence_end (GtkTextIter *iter);
gboolean gtk_source_vim_iter_forward_word_end (GtkTextIter *iter);
gboolean gtk_source_vim_iter_forward_WORD_end (GtkTextIter *iter);
+gboolean gtk_source_vim_iter_ends_word (GtkTextIter *iter);
+gboolean gtk_source_vim_iter_ends_WORD (GtkTextIter *iter);
+gboolean gtk_source_vim_iter_starts_word (GtkTextIter *iter);
+gboolean gtk_source_vim_iter_starts_WORD (GtkTextIter *iter);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]