]> git.ipfire.org Git - thirdparty/readline.git/commitdiff
Readline-5.0.005 import
authorChet Ramey <chet.ramey@case.edu>
Thu, 24 Nov 2011 00:13:32 +0000 (19:13 -0500)
committerChet Ramey <chet.ramey@case.edu>
Thu, 24 Nov 2011 00:13:32 +0000 (19:13 -0500)
display.c
mbutil.c
misc.c
vi_mode.c

index 0ff428e44e9f22dce3f39c1f8a0f485f8c290d3b..ff0cf5ab9e9b2b1a99154a92162e7d8197c0bf7c 100644 (file)
--- a/display.c
+++ b/display.c
@@ -201,7 +201,7 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
      int *lp, *lip, *niflp, *vlp;
 {
   char *r, *ret, *p;
-  int l, rl, last, ignoring, ninvis, invfl, ind, pind, physchars;
+  int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars;
 
   /* Short-circuit if we can. */
   if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, RL_PROMPT_START_IGNORE) == 0)
@@ -222,6 +222,7 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
   r = ret = (char *)xmalloc (l + 1);
 
   invfl = 0;   /* invisible chars in first line of prompt */
+  invflset = 0;        /* we only want to set invfl once */
 
   for (rl = ignoring = last = ninvis = physchars = 0, p = pmt; p && *p; p++)
     {
@@ -249,7 +250,10 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
              while (l--)
                *r++ = *p++;
              if (!ignoring)
-               rl += ind - pind;
+               {
+                 rl += ind - pind;
+                 physchars += _rl_col_width (pmt, pind, ind);
+               }
              else
                ninvis += ind - pind;
              p--;                      /* compensate for later increment */
@@ -259,16 +263,19 @@ expand_prompt (pmt, lp, lip, niflp, vlp)
            {
              *r++ = *p;
              if (!ignoring)
-               rl++;                   /* visible length byte counter */
+               {
+                 rl++;                 /* visible length byte counter */
+                 physchars++;
+               }
              else
                ninvis++;               /* invisible chars byte counter */
            }
 
-         if (rl >= _rl_screenwidth)
-           invfl = ninvis;
-
-         if (ignoring == 0)
-           physchars++;
+         if (invflset == 0 && rl >= _rl_screenwidth)
+           {
+             invfl = ninvis;
+             invflset = 1;
+           }
        }
     }
 
@@ -351,14 +358,14 @@ rl_expand_prompt (prompt)
       local_prompt = expand_prompt (p, &prompt_visible_length,
                                       &prompt_last_invisible,
                                       (int *)NULL,
-                                      (int *)NULL);
+                                      &prompt_physical_chars);
       c = *t; *t = '\0';
       /* The portion of the prompt string up to and including the
         final newline is now null-terminated. */
       local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length,
                                                   (int *)NULL,
                                                   &prompt_invis_chars_first_line,
-                                                  &prompt_physical_chars);
+                                                  (int *)NULL);
       *t = c;
       return (prompt_prefix_length);
     }
@@ -417,7 +424,7 @@ rl_redisplay ()
   register int in, out, c, linenum, cursor_linenum;
   register char *line;
   int c_pos, inv_botlin, lb_botlin, lb_linenum;
-  int newlines, lpos, temp, modmark;
+  int newlines, lpos, temp, modmark, n0, num;
   char *prompt_this_line;
 #if defined (HANDLE_MULTIBYTE)
   wchar_t wc;
@@ -573,6 +580,7 @@ rl_redisplay ()
 
 #if defined (HANDLE_MULTIBYTE)
   memset (_rl_wrapped_line, 0, vis_lbsize);
+  num = 0;
 #endif
 
   /* prompt_invis_chars_first_line is the number of invisible characters in
@@ -591,13 +599,32 @@ rl_redisplay ()
          probably too much work for the benefit gained.  How many people have
          prompts that exceed two physical lines?
          Additional logic fix from Edward Catmur <ed@catmur.co.uk> */
+#if defined (HANDLE_MULTIBYTE)
+      n0 = num;
+      temp = local_prompt ? strlen (local_prompt) : 0;
+      while (num < temp)
+       {
+         if (_rl_col_width  (local_prompt, n0, num) > _rl_screenwidth)
+           {
+             num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY);
+             break;
+           }
+         num++;
+       }
+      temp = num +
+#else
       temp = ((newlines + 1) * _rl_screenwidth) +
