To: vim_dev@googlegroups.com Subject: Patch 8.1.2378 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2378 Problem: Using old C style comments. Solution: Use // comments where appropriate. Files: src/dict.c, src/diff.c, src/digraph.c, src/dosinst.c, src/edit.c, src/eval.c, src/evalbuffer.c, src/evalfunc.c *** ../vim-8.1.2377/src/dict.c 2019-09-28 17:25:06.518498628 +0200 --- src/dict.c 2019-12-01 20:48:29.630640528 +0100 *************** *** 15,24 **** #if defined(FEAT_EVAL) || defined(PROTO) ! /* List head for garbage collection. Although there can be a reference loop ! * from partial to dict to partial, we don't need to keep track of the partial, ! * since it will get freed when the dict is unused and gets freed. */ ! static dict_T *first_dict = NULL; /* list of all dicts */ /* * Allocate an empty header for a dictionary. --- 15,24 ---- #if defined(FEAT_EVAL) || defined(PROTO) ! // List head for garbage collection. Although there can be a reference loop ! // from partial to dict to partial, we don't need to keep track of the partial, ! // since it will get freed when the dict is unused and gets freed. ! static dict_T *first_dict = NULL; /* * Allocate an empty header for a dictionary. *************** *** 31,37 **** d = ALLOC_CLEAR_ONE(dict_T); if (d != NULL) { ! /* Add the dict to the list of dicts for garbage collection. */ if (first_dict != NULL) first_dict->dv_used_prev = d; d->dv_used_next = first_dict; --- 31,37 ---- d = ALLOC_CLEAR_ONE(dict_T); if (d != NULL) { ! // Add the dict to the list of dicts for garbage collection. if (first_dict != NULL) first_dict->dv_used_prev = d; d->dv_used_next = first_dict; *************** *** 109,123 **** hashitem_T *hi; dictitem_T *di; ! /* Lock the hashtab, we don't want it to resize while freeing items. */ hash_lock(&d->dv_hashtab); todo = (int)d->dv_hashtab.ht_used; for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { ! /* Remove the item before deleting it, just in case there is ! * something recursive causing trouble. */ di = HI2DI(hi); hash_remove(&d->dv_hashtab, hi); dictitem_free(di); --- 109,123 ---- hashitem_T *hi; dictitem_T *di; ! // Lock the hashtab, we don't want it to resize while freeing items. hash_lock(&d->dv_hashtab); todo = (int)d->dv_hashtab.ht_used; for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { ! // Remove the item before deleting it, just in case there is ! // something recursive causing trouble. di = HI2DI(hi); hash_remove(&d->dv_hashtab, hi); dictitem_free(di); *************** *** 125,138 **** } } ! /* The hashtab is still locked, it has to be re-initialized anyway */ hash_clear(&d->dv_hashtab); } static void dict_free_dict(dict_T *d) { ! /* Remove the dict from the list of dicts for garbage collection. */ if (d->dv_used_prev == NULL) first_dict = d->dv_used_next; else --- 125,138 ---- } } ! // The hashtab is still locked, it has to be re-initialized anyway hash_clear(&d->dv_hashtab); } static void dict_free_dict(dict_T *d) { ! // Remove the dict from the list of dicts for garbage collection. if (d->dv_used_prev == NULL) first_dict = d->dv_used_next; else *************** *** 176,184 **** for (dd = first_dict; dd != NULL; dd = dd->dv_used_next) if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) { ! /* Free the Dictionary and ordinary items it contains, but don't ! * recurse into Lists and Dictionaries, they will be in the list ! * of dicts or list of lists. */ dict_free_contents(dd); did_free = TRUE; } --- 176,184 ---- for (dd = first_dict; dd != NULL; dd = dd->dv_used_next) if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) { ! // Free the Dictionary and ordinary items it contains, but don't ! // recurse into Lists and Dictionaries, they will be in the list ! // of dicts or list of lists. dict_free_contents(dd); did_free = TRUE; } *************** *** 577,583 **** } else { ! /* Avoid a malloc/free by using buf[]. */ vim_strncpy(buf, key, len); akey = buf; } --- 577,583 ---- } else { ! // Avoid a malloc/free by using buf[]. vim_strncpy(buf, key, len); akey = buf; } *************** *** 764,770 **** */ if (*start != '}') { ! if (eval1(&start, &tv, FALSE) == FAIL) /* recursive! */ return FAIL; if (*start == '}') return NOTDONE; --- 764,770 ---- */ if (*start != '}') { ! if (eval1(&start, &tv, FALSE) == FAIL) // recursive! return FAIL; if (*start == '}') return NOTDONE; *************** *** 798,811 **** key = tv_get_string_buf_chk(&tvkey, buf); if (key == NULL) { ! /* "key" is NULL when tv_get_string_buf_chk() gave an errmsg */ clear_tv(&tvkey); goto failret; } } *arg = skipwhite(*arg + 1); ! if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */ { if (evaluate) clear_tv(&tvkey); --- 798,811 ---- key = tv_get_string_buf_chk(&tvkey, buf); if (key == NULL) { ! // "key" is NULL when tv_get_string_buf_chk() gave an errmsg clear_tv(&tvkey); goto failret; } } *arg = skipwhite(*arg + 1); ! if (eval1(arg, &tv, evaluate) == FAIL) // recursive! { if (evaluate) clear_tv(&tvkey); *************** *** 881,888 **** di1 = dict_find(d1, hi2->hi_key, -1); if (d1->dv_scope != 0) { ! /* Disallow replacing a builtin function in l: and g:. ! * Check the key to be valid when adding to any scope. */ if (d1->dv_scope == VAR_DEF_SCOPE && HI2DI(hi2)->di_tv.v_type == VAR_FUNC && var_check_func_name(hi2->hi_key, di1 == NULL)) --- 881,888 ---- di1 = dict_find(d1, hi2->hi_key, -1); if (d1->dv_scope != 0) { ! // Disallow replacing a builtin function in l: and g:. ! // Check the key to be valid when adding to any scope. if (d1->dv_scope == VAR_DEF_SCOPE && HI2DI(hi2)->di_tv.v_type == VAR_FUNC && var_check_func_name(hi2->hi_key, di1 == NULL)) *************** *** 929,936 **** dict_equal( dict_T *d1, dict_T *d2, ! int ic, /* ignore case for strings */ ! int recursive) /* TRUE when used recursively */ { hashitem_T *hi; dictitem_T *item2; --- 929,936 ---- dict_equal( dict_T *d1, dict_T *d2, ! int ic, // ignore case for strings ! int recursive) // TRUE when used recursively { hashitem_T *hi; dictitem_T *item2; *************** *** 1004,1022 **** if (what == 0) { ! /* keys() */ li->li_tv.v_type = VAR_STRING; li->li_tv.v_lock = 0; li->li_tv.vval.v_string = vim_strsave(di->di_key); } else if (what == 1) { ! /* values() */ copy_tv(&di->di_tv, &li->li_tv); } else { ! /* items() */ l2 = list_alloc(); li->li_tv.v_type = VAR_LIST; li->li_tv.v_lock = 0; --- 1004,1022 ---- if (what == 0) { ! // keys() li->li_tv.v_type = VAR_STRING; li->li_tv.v_lock = 0; li->li_tv.vval.v_string = vim_strsave(di->di_key); } else if (what == 1) { ! // values() copy_tv(&di->di_tv, &li->li_tv); } else { ! // items() l2 = list_alloc(); li->li_tv.v_type = VAR_LIST; li->li_tv.v_lock = 0; *************** *** 1079,1085 **** int todo = (int)di->dv_hashtab.ht_used; hashitem_T *hi; ! /* Set readonly */ for (hi = di->dv_hashtab.ht_array; todo > 0 ; ++hi) { if (HASHITEM_EMPTY(hi)) --- 1079,1085 ---- int todo = (int)di->dv_hashtab.ht_used; hashitem_T *hi; ! // Set readonly for (hi = di->dv_hashtab.ht_array; todo > 0 ; ++hi) { if (HASHITEM_EMPTY(hi)) *************** *** 1139,1142 **** } } ! #endif /* defined(FEAT_EVAL) */ --- 1139,1142 ---- } } ! #endif // defined(FEAT_EVAL) *** ../vim-8.1.2377/src/diff.c 2019-11-16 13:50:18.773646774 +0100 --- src/diff.c 2019-12-01 20:51:25.410004020 +0100 *************** *** 24,30 **** static int diff_busy = FALSE; // using diff structs, don't change them static int diff_need_update = FALSE; // ex_diffupdate needs to be called ! /* flags obtained from the 'diffopt' option */ #define DIFF_FILLER 0x001 // display filler lines #define DIFF_IBLANK 0x002 // ignore empty lines #define DIFF_ICASE 0x004 // ignore case --- 24,30 ---- static int diff_busy = FALSE; // using diff structs, don't change them static int diff_need_update = FALSE; // ex_diffupdate needs to be called ! // flags obtained from the 'diffopt' option #define DIFF_FILLER 0x001 // display filler lines #define DIFF_IBLANK 0x002 // ignore empty lines #define DIFF_ICASE 0x004 // ignore case *************** *** 41,54 **** static long diff_algorithm = 0; ! #define LBUFLEN 50 /* length of line in diff file */ ! static int diff_a_works = MAYBE; /* TRUE when "diff -a" works, FALSE when it ! doesn't work, MAYBE when not checked yet */ #if defined(MSWIN) ! static int diff_bin_works = MAYBE; /* TRUE when "diff --binary" works, FALSE ! when it doesn't work, MAYBE when not ! checked yet */ #endif // used for diff input --- 41,54 ---- static long diff_algorithm = 0; ! #define LBUFLEN 50 // length of line in diff file ! static int diff_a_works = MAYBE; // TRUE when "diff -a" works, FALSE when it ! // doesn't work, MAYBE when not checked yet #if defined(MSWIN) ! static int diff_bin_works = MAYBE; // TRUE when "diff --binary" works, FALSE ! // when it doesn't work, MAYBE when not ! // checked yet #endif // used for diff input *************** *** 124,131 **** if (!win->w_p_diff) { ! /* When there is no window showing a diff for this buffer, remove ! * it from the diffs. */ FOR_ALL_WINDOWS(wp) if (wp->w_buffer == win->w_buffer && wp->w_p_diff) break; --- 124,131 ---- if (!win->w_p_diff) { ! // When there is no window showing a diff for this buffer, remove ! // it from the diffs. FOR_ALL_WINDOWS(wp) if (wp->w_buffer == win->w_buffer && wp->w_p_diff) break; *************** *** 158,164 **** int i; if (diff_buf_idx(buf) != DB_COUNT) ! return; /* It's already there. */ for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] == NULL) --- 158,164 ---- int i; if (diff_buf_idx(buf) != DB_COUNT) ! return; // It's already there. for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] == NULL) *************** *** 254,260 **** int idx; tabpage_T *tp; ! /* Handle all tab pages that use the current buffer in a diff. */ FOR_ALL_TABPAGES(tp) { idx = diff_buf_idx_tp(curbuf, tp); --- 254,260 ---- int idx; tabpage_T *tp; ! // Handle all tab pages that use the current buffer in a diff. FOR_ALL_TABPAGES(tp) { idx = diff_buf_idx_tp(curbuf, tp); *************** *** 286,292 **** int inserted, deleted; int n, off; linenr_T last; ! linenr_T lnum_deleted = line1; /* lnum of remaining deletion */ int check_unchanged; if (diff_internal()) --- 286,292 ---- int inserted, deleted; int n, off; linenr_T last; ! linenr_T lnum_deleted = line1; // lnum of remaining deletion int check_unchanged; if (diff_internal()) *************** *** 301,319 **** if (line2 == MAXLNUM) { ! /* mark_adjust(99, MAXLNUM, 9, 0): insert lines */ inserted = amount; deleted = 0; } else if (amount_after > 0) { ! /* mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines*/ inserted = amount_after; deleted = 0; } else { ! /* mark_adjust(98, 99, MAXLNUM, -2): delete lines */ inserted = 0; deleted = -amount_after; } --- 301,319 ---- if (line2 == MAXLNUM) { ! // mark_adjust(99, MAXLNUM, 9, 0): insert lines inserted = amount; deleted = 0; } else if (amount_after > 0) { ! // mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines inserted = amount_after; deleted = 0; } else { ! // mark_adjust(98, 99, MAXLNUM, -2): delete lines inserted = 0; deleted = -amount_after; } *************** *** 322,330 **** dp = tp->tp_first_diff; for (;;) { ! /* If the change is after the previous diff block and before the next ! * diff block, thus not touching an existing change, create a new diff ! * block. Don't do this when ex_diffgetput() is busy. */ if ((dp == NULL || dp->df_lnum[idx] - 1 > line2 || (line2 == MAXLNUM && dp->df_lnum[idx] > line1)) && (dprev == NULL --- 322,330 ---- dp = tp->tp_first_diff; for (;;) { ! // If the change is after the previous diff block and before the next ! // diff block, thus not touching an existing change, create a new diff ! // block. Don't do this when ex_diffgetput() is busy. if ((dp == NULL || dp->df_lnum[idx] - 1 > line2 || (line2 == MAXLNUM && dp->df_lnum[idx] > line1)) && (dprev == NULL *************** *** 350,356 **** } } ! /* if at end of the list, quit */ if (dp == NULL) break; --- 350,356 ---- } } ! // if at end of the list, quit if (dp == NULL) break; *************** *** 365,389 **** * 3 5 6 * 3 5 6 */ ! /* compute last line of this change */ last = dp->df_lnum[idx] + dp->df_count[idx] - 1; ! /* 1. change completely above line1: nothing to do */ if (last >= line1 - 1) { ! /* 6. change below line2: only adjust for amount_after; also when ! * "deleted" became zero when deleted all lines between two diffs */ if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2) { if (amount_after == 0) ! break; /* nothing left to change */ dp->df_lnum[idx] += amount_after; } else { check_unchanged = FALSE; ! /* 2. 3. 4. 5.: inserted/deleted lines touching this diff. */ if (deleted > 0) { if (dp->df_lnum[idx] >= line1) --- 365,389 ---- * 3 5 6 * 3 5 6 */ ! // compute last line of this change last = dp->df_lnum[idx] + dp->df_count[idx] - 1; ! // 1. change completely above line1: nothing to do if (last >= line1 - 1) { ! // 6. change below line2: only adjust for amount_after; also when ! // "deleted" became zero when deleted all lines between two diffs if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2) { if (amount_after == 0) ! break; // nothing left to change dp->df_lnum[idx] += amount_after; } else { check_unchanged = FALSE; ! // 2. 3. 4. 5.: inserted/deleted lines touching this diff. if (deleted > 0) { if (dp->df_lnum[idx] >= line1) *************** *** 391,402 **** off = dp->df_lnum[idx] - lnum_deleted; if (last <= line2) { ! /* 4. delete all lines of diff */ if (dp->df_next != NULL && dp->df_next->df_lnum[idx] - 1 <= line2) { ! /* delete continues in next diff, only do ! * lines until that one */ n = dp->df_next->df_lnum[idx] - lnum_deleted; deleted -= n; n -= dp->df_count[idx]; --- 391,402 ---- off = dp->df_lnum[idx] - lnum_deleted; if (last <= line2) { ! // 4. delete all lines of diff if (dp->df_next != NULL && dp->df_next->df_lnum[idx] - 1 <= line2) { ! // delete continues in next diff, only do ! // lines until that one n = dp->df_next->df_lnum[idx] - lnum_deleted; deleted -= n; n -= dp->df_count[idx]; *************** *** 408,414 **** } else { ! /* 5. delete lines at or just before top of diff */ n = off; dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1; check_unchanged = TRUE; --- 408,414 ---- } else { ! // 5. delete lines at or just before top of diff n = off; dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1; check_unchanged = TRUE; *************** *** 420,432 **** off = 0; if (last < line2) { ! /* 2. delete at end of diff */ dp->df_count[idx] -= last - lnum_deleted + 1; if (dp->df_next != NULL && dp->df_next->df_lnum[idx] - 1 <= line2) { ! /* delete continues in next diff, only do ! * lines until that one */ n = dp->df_next->df_lnum[idx] - 1 - last; deleted -= dp->df_next->df_lnum[idx] - lnum_deleted; --- 420,432 ---- off = 0; if (last < line2) { ! // 2. delete at end of diff dp->df_count[idx] -= last - lnum_deleted + 1; if (dp->df_next != NULL && dp->df_next->df_lnum[idx] - 1 <= line2) { ! // delete continues in next diff, only do ! // lines until that one n = dp->df_next->df_lnum[idx] - 1 - last; deleted -= dp->df_next->df_lnum[idx] - lnum_deleted; *************** *** 438,444 **** } else { ! /* 3. delete lines inside the diff */ n = 0; dp->df_count[idx] -= deleted; } --- 438,444 ---- } else { ! // 3. delete lines inside the diff n = 0; dp->df_count[idx] -= deleted; } *************** *** 455,478 **** { if (dp->df_lnum[idx] <= line1) { ! /* inserted lines somewhere in this diff */ dp->df_count[idx] += inserted; check_unchanged = TRUE; } else ! /* inserted lines somewhere above this diff */ dp->df_lnum[idx] += inserted; } if (check_unchanged) ! /* Check if inserted lines are equal, may reduce the ! * size of the diff. TODO: also check for equal lines ! * in the middle and perhaps split the block. */ diff_check_unchanged(tp, dp); } } ! /* check if this block touches the previous one, may merge them. */ if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx] == dp->df_lnum[idx]) { --- 455,478 ---- { if (dp->df_lnum[idx] <= line1) { ! // inserted lines somewhere in this diff dp->df_count[idx] += inserted; check_unchanged = TRUE; } else ! // inserted lines somewhere above this diff dp->df_lnum[idx] += inserted; } if (check_unchanged) ! // Check if inserted lines are equal, may reduce the ! // size of the diff. TODO: also check for equal lines ! // in the middle and perhaps split the block. diff_check_unchanged(tp, dp); } } ! // check if this block touches the previous one, may merge them. if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx] == dp->df_lnum[idx]) { *************** *** 485,491 **** } else { ! /* Advance to next entry. */ dprev = dp; dp = dp->df_next; } --- 485,491 ---- } else { ! // Advance to next entry. dprev = dp; dp = dp->df_next; } *************** *** 495,501 **** dp = tp->tp_first_diff; while (dp != NULL) { ! /* All counts are zero, remove this entry. */ for (i = 0; i < DB_COUNT; ++i) if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) break; --- 495,501 ---- dp = tp->tp_first_diff; while (dp != NULL) { ! // All counts are zero, remove this entry. for (i = 0; i < DB_COUNT; ++i) if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) break; *************** *** 511,517 **** } else { ! /* Advance to next entry. */ dprev = dp; dp = dp->df_next; } --- 511,517 ---- } else { ! // Advance to next entry. dprev = dp; dp = dp->df_next; } *************** *** 523,531 **** // Don't redraw right away, this updates the diffs, which can be slow. need_diff_redraw = TRUE; ! /* Need to recompute the scroll binding, may remove or add filler ! * lines (e.g., when adding lines above w_topline). But it's slow when ! * making many changes, postpone until redrawing. */ diff_need_scrollbind = TRUE; } } --- 523,531 ---- // Don't redraw right away, this updates the diffs, which can be slow. need_diff_redraw = TRUE; ! // Need to recompute the scroll binding, may remove or add filler ! // lines (e.g., when adding lines above w_topline). But it's slow when ! // making many changes, postpone until redrawing. diff_need_scrollbind = TRUE; } } *************** *** 565,591 **** char_u *line_org; int dir = FORWARD; ! /* Find the first buffers, use it as the original, compare the other ! * buffer lines against this one. */ for (i_org = 0; i_org < DB_COUNT; ++i_org) if (tp->tp_diffbuf[i_org] != NULL) break; ! if (i_org == DB_COUNT) /* safety check */ return; if (diff_check_sanity(tp, dp) == FAIL) return; ! /* First check lines at the top, then at the bottom. */ off_org = 0; off_new = 0; for (;;) { ! /* Repeat until a line is found which is different or the number of ! * lines has become zero. */ while (dp->df_count[i_org] > 0) { ! /* Copy the line, the next ml_get() will invalidate it. */ if (dir == BACKWARD) off_org = dp->df_count[i_org] - 1; line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], --- 565,591 ---- char_u *line_org; int dir = FORWARD; ! // Find the first buffers, use it as the original, compare the other ! // buffer lines against this one. for (i_org = 0; i_org < DB_COUNT; ++i_org) if (tp->tp_diffbuf[i_org] != NULL) break; ! if (i_org == DB_COUNT) // safety check return; if (diff_check_sanity(tp, dp) == FAIL) return; ! // First check lines at the top, then at the bottom. off_org = 0; off_new = 0; for (;;) { ! // Repeat until a line is found which is different or the number of ! // lines has become zero. while (dp->df_count[i_org] > 0) { ! // Copy the line, the next ml_get() will invalidate it. if (dir == BACKWARD) off_org = dp->df_count[i_org] - 1; line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], *************** *** 598,604 **** continue; if (dir == BACKWARD) off_new = dp->df_count[i_new] - 1; ! /* if other buffer doesn't have this line, it was inserted */ if (off_new < 0 || off_new >= dp->df_count[i_new]) break; if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], --- 598,604 ---- continue; if (dir == BACKWARD) off_new = dp->df_count[i_new] - 1; ! // if other buffer doesn't have this line, it was inserted if (off_new < 0 || off_new >= dp->df_count[i_new]) break; if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], *************** *** 607,617 **** } vim_free(line_org); ! /* Stop when a line isn't equal in all diff buffers. */ if (i_new != DB_COUNT) break; ! /* Line matched in all buffers, remove it from the diff. */ for (i_new = i_org; i_new < DB_COUNT; ++i_new) if (tp->tp_diffbuf[i_new] != NULL) { --- 607,617 ---- } vim_free(line_org); ! // Stop when a line isn't equal in all diff buffers. if (i_new != DB_COUNT) break; ! // Line matched in all buffers, remove it from the diff. for (i_new = i_org; i_new < DB_COUNT; ++i_new) if (tp->tp_diffbuf[i_new] != NULL) { *************** *** 662,669 **** if (dofold && foldmethodIsDiff(wp)) foldUpdateAll(wp); #endif ! /* A change may have made filler lines invalid, need to take care ! * of that for other windows. */ n = diff_check(wp, wp->w_topline); if ((wp != curwin && wp->w_topfill > 0) || n > 0) { --- 662,669 ---- if (dofold && foldmethodIsDiff(wp)) foldUpdateAll(wp); #endif ! // A change may have made filler lines invalid, need to take care ! // of that for other windows. n = diff_check(wp, wp->w_topline); if ((wp != curwin && wp->w_topfill > 0) || n > 0) { *************** *** 1003,1009 **** for (;;) { ! /* There must be a line that contains "1c1". */ if (vim_fgets(linebuf, LBUFLEN, fd)) break; if (STRNCMP(linebuf, "1c1", 3) == 0) --- 1003,1009 ---- for (;;) { ! // There must be a line that contains "1c1". if (vim_fgets(linebuf, LBUFLEN, fd)) break; if (STRNCMP(linebuf, "1c1", 3) == 0) *************** *** 1018,1030 **** } #ifdef FEAT_EVAL ! /* When using 'diffexpr' break here. */ if (*p_dex != NUL) break; #endif #if defined(MSWIN) ! /* If the "-a" argument works, also check if "--binary" works. */ if (ok && diff_a_works == MAYBE && diff_bin_works == MAYBE) { diff_a_works = TRUE; --- 1018,1030 ---- } #ifdef FEAT_EVAL ! // When using 'diffexpr' break here. if (*p_dex != NUL) break; #endif #if defined(MSWIN) ! // If the "-a" argument works, also check if "--binary" works. if (ok && diff_a_works == MAYBE && diff_bin_works == MAYBE) { diff_a_works = TRUE; *************** *** 1033,1050 **** } if (!ok && diff_a_works == TRUE && diff_bin_works == TRUE) { ! /* Tried --binary, but it failed. "-a" works though. */ diff_bin_works = FALSE; ok = TRUE; } #endif ! /* If we checked if "-a" works already, break here. */ if (diff_a_works != MAYBE) break; diff_a_works = ok; ! /* If "-a" works break here, otherwise retry without "-a". */ if (ok) break; } --- 1033,1050 ---- } if (!ok && diff_a_works == TRUE && diff_bin_works == TRUE) { ! // Tried --binary, but it failed. "-a" works though. diff_bin_works = FALSE; ok = TRUE; } #endif ! // If we checked if "-a" works already, break here. if (diff_a_works != MAYBE) break; diff_a_works = ok; ! // If "-a" works break here, otherwise retry without "-a". if (ok) break; } *************** *** 1172,1183 **** void ex_diffpatch(exarg_T *eap) { ! char_u *tmp_orig; /* name of original temp file */ ! char_u *tmp_new; /* name of patched temp file */ char_u *buf = NULL; size_t buflen; win_T *old_curwin = curwin; ! char_u *newname = NULL; /* name of patched file buffer */ #ifdef UNIX char_u dirbuf[MAXPATHL]; char_u *fullname = NULL; --- 1172,1183 ---- void ex_diffpatch(exarg_T *eap) { ! char_u *tmp_orig; // name of original temp file ! char_u *tmp_new; // name of patched temp file char_u *buf = NULL; size_t buflen; win_T *old_curwin = curwin; ! char_u *newname = NULL; // name of patched file buffer #ifdef UNIX char_u dirbuf[MAXPATHL]; char_u *fullname = NULL; *************** *** 1196,1221 **** eap->arg, NULL, NULL, (char_u *)_(BROWSE_FILTER_ALL_FILES), NULL); if (browseFile == NULL) ! return; /* operation cancelled */ eap->arg = browseFile; ! cmdmod.browse = FALSE; /* don't let do_ecmd() browse again */ } #endif ! /* We need two temp file names. */ tmp_orig = vim_tempname('o', FALSE); tmp_new = vim_tempname('n', FALSE); if (tmp_orig == NULL || tmp_new == NULL) goto theend; ! /* Write the current buffer to "tmp_orig". */ if (buf_write(curbuf, tmp_orig, NULL, (linenr_T)1, curbuf->b_ml.ml_line_count, NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) goto theend; #ifdef UNIX ! /* Get the absolute path of the patchfile, changing directory below. */ fullname = FullName_save(eap->arg, FALSE); #endif esc_name = vim_strsave_shellescape( --- 1196,1221 ---- eap->arg, NULL, NULL, (char_u *)_(BROWSE_FILTER_ALL_FILES), NULL); if (browseFile == NULL) ! return; // operation cancelled eap->arg = browseFile; ! cmdmod.browse = FALSE; // don't let do_ecmd() browse again } #endif ! // We need two temp file names. tmp_orig = vim_tempname('o', FALSE); tmp_new = vim_tempname('n', FALSE); if (tmp_orig == NULL || tmp_new == NULL) goto theend; ! // Write the current buffer to "tmp_orig". if (buf_write(curbuf, tmp_orig, NULL, (linenr_T)1, curbuf->b_ml.ml_line_count, NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) goto theend; #ifdef UNIX ! // Get the absolute path of the patchfile, changing directory below. fullname = FullName_save(eap->arg, FALSE); #endif esc_name = vim_strsave_shellescape( *************** *** 1231,1241 **** goto theend; #ifdef UNIX ! /* Temporarily chdir to /tmp, to avoid patching files in the current ! * directory when the patch file contains more than one patch. When we ! * have our own temp dir use that instead, it will be cleaned up when we ! * exit (any .rej files created). Don't change directory if we can't ! * return to the current. */ if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) dirbuf[0] = NUL; else --- 1231,1241 ---- goto theend; #ifdef UNIX ! // Temporarily chdir to /tmp, to avoid patching files in the current ! // directory when the patch file contains more than one patch. When we ! // have our own temp dir use that instead, it will be cleaned up when we ! // exit (any .rej files created). Don't change directory if we can't ! // return to the current. if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) dirbuf[0] = NUL; else *************** *** 1252,1258 **** #ifdef FEAT_EVAL if (*p_pex != NUL) ! /* Use 'patchexpr' to generate the new file. */ eval_patch(tmp_orig, # ifdef UNIX fullname != NULL ? fullname : --- 1252,1258 ---- #ifdef FEAT_EVAL if (*p_pex != NUL) ! // Use 'patchexpr' to generate the new file. eval_patch(tmp_orig, # ifdef UNIX fullname != NULL ? fullname : *************** *** 1261,1271 **** else #endif { ! /* Build the patch command and execute it. Ignore errors. Switch to ! * cooked mode to allow the user to respond to prompts. */ vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s", tmp_new, tmp_orig, esc_name); ! block_autocmds(); /* Avoid ShellCmdPost stuff */ (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); unblock_autocmds(); } --- 1261,1271 ---- else #endif { ! // Build the patch command and execute it. Ignore errors. Switch to ! // cooked mode to allow the user to respond to prompts. vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s", tmp_new, tmp_orig, esc_name); ! block_autocmds(); // Avoid ShellCmdPost stuff (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); unblock_autocmds(); } *************** *** 1279,1288 **** } #endif ! /* patch probably has written over the screen */ redraw_later(CLEAR); ! /* Delete any .orig or .rej file created. */ STRCPY(buf, tmp_new); STRCAT(buf, ".orig"); mch_remove(buf); --- 1279,1288 ---- } #endif ! // patch probably has written over the screen redraw_later(CLEAR); ! // Delete any .orig or .rej file created. STRCPY(buf, tmp_new); STRCAT(buf, ".orig"); mch_remove(buf); *************** *** 1290,1296 **** STRCAT(buf, ".rej"); mch_remove(buf); ! /* Only continue if the output file was created. */ if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0) emsg(_("E816: Cannot read patch output")); else --- 1290,1296 ---- STRCAT(buf, ".rej"); mch_remove(buf); ! // Only continue if the output file was created. if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0) emsg(_("E816: Cannot read patch output")); else *************** *** 1306,1335 **** #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif ! /* don't use a new tab page, each tab page has its own diffs */ cmdmod.tab = 0; if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { ! /* Pretend it was a ":split fname" command */ eap->cmdidx = CMD_split; eap->arg = tmp_new; do_exedit(eap, old_curwin); ! /* check that split worked and editing tmp_new */ if (curwin != old_curwin && win_valid(old_curwin)) { ! /* Set 'diff', 'scrollbind' on and 'wrap' off. */ diff_win_options(curwin, TRUE); diff_win_options(old_curwin, TRUE); if (newname != NULL) { ! /* do a ":file filename.new" on the patched buffer */ eap->arg = newname; ex_file(eap); ! /* Do filetype detection with the new name. */ if (au_has_group((char_u *)"filetypedetect")) do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); } --- 1306,1335 ---- #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif ! // don't use a new tab page, each tab page has its own diffs cmdmod.tab = 0; if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { ! // Pretend it was a ":split fname" command eap->cmdidx = CMD_split; eap->arg = tmp_new; do_exedit(eap, old_curwin); ! // check that split worked and editing tmp_new if (curwin != old_curwin && win_valid(old_curwin)) { ! // Set 'diff', 'scrollbind' on and 'wrap' off. diff_win_options(curwin, TRUE); diff_win_options(old_curwin, TRUE); if (newname != NULL) { ! // do a ":file filename.new" on the patched buffer eap->arg = newname; ex_file(eap); ! // Do filetype detection with the new name. if (au_has_group((char_u *)"filetypedetect")) do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); } *************** *** 1369,1403 **** #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif ! /* Need to compute w_fraction when no redraw happened yet. */ validate_cursor(); set_fraction(curwin); ! /* don't use a new tab page, each tab page has its own diffs */ cmdmod.tab = 0; if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { ! /* Pretend it was a ":split fname" command */ eap->cmdidx = CMD_split; curwin->w_p_diff = TRUE; do_exedit(eap, old_curwin); ! if (curwin != old_curwin) /* split must have worked */ { ! /* Set 'diff', 'scrollbind' on and 'wrap' off. */ diff_win_options(curwin, TRUE); if (win_valid(old_curwin)) { diff_win_options(old_curwin, TRUE); if (bufref_valid(&old_curbuf)) ! /* Move the cursor position to that of the old window. */ curwin->w_cursor.lnum = diff_get_corresponding_line( old_curbuf.br_buf, old_curwin->w_cursor.lnum); } ! /* Now that lines are folded scroll to show the cursor at the same ! * relative position. */ scroll_to_fraction(curwin, curwin->w_height); } } --- 1369,1403 ---- #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif ! // Need to compute w_fraction when no redraw happened yet. validate_cursor(); set_fraction(curwin); ! // don't use a new tab page, each tab page has its own diffs cmdmod.tab = 0; if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) { ! // Pretend it was a ":split fname" command eap->cmdidx = CMD_split; curwin->w_p_diff = TRUE; do_exedit(eap, old_curwin); ! if (curwin != old_curwin) // split must have worked { ! // Set 'diff', 'scrollbind' on and 'wrap' off. diff_win_options(curwin, TRUE); if (win_valid(old_curwin)) { diff_win_options(old_curwin, TRUE); if (bufref_valid(&old_curbuf)) ! // Move the cursor position to that of the old window. curwin->w_cursor.lnum = diff_get_corresponding_line( old_curbuf.br_buf, old_curwin->w_cursor.lnum); } ! // Now that lines are folded scroll to show the cursor at the same ! // relative position. scroll_to_fraction(curwin, curwin->w_height); } } *************** *** 1409,1415 **** void ex_diffthis(exarg_T *eap UNUSED) { ! /* Set 'diff', 'scrollbind' on and 'wrap' off. */ diff_win_options(curwin, TRUE); } --- 1409,1415 ---- void ex_diffthis(exarg_T *eap UNUSED) { ! // Set 'diff', 'scrollbind' on and 'wrap' off. diff_win_options(curwin, TRUE); } *************** *** 1433,1450 **** void diff_win_options( win_T *wp, ! int addbuf) /* Add buffer to diff. */ { # ifdef FEAT_FOLDING win_T *old_curwin = curwin; ! /* close the manually opened folds */ curwin = wp; newFoldLevel(); curwin = old_curwin; # endif ! /* Use 'scrollbind' and 'cursorbind' when available */ if (!wp->w_p_diff) wp->w_p_scb_save = wp->w_p_scb; wp->w_p_scb = TRUE; --- 1433,1450 ---- void diff_win_options( win_T *wp, ! int addbuf) // Add buffer to diff. { # ifdef FEAT_FOLDING win_T *old_curwin = curwin; ! // close the manually opened folds curwin = wp; newFoldLevel(); curwin = old_curwin; # endif ! // Use 'scrollbind' and 'cursorbind' when available if (!wp->w_p_diff) wp->w_p_scb_save = wp->w_p_scb; wp->w_p_scb = TRUE; *************** *** 1473,1484 **** wp->w_p_fen = TRUE; wp->w_p_fdl = 0; foldUpdateAll(wp); ! /* make sure topline is not halfway a fold */ changed_window_setting_win(wp); # endif if (vim_strchr(p_sbo, 'h') == NULL) do_cmdline_cmd((char_u *)"set sbo+=hor"); ! /* Save the current values, to be restored in ex_diffoff(). */ wp->w_p_diff_saved = TRUE; set_diff_option(wp, TRUE); --- 1473,1484 ---- wp->w_p_fen = TRUE; wp->w_p_fdl = 0; foldUpdateAll(wp); ! // make sure topline is not halfway a fold changed_window_setting_win(wp); # endif if (vim_strchr(p_sbo, 'h') == NULL) do_cmdline_cmd((char_u *)"set sbo+=hor"); ! // Save the current values, to be restored in ex_diffoff(). wp->w_p_diff_saved = TRUE; set_diff_option(wp, TRUE); *************** *** 1502,1510 **** { if (eap->forceit ? wp->w_p_diff : wp == curwin) { ! /* Set 'diff' off. If option values were saved in ! * diff_win_options(), restore the ones whose settings seem to have ! * been left over from diff mode. */ set_diff_option(wp, FALSE); if (wp->w_p_diff_saved) --- 1502,1510 ---- { if (eap->forceit ? wp->w_p_diff : wp == curwin) { ! // Set 'diff' off. If option values were saved in ! // diff_win_options(), restore the ones whose settings seem to have ! // been left over from diff mode. set_diff_option(wp, FALSE); if (wp->w_p_diff_saved) *************** *** 1526,1533 **** if (wp->w_p_fdl == 0) wp->w_p_fdl = wp->w_p_fdl_save; ! /* Only restore 'foldenable' when 'foldmethod' is not ! * "manual", otherwise we continue to show the diff folds. */ if (wp->w_p_fen) wp->w_p_fen = foldmethodIsManual(wp) ? FALSE : wp->w_p_fen_save; --- 1526,1533 ---- if (wp->w_p_fdl == 0) wp->w_p_fdl = wp->w_p_fdl_save; ! // Only restore 'foldenable' when 'foldmethod' is not ! // "manual", otherwise we continue to show the diff folds. if (wp->w_p_fen) wp->w_p_fen = foldmethodIsManual(wp) ? FALSE : wp->w_p_fen_save; *************** *** 1535,1554 **** foldUpdateAll(wp); #endif } ! /* remove filler lines */ wp->w_topfill = 0; ! /* make sure topline is not halfway a fold and cursor is ! * invalidated */ changed_window_setting_win(wp); ! /* Note: 'sbo' is not restored, it's a global option. */ diff_buf_adjust(wp); } diffwin |= wp->w_p_diff; } ! /* Also remove hidden buffers from the list. */ if (eap->forceit) diff_buf_clear(); --- 1535,1554 ---- foldUpdateAll(wp); #endif } ! // remove filler lines wp->w_topfill = 0; ! // make sure topline is not halfway a fold and cursor is ! // invalidated changed_window_setting_win(wp); ! // Note: 'sbo' is not restored, it's a global option. diff_buf_adjust(wp); } diffwin |= wp->w_p_diff; } ! // Also remove hidden buffers from the list. if (eap->forceit) diff_buf_clear(); *************** *** 1560,1566 **** diff_clear(curtab); } ! /* Remove "hor" from from 'scrollopt' if there are no diff windows left. */ if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) do_cmdline_cmd((char_u *)"set sbo-=hor"); } --- 1560,1566 ---- diff_clear(curtab); } ! // Remove "hor" from from 'scrollopt' if there are no diff windows left. if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) do_cmdline_cmd((char_u *)"set sbo-=hor"); } *************** *** 1579,1591 **** diff_T *dprev = NULL; diff_T *dp = curtab->tp_first_diff; diff_T *dn, *dpl; ! char_u linebuf[LBUFLEN]; /* only need to hold the diff line */ char_u *line; long off; int i; linenr_T lnum_orig, lnum_new; long count_orig, count_new; ! int notset = TRUE; /* block "*dp" not set yet */ enum { DIFF_ED, DIFF_UNIFIED, --- 1579,1591 ---- diff_T *dprev = NULL; diff_T *dp = curtab->tp_first_diff; diff_T *dn, *dpl; ! char_u linebuf[LBUFLEN]; // only need to hold the diff line char_u *line; long off; int i; linenr_T lnum_orig, lnum_new; long count_orig, count_new; ! int notset = TRUE; // block "*dp" not set yet enum { DIFF_ED, DIFF_UNIFIED, *************** *** 1829,1835 **** int diff_check(win_T *wp, linenr_T lnum) { ! int idx; /* index in tp_diffbuf[] for this buffer */ diff_T *dp; int maxcount; int i; --- 1829,1835 ---- int diff_check(win_T *wp, linenr_T lnum) { ! int idx; // index in tp_diffbuf[] for this buffer diff_T *dp; int maxcount; int i; *************** *** 1837,1862 **** int cmp; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); /* update after a big change */ ! if (curtab->tp_first_diff == NULL || !wp->w_p_diff) /* no diffs at all */ return 0; ! /* safety check: "lnum" must be a buffer line */ if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) return 0; idx = diff_buf_idx(buf); if (idx == DB_COUNT) ! return 0; /* no diffs for buffer "buf" */ #ifdef FEAT_FOLDING ! /* A closed fold never has filler lines. */ if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) return 0; #endif ! /* search for a change that includes "lnum" in the list of diffblocks. */ for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break; --- 1837,1862 ---- int cmp; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); // update after a big change ! if (curtab->tp_first_diff == NULL || !wp->w_p_diff) // no diffs at all return 0; ! // safety check: "lnum" must be a buffer line if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) return 0; idx = diff_buf_idx(buf); if (idx == DB_COUNT) ! return 0; // no diffs for buffer "buf" #ifdef FEAT_FOLDING ! // A closed fold never has filler lines. if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) return 0; #endif ! // search for a change that includes "lnum" in the list of diffblocks. for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break; *************** *** 1867,1875 **** { int zero = FALSE; ! /* Changed or inserted line. If the other buffers have a count of ! * zero, the lines were inserted. If the other buffers have the same ! * count, check if the lines are identical. */ cmp = FALSE; for (i = 0; i < DB_COUNT; ++i) if (i != idx && curtab->tp_diffbuf[i] != NULL) --- 1867,1875 ---- { int zero = FALSE; ! // Changed or inserted line. If the other buffers have a count of ! // zero, the lines were inserted. If the other buffers have the same ! // count, check if the lines are identical. cmp = FALSE; for (i = 0; i < DB_COUNT; ++i) if (i != idx && curtab->tp_diffbuf[i] != NULL) *************** *** 1879,1914 **** else { if (dp->df_count[i] != dp->df_count[idx]) ! return -1; /* nr of lines changed. */ cmp = TRUE; } } if (cmp) { ! /* Compare all lines. If they are equal the lines were inserted ! * in some buffers, deleted in others, but not changed. */ for (i = 0; i < DB_COUNT; ++i) if (i != idx && curtab->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) if (!diff_equal_entry(dp, idx, i)) return -1; } ! /* If there is no buffer with zero lines then there is no difference ! * any longer. Happens when making a change (or undo) that removes ! * the difference. Can't remove the entry here, we might be halfway ! * updating the window. Just report the text as unchanged. Other ! * windows might still show the change though. */ if (zero == FALSE) return 0; return -2; } ! /* If 'diffopt' doesn't contain "filler", return 0. */ if (!(diff_flags & DIFF_FILLER)) return 0; ! /* Insert filler lines above the line just below the change. Will return ! * 0 when this buf had the max count. */ maxcount = 0; for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) --- 1879,1914 ---- else { if (dp->df_count[i] != dp->df_count[idx]) ! return -1; // nr of lines changed. cmp = TRUE; } } if (cmp) { ! // Compare all lines. If they are equal the lines were inserted ! // in some buffers, deleted in others, but not changed. for (i = 0; i < DB_COUNT; ++i) if (i != idx && curtab->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) if (!diff_equal_entry(dp, idx, i)) return -1; } ! // If there is no buffer with zero lines then there is no difference ! // any longer. Happens when making a change (or undo) that removes ! // the difference. Can't remove the entry here, we might be halfway ! // updating the window. Just report the text as unchanged. Other ! // windows might still show the change though. if (zero == FALSE) return 0; return -2; } ! // If 'diffopt' doesn't contain "filler", return 0. if (!(diff_flags & DIFF_FILLER)) return 0; ! // Insert filler lines above the line just below the change. Will return ! // 0 when this buf had the max count. maxcount = 0; for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) *************** *** 2035,2041 **** { int n; ! /* be quick when there are no filler lines */ if (!(diff_flags & DIFF_FILLER)) return 0; n = diff_check(wp, lnum); --- 2035,2041 ---- { int n; ! // be quick when there are no filler lines if (!(diff_flags & DIFF_FILLER)) return 0; n = diff_check(wp, lnum); *************** *** 2061,2096 **** fromidx = diff_buf_idx(frombuf); if (fromidx == DB_COUNT) ! return; /* safety check */ if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); /* update after a big change */ towin->w_topfill = 0; ! /* search for a change that includes "lnum" in the list of diffblocks. */ for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) break; if (dp == NULL) { ! /* After last change, compute topline relative to end of file; no ! * filler lines. */ towin->w_topline = towin->w_buffer->b_ml.ml_line_count - (frombuf->b_ml.ml_line_count - lnum); } else { ! /* Find index for "towin". */ toidx = diff_buf_idx(towin->w_buffer); if (toidx == DB_COUNT) ! return; /* safety check */ towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); if (lnum >= dp->df_lnum[fromidx]) { ! /* Inside a change: compute filler lines. With three or more ! * buffers we need to know the largest count. */ max_count = 0; for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != NULL --- 2061,2096 ---- fromidx = diff_buf_idx(frombuf); if (fromidx == DB_COUNT) ! return; // safety check if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); // update after a big change towin->w_topfill = 0; ! // search for a change that includes "lnum" in the list of diffblocks. for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) break; if (dp == NULL) { ! // After last change, compute topline relative to end of file; no ! // filler lines. towin->w_topline = towin->w_buffer->b_ml.ml_line_count - (frombuf->b_ml.ml_line_count - lnum); } else { ! // Find index for "towin". toidx = diff_buf_idx(towin->w_buffer); if (toidx == DB_COUNT) ! return; // safety check towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); if (lnum >= dp->df_lnum[fromidx]) { ! // Inside a change: compute filler lines. With three or more ! // buffers we need to know the largest count. max_count = 0; for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != NULL *************** *** 2099,2122 **** if (dp->df_count[toidx] == dp->df_count[fromidx]) { ! /* same number of lines: use same filler count */ towin->w_topfill = fromwin->w_topfill; } else if (dp->df_count[toidx] > dp->df_count[fromidx]) { if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) { ! /* more lines in towin and fromwin doesn't show diff ! * lines, only filler lines */ if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) { ! /* towin also only shows filler lines */ towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; towin->w_topfill = fromwin->w_topfill; } else ! /* towin still has some diff lines to show */ towin->w_topline = dp->df_lnum[toidx] + max_count - fromwin->w_topfill; } --- 2099,2122 ---- if (dp->df_count[toidx] == dp->df_count[fromidx]) { ! // same number of lines: use same filler count towin->w_topfill = fromwin->w_topfill; } else if (dp->df_count[toidx] > dp->df_count[fromidx]) { if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) { ! // more lines in towin and fromwin doesn't show diff ! // lines, only filler lines if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) { ! // towin also only shows filler lines towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; towin->w_topfill = fromwin->w_topfill; } else ! // towin still has some diff lines to show towin->w_topline = dp->df_lnum[toidx] + max_count - fromwin->w_topfill; } *************** *** 2124,2139 **** else if (towin->w_topline >= dp->df_lnum[toidx] + dp->df_count[toidx]) { ! /* less lines in towin and no diff lines to show: compute ! * filler lines */ towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; if (diff_flags & DIFF_FILLER) { if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) ! /* fromwin is also out of diff lines */ towin->w_topfill = fromwin->w_topfill; else ! /* fromwin has some diff lines */ towin->w_topfill = dp->df_lnum[fromidx] + max_count - lnum; } --- 2124,2139 ---- else if (towin->w_topline >= dp->df_lnum[toidx] + dp->df_count[toidx]) { ! // less lines in towin and no diff lines to show: compute ! // filler lines towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; if (diff_flags & DIFF_FILLER) { if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) ! // fromwin is also out of diff lines towin->w_topfill = fromwin->w_topfill; else ! // fromwin has some diff lines towin->w_topfill = dp->df_lnum[fromidx] + max_count - lnum; } *************** *** 2141,2147 **** } } ! /* safety check (if diff info gets outdated strange things may happen) */ towin->w_botfill = FALSE; if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) { --- 2141,2147 ---- } } ! // safety check (if diff info gets outdated strange things may happen) towin->w_botfill = FALSE; if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) { *************** *** 2154,2160 **** towin->w_topfill = 0; } ! /* When w_topline changes need to recompute w_botline and cursor position */ invalidate_botline_win(towin); changed_line_abv_curs_win(towin); --- 2154,2160 ---- towin->w_topfill = 0; } ! // When w_topline changes need to recompute w_botline and cursor position invalidate_botline_win(towin); changed_line_abv_curs_win(towin); *************** *** 2287,2293 **** diff_algorithm_new |= diff_indent_heuristic; ! /* Can't have both "horizontal" and "vertical". */ if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) return FAIL; --- 2287,2293 ---- diff_algorithm_new |= diff_indent_heuristic; ! // Can't have both "horizontal" and "vertical". if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) return FAIL; *************** *** 2304,2311 **** diff_redraw(TRUE); ! /* recompute the scroll binding with the new option value, may ! * remove or add filler lines */ check_scrollbind((linenr_T)0, 0L); return OK; --- 2304,2311 ---- diff_redraw(TRUE); ! // recompute the scroll binding with the new option value, may ! // remove or add filler lines check_scrollbind((linenr_T)0, 0L); return OK; *************** *** 2346,2353 **** diff_find_change( win_T *wp, linenr_T lnum, ! int *startp, /* first char of the change */ ! int *endp) /* last char of the change */ { char_u *line_org; char_u *line_new; --- 2346,2353 ---- diff_find_change( win_T *wp, linenr_T lnum, ! int *startp, // first char of the change ! int *endp) // last char of the change { char_u *line_org; char_u *line_new; *************** *** 2361,2379 **** char_u *p1, *p2; int l; ! /* Make a copy of the line, the next ml_get() will invalidate it. */ line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); if (line_org == NULL) return FALSE; idx = diff_buf_idx(wp->w_buffer); ! if (idx == DB_COUNT) /* cannot happen */ { vim_free(line_org); return FALSE; } ! /* search for a change that includes "lnum" in the list of diffblocks. */ for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break; --- 2361,2379 ---- char_u *p1, *p2; int l; ! // Make a copy of the line, the next ml_get() will invalidate it. line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); if (line_org == NULL) return FALSE; idx = diff_buf_idx(wp->w_buffer); ! if (idx == DB_COUNT) // cannot happen { vim_free(line_org); return FALSE; } ! // search for a change that includes "lnum" in the list of diffblocks. for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break; *************** *** 2388,2401 **** for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != NULL && i != idx) { ! /* Skip lines that are not in the other change (filler lines). */ if (off >= dp->df_count[i]) continue; added = FALSE; line_new = ml_get_buf(curtab->tp_diffbuf[i], dp->df_lnum[i] + off, FALSE); ! /* Search for start of difference */ si_org = si_new = 0; while (line_org[si_org] != NUL) { --- 2388,2401 ---- for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != NULL && i != idx) { ! // Skip lines that are not in the other change (filler lines). if (off >= dp->df_count[i]) continue; added = FALSE; line_new = ml_get_buf(curtab->tp_diffbuf[i], dp->df_lnum[i] + off, FALSE); ! // Search for start of difference si_org = si_new = 0; while (line_org[si_org] != NUL) { *************** *** 2420,2434 **** } if (has_mbyte) { ! /* Move back to first byte of character in both lines (may ! * have "nn^" in line_org and "n^ in line_new). */ si_org -= (*mb_head_off)(line_org, line_org + si_org); si_new -= (*mb_head_off)(line_new, line_new + si_new); } if (*startp > si_org) *startp = si_org; ! /* Search for end of difference, if any. */ if (line_org[si_org] != NUL || line_new[si_new] != NUL) { ei_org = (int)STRLEN(line_org); --- 2420,2434 ---- } if (has_mbyte) { ! // Move back to first byte of character in both lines (may ! // have "nn^" in line_org and "n^ in line_new). si_org -= (*mb_head_off)(line_org, line_org + si_org); si_new -= (*mb_head_off)(line_new, line_new + si_new); } if (*startp > si_org) *startp = si_org; ! // Search for end of difference, if any. if (line_org[si_org] != NUL || line_new[si_new] != NUL) { ei_org = (int)STRLEN(line_org); *************** *** 2485,2491 **** int other = FALSE; diff_T *dp; ! /* Return if 'diff' isn't set. */ if (!wp->w_p_diff) return FALSE; --- 2485,2491 ---- int other = FALSE; diff_T *dp; ! // Return if 'diff' isn't set. if (!wp->w_p_diff) return FALSE; *************** *** 2497,2519 **** other = TRUE; } ! /* return here if there are no diffs in the window */ if (idx == -1 || !other) return FALSE; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); /* update after a big change */ ! /* Return if there are no diff blocks. All lines will be folded. */ if (curtab->tp_first_diff == NULL) return TRUE; for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { ! /* If this change is below the line there can't be any further match. */ if (dp->df_lnum[idx] - diff_context > lnum) break; ! /* If this change ends before the line we have a match. */ if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) return FALSE; } --- 2497,2519 ---- other = TRUE; } ! // return here if there are no diffs in the window if (idx == -1 || !other) return FALSE; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); // update after a big change ! // Return if there are no diff blocks. All lines will be folded. if (curtab->tp_first_diff == NULL) return TRUE; for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) { ! // If this change is below the line there can't be any further match. if (dp->df_lnum[idx] - diff_context > lnum) break; ! // If this change ends before the line we have a match. if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) return FALSE; } *************** *** 2581,2587 **** int buf_empty; int found_not_ma = FALSE; ! /* Find the current buffer in the list of diff buffers. */ idx_cur = diff_buf_idx(curbuf); if (idx_cur == DB_COUNT) { --- 2581,2587 ---- int buf_empty; int found_not_ma = FALSE; ! // Find the current buffer in the list of diff buffers. idx_cur = diff_buf_idx(curbuf); if (idx_cur == DB_COUNT) { *************** *** 2591,2597 **** if (*eap->arg == NUL) { ! /* No argument: Find the other buffer in the list of diff buffers. */ for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) if (curtab->tp_diffbuf[idx_other] != curbuf && curtab->tp_diffbuf[idx_other] != NULL) --- 2591,2597 ---- if (*eap->arg == NUL) { ! // No argument: Find the other buffer in the list of diff buffers. for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) if (curtab->tp_diffbuf[idx_other] != curbuf && curtab->tp_diffbuf[idx_other] != NULL) *************** *** 2610,2616 **** return; } ! /* Check that there isn't a third buffer in the list */ for (i = idx_other + 1; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != curbuf && curtab->tp_diffbuf[i] != NULL --- 2610,2616 ---- return; } ! // Check that there isn't a third buffer in the list for (i = idx_other + 1; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != curbuf && curtab->tp_diffbuf[i] != NULL *************** *** 2622,2640 **** } else { ! /* Buffer number or pattern given. Ignore trailing white space. */ p = eap->arg + STRLEN(eap->arg); while (p > eap->arg && VIM_ISWHITE(p[-1])) --p; for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) ; ! if (eap->arg + i == p) /* digits only */ i = atol((char *)eap->arg); else { i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); if (i < 0) ! return; /* error message already given */ } buf = buflist_findnr(i); if (buf == NULL) --- 2622,2640 ---- } else { ! // Buffer number or pattern given. Ignore trailing white space. p = eap->arg + STRLEN(eap->arg); while (p > eap->arg && VIM_ISWHITE(p[-1])) --p; for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) ; ! if (eap->arg + i == p) // digits only i = atol((char *)eap->arg); else { i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); if (i < 0) ! return; // error message already given } buf = buflist_findnr(i); if (buf == NULL) *************** *** 2643,2649 **** return; } if (buf == curbuf) ! return; /* nothing to do */ idx_other = diff_buf_idx(buf); if (idx_other == DB_COUNT) { --- 2643,2649 ---- return; } if (buf == curbuf) ! return; // nothing to do idx_other = diff_buf_idx(buf); if (idx_other == DB_COUNT) { *************** *** 2654,2664 **** diff_busy = TRUE; ! /* When no range given include the line above or below the cursor. */ if (eap->addr_count == 0) { ! /* Make it possible that ":diffget" on the last line gets line below ! * the cursor line when there is no difference above the cursor. */ if (eap->cmdidx == CMD_diffget && eap->line1 == curbuf->b_ml.ml_line_count && diff_check(curwin, eap->line1) == 0 --- 2654,2664 ---- diff_busy = TRUE; ! // When no range given include the line above or below the cursor. if (eap->addr_count == 0) { ! // Make it possible that ":diffget" on the last line gets line below ! // the cursor line when there is no difference above the cursor. if (eap->cmdidx == CMD_diffget && eap->line1 == curbuf->b_ml.ml_line_count && diff_check(curwin, eap->line1) == 0 *************** *** 2677,2691 **** { idx_from = idx_cur; idx_to = idx_other; ! /* Need to make the other buffer the current buffer to be able to make ! * changes in it. */ ! /* set curwin/curbuf to buf and save a few things */ aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); } ! /* May give the warning for a changed buffer here, which can trigger the ! * FileChangedRO autocommand, which may do nasty things and mess ! * everything up. */ if (!curbuf->b_changed) { change_warning(0); --- 2677,2691 ---- { idx_from = idx_cur; idx_to = idx_other; ! // Need to make the other buffer the current buffer to be able to make ! // changes in it. ! // set curwin/curbuf to buf and save a few things aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); } ! // May give the warning for a changed buffer here, which can trigger the ! // FileChangedRO autocommand, which may do nasty things and mess ! // everything up. if (!curbuf->b_changed) { change_warning(0); *************** *** 2700,2706 **** for (dp = curtab->tp_first_diff; dp != NULL; ) { if (dp->df_lnum[idx_cur] > eap->line2 + off) ! break; /* past the range that was specified */ dfree = NULL; lnum = dp->df_lnum[idx_to]; --- 2700,2706 ---- for (dp = curtab->tp_first_diff; dp != NULL; ) { if (dp->df_lnum[idx_cur] > eap->line2 + off) ! break; // past the range that was specified dfree = NULL; lnum = dp->df_lnum[idx_to]; *************** *** 2708,2723 **** if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off && u_save(lnum - 1, lnum + count) != FAIL) { ! /* Inside the specified range and saving for undo worked. */ start_skip = 0; end_skip = 0; if (eap->addr_count > 0) { ! /* A range was specified: check if lines need to be skipped. */ start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; if (start_skip > 0) { ! /* range starts below start of current diff block */ if (start_skip > count) { lnum += count; --- 2708,2723 ---- if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off && u_save(lnum - 1, lnum + count) != FAIL) { ! // Inside the specified range and saving for undo worked. start_skip = 0; end_skip = 0; if (eap->addr_count > 0) { ! // A range was specified: check if lines need to be skipped. start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; if (start_skip > 0) { ! // range starts below start of current diff block if (start_skip > count) { lnum += count; *************** *** 2736,2749 **** - (eap->line2 + off); if (end_skip > 0) { ! /* range ends above end of current/from diff block */ ! if (idx_cur == idx_from) /* :diffput */ { i = dp->df_count[idx_cur] - start_skip - end_skip; if (count > i) count = i; } ! else /* :diffget */ { count -= end_skip; end_skip = dp->df_count[idx_from] - start_skip - count; --- 2736,2749 ---- - (eap->line2 + off); if (end_skip > 0) { ! // range ends above end of current/from diff block ! if (idx_cur == idx_from) // :diffput { i = dp->df_count[idx_cur] - start_skip - end_skip; if (count > i) count = i; } ! else // :diffget { count -= end_skip; end_skip = dp->df_count[idx_from] - start_skip - count; *************** *** 2759,2765 **** added = 0; for (i = 0; i < count; ++i) { ! /* remember deleting the last line of the buffer */ buf_empty = curbuf->b_ml.ml_line_count == 1; ml_delete(lnum, FALSE); --added; --- 2759,2765 ---- added = 0; for (i = 0; i < count; ++i) { ! // remember deleting the last line of the buffer buf_empty = curbuf->b_ml.ml_line_count == 1; ml_delete(lnum, FALSE); --added; *************** *** 2780,2787 **** ++added; if (buf_empty && curbuf->b_ml.ml_line_count == 2) { ! /* Added the first line into an empty buffer, need to ! * delete the dummy empty line. */ buf_empty = FALSE; ml_delete((linenr_T)2, FALSE); } --- 2780,2787 ---- ++added; if (buf_empty && curbuf->b_ml.ml_line_count == 2) { ! // Added the first line into an empty buffer, need to ! // delete the dummy empty line. buf_empty = FALSE; ml_delete((linenr_T)2, FALSE); } *************** *** 2792,2799 **** if (start_skip == 0 && end_skip == 0) { ! /* Check if there are any other buffers and if the diff is ! * equal in them. */ for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != NULL && i != idx_from && i != idx_to --- 2792,2799 ---- if (start_skip == 0 && end_skip == 0) { ! // Check if there are any other buffers and if the diff is ! // equal in them. for (i = 0; i < DB_COUNT; ++i) if (curtab->tp_diffbuf[i] != NULL && i != idx_from && i != idx_to *************** *** 2801,2807 **** break; if (i == DB_COUNT) { ! /* delete the diff entry, the buffers are now equal here */ dfree = dp; dp = dp->df_next; if (dprev == NULL) --- 2801,2807 ---- break; if (i == DB_COUNT) { ! // delete the diff entry, the buffers are now equal here dfree = dp; dp = dp->df_next; if (dprev == NULL) *************** *** 2811,2824 **** } } ! /* Adjust marks. This will change the following entries! */ if (added != 0) { mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); if (curwin->w_cursor.lnum >= lnum) { ! /* Adjust the cursor position if it's in/after the changed ! * lines. */ if (curwin->w_cursor.lnum >= lnum + count) curwin->w_cursor.lnum += added; else if (added < 0) --- 2811,2824 ---- } } ! // Adjust marks. This will change the following entries! if (added != 0) { mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); if (curwin->w_cursor.lnum >= lnum) { ! // Adjust the cursor position if it's in/after the changed ! // lines. if (curwin->w_cursor.lnum >= lnum + count) curwin->w_cursor.lnum += added; else if (added < 0) *************** *** 2829,2850 **** if (dfree != NULL) { ! /* Diff is deleted, update folds in other windows. */ #ifdef FEAT_FOLDING diff_fold_update(dfree, idx_to); #endif vim_free(dfree); } else ! /* mark_adjust() may have changed the count in a wrong way */ dp->df_count[idx_to] = new_count; ! /* When changing the current buffer, keep track of line numbers */ if (idx_cur == idx_to) off += added; } ! /* If before the range or not deleted, go to next diff. */ if (dfree == NULL) { dprev = dp; --- 2829,2850 ---- if (dfree != NULL) { ! // Diff is deleted, update folds in other windows. #ifdef FEAT_FOLDING diff_fold_update(dfree, idx_to); #endif vim_free(dfree); } else ! // mark_adjust() may have changed the count in a wrong way dp->df_count[idx_to] = new_count; ! // When changing the current buffer, keep track of line numbers if (idx_cur == idx_to) off += added; } ! // If before the range or not deleted, go to next diff. if (dfree == NULL) { dprev = dp; *************** *** 2852,2863 **** } } ! /* restore curwin/curbuf and a few other things */ if (eap->cmdidx != CMD_diffget) { ! /* Syncing undo only works for the current buffer, but we change ! * another buffer. Sync undo if the command was typed. This isn't ! * 100% right when ":diffput" is used in a function or mapping. */ if (KeyTyped) u_sync(FALSE); aucmd_restbuf(&aco); --- 2852,2863 ---- } } ! // restore curwin/curbuf and a few other things if (eap->cmdidx != CMD_diffget) { ! // Syncing undo only works for the current buffer, but we change ! // another buffer. Sync undo if the command was typed. This isn't ! // 100% right when ":diffput" is used in a function or mapping. if (KeyTyped) u_sync(FALSE); aucmd_restbuf(&aco); *************** *** 2935,2948 **** return FAIL; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); /* update after a big change */ ! if (curtab->tp_first_diff == NULL) /* no diffs today */ return FAIL; while (--count >= 0) { ! /* Check if already before first diff. */ if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) break; --- 2935,2948 ---- return FAIL; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); // update after a big change ! if (curtab->tp_first_diff == NULL) // no diffs today return FAIL; while (--count >= 0) { ! // Check if already before first diff. if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) break; *************** *** 2961,2971 **** } } ! /* don't end up past the end of the file */ if (lnum > curbuf->b_ml.ml_line_count) lnum = curbuf->b_ml.ml_line_count; ! /* When the cursor didn't move at all we fail. */ if (lnum == curwin->w_cursor.lnum) return FAIL; --- 2961,2971 ---- } } ! // don't end up past the end of the file if (lnum > curbuf->b_ml.ml_line_count) lnum = curbuf->b_ml.ml_line_count; ! // When the cursor didn't move at all we fail. if (lnum == curwin->w_cursor.lnum) return FAIL; *************** *** 2996,3004 **** return lnum1; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); /* update after a big change */ ! if (curtab->tp_first_diff == NULL) /* no diffs today */ return lnum1; for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) --- 2996,3004 ---- return lnum1; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); // update after a big change ! if (curtab->tp_first_diff == NULL) // no diffs today return lnum1; for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) *************** *** 3007,3013 **** return lnum1 - baseline; if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) { ! /* Inside the diffblock */ baseline = lnum1 - dp->df_lnum[idx1]; if (baseline > dp->df_count[idx2]) baseline = dp->df_count[idx2]; --- 3007,3013 ---- return lnum1 - baseline; if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) { ! // Inside the diffblock baseline = lnum1 - dp->df_lnum[idx1]; if (baseline > dp->df_count[idx2]) baseline = dp->df_count[idx2]; *************** *** 3031,3037 **** - (dp->df_lnum[idx2] + dp->df_count[idx2]); } ! /* If we get here then the cursor is after the last diff */ return lnum1 - baseline; } --- 3031,3037 ---- - (dp->df_lnum[idx2] + dp->df_count[idx2]); } ! // If we get here then the cursor is after the last diff return lnum1 - baseline; } *************** *** 3044,3050 **** { linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1); ! /* don't end up past the end of the file */ if (lnum > curbuf->b_ml.ml_line_count) return curbuf->b_ml.ml_line_count; return lnum; --- 3044,3050 ---- { linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1); ! // don't end up past the end of the file if (lnum > curbuf->b_ml.ml_line_count) return curbuf->b_ml.ml_line_count; return lnum; *************** *** 3063,3087 **** linenr_T n; idx = diff_buf_idx(curbuf); ! if (idx == DB_COUNT) /* safety check */ return (linenr_T)0; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); /* update after a big change */ ! /* search for a change that includes "lnum" in the list of diffblocks. */ for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break; ! /* When after the last change, compute relative to the last line number. */ if (dp == NULL) return wp->w_buffer->b_ml.ml_line_count - (curbuf->b_ml.ml_line_count - lnum); ! /* Find index for "wp". */ i = diff_buf_idx(wp->w_buffer); ! if (i == DB_COUNT) /* safety check */ return (linenr_T)0; n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); --- 3063,3087 ---- linenr_T n; idx = diff_buf_idx(curbuf); ! if (idx == DB_COUNT) // safety check return (linenr_T)0; if (curtab->tp_diff_invalid) ! ex_diffupdate(NULL); // update after a big change ! // search for a change that includes "lnum" in the list of diffblocks. for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) break; ! // When after the last change, compute relative to the last line number. if (dp == NULL) return wp->w_buffer->b_ml.ml_line_count - (curbuf->b_ml.ml_line_count - lnum); ! // Find index for "wp". i = diff_buf_idx(wp->w_buffer); ! if (i == DB_COUNT) // safety check return (linenr_T)0; n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); *************** *** 3276,3288 **** int filler_lines; int col; ! if (lnum < 0) /* ignore type error in {lnum} arg */ lnum = 0; if (lnum != prev_lnum || changedtick != CHANGEDTICK(curbuf) || fnum != curbuf->b_fnum) { ! /* New line, buffer, change: need to get the values. */ filler_lines = diff_check(curwin, lnum); if (filler_lines < 0) { --- 3276,3288 ---- int filler_lines; int col; ! if (lnum < 0) // ignore type error in {lnum} arg lnum = 0; if (lnum != prev_lnum || changedtick != CHANGEDTICK(curbuf) || fnum != curbuf->b_fnum) { ! // New line, buffer, change: need to get the values. filler_lines = diff_check(curwin, lnum); if (filler_lines < 0) { *************** *** 3291,3302 **** change_start = MAXCOL; change_end = -1; if (diff_find_change(curwin, lnum, &change_start, &change_end)) ! hlID = HLF_ADD; /* added line */ else ! hlID = HLF_CHD; /* changed line */ } else ! hlID = HLF_ADD; /* added line */ } else hlID = (hlf_T)0; --- 3291,3302 ---- change_start = MAXCOL; change_end = -1; if (diff_find_change(curwin, lnum, &change_start, &change_end)) ! hlID = HLF_ADD; // added line else ! hlID = HLF_CHD; // changed line } else ! hlID = HLF_ADD; // added line } else hlID = (hlf_T)0; *************** *** 3307,3317 **** if (hlID == HLF_CHD || hlID == HLF_TXD) { ! col = tv_get_number(&argvars[1]) - 1; /* ignore type error in {col} */ if (col >= change_start && col <= change_end) ! hlID = HLF_TXD; /* changed text */ else ! hlID = HLF_CHD; /* changed line */ } rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)hlID; #endif --- 3307,3317 ---- if (hlID == HLF_CHD || hlID == HLF_TXD) { ! col = tv_get_number(&argvars[1]) - 1; // ignore type error in {col} if (col >= change_start && col <= change_end) ! hlID = HLF_TXD; // changed text else ! hlID = HLF_CHD; // changed line } rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)hlID; #endif *** ../vim-8.1.2377/src/digraph.c 2019-08-24 21:53:12.000023828 +0200 --- src/digraph.c 2019-12-01 20:52:55.665665757 +0100 *************** *** 26,32 **** static void printdigraph(digr_T *dp, result_T *previous); ! /* digraphs added by the user */ static garray_T user_digraphs = {0, 0, (int)sizeof(digr_T), 10, NULL}; /* --- 26,32 ---- static void printdigraph(digr_T *dp, result_T *previous); ! // digraphs added by the user static garray_T user_digraphs = {0, 0, (int)sizeof(digr_T), 10, NULL}; /* *************** *** 39,209 **** /* * ATARI digraphs */ ! {{'C', ',', 128}, /* ~@ XX */ ! {'u', '"', 129}, /*  */ ! {'e', '\'', 130}, /* ‚ */ ! {'a', '^', 131}, /* ƒ */ ! {'a', '"', 132}, /* „ */ ! {'a', '`', 133}, /* … */ ! {'a', '@', 134}, /* † */ ! {'c', ',', 135}, /* ~G XX */ ! {'e', '^', 136}, /* ~H XX */ ! {'e', '"', 137}, /* ‰ */ ! {'e', '`', 138}, /* Š */ ! {'i', '"', 139}, /* ‹ */ ! {'i', '^', 140}, /* Œ */ ! {'i', '`', 141}, /*  */ ! {'A', '"', 142}, /* Ž */ ! {'A', '@', 143}, /*  */ ! {'E', '\'', 144}, /*  */ ! {'a', 'e', 145}, /* ‘ */ ! {'A', 'E', 146}, /* ’ */ ! {'o', '^', 147}, /* “ */ ! {'o', '"', 148}, /* ” */ ! {'o', '`', 149}, /* • */ ! {'u', '^', 150}, /* – */ ! {'u', '`', 151}, /* — */ ! {'y', '"', 152}, /* ˜ */ ! {'O', '"', 153}, /* ™ */ ! {'U', '"', 154}, /* š */ ! {'c', '|', 155}, /* › */ ! {'$', '$', 156}, /* œ */ ! {'Y', '-', 157}, /* ~] XX */ ! {'s', 's', 158}, /* ž */ ! {'f', 'f', 159}, /* Ÿ */ ! {'a', '\'', 160}, /*   */ ! {'i', '\'', 161}, /* ¡ */ ! {'o', '\'', 162}, /* ¢ */ ! {'u', '\'', 163}, /* £ */ ! {'n', '~', 164}, /* ¤ */ ! {'N', '~', 165}, /* ¥ */ ! {'a', 'a', 166}, /* ¦ */ ! {'o', 'o', 167}, /* § */ ! {'~', '?', 168}, /* ¨ */ ! {'-', 'a', 169}, /* © */ ! {'a', '-', 170}, /* ª */ ! {'1', '2', 171}, /* « */ ! {'1', '4', 172}, /* ¬ */ ! {'~', '!', 173}, /* ­ */ ! {'<', '<', 174}, /* ® */ ! {'>', '>', 175}, /* ¯ */ ! {'j', 'u', 230}, /* æ */ ! {'o', '/', 237}, /* í */ ! {'+', '-', 241}, /* ñ */ ! {'>', '=', 242}, /* ò */ ! {'<', '=', 243}, /* ó */ ! {':', '-', 246}, /* ö */ ! {'~', '~', 247}, /* ÷ */ ! {'~', 'o', 248}, /* ø */ ! {'2', '2', 253}, /* ý */ {NUL, NUL, NUL} }; ! #else /* !__MINT__ */ # ifdef HPUX_DIGRAPHS /* * different HPUX digraphs */ ! {{'A', '`', 161}, /* ¡ */ ! {'A', '^', 162}, /* ¢ */ ! {'E', '`', 163}, /* £ */ ! {'E', '^', 164}, /* ¤ */ ! {'E', '"', 165}, /* ¥ */ ! {'I', '^', 166}, /* ¦ */ ! {'I', '"', 167}, /* § */ ! {'\'', '\'', 168}, /* ¨ */ ! {'`', '`', 169}, /* © */ ! {'^', '^', 170}, /* ª */ ! {'"', '"', 171}, /* « */ ! {'~', '~', 172}, /* ¬ */ ! {'U', '`', 173}, /* ­ */ ! {'U', '^', 174}, /* ® */ ! {'L', '=', 175}, /* ¯ */ ! {'~', '_', 176}, /* ° */ ! {'Y', '\'', 177}, /* ± */ ! {'y', '\'', 178}, /* ² */ ! {'~', 'o', 179}, /* ³ */ ! {'C', ',', 180}, /* ´ */ ! {'c', ',', 181}, /* µ */ ! {'N', '~', 182}, /* ¶ */ ! {'n', '~', 183}, /* · */ ! {'~', '!', 184}, /* ¸ */ ! {'~', '?', 185}, /* ¹ */ ! {'o', 'x', 186}, /* º */ ! {'L', '-', 187}, /* » */ ! {'Y', '=', 188}, /* ¼ */ ! {'p', 'p', 189}, /* ½ */ ! {'f', 'l', 190}, /* ¾ */ ! {'c', '|', 191}, /* ¿ */ ! {'a', '^', 192}, /* À */ ! {'e', '^', 193}, /* Á */ ! {'o', '^', 194}, /*  */ ! {'u', '^', 195}, /* à */ ! {'a', '\'', 196}, /* Ä */ ! {'e', '\'', 197}, /* Å */ ! {'o', '\'', 198}, /* Æ */ ! {'u', '\'', 199}, /* Ç */ ! {'a', '`', 200}, /* È */ ! {'e', '`', 201}, /* É */ ! {'o', '`', 202}, /* Ê */ ! {'u', '`', 203}, /* Ë */ ! {'a', '"', 204}, /* Ì */ ! {'e', '"', 205}, /* Í */ ! {'o', '"', 206}, /* Î */ ! {'u', '"', 207}, /* Ï */ ! {'A', 'o', 208}, /* Ð */ ! {'i', '^', 209}, /* Ñ */ ! {'O', '/', 210}, /* Ò */ ! {'A', 'E', 211}, /* Ó */ ! {'a', 'o', 212}, /* Ô */ ! {'i', '\'', 213}, /* Õ */ ! {'o', '/', 214}, /* Ö */ ! {'a', 'e', 215}, /* × */ ! {'A', '"', 216}, /* Ø */ ! {'i', '`', 217}, /* Ù */ ! {'O', '"', 218}, /* Ú */ ! {'U', '"', 219}, /* Û */ ! {'E', '\'', 220}, /* Ü */ ! {'i', '"', 221}, /* Ý */ ! {'s', 's', 222}, /* Þ */ ! {'O', '^', 223}, /* ß */ ! {'A', '\'', 224}, /* à */ ! {'A', '~', 225}, /* á */ ! {'a', '~', 226}, /* â */ ! {'D', '-', 227}, /* ã */ ! {'d', '-', 228}, /* ä */ ! {'I', '\'', 229}, /* å */ ! {'I', '`', 230}, /* æ */ ! {'O', '\'', 231}, /* ç */ ! {'O', '`', 232}, /* è */ ! {'O', '~', 233}, /* é */ ! {'o', '~', 234}, /* ê */ ! {'S', '~', 235}, /* ë */ ! {'s', '~', 236}, /* ì */ ! {'U', '\'', 237}, /* í */ ! {'Y', '"', 238}, /* î */ ! {'y', '"', 239}, /* ï */ ! {'p', '-', 240}, /* ð */ ! {'p', '~', 241}, /* ñ */ ! {'~', '.', 242}, /* ò */ ! {'j', 'u', 243}, /* ó */ ! {'P', 'p', 244}, /* ô */ ! {'3', '4', 245}, /* õ */ ! {'-', '-', 246}, /* ö */ ! {'1', '4', 247}, /* ÷ */ ! {'1', '2', 248}, /* ø */ ! {'a', '_', 249}, /* ù */ ! {'o', '_', 250}, /* ú */ ! {'<', '<', 251}, /* û */ ! {'x', 'x', 252}, /* ü */ ! {'>', '>', 253}, /* ý */ ! {'+', '-', 254}, /* þ */ ! {'n', 'u', 255}, /* x XX */ {NUL, NUL, NUL} }; ! # else /* !HPUX_DIGRAPHS */ # ifdef EBCDIC --- 39,209 ---- /* * ATARI digraphs */ ! {{'C', ',', 128}, // ~@ XX ! {'u', '"', 129}, //  ! {'e', '\'', 130}, // ‚ ! {'a', '^', 131}, // ƒ ! {'a', '"', 132}, // „ ! {'a', '`', 133}, // … ! {'a', '@', 134}, // † ! {'c', ',', 135}, // ~G XX ! {'e', '^', 136}, // ~H XX ! {'e', '"', 137}, // ‰ ! {'e', '`', 138}, // Š ! {'i', '"', 139}, // ‹ ! {'i', '^', 140}, // Œ ! {'i', '`', 141}, //  ! {'A', '"', 142}, // Ž ! {'A', '@', 143}, //  ! {'E', '\'', 144}, //  ! {'a', 'e', 145}, // ‘ ! {'A', 'E', 146}, // ’ ! {'o', '^', 147}, // “ ! {'o', '"', 148}, // ” ! {'o', '`', 149}, // • ! {'u', '^', 150}, // – ! {'u', '`', 151}, // — ! {'y', '"', 152}, // ˜ ! {'O', '"', 153}, // ™ ! {'U', '"', 154}, // š ! {'c', '|', 155}, // › ! {'$', '$', 156}, // œ ! {'Y', '-', 157}, // ~] XX ! {'s', 's', 158}, // ž ! {'f', 'f', 159}, // Ÿ ! {'a', '\'', 160}, //   ! {'i', '\'', 161}, // ¡ ! {'o', '\'', 162}, // ¢ ! {'u', '\'', 163}, // £ ! {'n', '~', 164}, // ¤ ! {'N', '~', 165}, // ¥ ! {'a', 'a', 166}, // ¦ ! {'o', 'o', 167}, // § ! {'~', '?', 168}, // ¨ ! {'-', 'a', 169}, // © ! {'a', '-', 170}, // ª ! {'1', '2', 171}, // « ! {'1', '4', 172}, // ¬ ! {'~', '!', 173}, // ­ ! {'<', '<', 174}, // ® ! {'>', '>', 175}, // ¯ ! {'j', 'u', 230}, // æ ! {'o', '/', 237}, // í ! {'+', '-', 241}, // ñ ! {'>', '=', 242}, // ò ! {'<', '=', 243}, // ó ! {':', '-', 246}, // ö ! {'~', '~', 247}, // ÷ ! {'~', 'o', 248}, // ø ! {'2', '2', 253}, // ý {NUL, NUL, NUL} }; ! #else // !__MINT__ # ifdef HPUX_DIGRAPHS /* * different HPUX digraphs */ ! {{'A', '`', 161}, // ¡ ! {'A', '^', 162}, // ¢ ! {'E', '`', 163}, // £ ! {'E', '^', 164}, // ¤ ! {'E', '"', 165}, // ¥ ! {'I', '^', 166}, // ¦ ! {'I', '"', 167}, // § ! {'\'', '\'', 168}, // ¨ ! {'`', '`', 169}, // © ! {'^', '^', 170}, // ª ! {'"', '"', 171}, // « ! {'~', '~', 172}, // ¬ ! {'U', '`', 173}, // ­ ! {'U', '^', 174}, // ® ! {'L', '=', 175}, // ¯ ! {'~', '_', 176}, // ° ! {'Y', '\'', 177}, // ± ! {'y', '\'', 178}, // ² ! {'~', 'o', 179}, // ³ ! {'C', ',', 180}, // ´ ! {'c', ',', 181}, // µ ! {'N', '~', 182}, // ¶ ! {'n', '~', 183}, // · ! {'~', '!', 184}, // ¸ ! {'~', '?', 185}, // ¹ ! {'o', 'x', 186}, // º ! {'L', '-', 187}, // » ! {'Y', '=', 188}, // ¼ ! {'p', 'p', 189}, // ½ ! {'f', 'l', 190}, // ¾ ! {'c', '|', 191}, // ¿ ! {'a', '^', 192}, // À ! {'e', '^', 193}, // Á ! {'o', '^', 194}, //  ! {'u', '^', 195}, // à ! {'a', '\'', 196}, // Ä ! {'e', '\'', 197}, // Å ! {'o', '\'', 198}, // Æ ! {'u', '\'', 199}, // Ç ! {'a', '`', 200}, // È ! {'e', '`', 201}, // É ! {'o', '`', 202}, // Ê ! {'u', '`', 203}, // Ë ! {'a', '"', 204}, // Ì ! {'e', '"', 205}, // Í ! {'o', '"', 206}, // Î ! {'u', '"', 207}, // Ï ! {'A', 'o', 208}, // Ð ! {'i', '^', 209}, // Ñ ! {'O', '/', 210}, // Ò ! {'A', 'E', 211}, // Ó ! {'a', 'o', 212}, // Ô ! {'i', '\'', 213}, // Õ ! {'o', '/', 214}, // Ö ! {'a', 'e', 215}, // × ! {'A', '"', 216}, // Ø ! {'i', '`', 217}, // Ù ! {'O', '"', 218}, // Ú ! {'U', '"', 219}, // Û ! {'E', '\'', 220}, // Ü ! {'i', '"', 221}, // Ý ! {'s', 's', 222}, // Þ ! {'O', '^', 223}, // ß ! {'A', '\'', 224}, // à ! {'A', '~', 225}, // á ! {'a', '~', 226}, // â ! {'D', '-', 227}, // ã ! {'d', '-', 228}, // ä ! {'I', '\'', 229}, // å ! {'I', '`', 230}, // æ ! {'O', '\'', 231}, // ç ! {'O', '`', 232}, // è ! {'O', '~', 233}, // é ! {'o', '~', 234}, // ê ! {'S', '~', 235}, // ë ! {'s', '~', 236}, // ì ! {'U', '\'', 237}, // í ! {'Y', '"', 238}, // î ! {'y', '"', 239}, // ï ! {'p', '-', 240}, // ð ! {'p', '~', 241}, // ñ ! {'~', '.', 242}, // ò ! {'j', 'u', 243}, // ó ! {'P', 'p', 244}, // ô ! {'3', '4', 245}, // õ ! {'-', '-', 246}, // ö ! {'1', '4', 247}, // ÷ ! {'1', '2', 248}, // ø ! {'a', '_', 249}, // ù ! {'o', '_', 250}, // ú ! {'<', '<', 251}, // û ! {'x', 'x', 252}, // ü ! {'>', '>', 253}, // ý ! {'+', '-', 254}, // þ ! {'n', 'u', 255}, // x XX {NUL, NUL, NUL} }; ! # else // !HPUX_DIGRAPHS # ifdef EBCDIC *************** *** 211,317 **** * EBCDIC - ISO digraphs * TODO: EBCDIC Table is Code-Page 1047 */ ! {{'a', '^', 66}, /* â */ ! {'a', '"', 67}, /* ä */ ! {'a', '`', 68}, /* à */ ! {'a', '\'', 69}, /* á */ ! {'a', '~', 70}, /* ã */ ! {'a', '@', 71}, /* å */ ! {'a', 'a', 71}, /* å */ ! {'c', ',', 72}, /* ç */ ! {'n', '~', 73}, /* ñ */ ! {'c', '|', 74}, /* ¢ */ ! {'e', '\'', 81}, /* é */ ! {'e', '^', 82}, /* ê */ ! {'e', '"', 83}, /* ë */ ! {'e', '`', 84}, /* è */ ! {'i', '\'', 85}, /* í */ ! {'i', '^', 86}, /* î */ ! {'i', '"', 87}, /* ï */ ! {'i', '`', 88}, /* ì */ ! {'s', 's', 89}, /* ß */ ! {'A', '^', 98}, /*  */ ! {'A', '"', 99}, /* Ä */ ! {'A', '`', 100}, /* À */ ! {'A', '\'', 101}, /* Á */ ! {'A', '~', 102}, /* à */ ! {'A', '@', 103}, /* Å */ ! {'A', 'A', 103}, /* Å */ ! {'C', ',', 104}, /* Ç */ ! {'N', '~', 105}, /* Ñ */ ! {'|', '|', 106}, /* ¦ */ ! {'o', '/', 112}, /* ø */ ! {'E', '\'', 113}, /* É */ ! {'E', '^', 114}, /* Ê */ ! {'E', '"', 115}, /* Ë */ ! {'E', '`', 116}, /* È */ ! {'I', '\'', 117}, /* Í */ ! {'I', '^', 118}, /* Î */ ! {'I', '"', 119}, /* Ï */ ! {'I', '`', 120}, /* Ì */ ! {'O', '/', 128}, /* 0/ XX */ ! {'<', '<', 138}, /* « */ ! {'>', '>', 139}, /* » */ ! {'d', '-', 140}, /* ð */ ! {'y', '\'', 141}, /* ý */ ! {'i', 'p', 142}, /* þ */ ! {'+', '-', 143}, /* ± */ ! {'~', 'o', 144}, /* ° */ ! {'a', '-', 154}, /* ª */ ! {'o', '-', 155}, /* º */ ! {'a', 'e', 156}, /* æ */ ! {',', ',', 157}, /* , XX */ ! {'A', 'E', 158}, /* Æ */ ! {'o', 'x', 159}, /* ¤ - currency symbol in ISO 8859-1 */ ! {'e', '=', 159}, /* ¤ - euro symbol in ISO 8859-15 */ ! {'E', 'u', 159}, /* ¤ - euro symbol in ISO 8859-15 */ ! {'j', 'u', 160}, /* µ */ ! {'y', '"', 167}, /* x XX */ ! {'~', '!', 170}, /* ¡ */ ! {'~', '?', 171}, /* ¿ */ ! {'D', '-', 172}, /* Ð */ ! {'I', 'p', 174}, /* Þ */ ! {'r', 'O', 175}, /* ® */ ! {'-', ',', 176}, /* ¬ */ ! {'$', '$', 177}, /* £ */ ! {'Y', '-', 178}, /* ¥ */ ! {'~', '.', 179}, /* · */ ! {'c', 'O', 180}, /* © */ ! {'p', 'a', 181}, /* § */ ! {'p', 'p', 182}, /* ¶ */ ! {'1', '4', 183}, /* ¼ */ ! {'1', '2', 184}, /* ½ */ ! {'3', '4', 185}, /* ¾ */ ! {'Y', '\'', 186}, /* Ý */ ! {'"', '"', 187}, /* ¨ */ ! {'-', '=', 188}, /* ¯ */ ! {'\'', '\'', 190}, /* ´ */ ! {'O', 'E', 191}, /* × - OE in ISO 8859-15 */ ! {'/', '\\', 191}, /* × - multiplication symbol in ISO 8859-1 */ ! {'-', '-', 202}, /* ­ */ ! {'o', '^', 203}, /* ô */ ! {'o', '"', 204}, /* ö */ ! {'o', '`', 205}, /* ò */ ! {'o', '\'', 206}, /* ó */ ! {'o', '~', 207}, /* õ */ ! {'1', '1', 218}, /* ¹ */ ! {'u', '^', 219}, /* û */ ! {'u', '"', 220}, /* ü */ ! {'u', '`', 221}, /* ù */ ! {'u', '\'', 222}, /* ú */ ! {':', '-', 225}, /* ÷ - division symbol in ISO 8859-1 */ ! {'o', 'e', 225}, /* ÷ - oe in ISO 8859-15 */ ! {'2', '2', 234}, /* ² */ ! {'O', '^', 235}, /* Ô */ ! {'O', '"', 236}, /* Ö */ ! {'O', '`', 237}, /* Ò */ ! {'O', '\'', 238}, /* Ó */ ! {'O', '~', 239}, /* Õ */ ! {'3', '3', 250}, /* ³ */ ! {'U', '^', 251}, /* Û */ ! {'U', '"', 252}, /* Ü */ ! {'U', '`', 253}, /* Ù */ ! {'U', '\'', 254}, /* Ú */ {NUL, NUL, NUL} }; --- 211,317 ---- * EBCDIC - ISO digraphs * TODO: EBCDIC Table is Code-Page 1047 */ ! {{'a', '^', 66}, // â ! {'a', '"', 67}, // ä ! {'a', '`', 68}, // à ! {'a', '\'', 69}, // á ! {'a', '~', 70}, // ã ! {'a', '@', 71}, // å ! {'a', 'a', 71}, // å ! {'c', ',', 72}, // ç ! {'n', '~', 73}, // ñ ! {'c', '|', 74}, // ¢ ! {'e', '\'', 81}, // é ! {'e', '^', 82}, // ê ! {'e', '"', 83}, // ë ! {'e', '`', 84}, // è ! {'i', '\'', 85}, // í ! {'i', '^', 86}, // î ! {'i', '"', 87}, // ï ! {'i', '`', 88}, // ì ! {'s', 's', 89}, // ß ! {'A', '^', 98}, //  ! {'A', '"', 99}, // Ä ! {'A', '`', 100}, // À ! {'A', '\'', 101}, // Á ! {'A', '~', 102}, // à ! {'A', '@', 103}, // Å ! {'A', 'A', 103}, // Å ! {'C', ',', 104}, // Ç ! {'N', '~', 105}, // Ñ ! {'|', '|', 106}, // ¦ ! {'o', '/', 112}, // ø ! {'E', '\'', 113}, // É ! {'E', '^', 114}, // Ê ! {'E', '"', 115}, // Ë ! {'E', '`', 116}, // È ! {'I', '\'', 117}, // Í ! {'I', '^', 118}, // Î ! {'I', '"', 119}, // Ï ! {'I', '`', 120}, // Ì ! {'O', '/', 128}, // 0/ XX ! {'<', '<', 138}, // « ! {'>', '>', 139}, // » ! {'d', '-', 140}, // ð ! {'y', '\'', 141}, // ý ! {'i', 'p', 142}, // þ ! {'+', '-', 143}, // ± ! {'~', 'o', 144}, // ° ! {'a', '-', 154}, // ª ! {'o', '-', 155}, // º ! {'a', 'e', 156}, // æ ! {',', ',', 157}, // , XX ! {'A', 'E', 158}, // Æ ! {'o', 'x', 159}, // ¤ - currency symbol in ISO 8859-1 ! {'e', '=', 159}, // ¤ - euro symbol in ISO 8859-15 ! {'E', 'u', 159}, // ¤ - euro symbol in ISO 8859-15 ! {'j', 'u', 160}, // µ ! {'y', '"', 167}, // x XX ! {'~', '!', 170}, // ¡ ! {'~', '?', 171}, // ¿ ! {'D', '-', 172}, // Ð ! {'I', 'p', 174}, // Þ ! {'r', 'O', 175}, // ® ! {'-', ',', 176}, // ¬ ! {'$', '$', 177}, // £ ! {'Y', '-', 178}, // ¥ ! {'~', '.', 179}, // · ! {'c', 'O', 180}, // © ! {'p', 'a', 181}, // § ! {'p', 'p', 182}, // ¶ ! {'1', '4', 183}, // ¼ ! {'1', '2', 184}, // ½ ! {'3', '4', 185}, // ¾ ! {'Y', '\'', 186}, // Ý ! {'"', '"', 187}, // ¨ ! {'-', '=', 188}, // ¯ ! {'\'', '\'', 190}, // ´ ! {'O', 'E', 191}, // × - OE in ISO 8859-15 ! {'/', '\\', 191}, // × - multiplication symbol in ISO 8859-1 ! {'-', '-', 202}, // ­ ! {'o', '^', 203}, // ô ! {'o', '"', 204}, // ö ! {'o', '`', 205}, // ò ! {'o', '\'', 206}, // ó ! {'o', '~', 207}, // õ ! {'1', '1', 218}, // ¹ ! {'u', '^', 219}, // û ! {'u', '"', 220}, // ü ! {'u', '`', 221}, // ù ! {'u', '\'', 222}, // ú ! {':', '-', 225}, // ÷ - division symbol in ISO 8859-1 ! {'o', 'e', 225}, // ÷ - oe in ISO 8859-15 ! {'2', '2', 234}, // ² ! {'O', '^', 235}, // Ô ! {'O', '"', 236}, // Ö ! {'O', '`', 237}, // Ò ! {'O', '\'', 238}, // Ó ! {'O', '~', 239}, // Õ ! {'3', '3', 250}, // ³ ! {'U', '^', 251}, // Û ! {'U', '"', 252}, // Ü ! {'U', '`', 253}, // Ù ! {'U', '\'', 254}, // Ú {NUL, NUL, NUL} }; *************** *** 321,436 **** /* * digraphs compatible with Vim 5.x */ ! {{'~', '!', 161}, /* ¡ */ ! {'c', '|', 162}, /* ¢ */ ! {'$', '$', 163}, /* £ */ ! {'o', 'x', 164}, /* ¤ - currency symbol in ISO 8859-1 */ ! {'e', '=', 164}, /* ¤ - euro symbol in ISO 8859-15 */ ! {'Y', '-', 165}, /* ¥ */ ! {'|', '|', 166}, /* ¦ */ ! {'p', 'a', 167}, /* § */ ! {'"', '"', 168}, /* ¨ */ ! {'c', 'O', 169}, /* © */ ! {'a', '-', 170}, /* ª */ ! {'<', '<', 171}, /* « */ ! {'-', ',', 172}, /* ¬ */ ! {'-', '-', 173}, /* ­ */ ! {'r', 'O', 174}, /* ® */ ! {'-', '=', 175}, /* ¯ */ ! {'~', 'o', 176}, /* ° */ ! {'+', '-', 177}, /* ± */ ! {'2', '2', 178}, /* ² */ ! {'3', '3', 179}, /* ³ */ ! {'\'', '\'', 180}, /* ´ */ ! {'j', 'u', 181}, /* µ */ ! {'p', 'p', 182}, /* ¶ */ ! {'~', '.', 183}, /* · */ ! {',', ',', 184}, /* ¸ */ ! {'1', '1', 185}, /* ¹ */ ! {'o', '-', 186}, /* º */ ! {'>', '>', 187}, /* » */ ! {'1', '4', 188}, /* ¼ */ ! {'1', '2', 189}, /* ½ */ ! {'3', '4', 190}, /* ¾ */ ! {'~', '?', 191}, /* ¿ */ ! {'A', '`', 192}, /* À */ ! {'A', '\'', 193}, /* Á */ ! {'A', '^', 194}, /*  */ ! {'A', '~', 195}, /* à */ ! {'A', '"', 196}, /* Ä */ ! {'A', '@', 197}, /* Å */ ! {'A', 'A', 197}, /* Å */ ! {'A', 'E', 198}, /* Æ */ ! {'C', ',', 199}, /* Ç */ ! {'E', '`', 200}, /* È */ ! {'E', '\'', 201}, /* É */ ! {'E', '^', 202}, /* Ê */ ! {'E', '"', 203}, /* Ë */ ! {'I', '`', 204}, /* Ì */ ! {'I', '\'', 205}, /* Í */ ! {'I', '^', 206}, /* Î */ ! {'I', '"', 207}, /* Ï */ ! {'D', '-', 208}, /* Ð */ ! {'N', '~', 209}, /* Ñ */ ! {'O', '`', 210}, /* Ò */ ! {'O', '\'', 211}, /* Ó */ ! {'O', '^', 212}, /* Ô */ ! {'O', '~', 213}, /* Õ */ ! {'O', '"', 214}, /* Ö */ ! {'/', '\\', 215}, /* × - multiplication symbol in ISO 8859-1 */ ! {'O', 'E', 215}, /* × - OE in ISO 8859-15 */ ! {'O', '/', 216}, /* Ø */ ! {'U', '`', 217}, /* Ù */ ! {'U', '\'', 218}, /* Ú */ ! {'U', '^', 219}, /* Û */ ! {'U', '"', 220}, /* Ü */ ! {'Y', '\'', 221}, /* Ý */ ! {'I', 'p', 222}, /* Þ */ ! {'s', 's', 223}, /* ß */ ! {'a', '`', 224}, /* à */ ! {'a', '\'', 225}, /* á */ ! {'a', '^', 226}, /* â */ ! {'a', '~', 227}, /* ã */ ! {'a', '"', 228}, /* ä */ ! {'a', '@', 229}, /* å */ ! {'a', 'a', 229}, /* å */ ! {'a', 'e', 230}, /* æ */ ! {'c', ',', 231}, /* ç */ ! {'e', '`', 232}, /* è */ ! {'e', '\'', 233}, /* é */ ! {'e', '^', 234}, /* ê */ ! {'e', '"', 235}, /* ë */ ! {'i', '`', 236}, /* ì */ ! {'i', '\'', 237}, /* í */ ! {'i', '^', 238}, /* î */ ! {'i', '"', 239}, /* ï */ ! {'d', '-', 240}, /* ð */ ! {'n', '~', 241}, /* ñ */ ! {'o', '`', 242}, /* ò */ ! {'o', '\'', 243}, /* ó */ ! {'o', '^', 244}, /* ô */ ! {'o', '~', 245}, /* õ */ ! {'o', '"', 246}, /* ö */ ! {':', '-', 247}, /* ÷ - division symbol in ISO 8859-1 */ ! {'o', 'e', 247}, /* ÷ - oe in ISO 8859-15 */ ! {'o', '/', 248}, /* ø */ ! {'u', '`', 249}, /* ù */ ! {'u', '\'', 250}, /* ú */ ! {'u', '^', 251}, /* û */ ! {'u', '"', 252}, /* ü */ ! {'y', '\'', 253}, /* ý */ ! {'i', 'p', 254}, /* þ */ ! {'y', '"', 255}, /* x XX */ {NUL, NUL, NUL} }; ! # else /* OLD_DIGRAPHS */ /* * digraphs for Unicode from RFC1345 * (also work for ISO-8859-1 aka latin1) */ { ! {'N', 'U', 0x0a}, /* LF for NUL */ {'S', 'H', 0x01}, {'S', 'X', 0x02}, {'E', 'X', 0x03}, --- 321,436 ---- /* * digraphs compatible with Vim 5.x */ ! {{'~', '!', 161}, // ¡ ! {'c', '|', 162}, // ¢ ! {'$', '$', 163}, // £ ! {'o', 'x', 164}, // ¤ - currency symbol in ISO 8859-1 ! {'e', '=', 164}, // ¤ - euro symbol in ISO 8859-15 ! {'Y', '-', 165}, // ¥ ! {'|', '|', 166}, // ¦ ! {'p', 'a', 167}, // § ! {'"', '"', 168}, // ¨ ! {'c', 'O', 169}, // © ! {'a', '-', 170}, // ª ! {'<', '<', 171}, // « ! {'-', ',', 172}, // ¬ ! {'-', '-', 173}, // ­ ! {'r', 'O', 174}, // ® ! {'-', '=', 175}, // ¯ ! {'~', 'o', 176}, // ° ! {'+', '-', 177}, // ± ! {'2', '2', 178}, // ² ! {'3', '3', 179}, // ³ ! {'\'', '\'', 180}, // ´ ! {'j', 'u', 181}, // µ ! {'p', 'p', 182}, // ¶ ! {'~', '.', 183}, // · ! {',', ',', 184}, // ¸ ! {'1', '1', 185}, // ¹ ! {'o', '-', 186}, // º ! {'>', '>', 187}, // » ! {'1', '4', 188}, // ¼ ! {'1', '2', 189}, // ½ ! {'3', '4', 190}, // ¾ ! {'~', '?', 191}, // ¿ ! {'A', '`', 192}, // À ! {'A', '\'', 193}, // Á ! {'A', '^', 194}, //  ! {'A', '~', 195}, // à ! {'A', '"', 196}, // Ä ! {'A', '@', 197}, // Å ! {'A', 'A', 197}, // Å ! {'A', 'E', 198}, // Æ ! {'C', ',', 199}, // Ç ! {'E', '`', 200}, // È ! {'E', '\'', 201}, // É ! {'E', '^', 202}, // Ê ! {'E', '"', 203}, // Ë ! {'I', '`', 204}, // Ì ! {'I', '\'', 205}, // Í ! {'I', '^', 206}, // Î ! {'I', '"', 207}, // Ï ! {'D', '-', 208}, // Ð ! {'N', '~', 209}, // Ñ ! {'O', '`', 210}, // Ò ! {'O', '\'', 211}, // Ó ! {'O', '^', 212}, // Ô ! {'O', '~', 213}, // Õ ! {'O', '"', 214}, // Ö ! {'/', '\\', 215}, // × - multiplication symbol in ISO 8859-1 ! {'O', 'E', 215}, // × - OE in ISO 8859-15 ! {'O', '/', 216}, // Ø ! {'U', '`', 217}, // Ù ! {'U', '\'', 218}, // Ú ! {'U', '^', 219}, // Û ! {'U', '"', 220}, // Ü ! {'Y', '\'', 221}, // Ý ! {'I', 'p', 222}, // Þ ! {'s', 's', 223}, // ß ! {'a', '`', 224}, // à ! {'a', '\'', 225}, // á ! {'a', '^', 226}, // â ! {'a', '~', 227}, // ã ! {'a', '"', 228}, // ä ! {'a', '@', 229}, // å ! {'a', 'a', 229}, // å ! {'a', 'e', 230}, // æ ! {'c', ',', 231}, // ç ! {'e', '`', 232}, // è ! {'e', '\'', 233}, // é ! {'e', '^', 234}, // ê ! {'e', '"', 235}, // ë ! {'i', '`', 236}, // ì ! {'i', '\'', 237}, // í ! {'i', '^', 238}, // î ! {'i', '"', 239}, // ï ! {'d', '-', 240}, // ð ! {'n', '~', 241}, // ñ ! {'o', '`', 242}, // ò ! {'o', '\'', 243}, // ó ! {'o', '^', 244}, // ô ! {'o', '~', 245}, // õ ! {'o', '"', 246}, // ö ! {':', '-', 247}, // ÷ - division symbol in ISO 8859-1 ! {'o', 'e', 247}, // ÷ - oe in ISO 8859-15 ! {'o', '/', 248}, // ø ! {'u', '`', 249}, // ù ! {'u', '\'', 250}, // ú ! {'u', '^', 251}, // û ! {'u', '"', 252}, // ü ! {'y', '\'', 253}, // ý ! {'i', 'p', 254}, // þ ! {'y', '"', 255}, // x XX {NUL, NUL, NUL} }; ! # else // OLD_DIGRAPHS /* * digraphs for Unicode from RFC1345 * (also work for ISO-8859-1 aka latin1) */ { ! {'N', 'U', 0x0a}, // LF for NUL {'S', 'H', 0x01}, {'S', 'X', 0x02}, {'E', 'X', 0x03}, *************** *** 1287,1296 **** {'L', 'i', 0x20a4}, {'P', 't', 0x20a7}, {'W', '=', 0x20a9}, ! {'=', 'e', 0x20ac}, /* euro */ ! {'E', 'u', 0x20ac}, /* euro */ ! {'=', 'R', 0x20bd}, /* rouble */ ! {'=', 'P', 0x20bd}, /* rouble */ #define DG_START_OTHER1 0x2103 {'o', 'C', 0x2103}, {'c', 'o', 0x2105}, --- 1287,1296 ---- {'L', 'i', 0x20a4}, {'P', 't', 0x20a7}, {'W', '=', 0x20a9}, ! {'=', 'e', 0x20ac}, // euro ! {'E', 'u', 0x20ac}, // euro ! {'=', 'R', 0x20bd}, // rouble ! {'=', 'P', 0x20bd}, // rouble #define DG_START_OTHER1 0x2103 {'o', 'C', 0x2103}, {'c', 'o', 0x2105}, *************** *** 1815,1822 **** {'7', 'c', 0x3226}, {'8', 'c', 0x3227}, {'9', 'c', 0x3228}, ! /* code points 0xe000 - 0xefff excluded, they have no assigned ! * characters, only used in proposals. */ {'f', 'f', 0xfb00}, {'f', 'i', 0xfb01}, {'f', 'l', 0xfb02}, --- 1815,1822 ---- {'7', 'c', 0x3226}, {'8', 'c', 0x3227}, {'9', 'c', 0x3228}, ! // code points 0xe000 - 0xefff excluded, they have no assigned ! // characters, only used in proposals. {'f', 'f', 0xfb00}, {'f', 'i', 0xfb01}, {'f', 'l', 0xfb02}, *************** *** 1826,1835 **** {NUL, NUL, NUL} }; ! # endif /* OLD_DIGRAPHS */ ! # endif /* EBCDIC */ ! # endif /* !HPUX_DIGRAPHS */ ! #endif /* !__MINT__ */ /* * handle digraphs after typing a character --- 1826,1835 ---- {NUL, NUL, NUL} }; ! # endif // OLD_DIGRAPHS ! # endif // EBCDIC ! # endif // !HPUX_DIGRAPHS ! #endif // !__MINT__ /* * handle digraphs after typing a character *************** *** 1837,1846 **** int do_digraph(int c) { ! static int backspaced; /* character before K_BS */ ! static int lastchar; /* last typed character */ ! if (c == -1) /* init values */ { backspaced = -1; } --- 1837,1846 ---- int do_digraph(int c) { ! static int backspaced; // character before K_BS ! static int lastchar; // last typed character ! if (c == -1) // init values { backspaced = -1; } *************** *** 1921,1927 **** */ int get_digraph( ! int cmdline) /* TRUE when called from the cmdline */ { int c, cc; --- 1921,1927 ---- */ int get_digraph( ! int cmdline) // TRUE when called from the cmdline { int c, cc; *************** *** 1930,1938 **** c = plain_vgetc(); --no_mapping; --allow_keys; ! if (c != ESC) /* ESC cancels CTRL-K */ { ! if (IS_SPECIAL(c)) /* insert special key code */ return c; if (cmdline) { --- 1930,1938 ---- c = plain_vgetc(); --no_mapping; --allow_keys; ! if (c != ESC) // ESC cancels CTRL-K { ! if (IS_SPECIAL(c)) // insert special key code return c; if (cmdline) { *************** *** 1952,1958 **** cc = plain_vgetc(); --no_mapping; --allow_keys; ! if (cc != ESC) /* ESC cancels CTRL-K */ return getdigraph(c, cc, TRUE); } return NUL; --- 1952,1958 ---- cc = plain_vgetc(); --no_mapping; --allow_keys; ! if (cc != ESC) // ESC cancels CTRL-K return getdigraph(c, cc, TRUE); } return NUL; *************** *** 2029,2041 **** } #endif ! /* Ignore multi-byte characters when not in multi-byte mode. */ if (!has_mbyte && retval > 0xff) retval = 0; ! if (retval == 0) /* digraph deleted or not found */ { ! if (char1 == ' ' && meta_char) /* --> meta-char */ return (char2 | 0x80); return char2; } --- 2029,2041 ---- } #endif ! // Ignore multi-byte characters when not in multi-byte mode. if (!has_mbyte && retval > 0xff) retval = 0; ! if (retval == 0) // digraph deleted or not found { ! if (char1 == ' ' && meta_char) // --> meta-char return (char2 | 0x80); return char2; } *************** *** 2094,2100 **** } n = getdigits(&str); ! /* If the digraph already exists, replace the result. */ dp = (digr_T *)user_digraphs.ga_data; for (i = 0; i < user_digraphs.ga_len; ++i) { --- 2094,2100 ---- } n = getdigits(&str); ! // If the digraph already exists, replace the result. dp = (digr_T *)user_digraphs.ga_data; for (i = 0; i < user_digraphs.ga_len; ++i) { *************** *** 2106,2112 **** ++dp; } ! /* Add a new digraph to the table. */ if (i == user_digraphs.ga_len) { if (ga_grow(&user_digraphs, 1) == OK) --- 2106,2112 ---- ++dp; } ! // Add a new digraph to the table. if (i == user_digraphs.ga_len) { if (ga_grow(&user_digraphs, 1) == OK) *************** *** 2147,2153 **** #if defined(USE_UNICODE_DIGRAPHS) digr_T tmp; ! /* May need to convert the result to 'encoding'. */ tmp.char1 = dp->char1; tmp.char2 = dp->char2; tmp.result = getexactdigraph(tmp.char1, tmp.char2, FALSE); --- 2147,2153 ---- #if defined(USE_UNICODE_DIGRAPHS) digr_T tmp; ! // May need to convert the result to 'encoding'. tmp.char1 = dp->char1; tmp.char2 = dp->char2; tmp.result = getexactdigraph(tmp.char1, tmp.char2, FALSE); *************** *** 2176,2183 **** ui_breakcheck(); ++dp; } ! must_redraw = CLEAR; /* clear screen, because some digraphs may be ! wrong, in which case we messed up ScreenLines */ } static struct dg_header_entry { --- 2176,2183 ---- ui_breakcheck(); ++dp; } ! must_redraw = CLEAR; // clear screen, because some digraphs may be ! // wrong, in which case we messed up ScreenLines } static struct dg_header_entry { *************** *** 2259,2265 **** p = buf; if (has_mbyte) { ! /* add a space to draw a composing char on */ if (enc_utf8 && utf_iscomposing(dp->result)) *p++ = ' '; p += (*mb_char2bytes)(dp->result, p); --- 2259,2265 ---- p = buf; if (has_mbyte) { ! // add a space to draw a composing char on if (enc_utf8 && utf_iscomposing(dp->result)) *p++ = ' '; p += (*mb_char2bytes)(dp->result, p); *************** *** 2276,2293 **** } } ! #endif /* FEAT_DIGRAPHS */ #if defined(FEAT_KEYMAP) || defined(PROTO) ! /* structure used for b_kmap_ga.ga_data */ typedef struct { char_u *from; char_u *to; } kmap_T; ! #define KMAP_MAXLEN 20 /* maximum length of "from" or "to" */ static void keymap_unload(void); --- 2276,2293 ---- } } ! #endif // FEAT_DIGRAPHS #if defined(FEAT_KEYMAP) || defined(PROTO) ! // structure used for b_kmap_ga.ga_data typedef struct { char_u *from; char_u *to; } kmap_T; ! #define KMAP_MAXLEN 20 // maximum length of "from" or "to" static void keymap_unload(void); *************** *** 2304,2311 **** if (*curbuf->b_p_keymap == NUL) { ! /* Stop any active keymap and clear the table. Also remove ! * b:keymap_name, as no keymap is active now. */ keymap_unload(); do_cmdline_cmd((char_u *)"unlet! b:keymap_name"); } --- 2304,2311 ---- if (*curbuf->b_p_keymap == NUL) { ! // Stop any active keymap and clear the table. Also remove ! // b:keymap_name, as no keymap is active now. keymap_unload(); do_cmdline_cmd((char_u *)"unlet! b:keymap_name"); } *************** *** 2314,2332 **** char_u *buf; size_t buflen; ! /* Source the keymap file. It will contain a ":loadkeymap" command ! * which will call ex_loadkeymap() below. */ buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14; buf = alloc(buflen); if (buf == NULL) return e_outofmem; ! /* try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' */ vim_snprintf((char *)buf, buflen, "keymap/%s_%s.vim", curbuf->b_p_keymap, p_enc); if (source_runtime(buf, 0) == FAIL) { ! /* try finding "keymap/'keymap'.vim" in 'runtimepath' */ vim_snprintf((char *)buf, buflen, "keymap/%s.vim", curbuf->b_p_keymap); if (source_runtime(buf, 0) == FAIL) --- 2314,2332 ---- char_u *buf; size_t buflen; ! // Source the keymap file. It will contain a ":loadkeymap" command ! // which will call ex_loadkeymap() below. buflen = STRLEN(curbuf->b_p_keymap) + STRLEN(p_enc) + 14; buf = alloc(buflen); if (buf == NULL) return e_outofmem; ! // try finding "keymap/'keymap'_'encoding'.vim" in 'runtimepath' vim_snprintf((char *)buf, buflen, "keymap/%s_%s.vim", curbuf->b_p_keymap, p_enc); if (source_runtime(buf, 0) == FAIL) { ! // try finding "keymap/'keymap'.vim" in 'runtimepath' vim_snprintf((char *)buf, buflen, "keymap/%s.vim", curbuf->b_p_keymap); if (source_runtime(buf, 0) == FAIL) *************** *** 2351,2357 **** char_u *p; char_u *s; kmap_T *kp; ! #define KMAP_LLEN 200 /* max length of "to" and "from" together */ char_u buf[KMAP_LLEN + 11]; int i; char_u *save_cpo = p_cpo; --- 2351,2357 ---- char_u *p; char_u *s; kmap_T *kp; ! #define KMAP_LLEN 200 // max length of "to" and "from" together char_u buf[KMAP_LLEN + 11]; int i; char_u *save_cpo = p_cpo; *************** *** 2370,2376 **** curbuf->b_kmap_state = 0; ga_init2(&curbuf->b_kmap_ga, (int)sizeof(kmap_T), 20); ! /* Set 'cpoptions' to "C" to avoid line continuation. */ p_cpo = (char_u *)"C"; /* --- 2370,2376 ---- curbuf->b_kmap_state = 0; ga_init2(&curbuf->b_kmap_ga, (int)sizeof(kmap_T), 20); ! // Set 'cpoptions' to "C" to avoid line continuation. p_cpo = (char_u *)"C"; /* *************** *** 2438,2447 **** if (!(curbuf->b_kmap_state & KEYMAP_LOADED)) return; ! /* Set 'cpoptions' to "C" to avoid line continuation. */ p_cpo = (char_u *)"C"; ! /* clear the ":lmap"s */ kp = (kmap_T *)curbuf->b_kmap_ga.ga_data; for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { --- 2438,2447 ---- if (!(curbuf->b_kmap_state & KEYMAP_LOADED)) return; ! // Set 'cpoptions' to "C" to avoid line continuation. p_cpo = (char_u *)"C"; ! // clear the ":lmap"s kp = (kmap_T *)curbuf->b_kmap_ga.ga_data; for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { *************** *** 2469,2472 **** vim_free(kp[i].to); } } ! #endif /* FEAT_KEYMAP */ --- 2469,2472 ---- vim_free(kp[i].to); } } ! #endif // FEAT_KEYMAP *** ../vim-8.1.2377/src/dosinst.c 2019-09-27 13:07:59.573833437 +0200 --- src/dosinst.c 2019-12-01 20:57:04.684704037 +0100 *************** *** 23,29 **** #define GVIMEXT64_PATH "GvimExt64\\gvimext.dll" #define GVIMEXT32_PATH "GvimExt32\\gvimext.dll" ! /* Macro to do an error check I was typing over and over */ #define CHECK_REG_ERROR(code) \ do { \ if (code != ERROR_SUCCESS) \ --- 23,29 ---- #define GVIMEXT64_PATH "GvimExt64\\gvimext.dll" #define GVIMEXT32_PATH "GvimExt32\\gvimext.dll" ! // Macro to do an error check I was typing over and over #define CHECK_REG_ERROR(code) \ do { \ if (code != ERROR_SUCCESS) \ *************** *** 33,63 **** } \ } while (0) ! int has_vim = 0; /* installable vim.exe exists */ ! int has_gvim = 0; /* installable gvim.exe exists */ ! char oldvimrc[BUFSIZE]; /* name of existing vimrc file */ ! char vimrc[BUFSIZE]; /* name of vimrc file to create */ ! char *default_bat_dir = NULL; /* when not NULL, use this as the default ! directory to write .bat files in */ ! char *default_vim_dir = NULL; /* when not NULL, use this as the default ! install dir for NSIS */ /* * Structure used for each choice the user can make. */ struct choice { ! int active; /* non-zero when choice is active */ ! char *text; /* text displayed for this choice */ ! void (*changefunc)(int idx); /* function to change this choice */ ! int arg; /* argument for function */ ! void (*installfunc)(int idx); /* function to install this choice */ }; ! struct choice choices[30]; /* choices the user can make */ ! int choice_count = 0; /* number of choices available */ #define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s)) --- 33,63 ---- } \ } while (0) ! int has_vim = 0; // installable vim.exe exists ! int has_gvim = 0; // installable gvim.exe exists ! char oldvimrc[BUFSIZE]; // name of existing vimrc file ! char vimrc[BUFSIZE]; // name of vimrc file to create ! char *default_bat_dir = NULL; // when not NULL, use this as the default ! // directory to write .bat files in ! char *default_vim_dir = NULL; // when not NULL, use this as the default ! // install dir for NSIS /* * Structure used for each choice the user can make. */ struct choice { ! int active; // non-zero when choice is active ! char *text; // text displayed for this choice ! void (*changefunc)(int idx); // function to change this choice ! int arg; // argument for function ! void (*installfunc)(int idx); // function to install this choice }; ! struct choice choices[30]; // choices the user can make ! int choice_count = 0; // number of choices available #define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s)) *************** *** 123,135 **** "In your HOME directory", }; ! /* non-zero when selected to install the popup menu entry. */ static int install_popup = 0; ! /* non-zero when selected to install the "Open with" entry. */ static int install_openwith = 0; ! /* non-zero when need to add an uninstall entry in the registry */ static int need_uninstall_entry = 0; /* --- 123,135 ---- "In your HOME directory", }; ! // non-zero when selected to install the popup menu entry. static int install_popup = 0; ! // non-zero when selected to install the "Open with" entry. static int install_openwith = 0; ! // non-zero when need to add an uninstall entry in the registry static int need_uninstall_entry = 0; /* *************** *** 191,197 **** FILE *fd; struct stat st; ! /* check for presence of the correct version number in installdir[] */ runtimeidx = strlen(installdir) - strlen(VIM_VERSION_NODOT); if (runtimeidx <= 0 || stricmp(installdir + runtimeidx, VIM_VERSION_NODOT) != 0 --- 191,197 ---- FILE *fd; struct stat st; ! // check for presence of the correct version number in installdir[] runtimeidx = strlen(installdir) - strlen(VIM_VERSION_NODOT); if (runtimeidx <= 0 || stricmp(installdir + runtimeidx, VIM_VERSION_NODOT) != 0 *************** *** 204,211 **** myexit(1); } ! /* check if filetype.vim is present, which means the runtime archive has ! * been unpacked */ sprintf(buf, "%s\\filetype.vim", installdir); if (stat(buf, &st) < 0) { --- 204,211 ---- myexit(1); } ! // check if filetype.vim is present, which means the runtime archive has ! // been unpacked sprintf(buf, "%s\\filetype.vim", installdir); if (stat(buf, &st) < 0) { *************** *** 216,222 **** myexit(1); } ! /* Check if vim.exe or gvim.exe is in the current directory. */ if ((fd = fopen("gvim.exe", "r")) != NULL) { fclose(fd); --- 216,222 ---- myexit(1); } ! // Check if vim.exe or gvim.exe is in the current directory. if ((fd = fopen("gvim.exe", "r")) != NULL) { fclose(fd); *************** *** 251,282 **** qlen = strlen(q); for (i = 0; ; ++i) { ! /* End of "p": check if "q" also ends or just has a slash. */ if (i == plen) { ! if (i == qlen) /* match */ return 0; if (i == qlen - 1 && (q[i] == '\\' || q[i] == '/')) ! return 0; /* match with trailing slash */ ! return 1; /* no match */ } ! /* End of "q": check if "p" also ends or just has a slash. */ if (i == qlen) { ! if (i == plen) /* match */ return 0; if (i == plen - 1 && (p[i] == '\\' || p[i] == '/')) ! return 0; /* match with trailing slash */ ! return 1; /* no match */ } if (!(mytoupper(p[i]) == mytoupper(q[i]) || ((p[i] == '/' || p[i] == '\\') && (q[i] == '/' || q[i] == '\\')))) ! return 1; /* no match */ } ! /*NOTREACHED*/ } /* --- 251,282 ---- qlen = strlen(q); for (i = 0; ; ++i) { ! // End of "p": check if "q" also ends or just has a slash. if (i == plen) { ! if (i == qlen) // match return 0; if (i == qlen - 1 && (q[i] == '\\' || q[i] == '/')) ! return 0; // match with trailing slash ! return 1; // no match } ! // End of "q": check if "p" also ends or just has a slash. if (i == qlen) { ! if (i == plen) // match return 0; if (i == plen - 1 && (p[i] == '\\' || p[i] == '/')) ! return 0; // match with trailing slash ! return 1; // no match } if (!(mytoupper(p[i]) == mytoupper(q[i]) || ((p[i] == '/' || p[i] == '\\') && (q[i] == '/' || q[i] == '\\')))) ! return 1; // no match } ! //NOTREACHED } /* *************** *** 308,314 **** tmpname = alloc(strlen(cp) + 1); strcpy(tmpname, cp); ! tmpname[strlen(tmpname) - 1] = 'x'; /* .exe -> .exx */ if (access(tmpname, 0) == 0) { --- 308,314 ---- tmpname = alloc(strlen(cp) + 1); strcpy(tmpname, cp); ! tmpname[strlen(tmpname) - 1] = 'x'; // .exe -> .exx if (access(tmpname, 0) == 0) { *************** *** 347,353 **** { int i; ! /* avoid looking in the "installdir" by chdir to system root */ mch_chdir(sysdrive); mch_chdir("\\"); --- 347,353 ---- { int i; ! // avoid looking in the "installdir" by chdir to system root mch_chdir(sysdrive); mch_chdir("\\"); *************** *** 386,392 **** FILE *fd; char fname[BUFSIZE]; ! /* First get $VIMRUNTIME. If it's set, remove the tail. */ vim = getenv("VIMRUNTIME"); if (vim != NULL && *vim != 0 && strlen(vim) < sizeof(buf)) { --- 386,392 ---- FILE *fd; char fname[BUFSIZE]; ! // First get $VIMRUNTIME. If it's set, remove the tail. vim = getenv("VIMRUNTIME"); if (vim != NULL && *vim != 0 && strlen(vim) < sizeof(buf)) { *************** *** 399,416 **** vim = getenv("VIM"); if (vim == NULL || *vim == 0) { ! /* Use the directory from an old uninstall entry. */ if (default_vim_dir != NULL) vim = default_vim_dir; else ! /* Let NSIS know there is no default, it should use ! * $PROGRAMFILES. */ vim = ""; } } ! /* NSIS also uses GetTempPath(), thus we should get the same directory ! * name as where NSIS will look for vimini.ini. */ GetTempPath(sizeof(fname) - 12, fname); add_pathsep(fname); strcat(fname, "vimini.ini"); --- 399,416 ---- vim = getenv("VIM"); if (vim == NULL || *vim == 0) { ! // Use the directory from an old uninstall entry. if (default_vim_dir != NULL) vim = default_vim_dir; else ! // Let NSIS know there is no default, it should use ! // $PROGRAMFILES. vim = ""; } } ! // NSIS also uses GetTempPath(), thus we should get the same directory ! // name as where NSIS will look for vimini.ini. GetTempPath(sizeof(fname) - 12, fname); add_pathsep(fname); strcat(fname, "vimini.ini"); *************** *** 418,425 **** fd = fopen(fname, "w"); if (fd != NULL) { ! /* Make it look like an .ini file, so that NSIS can read it with a ! * ReadINIStr command. */ fprintf(fd, "[vimini]\n"); fprintf(fd, "dir=\"%s\"\n", vim); fclose(fd); --- 418,425 ---- fd = fopen(fname, "w"); if (fd != NULL) { ! // Make it look like an .ini file, so that NSIS can read it with a ! // ReadINIStr command. fprintf(fd, "[vimini]\n"); fprintf(fd, "dir=\"%s\"\n", vim); fclose(fd); *************** *** 437,443 **** * Callback used for EnumWindows(): * Count the window if the title looks like it is for the uninstaller. */ ! /*ARGSUSED*/ static BOOL CALLBACK window_cb(HWND hwnd, LPARAM lparam) { --- 437,443 ---- * Callback used for EnumWindows(): * Count the window if the title looks like it is for the uninstaller. */ ! //ARGSUSED static BOOL CALLBACK window_cb(HWND hwnd, LPARAM lparam) { *************** *** 469,475 **** if (!GetTempPath(sizeof(temp_dir), temp_dir)) return FAIL; ! /* Copy the uninstaller to a temporary exe. */ tick = GetTickCount(); for (i = 0; ; i++) { --- 469,475 ---- if (!GetTempPath(sizeof(temp_dir), temp_dir)) return FAIL; ! // Copy the uninstaller to a temporary exe. tick = GetTickCount(); for (i = 0; ; i++) { *************** *** 483,489 **** return FAIL; } ! /* Run the copied uninstaller silently. */ if (strchr(temp_uninst, ' ') != NULL) sprintf(buf, "\"%s\" /S _?=%s", temp_uninst, vimrt_dir); else --- 483,489 ---- return FAIL; } ! // Run the copied uninstaller silently. if (strchr(temp_uninst, ' ') != NULL) sprintf(buf, "\"%s\" /S _?=%s", temp_uninst, vimrt_dir); else *************** *** 531,542 **** if (strncmp("Vim", subkey_name_buff, 3) == 0) { ! /* Open the key named Vim* */ code = RegOpenKeyEx(key_handle, subkey_name_buff, 0, KEY_WOW64_64KEY | KEY_READ, &uninstall_key_handle); CHECK_REG_ERROR(code); ! /* get the DisplayName out of it to show the user */ local_bufsize = sizeof(temp_string_buffer); code = RegQueryValueEx(uninstall_key_handle, "displayname", 0, &value_type, (LPBYTE)temp_string_buffer, --- 531,542 ---- if (strncmp("Vim", subkey_name_buff, 3) == 0) { ! // Open the key named Vim* code = RegOpenKeyEx(key_handle, subkey_name_buff, 0, KEY_WOW64_64KEY | KEY_READ, &uninstall_key_handle); CHECK_REG_ERROR(code); ! // get the DisplayName out of it to show the user local_bufsize = sizeof(temp_string_buffer); code = RegQueryValueEx(uninstall_key_handle, "displayname", 0, &value_type, (LPBYTE)temp_string_buffer, *************** *** 569,581 **** printf("\nDo you want to uninstall \"%s\" now?\n(y)es/(n)o) ", temp_string_buffer); fflush(stdout); ! /* get the UninstallString */ local_bufsize = sizeof(temp_string_buffer); code = RegQueryValueEx(uninstall_key_handle, "uninstallstring", 0, &value_type, (LPBYTE)temp_string_buffer, &local_bufsize); CHECK_REG_ERROR(code); ! /* Remember the directory, it is used as the default for NSIS. */ default_vim_dir = alloc(strlen(temp_string_buffer) + 1); strcpy(default_vim_dir, temp_string_buffer); remove_tail(default_vim_dir); --- 569,581 ---- printf("\nDo you want to uninstall \"%s\" now?\n(y)es/(n)o) ", temp_string_buffer); fflush(stdout); ! // get the UninstallString local_bufsize = sizeof(temp_string_buffer); code = RegQueryValueEx(uninstall_key_handle, "uninstallstring", 0, &value_type, (LPBYTE)temp_string_buffer, &local_bufsize); CHECK_REG_ERROR(code); ! // Remember the directory, it is used as the default for NSIS. default_vim_dir = alloc(strlen(temp_string_buffer) + 1); strcpy(default_vim_dir, temp_string_buffer); remove_tail(default_vim_dir); *************** *** 598,622 **** { case 'y': case 'Y': ! /* save the number of uninstall keys so we can know if ! * it changed */ RegQueryInfoKey(key_handle, NULL, NULL, NULL, &orig_num_keys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); ! /* Find existing .bat files before deleting them. */ find_bat_exe(TRUE); if (allow_silent) { if (run_silent_uninstall(temp_string_buffer) == FAIL) ! allow_silent = 0; /* Retry with non silent. */ } if (!allow_silent) { ! /* Execute the uninstall program. Put it in double ! * quotes if there is an embedded space. */ { char buf[BUFSIZE]; --- 598,622 ---- { case 'y': case 'Y': ! // save the number of uninstall keys so we can know if ! // it changed RegQueryInfoKey(key_handle, NULL, NULL, NULL, &orig_num_keys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); ! // Find existing .bat files before deleting them. find_bat_exe(TRUE); if (allow_silent) { if (run_silent_uninstall(temp_string_buffer) == FAIL) ! allow_silent = 0; // Retry with non silent. } if (!allow_silent) { ! // Execute the uninstall program. Put it in double ! // quotes if there is an embedded space. { char buf[BUFSIZE]; *************** *** 627,644 **** run_command(buf); } ! /* Count the number of windows with a title that match ! * the installer, so that we can check when it's done. ! * The uninstaller copies itself, executes the copy ! * and exits, thus we can't wait for the process to ! * finish. */ ! sleep(1); /* wait for uninstaller to start up */ num_windows = 0; EnumWindows(window_cb, 0); if (num_windows == 0) { ! /* Did not find the uninstaller, ask user to press ! * Enter when done. Just in case. */ printf("Press Enter when the uninstaller is finished\n"); rewind(stdin); (void)getchar(); --- 627,644 ---- run_command(buf); } ! // Count the number of windows with a title that ! // match the installer, so that we can check when ! // it's done. The uninstaller copies itself, ! // executes the copy and exits, thus we can't wait ! // for the process to finish. ! sleep(1); // wait for uninstaller to start up num_windows = 0; EnumWindows(window_cb, 0); if (num_windows == 0) { ! // Did not find the uninstaller, ask user to ! // press Enter when done. Just in case. printf("Press Enter when the uninstaller is finished\n"); rewind(stdin); (void)getchar(); *************** *** 650,656 **** { printf("."); fflush(stdout); ! sleep(1); /* wait for the uninstaller to finish */ num_windows = 0; EnumWindows(window_cb, 0); } while (num_windows > 0); --- 650,657 ---- { printf("."); fflush(stdout); ! sleep(1); // wait for the uninstaller to ! // finish num_windows = 0; EnumWindows(window_cb, 0); } while (num_windows > 0); *************** *** 658,667 **** } printf("\nDone!\n"); ! /* Check if an uninstall reg key was deleted. ! * if it was, we want to decrement key_index. ! * if we don't do this, we will skip the key ! * immediately after any key that we delete. */ RegQueryInfoKey(key_handle, NULL, NULL, NULL, &new_num_keys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); --- 659,668 ---- } printf("\nDone!\n"); ! // Check if an uninstall reg key was deleted. ! // if it was, we want to decrement key_index. ! // if we don't do this, we will skip the key ! // immediately after any key that we delete. RegQueryInfoKey(key_handle, NULL, NULL, NULL, &new_num_keys, NULL, NULL, NULL, NULL, NULL, NULL, NULL); *************** *** 673,683 **** case 'n': case 'N': ! /* Do not uninstall */ input = 'n'; break; ! default: /* just drop through and redo the loop */ break; } --- 674,684 ---- case 'n': case 'N': ! // Do not uninstall input = 'n'; break; ! default: // just drop through and redo the loop break; } *************** *** 705,711 **** int i; int foundone; ! /* This may take a little while, let the user know what we're doing. */ printf("Inspecting system...\n"); /* --- 706,712 ---- int i; int foundone; ! // This may take a little while, let the user know what we're doing. printf("Inspecting system...\n"); /* *************** *** 785,791 **** strcpy(oldvimrc + runtimeidx, "_vimrc"); if ((fd = fopen(oldvimrc, "r")) == NULL) { ! strcpy(oldvimrc + runtimeidx, "vimrc~1"); /* short version of .vimrc */ if ((fd = fopen(oldvimrc, "r")) == NULL) { strcpy(oldvimrc + runtimeidx, ".vimrc"); --- 786,792 ---- strcpy(oldvimrc + runtimeidx, "_vimrc"); if ((fd = fopen(oldvimrc, "r")) == NULL) { ! strcpy(oldvimrc + runtimeidx, "vimrc~1"); // short version of .vimrc if ((fd = fopen(oldvimrc, "r")) == NULL) { strcpy(oldvimrc + runtimeidx, ".vimrc"); *************** *** 814,822 **** ++choice_count; } ! /*********************************************** ! * stuff for creating the batch files. ! */ /* * Install the vim.bat, gvim.bat, etc. files. --- 815,822 ---- ++choice_count; } ! //////////////////////////////////////////////// ! // stuff for creating the batch files. /* * Install the vim.bat, gvim.bat, etc. files. *************** *** 844,850 **** fprintf(fd, "\n"); fprintf(fd, "setlocal\n"); ! /* Don't use double quotes for the "set" argument, also when it * contains a space. The quotes would be included in the value * for MSDOS and NT. * The order of preference is: --- 844,851 ---- fprintf(fd, "\n"); fprintf(fd, "setlocal\n"); ! /* ! * Don't use double quotes for the "set" argument, also when it * contains a space. The quotes would be included in the value * for MSDOS and NT. * The order of preference is: *************** *** 858,864 **** fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename); fprintf(fd, "\n"); ! /* Give an error message when the executable could not be found. */ fprintf(fd, "if exist \"%%VIM_EXE_DIR%%\\%s\" goto havevim\n", exename); fprintf(fd, "echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename); --- 859,865 ---- fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename); fprintf(fd, "\n"); ! // Give an error message when the executable could not be found. fprintf(fd, "if exist \"%%VIM_EXE_DIR%%\\%s\" goto havevim\n", exename); fprintf(fd, "echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename); *************** *** 890,904 **** fprintf(fd, "if .%%OS%%==.Windows_NT goto ntaction\n"); fprintf(fd, "\n"); ! /* For gvim.exe use "start" to avoid that the console window stays ! * open. */ if (*exename == 'g') { fprintf(fd, "if .%%VIMNOFORK%%==.1 goto nofork\n"); fprintf(fd, "start "); } ! /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n", exename, vimarg); fprintf(fd, "goto eof\n"); --- 891,905 ---- fprintf(fd, "if .%%OS%%==.Windows_NT goto ntaction\n"); fprintf(fd, "\n"); ! // For gvim.exe use "start" to avoid that the console window stays ! // open. if (*exename == 'g') { fprintf(fd, "if .%%VIMNOFORK%%==.1 goto nofork\n"); fprintf(fd, "start "); } ! // Always use quotes, $VIM or $VIMRUNTIME might have a space. fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n", exename, vimarg); fprintf(fd, "goto eof\n"); *************** *** 908,914 **** { fprintf(fd, ":nofork\n"); fprintf(fd, "start /w "); ! /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n", exename, vimarg); fprintf(fd, "goto eof\n"); --- 909,915 ---- { fprintf(fd, ":nofork\n"); fprintf(fd, "start /w "); ! // Always use quotes, $VIM or $VIMRUNTIME might have a space. fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n", exename, vimarg); fprintf(fd, "goto eof\n"); *************** *** 918,932 **** fprintf(fd, ":ntaction\n"); fprintf(fd, "rem for WinNT we can use %%*\n"); ! /* For gvim.exe use "start /b" to avoid that the console window ! * stays open. */ if (*exename == 'g') { fprintf(fd, "if .%%VIMNOFORK%%==.1 goto noforknt\n"); fprintf(fd, "start \"dummy\" /b "); } ! /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg); fprintf(fd, "goto eof\n"); fprintf(fd, "\n"); --- 919,933 ---- fprintf(fd, ":ntaction\n"); fprintf(fd, "rem for WinNT we can use %%*\n"); ! // For gvim.exe use "start /b" to avoid that the console window ! // stays open. if (*exename == 'g') { fprintf(fd, "if .%%VIMNOFORK%%==.1 goto noforknt\n"); fprintf(fd, "start \"dummy\" /b "); } ! // Always use quotes, $VIM or $VIMRUNTIME might have a space. fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg); fprintf(fd, "goto eof\n"); fprintf(fd, "\n"); *************** *** 935,941 **** { fprintf(fd, ":noforknt\n"); fprintf(fd, "start \"dummy\" /b /wait "); ! /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg); } --- 936,942 ---- { fprintf(fd, ":noforknt\n"); fprintf(fd, "start \"dummy\" /b /wait "); ! // Always use quotes, $VIM or $VIMRUNTIME might have a space. fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg); } *************** *** 1064,1078 **** if (n == count) { ! /* Selected last item, don't create bat file. */ *batpath = NUL; if (choices[idx].arg != 0) alloc_text(idx, " Do NOT create %s", name); } else { ! /* Selected one of the paths. For the first item only keep the path, ! * for the others append the batch file name. */ strcpy(batpath, names[n]); add_pathsep(batpath); if (choices[idx].arg != 0) --- 1065,1079 ---- if (n == count) { ! // Selected last item, don't create bat file. *batpath = NUL; if (choices[idx].arg != 0) alloc_text(idx, " Do NOT create %s", name); } else { ! // Selected one of the paths. For the first item only keep the path, ! // for the others append the batch file name. strcpy(batpath, names[n]); add_pathsep(batpath); if (choices[idx].arg != 0) *************** *** 1092,1098 **** { int i; ! /* let the user select a default directory or NONE */ change_bat_choice(idx); if (targets[0].batpath[0] != NUL) --- 1093,1099 ---- { int i; ! // let the user select a default directory or NONE change_bat_choice(idx); if (targets[0].batpath[0] != NUL) *************** *** 1100,1110 **** else choices[idx].text = bat_text_no; ! /* update the individual batch file selections */ for (i = 1; i < TARGET_COUNT; ++i) { ! /* Only make it active when the first item has a path and the vim.exe ! * or gvim.exe exists (there is a changefunc then). */ if (targets[0].batpath[0] != NUL && choices[idx + i].changefunc != NULL) { --- 1101,1111 ---- else choices[idx].text = bat_text_no; ! // update the individual batch file selections for (i = 1; i < TARGET_COUNT; ++i) { ! // Only make it active when the first item has a path and the vim.exe ! // or gvim.exe exists (there is a changefunc then). if (targets[0].batpath[0] != NUL && choices[idx + i].changefunc != NULL) { *************** *** 1135,1144 **** choices[choice_count].arg = target; choices[choice_count].installfunc = install_bat_choice; choices[choice_count].active = 1; ! choices[choice_count].text = NULL; /* will be set below */ if (oldbat != NULL) { ! /* A [g]vim.bat exists: Only choice is to overwrite it or not. */ choices[choice_count].changefunc = toggle_bat_choice; *batpath = NUL; toggle_bat_choice(choice_count); --- 1136,1145 ---- choices[choice_count].arg = target; choices[choice_count].installfunc = install_bat_choice; choices[choice_count].active = 1; ! choices[choice_count].text = NULL; // will be set below if (oldbat != NULL) { ! // A [g]vim.bat exists: Only choice is to overwrite it or not. choices[choice_count].changefunc = toggle_bat_choice; *batpath = NUL; toggle_bat_choice(choice_count); *************** *** 1146,1164 **** else { if (default_bat_dir != NULL) ! /* Prefer using the same path as an existing .bat file. */ strcpy(batpath, default_bat_dir); else { ! /* No [g]vim.bat exists: Write it to a directory in $PATH. Use ! * $WINDIR by default, if it's empty the first item in $PATH. */ p = getenv("WINDIR"); if (p != NULL && *p != NUL) strcpy(batpath, p); else { p = getenv("PATH"); ! if (p == NULL || *p == NUL) /* "cannot happen" */ strcpy(batpath, "C:/Windows"); else { --- 1147,1165 ---- else { if (default_bat_dir != NULL) ! // Prefer using the same path as an existing .bat file. strcpy(batpath, default_bat_dir); else { ! // No [g]vim.bat exists: Write it to a directory in $PATH. Use ! // $WINDIR by default, if it's empty the first item in $PATH. p = getenv("WINDIR"); if (p != NULL && *p != NUL) strcpy(batpath, p); else { p = getenv("PATH"); ! if (p == NULL || *p == NUL) // "cannot happen" strcpy(batpath, "C:/Windows"); else { *************** *** 1186,1193 **** { int i; ! /* The first item is used to switch installing batch files on/off and ! * setting the default path. */ choices[choice_count].text = bat_text_yes; choices[choice_count].changefunc = change_main_bat_choice; choices[choice_count].installfunc = NULL; --- 1187,1194 ---- { int i; ! // The first item is used to switch installing batch files on/off and ! // setting the default path. choices[choice_count].text = bat_text_yes; choices[choice_count].changefunc = change_main_bat_choice; choices[choice_count].installfunc = NULL; *************** *** 1195,1202 **** choices[choice_count].arg = 0; ++choice_count; ! /* Add items for each batch file target. Only used when not disabled by ! * the first item. When a .exe exists, don't offer to create a .bat. */ for (i = 1; i < TARGET_COUNT; ++i) if (targets[i].oldexe == NULL && (targets[i].exenamearg[0] == 'g' ? has_gvim : has_vim)) --- 1196,1203 ---- choices[choice_count].arg = 0; ++choice_count; ! // Add items for each batch file target. Only used when not disabled by ! // the first item. When a .exe exists, don't offer to create a .bat. for (i = 1; i < TARGET_COUNT; ++i) if (targets[i].oldexe == NULL && (targets[i].exenamearg[0] == 'g' ? has_gvim : has_vim)) *************** *** 1214,1221 **** FILE *fd, *tfd; char *fname; ! /* If an old vimrc file exists, overwrite it. ! * Otherwise create a new one. */ if (*oldvimrc != NUL) fname = oldvimrc; else --- 1215,1222 ---- FILE *fd, *tfd; char *fname; ! // If an old vimrc file exists, overwrite it. ! // Otherwise create a new one. if (*oldvimrc != NUL) fname = oldvimrc; else *************** *** 1275,1281 **** } if ((tfd = fopen("diff.exe", "r")) != NULL) { ! /* Use the diff.exe that comes with the self-extracting gvim.exe. */ fclose(tfd); fprintf(fd, "\n"); fprintf(fd, "\" Use the internal diff if available.\n"); --- 1276,1282 ---- } if ((tfd = fopen("diff.exe", "r")) != NULL) { ! // Use the diff.exe that comes with the self-extracting gvim.exe. fclose(tfd); fprintf(fd, "\n"); fprintf(fd, "\" Use the internal diff if available.\n"); *************** *** 1287,1294 **** fprintf(fd, " let opt = '-a --binary '\n"); fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n"); fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n"); ! /* Use quotes only when needed, they may cause trouble. ! * Always escape "!". */ fprintf(fd, " let arg1 = v:fname_in\n"); fprintf(fd, " if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif\n"); fprintf(fd, " let arg1 = substitute(arg1, '!', '\\!', 'g')\n"); --- 1288,1295 ---- fprintf(fd, " let opt = '-a --binary '\n"); fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n"); fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n"); ! // Use quotes only when needed, they may cause trouble. ! // Always escape "!". fprintf(fd, " let arg1 = v:fname_in\n"); fprintf(fd, " if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif\n"); fprintf(fd, " let arg1 = substitute(arg1, '!', '\\!', 'g')\n"); *************** *** 1299,1311 **** fprintf(fd, " if arg3 =~ ' ' | let arg3 = '\"' . arg3 . '\"' | endif\n"); fprintf(fd, " let arg3 = substitute(arg3, '!', '\\!', 'g')\n"); ! /* If the path has a space: When using cmd.exe (Win NT/2000/XP) put ! * quotes around the diff command and rely on the default value of ! * shellxquote to solve the quoting problem for the whole command. ! * ! * Otherwise put a double quote just before the space and at the ! * end of the command. Putting quotes around the whole thing ! * doesn't work on Win 95/98/ME. This is mostly guessed! */ fprintf(fd, " if $VIMRUNTIME =~ ' '\n"); fprintf(fd, " if &sh =~ '\\lpVtbl->QueryInterface(shelllink_ptr, &IID_IPersistFile, (void **) &persistfile_ptr); --- 1808,1825 ---- return FAIL; } ! // Instantiate a COM object for the ShellLink, store a pointer to it ! // in shelllink_ptr. hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void **) &shelllink_ptr); ! if (SUCCEEDED(hres)) // If the instantiation was successful... { ! // ...Then build a PersistFile interface for the ShellLink so we can ! // save it as a file after we build it. hres = shelllink_ptr->lpVtbl->QueryInterface(shelllink_ptr, &IID_IPersistFile, (void **) &persistfile_ptr); *************** *** 1827,1838 **** { wchar_t wsz[BUFSIZE]; ! /* translate the (possibly) multibyte shortcut filename to windows ! * Unicode so it can be used as a file name. ! */ MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, sizeof(wsz)/sizeof(wsz[0])); ! /* set the attributes */ shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target); shelllink_ptr->lpVtbl->SetWorkingDirectory(shelllink_ptr, workingdir); --- 1827,1837 ---- { wchar_t wsz[BUFSIZE]; ! // translate the (possibly) multibyte shortcut filename to windows ! // Unicode so it can be used as a file name. MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, sizeof(wsz)/sizeof(wsz[0])); ! // set the attributes shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target); shelllink_ptr->lpVtbl->SetWorkingDirectory(shelllink_ptr, workingdir); *************** *** 1840,1846 **** iconfile_path, iconindex); shelllink_ptr->lpVtbl->SetArguments(shelllink_ptr, shortcut_args); ! /* save the shortcut to a file and return the PersistFile object*/ persistfile_ptr->lpVtbl->Save(persistfile_ptr, wsz, 1); persistfile_ptr->lpVtbl->Release(persistfile_ptr); } --- 1839,1845 ---- iconfile_path, iconindex); shelllink_ptr->lpVtbl->SetArguments(shelllink_ptr, shortcut_args); ! // save the shortcut to a file and return the PersistFile object persistfile_ptr->lpVtbl->Save(persistfile_ptr, wsz, 1); persistfile_ptr->lpVtbl->Release(persistfile_ptr); } *************** *** 1850,1856 **** return FAIL; } ! /* Return the ShellLink object */ shelllink_ptr->lpVtbl->Release(shelllink_ptr); } else --- 1849,1855 ---- return FAIL; } ! // Return the ShellLink object shelllink_ptr->lpVtbl->Release(shelllink_ptr); } else *************** *** 1882,1892 **** return FAIL; } ! /* Make sure the directory exists (create Start Menu\Programs\Vim). ! * Ignore errors if it already exists. */ vim_mkdir(shell_folder_path, 0755); ! /* build the path to the shortcut and the path to gvim.exe */ sprintf(link_path, "%s\\%s.lnk", shell_folder_path, link_name); return OK; --- 1881,1891 ---- return FAIL; } ! // Make sure the directory exists (create Start Menu\Programs\Vim). ! // Ignore errors if it already exists. vim_mkdir(shell_folder_path, 0755); ! // build the path to the shortcut and the path to gvim.exe sprintf(link_path, "%s\\%s.lnk", shell_folder_path, link_name); return OK; *************** *** 1894,1901 **** static int build_shortcut( ! const char *name, /* Name of the shortcut */ ! const char *exename, /* Name of the executable (e.g., vim.exe) */ const char *args, const char *shell_folder, const char *workingdir) --- 1893,1900 ---- static int build_shortcut( ! const char *name, // Name of the shortcut ! const char *exename, // Name of the executable (e.g., vim.exe) const char *args, const char *shell_folder, const char *workingdir) *************** *** 1913,1919 **** return FAIL; } ! /* Create the shortcut: */ return create_shortcut(link_name, executable_path, 0, executable_path, args, workingdir); } --- 1912,1918 ---- return FAIL; } ! // Create the shortcut: return create_shortcut(link_name, executable_path, 0, executable_path, args, workingdir); } *************** *** 1965,1972 **** interactive ? "uninstall.exe" : "uninstall-gui.exe", "", VIM_STARTMENU, installdir) == FAIL) return; ! /* For Windows NT the working dir of the vimtutor.bat must be right, ! * otherwise gvim.exe won't be found and using gvimbat doesn't work. */ if (build_shortcut("Vim tutor", "vimtutor.bat", "", VIM_STARTMENU, installdir) == FAIL) return; --- 1964,1971 ---- interactive ? "uninstall.exe" : "uninstall-gui.exe", "", VIM_STARTMENU, installdir) == FAIL) return; ! // For Windows NT the working dir of the vimtutor.bat must be right, ! // otherwise gvim.exe won't be found and using gvimbat doesn't work. if (build_shortcut("Vim tutor", "vimtutor.bat", "", VIM_STARTMENU, installdir) == FAIL) return; *************** *** 1976,1982 **** { char shell_folder_path[BUFSIZE]; ! /* Creating the URL shortcut works a bit differently... */ if (get_shell_folder_path(shell_folder_path, VIM_STARTMENU) == FAIL) { printf("Finding the path of the Start menu failed\n"); --- 1975,1981 ---- { char shell_folder_path[BUFSIZE]; ! // Creating the URL shortcut works a bit differently... if (get_shell_folder_path(shell_folder_path, VIM_STARTMENU) == FAIL) { printf("Finding the path of the Start menu failed\n"); *************** *** 2020,2026 **** void install_shortcut_gvim(int idx) { ! /* Create shortcut(s) on the desktop */ if (choices[idx].arg) { (void)build_shortcut(icon_names[0], "gvim.exe", --- 2019,2025 ---- void install_shortcut_gvim(int idx) { ! // Create shortcut(s) on the desktop if (choices[idx].arg) { (void)build_shortcut(icon_names[0], "gvim.exe", *************** *** 2077,2087 **** static void init_startmenu_choice(void) { ! /* Start menu */ choices[choice_count].changefunc = toggle_startmenu_choice; choices[choice_count].installfunc = NULL; choices[choice_count].active = 1; ! toggle_startmenu_choice(choice_count); /* set the text */ ++choice_count; } --- 2076,2086 ---- static void init_startmenu_choice(void) { ! // Start menu choices[choice_count].changefunc = toggle_startmenu_choice; choices[choice_count].installfunc = NULL; choices[choice_count].active = 1; ! toggle_startmenu_choice(choice_count); // set the text ++choice_count; } *************** *** 2091,2097 **** static void init_shortcut_choices(void) { ! /* Shortcut to gvim */ choices[choice_count].text = NULL; choices[choice_count].arg = 0; choices[choice_count].active = has_gvim; --- 2090,2096 ---- static void init_shortcut_choices(void) { ! // Shortcut to gvim choices[choice_count].text = NULL; choices[choice_count].arg = 0; choices[choice_count].active = has_gvim; *************** *** 2100,2106 **** toggle_shortcut_choice(choice_count); ++choice_count; ! /* Shortcut to evim */ choices[choice_count].text = NULL; choices[choice_count].arg = 0; choices[choice_count].active = has_gvim; --- 2099,2105 ---- toggle_shortcut_choice(choice_count); ++choice_count; ! // Shortcut to evim choices[choice_count].text = NULL; choices[choice_count].arg = 0; choices[choice_count].active = has_gvim; *************** *** 2109,2115 **** toggle_shortcut_choice(choice_count); ++choice_count; ! /* Shortcut to gview */ choices[choice_count].text = NULL; choices[choice_count].arg = 0; choices[choice_count].active = has_gvim; --- 2108,2114 ---- toggle_shortcut_choice(choice_count); ++choice_count; ! // Shortcut to gview choices[choice_count].text = NULL; choices[choice_count].arg = 0; choices[choice_count].active = has_gvim; *************** *** 2145,2151 **** long last_char_to_copy; long path_length = strlen(path); ! /* skip the last character just in case it is a '\\' */ last_char_to_copy = path_length - 2; c = path[last_char_to_copy]; --- 2144,2150 ---- long last_char_to_copy; long path_length = strlen(path); ! // skip the last character just in case it is a '\\' last_char_to_copy = path_length - 2; c = path[last_char_to_copy]; *************** *** 2264,2270 **** { int choice_count = TABLE_SIZE(vimfiles_dir_choices); ! /* Don't offer the $HOME choice if $HOME isn't set. */ if (homedir == NULL) --choice_count; choices[idx].arg = get_choice(vimfiles_dir_choices, choice_count); --- 2263,2269 ---- { int choice_count = TABLE_SIZE(vimfiles_dir_choices); ! // Don't offer the $HOME choice if $HOME isn't set. if (homedir == NULL) --choice_count; choices[idx].arg = get_choice(vimfiles_dir_choices, choice_count); *************** *** 2274,2280 **** /* * Create the plugin directories... */ ! /*ARGSUSED*/ static void install_vimfilesdir(int idx) { --- 2273,2279 ---- /* * Create the plugin directories... */ ! //ARGSUSED static void install_vimfilesdir(int idx) { *************** *** 2285,2302 **** char vimfiles_path[MAX_PATH + 9]; char tmp_dirname[BUFSIZE]; ! /* switch on the location that the user wants the plugin directories ! * built in */ switch (vimfiles_dir_choice) { case vimfiles_dir_vim: { ! /* Go to the %VIM% directory - check env first, then go one dir ! * below installdir if there is no %VIM% environment variable. ! * The accuracy of $VIM is checked in inspect_system(), so we ! * can be sure it is ok to use here. */ p = getenv("VIM"); ! if (p == NULL) /* No $VIM in path */ dir_remove_last(installdir, vimdir_path); else strcpy(vimdir_path, p); --- 2284,2301 ---- char vimfiles_path[MAX_PATH + 9]; char tmp_dirname[BUFSIZE]; ! // switch on the location that the user wants the plugin directories ! // built in switch (vimfiles_dir_choice) { case vimfiles_dir_vim: { ! // Go to the %VIM% directory - check env first, then go one dir ! // below installdir if there is no %VIM% environment variable. ! // The accuracy of $VIM is checked in inspect_system(), so we ! // can be sure it is ok to use here. p = getenv("VIM"); ! if (p == NULL) // No $VIM in path dir_remove_last(installdir, vimdir_path); else strcpy(vimdir_path, p); *************** *** 2321,2328 **** } } ! /* Now, just create the directory. If it already exists, it will fail ! * silently. */ sprintf(vimfiles_path, "%s\\vimfiles", vimdir_path); vim_mkdir(vimfiles_path, 0755); --- 2320,2327 ---- } } ! // Now, just create the directory. If it already exists, it will fail ! // silently. sprintf(vimfiles_path, "%s\\vimfiles", vimdir_path); vim_mkdir(vimfiles_path, 0755); *************** *** 2386,2410 **** static void setup_choices(void) { ! /* install the batch files */ init_bat_choices(); ! /* (over) write _vimrc file */ init_vimrc_choices(); ! /* Whether to add Vim to the popup menu */ init_popup_choice(); ! /* Whether to add Vim to the "Open With..." menu */ init_openwith_choice(); ! /* Whether to add Vim to the Start Menu. */ init_startmenu_choice(); ! /* Whether to add shortcuts to the Desktop. */ init_shortcut_choices(); ! /* Whether to create the runtime directories. */ init_directories_choice(); } --- 2385,2409 ---- static void setup_choices(void) { ! // install the batch files init_bat_choices(); ! // (over) write _vimrc file init_vimrc_choices(); ! // Whether to add Vim to the popup menu init_popup_choice(); ! // Whether to add Vim to the "Open With..." menu init_openwith_choice(); ! // Whether to add Vim to the Start Menu. init_startmenu_choice(); ! // Whether to add shortcuts to the Desktop. init_shortcut_choices(); ! // Whether to create the runtime directories. init_directories_choice(); } *************** *** 2473,2481 **** } else if (strcmp(argv[i], "-create-vimrc") == 0) { ! /* Setup default vimrc choices. If there is already a _vimrc file, ! * it will NOT be overwritten. ! */ init_vimrc_choices(); } else if (strcmp(argv[i], "-vimrc-remap") == 0) --- 2472,2479 ---- } else if (strcmp(argv[i], "-create-vimrc") == 0) { ! // Setup default vimrc choices. If there is already a _vimrc file, ! // it will NOT be overwritten. init_vimrc_choices(); } else if (strcmp(argv[i], "-vimrc-remap") == 0) *************** *** 2554,2568 **** print_cmd_line_help(); } } ! else /* No choice specified, default to vim directory */ vimfiles_dir_choice = (int)vimfiles_dir_vim; choices[choice_count - 1].arg = vimfiles_dir_choice; } else if (strcmp(argv[i], "-register-OLE") == 0) { ! /* This is always done when gvim is found */ } ! else /* Unknown switch */ { printf("Got unknown argument argv[%d] = %s\n", i, argv[i]); print_cmd_line_help(); --- 2552,2566 ---- print_cmd_line_help(); } } ! else // No choice specified, default to vim directory vimfiles_dir_choice = (int)vimfiles_dir_vim; choices[choice_count - 1].arg = vimfiles_dir_choice; } else if (strcmp(argv[i], "-register-OLE") == 0) { ! // This is always done when gvim is found } ! else // Unknown switch { printf("Got unknown argument argv[%d] = %s\n", i, argv[i]); print_cmd_line_help(); *************** *** 2707,2725 **** { int i; ! /* Install the selected choices. */ for (i = 0; i < choice_count; ++i) if (choices[i].installfunc != NULL && choices[i].active) (choices[i].installfunc)(i); ! /* Add some entries to the registry, if needed. */ if (install_popup || install_openwith || (need_uninstall_entry && interactive) || !interactive) install_registry(); ! /* Register gvim with OLE. */ if (has_gvim) install_OLE_register(); } --- 2705,2723 ---- { int i; ! // Install the selected choices. for (i = 0; i < choice_count; ++i) if (choices[i].installfunc != NULL && choices[i].active) (choices[i].installfunc)(i); ! // Add some entries to the registry, if needed. if (install_popup || install_openwith || (need_uninstall_entry && interactive) || !interactive) install_registry(); ! // Register gvim with OLE. if (has_gvim) install_OLE_register(); } *************** *** 2754,2774 **** else interactive = 1; ! /* Initialize this program. */ do_inits(argv); init_homedir(); if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0) { ! /* Only check for already installed Vims. Used by NSIS installer. */ i = uninstall_check(1); ! /* Find the value of $VIM, because NSIS isn't able to do this by ! * itself. */ get_vim_env(); ! /* When nothing found exit quietly. If something found wait for ! * a little while, so that the user can read the messages. */ if (i && _isatty(1)) sleep(3); exit(0); --- 2752,2772 ---- else interactive = 1; ! // Initialize this program. do_inits(argv); init_homedir(); if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0) { ! // Only check for already installed Vims. Used by NSIS installer. i = uninstall_check(1); ! // Find the value of $VIM, because NSIS isn't able to do this by ! // itself. get_vim_env(); ! // When nothing found exit quietly. If something found wait for ! // a little while, so that the user can read the messages. if (i && _isatty(1)) sleep(3); exit(0); *************** *** 2777,2798 **** printf("This program sets up the installation of Vim " VIM_VERSION_MEDIUM "\n\n"); ! /* Check if the user unpacked the archives properly. */ check_unpack(); ! /* Check for already installed Vims. */ if (interactive) uninstall_check(0); ! /* Find out information about the system. */ inspect_system(); if (interactive) { ! /* Setup all the choices. */ setup_choices(); ! /* Let the user change choices and finally install (or quit). */ for (;;) { request_choice(); --- 2775,2796 ---- printf("This program sets up the installation of Vim " VIM_VERSION_MEDIUM "\n\n"); ! // Check if the user unpacked the archives properly. check_unpack(); ! // Check for already installed Vims. if (interactive) uninstall_check(0); ! // Find out information about the system. inspect_system(); if (interactive) { ! // Setup all the choices. setup_choices(); ! // Let the user change choices and finally install (or quit). for (;;) { request_choice(); *************** *** 2801,2807 **** { if (isdigit(buf[0])) { ! /* Change a choice. */ i = atoi(buf); if (i > 0 && i <= choice_count && choices[i - 1].active) (choices[i - 1].changefunc)(i - 1); --- 2799,2805 ---- { if (isdigit(buf[0])) { ! // Change a choice. i = atoi(buf); if (i > 0 && i <= choice_count && choices[i - 1].active) (choices[i - 1].changefunc)(i - 1); *************** *** 2810,2828 **** } else if (buf[0] == 'h' || buf[0] == 'H') { ! /* Help */ show_help(); } else if (buf[0] == 'd' || buf[0] == 'D') { ! /* Install! */ install(); printf("\nThat finishes the installation. Happy Vimming!\n"); break; } else if (buf[0] == 'q' || buf[0] == 'Q') { ! /* Quit */ printf("\nExiting without anything done\n"); break; } --- 2808,2826 ---- } else if (buf[0] == 'h' || buf[0] == 'H') { ! // Help show_help(); } else if (buf[0] == 'd' || buf[0] == 'D') { ! // Install! install(); printf("\nThat finishes the installation. Happy Vimming!\n"); break; } else if (buf[0] == 'q' || buf[0] == 'Q') { ! // Quit printf("\nExiting without anything done\n"); break; } *************** *** 2841,2848 **** command_line_setup_choices(argc, argv); install(); ! /* Avoid that the user has to hit Enter, just wait a little bit to ! * allow reading the messages. */ sleep(2); } --- 2839,2846 ---- command_line_setup_choices(argc, argv); install(); ! // Avoid that the user has to hit Enter, just wait a little bit to ! // allow reading the messages. sleep(2); } *** ../vim-8.1.2377/src/edit.c 2019-11-30 22:47:42.643331239 +0100 --- src/edit.c 2019-12-01 21:04:37.770887417 +0100 *************** *** 18,25 **** #define BACKSPACE_WORD_NOT_SPACE 3 #define BACKSPACE_LINE 4 ! /* Set when doing something for completion that may call edit() recursively, ! * which is not allowed. */ static int compl_busy = FALSE; --- 18,25 ---- #define BACKSPACE_WORD_NOT_SPACE 3 #define BACKSPACE_LINE 4 ! // Set when doing something for completion that may call edit() recursively, ! // which is not allowed. static int compl_busy = FALSE; *************** *** 79,108 **** static char_u *do_insert_char_pre(int c); #endif ! static colnr_T Insstart_textlen; /* length of line when insert started */ ! static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */ ! static int update_Insstart_orig = TRUE; /* set Insstart_orig to Insstart */ ! ! static char_u *last_insert = NULL; /* the text of the previous insert, ! K_SPECIAL and CSI are escaped */ ! static int last_insert_skip; /* nr of chars in front of previous insert */ ! static int new_insert_skip; /* nr of chars in front of current insert */ ! static int did_restart_edit; /* "restart_edit" when calling edit() */ #ifdef FEAT_CINDENT ! static int can_cindent; /* may do cindenting on this line */ #endif #ifdef FEAT_RIGHTLEFT ! static int revins_on; /* reverse insert mode on */ ! static int revins_chars; /* how much to skip after edit */ ! static int revins_legal; /* was the last char 'legal'? */ ! static int revins_scol; /* start column of revins session */ #endif ! static int ins_need_undo; /* call u_save() before inserting a ! char. Set when edit() is called. ! after that arrow_used is used. */ static int did_add_space = FALSE; // auto_format() added an extra space // under the cursor --- 79,108 ---- static char_u *do_insert_char_pre(int c); #endif ! static colnr_T Insstart_textlen; // length of line when insert started ! static colnr_T Insstart_blank_vcol; // vcol for first inserted blank ! static int update_Insstart_orig = TRUE; // set Insstart_orig to Insstart ! ! static char_u *last_insert = NULL; // the text of the previous insert, ! // K_SPECIAL and CSI are escaped ! static int last_insert_skip; // nr of chars in front of previous insert ! static int new_insert_skip; // nr of chars in front of current insert ! static int did_restart_edit; // "restart_edit" when calling edit() #ifdef FEAT_CINDENT ! static int can_cindent; // may do cindenting on this line #endif #ifdef FEAT_RIGHTLEFT ! static int revins_on; // reverse insert mode on ! static int revins_chars; // how much to skip after edit ! static int revins_legal; // was the last char 'legal'? ! static int revins_scol; // start column of revins session #endif ! static int ins_need_undo; // call u_save() before inserting a ! // char. Set when edit() is called. ! // after that arrow_used is used. static int did_add_space = FALSE; // auto_format() added an extra space // under the cursor *************** *** 131,137 **** int edit( int cmdchar, ! int startln, /* if set, insert at start of line */ long count) { int c = 0; --- 131,137 ---- int edit( int cmdchar, ! int startln, // if set, insert at start of line long count) { int c = 0; *************** *** 140,193 **** int mincol; static linenr_T o_lnum = 0; int i; ! int did_backspace = TRUE; /* previous char was backspace */ #ifdef FEAT_CINDENT ! int line_is_white = FALSE; /* line is empty before insert */ #endif ! linenr_T old_topline = 0; /* topline before insertion */ #ifdef FEAT_DIFF int old_topfill = -1; #endif ! int inserted_space = FALSE; /* just inserted a space */ int replaceState = REPLACE; ! int nomove = FALSE; /* don't move cursor on return */ #ifdef FEAT_JOB_CHANNEL int cmdchar_todo = cmdchar; #endif ! /* Remember whether editing was restarted after CTRL-O. */ did_restart_edit = restart_edit; ! /* sleep before redrawing, needed for "CTRL-O :" that results in an ! * error message */ check_for_delay(TRUE); ! /* set Insstart_orig to Insstart */ update_Insstart_orig = TRUE; #ifdef HAVE_SANDBOX ! /* Don't allow inserting in the sandbox. */ if (sandbox != 0) { emsg(_(e_sandbox)); return FALSE; } #endif ! /* Don't allow changes in the buffer while editing the cmdline. The ! * caller of getcmdline() may get confused. */ if (textlock != 0) { emsg(_(e_secure)); return FALSE; } ! /* Don't allow recursive insert mode when busy with completion. */ if (ins_compl_active() || compl_busy || pum_visible()) { emsg(_(e_secure)); return FALSE; } ! ins_compl_clear(); /* clear stuff for CTRL-X mode */ /* * Trigger InsertEnter autocommands. Do not do this for "r" or "grx". --- 140,193 ---- int mincol; static linenr_T o_lnum = 0; int i; ! int did_backspace = TRUE; // previous char was backspace #ifdef FEAT_CINDENT ! int line_is_white = FALSE; // line is empty before insert #endif ! linenr_T old_topline = 0; // topline before insertion #ifdef FEAT_DIFF int old_topfill = -1; #endif ! int inserted_space = FALSE; // just inserted a space int replaceState = REPLACE; ! int nomove = FALSE; // don't move cursor on return #ifdef FEAT_JOB_CHANNEL int cmdchar_todo = cmdchar; #endif ! // Remember whether editing was restarted after CTRL-O. did_restart_edit = restart_edit; ! // sleep before redrawing, needed for "CTRL-O :" that results in an ! // error message check_for_delay(TRUE); ! // set Insstart_orig to Insstart update_Insstart_orig = TRUE; #ifdef HAVE_SANDBOX ! // Don't allow inserting in the sandbox. if (sandbox != 0) { emsg(_(e_sandbox)); return FALSE; } #endif ! // Don't allow changes in the buffer while editing the cmdline. The ! // caller of getcmdline() may get confused. if (textlock != 0) { emsg(_(e_secure)); return FALSE; } ! // Don't allow recursive insert mode when busy with completion. if (ins_compl_active() || compl_busy || pum_visible()) { emsg(_(e_secure)); return FALSE; } ! ins_compl_clear(); // clear stuff for CTRL-X mode /* * Trigger InsertEnter autocommands. Do not do this for "r" or "grx". *************** *** 204,219 **** else ptr = (char_u *)"i"; set_vim_var_string(VV_INSERTMODE, ptr, 1); ! set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */ #endif ins_apply_autocmds(EVENT_INSERTENTER); ! /* Make sure the cursor didn't move. Do call check_cursor_col() in ! * case the text was modified. Since Insert mode was not started yet ! * a call to check_cursor_col() may move the cursor, especially with ! * the "A" command, thus set State to avoid that. Also check that the ! * line number is still valid (lines may have been deleted). ! * Do not restore if v:char was set to a non-empty string. */ if (!EQUAL_POS(curwin->w_cursor, save_cursor) #ifdef FEAT_EVAL && *get_vim_var_str(VV_CHAR) == NUL --- 204,219 ---- else ptr = (char_u *)"i"; set_vim_var_string(VV_INSERTMODE, ptr, 1); ! set_vim_var_string(VV_CHAR, NULL, -1); // clear v:char #endif ins_apply_autocmds(EVENT_INSERTENTER); ! // Make sure the cursor didn't move. Do call check_cursor_col() in ! // case the text was modified. Since Insert mode was not started yet ! // a call to check_cursor_col() may move the cursor, especially with ! // the "A" command, thus set State to avoid that. Also check that the ! // line number is still valid (lines may have been deleted). ! // Do not restore if v:char was set to a non-empty string. if (!EQUAL_POS(curwin->w_cursor, save_cursor) #ifdef FEAT_EVAL && *get_vim_var_str(VV_CHAR) == NUL *************** *** 230,237 **** } #ifdef FEAT_CONCEAL ! /* Check if the cursor line needs redrawing before changing State. If ! * 'concealcursor' is "n" it needs to be redrawn without concealing. */ conceal_check_cursor_line(); #endif --- 230,237 ---- } #ifdef FEAT_CONCEAL ! // Check if the cursor line needs redrawing before changing State. If ! // 'concealcursor' is "n" it needs to be redrawn without concealing. conceal_check_cursor_line(); #endif *************** *** 258,264 **** AppendNumberToRedobuff(count); if (cmdchar == 'V' || cmdchar == 'v') { ! /* "gR" or "gr" command */ AppendCharToRedobuff('g'); AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R'); } --- 258,264 ---- AppendNumberToRedobuff(count); if (cmdchar == 'V' || cmdchar == 'v') { ! // "gR" or "gr" command AppendCharToRedobuff('g'); AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R'); } *************** *** 268,277 **** AppendCharToRedobuff('a'); else AppendCharToRedobuff(cmdchar); ! if (cmdchar == 'g') /* "gI" command */ AppendCharToRedobuff('I'); ! else if (cmdchar == 'r') /* "r" command */ ! count = 1; /* insert only one */ } } --- 268,277 ---- AppendCharToRedobuff('a'); else AppendCharToRedobuff(cmdchar); ! if (cmdchar == 'g') // "gI" command AppendCharToRedobuff('I'); ! else if (cmdchar == 'r') // "r" command ! count = 1; // insert only one } } *************** *** 314,320 **** clear_showcmd(); #endif #ifdef FEAT_RIGHTLEFT ! /* there is no reverse replace mode */ revins_on = (State == INSERT && p_ri); if (revins_on) undisplay_dollar(); --- 314,320 ---- clear_showcmd(); #endif #ifdef FEAT_RIGHTLEFT ! // there is no reverse replace mode revins_on = (State == INSERT && p_ri); if (revins_on) undisplay_dollar(); *************** *** 377,386 **** else arrow_used = FALSE; ! /* we are in insert mode now, don't need to start it anymore */ need_start_insertmode = FALSE; ! /* Need to save the line for undo before inserting the first char. */ ins_need_undo = TRUE; where_paste_started.lnum = 0; --- 377,386 ---- else arrow_used = FALSE; ! // we are in insert mode now, don't need to start it anymore need_start_insertmode = FALSE; ! // Need to save the line for undo before inserting the first char. ins_need_undo = TRUE; where_paste_started.lnum = 0; *************** *** 388,395 **** can_cindent = TRUE; #endif #ifdef FEAT_FOLDING ! /* The cursor line is not in a closed fold, unless 'insertmode' is set or ! * restarting. */ if (!p_im && did_restart_edit == 0) foldOpenCursor(); #endif --- 388,395 ---- can_cindent = TRUE; #endif #ifdef FEAT_FOLDING ! // The cursor line is not in a closed fold, unless 'insertmode' is set or ! // restarting. if (!p_im && did_restart_edit == 0) foldOpenCursor(); #endif *************** *** 407,416 **** change_warning(i == 0 ? 0 : i + 1); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may show different cursor shape */ #endif #ifdef FEAT_DIGRAPHS ! do_digraph(-1); /* clear digraphs */ #endif /* --- 407,416 ---- change_warning(i == 0 ? 0 : i + 1); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may show different cursor shape #endif #ifdef FEAT_DIGRAPHS ! do_digraph(-1); // clear digraphs #endif /* *************** *** 435,445 **** { #ifdef FEAT_RIGHTLEFT if (!revins_legal) ! revins_scol = -1; /* reset on illegal motions */ else revins_legal = 0; #endif ! if (arrow_used) /* don't repeat insert when arrow key used */ count = 0; if (update_Insstart_orig) --- 435,445 ---- { #ifdef FEAT_RIGHTLEFT if (!revins_legal) ! revins_scol = -1; // reset on illegal motions else revins_legal = 0; #endif ! if (arrow_used) // don't repeat insert when arrow key used count = 0; if (update_Insstart_orig) *************** *** 447,463 **** if (stop_insert_mode && !pum_visible()) { ! /* ":stopinsert" used or 'insertmode' reset */ count = 0; goto doESCkey; } ! /* set curwin->w_curswant for next K_DOWN or K_UP */ if (!arrow_used) curwin->w_set_curswant = TRUE; ! /* If there is no typeahead may check for timestamps (e.g., for when a ! * menu invoked a shell command). */ if (stuff_empty()) { did_check_timestamps = FALSE; --- 447,463 ---- if (stop_insert_mode && !pum_visible()) { ! // ":stopinsert" used or 'insertmode' reset count = 0; goto doESCkey; } ! // set curwin->w_curswant for next K_DOWN or K_UP if (!arrow_used) curwin->w_set_curswant = TRUE; ! // If there is no typeahead may check for timestamps (e.g., for when a ! // menu invoked a shell command). if (stuff_empty()) { did_check_timestamps = FALSE; *************** *** 471,488 **** msg_scroll = FALSE; #ifdef FEAT_GUI ! /* When 'mousefocus' is set a mouse movement may have taken us to ! * another window. "need_mouse_correct" may then be set because of an ! * autocommand. */ if (need_mouse_correct) gui_mouse_correct(); #endif #ifdef FEAT_FOLDING ! /* Open fold at the cursor line, according to 'foldopen'. */ if (fdo_flags & FDO_INSERT) foldOpenCursor(); ! /* Close folds where the cursor isn't, according to 'foldclose' */ if (!char_avail()) foldCheckClose(); #endif --- 471,488 ---- msg_scroll = FALSE; #ifdef FEAT_GUI ! // When 'mousefocus' is set a mouse movement may have taken us to ! // another window. "need_mouse_correct" may then be set because of an ! // autocommand. if (need_mouse_correct) gui_mouse_correct(); #endif #ifdef FEAT_FOLDING ! // Open fold at the cursor line, according to 'foldopen'. if (fdo_flags & FDO_INSERT) foldOpenCursor(); ! // Close folds where the cursor isn't, according to 'foldclose' if (!char_avail()) foldCheckClose(); #endif *************** *** 546,557 **** } } ! /* May need to adjust w_topline to show the cursor. */ update_topline(); did_backspace = FALSE; ! validate_cursor(); /* may set must_redraw */ /* * Redraw the display when no characters are waiting. --- 546,557 ---- } } ! // May need to adjust w_topline to show the cursor. update_topline(); did_backspace = FALSE; ! validate_cursor(); // may set must_redraw /* * Redraw the display when no characters are waiting. *************** *** 571,592 **** #endif #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; /* allow scrolling here */ #endif /* * Get a character for Insert mode. Ignore K_IGNORE and K_NOP. */ if (c != K_CURSORHOLD) ! lastc = c; /* remember the previous char for CTRL-D */ ! /* After using CTRL-G U the next cursor key will not break undo. */ if (dont_sync_undo == MAYBE) dont_sync_undo = TRUE; else dont_sync_undo = FALSE; if (cmdchar == K_PS) ! /* Got here from normal mode when bracketed paste started. */ c = K_PS; else do --- 571,592 ---- #endif #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; // allow scrolling here #endif /* * Get a character for Insert mode. Ignore K_IGNORE and K_NOP. */ if (c != K_CURSORHOLD) ! lastc = c; // remember the previous char for CTRL-D ! // After using CTRL-G U the next cursor key will not break undo. if (dont_sync_undo == MAYBE) dont_sync_undo = TRUE; else dont_sync_undo = FALSE; if (cmdchar == K_PS) ! // Got here from normal mode when bracketed paste started. c = K_PS; else do *************** *** 602,613 **** } } while (c == K_IGNORE || c == K_NOP); ! /* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */ did_cursorhold = TRUE; #ifdef FEAT_RIGHTLEFT if (p_hkmap && KeyTyped) ! c = hkmap(c); /* Hebrew mode mapping */ #endif /* --- 602,613 ---- } } while (c == K_IGNORE || c == K_NOP); ! // Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. did_cursorhold = TRUE; #ifdef FEAT_RIGHTLEFT if (p_hkmap && KeyTyped) ! c = hkmap(c); // Hebrew mode mapping #endif /* *************** *** 620,637 **** && curwin->w_cursor.col >= ins_compl_col() && ins_compl_has_shown_match()) { ! /* BS: Delete one character from "compl_leader". */ if ((c == K_BS || c == Ctrl_H) && curwin->w_cursor.col > ins_compl_col() && (c = ins_compl_bs()) == NUL) continue; ! /* When no match was selected or it was edited. */ if (!ins_compl_used_match()) { ! /* CTRL-L: Add one character from the current match to ! * "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() || ins_compl_long_shown_match())) --- 620,637 ---- && curwin->w_cursor.col >= ins_compl_col() && ins_compl_has_shown_match()) { ! // BS: Delete one character from "compl_leader". if ((c == K_BS || c == Ctrl_H) && curwin->w_cursor.col > ins_compl_col() && (c = ins_compl_bs()) == NUL) continue; ! // When no match was selected or it was edited. if (!ins_compl_used_match()) { ! // CTRL-L: Add one character from the current match to ! // "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() || ins_compl_long_shown_match())) *************** *** 640,651 **** continue; } ! /* A non-white character that fits in with the current ! * completion: Add to "compl_leader". */ if (ins_compl_accept_char(c)) { #if defined(FEAT_EVAL) ! /* Trigger InsertCharPre. */ char_u *str = do_insert_char_pre(c); char_u *p; --- 640,651 ---- continue; } ! // A non-white character that fits in with the current ! // completion: Add to "compl_leader". if (ins_compl_accept_char(c)) { #if defined(FEAT_EVAL) ! // Trigger InsertCharPre. char_u *str = do_insert_char_pre(c); char_u *p; *************** *** 661,669 **** continue; } ! /* Pressing CTRL-Y selects the current match. When ! * ins_compl_enter_selects() is set the Enter key does the ! * same. */ if ((c == Ctrl_Y || (ins_compl_enter_selects() && (c == CAR || c == K_KENTER || c == NL))) && stop_arrow() == OK) --- 661,669 ---- continue; } ! // Pressing CTRL-Y selects the current match. When ! // ins_compl_enter_selects() is set the Enter key does the ! // same. if ((c == Ctrl_Y || (ins_compl_enter_selects() && (c == CAR || c == K_KENTER || c == NL))) && stop_arrow() == OK) *************** *** 674,691 **** } } ! /* Prepare for or stop CTRL-X mode. This doesn't do completion, but ! * it does fix up the text when finishing completion. */ ins_compl_init_get_longest(); if (ins_compl_prep(c)) continue; ! /* CTRL-\ CTRL-N goes to Normal mode, ! * CTRL-\ CTRL-G goes to mode selected with 'insertmode', ! * CTRL-\ CTRL-O is like CTRL-O but without moving the cursor. */ if (c == Ctrl_BSL) { ! /* may need to redraw when no more chars available now */ ins_redraw(FALSE); ++no_mapping; ++allow_keys; --- 674,691 ---- } } ! // Prepare for or stop CTRL-X mode. This doesn't do completion, but ! // it does fix up the text when finishing completion. ins_compl_init_get_longest(); if (ins_compl_prep(c)) continue; ! // CTRL-\ CTRL-N goes to Normal mode, ! // CTRL-\ CTRL-G goes to mode selected with 'insertmode', ! // CTRL-\ CTRL-O is like CTRL-O but without moving the cursor. if (c == Ctrl_BSL) { ! // may need to redraw when no more chars available now ins_redraw(FALSE); ++no_mapping; ++allow_keys; *************** *** 694,700 **** --allow_keys; if (c != Ctrl_N && c != Ctrl_G && c != Ctrl_O) { ! /* it's something else */ vungetc(c); c = Ctrl_BSL; } --- 694,700 ---- --allow_keys; if (c != Ctrl_N && c != Ctrl_G && c != Ctrl_O) { ! // it's something else vungetc(c); c = Ctrl_BSL; } *************** *** 705,711 **** if (c == Ctrl_O) { ins_ctrl_o(); ! ins_at_eol = FALSE; /* cursor keeps its column */ nomove = TRUE; } count = 0; --- 705,711 ---- if (c == Ctrl_O) { ins_ctrl_o(); ! ins_at_eol = FALSE; // cursor keeps its column nomove = TRUE; } count = 0; *************** *** 722,738 **** if (c == Ctrl_V || c == Ctrl_Q) { ins_ctrl_v(); ! c = Ctrl_V; /* pretend CTRL-V is last typed character */ continue; } #ifdef FEAT_CINDENT if (cindent_on() && ctrl_x_mode_none()) { ! /* A key name preceded by a bang means this key is not to be ! * inserted. Skip ahead to the re-indenting below. ! * A key name preceded by a star means that indenting has to be ! * done before inserting the key. */ line_is_white = inindent(0); if (in_cinkeys(c, '!', line_is_white)) goto force_cindent; --- 722,738 ---- if (c == Ctrl_V || c == Ctrl_Q) { ins_ctrl_v(); ! c = Ctrl_V; // pretend CTRL-V is last typed character continue; } #ifdef FEAT_CINDENT if (cindent_on() && ctrl_x_mode_none()) { ! // A key name preceded by a bang means this key is not to be ! // inserted. Skip ahead to the re-indenting below. ! // A key name preceded by a star means that indenting has to be ! // done before inserting the key. line_is_white = inindent(0); if (in_cinkeys(c, '!', line_is_white)) goto force_cindent; *************** *** 768,785 **** */ switch (c) { ! case ESC: /* End input mode */ if (echeck_abbr(ESC + ABBR_OFF)) break; ! /* FALLTHROUGH */ ! case Ctrl_C: /* End input mode */ #ifdef FEAT_CMDWIN if (c == Ctrl_C && cmdwin_type != 0) { ! /* Close the cmdline window. */ cmdwin_result = K_IGNORE; ! got_int = FALSE; /* don't stop executing autocommands et al. */ nomove = TRUE; goto doESCkey; } --- 768,785 ---- */ switch (c) { ! case ESC: // End input mode if (echeck_abbr(ESC + ABBR_OFF)) break; ! // FALLTHROUGH ! case Ctrl_C: // End input mode #ifdef FEAT_CMDWIN if (c == Ctrl_C && cmdwin_type != 0) { ! // Close the cmdline window. cmdwin_result = K_IGNORE; ! got_int = FALSE; // don't stop executing autocommands et al. nomove = TRUE; goto doESCkey; } *************** *** 801,813 **** #ifdef UNIX do_intr: #endif ! /* when 'insertmode' set, and not halfway a mapping, don't leave ! * Insert mode */ if (goto_im()) { if (got_int) { ! (void)vgetc(); /* flush all buffers */ got_int = FALSE; } else --- 801,813 ---- #ifdef UNIX do_intr: #endif ! // when 'insertmode' set, and not halfway a mapping, don't leave ! // Insert mode if (goto_im()) { if (got_int) { ! (void)vgetc(); // flush all buffers got_int = FALSE; } else *************** *** 818,825 **** /* * This is the ONLY return from edit()! */ ! /* Always update o_lnum, so that a "CTRL-O ." that adds a line ! * still puts the cursor back after the inserted text. */ if (ins_at_eol && gchar_cursor() == NUL) o_lnum = curwin->w_cursor.lnum; --- 818,825 ---- /* * This is the ONLY return from edit()! */ ! // Always update o_lnum, so that a "CTRL-O ." that adds a line ! // still puts the cursor back after the inserted text. if (ins_at_eol && gchar_cursor() == NUL) o_lnum = curwin->w_cursor.lnum; *************** *** 835,850 **** } continue; ! case Ctrl_Z: /* suspend when 'insertmode' set */ if (!p_im) ! goto normalchar; /* insert CTRL-Z as normal char */ do_cmdline_cmd((char_u *)"stop"); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may need to update cursor shape */ #endif continue; ! case Ctrl_O: /* execute one command */ #ifdef FEAT_COMPL_FUNC if (ctrl_x_mode_omni()) goto docomplete; --- 835,850 ---- } continue; ! case Ctrl_Z: // suspend when 'insertmode' set if (!p_im) ! goto normalchar; // insert CTRL-Z as normal char do_cmdline_cmd((char_u *)"stop"); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may need to update cursor shape #endif continue; ! case Ctrl_O: // execute one command #ifdef FEAT_COMPL_FUNC if (ctrl_x_mode_omni()) goto docomplete; *************** *** 853,859 **** break; ins_ctrl_o(); ! /* don't move the cursor left when 'virtualedit' has "onemore". */ if (ve_flags & VE_ONEMORE) { ins_at_eol = FALSE; --- 853,859 ---- break; ins_ctrl_o(); ! // don't move the cursor left when 'virtualedit' has "onemore". if (ve_flags & VE_ONEMORE) { ins_at_eol = FALSE; *************** *** 862,876 **** count = 0; goto doESCkey; ! case K_INS: /* toggle insert/replace mode */ case K_KINS: ins_insert(replaceState); break; ! case K_SELECT: /* end of Select mode mapping - ignore */ break; ! case K_HELP: /* Help key works like */ case K_F1: case K_XF1: stuffcharReadbuff(K_HELP); --- 862,876 ---- count = 0; goto doESCkey; ! case K_INS: // toggle insert/replace mode case K_KINS: ins_insert(replaceState); break; ! case K_SELECT: // end of Select mode mapping - ignore break; ! case K_HELP: // Help key works like case K_F1: case K_XF1: stuffcharReadbuff(K_HELP); *************** *** 879,933 **** goto doESCkey; #ifdef FEAT_NETBEANS_INTG ! case K_F21: /* NetBeans command */ ! ++no_mapping; /* don't map the next key hits */ i = plain_vgetc(); --no_mapping; netbeans_keycommand(i); break; #endif ! case K_ZERO: /* Insert the previously inserted text. */ case NUL: case Ctrl_A: ! /* For ^@ the trailing ESC will end the insert, unless there is an ! * error. */ if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL && c != Ctrl_A && !p_im) ! goto doESCkey; /* quit insert mode */ inserted_space = FALSE; break; ! case Ctrl_R: /* insert the contents of a register */ ins_reg(); auto_format(FALSE, TRUE); inserted_space = FALSE; break; ! case Ctrl_G: /* commands starting with CTRL-G */ ins_ctrl_g(); break; ! case Ctrl_HAT: /* switch input mode and/or langmap */ ins_ctrl_hat(); break; #ifdef FEAT_RIGHTLEFT ! case Ctrl__: /* switch between languages */ if (!p_ari) goto normalchar; ins_ctrl_(); break; #endif ! case Ctrl_D: /* Make indent one shiftwidth smaller. */ #if defined(FEAT_FIND_ID) if (ctrl_x_mode_path_defines()) goto docomplete; #endif ! /* FALLTHROUGH */ ! case Ctrl_T: /* Make indent one shiftwidth greater. */ if (c == Ctrl_T && ctrl_x_mode_thesaurus()) { if (has_compl_option(FALSE)) --- 879,933 ---- goto doESCkey; #ifdef FEAT_NETBEANS_INTG ! case K_F21: // NetBeans command ! ++no_mapping; // don't map the next key hits i = plain_vgetc(); --no_mapping; netbeans_keycommand(i); break; #endif ! case K_ZERO: // Insert the previously inserted text. case NUL: case Ctrl_A: ! // For ^@ the trailing ESC will end the insert, unless there is an ! // error. if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL && c != Ctrl_A && !p_im) ! goto doESCkey; // quit insert mode inserted_space = FALSE; break; ! case Ctrl_R: // insert the contents of a register ins_reg(); auto_format(FALSE, TRUE); inserted_space = FALSE; break; ! case Ctrl_G: // commands starting with CTRL-G ins_ctrl_g(); break; ! case Ctrl_HAT: // switch input mode and/or langmap ins_ctrl_hat(); break; #ifdef FEAT_RIGHTLEFT ! case Ctrl__: // switch between languages if (!p_ari) goto normalchar; ins_ctrl_(); break; #endif ! case Ctrl_D: // Make indent one shiftwidth smaller. #if defined(FEAT_FIND_ID) if (ctrl_x_mode_path_defines()) goto docomplete; #endif ! // FALLTHROUGH ! case Ctrl_T: // Make indent one shiftwidth greater. if (c == Ctrl_T && ctrl_x_mode_thesaurus()) { if (has_compl_option(FALSE)) *************** *** 940,958 **** inserted_space = FALSE; break; ! case K_DEL: /* delete character under the cursor */ case K_KDEL: ins_del(); auto_format(FALSE, TRUE); break; ! case K_BS: /* delete character before the cursor */ case Ctrl_H: did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space); auto_format(FALSE, TRUE); break; ! case Ctrl_W: /* delete word before the cursor */ #ifdef FEAT_JOB_CHANNEL if (bt_prompt(curbuf) && (mod_mask & MOD_MASK_SHIFT) == 0) { --- 940,958 ---- inserted_space = FALSE; break; ! case K_DEL: // delete character under the cursor case K_KDEL: ins_del(); auto_format(FALSE, TRUE); break; ! case K_BS: // delete character before the cursor case Ctrl_H: did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space); auto_format(FALSE, TRUE); break; ! case Ctrl_W: // delete word before the cursor #ifdef FEAT_JOB_CHANNEL if (bt_prompt(curbuf) && (mod_mask & MOD_MASK_SHIFT) == 0) { *************** *** 969,977 **** auto_format(FALSE, TRUE); break; ! case Ctrl_U: /* delete all inserted text in current line */ # ifdef FEAT_COMPL_FUNC ! /* CTRL-X CTRL-U completes with 'completefunc'. */ if (ctrl_x_mode_function()) goto docomplete; # endif --- 969,977 ---- auto_format(FALSE, TRUE); break; ! case Ctrl_U: // delete all inserted text in current line # ifdef FEAT_COMPL_FUNC ! // CTRL-X CTRL-U completes with 'completefunc'. if (ctrl_x_mode_function()) goto docomplete; # endif *************** *** 980,986 **** inserted_space = FALSE; break; ! case K_LEFTMOUSE: /* mouse keys */ case K_LEFTMOUSE_NM: case K_LEFTDRAG: case K_LEFTRELEASE: --- 980,986 ---- inserted_space = FALSE; break; ! case K_LEFTMOUSE: // mouse keys case K_LEFTMOUSE_NM: case K_LEFTDRAG: case K_LEFTRELEASE: *************** *** 1001,1030 **** ins_mouse(c); break; ! case K_MOUSEDOWN: /* Default action for scroll wheel up: scroll up */ ins_mousescroll(MSCR_DOWN); break; ! case K_MOUSEUP: /* Default action for scroll wheel down: scroll down */ ins_mousescroll(MSCR_UP); break; ! case K_MOUSELEFT: /* Scroll wheel left */ ins_mousescroll(MSCR_LEFT); break; ! case K_MOUSERIGHT: /* Scroll wheel right */ ins_mousescroll(MSCR_RIGHT); break; case K_PS: bracketed_paste(PASTE_INSERT, FALSE, NULL); if (cmdchar == K_PS) ! /* invoked from normal mode, bail out */ goto doESCkey; break; case K_PE: ! /* Got K_PE without K_PS, ignore. */ break; #ifdef FEAT_GUI_TABLINE --- 1001,1030 ---- ins_mouse(c); break; ! case K_MOUSEDOWN: // Default action for scroll wheel up: scroll up ins_mousescroll(MSCR_DOWN); break; ! case K_MOUSEUP: // Default action for scroll wheel down: scroll down ins_mousescroll(MSCR_UP); break; ! case K_MOUSELEFT: // Scroll wheel left ins_mousescroll(MSCR_LEFT); break; ! case K_MOUSERIGHT: // Scroll wheel right ins_mousescroll(MSCR_RIGHT); break; case K_PS: bracketed_paste(PASTE_INSERT, FALSE, NULL); if (cmdchar == K_PS) ! // invoked from normal mode, bail out goto doESCkey; break; case K_PE: ! // Got K_PE without K_PS, ignore. break; #ifdef FEAT_GUI_TABLINE *************** *** 1034,1050 **** break; #endif ! case K_IGNORE: /* Something mapped to nothing */ break; ! case K_CURSORHOLD: /* Didn't type something for a while. */ ins_apply_autocmds(EVENT_CURSORHOLDI); did_cursorhold = TRUE; break; #ifdef FEAT_GUI_MSWIN ! /* On MS-Windows ignore , we get it when closing the window ! * was cancelled. */ case K_F4: if (mod_mask != MOD_MASK_ALT) goto normalchar; --- 1034,1050 ---- break; #endif ! case K_IGNORE: // Something mapped to nothing break; ! case K_CURSORHOLD: // Didn't type something for a while. ins_apply_autocmds(EVENT_CURSORHOLDI); did_cursorhold = TRUE; break; #ifdef FEAT_GUI_MSWIN ! // On MS-Windows ignore , we get it when closing the window ! // was cancelled. case K_F4: if (mod_mask != MOD_MASK_ALT) goto normalchar; *************** *** 1061,1105 **** break; #endif ! case K_HOME: /* */ case K_KHOME: case K_S_HOME: case K_C_HOME: ins_home(c); break; ! case K_END: /* */ case K_KEND: case K_S_END: case K_C_END: ins_end(c); break; ! case K_LEFT: /* */ if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) ins_s_left(); else ins_left(); break; ! case K_S_LEFT: /* */ case K_C_LEFT: ins_s_left(); break; ! case K_RIGHT: /* */ if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) ins_s_right(); else ins_right(); break; ! case K_S_RIGHT: /* */ case K_C_RIGHT: ins_s_right(); break; ! case K_UP: /* */ if (pum_visible()) goto docomplete; if (mod_mask & MOD_MASK_SHIFT) --- 1061,1105 ---- break; #endif ! case K_HOME: // case K_KHOME: case K_S_HOME: case K_C_HOME: ins_home(c); break; ! case K_END: // case K_KEND: case K_S_END: case K_C_END: ins_end(c); break; ! case K_LEFT: // if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) ins_s_left(); else ins_left(); break; ! case K_S_LEFT: // case K_C_LEFT: ins_s_left(); break; ! case K_RIGHT: // if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) ins_s_right(); else ins_right(); break; ! case K_S_RIGHT: // case K_C_RIGHT: ins_s_right(); break; ! case K_UP: // if (pum_visible()) goto docomplete; if (mod_mask & MOD_MASK_SHIFT) *************** *** 1108,1114 **** ins_up(FALSE); break; ! case K_S_UP: /* */ case K_PAGEUP: case K_KPAGEUP: if (pum_visible()) --- 1108,1114 ---- ins_up(FALSE); break; ! case K_S_UP: // case K_PAGEUP: case K_KPAGEUP: if (pum_visible()) *************** *** 1116,1122 **** ins_pageup(); break; ! case K_DOWN: /* */ if (pum_visible()) goto docomplete; if (mod_mask & MOD_MASK_SHIFT) --- 1116,1122 ---- ins_pageup(); break; ! case K_DOWN: // if (pum_visible()) goto docomplete; if (mod_mask & MOD_MASK_SHIFT) *************** *** 1125,1131 **** ins_down(FALSE); break; ! case K_S_DOWN: /* */ case K_PAGEDOWN: case K_KPAGEDOWN: if (pum_visible()) --- 1125,1131 ---- ins_down(FALSE); break; ! case K_S_DOWN: // case K_PAGEDOWN: case K_KPAGEDOWN: if (pum_visible()) *************** *** 1134,1172 **** break; #ifdef FEAT_DND ! case K_DROP: /* drag-n-drop event */ ins_drop(); break; #endif ! case K_S_TAB: /* When not mapped, use like a normal TAB */ c = TAB; ! /* FALLTHROUGH */ ! case TAB: /* TAB or Complete patterns along path */ #if defined(FEAT_FIND_ID) if (ctrl_x_mode_path_patterns()) goto docomplete; #endif inserted_space = FALSE; if (ins_tab()) ! goto normalchar; /* insert TAB as a normal char */ auto_format(FALSE, TRUE); break; ! case K_KENTER: /* */ c = CAR; ! /* FALLTHROUGH */ case CAR: case NL: #if defined(FEAT_QUICKFIX) ! /* In a quickfix window a jumps to the error under the ! * cursor. */ if (bt_quickfix(curbuf) && c == CAR) { ! if (curwin->w_llist_ref == NULL) /* quickfix window */ do_cmdline_cmd((char_u *)".cc"); ! else /* location list window */ do_cmdline_cmd((char_u *)".ll"); break; } --- 1134,1172 ---- break; #ifdef FEAT_DND ! case K_DROP: // drag-n-drop event ins_drop(); break; #endif ! case K_S_TAB: // When not mapped, use like a normal TAB c = TAB; ! // FALLTHROUGH ! case TAB: // TAB or Complete patterns along path #if defined(FEAT_FIND_ID) if (ctrl_x_mode_path_patterns()) goto docomplete; #endif inserted_space = FALSE; if (ins_tab()) ! goto normalchar; // insert TAB as a normal char auto_format(FALSE, TRUE); break; ! case K_KENTER: // c = CAR; ! // FALLTHROUGH case CAR: case NL: #if defined(FEAT_QUICKFIX) ! // In a quickfix window a jumps to the error under the ! // cursor. if (bt_quickfix(curbuf) && c == CAR) { ! if (curwin->w_llist_ref == NULL) // quickfix window do_cmdline_cmd((char_u *)".cc"); ! else // location list window do_cmdline_cmd((char_u *)".ll"); break; } *************** *** 1174,1180 **** #ifdef FEAT_CMDWIN if (cmdwin_type != 0) { ! /* Execute the command in the cmdline window. */ cmdwin_result = CAR; goto doESCkey; } --- 1174,1180 ---- #ifdef FEAT_CMDWIN if (cmdwin_type != 0) { ! // Execute the command in the cmdline window. cmdwin_result = CAR; goto doESCkey; } *************** *** 1191,1202 **** } #endif if (ins_eol(c) == FAIL && !p_im) ! goto doESCkey; /* out of memory */ auto_format(FALSE, FALSE); inserted_space = FALSE; break; ! case Ctrl_K: /* digraph or keyword completion */ if (ctrl_x_mode_dictionary()) { if (has_compl_option(TRUE)) --- 1191,1202 ---- } #endif if (ins_eol(c) == FAIL && !p_im) ! goto doESCkey; // out of memory auto_format(FALSE, FALSE); inserted_space = FALSE; break; ! case Ctrl_K: // digraph or keyword completion if (ctrl_x_mode_dictionary()) { if (has_compl_option(TRUE)) *************** *** 1210,1239 **** #endif goto normalchar; ! case Ctrl_X: /* Enter CTRL-X mode */ ins_ctrl_x(); break; ! case Ctrl_RSB: /* Tag name completion after ^X */ if (!ctrl_x_mode_tags()) goto normalchar; goto docomplete; ! case Ctrl_F: /* File name completion after ^X */ if (!ctrl_x_mode_files()) goto normalchar; goto docomplete; ! case 's': /* Spelling completion after ^X */ case Ctrl_S: if (!ctrl_x_mode_spell()) goto normalchar; goto docomplete; ! case Ctrl_L: /* Whole line completion after ^X */ if (!ctrl_x_mode_whole_line()) { ! /* CTRL-L with 'insertmode' set: Leave Insert mode */ if (p_im) { if (echeck_abbr(Ctrl_L + ABBR_OFF)) --- 1210,1239 ---- #endif goto normalchar; ! case Ctrl_X: // Enter CTRL-X mode ins_ctrl_x(); break; ! case Ctrl_RSB: // Tag name completion after ^X if (!ctrl_x_mode_tags()) goto normalchar; goto docomplete; ! case Ctrl_F: // File name completion after ^X if (!ctrl_x_mode_files()) goto normalchar; goto docomplete; ! case 's': // Spelling completion after ^X case Ctrl_S: if (!ctrl_x_mode_spell()) goto normalchar; goto docomplete; ! case Ctrl_L: // Whole line completion after ^X if (!ctrl_x_mode_whole_line()) { ! // CTRL-L with 'insertmode' set: Leave Insert mode if (p_im) { if (echeck_abbr(Ctrl_L + ABBR_OFF)) *************** *** 1242,1253 **** } goto normalchar; } ! /* FALLTHROUGH */ ! case Ctrl_P: /* Do previous/next pattern completion */ case Ctrl_N: ! /* if 'complete' is empty then plain ^P is no longer special, ! * but it is under other ^X modes */ if (*curbuf->b_p_cpt == NUL && (ctrl_x_mode_normal() || ctrl_x_mode_whole_line()) && !(compl_cont_status & CONT_LOCAL)) --- 1242,1253 ---- } goto normalchar; } ! // FALLTHROUGH ! case Ctrl_P: // Do previous/next pattern completion case Ctrl_N: ! // if 'complete' is empty then plain ^P is no longer special, ! // but it is under other ^X modes if (*curbuf->b_p_cpt == NUL && (ctrl_x_mode_normal() || ctrl_x_mode_whole_line()) && !(compl_cont_status & CONT_LOCAL)) *************** *** 1256,1262 **** docomplete: compl_busy = TRUE; #ifdef FEAT_FOLDING ! disable_fold_update++; /* don't redraw folds here */ #endif if (ins_complete(c, TRUE) == FAIL) compl_cont_status = 0; --- 1256,1262 ---- docomplete: compl_busy = TRUE; #ifdef FEAT_FOLDING ! disable_fold_update++; // don't redraw folds here #endif if (ins_complete(c, TRUE) == FAIL) compl_cont_status = 0; *************** *** 1266,1279 **** compl_busy = FALSE; break; ! case Ctrl_Y: /* copy from previous line or scroll down */ ! case Ctrl_E: /* copy from next line or scroll up */ c = ins_ctrl_ey(c); break; default: #ifdef UNIX ! if (c == intr_char) /* special interrupt char */ goto do_intr; #endif --- 1266,1279 ---- compl_busy = FALSE; break; ! case Ctrl_Y: // copy from previous line or scroll down ! case Ctrl_E: // copy from next line or scroll up c = ins_ctrl_ey(c); break; default: #ifdef UNIX ! if (c == intr_char) // special interrupt char goto do_intr; #endif *************** *** 1284,1290 **** #if defined(FEAT_EVAL) if (!p_paste) { ! /* Trigger InsertCharPre. */ char_u *str = do_insert_char_pre(c); char_u *p; --- 1284,1290 ---- #if defined(FEAT_EVAL) if (!p_paste) { ! // Trigger InsertCharPre. char_u *str = do_insert_char_pre(c); char_u *p; *************** *** 1292,1298 **** { if (*str != NUL && stop_arrow() != FAIL) { ! /* Insert the new value of v:char literally. */ for (p = str; *p != NUL; MB_PTR_ADV(p)) { c = PTR2CHAR(p); --- 1292,1298 ---- { if (*str != NUL && stop_arrow() != FAIL) { ! // Insert the new value of v:char literally. for (p = str; *p != NUL; MB_PTR_ADV(p)) { c = PTR2CHAR(p); *************** *** 1307,1320 **** c = NUL; } ! /* If the new value is already inserted or an empty string ! * then don't insert any character. */ if (c == NUL) break; } #endif #ifdef FEAT_SMARTINDENT ! /* Try to perform smart-indenting. */ ins_try_si(c); #endif --- 1307,1320 ---- c = NUL; } ! // If the new value is already inserted or an empty string ! // then don't insert any character. if (c == NUL) break; } #endif #ifdef FEAT_SMARTINDENT ! // Try to perform smart-indenting. ins_try_si(c); #endif *************** *** 1330,1338 **** Insstart_blank_vcol = get_nolist_virtcol(); } ! /* Insert a normal character and check for abbreviations on a ! * special character. Let CTRL-] expand abbreviations without ! * inserting it. */ if (vim_iswordc(c) || (!echeck_abbr( // Add ABBR_OFF for characters above 0x100, this is // what check_abbr() expects. --- 1330,1338 ---- Insstart_blank_vcol = get_nolist_virtcol(); } ! // Insert a normal character and check for abbreviations on a ! // special character. Let CTRL-] expand abbreviations without ! // inserting it. if (vim_iswordc(c) || (!echeck_abbr( // Add ABBR_OFF for characters above 0x100, this is // what check_abbr() expects. *************** *** 1349,1371 **** auto_format(FALSE, TRUE); #ifdef FEAT_FOLDING ! /* When inserting a character the cursor line must never be in a ! * closed fold. */ foldOpenCursor(); #endif break; ! } /* end of switch (c) */ ! /* If typed something may trigger CursorHoldI again. */ if (c != K_CURSORHOLD #ifdef FEAT_COMPL_FUNC ! /* but not in CTRL-X mode, a script can't restore the state */ && ctrl_x_mode_normal() #endif ) did_cursorhold = FALSE; ! /* If the cursor was moved we didn't just insert a space */ if (arrow_used) inserted_space = FALSE; --- 1349,1371 ---- auto_format(FALSE, TRUE); #ifdef FEAT_FOLDING ! // When inserting a character the cursor line must never be in a ! // closed fold. foldOpenCursor(); #endif break; ! } // end of switch (c) ! // If typed something may trigger CursorHoldI again. if (c != K_CURSORHOLD #ifdef FEAT_COMPL_FUNC ! // but not in CTRL-X mode, a script can't restore the state && ctrl_x_mode_normal() #endif ) did_cursorhold = FALSE; ! // If the cursor was moved we didn't just insert a space if (arrow_used) inserted_space = FALSE; *************** *** 1379,1392 **** if (in_cinkeys(c, ' ', line_is_white)) { if (stop_arrow() == OK) ! /* re-indent the current line */ do_c_expr_indent(); } } ! #endif /* FEAT_CINDENT */ ! } /* for (;;) */ ! /* NOTREACHED */ } int --- 1379,1392 ---- if (in_cinkeys(c, ' ', line_is_white)) { if (stop_arrow() == OK) ! // re-indent the current line do_c_expr_indent(); } } ! #endif // FEAT_CINDENT ! } // for (;;) ! // NOTREACHED } int *************** *** 1414,1421 **** if (char_avail()) return; ! /* Trigger CursorMoved if the cursor moved. Not when the popup menu is ! * visible, the command might delete it. */ if (ready && (has_cursormovedI() # ifdef FEAT_PROP_POPUP || popup_visible --- 1414,1421 ---- if (char_avail()) return; ! // Trigger CursorMoved if the cursor moved. Not when the popup menu is ! // visible, the command might delete it. if (ready && (has_cursormovedI() # ifdef FEAT_PROP_POPUP || popup_visible *************** *** 1428,1444 **** && !pum_visible()) { # ifdef FEAT_SYN_HL ! /* Need to update the screen first, to make sure syntax ! * highlighting is correct after making a change (e.g., inserting ! * a "(". The autocommand may also require a redraw, so it's done ! * again below, unfortunately. */ if (syntax_present(curwin) && must_redraw) update_screen(0); # endif if (has_cursormovedI()) { ! /* Make sure curswant is correct, an autocommand may call ! * getcurpos(). */ update_curswant(); ins_apply_autocmds(EVENT_CURSORMOVEDI); } --- 1428,1444 ---- && !pum_visible()) { # ifdef FEAT_SYN_HL ! // Need to update the screen first, to make sure syntax ! // highlighting is correct after making a change (e.g., inserting ! // a "(". The autocommand may also require a redraw, so it's done ! // again below, unfortunately. if (syntax_present(curwin) && must_redraw) update_screen(0); # endif if (has_cursormovedI()) { ! // Make sure curswant is correct, an autocommand may call ! // getcurpos(). update_curswant(); ins_apply_autocmds(EVENT_CURSORMOVEDI); } *************** *** 1457,1463 **** last_cursormoved = curwin->w_cursor; } ! /* Trigger TextChangedI if b_changedtick differs. */ if (ready && has_textchangedI() && curbuf->b_last_changedtick != CHANGEDTICK(curbuf) && !pum_visible()) --- 1457,1463 ---- last_cursormoved = curwin->w_cursor; } ! // Trigger TextChangedI if b_changedtick differs. if (ready && has_textchangedI() && curbuf->b_last_changedtick != CHANGEDTICK(curbuf) && !pum_visible()) *************** *** 1475,1483 **** (linenr_T)(curwin->w_cursor.lnum + 1)); } ! /* Trigger TextChangedP if b_changedtick differs. When the popupmenu closes ! * TextChangedI will need to trigger for backwards compatibility, thus use ! * different b_last_changedtick* variables. */ if (ready && has_textchangedP() && curbuf->b_last_changedtick_pum != CHANGEDTICK(curbuf) && pum_visible()) --- 1475,1483 ---- (linenr_T)(curwin->w_cursor.lnum + 1)); } ! // Trigger TextChangedP if b_changedtick differs. When the popupmenu closes ! // TextChangedI will need to trigger for backwards compatibility, thus use ! // different b_last_changedtick* variables. if (ready && has_textchangedP() && curbuf->b_last_changedtick_pum != CHANGEDTICK(curbuf) && pum_visible()) *************** *** 1517,1526 **** if (must_redraw) update_screen(0); else if (clear_cmdline || redraw_cmdline) ! showmode(); /* clear cmdline and show mode */ showruler(FALSE); setcursor(); ! emsg_on_display = FALSE; /* may remove error message now */ } /* --- 1517,1526 ---- if (must_redraw) update_screen(0); else if (clear_cmdline || redraw_cmdline) ! showmode(); // clear cmdline and show mode showruler(FALSE); setcursor(); ! emsg_on_display = FALSE; // may remove error message now } /* *************** *** 1533,1539 **** int did_putchar = FALSE; int prev_mod_mask = mod_mask; ! /* may need to redraw when no more chars available now */ ins_redraw(FALSE); if (redrawing() && !char_avail()) --- 1533,1539 ---- int did_putchar = FALSE; int prev_mod_mask = mod_mask; ! // may need to redraw when no more chars available now ins_redraw(FALSE); if (redrawing() && !char_avail()) *************** *** 1541,1547 **** edit_putchar('^', TRUE); did_putchar = TRUE; } ! AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */ #ifdef FEAT_CMDL_INFO add_to_showcmd_c(Ctrl_V); --- 1541,1547 ---- edit_putchar('^', TRUE); did_putchar = TRUE; } ! AppendToRedobuff((char_u *)CTRL_V_STR); // CTRL-V #ifdef FEAT_CMDL_INFO add_to_showcmd_c(Ctrl_V); *************** *** 1549,1556 **** c = get_literal(); if (did_putchar) ! /* when the line fits in 'columns' the '^' is at the start of the next ! * line and will not removed by the redraw */ edit_unputchar(); #ifdef FEAT_CMDL_INFO clear_showcmd(); --- 1549,1556 ---- c = get_literal(); if (did_putchar) ! // when the line fits in 'columns' the '^' is at the start of the next ! // line and will not removed by the redraw edit_unputchar(); #ifdef FEAT_CMDL_INFO clear_showcmd(); *************** *** 1626,1636 **** * Used while handling CTRL-K, CTRL-V, etc. in Insert mode. */ static int pc_status; ! #define PC_STATUS_UNSET 0 /* pc_bytes was not set */ ! #define PC_STATUS_RIGHT 1 /* right halve of double-wide char */ ! #define PC_STATUS_LEFT 2 /* left halve of double-wide char */ ! #define PC_STATUS_SET 3 /* pc_bytes was filled */ ! static char_u pc_bytes[MB_MAXBYTES + 1]; /* saved bytes */ static int pc_attr; static int pc_row; static int pc_col; --- 1626,1636 ---- * Used while handling CTRL-K, CTRL-V, etc. in Insert mode. */ static int pc_status; ! #define PC_STATUS_UNSET 0 // pc_bytes was not set ! #define PC_STATUS_RIGHT 1 // right halve of double-wide char ! #define PC_STATUS_LEFT 2 // left halve of double-wide char ! #define PC_STATUS_SET 3 // pc_bytes was filled ! static char_u pc_bytes[MB_MAXBYTES + 1]; // saved bytes static int pc_attr; static int pc_row; static int pc_col; *************** *** 1642,1648 **** if (ScreenLines != NULL) { ! update_topline(); /* just in case w_topline isn't valid */ validate_cursor(); if (highlight) attr = HL_ATTR(HLF_8); --- 1642,1648 ---- if (ScreenLines != NULL) { ! update_topline(); // just in case w_topline isn't valid validate_cursor(); if (highlight) attr = HL_ATTR(HLF_8); *************** *** 1675,1681 **** pc_status = PC_STATUS_LEFT; } ! /* save the character to be able to put it back */ if (pc_status == PC_STATUS_UNSET) { screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr); --- 1675,1681 ---- pc_status = PC_STATUS_LEFT; } ! // save the character to be able to put it back if (pc_status == PC_STATUS_UNSET) { screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr); *************** *** 1737,1743 **** coladvance((colnr_T)MAXCOL); if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt)) curwin->w_cursor.col = (int)STRLEN(prompt); ! /* Make sure the cursor is in a valid position. */ check_cursor(); } --- 1737,1743 ---- coladvance((colnr_T)MAXCOL); if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt)) curwin->w_cursor.col = (int)STRLEN(prompt); ! // Make sure the cursor is in a valid position. check_cursor(); } *************** *** 1788,1798 **** { char_u *p; ! /* If on the last byte of a multi-byte move to the first byte. */ p = ml_get_curline(); curwin->w_cursor.col -= (*mb_head_off)(p, p + col); } ! curs_columns(FALSE); /* recompute w_wrow and w_wcol */ if (curwin->w_wcol < curwin->w_width) { edit_putchar('$', FALSE); --- 1788,1798 ---- { char_u *p; ! // If on the last byte of a multi-byte move to the first byte. p = ml_get_curline(); curwin->w_cursor.col -= (*mb_head_off)(p, p + col); } ! curs_columns(FALSE); // recompute w_wrow and w_wcol if (curwin->w_wcol < curwin->w_width) { edit_putchar('$', FALSE); *************** *** 1825,1835 **** { int i; ! /* find start of trailing white space */ for (i = (int)STRLEN(line) - 1; i >= 0 && VIM_ISWHITE(line[i]); i--) { if (State & REPLACE_FLAG) ! replace_join(0); /* remove a NUL from the replace stack */ } line[i + 1] = NUL; } --- 1825,1835 ---- { int i; ! // find start of trailing white space for (i = (int)STRLEN(line) - 1; i >= 0 && VIM_ISWHITE(line[i]); i--) { if (State & REPLACE_FLAG) ! replace_join(0); // remove a NUL from the replace stack } line[i + 1] = NUL; } *************** *** 1865,1879 **** { colnr_T ecol = curwin->w_cursor.col + 1; ! /* Make sure the cursor is at the start of a character, but ! * skip forward again when going too far back because of a ! * composing character. */ mb_adjust_cursor(); while (curwin->w_cursor.col < (colnr_T)limit_col) { int l = utf_ptr2len(ml_get_cursor()); ! if (l == 0) /* end of line */ break; curwin->w_cursor.col += l; } --- 1865,1879 ---- { colnr_T ecol = curwin->w_cursor.col + 1; ! // Make sure the cursor is at the start of a character, but ! // skip forward again when going too far back because of a ! // composing character. mb_adjust_cursor(); while (curwin->w_cursor.col < (colnr_T)limit_col) { int l = utf_ptr2len(ml_get_cursor()); ! if (l == 0) // end of line break; curwin->w_cursor.col += l; } *************** *** 1916,1924 **** ++allow_keys; #endif #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; /* disallow scrolling here */ #endif ! ++no_mapping; /* don't map the next key hits */ cc = 0; i = 0; for (;;) --- 1916,1924 ---- ++allow_keys; #endif #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; // disallow scrolling here #endif ! ++no_mapping; // don't map the next key hits cc = 0; i = 0; for (;;) *************** *** 1959,1983 **** } if (cc > 255 && unicode == 0) ! cc = 255; /* limit range to 0-255 */ nc = 0; ! if (hex) /* hex: up to two chars */ { if (i >= 2) break; } ! else if (unicode) /* Unicode: up to four or eight chars */ { if ((unicode == 'u' && i >= 4) || (unicode == 'U' && i >= 8)) break; } ! else if (i >= 3) /* decimal or octal: up to three chars */ break; } ! if (i == 0) /* no number entered */ { ! if (nc == K_ZERO) /* NUL is stored as NL */ { cc = '\n'; nc = 0; --- 1959,1983 ---- } if (cc > 255 && unicode == 0) ! cc = 255; // limit range to 0-255 nc = 0; ! if (hex) // hex: up to two chars { if (i >= 2) break; } ! else if (unicode) // Unicode: up to four or eight chars { if ((unicode == 'u' && i >= 4) || (unicode == 'U' && i >= 8)) break; } ! else if (i >= 3) // decimal or octal: up to three chars break; } ! if (i == 0) // no number entered { ! if (nc == K_ZERO) // NUL is stored as NL { cc = '\n'; nc = 0; *************** *** 1989,1999 **** } } ! if (cc == 0) /* NUL is stored as NL */ cc = '\n'; if (enc_dbcs && (cc & 0xff) == 0) ! cc = '?'; /* don't accept an illegal DBCS char, the NUL in the ! second byte will cause trouble! */ --no_mapping; #ifdef FEAT_GUI --- 1989,1999 ---- } } ! if (cc == 0) // NUL is stored as NL cc = '\n'; if (enc_dbcs && (cc & 0xff) == 0) ! cc = '?'; // don't accept an illegal DBCS char, the NUL in the ! // second byte will cause trouble! --no_mapping; #ifdef FEAT_GUI *************** *** 2002,2008 **** #endif if (nc) vungetc(nc); ! got_int = FALSE; /* CTRL-C typed after CTRL-V is not an interrupt */ return cc; } --- 2002,2008 ---- #endif if (nc) vungetc(nc); ! got_int = FALSE; // CTRL-C typed after CTRL-V is not an interrupt return cc; } *************** *** 2013,2019 **** insert_special( int c, int allow_modmask, ! int ctrlv) /* c was typed after CTRL-V */ { char_u *p; int len; --- 2013,2019 ---- insert_special( int c, int allow_modmask, ! int ctrlv) // c was typed after CTRL-V { char_u *p; int len; *************** *** 2026,2032 **** * unless 'allow_modmask' is TRUE. */ #ifdef MACOS_X ! /* Command-key never produces a normal key */ if (mod_mask & MOD_MASK_CMD) allow_modmask = TRUE; #endif --- 2026,2032 ---- * unless 'allow_modmask' is TRUE. */ #ifdef MACOS_X ! // Command-key never produces a normal key if (mod_mask & MOD_MASK_CMD) allow_modmask = TRUE; #endif *************** *** 2078,2086 **** */ void insertchar( ! int c, /* character to insert or NUL */ ! int flags, /* INSCHAR_FORMAT, etc. */ ! int second_indent) /* indent for second line if >= 0 */ { int textwidth; char_u *p; --- 2078,2086 ---- */ void insertchar( ! int c, // character to insert or NUL ! int flags, // INSCHAR_FORMAT, etc. ! int second_indent) // indent for second line if >= 0 { int textwidth; char_u *p; *************** *** 2118,2125 **** || Insstart_blank_vcol <= (colnr_T)textwidth )))))) { ! /* Format with 'formatexpr' when it's set. Use internal formatting ! * when 'formatexpr' isn't set or it returns non-zero. */ #if defined(FEAT_EVAL) int do_internal = TRUE; colnr_T virtcol = get_nolist_virtcol() --- 2118,2125 ---- || Insstart_blank_vcol <= (colnr_T)textwidth )))))) { ! // Format with 'formatexpr' when it's set. Use internal formatting ! // when 'formatexpr' isn't set or it returns non-zero. #if defined(FEAT_EVAL) int do_internal = TRUE; colnr_T virtcol = get_nolist_virtcol() *************** *** 2129,2136 **** && (force_format || virtcol > (colnr_T)textwidth)) { do_internal = (fex_format(curwin->w_cursor.lnum, 1L, c) != 0); ! /* It may be required to save for undo again, e.g. when setline() ! * was called. */ ins_need_undo = TRUE; } if (do_internal) --- 2129,2136 ---- && (force_format || virtcol > (colnr_T)textwidth)) { do_internal = (fex_format(curwin->w_cursor.lnum, 1L, c) != 0); ! // It may be required to save for undo again, e.g. when setline() ! // was called. ins_need_undo = TRUE; } if (do_internal) *************** *** 2138,2144 **** internal_format(textwidth, second_indent, flags, c == NUL, c); } ! if (c == NUL) /* only formatting was wanted */ return; // Check whether this character should end a comment. --- 2138,2144 ---- internal_format(textwidth, second_indent, flags, c == NUL, c); } ! if (c == NUL) // only formatting was wanted return; // Check whether this character should end a comment. *************** *** 2211,2217 **** * InsertCharPre autocommand could change the input buffer. */ #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; /* allow scrolling here */ #endif if ( !ISSPECIAL(c) --- 2211,2217 ---- * InsertCharPre autocommand could change the input buffer. */ #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; // allow scrolling here #endif if ( !ISSPECIAL(c) *************** *** 2255,2261 **** #ifdef FEAT_RIGHTLEFT c = vgetc(); if (p_hkmap && KeyTyped) ! c = hkmap(c); /* Hebrew mode mapping */ buf[i++] = c; #else buf[i++] = vgetc(); --- 2255,2261 ---- #ifdef FEAT_RIGHTLEFT c = vgetc(); if (p_hkmap && KeyTyped) ! c = hkmap(c); // Hebrew mode mapping buf[i++] = c; #else buf[i++] = vgetc(); *************** *** 2263,2270 **** } #ifdef FEAT_DIGRAPHS ! do_digraph(-1); /* clear digraphs */ ! do_digraph(buf[i-1]); /* may be the start of a digraph */ #endif buf[i] = NUL; ins_str(buf); --- 2263,2270 ---- } #ifdef FEAT_DIGRAPHS ! do_digraph(-1); // clear digraphs ! do_digraph(buf[i-1]); // may be the start of a digraph #endif buf[i] = NUL; ins_str(buf); *************** *** 2314,2320 **** int second_indent, int flags, int format_only, ! int c) /* character to be inserted (can be NUL) */ { int cc; int save_char = NUL; --- 2314,2320 ---- int second_indent, int flags, int format_only, ! int c) // character to be inserted (can be NUL) { int cc; int save_char = NUL; *************** *** 2329,2335 **** #ifdef FEAT_LINEBREAK int has_lbr = curwin->w_p_lbr; ! /* make sure win_lbr_chartabsize() counts correctly */ curwin->w_p_lbr = FALSE; #endif --- 2329,2335 ---- #ifdef FEAT_LINEBREAK int has_lbr = curwin->w_p_lbr; ! // make sure win_lbr_chartabsize() counts correctly curwin->w_p_lbr = FALSE; #endif *************** *** 2352,2361 **** */ while (!got_int) { ! int startcol; /* Cursor column at entry */ ! int wantcol; /* column at textwidth border */ ! int foundcol; /* column for start of spaces */ ! int end_foundcol = 0; /* column for start of word */ colnr_T len; colnr_T virtcol; int orig_col = 0; --- 2352,2361 ---- */ while (!got_int) { ! int startcol; // Cursor column at entry ! int wantcol; // column at textwidth border ! int foundcol; // column for start of spaces ! int end_foundcol = 0; // column for start of word colnr_T len; colnr_T virtcol; int orig_col = 0; *************** *** 2375,2390 **** && has_format_option(FO_WRAP_COMS)) do_comments = TRUE; ! /* Don't break until after the comment leader */ if (do_comments) leader_len = get_leader_len(ml_get_curline(), NULL, FALSE, TRUE); else leader_len = 0; ! /* If the line doesn't start with a comment leader, then don't ! * start one in a following broken line. Avoids that a %word ! * moved to the start of the next line causes all following lines ! * to start with %. */ if (leader_len == 0) no_leader = TRUE; if (!(flags & INSCHAR_FORMAT) --- 2375,2390 ---- && has_format_option(FO_WRAP_COMS)) do_comments = TRUE; ! // Don't break until after the comment leader if (do_comments) leader_len = get_leader_len(ml_get_curline(), NULL, FALSE, TRUE); else leader_len = 0; ! // If the line doesn't start with a comment leader, then don't ! // start one in a following broken line. Avoids that a %word ! // moved to the start of the next line causes all following lines ! // to start with %. if (leader_len == 0) no_leader = TRUE; if (!(flags & INSCHAR_FORMAT) *************** *** 2395,2401 **** if ((startcol = curwin->w_cursor.col) == 0) break; ! /* find column of textwidth border */ coladvance((colnr_T)textwidth); wantcol = curwin->w_cursor.col; --- 2395,2401 ---- if ((startcol = curwin->w_cursor.col) == 0) break; ! // find column of textwidth border coladvance((colnr_T)textwidth); wantcol = curwin->w_cursor.col; *************** *** 2417,2423 **** cc = gchar_cursor(); if (WHITECHAR(cc)) { ! /* remember position of blank just before text */ end_col = curwin->w_cursor.col; // find start of sequence of blanks --- 2417,2423 ---- cc = gchar_cursor(); if (WHITECHAR(cc)) { ! // remember position of blank just before text end_col = curwin->w_cursor.col; // find start of sequence of blanks *************** *** 2433,2454 **** wcc++; } if (curwin->w_cursor.col == 0 && WHITECHAR(cc)) ! break; /* only spaces in front of text */ // Don't break after a period when 'formatoptions' has 'p' and // there are less than two spaces. if (has_format_option(FO_PERIOD_ABBR) && cc == '.' && wcc < 2) continue; ! /* Don't break until after the comment leader */ if (curwin->w_cursor.col < leader_len) break; if (has_format_option(FO_ONE_LETTER)) { ! /* do not break after one-letter words */ if (curwin->w_cursor.col == 0) ! break; /* one-letter word at begin */ ! /* do not break "#a b" when 'tw' is 2 */ if (curwin->w_cursor.col <= leader_len) break; col = curwin->w_cursor.col; --- 2433,2454 ---- wcc++; } if (curwin->w_cursor.col == 0 && WHITECHAR(cc)) ! break; // only spaces in front of text // Don't break after a period when 'formatoptions' has 'p' and // there are less than two spaces. if (has_format_option(FO_PERIOD_ABBR) && cc == '.' && wcc < 2) continue; ! // Don't break until after the comment leader if (curwin->w_cursor.col < leader_len) break; if (has_format_option(FO_ONE_LETTER)) { ! // do not break after one-letter words if (curwin->w_cursor.col == 0) ! break; // one-letter word at begin ! // do not break "#a b" when 'tw' is 2 if (curwin->w_cursor.col <= leader_len) break; col = curwin->w_cursor.col; *************** *** 2456,2462 **** cc = gchar_cursor(); if (WHITECHAR(cc)) ! continue; /* one-letter, continue */ curwin->w_cursor.col = col; } --- 2456,2462 ---- cc = gchar_cursor(); if (WHITECHAR(cc)) ! continue; // one-letter, continue curwin->w_cursor.col = col; } *************** *** 2469,2483 **** } else if (cc >= 0x100 && fo_multibyte) { ! /* Break after or before a multi-byte character. */ if (curwin->w_cursor.col != startcol) { ! /* Don't break until after the comment leader */ if (curwin->w_cursor.col < leader_len) break; col = curwin->w_cursor.col; inc_cursor(); ! /* Don't change end_foundcol if already set. */ if (foundcol != curwin->w_cursor.col) { foundcol = curwin->w_cursor.col; --- 2469,2483 ---- } else if (cc >= 0x100 && fo_multibyte) { ! // Break after or before a multi-byte character. if (curwin->w_cursor.col != startcol) { ! // Don't break until after the comment leader if (curwin->w_cursor.col < leader_len) break; col = curwin->w_cursor.col; inc_cursor(); ! // Don't change end_foundcol if already set. if (foundcol != curwin->w_cursor.col) { foundcol = curwin->w_cursor.col; *************** *** 2497,2504 **** cc = gchar_cursor(); if (WHITECHAR(cc)) ! continue; /* break with space */ ! /* Don't break until after the comment leader */ if (curwin->w_cursor.col < leader_len) break; --- 2497,2504 ---- cc = gchar_cursor(); if (WHITECHAR(cc)) ! continue; // break with space ! // Don't break until after the comment leader if (curwin->w_cursor.col < leader_len) break; *************** *** 2514,2526 **** dec_cursor(); } ! if (foundcol == 0) /* no spaces, cannot break line */ { curwin->w_cursor.col = startcol; break; } ! /* Going to break the line, remove any "$" now. */ undisplay_dollar(); /* --- 2514,2526 ---- dec_cursor(); } ! if (foundcol == 0) // no spaces, cannot break line { curwin->w_cursor.col = startcol; break; } ! // Going to break the line, remove any "$" now. undisplay_dollar(); /* *************** *** 2529,2535 **** * over the text instead. */ if (State & VREPLACE_FLAG) ! orig_col = startcol; /* Will start backspacing from here */ else replace_offset = startcol - end_foundcol; --- 2529,2535 ---- * over the text instead. */ if (State & VREPLACE_FLAG) ! orig_col = startcol; // Will start backspacing from here else replace_offset = startcol - end_foundcol; *************** *** 2554,2569 **** saved_text = vim_strsave(ml_get_cursor()); curwin->w_cursor.col = orig_col; if (saved_text == NULL) ! break; /* Can't do it, out of memory */ saved_text[startcol] = NUL; ! /* Backspace over characters that will move to the next line */ if (!fo_white_par) backspace_until_column(foundcol); } else { ! /* put cursor after pos. to break line */ if (!fo_white_par) curwin->w_cursor.col = foundcol; } --- 2554,2569 ---- saved_text = vim_strsave(ml_get_cursor()); curwin->w_cursor.col = orig_col; if (saved_text == NULL) ! break; // Can't do it, out of memory saved_text[startcol] = NUL; ! // Backspace over characters that will move to the next line if (!fo_white_par) backspace_until_column(foundcol); } else { ! // put cursor after pos. to break line if (!fo_white_par) curwin->w_cursor.col = foundcol; } *************** *** 2606,2617 **** int i; int padding = second_indent - leader_len; ! /* We started at the first_line of a numbered list ! * that has a comment. the open_line() function has ! * inserted the proper comment leader and positioned ! * the cursor at the end of the split line. Now we ! * add the additional whitespace needed after the ! * comment leader for the numbered list. */ for (i = 0; i < padding; i++) ins_str((char_u *)" "); } --- 2606,2617 ---- int i; int padding = second_indent - leader_len; ! // We started at the first_line of a numbered list ! // that has a comment. the open_line() function has ! // inserted the proper comment leader and positioned ! // the cursor at the end of the split line. Now we ! // add the additional whitespace needed after the ! // comment leader for the numbered list. for (i = 0; i < padding; i++) ins_str((char_u *)" "); } *************** *** 2649,2655 **** #ifdef FEAT_CINDENT can_cindent = TRUE; #endif ! /* moved the cursor, don't autoindent or cindent now */ did_ai = FALSE; #ifdef FEAT_SMARTINDENT did_si = FALSE; --- 2649,2655 ---- #ifdef FEAT_CINDENT can_cindent = TRUE; #endif ! // moved the cursor, don't autoindent or cindent now did_ai = FALSE; #ifdef FEAT_SMARTINDENT did_si = FALSE; *************** *** 2659,2665 **** line_breakcheck(); } ! if (save_char != NUL) /* put back space after cursor */ pchar_cursor(save_char); #ifdef FEAT_LINEBREAK --- 2659,2665 ---- line_breakcheck(); } ! if (save_char != NUL) // put back space after cursor pchar_cursor(save_char); #ifdef FEAT_LINEBREAK *************** *** 2681,2688 **** */ void auto_format( ! int trailblank, /* when TRUE also format with trailing blank */ ! int prev_line) /* may start in previous line */ { pos_T pos; colnr_T len; --- 2681,2688 ---- */ void auto_format( ! int trailblank, // when TRUE also format with trailing blank ! int prev_line) // may start in previous line { pos_T pos; colnr_T len; *************** *** 2697,2710 **** pos = curwin->w_cursor; old = ml_get_curline(); ! /* may remove added space */ check_auto_format(FALSE); ! /* Don't format in Insert mode when the cursor is on a trailing blank, the ! * user might insert normal text next. Also skip formatting when "1" is ! * in 'formatoptions' and there is a single character before the cursor. ! * Otherwise the line would be broken and when typing another non-white ! * next they are not joined back together. */ wasatend = (pos.col == (colnr_T)STRLEN(old)); if (*old != NUL && !trailblank && wasatend) { --- 2697,2710 ---- pos = curwin->w_cursor; old = ml_get_curline(); ! // may remove added space check_auto_format(FALSE); ! // Don't format in Insert mode when the cursor is on a trailing blank, the ! // user might insert normal text next. Also skip formatting when "1" is ! // in 'formatoptions' and there is a single character before the cursor. ! // Otherwise the line would be broken and when typing another non-white ! // next they are not joined back together. wasatend = (pos.col == (colnr_T)STRLEN(old)); if (*old != NUL && !trailblank && wasatend) { *************** *** 2722,2729 **** curwin->w_cursor = pos; } ! /* With the 'c' flag in 'formatoptions' and 't' missing: only format ! * comments. */ if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP) && get_leader_len(old, NULL, FALSE, TRUE) == 0) return; --- 2722,2729 ---- curwin->w_cursor = pos; } ! // With the 'c' flag in 'formatoptions' and 't' missing: only format ! // comments. if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP) && get_leader_len(old, NULL, FALSE, TRUE) == 0) return; *************** *** 2751,2767 **** if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { ! /* "cannot happen" */ curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; coladvance((colnr_T)MAXCOL); } else check_cursor_col(); ! /* Insert mode: If the cursor is now after the end of the line while it ! * previously wasn't, the line was broken. Because of the rule above we ! * need to add a space when 'w' is in 'formatoptions' to keep a paragraph ! * formatted. */ if (!wasatend && has_format_option(FO_WHITE_PAR)) { new = ml_get_curline(); --- 2751,2767 ---- if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { ! // "cannot happen" curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; coladvance((colnr_T)MAXCOL); } else check_cursor_col(); ! // Insert mode: If the cursor is now after the end of the line while it ! // previously wasn't, the line was broken. Because of the rule above we ! // need to add a space when 'w' is in 'formatoptions' to keep a paragraph ! // formatted. if (!wasatend && has_format_option(FO_WHITE_PAR)) { new = ml_get_curline(); *************** *** 2772,2782 **** pnew[len] = ' '; pnew[len + 1] = NUL; ml_replace(curwin->w_cursor.lnum, pnew, FALSE); ! /* remove the space later */ did_add_space = TRUE; } else ! /* may remove added space */ check_auto_format(FALSE); } --- 2772,2782 ---- pnew[len] = ' '; pnew[len + 1] = NUL; ml_replace(curwin->w_cursor.lnum, pnew, FALSE); ! // remove the space later did_add_space = TRUE; } else ! // may remove added space check_auto_format(FALSE); } *************** *** 2790,2796 **** */ static void check_auto_format( ! int end_insert) /* TRUE when ending Insert mode */ { int c = ' '; int cc; --- 2790,2796 ---- */ static void check_auto_format( ! int end_insert) // TRUE when ending Insert mode { int c = ' '; int cc; *************** *** 2799,2805 **** { cc = gchar_cursor(); if (!WHITECHAR(cc)) ! /* Somehow the space was removed already. */ did_add_space = FALSE; else { --- 2799,2805 ---- { cc = gchar_cursor(); if (!WHITECHAR(cc)) ! // Somehow the space was removed already. did_add_space = FALSE; else { *************** *** 2811,2817 **** } if (c != NUL) { ! /* The space is no longer at the end of the line, delete it. */ del_char(FALSE); did_add_space = FALSE; } --- 2811,2817 ---- } if (c != NUL) { ! // The space is no longer at the end of the line, delete it. del_char(FALSE); did_add_space = FALSE; } *************** *** 2828,2842 **** */ int comp_textwidth( ! int ff) /* force formatting (for "gq" command) */ { int textwidth; textwidth = curbuf->b_p_tw; if (textwidth == 0 && curbuf->b_p_wm) { ! /* The width is the window width minus 'wrapmargin' minus all the ! * things that add to the margin. */ textwidth = curwin->w_width - curbuf->b_p_wm; #ifdef FEAT_CMDWIN if (cmdwin_type != 0) --- 2828,2842 ---- */ int comp_textwidth( ! int ff) // force formatting (for "gq" command) { int textwidth; textwidth = curbuf->b_p_tw; if (textwidth == 0 && curbuf->b_p_wm) { ! // The width is the window width minus 'wrapmargin' minus all the ! // things that add to the margin. textwidth = curwin->w_width - curbuf->b_p_wm; #ifdef FEAT_CMDWIN if (cmdwin_type != 0) *************** *** 2871,2878 **** { char_u buf[10]; ! /* Only digits need special treatment. Translate them into a string of ! * three digits. */ if (VIM_ISDIGIT(c)) { vim_snprintf((char *)buf, sizeof(buf), "%03d", c); --- 2871,2878 ---- { char_u buf[10]; ! // Only digits need special treatment. Translate them into a string of ! // three digits. if (VIM_ISDIGIT(c)) { vim_snprintf((char *)buf, sizeof(buf), "%03d", c); *************** *** 2888,2894 **** */ void start_arrow( ! pos_T *end_insert_pos) /* can be NULL */ { start_arrow_common(end_insert_pos, TRUE); } --- 2888,2894 ---- */ void start_arrow( ! pos_T *end_insert_pos) // can be NULL { start_arrow_common(end_insert_pos, TRUE); } *************** *** 2899,2906 **** */ static void start_arrow_with_change( ! pos_T *end_insert_pos, /* can be NULL */ ! int end_change) /* end undoable change */ { start_arrow_common(end_insert_pos, end_change); if (!end_change) --- 2899,2906 ---- */ static void start_arrow_with_change( ! pos_T *end_insert_pos, // can be NULL ! int end_change) // end undoable change { start_arrow_common(end_insert_pos, end_change); if (!end_change) *************** *** 2912,2925 **** static void start_arrow_common( ! pos_T *end_insert_pos, /* can be NULL */ ! int end_change) /* end undoable change */ { ! if (!arrow_used && end_change) /* something has been inserted */ { AppendToRedobuff(ESC_STR); stop_insert(end_insert_pos, FALSE, FALSE); ! arrow_used = TRUE; /* this means we stopped the current insert */ } #ifdef FEAT_SPELL check_spell_redraw(); --- 2912,2925 ---- static void start_arrow_common( ! pos_T *end_insert_pos, // can be NULL ! int end_change) // end undoable change { ! if (!arrow_used && end_change) // something has been inserted { AppendToRedobuff(ESC_STR); stop_insert(end_insert_pos, FALSE, FALSE); ! arrow_used = TRUE; // this means we stopped the current insert } #ifdef FEAT_SPELL check_spell_redraw(); *************** *** 2955,2964 **** { if (arrow_used) { ! Insstart = curwin->w_cursor; /* new insertion starts here */ if (Insstart.col > Insstart_orig.col && !ins_need_undo) ! /* Don't update the original insert position when moved to the ! * right, except when nothing was inserted yet. */ update_Insstart_orig = FALSE; Insstart_textlen = (colnr_T)linetabsize(ml_get_curline()); --- 2955,2964 ---- { if (arrow_used) { ! Insstart = curwin->w_cursor; // new insertion starts here if (Insstart.col > Insstart_orig.col && !ins_need_undo) ! // Don't update the original insert position when moved to the ! // right, except when nothing was inserted yet. update_Insstart_orig = FALSE; Insstart_textlen = (colnr_T)linetabsize(ml_get_curline()); *************** *** 2975,2981 **** vr_lines_changed = 1; } ResetRedobuff(); ! AppendToRedobuff((char_u *)"1i"); /* pretend we start an insertion */ new_insert_skip = 2; } else if (ins_need_undo) --- 2975,2981 ---- vr_lines_changed = 1; } ResetRedobuff(); ! AppendToRedobuff((char_u *)"1i"); // pretend we start an insertion new_insert_skip = 2; } else if (ins_need_undo) *************** *** 2985,2991 **** } #ifdef FEAT_FOLDING ! /* Always open fold at the cursor line when inserting something. */ foldOpenCursor(); #endif --- 2985,2991 ---- } #ifdef FEAT_FOLDING ! // Always open fold at the cursor line when inserting something. foldOpenCursor(); #endif *************** *** 3000,3013 **** static void stop_insert( pos_T *end_insert_pos, ! int esc, /* called by ins_esc() */ ! int nomove) /* , don't move cursor */ { int cc; char_u *ptr; stop_redo_ins(); ! replace_flush(); /* abandon replace stack */ /* * Save the inserted text for later redo with ^@ and CTRL-A. --- 3000,3013 ---- static void stop_insert( pos_T *end_insert_pos, ! int esc, // called by ins_esc() ! int nomove) // , don't move cursor { int cc; char_u *ptr; stop_redo_ins(); ! replace_flush(); // abandon replace stack /* * Save the inserted text for later redo with ^@ and CTRL-A. *************** *** 3027,3043 **** if (!arrow_used && end_insert_pos != NULL) { ! /* Auto-format now. It may seem strange to do this when stopping an ! * insertion (or moving the cursor), but it's required when appending ! * a line and having it end in a space. But only do it when something ! * was actually inserted, otherwise undo won't work. */ if (!ins_need_undo && has_format_option(FO_AUTO)) { pos_T tpos = curwin->w_cursor; ! /* When the cursor is at the end of the line after a space the ! * formatting will move it to the following word. Avoid that by ! * moving the cursor onto the space. */ cc = 'x'; if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL) { --- 3027,3043 ---- if (!arrow_used && end_insert_pos != NULL) { ! // Auto-format now. It may seem strange to do this when stopping an ! // insertion (or moving the cursor), but it's required when appending ! // a line and having it end in a space. But only do it when something ! // was actually inserted, otherwise undo won't work. if (!ins_need_undo && has_format_option(FO_AUTO)) { pos_T tpos = curwin->w_cursor; ! // When the cursor is at the end of the line after a space the ! // formatting will move it to the following word. Avoid that by ! // moving the cursor onto the space. cc = 'x'; if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL) { *************** *** 3062,3075 **** } } ! /* If a space was inserted for auto-formatting, remove it now. */ check_auto_format(TRUE); ! /* If we just did an auto-indent, remove the white space from the end ! * of the line, and put the cursor back. ! * Do this when ESC was used or moving the cursor up/down. ! * Check for the old position still being valid, just in case the text ! * got changed unexpectedly. */ if (!nomove && did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL && curwin->w_cursor.lnum != end_insert_pos->lnum)) && end_insert_pos->lnum <= curbuf->b_ml.ml_line_count) --- 3062,3075 ---- } } ! // If a space was inserted for auto-formatting, remove it now. check_auto_format(TRUE); ! // If we just did an auto-indent, remove the white space from the end ! // of the line, and put the cursor back. ! // Do this when ESC was used or moving the cursor up/down. ! // Check for the old position still being valid, just in case the text ! // got changed unexpectedly. if (!nomove && did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL && curwin->w_cursor.lnum != end_insert_pos->lnum)) && end_insert_pos->lnum <= curbuf->b_ml.ml_line_count) *************** *** 3077,3083 **** pos_T tpos = curwin->w_cursor; curwin->w_cursor = *end_insert_pos; ! check_cursor_col(); /* make sure it is not past the line */ for (;;) { if (gchar_cursor() == NUL && curwin->w_cursor.col > 0) --- 3077,3083 ---- pos_T tpos = curwin->w_cursor; curwin->w_cursor = *end_insert_pos; ! check_cursor_col(); // make sure it is not past the line for (;;) { if (gchar_cursor() == NUL && curwin->w_cursor.col > 0) *************** *** 3086,3106 **** if (!VIM_ISWHITE(cc)) break; if (del_char(TRUE) == FAIL) ! break; /* should not happen */ } if (curwin->w_cursor.lnum != tpos.lnum) curwin->w_cursor = tpos; else { ! /* reset tpos, could have been invalidated in the loop above */ tpos = curwin->w_cursor; tpos.col++; if (cc != NUL && gchar_pos(&tpos) == NUL) ! ++curwin->w_cursor.col; /* put cursor back on the NUL */ } ! /* may have started Visual mode, adjust the position for ! * deleted characters. */ if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum) { int len = (int)STRLEN(ml_get_curline()); --- 3086,3106 ---- if (!VIM_ISWHITE(cc)) break; if (del_char(TRUE) == FAIL) ! break; // should not happen } if (curwin->w_cursor.lnum != tpos.lnum) curwin->w_cursor = tpos; else { ! // reset tpos, could have been invalidated in the loop above tpos = curwin->w_cursor; tpos.col++; if (cc != NUL && gchar_pos(&tpos) == NUL) ! ++curwin->w_cursor.col; // put cursor back on the NUL } ! // may have started Visual mode, adjust the position for ! // deleted characters. if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum) { int len = (int)STRLEN(ml_get_curline()); *************** *** 3120,3127 **** can_si_back = FALSE; #endif ! /* Set '[ and '] to the inserted text. When end_insert_pos is NULL we are ! * now in a different buffer. */ if (end_insert_pos != NULL) { curbuf->b_op_start = Insstart; --- 3120,3127 ---- can_si_back = FALSE; #endif ! // Set '[ and '] to the inserted text. When end_insert_pos is NULL we are ! // now in a different buffer. if (end_insert_pos != NULL) { curbuf->b_op_start = Insstart; *************** *** 3144,3150 **** if (last_insert != NULL) { s = last_insert; ! /* Use the CTRL-V only when entering a special char */ if (c < ' ' || c == DEL) *s++ = Ctrl_V; s = add_char2buf(c, s); --- 3144,3150 ---- if (last_insert != NULL) { s = last_insert; ! // Use the CTRL-V only when entering a special char if (c < ' ' || c == DEL) *s++ = Ctrl_V; s = add_char2buf(c, s); *************** *** 3178,3184 **** for (i = 0; i < len; ++i) { c = temp[i]; ! /* Need to escape K_SPECIAL and CSI like in the typeahead buffer. */ if (c == K_SPECIAL) { *s++ = K_SPECIAL; --- 3178,3184 ---- for (i = 0; i < len; ++i) { c = temp[i]; ! // Need to escape K_SPECIAL and CSI like in the typeahead buffer. if (c == K_SPECIAL) { *s++ = K_SPECIAL; *************** *** 3246,3273 **** { pos_T prevpos = curwin->w_cursor; ! /* Adjust for multi-wide char (excluding TAB) */ ptr = ml_get_cursor(); coladvance(getviscol() + ((*ptr != TAB && vim_isprintc((*mb_ptr2char)(ptr))) ? ptr2cells(ptr) : 1)); curwin->w_set_curswant = TRUE; ! /* Return OK if the cursor moved, FAIL otherwise (at window edge). */ return (prevpos.col != curwin->w_cursor.col || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL; } ptr = ml_get_cursor(); if (*ptr == NUL) ! return FAIL; /* already at the very end */ if (has_mbyte) l = (*mb_ptr2len)(ptr); else l = 1; ! /* move "l" bytes right, but don't end up on the NUL, unless 'virtualedit' ! * contains "onemore". */ if (ptr[l] == NUL && (ve_flags & VE_ONEMORE) == 0) return FAIL; curwin->w_cursor.col += l; --- 3246,3273 ---- { pos_T prevpos = curwin->w_cursor; ! // Adjust for multi-wide char (excluding TAB) ptr = ml_get_cursor(); coladvance(getviscol() + ((*ptr != TAB && vim_isprintc((*mb_ptr2char)(ptr))) ? ptr2cells(ptr) : 1)); curwin->w_set_curswant = TRUE; ! // Return OK if the cursor moved, FAIL otherwise (at window edge). return (prevpos.col != curwin->w_cursor.col || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL; } ptr = ml_get_cursor(); if (*ptr == NUL) ! return FAIL; // already at the very end if (has_mbyte) l = (*mb_ptr2len)(ptr); else l = 1; ! // move "l" bytes right, but don't end up on the NUL, unless 'virtualedit' ! // contains "onemore". if (ptr[l] == NUL && (ve_flags & VE_ONEMORE) == 0) return FAIL; curwin->w_cursor.col += l; *************** *** 3290,3303 **** return FAIL; #ifdef FEAT_LINEBREAK ! /* We might get stuck on 'showbreak', skip over it. */ width = 1; for (;;) { coladvance(v - width); ! /* getviscol() is slow, skip it when 'showbreak' is empty, ! * 'breakindent' is not set and there are no multi-byte ! * characters */ if ((*get_showbreak_value(curwin) == NUL && !curwin->w_p_bri && !has_mbyte) || getviscol() < v) break; --- 3290,3303 ---- return FAIL; #ifdef FEAT_LINEBREAK ! // We might get stuck on 'showbreak', skip over it. width = 1; for (;;) { coladvance(v - width); ! // getviscol() is slow, skip it when 'showbreak' is empty, ! // 'breakindent' is not set and there are no multi-byte ! // characters if ((*get_showbreak_value(curwin) == NUL && !curwin->w_p_bri && !has_mbyte) || getviscol() < v) break; *************** *** 3311,3317 **** { char_u *ptr; ! /* Adjust for multi-wide char (not a TAB) */ ptr = ml_get_cursor(); if (*ptr != TAB && vim_isprintc((*mb_ptr2char)(ptr)) && ptr2cells(ptr) > 1) --- 3311,3317 ---- { char_u *ptr; ! // Adjust for multi-wide char (not a TAB) ptr = ml_get_cursor(); if (*ptr != TAB && vim_isprintc((*mb_ptr2char)(ptr)) && ptr2cells(ptr) > 1) *************** *** 3328,3335 **** curwin->w_set_curswant = TRUE; --curwin->w_cursor.col; ! /* if the character on the left of the current cursor is a multi-byte ! * character, move to its first byte */ if (has_mbyte) mb_adjust_cursor(); return OK; --- 3328,3335 ---- curwin->w_set_curswant = TRUE; --curwin->w_cursor.col; ! // if the character on the left of the current cursor is a multi-byte ! // character, move to its first byte if (has_mbyte) mb_adjust_cursor(); return OK; *************** *** 3338,3352 **** int cursor_up( long n, ! int upd_topline) /* When TRUE: update topline */ { linenr_T lnum; if (n > 0) { lnum = curwin->w_cursor.lnum; ! /* This fails if the cursor is already in the first line or the count ! * is larger than the line number and '-' is in 'cpoptions' */ if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL)) return FAIL; if (n >= lnum) --- 3338,3352 ---- int cursor_up( long n, ! int upd_topline) // When TRUE: update topline { linenr_T lnum; if (n > 0) { lnum = curwin->w_cursor.lnum; ! // This fails if the cursor is already in the first line or the count ! // is larger than the line number and '-' is in 'cpoptions' if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL)) return FAIL; if (n >= lnum) *************** *** 3358,3375 **** /* * Count each sequence of folded lines as one logical line. */ ! /* go to the start of the current fold */ (void)hasFolding(lnum, &lnum, NULL); while (n--) { ! /* move up one line */ --lnum; if (lnum <= 1) break; ! /* If we entered a fold, move to the beginning, unless in ! * Insert mode or when 'foldopen' contains "all": it will open ! * in a moment. */ if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL))) (void)hasFolding(lnum, &lnum, NULL); } --- 3358,3375 ---- /* * Count each sequence of folded lines as one logical line. */ ! // go to the start of the current fold (void)hasFolding(lnum, &lnum, NULL); while (n--) { ! // move up one line --lnum; if (lnum <= 1) break; ! // If we entered a fold, move to the beginning, unless in ! // Insert mode or when 'foldopen' contains "all": it will open ! // in a moment. if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL))) (void)hasFolding(lnum, &lnum, NULL); } *************** *** 3382,3392 **** curwin->w_cursor.lnum = lnum; } ! /* try to advance to the column we want to be at */ coladvance(curwin->w_curswant); if (upd_topline) ! update_topline(); /* make sure curwin->w_topline is valid */ return OK; } --- 3382,3392 ---- curwin->w_cursor.lnum = lnum; } ! // try to advance to the column we want to be at coladvance(curwin->w_curswant); if (upd_topline) ! update_topline(); // make sure curwin->w_topline is valid return OK; } *************** *** 3397,3403 **** int cursor_down( long n, ! int upd_topline) /* When TRUE: update topline */ { linenr_T lnum; --- 3397,3403 ---- int cursor_down( long n, ! int upd_topline) // When TRUE: update topline { linenr_T lnum; *************** *** 3405,3415 **** { lnum = curwin->w_cursor.lnum; #ifdef FEAT_FOLDING ! /* Move to last line of fold, will fail if it's the end-of-file. */ (void)hasFolding(lnum, NULL, &lnum); #endif ! /* This fails if the cursor is already in the last line or would move ! * beyond the last line and '-' is in 'cpoptions' */ if (lnum >= curbuf->b_ml.ml_line_count || (lnum + n > curbuf->b_ml.ml_line_count && vim_strchr(p_cpo, CPO_MINUS) != NULL)) --- 3405,3415 ---- { lnum = curwin->w_cursor.lnum; #ifdef FEAT_FOLDING ! // Move to last line of fold, will fail if it's the end-of-file. (void)hasFolding(lnum, NULL, &lnum); #endif ! // This fails if the cursor is already in the last line or would move ! // beyond the last line and '-' is in 'cpoptions' if (lnum >= curbuf->b_ml.ml_line_count || (lnum + n > curbuf->b_ml.ml_line_count && vim_strchr(p_cpo, CPO_MINUS) != NULL)) *************** *** 3422,3428 **** { linenr_T last; ! /* count each sequence of folded lines as one logical line */ while (n--) { if (hasFolding(lnum, NULL, &last)) --- 3422,3428 ---- { linenr_T last; ! // count each sequence of folded lines as one logical line while (n--) { if (hasFolding(lnum, NULL, &last)) *************** *** 3441,3451 **** curwin->w_cursor.lnum = lnum; } ! /* try to advance to the column we want to be at */ coladvance(curwin->w_curswant); if (upd_topline) ! update_topline(); /* make sure curwin->w_topline is valid */ return OK; } --- 3441,3451 ---- curwin->w_cursor.lnum = lnum; } ! // try to advance to the column we want to be at coladvance(curwin->w_curswant); if (upd_topline) ! update_topline(); // make sure curwin->w_topline is valid return OK; } *************** *** 3457,3465 **** */ int stuff_inserted( ! int c, /* Command character to be inserted */ ! long count, /* Repeat this many times */ ! int no_esc) /* Don't add an ESC at the end */ { char_u *esc_ptr; char_u *ptr; --- 3457,3465 ---- */ int stuff_inserted( ! int c, // Command character to be inserted ! long count, // Repeat this many times ! int no_esc) // Don't add an ESC at the end { char_u *esc_ptr; char_u *ptr; *************** *** 3473,3488 **** return FAIL; } ! /* may want to stuff the command character, to start Insert mode */ if (c != NUL) stuffcharReadbuff(c); if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL) ! *esc_ptr = NUL; /* remove the ESC */ ! /* when the last char is either "0" or "^" it will be quoted if no ESC ! * comes after it OR if it will inserted more than once and "ptr" ! * starts with ^D. -- Acevedo ! */ last_ptr = (esc_ptr ? esc_ptr : ptr + STRLEN(ptr)) - 1; if (last_ptr >= ptr && (*last_ptr == '0' || *last_ptr == '^') && (no_esc || (*ptr == Ctrl_D && count > 1))) --- 3473,3487 ---- return FAIL; } ! // may want to stuff the command character, to start Insert mode if (c != NUL) stuffcharReadbuff(c); if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL) ! *esc_ptr = NUL; // remove the ESC ! // when the last char is either "0" or "^" it will be quoted if no ESC ! // comes after it OR if it will inserted more than once and "ptr" ! // starts with ^D. -- Acevedo last_ptr = (esc_ptr ? esc_ptr : ptr + STRLEN(ptr)) - 1; if (last_ptr >= ptr && (*last_ptr == '0' || *last_ptr == '^') && (no_esc || (*ptr == Ctrl_D && count > 1))) *************** *** 3494,3500 **** do { stuffReadbuff(ptr); ! /* a trailing "0" is inserted as "048", "^" as "^" */ if (last) stuffReadbuff((char_u *)(last == '0' ? IF_EB("\026\060\064\070", CTRL_V_STR "xf0") --- 3493,3499 ---- do { stuffReadbuff(ptr); ! // a trailing "0" is inserted as "048", "^" as "^" if (last) stuffReadbuff((char_u *)(last == '0' ? IF_EB("\026\060\064\070", CTRL_V_STR "xf0") *************** *** 3506,3514 **** *last_ptr = last; if (esc_ptr != NULL) ! *esc_ptr = ESC; /* put the ESC back */ ! /* may want to stuff a trailing ESC, to get out of Insert mode */ if (!no_esc) stuffcharReadbuff(ESC); --- 3505,3513 ---- *last_ptr = last; if (esc_ptr != NULL) ! *esc_ptr = ESC; // put the ESC back ! // may want to stuff a trailing ESC, to get out of Insert mode if (!no_esc) stuffcharReadbuff(ESC); *************** *** 3539,3545 **** if (s != NULL) { len = (int)STRLEN(s); ! if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */ s[len - 1] = NUL; } return s; --- 3538,3544 ---- if (s != NULL) { len = (int)STRLEN(s); ! if (len > 0 && s[len - 1] == ESC) // remove trailing ESC s[len - 1] = NUL; } return s; *************** *** 3554,3561 **** static int echeck_abbr(int c) { ! /* Don't check for abbreviation in paste mode, when disabled and just ! * after moving around with cursor keys. */ if (p_paste || no_abbr || arrow_used) return FALSE; --- 3553,3560 ---- static int echeck_abbr(int c) { ! // Don't check for abbreviation in paste mode, when disabled and just ! // after moving around with cursor keys. if (p_paste || no_abbr || arrow_used) return FALSE; *************** *** 3583,3604 **** */ static char_u *replace_stack = NULL; ! static long replace_stack_nr = 0; /* next entry in replace stack */ ! static long replace_stack_len = 0; /* max. number of entries */ void replace_push( ! int c) /* character that is replaced (NUL is none) */ { char_u *p; ! if (replace_stack_nr < replace_offset) /* nothing to do */ return; if (replace_stack_len <= replace_stack_nr) { replace_stack_len += 50; p = ALLOC_MULT(char_u, replace_stack_len); ! if (p == NULL) /* out of memory */ { replace_stack_len -= 50; return; --- 3582,3603 ---- */ static char_u *replace_stack = NULL; ! static long replace_stack_nr = 0; // next entry in replace stack ! static long replace_stack_len = 0; // max. number of entries void replace_push( ! int c) // character that is replaced (NUL is none) { char_u *p; ! if (replace_stack_nr < replace_offset) // nothing to do return; if (replace_stack_len <= replace_stack_nr) { replace_stack_len += 50; p = ALLOC_MULT(char_u, replace_stack_len); ! if (p == NULL) // out of memory { replace_stack_len -= 50; return; *************** *** 3653,3659 **** */ void replace_join( ! int off) /* offset for which NUL to remove */ { int i; --- 3652,3658 ---- */ void replace_join( ! int off) // offset for which NUL to remove { int i; *************** *** 3677,3683 **** int cc; int oldState = State; ! State = NORMAL; /* don't want REPLACE here */ while ((cc = replace_pop()) > 0) { mb_replace_pop_ins(cc); --- 3676,3682 ---- int cc; int oldState = State; ! State = NORMAL; // don't want REPLACE here while ((cc = replace_pop()) > 0) { mb_replace_pop_ins(cc); *************** *** 3709,3723 **** ins_char(cc); if (enc_utf8) ! /* Handle composing chars. */ for (;;) { c = replace_pop(); ! if (c == -1) /* stack empty */ break; if ((n = MB_BYTE2LEN(c)) == 1) { ! /* Not a multi-byte char, put it back. */ replace_push(c); break; } --- 3708,3722 ---- ins_char(cc); if (enc_utf8) ! // Handle composing chars. for (;;) { c = replace_pop(); ! if (c == -1) // stack empty break; if ((n = MB_BYTE2LEN(c)) == 1) { ! // Not a multi-byte char, put it back. replace_push(c); break; } *************** *** 3730,3736 **** ins_bytes_len(buf, n); else { ! /* Not a composing char, put it back. */ for (i = n - 1; i >= 0; --i) replace_push(buf[i]); break; --- 3729,3735 ---- ins_bytes_len(buf, n); else { ! // Not a composing char, put it back. for (i = n - 1; i >= 0; --i) replace_push(buf[i]); break; *************** *** 3788,3795 **** #endif if (State & VREPLACE_FLAG) { ! /* Get the number of screen cells used by the character we are ! * going to delete. */ getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL); orig_vcols = chartabsize(ml_get_cursor(), start_vcol); } --- 3787,3794 ---- #endif if (State & VREPLACE_FLAG) { ! // Get the number of screen cells used by the character we are ! // going to delete. getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL); orig_vcols = chartabsize(ml_get_cursor(), start_vcol); } *************** *** 3810,3816 **** if (State & VREPLACE_FLAG) { ! /* Get the number of screen cells used by the inserted characters */ p = ml_get_cursor(); ins_len = (int)STRLEN(p) - orig_len; vcol = start_vcol; --- 3809,3815 ---- if (State & VREPLACE_FLAG) { ! // Get the number of screen cells used by the inserted characters p = ml_get_cursor(); ins_len = (int)STRLEN(p) - orig_len; vcol = start_vcol; *************** *** 3821,3828 **** } vcol -= start_vcol; ! /* Delete spaces that were inserted after the cursor to keep the ! * text aligned. */ curwin->w_cursor.col += ins_len; while (vcol > orig_vcols && gchar_cursor() == ' ') { --- 3820,3827 ---- } vcol -= start_vcol; ! // Delete spaces that were inserted after the cursor to keep the ! // text aligned. curwin->w_cursor.col += ins_len; while (vcol > orig_vcols && gchar_cursor() == ' ') { *************** *** 3857,3863 **** int hkmap(int c) { ! if (p_hkmapp) /* phonetic mapping, by Ilya Dogolazky */ { enum {hALEF=0, BET, GIMEL, DALET, HEI, VAV, ZAIN, HET, TET, IUD, KAFsofit, hKAF, LAMED, MEMsofit, MEM, NUNsofit, NUN, SAMEH, AIN, --- 3856,3862 ---- int hkmap(int c) { ! if (p_hkmapp) // phonetic mapping, by Ilya Dogolazky { enum {hALEF=0, BET, GIMEL, DALET, HEI, VAV, ZAIN, HET, TET, IUD, KAFsofit, hKAF, LAMED, MEMsofit, MEM, NUNsofit, NUN, SAMEH, AIN, *************** *** 3875,3899 **** if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z') return (int)(map[CharOrd(c)] - 1 + p_aleph); ! /* '-1'='sofit' */ else if (c == 'x') return 'X'; else if (c == 'q') ! return '\''; /* {geresh}={'} */ else if (c == 246) ! return ' '; /* \"o --> ' ' for a german keyboard */ else if (c == 228) ! return ' '; /* \"a --> ' ' -- / -- */ else if (c == 252) ! return ' '; /* \"u --> ' ' -- / -- */ #ifdef EBCDIC else if (islower(c)) #else ! /* NOTE: islower() does not do the right thing for us on Linux so we ! * do this the same was as 5.7 and previous, so it works correctly on ! * all systems. Specifically, the e.g. Delete and Arrow keys are ! * munged and won't work if e.g. searching for Hebrew text. ! */ else if (c >= 'a' && c <= 'z') #endif return (int)(map[CharOrdLow(c)] + p_aleph); --- 3874,3897 ---- if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z') return (int)(map[CharOrd(c)] - 1 + p_aleph); ! // '-1'='sofit' else if (c == 'x') return 'X'; else if (c == 'q') ! return '\''; // {geresh}={'} else if (c == 246) ! return ' '; // \"o --> ' ' for a german keyboard else if (c == 228) ! return ' '; // \"a --> ' ' -- / -- else if (c == 252) ! return ' '; // \"u --> ' ' -- / -- #ifdef EBCDIC else if (islower(c)) #else ! // NOTE: islower() does not do the right thing for us on Linux so we ! // do this the same was as 5.7 and previous, so it works correctly on ! // all systems. Specifically, the e.g. Delete and Arrow keys are ! // munged and won't work if e.g. searching for Hebrew text. else if (c >= 'a' && c <= 'z') #endif return (int)(map[CharOrdLow(c)] + p_aleph); *************** *** 3910,3916 **** case 'q': return '/'; case 'w': return '\''; ! /* Hebrew letters - set offset from 'a' */ case ',': c = '{'; break; case '.': c = 'v'; break; case ';': c = 't'; break; --- 3908,3914 ---- case 'q': return '/'; case 'w': return '\''; ! // Hebrew letters - set offset from 'a' case ',': c = '{'; break; case '.': c = 'v'; break; case ';': c = 't'; break; *************** *** 3918,3924 **** static char str[] = "zqbcxlsjphmkwonu ydafe rig"; #ifdef EBCDIC ! /* see note about islower() above */ if (!islower(c)) #else if (c < 'a' || c > 'z') --- 3916,3922 ---- static char str[] = "zqbcxlsjphmkwonu ydafe rig"; #ifdef EBCDIC ! // see note about islower() above if (!islower(c)) #else if (c < 'a' || c > 'z') *************** *** 3948,3954 **** pc_status = PC_STATUS_UNSET; if (redrawing() && !char_avail()) { ! /* may need to redraw when no more chars available now */ ins_redraw(FALSE); edit_putchar('"', TRUE); --- 3946,3952 ---- pc_status = PC_STATUS_UNSET; if (redrawing() && !char_avail()) { ! // may need to redraw when no more chars available now ins_redraw(FALSE); edit_putchar('"', TRUE); *************** *** 3958,3964 **** } #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; /* disallow scrolling here */ #endif /* --- 3956,3962 ---- } #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; // disallow scrolling here #endif /* *************** *** 3971,3977 **** LANGMAP_ADJUST(regname, TRUE); if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P) { ! /* Get a third key for literal register insertion */ literally = regname; #ifdef FEAT_CMDL_INFO add_to_showcmd_c(literally); --- 3969,3975 ---- LANGMAP_ADJUST(regname, TRUE); if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P) { ! // Get a third key for literal register insertion literally = regname; #ifdef FEAT_CMDL_INFO add_to_showcmd_c(literally); *************** *** 3983,3990 **** --allow_keys; #ifdef FEAT_EVAL ! /* Don't call u_sync() while typing the expression or giving an error ! * message for it. Only call it explicitly. */ ++no_u_sync; if (regname == '=') { --- 3981,3988 ---- --allow_keys; #ifdef FEAT_EVAL ! // Don't call u_sync() while typing the expression or giving an error ! // message for it. Only call it explicitly. ++no_u_sync; if (regname == '=') { *************** *** 3992,3999 **** # ifdef HAVE_INPUT_METHOD int im_on = im_get_status(); # endif ! /* Sync undo when evaluating the expression calls setline() or ! * append(), so that it can be undone separately. */ u_sync_once = 2; regname = get_expr_register(); --- 3990,3997 ---- # ifdef HAVE_INPUT_METHOD int im_on = im_get_status(); # endif ! // Sync undo when evaluating the expression calls setline() or ! // append(), so that it can be undone separately. u_sync_once = 2; regname = get_expr_register(); *************** *** 4010,4023 **** if (regname == NUL || !valid_yank_reg(regname, FALSE)) { vim_beep(BO_REG); ! need_redraw = TRUE; /* remove the '"' */ } else { #endif if (literally == Ctrl_O || literally == Ctrl_P) { ! /* Append the command to the redo buffer. */ AppendCharToRedobuff(Ctrl_R); AppendCharToRedobuff(literally); AppendCharToRedobuff(regname); --- 4008,4021 ---- if (regname == NUL || !valid_yank_reg(regname, FALSE)) { vim_beep(BO_REG); ! need_redraw = TRUE; // remove the '"' } else { #endif if (literally == Ctrl_O || literally == Ctrl_P) { ! // Append the command to the redo buffer. AppendCharToRedobuff(Ctrl_R); AppendCharToRedobuff(literally); AppendCharToRedobuff(regname); *************** *** 4028,4039 **** else if (insert_reg(regname, literally) == FAIL) { vim_beep(BO_REG); ! need_redraw = TRUE; /* remove the '"' */ } else if (stop_insert_mode) ! /* When the '=' register was used and a function was invoked that ! * did ":stopinsert" then stuff_empty() returns FALSE but we won't ! * insert anything, need to remove the '"' */ need_redraw = TRUE; #ifdef FEAT_EVAL --- 4026,4037 ---- else if (insert_reg(regname, literally) == FAIL) { vim_beep(BO_REG); ! need_redraw = TRUE; // remove the '"' } else if (stop_insert_mode) ! // When the '=' register was used and a function was invoked that ! // did ":stopinsert" then stuff_empty() returns FALSE but we won't ! // insert anything, need to remove the '"' need_redraw = TRUE; #ifdef FEAT_EVAL *************** *** 4047,4057 **** clear_showcmd(); #endif ! /* If the inserted register is empty, we need to remove the '"' */ if (need_redraw || stuff_empty()) edit_unputchar(); ! /* Disallow starting Visual mode here, would get a weird mode. */ if (!vis_active && VIsual_active) end_visual_mode(); } --- 4045,4055 ---- clear_showcmd(); #endif ! // If the inserted register is empty, we need to remove the '"' if (need_redraw || stuff_empty()) edit_unputchar(); ! // Disallow starting Visual mode here, would get a weird mode. if (!vis_active && VIsual_active) end_visual_mode(); } *************** *** 4078,4113 **** --allow_keys; switch (c) { ! /* CTRL-G k and CTRL-G : cursor up to Insstart.col */ case K_UP: case Ctrl_K: case 'k': ins_up(TRUE); break; ! /* CTRL-G j and CTRL-G : cursor down to Insstart.col */ case K_DOWN: case Ctrl_J: case 'j': ins_down(TRUE); break; ! /* CTRL-G u: start new undoable edit */ case 'u': u_sync(TRUE); ins_need_undo = TRUE; ! /* Need to reset Insstart, esp. because a BS that joins ! * a line to the previous one must save for undo. */ update_Insstart_orig = FALSE; Insstart = curwin->w_cursor; break; ! /* CTRL-G U: do not break undo with the next char */ case 'U': ! /* Allow one left/right cursor movement with the next char, ! * without breaking undo. */ dont_sync_undo = MAYBE; break; ! /* Unknown CTRL-G command, reserved for future expansion. */ default: vim_beep(BO_CTRLG); } } --- 4076,4111 ---- --allow_keys; switch (c) { ! // CTRL-G k and CTRL-G : cursor up to Insstart.col case K_UP: case Ctrl_K: case 'k': ins_up(TRUE); break; ! // CTRL-G j and CTRL-G : cursor down to Insstart.col case K_DOWN: case Ctrl_J: case 'j': ins_down(TRUE); break; ! // CTRL-G u: start new undoable edit case 'u': u_sync(TRUE); ins_need_undo = TRUE; ! // Need to reset Insstart, esp. because a BS that joins ! // a line to the previous one must save for undo. update_Insstart_orig = FALSE; Insstart = curwin->w_cursor; break; ! // CTRL-G U: do not break undo with the next char case 'U': ! // Allow one left/right cursor movement with the next char, ! // without breaking undo. dont_sync_undo = MAYBE; break; ! // Unknown CTRL-G command, reserved for future expansion. default: vim_beep(BO_CTRLG); } } *************** *** 4120,4126 **** { if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) { ! /* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */ if (State & LANGMAP) { curbuf->b_p_iminsert = B_IMODE_NONE; --- 4118,4124 ---- { if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) { ! // ":lmap" mappings exists, Toggle use of ":lmap" mappings. if (State & LANGMAP) { curbuf->b_p_iminsert = B_IMODE_NONE; *************** *** 4138,4144 **** #ifdef HAVE_INPUT_METHOD else { ! /* There are no ":lmap" mappings, toggle IM */ if (im_get_status()) { curbuf->b_p_iminsert = B_IMODE_NONE; --- 4136,4142 ---- #ifdef HAVE_INPUT_METHOD else { ! // There are no ":lmap" mappings, toggle IM if (im_get_status()) { curbuf->b_p_iminsert = B_IMODE_NONE; *************** *** 4155,4166 **** set_iminsert_global(); showmode(); #ifdef FEAT_GUI ! /* may show different cursor shape or color */ if (gui.in_use) gui_update_cursor(TRUE, FALSE); #endif #if defined(FEAT_KEYMAP) ! /* Show/unshow value of 'keymap' in status lines. */ status_redraw_curbuf(); #endif } --- 4153,4164 ---- set_iminsert_global(); showmode(); #ifdef FEAT_GUI ! // may show different cursor shape or color if (gui.in_use) gui_update_cursor(TRUE, FALSE); #endif #if defined(FEAT_KEYMAP) ! // Show/unshow value of 'keymap' in status lines. status_redraw_curbuf(); #endif } *************** *** 4174,4180 **** ins_esc( long *count, int cmdchar, ! int nomove) /* don't move cursor */ { int temp; static int disabled_redraw = FALSE; --- 4172,4178 ---- ins_esc( long *count, int cmdchar, ! int nomove) // don't move cursor { int temp; static int disabled_redraw = FALSE; *************** *** 4210,4238 **** *count = 0; } ! if (--*count > 0) /* repeat what was typed */ { ! /* Vi repeats the insert without replacing characters. */ if (vim_strchr(p_cpo, CPO_REPLCNT) != NULL) State &= ~REPLACE_FLAG; (void)start_redo_ins(); if (cmdchar == 'r' || cmdchar == 'v') ! stuffRedoReadbuff(ESC_STR); /* no ESC in redo buffer */ ++RedrawingDisabled; disabled_redraw = TRUE; ! return FALSE; /* repeat the insert */ } stop_insert(&curwin->w_cursor, TRUE, nomove); undisplay_dollar(); } ! /* When an autoindent was removed, curswant stays after the ! * indent */ if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col) curwin->w_set_curswant = TRUE; ! /* Remember the last Insert position in the '^ mark. */ if (!cmdmod.keepjumps) curbuf->b_last_insert = curwin->w_cursor; --- 4208,4236 ---- *count = 0; } ! if (--*count > 0) // repeat what was typed { ! // Vi repeats the insert without replacing characters. if (vim_strchr(p_cpo, CPO_REPLCNT) != NULL) State &= ~REPLACE_FLAG; (void)start_redo_ins(); if (cmdchar == 'r' || cmdchar == 'v') ! stuffRedoReadbuff(ESC_STR); // no ESC in redo buffer ++RedrawingDisabled; disabled_redraw = TRUE; ! return FALSE; // repeat the insert } stop_insert(&curwin->w_cursor, TRUE, nomove); undisplay_dollar(); } ! // When an autoindent was removed, curswant stays after the ! // indent if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col) curwin->w_set_curswant = TRUE; ! // Remember the last Insert position in the '^ mark. if (!cmdmod.keepjumps) curbuf->b_last_insert = curwin->w_cursor; *************** *** 4259,4281 **** else { --curwin->w_cursor.col; ! /* Correct cursor for multi-byte character. */ if (has_mbyte) mb_adjust_cursor(); } } #ifdef HAVE_INPUT_METHOD ! /* Disable IM to allow typing English directly for Normal mode commands. ! * When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as ! * well). */ if (!(State & LANGMAP)) im_save_status(&curbuf->b_p_iminsert); im_set_active(FALSE); #endif State = NORMAL; ! /* need to position cursor again (e.g. when on a TAB ) */ changed_cline_bef_curs(); setmouse(); --- 4257,4279 ---- else { --curwin->w_cursor.col; ! // Correct cursor for multi-byte character. if (has_mbyte) mb_adjust_cursor(); } } #ifdef HAVE_INPUT_METHOD ! // Disable IM to allow typing English directly for Normal mode commands. ! // When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as ! // well). if (!(State & LANGMAP)) im_save_status(&curbuf->b_p_iminsert); im_set_active(FALSE); #endif State = NORMAL; ! // need to position cursor again (e.g. when on a TAB ) changed_cline_bef_curs(); setmouse(); *************** *** 4356,4373 **** # endif if (!(mod_mask & MOD_MASK_SHIFT)) break; ! /* FALLTHROUGH */ case K_S_LEFT: case K_S_RIGHT: case K_S_UP: case K_S_DOWN: case K_S_END: case K_S_HOME: ! /* Start selection right away, the cursor can move with ! * CTRL-O when beyond the end of the line. */ start_selection(); ! /* Execute the key in (insert) Select mode. */ stuffcharReadbuff(Ctrl_O); if (mod_mask) { --- 4354,4371 ---- # endif if (!(mod_mask & MOD_MASK_SHIFT)) break; ! // FALLTHROUGH case K_S_LEFT: case K_S_RIGHT: case K_S_UP: case K_S_DOWN: case K_S_END: case K_S_HOME: ! // Start selection right away, the cursor can move with ! // CTRL-O when beyond the end of the line. start_selection(); ! // Execute the key in (insert) Select mode. stuffcharReadbuff(Ctrl_O); if (mod_mask) { *************** *** 4405,4411 **** AppendCharToRedobuff(K_INS); showmode(); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may show different cursor shape */ #endif } --- 4403,4409 ---- AppendCharToRedobuff(K_INS); showmode(); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may show different cursor shape #endif } *************** *** 4423,4429 **** else restart_edit = 'I'; if (virtual_active()) ! ins_at_eol = FALSE; /* cursor always keeps its column */ else ins_at_eol = (gchar_cursor() == NUL); } --- 4421,4427 ---- else restart_edit = 'I'; if (virtual_active()) ! ins_at_eol = FALSE; // cursor always keeps its column else ins_at_eol = (gchar_cursor() == NUL); } *************** *** 4449,4460 **** && curwin->w_cursor.col > 0) { --curwin->w_cursor.col; ! (void)del_char(FALSE); /* delete the '^' or '0' */ ! /* In Replace mode, restore the characters that '^' or '0' replaced. */ if (State & REPLACE_FLAG) replace_pop_ins(); if (lastc == '^') ! old_indent = get_indent(); /* remember curr. indent */ change_indent(INDENT_SET, 0, TRUE, 0, TRUE); } else --- 4447,4458 ---- && curwin->w_cursor.col > 0) { --curwin->w_cursor.col; ! (void)del_char(FALSE); // delete the '^' or '0' ! // In Replace mode, restore the characters that '^' or '0' replaced. if (State & REPLACE_FLAG) replace_pop_ins(); if (lastc == '^') ! old_indent = get_indent(); // remember curr. indent change_indent(INDENT_SET, 0, TRUE, 0, TRUE); } else *************** *** 4468,4474 **** can_si_back = FALSE; #endif #ifdef FEAT_CINDENT ! can_cindent = FALSE; /* no cindenting after ^D or ^T */ #endif } --- 4466,4472 ---- can_si_back = FALSE; #endif #ifdef FEAT_CINDENT ! can_cindent = FALSE; // no cindenting after ^D or ^T #endif } *************** *** 4479,4502 **** if (stop_arrow() == FAIL) return; ! if (gchar_cursor() == NUL) /* delete newline */ { temp = curwin->w_cursor.col; ! if (!can_bs(BS_EOL) /* only if "eol" included */ || do_join(2, FALSE, TRUE, FALSE, FALSE) == FAIL) vim_beep(BO_BS); else { curwin->w_cursor.col = temp; ! /* Adjust orig_line_count in case more lines have been deleted than ! * have been added. That makes sure, that open_line() later ! * can access all buffer lines correctly */ if (State & VREPLACE_FLAG && orig_line_count > curbuf->b_ml.ml_line_count) orig_line_count = curbuf->b_ml.ml_line_count; } } ! else if (del_char(FALSE) == FAIL) /* delete char under cursor */ vim_beep(BO_BS); did_ai = FALSE; #ifdef FEAT_SMARTINDENT --- 4477,4500 ---- if (stop_arrow() == FAIL) return; ! if (gchar_cursor() == NUL) // delete newline { temp = curwin->w_cursor.col; ! if (!can_bs(BS_EOL) // only if "eol" included || do_join(2, FALSE, TRUE, FALSE, FALSE) == FAIL) vim_beep(BO_BS); else { curwin->w_cursor.col = temp; ! // Adjust orig_line_count in case more lines have been deleted than ! // have been added. That makes sure, that open_line() later ! // can access all buffer lines correctly if (State & VREPLACE_FLAG && orig_line_count > curbuf->b_ml.ml_line_count) orig_line_count = curbuf->b_ml.ml_line_count; } } ! else if (del_char(FALSE) == FAIL) // delete char under cursor vim_beep(BO_BS); did_ai = FALSE; #ifdef FEAT_SMARTINDENT *************** *** 4517,4524 **** getvcol(curwin, &curwin->w_cursor, vcolp, NULL, NULL); if (State & REPLACE_FLAG) { ! /* Don't delete characters before the insert point when in ! * Replace mode */ if (curwin->w_cursor.lnum != Insstart.lnum || curwin->w_cursor.col >= Insstart.col) replace_do_bs(-1); --- 4515,4522 ---- getvcol(curwin, &curwin->w_cursor, vcolp, NULL, NULL); if (State & REPLACE_FLAG) { ! // Don't delete characters before the insert point when in ! // Replace mode if (curwin->w_cursor.lnum != Insstart.lnum || curwin->w_cursor.col >= Insstart.col) replace_do_bs(-1); *************** *** 4539,4551 **** { linenr_T lnum; int cc; ! int temp = 0; /* init for GCC */ colnr_T save_col; colnr_T mincol; int did_backspace = FALSE; int in_indent; int oldState; ! int cpc[MAX_MCO]; /* composing characters */ /* * can't delete anything in an empty file --- 4537,4549 ---- { linenr_T lnum; int cc; ! int temp = 0; // init for GCC colnr_T save_col; colnr_T mincol; int did_backspace = FALSE; int in_indent; int oldState; ! int cpc[MAX_MCO]; // composing characters /* * can't delete anything in an empty file *************** *** 4578,4594 **** if (in_indent) can_cindent = FALSE; #endif ! end_comment_pending = NUL; /* After BS, don't auto-end comment */ #ifdef FEAT_RIGHTLEFT ! if (revins_on) /* put cursor after last inserted char */ inc_cursor(); #endif ! /* Virtualedit: ! * BACKSPACE_CHAR eats a virtual space ! * BACKSPACE_WORD eats all coladd ! * BACKSPACE_LINE eats all coladd and keeps going ! */ if (curwin->w_cursor.coladd > 0) { if (mode == BACKSPACE_CHAR) --- 4576,4591 ---- if (in_indent) can_cindent = FALSE; #endif ! end_comment_pending = NUL; // After BS, don't auto-end comment #ifdef FEAT_RIGHTLEFT ! if (revins_on) // put cursor after last inserted char inc_cursor(); #endif ! // Virtualedit: ! // BACKSPACE_CHAR eats a virtual space ! // BACKSPACE_WORD eats all coladd ! // BACKSPACE_LINE eats all coladd and keeps going if (curwin->w_cursor.coladd > 0) { if (mode == BACKSPACE_CHAR) *************** *** 4629,4635 **** */ cc = -1; if (State & REPLACE_FLAG) ! cc = replace_pop(); /* returns -1 if NL was inserted */ /* * In replace mode, in the line we started replacing, we only move the * cursor. --- 4626,4632 ---- */ cc = -1; if (State & REPLACE_FLAG) ! cc = replace_pop(); // returns -1 if NL was inserted /* * In replace mode, in the line we started replacing, we only move the * cursor. *************** *** 4643,4654 **** if (!(State & VREPLACE_FLAG) || curwin->w_cursor.lnum > orig_line_count) { ! temp = gchar_cursor(); /* remember current char */ --curwin->w_cursor.lnum; ! /* When "aw" is in 'formatoptions' we must delete the space at ! * the end of the line, otherwise the line will be broken ! * again when auto-formatting. */ if (has_format_option(FO_AUTO) && has_format_option(FO_WHITE_PAR)) { --- 4640,4651 ---- if (!(State & VREPLACE_FLAG) || curwin->w_cursor.lnum > orig_line_count) { ! temp = gchar_cursor(); // remember current char --curwin->w_cursor.lnum; ! // When "aw" is in 'formatoptions' we must delete the space at ! // the end of the line, otherwise the line will be broken ! // again when auto-formatting. if (has_format_option(FO_AUTO) && has_format_option(FO_WHITE_PAR)) { *************** *** 4693,4699 **** curwin->w_cursor.col = save_col; cc = replace_pop(); } ! /* restore the characters that NL replaced */ replace_pop_ins(); State = oldState; } --- 4690,4696 ---- curwin->w_cursor.col = save_col; cc = replace_pop(); } ! // restore the characters that NL replaced replace_pop_ins(); State = oldState; } *************** *** 4706,4716 **** * Delete character(s) before the cursor. */ #ifdef FEAT_RIGHTLEFT ! if (revins_on) /* put cursor on last inserted char */ dec_cursor(); #endif mincol = 0; ! /* keep indent */ if (mode == BACKSPACE_LINE && (curbuf->b_p_ai #ifdef FEAT_CINDENT --- 4703,4713 ---- * Delete character(s) before the cursor. */ #ifdef FEAT_RIGHTLEFT ! if (revins_on) // put cursor on last inserted char dec_cursor(); #endif mincol = 0; ! // keep indent if (mode == BACKSPACE_LINE && (curbuf->b_p_ai #ifdef FEAT_CINDENT *************** *** 4751,4759 **** colnr_T start_vcol; *inserted_space_p = FALSE; ! /* Compute the virtual column where we want to be. Since ! * 'showbreak' may get in the way, need to get the last column of ! * the previous character. */ getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); start_vcol = vcol; dec_cursor(); --- 4748,4756 ---- colnr_T start_vcol; *inserted_space_p = FALSE; ! // Compute the virtual column where we want to be. Since ! // 'showbreak' may get in the way, need to get the last column of ! // the previous character. getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); start_vcol = vcol; dec_cursor(); *************** *** 4776,4790 **** want_vcol = (want_vcol / ts) * ts; #endif ! /* delete characters until we are at or before want_vcol */ while (vcol > want_vcol && (cc = *(ml_get_cursor() - 1), VIM_ISWHITE(cc))) ins_bs_one(&vcol); ! /* insert extra spaces until we are at want_vcol */ while (vcol < want_vcol) { ! /* Remember the first char we inserted */ if (curwin->w_cursor.lnum == Insstart_orig.lnum && curwin->w_cursor.col < Insstart_orig.col) Insstart_orig.col = curwin->w_cursor.col; --- 4773,4787 ---- want_vcol = (want_vcol / ts) * ts; #endif ! // delete characters until we are at or before want_vcol while (vcol > want_vcol && (cc = *(ml_get_cursor() - 1), VIM_ISWHITE(cc))) ins_bs_one(&vcol); ! // insert extra spaces until we are at want_vcol while (vcol < want_vcol) { ! // Remember the first char we inserted if (curwin->w_cursor.lnum == Insstart_orig.lnum && curwin->w_cursor.col < Insstart_orig.col) Insstart_orig.col = curwin->w_cursor.col; *************** *** 4800,4807 **** getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); } ! /* If we are now back where we started delete one character. Can ! * happen when using 'sts' and 'linebreak'. */ if (vcol >= start_vcol) ins_bs_one(&vcol); } --- 4797,4804 ---- getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); } ! // If we are now back where we started delete one character. Can ! // happen when using 'sts' and 'linebreak'. if (vcol >= start_vcol) ins_bs_one(&vcol); } *************** *** 4818,4842 **** do { #ifdef FEAT_RIGHTLEFT ! if (!revins_on) /* put cursor on char to be deleted */ #endif dec_cursor(); cc = gchar_cursor(); ! /* look multi-byte character class */ if (has_mbyte) { prev_cclass = cclass; cclass = mb_get_class(ml_get_cursor()); } ! /* start of word? */ if (mode == BACKSPACE_WORD && !vim_isspace(cc)) { mode = BACKSPACE_WORD_NOT_SPACE; temp = vim_iswordc(cc); } ! /* end of word? */ else if (mode == BACKSPACE_WORD_NOT_SPACE && ((vim_isspace(cc) || vim_iswordc(cc) != temp) || prev_cclass != cclass)) --- 4815,4839 ---- do { #ifdef FEAT_RIGHTLEFT ! if (!revins_on) // put cursor on char to be deleted #endif dec_cursor(); cc = gchar_cursor(); ! // look multi-byte character class if (has_mbyte) { prev_cclass = cclass; cclass = mb_get_class(ml_get_cursor()); } ! // start of word? if (mode == BACKSPACE_WORD && !vim_isspace(cc)) { mode = BACKSPACE_WORD_NOT_SPACE; temp = vim_iswordc(cc); } ! // end of word? else if (mode == BACKSPACE_WORD_NOT_SPACE && ((vim_isspace(cc) || vim_iswordc(cc) != temp) || prev_cclass != cclass)) *************** *** 4875,4881 **** break; #endif } ! /* Just a single backspace?: */ if (mode == BACKSPACE_CHAR) break; } while ( --- 4872,4878 ---- break; #endif } ! // Just a single backspace?: if (mode == BACKSPACE_CHAR) break; } while ( *************** *** 4902,4926 **** */ AppendCharToRedobuff(c); ! /* If deleted before the insertion point, adjust it */ if (curwin->w_cursor.lnum == Insstart_orig.lnum && curwin->w_cursor.col < Insstart_orig.col) Insstart_orig.col = curwin->w_cursor.col; ! /* vi behaviour: the cursor moves backward but the character that ! * was there remains visible ! * Vim behaviour: the cursor moves backward and the character that ! * was there is erased from the screen. ! * We can emulate the vi behaviour by pretending there is a dollar ! * displayed even when there isn't. ! * --pkv Sun Jan 19 01:56:40 EST 2003 */ if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == -1) dollar_vcol = curwin->w_virtcol; #ifdef FEAT_FOLDING ! /* When deleting a char the cursor line must never be in a closed fold. ! * E.g., when 'foldmethod' is indent and deleting the first non-white ! * char before a Tab. */ if (did_backspace) foldOpenCursor(); #endif --- 4899,4923 ---- */ AppendCharToRedobuff(c); ! // If deleted before the insertion point, adjust it if (curwin->w_cursor.lnum == Insstart_orig.lnum && curwin->w_cursor.col < Insstart_orig.col) Insstart_orig.col = curwin->w_cursor.col; ! // vi behaviour: the cursor moves backward but the character that ! // was there remains visible ! // Vim behaviour: the cursor moves backward and the character that ! // was there is erased from the screen. ! // We can emulate the vi behaviour by pretending there is a dollar ! // displayed even when there isn't. ! // --pkv Sun Jan 19 01:56:40 EST 2003 if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == -1) dollar_vcol = curwin->w_virtcol; #ifdef FEAT_FOLDING ! // When deleting a char the cursor line must never be in a closed fold. ! // E.g., when 'foldmethod' is indent and deleting the first non-white ! // char before a Tab. if (did_backspace) foldOpenCursor(); #endif *************** *** 4944,4950 **** int save_allow_keys = allow_keys; int save_paste = p_paste; ! /* If the end code is too long we can't detect it, read everything. */ if (STRLEN(end) >= NUMBUFLEN) end = NULL; ++no_mapping; --- 4941,4947 ---- int save_allow_keys = allow_keys; int save_paste = p_paste; ! // If the end code is too long we can't detect it, read everything. if (STRLEN(end) >= NUMBUFLEN) end = NULL; ++no_mapping; *************** *** 4975,4981 **** if (end != NULL && STRNCMP(buf, end, idx) == 0) { if (end[idx] == NUL) ! break; /* Found the end of paste code. */ continue; } if (!drop) --- 4972,4978 ---- if (end != NULL && STRNCMP(buf, end, idx) == 0) { if (end[idx] == NUL) ! break; // Found the end of paste code. continue; } if (!drop) *************** *** 5035,5041 **** static void ins_tabline(int c) { ! /* We will be leaving the current window, unless closing another tab. */ if (c != K_TABMENU || current_tabmenu != TABLINE_MENU_CLOSE || (current_tab != 0 && current_tab != tabpage_index(curtab))) { --- 5032,5038 ---- static void ins_tabline(int c) { ! // We will be leaving the current window, unless closing another tab. if (c != K_TABMENU || current_tabmenu != TABLINE_MENU_CLOSE || (current_tab != 0 && current_tab != tabpage_index(curtab))) { *************** *** 5051,5057 **** else { handle_tabmenu(); ! redraw_statuslines(); /* will redraw the tabline when needed */ } } #endif --- 5048,5054 ---- else { handle_tabmenu(); ! redraw_statuslines(); // will redraw the tabline when needed } } #endif *************** *** 5105,5112 **** if (oneleft() == OK) { #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) ! /* Only call start_arrow() when not busy with preediting, it will ! * break undo. K_LEFT is inserted in im_correct_cursor(). */ if (p_imst == IM_OVER_THE_SPOT || !im_is_preediting()) #endif { --- 5102,5109 ---- if (oneleft() == OK) { #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) ! // Only call start_arrow() when not busy with preediting, it will ! // break undo. K_LEFT is inserted in im_correct_cursor(). if (p_imst == IM_OVER_THE_SPOT || !im_is_preediting()) #endif { *************** *** 5115,5121 **** AppendCharToRedobuff(K_LEFT); } #ifdef FEAT_RIGHTLEFT ! /* If exit reversed string, position is fixed */ if (revins_scol != -1 && (int)curwin->w_cursor.col >= revins_scol) revins_legal++; revins_chars++; --- 5112,5118 ---- AppendCharToRedobuff(K_LEFT); } #ifdef FEAT_RIGHTLEFT ! // If exit reversed string, position is fixed if (revins_scol != -1 && (int)curwin->w_cursor.col >= revins_scol) revins_legal++; revins_chars++; *************** *** 5128,5138 **** */ else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1) { ! /* always break undo when moving upwards/downwards, else undo may break */ start_arrow(&tpos); --(curwin->w_cursor.lnum); coladvance((colnr_T)MAXCOL); ! curwin->w_set_curswant = TRUE; /* so we stay at the end */ } else vim_beep(BO_CRSR); --- 5125,5135 ---- */ else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1) { ! // always break undo when moving upwards/downwards, else undo may break start_arrow(&tpos); --(curwin->w_cursor.lnum); coladvance((colnr_T)MAXCOL); ! curwin->w_set_curswant = TRUE; // so we stay at the end } else vim_beep(BO_CRSR); *************** *** 5231,5238 **** revins_chars--; #endif } ! /* if 'whichwrap' set for cursor in insert mode, may move the ! * cursor to the next line */ else if (vim_strchr(p_ww, ']') != NULL && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { --- 5228,5235 ---- revins_chars--; #endif } ! // if 'whichwrap' set for cursor in insert mode, may move the ! // cursor to the next line else if (vim_strchr(p_ww, ']') != NULL && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { *************** *** 5271,5277 **** static void ins_up( ! int startcol) /* when TRUE move to Insstart.col */ { pos_T tpos; linenr_T old_topline = curwin->w_topline; --- 5268,5274 ---- static void ins_up( ! int startcol) // when TRUE move to Insstart.col { pos_T tpos; linenr_T old_topline = curwin->w_topline; *************** *** 5309,5315 **** if (mod_mask & MOD_MASK_CTRL) { ! /* : tab page back */ if (first_tabpage->tp_next != NULL) { start_arrow(&curwin->w_cursor); --- 5306,5312 ---- if (mod_mask & MOD_MASK_CTRL) { ! // : tab page back if (first_tabpage->tp_next != NULL) { start_arrow(&curwin->w_cursor); *************** *** 5332,5338 **** static void ins_down( ! int startcol) /* when TRUE move to Insstart.col */ { pos_T tpos; linenr_T old_topline = curwin->w_topline; --- 5329,5335 ---- static void ins_down( ! int startcol) // when TRUE move to Insstart.col { pos_T tpos; linenr_T old_topline = curwin->w_topline; *************** *** 5370,5376 **** if (mod_mask & MOD_MASK_CTRL) { ! /* : tab page forward */ if (first_tabpage->tp_next != NULL) { start_arrow(&curwin->w_cursor); --- 5367,5373 ---- if (mod_mask & MOD_MASK_CTRL) { ! // : tab page forward if (first_tabpage->tp_next != NULL) { start_arrow(&curwin->w_cursor); *************** *** 5427,5433 **** if (!curbuf->b_p_et #ifdef FEAT_VARTABS && !(p_sta && ind ! /* These five lines mean 'tabstop' != 'shiftwidth' */ && ((tabstop_count(curbuf->b_p_vts_array) > 1) || (tabstop_count(curbuf->b_p_vts_array) == 1 && tabstop_first(curbuf->b_p_vts_array) --- 5424,5430 ---- if (!curbuf->b_p_et #ifdef FEAT_VARTABS && !(p_sta && ind ! // These five lines mean 'tabstop' != 'shiftwidth' && ((tabstop_count(curbuf->b_p_vts_array) > 1) || (tabstop_count(curbuf->b_p_vts_array) == 1 && tabstop_first(curbuf->b_p_vts_array) *************** *** 5453,5476 **** AppendToRedobuff((char_u *)"\t"); #ifdef FEAT_VARTABS ! if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ { temp = (int)get_sw_value(curbuf); temp -= get_nolist_virtcol() % temp; } else if (tabstop_count(curbuf->b_p_vsts_array) > 0 || curbuf->b_p_sts != 0) ! /* use 'softtabstop' when set */ temp = tabstop_padding(get_nolist_virtcol(), get_sts_value(), curbuf->b_p_vsts_array); ! else /* otherwise use 'tabstop' */ temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_ts, curbuf->b_p_vts_array); #else ! if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ temp = (int)get_sw_value(curbuf); ! else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ temp = (int)get_sts_value(); ! else /* otherwise use 'tabstop' */ temp = (int)curbuf->b_p_ts; temp -= get_nolist_virtcol() % temp; #endif --- 5450,5473 ---- AppendToRedobuff((char_u *)"\t"); #ifdef FEAT_VARTABS ! if (p_sta && ind) // insert tab in indent, use 'shiftwidth' { temp = (int)get_sw_value(curbuf); temp -= get_nolist_virtcol() % temp; } else if (tabstop_count(curbuf->b_p_vsts_array) > 0 || curbuf->b_p_sts != 0) ! // use 'softtabstop' when set temp = tabstop_padding(get_nolist_virtcol(), get_sts_value(), curbuf->b_p_vsts_array); ! else // otherwise use 'tabstop' temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_ts, curbuf->b_p_vts_array); #else ! if (p_sta && ind) // insert tab in indent, use 'shiftwidth' temp = (int)get_sw_value(curbuf); ! else if (curbuf->b_p_sts != 0) // use 'softtabstop' when set temp = (int)get_sts_value(); ! else // otherwise use 'tabstop' temp = (int)curbuf->b_p_ts; temp -= get_nolist_virtcol() % temp; #endif *************** *** 5488,5494 **** else { ins_str((char_u *)" "); ! if (State & REPLACE_FLAG) /* no char replaced */ replace_push(NUL); } } --- 5485,5491 ---- else { ins_str((char_u *)" "); ! if (State & REPLACE_FLAG) // no char replaced replace_push(NUL); } } *************** *** 5505,5511 **** #endif { char_u *ptr; ! char_u *saved_line = NULL; /* init for GCC */ pos_T pos; pos_T fpos; pos_T *cursor; --- 5502,5508 ---- #endif { char_u *ptr; ! char_u *saved_line = NULL; // init for GCC pos_T pos; pos_T fpos; pos_T *cursor; *************** *** 5532,5542 **** cursor = &curwin->w_cursor; } ! /* When 'L' is not in 'cpoptions' a tab always takes up 'ts' spaces. */ if (vim_strchr(p_cpo, CPO_LISTWM) == NULL) curwin->w_p_list = FALSE; ! /* Find first white before the cursor */ fpos = curwin->w_cursor; while (fpos.col > 0 && VIM_ISWHITE(ptr[-1])) { --- 5529,5539 ---- cursor = &curwin->w_cursor; } ! // When 'L' is not in 'cpoptions' a tab always takes up 'ts' spaces. if (vim_strchr(p_cpo, CPO_LISTWM) == NULL) curwin->w_p_list = FALSE; ! // Find first white before the cursor fpos = curwin->w_cursor; while (fpos.col > 0 && VIM_ISWHITE(ptr[-1])) { *************** *** 5544,5550 **** --ptr; } ! /* In Replace mode, don't change characters before the insert point. */ if ((State & REPLACE_FLAG) && fpos.lnum == Insstart.lnum && fpos.col < Insstart.col) --- 5541,5547 ---- --ptr; } ! // In Replace mode, don't change characters before the insert point. if ((State & REPLACE_FLAG) && fpos.lnum == Insstart.lnum && fpos.col < Insstart.col) *************** *** 5553,5564 **** fpos.col = Insstart.col; } ! /* compute virtual column numbers of first white and cursor */ getvcol(curwin, &fpos, &vcol, NULL, NULL); getvcol(curwin, cursor, &want_vcol, NULL, NULL); ! /* Use as many TABs as possible. Beware of 'breakindent', 'showbreak' ! * and 'linebreak' adding extra virtual columns. */ while (VIM_ISWHITE(*ptr)) { i = lbr_chartabsize(NULL, (char_u *)"\t", vcol); --- 5550,5561 ---- fpos.col = Insstart.col; } ! // compute virtual column numbers of first white and cursor getvcol(curwin, &fpos, &vcol, NULL, NULL); getvcol(curwin, cursor, &want_vcol, NULL, NULL); ! // Use as many TABs as possible. Beware of 'breakindent', 'showbreak' ! // and 'linebreak' adding extra virtual columns. while (VIM_ISWHITE(*ptr)) { i = lbr_chartabsize(NULL, (char_u *)"\t", vcol); *************** *** 5569,5576 **** *ptr = TAB; if (change_col < 0) { ! change_col = fpos.col; /* Column of first change */ ! /* May have to adjust Insstart */ if (fpos.lnum == Insstart.lnum && fpos.col < Insstart.col) Insstart.col = fpos.col; } --- 5566,5573 ---- *ptr = TAB; if (change_col < 0) { ! change_col = fpos.col; // Column of first change ! // May have to adjust Insstart if (fpos.lnum == Insstart.lnum && fpos.col < Insstart.col) Insstart.col = fpos.col; } *************** *** 5585,5591 **** int repl_off = 0; char_u *line = ptr; ! /* Skip over the spaces we need. */ while (vcol < want_vcol && *ptr == ' ') { vcol += lbr_chartabsize(line, ptr, vcol); --- 5582,5588 ---- int repl_off = 0; char_u *line = ptr; ! // Skip over the spaces we need. while (vcol < want_vcol && *ptr == ' ') { vcol += lbr_chartabsize(line, ptr, vcol); *************** *** 5594,5611 **** } if (vcol > want_vcol) { ! /* Must have a char with 'showbreak' just before it. */ --ptr; --repl_off; } fpos.col += repl_off; ! /* Delete following spaces. */ i = cursor->col - fpos.col; if (i > 0) { STRMOVE(ptr, ptr + i); ! /* correct replace stack. */ if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG)) for (temp = i; --temp >= 0; ) replace_join(repl_off); --- 5591,5608 ---- } if (vcol > want_vcol) { ! // Must have a char with 'showbreak' just before it. --ptr; --repl_off; } fpos.col += repl_off; ! // Delete following spaces. i = cursor->col - fpos.col; if (i > 0) { STRMOVE(ptr, ptr + i); ! // correct replace stack. if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG)) for (temp = i; --temp >= 0; ) replace_join(repl_off); *************** *** 5630,5640 **** */ if (State & VREPLACE_FLAG) { ! /* Backspace from real cursor to change_col */ backspace_until_column(change_col); ! /* Insert each char in saved_line from changed_col to ! * ptr-cursor */ ins_bytes_len(saved_line + change_col, cursor->col - change_col); } --- 5627,5637 ---- */ if (State & VREPLACE_FLAG) { ! // Backspace from real cursor to change_col backspace_until_column(change_col); ! // Insert each char in saved_line from changed_col to ! // ptr-cursor ins_bytes_len(saved_line + change_col, cursor->col - change_col); } *************** *** 5678,5691 **** * in open_line(). */ ! /* Put cursor on NUL if on the last char and coladd is 1 (happens after ! * CTRL-O). */ if (virtual_active() && curwin->w_cursor.coladd > 0) coladvance(getviscol()); #ifdef FEAT_RIGHTLEFT ! /* NL in reverse insert will always start in the end of ! * current line. */ if (revins_on) curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); #endif --- 5675,5688 ---- * in open_line(). */ ! // Put cursor on NUL if on the last char and coladd is 1 (happens after ! // CTRL-O). if (virtual_active() && curwin->w_cursor.coladd > 0) coladvance(getviscol()); #ifdef FEAT_RIGHTLEFT ! // NL in reverse insert will always start in the end of ! // current line. if (revins_on) curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); #endif *************** *** 5698,5704 **** can_cindent = TRUE; #endif #ifdef FEAT_FOLDING ! /* When inserting a line the cursor line must never be in a closed fold. */ foldOpenCursor(); #endif --- 5695,5701 ---- can_cindent = TRUE; #endif #ifdef FEAT_FOLDING ! // When inserting a line the cursor line must never be in a closed fold. foldOpenCursor(); #endif *************** *** 5721,5727 **** pc_status = PC_STATUS_UNSET; if (redrawing() && !char_avail()) { ! /* may need to redraw when no more chars available now */ ins_redraw(FALSE); edit_putchar('?', TRUE); --- 5718,5724 ---- pc_status = PC_STATUS_UNSET; if (redrawing() && !char_avail()) { ! // may need to redraw when no more chars available now ins_redraw(FALSE); edit_putchar('?', TRUE); *************** *** 5732,5753 **** } #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; /* disallow scrolling here */ #endif ! /* don't map the digraph chars. This also prevents the ! * mode message to be deleted when ESC is hit */ ++no_mapping; ++allow_keys; c = plain_vgetc(); --no_mapping; --allow_keys; if (did_putchar) ! /* when the line fits in 'columns' the '?' is at the start of the next ! * line and will not be removed by the redraw */ edit_unputchar(); ! if (IS_SPECIAL(c) || mod_mask) /* special key */ { #ifdef FEAT_CMDL_INFO clear_showcmd(); --- 5729,5750 ---- } #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; // disallow scrolling here #endif ! // don't map the digraph chars. This also prevents the ! // mode message to be deleted when ESC is hit ++no_mapping; ++allow_keys; c = plain_vgetc(); --no_mapping; --allow_keys; if (did_putchar) ! // when the line fits in 'columns' the '?' is at the start of the next ! // line and will not be removed by the redraw edit_unputchar(); ! if (IS_SPECIAL(c) || mod_mask) // special key { #ifdef FEAT_CMDL_INFO clear_showcmd(); *************** *** 5760,5766 **** did_putchar = FALSE; if (redrawing() && !char_avail()) { ! /* may need to redraw when no more chars available now */ ins_redraw(FALSE); if (char2cells(c) == 1) --- 5757,5763 ---- did_putchar = FALSE; if (redrawing() && !char_avail()) { ! // may need to redraw when no more chars available now ins_redraw(FALSE); if (char2cells(c) == 1) *************** *** 5779,5786 **** --no_mapping; --allow_keys; if (did_putchar) ! /* when the line fits in 'columns' the '?' is at the start of the ! * next line and will not be removed by a redraw */ edit_unputchar(); if (cc != ESC) { --- 5776,5783 ---- --no_mapping; --allow_keys; if (did_putchar) ! // when the line fits in 'columns' the '?' is at the start of the ! // next line and will not be removed by a redraw edit_unputchar(); if (cc != ESC) { *************** *** 5817,5823 **** return NUL; } ! /* try to advance to the cursor column */ temp = 0; line = ptr = ml_get(lnum); prev_ptr = ptr; --- 5814,5820 ---- return NUL; } ! // try to advance to the cursor column temp = 0; line = ptr = ml_get(lnum); prev_ptr = ptr; *************** *** 5859,5870 **** { long tw_save; ! /* The character must be taken literally, insert like it ! * was typed after a CTRL-V, and pretend 'textwidth' ! * wasn't set. Digits, 'o' and 'x' are special after a ! * CTRL-V, don't use it for these. */ if (c < 256 && !isalnum(c)) ! AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */ tw_save = curbuf->b_p_tw; curbuf->b_p_tw = -1; insert_special(c, TRUE, FALSE); --- 5856,5867 ---- { long tw_save; ! // The character must be taken literally, insert like it ! // was typed after a CTRL-V, and pretend 'textwidth' ! // wasn't set. Digits, 'o' and 'x' are special after a ! // CTRL-V, don't use it for these. if (c < 256 && !isalnum(c)) ! AppendToRedobuff((char_u *)CTRL_V_STR); // CTRL-V tw_save = curbuf->b_p_tw; curbuf->b_p_tw = -1; insert_special(c, TRUE, FALSE); *************** *** 5873,5879 **** revins_chars++; revins_legal++; #endif ! c = Ctrl_V; /* pretend CTRL-V is last character */ auto_format(FALSE, TRUE); } } --- 5870,5876 ---- revins_chars++; revins_legal++; #endif ! c = Ctrl_V; // pretend CTRL-V is last character auto_format(FALSE, TRUE); } } *************** *** 5912,5918 **** char_u buf[MB_MAXBYTES + 1]; int save_State = State; ! /* Return quickly when there is nothing to do. */ if (!has_insertcharpre()) return NULL; --- 5909,5915 ---- char_u buf[MB_MAXBYTES + 1]; int save_State = State; ! // Return quickly when there is nothing to do. if (!has_insertcharpre()) return NULL; *************** *** 5924,5944 **** buf[1] = NUL; } ! /* Lock the text to avoid weird things from happening. */ ++textlock; ! set_vim_var_string(VV_CHAR, buf, -1); /* set v:char */ res = NULL; if (ins_apply_autocmds(EVENT_INSERTCHARPRE)) { ! /* Get the value of v:char. It may be empty or more than one ! * character. Only use it when changed, otherwise continue with the ! * original character to avoid breaking autoindent. */ if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0) res = vim_strsave(get_vim_var_str(VV_CHAR)); } ! set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */ --textlock; // Restore the State, it may have been changed. --- 5921,5941 ---- buf[1] = NUL; } ! // Lock the text to avoid weird things from happening. ++textlock; ! set_vim_var_string(VV_CHAR, buf, -1); // set v:char res = NULL; if (ins_apply_autocmds(EVENT_INSERTCHARPRE)) { ! // Get the value of v:char. It may be empty or more than one ! // character. Only use it when changed, otherwise continue with the ! // original character to avoid breaking autoindent. if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0) res = vim_strsave(get_vim_var_str(VV_CHAR)); } ! set_vim_var_string(VV_CHAR, NULL, -1); // clear v:char --textlock; // Restore the State, it may have been changed. *** ../vim-8.1.2377/src/eval.c 2019-11-30 22:47:42.643331239 +0100 --- src/eval.c 2019-12-01 21:07:44.378125163 +0100 *************** *** 36,54 **** */ static int current_copyID = 0; ! static int echo_attr = 0; /* attributes used for ":echo" */ /* * Info used by a ":for" loop. */ typedef struct { ! int fi_semicolon; /* TRUE if ending in '; var]' */ ! int fi_varcount; /* nr of variables in the list */ ! listwatch_T fi_lw; /* keep an eye on the item used. */ ! list_T *fi_list; /* list being used */ ! int fi_bi; /* index of blob */ ! blob_T *fi_blob; /* blob being used */ } forinfo_T; static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op); --- 36,54 ---- */ static int current_copyID = 0; ! static int echo_attr = 0; // attributes used for ":echo" /* * Info used by a ":for" loop. */ typedef struct { ! int fi_semicolon; // TRUE if ending in '; var]' ! int fi_varcount; // nr of variables in the list ! listwatch_T fi_lw; // keep an eye on the item used. ! list_T *fi_list; // list being used ! int fi_bi; // index of blob ! blob_T *fi_blob; // blob being used } forinfo_T; static int tv_op(typval_T *tv1, typval_T *tv2, char_u *op); *************** *** 174,180 **** char_u *arg, int *error, char_u **nextcmd, ! int skip) /* only parse, don't execute */ { typval_T tv; varnumber_T retval = FALSE; --- 174,180 ---- char_u *arg, int *error, char_u **nextcmd, ! int skip) // only parse, don't execute { typval_T tv; varnumber_T retval = FALSE; *************** *** 261,267 **** s = skipwhite(s); if (eval1_emsg(&s, rettv, TRUE) == FAIL) return FAIL; ! if (*s != NUL) /* check for trailing chars after expr */ { clear_tv(rettv); semsg(_(e_invexpr2), s); --- 261,267 ---- s = skipwhite(s); if (eval1_emsg(&s, rettv, TRUE) == FAIL) return FAIL; ! if (*s != NUL) // check for trailing chars after expr { clear_tv(rettv); semsg(_(e_invexpr2), s); *************** *** 300,306 **** eval_to_string_skip( char_u *arg, char_u **nextcmd, ! int skip) /* only parse, don't execute */ { typval_T tv; char_u *retval; --- 300,306 ---- eval_to_string_skip( char_u *arg, char_u **nextcmd, ! int skip) // only parse, don't execute { typval_T tv; char_u *retval; *************** *** 467,473 **** int ret; funcexe_T funcexe; ! rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ vim_memset(&funcexe, 0, sizeof(funcexe)); funcexe.firstline = curwin->w_cursor.lnum; funcexe.lastline = curwin->w_cursor.lnum; --- 467,473 ---- int ret; funcexe_T funcexe; ! rettv->v_type = VAR_UNKNOWN; // clear_tv() uses this vim_memset(&funcexe, 0, sizeof(funcexe)); funcexe.firstline = curwin->w_cursor.lnum; funcexe.lastline = curwin->w_cursor.lnum; *************** *** 574,588 **** retval = 0; else { ! /* If the result is a number, just return the number. */ if (tv.v_type == VAR_NUMBER) retval = tv.vval.v_number; else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL) retval = 0; else { ! /* If the result is a string, check if there is a non-digit before ! * the number. */ s = tv.vval.v_string; if (!VIM_ISDIGIT(*s) && *s != '-') *cp = *s++; --- 574,588 ---- retval = 0; else { ! // If the result is a number, just return the number. if (tv.v_type == VAR_NUMBER) retval = tv.vval.v_number; else if (tv.v_type != VAR_STRING || tv.vval.v_string == NULL) retval = 0; else { ! // If the result is a string, check if there is a non-digit before ! // the number. s = tv.vval.v_string; if (!VIM_ISDIGIT(*s) && *s != '-') *cp = *s++; *************** *** 625,632 **** lval_T *lp, int unlet, int skip, ! int flags, /* GLV_ values */ ! int fne_flags) /* flags for find_name_end() */ { char_u *p; char_u *expr_start, *expr_end; --- 625,632 ---- lval_T *lp, int unlet, int skip, ! int flags, // GLV_ values ! int fne_flags) // flags for find_name_end() { char_u *p; char_u *expr_start, *expr_end; *************** *** 641,661 **** hashtab_T *ht; int quiet = flags & GLV_QUIET; ! /* Clear everything in "lp". */ vim_memset(lp, 0, sizeof(lval_T)); if (skip) { ! /* When skipping just find the end of the name. */ lp->ll_name = name; return find_name_end(name, NULL, NULL, FNE_INCL_BR | fne_flags); } ! /* Find the end of the name. */ p = find_name_end(name, &expr_start, &expr_end, fne_flags); if (expr_start != NULL) { ! /* Don't expand the name when we already know there is an error. */ if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p) && *p != '[' && *p != '.') { --- 641,661 ---- hashtab_T *ht; int quiet = flags & GLV_QUIET; ! // Clear everything in "lp". vim_memset(lp, 0, sizeof(lval_T)); if (skip) { ! // When skipping just find the end of the name. lp->ll_name = name; return find_name_end(name, NULL, NULL, FNE_INCL_BR | fne_flags); } ! // Find the end of the name. p = find_name_end(name, &expr_start, &expr_end, fne_flags); if (expr_start != NULL) { ! // Don't expand the name when we already know there is an error. if (unlet && !VIM_ISWHITE(*p) && !ends_excmd(*p) && *p != '[' && *p != '.') { *************** *** 666,674 **** lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); if (lp->ll_exp_name == NULL) { ! /* Report an invalid expression in braces, unless the ! * expression evaluation has been cancelled due to an ! * aborting error, an interrupt, or an exception. */ if (!aborting() && !quiet) { emsg_severe = TRUE; --- 666,674 ---- lp->ll_exp_name = make_expanded_name(name, expr_start, expr_end, p); if (lp->ll_exp_name == NULL) { ! // Report an invalid expression in braces, unless the ! // expression evaluation has been cancelled due to an ! // aborting error, an interrupt, or an exception. if (!aborting() && !quiet) { emsg_severe = TRUE; *************** *** 681,694 **** else lp->ll_name = name; ! /* Without [idx] or .key we are done. */ if ((*p != '[' && *p != '.') || lp->ll_name == NULL) return p; cc = *p; *p = NUL; ! /* Only pass &ht when we would write to the variable, it prevents autoload ! * as well. */ v = find_var(lp->ll_name, (flags & GLV_READ_ONLY) ? NULL : &ht, flags & GLV_NO_AUTOLOAD); if (v == NULL && !quiet) --- 681,694 ---- else lp->ll_name = name; ! // Without [idx] or .key we are done. if ((*p != '[' && *p != '.') || lp->ll_name == NULL) return p; cc = *p; *p = NUL; ! // Only pass &ht when we would write to the variable, it prevents autoload ! // as well. v = find_var(lp->ll_name, (flags & GLV_READ_ONLY) ? NULL : &ht, flags & GLV_NO_AUTOLOAD); if (v == NULL && !quiet) *************** *** 738,761 **** } else { ! /* Get the index [expr] or the first index [expr: ]. */ p = skipwhite(p + 1); if (*p == ':') empty1 = TRUE; else { empty1 = FALSE; ! if (eval1(&p, &var1, TRUE) == FAIL) /* recursive! */ return NULL; if (tv_get_string_chk(&var1) == NULL) { ! /* not a number or string */ clear_tv(&var1); return NULL; } } ! /* Optionally get the second index [ :expr]. */ if (*p == ':') { if (lp->ll_tv->v_type == VAR_DICT) --- 738,761 ---- } else { ! // Get the index [expr] or the first index [expr: ]. p = skipwhite(p + 1); if (*p == ':') empty1 = TRUE; else { empty1 = FALSE; ! if (eval1(&p, &var1, TRUE) == FAIL) // recursive! return NULL; if (tv_get_string_chk(&var1) == NULL) { ! // not a number or string clear_tv(&var1); return NULL; } } ! // Optionally get the second index [ :expr]. if (*p == ':') { if (lp->ll_tv->v_type == VAR_DICT) *************** *** 782,795 **** else { lp->ll_empty2 = FALSE; ! if (eval1(&p, &var2, TRUE) == FAIL) /* recursive! */ { clear_tv(&var1); return NULL; } if (tv_get_string_chk(&var2) == NULL) { ! /* not a number or string */ clear_tv(&var1); clear_tv(&var2); return NULL; --- 782,795 ---- else { lp->ll_empty2 = FALSE; ! if (eval1(&p, &var2, TRUE) == FAIL) // recursive! { clear_tv(&var1); return NULL; } if (tv_get_string_chk(&var2) == NULL) { ! // not a number or string clear_tv(&var1); clear_tv(&var2); return NULL; *************** *** 809,815 **** return NULL; } ! /* Skip to past ']'. */ ++p; } --- 809,815 ---- return NULL; } ! // Skip to past ']'. ++p; } *************** *** 817,824 **** { if (len == -1) { ! /* "[key]": get key from "var1" */ ! key = tv_get_string_chk(&var1); /* is number or string */ if (key == NULL) { clear_tv(&var1); --- 817,824 ---- { if (len == -1) { ! // "[key]": get key from "var1" ! key = tv_get_string_chk(&var1); // is number or string if (key == NULL) { clear_tv(&var1); *************** *** 829,837 **** lp->ll_dict = lp->ll_tv->vval.v_dict; lp->ll_di = dict_find(lp->ll_dict, key, len); ! /* When assigning to a scope dictionary check that a function and ! * variable name is valid (only variable name unless it is l: or ! * g: dictionary). Disallow overwriting a builtin function. */ if (rettv != NULL && lp->ll_dict->dv_scope != 0) { int prevval; --- 829,837 ---- lp->ll_dict = lp->ll_tv->vval.v_dict; lp->ll_di = dict_find(lp->ll_dict, key, len); ! // When assigning to a scope dictionary check that a function and ! // variable name is valid (only variable name unless it is l: or ! // g: dictionary). Disallow overwriting a builtin function. if (rettv != NULL && lp->ll_dict->dv_scope != 0) { int prevval; *************** *** 843,849 **** key[len] = NUL; } else ! prevval = 0; /* avoid compiler warning */ wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE && rettv->v_type == VAR_FUNC && var_check_func_name(key, lp->ll_di == NULL)) --- 843,849 ---- key[len] = NUL; } else ! prevval = 0; // avoid compiler warning wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE && rettv->v_type == VAR_FUNC && var_check_func_name(key, lp->ll_di == NULL)) *************** *** 882,888 **** p = NULL; break; } ! /* existing variable, need to check if it can be changed */ else if ((flags & GLV_READ_ONLY) == 0 && var_check_ro(lp->ll_di->di_flags, name, FALSE)) { --- 882,888 ---- p = NULL; break; } ! // existing variable, need to check if it can be changed else if ((flags & GLV_READ_ONLY) == 0 && var_check_ro(lp->ll_di->di_flags, name, FALSE)) { *************** *** 941,947 **** if (empty1) lp->ll_n1 = 0; else ! /* is number or string */ lp->ll_n1 = (long)tv_get_number(&var1); clear_tv(&var1); --- 941,947 ---- if (empty1) lp->ll_n1 = 0; else ! // is number or string lp->ll_n1 = (long)tv_get_number(&var1); clear_tv(&var1); *************** *** 973,979 **** if (lp->ll_range && !lp->ll_empty2) { lp->ll_n2 = (long)tv_get_number(&var2); ! /* is number or string */ clear_tv(&var2); if (lp->ll_n2 < 0) { --- 973,979 ---- if (lp->ll_range && !lp->ll_empty2) { lp->ll_n2 = (long)tv_get_number(&var2); ! // is number or string clear_tv(&var2); if (lp->ll_n2 < 0) { *************** *** 987,993 **** lp->ll_n2 = list_idx_of_item(lp->ll_list, ni); } ! /* Check that lp->ll_n2 isn't before lp->ll_n1. */ if (lp->ll_n1 < 0) lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li); if (lp->ll_n2 < lp->ll_n1) --- 987,993 ---- lp->ll_n2 = list_idx_of_item(lp->ll_list, ni); } ! // Check that lp->ll_n2 isn't before lp->ll_n1. if (lp->ll_n1 < 0) lp->ll_n1 = list_idx_of_item(lp->ll_list, lp->ll_li); if (lp->ll_n2 < lp->ll_n1) *************** *** 1164,1170 **** break; if (lp->ll_li->li_next == NULL) { ! /* Need to add an empty item. */ if (list_append_number(lp->ll_list, 0) == FAIL) { ri = NULL; --- 1164,1170 ---- break; if (lp->ll_li->li_next == NULL) { ! // Need to add an empty item. if (list_append_number(lp->ll_list, 0) == FAIL) { ri = NULL; *************** *** 1199,1205 **** return; } ! /* Need to add an item to the Dictionary. */ di = dictitem_alloc(lp->ll_newkey); if (di == NULL) return; --- 1199,1205 ---- return; } ! // Need to add an item to the Dictionary. di = dictitem_alloc(lp->ll_newkey); if (di == NULL) return; *************** *** 1244,1250 **** char_u numbuf[NUMBUFLEN]; char_u *s; ! /* Can't do anything with a Funcref, Dict, v:true on the right. */ if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT && tv2->v_type != VAR_SPECIAL) { --- 1244,1250 ---- char_u numbuf[NUMBUFLEN]; char_u *s; ! // Can't do anything with a Funcref, Dict, v:true on the right. if (tv2->v_type != VAR_FUNC && tv2->v_type != VAR_DICT && tv2->v_type != VAR_SPECIAL) { *************** *** 1386,1392 **** typval_T tv; list_T *l; ! *errp = TRUE; /* default: there is an error */ fi = ALLOC_CLEAR_ONE(forinfo_T); if (fi == NULL) --- 1386,1392 ---- typval_T tv; list_T *l; ! *errp = TRUE; // default: there is an error fi = ALLOC_CLEAR_ONE(forinfo_T); if (fi == NULL) *************** *** 1526,1532 **** xp->xp_context = EXPAND_USER_VARS; if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) { ! /* ":let var1 var2 ...": find last space. */ for (p = arg + STRLEN(arg); p >= arg; ) { xp->xp_pattern = p; --- 1526,1532 ---- xp->xp_context = EXPAND_USER_VARS; if (vim_strpbrk(arg, (char_u *)"\"'+-*/%.=!?~|&$([<>,#") == NULL) { ! // ":let var1 var2 ...": find last space. for (p = arg + STRLEN(arg); p >= arg; ) { xp->xp_pattern = p; *************** *** 1563,1569 **** } else if (c == '$') { ! /* environment variable */ xp->xp_context = EXPAND_ENV_VARS; } else if (c == '=') --- 1563,1569 ---- } else if (c == '$') { ! // environment variable xp->xp_context = EXPAND_ENV_VARS; } else if (c == '=') *************** *** 1574,1601 **** else if (c == '#' && xp->xp_context == EXPAND_EXPRESSION) { ! /* Autoload function/variable contains '#'. */ break; } else if ((c == '<' || c == '#') && xp->xp_context == EXPAND_FUNCTIONS && vim_strchr(xp->xp_pattern, '(') == NULL) { ! /* Function name can start with "" and contain '#'. */ break; } else if (cmdidx != CMD_let || got_eq) { ! if (c == '"') /* string */ { while ((c = *++xp->xp_pattern) != NUL && c != '"') if (c == '\\' && xp->xp_pattern[1] != NUL) ++xp->xp_pattern; xp->xp_context = EXPAND_NOTHING; } ! else if (c == '\'') /* literal string */ { ! /* Trick: '' is like stopping and starting a literal string. */ while ((c = *++xp->xp_pattern) != NUL && c != '\'') /* skip */ ; xp->xp_context = EXPAND_NOTHING; --- 1574,1601 ---- else if (c == '#' && xp->xp_context == EXPAND_EXPRESSION) { ! // Autoload function/variable contains '#'. break; } else if ((c == '<' || c == '#') && xp->xp_context == EXPAND_FUNCTIONS && vim_strchr(xp->xp_pattern, '(') == NULL) { ! // Function name can start with "" and contain '#'. break; } else if (cmdidx != CMD_let || got_eq) { ! if (c == '"') // string { while ((c = *++xp->xp_pattern) != NUL && c != '"') if (c == '\\' && xp->xp_pattern[1] != NUL) ++xp->xp_pattern; xp->xp_context = EXPAND_NOTHING; } ! else if (c == '\'') // literal string { ! // Trick: '' is like stopping and starting a literal string. while ((c = *++xp->xp_pattern) != NUL && c != '\'') /* skip */ ; xp->xp_context = EXPAND_NOTHING; *************** *** 1614,1621 **** xp->xp_context = EXPAND_EXPRESSION; } else ! /* Doesn't look like something valid, expand as an expression ! * anyway. */ xp->xp_context = EXPAND_EXPRESSION; arg = xp->xp_pattern; if (*arg != NUL) --- 1614,1621 ---- xp->xp_context = EXPAND_EXPRESSION; } else ! // Doesn't look like something valid, expand as an expression ! // anyway. xp->xp_context = EXPAND_EXPRESSION; arg = xp->xp_pattern; if (*arg != NUL) *************** *** 1636,1642 **** char_u *save_cpo; regmatch_T regmatch; ! /* avoid 'l' flag in 'cpoptions' */ save_cpo = p_cpo; p_cpo = (char_u *)""; regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); --- 1636,1642 ---- char_u *save_cpo; regmatch_T regmatch; ! // avoid 'l' flag in 'cpoptions' save_cpo = p_cpo; p_cpo = (char_u *)""; regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); *************** *** 1672,1683 **** if (!evaluate) check_vars(s, len); ! /* If "s" is the name of a variable of type VAR_FUNC ! * use its contents. */ s = deref_func_name(s, &len, &partial, !evaluate); ! /* Need to make a copy, in case evaluating the arguments makes ! * the name invalid. */ s = vim_strsave(s); if (s == NULL) ret = FAIL; --- 1672,1683 ---- if (!evaluate) check_vars(s, len); ! // If "s" is the name of a variable of type VAR_FUNC ! // use its contents. s = deref_func_name(s, &len, &partial, !evaluate); ! // Need to make a copy, in case evaluating the arguments makes ! // the name invalid. s = vim_strsave(s); if (s == NULL) ret = FAIL; *************** *** 1696,1713 **** } vim_free(s); ! /* If evaluate is FALSE rettv->v_type was not set in ! * get_func_tv, but it's needed in handle_subscript() to parse ! * what follows. So set it here. */ if (rettv->v_type == VAR_UNKNOWN && !evaluate && **arg == '(') { rettv->vval.v_string = NULL; rettv->v_type = VAR_FUNC; } ! /* Stop the expression evaluation when immediately ! * aborting on error, or when an interrupt occurred or ! * an exception was thrown but not caught. */ if (evaluate && aborting()) { if (ret == OK) --- 1696,1713 ---- } vim_free(s); ! // If evaluate is FALSE rettv->v_type was not set in ! // get_func_tv, but it's needed in handle_subscript() to parse ! // what follows. So set it here. if (rettv->v_type == VAR_UNKNOWN && !evaluate && **arg == '(') { rettv->vval.v_string = NULL; rettv->v_type = VAR_FUNC; } ! // Stop the expression evaluation when immediately ! // aborting on error, or when an interrupt occurred or ! // an exception was thrown but not caught. if (evaluate && aborting()) { if (ret == OK) *************** *** 1806,1812 **** * Get the second variable. */ *arg = skipwhite(*arg + 1); ! if (eval1(arg, rettv, evaluate && result) == FAIL) /* recursive! */ return FAIL; /* --- 1806,1812 ---- * Get the second variable. */ *arg = skipwhite(*arg + 1); ! if (eval1(arg, rettv, evaluate && result) == FAIL) // recursive! return FAIL; /* *************** *** 1824,1830 **** * Get the third variable. */ *arg = skipwhite(*arg + 1); ! if (eval1(arg, &var2, evaluate && !result) == FAIL) /* recursive! */ { if (evaluate && result) clear_tv(rettv); --- 1824,1830 ---- * Get the third variable. */ *arg = skipwhite(*arg + 1); ! if (eval1(arg, &var2, evaluate && !result) == FAIL) // recursive! { if (evaluate && result) clear_tv(rettv); *************** *** 1998,2004 **** char_u *p; int i; exptype_T type = TYPE_UNKNOWN; ! int type_is = FALSE; /* TRUE for "is" and "isnot" */ int len = 2; int ic; --- 1998,2004 ---- char_u *p; int i; exptype_T type = TYPE_UNKNOWN; ! int type_is = FALSE; // TRUE for "is" and "isnot" int len = 2; int ic; *************** *** 2056,2074 **** */ if (type != TYPE_UNKNOWN) { ! /* extra question mark appended: ignore case */ if (p[len] == '?') { ic = TRUE; ++len; } ! /* extra '#' appended: match case */ else if (p[len] == '#') { ic = FALSE; ++len; } ! /* nothing appended: use 'ignorecase' */ else ic = p_ic; --- 2056,2074 ---- */ if (type != TYPE_UNKNOWN) { ! // extra question mark appended: ignore case if (p[len] == '?') { ic = TRUE; ++len; } ! // extra '#' appended: match case else if (p[len] == '#') { ic = FALSE; ++len; } ! // nothing appended: use 'ignorecase' else ic = p_ic; *************** *** 2145,2157 **** #endif ) { ! /* For "list + ...", an illegal use of the first operand as ! * a number cannot be determined before evaluating the 2nd ! * operand: if this is also a list, all is ok. ! * For "something . ...", "something - ..." or "non-list + ...", ! * we know that the first operand needs to be a string or number ! * without evaluating the 2nd operand. So check before to avoid ! * side effects after an error. */ if (evaluate && tv_get_string_chk(rettv) == NULL) { clear_tv(rettv); --- 2145,2157 ---- #endif ) { ! // For "list + ...", an illegal use of the first operand as ! // a number cannot be determined before evaluating the 2nd ! // operand: if this is also a list, all is ok. ! // For "something . ...", "something - ..." or "non-list + ...", ! // we know that the first operand needs to be a string or number ! // without evaluating the 2nd operand. So check before to avoid ! // side effects after an error. if (evaluate && tv_get_string_chk(rettv) == NULL) { clear_tv(rettv); *************** *** 2178,2186 **** */ if (op == '.') { ! s1 = tv_get_string_buf(rettv, buf1); /* already checked */ s2 = tv_get_string_buf_chk(&var2, buf2); ! if (s2 == NULL) /* type error ? */ { clear_tv(rettv); clear_tv(&var2); --- 2178,2186 ---- */ if (op == '.') { ! s1 = tv_get_string_buf(rettv, buf1); // already checked s2 = tv_get_string_buf_chk(&var2, buf2); ! if (s2 == NULL) // type error ? { clear_tv(rettv); clear_tv(&var2); *************** *** 2213,2219 **** else if (op == '+' && rettv->v_type == VAR_LIST && var2.v_type == VAR_LIST) { ! /* concatenate Lists */ if (list_concat(rettv->vval.v_list, var2.vval.v_list, &var3) == FAIL) { --- 2213,2219 ---- else if (op == '+' && rettv->v_type == VAR_LIST && var2.v_type == VAR_LIST) { ! // concatenate Lists if (list_concat(rettv->vval.v_list, var2.vval.v_list, &var3) == FAIL) { *************** *** 2240,2248 **** n1 = tv_get_number_chk(rettv, &error); if (error) { ! /* This can only happen for "list + non-list". For ! * "non-list + ..." or "something - ...", we returned ! * before evaluating the 2nd operand. */ clear_tv(rettv); return FAIL; } --- 2240,2248 ---- n1 = tv_get_number_chk(rettv, &error); if (error) { ! // This can only happen for "list + non-list". For ! // "non-list + ..." or "something - ...", we returned ! // before evaluating the 2nd operand. clear_tv(rettv); return FAIL; } *************** *** 2275,2281 **** clear_tv(rettv); #ifdef FEAT_FLOAT ! /* If there is a float on either side the result is a float. */ if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) { if (op == '+') --- 2275,2281 ---- clear_tv(rettv); #ifdef FEAT_FLOAT ! // If there is a float on either side the result is a float. if (rettv->v_type == VAR_FLOAT || var2.v_type == VAR_FLOAT) { if (op == '+') *************** *** 2318,2324 **** char_u **arg, typval_T *rettv, int evaluate, ! int want_string) /* after "." operator */ { typval_T var2; int op; --- 2318,2324 ---- char_u **arg, typval_T *rettv, int evaluate, ! int want_string) // after "." operator { typval_T var2; int op; *************** *** 2408,2418 **** else if (op == '/') { # ifdef VMS ! /* VMS crashes on divide by zero, work around it */ if (f2 == 0.0) { if (f1 == 0) ! f1 = -1 * __F_FLT_MAX - 1L; /* similar to NaN */ else if (f1 < 0) f1 = -1 * __F_FLT_MAX; else --- 2408,2418 ---- else if (op == '/') { # ifdef VMS ! // VMS crashes on divide by zero, work around it if (f2 == 0.0) { if (f1 == 0) ! f1 = -1 * __F_FLT_MAX - 1L; // similar to NaN else if (f1 < 0) f1 = -1 * __F_FLT_MAX; else *************** *** 2421,2428 **** else f1 = f1 / f2; # else ! /* We rely on the floating point library to handle divide ! * by zero to result in "inf" and not a crash. */ f1 = f1 / f2; # endif } --- 2421,2428 ---- else f1 = f1 / f2; # else ! // We rely on the floating point library to handle divide ! // by zero to result in "inf" and not a crash. f1 = f1 / f2; # endif } *************** *** 2487,2493 **** char_u **arg, typval_T *rettv, int evaluate, ! int want_string UNUSED) /* after "." operator */ { varnumber_T n; int len; --- 2487,2493 ---- char_u **arg, typval_T *rettv, int evaluate, ! int want_string UNUSED) // after "." operator { varnumber_T n; int len; *************** *** 2542,2554 **** char_u *p; int get_float = FALSE; ! /* We accept a float when the format matches ! * "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very ! * strict to avoid backwards compatibility problems. ! * With script version 2 and later the leading digit can be ! * omitted. ! * Don't look for a float after the "." operator, so that ! * ":let vers = 1.2.3" doesn't fail. */ if (**arg == '.') p = *arg; else --- 2542,2554 ---- char_u *p; int get_float = FALSE; ! // We accept a float when the format matches ! // "[0-9]\+\.[0-9]\+\([eE][+-]\?[0-9]\+\)\?". This is very ! // strict to avoid backwards compatibility problems. ! // With script version 2 and later the leading digit can be ! // omitted. ! // Don't look for a float after the "." operator, so that ! // ":let vers = 1.2.3" doesn't fail. if (**arg == '.') p = *arg; else *************** *** 2705,2711 **** * nested expression: (expression). */ case '(': *arg = skipwhite(*arg + 1); ! ret = eval1(arg, rettv, evaluate); /* recursive! */ if (**arg == ')') ++*arg; else if (ret == OK) --- 2705,2711 ---- * nested expression: (expression). */ case '(': *arg = skipwhite(*arg + 1); ! ret = eval1(arg, rettv, evaluate); // recursive! if (**arg == ')') ++*arg; else if (ret == OK) *************** *** 2735,2741 **** ret = FAIL; else { ! if (**arg == '(') /* recursive! */ ret = eval_func(arg, s, len, rettv, evaluate, NULL); else if (evaluate) ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE); --- 2735,2741 ---- ret = FAIL; else { ! if (**arg == '(') // recursive! ret = eval_func(arg, s, len, rettv, evaluate, NULL); else if (evaluate) ret = get_var_tv(s, len, rettv, NULL, TRUE, FALSE); *************** *** 2750,2757 **** *arg = skipwhite(*arg); ! /* Handle following '[', '(' and '.' for expr[expr], expr.name, ! * expr(expr), expr->name(expr) */ if (ret == OK) ret = handle_subscript(arg, rettv, evaluate, TRUE, start_leader, &end_leader); --- 2750,2757 ---- *arg = skipwhite(*arg); ! // Handle following '[', '(' and '.' for expr[expr], expr.name, ! // expr(expr), expr->name(expr) if (ret == OK) ret = handle_subscript(arg, rettv, evaluate, TRUE, start_leader, &end_leader); *************** *** 2853,2859 **** functv = *rettv; rettv->v_type = VAR_UNKNOWN; ! /* Invoke the function. Recursive! */ if (functv.v_type == VAR_PARTIAL) { pt = functv.vval.v_partial; --- 2853,2859 ---- functv = *rettv; rettv->v_type = VAR_UNKNOWN; ! // Invoke the function. Recursive! if (functv.v_type == VAR_PARTIAL) { pt = functv.vval.v_partial; *************** *** 2874,2881 **** funcexe.basetv = basetv; ret = get_func_tv(s, -1, rettv, arg, &funcexe); ! /* Clear the funcref afterwards, so that deleting it while ! * evaluating the arguments is possible (see test55). */ if (evaluate) clear_tv(&functv); --- 2874,2881 ---- funcexe.basetv = basetv; ret = get_func_tv(s, -1, rettv, arg, &funcexe); ! // Clear the funcref afterwards, so that deleting it while ! // evaluating the arguments is possible (see test55). if (evaluate) clear_tv(&functv); *************** *** 2892,2898 **** char_u **arg, typval_T *rettv, int evaluate, ! int verbose) /* give error messages */ { typval_T base = *rettv; int ret; --- 2892,2898 ---- char_u **arg, typval_T *rettv, int evaluate, ! int verbose) // give error messages { typval_T base = *rettv; int ret; *************** *** 2937,2943 **** char_u **arg, typval_T *rettv, int evaluate, ! int verbose) /* give error messages */ { char_u *name; long len; --- 2937,2943 ---- char_u **arg, typval_T *rettv, int evaluate, ! int verbose) // give error messages { char_u *name; long len; *************** *** 2996,3002 **** char_u **arg, typval_T *rettv, int evaluate, ! int verbose) /* give error messages */ { int empty1 = FALSE, empty2 = FALSE; typval_T var1, var2; --- 2996,3002 ---- char_u **arg, typval_T *rettv, int evaluate, ! int verbose) // give error messages { int empty1 = FALSE, empty2 = FALSE; typval_T var1, var2; *************** *** 3029,3035 **** case VAR_UNKNOWN: if (evaluate) return FAIL; ! /* FALLTHROUGH */ case VAR_STRING: case VAR_NUMBER: --- 3029,3035 ---- case VAR_UNKNOWN: if (evaluate) return FAIL; ! // FALLTHROUGH case VAR_STRING: case VAR_NUMBER: *************** *** 3063,3073 **** *arg = skipwhite(*arg + 1); if (**arg == ':') empty1 = TRUE; ! else if (eval1(arg, &var1, evaluate) == FAIL) /* recursive! */ return FAIL; else if (evaluate && tv_get_string_chk(&var1) == NULL) { ! /* not a number or string */ clear_tv(&var1); return FAIL; } --- 3063,3073 ---- *arg = skipwhite(*arg + 1); if (**arg == ':') empty1 = TRUE; ! else if (eval1(arg, &var1, evaluate) == FAIL) // recursive! return FAIL; else if (evaluate && tv_get_string_chk(&var1) == NULL) { ! // not a number or string clear_tv(&var1); return FAIL; } *************** *** 3081,3087 **** *arg = skipwhite(*arg + 1); if (**arg == ']') empty2 = TRUE; ! else if (eval1(arg, &var2, evaluate) == FAIL) /* recursive! */ { if (!empty1) clear_tv(&var1); --- 3081,3087 ---- *arg = skipwhite(*arg + 1); if (**arg == ']') empty2 = TRUE; ! else if (eval1(arg, &var2, evaluate) == FAIL) // recursive! { if (!empty1) clear_tv(&var1); *************** *** 3089,3095 **** } else if (evaluate && tv_get_string_chk(&var2) == NULL) { ! /* not a number or string */ if (!empty1) clear_tv(&var1); clear_tv(&var2); --- 3089,3095 ---- } else if (evaluate && tv_get_string_chk(&var2) == NULL) { ! // not a number or string if (!empty1) clear_tv(&var1); clear_tv(&var2); *************** *** 3097,3103 **** } } ! /* Check for the ']'. */ if (**arg != ']') { if (verbose) --- 3097,3103 ---- } } ! // Check for the ']'. if (**arg != ']') { if (verbose) *************** *** 3107,3113 **** clear_tv(&var2); return FAIL; } ! *arg = skipwhite(*arg + 1); /* skip the ']' */ } if (evaluate) --- 3107,3113 ---- clear_tv(&var2); return FAIL; } ! *arg = skipwhite(*arg + 1); // skip the ']' } if (evaluate) *************** *** 3138,3144 **** case VAR_SPECIAL: case VAR_JOB: case VAR_CHANNEL: ! break; /* not evaluating, skipping over subscript */ case VAR_NUMBER: case VAR_STRING: --- 3138,3144 ---- case VAR_SPECIAL: case VAR_JOB: case VAR_CHANNEL: ! break; // not evaluating, skipping over subscript case VAR_NUMBER: case VAR_STRING: *************** *** 3146,3153 **** len = (long)STRLEN(s); if (range) { ! /* The resulting variable is a substring. If the indexes ! * are out of range the result is empty. */ if (n1 < 0) { n1 = len + n1; --- 3146,3153 ---- len = (long)STRLEN(s); if (range) { ! // The resulting variable is a substring. If the indexes ! // are out of range the result is empty. if (n1 < 0) { n1 = len + n1; *************** *** 3165,3173 **** } else { ! /* The resulting variable is a string of a single ! * character. If the index is too big or negative the ! * result is empty. */ if (n1 >= len || n1 < 0) s = NULL; else --- 3165,3173 ---- } else { ! // The resulting variable is a string of a single ! // character. If the index is too big or negative the ! // result is empty. if (n1 >= len || n1 < 0) s = NULL; else *************** *** 3246,3253 **** n1 = len + n1; if (!empty1 && (n1 < 0 || n1 >= len)) { ! /* For a range we allow invalid values and return an empty ! * list. A list index out of range is an error. */ if (!range) { if (verbose) --- 3246,3253 ---- n1 = len + n1; if (!empty1 && (n1 < 0 || n1 >= len)) { ! // For a range we allow invalid values and return an empty ! // list. A list index out of range is an error. if (!range) { if (verbose) *************** *** 3342,3348 **** int get_option_tv( char_u **arg, ! typval_T *rettv, /* when NULL, only check if option exists */ int evaluate) { char_u *option_end; --- 3342,3348 ---- int get_option_tv( char_u **arg, ! typval_T *rettv, // when NULL, only check if option exists int evaluate) { char_u *option_end; *************** *** 3350,3356 **** char_u *stringval; int opt_type; int c; ! int working = (**arg == '+'); /* has("+option") */ int ret = OK; int opt_flags; --- 3350,3356 ---- char_u *stringval; int opt_type; int c; ! int working = (**arg == '+'); // has("+option") int ret = OK; int opt_flags; *************** *** 3376,3382 **** opt_type = get_option_value(*arg, &numval, rettv == NULL ? NULL : &stringval, opt_flags); ! if (opt_type == -3) /* invalid name */ { if (rettv != NULL) semsg(_("E113: Unknown option: %s"), *arg); --- 3376,3382 ---- opt_type = get_option_value(*arg, &numval, rettv == NULL ? NULL : &stringval, opt_flags); ! if (opt_type == -3) // invalid name { if (rettv != NULL) semsg(_("E113: Unknown option: %s"), *arg); *************** *** 3384,3405 **** } else if (rettv != NULL) { ! if (opt_type == -2) /* hidden string option */ { rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; } ! else if (opt_type == -1) /* hidden number option */ { rettv->v_type = VAR_NUMBER; rettv->vval.v_number = 0; } ! else if (opt_type == 1) /* number option */ { rettv->v_type = VAR_NUMBER; rettv->vval.v_number = numval; } ! else /* string option */ { rettv->v_type = VAR_STRING; rettv->vval.v_string = stringval; --- 3384,3405 ---- } else if (rettv != NULL) { ! if (opt_type == -2) // hidden string option { rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; } ! else if (opt_type == -1) // hidden number option { rettv->v_type = VAR_NUMBER; rettv->vval.v_number = 0; } ! else if (opt_type == 1) // number option { rettv->v_type = VAR_NUMBER; rettv->vval.v_number = numval; } ! else // string option { rettv->v_type = VAR_STRING; rettv->vval.v_string = stringval; *************** *** 3408,3414 **** else if (working && (opt_type == -2 || opt_type == -1)) ret = FAIL; ! *option_end = c; /* put back for error messages */ *arg = option_end; return ret; --- 3408,3414 ---- else if (working && (opt_type == -2 || opt_type == -1)) ret = FAIL; ! *option_end = c; // put back for error messages *arg = option_end; return ret; *************** *** 3433,3440 **** if (*p == '\\' && p[1] != NUL) { ++p; ! /* A "\" form occupies at least 4 characters, and produces up ! * to 6 characters: reserve space for 2 extra */ if (*p == '<') extra += 2; } --- 3433,3440 ---- if (*p == '\\' && p[1] != NUL) { ++p; ! // A "\" form occupies at least 4 characters, and produces up ! // to 6 characters: reserve space for 2 extra if (*p == '<') extra += 2; } *************** *** 3446,3452 **** return FAIL; } ! /* If only parsing, set *arg and return here */ if (!evaluate) { *arg = p + 1; --- 3446,3452 ---- return FAIL; } ! // If only parsing, set *arg and return here if (!evaluate) { *arg = p + 1; *************** *** 3476,3484 **** case 'r': *name++ = CAR; ++p; break; case 't': *name++ = TAB; ++p; break; ! case 'X': /* hex: "\x1", "\x12" */ case 'x': ! case 'u': /* Unicode: "\u0023" */ case 'U': if (vim_isxdigit(p[1])) { --- 3476,3484 ---- case 'r': *name++ = CAR; ++p; break; case 't': *name++ = TAB; ++p; break; ! case 'X': // hex: "\x1", "\x12" case 'x': ! case 'u': // Unicode: "\u0023" case 'U': if (vim_isxdigit(p[1])) { *************** *** 3498,3505 **** nr = (nr << 4) + hex2nr(*p); } ++p; ! /* For "\u" store the number according to ! * 'encoding'. */ if (c != 'X') name += (*mb_char2bytes)(nr, name); else --- 3498,3505 ---- nr = (nr << 4) + hex2nr(*p); } ++p; ! // For "\u" store the number according to ! // 'encoding'. if (c != 'X') name += (*mb_char2bytes)(nr, name); else *************** *** 3507,3513 **** } break; ! /* octal: "\1", "\12", "\123" */ case '0': case '1': case '2': --- 3507,3513 ---- } break; ! // octal: "\1", "\12", "\123" case '0': case '1': case '2': *************** *** 3525,3531 **** ++name; break; ! /* Special key, e.g.: "\" */ case '<': extra = trans_special(&p, name, TRUE, TRUE, TRUE, NULL); if (extra != 0) --- 3525,3531 ---- ++name; break; ! // Special key, e.g.: "\" case '<': extra = trans_special(&p, name, TRUE, TRUE, TRUE, NULL); if (extra != 0) *************** *** 3533,3539 **** name += extra; break; } ! /* FALLTHROUGH */ default: MB_COPY_CHAR(p, name); break; --- 3533,3539 ---- name += extra; break; } ! // FALLTHROUGH default: MB_COPY_CHAR(p, name); break; *************** *** 3544,3550 **** } *name = NUL; ! if (*p != NUL) /* just in case */ ++p; *arg = p; --- 3544,3550 ---- } *name = NUL; ! if (*p != NUL) // just in case ++p; *arg = p; *************** *** 3582,3588 **** return FAIL; } ! /* If only parsing return after setting "*arg" */ if (!evaluate) { *arg = p + 1; --- 3582,3588 ---- return FAIL; } ! // If only parsing return after setting "*arg" if (!evaluate) { *arg = p + 1; *************** *** 3661,3674 **** func_equal( typval_T *tv1, typval_T *tv2, ! int ic) /* ignore case */ { char_u *s1, *s2; dict_T *d1, *d2; int a1, a2; int i; ! /* empty and NULL function name considered the same */ s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string : partial_name(tv1->vval.v_partial); if (s1 != NULL && *s1 == NUL) --- 3661,3674 ---- func_equal( typval_T *tv1, typval_T *tv2, ! int ic) // ignore case { char_u *s1, *s2; dict_T *d1, *d2; int a1, a2; int i; ! // empty and NULL function name considered the same s1 = tv1->v_type == VAR_FUNC ? tv1->vval.v_string : partial_name(tv1->vval.v_partial); if (s1 != NULL && *s1 == NUL) *************** *** 3685,3691 **** else if (STRCMP(s1, s2) != 0) return FALSE; ! /* empty dict and NULL dict is different */ d1 = tv1->v_type == VAR_FUNC ? NULL : tv1->vval.v_partial->pt_dict; d2 = tv2->v_type == VAR_FUNC ? NULL : tv2->vval.v_partial->pt_dict; if (d1 == NULL || d2 == NULL) --- 3685,3691 ---- else if (STRCMP(s1, s2) != 0) return FALSE; ! // empty dict and NULL dict is different d1 = tv1->v_type == VAR_FUNC ? NULL : tv1->vval.v_partial->pt_dict; d2 = tv2->v_type == VAR_FUNC ? NULL : tv2->vval.v_partial->pt_dict; if (d1 == NULL || d2 == NULL) *************** *** 3696,3702 **** else if (!dict_equal(d1, d2, ic, TRUE)) return FALSE; ! /* empty list and no list considered the same */ a1 = tv1->v_type == VAR_FUNC ? 0 : tv1->vval.v_partial->pt_argc; a2 = tv2->v_type == VAR_FUNC ? 0 : tv2->vval.v_partial->pt_argc; if (a1 != a2) --- 3696,3702 ---- else if (!dict_equal(d1, d2, ic, TRUE)) return FALSE; ! // empty list and no list considered the same a1 = tv1->v_type == VAR_FUNC ? 0 : tv1->vval.v_partial->pt_argc; a2 = tv2->v_type == VAR_FUNC ? 0 : tv2->vval.v_partial->pt_argc; if (a1 != a2) *************** *** 3718,3737 **** tv_equal( typval_T *tv1, typval_T *tv2, ! int ic, /* ignore case */ ! int recursive) /* TRUE when used recursively */ { char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; char_u *s1, *s2; ! static int recursive_cnt = 0; /* catch recursive loops */ int r; ! /* Catch lists and dicts that have an endless loop by limiting ! * recursiveness to a limit. We guess they are equal then. ! * A fixed limit has the problem of still taking an awful long time. ! * Reduce the limit every time running into it. That should work fine for ! * deeply linked structures that are not recursively linked and catch ! * recursiveness quickly. */ if (!recursive) tv_equal_recurse_limit = 1000; if (recursive_cnt >= tv_equal_recurse_limit) --- 3718,3737 ---- tv_equal( typval_T *tv1, typval_T *tv2, ! int ic, // ignore case ! int recursive) // TRUE when used recursively { char_u buf1[NUMBUFLEN], buf2[NUMBUFLEN]; char_u *s1, *s2; ! static int recursive_cnt = 0; // catch recursive loops int r; ! // Catch lists and dicts that have an endless loop by limiting ! // recursiveness to a limit. We guess they are equal then. ! // A fixed limit has the problem of still taking an awful long time. ! // Reduce the limit every time running into it. That should work fine for ! // deeply linked structures that are not recursively linked and catch ! // recursiveness quickly. if (!recursive) tv_equal_recurse_limit = 1000; if (recursive_cnt >= tv_equal_recurse_limit) *************** *** 3740,3747 **** return TRUE; } ! /* For VAR_FUNC and VAR_PARTIAL compare the function name, bound dict and ! * arguments. */ if ((tv1->v_type == VAR_FUNC || (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL)) && (tv2->v_type == VAR_FUNC --- 3740,3747 ---- return TRUE; } ! // For VAR_FUNC and VAR_PARTIAL compare the function name, bound dict and ! // arguments. if ((tv1->v_type == VAR_FUNC || (tv1->v_type == VAR_PARTIAL && tv1->vval.v_partial != NULL)) && (tv2->v_type == VAR_FUNC *************** *** 3802,3809 **** break; } ! /* VAR_UNKNOWN can be the result of a invalid expression, let's say it ! * does not equal anything, not even itself. */ return FALSE; } --- 3802,3809 ---- break; } ! // VAR_UNKNOWN can be the result of a invalid expression, let's say it ! // does not equal anything, not even itself. return FALSE; } *************** *** 3855,3868 **** if (!testing) { ! /* Only do this once. */ want_garbage_collect = FALSE; may_garbage_collect = FALSE; garbage_collect_at_exit = FALSE; } ! /* We advance by two because we add one for items referenced through ! * previous_funccal. */ copyID = get_copyID(); /* --- 3855,3868 ---- if (!testing) { ! // Only do this once. want_garbage_collect = FALSE; may_garbage_collect = FALSE; garbage_collect_at_exit = FALSE; } ! // We advance by two because we add one for items referenced through ! // previous_funccal. copyID = get_copyID(); /* *************** *** 3870,3889 **** * with copyID. */ ! /* Don't free variables in the previous_funccal list unless they are only ! * referenced through previous_funccal. This must be first, because if ! * the item is referenced elsewhere the funccal must not be freed. */ abort = abort || set_ref_in_previous_funccal(copyID); ! /* script-local variables */ abort = abort || garbage_collect_scriptvars(copyID); ! /* buffer-local variables */ FOR_ALL_BUFFERS(buf) abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID, NULL, NULL); ! /* window-local variables */ FOR_ALL_TAB_WINDOWS(tp, wp) abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, NULL, NULL); --- 3870,3889 ---- * with copyID. */ ! // Don't free variables in the previous_funccal list unless they are only ! // referenced through previous_funccal. This must be first, because if ! // the item is referenced elsewhere the funccal must not be freed. abort = abort || set_ref_in_previous_funccal(copyID); ! // script-local variables abort = abort || garbage_collect_scriptvars(copyID); ! // buffer-local variables FOR_ALL_BUFFERS(buf) abort = abort || set_ref_in_item(&buf->b_bufvar.di_tv, copyID, NULL, NULL); ! // window-local variables FOR_ALL_TAB_WINDOWS(tp, wp) abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, NULL, NULL); *************** *** 3900,3922 **** NULL, NULL); #endif ! /* tabpage-local variables */ FOR_ALL_TABPAGES(tp) abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID, NULL, NULL); ! /* global variables */ abort = abort || garbage_collect_globvars(copyID); ! /* function-local variables */ abort = abort || set_ref_in_call_stack(copyID); ! /* named functions (matters for closures) */ abort = abort || set_ref_in_functions(copyID); ! /* function call arguments, if v:testing is set. */ abort = abort || set_ref_in_func_args(copyID); ! /* v: vars */ abort = abort || garbage_collect_vimvars(copyID); // callbacks in buffers --- 3900,3922 ---- NULL, NULL); #endif ! // tabpage-local variables FOR_ALL_TABPAGES(tp) abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID, NULL, NULL); ! // global variables abort = abort || garbage_collect_globvars(copyID); ! // function-local variables abort = abort || set_ref_in_call_stack(copyID); ! // named functions (matters for closures) abort = abort || set_ref_in_functions(copyID); ! // function call arguments, if v:testing is set. abort = abort || set_ref_in_func_args(copyID); ! // v: vars abort = abort || garbage_collect_vimvars(copyID); // callbacks in buffers *************** *** 3987,3995 **** { int did_free = FALSE; ! /* Let all "free" functions know that we are here. This means no ! * dictionaries, lists, channels or jobs are to be freed, because we will ! * do that here. */ in_free_unref_items = TRUE; /* --- 3987,3995 ---- { int did_free = FALSE; ! // Let all "free" functions know that we are here. This means no ! // dictionaries, lists, channels or jobs are to be freed, because we will ! // do that here. in_free_unref_items = TRUE; /* *************** *** 3997,4015 **** * themselves yet, so that it is possible to decrement refcount counters */ ! /* Go through the list of dicts and free items without the copyID. */ did_free |= dict_free_nonref(copyID); ! /* Go through the list of lists and free items without the copyID. */ did_free |= list_free_nonref(copyID); #ifdef FEAT_JOB_CHANNEL ! /* Go through the list of jobs and free items without the copyID. This ! * must happen before doing channels, because jobs refer to channels, but ! * the reference from the channel to the job isn't tracked. */ did_free |= free_unused_jobs_contents(copyID, COPYID_MASK); ! /* Go through the list of channels and free items without the copyID. */ did_free |= free_unused_channels_contents(copyID, COPYID_MASK); #endif --- 3997,4015 ---- * themselves yet, so that it is possible to decrement refcount counters */ ! // Go through the list of dicts and free items without the copyID. did_free |= dict_free_nonref(copyID); ! // Go through the list of lists and free items without the copyID. did_free |= list_free_nonref(copyID); #ifdef FEAT_JOB_CHANNEL ! // Go through the list of jobs and free items without the copyID. This ! // must happen before doing channels, because jobs refer to channels, but ! // the reference from the channel to the job isn't tracked. did_free |= free_unused_jobs_contents(copyID, COPYID_MASK); ! // Go through the list of channels and free items without the copyID. did_free |= free_unused_channels_contents(copyID, COPYID_MASK); #endif *************** *** 4020,4031 **** list_free_items(copyID); #ifdef FEAT_JOB_CHANNEL ! /* Go through the list of jobs and free items without the copyID. This ! * must happen before doing channels, because jobs refer to channels, but ! * the reference from the channel to the job isn't tracked. */ free_unused_jobs(copyID, COPYID_MASK); ! /* Go through the list of channels and free items without the copyID. */ free_unused_channels(copyID, COPYID_MASK); #endif --- 4020,4031 ---- list_free_items(copyID); #ifdef FEAT_JOB_CHANNEL ! // Go through the list of jobs and free items without the copyID. This ! // must happen before doing channels, because jobs refer to channels, but ! // the reference from the channel to the job isn't tracked. free_unused_jobs(copyID, COPYID_MASK); ! // Go through the list of channels and free items without the copyID. free_unused_channels(copyID, COPYID_MASK); #endif *************** *** 4055,4063 **** { if (!abort) { ! /* Mark each item in the hashtab. If the item contains a hashtab ! * it is added to ht_stack, if it contains a list it is added to ! * list_stack. */ todo = (int)cur_ht->ht_used; for (hi = cur_ht->ht_array; todo > 0; ++hi) if (!HASHITEM_EMPTY(hi)) --- 4055,4063 ---- { if (!abort) { ! // Mark each item in the hashtab. If the item contains a hashtab ! // it is added to ht_stack, if it contains a list it is added to ! // list_stack. todo = (int)cur_ht->ht_used; for (hi = cur_ht->ht_array; todo > 0; ++hi) if (!HASHITEM_EMPTY(hi)) *************** *** 4071,4077 **** if (ht_stack == NULL) break; ! /* take an item from the stack */ cur_ht = ht_stack->ht; tempitem = ht_stack; ht_stack = ht_stack->prev; --- 4071,4077 ---- if (ht_stack == NULL) break; ! // take an item from the stack cur_ht = ht_stack->ht; tempitem = ht_stack; ht_stack = ht_stack->prev; *************** *** 4130,4145 **** for (;;) { if (!abort) ! /* Mark each item in the list. If the item contains a hashtab ! * it is added to ht_stack, if it contains a list it is added to ! * list_stack. */ for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next) abort = abort || set_ref_in_item(&li->li_tv, copyID, ht_stack, &list_stack); if (list_stack == NULL) break; ! /* take an item from the stack */ cur_l = list_stack->list; tempitem = list_stack; list_stack = list_stack->prev; --- 4130,4145 ---- for (;;) { if (!abort) ! // Mark each item in the list. If the item contains a hashtab ! // it is added to ht_stack, if it contains a list it is added to ! // list_stack. for (li = cur_l->lv_first; !abort && li != NULL; li = li->li_next) abort = abort || set_ref_in_item(&li->li_tv, copyID, ht_stack, &list_stack); if (list_stack == NULL) break; ! // take an item from the stack cur_l = list_stack->list; tempitem = list_stack; list_stack = list_stack->prev; *************** *** 4171,4177 **** if (dd != NULL && dd->dv_copyID != copyID) { ! /* Didn't see this dict yet. */ dd->dv_copyID = copyID; if (ht_stack == NULL) { --- 4171,4177 ---- if (dd != NULL && dd->dv_copyID != copyID) { ! // Didn't see this dict yet. dd->dv_copyID = copyID; if (ht_stack == NULL) { *************** *** 4197,4203 **** if (ll != NULL && ll->lv_copyID != copyID) { ! /* Didn't see this list yet. */ ll->lv_copyID = copyID; if (list_stack == NULL) { --- 4197,4203 ---- if (ll != NULL && ll->lv_copyID != copyID) { ! // Didn't see this list yet. ll->lv_copyID = copyID; if (list_stack == NULL) { *************** *** 4227,4234 **** partial_T *pt = tv->vval.v_partial; int i; ! /* A partial does not have a copyID, because it cannot contain itself. ! */ if (pt != NULL) { abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID); --- 4227,4233 ---- partial_T *pt = tv->vval.v_partial; int i; ! // A partial does not have a copyID, because it cannot contain itself. if (pt != NULL) { abort = set_ref_in_func(pt->pt_name, pt->pt_func, copyID); *************** *** 4349,4357 **** { if (!did_echo_string_emsg) { ! /* Only give this message once for a recursive call to avoid ! * flooding the user with errors. And stop iterating over lists ! * and dicts. */ did_echo_string_emsg = TRUE; emsg(_("E724: variable nested too deep for displaying")); } --- 4348,4356 ---- { if (!did_echo_string_emsg) { ! // Only give this message once for a recursive call to avoid ! // flooding the user with errors. And stop iterating over lists ! // and dicts. did_echo_string_emsg = TRUE; emsg(_("E724: variable nested too deep for displaying")); } *************** *** 4612,4623 **** int string2float( char_u *text, ! float_T *value) /* result stored here */ { char *s = (char *)text; float_T f; ! /* MS-Windows does not deal with "inf" and "nan" properly. */ if (STRNICMP(text, "inf", 3) == 0) { *value = INFINITY; --- 4611,4622 ---- int string2float( char_u *text, ! float_T *value) // result stored here { char *s = (char *)text; float_T f; ! // MS-Windows does not deal with "inf" and "nan" properly. if (STRNICMP(text, "inf", 3) == 0) { *value = INFINITY; *************** *** 4660,4670 **** if (evaluate) { if (len == 0) ! return FAIL; /* invalid empty name */ cc = name[len]; name[len] = NUL; ! /* first try vim_getenv(), fast for normal environment vars */ string = vim_getenv(name, &mustfree); if (string != NULL && *string != NUL) { --- 4659,4669 ---- if (evaluate) { if (len == 0) ! return FAIL; // invalid empty name cc = name[len]; name[len] = NUL; ! // first try vim_getenv(), fast for normal environment vars string = vim_getenv(name, &mustfree); if (string != NULL && *string != NUL) { *************** *** 4676,4682 **** if (mustfree) vim_free(string); ! /* next try expanding things like $VIM and ${HOME} */ string = expand_env_save(name - 1); if (string != NULL && *string == '$') VIM_CLEAR(string); --- 4675,4681 ---- if (mustfree) vim_free(string); ! // next try expanding things like $VIM and ${HOME} string = expand_env_save(name - 1); if (string != NULL && *string == '$') VIM_CLEAR(string); *************** *** 4697,4710 **** pos_T * var2fpos( typval_T *varp, ! int dollar_lnum, /* TRUE when $ is last line */ ! int *fnum) /* set to fnum for '0, 'A, etc. */ { char_u *name; static pos_T pos; pos_T *pp; ! /* Argument can be [lnum, col, coladd]. */ if (varp->v_type == VAR_LIST) { list_T *l; --- 4696,4709 ---- pos_T * var2fpos( typval_T *varp, ! int dollar_lnum, // TRUE when $ is last line ! int *fnum) // set to fnum for '0, 'A, etc. { char_u *name; static pos_T pos; pos_T *pp; ! // Argument can be [lnum, col, coladd]. if (varp->v_type == VAR_LIST) { list_T *l; *************** *** 4716,4745 **** if (l == NULL) return NULL; ! /* Get the line number */ pos.lnum = list_find_nr(l, 0L, &error); if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count) ! return NULL; /* invalid line number */ ! /* Get the column number */ pos.col = list_find_nr(l, 1L, &error); if (error) return NULL; len = (long)STRLEN(ml_get(pos.lnum)); ! /* We accept "$" for the column number: last column. */ li = list_find(l, 1L); if (li != NULL && li->li_tv.v_type == VAR_STRING && li->li_tv.vval.v_string != NULL && STRCMP(li->li_tv.vval.v_string, "$") == 0) pos.col = len + 1; ! /* Accept a position up to the NUL after the line. */ if (pos.col == 0 || (int)pos.col > len + 1) ! return NULL; /* invalid column number */ --pos.col; ! /* Get the virtual offset. Defaults to zero. */ pos.coladd = list_find_nr(l, 2L, &error); if (error) pos.coladd = 0; --- 4715,4744 ---- if (l == NULL) return NULL; ! // Get the line number pos.lnum = list_find_nr(l, 0L, &error); if (error || pos.lnum <= 0 || pos.lnum > curbuf->b_ml.ml_line_count) ! return NULL; // invalid line number ! // Get the column number pos.col = list_find_nr(l, 1L, &error); if (error) return NULL; len = (long)STRLEN(ml_get(pos.lnum)); ! // We accept "$" for the column number: last column. li = list_find(l, 1L); if (li != NULL && li->li_tv.v_type == VAR_STRING && li->li_tv.vval.v_string != NULL && STRCMP(li->li_tv.vval.v_string, "$") == 0) pos.col = len + 1; ! // Accept a position up to the NUL after the line. if (pos.col == 0 || (int)pos.col > len + 1) ! return NULL; // invalid column number --pos.col; ! // Get the virtual offset. Defaults to zero. pos.coladd = list_find_nr(l, 2L, &error); if (error) pos.coladd = 0; *************** *** 4750,4764 **** name = tv_get_string_chk(varp); if (name == NULL) return NULL; ! if (name[0] == '.') /* cursor */ return &curwin->w_cursor; ! if (name[0] == 'v' && name[1] == NUL) /* Visual start */ { if (VIsual_active) return &VIsual; return &curwin->w_cursor; } ! if (name[0] == '\'') /* mark */ { pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) --- 4749,4763 ---- name = tv_get_string_chk(varp); if (name == NULL) return NULL; ! if (name[0] == '.') // cursor return &curwin->w_cursor; ! if (name[0] == 'v' && name[1] == NUL) // Visual start { if (VIsual_active) return &VIsual; return &curwin->w_cursor; } ! if (name[0] == '\'') // mark { pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) *************** *** 4771,4793 **** if (name[0] == 'w' && dollar_lnum) { pos.col = 0; ! if (name[1] == '0') /* "w0": first visible line */ { update_topline(); ! /* In silent Ex mode topline is zero, but that's not a valid line ! * number; use one instead. */ pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1; return &pos; } ! else if (name[1] == '$') /* "w$": last visible line */ { validate_botline(); ! /* In silent Ex mode botline is zero, return zero then. */ pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0; return &pos; } } ! else if (name[0] == '$') /* last column or line */ { if (dollar_lnum) { --- 4770,4792 ---- if (name[0] == 'w' && dollar_lnum) { pos.col = 0; ! if (name[1] == '0') // "w0": first visible line { update_topline(); ! // In silent Ex mode topline is zero, but that's not a valid line ! // number; use one instead. pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1; return &pos; } ! else if (name[1] == '$') // "w$": last visible line { validate_botline(); ! // In silent Ex mode botline is zero, return zero then. pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0; return &pos; } } ! else if (name[0] == '$') // last column or line { if (dollar_lnum) { *************** *** 4823,4830 **** long i = 0; long n; ! /* List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only ! * there when "fnump" isn't NULL; "coladd" and "curswant" are optional. */ if (arg->v_type != VAR_LIST || l == NULL || l->lv_len < (fnump == NULL ? 2 : 3) --- 4822,4829 ---- long i = 0; long n; ! // List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only ! // there when "fnump" isn't NULL; "coladd" and "curswant" are optional. if (arg->v_type != VAR_LIST || l == NULL || l->lv_len < (fnump == NULL ? 2 : 3) *************** *** 4833,4864 **** if (fnump != NULL) { ! n = list_find_nr(l, i++, NULL); /* fnum */ if (n < 0) return FAIL; if (n == 0) ! n = curbuf->b_fnum; /* current buffer */ *fnump = n; } ! n = list_find_nr(l, i++, NULL); /* lnum */ if (n < 0) return FAIL; posp->lnum = n; ! n = list_find_nr(l, i++, NULL); /* col */ if (n < 0) return FAIL; posp->col = n; ! n = list_find_nr(l, i, NULL); /* off */ if (n < 0) posp->coladd = 0; else posp->coladd = n; if (curswantp != NULL) ! *curswantp = list_find_nr(l, i + 1, NULL); /* curswant */ return OK; } --- 4832,4863 ---- if (fnump != NULL) { ! n = list_find_nr(l, i++, NULL); // fnum if (n < 0) return FAIL; if (n == 0) ! n = curbuf->b_fnum; // current buffer *fnump = n; } ! n = list_find_nr(l, i++, NULL); // lnum if (n < 0) return FAIL; posp->lnum = n; ! n = list_find_nr(l, i++, NULL); // col if (n < 0) return FAIL; posp->col = n; ! n = list_find_nr(l, i, NULL); // off if (n < 0) posp->coladd = 0; else posp->coladd = n; if (curswantp != NULL) ! *curswantp = list_find_nr(l, i + 1, NULL); // curswant return OK; } *************** *** 4876,4882 **** for (p = *arg; vim_isIDc(*p); ++p) ; ! if (p == *arg) /* no name found */ return 0; len = (int)(p - *arg); --- 4875,4881 ---- for (p = *arg; vim_isIDc(*p); ++p) ; ! if (p == *arg) // no name found return 0; len = (int)(p - *arg); *************** *** 4895,4914 **** char_u *p; int len; ! /* Find the end of the name. */ for (p = *arg; eval_isnamec(*p); ++p) { if (*p == ':') { ! /* "s:" is start of "s:var", but "n:" is not and can be used in ! * slice "[n:]". Also "xx:" is not a namespace. */ len = (int)(p - *arg); if ((len == 1 && vim_strchr(NAMESPACE_CHAR, **arg) == NULL) || len > 1) break; } } ! if (p == *arg) /* no name found */ return 0; len = (int)(p - *arg); --- 4894,4913 ---- char_u *p; int len; ! // Find the end of the name. for (p = *arg; eval_isnamec(*p); ++p) { if (*p == ':') { ! // "s:" is start of "s:var", but "n:" is not and can be used in ! // slice "[n:]". Also "xx:" is not a namespace. len = (int)(p - *arg); if ((len == 1 && vim_strchr(NAMESPACE_CHAR, **arg) == NULL) || len > 1) break; } } ! if (p == *arg) // no name found return 0; len = (int)(p - *arg); *************** *** 4938,4956 **** char_u *expr_start; char_u *expr_end; ! *alias = NULL; /* default to no alias */ if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA && (*arg)[2] == (int)KE_SNR) { ! /* hard coded , already translated */ *arg += 3; return get_id_len(arg) + 3; } len = eval_fname_script(*arg); if (len > 0) { ! /* literal "", "s:" or "" */ *arg += len; } --- 4937,4955 ---- char_u *expr_start; char_u *expr_end; ! *alias = NULL; // default to no alias if ((*arg)[0] == K_SPECIAL && (*arg)[1] == KS_EXTRA && (*arg)[2] == (int)KE_SNR) { ! // hard coded , already translated *arg += 3; return get_id_len(arg) + 3; } len = eval_fname_script(*arg); if (len > 0) { ! // literal "", "s:" or "" *arg += len; } *************** *** 5017,5023 **** *expr_end = NULL; } ! /* Quick check for valid starting character. */ if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg) && *arg != '{') return arg; --- 5016,5022 ---- *expr_end = NULL; } ! // Quick check for valid starting character. if ((flags & FNE_CHECK_START) && !eval_isnamec1(*arg) && *arg != '{') return arg; *************** *** 5030,5036 **** { if (*p == '\'') { ! /* skip over 'string' to avoid counting [ and ] inside it. */ for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) ; if (*p == NUL) --- 5029,5035 ---- { if (*p == '\'') { ! // skip over 'string' to avoid counting [ and ] inside it. for (p = p + 1; *p != NUL && *p != '\''; MB_PTR_ADV(p)) ; if (*p == NUL) *************** *** 5038,5044 **** } else if (*p == '"') { ! /* skip over "str\"ing" to avoid counting [ and ] inside it. */ for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) if (*p == '\\' && p[1] != NUL) ++p; --- 5037,5043 ---- } else if (*p == '"') { ! // skip over "str\"ing" to avoid counting [ and ] inside it. for (p = p + 1; *p != NUL && *p != '"'; MB_PTR_ADV(p)) if (*p == '\\' && p[1] != NUL) ++p; *************** *** 5047,5054 **** } else if (br_nest == 0 && mb_nest == 0 && *p == ':') { ! /* "s:" is start of "s:var", but "n:" is not and can be used in ! * slice "[n:]". Also "xx:" is not a namespace. But {ns}: is. */ len = (int)(p - arg); if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL) || (len > 1 && p[-1] != '}')) --- 5046,5053 ---- } else if (br_nest == 0 && mb_nest == 0 && *p == ':') { ! // "s:" is start of "s:var", but "n:" is not and can be used in ! // slice "[n:]". Also "xx:" is not a namespace. But {ns}: is. len = (int)(p - arg); if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL) || (len > 1 && p[-1] != '}')) *************** *** 5129,5135 **** } vim_free(temp_result); ! *in_end = c1; /* put char back for error messages */ *expr_start = '{'; *expr_end = '}'; --- 5128,5134 ---- } vim_free(temp_result); ! *in_end = c1; // put char back for error messages *expr_start = '{'; *expr_end = '}'; *************** *** 5138,5144 **** temp_result = find_name_end(retval, &expr_start, &expr_end, 0); if (expr_start != NULL) { ! /* Further expansion! */ temp_result = make_expanded_name(retval, expr_start, expr_end, temp_result); vim_free(retval); --- 5137,5143 ---- temp_result = find_name_end(retval, &expr_start, &expr_end, 0); if (expr_start != NULL) { ! // Further expansion! temp_result = make_expanded_name(retval, expr_start, expr_end, temp_result); vim_free(retval); *************** *** 5235,5241 **** ret = eval_method(arg, rettv, evaluate, verbose); } } ! else /* **arg == '[' || **arg == '.' */ { dict_unref(selfdict); if (rettv->v_type == VAR_DICT) --- 5234,5240 ---- ret = eval_method(arg, rettv, evaluate, verbose); } } ! else // **arg == '[' || **arg == '.' { dict_unref(selfdict); if (rettv->v_type == VAR_DICT) *************** *** 5254,5262 **** } } ! /* Turn "dict.Func" into a partial for "Func" bound to "dict". ! * Don't do this when "Func" is already a partial that was bound ! * explicitly (pt_auto is FALSE). */ if (selfdict != NULL && (rettv->v_type == VAR_FUNC || (rettv->v_type == VAR_PARTIAL --- 5253,5261 ---- } } ! // Turn "dict.Func" into a partial for "Func" bound to "dict". ! // Don't do this when "Func" is already a partial that was bound ! // explicitly (pt_auto is FALSE). if (selfdict != NULL && (rettv->v_type == VAR_FUNC || (rettv->v_type == VAR_PARTIAL *************** *** 5311,5317 **** { case VAR_FUNC: func_unref(varp->vval.v_string); ! /* FALLTHROUGH */ case VAR_STRING: vim_free(varp->vval.v_string); break; --- 5310,5316 ---- { case VAR_FUNC: func_unref(varp->vval.v_string); ! // FALLTHROUGH case VAR_STRING: vim_free(varp->vval.v_string); break; *************** *** 5359,5365 **** { case VAR_FUNC: func_unref(varp->vval.v_string); ! /* FALLTHROUGH */ case VAR_STRING: VIM_CLEAR(varp->vval.v_string); break; --- 5358,5364 ---- { case VAR_FUNC: func_unref(varp->vval.v_string); ! // FALLTHROUGH case VAR_STRING: VIM_CLEAR(varp->vval.v_string); break; *************** *** 5429,5435 **** { int error = FALSE; ! return tv_get_number_chk(varp, &error); /* return 0L on error */ } varnumber_T --- 5428,5434 ---- { int error = FALSE; ! return tv_get_number_chk(varp, &error); // return 0L on error } varnumber_T *************** *** 5481,5487 **** internal_error("tv_get_number(UNKNOWN)"); break; } ! if (denote == NULL) /* useful for values that must be unsigned */ n = -1; else *denote = TRUE; --- 5480,5486 ---- internal_error("tv_get_number(UNKNOWN)"); break; } ! if (denote == NULL) // useful for values that must be unsigned n = -1; else *denote = TRUE; *************** *** 5626,5632 **** (long)job->jv_proc_info.dwProcessId, status); # else ! /* fall-back */ vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status); # endif return buf; --- 5625,5631 ---- (long)job->jv_proc_info.dwProcessId, status); # else ! // fall-back vim_snprintf((char *)buf, NUMBUFLEN, "process ? %s", status); # endif return buf; *************** *** 5843,5849 **** to->vval.v_list = NULL; else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID) { ! /* use the copy made earlier */ to->vval.v_list = from->vval.v_list->lv_copylist; ++to->vval.v_list->lv_refcount; } --- 5842,5848 ---- to->vval.v_list = NULL; else if (copyID != 0 && from->vval.v_list->lv_copyID == copyID) { ! // use the copy made earlier to->vval.v_list = from->vval.v_list->lv_copylist; ++to->vval.v_list->lv_refcount; } *************** *** 5862,5868 **** to->vval.v_dict = NULL; else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID) { ! /* use the copy made earlier */ to->vval.v_dict = from->vval.v_dict->dv_copydict; ++to->vval.v_dict->dv_refcount; } --- 5861,5867 ---- to->vval.v_dict = NULL; else if (copyID != 0 && from->vval.v_dict->dv_copyID == copyID) { ! // use the copy made earlier to->vval.v_dict = from->vval.v_dict->dv_copydict; ++to->vval.v_dict->dv_refcount; } *************** *** 5901,5908 **** ++emsg_skip; while (*arg != NUL && *arg != '|' && *arg != '\n' && !got_int) { ! /* If eval1() causes an error message the text from the command may ! * still need to be cleared. E.g., "echo 22,44". */ need_clr_eos = needclr; p = arg; --- 5900,5907 ---- ++emsg_skip; while (*arg != NUL && *arg != '|' && *arg != '\n' && !got_int) { ! // If eval1() causes an error message the text from the command may ! // still need to be cleared. E.g., "echo 22,44". need_clr_eos = needclr; p = arg; *************** *** 5926,5938 **** if (atstart) { atstart = FALSE; ! /* Call msg_start() after eval1(), evaluating the expression ! * may cause a message to appear. */ if (eap->cmdidx == CMD_echo) { ! /* Mark the saved text as finishing the line, so that what ! * follows is displayed on a new line when scrolling back ! * at the more prompt. */ msg_sb_eol(); msg_start(); } --- 5925,5937 ---- if (atstart) { atstart = FALSE; ! // Call msg_start() after eval1(), evaluating the expression ! // may cause a message to appear. if (eap->cmdidx == CMD_echo) { ! // Mark the saved text as finishing the line, so that what ! // follows is displayed on a new line when scrolling back ! // at the more prompt. msg_sb_eol(); msg_start(); } *************** *** 5947,5953 **** { if (*p != TAB && needclr) { ! /* remove any text still there from the command */ msg_clr_eos(); needclr = FALSE; } --- 5946,5952 ---- { if (*p != TAB && needclr) { ! // remove any text still there from the command msg_clr_eos(); needclr = FALSE; } *************** *** 5977,5983 **** --emsg_skip; else { ! /* remove text that may still be there from the command */ if (needclr) msg_clr_eos(); if (eap->cmdidx == CMD_echo) --- 5976,5982 ---- --emsg_skip; else { ! // remove text that may still be there from the command if (needclr) msg_clr_eos(); if (eap->cmdidx == CMD_echo) *************** *** 6060,6068 **** { if (eap->cmdidx == CMD_echomsg || eap->cmdidx == CMD_echoerr) { ! /* Mark the already saved text as finishing the line, so that what ! * follows is displayed on a new line when scrolling back at the ! * more prompt. */ msg_sb_eol(); } --- 6059,6067 ---- { if (eap->cmdidx == CMD_echomsg || eap->cmdidx == CMD_echoerr) { ! // Mark the already saved text as finishing the line, so that what ! // follows is displayed on a new line when scrolling back at the ! // more prompt. msg_sb_eol(); } *************** *** 6073,6079 **** } else if (eap->cmdidx == CMD_echoerr) { ! /* We don't want to abort following commands, restore did_emsg. */ save_did_emsg = did_emsg; emsg(ga.ga_data); if (!force_abort) --- 6072,6078 ---- } else if (eap->cmdidx == CMD_echoerr) { ! // We don't want to abort following commands, restore did_emsg. save_did_emsg = did_emsg; emsg(ga.ga_data); if (!force_abort) *************** *** 6122,6128 **** *arg = p; if (p[0] == 't' && p[1] == '_' && p[2] != NUL && p[3] != NUL) ! p += 4; /* termcap option */ else while (ASCII_ISALPHA(*p)) ++p; --- 6121,6127 ---- *arg = p; if (p[0] == 't' && p[1] == '_' && p[2] != NUL && p[3] != NUL) ! p += 4; // termcap option else while (ASCII_ISALPHA(*p)) ++p; *************** *** 6162,6172 **** */ int typval_compare( ! typval_T *typ1, /* first operand */ ! typval_T *typ2, /* second operand */ ! exptype_T type, /* operator */ ! int type_is, /* TRUE for "is" and "isnot" */ ! int ic) /* ignore case */ { int i; varnumber_T n1, n2; --- 6161,6171 ---- */ int typval_compare( ! typval_T *typ1, // first operand ! typval_T *typ2, // second operand ! exptype_T type, // operator ! int type_is, // TRUE for "is" and "isnot" ! int ic) // ignore case { int i; varnumber_T n1, n2; *************** *** 6175,6182 **** if (type_is && typ1->v_type != typ2->v_type) { ! /* For "is" a different type always means FALSE, for "notis" ! * it means TRUE. */ n1 = (type == TYPE_NEQUAL); } else if (typ1->v_type == VAR_BLOB || typ2->v_type == VAR_BLOB) --- 6174,6181 ---- if (type_is && typ1->v_type != typ2->v_type) { ! // For "is" a different type always means FALSE, for "notis" ! // it means TRUE. n1 = (type == TYPE_NEQUAL); } else if (typ1->v_type == VAR_BLOB || typ2->v_type == VAR_BLOB) *************** *** 6227,6233 **** } else { ! /* Compare two Lists for being equal or unequal. */ n1 = list_equal(typ1->vval.v_list, typ2->vval.v_list, ic, FALSE); if (type == TYPE_NEQUAL) --- 6226,6232 ---- } else { ! // Compare two Lists for being equal or unequal. n1 = list_equal(typ1->vval.v_list, typ2->vval.v_list, ic, FALSE); if (type == TYPE_NEQUAL) *************** *** 6256,6262 **** } else { ! /* Compare two Dictionaries for being equal or unequal. */ n1 = dict_equal(typ1->vval.v_dict, typ2->vval.v_dict, ic, FALSE); if (type == TYPE_NEQUAL) --- 6255,6261 ---- } else { ! // Compare two Dictionaries for being equal or unequal. n1 = dict_equal(typ1->vval.v_dict, typ2->vval.v_dict, ic, FALSE); if (type == TYPE_NEQUAL) *************** *** 6277,6289 **** && typ1->vval.v_partial == NULL) || (typ2->v_type == VAR_PARTIAL && typ2->vval.v_partial == NULL)) ! /* when a partial is NULL assume not equal */ n1 = FALSE; else if (type_is) { if (typ1->v_type == VAR_FUNC && typ2->v_type == VAR_FUNC) ! /* strings are considered the same if their value is ! * the same */ n1 = tv_equal(typ1, typ2, ic, FALSE); else if (typ1->v_type == VAR_PARTIAL && typ2->v_type == VAR_PARTIAL) --- 6276,6288 ---- && typ1->vval.v_partial == NULL) || (typ2->v_type == VAR_PARTIAL && typ2->vval.v_partial == NULL)) ! // when a partial is NULL assume not equal n1 = FALSE; else if (type_is) { if (typ1->v_type == VAR_FUNC && typ2->v_type == VAR_FUNC) ! // strings are considered the same if their value is ! // the same n1 = tv_equal(typ1, typ2, ic, FALSE); else if (typ1->v_type == VAR_PARTIAL && typ2->v_type == VAR_PARTIAL) *************** *** 6320,6326 **** case TYPE_SEQUAL: n1 = (f1 <= f2); break; case TYPE_UNKNOWN: case TYPE_MATCH: ! case TYPE_NOMATCH: break; /* avoid gcc warning */ } } #endif --- 6319,6325 ---- case TYPE_SEQUAL: n1 = (f1 <= f2); break; case TYPE_UNKNOWN: case TYPE_MATCH: ! case TYPE_NOMATCH: break; // avoid gcc warning } } #endif *************** *** 6344,6350 **** case TYPE_SEQUAL: n1 = (n1 <= n2); break; case TYPE_UNKNOWN: case TYPE_MATCH: ! case TYPE_NOMATCH: break; /* avoid gcc warning */ } } else --- 6343,6349 ---- case TYPE_SEQUAL: n1 = (n1 <= n2); break; case TYPE_UNKNOWN: case TYPE_MATCH: ! case TYPE_NOMATCH: break; // avoid gcc warning } } else *************** *** 6372,6378 **** n1 = !n1; break; ! case TYPE_UNKNOWN: break; /* avoid gcc warning */ } } clear_tv(typ1); --- 6371,6377 ---- n1 = !n1; break; ! case TYPE_UNKNOWN: break; // avoid gcc warning } } clear_tv(typ1); *************** *** 6392,6398 **** if (arg == NULL) return vim_strsave((char_u *)"(does not exist)"); ret = tv2string(arg, &tofree, numbuf, 0); ! /* Make a copy if we have a value but it's not in allocated memory. */ if (ret != NULL && tofree == NULL) ret = vim_strsave(ret); return ret; --- 6391,6397 ---- if (arg == NULL) return vim_strsave((char_u *)"(does not exist)"); ret = tv2string(arg, &tofree, numbuf, 0); ! // Make a copy if we have a value but it's not in allocated memory. if (ret != NULL && tofree == NULL) ret = vim_strsave(ret); return ret; *************** *** 6425,6431 **** char_u *save_cpo; char_u *zero_width = NULL; ! /* Make 'cpoptions' empty, so that the 'l' flag doesn't work here */ save_cpo = p_cpo; p_cpo = empty_option; --- 6424,6430 ---- char_u *save_cpo; char_u *zero_width = NULL; ! // Make 'cpoptions' empty, so that the 'l' flag doesn't work here save_cpo = p_cpo; p_cpo = empty_option; *************** *** 6441,6452 **** end = str + STRLEN(str); while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) { ! /* Skip empty match except for first match. */ if (regmatch.startp[0] == regmatch.endp[0]) { if (zero_width == regmatch.startp[0]) { ! /* avoid getting stuck on a match with an empty string */ i = mb_ptr2len(tail); mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); --- 6440,6451 ---- end = str + STRLEN(str); while (vim_regexec_nl(®match, str, (colnr_T)(tail - str))) { ! // Skip empty match except for first match. if (regmatch.startp[0] == regmatch.endp[0]) { if (zero_width == regmatch.startp[0]) { ! // avoid getting stuck on a match with an empty string i = mb_ptr2len(tail); mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); *************** *** 6472,6481 **** break; } ! /* copy the text up to where the match is */ i = (int)(regmatch.startp[0] - tail); mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); ! /* add the substituted text */ (void)vim_regsub(®match, sub, expr, (char_u *)ga.ga_data + ga.ga_len + i, TRUE, TRUE, FALSE); ga.ga_len += i + sublen - 1; --- 6471,6480 ---- break; } ! // copy the text up to where the match is i = (int)(regmatch.startp[0] - tail); mch_memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); ! // add the substituted text (void)vim_regsub(®match, sub, expr, (char_u *)ga.ga_data + ga.ga_len + i, TRUE, TRUE, FALSE); ga.ga_len += i + sublen - 1; *************** *** 6497,6503 **** if (p_cpo == empty_option) p_cpo = save_cpo; else ! /* Darn, evaluating {sub} expression or {expr} changed the value. */ free_string_option(save_cpo); return ret; --- 6496,6502 ---- if (p_cpo == empty_option) p_cpo = save_cpo; else ! // Darn, evaluating {sub} expression or {expr} changed the value. free_string_option(save_cpo); return ret; *** ../vim-8.1.2377/src/evalbuffer.c 2019-11-30 22:47:42.643331239 +0100 --- src/evalbuffer.c 2019-12-01 21:07:58.806066016 +0100 *************** *** 825,831 **** restore_buffer(bufref_T *save_curbuf) { unblock_autocmds(); ! /* Check for valid buffer, just in case. */ if (bufref_valid(save_curbuf)) { --curbuf->b_nwindows; --- 825,831 ---- restore_buffer(bufref_T *save_curbuf) { unblock_autocmds(); ! // Check for valid buffer, just in case. if (bufref_valid(save_curbuf)) { --curbuf->b_nwindows; *** ../vim-8.1.2377/src/evalfunc.c 2019-11-30 22:47:42.643331239 +0100 --- src/evalfunc.c 2019-12-01 21:10:25.533463265 +0100 *************** *** 1290,1296 **** int size = split_message(msg, &array); int i; ! /* Skip the first and last item, they are always empty. */ for (i = 1; i < size - 1; ++i) list_append_string(rettv->vval.v_list, array[i].pum_text, -1); while (size > 0) --- 1290,1296 ---- int size = split_message(msg, &array); int i; ! // Skip the first and last item, they are always empty. for (i = 1; i < size - 1; ++i) list_append_string(rettv->vval.v_list, array[i].pum_text, -1); while (size > 0) *************** *** 1322,1328 **** buf = buflist_find_by_name(name, curtab_only); ! /* If not found, try expanding the name, like done for bufexists(). */ if (buf == NULL) buf = find_buffer(tv); --- 1322,1328 ---- buf = buflist_find_by_name(name, curtab_only); ! // If not found, try expanding the name, like done for bufexists(). if (buf == NULL) buf = find_buffer(tv); *************** *** 1357,1363 **** #else long boff = 0; ! boff = tv_get_number(&argvars[0]) - 1; /* boff gets -1 on type error */ if (boff < 0) rettv->vval.v_number = -1; else --- 1357,1363 ---- #else long boff = 0; ! boff = tv_get_number(&argvars[0]) - 1; // boff gets -1 on type error if (boff < 0) rettv->vval.v_number = -1; else *************** *** 1382,1388 **** t = str; for ( ; idx > 0; idx--) { ! if (*t == NUL) /* EOL reached */ return; if (enc_utf8 && comp) t += utf_ptr2len(t); --- 1382,1388 ---- t = str; for ( ; idx > 0; idx--) { ! if (*t == NUL) // EOL reached return; if (enc_utf8 && comp) t += utf_ptr2len(t); *************** *** 1438,1444 **** else func = tv_get_string(&argvars[0]); if (*func == NUL) ! return; /* type error or empty name */ if (argvars[2].v_type != VAR_UNKNOWN) { --- 1438,1444 ---- else func = tv_get_string(&argvars[0]); if (*func == NUL) ! return; // type error or empty name if (argvars[2].v_type != VAR_UNKNOWN) { *************** *** 1533,1539 **** { if (fp->col == MAXCOL) { ! /* '> can be MAXCOL, get the length of the line then */ if (fp->lnum <= curbuf->b_ml.ml_line_count) col = (colnr_T)STRLEN(ml_get(fp->lnum)) + 1; else --- 1533,1539 ---- { if (fp->col == MAXCOL) { ! // '> can be MAXCOL, get the length of the line then if (fp->lnum <= curbuf->b_ml.ml_line_count) col = (colnr_T)STRLEN(ml_get(fp->lnum)) + 1; else *************** *** 1542,1549 **** else { col = fp->col + 1; ! /* col(".") when the cursor is on the NUL at the end of the line ! * because of "coladd" can be seen as an extra column. */ if (virtual_active() && fp == &curwin->w_cursor) { char_u *p = ml_get_cursor(); --- 1542,1549 ---- else { col = fp->col + 1; ! // col(".") when the cursor is on the NUL at the end of the line ! // because of "coladd" can be seen as an extra column. if (virtual_active() && fp == &curwin->w_cursor) { char_u *p = ml_get_cursor(); *************** *** 1701,1716 **** coladd = (long)tv_get_number_chk(&argvars[2], NULL); } if (line < 0 || col < 0 || coladd < 0) ! return; /* type error; errmsg already given */ if (line > 0) curwin->w_cursor.lnum = line; if (col > 0) curwin->w_cursor.col = col - 1; curwin->w_cursor.coladd = coladd; ! /* Make sure the cursor is in a valid position. */ check_cursor(); ! /* Correct cursor for multi-byte character. */ if (has_mbyte) mb_adjust_cursor(); --- 1701,1716 ---- coladd = (long)tv_get_number_chk(&argvars[2], NULL); } if (line < 0 || col < 0 || coladd < 0) ! return; // type error; errmsg already given if (line > 0) curwin->w_cursor.lnum = line; if (col > 0) curwin->w_cursor.col = col - 1; curwin->w_cursor.coladd = coladd; ! // Make sure the cursor is in a valid position. check_cursor(); ! // Correct cursor for multi-byte character. if (has_mbyte) mb_adjust_cursor(); *************** *** 1949,1957 **** int len; if (value_len == -1) ! len = (int)STRLEN(value); /* Append the entire string */ else ! len = value_len; /* Append only "value_len" characters */ if (ga_grow(&redir_execute_ga, len) == OK) { mch_memmove((char *)redir_execute_ga.ga_data --- 1949,1957 ---- int len; if (value_len == -1) ! len = (int)STRLEN(value); // Append the entire string else ! len = value_len; // Append only "value_len" characters if (ga_grow(&redir_execute_ga, len) == OK) { mch_memmove((char *)redir_execute_ga.ga_data *************** *** 2009,2015 **** { list = argvars[arg_off].vval.v_list; if (list == NULL || list->lv_first == NULL) ! /* empty list, no commands, empty output */ return; ++list->lv_refcount; } --- 2009,2015 ---- { list = argvars[arg_off].vval.v_list; if (list == NULL || list->lv_first == NULL) ! // empty list, no commands, empty output return; ++list->lv_refcount; } *************** *** 2059,2065 **** --list->lv_refcount; } ! /* Need to append a NUL to the result. */ if (ga_grow(&redir_execute_ga, 1) == OK) { ((char *)redir_execute_ga.ga_data)[redir_execute_ga.ga_len] = NUL; --- 2059,2065 ---- --list->lv_refcount; } ! // Need to append a NUL to the result. if (ga_grow(&redir_execute_ga, 1) == OK) { ((char *)redir_execute_ga.ga_data)[redir_execute_ga.ga_len] = NUL; *************** *** 2109,2135 **** int n = FALSE; p = tv_get_string(&argvars[0]); ! if (*p == '$') /* environment variable */ { ! /* first try "normal" environment variables (fast) */ if (mch_getenv(p + 1) != NULL) n = TRUE; else { ! /* try expanding things like $VIM and ${HOME} */ p = expand_env_save(p); if (p != NULL && *p != '$') n = TRUE; vim_free(p); } } ! else if (*p == '&' || *p == '+') /* option */ { n = (get_option_tv(&p, NULL, TRUE) == OK); if (*skipwhite(p) != NUL) ! n = FALSE; /* trailing garbage */ } ! else if (*p == '*') /* internal or user defined function */ { n = function_exists(p + 1, FALSE); } --- 2109,2135 ---- int n = FALSE; p = tv_get_string(&argvars[0]); ! if (*p == '$') // environment variable { ! // first try "normal" environment variables (fast) if (mch_getenv(p + 1) != NULL) n = TRUE; else { ! // try expanding things like $VIM and ${HOME} p = expand_env_save(p); if (p != NULL && *p != '$') n = TRUE; vim_free(p); } } ! else if (*p == '&' || *p == '+') // option { n = (get_option_tv(&p, NULL, TRUE) == OK); if (*skipwhite(p) != NUL) ! n = FALSE; // trailing garbage } ! else if (*p == '*') // internal or user defined function { n = function_exists(p + 1, FALSE); } *************** *** 2144,2150 **** else n = au_exists(p + 1); } ! else /* internal variable */ { n = var_exists(p); } --- 2144,2150 ---- else n = au_exists(p + 1); } ! else // internal variable { n = var_exists(p); } *************** *** 2207,2214 **** } else { ! /* When the optional second argument is non-zero, don't remove matches ! * for 'wildignore' and don't put matches for 'suffixes' at the end. */ if (argvars[1].v_type != VAR_UNKNOWN && tv_get_number_chk(&argvars[1], &error)) options |= WILD_KEEP_ALL; --- 2207,2214 ---- } else { ! // When the optional second argument is non-zero, don't remove matches ! // for 'wildignore' and don't put matches for 'suffixes' at the end. if (argvars[1].v_type != VAR_UNKNOWN && tv_get_number_chk(&argvars[1], &error)) options |= WILD_KEEP_ALL; *************** *** 2281,2289 **** int lowlevel = FALSE; char_u *keys_esc; ! /* This is not allowed in the sandbox. If the commands would still be ! * executed in the sandbox it would be OK, but it probably happens later, ! * when "sandbox" is no longer set. */ if (check_secure()) return; --- 2281,2289 ---- int lowlevel = FALSE; char_u *keys_esc; ! // This is not allowed in the sandbox. If the commands would still be ! // executed in the sandbox it would be OK, but it probably happens later, ! // when "sandbox" is no longer set. if (check_secure()) return; *************** *** 2309,2316 **** if (*keys != NUL || execute) { ! /* Need to escape K_SPECIAL and CSI before putting the string in the ! * typeahead buffer. */ keys_esc = vim_strsave_escape_csi(keys); if (keys_esc != NULL) { --- 2309,2316 ---- if (*keys != NUL || execute) { ! // Need to escape K_SPECIAL and CSI before putting the string in the ! // typeahead buffer. keys_esc = vim_strsave_escape_csi(keys); if (keys_esc != NULL) { *************** *** 2339,2345 **** { int save_msg_scroll = msg_scroll; ! /* Avoid a 1 second delay when the keys start Insert mode. */ msg_scroll = FALSE; if (!dangerous) --- 2339,2345 ---- { int save_msg_scroll = msg_scroll; ! // Avoid a 1 second delay when the keys start Insert mode. msg_scroll = FALSE; if (!dangerous) *************** *** 2446,2464 **** if (argvars[0].v_type == VAR_FUNC) { ! /* function(MyFunc, [arg], dict) */ s = argvars[0].vval.v_string; } else if (argvars[0].v_type == VAR_PARTIAL && argvars[0].vval.v_partial != NULL) { ! /* function(dict.MyFunc, [arg]) */ arg_pt = argvars[0].vval.v_partial; s = partial_name(arg_pt); } else { ! /* function('MyFunc', [arg], dict) */ s = tv_get_string(&argvars[0]); use_string = TRUE; } --- 2446,2464 ---- if (argvars[0].v_type == VAR_FUNC) { ! // function(MyFunc, [arg], dict) s = argvars[0].vval.v_string; } else if (argvars[0].v_type == VAR_PARTIAL && argvars[0].vval.v_partial != NULL) { ! // function(dict.MyFunc, [arg]) arg_pt = argvars[0].vval.v_partial; s = partial_name(arg_pt); } else { ! // function('MyFunc', [arg], dict) s = tv_get_string(&argvars[0]); use_string = TRUE; } *************** *** 2475,2481 **** if (s == NULL || *s == NUL || (use_string && VIM_ISDIGIT(*s)) || (is_funcref && trans_name == NULL)) semsg(_(e_invarg2), use_string ? tv_get_string(&argvars[0]) : s); ! /* Don't check an autoload name for existence here. */ else if (trans_name != NULL && (is_funcref ? find_func(trans_name) == NULL : !translated_function_exists(trans_name))) --- 2475,2481 ---- if (s == NULL || *s == NUL || (use_string && VIM_ISDIGIT(*s)) || (is_funcref && trans_name == NULL)) semsg(_(e_invarg2), use_string ? tv_get_string(&argvars[0]) : s); ! // Don't check an autoload name for existence here. else if (trans_name != NULL && (is_funcref ? find_func(trans_name) == NULL : !translated_function_exists(trans_name))) *************** *** 2491,2500 **** char sid_buf[25]; int off = *s == 's' ? 2 : 5; ! /* Expand s: and into nr_, so that the function can ! * also be called from another script. Using trans_function_name() ! * would also work, but some plugins depend on the name being ! * printable text. */ sprintf(sid_buf, "%ld_", (long)current_sctx.sc_sid); name = alloc(STRLEN(sid_buf) + STRLEN(s + off) + 1); if (name != NULL) --- 2491,2500 ---- char sid_buf[25]; int off = *s == 's' ? 2 : 5; ! // Expand s: and into nr_, so that the function can ! // also be called from another script. Using trans_function_name() ! // would also work, but some plugins depend on the name being ! // printable text. sprintf(sid_buf, "%ld_", (long)current_sctx.sc_sid); name = alloc(STRLEN(sid_buf) + STRLEN(s + off) + 1); if (name != NULL) *************** *** 2510,2524 **** { if (argvars[2].v_type != VAR_UNKNOWN) { ! /* function(name, [args], dict) */ arg_idx = 1; dict_idx = 2; } else if (argvars[1].v_type == VAR_DICT) ! /* function(name, dict) */ dict_idx = 1; else ! /* function(name, [args]) */ arg_idx = 1; if (dict_idx > 0) { --- 2510,2524 ---- { if (argvars[2].v_type != VAR_UNKNOWN) { ! // function(name, [args], dict) arg_idx = 1; dict_idx = 2; } else if (argvars[1].v_type == VAR_DICT) ! // function(name, dict) dict_idx = 1; else ! // function(name, [args]) arg_idx = 1; if (dict_idx > 0) { *************** *** 2554,2560 **** { partial_T *pt = ALLOC_CLEAR_ONE(partial_T); ! /* result is a VAR_PARTIAL */ if (pt == NULL) vim_free(name); else --- 2554,2560 ---- { partial_T *pt = ALLOC_CLEAR_ONE(partial_T); ! // result is a VAR_PARTIAL if (pt == NULL) vim_free(name); else *************** *** 2586,2603 **** copy_tv(&li->li_tv, &pt->pt_argv[i++]); } ! /* For "function(dict.func, [], dict)" and "func" is a partial ! * use "dict". That is backwards compatible. */ if (dict_idx > 0) { ! /* The dict is bound explicitly, pt_auto is FALSE. */ pt->pt_dict = argvars[dict_idx].vval.v_dict; ++pt->pt_dict->dv_refcount; } else if (arg_pt != NULL) { ! /* If the dict was bound automatically the result is also ! * bound automatically. */ pt->pt_dict = arg_pt->pt_dict; pt->pt_auto = arg_pt->pt_auto; if (pt->pt_dict != NULL) --- 2586,2603 ---- copy_tv(&li->li_tv, &pt->pt_argv[i++]); } ! // For "function(dict.func, [], dict)" and "func" is a partial ! // use "dict". That is backwards compatible. if (dict_idx > 0) { ! // The dict is bound explicitly, pt_auto is FALSE. pt->pt_dict = argvars[dict_idx].vval.v_dict; ++pt->pt_dict->dv_refcount; } else if (arg_pt != NULL) { ! // If the dict was bound automatically the result is also ! // bound automatically. pt->pt_dict = arg_pt->pt_dict; pt->pt_auto = arg_pt->pt_auto; if (pt->pt_dict != NULL) *************** *** 2628,2634 **** } else { ! /* result is a VAR_FUNC */ rettv->v_type = VAR_FUNC; rettv->vval.v_string = name; func_ref(name); --- 2628,2634 ---- } else { ! // result is a VAR_FUNC rettv->v_type = VAR_FUNC; rettv->vval.v_string = name; func_ref(name); *************** *** 2662,2669 **** static void f_garbagecollect(typval_T *argvars, typval_T *rettv UNUSED) { ! /* This is postponed until we are back at the toplevel, because we may be ! * using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". */ want_garbage_collect = TRUE; if (argvars[0].v_type != VAR_UNKNOWN && tv_get_number(&argvars[0]) == 1) --- 2662,2669 ---- static void f_garbagecollect(typval_T *argvars, typval_T *rettv UNUSED) { ! // This is postponed until we are back at the toplevel, because we may be ! // using Lists and Dicts internally. E.g.: ":echo [garbagecollect()]". want_garbage_collect = TRUE; if (argvars[0].v_type != VAR_UNKNOWN && tv_get_number(&argvars[0]) == 1) *************** *** 2922,2940 **** if (argvars[0].v_type == VAR_UNKNOWN) { ! /* Get the "Normal" font. Either the name saved by ! * hl_set_font_name() or from the font ID. */ font = gui.norm_font; name = hl_get_font_name(); } else { name = tv_get_string(&argvars[0]); ! if (STRCMP(name, "*") == 0) /* don't use font dialog */ return; font = gui_mch_get_font(name, FALSE); if (font == NOFONT) ! return; /* Invalid font name, return empty string. */ } rettv->vval.v_string = gui_mch_get_fontname(font, name); if (argvars[0].v_type != VAR_UNKNOWN) --- 2922,2940 ---- if (argvars[0].v_type == VAR_UNKNOWN) { ! // Get the "Normal" font. Either the name saved by ! // hl_set_font_name() or from the font ID. font = gui.norm_font; name = hl_get_font_name(); } else { name = tv_get_string(&argvars[0]); ! if (STRCMP(name, "*") == 0) // don't use font dialog return; font = gui_mch_get_font(name, FALSE); if (font == NOFONT) ! return; // Invalid font name, return empty string. } rettv->vval.v_string = gui_mch_get_fontname(font, name); if (argvars[0].v_type != VAR_UNKNOWN) *************** *** 3137,3143 **** if (argvars[0].v_type != VAR_UNKNOWN) { strregname = tv_get_string_chk(&argvars[0]); ! if (strregname == NULL) /* type error; errmsg already given */ { rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; --- 3137,3143 ---- if (argvars[0].v_type != VAR_UNKNOWN) { strregname = tv_get_string_chk(&argvars[0]); ! if (strregname == NULL) // type error; errmsg already given { rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; *************** *** 3145,3151 **** } } else ! /* Default to v:register */ strregname = get_vim_var_str(VV_REG); regname = (strregname == NULL ? '"' : *strregname); --- 3145,3151 ---- } } else ! // Default to v:register strregname = get_vim_var_str(VV_REG); regname = (strregname == NULL ? '"' : *strregname); *************** *** 3188,3194 **** get_tagstack(wp, rettv->vval.v_dict); } ! /* for VIM_VERSION_ defines */ #include "version.h" /* --- 3188,3194 ---- get_tagstack(wp, rettv->vval.v_dict); } ! // for VIM_VERSION_ defines #include "version.h" /* *************** *** 3221,3231 **** "linux", #endif #ifdef MACOS_X ! "mac", /* Mac OS X (and, once, Mac OS Classic) */ ! "osx", /* Mac OS X */ # ifdef MACOS_X_DARWIN ! "macunix", /* Mac OS X, with the darwin feature */ ! "osxdarwin", /* synonym for macunix */ # endif #endif #ifdef __QNX__ --- 3221,3231 ---- "linux", #endif #ifdef MACOS_X ! "mac", // Mac OS X (and, once, Mac OS Classic) ! "osx", // Mac OS X # ifdef MACOS_X_DARWIN ! "macunix", // Mac OS X, with the darwin feature ! "osxdarwin", // synonym for macunix # endif #endif #ifdef __QNX__ *************** *** 3272,3278 **** #endif #ifdef FEAT_BEVAL_GUI "balloon_eval", ! # ifndef FEAT_GUI_MSWIN /* other GUIs always have multiline balloons */ "balloon_multiline", # endif #endif --- 3272,3278 ---- #endif #ifdef FEAT_BEVAL_GUI "balloon_eval", ! # ifndef FEAT_GUI_MSWIN // other GUIs always have multiline balloons "balloon_multiline", # endif #endif *************** *** 3347,3354 **** #ifdef FEAT_EMACS_TAGS "emacs_tags", #endif ! "eval", /* always present, of course! */ ! "ex_extra", /* graduated feature */ #ifdef FEAT_SEARCH_EXTRA "extra_search", #endif --- 3347,3354 ---- #ifdef FEAT_EMACS_TAGS "emacs_tags", #endif ! "eval", // always present, of course! ! "ex_extra", // graduated feature #ifdef FEAT_SEARCH_EXTRA "extra_search", #endif *************** *** 3422,3428 **** #ifdef FEAT_KEYMAP "keymap", #endif ! "lambda", /* always with FEAT_EVAL, since 7.4.2120 with closure */ #ifdef FEAT_LANGMAP "langmap", #endif --- 3422,3428 ---- #ifdef FEAT_KEYMAP "keymap", #endif ! "lambda", // always with FEAT_EVAL, since 7.4.2120 with closure #ifdef FEAT_LANGMAP "langmap", #endif *************** *** 3629,3635 **** #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) "unnamedplus", #endif ! "user-commands", /* was accidentally included in 5.4 */ "user_commands", #ifdef FEAT_VARTABS "vartabs", --- 3629,3635 ---- #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) "unnamedplus", #endif ! "user-commands", // was accidentally included in 5.4 "user_commands", #ifdef FEAT_VARTABS "vartabs", *************** *** 3670,3676 **** #endif #ifdef FEAT_XPM_W32 "xpm", ! "xpm_w32", /* for backward compatibility */ #else # if defined(HAVE_XPM) "xpm", --- 3670,3676 ---- #endif #ifdef FEAT_XPM_W32 "xpm", ! "xpm_w32", // for backward compatibility #else # if defined(HAVE_XPM) "xpm", *************** *** 3715,3721 **** int major = atoi((char *)name + 6); int minor = atoi((char *)name + 8); ! /* Expect "patch-9.9.01234". */ n = (major < VIM_VERSION_MAJOR || (major == VIM_VERSION_MAJOR && (minor < VIM_VERSION_MINOR --- 3715,3721 ---- int major = atoi((char *)name + 6); int minor = atoi((char *)name + 8); ! // Expect "patch-9.9.01234". n = (major < VIM_VERSION_MAJOR || (major == VIM_VERSION_MAJOR && (minor < VIM_VERSION_MINOR *************** *** 3791,3797 **** n = (gui.in_use || gui.starting); # ifdef FEAT_BROWSE else if (STRICMP(name, "browse") == 0) ! n = gui.in_use; /* gui_mch_browse() works when GUI is running */ # endif #endif #ifdef FEAT_SYN_HL --- 3791,3797 ---- n = (gui.in_use || gui.starting); # ifdef FEAT_BROWSE else if (STRICMP(name, "browse") == 0) ! n = gui.in_use; // gui_mch_browse() works when GUI is running # endif #endif #ifdef FEAT_SYN_HL *************** *** 3929,3935 **** vimconv.vc_type = CONV_NONE; convert_setup(&vimconv, from, to); ! /* If the encodings are equal, no conversion needed. */ if (vimconv.vc_type == CONV_NONE) rettv->vval.v_string = vim_strsave(str); else --- 3929,3935 ---- vimconv.vc_type = CONV_NONE; convert_setup(&vimconv, from, to); ! // If the encodings are equal, no conversion needed. if (vimconv.vc_type == CONV_NONE) rettv->vval.v_string = vim_strsave(str); else *************** *** 3999,4006 **** item = l->lv_first; if (argvars[2].v_type != VAR_UNKNOWN) { ! /* Start at specified item. Use the cached index that list_find() ! * sets, so that a negative number also works. */ item = list_find(l, (long)tv_get_number_chk(&argvars[2], &error)); idx = l->lv_idx; if (argvars[3].v_type != VAR_UNKNOWN) --- 3999,4006 ---- item = l->lv_first; if (argvars[2].v_type != VAR_UNKNOWN) { ! // Start at specified item. Use the cached index that list_find() ! // sets, so that a negative number also works. item = list_find(l, (long)tv_get_number_chk(&argvars[2], &error)); idx = l->lv_idx; if (argvars[3].v_type != VAR_UNKNOWN) *************** *** 4037,4043 **** f_inputdialog(typval_T *argvars, typval_T *rettv) { #if defined(FEAT_GUI_TEXTDIALOG) ! /* Use a GUI dialog if the GUI is running and 'c' is not in 'guioptions' */ if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) { char_u *message; --- 4037,4043 ---- f_inputdialog(typval_T *argvars, typval_T *rettv) { #if defined(FEAT_GUI_TEXTDIALOG) ! // Use a GUI dialog if the GUI is running and 'c' is not in 'guioptions' if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) { char_u *message; *************** *** 4082,4089 **** int mouse_used; #ifdef NO_CONSOLE_INPUT ! /* While starting up, there is no place to enter text. When running tests ! * with --not-a-term we assume feedkeys() will be used. */ if (no_console_input() && !is_not_a_term()) return; #endif --- 4082,4089 ---- int mouse_used; #ifdef NO_CONSOLE_INPUT ! // While starting up, there is no place to enter text. When running tests ! // with --not-a-term we assume feedkeys() will be used. if (no_console_input() && !is_not_a_term()) return; #endif *************** *** 4094,4101 **** } msg_start(); ! msg_row = Rows - 1; /* for when 'cmdheight' > 1 */ ! lines_left = Rows; /* avoid more prompt */ msg_scroll = TRUE; msg_clr_eos(); --- 4094,4101 ---- } msg_start(); ! msg_row = Rows - 1; // for when 'cmdheight' > 1 ! lines_left = Rows; // avoid more prompt msg_scroll = TRUE; msg_clr_eos(); *************** *** 4105,4111 **** msg_putchar('\n'); } ! /* Ask for choice. */ selected = prompt_for_number(&mouse_used); if (mouse_used) selected -= lines_left; --- 4105,4111 ---- msg_putchar('\n'); } ! // Ask for choice. selected = prompt_for_number(&mouse_used); if (mouse_used) selected -= lines_left; *************** *** 4126,4137 **** --ga_userinput.ga_len; restore_typeahead((tasave_T *)(ga_userinput.ga_data) + ga_userinput.ga_len); ! /* default return is zero == OK */ } else if (p_verbose > 1) { verb_msg(_("called inputrestore() more often than inputsave()")); ! rettv->vval.v_number = 1; /* Failed */ } } --- 4126,4137 ---- --ga_userinput.ga_len; restore_typeahead((tasave_T *)(ga_userinput.ga_data) + ga_userinput.ga_len); ! // default return is zero == OK } else if (p_verbose > 1) { verb_msg(_("called inputrestore() more often than inputsave()")); ! rettv->vval.v_number = 1; // Failed } } *************** *** 4141,4156 **** static void f_inputsave(typval_T *argvars UNUSED, typval_T *rettv) { ! /* Add an entry to the stack of typeahead storage. */ if (ga_grow(&ga_userinput, 1) == OK) { save_typeahead((tasave_T *)(ga_userinput.ga_data) + ga_userinput.ga_len); ++ga_userinput.ga_len; ! /* default return is zero == OK */ } else ! rettv->vval.v_number = 1; /* Failed */ } /* --- 4141,4156 ---- static void f_inputsave(typval_T *argvars UNUSED, typval_T *rettv) { ! // Add an entry to the stack of typeahead storage. if (ga_grow(&ga_userinput, 1) == OK) { save_typeahead((tasave_T *)(ga_userinput.ga_data) + ga_userinput.ga_len); ++ga_userinput.ga_len; ! // default return is zero == OK } else ! rettv->vval.v_number = 1; // Failed } /* *************** *** 4224,4234 **** di = find_var(lv.ll_name, NULL, TRUE); if (di != NULL) { ! /* Consider a variable locked when: ! * 1. the variable itself is locked ! * 2. the value of the variable is locked. ! * 3. the List or Dict value is locked. ! */ rettv->vval.v_number = ((di->di_flags & DI_FLAGS_LOCK) || tv_islocked(&di->di_tv)); } --- 4224,4233 ---- di = find_var(lv.ll_name, NULL, TRUE); if (di != NULL) { ! // Consider a variable locked when: ! // 1. the variable itself is locked ! // 2. the value of the variable is locked. ! // 3. the List or Dict value is locked. rettv->vval.v_number = ((di->di_flags & DI_FLAGS_LOCK) || tv_islocked(&di->di_tv)); } *************** *** 4238,4247 **** else if (lv.ll_newkey != NULL) semsg(_(e_dictkey), lv.ll_newkey); else if (lv.ll_list != NULL) ! /* List item. */ rettv->vval.v_number = tv_islocked(&lv.ll_li->li_tv); else ! /* Dictionary item. */ rettv->vval.v_number = tv_islocked(&lv.ll_di->di_tv); } } --- 4237,4246 ---- else if (lv.ll_newkey != NULL) semsg(_(e_dictkey), lv.ll_newkey); else if (lv.ll_list != NULL) ! // List item. rettv->vval.v_number = tv_islocked(&lv.ll_li->li_tv); else ! // Dictionary item. rettv->vval.v_number = tv_islocked(&lv.ll_di->di_tv); } } *************** *** 4338,4344 **** return; #ifdef FEAT_LIBCALL ! /* The first two args must be strings, otherwise it's meaningless */ if (argvars[0].v_type == VAR_STRING && argvars[1].v_type == VAR_STRING) { string_in = NULL; --- 4337,4343 ---- return; #ifdef FEAT_LIBCALL ! // The first two args must be strings, otherwise it's meaningless if (argvars[0].v_type == VAR_STRING && argvars[1].v_type == VAR_STRING) { string_in = NULL; *************** *** 4518,4528 **** typedef enum { ! MATCH_END, /* matchend() */ ! MATCH_MATCH, /* match() */ ! MATCH_STR, /* matchstr() */ ! MATCH_LIST, /* matchlist() */ ! MATCH_POS /* matchstrpos() */ } matchtype_T; static void --- 4517,4527 ---- typedef enum { ! MATCH_END, // matchend() ! MATCH_MATCH, // match() ! MATCH_STR, // matchstr() ! MATCH_LIST, // matchlist() ! MATCH_POS // matchstrpos() } matchtype_T; static void *************** *** 4545,4559 **** long idx = 0; char_u *tofree = NULL; ! /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ save_cpo = p_cpo; p_cpo = (char_u *)""; rettv->vval.v_number = -1; if (type == MATCH_LIST || type == MATCH_POS) { ! /* type MATCH_LIST: return empty list when there are no matches. ! * type MATCH_POS: return ["", -1, -1, -1] */ if (rettv_list_alloc(rettv) == FAIL) goto theend; if (type == MATCH_POS --- 4544,4558 ---- long idx = 0; char_u *tofree = NULL; ! // Make 'cpoptions' empty, the 'l' flag should not be used here. save_cpo = p_cpo; p_cpo = (char_u *)""; rettv->vval.v_number = -1; if (type == MATCH_LIST || type == MATCH_POS) { ! // type MATCH_LIST: return empty list when there are no matches. ! // type MATCH_POS: return ["", -1, -1, -1] if (rettv_list_alloc(rettv) == FAIL) goto theend; if (type == MATCH_POS *************** *** 4605,4611 **** li = list_find(l, start); if (li == NULL) goto theend; ! idx = l->lv_idx; /* use the cached index */ } else { --- 4604,4610 ---- li = list_find(l, start); if (li == NULL) goto theend; ! idx = l->lv_idx; // use the cached index } else { *************** *** 4613,4621 **** start = 0; if (start > len) goto theend; ! /* When "count" argument is there ignore matches before "start", ! * otherwise skip part of the string. Differs when pattern is "^" ! * or "\<". */ if (argvars[3].v_type != VAR_UNKNOWN) startcol = start; else --- 4612,4620 ---- start = 0; if (start > len) goto theend; ! // When "count" argument is there ignore matches before "start", ! // otherwise skip part of the string. Differs when pattern is "^" ! // or "\<". if (argvars[3].v_type != VAR_UNKNOWN) startcol = start; else *************** *** 4658,4664 **** if (l == NULL && !match) break; ! /* Advance to just after the match. */ if (l != NULL) { li = li->li_next; --- 4657,4663 ---- if (l == NULL && !match) break; ! // Advance to just after the match. if (l != NULL) { li = li->li_next; *************** *** 4700,4706 **** { int i; ! /* return list with matched string and submatches */ for (i = 0; i < NSUBEXP; ++i) { if (regmatch.endp[i] == NULL) --- 4699,4705 ---- { int i; ! // return list with matched string and submatches for (i = 0; i < NSUBEXP; ++i) { if (regmatch.endp[i] == NULL) *************** *** 4718,4724 **** } else if (type == MATCH_STR) { ! /* return matched string */ if (l != NULL) copy_tv(&li->li_tv, rettv); else --- 4717,4723 ---- } else if (type == MATCH_STR) { ! // return matched string if (l != NULL) copy_tv(&li->li_tv, rettv); else *************** *** 4743,4749 **** theend: if (type == MATCH_POS && l == NULL && rettv->vval.v_list != NULL) ! /* matchstrpos() without a list: drop the second item. */ listitem_remove(rettv->vval.v_list, rettv->vval.v_list->lv_first->li_next); vim_free(tofree); --- 4742,4748 ---- theend: if (type == MATCH_POS && l == NULL && rettv->vval.v_list != NULL) ! // matchstrpos() without a list: drop the second item. listitem_remove(rettv->vval.v_list, rettv->vval.v_list->lv_first->li_next); vim_free(tofree); *************** *** 5016,5025 **** rettv->vval.v_number = lnum; } ! /* This dummy va_list is here because: ! * - passing a NULL pointer doesn't work when va_list isn't a pointer ! * - locally in the function results in a "used before set" warning ! * - using va_start() to initialize it gives "function with fixed args" error */ static va_list ap; /* --- 5015,5024 ---- rettv->vval.v_number = lnum; } ! // This dummy va_list is here because: ! // - passing a NULL pointer doesn't work when va_list isn't a pointer ! // - locally in the function results in a "used before set" warning ! // - using va_start() to initialize it gives "function with fixed args" error static va_list ap; /* *************** *** 5037,5043 **** rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; ! /* Get the required length, allocate the buffer and do it for real. */ did_emsg = FALSE; fmt = (char *)tv_get_string_buf(&argvars[0], buf); len = vim_vsnprintf_typval(NULL, 0, fmt, ap, argvars + 1); --- 5036,5042 ---- rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; ! // Get the required length, allocate the buffer and do it for real. did_emsg = FALSE; fmt = (char *)tv_get_string_buf(&argvars[0], buf); len = vim_vsnprintf_typval(NULL, 0, fmt, ap, argvars + 1); *************** *** 5244,5250 **** } if (error) ! return; /* type error; errmsg already given */ if (stride == 0) emsg(_("E726: Stride is zero")); else if (stride > 0 ? end + 1 < start : end - 1 > start) --- 5243,5249 ---- } if (error) ! return; // type error; errmsg already given if (stride == 0) emsg(_("E726: Stride is zero")); else if (stride > 0 ? end + 1 < start : end - 1 > start) *************** *** 5312,5318 **** # endif return error ? FAIL : OK; } ! #endif /* FEAT_RELTIME */ /* * "reltime()" function --- 5311,5317 ---- # endif return error ? FAIL : OK; } ! #endif // FEAT_RELTIME /* * "reltime()" function *************** *** 5326,5332 **** if (argvars[0].v_type == VAR_UNKNOWN) { ! /* No arguments: get current time. */ profile_start(&res); } else if (argvars[1].v_type == VAR_UNKNOWN) --- 5325,5331 ---- if (argvars[0].v_type == VAR_UNKNOWN) { ! // No arguments: get current time. profile_start(&res); } else if (argvars[1].v_type == VAR_UNKNOWN) *************** *** 5337,5343 **** } else { ! /* Two arguments: compute the difference. */ if (list2proftime(&argvars[0], &start) == FAIL || list2proftime(&argvars[1], &res) == FAIL) return; --- 5336,5342 ---- } else { ! // Two arguments: compute the difference. if (list2proftime(&argvars[0], &start) == FAIL || list2proftime(&argvars[1], &res) == FAIL) return; *************** *** 5456,5462 **** server_name = tv_get_string_chk(&argvars[0]); if (server_name == NULL) ! return; /* type error; errmsg already given */ keys = tv_get_string_buf(&argvars[1], buf); # ifdef MSWIN if (serverSendToVim(server_name, keys, &r, &w, expr, timeout, TRUE) < 0) --- 5455,5461 ---- server_name = tv_get_string_chk(&argvars[0]); if (server_name == NULL) ! return; // type error; errmsg already given keys = tv_get_string_buf(&argvars[1], buf); # ifdef MSWIN if (serverSendToVim(server_name, keys, &r, &w, expr, timeout, TRUE) < 0) *************** *** 5517,5523 **** { #ifdef FEAT_CLIENTSERVER # ifdef MSWIN ! /* On Win32 it's done in this application. */ { char_u *server_name = tv_get_string_chk(&argvars[0]); --- 5516,5522 ---- { #ifdef FEAT_CLIENTSERVER # ifdef MSWIN ! // On Win32 it's done in this application. { char_u *server_name = tv_get_string_chk(&argvars[0]); *************** *** 5525,5531 **** serverForeground(server_name); } # else ! /* Send a foreground() expression to the server. */ argvars[1].v_type = VAR_STRING; argvars[1].vval.v_string = vim_strsave((char_u *)"foreground()"); argvars[2].v_type = VAR_UNKNOWN; --- 5524,5530 ---- serverForeground(server_name); } # else ! // Send a foreground() expression to the server. argvars[1].v_type = VAR_STRING; argvars[1].vval.v_string = vim_strsave((char_u *)"foreground()"); argvars[2].v_type = VAR_UNKNOWN; *************** *** 5557,5563 **** if (serverid == NULL) { rettv->vval.v_number = -1; ! return; /* type error; errmsg already given */ } # ifdef MSWIN sscanf((const char *)serverid, SCANF_HEX_LONG_U, &n); --- 5556,5562 ---- if (serverid == NULL) { rettv->vval.v_number = -1; ! return; // type error; errmsg already given } # ifdef MSWIN sscanf((const char *)serverid, SCANF_HEX_LONG_U, &n); *************** *** 5604,5610 **** { int timeout = 0; # ifdef MSWIN ! /* The server's HWND is encoded in the 'id' parameter */ long_u n = 0; # endif --- 5603,5609 ---- { int timeout = 0; # ifdef MSWIN ! // The server's HWND is encoded in the 'id' parameter long_u n = 0; # endif *************** *** 5651,5657 **** char_u *server = tv_get_string_chk(&argvars[0]); if (server == NULL) ! return; /* type error; errmsg already given */ if (serverName != NULL) emsg(_("E941: already started a server")); else --- 5650,5656 ---- char_u *server = tv_get_string_chk(&argvars[0]); if (server == NULL) ! return; // type error; errmsg already given if (serverName != NULL) emsg(_("E941: already started a server")); else *************** *** 5728,5741 **** } } ! #define SP_NOMOVE 0x01 /* don't move cursor */ ! #define SP_REPEAT 0x02 /* repeat to find outer pair */ ! #define SP_RETCOUNT 0x04 /* return matchcount */ ! #define SP_SETPCMARK 0x08 /* set previous context mark */ ! #define SP_START 0x10 /* accept match at start position */ ! #define SP_SUBPAT 0x20 /* return nr of matching sub-pattern */ ! #define SP_END 0x40 /* leave cursor at end of match */ ! #define SP_COLUMN 0x80 /* start at cursor column */ /* * Get flags for a search function. --- 5727,5740 ---- } } ! #define SP_NOMOVE 0x01 // don't move cursor ! #define SP_REPEAT 0x02 // repeat to find outer pair ! #define SP_RETCOUNT 0x04 // return matchcount ! #define SP_SETPCMARK 0x08 // set previous context mark ! #define SP_START 0x10 // accept match at start position ! #define SP_SUBPAT 0x20 // return nr of matching sub-pattern ! #define SP_END 0x40 // leave cursor at end of match ! #define SP_COLUMN 0x80 // start at cursor column /* * Get flags for a search function. *************** *** 5754,5760 **** { flags = tv_get_string_buf_chk(varp, nbuf); if (flags == NULL) ! return 0; /* type error; errmsg already given */ while (*flags != NUL) { switch (*flags) --- 5753,5759 ---- { flags = tv_get_string_buf_chk(varp, nbuf); if (flags == NULL) ! return 0; // type error; errmsg already given while (*flags != NUL) { switch (*flags) *************** *** 5803,5809 **** pos_T save_cursor; int save_p_ws = p_ws; int dir; ! int retval = 0; /* default: FAIL */ long lnum_stop = 0; #ifdef FEAT_RELTIME proftime_T tm; --- 5802,5808 ---- pos_T save_cursor; int save_p_ws = p_ws; int dir; ! int retval = 0; // default: FAIL long lnum_stop = 0; #ifdef FEAT_RELTIME proftime_T tm; *************** *** 5814,5820 **** searchit_arg_T sia; pat = tv_get_string(&argvars[0]); ! dir = get_search_arg(&argvars[1], flagsp); /* may set p_ws */ if (dir == 0) goto theend; flags = *flagsp; --- 5813,5819 ---- searchit_arg_T sia; pat = tv_get_string(&argvars[0]); ! dir = get_search_arg(&argvars[1], flagsp); // may set p_ws if (dir == 0) goto theend; flags = *flagsp; *************** *** 5825,5831 **** if (flags & SP_COLUMN) options |= SEARCH_COL; ! /* Optional arguments: line number to stop searching and timeout. */ if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) { lnum_stop = (long)tv_get_number_chk(&argvars[2], NULL); --- 5824,5830 ---- if (flags & SP_COLUMN) options |= SEARCH_COL; ! // Optional arguments: line number to stop searching and timeout. if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) { lnum_stop = (long)tv_get_number_chk(&argvars[2], NULL); *************** *** 5842,5848 **** } #ifdef FEAT_RELTIME ! /* Set the time limit, if there is one. */ profile_setlimit(time_limit, &tm); #endif --- 5841,5847 ---- } #ifdef FEAT_RELTIME ! // Set the time limit, if there is one. profile_setlimit(time_limit, &tm); #endif *************** *** 5878,5893 **** curwin->w_cursor = pos; if (match_pos != NULL) { ! /* Store the match cursor position */ match_pos->lnum = pos.lnum; match_pos->col = pos.col + 1; } ! /* "/$" will put the cursor after the end of the line, may need to ! * correct that here */ check_cursor(); } ! /* If 'n' flag is used: restore cursor position. */ if (flags & SP_NOMOVE) curwin->w_cursor = save_cursor; else --- 5877,5892 ---- curwin->w_cursor = pos; if (match_pos != NULL) { ! // Store the match cursor position match_pos->lnum = pos.lnum; match_pos->col = pos.col + 1; } ! // "/$" will put the cursor after the end of the line, may need to ! // correct that here check_cursor(); } ! // If 'n' flag is used: restore cursor position. if (flags & SP_NOMOVE) curwin->w_cursor = save_cursor; else *************** *** 6098,6104 **** int error = FALSE; char_u *name; ! rettv->vval.v_number = 1; /* default: FAIL */ name = tv_get_string_chk(&argvars[0]); if (argvars[1].v_type != VAR_UNKNOWN) --- 6097,6103 ---- int error = FALSE; char_u *name; ! rettv->vval.v_number = 1; // default: FAIL name = tv_get_string_chk(&argvars[0]); if (argvars[1].v_type != VAR_UNKNOWN) *************** *** 6125,6150 **** int flags = 0; char_u nbuf1[NUMBUFLEN]; char_u nbuf2[NUMBUFLEN]; ! int retval = 0; /* default: FAIL */ long lnum_stop = 0; long time_limit = 0; ! /* Get the three pattern arguments: start, middle, end. Will result in an ! * error if not a valid argument. */ spat = tv_get_string_chk(&argvars[0]); mpat = tv_get_string_buf_chk(&argvars[1], nbuf1); epat = tv_get_string_buf_chk(&argvars[2], nbuf2); if (spat == NULL || mpat == NULL || epat == NULL) ! goto theend; /* type error */ ! /* Handle the optional fourth argument: flags */ ! dir = get_search_arg(&argvars[3], &flags); /* may set p_ws */ if (dir == 0) goto theend; ! /* Don't accept SP_END or SP_SUBPAT. ! * Only one of the SP_NOMOVE or SP_SETPCMARK flags can be set. ! */ if ((flags & (SP_END | SP_SUBPAT)) != 0 || ((flags & SP_NOMOVE) && (flags & SP_SETPCMARK))) { --- 6124,6148 ---- int flags = 0; char_u nbuf1[NUMBUFLEN]; char_u nbuf2[NUMBUFLEN]; ! int retval = 0; // default: FAIL long lnum_stop = 0; long time_limit = 0; ! // Get the three pattern arguments: start, middle, end. Will result in an ! // error if not a valid argument. spat = tv_get_string_chk(&argvars[0]); mpat = tv_get_string_buf_chk(&argvars[1], nbuf1); epat = tv_get_string_buf_chk(&argvars[2], nbuf2); if (spat == NULL || mpat == NULL || epat == NULL) ! goto theend; // type error ! // Handle the optional fourth argument: flags ! dir = get_search_arg(&argvars[3], &flags); // may set p_ws if (dir == 0) goto theend; ! // Don't accept SP_END or SP_SUBPAT. ! // Only one of the SP_NOMOVE or SP_SETPCMARK flags can be set. if ((flags & (SP_END | SP_SUBPAT)) != 0 || ((flags & SP_NOMOVE) && (flags & SP_SETPCMARK))) { *************** *** 6152,6162 **** goto theend; } ! /* Using 'r' implies 'W', otherwise it doesn't work. */ if (flags & SP_REPEAT) p_ws = FALSE; ! /* Optional fifth argument: skip expression */ if (argvars[3].v_type == VAR_UNKNOWN || argvars[4].v_type == VAR_UNKNOWN) skip = NULL; --- 6150,6160 ---- goto theend; } ! // Using 'r' implies 'W', otherwise it doesn't work. if (flags & SP_REPEAT) p_ws = FALSE; ! // Optional fifth argument: skip expression if (argvars[3].v_type == VAR_UNKNOWN || argvars[4].v_type == VAR_UNKNOWN) skip = NULL; *************** *** 6166,6172 **** if (skip->v_type != VAR_FUNC && skip->v_type != VAR_PARTIAL && skip->v_type != VAR_STRING) { ! /* Type error */ semsg(_(e_invarg2), tv_get_string(&argvars[4])); goto theend; } --- 6164,6170 ---- if (skip->v_type != VAR_FUNC && skip->v_type != VAR_PARTIAL && skip->v_type != VAR_STRING) { ! // Type error semsg(_(e_invarg2), tv_get_string(&argvars[4])); goto theend; } *************** *** 6240,6254 **** */ long do_searchpair( ! char_u *spat, /* start pattern */ ! char_u *mpat, /* middle pattern */ ! char_u *epat, /* end pattern */ ! int dir, /* BACKWARD or FORWARD */ ! typval_T *skip, /* skip expression */ ! int flags, /* SP_SETPCMARK and other SP_ values */ pos_T *match_pos, ! linenr_T lnum_stop, /* stop at this line if not zero */ ! long time_limit UNUSED) /* stop after this many msec */ { char_u *save_cpo; char_u *pat, *pat2 = NULL, *pat3 = NULL; --- 6238,6252 ---- */ long do_searchpair( ! char_u *spat, // start pattern ! char_u *mpat, // middle pattern ! char_u *epat, // end pattern ! int dir, // BACKWARD or FORWARD ! typval_T *skip, // skip expression ! int flags, // SP_SETPCMARK and other SP_ values pos_T *match_pos, ! linenr_T lnum_stop, // stop at this line if not zero ! long time_limit UNUSED) // stop after this many msec { char_u *save_cpo; char_u *pat, *pat2 = NULL, *pat3 = NULL; *************** *** 6268,6284 **** proftime_T tm; #endif ! /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ save_cpo = p_cpo; p_cpo = empty_option; #ifdef FEAT_RELTIME ! /* Set the time limit, if there is one. */ profile_setlimit(time_limit, &tm); #endif ! /* Make two search patterns: start/end (pat2, for in nested pairs) and ! * start/middle/end (pat3, for the top pair). */ pat2 = alloc(STRLEN(spat) + STRLEN(epat) + 17); pat3 = alloc(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25); if (pat2 == NULL || pat3 == NULL) --- 6266,6282 ---- proftime_T tm; #endif ! // Make 'cpoptions' empty, the 'l' flag should not be used here. save_cpo = p_cpo; p_cpo = empty_option; #ifdef FEAT_RELTIME ! // Set the time limit, if there is one. profile_setlimit(time_limit, &tm); #endif ! // Make two search patterns: start/end (pat2, for in nested pairs) and ! // start/middle/end (pat3, for the top pair). pat2 = alloc(STRLEN(spat) + STRLEN(epat) + 17); pat3 = alloc(STRLEN(spat) + STRLEN(mpat) + STRLEN(epat) + 25); if (pat2 == NULL || pat3 == NULL) *************** *** 6294,6300 **** if (skip != NULL) { ! /* Empty string means to not use the skip expression. */ if (skip->v_type == VAR_STRING || skip->v_type == VAR_FUNC) use_skip = skip->vval.v_string != NULL && *skip->vval.v_string != NUL; --- 6292,6298 ---- if (skip != NULL) { ! // Empty string means to not use the skip expression. if (skip->v_type == VAR_STRING || skip->v_type == VAR_FUNC) use_skip = skip->vval.v_string != NULL && *skip->vval.v_string != NUL; *************** *** 6317,6332 **** n = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L, options, RE_SEARCH, &sia); if (n == FAIL || (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos))) ! /* didn't find it or found the first match again: FAIL */ break; if (firstpos.lnum == 0) firstpos = pos; if (EQUAL_POS(pos, foundpos)) { ! /* Found the same position again. Can happen with a pattern that ! * has "\zs" at the end and searching backwards. Advance one ! * character and try again. */ if (dir == BACKWARD) decl(&pos); else --- 6315,6330 ---- n = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L, options, RE_SEARCH, &sia); if (n == FAIL || (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos))) ! // didn't find it or found the first match again: FAIL break; if (firstpos.lnum == 0) firstpos = pos; if (EQUAL_POS(pos, foundpos)) { ! // Found the same position again. Can happen with a pattern that ! // has "\zs" at the end and searching backwards. Advance one ! // character and try again. if (dir == BACKWARD) decl(&pos); else *************** *** 6334,6343 **** } foundpos = pos; ! /* clear the start flag to avoid getting stuck here */ options &= ~SEARCH_START; ! /* If the skip pattern matches, ignore this match. */ if (use_skip) { save_pos = curwin->w_cursor; --- 6332,6341 ---- } foundpos = pos; ! // clear the start flag to avoid getting stuck here options &= ~SEARCH_START; ! // If the skip pattern matches, ignore this match. if (use_skip) { save_pos = curwin->w_cursor; *************** *** 6347,6353 **** curwin->w_cursor = save_pos; if (err) { ! /* Evaluating {skip} caused an error, break here. */ curwin->w_cursor = save_cursor; retval = -1; break; --- 6345,6351 ---- curwin->w_cursor = save_pos; if (err) { ! // Evaluating {skip} caused an error, break here. curwin->w_cursor = save_cursor; retval = -1; break; *************** *** 6358,6379 **** if ((dir == BACKWARD && n == 3) || (dir == FORWARD && n == 2)) { ! /* Found end when searching backwards or start when searching ! * forward: nested pair. */ ++nest; ! pat = pat2; /* nested, don't search for middle */ } else { ! /* Found end when searching forward or start when searching ! * backward: end of (nested) pair; or found middle in outer pair. */ if (--nest == 1) ! pat = pat3; /* outer level, search for middle */ } if (nest == 0) { ! /* Found the match: return matchcount or line number. */ if (flags & SP_RETCOUNT) ++retval; else --- 6356,6377 ---- if ((dir == BACKWARD && n == 3) || (dir == FORWARD && n == 2)) { ! // Found end when searching backwards or start when searching ! // forward: nested pair. ++nest; ! pat = pat2; // nested, don't search for middle } else { ! // Found end when searching forward or start when searching ! // backward: end of (nested) pair; or found middle in outer pair. if (--nest == 1) ! pat = pat3; // outer level, search for middle } if (nest == 0) { ! // Found the match: return matchcount or line number. if (flags & SP_RETCOUNT) ++retval; else *************** *** 6383,6400 **** curwin->w_cursor = pos; if (!(flags & SP_REPEAT)) break; ! nest = 1; /* search for next unmatched */ } } if (match_pos != NULL) { ! /* Store the match cursor position */ match_pos->lnum = curwin->w_cursor.lnum; match_pos->col = curwin->w_cursor.col + 1; } ! /* If 'n' flag is used or search failed: restore cursor position. */ if ((flags & SP_NOMOVE) || retval == 0) curwin->w_cursor = save_cursor; --- 6381,6398 ---- curwin->w_cursor = pos; if (!(flags & SP_REPEAT)) break; ! nest = 1; // search for next unmatched } } if (match_pos != NULL) { ! // Store the match cursor position match_pos->lnum = curwin->w_cursor.lnum; match_pos->col = curwin->w_cursor.col + 1; } ! // If 'n' flag is used or search failed: restore cursor position. if ((flags & SP_NOMOVE) || retval == 0) curwin->w_cursor = save_cursor; *************** *** 6404,6410 **** if (p_cpo == empty_option) p_cpo = save_cpo; else ! /* Darn, evaluating the {skip} expression changed the value. */ free_string_option(save_cpo); return retval; --- 6402,6408 ---- if (p_cpo == empty_option) p_cpo = save_cpo; else ! // Darn, evaluating the {skip} expression changed the value. free_string_option(save_cpo); return retval; *************** *** 6600,6606 **** pos.col = 0; if (name[0] == '.' && name[1] == NUL) { ! /* set cursor; "fnum" is ignored */ curwin->w_cursor = pos; if (curswant >= 0) { --- 6598,6604 ---- pos.col = 0; if (name[0] == '.' && name[1] == NUL) { ! // set cursor; "fnum" is ignored curwin->w_cursor = pos; if (curswant >= 0) { *************** *** 6612,6618 **** } else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) { ! /* set mark */ if (setmark_pos(name[1], &pos, fnum) == OK) rettv->vval.v_number = 0; } --- 6610,6616 ---- } else if (name[0] == '\'' && name[1] != NUL && name[2] == NUL) { ! // set mark if (setmark_pos(name[1], &pos, fnum) == OK) rettv->vval.v_number = 0; } *************** *** 6641,6650 **** append = FALSE; strregname = tv_get_string_chk(argvars); ! rettv->vval.v_number = 1; /* FAIL is default */ if (strregname == NULL) ! return; /* type error; errmsg already given */ regname = *strregname; if (regname == 0 || regname == '@') regname = '"'; --- 6639,6648 ---- append = FALSE; strregname = tv_get_string_chk(argvars); ! rettv->vval.v_number = 1; // FAIL is default if (strregname == NULL) ! return; // type error; errmsg already given regname = *strregname; if (regname == 0 || regname == '@') regname = '"'; *************** *** 6653,6672 **** { stropt = tv_get_string_chk(&argvars[2]); if (stropt == NULL) ! return; /* type error */ for (; *stropt != NUL; ++stropt) switch (*stropt) { ! case 'a': case 'A': /* append */ append = TRUE; break; ! case 'v': case 'c': /* character-wise selection */ yank_type = MCHAR; break; ! case 'V': case 'l': /* line-wise selection */ yank_type = MLINE; break; ! case 'b': case Ctrl_V: /* block-wise selection */ yank_type = MBLOCK; if (VIM_ISDIGIT(stropt[1])) { --- 6651,6670 ---- { stropt = tv_get_string_chk(&argvars[2]); if (stropt == NULL) ! return; // type error for (; *stropt != NUL; ++stropt) switch (*stropt) { ! case 'a': case 'A': // append append = TRUE; break; ! case 'v': case 'c': // character-wise selection yank_type = MCHAR; break; ! case 'V': case 'l': // line-wise selection yank_type = MLINE; break; ! case 'b': case Ctrl_V: // block-wise selection yank_type = MBLOCK; if (VIM_ISDIGIT(stropt[1])) { *************** *** 6689,6699 **** listitem_T *li; int len; ! /* If the list is NULL handle like an empty list. */ len = ll == NULL ? 0 : ll->lv_len; ! /* First half: use for pointers to result lines; second half: use for ! * pointers to allocated copies. */ lstval = ALLOC_MULT(char_u *, (len + 1) * 2); if (lstval == NULL) return; --- 6687,6697 ---- listitem_T *li; int len; ! // If the list is NULL handle like an empty list. len = ll == NULL ? 0 : ll->lv_len; ! // First half: use for pointers to result lines; second half: use for ! // pointers to allocated copies. lstval = ALLOC_MULT(char_u *, (len + 1) * 2); if (lstval == NULL) return; *************** *** 6709,6716 **** goto free_lstval; if (strval == buf) { ! /* Need to make a copy, next tv_get_string_buf_chk() will ! * overwrite the string. */ strval = vim_strsave(buf); if (strval == NULL) goto free_lstval; --- 6707,6714 ---- goto free_lstval; if (strval == buf) { ! // Need to make a copy, next tv_get_string_buf_chk() will ! // overwrite the string. strval = vim_strsave(buf); if (strval == NULL) goto free_lstval; *************** *** 6808,6814 **** sha256_bytes(p, (int)STRLEN(p), NULL, 0)); rettv->v_type = VAR_STRING; } ! #endif /* FEAT_CRYPT */ /* * "shellescape({string})" function --- 6806,6812 ---- sha256_bytes(p, (int)STRLEN(p), NULL, 0)); rettv->v_type = VAR_STRING; } ! #endif // FEAT_CRYPT /* * "shellescape({string})" function *************** *** 6912,6918 **** #ifdef FEAT_SPELL if (argvars[0].v_type == VAR_UNKNOWN) { ! /* Find the start and length of the badly spelled word. */ len = spell_move_to(curwin, FORWARD, TRUE, TRUE, &attr); if (len != 0) { --- 6910,6916 ---- #ifdef FEAT_SPELL if (argvars[0].v_type == VAR_UNKNOWN) { ! // Find the start and length of the badly spelled word. len = spell_move_to(curwin, FORWARD, TRUE, TRUE, &attr); if (len != 0) { *************** *** 6927,6933 **** if (str != NULL) { ! /* Check the argument for spelling. */ while (*str != NUL) { len = spell_check(curwin, str, &attr, &capcol, FALSE); --- 6925,6931 ---- if (str != NULL) { ! // Check the argument for spelling. while (*str != NUL) { len = spell_check(curwin, str, &attr, &capcol, FALSE); *************** *** 7027,7033 **** int keepempty = FALSE; int typeerr = FALSE; ! /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ save_cpo = p_cpo; p_cpo = (char_u *)""; --- 7025,7031 ---- int keepempty = FALSE; int typeerr = FALSE; ! // Make 'cpoptions' empty, the 'l' flag should not be used here. save_cpo = p_cpo; p_cpo = (char_u *)""; *************** *** 7055,7061 **** while (*str != NUL || keepempty) { if (*str == NUL) ! match = FALSE; /* empty item at the end */ else match = vim_regexec_nl(®match, str, col); if (match) --- 7053,7059 ---- while (*str != NUL || keepempty) { if (*str == NUL) ! match = FALSE; // empty item at the end else match = vim_regexec_nl(®match, str, col); if (match) *************** *** 7294,7300 **** else seconds = (time_t)tv_get_number(&argvars[1]); curtime = vim_localtime(&seconds, &tmval); ! /* MSVC returns NULL for an invalid value of seconds. */ if (curtime == NULL) rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)")); else --- 7292,7298 ---- else seconds = (time_t)tv_get_number(&argvars[1]); curtime = vim_localtime(&seconds, &tmval); ! // MSVC returns NULL for an invalid value of seconds. if (curtime == NULL) rettv->vval.v_string = vim_strsave((char_u *)_("(Invalid)")); else *************** *** 7321,7327 **** else rettv->vval.v_string = vim_strsave(result_buf); ! /* Release conversion descriptors */ convert_setup(&conv, NULL, NULL); vim_free(enc); } --- 7319,7325 ---- else rettv->vval.v_string = vim_strsave(result_buf); ! // Release conversion descriptors convert_setup(&conv, NULL, NULL); vim_free(enc); } *************** *** 7378,7384 **** save_haystack = haystack = tv_get_string_buf_chk(&argvars[0], buf); rettv->vval.v_number = -1; if (needle == NULL || haystack == NULL) ! return; /* type error; errmsg already given */ if (argvars[2].v_type != VAR_UNKNOWN) { --- 7376,7382 ---- save_haystack = haystack = tv_get_string_buf_chk(&argvars[0], buf); rettv->vval.v_number = -1; if (needle == NULL || haystack == NULL) ! return; // type error; errmsg already given if (argvars[2].v_type != VAR_UNKNOWN) { *************** *** 7408,7414 **** rettv->v_type = VAR_STRING; rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, get_copyID()); ! /* Make a copy if we have a value but it's not in allocated memory. */ if (rettv->vval.v_string != NULL && tofree == NULL) rettv->vval.v_string = vim_strsave(rettv->vval.v_string); } --- 7406,7412 ---- rettv->v_type = VAR_STRING; rettv->vval.v_string = tv2string(&argvars[0], &tofree, numbuf, get_copyID()); ! // Make a copy if we have a value but it's not in allocated memory. if (rettv->vval.v_string != NULL && tofree == NULL) rettv->vval.v_string = vim_strsave(rettv->vval.v_string); } *************** *** 7519,7525 **** } } else ! len = slen - nbyte; /* default: all bytes that are available. */ } /* --- 7517,7523 ---- } } else ! len = slen - nbyte; // default: all bytes that are available. } /* *************** *** 7563,7569 **** else if (argvars[2].v_type != VAR_UNKNOWN) len = (int)tv_get_number(&argvars[2]); else ! len = slen - n; /* default len: all bytes that are available. */ /* * Only return the overlap between the specified part and the actual --- 7561,7567 ---- else if (argvars[2].v_type != VAR_UNKNOWN) len = (int)tv_get_number(&argvars[2]); else ! len = slen - n; // default len: all bytes that are available. /* * Only return the overlap between the specified part and the actual *************** *** 7637,7658 **** rettv->vval.v_number = -1; if (needle == NULL || haystack == NULL) ! return; /* type error; errmsg already given */ haystack_len = (int)STRLEN(haystack); if (argvars[2].v_type != VAR_UNKNOWN) { ! /* Third argument: upper limit for index */ end_idx = (int)tv_get_number_chk(&argvars[2], NULL); if (end_idx < 0) ! return; /* can never find a match */ } else end_idx = haystack_len; if (*needle == NUL) { ! /* Empty string matches past the end. */ lastmatch = haystack + end_idx; } else --- 7635,7656 ---- rettv->vval.v_number = -1; if (needle == NULL || haystack == NULL) ! return; // type error; errmsg already given haystack_len = (int)STRLEN(haystack); if (argvars[2].v_type != VAR_UNKNOWN) { ! // Third argument: upper limit for index end_idx = (int)tv_get_number_chk(&argvars[2], NULL); if (end_idx < 0) ! return; // can never find a match } else end_idx = haystack_len; if (*needle == NUL) { ! // Empty string matches past the end. lastmatch = haystack + end_idx; } else *************** *** 7786,7793 **** int trans; int transerr = FALSE; ! lnum = tv_get_lnum(argvars); /* -1 on type error */ ! col = (linenr_T)tv_get_number(&argvars[1]) - 1; /* -1 on type error */ trans = (int)tv_get_number_chk(&argvars[2], &transerr); if (!transerr && lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count --- 7784,7791 ---- int trans; int transerr = FALSE; ! lnum = tv_get_lnum(argvars); // -1 on type error ! col = (linenr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error trans = (int)tv_get_number_chk(&argvars[2], &transerr); if (!transerr && lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count *************** *** 7819,7825 **** mode = tv_get_string_buf(&argvars[2], modebuf); modec = TOLOWER_ASC(mode[0]); if (modec != 't' && modec != 'c' && modec != 'g') ! modec = 0; /* replace invalid with current */ } else { --- 7817,7823 ---- mode = tv_get_string_buf(&argvars[2], modebuf); modec = TOLOWER_ASC(mode[0]); if (modec != 't' && modec != 'c' && modec != 'g') ! modec = 0; // replace invalid with current } else { *************** *** 7837,7884 **** switch (TOLOWER_ASC(what[0])) { case 'b': ! if (TOLOWER_ASC(what[1]) == 'g') /* bg[#] */ p = highlight_color(id, what, modec); ! else /* bold */ p = highlight_has_attr(id, HL_BOLD, modec); break; ! case 'f': /* fg[#] or font */ p = highlight_color(id, what, modec); break; case 'i': ! if (TOLOWER_ASC(what[1]) == 'n') /* inverse */ p = highlight_has_attr(id, HL_INVERSE, modec); ! else /* italic */ p = highlight_has_attr(id, HL_ITALIC, modec); break; ! case 'n': /* name */ p = get_highlight_name_ext(NULL, id - 1, FALSE); break; ! case 'r': /* reverse */ p = highlight_has_attr(id, HL_INVERSE, modec); break; case 's': ! if (TOLOWER_ASC(what[1]) == 'p') /* sp[#] */ p = highlight_color(id, what, modec); ! /* strikeout */ else if (TOLOWER_ASC(what[1]) == 't' && TOLOWER_ASC(what[2]) == 'r') p = highlight_has_attr(id, HL_STRIKETHROUGH, modec); ! else /* standout */ p = highlight_has_attr(id, HL_STANDOUT, modec); break; case 'u': if (STRLEN(what) <= 5 || TOLOWER_ASC(what[5]) != 'c') ! /* underline */ p = highlight_has_attr(id, HL_UNDERLINE, modec); else ! /* undercurl */ p = highlight_has_attr(id, HL_UNDERCURL, modec); break; } --- 7835,7882 ---- switch (TOLOWER_ASC(what[0])) { case 'b': ! if (TOLOWER_ASC(what[1]) == 'g') // bg[#] p = highlight_color(id, what, modec); ! else // bold p = highlight_has_attr(id, HL_BOLD, modec); break; ! case 'f': // fg[#] or font p = highlight_color(id, what, modec); break; case 'i': ! if (TOLOWER_ASC(what[1]) == 'n') // inverse p = highlight_has_attr(id, HL_INVERSE, modec); ! else // italic p = highlight_has_attr(id, HL_ITALIC, modec); break; ! case 'n': // name p = get_highlight_name_ext(NULL, id - 1, FALSE); break; ! case 'r': // reverse p = highlight_has_attr(id, HL_INVERSE, modec); break; case 's': ! if (TOLOWER_ASC(what[1]) == 'p') // sp[#] p = highlight_color(id, what, modec); ! // strikeout else if (TOLOWER_ASC(what[1]) == 't' && TOLOWER_ASC(what[2]) == 'r') p = highlight_has_attr(id, HL_STRIKETHROUGH, modec); ! else // standout p = highlight_has_attr(id, HL_STANDOUT, modec); break; case 'u': if (STRLEN(what) <= 5 || TOLOWER_ASC(what[5]) != 'c') ! // underline p = highlight_has_attr(id, HL_UNDERLINE, modec); else ! // undercurl p = highlight_has_attr(id, HL_UNDERCURL, modec); break; } *************** *** 7928,7935 **** rettv_list_set(rettv, NULL); #if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL) ! lnum = tv_get_lnum(argvars); /* -1 on type error */ ! col = (colnr_T)tv_get_number(&argvars[1]) - 1; /* -1 on type error */ vim_memset(str, NUL, sizeof(str)); --- 7926,7933 ---- rettv_list_set(rettv, NULL); #if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL) ! lnum = tv_get_lnum(argvars); // -1 on type error ! col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error vim_memset(str, NUL, sizeof(str)); *************** *** 7942,7948 **** (void)syn_get_id(curwin, lnum, col, FALSE, NULL, FALSE); syntax_flags = get_syntax_info(&matchid); ! /* get the conceal character */ if ((syntax_flags & HL_CONCEAL) && curwin->w_p_cole < 3) { cchar = syn_get_sub_char(); --- 7940,7946 ---- (void)syn_get_id(curwin, lnum, col, FALSE, NULL, FALSE); syntax_flags = get_syntax_info(&matchid); ! // get the conceal character if ((syntax_flags & HL_CONCEAL) && curwin->w_p_cole < 3) { cchar = syn_get_sub_char(); *************** *** 7960,7966 **** list_append_number(rettv->vval.v_list, (syntax_flags & HL_CONCEAL) != 0); ! /* -1 to auto-determine strlen */ list_append_string(rettv->vval.v_list, str, -1); list_append_number(rettv->vval.v_list, matchid); } --- 7958,7964 ---- list_append_number(rettv->vval.v_list, (syntax_flags & HL_CONCEAL) != 0); ! // -1 to auto-determine strlen list_append_string(rettv->vval.v_list, str, -1); list_append_number(rettv->vval.v_list, matchid); } *************** *** 7983,7990 **** rettv_list_set(rettv, NULL); #ifdef FEAT_SYN_HL ! lnum = tv_get_lnum(argvars); /* -1 on type error */ ! col = (colnr_T)tv_get_number(&argvars[1]) - 1; /* -1 on type error */ if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) --- 7981,7988 ---- rettv_list_set(rettv, NULL); #ifdef FEAT_SYN_HL ! lnum = tv_get_lnum(argvars); // -1 on type error ! col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) *************** *** 8151,8165 **** fromstr = tv_get_string_buf_chk(&argvars[1], buf); tostr = tv_get_string_buf_chk(&argvars[2], buf2); ! /* Default return value: empty string. */ rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; if (fromstr == NULL || tostr == NULL) ! return; /* type error; errmsg already given */ ga_init2(&ga, (int)sizeof(char), 80); if (!has_mbyte) ! /* not multi-byte: fromstr and tostr must be the same length */ if (STRLEN(fromstr) != STRLEN(tostr)) { error: --- 8149,8163 ---- fromstr = tv_get_string_buf_chk(&argvars[1], buf); tostr = tv_get_string_buf_chk(&argvars[2], buf2); ! // Default return value: empty string. rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; if (fromstr == NULL || tostr == NULL) ! return; // type error; errmsg already given ga_init2(&ga, (int)sizeof(char), 80); if (!has_mbyte) ! // not multi-byte: fromstr and tostr must be the same length if (STRLEN(fromstr) != STRLEN(tostr)) { error: *************** *** 8168,8174 **** return; } ! /* fromstr and tostr have to contain the same number of chars */ while (*in_str != NUL) { if (has_mbyte) --- 8166,8172 ---- return; } ! // fromstr and tostr have to contain the same number of chars while (*in_str != NUL) { if (has_mbyte) *************** *** 8192,8198 **** break; } } ! if (*p == NUL) /* tostr is shorter than fromstr */ goto error; break; } --- 8190,8196 ---- break; } } ! if (*p == NUL) // tostr is shorter than fromstr goto error; break; } *************** *** 8201,8209 **** if (first && cpstr == in_str) { ! /* Check that fromstr and tostr have the same number of ! * (multi-byte) characters. Done only once when a character ! * of in_str doesn't appear in fromstr. */ first = FALSE; for (p = tostr; *p != NUL; p += tolen) { --- 8199,8207 ---- if (first && cpstr == in_str) { ! // Check that fromstr and tostr have the same number of ! // (multi-byte) characters. Done only once when a character ! // of in_str doesn't appear in fromstr. first = FALSE; for (p = tostr; *p != NUL; p += tolen) { *************** *** 8222,8228 **** } else { ! /* When not using multi-byte chars we can do it faster. */ p = vim_strchr(fromstr, *in_str); if (p != NULL) ga_append(&ga, tostr[p - fromstr]); --- 8220,8226 ---- } else { ! // When not using multi-byte chars we can do it faster. p = vim_strchr(fromstr, *in_str); if (p != NULL) ga_append(&ga, tostr[p - fromstr]); *************** *** 8232,8238 **** } } ! /* add a terminating NUL */ (void)ga_grow(&ga, 1); ga_append(&ga, NUL); --- 8230,8236 ---- } } ! // add a terminating NUL (void)ga_grow(&ga, 1); ga_append(&ga, NUL); *************** *** 8316,8322 **** rettv->v_type = VAR_FLOAT; if (get_float_arg(argvars, &f) == OK) ! /* trunc() is not in C90, use floor() or ceil() instead. */ rettv->vval.v_float = f > 0 ? floor(f) : ceil(f); else rettv->vval.v_float = 0.0; --- 8314,8320 ---- rettv->v_type = VAR_FLOAT; if (get_float_arg(argvars, &f) == OK) ! // trunc() is not in C90, use floor() or ceil() instead. rettv->vval.v_float = f > 0 ? floor(f) : ceil(f); else rettv->vval.v_float = 0.0; *************** *** 8392,8398 **** str[1] = NUL; rettv->vval.v_string = vim_strsave(str); ! /* A non-zero number or non-empty string argument: reset mode. */ if (non_zero_arg(&argvars[0])) curbuf->b_visual_mode_eval = NUL; } --- 8390,8396 ---- str[1] = NUL; rettv->vval.v_string = vim_strsave(str); ! // A non-zero number or non-empty string argument: reset mode. if (non_zero_arg(&argvars[0])) curbuf->b_visual_mode_eval = NUL; } *************** *** 8430,8433 **** ^ tv_get_number_chk(&argvars[1], NULL); } ! #endif /* FEAT_EVAL */ --- 8428,8431 ---- ^ tv_get_number_chk(&argvars[1], NULL); } ! #endif // FEAT_EVAL *** ../vim-8.1.2377/src/version.c 2019-12-01 19:37:03.468332588 +0100 --- src/version.c 2019-12-01 21:10:57.333332325 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 2378, /**/ -- "Hit any key to continue" is a lie. /// 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 ///