Karsten Hopp 560310
To: vim_dev@googlegroups.com
Karsten Hopp 560310
Subject: Patch 7.4.653
Karsten Hopp 560310
Fcc: outbox
Karsten Hopp 560310
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 560310
Mime-Version: 1.0
Karsten Hopp 560310
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 560310
Content-Transfer-Encoding: 8bit
Karsten Hopp 560310
------------
Karsten Hopp 560310
Karsten Hopp 560310
Patch 7.4.653
Karsten Hopp 560310
Problem:    Insert mode completion with complete() may have CTRL-L work like
Karsten Hopp 560310
	    CTRL-P.
Karsten Hopp 560310
Solution:   Handle completion with complete() differently. (Yasuhiro
Karsten Hopp 560310
	    Matsumoto, Christian Brabandt, Hirohito Higashi)
Karsten Hopp 560310
Files:	    src/edit.c
Karsten Hopp 560310
Karsten Hopp 560310
Karsten Hopp 560310
*** ../vim-7.4.652/src/edit.c	2015-02-17 17:50:20.430274997 +0100
Karsten Hopp 560310
--- src/edit.c	2015-03-05 18:04:57.419602256 +0100
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 34,41 ****
Karsten Hopp 560310
--- 34,43 ----
Karsten Hopp 560310
  #define CTRL_X_OMNI		13
Karsten Hopp 560310
  #define CTRL_X_SPELL		14
Karsten Hopp 560310
  #define CTRL_X_LOCAL_MSG	15	/* only used in "ctrl_x_msgs" */
Karsten Hopp 560310
+ #define CTRL_X_EVAL		16	/* for builtin function complete() */
Karsten Hopp 560310
  
Karsten Hopp 560310
  #define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
Karsten Hopp 560310
+ #define CTRL_X_MODE_LINE_OR_EVAL(m) (m == CTRL_X_WHOLE_LINE || m == CTRL_X_EVAL)
Karsten Hopp 560310
  
Karsten Hopp 560310
  static char *ctrl_x_msgs[] =
Karsten Hopp 560310
  {
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 55,60 ****
Karsten Hopp 560310
--- 57,63 ----
Karsten Hopp 560310
      N_(" Omni completion (^O^N^P)"),
Karsten Hopp 560310
      N_(" Spelling suggestion (s^N^P)"),
Karsten Hopp 560310
      N_(" Keyword Local completion (^N^P)"),
Karsten Hopp 560310
+     NULL,   /* CTRL_X_EVAL doesn't use msg. */
Karsten Hopp 560310
  };
Karsten Hopp 560310
  
Karsten Hopp 560310
  static char e_hitend[] = N_("Hit end of paragraph");
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 802,808 ****
Karsten Hopp 560310
  		 * "compl_leader".  Except when at the original match and
Karsten Hopp 560310
  		 * there is nothing to add, CTRL-L works like CTRL-P then. */
Karsten Hopp 560310
  		if (c == Ctrl_L
Karsten Hopp 560310
! 			&& (ctrl_x_mode != CTRL_X_WHOLE_LINE
Karsten Hopp 560310
  			    || (int)STRLEN(compl_shown_match->cp_str)
Karsten Hopp 560310
  					  > curwin->w_cursor.col - compl_col))
Karsten Hopp 560310
  		{
Karsten Hopp 560310
--- 805,811 ----
Karsten Hopp 560310
  		 * "compl_leader".  Except when at the original match and
Karsten Hopp 560310
  		 * there is nothing to add, CTRL-L works like CTRL-P then. */
Karsten Hopp 560310
  		if (c == Ctrl_L
Karsten Hopp 560310
! 			&& (!CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)
Karsten Hopp 560310
  			    || (int)STRLEN(compl_shown_match->cp_str)
Karsten Hopp 560310
  					  > curwin->w_cursor.col - compl_col))