+#endif /* !HANDLE_MULTIBYTE */
              ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line
                                                            : ((newlines == 1) ? wrap_offset : 0))
                                         : ((newlines == 0) ? wrap_offset :0));
              
       inv_lbreaks[++newlines] = temp;
+#if defined (HANDLE_MULTIBYTE)
+      lpos -= _rl_col_width (local_prompt, n0, num);
+#else
       lpos -= _rl_screenwidth;
+#endif
     }
 
   prompt_last_screen_line = newlines;
index 9a8f17c0f74e0ca5cd0062ff2a8427dd91002599..695845a60f4e5fbc5a765ca2a34ac9a00d2673c9 100644 (file)
--- a/mbutil.c
+++ b/mbutil.c
@@ -126,11 +126,11 @@ _rl_find_next_mbchar_internal (string, seed, count, find_non_zero)
   if (find_non_zero)
     {
       tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps);
-      while (wcwidth (wc) == 0)
+      while (tmp > 0 && wcwidth (wc) == 0)
        {
          point += tmp;
          tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps);
-         if (tmp == (size_t)(0) || tmp == (size_t)(-1) || tmp == (size_t)(-2))
+         if (MB_NULLWCH (tmp) || MB_INVALIDCH (tmp))
            break;
        }
     }
diff --git a/misc.c b/misc.c
index ab1e1337fd3ab88b1a8a5094fe96d65e7d1d3aad..403313a04350f29e561f2423a88b4e104c03f03b 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -276,12 +276,6 @@ rl_maybe_save_line ()
       _rl_saved_line_for_history->line = savestring (rl_line_buffer);
       _rl_saved_line_for_history->data = (char *)rl_undo_list;
     }
-  else if (STREQ (rl_line_buffer, _rl_saved_line_for_history->line) == 0)
-    {
-      free (_rl_saved_line_for_history->line);
-      _rl_saved_line_for_history->line = savestring (rl_line_buffer);
-      _rl_saved_line_for_history->data = (char *)rl_undo_list; /* XXX possible memleak */
-    }
 
   return 0;
 }
index 74d8acbbc05ed830846bcfe7f33329d561e39f64..de723a1d3d8dbf6aa6989da87993306f8e762810 100644 (file)
--- a/vi_mode.c
+++ b/vi_mode.c
@@ -272,10 +272,12 @@ rl_vi_search (count, key)
   switch (key)
     {
     case '?':
+      _rl_free_saved_history_line ();
       rl_noninc_forward_search (count, key);
       break;
 
     case '/':
+      _rl_free_saved_history_line ();
       rl_noninc_reverse_search (count, key);
       break;
 
@@ -690,7 +692,7 @@ _rl_vi_change_mbchar_case (count)
 {
   wchar_t wc;
   char mb[MB_LEN_MAX+1];
-  int mblen;
+  int mblen, p;
   mbstate_t ps;
 
   memset (&ps, 0, sizeof (mbstate_t));
@@ -713,11 +715,14 @@ _rl_vi_change_mbchar_case (count)
       /* Vi is kind of strange here. */
       if (wc)
        {
+         p = rl_point;
          mblen = wcrtomb (mb, wc, &ps);
          if (mblen >= 0)
            mb[mblen] = '\0';
          rl_begin_undo_group ();
-         rl_delete (1, 0);
+         rl_vi_delete (1, 0);
+         if (rl_point < p)     /* Did we retreat at EOL? */
+           rl_point++; /* XXX - should we advance more than 1 for mbchar? */
          rl_insert_text (mb);
          rl_end_undo_group ();
          rl_vi_check ();
@@ -1310,12 +1315,16 @@ rl_vi_change_char (count, key)
       rl_vi_delete (1, c);
 #if defined (HANDLE_MULTIBYTE)
       if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
-       while (_rl_insert_char (1, c))
-         {
-           RL_SETSTATE (RL_STATE_MOREINPUT);
-           c = rl_read_key ();
-           RL_UNSETSTATE (RL_STATE_MOREINPUT);
-         }
+       {
+         if (rl_point < p)             /* Did we retreat at EOL? */
+           rl_point++;
+         while (_rl_insert_char (1, c))
+           {
+             RL_SETSTATE (RL_STATE_MOREINPUT);
+             c = rl_read_key ();
+             RL_UNSETSTATE (RL_STATE_MOREINPUT);
+           }
+       }
       else
 #endif
        {