⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vi_mode.c

📁 android-w.song.android.widget
💻 C
📖 第 1 页 / 共 3 页
字号:
static void_rl_vi_save_insert (up)      UNDO_LIST *up;{  int len, start, end;  if (up == 0 || up->what != UNDO_INSERT)    {      if (vi_insert_buffer_size >= 1)	vi_insert_buffer[0] = '\0';      return;    }  start = up->start;  end = up->end;  len = end - start + 1;  if (len >= vi_insert_buffer_size)    {      vi_insert_buffer_size += (len + 32) - (len % 32);      vi_insert_buffer = (char *)xrealloc (vi_insert_buffer, vi_insert_buffer_size);    }  strncpy (vi_insert_buffer, rl_line_buffer + start, len - 1);  vi_insert_buffer[len-1] = '\0';}    void_rl_vi_done_inserting (){  if (_rl_vi_doing_insert)    {      /* The `C', `s', and `S' commands set this. */      rl_end_undo_group ();      /* Now, the text between rl_undo_list->next->start and	 rl_undo_list->next->end is what was inserted while in insert	 mode.  It gets copied to VI_INSERT_BUFFER because it depends	 on absolute indices into the line which may change (though they	 probably will not). */      _rl_vi_doing_insert = 0;      _rl_vi_save_insert (rl_undo_list->next);      vi_continued_command = 1;    }  else    {      if (rl_undo_list && (_rl_vi_last_key_before_insert == 'i' ||			   _rl_vi_last_key_before_insert == 'a' ||			   _rl_vi_last_key_before_insert == 'I' ||			   _rl_vi_last_key_before_insert == 'A'))	_rl_vi_save_insert (rl_undo_list);      /* XXX - Other keys probably need to be checked. */      else if (_rl_vi_last_key_before_insert == 'C')	rl_end_undo_group ();      while (_rl_undo_group_level > 0)	rl_end_undo_group ();      vi_continued_command = 0;    }}intrl_vi_movement_mode (count, key)     int count, key;{  if (rl_point > 0)    rl_backward_char (1, key);  _rl_keymap = vi_movement_keymap;  _rl_vi_done_inserting ();  /* This is how POSIX.2 says `U' should behave -- everything up until the     first time you go into command mode should not be undone. */  if (RL_ISSTATE (RL_STATE_VICMDONCE) == 0)    rl_free_undo_list ();  RL_SETSTATE (RL_STATE_VICMDONCE);  return (0);}intrl_vi_arg_digit (count, c)     int count, c;{  if (c == '0' && rl_numeric_arg == 1 && !rl_explicit_arg)    return (rl_beg_of_line (1, c));  else    return (rl_digit_argument (count, c));}/* Change the case of the next COUNT characters. */#if defined (HANDLE_MULTIBYTE)static int_rl_vi_change_mbchar_case (count)     int count;{  wchar_t wc;  char mb[MB_LEN_MAX+1];  int mlen, p;  size_t m;  mbstate_t ps;  memset (&ps, 0, sizeof (mbstate_t));  if (_rl_adjust_point (rl_line_buffer, rl_point, &ps) > 0)    count--;  while (count-- && rl_point < rl_end)    {      m = mbrtowc (&wc, rl_line_buffer + rl_point, rl_end - rl_point, &ps);      if (MB_INVALIDCH (m))	wc = (wchar_t)rl_line_buffer[rl_point];      else if (MB_NULLWCH (m))	wc = L'\0';      if (iswupper (wc))	wc = towlower (wc);      else if (iswlower (wc))	wc = towupper (wc);      else	{	  /* Just skip over chars neither upper nor lower case */	  rl_forward_char (1, 0);	  continue;	}      /* Vi is kind of strange here. */      if (wc)	{	  p = rl_point;	  mlen = wcrtomb (mb, wc, &ps);	  if (mlen >= 0)	    mb[mlen] = '\0';	  rl_begin_undo_group ();	  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 ();	}      else	rl_forward_char (1, 0);    }  return 0;}#endifintrl_vi_change_case (count, ignore)     int count, ignore;{  int c, p;  /* Don't try this on an empty line. */  if (rl_point >= rl_end)    return (0);  c = 0;#if defined (HANDLE_MULTIBYTE)  if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)    return (_rl_vi_change_mbchar_case (count));#endif  while (count-- && rl_point < rl_end)    {      if (_rl_uppercase_p (rl_line_buffer[rl_point]))	c = _rl_to_lower (rl_line_buffer[rl_point]);      else if (_rl_lowercase_p (rl_line_buffer[rl_point]))	c = _rl_to_upper (rl_line_buffer[rl_point]);      else	{	  /* Just skip over characters neither upper nor lower case. */	  rl_forward_char (1, c);	  continue;	}      /* Vi is kind of strange here. */      if (c)	{	  p = rl_point;	  rl_begin_undo_group ();	  rl_vi_delete (1, c);	  if (rl_point < p)	/* Did we retreat at EOL? */	    rl_point++;	  _rl_insert_char (1, c);	  rl_end_undo_group ();	  rl_vi_check ();	}      else	rl_forward_char (1, c);    }  return (0);}intrl_vi_put (count, key)     int count, key;{  if (!_rl_uppercase_p (key) && (rl_point + 1 <= rl_end))    rl_point = _rl_find_next_mbchar (rl_line_buffer, rl_point, 1, MB_FIND_NONZERO);  while (count--)    rl_yank (1, key);  rl_backward_char (1, key);  return (0);}static void_rl_vi_backup (){  if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)    rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);  else    rl_point--;}intrl_vi_check (){  if (rl_point && rl_point == rl_end)    {      if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)	rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_NONZERO);      else	rl_point--;    }  return (0);}intrl_vi_column (count, key)     int count, key;{  if (count > rl_end)    rl_end_of_line (1, key);  else    rl_point = count - 1;  return (0);}/* Process C as part of the current numeric argument.  Return -1 if the   argument should be aborted, 0 if we should not read any more chars, and   1 if we should continue to read chars. */static int_rl_vi_arg_dispatch (c)     int c;{  int key;  key = c;  if (c >= 0 && _rl_keymap[c].type == ISFUNC && _rl_keymap[c].function == rl_universal_argument)    {      rl_numeric_arg *= 4;      return 1;    }  c = UNMETA (c);  if (_rl_digit_p (c))    {      if (rl_explicit_arg)	rl_numeric_arg = (rl_numeric_arg * 10) + _rl_digit_value (c);      else	rl_numeric_arg = _rl_digit_value (c);      rl_explicit_arg = 1;      return 1;		/* keep going */    }  else    {      rl_clear_message ();      rl_stuff_char (key);      return 0;		/* done */    }}/* A simplified loop for vi. Don't dispatch key at end.   Don't recognize minus sign?   Should this do rl_save_prompt/rl_restore_prompt? */static intrl_digit_loop1 (){  int c, r;  while (1)    {      if (_rl_arg_overflow ())	return 1;      c = _rl_arg_getchar ();      r = _rl_vi_arg_dispatch (c);      if (r <= 0)	break;    }  RL_UNSETSTATE(RL_STATE_NUMERICARG);  return (0);}static void_rl_mvcxt_init (m, op, key)     _rl_vimotion_cxt *m;     int op, key;{  m->op = op;  m->state = m->flags = 0;  m->ncxt = 0;  m->numeric_arg = -1;  m->start = rl_point;  m->end = rl_end;  m->key = key;  m->motion = -1;}static _rl_vimotion_cxt *_rl_mvcxt_alloc (op, key)     int op, key;{  _rl_vimotion_cxt *m;  m = xmalloc (sizeof (_rl_vimotion_cxt));  _rl_mvcxt_init (m, op, key);  return m;}static void_rl_mvcxt_dispose (m)     _rl_vimotion_cxt *m;{  xfree (m);}static intrl_domove_motion_callback (m)     _rl_vimotion_cxt *m;{  int c, save, r;  int old_end;  _rl_vi_last_motion = c = m->motion;  /* Append a blank character temporarily so that the motion routines     work right at the end of the line. */  old_end = rl_end;  rl_line_buffer[rl_end++] = ' ';  rl_line_buffer[rl_end] = '\0';  _rl_dispatch (c, _rl_keymap);  /* Remove the blank that we added. */  rl_end = old_end;  rl_line_buffer[rl_end] = '\0';  if (rl_point > rl_end)    rl_point = rl_end;  /* No change in position means the command failed. */  if (rl_mark == rl_point)    return (-1);  /* rl_vi_f[wW]ord () leaves the cursor on the first character of the next     word.  If we are not at the end of the line, and we are on a     non-whitespace character, move back one (presumably to whitespace). */  if ((_rl_to_upper (c) == 'W') && rl_point < rl_end && rl_point > rl_mark &&      !whitespace (rl_line_buffer[rl_point]))    rl_point--;  /* If cw or cW, back up to the end of a word, so the behaviour of ce     or cE is the actual result.  Brute-force, no subtlety. */  if (m->key == 'c' && rl_point >= rl_mark && (_rl_to_upper (c) == 'W'))    {      /* Don't move farther back than where we started. */      while (rl_point > rl_mark && whitespace (rl_line_buffer[rl_point]))	rl_point--;      /* Posix.2 says that if cw or cW moves the cursor towards the end of	 the line, the character under the cursor should be deleted. */      if (rl_point == rl_mark)	rl_point++;      else	{	  /* Move past the end of the word so that the kill doesn't	     remove the last letter of the previous word.  Only do this	     if we are not at the end of the line. */	  if (rl_point >= 0 && rl_point < (rl_end - 1) && !whitespace (rl_line_buffer[rl_point]))	    rl_point++;	}    }  if (rl_mark < rl_point)    SWAP (rl_point, rl_mark);#if defined (READLINE_CALLBACKS)  if (RL_ISSTATE (RL_STATE_CALLBACK))    (*rl_redisplay_function)();		/* make sure motion is displayed */#endif  r = vidomove_dispatch (m);  return (r);}#define RL_VIMOVENUMARG()	(RL_ISSTATE (RL_STATE_VIMOTION) && RL_ISSTATE (RL_STATE_NUMERICARG))static intrl_domove_read_callback (m)     _rl_vimotion_cxt *m;{  int c, save;  c = m->motion;  if (member (c, vi_motion))    {#if defined (READLINE_CALLBACKS)      /* If we just read a vi-mode motion command numeric argument, turn off	 the `reading numeric arg' state */      if (RL_ISSTATE (RL_STATE_CALLBACK) && RL_VIMOVENUMARG())	RL_UNSETSTATE (RL_STATE_NUMERICARG);#endif      /* Should do everything, including turning off RL_STATE_VIMOTION */      return (rl_domove_motion_callback (m));    }  else if (m->key == c && (m->key == 'd' || m->key == 'y' || m->key == 'c'))    {      rl_mark = rl_end;      rl_beg_of_line (1, c);      _rl_vi_last_motion = c;      RL_UNSETSTATE (RL_STATE_VIMOTION);      return (0);    }#if defined (READLINE_CALLBACKS)  /* XXX - these need to handle rl_universal_argument bindings */  /* Reading vi motion char continuing numeric argument */  else if (_rl_digit_p (c) && RL_ISSTATE (RL_STATE_CALLBACK) && RL_VIMOVENUMARG())    {      return (_rl_vi_arg_dispatch (c));    }  /* Readine vi motion char starting numeric argument */  else if (_rl_digit_p (c) && RL_ISSTATE (RL_STATE_CALLBACK) && RL_ISSTATE (RL_STATE_VIMOTION) && (RL_ISSTATE (RL_STATE_NUMERICARG) == 0))    {      RL_SETSTATE (RL_STATE_NUMERICARG);      return (_rl_vi_arg_dispatch (c));    }#endif  else if (_rl_digit_p (c))    {      /* This code path taken when not in callback mode */      save = rl_numeric_arg;      rl_numeric_arg = _rl_digit_value (c);      rl_explicit_arg = 1;      RL_SETSTATE (RL_STATE_NUMERICARG);      rl_digit_loop1 ();      rl_numeric_arg *= save;      c = rl_vi_domove_getchar (m);      if (c < 0)	{	  m->motion = 0;	  return -1;	}      m->motion = c;      return (rl_domove_motion_callback (m));    }  else    {      RL_UNSETSTATE (RL_STATE_VIMOTION);      RL_UNSETSTATE (RL_STATE_NUMERICARG);      return (1);    }}static intrl_vi_domove_getchar (m)     _rl_vimotion_cxt *m;{  int c;  RL_SETSTATE(RL_STATE_MOREINPUT);  c = rl_read_key ();  RL_UNSETSTATE(RL_STATE_MOREINPUT);  return c;}#if defined (READLINE_CALLBACKS)int_rl_vi_domove_callback (m)     _rl_vimotion_cxt *m;{  int c, r;  m->motion = c = rl_vi_domove_getchar (m);  /* XXX - what to do if this returns -1?  Should we return 1 for eof to     callback code? */  r = rl_domove_read_callback (m);  return ((r == 0) ? r : 1);	/* normalize return values */}#endif/* This code path taken when not in callback mode. */intrl_vi_domove (x, ignore)     int x, *ignore;{  int r;  _rl_vimotion_cxt *m;  m = _rl_vimvcxt;  *ignore = m->motion = rl_vi_domove_getchar (m);  if (m->motion < 0)    {      m->motion = 0;      return -1;    }  return (rl_domove_read_callback (m));}static intvi_delete_dispatch (m)     _rl_vimotion_cxt *m;{  /* These are the motion commands that do not require adjusting the     mark. */  if (((strchr (" l|h^0bBFT`", m->motion) == 0) && (rl_point >= m->start)) &&      (rl_mark < rl_end))    rl_mark++;  rl_kill_text (rl_point, rl_mark);  return (0);}intrl_vi_delete_to (count, key)     int count, key;{  int c, r;  _rl_vimvcxt = _rl_mvcxt_alloc (VIM_DELETE, key);  _rl_vimvcxt->start = rl_point;  rl_mark = rl_point;  if (_rl_uppercase_p (key))    {      _rl_vimvcxt->motion = '$';      r = rl_domove_motion_callback (_rl_vimvcxt);    }  else if (vi_redoing)    {      _rl_vimvcxt->motion = _rl_vi_last_motion;      r = rl_domove_motion_callback (_rl_vimvcxt);    }#if defined (READLINE_CALLBACKS)  else if (RL_ISSTATE (RL_STATE_CALLBACK))    {      RL_SETSTATE (RL_STATE_VIMOTION);      return (0);    }#endif  else    r = rl_vi_domove (key, &c);  if (r < 0)    {      rl_ding ();      r = -1;    }  _rl_mvcxt_dispose (_rl_vimvcxt);  _rl_vimvcxt = 0;  return r;}static intvi_change_dispatch (m)     _rl_vimotion_cxt *m;{  /* These are the motion commands that do not require adjusting the     mark.  c[wW] are handled by special-case code in rl_vi_domove(),     and already leave the mark at the correct location. */  if (((strchr (" l|hwW^0bBFT`", m->motion) == 0) && (rl_point >= m->start)) &&      (rl_mark < rl_end))    rl_mark++;  /* The cursor never moves with c[wW]. */  if ((_rl_to_upper (m->motion) == 'W') && rl_point < m->start)    rl_point = m->start;  if (vi_redoing)    {      if (vi_insert_buffer && *vi_insert_buffer)	rl_begin_undo_group ();      rl_delete_text (rl_point, rl_mark);      if (vi_insert_buffer && *vi_insert_buffer)	{	  rl_insert_text (vi_insert_buffer);	  rl_end_undo_group ();	}    }  else    {      rl_begin_undo_group ();		/* to make the `u' command work */      rl_kill_text (rl_point, rl_mark);      /* `C' does not save the text inserted for undoing or redoing. */      if (_rl_uppercase_p (m->key) == 0)	_rl_vi_doing_insert = 1;      /* XXX -- TODO -- use m->numericarg? */      rl_vi_start_inserting (m->key, rl_numeric_arg, rl_arg_sign);    }  return (0);}intrl_vi_change_to (count, key)     int count, key;{  int c, r;  _rl_vimvcxt = _rl_mvcxt_alloc (VIM_CHANGE, key);  _rl_vimvcxt->start = rl_point;  rl_mark = rl_point;  if (_rl_uppercase_p (key))    {      _rl_vimvcxt->motion = '$';      r = rl_domove_motion_callback (_rl_vimvcxt);    }  else if (vi_redoing)    {      _rl_vimvcxt->motion = _rl_vi_last_motion;      r = rl_domove_motion_callback (_rl_vimvcxt);    }#if defined (READLINE_CALLBACKS)  else if (RL_ISSTATE (RL_STATE_CALLBACK))    {      RL_SETSTATE (RL_STATE_VIMOTION);      return (0);    }#endif  else    r = rl_vi_domove (key, &c);  if (r < 0)    {      rl_ding ();      r = -1;	/* normalize return value */    }  _rl_mvcxt_dispose (_rl_vimvcxt);  _rl_vimvcxt = 0;  return r;}static intvi_yank_dispatch (m)     _rl_vimotion_cxt *m;{  /* These are the motion commands that do not require adjusting the     mark. */  if (((strchr (" l|h^0%bBFT`", m->motion) == 0) && (rl_point >= m->start)) &&      (rl_mark < rl_end))    rl_mark++;  rl_begin_undo_group ();  rl_kill_text (rl_point, rl_mark);  rl_end_undo_group ();  rl_do_undo ();  rl_point = m->start;  return (0);}intrl_vi_yank_to (count, key)     int count, key;{  int c, r;  _rl_vimvcxt = _rl_mvcxt_alloc (VIM_YANK, key);  _rl_vimvcxt->start = rl_point;  rl_mark = rl_point;  if (_rl_uppercase_p (key))    {      _rl_vimvcxt->motion = '$';      r = rl_domove_motion_callback (_rl_vimvcxt);    }#if defined (READLINE_CALLBACKS)  else if (RL_ISSTATE (RL_STATE_CALLBACK))    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -