[gnome-builder/wip/csoriano/operators: 2/2] source-vim: improve w modifier for operators



commit 4c6f1e87a013a4b968a6497a9597d010007aa6ca
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Feb 3 09:30:29 2015 +0100

    source-vim: improve w modifier for operators

 src/vim/gb-source-vim.c |   50 +++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/src/vim/gb-source-vim.c b/src/vim/gb-source-vim.c
index e2e554a..0e957d0 100644
--- a/src/vim/gb-source-vim.c
+++ b/src/vim/gb-source-vim.c
@@ -207,6 +207,7 @@ enum
 {
   CLASS_0,
   CLASS_SPACE,
+  CLASS_RETURN,
   CLASS_SPECIAL,
   CLASS_WORD,
 };
@@ -343,9 +344,11 @@ gb_source_vim_classify (gunichar ch)
   switch (ch)
     {
     case ' ':
+      return CLASS_SPACE;
+
     case '\t':
     case '\n':
-      return CLASS_SPACE;
+      return CLASS_RETURN;
 
     case '"': case '\'':
     case '(': case ')':
@@ -1037,7 +1040,6 @@ text_iter_backward_vim_word (GtkTextIter *iter)
    * If we are on space, walk until we get to non-whitespace. Then work our way
    * back to the beginning of the word.
    */
-  ch = gtk_text_iter_get_char (iter);
   if (gb_source_vim_classify (ch) == CLASS_SPACE)
     {
       for (;;)
@@ -1163,7 +1165,8 @@ gb_source_vim_move_forward (GbSourceVim *vim)
 }
 
 static gboolean
-text_iter_forward_vim_word (GtkTextIter *iter)
+text_iter_forward_vim_word (GtkTextIter *iter,
+                            gboolean     eol)
 {
   gint begin_class;
   gint cur_class;
@@ -1175,17 +1178,22 @@ text_iter_forward_vim_word (GtkTextIter *iter)
   begin_class = gb_source_vim_classify (ch);
 
   /* Move to the first non-whitespace character if necessary. */
-  if (begin_class == CLASS_SPACE)
+  if (begin_class == CLASS_SPACE || (!eol && begin_class == CLASS_RETURN))
     {
       for (;;)
         {
-          if (!gtk_text_iter_forward_char (iter))
+          g_print ("text_iter_forward_vim_word space %i\n", ch);
+          if (!gtk_text_iter_forward_char (iter)) {
+            g_print ("false\n");
             return FALSE;
+          }
 
           ch = gtk_text_iter_get_char (iter);
           cur_class = gb_source_vim_classify (ch);
-          if (cur_class != CLASS_SPACE)
+          if (cur_class != CLASS_SPACE && (eol || cur_class != CLASS_RETURN)) {
+            g_print ("rtrue\n");
             return TRUE;
+          }
         }
     }
 
@@ -1193,15 +1201,16 @@ text_iter_forward_vim_word (GtkTextIter *iter)
   while (gtk_text_iter_forward_char (iter))
     {
       ch = gtk_text_iter_get_char (iter);
+      g_print ("text_iter_forward_vim_word no space %i\n", ch);
       cur_class = gb_source_vim_classify (ch);
 
-      if (cur_class == CLASS_SPACE)
+      if (cur_class == CLASS_SPACE || (!eol && cur_class == CLASS_RETURN))
         {
           begin_class = CLASS_0;
           continue;
         }
 
-      if (cur_class != begin_class)
+      if (cur_class != begin_class || (eol && cur_class == CLASS_RETURN))
         return TRUE;
     }
 
@@ -1223,7 +1232,7 @@ text_iter_forward_vim_word_end (GtkTextIter *iter)
   /* If we are on space, walk to the start of the next word. */
   ch = gtk_text_iter_get_char (iter);
   if (gb_source_vim_classify (ch) == CLASS_SPACE)
-    if (!text_iter_forward_vim_word (iter))
+    if (!text_iter_forward_vim_word (iter, TRUE))
       return FALSE;
 
   ch = gtk_text_iter_get_char (iter);
@@ -1248,12 +1257,14 @@ text_iter_forward_vim_word_end (GtkTextIter *iter)
 }
 
 static void
-gb_source_vim_move_forward_word (GbSourceVim *vim)
+gb_source_vim_move_forward_word (GbSourceVim *vim,
+                                 gboolean     eol)
 {
   GtkTextBuffer *buffer;
   GtkTextIter iter;
   GtkTextIter selection;
   gboolean has_selection;
+  gboolean forward_word;
 
   g_assert (GB_IS_SOURCE_VIM (vim));
 
@@ -1264,7 +1275,9 @@ gb_source_vim_move_forward_word (GbSourceVim *vim)
   buffer = gtk_text_view_get_buffer (vim->priv->text_view);
   has_selection = gb_source_vim_get_selection_bounds (vim, &iter, &selection);
 
-  if (!text_iter_forward_vim_word (&iter))
+  forward_word = text_iter_forward_vim_word (&iter, eol);
+  g_print ("operator %i, %i\n", eol, forward_word);
+  if (!forward_word)
     gtk_text_buffer_get_end_iter (buffer, &iter);
 
   if (has_selection)
@@ -1938,6 +1951,7 @@ gb_source_vim_select_char (GbSourceVim *vim)
 static void
 gb_source_vim_apply_motion (GbSourceVim *vim,
                             char         motion,
+                            char         operator,
                             guint        count)
 {
   GbSourceVimCommand *cmd;
@@ -1951,7 +1965,8 @@ gb_source_vim_apply_motion (GbSourceVim *vim,
   else
     gb_source_vim_select_char (vim);
 
-  cmd->func (vim, count, '\0');
+  g_print ("apply motion %c\n", operator);
+  cmd->func (vim, count, operator);
 
   if ((cmd->flags & GB_SOURCE_VIM_COMMAND_FLAG_MOTION_EXCLUSIVE))
     {
@@ -4881,7 +4896,7 @@ gb_source_vim_cmd_delete (GbSourceVim *vim,
             gb_source_vim_cmd_select_line (vim, count, '\0');
         }
       else
-        gb_source_vim_apply_motion (vim, modifier, count);
+        gb_source_vim_apply_motion (vim, modifier, 'd', count);
     }
 
   gb_source_vim_delete_selection (vim);
@@ -5413,16 +5428,19 @@ gb_source_vim_cmd_select (GbSourceVim *vim,
 static void
 gb_source_vim_cmd_forward_word (GbSourceVim *vim,
                                 guint        count,
-                                gchar        modifier)
+                                gchar        operator)
 {
   guint i;
+  gboolean eol;
 
   g_assert (GB_IS_SOURCE_VIM (vim));
 
   count = MAX (1, count);
 
+  g_print ("forward word\n");
+  eol = operator == 'd' || operator == 'c';
   for (i = 0; i < count; i++)
-    gb_source_vim_move_forward_word (vim);
+    gb_source_vim_move_forward_word (vim, eol);
 }
 
 static void
@@ -5490,7 +5508,7 @@ gb_source_vim_cmd_yank (GbSourceVim *vim,
           gb_source_vim_cmd_select_line (vim, count, '\0');
         }
       else
-        gb_source_vim_apply_motion (vim, modifier, count);
+        gb_source_vim_apply_motion (vim, modifier, 'y', count);
     }
 
   gb_source_vim_yank (vim);


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