To: vim_dev@googlegroups.com Subject: Patch 8.1.2396 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2396 Problem: Using old C style comments. Solution: Use // comments where appropriate. Files: src/ui.c, src/undo.c, src/uninstall.c, src/usercmd.c, src/userfunc.c, src/winclip.c, src/window.c, src/xpm_w32.c *** ../vim-8.1.2395/src/ui.c 2019-11-30 22:47:42.659331167 +0100 --- src/ui.c 2019-12-05 21:39:28.277570444 +0100 *************** *** 37,43 **** } #endif #ifndef NO_CONSOLE ! /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */ if (!(silent_mode && p_verbose == 0)) { #if !defined(MSWIN) --- 37,43 ---- } #endif #ifndef NO_CONSOLE ! // Don't output anything in silent mode ("ex -s") unless 'verbose' set if (!(silent_mode && p_verbose == 0)) { #if !defined(MSWIN) *************** *** 45,51 **** if (output_conv.vc_type != CONV_NONE) { ! /* Convert characters from 'encoding' to 'termencoding'. */ tofree = string_convert(&output_conv, s, &len); if (tofree != NULL) s = tofree; --- 45,51 ---- if (output_conv.vc_type != CONV_NONE) { ! // Convert characters from 'encoding' to 'termencoding'. tofree = string_convert(&output_conv, s, &len); if (tofree != NULL) s = tofree; *************** *** 69,76 **** * here for the next call. */ static char_u *ta_str = NULL; ! static int ta_off; /* offset for next char to use when ta_str != NULL */ ! static int ta_len; /* length of ta_str when it's not NULL*/ void ui_inchar_undo(char_u *s, int len) --- 69,76 ---- * here for the next call. */ static char_u *ta_str = NULL; ! static int ta_off; // offset for next char to use when ta_str != NULL ! static int ta_len; // length of ta_str when it's not NULL void ui_inchar_undo(char_u *s, int len) *************** *** 116,122 **** ui_inchar( char_u *buf, int maxlen, ! long wtime, /* don't use "time", MIPS cannot handle it */ int tb_change_cnt) { int retval = 0; --- 116,122 ---- ui_inchar( char_u *buf, int maxlen, ! long wtime, // don't use "time", MIPS cannot handle it int tb_change_cnt) { int retval = 0; *************** *** 145,154 **** #endif #ifdef NO_CONSOLE_INPUT ! /* Don't wait for character input when the window hasn't been opened yet. ! * Do try reading, this works when redirecting stdin from a file. ! * Must return something, otherwise we'll loop forever. If we run into ! * this very often we probably got stuck, exit Vim. */ if (no_console_input()) { static int count = 0; --- 145,154 ---- #endif #ifdef NO_CONSOLE_INPUT ! // Don't wait for character input when the window hasn't been opened yet. ! // Do try reading, this works when redirecting stdin from a file. ! // Must return something, otherwise we'll loop forever. If we run into ! // this very often we probably got stuck, exit Vim. if (no_console_input()) { static int count = 0; *************** *** 166,179 **** } #endif ! /* If we are going to wait for some time or block... */ if (wtime == -1 || wtime > 100L) { ! /* ... allow signals to kill us. */ (void)vim_handle_signal(SIGNAL_UNBLOCK); ! /* ... there is no need for CTRL-C to interrupt something, don't let ! * it set got_int when it was mapped. */ if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) ctrl_c_interrupts = FALSE; } --- 166,179 ---- } #endif ! // If we are going to wait for some time or block... if (wtime == -1 || wtime > 100L) { ! // ... allow signals to kill us. (void)vim_handle_signal(SIGNAL_UNBLOCK); ! // ... there is no need for CTRL-C to interrupt something, don't let ! // it set got_int when it was mapped. if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) ctrl_c_interrupts = FALSE; } *************** *** 232,238 **** #endif if (wtime == -1 || wtime > 100L) ! /* block SIGHUP et al. */ (void)vim_handle_signal(SIGNAL_BLOCK); ctrl_c_interrupts = TRUE; --- 232,238 ---- #endif if (wtime == -1 || wtime > 100L) ! // block SIGHUP et al. (void)vim_handle_signal(SIGNAL_BLOCK); ctrl_c_interrupts = TRUE; *************** *** 282,292 **** ELAPSED_INIT(start_tv); #endif ! /* repeat until we got a character or waited long enough */ for (;;) { ! /* Check if window changed size while we were busy, perhaps the ":set ! * columns=99" command was used. */ if (resize_func != NULL) resize_func(FALSE); --- 282,292 ---- ELAPSED_INIT(start_tv); #endif ! // repeat until we got a character or waited long enough for (;;) { ! // Check if window changed size while we were busy, perhaps the ":set ! // columns=99" command was used. if (resize_func != NULL) resize_func(FALSE); *************** *** 454,460 **** due_time = check_due_timer(); if (typebuf.tb_change_cnt != tb_change_cnt) { ! /* timer may have used feedkeys() */ return FAIL; } if (due_time <= 0 || (wtime > 0 && due_time > remaining)) --- 454,460 ---- due_time = check_due_timer(); if (typebuf.tb_change_cnt != tb_change_cnt) { ! // timer may have used feedkeys() return FAIL; } if (due_time <= 0 || (wtime > 0 && due_time > remaining)) *************** *** 598,604 **** check_shellsize(); ! /* adjust the default for 'lines' and 'columns' */ if (retval == OK) { set_number_default("lines", Rows); --- 598,604 ---- check_shellsize(); ! // adjust the default for 'lines' and 'columns' if (retval == OK) { set_number_default("lines", Rows); *************** *** 614,620 **** */ void ui_set_shellsize( ! int mustset UNUSED) /* set by the user */ { #ifdef FEAT_GUI if (gui.in_use) --- 614,620 ---- */ void ui_set_shellsize( ! int mustset UNUSED) // set by the user { #ifdef FEAT_GUI if (gui.in_use) *************** *** 711,727 **** recursive = FALSE; } ! /***************************************************************************** ! * Functions for copying and pasting text between applications. ! * This is always included in a GUI version, but may also be included when the ! * clipboard and mouse is available to a terminal version such as xterm. ! * Note: there are some more functions in ops.c that handle selection stuff. ! * ! * Also note that the majority of functions here deal with the X 'primary' ! * (visible - for Visual mode use) selection, and only that. There are no ! * versions of these for the 'clipboard' selection, as Visual mode has no use ! * for them. ! */ #if defined(FEAT_CLIPBOARD) || defined(PROTO) --- 711,726 ---- recursive = FALSE; } ! ////////////////////////////////////////////////////////////////////////////// ! // Functions for copying and pasting text between applications. ! // This is always included in a GUI version, but may also be included when the ! // clipboard and mouse is available to a terminal version such as xterm. ! // Note: there are some more functions in ops.c that handle selection stuff. ! // ! // Also note that the majority of functions here deal with the X 'primary' ! // (visible - for Visual mode use) selection, and only that. There are no ! // versions of these for the 'clipboard' selection, as Visual mode has no use ! // for them. #if defined(FEAT_CLIPBOARD) || defined(PROTO) *************** *** 776,782 **** { pos_T start, end; ! /* If visual mode is only due to a redo command ("."), then ignore it */ if (!redo_VIsual_busy && VIsual_active && (State & NORMAL)) { if (LT_POS(VIsual, curwin->w_cursor)) --- 775,781 ---- { pos_T start, end; ! // If visual mode is only due to a redo command ("."), then ignore it if (!redo_VIsual_busy && VIsual_active && (State & NORMAL)) { if (LT_POS(VIsual, curwin->w_cursor)) *************** *** 814,821 **** * than a mapping etc. */ #ifdef FEAT_X11 ! /* Always own the selection, we might have lost it without being ! * notified, e.g. during a ":sh" command. */ if (cbd->available) { int was_owned = cbd->owned; --- 813,820 ---- * than a mapping etc. */ #ifdef FEAT_X11 ! // Always own the selection, we might have lost it without being ! // notified, e.g. during a ":sh" command. if (cbd->available) { int was_owned = cbd->owned; *************** *** 823,831 **** cbd->owned = (clip_gen_own_selection(cbd) == OK); if (!was_owned && (cbd == &clip_star || cbd == &clip_plus)) { ! /* May have to show a different kind of highlighting for the ! * selected area. There is no specific redraw command for this, ! * just redraw all windows on the current buffer. */ if (cbd->owned && (get_real_state() == VISUAL || get_real_state() == SELECTMODE) --- 822,830 ---- cbd->owned = (clip_gen_own_selection(cbd) == OK); if (!was_owned && (cbd == &clip_star || cbd == &clip_plus)) { ! // May have to show a different kind of highlighting for the ! // selected area. There is no specific redraw command for this, ! // just redraw all windows on the current buffer. if (cbd->owned && (get_real_state() == VISUAL || get_real_state() == SELECTMODE) *************** *** 836,842 **** } } #else ! /* Only own the clipboard when we didn't own it yet. */ if (!cbd->owned && cbd->available) cbd->owned = (clip_gen_own_selection(cbd) == OK); #endif --- 835,841 ---- } } #else ! // Only own the clipboard when we didn't own it yet. if (!cbd->owned && cbd->available) cbd->owned = (clip_gen_own_selection(cbd) == OK); #endif *************** *** 861,869 **** #ifdef FEAT_X11 if (visual_selection) { ! /* May have to show a different kind of highlighting for the selected ! * area. There is no specific redraw command for this, just redraw all ! * windows on the current buffer. */ if (was_owned && (get_real_state() == VISUAL || get_real_state() == SELECTMODE) --- 860,868 ---- #ifdef FEAT_X11 if (visual_selection) { ! // May have to show a different kind of highlighting for the selected ! // area. There is no specific redraw command for this, just redraw all ! // windows on the current buffer. if (was_owned && (get_real_state() == VISUAL || get_real_state() == SELECTMODE) *************** *** 899,906 **** * prevents accessing the clipboard very often which might slow down Vim * considerably. */ ! static int global_change_count = 0; /* if set, inside a start_global_changes */ ! static int clipboard_needs_update = FALSE; /* clipboard needs to be updated */ static int clip_did_set_selection = TRUE; /* --- 898,905 ---- * prevents accessing the clipboard very often which might slow down Vim * considerably. */ ! static int global_change_count = 0; // if set, inside a start_global_changes ! static int clipboard_needs_update = FALSE; // clipboard needs to be updated static int clip_did_set_selection = TRUE; /* *************** *** 938,944 **** end_global_changes(void) { if (--global_change_count > 0) ! /* recursive */ return; if (!clip_did_set_selection) { --- 937,943 ---- end_global_changes(void) { if (--global_change_count > 0) ! // recursive return; if (!clip_did_set_selection) { *************** *** 947,954 **** clip_unnamed_saved = 0; if (clipboard_needs_update) { ! /* only store something in the clipboard, ! * if we have yanked anything to it */ if (clip_unnamed & CLIP_UNNAMED) { clip_own_selection(&clip_star); --- 946,953 ---- clip_unnamed_saved = 0; if (clipboard_needs_update) { ! // only store something in the clipboard, ! // if we have yanked anything to it if (clip_unnamed & CLIP_UNNAMED) { clip_own_selection(&clip_star); *************** *** 1036,1043 **** && (mod_mask & MOD_MASK_3CLICK)); if (is_click && button == MOUSE_RIGHT) { ! /* Right mouse button: If there was no selection, start one. ! * Otherwise extend the existing selection. */ if (clip_star.state == SELECT_CLEARED) clip_start_selection(mouse_col, mouse_row, FALSE); clip_process_selection(button, mouse_col, mouse_row, repeat); --- 1035,1042 ---- && (mod_mask & MOD_MASK_3CLICK)); if (is_click && button == MOUSE_RIGHT) { ! // Right mouse button: If there was no selection, start one. ! // Otherwise extend the existing selection. if (clip_star.state == SELECT_CLEARED) clip_start_selection(mouse_col, mouse_row, FALSE); clip_process_selection(button, mouse_col, mouse_row, repeat); *************** *** 1046,1057 **** clip_start_selection(mouse_col, mouse_row, repeat); else if (is_drag) { ! /* Don't try extending a selection if there isn't one. Happens when ! * button-down is in the cmdline and them moving mouse upwards. */ if (clip_star.state != SELECT_CLEARED) clip_process_selection(button, mouse_col, mouse_row, repeat); } ! else /* release */ clip_process_selection(MOUSE_RELEASE, mouse_col, mouse_row, FALSE); } --- 1045,1056 ---- clip_start_selection(mouse_col, mouse_row, repeat); else if (is_drag) { ! // Don't try extending a selection if there isn't one. Happens when ! // button-down is in the cmdline and them moving mouse upwards. if (clip_star.state != SELECT_CLEARED) clip_process_selection(button, mouse_col, mouse_row, repeat); } ! else // release clip_process_selection(MOUSE_RELEASE, mouse_col, mouse_row, FALSE); } *************** *** 1135,1141 **** cb->mode = SELECT_MODE_CHAR; #ifdef FEAT_GUI ! /* clear the cursor until the selection is made */ if (gui.in_use) gui_undraw_cursor(); #endif --- 1134,1140 ---- cb->mode = SELECT_MODE_CHAR; #ifdef FEAT_GUI ! // clear the cursor until the selection is made if (gui.in_use) gui_undraw_cursor(); #endif *************** *** 1265,1271 **** cb->mode = SELECT_MODE_CHAR; } ! /* set state, for when using the right mouse button */ cb->state = SELECT_IN_PROGRESS; #ifdef DEBUG_SELECTION --- 1264,1270 ---- cb->mode = SELECT_MODE_CHAR; } ! // set state, for when using the right mouse button cb->state = SELECT_IN_PROGRESS; #ifdef DEBUG_SELECTION *************** *** 1278,1288 **** switch (cb->mode) { case SELECT_MODE_CHAR: ! /* If we're on a different line, find where the line ends */ if (row != cb->prev.lnum) cb->word_end_col = clip_get_line_end(cb, row); ! /* See if we are before or after the origin of the selection */ if (clip_compare_pos(row, col, cb->origin_row, cb->origin_start_col) >= 0) { --- 1277,1287 ---- switch (cb->mode) { case SELECT_MODE_CHAR: ! // If we're on a different line, find where the line ends if (row != cb->prev.lnum) cb->word_end_col = clip_get_line_end(cb, row); ! // See if we are before or after the origin of the selection if (clip_compare_pos(row, col, cb->origin_row, cb->origin_start_col) >= 0) { *************** *** 1312,1326 **** break; case SELECT_MODE_WORD: ! /* If we are still within the same word, do nothing */ if (row == cb->prev.lnum && col >= (int)cb->word_start_col && col < (int)cb->word_end_col && !repeated_click) return; ! /* Get new word boundaries */ clip_get_word_boundaries(cb, row, col); ! /* Handle being after the origin point of selection */ if (clip_compare_pos(row, col, cb->origin_row, cb->origin_start_col) >= 0) clip_update_modeless_selection(cb, cb->origin_row, --- 1311,1325 ---- break; case SELECT_MODE_WORD: ! // If we are still within the same word, do nothing if (row == cb->prev.lnum && col >= (int)cb->word_start_col && col < (int)cb->word_end_col && !repeated_click) return; ! // Get new word boundaries clip_get_word_boundaries(cb, row, col); ! // Handle being after the origin point of selection if (clip_compare_pos(row, col, cb->origin_row, cb->origin_start_col) >= 0) clip_update_modeless_selection(cb, cb->origin_row, *************** *** 1411,1417 **** */ void clip_scroll_selection( ! int rows) /* negative for scroll down */ { int lnum; --- 1410,1416 ---- */ void clip_scroll_selection( ! int rows) // negative for scroll down { int lnum; *************** *** 1421,1433 **** lnum = clip_star.start.lnum - rows; if (lnum <= 0) clip_star.start.lnum = 0; ! else if (lnum >= screen_Rows) /* scrolled off of the screen */ clip_star.state = SELECT_CLEARED; else clip_star.start.lnum = lnum; lnum = clip_star.end.lnum - rows; ! if (lnum < 0) /* scrolled off of the screen */ clip_star.state = SELECT_CLEARED; else if (lnum >= screen_Rows) clip_star.end.lnum = screen_Rows - 1; --- 1420,1432 ---- lnum = clip_star.start.lnum - rows; if (lnum <= 0) clip_star.start.lnum = 0; ! else if (lnum >= screen_Rows) // scrolled off of the screen clip_star.state = SELECT_CLEARED; else clip_star.start.lnum = lnum; lnum = clip_star.end.lnum - rows; ! if (lnum < 0) // scrolled off of the screen clip_star.state = SELECT_CLEARED; else if (lnum >= screen_Rows) clip_star.end.lnum = screen_Rows - 1; *************** *** 1464,1470 **** if (how == CLIP_SET) invert = TRUE; ! /* Swap the from and to positions so the from is always before */ if (clip_compare_pos(row1, col1, row2, col2) > 0) { int tmp_row, tmp_col; --- 1463,1469 ---- if (how == CLIP_SET) invert = TRUE; ! // Swap the from and to positions so the from is always before if (clip_compare_pos(row1, col1, row2, col2) > 0) { int tmp_row, tmp_col; *************** *** 1479,1492 **** else if (how == CLIP_TOGGLE) invert = TRUE; ! /* If all on the same line, do it the easy way */ if (row1 == row2) { clip_invert_rectangle(cbd, row1, col1, 1, col2 - col1, invert); } else { ! /* Handle a piece of the first line */ if (col1 > 0) { clip_invert_rectangle(cbd, row1, col1, 1, --- 1478,1491 ---- else if (how == CLIP_TOGGLE) invert = TRUE; ! // If all on the same line, do it the easy way if (row1 == row2) { clip_invert_rectangle(cbd, row1, col1, 1, col2 - col1, invert); } else { ! // Handle a piece of the first line if (col1 > 0) { clip_invert_rectangle(cbd, row1, col1, 1, *************** *** 1494,1507 **** row1++; } ! /* Handle a piece of the last line */ if (col2 < max_col) { clip_invert_rectangle(cbd, row2, 0, 1, col2, invert); row2--; } ! /* Handle the rectangle thats left */ if (row2 >= row1) clip_invert_rectangle(cbd, row1, 0, row2 - row1 + 1, (int)Columns, invert); --- 1493,1506 ---- row1++; } ! // Handle a piece of the last line if (col2 < max_col) { clip_invert_rectangle(cbd, row2, 0, 1, col2, invert); row2--; } ! // Handle the rectangle thats left if (row2 >= row1) clip_invert_rectangle(cbd, row1, 0, row2 - row1 + 1, (int)Columns, invert); *************** *** 1578,1584 **** int row2 = clip_star.end.lnum; int col2 = clip_star.end.col; ! /* Can't use ScreenLines unless initialized */ if (ScreenLines == NULL) return; --- 1577,1583 ---- int row2 = clip_star.end.lnum; int col2 = clip_star.end.col; ! // Can't use ScreenLines unless initialized if (ScreenLines == NULL) return; *************** *** 1606,1629 **** if (row2 > clip_star.max_row) row2 = clip_star.max_row; #endif ! /* correct starting point for being on right halve of double-wide char */ p = ScreenLines + LineOffset[row1]; if (enc_dbcs != 0) col1 -= (*mb_head_off)(p, p + col1); else if (enc_utf8 && p[col1] == 0) --col1; ! /* Create a temporary buffer for storing the text */ len = (row2 - row1 + 1) * Columns + 1; if (enc_dbcs != 0) ! len *= 2; /* max. 2 bytes per display cell */ else if (enc_utf8) len *= MB_MAXBYTES; buffer = alloc(len); ! if (buffer == NULL) /* out of memory */ return; ! /* Process each row in the selection */ for (bufp = buffer, row = row1; row <= row2; row++) { if (row == row1) --- 1605,1628 ---- if (row2 > clip_star.max_row) row2 = clip_star.max_row; #endif ! // correct starting point for being on right halve of double-wide char p = ScreenLines + LineOffset[row1]; if (enc_dbcs != 0) col1 -= (*mb_head_off)(p, p + col1); else if (enc_utf8 && p[col1] == 0) --col1; ! // Create a temporary buffer for storing the text len = (row2 - row1 + 1) * Columns + 1; if (enc_dbcs != 0) ! len *= 2; // max. 2 bytes per display cell else if (enc_utf8) len *= MB_MAXBYTES; buffer = alloc(len); ! if (buffer == NULL) // out of memory return; ! // Process each row in the selection for (bufp = buffer, row = row1; row <= row2; row++) { if (row == row1) *************** *** 1646,1652 **** line_end_col = clip_get_line_end(&clip_star, row); ! /* See if we need to nuke some trailing whitespace */ if (end_col >= #ifdef FEAT_PROP_POPUP clip_star.max_col --- 1645,1651 ---- line_end_col = clip_get_line_end(&clip_star, row); ! // See if we need to nuke some trailing whitespace if (end_col >= #ifdef FEAT_PROP_POPUP clip_star.max_col *************** *** 1655,1671 **** #endif && (row < row2 || end_col > line_end_col)) { ! /* Get rid of trailing whitespace */ end_col = line_end_col; if (end_col < start_col) end_col = start_col; ! /* If the last line extended to the end, add an extra newline */ if (row == row2) add_newline_flag = TRUE; } ! /* If after the first row, we need to always add a newline */ if (row > row1 && !LineWraps[row - 1]) *bufp++ = NL; --- 1654,1670 ---- #endif && (row < row2 || end_col > line_end_col)) { ! // Get rid of trailing whitespace end_col = line_end_col; if (end_col < start_col) end_col = start_col; ! // If the last line extended to the end, add an extra newline if (row == row2) add_newline_flag = TRUE; } ! // If after the first row, we need to always add a newline if (row > row1 && !LineWraps[row - 1]) *bufp++ = NL; *************** *** 1680,1686 **** for (i = start_col; i < end_col; ++i) if (enc_dbcs == DBCS_JPNU && p[i] == 0x8e) { ! /* single-width double-byte char */ *bufp++ = 0x8e; *bufp++ = ScreenLines2[LineOffset[row] + i]; } --- 1679,1685 ---- for (i = start_col; i < end_col; ++i) if (enc_dbcs == DBCS_JPNU && p[i] == 0x8e) { ! // single-width double-byte char *bufp++ = 0x8e; *bufp++ = ScreenLines2[LineOffset[row] + i]; } *************** *** 1700,1707 **** off = LineOffset[row]; for (i = start_col; i < end_col; ++i) { ! /* The base character is either in ScreenLinesUC[] or ! * ScreenLines[]. */ if (ScreenLinesUC[off + i] == 0) *bufp++ = ScreenLines[off + i]; else --- 1699,1706 ---- off = LineOffset[row]; for (i = start_col; i < end_col; ++i) { ! // The base character is either in ScreenLinesUC[] or ! // ScreenLines[]. if (ScreenLinesUC[off + i] == 0) *bufp++ = ScreenLines[off + i]; else *************** *** 1709,1722 **** bufp += utf_char2bytes(ScreenLinesUC[off + i], bufp); for (ci = 0; ci < Screen_mco; ++ci) { ! /* Add a composing character. */ if (ScreenLinesC[ci][off + i] == 0) break; bufp += utf_char2bytes(ScreenLinesC[ci][off + i], bufp); } } ! /* Skip right halve of double-wide character. */ if (ScreenLines[off + i + 1] == 0) ++i; } --- 1708,1721 ---- bufp += utf_char2bytes(ScreenLinesUC[off + i], bufp); for (ci = 0; ci < Screen_mco; ++ci) { ! // Add a composing character. if (ScreenLinesC[ci][off + i] == 0) break; bufp += utf_char2bytes(ScreenLinesC[ci][off + i], bufp); } } ! // Skip right halve of double-wide character. if (ScreenLines[off + i + 1] == 0) ++i; } *************** *** 1730,1753 **** } } ! /* Add a newline at the end if the selection ended there */ if (add_newline_flag) *bufp++ = NL; ! /* First cleanup any old selection and become the owner. */ clip_free_selection(&clip_star); clip_own_selection(&clip_star); ! /* Yank the text into the '*' register. */ clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_star); ! /* Make the register contents available to the outside world. */ clip_gen_set_selection(&clip_star); #ifdef FEAT_X11 if (both) { ! /* Do the same for the '+' register. */ clip_free_selection(&clip_plus); clip_own_selection(&clip_plus); clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_plus); --- 1729,1752 ---- } } ! // Add a newline at the end if the selection ended there if (add_newline_flag) *bufp++ = NL; ! // First cleanup any old selection and become the owner. clip_free_selection(&clip_star); clip_own_selection(&clip_star); ! // Yank the text into the '*' register. clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_star); ! // Make the register contents available to the outside world. clip_gen_set_selection(&clip_star); #ifdef FEAT_X11 if (both) { ! // Do the same for the '+' register. clip_free_selection(&clip_plus); clip_own_selection(&clip_plus); clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_plus); *************** *** 1775,1781 **** return; p = ScreenLines + LineOffset[row]; ! /* Correct for starting in the right halve of a double-wide char */ if (enc_dbcs != 0) col -= dbcs_screen_head_off(p, p + col); else if (enc_utf8 && p[col] == 0) --- 1774,1780 ---- return; p = ScreenLines + LineOffset[row]; ! // Correct for starting in the right halve of a double-wide char if (enc_dbcs != 0) col -= dbcs_screen_head_off(p, p + col); else if (enc_utf8 && p[col] == 0) *************** *** 1837,1843 **** int row2, int col2) { ! /* See if we changed at the beginning of the selection */ if (row1 != cb->start.lnum || col1 != (int)cb->start.col) { clip_invert_area(cb, row1, col1, (int)cb->start.lnum, cb->start.col, --- 1836,1842 ---- int row2, int col2) { ! // See if we changed at the beginning of the selection if (row1 != cb->start.lnum || col1 != (int)cb->start.col) { clip_invert_area(cb, row1, col1, (int)cb->start.lnum, cb->start.col, *************** *** 1846,1852 **** cb->start.col = col1; } ! /* See if we changed at the end of the selection */ if (row2 != cb->end.lnum || col2 != (int)cb->end.col) { clip_invert_area(cb, (int)cb->end.lnum, cb->end.col, row2, col2, --- 1845,1851 ---- cb->start.col = col1; } ! // See if we changed at the end of the selection if (row2 != cb->end.lnum || col2 != (int)cb->end.col) { clip_invert_area(cb, (int)cb->end.lnum, cb->end.col, row2, col2, *************** *** 1891,1898 **** { if (!clip_did_set_selection) { ! /* Updating postponed, so that accessing the system clipboard won't ! * hang Vim when accessing it many times (e.g. on a :g command). */ if ((cbd == &clip_plus && (clip_unnamed_saved & CLIP_UNNAMED_PLUS)) || (cbd == &clip_star && (clip_unnamed_saved & CLIP_UNNAMED))) { --- 1890,1897 ---- { if (!clip_did_set_selection) { ! // Updating postponed, so that accessing the system clipboard won't ! // hang Vim when accessing it many times (e.g. on a :g command). if ((cbd == &clip_plus && (clip_unnamed_saved & CLIP_UNNAMED_PLUS)) || (cbd == &clip_star && (clip_unnamed_saved & CLIP_UNNAMED))) { *************** *** 2037,2053 **** #endif // FEAT_CLIPBOARD ! /***************************************************************************** ! * Functions that handle the input buffer. ! * This is used for any GUI version, and the unix terminal version. ! * ! * For Unix, the input characters are buffered to be able to check for a ! * CTRL-C. This should be done with signals, but I don't know how to do that ! * in a portable way for a tty in RAW mode. ! * ! * For the client-server code in the console the received keys are put in the ! * input buffer. ! */ #if defined(USE_INPUT_BUF) || defined(PROTO) --- 2036,2051 ---- #endif // FEAT_CLIPBOARD ! ////////////////////////////////////////////////////////////////////////////// ! // Functions that handle the input buffer. ! // This is used for any GUI version, and the unix terminal version. ! // ! // For Unix, the input characters are buffered to be able to check for a ! // CTRL-C. This should be done with signals, but I don't know how to do that ! // in a portable way for a tty in RAW mode. ! // ! // For the client-server code in the console the received keys are put in the ! // input buffer. #if defined(USE_INPUT_BUF) || defined(PROTO) *************** *** 2068,2074 **** #endif static char_u inbuf[INBUFLEN + MAX_KEY_CODE_LEN]; ! static int inbufcount = 0; /* number of chars in inbuf[] */ /* * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and --- 2066,2072 ---- #endif static char_u inbuf[INBUFLEN + MAX_KEY_CODE_LEN]; ! static int inbufcount = 0; // number of chars in inbuf[] /* * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and *************** *** 2113,2123 **** { garray_T *gap; ! /* We use a growarray to store the data pointer and the length. */ gap = ALLOC_ONE(garray_T); if (gap != NULL) { ! /* Add one to avoid a zero size. */ gap->ga_data = alloc(inbufcount + 1); if (gap->ga_data != NULL) mch_memmove(gap->ga_data, inbuf, (size_t)inbufcount); --- 2111,2121 ---- { garray_T *gap; ! // We use a growarray to store the data pointer and the length. gap = ALLOC_ONE(garray_T); if (gap != NULL) { ! // Add one to avoid a zero size. gap->ga_data = alloc(inbufcount + 1); if (gap->ga_data != NULL) mch_memmove(gap->ga_data, inbuf, (size_t)inbufcount); *************** *** 2157,2163 **** add_to_input_buf(char_u *s, int len) { if (inbufcount + len > INBUFLEN + MAX_KEY_CODE_LEN) ! return; /* Shouldn't ever happen! */ while (len--) inbuf[inbufcount++] = *s++; --- 2155,2161 ---- add_to_input_buf(char_u *s, int len) { if (inbufcount + len > INBUFLEN + MAX_KEY_CODE_LEN) ! return; // Shouldn't ever happen! while (len--) inbuf[inbufcount++] = *s++; *************** *** 2177,2183 **** add_to_input_buf(str + i, 1); if (str[i] == CSI) { ! /* Turn CSI into K_CSI. */ buf[0] = KS_EXTRA; buf[1] = (int)KE_CSI; add_to_input_buf(buf, 2); --- 2175,2181 ---- add_to_input_buf(str + i, 1); if (str[i] == CSI) { ! // Turn CSI into K_CSI. buf[0] = KS_EXTRA; buf[1] = (int)KE_CSI; add_to_input_buf(buf, 2); *************** *** 2185,2191 **** } } ! /* Remove everything from the input buffer. Called when ^C is found */ void trash_input_buf(void) { --- 2183,2191 ---- } } ! /* ! * Remove everything from the input buffer. Called when ^C is found. ! */ void trash_input_buf(void) { *************** *** 2199,2205 **** int read_from_input_buf(char_u *buf, long maxlen) { ! if (inbufcount == 0) /* if the buffer is empty, fill it */ fill_input_buf(TRUE); if (maxlen > inbufcount) maxlen = inbufcount; --- 2199,2205 ---- int read_from_input_buf(char_u *buf, long maxlen) { ! if (inbufcount == 0) // if the buffer is empty, fill it fill_input_buf(TRUE); if (maxlen > inbufcount) maxlen = inbufcount; *************** *** 2217,2223 **** int len; int try; static int did_read_something = FALSE; ! static char_u *rest = NULL; /* unconverted rest of previous read */ static int restlen = 0; int unconverted; #endif --- 2217,2223 ---- int len; int try; static int did_read_something = FALSE; ! static char_u *rest = NULL; // unconverted rest of previous read static int restlen = 0; int unconverted; #endif *************** *** 2225,2232 **** #ifdef FEAT_GUI if (gui.in_use # ifdef NO_CONSOLE_INPUT ! /* Don't use the GUI input when the window hasn't been opened yet. ! * We get here from ui_inchar() when we should try reading from stdin. */ && !no_console_input() # endif ) --- 2225,2232 ---- #ifdef FEAT_GUI if (gui.in_use # ifdef NO_CONSOLE_INPUT ! // Don't use the GUI input when the window hasn't been opened yet. ! // We get here from ui_inchar() when we should try reading from stdin. && !no_console_input() # endif ) *************** *** 2257,2264 **** if (rest != NULL) { ! /* Use remainder of previous call, starts with an invalid character ! * that may become valid when reading more. */ if (restlen > INBUFLEN - inbufcount) unconverted = INBUFLEN - inbufcount; else --- 2257,2264 ---- if (rest != NULL) { ! // Use remainder of previous call, starts with an invalid character ! // that may become valid when reading more. if (restlen > INBUFLEN - inbufcount) unconverted = INBUFLEN - inbufcount; else *************** *** 2276,2282 **** else unconverted = 0; ! len = 0; /* to avoid gcc warning */ for (try = 0; try < 100; ++try) { size_t readlen = (size_t)((INBUFLEN - inbufcount) --- 2276,2282 ---- else unconverted = 0; ! len = 0; // to avoid gcc warning for (try = 0; try < 100; ++try) { size_t readlen = (size_t)((INBUFLEN - inbufcount) *************** *** 2297,2312 **** { int m = cur_tmode; ! /* We probably set the wrong file descriptor to raw mode. Switch ! * back to cooked mode, use another descriptor and set the mode to ! * what it was. */ settmode(TMODE_COOK); #ifdef HAVE_DUP ! /* Use stderr for stdin, also works for shell commands. */ close(0); vim_ignored = dup(2); #else ! read_cmd_fd = 2; /* read from stderr instead of stdin */ #endif settmode(m); } --- 2297,2312 ---- { int m = cur_tmode; ! // We probably set the wrong file descriptor to raw mode. Switch ! // back to cooked mode, use another descriptor and set the mode to ! // what it was. settmode(TMODE_COOK); #ifdef HAVE_DUP ! // Use stderr for stdin, also works for shell commands. close(0); vim_ignored = dup(2); #else ! read_cmd_fd = 2; // read from stderr instead of stdin #endif settmode(m); } *************** *** 2320,2326 **** did_read_something = TRUE; if (got_int) { ! /* Interrupted, pretend a CTRL-C was typed. */ inbuf[0] = 3; inbufcount = 1; } --- 2320,2326 ---- did_read_something = TRUE; if (got_int) { ! // Interrupted, pretend a CTRL-C was typed. inbuf[0] = 3; inbufcount = 1; } *************** *** 2348,2354 **** */ if (inbuf[inbufcount] == 3 && ctrl_c_interrupts) { ! /* remove everything typed before the CTRL-C */ mch_memmove(inbuf, inbuf + inbufcount, (size_t)(len + 1)); inbufcount = 0; got_int = TRUE; --- 2348,2354 ---- */ if (inbuf[inbufcount] == 3 && ctrl_c_interrupts) { ! // remove everything typed before the CTRL-C mch_memmove(inbuf, inbuf + inbufcount, (size_t)(len + 1)); inbufcount = 0; got_int = TRUE; *************** *** 2356,2364 **** ++inbufcount; } } ! #endif /* UNIX or VMS*/ } ! #endif /* defined(UNIX) || defined(FEAT_GUI) || defined(VMS) */ /* * Exit because of an input read error. --- 2356,2364 ---- ++inbufcount; } } ! #endif // UNIX or VMS } ! #endif // defined(UNIX) || defined(FEAT_GUI) || defined(VMS) /* * Exit because of an input read error. *************** *** 2366,2372 **** void read_error_exit(void) { ! if (silent_mode) /* Normal way to exit for "ex -s" */ getout(0); STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); preserve_exit(); --- 2366,2372 ---- void read_error_exit(void) { ! if (silent_mode) // Normal way to exit for "ex -s" getout(0); STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); preserve_exit(); *************** *** 2450,2462 **** } } ! static Atom vim_atom; /* Vim's own special selection format */ ! static Atom vimenc_atom; /* Vim's extended selection format */ static Atom utf8_atom; static Atom compound_text_atom; static Atom text_atom; static Atom targets_atom; ! static Atom timestamp_atom; /* Used to get a timestamp */ void x11_setup_atoms(Display *dpy) --- 2450,2462 ---- } } ! static Atom vim_atom; // Vim's own special selection format ! static Atom vimenc_atom; // Vim's extended selection format static Atom utf8_atom; static Atom compound_text_atom; static Atom text_atom; static Atom targets_atom; ! static Atom timestamp_atom; // Used to get a timestamp void x11_setup_atoms(Display *dpy) *************** *** 2496,2503 **** unsigned char *prop=NULL; XPropertyEvent *xproperty=&event->xproperty; ! /* Must be a property notify, state can't be Delete (True), has to be ! * one of the supported selection types. */ if (event->type != PropertyNotify || xproperty->state || (xproperty->atom != clip_star.sel_atom && xproperty->atom != clip_plus.sel_atom)) --- 2496,2503 ---- unsigned char *prop=NULL; XPropertyEvent *xproperty=&event->xproperty; ! // Must be a property notify, state can't be Delete (True), has to be ! // one of the supported selection types. if (event->type != PropertyNotify || xproperty->state || (xproperty->atom != clip_star.sel_atom && xproperty->atom != clip_plus.sel_atom)) *************** *** 2511,2527 **** if (prop) XFree(prop); ! /* Make sure the property type is "TIMESTAMP" and it's 32 bits. */ if (actual_type != timestamp_atom || format != 32) return; ! /* Get the selection, using the event timestamp. */ if (XtOwnSelection(w, xproperty->atom, xproperty->time, clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, clip_x11_notify_cb) == OK) { ! /* Set the "owned" flag now, there may have been a call to ! * lose_ownership_cb in between. */ if (xproperty->atom == clip_plus.sel_atom) clip_plus.owned = TRUE; else --- 2511,2527 ---- if (prop) XFree(prop); ! // Make sure the property type is "TIMESTAMP" and it's 32 bits. if (actual_type != timestamp_atom || format != 32) return; ! // Get the selection, using the event timestamp. if (XtOwnSelection(w, xproperty->atom, xproperty->time, clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, clip_x11_notify_cb) == OK) { ! // Set the "owned" flag now, there may have been a call to ! // lose_ownership_cb in between. if (xproperty->atom == clip_plus.sel_atom) clip_plus.owned = TRUE; else *************** *** 2560,2566 **** if (value == NULL || *length == 0) { ! clip_free_selection(cbd); /* nothing received, clear register */ *(int *)success = FALSE; return; } --- 2560,2566 ---- if (value == NULL || *length == 0) { ! clip_free_selection(cbd); // nothing received, clear register *(int *)success = FALSE; return; } *************** *** 2585,2597 **** p += STRLEN(p) + 1; len -= p - enc; ! /* If the encoding of the text is different from 'encoding', attempt ! * converting it. */ conv.vc_type = CONV_NONE; convert_setup(&conv, enc, p_enc); if (conv.vc_type != CONV_NONE) { ! convlen = len; /* Need to use an int here. */ tmpbuf = string_convert(&conv, p, &convlen); len = convlen; if (tmpbuf != NULL) --- 2585,2597 ---- p += STRLEN(p) + 1; len -= p - enc; ! // If the encoding of the text is different from 'encoding', attempt ! // converting it. conv.vc_type = CONV_NONE; convert_setup(&conv, enc, p_enc); if (conv.vc_type != CONV_NONE) { ! convlen = len; // Need to use an int here. tmpbuf = string_convert(&conv, p, &convlen); len = convlen; if (tmpbuf != NULL) *************** *** 2666,2680 **** && !enc_utf8 # endif ) ! /* Only request utf-8 when 'encoding' is utf8 and ! * Xutf8TextPropertyToTextList is available. */ continue; success = MAYBE; XtGetSelectionValue(myShell, cbd->sel_atom, type, clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); ! /* Make sure the request for the selection goes out before waiting for ! * a response. */ XFlush(dpy); /* --- 2666,2680 ---- && !enc_utf8 # endif ) ! // Only request utf-8 when 'encoding' is utf8 and ! // Xutf8TextPropertyToTextList is available. continue; success = MAYBE; XtGetSelectionValue(myShell, cbd->sel_atom, type, clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); ! // Make sure the request for the selection goes out before waiting for ! // a response. XFlush(dpy); /* *************** *** 2689,2732 **** || XCheckTypedEvent(dpy, SelectionNotify, &event) || XCheckTypedEvent(dpy, SelectionRequest, &event)) { ! /* This is where clip_x11_request_selection_cb() should be ! * called. It may actually happen a bit later, so we loop ! * until "success" changes. ! * We may get a SelectionRequest here and if we don't handle ! * it we hang. KDE klipper does this, for example. ! * We need to handle a PropertyNotify for large selections. */ XtDispatchEvent(&event); continue; } ! /* Time out after 2 to 3 seconds to avoid that we hang when the ! * other process doesn't respond. Note that the SelectionNotify ! * event may still come later when the selection owner comes back ! * to life and the text gets inserted unexpectedly. Don't know ! * why that happens or how to avoid that :-(. */ if (time(NULL) > start_time + 2) { timed_out = TRUE; break; } ! /* Do we need this? Probably not. */ XSync(dpy, False); ! /* Wait for 1 msec to avoid that we eat up all CPU time. */ ui_delay(1L, TRUE); } if (success == TRUE) return; ! /* don't do a retry with another type after timing out, otherwise we ! * hang for 15 seconds. */ if (timed_out) break; } ! /* Final fallback position - use the X CUT_BUFFER0 store */ yank_cut_buffer0(dpy, cbd); } --- 2689,2732 ---- || XCheckTypedEvent(dpy, SelectionNotify, &event) || XCheckTypedEvent(dpy, SelectionRequest, &event)) { ! // This is where clip_x11_request_selection_cb() should be ! // called. It may actually happen a bit later, so we loop ! // until "success" changes. ! // We may get a SelectionRequest here and if we don't handle ! // it we hang. KDE klipper does this, for example. ! // We need to handle a PropertyNotify for large selections. XtDispatchEvent(&event); continue; } ! // Time out after 2 to 3 seconds to avoid that we hang when the ! // other process doesn't respond. Note that the SelectionNotify ! // event may still come later when the selection owner comes back ! // to life and the text gets inserted unexpectedly. Don't know ! // why that happens or how to avoid that :-(. if (time(NULL) > start_time + 2) { timed_out = TRUE; break; } ! // Do we need this? Probably not. XSync(dpy, False); ! // Wait for 1 msec to avoid that we eat up all CPU time. ui_delay(1L, TRUE); } if (success == TRUE) return; ! // don't do a retry with another type after timing out, otherwise we ! // hang for 15 seconds. if (timed_out) break; } ! // Final fallback position - use the X CUT_BUFFER0 store yank_cut_buffer0(dpy, cbd); } *************** *** 2753,2761 **** cbd = &clip_star; if (!cbd->owned) ! return False; /* Shouldn't ever happen */ ! /* requestor wants to know what target types we support */ if (*target == targets_atom) { static Atom array[7]; --- 2753,2761 ---- cbd = &clip_star; if (!cbd->owned) ! return False; // Shouldn't ever happen ! // requestor wants to know what target types we support if (*target == targets_atom) { static Atom array[7]; *************** *** 2772,2779 **** array[i++] = compound_text_atom; *type = XA_ATOM; ! /* This used to be: *format = sizeof(Atom) * 8; but that caused ! * crashes on 64 bit machines. (Peter Derr) */ *format = 32; *length = i; return True; --- 2772,2779 ---- array[i++] = compound_text_atom; *type = XA_ATOM; ! // This used to be: *format = sizeof(Atom) * 8; but that caused ! // crashes on 64 bit machines. (Peter Derr) *format = 32; *length = i; return True; *************** *** 2792,2802 **** if (motion_type < 0) return False; ! /* For our own format, the first byte contains the motion type */ if (*target == vim_atom) (*length)++; ! /* Our own format with encoding: motion 'encoding' NUL text */ if (*target == vimenc_atom) *length += STRLEN(p_enc) + 2; --- 2792,2802 ---- if (motion_type < 0) return False; ! // For our own format, the first byte contains the motion type if (*target == vim_atom) (*length)++; ! // Our own format with encoding: motion 'encoding' NUL text if (*target == vimenc_atom) *length += STRLEN(p_enc) + 2; *************** *** 2823,2829 **** char *string_nt = (char *)save_result; int conv_result; ! /* create NUL terminated string which XmbTextListToTextProperty wants */ mch_memmove(string_nt, string, (size_t)*length); string_nt[*length] = NUL; conv_result = XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, --- 2823,2829 ---- char *string_nt = (char *)save_result; int conv_result; ! // create NUL terminated string which XmbTextListToTextProperty wants mch_memmove(string_nt, string, (size_t)*length); string_nt[*length] = NUL; conv_result = XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, *************** *** 2833,2839 **** vim_free(string); return False; } ! *value = (XtPointer)(text_prop.value); /* from plain text */ *length = text_prop.nitems; *type = compound_text_atom; XtFree((char *)save_result); --- 2833,2839 ---- vim_free(string); return False; } ! *value = (XtPointer)(text_prop.value); // from plain text *length = text_prop.nitems; *type = compound_text_atom; XtFree((char *)save_result); *************** *** 2855,2861 **** mch_memmove(save_result + 1, string, (size_t)(*length - 1)); *type = vim_atom; } ! *format = 8; /* 8 bits per char */ vim_free(string); return True; } --- 2855,2861 ---- mch_memmove(save_result + 1, string, (size_t)(*length - 1)); *type = vim_atom; } ! *format = 8; // 8 bits per char vim_free(string); return True; } *************** *** 2879,2894 **** static void clip_x11_notify_cb(Widget w UNUSED, Atom *sel_atom UNUSED, Atom *target UNUSED) { ! /* To prevent automatically freeing the selection value. */ } int clip_x11_own_selection(Widget myShell, Clipboard_T *cbd) { ! /* When using the GUI we have proper timestamps, use the one of the last ! * event. When in the console we don't get events (the terminal gets ! * them), Get the time by a zero-length append, clip_x11_timestamp_cb will ! * be called with the current timestamp. */ #ifdef FEAT_GUI if (gui.in_use) { --- 2879,2894 ---- static void clip_x11_notify_cb(Widget w UNUSED, Atom *sel_atom UNUSED, Atom *target UNUSED) { ! // To prevent automatically freeing the selection value. } int clip_x11_own_selection(Widget myShell, Clipboard_T *cbd) { ! // When using the GUI we have proper timestamps, use the one of the last ! // event. When in the console we don't get events (the terminal gets ! // them), Get the time by a zero-length append, clip_x11_timestamp_cb will ! // be called with the current timestamp. #ifdef FEAT_GUI if (gui.in_use) { *************** *** 2905,2911 **** cbd->sel_atom, timestamp_atom, 32, PropModeAppend, NULL, 0)) return FAIL; } ! /* Flush is required in a terminal as nothing else is doing it. */ XFlush(XtDisplay(myShell)); return OK; } --- 2905,2911 ---- cbd->sel_atom, timestamp_atom, 32, PropModeAppend, NULL, 0)) return FAIL; } ! // Flush is required in a terminal as nothing else is doing it. XFlush(XtDisplay(myShell)); return OK; } *************** *** 2944,2953 **** { int done = FALSE; ! /* CUT_BUFFER0 is supposed to be always latin1. Convert to 'enc' when ! * using a multi-byte encoding. Conversion between two 8-bit ! * character sets usually fails and the text might actually be in ! * 'enc' anyway. */ if (has_mbyte) { char_u *conv_buf; --- 2944,2953 ---- { int done = FALSE; ! // CUT_BUFFER0 is supposed to be always latin1. Convert to 'enc' when ! // using a multi-byte encoding. Conversion between two 8-bit ! // character sets usually fails and the text might actually be in ! // 'enc' anyway. if (has_mbyte) { char_u *conv_buf; *************** *** 2966,2972 **** convert_setup(&vc, NULL, NULL); } } ! if (!done) /* use the text without conversion */ clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd); XFree((void *)buffer); if (p_verbose > 0) --- 2966,2972 ---- convert_setup(&vc, NULL, NULL); } } ! if (!done) // use the text without conversion clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd); XFree((void *)buffer); if (p_verbose > 0) *************** *** 2986,2999 **** */ void ui_focus_change( ! int in_focus) /* TRUE if focus gained. */ { static time_t last_time = (time_t)0; int need_redraw = FALSE; ! /* When activated: Check if any file was modified outside of Vim. ! * Only do this when not done within the last two seconds (could get ! * several events in a row). */ if (in_focus && last_time + 2 < time(NULL)) { need_redraw = check_timestamps( --- 2986,2999 ---- */ void ui_focus_change( ! int in_focus) // TRUE if focus gained. { static time_t last_time = (time_t)0; int need_redraw = FALSE; ! // When activated: Check if any file was modified outside of Vim. ! // Only do this when not done within the last two seconds (could get ! // several events in a row). if (in_focus && last_time + 2 < time(NULL)) { need_redraw = check_timestamps( *************** *** 3014,3021 **** if (need_redraw) { ! /* Something was executed, make sure the cursor is put back where it ! * belongs. */ need_wait_return = FALSE; if (State & CMDLINE) --- 3014,3021 ---- if (need_redraw) { ! // Something was executed, make sure the cursor is put back where it ! // belongs. need_wait_return = FALSE; if (State & CMDLINE) *************** *** 3029,3035 **** update_screen(0); setcursor(); } ! cursor_on(); /* redrawing may have switched it off */ out_flush_cursor(FALSE, TRUE); # ifdef FEAT_GUI if (gui.in_use) --- 3029,3035 ---- update_screen(0); setcursor(); } ! cursor_on(); // redrawing may have switched it off out_flush_cursor(FALSE, TRUE); # ifdef FEAT_GUI if (gui.in_use) *************** *** 3037,3043 **** # endif } #ifdef FEAT_TITLE ! /* File may have been changed from 'readonly' to 'noreadonly' */ if (need_maketitle) maketitle(); #endif --- 3037,3043 ---- # endif } #ifdef FEAT_TITLE ! // File may have been changed from 'readonly' to 'noreadonly' if (need_maketitle) maketitle(); #endif *************** *** 3051,3063 **** void im_save_status(long *psave) { ! /* Don't save when 'imdisable' is set or "xic" is NULL, IM is always ! * disabled then (but might start later). ! * Also don't save when inside a mapping, vgetc_im_active has not been set ! * then. ! * And don't save when the keys were stuffed (e.g., for a "." command). ! * And don't save when the GUI is running but our window doesn't have ! * input focus (e.g., when a find dialog is open). */ if (!p_imdisable && KeyTyped && !KeyStuffed # ifdef FEAT_XIM && xic != NULL --- 3051,3063 ---- void im_save_status(long *psave) { ! // Don't save when 'imdisable' is set or "xic" is NULL, IM is always ! // disabled then (but might start later). ! // Also don't save when inside a mapping, vgetc_im_active has not been set ! // then. ! // And don't save when the keys were stuffed (e.g., for a "." command). ! // And don't save when the GUI is running but our window doesn't have ! // input focus (e.g., when a find dialog is open). if (!p_imdisable && KeyTyped && !KeyStuffed # ifdef FEAT_XIM && xic != NULL *************** *** 3067,3073 **** # endif ) { ! /* Do save when IM is on, or IM is off and saved status is on. */ if (vgetc_im_active) *psave = B_IMODE_IM; else if (*psave == B_IMODE_IM) --- 3067,3073 ---- # endif ) { ! // Do save when IM is on, or IM is off and saved status is on. if (vgetc_im_active) *psave = B_IMODE_IM; else if (*psave == B_IMODE_IM) *** ../vim-8.1.2395/src/undo.c 2019-11-02 22:54:37.409188799 +0100 --- src/undo.c 2019-12-05 21:40:57.789261222 +0100 *************** *** 75,101 **** * All data is allocated and will all be freed when the buffer is unloaded. */ ! /* Uncomment the next line for including the u_check() function. This warns ! * for errors in the debug information. */ ! /* #define U_DEBUG 1 */ ! #define UH_MAGIC 0x18dade /* value for uh_magic when in use */ ! #define UE_MAGIC 0xabc123 /* value for ue_magic when in use */ ! /* Size of buffer used for encryption. */ #define CRYPT_BUF_SIZE 8192 #include "vim.h" ! /* Structure passed around between functions. ! * Avoids passing cryptstate_T when encryption not available. */ typedef struct { buf_T *bi_buf; FILE *bi_fp; #ifdef FEAT_CRYPT cryptstate_T *bi_state; ! char_u *bi_buffer; /* CRYPT_BUF_SIZE, NULL when not buffering */ ! size_t bi_used; /* bytes written to/read from bi_buffer */ ! size_t bi_avail; /* bytes available in bi_buffer */ #endif } bufinfo_T; --- 75,101 ---- * All data is allocated and will all be freed when the buffer is unloaded. */ ! // Uncomment the next line for including the u_check() function. This warns ! // for errors in the debug information. ! // #define U_DEBUG 1 ! #define UH_MAGIC 0x18dade // value for uh_magic when in use ! #define UE_MAGIC 0xabc123 // value for ue_magic when in use ! // Size of buffer used for encryption. #define CRYPT_BUF_SIZE 8192 #include "vim.h" ! // Structure passed around between functions. ! // Avoids passing cryptstate_T when encryption not available. typedef struct { buf_T *bi_buf; FILE *bi_fp; #ifdef FEAT_CRYPT cryptstate_T *bi_state; ! char_u *bi_buffer; // CRYPT_BUF_SIZE, NULL when not buffering ! size_t bi_used; // bytes written to/read from bi_buffer ! size_t bi_avail; // bytes available in bi_buffer #endif } bufinfo_T; *************** *** 126,132 **** #define U_ALLOC_LINE(size) lalloc(size, FALSE) ! /* used in undo_end() to report number of added and deleted lines */ static long u_newcount, u_oldcount; /* --- 126,132 ---- #define U_ALLOC_LINE(size) lalloc(size, FALSE) ! // used in undo_end() to report number of added and deleted lines static long u_newcount, u_oldcount; /* *************** *** 171,177 **** emsg("uh_magic wrong (may be using freed memory)"); else { ! /* Check pointers back are correct. */ if (uhp->uh_next.ptr != exp_uh_next) { emsg("uh_next wrong"); --- 171,177 ---- emsg("uh_magic wrong (may be using freed memory)"); else { ! // Check pointers back are correct. if (uhp->uh_next.ptr != exp_uh_next) { emsg("uh_next wrong"); *************** *** 185,191 **** exp_uh_alt_prev, uhp->uh_alt_prev.ptr); } ! /* Check the undo tree at this header. */ for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next) { if (uep->ue_magic != UE_MAGIC) --- 185,191 ---- exp_uh_alt_prev, uhp->uh_alt_prev.ptr); } ! // Check the undo tree at this header. for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next) { if (uep->ue_magic != UE_MAGIC) *************** *** 195,204 **** } } ! /* Check the next alt tree. */ u_check_tree(uhp->uh_alt_next.ptr, uhp->uh_next.ptr, uhp); ! /* Check the next header in this branch. */ u_check_tree(uhp->uh_prev.ptr, uhp, NULL); } } --- 195,204 ---- } } ! // Check the next alt tree. u_check_tree(uhp->uh_alt_next.ptr, uhp->uh_next.ptr, uhp); ! // Check the next header in this branch. u_check_tree(uhp->uh_prev.ptr, uhp, NULL); } } *************** *** 313,319 **** int undo_allowed(void) { ! /* Don't allow changes when 'modifiable' is off. */ if (!curbuf->b_p_ma) { emsg(_(e_modifiable)); --- 313,319 ---- int undo_allowed(void) { ! // Don't allow changes when 'modifiable' is off. if (!curbuf->b_p_ma) { emsg(_(e_modifiable)); *************** *** 321,327 **** } #ifdef HAVE_SANDBOX ! /* In the sandbox it's not allowed to change the text. */ if (sandbox != 0) { emsg(_(e_sandbox)); --- 321,327 ---- } #ifdef HAVE_SANDBOX ! // In the sandbox it's not allowed to change the text. if (sandbox != 0) { emsg(_(e_sandbox)); *************** *** 329,336 **** } #endif ! /* Don't allow changes in the buffer while editing the cmdline. The ! * caller of getcmdline() may get confused. */ if (textlock != 0) { emsg(_(e_secure)); --- 329,336 ---- } #endif ! // Don't allow changes in the buffer while editing the cmdline. The ! // caller of getcmdline() may get confused. if (textlock != 0) { emsg(_(e_secure)); *************** *** 401,408 **** if (!reload) { ! /* When making changes is not allowed return FAIL. It's a crude way ! * to make all change commands fail. */ if (!undo_allowed()) return FAIL; --- 401,408 ---- if (!reload) { ! // When making changes is not allowed return FAIL. It's a crude way ! // to make all change commands fail. if (!undo_allowed()) return FAIL; *************** *** 426,432 **** } #endif #ifdef FEAT_TERMINAL ! /* A change in a terminal buffer removes the highlighting. */ term_change_in_curbuf(); #endif --- 426,432 ---- } #endif #ifdef FEAT_TERMINAL ! // A change in a terminal buffer removes the highlighting. term_change_in_curbuf(); #endif *************** *** 439,446 **** change_warning(0); if (bot > curbuf->b_ml.ml_line_count + 1) { ! /* This happens when the FileChangedRO autocommand changes the ! * file in a way it becomes shorter. */ emsg(_("E881: Line count changed unexpectedly")); return FAIL; } --- 439,446 ---- change_warning(0); if (bot > curbuf->b_ml.ml_line_count + 1) { ! // This happens when the FileChangedRO autocommand changes the ! // file in a way it becomes shorter. emsg(_("E881: Line count changed unexpectedly")); return FAIL; } *************** *** 458,464 **** if (curbuf->b_u_synced) { #ifdef FEAT_JUMPLIST ! /* Need to create new entry in b_changelist. */ curbuf->b_new_change = TRUE; #endif --- 458,464 ---- if (curbuf->b_u_synced) { #ifdef FEAT_JUMPLIST ! // Need to create new entry in b_changelist. curbuf->b_new_change = TRUE; #endif *************** *** 498,511 **** u_header_T *uhfree = curbuf->b_u_oldhead; if (uhfree == old_curhead) ! /* Can't reconnect the branch, delete all of it. */ u_freebranch(curbuf, uhfree, &old_curhead); else if (uhfree->uh_alt_next.ptr == NULL) ! /* There is no branch, only free one header. */ u_freeheader(curbuf, uhfree, &old_curhead); else { ! /* Free the oldest alternate branch as a whole. */ while (uhfree->uh_alt_next.ptr != NULL) uhfree = uhfree->uh_alt_next.ptr; u_freebranch(curbuf, uhfree, &old_curhead); --- 498,511 ---- u_header_T *uhfree = curbuf->b_u_oldhead; if (uhfree == old_curhead) ! // Can't reconnect the branch, delete all of it. u_freebranch(curbuf, uhfree, &old_curhead); else if (uhfree->uh_alt_next.ptr == NULL) ! // There is no branch, only free one header. u_freeheader(curbuf, uhfree, &old_curhead); else { ! // Free the oldest alternate branch as a whole. while (uhfree->uh_alt_next.ptr != NULL) uhfree = uhfree->uh_alt_next.ptr; u_freebranch(curbuf, uhfree, &old_curhead); *************** *** 515,521 **** #endif } ! if (uhp == NULL) /* no undo at all */ { if (old_curhead != NULL) u_freebranch(curbuf, old_curhead, NULL); --- 515,521 ---- #endif } ! if (uhp == NULL) // no undo at all { if (old_curhead != NULL) u_freebranch(curbuf, old_curhead, NULL); *************** *** 549,565 **** uhp->uh_walk = 0; uhp->uh_entry = NULL; uhp->uh_getbot_entry = NULL; ! uhp->uh_cursor = curwin->w_cursor; /* save cursor pos. for undo */ if (virtual_active() && curwin->w_cursor.coladd > 0) uhp->uh_cursor_vcol = getviscol(); else uhp->uh_cursor_vcol = -1; ! /* save changed and buffer empty flag for undo */ uhp->uh_flags = (curbuf->b_changed ? UH_CHANGED : 0) + ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0); ! /* save named marks and Visual marks for undo */ mch_memmove(uhp->uh_namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS); uhp->uh_visual = curbuf->b_visual; --- 549,565 ---- uhp->uh_walk = 0; uhp->uh_entry = NULL; uhp->uh_getbot_entry = NULL; ! uhp->uh_cursor = curwin->w_cursor; // save cursor pos. for undo if (virtual_active() && curwin->w_cursor.coladd > 0) uhp->uh_cursor_vcol = getviscol(); else uhp->uh_cursor_vcol = -1; ! // save changed and buffer empty flag for undo uhp->uh_flags = (curbuf->b_changed ? UH_CHANGED : 0) + ((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0); ! // save named marks and Visual marks for undo mch_memmove(uhp->uh_namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS); uhp->uh_visual = curbuf->b_visual; *************** *** 570,576 **** } else { ! if (get_undolevel() < 0) /* no undo at all */ return OK; /* --- 570,576 ---- } else { ! if (get_undolevel() < 0) // no undo at all return OK; /* *************** *** 591,598 **** if (uep == NULL) break; ! /* If lines have been inserted/deleted we give up. ! * Also when the line was included in a multi-line save. */ if ((curbuf->b_u_newhead->uh_getbot_entry != uep ? (uep->ue_top + uep->ue_size + 1 != (uep->ue_bot == 0 --- 591,598 ---- if (uep == NULL) break; ! // If lines have been inserted/deleted we give up. ! // Also when the line was included in a multi-line save. if ((curbuf->b_u_newhead->uh_getbot_entry != uep ? (uep->ue_top + uep->ue_size + 1 != (uep->ue_bot == 0 *************** *** 604,632 **** && top + 2 <= uep->ue_top + uep->ue_size + 1)) break; ! /* If it's the same line we can skip saving it again. */ if (uep->ue_size == 1 && uep->ue_top == top) { if (i > 0) { ! /* It's not the last entry: get ue_bot for the last ! * entry now. Following deleted/inserted lines go to ! * the re-used entry. */ u_getbot(); curbuf->b_u_synced = FALSE; ! /* Move the found entry to become the last entry. The ! * order of undo/redo doesn't matter for the entries ! * we move it over, since they don't change the line ! * count and don't include this line. It does matter ! * for the found entry if the line count is changed by ! * the executed command. */ prev_uep->ue_next = uep->ue_next; uep->ue_next = curbuf->b_u_newhead->uh_entry; curbuf->b_u_newhead->uh_entry = uep; } ! /* The executed command may change the line count. */ if (newbot != 0) uep->ue_bot = newbot; else if (bot > curbuf->b_ml.ml_line_count) --- 604,632 ---- && top + 2 <= uep->ue_top + uep->ue_size + 1)) break; ! // If it's the same line we can skip saving it again. if (uep->ue_size == 1 && uep->ue_top == top) { if (i > 0) { ! // It's not the last entry: get ue_bot for the last ! // entry now. Following deleted/inserted lines go to ! // the re-used entry. u_getbot(); curbuf->b_u_synced = FALSE; ! // Move the found entry to become the last entry. The ! // order of undo/redo doesn't matter for the entries ! // we move it over, since they don't change the line ! // count and don't include this line. It does matter ! // for the found entry if the line count is changed by ! // the executed command. prev_uep->ue_next = uep->ue_next; uep->ue_next = curbuf->b_u_newhead->uh_entry; curbuf->b_u_newhead->uh_entry = uep; } ! // The executed command may change the line count. if (newbot != 0) uep->ue_bot = newbot; else if (bot > curbuf->b_ml.ml_line_count) *************** *** 643,649 **** } } ! /* find line number for ue_bot for previous u_save() */ u_getbot(); } --- 643,649 ---- } } ! // find line number for ue_bot for previous u_save() u_getbot(); } *************** *** 718,728 **** return OK; nomem: ! msg_silent = 0; /* must display the prompt */ if (ask_yesno((char_u *)_("No undo possible; continue anyway"), TRUE) == 'y') { ! undo_off = TRUE; /* will be reset when character typed */ return OK; } do_outofmem_msg((long_u)0); --- 718,728 ---- return OK; nomem: ! msg_silent = 0; // must display the prompt if (ask_yesno((char_u *)_("No undo possible; continue anyway"), TRUE) == 'y') { ! undo_off = TRUE; // will be reset when character typed return OK; } do_outofmem_msg((long_u)0); *************** *** 731,749 **** #if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) ! # define UF_START_MAGIC "Vim\237UnDo\345" /* magic at start of undofile */ # define UF_START_MAGIC_LEN 9 ! # define UF_HEADER_MAGIC 0x5fd0 /* magic at start of header */ ! # define UF_HEADER_END_MAGIC 0xe7aa /* magic after last header */ ! # define UF_ENTRY_MAGIC 0xf518 /* magic at start of entry */ ! # define UF_ENTRY_END_MAGIC 0x3581 /* magic after last entry */ ! # define UF_VERSION 2 /* 2-byte undofile version number */ ! # define UF_VERSION_CRYPT 0x8002 /* idem, encrypted */ ! /* extra fields for header */ # define UF_LAST_SAVE_NR 1 ! /* extra fields for uhp */ # define UHP_SAVE_NR 1 static char_u e_not_open[] = N_("E828: Cannot open undo file for writing: %s"); --- 731,749 ---- #if defined(FEAT_PERSISTENT_UNDO) || defined(PROTO) ! # define UF_START_MAGIC "Vim\237UnDo\345" // magic at start of undofile # define UF_START_MAGIC_LEN 9 ! # define UF_HEADER_MAGIC 0x5fd0 // magic at start of header ! # define UF_HEADER_END_MAGIC 0xe7aa // magic after last header ! # define UF_ENTRY_MAGIC 0xf518 // magic at start of entry ! # define UF_ENTRY_END_MAGIC 0x3581 // magic after last entry ! # define UF_VERSION 2 // 2-byte undofile version number ! # define UF_VERSION_CRYPT 0x8002 // idem, encrypted ! // extra fields for header # define UF_LAST_SAVE_NR 1 ! // extra fields for uhp # define UHP_SAVE_NR 1 static char_u e_not_open[] = N_("E828: Cannot open undo file for writing: %s"); *************** *** 793,828 **** return NULL; #ifdef HAVE_READLINK ! /* Expand symlink in the file name, so that we put the undo file with the ! * actual file instead of with the symlink. */ if (resolve_symlink(ffname, fname_buf) == OK) ffname = fname_buf; #endif ! /* Loop over 'undodir'. When reading find the first file that exists. ! * When not reading use the first directory that exists or ".". */ dirp = p_udir; while (*dirp != NUL) { dir_len = copy_option_part(&dirp, dir_name, IOSIZE, ","); if (dir_len == 1 && dir_name[0] == '.') { ! /* Use same directory as the ffname, ! * "dir/name" -> "dir/.name.un~" */ undo_file_name = vim_strnsave(ffname, (int)(STRLEN(ffname) + 5)); if (undo_file_name == NULL) break; p = gettail(undo_file_name); #ifdef VMS ! /* VMS can not handle more than one dot in the filenames ! * use "dir/name" -> "dir/_un_name" - add _un_ ! * at the beginning to keep the extension */ mch_memmove(p + 4, p, STRLEN(p) + 1); mch_memmove(p, "_un_", 4); #else ! /* Use same directory as the ffname, ! * "dir/name" -> "dir/.name.un~" */ mch_memmove(p + 1, p, STRLEN(p) + 1); *p = '.'; STRCAT(p, ".un~"); --- 793,828 ---- return NULL; #ifdef HAVE_READLINK ! // Expand symlink in the file name, so that we put the undo file with the ! // actual file instead of with the symlink. if (resolve_symlink(ffname, fname_buf) == OK) ffname = fname_buf; #endif ! // Loop over 'undodir'. When reading find the first file that exists. ! // When not reading use the first directory that exists or ".". dirp = p_udir; while (*dirp != NUL) { dir_len = copy_option_part(&dirp, dir_name, IOSIZE, ","); if (dir_len == 1 && dir_name[0] == '.') { ! // Use same directory as the ffname, ! // "dir/name" -> "dir/.name.un~" undo_file_name = vim_strnsave(ffname, (int)(STRLEN(ffname) + 5)); if (undo_file_name == NULL) break; p = gettail(undo_file_name); #ifdef VMS ! // VMS can not handle more than one dot in the filenames ! // use "dir/name" -> "dir/_un_name" - add _un_ ! // at the beginning to keep the extension mch_memmove(p + 4, p, STRLEN(p) + 1); mch_memmove(p, "_un_", 4); #else ! // Use same directory as the ffname, ! // "dir/name" -> "dir/.name.un~" mch_memmove(p + 1, p, STRLEN(p) + 1); *p = '.'; STRCAT(p, ".un~"); *************** *** 846,852 **** } } ! /* When reading check if the file exists. */ if (undo_file_name != NULL && (!reading || mch_stat((char *)undo_file_name, &st) >= 0)) break; --- 846,852 ---- } } ! // When reading check if the file exists. if (undo_file_name != NULL && (!reading || mch_stat((char *)undo_file_name, &st) >= 0)) break; *************** *** 946,954 **** if (bi->bi_state != NULL && bi->bi_buffer == NULL) { ! /* crypting every piece of text separately */ if (len < 100) ! copy = small_buf; /* no malloc()/free() for short strings */ else { copy = lalloc(len, FALSE); --- 946,954 ---- if (bi->bi_state != NULL && bi->bi_buffer == NULL) { ! // crypting every piece of text separately if (len < 100) ! copy = small_buf; // no malloc()/free() for short strings else { copy = lalloc(len, FALSE); *************** *** 1106,1113 **** retval = FAIL; if (retval == FAIL) ! /* Error may be checked for only later. Fill with zeros, ! * so that the reader won't use garbage. */ vim_memset(buffer, 0, size); return retval; } --- 1106,1113 ---- retval = FAIL; if (retval == FAIL) ! // Error may be checked for only later. Fill with zeros, ! // so that the reader won't use garbage. vim_memset(buffer, 0, size); return retval; } *************** *** 1153,1164 **** FILE *fp = bi->bi_fp; char_u time_buf[8]; ! /* Start writing, first the magic marker and undo info version. */ if (fwrite(UF_START_MAGIC, (size_t)UF_START_MAGIC_LEN, (size_t)1, fp) != 1) return FAIL; ! /* If the buffer is encrypted then all text bytes following will be ! * encrypted. Numbers and other info is not crypted. */ #ifdef FEAT_CRYPT if (*buf->b_p_key != NUL) { --- 1153,1164 ---- FILE *fp = bi->bi_fp; char_u time_buf[8]; ! // Start writing, first the magic marker and undo info version. if (fwrite(UF_START_MAGIC, (size_t)UF_START_MAGIC_LEN, (size_t)1, fp) != 1) return FAIL; ! // If the buffer is encrypted then all text bytes following will be ! // encrypted. Numbers and other info is not crypted. #ifdef FEAT_CRYPT if (*buf->b_p_key != NUL) { *************** *** 1196,1207 **** undo_write_bytes(bi, (long_u)UF_VERSION, 2); ! /* Write a hash of the buffer text, so that we can verify it is still the ! * same when reading the buffer text. */ if (undo_write(bi, hash, (size_t)UNDO_HASH_SIZE) == FAIL) return FAIL; ! /* buffer-specific data */ undo_write_bytes(bi, (long_u)buf->b_ml.ml_line_count, 4); len = buf->b_u_line_ptr.ul_line == NULL ? 0L : (long)STRLEN(buf->b_u_line_ptr.ul_line); --- 1196,1207 ---- undo_write_bytes(bi, (long_u)UF_VERSION, 2); ! // Write a hash of the buffer text, so that we can verify it is still the ! // same when reading the buffer text. if (undo_write(bi, hash, (size_t)UNDO_HASH_SIZE) == FAIL) return FAIL; ! // buffer-specific data undo_write_bytes(bi, (long_u)buf->b_ml.ml_line_count, 4); len = buf->b_u_line_ptr.ul_line == NULL ? 0L : (long)STRLEN(buf->b_u_line_ptr.ul_line); *************** *** 1212,1218 **** undo_write_bytes(bi, (long_u)buf->b_u_line_lnum, 4); undo_write_bytes(bi, (long_u)buf->b_u_line_colnr, 4); ! /* Undo structures header data */ put_header_ptr(bi, buf->b_u_oldhead); put_header_ptr(bi, buf->b_u_newhead); put_header_ptr(bi, buf->b_u_curhead); --- 1212,1218 ---- undo_write_bytes(bi, (long_u)buf->b_u_line_lnum, 4); undo_write_bytes(bi, (long_u)buf->b_u_line_colnr, 4); ! // Undo structures header data put_header_ptr(bi, buf->b_u_oldhead); put_header_ptr(bi, buf->b_u_newhead); put_header_ptr(bi, buf->b_u_curhead); *************** *** 1223,1234 **** time_to_bytes(buf->b_u_time_cur, time_buf); undo_write(bi, time_buf, 8); ! /* Optional fields. */ undo_write_bytes(bi, 4, 1); undo_write_bytes(bi, UF_LAST_SAVE_NR, 1); undo_write_bytes(bi, (long_u)buf->b_u_save_nr_last, 4); ! undo_write_bytes(bi, 0, 1); /* end marker */ return OK; } --- 1223,1234 ---- time_to_bytes(buf->b_u_time_cur, time_buf); undo_write(bi, time_buf, 8); ! // Optional fields. undo_write_bytes(bi, 4, 1); undo_write_bytes(bi, UF_LAST_SAVE_NR, 1); undo_write_bytes(bi, (long_u)buf->b_u_save_nr_last, 4); ! undo_write_bytes(bi, 0, 1); // end marker return OK; } *************** *** 1251,1271 **** serialize_pos(bi, uhp->uh_cursor); undo_write_bytes(bi, (long_u)uhp->uh_cursor_vcol, 4); undo_write_bytes(bi, (long_u)uhp->uh_flags, 2); ! /* Assume NMARKS will stay the same. */ for (i = 0; i < NMARKS; ++i) serialize_pos(bi, uhp->uh_namedm[i]); serialize_visualinfo(bi, &uhp->uh_visual); time_to_bytes(uhp->uh_time, time_buf); undo_write(bi, time_buf, 8); ! /* Optional fields. */ undo_write_bytes(bi, 4, 1); undo_write_bytes(bi, UHP_SAVE_NR, 1); undo_write_bytes(bi, (long_u)uhp->uh_save_nr, 4); ! undo_write_bytes(bi, 0, 1); /* end marker */ ! /* Write all the entries. */ for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next) { undo_write_bytes(bi, (long_u)UF_ENTRY_MAGIC, 2); --- 1251,1271 ---- serialize_pos(bi, uhp->uh_cursor); undo_write_bytes(bi, (long_u)uhp->uh_cursor_vcol, 4); undo_write_bytes(bi, (long_u)uhp->uh_flags, 2); ! // Assume NMARKS will stay the same. for (i = 0; i < NMARKS; ++i) serialize_pos(bi, uhp->uh_namedm[i]); serialize_visualinfo(bi, &uhp->uh_visual); time_to_bytes(uhp->uh_time, time_buf); undo_write(bi, time_buf, 8); ! // Optional fields. undo_write_bytes(bi, 4, 1); undo_write_bytes(bi, UHP_SAVE_NR, 1); undo_write_bytes(bi, (long_u)uhp->uh_save_nr, 4); ! undo_write_bytes(bi, 0, 1); // end marker ! // Write all the entries. for (uep = uhp->uh_entry; uep != NULL; uep = uep->ue_next) { undo_write_bytes(bi, (long_u)UF_ENTRY_MAGIC, 2); *************** *** 1311,1317 **** unserialize_visualinfo(bi, &uhp->uh_visual); uhp->uh_time = undo_read_time(bi); ! /* Optional fields. */ for (;;) { int len = undo_read_byte(bi); --- 1311,1317 ---- unserialize_visualinfo(bi, &uhp->uh_visual); uhp->uh_time = undo_read_time(bi); ! // Optional fields. for (;;) { int len = undo_read_byte(bi); *************** *** 1332,1344 **** uhp->uh_save_nr = undo_read_4c(bi); break; default: ! /* field not supported, skip */ while (--len >= 0) (void)undo_read_byte(bi); } } ! /* Unserialize the uep list. */ last_uep = NULL; while ((c = undo_read_2c(bi)) == UF_ENTRY_MAGIC) { --- 1332,1344 ---- uhp->uh_save_nr = undo_read_4c(bi); break; default: ! // field not supported, skip while (--len >= 0) (void)undo_read_byte(bi); } } ! // Unserialize the uep list. last_uep = NULL; while ((c = undo_read_2c(bi)) == UF_ENTRY_MAGIC) { *************** *** 1573,1588 **** #endif } ! /* strip any s-bit and executable bit */ perm = perm & 0666; ! /* If the undo file already exists, verify that it actually is an undo ! * file, and delete it. */ if (mch_getperm(file_name) >= 0) { if (name == NULL || !forceit) { ! /* Check we can read it and it's an undo file. */ fd = mch_open((char *)file_name, O_RDONLY|O_EXTRA, 0); if (fd < 0) { --- 1573,1588 ---- #endif } ! // strip any s-bit and executable bit perm = perm & 0666; ! // If the undo file already exists, verify that it actually is an undo ! // file, and delete it. if (mch_getperm(file_name) >= 0) { if (name == NULL || !forceit) { ! // Check we can read it and it's an undo file. fd = mch_open((char *)file_name, O_RDONLY|O_EXTRA, 0); if (fd < 0) { *************** *** 1625,1632 **** mch_remove(file_name); } ! /* If there is no undo information at all, quit here after deleting any ! * existing undo file. */ if (buf->b_u_numhead == 0 && buf->b_u_line_ptr.ul_line == NULL) { if (p_verbose > 0) --- 1625,1632 ---- mch_remove(file_name); } ! // If there is no undo information at all, quit here after deleting any ! // existing undo file. if (buf->b_u_numhead == 0 && buf->b_u_line_ptr.ul_line == NULL) { if (p_verbose > 0) *************** *** 1650,1656 **** } #ifdef U_DEBUG ! /* Check there is no problem in undo info before writing. */ u_check(FALSE); #endif --- 1650,1656 ---- } #ifdef U_DEBUG ! // Check there is no problem in undo info before writing. u_check(FALSE); #endif *************** *** 1663,1669 **** if (st_old_valid && mch_stat((char *)file_name, &st_new) >= 0 && st_new.st_gid != st_old.st_gid ! # ifdef HAVE_FCHOWN /* sequent-ptx lacks fchown() */ && fchown(fd, (uid_t)-1, st_old.st_gid) != 0 # endif ) --- 1663,1669 ---- if (st_old_valid && mch_stat((char *)file_name, &st_new) >= 0 && st_new.st_gid != st_old.st_gid ! # ifdef HAVE_FCHOWN // sequent-ptx lacks fchown() && fchown(fd, (uid_t)-1, st_old.st_gid) != 0 # endif ) *************** *** 1683,1689 **** goto theend; } ! /* Undo must be synced. */ u_sync(TRUE); /* --- 1683,1689 ---- goto theend; } ! // Undo must be synced. u_sync(TRUE); /* *************** *** 1701,1707 **** uhp = buf->b_u_oldhead; while (uhp != NULL) { ! /* Serialize current UHP if we haven't seen it */ if (uhp->uh_walk != mark) { uhp->uh_walk = mark; --- 1701,1707 ---- uhp = buf->b_u_oldhead; while (uhp != NULL) { ! // Serialize current UHP if we haven't seen it if (uhp->uh_walk != mark) { uhp->uh_walk = mark; *************** *** 1712,1718 **** goto write_error; } ! /* Now walk through the tree - algorithm from undo_time(). */ if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != mark) uhp = uhp->uh_prev.ptr; else if (uhp->uh_alt_next.ptr != NULL --- 1712,1718 ---- goto write_error; } ! // Now walk through the tree - algorithm from undo_time(). if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != mark) uhp = uhp->uh_prev.ptr; else if (uhp->uh_alt_next.ptr != NULL *************** *** 1748,1755 **** semsg(_("E829: write error in undo file: %s"), file_name); #if defined(MSWIN) ! /* Copy file attributes; for systems where this can only be done after ! * closing the file. */ if (buf->b_ffname != NULL) (void)mch_copy_file_attribute(buf->b_ffname, file_name); #endif --- 1748,1755 ---- semsg(_("E829: write error in undo file: %s"), file_name); #if defined(MSWIN) ! // Copy file attributes; for systems where this can only be done after ! // closing the file. if (buf->b_ffname != NULL) (void)mch_copy_file_attribute(buf->b_ffname, file_name); #endif *************** *** 1758,1764 **** { vim_acl_T acl; ! /* For systems that support ACL: get the ACL from the original file. */ acl = mch_get_acl(buf->b_ffname); mch_set_acl(file_name, acl); mch_free_acl(acl); --- 1758,1764 ---- { vim_acl_T acl; ! // For systems that support ACL: get the ACL from the original file. acl = mch_get_acl(buf->b_ffname); mch_set_acl(file_name, acl); mch_free_acl(acl); *************** *** 1825,1832 **** return; #ifdef UNIX ! /* For safety we only read an undo file if the owner is equal to the ! * owner of the text file or equal to the current user. */ if (mch_stat((char *)orig_name, &st_orig) >= 0 && mch_stat((char *)file_name, &st_undo) >= 0 && st_orig.st_uid != st_undo.st_uid --- 1825,1832 ---- return; #ifdef UNIX ! // For safety we only read an undo file if the owner is equal to the ! // owner of the text file or equal to the current user. if (mch_stat((char *)orig_name, &st_orig) >= 0 && mch_stat((char *)file_name, &st_undo) >= 0 && st_orig.st_uid != st_undo.st_uid *************** *** 1932,1938 **** goto error; } ! /* Read undo data for "U" command. */ str_len = undo_read_4c(&bi); if (str_len < 0) goto error; --- 1932,1938 ---- goto error; } ! // Read undo data for "U" command. str_len = undo_read_4c(&bi); if (str_len < 0) goto error; *************** *** 1949,1955 **** goto error; } ! /* Begin general undo data */ old_header_seq = undo_read_4c(&bi); new_header_seq = undo_read_4c(&bi); cur_header_seq = undo_read_4c(&bi); --- 1949,1955 ---- goto error; } ! // Begin general undo data old_header_seq = undo_read_4c(&bi); new_header_seq = undo_read_4c(&bi); cur_header_seq = undo_read_4c(&bi); *************** *** 1958,1964 **** seq_cur = undo_read_4c(&bi); seq_time = undo_read_time(&bi); ! /* Optional header fields. */ for (;;) { int len = undo_read_byte(&bi); --- 1958,1964 ---- seq_cur = undo_read_4c(&bi); seq_time = undo_read_time(&bi); ! // Optional header fields. for (;;) { int len = undo_read_byte(&bi); *************** *** 1973,1988 **** last_save_nr = undo_read_4c(&bi); break; default: ! /* field not supported, skip */ while (--len >= 0) (void)undo_read_byte(&bi); } } ! /* uhp_table will store the freshly created undo headers we allocate ! * until we insert them into curbuf. The table remains sorted by the ! * sequence numbers of the headers. ! * When there are no headers uhp_table is NULL. */ if (num_head > 0) { if (num_head < LONG_MAX / (long)sizeof(u_header_T *)) --- 1973,1988 ---- last_save_nr = undo_read_4c(&bi); break; default: ! // field not supported, skip while (--len >= 0) (void)undo_read_byte(&bi); } } ! // uhp_table will store the freshly created undo headers we allocate ! // until we insert them into curbuf. The table remains sorted by the ! // sequence numbers of the headers. ! // When there are no headers uhp_table is NULL. if (num_head > 0) { if (num_head < LONG_MAX / (long)sizeof(u_header_T *)) *************** *** 2023,2031 **** # define SET_FLAG(j) #endif ! /* We have put all of the headers into a table. Now we iterate through the ! * table and swizzle each sequence number we have stored in uh_*_seq into ! * a pointer corresponding to the header with that sequence number. */ for (i = 0; i < num_head; i++) { uhp = uhp_table[i]; --- 2023,2031 ---- # define SET_FLAG(j) #endif ! // We have put all of the headers into a table. Now we iterate through the ! // table and swizzle each sequence number we have stored in uh_*_seq into ! // a pointer corresponding to the header with that sequence number. for (i = 0; i < num_head; i++) { uhp = uhp_table[i]; *************** *** 2087,2094 **** } } ! /* Now that we have read the undo info successfully, free the current undo ! * info and use the info from the file. */ u_blockfree(curbuf); curbuf->b_u_oldhead = old_idx < 0 ? NULL : uhp_table[old_idx]; curbuf->b_u_newhead = new_idx < 0 ? NULL : uhp_table[new_idx]; --- 2087,2094 ---- } } ! // Now that we have read the undo info successfully, free the current undo ! // info and use the info from the file. u_blockfree(curbuf); curbuf->b_u_oldhead = old_idx < 0 ? NULL : uhp_table[old_idx]; curbuf->b_u_newhead = new_idx < 0 ? NULL : uhp_table[new_idx]; *************** *** 2141,2147 **** return; } ! #endif /* FEAT_PERSISTENT_UNDO */ /* --- 2141,2147 ---- return; } ! #endif // FEAT_PERSISTENT_UNDO /* *************** *** 2198,2220 **** u_oldcount = -1; while (count--) { ! /* Do the change warning now, so that it triggers FileChangedRO when ! * needed. This may cause the file to be reloaded, that must happen ! * before we do anything, because it may change curbuf->b_u_curhead ! * and more. */ change_warning(0); if (undo_undoes) { ! if (curbuf->b_u_curhead == NULL) /* first undo */ curbuf->b_u_curhead = curbuf->b_u_newhead; ! else if (get_undolevel() > 0) /* multi level undo */ ! /* get next undo */ curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr; ! /* nothing to undo */ if (curbuf->b_u_numhead == 0 || curbuf->b_u_curhead == NULL) { ! /* stick curbuf->b_u_curhead at end */ curbuf->b_u_curhead = curbuf->b_u_oldhead; beep_flush(); if (count == startcount - 1) --- 2198,2220 ---- u_oldcount = -1; while (count--) { ! // Do the change warning now, so that it triggers FileChangedRO when ! // needed. This may cause the file to be reloaded, that must happen ! // before we do anything, because it may change curbuf->b_u_curhead ! // and more. change_warning(0); if (undo_undoes) { ! if (curbuf->b_u_curhead == NULL) // first undo curbuf->b_u_curhead = curbuf->b_u_newhead; ! else if (get_undolevel() > 0) // multi level undo ! // get next undo curbuf->b_u_curhead = curbuf->b_u_curhead->uh_next.ptr; ! // nothing to undo if (curbuf->b_u_numhead == 0 || curbuf->b_u_curhead == NULL) { ! // stick curbuf->b_u_curhead at end curbuf->b_u_curhead = curbuf->b_u_oldhead; beep_flush(); if (count == startcount - 1) *************** *** 2231,2237 **** { if (curbuf->b_u_curhead == NULL || get_undolevel() <= 0) { ! beep_flush(); /* nothing to redo */ if (count == startcount - 1) { msg(_("Already at newest change")); --- 2231,2237 ---- { if (curbuf->b_u_curhead == NULL || get_undolevel() <= 0) { ! beep_flush(); // nothing to redo if (count == startcount - 1) { msg(_("Already at newest change")); *************** *** 2242,2249 **** u_undoredo(FALSE); ! /* Advance for next redo. Set "newhead" when at the end of the ! * redoable changes. */ if (curbuf->b_u_curhead->uh_prev.ptr == NULL) curbuf->b_u_newhead = curbuf->b_u_curhead; curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev.ptr; --- 2242,2249 ---- u_undoredo(FALSE); ! // Advance for next redo. Set "newhead" when at the end of the ! // redoable changes. if (curbuf->b_u_curhead->uh_prev.ptr == NULL) curbuf->b_u_newhead = curbuf->b_u_curhead; curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev.ptr; *************** *** 2283,2289 **** int above = FALSE; int did_undo = TRUE; ! /* First make sure the current undoable change is synced. */ if (curbuf->b_u_synced == FALSE) u_sync(TRUE); --- 2283,2289 ---- int above = FALSE; int did_undo = TRUE; ! // First make sure the current undoable change is synced. if (curbuf->b_u_synced == FALSE) u_sync(TRUE); *************** *** 2292,2299 **** if (curbuf->b_ml.ml_flags & ML_EMPTY) u_oldcount = -1; ! /* "target" is the node below which we want to be. ! * Init "closest" to a value we can't reach. */ if (absolute) { target = step; --- 2292,2299 ---- if (curbuf->b_ml.ml_flags & ML_EMPTY) u_oldcount = -1; ! // "target" is the node below which we want to be. ! // Init "closest" to a value we can't reach. if (absolute) { target = step; *************** *** 2307,2340 **** { if (step < 0) { ! /* Going back to a previous write. If there were changes after ! * the last write, count that as moving one file-write, so ! * that ":earlier 1f" undoes all changes since the last save. */ uhp = curbuf->b_u_curhead; if (uhp != NULL) uhp = uhp->uh_next.ptr; else uhp = curbuf->b_u_newhead; if (uhp != NULL && uhp->uh_save_nr != 0) ! /* "uh_save_nr" was set in the last block, that means ! * there were no changes since the last write */ target = curbuf->b_u_save_nr_cur + step; else ! /* count the changes since the last write as one step */ target = curbuf->b_u_save_nr_cur + step + 1; if (target <= 0) ! /* Go to before first write: before the oldest change. Use ! * the sequence number for that. */ dofile = FALSE; } else { ! /* Moving forward to a newer write. */ target = curbuf->b_u_save_nr_cur + step; if (target > curbuf->b_u_save_nr_last) { ! /* Go to after last write: after the latest change. Use ! * the sequence number for that. */ target = curbuf->b_u_seq_last + 1; dofile = FALSE; } --- 2307,2340 ---- { if (step < 0) { ! // Going back to a previous write. If there were changes after ! // the last write, count that as moving one file-write, so ! // that ":earlier 1f" undoes all changes since the last save. uhp = curbuf->b_u_curhead; if (uhp != NULL) uhp = uhp->uh_next.ptr; else uhp = curbuf->b_u_newhead; if (uhp != NULL && uhp->uh_save_nr != 0) ! // "uh_save_nr" was set in the last block, that means ! // there were no changes since the last write target = curbuf->b_u_save_nr_cur + step; else ! // count the changes since the last write as one step target = curbuf->b_u_save_nr_cur + step + 1; if (target <= 0) ! // Go to before first write: before the oldest change. Use ! // the sequence number for that. dofile = FALSE; } else { ! // Moving forward to a newer write. target = curbuf->b_u_save_nr_cur + step; if (target > curbuf->b_u_save_nr_last) { ! // Go to after last write: after the latest change. Use ! // the sequence number for that. target = curbuf->b_u_seq_last + 1; dofile = FALSE; } *************** *** 2363,2372 **** closest_start = closest; closest_seq = curbuf->b_u_seq_cur; ! /* When "target" is 0; Back to origin. */ if (target == 0) { ! mark = lastmark; /* avoid that GCC complains */ goto target_zero; } --- 2363,2372 ---- closest_start = closest; closest_seq = curbuf->b_u_seq_cur; ! // When "target" is 0; Back to origin. if (target == 0) { ! mark = lastmark; // avoid that GCC complains goto target_zero; } *************** *** 2380,2393 **** */ for (round = 1; round <= 2; ++round) { ! /* Find the path from the current state to where we want to go. The ! * desired state can be anywhere in the undo tree, need to go all over ! * it. We put "nomark" in uh_walk where we have been without success, ! * "mark" where it could possibly be. */ mark = ++lastmark; nomark = ++lastmark; ! if (curbuf->b_u_curhead == NULL) /* at leaf of the tree */ uhp = curbuf->b_u_newhead; else uhp = curbuf->b_u_curhead; --- 2380,2393 ---- */ for (round = 1; round <= 2; ++round) { ! // Find the path from the current state to where we want to go. The ! // desired state can be anywhere in the undo tree, need to go all over ! // it. We put "nomark" in uh_walk where we have been without success, ! // "mark" where it could possibly be. mark = ++lastmark; nomark = ++lastmark; ! if (curbuf->b_u_curhead == NULL) // at leaf of the tree uhp = curbuf->b_u_newhead; else uhp = curbuf->b_u_curhead; *************** *** 2404,2413 **** if (round == 1 && !(dofile && val == 0)) { ! /* Remember the header that is closest to the target. ! * It must be at least in the right direction (checked with ! * "b_u_seq_cur"). When the timestamp is equal find the ! * highest/lowest sequence number. */ if ((step < 0 ? uhp->uh_seq <= curbuf->b_u_seq_cur : uhp->uh_seq > curbuf->b_u_seq_cur) && ((dosec && val == closest) --- 2404,2413 ---- if (round == 1 && !(dofile && val == 0)) { ! // Remember the header that is closest to the target. ! // It must be at least in the right direction (checked with ! // "b_u_seq_cur"). When the timestamp is equal find the ! // highest/lowest sequence number. if ((step < 0 ? uhp->uh_seq <= curbuf->b_u_seq_cur : uhp->uh_seq > curbuf->b_u_seq_cur) && ((dosec && val == closest) *************** *** 2428,2459 **** } } ! /* Quit searching when we found a match. But when searching for a ! * time we need to continue looking for the best uh_seq. */ if (target == val && !dosec) { target = uhp->uh_seq; break; } ! /* go down in the tree if we haven't been there */ if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark && uhp->uh_prev.ptr->uh_walk != mark) uhp = uhp->uh_prev.ptr; ! /* go to alternate branch if we haven't been there */ else if (uhp->uh_alt_next.ptr != NULL && uhp->uh_alt_next.ptr->uh_walk != nomark && uhp->uh_alt_next.ptr->uh_walk != mark) uhp = uhp->uh_alt_next.ptr; ! /* go up in the tree if we haven't been there and we are at the ! * start of alternate branches */ else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL && uhp->uh_next.ptr->uh_walk != nomark && uhp->uh_next.ptr->uh_walk != mark) { ! /* If still at the start we don't go through this change. */ if (uhp == curbuf->b_u_curhead) uhp->uh_walk = nomark; uhp = uhp->uh_next.ptr; --- 2428,2459 ---- } } ! // Quit searching when we found a match. But when searching for a ! // time we need to continue looking for the best uh_seq. if (target == val && !dosec) { target = uhp->uh_seq; break; } ! // go down in the tree if we haven't been there if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark && uhp->uh_prev.ptr->uh_walk != mark) uhp = uhp->uh_prev.ptr; ! // go to alternate branch if we haven't been there else if (uhp->uh_alt_next.ptr != NULL && uhp->uh_alt_next.ptr->uh_walk != nomark && uhp->uh_alt_next.ptr->uh_walk != mark) uhp = uhp->uh_alt_next.ptr; ! // go up in the tree if we haven't been there and we are at the ! // start of alternate branches else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL && uhp->uh_next.ptr->uh_walk != nomark && uhp->uh_next.ptr->uh_walk != mark) { ! // If still at the start we don't go through this change. if (uhp == curbuf->b_u_curhead) uhp->uh_walk = nomark; uhp = uhp->uh_next.ptr; *************** *** 2461,2467 **** else { ! /* need to backtrack; mark this node as useless */ uhp->uh_walk = nomark; if (uhp->uh_alt_prev.ptr != NULL) uhp = uhp->uh_alt_prev.ptr; --- 2461,2467 ---- else { ! // need to backtrack; mark this node as useless uhp->uh_walk = nomark; if (uhp->uh_alt_prev.ptr != NULL) uhp = uhp->uh_alt_prev.ptr; *************** *** 2470,2476 **** } } ! if (uhp != NULL) /* found it */ break; if (absolute) --- 2470,2476 ---- } } ! if (uhp != NULL) // found it break; if (absolute) *************** *** 2492,2502 **** dosec = FALSE; dofile = FALSE; if (step < 0) ! above = TRUE; /* stop above the header */ } target_zero: ! /* If we found it: Follow the path to go to where we want to be. */ if (uhp != NULL || target == 0) { /* --- 2492,2502 ---- dosec = FALSE; dofile = FALSE; if (step < 0) ! above = TRUE; // stop above the header } target_zero: ! // If we found it: Follow the path to go to where we want to be. if (uhp != NULL || target == 0) { /* *************** *** 2504,2510 **** */ while (!got_int) { ! /* Do the change warning now, for the same reason as above. */ change_warning(0); uhp = curbuf->b_u_curhead; --- 2504,2510 ---- */ while (!got_int) { ! // Do the change warning now, for the same reason as above. change_warning(0); uhp = curbuf->b_u_curhead; *************** *** 2518,2527 **** curbuf->b_u_curhead = uhp; u_undoredo(TRUE); if (target > 0) ! uhp->uh_walk = nomark; /* don't go back down here */ } ! /* When back to origin, redo is not needed. */ if (target > 0) { /* --- 2518,2527 ---- curbuf->b_u_curhead = uhp; u_undoredo(TRUE); if (target > 0) ! uhp->uh_walk = nomark; // don't go back down here } ! // When back to origin, redo is not needed. if (target > 0) { /* *************** *** 2529,2555 **** */ while (!got_int) { ! /* Do the change warning now, for the same reason as above. */ change_warning(0); uhp = curbuf->b_u_curhead; if (uhp == NULL) break; ! /* Go back to the first branch with a mark. */ while (uhp->uh_alt_prev.ptr != NULL && uhp->uh_alt_prev.ptr->uh_walk == mark) uhp = uhp->uh_alt_prev.ptr; ! /* Find the last branch with a mark, that's the one. */ last = uhp; while (last->uh_alt_next.ptr != NULL && last->uh_alt_next.ptr->uh_walk == mark) last = last->uh_alt_next.ptr; if (last != uhp) { ! /* Make the used branch the first entry in the list of ! * alternatives to make "u" and CTRL-R take this branch. */ while (uhp->uh_alt_prev.ptr != NULL) uhp = uhp->uh_alt_prev.ptr; if (last->uh_alt_next.ptr != NULL) --- 2529,2555 ---- */ while (!got_int) { ! // Do the change warning now, for the same reason as above. change_warning(0); uhp = curbuf->b_u_curhead; if (uhp == NULL) break; ! // Go back to the first branch with a mark. while (uhp->uh_alt_prev.ptr != NULL && uhp->uh_alt_prev.ptr->uh_walk == mark) uhp = uhp->uh_alt_prev.ptr; ! // Find the last branch with a mark, that's the one. last = uhp; while (last->uh_alt_next.ptr != NULL && last->uh_alt_next.ptr->uh_walk == mark) last = last->uh_alt_next.ptr; if (last != uhp) { ! // Make the used branch the first entry in the list of ! // alternatives to make "u" and CTRL-R take this branch. while (uhp->uh_alt_prev.ptr != NULL) uhp = uhp->uh_alt_prev.ptr; if (last->uh_alt_next.ptr != NULL) *************** *** 2570,2579 **** curbuf->b_u_curhead = uhp; if (uhp->uh_walk != mark) ! break; /* must have reached the target */ ! /* Stop when going backwards in time and didn't find the exact ! * header we were looking for. */ if (uhp->uh_seq == target && above) { curbuf->b_u_seq_cur = target - 1; --- 2570,2579 ---- curbuf->b_u_curhead = uhp; if (uhp->uh_walk != mark) ! break; // must have reached the target ! // Stop when going backwards in time and didn't find the exact ! // header we were looking for. if (uhp->uh_seq == target && above) { curbuf->b_u_seq_cur = target - 1; *************** *** 2582,2601 **** u_undoredo(FALSE); ! /* Advance "curhead" to below the header we last used. If it ! * becomes NULL then we need to set "newhead" to this leaf. */ if (uhp->uh_prev.ptr == NULL) curbuf->b_u_newhead = uhp; curbuf->b_u_curhead = uhp->uh_prev.ptr; did_undo = FALSE; ! if (uhp->uh_seq == target) /* found it! */ break; uhp = uhp->uh_prev.ptr; if (uhp == NULL || uhp->uh_walk != mark) { ! /* Need to redo more but can't find it... */ internal_error("undo_time()"); break; } --- 2582,2601 ---- u_undoredo(FALSE); ! // Advance "curhead" to below the header we last used. If it ! // becomes NULL then we need to set "newhead" to this leaf. if (uhp->uh_prev.ptr == NULL) curbuf->b_u_newhead = uhp; curbuf->b_u_curhead = uhp->uh_prev.ptr; did_undo = FALSE; ! if (uhp->uh_seq == target) // found it! break; uhp = uhp->uh_prev.ptr; if (uhp == NULL || uhp->uh_walk != mark) { ! // Need to redo more but can't find it... internal_error("undo_time()"); break; } *************** *** 2631,2641 **** int new_flags; pos_T namedm[NMARKS]; visualinfo_T visualinfo; ! int empty_buffer; /* buffer became empty */ u_header_T *curhead = curbuf->b_u_curhead; ! /* Don't want autocommands using the undo structures here, they are ! * invalid till the end. */ block_autocmds(); #ifdef U_DEBUG --- 2631,2641 ---- int new_flags; pos_T namedm[NMARKS]; visualinfo_T visualinfo; ! int empty_buffer; // buffer became empty u_header_T *curhead = curbuf->b_u_curhead; ! // Don't want autocommands using the undo structures here, they are ! // invalid till the end. block_autocmds(); #ifdef U_DEBUG *************** *** 2821,2827 **** changed(); else #ifdef FEAT_NETBEANS_INTG ! /* per netbeans undo rules, keep it as modified */ if (!isNetbeansModified(curbuf)) #endif unchanged(curbuf, FALSE, TRUE); --- 2821,2827 ---- changed(); else #ifdef FEAT_NETBEANS_INTG ! // per netbeans undo rules, keep it as modified if (!isNetbeansModified(curbuf)) #endif unchanged(curbuf, FALSE, TRUE); *************** *** 2867,2896 **** } else { ! /* We get here with the current cursor line being past the end (eg ! * after adding lines at the end of the file, and then undoing it). ! * check_cursor() will move the cursor to the last line. Move it to ! * the first column here. */ curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; } ! /* Make sure the cursor is on an existing line and column. */ check_cursor(); ! /* Remember where we are for "g-" and ":earlier 10s". */ curbuf->b_u_seq_cur = curhead->uh_seq; if (undo) { ! /* We are below the previous undo. However, to make ":earlier 1s" ! * work we compute this as being just above the just undone change. */ if (curhead->uh_next.ptr != NULL) curbuf->b_u_seq_cur = curhead->uh_next.ptr->uh_seq; else curbuf->b_u_seq_cur = 0; } ! /* Remember where we are for ":earlier 1f" and ":later 1f". */ if (curhead->uh_save_nr != 0) { if (undo) --- 2867,2896 ---- } else { ! // We get here with the current cursor line being past the end (eg ! // after adding lines at the end of the file, and then undoing it). ! // check_cursor() will move the cursor to the last line. Move it to ! // the first column here. curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; } ! // Make sure the cursor is on an existing line and column. check_cursor(); ! // Remember where we are for "g-" and ":earlier 10s". curbuf->b_u_seq_cur = curhead->uh_seq; if (undo) { ! // We are below the previous undo. However, to make ":earlier 1s" ! // work we compute this as being just above the just undone change. if (curhead->uh_next.ptr != NULL) curbuf->b_u_seq_cur = curhead->uh_next.ptr->uh_seq; else curbuf->b_u_seq_cur = 0; } ! // Remember where we are for ":earlier 1f" and ":later 1f". if (curhead->uh_save_nr != 0) { if (undo) *************** *** 2899,2906 **** curbuf->b_u_save_nr_cur = curhead->uh_save_nr; } ! /* The timestamp can be the same for multiple changes, just use the one of ! * the undone/redone change. */ curbuf->b_u_time_cur = curhead->uh_time; unblock_autocmds(); --- 2899,2906 ---- curbuf->b_u_save_nr_cur = curhead->uh_save_nr; } ! // The timestamp can be the same for multiple changes, just use the one of ! // the undone/redone change. curbuf->b_u_time_cur = curhead->uh_time; unblock_autocmds(); *************** *** 2916,2923 **** */ static void u_undo_end( ! int did_undo, /* just did an undo */ ! int absolute) /* used ":undo N" */ { char *msgstr; u_header_T *uhp; --- 2916,2923 ---- */ static void u_undo_end( ! int did_undo, // just did an undo ! int absolute) // used ":undo N" { char *msgstr; u_header_T *uhp; *************** *** 2928,2935 **** foldOpenCursor(); #endif ! if (global_busy /* no messages now, wait until global is finished */ ! || !messaging()) /* 'lazyredraw' set, don't do messages now */ return; if (curbuf->b_ml.ml_flags & ML_EMPTY) --- 2928,2935 ---- foldOpenCursor(); #endif ! if (global_busy // no messages now, wait until global is finished ! || !messaging()) // 'lazyredraw' set, don't do messages now return; if (curbuf->b_ml.ml_flags & ML_EMPTY) *************** *** 2955,2961 **** if (curbuf->b_u_curhead != NULL) { ! /* For ":undo N" we prefer a "after #N" message. */ if (absolute && curbuf->b_u_curhead->uh_next.ptr != NULL) { uhp = curbuf->b_u_curhead->uh_next.ptr; --- 2955,2961 ---- if (curbuf->b_u_curhead != NULL) { ! // For ":undo N" we prefer a "after #N" message. if (absolute && curbuf->b_u_curhead->uh_next.ptr != NULL) { uhp = curbuf->b_u_curhead->uh_next.ptr; *************** *** 2999,3018 **** */ void u_sync( ! int force) /* Also sync when no_u_sync is set. */ { ! /* Skip it when already synced or syncing is disabled. */ if (curbuf->b_u_synced || (!force && no_u_sync > 0)) return; #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) if (p_imst == IM_ON_THE_SPOT && im_is_preediting()) ! return; /* XIM is busy, don't break an undo sequence */ #endif if (get_undolevel() < 0) ! curbuf->b_u_synced = TRUE; /* no entries, nothing to do */ else { ! u_getbot(); /* compute ue_bot of previous u_save */ curbuf->b_u_curhead = NULL; } } --- 2999,3018 ---- */ void u_sync( ! int force) // Also sync when no_u_sync is set. { ! // Skip it when already synced or syncing is disabled. if (curbuf->b_u_synced || (!force && no_u_sync > 0)) return; #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) if (p_imst == IM_ON_THE_SPOT && im_is_preediting()) ! return; // XIM is busy, don't break an undo sequence #endif if (get_undolevel() < 0) ! curbuf->b_u_synced = TRUE; // no entries, nothing to do else { ! u_getbot(); // compute ue_bot of previous u_save curbuf->b_u_curhead = NULL; } } *************** *** 3063,3069 **** uhp->uh_walk = mark; ! /* go down in the tree if we haven't been there */ if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark && uhp->uh_prev.ptr->uh_walk != mark) { --- 3063,3069 ---- uhp->uh_walk = mark; ! // go down in the tree if we haven't been there if (uhp->uh_prev.ptr != NULL && uhp->uh_prev.ptr->uh_walk != nomark && uhp->uh_prev.ptr->uh_walk != mark) { *************** *** 3071,3084 **** ++changes; } ! /* go to alternate branch if we haven't been there */ else if (uhp->uh_alt_next.ptr != NULL && uhp->uh_alt_next.ptr->uh_walk != nomark && uhp->uh_alt_next.ptr->uh_walk != mark) uhp = uhp->uh_alt_next.ptr; ! /* go up in the tree if we haven't been there and we are at the ! * start of alternate branches */ else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL && uhp->uh_next.ptr->uh_walk != nomark && uhp->uh_next.ptr->uh_walk != mark) --- 3071,3084 ---- ++changes; } ! // go to alternate branch if we haven't been there else if (uhp->uh_alt_next.ptr != NULL && uhp->uh_alt_next.ptr->uh_walk != nomark && uhp->uh_alt_next.ptr->uh_walk != mark) uhp = uhp->uh_alt_next.ptr; ! // go up in the tree if we haven't been there and we are at the ! // start of alternate branches else if (uhp->uh_next.ptr != NULL && uhp->uh_alt_prev.ptr == NULL && uhp->uh_next.ptr->uh_walk != nomark && uhp->uh_next.ptr->uh_walk != mark) *************** *** 3089,3095 **** else { ! /* need to backtrack; mark this node as done */ uhp->uh_walk = nomark; if (uhp->uh_alt_prev.ptr != NULL) uhp = uhp->uh_alt_prev.ptr; --- 3089,3095 ---- else { ! // need to backtrack; mark this node as done uhp->uh_walk = nomark; if (uhp->uh_alt_prev.ptr != NULL) uhp = uhp->uh_alt_prev.ptr; *************** *** 3130,3147 **** ex_undojoin(exarg_T *eap UNUSED) { if (curbuf->b_u_newhead == NULL) ! return; /* nothing changed before */ if (curbuf->b_u_curhead != NULL) { emsg(_("E790: undojoin is not allowed after undo")); return; } if (!curbuf->b_u_synced) ! return; /* already unsynced */ if (get_undolevel() < 0) ! return; /* no entries, nothing to do */ else ! /* Append next change to the last entry */ curbuf->b_u_synced = FALSE; } --- 3130,3147 ---- ex_undojoin(exarg_T *eap UNUSED) { if (curbuf->b_u_newhead == NULL) ! return; // nothing changed before if (curbuf->b_u_curhead != NULL) { emsg(_("E790: undojoin is not allowed after undo")); return; } if (!curbuf->b_u_synced) ! return; // already unsynced if (get_undolevel() < 0) ! return; // no entries, nothing to do else ! // Append next change to the last entry curbuf->b_u_synced = FALSE; } *************** *** 3168,3176 **** linenr_T lnum; if (curbuf->b_u_curhead != NULL || uhp == NULL) ! return; /* undid something in an autocmd? */ ! /* Check that the last undo block was for the whole file. */ uep = uhp->uh_entry; if (uep->ue_top != 0 || uep->ue_bot != 0) return; --- 3168,3176 ---- linenr_T lnum; if (curbuf->b_u_curhead != NULL || uhp == NULL) ! return; // undid something in an autocmd? ! // Check that the last undo block was for the whole file. uep = uhp->uh_entry; if (uep->ue_top != 0 || uep->ue_bot != 0) return; *************** *** 3190,3196 **** } if (curbuf->b_ml.ml_line_count != uep->ue_size) { ! /* lines added or deleted at the end, put the cursor there */ CLEAR_POS(&(uhp->uh_cursor)); uhp->uh_cursor.lnum = lnum; } --- 3190,3196 ---- } if (curbuf->b_ml.ml_line_count != uep->ue_size) { ! // lines added or deleted at the end, put the cursor there CLEAR_POS(&(uhp->uh_cursor)); uhp->uh_cursor.lnum = lnum; } *************** *** 3225,3231 **** { uh->uh_flags |= UH_CHANGED; if (uh->uh_alt_next.ptr != NULL) ! u_unch_branch(uh->uh_alt_next.ptr); /* recursive */ } } --- 3225,3231 ---- { uh->uh_flags |= UH_CHANGED; if (uh->uh_alt_next.ptr != NULL) ! u_unch_branch(uh->uh_alt_next.ptr); // recursive } } *************** *** 3254,3260 **** u_entry_T *uep; linenr_T extra; ! uep = u_get_headentry(); /* check for corrupt undo list */ if (uep == NULL) return; --- 3254,3260 ---- u_entry_T *uep; linenr_T extra; ! uep = u_get_headentry(); // check for corrupt undo list if (uep == NULL) return; *************** *** 3271,3280 **** if (uep->ue_bot < 1 || uep->ue_bot > curbuf->b_ml.ml_line_count) { iemsg(_("E440: undo line missing")); ! uep->ue_bot = uep->ue_top + 1; /* assume all lines deleted, will ! * get all the old lines back ! * without deleting the current ! * ones */ } curbuf->b_u_newhead->uh_getbot_entry = NULL; --- 3271,3280 ---- if (uep->ue_bot < 1 || uep->ue_bot > curbuf->b_ml.ml_line_count) { iemsg(_("E440: undo line missing")); ! uep->ue_bot = uep->ue_top + 1; // assume all lines deleted, will ! // get all the old lines back ! // without deleting the current ! // ones } curbuf->b_u_newhead->uh_getbot_entry = NULL; *************** *** 3290,3308 **** u_freeheader( buf_T *buf, u_header_T *uhp, ! u_header_T **uhpp) /* if not NULL reset when freeing this header */ { u_header_T *uhap; ! /* When there is an alternate redo list free that branch completely, ! * because we can never go there. */ if (uhp->uh_alt_next.ptr != NULL) u_freebranch(buf, uhp->uh_alt_next.ptr, uhpp); if (uhp->uh_alt_prev.ptr != NULL) uhp->uh_alt_prev.ptr->uh_alt_next.ptr = NULL; ! /* Update the links in the list to remove the header. */ if (uhp->uh_next.ptr == NULL) buf->b_u_oldhead = uhp->uh_prev.ptr; else --- 3290,3308 ---- u_freeheader( buf_T *buf, u_header_T *uhp, ! u_header_T **uhpp) // if not NULL reset when freeing this header { u_header_T *uhap; ! // When there is an alternate redo list free that branch completely, ! // because we can never go there. if (uhp->uh_alt_next.ptr != NULL) u_freebranch(buf, uhp->uh_alt_next.ptr, uhpp); if (uhp->uh_alt_prev.ptr != NULL) uhp->uh_alt_prev.ptr->uh_alt_next.ptr = NULL; ! // Update the links in the list to remove the header. if (uhp->uh_next.ptr == NULL) buf->b_u_oldhead = uhp->uh_prev.ptr; else *************** *** 3325,3336 **** u_freebranch( buf_T *buf, u_header_T *uhp, ! u_header_T **uhpp) /* if not NULL reset when freeing this header */ { u_header_T *tofree, *next; ! /* If this is the top branch we may need to use u_freeheader() to update ! * all the pointers. */ if (uhp == buf->b_u_oldhead) { while (buf->b_u_oldhead != NULL) --- 3325,3336 ---- u_freebranch( buf_T *buf, u_header_T *uhp, ! u_header_T **uhpp) // if not NULL reset when freeing this header { u_header_T *tofree, *next; ! // If this is the top branch we may need to use u_freeheader() to update ! // all the pointers. if (uhp == buf->b_u_oldhead) { while (buf->b_u_oldhead != NULL) *************** *** 3346,3352 **** { tofree = next; if (tofree->uh_alt_next.ptr != NULL) ! u_freebranch(buf, tofree->uh_alt_next.ptr, uhpp); /* recursive */ next = tofree->uh_prev.ptr; u_freeentries(buf, tofree, uhpp); } --- 3346,3352 ---- { tofree = next; if (tofree->uh_alt_next.ptr != NULL) ! u_freebranch(buf, tofree->uh_alt_next.ptr, uhpp); // recursive next = tofree->uh_prev.ptr; u_freeentries(buf, tofree, uhpp); } *************** *** 3360,3374 **** u_freeentries( buf_T *buf, u_header_T *uhp, ! u_header_T **uhpp) /* if not NULL reset when freeing this header */ { u_entry_T *uep, *nuep; ! /* Check for pointers to the header that become invalid now. */ if (buf->b_u_curhead == uhp) buf->b_u_curhead = NULL; if (buf->b_u_newhead == uhp) ! buf->b_u_newhead = NULL; /* freeing the newest entry */ if (uhpp != NULL && uhp == *uhpp) *uhpp = NULL; --- 3360,3374 ---- u_freeentries( buf_T *buf, u_header_T *uhp, ! u_header_T **uhpp) // if not NULL reset when freeing this header { u_entry_T *uep, *nuep; ! // Check for pointers to the header that become invalid now. if (buf->b_u_curhead == uhp) buf->b_u_curhead = NULL; if (buf->b_u_newhead == uhp) ! buf->b_u_newhead = NULL; // freeing the newest entry if (uhpp != NULL && uhp == *uhpp) *uhpp = NULL; *************** *** 3420,3428 **** static void u_saveline(linenr_T lnum) { ! if (lnum == curbuf->b_u_line_lnum) /* line is already saved */ return; ! if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) /* should never happen */ return; u_clearline(); curbuf->b_u_line_lnum = lnum; --- 3420,3428 ---- static void u_saveline(linenr_T lnum) { ! if (lnum == curbuf->b_u_line_lnum) // line is already saved return; ! if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) // should never happen return; u_clearline(); curbuf->b_u_line_lnum = lnum; *************** *** 3584,3590 **** if (alt_list != NULL) { ! /* Recursive call to add alternate undo tree. */ u_eval_tree(uhp->uh_alt_next.ptr, alt_list); dict_add_list(dict, "alt", alt_list); } --- 3584,3590 ---- if (alt_list != NULL) { ! // Recursive call to add alternate undo tree. u_eval_tree(uhp->uh_alt_next.ptr, alt_list); dict_add_list(dict, "alt", alt_list); } *************** *** 3608,3614 **** if (*fname == NUL) { ! /* If there is no file name there will be no undo file. */ rettv->vval.v_string = NULL; } else --- 3608,3614 ---- if (*fname == NUL) { ! // If there is no file name there will be no undo file. rettv->vval.v_string = NULL; } else *** ../vim-8.1.2395/src/uninstall.c 2019-09-27 13:07:59.573833437 +0200 --- src/uninstall.c 2019-12-05 21:41:17.373193585 +0100 *************** *** 17,23 **** * - the Vim entry in the Start Menu */ ! /* Include common code for dosinst.c and uninstall.c. */ #include "dosinst.h" /* --- 17,23 ---- * - the Vim entry in the Start Menu */ ! // Include common code for dosinst.c and uninstall.c. #include "dosinst.h" /* *************** *** 41,49 **** if (!did_load) { ! /* The RegDeleteKeyEx() function is only available on new systems. It ! * is required for 64-bit registry access. For other systems fall ! * back to RegDeleteKey(). */ did_load = TRUE; advapi_lib = LoadLibrary("ADVAPI32.DLL"); if (advapi_lib != NULL) --- 41,49 ---- if (!did_load) { ! // The RegDeleteKeyEx() function is only available on new systems. It ! // is required for 64-bit registry access. For other systems fall ! // back to RegDeleteKey(). did_load = TRUE; advapi_lib = LoadLibrary("ADVAPI32.DLL"); if (advapi_lib != NULL) *************** *** 66,79 **** DWORD value_type; int r; ! /* Open the key where the path to gvim.exe is stored. */ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0, KEY_WOW64_64KEY | KEY_READ, &key_handle) != ERROR_SUCCESS) if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0, KEY_WOW64_32KEY | KEY_READ, &key_handle) != ERROR_SUCCESS) return 0; ! /* get the DisplayName out of it to show the user */ r = RegQueryValueEx(key_handle, "path", 0, &value_type, (LPBYTE)buf, &bufsize); RegCloseKey(key_handle); --- 66,79 ---- DWORD value_type; int r; ! // Open the key where the path to gvim.exe is stored. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0, KEY_WOW64_64KEY | KEY_READ, &key_handle) != ERROR_SUCCESS) if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0, KEY_WOW64_32KEY | KEY_READ, &key_handle) != ERROR_SUCCESS) return 0; ! // get the DisplayName out of it to show the user r = RegQueryValueEx(key_handle, "path", 0, &value_type, (LPBYTE)buf, &bufsize); RegCloseKey(key_handle); *************** *** 92,104 **** DWORD value_type; int r; ! /* Open the key where the path to gvim.exe is stored. */ if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "Applications\\gvim.exe\\shell\\edit\\command", 0, KEY_WOW64_64KEY | KEY_READ, &key_handle) != ERROR_SUCCESS) return 0; ! /* get the DisplayName out of it to show the user */ r = RegQueryValueEx(key_handle, "", 0, &value_type, (LPBYTE)buf, &bufsize); RegCloseKey(key_handle); --- 92,104 ---- DWORD value_type; int r; ! // Open the key where the path to gvim.exe is stored. if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "Applications\\gvim.exe\\shell\\edit\\command", 0, KEY_WOW64_64KEY | KEY_READ, &key_handle) != ERROR_SUCCESS) return 0; ! // get the DisplayName out of it to show the user r = RegQueryValueEx(key_handle, "", 0, &value_type, (LPBYTE)buf, &bufsize); RegCloseKey(key_handle); *************** *** 210,216 **** while (fgets(line, sizeof(line), fd) != NULL) { for (p = line; *p != 0; ++p) ! /* don't accept "vim60an" when looking for "vim60". */ if (strnicmp(p, VIM_VERSION_NODOT, ver_len) == 0 && !isdigit(p[ver_len]) && !isalpha(p[ver_len])) --- 210,216 ---- while (fgets(line, sizeof(line), fd) != NULL) { for (p = line; *p != 0; ++p) ! // don't accept "vim60an" when looking for "vim60". if (strnicmp(p, VIM_VERSION_NODOT, ver_len) == 0 && !isdigit(p[ver_len]) && !isalpha(p[ver_len])) *************** *** 293,299 **** remove_if_exists(path, targets[i].lnkname); remove_if_exists(path, "uninstall.lnk"); remove_if_exists(path, "Help.lnk"); ! /* Win95 uses .pif, WinNT uses .lnk */ remove_if_exists(path, "Vim tutor.pif"); remove_if_exists(path, "Vim tutor.lnk"); remove_if_exists(path, "Vim online.url"); --- 293,299 ---- remove_if_exists(path, targets[i].lnkname); remove_if_exists(path, "uninstall.lnk"); remove_if_exists(path, "Help.lnk"); ! // Win95 uses .pif, WinNT uses .lnk remove_if_exists(path, "Vim tutor.pif"); remove_if_exists(path, "Vim tutor.lnk"); remove_if_exists(path, "Vim online.url"); *************** *** 322,334 **** char path[MAX_PATH]; char popup_path[MAX_PATH]; ! /* The nsis uninstaller calls us with a "-nsis" argument. */ if (argc == 2 && stricmp(argv[1], "-nsis") == 0) interactive = FALSE; else interactive = TRUE; ! /* Initialize this program. */ do_inits(argv); printf("This program will remove the following items:\n"); --- 322,334 ---- char path[MAX_PATH]; char popup_path[MAX_PATH]; ! // The nsis uninstaller calls us with a "-nsis" argument. if (argc == 2 && stricmp(argv[1], "-nsis") == 0) interactive = FALSE; else interactive = TRUE; ! // Initialize this program. do_inits(argv); printf("This program will remove the following items:\n"); *************** *** 342,349 **** if (!interactive || confirm()) { remove_popup(); ! /* Assume the "Open With" entry can be removed as well, don't ! * bother the user with asking him again. */ remove_openwith(); } } --- 342,349 ---- if (!interactive || confirm()) { remove_popup(); ! // Assume the "Open With" entry can be removed as well, don't ! // bother the user with asking him again. remove_openwith(); } } *** ../vim-8.1.2395/src/usercmd.c 2019-10-13 16:43:35.960359646 +0200 --- src/usercmd.c 2019-12-05 21:41:34.441134614 +0100 *************** *** 392,398 **** long a; garray_T *gap; ! /* In cmdwin, the alternative buffer should be used. */ gap = #ifdef FEAT_CMDWIN (cmdwin_type != 0 && get_cmdline_type() == NUL) ? --- 392,398 ---- long a; garray_T *gap; ! // In cmdwin, the alternative buffer should be used. gap = #ifdef FEAT_CMDWIN (cmdwin_type != 0 && get_cmdline_type() == NUL) ? *** ../vim-8.1.2395/src/userfunc.c 2019-11-10 00:13:46.434916175 +0100 --- src/userfunc.c 2019-12-05 21:42:45.388889511 +0100 *************** *** 30,36 **** */ static hashtab_T func_hashtab; ! /* Used by get_func_tv() */ static garray_T funcargs = GA_EMPTY; // pointer to funccal for currently active function --- 30,36 ---- */ static hashtab_T func_hashtab; ! // Used by get_func_tv() static garray_T funcargs = GA_EMPTY; // pointer to funccal for currently active function *************** *** 128,134 **** goto err_ret; } ! /* Check for duplicate argument name. */ for (i = 0; i < newargs->ga_len; ++i) if (STRCMP(((char_u **)(newargs->ga_data))[i], arg) == 0) { --- 128,134 ---- goto err_ret; } ! // Check for duplicate argument name. for (i = 0; i < newargs->ga_len; ++i) if (STRCMP(((char_u **)(newargs->ga_data))[i], arg) == 0) { *************** *** 193,199 **** } if (*p != endchar) goto err_ret; ! ++p; /* skip "endchar" */ *argp = p; return OK; --- 193,199 ---- } if (*p != endchar) goto err_ret; ! ++p; // skip "endchar" *argp = p; return OK; *************** *** 213,219 **** register_closure(ufunc_T *fp) { if (fp->uf_scoped == current_funccal) ! /* no change */ return OK; funccal_unref(fp->uf_scoped, fp, FALSE); fp->uf_scoped = current_funccal; --- 213,219 ---- register_closure(ufunc_T *fp) { if (fp->uf_scoped == current_funccal) ! // no change return OK; funccal_unref(fp->uf_scoped, fp, FALSE); fp->uf_scoped = current_funccal; *************** *** 249,260 **** ga_init(&newargs); ga_init(&newlines); ! /* First, check if this is a lambda expression. "->" must exist. */ ret = get_function_args(&start, '-', NULL, NULL, NULL, TRUE); if (ret == FAIL || *start != '>') return NOTDONE; ! /* Parse the arguments again. */ if (evaluate) pnewargs = &newargs; else --- 249,260 ---- ga_init(&newargs); ga_init(&newlines); ! // First, check if this is a lambda expression. "->" must exist. ret = get_function_args(&start, '-', NULL, NULL, NULL, TRUE); if (ret == FAIL || *start != '>') return NOTDONE; ! // Parse the arguments again. if (evaluate) pnewargs = &newargs; else *************** *** 264,274 **** if (ret == FAIL || **arg != '>') goto errret; ! /* Set up a flag for checking local variables and arguments. */ if (evaluate) eval_lavars_used = &eval_lavars; ! /* Get the start and the end of the expression. */ *arg = skipwhite(*arg + 1); s = *arg; ret = skip_expr(arg); --- 264,274 ---- if (ret == FAIL || **arg != '>') goto errret; ! // Set up a flag for checking local variables and arguments. if (evaluate) eval_lavars_used = &eval_lavars; ! // Get the start and the end of the expression. *arg = skipwhite(*arg + 1); s = *arg; ret = skip_expr(arg); *************** *** 299,305 **** if (ga_grow(&newlines, 1) == FAIL) goto errret; ! /* Add "return " before the expression. */ len = 7 + e - s + 1; p = alloc(len); if (p == NULL) --- 299,305 ---- if (ga_grow(&newlines, 1) == FAIL) goto errret; ! // Add "return " before the expression. len = 7 + e - s + 1; p = alloc(len); if (p == NULL) *************** *** 378,384 **** if (v->di_tv.vval.v_string == NULL) { *lenp = 0; ! return (char_u *)""; /* just in case */ } s = v->di_tv.vval.v_string; *lenp = (int)STRLEN(s); --- 378,384 ---- if (v->di_tv.vval.v_string == NULL) { *lenp = 0; ! return (char_u *)""; // just in case } s = v->di_tv.vval.v_string; *lenp = (int)STRLEN(s); *************** *** 392,398 **** if (pt == NULL) { *lenp = 0; ! return (char_u *)""; /* just in case */ } if (partialp != NULL) *partialp = pt; --- 392,398 ---- if (pt == NULL) { *lenp = 0; ! return (char_u *)""; // just in case } if (partialp != NULL) *partialp = pt; *************** *** 436,443 **** { char_u *argp; int ret = OK; ! typval_T argvars[MAX_FUNC_ARGS + 1]; /* vars for arguments */ ! int argcount = 0; /* number of arguments found */ /* * Get the arguments. --- 436,443 ---- { char_u *argp; int ret = OK; ! typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments ! int argcount = 0; // number of arguments found /* * Get the arguments. *************** *** 446,452 **** while (argcount < MAX_FUNC_ARGS - (funcexe->partial == NULL ? 0 : funcexe->partial->pt_argc)) { ! argp = skipwhite(argp + 1); /* skip the '(' or ',' */ if (*argp == ')' || *argp == ',' || *argp == NUL) break; if (eval1(&argp, &argvars[argcount], funcexe->evaluate) == FAIL) --- 446,452 ---- while (argcount < MAX_FUNC_ARGS - (funcexe->partial == NULL ? 0 : funcexe->partial->pt_argc)) { ! argp = skipwhite(argp + 1); // skip the '(' or ',' if (*argp == ')' || *argp == ',' || *argp == NUL) break; if (eval1(&argp, &argvars[argcount], funcexe->evaluate) == FAIL) *************** *** 469,476 **** if (get_vim_var_nr(VV_TESTING)) { ! /* Prepare for calling test_garbagecollect_now(), need to know ! * what variables are used on the call stack. */ if (funcargs.ga_itemsize == 0) ga_init2(&funcargs, (int)sizeof(typval_T *), 50); for (i = 0; i < argcount; ++i) --- 469,476 ---- if (get_vim_var_nr(VV_TESTING)) { ! // Prepare for calling test_garbagecollect_now(), need to know ! // what variables are used on the call stack. if (funcargs.ga_itemsize == 0) ga_init2(&funcargs, (int)sizeof(typval_T *), 50); for (i = 0; i < argcount; ++i) *************** *** 530,536 **** fname_buf[1] = KS_EXTRA; fname_buf[2] = (int)KE_SNR; i = 3; ! if (eval_fname_sid(name)) /* "" or "s:" */ { if (current_sctx.sc_sid <= 0) *error = ERROR_SCRIPT; --- 530,536 ---- fname_buf[1] = KS_EXTRA; fname_buf[2] = (int)KE_SNR; i = 3; ! if (eval_fname_sid(name)) // "" or "s:" { if (current_sctx.sc_sid <= 0) *error = ERROR_SCRIPT; *************** *** 751,763 **** */ static void call_user_func( ! ufunc_T *fp, /* pointer to function */ ! int argcount, /* nr of args */ ! typval_T *argvars, /* arguments */ ! typval_T *rettv, /* return value */ ! linenr_T firstline, /* first line of range */ ! linenr_T lastline, /* last line of range */ ! dict_T *selfdict) /* Dictionary for "self" */ { char_u *save_sourcing_name; linenr_T save_sourcing_lnum; --- 751,763 ---- */ static void call_user_func( ! ufunc_T *fp, // pointer to function ! int argcount, // nr of args ! typval_T *argvars, // arguments ! typval_T *rettv, // return value ! linenr_T firstline, // first line of range ! linenr_T lastline, // last line of range ! dict_T *selfdict) // Dictionary for "self" { char_u *save_sourcing_name; linenr_T save_sourcing_lnum; *************** *** 768,774 **** int default_arg_err = FALSE; static int depth = 0; dictitem_T *v; ! int fixvar_idx = 0; /* index in fixvar[] */ int i; int ai; int islambda = FALSE; --- 768,774 ---- int default_arg_err = FALSE; static int depth = 0; dictitem_T *v; ! int fixvar_idx = 0; // index in fixvar[] int i; int ai; int islambda = FALSE; *************** *** 781,787 **** int started_profiling = FALSE; #endif ! /* If depth of calling is getting too high, don't execute the function */ if (depth >= p_mfd) { emsg(_("E132: Function call depth is higher than 'maxfuncdepth'")); --- 781,787 ---- int started_profiling = FALSE; #endif ! // If depth of calling is getting too high, don't execute the function if (depth >= p_mfd) { emsg(_("E132: Function call depth is higher than 'maxfuncdepth'")); *************** *** 791,797 **** } ++depth; ! line_breakcheck(); /* check for CTRL-C hit */ fc = ALLOC_CLEAR_ONE(funccall_T); if (fc == NULL) --- 791,797 ---- } ++depth; ! line_breakcheck(); // check for CTRL-C hit fc = ALLOC_CLEAR_ONE(funccall_T); if (fc == NULL) *************** *** 804,813 **** fc->linenr = 0; fc->returned = FALSE; fc->level = ex_nesting_level; ! /* Check if this function has a breakpoint. */ fc->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0); fc->dbg_tick = debug_tick; ! /* Set up fields for closure. */ fc->fc_refcount = 0; fc->fc_copyID = 0; ga_init2(&fc->fc_funcs, sizeof(ufunc_T *), 1); --- 804,813 ---- fc->linenr = 0; fc->returned = FALSE; fc->level = ex_nesting_level; ! // Check if this function has a breakpoint. fc->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0); fc->dbg_tick = debug_tick; ! // Set up fields for closure. fc->fc_refcount = 0; fc->fc_copyID = 0; ga_init2(&fc->fc_funcs, sizeof(ufunc_T *), 1); *************** *** 827,834 **** init_var_dict(&fc->l_vars, &fc->l_vars_var, VAR_DEF_SCOPE); if (selfdict != NULL) { ! /* Set l:self to "selfdict". Use "name" to avoid a warning from ! * some compiler that checks the destination size. */ v = &fc->fixvar[fixvar_idx++].var; name = v->di_key; STRCPY(name, "self"); --- 827,834 ---- init_var_dict(&fc->l_vars, &fc->l_vars_var, VAR_DEF_SCOPE); if (selfdict != NULL) { ! // Set l:self to "selfdict". Use "name" to avoid a warning from ! // some compiler that checks the destination size. v = &fc->fixvar[fixvar_idx++].var; name = v->di_key; STRCPY(name, "self"); *************** *** 850,857 **** (varnumber_T)(argcount >= fp->uf_args.ga_len ? argcount - fp->uf_args.ga_len : 0)); fc->l_avars.dv_lock = VAR_FIXED; ! /* Use "name" to avoid a warning from some compiler that checks the ! * destination size. */ v = &fc->fixvar[fixvar_idx++].var; name = v->di_key; STRCPY(name, "000"); --- 850,857 ---- (varnumber_T)(argcount >= fp->uf_args.ga_len ? argcount - fp->uf_args.ga_len : 0)); fc->l_avars.dv_lock = VAR_FIXED; ! // Use "name" to avoid a warning from some compiler that checks the ! // destination size. v = &fc->fixvar[fixvar_idx++].var; name = v->di_key; STRCPY(name, "000"); *************** *** 882,888 **** ai = i - fp->uf_args.ga_len; if (ai < 0) { ! /* named argument a:name */ name = FUNCARG(fp, i); if (islambda) addlocal = TRUE; --- 882,888 ---- ai = i - fp->uf_args.ga_len; if (ai < 0) { ! // named argument a:name name = FUNCARG(fp, i); if (islambda) addlocal = TRUE; *************** *** 908,914 **** } else { ! /* "..." argument a:1, a:2, etc. */ sprintf((char *)numbuf, "%d", ai + 1); name = numbuf; } --- 908,914 ---- } else { ! // "..." argument a:1, a:2, etc. sprintf((char *)numbuf, "%d", ai + 1); name = numbuf; } *************** *** 933,940 **** if (addlocal) { ! /* Named arguments should be accessed without the "a:" prefix in ! * lambda expressions. Add to the l: dict. */ copy_tv(&v->di_tv, &v->di_tv); hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v)); } --- 933,940 ---- if (addlocal) { ! // Named arguments should be accessed without the "a:" prefix in ! // lambda expressions. Add to the l: dict. copy_tv(&v->di_tv, &v->di_tv); hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v)); } *************** *** 951,957 **** } } ! /* Don't redraw while executing the function. */ ++RedrawingDisabled; save_sourcing_name = sourcing_name; save_sourcing_lnum = sourcing_lnum; --- 951,957 ---- } } ! // Don't redraw while executing the function. ++RedrawingDisabled; save_sourcing_name = sourcing_name; save_sourcing_lnum = sourcing_lnum; *************** *** 963,969 **** ++sandbox; } ! /* need space for function name + ("function " + 3) or "[number]" */ len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) + STRLEN(fp->uf_name) + 20; sourcing_name = alloc(len); --- 963,969 ---- ++sandbox; } ! // need space for function name + ("function " + 3) or "[number]" len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) + STRLEN(fp->uf_name) + 20; sourcing_name = alloc(len); *************** *** 999,1005 **** msg_outnum((long)argvars[i].vval.v_number); else { ! /* Do not want errors such as E724 here. */ ++emsg_off; s = tv2string(&argvars[i], &tofree, numbuf2, 0); --emsg_off; --- 999,1005 ---- msg_outnum((long)argvars[i].vval.v_number); else { ! // Do not want errors such as E724 here. ++emsg_off; s = tv2string(&argvars[i], &tofree, numbuf2, 0); --emsg_off; *************** *** 1017,1023 **** } msg_puts(")"); } ! msg_puts("\n"); /* don't overwrite this either */ verbose_leave_scroll(); --no_wait_return; --- 1017,1023 ---- } msg_puts(")"); } ! msg_puts("\n"); // don't overwrite this either verbose_leave_scroll(); --no_wait_return; *************** *** 1056,1062 **** --RedrawingDisabled; ! /* when the function was aborted because of an error, return -1 */ if ((did_emsg && (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN) { clear_tv(rettv); --- 1056,1062 ---- --RedrawingDisabled; ! // when the function was aborted because of an error, return -1 if ((did_emsg && (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN) { clear_tv(rettv); *************** *** 1083,1089 **** } #endif ! /* when being verbose, mention the return value */ if (p_verbose >= 12) { ++no_wait_return; --- 1083,1089 ---- } #endif ! // when being verbose, mention the return value if (p_verbose >= 12) { ++no_wait_return; *************** *** 1101,1109 **** char_u *tofree; char_u *s; ! /* The value may be very long. Skip the middle part, so that we ! * have some idea how it starts and ends. smsg() would always ! * truncate it at the end. Don't want errors such as E724 here. */ ++emsg_off; s = tv2string(fc->rettv, &tofree, numbuf2, 0); --emsg_off; --- 1101,1109 ---- char_u *tofree; char_u *s; ! // The value may be very long. Skip the middle part, so that we ! // have some idea how it starts and ends. smsg() would always ! // truncate it at the end. Don't want errors such as E724 here. ++emsg_off; s = tv2string(fc->rettv, &tofree, numbuf2, 0); --emsg_off; *************** *** 1118,1124 **** vim_free(tofree); } } ! msg_puts("\n"); /* don't overwrite this either */ verbose_leave_scroll(); --no_wait_return; --- 1118,1124 ---- vim_free(tofree); } } ! msg_puts("\n"); // don't overwrite this either verbose_leave_scroll(); --no_wait_return; *************** *** 1141,1147 **** verbose_enter_scroll(); smsg(_("continuing in %s"), sourcing_name); ! msg_puts("\n"); /* don't overwrite this either */ verbose_leave_scroll(); --no_wait_return; --- 1141,1147 ---- verbose_enter_scroll(); smsg(_("continuing in %s"), sourcing_name); ! msg_puts("\n"); // don't overwrite this either verbose_leave_scroll(); --no_wait_return; *************** *** 1231,1237 **** return; fp->uf_cleared = TRUE; ! /* clear this function */ func_clear_items(fp); funccal_unref(fp->uf_scoped, fp, force); } --- 1231,1237 ---- return; fp->uf_cleared = TRUE; ! // clear this function func_clear_items(fp); funccal_unref(fp->uf_scoped, fp, force); } *************** *** 1243,1250 **** static void func_free(ufunc_T *fp) { ! /* only remove it when not done already, otherwise we would remove a newer ! * version of the function */ if ((fp->uf_flags & (FC_DELETED | FC_REMOVED)) == 0) func_remove(fp); --- 1243,1250 ---- static void func_free(ufunc_T *fp) { ! // only remove it when not done already, otherwise we would remove a newer ! // version of the function if ((fp->uf_flags & (FC_DELETED | FC_REMOVED)) == 0) func_remove(fp); *************** *** 1319,1325 **** long_u todo = 1; long_u used; ! /* Clean up the current_funccal chain and the funccal stack. */ while (current_funccal != NULL) { clear_tv(current_funccal->rettv); --- 1319,1325 ---- long_u todo = 1; long_u used; ! // Clean up the current_funccal chain and the funccal stack. while (current_funccal != NULL) { clear_tv(current_funccal->rettv); *************** *** 1328,1344 **** restore_funccal(); } ! /* First clear what the functions contain. Since this may lower the ! * reference count of a function, it may also free a function and change ! * the hash table. Restart if that happens. */ while (todo > 0) { todo = func_hashtab.ht_used; for (hi = func_hashtab.ht_array; todo > 0; ++hi) if (!HASHITEM_EMPTY(hi)) { ! /* Only free functions that are not refcounted, those are ! * supposed to be freed when no longer referenced. */ fp = HI2UF(hi); if (func_name_refcount(fp->uf_name)) ++skipped; --- 1328,1344 ---- restore_funccal(); } ! // First clear what the functions contain. Since this may lower the ! // reference count of a function, it may also free a function and change ! // the hash table. Restart if that happens. while (todo > 0) { todo = func_hashtab.ht_used; for (hi = func_hashtab.ht_array; todo > 0; ++hi) if (!HASHITEM_EMPTY(hi)) { ! // Only free functions that are not refcounted, those are ! // supposed to be freed when no longer referenced. fp = HI2UF(hi); if (func_name_refcount(fp->uf_name)) ++skipped; *************** *** 1356,1363 **** } } ! /* Now actually free the functions. Need to start all over every time, ! * because func_free() may change the hash table. */ skipped = 0; while (func_hashtab.ht_used > skipped) { --- 1356,1363 ---- } } ! // Now actually free the functions. Need to start all over every time, ! // because func_free() may change the hash table. skipped = 0; while (func_hashtab.ht_used > skipped) { *************** *** 1366,1373 **** if (!HASHITEM_EMPTY(hi)) { --todo; ! /* Only free functions that are not refcounted, those are ! * supposed to be freed when no longer referenced. */ fp = HI2UF(hi); if (func_name_refcount(fp->uf_name)) ++skipped; --- 1366,1373 ---- if (!HASHITEM_EMPTY(hi)) { --todo; ! // Only free functions that are not refcounted, those are ! // supposed to be freed when no longer referenced. fp = HI2UF(hi); if (func_name_refcount(fp->uf_name)) ++skipped; *************** *** 1421,1429 **** emsg(_("E699: Too many arguments")); break; } ! /* Make a copy of each argument. This is needed to be able to set ! * v_lock to VAR_FIXED in the copy without changing the original list. ! */ copy_tv(&item->li_tv, &argv[argc++]); } --- 1421,1428 ---- emsg(_("E699: Too many arguments")); break; } ! // Make a copy of each argument. This is needed to be able to set ! // v_lock to VAR_FIXED in the copy without changing the original list. copy_tv(&item->li_tv, &argv[argc++]); } *************** *** 1440,1446 **** r = call_func(name, -1, rettv, argc, argv, &funcexe); } ! /* Free the arguments. */ while (argc > 0) clear_tv(&argv[--argc]); --- 1439,1445 ---- r = call_func(name, -1, rettv, argc, argv, &funcexe); } ! // Free the arguments. while (argc > 0) clear_tv(&argv[--argc]); *************** *** 1529,1537 **** if (partial != NULL) { ! /* When the function has a partial with a dict and there is a dict ! * argument, use the dict argument. That is backwards compatible. ! * When the dict was bound explicitly use the one from the partial. */ if (partial->pt_dict != NULL && (selfdict == NULL || !partial->pt_auto)) selfdict = partial->pt_dict; if (error == ERROR_NONE && partial->pt_argc > 0) --- 1528,1536 ---- if (partial != NULL) { ! // When the function has a partial with a dict and there is a dict ! // argument, use the dict argument. That is backwards compatible. ! // When the dict was bound explicitly use the one from the partial. if (partial->pt_dict != NULL && (selfdict == NULL || !partial->pt_auto)) selfdict = partial->pt_dict; if (error == ERROR_NONE && partial->pt_argc > 0) *************** *** 1556,1566 **** { char_u *rfname = fname; ! /* Ignore "g:" before a function name. */ if (fname[0] == 'g' && fname[1] == ':') rfname = fname + 2; ! rettv->v_type = VAR_NUMBER; /* default rettv is number zero */ rettv->vval.v_number = 0; error = ERROR_UNKNOWN; --- 1555,1565 ---- { char_u *rfname = fname; ! // Ignore "g:" before a function name. if (fname[0] == 'g' && fname[1] == ':') rfname = fname + 2; ! rettv->v_type = VAR_NUMBER; // default rettv is number zero rettv->vval.v_number = 0; error = ERROR_UNKNOWN; *************** *** 1574,1592 **** else fp = find_func(rfname); ! /* Trigger FuncUndefined event, may load the function. */ if (fp == NULL && apply_autocmds(EVENT_FUNCUNDEFINED, rfname, rfname, TRUE, NULL) && !aborting()) { ! /* executed an autocommand, search for the function again */ fp = find_func(rfname); } ! /* Try loading a package. */ if (fp == NULL && script_autoload(rfname, TRUE) && !aborting()) { ! /* loaded a package, search for the function again */ fp = find_func(rfname); } --- 1573,1591 ---- else fp = find_func(rfname); ! // Trigger FuncUndefined event, may load the function. if (fp == NULL && apply_autocmds(EVENT_FUNCUNDEFINED, rfname, rfname, TRUE, NULL) && !aborting()) { ! // executed an autocommand, search for the function again fp = find_func(rfname); } ! // Try loading a package. if (fp == NULL && script_autoload(rfname, TRUE) && !aborting()) { ! // loaded a package, search for the function again fp = find_func(rfname); } *************** *** 1638,1645 **** funcexe->firstline, funcexe->lastline, (fp->uf_flags & FC_DICT) ? selfdict : NULL); if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0) ! /* Function was unreferenced while being used, free it ! * now. */ func_clear_free(fp, FALSE); if (did_save_redo) restoreRedobuff(&save_redo); --- 1637,1644 ---- funcexe->firstline, funcexe->lastline, (fp->uf_flags & FC_DICT) ? selfdict : NULL); if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0) ! // Function was unreferenced while being used, free it ! // now. func_clear_free(fp, FALSE); if (did_save_redo) restoreRedobuff(&save_redo); *************** *** 1796,1805 **** char_u * trans_function_name( char_u **pp, ! int skip, /* only find the end, don't evaluate */ int flags, ! funcdict_T *fdp, /* return: info about dictionary used */ ! partial_T **partial) /* return: partial of a FuncRef */ { char_u *name = NULL; char_u *start; --- 1795,1804 ---- char_u * trans_function_name( char_u **pp, ! int skip, // only find the end, don't evaluate int flags, ! funcdict_T *fdp, // return: info about dictionary used ! partial_T **partial) // return: partial of a FuncRef { char_u *name = NULL; char_u *start; *************** *** 1813,1820 **** vim_memset(fdp, 0, sizeof(funcdict_T)); start = *pp; ! /* Check for hard coded : already translated function ID (from a user ! * command). */ if ((*pp)[0] == K_SPECIAL && (*pp)[1] == KS_EXTRA && (*pp)[2] == (int)KE_SNR) { --- 1812,1819 ---- vim_memset(fdp, 0, sizeof(funcdict_T)); start = *pp; ! // Check for hard coded : already translated function ID (from a user ! // command). if ((*pp)[0] == K_SPECIAL && (*pp)[1] == KS_EXTRA && (*pp)[2] == (int)KE_SNR) { *************** *** 1823,1835 **** return vim_strnsave(start, len); } ! /* A name starting with "" or "" is local to a script. But ! * don't skip over "s:", get_lval() needs it for "s:dict.func". */ lead = eval_fname_script(start); if (lead > 2) start += lead; ! /* Note that TFN_ flags use the same values as GLV_ flags. */ end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY, lead > 2 ? 0 : FNE_CHECK_START); if (end == start) --- 1822,1834 ---- return vim_strnsave(start, len); } ! // A name starting with "" or "" is local to a script. But ! // don't skip over "s:", get_lval() needs it for "s:dict.func". lead = eval_fname_script(start); if (lead > 2) start += lead; ! // Note that TFN_ flags use the same values as GLV_ flags. end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY, lead > 2 ? 0 : FNE_CHECK_START); if (end == start) *************** *** 1891,1902 **** if (lv.ll_name == NULL) { ! /* Error found, but continue after the function name. */ *pp = end; goto theend; } ! /* Check if the name is a Funcref. If so, use the value. */ if (lv.ll_exp_name != NULL) { len = (int)STRLEN(lv.ll_exp_name); --- 1890,1901 ---- if (lv.ll_name == NULL) { ! // Error found, but continue after the function name. *pp = end; goto theend; } ! // Check if the name is a Funcref. If so, use the value. if (lv.ll_exp_name != NULL) { len = (int)STRLEN(lv.ll_exp_name); *************** *** 1918,1924 **** *pp = end; if (STRNCMP(name, "", 5) == 0) { ! /* Change "" to the byte sequence. */ name[0] = K_SPECIAL; name[1] = KS_EXTRA; name[2] = (int)KE_SNR; --- 1917,1923 ---- *pp = end; if (STRNCMP(name, "", 5) == 0) { ! // Change "" to the byte sequence. name[0] = K_SPECIAL; name[1] = KS_EXTRA; name[2] = (int)KE_SNR; *************** *** 1933,1940 **** if (lead <= 2 && lv.ll_name == lv.ll_exp_name && STRNCMP(lv.ll_name, "s:", 2) == 0) { ! /* When there was "s:" already or the name expanded to get a ! * leading "s:" then remove it. */ lv.ll_name += 2; len -= 2; lead = 2; --- 1932,1939 ---- if (lead <= 2 && lv.ll_name == lv.ll_exp_name && STRNCMP(lv.ll_name, "s:", 2) == 0) { ! // When there was "s:" already or the name expanded to get a ! // leading "s:" then remove it. lv.ll_name += 2; len -= 2; lead = 2; *************** *** 1942,1948 **** } else { ! /* skip over "s:" and "g:" */ if (lead == 2 || (lv.ll_name[0] == 'g' && lv.ll_name[1] == ':')) lv.ll_name += 2; len = (int)(end - lv.ll_name); --- 1941,1947 ---- } else { ! // skip over "s:" and "g:" if (lead == 2 || (lv.ll_name[0] == 'g' && lv.ll_name[1] == ':')) lv.ll_name += 2; len = (int)(end - lv.ll_name); *************** *** 1954,1967 **** * Accept 123_name() outside a script. */ if (skip) ! lead = 0; /* do nothing */ else if (lead > 0) { lead = 3; if ((lv.ll_exp_name != NULL && eval_fname_sid(lv.ll_exp_name)) || eval_fname_sid(*pp)) { ! /* It's "s:" or "" */ if (current_sctx.sc_sid <= 0) { emsg(_(e_usingsid)); --- 1953,1966 ---- * Accept 123_name() outside a script. */ if (skip) ! lead = 0; // do nothing else if (lead > 0) { lead = 3; if ((lv.ll_exp_name != NULL && eval_fname_sid(lv.ll_exp_name)) || eval_fname_sid(*pp)) { ! // It's "s:" or "" if (current_sctx.sc_sid <= 0) { emsg(_(e_usingsid)); *************** *** 1996,2002 **** name[0] = K_SPECIAL; name[1] = KS_EXTRA; name[2] = (int)KE_SNR; ! if (lead > 3) /* If it's "" */ STRCPY(name + 3, sid_buf); } mch_memmove(name + lead, lv.ll_name, (size_t)len); --- 1995,2001 ---- name[0] = K_SPECIAL; name[1] = KS_EXTRA; name[2] = (int)KE_SNR; ! if (lead > 3) // If it's "" STRCPY(name + 3, sid_buf); } mch_memmove(name + lead, lv.ll_name, (size_t)len); *************** *** 2036,2042 **** int nesting; dictitem_T *v; funcdict_T fudi; ! static int func_nr = 0; /* number for nameless function */ int paren; hashtab_T *ht; int todo; --- 2035,2041 ---- int nesting; dictitem_T *v; funcdict_T fudi; ! static int func_nr = 0; // number for nameless function int paren; hashtab_T *ht; int todo; *************** *** 2149,2156 **** eap->skip = TRUE; } ! /* An error in a function call during evaluation of an expression in magic ! * braces should not cause the function not to be defined. */ saved_did_emsg = did_emsg; did_emsg = FALSE; --- 2148,2155 ---- eap->skip = TRUE; } ! // An error in a function call during evaluation of an expression in magic ! // braces should not cause the function not to be defined. saved_did_emsg = did_emsg; did_emsg = FALSE; *************** *** 2184,2190 **** if (j < 99) msg_putchar(' '); msg_prt_line(FUNCLINE(fp, j), FALSE); ! out_flush(); /* show a line at a time */ ui_breakcheck(); } if (!got_int) --- 2183,2189 ---- if (j < 99) msg_putchar(' '); msg_prt_line(FUNCLINE(fp, j), FALSE); ! out_flush(); // show a line at a time ui_breakcheck(); } if (!got_int) *************** *** 2210,2216 **** semsg(_("E124: Missing '(': %s"), eap->arg); goto ret_free; } ! /* attempt to continue by skipping some text */ if (vim_strchr(p, '(') != NULL) p = vim_strchr(p, '('); } --- 2209,2215 ---- semsg(_("E124: Missing '(': %s"), eap->arg); goto ret_free; } ! // attempt to continue by skipping some text if (vim_strchr(p, '(') != NULL) p = vim_strchr(p, '('); } *************** *** 2220,2227 **** if (!eap->skip) { ! /* Check the name of the function. Unless it's a dictionary function ! * (that we are overwriting). */ if (name != NULL) arg = name; else --- 2219,2226 ---- if (!eap->skip) { ! // Check the name of the function. Unless it's a dictionary function ! // (that we are overwriting). if (name != NULL) arg = name; else *************** *** 2240,2246 **** if (arg[j] != NUL) emsg_funcname((char *)e_invarg2, arg); } ! /* Disallow using the g: dict. */ if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE) emsg(_("E862: Cannot use g: here")); } --- 2239,2245 ---- if (arg[j] != NUL) emsg_funcname((char *)e_invarg2, arg); } ! // Disallow using the g: dict. if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE) emsg(_("E862: Cannot use g: here")); } *************** *** 2249,2255 **** &default_args, eap->skip) == FAIL) goto errret_2; ! /* find extra arguments "range", "dict", "abort" and "closure" */ for (;;) { p = skipwhite(p); --- 2248,2254 ---- &default_args, eap->skip) == FAIL) goto errret_2; ! // find extra arguments "range", "dict", "abort" and "closure" for (;;) { p = skipwhite(p); *************** *** 2283,2290 **** break; } ! /* When there is a line break use what follows for the function body. ! * Makes 'exe "func Test()\n...\nendfunc"' work. */ if (*p == '\n') line_arg = p + 1; else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg) --- 2282,2289 ---- break; } ! // When there is a line break use what follows for the function body. ! // Makes 'exe "func Test()\n...\nendfunc"' work. if (*p == '\n') line_arg = p + 1; else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg) *************** *** 2295,2303 **** */ if (KeyTyped) { ! /* Check if the function already exists, don't let the user type the ! * whole function before telling him it doesn't work! For a script we ! * need to skip the body to be able to find what follows. */ if (!eap->skip && !eap->forceit) { if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) --- 2294,2302 ---- */ if (KeyTyped) { ! // Check if the function already exists, don't let the user type the ! // whole function before telling him it doesn't work! For a script we ! // need to skip the body to be able to find what follows. if (!eap->skip && !eap->forceit) { if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) *************** *** 2309,2315 **** if (!eap->skip && did_emsg) goto erret; ! msg_putchar('\n'); /* don't overwrite the function name */ cmdline_row = msg_row; } --- 2308,2314 ---- if (!eap->skip && did_emsg) goto erret; ! msg_putchar('\n'); // don't overwrite the function name cmdline_row = msg_row; } *************** *** 2329,2335 **** if (line_arg != NULL) { ! /* Use eap->arg, split up in parts by line breaks. */ theline = line_arg; p = vim_strchr(theline, '\n'); if (p == NULL) --- 2328,2334 ---- if (line_arg != NULL) { ! // Use eap->arg, split up in parts by line breaks. theline = line_arg; p = vim_strchr(theline, '\n'); if (p == NULL) *************** *** 2357,2363 **** goto erret; } ! /* Detect line continuation: sourcing_lnum increased more than one. */ sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie); if (sourcing_lnum < sourcing_lnum_off) sourcing_lnum_off -= sourcing_lnum; --- 2356,2362 ---- goto erret; } ! // Detect line continuation: sourcing_lnum increased more than one. sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie); if (sourcing_lnum < sourcing_lnum_off) sourcing_lnum_off -= sourcing_lnum; *************** *** 2393,2403 **** } else { ! /* skip ':' and blanks*/ for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p) ; ! /* Check for "endfunction". */ if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) { char_u *nextcmd = NULL; --- 2392,2402 ---- } else { ! // skip ':' and blanks for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p) ; ! // Check for "endfunction". if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) { char_u *nextcmd = NULL; *************** *** 2412,2420 **** p, TRUE); if (nextcmd != NULL) { ! /* Another command follows. If the line came from "eap" we ! * can simply point into it, otherwise we need to change ! * "eap->cmdlinep". */ eap->nextcmd = nextcmd; if (line_to_free != NULL) { --- 2411,2419 ---- p, TRUE); if (nextcmd != NULL) { ! // Another command follows. If the line came from "eap" we ! // can simply point into it, otherwise we need to change ! // "eap->cmdlinep". eap->nextcmd = nextcmd; if (line_to_free != NULL) { *************** *** 2426,2433 **** break; } ! /* Increase indent inside "if", "while", "for" and "try", decrease ! * at "end". */ if (indent > 2 && STRNCMP(p, "end", 3) == 0) indent -= 2; else if (STRNCMP(p, "if", 2) == 0 --- 2425,2432 ---- break; } ! // Increase indent inside "if", "while", "for" and "try", decrease ! // at "end". if (indent > 2 && STRNCMP(p, "end", 3) == 0) indent -= 2; else if (STRNCMP(p, "if", 2) == 0 *************** *** 2436,2442 **** || STRNCMP(p, "try", 3) == 0) indent += 2; ! /* Check for defining a function inside this function. */ if (checkforcmd(&p, "function", 2)) { if (*p == '!') --- 2435,2441 ---- || STRNCMP(p, "try", 3) == 0) indent += 2; ! // Check for defining a function inside this function. if (checkforcmd(&p, "function", 2)) { if (*p == '!') *************** *** 2450,2456 **** } } ! /* Check for ":append", ":change", ":insert". */ p = skip_range(p, NULL); if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) || (p[0] == 'c' --- 2449,2455 ---- } } ! // Check for ":append", ":change", ":insert". p = skip_range(p, NULL); if ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) || (p[0] == 'c' *************** *** 2463,2469 **** && (!ASCII_ISALPHA(p[2]) || (p[2] == 's')))))) skip_until = vim_strsave((char_u *)"."); ! /* Check for ":python < 0) ((char_u **)(newlines.ga_data))[newlines.ga_len++] = NULL; ! /* Check for end of eap->arg. */ if (line_arg != NULL && *line_arg == NUL) line_arg = NULL; } ! /* Don't define the function when skipping commands or when an error was ! * detected. */ if (eap->skip || did_emsg) goto erret; --- 2518,2547 ---- } } ! // Add the line to the function. if (ga_grow(&newlines, 1 + sourcing_lnum_off) == FAIL) goto erret; ! // Copy the line to newly allocated memory. get_one_sourceline() ! // allocates 250 bytes per line, this saves 80% on average. The cost ! // is an extra alloc/free. p = vim_strsave(theline); if (p == NULL) goto erret; ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p; ! // Add NULL lines for continuation lines, so that the line count is ! // equal to the index in the growarray. while (sourcing_lnum_off-- > 0) ((char_u **)(newlines.ga_data))[newlines.ga_len++] = NULL; ! // Check for end of eap->arg. if (line_arg != NULL && *line_arg == NUL) line_arg = NULL; } ! // Don't define the function when skipping commands or when an error was ! // detected. if (eap->skip || did_emsg) goto erret; *************** *** 2580,2587 **** } if (fp->uf_refcount > 1) { ! /* This function is referenced somewhere, don't redefine it but ! * create a new one. */ --fp->uf_refcount; fp->uf_flags |= FC_REMOVED; fp = NULL; --- 2579,2586 ---- } if (fp->uf_refcount > 1) { ! // This function is referenced somewhere, don't redefine it but ! // create a new one. --fp->uf_refcount; fp->uf_flags |= FC_REMOVED; fp = NULL; *************** *** 2589,2595 **** } else { ! /* redefine existing function */ VIM_CLEAR(name); func_clear_items(fp); #ifdef FEAT_PROFILE --- 2588,2594 ---- } else { ! // redefine existing function VIM_CLEAR(name); func_clear_items(fp); #ifdef FEAT_PROFILE *************** *** 2611,2626 **** } if (fudi.fd_di == NULL) { ! /* Can't add a function to a locked dictionary */ if (var_check_lock(fudi.fd_dict->dv_lock, eap->arg, FALSE)) goto erret; } ! /* Can't change an existing function if it is locked */ else if (var_check_lock(fudi.fd_di->di_tv.v_lock, eap->arg, FALSE)) goto erret; ! /* Give the function a sequential number. Can only be used with a ! * Funcref! */ vim_free(name); sprintf(numbuf, "%d", ++func_nr); name = vim_strsave((char_u *)numbuf); --- 2610,2625 ---- } if (fudi.fd_di == NULL) { ! // Can't add a function to a locked dictionary if (var_check_lock(fudi.fd_dict->dv_lock, eap->arg, FALSE)) goto erret; } ! // Can't change an existing function if it is locked else if (var_check_lock(fudi.fd_di->di_tv.v_lock, eap->arg, FALSE)) goto erret; ! // Give the function a sequential number. Can only be used with a ! // Funcref! vim_free(name); sprintf(numbuf, "%d", ++func_nr); name = vim_strsave((char_u *)numbuf); *************** *** 2635,2641 **** int slen, plen; char_u *scriptname; ! /* Check that the autoload name matches the script name. */ j = FAIL; if (sourcing_name != NULL) { --- 2634,2640 ---- int slen, plen; char_u *scriptname; ! // Check that the autoload name matches the script name. j = FAIL; if (sourcing_name != NULL) { *************** *** 2666,2672 **** { if (fudi.fd_di == NULL) { ! /* add new dict entry */ fudi.fd_di = dictitem_alloc(fudi.fd_newkey); if (fudi.fd_di == NULL) { --- 2665,2671 ---- { if (fudi.fd_di == NULL) { ! // add new dict entry fudi.fd_di = dictitem_alloc(fudi.fd_newkey); if (fudi.fd_di == NULL) { *************** *** 2681,2696 **** } } else ! /* overwrite existing dict entry */ clear_tv(&fudi.fd_di->di_tv); fudi.fd_di->di_tv.v_type = VAR_FUNC; fudi.fd_di->di_tv.vval.v_string = vim_strsave(name); ! /* behave like "dict" was used */ flags |= FC_DICT; } ! /* insert the new function in the function list */ STRCPY(fp->uf_name, name); if (overwrite) { --- 2680,2695 ---- } } else ! // overwrite existing dict entry clear_tv(&fudi.fd_di->di_tv); fudi.fd_di->di_tv.v_type = VAR_FUNC; fudi.fd_di->di_tv.vval.v_string = vim_strsave(name); ! // behave like "dict" was used flags |= FC_DICT; } ! // insert the new function in the function list STRCPY(fp->uf_name, name); if (overwrite) { *************** *** 2750,2757 **** int eval_fname_script(char_u *p) { ! /* Use MB_STRICMP() because in Turkish comparing the "I" may not work with ! * the standard library function. */ if (p[0] == '<' && (MB_STRNICMP(p + 1, "SID>", 4) == 0 || MB_STRNICMP(p + 1, "SNR>", 4) == 0)) return 5; --- 2749,2756 ---- int eval_fname_script(char_u *p) { ! // Use MB_STRICMP() because in Turkish comparing the "I" may not work with ! // the standard library function. if (p[0] == '<' && (MB_STRNICMP(p + 1, "SID>", 4) == 0 || MB_STRNICMP(p + 1, "SNR>", 4) == 0)) return 5; *************** *** 2786,2793 **** p = trans_function_name(&nm, FALSE, flag, NULL, NULL); nm = skipwhite(nm); ! /* Only accept "funcname", "funcname ", "funcname (..." and ! * "funcname(...", not "funcname!...". */ if (p != NULL && (*nm == NUL || *nm == '(')) n = translated_function_exists(p); vim_free(p); --- 2785,2792 ---- p = trans_function_name(&nm, FALSE, flag, NULL, NULL); nm = skipwhite(nm); ! // Only accept "funcname", "funcname ", "funcname (..." and ! // "funcname(...", not "funcname!...". if (p != NULL && (*nm == NUL || *nm == '(')) n = translated_function_exists(p); vim_free(p); *************** *** 2838,2847 **** if ((fp->uf_flags & FC_DICT) || STRNCMP(fp->uf_name, "", 8) == 0) ! return (char_u *)""; /* don't show dict and lambda functions */ if (STRLEN(fp->uf_name) + 4 >= IOSIZE) ! return fp->uf_name; /* prevents overflow */ cat_func_name(IObuff, fp); if (xp->xp_context != EXPAND_USER_FUNC) --- 2837,2846 ---- if ((fp->uf_flags & FC_DICT) || STRNCMP(fp->uf_name, "", 8) == 0) ! return (char_u *)""; // don't show dict and lambda functions if (STRLEN(fp->uf_name) + 4 >= IOSIZE) ! return fp->uf_name; // prevents overflow cat_func_name(IObuff, fp); if (xp->xp_context != EXPAND_USER_FUNC) *************** *** 2905,2925 **** if (fudi.fd_dict != NULL) { ! /* Delete the dict item that refers to the function, it will ! * invoke func_unref() and possibly delete the function. */ dictitem_remove(fudi.fd_dict, fudi.fd_di); } else { ! /* A normal function (not a numbered function or lambda) has a ! * refcount of 1 for the entry in the hashtable. When deleting ! * it and the refcount is more than one, it should be kept. ! * A numbered function and lambda should be kept if the refcount is ! * one or more. */ if (fp->uf_refcount > (func_name_refcount(fp->uf_name) ? 0 : 1)) { ! /* Function is still referenced somewhere. Don't free it but ! * do remove it from the hashtable. */ if (func_remove(fp)) fp->uf_refcount--; fp->uf_flags |= FC_DELETED; --- 2904,2924 ---- if (fudi.fd_dict != NULL) { ! // Delete the dict item that refers to the function, it will ! // invoke func_unref() and possibly delete the function. dictitem_remove(fudi.fd_dict, fudi.fd_di); } else { ! // A normal function (not a numbered function or lambda) has a ! // refcount of 1 for the entry in the hashtable. When deleting ! // it and the refcount is more than one, it should be kept. ! // A numbered function and lambda should be kept if the refcount is ! // one or more. if (fp->uf_refcount > (func_name_refcount(fp->uf_name) ? 0 : 1)) { ! // Function is still referenced somewhere. Don't free it but ! // do remove it from the hashtable. if (func_remove(fp)) fp->uf_refcount--; fp->uf_flags |= FC_DELETED; *************** *** 2951,2958 **** } if (fp != NULL && --fp->uf_refcount <= 0) { ! /* Only delete it when it's not being used. Otherwise it's done ! * when "uf_calls" becomes zero. */ if (fp->uf_calls == 0) func_clear_free(fp, FALSE); } --- 2950,2957 ---- } if (fp != NULL && --fp->uf_refcount <= 0) { ! // Only delete it when it's not being used. Otherwise it's done ! // when "uf_calls" becomes zero. if (fp->uf_calls == 0) func_clear_free(fp, FALSE); } *************** *** 2967,2974 **** { if (fp != NULL && --fp->uf_refcount <= 0) { ! /* Only delete it when it's not being used. Otherwise it's done ! * when "uf_calls" becomes zero. */ if (fp->uf_calls == 0) func_clear_free(fp, FALSE); } --- 2966,2973 ---- { if (fp != NULL && --fp->uf_refcount <= 0) { ! // Only delete it when it's not being used. Otherwise it's done ! // when "uf_calls" becomes zero. if (fp->uf_calls == 0) func_clear_free(fp, FALSE); } *************** *** 2988,2995 **** if (fp != NULL) ++fp->uf_refcount; else if (isdigit(*name)) ! /* Only give an error for a numbered function. ! * Fail silently, when named or lambda function isn't found. */ internal_error("func_ref()"); } --- 2987,2994 ---- if (fp != NULL) ++fp->uf_refcount; else if (isdigit(*name)) ! // Only give an error for a numbered function. ! // Fail silently, when named or lambda function isn't found. internal_error("func_ref()"); } *************** *** 3044,3053 **** else clear_tv(&rettv); } ! /* It's safer to return also on error. */ else if (!eap->skip) { ! /* In return statement, cause_abort should be force_abort. */ update_force_abort(); /* --- 3043,3052 ---- else clear_tv(&rettv); } ! // It's safer to return also on error. else if (!eap->skip) { ! // In return statement, cause_abort should be force_abort. update_force_abort(); /* *************** *** 3058,3069 **** returning = do_return(eap, FALSE, TRUE, NULL); } ! /* When skipping or the return gets pending, advance to the next command ! * in this line (!returning). Otherwise, ignore the rest of the line. ! * Following lines will be ignored by get_func_line(). */ if (returning) eap->nextcmd = NULL; ! else if (eap->nextcmd == NULL) /* no argument */ eap->nextcmd = check_nextcmd(arg); if (eap->skip) --- 3057,3068 ---- returning = do_return(eap, FALSE, TRUE, NULL); } ! // When skipping or the return gets pending, advance to the next command ! // in this line (!returning). Otherwise, ignore the rest of the line. ! // Following lines will be ignored by get_func_line(). if (returning) eap->nextcmd = NULL; ! else if (eap->nextcmd == NULL) // no argument eap->nextcmd = check_nextcmd(arg); if (eap->skip) *************** *** 3090,3098 **** if (eap->skip) { ! /* trans_function_name() doesn't work well when skipping, use eval0() ! * instead to skip to any following command, e.g. for: ! * :if 0 | call dict.foo().bar() | endif */ ++emsg_skip; if (eval0(eap->arg, &rettv, &eap->nextcmd, FALSE) != FAIL) clear_tv(&rettv); --- 3089,3097 ---- if (eap->skip) { ! // trans_function_name() doesn't work well when skipping, use eval0() ! // instead to skip to any following command, e.g. for: ! // :if 0 | call dict.foo().bar() | endif ++emsg_skip; if (eval0(eap->arg, &rettv, &eap->nextcmd, FALSE) != FAIL) clear_tv(&rettv); *************** *** 3103,3131 **** tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi, &partial); if (fudi.fd_newkey != NULL) { ! /* Still need to give an error message for missing key. */ semsg(_(e_dictkey), fudi.fd_newkey); vim_free(fudi.fd_newkey); } if (tofree == NULL) return; ! /* Increase refcount on dictionary, it could get deleted when evaluating ! * the arguments. */ if (fudi.fd_dict != NULL) ++fudi.fd_dict->dv_refcount; ! /* If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its ! * contents. For VAR_PARTIAL get its partial, unless we already have one ! * from trans_function_name(). */ len = (int)STRLEN(tofree); name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, FALSE); ! /* Skip white space to allow ":call func ()". Not good, but required for ! * backward compatibility. */ startarg = skipwhite(arg); ! rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */ if (*startarg != '(') { --- 3102,3130 ---- tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi, &partial); if (fudi.fd_newkey != NULL) { ! // Still need to give an error message for missing key. semsg(_(e_dictkey), fudi.fd_newkey); vim_free(fudi.fd_newkey); } if (tofree == NULL) return; ! // Increase refcount on dictionary, it could get deleted when evaluating ! // the arguments. if (fudi.fd_dict != NULL) ++fudi.fd_dict->dv_refcount; ! // If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its ! // contents. For VAR_PARTIAL get its partial, unless we already have one ! // from trans_function_name(). len = (int)STRLEN(tofree); name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, FALSE); ! // Skip white space to allow ":call func ()". Not good, but required for ! // backward compatibility. startarg = skipwhite(arg); ! rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this if (*startarg != '(') { *************** *** 3142,3148 **** if (eap->skip) { ++emsg_skip; ! lnum = eap->line2; /* do it once, also with an invalid range */ } else lnum = eap->line1; --- 3141,3147 ---- if (eap->skip) { ++emsg_skip; ! lnum = eap->line2; // do it once, also with an invalid range } else lnum = eap->line1; *************** *** 3192,3201 **** if (doesrange || eap->skip) break; ! /* Stop when immediately aborting on error, or when an interrupt ! * occurred or an exception was thrown but not caught. ! * get_func_tv() returned OK, so that the check for trailing ! * characters below is executed. */ if (aborting()) break; } --- 3191,3200 ---- if (doesrange || eap->skip) break; ! // Stop when immediately aborting on error, or when an interrupt ! // occurred or an exception was thrown but not caught. ! // get_func_tv() returned OK, so that the check for trailing ! // characters below is executed. if (aborting()) break; } *************** *** 3204,3210 **** if (!failed) { ! /* Check for trailing illegal characters and a following command. */ if (!ends_excmd(*arg)) { emsg_severe = TRUE; --- 3203,3209 ---- if (!failed) { ! // Check for trailing illegal characters and a following command. if (!ends_excmd(*arg)) { emsg_severe = TRUE; *************** *** 3238,3244 **** struct condstack *cstack = eap->cstack; if (reanimate) ! /* Undo the return. */ current_funccal->returned = FALSE; /* --- 3237,3243 ---- struct condstack *cstack = eap->cstack; if (reanimate) ! // Undo the return. current_funccal->returned = FALSE; /* *************** *** 3253,3272 **** cstack->cs_pending[idx] = CSTP_RETURN; if (!is_cmd && !reanimate) ! /* A pending return again gets pending. "rettv" points to an ! * allocated variable with the rettv of the original ":return"'s ! * argument if present or is NULL else. */ cstack->cs_rettv[idx] = rettv; else { ! /* When undoing a return in order to make it pending, get the stored ! * return rettv. */ if (reanimate) rettv = current_funccal->rettv; if (rettv != NULL) { ! /* Store the value of the pending return. */ if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL) *(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv; else --- 3252,3271 ---- cstack->cs_pending[idx] = CSTP_RETURN; if (!is_cmd && !reanimate) ! // A pending return again gets pending. "rettv" points to an ! // allocated variable with the rettv of the original ":return"'s ! // argument if present or is NULL else. cstack->cs_rettv[idx] = rettv; else { ! // When undoing a return in order to make it pending, get the stored ! // return rettv. if (reanimate) rettv = current_funccal->rettv; if (rettv != NULL) { ! // Store the value of the pending return. if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL) *(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv; else *************** *** 3277,3285 **** if (reanimate) { ! /* The pending return value could be overwritten by a ":return" ! * without argument in a finally clause; reset the default ! * return value. */ current_funccal->rettv->v_type = VAR_NUMBER; current_funccal->rettv->vval.v_number = 0; } --- 3276,3284 ---- if (reanimate) { ! // The pending return value could be overwritten by a ":return" ! // without argument in a finally clause; reset the default ! // return value. current_funccal->rettv->v_type = VAR_NUMBER; current_funccal->rettv->vval.v_number = 0; } *************** *** 3290,3298 **** { current_funccal->returned = TRUE; ! /* If the return is carried out now, store the return value. For ! * a return immediately after reanimation, the value is already ! * there. */ if (!reanimate && rettv != NULL) { clear_tv(current_funccal->rettv); --- 3289,3297 ---- { current_funccal->returned = TRUE; ! // If the return is carried out now, store the return value. For ! // a return immediately after reanimation, the value is already ! // there. if (!reanimate && rettv != NULL) { clear_tv(current_funccal->rettv); *************** *** 3353,3361 **** funccall_T *fcp = (funccall_T *)cookie; ufunc_T *fp = fcp->func; char_u *retval; ! garray_T *gap; /* growarray with function lines */ ! /* If breakpoints have been added/deleted need to check for it. */ if (fcp->dbg_tick != debug_tick) { fcp->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, --- 3352,3360 ---- funccall_T *fcp = (funccall_T *)cookie; ufunc_T *fp = fcp->func; char_u *retval; ! garray_T *gap; // growarray with function lines ! // If breakpoints have been added/deleted need to check for it. if (fcp->dbg_tick != debug_tick) { fcp->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, *************** *** 3373,3379 **** retval = NULL; else { ! /* Skip NULL lines (continuation lines). */ while (fcp->linenr < gap->ga_len && ((char_u **)(gap->ga_data))[fcp->linenr] == NULL) ++fcp->linenr; --- 3372,3378 ---- retval = NULL; else { ! // Skip NULL lines (continuation lines). while (fcp->linenr < gap->ga_len && ((char_u **)(gap->ga_data))[fcp->linenr] == NULL) ++fcp->linenr; *************** *** 3390,3400 **** } } ! /* Did we encounter a breakpoint? */ if (fcp->breakpoint != 0 && fcp->breakpoint <= sourcing_lnum) { dbg_breakpoint(fp->uf_name, sourcing_lnum); ! /* Find next breakpoint. */ fcp->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, sourcing_lnum); fcp->dbg_tick = debug_tick; --- 3389,3399 ---- } } ! // Did we encounter a breakpoint? if (fcp->breakpoint != 0 && fcp->breakpoint <= sourcing_lnum) { dbg_breakpoint(fp->uf_name, sourcing_lnum); ! // Find next breakpoint. fcp->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, sourcing_lnum); fcp->dbg_tick = debug_tick; *************** *** 3412,3419 **** { funccall_T *fcp = (funccall_T *)cookie; ! /* Ignore the "abort" flag if the abortion behavior has been changed due to ! * an error inside a try conditional. */ return (((fcp->func->uf_flags & FC_ABORT) && did_emsg && !aborted_in_try()) || fcp->returned); } --- 3411,3418 ---- { funccall_T *fcp = (funccall_T *)cookie; ! // Ignore the "abort" flag if the abortion behavior has been changed due to ! // an error inside a try conditional. return (((fcp->func->uf_flags & FC_ABORT) && did_emsg && !aborted_in_try()) || fcp->returned); } *************** *** 3452,3458 **** { fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string : rettv->vval.v_partial->pt_name; ! /* Translate "s:func" to the stored function name. */ fname = fname_trans_sid(fname, fname_buf, &tofree, &error); fp = find_func(fname); vim_free(tofree); --- 3451,3457 ---- { fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string : rettv->vval.v_partial->pt_name; ! // Translate "s:func" to the stored function name. fname = fname_trans_sid(fname, fname_buf, &tofree, &error); fp = find_func(fname); vim_free(tofree); *************** *** 3470,3477 **** selfdict = NULL; if (rettv->v_type == VAR_FUNC) { ! /* Just a function: Take over the function name and use ! * selfdict. */ pt->pt_name = rettv->vval.v_string; } else --- 3469,3476 ---- selfdict = NULL; if (rettv->v_type == VAR_FUNC) { ! // Just a function: Take over the function name and use ! // selfdict. pt->pt_name = rettv->vval.v_string; } else *************** *** 3479,3487 **** partial_T *ret_pt = rettv->vval.v_partial; int i; ! /* Partial: copy the function name, use selfdict and copy ! * args. Can't take over name or args, the partial might ! * be referenced elsewhere. */ if (ret_pt->pt_name != NULL) { pt->pt_name = vim_strsave(ret_pt->pt_name); --- 3478,3486 ---- partial_T *ret_pt = rettv->vval.v_partial; int i; ! // Partial: copy the function name, use selfdict and copy ! // args. Can't take over name or args, the partial might ! // be referenced elsewhere. if (ret_pt->pt_name != NULL) { pt->pt_name = vim_strsave(ret_pt->pt_name); *************** *** 3496,3502 **** { pt->pt_argv = ALLOC_MULT(typval_T, ret_pt->pt_argc); if (pt->pt_argv == NULL) ! /* out of memory: drop the arguments */ pt->pt_argc = 0; else { --- 3495,3501 ---- { pt->pt_argv = ALLOC_MULT(typval_T, ret_pt->pt_argc); if (pt->pt_argv == NULL) ! // out of memory: drop the arguments pt->pt_argc = 0; else { *************** *** 3580,3587 **** pfc = &(*pfc)->caller; } if (did_free_funccal) ! /* When a funccal was freed some more items might be garbage ! * collected, so run again. */ (void)garbage_collect(testing); return did_free; --- 3579,3586 ---- pfc = &(*pfc)->caller; } if (did_free_funccal) ! // When a funccal was freed some more items might be garbage ! // collected, so run again. (void)garbage_collect(testing); return did_free; *************** *** 3606,3612 **** if (temp_funccal) funccal = temp_funccal; else ! /* backtrace level overflow. reset to max */ debug_backtrace_level = i; } } --- 3605,3611 ---- if (temp_funccal) funccal = temp_funccal; else ! // backtrace level overflow. reset to max debug_backtrace_level = i; } } *************** *** 3700,3706 **** if (current_funccal == NULL || current_funccal->func->uf_scoped == NULL) return NULL; ! /* Search in parent scope which is possible to reference from lambda */ current_funccal = current_funccal->func->uf_scoped; while (current_funccal != NULL) { --- 3699,3705 ---- if (current_funccal == NULL || current_funccal->func->uf_scoped == NULL) return NULL; ! // Search in parent scope which is possible to reference from lambda current_funccal = current_funccal->func->uf_scoped; while (current_funccal != NULL) { *************** *** 3737,3743 **** if (current_funccal == NULL || current_funccal->func->uf_scoped == NULL) return NULL; ! /* Search in parent scope which is possible to reference from lambda */ current_funccal = current_funccal->func->uf_scoped; while (current_funccal) { --- 3736,3742 ---- if (current_funccal == NULL || current_funccal->func->uf_scoped == NULL) return NULL; ! // Search in parent scope which is possible to reference from lambda current_funccal = current_funccal->func->uf_scoped; while (current_funccal) { *************** *** 3887,3890 **** return abort; } ! #endif /* FEAT_EVAL */ --- 3886,3889 ---- return abort; } ! #endif // FEAT_EVAL *** ../vim-8.1.2395/src/winclip.c 2019-06-14 21:36:51.018437479 +0200 --- src/winclip.c 2019-12-05 21:43:22.924759854 +0100 *************** *** 61,71 **** while (todo > 0) { ! /* Only convert if we have a complete sequence. */ l = utf_ptr2len_len(p, todo); if (l > todo) { ! /* Return length of incomplete sequence. */ if (unconvlenp != NULL) *unconvlenp = todo; break; --- 61,71 ---- while (todo > 0) { ! // Only convert if we have a complete sequence. l = utf_ptr2len_len(p, todo); if (l > todo) { ! // Return length of incomplete sequence. if (unconvlenp != NULL) *unconvlenp = todo; break; *************** *** 74,80 **** ch = utf_ptr2char(p); if (ch >= 0x10000) { ! /* non-BMP character, encoding with surrogate pairs */ ++outlen; if (outstr != NULL) { --- 74,80 ---- ch = utf_ptr2char(p); if (ch >= 0x10000) { ! // non-BMP character, encoding with surrogate pairs ++outlen; if (outstr != NULL) { *************** *** 113,119 **** ch = *p; if (ch >= 0xD800 && ch <= 0xDBFF && todo > 1) { ! /* surrogate pairs handling */ ch2 = p[1]; if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { --- 113,119 ---- ch = *p; if (ch >= 0xD800 && ch <= 0xDBFF && todo > 1) { ! // surrogate pairs handling ch2 = p[1]; if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { *************** *** 148,154 **** LPWSTR *out, int *outlen) { *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0); ! /* Add one one word to avoid a zero-length alloc(). */ *out = ALLOC_MULT(WCHAR, *outlen + 1); if (*out != NULL) { --- 148,154 ---- LPWSTR *out, int *outlen) { *outlen = MultiByteToWideChar(cp, flags, in, inlen, 0, 0); ! // Add one one word to avoid a zero-length alloc(). *out = ALLOC_MULT(WCHAR, *outlen + 1); if (*out != NULL) { *************** *** 168,174 **** LPCSTR def, LPBOOL useddef) { *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); ! /* Add one one byte to avoid a zero-length alloc(). */ *out = alloc(*outlen + 1); if (*out != NULL) { --- 168,174 ---- LPCSTR def, LPBOOL useddef) { *outlen = WideCharToMultiByte(cp, flags, in, inlen, NULL, 0, def, useddef); ! // Add one one byte to avoid a zero-length alloc(). *out = alloc(*outlen + 1); if (*out != NULL) { *************** *** 198,211 **** clip_star.format_raw = RegisterClipboardFormat("VimRawBytes"); } ! /* Type used for the clipboard type of Vim's data. */ typedef struct { ! int type; /* MCHAR, MBLOCK or MLINE */ ! int txtlen; /* length of CF_TEXT in bytes */ ! int ucslen; /* length of CF_UNICODETEXT in words */ ! int rawlen; /* length of clip_star.format_raw, including encoding, ! excluding terminating NUL */ } VimClipType_t; /* --- 198,211 ---- clip_star.format_raw = RegisterClipboardFormat("VimRawBytes"); } ! // Type used for the clipboard type of Vim's data. typedef struct { ! int type; // MCHAR, MBLOCK or MLINE ! int txtlen; // length of CF_TEXT in bytes ! int ucslen; // length of CF_UNICODETEXT in words ! int rawlen; // length of clip_star.format_raw, including encoding, ! // excluding terminating NUL } VimClipType_t; /* *************** *** 227,233 **** void clip_mch_lose_selection(Clipboard_T *cbd UNUSED) { ! /* Nothing needs to be done here */ } /* --- 227,233 ---- void clip_mch_lose_selection(Clipboard_T *cbd UNUSED) { ! // Nothing needs to be done here } /* *************** *** 243,249 **** char_u *ret; char_u *retp; ! /* Avoid allocating zero bytes, it generates an error message. */ ret = alloc(str_len == 0 ? 1 : str_len); if (ret != NULL) { --- 243,249 ---- char_u *ret; char_u *retp; ! // Avoid allocating zero bytes, it generates an error message. ret = alloc(str_len == 0 ? 1 : str_len); if (ret != NULL) { *************** *** 274,282 **** while (!OpenClipboard(NULL)) { if (delay > 500) ! return FALSE; /* waited too long, give up */ Sleep(delay); ! delay *= 2; /* wait for 10, 20, 40, 80, etc. msec */ } return TRUE; } --- 274,282 ---- while (!OpenClipboard(NULL)) { if (delay > 500) ! return FALSE; // waited too long, give up Sleep(delay); ! delay *= 2; // wait for 10, 20, 40, 80, etc. msec } return TRUE; } *************** *** 311,329 **** if (!vim_open_clipboard()) return; ! /* Check for vim's own clipboard format first. This only gets the type of ! * the data, still need to use CF_UNICODETEXT or CF_TEXT for the text. */ if (IsClipboardFormatAvailable(cbd->format)) { VimClipType_t *meta_p; HGLOBAL meta_h; ! /* We have metadata on the clipboard; try to get it. */ if ((meta_h = GetClipboardData(cbd->format)) != NULL && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL) { ! /* The size of "VimClipType_t" changed, "rawlen" was added later. ! * Only copy what is available for backwards compatibility. */ n = sizeof(VimClipType_t); if (GlobalSize(meta_h) < n) n = GlobalSize(meta_h); --- 311,329 ---- if (!vim_open_clipboard()) return; ! // Check for vim's own clipboard format first. This only gets the type of ! // the data, still need to use CF_UNICODETEXT or CF_TEXT for the text. if (IsClipboardFormatAvailable(cbd->format)) { VimClipType_t *meta_p; HGLOBAL meta_h; ! // We have metadata on the clipboard; try to get it. if ((meta_h = GetClipboardData(cbd->format)) != NULL && (meta_p = (VimClipType_t *)GlobalLock(meta_h)) != NULL) { ! // The size of "VimClipType_t" changed, "rawlen" was added later. ! // Only copy what is available for backwards compatibility. n = sizeof(VimClipType_t); if (GlobalSize(meta_h) < n) n = GlobalSize(meta_h); *************** *** 332,343 **** } } ! /* Check for Vim's raw clipboard format first. This is used without ! * conversion, but only if 'encoding' matches. */ if (IsClipboardFormatAvailable(cbd->format_raw) && metadata.rawlen > (int)STRLEN(p_enc)) { ! /* We have raw data on the clipboard; try to get it. */ if ((rawh = GetClipboardData(cbd->format_raw)) != NULL) { char_u *rawp; --- 332,343 ---- } } ! // Check for Vim's raw clipboard format first. This is used without ! // conversion, but only if 'encoding' matches. if (IsClipboardFormatAvailable(cbd->format_raw) && metadata.rawlen > (int)STRLEN(p_enc)) { ! // We have raw data on the clipboard; try to get it. if ((rawh = GetClipboardData(cbd->format_raw)) != NULL) { char_u *rawp; *************** *** 358,364 **** } if (str == NULL) { ! /* Try to get the clipboard in Unicode if it's not an empty string. */ if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0) { HGLOBAL hMemW; --- 358,364 ---- } if (str == NULL) { ! // Try to get the clipboard in Unicode if it's not an empty string. if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0) { HGLOBAL hMemW; *************** *** 367,374 **** { WCHAR *hMemWstr = (WCHAR *)GlobalLock(hMemW); ! /* Use the length of our metadata if possible, but limit it to ! * the GlobalSize() for safety. */ maxlen = (int)(GlobalSize(hMemW) / sizeof(WCHAR)); if (metadata.ucslen >= 0) { --- 367,374 ---- { WCHAR *hMemWstr = (WCHAR *)GlobalLock(hMemW); ! // Use the length of our metadata if possible, but limit it to ! // the GlobalSize() for safety. maxlen = (int)(GlobalSize(hMemW) / sizeof(WCHAR)); if (metadata.ucslen >= 0) { *************** *** 387,401 **** GlobalUnlock(hMemW); } } ! /* Get the clipboard in the Active codepage. */ else if (IsClipboardFormatAvailable(CF_TEXT)) { if ((hMem = GetClipboardData(CF_TEXT)) != NULL) { str = (char_u *)GlobalLock(hMem); ! /* The length is either what our metadata says or the strlen(). ! * But limit it to the GlobalSize() for safety. */ maxlen = (int)GlobalSize(hMem); if (metadata.txtlen >= 0) { --- 387,401 ---- GlobalUnlock(hMemW); } } ! // Get the clipboard in the Active codepage. else if (IsClipboardFormatAvailable(CF_TEXT)) { if ((hMem = GetClipboardData(CF_TEXT)) != NULL) { str = (char_u *)GlobalLock(hMem); ! // The length is either what our metadata says or the strlen(). ! // But limit it to the GlobalSize() for safety. maxlen = (int)GlobalSize(hMem); if (metadata.txtlen >= 0) { *************** *** 411,418 **** break; } ! /* The text is in the active codepage. Convert to ! * 'encoding', going through UTF-16. */ acp_to_enc(str, str_size, &to_free, &maxlen); if (to_free != NULL) { --- 411,418 ---- break; } ! // The text is in the active codepage. Convert to ! // 'encoding', going through UTF-16. acp_to_enc(str, str_size, &to_free, &maxlen); if (to_free != NULL) { *************** *** 427,437 **** { char_u *temp_clipboard; ! /* If the type is not known detect it. */ if (metadata.type == -1) metadata.type = MAUTO; ! /* Translate into . */ temp_clipboard = crnl_to_nl(str, &str_size); if (temp_clipboard != NULL) { --- 427,437 ---- { char_u *temp_clipboard; ! // If the type is not known detect it. if (metadata.type == -1) metadata.type = MAUTO; ! // Translate into . temp_clipboard = crnl_to_nl(str, &str_size); if (temp_clipboard != NULL) { *************** *** 440,446 **** } } ! /* unlock the global object */ if (hMem != NULL) GlobalUnlock(hMem); if (rawh != NULL) --- 440,446 ---- } } ! // unlock the global object if (hMem != NULL) GlobalUnlock(hMem); if (rawh != NULL) *************** *** 463,474 **** HGLOBAL hMemVim = NULL; HGLOBAL hMemW = NULL; ! /* If the '*' register isn't already filled in, fill it in now */ cbd->owned = TRUE; clip_get_selection(cbd); cbd->owned = FALSE; ! /* Get the text to be put on the clipboard, with CR-LF. */ metadata.type = clip_convert_selection(&str, &txtlen, cbd); if (metadata.type < 0) return; --- 463,474 ---- HGLOBAL hMemVim = NULL; HGLOBAL hMemW = NULL; ! // If the '*' register isn't already filled in, fill it in now cbd->owned = TRUE; clip_get_selection(cbd); cbd->owned = FALSE; ! // Get the text to be put on the clipboard, with CR-LF. metadata.type = clip_convert_selection(&str, &txtlen, cbd); if (metadata.type < 0) return; *************** *** 476,484 **** metadata.ucslen = 0; metadata.rawlen = 0; ! /* Always set the raw bytes: 'encoding', NUL and the text. This is used ! * when copy/paste from/to Vim with the same 'encoding', so that illegal ! * bytes can also be copied and no conversion is needed. */ { LPSTR lpszMemRaw; --- 476,484 ---- metadata.ucslen = 0; metadata.rawlen = 0; ! // Always set the raw bytes: 'encoding', NUL and the text. This is used ! // when copy/paste from/to Vim with the same 'encoding', so that illegal ! // bytes can also be copied and no conversion is needed. { LPSTR lpszMemRaw; *************** *** 500,514 **** WCHAR *out; int len = metadata.txtlen; ! /* Convert the text to UTF-16. This is put on the clipboard as ! * CF_UNICODETEXT. */ out = (WCHAR *)enc_to_utf16(str, &len); if (out != NULL) { WCHAR *lpszMemW; ! /* Convert the text for CF_TEXT to Active codepage. Otherwise it's ! * p_enc, which has no relation to the Active codepage. */ metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len, NULL, 0, 0, 0); vim_free(str); --- 500,514 ---- WCHAR *out; int len = metadata.txtlen; ! // Convert the text to UTF-16. This is put on the clipboard as ! // CF_UNICODETEXT. out = (WCHAR *)enc_to_utf16(str, &len); if (out != NULL) { WCHAR *lpszMemW; ! // Convert the text for CF_TEXT to Active codepage. Otherwise it's ! // p_enc, which has no relation to the Active codepage. metadata.txtlen = WideCharToMultiByte(GetACP(), 0, out, len, NULL, 0, 0, 0); vim_free(str); *************** *** 516,528 **** if (str == NULL) { vim_free(out); ! return; /* out of memory */ } WideCharToMultiByte(GetACP(), 0, out, len, (LPSTR)str, metadata.txtlen, 0, 0); ! /* Allocate memory for the UTF-16 text, add one NUL word to ! * terminate the string. */ hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (len + 1) * sizeof(WCHAR)); lpszMemW = (WCHAR *)GlobalLock(hMemW); --- 516,528 ---- if (str == NULL) { vim_free(out); ! return; // out of memory } WideCharToMultiByte(GetACP(), 0, out, len, (LPSTR)str, metadata.txtlen, 0, 0); ! // Allocate memory for the UTF-16 text, add one NUL word to ! // terminate the string. hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (len + 1) * sizeof(WCHAR)); lpszMemW = (WCHAR *)GlobalLock(hMemW); *************** *** 537,544 **** } } ! /* Allocate memory for the text, add one NUL byte to terminate the string. ! */ hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1); { LPSTR lpszMem = (LPSTR)GlobalLock(hMem); --- 537,543 ---- } } ! // Allocate memory for the text, add one NUL byte to terminate the string. hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1); { LPSTR lpszMem = (LPSTR)GlobalLock(hMem); *************** *** 550,556 **** } } ! /* Set up metadata: */ { VimClipType_t *lpszMemVim = NULL; --- 549,555 ---- } } ! // Set up metadata: { VimClipType_t *lpszMemVim = NULL; *************** *** 580,587 **** if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL) hMemW = NULL; } ! /* Always use CF_TEXT. On Win98 Notepad won't obtain the ! * CF_UNICODETEXT text, only CF_TEXT. */ SetClipboardData(CF_TEXT, hMem); hMem = 0; } --- 579,586 ---- if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL) hMemW = NULL; } ! // Always use CF_TEXT. On Win98 Notepad won't obtain the ! // CF_UNICODETEXT text, only CF_TEXT. SetClipboardData(CF_TEXT, hMem); hMem = 0; } *************** *** 589,595 **** } vim_free(str); ! /* Free any allocations we didn't give to the clipboard: */ if (hMemRaw) GlobalFree(hMemRaw); if (hMem) --- 588,594 ---- } vim_free(str); ! // Free any allocations we didn't give to the clipboard: if (hMemRaw) GlobalFree(hMemRaw); if (hMem) *************** *** 600,606 **** GlobalFree(hMemVim); } ! #endif /* FEAT_CLIPBOARD */ /* * Note: the following two functions are only guaranteed to work when using --- 599,605 ---- GlobalFree(hMemVim); } ! #endif // FEAT_CLIPBOARD /* * Note: the following two functions are only guaranteed to work when using *************** *** 631,646 **** if (enc_codepage > 0) { ! /* We can do any CP### -> UTF-16 in one pass, and we can do it ! * without iconv() (convert_* may need iconv). */ MultiByteToWideChar_alloc(enc_codepage, 0, (LPCSTR)str, *lenp, &ret, &length); } else { ! /* Use "latin1" by default, we might be called before we have p_enc ! * set up. Convert to utf-8 first, works better with iconv(). Does ! * nothing if 'encoding' is "utf-8". */ conv.vc_type = CONV_NONE; if (convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1", (char_u *)"utf-8") == FAIL) --- 630,645 ---- if (enc_codepage > 0) { ! // We can do any CP### -> UTF-16 in one pass, and we can do it ! // without iconv() (convert_* may need iconv). MultiByteToWideChar_alloc(enc_codepage, 0, (LPCSTR)str, *lenp, &ret, &length); } else { ! // Use "latin1" by default, we might be called before we have p_enc ! // set up. Convert to utf-8 first, works better with iconv(). Does ! // nothing if 'encoding' is "utf-8". conv.vc_type = CONV_NONE; if (convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1", (char_u *)"utf-8") == FAIL) *************** *** 691,697 **** if (enc_codepage > 0) { ! /* We can do any UTF-16 -> CP### in one pass. */ int length; WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp, --- 690,696 ---- if (enc_codepage > 0) { ! // We can do any UTF-16 -> CP### in one pass. int length; WideCharToMultiByte_alloc(enc_codepage, 0, str, *lenp, *************** *** 700,718 **** return enc_str; } ! /* Avoid allocating zero bytes, it generates an error message. */ utf8_str = alloc(utf16_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL)); if (utf8_str != NULL) { *lenp = utf16_to_utf8(str, *lenp, utf8_str); ! /* We might be called before we have p_enc set up. */ conv.vc_type = CONV_NONE; convert_setup(&conv, (char_u *)"utf-8", p_enc? p_enc: (char_u *)"latin1"); if (conv.vc_type == CONV_NONE) { ! /* p_enc is utf-8, so we're done. */ enc_str = utf8_str; } else --- 699,717 ---- return enc_str; } ! // Avoid allocating zero bytes, it generates an error message. utf8_str = alloc(utf16_to_utf8(str, *lenp == 0 ? 1 : *lenp, NULL)); if (utf8_str != NULL) { *lenp = utf16_to_utf8(str, *lenp, utf8_str); ! // We might be called before we have p_enc set up. conv.vc_type = CONV_NONE; convert_setup(&conv, (char_u *)"utf-8", p_enc? p_enc: (char_u *)"latin1"); if (conv.vc_type == CONV_NONE) { ! // p_enc is utf-8, so we're done. enc_str = utf8_str; } else *************** *** 746,752 **** &widestr, outlen); if (widestr != NULL) { ! ++*outlen; /* Include the 0 after the string */ *out = utf16_to_enc((short_u *)widestr, outlen); vim_free(widestr); } --- 745,751 ---- &widestr, outlen); if (widestr != NULL) { ! ++*outlen; // Include the 0 after the string *out = utf16_to_enc((short_u *)widestr, outlen); vim_free(widestr); } *** ../vim-8.1.2395/src/window.c 2019-11-30 22:47:42.659331167 +0100 --- src/window.c 2019-12-05 21:46:52.039984363 +0100 *************** *** 63,69 **** static win_T *win_alloc(win_T *after, int hidden); ! #define NOWIN (win_T *)-1 /* non-existing window */ #define ROWS_AVAIL (Rows - p_ch - tabline_height()) --- 63,69 ---- static win_T *win_alloc(win_T *after, int hidden); ! #define NOWIN (win_T *)-1 // non-existing window #define ROWS_AVAIL (Rows - p_ch - tabline_height()) *************** *** 108,114 **** do_window( int nchar, long Prenum, ! int xchar) /* extra char from ":wincmd gx" or NUL */ { long Prenum1; win_T *wp; --- 108,114 ---- do_window( int nchar, long Prenum, ! int xchar) // extra char from ":wincmd gx" or NUL { long Prenum1; win_T *wp; *************** *** 142,156 **** switch (nchar) { ! /* split current window in two parts, horizontally */ case 'S': case Ctrl_S: case 's': CHECK_CMDWIN; ! reset_VIsual_and_resel(); /* stop Visual mode */ #ifdef FEAT_QUICKFIX ! /* When splitting the quickfix window open a new buffer in it, ! * don't replicate the quickfix buffer. */ if (bt_quickfix(curbuf)) goto newwindow; #endif --- 142,156 ---- switch (nchar) { ! // split current window in two parts, horizontally case 'S': case Ctrl_S: case 's': CHECK_CMDWIN; ! reset_VIsual_and_resel(); // stop Visual mode #ifdef FEAT_QUICKFIX ! // When splitting the quickfix window open a new buffer in it, ! // don't replicate the quickfix buffer. if (bt_quickfix(curbuf)) goto newwindow; #endif *************** *** 160,173 **** (void)win_split((int)Prenum, 0); break; ! /* split current window in two parts, vertically */ case Ctrl_V: case 'v': CHECK_CMDWIN; ! reset_VIsual_and_resel(); /* stop Visual mode */ #ifdef FEAT_QUICKFIX ! /* When splitting the quickfix window open a new buffer in it, ! * don't replicate the quickfix buffer. */ if (bt_quickfix(curbuf)) goto newwindow; #endif --- 160,173 ---- (void)win_split((int)Prenum, 0); break; ! // split current window in two parts, vertically case Ctrl_V: case 'v': CHECK_CMDWIN; ! reset_VIsual_and_resel(); // stop Visual mode #ifdef FEAT_QUICKFIX ! // When splitting the quickfix window open a new buffer in it, ! // don't replicate the quickfix buffer. if (bt_quickfix(curbuf)) goto newwindow; #endif *************** *** 177,187 **** (void)win_split((int)Prenum, WSP_VERT); break; ! /* split current window and edit alternate file */ case Ctrl_HAT: case '^': CHECK_CMDWIN; ! reset_VIsual_and_resel(); /* stop Visual mode */ if (buflist_findnr(Prenum == 0 ? curwin->w_alt_fnum : Prenum) == NULL) --- 177,187 ---- (void)win_split((int)Prenum, WSP_VERT); break; ! // split current window and edit alternate file case Ctrl_HAT: case '^': CHECK_CMDWIN; ! reset_VIsual_and_resel(); // stop Visual mode if (buflist_findnr(Prenum == 0 ? curwin->w_alt_fnum : Prenum) == NULL) *************** *** 199,214 **** (linenr_T)0, GETF_ALT, FALSE); break; ! /* open new window */ case Ctrl_N: case 'n': CHECK_CMDWIN; ! reset_VIsual_and_resel(); /* stop Visual mode */ #ifdef FEAT_QUICKFIX newwindow: #endif if (Prenum) ! /* window height */ vim_snprintf((char *)cbuf, sizeof(cbuf) - 5, "%ld", Prenum); else cbuf[0] = NUL; --- 199,214 ---- (linenr_T)0, GETF_ALT, FALSE); break; ! // open new window case Ctrl_N: case 'n': CHECK_CMDWIN; ! reset_VIsual_and_resel(); // stop Visual mode #ifdef FEAT_QUICKFIX newwindow: #endif if (Prenum) ! // window height vim_snprintf((char *)cbuf, sizeof(cbuf) - 5, "%ld", Prenum); else cbuf[0] = NUL; *************** *** 220,251 **** do_cmdline_cmd(cbuf); break; ! /* quit current window */ case Ctrl_Q: case 'q': ! reset_VIsual_and_resel(); /* stop Visual mode */ cmd_with_count("quit", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; ! /* close current window */ case Ctrl_C: case 'c': ! reset_VIsual_and_resel(); /* stop Visual mode */ cmd_with_count("close", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; #if defined(FEAT_QUICKFIX) ! /* close preview window */ case Ctrl_Z: case 'z': CHECK_CMDWIN; ! reset_VIsual_and_resel(); /* stop Visual mode */ do_cmdline_cmd((char_u *)"pclose"); break; ! /* cursor to preview window */ case 'P': FOR_ALL_WINDOWS(wp) if (wp->w_p_pvw) --- 220,251 ---- do_cmdline_cmd(cbuf); break; ! // quit current window case Ctrl_Q: case 'q': ! reset_VIsual_and_resel(); // stop Visual mode cmd_with_count("quit", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; ! // close current window case Ctrl_C: case 'c': ! reset_VIsual_and_resel(); // stop Visual mode cmd_with_count("close", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; #if defined(FEAT_QUICKFIX) ! // close preview window case Ctrl_Z: case 'z': CHECK_CMDWIN; ! reset_VIsual_and_resel(); // stop Visual mode do_cmdline_cmd((char_u *)"pclose"); break; ! // cursor to preview window case 'P': FOR_ALL_WINDOWS(wp) if (wp->w_p_pvw) *************** *** 257,282 **** break; #endif ! /* close all but current window */ case Ctrl_O: case 'o': CHECK_CMDWIN; ! reset_VIsual_and_resel(); /* stop Visual mode */ cmd_with_count("only", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; ! /* cursor to next window with wrap around */ case Ctrl_W: case 'w': ! /* cursor to previous window with wrap around */ case 'W': CHECK_CMDWIN; ! if (ONE_WINDOW && Prenum != 1) /* just one window */ beep_flush(); else { ! if (Prenum) /* go to specified window */ { for (wp = firstwin; --Prenum > 0; ) { --- 257,282 ---- break; #endif ! // close all but current window case Ctrl_O: case 'o': CHECK_CMDWIN; ! reset_VIsual_and_resel(); // stop Visual mode cmd_with_count("only", cbuf, sizeof(cbuf), Prenum); do_cmdline_cmd(cbuf); break; ! // cursor to next window with wrap around case Ctrl_W: case 'w': ! // cursor to previous window with wrap around case 'W': CHECK_CMDWIN; ! if (ONE_WINDOW && Prenum != 1) // just one window beep_flush(); else { ! if (Prenum) // go to specified window { for (wp = firstwin; --Prenum > 0; ) { *************** *** 288,311 **** } else { ! if (nchar == 'W') /* go to previous window */ { wp = curwin->w_prev; if (wp == NULL) ! wp = lastwin; /* wrap around */ } ! else /* go to next window */ { wp = curwin->w_next; if (wp == NULL) ! wp = firstwin; /* wrap around */ } } win_goto(wp); } break; ! /* cursor to window below */ case 'j': case K_DOWN: case Ctrl_J: --- 288,311 ---- } else { ! if (nchar == 'W') // go to previous window { wp = curwin->w_prev; if (wp == NULL) ! wp = lastwin; // wrap around } ! else // go to next window { wp = curwin->w_next; if (wp == NULL) ! wp = firstwin; // wrap around } } win_goto(wp); } break; ! // cursor to window below case 'j': case K_DOWN: case Ctrl_J: *************** *** 313,319 **** win_goto_ver(FALSE, Prenum1); break; ! /* cursor to window above */ case 'k': case K_UP: case Ctrl_K: --- 313,319 ---- win_goto_ver(FALSE, Prenum1); break; ! // cursor to window above case 'k': case K_UP: case Ctrl_K: *************** *** 321,327 **** win_goto_ver(TRUE, Prenum1); break; ! /* cursor to left window */ case 'h': case K_LEFT: case Ctrl_H: --- 321,327 ---- win_goto_ver(TRUE, Prenum1); break; ! // cursor to left window case 'h': case K_LEFT: case Ctrl_H: *************** *** 330,336 **** win_goto_hor(TRUE, Prenum1); break; ! /* cursor to right window */ case 'l': case K_RIGHT: case Ctrl_L: --- 330,336 ---- win_goto_hor(TRUE, Prenum1); break; ! // cursor to right window case 'l': case K_RIGHT: case Ctrl_L: *************** *** 338,344 **** win_goto_hor(FALSE, Prenum1); break; ! /* move window to new tab page */ case 'T': if (one_window()) msg(_(m_onlyone)); --- 338,344 ---- win_goto_hor(FALSE, Prenum1); break; ! // move window to new tab page case 'T': if (one_window()) msg(_(m_onlyone)); *************** *** 347,354 **** tabpage_T *oldtab = curtab; tabpage_T *newtab; ! /* First create a new tab with the window, then go back to ! * the old tab and close the window there. */ wp = curwin; if (win_new_tabpage((int)Prenum) == OK && valid_tabpage(oldtab)) --- 347,354 ---- tabpage_T *oldtab = curtab; tabpage_T *newtab; ! // First create a new tab with the window, then go back to ! // the old tab and close the window there. wp = curwin; if (win_new_tabpage((int)Prenum) == OK && valid_tabpage(oldtab)) *************** *** 363,381 **** } break; ! /* cursor to top-left window */ case 't': case Ctrl_T: win_goto(firstwin); break; ! /* cursor to bottom-right window */ case 'b': case Ctrl_B: win_goto(lastwin); break; ! /* cursor to last accessed (previous) window */ case 'p': case Ctrl_P: if (!win_valid(prevwin)) --- 363,381 ---- } break; ! // cursor to top-left window case 't': case Ctrl_T: win_goto(firstwin); break; ! // cursor to bottom-right window case 'b': case Ctrl_B: win_goto(lastwin); break; ! // cursor to last accessed (previous) window case 'p': case Ctrl_P: if (!win_valid(prevwin)) *************** *** 384,412 **** win_goto(prevwin); break; ! /* exchange current and next window */ case 'x': case Ctrl_X: CHECK_CMDWIN; win_exchange(Prenum); break; ! /* rotate windows downwards */ case Ctrl_R: case 'r': CHECK_CMDWIN; ! reset_VIsual_and_resel(); /* stop Visual mode */ ! win_rotate(FALSE, (int)Prenum1); /* downwards */ break; ! /* rotate windows upwards */ case 'R': CHECK_CMDWIN; ! reset_VIsual_and_resel(); /* stop Visual mode */ ! win_rotate(TRUE, (int)Prenum1); /* upwards */ break; ! /* move window to the very top/bottom/left/right */ case 'K': case 'J': case 'H': --- 384,412 ---- win_goto(prevwin); break; ! // exchange current and next window case 'x': case Ctrl_X: CHECK_CMDWIN; win_exchange(Prenum); break; ! // rotate windows downwards case Ctrl_R: case 'r': CHECK_CMDWIN; ! reset_VIsual_and_resel(); // stop Visual mode ! win_rotate(FALSE, (int)Prenum1); // downwards break; ! // rotate windows upwards case 'R': CHECK_CMDWIN; ! reset_VIsual_and_resel(); // stop Visual mode ! win_rotate(TRUE, (int)Prenum1); // upwards break; ! // move window to the very top/bottom/left/right case 'K': case 'J': case 'H': *************** *** 417,423 **** | ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT)); break; ! /* make all windows the same height */ case '=': #ifdef FEAT_GUI need_mouse_correct = TRUE; --- 417,423 ---- | ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT)); break; ! // make all windows the same height case '=': #ifdef FEAT_GUI need_mouse_correct = TRUE; *************** *** 425,431 **** win_equal(NULL, FALSE, 'b'); break; ! /* increase current window height */ case '+': #ifdef FEAT_GUI need_mouse_correct = TRUE; --- 425,431 ---- win_equal(NULL, FALSE, 'b'); break; ! // increase current window height case '+': #ifdef FEAT_GUI need_mouse_correct = TRUE; *************** *** 433,439 **** win_setheight(curwin->w_height + (int)Prenum1); break; ! /* decrease current window height */ case '-': #ifdef FEAT_GUI need_mouse_correct = TRUE; --- 433,439 ---- win_setheight(curwin->w_height + (int)Prenum1); break; ! // decrease current window height case '-': #ifdef FEAT_GUI need_mouse_correct = TRUE; *************** *** 441,447 **** win_setheight(curwin->w_height - (int)Prenum1); break; ! /* set current window height */ case Ctrl__: case '_': #ifdef FEAT_GUI --- 441,447 ---- win_setheight(curwin->w_height - (int)Prenum1); break; ! // set current window height case Ctrl__: case '_': #ifdef FEAT_GUI *************** *** 450,456 **** win_setheight(Prenum ? (int)Prenum : 9999); break; ! /* increase current window width */ case '>': #ifdef FEAT_GUI need_mouse_correct = TRUE; --- 450,456 ---- win_setheight(Prenum ? (int)Prenum : 9999); break; ! // increase current window width case '>': #ifdef FEAT_GUI need_mouse_correct = TRUE; *************** *** 458,464 **** win_setwidth(curwin->w_width + (int)Prenum1); break; ! /* decrease current window width */ case '<': #ifdef FEAT_GUI need_mouse_correct = TRUE; --- 458,464 ---- win_setwidth(curwin->w_width + (int)Prenum1); break; ! // decrease current window width case '<': #ifdef FEAT_GUI need_mouse_correct = TRUE; *************** *** 466,472 **** win_setwidth(curwin->w_width - (int)Prenum1); break; ! /* set current window width */ case '|': #ifdef FEAT_GUI need_mouse_correct = TRUE; --- 466,472 ---- win_setwidth(curwin->w_width - (int)Prenum1); break; ! // set current window width case '|': #ifdef FEAT_GUI need_mouse_correct = TRUE; *************** *** 474,480 **** win_setwidth(Prenum != 0 ? (int)Prenum : 9999); break; ! /* jump to tag and split window if tag exists (in preview window) */ #if defined(FEAT_QUICKFIX) case '}': CHECK_CMDWIN; --- 474,480 ---- win_setwidth(Prenum != 0 ? (int)Prenum : 9999); break; ! // jump to tag and split window if tag exists (in preview window) #if defined(FEAT_QUICKFIX) case '}': CHECK_CMDWIN; *************** *** 483,493 **** else g_do_tagpreview = p_pvh; #endif ! /* FALLTHROUGH */ case ']': case Ctrl_RSB: CHECK_CMDWIN; ! /* keep Visual mode, can select words to use as a tag */ if (Prenum) postponed_split = Prenum; else --- 483,493 ---- else g_do_tagpreview = p_pvh; #endif ! // FALLTHROUGH case ']': case Ctrl_RSB: CHECK_CMDWIN; ! // keep Visual mode, can select words to use as a tag if (Prenum) postponed_split = Prenum; else *************** *** 497,509 **** g_do_tagpreview = 0; #endif ! /* Execute the command right here, required when "wincmd ]" ! * was used in a function. */ do_nv_ident(Ctrl_RSB, NUL); break; #ifdef FEAT_SEARCHPATH ! /* edit file name under cursor in a new window */ case 'f': case 'F': case Ctrl_F: --- 497,509 ---- g_do_tagpreview = 0; #endif ! // Execute the command right here, required when "wincmd ]" ! // was used in a function. do_nv_ident(Ctrl_RSB, NUL); break; #ifdef FEAT_SEARCHPATH ! // edit file name under cursor in a new window case 'f': case 'F': case Ctrl_F: *************** *** 525,532 **** if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, ECMD_HIDE, NULL) == FAIL) { ! /* Failed to open the file, close the window ! * opened for it. */ win_close(curwin, FALSE); goto_tabpage_win(oldtab, oldwin); } --- 525,532 ---- if (do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, ECMD_HIDE, NULL) == FAIL) { ! // Failed to open the file, close the window ! // opened for it. win_close(curwin, FALSE); goto_tabpage_win(oldtab, oldwin); } *************** *** 543,556 **** #endif #ifdef FEAT_FIND_ID ! /* Go to the first occurrence of the identifier under cursor along path in a ! * new window -- webb ! */ ! case 'i': /* Go to any match */ case Ctrl_I: type = FIND_ANY; ! /* FALLTHROUGH */ ! case 'd': /* Go to definition, using 'define' */ case Ctrl_D: CHECK_CMDWIN; if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) --- 543,555 ---- #endif #ifdef FEAT_FIND_ID ! // Go to the first occurrence of the identifier under cursor along path in a ! // new window -- webb ! case 'i': // Go to any match case Ctrl_I: type = FIND_ANY; ! // FALLTHROUGH ! case 'd': // Go to definition, using 'define' case Ctrl_D: CHECK_CMDWIN; if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0) *************** *** 562,568 **** break; #endif ! /* Quickfix window only: view the result under the cursor in a new split. */ #if defined(FEAT_QUICKFIX) case K_KENTER: case CAR: --- 561,567 ---- break; #endif ! // Quickfix window only: view the result under the cursor in a new split. #if defined(FEAT_QUICKFIX) case K_KENTER: case CAR: *************** *** 571,585 **** break; #endif ! /* CTRL-W g extended commands */ case 'g': case Ctrl_G: CHECK_CMDWIN; #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; /* disallow scrolling here */ #endif ++no_mapping; ! ++allow_keys; /* no mapping for xchar, but allow key codes */ if (xchar == NUL) xchar = plain_vgetc(); LANGMAP_ADJUST(xchar, TRUE); --- 570,584 ---- break; #endif ! // CTRL-W g extended commands case 'g': case Ctrl_G: CHECK_CMDWIN; #ifdef USE_ON_FLY_SCROLL ! dont_scroll = TRUE; // disallow scrolling here #endif ++no_mapping; ! ++allow_keys; // no mapping for xchar, but allow key codes if (xchar == NUL) xchar = plain_vgetc(); LANGMAP_ADJUST(xchar, TRUE); *************** *** 598,620 **** else g_do_tagpreview = p_pvh; #endif ! /* FALLTHROUGH */ case ']': case Ctrl_RSB: ! /* keep Visual mode, can select words to use as a tag */ if (Prenum) postponed_split = Prenum; else postponed_split = -1; ! /* Execute the command right here, required when ! * "wincmd g}" was used in a function. */ do_nv_ident('g', xchar); break; #ifdef FEAT_SEARCHPATH ! case 'f': /* CTRL-W gf: "gf" in a new tab page */ ! case 'F': /* CTRL-W gF: "gF" in a new tab page */ cmdmod.tab = tabpage_index(curtab) + 1; nchar = xchar; goto wingotofile; --- 597,619 ---- else g_do_tagpreview = p_pvh; #endif ! // FALLTHROUGH case ']': case Ctrl_RSB: ! // keep Visual mode, can select words to use as a tag if (Prenum) postponed_split = Prenum; else postponed_split = -1; ! // Execute the command right here, required when ! // "wincmd g}" was used in a function. do_nv_ident('g', xchar); break; #ifdef FEAT_SEARCHPATH ! case 'f': // CTRL-W gf: "gf" in a new tab page ! case 'F': // CTRL-W gF: "gF" in a new tab page cmdmod.tab = tabpage_index(curtab) + 1; nchar = xchar; goto wingotofile; *************** *** 788,798 **** if (ERROR_IF_POPUP_WINDOW) return FAIL; ! /* When the ":tab" modifier was used open a new tab page instead. */ if (may_open_tabpage() == OK) return OK; ! /* Add flags from ":vertical", ":topleft" and ":botright". */ flags |= cmdmod.split; if ((flags & WSP_TOP) && (flags & WSP_BOT)) { --- 787,797 ---- if (ERROR_IF_POPUP_WINDOW) return FAIL; ! // When the ":tab" modifier was used open a new tab page instead. if (may_open_tabpage() == OK) return OK; ! // Add flags from ":vertical", ":topleft" and ":botright". flags |= cmdmod.split; if ((flags & WSP_TOP) && (flags & WSP_BOT)) { *************** *** 802,809 **** if (check_split_disallowed() == FAIL) return FAIL; ! /* When creating the help window make a snapshot of the window layout. ! * Otherwise clear the snapshot, it's now invalid. */ if (flags & WSP_HELP) make_snapshot(SNAP_HELP_IDX); else --- 801,808 ---- if (check_split_disallowed() == FAIL) return FAIL; ! // When creating the help window make a snapshot of the window layout. ! // Otherwise clear the snapshot, it's now invalid. if (flags & WSP_HELP) make_snapshot(SNAP_HELP_IDX); else *************** *** 848,854 **** else oldwin = curwin; ! /* add a status line when p_ls == 1 and splitting the first window */ if (ONE_WINDOW && p_ls == 1 && oldwin->w_status_height == 0) { if (VISIBLE_HEIGHT(oldwin) <= p_wmh && new_wp == NULL) --- 847,853 ---- else oldwin = curwin; ! // add a status line when p_ls == 1 and splitting the first window if (ONE_WINDOW && p_ls == 1 && oldwin->w_status_height == 0) { if (VISIBLE_HEIGHT(oldwin) <= p_wmh && new_wp == NULL) *************** *** 860,866 **** } #ifdef FEAT_GUI ! /* May be needed for the scrollbars that are going to change. */ if (gui.in_use) out_flush(); #endif --- 859,865 ---- } #ifdef FEAT_GUI ! // May be needed for the scrollbars that are going to change. if (gui.in_use) out_flush(); #endif *************** *** 876,882 **** * Check if we are able to split the current window and compute its * width. */ ! /* Current window requires at least 1 space. */ wmw1 = (p_wmw == 0 ? 1 : p_wmw); needed = wmw1 + 1; if (flags & WSP_ROOM) --- 875,881 ---- * Check if we are able to split the current window and compute its * width. */ ! // Current window requires at least 1 space. wmw1 = (p_wmw == 0 ? 1 : p_wmw); needed = wmw1 + 1; if (flags & WSP_ROOM) *************** *** 921,938 **** if (new_size < wmw1) new_size = wmw1; ! /* if it doesn't fit in the current window, need win_equal() */ if (oldwin->w_width - new_size - 1 < p_wmw) do_equal = TRUE; ! /* We don't like to take lines for the new window from a ! * 'winfixwidth' window. Take them from a window to the left or right ! * instead, if possible. Add one for the separator. */ if (oldwin->w_p_wfw) win_setwidth_win(oldwin->w_width + new_size + 1, oldwin); ! /* Only make all windows the same width if one of them (except oldwin) ! * is wider than one of the split windows. */ if (!do_equal && p_ea && size == 0 && *p_ead != 'v' && oldwin->w_frame->fr_parent != NULL) { --- 920,937 ---- if (new_size < wmw1) new_size = wmw1; ! // if it doesn't fit in the current window, need win_equal() if (oldwin->w_width - new_size - 1 < p_wmw) do_equal = TRUE; ! // We don't like to take lines for the new window from a ! // 'winfixwidth' window. Take them from a window to the left or right ! // instead, if possible. Add one for the separator. if (oldwin->w_p_wfw) win_setwidth_win(oldwin->w_width + new_size + 1, oldwin); ! // Only make all windows the same width if one of them (except oldwin) ! // is wider than one of the split windows. if (!do_equal && p_ea && size == 0 && *p_ead != 'v' && oldwin->w_frame->fr_parent != NULL) { *************** *** 959,965 **** * Check if we are able to split the current window and compute its * height. */ ! /* Current window requires at least 1 space. */ wmh1 = (p_wmh == 0 ? 1 : p_wmh) + WINBAR_HEIGHT(curwin); needed = wmh1 + STATUS_HEIGHT; if (flags & WSP_ROOM) --- 958,964 ---- * Check if we are able to split the current window and compute its * height. */ ! // Current window requires at least 1 space. wmh1 = (p_wmh == 0 ? 1 : p_wmh) + WINBAR_HEIGHT(curwin); needed = wmh1 + STATUS_HEIGHT; if (flags & WSP_ROOM) *************** *** 1010,1026 **** if (new_size < wmh1) new_size = wmh1; ! /* if it doesn't fit in the current window, need win_equal() */ if (oldwin_height - new_size - STATUS_HEIGHT < p_wmh) do_equal = TRUE; ! /* We don't like to take lines for the new window from a ! * 'winfixheight' window. Take them from a window above or below ! * instead, if possible. */ if (oldwin->w_p_wfh) { ! /* Set w_fraction now so that the cursor keeps the same relative ! * vertical position using the old height. */ set_fraction(oldwin); did_set_fraction = TRUE; --- 1009,1025 ---- if (new_size < wmh1) new_size = wmh1; ! // if it doesn't fit in the current window, need win_equal() if (oldwin_height - new_size - STATUS_HEIGHT < p_wmh) do_equal = TRUE; ! // We don't like to take lines for the new window from a ! // 'winfixheight' window. Take them from a window above or below ! // instead, if possible. if (oldwin->w_p_wfh) { ! // Set w_fraction now so that the cursor keeps the same relative ! // vertical position using the old height. set_fraction(oldwin); did_set_fraction = TRUE; *************** *** 1031,1038 **** oldwin_height -= STATUS_HEIGHT; } ! /* Only make all windows the same height if one of them (except oldwin) ! * is higher than one of the split windows. */ if (!do_equal && p_ea && size == 0 && *p_ead != 'h' && oldwin->w_frame->fr_parent != NULL) { --- 1030,1037 ---- oldwin_height -= STATUS_HEIGHT; } ! // Only make all windows the same height if one of them (except oldwin) ! // is higher than one of the split windows. if (!do_equal && p_ea && size == 0 && *p_ead != 'h' && oldwin->w_frame->fr_parent != NULL) { *************** *** 1061,1067 **** || (!(flags & WSP_ABOVE) && ( (flags & WSP_VERT) ? p_spr : p_sb)))) { ! /* new window below/right of current one */ if (new_wp == NULL) wp = win_alloc(oldwin, FALSE); else --- 1060,1066 ---- || (!(flags & WSP_ABOVE) && ( (flags & WSP_VERT) ? p_spr : p_sb)))) { ! // new window below/right of current one if (new_wp == NULL) wp = win_alloc(oldwin, FALSE); else *************** *** 1087,1093 **** return FAIL; } ! /* make the contents of the new window the same as the current one */ win_init(wp, curwin, flags); } --- 1086,1092 ---- return FAIL; } ! // make the contents of the new window the same as the current one win_init(wp, curwin, flags); } *************** *** 1122,1128 **** } if (curfrp->fr_parent == NULL || curfrp->fr_parent->fr_layout != layout) { ! /* Need to create a new frame in the tree to make a branch. */ frp = ALLOC_CLEAR_ONE(frame_T); *frp = *curfrp; curfrp->fr_layout = layout; --- 1121,1127 ---- } if (curfrp->fr_parent == NULL || curfrp->fr_parent->fr_layout != layout) { ! // Need to create a new frame in the tree to make a branch. frp = ALLOC_CLEAR_ONE(frame_T); *frp = *curfrp; curfrp->fr_layout = layout; *************** *** 1145,1158 **** frp = new_wp->w_frame; frp->fr_parent = curfrp->fr_parent; ! /* Insert the new frame at the right place in the frame list. */ if (before) frame_insert(curfrp, frp); else frame_append(curfrp, frp); ! /* Set w_fraction now so that the cursor keeps the same relative ! * vertical position. */ if (!did_set_fraction) set_fraction(oldwin); wp->w_fraction = oldwin->w_fraction; --- 1144,1157 ---- frp = new_wp->w_frame; frp->fr_parent = curfrp->fr_parent; ! // Insert the new frame at the right place in the frame list. if (before) frame_insert(curfrp, frp); else frame_append(curfrp, frp); ! // Set w_fraction now so that the cursor keeps the same relative ! // vertical position. if (!did_set_fraction) set_fraction(oldwin); wp->w_fraction = oldwin->w_fraction; *************** *** 1168,1174 **** } if (flags & (WSP_TOP | WSP_BOT)) { ! /* set height and row of new window to full height */ wp->w_winrow = tabline_height(); win_new_height(wp, curfrp->fr_height - (p_ls > 0) - WINBAR_HEIGHT(wp)); --- 1167,1173 ---- } if (flags & (WSP_TOP | WSP_BOT)) { ! // set height and row of new window to full height wp->w_winrow = tabline_height(); win_new_height(wp, curfrp->fr_height - (p_ls > 0) - WINBAR_HEIGHT(wp)); *************** *** 1176,1190 **** } else { ! /* height and row of new window is same as current window */ wp->w_winrow = oldwin->w_winrow; win_new_height(wp, VISIBLE_HEIGHT(oldwin)); wp->w_status_height = oldwin->w_status_height; } frp->fr_height = curfrp->fr_height; ! /* "new_size" of the current window goes to the new window, use ! * one column for the vertical separator */ win_new_width(wp, new_size); if (before) wp->w_vsep_width = 1; --- 1175,1189 ---- } else { ! // height and row of new window is same as current window wp->w_winrow = oldwin->w_winrow; win_new_height(wp, VISIBLE_HEIGHT(oldwin)); wp->w_status_height = oldwin->w_status_height; } frp->fr_height = curfrp->fr_height; ! // "new_size" of the current window goes to the new window, use ! // one column for the vertical separator win_new_width(wp, new_size); if (before) wp->w_vsep_width = 1; *************** *** 1197,1222 **** { if (flags & WSP_BOT) frame_add_vsep(curfrp); ! /* Set width of neighbor frame */ frame_new_width(curfrp, curfrp->fr_width - (new_size + ((flags & WSP_TOP) != 0)), flags & WSP_TOP, FALSE); } else win_new_width(oldwin, oldwin->w_width - (new_size + 1)); ! if (before) /* new window left of current one */ { wp->w_wincol = oldwin->w_wincol; oldwin->w_wincol += new_size + 1; } ! else /* new window right of current one */ wp->w_wincol = oldwin->w_wincol + oldwin->w_width + 1; frame_fix_width(oldwin); frame_fix_width(wp); } else { ! /* width and column of new window is same as current window */ if (flags & (WSP_TOP | WSP_BOT)) { wp->w_wincol = 0; --- 1196,1221 ---- { if (flags & WSP_BOT) frame_add_vsep(curfrp); ! // Set width of neighbor frame frame_new_width(curfrp, curfrp->fr_width - (new_size + ((flags & WSP_TOP) != 0)), flags & WSP_TOP, FALSE); } else win_new_width(oldwin, oldwin->w_width - (new_size + 1)); ! if (before) // new window left of current one { wp->w_wincol = oldwin->w_wincol; oldwin->w_wincol += new_size + 1; } ! else // new window right of current one wp->w_wincol = oldwin->w_wincol + oldwin->w_width + 1; frame_fix_width(oldwin); frame_fix_width(wp); } else { ! // width and column of new window is same as current window if (flags & (WSP_TOP | WSP_BOT)) { wp->w_wincol = 0; *************** *** 1231,1238 **** } frp->fr_width = curfrp->fr_width; ! /* "new_size" of the current window goes to the new window, use ! * one row for the status line */ win_new_height(wp, new_size); if (flags & (WSP_TOP | WSP_BOT)) { --- 1230,1237 ---- } frp->fr_width = curfrp->fr_width; ! // "new_size" of the current window goes to the new window, use ! // one row for the status line win_new_height(wp, new_size); if (flags & (WSP_TOP | WSP_BOT)) { *************** *** 1245,1257 **** } else win_new_height(oldwin, oldwin_height - (new_size + STATUS_HEIGHT)); ! if (before) /* new window above current one */ { wp->w_winrow = oldwin->w_winrow; wp->w_status_height = STATUS_HEIGHT; oldwin->w_winrow += wp->w_height + STATUS_HEIGHT; } ! else /* new window below current one */ { wp->w_winrow = oldwin->w_winrow + VISIBLE_HEIGHT(oldwin) + STATUS_HEIGHT; --- 1244,1256 ---- } else win_new_height(oldwin, oldwin_height - (new_size + STATUS_HEIGHT)); ! if (before) // new window above current one { wp->w_winrow = oldwin->w_winrow; wp->w_status_height = STATUS_HEIGHT; oldwin->w_winrow += wp->w_height + STATUS_HEIGHT; } ! else // new window below current one { wp->w_winrow = oldwin->w_winrow + VISIBLE_HEIGHT(oldwin) + STATUS_HEIGHT; *************** *** 1280,1289 **** { msg_row = Rows - 1; msg_col = sc_col; ! msg_clr_eos_force(); /* Old command/ruler may still be there */ comp_col(); msg_row = Rows - 1; ! msg_col = 0; /* put position back at start of line */ } /* --- 1279,1288 ---- { msg_row = Rows - 1; msg_col = sc_col; ! msg_clr_eos_force(); // Old command/ruler may still be there comp_col(); msg_row = Rows - 1; ! msg_col = 0; // put position back at start of line } /* *************** *** 1294,1301 **** (flags & WSP_VERT) ? (dir == 'v' ? 'b' : 'h') : dir == 'h' ? 'b' : 'v'); ! /* Don't change the window height/width to 'winheight' / 'winwidth' if a ! * size was given. */ if (flags & WSP_VERT) { i = p_wiw; --- 1293,1300 ---- (flags & WSP_VERT) ? (dir == 'v' ? 'b' : 'h') : dir == 'h' ? 'b' : 'v'); ! // Don't change the window height/width to 'winheight' / 'winwidth' if a ! // size was given. if (flags & WSP_VERT) { i = p_wiw; *************** *** 1303,1309 **** p_wiw = size; # ifdef FEAT_GUI ! /* When 'guioptions' includes 'L' or 'R' may have to add scrollbars. */ if (gui.in_use) gui_init_which_components(NULL); # endif --- 1302,1308 ---- p_wiw = size; # ifdef FEAT_GUI ! // When 'guioptions' includes 'L' or 'R' may have to add scrollbars. if (gui.in_use) gui_init_which_components(NULL); # endif *************** *** 1316,1322 **** } #ifdef FEAT_JUMPLIST ! /* Keep same changelist position in new window. */ wp->w_changelistidx = oldwin->w_changelistidx; #endif --- 1315,1321 ---- } #ifdef FEAT_JUMPLIST ! // Keep same changelist position in new window. wp->w_changelistidx = oldwin->w_changelistidx; #endif *************** *** 1371,1377 **** #ifdef FEAT_QUICKFIX if (flags & WSP_NEWLOC) { ! /* Don't copy the location list. */ newp->w_llist = NULL; newp->w_llist_ref = NULL; } --- 1370,1376 ---- #ifdef FEAT_QUICKFIX if (flags & WSP_NEWLOC) { ! // Don't copy the location list. newp->w_llist = NULL; newp->w_llist_ref = NULL; } *************** *** 1381,1387 **** newp->w_localdir = (oldp->w_localdir == NULL) ? NULL : vim_strsave(oldp->w_localdir); ! /* copy tagstack and folds */ for (i = 0; i < oldp->w_tagstacklen; i++) { taggy_T *tag = &newp->w_tagstack[i]; --- 1380,1386 ---- newp->w_localdir = (oldp->w_localdir == NULL) ? NULL : vim_strsave(oldp->w_localdir); ! // copy tagstack and folds for (i = 0; i < oldp->w_tagstacklen; i++) { taggy_T *tag = &newp->w_tagstack[i]; *************** *** 1411,1422 **** static void win_init_some(win_T *newp, win_T *oldp) { ! /* Use the same argument list. */ newp->w_alist = oldp->w_alist; ++newp->w_alist->al_refcount; newp->w_arg_idx = oldp->w_arg_idx; ! /* copy options from existing window */ win_copy_options(oldp, newp); } --- 1410,1421 ---- static void win_init_some(win_T *newp, win_T *oldp) { ! // Use the same argument list. newp->w_alist = oldp->w_alist; ++newp->w_alist->al_refcount; newp->w_arg_idx = oldp->w_arg_idx; ! // copy options from existing window win_copy_options(oldp, newp); } *************** *** 1505,1525 **** int make_windows( int count, ! int vertical UNUSED) /* split windows vertically if TRUE */ { int maxcount; int todo; if (vertical) { ! /* Each windows needs at least 'winminwidth' lines and a separator ! * column. */ maxcount = (curwin->w_width + curwin->w_vsep_width - (p_wiw - p_wmw)) / (p_wmw + 1); } else { ! /* Each window needs at least 'winminheight' lines and a status line. */ maxcount = (VISIBLE_HEIGHT(curwin) + curwin->w_status_height - (p_wh - p_wmh)) / (p_wmh + STATUS_HEIGHT); } --- 1504,1524 ---- int make_windows( int count, ! int vertical UNUSED) // split windows vertically if TRUE { int maxcount; int todo; if (vertical) { ! // Each windows needs at least 'winminwidth' lines and a separator ! // column. maxcount = (curwin->w_width + curwin->w_vsep_width - (p_wiw - p_wmw)) / (p_wmw + 1); } else { ! // Each window needs at least 'winminheight' lines and a status line. maxcount = (VISIBLE_HEIGHT(curwin) + curwin->w_status_height - (p_wh - p_wmh)) / (p_wmh + STATUS_HEIGHT); } *************** *** 1541,1547 **** */ block_autocmds(); ! /* todo is number of windows left to create */ for (todo = count - 1; todo > 0; --todo) if (vertical) { --- 1540,1546 ---- */ block_autocmds(); ! // todo is number of windows left to create for (todo = count - 1; todo > 0; --todo) if (vertical) { *************** *** 1559,1565 **** unblock_autocmds(); ! /* return actual number of windows */ return (count - todo); } --- 1558,1564 ---- unblock_autocmds(); ! // return actual number of windows return (count - todo); } *************** *** 1596,1608 **** while (frp != NULL && --Prenum > 0) frp = frp->fr_next; } ! else if (curwin->w_frame->fr_next != NULL) /* Swap with next */ frp = curwin->w_frame->fr_next; ! else /* Swap last window in row/col with previous */ frp = curwin->w_frame->fr_prev; ! /* We can only exchange a window with another window, not with a frame ! * containing windows. */ if (frp == NULL || frp->fr_win == NULL || frp->fr_win == curwin) return; wp = frp->fr_win; --- 1595,1607 ---- while (frp != NULL && --Prenum > 0) frp = frp->fr_next; } ! else if (curwin->w_frame->fr_next != NULL) // Swap with next frp = curwin->w_frame->fr_next; ! else // Swap last window in row/col with previous frp = curwin->w_frame->fr_prev; ! // We can only exchange a window with another window, not with a frame ! // containing windows. if (frp == NULL || frp->fr_win == NULL || frp->fr_win == curwin) return; wp = frp->fr_win; *************** *** 1641,1648 **** curwin->w_vsep_width = wp->w_vsep_width; wp->w_vsep_width = temp; ! /* If the windows are not in the same frame, exchange the sizes to avoid ! * messing up the window layout. Otherwise fix the frame sizes. */ if (curwin->w_frame->fr_parent != wp->w_frame->fr_parent) { temp = curwin->w_height; --- 1640,1647 ---- curwin->w_vsep_width = wp->w_vsep_width; wp->w_vsep_width = temp; ! // If the windows are not in the same frame, exchange the sizes to avoid ! // messing up the window layout. Otherwise fix the frame sizes. if (curwin->w_frame->fr_parent != wp->w_frame->fr_parent) { temp = curwin->w_height; *************** *** 1660,1666 **** frame_fix_width(wp); } ! (void)win_comp_pos(); /* recompute window positions */ win_enter(wp, TRUE); redraw_all_later(NOT_VALID); --- 1659,1665 ---- frame_fix_width(wp); } ! (void)win_comp_pos(); // recompute window positions win_enter(wp, TRUE); redraw_all_later(NOT_VALID); *************** *** 1678,1684 **** frame_T *frp; int n; ! if (ONE_WINDOW) /* nothing to do */ { beep_flush(); return; --- 1677,1683 ---- frame_T *frp; int n; ! if (ONE_WINDOW) // nothing to do { beep_flush(); return; *************** *** 1688,1694 **** need_mouse_correct = TRUE; #endif ! /* Check if all frames in this row/col have one window. */ FOR_ALL_FRAMES(frp, curwin->w_frame->fr_parent->fr_child) if (frp->fr_win == NULL) { --- 1687,1693 ---- need_mouse_correct = TRUE; #endif ! // Check if all frames in this row/col have one window. FOR_ALL_FRAMES(frp, curwin->w_frame->fr_parent->fr_child) if (frp->fr_win == NULL) { *************** *** 1698,1736 **** while (count--) { ! if (upwards) /* first window becomes last window */ { ! /* remove first window/frame from the list */ frp = curwin->w_frame->fr_parent->fr_child; wp1 = frp->fr_win; win_remove(wp1, NULL); frame_remove(frp); ! /* find last frame and append removed window/frame after it */ for ( ; frp->fr_next != NULL; frp = frp->fr_next) ; win_append(frp->fr_win, wp1); frame_append(frp, wp1->w_frame); ! wp2 = frp->fr_win; /* previously last window */ } ! else /* last window becomes first window */ { ! /* find last window/frame in the list and remove it */ for (frp = curwin->w_frame; frp->fr_next != NULL; frp = frp->fr_next) ; wp1 = frp->fr_win; ! wp2 = wp1->w_prev; /* will become last window */ win_remove(wp1, NULL); frame_remove(frp); ! /* append the removed window/frame before the first in the list */ win_append(frp->fr_parent->fr_child->fr_win->w_prev, wp1); frame_insert(frp->fr_parent->fr_child, frp); } ! /* exchange status height and vsep width of old and new last window */ n = wp2->w_status_height; wp2->w_status_height = wp1->w_status_height; wp1->w_status_height = n; --- 1697,1735 ---- while (count--) { ! if (upwards) // first window becomes last window { ! // remove first window/frame from the list frp = curwin->w_frame->fr_parent->fr_child; wp1 = frp->fr_win; win_remove(wp1, NULL); frame_remove(frp); ! // find last frame and append removed window/frame after it for ( ; frp->fr_next != NULL; frp = frp->fr_next) ; win_append(frp->fr_win, wp1); frame_append(frp, wp1->w_frame); ! wp2 = frp->fr_win; // previously last window } ! else // last window becomes first window { ! // find last window/frame in the list and remove it for (frp = curwin->w_frame; frp->fr_next != NULL; frp = frp->fr_next) ; wp1 = frp->fr_win; ! wp2 = wp1->w_prev; // will become last window win_remove(wp1, NULL); frame_remove(frp); ! // append the removed window/frame before the first in the list win_append(frp->fr_parent->fr_child->fr_win->w_prev, wp1); frame_insert(frp->fr_parent->fr_child, frp); } ! // exchange status height and vsep width of old and new last window n = wp2->w_status_height; wp2->w_status_height = wp1->w_status_height; wp1->w_status_height = n; *************** *** 1742,1748 **** frame_fix_width(wp1); frame_fix_width(wp2); ! /* recompute w_winrow and w_wincol for all windows */ (void)win_comp_pos(); } --- 1741,1747 ---- frame_fix_width(wp1); frame_fix_width(wp2); ! // recompute w_winrow and w_wincol for all windows (void)win_comp_pos(); } *************** *** 1766,1778 **** if (check_split_disallowed() == FAIL) return; ! /* Remove the window and frame from the tree of frames. */ (void)winframe_remove(curwin, &dir, NULL); win_remove(curwin, NULL); ! last_status(FALSE); /* may need to remove last status line */ ! (void)win_comp_pos(); /* recompute window positions */ ! /* Split a window on the desired side and put the window there. */ (void)win_split_ins(size, flags, curwin, dir); if (!(flags & WSP_VERT)) { --- 1765,1777 ---- if (check_split_disallowed() == FAIL) return; ! // Remove the window and frame from the tree of frames. (void)winframe_remove(curwin, &dir, NULL); win_remove(curwin, NULL); ! last_status(FALSE); // may need to remove last status line ! (void)win_comp_pos(); // recompute window positions ! // Split a window on the desired side and put the window there. (void)win_split_ins(size, flags, curwin, dir); if (!(flags & WSP_VERT)) { *************** *** 1782,1789 **** } #if defined(FEAT_GUI) ! /* When 'guioptions' includes 'L' or 'R' may have to remove or add ! * scrollbars. Have to update them anyway. */ gui_may_update_scrollbars(); #endif } --- 1781,1788 ---- } #if defined(FEAT_GUI) ! // When 'guioptions' includes 'L' or 'R' may have to remove or add ! // scrollbars. Have to update them anyway. gui_may_update_scrollbars(); #endif } *************** *** 1797,1807 **** { int height; ! /* check if the arguments are reasonable */ if (win1 == win2) return; ! /* check if there is something to do */ if (win2->w_next != win1) { if (win1->w_frame->fr_parent != win2->w_frame->fr_parent) --- 1796,1806 ---- { int height; ! // check if the arguments are reasonable if (win1 == win2) return; ! // check if there is something to do if (win2->w_next != win1) { if (win1->w_frame->fr_parent != win2->w_frame->fr_parent) *************** *** 1810,1817 **** return; } ! /* may need move the status line/vertical separator of the last window ! * */ if (win1 == lastwin) { height = win1->w_prev->w_status_height; --- 1809,1816 ---- return; } ! // may need move the status line/vertical separator of the last window ! // if (win1 == lastwin) { height = win1->w_prev->w_status_height; *************** *** 1819,1826 **** win1->w_status_height = height; if (win1->w_prev->w_vsep_width == 1) { ! /* Remove the vertical separator from the last-but-one window, ! * add it to the last window. Adjust the frame widths. */ win1->w_prev->w_vsep_width = 0; win1->w_prev->w_frame->fr_width -= 1; win1->w_vsep_width = 1; --- 1818,1825 ---- win1->w_status_height = height; if (win1->w_prev->w_vsep_width == 1) { ! // Remove the vertical separator from the last-but-one window, ! // add it to the last window. Adjust the frame widths. win1->w_prev->w_vsep_width = 0; win1->w_prev->w_frame->fr_width -= 1; win1->w_vsep_width = 1; *************** *** 1834,1841 **** win2->w_status_height = height; if (win1->w_vsep_width == 1) { ! /* Remove the vertical separator from win1, add it to the last ! * window, win2. Adjust the frame widths. */ win2->w_vsep_width = 1; win2->w_frame->fr_width += 1; win1->w_vsep_width = 0; --- 1833,1840 ---- win2->w_status_height = height; if (win1->w_vsep_width == 1) { ! // Remove the vertical separator from win1, add it to the last ! // window, win2. Adjust the frame widths. win2->w_vsep_width = 1; win2->w_frame->fr_width += 1; win1->w_vsep_width = 0; *************** *** 1847,1853 **** win_append(win2, win1); frame_append(win2->w_frame, win1->w_frame); ! (void)win_comp_pos(); /* recompute w_winrow for all windows */ redraw_later(NOT_VALID); } win_enter(win1, FALSE); --- 1846,1852 ---- win_append(win2, win1); frame_append(win2->w_frame, win1->w_frame); ! (void)win_comp_pos(); // recompute w_winrow for all windows redraw_later(NOT_VALID); } win_enter(win1, FALSE); *************** *** 1860,1869 **** */ void win_equal( ! win_T *next_curwin, /* pointer to current window to be or NULL */ ! int current, /* do only frame with current window */ ! int dir) /* 'v' for vertically, 'h' for horizontally, ! 'b' for both, 0 for using p_ead */ { if (dir == 0) dir = *p_ead; --- 1859,1868 ---- */ void win_equal( ! win_T *next_curwin, // pointer to current window to be or NULL ! int current, // do only frame with current window ! int dir) // 'v' for vertically, 'h' for horizontally, ! // 'b' for both, 0 for using p_ead { if (dir == 0) dir = *p_ead; *************** *** 1880,1893 **** */ static void win_equal_rec( ! win_T *next_curwin, /* pointer to current window to be or NULL */ ! int current, /* do only frame with current window */ ! frame_T *topfr, /* frame to set size off */ ! int dir, /* 'v', 'h' or 'b', see win_equal() */ ! int col, /* horizontal position for frame */ ! int row, /* vertical position for frame */ ! int width, /* new width of frame */ ! int height) /* new height of frame */ { int n, m; int extra_sep = 0; --- 1879,1892 ---- */ static void win_equal_rec( ! win_T *next_curwin, // pointer to current window to be or NULL ! int current, // do only frame with current window ! frame_T *topfr, // frame to set size off ! int dir, // 'v', 'h' or 'b', see win_equal() ! int col, // horizontal position for frame ! int row, // vertical position for frame ! int width, // new width of frame ! int height) // new height of frame { int n, m; int extra_sep = 0; *************** *** 1901,1908 **** if (topfr->fr_layout == FR_LEAF) { ! /* Set the width/height of this frame. ! * Redraw when size or position changes */ if (topfr->fr_height != height || topfr->fr_win->w_winrow != row || topfr->fr_width != width || topfr->fr_win->w_wincol != col ) --- 1900,1907 ---- if (topfr->fr_layout == FR_LEAF) { ! // Set the width/height of this frame. ! // Redraw when size or position changes if (topfr->fr_height != height || topfr->fr_win->w_winrow != row || topfr->fr_width != width || topfr->fr_win->w_wincol != col ) *************** *** 1919,1930 **** topfr->fr_width = width; topfr->fr_height = height; ! if (dir != 'v') /* equalize frame widths */ { ! /* Compute the maximum number of windows horizontally in this ! * frame. */ n = frame_minwidth(topfr, NOWIN); ! /* add one for the rightmost window, it doesn't have a separator */ if (col + width == Columns) extra_sep = 1; else --- 1918,1929 ---- topfr->fr_width = width; topfr->fr_height = height; ! if (dir != 'v') // equalize frame widths { ! // Compute the maximum number of windows horizontally in this ! // frame. n = frame_minwidth(topfr, NOWIN); ! // add one for the rightmost window, it doesn't have a separator if (col + width == Columns) extra_sep = 1; else *************** *** 1949,1957 **** next_curwin_size = -1; FOR_ALL_FRAMES(fr, topfr->fr_child) { ! /* If 'winfixwidth' set keep the window width if ! * possible. ! * Watch out for this window being the next_curwin. */ if (frame_fixed_width(fr)) { n = frame_minwidth(fr, NOWIN); --- 1948,1956 ---- next_curwin_size = -1; FOR_ALL_FRAMES(fr, topfr->fr_child) { ! // If 'winfixwidth' set keep the window width if ! // possible. ! // Watch out for this window being the next_curwin. if (frame_fixed_width(fr)) { n = frame_minwidth(fr, NOWIN); *************** *** 1964,1970 **** new_size = p_wiw; } else ! /* These windows don't use up room. */ totwincount -= (n + (fr->fr_next == NULL ? extra_sep : 0)) / (p_wmw + 1); room -= new_size - n; --- 1963,1969 ---- new_size = p_wiw; } else ! // These windows don't use up room. totwincount -= (n + (fr->fr_next == NULL ? extra_sep : 0)) / (p_wmw + 1); room -= new_size - n; *************** *** 1984,1991 **** && (room + (totwincount - 2)) / (totwincount - 1) > p_wiw) { ! /* Can make all windows wider than 'winwidth', spread ! * the room equally. */ next_curwin_size = (room + p_wiw + (totwincount - 1) * p_wmw + (totwincount - 1)) / totwincount; --- 1983,1990 ---- && (room + (totwincount - 2)) / (totwincount - 1) > p_wiw) { ! // Can make all windows wider than 'winwidth', spread ! // the room equally. next_curwin_size = (room + p_wiw + (totwincount - 1) * p_wmw + (totwincount - 1)) / totwincount; *************** *** 1997,2021 **** } if (has_next_curwin) ! --totwincount; /* don't count curwin */ } FOR_ALL_FRAMES(fr, topfr->fr_child) { wincount = 1; if (fr->fr_next == NULL) ! /* last frame gets all that remains (avoid roundoff error) */ new_size = width; else if (dir == 'v') new_size = fr->fr_width; else if (frame_fixed_width(fr)) { new_size = fr->fr_newwidth; ! wincount = 0; /* doesn't count as a sizeable window */ } else { ! /* Compute the maximum number of windows horiz. in "fr". */ n = frame_minwidth(fr, NOWIN); wincount = (n + (fr->fr_next == NULL ? extra_sep : 0)) / (p_wmw + 1); --- 1996,2020 ---- } if (has_next_curwin) ! --totwincount; // don't count curwin } FOR_ALL_FRAMES(fr, topfr->fr_child) { wincount = 1; if (fr->fr_next == NULL) ! // last frame gets all that remains (avoid roundoff error) new_size = width; else if (dir == 'v') new_size = fr->fr_width; else if (frame_fixed_width(fr)) { new_size = fr->fr_newwidth; ! wincount = 0; // doesn't count as a sizeable window } else { ! // Compute the maximum number of windows horiz. in "fr". n = frame_minwidth(fr, NOWIN); wincount = (n + (fr->fr_next == NULL ? extra_sep : 0)) / (p_wmw + 1); *************** *** 2024,2037 **** hnc = frame_has_win(fr, next_curwin); else hnc = FALSE; ! if (hnc) /* don't count next_curwin */ --wincount; if (totwincount == 0) new_size = room; else new_size = (wincount * room + ((unsigned)totwincount >> 1)) / totwincount; ! if (hnc) /* add next_curwin size */ { next_curwin_size -= p_wiw - (m - n); new_size += next_curwin_size; --- 2023,2036 ---- hnc = frame_has_win(fr, next_curwin); else hnc = FALSE; ! if (hnc) // don't count next_curwin --wincount; if (totwincount == 0) new_size = room; else new_size = (wincount * room + ((unsigned)totwincount >> 1)) / totwincount; ! if (hnc) // add next_curwin size { next_curwin_size -= p_wiw - (m - n); new_size += next_curwin_size; *************** *** 2042,2049 **** new_size += n; } ! /* Skip frame that is full width when splitting or closing a ! * window, unless equalizing all frames. */ if (!current || dir != 'v' || topfr->fr_parent != NULL || (new_size != fr->fr_width) || frame_has_win(fr, next_curwin)) --- 2041,2048 ---- new_size += n; } ! // Skip frame that is full width when splitting or closing a ! // window, unless equalizing all frames. if (!current || dir != 'v' || topfr->fr_parent != NULL || (new_size != fr->fr_width) || frame_has_win(fr, next_curwin)) *************** *** 2054,2069 **** totwincount -= wincount; } } ! else /* topfr->fr_layout == FR_COL */ { topfr->fr_width = width; topfr->fr_height = height; ! if (dir != 'h') /* equalize frame heights */ { ! /* Compute maximum number of windows vertically in this frame. */ n = frame_minheight(topfr, NOWIN); ! /* add one for the bottom window if it doesn't have a statusline */ if (row + height == cmdline_row && p_ls == 0) extra_sep = 1; else --- 2053,2068 ---- totwincount -= wincount; } } ! else // topfr->fr_layout == FR_COL { topfr->fr_width = width; topfr->fr_height = height; ! if (dir != 'h') // equalize frame heights { ! // Compute maximum number of windows vertically in this frame. n = frame_minheight(topfr, NOWIN); ! // add one for the bottom window if it doesn't have a statusline if (row + height == cmdline_row && p_ls == 0) extra_sep = 1; else *************** *** 2080,2087 **** room = height - m; if (room < 0) { ! /* The room is less then 'winheight', use all space for the ! * current window. */ next_curwin_size = p_wh + room; room = 0; } --- 2079,2086 ---- room = height - m; if (room < 0) { ! // The room is less then 'winheight', use all space for the ! // current window. next_curwin_size = p_wh + room; room = 0; } *************** *** 2090,2098 **** next_curwin_size = -1; FOR_ALL_FRAMES(fr, topfr->fr_child) { ! /* If 'winfixheight' set keep the window height if ! * possible. ! * Watch out for this window being the next_curwin. */ if (frame_fixed_height(fr)) { n = frame_minheight(fr, NOWIN); --- 2089,2097 ---- next_curwin_size = -1; FOR_ALL_FRAMES(fr, topfr->fr_child) { ! // If 'winfixheight' set keep the window height if ! // possible. ! // Watch out for this window being the next_curwin. if (frame_fixed_height(fr)) { n = frame_minheight(fr, NOWIN); *************** *** 2105,2111 **** new_size = p_wh; } else ! /* These windows don't use up room. */ totwincount -= (n + (fr->fr_next == NULL ? extra_sep : 0)) / (p_wmh + 1); room -= new_size - n; --- 2104,2110 ---- new_size = p_wh; } else ! // These windows don't use up room. totwincount -= (n + (fr->fr_next == NULL ? extra_sep : 0)) / (p_wmh + 1); room -= new_size - n; *************** *** 2125,2132 **** && (room + (totwincount - 2)) / (totwincount - 1) > p_wh) { ! /* can make all windows higher than 'winheight', ! * spread the room equally. */ next_curwin_size = (room + p_wh + (totwincount - 1) * p_wmh + (totwincount - 1)) / totwincount; --- 2124,2131 ---- && (room + (totwincount - 2)) / (totwincount - 1) > p_wh) { ! // can make all windows higher than 'winheight', ! // spread the room equally. next_curwin_size = (room + p_wh + (totwincount - 1) * p_wmh + (totwincount - 1)) / totwincount; *************** *** 2138,2162 **** } if (has_next_curwin) ! --totwincount; /* don't count curwin */ } FOR_ALL_FRAMES(fr, topfr->fr_child) { wincount = 1; if (fr->fr_next == NULL) ! /* last frame gets all that remains (avoid roundoff error) */ new_size = height; else if (dir == 'h') new_size = fr->fr_height; else if (frame_fixed_height(fr)) { new_size = fr->fr_newheight; ! wincount = 0; /* doesn't count as a sizeable window */ } else { ! /* Compute the maximum number of windows vert. in "fr". */ n = frame_minheight(fr, NOWIN); wincount = (n + (fr->fr_next == NULL ? extra_sep : 0)) / (p_wmh + 1); --- 2137,2161 ---- } if (has_next_curwin) ! --totwincount; // don't count curwin } FOR_ALL_FRAMES(fr, topfr->fr_child) { wincount = 1; if (fr->fr_next == NULL) ! // last frame gets all that remains (avoid roundoff error) new_size = height; else if (dir == 'h') new_size = fr->fr_height; else if (frame_fixed_height(fr)) { new_size = fr->fr_newheight; ! wincount = 0; // doesn't count as a sizeable window } else { ! // Compute the maximum number of windows vert. in "fr". n = frame_minheight(fr, NOWIN); wincount = (n + (fr->fr_next == NULL ? extra_sep : 0)) / (p_wmh + 1); *************** *** 2165,2178 **** hnc = frame_has_win(fr, next_curwin); else hnc = FALSE; ! if (hnc) /* don't count next_curwin */ --wincount; if (totwincount == 0) new_size = room; else new_size = (wincount * room + ((unsigned)totwincount >> 1)) / totwincount; ! if (hnc) /* add next_curwin size */ { next_curwin_size -= p_wh - (m - n); new_size += next_curwin_size; --- 2164,2177 ---- hnc = frame_has_win(fr, next_curwin); else hnc = FALSE; ! if (hnc) // don't count next_curwin --wincount; if (totwincount == 0) new_size = room; else new_size = (wincount * room + ((unsigned)totwincount >> 1)) / totwincount; ! if (hnc) // add next_curwin size { next_curwin_size -= p_wh - (m - n); new_size += next_curwin_size; *************** *** 2182,2189 **** room -= new_size; new_size += n; } ! /* Skip frame that is full width when splitting or closing a ! * window, unless equalizing all frames. */ if (!current || dir != 'h' || topfr->fr_parent != NULL || (new_size != fr->fr_height) || frame_has_win(fr, next_curwin)) --- 2181,2188 ---- room -= new_size; new_size += n; } ! // Skip frame that is full width when splitting or closing a ! // window, unless equalizing all frames. if (!current || dir != 'h' || topfr->fr_parent != NULL || (new_size != fr->fr_height) || frame_has_win(fr, next_curwin)) *************** *** 2208,2214 **** // it when entering that window again. win->w_buffer->b_prompt_insert = restart_edit; if (restart_edit != 0 && mode_displayed) ! clear_cmdline = TRUE; /* unshow mode later */ restart_edit = NUL; // When leaving the window (or closing the window) was done from a --- 2207,2213 ---- // it when entering that window again. win->w_buffer->b_prompt_insert = restart_edit; if (restart_edit != 0 && mode_displayed) ! clear_cmdline = TRUE; // unshow mode later restart_edit = NUL; // When leaving the window (or closing the window) was done from a *************** *** 2246,2252 **** void close_windows( buf_T *buf, ! int keep_curwin) /* don't close "curwin" */ { win_T *wp; tabpage_T *tp, *nexttp; --- 2245,2251 ---- void close_windows( buf_T *buf, ! int keep_curwin) // don't close "curwin" { win_T *wp; tabpage_T *tp, *nexttp; *************** *** 2261,2278 **** && !(wp->w_closing || wp->w_buffer->b_locked > 0)) { if (win_close(wp, FALSE) == FAIL) ! /* If closing the window fails give up, to avoid looping ! * forever. */ break; ! /* Start all over, autocommands may change the window layout. */ wp = firstwin; } else wp = wp->w_next; } ! /* Also check windows in other tab pages. */ for (tp = first_tabpage; tp != NULL; tp = nexttp) { nexttp = tp->tp_next; --- 2260,2277 ---- && !(wp->w_closing || wp->w_buffer->b_locked > 0)) { if (win_close(wp, FALSE) == FAIL) ! // If closing the window fails give up, to avoid looping ! // forever. break; ! // Start all over, autocommands may change the window layout. wp = firstwin; } else wp = wp->w_next; } ! // Also check windows in other tab pages. for (tp = first_tabpage; tp != NULL; tp = nexttp) { nexttp = tp->tp_next; *************** *** 2283,2290 **** { win_close_othertab(wp, FALSE, tp); ! /* Start all over, the tab page may be closed and ! * autocommands may change the window layout. */ nexttp = first_tabpage; break; } --- 2282,2289 ---- { win_close_othertab(wp, FALSE, tp); ! // Start all over, the tab page may be closed and ! // autocommands may change the window layout. nexttp = first_tabpage; break; } *************** *** 2358,2365 **** goto_tabpage_tp(alt_tabpage(), FALSE, TRUE); redraw_tabline = TRUE; ! /* Safety check: Autocommands may have closed the window when jumping ! * to the other tab page. */ if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win) { int h = tabline_height(); --- 2357,2364 ---- goto_tabpage_tp(alt_tabpage(), FALSE, TRUE); redraw_tabline = TRUE; ! // Safety check: Autocommands may have closed the window when jumping ! // to the other tab page. if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win) { int h = tabline_height(); *************** *** 2371,2378 **** #ifdef FEAT_JOB_CHANNEL entering_window(curwin); #endif ! /* Since goto_tabpage_tp above did not trigger *Enter autocommands, do ! * that now. */ apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); --- 2370,2377 ---- #ifdef FEAT_JOB_CHANNEL entering_window(curwin); #endif ! // Since goto_tabpage_tp above did not trigger *Enter autocommands, do ! // that now. apply_autocmds(EVENT_TABCLOSED, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_WINENTER, NULL, NULL, FALSE, curbuf); apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); *************** *** 2453,2459 **** if (win->w_closing || (win->w_buffer != NULL && win->w_buffer->b_locked > 0)) ! return FAIL; /* window is already being closed */ if (win_unlisted(win)) { emsg(_("E813: Cannot close autocmd or popup window")); --- 2452,2458 ---- if (win->w_closing || (win->w_buffer != NULL && win->w_buffer->b_locked > 0)) ! return FAIL; // window is already being closed if (win_unlisted(win)) { emsg(_("E813: Cannot close autocmd or popup window")); *************** *** 2465,2478 **** return FAIL; } ! /* When closing the last window in a tab page first go to another tab page ! * and then close the window and the tab page to avoid that curwin and ! * curtab are invalid while we are freeing memory. */ if (close_last_window_tabpage(win, free_buf, prev_curtab)) return FAIL; ! /* When closing the help window, try restoring a snapshot after closing ! * the window. Otherwise clear the snapshot, it's now invalid. */ if (bt_help(win->w_buffer)) help_window = TRUE; else --- 2464,2477 ---- return FAIL; } ! // When closing the last window in a tab page first go to another tab page ! // and then close the window and the tab page to avoid that curwin and ! // curtab are invalid while we are freeing memory. if (close_last_window_tabpage(win, free_buf, prev_curtab)) return FAIL; ! // When closing the help window, try restoring a snapshot after closing ! // the window. Otherwise clear the snapshot, it's now invalid. if (bt_help(win->w_buffer)) help_window = TRUE; else *************** *** 2512,2518 **** if (last_window()) return FAIL; #ifdef FEAT_EVAL ! /* autocmds may abort script processing */ if (aborting()) return FAIL; #endif --- 2511,2517 ---- if (last_window()) return FAIL; #ifdef FEAT_EVAL ! // autocmds may abort script processing if (aborting()) return FAIL; #endif *************** *** 2535,2558 **** && (last_window() || curtab != prev_curtab || close_last_window_tabpage(win, free_buf, prev_curtab))) { ! /* Autocommands have closed all windows, quit now. Restore ! * curwin->w_buffer, otherwise writing viminfo may fail. */ if (curwin->w_buffer == NULL) curwin->w_buffer = curbuf; getout(0); } ! /* Autocommands may have moved to another tab page. */ if (curtab != prev_curtab && win_valid_any_tab(win) && win->w_buffer == NULL) { ! /* Need to close the window anyway, since the buffer is NULL. */ win_close_othertab(win, FALSE, prev_curtab); return FAIL; } ! /* Autocommands may have closed the window already or closed the only ! * other window. */ if (!win_valid(win) || last_window() || close_last_window_tabpage(win, free_buf, prev_curtab)) return FAIL; --- 2534,2557 ---- && (last_window() || curtab != prev_curtab || close_last_window_tabpage(win, free_buf, prev_curtab))) { ! // Autocommands have closed all windows, quit now. Restore ! // curwin->w_buffer, otherwise writing viminfo may fail. if (curwin->w_buffer == NULL) curwin->w_buffer = curbuf; getout(0); } ! // Autocommands may have moved to another tab page. if (curtab != prev_curtab && win_valid_any_tab(win) && win->w_buffer == NULL) { ! // Need to close the window anyway, since the buffer is NULL. win_close_othertab(win, FALSE, prev_curtab); return FAIL; } ! // Autocommands may have closed the window already or closed the only ! // other window. if (!win_valid(win) || last_window() || close_last_window_tabpage(win, free_buf, prev_curtab)) return FAIL; *************** *** 2561,2573 **** // to split a window to avoid trouble. ++split_disallowed; ! /* Free the memory used for the window and get the window that received ! * the screen space. */ wp = win_free_mem(win, &dir, NULL); ! /* Make sure curwin isn't invalid. It can cause severe trouble when ! * printing an error message. For win_equal() curbuf needs to be valid ! * too. */ if (win == curwin) { curwin = wp; --- 2560,2572 ---- // to split a window to avoid trouble. ++split_disallowed; ! // Free the memory used for the window and get the window that received ! // the screen space. wp = win_free_mem(win, &dir, NULL); ! // Make sure curwin isn't invalid. It can cause severe trouble when ! // printing an error message. For win_equal() curbuf needs to be valid ! // too. if (win == curwin) { curwin = wp; *************** *** 2597,2609 **** curbuf = curwin->w_buffer; close_curwin = TRUE; ! /* The cursor position may be invalid if the buffer changed after last ! * using the window. */ check_cursor(); } if (p_ea && (*p_ead == 'b' || *p_ead == dir)) ! /* If the frame of the closed window contains the new current window, ! * only resize that frame. Otherwise resize all windows. */ win_equal(curwin, curwin->w_frame->fr_parent == win_frame, dir); else win_comp_pos(); --- 2596,2608 ---- curbuf = curwin->w_buffer; close_curwin = TRUE; ! // The cursor position may be invalid if the buffer changed after last ! // using the window. check_cursor(); } if (p_ea && (*p_ead == 'b' || *p_ead == dir)) ! // If the frame of the closed window contains the new current window, ! // only resize that frame. Otherwise resize all windows. win_equal(curwin, curwin->w_frame->fr_parent == win_frame, dir); else win_comp_pos(); *************** *** 2611,2617 **** { win_enter_ext(wp, FALSE, TRUE, FALSE, TRUE, TRUE); if (other_buffer) ! /* careful: after this wp and win may be invalid! */ apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); } --- 2610,2616 ---- { win_enter_ext(wp, FALSE, TRUE, FALSE, TRUE, TRUE); if (other_buffer) ! // careful: after this wp and win may be invalid! apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); } *************** *** 2623,2630 **** */ last_status(FALSE); ! /* After closing the help window, try restoring the window layout from ! * before it was opened. */ if (help_window) restore_snapshot(SNAP_HELP_IDX, close_curwin); --- 2622,2629 ---- */ last_status(FALSE); ! // After closing the help window, try restoring the window layout from ! // before it was opened. if (help_window) restore_snapshot(SNAP_HELP_IDX, close_curwin); *************** *** 2646,2652 **** #endif #if defined(FEAT_GUI) ! /* When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. */ if (gui.in_use && !win_hasvertsplit()) gui_init_which_components(NULL); #endif --- 2645,2651 ---- #endif #if defined(FEAT_GUI) ! // When 'guioptions' includes 'L' or 'R' may have to remove scrollbars. if (gui.in_use && !win_hasvertsplit()) gui_init_which_components(NULL); #endif *************** *** 2670,2699 **** tabpage_T *ptp = NULL; int free_tp = FALSE; ! /* Get here with win->w_buffer == NULL when win_close() detects the tab ! * page changed. */ if (win->w_closing || (win->w_buffer != NULL && win->w_buffer->b_locked > 0)) ! return; /* window is already being closed */ if (win->w_buffer != NULL) ! /* Close the link to the buffer. */ close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, FALSE); ! /* Careful: Autocommands may have closed the tab page or made it the ! * current tab page. */ for (ptp = first_tabpage; ptp != NULL && ptp != tp; ptp = ptp->tp_next) ; if (ptp == NULL || tp == curtab) return; ! /* Autocommands may have closed the window already. */ for (wp = tp->tp_firstwin; wp != NULL && wp != win; wp = wp->w_next) ; if (wp == NULL) return; ! /* When closing the last window in a tab page remove the tab page. */ if (tp->tp_firstwin == tp->tp_lastwin) { if (tp == first_tabpage) --- 2669,2698 ---- tabpage_T *ptp = NULL; int free_tp = FALSE; ! // Get here with win->w_buffer == NULL when win_close() detects the tab ! // page changed. if (win->w_closing || (win->w_buffer != NULL && win->w_buffer->b_locked > 0)) ! return; // window is already being closed if (win->w_buffer != NULL) ! // Close the link to the buffer. close_buffer(win, win->w_buffer, free_buf ? DOBUF_UNLOAD : 0, FALSE); ! // Careful: Autocommands may have closed the tab page or made it the ! // current tab page. for (ptp = first_tabpage; ptp != NULL && ptp != tp; ptp = ptp->tp_next) ; if (ptp == NULL || tp == curtab) return; ! // Autocommands may have closed the window already. for (wp = tp->tp_firstwin; wp != NULL && wp != win; wp = wp->w_next) ; if (wp == NULL) return; ! // When closing the last window in a tab page remove the tab page. if (tp->tp_firstwin == tp->tp_lastwin) { if (tp == first_tabpage) *************** *** 2713,2719 **** free_tp = TRUE; } ! /* Free the memory used for the window. */ win_free_mem(win, &dir, tp); if (free_tp) --- 2712,2718 ---- free_tp = TRUE; } ! // Free the memory used for the window. win_free_mem(win, &dir, tp); if (free_tp) *************** *** 2727,2746 **** static win_T * win_free_mem( win_T *win, ! int *dirp, /* set to 'v' or 'h' for direction if 'ea' */ ! tabpage_T *tp) /* tab page "win" is in, NULL for current */ { frame_T *frp; win_T *wp; ! /* Remove the window and its frame from the tree of frames. */ frp = win->w_frame; wp = winframe_remove(win, dirp, tp); vim_free(frp); win_free(win, tp); ! /* When deleting the current window of another tab page select a new ! * current window. */ if (tp != NULL && win == tp->tp_curwin) tp->tp_curwin = wp; --- 2726,2745 ---- static win_T * win_free_mem( win_T *win, ! int *dirp, // set to 'v' or 'h' for direction if 'ea' ! tabpage_T *tp) // tab page "win" is in, NULL for current { frame_T *frp; win_T *wp; ! // Remove the window and its frame from the tree of frames. frp = win->w_frame; wp = winframe_remove(win, dirp, tp); vim_free(frp); win_free(win, tp); ! // When deleting the current window of another tab page select a new ! // current window. if (tp != NULL && win == tp->tp_curwin) tp->tp_curwin = wp; *************** *** 2768,2775 **** while (firstwin != NULL) (void)win_free_mem(firstwin, &dummy, NULL); ! /* No window should be used after this. Set curwin to NULL to crash ! * instead of using freed memory. */ curwin = NULL; } #endif --- 2767,2774 ---- while (firstwin != NULL) (void)win_free_mem(firstwin, &dummy, NULL); ! // No window should be used after this. Set curwin to NULL to crash ! // instead of using freed memory. curwin = NULL; } #endif *************** *** 2781,2788 **** win_T * winframe_remove( win_T *win, ! int *dirp UNUSED, /* set to 'v' or 'h' for direction if 'ea' */ ! tabpage_T *tp) /* tab page "win" is in, NULL for current */ { frame_T *frp, *frp2, *frp3; frame_T *frp_close = win->w_frame; --- 2780,2787 ---- win_T * winframe_remove( win_T *win, ! int *dirp UNUSED, // set to 'v' or 'h' for direction if 'ea' ! tabpage_T *tp) // tab page "win" is in, NULL for current { frame_T *frp, *frp2, *frp3; frame_T *frp_close = win->w_frame; *************** *** 2800,2813 **** frp2 = win_altframe(win, tp); wp = frame2win(frp2); ! /* Remove this frame from the list of frames. */ frame_remove(frp_close); if (frp_close->fr_parent->fr_layout == FR_COL) { ! /* When 'winfixheight' is set, try to find another frame in the column ! * (as close to the closed frame as possible) to distribute the height ! * to. */ if (frp2->fr_win != NULL && frp2->fr_win->w_p_wfh) { frp = frp_close->fr_prev; --- 2799,2812 ---- frp2 = win_altframe(win, tp); wp = frame2win(frp2); ! // Remove this frame from the list of frames. frame_remove(frp_close); if (frp_close->fr_parent->fr_layout == FR_COL) { ! // When 'winfixheight' is set, try to find another frame in the column ! // (as close to the closed frame as possible) to distribute the height ! // to. if (frp2->fr_win != NULL && frp2->fr_win->w_p_wfh) { frp = frp_close->fr_prev; *************** *** 2842,2850 **** } else { ! /* When 'winfixwidth' is set, try to find another frame in the column ! * (as close to the closed frame as possible) to distribute the width ! * to. */ if (frp2->fr_win != NULL && frp2->fr_win->w_p_wfw) { frp = frp_close->fr_prev; --- 2841,2849 ---- } else { ! // When 'winfixwidth' is set, try to find another frame in the column ! // (as close to the closed frame as possible) to distribute the width ! // to. if (frp2->fr_win != NULL && frp2->fr_win->w_p_wfw) { frp = frp_close->fr_prev; *************** *** 2878,2885 **** *dirp = 'h'; } ! /* If rows/columns go to a window below/right its positions need to be ! * updated. Can only be done after the sizes have been updated. */ if (frp2 == frp_close->fr_next) { int row = win->w_winrow; --- 2877,2884 ---- *dirp = 'h'; } ! // If rows/columns go to a window below/right its positions need to be ! // updated. Can only be done after the sizes have been updated. if (frp2 == frp_close->fr_next) { int row = win->w_winrow; *************** *** 2890,2897 **** if (frp2->fr_next == NULL && frp2->fr_prev == NULL) { ! /* There is no other frame in this list, move its info to the parent ! * and remove it. */ frp2->fr_parent->fr_layout = frp2->fr_layout; frp2->fr_parent->fr_child = frp2->fr_child; FOR_ALL_FRAMES(frp, frp2->fr_child) --- 2889,2896 ---- if (frp2->fr_next == NULL && frp2->fr_prev == NULL) { ! // There is no other frame in this list, move its info to the parent ! // and remove it. frp2->fr_parent->fr_layout = frp2->fr_layout; frp2->fr_parent->fr_child = frp2->fr_child; FOR_ALL_FRAMES(frp, frp2->fr_child) *************** *** 2907,2914 **** frp2 = frp->fr_parent; if (frp2 != NULL && frp2->fr_layout == frp->fr_layout) { ! /* The frame above the parent has the same layout, have to merge ! * the frames into this list. */ if (frp2->fr_child == frp) frp2->fr_child = frp->fr_child; frp->fr_child->fr_prev = frp->fr_prev; --- 2906,2913 ---- frp2 = frp->fr_parent; if (frp2 != NULL && frp2->fr_layout == frp->fr_layout) { ! // The frame above the parent has the same layout, have to merge ! // the frames into this list. if (frp2->fr_child == frp) frp2->fr_child = frp->fr_child; frp->fr_child->fr_prev = frp->fr_prev; *************** *** 2947,2953 **** static frame_T * win_altframe( win_T *win, ! tabpage_T *tp) /* tab page "win" is in, NULL for current */ { frame_T *frp; frame_T *other_fr, *target_fr; --- 2946,2952 ---- static frame_T * win_altframe( win_T *win, ! tabpage_T *tp) // tab page "win" is in, NULL for current { frame_T *frp; frame_T *other_fr, *target_fr; *************** *** 2970,2977 **** other_fr = frp->fr_next; } ! /* If 'wfh' or 'wfw' is set for the target and not for the alternate ! * window, reverse the selection. */ if (frp->fr_parent != NULL && frp->fr_parent->fr_layout == FR_ROW) { if (frame_fixed_width(target_fr) && !frame_fixed_width(other_fr)) --- 2969,2976 ---- other_fr = frp->fr_next; } ! // If 'wfh' or 'wfw' is set for the target and not for the alternate ! // window, reverse the selection. if (frp->fr_parent != NULL && frp->fr_parent->fr_layout == FR_ROW) { if (frame_fixed_width(target_fr) && !frame_fixed_width(other_fr)) *************** *** 2994,3004 **** { tabpage_T *tp; ! /* Use the next tab page if possible. */ if (curtab->tp_next != NULL) return curtab->tp_next; ! /* Find the last but one tab page. */ for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next) ; return tp; --- 2993,3003 ---- { tabpage_T *tp; ! // Use the next tab page if possible. if (curtab->tp_next != NULL) return curtab->tp_next; ! // Find the last but one tab page. for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next) ; return tp; *************** *** 3040,3048 **** frame_new_height( frame_T *topfrp, int height, ! int topfirst, /* resize topmost contained frame first */ ! int wfh) /* obey 'winfixheight' when there is a choice; ! may cause the height not to be set */ { frame_T *frp; int extra_lines; --- 3039,3047 ---- frame_new_height( frame_T *topfrp, int height, ! int topfirst, // resize topmost contained frame first ! int wfh) // obey 'winfixheight' when there is a choice; ! // may cause the height not to be set { frame_T *frp; int extra_lines; *************** *** 3050,3056 **** if (topfrp->fr_win != NULL) { ! /* Simple case: just one window. */ win_new_height(topfrp->fr_win, height - topfrp->fr_win->w_status_height - WINBAR_HEIGHT(topfrp->fr_win)); --- 3049,3055 ---- if (topfrp->fr_win != NULL) { ! // Simple case: just one window. win_new_height(topfrp->fr_win, height - topfrp->fr_win->w_status_height - WINBAR_HEIGHT(topfrp->fr_win)); *************** *** 3059,3071 **** { do { ! /* All frames in this row get the same new height. */ FOR_ALL_FRAMES(frp, topfrp->fr_child) { frame_new_height(frp, height, topfirst, wfh); if (frp->fr_height > height) { ! /* Could not fit the windows, make the whole row higher. */ height = frp->fr_height; break; } --- 3058,3070 ---- { do { ! // All frames in this row get the same new height. FOR_ALL_FRAMES(frp, topfrp->fr_child) { frame_new_height(frp, height, topfirst, wfh); if (frp->fr_height > height) { ! // Could not fit the windows, make the whole row higher. height = frp->fr_height; break; } *************** *** 3073,3099 **** } while (frp != NULL); } ! else /* fr_layout == FR_COL */ { ! /* Complicated case: Resize a column of frames. Resize the bottom ! * frame first, frames above that when needed. */ frp = topfrp->fr_child; if (wfh) ! /* Advance past frames with one window with 'wfh' set. */ while (frame_fixed_height(frp)) { frp = frp->fr_next; if (frp == NULL) ! return; /* no frame without 'wfh', give up */ } if (!topfirst) { ! /* Find the bottom frame of this column */ while (frp->fr_next != NULL) frp = frp->fr_next; if (wfh) ! /* Advance back for frames with one window with 'wfh' set. */ while (frame_fixed_height(frp)) frp = frp->fr_prev; } --- 3072,3098 ---- } while (frp != NULL); } ! else // fr_layout == FR_COL { ! // Complicated case: Resize a column of frames. Resize the bottom ! // frame first, frames above that when needed. frp = topfrp->fr_child; if (wfh) ! // Advance past frames with one window with 'wfh' set. while (frame_fixed_height(frp)) { frp = frp->fr_next; if (frp == NULL) ! return; // no frame without 'wfh', give up } if (!topfirst) { ! // Find the bottom frame of this column while (frp->fr_next != NULL) frp = frp->fr_next; if (wfh) ! // Advance back for frames with one window with 'wfh' set. while (frame_fixed_height(frp)) frp = frp->fr_prev; } *************** *** 3101,3107 **** extra_lines = height - topfrp->fr_height; if (extra_lines < 0) { ! /* reduce height of contained frames, bottom or top frame first */ while (frp != NULL) { h = frame_minheight(frp, NULL); --- 3100,3106 ---- extra_lines = height - topfrp->fr_height; if (extra_lines < 0) { ! // reduce height of contained frames, bottom or top frame first while (frp != NULL) { h = frame_minheight(frp, NULL); *************** *** 3128,3141 **** frp = frp->fr_prev; while (wfh && frp != NULL && frame_fixed_height(frp)); } ! /* Increase "height" if we could not reduce enough frames. */ if (frp == NULL) height -= extra_lines; } } else if (extra_lines > 0) { ! /* increase height of bottom or top frame */ frame_new_height(frp, frp->fr_height + extra_lines, topfirst, wfh); } } --- 3127,3140 ---- frp = frp->fr_prev; while (wfh && frp != NULL && frame_fixed_height(frp)); } ! // Increase "height" if we could not reduce enough frames. if (frp == NULL) height -= extra_lines; } } else if (extra_lines > 0) { ! // increase height of bottom or top frame frame_new_height(frp, frp->fr_height + extra_lines, topfirst, wfh); } } *************** *** 3149,3170 **** static int frame_fixed_height(frame_T *frp) { ! /* frame with one window: fixed height if 'winfixheight' set. */ if (frp->fr_win != NULL) return frp->fr_win->w_p_wfh; if (frp->fr_layout == FR_ROW) { ! /* The frame is fixed height if one of the frames in the row is fixed ! * height. */ FOR_ALL_FRAMES(frp, frp->fr_child) if (frame_fixed_height(frp)) return TRUE; return FALSE; } ! /* frp->fr_layout == FR_COL: The frame is fixed height if all of the ! * frames in the row are fixed height. */ FOR_ALL_FRAMES(frp, frp->fr_child) if (!frame_fixed_height(frp)) return FALSE; --- 3148,3169 ---- static int frame_fixed_height(frame_T *frp) { ! // frame with one window: fixed height if 'winfixheight' set. if (frp->fr_win != NULL) return frp->fr_win->w_p_wfh; if (frp->fr_layout == FR_ROW) { ! // The frame is fixed height if one of the frames in the row is fixed ! // height. FOR_ALL_FRAMES(frp, frp->fr_child) if (frame_fixed_height(frp)) return TRUE; return FALSE; } ! // frp->fr_layout == FR_COL: The frame is fixed height if all of the ! // frames in the row are fixed height. FOR_ALL_FRAMES(frp, frp->fr_child) if (!frame_fixed_height(frp)) return FALSE; *************** *** 3178,3199 **** static int frame_fixed_width(frame_T *frp) { ! /* frame with one window: fixed width if 'winfixwidth' set. */ if (frp->fr_win != NULL) return frp->fr_win->w_p_wfw; if (frp->fr_layout == FR_COL) { ! /* The frame is fixed width if one of the frames in the row is fixed ! * width. */ FOR_ALL_FRAMES(frp, frp->fr_child) if (frame_fixed_width(frp)) return TRUE; return FALSE; } ! /* frp->fr_layout == FR_ROW: The frame is fixed width if all of the ! * frames in the row are fixed width. */ FOR_ALL_FRAMES(frp, frp->fr_child) if (!frame_fixed_width(frp)) return FALSE; --- 3177,3198 ---- static int frame_fixed_width(frame_T *frp) { ! // frame with one window: fixed width if 'winfixwidth' set. if (frp->fr_win != NULL) return frp->fr_win->w_p_wfw; if (frp->fr_layout == FR_COL) { ! // The frame is fixed width if one of the frames in the row is fixed ! // width. FOR_ALL_FRAMES(frp, frp->fr_child) if (frame_fixed_width(frp)) return TRUE; return FALSE; } ! // frp->fr_layout == FR_ROW: The frame is fixed width if all of the ! // frames in the row are fixed width. FOR_ALL_FRAMES(frp, frp->fr_child) if (!frame_fixed_width(frp)) return FALSE; *************** *** 3214,3233 **** wp = frp->fr_win; if (wp->w_status_height == 0) { ! if (wp->w_height > 0) /* don't make it negative */ --wp->w_height; wp->w_status_height = STATUS_HEIGHT; } } else if (frp->fr_layout == FR_ROW) { ! /* Handle all the frames in the row. */ FOR_ALL_FRAMES(frp, frp->fr_child) frame_add_statusline(frp); } ! else /* frp->fr_layout == FR_COL */ { ! /* Only need to handle the last frame in the column. */ for (frp = frp->fr_child; frp->fr_next != NULL; frp = frp->fr_next) ; frame_add_statusline(frp); --- 3213,3232 ---- wp = frp->fr_win; if (wp->w_status_height == 0) { ! if (wp->w_height > 0) // don't make it negative --wp->w_height; wp->w_status_height = STATUS_HEIGHT; } } else if (frp->fr_layout == FR_ROW) { ! // Handle all the frames in the row. FOR_ALL_FRAMES(frp, frp->fr_child) frame_add_statusline(frp); } ! else // frp->fr_layout == FR_COL { ! // Only need to handle the last frame in the column. for (frp = frp->fr_child; frp->fr_next != NULL; frp = frp->fr_next) ; frame_add_statusline(frp); *************** *** 3242,3250 **** frame_new_width( frame_T *topfrp, int width, ! int leftfirst, /* resize leftmost contained frame first */ ! int wfw) /* obey 'winfixwidth' when there is a choice; ! may cause the width not to be set */ { frame_T *frp; int extra_cols; --- 3241,3249 ---- frame_new_width( frame_T *topfrp, int width, ! int leftfirst, // resize leftmost contained frame first ! int wfw) // obey 'winfixwidth' when there is a choice; ! // may cause the width not to be set { frame_T *frp; int extra_cols; *************** *** 3253,3261 **** if (topfrp->fr_layout == FR_LEAF) { ! /* Simple case: just one window. */ wp = topfrp->fr_win; ! /* Find out if there are any windows right of this one. */ for (frp = topfrp; frp->fr_parent != NULL; frp = frp->fr_parent) if (frp->fr_parent->fr_layout == FR_ROW && frp->fr_next != NULL) break; --- 3252,3260 ---- if (topfrp->fr_layout == FR_LEAF) { ! // Simple case: just one window. wp = topfrp->fr_win; ! // Find out if there are any windows right of this one. for (frp = topfrp; frp->fr_parent != NULL; frp = frp->fr_parent) if (frp->fr_parent->fr_layout == FR_ROW && frp->fr_next != NULL) break; *************** *** 3267,3306 **** { do { ! /* All frames in this column get the same new width. */ FOR_ALL_FRAMES(frp, topfrp->fr_child) { frame_new_width(frp, width, leftfirst, wfw); if (frp->fr_width > width) { ! /* Could not fit the windows, make whole column wider. */ width = frp->fr_width; break; } } } while (frp != NULL); } ! else /* fr_layout == FR_ROW */ { ! /* Complicated case: Resize a row of frames. Resize the rightmost ! * frame first, frames left of it when needed. */ frp = topfrp->fr_child; if (wfw) ! /* Advance past frames with one window with 'wfw' set. */ while (frame_fixed_width(frp)) { frp = frp->fr_next; if (frp == NULL) ! return; /* no frame without 'wfw', give up */ } if (!leftfirst) { ! /* Find the rightmost frame of this row */ while (frp->fr_next != NULL) frp = frp->fr_next; if (wfw) ! /* Advance back for frames with one window with 'wfw' set. */ while (frame_fixed_width(frp)) frp = frp->fr_prev; } --- 3266,3305 ---- { do { ! // All frames in this column get the same new width. FOR_ALL_FRAMES(frp, topfrp->fr_child) { frame_new_width(frp, width, leftfirst, wfw); if (frp->fr_width > width) { ! // Could not fit the windows, make whole column wider. width = frp->fr_width; break; } } } while (frp != NULL); } ! else // fr_layout == FR_ROW { ! // Complicated case: Resize a row of frames. Resize the rightmost ! // frame first, frames left of it when needed. frp = topfrp->fr_child; if (wfw) ! // Advance past frames with one window with 'wfw' set. while (frame_fixed_width(frp)) { frp = frp->fr_next; if (frp == NULL) ! return; // no frame without 'wfw', give up } if (!leftfirst) { ! // Find the rightmost frame of this row while (frp->fr_next != NULL) frp = frp->fr_next; if (wfw) ! // Advance back for frames with one window with 'wfw' set. while (frame_fixed_width(frp)) frp = frp->fr_prev; } *************** *** 3308,3314 **** extra_cols = width - topfrp->fr_width; if (extra_cols < 0) { ! /* reduce frame width, rightmost frame first */ while (frp != NULL) { w = frame_minwidth(frp, NULL); --- 3307,3313 ---- extra_cols = width - topfrp->fr_width; if (extra_cols < 0) { ! // reduce frame width, rightmost frame first while (frp != NULL) { w = frame_minwidth(frp, NULL); *************** *** 3335,3348 **** frp = frp->fr_prev; while (wfw && frp != NULL && frame_fixed_width(frp)); } ! /* Increase "width" if we could not reduce enough frames. */ if (frp == NULL) width -= extra_cols; } } else if (extra_cols > 0) { ! /* increase width of rightmost frame */ frame_new_width(frp, frp->fr_width + extra_cols, leftfirst, wfw); } } --- 3334,3347 ---- frp = frp->fr_prev; while (wfw && frp != NULL && frame_fixed_width(frp)); } ! // Increase "width" if we could not reduce enough frames. if (frp == NULL) width -= extra_cols; } } else if (extra_cols > 0) { ! // increase width of rightmost frame frame_new_width(frp, frp->fr_width + extra_cols, leftfirst, wfw); } } *************** *** 3363,3382 **** wp = frp->fr_win; if (wp->w_vsep_width == 0) { ! if (wp->w_width > 0) /* don't make it negative */ --wp->w_width; wp->w_vsep_width = 1; } } else if (frp->fr_layout == FR_COL) { ! /* Handle all the frames in the column. */ FOR_ALL_FRAMES(frp, frp->fr_child) frame_add_vsep(frp); } ! else /* frp->fr_layout == FR_ROW */ { ! /* Only need to handle the last frame in the row. */ frp = frp->fr_child; while (frp->fr_next != NULL) frp = frp->fr_next; --- 3362,3381 ---- wp = frp->fr_win; if (wp->w_vsep_width == 0) { ! if (wp->w_width > 0) // don't make it negative --wp->w_width; wp->w_vsep_width = 1; } } else if (frp->fr_layout == FR_COL) { ! // Handle all the frames in the column. FOR_ALL_FRAMES(frp, frp->fr_child) frame_add_vsep(frp); } ! else // frp->fr_layout == FR_ROW { ! // Only need to handle the last frame in the row. frp = frp->fr_child; while (frp->fr_next != NULL) frp = frp->fr_next; *************** *** 3422,3433 **** m = p_wh + topfrp->fr_win->w_status_height; else { ! /* window: minimal height of the window plus status line */ m = p_wmh + topfrp->fr_win->w_status_height; if (topfrp->fr_win == curwin && next_curwin == NULL) { ! /* Current window is minimal one line high and WinBar is ! * visible. */ if (p_wmh == 0) ++m; m += WINBAR_HEIGHT(curwin); --- 3421,3432 ---- m = p_wh + topfrp->fr_win->w_status_height; else { ! // window: minimal height of the window plus status line m = p_wmh + topfrp->fr_win->w_status_height; if (topfrp->fr_win == curwin && next_curwin == NULL) { ! // Current window is minimal one line high and WinBar is ! // visible. if (p_wmh == 0) ++m; m += WINBAR_HEIGHT(curwin); *************** *** 3436,3442 **** } else if (topfrp->fr_layout == FR_ROW) { ! /* get the minimal height from each frame in this row */ m = 0; FOR_ALL_FRAMES(frp, topfrp->fr_child) { --- 3435,3441 ---- } else if (topfrp->fr_layout == FR_ROW) { ! // get the minimal height from each frame in this row m = 0; FOR_ALL_FRAMES(frp, topfrp->fr_child) { *************** *** 3447,3453 **** } else { ! /* Add up the minimal heights for all frames in this column. */ m = 0; FOR_ALL_FRAMES(frp, topfrp->fr_child) m += frame_minheight(frp, next_curwin); --- 3446,3452 ---- } else { ! // Add up the minimal heights for all frames in this column. m = 0; FOR_ALL_FRAMES(frp, topfrp->fr_child) m += frame_minheight(frp, next_curwin); *************** *** 3465,3471 **** static int frame_minwidth( frame_T *topfrp, ! win_T *next_curwin) /* use p_wh and p_wiw for next_curwin */ { frame_T *frp; int m, n; --- 3464,3470 ---- static int frame_minwidth( frame_T *topfrp, ! win_T *next_curwin) // use p_wh and p_wiw for next_curwin { frame_T *frp; int m, n; *************** *** 3476,3491 **** m = p_wiw + topfrp->fr_win->w_vsep_width; else { ! /* window: minimal width of the window plus separator column */ m = p_wmw + topfrp->fr_win->w_vsep_width; ! /* Current window is minimal one column wide */ if (p_wmw == 0 && topfrp->fr_win == curwin && next_curwin == NULL) ++m; } } else if (topfrp->fr_layout == FR_COL) { ! /* get the minimal width from each frame in this column */ m = 0; FOR_ALL_FRAMES(frp, topfrp->fr_child) { --- 3475,3490 ---- m = p_wiw + topfrp->fr_win->w_vsep_width; else { ! // window: minimal width of the window plus separator column m = p_wmw + topfrp->fr_win->w_vsep_width; ! // Current window is minimal one column wide if (p_wmw == 0 && topfrp->fr_win == curwin && next_curwin == NULL) ++m; } } else if (topfrp->fr_layout == FR_COL) { ! // get the minimal width from each frame in this column m = 0; FOR_ALL_FRAMES(frp, topfrp->fr_child) { *************** *** 3496,3502 **** } else { ! /* Add up the minimal widths for all frames in this row. */ m = 0; FOR_ALL_FRAMES(frp, topfrp->fr_child) m += frame_minwidth(frp, next_curwin); --- 3495,3501 ---- } else { ! // Add up the minimal widths for all frames in this row. m = 0; FOR_ALL_FRAMES(frp, topfrp->fr_child) m += frame_minwidth(frp, next_curwin); *************** *** 3516,3522 **** void close_others( int message, ! int forceit) /* always hide all other windows */ { win_T *wp; win_T *nextwp; --- 3515,3521 ---- void close_others( int message, ! int forceit) // always hide all other windows { win_T *wp; win_T *nextwp; *************** *** 3529,3544 **** return; } ! /* Be very careful here: autocommands may change the window layout. */ for (wp = firstwin; win_valid(wp); wp = nextwp) { nextwp = wp->w_next; ! if (wp != curwin) /* don't close current window */ { ! /* Check if it's allowed to abandon this window */ r = can_abandon(wp->w_buffer, forceit); ! if (!win_valid(wp)) /* autocommands messed wp up */ { nextwp = firstwin; continue; --- 3528,3543 ---- return; } ! // Be very careful here: autocommands may change the window layout. for (wp = firstwin; win_valid(wp); wp = nextwp) { nextwp = wp->w_next; ! if (wp != curwin) // don't close current window { ! // Check if it's allowed to abandon this window r = can_abandon(wp->w_buffer, forceit); ! if (!win_valid(wp)) // autocommands messed wp up { nextwp = firstwin; continue; *************** *** 3549,3555 **** if (message && (p_confirm || cmdmod.confirm) && p_write) { dialog_changed(wp->w_buffer, FALSE); ! if (!win_valid(wp)) /* autocommands messed wp up */ { nextwp = firstwin; continue; --- 3548,3554 ---- if (message && (p_confirm || cmdmod.confirm) && p_write) { dialog_changed(wp->w_buffer, FALSE); ! if (!win_valid(wp)) // autocommands messed wp up { nextwp = firstwin; continue; *************** *** 3576,3582 **** wp->w_cursor.lnum = 1; wp->w_curswant = wp->w_cursor.col = 0; wp->w_cursor.coladd = 0; ! wp->w_pcmark.lnum = 1; /* pcmark not cleared but set to line 1 */ wp->w_pcmark.col = 0; wp->w_prev_pcmark.lnum = 0; wp->w_prev_pcmark.col = 0; --- 3575,3581 ---- wp->w_cursor.lnum = 1; wp->w_curswant = wp->w_cursor.col = 0; wp->w_cursor.coladd = 0; ! wp->w_pcmark.lnum = 1; // pcmark not cleared but set to line 1 wp->w_pcmark.col = 0; wp->w_prev_pcmark.lnum = 0; wp->w_prev_pcmark.col = 0; *************** *** 3670,3677 **** curwin = win_alloc(NULL, FALSE); if (oldwin == NULL) { ! /* Very first window, need to create an empty buffer for it and ! * initialize from scratch. */ curbuf = buflist_new(NULL, NULL, 1L, BLN_LISTED); if (curwin == NULL || curbuf == NULL) return FAIL; --- 3669,3676 ---- curwin = win_alloc(NULL, FALSE); if (oldwin == NULL) { ! // Very first window, need to create an empty buffer for it and ! // initialize from scratch. curbuf = buflist_new(NULL, NULL, 1L, BLN_LISTED); if (curwin == NULL || curbuf == NULL) return FAIL; *************** *** 3679,3694 **** #ifdef FEAT_SYN_HL curwin->w_s = &(curbuf->b_s); #endif ! curbuf->b_nwindows = 1; /* there is one window */ curwin->w_alist = &global_alist; ! curwin_init(); /* init current window */ } else { ! /* First window in new tab page, initialize it from "oldwin". */ win_init(curwin, oldwin, 0); ! /* We don't want cursor- and scroll-binding in the first window. */ RESET_BINDING(curwin); } --- 3678,3693 ---- #ifdef FEAT_SYN_HL curwin->w_s = &(curbuf->b_s); #endif ! curbuf->b_nwindows = 1; // there is one window curwin->w_alist = &global_alist; ! curwin_init(); // init current window } else { ! // First window in new tab page, initialize it from "oldwin". win_init(curwin, oldwin, 0); ! // We don't want cursor- and scroll-binding in the first window. RESET_BINDING(curwin); } *************** *** 3748,3754 **** return NULL; # ifdef FEAT_EVAL ! /* init t: variables */ tp->tp_vars = dict_alloc(); if (tp->tp_vars == NULL) { --- 3747,3753 ---- return NULL; # ifdef FEAT_EVAL ! // init t: variables tp->tp_vars = dict_alloc(); if (tp->tp_vars == NULL) { *************** *** 3785,3791 **** for (idx = 0; idx < SNAP_COUNT; ++idx) clear_snapshot(tp, idx); #ifdef FEAT_EVAL ! vars_clear(&tp->tp_vars->dv_hashtab); /* free all t: variables */ hash_init(&tp->tp_vars->dv_hashtab); unref_var_dict(tp->tp_vars); #endif --- 3784,3790 ---- for (idx = 0; idx < SNAP_COUNT; ++idx) clear_snapshot(tp, idx); #ifdef FEAT_EVAL ! vars_clear(&tp->tp_vars->dv_hashtab); // free all t: variables hash_init(&tp->tp_vars->dv_hashtab); unref_var_dict(tp->tp_vars); #endif *************** *** 3821,3827 **** if (newtp == NULL) return FAIL; ! /* Remember the current windows in this Tab page. */ if (leave_tabpage(curbuf, TRUE) == FAIL) { vim_free(newtp); --- 3820,3826 ---- if (newtp == NULL) return FAIL; ! // Remember the current windows in this Tab page. if (leave_tabpage(curbuf, TRUE) == FAIL) { vim_free(newtp); *************** *** 3831,3843 **** newtp->tp_localdir = (tp->tp_localdir == NULL) ? NULL : vim_strsave(tp->tp_localdir); ! /* Create a new empty window. */ if (win_alloc_firstwin(tp->tp_curwin) == OK) { ! /* Make the new Tab page the new topframe. */ if (after == 1) { ! /* New tab page becomes the first one. */ newtp->tp_next = first_tabpage; first_tabpage = newtp; } --- 3830,3842 ---- newtp->tp_localdir = (tp->tp_localdir == NULL) ? NULL : vim_strsave(tp->tp_localdir); ! // Create a new empty window. if (win_alloc_firstwin(tp->tp_curwin) == OK) { ! // Make the new Tab page the new topframe. if (after == 1) { ! // New tab page becomes the first one. newtp->tp_next = first_tabpage; first_tabpage = newtp; } *************** *** 3845,3851 **** { if (after > 0) { ! /* Put new tab page before tab page "after". */ n = 2; for (tp = first_tabpage; tp->tp_next != NULL && n < after; tp = tp->tp_next) --- 3844,3850 ---- { if (after > 0) { ! // Put new tab page before tab page "after". n = 2; for (tp = first_tabpage; tp->tp_next != NULL && n < after; tp = tp->tp_next) *************** *** 3862,3869 **** last_status(FALSE); #if defined(FEAT_GUI) ! /* When 'guioptions' includes 'L' or 'R' may have to remove or add ! * scrollbars. Have to update them anyway. */ gui_may_update_scrollbars(); #endif #ifdef FEAT_JOB_CHANNEL --- 3861,3868 ---- last_status(FALSE); #if defined(FEAT_GUI) ! // When 'guioptions' includes 'L' or 'R' may have to remove or add ! // scrollbars. Have to update them anyway. gui_may_update_scrollbars(); #endif #ifdef FEAT_JOB_CHANNEL *************** *** 3878,3884 **** return OK; } ! /* Failed, get back the previous Tab page */ enter_tabpage(curtab, curbuf, TRUE, TRUE); return FAIL; } --- 3877,3883 ---- return OK; } ! // Failed, get back the previous Tab page enter_tabpage(curtab, curbuf, TRUE, TRUE); return FAIL; } *************** *** 3895,3901 **** if (n != 0) { ! cmdmod.tab = 0; /* reset it to avoid doing it twice */ postponed_split_tab = 0; return win_new_tabpage(n); } --- 3894,3900 ---- if (n != 0) { ! cmdmod.tab = 0; // reset it to avoid doing it twice postponed_split_tab = 0; return win_new_tabpage(n); } *************** *** 3912,3918 **** int count = maxcount; int todo; ! /* Limit to 'tabpagemax' tabs. */ if (count > p_tpm) count = p_tpm; --- 3911,3917 ---- int count = maxcount; int todo; ! // Limit to 'tabpagemax' tabs. if (count > p_tpm) count = p_tpm; *************** *** 3928,3934 **** unblock_autocmds(); ! /* return actual number of tab pages */ return (count - todo); } --- 3927,3933 ---- unblock_autocmds(); ! // return actual number of tab pages return (count - todo); } *************** *** 3968,3974 **** return FALSE; } } ! /* shouldn't happen */ return FALSE; } --- 3967,3973 ---- return FALSE; } } ! // shouldn't happen return FALSE; } *************** *** 4039,4046 **** */ static int leave_tabpage( ! buf_T *new_curbuf UNUSED, /* what is going to be the new curbuf, ! NULL if unknown */ int trigger_leave_autocmds UNUSED) { tabpage_T *tp = curtab; --- 4038,4045 ---- */ static int leave_tabpage( ! buf_T *new_curbuf UNUSED, // what is going to be the new curbuf, ! // NULL if unknown int trigger_leave_autocmds UNUSED) { tabpage_T *tp = curtab; *************** *** 4048,4054 **** #ifdef FEAT_JOB_CHANNEL leaving_window(curwin); #endif ! reset_VIsual_and_resel(); /* stop Visual mode */ if (trigger_leave_autocmds) { if (new_curbuf != curbuf) --- 4047,4053 ---- #ifdef FEAT_JOB_CHANNEL leaving_window(curwin); #endif ! reset_VIsual_and_resel(); // stop Visual mode if (trigger_leave_autocmds) { if (new_curbuf != curbuf) *************** *** 4065,4071 **** return FAIL; } #if defined(FEAT_GUI) ! /* Remove the scrollbars. They may be added back later. */ if (gui.in_use) gui_remove_scrollbars(); #endif --- 4064,4070 ---- return FAIL; } #if defined(FEAT_GUI) ! // Remove the scrollbars. They may be added back later. if (gui.in_use) gui_remove_scrollbars(); #endif *************** *** 4101,4123 **** lastwin = tp->tp_lastwin; topframe = tp->tp_topframe; ! /* We would like doing the TabEnter event first, but we don't have a ! * valid current window yet, which may break some commands. ! * This triggers autocommands, thus may make "tp" invalid. */ win_enter_ext(tp->tp_curwin, FALSE, TRUE, FALSE, trigger_enter_autocmds, trigger_leave_autocmds); prevwin = next_prevwin; ! last_status(FALSE); /* status line may appear or disappear */ ! (void)win_comp_pos(); /* recompute w_winrow for all windows */ #ifdef FEAT_DIFF diff_need_scrollbind = TRUE; #endif ! /* The tabpage line may have appeared or disappeared, may need to resize ! * the frames for that. When the Vim window was resized need to update ! * frame sizes too. Use the stored value of p_ch, so that it can be ! * different for each tab page. */ if (p_ch != curtab->tp_ch_used) clear_cmdline = TRUE; p_ch = curtab->tp_ch_used; --- 4100,4122 ---- lastwin = tp->tp_lastwin; topframe = tp->tp_topframe; ! // We would like doing the TabEnter event first, but we don't have a ! // valid current window yet, which may break some commands. ! // This triggers autocommands, thus may make "tp" invalid. win_enter_ext(tp->tp_curwin, FALSE, TRUE, FALSE, trigger_enter_autocmds, trigger_leave_autocmds); prevwin = next_prevwin; ! last_status(FALSE); // status line may appear or disappear ! (void)win_comp_pos(); // recompute w_winrow for all windows #ifdef FEAT_DIFF diff_need_scrollbind = TRUE; #endif ! // The tabpage line may have appeared or disappeared, may need to resize ! // the frames for that. When the Vim window was resized need to update ! // frame sizes too. Use the stored value of p_ch, so that it can be ! // different for each tab page. if (p_ch != curtab->tp_ch_used) clear_cmdline = TRUE; p_ch = curtab->tp_ch_used; *************** *** 4128,4143 **** )) shell_new_rows(); if (curtab->tp_old_Columns != Columns && starting == 0) ! shell_new_columns(); /* update window widths */ #if defined(FEAT_GUI) ! /* When 'guioptions' includes 'L' or 'R' may have to remove or add ! * scrollbars. Have to update them anyway. */ gui_may_update_scrollbars(); #endif ! /* Apply autocommands after updating the display, when 'rows' and ! * 'columns' have been set correctly. */ if (trigger_enter_autocmds) { apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); --- 4127,4142 ---- )) shell_new_rows(); if (curtab->tp_old_Columns != Columns && starting == 0) ! shell_new_columns(); // update window widths #if defined(FEAT_GUI) ! // When 'guioptions' includes 'L' or 'R' may have to remove or add ! // scrollbars. Have to update them anyway. gui_may_update_scrollbars(); #endif ! // Apply autocommands after updating the display, when 'rows' and ! // 'columns' have been set correctly. if (trigger_enter_autocmds) { apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf); *************** *** 4161,4172 **** if (text_locked()) { ! /* Not allowed when editing the command line. */ text_locked_msg(); return; } ! /* If there is only one it can't work. */ if (first_tabpage->tp_next == NULL) { if (n > 1) --- 4160,4171 ---- if (text_locked()) { ! // Not allowed when editing the command line. text_locked_msg(); return; } ! // If there is only one it can't work. if (first_tabpage->tp_next == NULL) { if (n > 1) *************** *** 4176,4182 **** if (n == 0) { ! /* No count, go to next tab page, wrap around end. */ if (curtab->tp_next == NULL) tp = first_tabpage; else --- 4175,4181 ---- if (n == 0) { ! // No count, go to next tab page, wrap around end. if (curtab->tp_next == NULL) tp = first_tabpage; else *************** *** 4184,4191 **** } else if (n < 0) { ! /* "gT": go to previous tab page, wrap around end. "N gT" repeats ! * this N times. */ ttp = curtab; for (i = n; i < 0; ++i) { --- 4183,4190 ---- } else if (n < 0) { ! // "gT": go to previous tab page, wrap around end. "N gT" repeats ! // this N times. ttp = curtab; for (i = n; i < 0; ++i) { *************** *** 4197,4209 **** } else if (n == 9999) { ! /* Go to last tab page. */ for (tp = first_tabpage; tp->tp_next != NULL; tp = tp->tp_next) ; } else { ! /* Go to tab page "n". */ tp = find_tabpage(n); if (tp == NULL) { --- 4196,4208 ---- } else if (n == 9999) { ! // Go to last tab page. for (tp = first_tabpage; tp->tp_next != NULL; tp = tp->tp_next) ; } else { ! // Go to tab page "n". tp = find_tabpage(n); if (tp == NULL) { *************** *** 4232,4238 **** int trigger_enter_autocmds, int trigger_leave_autocmds) { ! /* Don't repeat a message in another tab page. */ set_keep_msg(NULL, 0); if (tp != curtab && leave_tabpage(tp->tp_curwin->w_buffer, --- 4231,4237 ---- int trigger_enter_autocmds, int trigger_leave_autocmds) { ! // Don't repeat a message in another tab page. set_keep_msg(NULL, 0); if (tp != curtab && leave_tabpage(tp->tp_curwin->w_buffer, *************** *** 4286,4292 **** tp_dst = tp; ! /* Remove the current tab page from the list of tab pages. */ if (curtab == first_tabpage) first_tabpage = curtab->tp_next; else --- 4285,4291 ---- tp_dst = tp; ! // Remove the current tab page from the list of tab pages. if (curtab == first_tabpage) first_tabpage = curtab->tp_next; else *************** *** 4294,4305 **** FOR_ALL_TABPAGES(tp) if (tp->tp_next == curtab) break; ! if (tp == NULL) /* "cannot happen" */ return; tp->tp_next = curtab->tp_next; } ! /* Re-insert it at the specified position. */ if (nr <= 0) { curtab->tp_next = first_tabpage; --- 4293,4304 ---- FOR_ALL_TABPAGES(tp) if (tp->tp_next == curtab) break; ! if (tp == NULL) // "cannot happen" return; tp->tp_next = curtab->tp_next; } ! // Re-insert it at the specified position. if (nr <= 0) { curtab->tp_next = first_tabpage; *************** *** 4311,4317 **** tp_dst->tp_next = curtab; } ! /* Need to redraw the tabline. Tab page contents doesn't change. */ redraw_tabline = TRUE; } --- 4310,4316 ---- tp_dst->tp_next = curtab; } ! // Need to redraw the tabline. Tab page contents doesn't change. redraw_tabline = TRUE; } *************** *** 4440,4446 **** fr = nfr->fr_child; if (nfr->fr_layout == FR_ROW) { ! /* Find the frame at the cursor row. */ while (fr->fr_next != NULL && frame2win(fr)->w_wincol + fr->fr_width <= wp->w_wincol + wp->w_wcol) --- 4439,4445 ---- fr = nfr->fr_child; if (nfr->fr_layout == FR_ROW) { ! // Find the frame at the cursor row. while (fr->fr_next != NULL && frame2win(fr)->w_wincol + fr->fr_width <= wp->w_wincol + wp->w_wcol) *************** *** 4518,4524 **** fr = nfr->fr_child; if (nfr->fr_layout == FR_COL) { ! /* Find the frame at the cursor row. */ while (fr->fr_next != NULL && frame2win(fr)->w_winrow + fr->fr_height <= wp->w_winrow + wp->w_wrow) --- 4517,4523 ---- fr = nfr->fr_child; if (nfr->fr_layout == FR_COL) { ! // Find the frame at the cursor row. while (fr->fr_next != NULL && frame2win(fr)->w_winrow + fr->fr_height <= wp->w_winrow + wp->w_wrow) *************** *** 4574,4580 **** { int other_buffer = FALSE; ! if (wp == curwin && !curwin_invalid) /* nothing to do */ return; #ifdef FEAT_JOB_CHANNEL --- 4573,4579 ---- { int other_buffer = FALSE; ! if (wp == curwin && !curwin_invalid) // nothing to do return; #ifdef FEAT_JOB_CHANNEL *************** *** 4598,4623 **** if (!win_valid(wp)) return; #ifdef FEAT_EVAL ! /* autocmds may abort script processing */ if (aborting()) return; #endif } ! /* sync undo before leaving the current buffer */ if (undo_sync && curbuf != wp->w_buffer) u_sync(FALSE); ! /* Might need to scroll the old window before switching, e.g., when the ! * cursor was moved. */ update_topline(); ! /* may have to copy the buffer options when 'cpo' contains 'S' */ if (wp->w_buffer != curbuf) buf_copy_options(wp->w_buffer, BCO_ENTER | BCO_NOHELP); if (!curwin_invalid) { ! prevwin = curwin; /* remember for CTRL-W p */ curwin->w_redr_status = TRUE; } curwin = wp; --- 4597,4622 ---- if (!win_valid(wp)) return; #ifdef FEAT_EVAL ! // autocmds may abort script processing if (aborting()) return; #endif } ! // sync undo before leaving the current buffer if (undo_sync && curbuf != wp->w_buffer) u_sync(FALSE); ! // Might need to scroll the old window before switching, e.g., when the ! // cursor was moved. update_topline(); ! // may have to copy the buffer options when 'cpo' contains 'S' if (wp->w_buffer != curbuf) buf_copy_options(wp->w_buffer, BCO_ENTER | BCO_NOHELP); if (!curwin_invalid) { ! prevwin = curwin; // remember for CTRL-W p curwin->w_redr_status = TRUE; } curwin = wp; *************** *** 4625,4631 **** check_cursor(); if (!virtual_active()) curwin->w_cursor.coladd = 0; ! changed_line_abv_curs(); /* assume cursor position needs updating */ if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL) { --- 4624,4630 ---- check_cursor(); if (!virtual_active()) curwin->w_cursor.coladd = 0; ! changed_line_abv_curs(); // assume cursor position needs updating if (curwin->w_localdir != NULL || curtab->tp_localdir != NULL) { *************** *** 4651,4658 **** } else if (globaldir != NULL) { ! /* Window doesn't have a local directory and we are not in the global ! * directory: Change to the global directory. */ vim_ignored = mch_chdir((char *)globaldir); VIM_CLEAR(globaldir); shorten_fnames(TRUE); --- 4650,4657 ---- } else if (globaldir != NULL) { ! // Window doesn't have a local directory and we are not in the global ! // directory: Change to the global directory. vim_ignored = mch_chdir((char *)globaldir); VIM_CLEAR(globaldir); shorten_fnames(TRUE); *************** *** 4682,4690 **** #endif redraw_tabline = TRUE; if (restart_edit) ! redraw_later(VALID); /* causes status line redraw */ ! /* set window height to desired minimal value */ if (curwin->w_height < p_wh && !curwin->w_p_wfh #ifdef FEAT_PROP_POPUP && !popup_is_popup(curwin) --- 4681,4689 ---- #endif redraw_tabline = TRUE; if (restart_edit) ! redraw_later(VALID); // causes status line redraw ! // set window height to desired minimal value if (curwin->w_height < p_wh && !curwin->w_p_wfh #ifdef FEAT_PROP_POPUP && !popup_is_popup(curwin) *************** *** 4694,4706 **** else if (curwin->w_height == 0) win_setheight(1); ! /* set window width to desired minimal value */ if (curwin->w_width < p_wiw && !curwin->w_p_wfw) win_setwidth((int)p_wiw); setmouse(); // in case jumped to/from help buffer ! /* Change directories when the 'acd' option is set. */ DO_AUTOCHDIR; } --- 4693,4705 ---- else if (curwin->w_height == 0) win_setheight(1); ! // set window width to desired minimal value if (curwin->w_width < p_wiw && !curwin->w_p_wfw) win_setwidth((int)p_wiw); setmouse(); // in case jumped to/from help buffer ! // Change directories when the 'acd' option is set. DO_AUTOCHDIR; } *************** *** 4749,4755 **** { goto_tabpage_win(tp, wp); if (curwin != wp) ! wp = NULL; /* something went wrong */ break; } } --- 4748,4754 ---- { goto_tabpage_win(tp, wp); if (curwin != wp) ! wp = NULL; // something went wrong break; } } *************** *** 4783,4789 **** new_wp->w_id = ++last_win_id; #ifdef FEAT_EVAL ! /* init w: variables */ new_wp->w_vars = dict_alloc(); if (new_wp->w_vars == NULL) { --- 4782,4788 ---- new_wp->w_id = ++last_win_id; #ifdef FEAT_EVAL ! // init w: variables new_wp->w_vars = dict_alloc(); if (new_wp->w_vars == NULL) { *************** *** 4794,4802 **** init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE); #endif ! /* Don't execute autocommands while the window is not properly ! * initialized yet. gui_create_scrollbar() may trigger a FocusGained ! * event. */ block_autocmds(); /* --- 4793,4801 ---- init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE); #endif ! // Don't execute autocommands while the window is not properly ! // initialized yet. gui_create_scrollbar() may trigger a FocusGained ! // event. block_autocmds(); /* *************** *** 4807,4813 **** new_wp->w_wincol = 0; new_wp->w_width = Columns; ! /* position the display and the cursor at the top of the file. */ new_wp->w_topline = 1; #ifdef FEAT_DIFF new_wp->w_topfill = 0; --- 4806,4812 ---- new_wp->w_wincol = 0; new_wp->w_width = Columns; ! // position the display and the cursor at the top of the file. new_wp->w_topline = 1; #ifdef FEAT_DIFF new_wp->w_topfill = 0; *************** *** 4820,4826 **** new_wp->w_p_so = -1; new_wp->w_p_siso = -1; ! /* We won't calculate w_fraction until resizing the window */ new_wp->w_fraction = 0; new_wp->w_prev_fraction_row = -1; --- 4819,4825 ---- new_wp->w_p_so = -1; new_wp->w_p_siso = -1; ! // We won't calculate w_fraction until resizing the window new_wp->w_fraction = 0; new_wp->w_prev_fraction_row = -1; *************** *** 4850,4856 **** static void win_free( win_T *wp, ! tabpage_T *tp) /* tab page "win" is in, NULL for current */ { int i; buf_T *buf; --- 4849,4855 ---- static void win_free( win_T *wp, ! tabpage_T *tp) // tab page "win" is in, NULL for current { int i; buf_T *buf; *************** *** 4860,4870 **** clearFolding(wp); #endif ! /* reduce the reference count to the argument list. */ alist_unlink(wp->w_alist); ! /* Don't execute autocommands while the window is halfway being deleted. ! * gui_mch_destroy_scrollbar() may trigger a FocusGained event. */ block_autocmds(); #ifdef FEAT_LUA --- 4859,4869 ---- clearFolding(wp); #endif ! // reduce the reference count to the argument list. alist_unlink(wp->w_alist); ! // Don't execute autocommands while the window is halfway being deleted. ! // gui_mch_destroy_scrollbar() may trigger a FocusGained event. block_autocmds(); #ifdef FEAT_LUA *************** *** 4899,4905 **** clear_winopt(&wp->w_allbuf_opt); #ifdef FEAT_EVAL ! vars_clear(&wp->w_vars->dv_hashtab); /* free all w: variables */ hash_init(&wp->w_vars->dv_hashtab); unref_var_dict(wp->w_vars); #endif --- 4898,4904 ---- clear_winopt(&wp->w_allbuf_opt); #ifdef FEAT_EVAL ! vars_clear(&wp->w_vars->dv_hashtab); // free all w: variables hash_init(&wp->w_vars->dv_hashtab); unref_var_dict(wp->w_vars); #endif *************** *** 4922,4929 **** } vim_free(wp->w_localdir); ! /* Remove the window from the b_wininfo lists, it may happen that the ! * freed memory is re-used for another window. */ FOR_ALL_BUFFERS(buf) for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) if (wip->wi_win == wp) --- 4921,4928 ---- } vim_free(wp->w_localdir); ! // Remove the window from the b_wininfo lists, it may happen that the ! // freed memory is re-used for another window. FOR_ALL_BUFFERS(buf) for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) if (wip->wi_win == wp) *************** *** 4947,4953 **** gui_mch_destroy_scrollbar(&wp->w_scrollbars[SBAR_LEFT]); gui_mch_destroy_scrollbar(&wp->w_scrollbars[SBAR_RIGHT]); } ! #endif /* FEAT_GUI */ #ifdef FEAT_MENU remove_winbar(wp); --- 4946,4952 ---- gui_mch_destroy_scrollbar(&wp->w_scrollbars[SBAR_LEFT]); gui_mch_destroy_scrollbar(&wp->w_scrollbars[SBAR_RIGHT]); } ! #endif // FEAT_GUI #ifdef FEAT_MENU remove_winbar(wp); *************** *** 5020,5026 **** { win_T *before; ! if (after == NULL) /* after NULL is in front of the first */ before = firstwin; else before = after->w_next; --- 5019,5025 ---- { win_T *before; ! if (after == NULL) // after NULL is in front of the first before = firstwin; else before = after->w_next; *************** *** 5043,5049 **** void win_remove( win_T *wp, ! tabpage_T *tp) /* tab page "win" is in, NULL for current */ { if (wp->w_prev != NULL) wp->w_prev->w_next = wp->w_next; --- 5042,5048 ---- void win_remove( win_T *wp, ! tabpage_T *tp) // tab page "win" is in, NULL for current { if (wp->w_prev != NULL) wp->w_prev->w_next = wp->w_next; *************** *** 5099,5105 **** else { frp->fr_parent->fr_child = frp->fr_next; ! /* special case: topframe->fr_child == frp */ if (topframe->fr_child == frp) topframe->fr_child = frp->fr_next; } --- 5098,5104 ---- else { frp->fr_parent->fr_child = frp->fr_next; ! // special case: topframe->fr_child == frp if (topframe->fr_child == frp) topframe->fr_child = frp->fr_next; } *************** *** 5127,5133 **** void win_free_lsize(win_T *wp) { ! /* TODO: why would wp be NULL here? */ if (wp != NULL) VIM_CLEAR(wp->w_lines); } --- 5126,5132 ---- void win_free_lsize(win_T *wp) { ! // TODO: why would wp be NULL here? if (wp != NULL) VIM_CLEAR(wp->w_lines); } *************** *** 5141,5163 **** { int h = (int)ROWS_AVAIL; ! if (firstwin == NULL) /* not initialized yet */ return; if (h < frame_minheight(topframe, NULL)) h = frame_minheight(topframe, NULL); ! /* First try setting the heights of windows with 'winfixheight'. If ! * that doesn't result in the right height, forget about that option. */ frame_new_height(topframe, h, FALSE, TRUE); if (!frame_check_height(topframe, h)) frame_new_height(topframe, h, FALSE, FALSE); ! (void)win_comp_pos(); /* recompute w_winrow and w_wincol */ compute_cmdrow(); curtab->tp_ch_used = p_ch; #if 0 ! /* Disabled: don't want making the screen smaller make a window larger. */ if (p_ea) win_equal(curwin, FALSE, 'v'); #endif --- 5140,5162 ---- { int h = (int)ROWS_AVAIL; ! if (firstwin == NULL) // not initialized yet return; if (h < frame_minheight(topframe, NULL)) h = frame_minheight(topframe, NULL); ! // First try setting the heights of windows with 'winfixheight'. If ! // that doesn't result in the right height, forget about that option. frame_new_height(topframe, h, FALSE, TRUE); if (!frame_check_height(topframe, h)) frame_new_height(topframe, h, FALSE, FALSE); ! (void)win_comp_pos(); // recompute w_winrow and w_wincol compute_cmdrow(); curtab->tp_ch_used = p_ch; #if 0 ! // Disabled: don't want making the screen smaller make a window larger. if (p_ea) win_equal(curwin, FALSE, 'v'); #endif *************** *** 5169,5186 **** void shell_new_columns(void) { ! if (firstwin == NULL) /* not initialized yet */ return; ! /* First try setting the widths of windows with 'winfixwidth'. If that ! * doesn't result in the right width, forget about that option. */ frame_new_width(topframe, (int)Columns, FALSE, TRUE); if (!frame_check_width(topframe, Columns)) frame_new_width(topframe, (int)Columns, FALSE, FALSE); ! (void)win_comp_pos(); /* recompute w_winrow and w_wincol */ #if 0 ! /* Disabled: don't want making the screen smaller make a window larger. */ if (p_ea) win_equal(curwin, FALSE, 'h'); #endif --- 5168,5185 ---- void shell_new_columns(void) { ! if (firstwin == NULL) // not initialized yet return; ! // First try setting the widths of windows with 'winfixwidth'. If that ! // doesn't result in the right width, forget about that option. frame_new_width(topframe, (int)Columns, FALSE, TRUE); if (!frame_check_width(topframe, Columns)) frame_new_width(topframe, (int)Columns, FALSE, FALSE); ! (void)win_comp_pos(); // recompute w_winrow and w_wincol #if 0 ! // Disabled: don't want making the screen smaller make a window larger. if (p_ea) win_equal(curwin, FALSE, 'h'); #endif *************** *** 5225,5232 **** if (win_count() * 2 + 1 == gap->ga_len && ((int *)gap->ga_data)[0] == Rows) { ! /* The order matters, because frames contain other frames, but it's ! * difficult to get right. The easy way out is to do it twice. */ for (j = 0; j < 2; ++j) { i = 1; --- 5224,5231 ---- if (win_count() * 2 + 1 == gap->ga_len && ((int *)gap->ga_data)[0] == Rows) { ! // The order matters, because frames contain other frames, but it's ! // difficult to get right. The easy way out is to do it twice. for (j = 0; j < 2; ++j) { i = 1; *************** *** 5236,5246 **** win_setheight_win(((int *)gap->ga_data)[i++], wp); } } ! /* recompute the window positions */ (void)win_comp_pos(); } } ! #endif /* FEAT_CMDWIN */ /* * Update the position for all windows, using the width and height of the --- 5235,5245 ---- win_setheight_win(((int *)gap->ga_data)[i++], wp); } } ! // recompute the window positions (void)win_comp_pos(); } } ! #endif // FEAT_CMDWIN /* * Update the position for all windows, using the width and height of the *************** *** 5277,5289 **** { if (wp->w_winrow != *row || wp->w_wincol != *col) { ! /* position changed, redraw */ wp->w_winrow = *row; wp->w_wincol = *col; redraw_win_later(wp, NOT_VALID); wp->w_redr_status = TRUE; } ! /* WinBar will not show if the window height is zero */ h = VISIBLE_HEIGHT(wp) + wp->w_status_height; *row += h > topfrp->fr_height ? topfrp->fr_height : h; *col += wp->w_width + wp->w_vsep_width; --- 5276,5288 ---- { if (wp->w_winrow != *row || wp->w_wincol != *col) { ! // position changed, redraw wp->w_winrow = *row; wp->w_wincol = *col; redraw_win_later(wp, NOT_VALID); wp->w_redr_status = TRUE; } ! // WinBar will not show if the window height is zero h = VISIBLE_HEIGHT(wp) + wp->w_status_height; *row += h > topfrp->fr_height ? topfrp->fr_height : h; *col += wp->w_width + wp->w_vsep_width; *************** *** 5295,5303 **** FOR_ALL_FRAMES(frp, topfrp->fr_child) { if (topfrp->fr_layout == FR_ROW) ! *row = startrow; /* all frames are at the same row */ else ! *col = startcol; /* all frames are at the same col */ frame_comp_pos(frp, row, col); } } --- 5294,5302 ---- FOR_ALL_FRAMES(frp, topfrp->fr_child) { if (topfrp->fr_layout == FR_ROW) ! *row = startrow; // all frames are at the same row else ! *col = startcol; // all frames are at the same col frame_comp_pos(frp, row, col); } } *************** *** 5324,5331 **** if (win == curwin) { ! /* Always keep current window at least one line high, even when ! * 'winminheight' is zero. */ if (height < p_wmh) height = p_wmh; if (height == 0) --- 5323,5330 ---- if (win == curwin) { ! // Always keep current window at least one line high, even when ! // 'winminheight' is zero. if (height < p_wmh) height = p_wmh; if (height == 0) *************** *** 5335,5341 **** frame_setheight(win->w_frame, height + win->w_status_height); ! /* recompute the window positions */ row = win_comp_pos(); /* --- 5334,5340 ---- frame_setheight(win->w_frame, height + win->w_status_height); ! // recompute the window positions row = win_comp_pos(); /* *************** *** 5367,5387 **** static void frame_setheight(frame_T *curfrp, int height) { ! int room; /* total number of lines available */ ! int take; /* number of lines taken from other windows */ ! int room_cmdline; /* lines available from cmdline */ int run; frame_T *frp; int h; int room_reserved; ! /* If the height already is the desired value, nothing to do. */ if (curfrp->fr_height == height) return; if (curfrp->fr_parent == NULL) { ! /* topframe: can only change the command line */ if (height > ROWS_AVAIL) height = ROWS_AVAIL; if (height > 0) --- 5366,5386 ---- static void frame_setheight(frame_T *curfrp, int height) { ! int room; // total number of lines available ! int take; // number of lines taken from other windows ! int room_cmdline; // lines available from cmdline int run; frame_T *frp; int h; int room_reserved; ! // If the height already is the desired value, nothing to do. if (curfrp->fr_height == height) return; if (curfrp->fr_parent == NULL) { ! // topframe: can only change the command line if (height > ROWS_AVAIL) height = ROWS_AVAIL; if (height > 0) *************** *** 5389,5396 **** } else if (curfrp->fr_parent->fr_layout == FR_ROW) { ! /* Row of frames: Also need to resize frames left and right of this ! * one. First check for the minimal height of these. */ h = frame_minheight(curfrp->fr_parent, NULL); if (height < h) height = h; --- 5388,5395 ---- } else if (curfrp->fr_parent->fr_layout == FR_ROW) { ! // Row of frames: Also need to resize frames left and right of this ! // one. First check for the minimal height of these. h = frame_minheight(curfrp->fr_parent, NULL); if (height < h) height = h; *************** *** 5451,5468 **** */ take = height - curfrp->fr_height; ! /* If there is not enough room, also reduce the height of a window ! * with 'winfixheight' set. */ if (height > room + room_cmdline - room_reserved) room_reserved = room + room_cmdline - height; ! /* If there is only a 'winfixheight' window and making the ! * window smaller, need to make the other window taller. */ if (take < 0 && room - curfrp->fr_height < room_reserved) room_reserved = 0; if (take > 0 && room_cmdline > 0) { ! /* use lines from cmdline first */ if (take < room_cmdline) room_cmdline = take; take -= room_cmdline; --- 5450,5467 ---- */ take = height - curfrp->fr_height; ! // If there is not enough room, also reduce the height of a window ! // with 'winfixheight' set. if (height > room + room_cmdline - room_reserved) room_reserved = room + room_cmdline - height; ! // If there is only a 'winfixheight' window and making the ! // window smaller, need to make the other window taller. if (take < 0 && room - curfrp->fr_height < room_reserved) room_reserved = 0; if (take > 0 && room_cmdline > 0) { ! // use lines from cmdline first if (take < room_cmdline) room_cmdline = take; take -= room_cmdline; *************** *** 5482,5490 **** for (run = 0; run < 2; ++run) { if (run == 0) ! frp = curfrp->fr_next; /* 1st run: start with next window */ else ! frp = curfrp->fr_prev; /* 2nd run: start with prev window */ while (frp != NULL && take != 0) { h = frame_minheight(frp, NULL); --- 5481,5489 ---- for (run = 0; run < 2; ++run) { if (run == 0) ! frp = curfrp->fr_next; // 1st run: start with next window else ! frp = curfrp->fr_prev; // 2nd run: start with prev window while (frp != NULL && take != 0) { h = frame_minheight(frp, NULL); *************** *** 5539,5546 **** void win_setwidth_win(int width, win_T *wp) { ! /* Always keep current window at least one column wide, even when ! * 'winminwidth' is zero. */ if (wp == curwin) { if (width < p_wmw) --- 5538,5545 ---- void win_setwidth_win(int width, win_T *wp) { ! // Always keep current window at least one column wide, even when ! // 'winminwidth' is zero. if (wp == curwin) { if (width < p_wmw) *************** *** 5551,5557 **** frame_setwidth(wp->w_frame, width + wp->w_vsep_width); ! /* recompute the window positions */ (void)win_comp_pos(); redraw_all_later(NOT_VALID); --- 5550,5556 ---- frame_setwidth(wp->w_frame, width + wp->w_vsep_width); ! // recompute the window positions (void)win_comp_pos(); redraw_all_later(NOT_VALID); *************** *** 5567,5591 **** static void frame_setwidth(frame_T *curfrp, int width) { ! int room; /* total number of lines available */ ! int take; /* number of lines taken from other windows */ int run; frame_T *frp; int w; int room_reserved; ! /* If the width already is the desired value, nothing to do. */ if (curfrp->fr_width == width) return; if (curfrp->fr_parent == NULL) ! /* topframe: can't change width */ return; if (curfrp->fr_parent->fr_layout == FR_COL) { ! /* Column of frames: Also need to resize frames above and below of ! * this one. First check for the minimal width of these. */ w = frame_minwidth(curfrp->fr_parent, NULL); if (width < w) width = w; --- 5566,5590 ---- static void frame_setwidth(frame_T *curfrp, int width) { ! int room; // total number of lines available ! int take; // number of lines taken from other windows int run; frame_T *frp; int w; int room_reserved; ! // If the width already is the desired value, nothing to do. if (curfrp->fr_width == width) return; if (curfrp->fr_parent == NULL) ! // topframe: can't change width return; if (curfrp->fr_parent->fr_layout == FR_COL) { ! // Column of frames: Also need to resize frames above and below of ! // this one. First check for the minimal width of these. w = frame_minwidth(curfrp->fr_parent, NULL); if (width < w) width = w; *************** *** 5634,5645 **** */ take = width - curfrp->fr_width; ! /* If there is not enough room, also reduce the width of a window ! * with 'winfixwidth' set. */ if (width > room - room_reserved) room_reserved = room - width; ! /* If there is only a 'winfixwidth' window and making the ! * window smaller, need to make the other window narrower. */ if (take < 0 && room - curfrp->fr_width < room_reserved) room_reserved = 0; --- 5633,5644 ---- */ take = width - curfrp->fr_width; ! // If there is not enough room, also reduce the width of a window ! // with 'winfixwidth' set. if (width > room - room_reserved) room_reserved = room - width; ! // If there is only a 'winfixwidth' window and making the ! // window smaller, need to make the other window narrower. if (take < 0 && room - curfrp->fr_width < room_reserved) room_reserved = 0; *************** *** 5656,5664 **** for (run = 0; run < 2; ++run) { if (run == 0) ! frp = curfrp->fr_next; /* 1st run: start with next window */ else ! frp = curfrp->fr_prev; /* 2nd run: start with prev window */ while (frp != NULL && take != 0) { w = frame_minwidth(frp, NULL); --- 5655,5663 ---- for (run = 0; run < 2; ++run) { if (run == 0) ! frp = curfrp->fr_next; // 1st run: start with next window else ! frp = curfrp->fr_prev; // 2nd run: start with prev window while (frp != NULL && take != 0) { w = frame_minwidth(frp, NULL); *************** *** 5762,5787 **** frame_T *fr; int room; int row; ! int up; /* if TRUE, drag status line up, otherwise down */ int n; fr = dragwin->w_frame; curfr = fr; ! if (fr != topframe) /* more than one window */ { fr = fr->fr_parent; ! /* When the parent frame is not a column of frames, its parent should ! * be. */ if (fr->fr_layout != FR_COL) { curfr = fr; ! if (fr != topframe) /* only a row of windows, may drag statusline */ fr = fr->fr_parent; } } ! /* If this is the last frame in a column, may want to resize the parent ! * frame instead (go two up to skip a row of frames). */ while (curfr != topframe && curfr->fr_next == NULL) { if (fr != topframe) --- 5761,5786 ---- frame_T *fr; int room; int row; ! int up; // if TRUE, drag status line up, otherwise down int n; fr = dragwin->w_frame; curfr = fr; ! if (fr != topframe) // more than one window { fr = fr->fr_parent; ! // When the parent frame is not a column of frames, its parent should ! // be. if (fr->fr_layout != FR_COL) { curfr = fr; ! if (fr != topframe) // only a row of windows, may drag statusline fr = fr->fr_parent; } } ! // If this is the last frame in a column, may want to resize the parent ! // frame instead (go two up to skip a row of frames). while (curfr != topframe && curfr->fr_next == NULL) { if (fr != topframe) *************** *** 5791,5804 **** fr = fr->fr_parent; } ! if (offset < 0) /* drag up */ { up = TRUE; offset = -offset; ! /* sum up the room of the current frame and above it */ if (fr == curfr) { ! /* only one window */ room = fr->fr_height - frame_minheight(fr, NULL); } else --- 5790,5803 ---- fr = fr->fr_parent; } ! if (offset < 0) // drag up { up = TRUE; offset = -offset; ! // sum up the room of the current frame and above it if (fr == curfr) { ! // only one window room = fr->fr_height - frame_minheight(fr, NULL); } else *************** *** 5811,5819 **** break; } } ! fr = curfr->fr_next; /* put fr at frame that grows */ } ! else /* drag down */ { up = FALSE; /* --- 5810,5818 ---- break; } } ! fr = curfr->fr_next; // put fr at frame that grows } ! else // drag down { up = FALSE; /* *************** *** 5826,5839 **** room -= p_ch; if (room < 0) room = 0; ! /* sum up the room of frames below of the current one */ FOR_ALL_FRAMES(fr, curfr->fr_next) room += fr->fr_height - frame_minheight(fr, NULL); ! fr = curfr; /* put fr at window that grows */ } ! if (room < offset) /* Not enough room */ ! offset = room; /* Move as far as we can */ if (offset <= 0) return; --- 5825,5838 ---- room -= p_ch; if (room < 0) room = 0; ! // sum up the room of frames below of the current one FOR_ALL_FRAMES(fr, curfr->fr_next) room += fr->fr_height - frame_minheight(fr, NULL); ! fr = curfr; // put fr at window that grows } ! if (room < offset) // Not enough room ! offset = room; // Move as far as we can if (offset <= 0) return; *************** *** 5845,5853 **** frame_new_height(fr, fr->fr_height + offset, up, FALSE); if (up) ! fr = curfr; /* current frame gets smaller */ else ! fr = curfr->fr_next; /* next frame gets smaller */ /* * Now make the other frames smaller. --- 5844,5852 ---- frame_new_height(fr, fr->fr_height + offset, up, FALSE); if (up) ! fr = curfr; // current frame gets smaller else ! fr = curfr->fr_next; // next frame gets smaller /* * Now make the other frames smaller. *************** *** 5890,5914 **** frame_T *curfr; frame_T *fr; int room; ! int left; /* if TRUE, drag separator line left, otherwise right */ int n; fr = dragwin->w_frame; ! if (fr == topframe) /* only one window (cannot happen?) */ return; curfr = fr; fr = fr->fr_parent; ! /* When the parent frame is not a row of frames, its parent should be. */ if (fr->fr_layout != FR_ROW) { ! if (fr == topframe) /* only a column of windows (cannot happen?) */ return; curfr = fr; fr = fr->fr_parent; } ! /* If this is the last frame in a row, may want to resize a parent ! * frame instead. */ while (curfr->fr_next == NULL) { if (fr == topframe) --- 5889,5913 ---- frame_T *curfr; frame_T *fr; int room; ! int left; // if TRUE, drag separator line left, otherwise right int n; fr = dragwin->w_frame; ! if (fr == topframe) // only one window (cannot happen?) return; curfr = fr; fr = fr->fr_parent; ! // When the parent frame is not a row of frames, its parent should be. if (fr->fr_layout != FR_ROW) { ! if (fr == topframe) // only a column of windows (cannot happen?) return; curfr = fr; fr = fr->fr_parent; } ! // If this is the last frame in a row, may want to resize a parent ! // frame instead. while (curfr->fr_next == NULL) { if (fr == topframe) *************** *** 5922,5932 **** } } ! if (offset < 0) /* drag left */ { left = TRUE; offset = -offset; ! /* sum up the room of the current frame and left of it */ room = 0; for (fr = fr->fr_child; ; fr = fr->fr_next) { --- 5921,5931 ---- } } ! if (offset < 0) // drag left { left = TRUE; offset = -offset; ! // sum up the room of the current frame and left of it room = 0; for (fr = fr->fr_child; ; fr = fr->fr_next) { *************** *** 5934,5966 **** if (fr == curfr) break; } ! fr = curfr->fr_next; /* put fr at frame that grows */ } ! else /* drag right */ { left = FALSE; ! /* sum up the room of frames right of the current one */ room = 0; FOR_ALL_FRAMES(fr, curfr->fr_next) room += fr->fr_width - frame_minwidth(fr, NULL); ! fr = curfr; /* put fr at window that grows */ } ! if (room < offset) /* Not enough room */ ! offset = room; /* Move as far as we can */ ! if (offset <= 0) /* No room at all, quit. */ return; if (fr == NULL) ! return; /* Safety check, should not happen. */ ! /* grow frame fr by offset lines */ frame_new_width(fr, fr->fr_width + offset, left, FALSE); ! /* shrink other frames: current and at the left or at the right */ if (left) ! fr = curfr; /* current frame gets smaller */ else ! fr = curfr->fr_next; /* next frame gets smaller */ while (fr != NULL && offset > 0) { --- 5933,5965 ---- if (fr == curfr) break; } ! fr = curfr->fr_next; // put fr at frame that grows } ! else // drag right { left = FALSE; ! // sum up the room of frames right of the current one room = 0; FOR_ALL_FRAMES(fr, curfr->fr_next) room += fr->fr_width - frame_minwidth(fr, NULL); ! fr = curfr; // put fr at window that grows } ! if (room < offset) // Not enough room ! offset = room; // Move as far as we can ! if (offset <= 0) // No room at all, quit. return; if (fr == NULL) ! return; // Safety check, should not happen. ! // grow frame fr by offset lines frame_new_width(fr, fr->fr_width + offset, left, FALSE); ! // shrink other frames: current and at the left or at the right if (left) ! fr = curfr; // current frame gets smaller else ! fr = curfr->fr_next; // next frame gets smaller while (fr != NULL && offset > 0) { *************** *** 6012,6033 **** { int prev_height = wp->w_height; ! /* Don't want a negative height. Happens when splitting a tiny window. ! * Will equalize heights soon to fix it. */ if (height < 0) height = 0; if (wp->w_height == height) ! return; /* nothing to do */ if (wp->w_height > 0) { if (wp == curwin) ! /* w_wrow needs to be valid. When setting 'laststatus' this may ! * call win_new_height() recursively. */ validate_cursor(); if (wp->w_height != prev_height) ! return; /* Recursive call already changed the size, bail out here ! to avoid the following to mess things up. */ if (wp->w_wrow != wp->w_prev_fraction_row) set_fraction(wp); } --- 6011,6032 ---- { int prev_height = wp->w_height; ! // Don't want a negative height. Happens when splitting a tiny window. ! // Will equalize heights soon to fix it. if (height < 0) height = 0; if (wp->w_height == height) ! return; // nothing to do if (wp->w_height > 0) { if (wp == curwin) ! // w_wrow needs to be valid. When setting 'laststatus' this may ! // call win_new_height() recursively. validate_cursor(); if (wp->w_height != prev_height) ! return; // Recursive call already changed the size, bail out here ! // to avoid the following to mess things up. if (wp->w_wrow != wp->w_prev_fraction_row) set_fraction(wp); } *************** *** 6035,6042 **** wp->w_height = height; wp->w_skipcol = 0; ! /* There is no point in adjusting the scroll position when exiting. Some ! * values might be invalid. */ if (!exiting) scroll_to_fraction(wp, prev_height); } --- 6034,6041 ---- wp->w_height = height; wp->w_skipcol = 0; ! // There is no point in adjusting the scroll position when exiting. Some ! // values might be invalid. if (!exiting) scroll_to_fraction(wp, prev_height); } *************** *** 6062,6068 **** * relative position in the window as before (more or less). */ lnum = wp->w_cursor.lnum; ! if (lnum < 1) /* can happen when starting up */ lnum = 1; wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L) / FRACTION_MULT; --- 6061,6067 ---- * relative position in the window as before (more or less). */ lnum = wp->w_cursor.lnum; ! if (lnum < 1) // can happen when starting up lnum = 1; wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L) / FRACTION_MULT; *************** *** 6071,6077 **** if (sline >= 0) { ! /* Make sure the whole cursor line is visible, if possible. */ int rows = plines_win(wp, lnum, FALSE); if (sline > wp->w_height - rows) --- 6070,6076 ---- if (sline >= 0) { ! // Make sure the whole cursor line is visible, if possible. int rows = plines_win(wp, lnum, FALSE); if (sline > wp->w_height - rows) *************** *** 6110,6116 **** hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); if (lnum == 1) { ! /* first line in buffer is folded */ line_size = 1; --sline; break; --- 6109,6115 ---- hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); if (lnum == 1) { ! // first line in buffer is folded line_size = 1; --sline; break; *************** *** 6153,6159 **** { if (get_scrolloff_value()) update_topline(); ! curs_columns(FALSE); /* validate w_wrow */ } if (prev_height > 0) wp->w_prev_fraction_row = wp->w_wrow; --- 6152,6158 ---- { if (get_scrolloff_value()) update_topline(); ! curs_columns(FALSE); // validate w_wrow } if (prev_height > 0) wp->w_prev_fraction_row = wp->w_wrow; *************** *** 6177,6183 **** if (wp == curwin) { update_topline(); ! curs_columns(TRUE); /* validate w_wrow */ } redraw_win_later(wp, NOT_VALID); wp->w_redr_status = TRUE; --- 6176,6182 ---- if (wp == curwin) { update_topline(); ! curs_columns(TRUE); // validate w_wrow } redraw_win_later(wp, NOT_VALID); wp->w_redr_status = TRUE; *************** *** 6201,6217 **** frame_T *frp; int old_p_ch = curtab->tp_ch_used; ! /* Use the value of p_ch that we remembered. This is needed for when the ! * GUI starts up, we can't be sure in what order things happen. And when ! * p_ch was changed in another tab page. */ curtab->tp_ch_used = p_ch; ! /* Find bottom frame with width of screen. */ frp = lastwin->w_frame; while (frp->fr_width != Columns && frp->fr_parent != NULL) frp = frp->fr_parent; ! /* Avoid changing the height of a window with 'winfixheight' set. */ while (frp->fr_prev != NULL && frp->fr_layout == FR_LEAF && frp->fr_win->w_p_wfh) frp = frp->fr_prev; --- 6200,6216 ---- frame_T *frp; int old_p_ch = curtab->tp_ch_used; ! // Use the value of p_ch that we remembered. This is needed for when the ! // GUI starts up, we can't be sure in what order things happen. And when ! // p_ch was changed in another tab page. curtab->tp_ch_used = p_ch; ! // Find bottom frame with width of screen. frp = lastwin->w_frame; while (frp->fr_width != Columns && frp->fr_parent != NULL) frp = frp->fr_parent; ! // Avoid changing the height of a window with 'winfixheight' set. while (frp->fr_prev != NULL && frp->fr_layout == FR_LEAF && frp->fr_win->w_p_wfh) frp = frp->fr_prev; *************** *** 6220,6226 **** { cmdline_row = Rows - p_ch; ! if (p_ch > old_p_ch) /* p_ch got bigger */ { while (p_ch > old_p_ch) { --- 6219,6225 ---- { cmdline_row = Rows - p_ch; ! if (p_ch > old_p_ch) // p_ch got bigger { while (p_ch > old_p_ch) { *************** *** 6240,6249 **** frp = frp->fr_prev; } ! /* Recompute window positions. */ (void)win_comp_pos(); ! /* clear the lines added to cmdline */ if (full_screen) screen_fill((int)(cmdline_row), (int)Rows, 0, (int)Columns, ' ', ' ', 0); --- 6239,6248 ---- frp = frp->fr_prev; } ! // Recompute window positions. (void)win_comp_pos(); ! // clear the lines added to cmdline if (full_screen) screen_fill((int)(cmdline_row), (int)Rows, 0, (int)Columns, ' ', ' ', 0); *************** *** 6258,6264 **** } frame_add_height(frp, (int)(old_p_ch - p_ch)); ! /* Recompute window positions. */ if (frp != lastwin->w_frame) (void)win_comp_pos(); } --- 6257,6263 ---- } frame_add_height(frp, (int)(old_p_ch - p_ch)); ! // Recompute window positions. if (frp != lastwin->w_frame) (void)win_comp_pos(); } *************** *** 6286,6294 **** */ void last_status( ! int morewin) /* pretend there are two or more windows */ { ! /* Don't make a difference between horizontal or vertical split. */ last_status_rec(topframe, (p_ls == 2 || (p_ls == 1 && (morewin || !ONE_WINDOW)))); } --- 6285,6293 ---- */ void last_status( ! int morewin) // pretend there are two or more windows { ! // Don't make a difference between horizontal or vertical split. last_status_rec(topframe, (p_ls == 2 || (p_ls == 1 && (morewin || !ONE_WINDOW)))); } *************** *** 6304,6317 **** wp = fr->fr_win; if (wp->w_status_height != 0 && !statusline) { ! /* remove status line */ win_new_height(wp, wp->w_height + 1); wp->w_status_height = 0; comp_col(); } else if (wp->w_status_height == 0 && statusline) { ! /* Find a frame to take a line from. */ fp = fr; while (fp->fr_height <= frame_minheight(fp, NULL)) { --- 6303,6316 ---- wp = fr->fr_win; if (wp->w_status_height != 0 && !statusline) { ! // remove status line win_new_height(wp, wp->w_height + 1); wp->w_status_height = 0; comp_col(); } else if (wp->w_status_height == 0 && statusline) { ! // Find a frame to take a line from. fp = fr; while (fp->fr_height <= frame_minheight(fp, NULL)) { *************** *** 6320,6327 **** emsg(_(e_noroom)); return; } ! /* In a column of frames: go to frame above. If already at ! * the top or in a row of frames: go to parent. */ if (fp->fr_parent->fr_layout == FR_COL && fp->fr_prev != NULL) fp = fp->fr_prev; else --- 6319,6326 ---- emsg(_(e_noroom)); return; } ! // In a column of frames: go to frame above. If already at ! // the top or in a row of frames: go to parent. if (fp->fr_parent->fr_layout == FR_COL && fp->fr_prev != NULL) fp = fp->fr_prev; else *************** *** 6342,6354 **** } else if (fr->fr_layout == FR_ROW) { ! /* vertically split windows, set status line for each one */ FOR_ALL_FRAMES(fp, fr->fr_child) last_status_rec(fp, statusline); } else { ! /* horizontally split window, set status line for last one */ for (fp = fr->fr_child; fp->fr_next != NULL; fp = fp->fr_next) ; last_status_rec(fp, statusline); --- 6341,6353 ---- } else if (fr->fr_layout == FR_ROW) { ! // vertically split windows, set status line for each one FOR_ALL_FRAMES(fp, fr->fr_child) last_status_rec(fp, statusline); } else { ! // horizontally split window, set status line for last one for (fp = fr->fr_child; fp->fr_next != NULL; fp = fp->fr_next) ; last_status_rec(fp, statusline); *************** *** 6362,6368 **** tabline_height(void) { #ifdef FEAT_GUI_TABLINE ! /* When the GUI has the tabline then this always returns zero. */ if (gui_use_tabline()) return 0; #endif --- 6361,6367 ---- tabline_height(void) { #ifdef FEAT_GUI_TABLINE ! // When the GUI has the tabline then this always returns zero. if (gui_use_tabline()) return 0; #endif *************** *** 6385,6391 **** tabpage_T *tp; int n; ! if (firstwin == NULL) /* not initialized yet */ return MIN_LINES; total = 0; --- 6384,6390 ---- tabpage_T *tp; int n; ! if (firstwin == NULL) // not initialized yet return MIN_LINES; total = 0; *************** *** 6396,6402 **** total = n; } total += tabline_height(); ! total += 1; /* count the room for the command line */ return total; } --- 6395,6401 ---- total = n; } total += tabline_height(); ! total += 1; // count the room for the command line return total; } *************** *** 6411,6417 **** int count = 0; win_T *wp; ! /* If there is another tab page there always is another window. */ if (first_tabpage->tp_next != NULL) return FALSE; --- 6410,6416 ---- int count = 0; win_T *wp; ! // If there is another tab page there always is another window. if (first_tabpage->tp_next != NULL) return FALSE; *************** *** 6544,6550 **** void restore_snapshot( int idx, ! int close_curwin) /* closing current window */ { win_T *wp; --- 6543,6549 ---- void restore_snapshot( int idx, ! int close_curwin) // closing current window { win_T *wp; *** ../vim-8.1.2395/src/xpm_w32.c 2016-08-29 22:42:21.000000000 +0200 --- src/xpm_w32.c 2019-12-05 21:47:21.427863724 +0100 *************** *** 16,22 **** #include "xpm_w32.h" ! /* Engage Windows support in libXpm */ #define FOR_MSW #include "xpm.h" --- 16,22 ---- #include "xpm_w32.h" ! // Engage Windows support in libXpm #define FOR_MSW #include "xpm.h" *************** *** 33,40 **** HBITMAP *hImage, HBITMAP *hShape) { ! XImage *img; /* loaded image */ ! XImage *shp; /* shapeimage */ XpmAttributes attr; int res; HDC hdc = CreateCompatibleDC(NULL); --- 33,40 ---- HBITMAP *hImage, HBITMAP *hShape) { ! XImage *img; // loaded image ! XImage *shp; // shapeimage XpmAttributes attr; int res; HDC hdc = CreateCompatibleDC(NULL); *** ../vim-8.1.2395/src/version.c 2019-12-05 21:33:12.326868085 +0100 --- src/version.c 2019-12-05 21:37:46.593921677 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 2396, /**/ -- Some of the well known MS-Windows errors: EHUH Unexpected error EUSER User error, not our fault! EGOD Horrible problem, god knows what has happened EERR Errornous error: nothing wrong /// 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 ///