To: vim_dev@googlegroups.com Subject: Patch 8.1.2379 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2379 Problem: Using old C style comments. Solution: Use // comments where appropriate. Files: src/ex_cmds.c, src/ex_cmds2.c, src/ex_docmd.c, src/ex_eval.c, src/ex_getln.c, src/fileio.c, src/filepath.c, src/findfile.c, src/fold.c *** ../vim-8.1.2378/src/ex_cmds.c 2019-12-01 15:23:07.464344509 +0100 --- src/ex_cmds.c 2019-12-01 21:23:08.482354137 +0100 *************** *** 57,66 **** IObuff[0] = NUL; if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80) { ! if (c == NL) /* NUL is stored as NL */ c = NUL; if (c == CAR && get_fileformat(curbuf) == EOL_MAC) ! cval = NL; /* NL is stored as CR */ else cval = c; if (vim_isprintc_strict(c) && (c < ' ' --- 57,66 ---- IObuff[0] = NUL; if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80) { ! if (c == NL) // NUL is stored as NL c = NUL; if (c == CAR && get_fileformat(curbuf) == EOL_MAC) ! cval = NL; // NL is stored as CR else cval = c; if (vim_isprintc_strict(c) && (c < ' ' *************** *** 98,108 **** c = 0; } ! /* Repeat for combining characters. */ while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80))) { len = (int)STRLEN(IObuff); ! /* This assumes every multi-byte char is printable... */ if (len > 0) IObuff[len++] = ' '; IObuff[len++] = '<'; --- 98,108 ---- c = 0; } ! // Repeat for combining characters. while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80))) { len = (int)STRLEN(IObuff); ! // This assumes every multi-byte char is printable... if (len > 0) IObuff[len++] = ' '; IObuff[len++] = '<'; *************** *** 111,117 **** && !gui.in_use # endif ) ! IObuff[len++] = ' '; /* draw composing char on top of a space */ len += (*mb_char2bytes)(c, IObuff + len); #ifdef FEAT_DIGRAPHS dig = get_digraph_for_char(c); --- 111,117 ---- && !gui.in_use # endif ) ! IObuff[len++] = ' '; // draw composing char on top of a space len += (*mb_char2bytes)(c, IObuff + len); #ifdef FEAT_DIGRAPHS dig = get_digraph_for_char(c); *************** *** 153,159 **** #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) { ! /* switch left and right aligning */ if (eap->cmdidx == CMD_right) eap->cmdidx = CMD_left; else if (eap->cmdidx == CMD_left) --- 153,159 ---- #ifdef FEAT_RIGHTLEFT if (curwin->w_p_rl) { ! // switch left and right aligning if (eap->cmdidx == CMD_right) eap->cmdidx = CMD_left; else if (eap->cmdidx == CMD_left) *************** *** 163,169 **** width = atoi((char *)eap->arg); save_curpos = curwin->w_cursor; ! if (eap->cmdidx == CMD_left) /* width is used for new indent */ { if (width >= 0) indent = width; --- 163,169 ---- width = atoi((char *)eap->arg); save_curpos = curwin->w_cursor; ! if (eap->cmdidx == CMD_left) // width is used for new indent { if (width >= 0) indent = width; *************** *** 189,210 **** for (curwin->w_cursor.lnum = eap->line1; curwin->w_cursor.lnum <= eap->line2; ++curwin->w_cursor.lnum) { ! if (eap->cmdidx == CMD_left) /* left align */ new_indent = indent; else { ! has_tab = FALSE; /* avoid uninit warnings */ len = linelen(eap->cmdidx == CMD_right ? &has_tab : NULL) - get_indent(); ! if (len <= 0) /* skip blank lines */ continue; if (eap->cmdidx == CMD_center) new_indent = (width - len) / 2; else { ! new_indent = width - len; /* right align */ /* * Make sure that embedded TABs don't make the text go too far --- 189,210 ---- for (curwin->w_cursor.lnum = eap->line1; curwin->w_cursor.lnum <= eap->line2; ++curwin->w_cursor.lnum) { ! if (eap->cmdidx == CMD_left) // left align new_indent = indent; else { ! has_tab = FALSE; // avoid uninit warnings len = linelen(eap->cmdidx == CMD_right ? &has_tab : NULL) - get_indent(); ! if (len <= 0) // skip blank lines continue; if (eap->cmdidx == CMD_center) new_indent = (width - len) / 2; else { ! new_indent = width - len; // right align /* * Make sure that embedded TABs don't make the text go too far *************** *** 232,238 **** } if (new_indent < 0) new_indent = 0; ! (void)set_indent(new_indent, 0); /* set indent */ } changed_lines(eap->line1, 0, eap->line2 + 1, 0L); curwin->w_cursor = save_curpos; --- 232,238 ---- } if (new_indent < 0) new_indent = 0; ! (void)set_indent(new_indent, 0); // set indent } changed_lines(eap->line1, 0, eap->line2 + 1, 0L); curwin->w_cursor = save_curpos; *************** *** 274,294 **** return len; } ! /* Buffer for two lines used during sorting. They are allocated to ! * contain the longest line being sorted. */ static char_u *sortbuf1; static char_u *sortbuf2; ! static int sort_ic; /* ignore case */ ! static int sort_nr; /* sort on number */ ! static int sort_rx; /* sort on regex instead of skipping it */ #ifdef FEAT_FLOAT ! static int sort_flt; /* sort on floating number */ #endif ! static int sort_abort; /* flag to indicate if sorting has been interrupted */ ! /* Struct to store info to be sorted. */ typedef struct { linenr_T lnum; // line number --- 274,294 ---- return len; } ! // Buffer for two lines used during sorting. They are allocated to ! // contain the longest line being sorted. static char_u *sortbuf1; static char_u *sortbuf2; ! static int sort_ic; // ignore case ! static int sort_nr; // sort on number ! static int sort_rx; // sort on regex instead of skipping it #ifdef FEAT_FLOAT ! static int sort_flt; // sort on floating number #endif ! static int sort_abort; // flag to indicate if sorting has been interrupted ! // Struct to store info to be sorted. typedef struct { linenr_T lnum; // line number *************** *** 318,326 **** sorti_T l2 = *(sorti_T *)s2; int result = 0; ! /* If the user interrupts, there's no way to stop qsort() immediately, but ! * if we return 0 every time, qsort will assume it's done sorting and ! * exit. */ if (sort_abort) return 0; fast_breakcheck(); --- 318,326 ---- sorti_T l2 = *(sorti_T *)s2; int result = 0; ! // If the user interrupts, there's no way to stop qsort() immediately, but ! // if we return 0 every time, qsort will assume it's done sorting and ! // exit. if (sort_abort) return 0; fast_breakcheck(); *************** *** 342,350 **** #endif else { ! /* We need to copy one line into "sortbuf1", because there is no ! * guarantee that the first pointer becomes invalid when obtaining the ! * second one. */ STRNCPY(sortbuf1, ml_get(l1.lnum) + l1.st_u.line.start_col_nr, l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr + 1); sortbuf1[l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr] = 0; --- 342,350 ---- #endif else { ! // We need to copy one line into "sortbuf1", because there is no ! // guarantee that the first pointer becomes invalid when obtaining the ! // second one. STRNCPY(sortbuf1, ml_get(l1.lnum) + l1.st_u.line.start_col_nr, l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr + 1); sortbuf1[l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr] = 0; *************** *** 356,362 **** : STRCMP(sortbuf1, sortbuf2); } ! /* If two lines have the same value, preserve the original line order. */ if (result == 0) return (int)(l1.lnum - l2.lnum); return result; --- 356,362 ---- : STRCMP(sortbuf1, sortbuf2); } ! // If two lines have the same value, preserve the original line order. if (result == 0) return (int)(l1.lnum - l2.lnum); return result; *************** *** 378,384 **** char_u *p; char_u *s; char_u *s2; ! char_u c; /* temporary character storage */ int unique = FALSE; long deleted; colnr_T start_col; --- 378,384 ---- char_u *p; char_u *s; char_u *s2; ! char_u c; // temporary character storage int unique = FALSE; long deleted; colnr_T start_col; *************** *** 387,393 **** int format_found = 0; int change_occurred = FALSE; // Buffer contents changed. ! /* Sorting one line is really quick! */ if (count <= 1) return; --- 387,393 ---- int format_found = 0; int change_occurred = FALSE; // Buffer contents changed. ! // Sorting one line is really quick! if (count <= 1) return; *************** *** 442,448 **** } else if (*p == 'u') unique = TRUE; ! else if (*p == '"') /* comment start */ break; else if (check_nextcmd(p) != NULL) { --- 442,448 ---- } else if (*p == 'u') unique = TRUE; ! else if (*p == '"') // comment start break; else if (check_nextcmd(p) != NULL) { *************** *** 458,464 **** goto sortend; } *s = NUL; ! /* Use last search pattern if sort pattern is empty. */ if (s == p + 1) { if (last_search_pat() == NULL) --- 458,464 ---- goto sortend; } *s = NUL; ! // Use last search pattern if sort pattern is empty. if (s == p + 1) { if (last_search_pat() == NULL) *************** *** 472,478 **** regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); if (regmatch.regprog == NULL) goto sortend; ! p = s; /* continue after the regexp */ regmatch.rm_ic = p_ic; } else --- 472,478 ---- regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); if (regmatch.regprog == NULL) goto sortend; ! p = s; // continue after the regexp regmatch.rm_ic = p_ic; } else *************** *** 482,496 **** } } ! /* Can only have one of 'n', 'b', 'o' and 'x'. */ if (format_found > 1) { emsg(_(e_invarg)); goto sortend; } ! /* From here on "sort_nr" is used as a flag for any integer number ! * sorting. */ sort_nr += sort_what; /* --- 482,496 ---- } } ! // Can only have one of 'n', 'b', 'o' and 'x'. if (format_found > 1) { emsg(_(e_invarg)); goto sortend; } ! // From here on "sort_nr" is used as a flag for any integer number ! // sorting. sort_nr += sort_what; /* *************** *** 530,541 **** #endif ) { ! /* Make sure vim_str2nr doesn't read any digits past the end ! * of the match, by temporarily terminating the string there */ s2 = s + end_col; c = *s2; *s2 = NUL; ! /* Sorting on number: Store the number itself. */ p = s + start_col; if (sort_nr) { --- 530,541 ---- #endif ) { ! // Make sure vim_str2nr doesn't read any digits past the end ! // of the match, by temporarily terminating the string there s2 = s + end_col; c = *s2; *s2 = NUL; ! // Sorting on number: Store the number itself. p = s + start_col; if (sort_nr) { *************** *** 546,555 **** else s = skiptodigit(p); if (s > p && s[-1] == '-') ! --s; /* include preceding negative sign */ if (*s == NUL) { ! /* line without number should sort before any number */ nrs[lnum - eap->line1].st_u.num.is_number = FALSE; nrs[lnum - eap->line1].st_u.num.value = 0; } --- 546,555 ---- else s = skiptodigit(p); if (s > p && s[-1] == '-') ! --s; // include preceding negative sign if (*s == NUL) { ! // line without number should sort before any number nrs[lnum - eap->line1].st_u.num.is_number = FALSE; nrs[lnum - eap->line1].st_u.num.value = 0; } *************** *** 569,575 **** s = skipwhite(s + 1); if (*s == NUL) ! /* empty line should sort before any number */ nrs[lnum - eap->line1].st_u.value_flt = -DBL_MAX; else nrs[lnum - eap->line1].st_u.value_flt = --- 569,575 ---- s = skipwhite(s + 1); if (*s == NUL) ! // empty line should sort before any number nrs[lnum - eap->line1].st_u.value_flt = -DBL_MAX; else nrs[lnum - eap->line1].st_u.value_flt = *************** *** 580,586 **** } else { ! /* Store the column to sort at. */ nrs[lnum - eap->line1].st_u.line.start_col_nr = start_col; nrs[lnum - eap->line1].st_u.line.end_col_nr = end_col; } --- 580,586 ---- } else { ! // Store the column to sort at. nrs[lnum - eap->line1].st_u.line.start_col_nr = start_col; nrs[lnum - eap->line1].st_u.line.end_col_nr = end_col; } *************** *** 593,599 **** goto sortend; } ! /* Allocate a buffer that can hold the longest line. */ sortbuf1 = alloc(maxlen + 1); if (sortbuf1 == NULL) goto sortend; --- 593,599 ---- goto sortend; } ! // Allocate a buffer that can hold the longest line. sortbuf1 = alloc(maxlen + 1); if (sortbuf1 == NULL) goto sortend; *************** *** 601,613 **** if (sortbuf2 == NULL) goto sortend; ! /* Sort the array of line numbers. Note: can't be interrupted! */ qsort((void *)nrs, count, sizeof(sorti_T), sort_compare); if (sort_abort) goto sortend; ! /* Insert the lines in the sorted order below the last one. */ lnum = eap->line2; for (i = 0; i < count; ++i) { --- 601,613 ---- if (sortbuf2 == NULL) goto sortend; ! // Sort the array of line numbers. Note: can't be interrupted! qsort((void *)nrs, count, sizeof(sorti_T), sort_compare); if (sort_abort) goto sortend; ! // Insert the lines in the sorted order below the last one. lnum = eap->line2; for (i = 0; i < count; ++i) { *************** *** 633,646 **** goto sortend; } ! /* delete the original lines if appending worked */ if (i == count) for (i = 0; i < count; ++i) ml_delete(eap->line1, FALSE); else count = 0; ! /* Adjust marks for deleted (or added) lines and prepare for displaying. */ deleted = (long)(count - (lnum - eap->line2)); if (deleted > 0) { --- 633,646 ---- goto sortend; } ! // delete the original lines if appending worked if (i == count) for (i = 0; i < count; ++i) ml_delete(eap->line1, FALSE); else count = 0; ! // Adjust marks for deleted (or added) lines and prepare for displaying. deleted = (long)(count - (lnum - eap->line2)); if (deleted > 0) { *************** *** 844,858 **** curwin->w_cursor.lnum = n; while (line1 <= line2) { ! /* need to use vim_strsave() because the line will be unlocked within ! * ml_append() */ p = vim_strsave(ml_get(line1)); if (p != NULL) { ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); vim_free(p); } ! /* situation 2: skip already copied lines */ if (line1 == n) line1 = curwin->w_cursor.lnum; ++line1; --- 844,858 ---- curwin->w_cursor.lnum = n; while (line1 <= line2) { ! // need to use vim_strsave() because the line will be unlocked within ! // ml_append() p = vim_strsave(ml_get(line1)); if (p != NULL) { ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); vim_free(p); } ! // situation 2: skip already copied lines if (line1 == n) line1 = curwin->w_cursor.lnum; ++line1; *************** *** 868,874 **** msgmore((long)count); } ! static char_u *prevcmd = NULL; /* the previous command */ #if defined(EXITFREE) || defined(PROTO) void --- 868,874 ---- msgmore((long)count); } ! static char_u *prevcmd = NULL; // the previous command #if defined(EXITFREE) || defined(PROTO) void *************** *** 891,901 **** int do_in, int do_out) { ! char_u *arg = eap->arg; /* command */ ! linenr_T line1 = eap->line1; /* start of range */ ! linenr_T line2 = eap->line2; /* end of range */ ! char_u *newcmd = NULL; /* the new command */ ! int free_newcmd = FALSE; /* need to free() newcmd */ int ins_prevcmd; char_u *t; char_u *p; --- 891,901 ---- int do_in, int do_out) { ! char_u *arg = eap->arg; // command ! linenr_T line1 = eap->line1; // start of range ! linenr_T line2 = eap->line2; // end of range ! char_u *newcmd = NULL; // the new command ! int free_newcmd = FALSE; // need to free() newcmd int ins_prevcmd; char_u *t; char_u *p; *************** *** 911,919 **** if (check_restricted() || check_secure()) return; ! if (addr_count == 0) /* :! */ { ! msg_scroll = FALSE; /* don't scroll here */ autowrite_all(); msg_scroll = scroll_save; } --- 911,919 ---- if (check_restricted() || check_secure()) return; ! if (addr_count == 0) // :! { ! msg_scroll = FALSE; // don't scroll here autowrite_all(); msg_scroll = scroll_save; } *************** *** 980,990 **** vim_free(prevcmd); prevcmd = newcmd; ! if (bangredo) /* put cmd in redo buffer for ! command */ { ! /* If % or # appears in the command, it must have been escaped. ! * Reescape them, so that redoing them does not substitute them by the ! * buffername. */ char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); if (cmd != NULL) --- 980,990 ---- vim_free(prevcmd); prevcmd = newcmd; ! if (bangredo) // put cmd in redo buffer for ! command { ! // If % or # appears in the command, it must have been escaped. ! // Reescape them, so that redoing them does not substitute them by the ! // buffername. char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); if (cmd != NULL) *************** *** 1010,1018 **** STRCAT(newcmd, p_shq); free_newcmd = TRUE; } ! if (addr_count == 0) /* :! */ { ! /* echo the command */ msg_start(); msg_putchar(':'); msg_putchar('!'); --- 1010,1018 ---- STRCAT(newcmd, p_shq); free_newcmd = TRUE; } ! if (addr_count == 0) // :! { ! // echo the command msg_start(); msg_putchar(':'); msg_putchar('!'); *************** *** 1022,1031 **** do_shell(newcmd, 0); } ! else /* :range! */ { ! /* Careful: This may recursively call do_bang() again! (because of ! * autocommands) */ do_filter(line1, line2, eap, newcmd, do_in, do_out); apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); } --- 1022,1031 ---- do_shell(newcmd, 0); } ! else // :range! { ! // Careful: This may recursively call do_bang() again! (because of ! // autocommands) do_filter(line1, line2, eap, newcmd, do_in, do_out); apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); } *************** *** 1052,1058 **** do_filter( linenr_T line1, linenr_T line2, ! exarg_T *eap, /* for forced 'ff' and 'fenc' */ char_u *cmd, int do_in, int do_out) --- 1052,1058 ---- do_filter( linenr_T line1, linenr_T line2, ! exarg_T *eap, // for forced 'ff' and 'fenc' char_u *cmd, int do_in, int do_out) *************** *** 1072,1078 **** int stmp = p_stmp; #endif ! if (*cmd == NUL) /* no filter command */ return; // Temporarily disable lockmarks since that's needed to propagate changed --- 1072,1078 ---- int stmp = p_stmp; #endif ! if (*cmd == NUL) // no filter command return; // Temporarily disable lockmarks since that's needed to propagate changed *************** *** 1110,1130 **** if (!do_in && do_out && !stmp) { ! /* Use a pipe to fetch stdout of the command, do not use a temp file. */ shell_flags |= SHELL_READ; curwin->w_cursor.lnum = line2; } else if (do_in && !do_out && !stmp) { ! /* Use a pipe to write stdin of the command, do not use a temp file. */ shell_flags |= SHELL_WRITE; curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; } else if (do_in && do_out && !stmp) { ! /* Use a pipe to write stdin and fetch stdout of the command, do not ! * use a temp file. */ shell_flags |= SHELL_READ|SHELL_WRITE; curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; --- 1110,1130 ---- if (!do_in && do_out && !stmp) { ! // Use a pipe to fetch stdout of the command, do not use a temp file. shell_flags |= SHELL_READ; curwin->w_cursor.lnum = line2; } else if (do_in && !do_out && !stmp) { ! // Use a pipe to write stdin of the command, do not use a temp file. shell_flags |= SHELL_WRITE; curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; } else if (do_in && do_out && !stmp) { ! // Use a pipe to write stdin and fetch stdout of the command, do not ! // use a temp file. shell_flags |= SHELL_READ|SHELL_WRITE; curbuf->b_op_start.lnum = line1; curbuf->b_op_end.lnum = line2; *************** *** 1143,1158 **** * The writing and reading of temp files will not be shown. * Vi also doesn't do this and the messages are not very informative. */ ! ++no_wait_return; /* don't call wait_return() while busy */ if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, FALSE, FALSE, FALSE, TRUE) == FAIL) { ! msg_putchar('\n'); /* keep message from buf_write() */ --no_wait_return; #if defined(FEAT_EVAL) if (!aborting()) #endif ! (void)semsg(_(e_notcreate), itmp); /* will call wait_return */ goto filterend; } if (curbuf != old_curbuf) --- 1143,1158 ---- * The writing and reading of temp files will not be shown. * Vi also doesn't do this and the messages are not very informative. */ ! ++no_wait_return; // don't call wait_return() while busy if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, FALSE, FALSE, FALSE, TRUE) == FAIL) { ! msg_putchar('\n'); // keep message from buf_write() --no_wait_return; #if defined(FEAT_EVAL) if (!aborting()) #endif ! (void)semsg(_(e_notcreate), itmp); // will call wait_return goto filterend; } if (curbuf != old_curbuf) *************** *** 1161,1167 **** if (!do_out) msg_putchar('\n'); ! /* Create the shell command in allocated memory. */ cmd_buf = make_filter_cmd(cmd, itmp, otmp); if (cmd_buf == NULL) goto filterend; --- 1161,1167 ---- if (!do_out) msg_putchar('\n'); ! // Create the shell command in allocated memory. cmd_buf = make_filter_cmd(cmd, itmp, otmp); if (cmd_buf == NULL) goto filterend; *************** *** 1209,1217 **** did_check_timestamps = FALSE; need_check_timestamps = TRUE; ! /* When interrupting the shell command, it may still have produced some ! * useful output. Reset got_int here, so that readfile() won't cancel ! * reading. */ ui_breakcheck(); got_int = FALSE; --- 1209,1217 ---- did_check_timestamps = FALSE; need_check_timestamps = TRUE; ! // When interrupting the shell command, it may still have produced some ! // useful output. Reset got_int here, so that readfile() won't cancel ! // reading. ui_breakcheck(); got_int = FALSE; *************** *** 1249,1260 **** if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) { if (read_linecount >= linecount) ! /* move all marks from old lines to new lines */ mark_adjust(line1, line2, linecount, 0L); else { ! /* move marks from old lines to new lines, delete marks ! * that are in deleted lines */ mark_adjust(line1, line1 + read_linecount - 1, linecount, 0L); mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L); --- 1249,1260 ---- if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) { if (read_linecount >= linecount) ! // move all marks from old lines to new lines mark_adjust(line1, line2, linecount, 0L); else { ! // move marks from old lines to new lines, delete marks ! // that are in deleted lines mark_adjust(line1, line1 + read_linecount - 1, linecount, 0L); mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L); *************** *** 1267,1276 **** */ curwin->w_cursor.lnum = line1; del_lines(linecount, TRUE); ! curbuf->b_op_start.lnum -= linecount; /* adjust '[ */ ! curbuf->b_op_end.lnum -= linecount; /* adjust '] */ ! write_lnum_adjust(-linecount); /* adjust last line ! for next write */ #ifdef FEAT_FOLDING foldUpdate(curwin, curbuf->b_op_start.lnum, curbuf->b_op_end.lnum); #endif --- 1267,1276 ---- */ curwin->w_cursor.lnum = line1; del_lines(linecount, TRUE); ! curbuf->b_op_start.lnum -= linecount; // adjust '[ ! curbuf->b_op_end.lnum -= linecount; // adjust '] ! write_lnum_adjust(-linecount); // adjust last line ! // for next write #ifdef FEAT_FOLDING foldUpdate(curwin, curbuf->b_op_start.lnum, curbuf->b_op_end.lnum); #endif *************** *** 1284,1290 **** curwin->w_cursor.lnum = curbuf->b_op_end.lnum; } ! beginline(BL_WHITE | BL_FIX); /* cursor on first non-blank */ --no_wait_return; if (linecount > p_report) --- 1284,1290 ---- curwin->w_cursor.lnum = curbuf->b_op_end.lnum; } ! beginline(BL_WHITE | BL_FIX); // cursor on first non-blank --no_wait_return; if (linecount > p_report) *************** *** 1294,1300 **** vim_snprintf(msg_buf, sizeof(msg_buf), _("%ld lines filtered"), (long)linecount); if (msg(msg_buf) && !msg_scroll) ! /* save message to display it after redraw */ set_keep_msg((char_u *)msg_buf, 0); } else --- 1294,1300 ---- vim_snprintf(msg_buf, sizeof(msg_buf), _("%ld lines filtered"), (long)linecount); if (msg(msg_buf) && !msg_scroll) ! // save message to display it after redraw set_keep_msg((char_u *)msg_buf, 0); } else *************** *** 1304,1310 **** else { error: ! /* put cursor back in same position for ":w !cmd" */ curwin->w_cursor = cursor_save; --no_wait_return; wait_return(FALSE); --- 1304,1310 ---- else { error: ! // put cursor back in same position for ":w !cmd" curwin->w_cursor = cursor_save; --no_wait_return; wait_return(FALSE); *************** *** 1339,1345 **** void do_shell( char_u *cmd, ! int flags) /* may be SHELL_DOOUT when output is redirected */ { buf_T *buf; #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) --- 1339,1345 ---- void do_shell( char_u *cmd, ! int flags) // may be SHELL_DOOUT when output is redirected { buf_T *buf; #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) *************** *** 1473,1479 **** no_wait_return = save_nwr; } } ! #endif /* FEAT_GUI_MSWIN */ #ifdef MSWIN if (!keep_termcap) // if keep_termcap is TRUE didn't stop termcap --- 1473,1479 ---- no_wait_return = save_nwr; } } ! #endif // FEAT_GUI_MSWIN #ifdef MSWIN if (!keep_termcap) // if keep_termcap is TRUE didn't stop termcap *************** *** 1488,1510 **** * but it saves an extra redraw. */ #ifdef AMIGA ! if (skip_redraw) /* ':' hit in wait_return() */ { if (msg_silent == 0) redraw_later_clear(); } else if (term_console) { ! OUT_STR(IF_EB("\033[0 q", ESC_STR "[0 q")); /* get window size */ if (got_int && msg_silent == 0) ! redraw_later_clear(); /* if got_int is TRUE, redraw needed */ else ! must_redraw = 0; /* no extra redraw needed */ } #endif } ! /* display any error messages now */ display_errors(); apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf); --- 1488,1510 ---- * but it saves an extra redraw. */ #ifdef AMIGA ! if (skip_redraw) // ':' hit in wait_return() { if (msg_silent == 0) redraw_later_clear(); } else if (term_console) { ! OUT_STR(IF_EB("\033[0 q", ESC_STR "[0 q")); // get window size if (got_int && msg_silent == 0) ! redraw_later_clear(); // if got_int is TRUE, redraw needed else ! must_redraw = 0; // no extra redraw needed } #endif } ! // display any error messages now display_errors(); apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf); *************** *** 1537,1545 **** */ char_u * make_filter_cmd( ! char_u *cmd, /* command */ ! char_u *itmp, /* NULL or name of input file */ ! char_u *otmp) /* NULL or name of output file */ { char_u *buf; long_u len; --- 1537,1545 ---- */ char_u * make_filter_cmd( ! char_u *cmd, // command ! char_u *itmp, // NULL or name of input file ! char_u *otmp) // NULL or name of output file { char_u *buf; long_u len; *************** *** 1548,1565 **** int is_fish_shell; char_u *shell_name = get_isolated_shell_name(); ! /* Account for fish's different syntax for subshells */ is_fish_shell = (fnamecmp(shell_name, "fish") == 0); vim_free(shell_name); if (is_fish_shell) ! len = (long_u)STRLEN(cmd) + 13; /* "begin; " + "; end" + NUL */ else #endif ! len = (long_u)STRLEN(cmd) + 3; /* "()" + NUL */ if (itmp != NULL) ! len += (long_u)STRLEN(itmp) + 9; /* " { < " + " } " */ if (otmp != NULL) ! len += (long_u)STRLEN(otmp) + (long_u)STRLEN(p_srr) + 2; /* " " */ buf = alloc(len); if (buf == NULL) return NULL; --- 1548,1565 ---- int is_fish_shell; char_u *shell_name = get_isolated_shell_name(); ! // Account for fish's different syntax for subshells is_fish_shell = (fnamecmp(shell_name, "fish") == 0); vim_free(shell_name); if (is_fish_shell) ! len = (long_u)STRLEN(cmd) + 13; // "begin; " + "; end" + NUL else #endif ! len = (long_u)STRLEN(cmd) + 3; // "()" + NUL if (itmp != NULL) ! len += (long_u)STRLEN(itmp) + 9; // " { < " + " } " if (otmp != NULL) ! len += (long_u)STRLEN(otmp) + (long_u)STRLEN(p_srr) + 2; // " " buf = alloc(len); if (buf == NULL) return NULL; *************** *** 1720,1726 **** { vim_snprintf(numbuf, sizeof(numbuf), "%*ld ", number_width(curwin), (long)lnum); ! msg_puts_attr(numbuf, HL_ATTR(HLF_N)); /* Highlight line nrs */ } msg_prt_line(ml_get(lnum), list); } --- 1720,1726 ---- { vim_snprintf(numbuf, sizeof(numbuf), "%*ld ", number_width(curwin), (long)lnum); ! msg_puts_attr(numbuf, HL_ATTR(HLF_N)); // Highlight line nrs } msg_prt_line(ml_get(lnum), list); } *************** *** 1733,1750 **** { int save_silent = silent_mode; ! /* apply :filter /pat/ */ if (message_filtered(ml_get(lnum))) return; msg_start(); silent_mode = FALSE; ! info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ print_line_no_prefix(lnum, use_number, list); if (save_silent) { msg_putchar('\n'); ! cursor_on(); /* msg_start() switches it off */ out_flush(); silent_mode = save_silent; } --- 1733,1750 ---- { int save_silent = silent_mode; ! // apply :filter /pat/ if (message_filtered(ml_get(lnum))) return; msg_start(); silent_mode = FALSE; ! info_message = TRUE; // use mch_msg(), not mch_errmsg() print_line_no_prefix(lnum, use_number, list); if (save_silent) { msg_putchar('\n'); ! cursor_on(); // msg_start() switches it off out_flush(); silent_mode = save_silent; } *************** *** 1759,1769 **** buf = curbuf; apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); ! /* buffer changed, don't change name now */ if (buf != curbuf) return FAIL; #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return FAIL; #endif /* --- 1759,1769 ---- buf = curbuf; apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); ! // buffer changed, don't change name now if (buf != curbuf) return FAIL; #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return FAIL; #endif /* *************** *** 1795,1801 **** vim_free(sfname); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); ! /* Change directories when the 'acd' option is set. */ DO_AUTOCHDIR; return OK; } --- 1795,1801 ---- vim_free(sfname); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); ! // Change directories when the 'acd' option is set. DO_AUTOCHDIR; return OK; } *************** *** 1806,1813 **** void ex_file(exarg_T *eap) { ! /* ":0file" removes the file name. Check for illegal uses ":3file", ! * "0file name", etc. */ if (eap->addr_count > 0 && (*eap->arg != NUL || eap->line2 > 0 --- 1806,1813 ---- void ex_file(exarg_T *eap) { ! // ":0file" removes the file name. Check for illegal uses ":3file", ! // "0file name", etc. if (eap->addr_count > 0 && (*eap->arg != NUL || eap->line2 > 0 *************** *** 1852,1858 **** eap->line2 = curbuf->b_ml.ml_line_count; } ! if (eap->usefilter) /* input lines to shell command */ do_bang(1, eap, FALSE, TRUE, FALSE); else (void)do_write(eap); --- 1852,1858 ---- eap->line2 = curbuf->b_ml.ml_line_count; } ! if (eap->usefilter) // input lines to shell command do_bang(1, eap, FALSE, TRUE, FALSE); else (void)do_write(eap); *************** *** 1870,1876 **** do_write(exarg_T *eap) { int other; ! char_u *fname = NULL; /* init to shut up gcc */ char_u *ffname; int retval = FAIL; char_u *free_fname = NULL; --- 1870,1876 ---- do_write(exarg_T *eap) { int other; ! char_u *fname = NULL; // init to shut up gcc char_u *ffname; int retval = FAIL; char_u *free_fname = NULL; *************** *** 1880,1886 **** buf_T *alt_buf = NULL; int name_was_missing; ! if (not_writing()) /* check 'write' option */ return FAIL; ffname = eap->arg; --- 1880,1886 ---- buf_T *alt_buf = NULL; int name_was_missing; ! if (not_writing()) // check 'write' option return FAIL; ffname = eap->arg; *************** *** 1928,1935 **** alt_buf = buflist_findname(ffname); if (alt_buf != NULL && alt_buf->b_ml.ml_mfp != NULL) { ! /* Overwriting a file that is loaded in another buffer is not a ! * good idea. */ emsg(_(e_bufloaded)); goto theend; } --- 1928,1935 ---- alt_buf = buflist_findname(ffname); if (alt_buf != NULL && alt_buf->b_ml.ml_mfp != NULL) { ! // Overwriting a file that is loaded in another buffer is not a ! // good idea. emsg(_(e_bufloaded)); goto theend; } *************** *** 1991,2005 **** if (curbuf != was_curbuf) #endif { ! /* buffer changed, don't change name now */ retval = FAIL; goto theend; } ! /* Exchange the file names for the current and the alternate ! * buffer. This makes it look like we are now editing the buffer ! * under the new name. Must be done before buf_write(), because ! * if there is no file name and 'cpo' contains 'F', it will set ! * the file name. */ fname = alt_buf->b_fname; alt_buf->b_fname = curbuf->b_fname; curbuf->b_fname = fname; --- 1991,2005 ---- if (curbuf != was_curbuf) #endif { ! // buffer changed, don't change name now retval = FAIL; goto theend; } ! // Exchange the file names for the current and the alternate ! // buffer. This makes it look like we are now editing the buffer ! // under the new name. Must be done before buf_write(), because ! // if there is no file name and 'cpo' contains 'F', it will set ! // the file name. fname = alt_buf->b_fname; alt_buf->b_fname = curbuf->b_fname; curbuf->b_fname = fname; *************** *** 2024,2035 **** if (curbuf != was_curbuf) #endif { ! /* buffer changed, don't write the file */ retval = FAIL; goto theend; } ! /* If 'filetype' was empty try detecting it now. */ if (*curbuf->b_p_ft == NUL) { if (au_has_group((char_u *)"filetypedetect")) --- 2024,2035 ---- if (curbuf != was_curbuf) #endif { ! // buffer changed, don't write the file retval = FAIL; goto theend; } ! // If 'filetype' was empty try detecting it now. if (*curbuf->b_p_ft == NUL) { if (au_has_group((char_u *)"filetypedetect")) *************** *** 2038,2045 **** do_modelines(0); } ! /* Autocommands may have changed buffer names, esp. when ! * 'autochdir' is set. */ fname = curbuf->b_sfname; } --- 2038,2045 ---- do_modelines(0); } ! // Autocommands may have changed buffer names, esp. when ! // 'autochdir' is set. fname = curbuf->b_sfname; } *************** *** 2048,2054 **** retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, eap, eap->append, eap->forceit, TRUE, FALSE); ! /* After ":saveas fname" reset 'readonly'. */ if (eap->cmdidx == CMD_saveas) { if (retval == OK) --- 2048,2054 ---- retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, eap, eap->append, eap->forceit, TRUE, FALSE); ! // After ":saveas fname" reset 'readonly'. if (eap->cmdidx == CMD_saveas) { if (retval == OK) *************** *** 2058,2065 **** } } ! /* Change directories when the 'acd' option is set and the file name ! * got changed or set. */ if (eap->cmdidx == CMD_saveas || name_was_missing) DO_AUTOCHDIR; } --- 2058,2065 ---- } } ! // Change directories when the 'acd' option is set and the file name ! // got changed or set. if (eap->cmdidx == CMD_saveas || name_was_missing) DO_AUTOCHDIR; } *************** *** 2082,2091 **** check_overwrite( exarg_T *eap, buf_T *buf, ! char_u *fname, /* file name to be used (can differ from ! buf->ffname) */ ! char_u *ffname, /* full path version of fname */ ! int other) /* writing under other name */ { /* * write to other file or b_flags set or not writing the whole file: --- 2082,2091 ---- check_overwrite( exarg_T *eap, buf_T *buf, ! char_u *fname, // file name to be used (can differ from ! // buf->ffname) ! char_u *ffname, // full path version of fname ! int other) // writing under other name { /* * write to other file or b_flags set or not writing the whole file: *************** *** 2105,2111 **** if (!eap->forceit && !eap->append) { #ifdef UNIX ! /* with UNIX it is possible to open a directory */ if (mch_isdir(ffname)) { semsg(_(e_isadir2), ffname); --- 2105,2111 ---- if (!eap->forceit && !eap->append) { #ifdef UNIX ! // with UNIX it is possible to open a directory if (mch_isdir(ffname)) { semsg(_(e_isadir2), ffname); *************** *** 2130,2136 **** } } ! /* For ":w! filename" check that no swap file exists for "filename". */ if (other && !emsg_silent) { char_u *dir; --- 2130,2136 ---- } } ! // For ":w! filename" check that no swap file exists for "filename". if (other && !emsg_silent) { char_u *dir; *************** *** 2138,2148 **** int r; char_u *swapname; ! /* We only try the first entry in 'directory', without checking if ! * it's writable. If the "." directory is not writable the write ! * will probably fail anyway. ! * Use 'shortname' of the current buffer, since there is no buffer ! * for the written file. */ if (*p_dir == NUL) { dir = alloc(5); --- 2138,2148 ---- int r; char_u *swapname; ! // We only try the first entry in 'directory', without checking if ! // it's writable. If the "." directory is not writable the write ! // will probably fail anyway. ! // Use 'shortname' of the current buffer, since there is no buffer ! // for the written file. if (*p_dir == NUL) { dir = alloc(5); *************** *** 2250,2256 **** break; } #ifdef FEAT_BROWSE ! /* ":browse wall": ask for file name if there isn't one */ if (buf->b_ffname == NULL && cmdmod.browse) browse_save_fname(buf); #endif --- 2250,2256 ---- break; } #ifdef FEAT_BROWSE ! // ":browse wall": ask for file name if there isn't one if (buf->b_ffname == NULL && cmdmod.browse) browse_save_fname(buf); #endif *************** *** 2272,2288 **** set_bufref(&bufref, buf); if (buf_write_all(buf, eap->forceit) == FAIL) ++error; ! /* an autocommand may have deleted the buffer */ if (!bufref_valid(&bufref)) buf = firstbuf; } ! eap->forceit = save_forceit; /* check_overwrite() may set it */ } } if (exiting) { if (!error) ! getout(0); /* exit Vim */ not_exiting(); } } --- 2272,2288 ---- set_bufref(&bufref, buf); if (buf_write_all(buf, eap->forceit) == FAIL) ++error; ! // an autocommand may have deleted the buffer if (!bufref_valid(&bufref)) buf = firstbuf; } ! eap->forceit = save_forceit; // check_overwrite() may set it } } if (exiting) { if (!error) ! getout(0); // exit Vim not_exiting(); } } *************** *** 2310,2319 **** { stat_T st; ! /* Handle a file being readonly when the 'readonly' option is set or when ! * the file exists and permissions are read-only. ! * We will send 0777 to check_file_readonly(), as the "perm" variable is ! * important for device checks but not here. */ if (!*forceit && (buf->b_p_ro || (mch_stat((char *)buf->b_ffname, &st) >= 0 && check_file_readonly(buf->b_ffname, 0777)))) --- 2310,2319 ---- { stat_T st; ! // Handle a file being readonly when the 'readonly' option is set or when ! // the file exists and permissions are read-only. ! // We will send 0777 to check_file_readonly(), as the "perm" variable is ! // important for device checks but not here. if (!*forceit && (buf->b_p_ro || (mch_stat((char *)buf->b_ffname, &st) >= 0 && check_file_readonly(buf->b_ffname, 0777)))) *************** *** 2332,2338 **** if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES) { ! /* Set forceit, to force the writing of a readonly file */ *forceit = TRUE; return FALSE; } --- 2332,2338 ---- if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES) { ! // Set forceit, to force the writing of a readonly file *forceit = TRUE; return FALSE; } *************** *** 2385,2400 **** if (fnum == 0) { ! /* make ffname full path, set sfname */ fname_expand(curbuf, &ffname, &sfname); other = otherfile(ffname); ! free_me = ffname; /* has been allocated, free() later */ } else other = (fnum != curbuf->b_fnum); if (other) ! ++no_wait_return; /* don't wait for autowrite message */ if (other && !forceit && curbuf->b_nwindows == 1 && !buf_hide(curbuf) && curbufIsChanged() && autowrite(curbuf, forceit) == FAIL) { --- 2385,2400 ---- if (fnum == 0) { ! // make ffname full path, set sfname fname_expand(curbuf, &ffname, &sfname); other = otherfile(ffname); ! free_me = ffname; // has been allocated, free() later } else other = (fnum != curbuf->b_fnum); if (other) ! ++no_wait_return; // don't wait for autowrite message if (other && !forceit && curbuf->b_nwindows == 1 && !buf_hide(curbuf) && curbufIsChanged() && autowrite(curbuf, forceit) == FAIL) { *************** *** 2407,2413 **** if (other) --no_wait_return; no_write_message(); ! retval = GETFILE_NOT_WRITTEN; /* file has been changed */ goto theend; } } --- 2407,2413 ---- if (other) --no_wait_return; no_write_message(); ! retval = GETFILE_NOT_WRITTEN; // file has been changed goto theend; } } *************** *** 2421,2434 **** curwin->w_cursor.lnum = lnum; check_cursor_lnum(); beginline(BL_SOL | BL_FIX); ! retval = GETFILE_SAME_FILE; /* it's in the same file */ } else if (do_ecmd(fnum, ffname, sfname, NULL, lnum, (buf_hide(curbuf) ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0), curwin) == OK) ! retval = GETFILE_OPEN_OTHER; /* opened another file */ else ! retval = GETFILE_ERROR; /* error encountered */ theend: vim_free(free_me); --- 2421,2434 ---- curwin->w_cursor.lnum = lnum; check_cursor_lnum(); beginline(BL_SOL | BL_FIX); ! retval = GETFILE_SAME_FILE; // it's in the same file } else if (do_ecmd(fnum, ffname, sfname, NULL, lnum, (buf_hide(curbuf) ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0), curwin) == OK) ! retval = GETFILE_OPEN_OTHER; // opened another file else ! retval = GETFILE_ERROR; // error encountered theend: vim_free(free_me); *************** *** 2469,2483 **** int fnum, char_u *ffname, char_u *sfname, ! exarg_T *eap, /* can be NULL! */ linenr_T newlnum, int flags, win_T *oldwin) { ! int other_file; /* TRUE if editing another file */ ! int oldbuf; /* TRUE if using existing buffer */ ! int auto_buf = FALSE; /* TRUE if autocommands brought us ! into the buffer unexpectedly */ char_u *new_name = NULL; #if defined(FEAT_EVAL) int did_set_swapcommand = FALSE; --- 2469,2483 ---- int fnum, char_u *ffname, char_u *sfname, ! exarg_T *eap, // can be NULL! linenr_T newlnum, int flags, win_T *oldwin) { ! int other_file; // TRUE if editing another file ! int oldbuf; // TRUE if using existing buffer ! int auto_buf = FALSE; // TRUE if autocommands brought us ! // into the buffer unexpectedly char_u *new_name = NULL; #if defined(FEAT_EVAL) int did_set_swapcommand = FALSE; *************** *** 2510,2517 **** if (fnum != 0) { ! if (fnum == curbuf->b_fnum) /* file is already being edited */ ! return OK; /* nothing to do */ other_file = TRUE; } else --- 2510,2517 ---- if (fnum != 0) { ! if (fnum == curbuf->b_fnum) // file is already being edited ! return OK; // nothing to do other_file = TRUE; } else *************** *** 2525,2532 **** # endif au_has_group((char_u *)"FileExplorer")) { ! /* No browsing supported but we do have the file explorer: ! * Edit the directory. */ if (ffname == NULL || !mch_isdir(ffname)) ffname = (char_u *)"."; } --- 2525,2532 ---- # endif au_has_group((char_u *)"FileExplorer")) { ! // No browsing supported but we do have the file explorer: ! // Edit the directory. if (ffname == NULL || !mch_isdir(ffname)) ffname = (char_u *)"."; } *************** *** 2540,2551 **** } } #endif ! /* if no short name given, use ffname for short name */ if (sfname == NULL) sfname = ffname; #ifdef USE_FNAME_CASE if (sfname != NULL) ! fname_case(sfname, 0); /* set correct case for sfname */ #endif if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL)) --- 2540,2551 ---- } } #endif ! // if no short name given, use ffname for short name if (sfname == NULL) sfname = ffname; #ifdef USE_FNAME_CASE if (sfname != NULL) ! fname_case(sfname, 0); // set correct case for sfname #endif if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL)) *************** *** 2553,2569 **** if (ffname == NULL) other_file = TRUE; ! /* there is no file name */ else if (*ffname == NUL && curbuf->b_ffname == NULL) other_file = FALSE; else { ! if (*ffname == NUL) /* re-edit with same file name */ { ffname = curbuf->b_ffname; sfname = curbuf->b_fname; } ! free_fname = fix_fname(ffname); /* may expand to full path name */ if (free_fname != NULL) ffname = free_fname; other_file = otherfile(ffname); --- 2553,2569 ---- if (ffname == NULL) other_file = TRUE; ! // there is no file name else if (*ffname == NUL && curbuf->b_ffname == NULL) other_file = FALSE; else { ! if (*ffname == NUL) // re-edit with same file name { ffname = curbuf->b_ffname; sfname = curbuf->b_fname; } ! free_fname = fix_fname(ffname); // may expand to full path name if (free_fname != NULL) ffname = free_fname; other_file = otherfile(ffname); *************** *** 2601,2607 **** int len; char_u *p; ! /* Set v:swapcommand for the SwapExists autocommands. */ if (command != NULL) len = (int)STRLEN(command) + 3; else --- 2601,2607 ---- int len; char_u *p; ! // Set v:swapcommand for the SwapExists autocommands. if (command != NULL) len = (int)STRLEN(command) + 3; else *************** *** 2654,2687 **** buf = buflist_new(ffname, sfname, 0L, BLN_CURBUF | ((flags & ECMD_SET_HELP) ? 0 : BLN_LISTED)); ! /* autocommands may change curwin and curbuf */ if (oldwin != NULL) oldwin = curwin; set_bufref(&old_curbuf, curbuf); } if (buf == NULL) goto theend; ! if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */ { oldbuf = FALSE; } ! else /* existing memfile */ { oldbuf = TRUE; set_bufref(&bufref, buf); (void)buf_check_timestamp(buf, FALSE); ! /* Check if autocommands made the buffer invalid or changed the ! * current buffer. */ if (!bufref_valid(&bufref) || curbuf != old_curbuf.br_buf) goto theend; #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ goto theend; #endif } ! /* May jump to last used line number for a loaded buffer or when asked ! * for explicitly */ if ((oldbuf && newlnum == ECMD_LASTL) || newlnum == ECMD_LAST) { pos = buflist_findfpos(buf); --- 2654,2687 ---- buf = buflist_new(ffname, sfname, 0L, BLN_CURBUF | ((flags & ECMD_SET_HELP) ? 0 : BLN_LISTED)); ! // autocommands may change curwin and curbuf if (oldwin != NULL) oldwin = curwin; set_bufref(&old_curbuf, curbuf); } if (buf == NULL) goto theend; ! if (buf->b_ml.ml_mfp == NULL) // no memfile yet { oldbuf = FALSE; } ! else // existing memfile { oldbuf = TRUE; set_bufref(&bufref, buf); (void)buf_check_timestamp(buf, FALSE); ! // Check if autocommands made the buffer invalid or changed the ! // current buffer. if (!bufref_valid(&bufref) || curbuf != old_curbuf.br_buf) goto theend; #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing goto theend; #endif } ! // May jump to last used line number for a loaded buffer or when asked ! // for explicitly if ((oldbuf && newlnum == ECMD_LASTL) || newlnum == ECMD_LAST) { pos = buflist_findfpos(buf); *************** *** 2713,2745 **** apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); if (!bufref_valid(&au_new_curbuf)) { ! /* new buffer has been deleted */ ! delbuf_msg(new_name); /* frees new_name */ goto theend; } #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ { vim_free(new_name); goto theend; } #endif ! if (buf == curbuf) /* already in new buffer */ auto_buf = TRUE; else { win_T *the_curwin = curwin; ! /* Set the w_closing flag to avoid that autocommands close the ! * window. And set b_locked for the same reason. */ the_curwin->w_closing = TRUE; ++buf->b_locked; if (curbuf == old_curbuf.br_buf) buf_copy_options(buf, BCO_ENTER); ! /* Close the link to the current buffer. This will set ! * oldwin->w_buffer to NULL. */ u_sync(FALSE); close_buffer(oldwin, curbuf, (flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE); --- 2713,2745 ---- apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); if (!bufref_valid(&au_new_curbuf)) { ! // new buffer has been deleted ! delbuf_msg(new_name); // frees new_name goto theend; } #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing { vim_free(new_name); goto theend; } #endif ! if (buf == curbuf) // already in new buffer auto_buf = TRUE; else { win_T *the_curwin = curwin; ! // Set the w_closing flag to avoid that autocommands close the ! // window. And set b_locked for the same reason. the_curwin->w_closing = TRUE; ++buf->b_locked; if (curbuf == old_curbuf.br_buf) buf_copy_options(buf, BCO_ENTER); ! // Close the link to the current buffer. This will set ! // oldwin->w_buffer to NULL. u_sync(FALSE); close_buffer(oldwin, curbuf, (flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE); *************** *** 2748,2768 **** --buf->b_locked; #ifdef FEAT_EVAL ! /* autocmds may abort script processing */ if (aborting() && curwin->w_buffer != NULL) { vim_free(new_name); goto theend; } #endif ! /* Be careful again, like above. */ if (!bufref_valid(&au_new_curbuf)) { ! /* new buffer has been deleted */ ! delbuf_msg(new_name); /* frees new_name */ goto theend; } ! if (buf == curbuf) /* already in new buffer */ auto_buf = TRUE; else { --- 2748,2768 ---- --buf->b_locked; #ifdef FEAT_EVAL ! // autocmds may abort script processing if (aborting() && curwin->w_buffer != NULL) { vim_free(new_name); goto theend; } #endif ! // Be careful again, like above. if (!bufref_valid(&au_new_curbuf)) { ! // new buffer has been deleted ! delbuf_msg(new_name); // frees new_name goto theend; } ! if (buf == curbuf) // already in new buffer auto_buf = TRUE; else { *************** *** 2779,2785 **** curbuf = buf; ++curbuf->b_nwindows; ! /* Set 'fileformat', 'binary' and 'fenc' when forced. */ if (!oldbuf && eap != NULL) { set_file_options(TRUE, eap); --- 2779,2785 ---- curbuf = buf; ++curbuf->b_nwindows; ! // Set 'fileformat', 'binary' and 'fenc' when forced. if (!oldbuf && eap != NULL) { set_file_options(TRUE, eap); *************** *** 2787,2796 **** } } ! /* May get the window options from the last time this buffer ! * was in this window (or another window). If not used ! * before, reset the local window options to the global ! * values. Also restores old folding stuff. */ get_winopts(curbuf); #ifdef FEAT_SPELL did_get_winopts = TRUE; --- 2787,2796 ---- } } ! // May get the window options from the last time this buffer ! // was in this window (or another window). If not used ! // before, reset the local window options to the global ! // values. Also restores old folding stuff. get_winopts(curbuf); #ifdef FEAT_SPELL did_get_winopts = TRUE; *************** *** 2804,2810 **** curwin->w_pcmark.lnum = 1; curwin->w_pcmark.col = 0; } ! else /* !other_file */ { if ((flags & ECMD_ADDBUF) || check_fname() == FAIL) goto theend; --- 2804,2810 ---- curwin->w_pcmark.lnum = 1; curwin->w_pcmark.col = 0; } ! else // !other_file { if ((flags & ECMD_ADDBUF) || check_fname() == FAIL) goto theend; *************** *** 2812,2819 **** oldbuf = (flags & ECMD_OLDBUF); } ! /* Don't redraw until the cursor is in the right line, otherwise ! * autocommands may cause ml_get errors. */ ++RedrawingDisabled; did_inc_redrawing_disabled = TRUE; --- 2812,2819 ---- oldbuf = (flags & ECMD_OLDBUF); } ! // Don't redraw until the cursor is in the right line, otherwise ! // autocommands may cause ml_get errors. ++RedrawingDisabled; did_inc_redrawing_disabled = TRUE; *************** *** 2824,2847 **** } else { ! /* Don't make a buffer listed if it's a help buffer. Useful when ! * using CTRL-O to go back to a help file. */ if (!curbuf->b_help) set_buflisted(TRUE); } ! /* If autocommands change buffers under our fingers, forget about ! * editing the file. */ if (buf != curbuf) goto theend; #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ goto theend; #endif ! /* Since we are starting to edit a file, consider the filetype to be ! * unset. Helps for when an autocommand changes files and expects syntax ! * highlighting to work in the other file. */ did_filetype = FALSE; /* --- 2824,2847 ---- } else { ! // Don't make a buffer listed if it's a help buffer. Useful when ! // using CTRL-O to go back to a help file. if (!curbuf->b_help) set_buflisted(TRUE); } ! // If autocommands change buffers under our fingers, forget about ! // editing the file. if (buf != curbuf) goto theend; #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing goto theend; #endif ! // Since we are starting to edit a file, consider the filetype to be ! // unset. Helps for when an autocommand changes files and expects syntax ! // highlighting to work in the other file. did_filetype = FALSE; /* *************** *** 2851,2859 **** * TRUE FALSE start editing new file, new buffer * TRUE TRUE start editing in existing buffer (nothing to do) */ ! if (!other_file && !oldbuf) /* re-use the buffer */ { ! set_last_cursor(curwin); /* may set b_last_cursor */ if (newlnum == ECMD_LAST || newlnum == ECMD_LASTL) { newlnum = curwin->w_cursor.lnum; --- 2851,2859 ---- * TRUE FALSE start editing new file, new buffer * TRUE TRUE start editing in existing buffer (nothing to do) */ ! if (!other_file && !oldbuf) // re-use the buffer { ! set_last_cursor(curwin); // may set b_last_cursor if (newlnum == ECMD_LAST || newlnum == ECMD_LASTL) { newlnum = curwin->w_cursor.lnum; *************** *** 2868,2875 **** if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) { ! /* Save all the text, so that the reload can be undone. ! * Sync first so that this is a separate undo-able action. */ u_sync(FALSE); if (u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, TRUE) == FAIL) --- 2868,2875 ---- if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) { ! // Save all the text, so that the reload can be undone. ! // Sync first so that this is a separate undo-able action. u_sync(FALSE); if (u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, TRUE) == FAIL) *************** *** 2880,2918 **** u_unchanged(curbuf); buf_freeall(curbuf, BFA_KEEP_UNDO); ! /* tell readfile() not to clear or reload undo info */ readfile_flags = READ_KEEP_UNDO; } else ! buf_freeall(curbuf, 0); /* free all things for buffer */ ! /* If autocommands deleted the buffer we were going to re-edit, give ! * up and jump to the end. */ if (!bufref_valid(&bufref)) { ! delbuf_msg(new_name); /* frees new_name */ goto theend; } vim_free(new_name); ! /* If autocommands change buffers under our fingers, forget about ! * re-editing the file. Should do the buf_clear_file(), but perhaps ! * the autocommands changed the buffer... */ if (buf != curbuf) goto theend; #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ goto theend; #endif buf_clear_file(curbuf); ! curbuf->b_op_start.lnum = 0; /* clear '[ and '] marks */ curbuf->b_op_end.lnum = 0; } /* * If we get here we are sure to start editing */ ! /* Assume success now */ retval = OK; /* --- 2880,2918 ---- u_unchanged(curbuf); buf_freeall(curbuf, BFA_KEEP_UNDO); ! // tell readfile() not to clear or reload undo info readfile_flags = READ_KEEP_UNDO; } else ! buf_freeall(curbuf, 0); // free all things for buffer ! // If autocommands deleted the buffer we were going to re-edit, give ! // up and jump to the end. if (!bufref_valid(&bufref)) { ! delbuf_msg(new_name); // frees new_name goto theend; } vim_free(new_name); ! // If autocommands change buffers under our fingers, forget about ! // re-editing the file. Should do the buf_clear_file(), but perhaps ! // the autocommands changed the buffer... if (buf != curbuf) goto theend; #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing goto theend; #endif buf_clear_file(curbuf); ! curbuf->b_op_start.lnum = 0; // clear '[ and '] marks curbuf->b_op_end.lnum = 0; } /* * If we get here we are sure to start editing */ ! // Assume success now retval = OK; /* *************** *** 2930,2937 **** curwin_init(); #ifdef FEAT_FOLDING ! /* It's possible that all lines in the buffer changed. Need to update ! * automatic folding for all windows where it's used. */ { win_T *win; tabpage_T *tp; --- 2930,2937 ---- curwin_init(); #ifdef FEAT_FOLDING ! // It's possible that all lines in the buffer changed. Need to update ! // automatic folding for all windows where it's used. { win_T *win; tabpage_T *tp; *************** *** 2942,2948 **** } #endif ! /* Change directories when the 'acd' option is set. */ DO_AUTOCHDIR; /* --- 2942,2948 ---- } #endif ! // Change directories when the 'acd' option is set. DO_AUTOCHDIR; /* *************** *** 2951,2957 **** */ orig_pos = curwin->w_cursor; topline = curwin->w_topline; ! if (!oldbuf) /* need to read the file */ { #ifdef FEAT_PROP_POPUP // Don't use the swap-exists dialog for a popup window, can't edit --- 2951,2957 ---- */ orig_pos = curwin->w_cursor; topline = curwin->w_topline; ! if (!oldbuf) // need to read the file { #ifdef FEAT_PROP_POPUP // Don't use the swap-exists dialog for a popup window, can't edit *************** *** 2960,2966 **** curbuf->b_flags |= BF_NO_SEA; #endif swap_exists_action = SEA_DIALOG; ! curbuf->b_flags |= BF_CHECK_RO; /* set/reset 'ro' flag */ /* * Open the buffer and read the file. --- 2960,2966 ---- curbuf->b_flags |= BF_NO_SEA; #endif swap_exists_action = SEA_DIALOG; ! curbuf->b_flags |= BF_CHECK_RO; // set/reset 'ro' flag /* * Open the buffer and read the file. *************** *** 2981,2989 **** } else { ! /* Read the modelines, but only to set window-local options. Any ! * buffer-local options have already been set and may have been ! * changed by the user. */ do_modelines(OPT_WINONLY); apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, --- 2981,2989 ---- } else { ! // Read the modelines, but only to set window-local options. Any ! // buffer-local options have already been set and may have been ! // changed by the user. do_modelines(OPT_WINONLY); apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, *************** *** 2993,3001 **** } check_arg_idx(curwin); ! /* If autocommands change the cursor position or topline, we should ! * keep it. Also when it moves within a line. But not when it moves ! * to the first non-blank. */ if (!EQUAL_POS(curwin->w_cursor, orig_pos)) { char_u *text = ml_get_curline(); --- 2993,3001 ---- } check_arg_idx(curwin); ! // If autocommands change the cursor position or topline, we should ! // keep it. Also when it moves within a line. But not when it moves ! // to the first non-blank. if (!EQUAL_POS(curwin->w_cursor, orig_pos)) { char_u *text = ml_get_curline(); *************** *** 3010,3016 **** if (curwin->w_topline == topline) topline = 0; ! /* Even when cursor didn't move we need to recompute topline. */ changed_line_abv_curs(); #ifdef FEAT_TITLE --- 3010,3016 ---- if (curwin->w_topline == topline) topline = 0; ! // Even when cursor didn't move we need to recompute topline. changed_line_abv_curs(); #ifdef FEAT_TITLE *************** *** 3023,3031 **** } #ifdef FEAT_DIFF ! /* Tell the diff stuff that this buffer is new and/or needs updating. ! * Also needed when re-editing the same buffer, because unloading will ! * have removed it as a diff buffer. */ if (curwin->w_p_diff) { diff_buf_add(curbuf); --- 3023,3031 ---- } #ifdef FEAT_DIFF ! // Tell the diff stuff that this buffer is new and/or needs updating. ! // Also needed when re-editing the same buffer, because unloading will ! // have removed it as a diff buffer. if (curwin->w_p_diff) { diff_buf_add(curbuf); *************** *** 3034,3060 **** #endif #ifdef FEAT_SPELL ! /* If the window options were changed may need to set the spell language. ! * Can only do this after the buffer has been properly setup. */ if (did_get_winopts && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) (void)did_set_spelllang(curwin); #endif if (command == NULL) { ! if (newcol >= 0) /* position set by autocommands */ { curwin->w_cursor.lnum = newlnum; curwin->w_cursor.col = newcol; check_cursor(); } ! else if (newlnum > 0) /* line number from caller or old position */ { curwin->w_cursor.lnum = newlnum; check_cursor_lnum(); if (solcol >= 0 && !p_sol) { ! /* 'sol' is off: Use last known column. */ curwin->w_cursor.col = solcol; check_cursor_col(); curwin->w_cursor.coladd = 0; --- 3034,3060 ---- #endif #ifdef FEAT_SPELL ! // If the window options were changed may need to set the spell language. ! // Can only do this after the buffer has been properly setup. if (did_get_winopts && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) (void)did_set_spelllang(curwin); #endif if (command == NULL) { ! if (newcol >= 0) // position set by autocommands { curwin->w_cursor.lnum = newlnum; curwin->w_cursor.col = newcol; check_cursor(); } ! else if (newlnum > 0) // line number from caller or old position { curwin->w_cursor.lnum = newlnum; check_cursor_lnum(); if (solcol >= 0 && !p_sol) { ! // 'sol' is off: Use last known column. curwin->w_cursor.col = solcol; check_cursor_col(); curwin->w_cursor.coladd = 0; *************** *** 3063,3069 **** else beginline(BL_SOL | BL_FIX); } ! else /* no line number, go to last line in Ex mode */ { if (exmode_active) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; --- 3063,3069 ---- else beginline(BL_SOL | BL_FIX); } ! else // no line number, go to last line in Ex mode { if (exmode_active) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; *************** *** 3071,3077 **** } } ! /* Check if cursors in other windows on the same buffer are still valid */ check_lnums(FALSE); /* --- 3071,3077 ---- } } ! // Check if cursors in other windows on the same buffer are still valid check_lnums(FALSE); /* *************** *** 3082,3092 **** { int msg_scroll_save = msg_scroll; ! /* Obey the 'O' flag in 'cpoptions': overwrite any previous file ! * message. */ if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) msg_scroll = FALSE; ! if (!msg_scroll) /* wait a bit when overwriting an error msg */ check_for_delay(FALSE); msg_start(); msg_scroll = msg_scroll_save; --- 3082,3092 ---- { int msg_scroll_save = msg_scroll; ! // Obey the 'O' flag in 'cpoptions': overwrite any previous file ! // message. if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) msg_scroll = FALSE; ! if (!msg_scroll) // wait a bit when overwriting an error msg check_for_delay(FALSE); msg_start(); msg_scroll = msg_scroll_save; *************** *** 3120,3135 **** update_topline(); curwin->w_scbind_pos = curwin->w_topline; *so_ptr = n; ! redraw_curbuf_later(NOT_VALID); /* redraw this buffer later */ } if (p_im) need_start_insertmode = TRUE; #ifdef FEAT_AUTOCHDIR ! /* Change directories when the 'acd' option is set and we aren't already in ! * that directory (should already be done above). Expect getcwd() to be ! * faster than calling shorten_fnames() unnecessarily. */ if (p_acd && curbuf->b_ffname != NULL) { char_u curdir[MAXPATHL]; --- 3120,3135 ---- update_topline(); curwin->w_scbind_pos = curwin->w_topline; *so_ptr = n; ! redraw_curbuf_later(NOT_VALID); // redraw this buffer later } if (p_im) need_start_insertmode = TRUE; #ifdef FEAT_AUTOCHDIR ! // Change directories when the 'acd' option is set and we aren't already in ! // that directory (should already be done above). Expect getcwd() to be ! // faster than calling shorten_fnames() unnecessarily. if (p_acd && curbuf->b_ffname != NULL) { char_u curdir[MAXPATHL]; *************** *** 3177,3183 **** au_new_curbuf.br_buf_free_count = 0; } ! static int append_indent = 0; /* autoindent for first line */ /* * ":insert" and ":append", also used by ":change" --- 3177,3183 ---- au_new_curbuf.br_buf_free_count = 0; } ! static int append_indent = 0; // autoindent for first line /* * ":insert" and ":append", also used by ":change" *************** *** 3193,3214 **** int vcol; int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); ! /* the ! flag toggles autoindent */ if (eap->forceit) curbuf->b_p_ai = !curbuf->b_p_ai; ! /* First autoindent comes from the line we start on */ if (eap->cmdidx != CMD_change && curbuf->b_p_ai && lnum > 0) append_indent = get_indent_lnum(lnum); if (eap->cmdidx != CMD_append) --lnum; ! /* when the buffer is empty need to delete the dummy line */ if (empty && lnum == 1) lnum = 0; ! State = INSERT; /* behave like in Insert mode */ if (curbuf->b_p_iminsert == B_IMODE_LMAP) State |= LANGMAP; --- 3193,3214 ---- int vcol; int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); ! // the ! flag toggles autoindent if (eap->forceit) curbuf->b_p_ai = !curbuf->b_p_ai; ! // First autoindent comes from the line we start on if (eap->cmdidx != CMD_change && curbuf->b_p_ai && lnum > 0) append_indent = get_indent_lnum(lnum); if (eap->cmdidx != CMD_append) --lnum; ! // when the buffer is empty need to delete the dummy line if (empty && lnum == 1) lnum = 0; ! State = INSERT; // behave like in Insert mode if (curbuf->b_p_iminsert == B_IMODE_LMAP) State |= LANGMAP; *************** *** 3229,3236 **** ex_keep_indent = FALSE; if (eap->getline == NULL) { ! /* No getline() function, use the lines that follow. This ends ! * when there is no more. */ if (eap->nextcmd == NULL || *eap->nextcmd == NUL) break; p = vim_strchr(eap->nextcmd, NL); --- 3229,3236 ---- ex_keep_indent = FALSE; if (eap->getline == NULL) { ! // No getline() function, use the lines that follow. This ends ! // when there is no more. if (eap->nextcmd == NULL || *eap->nextcmd == NUL) break; p = vim_strchr(eap->nextcmd, NL); *************** *** 3245,3252 **** { int save_State = State; ! /* Set State to avoid the cursor shape to be set to INSERT mode ! * when getline() returns. */ State = CMDLINE; theline = eap->getline( #ifdef FEAT_EVAL --- 3245,3252 ---- { int save_State = State; ! // Set State to avoid the cursor shape to be set to INSERT mode ! // when getline() returns. State = CMDLINE; theline = eap->getline( #ifdef FEAT_EVAL *************** *** 3259,3269 **** if (theline == NULL) break; ! /* Using ^ CTRL-D in getexmodeline() makes us repeat the indent. */ if (ex_keep_indent) append_indent = indent; ! /* Look for the "." after automatic indent. */ vcol = 0; for (p = theline; indent > vcol; ++p) { --- 3259,3269 ---- if (theline == NULL) break; ! // Using ^ CTRL-D in getexmodeline() makes us repeat the indent. if (ex_keep_indent) append_indent = indent; ! // Look for the "." after automatic indent. vcol = 0; for (p = theline; indent > vcol; ++p) { *************** *** 3282,3288 **** break; } ! /* don't use autoindent if nothing was typed. */ if (p[0] == NUL) theline[0] = NUL; --- 3282,3288 ---- break; } ! // don't use autoindent if nothing was typed. if (p[0] == NUL) theline[0] = NUL; *************** *** 3304,3313 **** if (eap->forceit) curbuf->b_p_ai = !curbuf->b_p_ai; ! /* "start" is set to eap->line2+1 unless that position is invalid (when ! * eap->line2 pointed to the end of the buffer and nothing was appended) ! * "end" is set to lnum when something has been appended, otherwise ! * it is the same than "start" -- Acevedo */ if (!cmdmod.lockmarks) { curbuf->b_op_start.lnum = (eap->line2 < curbuf->b_ml.ml_line_count) ? --- 3304,3313 ---- if (eap->forceit) curbuf->b_p_ai = !curbuf->b_p_ai; ! // "start" is set to eap->line2+1 unless that position is invalid (when ! // eap->line2 pointed to the end of the buffer and nothing was appended) ! // "end" is set to lnum when something has been appended, otherwise ! // it is the same than "start" -- Acevedo if (!cmdmod.lockmarks) { curbuf->b_op_start.lnum = (eap->line2 < curbuf->b_ml.ml_line_count) ? *************** *** 3322,3328 **** check_cursor_lnum(); beginline(BL_SOL | BL_FIX); ! need_wait_return = FALSE; /* don't use wait_return() now */ ex_no_reprint = TRUE; } --- 3322,3328 ---- check_cursor_lnum(); beginline(BL_SOL | BL_FIX); ! need_wait_return = FALSE; // don't use wait_return() now ex_no_reprint = TRUE; } *************** *** 3338,3359 **** && u_save(eap->line1 - 1, eap->line2 + 1) == FAIL) return; ! /* the ! flag toggles autoindent */ if (eap->forceit ? !curbuf->b_p_ai : curbuf->b_p_ai) append_indent = get_indent_lnum(eap->line1); for (lnum = eap->line2; lnum >= eap->line1; --lnum) { ! if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */ break; ml_delete(eap->line1, FALSE); } ! /* make sure the cursor is not beyond the end of the file now */ check_cursor_lnum(); deleted_lines_mark(eap->line1, (long)(eap->line2 - lnum)); ! /* ":append" on the line above the deleted lines. */ eap->line2 = eap->line1; ex_append(eap); } --- 3338,3359 ---- && u_save(eap->line1 - 1, eap->line2 + 1) == FAIL) return; ! // the ! flag toggles autoindent if (eap->forceit ? !curbuf->b_p_ai : curbuf->b_p_ai) append_indent = get_indent_lnum(eap->line1); for (lnum = eap->line2; lnum >= eap->line1; --lnum) { ! if (curbuf->b_ml.ml_flags & ML_EMPTY) // nothing to delete break; ml_delete(eap->line1, FALSE); } ! // make sure the cursor is not beyond the end of the file now check_cursor_lnum(); deleted_lines_mark(eap->line1, (long)(eap->line2 - lnum)); ! // ":append" on the line above the deleted lines. eap->line2 = eap->line1; ex_append(eap); } *************** *** 3369,3376 **** int j; linenr_T lnum = eap->line2; ! /* Vi compatible: ":z!" uses display height, without a count uses ! * 'scroll' */ if (eap->forceit) bigness = curwin->w_height; else if (!ONE_WINDOW) --- 3369,3376 ---- int j; linenr_T lnum = eap->line2; ! // Vi compatible: ":z!" uses display height, without a count uses ! // 'scroll' if (eap->forceit) bigness = curwin->w_height; else if (!ONE_WINDOW) *************** *** 3399,3405 **** { bigness = atol((char *)x); ! /* bigness could be < 0 if atol(x) overflows. */ if (bigness > 2 * curbuf->b_ml.ml_line_count || bigness < 0) bigness = 2 * curbuf->b_ml.ml_line_count; --- 3399,3405 ---- { bigness = atol((char *)x); ! // bigness could be < 0 if atol(x) overflows. if (bigness > 2 * curbuf->b_ml.ml_line_count || bigness < 0) bigness = 2 * curbuf->b_ml.ml_line_count; *************** *** 3409,3415 **** } } ! /* the number of '-' and '+' multiplies the distance */ if (*kind == '-' || *kind == '+') for (x = kind + 1; *x == *kind; ++x) ; --- 3409,3415 ---- } } ! // the number of '-' and '+' multiplies the distance if (*kind == '-' || *kind == '+') for (x = kind + 1; *x == *kind; ++x) ; *************** *** 3441,3447 **** curs = end; break; ! default: /* '+' */ start = lnum; if (*kind == '+') start += bigness * (linenr_T)(x - kind - 1) + 1; --- 3441,3447 ---- curs = end; break; ! default: // '+' start = lnum; if (*kind == '+') start += bigness * (linenr_T)(x - kind - 1) + 1; *************** *** 3536,3560 **** return FALSE; } ! static char_u *old_sub = NULL; /* previous substitute pattern */ ! static int global_need_beginline; /* call beginline() after ":g" */ /* * Flags that are kept between calls to :substitute. */ typedef struct { ! int do_all; /* do multiple substitutions per line */ ! int do_ask; /* ask for confirmation */ ! int do_count; /* count only */ ! int do_error; /* if false, ignore errors */ ! int do_print; /* print last line with subs. */ ! int do_list; /* list last line with subs. */ ! int do_number; /* list last line with line nr*/ ! int do_ic; /* ignore case flag */ } subflags_T; ! /* do_sub() ! * * Perform a substitution from line eap->line1 to line eap->line2 using the * command pointed to by eap->arg which should be of the form: * --- 3536,3559 ---- return FALSE; } ! static char_u *old_sub = NULL; // previous substitute pattern ! static int global_need_beginline; // call beginline() after ":g" /* * Flags that are kept between calls to :substitute. */ typedef struct { ! int do_all; // do multiple substitutions per line ! int do_ask; // ask for confirmation ! int do_count; // count only ! int do_error; // if false, ignore errors ! int do_print; // print last line with subs. ! int do_list; // list last line with subs. ! int do_number; // list last line with line nr ! int do_ic; // ignore case flag } subflags_T; ! /* * Perform a substitution from line eap->line1 to line eap->line2 using the * command pointed to by eap->arg which should be of the form: * *************** *** 3573,3581 **** #ifdef FEAT_EVAL subflags_T subflags_save; #endif ! int save_do_all; /* remember user specified 'g' flag */ ! int save_do_ask; /* remember user specified 'c' flag */ ! char_u *pat = NULL, *sub = NULL; /* init for GCC */ int delimiter; int sublen; int got_quit = FALSE; --- 3572,3580 ---- #ifdef FEAT_EVAL subflags_T subflags_save; #endif ! int save_do_all; // remember user specified 'g' flag ! int save_do_ask; // remember user specified 'c' flag ! char_u *pat = NULL, *sub = NULL; // init for GCC int delimiter; int sublen; int got_quit = FALSE; *************** *** 3584,3597 **** int which_pat; char_u *cmd; int save_State; ! linenr_T first_line = 0; /* first changed line */ ! linenr_T last_line= 0; /* below last changed line AFTER the ! * change */ linenr_T old_line_count = curbuf->b_ml.ml_line_count; linenr_T line2; ! long nmatch; /* number of lines in match */ ! char_u *sub_firstline; /* allocated copy of first sub line */ ! int endcolumn = FALSE; /* cursor in last column when done */ pos_T old_cursor = curwin->w_cursor; int start_nsubs; #ifdef FEAT_EVAL --- 3583,3596 ---- int which_pat; char_u *cmd; int save_State; ! linenr_T first_line = 0; // first changed line ! linenr_T last_line= 0; // below last changed line AFTER the ! // change linenr_T old_line_count = curbuf->b_ml.ml_line_count; linenr_T line2; ! long nmatch; // number of lines in match ! char_u *sub_firstline; // allocated copy of first sub line ! int endcolumn = FALSE; // cursor in last column when done pos_T old_cursor = curwin->w_cursor; int start_nsubs; #ifdef FEAT_EVAL *************** *** 3607,3621 **** start_nsubs = sub_nsubs; if (eap->cmdidx == CMD_tilde) ! which_pat = RE_LAST; /* use last used regexp */ else ! which_pat = RE_SUBST; /* use last substitute regexp */ ! /* new pattern and substitution */ if (eap->cmd[0] == 's' && *cmd != NUL && !VIM_ISWHITE(*cmd) && vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL) { ! /* don't accept alphanumeric for separator */ if (isalpha(*cmd)) { emsg(_("E146: Regular expressions can't be delimited by letters")); --- 3606,3620 ---- start_nsubs = sub_nsubs; if (eap->cmdidx == CMD_tilde) ! which_pat = RE_LAST; // use last used regexp else ! which_pat = RE_SUBST; // use last substitute regexp ! // new pattern and substitution if (eap->cmd[0] == 's' && *cmd != NUL && !VIM_ISWHITE(*cmd) && vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL) { ! // don't accept alphanumeric for separator if (isalpha(*cmd)) { emsg(_("E146: Regular expressions can't be delimited by letters")); *************** *** 3635,3679 **** return; } if (*cmd != '&') ! which_pat = RE_SEARCH; /* use last '/' pattern */ ! pat = (char_u *)""; /* empty search pattern */ ! delimiter = *cmd++; /* remember delimiter character */ ! } ! else /* find the end of the regexp */ ! { ! which_pat = RE_LAST; /* use last used regexp */ ! delimiter = *cmd++; /* remember delimiter character */ ! pat = cmd; /* remember start of search pat */ cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg); ! if (cmd[0] == delimiter) /* end delimiter found */ ! *cmd++ = NUL; /* replace it with a NUL */ } /* * Small incompatibility: vi sees '\n' as end of the command, but in * Vim we want to use '\n' to find/substitute a NUL. */ ! sub = cmd; /* remember the start of the substitution */ while (cmd[0]) { ! if (cmd[0] == delimiter) /* end delimiter found */ { ! *cmd++ = NUL; /* replace it with a NUL */ break; } ! if (cmd[0] == '\\' && cmd[1] != 0) /* skip escaped characters */ ++cmd; MB_PTR_ADV(cmd); } if (!eap->skip) { ! /* In POSIX vi ":s/pat/%/" uses the previous subst. string. */ if (STRCMP(sub, "%") == 0 && vim_strchr(p_cpo, CPO_SUBPERCENT) != NULL) { ! if (old_sub == NULL) /* there is no previous command */ { emsg(_(e_nopresub)); return; --- 3634,3678 ---- return; } if (*cmd != '&') ! which_pat = RE_SEARCH; // use last '/' pattern ! pat = (char_u *)""; // empty search pattern ! delimiter = *cmd++; // remember delimiter character ! } ! else // find the end of the regexp ! { ! which_pat = RE_LAST; // use last used regexp ! delimiter = *cmd++; // remember delimiter character ! pat = cmd; // remember start of search pat cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg); ! if (cmd[0] == delimiter) // end delimiter found ! *cmd++ = NUL; // replace it with a NUL } /* * Small incompatibility: vi sees '\n' as end of the command, but in * Vim we want to use '\n' to find/substitute a NUL. */ ! sub = cmd; // remember the start of the substitution while (cmd[0]) { ! if (cmd[0] == delimiter) // end delimiter found { ! *cmd++ = NUL; // replace it with a NUL break; } ! if (cmd[0] == '\\' && cmd[1] != 0) // skip escaped characters ++cmd; MB_PTR_ADV(cmd); } if (!eap->skip) { ! // In POSIX vi ":s/pat/%/" uses the previous subst. string. if (STRCMP(sub, "%") == 0 && vim_strchr(p_cpo, CPO_SUBPERCENT) != NULL) { ! if (old_sub == NULL) // there is no previous command { emsg(_(e_nopresub)); return; *************** *** 3687,3712 **** } } } ! else if (!eap->skip) /* use previous pattern and substitution */ { ! if (old_sub == NULL) /* there is no previous command */ { emsg(_(e_nopresub)); return; } ! pat = NULL; /* search_regcomp() will use previous pattern */ sub = old_sub; ! /* Vi compatibility quirk: repeating with ":s" keeps the cursor in the ! * last column after using "$". */ endcolumn = (curwin->w_curswant == MAXCOL); } ! /* Recognize ":%s/\n//" and turn it into a join command, which is much ! * more efficient. ! * TODO: find a generic solution to make line-joining operations more ! * efficient, avoid allocating a string that grows in size. ! */ if (pat != NULL && STRCMP(pat, "\\n") == 0 && *sub == NUL && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l' --- 3686,3710 ---- } } } ! else if (!eap->skip) // use previous pattern and substitution { ! if (old_sub == NULL) // there is no previous command { emsg(_(e_nopresub)); return; } ! pat = NULL; // search_regcomp() will use previous pattern sub = old_sub; ! // Vi compatibility quirk: repeating with ":s" keeps the cursor in the ! // last column after using "$". endcolumn = (curwin->w_curswant == MAXCOL); } ! // Recognize ":%s/\n//" and turn it into a join command, which is much ! // more efficient. ! // TODO: find a generic solution to make line-joining operations more ! // efficient, avoid allocating a string that grows in size. if (pat != NULL && STRCMP(pat, "\\n") == 0 && *sub == NUL && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l' *************** *** 3722,3729 **** else if (*cmd == 'p') eap->flags = EXFLAG_PRINT; ! /* The number of lines joined is the number of lines in the range plus ! * one. One less when the last line is included. */ joined_lines_count = eap->line2 - eap->line1 + 1; if (eap->line2 < curbuf->b_ml.ml_line_count) ++joined_lines_count; --- 3720,3727 ---- else if (*cmd == 'p') eap->flags = EXFLAG_PRINT; ! // The number of lines joined is the number of lines in the range plus ! // one. One less when the last line is included. joined_lines_count = eap->line2 - eap->line1 + 1; if (eap->line2 < curbuf->b_ml.ml_line_count) ++joined_lines_count; *************** *** 3753,3759 **** { if (!p_ed) { ! if (p_gd) /* default is global on */ subflags.do_all = TRUE; else subflags.do_all = FALSE; --- 3751,3757 ---- { if (!p_ed) { ! if (p_gd) // default is global on subflags.do_all = TRUE; else subflags.do_all = FALSE; *************** *** 3780,3786 **** subflags.do_count = TRUE; else if (*cmd == 'e') subflags.do_error = !subflags.do_error; ! else if (*cmd == 'r') /* use last used regexp */ which_pat = RE_LAST; else if (*cmd == 'p') subflags.do_print = TRUE; --- 3778,3784 ---- subflags.do_count = TRUE; else if (*cmd == 'e') subflags.do_error = !subflags.do_error; ! else if (*cmd == 'r') // use last used regexp which_pat = RE_LAST; else if (*cmd == 'p') subflags.do_print = TRUE; *************** *** 3794,3802 **** subflags.do_print = TRUE; subflags.do_list = TRUE; } ! else if (*cmd == 'i') /* ignore case */ subflags.do_ic = 'i'; ! else if (*cmd == 'I') /* don't ignore case */ subflags.do_ic = 'I'; else break; --- 3792,3800 ---- subflags.do_print = TRUE; subflags.do_list = TRUE; } ! else if (*cmd == 'i') // ignore case subflags.do_ic = 'i'; ! else if (*cmd == 'I') // don't ignore case subflags.do_ic = 'I'; else break; *************** *** 3830,3836 **** * check for trailing command or garbage */ cmd = skipwhite(cmd); ! if (*cmd && *cmd != '"') /* if not end-of-line or comment */ { eap->nextcmd = check_nextcmd(cmd); if (eap->nextcmd == NULL) --- 3828,3834 ---- * check for trailing command or garbage */ cmd = skipwhite(cmd); ! if (*cmd && *cmd != '"') // if not end-of-line or comment { eap->nextcmd = check_nextcmd(cmd); if (eap->nextcmd == NULL) *************** *** 3840,3851 **** } } ! if (eap->skip) /* not executing commands, only parsing */ return; if (!subflags.do_count && !curbuf->b_p_ma) { ! /* Substitution is not allowed in non-'modifiable' buffer */ emsg(_(e_modifiable)); return; } --- 3838,3849 ---- } } ! if (eap->skip) // not executing commands, only parsing return; if (!subflags.do_count && !curbuf->b_p_ma) { ! // Substitution is not allowed in non-'modifiable' buffer emsg(_(e_modifiable)); return; } *************** *** 3857,3863 **** return; } ! /* the 'i' or 'I' flag overrules 'ignorecase' and 'smartcase' */ if (subflags.do_ic == 'i') regmatch.rmm_ic = TRUE; else if (subflags.do_ic == 'I') --- 3855,3861 ---- return; } ! // the 'i' or 'I' flag overrules 'ignorecase' and 'smartcase' if (subflags.do_ic == 'i') regmatch.rmm_ic = TRUE; else if (subflags.do_ic == 'I') *************** *** 3896,3905 **** int did_sub = FALSE; int lastone; int len, copy_len, needed_len; ! long nmatch_tl = 0; /* nr of lines matched below lnum */ ! int do_again; /* do it again after joining lines */ int skip_match = FALSE; ! linenr_T sub_firstlnum; /* nr of first sub line */ #ifdef FEAT_PROP_POPUP int apc_flags = APC_SAVE_FOR_UNDO | APC_SUBSTITUTE; colnr_T total_added = 0; --- 3894,3903 ---- int did_sub = FALSE; int lastone; int len, copy_len, needed_len; ! long nmatch_tl = 0; // nr of lines matched below lnum ! int do_again; // do it again after joining lines int skip_match = FALSE; ! linenr_T sub_firstlnum; // nr of first sub line #ifdef FEAT_PROP_POPUP int apc_flags = APC_SAVE_FOR_UNDO | APC_SUBSTITUTE; colnr_T total_added = 0; *************** *** 3954,3960 **** copycol = 0; matchcol = 0; ! /* At first match, remember current cursor position. */ if (!got_match) { setpcmark(); --- 3952,3958 ---- copycol = 0; matchcol = 0; ! // At first match, remember current cursor position. if (!got_match) { setpcmark(); *************** *** 3971,3979 **** */ for (;;) { ! /* Advance "lnum" to the line where the match starts. The ! * match does not start in the first line when there is a line ! * break before \zs. */ if (regmatch.startpos[0].lnum > 0) { lnum += regmatch.startpos[0].lnum; --- 3969,3977 ---- */ for (;;) { ! // Advance "lnum" to the line where the match starts. The ! // match does not start in the first line when there is a line ! // break before \zs. if (regmatch.startpos[0].lnum > 0) { lnum += regmatch.startpos[0].lnum; *************** *** 3997,4004 **** } } ! /* Save the line number of the last change for the final ! * cursor position (just like Vi). */ curwin->w_cursor.lnum = lnum; do_again = FALSE; --- 3995,4002 ---- } } ! // Save the line number of the last change for the final ! // cursor position (just like Vi). curwin->w_cursor.lnum = lnum; do_again = FALSE; *************** *** 4012,4023 **** && matchcol == regmatch.endpos[0].col) { if (sub_firstline[matchcol] == NUL) ! /* We already were at the end of the line. Don't look ! * for a match in this line again. */ skip_match = TRUE; else { ! /* search for a match at next column */ if (has_mbyte) matchcol += mb_ptr2len(sub_firstline + matchcol); else --- 4010,4021 ---- && matchcol == regmatch.endpos[0].col) { if (sub_firstline[matchcol] == NUL) ! // We already were at the end of the line. Don't look ! // for a match in this line again. skip_match = TRUE; else { ! // search for a match at next column if (has_mbyte) matchcol += mb_ptr2len(sub_firstline + matchcol); else *************** *** 4026,4033 **** goto skip; } ! /* Normally we continue searching for a match just after the ! * previous match. */ matchcol = regmatch.endpos[0].col; prev_matchcol = matchcol; --- 4024,4031 ---- goto skip; } ! // Normally we continue searching for a match just after the ! // previous match. matchcol = regmatch.endpos[0].col; prev_matchcol = matchcol; *************** *** 4037,4046 **** */ if (subflags.do_count) { ! /* For a multi-line match, put matchcol at the NUL at ! * the end of the line and set nmatch to one, so that ! * we continue looking for a match on the next line. ! * Avoids that ":s/\nB\@=//gc" get stuck. */ if (nmatch > 1) { matchcol = (colnr_T)STRLEN(sub_firstline); --- 4035,4044 ---- */ if (subflags.do_count) { ! // For a multi-line match, put matchcol at the NUL at ! // the end of the line and set nmatch to one, so that ! // we continue looking for a match on the next line. ! // Avoids that ":s/\nB\@=//gc" get stuck. if (nmatch > 1) { matchcol = (colnr_T)STRLEN(sub_firstline); *************** *** 4050,4057 **** sub_nsubs++; did_sub = TRUE; #ifdef FEAT_EVAL ! /* Skip the substitution, unless an expression is used, ! * then it is evaluated in the sandbox. */ if (!(sub[0] == '\\' && sub[1] == '=')) #endif goto skip; --- 4048,4055 ---- sub_nsubs++; did_sub = TRUE; #ifdef FEAT_EVAL ! // Skip the substitution, unless an expression is used, ! // then it is evaluated in the sandbox. if (!(sub[0] == '\\' && sub[1] == '=')) #endif goto skip; *************** *** 4061,4068 **** { int typed = 0; ! /* change State to CONFIRM, so that the mouse works ! * properly */ save_State = State; State = CONFIRM; setmouse(); // disable mouse in xterm --- 4059,4066 ---- { int typed = 0; ! // change State to CONFIRM, so that the mouse works ! // properly save_State = State; State = CONFIRM; setmouse(); // disable mouse in xterm *************** *** 4070,4077 **** if (curwin->w_p_crb) do_check_cursorbind(); ! /* When 'cpoptions' contains "u" don't sync undo when ! * asking for confirmation. */ if (vim_strchr(p_cpo, CPO_UNDO) != NULL) ++no_u_sync; --- 4068,4075 ---- if (curwin->w_p_crb) do_check_cursorbind(); ! // When 'cpoptions' contains "u" don't sync undo when ! // asking for confirmation. if (vim_strchr(p_cpo, CPO_UNDO) != NULL) ++no_u_sync; *************** *** 4121,4138 **** curwin->w_p_fen = FALSE; #endif ! /* Invert the matched string. ! * Remove the inversion afterwards. */ temp = RedrawingDisabled; RedrawingDisabled = 0; if (new_start != NULL) { ! /* There already was a substitution, we would ! * like to show this to the user. We cannot ! * really update the line, it would change ! * what matches. Temporarily replace the line ! * and change it back afterwards. */ orig_line = vim_strsave(ml_get(lnum)); if (orig_line != NULL) { --- 4119,4136 ---- curwin->w_p_fen = FALSE; #endif ! // Invert the matched string. ! // Remove the inversion afterwards. temp = RedrawingDisabled; RedrawingDisabled = 0; if (new_start != NULL) { ! // There already was a substitution, we would ! // like to show this to the user. We cannot ! // really update the line, it would change ! // what matches. Temporarily replace the line ! // and change it back afterwards. orig_line = vim_strsave(ml_get(lnum)); if (orig_line != NULL) { *************** *** 4143,4153 **** VIM_CLEAR(orig_line); else { ! /* Position the cursor relative to the ! * end of the line, the previous ! * substitute may have inserted or ! * deleted characters before the ! * cursor. */ len_change = (int)STRLEN(new_line) - (int)STRLEN(orig_line); curwin->w_cursor.col += len_change; --- 4141,4151 ---- VIM_CLEAR(orig_line); else { ! // Position the cursor relative to the ! // end of the line, the previous ! // substitute may have inserted or ! // deleted characters before the ! // cursor. len_change = (int)STRLEN(new_line) - (int)STRLEN(orig_line); curwin->w_cursor.col += len_change; *************** *** 4172,4185 **** curwin->w_p_fen = save_p_fen; #endif if (msg_row == Rows - 1) ! msg_didout = FALSE; /* avoid a scroll-up */ msg_starthere(); i = msg_scroll; ! msg_scroll = 0; /* truncate msg when ! needed */ msg_no_more = TRUE; ! /* write message same highlighting as for ! * wait_return */ smsg_attr(HL_ATTR(HLF_R), _("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); msg_no_more = FALSE; --- 4170,4183 ---- curwin->w_p_fen = save_p_fen; #endif if (msg_row == Rows - 1) ! msg_didout = FALSE; // avoid a scroll-up msg_starthere(); i = msg_scroll; ! msg_scroll = 0; // truncate msg when ! // needed msg_no_more = TRUE; ! // write message same highlighting as for ! // wait_return smsg_attr(HL_ATTR(HLF_R), _("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); msg_no_more = FALSE; *************** *** 4189,4213 **** RedrawingDisabled = temp; #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; /* allow scrolling here */ #endif ! ++no_mapping; /* don't map this key */ ! ++allow_keys; /* allow special keys */ typed = plain_vgetc(); --allow_keys; --no_mapping; ! /* clear the question */ ! msg_didout = FALSE; /* don't scroll up */ msg_col = 0; gotocmdline(TRUE); ! /* restore the line */ if (orig_line != NULL) ml_replace(lnum, orig_line, FALSE); } ! need_wait_return = FALSE; /* no hit-return prompt */ if (typed == 'q' || typed == ESC || typed == Ctrl_C #ifdef UNIX || typed == intr_char --- 4187,4211 ---- RedrawingDisabled = temp; #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; // allow scrolling here #endif ! ++no_mapping; // don't map this key ! ++allow_keys; // allow special keys typed = plain_vgetc(); --allow_keys; --no_mapping; ! // clear the question ! msg_didout = FALSE; // don't scroll up msg_col = 0; gotocmdline(TRUE); ! // restore the line if (orig_line != NULL) ml_replace(lnum, orig_line, FALSE); } ! need_wait_return = FALSE; // no hit-return prompt if (typed == 'q' || typed == ESC || typed == Ctrl_C #ifdef UNIX || typed == intr_char *************** *** 4223,4229 **** break; if (typed == 'l') { ! /* last: replace and then stop */ subflags.do_all = FALSE; line2 = lnum; break; --- 4221,4227 ---- break; if (typed == 'l') { ! // last: replace and then stop subflags.do_all = FALSE; line2 = lnum; break; *************** *** 4245,4255 **** if (typed == 'n') { ! /* For a multi-line match, put matchcol at the NUL at ! * the end of the line and set nmatch to one, so that ! * we continue looking for a match on the next line. ! * Avoids that ":%s/\nB\@=//gc" and ":%s/\n/,\r/gc" ! * get stuck when pressing 'n'. */ if (nmatch > 1) { matchcol = (colnr_T)STRLEN(sub_firstline); --- 4243,4253 ---- if (typed == 'n') { ! // For a multi-line match, put matchcol at the NUL at ! // the end of the line and set nmatch to one, so that ! // we continue looking for a match on the next line. ! // Avoids that ":%s/\nB\@=//gc" and ":%s/\n/,\r/gc" ! // get stuck when pressing 'n'. if (nmatch > 1) { matchcol = (colnr_T)STRLEN(sub_firstline); *************** *** 4261,4268 **** goto skip; } ! /* Move the cursor to the start of the match, so that we can ! * use "\=col("."). */ curwin->w_cursor.col = regmatch.startpos[0].col; /* --- 4259,4266 ---- goto skip; } ! // Move the cursor to the start of the match, so that we can ! // use "\=col("."). curwin->w_cursor.col = regmatch.startpos[0].col; /* *************** *** 4298,4319 **** } #endif ! /* When the match included the "$" of the last line it may ! * go beyond the last line of the buffer. */ if (nmatch > curbuf->b_ml.ml_line_count - sub_firstlnum + 1) { nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1; skip_match = TRUE; } ! /* Need room for: ! * - result so far in new_start (not for first sub in line) ! * - original text up to match ! * - length of substituted part ! * - original text after match ! * Adjust text properties here, since we have all information ! * needed. ! */ if (nmatch == 1) { p1 = sub_firstline; --- 4296,4316 ---- } #endif ! // When the match included the "$" of the last line it may ! // go beyond the last line of the buffer. if (nmatch > curbuf->b_ml.ml_line_count - sub_firstlnum + 1) { nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1; skip_match = TRUE; } ! // Need room for: ! // - result so far in new_start (not for first sub in line) ! // - original text up to match ! // - length of substituted part ! // - original text after match ! // Adjust text properties here, since we have all information ! // needed. if (nmatch == 1) { p1 = sub_firstline; *************** *** 4392,4422 **** sub_nsubs++; did_sub = TRUE; ! /* Move the cursor to the start of the line, to avoid that it ! * is beyond the end of the line after the substitution. */ curwin->w_cursor.col = 0; ! /* For a multi-line match, make a copy of the last matched ! * line and continue in that one. */ if (nmatch > 1) { sub_firstlnum += nmatch - 1; vim_free(sub_firstline); sub_firstline = vim_strsave(ml_get(sub_firstlnum)); ! /* When going beyond the last line, stop substituting. */ if (sub_firstlnum <= line2) do_again = TRUE; else subflags.do_all = FALSE; } ! /* Remember next character to be copied. */ copycol = regmatch.endpos[0].col; if (skip_match) { ! /* Already hit end of the buffer, sub_firstlnum is one ! * less than what it ought to be. */ vim_free(sub_firstline); sub_firstline = vim_strsave((char_u *)""); copycol = 0; --- 4389,4419 ---- sub_nsubs++; did_sub = TRUE; ! // Move the cursor to the start of the line, to avoid that it ! // is beyond the end of the line after the substitution. curwin->w_cursor.col = 0; ! // For a multi-line match, make a copy of the last matched ! // line and continue in that one. if (nmatch > 1) { sub_firstlnum += nmatch - 1; vim_free(sub_firstline); sub_firstline = vim_strsave(ml_get(sub_firstlnum)); ! // When going beyond the last line, stop substituting. if (sub_firstlnum <= line2) do_again = TRUE; else subflags.do_all = FALSE; } ! // Remember next character to be copied. copycol = regmatch.endpos[0].col; if (skip_match) { ! // Already hit end of the buffer, sub_firstlnum is one ! // less than what it ought to be. vim_free(sub_firstline); sub_firstline = vim_strsave((char_u *)""); copycol = 0; *************** *** 4432,4438 **** */ for (p1 = new_end; *p1; ++p1) { ! if (p1[0] == '\\' && p1[1] != NUL) /* remove backslash */ { STRMOVE(p1, p1 + 1); #ifdef FEAT_PROP_POPUP --- 4429,4435 ---- */ for (p1 = new_end; *p1; ++p1) { ! if (p1[0] == '\\' && p1[1] != NUL) // remove backslash { STRMOVE(p1, p1 + 1); #ifdef FEAT_PROP_POPUP *************** *** 4489,4499 **** * But ":s/\n/#/" is OK. */ skip: ! /* We already know that we did the last subst when we are at ! * the end of the line, except that a pattern like ! * "bar\|\nfoo" may match at the NUL. "lnum" can be below ! * "line2" when there is a \zs in the pattern after a line ! * break. */ lastone = (skip_match || got_int || got_quit --- 4486,4496 ---- * But ":s/\n/#/" is OK. */ skip: ! // We already know that we did the last subst when we are at ! // the end of the line, except that a pattern like ! // "bar\|\nfoo" may match at the NUL. "lnum" can be below ! // "line2" when there is a \zs in the pattern after a line ! // break. lastone = (skip_match || got_int || got_quit *************** *** 4555,4566 **** if (subflags.do_ask) deleted_lines(lnum, nmatch_tl); --lnum; ! line2 -= nmatch_tl; /* nr of lines decreases */ nmatch_tl = 0; } ! /* When asking, undo is saved each time, must also set ! * changed flag each time. */ if (subflags.do_ask) changed_bytes(lnum, 0); else --- 4552,4563 ---- if (subflags.do_ask) deleted_lines(lnum, nmatch_tl); --lnum; ! line2 -= nmatch_tl; // nr of lines decreases nmatch_tl = 0; } ! // When asking, undo is saved each time, must also set ! // changed flag each time. if (subflags.do_ask) changed_bytes(lnum, 0); else *************** *** 4571,4577 **** } sub_firstlnum = lnum; ! vim_free(sub_firstline); /* free the temp buffer */ sub_firstline = new_start; new_start = NULL; matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; --- 4568,4574 ---- } sub_firstlnum = lnum; ! vim_free(sub_firstline); // free the temp buffer sub_firstline = new_start; new_start = NULL; matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; *************** *** 4588,4596 **** */ if (nmatch <= 0) { ! /* If the match found didn't start where we were ! * searching, do the next search in the line where we ! * found the match. */ if (nmatch == -1) lnum -= regmatch.startpos[0].lnum; break; --- 4585,4593 ---- */ if (nmatch <= 0) { ! // If the match found didn't start where we were ! // searching, do the next search in the line where we ! // found the match. if (nmatch == -1) lnum -= regmatch.startpos[0].lnum; break; *************** *** 4602,4609 **** if (did_sub) ++sub_nlines; ! vim_free(new_start); /* for when substitute was cancelled */ ! VIM_CLEAR(sub_firstline); /* free the copy of the original line */ } line_breakcheck(); --- 4599,4606 ---- if (did_sub) ++sub_nlines; ! vim_free(new_start); // for when substitute was cancelled ! VIM_CLEAR(sub_firstline); // free the copy of the original line } line_breakcheck(); *************** *** 4611,4627 **** if (first_line != 0) { ! /* Need to subtract the number of added lines from "last_line" to get ! * the line number before the change (same as adding the number of ! * deleted lines). */ i = curbuf->b_ml.ml_line_count - old_line_count; changed_lines(first_line, 0, last_line - i, i); } outofmem: ! vim_free(sub_firstline); /* may have to free allocated copy of the line */ ! /* ":s/pat//n" doesn't move the cursor */ if (subflags.do_count) curwin->w_cursor = old_cursor; --- 4608,4624 ---- if (first_line != 0) { ! // Need to subtract the number of added lines from "last_line" to get ! // the line number before the change (same as adding the number of ! // deleted lines). i = curbuf->b_ml.ml_line_count - old_line_count; changed_lines(first_line, 0, last_line - i, i); } outofmem: ! vim_free(sub_firstline); // may have to free allocated copy of the line ! // ":s/pat//n" doesn't move the cursor if (subflags.do_count) curwin->w_cursor = old_cursor; *************** *** 4637,4643 **** if (!global_busy) { ! /* when interactive leave cursor on the match */ if (!subflags.do_ask) { if (endcolumn) --- 4634,4640 ---- if (!global_busy) { ! // when interactive leave cursor on the match if (!subflags.do_ask) { if (endcolumn) *************** *** 4656,4678 **** } else if (!global_busy) { ! if (got_int) /* interrupted */ emsg(_(e_interr)); ! else if (got_match) /* did find something but nothing substituted */ msg(""); ! else if (subflags.do_error) /* nothing found */ semsg(_(e_patnotf2), get_search_pat()); } #ifdef FEAT_FOLDING if (subflags.do_ask && hasAnyFolding(curwin)) ! /* Cursor position may require updating */ changed_window_setting(); #endif vim_regfree(regmatch.regprog); ! /* Restore the flag values, they can be used for ":&&". */ subflags.do_all = save_do_all; subflags.do_ask = save_do_ask; } --- 4653,4675 ---- } else if (!global_busy) { ! if (got_int) // interrupted emsg(_(e_interr)); ! else if (got_match) // did find something but nothing substituted msg(""); ! else if (subflags.do_error) // nothing found semsg(_(e_patnotf2), get_search_pat()); } #ifdef FEAT_FOLDING if (subflags.do_ask && hasAnyFolding(curwin)) ! // Cursor position may require updating changed_window_setting(); #endif vim_regfree(regmatch.regprog); ! // Restore the flag values, they can be used for ":&&". subflags.do_all = save_do_all; subflags.do_ask = save_do_ask; } *************** *** 4684,4690 **** */ int do_sub_msg( ! int count_only) /* used 'n' flag for ":s" */ { /* * Only report substitutions when: --- 4681,4687 ---- */ int do_sub_msg( ! int count_only) // used 'n' flag for ":s" { /* * Only report substitutions when: *************** *** 4720,4726 **** sub_nsubs, (long)sub_nlines); if (msg(msg_buf)) ! /* save message to display it after redraw */ set_keep_msg((char_u *)msg_buf, 0); return TRUE; } --- 4717,4723 ---- sub_nsubs, (long)sub_nlines); if (msg(msg_buf)) ! // save message to display it after redraw set_keep_msg((char_u *)msg_buf, 0); return TRUE; } *************** *** 4762,4794 **** void ex_global(exarg_T *eap) { ! linenr_T lnum; /* line number according to old situation */ int ndone = 0; ! int type; /* first char of cmd: 'v' or 'g' */ ! char_u *cmd; /* command argument */ ! char_u delim; /* delimiter, normally '/' */ char_u *pat; regmmatch_T regmatch; int match; int which_pat; ! /* When nesting the command works on one line. This allows for ! * ":g/found/v/notfound/command". */ if (global_busy && (eap->line1 != 1 || eap->line2 != curbuf->b_ml.ml_line_count)) { ! /* will increment global_busy to break out of the loop */ emsg(_("E147: Cannot do :global recursive with a range")); return; } ! if (eap->forceit) /* ":global!" is like ":vglobal" */ type = 'v'; else type = *eap->cmd; cmd = eap->arg; ! which_pat = RE_LAST; /* default: use last used regexp */ /* * undocumented vi feature: --- 4759,4791 ---- void ex_global(exarg_T *eap) { ! linenr_T lnum; // line number according to old situation int ndone = 0; ! int type; // first char of cmd: 'v' or 'g' ! char_u *cmd; // command argument ! char_u delim; // delimiter, normally '/' char_u *pat; regmmatch_T regmatch; int match; int which_pat; ! // When nesting the command works on one line. This allows for ! // ":g/found/v/notfound/command". if (global_busy && (eap->line1 != 1 || eap->line2 != curbuf->b_ml.ml_line_count)) { ! // will increment global_busy to break out of the loop emsg(_("E147: Cannot do :global recursive with a range")); return; } ! if (eap->forceit) // ":global!" is like ":vglobal" type = 'v'; else type = *eap->cmd; cmd = eap->arg; ! which_pat = RE_LAST; // default: use last used regexp /* * undocumented vi feature: *************** *** 4804,4812 **** return; } if (*cmd == '&') ! which_pat = RE_SUBST; /* use previous substitute pattern */ else ! which_pat = RE_SEARCH; /* use previous search pattern */ ++cmd; pat = (char_u *)""; } --- 4801,4809 ---- return; } if (*cmd == '&') ! which_pat = RE_SUBST; // use previous substitute pattern else ! which_pat = RE_SEARCH; // use previous search pattern ++cmd; pat = (char_u *)""; } *************** *** 4817,4829 **** } else { ! delim = *cmd; /* get the delimiter */ if (delim) ! ++cmd; /* skip delimiter if there is one */ ! pat = cmd; /* remember start of pattern */ cmd = skip_regexp(cmd, delim, p_magic, &eap->arg); ! if (cmd[0] == delim) /* end delimiter found */ ! *cmd++ = NUL; /* replace it with a NUL */ } if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) --- 4814,4826 ---- } else { ! delim = *cmd; // get the delimiter if (delim) ! ++cmd; // skip delimiter if there is one ! pat = cmd; // remember start of pattern cmd = skip_regexp(cmd, delim, p_magic, &eap->arg); ! if (cmd[0] == delim) // end delimiter found ! *cmd++ = NUL; // replace it with a NUL } if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) *************** *** 4847,4853 **** */ for (lnum = eap->line1; lnum <= eap->line2 && !got_int; ++lnum) { ! /* a match on this line? */ match = vim_regexec_multi(®match, curwin, curbuf, lnum, (colnr_T)0, NULL, NULL); if ((type == 'g' && match) || (type == 'v' && !match)) --- 4844,4850 ---- */ for (lnum = eap->line1; lnum <= eap->line2 && !got_int; ++lnum) { ! // a match on this line? match = vim_regexec_multi(®match, curwin, curbuf, lnum, (colnr_T)0, NULL, NULL); if ((type == 'g' && match) || (type == 'v' && !match)) *************** *** 4881,4887 **** #endif } ! ml_clearmarked(); /* clear rest of the marks */ } vim_regfree(regmatch.regprog); --- 4878,4884 ---- #endif } ! ml_clearmarked(); // clear rest of the marks } vim_regfree(regmatch.regprog); *************** *** 4893,4901 **** void global_exe(char_u *cmd) { ! linenr_T old_lcount; /* b_ml.ml_line_count before the command */ ! buf_T *old_buf = curbuf; /* remember what buffer we started in */ ! linenr_T lnum; /* line number according to old situation */ /* * Set current position only once for a global command. --- 4890,4898 ---- void global_exe(char_u *cmd) { ! linenr_T old_lcount; // b_ml.ml_line_count before the command ! buf_T *old_buf = curbuf; // remember what buffer we started in ! linenr_T lnum; // line number according to old situation /* * Set current position only once for a global command. *************** *** 4904,4910 **** */ setpcmark(); ! /* When the command writes a message, don't overwrite the command. */ msg_didout = TRUE; sub_nsubs = 0; --- 4901,4907 ---- */ setpcmark(); ! // When the command writes a message, don't overwrite the command. msg_didout = TRUE; sub_nsubs = 0; *************** *** 4922,4942 **** if (global_need_beginline) beginline(BL_WHITE | BL_FIX); else ! check_cursor(); /* cursor may be beyond the end of the line */ ! /* the cursor may not have moved in the text but a change in a previous ! * line may move it on the screen */ changed_line_abv_curs(); ! /* If it looks like no message was written, allow overwriting the ! * command with the report for number of changes. */ if (msg_col == 0 && msg_scrolled == 0) msg_didout = FALSE; ! /* If substitutes done, report number of substitutes, otherwise report ! * number of extra or deleted lines. ! * Don't report extra or deleted lines in the edge case where the buffer ! * we are in after execution is different from the buffer we started in. */ if (!do_sub_msg(FALSE) && curbuf == old_buf) msgmore(curbuf->b_ml.ml_line_count - old_lcount); } --- 4919,4939 ---- if (global_need_beginline) beginline(BL_WHITE | BL_FIX); else ! check_cursor(); // cursor may be beyond the end of the line ! // the cursor may not have moved in the text but a change in a previous ! // line may move it on the screen changed_line_abv_curs(); ! // If it looks like no message was written, allow overwriting the ! // command with the report for number of changes. if (msg_col == 0 && msg_scrolled == 0) msg_didout = FALSE; ! // If substitutes done, report number of substitutes, otherwise report ! // number of extra or deleted lines. ! // Don't report extra or deleted lines in the edge case where the buffer ! // we are in after execution is different from the buffer we started in. if (!do_sub_msg(FALSE) && curbuf == old_buf) msgmore(curbuf->b_ml.ml_line_count - old_lcount); } *************** *** 5062,5068 **** { char_u *arg; char_u *tag; ! FILE *helpfd; /* file descriptor of help file */ int n; int i; win_T *wp; --- 5059,5065 ---- { char_u *arg; char_u *tag; ! FILE *helpfd; // file descriptor of help file int n; int i; win_T *wp; *************** *** 5104,5126 **** return; } ! if (eap->skip) /* not executing commands */ return; } else arg = (char_u *)""; ! /* remove trailing blanks */ p = arg + STRLEN(arg) - 1; while (p > arg && VIM_ISWHITE(*p) && p[-1] != '\\') *p-- = NUL; #ifdef FEAT_MULTI_LANG ! /* Check for a specified language */ lang = check_help_lang(arg); #endif ! /* When no argument given go to the index. */ if (*arg == NUL) arg = (char_u *)"help.txt"; --- 5101,5123 ---- return; } ! if (eap->skip) // not executing commands return; } else arg = (char_u *)""; ! // remove trailing blanks p = arg + STRLEN(arg) - 1; while (p > arg && VIM_ISWHITE(*p) && p[-1] != '\\') *p-- = NUL; #ifdef FEAT_MULTI_LANG ! // Check for a specified language lang = check_help_lang(arg); #endif ! // When no argument given go to the index. if (*arg == NUL) arg = (char_u *)"help.txt"; *************** *** 5133,5139 **** i = 0; #ifdef FEAT_MULTI_LANG if (n != FAIL && lang != NULL) ! /* Find first item with the requested language. */ for (i = 0; i < num_matches; ++i) { len = (int)STRLEN(matches[i]); --- 5130,5136 ---- i = 0; #ifdef FEAT_MULTI_LANG if (n != FAIL && lang != NULL) ! // Find first item with the requested language. for (i = 0; i < num_matches; ++i) { len = (int)STRLEN(matches[i]); *************** *** 5155,5161 **** return; } ! /* The first match (in the requested language) is the best match. */ tag = vim_strsave(matches[i]); FreeWild(num_matches, matches); --- 5152,5158 ---- return; } ! // The first match (in the requested language) is the best match. tag = vim_strsave(matches[i]); FreeWild(num_matches, matches); *************** *** 5190,5198 **** } fclose(helpfd); ! /* Split off help window; put it at far top if no position ! * specified, the current window is vertically split and ! * narrow. */ n = WSP_HELP; if (cmdmod.split == 0 && curwin->w_width != Columns && curwin->w_width < 80) --- 5187,5195 ---- } fclose(helpfd); ! // Split off help window; put it at far top if no position ! // specified, the current window is vertically split and ! // narrow. n = WSP_HELP; if (cmdmod.split == 0 && curwin->w_width != Columns && curwin->w_width < 80) *************** *** 5211,5217 **** alt_fnum = curbuf->b_fnum; (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL, ECMD_HIDE + ECMD_SET_HELP, ! NULL); /* buffer is still open, don't store info */ if (!cmdmod.keepalt) curwin->w_alt_fnum = alt_fnum; empty_fnum = curbuf->b_fnum; --- 5208,5214 ---- alt_fnum = curbuf->b_fnum; (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL, ECMD_HIDE + ECMD_SET_HELP, ! NULL); // buffer is still open, don't store info if (!cmdmod.keepalt) curwin->w_alt_fnum = alt_fnum; empty_fnum = curbuf->b_fnum; *************** *** 5219,5238 **** } if (!p_im) ! restart_edit = 0; /* don't want insert mode in help file */ #ifdef FEAT_FOLDING ! /* Restore KeyTyped, setting 'filetype=help' may reset it. ! * It is needed for do_tag top open folds under the cursor. */ KeyTyped = old_KeyTyped; #endif if (tag != NULL) do_tag(tag, DT_HELP, 1, FALSE, TRUE); ! /* Delete the empty buffer if we're not using it. Careful: autocommands ! * may have jumped to another window, check that the buffer is not in a ! * window. */ if (empty_fnum != 0 && curbuf->b_fnum != empty_fnum) { buf = buflist_findnr(empty_fnum); --- 5216,5235 ---- } if (!p_im) ! restart_edit = 0; // don't want insert mode in help file #ifdef FEAT_FOLDING ! // Restore KeyTyped, setting 'filetype=help' may reset it. ! // It is needed for do_tag top open folds under the cursor. KeyTyped = old_KeyTyped; #endif if (tag != NULL) do_tag(tag, DT_HELP, 1, FALSE, TRUE); ! // Delete the empty buffer if we're not using it. Careful: autocommands ! // may have jumped to another window, check that the buffer is not in a ! // window. if (empty_fnum != 0 && curbuf->b_fnum != empty_fnum) { buf = buflist_findnr(empty_fnum); *************** *** 5240,5246 **** wipe_buffer(buf, TRUE); } ! /* keep the previous alternate file */ if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum && !cmdmod.keepalt) curwin->w_alt_fnum = alt_fnum; --- 5237,5243 ---- wipe_buffer(buf, TRUE); } ! // keep the previous alternate file if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum && !cmdmod.keepalt) curwin->w_alt_fnum = alt_fnum; *************** *** 5280,5286 **** if (len >= 3 && arg[len - 3] == '@' && ASCII_ISALPHA(arg[len - 2]) && ASCII_ISALPHA(arg[len - 1])) { ! arg[len - 3] = NUL; /* remove the '@' */ return arg + len - 2; } return NULL; --- 5277,5283 ---- if (len >= 3 && arg[len - 3] == '@' && ASCII_ISALPHA(arg[len - 2]) && ASCII_ISALPHA(arg[len - 1])) { ! arg[len - 3] = NUL; // remove the '@' return arg + len - 2; } return NULL; *************** *** 5301,5308 **** int help_heuristic( char_u *matched_string, ! int offset, /* offset for match */ ! int wrong_case) /* no matching case */ { int num_letters; char_u *p; --- 5298,5305 ---- int help_heuristic( char_u *matched_string, ! int offset, // offset for match ! int wrong_case) // no matching case { int num_letters; char_u *p; *************** *** 5328,5335 **** offset *= 200; if (wrong_case) offset += 5000; ! /* Features are less interesting than the subjects themselves, but "+" ! * alone is not a feature. */ if (matched_string[0] == '+' && matched_string[1] != NUL) offset += 100; return (int)(100 * num_letters + STRLEN(matched_string) + offset); --- 5325,5332 ---- offset *= 200; if (wrong_case) offset += 5000; ! // Features are less interesting than the subjects themselves, but "+" ! // alone is not a feature. if (matched_string[0] == '+' && matched_string[1] != NUL) offset += 100; return (int)(100 * num_letters + STRLEN(matched_string) + offset); *************** *** 5391,5397 **** ">=?", ">?", "is?", "isnot?"}; int flags; ! d = IObuff; /* assume IObuff is long enough! */ if (STRNICMP(arg, "expr-", 5) == 0) { --- 5388,5394 ---- ">=?", ">?", "is?", "isnot?"}; int flags; ! d = IObuff; // assume IObuff is long enough! if (STRNICMP(arg, "expr-", 5) == 0) { *************** *** 5427,5439 **** } } ! if (i < 0) /* no match in table */ { ! /* Replace "\S" with "/\\S", etc. Otherwise every tag is matched. ! * Also replace "\%^" and "\%(", they match every tag too. ! * Also "\zs", "\z1", etc. ! * Also "\@<", "\@=", "\@<=", etc. ! * And also "\_$" and "\_^". */ if (arg[0] == '\\' && ((arg[1] != NUL && arg[2] == NUL) || (vim_strchr((char_u *)"%_z@", arg[1]) != NULL --- 5424,5436 ---- } } ! if (i < 0) // no match in table { ! // Replace "\S" with "/\\S", etc. Otherwise every tag is matched. ! // Also replace "\%^" and "\%(", they match every tag too. ! // Also "\zs", "\z1", etc. ! // Also "\@<", "\@=", "\@<=", etc. ! // And also "\_$" and "\_^". if (arg[0] == '\\' && ((arg[1] != NUL && arg[2] == NUL) || (vim_strchr((char_u *)"%_z@", arg[1]) != NULL *************** *** 5441,5457 **** { STRCPY(d, "/\\\\"); STRCPY(d + 3, arg + 1); ! /* Check for "/\\_$", should be "/\\_\$" */ if (d[3] == '_' && d[4] == '$') STRCPY(d + 4, "\\$"); } else { ! /* Replace: ! * "[:...:]" with "\[:...:]" ! * "[++...]" with "\[++...]" ! * "\{" with "\\{" -- matching "} \}" ! */ if ((arg[0] == '[' && (arg[1] == ':' || (arg[1] == '+' && arg[2] == '+'))) || (arg[0] == '\\' && arg[1] == '{')) --- 5438,5453 ---- { STRCPY(d, "/\\\\"); STRCPY(d + 3, arg + 1); ! // Check for "/\\_$", should be "/\\_\$" if (d[3] == '_' && d[4] == '$') STRCPY(d + 4, "\\$"); } else { ! // Replace: ! // "[:...:]" with "\[:...:]" ! // "[++...]" with "\[++...]" ! // "\{" with "\\{" -- matching "} \}" if ((arg[0] == '[' && (arg[1] == ':' || (arg[1] == '+' && arg[2] == '+'))) || (arg[0] == '\\' && arg[1] == '{')) *************** *** 5472,5478 **** * Insert a backslash before '~', '$' and '.' to avoid their * special meaning. */ ! if (d - IObuff > IOSIZE - 10) /* getting too long!? */ break; switch (*s) { --- 5468,5474 ---- * Insert a backslash before '~', '$' and '.' to avoid their * special meaning. */ ! if (d - IObuff > IOSIZE - 10) // getting too long!? break; switch (*s) { *************** *** 5501,5507 **** || vim_strchr((char_u *)"?@[\\]^", s[1]) != NULL))) { if (d > IObuff && d[-1] != '_' && d[-1] != '\\') ! *d++ = '_'; /* prepend a '_' to make x_CTRL-x */ STRCPY(d, "CTRL-"); d += 5; if (*s < ' ') --- 5497,5503 ---- || vim_strchr((char_u *)"?@[\\]^", s[1]) != NULL))) { if (d > IObuff && d[-1] != '_' && d[-1] != '\\') ! *d++ = '_'; // prepend a '_' to make x_CTRL-x STRCPY(d, "CTRL-"); d += 5; if (*s < ' ') *************** *** 5512,5526 **** *d++ = *s + '@'; #endif if (d[-1] == '\\') ! *d++ = '\\'; /* double a backslash */ } else *d++ = *++s; if (s[1] != NUL && s[1] != '_') ! *d++ = '_'; /* append a '_' */ continue; } ! else if (*s == '^') /* "^" or "CTRL-^" or "^_" */ *d++ = '\\'; /* --- 5508,5522 ---- *d++ = *s + '@'; #endif if (d[-1] == '\\') ! *d++ = '\\'; // double a backslash } else *d++ = *++s; if (s[1] != NUL && s[1] != '_') ! *d++ = '_'; // append a '_' continue; } ! else if (*s == '^') // "^" or "CTRL-^" or "^_" *d++ = '\\'; /* *************** *** 5531,5538 **** && *arg == '/' && s == arg + 1) *d++ = '\\'; ! /* "CTRL-\_" -> "CTRL-\\_" to avoid the special meaning of "\_" in ! * "CTRL-\_CTRL-N" */ if (STRNICMP(s, "CTRL-\\_", 7) == 0) { STRCPY(d, "CTRL-\\\\"); --- 5527,5534 ---- && *arg == '/' && s == arg + 1) *d++ = '\\'; ! // "CTRL-\_" -> "CTRL-\\_" to avoid the special meaning of "\_" in ! // "CTRL-\_CTRL-N" if (STRNICMP(s, "CTRL-\\_", 7) == 0) { STRCPY(d, "CTRL-\\\\"); *************** *** 5555,5561 **** */ if (*s == '\'' && s > arg && *arg == '\'') break; ! /* Also '{' and '}'. */ if (*s == '}' && s > arg && *arg == '{') break; } --- 5551,5557 ---- */ if (*s == '\'' && s > arg && *arg == '\'') break; ! // Also '{' and '}'. if (*s == '}' && s > arg && *arg == '{') break; } *************** *** 5565,5584 **** { if (d > IObuff + 2 && d[-1] == '`') { ! /* remove the backticks from `command` */ mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-2] = NUL; } else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') { ! /* remove the backticks and comma from `command`, */ mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-3] = NUL; } else if (d > IObuff + 4 && d[-3] == '`' && d[-2] == '\\' && d[-1] == '.') { ! /* remove the backticks and dot from `command`\. */ mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-4] = NUL; } --- 5561,5580 ---- { if (d > IObuff + 2 && d[-1] == '`') { ! // remove the backticks from `command` mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-2] = NUL; } else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') { ! // remove the backticks and comma from `command`, mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-3] = NUL; } else if (d > IObuff + 4 && d[-3] == '`' && d[-2] == '\\' && d[-1] == '.') { ! // remove the backticks and dot from `command`\. mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); d[-4] = NUL; } *************** *** 5594,5604 **** if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK && *num_matches > 0) { ! /* Sort the matches found on the heuristic number that is after the ! * tag name. */ qsort((void *)*matches, (size_t)*num_matches, sizeof(char_u *), help_compare); ! /* Delete more than TAG_MANY to reduce the size of the listing. */ while (*num_matches > TAG_MANY) vim_free((*matches)[--*num_matches]); } --- 5590,5600 ---- if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK && *num_matches > 0) { ! // Sort the matches found on the heuristic number that is after the ! // tag name. qsort((void *)*matches, (size_t)*num_matches, sizeof(char_u *), help_compare); ! // Delete more than TAG_MANY to reduce the size of the listing. while (*num_matches > TAG_MANY) vim_free((*matches)[--*num_matches]); } *************** *** 5640,5672 **** } #ifdef FEAT_FOLDING ! /* Don't use the global foldmethod.*/ set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual", OPT_FREE|OPT_LOCAL, 0); #endif ! curbuf->b_p_ts = 8; /* 'tabstop' is 8 */ ! curwin->w_p_list = FALSE; /* no list mode */ ! curbuf->b_p_ma = FALSE; /* not modifiable */ ! curbuf->b_p_bin = FALSE; /* reset 'bin' before reading file */ ! curwin->w_p_nu = 0; /* no line numbers */ ! curwin->w_p_rnu = 0; /* no relative line numbers */ ! RESET_BINDING(curwin); /* no scroll or cursor binding */ #ifdef FEAT_ARABIC ! curwin->w_p_arab = FALSE; /* no arabic mode */ #endif #ifdef FEAT_RIGHTLEFT ! curwin->w_p_rl = FALSE; /* help window is left-to-right */ #endif #ifdef FEAT_FOLDING ! curwin->w_p_fen = FALSE; /* No folding in the help window */ #endif #ifdef FEAT_DIFF ! curwin->w_p_diff = FALSE; /* No 'diff' */ #endif #ifdef FEAT_SPELL ! curwin->w_p_spell = FALSE; /* No spell checking */ #endif set_buflisted(FALSE); --- 5636,5668 ---- } #ifdef FEAT_FOLDING ! // Don't use the global foldmethod. set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual", OPT_FREE|OPT_LOCAL, 0); #endif ! curbuf->b_p_ts = 8; // 'tabstop' is 8 ! curwin->w_p_list = FALSE; // no list mode ! curbuf->b_p_ma = FALSE; // not modifiable ! curbuf->b_p_bin = FALSE; // reset 'bin' before reading file ! curwin->w_p_nu = 0; // no line numbers ! curwin->w_p_rnu = 0; // no relative line numbers ! RESET_BINDING(curwin); // no scroll or cursor binding #ifdef FEAT_ARABIC ! curwin->w_p_arab = FALSE; // no arabic mode #endif #ifdef FEAT_RIGHTLEFT ! curwin->w_p_rl = FALSE; // help window is left-to-right #endif #ifdef FEAT_FOLDING ! curwin->w_p_fen = FALSE; // No folding in the help window #endif #ifdef FEAT_DIFF ! curwin->w_p_diff = FALSE; // No 'diff' #endif #ifdef FEAT_SPELL ! curwin->w_p_spell = FALSE; // No spell checking #endif set_buflisted(FALSE); *************** *** 5688,5694 **** char_u *rt; int mustfree; ! /* Set filetype to "help" if still needed. */ if (STRCMP(curbuf->b_p_ft, "help") != 0) { ++curbuf_lock; --- 5684,5690 ---- char_u *rt; int mustfree; ! // Set filetype to "help" if still needed. if (STRCMP(curbuf->b_p_ft, "help") != 0) { ++curbuf_lock; *************** *** 5706,5715 **** len = (int)STRLEN(line); if (in_example && len > 0 && !VIM_ISWHITE(line[0])) { ! /* End of example: non-white or '<' in first column. */ if (line[0] == '<') { ! /* blank-out a '<' in the first column */ line = ml_get_buf(curbuf, lnum, TRUE); line[0] = ' '; } --- 5702,5711 ---- len = (int)STRLEN(line); if (in_example && len > 0 && !VIM_ISWHITE(line[0])) { ! // End of example: non-white or '<' in first column. if (line[0] == '<') { ! // blank-out a '<' in the first column line = ml_get_buf(curbuf, lnum, TRUE); line[0] = ' '; } *************** *** 5719,5732 **** { if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) { ! /* blank-out a '>' in the last column (start of example) */ line = ml_get_buf(curbuf, lnum, TRUE); line[len - 1] = ' '; in_example = TRUE; } else if (line[len - 1] == '~') { ! /* blank-out a '~' at the end of line (header marker) */ line = ml_get_buf(curbuf, lnum, TRUE); line[len - 1] = ' '; } --- 5715,5728 ---- { if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) { ! // blank-out a '>' in the last column (start of example) line = ml_get_buf(curbuf, lnum, TRUE); line[len - 1] = ' '; in_example = TRUE; } else if (line[len - 1] == '~') { ! // blank-out a '~' at the end of line (header marker) line = ml_get_buf(curbuf, lnum, TRUE); line[len - 1] = ' '; } *************** *** 5755,5762 **** if (strstr((char *)line, "*local-additions*") == NULL) continue; ! /* Go through all directories in 'runtimepath', skipping ! * $VIMRUNTIME. */ p = p_rtp; while (*p != NUL) { --- 5751,5758 ---- if (strstr((char *)line, "*local-additions*") == NULL) continue; ! // Go through all directories in 'runtimepath', skipping ! // $VIMRUNTIME. p = p_rtp; while (*p != NUL) { *************** *** 5774,5780 **** vimconv_T vc; char_u *cp; ! /* Find all "doc/ *.txt" files in this directory. */ add_pathsep(NameBuff); #ifdef FEAT_MULTI_LANG STRCAT(NameBuff, "doc/*.??[tx]"); --- 5770,5776 ---- vimconv_T vc; char_u *cp; ! // Find all "doc/ *.txt" files in this directory. add_pathsep(NameBuff); #ifdef FEAT_MULTI_LANG STRCAT(NameBuff, "doc/*.??[tx]"); *************** *** 5791,5798 **** char_u *t1, *t2; char_u *e1, *e2; ! /* If foo.abx is found use it instead of foo.txt in ! * the same directory. */ for (i1 = 0; i1 < fcount; ++i1) { for (i2 = 0; i2 < fcount; ++i2) --- 5787,5794 ---- char_u *t1, *t2; char_u *e1, *e2; ! // If foo.abx is found use it instead of foo.txt in ! // the same directory. for (i1 = 0; i1 < fcount; ++i1) { for (i2 = 0; i2 < fcount; ++i2) *************** *** 5812,5818 **** if (fnamecmp(e1, ".txt") != 0 && fnamecmp(e1, fname + 4) != 0) { ! /* Not .txt and not .abx, remove it. */ VIM_CLEAR(fnames[i1]); continue; } --- 5808,5814 ---- if (fnamecmp(e1, ".txt") != 0 && fnamecmp(e1, fname + 4) != 0) { ! // Not .txt and not .abx, remove it. VIM_CLEAR(fnames[i1]); continue; } *************** *** 5821,5827 **** continue; if (fnamecmp(e1, ".txt") == 0 && fnamecmp(e2, fname + 4) == 0) ! /* use .abx instead of .txt */ VIM_CLEAR(fnames[i1]); } } --- 5817,5823 ---- continue; if (fnamecmp(e1, ".txt") == 0 && fnamecmp(e2, fname + 4) == 0) ! // use .abx instead of .txt VIM_CLEAR(fnames[i1]); } } *************** *** 5840,5857 **** { int this_utf = MAYBE; ! /* Change tag definition to a ! * reference and remove /. */ IObuff[0] = '|'; *s = '|'; while (*s != NUL) { if (*s == '\r' || *s == '\n') *s = NUL; ! /* The text is utf-8 when a byte ! * above 127 is found and no ! * illegal byte sequence is found. ! */ if (*s >= 0x80 && this_utf != FALSE) { int l; --- 5836,5852 ---- { int this_utf = MAYBE; ! // Change tag definition to a ! // reference and remove /. IObuff[0] = '|'; *s = '|'; while (*s != NUL) { if (*s == '\r' || *s == '\n') *s = NUL; ! // The text is utf-8 when a byte ! // above 127 is found and no ! // illegal byte sequence is found. if (*s >= 0x80 && this_utf != FALSE) { int l; *************** *** 5865,5884 **** ++s; } ! /* The help file is latin1 or utf-8; ! * conversion to the current ! * 'encoding' may be required. */ vc.vc_type = CONV_NONE; convert_setup(&vc, (char_u *)( this_utf == TRUE ? "utf-8" : "latin1"), p_enc); if (vc.vc_type == CONV_NONE) ! /* No conversion needed. */ cp = IObuff; else { ! /* Do the conversion. If it fails ! * use the unconverted text. */ cp = string_convert(&vc, IObuff, NULL); if (cp == NULL) --- 5860,5879 ---- ++s; } ! // The help file is latin1 or utf-8; ! // conversion to the current ! // 'encoding' may be required. vc.vc_type = CONV_NONE; convert_setup(&vc, (char_u *)( this_utf == TRUE ? "utf-8" : "latin1"), p_enc); if (vc.vc_type == CONV_NONE) ! // No conversion needed. cp = IObuff; else { ! // Do the conversion. If it fails ! // use the unconverted text. cp = string_convert(&vc, IObuff, NULL); if (cp == NULL) *************** *** 5928,5937 **** */ static void helptags_one( ! char_u *dir, /* doc directory */ ! char_u *ext, /* suffix, ".txt", ".itx", ".frx", etc. */ ! char_u *tagfname, /* "tags" for English, "tags-fr" for French. */ ! int add_help_tags) /* add "help-tags" tag */ { FILE *fd_tags; FILE *fd; --- 5923,5932 ---- */ static void helptags_one( ! char_u *dir, // doc directory ! char_u *ext, // suffix, ".txt", ".itx", ".frx", etc. ! char_u *tagfname, // "tags" for English, "tags-fr" for French. ! int add_help_tags) // add "help-tags" tag { FILE *fd_tags; FILE *fd; *************** *** 5947,5953 **** int utf8 = MAYBE; int this_utf8; int firstline; ! int mix = FALSE; /* detected mixed encodings */ /* * Find all *.txt files. --- 5942,5948 ---- int utf8 = MAYBE; int this_utf8; int firstline; ! int mix = FALSE; // detected mixed encodings /* * Find all *.txt files. *************** *** 6022,6028 **** { if (firstline) { ! /* Detect utf-8 file by a non-ASCII char in the first line. */ this_utf8 = MAYBE; for (s = IObuff; *s != NUL; ++s) if (*s >= 0x80) --- 6017,6023 ---- { if (firstline) { ! // Detect utf-8 file by a non-ASCII char in the first line. this_utf8 = MAYBE; for (s = IObuff; *s != NUL; ++s) if (*s >= 0x80) *************** *** 6033,6047 **** l = utf_ptr2len(s); if (l == 1) { ! /* Illegal UTF-8 byte sequence. */ this_utf8 = FALSE; break; } s += l - 1; } ! if (this_utf8 == MAYBE) /* only ASCII characters found */ this_utf8 = FALSE; ! if (utf8 == MAYBE) /* first file */ utf8 = this_utf8; else if (utf8 != this_utf8) { --- 6028,6042 ---- l = utf_ptr2len(s); if (l == 1) { ! // Illegal UTF-8 byte sequence. this_utf8 = FALSE; break; } s += l - 1; } ! if (this_utf8 == MAYBE) // only ASCII characters found this_utf8 = FALSE; ! if (utf8 == MAYBE) // first file utf8 = this_utf8; else if (utf8 != this_utf8) { *************** *** 6051,6064 **** } firstline = FALSE; } ! p1 = vim_strchr(IObuff, '*'); /* find first '*' */ while (p1 != NULL) { ! /* Use vim_strbyte() instead of vim_strchr() so that when ! * 'encoding' is dbcs it still works, don't find '*' in the ! * second byte. */ ! p2 = vim_strbyte(p1 + 1, '*'); /* find second '*' */ ! if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */ { for (s = p1 + 1; s < p2; ++s) if (*s == ' ' || *s == '\t' || *s == '|') --- 6046,6059 ---- } firstline = FALSE; } ! p1 = vim_strchr(IObuff, '*'); // find first '*' while (p1 != NULL) { ! // Use vim_strbyte() instead of vim_strchr() so that when ! // 'encoding' is dbcs it still works, don't find '*' in the ! // second byte. ! p2 = vim_strbyte(p1 + 1, '*'); // find second '*' ! if (p2 != NULL && p2 > p1 + 1) // skip "*" and "**" { for (s = p1 + 1; s < p2; ++s) if (*s == ' ' || *s == '\t' || *s == '|') *************** *** 6091,6097 **** ++ga.ga_len; sprintf((char *)s, "%s\t%s", p1, fname); ! /* find next '*' */ p2 = vim_strchr(p2 + 1, '*'); } } --- 6086,6092 ---- ++ga.ga_len; sprintf((char *)s, "%s\t%s", p1, fname); ! // find next '*' p2 = vim_strchr(p2 + 1, '*'); } } *************** *** 6147,6160 **** { s = ((char_u **)ga.ga_data)[i]; if (STRNCMP(s, "help-tags\t", 10) == 0) ! /* help-tags entry was added in formatted form */ fputs((char *)s, fd_tags); else { fprintf(fd_tags, "%s\t/*", s); for (p1 = s; *p1 != '\t'; ++p1) { ! /* insert backslash before '\\' and '/' */ if (*p1 == '\\' || *p1 == '/') putc('\\', fd_tags); putc(*p1, fd_tags); --- 6142,6155 ---- { s = ((char_u **)ga.ga_data)[i]; if (STRNCMP(s, "help-tags\t", 10) == 0) ! // help-tags entry was added in formatted form fputs((char *)s, fd_tags); else { fprintf(fd_tags, "%s\t/*", s); for (p1 = s; *p1 != '\t'; ++p1) { ! // insert backslash before '\\' and '/' if (*p1 == '\\' || *p1 == '/') putc('\\', fd_tags); putc(*p1, fd_tags); *************** *** 6164,6175 **** } } if (mix) ! got_int = FALSE; /* continue with other languages */ for (i = 0; i < ga.ga_len; ++i) vim_free(((char_u **)ga.ga_data)[i]); ga_clear(&ga); ! fclose(fd_tags); /* there is no check for an error... */ } /* --- 6159,6170 ---- } } if (mix) ! got_int = FALSE; // continue with other languages for (i = 0; i < ga.ga_len; ++i) vim_free(((char_u **)ga.ga_data)[i]); ga_clear(&ga); ! fclose(fd_tags); // there is no check for an error... } /* *************** *** 6188,6194 **** int filecount; char_u **files; ! /* Get a list of all files in the help directory and in subdirectories. */ STRCPY(NameBuff, dirname); add_pathsep(NameBuff); STRCAT(NameBuff, "**"); --- 6183,6189 ---- int filecount; char_u **files; ! // Get a list of all files in the help directory and in subdirectories. STRCPY(NameBuff, dirname); add_pathsep(NameBuff); STRCAT(NameBuff, "**"); *************** *** 6200,6207 **** return; } ! /* Go over all files in the directory to find out what languages are ! * present. */ ga_init2(&ga, 1, 10); for (i = 0; i < filecount; ++i) { --- 6195,6202 ---- return; } ! // Go over all files in the directory to find out what languages are ! // present. ga_init2(&ga, 1, 10); for (i = 0; i < filecount; ++i) { *************** *** 6210,6216 **** { if (STRICMP(files[i] + len - 4, ".txt") == 0) { ! /* ".txt" -> language "en" */ lang[0] = 'e'; lang[1] = 'n'; } --- 6205,6211 ---- { if (STRICMP(files[i] + len - 4, ".txt") == 0) { ! // ".txt" -> language "en" lang[0] = 'e'; lang[1] = 'n'; } *************** *** 6219,6238 **** && ASCII_ISALPHA(files[i][len - 2]) && TOLOWER_ASC(files[i][len - 1]) == 'x') { ! /* ".abx" -> language "ab" */ lang[0] = TOLOWER_ASC(files[i][len - 3]); lang[1] = TOLOWER_ASC(files[i][len - 2]); } else continue; ! /* Did we find this language already? */ for (j = 0; j < ga.ga_len; j += 2) if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0) break; if (j == ga.ga_len) { ! /* New language, add it. */ if (ga_grow(&ga, 2) == FAIL) break; ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; --- 6214,6233 ---- && ASCII_ISALPHA(files[i][len - 2]) && TOLOWER_ASC(files[i][len - 1]) == 'x') { ! // ".abx" -> language "ab" lang[0] = TOLOWER_ASC(files[i][len - 3]); lang[1] = TOLOWER_ASC(files[i][len - 2]); } else continue; ! // Did we find this language already? for (j = 0; j < ga.ga_len; j += 2) if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0) break; if (j == ga.ga_len) { ! // New language, add it. if (ga_grow(&ga, 2) == FAIL) break; ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; *************** *** 6251,6263 **** fname[6] = ((char_u *)ga.ga_data)[j + 1]; if (fname[5] == 'e' && fname[6] == 'n') { ! /* English is an exception: use ".txt" and "tags". */ fname[4] = NUL; STRCPY(ext, ".txt"); } else { ! /* Language "ab" uses ".abx" and "tags-ab". */ STRCPY(ext, ".xxx"); ext[1] = fname[5]; ext[2] = fname[6]; --- 6246,6258 ---- fname[6] = ((char_u *)ga.ga_data)[j + 1]; if (fname[5] == 'e' && fname[6] == 'n') { ! // English is an exception: use ".txt" and "tags". fname[4] = NUL; STRCPY(ext, ".txt"); } else { ! // Language "ab" uses ".abx" and "tags-ab". STRCPY(ext, ".xxx"); ext[1] = fname[5]; ext[2] = fname[6]; *************** *** 6269,6275 **** FreeWild(filecount, files); #else ! /* No language support, just use "*.txt" and "tags". */ helptags_one(dirname, (char_u *)".txt", (char_u *)"tags", add_help_tags); #endif } --- 6264,6270 ---- FreeWild(filecount, files); #else ! // No language support, just use "*.txt" and "tags". helptags_one(dirname, (char_u *)".txt", (char_u *)"tags", add_help_tags); #endif } *************** *** 6290,6296 **** char_u *dirname; int add_help_tags = FALSE; ! /* Check for ":helptags ++t {dir}". */ if (STRNCMP(eap->arg, "++t", 3) == 0 && VIM_ISWHITE(eap->arg[3])) { add_help_tags = TRUE; --- 6285,6291 ---- char_u *dirname; int add_help_tags = FALSE; ! // Check for ":helptags ++t {dir}". if (STRNCMP(eap->arg, "++t", 3) == 0 && VIM_ISWHITE(eap->arg[3])) { add_help_tags = TRUE; *************** *** 6378,6393 **** if (cmdmod.tab) { ! /* ":tab drop file ...": open a tab for each argument that isn't ! * edited in a window yet. It's like ":tab all" but without closing ! * windows or tabs. */ ex_all(eap); } else { ! /* ":drop file ...": Edit the first argument. Jump to an existing ! * window if possible, edit in current window if the current buffer ! * can be abandoned, otherwise open a new window. */ buf = buflist_findnr(ARGLIST[0].ae_fnum); FOR_ALL_TAB_WINDOWS(tp, wp) --- 6373,6388 ---- if (cmdmod.tab) { ! // ":tab drop file ...": open a tab for each argument that isn't ! // edited in a window yet. It's like ":tab all" but without closing ! // windows or tabs. ex_all(eap); } else { ! // ":drop file ...": Edit the first argument. Jump to an existing ! // window if possible, edit in current window if the current buffer ! // can be abandoned, otherwise open a new window. buf = buflist_findnr(ARGLIST[0].ae_fnum); FOR_ALL_TAB_WINDOWS(tp, wp) *************** *** 6413,6419 **** --emsg_off; } ! /* Fake a ":sfirst" or ":first" command edit the first argument. */ if (split) { eap->cmdidx = CMD_sfirst; --- 6408,6414 ---- --emsg_off; } ! // Fake a ":sfirst" or ":first" command edit the first argument. if (split) { eap->cmdidx = CMD_sfirst; *************** *** 6439,6445 **** if (vim_isIDc(*p)) { ! /* ":vimgrep pattern fname" */ if (s != NULL) *s = p; p = skiptowhite(p); --- 6434,6440 ---- if (vim_isIDc(*p)) { ! // ":vimgrep pattern fname" if (s != NULL) *s = p; p = skiptowhite(p); *************** *** 6448,6454 **** } else { ! /* ":vimgrep /pattern/[g][j] fname" */ if (s != NULL) *s = p + 1; c = *p; --- 6443,6449 ---- } else { ! // ":vimgrep /pattern/[g][j] fname" if (s != NULL) *s = p + 1; c = *p; *************** *** 6456,6467 **** if (*p != c) return NULL; ! /* Truncate the pattern. */ if (s != NULL) *p = NUL; ++p; ! /* Find the flags */ while (*p == 'g' || *p == 'j') { if (flags != NULL) --- 6451,6462 ---- if (*p != c) return NULL; ! // Truncate the pattern. if (s != NULL) *p = NUL; ++p; ! // Find the flags while (*p == 'g' || *p == 'j') { if (flags != NULL) *************** *** 6506,6517 **** msg_outtrans(fname); msg_clr_eos(); msg_putchar('\n'); ! out_flush(); /* output one line at a time */ ui_breakcheck(); } } ! /* Assume "got_int" was set to truncate the listing. */ got_int = FALSE; # ifdef FEAT_BROWSE_CMD --- 6501,6512 ---- msg_outtrans(fname); msg_clr_eos(); msg_putchar('\n'); ! out_flush(); // output one line at a time ui_breakcheck(); } } ! // Assume "got_int" was set to truncate the listing. got_int = FALSE; # ifdef FEAT_BROWSE_CMD *** ../vim-8.1.2378/src/ex_cmds2.c 2019-09-10 21:27:15.171646995 +0200 --- src/ex_cmds2.c 2019-12-01 21:24:22.574050634 +0100 *************** *** 89,95 **** if (timer == NULL) return NULL; if (++last_timer_id <= prev_id) ! /* Overflow! Might cause duplicates... */ last_timer_id = 0; timer->tr_id = last_timer_id; insert_timer(timer); --- 89,95 ---- if (timer == NULL) return NULL; if (++last_timer_id <= prev_id) ! // Overflow! Might cause duplicates... last_timer_id = 0; timer->tr_id = last_timer_id; insert_timer(timer); *************** *** 135,141 **** int need_update_screen = FALSE; long current_id = last_timer_id; ! /* Don't run any timers while exiting or dealing with an error. */ if (exiting || aborting()) return next_due; --- 135,141 ---- int need_update_screen = FALSE; long current_id = last_timer_id; ! // Don't run any timers while exiting or dealing with an error. if (exiting || aborting()) return next_due; *************** *** 149,156 **** this_due = proftime_time_left(&timer->tr_due, &now); if (this_due <= 1) { ! /* Save and restore a lot of flags, because the timer fires while ! * waiting for a character, which might be halfway a command. */ int save_timer_busy = timer_busy; int save_vgetc_busy = vgetc_busy; int save_did_emsg = did_emsg; --- 149,156 ---- this_due = proftime_time_left(&timer->tr_due, &now); if (this_due <= 1) { ! // Save and restore a lot of flags, because the timer fires while ! // waiting for a character, which might be halfway a command. int save_timer_busy = timer_busy; int save_vgetc_busy = vgetc_busy; int save_did_emsg = did_emsg; *************** *** 163,170 **** except_T *save_current_exception = current_exception; vimvars_save_T vvsave; ! /* Create a scope for running the timer callback, ignoring most of ! * the current scope, such as being inside a try/catch. */ timer_busy = timer_busy > 0 || vgetc_busy > 0; vgetc_busy = 0; called_emsg = FALSE; --- 163,170 ---- except_T *save_current_exception = current_exception; vimvars_save_T vvsave; ! // Create a scope for running the timer callback, ignoring most of ! // the current scope, such as being inside a try/catch. timer_busy = timer_busy > 0 || vgetc_busy > 0; vgetc_busy = 0; called_emsg = FALSE; *************** *** 200,207 **** set_pressedreturn(save_ex_pressedreturn); may_garbage_collect = save_may_garbage_collect; ! /* Only fire the timer again if it repeats and stop_timer() wasn't ! * called while inside the callback (tr_id == -1). */ if (timer->tr_repeat != 0 && timer->tr_id != -1 && timer->tr_emsg_count < 3) { --- 200,207 ---- set_pressedreturn(save_ex_pressedreturn); may_garbage_collect = save_may_garbage_collect; ! // Only fire the timer again if it repeats and stop_timer() wasn't ! // called while inside the callback (tr_id == -1). if (timer->tr_repeat != 0 && timer->tr_id != -1 && timer->tr_emsg_count < 3) { *************** *** 250,256 **** } #endif #ifdef FEAT_TERMINAL ! /* Some terminal windows may need their buffer updated. */ next_due = term_check_timers(next_due, &now); #endif --- 250,256 ---- } #endif #ifdef FEAT_TERMINAL ! // Some terminal windows may need their buffer updated. next_due = term_check_timers(next_due, &now); #endif *************** *** 282,288 **** stop_timer(timer_T *timer) { if (timer->tr_firing) ! /* Free the timer after the callback returns. */ timer->tr_id = -1; else { --- 282,288 ---- stop_timer(timer_T *timer) { if (timer->tr_firing) ! // Free the timer after the callback returns. timer->tr_id = -1; else { *************** *** 520,526 **** if (!(p_aw || p_awa) || !p_write #ifdef FEAT_QUICKFIX ! /* never autowrite a "nofile" or "nowrite" buffer */ || bt_dontwrite(buf) #endif || (!forceit && buf->b_p_ro) || buf->b_ffname == NULL) --- 520,526 ---- if (!(p_aw || p_awa) || !p_write #ifdef FEAT_QUICKFIX ! // never autowrite a "nofile" or "nowrite" buffer || bt_dontwrite(buf) #endif || (!forceit && buf->b_p_ro) || buf->b_ffname == NULL) *************** *** 528,535 **** set_bufref(&bufref, buf); r = buf_write_all(buf, forceit); ! /* Writing may succeed but the buffer still changed, e.g., when there is a ! * conversion error. We do want to return FAIL then. */ if (bufref_valid(&bufref) && bufIsChanged(buf)) r = FAIL; return r; --- 528,535 ---- set_bufref(&bufref, buf); r = buf_write_all(buf, forceit); ! // Writing may succeed but the buffer still changed, e.g., when there is a ! // conversion error. We do want to return FAIL then. if (bufref_valid(&bufref) && bufIsChanged(buf)) r = FAIL; return r; *************** *** 554,560 **** (void)buf_write_all(buf, FALSE); ! /* an autocommand may have deleted the buffer */ if (!bufref_valid(&bufref)) buf = firstbuf; } --- 554,560 ---- (void)buf_write_all(buf, FALSE); ! // an autocommand may have deleted the buffer if (!bufref_valid(&bufref)) buf = firstbuf; } *************** *** 593,605 **** )) ++count; if (!bufref_valid(&bufref)) ! /* Autocommand deleted buffer, oops! It's not changed now. */ return FALSE; dialog_changed(buf, count > 1); if (!bufref_valid(&bufref)) ! /* Autocommand deleted buffer, oops! It's not changed now. */ return FALSE; return bufIsChanged(buf); } --- 593,605 ---- )) ++count; if (!bufref_valid(&bufref)) ! // Autocommand deleted buffer, oops! It's not changed now. return FALSE; dialog_changed(buf, count > 1); if (!bufref_valid(&bufref)) ! // Autocommand deleted buffer, oops! It's not changed now. return FALSE; return bufIsChanged(buf); } *************** *** 645,651 **** void dialog_changed( buf_T *buf, ! int checkall) /* may abandon all changed buffers */ { char_u buff[DIALOG_MSG_SIZE]; int ret; --- 645,651 ---- void dialog_changed( buf_T *buf, ! int checkall) // may abandon all changed buffers { char_u buff[DIALOG_MSG_SIZE]; int ret; *************** *** 665,676 **** if (ret == VIM_YES) { #ifdef FEAT_BROWSE ! /* May get file name, when there is none */ browse_save_fname(buf); #endif if (buf->b_fname != NULL && check_overwrite(&ea, buf, buf->b_fname, buf->b_ffname, FALSE) == OK) ! /* didn't hit Cancel */ (void)buf_write_all(buf, FALSE); } else if (ret == VIM_NO) --- 665,676 ---- if (ret == VIM_YES) { #ifdef FEAT_BROWSE ! // May get file name, when there is none browse_save_fname(buf); #endif if (buf->b_fname != NULL && check_overwrite(&ea, buf, buf->b_fname, buf->b_ffname, FALSE) == OK) ! // didn't hit Cancel (void)buf_write_all(buf, FALSE); } else if (ret == VIM_NO) *************** *** 698,712 **** set_bufref(&bufref, buf2); #ifdef FEAT_BROWSE ! /* May get file name, when there is none */ browse_save_fname(buf2); #endif if (buf2->b_fname != NULL && check_overwrite(&ea, buf2, buf2->b_fname, buf2->b_ffname, FALSE) == OK) ! /* didn't hit Cancel */ (void)buf_write_all(buf2, FALSE); ! /* an autocommand may have deleted the buffer */ if (!bufref_valid(&bufref)) buf2 = firstbuf; } --- 698,712 ---- set_bufref(&bufref, buf2); #ifdef FEAT_BROWSE ! // May get file name, when there is none browse_save_fname(buf2); #endif if (buf2->b_fname != NULL && check_overwrite(&ea, buf2, buf2->b_fname, buf2->b_ffname, FALSE) == OK) ! // didn't hit Cancel (void)buf_write_all(buf2, FALSE); ! // an autocommand may have deleted the buffer if (!bufref_valid(&bufref)) buf2 = firstbuf; } *************** *** 760,766 **** */ int check_changed_any( ! int hidden, /* Only check hidden buffers */ int unload) { int ret = FALSE; --- 760,766 ---- */ int check_changed_any( ! int hidden, // Only check hidden buffers int unload) { int ret = FALSE; *************** *** 773,779 **** tabpage_T *tp; win_T *wp; ! /* Make a list of all buffers, with the most important ones first. */ FOR_ALL_BUFFERS(buf) ++bufcount; --- 773,779 ---- tabpage_T *tp; win_T *wp; ! // Make a list of all buffers, with the most important ones first. FOR_ALL_BUFFERS(buf) ++bufcount; *************** *** 784,804 **** if (bufnrs == NULL) return FALSE; ! /* curbuf */ bufnrs[bufnum++] = curbuf->b_fnum; ! /* buffers in current tab */ FOR_ALL_WINDOWS(wp) if (wp->w_buffer != curbuf) add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); ! /* buffers in other tabs */ FOR_ALL_TABPAGES(tp) if (tp != curtab) for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); ! /* any other buffer */ FOR_ALL_BUFFERS(buf) add_bufnum(bufnrs, &bufnum, buf->b_fnum); --- 784,804 ---- if (bufnrs == NULL) return FALSE; ! // curbuf bufnrs[bufnum++] = curbuf->b_fnum; ! // buffers in current tab FOR_ALL_WINDOWS(wp) if (wp->w_buffer != curbuf) add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); ! // buffers in other tabs FOR_ALL_TABPAGES(tp) if (tp != curtab) for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next) add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum); ! // any other buffer FOR_ALL_BUFFERS(buf) add_bufnum(bufnrs, &bufnum, buf->b_fnum); *************** *** 820,838 **** } else #endif ! /* Try auto-writing the buffer. If this fails but the buffer no ! * longer exists it's not changed, that's OK. */ if (check_changed(buf, (p_awa ? CCGD_AW : 0) | CCGD_MULTWIN | CCGD_ALLBUF) && bufref_valid(&bufref)) ! break; /* didn't save - still changes */ } } if (i >= bufnum) goto theend; ! /* Get here if "buf" cannot be abandoned. */ ret = TRUE; exiting = FALSE; #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) --- 820,838 ---- } else #endif ! // Try auto-writing the buffer. If this fails but the buffer no ! // longer exists it's not changed, that's OK. if (check_changed(buf, (p_awa ? CCGD_AW : 0) | CCGD_MULTWIN | CCGD_ALLBUF) && bufref_valid(&bufref)) ! break; // didn't save - still changes } } if (i >= bufnum) goto theend; ! // Get here if "buf" cannot be abandoned. ret = TRUE; exiting = FALSE; #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) *************** *** 842,851 **** if (!(p_confirm || cmdmod.confirm)) #endif { ! /* There must be a wait_return for this message, do_buffer() ! * may cause a redraw. But wait_return() is a no-op when vgetc() ! * is busy (Quit used from window menu), then make sure we don't ! * cause a scroll up. */ if (vgetc_busy > 0) { msg_row = cmdline_row; --- 842,851 ---- if (!(p_confirm || cmdmod.confirm)) #endif { ! // There must be a wait_return for this message, do_buffer() ! // may cause a redraw. But wait_return() is a no-op when vgetc() ! // is busy (Quit used from window menu), then make sure we don't ! // cause a scroll up. if (vgetc_busy > 0) { msg_row = cmdline_row; *************** *** 869,875 **** } } ! /* Try to find a window that contains the buffer. */ if (buf != curbuf) FOR_ALL_TAB_WINDOWS(tp, wp) if (wp->w_buffer == buf) --- 869,875 ---- } } ! // Try to find a window that contains the buffer. if (buf != curbuf) FOR_ALL_TAB_WINDOWS(tp, wp) if (wp->w_buffer == buf) *************** *** 887,893 **** } buf_found: ! /* Open the changed buffer in the current window. */ if (buf != curbuf) set_curbuf(buf, unload ? DOBUF_UNLOAD : DOBUF_GOTO); --- 887,893 ---- } buf_found: ! // Open the changed buffer in the current window. if (buf != curbuf) set_curbuf(buf, unload ? DOBUF_UNLOAD : DOBUF_GOTO); *************** *** 965,972 **** #if defined(FEAT_SYN_HL) if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) { ! /* Don't do syntax HL autocommands. Skipping the syntax file is a ! * great speed improvement. */ save_ei = au_event_disable(",Syntax"); for (buf = firstbuf; buf != NULL; buf = buf->b_next) --- 965,972 ---- #if defined(FEAT_SYN_HL) if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) { ! // Don't do syntax HL autocommands. Skipping the syntax file is a ! // great speed improvement. save_ei = au_event_disable(",Syntax"); for (buf = firstbuf; buf != NULL; buf = buf->b_next) *************** *** 986,992 **** | CCGD_EXCMD)) { i = 0; ! /* start at the eap->line1 argument/window/buffer */ wp = firstwin; tp = first_tabpage; switch (eap->cmdidx) --- 986,992 ---- | CCGD_EXCMD)) { i = 0; ! // start at the eap->line1 argument/window/buffer wp = firstwin; tp = first_tabpage; switch (eap->cmdidx) *************** *** 1005,1014 **** default: break; } ! /* set pcmark now */ if (eap->cmdidx == CMD_bufdo) { ! /* Advance to the first listed buffer after "eap->line1". */ for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1 || !buf->b_p_bl); buf = buf->b_next) if (buf->b_fnum > eap->line2) --- 1005,1014 ---- default: break; } ! // set pcmark now if (eap->cmdidx == CMD_bufdo) { ! // Advance to the first listed buffer after "eap->line1". for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1 || !buf->b_p_bl); buf = buf->b_next) if (buf->b_fnum > eap->line2) *************** *** 1033,1060 **** buf = curbuf; i = eap->line1 - 1; if (eap->addr_count <= 0) ! /* default is all the quickfix/location list entries */ eap->line2 = qf_size; } } #endif else setpcmark(); ! listcmd_busy = TRUE; /* avoids setting pcmark below */ while (!got_int && buf != NULL) { if (eap->cmdidx == CMD_argdo) { ! /* go to argument "i" */ if (i == ARGCOUNT) break; ! /* Don't call do_argfile() when already there, it will try ! * reloading the file. */ if (curwin->w_arg_idx != i || !editing_arg_idx(curwin)) { ! /* Clear 'shm' to avoid that the file message overwrites ! * any output from the command. */ p_shm_save = vim_strsave(p_shm); set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); do_argfile(eap, i); --- 1033,1060 ---- buf = curbuf; i = eap->line1 - 1; if (eap->addr_count <= 0) ! // default is all the quickfix/location list entries eap->line2 = qf_size; } } #endif else setpcmark(); ! listcmd_busy = TRUE; // avoids setting pcmark below while (!got_int && buf != NULL) { if (eap->cmdidx == CMD_argdo) { ! // go to argument "i" if (i == ARGCOUNT) break; ! // Don't call do_argfile() when already there, it will try ! // reloading the file. if (curwin->w_arg_idx != i || !editing_arg_idx(curwin)) { ! // Clear 'shm' to avoid that the file message overwrites ! // any output from the command. p_shm_save = vim_strsave(p_shm); set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); do_argfile(eap, i); *************** *** 1066,1082 **** } else if (eap->cmdidx == CMD_windo) { ! /* go to window "wp" */ if (!win_valid(wp)) break; win_goto(wp); if (curwin != wp) ! break; /* something must be wrong */ wp = curwin->w_next; } else if (eap->cmdidx == CMD_tabdo) { ! /* go to window "tp" */ if (!valid_tabpage(tp)) break; goto_tabpage_tp(tp, TRUE, TRUE); --- 1066,1082 ---- } else if (eap->cmdidx == CMD_windo) { ! // go to window "wp" if (!win_valid(wp)) break; win_goto(wp); if (curwin != wp) ! break; // something must be wrong wp = curwin->w_next; } else if (eap->cmdidx == CMD_tabdo) { ! // go to window "tp" if (!valid_tabpage(tp)) break; goto_tabpage_tp(tp, TRUE, TRUE); *************** *** 1084,1091 **** } else if (eap->cmdidx == CMD_bufdo) { ! /* Remember the number of the next listed buffer, in case ! * ":bwipe" is used or autocommands do something strange. */ next_fnum = -1; for (buf = curbuf->b_next; buf != NULL; buf = buf->b_next) if (buf->b_p_bl) --- 1084,1091 ---- } else if (eap->cmdidx == CMD_bufdo) { ! // Remember the number of the next listed buffer, in case ! // ":bwipe" is used or autocommands do something strange. next_fnum = -1; for (buf = curbuf->b_next; buf != NULL; buf = buf->b_next) if (buf->b_p_bl) *************** *** 1097,1127 **** ++i; ! /* execute the command */ do_cmdline(eap->arg, eap->getline, eap->cookie, DOCMD_VERBOSE + DOCMD_NOWAIT); if (eap->cmdidx == CMD_bufdo) { ! /* Done? */ if (next_fnum < 0 || next_fnum > eap->line2) break; ! /* Check if the buffer still exists. */ FOR_ALL_BUFFERS(buf) if (buf->b_fnum == next_fnum) break; if (buf == NULL) break; ! /* Go to the next buffer. Clear 'shm' to avoid that the file ! * message overwrites any output from the command. */ p_shm_save = vim_strsave(p_shm); set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); set_option_value((char_u *)"shm", 0L, p_shm_save, 0); vim_free(p_shm_save); ! /* If autocommands took us elsewhere, quit here. */ if (curbuf->b_fnum != next_fnum) break; } --- 1097,1127 ---- ++i; ! // execute the command do_cmdline(eap->arg, eap->getline, eap->cookie, DOCMD_VERBOSE + DOCMD_NOWAIT); if (eap->cmdidx == CMD_bufdo) { ! // Done? if (next_fnum < 0 || next_fnum > eap->line2) break; ! // Check if the buffer still exists. FOR_ALL_BUFFERS(buf) if (buf->b_fnum == next_fnum) break; if (buf == NULL) break; ! // Go to the next buffer. Clear 'shm' to avoid that the file ! // message overwrites any output from the command. p_shm_save = vim_strsave(p_shm); set_option_value((char_u *)"shm", 0L, (char_u *)"", 0); goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); set_option_value((char_u *)"shm", 0L, p_shm_save, 0); vim_free(p_shm_save); ! // If autocommands took us elsewhere, quit here. if (curbuf->b_fnum != next_fnum) break; } *************** *** 1137,1143 **** ex_cnext(eap); ! /* If jumping to the next quickfix entry fails, quit here */ if (qf_get_cur_idx(eap) == qf_idx) break; } --- 1137,1143 ---- ex_cnext(eap); ! // If jumping to the next quickfix entry fails, quit here if (qf_get_cur_idx(eap) == qf_idx) break; } *************** *** 1145,1153 **** if (eap->cmdidx == CMD_windo) { ! validate_cursor(); /* cursor may have moved */ ! /* required when 'scrollbind' has been set */ if (curwin->w_p_scb) do_check_scrollbind(TRUE); } --- 1145,1153 ---- if (eap->cmdidx == CMD_windo) { ! validate_cursor(); // cursor may have moved ! // required when 'scrollbind' has been set if (curwin->w_p_scb) do_check_scrollbind(TRUE); } *************** *** 1213,1221 **** if (*eap->arg == NUL) { ! /* List all compiler scripts. */ do_cmdline_cmd((char_u *)"echo globpath(&rtp, 'compiler/*.vim')"); ! /* ) keep the indenter happy... */ } else { --- 1213,1221 ---- if (*eap->arg == NUL) { ! // List all compiler scripts. do_cmdline_cmd((char_u *)"echo globpath(&rtp, 'compiler/*.vim')"); ! // ) keep the indenter happy... } else { *************** *** 1224,1241 **** { if (eap->forceit) { ! /* ":compiler! {name}" sets global options */ do_cmdline_cmd((char_u *) "command -nargs=* CompilerSet set "); } else { ! /* ":compiler! {name}" sets local options. ! * To remain backwards compatible "current_compiler" is always ! * used. A user's compiler plugin may set it, the distributed ! * plugin will then skip the settings. Afterwards set ! * "b:current_compiler" and restore "current_compiler". ! * Explicitly prepend "g:" to make it work in a function. */ old_cur_comp = get_var_value((char_u *)"g:current_compiler"); if (old_cur_comp != NULL) old_cur_comp = vim_strsave(old_cur_comp); --- 1224,1241 ---- { if (eap->forceit) { ! // ":compiler! {name}" sets global options do_cmdline_cmd((char_u *) "command -nargs=* CompilerSet set "); } else { ! // ":compiler! {name}" sets local options. ! // To remain backwards compatible "current_compiler" is always ! // used. A user's compiler plugin may set it, the distributed ! // plugin will then skip the settings. Afterwards set ! // "b:current_compiler" and restore "current_compiler". ! // Explicitly prepend "g:" to make it work in a function. old_cur_comp = get_var_value((char_u *)"g:current_compiler"); if (old_cur_comp != NULL) old_cur_comp = vim_strsave(old_cur_comp); *************** *** 1252,1263 **** do_cmdline_cmd((char_u *)":delcommand CompilerSet"); ! /* Set "b:current_compiler" from "current_compiler". */ p = get_var_value((char_u *)"g:current_compiler"); if (p != NULL) set_internal_string_var((char_u *)"b:current_compiler", p); ! /* Restore "current_compiler" for ":compiler {name}". */ if (!eap->forceit) { if (old_cur_comp != NULL) --- 1252,1263 ---- do_cmdline_cmd((char_u *)":delcommand CompilerSet"); ! // Set "b:current_compiler" from "current_compiler". p = get_var_value((char_u *)"g:current_compiler"); if (p != NULL) set_internal_string_var((char_u *)"b:current_compiler", p); ! // Restore "current_compiler" for ":compiler {name}". if (!eap->forceit) { if (old_cur_comp != NULL) *************** *** 1322,1328 **** break; if (i == 0 && IObuff[0] == '#' && IObuff[1] == '!') { ! /* Check shebang. */ if (strstr((char *)IObuff + 2, "python2") != NULL) { requires_py_version = 2; --- 1322,1328 ---- break; if (i == 0 && IObuff[0] == '#' && IObuff[1] == '!') { ! // Check shebang. if (strstr((char *)IObuff + 2, "python2") != NULL) { requires_py_version = 2; *************** *** 1367,1373 **** if (v == 0) { # if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) ! /* user didn't choose a preference, 'pyx' is used */ v = p_pyx; # elif defined(FEAT_PYTHON) v = 2; --- 1367,1373 ---- if (v == 0) { # if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3) ! // user didn't choose a preference, 'pyx' is used v = p_pyx; # elif defined(FEAT_PYTHON) v = 2; *************** *** 1472,1483 **** int save_no_check_timestamps = no_check_timestamps; no_check_timestamps = 0; ! if (eap->addr_count == 0) /* default is all buffers */ check_timestamps(FALSE); else { buf = buflist_findnr((int)eap->line2); ! if (buf != NULL) /* cannot happen? */ (void)buf_check_timestamp(buf, FALSE); } no_check_timestamps = save_no_check_timestamps; --- 1472,1483 ---- int save_no_check_timestamps = no_check_timestamps; no_check_timestamps = 0; ! if (eap->addr_count == 0) // default is all buffers check_timestamps(FALSE); else { buf = buflist_findnr((int)eap->line2); ! if (buf != NULL) // cannot happen? (void)buf_check_timestamp(buf, FALSE); } no_check_timestamps = save_no_check_timestamps; *************** *** 1491,1497 **** { char_u *loc; ! /* Obtain the locale value from the libraries. */ loc = (char_u *)setlocale(what, NULL); # ifdef MSWIN --- 1491,1497 ---- { char_u *loc; ! // Obtain the locale value from the libraries. loc = (char_u *)setlocale(what, NULL); # ifdef MSWIN *************** *** 1499,1511 **** { char_u *p; ! /* setocale() returns something like "LC_COLLATE=;LC_..." when ! * one of the values (e.g., LC_CTYPE) differs. */ p = vim_strchr(loc, '='); if (p != NULL) { loc = ++p; ! while (*p != NUL) /* remove trailing newline */ { if (*p < ' ' || *p == ';') { --- 1499,1511 ---- { char_u *p; ! // setocale() returns something like "LC_COLLATE=;LC_..." when ! // one of the values (e.g., LC_CTYPE) differs. p = vim_strchr(loc, '='); if (p != NULL) { loc = ++p; ! while (*p != NUL) // remove trailing newline { if (*p < ' ' || *p == ';') { *************** *** 1585,1594 **** # if defined(LC_MESSAGES) p = get_locale_val(LC_MESSAGES); # else ! /* This is necessary for Win32, where LC_MESSAGES is not defined and $LANG ! * may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME ! * and LC_MONETARY may be set differently for a Japanese working in the ! * US. */ p = get_locale_val(LC_COLLATE); # endif # else --- 1585,1594 ---- # if defined(LC_MESSAGES) p = get_locale_val(LC_MESSAGES); # else ! // This is necessary for Win32, where LC_MESSAGES is not defined and $LANG ! // may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME ! // and LC_MONETARY may be set differently for a Japanese working in the ! // US. p = get_locale_val(LC_COLLATE); # endif # else *************** *** 1607,1613 **** } #endif ! /* Complicated #if; matches with where get_mess_env() is used below. */ #if (defined(FEAT_EVAL) && !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ && defined(LC_MESSAGES))) \ || ((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ --- 1607,1613 ---- } #endif ! // Complicated #if; matches with where get_mess_env() is used below. #if (defined(FEAT_EVAL) && !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ && defined(LC_MESSAGES))) \ || ((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ *************** *** 1628,1634 **** { p = mch_getenv((char_u *)"LANG"); if (p != NULL && VIM_ISDIGIT(*p)) ! p = NULL; /* ignore something like "1043" */ # ifdef HAVE_GET_LOCALE_VAL if (p == NULL || *p == NUL) p = get_locale_val(LC_CTYPE); --- 1628,1634 ---- { p = mch_getenv((char_u *)"LANG"); if (p != NULL && VIM_ISDIGIT(*p)) ! p = NULL; // ignore something like "1043" # ifdef HAVE_GET_LOCALE_VAL if (p == NULL || *p == NUL) p = get_locale_val(LC_CTYPE); *************** *** 1653,1665 **** # ifdef HAVE_GET_LOCALE_VAL loc = get_locale_val(LC_CTYPE); # else ! /* setlocale() not supported: use the default value */ loc = (char_u *)"C"; # endif set_vim_var_string(VV_CTYPE, loc, -1); ! /* When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall ! * back to LC_CTYPE if it's empty. */ # if defined(HAVE_GET_LOCALE_VAL) && defined(LC_MESSAGES) loc = get_locale_val(LC_MESSAGES); # else --- 1653,1665 ---- # ifdef HAVE_GET_LOCALE_VAL loc = get_locale_val(LC_CTYPE); # else ! // setlocale() not supported: use the default value loc = (char_u *)"C"; # endif set_vim_var_string(VV_CTYPE, loc, -1); ! // When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall ! // back to LC_CTYPE if it's empty. # if defined(HAVE_GET_LOCALE_VAL) && defined(LC_MESSAGES) loc = get_locale_val(LC_MESSAGES); # else *************** *** 1694,1702 **** name = eap->arg; ! /* Check for "messages {name}", "ctype {name}" or "time {name}" argument. ! * Allow abbreviation, but require at least 3 characters to avoid ! * confusion with a two letter language name "me" or "ct". */ p = skiptowhite(eap->arg); if ((*p == NUL || VIM_ISWHITE(*p)) && p - eap->arg >= 3) { --- 1694,1702 ---- name = eap->arg; ! // Check for "messages {name}", "ctype {name}" or "time {name}" argument. ! // Allow abbreviation, but require at least 3 characters to avoid ! // confusion with a two letter language name "me" or "ct". p = skiptowhite(eap->arg); if ((*p == NUL || VIM_ISWHITE(*p)) && p - eap->arg >= 3) { *************** *** 1742,1748 **** { loc = setlocale(what, (char *)name); #if defined(FEAT_FLOAT) && defined(LC_NUMERIC) ! /* Make sure strtod() uses a decimal point, not a comma. */ setlocale(LC_NUMERIC, "C"); #endif } --- 1742,1748 ---- { loc = setlocale(what, (char *)name); #if defined(FEAT_FLOAT) && defined(LC_NUMERIC) ! // Make sure strtod() uses a decimal point, not a comma. setlocale(LC_NUMERIC, "C"); #endif } *************** *** 1751,1781 **** else { #ifdef HAVE_NL_MSG_CAT_CNTR ! /* Need to do this for GNU gettext, otherwise cached translations ! * will be used again. */ extern int _nl_msg_cat_cntr; ++_nl_msg_cat_cntr; #endif ! /* Reset $LC_ALL, otherwise it would overrule everything. */ vim_setenv((char_u *)"LC_ALL", (char_u *)""); if (what != LC_TIME) { ! /* Tell gettext() what to translate to. It apparently doesn't ! * use the currently effective locale. Also do this when ! * FEAT_GETTEXT isn't defined, so that shell commands use this ! * value. */ if (what == LC_ALL) { vim_setenv((char_u *)"LANG", name); ! /* Clear $LANGUAGE because GNU gettext uses it. */ vim_setenv((char_u *)"LANGUAGE", (char_u *)""); # ifdef MSWIN ! /* Apparently MS-Windows printf() may cause a crash when ! * we give it 8-bit text while it's expecting text in the ! * current locale. This call avoids that. */ setlocale(LC_CTYPE, "C"); # endif } --- 1751,1781 ---- else { #ifdef HAVE_NL_MSG_CAT_CNTR ! // Need to do this for GNU gettext, otherwise cached translations ! // will be used again. extern int _nl_msg_cat_cntr; ++_nl_msg_cat_cntr; #endif ! // Reset $LC_ALL, otherwise it would overrule everything. vim_setenv((char_u *)"LC_ALL", (char_u *)""); if (what != LC_TIME) { ! // Tell gettext() what to translate to. It apparently doesn't ! // use the currently effective locale. Also do this when ! // FEAT_GETTEXT isn't defined, so that shell commands use this ! // value. if (what == LC_ALL) { vim_setenv((char_u *)"LANG", name); ! // Clear $LANGUAGE because GNU gettext uses it. vim_setenv((char_u *)"LANGUAGE", (char_u *)""); # ifdef MSWIN ! // Apparently MS-Windows printf() may cause a crash when ! // we give it 8-bit text while it's expecting text in the ! // current locale. This call avoids that. setlocale(LC_CTYPE, "C"); # endif } *************** *** 1795,1801 **** } # ifdef FEAT_EVAL ! /* Set v:lang, v:lc_time and v:ctype to the final result. */ set_lang_var(); # endif # ifdef FEAT_TITLE --- 1795,1801 ---- } # ifdef FEAT_EVAL ! // Set v:lang, v:lc_time and v:ctype to the final result. set_lang_var(); # endif # ifdef FEAT_TITLE *************** *** 1805,1811 **** } } ! static char_u **locales = NULL; /* Array of all available locales */ # ifndef MSWIN static int did_init_locales = FALSE; --- 1805,1811 ---- } } ! static char_u **locales = NULL; // Array of all available locales # ifndef MSWIN static int did_init_locales = FALSE; *************** *** 1820,1835 **** garray_T locales_ga; char_u *loc; ! /* Find all available locales by running command "locale -a". If this ! * doesn't work we won't have completion. */ char_u *locale_a = get_cmd_output((char_u *)"locale -a", NULL, SHELL_SILENT, NULL); if (locale_a == NULL) return NULL; ga_init2(&locales_ga, sizeof(char_u *), 20); ! /* Transform locale_a string where each locale is separated by "\n" ! * into an array of locale strings. */ loc = (char_u *)strtok((char *)locale_a, "\n"); while (loc != NULL) --- 1820,1835 ---- garray_T locales_ga; char_u *loc; ! // Find all available locales by running command "locale -a". If this ! // doesn't work we won't have completion. char_u *locale_a = get_cmd_output((char_u *)"locale -a", NULL, SHELL_SILENT, NULL); if (locale_a == NULL) return NULL; ga_init2(&locales_ga, sizeof(char_u *), 20); ! // Transform locale_a string where each locale is separated by "\n" ! // into an array of locale strings. loc = (char_u *)strtok((char *)locale_a, "\n"); while (loc != NULL) *** ../vim-8.1.2378/src/ex_docmd.c 2019-11-30 22:47:42.647331219 +0100 --- src/ex_docmd.c 2019-12-01 21:28:09.321119369 +0100 *************** *** 23,29 **** static char_u *do_one_cmd(char_u **, int, struct condstack *, char_u *(*fgetline)(int, void *, int, int), void *cookie); #else static char_u *do_one_cmd(char_u **, int, char_u *(*fgetline)(int, void *, int, int), void *cookie); ! static int if_level = 0; /* depth in :if */ #endif static void free_cmdmod(void); static void append_command(char_u *cmd); --- 23,29 ---- static char_u *do_one_cmd(char_u **, int, struct condstack *, char_u *(*fgetline)(int, void *, int, int), void *cookie); #else static char_u *do_one_cmd(char_u **, int, char_u *(*fgetline)(int, void *, int, int), void *cookie); ! static int if_level = 0; // depth in :if #endif static void free_cmdmod(void); static void append_command(char_u *cmd); *************** *** 383,393 **** #ifdef FEAT_EVAL ! /* Struct for storing a line inside a while/for loop */ typedef struct { ! char_u *line; /* command line */ ! linenr_T lnum; /* sourcing_lnum of the line */ } wcmd_T; /* --- 383,393 ---- #ifdef FEAT_EVAL ! // Struct for storing a line inside a while/for loop typedef struct { ! char_u *line; // command line ! linenr_T lnum; // sourcing_lnum of the line } wcmd_T; /* *************** *** 397,406 **** */ struct loop_cookie { ! garray_T *lines_gap; /* growarray with line info */ ! int current_line; /* last read line from growarray */ ! int repeating; /* TRUE when looping a second time */ ! /* When "repeating" is FALSE use "getline" and "cookie" to get lines */ char_u *(*getline)(int, void *, int, int); void *cookie; }; --- 397,406 ---- */ struct loop_cookie { ! garray_T *lines_gap; // growarray with line info ! int current_line; // last read line from growarray ! int repeating; // TRUE when looping a second time ! // When "repeating" is FALSE use "getline" and "cookie" to get lines char_u *(*getline)(int, void *, int, int); void *cookie; }; *************** *** 409,415 **** static int store_loop_line(garray_T *gap, char_u *line); static void free_cmdlines(garray_T *gap); ! /* Struct to save a few things while debugging. Used in do_cmdline() only. */ struct dbg_stuff { int trylevel; --- 409,415 ---- static int store_loop_line(garray_T *gap, char_u *line); static void free_cmdlines(garray_T *gap); ! // Struct to save a few things while debugging. Used in do_cmdline() only. struct dbg_stuff { int trylevel; *************** *** 434,440 **** dsp->vv_exception = v_exception(NULL); dsp->vv_throwpoint = v_throwpoint(NULL); ! /* Necessary for debugging an inactive ":catch", ":finally", ":endtry" */ dsp->did_emsg = did_emsg; did_emsg = FALSE; dsp->got_int = got_int; got_int = FALSE; dsp->did_throw = did_throw; did_throw = FALSE; --- 434,440 ---- dsp->vv_exception = v_exception(NULL); dsp->vv_throwpoint = v_throwpoint(NULL); ! // Necessary for debugging an inactive ":catch", ":finally", ":endtry" dsp->did_emsg = did_emsg; did_emsg = FALSE; dsp->got_int = got_int; got_int = FALSE; dsp->did_throw = did_throw; did_throw = FALSE; *************** *** 467,473 **** */ void do_exmode( ! int improved) /* TRUE for "improved Ex" mode */ { int save_msg_scroll; int prev_msg_row; --- 467,473 ---- */ void do_exmode( ! int improved) // TRUE for "improved Ex" mode { int save_msg_scroll; int prev_msg_row; *************** *** 480,502 **** exmode_active = EXMODE_NORMAL; State = NORMAL; ! /* When using ":global /pat/ visual" and then "Q" we return to continue ! * the :global command. */ if (global_busy) return; save_msg_scroll = msg_scroll; ! ++RedrawingDisabled; /* don't redisplay the window */ ! ++no_wait_return; /* don't wait for return */ #ifdef FEAT_GUI ! /* Ignore scrollbar and mouse events in Ex mode */ ++hold_gui_events; #endif msg(_("Entering Ex mode. Type \"visual\" to go to Normal mode.")); while (exmode_active) { ! /* Check for a ":normal" command and no more characters left. */ if (ex_normal_busy > 0 && typebuf.tb_len == 0) { exmode_active = FALSE; --- 480,502 ---- exmode_active = EXMODE_NORMAL; State = NORMAL; ! // When using ":global /pat/ visual" and then "Q" we return to continue ! // the :global command. if (global_busy) return; save_msg_scroll = msg_scroll; ! ++RedrawingDisabled; // don't redisplay the window ! ++no_wait_return; // don't wait for return #ifdef FEAT_GUI ! // Ignore scrollbar and mouse events in Ex mode ++hold_gui_events; #endif msg(_("Entering Ex mode. Type \"visual\" to go to Normal mode.")); while (exmode_active) { ! // Check for a ":normal" command and no more characters left. if (ex_normal_busy > 0 && typebuf.tb_len == 0) { exmode_active = FALSE; *************** *** 527,534 **** { if (ex_pressedreturn) { ! /* go up one line, to overwrite the ":" line, so the ! * output doesn't contain empty lines. */ msg_row = prev_msg_row; if (prev_msg_row == Rows - 1) msg_row--; --- 527,534 ---- { if (ex_pressedreturn) { ! // go up one line, to overwrite the ":" line, so the ! // output doesn't contain empty lines. msg_row = prev_msg_row; if (prev_msg_row == Rows - 1) msg_row--; *************** *** 538,544 **** msg_clr_eos(); } } ! else if (ex_pressedreturn && !ex_no_reprint) /* must be at EOF */ { if (curbuf->b_ml.ml_flags & ML_EMPTY) emsg(_(e_emptybuf)); --- 538,544 ---- msg_clr_eos(); } } ! else if (ex_pressedreturn && !ex_no_reprint) // must be at EOF { if (curbuf->b_ml.ml_flags & ML_EMPTY) emsg(_(e_emptybuf)); *************** *** 611,640 **** do_cmdline( char_u *cmdline, char_u *(*fgetline)(int, void *, int, int), ! void *cookie, /* argument for fgetline() */ int flags) { ! char_u *next_cmdline; /* next cmd to execute */ ! char_u *cmdline_copy = NULL; /* copy of cmd line */ ! int used_getline = FALSE; /* used "fgetline" to obtain command */ ! static int recursive = 0; /* recursive depth */ int msg_didout_before_start = 0; ! int count = 0; /* line number count */ ! int did_inc = FALSE; /* incremented RedrawingDisabled */ int retval = OK; #ifdef FEAT_EVAL ! struct condstack cstack; /* conditional stack */ ! garray_T lines_ga; /* keep lines for ":while"/":for" */ ! int current_line = 0; /* active line in lines_ga */ ! char_u *fname = NULL; /* function or script name */ ! linenr_T *breakpoint = NULL; /* ptr to breakpoint field in cookie */ ! int *dbg_tick = NULL; /* ptr to dbg_tick field in cookie */ ! struct dbg_stuff debug_saved; /* saved things for debug mode */ int initial_trylevel; struct msglist **saved_msg_list = NULL; struct msglist *private_msg_list; ! /* "fgetline" and "cookie" passed to do_one_cmd() */ char_u *(*cmd_getline)(int, void *, int, int); void *cmd_cookie; struct loop_cookie cmd_loop_cookie; --- 611,640 ---- do_cmdline( char_u *cmdline, char_u *(*fgetline)(int, void *, int, int), ! void *cookie, // argument for fgetline() int flags) { ! char_u *next_cmdline; // next cmd to execute ! char_u *cmdline_copy = NULL; // copy of cmd line ! int used_getline = FALSE; // used "fgetline" to obtain command ! static int recursive = 0; // recursive depth int msg_didout_before_start = 0; ! int count = 0; // line number count ! int did_inc = FALSE; // incremented RedrawingDisabled int retval = OK; #ifdef FEAT_EVAL ! struct condstack cstack; // conditional stack ! garray_T lines_ga; // keep lines for ":while"/":for" ! int current_line = 0; // active line in lines_ga ! char_u *fname = NULL; // function or script name ! linenr_T *breakpoint = NULL; // ptr to breakpoint field in cookie ! int *dbg_tick = NULL; // ptr to dbg_tick field in cookie ! struct dbg_stuff debug_saved; // saved things for debug mode int initial_trylevel; struct msglist **saved_msg_list = NULL; struct msglist *private_msg_list; ! // "fgetline" and "cookie" passed to do_one_cmd() char_u *(*cmd_getline)(int, void *, int, int); void *cmd_cookie; struct loop_cookie cmd_loop_cookie; *************** *** 644,666 **** # define cmd_getline fgetline # define cmd_cookie cookie #endif ! static int call_depth = 0; /* recursiveness */ #ifdef FEAT_EVAL ! /* For every pair of do_cmdline()/do_one_cmd() calls, use an extra memory ! * location for storing error messages to be converted to an exception. ! * This ensures that the do_errthrow() call in do_one_cmd() does not ! * combine the messages stored by an earlier invocation of do_one_cmd() ! * with the command name of the later one. This would happen when ! * BufWritePost autocommands are executed after a write error. */ saved_msg_list = msg_list; msg_list = &private_msg_list; private_msg_list = NULL; #endif ! /* It's possible to create an endless loop with ":execute", catch that ! * here. The value of 200 allows nested function calls, ":source", etc. ! * Allow 200 or 'maxfuncdepth', whatever is larger. */ if (call_depth >= 200 #ifdef FEAT_EVAL && call_depth >= p_mfd --- 644,666 ---- # define cmd_getline fgetline # define cmd_cookie cookie #endif ! static int call_depth = 0; // recursiveness #ifdef FEAT_EVAL ! // For every pair of do_cmdline()/do_one_cmd() calls, use an extra memory ! // location for storing error messages to be converted to an exception. ! // This ensures that the do_errthrow() call in do_one_cmd() does not ! // combine the messages stored by an earlier invocation of do_one_cmd() ! // with the command name of the later one. This would happen when ! // BufWritePost autocommands are executed after a write error. saved_msg_list = msg_list; msg_list = &private_msg_list; private_msg_list = NULL; #endif ! // It's possible to create an endless loop with ":execute", catch that ! // here. The value of 200 allows nested function calls, ":source", etc. ! // Allow 200 or 'maxfuncdepth', whatever is larger. if (call_depth >= 200 #ifdef FEAT_EVAL && call_depth >= p_mfd *************** *** 669,676 **** { emsg(_("E169: Command too recursive")); #ifdef FEAT_EVAL ! /* When converting to an exception, we do not include the command name ! * since this is not an error of the specific command. */ do_errthrow((struct condstack *)NULL, (char_u *)NULL); msg_list = saved_msg_list; #endif --- 669,676 ---- { emsg(_("E169: Command too recursive")); #ifdef FEAT_EVAL ! // When converting to an exception, we do not include the command name ! // since this is not an error of the specific command. do_errthrow((struct condstack *)NULL, (char_u *)NULL); msg_list = saved_msg_list; #endif *************** *** 688,700 **** real_cookie = getline_cookie(fgetline, cookie); ! /* Inside a function use a higher nesting level. */ getline_is_func = getline_equal(fgetline, cookie, get_func_line); if (getline_is_func && ex_nesting_level == func_level(real_cookie)) ++ex_nesting_level; ! /* Get the function or script name and the address where the next breakpoint ! * line and the debug tick for a function or script are stored. */ if (getline_is_func) { fname = func_name(real_cookie); --- 688,700 ---- real_cookie = getline_cookie(fgetline, cookie); ! // Inside a function use a higher nesting level. getline_is_func = getline_equal(fgetline, cookie, get_func_line); if (getline_is_func && ex_nesting_level == func_level(real_cookie)) ++ex_nesting_level; ! // Get the function or script name and the address where the next breakpoint ! // line and the debug tick for a function or script are stored. if (getline_is_func) { fname = func_name(real_cookie); *************** *** 762,768 **** getline_is_func = getline_equal(fgetline, cookie, get_func_line); #endif ! /* stop skipping cmds for an error msg after all endif/while/for */ if (next_cmdline == NULL #ifdef FEAT_EVAL && !force_abort --- 762,768 ---- getline_is_func = getline_equal(fgetline, cookie, get_func_line); #endif ! // stop skipping cmds for an error msg after all endif/while/for if (next_cmdline == NULL #ifdef FEAT_EVAL && !force_abort *************** *** 779,793 **** */ #ifdef FEAT_EVAL ! /* 1. If repeating, get a previous line from lines_ga. */ if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) { ! /* Each '|' separated command is stored separately in lines_ga, to ! * be able to jump to it. Don't use next_cmdline now. */ VIM_CLEAR(cmdline_copy); ! /* Check if a function has returned or, unless it has an unclosed ! * try conditional, aborted. */ if (getline_is_func) { # ifdef FEAT_PROFILE --- 779,793 ---- */ #ifdef FEAT_EVAL ! // 1. If repeating, get a previous line from lines_ga. if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len) { ! // Each '|' separated command is stored separately in lines_ga, to ! // be able to jump to it. Don't use next_cmdline now. VIM_CLEAR(cmdline_copy); ! // Check if a function has returned or, unless it has an unclosed ! // try conditional, aborted. if (getline_is_func) { # ifdef FEAT_PROFILE *************** *** 806,819 **** script_line_end(); #endif ! /* Check if a sourced file hit a ":finish" command. */ if (source_finished(fgetline, cookie)) { retval = FAIL; break; } ! /* If breakpoints have been added/deleted need to check for it. */ if (breakpoint != NULL && dbg_tick != NULL && *dbg_tick != debug_tick) { --- 806,819 ---- script_line_end(); #endif ! // Check if a sourced file hit a ":finish" command. if (source_finished(fgetline, cookie)) { retval = FAIL; break; } ! // If breakpoints have been added/deleted need to check for it. if (breakpoint != NULL && dbg_tick != NULL && *dbg_tick != debug_tick) { *************** *** 826,837 **** next_cmdline = ((wcmd_T *)(lines_ga.ga_data))[current_line].line; sourcing_lnum = ((wcmd_T *)(lines_ga.ga_data))[current_line].lnum; ! /* Did we encounter a breakpoint? */ if (breakpoint != NULL && *breakpoint != 0 && *breakpoint <= sourcing_lnum) { dbg_breakpoint(fname, sourcing_lnum); ! /* Find next breakpoint. */ *breakpoint = dbg_find_breakpoint( getline_equal(fgetline, cookie, getsourceline), fname, sourcing_lnum); --- 826,837 ---- next_cmdline = ((wcmd_T *)(lines_ga.ga_data))[current_line].line; sourcing_lnum = ((wcmd_T *)(lines_ga.ga_data))[current_line].lnum; ! // Did we encounter a breakpoint? if (breakpoint != NULL && *breakpoint != 0 && *breakpoint <= sourcing_lnum) { dbg_breakpoint(fname, sourcing_lnum); ! // Find next breakpoint. *breakpoint = dbg_find_breakpoint( getline_equal(fgetline, cookie, getsourceline), fname, sourcing_lnum); *************** *** 850,860 **** if (cstack.cs_looplevel > 0) { ! /* Inside a while/for loop we need to store the lines and use them ! * again. Pass a different "fgetline" function to do_one_cmd() ! * below, so that it stores lines in or reads them from ! * "lines_ga". Makes it possible to define a function inside a ! * while/for loop. */ cmd_getline = get_loop_line; cmd_cookie = (void *)&cmd_loop_cookie; cmd_loop_cookie.lines_gap = &lines_ga; --- 850,860 ---- if (cstack.cs_looplevel > 0) { ! // Inside a while/for loop we need to store the lines and use them ! // again. Pass a different "fgetline" function to do_one_cmd() ! // below, so that it stores lines in or reads them from ! // "lines_ga". Makes it possible to define a function inside a ! // while/for loop. cmd_getline = get_loop_line; cmd_cookie = (void *)&cmd_loop_cookie; cmd_loop_cookie.lines_gap = &lines_ga; *************** *** 870,876 **** } #endif ! /* 2. If no line given, get an allocated line with fgetline(). */ if (next_cmdline == NULL) { /* --- 870,876 ---- } #endif ! // 2. If no line given, get an allocated line with fgetline(). if (next_cmdline == NULL) { /* *************** *** 887,895 **** #endif , TRUE)) == NULL) { ! /* Don't call wait_return for aborted command line. The NULL ! * returned for the end of a sourced file or executed function ! * doesn't do this. */ if (KeyTyped && !(flags & DOCMD_REPEAT)) need_wait_return = FALSE; retval = FAIL; --- 887,895 ---- #endif , TRUE)) == NULL) { ! // Don't call wait_return for aborted command line. The NULL ! // returned for the end of a sourced file or executed function ! // doesn't do this. if (KeyTyped && !(flags & DOCMD_REPEAT)) need_wait_return = FALSE; retval = FAIL; *************** *** 910,916 **** } } ! /* 3. Make a copy of the command so we can mess with it. */ else if (cmdline_copy == NULL) { next_cmdline = vim_strsave(next_cmdline); --- 910,916 ---- } } ! // 3. Make a copy of the command so we can mess with it. else if (cmdline_copy == NULL) { next_cmdline = vim_strsave(next_cmdline); *************** *** 954,963 **** if (!(flags & DOCMD_NOWAIT) && !recursive) { msg_didout_before_start = msg_didout; ! msg_didany = FALSE; /* no output yet */ msg_start(); ! msg_scroll = TRUE; /* put messages below each other */ ! ++no_wait_return; /* don't wait for return until finished */ ++RedrawingDisabled; did_inc = TRUE; } --- 954,963 ---- if (!(flags & DOCMD_NOWAIT) && !recursive) { msg_didout_before_start = msg_didout; ! msg_didany = FALSE; // no output yet msg_start(); ! msg_scroll = TRUE; // put messages below each other ! ++no_wait_return; // don't wait for return until finished ++RedrawingDisabled; did_inc = TRUE; } *************** *** 981,988 **** #ifdef FEAT_EVAL if (cmd_cookie == (void *)&cmd_loop_cookie) ! /* Use "current_line" from "cmd_loop_cookie", it may have been ! * incremented when defining a function. */ current_line = cmd_loop_cookie.current_line; #endif --- 981,988 ---- #ifdef FEAT_EVAL if (cmd_cookie == (void *)&cmd_loop_cookie) ! // Use "current_line" from "cmd_loop_cookie", it may have been ! // incremented when defining a function. current_line = cmd_loop_cookie.current_line; #endif *************** *** 1004,1018 **** } else { ! /* need to copy the command after the '|' to cmdline_copy, for the ! * next do_one_cmd() */ STRMOVE(cmdline_copy, next_cmdline); next_cmdline = cmdline_copy; } #ifdef FEAT_EVAL ! /* reset did_emsg for a function that is not aborted by an error */ if (did_emsg && !force_abort && getline_equal(fgetline, cookie, get_func_line) && !func_has_abort(real_cookie)) --- 1004,1018 ---- } else { ! // need to copy the command after the '|' to cmdline_copy, for the ! // next do_one_cmd() STRMOVE(cmdline_copy, next_cmdline); next_cmdline = cmdline_copy; } #ifdef FEAT_EVAL ! // reset did_emsg for a function that is not aborted by an error if (did_emsg && !force_abort && getline_equal(fgetline, cookie, get_func_line) && !func_has_abort(real_cookie)) *************** *** 1032,1041 **** { cstack.cs_lflags &= ~(CSL_HAD_CONT | CSL_HAD_ENDLOOP); ! /* Jump back to the matching ":while" or ":for". Be careful ! * not to use a cs_line[] from an entry that isn't a ":while" ! * or ":for": It would make "current_line" invalid and can ! * cause a crash. */ if (!did_emsg && !got_int && !did_throw && cstack.cs_idx >= 0 && (cstack.cs_flags[cstack.cs_idx] --- 1032,1041 ---- { cstack.cs_lflags &= ~(CSL_HAD_CONT | CSL_HAD_ENDLOOP); ! // Jump back to the matching ":while" or ":for". Be careful ! // not to use a cs_line[] from an entry that isn't a ":while" ! // or ":for": It would make "current_line" invalid and can ! // cause a crash. if (!did_emsg && !got_int && !did_throw && cstack.cs_idx >= 0 && (cstack.cs_flags[cstack.cs_idx] *************** *** 1044,1055 **** && (cstack.cs_flags[cstack.cs_idx] & CSF_ACTIVE)) { current_line = cstack.cs_line[cstack.cs_idx]; ! /* remember we jumped there */ cstack.cs_lflags |= CSL_HAD_LOOP; ! line_breakcheck(); /* check if CTRL-C typed */ ! /* Check for the next breakpoint at or after the ":while" ! * or ":for". */ if (breakpoint != NULL) { *breakpoint = dbg_find_breakpoint( --- 1044,1055 ---- && (cstack.cs_flags[cstack.cs_idx] & CSF_ACTIVE)) { current_line = cstack.cs_line[cstack.cs_idx]; ! // remember we jumped there cstack.cs_lflags |= CSL_HAD_LOOP; ! line_breakcheck(); // check if CTRL-C typed ! // Check for the next breakpoint at or after the ":while" ! // or ":for". if (breakpoint != NULL) { *breakpoint = dbg_find_breakpoint( *************** *** 1061,1067 **** } else { ! /* can only get here with ":endwhile" or ":endfor" */ if (cstack.cs_idx >= 0) rewind_conditionals(&cstack, cstack.cs_idx - 1, CSF_WHILE | CSF_FOR, &cstack.cs_looplevel); --- 1061,1067 ---- } else { ! // can only get here with ":endwhile" or ":endfor" if (cstack.cs_idx >= 0) rewind_conditionals(&cstack, cstack.cs_idx - 1, CSF_WHILE | CSF_FOR, &cstack.cs_looplevel); *************** *** 1078,1084 **** } } ! /* Check for the next breakpoint after a watchexpression */ if (breakpoint != NULL && has_watchexpr()) { *breakpoint = dbg_find_breakpoint(FALSE, fname, sourcing_lnum); --- 1078,1084 ---- } } ! // Check for the next breakpoint after a watchexpression if (breakpoint != NULL && has_watchexpr()) { *breakpoint = dbg_find_breakpoint(FALSE, fname, sourcing_lnum); *************** *** 1116,1123 **** cstack.cs_flags[cstack.cs_idx] |= CSF_ACTIVE | CSF_FINALLY; } ! /* Update global "trylevel" for recursive calls to do_cmdline() from ! * within this loop. */ trylevel = initial_trylevel + cstack.cs_trylevel; /* --- 1116,1123 ---- cstack.cs_flags[cstack.cs_idx] |= CSF_ACTIVE | CSF_FINALLY; } ! // Update global "trylevel" for recursive calls to do_cmdline() from ! // within this loop. trylevel = initial_trylevel + cstack.cs_trylevel; /* *************** *** 1130,1138 **** if (trylevel == 0 && !did_emsg && !got_int && !did_throw) force_abort = FALSE; ! /* Convert an interrupt to an exception if appropriate. */ (void)do_intthrow(&cstack); ! #endif /* FEAT_EVAL */ } /* --- 1130,1138 ---- if (trylevel == 0 && !did_emsg && !got_int && !did_throw) force_abort = FALSE; ! // Convert an interrupt to an exception if appropriate. (void)do_intthrow(&cstack); ! #endif // FEAT_EVAL } /* *************** *** 1155,1163 **** ) && !(did_emsg #ifdef FEAT_EVAL ! /* Keep going when inside try/catch, so that the error can be ! * deal with, except when it is a syntax error, it may cause ! * the :endtry to be missed. */ && (cstack.cs_trylevel == 0 || did_emsg_syntax) #endif && used_getline --- 1155,1163 ---- ) && !(did_emsg #ifdef FEAT_EVAL ! // Keep going when inside try/catch, so that the error can be ! // deal with, except when it is a syntax error, it may cause ! // the :endtry to be missed. && (cstack.cs_trylevel == 0 || did_emsg_syntax) #endif && used_getline *************** *** 1209,1215 **** int idx = cleanup_conditionals(&cstack, 0, TRUE); if (idx >= 0) ! --idx; /* remove try block not in its finally clause */ rewind_conditionals(&cstack, idx, CSF_WHILE | CSF_FOR, &cstack.cs_looplevel); } --- 1209,1215 ---- int idx = cleanup_conditionals(&cstack, 0, TRUE); if (idx >= 0) ! --idx; // remove try block not in its finally clause rewind_conditionals(&cstack, idx, CSF_WHILE | CSF_FOR, &cstack.cs_looplevel); } *************** *** 1217,1225 **** trylevel = initial_trylevel; } ! /* If a missing ":endtry", ":endwhile", ":endfor", or ":endif" or a memory ! * lack was reported above and the error message is to be converted to an ! * exception, do this now after rewinding the cstack. */ do_errthrow(&cstack, getline_equal(fgetline, cookie, get_func_line) ? (char_u *)"endfunction" : (char_u *)NULL); --- 1217,1225 ---- trylevel = initial_trylevel; } ! // If a missing ":endtry", ":endwhile", ":endfor", or ":endif" or a memory ! // lack was reported above and the error message is to be converted to an ! // exception, do this now after rewinding the cstack. do_errthrow(&cstack, getline_equal(fgetline, cookie, get_func_line) ? (char_u *)"endfunction" : (char_u *)NULL); *************** *** 1266,1272 **** sourcing_lnum = current_exception->throw_lnum; current_exception->throw_name = NULL; ! discard_current_exception(); /* uses IObuff if 'verbose' */ suppress_errthrow = TRUE; force_abort = TRUE; --- 1266,1272 ---- sourcing_lnum = current_exception->throw_lnum; current_exception->throw_name = NULL; ! discard_current_exception(); // uses IObuff if 'verbose' suppress_errthrow = TRUE; force_abort = TRUE; *************** *** 1323,1329 **** } else { ! /* When leaving a function, reduce nesting level. */ if (getline_equal(fgetline, cookie, get_func_line)) --ex_nesting_level; /* --- 1323,1329 ---- } else { ! // When leaving a function, reduce nesting level. if (getline_equal(fgetline, cookie, get_func_line)) --ex_nesting_level; /* *************** *** 1346,1352 **** restore_dbg_stuff(&debug_saved); msg_list = saved_msg_list; ! #endif /* FEAT_EVAL */ /* * If there was too much output to fit on the command line, ask the user to --- 1346,1352 ---- restore_dbg_stuff(&debug_saved); msg_list = saved_msg_list; ! #endif // FEAT_EVAL /* * If there was too much output to fit on the command line, ask the user to *************** *** 1370,1376 **** ) { need_wait_return = FALSE; ! msg_didany = FALSE; /* don't wait when restarting edit */ } else if (need_wait_return) { --- 1370,1376 ---- ) { need_wait_return = FALSE; ! msg_didany = FALSE; // don't wait when restarting edit } else if (need_wait_return) { *************** *** 1385,1391 **** } #ifdef FEAT_EVAL ! did_endif = FALSE; /* in case do_cmdline used recursively */ #else /* * Reset if_level, in case a sourced script file contains more ":if" than --- 1385,1391 ---- } #ifdef FEAT_EVAL ! did_endif = FALSE; // in case do_cmdline used recursively #else /* * Reset if_level, in case a sourced script file contains more ":if" than *************** *** 1412,1420 **** if (cp->current_line + 1 >= cp->lines_gap->ga_len) { if (cp->repeating) ! return NULL; /* trying to read past ":endwhile"/":endfor" */ ! /* First time inside the ":while"/":for": get line normally. */ if (cp->getline == NULL) line = getcmdline(c, 0L, indent, do_concat); else --- 1412,1420 ---- if (cp->current_line + 1 >= cp->lines_gap->ga_len) { if (cp->repeating) ! return NULL; // trying to read past ":endwhile"/":endfor" ! // First time inside the ":while"/":for": get line normally. if (cp->getline == NULL) line = getcmdline(c, 0L, indent, do_concat); else *************** *** 1467,1482 **** int getline_equal( char_u *(*fgetline)(int, void *, int, int), ! void *cookie UNUSED, /* argument for fgetline() */ char_u *(*func)(int, void *, int, int)) { #ifdef FEAT_EVAL char_u *(*gp)(int, void *, int, int); struct loop_cookie *cp; ! /* When "fgetline" is "get_loop_line()" use the "cookie" to find the ! * function that's originally used to obtain the lines. This may be ! * nested several levels. */ gp = fgetline; cp = (struct loop_cookie *)cookie; while (gp == get_loop_line) --- 1467,1482 ---- int getline_equal( char_u *(*fgetline)(int, void *, int, int), ! void *cookie UNUSED, // argument for fgetline() char_u *(*func)(int, void *, int, int)) { #ifdef FEAT_EVAL char_u *(*gp)(int, void *, int, int); struct loop_cookie *cp; ! // When "fgetline" is "get_loop_line()" use the "cookie" to find the ! // function that's originally used to obtain the lines. This may be ! // nested several levels. gp = fgetline; cp = (struct loop_cookie *)cookie; while (gp == get_loop_line) *************** *** 1497,1511 **** void * getline_cookie( char_u *(*fgetline)(int, void *, int, int) UNUSED, ! void *cookie) /* argument for fgetline() */ { #ifdef FEAT_EVAL char_u *(*gp)(int, void *, int, int); struct loop_cookie *cp; ! /* When "fgetline" is "get_loop_line()" use the "cookie" to find the ! * cookie that's originally used to obtain the lines. This may be nested ! * several levels. */ gp = fgetline; cp = (struct loop_cookie *)cookie; while (gp == get_loop_line) --- 1497,1511 ---- void * getline_cookie( char_u *(*fgetline)(int, void *, int, int) UNUSED, ! void *cookie) // argument for fgetline() { #ifdef FEAT_EVAL char_u *(*gp)(int, void *, int, int); struct loop_cookie *cp; ! // When "fgetline" is "get_loop_line()" use the "cookie" to find the ! // cookie that's originally used to obtain the lines. This may be nested ! // several levels. gp = fgetline; cp = (struct loop_cookie *)cookie; while (gp == get_loop_line) *************** *** 1543,1549 **** break; buf = nextbuf; if (addr_type == ADDR_LOADED_BUFFERS) ! /* skip over unloaded buffers */ while (buf->b_ml.ml_mfp == NULL) { nextbuf = (offset < 0) ? buf->b_prev : buf->b_next; --- 1543,1549 ---- break; buf = nextbuf; if (addr_type == ADDR_LOADED_BUFFERS) ! // skip over unloaded buffers while (buf->b_ml.ml_mfp == NULL) { nextbuf = (offset < 0) ? buf->b_prev : buf->b_next; *************** *** 1552,1558 **** buf = nextbuf; } } ! /* we might have gone too far, last buffer is not loadedd */ if (addr_type == ADDR_LOADED_BUFFERS) while (buf->b_ml.ml_mfp == NULL) { --- 1552,1558 ---- buf = nextbuf; } } ! // we might have gone too far, last buffer is not loadedd if (addr_type == ADDR_LOADED_BUFFERS) while (buf->b_ml.ml_mfp == NULL) { *************** *** 1634,1651 **** struct condstack *cstack, #endif char_u *(*fgetline)(int, void *, int, int), ! void *cookie) /* argument for fgetline() */ { char_u *p; linenr_T lnum; long n; ! char *errormsg = NULL; /* error message */ char_u *after_modifier = NULL; ! exarg_T ea; /* Ex command arguments */ int save_msg_scroll = msg_scroll; cmdmod_T save_cmdmod; int save_reg_executing = reg_executing; ! int ni; /* set when Not Implemented */ char_u *cmd; vim_memset(&ea, 0, sizeof(ea)); --- 1634,1651 ---- struct condstack *cstack, #endif char_u *(*fgetline)(int, void *, int, int), ! void *cookie) // argument for fgetline() { char_u *p; linenr_T lnum; long n; ! char *errormsg = NULL; // error message char_u *after_modifier = NULL; ! exarg_T ea; // Ex command arguments int save_msg_scroll = msg_scroll; cmdmod_T save_cmdmod; int save_reg_executing = reg_executing; ! int ni; // set when Not Implemented char_u *cmd; vim_memset(&ea, 0, sizeof(ea)); *************** *** 1655,1667 **** ++ex_nesting_level; #endif ! /* When the last file has not been edited :q has to be typed twice. */ if (quitmore #ifdef FEAT_EVAL ! /* avoid that a function call in 'statusline' does this */ && !getline_equal(fgetline, cookie, get_func_line) #endif ! /* avoid that an autocommand, e.g. QuitPre, does this */ && !getline_equal(fgetline, cookie, getnextac)) --quitmore; --- 1655,1667 ---- ++ex_nesting_level; #endif ! // When the last file has not been edited :q has to be typed twice. if (quitmore #ifdef FEAT_EVAL ! // avoid that a function call in 'statusline' does this && !getline_equal(fgetline, cookie, get_func_line) #endif ! // avoid that an autocommand, e.g. QuitPre, does this && !getline_equal(fgetline, cookie, getnextac)) --quitmore; *************** *** 1671,1677 **** */ save_cmdmod = cmdmod; ! /* "#!anything" is handled like a comment. */ if ((*cmdlinep)[0] == '#' && (*cmdlinep)[1] == '!') goto doend; --- 1671,1677 ---- */ save_cmdmod = cmdmod; ! // "#!anything" is handled like a comment. if ((*cmdlinep)[0] == '#' && (*cmdlinep)[1] == '!') goto doend; *************** *** 1748,1755 **** } # endif ! /* May go to debug mode. If this happens and the ">quit" debug command is ! * used, throw an interrupt exception and skip the next command. */ dbg_check_breakpoint(&ea); if (!ea.skip && got_int) { --- 1748,1755 ---- } # endif ! // May go to debug mode. If this happens and the ">quit" debug command is ! // used, throw an interrupt exception and skip the next command. dbg_check_breakpoint(&ea); if (!ea.skip && got_int) { *************** *** 1821,1827 **** * ":3|..." prints line 3 * ":|" prints current line */ ! if (ea.skip) /* skip this if inside :if */ goto doend; if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) { --- 1821,1827 ---- * ":3|..." prints line 3 * ":|" prints current line */ ! if (ea.skip) // skip this if inside :if goto doend; if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) { *************** *** 1837,1844 **** { if (ea.line2 > curbuf->b_ml.ml_line_count) { ! /* With '-' in 'cpoptions' a line number past the file is an ! * error, otherwise put it at the end of the file. */ if (vim_strchr(p_cpo, CPO_MINUS) != NULL) ea.line2 = -1; else --- 1837,1844 ---- { if (ea.line2 > curbuf->b_ml.ml_line_count) { ! // With '-' in 'cpoptions' a line number past the file is an ! // error, otherwise put it at the end of the file. if (vim_strchr(p_cpo, CPO_MINUS) != NULL) ea.line2 = -1; else *************** *** 1859,1866 **** goto doend; } ! /* If this looks like an undefined user command and there are CmdUndefined ! * autocommands defined, trigger the matching autocommands. */ if (p != NULL && ea.cmdidx == CMD_SIZE && !ea.skip && ASCII_ISUPPER(*ea.cmd) && has_cmdundefined()) --- 1859,1866 ---- goto doend; } ! // If this looks like an undefined user command and there are CmdUndefined ! // autocommands defined, trigger the matching autocommands. if (p != NULL && ea.cmdidx == CMD_SIZE && !ea.skip && ASCII_ISUPPER(*ea.cmd) && has_cmdundefined()) *************** *** 1873,1880 **** p = vim_strnsave(ea.cmd, (int)(p - ea.cmd)); ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL); vim_free(p); ! /* If the autocommands did something and didn't cause an error, try ! * finding the command again. */ p = (ret #ifdef FEAT_EVAL && !aborting() --- 1873,1880 ---- p = vim_strnsave(ea.cmd, (int)(p - ea.cmd)); ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL); vim_free(p); ! // If the autocommands did something and didn't cause an error, try ! // finding the command again. p = (ret #ifdef FEAT_EVAL && !aborting() *************** *** 1903,1910 **** STRCPY(IObuff, _("E492: Not an editor command")); if (!sourcing) { ! /* If the modifier was parsed OK the error must be in the ! * following command */ if (after_modifier != NULL) append_command(after_modifier); else --- 1903,1910 ---- STRCPY(IObuff, _("E492: Not an editor command")); if (!sourcing) { ! // If the modifier was parsed OK the error must be in the ! // following command if (after_modifier != NULL) append_command(after_modifier); else *************** *** 1939,1945 **** #endif ! /* forced commands */ if (*p == '!' && ea.cmdidx != CMD_substitute && ea.cmdidx != CMD_smagic && ea.cmdidx != CMD_snomagic) { --- 1939,1945 ---- #endif ! // forced commands if (*p == '!' && ea.cmdidx != CMD_substitute && ea.cmdidx != CMD_smagic && ea.cmdidx != CMD_snomagic) { *************** *** 1972,1978 **** } if (!curbuf->b_p_ma && (ea.argt & EX_MODIFY)) { ! /* Command not allowed in non-'modifiable' buffer */ errormsg = _(e_modifiable); goto doend; } --- 1972,1978 ---- } if (!curbuf->b_p_ma && (ea.argt & EX_MODIFY)) { ! // Command not allowed in non-'modifiable' buffer errormsg = _(e_modifiable); goto doend; } *************** *** 1980,1994 **** if (text_locked() && !(ea.argt & EX_CMDWIN) && !IS_USER_CMDIDX(ea.cmdidx)) { ! /* Command not allowed when editing the command line. */ errormsg = _(get_text_locked_msg()); goto doend; } ! /* Disallow editing another buffer when "curbuf_lock" is set. ! * Do allow ":checktime" (it is postponed). ! * Do allow ":edit" (check for an argument later). ! * Do allow ":file" with no arguments (check for an argument later). */ if (!(ea.argt & EX_CMDWIN) && ea.cmdidx != CMD_checktime && ea.cmdidx != CMD_edit --- 1980,1994 ---- if (text_locked() && !(ea.argt & EX_CMDWIN) && !IS_USER_CMDIDX(ea.cmdidx)) { ! // Command not allowed when editing the command line. errormsg = _(get_text_locked_msg()); goto doend; } ! // Disallow editing another buffer when "curbuf_lock" is set. ! // Do allow ":checktime" (it is postponed). ! // Do allow ":edit" (check for an argument later). ! // Do allow ":file" with no arguments (check for an argument later). if (!(ea.argt & EX_CMDWIN) && ea.cmdidx != CMD_checktime && ea.cmdidx != CMD_edit *************** *** 1999,2005 **** if (!ni && !(ea.argt & EX_RANGE) && ea.addr_count > 0) { ! /* no range allowed */ errormsg = _(e_norange); goto doend; } --- 1999,2005 ---- if (!ni && !(ea.argt & EX_RANGE) && ea.addr_count > 0) { ! // no range allowed errormsg = _(e_norange); goto doend; } *************** *** 2053,2060 **** if (((ea.argt & EX_WHOLEFOLD) || ea.addr_count >= 2) && !global_busy && ea.addr_type == ADDR_LINES) { ! /* Put the first line at the start of a closed fold, put the last line ! * at the end of a closed fold. */ (void)hasFolding(ea.line1, &ea.line1, NULL); (void)hasFolding(ea.line2, NULL, &ea.line2); } --- 2053,2060 ---- if (((ea.argt & EX_WHOLEFOLD) || ea.addr_count >= 2) && !global_busy && ea.addr_type == ADDR_LINES) { ! // Put the first line at the start of a closed fold, put the last line ! // at the end of a closed fold. (void)hasFolding(ea.line1, &ea.line1, NULL); (void)hasFolding(ea.line2, NULL, &ea.line2); } *************** *** 2097,2105 **** if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update) { ! if (*ea.arg == '>') /* append */ { ! if (*++ea.arg != '>') /* typed wrong */ { errormsg = _("E494: Use w or w>>"); goto doend; --- 2097,2105 ---- if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update) { ! if (*ea.arg == '>') // append { ! if (*++ea.arg != '>') // typed wrong { errormsg = _("E494: Use w or w>>"); goto doend; *************** *** 2107,2113 **** ea.arg = skipwhite(ea.arg + 1); ea.append = TRUE; } ! else if (*ea.arg == '!' && ea.cmdidx == CMD_write) /* :w !filter */ { ++ea.arg; ea.usefilter = TRUE; --- 2107,2113 ---- ea.arg = skipwhite(ea.arg + 1); ea.append = TRUE; } ! else if (*ea.arg == '!' && ea.cmdidx == CMD_write) // :w !filter { ++ea.arg; ea.usefilter = TRUE; *************** *** 2118,2127 **** { if (ea.forceit) { ! ea.usefilter = TRUE; /* :r! filter if ea.forceit */ ea.forceit = FALSE; } ! else if (*ea.arg == '!') /* :r !filter */ { ++ea.arg; ea.usefilter = TRUE; --- 2118,2127 ---- { if (ea.forceit) { ! ea.usefilter = TRUE; // :r! filter if ea.forceit ea.forceit = FALSE; } ! else if (*ea.arg == '!') // :r !filter { ++ea.arg; ea.usefilter = TRUE; *************** *** 2131,2137 **** if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift) { ea.amount = 1; ! while (*ea.arg == *ea.cmd) /* count number of '>' or '<' */ { ++ea.arg; ++ea.amount; --- 2131,2137 ---- if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift) { ea.amount = 1; ! while (*ea.arg == *ea.cmd) // count number of '>' or '<' { ++ea.arg; ++ea.amount; *************** *** 2166,2177 **** { for (p = ea.arg; *p; ++p) { ! /* Remove one backslash before a newline, so that it's possible to ! * pass a newline to the shell and also a newline that is preceded ! * with a backslash. This makes it impossible to end a shell ! * command in a backslash, but that doesn't appear useful. ! * Halving the number of backslashes is incompatible with previous ! * versions. */ if (*p == '\\' && p[1] == '\n') STRMOVE(p, p + 1); else if (*p == '\n') --- 2166,2177 ---- { for (p = ea.arg; *p; ++p) { ! // Remove one backslash before a newline, so that it's possible to ! // pass a newline to the shell and also a newline that is preceded ! // with a backslash. This makes it impossible to end a shell ! // command in a backslash, but that doesn't appear useful. ! // Halving the number of backslashes is incompatible with previous ! // versions. if (*p == '\\' && p[1] == '\n') STRMOVE(p, p + 1); else if (*p == '\n') *************** *** 2238,2252 **** } } ! /* accept numbered register only when no count allowed (:put) */ if ( (ea.argt & EX_REGSTR) && *ea.arg != NUL ! /* Do not allow register = for user commands */ && (!IS_USER_CMDIDX(ea.cmdidx) || *ea.arg != '=') && !((ea.argt & EX_COUNT) && VIM_ISDIGIT(*ea.arg))) { #ifndef FEAT_CLIPBOARD ! /* check these explicitly for a more specific error message */ if (*ea.arg == '*' || *ea.arg == '+') { errormsg = _(e_invalidreg); --- 2238,2252 ---- } } ! // accept numbered register only when no count allowed (:put) if ( (ea.argt & EX_REGSTR) && *ea.arg != NUL ! // Do not allow register = for user commands && (!IS_USER_CMDIDX(ea.cmdidx) || *ea.arg != '=') && !((ea.argt & EX_COUNT) && VIM_ISDIGIT(*ea.arg))) { #ifndef FEAT_CLIPBOARD ! // check these explicitly for a more specific error message if (*ea.arg == '*' || *ea.arg == '+') { errormsg = _(e_invalidreg); *************** *** 2258,2264 **** { ea.regname = *ea.arg++; #ifdef FEAT_EVAL ! /* for '=' register: accept the rest of the line as an expression */ if (ea.arg[-1] == '=' && ea.arg[0] != NUL) { set_expr_line(vim_strsave(ea.arg)); --- 2258,2264 ---- { ea.regname = *ea.arg++; #ifdef FEAT_EVAL ! // for '=' register: accept the rest of the line as an expression if (ea.arg[-1] == '=' && ea.arg[0] != NUL) { set_expr_line(vim_strsave(ea.arg)); *************** *** 2333,2339 **** { switch (ea.cmdidx) { ! /* commands that need evaluation */ case CMD_while: case CMD_endwhile: case CMD_for: --- 2333,2339 ---- { switch (ea.cmdidx) { ! // commands that need evaluation case CMD_while: case CMD_endwhile: case CMD_for: *************** *** 2349,2357 **** case CMD_function: break; ! /* Commands that handle '|' themselves. Check: A command should ! * either have the EX_TRLBAR flag, appear in this list or appear in ! * the list at ":help :bar". */ case CMD_aboveleft: case CMD_and: case CMD_belowright: --- 2349,2357 ---- case CMD_function: break; ! // Commands that handle '|' themselves. Check: A command should ! // either have the EX_TRLBAR flag, appear in this list or appear in ! // the list at ":help :bar". case CMD_aboveleft: case CMD_and: case CMD_belowright: *************** *** 2449,2462 **** } ea.line2 = buflist_findpat(ea.arg, p, (ea.argt & EX_BUFUNL) != 0, FALSE, FALSE); ! if (ea.line2 < 0) /* failed */ goto doend; ea.addr_count = 1; ea.arg = skipwhite(p); } ! /* The :try command saves the emsg_silent flag, reset it here when ! * ":silent! try" was used, it should only apply to :try itself. */ if (ea.cmdidx == CMD_try && ea.did_esilent > 0) { emsg_silent -= ea.did_esilent; --- 2449,2462 ---- } ea.line2 = buflist_findpat(ea.arg, p, (ea.argt & EX_BUFUNL) != 0, FALSE, FALSE); ! if (ea.line2 < 0) // failed goto doend; ea.addr_count = 1; ea.arg = skipwhite(p); } ! // The :try command saves the emsg_silent flag, reset it here when ! // ":silent! try" was used, it should only apply to :try itself. if (ea.cmdidx == CMD_try && ea.did_esilent > 0) { emsg_silent -= ea.did_esilent; *************** *** 2509,2515 **** #endif doend: ! if (curwin->w_cursor.lnum == 0) /* can happen with zero line number */ { curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; --- 2509,2515 ---- #endif doend: ! if (curwin->w_cursor.lnum == 0) // can happen with zero line number { curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; *************** *** 2543,2561 **** if (ea.save_msg_silent != -1) { ! /* messages could be enabled for a serious error, need to check if the ! * counters don't become negative */ if (!did_emsg || msg_silent > ea.save_msg_silent) msg_silent = ea.save_msg_silent; emsg_silent -= ea.did_esilent; if (emsg_silent < 0) emsg_silent = 0; ! /* Restore msg_scroll, it's set by file I/O commands, even when no ! * message is actually displayed. */ msg_scroll = save_msg_scroll; ! /* "silent reg" or "silent echo x" inside "redir" leaves msg_col ! * somewhere in the line. Put it back in the first column. */ if (redirecting()) msg_col = 0; } --- 2543,2561 ---- if (ea.save_msg_silent != -1) { ! // messages could be enabled for a serious error, need to check if the ! // counters don't become negative if (!did_emsg || msg_silent > ea.save_msg_silent) msg_silent = ea.save_msg_silent; emsg_silent -= ea.did_esilent; if (emsg_silent < 0) emsg_silent = 0; ! // Restore msg_scroll, it's set by file I/O commands, even when no ! // message is actually displayed. msg_scroll = save_msg_scroll; ! // "silent reg" or "silent echo x" inside "redir" leaves msg_col ! // somewhere in the line. Put it back in the first column. if (redirecting()) msg_col = 0; } *************** *** 2565,2571 **** --sandbox; #endif ! if (ea.nextcmd && *ea.nextcmd == NUL) /* not really a next command */ ea.nextcmd = NULL; #ifdef FEAT_EVAL --- 2565,2571 ---- --sandbox; #endif ! if (ea.nextcmd && *ea.nextcmd == NUL) // not really a next command ea.nextcmd = NULL; #ifdef FEAT_EVAL *************** *** 2607,2613 **** while (*eap->cmd == ' ' || *eap->cmd == '\t' || *eap->cmd == ':') ++eap->cmd; ! /* in ex mode, an empty line works like :+ */ if (*eap->cmd == NUL && exmode_active && (getline_equal(eap->getline, eap->cookie, getexmodeline) || getline_equal(eap->getline, eap->cookie, getexline)) --- 2607,2613 ---- while (*eap->cmd == ' ' || *eap->cmd == '\t' || *eap->cmd == ':') ++eap->cmd; ! // in ex mode, an empty line works like :+ if (*eap->cmd == NUL && exmode_active && (getline_equal(eap->getline, eap->cookie, getexmodeline) || getline_equal(eap->getline, eap->cookie, getexline)) *************** *** 2618,2624 **** ex_pressedreturn = TRUE; } ! /* ignore comment and empty lines */ if (*eap->cmd == '"') return FAIL; if (*eap->cmd == NUL) --- 2618,2624 ---- ex_pressedreturn = TRUE; } ! // ignore comment and empty lines if (*eap->cmd == '"') return FAIL; if (*eap->cmd == NUL) *************** *** 2631,2637 **** p = skip_range(eap->cmd, NULL); switch (*p) { ! /* When adding an entry, also modify cmd_exists(). */ case 'a': if (!checkforcmd(&eap->cmd, "aboveleft", 3)) break; cmdmod.split |= WSP_ABOVE; --- 2631,2637 ---- p = skip_range(eap->cmd, NULL); switch (*p) { ! // When adding an entry, also modify cmd_exists(). case 'a': if (!checkforcmd(&eap->cmd, "aboveleft", 3)) break; cmdmod.split |= WSP_ABOVE; *************** *** 2681,2687 **** cmdmod.keepjumps = TRUE; continue; ! case 'f': /* only accept ":filter {pat} cmd" */ { char_u *reg_pat; --- 2681,2687 ---- cmdmod.keepjumps = TRUE; continue; ! case 'f': // only accept ":filter {pat} cmd" { char_u *reg_pat; *************** *** 2713,2719 **** continue; } ! /* ":hide" and ":hide | cmd" are not modifiers */ case 'h': if (p != eap->cmd || !checkforcmd(&p, "hide", 3) || *p == NUL || ends_excmd(*p)) break; --- 2713,2719 ---- continue; } ! // ":hide" and ":hide | cmd" are not modifiers case 'h': if (p != eap->cmd || !checkforcmd(&p, "hide", 3) || *p == NUL || ends_excmd(*p)) break; *************** *** 2736,2743 **** { if (cmdmod.save_ei == NULL && !skip_only) { ! /* Set 'eventignore' to "all". Restore the ! * existing option value later. */ cmdmod.save_ei = vim_strsave(p_ei); set_string_option_direct((char_u *)"ei", -1, (char_u *)"all", OPT_FREE, SID_NONE); --- 2736,2743 ---- { if (cmdmod.save_ei == NULL && !skip_only) { ! // Set 'eventignore' to "all". Restore the ! // existing option value later. cmdmod.save_ei = vim_strsave(p_ei); set_string_option_direct((char_u *)"ei", -1, (char_u *)"all", OPT_FREE, SID_NONE); *************** *** 2776,2782 **** } if (*eap->cmd == '!' && !VIM_ISWHITE(eap->cmd[-1])) { ! /* ":silent!", but not "silent !cmd" */ eap->cmd = skipwhite(eap->cmd + 1); if (!skip_only) { --- 2776,2782 ---- } if (*eap->cmd == '!' && !VIM_ISWHITE(eap->cmd[-1])) { ! // ":silent!", but not "silent !cmd" eap->cmd = skipwhite(eap->cmd + 1); if (!skip_only) { *************** *** 2856,2862 **** { if (cmdmod.save_ei != NULL) { ! /* Restore 'eventignore' to the value before ":noautocmd". */ set_string_option_direct((char_u *)"ei", -1, cmdmod.save_ei, OPT_FREE, SID_NONE); free_string_option(cmdmod.save_ei); --- 2856,2862 ---- { if (cmdmod.save_ei != NULL) { ! // Restore 'eventignore' to the value before ":noautocmd". set_string_option_direct((char_u *)"ei", -1, cmdmod.save_ei, OPT_FREE, SID_NONE); free_string_option(cmdmod.save_ei); *************** *** 3062,3070 **** */ int checkforcmd( ! char_u **pp, /* start of command */ ! char *cmd, /* name of command */ ! int len) /* required length */ { int i; --- 3062,3070 ---- */ int checkforcmd( ! char_u **pp, // start of command ! char *cmd, // name of command ! int len) // required length { int i; *************** *** 3150,3168 **** { while (ASCII_ISALPHA(*p)) ++p; ! /* for python 3.x support ":py3", ":python3", ":py3file", etc. */ if (eap->cmd[0] == 'p' && eap->cmd[1] == 'y') while (ASCII_ISALNUM(*p)) ++p; ! /* check for non-alpha command */ if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL) ++p; len = (int)(p - eap->cmd); if (*eap->cmd == 'd' && (p[-1] == 'l' || p[-1] == 'p')) { ! /* Check for ":dl", ":dell", etc. to ":deletel": that's ! * :delete with the 'l' flag. Same for 'p'. */ for (i = 0; i < len; ++i) if (eap->cmd[i] != ((char_u *)"delete")[i]) break; --- 3150,3168 ---- { while (ASCII_ISALPHA(*p)) ++p; ! // for python 3.x support ":py3", ":python3", ":py3file", etc. if (eap->cmd[0] == 'p' && eap->cmd[1] == 'y') while (ASCII_ISALNUM(*p)) ++p; ! // check for non-alpha command if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL) ++p; len = (int)(p - eap->cmd); if (*eap->cmd == 'd' && (p[-1] == 'l' || p[-1] == 'p')) { ! // Check for ":dl", ":dell", etc. to ":deletel": that's ! // :delete with the 'l' flag. Same for 'p'. for (i = 0; i < len; ++i) if (eap->cmd[i] != ((char_u *)"delete")[i]) break; *************** *** 3187,3194 **** getout(1); } ! /* Use a precomputed index for fast look-up in cmdnames[] ! * taking into account the first 2 letters of eap->cmd. */ eap->cmdidx = cmdidxs1[CharOrdLow(c1)]; if (ASCII_ISLOWER(c2)) eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)]; --- 3187,3194 ---- getout(1); } ! // Use a precomputed index for fast look-up in cmdnames[] ! // taking into account the first 2 letters of eap->cmd. eap->cmdidx = cmdidxs1[CharOrdLow(c1)]; if (ASCII_ISLOWER(c2)) eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)]; *************** *** 3231,3237 **** { char *name; int minlen; ! int has_count; /* :123verbose :3tab */ } cmdmods[] = { {"aboveleft", 3, FALSE}, {"belowright", 3, FALSE}, --- 3231,3237 ---- { char *name; int minlen; ! int has_count; // :123verbose :3tab } cmdmods[] = { {"aboveleft", 3, FALSE}, {"belowright", 3, FALSE}, *************** *** 3296,3302 **** int j; char_u *p; ! /* Check command modifiers. */ for (i = 0; i < (int)(sizeof(cmdmods) / sizeof(struct cmdmod)); ++i) { for (j = 0; name[j] != NUL; ++j) --- 3296,3302 ---- int j; char_u *p; ! // Check command modifiers. for (i = 0; i < (int)(sizeof(cmdmods) / sizeof(struct cmdmod)); ++i) { for (j = 0; name[j] != NUL; ++j) *************** *** 3306,3313 **** return (cmdmods[i].name[j] == NUL ? 2 : 1); } ! /* Check built-in commands and user defined commands. ! * For ":2match" and ":3match" we need to skip the number. */ ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name; ea.cmdidx = (cmdidx_T)0; p = find_command(&ea, &full); --- 3306,3313 ---- return (cmdmods[i].name[j] == NUL ? 2 : 1); } ! // Check built-in commands and user defined commands. ! // For ":2match" and ":3match" we need to skip the number. ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name; ea.cmdidx = (cmdidx_T)0; p = find_command(&ea, &full); *************** *** 3316,3322 **** if (vim_isdigit(*name) && ea.cmdidx != CMD_match) return 0; if (*skipwhite(p) != NUL) ! return 0; /* trailing garbage */ return (ea.cmdidx == CMD_SIZE ? 0 : (full ? 2 : 1)); } #endif --- 3316,3322 ---- if (vim_isdigit(*name) && ea.cmdidx != CMD_match) return 0; if (*skipwhite(p) != NUL) ! return 0; // trailing garbage return (ea.cmdidx == CMD_SIZE ? 0 : (full ? 2 : 1)); } #endif *************** *** 3352,3358 **** char_u * skip_range( char_u *cmd, ! int *ctx) /* pointer to xp_context or NULL */ { unsigned delim; --- 3352,3358 ---- char_u * skip_range( char_u *cmd, ! int *ctx) // pointer to xp_context or NULL { unsigned delim; *************** *** 3383,3389 **** ++cmd; } ! /* Skip ":" and white space. */ while (*cmd == ':') cmd = skipwhite(cmd + 1); --- 3383,3389 ---- ++cmd; } ! // Skip ":" and white space. while (*cmd == ':') cmd = skipwhite(cmd + 1); *************** *** 3434,3440 **** { switch (*cmd) { ! case '.': /* '.' - Cursor position */ ++cmd; switch (addr_type) { --- 3434,3440 ---- { switch (*cmd) { ! case '.': // '.' - Cursor position ++cmd; switch (addr_type) { *************** *** 3475,3481 **** } break; ! case '$': /* '$' - last line */ ++cmd; switch (addr_type) { --- 3475,3481 ---- } break; ! case '$': // '$' - last line ++cmd; switch (addr_type) { *************** *** 3529,3535 **** } break; ! case '\'': /* ''' - mark */ if (*++cmd == NUL) { cmd = NULL; --- 3529,3535 ---- } break; ! case '\'': // ''' - mark if (*++cmd == NUL) { cmd = NULL; *************** *** 3545,3556 **** ++cmd; else { ! /* Only accept a mark in another file when it is ! * used by itself: ":'M". */ fp = getmark(*cmd, to_other_file && cmd[1] == NUL); ++cmd; if (fp == (pos_T *)-1) ! /* Jumped to another file. */ lnum = curwin->w_cursor.lnum; else { --- 3545,3556 ---- ++cmd; else { ! // Only accept a mark in another file when it is ! // used by itself: ":'M". fp = getmark(*cmd, to_other_file && cmd[1] == NUL); ++cmd; if (fp == (pos_T *)-1) ! // Jumped to another file. lnum = curwin->w_cursor.lnum; else { *************** *** 3565,3571 **** break; case '/': ! case '?': /* '/' or '?' - search */ c = *cmd++; if (addr_type != ADDR_LINES) { --- 3565,3571 ---- break; case '/': ! case '?': // '/' or '?' - search c = *cmd++; if (addr_type != ADDR_LINES) { *************** *** 3573,3579 **** cmd = NULL; goto error; } ! if (skip) /* skip "/pat/" */ { cmd = skip_regexp(cmd, c, (int)p_magic, NULL); if (*cmd == c) --- 3573,3579 ---- cmd = NULL; goto error; } ! if (skip) // skip "/pat/" { cmd = skip_regexp(cmd, c, (int)p_magic, NULL); if (*cmd == c) *************** *** 3610,3621 **** } lnum = curwin->w_cursor.lnum; curwin->w_cursor = pos; ! /* adjust command string pointer */ cmd += searchcmdlen; } break; ! case '\\': /* "\?", "\/" or "\&", repeat search */ ++cmd; if (addr_type != ADDR_LINES) { --- 3610,3621 ---- } lnum = curwin->w_cursor.lnum; curwin->w_cursor = pos; ! // adjust command string pointer cmd += searchcmdlen; } break; ! case '\\': // "\?", "\/" or "\&", repeat search ++cmd; if (addr_type != ADDR_LINES) { *************** *** 3668,3674 **** break; default: ! if (VIM_ISDIGIT(*cmd)) /* absolute line number */ lnum = getdigits(&cmd); } --- 3668,3674 ---- break; default: ! if (VIM_ISDIGIT(*cmd)) // absolute line number lnum = getdigits(&cmd); } *************** *** 3721,3730 **** } if (VIM_ISDIGIT(*cmd)) ! i = '+'; /* "number" is same as "+number" */ else i = *cmd++; ! if (!VIM_ISDIGIT(*cmd)) /* '+' is '+1', but '+0' is not '+1' */ n = 1; else n = getdigits(&cmd); --- 3721,3730 ---- } if (VIM_ISDIGIT(*cmd)) ! i = '+'; // "number" is same as "+number" else i = *cmd++; ! if (!VIM_ISDIGIT(*cmd)) // '+' is '+1', but '+0' is not '+1' n = 1; else n = getdigits(&cmd); *************** *** 3742,3749 **** else { #ifdef FEAT_FOLDING ! /* Relative line addressing, need to adjust for folded lines ! * now, but only do it after the first address. */ if (addr_type == ADDR_LINES && (i == '-' || i == '+') && address_count >= 2) (void)hasFolding(lnum, NULL, &lnum); --- 3742,3749 ---- else { #ifdef FEAT_FOLDING ! // Relative line addressing, need to adjust for folded lines ! // now, but only do it after the first address. if (addr_type == ADDR_LINES && (i == '-' || i == '+') && address_count >= 2) (void)hasFolding(lnum, NULL, &lnum); *************** *** 3831,3837 **** return _(e_invrange); break; case ADDR_ARGUMENTS: ! /* add 1 if ARGCOUNT is 0 */ if (eap->line2 > ARGCOUNT + (!ARGCOUNT)) return _(e_invrange); break; --- 3831,3837 ---- return _(e_invrange); break; case ADDR_ARGUMENTS: ! // add 1 if ARGCOUNT is 0 if (eap->line2 > ARGCOUNT + (!ARGCOUNT)) return _(e_invrange); break; *************** *** 3979,3992 **** if ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) { ! /* replace $* by given arguments */ i = 1; while ((pos = (char_u *)strstr((char *)pos + 2, "$*")) != NULL) ++i; len = (int)STRLEN(p); new_cmdline = alloc(STRLEN(program) + i * (len - 2) + 1); if (new_cmdline == NULL) ! return NULL; /* out of memory */ ptr = new_cmdline; while ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) { --- 3979,3992 ---- if ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) { ! // replace $* by given arguments i = 1; while ((pos = (char_u *)strstr((char *)pos + 2, "$*")) != NULL) ++i; len = (int)STRLEN(p); new_cmdline = alloc(STRLEN(program) + i * (len - 2) + 1); if (new_cmdline == NULL) ! return NULL; // out of memory ptr = new_cmdline; while ((pos = (char_u *)strstr((char *)program, "$*")) != NULL) { *************** *** 4002,4015 **** { new_cmdline = alloc(STRLEN(program) + STRLEN(p) + 2); if (new_cmdline == NULL) ! return NULL; /* out of memory */ STRCPY(new_cmdline, program); STRCAT(new_cmdline, " "); STRCAT(new_cmdline, p); } msg_make(p); ! /* 'eap->cmd' is not set here, because it is not used at CMD_make */ vim_free(*cmdlinep); *cmdlinep = new_cmdline; p = new_cmdline; --- 4002,4015 ---- { new_cmdline = alloc(STRLEN(program) + STRLEN(p) + 2); if (new_cmdline == NULL) ! return NULL; // out of memory STRCPY(new_cmdline, program); STRCAT(new_cmdline, " "); STRCAT(new_cmdline, p); } msg_make(p); ! // 'eap->cmd' is not set here, because it is not used at CMD_make vim_free(*cmdlinep); *cmdlinep = new_cmdline; p = new_cmdline; *************** *** 4029,4035 **** char_u **cmdlinep, char **errormsgp) { ! int has_wildcards; /* need to expand wildcards */ char_u *repl; int srclen; char_u *p; --- 4029,4035 ---- char_u **cmdlinep, char **errormsgp) { ! int has_wildcards; // need to expand wildcards char_u *repl; int srclen; char_u *p; *************** *** 4037,4043 **** int escaped; #ifdef FEAT_QUICKFIX ! /* Skip a regexp pattern for ":vimgrep[add] pat file..." */ p = skip_grep_pat(eap); #else p = eap->arg; --- 4037,4043 ---- int escaped; #ifdef FEAT_QUICKFIX ! // Skip a regexp pattern for ":vimgrep[add] pat file..." p = skip_grep_pat(eap); #else p = eap->arg; *************** *** 4052,4058 **** while (*p != NUL) { #ifdef FEAT_EVAL ! /* Skip over `=expr`, wildcards in it are not expanded. */ if (p[0] == '`' && p[1] == '=') { p += 2; --- 4052,4058 ---- while (*p != NUL) { #ifdef FEAT_EVAL ! // Skip over `=expr`, wildcards in it are not expanded. if (p[0] == '`' && p[1] == '=') { p += 2; *************** *** 4077,4092 **** */ repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum), errormsgp, &escaped); ! if (*errormsgp != NULL) /* error detected */ return FAIL; ! if (repl == NULL) /* no match found */ { p += srclen; continue; } ! /* Wildcards won't be expanded below, the replacement is taken ! * literally. But do expand "~/file", "~user/file" and "$HOME/file". */ if (vim_strchr(repl, '$') != NULL || vim_strchr(repl, '~') != NULL) { char_u *l = repl; --- 4077,4092 ---- */ repl = eval_vars(p, eap->arg, &srclen, &(eap->do_ecmd_lnum), errormsgp, &escaped); ! if (*errormsgp != NULL) // error detected return FAIL; ! if (repl == NULL) // no match found { p += srclen; continue; } ! // Wildcards won't be expanded below, the replacement is taken ! // literally. But do expand "~/file", "~user/file" and "$HOME/file". if (vim_strchr(repl, '$') != NULL || vim_strchr(repl, '~') != NULL) { char_u *l = repl; *************** *** 4095,4107 **** vim_free(l); } ! /* Need to escape white space et al. with a backslash. ! * Don't do this for: ! * - replacement that already has been escaped: "##" ! * - shell commands (may have to use quotes instead). ! * - non-unix systems when there is a single argument (spaces don't ! * separate arguments then). ! */ if (!eap->usefilter && !escaped && eap->cmdidx != CMD_bang --- 4095,4106 ---- vim_free(l); } ! // Need to escape white space et al. with a backslash. ! // Don't do this for: ! // - replacement that already has been escaped: "##" ! // - shell commands (may have to use quotes instead). ! // - non-unix systems when there is a single argument (spaces don't ! // separate arguments then). if (!eap->usefilter && !escaped && eap->cmdidx != CMD_bang *************** *** 4120,4127 **** { char_u *l; #ifdef BACKSLASH_IN_FILENAME ! /* Don't escape a backslash here, because rem_backslash() doesn't ! * remove it later. */ static char_u *nobslash = (char_u *)" \t\"|"; # define ESCAPE_CHARS nobslash #else --- 4119,4126 ---- { char_u *l; #ifdef BACKSLASH_IN_FILENAME ! // Don't escape a backslash here, because rem_backslash() doesn't ! // remove it later. static char_u *nobslash = (char_u *)" \t\"|"; # define ESCAPE_CHARS nobslash #else *************** *** 4141,4147 **** } } ! /* For a shell command a '!' must be escaped. */ if ((eap->usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal) && vim_strpbrk(repl, (char_u *)"!") != NULL) --- 4140,4146 ---- } } ! // For a shell command a '!' must be escaped. if ((eap->usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal) && vim_strpbrk(repl, (char_u *)"!") != NULL) *************** *** 4210,4216 **** else p = NULL; } ! else /* n == 2 */ { expand_T xpc; int options = WILD_LIST_NOTFOUND --- 4209,4215 ---- else p = NULL; } ! else // n == 2 { expand_T xpc; int options = WILD_LIST_NOTFOUND *************** *** 4229,4235 **** { (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), p, cmdlinep); ! if (n == 2) /* p came from ExpandOne() */ vim_free(p); } } --- 4228,4234 ---- { (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg), p, cmdlinep); ! if (n == 2) // p came from ExpandOne() vim_free(p); } } *************** *** 4266,4274 **** len = (int)STRLEN(repl); i = (int)(src - *cmdlinep) + (int)STRLEN(src + srclen) + len + 3; if (eap->nextcmd != NULL) ! i += (int)STRLEN(eap->nextcmd);/* add space for next command */ if ((new_cmdline = alloc(i)) == NULL) ! return NULL; /* out of memory! */ /* * Copy the stuff before the expanded part. --- 4265,4273 ---- len = (int)STRLEN(repl); i = (int)(src - *cmdlinep) + (int)STRLEN(src + srclen) + len + 3; if (eap->nextcmd != NULL) ! i += (int)STRLEN(eap->nextcmd);// add space for next command if ((new_cmdline = alloc(i)) == NULL) ! return NULL; // out of memory! /* * Copy the stuff before the expanded part. *************** *** 4276,4290 **** * Copy what came after the expanded part. * Copy the next commands, if there are any. */ ! i = (int)(src - *cmdlinep); /* length of part before match */ mch_memmove(new_cmdline, *cmdlinep, (size_t)i); mch_memmove(new_cmdline + i, repl, (size_t)len); ! i += len; /* remember the end of the string */ STRCPY(new_cmdline + i, src + srclen); ! src = new_cmdline + i; /* remember where to continue */ ! if (eap->nextcmd != NULL) /* append next command */ { i = (int)STRLEN(new_cmdline) + 1; STRCPY(new_cmdline + i, eap->nextcmd); --- 4275,4289 ---- * Copy what came after the expanded part. * Copy the next commands, if there are any. */ ! i = (int)(src - *cmdlinep); // length of part before match mch_memmove(new_cmdline, *cmdlinep, (size_t)i); mch_memmove(new_cmdline + i, repl, (size_t)len); ! i += len; // remember the end of the string STRCPY(new_cmdline + i, src + srclen); ! src = new_cmdline + i; // remember where to continue ! if (eap->nextcmd != NULL) // append next command { i = (int)STRLEN(new_cmdline) + 1; STRCPY(new_cmdline + i, eap->nextcmd); *************** *** 4319,4334 **** if (*p == Ctrl_V) { if (eap->argt & (EX_CTRLV | EX_XFILE)) ! ++p; /* skip CTRL-V and next char */ else ! /* remove CTRL-V and skip next char */ STRMOVE(p, p + 1); ! if (*p == NUL) /* stop at NUL after CTRL-V */ break; } #ifdef FEAT_EVAL ! /* Skip over `=expr` when wildcards are expanded. */ else if (p[0] == '`' && p[1] == '=' && (eap->argt & EX_XFILE)) { p += 2; --- 4318,4333 ---- if (*p == Ctrl_V) { if (eap->argt & (EX_CTRLV | EX_XFILE)) ! ++p; // skip CTRL-V and next char else ! // remove CTRL-V and skip next char STRMOVE(p, p + 1); ! if (*p == NUL) // stop at NUL after CTRL-V break; } #ifdef FEAT_EVAL ! // Skip over `=expr` when wildcards are expanded. else if (p[0] == '`' && p[1] == '=' && (eap->argt & EX_XFILE)) { p += 2; *************** *** 4336,4344 **** } #endif ! /* Check for '"': start of comment or '|': next command */ ! /* :@" and :*" do not start a comment! ! * :redir @" doesn't either. */ else if ((*p == '"' && !(eap->argt & EX_NOTRLCOM) && ((eap->cmdidx != CMD_at && eap->cmdidx != CMD_star) || p != eap->arg) --- 4335,4343 ---- } #endif ! // Check for '"': start of comment or '|': next command ! // :@" and :*" do not start a comment! ! // :redir @" doesn't either. else if ((*p == '"' && !(eap->argt & EX_NOTRLCOM) && ((eap->cmdidx != CMD_at && eap->cmdidx != CMD_star) || p != eap->arg) *************** *** 4353,4359 **** if ((vim_strchr(p_cpo, CPO_BAR) == NULL || !(eap->argt & EX_CTRLV)) && *(p - 1) == '\\') { ! STRMOVE(p - 1, p); /* remove the '\' */ --p; } else --- 4352,4358 ---- if ((vim_strchr(p_cpo, CPO_BAR) == NULL || !(eap->argt & EX_CTRLV)) && *(p - 1) == '\\') { ! STRMOVE(p - 1, p); // remove the '\' --p; } else *************** *** 4365,4371 **** } } ! if (!(eap->argt & EX_NOTRLCOM)) /* remove trailing spaces */ del_trailing_spaces(eap->arg); } --- 4364,4370 ---- } } ! if (!(eap->argt & EX_NOTRLCOM)) // remove trailing spaces del_trailing_spaces(eap->arg); } *************** *** 4378,4384 **** char_u *arg = *argp; char_u *command = NULL; ! if (*arg == '+') /* +[command] */ { ++arg; if (vim_isspace(*arg) || *arg == NUL) --- 4377,4383 ---- char_u *arg = *argp; char_u *command = NULL; ! if (*arg == '+') // +[command] { ++arg; if (vim_isspace(*arg) || *arg == NUL) *************** *** 4388,4397 **** command = arg; arg = skip_cmd_arg(command, TRUE); if (*arg != NUL) ! *arg++ = NUL; /* terminate command with NUL */ } ! arg = skipwhite(arg); /* skip over spaces */ *argp = arg; } return command; --- 4387,4396 ---- command = arg; arg = skip_cmd_arg(command, TRUE); if (*arg != NUL) ! *arg++ = NUL; // terminate command with NUL } ! arg = skipwhite(arg); // skip over spaces *argp = arg; } return command; *************** *** 4403,4409 **** char_u * skip_cmd_arg( char_u *p, ! int rembs) /* TRUE to halve the number of backslashes */ { while (*p && !vim_isspace(*p)) { --- 4402,4408 ---- char_u * skip_cmd_arg( char_u *p, ! int rembs) // TRUE to halve the number of backslashes { while (*p && !vim_isspace(*p)) { *************** *** 4445,4451 **** int bad_char_idx; char_u *p; ! /* ":edit ++[no]bin[ary] file" */ if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0) { if (*arg == 'n') --- 4444,4450 ---- int bad_char_idx; char_u *p; ! // ":edit ++[no]bin[ary] file" if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0) { if (*arg == 'n') *************** *** 4461,4467 **** return OK; } ! /* ":read ++edit file" */ if (STRNCMP(arg, "edit", 4) == 0) { eap->read_edit = TRUE; --- 4460,4466 ---- return OK; } ! // ":read ++edit file" if (STRNCMP(arg, "edit", 4) == 0) { eap->read_edit = TRUE; *************** *** 4510,4523 **** } else if (pp == &eap->force_enc) { ! /* Make 'fileencoding' lower case. */ for (p = eap->cmd + eap->force_enc; *p != NUL; ++p) *p = TOLOWER_ASC(*p); } else { ! /* Check ++bad= argument. Must be a single-byte character, "keep" or ! * "drop". */ if (get_bad_opt(eap->cmd + bad_char_idx, eap) == FAIL) return FAIL; } --- 4509,4522 ---- } else if (pp == &eap->force_enc) { ! // Make 'fileencoding' lower case. for (p = eap->cmd + eap->force_enc; *p != NUL; ++p) *p = TOLOWER_ASC(*p); } else { ! // Check ++bad= argument. Must be a single-byte character, "keep" or ! // "drop". if (get_bad_opt(eap->cmd + bad_char_idx, eap) == FAIL) return FAIL; } *************** *** 4554,4560 **** int did_aucmd; (void)do_doautocmd(arg, TRUE, &did_aucmd); ! /* Only when there is no . */ if (call_do_modelines && did_aucmd) do_modelines(0); } --- 4553,4559 ---- int did_aucmd; (void)do_doautocmd(arg, TRUE, &did_aucmd); ! // Only when there is no . if (call_do_modelines && did_aucmd) do_modelines(0); } *************** *** 4589,4595 **** eap->errmsg = e_trailing; else { ! if (eap->addr_count == 0) /* default is current buffer */ goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0); else goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2); --- 4588,4594 ---- eap->errmsg = e_trailing; else { ! if (eap->addr_count == 0) // default is current buffer goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0); else goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2); *************** *** 4712,4718 **** */ static int check_more( ! int message, /* when FALSE check only, no messages */ int forceit) { int n = ARGCOUNT - curwin->w_arg_idx - 1; --- 4711,4717 ---- */ static int check_more( ! int message, // when FALSE check only, no messages int forceit) { int n = ARGCOUNT - curwin->w_arg_idx - 1; *************** *** 4737,4743 **** #endif semsg(NGETTEXT("E173: %d more file to edit", "E173: %d more files to edit", n), n); ! quitmore = 2; /* next try to quit is allowed */ } return FAIL; } --- 4736,4742 ---- #endif semsg(NGETTEXT("E173: %d more file to edit", "E173: %d more files to edit", n), n); ! quitmore = 2; // next try to quit is allowed } return FAIL; } *************** *** 4859,4865 **** return; } #endif ! /* Don't quit while editing the command line. */ if (text_locked()) { text_locked_msg(); --- 4858,4864 ---- return; } #endif ! // Don't quit while editing the command line. if (text_locked()) { text_locked_msg(); *************** *** 4876,4886 **** else wp = curwin; ! /* Refuse to quit when locked. */ if (curbuf_locked()) return; ! /* Trigger QuitPre and maybe ExitPre */ if (before_quit_autocmds(wp, FALSE, eap->forceit)) return; --- 4875,4885 ---- else wp = curwin; ! // Refuse to quit when locked. if (curbuf_locked()) return; ! // Trigger QuitPre and maybe ExitPre if (before_quit_autocmds(wp, FALSE, eap->forceit)) return; *************** *** 4904,4923 **** } else { ! /* quit last window ! * Note: only_one_window() returns true, even so a help window is ! * still open. In that case only quit, if no address has been ! * specified. Example: ! * :h|wincmd w|1q - don't quit ! * :h|wincmd w|q - quit ! */ if (only_one_window() && (ONE_WINDOW || eap->addr_count == 0)) getout(0); not_exiting(); #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif ! /* close window; may free buffer */ win_close(wp, !buf_hide(wp->w_buffer) || eap->forceit); } } --- 4903,4921 ---- } else { ! // quit last window ! // Note: only_one_window() returns true, even so a help window is ! // still open. In that case only quit, if no address has been ! // specified. Example: ! // :h|wincmd w|1q - don't quit ! // :h|wincmd w|q - quit if (only_one_window() && (ONE_WINDOW || eap->addr_count == 0)) getout(0); not_exiting(); #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif ! // close window; may free buffer win_close(wp, !buf_hide(wp->w_buffer) || eap->forceit); } } *************** *** 4928,4935 **** static void ex_cquit(exarg_T *eap UNUSED) { ! getout(1); /* this does not always pass on the exit code to the Manx ! compiler. why? */ } /* --- 4926,4933 ---- static void ex_cquit(exarg_T *eap UNUSED) { ! getout(1); // this does not always pass on the exit code to the Manx ! // compiler. why? } /* *************** *** 4942,4955 **** if (cmdwin_type != 0) { if (eap->forceit) ! cmdwin_result = K_XF1; /* ex_window() takes care of this */ else cmdwin_result = K_XF2; return; } # endif ! /* Don't quit while editing the command line. */ if (text_locked()) { text_locked_msg(); --- 4940,4953 ---- if (cmdwin_type != 0) { if (eap->forceit) ! cmdwin_result = K_XF1; // ex_window() takes care of this else cmdwin_result = K_XF2; return; } # endif ! // Don't quit while editing the command line. if (text_locked()) { text_locked_msg(); *************** *** 5028,5034 **** ex_win_close( int forceit, win_T *win, ! tabpage_T *tp) /* NULL or the tab page "win" is in */ { int need_hide; buf_T *buf = win->w_buffer; --- 5026,5032 ---- ex_win_close( int forceit, win_T *win, ! tabpage_T *tp) // NULL or the tab page "win" is in { int need_hide; buf_T *buf = win->w_buffer; *************** *** 5059,5065 **** need_mouse_correct = TRUE; #endif ! /* free buffer when not hiding it or when it's a scratch buffer */ if (tp == NULL) win_close(win, !need_hide && !buf_hide(buf)); else --- 5057,5063 ---- need_mouse_correct = TRUE; #endif ! // free buffer when not hiding it or when it's a scratch buffer if (tp == NULL) win_close(win, !need_hide && !buf_hide(buf)); else *************** *** 5081,5088 **** { char_u *p = eap->arg; char_u *p_save; ! int relative = 0; /* argument +N/-N means: go to N places to the ! * right/left relative to the current position. */ if (*p == '-') { --- 5079,5086 ---- { char_u *p = eap->arg; char_u *p_save; ! int relative = 0; // argument +N/-N means: go to N places to the ! // right/left relative to the current position. if (*p == '-') { *************** *** 5105,5111 **** else if (p == p_save || *p_save == '-' || *p != NUL || tab_number > LAST_TAB_NR) { ! /* No numbers as argument. */ eap->errmsg = e_invarg; goto theend; } --- 5103,5109 ---- else if (p == p_save || *p_save == '-' || *p != NUL || tab_number > LAST_TAB_NR) { ! // No numbers as argument. eap->errmsg = e_invarg; goto theend; } *************** *** 5117,5123 **** else if (p == p_save || *p_save == '-' || *p != NUL || tab_number == 0) { ! /* No numbers as argument. */ eap->errmsg = e_invarg; goto theend; } --- 5115,5121 ---- else if (p == p_save || *p_save == '-' || *p != NUL || tab_number == 0) { ! // No numbers as argument. eap->errmsg = e_invarg; goto theend; } *************** *** 5229,5246 **** if (eap->errmsg == NULL) { goto_tabpage(tab_number); ! /* Repeat this up to a 1000 times, because autocommands may ! * mess up the lists. */ for (done = 0; done < 1000; ++done) { FOR_ALL_TABPAGES(tp) if (tp->tp_topframe != topframe) { tabpage_close_other(tp, eap->forceit); ! /* if we failed to close it quit */ if (valid_tabpage(tp)) done = 1000; ! /* start over, "tp" is now invalid */ break; } if (first_tabpage->tp_next == NULL) --- 5227,5244 ---- if (eap->errmsg == NULL) { goto_tabpage(tab_number); ! // Repeat this up to a 1000 times, because autocommands may ! // mess up the lists. for (done = 0; done < 1000; ++done) { FOR_ALL_TABPAGES(tp) if (tp->tp_topframe != topframe) { tabpage_close_other(tp, eap->forceit); ! // if we failed to close it quit if (valid_tabpage(tp)) done = 1000; ! // start over, "tp" is now invalid break; } if (first_tabpage->tp_next == NULL) *************** *** 5256,5263 **** void tabpage_close(int forceit) { ! /* First close all the windows but the current one. If that worked then ! * close the last window in this tab, that will close it. */ if (!ONE_WINDOW) close_others(TRUE, forceit); if (ONE_WINDOW) --- 5254,5261 ---- void tabpage_close(int forceit) { ! // First close all the windows but the current one. If that worked then ! // close the last window in this tab, that will close it. if (!ONE_WINDOW) close_others(TRUE, forceit); if (ONE_WINDOW) *************** *** 5280,5294 **** win_T *wp; int h = tabline_height(); ! /* Limit to 1000 windows, autocommands may add a window while we close ! * one. OK, so I'm paranoid... */ while (++done < 1000) { wp = tp->tp_firstwin; ex_win_close(forceit, wp, tp); ! /* Autocommands may delete the tab page under our fingers and we may ! * fail to close a window with a modified buffer. */ if (!valid_tabpage(tp) || tp->tp_firstwin == wp) break; } --- 5278,5292 ---- win_T *wp; int h = tabline_height(); ! // Limit to 1000 windows, autocommands may add a window while we close ! // one. OK, so I'm paranoid... while (++done < 1000) { wp = tp->tp_firstwin; ex_win_close(forceit, wp, tp); ! // Autocommands may delete the tab page under our fingers and we may ! // fail to close a window with a modified buffer. if (!valid_tabpage(tp) || tp->tp_firstwin == wp) break; } *************** *** 5329,5342 **** static void ex_hide(exarg_T *eap UNUSED) { ! /* ":hide" or ":hide | cmd": hide current window */ if (!eap->skip) { #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif if (eap->addr_count == 0) ! win_close(curwin, FALSE); /* don't free buffer */ else { int winnr = 0; --- 5327,5340 ---- static void ex_hide(exarg_T *eap UNUSED) { ! // ":hide" or ":hide | cmd": hide current window if (!eap->skip) { #ifdef FEAT_GUI need_mouse_correct = TRUE; #endif if (eap->addr_count == 0) ! win_close(curwin, FALSE); // don't free buffer else { int winnr = 0; *************** *** 5372,5390 **** out_char('\n'); out_flush(); stoptermcap(); ! out_flush(); /* needed for SUN to restore xterm buffer */ #ifdef FEAT_TITLE ! mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */ #endif ! ui_suspend(); /* call machine specific function */ #ifdef FEAT_TITLE maketitle(); ! resettitle(); /* force updating the title */ #endif starttermcap(); ! scroll_start(); /* scroll screen before redrawing */ redraw_later_clear(); ! shell_resized(); /* may have resized window */ } } --- 5370,5388 ---- out_char('\n'); out_flush(); stoptermcap(); ! out_flush(); // needed for SUN to restore xterm buffer #ifdef FEAT_TITLE ! mch_restore_title(SAVE_RESTORE_BOTH); // restore window titles #endif ! ui_suspend(); // call machine specific function #ifdef FEAT_TITLE maketitle(); ! resettitle(); // force updating the title #endif starttermcap(); ! scroll_start(); // scroll screen before redrawing redraw_later_clear(); ! shell_resized(); // may have resized window } } *************** *** 5401,5407 **** return; } #endif ! /* Don't quit while editing the command line. */ if (text_locked()) { text_locked_msg(); --- 5399,5405 ---- return; } #endif ! // Don't quit while editing the command line. if (text_locked()) { text_locked_msg(); *************** *** 5426,5438 **** } else { ! if (only_one_window()) /* quit last window, exit Vim */ getout(0); not_exiting(); # ifdef FEAT_GUI need_mouse_correct = TRUE; # endif ! /* Quit current window, may free the buffer. */ win_close(curwin, !buf_hide(curwin->w_buffer)); } } --- 5424,5436 ---- } else { ! if (only_one_window()) // quit last window, exit Vim getout(0); not_exiting(); # ifdef FEAT_GUI need_mouse_correct = TRUE; # endif ! // Quit current window, may free the buffer. win_close(curwin, !buf_hide(curwin->w_buffer)); } } *************** *** 5455,5464 **** eap->cmdidx == CMD_list || (eap->flags & EXFLAG_LIST)); if (++eap->line1 > eap->line2) break; ! out_flush(); /* show one line at a time */ } setpcmark(); ! /* put cursor at last line */ curwin->w_cursor.lnum = eap->line2; beginline(BL_SOL | BL_FIX); } --- 5453,5462 ---- eap->cmdidx == CMD_list || (eap->flags & EXFLAG_LIST)); if (++eap->line1 > eap->line2) break; ! out_flush(); // show one line at a time } setpcmark(); ! // put cursor at last line curwin->w_cursor.lnum = eap->line2; beginline(BL_SOL | BL_FIX); } *************** *** 5502,5512 **** // recursively. Avoid that by setting drop_busy. drop_busy = TRUE; ! /* Check whether the current buffer is changed. If so, we will need ! * to split the current window or data could be lost. ! * We don't need to check if the 'hidden' option is set, as in this ! * case the buffer won't be lost. ! */ if (!buf_hide(curbuf) && !drop_split) { ++emsg_off; --- 5500,5509 ---- // recursively. Avoid that by setting drop_busy. drop_busy = TRUE; ! // Check whether the current buffer is changed. If so, we will need ! // to split the current window or data could be lost. ! // We don't need to check if the 'hidden' option is set, as in this ! // case the buffer won't be lost. if (!buf_hide(curbuf) && !drop_split) { ++emsg_off; *************** *** 5519,5526 **** return; RESET_BINDING(curwin); ! /* When splitting the window, create a new alist. Otherwise the ! * existing one is overwritten. */ alist_unlink(curwin->w_alist); alist_new(); } --- 5516,5523 ---- return; RESET_BINDING(curwin); ! // When splitting the window, create a new alist. Otherwise the ! // existing one is overwritten. alist_unlink(curwin->w_alist); alist_new(); } *************** *** 5533,5550 **** /* * Move to the first file. */ ! /* Fake up a minimal "next" command for do_argfile() */ vim_memset(&ea, 0, sizeof(ea)); ea.cmd = (char_u *)"next"; do_argfile(&ea, 0); ! /* do_ecmd() may set need_start_insertmode, but since we never left Insert ! * mode that is not needed here. */ need_start_insertmode = FALSE; ! /* Restore msg_scroll, otherwise a following command may cause scrolling ! * unexpectedly. The screen will be redrawn by the caller, thus ! * msg_scroll being set by displaying a message is irrelevant. */ msg_scroll = save_msg_scroll; if (drop_callback != NULL) --- 5530,5547 ---- /* * Move to the first file. */ ! // Fake up a minimal "next" command for do_argfile() vim_memset(&ea, 0, sizeof(ea)); ea.cmd = (char_u *)"next"; do_argfile(&ea, 0); ! // do_ecmd() may set need_start_insertmode, but since we never left Insert ! // mode that is not needed here. need_start_insertmode = FALSE; ! // Restore msg_scroll, otherwise a following command may cause scrolling ! // unexpectedly. The screen will be redrawn by the caller, thus ! // msg_scroll being set by displaying a message is irrelevant. msg_scroll = save_msg_scroll; if (drop_callback != NULL) *************** *** 5637,5643 **** static void ex_recover(exarg_T *eap) { ! /* Set recoverymode right away to avoid the ATTENTION prompt. */ recoverymode = TRUE; if (!check_changed(curbuf, (p_awa ? CCGD_AW : 0) | CCGD_MULTWIN --- 5634,5640 ---- static void ex_recover(exarg_T *eap) { ! // Set recoverymode right away to avoid the ATTENTION prompt. recoverymode = TRUE; if (!check_changed(curbuf, (p_awa ? CCGD_AW : 0) | CCGD_MULTWIN *************** *** 5694,5701 **** #endif #ifdef FEAT_QUICKFIX ! /* A ":split" in the quickfix window works like ":new". Don't want two ! * quickfix windows. But it's OK when doing ":tab split". */ if (bt_quickfix(curbuf) && cmdmod.tab == 0) { if (eap->cmdidx == CMD_split) --- 5691,5698 ---- #endif #ifdef FEAT_QUICKFIX ! // A ":split" in the quickfix window works like ":new". Don't want two ! // quickfix windows. But it's OK when doing ":tab split". if (bt_quickfix(curbuf) && cmdmod.tab == 0) { if (eap->cmdidx == CMD_split) *************** *** 5729,5736 **** # endif au_has_group((char_u *)"FileExplorer")) { ! /* No browsing supported but we do have the file explorer: ! * Edit the directory. */ if (*eap->arg == NUL || !mch_isdir(eap->arg)) eap->arg = (char_u *)"."; } --- 5726,5733 ---- # endif au_has_group((char_u *)"FileExplorer")) { ! // No browsing supported but we do have the file explorer: ! // Edit the directory. if (*eap->arg == NUL || !mch_isdir(eap->arg)) eap->arg = (char_u *)"."; } *************** *** 5745,5751 **** eap->arg = fname; } } ! cmdmod.browse = FALSE; /* Don't browse again in do_ecmd(). */ #endif /* --- 5742,5748 ---- eap->arg = fname; } } ! cmdmod.browse = FALSE; // Don't browse again in do_ecmd(). #endif /* *************** *** 5759,5765 **** { do_exedit(eap, old_curwin); ! /* set the alternate buffer for the window we came from */ if (curwin != old_curwin && win_valid(old_curwin) && old_curwin->w_buffer != curbuf --- 5756,5762 ---- { do_exedit(eap, old_curwin); ! // set the alternate buffer for the window we came from if (curwin != old_curwin && win_valid(old_curwin) && old_curwin->w_buffer != curbuf *************** *** 5770,5777 **** else if (win_split(eap->addr_count > 0 ? (int)eap->line2 : 0, *eap->cmd == 'v' ? WSP_VERT : 0) != FAIL) { ! /* Reset 'scrollbind' when editing another file, but keep it when ! * doing ":split" without arguments. */ if (*eap->arg != NUL # ifdef FEAT_BROWSE || cmdmod.browse --- 5767,5774 ---- else if (win_split(eap->addr_count > 0 ? (int)eap->line2 : 0, *eap->cmd == 'v' ? WSP_VERT : 0) != FAIL) { ! // Reset 'scrollbind' when editing another file, but keep it when ! // doing ":split" without arguments. if (*eap->arg != NUL # ifdef FEAT_BROWSE || cmdmod.browse *************** *** 5838,5844 **** if (p == p_save || *p_save == '-' || *p != NUL || tab_number == 0) { ! /* No numbers as argument. */ eap->errmsg = e_invarg; return; } --- 5835,5841 ---- if (p == p_save || *p_save == '-' || *p != NUL || tab_number == 0) { ! // No numbers as argument. eap->errmsg = e_invarg; return; } *************** *** 5859,5865 **** } goto_tabpage(-tab_number); break; ! default: /* CMD_tabnext */ tab_number = get_tabpage_arg(eap); if (eap->errmsg == NULL) goto_tabpage(tab_number); --- 5856,5862 ---- } goto_tabpage(-tab_number); break; ! default: // CMD_tabnext tab_number = get_tabpage_arg(eap); if (eap->errmsg == NULL) goto_tabpage(tab_number); *************** *** 5897,5903 **** msg_putchar('\n'); vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++); msg_outtrans_attr(IObuff, HL_ATTR(HLF_T)); ! out_flush(); /* output one line at a time */ ui_breakcheck(); if (tp == curtab) --- 5894,5900 ---- msg_putchar('\n'); vim_snprintf((char *)IObuff, IOSIZE, _("Tab page %d"), tabcount++); msg_outtrans_attr(IObuff, HL_ATTR(HLF_T)); ! out_flush(); // output one line at a time ui_breakcheck(); if (tp == curtab) *************** *** 5917,5923 **** home_replace(wp->w_buffer, wp->w_buffer->b_fname, IObuff, IOSIZE, TRUE); msg_outtrans(IObuff); ! out_flush(); /* output one line at a time */ ui_breakcheck(); } } --- 5914,5920 ---- home_replace(wp->w_buffer, wp->w_buffer->b_fname, IObuff, IOSIZE, TRUE); msg_outtrans(IObuff); ! out_flush(); // output one line at a time ui_breakcheck(); } } *************** *** 5961,5967 **** { if (*eap->arg == '-' || *eap->arg == '+') n += curwin->w_width; ! else if (n == 0 && eap->arg[0] == NUL) /* default is very wide */ n = 9999; win_setwidth_win((int)n, wp); } --- 5958,5964 ---- { if (*eap->arg == '-' || *eap->arg == '+') n += curwin->w_width; ! else if (n == 0 && eap->arg[0] == NUL) // default is very wide n = 9999; win_setwidth_win((int)n, wp); } *************** *** 5969,5975 **** { if (*eap->arg == '-' || *eap->arg == '+') n += curwin->w_height; ! else if (n == 0 && eap->arg[0] == NUL) /* default is very high */ n = 9999; win_setheight_win((int)n, wp); } --- 5966,5972 ---- { if (*eap->arg == '-' || *eap->arg == '+') n += curwin->w_height; ! else if (n == 0 && eap->arg[0] == NUL) // default is very high n = 9999; win_setheight_win((int)n, wp); } *************** *** 5989,5996 **** TRUE, curbuf->b_ffname); if (eap->addr_count > 0) { ! /* Repeat finding the file "count" times. This matters when it ! * appears several times in the path. */ count = eap->line2; while (fname != NULL && --count > 0) { --- 5986,5993 ---- TRUE, curbuf->b_ffname); if (eap->addr_count > 0) { ! // Repeat finding the file "count" times. This matters when it ! // appears several times in the path. count = eap->line2; while (fname != NULL && --count > 0) { *************** *** 6024,6030 **** beginline(BL_SOL | BL_FIX); if (*eap->arg == '/') { ! /* ":open /pattern/": put cursor in column found with pattern */ ++eap->arg; p = skip_regexp(eap->arg, '/', p_magic, NULL); *p = NUL; --- 6021,6027 ---- beginline(BL_SOL | BL_FIX); if (*eap->arg == '/') { ! // ":open /pattern/": put cursor in column found with pattern ++eap->arg; p = skip_regexp(eap->arg, '/', p_magic, NULL); *p = NUL; *************** *** 6039,6045 **** emsg(_(e_nomatch)); vim_regfree(regmatch.regprog); } ! /* Move to the NUL, ignore any other arguments. */ eap->arg += STRLEN(eap->arg); } check_cursor(); --- 6036,6042 ---- emsg(_(e_nomatch)); vim_regfree(regmatch.regprog); } ! // Move to the NUL, ignore any other arguments. eap->arg += STRLEN(eap->arg); } check_cursor(); *************** *** 6063,6069 **** void do_exedit( exarg_T *eap, ! win_T *old_curwin) /* curwin before doing a split or NULL */ { int n; int need_hide; --- 6060,6066 ---- void do_exedit( exarg_T *eap, ! win_T *old_curwin) // curwin before doing a split or NULL { int n; int need_hide; *************** *** 6080,6086 **** exmode_active = FALSE; if (*eap->arg == NUL) { ! /* Special case: ":global/pat/visual\NLvi-commands" */ if (global_busy) { int rd = RedrawingDisabled; --- 6077,6083 ---- exmode_active = FALSE; if (*eap->arg == NUL) { ! // Special case: ":global/pat/visual\NLvi-commands" if (global_busy) { int rd = RedrawingDisabled; *************** *** 6125,6131 **** || eap->cmdidx == CMD_tabedit || eap->cmdidx == CMD_vnew) && *eap->arg == NUL) { ! /* ":new" or ":tabnew" without argument: edit an new empty buffer */ setpcmark(); (void)do_ecmd(0, NULL, NULL, eap, ECMD_ONE, ECMD_HIDE + (eap->forceit ? ECMD_FORCEIT : 0), --- 6122,6128 ---- || eap->cmdidx == CMD_tabedit || eap->cmdidx == CMD_vnew) && *eap->arg == NUL) { ! // ":new" or ":tabnew" without argument: edit an new empty buffer setpcmark(); (void)do_ecmd(0, NULL, NULL, eap, ECMD_ONE, ECMD_HIDE + (eap->forceit ? ECMD_FORCEIT : 0), *************** *** 6138,6145 **** #endif ) { ! /* Can't edit another file when "curbuf_lock" is set. Only ":edit" ! * can bring us here, others are stopped earlier. */ if (*eap->arg != NUL && curbuf_locked()) return; --- 6135,6142 ---- #endif ) { ! // Can't edit another file when "curbuf_lock" is set. Only ":edit" ! // can bring us here, others are stopped earlier. if (*eap->arg != NUL && curbuf_locked()) return; *************** *** 6147,6169 **** if (eap->cmdidx == CMD_view || eap->cmdidx == CMD_sview) readonlymode = TRUE; else if (eap->cmdidx == CMD_enew) ! readonlymode = FALSE; /* 'readonly' doesn't make sense in an ! empty buffer */ setpcmark(); if (do_ecmd(0, (eap->cmdidx == CMD_enew ? NULL : eap->arg), NULL, eap, ! /* ":edit" goes to first line if Vi compatible */ (*eap->arg == NUL && eap->do_ecmd_lnum == 0 && vim_strchr(p_cpo, CPO_GOTO1) != NULL) ? ECMD_ONE : eap->do_ecmd_lnum, (buf_hide(curbuf) ? ECMD_HIDE : 0) + (eap->forceit ? ECMD_FORCEIT : 0) ! /* after a split we can use an existing buffer */ + (old_curwin != NULL ? ECMD_OLDBUF : 0) + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 ) , old_curwin == NULL ? curwin : NULL) == FAIL) { ! /* Editing the file failed. If the window was split, close it. */ if (old_curwin != NULL) { need_hide = (curbufIsChanged() && curbuf->b_nwindows <= 1); --- 6144,6166 ---- if (eap->cmdidx == CMD_view || eap->cmdidx == CMD_sview) readonlymode = TRUE; else if (eap->cmdidx == CMD_enew) ! readonlymode = FALSE; // 'readonly' doesn't make sense in an ! // empty buffer setpcmark(); if (do_ecmd(0, (eap->cmdidx == CMD_enew ? NULL : eap->arg), NULL, eap, ! // ":edit" goes to first line if Vi compatible (*eap->arg == NUL && eap->do_ecmd_lnum == 0 && vim_strchr(p_cpo, CPO_GOTO1) != NULL) ? ECMD_ONE : eap->do_ecmd_lnum, (buf_hide(curbuf) ? ECMD_HIDE : 0) + (eap->forceit ? ECMD_FORCEIT : 0) ! // after a split we can use an existing buffer + (old_curwin != NULL ? ECMD_OLDBUF : 0) + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 ) , old_curwin == NULL ? curwin : NULL) == FAIL) { ! // Editing the file failed. If the window was split, close it. if (old_curwin != NULL) { need_hide = (curbufIsChanged() && curbuf->b_nwindows <= 1); *************** *** 6172,6179 **** #if defined(FEAT_EVAL) cleanup_T cs; ! /* Reset the error/interrupt/exception state here so that ! * aborting() returns FALSE when closing a window. */ enter_cleanup(&cs); #endif #ifdef FEAT_GUI --- 6169,6176 ---- #if defined(FEAT_EVAL) cleanup_T cs; ! // Reset the error/interrupt/exception state here so that ! // aborting() returns FALSE when closing a window. enter_cleanup(&cs); #endif #ifdef FEAT_GUI *************** *** 6182,6190 **** win_close(curwin, !need_hide && !buf_hide(curbuf)); #if defined(FEAT_EVAL) ! /* Restore the error/interrupt/exception state if not ! * discarded by a new aborting error, interrupt, or ! * uncaught exception. */ leave_cleanup(&cs); #endif } --- 6179,6187 ---- win_close(curwin, !need_hide && !buf_hide(curbuf)); #if defined(FEAT_EVAL) ! // Restore the error/interrupt/exception state if not ! // discarded by a new aborting error, interrupt, or ! // uncaught exception. leave_cleanup(&cs); #endif } *************** *** 6192,6201 **** } else if (readonlymode && curbuf->b_nwindows == 1) { ! /* When editing an already visited buffer, 'readonly' won't be set ! * but the previous value is kept. With ":view" and ":sview" we ! * want the file to be readonly, except when another window is ! * editing the same buffer. */ curbuf->b_p_ro = TRUE; } readonlymode = n; --- 6189,6198 ---- } else if (readonlymode && curbuf->b_nwindows == 1) { ! // When editing an already visited buffer, 'readonly' won't be set ! // but the previous value is kept. With ":view" and ":sview" we ! // want the file to be readonly, except when another window is ! // editing the same buffer. curbuf->b_p_ro = TRUE; } readonlymode = n; *************** *** 6360,6366 **** int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); linenr_T lnum; ! if (eap->usefilter) /* :r!cmd */ do_bang(1, eap, FALSE, FALSE, TRUE); else { --- 6357,6363 ---- int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); linenr_T lnum; ! if (eap->usefilter) // :r!cmd do_bang(1, eap, FALSE, FALSE, TRUE); else { *************** *** 6387,6393 **** #endif if (*eap->arg == NUL) { ! if (check_fname() == FAIL) /* check for no file name */ return; i = readfile(curbuf->b_ffname, curbuf->b_fname, eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0); --- 6384,6390 ---- #endif if (*eap->arg == NUL) { ! if (check_fname() == FAIL) // check for no file name return; i = readfile(curbuf->b_ffname, curbuf->b_fname, eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0); *************** *** 6411,6418 **** { if (empty && exmode_active) { ! /* Delete the empty line that remains. Historically ex does ! * this but vi doesn't. */ if (eap->line2 == 0) lnum = curbuf->b_ml.ml_line_count; else --- 6408,6415 ---- { if (empty && exmode_active) { ! // Delete the empty line that remains. Historically ex does ! // this but vi doesn't. if (eap->line2 == 0) lnum = curbuf->b_ml.ml_line_count; else *************** *** 6456,6466 **** VIM_CLEAR(curwin->w_localdir); if (scope != CDSCOPE_GLOBAL) { ! /* If still in global directory, need to remember current ! * directory as global directory. */ if (globaldir == NULL && prev_dir != NULL) globaldir = vim_strsave(prev_dir); ! /* Remember this local directory for the window. */ if (mch_dirname(NameBuff, MAXPATHL) == OK) { if (scope == CDSCOPE_TABPAGE) --- 6453,6463 ---- VIM_CLEAR(curwin->w_localdir); if (scope != CDSCOPE_GLOBAL) { ! // If still in global directory, need to remember current ! // directory as global directory. if (globaldir == NULL && prev_dir != NULL) globaldir = vim_strsave(prev_dir); ! // Remember this local directory for the window. if (mch_dirname(NameBuff, MAXPATHL) == OK) { if (scope == CDSCOPE_TABPAGE) *************** *** 6471,6478 **** } else { ! /* We are now in the global directory, no need to remember its ! * name. */ VIM_CLEAR(globaldir); } --- 6468,6475 ---- } else { ! // We are now in the global directory, no need to remember its ! // name. VIM_CLEAR(globaldir); } *************** *** 6747,6753 **** if (*eap->arg == 'g' || *eap->arg == Ctrl_G) { ! /* CTRL-W g and CTRL-W CTRL-G have an extra command character */ if (eap->arg[1] == NUL) { emsg(_(e_invarg)); --- 6744,6750 ---- if (*eap->arg == 'g' || *eap->arg == Ctrl_G) { ! // CTRL-W g and CTRL-W CTRL-G have an extra command character if (eap->arg[1] == NUL) { emsg(_(e_invarg)); *************** *** 6765,6771 **** emsg(_(e_invarg)); else if (!eap->skip) { ! /* Pass flags on for ":vertical wincmd ]". */ postponed_split_flags = cmdmod.split; postponed_split_tab = cmdmod.tab; do_window(*eap->arg, eap->addr_count > 0 ? eap->line2 : 0L, xchar); --- 6762,6768 ---- emsg(_(e_invarg)); else if (!eap->skip) { ! // Pass flags on for ":vertical wincmd ]". postponed_split_flags = cmdmod.split; postponed_split_tab = cmdmod.tab; do_window(*eap->arg, eap->addr_count > 0 ? eap->line2 : 0L, xchar); *************** *** 6820,6826 **** gui_mch_set_winpos(x, y); else if (gui.starting) { ! /* Remember the coordinates for when the window is opened. */ gui_win_x = x; gui_win_y = y; } --- 6817,6823 ---- gui_mch_set_winpos(x, y); else if (gui.starting) { ! // Remember the coordinates for when the window is opened. gui_win_x = x; gui_win_y = y; } *************** *** 6854,6860 **** oa.line_count = eap->line2 - eap->line1 + 1; oa.motion_type = MLINE; virtual_op = FALSE; ! if (eap->cmdidx != CMD_yank) /* position cursor for undo */ { setpcmark(); curwin->w_cursor.lnum = eap->line1; --- 6851,6857 ---- oa.line_count = eap->line2 - eap->line1 + 1; oa.motion_type = MLINE; virtual_op = FALSE; ! if (eap->cmdidx != CMD_yank) // position cursor for undo { setpcmark(); curwin->w_cursor.lnum = eap->line1; *************** *** 6876,6882 **** (void)op_yank(&oa, FALSE, TRUE); break; ! default: /* CMD_rshift or CMD_lshift */ if ( #ifdef FEAT_RIGHTLEFT (eap->cmdidx == CMD_rshift) ^ curwin->w_p_rl --- 6873,6879 ---- (void)op_yank(&oa, FALSE, TRUE); break; ! default: // CMD_rshift or CMD_lshift if ( #ifdef FEAT_RIGHTLEFT (eap->cmdidx == CMD_rshift) ^ curwin->w_p_rl *************** *** 6900,6906 **** static void ex_put(exarg_T *eap) { ! /* ":0put" works like ":1put!". */ if (eap->line2 == 0) { eap->line2 = 1; --- 6897,6903 ---- static void ex_put(exarg_T *eap) { ! // ":0put" works like ":1put!". if (eap->line2 == 0) { eap->line2 = 1; *************** *** 6920,6926 **** long n; n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1); ! if (eap->arg == NULL) /* error detected */ { eap->nextcmd = NULL; return; --- 6917,6923 ---- long n; n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1); ! if (eap->arg == NULL) // error detected { eap->nextcmd = NULL; return; *************** *** 6984,6990 **** curwin->w_cursor.lnum = eap->line1; if (eap->line1 == eap->line2) { ! if (eap->addr_count >= 2) /* :2,2join does nothing */ return; if (eap->line2 == curbuf->b_ml.ml_line_count) { --- 6981,6987 ---- curwin->w_cursor.lnum = eap->line1; if (eap->line1 == eap->line2) { ! if (eap->addr_count >= 2) // :2,2join does nothing return; if (eap->line2 == curbuf->b_ml.ml_line_count) { *************** *** 7011,7024 **** check_cursor_col(); #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; /* disallow scrolling here */ #endif ! /* get the register name. No name means to use the previous one */ c = *eap->arg; if (c == NUL || (c == '*' && *eap->cmd == '*')) c = '@'; ! /* Put the register in the typeahead buffer with the "silent" flag. */ if (do_execreg(c, TRUE, vim_strchr(p_cpo, CPO_EXECBUF) != NULL, TRUE) == FAIL) { --- 7008,7021 ---- check_cursor_col(); #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; // disallow scrolling here #endif ! // get the register name. No name means to use the previous one c = *eap->arg; if (c == NUL || (c == '*' && *eap->cmd == '*')) c = '@'; ! // Put the register in the typeahead buffer with the "silent" flag. if (do_execreg(c, TRUE, vim_strchr(p_cpo, CPO_EXECBUF) != NULL, TRUE) == FAIL) { *************** *** 7057,7063 **** static void ex_undo(exarg_T *eap) { ! if (eap->addr_count == 1) /* :undo 123 */ undo_time(eap->line2, FALSE, FALSE, TRUE); else u_undo(1); --- 7054,7060 ---- static void ex_undo(exarg_T *eap) { ! if (eap->addr_count == 1) // :undo 123 undo_time(eap->line2, FALSE, FALSE, TRUE); else u_undo(1); *************** *** 7161,7167 **** close_redir(); ! /* Expand environment variables and "~/". */ fname = expand_env_save(arg); if (fname == NULL) return; --- 7158,7164 ---- close_redir(); ! // Expand environment variables and "~/". fname = expand_env_save(arg); if (fname == NULL) return; *************** *** 7175,7184 **** fname, NULL, NULL, (char_u *)_(BROWSE_FILTER_ALL_FILES), curbuf); if (browseFile == NULL) ! return; /* operation cancelled */ vim_free(fname); fname = browseFile; ! eap->forceit = TRUE; /* since dialog already asked */ } #endif --- 7172,7181 ---- fname, NULL, NULL, (char_u *)_(BROWSE_FILTER_ALL_FILES), curbuf); if (browseFile == NULL) ! return; // operation cancelled vim_free(fname); fname = browseFile; ! eap->forceit = TRUE; // since dialog already asked } #endif *************** *** 7188,7194 **** #ifdef FEAT_EVAL else if (*arg == '@') { ! /* redirect to a register a-z (resp. A-Z for appending) */ close_redir(); ++arg; if (ASCII_ISALPHA(*arg) --- 7185,7191 ---- #ifdef FEAT_EVAL else if (*arg == '@') { ! // redirect to a register a-z (resp. A-Z for appending) close_redir(); ++arg; if (ASCII_ISALPHA(*arg) *************** *** 7199,7213 **** || *arg == '"') { redir_reg = *arg++; ! if (*arg == '>' && arg[1] == '>') /* append */ arg += 2; else { ! /* Can use both "@a" and "@a>". */ if (*arg == '>') arg++; ! /* Make register empty when not using @A-@Z and the ! * command is valid. */ if (*arg == NUL && !isupper(redir_reg)) write_reg_contents(redir_reg, (char_u *)"", -1, FALSE); } --- 7196,7210 ---- || *arg == '"') { redir_reg = *arg++; ! if (*arg == '>' && arg[1] == '>') // append arg += 2; else { ! // Can use both "@a" and "@a>". if (*arg == '>') arg++; ! // Make register empty when not using @A-@Z and the ! // command is valid. if (*arg == NUL && !isupper(redir_reg)) write_reg_contents(redir_reg, (char_u *)"", -1, FALSE); } *************** *** 7222,7228 **** { int append; ! /* redirect to a variable */ close_redir(); arg += 2; --- 7219,7225 ---- { int append; ! // redirect to a variable close_redir(); arg += 2; *************** *** 7239,7252 **** } #endif ! /* TODO: redirect to a buffer */ else semsg(_(e_invarg2), eap->arg); } ! /* Make sure redirection is not off. Can happen for cmdline completion ! * that indirectly invokes a command to catch its output. */ if (redir_fd != NULL #ifdef FEAT_EVAL || redir_reg || redir_vname --- 7236,7249 ---- } #endif ! // TODO: redirect to a buffer else semsg(_(e_invarg2), eap->arg); } ! // Make sure redirection is not off. Can happen for cmdline completion ! // that indirectly invokes a command to catch its output. if (redir_fd != NULL #ifdef FEAT_EVAL || redir_reg || redir_vname *************** *** 7282,7292 **** RedrawingDisabled = r; p_lz = p; ! /* Reset msg_didout, so that a message that's there is overwritten. */ msg_didout = FALSE; msg_col = 0; ! /* No need to wait after an intentional redraw. */ need_wait_return = FALSE; out_flush(); --- 7279,7289 ---- RedrawingDisabled = r; p_lz = p; ! // Reset msg_didout, so that a message that's there is overwritten. msg_didout = FALSE; msg_col = 0; ! // No need to wait after an intentional redraw. need_wait_return = FALSE; out_flush(); *************** *** 7371,7382 **** open_exfile( char_u *fname, int forceit, ! char *mode) /* "w" for create new file or "a" for append */ { FILE *fd; #ifdef UNIX ! /* with Unix it is possible to open a directory */ if (mch_isdir(fname)) { semsg(_(e_isadir2), fname); --- 7368,7379 ---- open_exfile( char_u *fname, int forceit, ! char *mode) // "w" for create new file or "a" for append { FILE *fd; #ifdef UNIX ! // with Unix it is possible to open a directory if (mch_isdir(fname)) { semsg(_(e_isadir2), fname); *************** *** 7403,7420 **** { pos_T pos; ! if (*eap->arg == NUL) /* No argument? */ emsg(_(e_argreq)); ! else if (eap->arg[1] != NUL) /* more than one character? */ emsg(_(e_trailing)); else { ! pos = curwin->w_cursor; /* save curwin->w_cursor */ curwin->w_cursor.lnum = eap->line2; beginline(BL_WHITE | BL_FIX); ! if (setmark(*eap->arg) == FAIL) /* set mark */ emsg(_("E191: Argument must be a letter or forward/backward quote")); ! curwin->w_cursor = pos; /* restore curwin->w_cursor */ } } --- 7400,7417 ---- { pos_T pos; ! if (*eap->arg == NUL) // No argument? emsg(_(e_argreq)); ! else if (eap->arg[1] != NUL) // more than one character? emsg(_(e_trailing)); else { ! pos = curwin->w_cursor; // save curwin->w_cursor curwin->w_cursor.lnum = eap->line2; beginline(BL_WHITE | BL_FIX); ! if (setmark(*eap->arg) == FAIL) // set mark emsg(_("E191: Argument must be a letter or forward/backward quote")); ! curwin->w_cursor = pos; // restore curwin->w_cursor } } *************** *** 7424,7430 **** void update_topline_cursor(void) { ! check_cursor(); /* put cursor on valid line */ update_topline(); if (!curwin->w_p_wrap) validate_cursor(); --- 7421,7427 ---- void update_topline_cursor(void) { ! check_cursor(); // put cursor on valid line update_topline(); if (!curwin->w_p_wrap) validate_cursor(); *************** *** 7447,7455 **** sst->save_opcount = opcount; sst->save_reg_executing = reg_executing; ! msg_scroll = FALSE; /* no msg scrolling in Normal mode */ ! restart_edit = 0; /* don't go to Insert mode */ ! p_im = FALSE; /* don't use 'insertmode' */ /* * Save the current typeahead. This is required to allow using ":normal" --- 7444,7452 ---- sst->save_opcount = opcount; sst->save_reg_executing = reg_executing; ! msg_scroll = FALSE; // no msg scrolling in Normal mode ! restart_edit = 0; // don't go to Insert mode ! p_im = FALSE; // don't use 'insertmode' /* * Save the current typeahead. This is required to allow using ":normal" *************** *** 7463,7469 **** void restore_current_state(save_state_T *sst) { ! /* Restore the previous typeahead. */ restore_typeahead(&sst->tabuf); msg_scroll = sst->save_msg_scroll; --- 7460,7466 ---- void restore_current_state(save_state_T *sst) { ! // Restore the previous typeahead. restore_typeahead(&sst->tabuf); msg_scroll = sst->save_msg_scroll; *************** *** 7472,7484 **** finish_op = sst->save_finish_op; opcount = sst->save_opcount; reg_executing = sst->save_reg_executing; ! msg_didout |= sst->save_msg_didout; /* don't reset msg_didout now */ ! /* Restore the state (needed when called from a function executed for ! * 'indentexpr'). Update the mouse and cursor, they may have changed. */ State = sst->save_State; #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may show different cursor shape */ #endif } --- 7469,7481 ---- finish_op = sst->save_finish_op; opcount = sst->save_opcount; reg_executing = sst->save_reg_executing; ! msg_didout |= sst->save_msg_didout; // don't reset msg_didout now ! // Restore the state (needed when called from a function executed for ! // 'indentexpr'). Update the mouse and cursor, they may have changed. State = sst->save_State; #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may show different cursor shape #endif } *************** *** 7513,7527 **** { int len = 0; ! /* Count the number of characters to be escaped. */ for (p = eap->arg; *p != NUL; ++p) { #ifdef FEAT_GUI ! if (*p == CSI) /* leadbyte CSI */ len += 2; #endif for (l = (*mb_ptr2len)(p) - 1; l > 0; --l) ! if (*++p == K_SPECIAL /* trailbyte K_SPECIAL or CSI */ #ifdef FEAT_GUI || *p == CSI #endif --- 7510,7524 ---- { int len = 0; ! // Count the number of characters to be escaped. for (p = eap->arg; *p != NUL; ++p) { #ifdef FEAT_GUI ! if (*p == CSI) // leadbyte CSI len += 2; #endif for (l = (*mb_ptr2len)(p) - 1; l > 0; --l) ! if (*++p == K_SPECIAL // trailbyte K_SPECIAL or CSI #ifdef FEAT_GUI || *p == CSI #endif *************** *** 7590,7603 **** while (eap->addr_count > 0 && eap->line1 <= eap->line2 && !got_int); } ! /* Might not return to the main loop when in an event handler. */ update_topline_cursor(); restore_current_state(&save_state); --ex_normal_busy; setmouse(); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may show different cursor shape */ #endif vim_free(arg); --- 7587,7600 ---- while (eap->addr_count > 0 && eap->line1 <= eap->line2 && !got_int); } ! // Might not return to the main loop when in an event handler. update_topline_cursor(); restore_current_state(&save_state); --ex_normal_busy; setmouse(); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may show different cursor shape #endif vim_free(arg); *************** *** 7655,7661 **** void exec_normal_cmd(char_u *cmd, int remap, int silent) { ! /* Stuff the argument into the typeahead buffer. */ ins_typebuf(cmd, remap, 0, TRUE, silent); exec_normal(FALSE, FALSE, FALSE); } --- 7652,7658 ---- void exec_normal_cmd(char_u *cmd, int remap, int silent) { ! // Stuff the argument into the typeahead buffer. ins_typebuf(cmd, remap, 0, TRUE, silent); exec_normal(FALSE, FALSE, FALSE); } *************** *** 7685,7699 **** && oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) { ! /* If terminal_loop() returns OK we got a key that is handled ! * in Normal model. With FAIL we first need to position the ! * cursor and the screen needs to be redrawn. */ if (terminal_loop(TRUE) == OK) normal_cmd(&oa, TRUE); } else #endif ! /* execute a Normal mode cmd */ normal_cmd(&oa, TRUE); } } --- 7682,7696 ---- && oa.op_type == OP_NOP && oa.regname == NUL && !VIsual_active) { ! // If terminal_loop() returns OK we got a key that is handled ! // in Normal model. With FAIL we first need to position the ! // cursor and the screen needs to be redrawn. if (terminal_loop(TRUE) == OK) normal_cmd(&oa, TRUE); } else #endif ! // execute a Normal mode cmd normal_cmd(&oa, TRUE); } } *************** *** 7730,7759 **** switch (cmdnames[eap->cmdidx].cmd_name[2]) { ! case 'e': /* ":psearch", ":isearch" and ":dsearch" */ if (cmdnames[eap->cmdidx].cmd_name[0] == 'p') action = ACTION_GOTO; else action = ACTION_SHOW; break; ! case 'i': /* ":ilist" and ":dlist" */ action = ACTION_SHOW_ALL; break; ! case 'u': /* ":ijump" and ":djump" */ action = ACTION_GOTO; break; ! default: /* ":isplit" and ":dsplit" */ action = ACTION_SPLIT; break; } n = 1; ! if (vim_isdigit(*eap->arg)) /* get count */ { n = getdigits(&eap->arg); eap->arg = skipwhite(eap->arg); } ! if (*eap->arg == '/') /* Match regexp, not just whole words */ { whole = FALSE; ++eap->arg; --- 7727,7756 ---- switch (cmdnames[eap->cmdidx].cmd_name[2]) { ! case 'e': // ":psearch", ":isearch" and ":dsearch" if (cmdnames[eap->cmdidx].cmd_name[0] == 'p') action = ACTION_GOTO; else action = ACTION_SHOW; break; ! case 'i': // ":ilist" and ":dlist" action = ACTION_SHOW_ALL; break; ! case 'u': // ":ijump" and ":djump" action = ACTION_GOTO; break; ! default: // ":isplit" and ":dsplit" action = ACTION_SPLIT; break; } n = 1; ! if (vim_isdigit(*eap->arg)) // get count { n = getdigits(&eap->arg); eap->arg = skipwhite(eap->arg); } ! if (*eap->arg == '/') // Match regexp, not just whole words { whole = FALSE; ++eap->arg; *************** *** 7763,7769 **** *p++ = NUL; p = skipwhite(p); ! /* Check for trailing illegal characters */ if (!ends_excmd(*p)) eap->errmsg = e_trailing; else --- 7760,7766 ---- *p++ = NUL; p = skipwhite(p); ! // Check for trailing illegal characters if (!ends_excmd(*p)) eap->errmsg = e_trailing; else *************** *** 7786,7792 **** static void ex_ptag(exarg_T *eap) { ! g_do_tagpreview = p_pvh; /* will be reset to 0 in ex_tag_cmd() */ ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name + 1); } --- 7783,7789 ---- static void ex_ptag(exarg_T *eap) { ! g_do_tagpreview = p_pvh; // will be reset to 0 in ex_tag_cmd() ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name + 1); } *************** *** 7853,7876 **** switch (name[1]) { ! case 'j': cmd = DT_JUMP; /* ":tjump" */ break; ! case 's': cmd = DT_SELECT; /* ":tselect" */ break; ! case 'p': cmd = DT_PREV; /* ":tprevious" */ break; ! case 'N': cmd = DT_PREV; /* ":tNext" */ break; ! case 'n': cmd = DT_NEXT; /* ":tnext" */ break; ! case 'o': cmd = DT_POP; /* ":pop" */ break; ! case 'f': /* ":tfirst" */ ! case 'r': cmd = DT_FIRST; /* ":trewind" */ break; ! case 'l': cmd = DT_LAST; /* ":tlast" */ break; ! default: /* ":tag" */ #ifdef FEAT_CSCOPE if (p_cst && *eap->arg != NUL) { --- 7850,7873 ---- switch (name[1]) { ! case 'j': cmd = DT_JUMP; // ":tjump" break; ! case 's': cmd = DT_SELECT; // ":tselect" break; ! case 'p': cmd = DT_PREV; // ":tprevious" break; ! case 'N': cmd = DT_PREV; // ":tNext" break; ! case 'n': cmd = DT_NEXT; // ":tnext" break; ! case 'o': cmd = DT_POP; // ":pop" break; ! case 'f': // ":tfirst" ! case 'r': cmd = DT_FIRST; // ":trewind" break; ! case 'l': cmd = DT_LAST; // ":tlast" break; ! default: // ":tag" #ifdef FEAT_CSCOPE if (p_cst && *eap->arg != NUL) { *************** *** 7911,7935 **** #define SPEC_PERC 0 "#", #define SPEC_HASH (SPEC_PERC + 1) ! "", /* cursor word */ #define SPEC_CWORD (SPEC_HASH + 1) ! "", /* cursor WORD */ #define SPEC_CCWORD (SPEC_CWORD + 1) ! "", /* expr under cursor */ #define SPEC_CEXPR (SPEC_CCWORD + 1) ! "", /* cursor path name */ #define SPEC_CFILE (SPEC_CEXPR + 1) ! "", /* ":so" file name */ #define SPEC_SFILE (SPEC_CFILE + 1) ! "", /* ":so" file line number */ #define SPEC_SLNUM (SPEC_SFILE + 1) ! "", /* autocommand file name */ #define SPEC_AFILE (SPEC_SLNUM + 1) ! "", /* autocommand buffer number */ #define SPEC_ABUF (SPEC_AFILE + 1) ! "", /* autocommand match name */ #define SPEC_AMATCH (SPEC_ABUF + 1) ! "", /* script file line number */ #define SPEC_SFLNUM (SPEC_AMATCH + 1) #ifdef FEAT_CLIENTSERVER "" --- 7908,7932 ---- #define SPEC_PERC 0 "#", #define SPEC_HASH (SPEC_PERC + 1) ! "", // cursor word #define SPEC_CWORD (SPEC_HASH + 1) ! "", // cursor WORD #define SPEC_CCWORD (SPEC_CWORD + 1) ! "", // expr under cursor #define SPEC_CEXPR (SPEC_CCWORD + 1) ! "", // cursor path name #define SPEC_CFILE (SPEC_CEXPR + 1) ! "", // ":so" file name #define SPEC_SFILE (SPEC_CFILE + 1) ! "", // ":so" file line number #define SPEC_SLNUM (SPEC_SFILE + 1) ! "", // autocommand file name #define SPEC_AFILE (SPEC_SLNUM + 1) ! "", // autocommand buffer number #define SPEC_ABUF (SPEC_AFILE + 1) ! "", // autocommand match name #define SPEC_AMATCH (SPEC_ABUF + 1) ! "", // script file line number #define SPEC_SFLNUM (SPEC_AMATCH + 1) #ifdef FEAT_CLIENTSERVER "" *************** *** 7972,7984 **** */ char_u * eval_vars( ! char_u *src, /* pointer into commandline */ ! char_u *srcstart, /* beginning of valid memory for src */ ! int *usedlen, /* characters after src that are used */ ! linenr_T *lnump, /* line number for :e command, or NULL */ ! char **errormsg, /* pointer to error message */ ! int *escaped) /* return value has escaped white space (can ! * be NULL) */ { int i; char_u *s; --- 7969,7981 ---- */ char_u * eval_vars( ! char_u *src, // pointer into commandline ! char_u *srcstart, // beginning of valid memory for src ! int *usedlen, // characters after src that are used ! linenr_T *lnump, // line number for :e command, or NULL ! char **errormsg, // pointer to error message ! int *escaped) // return value has escaped white space (can ! // be NULL) { int i; char_u *s; *************** *** 7986,7992 **** char_u *resultbuf = NULL; int resultlen; buf_T *buf; ! int valid = VALID_HEAD + VALID_PATH; /* assume valid result */ int spec_idx; int tilde_file = FALSE; int skip_mod = FALSE; --- 7983,7989 ---- char_u *resultbuf = NULL; int resultlen; buf_T *buf; ! int valid = VALID_HEAD + VALID_PATH; // assume valid result int spec_idx; int tilde_file = FALSE; int skip_mod = FALSE; *************** *** 8000,8006 **** * Check if there is something to do. */ spec_idx = find_cmdline_var(src, usedlen); ! if (spec_idx < 0) /* no match */ { *usedlen = 1; return NULL; --- 7997,8003 ---- * Check if there is something to do. */ spec_idx = find_cmdline_var(src, usedlen); ! if (spec_idx < 0) // no match { *usedlen = 1; return NULL; *************** *** 8013,8019 **** if (src > srcstart && src[-1] == '\\') { *usedlen = 0; ! STRMOVE(src - 1, src); /* remove backslash */ return NULL; } --- 8010,8016 ---- if (src > srcstart && src[-1] == '\\') { *usedlen = 0; ! STRMOVE(src - 1, src); // remove backslash return NULL; } *************** *** 8045,8055 **** { switch (spec_idx) { ! case SPEC_PERC: /* '%': current file */ if (curbuf->b_fname == NULL) { result = (char_u *)""; ! valid = 0; /* Must have ":p:h" to be valid */ } else { --- 8042,8052 ---- { switch (spec_idx) { ! case SPEC_PERC: // '%': current file if (curbuf->b_fname == NULL) { result = (char_u *)""; ! valid = 0; // Must have ":p:h" to be valid } else { *************** *** 8058,8065 **** } break; ! case SPEC_HASH: /* '#' or "#99": alternate file */ ! if (src[1] == '#') /* "##": the argument list */ { result = arg_all(); resultbuf = result; --- 8055,8062 ---- } break; ! case SPEC_HASH: // '#' or "#99": alternate file ! if (src[1] == '#') // "##": the argument list { result = arg_all(); resultbuf = result; *************** *** 8070,8088 **** break; } s = src + 1; ! if (*s == '<') /* "#<99" uses v:oldfiles */ ++s; i = (int)getdigits(&s); if (s == src + 2 && src[1] == '-') ! /* just a minus sign, don't skip over it */ s--; ! *usedlen = (int)(s - src); /* length of what we expand */ if (src[1] == '<' && i != 0) { if (*usedlen < 2) { ! /* Should we give an error message for #b_fname == NULL) { result = (char_u *)""; ! valid = 0; /* Must have ":p:h" to be valid */ } else { --- 8111,8117 ---- if (buf->b_fname == NULL) { result = (char_u *)""; ! valid = 0; // Must have ":p:h" to be valid } else { *************** *** 8125,8147 **** break; #ifdef FEAT_SEARCHPATH ! case SPEC_CFILE: /* file name under cursor */ result = file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L, NULL); if (result == NULL) { *errormsg = ""; return NULL; } ! resultbuf = result; /* remember allocated string */ break; #endif ! case SPEC_AFILE: /* file name for autocommand */ result = autocmd_fname; if (result != NULL && !autocmd_fname_full) { ! /* Still need to turn the fname into a full path. It is ! * postponed to avoid a delay when is not used. */ autocmd_fname_full = TRUE; result = FullName_save(autocmd_fname, FALSE); vim_free(autocmd_fname); --- 8122,8144 ---- break; #ifdef FEAT_SEARCHPATH ! case SPEC_CFILE: // file name under cursor result = file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L, NULL); if (result == NULL) { *errormsg = ""; return NULL; } ! resultbuf = result; // remember allocated string break; #endif ! case SPEC_AFILE: // file name for autocommand result = autocmd_fname; if (result != NULL && !autocmd_fname_full) { ! // Still need to turn the fname into a full path. It is ! // postponed to avoid a delay when is not used. autocmd_fname_full = TRUE; result = FullName_save(autocmd_fname, FALSE); vim_free(autocmd_fname); *************** *** 8155,8161 **** result = shorten_fname1(result); break; ! case SPEC_ABUF: /* buffer number for autocommand */ if (autocmd_bufnr <= 0) { *errormsg = _("E496: no autocommand buffer number to substitute for \"\""); --- 8152,8158 ---- result = shorten_fname1(result); break; ! case SPEC_ABUF: // buffer number for autocommand if (autocmd_bufnr <= 0) { *errormsg = _("E496: no autocommand buffer number to substitute for \"\""); *************** *** 8165,8171 **** result = strbuf; break; ! case SPEC_AMATCH: /* match name for autocommand */ result = autocmd_match; if (result == NULL) { --- 8162,8168 ---- result = strbuf; break; ! case SPEC_AMATCH: // match name for autocommand result = autocmd_match; if (result == NULL) { *************** *** 8174,8180 **** } break; ! case SPEC_SFILE: /* file name for ":so" command */ result = sourcing_name; if (result == NULL) { --- 8171,8177 ---- } break; ! case SPEC_SFILE: // file name for ":so" command result = sourcing_name; if (result == NULL) { *************** *** 8183,8189 **** } break; ! case SPEC_SLNUM: /* line in file for ":so" command */ if (sourcing_name == NULL || sourcing_lnum == 0) { *errormsg = _("E842: no line number to use for \"\""); --- 8180,8186 ---- } break; ! case SPEC_SLNUM: // line in file for ":so" command if (sourcing_name == NULL || sourcing_lnum == 0) { *errormsg = _("E842: no line number to use for \"\""); *************** *** 8194,8200 **** break; #ifdef FEAT_EVAL ! case SPEC_SFLNUM: /* line in script file */ if (current_sctx.sc_lnum + sourcing_lnum == 0) { *errormsg = _("E961: no line number to use for \"\""); --- 8191,8197 ---- break; #ifdef FEAT_EVAL ! case SPEC_SFLNUM: // line in script file if (current_sctx.sc_lnum + sourcing_lnum == 0) { *errormsg = _("E961: no line number to use for \"\""); *************** *** 8207,8213 **** #endif #ifdef FEAT_CLIENTSERVER ! case SPEC_CLIENT: /* Source of last submitted input */ sprintf((char *)strbuf, PRINTF_HEX_LONG_U, (long_u)clientWindow); result = strbuf; --- 8204,8210 ---- #endif #ifdef FEAT_CLIENTSERVER ! case SPEC_CLIENT: // Source of last submitted input sprintf((char *)strbuf, PRINTF_HEX_LONG_U, (long_u)clientWindow); result = strbuf; *************** *** 8215,8226 **** #endif default: ! result = (char_u *)""; /* avoid gcc warning */ break; } ! resultlen = (int)STRLEN(result); /* length of new string */ ! if (src[*usedlen] == '<') /* remove the file name extension */ { ++*usedlen; if ((s = vim_strrchr(result, '.')) != NULL && s >= gettail(result)) --- 8212,8223 ---- #endif default: ! result = (char_u *)""; // avoid gcc warning break; } ! resultlen = (int)STRLEN(result); // length of new string ! if (src[*usedlen] == '<') // remove the file name extension { ++*usedlen; if ((s = vim_strrchr(result, '.')) != NULL && s >= gettail(result)) *************** *** 8241,8247 **** if (resultlen == 0 || valid != VALID_HEAD + VALID_PATH) { if (valid != VALID_HEAD + VALID_PATH) ! /* xgettext:no-c-format */ *errormsg = _("E499: Empty file name for '%' or '#', only works with \":p:h\""); else *errormsg = _("E500: Evaluates to an empty string"); --- 8238,8244 ---- if (resultlen == 0 || valid != VALID_HEAD + VALID_PATH) { if (valid != VALID_HEAD + VALID_PATH) ! // xgettext:no-c-format *errormsg = _("E499: Empty file name for '%' or '#', only works with \":p:h\""); else *errormsg = _("E500: Evaluates to an empty string"); *************** *** 8279,8285 **** ++p; else { ! /* replace "" with the sourced file name, and do ":" stuff */ repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL); if (errormsg != NULL) { --- 8276,8282 ---- ++p; else { ! // replace "" with the sourced file name, and do ":" stuff repl = eval_vars(p, result, &srclen, NULL, &errormsg, NULL); if (errormsg != NULL) { *************** *** 8288,8294 **** vim_free(result); return NULL; } ! if (repl == NULL) /* no match (cannot happen) */ { p += srclen; continue; --- 8285,8291 ---- vim_free(result); return NULL; } ! if (repl == NULL) // no match (cannot happen) { p += srclen; continue; *************** *** 8308,8314 **** vim_free(repl); vim_free(result); result = newres; ! p = newres + len; /* continue after the match */ } } --- 8305,8311 ---- vim_free(repl); vim_free(result); result = newres; ! p = newres + len; // continue after the match } } *************** *** 8376,8382 **** if (*eap->arg == NUL) { ! /* Print current status. */ smsg("filetype detection:%s plugin:%s indent:%s", filetype_detect ? "ON" : "OFF", filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF", --- 8373,8379 ---- if (*eap->arg == NUL) { ! // Print current status. smsg("filetype detection:%s plugin:%s indent:%s", filetype_detect ? "ON" : "OFF", filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF", *************** *** 8384,8390 **** return; } ! /* Accept "plugin" and "indent" in any order. */ for (;;) { if (STRNCMP(arg, "plugin", 6) == 0) --- 8381,8387 ---- return; } ! // Accept "plugin" and "indent" in any order. for (;;) { if (STRNCMP(arg, "plugin", 6) == 0) *************** *** 8555,8568 **** start_global_changes(); # endif ! /* First set the marks for all lines closed/open. */ for (lnum = eap->line1; lnum <= eap->line2; ++lnum) if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) ml_setmarked(lnum); ! /* Execute the command on the marked lines. */ global_exe(eap->arg); ! ml_clearmarked(); /* clear rest of the marks */ # ifdef FEAT_CLIPBOARD end_global_changes(); # endif --- 8552,8565 ---- start_global_changes(); # endif ! // First set the marks for all lines closed/open. for (lnum = eap->line1; lnum <= eap->line2; ++lnum) if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed)) ml_setmarked(lnum); ! // Execute the command on the marked lines. global_exe(eap->arg); ! ml_clearmarked(); // clear rest of the marks # ifdef FEAT_CLIPBOARD end_global_changes(); # endif *** ../vim-8.1.2378/src/ex_eval.c 2019-11-25 00:04:34.263239656 +0100 --- src/ex_eval.c 2019-12-01 21:29:18.464834815 +0100 *************** *** 52,63 **** * for a variable that is allowed to be changed during execution of a script. */ #if 0 ! /* Expressions used for testing during the development phase. */ # define THROW_ON_ERROR (!eval_to_number("$VIMNOERRTHROW")) # define THROW_ON_INTERRUPT (!eval_to_number("$VIMNOINTTHROW")) # define THROW_TEST #else ! /* Values used for the Vim release. */ # define THROW_ON_ERROR TRUE # define THROW_ON_ERROR_TRUE # define THROW_ON_INTERRUPT TRUE --- 52,63 ---- * for a variable that is allowed to be changed during execution of a script. */ #if 0 ! // Expressions used for testing during the development phase. # define THROW_ON_ERROR (!eval_to_number("$VIMNOERRTHROW")) # define THROW_ON_INTERRUPT (!eval_to_number("$VIMNOINTTHROW")) # define THROW_TEST #else ! // Values used for the Vim release. # define THROW_ON_ERROR TRUE # define THROW_ON_ERROR_TRUE # define THROW_ON_INTERRUPT TRUE *************** *** 127,134 **** int aborted_in_try(void) { ! /* This function is only called after an error. In this case, "force_abort" ! * determines whether searching for finally clauses is necessary. */ return force_abort; } --- 127,134 ---- int aborted_in_try(void) { ! // This function is only called after an error. In this case, "force_abort" ! // determines whether searching for finally clauses is necessary. return force_abort; } *************** *** 215,223 **** */ if (did_throw) { ! /* When discarding an interrupt exception, reset got_int to prevent the ! * same interrupt being converted to an exception again and discarding ! * the error exception we are about to throw here. */ if (current_exception->type == ET_INTERRUPT) got_int = FALSE; discard_current_exception(); --- 215,223 ---- */ if (did_throw) { ! // When discarding an interrupt exception, reset got_int to prevent the ! // same interrupt being converted to an exception again and discarding ! // the error exception we are about to throw here. if (current_exception->type == ET_INTERRUPT) got_int = FALSE; discard_current_exception(); *************** *** 276,282 **** { char *tmsg; ! /* Skip the extra "Vim " prefix for message "E458". */ tmsg = elem->msg; if (STRNCMP(tmsg, "Vim E", 5) == 0 && VIM_ISDIGIT(tmsg[5]) --- 276,282 ---- { char *tmsg; ! // Skip the extra "Vim " prefix for message "E458". tmsg = elem->msg; if (STRNCMP(tmsg, "Vim E", 5) == 0 && VIM_ISDIGIT(tmsg[5]) *************** *** 342,349 **** force_abort = TRUE; } ! /* If no exception is to be thrown or the conversion should be done after ! * returning to a previous invocation of do_one_cmd(), do nothing. */ if (msg_list == NULL || *msg_list == NULL) return; --- 342,349 ---- force_abort = TRUE; } ! // If no exception is to be thrown or the conversion should be done after ! // returning to a previous invocation of do_one_cmd(), do nothing. if (msg_list == NULL || *msg_list == NULL) return; *************** *** 374,380 **** if (!got_int || (trylevel == 0 && !did_throw)) return FALSE; ! #ifdef THROW_TEST /* avoid warning for condition always true */ if (!THROW_ON_INTERRUPT) { /* --- 374,380 ---- if (!got_int || (trylevel == 0 && !did_throw)) return FALSE; ! #ifdef THROW_TEST // avoid warning for condition always true if (!THROW_ON_INTERRUPT) { /* *************** *** 401,407 **** if (current_exception->type == ET_INTERRUPT) return FALSE; ! /* An interrupt exception replaces any user or error exception. */ discard_current_exception(); } if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) != FAIL) --- 401,407 ---- if (current_exception->type == ET_INTERRUPT) return FALSE; ! // An interrupt exception replaces any user or error exception. discard_current_exception(); } if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) != FAIL) *************** *** 449,457 **** val = ret + 4; } ! /* msg_add_fname may have been used to prefix the message with a file ! * name in quotes. In the exception value, put the file name in ! * parentheses and move it to the end. */ for (p = mesg; ; p++) { if (*p == NUL --- 449,457 ---- val = ret + 4; } ! // msg_add_fname may have been used to prefix the message with a file ! // name in quotes. In the exception value, put the file name in ! // parentheses and move it to the end. for (p = mesg; ; p++) { if (*p == NUL *************** *** 464,476 **** && p[4] == ':')))))) { if (*p == NUL || p == mesg) ! STRCAT(val, mesg); /* 'E123' missing or at beginning */ else { ! /* '"filename" E123: message text' */ if (mesg[0] != '"' || p-2 < &mesg[1] || p[-2] != '"' || p[-1] != ' ') ! /* "E123:" is part of the file name. */ continue; STRCAT(val, p); --- 464,476 ---- && p[4] == ':')))))) { if (*p == NUL || p == mesg) ! STRCAT(val, mesg); // 'E123' missing or at beginning else { ! // '"filename" E123: message text' if (mesg[0] != '"' || p-2 < &mesg[1] || p[-2] != '"' || p[-1] != ' ') ! // "E123:" is part of the file name. continue; STRCAT(val, p); *************** *** 525,532 **** goto nomem; if (type == ET_ERROR) ! /* Store the original message and prefix the exception value with ! * "Vim:" or, if a command name is given, "Vim(cmdname):". */ excp->messages = (struct msglist *)value; excp->value = get_exception_string(value, type, cmdname, &should_free); --- 525,532 ---- goto nomem; if (type == ET_ERROR) ! // Store the original message and prefix the exception value with ! // "Vim:" or, if a command name is given, "Vim(cmdname):". excp->messages = (struct msglist *)value; excp->value = get_exception_string(value, type, cmdname, &should_free); *************** *** 549,563 **** int save_msg_silent = msg_silent; if (debug_break_level > 0) ! msg_silent = FALSE; /* display messages */ else verbose_enter(); ++no_wait_return; if (debug_break_level > 0 || *p_vfile == NUL) ! msg_scroll = TRUE; /* always scroll up, don't overwrite */ smsg(_("Exception thrown: %s"), excp->value); ! msg_puts("\n"); /* don't overwrite this either */ if (debug_break_level > 0 || *p_vfile == NUL) cmdline_row = msg_row; --- 549,563 ---- int save_msg_silent = msg_silent; if (debug_break_level > 0) ! msg_silent = FALSE; // display messages else verbose_enter(); ++no_wait_return; if (debug_break_level > 0 || *p_vfile == NUL) ! msg_scroll = TRUE; // always scroll up, don't overwrite smsg(_("Exception thrown: %s"), excp->value); ! msg_puts("\n"); // don't overwrite this either if (debug_break_level > 0 || *p_vfile == NUL) cmdline_row = msg_row; *************** *** 601,617 **** saved_IObuff = vim_strsave(IObuff); if (debug_break_level > 0) ! msg_silent = FALSE; /* display messages */ else verbose_enter(); ++no_wait_return; if (debug_break_level > 0 || *p_vfile == NUL) ! msg_scroll = TRUE; /* always scroll up, don't overwrite */ smsg(was_finished ? _("Exception finished: %s") : _("Exception discarded: %s"), excp->value); ! msg_puts("\n"); /* don't overwrite this either */ if (debug_break_level > 0 || *p_vfile == NUL) cmdline_row = msg_row; --no_wait_return; --- 601,617 ---- saved_IObuff = vim_strsave(IObuff); if (debug_break_level > 0) ! msg_silent = FALSE; // display messages else verbose_enter(); ++no_wait_return; if (debug_break_level > 0 || *p_vfile == NUL) ! msg_scroll = TRUE; // always scroll up, don't overwrite smsg(was_finished ? _("Exception finished: %s") : _("Exception discarded: %s"), excp->value); ! msg_puts("\n"); // don't overwrite this either if (debug_break_level > 0 || *p_vfile == NUL) cmdline_row = msg_row; --no_wait_return; *************** *** 664,670 **** set_vim_var_string(VV_THROWPOINT, IObuff, -1); } else ! /* throw_name not set on an exception from a command that was typed. */ set_vim_var_string(VV_THROWPOINT, NULL, -1); if (p_verbose >= 13 || debug_break_level > 0) --- 664,670 ---- set_vim_var_string(VV_THROWPOINT, IObuff, -1); } else ! // throw_name not set on an exception from a command that was typed. set_vim_var_string(VV_THROWPOINT, NULL, -1); if (p_verbose >= 13 || debug_break_level > 0) *************** *** 672,686 **** int save_msg_silent = msg_silent; if (debug_break_level > 0) ! msg_silent = FALSE; /* display messages */ else verbose_enter(); ++no_wait_return; if (debug_break_level > 0 || *p_vfile == NUL) ! msg_scroll = TRUE; /* always scroll up, don't overwrite */ smsg(_("Exception caught: %s"), excp->value); ! msg_puts("\n"); /* don't overwrite this either */ if (debug_break_level > 0 || *p_vfile == NUL) cmdline_row = msg_row; --- 672,686 ---- int save_msg_silent = msg_silent; if (debug_break_level > 0) ! msg_silent = FALSE; // display messages else verbose_enter(); ++no_wait_return; if (debug_break_level > 0 || *p_vfile == NUL) ! msg_scroll = TRUE; // always scroll up, don't overwrite smsg(_("Exception caught: %s"), excp->value); ! msg_puts("\n"); // don't overwrite this either if (debug_break_level > 0 || *p_vfile == NUL) cmdline_row = msg_row; *************** *** 716,723 **** set_vim_var_string(VV_THROWPOINT, IObuff, -1); } else ! /* throw_name not set on an exception from a command that was ! * typed. */ set_vim_var_string(VV_THROWPOINT, NULL, -1); } else --- 716,723 ---- set_vim_var_string(VV_THROWPOINT, IObuff, -1); } else ! // throw_name not set on an exception from a command that was ! // typed. set_vim_var_string(VV_THROWPOINT, NULL, -1); } else *************** *** 726,732 **** set_vim_var_string(VV_THROWPOINT, NULL, -1); } ! /* Discard the exception, but use the finish message for 'verbose'. */ discard_exception(excp, TRUE); } --- 726,732 ---- set_vim_var_string(VV_THROWPOINT, NULL, -1); } ! // Discard the exception, but use the finish message for 'verbose'. discard_exception(excp, TRUE); } *************** *** 760,766 **** case RP_RESUME: mesg = _("%s resumed"); break; ! /* case RP_DISCARD: */ default: mesg = _("%s discarded"); break; --- 760,766 ---- case RP_RESUME: mesg = _("%s resumed"); break; ! // case RP_DISCARD: default: mesg = _("%s discarded"); break; *************** *** 781,787 **** s = ":finish"; break; case CSTP_RETURN: ! /* ":return" command producing value, allocated */ s = (char *)get_return_cmd(value); break; --- 781,787 ---- s = ":finish"; break; case CSTP_RETURN: ! // ":return" command producing value, allocated s = (char *)get_return_cmd(value); break; *************** *** 797,813 **** s = _("Error and interrupt"); else if (pending & CSTP_ERROR) s = _("Error"); ! else /* if (pending & CSTP_INTERRUPT) */ s = _("Interrupt"); } save_msg_silent = msg_silent; if (debug_break_level > 0) ! msg_silent = FALSE; /* display messages */ ++no_wait_return; ! msg_scroll = TRUE; /* always scroll up, don't overwrite */ smsg(mesg, s); ! msg_puts("\n"); /* don't overwrite this either */ cmdline_row = msg_row; --no_wait_return; if (debug_break_level > 0) --- 797,813 ---- s = _("Error and interrupt"); else if (pending & CSTP_ERROR) s = _("Error"); ! else // if (pending & CSTP_INTERRUPT) s = _("Interrupt"); } save_msg_silent = msg_silent; if (debug_break_level > 0) ! msg_silent = FALSE; // display messages ++no_wait_return; ! msg_scroll = TRUE; // always scroll up, don't overwrite smsg(mesg, s); ! msg_puts("\n"); // don't overwrite this either cmdline_row = msg_row; --no_wait_return; if (debug_break_level > 0) *************** *** 916,922 **** cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE; } else ! /* set TRUE, so this conditional will never get active */ cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; } } --- 916,922 ---- cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE | CSF_TRUE; } else ! // set TRUE, so this conditional will never get active cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; } } *************** *** 992,1003 **** skip = TRUE; } ! /* if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it */ if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE) { if (eap->errmsg == NULL) cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; ! skip = TRUE; /* don't evaluate an ":elseif" */ } else cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE; --- 992,1003 ---- skip = TRUE; } ! // if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE) { if (eap->errmsg == NULL) cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; ! skip = TRUE; // don't evaluate an ":elseif" } else cstack->cs_flags[cstack->cs_idx] = CSF_ACTIVE; *************** *** 1021,1031 **** if (eap->cmdidx == CMD_elseif) { result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip); ! /* When throwing error exceptions, we want to throw always the first ! * of several errors in a row. This is what actually happens when ! * a conditional error was detected above and there is another failure ! * when parsing the expression. Since the skip flag is set in this ! * case, the parsing error will be ignored by emsg(). */ if (!skip && !error) { --- 1021,1031 ---- if (eap->cmdidx == CMD_elseif) { result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip); ! // When throwing error exceptions, we want to throw always the first ! // of several errors in a row. This is what actually happens when ! // a conditional error was detected above and there is another failure ! // when parsing the expression. Since the skip flag is set in this ! // case, the parsing error will be ignored by emsg(). if (!skip && !error) { *************** *** 1035,1041 **** cstack->cs_flags[cstack->cs_idx] = 0; } else if (eap->errmsg == NULL) ! /* set TRUE, so this conditional will never get active */ cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; } else --- 1035,1041 ---- cstack->cs_flags[cstack->cs_idx] = 0; } else if (eap->errmsg == NULL) ! // set TRUE, so this conditional will never get active cstack->cs_flags[cstack->cs_idx] = CSF_TRUE; } else *************** *** 1093,1111 **** */ if ((cstack->cs_lflags & CSL_HAD_LOOP) != 0) { ! /* Jumping here from a ":continue" or ":endfor": use the ! * previously evaluated list. */ fi = cstack->cs_forinfo[cstack->cs_idx]; error = FALSE; } else { ! /* Evaluate the argument and get the info in a structure. */ fi = eval_for_line(eap->arg, &error, &eap->nextcmd, skip); cstack->cs_forinfo[cstack->cs_idx] = fi; } ! /* use the element at the start of the list and advance */ if (!error && fi != NULL && !skip) result = next_for_item(fi, eap->arg); else --- 1093,1111 ---- */ if ((cstack->cs_lflags & CSL_HAD_LOOP) != 0) { ! // Jumping here from a ":continue" or ":endfor": use the ! // previously evaluated list. fi = cstack->cs_forinfo[cstack->cs_idx]; error = FALSE; } else { ! // Evaluate the argument and get the info in a structure. fi = eval_for_line(eap->arg, &error, &eap->nextcmd, skip); cstack->cs_forinfo[cstack->cs_idx] = fi; } ! // use the element at the start of the list and advance if (!error && fi != NULL && !skip) result = next_for_item(fi, eap->arg); else *************** *** 1131,1140 **** else { cstack->cs_lflags &= ~CSL_HAD_LOOP; ! /* If the ":while" evaluates to FALSE or ":for" is past the end of ! * the list, show the debug prompt at the ":endwhile"/":endfor" as ! * if there was a ":break" in a ":while"/":for" evaluating to ! * TRUE. */ if (!skip && !error) cstack->cs_flags[cstack->cs_idx] |= CSF_TRUE; } --- 1131,1140 ---- else { cstack->cs_lflags &= ~CSL_HAD_LOOP; ! // If the ":while" evaluates to FALSE or ":for" is past the end of ! // the list, show the debug prompt at the ":endwhile"/":endfor" as ! // if there was a ":break" in a ":while"/":for" evaluating to ! // TRUE. if (!skip && !error) cstack->cs_flags[cstack->cs_idx] |= CSF_TRUE; } *************** *** 1154,1163 **** eap->errmsg = N_("E586: :continue without :while or :for"); else { ! /* Try to find the matching ":while". This might stop at a try ! * conditional not in its finally clause (which is then to be executed ! * next). Therefor, inactivate all conditionals except the ":while" ! * itself (if reached). */ idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); if (idx >= 0 && (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) { --- 1154,1163 ---- eap->errmsg = N_("E586: :continue without :while or :for"); else { ! // Try to find the matching ":while". This might stop at a try ! // conditional not in its finally clause (which is then to be executed ! // next). Therefor, inactivate all conditionals except the ":while" ! // itself (if reached). idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); if (idx >= 0 && (cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) { *************** *** 1167,1178 **** * Set CSL_HAD_CONT, so do_cmdline() will jump back to the * matching ":while". */ ! cstack->cs_lflags |= CSL_HAD_CONT; /* let do_cmdline() handle it */ } else { ! /* If a try conditional not in its finally clause is reached first, ! * make the ":continue" pending for execution at the ":endtry". */ cstack->cs_pending[idx] = CSTP_CONTINUE; report_make_pending(CSTP_CONTINUE, NULL); } --- 1167,1178 ---- * Set CSL_HAD_CONT, so do_cmdline() will jump back to the * matching ":while". */ ! cstack->cs_lflags |= CSL_HAD_CONT; // let do_cmdline() handle it } else { ! // If a try conditional not in its finally clause is reached first, ! // make the ":continue" pending for execution at the ":endtry". cstack->cs_pending[idx] = CSTP_CONTINUE; report_make_pending(CSTP_CONTINUE, NULL); } *************** *** 1192,1201 **** eap->errmsg = N_("E587: :break without :while or :for"); else { ! /* Inactivate conditionals until the matching ":while" or a try ! * conditional not in its finally clause (which is then to be ! * executed next) is found. In the latter case, make the ":break" ! * pending for execution at the ":endtry". */ idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, TRUE); if (idx >= 0 && !(cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) { --- 1192,1201 ---- eap->errmsg = N_("E587: :break without :while or :for"); else { ! // Inactivate conditionals until the matching ":while" or a try ! // conditional not in its finally clause (which is then to be ! // executed next) is found. In the latter case, make the ":break" ! // pending for execution at the ":endtry". idx = cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, TRUE); if (idx >= 0 && !(cstack->cs_flags[idx] & (CSF_WHILE | CSF_FOR))) { *************** *** 1235,1242 **** fl = cstack->cs_flags[cstack->cs_idx]; if (!(fl & csf)) { ! /* If we are in a ":while" or ":for" but used the wrong endloop ! * command, do not rewind to the next enclosing ":for"/":while". */ if (fl & CSF_WHILE) eap->errmsg = _("E732: Using :endfor with :while"); else if (fl & CSF_FOR) --- 1235,1242 ---- fl = cstack->cs_flags[cstack->cs_idx]; if (!(fl & csf)) { ! // If we are in a ":while" or ":for" but used the wrong endloop ! // command, do not rewind to the next enclosing ":for"/":while". if (fl & CSF_WHILE) eap->errmsg = _("E732: Using :endfor with :while"); else if (fl & CSF_FOR) *************** *** 1248,1268 **** eap->errmsg = e_endif; else if (fl & CSF_FINALLY) eap->errmsg = e_endtry; ! /* Try to find the matching ":while" and report what's missing. */ for (idx = cstack->cs_idx; idx > 0; --idx) { fl = cstack->cs_flags[idx]; if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) { ! /* Give up at a try conditional not in its finally clause. ! * Ignore the ":endwhile"/":endfor". */ eap->errmsg = err; return; } if (fl & csf) break; } ! /* Cleanup and rewind all contained (and unclosed) conditionals. */ (void)cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel); } --- 1248,1268 ---- eap->errmsg = e_endif; else if (fl & CSF_FINALLY) eap->errmsg = e_endtry; ! // Try to find the matching ":while" and report what's missing. for (idx = cstack->cs_idx; idx > 0; --idx) { fl = cstack->cs_flags[idx]; if ((fl & CSF_TRY) && !(fl & CSF_FINALLY)) { ! // Give up at a try conditional not in its finally clause. ! // Ignore the ":endwhile"/":endfor". eap->errmsg = err; return; } if (fl & csf) break; } ! // Cleanup and rewind all contained (and unclosed) conditionals. (void)cleanup_conditionals(cstack, CSF_WHILE | CSF_FOR, FALSE); rewind_conditionals(cstack, idx, CSF_TRY, &cstack->cs_trylevel); } *************** *** 1308,1315 **** value = NULL; } ! /* On error or when an exception is thrown during argument evaluation, do ! * not throw. */ if (!eap->skip && value != NULL) { if (throw_exception(value, ET_USER, NULL) == FAIL) --- 1308,1315 ---- value = NULL; } ! // On error or when an exception is thrown during argument evaluation, do ! // not throw. if (!eap->skip && value != NULL) { if (throw_exception(value, ET_USER, NULL) == FAIL) *************** *** 1374,1390 **** if (cstack->cs_flags[idx] & CSF_ACTIVE) cstack->cs_flags[idx] |= CSF_THROWN; else ! /* THROWN may have already been set for a catchable exception ! * that has been discarded. Ensure it is reset for the new ! * exception. */ cstack->cs_flags[idx] &= ~CSF_THROWN; } cstack->cs_flags[idx] &= ~CSF_ACTIVE; cstack->cs_exception[idx] = current_exception; } #if 0 ! /* TODO: Add optimization below. Not yet done because of interface ! * problems to eval.c and ex_cmds2.c. (Servatius) */ else { /* --- 1374,1390 ---- if (cstack->cs_flags[idx] & CSF_ACTIVE) cstack->cs_flags[idx] |= CSF_THROWN; else ! // THROWN may have already been set for a catchable exception ! // that has been discarded. Ensure it is reset for the new ! // exception. cstack->cs_flags[idx] &= ~CSF_THROWN; } cstack->cs_flags[idx] &= ~CSF_ACTIVE; cstack->cs_exception[idx] = current_exception; } #if 0 ! // TODO: Add optimization below. Not yet done because of interface ! // problems to eval.c and ex_cmds2.c. (Servatius) else { /* *************** *** 1429,1437 **** if (!skip) { ! /* Set ACTIVE and TRUE. TRUE means that the corresponding ":catch" ! * commands should check for a match if an exception is thrown and ! * that the finally clause needs to be executed. */ cstack->cs_flags[cstack->cs_idx] |= CSF_ACTIVE | CSF_TRUE; /* --- 1429,1437 ---- if (!skip) { ! // Set ACTIVE and TRUE. TRUE means that the corresponding ":catch" ! // commands should check for a match if an exception is thrown and ! // that the finally clause needs to be executed. cstack->cs_flags[cstack->cs_idx] |= CSF_ACTIVE | CSF_TRUE; /* *************** *** 1498,1505 **** { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { ! /* Report what's missing if the matching ":try" is not in its ! * finally clause. */ eap->errmsg = get_end_emsg(cstack); skip = TRUE; } --- 1498,1505 ---- { if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { ! // Report what's missing if the matching ":try" is not in its ! // finally clause. eap->errmsg = get_end_emsg(cstack); skip = TRUE; } *************** *** 1508,1515 **** break; if (cstack->cs_flags[idx] & CSF_FINALLY) { ! /* Give up for a ":catch" after ":finally" and ignore it. ! * Just parse. */ eap->errmsg = N_("E604: :catch after :finally"); give_up = TRUE; } --- 1508,1515 ---- break; if (cstack->cs_flags[idx] & CSF_FINALLY) { ! // Give up for a ":catch" after ":finally" and ignore it. ! // Just parse. eap->errmsg = N_("E604: :catch after :finally"); give_up = TRUE; } *************** *** 1518,1524 **** &cstack->cs_looplevel); } ! if (ends_excmd(*eap->arg)) /* no argument, catch all errors */ { pat = (char_u *)".*"; end = NULL; --- 1518,1524 ---- &cstack->cs_looplevel); } ! if (ends_excmd(*eap->arg)) // no argument, catch all errors { pat = (char_u *)".*"; end = NULL; *************** *** 1554,1570 **** return; } ! /* When debugging or a breakpoint was encountered, display the ! * debug prompt (if not already done) before checking for a match. ! * This is a helpful hint for the user when the regular expression ! * matching fails. Handle a ">quit" debug command as if an ! * interrupt had occurred before the ":catch". That is, discard ! * the original exception, replace it by an interrupt exception, ! * and don't catch it in this try block. */ if (!dbg_check_skipped(eap) || !do_intthrow(cstack)) { ! /* Terminate the pattern and avoid the 'l' flag in 'cpoptions' ! * while compiling it. */ if (end != NULL) { save_char = *end; --- 1554,1570 ---- return; } ! // When debugging or a breakpoint was encountered, display the ! // debug prompt (if not already done) before checking for a match. ! // This is a helpful hint for the user when the regular expression ! // matching fails. Handle a ">quit" debug command as if an ! // interrupt had occurred before the ":catch". That is, discard ! // the original exception, replace it by an interrupt exception, ! // and don't catch it in this try block. if (!dbg_check_skipped(eap) || !do_intthrow(cstack)) { ! // Terminate the pattern and avoid the 'l' flag in 'cpoptions' ! // while compiling it. if (end != NULL) { save_char = *end; *************** *** 1572,1579 **** } save_cpo = p_cpo; p_cpo = (char_u *)""; ! /* Disable error messages, it will make current_exception ! * invalid. */ ++emsg_off; regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); --emsg_off; --- 1572,1579 ---- } save_cpo = p_cpo; p_cpo = (char_u *)""; ! // Disable error messages, it will make current_exception ! // invalid. ++emsg_off; regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); --emsg_off; *************** *** 1602,1617 **** if (caught) { ! /* Make this ":catch" clause active and reset did_emsg, got_int, ! * and did_throw. Put the exception on the caught stack. */ cstack->cs_flags[idx] |= CSF_ACTIVE | CSF_CAUGHT; did_emsg = got_int = did_throw = FALSE; catch_exception((except_T *)cstack->cs_exception[idx]); ! /* It's mandatory that the current exception is stored in the cstack ! * so that it can be discarded at the next ":catch", ":finally", or ! * ":endtry" or when the catch clause is left by a ":continue", ! * ":break", ":return", ":finish", error, interrupt, or another ! * exception. */ if (cstack->cs_exception[cstack->cs_idx] != current_exception) internal_error("ex_catch()"); } --- 1602,1617 ---- if (caught) { ! // Make this ":catch" clause active and reset did_emsg, got_int, ! // and did_throw. Put the exception on the caught stack. cstack->cs_flags[idx] |= CSF_ACTIVE | CSF_CAUGHT; did_emsg = got_int = did_throw = FALSE; catch_exception((except_T *)cstack->cs_exception[idx]); ! // It's mandatory that the current exception is stored in the cstack ! // so that it can be discarded at the next ":catch", ":finally", or ! // ":endtry" or when the catch clause is left by a ":continue", ! // ":break", ":return", ":finish", error, interrupt, or another ! // exception. if (cstack->cs_exception[cstack->cs_idx] != current_exception) internal_error("ex_catch()"); } *************** *** 1656,1664 **** for (idx = cstack->cs_idx - 1; idx > 0; --idx) if (cstack->cs_flags[idx] & CSF_TRY) break; ! /* Make this error pending, so that the commands in the following ! * finally clause can be executed. This overrules also a pending ! * ":continue", ":break", ":return", or ":finish". */ pending = CSTP_ERROR; } else --- 1656,1664 ---- for (idx = cstack->cs_idx - 1; idx > 0; --idx) if (cstack->cs_flags[idx] & CSF_TRY) break; ! // Make this error pending, so that the commands in the following ! // finally clause can be executed. This overrules also a pending ! // ":continue", ":break", ":return", or ":finish". pending = CSTP_ERROR; } else *************** *** 1666,1672 **** if (cstack->cs_flags[idx] & CSF_FINALLY) { ! /* Give up for a multiple ":finally" and ignore it. */ eap->errmsg = N_("E607: multiple :finally"); return; } --- 1666,1672 ---- if (cstack->cs_flags[idx] & CSF_FINALLY) { ! // Give up for a multiple ":finally" and ignore it. eap->errmsg = N_("E607: multiple :finally"); return; } *************** *** 1685,1699 **** if (!skip) { ! /* When debugging or a breakpoint was encountered, display the ! * debug prompt (if not already done). The user then knows that the ! * finally clause is executed. */ if (dbg_check_skipped(eap)) { ! /* Handle a ">quit" debug command as if an interrupt had ! * occurred before the ":finally". That is, discard the ! * original exception and replace it by an interrupt ! * exception. */ (void)do_intthrow(cstack); } --- 1685,1699 ---- if (!skip) { ! // When debugging or a breakpoint was encountered, display the ! // debug prompt (if not already done). The user then knows that the ! // finally clause is executed. if (dbg_check_skipped(eap)) { ! // Handle a ">quit" debug command as if an interrupt had ! // occurred before the ":finally". That is, discard the ! // original exception and replace it by an interrupt ! // exception. (void)do_intthrow(cstack); } *************** *** 1738,1750 **** pending |= got_int ? CSTP_INTERRUPT : 0; cstack->cs_pending[cstack->cs_idx] = pending; ! /* It's mandatory that the current exception is stored in the ! * cstack so that it can be rethrown at the ":endtry" or be ! * discarded if the finally clause is left by a ":continue", ! * ":break", ":return", ":finish", error, interrupt, or another ! * exception. When emsg() is called for a missing ":endif" or ! * a missing ":endwhile"/":endfor" detected here, the ! * exception will be discarded. */ if (did_throw && cstack->cs_exception[cstack->cs_idx] != current_exception) internal_error("ex_finally()"); --- 1738,1750 ---- pending |= got_int ? CSTP_INTERRUPT : 0; cstack->cs_pending[cstack->cs_idx] = pending; ! // It's mandatory that the current exception is stored in the ! // cstack so that it can be rethrown at the ":endtry" or be ! // discarded if the finally clause is left by a ":continue", ! // ":break", ":return", ":finish", error, interrupt, or another ! // exception. When emsg() is called for a missing ":endif" or ! // a missing ":endwhile"/":endfor" detected here, the ! // exception will be discarded. if (did_throw && cstack->cs_exception[cstack->cs_idx] != current_exception) internal_error("ex_finally()"); *************** *** 1796,1802 **** if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { eap->errmsg = get_end_emsg(cstack); ! /* Find the matching ":try" and report what's missing. */ idx = cstack->cs_idx; do --idx; --- 1796,1802 ---- if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) { eap->errmsg = get_end_emsg(cstack); ! // Find the matching ":try" and report what's missing. idx = cstack->cs_idx; do --idx; *************** *** 1830,1857 **** rethrow = TRUE; } ! /* If there was no finally clause, show the user when debugging or ! * a breakpoint was encountered that the end of the try conditional has ! * been reached: display the debug prompt (if not already done). Do ! * this on normal control flow or when an exception was thrown, but not ! * on an interrupt or error not converted to an exception or when ! * a ":break", ":continue", ":return", or ":finish" is pending. These ! * actions are carried out immediately. ! */ if ((rethrow || (!skip && !(cstack->cs_flags[idx] & CSF_FINALLY) && !cstack->cs_pending[idx])) && dbg_check_skipped(eap)) { ! /* Handle a ">quit" debug command as if an interrupt had occurred ! * before the ":endtry". That is, throw an interrupt exception and ! * set "skip" and "rethrow". */ if (got_int) { skip = TRUE; (void)do_intthrow(cstack); ! /* The do_intthrow() call may have reset did_throw or ! * cstack->cs_pending[idx].*/ rethrow = FALSE; if (did_throw && !(cstack->cs_flags[idx] & CSF_FINALLY)) rethrow = TRUE; --- 1830,1856 ---- rethrow = TRUE; } ! // If there was no finally clause, show the user when debugging or ! // a breakpoint was encountered that the end of the try conditional has ! // been reached: display the debug prompt (if not already done). Do ! // this on normal control flow or when an exception was thrown, but not ! // on an interrupt or error not converted to an exception or when ! // a ":break", ":continue", ":return", or ":finish" is pending. These ! // actions are carried out immediately. if ((rethrow || (!skip && !(cstack->cs_flags[idx] & CSF_FINALLY) && !cstack->cs_pending[idx])) && dbg_check_skipped(eap)) { ! // Handle a ">quit" debug command as if an interrupt had occurred ! // before the ":endtry". That is, throw an interrupt exception and ! // set "skip" and "rethrow". if (got_int) { skip = TRUE; (void)do_intthrow(cstack); ! // The do_intthrow() call may have reset did_throw or ! // cstack->cs_pending[idx]. rethrow = FALSE; if (did_throw && !(cstack->cs_flags[idx] & CSF_FINALLY)) rethrow = TRUE; *************** *** 1899,1911 **** case CSTP_NONE: break; ! /* Reactivate a pending ":continue", ":break", ":return", ! * ":finish" from the try block or a catch clause of this try ! * conditional. This is skipped, if there was an error in an ! * (unskipped) conditional command or an interrupt afterwards ! * or if the finally clause is present and executed a new error, ! * interrupt, throw, ":continue", ":break", ":return", or ! * ":finish". */ case CSTP_CONTINUE: ex_continue(eap); break; --- 1898,1910 ---- case CSTP_NONE: break; ! // Reactivate a pending ":continue", ":break", ":return", ! // ":finish" from the try block or a catch clause of this try ! // conditional. This is skipped, if there was an error in an ! // (unskipped) conditional command or an interrupt afterwards ! // or if the finally clause is present and executed a new error, ! // interrupt, throw, ":continue", ":break", ":return", or ! // ":finish". case CSTP_CONTINUE: ex_continue(eap); break; *************** *** 1919,1930 **** do_finish(eap, FALSE); break; ! /* When the finally clause was entered due to an error, ! * interrupt or throw (as opposed to a ":continue", ":break", ! * ":return", or ":finish"), restore the pending values of ! * did_emsg, got_int, and did_throw. This is skipped, if there ! * was a new error, interrupt, throw, ":continue", ":break", ! * ":return", or ":finish". in the finally clause. */ default: if (pending & CSTP_ERROR) did_emsg = TRUE; --- 1918,1929 ---- do_finish(eap, FALSE); break; ! // When the finally clause was entered due to an error, ! // interrupt or throw (as opposed to a ":continue", ":break", ! // ":return", or ":finish"), restore the pending values of ! // did_emsg, got_int, and did_throw. This is skipped, if there ! // was a new error, interrupt, throw, ":continue", ":break", ! // ":return", or ":finish". in the finally clause. default: if (pending & CSTP_ERROR) did_emsg = TRUE; *************** *** 1937,1943 **** } if (rethrow) ! /* Rethrow the current exception (within this cstack). */ do_throw(cstack); } } --- 1936,1942 ---- } if (rethrow) ! // Rethrow the current exception (within this cstack). do_throw(cstack); } } *************** *** 1980,1992 **** | (did_throw ? CSTP_THROW : 0) | (need_rethrow ? CSTP_THROW : 0); ! /* If we are currently throwing an exception (did_throw), save it as ! * well. On an error not yet converted to an exception, update ! * "force_abort" and reset "cause_abort" (as do_errthrow() would do). ! * This is needed for the do_cmdline() call that is going to be made ! * for autocommand execution. We need not save *msg_list because ! * there is an extra instance for every call of do_cmdline(), anyway. ! */ if (did_throw || need_rethrow) { csp->exception = current_exception; --- 1979,1990 ---- | (did_throw ? CSTP_THROW : 0) | (need_rethrow ? CSTP_THROW : 0); ! // If we are currently throwing an exception (did_throw), save it as ! // well. On an error not yet converted to an exception, update ! // "force_abort" and reset "cause_abort" (as do_errthrow() would do). ! // This is needed for the do_cmdline() call that is going to be made ! // for autocommand execution. We need not save *msg_list because ! // there is an extra instance for every call of do_cmdline(), anyway. if (did_throw || need_rethrow) { csp->exception = current_exception; *************** *** 2003,2009 **** } did_emsg = got_int = did_throw = need_rethrow = FALSE; ! /* Report if required by the 'verbose' option or when debugging. */ report_make_pending(pending, csp->exception); } else --- 2001,2007 ---- } did_emsg = got_int = did_throw = need_rethrow = FALSE; ! // Report if required by the 'verbose' option or when debugging. report_make_pending(pending, csp->exception); } else *************** *** 2033,2055 **** { int pending = csp->pending; ! if (pending == CSTP_NONE) /* nothing to do */ return; ! /* If there was an aborting error, an interrupt, or an uncaught exception ! * after the corresponding call to enter_cleanup(), discard what has been ! * made pending by it. Report this to the user if required by the ! * 'verbose' option or when debugging. */ if (aborting() || need_rethrow) { if (pending & CSTP_THROW) ! /* Cancel the pending exception (includes report). */ discard_exception((except_T *)csp->exception, FALSE); else report_discard_pending(pending, NULL); ! /* If an error was about to be converted to an exception when ! * enter_cleanup() was called, free the message list. */ if (msg_list != NULL) free_global_msglist(); } --- 2031,2053 ---- { int pending = csp->pending; ! if (pending == CSTP_NONE) // nothing to do return; ! // If there was an aborting error, an interrupt, or an uncaught exception ! // after the corresponding call to enter_cleanup(), discard what has been ! // made pending by it. Report this to the user if required by the ! // 'verbose' option or when debugging. if (aborting() || need_rethrow) { if (pending & CSTP_THROW) ! // Cancel the pending exception (includes report). discard_exception((except_T *)csp->exception, FALSE); else report_discard_pending(pending, NULL); ! // If an error was about to be converted to an exception when ! // enter_cleanup() was called, free the message list. if (msg_list != NULL) free_global_msglist(); } *************** *** 2088,2096 **** if (pending & CSTP_INTERRUPT) got_int = TRUE; if (pending & CSTP_THROW) ! need_rethrow = TRUE; /* did_throw will be set by do_one_cmd() */ ! /* Report if required by the 'verbose' option or when debugging. */ report_resume_pending(pending, (pending & CSTP_THROW) ? (void *)current_exception : NULL); } --- 2086,2094 ---- if (pending & CSTP_INTERRUPT) got_int = TRUE; if (pending & CSTP_THROW) ! need_rethrow = TRUE; // did_throw will be set by do_one_cmd() ! // Report if required by the 'verbose' option or when debugging. report_resume_pending(pending, (pending & CSTP_THROW) ? (void *)current_exception : NULL); } *************** *** 2158,2166 **** { if (cstack->cs_pending[idx] & CSTP_THROW) { ! /* Cancel the pending exception. This is in the ! * finally clause, so that the stack of the ! * caught exceptions is not involved. */ discard_exception((except_T *) cstack->cs_exception[idx], FALSE); --- 2156,2164 ---- { if (cstack->cs_pending[idx] & CSTP_THROW) { ! // Cancel the pending exception. This is in the ! // finally clause, so that the stack of the ! // caught exceptions is not involved. discard_exception((except_T *) cstack->cs_exception[idx], FALSE); *************** *** 2184,2193 **** if ((cstack->cs_flags[idx] & CSF_ACTIVE) && (cstack->cs_flags[idx] & CSF_CAUGHT)) finish_exception((except_T *)cstack->cs_exception[idx]); ! /* Stop at this try conditional - except the try block never ! * got active (because of an inactive surrounding conditional ! * or when the ":try" appeared after an error or interrupt or ! * throw). */ if (cstack->cs_flags[idx] & CSF_TRUE) { if (searched_cond == 0 && !inclusive) --- 2182,2191 ---- if ((cstack->cs_flags[idx] & CSF_ACTIVE) && (cstack->cs_flags[idx] & CSF_CAUGHT)) finish_exception((except_T *)cstack->cs_exception[idx]); ! // Stop at this try conditional - except the try block never ! // got active (because of an inactive surrounding conditional ! // or when the ":try" appeared after an error or interrupt or ! // throw). if (cstack->cs_flags[idx] & CSF_TRUE) { if (searched_cond == 0 && !inclusive) *************** *** 2197,2206 **** } } ! /* Stop on the searched conditional type (even when the surrounding ! * conditional is not active or something has been made pending). ! * If "inclusive" is TRUE and "searched_cond" is CSF_TRY|CSF_SILENT, ! * check first whether "emsg_silent" needs to be restored. */ if (cstack->cs_flags[idx] & searched_cond) { if (!inclusive) --- 2195,2204 ---- } } ! // Stop on the searched conditional type (even when the surrounding ! // conditional is not active or something has been made pending). ! // If "inclusive" is TRUE and "searched_cond" is CSF_TRY|CSF_SILENT, ! // check first whether "emsg_silent" needs to be restored. if (cstack->cs_flags[idx] & searched_cond) { if (!inclusive) *************** *** 2288,2294 **** { int len; ! /* skip modifiers, white space and ':' */ for (;;) { while (*p == ' ' || *p == '\t' || *p == ':') --- 2286,2292 ---- { int len; ! // skip modifiers, white space and ':' for (;;) { while (*p == ' ' || *p == '\t' || *p == ':') *************** *** 2304,2307 **** return FALSE; } ! #endif /* FEAT_EVAL */ --- 2302,2305 ---- return FALSE; } ! #endif // FEAT_EVAL *** ../vim-8.1.2378/src/ex_getln.c 2019-11-26 19:33:03.458605263 +0100 --- src/ex_getln.c 2019-12-01 21:31:47.912219064 +0100 *************** *** 23,37 **** static cmdline_info_T ccline; #ifdef FEAT_EVAL ! static int new_cmdpos; /* position set by set_cmdline_pos() */ #endif ! static int extra_char = NUL; /* extra character to display when redrawing ! * the command line */ static int extra_char_shift; #ifdef FEAT_RIGHTLEFT ! static int cmd_hkmap = 0; /* Hebrew mapping during command line */ #endif static char_u *getcmdline_int(int firstc, long count, int indent, int init_ccline); --- 23,37 ---- static cmdline_info_T ccline; #ifdef FEAT_EVAL ! static int new_cmdpos; // position set by set_cmdline_pos() #endif ! static int extra_char = NUL; // extra character to display when redrawing ! // the command line static int extra_char_shift; #ifdef FEAT_RIGHTLEFT ! static int cmd_hkmap = 0; // Hebrew mapping during command line #endif static char_u *getcmdline_int(int firstc, long count, int indent, int init_ccline); *************** *** 90,96 **** { size_t n = STRLEN(p); ! /* remove trailing \v and the like */ while (n >= 2 && p[n - 2] == '\\' && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) n -= 2; --- 90,96 ---- { size_t n = STRLEN(p); ! // remove trailing \v and the like while (n >= 2 && p[n - 2] == '\\' && vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL) n -= 2; *************** *** 359,365 **** p_magic = is_state->magic_save; ! validate_cursor(); /* needed for TAB */ redraw_all_later(SOME_VALID); if (call_update_screen) update_screen(SOME_VALID); --- 359,365 ---- p_magic = is_state->magic_save; ! validate_cursor(); // needed for TAB redraw_all_later(SOME_VALID); if (call_update_screen) update_screen(SOME_VALID); *************** *** 794,815 **** int c; int i; int j; ! int gotesc = FALSE; /* TRUE when just typed */ ! int do_abbr; /* when TRUE check for abbr. */ ! char_u *lookfor = NULL; /* string to match */ ! int hiscnt; /* current history line in use */ ! int histype; /* history type to be used */ #ifdef FEAT_SEARCH_EXTRA incsearch_state_T is_state; #endif ! int did_wild_list = FALSE; /* did wild_list() recently */ ! int wim_index = 0; /* index in wim_flags[] */ int res; int save_msg_scroll = msg_scroll; ! int save_State = State; /* remember State when called */ ! int some_key_typed = FALSE; /* one of the keys was typed */ ! /* mouse drag and release events are ignored, unless they are ! * preceded with a mouse down event */ int ignore_drag_release = TRUE; #ifdef FEAT_EVAL int break_ctrl_c = FALSE; --- 794,815 ---- int c; int i; int j; ! int gotesc = FALSE; // TRUE when just typed ! int do_abbr; // when TRUE check for abbr. ! char_u *lookfor = NULL; // string to match ! int hiscnt; // current history line in use ! int histype; // history type to be used #ifdef FEAT_SEARCH_EXTRA incsearch_state_T is_state; #endif ! int did_wild_list = FALSE; // did wild_list() recently ! int wim_index = 0; // index in wim_flags[] int res; int save_msg_scroll = msg_scroll; ! int save_State = State; // remember State when called ! int some_key_typed = FALSE; // one of the keys was typed ! // mouse drag and release events are ignored, unless they are ! // preceded with a mouse down event int ignore_drag_release = TRUE; #ifdef FEAT_EVAL int break_ctrl_c = FALSE; *************** *** 838,849 **** } #endif #ifdef FEAT_RIGHTLEFT ! /* start without Hebrew mapping for a command line */ if (firstc == ':' || firstc == '=' || firstc == '>') cmd_hkmap = 0; #endif ! ccline.overstrike = FALSE; /* always start in insert mode */ #ifdef FEAT_SEARCH_EXTRA init_incsearch_state(&is_state); --- 838,849 ---- } #endif #ifdef FEAT_RIGHTLEFT ! // start without Hebrew mapping for a command line if (firstc == ':' || firstc == '=' || firstc == '>') cmd_hkmap = 0; #endif ! ccline.overstrike = FALSE; // always start in insert mode #ifdef FEAT_SEARCH_EXTRA init_incsearch_state(&is_state); *************** *** 855,861 **** ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); ccline.cmdindent = (firstc > 0 ? indent : 0); ! /* alloc initial ccline.cmdbuff */ alloc_cmdbuff(exmode_active ? 250 : indent + 1); if (ccline.cmdbuff == NULL) goto theend; // out of memory --- 855,861 ---- ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); ccline.cmdindent = (firstc > 0 ? indent : 0); ! // alloc initial ccline.cmdbuff alloc_cmdbuff(exmode_active ? 250 : indent + 1); if (ccline.cmdbuff == NULL) goto theend; // out of memory *************** *** 863,869 **** ccline.cmdbuff[0] = NUL; sb_text_start_cmdline(); ! /* autoindent for :insert and :append */ if (firstc <= 0) { vim_memset(ccline.cmdbuff, ' ', indent); --- 863,869 ---- ccline.cmdbuff[0] = NUL; sb_text_start_cmdline(); ! // autoindent for :insert and :append if (firstc <= 0) { vim_memset(ccline.cmdbuff, ' ', indent); *************** *** 884,897 **** cmdmsg_rl = FALSE; #endif ! redir_off = TRUE; /* don't redirect the typed command */ if (!cmd_silent) { i = msg_scrolled; ! msg_scrolled = 0; /* avoid wait_return message */ gotocmdline(TRUE); msg_scrolled += i; ! redrawcmdprompt(); /* draw prompt or indent */ set_cmdspos(); } xpc.xp_context = EXPAND_NOTHING; --- 884,897 ---- cmdmsg_rl = FALSE; #endif ! redir_off = TRUE; // don't redirect the typed command if (!cmd_silent) { i = msg_scrolled; ! msg_scrolled = 0; // avoid wait_return message gotocmdline(TRUE); msg_scrolled += i; ! redrawcmdprompt(); // draw prompt or indent set_cmdspos(); } xpc.xp_context = EXPAND_NOTHING; *************** *** 919,925 **** if (firstc == '/' || firstc == '?' || firstc == '@') { ! /* Use ":lmap" mappings for search pattern and input(). */ if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) b_im_ptr = &curbuf->b_p_iminsert; else --- 919,925 ---- if (firstc == '/' || firstc == '?' || firstc == '@') { ! // Use ":lmap" mappings for search pattern and input(). if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT) b_im_ptr = &curbuf->b_p_iminsert; else *************** *** 937,963 **** setmouse(); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may show different cursor shape */ #endif ! /* When inside an autocommand for writing "exiting" may be set and ! * terminal mode set to cooked. Need to set raw mode here then. */ settmode(TMODE_RAW); ! /* Trigger CmdlineEnter autocommands. */ cmdline_type = firstc == NUL ? '-' : firstc; trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINEENTER); init_history(); ! hiscnt = get_hislen(); /* set hiscnt to impossible history value */ histype = hist_char2type(firstc); #ifdef FEAT_DIGRAPHS ! do_digraph(-1); /* init digraph typeahead */ #endif ! /* If something above caused an error, reset the flags, we do want to type ! * and execute commands. Display may be messed up a bit. */ if (did_emsg) redrawcmd(); did_emsg = FALSE; --- 937,963 ---- setmouse(); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may show different cursor shape #endif ! // When inside an autocommand for writing "exiting" may be set and ! // terminal mode set to cooked. Need to set raw mode here then. settmode(TMODE_RAW); ! // Trigger CmdlineEnter autocommands. cmdline_type = firstc == NUL ? '-' : firstc; trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINEENTER); init_history(); ! hiscnt = get_hislen(); // set hiscnt to impossible history value histype = hist_char2type(firstc); #ifdef FEAT_DIGRAPHS ! do_digraph(-1); // init digraph typeahead #endif ! // If something above caused an error, reset the flags, we do want to type ! // and execute commands. Display may be messed up a bit. if (did_emsg) redrawcmd(); did_emsg = FALSE; *************** *** 968,992 **** */ for (;;) { ! redir_off = TRUE; /* Don't redirect the typed command. ! Repeated, because a ":redir" inside ! completion may switch it on. */ #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; /* allow scrolling here */ #endif ! quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */ ! did_emsg = FALSE; /* There can't really be a reason why an error ! that occurs while typing a command should ! cause the command not to be executed. */ // Trigger SafeState if nothing is pending. may_trigger_safestate(xpc.xp_numfiles <= 0); ! cursorcmd(); /* set the cursor on the right spot */ ! /* Get a character. Ignore K_IGNORE and K_NOP, they should not do ! * anything, such as stop completion. */ do c = safe_vgetc(); while (c == K_IGNORE || c == K_NOP); --- 968,992 ---- */ for (;;) { ! redir_off = TRUE; // Don't redirect the typed command. ! // Repeated, because a ":redir" inside ! // completion may switch it on. #ifdef USE_ON_FLY_SCROLL ! dont_scroll = FALSE; // allow scrolling here #endif ! quit_more = FALSE; // reset after CTRL-D which had a more-prompt ! did_emsg = FALSE; // There can't really be a reason why an error ! // that occurs while typing a command should ! // cause the command not to be executed. // Trigger SafeState if nothing is pending. may_trigger_safestate(xpc.xp_numfiles <= 0); ! cursorcmd(); // set the cursor on the right spot ! // Get a character. Ignore K_IGNORE and K_NOP, they should not do ! // anything, such as stop completion. do c = safe_vgetc(); while (c == K_IGNORE || c == K_NOP); *************** *** 999,1007 **** c = hkmap(c); if (cmdmsg_rl && !KeyStuffed) { ! /* Invert horizontal movements and operations. Only when ! * typed by the user directly, not when the result of a ! * mapping. */ switch (c) { case K_RIGHT: c = K_LEFT; break; --- 999,1007 ---- c = hkmap(c); if (cmdmsg_rl && !KeyStuffed) { ! // Invert horizontal movements and operations. Only when ! // typed by the user directly, not when the result of a ! // mapping. switch (c) { case K_RIGHT: c = K_LEFT; break; *************** *** 1054,1060 **** c = Ctrl_P; #ifdef FEAT_WILDMENU ! /* Special translations for 'wildmenu' */ if (did_wild_list && p_wmnu) { if (c == K_LEFT) --- 1054,1060 ---- c = Ctrl_P; #ifdef FEAT_WILDMENU ! // Special translations for 'wildmenu' if (did_wild_list && p_wmnu) { if (c == K_LEFT) *************** *** 1062,1068 **** else if (c == K_RIGHT) c = Ctrl_N; } ! /* Hitting CR after "emenu Name.": complete submenu */ if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu && ccline.cmdpos > 1 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' --- 1062,1068 ---- else if (c == K_RIGHT) c = Ctrl_N; } ! // Hitting CR after "emenu Name.": complete submenu if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu && ccline.cmdpos > 1 && ccline.cmdbuff[ccline.cmdpos - 1] == '.' *************** *** 1071,1077 **** c = K_DOWN; #endif ! /* free expanded names when finished walking through matches */ if (xpc.xp_numfiles != -1 && !(c == p_wc && KeyTyped) && c != p_wcm && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A --- 1071,1077 ---- c = K_DOWN; #endif ! // free expanded names when finished walking through matches if (xpc.xp_numfiles != -1 && !(c == p_wc && KeyTyped) && c != p_wcm && c != Ctrl_N && c != Ctrl_P && c != Ctrl_A *************** *** 1095,1111 **** if (wild_menu_showing == WM_SCROLLED) { ! /* Entered command line, move it up */ cmdline_row--; redrawcmd(); } else if (save_p_ls != -1) { ! /* restore 'laststatus' and 'winminheight' */ p_ls = save_p_ls; p_wmh = save_p_wmh; last_status(FALSE); ! update_screen(VALID); /* redraw the screen NOW */ redrawcmd(); save_p_ls = -1; } --- 1095,1111 ---- if (wild_menu_showing == WM_SCROLLED) { ! // Entered command line, move it up cmdline_row--; redrawcmd(); } else if (save_p_ls != -1) { ! // restore 'laststatus' and 'winminheight' p_ls = save_p_ls; p_wmh = save_p_wmh; last_status(FALSE); ! update_screen(VALID); // redraw the screen NOW redrawcmd(); save_p_ls = -1; } *************** *** 1123,1153 **** } #ifdef FEAT_WILDMENU ! /* Special translations for 'wildmenu' */ if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) { ! /* Hitting after "emenu Name.": complete submenu */ if (c == K_DOWN && ccline.cmdpos > 0 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') c = p_wc; else if (c == K_UP) { ! /* Hitting : Remove one submenu name in front of the ! * cursor */ int found = FALSE; j = (int)(xpc.xp_pattern - ccline.cmdbuff); i = 0; while (--j > 0) { ! /* check for start of menu name */ if (ccline.cmdbuff[j] == ' ' && ccline.cmdbuff[j - 1] != '\\') { i = j + 1; break; } ! /* check for start of submenu name */ if (ccline.cmdbuff[j] == '.' && ccline.cmdbuff[j - 1] != '\\') { --- 1123,1153 ---- } #ifdef FEAT_WILDMENU ! // Special translations for 'wildmenu' if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu) { ! // Hitting after "emenu Name.": complete submenu if (c == K_DOWN && ccline.cmdpos > 0 && ccline.cmdbuff[ccline.cmdpos - 1] == '.') c = p_wc; else if (c == K_UP) { ! // Hitting : Remove one submenu name in front of the ! // cursor int found = FALSE; j = (int)(xpc.xp_pattern - ccline.cmdbuff); i = 0; while (--j > 0) { ! // check for start of menu name if (ccline.cmdbuff[j] == ' ' && ccline.cmdbuff[j - 1] != '\\') { i = j + 1; break; } ! // check for start of submenu name if (ccline.cmdbuff[j] == '.' && ccline.cmdbuff[j - 1] != '\\') { *************** *** 1185,1196 **** || ccline.cmdbuff[ccline.cmdpos - 2] != '.' || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) { ! /* go down a directory */ c = p_wc; } else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) { ! /* If in a direct ancestor, strip off one ../ to go down */ int found = FALSE; j = ccline.cmdpos; --- 1185,1196 ---- || ccline.cmdbuff[ccline.cmdpos - 2] != '.' || ccline.cmdbuff[ccline.cmdpos - 3] != '.')) { ! // go down a directory c = p_wc; } else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN) { ! // If in a direct ancestor, strip off one ../ to go down int found = FALSE; j = ccline.cmdpos; *************** *** 1216,1222 **** } else if (c == K_UP) { ! /* go up a directory */ int found = FALSE; j = ccline.cmdpos - 1; --- 1216,1222 ---- } else if (c == K_UP) { ! // go up a directory int found = FALSE; j = ccline.cmdpos - 1; *************** *** 1253,1277 **** j = 0; if (j > 0) { ! /* TODO this is only for DOS/UNIX systems - need to put in ! * machine-specific stuff here and in upseg init */ cmdline_del(j); put_on_cmdline(upseg + 1, 3, FALSE); } else if (ccline.cmdpos > i) cmdline_del(i); ! /* Now complete in the new directory. Set KeyTyped in case the ! * Up key came from a mapping. */ c = p_wc; KeyTyped = TRUE; } } ! #endif /* FEAT_WILDMENU */ ! /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert ! * mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */ if (c == Ctrl_BSL) { ++no_mapping; --- 1253,1277 ---- j = 0; if (j > 0) { ! // TODO this is only for DOS/UNIX systems - need to put in ! // machine-specific stuff here and in upseg init cmdline_del(j); put_on_cmdline(upseg + 1, 3, FALSE); } else if (ccline.cmdpos > i) cmdline_del(i); ! // Now complete in the new directory. Set KeyTyped in case the ! // Up key came from a mapping. c = p_wc; KeyTyped = TRUE; } } ! #endif // FEAT_WILDMENU ! // CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert ! // mode when 'insertmode' is set, CTRL-\ e prompts for an expression. if (c == Ctrl_BSL) { ++no_mapping; *************** *** 1279,1286 **** c = plain_vgetc(); --no_mapping; --allow_keys; ! /* CTRL-\ e doesn't work when obtaining an expression, unless it ! * is in a mapping. */ if (c != Ctrl_N && c != Ctrl_G && (c != 'e' || (ccline.cmdfirstc == '=' && KeyTyped) #ifdef FEAT_EVAL --- 1279,1286 ---- c = plain_vgetc(); --no_mapping; --allow_keys; ! // CTRL-\ e doesn't work when obtaining an expression, unless it ! // is in a mapping. if (c != Ctrl_N && c != Ctrl_G && (c != 'e' || (ccline.cmdfirstc == '=' && KeyTyped) #ifdef FEAT_EVAL *************** *** 1303,1318 **** * able to enter a new one... */ if (ccline.cmdpos == ccline.cmdlen) ! new_cmdpos = 99999; /* keep it at the end */ else new_cmdpos = ccline.cmdpos; c = get_expr_register(); if (c == '=') { ! /* Need to save and restore ccline. And set "textlock" ! * to avoid nasty things like going to another buffer when ! * evaluating an expression. */ ++textlock; p = get_expr_line(); --textlock; --- 1303,1318 ---- * able to enter a new one... */ if (ccline.cmdpos == ccline.cmdlen) ! new_cmdpos = 99999; // keep it at the end else new_cmdpos = ccline.cmdpos; c = get_expr_register(); if (c == '=') { ! // Need to save and restore ccline. And set "textlock" ! // to avoid nasty things like going to another buffer when ! // evaluating an expression. ++textlock; p = get_expr_line(); --textlock; *************** *** 1326,1339 **** STRCPY(ccline.cmdbuff, p); vim_free(p); ! /* Restore the cursor or use the position set with ! * set_cmdline_pos(). */ if (new_cmdpos > ccline.cmdlen) ccline.cmdpos = ccline.cmdlen; else ccline.cmdpos = new_cmdpos; ! KeyTyped = FALSE; /* Don't do p_wc completion. */ redrawcmd(); goto cmdline_changed; } --- 1326,1339 ---- STRCPY(ccline.cmdbuff, p); vim_free(p); ! // Restore the cursor or use the position set with ! // set_cmdline_pos(). if (new_cmdpos > ccline.cmdlen) ccline.cmdpos = ccline.cmdlen; else ccline.cmdpos = new_cmdpos; ! KeyTyped = FALSE; // Don't do p_wc completion. redrawcmd(); goto cmdline_changed; } *************** *** 1341,1347 **** } } beep_flush(); ! got_int = FALSE; /* don't abandon the command line */ did_emsg = FALSE; emsg_on_display = FALSE; redrawcmd(); --- 1341,1347 ---- } } beep_flush(); ! got_int = FALSE; // don't abandon the command line did_emsg = FALSE; emsg_on_display = FALSE; redrawcmd(); *************** *** 1352,1360 **** { if (c == Ctrl_G && p_im && restart_edit == 0) restart_edit = 'a'; ! gotesc = TRUE; /* will free ccline.cmdbuff after putting it ! in history */ ! goto returncmd; /* back to Normal mode */ } } --- 1352,1360 ---- { if (c == Ctrl_G && p_im && restart_edit == 0) restart_edit = 'a'; ! gotesc = TRUE; // will free ccline.cmdbuff after putting it ! // in history ! goto returncmd; // back to Normal mode } } *************** *** 1381,1387 **** if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) { ! /* In Ex mode a backslash escapes a newline. */ if (exmode_active && c != ESC && ccline.cmdpos == ccline.cmdlen --- 1381,1387 ---- if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL))) { ! // In Ex mode a backslash escapes a newline. if (exmode_active && c != ESC && ccline.cmdpos == ccline.cmdlen *************** *** 1393,1400 **** } else { ! gotesc = FALSE; /* Might have typed ESC previously, don't ! truncate the cmdline now. */ if (ccheck_abbr(c + ABBR_OFF)) goto cmdline_changed; if (!cmd_silent) --- 1393,1400 ---- } else { ! gotesc = FALSE; // Might have typed ESC previously, don't ! // truncate the cmdline now. if (ccheck_abbr(c + ABBR_OFF)) goto cmdline_changed; if (!cmd_silent) *************** *** 1417,1425 **** int options = WILD_NO_BEEP; if (wim_flags[wim_index] & WIM_BUFLASTUSED) options |= WILD_BUFLASTUSED; ! if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */ { ! /* if 'wildmode' contains "list" may still need to list */ if (xpc.xp_numfiles > 1 && !did_wild_list && (wim_flags[wim_index] & WIM_LIST)) --- 1417,1425 ---- int options = WILD_NO_BEEP; if (wim_flags[wim_index] & WIM_BUFLASTUSED) options |= WILD_BUFLASTUSED; ! if (xpc.xp_numfiles > 0) // typed p_wc at least twice { ! // if 'wildmode' contains "list" may still need to list if (xpc.xp_numfiles > 1 && !did_wild_list && (wim_flags[wim_index] & WIM_LIST)) *************** *** 1435,1448 **** res = nextwild(&xpc, WILD_NEXT, options, firstc != '@'); else ! res = OK; /* don't insert 'wildchar' now */ } ! else /* typed p_wc first time */ { wim_index = 0; j = ccline.cmdpos; ! /* if 'wildmode' first contains "longest", get longest ! * common part */ if (wim_flags[0] & WIM_LONGEST) res = nextwild(&xpc, WILD_LONGEST, options, firstc != '@'); --- 1435,1448 ---- res = nextwild(&xpc, WILD_NEXT, options, firstc != '@'); else ! res = OK; // don't insert 'wildchar' now } ! else // typed p_wc first time { wim_index = 0; j = ccline.cmdpos; ! // if 'wildmode' first contains "longest", get longest ! // common part if (wim_flags[0] & WIM_LONGEST) res = nextwild(&xpc, WILD_LONGEST, options, firstc != '@'); *************** *** 1450,1460 **** res = nextwild(&xpc, WILD_EXPAND_KEEP, options, firstc != '@'); ! /* if interrupted while completing, behave like it failed */ if (got_int) { ! (void)vpeekc(); /* remove from input stream */ ! got_int = FALSE; /* don't abandon the command line */ (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); #ifdef FEAT_WILDMENU xpc.xp_context = EXPAND_NOTHING; --- 1450,1460 ---- res = nextwild(&xpc, WILD_EXPAND_KEEP, options, firstc != '@'); ! // if interrupted while completing, behave like it failed if (got_int) { ! (void)vpeekc(); // remove from input stream ! got_int = FALSE; // don't abandon the command line (void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE); #ifdef FEAT_WILDMENU xpc.xp_context = EXPAND_NOTHING; *************** *** 1462,1474 **** goto cmdline_changed; } ! /* when more than one match, and 'wildmode' first contains ! * "list", or no change and 'wildmode' contains "longest,list", ! * list all matches */ if (res == OK && xpc.xp_numfiles > 1) { ! /* a "longest" that didn't do anything is skipped (but not ! * "list:longest") */ if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) wim_index = 1; if ((wim_flags[wim_index] & WIM_LIST) --- 1462,1474 ---- goto cmdline_changed; } ! // when more than one match, and 'wildmode' first contains ! // "list", or no change and 'wildmode' contains "longest,list", ! // list all matches if (res == OK && xpc.xp_numfiles > 1) { ! // a "longest" that didn't do anything is skipped (but not ! // "list:longest") if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j) wim_index = 1; if ((wim_flags[wim_index] & WIM_LIST) *************** *** 1483,1489 **** int p_wmnu_save = p_wmnu; p_wmnu = 0; #endif ! /* remove match */ nextwild(&xpc, WILD_PREV, 0, firstc != '@'); #ifdef FEAT_WILDMENU p_wmnu = p_wmnu_save; --- 1483,1489 ---- int p_wmnu_save = p_wmnu; p_wmnu = 0; #endif ! // remove match nextwild(&xpc, WILD_PREV, 0, firstc != '@'); #ifdef FEAT_WILDMENU p_wmnu = p_wmnu_save; *************** *** 1522,1528 **** gotesc = FALSE; ! /* goes to last match, in a clumsy way */ if (c == K_S_TAB && KeyTyped) { if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK --- 1522,1528 ---- gotesc = FALSE; ! // goes to last match, in a clumsy way if (c == K_S_TAB && KeyTyped) { if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK *************** *** 1531,1540 **** goto cmdline_changed; } ! if (c == NUL || c == K_ZERO) /* NUL is stored as NL */ c = NL; ! do_abbr = TRUE; /* default: check for abbreviation */ /* * Big switch for a typed command line character. --- 1531,1540 ---- goto cmdline_changed; } ! if (c == NUL || c == K_ZERO) // NUL is stored as NL c = NL; ! do_abbr = TRUE; // default: check for abbreviation /* * Big switch for a typed command line character. *************** *** 1595,1608 **** while (i < ccline.cmdlen) ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; ! /* Truncate at the end, required for multi-byte chars. */ ccline.cmdbuff[ccline.cmdlen] = NUL; #ifdef FEAT_SEARCH_EXTRA if (ccline.cmdlen == 0) { is_state.search_start = is_state.save_cursor; ! /* save view settings, so that the screen ! * won't be restored at the wrong position */ is_state.old_viewstate = is_state.init_viewstate; } #endif --- 1595,1608 ---- while (i < ccline.cmdlen) ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; ! // Truncate at the end, required for multi-byte chars. ccline.cmdbuff[ccline.cmdlen] = NUL; #ifdef FEAT_SEARCH_EXTRA if (ccline.cmdlen == 0) { is_state.search_start = is_state.save_cursor; ! // save view settings, so that the screen ! // won't be restored at the wrong position is_state.old_viewstate = is_state.init_viewstate; } #endif *************** *** 1611,1617 **** else if (ccline.cmdlen == 0 && c != Ctrl_W && ccline.cmdprompt == NULL && indent == 0) { ! /* In ex and debug mode it doesn't make sense to return. */ if (exmode_active #ifdef FEAT_EVAL || ccline.cmdfirstc == '>' --- 1611,1617 ---- else if (ccline.cmdlen == 0 && c != Ctrl_W && ccline.cmdprompt == NULL && indent == 0) { ! // In ex and debug mode it doesn't make sense to return. if (exmode_active #ifdef FEAT_EVAL || ccline.cmdfirstc == '>' *************** *** 1619,1625 **** ) goto cmdline_not_changed; ! VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */ if (!cmd_silent) { #ifdef FEAT_RIGHTLEFT --- 1619,1625 ---- ) goto cmdline_not_changed; ! VIM_CLEAR(ccline.cmdbuff); // no commandline to return if (!cmd_silent) { #ifdef FEAT_RIGHTLEFT *************** *** 1628,1641 **** else #endif msg_col = 0; ! msg_putchar(' '); /* delete ':' */ } #ifdef FEAT_SEARCH_EXTRA if (ccline.cmdlen == 0) is_state.search_start = is_state.save_cursor; #endif redraw_cmdline = TRUE; ! goto returncmd; /* back to cmd mode */ } goto cmdline_changed; --- 1628,1641 ---- else #endif msg_col = 0; ! msg_putchar(' '); // delete ':' } #ifdef FEAT_SEARCH_EXTRA if (ccline.cmdlen == 0) is_state.search_start = is_state.save_cursor; #endif redraw_cmdline = TRUE; ! goto returncmd; // back to cmd mode } goto cmdline_changed; *************** *** 1643,1659 **** case K_KINS: ccline.overstrike = !ccline.overstrike; #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may show different cursor shape */ #endif goto cmdline_not_changed; case Ctrl_HAT: if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) { ! /* ":lmap" mappings exists, toggle use of mappings. */ State ^= LANGMAP; #ifdef HAVE_INPUT_METHOD ! im_set_active(FALSE); /* Disable input method */ #endif if (b_im_ptr != NULL) { --- 1643,1659 ---- case K_KINS: ccline.overstrike = !ccline.overstrike; #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may show different cursor shape #endif goto cmdline_not_changed; case Ctrl_HAT: if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) { ! // ":lmap" mappings exists, toggle use of mappings. State ^= LANGMAP; #ifdef HAVE_INPUT_METHOD ! im_set_active(FALSE); // Disable input method #endif if (b_im_ptr != NULL) { *************** *** 1666,1684 **** #ifdef HAVE_INPUT_METHOD else { ! /* There are no ":lmap" mappings, toggle IM. When ! * 'imdisable' is set don't try getting the status, it's ! * always off. */ if ((p_imdisable && b_im_ptr != NULL) ? *b_im_ptr == B_IMODE_IM : im_get_status()) { ! im_set_active(FALSE); /* Disable input method */ if (b_im_ptr != NULL) *b_im_ptr = B_IMODE_NONE; } else { ! im_set_active(TRUE); /* Enable input method */ if (b_im_ptr != NULL) *b_im_ptr = B_IMODE_IM; } --- 1666,1684 ---- #ifdef HAVE_INPUT_METHOD else { ! // There are no ":lmap" mappings, toggle IM. When ! // 'imdisable' is set don't try getting the status, it's ! // always off. if ((p_imdisable && b_im_ptr != NULL) ? *b_im_ptr == B_IMODE_IM : im_get_status()) { ! im_set_active(FALSE); // Disable input method if (b_im_ptr != NULL) *b_im_ptr = B_IMODE_NONE; } else { ! im_set_active(TRUE); // Enable input method if (b_im_ptr != NULL) *b_im_ptr = B_IMODE_IM; } *************** *** 1692,1714 **** set_imsearch_global(); } #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may show different cursor shape */ #endif #if defined(FEAT_KEYMAP) ! /* Show/unshow value of 'keymap' in status lines later. */ status_redraw_curbuf(); #endif goto cmdline_not_changed; ! /* case '@': only in very old vi */ case Ctrl_U: ! /* delete all characters left of the cursor */ j = ccline.cmdpos; ccline.cmdlen -= j; i = ccline.cmdpos = 0; while (i < ccline.cmdlen) ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; ! /* Truncate at the end, required for multi-byte chars. */ ccline.cmdbuff[ccline.cmdlen] = NUL; #ifdef FEAT_SEARCH_EXTRA if (ccline.cmdlen == 0) --- 1692,1714 ---- set_imsearch_global(); } #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may show different cursor shape #endif #if defined(FEAT_KEYMAP) ! // Show/unshow value of 'keymap' in status lines later. status_redraw_curbuf(); #endif goto cmdline_not_changed; ! // case '@': only in very old vi case Ctrl_U: ! // delete all characters left of the cursor j = ccline.cmdpos; ccline.cmdlen -= j; i = ccline.cmdpos = 0; while (i < ccline.cmdlen) ccline.cmdbuff[i++] = ccline.cmdbuff[j++]; ! // Truncate at the end, required for multi-byte chars. ccline.cmdbuff[ccline.cmdlen] = NUL; #ifdef FEAT_SEARCH_EXTRA if (ccline.cmdlen == 0) *************** *** 1719,1725 **** #ifdef FEAT_CLIPBOARD case Ctrl_Y: ! /* Copy the modeless selection, if there is one. */ if (clip_star.state != SELECT_CLEARED) { if (clip_star.state == SELECT_DONE) --- 1719,1725 ---- #ifdef FEAT_CLIPBOARD case Ctrl_Y: ! // Copy the modeless selection, if there is one. if (clip_star.state != SELECT_CLEARED) { if (clip_star.state == SELECT_DONE) *************** *** 1729,1758 **** break; #endif ! case ESC: /* get here if p_wc != ESC or when ESC typed twice */ case Ctrl_C: ! /* In exmode it doesn't make sense to return. Except when ! * ":normal" runs out of characters. */ if (exmode_active && (ex_normal_busy == 0 || typebuf.tb_len > 0)) goto cmdline_not_changed; ! gotesc = TRUE; /* will free ccline.cmdbuff after ! putting it in history */ ! goto returncmd; /* back to cmd mode */ ! case Ctrl_R: /* insert register */ #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; /* disallow scrolling here */ #endif putcmdline('"', TRUE); ++no_mapping; ++allow_keys; ! i = c = plain_vgetc(); /* CTRL-R */ if (i == Ctrl_O) ! i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */ if (i == Ctrl_R) ! c = plain_vgetc(); /* CTRL-R CTRL-R */ extra_char = NUL; --no_mapping; --allow_keys; --- 1729,1758 ---- break; #endif ! case ESC: // get here if p_wc != ESC or when ESC typed twice case Ctrl_C: ! // In exmode it doesn't make sense to return. Except when ! // ":normal" runs out of characters. if (exmode_active && (ex_normal_busy == 0 || typebuf.tb_len > 0)) goto cmdline_not_changed; ! gotesc = TRUE; // will free ccline.cmdbuff after ! // putting it in history ! goto returncmd; // back to cmd mode ! case Ctrl_R: // insert register #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; // disallow scrolling here #endif putcmdline('"', TRUE); ++no_mapping; ++allow_keys; ! i = c = plain_vgetc(); // CTRL-R if (i == Ctrl_O) ! i = Ctrl_R; // CTRL-R CTRL-O == CTRL-R CTRL-R if (i == Ctrl_R) ! c = plain_vgetc(); // CTRL-R CTRL-R extra_char = NUL; --no_mapping; --allow_keys; *************** *** 1775,1799 **** c = get_expr_register(); } #endif ! if (c != ESC) /* use ESC to cancel inserting register */ { cmdline_paste(c, i == Ctrl_R, FALSE); #ifdef FEAT_EVAL ! /* When there was a serious error abort getting the ! * command line. */ if (aborting()) { ! gotesc = TRUE; /* will free ccline.cmdbuff after ! putting it in history */ ! goto returncmd; /* back to cmd mode */ } #endif ! KeyTyped = FALSE; /* Don't do p_wc completion. */ #ifdef FEAT_EVAL if (new_cmdpos >= 0) { ! /* set_cmdline_pos() was used */ if (new_cmdpos > ccline.cmdlen) ccline.cmdpos = ccline.cmdlen; else --- 1775,1799 ---- c = get_expr_register(); } #endif ! if (c != ESC) // use ESC to cancel inserting register { cmdline_paste(c, i == Ctrl_R, FALSE); #ifdef FEAT_EVAL ! // When there was a serious error abort getting the ! // command line. if (aborting()) { ! gotesc = TRUE; // will free ccline.cmdbuff after ! // putting it in history ! goto returncmd; // back to cmd mode } #endif ! KeyTyped = FALSE; // Don't do p_wc completion. #ifdef FEAT_EVAL if (new_cmdpos >= 0) { ! // set_cmdline_pos() was used if (new_cmdpos > ccline.cmdlen) ccline.cmdpos = ccline.cmdlen; else *************** *** 1806,1815 **** case Ctrl_D: if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) ! break; /* Use ^D as normal char instead */ redrawcmd(); ! continue; /* don't do incremental search now */ case K_RIGHT: case K_S_RIGHT: --- 1806,1815 ---- case Ctrl_D: if (showmatches(&xpc, FALSE) == EXPAND_NOTHING) ! break; // Use ^D as normal char instead redrawcmd(); ! continue; // don't do incremental search now case K_RIGHT: case K_S_RIGHT: *************** *** 1843,1849 **** do { --ccline.cmdpos; ! if (has_mbyte) /* move to first byte of char */ ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); --- 1843,1849 ---- do { --ccline.cmdpos; ! if (has_mbyte) // move to first byte of char ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= cmdline_charsize(ccline.cmdpos); *************** *** 1857,1872 **** goto cmdline_not_changed; case K_IGNORE: ! /* Ignore mouse event or open_cmdwin() result. */ goto cmdline_not_changed; #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) { ! redrawcmd(); /* somehow the cmdline is cleared */ goto cmdline_not_changed; } break; --- 1857,1872 ---- goto cmdline_not_changed; case K_IGNORE: ! // Ignore mouse event or open_cmdwin() result. goto cmdline_not_changed; #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) { ! redrawcmd(); // somehow the cmdline is cleared goto cmdline_not_changed; } break; *************** *** 1874,1888 **** case K_MIDDLEDRAG: case K_MIDDLERELEASE: ! goto cmdline_not_changed; /* Ignore mouse */ case K_MIDDLEMOUSE: # ifdef FEAT_GUI ! /* When GUI is active, also paste when 'mouse' is empty */ if (!gui.in_use) # endif if (!mouse_has(MOUSE_COMMAND)) ! goto cmdline_not_changed; /* Ignore mouse */ # ifdef FEAT_CLIPBOARD if (clip_star.available) cmdline_paste('*', TRUE, TRUE); --- 1874,1888 ---- case K_MIDDLEDRAG: case K_MIDDLERELEASE: ! goto cmdline_not_changed; // Ignore mouse case K_MIDDLEMOUSE: # ifdef FEAT_GUI ! // When GUI is active, also paste when 'mouse' is empty if (!gui.in_use) # endif if (!mouse_has(MOUSE_COMMAND)) ! goto cmdline_not_changed; // Ignore mouse # ifdef FEAT_CLIPBOARD if (clip_star.available) cmdline_paste('*', TRUE, TRUE); *************** *** 1903,1913 **** case K_LEFTRELEASE: case K_RIGHTDRAG: case K_RIGHTRELEASE: ! /* Ignore drag and release events when the button-down wasn't ! * seen before. */ if (ignore_drag_release) goto cmdline_not_changed; ! /* FALLTHROUGH */ case K_LEFTMOUSE: case K_RIGHTMOUSE: if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) --- 1903,1913 ---- case K_LEFTRELEASE: case K_RIGHTDRAG: case K_RIGHTRELEASE: ! // Ignore drag and release events when the button-down wasn't ! // seen before. if (ignore_drag_release) goto cmdline_not_changed; ! // FALLTHROUGH case K_LEFTMOUSE: case K_RIGHTMOUSE: if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE) *************** *** 1915,1925 **** else ignore_drag_release = FALSE; # ifdef FEAT_GUI ! /* When GUI is active, also move when 'mouse' is empty */ if (!gui.in_use) # endif if (!mouse_has(MOUSE_COMMAND)) ! goto cmdline_not_changed; /* Ignore mouse */ # ifdef FEAT_CLIPBOARD if (mouse_row < cmdline_row && clip_star.available) { --- 1915,1925 ---- else ignore_drag_release = FALSE; # ifdef FEAT_GUI ! // When GUI is active, also move when 'mouse' is empty if (!gui.in_use) # endif if (!mouse_has(MOUSE_COMMAND)) ! goto cmdline_not_changed; // Ignore mouse # ifdef FEAT_CLIPBOARD if (mouse_row < cmdline_row && clip_star.available) { *************** *** 1933,1939 **** if (mouse_model_popup() && button == MOUSE_LEFT && (mod_mask & MOD_MASK_SHIFT)) { ! /* Translate shift-left to right button. */ button = MOUSE_RIGHT; mod_mask &= ~MOD_MASK_SHIFT; } --- 1933,1939 ---- if (mouse_model_popup() && button == MOUSE_LEFT && (mod_mask & MOD_MASK_SHIFT)) { ! // Translate shift-left to right button. button = MOUSE_RIGHT; mod_mask &= ~MOD_MASK_SHIFT; } *************** *** 1952,1958 **** break; if (has_mbyte) { ! /* Count ">" for double-wide char that doesn't fit. */ correct_cmdspos(ccline.cmdpos, i); ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; --- 1952,1958 ---- break; if (has_mbyte) { ! // Count ">" for double-wide char that doesn't fit. correct_cmdspos(ccline.cmdpos, i); ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1; *************** *** 1961,1972 **** } goto cmdline_not_changed; ! /* Mouse scroll wheel: ignored here */ case K_MOUSEDOWN: case K_MOUSEUP: case K_MOUSELEFT: case K_MOUSERIGHT: ! /* Alternate buttons ignored here */ case K_X1MOUSE: case K_X1DRAG: case K_X1RELEASE: --- 1961,1972 ---- } goto cmdline_not_changed; ! // Mouse scroll wheel: ignored here case K_MOUSEDOWN: case K_MOUSEUP: case K_MOUSELEFT: case K_MOUSERIGHT: ! // Alternate buttons ignored here case K_X1MOUSE: case K_X1DRAG: case K_X1RELEASE: *************** *** 1977,1983 **** goto cmdline_not_changed; #ifdef FEAT_GUI ! case K_LEFTMOUSE_NM: /* mousefocus click, ignored */ case K_LEFTRELEASE_NM: goto cmdline_not_changed; --- 1977,1983 ---- goto cmdline_not_changed; #ifdef FEAT_GUI ! case K_LEFTMOUSE_NM: // mousefocus click, ignored case K_LEFTRELEASE_NM: goto cmdline_not_changed; *************** *** 2000,2016 **** #ifdef FEAT_GUI_TABLINE case K_TABLINE: case K_TABMENU: ! /* Don't want to change any tabs here. Make sure the same tab ! * is still selected. */ if (gui_use_tabline()) gui_mch_set_curtab(tabpage_index(curtab)); goto cmdline_not_changed; #endif ! case K_SELECT: /* end of Select mode mapping - ignore */ goto cmdline_not_changed; ! case Ctrl_B: /* begin of command line */ case K_HOME: case K_KHOME: case K_S_HOME: --- 2000,2016 ---- #ifdef FEAT_GUI_TABLINE case K_TABLINE: case K_TABMENU: ! // Don't want to change any tabs here. Make sure the same tab ! // is still selected. if (gui_use_tabline()) gui_mch_set_curtab(tabpage_index(curtab)); goto cmdline_not_changed; #endif ! case K_SELECT: // end of Select mode mapping - ignore goto cmdline_not_changed; ! case Ctrl_B: // begin of command line case K_HOME: case K_KHOME: case K_S_HOME: *************** *** 2019,2025 **** set_cmdspos(); goto cmdline_not_changed; ! case Ctrl_E: /* end of command line */ case K_END: case K_KEND: case K_S_END: --- 2019,2025 ---- set_cmdspos(); goto cmdline_not_changed; ! case Ctrl_E: // end of command line case K_END: case K_KEND: case K_S_END: *************** *** 2028,2034 **** set_cmdspos_cursor(); goto cmdline_not_changed; ! case Ctrl_A: /* all matches */ if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) break; goto cmdline_changed; --- 2028,2034 ---- set_cmdspos_cursor(); goto cmdline_not_changed; ! case Ctrl_A: // all matches if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL) break; goto cmdline_changed; *************** *** 2039,2051 **** goto cmdline_not_changed; #endif ! /* completion: longest common part */ if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) break; goto cmdline_changed; ! case Ctrl_N: /* next match */ ! case Ctrl_P: /* previous match */ if (xpc.xp_numfiles > 0) { if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, --- 2039,2051 ---- goto cmdline_not_changed; #endif ! // completion: longest common part if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL) break; goto cmdline_changed; ! case Ctrl_N: // next match ! case Ctrl_P: // previous match if (xpc.xp_numfiles > 0) { if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT, *************** *** 2053,2059 **** break; goto cmdline_not_changed; } ! /* FALLTHROUGH */ case K_UP: case K_DOWN: case K_S_UP: --- 2053,2059 ---- break; goto cmdline_not_changed; } ! // FALLTHROUGH case K_UP: case K_DOWN: case K_S_UP: *************** *** 2062,2073 **** case K_KPAGEUP: case K_PAGEDOWN: case K_KPAGEDOWN: ! if (get_hislen() == 0 || firstc == NUL) /* no history */ goto cmdline_not_changed; i = hiscnt; ! /* save current command string so it can be restored later */ if (lookfor == NULL) { if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) --- 2062,2073 ---- case K_KPAGEUP: case K_PAGEDOWN: case K_KPAGEDOWN: ! if (get_hislen() == 0 || firstc == NUL) // no history goto cmdline_not_changed; i = hiscnt; ! // save current command string so it can be restored later if (lookfor == NULL) { if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL) *************** *** 2078,2117 **** j = (int)STRLEN(lookfor); for (;;) { ! /* one step backwards */ if (c == K_UP|| c == K_S_UP || c == Ctrl_P || c == K_PAGEUP || c == K_KPAGEUP) { ! if (hiscnt == get_hislen()) /* first time */ hiscnt = *get_hisidx(histype); ! else if (hiscnt == 0 && *get_hisidx(histype) != get_hislen() - 1) hiscnt = get_hislen() - 1; else if (hiscnt != *get_hisidx(histype) + 1) --hiscnt; ! else /* at top of list */ { hiscnt = i; break; } } ! else /* one step forwards */ { ! /* on last entry, clear the line */ if (hiscnt == *get_hisidx(histype)) { hiscnt = get_hislen(); break; } ! /* not on a history line, nothing to do */ if (hiscnt == get_hislen()) break; ! if (hiscnt == get_hislen() - 1) /* wrap around */ hiscnt = 0; else ++hiscnt; } ! if (hiscnt < 0 || get_histentry(histype)[hiscnt].hisstr == NULL) { hiscnt = i; break; --- 2078,2119 ---- j = (int)STRLEN(lookfor); for (;;) { ! // one step backwards if (c == K_UP|| c == K_S_UP || c == Ctrl_P || c == K_PAGEUP || c == K_KPAGEUP) { ! if (hiscnt == get_hislen()) // first time hiscnt = *get_hisidx(histype); ! else if (hiscnt == 0 && *get_hisidx(histype) ! != get_hislen() - 1) hiscnt = get_hislen() - 1; else if (hiscnt != *get_hisidx(histype) + 1) --hiscnt; ! else // at top of list { hiscnt = i; break; } } ! else // one step forwards { ! // on last entry, clear the line if (hiscnt == *get_hisidx(histype)) { hiscnt = get_hislen(); break; } ! // not on a history line, nothing to do if (hiscnt == get_hislen()) break; ! if (hiscnt == get_hislen() - 1) // wrap around hiscnt = 0; else ++hiscnt; } ! if (hiscnt < 0 || get_histentry(histype)[hiscnt].hisstr ! == NULL) { hiscnt = i; break; *************** *** 2123,2129 **** break; } ! if (hiscnt != i) /* jumped to other entry */ { char_u *p; int len; --- 2125,2131 ---- break; } ! if (hiscnt != i) // jumped to other entry { char_u *p; int len; *************** *** 2132,2138 **** VIM_CLEAR(ccline.cmdbuff); xpc.xp_context = EXPAND_NOTHING; if (hiscnt == get_hislen()) ! p = lookfor; /* back to the old one */ else p = get_histentry(histype)[hiscnt].hisstr; --- 2134,2140 ---- VIM_CLEAR(ccline.cmdbuff); xpc.xp_context = EXPAND_NOTHING; if (hiscnt == get_hislen()) ! p = lookfor; // back to the old one else p = get_histentry(histype)[hiscnt].hisstr; *************** *** 2140,2156 **** && p != lookfor && (old_firstc = p[STRLEN(p) + 1]) != firstc) { ! /* Correct for the separator character used when ! * adding the history entry vs the one used now. ! * First loop: count length. ! * Second loop: copy the characters. */ for (i = 0; i <= 1; ++i) { len = 0; for (j = 0; p[j] != NUL; ++j) { ! /* Replace old sep with new sep, unless it is ! * escaped. */ if (p[j] == old_firstc && (j == 0 || p[j - 1] != '\\')) { --- 2142,2158 ---- && p != lookfor && (old_firstc = p[STRLEN(p) + 1]) != firstc) { ! // Correct for the separator character used when ! // adding the history entry vs the one used now. ! // First loop: count length. ! // Second loop: copy the characters. for (i = 0; i <= 1; ++i) { len = 0; for (j = 0; p[j] != NUL; ++j) { ! // Replace old sep with new sep, unless it is ! // escaped. if (p[j] == old_firstc && (j == 0 || p[j - 1] != '\\')) { *************** *** 2159,2166 **** } else { ! /* Escape new sep, unless it is already ! * escaped. */ if (p[j] == firstc && (j == 0 || p[j - 1] != '\\')) { --- 2161,2168 ---- } else { ! // Escape new sep, unless it is already ! // escaped. if (p[j] == firstc && (j == 0 || p[j - 1] != '\\')) { *************** *** 2198,2205 **** goto cmdline_not_changed; #ifdef FEAT_SEARCH_EXTRA ! case Ctrl_G: /* next match */ ! case Ctrl_T: /* previous match */ if (may_adjust_incsearch_highlighting( firstc, count, &is_state, c) == FAIL) goto cmdline_not_changed; --- 2200,2207 ---- goto cmdline_not_changed; #ifdef FEAT_SEARCH_EXTRA ! case Ctrl_G: // next match ! case Ctrl_T: // previous match if (may_adjust_incsearch_highlighting( firstc, count, &is_state, c) == FAIL) goto cmdline_not_changed; *************** *** 2240,2246 **** ignore_drag_release = TRUE; putcmdline('?', TRUE); # ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; /* disallow scrolling here */ # endif c = get_digraph(TRUE); extra_char = NUL; --- 2242,2248 ---- ignore_drag_release = TRUE; putcmdline('?', TRUE); # ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; // disallow scrolling here # endif c = get_digraph(TRUE); extra_char = NUL; *************** *** 2252,2258 **** #endif // FEAT_DIGRAPHS #ifdef FEAT_RIGHTLEFT ! case Ctrl__: /* CTRL-_: switch language mode */ if (!p_ari) break; cmd_hkmap = !cmd_hkmap; --- 2254,2260 ---- #endif // FEAT_DIGRAPHS #ifdef FEAT_RIGHTLEFT ! case Ctrl__: // CTRL-_: switch language mode if (!p_ari) break; cmd_hkmap = !cmd_hkmap; *************** *** 2267,2275 **** #ifdef UNIX if (c == intr_char) { ! gotesc = TRUE; /* will free ccline.cmdbuff after ! putting it in history */ ! goto returncmd; /* back to Normal mode */ } #endif /* --- 2269,2277 ---- #ifdef UNIX if (c == intr_char) { ! gotesc = TRUE; // will free ccline.cmdbuff after ! // putting it in history ! goto returncmd; // back to Normal mode } #endif /* *************** *** 2304,2310 **** if (has_mbyte) { j = (*mb_char2bytes)(c, IObuff); ! IObuff[j] = NUL; /* exclude composing chars */ put_on_cmdline(IObuff, j, TRUE); } else --- 2306,2312 ---- if (has_mbyte) { j = (*mb_char2bytes)(c, IObuff); ! IObuff[j] = NUL; // exclude composing chars put_on_cmdline(IObuff, j, TRUE); } else *************** *** 2330,2336 **** #endif cmdline_changed: ! /* Trigger CmdlineChanged autocommands. */ trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED); #ifdef FEAT_SEARCH_EXTRA --- 2332,2338 ---- #endif cmdline_changed: ! // Trigger CmdlineChanged autocommands. trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED); #ifdef FEAT_SEARCH_EXTRA *************** *** 2344,2353 **** && cmdline_has_arabic(0, ccline.cmdlen)) # endif ) ! /* Always redraw the whole command line to fix shaping and ! * right-left typing. Not efficient, but it works. ! * Do it only when there are no characters left to read ! * to avoid useless intermediate redraws. */ if (vpeekc() == NUL) redrawcmd(); #endif --- 2346,2355 ---- && cmdline_has_arabic(0, ccline.cmdlen)) # endif ) ! // Always redraw the whole command line to fix shaping and ! // right-left typing. Not efficient, but it works. ! // Do it only when there are no characters left to read ! // to avoid useless intermediate redraws. if (vpeekc() == NUL) redrawcmd(); #endif *************** *** 2396,2406 **** msg_scroll = save_msg_scroll; redir_off = FALSE; ! /* When the command line was typed, no need for a wait-return prompt. */ if (some_key_typed) need_wait_return = FALSE; ! /* Trigger CmdlineLeave autocommands. */ trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVE); State = save_State; --- 2398,2408 ---- msg_scroll = save_msg_scroll; redir_off = FALSE; ! // When the command line was typed, no need for a wait-return prompt. if (some_key_typed) need_wait_return = FALSE; ! // Trigger CmdlineLeave autocommands. trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVE); State = save_State; *************** *** 2411,2417 **** #endif setmouse(); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); /* may show different cursor shape */ #endif sb_text_end_cmdline(); --- 2413,2419 ---- #endif setmouse(); #ifdef CURSOR_SHAPE ! ui_cursor_shape(); // may show different cursor shape #endif sb_text_end_cmdline(); *************** *** 2437,2446 **** char_u * getcmdline_prompt( int firstc, ! char_u *prompt, /* command line prompt */ ! int attr, /* attributes for prompt */ ! int xp_context, /* type of expansion */ ! char_u *xp_arg) /* user-defined expansion argument */ { char_u *s; cmdline_info_T save_ccline; --- 2439,2448 ---- char_u * getcmdline_prompt( int firstc, ! char_u *prompt, // command line prompt ! int attr, // attributes for prompt ! int xp_context, // type of expansion ! char_u *xp_arg) // user-defined expansion argument { char_u *s; cmdline_info_T save_ccline; *************** *** 2470,2479 **** restore_cmdline(&save_ccline); msg_silent = msg_silent_save; ! /* Restore msg_col, the prompt from input() may have changed it. ! * But only if called recursively and the commandline is therefore being ! * restored to an old one; if not, the input() prompt stays on the screen, ! * so we need its modified msg_col left intact. */ if (ccline.cmdbuff != NULL) msg_col = msg_col_save; --- 2472,2481 ---- restore_cmdline(&save_ccline); msg_silent = msg_silent_save; ! // Restore msg_col, the prompt from input() may have changed it. ! // But only if called recursively and the commandline is therefore being ! // restored to an old one; if not, the input() prompt stays on the screen, ! // so we need its modified msg_col left intact. if (ccline.cmdbuff != NULL) msg_col = msg_col_save; *************** *** 2522,2535 **** } } ! /* fill remaining entries with last flag */ while (idx < 3) { new_wim_flags[idx + 1] = new_wim_flags[idx]; ++idx; } ! /* only when there are no errors, wim_flags[] is changed */ for (i = 0; i < 4; ++i) wim_flags[i] = new_wim_flags[i]; return OK; --- 2524,2537 ---- } } ! // fill remaining entries with last flag while (idx < 3) { new_wim_flags[idx + 1] = new_wim_flags[idx]; ++idx; } ! // only when there are no errors, wim_flags[] is changed for (i = 0; i < 4; ++i) wim_flags[i] = new_wim_flags[i]; return OK; *************** *** 2604,2610 **** cmdline_charsize(int idx) { #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) ! if (cmdline_star > 0) /* showing '*', always 1 position */ return 1; #endif return ptr2cells(ccline.cmdbuff + idx); --- 2606,2612 ---- cmdline_charsize(int idx) { #if defined(FEAT_CRYPT) || defined(FEAT_EVAL) ! if (cmdline_star > 0) // showing '*', always 1 position return 1; #endif return ptr2cells(ccline.cmdbuff + idx); *************** *** 2635,2641 **** if (KeyTyped) { m = Columns * Rows; ! if (m < 0) /* overflow, Columns or Rows at weird value */ m = MAXCOL; } else --- 2637,2643 ---- if (KeyTyped) { m = Columns * Rows; ! if (m < 0) // overflow, Columns or Rows at weird value m = MAXCOL; } else *************** *** 2643,2653 **** for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) { c = cmdline_charsize(i); ! /* Count ">" for double-wide multi-byte char that doesn't fit. */ if (has_mbyte) correct_cmdspos(i, c); ! /* If the cmdline doesn't fit, show cursor on last visible char. ! * Don't move the cursor itself, so we can still append. */ if ((ccline.cmdspos += c) >= m) { ccline.cmdspos -= c; --- 2645,2655 ---- for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i) { c = cmdline_charsize(i); ! // Count ">" for double-wide multi-byte char that doesn't fit. if (has_mbyte) correct_cmdspos(i, c); ! // If the cmdline doesn't fit, show cursor on last visible char. ! // Don't move the cursor itself, so we can still append. if ((ccline.cmdspos += c) >= m) { ccline.cmdspos -= c; *************** *** 2676,2687 **** */ char_u * getexline( ! int c, /* normally ':', NUL for ":append" */ void *cookie UNUSED, ! int indent, /* indent for inside conditionals */ int do_concat) { ! /* When executing a register, remove ':' that's in front of each line. */ if (exec_from_reg && vpeekc() == ':') (void)vgetc(); return getcmdline(c, 1L, indent, do_concat); --- 2678,2689 ---- */ char_u * getexline( ! int c, // normally ':', NUL for ":append" void *cookie UNUSED, ! int indent, // indent for inside conditionals int do_concat) { ! // When executing a register, remove ':' that's in front of each line. if (exec_from_reg && vpeekc() == ':') (void)vgetc(); return getcmdline(c, 1L, indent, do_concat); *************** *** 2695,2727 **** */ char_u * getexmodeline( ! int promptc, /* normally ':', NUL for ":append" and '?' for ! :s prompt */ void *cookie UNUSED, ! int indent, /* indent for inside conditionals */ int do_concat UNUSED) { garray_T line_ga; char_u *pend; int startcol = 0; int c1 = 0; ! int escaped = FALSE; /* CTRL-V typed */ int vcol = 0; char_u *p; int prev_char; int len; ! /* Switch cursor on now. This avoids that it happens after the "\n", which ! * confuses the system function that computes tabstops. */ cursor_on(); ! /* always start in column 0; write a newline if necessary */ compute_cmdrow(); if ((msg_col || msg_didout) && promptc != '?') msg_putchar('\n'); if (promptc == ':') { ! /* indent that is only displayed, not in the line itself */ if (p_prompt) msg_putchar(':'); while (indent-- > 0) --- 2697,2729 ---- */ char_u * getexmodeline( ! int promptc, // normally ':', NUL for ":append" and '?' for ! // :s prompt void *cookie UNUSED, ! int indent, // indent for inside conditionals int do_concat UNUSED) { garray_T line_ga; char_u *pend; int startcol = 0; int c1 = 0; ! int escaped = FALSE; // CTRL-V typed int vcol = 0; char_u *p; int prev_char; int len; ! // Switch cursor on now. This avoids that it happens after the "\n", which ! // confuses the system function that computes tabstops. cursor_on(); ! // always start in column 0; write a newline if necessary compute_cmdrow(); if ((msg_col || msg_didout) && promptc != '?') msg_putchar('\n'); if (promptc == ':') { ! // indent that is only displayed, not in the line itself if (p_prompt) msg_putchar(':'); while (indent-- > 0) *************** *** 2731,2737 **** ga_init2(&line_ga, 1, 30); ! /* autoindent for :insert and :append is in the line itself */ if (promptc <= 0) { vcol = indent; --- 2733,2739 ---- ga_init2(&line_ga, 1, 30); ! // autoindent for :insert and :append is in the line itself if (promptc <= 0) { vcol = indent; *************** *** 2767,2773 **** */ prev_char = c1; ! /* Check for a ":normal" command and no more characters left. */ if (ex_normal_busy > 0 && typebuf.tb_len == 0) c1 = '\n'; else --- 2769,2775 ---- */ prev_char = c1; ! // Check for a ":normal" command and no more characters left. if (ex_normal_busy > 0 && typebuf.tb_len == 0) c1 = '\n'; else *************** *** 2792,2798 **** if (!escaped) { ! /* CR typed means "enter", which is NL */ if (c1 == '\r') c1 = '\n'; --- 2794,2800 ---- if (!escaped) { ! // CR typed means "enter", which is NL if (c1 == '\r') c1 = '\n'; *************** *** 2833,2839 **** add_indent: while (get_indent_str(p, 8, FALSE) < indent) { ! (void)ga_grow(&line_ga, 2); /* one more for the NUL */ p = (char_u *)line_ga.ga_data; s = skipwhite(p); mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); --- 2835,2841 ---- add_indent: while (get_indent_str(p, 8, FALSE) < indent) { ! (void)ga_grow(&line_ga, 2); // one more for the NUL p = (char_u *)line_ga.ga_data; s = skipwhite(p); mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1); *************** *** 2841,2847 **** ++line_ga.ga_len; } redraw: ! /* redraw the line */ msg_col = startcol; vcol = 0; p = (char_u *)line_ga.ga_data; --- 2843,2849 ---- ++line_ga.ga_len; } redraw: ! // redraw the line msg_col = startcol; vcol = 0; p = (char_u *)line_ga.ga_data; *************** *** 2870,2876 **** if (c1 == Ctrl_D) { ! /* Delete one shiftwidth. */ p = (char_u *)line_ga.ga_data; if (prev_char == '0' || prev_char == '^') { --- 2872,2878 ---- if (c1 == Ctrl_D) { ! // Delete one shiftwidth. p = (char_u *)line_ga.ga_data; if (prev_char == '0' || prev_char == '^') { *************** *** 2904,2910 **** continue; } ! /* Ignore special key codes: mouse movement, K_IGNORE, etc. */ if (IS_SPECIAL(c1)) continue; } --- 2906,2912 ---- continue; } ! // Ignore special key codes: mouse movement, K_IGNORE, etc. if (IS_SPECIAL(c1)) continue; } *************** *** 2923,2929 **** msg_putchar('\n'); else if (c1 == TAB) { ! /* Don't use chartabsize(), 'ts' can be different */ do msg_putchar(' '); while (++vcol % 8); --- 2925,2931 ---- msg_putchar('\n'); else if (c1 == TAB) { ! // Don't use chartabsize(), 'ts' can be different do msg_putchar(' '); while (++vcol % 8); *************** *** 2940,2947 **** windgoto(msg_row, msg_col); pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; ! /* We are done when a NL is entered, but not when it comes after an ! * odd number of backslashes, that results in a NUL. */ if (line_ga.ga_len > 0 && pend[-1] == '\n') { int bcount = 0; --- 2942,2949 ---- windgoto(msg_row, msg_col); pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; ! // We are done when a NL is entered, but not when it comes after an ! // odd number of backslashes, that results in a NUL. if (line_ga.ga_len > 0 && pend[-1] == '\n') { int bcount = 0; *************** *** 2951,2958 **** if (bcount > 0) { ! /* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> ! * "\NL", etc. */ line_ga.ga_len -= (bcount + 1) / 2; pend -= (bcount + 1) / 2; pend[-1] = '\n'; --- 2953,2960 ---- if (bcount > 0) { ! // Halve the number of backslashes: "\NL" -> "NUL", "\\NL" -> ! // "\NL", etc. line_ga.ga_len -= (bcount + 1) / 2; pend -= (bcount + 1) / 2; pend[-1] = '\n'; *************** *** 2971,2982 **** --no_mapping; --allow_keys; ! /* make following messages go to the next line */ msg_didout = FALSE; msg_col = 0; if (msg_row < Rows - 1) ++msg_row; ! emsg_on_display = FALSE; /* don't want ui_delay() */ if (got_int) ga_clear(&line_ga); --- 2973,2984 ---- --no_mapping; --allow_keys; ! // make following messages go to the next line msg_didout = FALSE; msg_col = 0; if (msg_row < Rows - 1) ++msg_row; ! emsg_on_display = FALSE; // don't want ui_delay() if (got_int) ga_clear(&line_ga); *************** *** 3041,3047 **** { if ((State & CMDLINE) && xic != NULL ! /* && im_get_status() doesn't work when using SCIM */ && !p_imdisable && im_is_preediting()) { --- 3043,3049 ---- { if ((State & CMDLINE) && xic != NULL ! // && im_get_status() doesn't work when using SCIM && !p_imdisable && im_is_preediting()) { *************** *** 3082,3088 **** char_attr = im_get_feedback_attr(col); if (char_attr < 0) ! break; /* end of preedit string */ if (has_mbyte) char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); --- 3084,3090 ---- char_attr = im_get_feedback_attr(col); if (char_attr < 0) ! break; // end of preedit string if (has_mbyte) char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos); *************** *** 3097,3103 **** msg_col = old_col; } } ! #endif /* FEAT_XIM && FEAT_GUI_GTK */ /* * Allocate a new command line buffer. --- 3099,3105 ---- msg_col = old_col; } } ! #endif // FEAT_XIM && FEAT_GUI_GTK /* * Allocate a new command line buffer. *************** *** 3114,3120 **** else len += 20; ! ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */ ccline.cmdbufflen = len; } --- 3116,3122 ---- else len += 20; ! ccline.cmdbuff = alloc(len); // caller should check for out-of-memory ccline.cmdbufflen = len; } *************** *** 3128,3144 **** char_u *p; if (len < ccline.cmdbufflen) ! return OK; /* no need to resize */ p = ccline.cmdbuff; ! alloc_cmdbuff(len); /* will get some more */ ! if (ccline.cmdbuff == NULL) /* out of memory */ { ! ccline.cmdbuff = p; /* keep the old one */ return FAIL; } ! /* There isn't always a NUL after the command, but it may need to be ! * there, thus copy up to the NUL and add a NUL. */ mch_memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen); ccline.cmdbuff[ccline.cmdlen] = NUL; vim_free(p); --- 3130,3146 ---- char_u *p; if (len < ccline.cmdbufflen) ! return OK; // no need to resize p = ccline.cmdbuff; ! alloc_cmdbuff(len); // will get some more ! if (ccline.cmdbuff == NULL) // out of memory { ! ccline.cmdbuff = p; // keep the old one return FAIL; } ! // There isn't always a NUL after the command, but it may need to be ! // there, thus copy up to the NUL and add a NUL. mch_memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen); ccline.cmdbuff[ccline.cmdlen] = NUL; vim_free(p); *************** *** 3150,3157 **** { int i = (int)(ccline.xpc->xp_pattern - p); ! /* If xp_pattern points inside the old cmdbuff it needs to be adjusted ! * to point into the newly allocated memory. */ if (i >= 0 && i <= ccline.cmdlen) ccline.xpc->xp_pattern = ccline.cmdbuff + i; } --- 3152,3159 ---- { int i = (int)(ccline.xpc->xp_pattern - p); ! // If xp_pattern points inside the old cmdbuff it needs to be adjusted ! // to point into the newly allocated memory. if (i >= 0 && i <= ccline.cmdlen) ccline.xpc->xp_pattern = ccline.cmdbuff + i; } *************** *** 3211,3228 **** */ if (len * 2 + 2 > buflen) { ! /* Re-allocate the buffer. We keep it around to avoid a lot of ! * alloc()/free() calls. */ vim_free(arshape_buf); buflen = len * 2 + 2; arshape_buf = alloc(buflen); if (arshape_buf == NULL) ! return; /* out of memory */ } if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) { ! /* Prepend a space to draw the leading composing char on. */ arshape_buf[0] = ' '; newlen = 1; } --- 3213,3230 ---- */ if (len * 2 + 2 > buflen) { ! // Re-allocate the buffer. We keep it around to avoid a lot of ! // alloc()/free() calls. vim_free(arshape_buf); buflen = len * 2 + 2; arshape_buf = alloc(buflen); if (arshape_buf == NULL) ! return; // out of memory } if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) { ! // Prepend a space to draw the leading composing char on. arshape_buf[0] = ' '; newlen = 1; } *************** *** 3234,3243 **** mb_l = utfc_ptr2len_len(p, start + len - j); if (ARABIC_CHAR(u8c)) { ! /* Do Arabic shaping. */ if (cmdmsg_rl) { ! /* displaying from right to left */ pc = prev_c; pc1 = prev_c1; prev_c1 = u8cc[0]; --- 3236,3245 ---- mb_l = utfc_ptr2len_len(p, start + len - j); if (ARABIC_CHAR(u8c)) { ! // Do Arabic shaping. if (cmdmsg_rl) { ! // displaying from right to left pc = prev_c; pc1 = prev_c1; prev_c1 = u8cc[0]; *************** *** 3248,3254 **** } else { ! /* displaying from left to right */ if (j + mb_l >= start + len) pc = NUL; else --- 3250,3256 ---- } else { ! // displaying from left to right if (j + mb_l >= start + len) pc = NUL; else *************** *** 3349,3355 **** if (len < 0) len = (int)STRLEN(str); ! /* Check if ccline.cmdbuff needs to be longer */ if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen) retval = realloc_cmdbuff(ccline.cmdlen + len + 1); else --- 3351,3357 ---- if (len < 0) len = (int)STRLEN(str); ! // Check if ccline.cmdbuff needs to be longer if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen) retval = realloc_cmdbuff(ccline.cmdlen + len + 1); else *************** *** 3367,3378 **** { if (has_mbyte) { ! /* Count nr of characters in the new string. */ m = 0; for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) ++m; ! /* Count nr of bytes in cmdline that are overwritten by these ! * characters. */ for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; i += (*mb_ptr2len)(ccline.cmdbuff + i)) --m; --- 3369,3380 ---- { if (has_mbyte) { ! // Count nr of characters in the new string. m = 0; for (i = 0; i < len; i += (*mb_ptr2len)(str + i)) ++m; ! // Count nr of bytes in cmdline that are overwritten by these ! // characters. for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; i += (*mb_ptr2len)(ccline.cmdbuff + i)) --m; *************** *** 3393,3401 **** if (enc_utf8) { ! /* When the inserted text starts with a composing character, ! * backup to the character before it. There could be two of them. ! */ i = 0; c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); while (ccline.cmdpos > 0 && utf_iscomposing(c)) --- 3395,3402 ---- if (enc_utf8) { ! // When the inserted text starts with a composing character, ! // backup to the character before it. There could be two of them. i = 0; c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); while (ccline.cmdpos > 0 && utf_iscomposing(c)) *************** *** 3409,3415 **** #ifdef FEAT_ARABIC if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) { ! /* Check the previous character for Arabic combining pair. */ i = (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; if (arabic_combine(utf_ptr2char(ccline.cmdbuff --- 3410,3416 ---- #ifdef FEAT_ARABIC if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) { ! // Check the previous character for Arabic combining pair. i = (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; if (arabic_combine(utf_ptr2char(ccline.cmdbuff *************** *** 3424,3430 **** #endif if (i != 0) { ! /* Also backup the cursor position. */ i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= i; msg_col -= i; --- 3425,3431 ---- #endif if (i != 0) { ! // Also backup the cursor position. i = ptr2cells(ccline.cmdbuff + ccline.cmdpos); ccline.cmdspos -= i; msg_col -= i; *************** *** 3442,3448 **** i = cmdline_row; cursorcmd(); draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); ! /* Avoid clearing the rest of the line too often. */ if (cmdline_row != i || ccline.overstrike) msg_clr_eos(); msg_no_more = FALSE; --- 3443,3449 ---- i = cmdline_row; cursorcmd(); draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos); ! // Avoid clearing the rest of the line too often. if (cmdline_row != i || ccline.overstrike) msg_clr_eos(); msg_no_more = FALSE; *************** *** 3450,3456 **** if (KeyTyped) { m = Columns * Rows; ! if (m < 0) /* overflow, Columns or Rows at weird value */ m = MAXCOL; } else --- 3451,3457 ---- if (KeyTyped) { m = Columns * Rows; ! if (m < 0) // overflow, Columns or Rows at weird value m = MAXCOL; } else *************** *** 3458,3469 **** for (i = 0; i < len; ++i) { c = cmdline_charsize(ccline.cmdpos); ! /* count ">" for a double-wide char that doesn't fit. */ if (has_mbyte) correct_cmdspos(ccline.cmdpos, c); ! /* Stop cursor at the end of the screen, but do increment the ! * insert position, so that entering a very long command ! * works, even though you can't see it. */ if (ccline.cmdspos + c < m) ccline.cmdspos += c; --- 3459,3470 ---- for (i = 0; i < len; ++i) { c = cmdline_charsize(ccline.cmdpos); ! // count ">" for a double-wide char that doesn't fit. if (has_mbyte) correct_cmdspos(ccline.cmdpos, c); ! // Stop cursor at the end of the screen, but do increment the ! // insert position, so that entering a very long command ! // works, even though you can't see it. if (ccline.cmdspos + c < m) ccline.cmdspos += c; *************** *** 3525,3547 **** static int cmdline_paste( int regname, ! int literally, /* Insert text literally instead of "as typed" */ ! int remcr) /* remove trailing CR */ { long i; char_u *arg; char_u *p; int allocated; ! /* check for valid regname; also accept special characters for CTRL-R in ! * the command line */ if (regname != Ctrl_F && regname != Ctrl_P && regname != Ctrl_W && regname != Ctrl_A && regname != Ctrl_L && !valid_yank_reg(regname, FALSE)) return FAIL; ! /* A register containing CTRL-R can cause an endless loop. Allow using ! * CTRL-C to break the loop. */ line_breakcheck(); if (got_int) return FAIL; --- 3526,3548 ---- static int cmdline_paste( int regname, ! int literally, // Insert text literally instead of "as typed" ! int remcr) // remove trailing CR { long i; char_u *arg; char_u *p; int allocated; ! // check for valid regname; also accept special characters for CTRL-R in ! // the command line if (regname != Ctrl_F && regname != Ctrl_P && regname != Ctrl_W && regname != Ctrl_A && regname != Ctrl_L && !valid_yank_reg(regname, FALSE)) return FAIL; ! // A register containing CTRL-R can cause an endless loop. Allow using ! // CTRL-C to break the loop. line_breakcheck(); if (got_int) return FAIL; *************** *** 3558,3576 **** if (i) { ! /* Got the value of a special register in "arg". */ if (arg == NULL) return FAIL; ! /* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate ! * part of the word. */ p = arg; if (p_is && regname == Ctrl_W) { char_u *w; int len; ! /* Locate start of last word in the cmd buffer. */ for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) { if (has_mbyte) --- 3559,3577 ---- if (i) { ! // Got the value of a special register in "arg". if (arg == NULL) return FAIL; ! // When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate ! // part of the word. p = arg; if (p_is && regname == Ctrl_W) { char_u *w; int len; ! // Locate start of last word in the cmd buffer. for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) { if (has_mbyte) *************** *** 3686,3692 **** { msg_puts_attr((char *)ccline.cmdprompt, ccline.cmdattr); ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; ! /* do the reverse of set_cmdspos() */ if (ccline.cmdfirstc != NUL) --ccline.cmdindent; } --- 3687,3693 ---- { msg_puts_attr((char *)ccline.cmdprompt, ccline.cmdattr); ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns; ! // do the reverse of set_cmdspos() if (ccline.cmdfirstc != NUL) --ccline.cmdindent; } *************** *** 3704,3710 **** if (cmd_silent) return; ! /* when 'incsearch' is set there may be no command line while redrawing */ if (ccline.cmdbuff == NULL) { windgoto(cmdline_row, 0); --- 3705,3711 ---- if (cmd_silent) return; ! // when 'incsearch' is set there may be no command line while redrawing if (ccline.cmdbuff == NULL) { windgoto(cmdline_row, 0); *************** *** 3715,3721 **** msg_start(); redrawcmdprompt(); ! /* Don't use more prompt, truncate the cmdline if it doesn't fit. */ msg_no_more = TRUE; draw_cmdline(0, ccline.cmdlen); msg_clr_eos(); --- 3716,3722 ---- msg_start(); redrawcmdprompt(); ! // Don't use more prompt, truncate the cmdline if it doesn't fit. msg_no_more = TRUE; draw_cmdline(0, ccline.cmdlen); msg_clr_eos(); *************** *** 3729,3738 **** * An emsg() before may have set msg_scroll. This is used in normal mode, * in cmdline mode we can reset them now. */ ! msg_scroll = FALSE; /* next message overwrites cmdline */ ! /* Typing ':' at the more prompt may set skip_redraw. We don't want this ! * in cmdline mode */ skip_redraw = FALSE; } --- 3730,3739 ---- * An emsg() before may have set msg_scroll. This is used in normal mode, * in cmdline mode we can reset them now. */ ! msg_scroll = FALSE; // next message overwrites cmdline ! // Typing ':' at the more prompt may set skip_redraw. We don't want this ! // in cmdline mode skip_redraw = FALSE; } *************** *** 3788,3796 **** msg_col = Columns - 1; else #endif ! msg_col = 0; /* always start in column 0 */ ! if (clr) /* clear the bottom line(s) */ ! msg_clr_eos(); /* will reset clear_cmdline */ windgoto(cmdline_row, 0); } --- 3789,3797 ---- msg_col = Columns - 1; else #endif ! msg_col = 0; // always start in column 0 ! if (clr) // clear the bottom line(s) ! msg_clr_eos(); // will reset clear_cmdline windgoto(cmdline_row, 0); } *************** *** 3805,3815 **** { int spos = 0; ! if (p_paste || no_abbr) /* no abbreviations or in paste mode */ return FALSE; ! /* Do not consider '<,'> be part of the mapping, skip leading whitespace. ! * Actually accepts any mark. */ while (VIM_ISWHITE(ccline.cmdbuff[spos]) && spos < ccline.cmdlen) spos++; if (ccline.cmdlen - spos > 5 --- 3806,3816 ---- { int spos = 0; ! if (p_paste || no_abbr) // no abbreviations or in paste mode return FALSE; ! // Do not consider '<,'> be part of the mapping, skip leading whitespace. ! // Actually accepts any mark. while (VIM_ISWHITE(ccline.cmdbuff[spos]) && spos < ccline.cmdlen) spos++; if (ccline.cmdlen - spos > 5 *************** *** 3818,3824 **** && ccline.cmdbuff[spos + 3] == '\'') spos += 5; else ! /* check abbreviation from the beginning of the commandline */ spos = 0; return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); --- 3819,3825 ---- && ccline.cmdbuff[spos + 3] == '\'') spos += 5; else ! // check abbreviation from the beginning of the commandline spos = 0; return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos); *************** *** 3837,3843 **** char_u buf[20]; int j = 0; ! /* Don't escape '[', '{' and '!' if they are in 'isfname'. */ for (p = PATH_ESC_CHARS; *p != NUL; ++p) if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) buf[j++] = *p; --- 3838,3844 ---- char_u buf[20]; int j = 0; ! // Don't escape '[', '{' and '!' if they are in 'isfname'. for (p = PATH_ESC_CHARS; *p != NUL; ++p) if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) buf[j++] = *p; *************** *** 3849,3864 **** { char_u *s; ! /* For csh and similar shells need to put two backslashes before '!'. ! * One is taken by Vim, one by the shell. */ s = vim_strsave_escaped(p, (char_u *)"!"); vim_free(p); p = s; } #endif ! /* '>' and '+' are special at the start of some commands, e.g. ":edit" and ! * ":write". "cd -" has a special meaning. */ if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) escape_fname(&p); --- 3850,3865 ---- { char_u *s; ! // For csh and similar shells need to put two backslashes before '!'. ! // One is taken by Vim, one by the shell. s = vim_strsave_escaped(p, (char_u *)"!"); vim_free(p); p = s; } #endif ! // '>' and '+' are special at the start of some commands, e.g. ":edit" and ! // ":write". "cd -" has a special meaning. if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL))) escape_fname(&p); *************** *** 3993,4000 **** if (p == NULL) return 1; ! /* The position is not set directly but after CTRL-\ e or CTRL-R = has ! * changed the command line. */ if (pos < 0) new_cmdpos = 0; else --- 3994,4001 ---- if (p == NULL) return 1; ! // The position is not set directly but after CTRL-\ e or CTRL-R = has ! // changed the command line. if (pos < 0) new_cmdpos = 0; else *************** *** 4077,4083 **** varnumber_T num; *str = skipwhite(*str); ! if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */ { vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE); *str += len; --- 4078,4084 ---- varnumber_T num; *str = skipwhite(*str); ! if (**str == '-' || vim_isdigit(**str)) // parse "from" part of range { vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE); *str += len; *************** *** 4085,4091 **** first = TRUE; } *str = skipwhite(*str); ! if (**str == ',') /* parse "to" part of range */ { *str = skipwhite(*str + 1); vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE); --- 4086,4092 ---- first = TRUE; } *str = skipwhite(*str); ! if (**str == ',') // parse "to" part of range { *str = skipwhite(*str + 1); vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE); *************** *** 4094,4103 **** *num2 = (int)num; *str = skipwhite(*str + len); } ! else if (!first) /* no number given at all */ return FAIL; } ! else if (first) /* only one number given */ *num2 = *num1; return OK; } --- 4095,4104 ---- *num2 = (int)num; *str = skipwhite(*str + len); } ! else if (!first) // no number given at all return FAIL; } ! else if (first) // only one number given *num2 = *num1; return OK; } *************** *** 4153,4159 **** int save_KeyTyped; #endif ! /* Can't do this recursively. Can't do it when typing a password. */ if (cmdwin_type != 0 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) || cmdline_star > 0 --- 4154,4160 ---- int save_KeyTyped; #endif ! // Can't do this recursively. Can't do it when typing a password. if (cmdwin_type != 0 # if defined(FEAT_CRYPT) || defined(FEAT_EVAL) || cmdline_star > 0 *************** *** 4240,4247 **** } } ! /* Replace the empty last line with the current command-line and put the ! * cursor there. */ ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_cursor.col = ccline.cmdpos; --- 4241,4248 ---- } } ! // Replace the empty last line with the current command-line and put the ! // cursor there. ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE); curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_cursor.col = ccline.cmdpos; *************** *** 4288,4295 **** cmdwin_type = 0; exmode_active = save_exmode; ! /* Safety check: The old window or buffer was deleted: It's a bug when ! * this happens! */ if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) { cmdwin_result = Ctrl_C; --- 4289,4296 ---- cmdwin_type = 0; exmode_active = save_exmode; ! // Safety check: The old window or buffer was deleted: It's a bug when ! // this happens! if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf)) { cmdwin_result = Ctrl_C; *************** *** 4298,4337 **** else { # if defined(FEAT_EVAL) ! /* autocmds may abort script processing */ if (aborting() && cmdwin_result != K_IGNORE) cmdwin_result = Ctrl_C; # endif ! /* Set the new command line from the cmdline buffer. */ vim_free(ccline.cmdbuff); ! if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */ { char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; if (histtype == HIST_CMD) { ! /* Execute the command directly. */ ccline.cmdbuff = vim_strsave((char_u *)p); cmdwin_result = CAR; } else { ! /* First need to cancel what we were doing. */ ccline.cmdbuff = NULL; stuffcharReadbuff(':'); stuffReadbuff((char_u *)p); stuffcharReadbuff(CAR); } } ! else if (cmdwin_result == K_XF2) /* :qa typed */ { ccline.cmdbuff = vim_strsave((char_u *)"qa"); cmdwin_result = CAR; } else if (cmdwin_result == Ctrl_C) { ! /* :q or :close, don't execute any command ! * and don't modify the cmd window. */ ccline.cmdbuff = NULL; } else --- 4299,4338 ---- else { # if defined(FEAT_EVAL) ! // autocmds may abort script processing if (aborting() && cmdwin_result != K_IGNORE) cmdwin_result = Ctrl_C; # endif ! // Set the new command line from the cmdline buffer. vim_free(ccline.cmdbuff); ! if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) // :qa[!] typed { char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!"; if (histtype == HIST_CMD) { ! // Execute the command directly. ccline.cmdbuff = vim_strsave((char_u *)p); cmdwin_result = CAR; } else { ! // First need to cancel what we were doing. ccline.cmdbuff = NULL; stuffcharReadbuff(':'); stuffReadbuff((char_u *)p); stuffcharReadbuff(CAR); } } ! else if (cmdwin_result == K_XF2) // :qa typed { ccline.cmdbuff = vim_strsave((char_u *)"qa"); cmdwin_result = CAR; } else if (cmdwin_result == Ctrl_C) { ! // :q or :close, don't execute any command ! // and don't modify the cmd window. ccline.cmdbuff = NULL; } else *** ../vim-8.1.2378/src/fileio.c 2019-12-01 15:23:07.464344509 +0100 --- src/fileio.c 2019-12-01 21:36:02.779167229 +0100 *************** *** 14,23 **** #include "vim.h" #if defined(__TANDEM) || defined(__MINT__) ! # include /* for SSIZE_MAX */ #endif ! /* Is there any system that doesn't have access()? */ #define USE_MCH_ACCESS static char_u *next_fenc(char_u **pp, int *alloced); --- 14,23 ---- #include "vim.h" #if defined(__TANDEM) || defined(__MINT__) ! # include // for SSIZE_MAX #endif ! // Is there any system that doesn't have access()? #define USE_MCH_ACCESS static char_u *next_fenc(char_u **pp, int *alloced); *************** *** 43,50 **** if (msg_silent != 0) return; ! msg_add_fname(buf, name); /* put file name in IObuff with quotes */ ! /* If it's extremely long, truncate it. */ if (STRLEN(IObuff) > IOSIZE - 80) IObuff[IOSIZE - 80] = NUL; STRCAT(IObuff, s); --- 43,50 ---- if (msg_silent != 0) return; ! msg_add_fname(buf, name); // put file name in IObuff with quotes ! // If it's extremely long, truncate it. if (STRLEN(IObuff) > IOSIZE - 80) IObuff[IOSIZE - 80] = NUL; STRCAT(IObuff, s); *************** *** 56,69 **** msg_scroll_save = msg_scroll; if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) msg_scroll = FALSE; ! if (!msg_scroll) /* wait a bit when overwriting an error msg */ check_for_delay(FALSE); msg_start(); if (prev_msg_col != 0 && msg_col == 0) msg_putchar('\r'); // overwrite any previous message. msg_scroll = msg_scroll_save; msg_scrolled_ign = TRUE; ! /* may truncate the message to avoid a hit-return prompt */ msg_outtrans_attr(msg_may_trunc(FALSE, IObuff), attr); msg_clr_eos(); out_flush(); --- 56,69 ---- msg_scroll_save = msg_scroll; if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) msg_scroll = FALSE; ! if (!msg_scroll) // wait a bit when overwriting an error msg check_for_delay(FALSE); msg_start(); if (prev_msg_col != 0 && msg_col == 0) msg_putchar('\r'); // overwrite any previous message. msg_scroll = msg_scroll_save; msg_scrolled_ign = TRUE; ! // may truncate the message to avoid a hit-return prompt msg_outtrans_attr(msg_may_trunc(FALSE, IObuff), attr); msg_clr_eos(); out_flush(); *************** *** 102,108 **** linenr_T from, linenr_T lines_to_skip, linenr_T lines_to_read, ! exarg_T *eap, /* can be NULL! */ int flags) { int fd = 0; --- 102,108 ---- linenr_T from, linenr_T lines_to_skip, linenr_T lines_to_read, ! exarg_T *eap, // can be NULL! int flags) { int fd = 0; *************** *** 114,128 **** int read_fifo = (flags & READ_FIFO); int set_options = newfile || read_buffer || (eap != NULL && eap->read_edit); ! linenr_T read_buf_lnum = 1; /* next line to read from curbuf */ ! colnr_T read_buf_col = 0; /* next char to read from this line */ char_u c; linenr_T lnum = from; ! char_u *ptr = NULL; /* pointer into read buffer */ ! char_u *buffer = NULL; /* read buffer */ ! char_u *new_buffer = NULL; /* init to shut up gcc */ ! char_u *line_start = NULL; /* init to shut up gcc */ ! int wasempty; /* buffer was empty before reading */ colnr_T len; long size = 0; char_u *p; --- 114,128 ---- int read_fifo = (flags & READ_FIFO); int set_options = newfile || read_buffer || (eap != NULL && eap->read_edit); ! linenr_T read_buf_lnum = 1; // next line to read from curbuf ! colnr_T read_buf_col = 0; // next char to read from this line char_u c; linenr_T lnum = from; ! char_u *ptr = NULL; // pointer into read buffer ! char_u *buffer = NULL; // read buffer ! char_u *new_buffer = NULL; // init to shut up gcc ! char_u *line_start = NULL; // init to shut up gcc ! int wasempty; // buffer was empty before reading colnr_T len; long size = 0; char_u *p; *************** *** 136,193 **** context_sha256_T sha_ctx; int read_undo_file = FALSE; #endif ! int split = 0; /* number of split lines */ ! #define UNKNOWN 0x0fffffff /* file size is unknown */ linenr_T linecnt; ! int error = FALSE; /* errors encountered */ ! int ff_error = EOL_UNKNOWN; /* file format with errors */ ! long linerest = 0; /* remaining chars in line */ #ifdef UNIX int perm = 0; ! int swap_mode = -1; /* protection bits for swap file */ #else int perm; #endif ! int fileformat = 0; /* end-of-line format */ int keep_fileformat = FALSE; stat_T st; int file_readonly; linenr_T skip_count = 0; linenr_T read_count = 0; int msg_save = msg_scroll; ! linenr_T read_no_eol_lnum = 0; /* non-zero lnum when last line of ! * last read was missing the eol */ int try_mac; int try_dos; int try_unix; int file_rewind = FALSE; int can_retry; ! linenr_T conv_error = 0; /* line nr with conversion error */ ! linenr_T illegal_byte = 0; /* line nr with illegal byte */ ! int keep_dest_enc = FALSE; /* don't retry when char doesn't fit ! in destination encoding */ int bad_char_behavior = BAD_REPLACE; ! /* BAD_KEEP, BAD_DROP or character to ! * replace with */ ! char_u *tmpname = NULL; /* name of 'charconvert' output file */ int fio_flags = 0; ! char_u *fenc; /* fileencoding to use */ ! int fenc_alloced; /* fenc_next is in allocated memory */ ! char_u *fenc_next = NULL; /* next item in 'fencs' or NULL */ int advance_fenc = FALSE; long real_size = 0; #ifdef USE_ICONV ! iconv_t iconv_fd = (iconv_t)-1; /* descriptor for iconv() or -1 */ # ifdef FEAT_EVAL ! int did_iconv = FALSE; /* TRUE when iconv() failed and trying ! 'charconvert' next */ # endif #endif ! int converted = FALSE; /* TRUE if conversion done */ ! int notconverted = FALSE; /* TRUE if conversion wanted but it ! wasn't possible */ char_u conv_rest[CONV_RESTLEN]; ! int conv_restlen = 0; /* nr of bytes in conv_rest[] */ pos_T orig_start; buf_T *old_curbuf; char_u *old_b_ffname; --- 136,193 ---- context_sha256_T sha_ctx; int read_undo_file = FALSE; #endif ! int split = 0; // number of split lines ! #define UNKNOWN 0x0fffffff // file size is unknown linenr_T linecnt; ! int error = FALSE; // errors encountered ! int ff_error = EOL_UNKNOWN; // file format with errors ! long linerest = 0; // remaining chars in line #ifdef UNIX int perm = 0; ! int swap_mode = -1; // protection bits for swap file #else int perm; #endif ! int fileformat = 0; // end-of-line format int keep_fileformat = FALSE; stat_T st; int file_readonly; linenr_T skip_count = 0; linenr_T read_count = 0; int msg_save = msg_scroll; ! linenr_T read_no_eol_lnum = 0; // non-zero lnum when last line of ! // last read was missing the eol int try_mac; int try_dos; int try_unix; int file_rewind = FALSE; int can_retry; ! linenr_T conv_error = 0; // line nr with conversion error ! linenr_T illegal_byte = 0; // line nr with illegal byte ! int keep_dest_enc = FALSE; // don't retry when char doesn't fit ! // in destination encoding int bad_char_behavior = BAD_REPLACE; ! // BAD_KEEP, BAD_DROP or character to ! // replace with ! char_u *tmpname = NULL; // name of 'charconvert' output file int fio_flags = 0; ! char_u *fenc; // fileencoding to use ! int fenc_alloced; // fenc_next is in allocated memory ! char_u *fenc_next = NULL; // next item in 'fencs' or NULL int advance_fenc = FALSE; long real_size = 0; #ifdef USE_ICONV ! iconv_t iconv_fd = (iconv_t)-1; // descriptor for iconv() or -1 # ifdef FEAT_EVAL ! int did_iconv = FALSE; // TRUE when iconv() failed and trying ! // 'charconvert' next # endif #endif ! int converted = FALSE; // TRUE if conversion done ! int notconverted = FALSE; // TRUE if conversion wanted but it ! // wasn't possible char_u conv_rest[CONV_RESTLEN]; ! int conv_restlen = 0; // nr of bytes in conv_rest[] pos_T orig_start; buf_T *old_curbuf; char_u *old_b_ffname; *************** *** 195,203 **** int using_b_ffname; int using_b_fname; ! au_did_filetype = FALSE; /* reset before triggering any autocommands */ ! curbuf->b_no_eol_lnum = 0; /* in case it was set by the previous read */ /* * If there is no file name yet, use the one for the read file. --- 195,203 ---- int using_b_ffname; int using_b_fname; ! au_did_filetype = FALSE; // reset before triggering any autocommands ! curbuf->b_no_eol_lnum = 0; // in case it was set by the previous read /* * If there is no file name yet, use the one for the read file. *************** *** 215,224 **** return FAIL; } ! /* Remember the initial values of curbuf, curbuf->b_ffname and ! * curbuf->b_fname to detect whether they are altered as a result of ! * executing nasty autocommands. Also check if "fname" and "sfname" ! * point to one of these values. */ old_curbuf = curbuf; old_b_ffname = curbuf->b_ffname; old_b_fname = curbuf->b_fname; --- 215,224 ---- return FAIL; } ! // Remember the initial values of curbuf, curbuf->b_ffname and ! // curbuf->b_fname to detect whether they are altered as a result of ! // executing nasty autocommands. Also check if "fname" and "sfname" ! // point to one of these values. old_curbuf = curbuf; old_b_ffname = curbuf->b_ffname; old_b_fname = curbuf->b_fname; *************** *** 226,236 **** || (sfname == curbuf->b_ffname); using_b_fname = (fname == curbuf->b_fname) || (sfname == curbuf->b_fname); ! /* After reading a file the cursor line changes but we don't want to ! * display the line. */ ex_no_reprint = TRUE; ! /* don't display the file info for another buffer now */ need_fileinfo = FALSE; /* --- 226,236 ---- || (sfname == curbuf->b_ffname); using_b_fname = (fname == curbuf->b_fname) || (sfname == curbuf->b_fname); ! // After reading a file the cursor line changes but we don't want to ! // display the line. ex_no_reprint = TRUE; ! // don't display the file info for another buffer now need_fileinfo = FALSE; /* *************** *** 253,259 **** { orig_start = curbuf->b_op_start; ! /* Set '[ mark to the line above where the lines go (line 1 if zero). */ curbuf->b_op_start.lnum = ((from == 0) ? 1 : from); curbuf->b_op_start.col = 0; --- 253,259 ---- { orig_start = curbuf->b_op_start; ! // Set '[ mark to the line above where the lines go (line 1 if zero). curbuf->b_op_start.lnum = ((from == 0) ? 1 : from); curbuf->b_op_start.col = 0; *************** *** 279,287 **** } if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0) ! msg_scroll = FALSE; /* overwrite previous file message */ else ! msg_scroll = TRUE; /* don't overwrite previous file message */ /* * If the name ends in a path separator, we can't open it. Check here, --- 279,287 ---- } if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0) ! msg_scroll = FALSE; // overwrite previous file message else ! msg_scroll = TRUE; // don't overwrite previous file message /* * If the name ends in a path separator, we can't open it. Check here, *************** *** 309,320 **** * check for it before the mch_open(). */ perm = mch_getperm(fname); ! if (perm >= 0 && !S_ISREG(perm) /* not a regular file ... */ ! && !S_ISFIFO(perm) /* ... or fifo */ ! && !S_ISSOCK(perm) /* ... or socket */ # ifdef OPEN_CHR_FILES && !(S_ISCHR(perm) && is_dev_fd_file(fname)) ! /* ... or a character special file named /dev/fd/ */ # endif ) { --- 309,320 ---- * check for it before the mch_open(). */ perm = mch_getperm(fname); ! if (perm >= 0 && !S_ISREG(perm) // not a regular file ... ! && !S_ISFIFO(perm) // ... or fifo ! && !S_ISSOCK(perm) // ... or socket # ifdef OPEN_CHR_FILES && !(S_ISCHR(perm) && is_dev_fd_file(fname)) ! // ... or a character special file named /dev/fd/ # endif ) { *************** *** 347,353 **** #endif } ! /* Set default or forced 'fileformat' and 'binary'. */ set_file_options(set_options, eap); /* --- 347,353 ---- #endif } ! // Set default or forced 'fileformat' and 'binary'. set_file_options(set_options, eap); /* *************** *** 362,368 **** if (newfile && !read_stdin && !read_buffer && !read_fifo) { ! /* Remember time of file. */ if (mch_stat((char *)fname, &st) >= 0) { buf_store_time(curbuf, &st, fname); --- 362,368 ---- if (newfile && !read_stdin && !read_buffer && !read_fifo) { ! // Remember time of file. if (mch_stat((char *)fname, &st) >= 0) { buf_store_time(curbuf, &st, fname); *************** *** 382,390 **** swap_mode = (st.st_mode & 0644) | 0600; #endif #ifdef FEAT_CW_EDITOR ! /* Get the FSSpec on MacOS ! * TODO: Update it properly when the buffer name changes ! */ (void)GetFSSpecFromPath(curbuf->b_ffname, &curbuf->b_FSSpec); #endif #ifdef VMS --- 382,389 ---- swap_mode = (st.st_mode & 0644) | 0600; #endif #ifdef FEAT_CW_EDITOR ! // Get the FSSpec on MacOS ! // TODO: Update it properly when the buffer name changes (void)GetFSSpecFromPath(curbuf->b_ffname, &curbuf->b_FSSpec); #endif #ifdef VMS *************** *** 401,408 **** curbuf->b_orig_mode = 0; } ! /* Reset the "new file" flag. It will be set again below when the ! * file doesn't exist. */ curbuf->b_flags &= ~(BF_NEW | BF_NEW_W); } --- 400,407 ---- curbuf->b_orig_mode = 0; } ! // Reset the "new file" flag. It will be set again below when the ! // file doesn't exist. curbuf->b_flags &= ~(BF_NEW | BF_NEW_W); } *************** *** 414,420 **** if (read_stdin) { #if defined(MSWIN) ! /* Force binary I/O on stdin to avoid CR-LF -> LF conversion. */ setmode(0, O_BINARY); #endif } --- 413,419 ---- if (read_stdin) { #if defined(MSWIN) ! // Force binary I/O on stdin to avoid CR-LF -> LF conversion. setmode(0, O_BINARY); #endif } *************** *** 434,446 **** || (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0) { file_readonly = TRUE; ! /* try to open ro */ fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); } #endif } ! if (fd < 0) /* cannot open at all */ { #ifndef UNIX int isdir_f; --- 433,445 ---- || (fd = mch_open((char *)fname, O_RDWR | O_EXTRA, 0)) < 0) { file_readonly = TRUE; ! // try to open ro fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); } #endif } ! if (fd < 0) // cannot open at all { #ifndef UNIX int isdir_f; *************** *** 451,461 **** * On Amiga we can't open a directory, check here. */ isdir_f = (mch_isdir(fname)); ! perm = mch_getperm(fname); /* check if the file exists */ if (isdir_f) { filemess(curbuf, sfname, (char_u *)_("is a directory"), 0); ! curbuf->b_p_ro = TRUE; /* must use "w!" now */ } else #endif --- 450,460 ---- * On Amiga we can't open a directory, check here. */ isdir_f = (mch_isdir(fname)); ! perm = mch_getperm(fname); // check if the file exists if (isdir_f) { filemess(curbuf, sfname, (char_u *)_("is a directory"), 0); ! curbuf->b_p_ro = TRUE; // must use "w!" now } else #endif *************** *** 473,487 **** */ curbuf->b_flags |= BF_NEW; ! /* Create a swap file now, so that other Vims are warned ! * that we are editing this file. Don't do this for a ! * "nofile" or "nowrite" buffer type. */ #ifdef FEAT_QUICKFIX if (!bt_dontwrite(curbuf)) #endif { check_need_swap(newfile); ! /* SwapExists autocommand may mess things up */ if (curbuf != old_curbuf || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) --- 472,486 ---- */ curbuf->b_flags |= BF_NEW; ! // Create a swap file now, so that other Vims are warned ! // that we are editing this file. Don't do this for a ! // "nofile" or "nowrite" buffer type. #ifdef FEAT_QUICKFIX if (!bt_dontwrite(curbuf)) #endif { check_need_swap(newfile); ! // SwapExists autocommand may mess things up if (curbuf != old_curbuf || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) *************** *** 498,520 **** filemess(curbuf, sfname, (char_u *)_("[New DIRECTORY]"), 0); #ifdef FEAT_VIMINFO ! /* Even though this is a new file, it might have been ! * edited before and deleted. Get the old marks. */ check_marks_read(); #endif ! /* Set forced 'fileencoding'. */ if (eap != NULL) set_forced_fenc(eap); apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, FALSE, curbuf, eap); ! /* remember the current fileformat */ save_file_ff(curbuf); #if defined(FEAT_EVAL) ! if (aborting()) /* autocmds may abort script processing */ return FAIL; #endif ! return OK; /* a new file is not an error */ } else { --- 497,519 ---- filemess(curbuf, sfname, (char_u *)_("[New DIRECTORY]"), 0); #ifdef FEAT_VIMINFO ! // Even though this is a new file, it might have been ! // edited before and deleted. Get the old marks. check_marks_read(); #endif ! // Set forced 'fileencoding'. if (eap != NULL) set_forced_fenc(eap); apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, FALSE, curbuf, eap); ! // remember the current fileformat save_file_ff(curbuf); #if defined(FEAT_EVAL) ! if (aborting()) // autocmds may abort script processing return FAIL; #endif ! return OK; // a new file is not an error } else { *************** *** 526,532 **** (errno == EOVERFLOW) ? _("[File too big]") : # endif _("[Permission Denied]")), 0); ! curbuf->b_p_ro = TRUE; /* must use "w!" now */ } } --- 525,531 ---- (errno == EOVERFLOW) ? _("[File too big]") : # endif _("[Permission Denied]")), 0); ! curbuf->b_p_ro = TRUE; // must use "w!" now } } *************** *** 542,549 **** if (set_options) { ! /* Don't change 'eol' if reading from buffer as it will already be ! * correctly set when reading stdin. */ if (!read_buffer) { curbuf->b_p_eol = TRUE; --- 541,548 ---- if (set_options) { ! // Don't change 'eol' if reading from buffer as it will already be ! // correctly set when reading stdin. if (!read_buffer) { curbuf->b_p_eol = TRUE; *************** *** 553,561 **** curbuf->b_start_bomb = FALSE; } ! /* Create a swap file now, so that other Vims are warned that we are ! * editing this file. ! * Don't do this for a "nofile" or "nowrite" buffer type. */ #ifdef FEAT_QUICKFIX if (!bt_dontwrite(curbuf)) #endif --- 552,560 ---- curbuf->b_start_bomb = FALSE; } ! // Create a swap file now, so that other Vims are warned that we are ! // editing this file. ! // Don't do this for a "nofile" or "nowrite" buffer type. #ifdef FEAT_QUICKFIX if (!bt_dontwrite(curbuf)) #endif *************** *** 571,577 **** return FAIL; } #ifdef UNIX ! /* Set swap file protection bits after creating it. */ if (swap_mode > 0 && curbuf->b_ml.ml_mfp != NULL && curbuf->b_ml.ml_mfp->mf_fname != NULL) { --- 570,576 ---- return FAIL; } #ifdef UNIX ! // Set swap file protection bits after creating it. if (swap_mode > 0 && curbuf->b_ml.ml_mfp != NULL && curbuf->b_ml.ml_mfp->mf_fname != NULL) { *************** *** 611,617 **** return FAIL; } ! ++no_wait_return; /* don't wait for return yet */ /* * Set '[ mark to the line above where the lines go (line 1 if zero). --- 610,616 ---- return FAIL; } ! ++no_wait_return; // don't wait for return yet /* * Set '[ mark to the line above where the lines go (line 1 if zero). *************** *** 634,640 **** * the file before reading it. */ if (!read_stdin) ! close(fd); /* ignore errors */ /* * The output from the autocommands should not overwrite anything and --- 633,639 ---- * the file before reading it. */ if (!read_stdin) ! close(fd); // ignore errors /* * The output from the autocommands should not overwrite anything and *************** *** 654,660 **** else apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname, FALSE, NULL, eap); ! /* autocommands may have changed it */ try_mac = (vim_strchr(p_ffs, 'm') != NULL); try_dos = (vim_strchr(p_ffs, 'd') != NULL); try_unix = (vim_strchr(p_ffs, 'x') != NULL); --- 653,659 ---- else apply_autocmds_exarg(EVENT_FILEREADPRE, sfname, sfname, FALSE, NULL, eap); ! // autocommands may have changed it try_mac = (vim_strchr(p_ffs, 'm') != NULL); try_dos = (vim_strchr(p_ffs, 'd') != NULL); try_unix = (vim_strchr(p_ffs, 'x') != NULL); *************** *** 664,674 **** msg_scroll = m; #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ { --no_wait_return; msg_scroll = msg_save; ! curbuf->b_p_ro = TRUE; /* must use "w!" now */ return FAIL; } #endif --- 663,673 ---- msg_scroll = m; #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing { --no_wait_return; msg_scroll = msg_save; ! curbuf->b_p_ro = TRUE; // must use "w!" now return FAIL; } #endif *************** *** 690,701 **** emsg(_("E200: *ReadPre autocommands made the file unreadable")); else emsg(_("E201: *ReadPre autocommands must not change current buffer")); ! curbuf->b_p_ro = TRUE; /* must use "w!" now */ return FAIL; } } ! /* Autocommands may add lines to the file, need to check if it is empty */ wasempty = (curbuf->b_ml.ml_flags & ML_EMPTY); if (!recoverymode && !filtering && !(flags & READ_DUMMY)) --- 689,700 ---- emsg(_("E200: *ReadPre autocommands made the file unreadable")); else emsg(_("E201: *ReadPre autocommands must not change current buffer")); ! curbuf->b_p_ro = TRUE; // must use "w!" now return FAIL; } } ! // Autocommands may add lines to the file, need to check if it is empty wasempty = (curbuf->b_ml.ml_flags & ML_EMPTY); if (!recoverymode && !filtering && !(flags & READ_DUMMY)) *************** *** 717,723 **** mch_msg(_("Vim: Reading from stdin...\n")); #endif #ifdef FEAT_GUI ! /* Also write a message in the GUI window, if there is one. */ if (gui.in_use && !gui.dying && !gui.starting) { p = (char_u *)_("Reading from stdin..."); --- 716,722 ---- mch_msg(_("Vim: Reading from stdin...\n")); #endif #ifdef FEAT_GUI ! // Also write a message in the GUI window, if there is one. if (gui.in_use && !gui.dying && !gui.starting) { p = (char_u *)_("Reading from stdin..."); *************** *** 730,736 **** filemess(curbuf, sfname, (char_u *)"", 0); } ! msg_scroll = FALSE; /* overwrite the file message */ /* * Set linecnt now, before the "retry" caused by a wrong guess for --- 729,735 ---- filemess(curbuf, sfname, (char_u *)"", 0); } ! msg_scroll = FALSE; // overwrite the file message /* * Set linecnt now, before the "retry" caused by a wrong guess for *************** *** 738,744 **** */ linecnt = curbuf->b_ml.ml_line_count; ! /* "++bad=" argument. */ if (eap != NULL && eap->bad_char != 0) { bad_char_behavior = eap->bad_char; --- 737,743 ---- */ linecnt = curbuf->b_ml.ml_line_count; ! // "++bad=" argument. if (eap != NULL && eap->bad_char != 0) { bad_char_behavior = eap->bad_char; *************** *** 759,765 **** } else if (curbuf->b_p_bin) { ! fenc = (char_u *)""; /* binary: don't convert */ fenc_alloced = FALSE; } else if (curbuf->b_help) --- 758,764 ---- } else if (curbuf->b_p_bin) { ! fenc = (char_u *)""; // binary: don't convert fenc_alloced = FALSE; } else if (curbuf->b_help) *************** *** 767,778 **** char_u firstline[80]; int fc; ! /* Help files are either utf-8 or latin1. Try utf-8 first, if this ! * fails it must be latin1. ! * Always do this when 'encoding' is "utf-8". Otherwise only do ! * this when needed to avoid [converted] remarks all the time. ! * It is needed when the first line contains non-ASCII characters. ! * That is only in *.??x files. */ fenc = (char_u *)"latin1"; c = enc_utf8; if (!c && !read_stdin) --- 766,777 ---- char_u firstline[80]; int fc; ! // Help files are either utf-8 or latin1. Try utf-8 first, if this ! // fails it must be latin1. ! // Always do this when 'encoding' is "utf-8". Otherwise only do ! // this when needed to avoid [converted] remarks all the time. ! // It is needed when the first line contains non-ASCII characters. ! // That is only in *.??x files. fenc = (char_u *)"latin1"; c = enc_utf8; if (!c && !read_stdin) *************** *** 780,787 **** fc = fname[STRLEN(fname) - 1]; if (TOLOWER_ASC(fc) == 'x') { ! /* Read the first line (and a bit more). Immediately rewind to ! * the start of the file. If the read() fails "len" is -1. */ len = read_eintr(fd, firstline, 80); vim_lseek(fd, (off_T)0L, SEEK_SET); for (p = firstline; p < firstline + len; ++p) --- 779,786 ---- fc = fname[STRLEN(fname) - 1]; if (TOLOWER_ASC(fc) == 'x') { ! // Read the first line (and a bit more). Immediately rewind to ! // the start of the file. If the read() fails "len" is -1. len = read_eintr(fd, firstline, 80); vim_lseek(fd, (off_T)0L, SEEK_SET); for (p = firstline; p < firstline + len; ++p) *************** *** 798,806 **** fenc_next = fenc; fenc = (char_u *)"utf-8"; ! /* When the file is utf-8 but a character doesn't fit in ! * 'encoding' don't retry. In help text editing utf-8 bytes ! * doesn't make sense. */ if (!enc_utf8) keep_dest_enc = TRUE; } --- 797,805 ---- fenc_next = fenc; fenc = (char_u *)"utf-8"; ! // When the file is utf-8 but a character doesn't fit in ! // 'encoding' don't retry. In help text editing utf-8 bytes ! // doesn't make sense. if (!enc_utf8) keep_dest_enc = TRUE; } *************** *** 808,819 **** } else if (*p_fencs == NUL) { ! fenc = curbuf->b_p_fenc; /* use format from buffer */ fenc_alloced = FALSE; } else { ! fenc_next = p_fencs; /* try items in 'fileencodings' */ fenc = next_fenc(&fenc_next, &fenc_alloced); } --- 807,818 ---- } else if (*p_fencs == NUL) { ! fenc = curbuf->b_p_fenc; // use format from buffer fenc_alloced = FALSE; } else { ! fenc_next = p_fencs; // try items in 'fileencodings' fenc = next_fenc(&fenc_next, &fenc_alloced); } *************** *** 847,857 **** } else if (read_stdin || vim_lseek(fd, (off_T)0L, SEEK_SET) != 0) { ! /* Can't rewind the file, give up. */ error = TRUE; goto failed; } ! /* Delete the previously read lines. */ while (lnum > from) ml_delete(lnum--, FALSE); file_rewind = FALSE; --- 846,856 ---- } else if (read_stdin || vim_lseek(fd, (off_T)0L, SEEK_SET) != 0) { ! // Can't rewind the file, give up. error = TRUE; goto failed; } ! // Delete the previously read lines. while (lnum > from) ml_delete(lnum--, FALSE); file_rewind = FALSE; *************** *** 877,893 **** try_unix = try_dos = try_mac = FALSE; } else if (curbuf->b_p_bin) ! fileformat = EOL_UNIX; /* binary: use Unix format */ else if (*p_ffs == NUL) ! fileformat = get_fileformat(curbuf);/* use format from buffer */ else ! fileformat = EOL_UNKNOWN; /* detect from file */ } #ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) { ! /* aborted conversion with iconv(), close the descriptor */ iconv_close(iconv_fd); iconv_fd = (iconv_t)-1; } --- 876,892 ---- try_unix = try_dos = try_mac = FALSE; } else if (curbuf->b_p_bin) ! fileformat = EOL_UNIX; // binary: use Unix format else if (*p_ffs == NUL) ! fileformat = get_fileformat(curbuf);// use format from buffer else ! fileformat = EOL_UNKNOWN; // detect from file } #ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) { ! // aborted conversion with iconv(), close the descriptor iconv_close(iconv_fd); iconv_fd = (iconv_t)-1; } *************** *** 902,909 **** if (eap != NULL && eap->force_enc != 0) { ! /* Conversion given with "++cc=" wasn't possible, read ! * without conversion. */ notconverted = TRUE; conv_error = 0; if (fenc_alloced) --- 901,908 ---- if (eap != NULL && eap->force_enc != 0) { ! // Conversion given with "++cc=" wasn't possible, read ! // without conversion. notconverted = TRUE; conv_error = 0; if (fenc_alloced) *************** *** 927,933 **** } if (tmpname != NULL) { ! mch_remove(tmpname); /* delete converted file */ VIM_CLEAR(tmpname); } } --- 926,932 ---- } if (tmpname != NULL) { ! mch_remove(tmpname); // delete converted file VIM_CLEAR(tmpname); } } *************** *** 941,948 **** if (converted) { ! /* "ucs-bom" means we need to check the first bytes of the file ! * for a BOM. */ if (STRCMP(fenc, ENC_UCSBOM) == 0) fio_flags = FIO_UCSBOM; --- 940,947 ---- if (converted) { ! // "ucs-bom" means we need to check the first bytes of the file ! // for a BOM. if (STRCMP(fenc, ENC_UCSBOM) == 0) fio_flags = FIO_UCSBOM; *************** *** 968,974 **** #endif #ifdef MACOS_CONVERT ! /* Conversion from Apple MacRoman to latin1 or UTF-8 */ if (fio_flags == 0) fio_flags = get_mac_fio_flags(fenc); #endif --- 967,973 ---- #endif #ifdef MACOS_CONVERT ! // Conversion from Apple MacRoman to latin1 or UTF-8 if (fio_flags == 0) fio_flags = get_mac_fio_flags(fenc); #endif *************** *** 1001,1018 **** # ifdef USE_ICONV did_iconv = FALSE; # endif ! /* Skip conversion when it's already done (retry for wrong ! * "fileformat"). */ if (tmpname == NULL) { tmpname = readfile_charconvert(fname, fenc, &fd); if (tmpname == NULL) { ! /* Conversion failed. Try another one. */ advance_fenc = TRUE; if (fd < 0) { ! /* Re-opening the original file failed! */ emsg(_("E202: Conversion made file unreadable!")); error = TRUE; goto failed; --- 1000,1017 ---- # ifdef USE_ICONV did_iconv = FALSE; # endif ! // Skip conversion when it's already done (retry for wrong ! // "fileformat"). if (tmpname == NULL) { tmpname = readfile_charconvert(fname, fenc, &fd); if (tmpname == NULL) { ! // Conversion failed. Try another one. advance_fenc = TRUE; if (fd < 0) { ! // Re-opening the original file failed! emsg(_("E202: Conversion made file unreadable!")); error = TRUE; goto failed; *************** *** 1030,1046 **** #endif ) { ! /* Conversion wanted but we can't. ! * Try the next conversion in 'fileencodings' */ advance_fenc = TRUE; goto retry; } } } ! /* Set "can_retry" when it's possible to rewind the file and try with ! * another "fenc" value. It's FALSE when no other "fenc" to try, reading ! * stdin or fixed at a specific encoding. */ can_retry = (*fenc != NUL && !read_stdin && !read_fifo && !keep_dest_enc); if (!skip_read) --- 1029,1045 ---- #endif ) { ! // Conversion wanted but we can't. ! // Try the next conversion in 'fileencodings' advance_fenc = TRUE; goto retry; } } } ! // Set "can_retry" when it's possible to rewind the file and try with ! // another "fenc" value. It's FALSE when no other "fenc" to try, reading ! // stdin or fixed at a specific encoding. can_retry = (*fenc != NUL && !read_stdin && !read_fifo && !keep_dest_enc); if (!skip_read) *************** *** 1064,1071 **** #ifdef FEAT_CRYPT if (curbuf->b_cryptstate != NULL) { ! /* Need to free the state, but keep the key, don't want to ask for ! * it again. */ crypt_free_state(curbuf->b_cryptstate); curbuf->b_cryptstate = NULL; } --- 1063,1070 ---- #ifdef FEAT_CRYPT if (curbuf->b_cryptstate != NULL) { ! // Need to free the state, but keep the key, don't want to ask for ! // it again. crypt_free_state(curbuf->b_cryptstate); curbuf->b_cryptstate = NULL; } *************** *** 1083,1105 **** if (!skip_read) { #if defined(SSIZE_MAX) && (SSIZE_MAX < 0x10000L) ! size = SSIZE_MAX; /* use max I/O size, 52K */ #else ! /* Use buffer >= 64K. Add linerest to double the size if the ! * line gets very long, to avoid a lot of copying. But don't ! * read more than 1 Mbyte at a time, so we can be interrupted. ! */ size = 0x10000L + linerest; if (size > 0x100000L) size = 0x100000L; #endif } ! /* Protect against the argument of lalloc() going negative. */ if (size < 0 || size + linerest + 1 < 0 || linerest >= MAXCOL) { ++split; ! *ptr = NL; /* split line by inserting a NL */ size = 1; } else --- 1082,1103 ---- if (!skip_read) { #if defined(SSIZE_MAX) && (SSIZE_MAX < 0x10000L) ! size = SSIZE_MAX; // use max I/O size, 52K #else ! // Use buffer >= 64K. Add linerest to double the size if the ! // line gets very long, to avoid a lot of copying. But don't ! // read more than 1 Mbyte at a time, so we can be interrupted. size = 0x10000L + linerest; if (size > 0x100000L) size = 0x100000L; #endif } ! // Protect against the argument of lalloc() going negative. if (size < 0 || size + linerest + 1 < 0 || linerest >= MAXCOL) { ++split; ! *ptr = NL; // split line by inserting a NL size = 1; } else *************** *** 1118,1140 **** error = TRUE; break; } ! if (linerest) /* copy characters from the previous buffer */ mch_memmove(new_buffer, ptr - linerest, (size_t)linerest); vim_free(buffer); buffer = new_buffer; ptr = buffer + linerest; line_start = buffer; ! /* May need room to translate into. ! * For iconv() we don't really know the required space, use a ! * factor ICONV_MULT. ! * latin1 to utf-8: 1 byte becomes up to 2 bytes ! * utf-16 to utf-8: 2 bytes become up to 3 bytes, 4 bytes ! * become up to 4 bytes, size must be multiple of 2 ! * ucs-2 to utf-8: 2 bytes become up to 3 bytes, size must be ! * multiple of 2 ! * ucs-4 to utf-8: 4 bytes become up to 6 bytes, size must be ! * multiple of 4 */ real_size = (int)size; #ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) --- 1116,1138 ---- error = TRUE; break; } ! if (linerest) // copy characters from the previous buffer mch_memmove(new_buffer, ptr - linerest, (size_t)linerest); vim_free(buffer); buffer = new_buffer; ptr = buffer + linerest; line_start = buffer; ! // May need room to translate into. ! // For iconv() we don't really know the required space, use a ! // factor ICONV_MULT. ! // latin1 to utf-8: 1 byte becomes up to 2 bytes ! // utf-16 to utf-8: 2 bytes become up to 3 bytes, 4 bytes ! // become up to 4 bytes, size must be multiple of 2 ! // ucs-2 to utf-8: 2 bytes become up to 3 bytes, size must be ! // multiple of 2 ! // ucs-4 to utf-8: 4 bytes become up to 6 bytes, size must be ! // multiple of 4 real_size = (int)size; #ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) *************** *** 1148,1166 **** else if (fio_flags & FIO_UCS4) size = (size * 2 / 3) & ~3; else if (fio_flags == FIO_UCSBOM) ! size = size / ICONV_MULT; /* worst case */ #ifdef MSWIN else if (fio_flags & FIO_CODEPAGE) ! size = size / ICONV_MULT; /* also worst case */ #endif #ifdef MACOS_CONVERT else if (fio_flags & FIO_MACROMAN) ! size = size / ICONV_MULT; /* also worst case */ #endif if (conv_restlen > 0) { ! /* Insert unconverted bytes from previous line. */ mch_memmove(ptr, conv_rest, conv_restlen); ptr += conv_restlen; size -= conv_restlen; --- 1146,1164 ---- else if (fio_flags & FIO_UCS4) size = (size * 2 / 3) & ~3; else if (fio_flags == FIO_UCSBOM) ! size = size / ICONV_MULT; // worst case #ifdef MSWIN else if (fio_flags & FIO_CODEPAGE) ! size = size / ICONV_MULT; // also worst case #endif #ifdef MACOS_CONVERT else if (fio_flags & FIO_MACROMAN) ! size = size / ICONV_MULT; // also worst case #endif if (conv_restlen > 0) { ! // Insert unconverted bytes from previous line. mch_memmove(ptr, conv_rest, conv_restlen); ptr += conv_restlen; size -= conv_restlen; *************** *** 1186,1194 **** n = (int)STRLEN(p); if ((int)tlen + n + 1 > size) { ! /* Filled up to "size", append partial line. ! * Change NL to NUL to reverse the effect done ! * below. */ n = (int)(size - tlen); for (ni = 0; ni < n; ++ni) { --- 1184,1192 ---- n = (int)STRLEN(p); if ((int)tlen + n + 1 > size) { ! // Filled up to "size", append partial line. ! // Change NL to NUL to reverse the effect done ! // below. n = (int)(size - tlen); for (ni = 0; ni < n; ++ni) { *************** *** 1202,1209 **** } else { ! /* Append whole line and new-line. Change NL ! * to NUL to reverse the effect done below. */ for (ni = 0; ni < n; ++ni) { if (p[ni] == NL) --- 1200,1207 ---- } else { ! // Append whole line and new-line. Change NL ! // to NUL to reverse the effect done below. for (ni = 0; ni < n; ++ni) { if (p[ni] == NL) *************** *** 1215,1222 **** read_buf_col = 0; if (++read_buf_lnum > from) { ! /* When the last line didn't have an ! * end-of-line don't add it now either. */ if (!curbuf->b_p_eol) --tlen; size = tlen; --- 1213,1220 ---- read_buf_col = 0; if (++read_buf_lnum > from) { ! // When the last line didn't have an ! // end-of-line don't add it now either. if (!curbuf->b_p_eol) --tlen; size = tlen; *************** *** 1264,1285 **** decrypted_size = crypt_decode_alloc( curbuf->b_cryptstate, ptr, size, &newptr); ! /* If the crypt layer is buffering, not producing ! * anything yet, need to read more. */ if (decrypted_size == 0) continue; if (linerest == 0) { ! /* Simple case: reuse returned buffer (may be ! * NULL, checked later). */ new_buffer = newptr; } else { long_u new_size; ! /* Need new buffer to add bytes carried over. */ new_size = (long_u)(decrypted_size + linerest + 1); new_buffer = lalloc(new_size, FALSE); if (new_buffer == NULL) --- 1262,1283 ---- decrypted_size = crypt_decode_alloc( curbuf->b_cryptstate, ptr, size, &newptr); ! // If the crypt layer is buffering, not producing ! // anything yet, need to read more. if (decrypted_size == 0) continue; if (linerest == 0) { ! // Simple case: reuse returned buffer (may be ! // NULL, checked later). new_buffer = newptr; } else { long_u new_size; ! // Need new buffer to add bytes carried over. new_size = (long_u)(decrypted_size + linerest + 1); new_buffer = lalloc(new_size, FALSE); if (new_buffer == NULL) *************** *** 1311,1317 **** if (size <= 0) { ! if (size < 0) /* read error */ error = TRUE; else if (conv_restlen > 0) { --- 1309,1315 ---- if (size <= 0) { ! if (size < 0) // read error error = TRUE; else if (conv_restlen > 0) { *************** *** 1320,1326 **** * not be converted. Truncated file? */ ! /* When we did a conversion report an error. */ if (fio_flags != 0 #ifdef USE_ICONV || iconv_fd != (iconv_t)-1 --- 1318,1324 ---- * not be converted. Truncated file? */ ! // When we did a conversion report an error. if (fio_flags != 0 #ifdef USE_ICONV || iconv_fd != (iconv_t)-1 *************** *** 1333,1339 **** conv_error = curbuf->b_ml.ml_line_count - linecnt + 1; } ! /* Remember the first linenr with an illegal byte */ else if (illegal_byte == 0) illegal_byte = curbuf->b_ml.ml_line_count - linecnt + 1; --- 1331,1337 ---- conv_error = curbuf->b_ml.ml_line_count - linecnt + 1; } ! // Remember the first linenr with an illegal byte else if (illegal_byte == 0) illegal_byte = curbuf->b_ml.ml_line_count - linecnt + 1; *************** *** 1344,1353 **** } else { ! /* Replace the trailing bytes with the replacement ! * character if we were converting; if we weren't, ! * leave the UTF8 checking code to do it, as it ! * works slightly differently. */ if (bad_char_behavior != BAD_KEEP && (fio_flags != 0 #ifdef USE_ICONV || iconv_fd != (iconv_t)-1 --- 1342,1351 ---- } else { ! // Replace the trailing bytes with the replacement ! // character if we were converting; if we weren't, ! // leave the UTF8 checking code to do it, as it ! // works slightly differently. if (bad_char_behavior != BAD_KEEP && (fio_flags != 0 #ifdef USE_ICONV || iconv_fd != (iconv_t)-1 *************** *** 1360,1366 **** --conv_restlen; } } ! fio_flags = 0; /* don't convert this */ #ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) { --- 1358,1364 ---- --conv_restlen; } } ! fio_flags = 0; // don't convert this #ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) { *************** *** 1395,1401 **** char_u *ccname; int blen; ! /* no BOM detection in a short file or in binary mode */ if (size < 2 || curbuf->b_p_bin) ccname = NULL; else --- 1393,1399 ---- char_u *ccname; int blen; ! // no BOM detection in a short file or in binary mode if (size < 2 || curbuf->b_p_bin) ccname = NULL; else *************** *** 1403,1409 **** fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc)); if (ccname != NULL) { ! /* Remove BOM from the text */ filesize += blen; size -= blen; mch_memmove(ptr, ptr + blen, (size_t)size); --- 1401,1407 ---- fio_flags == FIO_UCSBOM ? FIO_ALL : get_fio_flags(fenc)); if (ccname != NULL) { ! // Remove BOM from the text filesize += blen; size -= blen; mch_memmove(ptr, ptr + blen, (size_t)size); *************** *** 1418,1441 **** { if (ccname == NULL) { ! /* No BOM detected: retry with next encoding. */ advance_fenc = TRUE; } else { ! /* BOM detected: set "fenc" and jump back */ if (fenc_alloced) vim_free(fenc); fenc = ccname; fenc_alloced = FALSE; } ! /* retry reading without getting new bytes or rewinding */ skip_read = TRUE; goto retry; } } ! /* Include not converted bytes. */ ptr -= conv_restlen; size += conv_restlen; conv_restlen = 0; --- 1416,1439 ---- { if (ccname == NULL) { ! // No BOM detected: retry with next encoding. advance_fenc = TRUE; } else { ! // BOM detected: set "fenc" and jump back if (fenc_alloced) vim_free(fenc); fenc = ccname; fenc_alloced = FALSE; } ! // retry reading without getting new bytes or rewinding skip_read = TRUE; goto retry; } } ! // Include not converted bytes. ptr -= conv_restlen; size += conv_restlen; conv_restlen = 0; *************** *** 1480,1486 **** conv_error = readfile_linenr(linecnt, ptr, (char_u *)top); ! /* Deal with a bad byte and continue with the next. */ ++fromp; --from_size; if (bad_char_behavior == BAD_KEEP) --- 1478,1484 ---- conv_error = readfile_linenr(linecnt, ptr, (char_u *)top); ! // Deal with a bad byte and continue with the next. ++fromp; --from_size; if (bad_char_behavior == BAD_KEEP) *************** *** 1497,1509 **** if (from_size > 0) { ! /* Some remaining characters, keep them for the next ! * round. */ mch_memmove(conv_rest, (char_u *)fromp, from_size); conv_restlen = (int)from_size; } ! /* move the linerest to before the converted characters */ line_start = ptr - linerest; mch_memmove(line_start, buffer, (size_t)linerest); size = (long)((char_u *)top - ptr); --- 1495,1507 ---- if (from_size > 0) { ! // Some remaining characters, keep them for the next ! // round. mch_memmove(conv_rest, (char_u *)fromp, from_size); conv_restlen = (int)from_size; } ! // move the linerest to before the converted characters line_start = ptr - linerest; mch_memmove(line_start, buffer, (size_t)linerest); size = (long)((char_u *)top - ptr); *************** *** 1533,1539 **** * character at a time to get it right. */ ! /* Replacement string for WideCharToMultiByte(). */ if (bad_char_behavior > 0) replstr[0] = bad_char_behavior; else --- 1531,1537 ---- * character at a time to get it right. */ ! // Replacement string for WideCharToMultiByte(). if (bad_char_behavior > 0) replstr[0] = bad_char_behavior; else *************** *** 1556,1577 **** { found_bad = FALSE; ! # ifdef CP_UTF8 /* VC 4.1 doesn't define CP_UTF8 */ if (codepage == CP_UTF8) { ! /* Handle CP_UTF8 input ourselves to be able to handle ! * trailing bytes properly. ! * Get one UTF-8 character from src. */ bytelen = (int)utf_ptr2len_len(src, size); if (bytelen > size) { ! /* Only got some bytes of a character. Normally ! * it's put in "conv_rest", but if it's too long ! * deal with it as if they were illegal bytes. */ if (bytelen <= CONV_RESTLEN) break; ! /* weird overlong byte sequence */ bytelen = size; found_bad = TRUE; } --- 1554,1575 ---- { found_bad = FALSE; ! # ifdef CP_UTF8 // VC 4.1 doesn't define CP_UTF8 if (codepage == CP_UTF8) { ! // Handle CP_UTF8 input ourselves to be able to handle ! // trailing bytes properly. ! // Get one UTF-8 character from src. bytelen = (int)utf_ptr2len_len(src, size); if (bytelen > size) { ! // Only got some bytes of a character. Normally ! // it's put in "conv_rest", but if it's too long ! // deal with it as if they were illegal bytes. if (bytelen <= CONV_RESTLEN) break; ! // weird overlong byte sequence bytelen = size; found_bad = TRUE; } *************** *** 1588,1595 **** else # endif { ! /* We don't know how long the byte sequence is, try ! * from one to three bytes. */ for (bytelen = 1; bytelen <= size && bytelen <= 3; ++bytelen) { --- 1586,1593 ---- else # endif { ! // We don't know how long the byte sequence is, try ! // from one to three bytes. for (bytelen = 1; bytelen <= size && bytelen <= 3; ++bytelen) { *************** *** 1602,1610 **** } if (ucs2len == 0) { ! /* If we have only one byte then it's probably an ! * incomplete byte sequence. Otherwise discard ! * one byte as a bad character. */ if (size == 1) break; found_bad = TRUE; --- 1600,1608 ---- } if (ucs2len == 0) { ! // If we have only one byte then it's probably an ! // incomplete byte sequence. Otherwise discard ! // one byte as a bad character. if (size == 1) break; found_bad = TRUE; *************** *** 1616,1625 **** { int i; ! /* Convert "ucs2buf[ucs2len]" to 'enc' in "dst". */ if (enc_utf8) { ! /* From UCS-2 to UTF-8. Cannot fail. */ for (i = 0; i < ucs2len; ++i) dst += utf_char2bytes(ucs2buf[i], dst); } --- 1614,1623 ---- { int i; ! // Convert "ucs2buf[ucs2len]" to 'enc' in "dst". if (enc_utf8) { ! // From UCS-2 to UTF-8. Cannot fail. for (i = 0; i < ucs2len; ++i) dst += utf_char2bytes(ucs2buf[i], dst); } *************** *** 1628,1636 **** BOOL bad = FALSE; int dstlen; ! /* From UCS-2 to "enc_codepage". If the ! * conversion uses the default character "?", ! * the data doesn't fit in this encoding. */ dstlen = WideCharToMultiByte(enc_codepage, 0, (LPCWSTR)ucs2buf, ucs2len, (LPSTR)dst, (int)(src - dst), --- 1626,1634 ---- BOOL bad = FALSE; int dstlen; ! // From UCS-2 to "enc_codepage". If the ! // conversion uses the default character "?", ! // the data doesn't fit in this encoding. dstlen = WideCharToMultiByte(enc_codepage, 0, (LPCWSTR)ucs2buf, ucs2len, (LPSTR)dst, (int)(src - dst), *************** *** 1644,1650 **** if (found_bad) { ! /* Deal with bytes we can't convert. */ if (can_retry) goto rewind_retry; if (conv_error == 0) --- 1642,1648 ---- if (found_bad) { ! // Deal with bytes we can't convert. if (can_retry) goto rewind_retry; if (conv_error == 0) *************** *** 1667,1678 **** if (size > 0) { ! /* An incomplete byte sequence remaining. */ mch_memmove(conv_rest, src, size); conv_restlen = size; } ! /* The new size is equal to how much "dst" was advanced. */ size = (long)(dst - ptr); } else --- 1665,1676 ---- if (size > 0) { ! // An incomplete byte sequence remaining. mch_memmove(conv_rest, src, size); conv_restlen = size; } ! // The new size is equal to how much "dst" was advanced. size = (long)(dst - ptr); } else *************** *** 1709,1715 **** p = ptr + size; if (fio_flags == FIO_UTF8) { ! /* Check for a trailing incomplete UTF-8 sequence */ tail = ptr + size - 1; while (tail > ptr && (*tail & 0xc0) == 0x80) --tail; --- 1707,1713 ---- p = ptr + size; if (fio_flags == FIO_UTF8) { ! // Check for a trailing incomplete UTF-8 sequence tail = ptr + size - 1; while (tail > ptr && (*tail & 0xc0) == 0x80) --tail; *************** *** 1721,1733 **** } else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) { ! /* Check for a trailing byte */ p = ptr + (size & ~1); if (size & 1) tail = p; if ((fio_flags & FIO_UTF16) && p > ptr) { ! /* Check for a trailing leading word */ if (fio_flags & FIO_ENDIAN_L) { u8c = (*--p << 8); --- 1719,1731 ---- } else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) { ! // Check for a trailing byte p = ptr + (size & ~1); if (size & 1) tail = p; if ((fio_flags & FIO_UTF16) && p > ptr) { ! // Check for a trailing leading word if (fio_flags & FIO_ENDIAN_L) { u8c = (*--p << 8); *************** *** 1744,1759 **** p += 2; } } ! else /* FIO_UCS4 */ { ! /* Check for trailing 1, 2 or 3 bytes */ p = ptr + (size & ~3); if (size & 3) tail = p; } ! /* If there is a trailing incomplete sequence move it to ! * conv_rest[]. */ if (tail != NULL) { conv_restlen = (int)((ptr + size) - tail); --- 1742,1757 ---- p += 2; } } ! else // FIO_UCS4 { ! // Check for trailing 1, 2 or 3 bytes p = ptr + (size & ~3); if (size & 3) tail = p; } ! // If there is a trailing incomplete sequence move it to ! // conv_rest[]. if (tail != NULL) { conv_restlen = (int)((ptr + size) - tail); *************** *** 1785,1791 **** if (p == ptr) { ! /* Missing leading word. */ if (can_retry) goto rewind_retry; if (conv_error == 0) --- 1783,1789 ---- if (p == ptr) { ! // Missing leading word. if (can_retry) goto rewind_retry; if (conv_error == 0) *************** *** 1797,1804 **** u8c = bad_char_behavior; } ! /* found second word of double-word, get the first ! * word and compute the resulting character */ if (fio_flags & FIO_ENDIAN_L) { u16c = (*--p << 8); --- 1795,1802 ---- u8c = bad_char_behavior; } ! // found second word of double-word, get the first ! // word and compute the resulting character if (fio_flags & FIO_ENDIAN_L) { u16c = (*--p << 8); *************** *** 1812,1818 **** u8c = 0x10000 + ((u16c & 0x3ff) << 10) + (u8c & 0x3ff); ! /* Check if the word is indeed a leading word. */ if (u16c < 0xd800 || u16c > 0xdbff) { if (can_retry) --- 1810,1816 ---- u8c = 0x10000 + ((u16c & 0x3ff) << 10) + (u8c & 0x3ff); ! // Check if the word is indeed a leading word. if (u16c < 0xd800 || u16c > 0xdbff) { if (can_retry) *************** *** 1836,1842 **** u8c += (unsigned)*--p << 8; u8c += *--p; } ! else /* big endian */ { u8c = *--p; u8c += (unsigned)*--p << 8; --- 1834,1840 ---- u8c += (unsigned)*--p << 8; u8c += *--p; } ! else // big endian { u8c = *--p; u8c += (unsigned)*--p << 8; *************** *** 1844,1850 **** u8c += (unsigned)*--p << 24; } } ! else /* UTF-8 */ { if (*--p < 0x80) u8c = *p; --- 1842,1848 ---- u8c += (unsigned)*--p << 24; } } ! else // UTF-8 { if (*--p < 0x80) u8c = *p; *************** *** 1855,1863 **** u8c = utf_ptr2char(p); if (len == 0) { ! /* Not a valid UTF-8 character, retry with ! * another fenc when possible, otherwise just ! * report the error. */ if (can_retry) goto rewind_retry; if (conv_error == 0) --- 1853,1861 ---- u8c = utf_ptr2char(p); if (len == 0) { ! // Not a valid UTF-8 character, retry with ! // another fenc when possible, otherwise just ! // report the error. if (can_retry) goto rewind_retry; if (conv_error == 0) *************** *** 1870,1888 **** } } } ! if (enc_utf8) /* produce UTF-8 */ { dest -= utf_char2len(u8c); (void)utf_char2bytes(u8c, dest); } ! else /* produce Latin1 */ { --dest; if (u8c >= 0x100) { ! /* character doesn't fit in latin1, retry with ! * another fenc when possible, otherwise just ! * report the error. */ if (can_retry) goto rewind_retry; if (conv_error == 0) --- 1868,1886 ---- } } } ! if (enc_utf8) // produce UTF-8 { dest -= utf_char2len(u8c); (void)utf_char2bytes(u8c, dest); } ! else // produce Latin1 { --dest; if (u8c >= 0x100) { ! // character doesn't fit in latin1, retry with ! // another fenc when possible, otherwise just ! // report the error. if (can_retry) goto rewind_retry; if (conv_error == 0) *************** *** 1901,1907 **** } } ! /* move the linerest to before the converted characters */ line_start = dest - linerest; mch_memmove(line_start, buffer, (size_t)linerest); size = (long)((ptr + real_size) - dest); --- 1899,1905 ---- } } ! // move the linerest to before the converted characters line_start = dest - linerest; mch_memmove(line_start, buffer, (size_t)linerest); size = (long)((ptr + real_size) - dest); *************** *** 1911,1917 **** { int incomplete_tail = FALSE; ! /* Reading UTF-8: Check if the bytes are valid UTF-8. */ for (p = ptr; ; ++p) { int todo = (int)((ptr + size) - p); --- 1909,1915 ---- { int incomplete_tail = FALSE; ! // Reading UTF-8: Check if the bytes are valid UTF-8. for (p = ptr; ; ++p) { int todo = (int)((ptr + size) - p); *************** *** 1921,1942 **** break; if (*p >= 0x80) { ! /* A length of 1 means it's an illegal byte. Accept ! * an incomplete character at the end though, the next ! * read() will get the next bytes, we'll check it ! * then. */ l = utf_ptr2len_len(p, todo); if (l > todo && !incomplete_tail) { ! /* Avoid retrying with a different encoding when ! * a truncated file is more likely, or attempting ! * to read the rest of an incomplete sequence when ! * we have already done so. */ if (p > ptr || filesize > 0) incomplete_tail = TRUE; ! /* Incomplete byte sequence, move it to conv_rest[] ! * and try to read the rest of it, unless we've ! * already done so. */ if (p > ptr) { conv_restlen = todo; --- 1919,1940 ---- break; if (*p >= 0x80) { ! // A length of 1 means it's an illegal byte. Accept ! // an incomplete character at the end though, the next ! // read() will get the next bytes, we'll check it ! // then. l = utf_ptr2len_len(p, todo); if (l > todo && !incomplete_tail) { ! // Avoid retrying with a different encoding when ! // a truncated file is more likely, or attempting ! // to read the rest of an incomplete sequence when ! // we have already done so. if (p > ptr || filesize > 0) incomplete_tail = TRUE; ! // Incomplete byte sequence, move it to conv_rest[] ! // and try to read the rest of it, unless we've ! // already done so. if (p > ptr) { conv_restlen = todo; *************** *** 1947,1967 **** } if (l == 1 || l > todo) { ! /* Illegal byte. If we can try another encoding ! * do that, unless at EOF where a truncated ! * file is more likely than a conversion error. */ if (can_retry && !incomplete_tail) break; #ifdef USE_ICONV ! /* When we did a conversion report an error. */ if (iconv_fd != (iconv_t)-1 && conv_error == 0) conv_error = readfile_linenr(linecnt, ptr, p); #endif ! /* Remember the first linenr with an illegal byte */ if (conv_error == 0 && illegal_byte == 0) illegal_byte = readfile_linenr(linecnt, ptr, p); ! /* Drop, keep or replace the bad byte. */ if (bad_char_behavior == BAD_DROP) { mch_memmove(p, p + 1, todo - 1); --- 1945,1965 ---- } if (l == 1 || l > todo) { ! // Illegal byte. If we can try another encoding ! // do that, unless at EOF where a truncated ! // file is more likely than a conversion error. if (can_retry && !incomplete_tail) break; #ifdef USE_ICONV ! // When we did a conversion report an error. if (iconv_fd != (iconv_t)-1 && conv_error == 0) conv_error = readfile_linenr(linecnt, ptr, p); #endif ! // Remember the first linenr with an illegal byte if (conv_error == 0 && illegal_byte == 0) illegal_byte = readfile_linenr(linecnt, ptr, p); ! // Drop, keep or replace the bad byte. if (bad_char_behavior == BAD_DROP) { mch_memmove(p, p + 1, todo - 1); *************** *** 1977,1999 **** } if (p < ptr + size && !incomplete_tail) { ! /* Detected a UTF-8 error. */ rewind_retry: ! /* Retry reading with another conversion. */ #if defined(FEAT_EVAL) && defined(USE_ICONV) if (*p_ccv != NUL && iconv_fd != (iconv_t)-1) ! /* iconv() failed, try 'charconvert' */ did_iconv = TRUE; else #endif ! /* use next item from 'fileencodings' */ advance_fenc = TRUE; file_rewind = TRUE; goto retry; } } ! /* count the number of characters (after conversion!) */ filesize += size; /* --- 1975,1997 ---- } if (p < ptr + size && !incomplete_tail) { ! // Detected a UTF-8 error. rewind_retry: ! // Retry reading with another conversion. #if defined(FEAT_EVAL) && defined(USE_ICONV) if (*p_ccv != NUL && iconv_fd != (iconv_t)-1) ! // iconv() failed, try 'charconvert' did_iconv = TRUE; else #endif ! // use next item from 'fileencodings' advance_fenc = TRUE; file_rewind = TRUE; goto retry; } } ! // count the number of characters (after conversion!) filesize += size; /* *************** *** 2001,2010 **** */ if (fileformat == EOL_UNKNOWN) { ! /* First try finding a NL, for Dos and Unix */ if (try_dos || try_unix) { ! /* Reset the carriage return counter. */ if (try_mac) try_mac = 1; --- 1999,2008 ---- */ if (fileformat == EOL_UNKNOWN) { ! // First try finding a NL, for Dos and Unix if (try_dos || try_unix) { ! // Reset the carriage return counter. if (try_mac) try_mac = 1; *************** *** 2023,2032 **** try_mac++; } ! /* Don't give in to EOL_UNIX if EOL_MAC is more likely */ if (fileformat == EOL_UNIX && try_mac) { ! /* Need to reset the counters when retrying fenc. */ try_mac = 1; try_unix = 1; for (; p >= ptr && *p != CAR; p--) --- 2021,2030 ---- try_mac++; } ! // Don't give in to EOL_UNIX if EOL_MAC is more likely if (fileformat == EOL_UNIX && try_mac) { ! // Need to reset the counters when retrying fenc. try_mac = 1; try_unix = 1; for (; p >= ptr && *p != CAR; p--) *************** *** 2045,2064 **** } } else if (fileformat == EOL_UNKNOWN && try_mac == 1) ! /* Looking for CR but found no end-of-line markers at ! * all: use the default format. */ fileformat = default_fileformat(); } ! /* No NL found: may use Mac format */ if (fileformat == EOL_UNKNOWN && try_mac) fileformat = EOL_MAC; ! /* Still nothing found? Use first format in 'ffs' */ if (fileformat == EOL_UNKNOWN) fileformat = default_fileformat(); ! /* if editing a new file: may set p_tx and p_ff */ if (set_options) set_fileformat(fileformat, OPT_LOCAL); } --- 2043,2062 ---- } } else if (fileformat == EOL_UNKNOWN && try_mac == 1) ! // Looking for CR but found no end-of-line markers at ! // all: use the default format. fileformat = default_fileformat(); } ! // No NL found: may use Mac format if (fileformat == EOL_UNKNOWN && try_mac) fileformat = EOL_MAC; ! // Still nothing found? Use first format in 'ffs' if (fileformat == EOL_UNKNOWN) fileformat = default_fileformat(); ! // if editing a new file: may set p_tx and p_ff if (set_options) set_fileformat(fileformat, OPT_LOCAL); } *************** *** 2073,2090 **** --ptr; while (++ptr, --size >= 0) { ! /* catch most common case first */ if ((c = *ptr) != NUL && c != CAR && c != NL) continue; if (c == NUL) ! *ptr = NL; /* NULs are replaced by newlines! */ else if (c == NL) ! *ptr = CAR; /* NLs are replaced by CRs! */ else { if (skip_count == 0) { ! *ptr = NUL; /* end of line */ len = (colnr_T) (ptr - line_start + 1); if (ml_append(lnum, line_start, len, newfile) == FAIL) { --- 2071,2088 ---- --ptr; while (++ptr, --size >= 0) { ! // catch most common case first if ((c = *ptr) != NUL && c != CAR && c != NL) continue; if (c == NUL) ! *ptr = NL; // NULs are replaced by newlines! else if (c == NL) ! *ptr = CAR; // NLs are replaced by CRs! else { if (skip_count == 0) { ! *ptr = NUL; // end of line len = (colnr_T) (ptr - line_start + 1); if (ml_append(lnum, line_start, len, newfile) == FAIL) { *************** *** 2098,2105 **** ++lnum; if (--read_count == 0) { ! error = TRUE; /* break loop */ ! line_start = ptr; /* nothing left to write */ break; } } --- 2096,2103 ---- ++lnum; if (--read_count == 0) { ! error = TRUE; // break loop ! line_start = ptr; // nothing left to write break; } } *************** *** 2114,2134 **** --ptr; while (++ptr, --size >= 0) { ! if ((c = *ptr) != NUL && c != NL) /* catch most common case */ continue; if (c == NUL) ! *ptr = NL; /* NULs are replaced by newlines! */ else { if (skip_count == 0) { ! *ptr = NUL; /* end of line */ len = (colnr_T)(ptr - line_start + 1); if (fileformat == EOL_DOS) { if (ptr > line_start && ptr[-1] == CAR) { ! /* remove CR before NL */ ptr[-1] = NUL; --len; } --- 2112,2132 ---- --ptr; while (++ptr, --size >= 0) { ! if ((c = *ptr) != NUL && c != NL) // catch most common case continue; if (c == NUL) ! *ptr = NL; // NULs are replaced by newlines! else { if (skip_count == 0) { ! *ptr = NUL; // end of line len = (colnr_T)(ptr - line_start + 1); if (fileformat == EOL_DOS) { if (ptr > line_start && ptr[-1] == CAR) { ! // remove CR before NL ptr[-1] = NUL; --len; } *************** *** 2168,2175 **** ++lnum; if (--read_count == 0) { ! error = TRUE; /* break loop */ ! line_start = ptr; /* nothing left to write */ break; } } --- 2166,2173 ---- ++lnum; if (--read_count == 0) { ! error = TRUE; // break loop ! line_start = ptr; // nothing left to write break; } } *************** *** 2184,2190 **** } failed: ! /* not an error, max. number of lines reached */ if (error && read_count == 0) error = FALSE; --- 2182,2188 ---- } failed: ! // not an error, max. number of lines reached if (error && read_count == 0) error = FALSE; *************** *** 2201,2207 **** && *line_start == Ctrl_Z && ptr == line_start + 1)) { ! /* remember for when writing */ if (set_options) curbuf->b_p_eol = FALSE; *ptr = NUL; --- 2199,2205 ---- && *line_start == Ctrl_Z && ptr == line_start + 1)) { ! // remember for when writing if (set_options) curbuf->b_p_eol = FALSE; *ptr = NUL; *************** *** 2219,2225 **** } if (set_options) ! save_file_ff(curbuf); /* remember the current file format */ #ifdef FEAT_CRYPT if (curbuf->b_cryptstate != NULL) --- 2217,2223 ---- } if (set_options) ! save_file_ff(curbuf); // remember the current file format #ifdef FEAT_CRYPT if (curbuf->b_cryptstate != NULL) *************** *** 2229,2240 **** } if (cryptkey != NULL && cryptkey != curbuf->b_p_key) crypt_free_key(cryptkey); ! /* Don't set cryptkey to NULL, it's used below as a flag that ! * encryption was used. */ #endif ! /* If editing a new file: set 'fenc' for the current buffer. ! * Also for ":read ++edit file". */ if (set_options) set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); --- 2227,2238 ---- } if (cryptkey != NULL && cryptkey != curbuf->b_p_key) crypt_free_key(cryptkey); ! // Don't set cryptkey to NULL, it's used below as a flag that ! // encryption was used. #endif ! // If editing a new file: set 'fenc' for the current buffer. ! // Also for ":read ++edit file". if (set_options) set_string_option_direct((char_u *)"fenc", -1, fenc, OPT_FREE|OPT_LOCAL, 0); *************** *** 2246,2252 **** #endif if (!read_buffer && !read_stdin) ! close(fd); /* errors are ignored */ #ifdef HAVE_FD_CLOEXEC else { --- 2244,2250 ---- #endif if (!read_buffer && !read_stdin) ! close(fd); // errors are ignored #ifdef HAVE_FD_CLOEXEC else { *************** *** 2260,2266 **** #ifdef HAVE_DUP if (read_stdin) { ! /* Use stderr for stdin, makes shell commands work. */ close(0); vim_ignored = dup(2); } --- 2258,2264 ---- #ifdef HAVE_DUP if (read_stdin) { ! // Use stderr for stdin, makes shell commands work. close(0); vim_ignored = dup(2); } *************** *** 2268,2284 **** if (tmpname != NULL) { ! mch_remove(tmpname); /* delete converted file */ vim_free(tmpname); } ! --no_wait_return; /* may wait for return now */ /* * In recovery mode everything but autocommands is skipped. */ if (!recoverymode) { ! /* need to delete the last line, which comes from the empty buffer */ if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY)) { #ifdef FEAT_NETBEANS_INTG --- 2266,2282 ---- if (tmpname != NULL) { ! mch_remove(tmpname); // delete converted file vim_free(tmpname); } ! --no_wait_return; // may wait for return now /* * In recovery mode everything but autocommands is skipped. */ if (!recoverymode) { ! // need to delete the last line, which comes from the empty buffer if (newfile && wasempty && !(curbuf->b_ml.ml_flags & ML_EMPTY)) { #ifdef FEAT_NETBEANS_INTG *************** *** 2297,2313 **** { redraw_curbuf_later(NOT_VALID); #ifdef FEAT_DIFF ! /* After reading the text into the buffer the diff info needs to ! * be updated. */ diff_invalidate(curbuf); #endif #ifdef FEAT_FOLDING ! /* All folds in the window are invalid now. Mark them for update ! * before triggering autocommands. */ foldUpdateAll(curwin); #endif } ! else if (linecnt) /* appended at least one line */ appended_lines_mark(from, linecnt); #ifndef ALWAYS_USE_GUI --- 2295,2311 ---- { redraw_curbuf_later(NOT_VALID); #ifdef FEAT_DIFF ! // After reading the text into the buffer the diff info needs to ! // be updated. diff_invalidate(curbuf); #endif #ifdef FEAT_FOLDING ! // All folds in the window are invalid now. Mark them for update ! // before triggering autocommands. foldUpdateAll(curwin); #endif } ! else if (linecnt) // appended at least one line appended_lines_mark(from, linecnt); #ifndef ALWAYS_USE_GUI *************** *** 2318,2324 **** */ if (read_stdin) { ! settmode(TMODE_RAW); /* set to raw mode */ starttermcap(); screenclear(); } --- 2316,2322 ---- */ if (read_stdin) { ! settmode(TMODE_RAW); // set to raw mode starttermcap(); screenclear(); } *************** *** 2330,2362 **** { filemess(curbuf, sfname, (char_u *)_(e_interr), 0); if (newfile) ! curbuf->b_p_ro = TRUE; /* must use "w!" now */ } msg_scroll = msg_save; #ifdef FEAT_VIMINFO check_marks_read(); #endif ! return OK; /* an interrupt isn't really an error */ } if (!filtering && !(flags & READ_DUMMY)) { ! msg_add_fname(curbuf, sfname); /* fname in IObuff with quotes */ c = FALSE; #ifdef UNIX ! if (S_ISFIFO(perm)) /* fifo */ { STRCAT(IObuff, _("[fifo]")); c = TRUE; } ! if (S_ISSOCK(perm)) /* or socket */ { STRCAT(IObuff, _("[socket]")); c = TRUE; } # ifdef OPEN_CHR_FILES ! if (S_ISCHR(perm)) /* or character special */ { STRCAT(IObuff, _("[character special]")); c = TRUE; --- 2328,2360 ---- { filemess(curbuf, sfname, (char_u *)_(e_interr), 0); if (newfile) ! curbuf->b_p_ro = TRUE; // must use "w!" now } msg_scroll = msg_save; #ifdef FEAT_VIMINFO check_marks_read(); #endif ! return OK; // an interrupt isn't really an error } if (!filtering && !(flags & READ_DUMMY)) { ! msg_add_fname(curbuf, sfname); // fname in IObuff with quotes c = FALSE; #ifdef UNIX ! if (S_ISFIFO(perm)) // fifo { STRCAT(IObuff, _("[fifo]")); c = TRUE; } ! if (S_ISSOCK(perm)) // or socket { STRCAT(IObuff, _("[socket]")); c = TRUE; } # ifdef OPEN_CHR_FILES ! if (S_ISCHR(perm)) // or character special { STRCAT(IObuff, _("[character special]")); c = TRUE; *************** *** 2430,2437 **** VIM_CLEAR(keep_msg); msg_scrolled_ign = TRUE; #ifdef ALWAYS_USE_GUI ! /* Don't show the message when reading stdin, it would end up in a ! * message box (which might be shown when exiting!) */ if (read_stdin || read_buffer) p = msg_may_trunc(FALSE, IObuff); else --- 2428,2435 ---- VIM_CLEAR(keep_msg); msg_scrolled_ign = TRUE; #ifdef ALWAYS_USE_GUI ! // Don't show the message when reading stdin, it would end up in a ! // message box (which might be shown when exiting!) if (read_stdin || read_buffer) p = msg_may_trunc(FALSE, IObuff); else *************** *** 2443,2465 **** } if (read_stdin || read_buffer || restart_edit != 0 || (msg_scrolled != 0 && !need_wait_return)) ! /* Need to repeat the message after redrawing when: ! * - When reading from stdin (the screen will be cleared next). ! * - When restart_edit is set (otherwise there will be a delay ! * before redrawing). ! * - When the screen was scrolled but there is no wait-return ! * prompt. */ set_keep_msg(p, 0); msg_scrolled_ign = FALSE; } ! /* with errors writing the file requires ":w!" */ if (newfile && (error || conv_error != 0 || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP))) curbuf->b_p_ro = TRUE; ! u_clearline(); /* cannot use "U" command after adding lines */ /* * In Ex mode: cursor at last new line. --- 2441,2463 ---- } if (read_stdin || read_buffer || restart_edit != 0 || (msg_scrolled != 0 && !need_wait_return)) ! // Need to repeat the message after redrawing when: ! // - When reading from stdin (the screen will be cleared next). ! // - When restart_edit is set (otherwise there will be a delay ! // before redrawing). ! // - When the screen was scrolled but there is no wait-return ! // prompt. set_keep_msg(p, 0); msg_scrolled_ign = FALSE; } ! // with errors writing the file requires ":w!" if (newfile && (error || conv_error != 0 || (illegal_byte > 0 && bad_char_behavior != BAD_KEEP))) curbuf->b_p_ro = TRUE; ! u_clearline(); // cannot use "U" command after adding lines /* * In Ex mode: cursor at last new line. *************** *** 2470,2476 **** else curwin->w_cursor.lnum = from + 1; check_cursor_lnum(); ! beginline(BL_WHITE | BL_FIX); /* on first non-blank */ if (!cmdmod.lockmarks) { --- 2468,2474 ---- else curwin->w_cursor.lnum = from + 1; check_cursor_lnum(); ! beginline(BL_WHITE | BL_FIX); // on first non-blank if (!cmdmod.lockmarks) { *************** *** 2514,2521 **** */ curbuf->b_no_eol_lnum = read_no_eol_lnum; ! /* When reloading a buffer put the cursor at the first line that is ! * different. */ if (flags & READ_KEEP_UNDO) u_find_first_changed(); --- 2512,2519 ---- */ curbuf->b_no_eol_lnum = read_no_eol_lnum; ! // When reloading a buffer put the cursor at the first line that is ! // different. if (flags & READ_KEEP_UNDO) u_find_first_changed(); *************** *** 2537,2544 **** int m = msg_scroll; int n = msg_scrolled; ! /* Save the fileformat now, otherwise the buffer will be considered ! * modified if the format/encoding was automatically detected. */ if (set_options) save_file_ff(curbuf); --- 2535,2542 ---- int m = msg_scroll; int n = msg_scrolled; ! // Save the fileformat now, otherwise the buffer will be considered ! // modified if the format/encoding was automatically detected. if (set_options) save_file_ff(curbuf); *************** *** 2569,2575 **** if (msg_scrolled == n) msg_scroll = m; # ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return FAIL; # endif } --- 2567,2573 ---- if (msg_scrolled == n) msg_scroll = m; # ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return FAIL; # endif } *************** *** 2604,2612 **** */ static linenr_T readfile_linenr( ! linenr_T linecnt, /* line count before reading more bytes */ ! char_u *p, /* start of more bytes read */ ! char_u *endp) /* end of more bytes read */ { char_u *s; linenr_T lnum; --- 2602,2610 ---- */ static linenr_T readfile_linenr( ! linenr_T linecnt, // line count before reading more bytes ! char_u *p, // start of more bytes read ! char_u *endp) // end of more bytes read { char_u *s; linenr_T lnum; *************** *** 2647,2653 **** void set_file_options(int set_options, exarg_T *eap) { ! /* set default 'fileformat' */ if (set_options) { if (eap != NULL && eap->force_ff != 0) --- 2645,2651 ---- void set_file_options(int set_options, exarg_T *eap) { ! // set default 'fileformat' if (set_options) { if (eap != NULL && eap->force_ff != 0) *************** *** 2656,2662 **** set_fileformat(default_fileformat(), OPT_LOCAL); } ! /* set or reset 'binary' */ if (eap != NULL && eap->force_bin != 0) { int oldval = curbuf->b_p_bin; --- 2654,2660 ---- set_fileformat(default_fileformat(), OPT_LOCAL); } ! // set or reset 'binary' if (eap != NULL && eap->force_bin != 0) { int oldval = curbuf->b_p_bin; *************** *** 2742,2750 **** */ static char_u * readfile_charconvert( ! char_u *fname, /* name of input file */ ! char_u *fenc, /* converted from */ ! int *fdp) /* in/out: file descriptor of file */ { char_u *tmpname; char *errmsg = NULL; --- 2740,2748 ---- */ static char_u * readfile_charconvert( ! char_u *fname, // name of input file ! char_u *fenc, // converted from ! int *fdp) // in/out: file descriptor of file { char_u *tmpname; char *errmsg = NULL; *************** *** 2754,2760 **** errmsg = _("Can't find temp file for conversion"); else { ! close(*fdp); /* close the input file, ignore errors */ *fdp = -1; if (eval_charconvert(fenc, enc_utf8 ? (char_u *)"utf-8" : p_enc, fname, tmpname) == FAIL) --- 2752,2758 ---- errmsg = _("Can't find temp file for conversion"); else { ! close(*fdp); // close the input file, ignore errors *fdp = -1; if (eval_charconvert(fenc, enc_utf8 ? (char_u *)"utf-8" : p_enc, fname, tmpname) == FAIL) *************** *** 2766,2782 **** if (errmsg != NULL) { ! /* Don't use emsg(), it breaks mappings, the retry with ! * another type of conversion might still work. */ msg(errmsg); if (tmpname != NULL) { ! mch_remove(tmpname); /* delete converted file */ VIM_CLEAR(tmpname); } } ! /* If the input file is closed, open it (caller should check for error). */ if (*fdp < 0) *fdp = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); --- 2764,2780 ---- if (errmsg != NULL) { ! // Don't use emsg(), it breaks mappings, the retry with ! // another type of conversion might still work. msg(errmsg); if (tmpname != NULL) { ! mch_remove(tmpname); // delete converted file VIM_CLEAR(tmpname); } } ! // If the input file is closed, open it (caller should check for error). if (*fdp < 0) *fdp = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0); *************** *** 2793,2816 **** */ static char_u * check_for_cryptkey( ! char_u *cryptkey, /* previous encryption key or NULL */ ! char_u *ptr, /* pointer to read bytes */ ! long *sizep, /* length of read bytes */ ! off_T *filesizep, /* nr of bytes used from file */ ! int newfile, /* editing a new buffer */ ! char_u *fname, /* file name to display */ ! int *did_ask) /* flag: whether already asked for key */ { int method = crypt_method_nr_from_magic((char *)ptr, *sizep); int b_p_ro = curbuf->b_p_ro; if (method >= 0) { ! /* Mark the buffer as read-only until the decryption has taken place. ! * Avoids accidentally overwriting the file with garbage. */ curbuf->b_p_ro = TRUE; ! /* Set the cryptmethod local to the buffer. */ crypt_set_cm_option(curbuf, method); if (cryptkey == NULL && !*did_ask) { --- 2791,2814 ---- */ static char_u * check_for_cryptkey( ! char_u *cryptkey, // previous encryption key or NULL ! char_u *ptr, // pointer to read bytes ! long *sizep, // length of read bytes ! off_T *filesizep, // nr of bytes used from file ! int newfile, // editing a new buffer ! char_u *fname, // file name to display ! int *did_ask) // flag: whether already asked for key { int method = crypt_method_nr_from_magic((char *)ptr, *sizep); int b_p_ro = curbuf->b_p_ro; if (method >= 0) { ! // Mark the buffer as read-only until the decryption has taken place. ! // Avoids accidentally overwriting the file with garbage. curbuf->b_p_ro = TRUE; ! // Set the cryptmethod local to the buffer. crypt_set_cm_option(curbuf, method); if (cryptkey == NULL && !*did_ask) { *************** *** 2818,2834 **** cryptkey = curbuf->b_p_key; else { ! /* When newfile is TRUE, store the typed key in the 'key' ! * option and don't free it. bf needs hash of the key saved. ! * Don't ask for the key again when first time Enter was hit. ! * Happens when retrying to detect encoding. */ smsg(_(need_key_msg), fname); msg_scroll = TRUE; crypt_check_method(method); cryptkey = crypt_get_key(newfile, FALSE); *did_ask = TRUE; ! /* check if empty key entered */ if (cryptkey != NULL && *cryptkey == NUL) { if (cryptkey != curbuf->b_p_key) --- 2816,2832 ---- cryptkey = curbuf->b_p_key; else { ! // When newfile is TRUE, store the typed key in the 'key' ! // option and don't free it. bf needs hash of the key saved. ! // Don't ask for the key again when first time Enter was hit. ! // Happens when retrying to detect encoding. smsg(_(need_key_msg), fname); msg_scroll = TRUE; crypt_check_method(method); cryptkey = crypt_get_key(newfile, FALSE); *did_ask = TRUE; ! // check if empty key entered if (cryptkey != NULL && *cryptkey == NUL) { if (cryptkey != curbuf->b_p_key) *************** *** 2846,2875 **** method, cryptkey, ptr); crypt_set_cm_option(curbuf, method); ! /* Remove cryptmethod specific header from the text. */ header_len = crypt_get_header_len(method); if (*sizep <= header_len) ! /* invalid header, buffer can't be encrypted */ return NULL; *filesizep += header_len; *sizep -= header_len; mch_memmove(ptr, ptr + header_len, (size_t)*sizep); ! /* Restore the read-only flag. */ curbuf->b_p_ro = b_p_ro; } } ! /* When starting to edit a new file which does not have encryption, clear ! * the 'key' option, except when starting up (called with -x argument) */ else if (newfile && *curbuf->b_p_key != NUL && !starting) set_option_value((char_u *)"key", 0L, (char_u *)"", OPT_LOCAL); return cryptkey; } ! #endif /* FEAT_CRYPT */ #if defined(VMS) && !defined(MIN) ! /* Older DECC compiler for VAX doesn't define MIN() */ # define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif --- 2844,2873 ---- method, cryptkey, ptr); crypt_set_cm_option(curbuf, method); ! // Remove cryptmethod specific header from the text. header_len = crypt_get_header_len(method); if (*sizep <= header_len) ! // invalid header, buffer can't be encrypted return NULL; *filesizep += header_len; *sizep -= header_len; mch_memmove(ptr, ptr + header_len, (size_t)*sizep); ! // Restore the read-only flag. curbuf->b_p_ro = b_p_ro; } } ! // When starting to edit a new file which does not have encryption, clear ! // the 'key' option, except when starting up (called with -x argument) else if (newfile && *curbuf->b_p_key != NUL && !starting) set_option_value((char_u *)"key", 0L, (char_u *)"", OPT_LOCAL); return cryptkey; } ! #endif // FEAT_CRYPT #if defined(VMS) && !defined(MIN) ! // Older DECC compiler for VAX doesn't define MIN() # define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif *************** *** 2878,2885 **** */ int check_file_readonly( ! char_u *fname, /* full path to file */ ! int perm UNUSED) /* known permissions on file */ { #ifndef USE_MCH_ACCESS int fd = 0; --- 2876,2883 ---- */ int check_file_readonly( ! char_u *fname, // full path to file ! int perm UNUSED) // known permissions on file { #ifndef USE_MCH_ACCESS int fd = 0; *************** *** 2926,2942 **** { buf_T *buf = curbuf; ! /* It's like the unnamed buffer is deleted.... */ if (curbuf->b_p_bl) apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return FAIL; #endif if (curbuf != buf) { ! /* We are in another buffer now, don't do the renaming. */ emsg(_(e_auchangedbuf)); return FAIL; } --- 2924,2940 ---- { buf_T *buf = curbuf; ! // It's like the unnamed buffer is deleted.... if (curbuf->b_p_bl) apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return FAIL; #endif if (curbuf != buf) { ! // We are in another buffer now, don't do the renaming. emsg(_(e_auchangedbuf)); return FAIL; } *************** *** 2944,2959 **** if (setfname(curbuf, fname, sfname, FALSE) == OK) curbuf->b_flags |= BF_NOTEDITED; ! /* ....and a new named one is created */ apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf); if (curbuf->b_p_bl) apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return FAIL; #endif ! /* Do filetype detection now if 'filetype' is empty. */ if (*curbuf->b_p_ft == NUL) { if (au_has_group((char_u *)"filetypedetect")) --- 2942,2957 ---- if (setfname(curbuf, fname, sfname, FALSE) == OK) curbuf->b_flags |= BF_NOTEDITED; ! // ....and a new named one is created apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf); if (curbuf->b_p_bl) apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return FAIL; #endif ! // Do filetype detection now if 'filetype' is empty. if (*curbuf->b_p_ft == NUL) { if (au_has_group((char_u *)"filetypedetect")) *************** *** 3047,3055 **** time_differs(long t1, long t2) { #if defined(__linux__) || defined(MSWIN) ! /* On a FAT filesystem, esp. under Linux, there are only 5 bits to store ! * the seconds. Since the roundoff is done when flushing the inode, the ! * time may change unexpectedly by one second!!! */ return (t1 - t2 > 1 || t2 - t1 > 1); #else return (t1 != t2); --- 3045,3053 ---- time_differs(long t1, long t2) { #if defined(__linux__) || defined(MSWIN) ! // On a FAT filesystem, esp. under Linux, there are only 5 bits to store ! // the seconds. Since the roundoff is done when flushing the inode, the ! // time may change unexpectedly by one second!!! return (t1 - t2 > 1 || t2 - t1 > 1); #else return (t1 != t2); *************** *** 3074,3094 **** } else { ! /* Ignore difference between "ansi" and "latin1", "ucs-4" and ! * "ucs-4be", etc. */ enc_flags = get_fio_flags(p_enc); fenc_flags = get_fio_flags(fenc); same_encoding = (enc_flags != 0 && fenc_flags == enc_flags); } if (same_encoding) { ! /* Specified encoding matches with 'encoding'. This requires ! * conversion when 'encoding' is Unicode but not UTF-8. */ return enc_unicode != 0; } ! /* Encodings differ. However, conversion is not needed when 'enc' is any ! * Unicode encoding and the file is UTF-8. */ return !(enc_utf8 && fenc_flags == FIO_UTF8); } --- 3072,3092 ---- } else { ! // Ignore difference between "ansi" and "latin1", "ucs-4" and ! // "ucs-4be", etc. enc_flags = get_fio_flags(p_enc); fenc_flags = get_fio_flags(fenc); same_encoding = (enc_flags != 0 && fenc_flags == enc_flags); } if (same_encoding) { ! // Specified encoding matches with 'encoding'. This requires ! // conversion when 'encoding' is Unicode but not UTF-8. return enc_unicode != 0; } ! // Encodings differ. However, conversion is not needed when 'enc' is any ! // Unicode encoding and the file is UTF-8. return !(enc_utf8 && fenc_flags == FIO_UTF8); } *************** *** 3130,3136 **** } if (prop & ENC_LATIN1) return FIO_LATIN1; ! /* must be ENC_DBCS, requires iconv() */ return 0; } --- 3128,3134 ---- } if (prop & ENC_LATIN1) return FIO_LATIN1; ! // must be ENC_DBCS, requires iconv() return 0; } *************** *** 3145,3158 **** { int cp; ! /* Cannot do this when 'encoding' is not utf-8 and not a codepage. */ if (!enc_utf8 && enc_codepage <= 0) return 0; cp = encname2codepage(ptr); if (cp == 0) { ! # ifdef CP_UTF8 /* VC 4.1 doesn't define CP_UTF8 */ if (STRCMP(ptr, "utf-8") == 0) cp = CP_UTF8; else --- 3143,3156 ---- { int cp; ! // Cannot do this when 'encoding' is not utf-8 and not a codepage. if (!enc_utf8 && enc_codepage <= 0) return 0; cp = encname2codepage(ptr); if (cp == 0) { ! # ifdef CP_UTF8 // VC 4.1 doesn't define CP_UTF8 if (STRCMP(ptr, "utf-8") == 0) cp = CP_UTF8; else *************** *** 3197,3203 **** if (p[0] == 0xef && p[1] == 0xbb && size >= 3 && p[2] == 0xbf && (flags == FIO_ALL || flags == FIO_UTF8 || flags == 0)) { ! name = "utf-8"; /* EF BB BF */ len = 3; } else if (p[0] == 0xff && p[1] == 0xfe) --- 3195,3201 ---- if (p[0] == 0xef && p[1] == 0xbb && size >= 3 && p[2] == 0xbf && (flags == FIO_ALL || flags == FIO_UTF8 || flags == 0)) { ! name = "utf-8"; // EF BB BF len = 3; } else if (p[0] == 0xff && p[1] == 0xfe) *************** *** 3205,3232 **** if (size >= 4 && p[2] == 0 && p[3] == 0 && (flags == FIO_ALL || flags == (FIO_UCS4 | FIO_ENDIAN_L))) { ! name = "ucs-4le"; /* FF FE 00 00 */ len = 4; } else if (flags == (FIO_UCS2 | FIO_ENDIAN_L)) ! name = "ucs-2le"; /* FF FE */ else if (flags == FIO_ALL || flags == (FIO_UTF16 | FIO_ENDIAN_L)) ! /* utf-16le is preferred, it also works for ucs-2le text */ ! name = "utf-16le"; /* FF FE */ } else if (p[0] == 0xfe && p[1] == 0xff && (flags == FIO_ALL || flags == FIO_UCS2 || flags == FIO_UTF16)) { ! /* Default to utf-16, it works also for ucs-2 text. */ if (flags == FIO_UCS2) ! name = "ucs-2"; /* FE FF */ else ! name = "utf-16"; /* FE FF */ } else if (size >= 4 && p[0] == 0 && p[1] == 0 && p[2] == 0xfe && p[3] == 0xff && (flags == FIO_ALL || flags == FIO_UCS4)) { ! name = "ucs-4"; /* 00 00 FE FF */ len = 4; } --- 3203,3230 ---- if (size >= 4 && p[2] == 0 && p[3] == 0 && (flags == FIO_ALL || flags == (FIO_UCS4 | FIO_ENDIAN_L))) { ! name = "ucs-4le"; // FF FE 00 00 len = 4; } else if (flags == (FIO_UCS2 | FIO_ENDIAN_L)) ! name = "ucs-2le"; // FF FE else if (flags == FIO_ALL || flags == (FIO_UTF16 | FIO_ENDIAN_L)) ! // utf-16le is preferred, it also works for ucs-2le text ! name = "utf-16le"; // FF FE } else if (p[0] == 0xfe && p[1] == 0xff && (flags == FIO_ALL || flags == FIO_UCS2 || flags == FIO_UTF16)) { ! // Default to utf-16, it works also for ucs-2 text. if (flags == FIO_UCS2) ! name = "ucs-2"; // FE FF else ! name = "utf-16"; // FE FF } else if (size >= 4 && p[0] == 0 && p[1] == 0 && p[2] == 0xfe && p[3] == 0xff && (flags == FIO_ALL || flags == FIO_UCS4)) { ! name = "ucs-4"; // 00 00 FE FF len = 4; } *************** *** 3287,3293 **** { if (vim_ispathsep(*p)) ++p; ! #ifndef VMS /* the path separator is always part of the path */ else p = NULL; #endif --- 3285,3291 ---- { if (vim_ispathsep(*p)) ++p; ! #ifndef VMS // the path separator is always part of the path else p = NULL; #endif *************** *** 3360,3367 **** { shorten_buf_fname(buf, dirname, force); ! /* Always make the swap file name a full path, a "nofile" buffer may ! * also have a swap file. */ mf_fullname(buf->b_ml.ml_mfp); } status_redraw_all(); --- 3358,3365 ---- { shorten_buf_fname(buf, dirname, force); ! // Always make the swap file name a full path, a "nofile" buffer may ! // also have a swap file. mf_fullname(buf->b_ml.ml_mfp); } status_redraw_all(); *************** *** 3392,3400 **** { if ((p = shorten_fname(fnames[i], dirname)) != NULL) { ! /* shorten_fname() returns pointer in given "fnames[i]". If free ! * "fnames[i]" first, "p" becomes invalid. So we need to copy ! * "p" first then free fnames[i]. */ p = vim_strsave(p); vim_free(fnames[i]); fnames[i] = p; --- 3390,3398 ---- { if ((p = shorten_fname(fnames[i], dirname)) != NULL) { ! // shorten_fname() returns pointer in given "fnames[i]". If free ! // "fnames[i]" first, "p" becomes invalid. So we need to copy ! // "p" first then free fnames[i]. p = vim_strsave(p); vim_free(fnames[i]); fnames[i] = p; *************** *** 3418,3424 **** modname( char_u *fname, char_u *ext, ! int prepend_dot) /* may prepend a '.' to file name */ { return buf_modname((curbuf->b_p_sn || curbuf->b_shortname), fname, ext, prepend_dot); --- 3416,3422 ---- modname( char_u *fname, char_u *ext, ! int prepend_dot) // may prepend a '.' to file name { return buf_modname((curbuf->b_p_sn || curbuf->b_shortname), fname, ext, prepend_dot); *************** *** 3426,3435 **** char_u * buf_modname( ! int shortname, /* use 8.3 file name */ char_u *fname, char_u *ext, ! int prepend_dot) /* may prepend a '.' to file name */ { char_u *retval; char_u *s; --- 3424,3433 ---- char_u * buf_modname( ! int shortname, // use 8.3 file name char_u *fname, char_u *ext, ! int prepend_dot) // may prepend a '.' to file name { char_u *retval; char_u *s; *************** *** 3459,3465 **** retval[fnamelen++] = PATHSEP; retval[fnamelen] = NUL; } ! prepend_dot = FALSE; /* nothing to prepend a dot to */ } else { --- 3457,3463 ---- retval[fnamelen++] = PATHSEP; retval[fnamelen] = NUL; } ! prepend_dot = FALSE; // nothing to prepend a dot to } else { *************** *** 3469,3475 **** return NULL; STRCPY(retval, fname); #ifdef VMS ! vms_remove_version(retval); /* we do not need versions here */ #endif } --- 3467,3473 ---- return NULL; STRCPY(retval, fname); #ifdef VMS ! vms_remove_version(retval); // we do not need versions here #endif } *************** *** 3482,3488 **** for (ptr = retval + fnamelen; ptr > retval; MB_PTR_BACK(retval, ptr)) { if (*ext == '.' && shortname) ! if (*ptr == '.') /* replace '.' by '_' */ *ptr = '_'; if (vim_ispathsep(*ptr)) { --- 3480,3486 ---- for (ptr = retval + fnamelen; ptr > retval; MB_PTR_BACK(retval, ptr)) { if (*ext == '.' && shortname) ! if (*ptr == '.') // replace '.' by '_' *ptr = '_'; if (vim_ispathsep(*ptr)) { *************** *** 3491,3497 **** } } ! /* the file name has at most BASENAMELEN characters. */ if (STRLEN(ptr) > (unsigned)BASENAMELEN) ptr[BASENAMELEN] = '\0'; --- 3489,3495 ---- } } ! // the file name has at most BASENAMELEN characters. if (STRLEN(ptr) > (unsigned)BASENAMELEN) ptr[BASENAMELEN] = '\0'; *************** *** 3569,3575 **** */ if (fname != NULL && STRCMP(fname, retval) == 0) { ! /* we search for a character that can be replaced by '_' */ while (--s >= ptr) { if (*s != '_') --- 3567,3573 ---- */ if (fname != NULL && STRCMP(fname, retval) == 0) { ! // we search for a character that can be replaced by '_' while (--s >= ptr) { if (*s != '_') *************** *** 3578,3584 **** break; } } ! if (s < ptr) /* fname was "________.", how tricky! */ *ptr = 'v'; } return retval; --- 3576,3582 ---- break; } } ! if (s < ptr) // fname was "________.", how tricky! *ptr = 'v'; } return retval; *************** *** 3600,3608 **** eof = fgets((char *)buf, size, fp); if (buf[size - 2] != NUL && buf[size - 2] != '\n') { ! buf[size - 1] = NUL; /* Truncate the line */ ! /* Now throw away the rest of the line: */ do { tbuf[FGETS_SIZE - 2] = NUL; --- 3598,3606 ---- eof = fgets((char *)buf, size, fp); if (buf[size - 2] != NUL && buf[size - 2] != '\n') { ! buf[size - 1] = NUL; // Truncate the line ! // Now throw away the rest of the line: do { tbuf[FGETS_SIZE - 2] = NUL; *************** *** 3631,3637 **** stat_T st; long perm; #ifdef HAVE_ACL ! vim_acl_T acl; /* ACL from original file */ #endif int use_tmp_file = FALSE; --- 3629,3635 ---- stat_T st; long perm; #ifdef HAVE_ACL ! vim_acl_T acl; // ACL from original file #endif int use_tmp_file = FALSE; *************** *** 3658,3666 **** { stat_T st_to; ! /* It's possible for the source and destination to be the same file. ! * This happens when "from" and "to" differ in case and are on a FAT32 ! * filesystem. In that case go through a temp file name. */ if (mch_stat((char *)to, &st_to) >= 0 && st.st_dev == st_to.st_dev && st.st_ino == st_to.st_ino) --- 3656,3664 ---- { stat_T st_to; ! // It's possible for the source and destination to be the same file. ! // This happens when "from" and "to" differ in case and are on a FAT32 ! // filesystem. In that case go through a temp file name. if (mch_stat((char *)to, &st_to) >= 0 && st.st_dev == st_to.st_dev && st.st_ino == st_to.st_ino) *************** *** 3671,3679 **** { BY_HANDLE_FILE_INFORMATION info1, info2; ! /* It's possible for the source and destination to be the same file. ! * In that case go through a temp file name. This makes rename("foo", ! * "./foo") a no-op (in a complicated way). */ if (win32_fileinfo(from, &info1) == FILEINFO_OK && win32_fileinfo(to, &info2) == FILEINFO_OK && info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber --- 3669,3677 ---- { BY_HANDLE_FILE_INFORMATION info1, info2; ! // It's possible for the source and destination to be the same file. ! // In that case go through a temp file name. This makes rename("foo", ! // "./foo") a no-op (in a complicated way). if (win32_fileinfo(from, &info1) == FILEINFO_OK && win32_fileinfo(to, &info2) == FILEINFO_OK && info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber *************** *** 3703,3715 **** { if (mch_rename(tempname, (char *)to) == 0) return 0; ! /* Strange, the second step failed. Try moving the ! * file back and return failure. */ mch_rename(tempname, (char *)from); return -1; } ! /* If it fails for one temp name it will most likely fail ! * for any temp name, give up. */ return -1; } } --- 3701,3713 ---- { if (mch_rename(tempname, (char *)to) == 0) return 0; ! // Strange, the second step failed. Try moving the ! // file back and return failure. mch_rename(tempname, (char *)from); return -1; } ! // If it fails for one temp name it will most likely fail ! // for any temp name, give up. return -1; } } *************** *** 3755,3761 **** */ perm = mch_getperm(from); #ifdef HAVE_ACL ! /* For systems that support ACL: get the ACL from the original file. */ acl = mch_get_acl(from); #endif fd_in = mch_open((char *)from, O_RDONLY|O_EXTRA, 0); --- 3753,3759 ---- */ perm = mch_getperm(from); #ifdef HAVE_ACL ! // For systems that support ACL: get the ACL from the original file. acl = mch_get_acl(from); #endif fd_in = mch_open((char *)from, O_RDONLY|O_EXTRA, 0); *************** *** 3767,3773 **** return -1; } ! /* Create the new file with same permissions as the original. */ fd_out = mch_open((char *)to, O_CREAT|O_EXCL|O_WRONLY|O_EXTRA|O_NOFOLLOW, (int)perm); if (fd_out == -1) --- 3765,3771 ---- return -1; } ! // Create the new file with same permissions as the original. fd_out = mch_open((char *)to, O_CREAT|O_EXCL|O_WRONLY|O_EXTRA|O_NOFOLLOW, (int)perm); if (fd_out == -1) *************** *** 3806,3812 **** errmsg = _("E210: Error reading \"%s\""); to = from; } ! #ifndef UNIX /* for Unix mch_open() already set the permission */ mch_setperm(to, perm); #endif #ifdef HAVE_ACL --- 3804,3810 ---- errmsg = _("E210: Error reading \"%s\""); to = from; } ! #ifndef UNIX // for Unix mch_open() already set the permission mch_setperm(to, perm); #endif #ifdef HAVE_ACL *************** *** 3837,3856 **** */ int check_timestamps( ! int focus) /* called for GUI focus event */ { buf_T *buf; int didit = 0; int n; ! /* Don't check timestamps while system() or another low-level function may ! * cause us to lose and gain focus. */ if (no_check_timestamps > 0) return FALSE; ! /* Avoid doing a check twice. The OK/Reload dialog can cause a focus ! * event and we would keep on checking if the file is steadily growing. ! * Do check again after typing something. */ if (focus && did_check_timestamps) { need_check_timestamps = TRUE; --- 3835,3854 ---- */ int check_timestamps( ! int focus) // called for GUI focus event { buf_T *buf; int didit = 0; int n; ! // Don't check timestamps while system() or another low-level function may ! // cause us to lose and gain focus. if (no_check_timestamps > 0) return FALSE; ! // Avoid doing a check twice. The OK/Reload dialog can cause a focus ! // event and we would keep on checking if the file is steadily growing. ! // Do check again after typing something. if (focus && did_check_timestamps) { need_check_timestamps = TRUE; *************** *** 3859,3865 **** if (!stuff_empty() || global_busy || !typebuf_typed() || autocmd_busy || curbuf_lock > 0 || allbuf_lock > 0) ! need_check_timestamps = TRUE; /* check later */ else { ++no_wait_return; --- 3857,3863 ---- if (!stuff_empty() || global_busy || !typebuf_typed() || autocmd_busy || curbuf_lock > 0 || allbuf_lock > 0) ! need_check_timestamps = TRUE; // check later else { ++no_wait_return; *************** *** 3867,3873 **** already_warned = FALSE; FOR_ALL_BUFFERS(buf) { ! /* Only check buffers in a window. */ if (buf->b_nwindows > 0) { bufref_T bufref; --- 3865,3871 ---- already_warned = FALSE; FOR_ALL_BUFFERS(buf) { ! // Only check buffers in a window. if (buf->b_nwindows > 0) { bufref_T bufref; *************** *** 3878,3885 **** didit = n; if (n > 0 && !bufref_valid(&bufref)) { ! /* Autocommands have removed the buffer, start at the ! * first one again. */ buf = firstbuf; continue; } --- 3876,3883 ---- didit = n; if (n > 0 && !bufref_valid(&bufref)) { ! // Autocommands have removed the buffer, start at the ! // first one again. buf = firstbuf; continue; } *************** *** 3889,3895 **** need_check_timestamps = FALSE; if (need_wait_return && didit == 2) { ! /* make sure msg isn't overwritten */ msg_puts("\n"); out_flush(); } --- 3887,3893 ---- need_check_timestamps = FALSE; if (need_wait_return && didit == 2) { ! // make sure msg isn't overwritten msg_puts("\n"); out_flush(); } *************** *** 3910,3916 **** linenr_T lnum; char_u *p; ! /* Copy the lines in "frombuf" to "tobuf". */ curbuf = tobuf; for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) { --- 3908,3914 ---- linenr_T lnum; char_u *p; ! // Copy the lines in "frombuf" to "tobuf". curbuf = tobuf; for (lnum = 1; lnum <= frombuf->b_ml.ml_line_count; ++lnum) { *************** *** 3924,3938 **** vim_free(p); } ! /* Delete all the lines in "frombuf". */ if (retval != FAIL) { curbuf = frombuf; for (lnum = curbuf->b_ml.ml_line_count; lnum > 0; --lnum) if (ml_delete(lnum, FALSE) == FAIL) { ! /* Oops! We could try putting back the saved lines, but that ! * might fail again... */ retval = FAIL; break; } --- 3922,3936 ---- vim_free(p); } ! // Delete all the lines in "frombuf". if (retval != FAIL) { curbuf = frombuf; for (lnum = curbuf->b_ml.ml_line_count; lnum > 0; --lnum) if (ml_delete(lnum, FALSE) == FAIL) { ! // Oops! We could try putting back the saved lines, but that ! // might fail again... retval = FAIL; break; } *************** *** 3952,3958 **** int buf_check_timestamp( buf_T *buf, ! int focus UNUSED) /* called for GUI focus event */ { stat_T st; int stat_res; --- 3950,3956 ---- int buf_check_timestamp( buf_T *buf, ! int focus UNUSED) // called for GUI focus event { stat_T st; int stat_res; *************** *** 3981,3989 **** set_bufref(&bufref, buf); ! /* If there is no file name, the buffer is not loaded, 'buftype' is ! * set, we are in the middle of a save or being called recursively: ignore ! * this buffer. */ if (buf->b_ffname == NULL || buf->b_ml.ml_mfp == NULL || !bt_normal(buf) --- 3979,3987 ---- set_bufref(&bufref, buf); ! // If there is no file name, the buffer is not loaded, 'buftype' is ! // set, we are in the middle of a save or being called recursively: ignore ! // this buffer. if (buf->b_ffname == NULL || buf->b_ml.ml_mfp == NULL || !bt_normal(buf) *************** *** 4026,4033 **** else buf_store_time(buf, &st, buf->b_ffname); ! /* Don't do anything for a directory. Might contain the file ! * explorer. */ if (mch_isdir(buf->b_fname)) ; --- 4024,4031 ---- else buf_store_time(buf, &st, buf->b_ffname); ! // Don't do anything for a directory. Might contain the file ! // explorer. if (mch_isdir(buf->b_fname)) ; *************** *** 4116,4123 **** mesg2 = _("See \":help W16\" for more info."); } else ! /* Only timestamp changed, store it to avoid a warning ! * in check_mtime() later. */ buf->b_mtime_read = buf->b_mtime; } } --- 4114,4121 ---- mesg2 = _("See \":help W16\" for more info."); } else ! // Only timestamp changed, store it to avoid a warning ! // in check_mtime() later. buf->b_mtime_read = buf->b_mtime; } } *************** *** 4145,4152 **** tbuf = alloc(STRLEN(path) + STRLEN(mesg) + STRLEN(mesg2) + 2); sprintf(tbuf, mesg, path); #ifdef FEAT_EVAL ! /* Set warningmsg here, before the unimportant and output-specific ! * mesg2 has been appended. */ set_vim_var_string(VV_WARNINGMSG, (char_u *)tbuf, -1); #endif #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) --- 4143,4150 ---- tbuf = alloc(STRLEN(path) + STRLEN(mesg) + STRLEN(mesg2) + 2); sprintf(tbuf, mesg, path); #ifdef FEAT_EVAL ! // Set warningmsg here, before the unimportant and output-specific ! // mesg2 has been appended. set_vim_var_string(VV_WARNINGMSG, (char_u *)tbuf, -1); #endif #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) *************** *** 4190,4199 **** #ifdef FEAT_GUI if (!focus) #endif ! /* give the user some time to think about it */ ui_delay(1004L, TRUE); ! /* don't redraw and erase the message */ redraw_cmdline = FALSE; } } --- 4188,4197 ---- #ifdef FEAT_GUI if (!focus) #endif ! // give the user some time to think about it ui_delay(1004L, TRUE); ! // don't redraw and erase the message redraw_cmdline = FALSE; } } *************** *** 4207,4213 **** if (reload) { ! /* Reload the buffer. */ buf_reload(buf, orig_mode); #ifdef FEAT_PERSISTENT_UNDO if (buf->b_p_udf && buf->b_ffname != NULL) --- 4205,4211 ---- if (reload) { ! // Reload the buffer. buf_reload(buf, orig_mode); #ifdef FEAT_PERSISTENT_UNDO if (buf->b_p_udf && buf->b_ffname != NULL) *************** *** 4215,4221 **** char_u hash[UNDO_HASH_SIZE]; buf_T *save_curbuf = curbuf; ! /* Any existing undo file is unusable, write it now. */ curbuf = buf; u_compute_hash(hash); u_write_undo(NULL, FALSE, buf, hash); --- 4213,4219 ---- char_u hash[UNDO_HASH_SIZE]; buf_T *save_curbuf = curbuf; ! // Any existing undo file is unusable, write it now. curbuf = buf; u_compute_hash(hash); u_write_undo(NULL, FALSE, buf, hash); *************** *** 4224,4236 **** #endif } ! /* Trigger FileChangedShell when the file was changed in any way. */ if (bufref_valid(&bufref) && retval != 0) (void)apply_autocmds(EVENT_FILECHANGEDSHELLPOST, buf->b_fname, buf->b_fname, FALSE, buf); #ifdef FEAT_GUI ! /* restore this in case an autocommand has set it; it would break ! * 'mousefocus' */ need_mouse_correct = save_mouse_correct; #endif --- 4222,4234 ---- #endif } ! // Trigger FileChangedShell when the file was changed in any way. if (bufref_valid(&bufref) && retval != 0) (void)apply_autocmds(EVENT_FILECHANGEDSHELLPOST, buf->b_fname, buf->b_fname, FALSE, buf); #ifdef FEAT_GUI ! // restore this in case an autocommand has set it; it would break ! // 'mousefocus' need_mouse_correct = save_mouse_correct; #endif *************** *** 4256,4267 **** aco_save_T aco; int flags = READ_NEW; ! /* set curwin/curbuf for "buf" and save some things */ aucmd_prepbuf(&aco, buf); ! /* We only want to read the text from the file, not reset the syntax ! * highlighting, clear marks, diff status, etc. Force the fileformat ! * and encoding to be the same. */ if (prep_exarg(&ea, buf) == OK) { old_cursor = curwin->w_cursor; --- 4254,4265 ---- aco_save_T aco; int flags = READ_NEW; ! // set curwin/curbuf for "buf" and save some things aucmd_prepbuf(&aco, buf); ! // We only want to read the text from the file, not reset the syntax ! // highlighting, clear marks, diff status, etc. Force the fileformat ! // and encoding to be the same. if (prep_exarg(&ea, buf) == OK) { old_cursor = curwin->w_cursor; *************** *** 4269,4276 **** if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) { ! /* Save all the text, so that the reload can be undone. ! * Sync first so that this is a separate undo-able action. */ u_sync(FALSE); saved = u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, TRUE); flags |= READ_KEEP_UNDO; --- 4267,4274 ---- if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) { ! // Save all the text, so that the reload can be undone. ! // Sync first so that this is a separate undo-able action. u_sync(FALSE); saved = u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, TRUE); flags |= READ_KEEP_UNDO; *************** *** 4287,4298 **** savebuf = NULL; else { ! /* Allocate a buffer without putting it in the buffer list. */ savebuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); set_bufref(&bufref, savebuf); if (savebuf != NULL && buf == curbuf) { ! /* Open the memline. */ curbuf = savebuf; curwin->w_buffer = savebuf; saved = ml_open(curbuf); --- 4285,4296 ---- savebuf = NULL; else { ! // Allocate a buffer without putting it in the buffer list. savebuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); set_bufref(&bufref, savebuf); if (savebuf != NULL && buf == curbuf) { ! // Open the memline. curbuf = savebuf; curwin->w_buffer = savebuf; saved = ml_open(curbuf); *************** *** 4310,4317 **** if (saved == OK) { ! curbuf->b_flags |= BF_CHECK_RO; /* check for RO again */ ! keep_filetype = TRUE; /* don't detect 'filetype' */ if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, &ea, flags) != OK) --- 4308,4315 ---- if (saved == OK) { ! curbuf->b_flags |= BF_CHECK_RO; // check for RO again ! keep_filetype = TRUE; // don't detect 'filetype' if (readfile(buf->b_ffname, buf->b_fname, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, &ea, flags) != OK) *************** *** 4322,4338 **** semsg(_("E321: Could not reload \"%s\""), buf->b_fname); if (savebuf != NULL && bufref_valid(&bufref) && buf == curbuf) { ! /* Put the text back from the save buffer. First ! * delete any lines that readfile() added. */ while (!BUFEMPTY()) if (ml_delete(buf->b_ml.ml_line_count, FALSE) == FAIL) break; (void)move_lines(savebuf, buf); } } ! else if (buf == curbuf) /* "buf" still valid */ { ! /* Mark the buffer as unmodified and free undo info. */ unchanged(buf, TRUE, TRUE); if ((flags & READ_KEEP_UNDO) == 0) { --- 4320,4336 ---- semsg(_("E321: Could not reload \"%s\""), buf->b_fname); if (savebuf != NULL && bufref_valid(&bufref) && buf == curbuf) { ! // Put the text back from the save buffer. First ! // delete any lines that readfile() added. while (!BUFEMPTY()) if (ml_delete(buf->b_ml.ml_line_count, FALSE) == FAIL) break; (void)move_lines(savebuf, buf); } } ! else if (buf == curbuf) // "buf" still valid { ! // Mark the buffer as unmodified and free undo info. unchanged(buf, TRUE, TRUE); if ((flags & READ_KEEP_UNDO) == 0) { *************** *** 4341,4347 **** } else { ! /* Mark all undo states as changed. */ u_unchanged(curbuf); } } --- 4339,4345 ---- } else { ! // Mark all undo states as changed. u_unchanged(curbuf); } } *************** *** 4352,4363 **** wipe_buffer(savebuf, FALSE); #ifdef FEAT_DIFF ! /* Invalidate diff info if necessary. */ diff_invalidate(curbuf); #endif ! /* Restore the topline and cursor position and check it (lines may ! * have been removed). */ if (old_topline > curbuf->b_ml.ml_line_count) curwin->w_topline = curbuf->b_ml.ml_line_count; else --- 4350,4361 ---- wipe_buffer(savebuf, FALSE); #ifdef FEAT_DIFF ! // Invalidate diff info if necessary. diff_invalidate(curbuf); #endif ! // Restore the topline and cursor position and check it (lines may ! // have been removed). if (old_topline > curbuf->b_ml.ml_line_count) curwin->w_topline = curbuf->b_ml.ml_line_count; else *************** *** 4371,4396 **** win_T *wp; tabpage_T *tp; ! /* Update folds unless they are defined manually. */ FOR_ALL_TAB_WINDOWS(tp, wp) if (wp->w_buffer == curwin->w_buffer && !foldmethodIsManual(wp)) foldUpdateAll(wp); } #endif ! /* If the mode didn't change and 'readonly' was set, keep the old ! * value; the user probably used the ":view" command. But don't ! * reset it, might have had a read error. */ if (orig_mode == curbuf->b_orig_mode) curbuf->b_p_ro |= old_ro; ! /* Modelines must override settings done by autocommands. */ do_modelines(0); } ! /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); ! /* Careful: autocommands may have made "buf" invalid! */ } void --- 4369,4394 ---- win_T *wp; tabpage_T *tp; ! // Update folds unless they are defined manually. FOR_ALL_TAB_WINDOWS(tp, wp) if (wp->w_buffer == curwin->w_buffer && !foldmethodIsManual(wp)) foldUpdateAll(wp); } #endif ! // If the mode didn't change and 'readonly' was set, keep the old ! // value; the user probably used the ":view" command. But don't ! // reset it, might have had a read error. if (orig_mode == curbuf->b_orig_mode) curbuf->b_p_ro |= old_ro; ! // Modelines must override settings done by autocommands. do_modelines(0); } ! // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); ! // Careful: autocommands may have made "buf" invalid! } void *************** *** 4412,4418 **** void write_lnum_adjust(linenr_T offset) { ! if (curbuf->b_no_eol_lnum != 0) /* only if there is a missing eol */ curbuf->b_no_eol_lnum += offset; } --- 4410,4416 ---- void write_lnum_adjust(linenr_T offset) { ! if (curbuf->b_no_eol_lnum != 0) // only if there is a missing eol curbuf->b_no_eol_lnum += offset; } *************** *** 4611,4617 **** #endif #if defined(TEMPDIRNAMES) || defined(PROTO) ! static long temp_count = 0; /* Temp filename counter. */ /* * Delete the temp directory and all files it contains. --- 4609,4615 ---- #endif #if defined(TEMPDIRNAMES) || defined(PROTO) ! static long temp_count = 0; // Temp filename counter. /* * Delete the temp directory and all files it contains. *************** *** 4621,4627 **** { if (vim_tempdir != NULL) { ! /* remove the trailing path separator */ gettail(vim_tempdir)[-1] = NUL; delete_recursive(vim_tempdir); VIM_CLEAR(vim_tempdir); --- 4619,4625 ---- { if (vim_tempdir != NULL) { ! // remove the trailing path separator gettail(vim_tempdir)[-1] = NUL; delete_recursive(vim_tempdir); VIM_CLEAR(vim_tempdir); *************** *** 4661,4671 **** */ char_u * vim_tempname( ! int extra_char UNUSED, /* char to use in the name instead of '?' */ int keep UNUSED) { #ifdef USE_TMPNAM ! char_u itmp[L_tmpnam]; /* use tmpnam() */ #elif defined(MSWIN) WCHAR itmp[TEMPNAMELEN]; #else --- 4659,4669 ---- */ char_u * vim_tempname( ! int extra_char UNUSED, // char to use in the name instead of '?' int keep UNUSED) { #ifdef USE_TMPNAM ! char_u itmp[L_tmpnam]; // use tmpnam() #elif defined(MSWIN) WCHAR itmp[TEMPNAMELEN]; #else *************** *** 4699,4720 **** long off; # endif ! /* Expand $TMP, leave room for "/v1100000/999999999". ! * Skip the directory check if the expansion fails. */ expand_env((char_u *)tempdirs[i], itmp, TEMPNAMELEN - 20); if (itmp[0] != '$' && mch_isdir(itmp)) { ! /* directory exists */ add_pathsep(itmp); # ifdef HAVE_MKDTEMP { # if defined(UNIX) || defined(VMS) ! /* Make sure the umask doesn't remove the executable bit. ! * "repl" has been reported to use "177". */ mode_t umask_save = umask(077); # endif ! /* Leave room for filename */ STRCAT(itmp, "vXXXXXX"); if (mkdtemp((char *)itmp) != NULL) vim_settempdir(itmp); --- 4697,4718 ---- long off; # endif ! // Expand $TMP, leave room for "/v1100000/999999999". ! // Skip the directory check if the expansion fails. expand_env((char_u *)tempdirs[i], itmp, TEMPNAMELEN - 20); if (itmp[0] != '$' && mch_isdir(itmp)) { ! // directory exists add_pathsep(itmp); # ifdef HAVE_MKDTEMP { # if defined(UNIX) || defined(VMS) ! // Make sure the umask doesn't remove the executable bit. ! // "repl" has been reported to use "177". mode_t umask_save = umask(077); # endif ! // Leave room for filename STRCAT(itmp, "vXXXXXX"); if (mkdtemp((char *)itmp) != NULL) vim_settempdir(itmp); *************** *** 4723,4737 **** # endif } # else ! /* Get an arbitrary number of up to 6 digits. When it's ! * unlikely that it already exists it will be faster, ! * otherwise it doesn't matter. The use of mkdir() avoids any ! * security problems because of the predictable number. */ nr = (mch_get_pid() + (long)time(NULL)) % 1000000L; itmplen = STRLEN(itmp); ! /* Try up to 10000 different values until we find a name that ! * doesn't exist. */ for (off = 0; off < 10000L; ++off) { int r; --- 4721,4735 ---- # endif } # else ! // Get an arbitrary number of up to 6 digits. When it's ! // unlikely that it already exists it will be faster, ! // otherwise it doesn't matter. The use of mkdir() avoids any ! // security problems because of the predictable number. nr = (mch_get_pid() + (long)time(NULL)) % 1000000L; itmplen = STRLEN(itmp); ! // Try up to 10000 different values until we find a name that ! // doesn't exist. for (off = 0; off < 10000L; ++off) { int r; *************** *** 4741,4755 **** sprintf((char *)itmp + itmplen, "v%ld", nr + off); # ifndef EEXIST ! /* If mkdir() does not set errno to EEXIST, check for ! * existing file here. There is a race condition then, ! * although it's fail-safe. */ if (mch_stat((char *)itmp, &st) >= 0) continue; # endif # if defined(UNIX) || defined(VMS) ! /* Make sure the umask doesn't remove the executable bit. ! * "repl" has been reported to use "177". */ umask_save = umask(077); # endif r = vim_mkdir(itmp, 0700); --- 4739,4753 ---- sprintf((char *)itmp + itmplen, "v%ld", nr + off); # ifndef EEXIST ! // If mkdir() does not set errno to EEXIST, check for ! // existing file here. There is a race condition then, ! // although it's fail-safe. if (mch_stat((char *)itmp, &st) >= 0) continue; # endif # if defined(UNIX) || defined(VMS) ! // Make sure the umask doesn't remove the executable bit. ! // "repl" has been reported to use "177". umask_save = umask(077); # endif r = vim_mkdir(itmp, 0700); *************** *** 4762,4775 **** break; } # ifdef EEXIST ! /* If the mkdir() didn't fail because the file/dir exists, ! * we probably can't create any dir here, try another ! * place. */ if (errno != EEXIST) # endif break; } ! # endif /* HAVE_MKDTEMP */ if (vim_tempdir != NULL) break; } --- 4760,4773 ---- break; } # ifdef EEXIST ! // If the mkdir() didn't fail because the file/dir exists, ! // we probably can't create any dir here, try another ! // place. if (errno != EEXIST) # endif break; } ! # endif // HAVE_MKDTEMP if (vim_tempdir != NULL) break; } *************** *** 4778,4792 **** if (vim_tempdir != NULL) { ! /* There is no need to check if the file exists, because we own the ! * directory and nobody else creates a file in it. */ sprintf((char *)itmp, "%s%ld", vim_tempdir, temp_count++); return vim_strsave(itmp); } return NULL; ! #else /* TEMPDIRNAMES */ # ifdef MSWIN WCHAR wszTempFile[_MAX_PATH + 1]; --- 4776,4790 ---- if (vim_tempdir != NULL) { ! // There is no need to check if the file exists, because we own the ! // directory and nobody else creates a file in it. sprintf((char *)itmp, "%s%ld", vim_tempdir, temp_count++); return vim_strsave(itmp); } return NULL; ! #else // TEMPDIRNAMES # ifdef MSWIN WCHAR wszTempFile[_MAX_PATH + 1]; *************** *** 4801,4807 **** wszTempFile[1] = NUL; } wcscpy(buf4, L"VIM"); ! buf4[2] = extra_char; /* make it "VIa", "VIb", etc. */ if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0) return NULL; if (!keep) --- 4799,4805 ---- wszTempFile[1] = NUL; } wcscpy(buf4, L"VIM"); ! buf4[2] = extra_char; // make it "VIa", "VIb", etc. if (GetTempFileNameW(wszTempFile, buf4, 0, itmp) == 0) return NULL; if (!keep) *************** *** 4823,4829 **** # ifdef USE_TMPNAM char_u *p; ! /* tmpnam() will make its own name */ p = tmpnam((char *)itmp); if (p == NULL || *p == NUL) return NULL; --- 4821,4827 ---- # ifdef USE_TMPNAM char_u *p; ! // tmpnam() will make its own name p = tmpnam((char *)itmp); if (p == NULL || *p == NUL) return NULL; *************** *** 4831,4845 **** char_u *p; # ifdef VMS_TEMPNAM ! /* mktemp() is not working on VMS. It seems to be ! * a do-nothing function. Therefore we use tempnam(). ! */ sprintf((char *)itmp, "VIM%c", extra_char); p = (char_u *)tempnam("tmp:", (char *)itmp); if (p != NULL) { ! /* VMS will use '.LIS' if we don't explicitly specify an extension, ! * and VIM will then be unable to find the file later */ STRCPY(itmp, p); STRCAT(itmp, ".txt"); free(p); --- 4829,4842 ---- char_u *p; # ifdef VMS_TEMPNAM ! // mktemp() is not working on VMS. It seems to be ! // a do-nothing function. Therefore we use tempnam(). sprintf((char *)itmp, "VIM%c", extra_char); p = (char_u *)tempnam("tmp:", (char *)itmp); if (p != NULL) { ! // VMS will use '.LIS' if we don't explicitly specify an extension, ! // and VIM will then be unable to find the file later STRCPY(itmp, p); STRCAT(itmp, ".txt"); free(p); *************** *** 4857,4863 **** return vim_strsave(itmp); # endif // MSWIN ! #endif /* TEMPDIRNAMES */ } #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) --- 4854,4860 ---- return vim_strsave(itmp); # endif // MSWIN ! #endif // TEMPDIRNAMES } #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) *************** *** 4873,4879 **** if (path_with_url(fname)) return; for (p = fname; *p != NUL; ++p) ! /* The Big5 encoding can have '\' in the trail byte. */ if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) ++p; else if (*p == '\\') --- 4870,4876 ---- if (path_with_url(fname)) return; for (p = fname; *p != NUL; ++p) ! // The Big5 encoding can have '\' in the trail byte. if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) ++p; else if (*p == '\\') *************** *** 4890,4906 **** */ int match_file_pat( ! char_u *pattern, /* pattern to match with */ ! regprog_T **prog, /* pre-compiled regprog or NULL */ ! char_u *fname, /* full path of file name */ ! char_u *sfname, /* short file name or NULL */ ! char_u *tail, /* tail of path */ ! int allow_dirs) /* allow matching with dir */ { regmatch_T regmatch; int result = FALSE; ! regmatch.rm_ic = p_fic; /* ignore case if 'fileignorecase' is set */ if (prog != NULL) regmatch.regprog = *prog; else --- 4887,4903 ---- */ int match_file_pat( ! char_u *pattern, // pattern to match with ! regprog_T **prog, // pre-compiled regprog or NULL ! char_u *fname, // full path of file name ! char_u *sfname, // short file name or NULL ! char_u *tail, // tail of path ! int allow_dirs) // allow matching with dir { regmatch_T regmatch; int result = FALSE; ! regmatch.rm_ic = p_fic; // ignore case if 'fileignorecase' is set if (prog != NULL) regmatch.regprog = *prog; else *************** *** 4945,4951 **** tail = gettail(sfname); ! /* try all patterns in 'wildignore' */ p = list; while (*p) { --- 4942,4948 ---- tail = gettail(sfname); ! // try all patterns in 'wildignore' p = list; while (*p) { *************** *** 4975,4985 **** char_u * file_pat_to_reg_pat( char_u *pat, ! char_u *pat_end, /* first char after pattern or NULL */ ! char *allow_dirs, /* Result passed back out in here */ ! int no_bslash UNUSED) /* Don't use a backward slash as pathsep */ { ! int size = 2; /* '^' at start, '$' at end */ char_u *endp; char_u *reg_pat; char_u *p; --- 4972,4982 ---- char_u * file_pat_to_reg_pat( char_u *pat, ! char_u *pat_end, // first char after pattern or NULL ! char *allow_dirs, // Result passed back out in here ! int no_bslash UNUSED) // Don't use a backward slash as pathsep { ! int size = 2; // '^' at start, '$' at end char_u *endp; char_u *reg_pat; char_u *p; *************** *** 5002,5013 **** case '{': case '}': case '~': ! size += 2; /* extra backslash */ break; #ifdef BACKSLASH_IN_FILENAME case '\\': case '/': ! size += 4; /* could become "[\/]" */ break; #endif default: --- 4999,5010 ---- case '{': case '}': case '~': ! size += 2; // extra backslash break; #ifdef BACKSLASH_IN_FILENAME case '\\': case '/': ! size += 4; // could become "[\/]" break; #endif default: *************** *** 5045,5051 **** case '*': reg_pat[i++] = '.'; reg_pat[i++] = '*'; ! while (p[1] == '*') /* "**" matches like "*" */ ++p; break; case '.': --- 5042,5048 ---- case '*': reg_pat[i++] = '.'; reg_pat[i++] = '*'; ! while (p[1] == '*') // "**" matches like "*" ++p; break; case '.': *************** *** 5062,5073 **** #ifdef BACKSLASH_IN_FILENAME if (!no_bslash) { ! /* translate: ! * "\x" to "\\x" e.g., "dir\file" ! * "\*" to "\\.*" e.g., "dir\*.c" ! * "\?" to "\\." e.g., "dir\??.c" ! * "\+" to "\+" e.g., "fileX\+.c" ! */ if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?') && p[1] != '+') { --- 5059,5069 ---- #ifdef BACKSLASH_IN_FILENAME if (!no_bslash) { ! // translate: ! // "\x" to "\\x" e.g., "dir\file" ! // "\*" to "\\.*" e.g., "dir\*.c" ! // "\?" to "\\." e.g., "dir\??.c" ! // "\+" to "\+" e.g., "fileX\+.c" if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?') && p[1] != '+') { *************** *** 5081,5096 **** } } #endif ! /* Undo escaping from ExpandEscape(): ! * foo\?bar -> foo?bar ! * foo\%bar -> foo%bar ! * foo\,bar -> foo,bar ! * foo\ bar -> foo bar ! * Don't unescape \, * and others that are also special in a ! * regexp. ! * An escaped { must be unescaped since we use magic not ! * verymagic. Use "\\\{n,m\}"" to get "\{n,m}". ! */ if (*++p == '?' #ifdef BACKSLASH_IN_FILENAME && no_bslash --- 5077,5091 ---- } } #endif ! // Undo escaping from ExpandEscape(): ! // foo\?bar -> foo?bar ! // foo\%bar -> foo%bar ! // foo\,bar -> foo,bar ! // foo\ bar -> foo bar ! // Don't unescape \, * and others that are also special in a ! // regexp. ! // An escaped { must be unescaped since we use magic not ! // verymagic. Use "\\\{n,m\}"" to get "\{n,m}". if (*++p == '?' #ifdef BACKSLASH_IN_FILENAME && no_bslash *************** *** 5200,5207 **** long ret = 0; long wlen; ! /* Repeat the write() so long it didn't fail, other than being interrupted ! * by a signal. */ while (ret < (long)bufsize) { wlen = vim_write(fd, (char *)buf + ret, bufsize - ret); --- 5195,5202 ---- long ret = 0; long wlen; ! // Repeat the write() so long it didn't fail, other than being interrupted ! // by a signal. while (ret < (long)bufsize) { wlen = vim_write(fd, (char *)buf + ret, bufsize - ret); *** ../vim-8.1.2378/src/filepath.c 2019-11-04 20:36:46.128633933 +0100 --- src/filepath.c 2019-12-01 21:36:22.231086872 +0100 *************** *** 162,168 **** * path with the remaining path at the tail. */ ! /* Compute the length of the new path. */ sfx_len = (int)(save_endp - endp) + 1; new_len = len + sfx_len; --- 162,168 ---- * path with the remaining path at the tail. */ ! // Compute the length of the new path. sfx_len = (int)(save_endp - endp) + 1; new_len = len + sfx_len; *************** *** 2367,2373 **** r2 = mch_stat((char *)s2, &st2); if (r1 != 0 && r2 != 0) { ! /* if mch_stat() doesn't work, may compare the names */ if (checkname) { if (fnamecmp(exp1, s2) == 0) --- 2367,2373 ---- r2 = mch_stat((char *)s2, &st2); if (r1 != 0 && r2 != 0) { ! // if mch_stat() doesn't work, may compare the names if (checkname) { if (fnamecmp(exp1, s2) == 0) *************** *** 3689,3695 **** void addfile( garray_T *gap, ! char_u *f, /* filename */ int flags) { char_u *p; --- 3689,3695 ---- void addfile( garray_T *gap, ! char_u *f, // filename int flags) { char_u *p; *** ../vim-8.1.2378/src/findfile.c 2019-10-06 22:00:08.297244105 +0200 --- src/findfile.c 2019-12-01 21:36:43.139000511 +0100 *************** *** 968,974 **** { if (!path_with_url(stackp->ffs_filearray[i]) && !mch_isdir(stackp->ffs_filearray[i])) ! continue; /* not a directory */ // prepare the filename to be checked for existence // below --- 968,974 ---- { if (!path_with_url(stackp->ffs_filearray[i]) && !mch_isdir(stackp->ffs_filearray[i])) ! continue; // not a directory // prepare the filename to be checked for existence // below *************** *** 2690,2696 **** char_u saved_char; stat_T st; ! /* Don't strip for an erroneous file name. */ if (!stripping_disabled) { // If the preceding component does not exist in the file --- 2690,2696 ---- char_u saved_char; stat_T st; ! // Don't strip for an erroneous file name. if (!stripping_disabled) { // If the preceding component does not exist in the file *************** *** 2827,2833 **** p = tv_get_string(&argvars[0]); rettv->vval.v_string = vim_strsave(p); ! simplify_filename(rettv->vval.v_string); /* simplify in place */ rettv->v_type = VAR_STRING; } #endif // FEAT_EVAL --- 2827,2833 ---- p = tv_get_string(&argvars[0]); rettv->vval.v_string = vim_strsave(p); ! simplify_filename(rettv->vval.v_string); // simplify in place rettv->v_type = VAR_STRING; } #endif // FEAT_EVAL *** ../vim-8.1.2378/src/fold.c 2019-09-28 19:04:06.993029586 +0200 --- src/fold.c 2019-12-01 21:40:39.786022604 +0100 *************** *** 16,23 **** #if defined(FEAT_FOLDING) || defined(PROTO) ! /* local declarations. {{{1 */ ! /* typedef fold_T {{{2 */ /* * The toplevel folds for each window are stored in the w_folds growarray. * Each toplevel fold can contain an array of second level folds in the --- 16,23 ---- #if defined(FEAT_FOLDING) || defined(PROTO) ! // local declarations. {{{1 ! // typedef fold_T {{{2 /* * The toplevel folds for each window are stored in the w_folds growarray. * Each toplevel fold can contain an array of second level folds in the *************** *** 26,48 **** */ typedef struct { ! linenr_T fd_top; /* first line of fold; for nested fold ! * relative to parent */ ! linenr_T fd_len; /* number of lines in the fold */ ! garray_T fd_nested; /* array of nested folds */ ! char fd_flags; /* see below */ ! char fd_small; /* TRUE, FALSE or MAYBE: fold smaller than ! 'foldminlines'; MAYBE applies to nested ! folds too */ } fold_T; ! #define FD_OPEN 0 /* fold is open (nested ones can be closed) */ ! #define FD_CLOSED 1 /* fold is closed */ ! #define FD_LEVEL 2 /* depends on 'foldlevel' (nested folds too) */ ! #define MAX_LEVEL 20 /* maximum fold depth */ ! /* static functions {{{2 */ static void newFoldLevelWin(win_T *wp); static int checkCloseRec(garray_T *gap, linenr_T lnum, int level); static int foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp); --- 26,48 ---- */ typedef struct { ! linenr_T fd_top; // first line of fold; for nested fold ! // relative to parent ! linenr_T fd_len; // number of lines in the fold ! garray_T fd_nested; // array of nested folds ! char fd_flags; // see below ! char fd_small; // TRUE, FALSE or MAYBE: fold smaller than ! // 'foldminlines'; MAYBE applies to nested ! // folds too } fold_T; ! #define FD_OPEN 0 // fold is open (nested ones can be closed) ! #define FD_CLOSED 1 // fold is closed ! #define FD_LEVEL 2 // depends on 'foldlevel' (nested folds too) ! #define MAX_LEVEL 20 // maximum fold depth ! // static functions {{{2 static void newFoldLevelWin(win_T *wp); static int checkCloseRec(garray_T *gap, linenr_T lnum, int level); static int foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp); *************** *** 84,100 **** static linenr_T prev_lnum = 0; static int prev_lnum_lvl = -1; ! /* Flags used for "done" argument of setManualFold. */ #define DONE_NOTHING 0 ! #define DONE_ACTION 1 /* did close or open a fold */ ! #define DONE_FOLD 2 /* did find a fold */ static int foldstartmarkerlen; static char_u *foldendmarker; static int foldendmarkerlen; ! /* Exported folding functions. {{{1 */ ! /* copyFoldingState() {{{2 */ /* * Copy that folding state from window "wp_from" to window "wp_to". --- 84,100 ---- static linenr_T prev_lnum = 0; static int prev_lnum_lvl = -1; ! // Flags used for "done" argument of setManualFold. #define DONE_NOTHING 0 ! #define DONE_ACTION 1 // did close or open a fold ! #define DONE_FOLD 2 // did find a fold static int foldstartmarkerlen; static char_u *foldendmarker; static int foldendmarkerlen; ! // Exported folding functions. {{{1 ! // copyFoldingState() {{{2 /* * Copy that folding state from window "wp_from" to window "wp_to". *************** *** 107,125 **** cloneFoldGrowArray(&wp_from->w_folds, &wp_to->w_folds); } ! /* hasAnyFolding() {{{2 */ /* * Return TRUE if there may be folded lines in the current window. */ int hasAnyFolding(win_T *win) { ! /* very simple now, but can become more complex later */ return (win->w_p_fen && (!foldmethodIsManual(win) || win->w_folds.ga_len > 0)); } ! /* hasFolding() {{{2 */ /* * Return TRUE if line "lnum" in the current window is part of a closed * fold. --- 107,125 ---- cloneFoldGrowArray(&wp_from->w_folds, &wp_to->w_folds); } ! // hasAnyFolding() {{{2 /* * Return TRUE if there may be folded lines in the current window. */ int hasAnyFolding(win_T *win) { ! // very simple now, but can become more complex later return (win->w_p_fen && (!foldmethodIsManual(win) || win->w_folds.ga_len > 0)); } ! // hasFolding() {{{2 /* * Return TRUE if line "lnum" in the current window is part of a closed * fold. *************** *** 132,146 **** return hasFoldingWin(curwin, lnum, firstp, lastp, TRUE, NULL); } ! /* hasFoldingWin() {{{2 */ int hasFoldingWin( win_T *win, linenr_T lnum, linenr_T *firstp, linenr_T *lastp, ! int cache, /* when TRUE: use cached values of window */ ! foldinfo_T *infop) /* where to store fold info */ { int had_folded = FALSE; linenr_T first = 0; --- 132,146 ---- return hasFoldingWin(curwin, lnum, firstp, lastp, TRUE, NULL); } ! // hasFoldingWin() {{{2 int hasFoldingWin( win_T *win, linenr_T lnum, linenr_T *firstp, linenr_T *lastp, ! int cache, // when TRUE: use cached values of window ! foldinfo_T *infop) // where to store fold info { int had_folded = FALSE; linenr_T first = 0; *************** *** 192,216 **** if (!foldFind(gap, lnum_rel, &fp)) break; ! /* Remember lowest level of fold that starts in "lnum". */ if (lnum_rel == fp->fd_top && low_level == 0) low_level = level + 1; first += fp->fd_top; last += fp->fd_top; ! /* is this fold closed? */ had_folded = check_closed(win, fp, &use_level, level, &maybe_small, lnum - lnum_rel); if (had_folded) { ! /* Fold closed: Set last and quit loop. */ last += fp->fd_len - 1; break; } ! /* Fold found, but it's open: Check nested folds. Line number is ! * relative to containing fold. */ gap = &fp->fd_nested; lnum_rel -= fp->fd_top; ++level; --- 192,216 ---- if (!foldFind(gap, lnum_rel, &fp)) break; ! // Remember lowest level of fold that starts in "lnum". if (lnum_rel == fp->fd_top && low_level == 0) low_level = level + 1; first += fp->fd_top; last += fp->fd_top; ! // is this fold closed? had_folded = check_closed(win, fp, &use_level, level, &maybe_small, lnum - lnum_rel); if (had_folded) { ! // Fold closed: Set last and quit loop. last += fp->fd_len - 1; break; } ! // Fold found, but it's open: Check nested folds. Line number is ! // relative to containing fold. gap = &fp->fd_nested; lnum_rel -= fp->fd_top; ++level; *************** *** 243,249 **** return TRUE; } ! /* foldLevel() {{{2 */ #ifdef FEAT_EVAL /* * Return fold level at line number "lnum" in the current window. --- 243,249 ---- return TRUE; } ! // foldLevel() {{{2 #ifdef FEAT_EVAL /* * Return fold level at line number "lnum" in the current window. *************** *** 251,258 **** static int foldLevel(linenr_T lnum) { ! /* While updating the folds lines between invalid_top and invalid_bot have ! * an undefined fold level. Otherwise update the folds first. */ if (invalid_top == (linenr_T)0) checkupdate(curwin); else if (lnum == prev_lnum && prev_lnum_lvl >= 0) --- 251,258 ---- static int foldLevel(linenr_T lnum) { ! // While updating the folds lines between invalid_top and invalid_bot have ! // an undefined fold level. Otherwise update the folds first. if (invalid_top == (linenr_T)0) checkupdate(curwin); else if (lnum == prev_lnum && prev_lnum_lvl >= 0) *************** *** 260,266 **** else if (lnum >= invalid_top && lnum <= invalid_bot) return -1; ! /* Return quickly when there is no folding at all in this window. */ if (!hasAnyFolding(curwin)) return 0; --- 260,266 ---- else if (lnum >= invalid_top && lnum <= invalid_bot) return -1; ! // Return quickly when there is no folding at all in this window. if (!hasAnyFolding(curwin)) return 0; *************** *** 268,274 **** } #endif ! /* lineFolded() {{{2 */ /* * Low level function to check if a line is folded. Doesn't use any caching. * Return TRUE if line is folded. --- 268,274 ---- } #endif ! // lineFolded() {{{2 /* * Low level function to check if a line is folded. Doesn't use any caching. * Return TRUE if line is folded. *************** *** 281,287 **** return foldedCount(win, lnum, NULL) != 0; } ! /* foldedCount() {{{2 */ /* * Count the number of lines that are folded at line number "lnum". * Normally "lnum" is the first line of a possible fold, and the returned --- 281,287 ---- return foldedCount(win, lnum, NULL) != 0; } ! // foldedCount() {{{2 /* * Count the number of lines that are folded at line number "lnum". * Normally "lnum" is the first line of a possible fold, and the returned *************** *** 300,306 **** return 0; } ! /* foldmethodIsManual() {{{2 */ /* * Return TRUE if 'foldmethod' is "manual" */ --- 300,306 ---- return 0; } ! // foldmethodIsManual() {{{2 /* * Return TRUE if 'foldmethod' is "manual" */ *************** *** 310,316 **** return (wp->w_p_fdm[3] == 'u'); } ! /* foldmethodIsIndent() {{{2 */ /* * Return TRUE if 'foldmethod' is "indent" */ --- 310,316 ---- return (wp->w_p_fdm[3] == 'u'); } ! // foldmethodIsIndent() {{{2 /* * Return TRUE if 'foldmethod' is "indent" */ *************** *** 320,326 **** return (wp->w_p_fdm[0] == 'i'); } ! /* foldmethodIsExpr() {{{2 */ /* * Return TRUE if 'foldmethod' is "expr" */ --- 320,326 ---- return (wp->w_p_fdm[0] == 'i'); } ! // foldmethodIsExpr() {{{2 /* * Return TRUE if 'foldmethod' is "expr" */ *************** *** 330,336 **** return (wp->w_p_fdm[1] == 'x'); } ! /* foldmethodIsMarker() {{{2 */ /* * Return TRUE if 'foldmethod' is "marker" */ --- 330,336 ---- return (wp->w_p_fdm[1] == 'x'); } ! // foldmethodIsMarker() {{{2 /* * Return TRUE if 'foldmethod' is "marker" */ *************** *** 340,346 **** return (wp->w_p_fdm[2] == 'r'); } ! /* foldmethodIsSyntax() {{{2 */ /* * Return TRUE if 'foldmethod' is "syntax" */ --- 340,346 ---- return (wp->w_p_fdm[2] == 'r'); } ! // foldmethodIsSyntax() {{{2 /* * Return TRUE if 'foldmethod' is "syntax" */ *************** *** 350,356 **** return (wp->w_p_fdm[0] == 's'); } ! /* foldmethodIsDiff() {{{2 */ /* * Return TRUE if 'foldmethod' is "diff" */ --- 350,356 ---- return (wp->w_p_fdm[0] == 's'); } ! // foldmethodIsDiff() {{{2 /* * Return TRUE if 'foldmethod' is "diff" */ *************** *** 360,366 **** return (wp->w_p_fdm[0] == 'd'); } ! /* closeFold() {{{2 */ /* * Close fold for current window at line "lnum". * Repeat "count" times. --- 360,366 ---- return (wp->w_p_fdm[0] == 'd'); } ! // closeFold() {{{2 /* * Close fold for current window at line "lnum". * Repeat "count" times. *************** *** 371,377 **** setFoldRepeat(lnum, count, FALSE); } ! /* closeFoldRecurse() {{{2 */ /* * Close fold for current window at line "lnum" recursively. */ --- 371,377 ---- setFoldRepeat(lnum, count, FALSE); } ! // closeFoldRecurse() {{{2 /* * Close fold for current window at line "lnum" recursively. */ *************** *** 381,387 **** (void)setManualFold(lnum, FALSE, TRUE, NULL); } ! /* opFoldRange() {{{2 */ /* * Open or Close folds for current window in lines "first" to "last". * Used for "zo", "zO", "zc" and "zC" in Visual mode. --- 381,387 ---- (void)setManualFold(lnum, FALSE, TRUE, NULL); } ! // opFoldRange() {{{2 /* * Open or Close folds for current window in lines "first" to "last". * Used for "zo", "zO", "zc" and "zC" in Visual mode. *************** *** 390,424 **** opFoldRange( linenr_T first, linenr_T last, ! int opening, /* TRUE to open, FALSE to close */ ! int recurse, /* TRUE to do it recursively */ ! int had_visual) /* TRUE when Visual selection used */ { ! int done = DONE_NOTHING; /* avoid error messages */ linenr_T lnum; linenr_T lnum_next; for (lnum = first; lnum <= last; lnum = lnum_next + 1) { lnum_next = lnum; ! /* Opening one level only: next fold to open is after the one going to ! * be opened. */ if (opening && !recurse) (void)hasFolding(lnum, NULL, &lnum_next); (void)setManualFold(lnum, opening, recurse, &done); ! /* Closing one level only: next line to close a fold is after just ! * closed fold. */ if (!opening && !recurse) (void)hasFolding(lnum, NULL, &lnum_next); } if (done == DONE_NOTHING) emsg(_(e_nofold)); ! /* Force a redraw to remove the Visual highlighting. */ if (had_visual) redraw_curbuf_later(INVERTED); } ! /* openFold() {{{2 */ /* * Open fold for current window at line "lnum". * Repeat "count" times. --- 390,424 ---- opFoldRange( linenr_T first, linenr_T last, ! int opening, // TRUE to open, FALSE to close ! int recurse, // TRUE to do it recursively ! int had_visual) // TRUE when Visual selection used { ! int done = DONE_NOTHING; // avoid error messages linenr_T lnum; linenr_T lnum_next; for (lnum = first; lnum <= last; lnum = lnum_next + 1) { lnum_next = lnum; ! // Opening one level only: next fold to open is after the one going to ! // be opened. if (opening && !recurse) (void)hasFolding(lnum, NULL, &lnum_next); (void)setManualFold(lnum, opening, recurse, &done); ! // Closing one level only: next line to close a fold is after just ! // closed fold. if (!opening && !recurse) (void)hasFolding(lnum, NULL, &lnum_next); } if (done == DONE_NOTHING) emsg(_(e_nofold)); ! // Force a redraw to remove the Visual highlighting. if (had_visual) redraw_curbuf_later(INVERTED); } ! // openFold() {{{2 /* * Open fold for current window at line "lnum". * Repeat "count" times. *************** *** 429,435 **** setFoldRepeat(lnum, count, TRUE); } ! /* openFoldRecurse() {{{2 */ /* * Open fold for current window at line "lnum" recursively. */ --- 429,435 ---- setFoldRepeat(lnum, count, TRUE); } ! // openFoldRecurse() {{{2 /* * Open fold for current window at line "lnum" recursively. */ *************** *** 439,445 **** (void)setManualFold(lnum, TRUE, TRUE, NULL); } ! /* foldOpenCursor() {{{2 */ /* * Open folds until the cursor line is not in a closed fold. */ --- 439,445 ---- (void)setManualFold(lnum, TRUE, TRUE, NULL); } ! // foldOpenCursor() {{{2 /* * Open folds until the cursor line is not in a closed fold. */ *************** *** 459,465 **** } } ! /* newFoldLevel() {{{2 */ /* * Set new foldlevel for current window. */ --- 459,465 ---- } } ! // newFoldLevel() {{{2 /* * Set new foldlevel for current window. */ *************** *** 497,505 **** checkupdate(wp); if (wp->w_fold_manual) { ! /* Set all flags for the first level of folds to FD_LEVEL. Following ! * manual open/close will then change the flags to FD_OPEN or ! * FD_CLOSED for those folds that don't use 'foldlevel'. */ fp = (fold_T *)wp->w_folds.ga_data; for (i = 0; i < wp->w_folds.ga_len; ++i) fp[i].fd_flags = FD_LEVEL; --- 497,505 ---- checkupdate(wp); if (wp->w_fold_manual) { ! // Set all flags for the first level of folds to FD_LEVEL. Following ! // manual open/close will then change the flags to FD_OPEN or ! // FD_CLOSED for those folds that don't use 'foldlevel'. fp = (fold_T *)wp->w_folds.ga_data; for (i = 0; i < wp->w_folds.ga_len; ++i) fp[i].fd_flags = FD_LEVEL; *************** *** 508,521 **** changed_window_setting_win(wp); } ! /* foldCheckClose() {{{2 */ /* * Apply 'foldlevel' to all folds that don't contain the cursor. */ void foldCheckClose(void) { ! if (*p_fcl != NUL) /* can only be "all" right now */ { checkupdate(curwin); if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum, --- 508,521 ---- changed_window_setting_win(wp); } ! // foldCheckClose() {{{2 /* * Apply 'foldlevel' to all folds that don't contain the cursor. */ void foldCheckClose(void) { ! if (*p_fcl != NUL) // can only be "all" right now { checkupdate(curwin); if (checkCloseRec(&curwin->w_folds, curwin->w_cursor.lnum, *************** *** 524,530 **** } } ! /* checkCloseRec() {{{2 */ static int checkCloseRec(garray_T *gap, linenr_T lnum, int level) { --- 524,530 ---- } } ! // checkCloseRec() {{{2 static int checkCloseRec(garray_T *gap, linenr_T lnum, int level) { *************** *** 535,541 **** fp = (fold_T *)gap->ga_data; for (i = 0; i < gap->ga_len; ++i) { ! /* Only manually opened folds may need to be closed. */ if (fp[i].fd_flags == FD_OPEN) { if (level <= 0 && (lnum < fp[i].fd_top --- 535,541 ---- fp = (fold_T *)gap->ga_data; for (i = 0; i < gap->ga_len; ++i) { ! // Only manually opened folds may need to be closed. if (fp[i].fd_flags == FD_OPEN) { if (level <= 0 && (lnum < fp[i].fd_top *************** *** 552,558 **** return retval; } ! /* foldCreateAllowed() {{{2 */ /* * Return TRUE if it's allowed to manually create or delete a fold. * Give an error message and return FALSE if not. --- 552,558 ---- return retval; } ! // foldCreateAllowed() {{{2 /* * Return TRUE if it's allowed to manually create or delete a fold. * Give an error message and return FALSE if not. *************** *** 569,575 **** return FALSE; } ! /* foldCreate() {{{2 */ /* * Create a fold from line "start" to line "end" (inclusive) in the current * window. --- 569,575 ---- return FALSE; } ! // foldCreate() {{{2 /* * Create a fold from line "start" to line "end" (inclusive) in the current * window. *************** *** 590,603 **** if (start > end) { ! /* reverse the range */ end = start_rel; start = end_rel; start_rel = start; end_rel = end; } ! /* When 'foldmethod' is "marker" add markers, which creates the folds. */ if (foldmethodIsMarker(curwin)) { foldCreateMarkers(start, end); --- 590,603 ---- if (start > end) { ! // reverse the range end = start_rel; start = end_rel; start_rel = start; end_rel = end; } ! // When 'foldmethod' is "marker" add markers, which creates the folds. if (foldmethodIsMarker(curwin)) { foldCreateMarkers(start, end); *************** *** 606,612 **** checkupdate(curwin); ! /* Find the place to insert the new fold. */ gap = &curwin->w_folds; for (;;) { --- 606,612 ---- checkupdate(curwin); ! // Find the place to insert the new fold. gap = &curwin->w_folds; for (;;) { *************** *** 614,620 **** break; if (fp->fd_top + fp->fd_len > end_rel) { ! /* New fold is completely inside this fold: Go one level deeper. */ gap = &fp->fd_nested; start_rel -= fp->fd_top; end_rel -= fp->fd_top; --- 614,620 ---- break; if (fp->fd_top + fp->fd_len > end_rel) { ! // New fold is completely inside this fold: Go one level deeper. gap = &fp->fd_nested; start_rel -= fp->fd_top; end_rel -= fp->fd_top; *************** *** 630,637 **** } else { ! /* This fold and new fold overlap: Insert here and move some folds ! * inside the new fold. */ break; } } --- 630,637 ---- } else { ! // This fold and new fold overlap: Insert here and move some folds ! // inside the new fold. break; } } *************** *** 642,686 **** fp = (fold_T *)gap->ga_data + i; ga_init2(&fold_ga, (int)sizeof(fold_T), 10); ! /* Count number of folds that will be contained in the new fold. */ for (cont = 0; i + cont < gap->ga_len; ++cont) if (fp[cont].fd_top > end_rel) break; if (cont > 0 && ga_grow(&fold_ga, cont) == OK) { ! /* If the first fold starts before the new fold, let the new fold ! * start there. Otherwise the existing fold would change. */ if (start_rel > fp->fd_top) start_rel = fp->fd_top; ! /* When last contained fold isn't completely contained, adjust end ! * of new fold. */ if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; ! /* Move contained folds to inside new fold. */ mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); fold_ga.ga_len += cont; i += cont; ! /* Adjust line numbers in contained folds to be relative to the ! * new fold. */ for (j = 0; j < cont; ++j) ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel; } ! /* Move remaining entries to after the new fold. */ if (i < gap->ga_len) mch_memmove(fp + 1, (fold_T *)gap->ga_data + i, sizeof(fold_T) * (gap->ga_len - i)); gap->ga_len = gap->ga_len + 1 - cont; ! /* insert new fold */ fp->fd_nested = fold_ga; fp->fd_top = start_rel; fp->fd_len = end_rel - start_rel + 1; ! /* We want the new fold to be closed. If it would remain open because ! * of using 'foldlevel', need to adjust fd_flags of containing folds. ! */ if (use_level && !closed && level < curwin->w_p_fdl) closeFold(start, 1L); if (!use_level) --- 642,685 ---- fp = (fold_T *)gap->ga_data + i; ga_init2(&fold_ga, (int)sizeof(fold_T), 10); ! // Count number of folds that will be contained in the new fold. for (cont = 0; i + cont < gap->ga_len; ++cont) if (fp[cont].fd_top > end_rel) break; if (cont > 0 && ga_grow(&fold_ga, cont) == OK) { ! // If the first fold starts before the new fold, let the new fold ! // start there. Otherwise the existing fold would change. if (start_rel > fp->fd_top) start_rel = fp->fd_top; ! // When last contained fold isn't completely contained, adjust end ! // of new fold. if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; ! // Move contained folds to inside new fold. mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); fold_ga.ga_len += cont; i += cont; ! // Adjust line numbers in contained folds to be relative to the ! // new fold. for (j = 0; j < cont; ++j) ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel; } ! // Move remaining entries to after the new fold. if (i < gap->ga_len) mch_memmove(fp + 1, (fold_T *)gap->ga_data + i, sizeof(fold_T) * (gap->ga_len - i)); gap->ga_len = gap->ga_len + 1 - cont; ! // insert new fold fp->fd_nested = fold_ga; fp->fd_top = start_rel; fp->fd_len = end_rel - start_rel + 1; ! // We want the new fold to be closed. If it would remain open because ! // of using 'foldlevel', need to adjust fd_flags of containing folds. if (use_level && !closed && level < curwin->w_p_fdl) closeFold(start, 1L); if (!use_level) *************** *** 688,699 **** fp->fd_flags = FD_CLOSED; fp->fd_small = MAYBE; ! /* redraw */ changed_window_setting(); } } ! /* deleteFold() {{{2 */ /* * Delete a fold at line "start" in the current window. * When "end" is not 0, delete all folds from "start" to "end". --- 687,698 ---- fp->fd_flags = FD_CLOSED; fp->fd_small = MAYBE; ! // redraw changed_window_setting(); } } ! // deleteFold() {{{2 /* * Delete a fold at line "start" in the current window. * When "end" is not 0, delete all folds from "start" to "end". *************** *** 704,710 **** linenr_T start, linenr_T end, int recursive, ! int had_visual) /* TRUE when Visual selection used */ { garray_T *gap; fold_T *fp; --- 703,709 ---- linenr_T start, linenr_T end, int recursive, ! int had_visual) // TRUE when Visual selection used { garray_T *gap; fold_T *fp; *************** *** 724,730 **** while (lnum <= end) { ! /* Find the deepest fold for "start". */ gap = &curwin->w_folds; found_ga = NULL; lnum_off = 0; --- 723,729 ---- while (lnum <= end) { ! // Find the deepest fold for "start". gap = &curwin->w_folds; found_ga = NULL; lnum_off = 0; *************** *** 733,749 **** { if (!foldFind(gap, lnum - lnum_off, &fp)) break; ! /* lnum is inside this fold, remember info */ found_ga = gap; found_fp = fp; found_off = lnum_off; ! /* if "lnum" is folded, don't check nesting */ if (check_closed(curwin, fp, &use_level, level, &maybe_small, lnum_off)) break; ! /* check nested folds */ gap = &fp->fd_nested; lnum_off += fp->fd_top; ++level; --- 732,748 ---- { if (!foldFind(gap, lnum - lnum_off, &fp)) break; ! // lnum is inside this fold, remember info found_ga = gap; found_fp = fp; found_off = lnum_off; ! // if "lnum" is folded, don't check nesting if (check_closed(curwin, fp, &use_level, level, &maybe_small, lnum_off)) break; ! // check nested folds gap = &fp->fd_nested; lnum_off += fp->fd_top; ++level; *************** *** 771,796 **** } did_one = TRUE; ! /* redraw window */ changed_window_setting(); } } if (!did_one) { emsg(_(e_nofold)); ! /* Force a redraw to remove the Visual highlighting. */ if (had_visual) redraw_curbuf_later(INVERTED); } else ! /* Deleting markers may make cursor column invalid. */ check_cursor_col(); if (last_lnum > 0) changed_lines(first_lnum, (colnr_T)0, last_lnum, 0L); } ! /* clearFolding() {{{2 */ /* * Remove all folding for window "win". */ --- 770,795 ---- } did_one = TRUE; ! // redraw window changed_window_setting(); } } if (!did_one) { emsg(_(e_nofold)); ! // Force a redraw to remove the Visual highlighting. if (had_visual) redraw_curbuf_later(INVERTED); } else ! // Deleting markers may make cursor column invalid. check_cursor_col(); if (last_lnum > 0) changed_lines(first_lnum, (colnr_T)0, last_lnum, 0L); } ! // clearFolding() {{{2 /* * Remove all folding for window "win". */ *************** *** 801,807 **** win->w_foldinvalid = FALSE; } ! /* foldUpdate() {{{2 */ /* * Update folds for changes in the buffer of a window. * Note that inserted/deleted lines must have already been taken care of by --- 800,806 ---- win->w_foldinvalid = FALSE; } ! // foldUpdate() {{{2 /* * Update folds for changes in the buffer of a window. * Note that inserted/deleted lines must have already been taken care of by *************** *** 821,827 **** return; #endif ! /* Mark all folds from top to bot as maybe-small. */ (void)foldFind(&wp->w_folds, top, &fp); while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len && fp->fd_top < bot) --- 820,826 ---- return; #endif ! // Mark all folds from top to bot as maybe-small. (void)foldFind(&wp->w_folds, top, &fp); while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len && fp->fd_top < bot) *************** *** 840,853 **** { int save_got_int = got_int; ! /* reset got_int here, otherwise it won't work */ got_int = FALSE; foldUpdateIEMS(wp, top, bot); got_int |= save_got_int; } } ! /* foldUpdateAll() {{{2 */ /* * Update all lines in a window for folding. * Used when a fold setting changes or after reloading the buffer. --- 839,852 ---- { int save_got_int = got_int; ! // reset got_int here, otherwise it won't work got_int = FALSE; foldUpdateIEMS(wp, top, bot); got_int |= save_got_int; } } ! // foldUpdateAll() {{{2 /* * Update all lines in a window for folding. * Used when a fold setting changes or after reloading the buffer. *************** *** 861,867 **** redraw_win_later(win, NOT_VALID); } ! /* foldMoveTo() {{{2 */ /* * If "updown" is FALSE: Move to the start or end of the fold. * If "updown" is TRUE: move to fold at the same level. --- 860,866 ---- redraw_win_later(win, NOT_VALID); } ! // foldMoveTo() {{{2 /* * If "updown" is FALSE: Move to the start or end of the fold. * If "updown" is TRUE: move to fold at the same level. *************** *** 870,876 **** int foldMoveTo( int updown, ! int dir, /* FORWARD or BACKWARD */ long count) { long n; --- 869,875 ---- int foldMoveTo( int updown, ! int dir, // FORWARD or BACKWARD long count) { long n; *************** *** 887,897 **** checkupdate(curwin); ! /* Repeat "count" times. */ for (n = 0; n < count; ++n) { ! /* Find nested folds. Stop when a fold is closed. The deepest fold ! * that moves the cursor is used. */ lnum_off = 0; gap = &curwin->w_folds; use_level = FALSE; --- 886,896 ---- checkupdate(curwin); ! // Repeat "count" times. for (n = 0; n < count; ++n) { ! // Find nested folds. Stop when a fold is closed. The deepest fold ! // that moves the cursor is used. lnum_off = 0; gap = &curwin->w_folds; use_level = FALSE; *************** *** 906,913 **** if (!updown) break; ! /* When moving up, consider a fold above the cursor; when ! * moving down consider a fold below the cursor. */ if (dir == FORWARD) { if (fp - (fold_T *)gap->ga_data >= gap->ga_len) --- 905,912 ---- if (!updown) break; ! // When moving up, consider a fold above the cursor; when ! // moving down consider a fold below the cursor. if (dir == FORWARD) { if (fp - (fold_T *)gap->ga_data >= gap->ga_len) *************** *** 919,937 **** if (fp == (fold_T *)gap->ga_data) break; } ! /* don't look for contained folds, they will always move ! * the cursor too far. */ last = TRUE; } if (!last) { ! /* Check if this fold is closed. */ if (check_closed(curwin, fp, &use_level, level, &maybe_small, lnum_off)) last = TRUE; ! /* "[z" and "]z" stop at closed fold */ if (last && !updown) break; } --- 918,936 ---- if (fp == (fold_T *)gap->ga_data) break; } ! // don't look for contained folds, they will always move ! // the cursor too far. last = TRUE; } if (!last) { ! // Check if this fold is closed. if (check_closed(curwin, fp, &use_level, level, &maybe_small, lnum_off)) last = TRUE; ! // "[z" and "]z" stop at closed fold if (last && !updown) break; } *************** *** 940,946 **** { if (dir == FORWARD) { ! /* to start of next fold if there is one */ if (fp + 1 - (fold_T *)gap->ga_data < gap->ga_len) { lnum = fp[1].fd_top + lnum_off; --- 939,945 ---- { if (dir == FORWARD) { ! // to start of next fold if there is one if (fp + 1 - (fold_T *)gap->ga_data < gap->ga_len) { lnum = fp[1].fd_top + lnum_off; *************** *** 950,956 **** } else { ! /* to end of previous fold if there is one */ if (fp > (fold_T *)gap->ga_data) { lnum = fp[-1].fd_top + lnum_off + fp[-1].fd_len - 1; --- 949,955 ---- } else { ! // to end of previous fold if there is one if (fp > (fold_T *)gap->ga_data) { lnum = fp[-1].fd_top + lnum_off + fp[-1].fd_len - 1; *************** *** 961,968 **** } else { ! /* Open fold found, set cursor to its start/end and then check ! * nested folds. */ if (dir == FORWARD) { lnum = fp->fd_top + lnum_off + fp->fd_len - 1; --- 960,967 ---- } else { ! // Open fold found, set cursor to its start/end and then check ! // nested folds. if (dir == FORWARD) { lnum = fp->fd_top + lnum_off + fp->fd_len - 1; *************** *** 980,986 **** if (last) break; ! /* Check nested folds (if any). */ gap = &fp->fd_nested; lnum_off += fp->fd_top; ++level; --- 979,985 ---- if (last) break; ! // Check nested folds (if any). gap = &fp->fd_nested; lnum_off += fp->fd_top; ++level; *************** *** 1000,1006 **** return retval; } ! /* foldInitWin() {{{2 */ /* * Init the fold info in a new window. */ --- 999,1005 ---- return retval; } ! // foldInitWin() {{{2 /* * Init the fold info in a new window. */ *************** *** 1010,1016 **** ga_init2(&new_win->w_folds, (int)sizeof(fold_T), 10); } ! /* find_wl_entry() {{{2 */ /* * Find an entry in the win->w_lines[] array for buffer line "lnum". * Only valid entries are considered (for entries where wl_valid is FALSE the --- 1009,1015 ---- ga_init2(&new_win->w_folds, (int)sizeof(fold_T), 10); } ! // find_wl_entry() {{{2 /* * Find an entry in the win->w_lines[] array for buffer line "lnum". * Only valid entries are considered (for entries where wl_valid is FALSE the *************** *** 1033,1039 **** return -1; } ! /* foldAdjustVisual() {{{2 */ /* * Adjust the Visual area to include any fold at the start or end completely. */ --- 1032,1038 ---- return -1; } ! // foldAdjustVisual() {{{2 /* * Adjust the Visual area to include any fold at the start or end completely. */ *************** *** 1064,1076 **** end->col = (colnr_T)STRLEN(ptr); if (end->col > 0 && *p_sel == 'o') --end->col; ! /* prevent cursor from moving on the trail byte */ if (has_mbyte) mb_adjust_cursor(); } } ! /* cursor_foldstart() {{{2 */ /* * Move the cursor to the first line of a closed fold. */ --- 1063,1075 ---- end->col = (colnr_T)STRLEN(ptr); if (end->col > 0 && *p_sel == 'o') --end->col; ! // prevent cursor from moving on the trail byte if (has_mbyte) mb_adjust_cursor(); } } ! // cursor_foldstart() {{{2 /* * Move the cursor to the first line of a closed fold. */ *************** *** 1080,1087 **** (void)hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL); } ! /* Internal functions for "fold_T" {{{1 */ ! /* cloneFoldGrowArray() {{{2 */ /* * Will "clone" (i.e deep copy) a garray_T of folds. * --- 1079,1086 ---- (void)hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL); } ! // Internal functions for "fold_T" {{{1 ! // cloneFoldGrowArray() {{{2 /* * Will "clone" (i.e deep copy) a garray_T of folds. * *************** *** 1114,1120 **** } } ! /* foldFind() {{{2 */ /* * Search for line "lnum" in folds of growarray "gap". * Set *fpp to the fold struct for the fold that contains "lnum" or --- 1113,1119 ---- } } ! // foldFind() {{{2 /* * Search for line "lnum" in folds of growarray "gap". * Set *fpp to the fold struct for the fold that contains "lnum" or *************** *** 1140,1153 **** { i = (low + high) / 2; if (fp[i].fd_top > lnum) ! /* fold below lnum, adjust high */ high = i - 1; else if (fp[i].fd_top + fp[i].fd_len <= lnum) ! /* fold above lnum, adjust low */ low = i + 1; else { ! /* lnum is inside this fold */ *fpp = fp + i; return TRUE; } --- 1139,1152 ---- { i = (low + high) / 2; if (fp[i].fd_top > lnum) ! // fold below lnum, adjust high high = i - 1; else if (fp[i].fd_top + fp[i].fd_len <= lnum) ! // fold above lnum, adjust low low = i + 1; else { ! // lnum is inside this fold *fpp = fp + i; return TRUE; } *************** *** 1156,1162 **** return FALSE; } ! /* foldLevelWin() {{{2 */ /* * Return fold level at line number "lnum" in window "wp". */ --- 1155,1161 ---- return FALSE; } ! // foldLevelWin() {{{2 /* * Return fold level at line number "lnum" in window "wp". */ *************** *** 1168,1180 **** int level = 0; garray_T *gap; ! /* Recursively search for a fold that contains "lnum". */ gap = &wp->w_folds; for (;;) { if (!foldFind(gap, lnum_rel, &fp)) break; ! /* Check nested folds. Line number is relative to containing fold. */ gap = &fp->fd_nested; lnum_rel -= fp->fd_top; ++level; --- 1167,1179 ---- int level = 0; garray_T *gap; ! // Recursively search for a fold that contains "lnum". gap = &wp->w_folds; for (;;) { if (!foldFind(gap, lnum_rel, &fp)) break; ! // Check nested folds. Line number is relative to containing fold. gap = &fp->fd_nested; lnum_rel -= fp->fd_top; ++level; *************** *** 1183,1189 **** return level; } ! /* checkupdate() {{{2 */ /* * Check if the folds in window "wp" are invalid and update them if needed. */ --- 1182,1188 ---- return level; } ! // checkupdate() {{{2 /* * Check if the folds in window "wp" are invalid and update them if needed. */ *************** *** 1192,1203 **** { if (wp->w_foldinvalid) { ! foldUpdate(wp, (linenr_T)1, (linenr_T)MAXLNUM); /* will update all */ wp->w_foldinvalid = FALSE; } } ! /* setFoldRepeat() {{{2 */ /* * Open or close fold for current window at line "lnum". * Repeat "count" times. --- 1191,1202 ---- { if (wp->w_foldinvalid) { ! foldUpdate(wp, (linenr_T)1, (linenr_T)MAXLNUM); // will update all wp->w_foldinvalid = FALSE; } } ! // setFoldRepeat() {{{2 /* * Open or close fold for current window at line "lnum". * Repeat "count" times. *************** *** 1214,1220 **** (void)setManualFold(lnum, do_open, FALSE, &done); if (!(done & DONE_ACTION)) { ! /* Only give an error message when no fold could be opened. */ if (n == 0 && !(done & DONE_FOLD)) emsg(_(e_nofold)); break; --- 1213,1219 ---- (void)setManualFold(lnum, do_open, FALSE, &done); if (!(done & DONE_ACTION)) { ! // Only give an error message when no fold could be opened. if (n == 0 && !(done & DONE_FOLD)) emsg(_(e_nofold)); break; *************** *** 1222,1228 **** } } ! /* setManualFold() {{{2 */ /* * Open or close the fold in the current window which contains "lnum". * Also does this for other windows in diff mode when needed. --- 1221,1227 ---- } } ! // setManualFold() {{{2 /* * Open or close the fold in the current window which contains "lnum". * Also does this for other windows in diff mode when needed. *************** *** 1230,1237 **** static linenr_T setManualFold( linenr_T lnum, ! int opening, /* TRUE when opening, FALSE when closing */ ! int recurse, /* TRUE when closing/opening recursive */ int *donep) { #ifdef FEAT_DIFF --- 1229,1236 ---- static linenr_T setManualFold( linenr_T lnum, ! int opening, // TRUE when opening, FALSE when closing ! int recurse, // TRUE when closing/opening recursive int *donep) { #ifdef FEAT_DIFF *************** *** 1259,1265 **** return setManualFoldWin(curwin, lnum, opening, recurse, donep); } ! /* setManualFoldWin() {{{2 */ /* * Open or close the fold in window "wp" which contains "lnum". * "donep", when not NULL, points to flag that is set to DONE_FOLD when some --- 1258,1264 ---- return setManualFoldWin(curwin, lnum, opening, recurse, donep); } ! // setManualFoldWin() {{{2 /* * Open or close the fold in window "wp" which contains "lnum". * "donep", when not NULL, points to flag that is set to DONE_FOLD when some *************** *** 1273,1280 **** setManualFoldWin( win_T *wp, linenr_T lnum, ! int opening, /* TRUE when opening, FALSE when closing */ ! int recurse, /* TRUE when closing/opening recursive */ int *donep) { fold_T *fp; --- 1272,1279 ---- setManualFoldWin( win_T *wp, linenr_T lnum, ! int opening, // TRUE when opening, FALSE when closing ! int recurse, // TRUE when closing/opening recursive int *donep) { fold_T *fp; *************** *** 1299,1318 **** { if (!foldFind(gap, lnum, &fp)) { ! /* If there is a following fold, continue there next time. */ if (fp < (fold_T *)gap->ga_data + gap->ga_len) next = fp->fd_top + off; break; } ! /* lnum is inside this fold */ found_fold = TRUE; ! /* If there is a following fold, continue there next time. */ if (fp + 1 < (fold_T *)gap->ga_data + gap->ga_len) next = fp[1].fd_top + off; ! /* Change from level-dependent folding to manual. */ if (use_level || fp->fd_flags == FD_LEVEL) { use_level = TRUE; --- 1298,1317 ---- { if (!foldFind(gap, lnum, &fp)) { ! // If there is a following fold, continue there next time. if (fp < (fold_T *)gap->ga_data + gap->ga_len) next = fp->fd_top + off; break; } ! // lnum is inside this fold found_fold = TRUE; ! // If there is a following fold, continue there next time. if (fp + 1 < (fold_T *)gap->ga_data + gap->ga_len) next = fp[1].fd_top + off; ! // Change from level-dependent folding to manual. if (use_level || fp->fd_flags == FD_LEVEL) { use_level = TRUE; *************** *** 1325,1331 **** fp2[j].fd_flags = FD_LEVEL; } ! /* Simple case: Close recursively means closing the fold. */ if (!opening && recurse) { if (fp->fd_flags != FD_CLOSED) --- 1324,1330 ---- fp2[j].fd_flags = FD_LEVEL; } ! // Simple case: Close recursively means closing the fold. if (!opening && recurse) { if (fp->fd_flags != FD_CLOSED) *************** *** 1336,1342 **** } else if (fp->fd_flags == FD_CLOSED) { ! /* When opening, open topmost closed fold. */ if (opening) { fp->fd_flags = FD_OPEN; --- 1335,1341 ---- } else if (fp->fd_flags == FD_CLOSED) { ! // When opening, open topmost closed fold. if (opening) { fp->fd_flags = FD_OPEN; *************** *** 1347,1353 **** break; } ! /* fold is open, check nested folds */ found = fp; gap = &fp->fd_nested; lnum -= fp->fd_top; --- 1346,1352 ---- break; } ! // fold is open, check nested folds found = fp; gap = &fp->fd_nested; lnum -= fp->fd_top; *************** *** 1356,1362 **** } if (found_fold) { ! /* When closing and not recurse, close deepest open fold. */ if (!opening && found != NULL) { found->fd_flags = FD_CLOSED; --- 1355,1361 ---- } if (found_fold) { ! // When closing and not recurse, close deepest open fold. if (!opening && found != NULL) { found->fd_flags = FD_CLOSED; *************** *** 1376,1382 **** return next; } ! /* foldOpenNested() {{{2 */ /* * Open all nested folds in fold "fpr" recursively. */ --- 1375,1381 ---- return next; } ! // foldOpenNested() {{{2 /* * Open all nested folds in fold "fpr" recursively. */ *************** *** 1394,1400 **** } } ! /* deleteFoldEntry() {{{2 */ /* * Delete fold "idx" from growarray "gap". * When "recursive" is TRUE also delete all the folds contained in it. --- 1393,1399 ---- } } ! // deleteFoldEntry() {{{2 /* * Delete fold "idx" from growarray "gap". * When "recursive" is TRUE also delete all the folds contained in it. *************** *** 1411,1417 **** fp = (fold_T *)gap->ga_data + idx; if (recursive || fp->fd_nested.ga_len == 0) { ! /* recursively delete the contained folds */ deleteFoldRecurse(&fp->fd_nested); --gap->ga_len; if (idx < gap->ga_len) --- 1410,1416 ---- fp = (fold_T *)gap->ga_data + idx; if (recursive || fp->fd_nested.ga_len == 0) { ! // recursively delete the contained folds deleteFoldRecurse(&fp->fd_nested); --gap->ga_len; if (idx < gap->ga_len) *************** *** 1419,1433 **** } else { ! /* Move nested folds one level up, to overwrite the fold that is ! * deleted. */ moved = fp->fd_nested.ga_len; if (ga_grow(gap, (int)(moved - 1)) == OK) { ! /* Get "fp" again, the array may have been reallocated. */ fp = (fold_T *)gap->ga_data + idx; ! /* adjust fd_top and fd_flags for the moved folds */ nfp = (fold_T *)fp->fd_nested.ga_data; for (i = 0; i < moved; ++i) { --- 1418,1432 ---- } else { ! // Move nested folds one level up, to overwrite the fold that is ! // deleted. moved = fp->fd_nested.ga_len; if (ga_grow(gap, (int)(moved - 1)) == OK) { ! // Get "fp" again, the array may have been reallocated. fp = (fold_T *)gap->ga_data + idx; ! // adjust fd_top and fd_flags for the moved folds nfp = (fold_T *)fp->fd_nested.ga_data; for (i = 0; i < moved; ++i) { *************** *** 1438,1448 **** nfp[i].fd_small = MAYBE; } ! /* move the existing folds down to make room */ if (idx + 1 < gap->ga_len) mch_memmove(fp + moved, fp + 1, sizeof(fold_T) * (gap->ga_len - (idx + 1))); ! /* move the contained folds one level up */ mch_memmove(fp, nfp, (size_t)(sizeof(fold_T) * moved)); vim_free(nfp); gap->ga_len += moved - 1; --- 1437,1447 ---- nfp[i].fd_small = MAYBE; } ! // move the existing folds down to make room if (idx + 1 < gap->ga_len) mch_memmove(fp + moved, fp + 1, sizeof(fold_T) * (gap->ga_len - (idx + 1))); ! // move the contained folds one level up mch_memmove(fp, nfp, (size_t)(sizeof(fold_T) * moved)); vim_free(nfp); gap->ga_len += moved - 1; *************** *** 1450,1456 **** } } ! /* deleteFoldRecurse() {{{2 */ /* * Delete nested folds in a fold. */ --- 1449,1455 ---- } } ! // deleteFoldRecurse() {{{2 /* * Delete nested folds in a fold. */ *************** *** 1464,1470 **** ga_clear(gap); } ! /* foldMarkAdjust() {{{2 */ /* * Update line numbers of folds for inserted/deleted lines. */ --- 1463,1469 ---- ga_clear(gap); } ! // foldMarkAdjust() {{{2 /* * Update line numbers of folds for inserted/deleted lines. */ *************** *** 1476,1493 **** long amount, long amount_after) { ! /* If deleting marks from line1 to line2, but not deleting all those ! * lines, set line2 so that only deleted lines have their folds removed. */ if (amount == MAXLNUM && line2 >= line1 && line2 - line1 >= -amount_after) line2 = line1 - amount_after - 1; ! /* If appending a line in Insert mode, it should be included in the fold ! * just above the line. */ if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) --line1; foldMarkAdjustRecurse(&wp->w_folds, line1, line2, amount, amount_after); } ! /* foldMarkAdjustRecurse() {{{2 */ static void foldMarkAdjustRecurse( garray_T *gap, --- 1475,1492 ---- long amount, long amount_after) { ! // If deleting marks from line1 to line2, but not deleting all those ! // lines, set line2 so that only deleted lines have their folds removed. if (amount == MAXLNUM && line2 >= line1 && line2 - line1 >= -amount_after) line2 = line1 - amount_after - 1; ! // If appending a line in Insert mode, it should be included in the fold ! // just above the line. if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) --line1; foldMarkAdjustRecurse(&wp->w_folds, line1, line2, amount, amount_after); } ! // foldMarkAdjustRecurse() {{{2 static void foldMarkAdjustRecurse( garray_T *gap, *************** *** 1501,1514 **** linenr_T last; linenr_T top; ! /* In Insert mode an inserted line at the top of a fold is considered part ! * of the fold, otherwise it isn't. */ if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) top = line1 + 1; else top = line1; ! /* Find the fold containing or just below "line1". */ (void)foldFind(gap, line1, &fp); /* --- 1500,1513 ---- linenr_T last; linenr_T top; ! // In Insert mode an inserted line at the top of a fold is considered part ! // of the fold, otherwise it isn't. if ((State & INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) top = line1 + 1; else top = line1; ! // Find the fold containing or just below "line1". (void)foldFind(gap, line1, &fp); /* *************** *** 1528,1540 **** * 3 5 6 */ ! last = fp->fd_top + fp->fd_len - 1; /* last line of fold */ ! /* 1. fold completely above line1: nothing to do */ if (last < line1) continue; ! /* 6. fold below line2: only adjust for amount_after */ if (fp->fd_top > line2) { if (amount_after == 0) --- 1527,1539 ---- * 3 5 6 */ ! last = fp->fd_top + fp->fd_len - 1; // last line of fold ! // 1. fold completely above line1: nothing to do if (last < line1) continue; ! // 6. fold below line2: only adjust for amount_after if (fp->fd_top > line2) { if (amount_after == 0) *************** *** 1545,1556 **** { if (fp->fd_top >= top && last <= line2) { ! /* 4. fold completely contained in range */ if (amount == MAXLNUM) { ! /* Deleting lines: delete the fold completely */ deleteFoldEntry(gap, i, TRUE); ! --i; /* adjust index for deletion */ --fp; } else --- 1544,1555 ---- { if (fp->fd_top >= top && last <= line2) { ! // 4. fold completely contained in range if (amount == MAXLNUM) { ! // Deleting lines: delete the fold completely deleteFoldEntry(gap, i, TRUE); ! --i; // adjust index for deletion --fp; } else *************** *** 1560,1571 **** { if (fp->fd_top < top) { ! /* 2 or 3: need to correct nested folds too */ foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top, line2 - fp->fd_top, amount, amount_after); if (last <= line2) { ! /* 2. fold contains line1, line2 is below fold */ if (amount == MAXLNUM) fp->fd_len = line1 - fp->fd_top; else --- 1559,1570 ---- { if (fp->fd_top < top) { ! // 2 or 3: need to correct nested folds too foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top, line2 - fp->fd_top, amount, amount_after); if (last <= line2) { ! // 2. fold contains line1, line2 is below fold if (amount == MAXLNUM) fp->fd_len = line1 - fp->fd_top; else *************** *** 1573,1586 **** } else { ! /* 3. fold contains line1 and line2 */ fp->fd_len += amount_after; } } else { ! /* 5. fold is below line1 and contains line2; need to ! * correct nested folds too */ if (amount == MAXLNUM) { foldMarkAdjustRecurse(&fp->fd_nested, --- 1572,1585 ---- } else { ! // 3. fold contains line1 and line2 fp->fd_len += amount_after; } } else { ! // 5. fold is below line1 and contains line2; need to ! // correct nested folds too if (amount == MAXLNUM) { foldMarkAdjustRecurse(&fp->fd_nested, *************** *** 1607,1613 **** } } ! /* getDeepestNesting() {{{2 */ /* * Get the lowest 'foldlevel' value that makes the deepest nested fold in the * current window open. --- 1606,1612 ---- } } ! // getDeepestNesting() {{{2 /* * Get the lowest 'foldlevel' value that makes the deepest nested fold in the * current window open. *************** *** 1638,1644 **** return maxlevel; } ! /* check_closed() {{{2 */ /* * Check if a fold is closed and update the info needed to check nested folds. */ --- 1637,1643 ---- return maxlevel; } ! // check_closed() {{{2 /* * Check if a fold is closed and update the info needed to check nested folds. */ *************** *** 1646,1660 **** check_closed( win_T *win, fold_T *fp, ! int *use_levelp, /* TRUE: outer fold had FD_LEVEL */ ! int level, /* folding depth */ ! int *maybe_smallp, /* TRUE: outer this had fd_small == MAYBE */ ! linenr_T lnum_off) /* line number offset for fp->fd_top */ { int closed = FALSE; ! /* Check if this fold is closed. If the flag is FD_LEVEL this ! * fold and all folds it contains depend on 'foldlevel'. */ if (*use_levelp || fp->fd_flags == FD_LEVEL) { *use_levelp = TRUE; --- 1645,1659 ---- check_closed( win_T *win, fold_T *fp, ! int *use_levelp, // TRUE: outer fold had FD_LEVEL ! int level, // folding depth ! int *maybe_smallp, // TRUE: outer this had fd_small == MAYBE ! linenr_T lnum_off) // line number offset for fp->fd_top { int closed = FALSE; ! // Check if this fold is closed. If the flag is FD_LEVEL this ! // fold and all folds it contains depend on 'foldlevel'. if (*use_levelp || fp->fd_flags == FD_LEVEL) { *use_levelp = TRUE; *************** *** 1664,1670 **** else if (fp->fd_flags == FD_CLOSED) closed = TRUE; ! /* Small fold isn't closed anyway. */ if (fp->fd_small == MAYBE) *maybe_smallp = TRUE; if (closed) --- 1663,1669 ---- else if (fp->fd_flags == FD_CLOSED) closed = TRUE; ! // Small fold isn't closed anyway. if (fp->fd_small == MAYBE) *maybe_smallp = TRUE; if (closed) *************** *** 1678,1684 **** return closed; } ! /* checkSmall() {{{2 */ /* * Update fd_small field of fold "fp". */ --- 1677,1683 ---- return closed; } ! // checkSmall() {{{2 /* * Update fd_small field of fold "fp". */ *************** *** 1686,1699 **** checkSmall( win_T *wp, fold_T *fp, ! linenr_T lnum_off) /* offset for fp->fd_top */ { int count; int n; if (fp->fd_small == MAYBE) { ! /* Mark any nested folds to maybe-small */ setSmallMaybe(&fp->fd_nested); if (fp->fd_len > curwin->w_p_fml) --- 1685,1698 ---- checkSmall( win_T *wp, fold_T *fp, ! linenr_T lnum_off) // offset for fp->fd_top { int count; int n; if (fp->fd_small == MAYBE) { ! // Mark any nested folds to maybe-small setSmallMaybe(&fp->fd_nested); if (fp->fd_len > curwin->w_p_fml) *************** *** 1715,1721 **** } } ! /* setSmallMaybe() {{{2 */ /* * Set small flags in "gap" to MAYBE. */ --- 1714,1720 ---- } } ! // setSmallMaybe() {{{2 /* * Set small flags in "gap" to MAYBE. */ *************** *** 1730,1736 **** fp[i].fd_small = MAYBE; } ! /* foldCreateMarkers() {{{2 */ /* * Create a fold from line "start" to line "end" (inclusive) in the current * window by adding markers. --- 1729,1735 ---- fp[i].fd_small = MAYBE; } ! // foldCreateMarkers() {{{2 /* * Create a fold from line "start" to line "end" (inclusive) in the current * window by adding markers. *************** *** 1748,1759 **** foldAddMarker(start, curwin->w_p_fmr, foldstartmarkerlen); foldAddMarker(end, foldendmarker, foldendmarkerlen); ! /* Update both changes here, to avoid all folds after the start are ! * changed when the start marker is inserted and the end isn't. */ changed_lines(start, (colnr_T)0, end, 0L); } ! /* foldAddMarker() {{{2 */ /* * Add "marker[markerlen]" in 'commentstring' to line "lnum". */ --- 1747,1758 ---- foldAddMarker(start, curwin->w_p_fmr, foldstartmarkerlen); foldAddMarker(end, foldendmarker, foldendmarkerlen); ! // Update both changes here, to avoid all folds after the start are ! // changed when the start marker is inserted and the end isn't. changed_lines(start, (colnr_T)0, end, 0L); } ! // foldAddMarker() {{{2 /* * Add "marker[markerlen]" in 'commentstring' to line "lnum". */ *************** *** 1767,1785 **** char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s"); int line_is_comment = FALSE; ! /* Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end */ line = ml_get(lnum); line_len = (int)STRLEN(line); if (u_save(lnum - 1, lnum + 1) == OK) { ! /* Check if the line ends with an unclosed comment */ (void)skip_comment(line, FALSE, FALSE, &line_is_comment); newline = alloc(line_len + markerlen + STRLEN(cms) + 1); if (newline == NULL) return; STRCPY(newline, line); ! /* Append the marker to the end of the line */ if (p == NULL || line_is_comment) vim_strncpy(newline + line_len, marker, markerlen); else --- 1766,1784 ---- char_u *p = (char_u *)strstr((char *)curbuf->b_p_cms, "%s"); int line_is_comment = FALSE; ! // Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end line = ml_get(lnum); line_len = (int)STRLEN(line); if (u_save(lnum - 1, lnum + 1) == OK) { ! // Check if the line ends with an unclosed comment (void)skip_comment(line, FALSE, FALSE, &line_is_comment); newline = alloc(line_len + markerlen + STRLEN(cms) + 1); if (newline == NULL) return; STRCPY(newline, line); ! // Append the marker to the end of the line if (p == NULL || line_is_comment) vim_strncpy(newline + line_len, marker, markerlen); else *************** *** 1793,1799 **** } } ! /* deleteFoldMarkers() {{{2 */ /* * Delete the markers for a fold, causing it to be deleted. */ --- 1792,1798 ---- } } ! // deleteFoldMarkers() {{{2 /* * Delete the markers for a fold, causing it to be deleted. */ *************** *** 1801,1807 **** deleteFoldMarkers( fold_T *fp, int recursive, ! linenr_T lnum_off) /* offset for fp->fd_top */ { int i; --- 1800,1806 ---- deleteFoldMarkers( fold_T *fp, int recursive, ! linenr_T lnum_off) // offset for fp->fd_top { int i; *************** *** 1814,1820 **** foldendmarker, foldendmarkerlen); } ! /* foldDelMarker() {{{2 */ /* * Delete marker "marker[markerlen]" at the end of line "lnum". * Delete 'commentstring' if it matches. --- 1813,1819 ---- foldendmarker, foldendmarkerlen); } ! // foldDelMarker() {{{2 /* * Delete marker "marker[markerlen]" at the end of line "lnum". * Delete 'commentstring' if it matches. *************** *** 1838,1850 **** for (p = line; *p != NUL; ++p) if (STRNCMP(p, marker, markerlen) == 0) { ! /* Found the marker, include a digit if it's there. */ len = markerlen; if (VIM_ISDIGIT(p[len])) ++len; if (*cms != NUL) { ! /* Also delete 'commentstring' if it matches. */ cms2 = (char_u *)strstr((char *)cms, "%s"); if (p - line >= cms2 - cms && STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0 --- 1837,1849 ---- for (p = line; *p != NUL; ++p) if (STRNCMP(p, marker, markerlen) == 0) { ! // Found the marker, include a digit if it's there. len = markerlen; if (VIM_ISDIGIT(p[len])) ++len; if (*cms != NUL) { ! // Also delete 'commentstring' if it matches. cms2 = (char_u *)strstr((char *)cms, "%s"); if (p - line >= cms2 - cms && STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0 *************** *** 1856,1862 **** } if (u_save(lnum - 1, lnum + 1) == OK) { ! /* Make new line: text-before-marker + text-after-marker */ newline = alloc(STRLEN(line) - len + 1); if (newline != NULL) { --- 1855,1861 ---- } if (u_save(lnum - 1, lnum + 1) == OK) { ! // Make new line: text-before-marker + text-after-marker newline = alloc(STRLEN(line) - len + 1); if (newline != NULL) { *************** *** 1869,1875 **** } } ! /* get_foldtext() {{{2 */ /* * Return the text for a closed fold at line "lnum", with last line "lnume". * When 'foldtext' isn't set puts the result in "buf[FOLD_TEXT_LEN]". --- 1868,1874 ---- } } ! // get_foldtext() {{{2 /* * Return the text for a closed fold at line "lnum", with last line "lnume". * When 'foldtext' isn't set puts the result in "buf[FOLD_TEXT_LEN]". *************** *** 1885,1891 **** { char_u *text = NULL; #ifdef FEAT_EVAL ! /* an error occurred when evaluating 'fdt' setting */ static int got_fdt_error = FALSE; int save_did_emsg = did_emsg; static win_T *last_wp = NULL; --- 1884,1890 ---- { char_u *text = NULL; #ifdef FEAT_EVAL ! // an error occurred when evaluating 'fdt' setting static int got_fdt_error = FALSE; int save_did_emsg = did_emsg; static win_T *last_wp = NULL; *************** *** 1893,1903 **** if (last_wp != wp || last_wp == NULL || last_lnum > lnum || last_lnum == 0) ! /* window changed, try evaluating foldtext setting once again */ got_fdt_error = FALSE; if (!got_fdt_error) ! /* a previous error should not abort evaluating 'foldexpr' */ did_emsg = FALSE; if (*wp->w_p_fdt != NUL) --- 1892,1902 ---- if (last_wp != wp || last_wp == NULL || last_lnum > lnum || last_lnum == 0) ! // window changed, try evaluating foldtext setting once again got_fdt_error = FALSE; if (!got_fdt_error) ! // a previous error should not abort evaluating 'foldexpr' did_emsg = FALSE; if (*wp->w_p_fdt != NUL) *************** *** 1907,1918 **** int level; char_u *p; ! /* Set "v:foldstart" and "v:foldend". */ set_vim_var_nr(VV_FOLDSTART, lnum); set_vim_var_nr(VV_FOLDEND, lnume); ! /* Set "v:folddashes" to a string of "level" dashes. */ ! /* Set "v:foldlevel" to "level". */ level = foldinfo->fi_level; if (level > (int)sizeof(dashes) - 1) level = (int)sizeof(dashes) - 1; --- 1906,1917 ---- int level; char_u *p; ! // Set "v:foldstart" and "v:foldend". set_vim_var_nr(VV_FOLDSTART, lnum); set_vim_var_nr(VV_FOLDEND, lnume); ! // Set "v:folddashes" to a string of "level" dashes. ! // Set "v:foldlevel" to "level". level = foldinfo->fi_level; if (level > (int)sizeof(dashes) - 1) level = (int)sizeof(dashes) - 1; *************** *** 1921,1934 **** set_vim_var_string(VV_FOLDDASHES, dashes, -1); set_vim_var_nr(VV_FOLDLEVEL, (long)level); ! /* skip evaluating foldtext on errors */ if (!got_fdt_error) { save_curwin = curwin; curwin = wp; curbuf = wp->w_buffer; ! ++emsg_silent; /* handle exceptions, but don't display errors */ text = eval_to_string_safe(wp->w_p_fdt, NULL, was_set_insecurely((char_u *)"foldtext", OPT_LOCAL)); --emsg_silent; --- 1920,1933 ---- set_vim_var_string(VV_FOLDDASHES, dashes, -1); set_vim_var_nr(VV_FOLDLEVEL, (long)level); ! // skip evaluating foldtext on errors if (!got_fdt_error) { save_curwin = curwin; curwin = wp; curbuf = wp->w_buffer; ! ++emsg_silent; // handle exceptions, but don't display errors text = eval_to_string_safe(wp->w_p_fdt, NULL, was_set_insecurely((char_u *)"foldtext", OPT_LOCAL)); --emsg_silent; *************** *** 1948,1955 **** if (text != NULL) { ! /* Replace unprintable characters, if there are any. But ! * replace a TAB with a space. */ for (p = text; *p != NUL; ++p) { int len; --- 1947,1954 ---- if (text != NULL) { ! // Replace unprintable characters, if there are any. But ! // replace a TAB with a space. for (p = text; *p != NUL; ++p) { int len; *************** *** 1988,1994 **** return text; } ! /* foldtext_cleanup() {{{2 */ #ifdef FEAT_EVAL /* * Remove 'foldmarker' and 'commentstring' from "str" (in-place). --- 1987,1993 ---- return text; } ! // foldtext_cleanup() {{{2 #ifdef FEAT_EVAL /* * Remove 'foldmarker' and 'commentstring' from "str" (in-place). *************** *** 1996,2029 **** static void foldtext_cleanup(char_u *str) { ! char_u *cms_start; /* first part or the whole comment */ ! int cms_slen = 0; /* length of cms_start */ ! char_u *cms_end; /* last part of the comment or NULL */ ! int cms_elen = 0; /* length of cms_end */ char_u *s; char_u *p; int len; int did1 = FALSE; int did2 = FALSE; ! /* Ignore leading and trailing white space in 'commentstring'. */ cms_start = skipwhite(curbuf->b_p_cms); cms_slen = (int)STRLEN(cms_start); while (cms_slen > 0 && VIM_ISWHITE(cms_start[cms_slen - 1])) --cms_slen; ! /* locate "%s" in 'commentstring', use the part before and after it. */ cms_end = (char_u *)strstr((char *)cms_start, "%s"); if (cms_end != NULL) { cms_elen = cms_slen - (int)(cms_end - cms_start); cms_slen = (int)(cms_end - cms_start); ! /* exclude white space before "%s" */ while (cms_slen > 0 && VIM_ISWHITE(cms_start[cms_slen - 1])) --cms_slen; ! /* skip "%s" and white space after it */ s = skipwhite(cms_end + 2); cms_elen -= (int)(s - cms_end); cms_end = s; --- 1995,2028 ---- static void foldtext_cleanup(char_u *str) { ! char_u *cms_start; // first part or the whole comment ! int cms_slen = 0; // length of cms_start ! char_u *cms_end; // last part of the comment or NULL ! int cms_elen = 0; // length of cms_end char_u *s; char_u *p; int len; int did1 = FALSE; int did2 = FALSE; ! // Ignore leading and trailing white space in 'commentstring'. cms_start = skipwhite(curbuf->b_p_cms); cms_slen = (int)STRLEN(cms_start); while (cms_slen > 0 && VIM_ISWHITE(cms_start[cms_slen - 1])) --cms_slen; ! // locate "%s" in 'commentstring', use the part before and after it. cms_end = (char_u *)strstr((char *)cms_start, "%s"); if (cms_end != NULL) { cms_elen = cms_slen - (int)(cms_end - cms_start); cms_slen = (int)(cms_end - cms_start); ! // exclude white space before "%s" while (cms_slen > 0 && VIM_ISWHITE(cms_start[cms_slen - 1])) --cms_slen; ! // skip "%s" and white space after it s = skipwhite(cms_end + 2); cms_elen -= (int)(s - cms_end); cms_end = s; *************** *** 2042,2049 **** if (VIM_ISDIGIT(s[len])) ++len; ! /* May remove 'commentstring' start. Useful when it's a double ! * quote and we already removed a double quote. */ for (p = s; p > str && VIM_ISWHITE(p[-1]); --p) ; if (p >= str + cms_slen --- 2041,2048 ---- if (VIM_ISDIGIT(s[len])) ++len; ! // May remove 'commentstring' start. Useful when it's a double ! // quote and we already removed a double quote. for (p = s; p > str && VIM_ISWHITE(p[-1]); --p) ; if (p >= str + cms_slen *************** *** 2081,2108 **** } #endif ! /* Folding by indent, expr, marker and syntax. {{{1 */ ! /* Define "fline_T", passed to get fold level for a line. {{{2 */ typedef struct { ! win_T *wp; /* window */ ! linenr_T lnum; /* current line number */ ! linenr_T off; /* offset between lnum and real line number */ ! linenr_T lnum_save; /* line nr used by foldUpdateIEMSRecurse() */ ! int lvl; /* current level (-1 for undefined) */ ! int lvl_next; /* level used for next line */ ! int start; /* number of folds that are forced to start at ! this line. */ ! int end; /* level of fold that is forced to end below ! this line */ ! int had_end; /* level of fold that is forced to end above ! this line (copy of "end" of prev. line) */ } fline_T; ! /* Flag is set when redrawing is needed. */ static int fold_changed; ! /* Function declarations. {{{2 */ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level, linenr_T startlnum, fline_T *flp, void (*getlevel)(fline_T *), linenr_T bot, int topflags); static int foldInsert(garray_T *gap, int i); static void foldSplit(garray_T *gap, int i, linenr_T top, linenr_T bot); --- 2080,2107 ---- } #endif ! // Folding by indent, expr, marker and syntax. {{{1 ! // Define "fline_T", passed to get fold level for a line. {{{2 typedef struct { ! win_T *wp; // window ! linenr_T lnum; // current line number ! linenr_T off; // offset between lnum and real line number ! linenr_T lnum_save; // line nr used by foldUpdateIEMSRecurse() ! int lvl; // current level (-1 for undefined) ! int lvl_next; // level used for next line ! int start; // number of folds that are forced to start at ! // this line. ! int end; // level of fold that is forced to end below ! // this line ! int had_end; // level of fold that is forced to end above ! // this line (copy of "end" of prev. line) } fline_T; ! // Flag is set when redrawing is needed. static int fold_changed; ! // Function declarations. {{{2 static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level, linenr_T startlnum, fline_T *flp, void (*getlevel)(fline_T *), linenr_T bot, int topflags); static int foldInsert(garray_T *gap, int i); static void foldSplit(garray_T *gap, int i, linenr_T top, linenr_T bot); *************** *** 2116,2122 **** static void foldlevelMarker(fline_T *flp); static void foldlevelSyntax(fline_T *flp); ! /* foldUpdateIEMS() {{{2 */ /* * Update the folding for window "wp", at least from lines "top" to "bot". * Return TRUE if any folds did change. --- 2115,2121 ---- static void foldlevelMarker(fline_T *flp); static void foldlevelSyntax(fline_T *flp); ! // foldUpdateIEMS() {{{2 /* * Update the folding for window "wp", at least from lines "top" to "bot". * Return TRUE if any folds did change. *************** *** 2131,2153 **** int level; fold_T *fp; ! /* Avoid problems when being called recursively. */ if (invalid_top != (linenr_T)0) return; if (wp->w_foldinvalid) { ! /* Need to update all folds. */ top = 1; bot = wp->w_buffer->b_ml.ml_line_count; wp->w_foldinvalid = FALSE; ! /* Mark all folds a maybe-small. */ setSmallMaybe(&wp->w_folds); } #ifdef FEAT_DIFF ! /* add the context for "diff" folding */ if (foldmethodIsDiff(wp)) { if (top > diff_context) --- 2130,2152 ---- int level; fold_T *fp; ! // Avoid problems when being called recursively. if (invalid_top != (linenr_T)0) return; if (wp->w_foldinvalid) { ! // Need to update all folds. top = 1; bot = wp->w_buffer->b_ml.ml_line_count; wp->w_foldinvalid = FALSE; ! // Mark all folds a maybe-small. setSmallMaybe(&wp->w_folds); } #ifdef FEAT_DIFF ! // add the context for "diff" folding if (foldmethodIsDiff(wp)) { if (top > diff_context) *************** *** 2158,2165 **** } #endif ! /* When deleting lines at the end of the buffer "top" can be past the end ! * of the buffer. */ if (top > wp->w_buffer->b_ml.ml_line_count) top = wp->w_buffer->b_ml.ml_line_count; --- 2157,2164 ---- } #endif ! // When deleting lines at the end of the buffer "top" can be past the end ! // of the buffer. if (top > wp->w_buffer->b_ml.ml_line_count) top = wp->w_buffer->b_ml.ml_line_count; *************** *** 2179,2202 **** { getlevel = foldlevelMarker; ! /* Init marker variables to speed up foldlevelMarker(). */ parseMarker(wp); ! /* Need to get the level of the line above top, it is used if there is ! * no marker at the top. */ if (top > 1) { ! /* Get the fold level at top - 1. */ level = foldLevelWin(wp, top - 1); ! /* The fold may end just above the top, check for that. */ fline.lnum = top - 1; fline.lvl = level; getlevel(&fline); ! /* If a fold started here, we already had the level, if it stops ! * here, we need to use lvl_next. Could also start and end a fold ! * in the same line. */ if (fline.lvl > level) fline.lvl = level - (fline.lvl - fline.lvl_next); else --- 2178,2201 ---- { getlevel = foldlevelMarker; ! // Init marker variables to speed up foldlevelMarker(). parseMarker(wp); ! // Need to get the level of the line above top, it is used if there is ! // no marker at the top. if (top > 1) { ! // Get the fold level at top - 1. level = foldLevelWin(wp, top - 1); ! // The fold may end just above the top, check for that. fline.lnum = top - 1; fline.lvl = level; getlevel(&fline); ! // If a fold started here, we already had the level, if it stops ! // here, we need to use lvl_next. Could also start and end a fold ! // in the same line. if (fline.lvl > level) fline.lvl = level - (fline.lvl - fline.lvl_next); else *************** *** 2211,2218 **** if (foldmethodIsExpr(wp)) { getlevel = foldlevelExpr; ! /* start one line back, because a "<1" may indicate the end of a ! * fold in the topline */ if (top > 1) --fline.lnum; } --- 2210,2217 ---- if (foldmethodIsExpr(wp)) { getlevel = foldlevelExpr; ! // start one line back, because a "<1" may indicate the end of a ! // fold in the topline if (top > 1) --fline.lnum; } *************** *** 2225,2237 **** else getlevel = foldlevelIndent; ! /* Backup to a line for which the fold level is defined. Since it's ! * always defined for line one, we will stop there. */ fline.lvl = -1; for ( ; !got_int; --fline.lnum) { ! /* Reset lvl_next each time, because it will be set to a value for ! * the next line, but we search backwards here. */ fline.lvl_next = -1; getlevel(&fline); if (fline.lvl >= 0) --- 2224,2236 ---- else getlevel = foldlevelIndent; ! // Backup to a line for which the fold level is defined. Since it's ! // always defined for line one, we will stop there. fline.lvl = -1; for ( ; !got_int; --fline.lnum) { ! // Reset lvl_next each time, because it will be set to a value for ! // the next line, but we search backwards here. fline.lvl_next = -1; getlevel(&fline); if (fline.lvl >= 0) *************** *** 2275,2294 **** start = fline.lnum; end = bot; ! /* Do at least one line. */ if (start > end && end < wp->w_buffer->b_ml.ml_line_count) end = start; while (!got_int) { ! /* Always stop at the end of the file ("end" can be past the end of ! * the file). */ if (fline.lnum > wp->w_buffer->b_ml.ml_line_count) break; if (fline.lnum > end) { ! /* For "marker", "expr" and "syntax" methods: If a change caused ! * a fold to be removed, we need to continue at least until where ! * it ended. */ if (getlevel != foldlevelMarker && getlevel != foldlevelSyntax && getlevel != foldlevelExpr) --- 2274,2293 ---- start = fline.lnum; end = bot; ! // Do at least one line. if (start > end && end < wp->w_buffer->b_ml.ml_line_count) end = start; while (!got_int) { ! // Always stop at the end of the file ("end" can be past the end of ! // the file). if (fline.lnum > wp->w_buffer->b_ml.ml_line_count) break; if (fline.lnum > end) { ! // For "marker", "expr" and "syntax" methods: If a change caused ! // a fold to be removed, we need to continue at least until where ! // it ended. if (getlevel != foldlevelMarker && getlevel != foldlevelSyntax && getlevel != foldlevelExpr) *************** *** 2302,2316 **** end = fp->fd_top + fp->fd_len - 1; else if (getlevel == foldlevelSyntax && foldLevelWin(wp, fline.lnum) != fline.lvl) ! /* For "syntax" method: Compare the foldlevel that the syntax ! * tells us to the foldlevel from the existing folds. If they ! * don't match continue updating folds. */ end = fline.lnum; else break; } ! /* A level 1 fold starts at a line with foldlevel > 0. */ if (fline.lvl > 0) { invalid_top = fline.lnum; --- 2301,2315 ---- end = fp->fd_top + fp->fd_len - 1; else if (getlevel == foldlevelSyntax && foldLevelWin(wp, fline.lnum) != fline.lvl) ! // For "syntax" method: Compare the foldlevel that the syntax ! // tells us to the foldlevel from the existing folds. If they ! // don't match continue updating folds. end = fline.lnum; else break; } ! // A level 1 fold starts at a line with foldlevel > 0. if (fline.lvl > 0) { invalid_top = fline.lnum; *************** *** 2329,2344 **** } } ! /* There can't be any folds from start until end now. */ foldRemove(&wp->w_folds, start, end); ! /* If some fold changed, need to redraw and position cursor. */ if (fold_changed && wp->w_p_fen) changed_window_setting_win(wp); ! /* If we updated folds past "bot", need to redraw more lines. Don't do ! * this in other situations, the changed lines will be redrawn anyway and ! * this method can cause the whole window to be updated. */ if (end != bot) { if (wp->w_redraw_top == 0 || wp->w_redraw_top > top) --- 2328,2343 ---- } } ! // There can't be any folds from start until end now. foldRemove(&wp->w_folds, start, end); ! // If some fold changed, need to redraw and position cursor. if (fold_changed && wp->w_p_fen) changed_window_setting_win(wp); ! // If we updated folds past "bot", need to redraw more lines. Don't do ! // this in other situations, the changed lines will be redrawn anyway and ! // this method can cause the whole window to be updated. if (end != bot) { if (wp->w_redraw_top == 0 || wp->w_redraw_top > top) *************** *** 2350,2356 **** invalid_top = (linenr_T)0; } ! /* foldUpdateIEMSRecurse() {{{2 */ /* * Update a fold that starts at "flp->lnum". At this line there is always a * valid foldlevel, and its level >= "level". --- 2349,2355 ---- invalid_top = (linenr_T)0; } ! // foldUpdateIEMSRecurse() {{{2 /* * Update a fold that starts at "flp->lnum". At this line there is always a * valid foldlevel, and its level >= "level". *************** *** 2382,2395 **** fline_T *flp, void (*getlevel)(fline_T *), linenr_T bot, ! int topflags) /* flags used by containing fold */ { linenr_T ll; fold_T *fp = NULL; fold_T *fp2; int lvl = level; linenr_T startlnum2 = startlnum; ! linenr_T firstlnum = flp->lnum; /* first lnum we got */ int i; int finish = FALSE; linenr_T linecount = flp->wp->w_buffer->b_ml.ml_line_count - flp->off; --- 2381,2394 ---- fline_T *flp, void (*getlevel)(fline_T *), linenr_T bot, ! int topflags) // flags used by containing fold { linenr_T ll; fold_T *fp = NULL; fold_T *fp2; int lvl = level; linenr_T startlnum2 = startlnum; ! linenr_T firstlnum = flp->lnum; // first lnum we got int i; int finish = FALSE; linenr_T linecount = flp->wp->w_buffer->b_ml.ml_line_count - flp->off; *************** *** 2424,2436 **** flp->lnum_save = flp->lnum; while (!got_int) { ! /* Updating folds can be slow, check for CTRL-C. */ line_breakcheck(); ! /* Set "lvl" to the level of line "flp->lnum". When flp->start is set ! * and after the first line of the fold, set the level to zero to ! * force the fold to end. Do the same when had_end is set: Previous ! * line was marked as end of a fold. */ lvl = flp->lvl; if (lvl > MAX_LEVEL) lvl = MAX_LEVEL; --- 2423,2435 ---- flp->lnum_save = flp->lnum; while (!got_int) { ! // Updating folds can be slow, check for CTRL-C. line_breakcheck(); ! // Set "lvl" to the level of line "flp->lnum". When flp->start is set ! // and after the first line of the fold, set the level to zero to ! // force the fold to end. Do the same when had_end is set: Previous ! // line was marked as end of a fold. lvl = flp->lvl; if (lvl > MAX_LEVEL) lvl = MAX_LEVEL; *************** *** 2440,2451 **** if (flp->lnum > bot && !finish && fp != NULL) { ! /* For "marker" and "syntax" methods: ! * - If a change caused a nested fold to be removed, we need to ! * delete it and continue at least until where it ended. ! * - If a change caused a nested fold to be created, or this fold ! * to continue below its original end, need to finish this fold. ! */ if (getlevel != foldlevelMarker && getlevel != foldlevelExpr && getlevel != foldlevelSyntax) --- 2439,2449 ---- if (flp->lnum > bot && !finish && fp != NULL) { ! // For "marker" and "syntax" methods: ! // - If a change caused a nested fold to be removed, we need to ! // delete it and continue at least until where it ended. ! // - If a change caused a nested fold to be created, or this fold ! // to continue below its original end, need to finish this fold. if (getlevel != foldlevelMarker && getlevel != foldlevelExpr && getlevel != foldlevelSyntax) *************** *** 2454,2462 **** fp2 = fp; if (lvl >= level) { ! /* Compute how deep the folds currently are, if it's deeper ! * than "lvl" then some must be deleted, need to update ! * at least one nested fold. */ ll = flp->lnum - fp->fd_top; while (foldFind(&fp2->fd_nested, ll, &fp2)) { --- 2452,2460 ---- fp2 = fp; if (lvl >= level) { ! // Compute how deep the folds currently are, if it's deeper ! // than "lvl" then some must be deleted, need to update ! // at least one nested fold. ll = flp->lnum - fp->fd_top; while (foldFind(&fp2->fd_nested, ll, &fp2)) { *************** *** 2476,2484 **** break; } ! /* At the start of the first nested fold and at the end of the current ! * fold: check if existing folds at this level, before the current ! * one, need to be deleted or truncated. */ if (fp == NULL && (lvl != level || flp->lnum_save >= bot --- 2474,2482 ---- break; } ! // At the start of the first nested fold and at the end of the current ! // fold: check if existing folds at this level, before the current ! // one, need to be deleted or truncated. if (fp == NULL && (lvl != level || flp->lnum_save >= bot *************** *** 2492,2507 **** */ while (!got_int) { ! /* set concat to 1 if it's allowed to concatenated this fold ! * with a previous one that touches it. */ if (flp->start != 0 || flp->had_end <= MAX_LEVEL) concat = 0; else concat = 1; ! /* Find an existing fold to re-use. Preferably one that ! * includes startlnum, otherwise one that ends just before ! * startlnum or starts after it. */ if (foldFind(gap, startlnum, &fp) || (fp < ((fold_T *)gap->ga_data) + gap->ga_len && fp->fd_top <= firstlnum) --- 2490,2505 ---- */ while (!got_int) { ! // set concat to 1 if it's allowed to concatenated this fold ! // with a previous one that touches it. if (flp->start != 0 || flp->had_end <= MAX_LEVEL) concat = 0; else concat = 1; ! // Find an existing fold to re-use. Preferably one that ! // includes startlnum, otherwise one that ends just before ! // startlnum or starts after it. if (foldFind(gap, startlnum, &fp) || (fp < ((fold_T *)gap->ga_data) + gap->ga_len && fp->fd_top <= firstlnum) *************** *** 2513,2535 **** { if (fp->fd_top + fp->fd_len + concat > firstlnum) { ! /* Use existing fold for the new fold. If it starts ! * before where we started looking, extend it. If it ! * starts at another line, update nested folds to keep ! * their position, compensating for the new fd_top. */ if (fp->fd_top == firstlnum) { ! /* have found a fold beginning where we want */ } else if (fp->fd_top >= startlnum) { if (fp->fd_top > firstlnum) ! /* like lines are inserted */ foldMarkAdjustRecurse(&fp->fd_nested, (linenr_T)0, (linenr_T)MAXLNUM, (long)(fp->fd_top - firstlnum), 0L); else ! /* like lines are deleted */ foldMarkAdjustRecurse(&fp->fd_nested, (linenr_T)0, (long)(firstlnum - fp->fd_top - 1), --- 2511,2533 ---- { if (fp->fd_top + fp->fd_len + concat > firstlnum) { ! // Use existing fold for the new fold. If it starts ! // before where we started looking, extend it. If it ! // starts at another line, update nested folds to keep ! // their position, compensating for the new fd_top. if (fp->fd_top == firstlnum) { ! // have found a fold beginning where we want } else if (fp->fd_top >= startlnum) { if (fp->fd_top > firstlnum) ! // like lines are inserted foldMarkAdjustRecurse(&fp->fd_nested, (linenr_T)0, (linenr_T)MAXLNUM, (long)(fp->fd_top - firstlnum), 0L); else ! // like lines are deleted foldMarkAdjustRecurse(&fp->fd_nested, (linenr_T)0, (long)(firstlnum - fp->fd_top - 1), *************** *** 2577,2585 **** foldSplit(gap, i, breakstart, breakend - 1); fp = (fold_T *)gap->ga_data + i + 1; ! /* If using the "marker" or "syntax" method, we ! * need to continue until the end of the fold is ! * found. */ if (getlevel == foldlevelMarker || getlevel == foldlevelExpr || getlevel == foldlevelSyntax) --- 2575,2583 ---- foldSplit(gap, i, breakstart, breakend - 1); fp = (fold_T *)gap->ga_data + i + 1; ! // If using the "marker" or "syntax" method, we ! // need to continue until the end of the fold is ! // found. if (getlevel == foldlevelMarker || getlevel == foldlevelExpr || getlevel == foldlevelSyntax) *************** *** 2603,2618 **** } if (fp->fd_top >= startlnum) { ! /* A fold that starts at or after startlnum and stops ! * before the new fold must be deleted. Continue ! * looking for the next one. */ deleteFoldEntry(gap, (int)(fp - (fold_T *)gap->ga_data), TRUE); } else { ! /* A fold has some lines above startlnum, truncate it ! * to stop just above startlnum. */ fp->fd_len = startlnum - fp->fd_top; foldMarkAdjustRecurse(&fp->fd_nested, (linenr_T)fp->fd_len, (linenr_T)MAXLNUM, --- 2601,2616 ---- } if (fp->fd_top >= startlnum) { ! // A fold that starts at or after startlnum and stops ! // before the new fold must be deleted. Continue ! // looking for the next one. deleteFoldEntry(gap, (int)(fp - (fold_T *)gap->ga_data), TRUE); } else { ! // A fold has some lines above startlnum, truncate it ! // to stop just above startlnum. fp->fd_len = startlnum - fp->fd_top; foldMarkAdjustRecurse(&fp->fd_nested, (linenr_T)fp->fd_len, (linenr_T)MAXLNUM, *************** *** 2622,2640 **** } else { ! /* Insert new fold. Careful: ga_data may be NULL and it ! * may change! */ i = (int)(fp - (fold_T *)gap->ga_data); if (foldInsert(gap, i) != OK) return bot; fp = (fold_T *)gap->ga_data + i; ! /* The new fold continues until bot, unless we find the ! * end earlier. */ fp->fd_top = firstlnum; fp->fd_len = bot - firstlnum + 1; ! /* When the containing fold is open, the new fold is open. ! * The new fold is closed if the fold above it is closed. ! * The first fold depends on the containing fold. */ if (topflags == FD_OPEN) { flp->wp->w_fold_manual = TRUE; --- 2620,2638 ---- } else { ! // Insert new fold. Careful: ga_data may be NULL and it ! // may change! i = (int)(fp - (fold_T *)gap->ga_data); if (foldInsert(gap, i) != OK) return bot; fp = (fold_T *)gap->ga_data + i; ! // The new fold continues until bot, unless we find the ! // end earlier. fp->fd_top = firstlnum; fp->fd_len = bot - firstlnum + 1; ! // When the containing fold is open, the new fold is open. ! // The new fold is closed if the fold above it is closed. ! // The first fold depends on the containing fold. if (topflags == FD_OPEN) { flp->wp->w_fold_manual = TRUE; *************** *** 2649,2656 **** else fp->fd_flags = (fp - 1)->fd_flags; fp->fd_small = MAYBE; ! /* If using the "marker", "expr" or "syntax" method, we ! * need to continue until the end of the fold is found. */ if (getlevel == foldlevelMarker || getlevel == foldlevelExpr || getlevel == foldlevelSyntax) --- 2647,2654 ---- else fp->fd_flags = (fp - 1)->fd_flags; fp->fd_small = MAYBE; ! // If using the "marker", "expr" or "syntax" method, we ! // need to continue until the end of the fold is found. if (getlevel == foldlevelMarker || getlevel == foldlevelExpr || getlevel == foldlevelSyntax) *************** *** 2679,2690 **** /* * There is a nested fold, handle it recursively. */ ! /* At least do one line (can happen when finish is TRUE). */ if (bot < flp->lnum) bot = flp->lnum; ! /* Line numbers in the nested fold are relative to the start of ! * this fold. */ flp->lnum = flp->lnum_save - fp->fd_top; flp->off += fp->fd_top; i = (int)(fp - (fold_T *)gap->ga_data); --- 2677,2688 ---- /* * There is a nested fold, handle it recursively. */ ! // At least do one line (can happen when finish is TRUE). if (bot < flp->lnum) bot = flp->lnum; ! // Line numbers in the nested fold are relative to the start of ! // this fold. flp->lnum = flp->lnum_save - fp->fd_top; flp->off += fp->fd_top; i = (int)(fp - (fold_T *)gap->ga_data); *************** *** 2698,2704 **** bot += fp->fd_top; startlnum2 = flp->lnum; ! /* This fold may end at the same line, don't incr. flp->lnum. */ } else { --- 2696,2702 ---- bot += fp->fd_top; startlnum2 = flp->lnum; ! // This fold may end at the same line, don't incr. flp->lnum. } else { *************** *** 2712,2718 **** ll = flp->lnum + 1; while (!got_int) { ! /* Make the previous level available to foldlevel(). */ prev_lnum = flp->lnum; prev_lnum_lvl = flp->lvl; --- 2710,2716 ---- ll = flp->lnum + 1; while (!got_int) { ! // Make the previous level available to foldlevel(). prev_lnum = flp->lnum; prev_lnum_lvl = flp->lvl; *************** *** 2727,2740 **** if (flp->lnum > linecount) break; ! /* leave flp->lnum_save to lnum of the line that was used to get ! * the level, flp->lnum to the lnum of the next line. */ flp->lnum_save = flp->lnum; flp->lnum = ll; } } ! if (fp == NULL) /* only happens when got_int is set */ return bot; /* --- 2725,2738 ---- if (flp->lnum > linecount) break; ! // leave flp->lnum_save to lnum of the line that was used to get ! // the level, flp->lnum to the lnum of the next line. flp->lnum_save = flp->lnum; flp->lnum = ll; } } ! if (fp == NULL) // only happens when got_int is set return bot; /* *************** *** 2761,2785 **** if (lvl < level) { ! /* End of fold found, update the length when it got shorter. */ if (fp->fd_len != flp->lnum - fp->fd_top) { if (fp->fd_top + fp->fd_len - 1 > bot) { ! /* fold continued below bot */ if (getlevel == foldlevelMarker || getlevel == foldlevelExpr || getlevel == foldlevelSyntax) { ! /* marker method: truncate the fold and make sure the ! * previously included lines are processed again */ bot = fp->fd_top + fp->fd_len - 1; fp->fd_len = flp->lnum - fp->fd_top; } else { ! /* indent or expr method: split fold to create a new one ! * below bot */ i = (int)(fp - (fold_T *)gap->ga_data); foldSplit(gap, i, flp->lnum, bot); fp = (fold_T *)gap->ga_data + i; --- 2759,2783 ---- if (lvl < level) { ! // End of fold found, update the length when it got shorter. if (fp->fd_len != flp->lnum - fp->fd_top) { if (fp->fd_top + fp->fd_len - 1 > bot) { ! // fold continued below bot if (getlevel == foldlevelMarker || getlevel == foldlevelExpr || getlevel == foldlevelSyntax) { ! // marker method: truncate the fold and make sure the ! // previously included lines are processed again bot = fp->fd_top + fp->fd_len - 1; fp->fd_len = flp->lnum - fp->fd_top; } else { ! // indent or expr method: split fold to create a new one ! // below bot i = (int)(fp - (fold_T *)gap->ga_data); foldSplit(gap, i, flp->lnum, bot); fp = (fold_T *)gap->ga_data + i; *************** *** 2791,2797 **** } } ! /* delete following folds that end before the current line */ for (;;) { fp2 = fp + 1; --- 2789,2795 ---- } } ! // delete following folds that end before the current line for (;;) { fp2 = fp + 1; *************** *** 2802,2808 **** { if (fp2->fd_top < flp->lnum) { ! /* Make fold that includes lnum start at lnum. */ foldMarkAdjustRecurse(&fp2->fd_nested, (linenr_T)0, (long)(flp->lnum - fp2->fd_top - 1), (linenr_T)MAXLNUM, (long)(fp2->fd_top - flp->lnum)); --- 2800,2806 ---- { if (fp2->fd_top < flp->lnum) { ! // Make fold that includes lnum start at lnum. foldMarkAdjustRecurse(&fp2->fd_nested, (linenr_T)0, (long)(flp->lnum - fp2->fd_top - 1), (linenr_T)MAXLNUM, (long)(fp2->fd_top - flp->lnum)); *************** *** 2813,2819 **** if (lvl >= level) { ! /* merge new fold with existing fold that follows */ foldMerge(fp, gap, fp2); } break; --- 2811,2817 ---- if (lvl >= level) { ! // merge new fold with existing fold that follows foldMerge(fp, gap, fp2); } break; *************** *** 2822,2836 **** deleteFoldEntry(gap, (int)(fp2 - (fold_T *)gap->ga_data), TRUE); } ! /* Need to redraw the lines we inspected, which might be further down than ! * was asked for. */ if (bot < flp->lnum - 1) bot = flp->lnum - 1; return bot; } ! /* foldInsert() {{{2 */ /* * Insert a new fold in "gap" at position "i". * Returns OK for success, FAIL for failure. --- 2820,2834 ---- deleteFoldEntry(gap, (int)(fp2 - (fold_T *)gap->ga_data), TRUE); } ! // Need to redraw the lines we inspected, which might be further down than ! // was asked for. if (bot < flp->lnum - 1) bot = flp->lnum - 1; return bot; } ! // foldInsert() {{{2 /* * Insert a new fold in "gap" at position "i". * Returns OK for success, FAIL for failure. *************** *** 2850,2856 **** return OK; } ! /* foldSplit() {{{2 */ /* * Split the "i"th fold in "gap", which starts before "top" and ends below * "bot" in two pieces, one ending above "top" and the other starting below --- 2848,2854 ---- return OK; } ! // foldSplit() {{{2 /* * Split the "i"th fold in "gap", which starts before "top" and ends below * "bot" in two pieces, one ending above "top" and the other starting below *************** *** 2872,2878 **** int idx; int len; ! /* The fold continues below bot, need to split it. */ if (foldInsert(gap, i + 1) == FAIL) return; fp = (fold_T *)gap->ga_data + i; --- 2870,2876 ---- int idx; int len; ! // The fold continues below bot, need to split it. if (foldInsert(gap, i + 1) == FAIL) return; fp = (fold_T *)gap->ga_data + i; *************** *** 2882,2889 **** fp[1].fd_small = MAYBE; fp->fd_small = MAYBE; ! /* Move nested folds below bot to new fold. There can't be ! * any between top and bot, they have been removed by the caller. */ gap1 = &fp->fd_nested; gap2 = &fp[1].fd_nested; (void)(foldFind(gap1, bot + 1 - fp->fd_top, &fp2)); --- 2880,2887 ---- fp[1].fd_small = MAYBE; fp->fd_small = MAYBE; ! // Move nested folds below bot to new fold. There can't be ! // any between top and bot, they have been removed by the caller. gap1 = &fp->fd_nested; gap2 = &fp[1].fd_nested; (void)(foldFind(gap1, bot + 1 - fp->fd_top, &fp2)); *************** *** 2903,2909 **** fold_changed = TRUE; } ! /* foldRemove() {{{2 */ /* * Remove folds within the range "top" to and including "bot". * Check for these situations: --- 2901,2907 ---- fold_changed = TRUE; } ! // foldRemove() {{{2 /* * Remove folds within the range "top" to and including "bot". * Check for these situations: *************** *** 2928,2950 **** fold_T *fp = NULL; if (bot < top) ! return; /* nothing to do */ for (;;) { ! /* Find fold that includes top or a following one. */ if (foldFind(gap, top, &fp) && fp->fd_top < top) { ! /* 2: or 3: need to delete nested folds */ foldRemove(&fp->fd_nested, top - fp->fd_top, bot - fp->fd_top); if (fp->fd_top + fp->fd_len - 1 > bot) { ! /* 3: need to split it. */ foldSplit(gap, (int)(fp - (fold_T *)gap->ga_data), top, bot); } else { ! /* 2: truncate fold at "top". */ fp->fd_len = top - fp->fd_top; } fold_changed = TRUE; --- 2926,2948 ---- fold_T *fp = NULL; if (bot < top) ! return; // nothing to do for (;;) { ! // Find fold that includes top or a following one. if (foldFind(gap, top, &fp) && fp->fd_top < top) { ! // 2: or 3: need to delete nested folds foldRemove(&fp->fd_nested, top - fp->fd_top, bot - fp->fd_top); if (fp->fd_top + fp->fd_len - 1 > bot) { ! // 3: need to split it. foldSplit(gap, (int)(fp - (fold_T *)gap->ga_data), top, bot); } else { ! // 2: truncate fold at "top". fp->fd_len = top - fp->fd_top; } fold_changed = TRUE; *************** *** 2953,2968 **** if (fp >= (fold_T *)(gap->ga_data) + gap->ga_len || fp->fd_top > bot) { ! /* 6: Found a fold below bot, can stop looking. */ break; } if (fp->fd_top >= top) { ! /* Found an entry below top. */ fold_changed = TRUE; if (fp->fd_top + fp->fd_len - 1 > bot) { ! /* 5: Make fold that includes bot start below bot. */ foldMarkAdjustRecurse(&fp->fd_nested, (linenr_T)0, (long)(bot - fp->fd_top), (linenr_T)MAXLNUM, (long)(fp->fd_top - bot - 1)); --- 2951,2966 ---- if (fp >= (fold_T *)(gap->ga_data) + gap->ga_len || fp->fd_top > bot) { ! // 6: Found a fold below bot, can stop looking. break; } if (fp->fd_top >= top) { ! // Found an entry below top. fold_changed = TRUE; if (fp->fd_top + fp->fd_len - 1 > bot) { ! // 5: Make fold that includes bot start below bot. foldMarkAdjustRecurse(&fp->fd_nested, (linenr_T)0, (long)(bot - fp->fd_top), (linenr_T)MAXLNUM, (long)(fp->fd_top - bot - 1)); *************** *** 2971,2983 **** break; } ! /* 4: Delete completely contained fold. */ deleteFoldEntry(gap, (int)(fp - (fold_T *)gap->ga_data), TRUE); } } } ! /* foldReverseOrder() {{{2 */ static void foldReverseOrder(garray_T *gap, linenr_T start_arg, linenr_T end_arg) { --- 2969,2981 ---- break; } ! // 4: Delete completely contained fold. deleteFoldEntry(gap, (int)(fp - (fold_T *)gap->ga_data), TRUE); } } } ! // foldReverseOrder() {{{2 static void foldReverseOrder(garray_T *gap, linenr_T start_arg, linenr_T end_arg) { *************** *** 2996,3002 **** } } ! /* foldMoveRange() {{{2 */ /* * Move folds within the inclusive range "line1" to "line2" to after "dest" * requires "line1" <= "line2" <= "dest" --- 2994,3000 ---- } } ! // foldMoveRange() {{{2 /* * Move folds within the inclusive range "line1" to "line2" to after "dest" * requires "line1" <= "line2" <= "dest" *************** *** 3054,3102 **** { if (fold_end(fp) > dest) { ! /* Case 4 ! * don't have to change this fold, but have to move nested folds. ! */ foldMoveRange(&fp->fd_nested, line1 - fp->fd_top, line2 - fp->fd_top, dest - fp->fd_top); return; } else if (fold_end(fp) > line2) { ! /* Case 3 ! * Remove nested folds between line1 and line2 & reduce the ! * length of fold by "range_len". ! * Folds after this one must be dealt with. ! */ foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top, line2 - fp->fd_top, MAXLNUM, -range_len); fp->fd_len -= range_len; } else ! /* Case 2 truncate fold, folds after this one must be dealt with. */ truncate_fold(fp, line1 - 1); ! /* Look at the next fold, and treat that one as if it were the first ! * after "line1" (because now it is). */ fp = fp + 1; } if (!valid_fold(fp, gap) || fp->fd_top > dest) { ! /* Case 10 ! * No folds after "line1" and before "dest" ! */ return; } else if (fp->fd_top > line2) { for (; valid_fold(fp, gap) && fold_end(fp) <= dest; fp++) ! /* Case 9. (for all case 9's) -- shift up. */ fp->fd_top -= range_len; if (valid_fold(fp, gap) && fp->fd_top <= dest) { ! /* Case 8. -- ensure truncated at dest, shift up */ truncate_fold(fp, dest); fp->fd_top -= range_len; } --- 3052,3097 ---- { if (fold_end(fp) > dest) { ! // Case 4 ! // don't have to change this fold, but have to move nested folds. foldMoveRange(&fp->fd_nested, line1 - fp->fd_top, line2 - fp->fd_top, dest - fp->fd_top); return; } else if (fold_end(fp) > line2) { ! // Case 3 ! // Remove nested folds between line1 and line2 & reduce the ! // length of fold by "range_len". ! // Folds after this one must be dealt with. foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top, line2 - fp->fd_top, MAXLNUM, -range_len); fp->fd_len -= range_len; } else ! // Case 2 truncate fold, folds after this one must be dealt with. truncate_fold(fp, line1 - 1); ! // Look at the next fold, and treat that one as if it were the first ! // after "line1" (because now it is). fp = fp + 1; } if (!valid_fold(fp, gap) || fp->fd_top > dest) { ! // Case 10 ! // No folds after "line1" and before "dest" return; } else if (fp->fd_top > line2) { for (; valid_fold(fp, gap) && fold_end(fp) <= dest; fp++) ! // Case 9. (for all case 9's) -- shift up. fp->fd_top -= range_len; if (valid_fold(fp, gap) && fp->fd_top <= dest) { ! // Case 8. -- ensure truncated at dest, shift up truncate_fold(fp, dest); fp->fd_top -= range_len; } *************** *** 3104,3110 **** } else if (fold_end(fp) > dest) { ! /* Case 7 -- remove nested folds and shrink */ foldMarkAdjustRecurse(&fp->fd_nested, line2 + 1 - fp->fd_top, dest - fp->fd_top, MAXLNUM, -move_len); fp->fd_len -= move_len; --- 3099,3105 ---- } else if (fold_end(fp) > dest) { ! // Case 7 -- remove nested folds and shrink foldMarkAdjustRecurse(&fp->fd_nested, line2 + 1 - fp->fd_top, dest - fp->fd_top, MAXLNUM, -move_len); fp->fd_len -= move_len; *************** *** 3112,3137 **** return; } ! /* Case 5 or 6 ! * changes rely on whether there are folds between the end of ! * this fold and "dest". ! */ move_start = fold_index(fp, gap); for (; valid_fold(fp, gap) && fp->fd_top <= dest; fp++) { if (fp->fd_top <= line2) { ! /* 1. 2. or 3. */ if (fold_end(fp) > line2) ! /* 2. or 3., truncate before moving */ truncate_fold(fp, line2); fp->fd_top += move_len; continue; } ! /* Record index of the first fold after the moved range. */ if (move_end == 0) move_end = fold_index(fp, gap); --- 3107,3131 ---- return; } ! // Case 5 or 6 ! // changes rely on whether there are folds between the end of ! // this fold and "dest". move_start = fold_index(fp, gap); for (; valid_fold(fp, gap) && fp->fd_top <= dest; fp++) { if (fp->fd_top <= line2) { ! // 1. 2. or 3. if (fold_end(fp) > line2) ! // 2. or 3., truncate before moving truncate_fold(fp, line2); fp->fd_top += move_len; continue; } ! // Record index of the first fold after the moved range. if (move_end == 0) move_end = fold_index(fp, gap); *************** *** 3149,3156 **** * range [move_start, move_end). */ if (move_end == 0) ! /* There are no folds after those moved, hence no folds have been moved ! * out of order. */ return; foldReverseOrder(gap, (linenr_T)move_start, (linenr_T)dest_index - 1); foldReverseOrder(gap, (linenr_T)move_start, --- 3143,3150 ---- * range [move_start, move_end). */ if (move_end == 0) ! // There are no folds after those moved, hence no folds have been moved ! // out of order. return; foldReverseOrder(gap, (linenr_T)move_start, (linenr_T)dest_index - 1); foldReverseOrder(gap, (linenr_T)move_start, *************** *** 3162,3168 **** #undef valid_fold #undef fold_index ! /* foldMerge() {{{2 */ /* * Merge two adjacent folds (and the nested ones in them). * This only works correctly when the folds are really adjacent! Thus "fp1" --- 3156,3162 ---- #undef valid_fold #undef fold_index ! // foldMerge() {{{2 /* * Merge two adjacent folds (and the nested ones in them). * This only works correctly when the folds are really adjacent! Thus "fp1" *************** *** 3179,3190 **** garray_T *gap1 = &fp1->fd_nested; garray_T *gap2 = &fp2->fd_nested; ! /* If the last nested fold in fp1 touches the first nested fold in fp2, ! * merge them recursively. */ if (foldFind(gap1, fp1->fd_len - 1L, &fp3) && foldFind(gap2, 0L, &fp4)) foldMerge(fp3, gap2, fp4); ! /* Move nested folds in fp2 to the end of fp1. */ if (gap2->ga_len > 0 && ga_grow(gap1, gap2->ga_len) == OK) { for (idx = 0; idx < gap2->ga_len; ++idx) --- 3173,3184 ---- garray_T *gap1 = &fp1->fd_nested; garray_T *gap2 = &fp2->fd_nested; ! // If the last nested fold in fp1 touches the first nested fold in fp2, ! // merge them recursively. if (foldFind(gap1, fp1->fd_len - 1L, &fp3) && foldFind(gap2, 0L, &fp4)) foldMerge(fp3, gap2, fp4); ! // Move nested folds in fp2 to the end of fp1. if (gap2->ga_len > 0 && ga_grow(gap1, gap2->ga_len) == OK) { for (idx = 0; idx < gap2->ga_len; ++idx) *************** *** 3202,3208 **** fold_changed = TRUE; } ! /* foldlevelIndent() {{{2 */ /* * Low level function to get the foldlevel for the "indent" method. * Doesn't use any caching. --- 3196,3202 ---- fold_changed = TRUE; } ! // foldlevelIndent() {{{2 /* * Low level function to get the foldlevel for the "indent" method. * Doesn't use any caching. *************** *** 3218,3228 **** buf = flp->wp->w_buffer; s = skipwhite(ml_get_buf(buf, lnum, FALSE)); ! /* empty line or lines starting with a character in 'foldignore': level ! * depends on surrounding lines */ if (*s == NUL || vim_strchr(flp->wp->w_p_fdi, *s) != NULL) { ! /* first and last line can't be undefined, use level 0 */ if (lnum == 1 || lnum == buf->b_ml.ml_line_count) flp->lvl = 0; else --- 3212,3222 ---- buf = flp->wp->w_buffer; s = skipwhite(ml_get_buf(buf, lnum, FALSE)); ! // empty line or lines starting with a character in 'foldignore': level ! // depends on surrounding lines if (*s == NUL || vim_strchr(flp->wp->w_p_fdi, *s) != NULL) { ! // first and last line can't be undefined, use level 0 if (lnum == 1 || lnum == buf->b_ml.ml_line_count) flp->lvl = 0; else *************** *** 3238,3244 **** } } ! /* foldlevelDiff() {{{2 */ #ifdef FEAT_DIFF /* * Low level function to get the foldlevel for the "diff" method. --- 3232,3238 ---- } } ! // foldlevelDiff() {{{2 #ifdef FEAT_DIFF /* * Low level function to get the foldlevel for the "diff" method. *************** *** 3254,3260 **** } #endif ! /* foldlevelExpr() {{{2 */ /* * Low level function to get the foldlevel for the "expr" method. * Doesn't use any caching. --- 3248,3254 ---- } #endif ! // foldlevelExpr() {{{2 /* * Low level function to get the foldlevel for the "expr" method. * Doesn't use any caching. *************** *** 3284,3298 **** if (lnum <= 1) flp->lvl = 0; ! /* KeyTyped may be reset to 0 when calling a function which invokes ! * do_cmdline(). To make 'foldopen' work correctly restore KeyTyped. */ save_keytyped = KeyTyped; n = (int)eval_foldexpr(flp->wp->w_p_fde, &c); KeyTyped = save_keytyped; switch (c) { ! /* "a1", "a2", .. : add to the fold level */ case 'a': if (flp->lvl >= 0) { flp->lvl += n; --- 3278,3292 ---- if (lnum <= 1) flp->lvl = 0; ! // KeyTyped may be reset to 0 when calling a function which invokes ! // do_cmdline(). To make 'foldopen' work correctly restore KeyTyped. save_keytyped = KeyTyped; n = (int)eval_foldexpr(flp->wp->w_p_fde, &c); KeyTyped = save_keytyped; switch (c) { ! // "a1", "a2", .. : add to the fold level case 'a': if (flp->lvl >= 0) { flp->lvl += n; *************** *** 3301,3307 **** flp->start = n; break; ! /* "s1", "s2", .. : subtract from the fold level */ case 's': if (flp->lvl >= 0) { if (n > flp->lvl) --- 3295,3301 ---- flp->start = n; break; ! // "s1", "s2", .. : subtract from the fold level case 's': if (flp->lvl >= 0) { if (n > flp->lvl) *************** *** 3312,3336 **** } break; ! /* ">1", ">2", .. : start a fold with a certain level */ case '>': flp->lvl = n; flp->lvl_next = n; flp->start = 1; break; ! /* "<1", "<2", .. : end a fold with a certain level */ case '<': flp->lvl_next = n - 1; flp->end = n; break; ! /* "=": No change in level */ case '=': flp->lvl_next = flp->lvl; break; ! /* "-1", "0", "1", ..: set fold level */ default: if (n < 0) ! /* Use the current level for the next line, so that "a1" ! * will work there. */ flp->lvl_next = flp->lvl; else flp->lvl_next = n; --- 3306,3330 ---- } break; ! // ">1", ">2", .. : start a fold with a certain level case '>': flp->lvl = n; flp->lvl_next = n; flp->start = 1; break; ! // "<1", "<2", .. : end a fold with a certain level case '<': flp->lvl_next = n - 1; flp->end = n; break; ! // "=": No change in level case '=': flp->lvl_next = flp->lvl; break; ! // "-1", "0", "1", ..: set fold level default: if (n < 0) ! // Use the current level for the next line, so that "a1" ! // will work there. flp->lvl_next = flp->lvl; else flp->lvl_next = n; *************** *** 3338,3345 **** break; } ! /* If the level is unknown for the first or the last line in the file, use ! * level 0. */ if (flp->lvl < 0) { if (lnum <= 1) --- 3332,3339 ---- break; } ! // If the level is unknown for the first or the last line in the file, use ! // level 0. if (flp->lvl < 0) { if (lnum <= 1) *************** *** 3356,3362 **** #endif } ! /* parseMarker() {{{2 */ /* * Parse 'foldmarker' and set "foldendmarker", "foldstartmarkerlen" and * "foldendmarkerlen". --- 3350,3356 ---- #endif } ! // parseMarker() {{{2 /* * Parse 'foldmarker' and set "foldendmarker", "foldstartmarkerlen" and * "foldendmarkerlen". *************** *** 3370,3376 **** foldendmarkerlen = (int)STRLEN(foldendmarker); } ! /* foldlevelMarker() {{{2 */ /* * Low level function to get the foldlevel for the "marker" method. * "foldendmarker", "foldstartmarkerlen" and "foldendmarkerlen" must have been --- 3364,3370 ---- foldendmarkerlen = (int)STRLEN(foldendmarker); } ! // foldlevelMarker() {{{2 /* * Low level function to get the foldlevel for the "marker" method. * "foldendmarker", "foldstartmarkerlen" and "foldendmarkerlen" must have been *************** *** 3390,3402 **** char_u *s; int n; ! /* cache a few values for speed */ startmarker = flp->wp->w_p_fmr; cstart = *startmarker; ++startmarker; cend = *foldendmarker; ! /* Default: no start found, next level is same as current level */ flp->start = 0; flp->lvl_next = flp->lvl; --- 3384,3396 ---- char_u *s; int n; ! // cache a few values for speed startmarker = flp->wp->w_p_fmr; cstart = *startmarker; ++startmarker; cend = *foldendmarker; ! // Default: no start found, next level is same as current level flp->start = 0; flp->lvl_next = flp->lvl; *************** *** 3406,3412 **** if (*s == cstart && STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { ! /* found startmarker: set flp->lvl */ s += foldstartmarkerlen; if (VIM_ISDIGIT(*s)) { --- 3400,3406 ---- if (*s == cstart && STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { ! // found startmarker: set flp->lvl s += foldstartmarkerlen; if (VIM_ISDIGIT(*s)) { *************** *** 3431,3437 **** else if (*s == cend && STRNCMP(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0) { ! /* found endmarker: set flp->lvl_next */ s += foldendmarkerlen; if (VIM_ISDIGIT(*s)) { --- 3425,3431 ---- else if (*s == cend && STRNCMP(s + 1, foldendmarker + 1, foldendmarkerlen - 1) == 0) { ! // found endmarker: set flp->lvl_next s += foldendmarkerlen; if (VIM_ISDIGIT(*s)) { *************** *** 3440,3446 **** { flp->lvl = n; flp->lvl_next = n - 1; ! /* never start a fold with an end marker */ if (flp->lvl_next > start_lvl) flp->lvl_next = start_lvl; } --- 3434,3440 ---- { flp->lvl = n; flp->lvl_next = n - 1; ! // never start a fold with an end marker if (flp->lvl_next > start_lvl) flp->lvl_next = start_lvl; } *************** *** 3452,3463 **** MB_PTR_ADV(s); } ! /* The level can't go negative, must be missing a start marker. */ if (flp->lvl_next < 0) flp->lvl_next = 0; } ! /* foldlevelSyntax() {{{2 */ /* * Low level function to get the foldlevel for the "syntax" method. * Doesn't use any caching. --- 3446,3457 ---- MB_PTR_ADV(s); } ! // The level can't go negative, must be missing a start marker. if (flp->lvl_next < 0) flp->lvl_next = 0; } ! // foldlevelSyntax() {{{2 /* * Low level function to get the foldlevel for the "syntax" method. * Doesn't use any caching. *************** *** 3472,3478 **** linenr_T lnum = flp->lnum + flp->off; int n; ! /* Use the maximum fold level at the start of this line and the next. */ flp->lvl = syn_get_foldlevel(flp->wp, lnum); flp->start = 0; if (lnum < flp->wp->w_buffer->b_ml.ml_line_count) --- 3466,3472 ---- linenr_T lnum = flp->lnum + flp->off; int n; ! // Use the maximum fold level at the start of this line and the next. flp->lvl = syn_get_foldlevel(flp->wp, lnum); flp->start = 0; if (lnum < flp->wp->w_buffer->b_ml.ml_line_count) *************** *** 3480,3494 **** n = syn_get_foldlevel(flp->wp, lnum + 1); if (n > flp->lvl) { ! flp->start = n - flp->lvl; /* fold(s) start here */ flp->lvl = n; } } #endif } ! /* functions for storing the fold state in a View {{{1 */ ! /* put_folds() {{{2 */ #if defined(FEAT_SESSION) || defined(PROTO) static int put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off); static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off); --- 3474,3488 ---- n = syn_get_foldlevel(flp->wp, lnum + 1); if (n > flp->lvl) { ! flp->start = n - flp->lvl; // fold(s) start here flp->lvl = n; } } #endif } ! // functions for storing the fold state in a View {{{1 ! // put_folds() {{{2 #if defined(FEAT_SESSION) || defined(PROTO) static int put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off); static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off); *************** *** 3508,3521 **** return FAIL; } ! /* If some folds are manually opened/closed, need to restore that. */ if (wp->w_fold_manual) return put_foldopen_recurse(fd, wp, &wp->w_folds, (linenr_T)0); return OK; } ! /* put_folds_recurse() {{{2 */ /* * Write commands to "fd" to recreate manually created folds. * Returns FAIL when writing failed. --- 3502,3515 ---- return FAIL; } ! // If some folds are manually opened/closed, need to restore that. if (wp->w_fold_manual) return put_foldopen_recurse(fd, wp, &wp->w_folds, (linenr_T)0); return OK; } ! // put_folds_recurse() {{{2 /* * Write commands to "fd" to recreate manually created folds. * Returns FAIL when writing failed. *************** *** 3529,3535 **** fp = (fold_T *)gap->ga_data; for (i = 0; i < gap->ga_len; i++) { ! /* Do nested folds first, they will be created closed. */ if (put_folds_recurse(fd, &fp->fd_nested, off + fp->fd_top) == FAIL) return FAIL; if (fprintf(fd, "%ld,%ldfold", fp->fd_top + off, --- 3523,3529 ---- fp = (fold_T *)gap->ga_data; for (i = 0; i < gap->ga_len; i++) { ! // Do nested folds first, they will be created closed. if (put_folds_recurse(fd, &fp->fd_nested, off + fp->fd_top) == FAIL) return FAIL; if (fprintf(fd, "%ld,%ldfold", fp->fd_top + off, *************** *** 3541,3547 **** return OK; } ! /* put_foldopen_recurse() {{{2 */ /* * Write commands to "fd" to open and close manually opened/closed folds. * Returns FAIL when writing failed. --- 3535,3541 ---- return OK; } ! // put_foldopen_recurse() {{{2 /* * Write commands to "fd" to open and close manually opened/closed folds. * Returns FAIL when writing failed. *************** *** 3564,3570 **** { if (fp->fd_nested.ga_len > 0) { ! /* open nested folds while this fold is open */ if (fprintf(fd, "%ld", fp->fd_top + off) < 0 || put_eol(fd) == FAIL || put_line(fd, "normal! zo") == FAIL) --- 3558,3564 ---- { if (fp->fd_nested.ga_len > 0) { ! // open nested folds while this fold is open if (fprintf(fd, "%ld", fp->fd_top + off) < 0 || put_eol(fd) == FAIL || put_line(fd, "normal! zo") == FAIL) *************** *** 3573,3579 **** off + fp->fd_top) == FAIL) return FAIL; ! /* close the parent when needed */ if (fp->fd_flags == FD_CLOSED) { if (put_fold_open_close(fd, fp, off) == FAIL) --- 3567,3573 ---- off + fp->fd_top) == FAIL) return FAIL; ! // close the parent when needed if (fp->fd_flags == FD_CLOSED) { if (put_fold_open_close(fd, fp, off) == FAIL) *************** *** 3582,3590 **** } else { ! /* Open or close the leaf according to the window foldlevel. ! * Do not close a leaf that is already closed, as it will close ! * the parent. */ level = foldLevelWin(wp, off + fp->fd_top); if ((fp->fd_flags == FD_CLOSED && wp->w_p_fdl >= level) || (fp->fd_flags != FD_CLOSED && wp->w_p_fdl < level)) --- 3576,3584 ---- } else { ! // Open or close the leaf according to the window foldlevel. ! // Do not close a leaf that is already closed, as it will close ! // the parent. level = foldLevelWin(wp, off + fp->fd_top); if ((fp->fd_flags == FD_CLOSED && wp->w_p_fdl >= level) || (fp->fd_flags != FD_CLOSED && wp->w_p_fdl < level)) *************** *** 3598,3604 **** return OK; } ! /* put_fold_open_close() {{{2 */ /* * Write the open or close command to "fd". * Returns FAIL when writing failed. --- 3592,3598 ---- return OK; } ! // put_fold_open_close() {{{2 /* * Write the open or close command to "fd". * Returns FAIL when writing failed. *************** *** 3615,3623 **** return OK; } ! #endif /* FEAT_SESSION */ ! /* }}}1 */ #endif // defined(FEAT_FOLDING) || defined(PROTO) #if defined(FEAT_EVAL) || defined(PROTO) --- 3609,3617 ---- return OK; } ! #endif // FEAT_SESSION ! // }}}1 #endif // defined(FEAT_FOLDING) || defined(PROTO) #if defined(FEAT_EVAL) || defined(PROTO) *** ../vim-8.1.2378/src/version.c 2019-12-01 21:11:18.437245361 +0100 --- src/version.c 2019-12-01 21:40:56.193954805 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 2379, /**/ -- Apathy Error: Don't bother striking any key. /// 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 ///