Karsten Hopp 560310
  		{
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 2267,2272 ****
Karsten Hopp 560310
--- 2270,2277 ----
Karsten Hopp 560310
  #endif
Karsten Hopp 560310
  	case CTRL_X_SPELL:
Karsten Hopp 560310
  	    return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N);
Karsten Hopp 560310
+ 	case CTRL_X_EVAL:
Karsten Hopp 560310
+ 	    return (c == Ctrl_P || c == Ctrl_N);
Karsten Hopp 560310
      }
Karsten Hopp 560310
      EMSG(_(e_internal));
Karsten Hopp 560310
      return FALSE;
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 2773,2780 ****
Karsten Hopp 560310
  			-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
Karsten Hopp 560310
  	return;
Karsten Hopp 560310
  
Karsten Hopp 560310
!     /* Handle like dictionary completion. */
Karsten Hopp 560310
!     ctrl_x_mode = CTRL_X_WHOLE_LINE;
Karsten Hopp 560310
  
Karsten Hopp 560310
      ins_compl_add_list(list);
Karsten Hopp 560310
      compl_matches = ins_compl_make_cyclic();
Karsten Hopp 560310
--- 2778,2784 ----
Karsten Hopp 560310
  			-1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
Karsten Hopp 560310
  	return;
Karsten Hopp 560310
  
Karsten Hopp 560310
!     ctrl_x_mode = CTRL_X_EVAL;
Karsten Hopp 560310
  
Karsten Hopp 560310
      ins_compl_add_list(list);
Karsten Hopp 560310
      compl_matches = ins_compl_make_cyclic();
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 3060,3066 ****
Karsten Hopp 560310
      /* When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern
Karsten Hopp 560310
       * to only match at the start of a line.  Otherwise just match the
Karsten Hopp 560310
       * pattern. Also need to double backslashes. */
Karsten Hopp 560310
!     if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
      {
Karsten Hopp 560310
  	char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
Karsten Hopp 560310
  	size_t len;
Karsten Hopp 560310
--- 3064,3070 ----
Karsten Hopp 560310
      /* When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern
Karsten Hopp 560310
       * to only match at the start of a line.  Otherwise just match the
Karsten Hopp 560310
       * pattern. Also need to double backslashes. */
Karsten Hopp 560310
!     if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
      {
Karsten Hopp 560310
  	char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
Karsten Hopp 560310
  	size_t len;
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 3181,3187 ****
Karsten Hopp 560310
  		while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf)))
Karsten Hopp 560310
  		{
Karsten Hopp 560310
  		    ptr = regmatch->startp[0];
Karsten Hopp 560310
! 		    if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  			ptr = find_line_end(ptr);
Karsten Hopp 560310
  		    else
Karsten Hopp 560310
  			ptr = find_word_end(ptr);
Karsten Hopp 560310
--- 3185,3191 ----
Karsten Hopp 560310
  		while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf)))
