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