Karsten Hopp 560310
  		{
Karsten Hopp 560310
  		    ptr = regmatch->startp[0];
Karsten Hopp 560310
! 		    if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  			ptr = find_line_end(ptr);
Karsten Hopp 560310
  		    else
Karsten Hopp 560310
  			ptr = find_word_end(ptr);
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 3394,3400 ****
Karsten Hopp 560310
       * allow the word to be deleted, we won't match everything. */
Karsten Hopp 560310
      if ((int)(p - line) - (int)compl_col < 0
Karsten Hopp 560310
  	    || ((int)(p - line) - (int)compl_col == 0
Karsten Hopp 560310
! 		&& ctrl_x_mode != CTRL_X_OMNI))
Karsten Hopp 560310
  	return K_BS;
Karsten Hopp 560310
  
Karsten Hopp 560310
      /* Deleted more than what was used to find matches or didn't finish
Karsten Hopp 560310
--- 3398,3404 ----
Karsten Hopp 560310
       * allow the word to be deleted, we won't match everything. */
Karsten Hopp 560310
      if ((int)(p - line) - (int)compl_col < 0
Karsten Hopp 560310
  	    || ((int)(p - line) - (int)compl_col == 0
Karsten Hopp 560310
! 		&& ctrl_x_mode != CTRL_X_OMNI) || ctrl_x_mode == CTRL_X_EVAL)
Karsten Hopp 560310
  	return K_BS;
Karsten Hopp 560310
  
Karsten Hopp 560310
      /* Deleted more than what was used to find matches or didn't finish
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 4208,4214 ****
Karsten Hopp 560310
  	/* For ^N/^P pick a new entry from e_cpt if compl_started is off,
Karsten Hopp 560310
  	 * or if found_all says this entry is done.  For ^X^L only use the
Karsten Hopp 560310
  	 * entries from 'complete' that look in loaded buffers. */
Karsten Hopp 560310
! 	if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  					&& (!compl_started || found_all))
Karsten Hopp 560310
  	{
Karsten Hopp 560310
  	    found_all = FALSE;
Karsten Hopp 560310
--- 4212,4218 ----
Karsten Hopp 560310
  	/* For ^N/^P pick a new entry from e_cpt if compl_started is off,
Karsten Hopp 560310
  	 * or if found_all says this entry is done.  For ^X^L only use the
Karsten Hopp 560310
  	 * entries from 'complete' that look in loaded buffers. */
Karsten Hopp 560310
! 	if ((ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  					&& (!compl_started || found_all))
Karsten Hopp 560310
  	{
Karsten Hopp 560310
  	    found_all = FALSE;
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 4261,4267 ****
Karsten Hopp 560310
  		break;
Karsten Hopp 560310
  	    else
Karsten Hopp 560310
  	    {
Karsten Hopp 560310
! 		if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  		    type = -1;
Karsten Hopp 560310
  		else if (*e_cpt == 'k' || *e_cpt == 's')
Karsten Hopp 560310
  		{
Karsten Hopp 560310
--- 4265,4271 ----
Karsten Hopp 560310
  		break;
Karsten Hopp 560310
  	    else
Karsten Hopp 560310
  	    {
Karsten Hopp 560310
! 		if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  		    type = -1;
Karsten Hopp 560310
  		else if (*e_cpt == 'k' || *e_cpt == 's')
Karsten Hopp 560310
  		{
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 4406,4414 ****
Karsten Hopp 560310
  
Karsten Hopp 560310
  		++msg_silent;  /* Don't want messages for wrapscan. */
Karsten Hopp 560310
  
Karsten Hopp 560310
! 		/* ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that
Karsten Hopp 560310
  		 * has added a word that was at the beginning of the line */
Karsten Hopp 560310
! 		if (	ctrl_x_mode == CTRL_X_WHOLE_LINE
Karsten Hopp 560310
  			|| (compl_cont_status & CONT_SOL))
Karsten Hopp 560310
  		    found_new_match = search_for_exact_line(ins_buf, pos,
Karsten Hopp 560310
  					      compl_direction, compl_pattern);
Karsten Hopp 560310
--- 4410,4419 ----
Karsten Hopp 560310
  
Karsten Hopp 560310
  		++msg_silent;  /* Don't want messages for wrapscan. */
Karsten Hopp 560310
  
Karsten Hopp 560310
! 		/* CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)
Karsten Hopp 560310
! 		 * || word-wise search that
Karsten Hopp 560310
  		 * has added a word that was at the beginning of the line */
Karsten Hopp 560310
! 		if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)
Karsten Hopp 560310
  			|| (compl_cont_status & CONT_SOL))
Karsten Hopp 560310
  		    found_new_match = search_for_exact_line(ins_buf, pos,
Karsten Hopp 560310
  					      compl_direction, compl_pattern);
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 4442,4448 ****
Karsten Hopp 560310
  			&& ini->col  == pos->col)
Karsten Hopp 560310
  		    continue;
Karsten Hopp 560310
  		ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
Karsten Hopp 560310
! 		if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  		{
Karsten Hopp 560310
  		    if (compl_cont_status & CONT_ADDING)
Karsten Hopp 560310
  		    {
Karsten Hopp 560310
--- 4447,4453 ----
Karsten Hopp 560310
  			&& ini->col  == pos->col)
Karsten Hopp 560310
  		    continue;
Karsten Hopp 560310
  		ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
Karsten Hopp 560310
! 		if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  		{
Karsten Hopp 560310
  		    if (compl_cont_status & CONT_ADDING)
Karsten Hopp 560310
  		    {
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 4536,4542 ****
Karsten Hopp 560310
  
Karsten Hopp 560310
  	/* break the loop for specialized modes (use 'complete' just for the
Karsten Hopp 560310
  	 * generic ctrl_x_mode == 0) or when we've found a new match */
Karsten Hopp 560310
! 	if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  						   || found_new_match != FAIL)
Karsten Hopp 560310
  	{
Karsten Hopp 560310
  	    if (got_int)
Karsten Hopp 560310
--- 4541,4547 ----
Karsten Hopp 560310
  
Karsten Hopp 560310
  	/* break the loop for specialized modes (use 'complete' just for the
Karsten Hopp 560310
  	 * generic ctrl_x_mode == 0) or when we've found a new match */
Karsten Hopp 560310
! 	if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  						   || found_new_match != FAIL)
Karsten Hopp 560310
  	{
Karsten Hopp 560310
  	    if (got_int)
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 4545,4551 ****
Karsten Hopp 560310
  	    if (type != -1)
Karsten Hopp 560310
  		ins_compl_check_keys(0);
Karsten Hopp 560310
  
Karsten Hopp 560310
! 	    if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  							 || compl_interrupted)
Karsten Hopp 560310
  		break;
Karsten Hopp 560310
  	    compl_started = TRUE;
Karsten Hopp 560310
--- 4550,4556 ----
Karsten Hopp 560310
  	    if (type != -1)
Karsten Hopp 560310
  		ins_compl_check_keys(0);
Karsten Hopp 560310
  
Karsten Hopp 560310
! 	    if ((ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  							 || compl_interrupted)
Karsten Hopp 560310
  		break;
Karsten Hopp 560310
  	    compl_started = TRUE;
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 4561,4573 ****
Karsten Hopp 560310
      }
Karsten Hopp 560310
      compl_started = TRUE;
Karsten Hopp 560310
  
Karsten Hopp 560310
!     if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  	    && *e_cpt == NUL)		/* Got to end of 'complete' */
Karsten Hopp 560310
  	found_new_match = FAIL;
Karsten Hopp 560310
  
Karsten Hopp 560310
      i = -1;		/* total of matches, unknown */
Karsten Hopp 560310
      if (found_new_match == FAIL
Karsten Hopp 560310
! 	    || (ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE))
Karsten Hopp 560310
  	i = ins_compl_make_cyclic();
Karsten Hopp 560310
  
Karsten Hopp 560310
      /* If several matches were added (FORWARD) or the search failed and has
Karsten Hopp 560310
--- 4566,4578 ----
Karsten Hopp 560310
      }
Karsten Hopp 560310
      compl_started = TRUE;
Karsten Hopp 560310
  
Karsten Hopp 560310
!     if ((ctrl_x_mode == 0 || CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  	    && *e_cpt == NUL)		/* Got to end of 'complete' */
Karsten Hopp 560310
  	found_new_match = FAIL;
Karsten Hopp 560310
  
Karsten Hopp 560310
      i = -1;		/* total of matches, unknown */
Karsten Hopp 560310
      if (found_new_match == FAIL
Karsten Hopp 560310
! 	    || (ctrl_x_mode != 0 && !CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode)))
Karsten Hopp 560310
  	i = ins_compl_make_cyclic();
Karsten Hopp 560310
  
Karsten Hopp 560310
      /* If several matches were added (FORWARD) or the search failed and has
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 5052,5058 ****
Karsten Hopp 560310
  		if (compl_length < 1)
Karsten Hopp 560310
  		    compl_cont_status &= CONT_LOCAL;
Karsten Hopp 560310
  	    }
Karsten Hopp 560310
! 	    else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  		compl_cont_status = CONT_ADDING | CONT_N_ADDS;
Karsten Hopp 560310
  	    else
Karsten Hopp 560310
  		compl_cont_status = 0;
Karsten Hopp 560310
--- 5057,5063 ----
Karsten Hopp 560310
  		if (compl_length < 1)
Karsten Hopp 560310
  		    compl_cont_status &= CONT_LOCAL;
Karsten Hopp 560310
  	    }
Karsten Hopp 560310
! 	    else if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  		compl_cont_status = CONT_ADDING | CONT_N_ADDS;
Karsten Hopp 560310
  	    else
Karsten Hopp 560310
  		compl_cont_status = 0;
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 5183,5189 ****
Karsten Hopp 560310
  		}
Karsten Hopp 560310
  	    }
Karsten Hopp 560310
  	}
Karsten Hopp 560310
! 	else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  	{
Karsten Hopp 560310
  	    compl_col = (colnr_T)(skipwhite(line) - line);
Karsten Hopp 560310
  	    compl_length = (int)curs_col - (int)compl_col;
Karsten Hopp 560310
--- 5188,5194 ----
Karsten Hopp 560310
  		}
Karsten Hopp 560310
  	    }
Karsten Hopp 560310
  	}
Karsten Hopp 560310
! 	else if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  	{
Karsten Hopp 560310
  	    compl_col = (colnr_T)(skipwhite(line) - line);
Karsten Hopp 560310
  	    compl_length = (int)curs_col - (int)compl_col;
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 5348,5354 ****
Karsten Hopp 560310
  	if (compl_cont_status & CONT_ADDING)
Karsten Hopp 560310
  	{
Karsten Hopp 560310
  	    edit_submode_pre = (char_u *)_(" Adding");
Karsten Hopp 560310
! 	    if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
Karsten Hopp 560310
  	    {
Karsten Hopp 560310
  		/* Insert a new line, keep indentation but ignore 'comments' */
Karsten Hopp 560310
  #ifdef FEAT_COMMENTS
Karsten Hopp 560310
--- 5353,5359 ----
Karsten Hopp 560310
  	if (compl_cont_status & CONT_ADDING)
Karsten Hopp 560310
  	{
Karsten Hopp 560310
  	    edit_submode_pre = (char_u *)_(" Adding");
Karsten Hopp 560310
! 	    if (CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode))
Karsten Hopp 560310
  	    {
Karsten Hopp 560310
  		/* Insert a new line, keep indentation but ignore 'comments' */
Karsten Hopp 560310
  #ifdef FEAT_COMMENTS
Karsten Hopp 560310
*** ../vim-7.4.652/src/version.c	2015-03-05 17:51:10.788921008 +0100
Karsten Hopp 560310
--- src/version.c	2015-03-05 18:05:13.219424060 +0100
Karsten Hopp 560310
***************
Karsten Hopp 560310
*** 743,744 ****
Karsten Hopp 560310
--- 743,746 ----
Karsten Hopp 560310
  {   /* Add new patch number below this line */
Karsten Hopp 560310
+ /**/
Karsten Hopp 560310
+     653,
Karsten Hopp 560310
  /**/
Karsten Hopp 560310
Karsten Hopp 560310
-- 
Karsten Hopp 560310
I'd like to meet the man who invented sex and see what he's working on now.
Karsten Hopp 560310
Karsten Hopp 560310
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 560310
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 560310
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 560310
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///