To: vim_dev@googlegroups.com Subject: Patch 8.1.2368 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2368 Problem: Using old C style comments. Solution: Use // comments where appropriate. Files: src/autocmd.c, src/beval.c, src/blob.c, src/blowfish.c, src/buffer.c, src/change.c, src/channel.c, src/charset.c, src/cindent.c, src/crypt.c, src/crypt_zip.c *** ../vim-8.1.2367/src/autocmd.c 2019-11-02 22:54:37.397188845 +0100 --- src/autocmd.c 2019-11-30 20:32:37.963297115 +0100 *************** *** 232,245 **** struct AutoPatCmd *next; // chain of active apc-s for auto-invalidation } AutoPatCmd; ! static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */ /* * augroups stores a list of autocmd group names. */ static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL}; #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i]) ! /* use get_deleted_augroup() to get this */ static char_u *deleted_augroup = NULL; /* --- 232,245 ---- struct AutoPatCmd *next; // chain of active apc-s for auto-invalidation } AutoPatCmd; ! static AutoPatCmd *active_apc_list = NULL; // stack of active autocommands /* * augroups stores a list of autocmd group names. */ static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL}; #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i]) ! // use get_deleted_augroup() to get this static char_u *deleted_augroup = NULL; /* *************** *** 247,253 **** */ static int current_augroup = AUGROUP_DEFAULT; ! static int au_need_clean = FALSE; /* need to delete marked patterns */ static char_u *event_nr2name(event_T event); static int au_get_grouparg(char_u **argp); --- 247,253 ---- */ static int current_augroup = AUGROUP_DEFAULT; ! static int au_need_clean = FALSE; // need to delete marked patterns static char_u *event_nr2name(event_T event); static int au_get_grouparg(char_u **argp); *************** *** 258,264 **** static event_T last_event; static int last_group; ! static int autocmd_blocked = 0; /* block all autocmds */ static char_u * get_deleted_augroup(void) --- 258,264 ---- static event_T last_event; static int last_group; ! static int autocmd_blocked = 0; // block all autocmds static char_u * get_deleted_augroup(void) *************** *** 783,789 **** vim_free(old_ei); } } ! # endif /* FEAT_SYN_HL */ /* * do_autocmd() -- implements the :autocmd command. Can be used in the --- 783,789 ---- vim_free(old_ei); } } ! # endif // FEAT_SYN_HL /* * do_autocmd() -- implements the :autocmd command. Can be used in the *************** *** 1027,1033 **** int patlen; int is_buflocal; int buflocal_nr; ! char_u buflocal_pat[25]; /* for "" */ if (group == AUGROUP_ALL) findgroup = current_augroup; --- 1027,1033 ---- int patlen; int is_buflocal; int buflocal_nr; ! char_u buflocal_pat[25]; // for "" if (group == AUGROUP_ALL) findgroup = current_augroup; *************** *** 1120,1126 **** { if (ap->pat != NULL) { ! /* Accept a pattern when: * - a group was specified and it's that group, or a group was * not specified and it's the current group, or a group was * not specified and we are listing --- 1120,1127 ---- { if (ap->pat != NULL) { ! /* ! * Accept a pattern when: * - a group was specified and it's that group, or a group was * not specified and it's the current group, or a group was * not specified and we are listing *************** *** 1177,1183 **** */ if (ap == NULL) { ! /* refuse to add buffer-local ap if buffer number is invalid */ if (is_buflocal && (buflocal_nr == 0 || buflist_findnr(buflocal_nr) == NULL)) { --- 1178,1184 ---- */ if (ap == NULL) { ! // refuse to add buffer-local ap if buffer number is invalid if (is_buflocal && (buflocal_nr == 0 || buflist_findnr(buflocal_nr) == NULL)) { *** ../vim-8.1.2367/src/beval.c 2019-10-06 22:00:08.293244132 +0200 --- src/beval.c 2019-11-30 20:32:57.279211506 +0100 *************** *** 239,251 **** #endif static int recursive = FALSE; ! /* Don't do anything when 'ballooneval' is off, messages scrolled the ! * windows up or we have no beval area. */ if (!can_use_beval() || beval == NULL) return; ! /* Don't do this recursively. Happens when the expression evaluation ! * takes a long time and invokes something that checks for CTRL-C typed. */ if (recursive) return; recursive = TRUE; --- 239,251 ---- #endif static int recursive = FALSE; ! // Don't do anything when 'ballooneval' is off, messages scrolled the ! // windows up or we have no beval area. if (!can_use_beval() || beval == NULL) return; ! // Don't do this recursively. Happens when the expression evaluation ! // takes a long time and invokes something that checks for CTRL-C typed. if (recursive) return; recursive = TRUE; *************** *** 257,263 **** : wp->w_buffer->b_p_bexpr; if (*bexpr != NUL) { ! /* Convert window pointer to number. */ for (cw = firstwin; cw != wp; cw = cw->w_next) ++winnr; --- 257,263 ---- : wp->w_buffer->b_p_bexpr; if (*bexpr != NUL) { ! // Convert window pointer to number. for (cw = firstwin; cw != wp; cw = cw->w_next) ++winnr; *************** *** 285,293 **** vim_free(result); result = eval_to_string(bexpr, NULL, TRUE); ! /* Remove one trailing newline, it is added when the result was a ! * list and it's hardly ever useful. If the user really wants a ! * trailing newline he can add two and one remains. */ if (result != NULL) { len = STRLEN(result); --- 285,293 ---- vim_free(result); result = eval_to_string(bexpr, NULL, TRUE); ! // Remove one trailing newline, it is added when the result was a ! // list and it's hardly ever useful. If the user really wants a ! // trailing newline he can add two and one remains. if (result != NULL) { len = STRLEN(result); *************** *** 322,325 **** } #endif - --- 322,324 ---- *** ../vim-8.1.2367/src/blob.c 2019-07-27 23:12:08.667924110 +0200 --- src/blob.c 2019-11-30 20:33:12.211145344 +0100 *************** *** 328,331 **** } } ! #endif /* defined(FEAT_EVAL) */ --- 328,331 ---- } } ! #endif // defined(FEAT_EVAL) *** ../vim-8.1.2367/src/blowfish.c 2019-05-28 23:08:12.052648779 +0200 --- src/blowfish.c 2019-11-30 20:34:07.802899168 +0100 *************** *** 35,62 **** } block8; #if defined(MSWIN) ! /* MS-Windows is always little endian */ #else # ifdef HAVE_CONFIG_H ! /* in configure.ac AC_C_BIGENDIAN() defines WORDS_BIGENDIAN when needed */ # else error! Please change this code to define WORDS_BIGENDIAN for big-endian machines. # endif #endif ! /* The state of encryption, referenced by cryptstate_T. */ typedef struct { ! UINT32_T pax[18]; /* P-array */ ! UINT32_T sbx[4][256]; /* S-boxes */ int randbyte_offset; int update_offset; ! char_u cfb_buffer[BF_MAX_CFB_LEN]; /* up to 64 bytes used */ ! int cfb_len; /* size of cfb_buffer actually used */ } bf_state_T; ! /* Blowfish code */ static UINT32_T pax_init[18] = { 0x243f6a88u, 0x85a308d3u, 0x13198a2eu, 0x03707344u, 0xa4093822u, 0x299f31d0u, --- 35,62 ---- } block8; #if defined(MSWIN) ! // MS-Windows is always little endian #else # ifdef HAVE_CONFIG_H ! // in configure.ac AC_C_BIGENDIAN() defines WORDS_BIGENDIAN when needed # else error! Please change this code to define WORDS_BIGENDIAN for big-endian machines. # endif #endif ! // The state of encryption, referenced by cryptstate_T. typedef struct { ! UINT32_T pax[18]; // P-array ! UINT32_T sbx[4][256]; // S-boxes int randbyte_offset; int update_offset; ! char_u cfb_buffer[BF_MAX_CFB_LEN]; // up to 64 bytes used ! int cfb_len; // size of cfb_buffer actually used } bf_state_T; ! // Blowfish code static UINT32_T pax_init[18] = { 0x243f6a88u, 0x85a308d3u, 0x13198a2eu, 0x03707344u, 0xa4093822u, 0x299f31d0u, *************** *** 409,421 **** char_u *key; int keylen; ! /* Process the key 1001 times. ! * See http://en.wikipedia.org/wiki/Key_strengthening. */ key = sha256_key(password, salt, salt_len); for (i = 0; i < 1000; i++) key = sha256_key(key, salt, salt_len); ! /* Convert the key from 64 hex chars to 32 binary chars. */ keylen = (int)STRLEN(key) / 2; if (keylen == 0) { --- 409,421 ---- char_u *key; int keylen; ! // Process the key 1001 times. ! // See http://en.wikipedia.org/wiki/Key_strengthening. key = sha256_key(password, salt, salt_len); for (i = 0; i < 1000; i++) key = sha256_key(key, salt, salt_len); ! // Convert the key from 64 hex chars to 32 binary chars. keylen = (int)STRLEN(key) / 2; if (keylen == 0) { *************** *** 428,435 **** key[i] = u; } ! /* Use "key" to initialize the P-array ("pax") and S-boxes ("sbx") of ! * Blowfish. */ mch_memmove(bfs->sbx, sbx_init, 4 * 4 * 256); for (i = 0; i < 18; ++i) --- 428,435 ---- key[i] = u; } ! // Use "key" to initialize the P-array ("pax") and S-boxes ("sbx") of ! // Blowfish. mch_memmove(bfs->sbx, sbx_init, 4 * 4 * 256); for (i = 0; i < 18; ++i) *************** *** 484,490 **** char_u salt[9]; char_u plaintxt[9]; char_u cryptxt[9]; ! char_u badcryptxt[9]; /* cryptxt when big/little endian is wrong */ UINT32_T keysum; } struct_bf_test_data; --- 484,490 ---- char_u salt[9]; char_u plaintxt[9]; char_u cryptxt[9]; ! char_u badcryptxt[9]; // cryptxt when big/little endian is wrong UINT32_T keysum; } struct_bf_test_data; *************** *** 497,505 **** "password", "salt", "plaintxt", ! "\xad\x3d\xfa\x7f\xe8\xea\x40\xf6", /* cryptxt */ ! "\x72\x50\x3b\x38\x10\x60\x22\xa7", /* badcryptxt */ ! 0x56701b5du /* keysum */ }, }; --- 497,505 ---- "password", "salt", "plaintxt", ! "\xad\x3d\xfa\x7f\xe8\xea\x40\xf6", // cryptxt ! "\x72\x50\x3b\x38\x10\x60\x22\xa7", // badcryptxt ! 0x56701b5du // keysum }, }; *************** *** 518,525 **** vim_memset(&state, 0, sizeof(bf_state_T)); state.cfb_len = BF_MAX_CFB_LEN; ! /* We can't simply use sizeof(UINT32_T), it would generate a compiler ! * warning. */ if (ui != 0xffffffffUL || ui + 1 != 0) { err++; emsg(_("E820: sizeof(uint32_t) != 4")); --- 518,525 ---- vim_memset(&state, 0, sizeof(bf_state_T)); state.cfb_len = BF_MAX_CFB_LEN; ! // We can't simply use sizeof(UINT32_T), it would generate a compiler ! // warning. if (ui != 0xffffffffUL || ui + 1 != 0) { err++; emsg(_("E820: sizeof(uint32_t) != 4")); *************** *** 537,543 **** if (!bf_check_tables(state.pax, state.sbx, bf_test_data[i].keysum)) err++; ! /* Don't modify bf_test_data[i].plaintxt, self test is idempotent. */ memcpy(bk.uc, bf_test_data[i].plaintxt, 8); bf_e_cblock(&state, bk.uc); if (memcmp(bk.uc, bf_test_data[i].cryptxt, 8) != 0) --- 537,543 ---- if (!bf_check_tables(state.pax, state.sbx, bf_test_data[i].keysum)) err++; ! // Don't modify bf_test_data[i].plaintxt, self test is idempotent. memcpy(bk.uc, bf_test_data[i].plaintxt, 8); bf_e_cblock(&state, bk.uc); if (memcmp(bk.uc, bf_test_data[i].cryptxt, 8) != 0) *************** *** 651,658 **** return FAIL; state->method_state = bfs; ! /* "blowfish" uses a 64 byte buffer, causing it to repeat 8 byte groups 8 ! * times. "blowfish2" uses a 8 byte buffer to avoid repeating. */ bfs->cfb_len = state->method_nr == CRYPT_M_BF ? BF_MAX_CFB_LEN : BF_BLOCK; if (blowfish_self_test() == FAIL) --- 651,658 ---- return FAIL; state->method_state = bfs; ! // "blowfish" uses a 64 byte buffer, causing it to repeat 8 byte groups 8 ! // times. "blowfish2" uses a 8 byte buffer to avoid repeating. bfs->cfb_len = state->method_nr == CRYPT_M_BF ? BF_MAX_CFB_LEN : BF_BLOCK; if (blowfish_self_test() == FAIL) *************** *** 684,687 **** return OK; } ! #endif /* FEAT_CRYPT */ --- 684,687 ---- return OK; } ! #endif // FEAT_CRYPT *** ../vim-8.1.2367/src/buffer.c 2019-11-30 15:05:17.995249610 +0100 --- src/buffer.c 2019-11-30 20:43:29.716419163 +0100 *************** *** 78,86 **** */ static int read_buffer( ! int read_stdin, /* read file from stdin, otherwise fifo */ ! exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ ! int flags) /* extra flags for readfile() */ { int retval = OK; linenr_T line_count; --- 78,86 ---- */ static int read_buffer( ! int read_stdin, // read file from stdin, otherwise fifo ! exarg_T *eap, // for forced 'ff' and 'fenc' or NULL ! int flags) // extra flags for readfile() { int retval = OK; linenr_T line_count; *************** *** 98,121 **** flags | READ_BUFFER); if (retval == OK) { ! /* Delete the binary lines. */ while (--line_count >= 0) ml_delete((linenr_T)1, FALSE); } else { ! /* Delete the converted lines. */ while (curbuf->b_ml.ml_line_count > line_count) ml_delete(line_count, FALSE); } ! /* Put the cursor on the first line. */ curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; if (read_stdin) { ! /* Set or reset 'modified' before executing autocommands, so that ! * it can be changed there. */ if (!readonlymode && !BUFEMPTY()) changed(); else if (retval == OK) --- 98,121 ---- flags | READ_BUFFER); if (retval == OK) { ! // Delete the binary lines. while (--line_count >= 0) ml_delete((linenr_T)1, FALSE); } else { ! // Delete the converted lines. while (curbuf->b_ml.ml_line_count > line_count) ml_delete(line_count, FALSE); } ! // Put the cursor on the first line. curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; if (read_stdin) { ! // Set or reset 'modified' before executing autocommands, so that ! // it can be changed there. if (!readonlymode && !BUFEMPTY()) changed(); else if (retval == OK) *************** *** 158,166 **** */ int open_buffer( ! int read_stdin, /* read file from stdin */ ! exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ ! int flags) /* extra flags for readfile() */ { int retval = OK; bufref_T old_curbuf; --- 158,166 ---- */ int open_buffer( ! int read_stdin, // read file from stdin ! exarg_T *eap, // for forced 'ff' and 'fenc' or NULL ! int flags) // extra flags for readfile() { int retval = OK; bufref_T old_curbuf; *************** *** 211,222 **** return FAIL; } ! /* The autocommands in readfile() may change the buffer, but only AFTER ! * reading the file. */ set_bufref(&old_curbuf, curbuf); modified_was_set = FALSE; ! /* mark cursor position as being invalid */ curwin->w_valid = 0; if (curbuf->b_ffname != NULL --- 211,222 ---- return FAIL; } ! // The autocommands in readfile() may change the buffer, but only AFTER ! // reading the file. set_bufref(&old_curbuf, curbuf); modified_was_set = FALSE; ! // mark cursor position as being invalid curwin->w_valid = 0; if (curbuf->b_ffname != NULL *************** *** 264,270 **** #ifdef FEAT_NETBEANS_INTG netbeansFireChanges = oldFire; #endif ! /* Help buffer is filtered. */ if (bt_help(curbuf)) fix_help_buffer(); } --- 264,270 ---- #ifdef FEAT_NETBEANS_INTG netbeansFireChanges = oldFire; #endif ! // Help buffer is filtered. if (bt_help(curbuf)) fix_help_buffer(); } *************** *** 287,293 **** retval = read_buffer(TRUE, eap, flags); } ! /* if first time loading this buffer, init b_chartab[] */ if (curbuf->b_flags & BF_NEVERLOADED) { (void)buf_init_chartab(curbuf, FALSE); --- 287,293 ---- retval = read_buffer(TRUE, eap, flags); } ! // if first time loading this buffer, init b_chartab[] if (curbuf->b_flags & BF_NEVERLOADED) { (void)buf_init_chartab(curbuf, FALSE); *************** *** 301,311 **** * Apply the automatic commands, before processing the modelines. * So the modelines have priority over autocommands. */ ! /* When reading stdin, the buffer contents always needs writing, so set ! * the changed flag. Unless in readonly mode: "ls | gview -". ! * When interrupted and 'cpoptions' contains 'i' set changed flag. */ if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) ! || modified_was_set /* ":set modified" used in autocmd */ #ifdef FEAT_EVAL || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL) #endif --- 301,311 ---- * Apply the automatic commands, before processing the modelines. * So the modelines have priority over autocommands. */ ! // When reading stdin, the buffer contents always needs writing, so set ! // the changed flag. Unless in readonly mode: "ls | gview -". ! // When interrupted and 'cpoptions' contains 'i' set changed flag. if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) ! || modified_was_set // ":set modified" used in autocmd #ifdef FEAT_EVAL || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL) #endif *************** *** 313,326 **** changed(); else if (retval == OK && !read_stdin && !read_fifo) unchanged(curbuf, FALSE, TRUE); ! save_file_ff(curbuf); /* keep this fileformat */ ! /* Set last_changedtick to avoid triggering a TextChanged autocommand right ! * after it was added. */ curbuf->b_last_changedtick = CHANGEDTICK(curbuf); curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf); ! /* require "!" to overwrite the file, because it wasn't read completely */ #ifdef FEAT_EVAL if (aborting()) #else --- 313,326 ---- changed(); else if (retval == OK && !read_stdin && !read_fifo) unchanged(curbuf, FALSE, TRUE); ! save_file_ff(curbuf); // keep this fileformat ! // Set last_changedtick to avoid triggering a TextChanged autocommand right ! // after it was added. curbuf->b_last_changedtick = CHANGEDTICK(curbuf); curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf); ! // require "!" to overwrite the file, because it wasn't read completely #ifdef FEAT_EVAL if (aborting()) #else *************** *** 329,340 **** curbuf->b_flags |= BF_READERR; #ifdef FEAT_FOLDING ! /* Need to update automatic folding. Do this before the autocommands, ! * they may use the fold info. */ foldUpdateAll(curwin); #endif ! /* need to set w_topline, unless some autocommand already did that. */ if (!(curwin->w_valid & VALID_TOPLINE)) { curwin->w_topline = 1; --- 329,340 ---- curbuf->b_flags |= BF_READERR; #ifdef FEAT_FOLDING ! // Need to update automatic folding. Do this before the autocommands, ! // they may use the fold info. foldUpdateAll(curwin); #endif ! // need to set w_topline, unless some autocommand already did that. if (!(curwin->w_valid & VALID_TOPLINE)) { curwin->w_topline = 1; *************** *** 358,364 **** { aco_save_T aco; ! /* Go to the buffer that was opened. */ aucmd_prepbuf(&aco, old_curbuf.br_buf); do_modelines(0); curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); --- 358,364 ---- { aco_save_T aco; ! // Go to the buffer that was opened. aucmd_prepbuf(&aco, old_curbuf.br_buf); do_modelines(0); curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); *************** *** 370,376 **** apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); #endif ! /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); } } --- 370,376 ---- apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); #endif ! // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); } } *************** *** 413,420 **** { buf_T *bp; ! /* Assume that we more often have a recent buffer, start with the last ! * one. */ for (bp = lastbuf; bp != NULL; bp = bp->b_prev) if (bp == buf) return TRUE; --- 413,420 ---- { buf_T *bp; ! // Assume that we more often have a recent buffer, start with the last ! // one. for (bp = lastbuf; bp != NULL; bp = bp->b_prev) if (bp == buf) return TRUE; *************** *** 490,496 **** */ void close_buffer( ! win_T *win, /* if not NULL, set b_last_cursor */ buf_T *buf, int action, int abort_if_last) --- 490,496 ---- */ void close_buffer( ! win_T *win, // if not NULL, set b_last_cursor buf_T *buf, int action, int abort_if_last) *************** *** 510,527 **** * The caller must take care of NOT deleting/freeing when 'bufhidden' is * "hide" (otherwise we could never free or delete a buffer). */ ! if (buf->b_p_bh[0] == 'd') /* 'bufhidden' == "delete" */ { del_buf = TRUE; unload_buf = TRUE; } ! else if (buf->b_p_bh[0] == 'w') /* 'bufhidden' == "wipe" */ { del_buf = TRUE; unload_buf = TRUE; wipe_buf = TRUE; } ! else if (buf->b_p_bh[0] == 'u') /* 'bufhidden' == "unload" */ unload_buf = TRUE; #ifdef FEAT_TERMINAL --- 510,527 ---- * The caller must take care of NOT deleting/freeing when 'bufhidden' is * "hide" (otherwise we could never free or delete a buffer). */ ! if (buf->b_p_bh[0] == 'd') // 'bufhidden' == "delete" { del_buf = TRUE; unload_buf = TRUE; } ! else if (buf->b_p_bh[0] == 'w') // 'bufhidden' == "wipe" { del_buf = TRUE; unload_buf = TRUE; wipe_buf = TRUE; } ! else if (buf->b_p_bh[0] == 'u') // 'bufhidden' == "unload" unload_buf = TRUE; #ifdef FEAT_TERMINAL *************** *** 534,552 **** if (!can_unload_buffer(buf)) return; ! /* Wiping out or unloading a terminal buffer kills the job. */ free_terminal(buf); } else { ! /* The job keeps running, hide the buffer. */ del_buf = FALSE; unload_buf = FALSE; } } else { ! /* A terminal buffer is wiped out if the job has finished. */ del_buf = TRUE; unload_buf = TRUE; wipe_buf = TRUE; --- 534,552 ---- if (!can_unload_buffer(buf)) return; ! // Wiping out or unloading a terminal buffer kills the job. free_terminal(buf); } else { ! // The job keeps running, hide the buffer. del_buf = FALSE; unload_buf = FALSE; } } else { ! // A terminal buffer is wiped out if the job has finished. del_buf = TRUE; unload_buf = TRUE; wipe_buf = TRUE; *************** *** 554,571 **** } #endif ! /* Disallow deleting the buffer when it is locked (already being closed or ! * halfway a command that relies on it). Unloading is allowed. */ if ((del_buf || wipe_buf) && !can_unload_buffer(buf)) return; ! /* check no autocommands closed the window */ if (win != NULL && win_valid_any_tab(win)) { ! /* Set b_last_cursor when closing the last window for the buffer. ! * Remember the last cursor position and window options of the buffer. ! * This used to be only for the current window, but then options like ! * 'foldmethod' may be lost with a ":only" command. */ if (buf->b_nwindows == 1) set_last_cursor(win); buflist_setfpos(buf, win, --- 554,571 ---- } #endif ! // Disallow deleting the buffer when it is locked (already being closed or ! // halfway a command that relies on it). Unloading is allowed. if ((del_buf || wipe_buf) && !can_unload_buffer(buf)) return; ! // check no autocommands closed the window if (win != NULL && win_valid_any_tab(win)) { ! // Set b_last_cursor when closing the last window for the buffer. ! // Remember the last cursor position and window options of the buffer. ! // This used to be only for the current window, but then options like ! // 'foldmethod' may be lost with a ":only" command. if (buf->b_nwindows == 1) set_last_cursor(win); buflist_setfpos(buf, win, *************** *** 575,581 **** set_bufref(&bufref, buf); ! /* When the buffer is no longer in a window, trigger BufWinLeave */ if (buf->b_nwindows == 1) { ++buf->b_locked; --- 575,581 ---- set_bufref(&bufref, buf); ! // When the buffer is no longer in a window, trigger BufWinLeave if (buf->b_nwindows == 1) { ++buf->b_locked; *************** *** 583,622 **** FALSE, buf) && !bufref_valid(&bufref)) { ! /* Autocommands deleted the buffer. */ aucmd_abort: emsg(_(e_auabort)); return; } --buf->b_locked; if (abort_if_last && one_window()) ! /* Autocommands made this the only window. */ goto aucmd_abort; ! /* When the buffer becomes hidden, but is not unloaded, trigger ! * BufHidden */ if (!unload_buf) { ++buf->b_locked; if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, FALSE, buf) && !bufref_valid(&bufref)) ! /* Autocommands deleted the buffer. */ goto aucmd_abort; --buf->b_locked; if (abort_if_last && one_window()) ! /* Autocommands made this the only window. */ goto aucmd_abort; } #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return; #endif } ! /* If the buffer was in curwin and the window has changed, go back to that ! * window, if it still exists. This avoids that ":edit x" triggering a ! * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) { block_autocmds(); --- 583,622 ---- FALSE, buf) && !bufref_valid(&bufref)) { ! // Autocommands deleted the buffer. aucmd_abort: emsg(_(e_auabort)); return; } --buf->b_locked; if (abort_if_last && one_window()) ! // Autocommands made this the only window. goto aucmd_abort; ! // When the buffer becomes hidden, but is not unloaded, trigger ! // BufHidden if (!unload_buf) { ++buf->b_locked; if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, FALSE, buf) && !bufref_valid(&bufref)) ! // Autocommands deleted the buffer. goto aucmd_abort; --buf->b_locked; if (abort_if_last && one_window()) ! // Autocommands made this the only window. goto aucmd_abort; } #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return; #endif } ! // If the buffer was in curwin and the window has changed, go back to that ! // window, if it still exists. This avoids that ":edit x" triggering a ! // "tabnext" BufUnload autocmd leaves a window behind without a buffer. if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) { block_autocmds(); *************** *** 626,651 **** nwindows = buf->b_nwindows; ! /* decrease the link count from windows (unless not in any window) */ if (buf->b_nwindows > 0) --buf->b_nwindows; #ifdef FEAT_DIFF if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0) ! diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */ #endif ! /* Return when a window is displaying the buffer or when it's not ! * unloaded. */ if (buf->b_nwindows > 0 || !unload_buf) return; ! /* Always remove the buffer when there is no file name. */ if (buf->b_ffname == NULL) del_buf = TRUE; ! /* When closing the current buffer stop Visual mode before freeing ! * anything. */ if (buf == curbuf && VIsual_active #if defined(EXITFREE) && !entered_free_all_mem --- 626,651 ---- nwindows = buf->b_nwindows; ! // decrease the link count from windows (unless not in any window) if (buf->b_nwindows > 0) --buf->b_nwindows; #ifdef FEAT_DIFF if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0) ! diff_buf_delete(buf); // Clear 'diff' for hidden buffer. #endif ! // Return when a window is displaying the buffer or when it's not ! // unloaded. if (buf->b_nwindows > 0 || !unload_buf) return; ! // Always remove the buffer when there is no file name. if (buf->b_ffname == NULL) del_buf = TRUE; ! // When closing the current buffer stop Visual mode before freeing ! // anything. if (buf == curbuf && VIsual_active #if defined(EXITFREE) && !entered_free_all_mem *************** *** 657,674 **** * Free all things allocated for this buffer. * Also calls the "BufDelete" autocommands when del_buf is TRUE. */ ! /* Remember if we are closing the current buffer. Restore the number of ! * windows, so that autocommands in buf_freeall() don't get confused. */ is_curbuf = (buf == curbuf); buf->b_nwindows = nwindows; buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); ! /* Autocommands may have deleted the buffer. */ if (!bufref_valid(&bufref)) return; #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return; #endif --- 657,674 ---- * Free all things allocated for this buffer. * Also calls the "BufDelete" autocommands when del_buf is TRUE. */ ! // Remember if we are closing the current buffer. Restore the number of ! // windows, so that autocommands in buf_freeall() don't get confused. is_curbuf = (buf == curbuf); buf->b_nwindows = nwindows; buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); ! // Autocommands may have deleted the buffer. if (!bufref_valid(&bufref)) return; #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return; #endif *************** *** 683,692 **** return; if (win_valid_any_tab(win) && win->w_buffer == buf) ! win->w_buffer = NULL; /* make sure we don't use the buffer now */ ! /* Autocommands may have opened or closed windows for this buffer. ! * Decrement the count for the close we do here. */ if (buf->b_nwindows > 0) --buf->b_nwindows; --- 683,692 ---- return; if (win_valid_any_tab(win) && win->w_buffer == buf) ! win->w_buffer = NULL; // make sure we don't use the buffer now ! // Autocommands may have opened or closed windows for this buffer. ! // Decrement the count for the close we do here. if (buf->b_nwindows > 0) --buf->b_nwindows; *************** *** 722,735 **** { if (del_buf) { ! /* Free all internal variables and reset option values, to make ! * ":bdel" compatible with Vim 5.7. */ free_buffer_stuff(buf, TRUE); ! /* Make it look like a new buffer. */ buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; ! /* Init the options when loaded again. */ buf->b_p_initialized = FALSE; } buf_clear_file(buf); --- 722,735 ---- { if (del_buf) { ! // Free all internal variables and reset option values, to make ! // ":bdel" compatible with Vim 5.7. free_buffer_stuff(buf, TRUE); ! // Make it look like a new buffer. buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; ! // Init the options when loaded again. buf->b_p_initialized = FALSE; } buf_clear_file(buf); *************** *** 752,758 **** buf->b_p_bomb = FALSE; buf->b_start_bomb = FALSE; buf->b_ml.ml_mfp = NULL; ! buf->b_ml.ml_flags = ML_EMPTY; /* empty buffer */ #ifdef FEAT_NETBEANS_INTG netbeans_deleted_all_lines(buf); #endif --- 752,758 ---- buf->b_p_bomb = FALSE; buf->b_start_bomb = FALSE; buf->b_ml.ml_mfp = NULL; ! buf->b_ml.ml_flags = ML_EMPTY; // empty buffer #ifdef FEAT_NETBEANS_INTG netbeans_deleted_all_lines(buf); #endif *************** *** 775,781 **** win_T *the_curwin = curwin; tabpage_T *the_curtab = curtab; ! /* Make sure the buffer isn't closed by autocommands. */ ++buf->b_locked; set_bufref(&bufref, buf); if (buf->b_ml.ml_mfp != NULL) --- 775,781 ---- win_T *the_curwin = curwin; tabpage_T *the_curtab = curtab; ! // Make sure the buffer isn't closed by autocommands. ++buf->b_locked; set_bufref(&bufref, buf); if (buf->b_ml.ml_mfp != NULL) *************** *** 783,789 **** if (apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, FALSE, buf) && !bufref_valid(&bufref)) ! /* autocommands deleted the buffer */ return; } if ((flags & BFA_DEL) && buf->b_p_bl) --- 783,789 ---- if (apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, FALSE, buf) && !bufref_valid(&bufref)) ! // autocommands deleted the buffer return; } if ((flags & BFA_DEL) && buf->b_p_bl) *************** *** 791,797 **** if (apply_autocmds(EVENT_BUFDELETE, buf->b_fname, buf->b_fname, FALSE, buf) && !bufref_valid(&bufref)) ! /* autocommands deleted the buffer */ return; } if (flags & BFA_WIPE) --- 791,797 ---- if (apply_autocmds(EVENT_BUFDELETE, buf->b_fname, buf->b_fname, FALSE, buf) && !bufref_valid(&bufref)) ! // autocommands deleted the buffer return; } if (flags & BFA_WIPE) *************** *** 799,812 **** if (apply_autocmds(EVENT_BUFWIPEOUT, buf->b_fname, buf->b_fname, FALSE, buf) && !bufref_valid(&bufref)) ! /* autocommands deleted the buffer */ return; } --buf->b_locked; ! /* If the buffer was in curwin and the window has changed, go back to that ! * window, if it still exists. This avoids that ":edit x" triggering a ! * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) { block_autocmds(); --- 799,812 ---- if (apply_autocmds(EVENT_BUFWIPEOUT, buf->b_fname, buf->b_fname, FALSE, buf) && !bufref_valid(&bufref)) ! // autocommands deleted the buffer return; } --buf->b_locked; ! // If the buffer was in curwin and the window has changed, go back to that ! // window, if it still exists. This avoids that ":edit x" triggering a ! // "tabnext" BufUnload autocmd leaves a window behind without a buffer. if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) { block_autocmds(); *************** *** 815,821 **** } #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return; #endif --- 815,821 ---- } #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return; #endif *************** *** 828,843 **** if (buf == curbuf && !is_curbuf) return; #ifdef FEAT_DIFF ! diff_buf_delete(buf); /* Can't use 'diff' for unloaded buffer. */ #endif #ifdef FEAT_SYN_HL ! /* Remove any ownsyntax, unless exiting. */ if (curwin != NULL && curwin->w_buffer == buf) reset_synblock(curwin); #endif #ifdef FEAT_FOLDING ! /* No folds in an empty buffer. */ { win_T *win; tabpage_T *tp; --- 828,843 ---- if (buf == curbuf && !is_curbuf) return; #ifdef FEAT_DIFF ! diff_buf_delete(buf); // Can't use 'diff' for unloaded buffer. #endif #ifdef FEAT_SYN_HL ! // Remove any ownsyntax, unless exiting. if (curwin != NULL && curwin->w_buffer == buf) reset_synblock(curwin); #endif #ifdef FEAT_FOLDING ! // No folds in an empty buffer. { win_T *win; tabpage_T *tp; *************** *** 851,870 **** #ifdef FEAT_TCL tcl_buffer_free(buf); #endif ! ml_close(buf, TRUE); /* close and delete the memline/memfile */ ! buf->b_ml.ml_line_count = 0; /* no lines in buffer */ if ((flags & BFA_KEEP_UNDO) == 0) { ! u_blockfree(buf); /* free the memory allocated for undo */ ! u_clearall(buf); /* reset all undo information */ } #ifdef FEAT_SYN_HL ! syntax_clear(&buf->b_s); /* reset syntax info */ #endif #ifdef FEAT_TEXT_PROP clear_buf_prop_types(buf); #endif ! buf->b_flags &= ~BF_READERR; /* a read error is no longer relevant */ } /* --- 851,870 ---- #ifdef FEAT_TCL tcl_buffer_free(buf); #endif ! ml_close(buf, TRUE); // close and delete the memline/memfile ! buf->b_ml.ml_line_count = 0; // no lines in buffer if ((flags & BFA_KEEP_UNDO) == 0) { ! u_blockfree(buf); // free the memory allocated for undo ! u_clearall(buf); // reset all undo information } #ifdef FEAT_SYN_HL ! syntax_clear(&buf->b_s); // reset syntax info #endif #ifdef FEAT_TEXT_PROP clear_buf_prop_types(buf); #endif ! buf->b_flags &= ~BF_READERR; // a read error is no longer relevant } /* *************** *** 877,883 **** ++buf_free_count; free_buffer_stuff(buf, TRUE); #ifdef FEAT_EVAL ! /* b:changedtick uses an item in buf_T, remove it now */ dictitem_remove(buf->b_vars, (dictitem_T *)&buf->b_ct_di); unref_var_dict(buf->b_vars); remove_listeners(buf); --- 877,883 ---- ++buf_free_count; free_buffer_stuff(buf, TRUE); #ifdef FEAT_EVAL ! // b:changedtick uses an item in buf_T, remove it now dictitem_remove(buf->b_vars, (dictitem_T *)&buf->b_ct_di); unref_var_dict(buf->b_vars); remove_listeners(buf); *************** *** 918,925 **** if (autocmd_busy) { ! /* Do not free the buffer structure while autocommands are executing, ! * it's still needed. Free it when autocmd_busy is reset. */ buf->b_next = au_pending_free_buf; au_pending_free_buf = buf; } --- 918,925 ---- if (autocmd_busy) { ! // Do not free the buffer structure while autocommands are executing, ! // it's still needed. Free it when autocmd_busy is reset. buf->b_next = au_pending_free_buf; au_pending_free_buf = buf; } *************** *** 952,962 **** static void free_buffer_stuff( buf_T *buf, ! int free_options) /* free options as well */ { if (free_options) { ! clear_wininfo(buf); /* including window-local options */ free_buf_options(buf, TRUE); #ifdef FEAT_SPELL ga_clear(&buf->b_s.b_langp); --- 952,962 ---- static void free_buffer_stuff( buf_T *buf, ! int free_options) // free options as well { if (free_options) { ! clear_wininfo(buf); // including window-local options free_buf_options(buf, TRUE); #ifdef FEAT_SPELL ga_clear(&buf->b_s.b_langp); *************** *** 966,972 **** { varnumber_T tick = CHANGEDTICK(buf); ! vars_clear(&buf->b_vars->dv_hashtab); /* free all buffer variables */ hash_init(&buf->b_vars->dv_hashtab); init_changedtick(buf); CHANGEDTICK(buf) = tick; --- 966,972 ---- { varnumber_T tick = CHANGEDTICK(buf); ! vars_clear(&buf->b_vars->dv_hashtab); // free all buffer variables hash_init(&buf->b_vars->dv_hashtab); init_changedtick(buf); CHANGEDTICK(buf) = tick; *************** *** 979,986 **** #ifdef FEAT_NETBEANS_INTG netbeans_file_killed(buf); #endif ! map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */ ! map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */ VIM_CLEAR(buf->b_start_fenc); } --- 979,986 ---- #ifdef FEAT_NETBEANS_INTG netbeans_file_killed(buf); #endif ! map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); // clear local mappings ! map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); // clear local abbrevs VIM_CLEAR(buf->b_start_fenc); } *************** *** 1029,1047 **** #if defined(FEAT_EVAL) cleanup_T cs; ! /* Reset the error/interrupt/exception state here so that ! * aborting() returns FALSE when closing a window. */ enter_cleanup(&cs); #endif ! /* Quitting means closing the split window, nothing else. */ win_close(curwin, TRUE); swap_exists_action = SEA_NONE; swap_exists_did_quit = TRUE; #if defined(FEAT_EVAL) ! /* Restore the error/interrupt/exception state if not discarded by a ! * new aborting error, interrupt, or uncaught exception. */ leave_cleanup(&cs); #endif } --- 1029,1047 ---- #if defined(FEAT_EVAL) cleanup_T cs; ! // Reset the error/interrupt/exception state here so that ! // aborting() returns FALSE when closing a window. enter_cleanup(&cs); #endif ! // Quitting means closing the split window, nothing else. win_close(curwin, TRUE); swap_exists_action = SEA_NONE; swap_exists_did_quit = TRUE; #if defined(FEAT_EVAL) ! // Restore the error/interrupt/exception state if not discarded by a ! // new aborting error, interrupt, or uncaught exception. leave_cleanup(&cs); #endif } *************** *** 1067,1081 **** if (swap_exists_action == SEA_QUIT) { #if defined(FEAT_EVAL) ! /* Reset the error/interrupt/exception state here so that ! * aborting() returns FALSE when closing a buffer. */ enter_cleanup(&cs); #endif ! /* User selected Quit at ATTENTION prompt. Go back to previous ! * buffer. If that buffer is gone or the same as the current one, ! * open a new, empty buffer. */ ! swap_exists_action = SEA_NONE; /* don't want it again */ swap_exists_did_quit = TRUE; close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE); if (old_curbuf == NULL || !bufref_valid(old_curbuf) --- 1067,1081 ---- if (swap_exists_action == SEA_QUIT) { #if defined(FEAT_EVAL) ! // Reset the error/interrupt/exception state here so that ! // aborting() returns FALSE when closing a buffer. enter_cleanup(&cs); #endif ! // User selected Quit at ATTENTION prompt. Go back to previous ! // buffer. If that buffer is gone or the same as the current one, ! // open a new, empty buffer. ! swap_exists_action = SEA_NONE; // don't want it again swap_exists_did_quit = TRUE; close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE); if (old_curbuf == NULL || !bufref_valid(old_curbuf) *************** *** 1098,1129 **** check_colorcolumn(curwin); #endif } ! /* If "old_curbuf" is NULL we are in big trouble here... */ #if defined(FEAT_EVAL) ! /* Restore the error/interrupt/exception state if not discarded by a ! * new aborting error, interrupt, or uncaught exception. */ leave_cleanup(&cs); #endif } else if (swap_exists_action == SEA_RECOVER) { #if defined(FEAT_EVAL) ! /* Reset the error/interrupt/exception state here so that ! * aborting() returns FALSE when closing a buffer. */ enter_cleanup(&cs); #endif ! /* User selected Recover at ATTENTION prompt. */ msg_scroll = TRUE; ml_recover(FALSE); ! msg_puts("\n"); /* don't overwrite the last message */ cmdline_row = msg_row; do_modelines(0); #if defined(FEAT_EVAL) ! /* Restore the error/interrupt/exception state if not discarded by a ! * new aborting error, interrupt, or uncaught exception. */ leave_cleanup(&cs); #endif } --- 1098,1129 ---- check_colorcolumn(curwin); #endif } ! // If "old_curbuf" is NULL we are in big trouble here... #if defined(FEAT_EVAL) ! // Restore the error/interrupt/exception state if not discarded by a ! // new aborting error, interrupt, or uncaught exception. leave_cleanup(&cs); #endif } else if (swap_exists_action == SEA_RECOVER) { #if defined(FEAT_EVAL) ! // Reset the error/interrupt/exception state here so that ! // aborting() returns FALSE when closing a buffer. enter_cleanup(&cs); #endif ! // User selected Recover at ATTENTION prompt. msg_scroll = TRUE; ml_recover(FALSE); ! msg_puts("\n"); // don't overwrite the last message cmdline_row = msg_row; do_modelines(0); #if defined(FEAT_EVAL) ! // Restore the error/interrupt/exception state if not discarded by a ! // new aborting error, interrupt, or uncaught exception. leave_cleanup(&cs); #endif } *************** *** 1146,1161 **** char * do_bufdel( int command, ! char_u *arg, /* pointer to extra arguments */ int addr_count, ! int start_bnr, /* first buffer number in a range */ ! int end_bnr, /* buffer nr or last buffer nr in a range */ int forceit) { ! int do_current = 0; /* delete current buffer? */ ! int deleted = 0; /* number of buffers deleted */ ! char *errormsg = NULL; /* return value */ ! int bnr; /* buffer number */ char_u *p; if (addr_count == 0) --- 1146,1161 ---- char * do_bufdel( int command, ! char_u *arg, // pointer to extra arguments int addr_count, ! int start_bnr, // first buffer number in a range ! int end_bnr, // buffer nr or last buffer nr in a range int forceit) { ! int do_current = 0; // delete current buffer? ! int deleted = 0; // number of buffers deleted ! char *errormsg = NULL; // return value ! int bnr; // buffer number char_u *p; if (addr_count == 0) *************** *** 1166,1176 **** { if (addr_count == 2) { ! if (*arg) /* both range and argument is not allowed */ return _(e_trailing); bnr = start_bnr; } ! else /* addr_count == 1 */ bnr = end_bnr; for ( ;!got_int; ui_breakcheck()) --- 1166,1176 ---- { if (addr_count == 2) { ! if (*arg) // both range and argument is not allowed return _(e_trailing); bnr = start_bnr; } ! else // addr_count == 1 bnr = end_bnr; for ( ;!got_int; ui_breakcheck()) *************** *** 1195,1201 **** if (++bnr > end_bnr) break; } ! else /* addr_count == 1 */ { arg = skipwhite(arg); if (*arg == NUL) --- 1195,1201 ---- if (++bnr > end_bnr) break; } ! else // addr_count == 1 { arg = skipwhite(arg); if (*arg == NUL) *************** *** 1206,1212 **** bnr = buflist_findpat(arg, p, command == DOBUF_WIPE || command == DOBUF_WIPE_REUSE, FALSE, FALSE); ! if (bnr < 0) /* failed */ break; arg = p; } --- 1206,1212 ---- bnr = buflist_findpat(arg, p, command == DOBUF_WIPE || command == DOBUF_WIPE_REUSE, FALSE, FALSE); ! if (bnr < 0) // failed break; arg = p; } *************** *** 1268,1274 **** set_bufref(&bufref, buf); if (close_others) ! /* Close any other windows on this buffer, then make it empty. */ close_windows(buf, TRUE); setpcmark(); --- 1268,1274 ---- set_bufref(&bufref, buf); if (close_others) ! // Close any other windows on this buffer, then make it empty. close_windows(buf, TRUE); setpcmark(); *************** *** 1308,1316 **** do_buffer( int action, int start, ! int dir, /* FORWARD or BACKWARD */ ! int count, /* buffer number or number of buffers */ ! int forceit) /* TRUE for :...! */ { buf_T *buf; buf_T *bp; --- 1308,1316 ---- do_buffer( int action, int start, ! int dir, // FORWARD or BACKWARD ! int count, // buffer number or number of buffers ! int forceit) // TRUE for :...! { buf_T *buf; buf_T *bp; *************** *** 1323,1329 **** case DOBUF_LAST: buf = lastbuf; break; default: buf = curbuf; break; } ! if (start == DOBUF_MOD) /* find next modified buffer */ { while (count-- > 0) { --- 1323,1329 ---- case DOBUF_LAST: buf = lastbuf; break; default: buf = curbuf; break; } ! if (start == DOBUF_MOD) // find next modified buffer { while (count-- > 0) { *************** *** 1341,1347 **** return FAIL; } } ! else if (start == DOBUF_FIRST && count) /* find specified buffer number */ { while (buf != NULL && buf->b_fnum != count) buf = buf->b_next; --- 1341,1347 ---- return FAIL; } } ! else if (start == DOBUF_FIRST && count) // find specified buffer number { while (buf != NULL && buf->b_fnum != count) buf = buf->b_next; *************** *** 1351,1358 **** bp = NULL; while (count > 0 || (!unload && !buf->b_p_bl && bp != buf)) { ! /* remember the buffer where we start, we come back there when all ! * buffers are unlisted. */ if (bp == NULL) bp = buf; if (dir == FORWARD) --- 1351,1358 ---- bp = NULL; while (count > 0 || (!unload && !buf->b_p_bl && bp != buf)) { ! // remember the buffer where we start, we come back there when all ! // buffers are unlisted. if (bp == NULL) bp = buf; if (dir == FORWARD) *************** *** 1367,1392 **** if (buf == NULL) buf = lastbuf; } ! /* don't count unlisted buffers */ if (unload || buf->b_p_bl) { --count; ! bp = NULL; /* use this buffer as new starting point */ } if (bp == buf) { ! /* back where we started, didn't find anything. */ emsg(_("E85: There is no listed buffer")); return FAIL; } } } ! if (buf == NULL) /* could not find it */ { if (start == DOBUF_FIRST) { ! /* don't warn when deleting */ if (!unload) semsg(_(e_nobufnr), count); } --- 1367,1392 ---- if (buf == NULL) buf = lastbuf; } ! // don't count unlisted buffers if (unload || buf->b_p_bl) { --count; ! bp = NULL; // use this buffer as new starting point } if (bp == buf) { ! // back where we started, didn't find anything. emsg(_("E85: There is no listed buffer")); return FAIL; } } } ! if (buf == NULL) // could not find it { if (start == DOBUF_FIRST) { ! // don't warn when deleting if (!unload) semsg(_(e_nobufnr), count); } *************** *** 1414,1421 **** set_bufref(&bufref, buf); ! /* When unloading or deleting a buffer that's already unloaded and ! * unlisted: fail silently. */ if (action != DOBUF_WIPE && action != DOBUF_WIPE_REUSE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) return FAIL; --- 1414,1421 ---- set_bufref(&bufref, buf); ! // When unloading or deleting a buffer that's already unloaded and ! // unlisted: fail silently. if (action != DOBUF_WIPE && action != DOBUF_WIPE_REUSE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) return FAIL; *************** *** 1427,1437 **** { dialog_changed(buf, FALSE); if (!bufref_valid(&bufref)) ! /* Autocommand deleted buffer, oops! It's not changed ! * now. */ return FAIL; ! /* If it's still changed fail silently, the dialog already ! * mentioned why it fails. */ if (bufIsChanged(buf)) return FAIL; } --- 1427,1437 ---- { dialog_changed(buf, FALSE); if (!bufref_valid(&bufref)) ! // Autocommand deleted buffer, oops! It's not changed ! // now. return FAIL; ! // If it's still changed fail silently, the dialog already ! // mentioned why it fails. if (bufIsChanged(buf)) return FAIL; } *************** *** 1444,1450 **** } } ! /* When closing the current buffer stop Visual mode. */ if (buf == curbuf && VIsual_active) end_visual_mode(); --- 1444,1450 ---- } } ! // When closing the current buffer stop Visual mode. if (buf == curbuf && VIsual_active) end_visual_mode(); *************** *** 1492,1499 **** * then before the current buffer. * Finally use any buffer. */ ! buf = NULL; /* selected buffer */ ! bp = NULL; /* used when no loaded buffer found */ if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) buf = au_new_curbuf.br_buf; #ifdef FEAT_JUMPLIST --- 1492,1499 ---- * then before the current buffer. * Finally use any buffer. */ ! buf = NULL; // selected buffer ! bp = NULL; // used when no loaded buffer found if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) buf = au_new_curbuf.br_buf; #ifdef FEAT_JUMPLIST *************** *** 1512,1540 **** if (buf != NULL) { if (buf == curbuf || !buf->b_p_bl) ! buf = NULL; /* skip current and unlisted bufs */ else if (buf->b_ml.ml_mfp == NULL) { ! /* skip unloaded buf, but may keep it for later */ if (bp == NULL) bp = buf; buf = NULL; } } ! if (buf != NULL) /* found a valid buffer: stop searching */ break; ! /* advance to older entry in jump list */ if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen) break; if (--jumpidx < 0) jumpidx = curwin->w_jumplistlen - 1; ! if (jumpidx == forward) /* List exhausted for sure */ break; } } #endif ! if (buf == NULL) /* No previous buffer, Try 2'nd approach */ { forward = TRUE; buf = curbuf->b_next; --- 1512,1540 ---- if (buf != NULL) { if (buf == curbuf || !buf->b_p_bl) ! buf = NULL; // skip current and unlisted bufs else if (buf->b_ml.ml_mfp == NULL) { ! // skip unloaded buf, but may keep it for later if (bp == NULL) bp = buf; buf = NULL; } } ! if (buf != NULL) // found a valid buffer: stop searching break; ! // advance to older entry in jump list if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen) break; if (--jumpidx < 0) jumpidx = curwin->w_jumplistlen - 1; ! if (jumpidx == forward) // List exhausted for sure break; } } #endif ! if (buf == NULL) // No previous buffer, Try 2'nd approach { forward = TRUE; buf = curbuf->b_next; *************** *** 1542,1559 **** { if (buf == NULL) { ! if (!forward) /* tried both directions */ break; buf = curbuf->b_prev; forward = FALSE; continue; } ! /* in non-help buffer, try to skip help buffers, and vv */ if (buf->b_help == curbuf->b_help && buf->b_p_bl) { ! if (buf->b_ml.ml_mfp != NULL) /* found loaded buffer */ break; ! if (bp == NULL) /* remember unloaded buf for later */ bp = buf; } if (forward) --- 1542,1559 ---- { if (buf == NULL) { ! if (!forward) // tried both directions break; buf = curbuf->b_prev; forward = FALSE; continue; } ! // in non-help buffer, try to skip help buffers, and vv if (buf->b_help == curbuf->b_help && buf->b_p_bl) { ! if (buf->b_ml.ml_mfp != NULL) // found loaded buffer break; ! if (bp == NULL) // remember unloaded buf for later bp = buf; } if (forward) *************** *** 1562,1576 **** buf = buf->b_prev; } } ! if (buf == NULL) /* No loaded buffer, use unloaded one */ buf = bp; ! if (buf == NULL) /* No loaded buffer, find listed one */ { FOR_ALL_BUFFERS(buf) if (buf->b_p_bl && buf != curbuf) break; } ! if (buf == NULL) /* Still no buffer, just take one */ { if (curbuf->b_next != NULL) buf = curbuf->b_next; --- 1562,1576 ---- buf = buf->b_prev; } } ! if (buf == NULL) // No loaded buffer, use unloaded one buf = bp; ! if (buf == NULL) // No loaded buffer, find listed one { FOR_ALL_BUFFERS(buf) if (buf->b_p_bl && buf != curbuf) break; } ! if (buf == NULL) // Still no buffer, just take one { if (curbuf->b_next != NULL) buf = curbuf->b_next; *************** *** 1581,1609 **** if (buf == NULL) { ! /* Autocommands must have wiped out all other buffers. Only option ! * now is to make the current buffer empty. */ return empty_curbuf(FALSE, forceit, action); } /* * make buf current buffer */ ! if (action == DOBUF_SPLIT) /* split window first */ { ! /* If 'switchbuf' contains "useopen": jump to first window containing ! * "buf" if one exists */ if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) return OK; ! /* If 'switchbuf' contains "usetab": jump to first window in any tab ! * page containing "buf" if one exists */ if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) return OK; if (win_split(0, 0) == FAIL) return FAIL; } ! /* go to current buffer - nothing to do */ if (buf == curbuf) return OK; --- 1581,1609 ---- if (buf == NULL) { ! // Autocommands must have wiped out all other buffers. Only option ! // now is to make the current buffer empty. return empty_curbuf(FALSE, forceit, action); } /* * make buf current buffer */ ! if (action == DOBUF_SPLIT) // split window first { ! // If 'switchbuf' contains "useopen": jump to first window containing ! // "buf" if one exists if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) return OK; ! // If 'switchbuf' contains "usetab": jump to first window in any tab ! // page containing "buf" if one exists if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) return OK; if (win_split(0, 0) == FAIL) return FAIL; } ! // go to current buffer - nothing to do if (buf == curbuf) return OK; *************** *** 1620,1626 **** set_bufref(&bufref, buf); dialog_changed(curbuf, FALSE); if (!bufref_valid(&bufref)) ! /* Autocommand deleted buffer, oops! */ return FAIL; } if (bufIsChanged(curbuf)) --- 1620,1626 ---- set_bufref(&bufref, buf); dialog_changed(curbuf, FALSE); if (!bufref_valid(&bufref)) ! // Autocommand deleted buffer, oops! return FAIL; } if (bufIsChanged(curbuf)) *************** *** 1631,1644 **** } } ! /* Go to the other buffer. */ set_curbuf(buf, action); if (action == DOBUF_SPLIT) ! RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */ #if defined(FEAT_EVAL) ! if (aborting()) /* autocmds may abort script processing */ return FAIL; #endif --- 1631,1644 ---- } } ! // Go to the other buffer. set_curbuf(buf, action); if (action == DOBUF_SPLIT) ! RESET_BINDING(curwin); // reset 'scrollbind' and 'cursorbind' #if defined(FEAT_EVAL) ! if (aborting()) // autocmds may abort script processing return FAIL; #endif *************** *** 1669,1688 **** setpcmark(); if (!cmdmod.keepalt) ! curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */ ! buflist_altfpos(curwin); /* remember curpos */ ! /* Don't restart Select mode after switching to another buffer. */ VIsual_reselect = FALSE; ! /* close_windows() or apply_autocmds() may change curbuf and wipe out "buf" ! */ prevbuf = curbuf; set_bufref(&prevbufref, prevbuf); set_bufref(&newbufref, buf); ! /* Autocommands may delete the curren buffer and/or the buffer we wan to go ! * to. In those cases don't close the buffer. */ if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf) || (bufref_valid(&prevbufref) && bufref_valid(&newbufref) --- 1669,1687 ---- setpcmark(); if (!cmdmod.keepalt) ! curwin->w_alt_fnum = curbuf->b_fnum; // remember alternate file ! buflist_altfpos(curwin); // remember curpos ! // Don't restart Select mode after switching to another buffer. VIsual_reselect = FALSE; ! // close_windows() or apply_autocmds() may change curbuf and wipe out "buf" prevbuf = curbuf; set_bufref(&prevbufref, prevbuf); set_bufref(&newbufref, buf); ! // Autocommands may delete the curren buffer and/or the buffer we wan to go ! // to. In those cases don't close the buffer. if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf) || (bufref_valid(&prevbufref) && bufref_valid(&newbufref) *************** *** 1711,1723 **** && !buf_hide(prevbuf) && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, FALSE); if (curwin != previouswin && win_valid(previouswin)) ! /* autocommands changed curwin, Grr! */ curwin = previouswin; } } ! /* An autocommand may have deleted "buf", already entered it (e.g., when ! * it did ":bunload") or aborted the script processing. ! * If curwin->w_buffer is null, enter_buffer() will make it valid again */ if ((buf_valid(buf) && buf != curbuf #ifdef FEAT_EVAL && !aborting() --- 1710,1722 ---- && !buf_hide(prevbuf) && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, FALSE); if (curwin != previouswin && win_valid(previouswin)) ! // autocommands changed curwin, Grr! curwin = previouswin; } } ! // An autocommand may have deleted "buf", already entered it (e.g., when ! // it did ":bunload") or aborted the script processing. ! // If curwin->w_buffer is null, enter_buffer() will make it valid again if ((buf_valid(buf) && buf != curbuf #ifdef FEAT_EVAL && !aborting() *************** *** 1765,1789 **** curwin->w_s = &(curbuf->b_s); #endif ! /* Cursor on first line by default. */ curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; curwin->w_set_curswant = TRUE; curwin->w_topline_was_set = FALSE; ! /* mark cursor position as being invalid */ curwin->w_valid = 0; buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.lnum, curbuf->b_last_cursor.col, TRUE); ! /* Make sure the buffer is loaded. */ ! if (curbuf->b_ml.ml_mfp == NULL) /* need to load the file */ { ! /* If there is no filetype, allow for detecting one. Esp. useful for ! * ":ball" used in a autocommand. If there already is a filetype we ! * might prefer to keep it. */ if (*curbuf->b_p_ft == NUL) did_filetype = FALSE; --- 1764,1788 ---- curwin->w_s = &(curbuf->b_s); #endif ! // Cursor on first line by default. curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; curwin->w_set_curswant = TRUE; curwin->w_topline_was_set = FALSE; ! // mark cursor position as being invalid curwin->w_valid = 0; buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.lnum, curbuf->b_last_cursor.col, TRUE); ! // Make sure the buffer is loaded. ! if (curbuf->b_ml.ml_mfp == NULL) // need to load the file { ! // If there is no filetype, allow for detecting one. Esp. useful for ! // ":ball" used in a autocommand. If there already is a filetype we ! // might prefer to keep it. if (*curbuf->b_p_ft == NUL) did_filetype = FALSE; *************** *** 1805,1829 **** apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); } ! /* If autocommands did not change the cursor position, restore cursor lnum ! * and possibly cursor col. */ if (curwin->w_cursor.lnum == 1 && inindent(0)) buflist_getfpos(); ! check_arg_idx(curwin); /* check for valid arg_idx */ #ifdef FEAT_TITLE maketitle(); #endif ! /* when autocmds didn't change it */ if (curwin->w_topline == 1 && !curwin->w_topline_was_set) ! scroll_cursor_halfway(FALSE); /* redisplay at correct position */ #ifdef FEAT_NETBEANS_INTG ! /* Send fileOpened event because we've changed buffers. */ netbeans_file_activated(curbuf); #endif ! /* Change directories when the 'acd' option is set. */ DO_AUTOCHDIR; #ifdef FEAT_KEYMAP --- 1804,1828 ---- apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); } ! // If autocommands did not change the cursor position, restore cursor lnum ! // and possibly cursor col. if (curwin->w_cursor.lnum == 1 && inindent(0)) buflist_getfpos(); ! check_arg_idx(curwin); // check for valid arg_idx #ifdef FEAT_TITLE maketitle(); #endif ! // when autocmds didn't change it if (curwin->w_topline == 1 && !curwin->w_topline_was_set) ! scroll_cursor_halfway(FALSE); // redisplay at correct position #ifdef FEAT_NETBEANS_INTG ! // Send fileOpened event because we've changed buffers. netbeans_file_activated(curbuf); #endif ! // Change directories when the 'acd' option is set. DO_AUTOCHDIR; #ifdef FEAT_KEYMAP *************** *** 1831,1838 **** (void)keymap_init(); #endif #ifdef FEAT_SPELL ! /* May need to set the spell language. Can only do this after the buffer ! * has been properly setup. */ if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) (void)did_set_spelllang(curwin); #endif --- 1830,1837 ---- (void)keymap_init(); #endif #ifdef FEAT_SPELL ! // May need to set the spell language. Can only do this after the buffer ! // has been properly setup. if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) (void)did_set_spelllang(curwin); #endif *************** *** 1937,1944 **** * If file name already exists in the list, update the entry. */ #ifdef UNIX ! /* On Unix we can use inode numbers when the file exists. Works better ! * for hard links. */ if (sfname == NULL || mch_stat((char *)sfname, &st) < 0) st.st_dev = (dev_T)-1; #endif --- 1936,1943 ---- * If file name already exists in the list, update the entry. */ #ifdef UNIX ! // On Unix we can use inode numbers when the file exists. Works better ! // for hard links. if (sfname == NULL || mch_stat((char *)sfname, &st) < 0) st.st_dev = (dev_T)-1; #endif *************** *** 1955,1962 **** buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE); if ((flags & BLN_NOOPT) == 0) ! /* copy the options now, if 'cpo' doesn't have 's' and not done ! * already */ buf_copy_options(buf, 0); if ((flags & BLN_LISTED) && !buf->b_p_bl) --- 1954,1961 ---- buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE); if ((flags & BLN_NOOPT) == 0) ! // copy the options now, if 'cpo' doesn't have 's' and not done ! // already buf_copy_options(buf, 0); if ((flags & BLN_LISTED) && !buf->b_p_bl) *************** *** 1987,2005 **** if ((flags & BLN_CURBUF) && curbuf_reusable()) { buf = curbuf; ! /* It's like this buffer is deleted. Watch out for autocommands that ! * change curbuf! If that happens, allocate a new buffer anyway. */ if (curbuf->b_p_bl) apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); if (buf == curbuf) apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return NULL; #endif if (buf == curbuf) { ! /* Make sure 'bufhidden' and 'buftype' are empty */ clear_string_option(&buf->b_p_bh); clear_string_option(&buf->b_p_bt); } --- 1986,2004 ---- if ((flags & BLN_CURBUF) && curbuf_reusable()) { buf = curbuf; ! // It's like this buffer is deleted. Watch out for autocommands that ! // change curbuf! If that happens, allocate a new buffer anyway. if (curbuf->b_p_bl) apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); if (buf == curbuf) apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return NULL; #endif if (buf == curbuf) { ! // Make sure 'bufhidden' and 'buftype' are empty clear_string_option(&buf->b_p_bh); clear_string_option(&buf->b_p_bt); } *************** *** 2013,2019 **** return NULL; } #ifdef FEAT_EVAL ! /* init b: variables */ buf->b_vars = dict_alloc(); if (buf->b_vars == NULL) { --- 2012,2018 ---- return NULL; } #ifdef FEAT_EVAL ! // init b: variables buf->b_vars = dict_alloc(); if (buf->b_vars == NULL) { *************** *** 2050,2071 **** if (buf == curbuf) { ! /* free all things allocated for this buffer */ buf_freeall(buf, 0); ! if (buf != curbuf) /* autocommands deleted the buffer! */ return NULL; #if defined(FEAT_EVAL) ! if (aborting()) /* autocmds may abort script processing */ return NULL; #endif ! free_buffer_stuff(buf, FALSE); /* delete local variables et al. */ ! /* Init the options. */ buf->b_p_initialized = FALSE; buf_copy_options(buf, BCO_ENTER); #ifdef FEAT_KEYMAP ! /* need to reload lmaps and set b:keymap_name */ curbuf->b_kmap_state |= KEYMAP_INIT; #endif } --- 2049,2070 ---- if (buf == curbuf) { ! // free all things allocated for this buffer buf_freeall(buf, 0); ! if (buf != curbuf) // autocommands deleted the buffer! return NULL; #if defined(FEAT_EVAL) ! if (aborting()) // autocmds may abort script processing return NULL; #endif ! free_buffer_stuff(buf, FALSE); // delete local variables et al. ! // Init the options. buf->b_p_initialized = FALSE; buf_copy_options(buf, BCO_ENTER); #ifdef FEAT_KEYMAP ! // need to reload lmaps and set b:keymap_name curbuf->b_kmap_state |= KEYMAP_INIT; #endif } *************** *** 2075,2086 **** * put new buffer at the end of the buffer list */ buf->b_next = NULL; ! if (firstbuf == NULL) /* buffer list is empty */ { buf->b_prev = NULL; firstbuf = buf; } ! else /* append new buffer at end of list */ { lastbuf->b_next = buf; buf->b_prev = lastbuf; --- 2074,2085 ---- * put new buffer at the end of the buffer list */ buf->b_next = NULL; ! if (firstbuf == NULL) // buffer list is empty { buf->b_prev = NULL; firstbuf = buf; } ! else // append new buffer at end of list { lastbuf->b_next = buf; buf->b_prev = lastbuf; *************** *** 2097,2103 **** } else buf->b_fnum = top_file_num++; ! if (top_file_num < 0) /* wrap around (may cause duplicates) */ { emsg(_("W14: Warning: List of file names overflow")); if (emsg_silent == 0) --- 2096,2102 ---- } else buf->b_fnum = top_file_num++; ! if (top_file_num < 0) // wrap around (may cause duplicates) { emsg(_("W14: Warning: List of file names overflow")); if (emsg_silent == 0) *************** *** 2139,2154 **** if (flags & BLN_DUMMY) buf->b_flags |= BF_DUMMY; buf_clear_file(buf); ! clrallmarks(buf); /* clear marks */ ! fmarks_check_names(buf); /* check file marks for this file */ ! buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */ if (!(flags & BLN_DUMMY)) { bufref_T bufref; ! /* Tricky: these autocommands may change the buffer list. They could ! * also split the window with re-using the one empty buffer. This may ! * result in unexpectedly losing the empty buffer. */ set_bufref(&bufref, buf); if (apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, buf) && !bufref_valid(&bufref)) --- 2138,2153 ---- if (flags & BLN_DUMMY) buf->b_flags |= BF_DUMMY; buf_clear_file(buf); ! clrallmarks(buf); // clear marks ! fmarks_check_names(buf); // check file marks for this file ! buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; // init 'buflisted' if (!(flags & BLN_DUMMY)) { bufref_T bufref; ! // Tricky: these autocommands may change the buffer list. They could ! // also split the window with re-using the one empty buffer. This may ! // result in unexpectedly losing the empty buffer. set_bufref(&bufref, buf); if (apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, buf) && !bufref_valid(&bufref)) *************** *** 2160,2166 **** return NULL; } #ifdef FEAT_EVAL ! if (aborting()) /* autocmds may abort script processing */ return NULL; #endif } --- 2159,2165 ---- return NULL; } #ifdef FEAT_EVAL ! if (aborting()) // autocmds may abort script processing return NULL; #endif } *************** *** 2318,2324 **** return FAIL; } ! /* if alternate file is the current buffer, nothing to do */ if (buf == curbuf) return OK; --- 2317,2323 ---- return FAIL; } ! // if alternate file is the current buffer, nothing to do if (buf == curbuf) return OK; *************** *** 2330,2336 **** if (curbuf_locked()) return FAIL; ! /* altfpos may be changed by getfile(), get it now */ if (lnum == 0) { fpos = buflist_findfpos(buf); --- 2329,2335 ---- if (curbuf_locked()) return FAIL; ! // altfpos may be changed by getfile(), get it now if (lnum == 0) { fpos = buflist_findfpos(buf); *************** *** 2342,2359 **** if (options & GETF_SWITCH) { ! /* If 'switchbuf' contains "useopen": jump to first window containing ! * "buf" if one exists */ if (swb_flags & SWB_USEOPEN) wp = buf_jump_open_win(buf); ! /* If 'switchbuf' contains "usetab": jump to first window in any tab ! * page containing "buf" if one exists */ if (wp == NULL && (swb_flags & SWB_USETAB)) wp = buf_jump_open_tab(buf); ! /* If 'switchbuf' contains "split", "vsplit" or "newtab" and the ! * current buffer isn't empty: open new tab or window */ if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB)) && !BUFEMPTY()) { --- 2341,2358 ---- if (options & GETF_SWITCH) { ! // If 'switchbuf' contains "useopen": jump to first window containing ! // "buf" if one exists if (swb_flags & SWB_USEOPEN) wp = buf_jump_open_win(buf); ! // If 'switchbuf' contains "usetab": jump to first window in any tab ! // page containing "buf" if one exists if (wp == NULL && (swb_flags & SWB_USETAB)) wp = buf_jump_open_tab(buf); ! // If 'switchbuf' contains "split", "vsplit" or "newtab" and the ! // current buffer isn't empty: open new tab or window if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB)) && !BUFEMPTY()) { *************** *** 2372,2378 **** { --RedrawingDisabled; ! /* cursor is at to BOL and w_cursor.lnum is checked due to getfile() */ if (!p_sol && col != 0) { curwin->w_cursor.col = col; --- 2371,2377 ---- { --RedrawingDisabled; ! // cursor is at to BOL and w_cursor.lnum is checked due to getfile() if (!p_sol && col != 0) { curwin->w_cursor.col = col; *************** *** 2421,2430 **** char_u *ffname; buf_T *buf = NULL; ! /* First make the name into a full path name */ ffname = FullName_save(fname, #ifdef UNIX ! TRUE /* force expansion, get rid of symbolic links */ #else FALSE #endif --- 2420,2429 ---- char_u *ffname; buf_T *buf = NULL; ! // First make the name into a full path name ffname = FullName_save(fname, #ifdef UNIX ! TRUE // force expansion, get rid of symbolic links #else FALSE #endif *************** *** 2468,2474 **** #endif buf_T *buf; ! /* Start at the last buffer, expect to find a match sooner. */ for (buf = lastbuf; buf != NULL; buf = buf->b_prev) if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname #ifdef UNIX --- 2467,2473 ---- #endif buf_T *buf; ! // Start at the last buffer, expect to find a match sooner. for (buf = lastbuf; buf != NULL; buf = buf->b_prev) if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname #ifdef UNIX *************** *** 2487,2496 **** int buflist_findpat( char_u *pattern, ! char_u *pattern_end, /* pointer to first char after pattern */ ! int unlisted, /* find unlisted buffers */ ! int diffmode UNUSED, /* find diff-mode buffers only */ ! int curtab_only) /* find buffers in current tab only */ { buf_T *buf; int match = -1; --- 2486,2495 ---- int buflist_findpat( char_u *pattern, ! char_u *pattern_end, // pointer to first char after pattern ! int unlisted, // find unlisted buffers ! int diffmode UNUSED, // find diff-mode buffers only ! int curtab_only) // find buffers in current tab only { buf_T *buf; int match = -1; *************** *** 2530,2537 **** patend = pat + STRLEN(pat) - 1; toggledollar = (patend > pat && *patend == '$'); ! /* First try finding a listed buffer. If not found and "unlisted" ! * is TRUE, try finding an unlisted buffer. */ find_listed = TRUE; for (;;) { --- 2529,2536 ---- patend = pat + STRLEN(pat) - 1; toggledollar = (patend > pat && *patend == '$'); ! // First try finding a listed buffer. If not found and "unlisted" ! // is TRUE, try finding an unlisted buffer. find_listed = TRUE; for (;;) { *************** *** 2539,2549 **** { regmatch_T regmatch; ! /* may add '^' and '$' */ if (toggledollar) ! *patend = (attempt < 2) ? NUL : '$'; /* add/remove '$' */ p = pat; ! if (*p == '^' && !(attempt & 1)) /* add/remove '^' */ ++p; regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); if (regmatch.regprog == NULL) --- 2538,2548 ---- { regmatch_T regmatch; ! // may add '^' and '$' if (toggledollar) ! *patend = (attempt < 2) ? NUL : '$'; // add/remove '$' p = pat; ! if (*p == '^' && !(attempt & 1)) // add/remove '^' ++p; regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); if (regmatch.regprog == NULL) *************** *** 2561,2568 **** { if (curtab_only) { ! /* Ignore the match if the buffer is not open in ! * the current tab. */ win_T *wp; FOR_ALL_WINDOWS(wp) --- 2560,2567 ---- { if (curtab_only) { ! // Ignore the match if the buffer is not open in ! // the current tab. win_T *wp; FOR_ALL_WINDOWS(wp) *************** *** 2571,2591 **** if (wp == NULL) continue; } ! if (match >= 0) /* already found a match */ { match = -2; break; } ! match = buf->b_fnum; /* remember first match */ } vim_regfree(regmatch.regprog); ! if (match >= 0) /* found one match */ break; } ! /* Only search for unlisted buffers if there was no match with ! * a listed buffer. */ if (!unlisted || !find_listed || match != -1) break; find_listed = FALSE; --- 2570,2590 ---- if (wp == NULL) continue; } ! if (match >= 0) // already found a match { match = -2; break; } ! match = buf->b_fnum; // remember first match } vim_regfree(regmatch.regprog); ! if (match >= 0) // found one match break; } ! // Only search for unlisted buffers if there was no match with ! // a listed buffer. if (!unlisted || !find_listed || match != -1) break; find_listed = FALSE; *************** *** 2630,2639 **** bufmatch_T *matches = NULL; #endif ! *num_file = 0; /* return values in case of FAIL */ *file = NULL; ! /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */ if (*pat == '^') { patc = alloc(STRLEN(pat) + 11); --- 2629,2638 ---- bufmatch_T *matches = NULL; #endif ! *num_file = 0; // return values in case of FAIL *file = NULL; ! // Make a copy of "pat" and change "^" to "\(^\|[\/]\)". if (*pat == '^') { patc = alloc(STRLEN(pat) + 11); *************** *** 2654,2660 **** regmatch_T regmatch; if (attempt > 0 && patc == pat) ! break; /* there was no anchor, no need to try again */ regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); if (regmatch.regprog == NULL) { --- 2653,2659 ---- regmatch_T regmatch; if (attempt > 0 && patc == pat) ! break; // there was no anchor, no need to try again regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); if (regmatch.regprog == NULL) { *************** *** 2672,2678 **** count = 0; FOR_ALL_BUFFERS(buf) { ! if (!buf->b_p_bl) /* skip unlisted buffers */ continue; p = buflist_match(®match, buf, p_wic); if (p != NULL) --- 2671,2677 ---- count = 0; FOR_ALL_BUFFERS(buf) { ! if (!buf->b_p_bl) // skip unlisted buffers continue; p = buflist_match(®match, buf, p_wic); if (p != NULL) *************** *** 2698,2704 **** } } } ! if (count == 0) /* no match found, break here */ break; if (round == 1) { --- 2697,2703 ---- } } } ! if (count == 0) // no match found, break here break; if (round == 1) { *************** *** 2717,2723 **** } } vim_regfree(regmatch.regprog); ! if (count) /* match(es) found, break here */ break; } --- 2716,2722 ---- } } vim_regfree(regmatch.regprog); ! if (count) // match(es) found, break here break; } *************** *** 2757,2767 **** buflist_match( regmatch_T *rmp, buf_T *buf, ! int ignore_case) /* when TRUE ignore case, when FALSE use 'fic' */ { char_u *match; ! /* First try the short file name, then the long file name. */ match = fname_match(rmp, buf->b_sfname, ignore_case); if (match == NULL) match = fname_match(rmp, buf->b_ffname, ignore_case); --- 2756,2766 ---- buflist_match( regmatch_T *rmp, buf_T *buf, ! int ignore_case) // when TRUE ignore case, when FALSE use 'fic' { char_u *match; ! // First try the short file name, then the long file name. match = fname_match(rmp, buf->b_sfname, ignore_case); if (match == NULL) match = fname_match(rmp, buf->b_ffname, ignore_case); *************** *** 2777,2796 **** fname_match( regmatch_T *rmp, char_u *name, ! int ignore_case) /* when TRUE ignore case, when FALSE use 'fic' */ { char_u *match = NULL; char_u *p; if (name != NULL) { ! /* Ignore case when 'fileignorecase' or the argument is set. */ rmp->rm_ic = p_fic || ignore_case; if (vim_regexec(rmp, name, (colnr_T)0)) match = name; else { ! /* Replace $(HOME) with '~' and try matching again. */ p = home_replace_save(NULL, name); if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) match = name; --- 2776,2795 ---- fname_match( regmatch_T *rmp, char_u *name, ! int ignore_case) // when TRUE ignore case, when FALSE use 'fic' { char_u *match = NULL; char_u *p; if (name != NULL) { ! // Ignore case when 'fileignorecase' or the argument is set. rmp->rm_ic = p_fic || ignore_case; if (vim_regexec(rmp, name, (colnr_T)0)) match = name; else { ! // Replace $(HOME) with '~' and try matching again. p = home_replace_save(NULL, name); if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) match = name; *************** *** 2831,2837 **** buflist_nr2name( int n, int fullname, ! int helptail) /* for help buffers return tail only */ { buf_T *buf; --- 2830,2836 ---- buflist_nr2name( int n, int fullname, ! int helptail) // for help buffers return tail only { buf_T *buf; *************** *** 2862,2878 **** break; if (wip == NULL) { ! /* allocate a new entry */ wip = ALLOC_CLEAR_ONE(wininfo_T); if (wip == NULL) return; wip->wi_win = win; ! if (lnum == 0) /* set lnum even when it's 0 */ lnum = 1; } else { ! /* remove the entry from the list */ if (wip->wi_prev) wip->wi_prev->wi_next = wip->wi_next; else --- 2861,2877 ---- break; if (wip == NULL) { ! // allocate a new entry wip = ALLOC_CLEAR_ONE(wininfo_T); if (wip == NULL) return; wip->wi_win = win; ! if (lnum == 0) // set lnum even when it's 0 lnum = 1; } else { ! // remove the entry from the list if (wip->wi_prev) wip->wi_prev->wi_next = wip->wi_next; else *************** *** 2894,2900 **** } if (copy_options) { ! /* Save the window-specific option values. */ copy_winopt(&win->w_onebuf_opt, &wip->wi_opt); #ifdef FEAT_FOLDING wip->wi_fold_manual = win->w_fold_manual; --- 2893,2899 ---- } if (copy_options) { ! // Save the window-specific option values. copy_winopt(&win->w_onebuf_opt, &wip->wi_opt); #ifdef FEAT_FOLDING wip->wi_fold_manual = win->w_fold_manual; *************** *** 2903,2909 **** wip->wi_optset = TRUE; } ! /* insert the entry in front of the list */ wip->wi_next = buf->b_wininfo; buf->b_wininfo = wip; wip->wi_prev = NULL; --- 2902,2908 ---- wip->wi_optset = TRUE; } ! // insert the entry in front of the list wip->wi_next = buf->b_wininfo; buf->b_wininfo = wip; wip->wi_prev = NULL; *************** *** 2926,2933 **** if (wip->wi_opt.wo_diff) { FOR_ALL_WINDOWS(wp) ! /* return FALSE when it's a window in the current tab page, thus ! * the buffer was in diff mode here */ if (wip->wi_win == wp) return FALSE; return TRUE; --- 2925,2932 ---- if (wip->wi_opt.wo_diff) { FOR_ALL_WINDOWS(wp) ! // return FALSE when it's a window in the current tab page, thus ! // the buffer was in diff mode here if (wip->wi_win == wp) return FALSE; return TRUE; *************** *** 2958,2965 **** ) break; ! /* If no wininfo for curwin, use the first in the list (that doesn't have ! * 'diff' set and is in another tab page). */ if (wip == NULL) { #ifdef FEAT_DIFF --- 2957,2964 ---- ) break; ! // If no wininfo for curwin, use the first in the list (that doesn't have ! // 'diff' set and is in another tab page). if (wip == NULL) { #ifdef FEAT_DIFF *************** *** 2996,3003 **** if (wip != NULL && wip->wi_win != NULL && wip->wi_win != curwin && wip->wi_win->w_buffer == buf) { ! /* The buffer is currently displayed in the window: use the actual ! * option values instead of the saved (possibly outdated) values. */ win_T *wp = wip->wi_win; copy_winopt(&wp->w_onebuf_opt, &curwin->w_onebuf_opt); --- 2995,3002 ---- if (wip != NULL && wip->wi_win != NULL && wip->wi_win != curwin && wip->wi_win->w_buffer == buf) { ! // The buffer is currently displayed in the window: use the actual ! // option values instead of the saved (possibly outdated) values. win_T *wp = wip->wi_win; copy_winopt(&wp->w_onebuf_opt, &curwin->w_onebuf_opt); *************** *** 3009,3015 **** } else if (wip != NULL && wip->wi_optset) { ! /* the buffer was displayed in the current window earlier */ copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt); #ifdef FEAT_FOLDING curwin->w_fold_manual = wip->wi_fold_manual; --- 3008,3014 ---- } else if (wip != NULL && wip->wi_optset) { ! // the buffer was displayed in the current window earlier copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt); #ifdef FEAT_FOLDING curwin->w_fold_manual = wip->wi_fold_manual; *************** *** 3021,3027 **** copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt); #ifdef FEAT_FOLDING ! /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */ if (p_fdls >= 0) curwin->w_p_fdl = p_fdls; #endif --- 3020,3026 ---- copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt); #ifdef FEAT_FOLDING ! // Set 'foldlevel' to 'foldlevelstart' if it's not negative. if (p_fdls >= 0) curwin->w_p_fdl = p_fdls; #endif *************** *** 3103,3109 **** job_running = term_job_running(buf->b_term); job_none_open = job_running && term_none_open(buf->b_term); #endif ! /* skip unlisted buffers, unless ! was used */ if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u')) || (vim_strchr(eap->arg, 'u') && buf->b_p_bl) || (vim_strchr(eap->arg, '+') --- 3102,3108 ---- job_running = term_job_running(buf->b_term); job_none_open = job_running && term_none_open(buf->b_term); #endif ! // skip unlisted buffers, unless ! was used if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u')) || (vim_strchr(eap->arg, 'u') && buf->b_p_bl) || (vim_strchr(eap->arg, '+') *************** *** 3143,3150 **** ro_char = '?'; else ro_char = 'R'; ! changed_char = ' '; /* bufIsChanged() returns TRUE to avoid ! * closing, but it's not actually changed. */ } else if (buf->b_term != NULL) ro_char = 'F'; --- 3142,3149 ---- ro_char = '?'; else ro_char = 'R'; ! changed_char = ' '; // bufIsChanged() returns TRUE to avoid ! // closing, but it's not actually changed. } else if (buf->b_term != NULL) ro_char = 'F'; *************** *** 3166,3172 **** if (len > IOSIZE - 20) len = IOSIZE - 20; ! /* put "line 999" in column 40 or after the file name */ i = 40 - vim_strsize(IObuff); do IObuff[len++] = ' '; --- 3165,3171 ---- if (len > IOSIZE - 20) len = IOSIZE - 20; ! // put "line 999" in column 40 or after the file name i = 40 - vim_strsize(IObuff); do IObuff[len++] = ' '; *************** *** 3180,3186 **** _("line %ld"), buf == curbuf ? curwin->w_cursor.lnum : (long)buflist_findlnum(buf)); msg_outtrans(IObuff); ! out_flush(); /* output one line at a time */ ui_breakcheck(); } --- 3179,3185 ---- _("line %ld"), buf == curbuf ? curwin->w_cursor.lnum : (long)buflist_findlnum(buf)); msg_outtrans(IObuff); ! out_flush(); // output one line at a time ui_breakcheck(); } *************** *** 3226,3232 **** buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, ! int message) /* give message when buffer already exists */ { char_u *ffname = ffname_arg; char_u *sfname = sfname_arg; --- 3225,3231 ---- buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, ! int message) // give message when buffer already exists { char_u *ffname = ffname_arg; char_u *sfname = sfname_arg; *************** *** 3237,3243 **** if (ffname == NULL || *ffname == NUL) { ! /* Removing the name. */ if (buf->b_sfname != buf->b_ffname) VIM_CLEAR(buf->b_sfname); else --- 3236,3242 ---- if (ffname == NULL || *ffname == NUL) { ! // Removing the name. if (buf->b_sfname != buf->b_ffname) VIM_CLEAR(buf->b_sfname); else *************** *** 3249,3256 **** } else { ! fname_expand(buf, &ffname, &sfname); /* will allocate ffname */ ! if (ffname == NULL) /* out of memory */ return FAIL; /* --- 3248,3255 ---- } else { ! fname_expand(buf, &ffname, &sfname); // will allocate ffname ! if (ffname == NULL) // out of memory return FAIL; /* *************** *** 3270,3283 **** #endif if (obuf != NULL && obuf != buf) { ! if (obuf->b_ml.ml_mfp != NULL) /* it's loaded, fail */ { if (message) emsg(_("E95: Buffer with this name already exists")); vim_free(ffname); return FAIL; } ! /* delete from the list */ close_buffer(NULL, obuf, DOBUF_WIPE, FALSE); } sfname = vim_strsave(sfname); --- 3269,3282 ---- #endif if (obuf != NULL && obuf != buf) { ! if (obuf->b_ml.ml_mfp != NULL) // it's loaded, fail { if (message) emsg(_("E95: Buffer with this name already exists")); vim_free(ffname); return FAIL; } ! // delete from the list close_buffer(NULL, obuf, DOBUF_WIPE, FALSE); } sfname = vim_strsave(sfname); *************** *** 3288,3294 **** return FAIL; } #ifdef USE_FNAME_CASE ! fname_case(sfname, 0); /* set correct case for short file name */ #endif if (buf->b_sfname != buf->b_ffname) vim_free(buf->b_sfname); --- 3287,3293 ---- return FAIL; } #ifdef USE_FNAME_CASE ! fname_case(sfname, 0); // set correct case for short file name #endif if (buf->b_sfname != buf->b_ffname) vim_free(buf->b_sfname); *************** *** 3331,3338 **** vim_free(buf->b_ffname); buf->b_ffname = vim_strsave(name); buf->b_sfname = NULL; ! /* Allocate ffname and expand into full path. Also resolves .lnk ! * files on Win32. */ fname_expand(buf, &buf->b_ffname, &buf->b_sfname); buf->b_fname = buf->b_sfname; } --- 3330,3337 ---- vim_free(buf->b_ffname); buf->b_ffname = vim_strsave(name); buf->b_sfname = NULL; ! // Allocate ffname and expand into full path. Also resolves .lnk ! // files on Win32. fname_expand(buf, &buf->b_ffname, &buf->b_sfname); buf->b_fname = buf->b_sfname; } *************** *** 3352,3364 **** ml_setname(buf); if (curwin->w_buffer == buf) ! check_arg_idx(curwin); /* check file name for arg list */ #ifdef FEAT_TITLE ! maketitle(); /* set window title */ #endif ! status_redraw_all(); /* status lines need to be redrawn */ ! fmarks_check_names(buf); /* check named file marks */ ! ml_timestamp(buf); /* reset timestamp */ } /* --- 3351,3363 ---- ml_setname(buf); if (curwin->w_buffer == buf) ! check_arg_idx(curwin); // check file name for arg list #ifdef FEAT_TITLE ! maketitle(); // set window title #endif ! status_redraw_all(); // status lines need to be redrawn ! fmarks_check_names(buf); // check named file marks ! ml_timestamp(buf); // reset timestamp } /* *************** *** 3375,3381 **** { buf_T *buf; ! /* Create a buffer. 'buflisted' is not set if it's a new buffer */ buf = buflist_new(ffname, sfname, lnum, 0); if (buf != NULL && !cmdmod.keepalt) curwin->w_alt_fnum = buf->b_fnum; --- 3374,3380 ---- { buf_T *buf; ! // Create a buffer. 'buflisted' is not set if it's a new buffer buf = buflist_new(ffname, sfname, lnum, 0); if (buf != NULL && !cmdmod.keepalt) curwin->w_alt_fnum = buf->b_fnum; *************** *** 3388,3394 **** */ char_u * getaltfname( ! int errmsg) /* give error message */ { char_u *fname; linenr_T dummy; --- 3387,3393 ---- */ char_u * getaltfname( ! int errmsg) // give error message { char_u *fname; linenr_T dummy; *************** *** 3471,3477 **** #endif ) { ! /* no name is different */ if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) return TRUE; if (fnamecmp(ffname, buf->b_ffname) == 0) --- 3470,3476 ---- #endif ) { ! // no name is different if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) return TRUE; if (fnamecmp(ffname, buf->b_ffname) == 0) *************** *** 3480,3501 **** { stat_T st; ! /* If no stat_T given, get it now */ if (stp == NULL) { if (!buf->b_dev_valid || mch_stat((char *)ffname, &st) < 0) st.st_dev = (dev_T)-1; stp = &st; } ! /* Use dev/ino to check if the files are the same, even when the names ! * are different (possible with links). Still need to compare the ! * name above, for when the file doesn't exist yet. ! * Problem: The dev/ino changes when a file is deleted (and created ! * again) and remains the same when renamed/moved. We don't want to ! * mch_stat() each buffer each time, that would be too slow. Get the ! * dev/ino again when they appear to match, but not when they appear ! * to be different: Could skip a buffer when it's actually the same ! * file. */ if (buf_same_ino(buf, stp)) { buf_setino(buf); --- 3479,3500 ---- { stat_T st; ! // If no stat_T given, get it now if (stp == NULL) { if (!buf->b_dev_valid || mch_stat((char *)ffname, &st) < 0) st.st_dev = (dev_T)-1; stp = &st; } ! // Use dev/ino to check if the files are the same, even when the names ! // are different (possible with links). Still need to compare the ! // name above, for when the file doesn't exist yet. ! // Problem: The dev/ino changes when a file is deleted (and created ! // again) and remains the same when renamed/moved. We don't want to ! // mch_stat() each buffer each time, that would be too slow. Get the ! // dev/ino again when they appear to match, but not when they appear ! // to be different: Could skip a buffer when it's actually the same ! // file. if (buf_same_ino(buf, stp)) { buf_setino(buf); *************** *** 3546,3552 **** */ void fileinfo( ! int fullname, /* when non-zero print full path */ int shorthelp, int dont_truncate) { --- 3545,3551 ---- */ void fileinfo( ! int fullname, // when non-zero print full path int shorthelp, int dont_truncate) { *************** *** 3560,3566 **** if (buffer == NULL) return; ! if (fullname > 1) /* 2 CTRL-G: include buffer number */ { vim_snprintf(buffer, IOSIZE, "buf %d: ", curbuf->b_fnum); p = buffer + STRLEN(buffer); --- 3559,3565 ---- if (buffer == NULL) return; ! if (fullname > 1) // 2 CTRL-G: include buffer number { vim_snprintf(buffer, IOSIZE, "buf %d: ", curbuf->b_fnum); p = buffer + STRLEN(buffer); *************** *** 3600,3607 **** (curbufIsChanged() || (curbuf->b_flags & BF_WRITE_MASK) || curbuf->b_p_ro) ? " " : ""); ! /* With 32 bit longs and more than 21,474,836 lines multiplying by 100 ! * causes an overflow, thus for large numbers divide instead. */ if (curwin->w_cursor.lnum > 1000000L) n = (int)(((long)curwin->w_cursor.lnum) / ((long)curbuf->b_ml.ml_line_count / 100L)); --- 3599,3606 ---- (curbufIsChanged() || (curbuf->b_flags & BF_WRITE_MASK) || curbuf->b_p_ro) ? " " : ""); ! // With 32 bit longs and more than 21,474,836 lines multiplying by 100 ! // causes an overflow, thus for large numbers divide instead. if (curwin->w_cursor.lnum > 1000000L) n = (int)(((long)curwin->w_cursor.lnum) / ((long)curbuf->b_ml.ml_line_count / 100L)); *************** *** 3612,3618 **** vim_snprintf_add(buffer, IOSIZE, "%s", _(no_lines_msg)); #ifdef FEAT_CMDL_INFO else if (p_ru) ! /* Current line and column are already on the screen -- webb */ vim_snprintf_add(buffer, IOSIZE, NGETTEXT("%ld line --%d%%--", "%ld lines --%d%%--", curbuf->b_ml.ml_line_count), --- 3611,3617 ---- vim_snprintf_add(buffer, IOSIZE, "%s", _(no_lines_msg)); #ifdef FEAT_CMDL_INFO else if (p_ru) ! // Current line and column are already on the screen -- webb vim_snprintf_add(buffer, IOSIZE, NGETTEXT("%ld line --%d%%--", "%ld lines --%d%%--", curbuf->b_ml.ml_line_count), *************** *** 3636,3643 **** if (dont_truncate) { ! /* Temporarily set msg_scroll to avoid the message being truncated. ! * First call msg_start() to get the message in the right place. */ msg_start(); n = msg_scroll; msg_scroll = TRUE; --- 3635,3642 ---- if (dont_truncate) { ! // Temporarily set msg_scroll to avoid the message being truncated. ! // First call msg_start() to get the message in the right place. msg_start(); n = msg_scroll; msg_scroll = TRUE; *************** *** 3648,3658 **** { p = (char *)msg_trunc_attr(buffer, FALSE, 0); if (restart_edit != 0 || (msg_scrolled && !need_wait_return)) ! /* Need to repeat the message after redrawing when: ! * - When restart_edit is set (otherwise there will be a delay ! * before redrawing). ! * - When the screen was scrolled but there is no wait-return ! * prompt. */ set_keep_msg((char_u *)p, 0); } --- 3647,3657 ---- { p = (char *)msg_trunc_attr(buffer, FALSE, 0); if (restart_edit != 0 || (msg_scrolled && !need_wait_return)) ! // Need to repeat the message after redrawing when: ! // - When restart_edit is set (otherwise there will be a delay ! // before redrawing). ! // - When the screen was scrolled but there is no wait-return ! // prompt. set_keep_msg((char_u *)p, 0); } *************** *** 3693,3699 **** if (!redrawing()) { ! /* Postpone updating the title when 'lazyredraw' is set. */ need_maketitle = TRUE; return; } --- 3692,3698 ---- if (!redrawing()) { ! // Postpone updating the title when 'lazyredraw' is set. need_maketitle = TRUE; return; } *************** *** 3738,3748 **** } else { ! /* format: "fname + (path) (1 of 2) - VIM" */ #define SPACE_FOR_FNAME (IOSIZE - 100) #define SPACE_FOR_DIR (IOSIZE - 20) ! #define SPACE_FOR_ARGNR (IOSIZE - 10) /* at least room for " - VIM" */ if (curbuf->b_fname == NULL) vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME); #ifdef FEAT_TERMINAL --- 3737,3747 ---- } else { ! // format: "fname + (path) (1 of 2) - VIM" #define SPACE_FOR_FNAME (IOSIZE - 100) #define SPACE_FOR_DIR (IOSIZE - 20) ! #define SPACE_FOR_ARGNR (IOSIZE - 10) // at least room for " - VIM" if (curbuf->b_fname == NULL) vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME); #ifdef FEAT_TERMINAL *************** *** 3781,3811 **** #endif ) { ! /* Get path of file, replace home dir with ~ */ off = (int)STRLEN(buf); buf[off++] = ' '; buf[off++] = '('; home_replace(curbuf, curbuf->b_ffname, buf + off, SPACE_FOR_DIR - off, TRUE); #ifdef BACKSLASH_IN_FILENAME ! /* avoid "c:/name" to be reduced to "c" */ if (isalpha(buf[off]) && buf[off + 1] == ':') off += 2; #endif ! /* remove the file name */ p = gettail_sep(buf + off); if (p == buf + off) { ! /* must be a help buffer */ vim_strncpy(buf + off, (char_u *)_("help"), (size_t)(SPACE_FOR_DIR - off - 1)); } else *p = NUL; ! /* Translate unprintable chars and concatenate. Keep some ! * room for the server name. When there is no room (very long ! * file name) use (...). */ if (off < SPACE_FOR_DIR) { p = transstr(buf + off); --- 3780,3810 ---- #endif ) { ! // Get path of file, replace home dir with ~ off = (int)STRLEN(buf); buf[off++] = ' '; buf[off++] = '('; home_replace(curbuf, curbuf->b_ffname, buf + off, SPACE_FOR_DIR - off, TRUE); #ifdef BACKSLASH_IN_FILENAME ! // avoid "c:/name" to be reduced to "c" if (isalpha(buf[off]) && buf[off + 1] == ':') off += 2; #endif ! // remove the file name p = gettail_sep(buf + off); if (p == buf + off) { ! // must be a help buffer vim_strncpy(buf + off, (char_u *)_("help"), (size_t)(SPACE_FOR_DIR - off - 1)); } else *p = NUL; ! // Translate unprintable chars and concatenate. Keep some ! // room for the server name. When there is no room (very long ! // file name) use (...). if (off < SPACE_FOR_DIR) { p = transstr(buf + off); *************** *** 3834,3840 **** if (maxlen > 0) { ! /* make it shorter by removing a bit in the middle */ if (vim_strsize(buf) > maxlen) trunc_string(buf, buf, maxlen, IOSIZE); } --- 3833,3839 ---- if (maxlen > 0) { ! // make it shorter by removing a bit in the middle if (vim_strsize(buf) > maxlen) trunc_string(buf, buf, maxlen, IOSIZE); } *************** *** 3873,3882 **** { if (buf_spname(curbuf) != NULL) p = buf_spname(curbuf); ! else /* use file name only in icon */ p = gettail(curbuf->b_ffname); *icon_str = NUL; ! /* Truncate name at 100 bytes. */ len = (int)STRLEN(p); if (len > 100) { --- 3872,3881 ---- { if (buf_spname(curbuf) != NULL) p = buf_spname(curbuf); ! else // use file name only in icon p = gettail(curbuf->b_ffname); *icon_str = NUL; ! // Truncate name at 100 bytes. len = (int)STRLEN(p); if (len > 100) { *************** *** 3941,3947 **** } # endif ! #endif /* FEAT_TITLE */ #if defined(FEAT_STL_OPT) || defined(FEAT_GUI_TABLINE) || defined(PROTO) /* --- 3940,3946 ---- } # endif ! #endif // FEAT_TITLE #if defined(FEAT_STL_OPT) || defined(FEAT_GUI_TABLINE) || defined(PROTO) /* *************** *** 3961,3974 **** int build_stl_str_hl( win_T *wp, ! char_u *out, /* buffer to write into != NameBuff */ ! size_t outlen, /* length of out[] */ char_u *fmt, ! int use_sandbox UNUSED, /* "fmt" was set insecurely, use sandbox */ int fillchar, int maxwidth, ! struct stl_hlrec *hltab, /* return: HL attributes (can be NULL) */ ! struct stl_hlrec *tabtab) /* return: tab page nrs (can be NULL) */ { linenr_T lnum; size_t len; --- 3960,3973 ---- int build_stl_str_hl( win_T *wp, ! char_u *out, // buffer to write into != NameBuff ! size_t outlen, // length of out[] char_u *fmt, ! int use_sandbox UNUSED, // "fmt" was set insecurely, use sandbox int fillchar, int maxwidth, ! struct stl_hlrec *hltab, // return: HL attributes (can be NULL) ! struct stl_hlrec *tabtab) // return: tab page nrs (can be NULL) { linenr_T lnum; size_t len; *************** *** 4050,4056 **** if (fillchar == 0) fillchar = ' '; ! /* Can't handle a multi-byte fill character yet. */ else if (mb_char2len(fillchar) > 1) fillchar = '-'; --- 4049,4055 ---- if (fillchar == 0) fillchar = ' '; ! // Can't handle a multi-byte fill character yet. else if (mb_char2len(fillchar) > 1) fillchar = '-'; *************** *** 4091,4098 **** { if (curitem == STL_MAX_ITEM) { ! /* There are too many items. Add the error code to the statusline ! * to give the user a hint about what went wrong. */ if (p + 6 < out + outlen) { mch_memmove(p, " E541", (size_t)5); --- 4090,4097 ---- { if (curitem == STL_MAX_ITEM) { ! // There are too many items. Add the error code to the statusline ! // to give the user a hint about what went wrong. if (p + 6 < out + outlen) { mch_memmove(p, " E541", (size_t)5); *************** *** 4116,4122 **** * Handle one '%' item. */ s++; ! if (*s == NUL) /* ignore trailing % */ break; if (*s == '%') { --- 4115,4121 ---- * Handle one '%' item. */ s++; ! if (*s == NUL) // ignore trailing % break; if (*s == '%') { *************** *** 4155,4162 **** if (curitem > groupitem[groupdepth] + 1 && item[groupitem[groupdepth]].minwid == 0) { ! /* remove group if all items are empty and highlight group ! * doesn't change */ group_start_userhl = group_end_userhl = 0; for (n = groupitem[groupdepth] - 1; n >= 0; n--) { --- 4154,4161 ---- if (curitem > groupitem[groupdepth] + 1 && item[groupitem[groupdepth]].minwid == 0) { ! // remove group if all items are empty and highlight group ! // doesn't change group_start_userhl = group_end_userhl = 0; for (n = groupitem[groupdepth] - 1; n >= 0; n--) { *************** *** 4181,4190 **** } if (l > item[groupitem[groupdepth]].maxwid) { ! /* truncate, remove n bytes of text at the start */ if (has_mbyte) { ! /* Find the first character that should be included. */ n = 0; while (l >= item[groupitem[groupdepth]].maxwid) { --- 4180,4189 ---- } if (l > item[groupitem[groupdepth]].maxwid) { ! // truncate, remove n bytes of text at the start if (has_mbyte) { ! // Find the first character that should be included. n = 0; while (l >= item[groupitem[groupdepth]].maxwid) { *************** *** 4203,4209 **** while (++l < item[groupitem[groupdepth]].minwid) *p++ = fillchar; ! /* correct the start of the items for the truncation */ for (l = groupitem[groupdepth] + 1; l < curitem; l++) { item[l].start -= n; --- 4202,4208 ---- while (++l < item[groupitem[groupdepth]].minwid) *p++ = fillchar; ! // correct the start of the items for the truncation for (l = groupitem[groupdepth] + 1; l < curitem; l++) { item[l].start -= n; *************** *** 4213,4230 **** } else if (abs(item[groupitem[groupdepth]].minwid) > l) { ! /* fill */ n = item[groupitem[groupdepth]].minwid; if (n < 0) { ! /* fill by appending characters */ n = 0 - n; while (l++ < n && p + 1 < out + outlen) *p++ = fillchar; } else { ! /* fill by inserting characters */ mch_memmove(t + n - l, t, (size_t)(p - t)); l = n - l; if (p + l >= out + outlen) --- 4212,4229 ---- } else if (abs(item[groupitem[groupdepth]].minwid) > l) { ! // fill n = item[groupitem[groupdepth]].minwid; if (n < 0) { ! // fill by appending characters n = 0 - n; while (l++ < n && p + 1 < out + outlen) *p++ = fillchar; } else { ! // fill by inserting characters mch_memmove(t + n - l, t, (size_t)(p - t)); l = n - l; if (p + l >= out + outlen) *************** *** 4255,4261 **** if (VIM_ISDIGIT(*s)) { minwid = (int)getdigits(&s); ! if (minwid < 0) /* overflow */ minwid = 0; } if (*s == STL_USER_HL) --- 4254,4260 ---- if (VIM_ISDIGIT(*s)) { minwid = (int)getdigits(&s); ! if (minwid < 0) // overflow minwid = 0; } if (*s == STL_USER_HL) *************** *** 4273,4280 **** { if (minwid == 0) { ! /* %X ends the close label, go back to the previously ! * define tab label nr. */ for (n = curitem - 1; n >= 0; --n) if (item[n].type == TabPage && item[n].minwid >= 0) { --- 4272,4279 ---- { if (minwid == 0) { ! // %X ends the close label, go back to the previously ! // define tab label nr. for (n = curitem - 1; n >= 0; --n) if (item[n].type == TabPage && item[n].minwid >= 0) { *************** *** 4283,4289 **** } } else ! /* close nrs are stored as negative values */ minwid = - minwid; } item[curitem].type = TabPage; --- 4282,4288 ---- } } else ! // close nrs are stored as negative values minwid = - minwid; } item[curitem].type = TabPage; *************** *** 4299,4305 **** if (VIM_ISDIGIT(*s)) { maxwid = (int)getdigits(&s); ! if (maxwid <= 0) /* overflow */ maxwid = 50; } } --- 4298,4304 ---- if (VIM_ISDIGIT(*s)) { maxwid = (int)getdigits(&s); ! if (maxwid <= 0) // overflow maxwid = 50; } } *************** *** 4322,4328 **** } opt = *s++; ! /* OK - now for the real work */ base = 'D'; itemisflag = FALSE; fillable = TRUE; --- 4321,4327 ---- } opt = *s++; ! // OK - now for the real work base = 'D'; itemisflag = FALSE; fillable = TRUE; *************** *** 4333,4339 **** case STL_FILEPATH: case STL_FULLPATH: case STL_FILENAME: ! fillable = FALSE; /* don't change ' ' to fillchar */ if (buf_spname(wp->w_buffer) != NULL) vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1); else --- 4332,4338 ---- case STL_FILEPATH: case STL_FULLPATH: case STL_FILENAME: ! fillable = FALSE; // don't change ' ' to fillchar if (buf_spname(wp->w_buffer) != NULL) vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1); else *************** *** 4349,4360 **** str = gettail(NameBuff); break; ! case STL_VIM_EXPR: /* '{' */ itemisflag = TRUE; t = p; while (*s != '}' && *s != NUL && p + 1 < out + outlen) *p++ = *s++; ! if (*s != '}') /* missing '}' or out of space */ break; s++; *p = 0; --- 4348,4359 ---- str = gettail(NameBuff); break; ! case STL_VIM_EXPR: // '{' itemisflag = TRUE; t = p; while (*s != '}' && *s != NUL && p + 1 < out + outlen) *p++ = *s++; ! if (*s != '}') // missing '}' or out of space break; s++; *p = 0; *************** *** 4412,4418 **** case STL_VIRTCOL: case STL_VIRTCOL_ALT: ! /* In list mode virtcol needs to be recomputed */ virtcol = wp->w_virtcol; if (wp->w_p_list && lcs_tab1 == NUL) { --- 4411,4417 ---- case STL_VIRTCOL: case STL_VIRTCOL_ALT: ! // In list mode virtcol needs to be recomputed virtcol = wp->w_virtcol; if (wp->w_p_list && lcs_tab1 == NUL) { *************** *** 4421,4427 **** wp->w_p_list = TRUE; } ++virtcol; ! /* Don't display %V if it's the same as %c. */ if (opt == STL_VIRTCOL_ALT && (virtcol == (colnr_T)(!(State & INSERT) && empty_line ? 0 : (int)wp->w_cursor.col + 1))) --- 4420,4426 ---- wp->w_p_list = TRUE; } ++virtcol; ! // Don't display %V if it's the same as %c. if (opt == STL_VIRTCOL_ALT && (virtcol == (colnr_T)(!(State & INSERT) && empty_line ? 0 : (int)wp->w_cursor.col + 1))) *************** *** 4465,4471 **** case STL_OFFSET_X: base = 'X'; ! /* FALLTHROUGH */ case STL_OFFSET: #ifdef FEAT_BYTEOFF l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL); --- 4464,4470 ---- case STL_OFFSET_X: base = 'X'; ! // FALLTHROUGH case STL_OFFSET: #ifdef FEAT_BYTEOFF l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL); *************** *** 4477,4483 **** case STL_BYTEVAL_X: base = 'X'; ! /* FALLTHROUGH */ case STL_BYTEVAL: num = byteval; if (num == NL) --- 4476,4482 ---- case STL_BYTEVAL_X: base = 'X'; ! // FALLTHROUGH case STL_BYTEVAL: num = byteval; if (num == NL) *************** *** 4607,4613 **** { for (; l < minwid && p + 1 < out + outlen; l++) { ! /* Don't put a "-" in front of a digit. */ if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t)) *p++ = ' '; else --- 4606,4612 ---- { for (; l < minwid && p + 1 < out + outlen; l++) { ! // Don't put a "-" in front of a digit. if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t)) *p++ = ' '; else *************** *** 4620,4627 **** while (*t && p + 1 < out + outlen) { *p++ = *t++; ! /* Change a space by fillchar, unless fillchar is '-' and a ! * digit follows. */ if (fillable && p[-1] == ' ' && (!VIM_ISDIGIT(*t) || fillchar != '-')) p[-1] = fillchar; --- 4619,4626 ---- while (*t && p + 1 < out + outlen) { *p++ = *t++; ! // Change a space by fillchar, unless fillchar is '-' and a ! // digit follows. if (fillable && p[-1] == ' ' && (!VIM_ISDIGIT(*t) || fillchar != '-')) p[-1] = fillchar; *************** *** 4635,4641 **** char_u nstr[20]; if (p + 20 >= out + outlen) ! break; /* not sufficient space */ prevchar_isitem = TRUE; t = nstr; if (opt == STL_VIRTCOL_ALT) --- 4634,4640 ---- char_u nstr[20]; if (p + 20 >= out + outlen) ! break; // not sufficient space prevchar_isitem = TRUE; t = nstr; if (opt == STL_VIRTCOL_ALT) *************** *** 4679,4685 **** vim_free(str); if (num >= 0 || (!itemisflag && str && *str)) ! prevchar_isflag = FALSE; /* Item not NULL, but not a flag */ curitem++; } *p = NUL; --- 4678,4684 ---- vim_free(str); if (num >= 0 || (!itemisflag && str && *str)) ! prevchar_isflag = FALSE; // Item not NULL, but not a flag curitem++; } *p = NUL; *************** *** 4693,4699 **** width = vim_strsize(out); if (maxwidth > 0 && width > maxwidth) { ! /* Result is too long, must truncate somewhere. */ l = 0; if (itemcnt == 0) s = out; --- 4692,4698 ---- width = vim_strsize(out); if (maxwidth > 0 && width > maxwidth) { ! // Result is too long, must truncate somewhere. l = 0; if (itemcnt == 0) s = out; *************** *** 4702,4714 **** for ( ; l < itemcnt; l++) if (item[l].type == Trunc) { ! /* Truncate at %< item. */ s = item[l].start; break; } if (l == itemcnt) { ! /* No %< item, truncate first item. */ s = item[0].start; l = 0; } --- 4701,4713 ---- for ( ; l < itemcnt; l++) if (item[l].type == Trunc) { ! // Truncate at %< item. s = item[l].start; break; } if (l == itemcnt) { ! // No %< item, truncate first item. s = item[0].start; l = 0; } *************** *** 4716,4722 **** if (width - vim_strsize(s) >= maxwidth) { ! /* Truncation mark is beyond max length */ if (has_mbyte) { s = out; --- 4715,4721 ---- if (width - vim_strsize(s) >= maxwidth) { ! // Truncation mark is beyond max length if (has_mbyte) { s = out; *************** *** 4728,4734 **** break; s += (*mb_ptr2len)(s); } ! /* Fill up for half a double-wide character. */ while (++width < maxwidth) *s++ = fillchar; } --- 4727,4733 ---- break; s += (*mb_ptr2len)(s); } ! // Fill up for half a double-wide character. while (++width < maxwidth) *s++ = fillchar; } *************** *** 4758,4764 **** STRMOVE(s + 1, p); *s = '<'; ! /* Fill up for half a double-wide character. */ while (++width < maxwidth) { s = s + STRLEN(s); --- 4757,4763 ---- STRMOVE(s + 1, p); *s = '<'; ! // Fill up for half a double-wide character. while (++width < maxwidth) { s = s + STRLEN(s); *************** *** 4766,4772 **** *s = NUL; } ! --n; /* count the '<' */ for (; l < itemcnt; l++) { if (item[l].start - n >= s) --- 4765,4771 ---- *s = NUL; } ! --n; // count the '<' for (; l < itemcnt; l++) { if (item[l].start - n >= s) *************** *** 4779,4785 **** } else if (width < maxwidth && STRLEN(out) + maxwidth - width + 1 < outlen) { ! /* Apply STL_MIDDLE if any */ for (l = 0; l < itemcnt; l++) if (item[l].type == Middle) break; --- 4778,4784 ---- } else if (width < maxwidth && STRLEN(out) + maxwidth - width + 1 < outlen) { ! // Apply STL_MIDDLE if any for (l = 0; l < itemcnt; l++) if (item[l].type == Middle) break; *************** *** 4795,4801 **** } } ! /* Store the info about highlighting. */ if (hltab != NULL) { sp = hltab; --- 4794,4800 ---- } } ! // Store the info about highlighting. if (hltab != NULL) { sp = hltab; *************** *** 4812,4818 **** sp->userhl = 0; } ! /* Store the info about tab pages labels. */ if (tabtab != NULL) { sp = tabtab; --- 4811,4817 ---- sp->userhl = 0; } ! // Store the info about tab pages labels. if (tabtab != NULL) { sp = tabtab; *************** *** 4829,4836 **** sp->userhl = 0; } ! /* When inside update_screen we do not want redrawing a stausline, ruler, ! * title, etc. to trigger another redraw, it may cause an endless loop. */ if (updating_screen) { must_redraw = save_must_redraw; --- 4828,4835 ---- sp->userhl = 0; } ! // When inside update_screen we do not want redrawing a stausline, ruler, ! // title, etc. to trigger another redraw, it may cause an endless loop. if (updating_screen) { must_redraw = save_must_redraw; *************** *** 4839,4845 **** return width; } ! #endif /* FEAT_STL_OPT */ #if defined(FEAT_STL_OPT) || defined(FEAT_CMDL_INFO) \ || defined(FEAT_GUI_TABLINE) || defined(PROTO) --- 4838,4844 ---- return width; } ! #endif // FEAT_STL_OPT #if defined(FEAT_STL_OPT) || defined(FEAT_CMDL_INFO) \ || defined(FEAT_GUI_TABLINE) || defined(PROTO) *************** *** 4853,4870 **** char_u *buf, int buflen) { ! long above; /* number of lines above window */ ! long below; /* number of lines below window */ ! if (buflen < 3) /* need at least 3 chars for writing */ return; above = wp->w_topline - 1; #ifdef FEAT_DIFF above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill; if (wp->w_topline == 1 && wp->w_topfill >= 1) ! above = 0; /* All buffer lines are displayed and there is an ! * indication of filler lines, that can be considered ! * seeing all lines. */ #endif below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1; if (below <= 0) --- 4852,4869 ---- char_u *buf, int buflen) { ! long above; // number of lines above window ! long below; // number of lines below window ! if (buflen < 3) // need at least 3 chars for writing return; above = wp->w_topline - 1; #ifdef FEAT_DIFF above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill; if (wp->w_topline == 1 && wp->w_topfill >= 1) ! above = 0; // All buffer lines are displayed and there is an ! // indication of filler lines, that can be considered ! // seeing all lines. #endif below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1; if (below <= 0) *************** *** 4888,4902 **** win_T *wp, char_u *buf, int buflen, ! int add_file) /* Add "file" before the arg number */ { char_u *p; ! if (ARGCOUNT <= 1) /* nothing to do */ return FALSE; ! p = buf + STRLEN(buf); /* go to the end of the buffer */ ! if (p - buf + 35 >= buflen) /* getting too long */ return FALSE; *p++ = ' '; *p++ = '('; --- 4887,4901 ---- win_T *wp, char_u *buf, int buflen, ! int add_file) // Add "file" before the arg number { char_u *p; ! if (ARGCOUNT <= 1) // nothing to do return FALSE; ! p = buf + STRLEN(buf); // go to the end of the buffer ! if (p - buf + 35 >= buflen) // getting too long return FALSE; *p++ = ' '; *p++ = '('; *************** *** 4945,4951 **** # ifdef USE_FNAME_CASE if (fname != NULL) ! fname_case(fname, 0); /* set correct case for file name */ # endif return fname; --- 4944,4950 ---- # ifdef USE_FNAME_CASE if (fname != NULL) ! fname_case(fname, 0); // set correct case for file name # endif return fname; *************** *** 5001,5015 **** int p_ea_save; int open_wins = 0; int r; ! int count; /* Maximum number of windows to open. */ ! int all; /* When TRUE also load inactive buffers. */ int had_tab = cmdmod.tab; tabpage_T *tpnext; ! if (eap->addr_count == 0) /* make as many windows as possible */ count = 9999; else ! count = eap->line2; /* make as many windows as specified */ if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide) all = FALSE; else --- 5000,5014 ---- int p_ea_save; int open_wins = 0; int r; ! int count; // Maximum number of windows to open. ! int all; // When TRUE also load inactive buffers. int had_tab = cmdmod.tab; tabpage_T *tpnext; ! if (eap->addr_count == 0) // make as many windows as possible count = 9999; else ! count = eap->line2; // make as many windows as specified if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide) all = FALSE; else *************** *** 5042,5057 **** && !(wp->w_closing || wp->w_buffer->b_locked > 0)) { win_close(wp, FALSE); ! wpnext = firstwin; /* just in case an autocommand does ! something strange with windows */ ! tpnext = first_tabpage; /* start all over... */ open_wins = 0; } else ++open_wins; } ! /* Without the ":tab" modifier only do the current tab page. */ if (had_tab == 0 || tpnext == NULL) break; goto_tabpage_tp(tpnext, TRUE, TRUE); --- 5041,5056 ---- && !(wp->w_closing || wp->w_buffer->b_locked > 0)) { win_close(wp, FALSE); ! wpnext = firstwin; // just in case an autocommand does ! // something strange with windows ! tpnext = first_tabpage; // start all over... open_wins = 0; } else ++open_wins; } ! // Without the ":tab" modifier only do the current tab page. if (had_tab == 0 || tpnext == NULL) break; goto_tabpage_tp(tpnext, TRUE, TRUE); *************** *** 5062,5092 **** * open one. Otherwise move the window to the right position. * Watch out for autocommands that delete buffers or windows! */ ! /* Don't execute Win/Buf Enter/Leave autocommands here. */ ++autocmd_no_enter; win_enter(lastwin, FALSE); ++autocmd_no_leave; for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) { ! /* Check if this buffer needs a window */ if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) continue; if (had_tab != 0) { ! /* With the ":tab" modifier don't move the window. */ if (buf->b_nwindows > 0) ! wp = lastwin; /* buffer has a window, skip it */ else wp = NULL; } else { ! /* Check if this buffer already has a window */ FOR_ALL_WINDOWS(wp) if (wp->w_buffer == buf) break; ! /* If the buffer already has a window, move it */ if (wp != NULL) win_move_after(wp, curwin); } --- 5061,5091 ---- * open one. Otherwise move the window to the right position. * Watch out for autocommands that delete buffers or windows! */ ! // Don't execute Win/Buf Enter/Leave autocommands here. ++autocmd_no_enter; win_enter(lastwin, FALSE); ++autocmd_no_leave; for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) { ! // Check if this buffer needs a window if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) continue; if (had_tab != 0) { ! // With the ":tab" modifier don't move the window. if (buf->b_nwindows > 0) ! wp = lastwin; // buffer has a window, skip it else wp = NULL; } else { ! // Check if this buffer already has a window FOR_ALL_WINDOWS(wp) if (wp->w_buffer == buf) break; ! // If the buffer already has a window, move it if (wp != NULL) win_move_after(wp, curwin); } *************** *** 5097,5117 **** set_bufref(&bufref, buf); ! /* Split the window and put the buffer in it */ p_ea_save = p_ea; ! p_ea = TRUE; /* use space from all windows */ split_ret = win_split(0, WSP_ROOM | WSP_BELOW); ++open_wins; p_ea = p_ea_save; if (split_ret == FAIL) continue; ! /* Open the buffer in this window. */ swap_exists_action = SEA_DIALOG; set_curbuf(buf, DOBUF_GOTO); if (!bufref_valid(&bufref)) { ! /* autocommands deleted the buffer!!! */ swap_exists_action = SEA_NONE; break; } --- 5096,5116 ---- set_bufref(&bufref, buf); ! // Split the window and put the buffer in it p_ea_save = p_ea; ! p_ea = TRUE; // use space from all windows split_ret = win_split(0, WSP_ROOM | WSP_BELOW); ++open_wins; p_ea = p_ea_save; if (split_ret == FAIL) continue; ! // Open the buffer in this window. swap_exists_action = SEA_DIALOG; set_curbuf(buf, DOBUF_GOTO); if (!bufref_valid(&bufref)) { ! // autocommands deleted the buffer!!! swap_exists_action = SEA_NONE; break; } *************** *** 5120,5140 **** #if defined(FEAT_EVAL) cleanup_T cs; ! /* Reset the error/interrupt/exception state here so that ! * aborting() returns FALSE when closing a window. */ enter_cleanup(&cs); #endif ! /* User selected Quit at ATTENTION prompt; close this window. */ win_close(curwin, TRUE); --open_wins; swap_exists_action = SEA_NONE; swap_exists_did_quit = TRUE; #if defined(FEAT_EVAL) ! /* Restore the error/interrupt/exception state if not ! * discarded by a new aborting error, interrupt, or uncaught ! * exception. */ leave_cleanup(&cs); #endif } --- 5119,5139 ---- #if defined(FEAT_EVAL) cleanup_T cs; ! // Reset the error/interrupt/exception state here so that ! // aborting() returns FALSE when closing a window. enter_cleanup(&cs); #endif ! // User selected Quit at ATTENTION prompt; close this window. win_close(curwin, TRUE); --open_wins; swap_exists_action = SEA_NONE; swap_exists_did_quit = TRUE; #if defined(FEAT_EVAL) ! // Restore the error/interrupt/exception state if not ! // discarded by a new aborting error, interrupt, or uncaught ! // exception. leave_cleanup(&cs); #endif } *************** *** 5145,5164 **** ui_breakcheck(); if (got_int) { ! (void)vgetc(); /* only break the file loading, not the rest */ break; } #ifdef FEAT_EVAL ! /* Autocommands deleted the buffer or aborted script processing!!! */ if (aborting()) break; #endif ! /* When ":tab" was used open a new tab for a new window repeatedly. */ if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) cmdmod.tab = 9999; } --autocmd_no_enter; ! win_enter(firstwin, FALSE); /* back to first window */ --autocmd_no_leave; /* --- 5144,5163 ---- ui_breakcheck(); if (got_int) { ! (void)vgetc(); // only break the file loading, not the rest break; } #ifdef FEAT_EVAL ! // Autocommands deleted the buffer or aborted script processing!!! if (aborting()) break; #endif ! // When ":tab" was used open a new tab for a new window repeatedly. if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) cmdmod.tab = 9999; } --autocmd_no_enter; ! win_enter(firstwin, FALSE); // back to first window --autocmd_no_leave; /* *************** *** 5170,5176 **** || autowrite(wp->w_buffer, FALSE) == OK); if (!win_valid(wp)) { ! /* BufWrite Autocommands made the window invalid, start over */ wp = lastwin; } else if (r) --- 5169,5175 ---- || autowrite(wp->w_buffer, FALSE) == OK); if (!win_valid(wp)) { ! // BufWrite Autocommands made the window invalid, start over wp = lastwin; } else if (r) *************** *** 5210,5217 **** if (!curbuf->b_p_ml || (nmlines = (int)p_mls) == 0) return; ! /* Disallow recursive entry here. Can happen when executing a modeline ! * triggers an autocommand, which reloads modelines with a ":do". */ if (entered) return; --- 5209,5216 ---- if (!curbuf->b_p_ml || (nmlines = (int)p_mls) == 0) return; ! // Disallow recursive entry here. Can happen when executing a modeline ! // triggers an autocommand, which reloads modelines with a ":do". if (entered) return; *************** *** 5228,5234 **** --entered; } ! #include "version.h" /* for version number */ /* * chk_modeline() - check a single line for a mode string --- 5227,5233 ---- --entered; } ! #include "version.h" // for version number /* * chk_modeline() - check a single line for a mode string *************** *** 5237,5247 **** static int chk_modeline( linenr_T lnum, ! int flags) /* Same as for do_modelines(). */ { char_u *s; char_u *e; ! char_u *linecopy; /* local copy of any modeline found */ int prev; int vers; int end; --- 5236,5246 ---- static int chk_modeline( linenr_T lnum, ! int flags) // Same as for do_modelines(). { char_u *s; char_u *e; ! char_u *linecopy; // local copy of any modeline found int prev; int vers; int end; *************** *** 5260,5266 **** if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0) || STRNCMP(s, "vi:", (size_t)3) == 0) break; ! /* Accept both "vim" and "Vim". */ if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') { if (s[3] == '<' || s[3] == '=' || s[3] == '>') --- 5259,5265 ---- if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0) || STRNCMP(s, "vi:", (size_t)3) == 0) break; ! // Accept both "vim" and "Vim". if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') { if (s[3] == '<' || s[3] == '=' || s[3] == '>') *************** *** 5284,5300 **** if (*s) { ! do /* skip over "ex:", "vi:" or "vim:" */ ++s; while (s[-1] != ':'); ! s = linecopy = vim_strsave(s); /* copy the line, it will change */ if (linecopy == NULL) return FAIL; save_sourcing_lnum = sourcing_lnum; save_sourcing_name = sourcing_name; ! sourcing_lnum = lnum; /* prepare for emsg() */ sourcing_name = (char_u *)"modelines"; end = FALSE; --- 5283,5299 ---- if (*s) { ! do // skip over "ex:", "vi:" or "vim:" ++s; while (s[-1] != ':'); ! s = linecopy = vim_strsave(s); // copy the line, it will change if (linecopy == NULL) return FAIL; save_sourcing_lnum = sourcing_lnum; save_sourcing_name = sourcing_name; ! sourcing_lnum = lnum; // prepare for emsg() sourcing_name = (char_u *)"modelines"; end = FALSE; *************** *** 5324,5337 **** if (STRNCMP(s, "set ", (size_t)4) == 0 || STRNCMP(s, "se ", (size_t)3) == 0) { ! if (*e != ':') /* no terminating ':'? */ break; end = TRUE; s = vim_strchr(s, ' ') + 1; } ! *e = NUL; /* truncate the set command */ ! if (*s != NUL) /* skip over an empty "::" */ { int secure_save = secure; #ifdef FEAT_EVAL --- 5323,5336 ---- if (STRNCMP(s, "set ", (size_t)4) == 0 || STRNCMP(s, "se ", (size_t)3) == 0) { ! if (*e != ':') // no terminating ':'? break; end = TRUE; s = vim_strchr(s, ' ') + 1; } ! *e = NUL; // truncate the set command ! if (*s != NUL) // skip over an empty "::" { int secure_save = secure; #ifdef FEAT_EVAL *************** *** 5350,5359 **** #ifdef FEAT_EVAL current_sctx = save_current_sctx; #endif ! if (retval == FAIL) /* stop if error found */ break; } ! s = e + 1; /* advance to next part */ } sourcing_lnum = save_sourcing_lnum; --- 5349,5358 ---- #ifdef FEAT_EVAL current_sctx = save_current_sctx; #endif ! if (retval == FAIL) // stop if error found break; } ! s = e + 1; // advance to next part } sourcing_lnum = save_sourcing_lnum; *************** *** 5477,5489 **** int buf_hide(buf_T *buf) { ! /* 'bufhidden' overrules 'hidden' and ":hide", check it first */ switch (buf->b_p_bh[0]) { ! case 'u': /* "unload" */ ! case 'w': /* "wipe" */ ! case 'd': return FALSE; /* "delete" */ ! case 'h': return TRUE; /* "hide" */ } return (p_hid || cmdmod.hide); } --- 5476,5488 ---- int buf_hide(buf_T *buf) { ! // 'bufhidden' overrules 'hidden' and ":hide", check it first switch (buf->b_p_bh[0]) { ! case 'u': // "unload" ! case 'w': // "wipe" ! case 'd': return FALSE; // "delete" ! case 'h': return TRUE; // "hide" } return (p_hid || cmdmod.hide); } *************** *** 5509,5516 **** } #endif ! /* There is no _file_ when 'buftype' is "nofile", b_sfname ! * contains the name as specified by the user. */ if (bt_nofilename(buf)) { #ifdef FEAT_TERMINAL --- 5508,5515 ---- } #endif ! // There is no _file_ when 'buftype' is "nofile", b_sfname ! // contains the name as specified by the user. if (bt_nofilename(buf)) { #ifdef FEAT_TERMINAL *************** *** 5564,5582 **** aco_save_T aco; exarg_T ea; ! /* Allocate a buffer without putting it in the buffer list. */ newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); if (newbuf == NULL) return TRUE; ! /* Force the 'fileencoding' and 'fileformat' to be equal. */ if (prep_exarg(&ea, buf) == FAIL) { wipe_buffer(newbuf, FALSE); return TRUE; } ! /* set curwin/curbuf to buf and save a few things */ aucmd_prepbuf(&aco, newbuf); if (ml_open(curbuf) == OK --- 5563,5581 ---- aco_save_T aco; exarg_T ea; ! // Allocate a buffer without putting it in the buffer list. newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); if (newbuf == NULL) return TRUE; ! // Force the 'fileencoding' and 'fileformat' to be equal. if (prep_exarg(&ea, buf) == FAIL) { wipe_buffer(newbuf, FALSE); return TRUE; } ! // set curwin/curbuf to buf and save a few things aucmd_prepbuf(&aco, newbuf); if (ml_open(curbuf) == OK *************** *** 5584,5590 **** (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, &ea, READ_NEW | READ_DUMMY) == OK) { ! /* compare the two files line by line */ if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) { differ = FALSE; --- 5583,5589 ---- (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, &ea, READ_NEW | READ_DUMMY) == OK) { ! // compare the two files line by line if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) { differ = FALSE; *************** *** 5598,5607 **** } vim_free(ea.cmd); ! /* restore curwin/curbuf and a few other things */ aucmd_restbuf(&aco); ! if (curbuf != newbuf) /* safety check */ wipe_buffer(newbuf, FALSE); return differ; --- 5597,5606 ---- } vim_free(ea.cmd); ! // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); ! if (curbuf != newbuf) // safety check wipe_buffer(newbuf, FALSE); return differ; *************** *** 5615,5626 **** void wipe_buffer( buf_T *buf, ! int aucmd UNUSED) /* When TRUE trigger autocommands. */ { if (buf->b_fnum == top_file_num - 1) --top_file_num; ! if (!aucmd) /* Don't trigger BufDelete autocommands here. */ block_autocmds(); close_buffer(NULL, buf, DOBUF_WIPE, FALSE); --- 5614,5625 ---- void wipe_buffer( buf_T *buf, ! int aucmd UNUSED) // When TRUE trigger autocommands. { if (buf->b_fnum == top_file_num - 1) --top_file_num; ! if (!aucmd) // Don't trigger BufDelete autocommands here. block_autocmds(); close_buffer(NULL, buf, DOBUF_WIPE, FALSE); *** ../vim-8.1.2367/src/change.c 2019-11-21 22:14:14.353810993 +0100 --- src/change.c 2019-11-30 20:44:04.792264664 +0100 *************** *** 878,884 **** buf->b_start_eol = buf->b_p_eol; buf->b_start_bomb = buf->b_p_bomb; ! /* Only use free/alloc when necessary, they take time. */ if (buf->b_start_fenc == NULL || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { --- 878,884 ---- buf->b_start_eol = buf->b_p_eol; buf->b_start_bomb = buf->b_p_bomb; ! // Only use free/alloc when necessary, they take time. if (buf->b_start_fenc == NULL || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0) { *************** *** 899,905 **** int file_ff_differs(buf_T *buf, int ignore_empty) { ! /* In a buffer that was never loaded the options are not valid. */ if (buf->b_flags & BF_NEVERLOADED) return FALSE; if (ignore_empty --- 899,905 ---- int file_ff_differs(buf_T *buf, int ignore_empty) { ! // In a buffer that was never loaded the options are not valid. if (buf->b_flags & BF_NEVERLOADED) return FALSE; if (ignore_empty *************** *** 1371,1377 **** // make a copy of the current line so we can mess with it saved_line = vim_strsave(ml_get_curline()); ! if (saved_line == NULL) /* out of memory! */ return FALSE; if (State & VREPLACE_FLAG) --- 1371,1377 ---- // make a copy of the current line so we can mess with it saved_line = vim_strsave(ml_get_curline()); ! if (saved_line == NULL) // out of memory! return FALSE; if (State & VREPLACE_FLAG) *************** *** 1646,1652 **** } // Isolate the strings of the middle and end leader. ! while (*p && p[-1] != ':') /* find end of middle flags */ { if (*p == COM_BLANK) require_blank = TRUE; --- 1646,1652 ---- } // Isolate the strings of the middle and end leader. ! while (*p && p[-1] != ':') // find end of middle flags { if (*p == COM_BLANK) require_blank = TRUE; *************** *** 2008,2014 **** // When in REPLACE mode, put the deleted blanks on the replace stack, // preceded by a NUL, so they can be put back when a BS is entered. if (REPLACE_NORMAL(State)) ! replace_push(NUL); /* end of extra blanks */ if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) { while ((*p_extra == ' ' || *p_extra == '\t') --- 2008,2014 ---- // When in REPLACE mode, put the deleted blanks on the replace stack, // preceded by a NUL, so they can be put back when a BS is entered. if (REPLACE_NORMAL(State)) ! replace_push(NUL); // end of extra blanks if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) { while ((*p_extra == ' ' || *p_extra == '\t') *************** *** 2090,2096 **** { // In case we NL to a new line, BS to the previous one, and NL // again, we don't want to save the new line for undo twice. ! (void)u_save_cursor(); /* errors are ignored! */ vr_lines_changed++; } ml_replace(curwin->w_cursor.lnum, p_extra, TRUE); --- 2090,2096 ---- { // In case we NL to a new line, BS to the previous one, and NL // again, we don't want to save the new line for undo twice. ! (void)u_save_cursor(); // errors are ignored! vr_lines_changed++; } ml_replace(curwin->w_cursor.lnum, p_extra, TRUE); *** ../vim-8.1.2367/src/channel.c 2019-09-27 23:12:41.846038561 +0200 --- src/channel.c 2019-11-30 20:46:46.927697639 +0100 *************** *** 14,28 **** #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) ! /* TRUE when netbeans is running with a GUI. */ #ifdef FEAT_GUI # define CH_HAS_GUI (gui.in_use || gui.starting) #endif ! /* Note: when making changes here also adjust configure.ac. */ #ifdef MSWIN ! /* WinSock API is separated from C API, thus we can't use read(), write(), ! * errno... */ # define SOCK_ERRNO errno = WSAGetLastError() # undef ECONNREFUSED # define ECONNREFUSED WSAECONNREFUSED --- 14,28 ---- #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) ! // TRUE when netbeans is running with a GUI. #ifdef FEAT_GUI # define CH_HAS_GUI (gui.in_use || gui.starting) #endif ! // Note: when making changes here also adjust configure.ac. #ifdef MSWIN ! // WinSock API is separated from C API, thus we can't use read(), write(), ! // errno... # define SOCK_ERRNO errno = WSAGetLastError() # undef ECONNREFUSED # define ECONNREFUSED WSAECONNREFUSED *************** *** 61,71 **** static ch_part_T channel_part_read(channel_T *channel); static void free_job_options(jobopt_T *opt); ! /* Whether a redraw is needed for appending a line to a buffer. */ static int channel_need_redraw = FALSE; ! /* Whether we are inside channel_parse_messages() or another situation where it ! * is safe to invoke callbacks. */ static int safe_to_invoke_callback = 0; static char *part_names[] = {"sock", "out", "err", "in"}; --- 61,71 ---- static ch_part_T channel_part_read(channel_T *channel); static void free_job_options(jobopt_T *opt); ! // Whether a redraw is needed for appending a line to a buffer. static int channel_need_redraw = FALSE; ! // Whether we are inside channel_parse_messages() or another situation where it ! // is safe to invoke callbacks. static int safe_to_invoke_callback = 0; static char *part_names[] = {"sock", "out", "err", "in"}; *************** *** 129,135 **** } #endif ! /* Log file opened with ch_logfile(). */ static FILE *log_fd = NULL; #ifdef FEAT_RELTIME static proftime_T log_start; --- 129,135 ---- } #endif ! // Log file opened with ch_logfile(). static FILE *log_fd = NULL; #ifdef FEAT_RELTIME static proftime_T log_start; *************** *** 269,275 **** 0, NULL); if (msgbuf != NULL) ! /* chomp \r or \n */ for (ptr = (char_u *)msgbuf; *ptr; ptr++) switch (*ptr) { --- 269,275 ---- 0, NULL); if (msgbuf != NULL) ! // chomp \r or \n for (ptr = (char_u *)msgbuf; *ptr; ptr++) switch (*ptr) { *************** *** 352,371 **** int has_out_msg; int has_err_msg; ! /* If the job was killed the channel is not expected to work anymore. */ if (channel->ch_job_killed && channel->ch_job == NULL) return FALSE; ! /* If there is a close callback it may still need to be invoked. */ if (channel->ch_close_cb.cb_name != NULL) return TRUE; ! /* If reading from or a buffer it's still useful. */ if (channel->ch_part[PART_IN].ch_bufref.br_buf != NULL) return TRUE; ! /* If there is no callback then nobody can get readahead. If the fd is ! * closed and there is no readahead then the callback won't be called. */ has_sock_msg = channel->ch_part[PART_SOCK].ch_fd != INVALID_FD || channel->ch_part[PART_SOCK].ch_head.rq_next != NULL || channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL; --- 352,371 ---- int has_out_msg; int has_err_msg; ! // If the job was killed the channel is not expected to work anymore. if (channel->ch_job_killed && channel->ch_job == NULL) return FALSE; ! // If there is a close callback it may still need to be invoked. if (channel->ch_close_cb.cb_name != NULL) return TRUE; ! // If reading from or a buffer it's still useful. if (channel->ch_part[PART_IN].ch_bufref.br_buf != NULL) return TRUE; ! // If there is no callback then nobody can get readahead. If the fd is ! // closed and there is no readahead then the callback won't be called. has_sock_msg = channel->ch_part[PART_SOCK].ch_fd != INVALID_FD || channel->ch_part[PART_SOCK].ch_head.rq_next != NULL || channel->ch_part[PART_SOCK].ch_json_head.jq_next != NULL; *************** *** 468,483 **** int did_free = FALSE; channel_T *ch; ! /* This is invoked from the garbage collector, which only runs at a safe ! * point. */ ++safe_to_invoke_callback; for (ch = first_channel; ch != NULL; ch = ch->ch_next) if (!channel_still_useful(ch) && (ch->ch_copyID & mask) != (copyID & mask)) { ! /* Free the channel and ordinary items it contains, but don't ! * recurse into Lists, Dictionaries etc. */ channel_free_contents(ch); did_free = TRUE; } --- 468,483 ---- int did_free = FALSE; channel_T *ch; ! // This is invoked from the garbage collector, which only runs at a safe ! // point. ++safe_to_invoke_callback; for (ch = first_channel; ch != NULL; ch = ch->ch_next) if (!channel_still_useful(ch) && (ch->ch_copyID & mask) != (copyID & mask)) { ! // Free the channel and ordinary items it contains, but don't ! // recurse into Lists, Dictionaries etc. channel_free_contents(ch); did_free = TRUE; } *************** *** 498,504 **** if (!channel_still_useful(ch) && (ch->ch_copyID & mask) != (copyID & mask)) { ! /* Free the channel struct itself. */ channel_free_channel(ch); } } --- 498,504 ---- if (!channel_still_useful(ch) && (ch->ch_copyID & mask) != (copyID & mask)) { ! // Free the channel struct itself. channel_free_channel(ch); } } *************** *** 566,573 **** gpointer clientData) { channel_read_fd(GPOINTER_TO_INT(clientData)); ! return TRUE; /* Return FALSE instead in case the event source is to ! * be removed after this function returns. */ } # else static void --- 566,573 ---- gpointer clientData) { channel_read_fd(GPOINTER_TO_INT(clientData)); ! return TRUE; // Return FALSE instead in case the event source is to ! // be removed after this function returns. } # else static void *************** *** 586,598 **** if (!CH_HAS_GUI) return; ! /* gets stuck in handling events for a not connected channel */ if (channel->ch_keep_open) return; # ifdef FEAT_GUI_X11 ! /* Tell notifier we are interested in being called when there is input on ! * the editor connection socket. */ if (channel->ch_part[part].ch_inputHandler == (XtInputId)NULL) { ch_log(channel, "Registering part %s with fd %d", --- 586,598 ---- if (!CH_HAS_GUI) return; ! // gets stuck in handling events for a not connected channel if (channel->ch_keep_open) return; # ifdef FEAT_GUI_X11 ! // Tell notifier we are interested in being called when there is input on ! // the editor connection socket. if (channel->ch_part[part].ch_inputHandler == (XtInputId)NULL) { ch_log(channel, "Registering part %s with fd %d", *************** *** 607,614 **** } # else # ifdef FEAT_GUI_GTK ! /* Tell gdk we are interested in being called when there is input on the ! * editor connection socket. */ if (channel->ch_part[part].ch_inputHandler == 0) { ch_log(channel, "Registering part %s with fd %d", --- 607,614 ---- } # else # ifdef FEAT_GUI_GTK ! // Tell gdk we are interested in being called when there is input on the ! // editor connection socket. if (channel->ch_part[part].ch_inputHandler == 0) { ch_log(channel, "Registering part %s with fd %d", *************** *** 740,747 **** return NULL; } ! /* Get the server internet address and put into addr structure */ ! /* fill in the socket address structure and connect to server */ vim_memset((char *)&server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(port); --- 740,747 ---- return NULL; } ! // Get the server internet address and put into addr structure ! // fill in the socket address structure and connect to server vim_memset((char *)&server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(port); *************** *** 755,769 **** { char *p; ! /* When using host->h_addr_list[0] directly ubsan warns for it to not ! * be aligned. First copy the pointer to avoid that. */ memcpy(&p, &host->h_addr_list[0], sizeof(p)); memcpy((char *)&server.sin_addr, p, host->h_length); } ! /* On Mac and Solaris a zero timeout almost never works. At least wait ! * one millisecond. Let's do it for all systems, because we don't know why ! * this is needed. */ if (waittime == 0) waittime = 1; --- 755,769 ---- { char *p; ! // When using host->h_addr_list[0] directly ubsan warns for it to not ! // be aligned. First copy the pointer to avoid that. memcpy(&p, &host->h_addr_list[0], sizeof(p)); memcpy((char *)&server.sin_addr, p, host->h_length); } ! // On Mac and Solaris a zero timeout almost never works. At least wait ! // one millisecond. Let's do it for all systems, because we don't know why ! // this is needed. if (waittime == 0) waittime = 1; *************** *** 789,795 **** if (waittime >= 0) { ! /* Make connect() non-blocking. */ if ( #ifdef MSWIN ioctlsocket(sd, FIONBIO, &val) < 0 --- 789,795 ---- if (waittime >= 0) { ! // Make connect() non-blocking. if ( #ifdef MSWIN ioctlsocket(sd, FIONBIO, &val) < 0 *************** *** 807,818 **** } } ! /* Try connecting to the server. */ ch_log(channel, "Connecting to %s port %d", hostname, port); ret = connect(sd, (struct sockaddr *)&server, sizeof(server)); if (ret == 0) ! /* The connection could be established. */ break; SOCK_ERRNO; --- 807,818 ---- } } ! // Try connecting to the server. ch_log(channel, "Connecting to %s port %d", hostname, port); ret = connect(sd, (struct sockaddr *)&server, sizeof(server)); if (ret == 0) ! // The connection could be established. break; SOCK_ERRNO; *************** *** 831,842 **** return NULL; } ! /* Limit the waittime to 50 msec. If it doesn't work within this ! * time we close the socket and try creating it again. */ waitnow = waittime > 50 ? 50 : waittime; ! /* If connect() didn't finish then try using select() to wait for the ! * connection to be made. For Win32 always use select() to wait. */ #ifndef MSWIN if (errno != ECONNREFUSED) #endif --- 831,842 ---- return NULL; } ! // Limit the waittime to 50 msec. If it doesn't work within this ! // time we close the socket and try creating it again. waitnow = waittime > 50 ? 50 : waittime; ! // If connect() didn't finish then try using select() to wait for the ! // connection to be made. For Win32 always use select() to wait. #ifndef MSWIN if (errno != ECONNREFUSED) #endif *************** *** 876,883 **** } #ifdef MSWIN ! /* On Win32: select() is expected to work and wait for up to ! * "waitnow" msec for the socket to be open. */ if (FD_ISSET(sd, &wfds)) break; elapsed_msec = waitnow; --- 876,883 ---- } #ifdef MSWIN ! // On Win32: select() is expected to work and wait for up to ! // "waitnow" msec for the socket to be open. if (FD_ISSET(sd, &wfds)) break; elapsed_msec = waitnow; *************** *** 887,899 **** continue; } #else ! /* On Linux-like systems: See socket(7) for the behavior ! * After putting the socket in non-blocking mode, connect() will ! * return EINPROGRESS, select() will not wait (as if writing is ! * possible), need to use getsockopt() to check if the socket is ! * actually able to connect. ! * We detect a failure to connect when either read and write fds ! * are set. Use getsockopt() to find out what kind of failure. */ if (FD_ISSET(sd, &rfds) || FD_ISSET(sd, &wfds)) { ret = getsockopt(sd, --- 887,899 ---- continue; } #else ! // On Linux-like systems: See socket(7) for the behavior ! // After putting the socket in non-blocking mode, connect() will ! // return EINPROGRESS, select() will not wait (as if writing is ! // possible), need to use getsockopt() to check if the socket is ! // actually able to connect. ! // We detect a failure to connect when either read and write fds ! // are set. Use getsockopt() to find out what kind of failure. if (FD_ISSET(sd, &rfds) || FD_ISSET(sd, &wfds)) { ret = getsockopt(sd, *************** *** 917,923 **** } if (FD_ISSET(sd, &wfds) && so_error == 0) ! /* Did not detect an error, connection is established. */ break; gettimeofday(&end_tv, NULL); --- 917,923 ---- } if (FD_ISSET(sd, &wfds) && so_error == 0) ! // Did not detect an error, connection is established. break; gettimeofday(&end_tv, NULL); *************** *** 929,938 **** #ifndef MSWIN if (waittime > 1 && elapsed_msec < waittime) { ! /* The port isn't ready but we also didn't get an error. ! * This happens when the server didn't open the socket ! * yet. Select() may return early, wait until the remaining ! * "waitnow" and try again. */ waitnow -= elapsed_msec; waittime -= elapsed_msec; if (waitnow > 0) --- 929,938 ---- #ifndef MSWIN if (waittime > 1 && elapsed_msec < waittime) { ! // The port isn't ready but we also didn't get an error. ! // This happens when the server didn't open the socket ! // yet. Select() may return early, wait until the remaining ! // "waitnow" and try again. waitnow -= elapsed_msec; waittime -= elapsed_msec; if (waitnow > 0) *************** *** 944,958 **** if (!got_int) { if (waittime <= 0) ! /* give it one more try */ waittime = 1; continue; } ! /* we were interrupted, behave as if timed out */ } #endif ! /* We timed out. */ ch_error(channel, "Connection timed out"); sock_close(sd); channel_free(channel); --- 944,958 ---- if (!got_int) { if (waittime <= 0) ! // give it one more try waittime = 1; continue; } ! // we were interrupted, behave as if timed out } #endif ! // We timed out. ch_error(channel, "Connection timed out"); sock_close(sd); channel_free(channel); *************** *** 1115,1121 **** { buf_T *buf; ! /* writing output to a buffer. Default mode is NL. */ if (!(opt->jo_set & JO_OUT_MODE)) channel->ch_part[PART_OUT].ch_mode = MODE_NL; if (opt->jo_set & JO_OUT_BUF) --- 1115,1121 ---- { buf_T *buf; ! // writing output to a buffer. Default mode is NL. if (!(opt->jo_set & JO_OUT_MODE)) channel->ch_part[PART_OUT].ch_mode = MODE_NL; if (opt->jo_set & JO_OUT_BUF) *************** *** 1160,1166 **** { buf_T *buf; ! /* writing err to a buffer. Default mode is NL. */ if (!(opt->jo_set & JO_ERR_MODE)) channel->ch_part[PART_ERR].ch_mode = MODE_NL; if (opt->jo_io[PART_ERR] == JIO_OUT) --- 1160,1166 ---- { buf_T *buf; ! // writing err to a buffer. Default mode is NL. if (!(opt->jo_set & JO_ERR_MODE)) channel->ch_part[PART_ERR].ch_mode = MODE_NL; if (opt->jo_io[PART_ERR] == JIO_OUT) *************** *** 1226,1232 **** return NULL; } ! /* parse address */ p = vim_strchr(address, ':'); if (p == NULL) { --- 1226,1232 ---- return NULL; } ! // parse address p = vim_strchr(address, ':'); if (p == NULL) { *************** *** 1242,1248 **** return NULL; } ! /* parse options */ clear_job_options(&opt); opt.jo_mode = MODE_JSON; opt.jo_timeout = 2000; --- 1242,1248 ---- return NULL; } ! // parse options clear_job_options(&opt); opt.jo_mode = MODE_JSON; opt.jo_timeout = 2000; *************** *** 1277,1284 **** sock_close(*fd); else { ! /* When using a pty the same FD is set on multiple parts, only ! * close it when the last reference is closed. */ if ((part == PART_IN || channel->CH_IN_FD != *fd) && (part == PART_OUT || channel->CH_OUT_FD != *fd) && (part == PART_ERR || channel->CH_ERR_FD != *fd)) --- 1277,1284 ---- sock_close(*fd); else { ! // When using a pty the same FD is set on multiple parts, only ! // close it when the last reference is closed. if ((part == PART_IN || channel->CH_IN_FD != *fd) && (part == PART_OUT || channel->CH_OUT_FD != *fd) && (part == PART_ERR || channel->CH_ERR_FD != *fd)) *************** *** 1292,1298 **** } *fd = INVALID_FD; ! /* channel is closed, may want to end the job if it was the last */ channel->ch_to_be_closed &= ~(1U << part); } } --- 1292,1298 ---- } *fd = INVALID_FD; ! // channel is closed, may want to end the job if it was the last channel->ch_to_be_closed &= ~(1U << part); } } *************** *** 1305,1312 **** ch_close_part(channel, PART_IN); channel->CH_IN_FD = in; # if defined(UNIX) ! /* Do not end the job when all output channels are closed, wait until ! * the job ended. */ if (mch_isatty(in)) channel->ch_to_be_closed |= (1U << PART_IN); # endif --- 1305,1312 ---- ch_close_part(channel, PART_IN); channel->CH_IN_FD = in; # if defined(UNIX) ! // Do not end the job when all output channels are closed, wait until ! // the job ended. if (mch_isatty(in)) channel->ch_to_be_closed |= (1U << PART_IN); # endif *************** *** 1359,1366 **** { if (options->jo_in_top == 0 && !(options->jo_set & JO_IN_BOT)) { ! /* Special mode: send last-but-one line when appending a line ! * to the buffer. */ in_part->ch_bufref.br_buf->b_write_to_channel = TRUE; in_part->ch_buf_append = TRUE; in_part->ch_buf_top = --- 1359,1366 ---- { if (options->jo_in_top == 0 && !(options->jo_set & JO_IN_BOT)) { ! // Special mode: send last-but-one line when appending a line ! // to the buffer. in_part->ch_bufref.br_buf->b_write_to_channel = TRUE; in_part->ch_buf_append = TRUE; in_part->ch_buf_top = *************** *** 1413,1419 **** char_u *p; int i; ! /* Need to make a copy to be able to append a NL. */ if ((p = alloc(len + 2)) == NULL) return; memcpy((char *)p, (char *)line, len); --- 1413,1419 ---- char_u *p; int i; ! // Need to make a copy to be able to append a NL. if ((p = alloc(len + 2)) == NULL) return; memcpy((char *)p, (char *)line, len); *************** *** 1443,1457 **** chanpart_T *in_part = &channel->ch_part[PART_IN]; if (in_part->ch_fd == INVALID_FD) ! return FALSE; /* pipe was closed */ ! /* for testing: block every other attempt to write */ if (in_part->ch_block_write == 1) in_part->ch_block_write = -1; else if (in_part->ch_block_write == -1) in_part->ch_block_write = 1; ! /* TODO: Win32 implementation, probably using WaitForMultipleObjects() */ #ifndef MSWIN { # if defined(HAVE_SELECT) --- 1443,1457 ---- chanpart_T *in_part = &channel->ch_part[PART_IN]; if (in_part->ch_fd == INVALID_FD) ! return FALSE; // pipe was closed ! // for testing: block every other attempt to write if (in_part->ch_block_write == 1) in_part->ch_block_write = -1; else if (in_part->ch_block_write == -1) in_part->ch_block_write = 1; ! // TODO: Win32 implementation, probably using WaitForMultipleObjects() #ifndef MSWIN { # if defined(HAVE_SELECT) *************** *** 1514,1523 **** int written = 0; if (buf == NULL || in_part->ch_buf_append) ! return; /* no buffer or using appending */ if (!bufref_valid(&in_part->ch_bufref) || buf->b_ml.ml_mfp == NULL) { ! /* buffer was wiped out or unloaded */ ch_log(channel, "input buffer has been wiped out"); in_part->ch_bufref.br_buf = NULL; return; --- 1514,1523 ---- int written = 0; if (buf == NULL || in_part->ch_buf_append) ! return; // no buffer or using appending if (!bufref_valid(&in_part->ch_bufref) || buf->b_ml.ml_mfp == NULL) { ! // buffer was wiped out or unloaded ch_log(channel, "input buffer has been wiped out"); in_part->ch_bufref.br_buf = NULL; return; *************** *** 1541,1556 **** if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot) { #if defined(FEAT_TERMINAL) ! /* Send CTRL-D or "eof_chars" to close stdin on MS-Windows. */ if (channel->ch_job != NULL) term_send_eof(channel); #endif ! /* Writing is done, no longer need the buffer. */ in_part->ch_bufref.br_buf = NULL; ch_log(channel, "Finished writing all lines to channel"); ! /* Close the pipe/socket, so that the other side gets EOF. */ ch_close_part(channel, PART_IN); } else --- 1541,1556 ---- if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot) { #if defined(FEAT_TERMINAL) ! // Send CTRL-D or "eof_chars" to close stdin on MS-Windows. if (channel->ch_job != NULL) term_send_eof(channel); #endif ! // Writing is done, no longer need the buffer. in_part->ch_bufref.br_buf = NULL; ch_log(channel, "Finished writing all lines to channel"); ! // Close the pipe/socket, so that the other side gets EOF. ch_close_part(channel, PART_IN); } else *************** *** 1621,1628 **** channel_T *channel; int found_one = FALSE; ! /* There could be more than one channel for the buffer, loop over all of ! * them. */ for (channel = first_channel; channel != NULL; channel = channel->ch_next) { chanpart_T *in_part = &channel->ch_part[PART_IN]; --- 1621,1628 ---- channel_T *channel; int found_one = FALSE; ! // There could be more than one channel for the buffer, loop over all of ! // them. for (channel = first_channel; channel != NULL; channel = channel->ch_next) { chanpart_T *in_part = &channel->ch_part[PART_IN]; *************** *** 1632,1638 **** if (in_part->ch_bufref.br_buf == buf && in_part->ch_buf_append) { if (in_part->ch_fd == INVALID_FD) ! continue; /* pipe was closed */ found_one = TRUE; for (lnum = in_part->ch_buf_bot; lnum < buf->b_ml.ml_line_count; ++lnum) --- 1632,1638 ---- if (in_part->ch_bufref.br_buf == buf && in_part->ch_buf_append) { if (in_part->ch_fd == INVALID_FD) ! continue; // pipe was closed found_one = TRUE; for (lnum = in_part->ch_buf_bot; lnum < buf->b_ml.ml_line_count; ++lnum) *************** *** 1723,1729 **** return NULL; if (outlen != NULL) *outlen += node->rq_buflen; ! /* dispose of the node but keep the buffer */ p = node->rq_buffer; head->rq_next = node->rq_next; if (node->rq_next == NULL) --- 1723,1729 ---- return NULL; if (outlen != NULL) *outlen += node->rq_buflen; ! // dispose of the node but keep the buffer p = node->rq_buffer; head->rq_next = node->rq_next; if (node->rq_next == NULL) *************** *** 1853,1859 **** p = newbuf = alloc(len + 1); if (newbuf == NULL) ! return FAIL; /* out of memory */ mch_memmove(p, node->rq_buffer, node->rq_buflen); p += node->rq_buflen; vim_free(node->rq_buffer); --- 1853,1859 ---- p = newbuf = alloc(len + 1); if (newbuf == NULL) ! return FAIL; // out of memory mch_memmove(p, node->rq_buffer, node->rq_buflen); p += node->rq_buflen; vim_free(node->rq_buffer); *************** *** 1868,1874 **** *p = NUL; node->rq_buflen = (long_u)(p - newbuf); ! /* dispose of the collapsed nodes and their buffers */ for (n = node->rq_next; n != last_node; ) { n = n->rq_next; --- 1868,1874 ---- *p = NUL; node->rq_buflen = (long_u)(p - newbuf); ! // dispose of the collapsed nodes and their buffers for (n = node->rq_next; n != last_node; ) { n = n->rq_next; *************** *** 1899,1917 **** node = ALLOC_ONE(readq_T); if (node == NULL) ! return FAIL; /* out of memory */ ! /* A NUL is added at the end, because netbeans code expects that. ! * Otherwise a NUL may appear inside the text. */ node->rq_buffer = alloc(len + 1); if (node->rq_buffer == NULL) { vim_free(node); ! return FAIL; /* out of memory */ } if (channel->ch_part[part].ch_mode == MODE_NL) { ! /* Drop any CR before a NL. */ p = node->rq_buffer; for (i = 0; i < len; ++i) if (buf[i] != CAR || i + 1 >= len || buf[i + 1] != NL) --- 1899,1917 ---- node = ALLOC_ONE(readq_T); if (node == NULL) ! return FAIL; // out of memory ! // A NUL is added at the end, because netbeans code expects that. ! // Otherwise a NUL may appear inside the text. node->rq_buffer = alloc(len + 1); if (node->rq_buffer == NULL) { vim_free(node); ! return FAIL; // out of memory } if (channel->ch_part[part].ch_mode == MODE_NL) { ! // Drop any CR before a NL. p = node->rq_buffer; for (i = 0; i < len; ++i) if (buf[i] != CAR || i + 1 >= len || buf[i + 1] != NL) *************** *** 1979,1985 **** keeplen = reader->js_end - reader->js_buf; if (keeplen > 0) { ! /* Prepend unused text. */ addlen = (int)STRLEN(next); p = alloc(keeplen + addlen + 1); if (p == NULL) --- 1979,1985 ---- keeplen = reader->js_end - reader->js_buf; if (keeplen > 0) { ! // Prepend unused text. addlen = (int)STRLEN(next); p = alloc(keeplen + addlen + 1); if (p == NULL) *************** *** 2023,2040 **** reader.js_cookie = channel; reader.js_cookie_arg = part; ! /* When a message is incomplete we wait for a short while for more to ! * arrive. After the delay drop the input, otherwise a truncated string ! * or list will make us hang. ! * Do not generate error messages, they will be written in a channel log. */ ++emsg_silent; status = json_decode(&reader, &listtv, chanpart->ch_mode == MODE_JS ? JSON_JS : 0); --emsg_silent; if (status == OK) { ! /* Only accept the response when it is a list with at least two ! * items. */ if (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2) { if (listtv.v_type != VAR_LIST) --- 2023,2040 ---- reader.js_cookie = channel; reader.js_cookie_arg = part; ! // When a message is incomplete we wait for a short while for more to ! // arrive. After the delay drop the input, otherwise a truncated string ! // or list will make us hang. ! // Do not generate error messages, they will be written in a channel log. ++emsg_silent; status = json_decode(&reader, &listtv, chanpart->ch_mode == MODE_JS ? JSON_JS : 0); --emsg_silent; if (status == OK) { ! // Only accept the response when it is a list with at least two ! // items. if (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2) { if (listtv.v_type != VAR_LIST) *************** *** 2081,2088 **** if (chanpart->ch_wait_len < buflen) { ! /* First time encountering incomplete message or after receiving ! * more (but still incomplete): set a deadline of 100 msec. */ ch_log(channel, "Incomplete message (%d bytes) - wait 100 msec for more", (int)buflen); --- 2081,2088 ---- if (chanpart->ch_wait_len < buflen) { ! // First time encountering incomplete message or after receiving ! // more (but still incomplete): set a deadline of 100 msec. ch_log(channel, "Incomplete message (%d bytes) - wait 100 msec for more", (int)buflen); *************** *** 2137,2143 **** } else if (reader.js_buf[reader.js_used] != NUL) { ! /* Put the unread part back into the channel. */ channel_save(channel, part, reader.js_buf + reader.js_used, (int)(reader.js_end - reader.js_buf) - reader.js_used, TRUE, NULL); --- 2137,2143 ---- } else if (reader.js_buf[reader.js_used] != NUL) { ! // Put the unread part back into the channel. channel_save(channel, part, reader.js_buf + reader.js_used, (int)(reader.js_end - reader.js_buf) - reader.js_used, TRUE, NULL); *************** *** 2296,2305 **** jsonq_T *newitem; if (head->jq_prev != NULL && head->jq_prev->jq_no_callback) ! /* last item was pushed back, append to the end */ item = NULL; else while (item != NULL && item->jq_no_callback) ! /* append after the last item that was pushed back */ item = item->jq_next; newitem = ALLOC_ONE(jsonq_T); --- 2296,2305 ---- jsonq_T *newitem; if (head->jq_prev != NULL && head->jq_prev->jq_no_callback) ! // last item was pushed back, append to the end item = NULL; else while (item != NULL && item->jq_no_callback) ! // append after the last item that was pushed back item = item->jq_next; newitem = ALLOC_ONE(jsonq_T); *************** *** 2319,2325 **** *newitem->jq_value = *rettv; if (item == NULL) { ! /* append to the end */ newitem->jq_prev = head->jq_prev; head->jq_prev = newitem; newitem->jq_next = NULL; --- 2319,2325 ---- *newitem->jq_value = *rettv; if (item == NULL) { ! // append to the end newitem->jq_prev = head->jq_prev; head->jq_prev = newitem; newitem->jq_next = NULL; *************** *** 2330,2336 **** } else { ! /* append after "item" */ newitem->jq_prev = item; newitem->jq_next = item->jq_next; item->jq_next = newitem; --- 2330,2336 ---- } else { ! // append after "item" newitem->jq_prev = item; newitem->jq_next = item->jq_next; item->jq_next = newitem; *************** *** 2390,2396 **** vim_memset(&ea, 0, sizeof(ea)); ea.arg = arg; ea.addr_count = 0; ! ea.forceit = TRUE; /* no mapping */ ex_normal(&ea); } else if (STRCMP(cmd, "redraw") == 0) --- 2390,2396 ---- vim_memset(&ea, 0, sizeof(ea)); ea.arg = arg; ea.addr_count = 0; ! ea.forceit = TRUE; // no mapping ex_normal(&ea); } else if (STRCMP(cmd, "redraw") == 0) *************** *** 2430,2436 **** typval_T err_tv; char_u *json = NULL; ! /* Don't pollute the display with errors. */ ++emsg_skip; if (!is_call) { --- 2430,2436 ---- typval_T err_tv; char_u *json = NULL; ! // Don't pollute the display with errors. ++emsg_skip; if (!is_call) { *************** *** 2452,2459 **** json = json_encode_nr_expr(id, tv, options | JSON_NL); if (tv == NULL || (json != NULL && *json == NUL)) { ! /* If evaluation failed or the result can't be encoded ! * then return the string "ERROR". */ vim_free(json); err_tv.v_type = VAR_STRING; err_tv.vval.v_string = (char_u *)"ERROR"; --- 2452,2459 ---- json = json_encode_nr_expr(id, tv, options | JSON_NL); if (tv == NULL || (json != NULL && *json == NUL)) { ! // If evaluation failed or the result can't be encoded ! // then return the string "ERROR". vim_free(json); err_tv.v_type = VAR_STRING; err_tv.vval.v_string = (char_u *)"ERROR"; *************** *** 2494,2501 **** { ch_log(channel, "Invoking one-time callback %s", (char *)item->cq_callback.cb_name); ! /* Remove the item from the list first, if the callback ! * invokes ch_close() the list will be cleared. */ remove_cb_node(cbhead, item); invoke_callback(channel, &item->cq_callback, argv); free_callback(&item->cq_callback); --- 2494,2501 ---- { ch_log(channel, "Invoking one-time callback %s", (char *)item->cq_callback.cb_name); ! // Remove the item from the list first, if the callback ! // invokes ch_close() the list will be cleared. remove_cb_node(cbhead, item); invoke_callback(channel, &item->cq_callback, argv); free_callback(&item->cq_callback); *************** *** 2524,2552 **** return; } ! /* If the buffer is also used as input insert above the last ! * line. Don't write these lines. */ if (save_write_to) { --lnum; buffer->b_write_to_channel = FALSE; } ! /* Append to the buffer */ ch_log(channel, "appending line %d to buffer", (int)lnum + 1 - empty); buffer->b_p_ma = TRUE; ! /* Save curbuf/curwin/curtab and make "buffer" the current buffer. */ switch_to_win_for_buf(buffer, &save_curwin, &save_curtab, &save_curbuf); u_sync(TRUE); ! /* ignore undo failure, undo is not very useful here */ vim_ignored = u_save(lnum - empty, lnum + 1); if (empty) { ! /* The buffer is empty, replace the first (dummy) line. */ ml_replace(lnum, msg, TRUE); lnum = 0; } --- 2524,2552 ---- return; } ! // If the buffer is also used as input insert above the last ! // line. Don't write these lines. if (save_write_to) { --lnum; buffer->b_write_to_channel = FALSE; } ! // Append to the buffer ch_log(channel, "appending line %d to buffer", (int)lnum + 1 - empty); buffer->b_p_ma = TRUE; ! // Save curbuf/curwin/curtab and make "buffer" the current buffer. switch_to_win_for_buf(buffer, &save_curwin, &save_curtab, &save_curbuf); u_sync(TRUE); ! // ignore undo failure, undo is not very useful here vim_ignored = u_save(lnum - empty, lnum + 1); if (empty) { ! // The buffer is empty, replace the first (dummy) line. ml_replace(lnum, msg, TRUE); lnum = 0; } *************** *** 2554,2560 **** ml_append(lnum, msg, 0, FALSE); appended_lines_mark(lnum, 1L); ! /* Restore curbuf/curwin/curtab */ restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); if (ch_part->ch_nomodifiable) --- 2554,2560 ---- ml_append(lnum, msg, 0, FALSE); appended_lines_mark(lnum, 1L); ! // Restore curbuf/curwin/curtab restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); if (ch_part->ch_nomodifiable) *************** *** 2598,2605 **** { channel_T *ch; ! /* Find channels reading from this buffer and adjust their ! * next-to-read line number. */ buffer->b_write_to_channel = TRUE; for (ch = first_channel; ch != NULL; ch = ch->ch_next) { --- 2598,2605 ---- { channel_T *ch; ! // Find channels reading from this buffer and adjust their ! // next-to-read line number. buffer->b_write_to_channel = TRUE; for (ch = first_channel; ch != NULL; ch = ch->ch_next) { *************** *** 2644,2653 **** char_u *p; if (channel->ch_nb_close_cb != NULL) ! /* this channel is handled elsewhere (netbeans) */ return FALSE; ! /* Use a message-specific callback, part callback or channel callback */ for (cbitem = cbhead->cq_next; cbitem != NULL; cbitem = cbitem->cq_next) if (cbitem->cq_seq_nr == 0) break; --- 2644,2653 ---- char_u *p; if (channel->ch_nb_close_cb != NULL) ! // this channel is handled elsewhere (netbeans) return FALSE; ! // Use a message-specific callback, part callback or channel callback for (cbitem = cbhead->cq_next; cbitem != NULL; cbitem = cbitem->cq_next) if (cbitem->cq_seq_nr == 0) break; *************** *** 2662,2668 **** if (buffer != NULL && (!bufref_valid(&ch_part->ch_bufref) || buffer->b_ml.ml_mfp == NULL)) { ! /* buffer was wiped out or unloaded */ ch_log(channel, "%s buffer has been wiped out", part_names[part]); ch_part->ch_bufref.br_buf = NULL; buffer = NULL; --- 2662,2668 ---- if (buffer != NULL && (!bufref_valid(&ch_part->ch_bufref) || buffer->b_ml.ml_mfp == NULL)) { ! // buffer was wiped out or unloaded ch_log(channel, "%s buffer has been wiped out", part_names[part]); ch_part->ch_bufref.br_buf = NULL; buffer = NULL; *************** *** 2673,2682 **** listitem_T *item; int argc = 0; ! /* Get any json message in the queue. */ if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL) { ! /* Parse readahead, return when there is still no message. */ channel_parse_json(channel, part); if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL) return FALSE; --- 2673,2682 ---- listitem_T *item; int argc = 0; ! // Get any json message in the queue. if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL) { ! // Parse readahead, return when there is still no message. channel_parse_json(channel, part); if (channel_get_json(channel, part, -1, FALSE, &listtv) == FAIL) return FALSE; *************** *** 2691,2697 **** if (argv[0].v_type == VAR_STRING) { ! /* ["cmd", arg] or ["cmd", arg, arg] or ["cmd", arg, arg, arg] */ channel_exe_cmd(channel, part, argv); free_tv(listtv); return TRUE; --- 2691,2697 ---- if (argv[0].v_type == VAR_STRING) { ! // ["cmd", arg] or ["cmd", arg, arg] or ["cmd", arg, arg, arg] channel_exe_cmd(channel, part, argv); free_tv(listtv); return TRUE; *************** *** 2708,2723 **** } else if (channel_peek(channel, part) == NULL) { ! /* nothing to read on RAW or NL channel */ return FALSE; } else { ! /* If there is no callback or buffer drop the message. */ if (callback == NULL && buffer == NULL) { ! /* If there is a close callback it may use ch_read() to get the ! * messages. */ if (channel->ch_close_cb.cb_name == NULL && !channel->ch_drop_never) drop_messages(channel, part); return FALSE; --- 2708,2723 ---- } else if (channel_peek(channel, part) == NULL) { ! // nothing to read on RAW or NL channel return FALSE; } else { ! // If there is no callback or buffer drop the message. if (callback == NULL && buffer == NULL) { ! // If there is a close callback it may use ch_read() to get the ! // messages. if (channel->ch_close_cb.cb_name == NULL && !channel->ch_drop_never) drop_messages(channel, part); return FALSE; *************** *** 2729,2736 **** char_u *buf; readq_T *node; ! /* See if we have a message ending in NL in the first buffer. If ! * not try to concatenate the first and the second buffer. */ while (TRUE) { node = channel_peek(channel, part); --- 2729,2736 ---- char_u *buf; readq_T *node; ! // See if we have a message ending in NL in the first buffer. If ! // not try to concatenate the first and the second buffer. while (TRUE) { node = channel_peek(channel, part); *************** *** 2741,2747 **** { if (ch_part->ch_fd == INVALID_FD && node->rq_buflen > 0) break; ! return FALSE; /* incomplete message */ } } buf = node->rq_buffer; --- 2741,2747 ---- { if (ch_part->ch_fd == INVALID_FD && node->rq_buflen > 0) break; ! return FALSE; // incomplete message } } buf = node->rq_buffer; *************** *** 2765,2786 **** } else { ! /* Copy the message into allocated memory (excluding the NL) ! * and remove it from the buffer (including the NL). */ msg = vim_strnsave(buf, (int)(nl - buf)); channel_consume(channel, part, (int)(nl - buf) + 1); } } else { ! /* For a raw channel we don't know where the message ends, just ! * get everything we have. ! * Convert NUL to NL, the internal representation. */ msg = channel_get_all(channel, part, NULL); } if (msg == NULL) ! return FALSE; /* out of memory (and avoids Coverity warning) */ argv[1].v_type = VAR_STRING; argv[1].vval.v_string = msg; --- 2765,2786 ---- } else { ! // Copy the message into allocated memory (excluding the NL) ! // and remove it from the buffer (including the NL). msg = vim_strnsave(buf, (int)(nl - buf)); channel_consume(channel, part, (int)(nl - buf) + 1); } } else { ! // For a raw channel we don't know where the message ends, just ! // get everything we have. ! // Convert NUL to NL, the internal representation. msg = channel_get_all(channel, part, NULL); } if (msg == NULL) ! return FALSE; // out of memory (and avoids Coverity warning) argv[1].v_type = VAR_STRING; argv[1].vval.v_string = msg; *************** *** 2790,2796 **** { int done = FALSE; ! /* JSON or JS mode: invoke the one-time callback with the matching nr */ for (cbitem = cbhead->cq_next; cbitem != NULL; cbitem = cbitem->cq_next) if (cbitem->cq_seq_nr == seq_nr) { --- 2790,2796 ---- { int done = FALSE; ! // JSON or JS mode: invoke the one-time callback with the matching nr for (cbitem = cbhead->cq_next; cbitem != NULL; cbitem = cbitem->cq_next) if (cbitem->cq_seq_nr == seq_nr) { *************** *** 2802,2808 **** { if (channel->ch_drop_never) { ! /* message must be read with ch_read() */ channel_push_json(channel, part, listtv); listtv = NULL; } --- 2802,2808 ---- { if (channel->ch_drop_never) { ! // message must be read with ch_read() channel_push_json(channel, part, listtv); listtv = NULL; } *************** *** 2816,2822 **** if (buffer != NULL) { if (msg == NULL) ! /* JSON or JS mode: re-encode the message. */ msg = json_encode(listtv, ch_mode); if (msg != NULL) { --- 2816,2822 ---- if (buffer != NULL) { if (msg == NULL) ! // JSON or JS mode: re-encode the message. msg = json_encode(listtv, ch_mode); if (msg != NULL) { *************** *** 2835,2841 **** invoke_one_time_callback(channel, cbhead, cbitem, argv); else { ! /* invoke the channel callback */ ch_log(channel, "Invoking channel callback %s", (char *)callback->cb_name); invoke_callback(channel, callback, argv); --- 2835,2841 ---- invoke_one_time_callback(channel, cbhead, cbitem, argv); else { ! // invoke the channel callback ch_log(channel, "Invoking channel callback %s", (char *)callback->cb_name); invoke_callback(channel, callback, argv); *************** *** 2947,2953 **** channel_part_info(channel_T *channel, dict_T *dict, char *name, ch_part_T part) { chanpart_T *chanpart = &channel->ch_part[part]; ! char namebuf[20]; /* longest is "sock_timeout" */ size_t tail; char *status; char *s = ""; --- 2947,2953 ---- channel_part_info(channel_T *channel, dict_T *dict, char *name, ch_part_T part) { chanpart_T *chanpart = &channel->ch_part[part]; ! char namebuf[20]; // longest is "sock_timeout" size_t tail; char *status; char *s = ""; *************** *** 3035,3041 **** { ch_part_T part; ! /* Invoke callbacks and flush buffers before the close callback. */ if (channel->ch_close_cb.cb_name != NULL) ch_log(channel, "Invoking callbacks and flushing buffers before closing"); --- 3035,3041 ---- { ch_part_T part; ! // Invoke callbacks and flush buffers before the close callback. if (channel->ch_close_cb.cb_name != NULL) ch_log(channel, "Invoking callbacks and flushing buffers before closing"); *************** *** 3044,3051 **** if (channel->ch_close_cb.cb_name != NULL || channel->ch_part[part].ch_bufref.br_buf != NULL) { ! /* Increment the refcount to avoid the channel being freed ! * halfway. */ ++channel->ch_refcount; if (channel->ch_close_cb.cb_name == NULL) ch_log(channel, "flushing %s buffers before closing", --- 3044,3051 ---- if (channel->ch_close_cb.cb_name != NULL || channel->ch_part[part].ch_bufref.br_buf != NULL) { ! // Increment the refcount to avoid the channel being freed ! // halfway. ++channel->ch_refcount; if (channel->ch_close_cb.cb_name == NULL) ch_log(channel, "flushing %s buffers before closing", *************** *** 3061,3068 **** typval_T argv[1]; typval_T rettv; ! /* Increment the refcount to avoid the channel being freed ! * halfway. */ ++channel->ch_refcount; ch_log(channel, "Invoking close callback %s", (char *)channel->ch_close_cb.cb_name); --- 3061,3068 ---- typval_T argv[1]; typval_T rettv; ! // Increment the refcount to avoid the channel being freed ! // halfway. ++channel->ch_refcount; ch_log(channel, "Invoking close callback %s", (char *)channel->ch_close_cb.cb_name); *************** *** 3072,3078 **** clear_tv(&rettv); channel_need_redraw = TRUE; ! /* the callback is only called once */ free_callback(&channel->ch_close_cb); if (channel_need_redraw) --- 3072,3078 ---- clear_tv(&rettv); channel_need_redraw = TRUE; ! // the callback is only called once free_callback(&channel->ch_close_cb); if (channel_need_redraw) *************** *** 3082,3088 **** } if (!channel->ch_drop_never) ! /* any remaining messages are useless now */ for (part = PART_SOCK; part < PART_IN; ++part) drop_messages(channel, part); --- 3082,3088 ---- } if (!channel->ch_drop_never) ! // any remaining messages are useless now for (part = PART_SOCK; part < PART_IN; ++part) drop_messages(channel, part); *************** *** 3183,3192 **** #endif ! /* Sent when the netbeans channel is found closed when reading. */ #define DETACH_MSG_RAW "DETACH\n" ! /* Buffer size for reading incoming messages. */ #define MAXMSGSIZE 4096 #if defined(HAVE_SELECT) --- 3183,3192 ---- #endif ! // Sent when the netbeans channel is found closed when reading. #define DETACH_MSG_RAW "DETACH\n" ! // Buffer size for reading incoming messages. #define MAXMSGSIZE 4096 #if defined(HAVE_SELECT) *************** *** 3270,3276 **** DWORD deadline = GetTickCount() + timeout; int delay = 1; ! /* reading from a pipe, not a socket */ while (TRUE) { int r = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL); --- 3270,3276 ---- DWORD deadline = GetTickCount() + timeout; int delay = 1; ! // reading from a pipe, not a socket while (TRUE) { int r = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL); *************** *** 3286,3299 **** else if (r == 0) return CW_ERROR; ! /* perhaps write some buffer lines */ channel_write_any_lines(); sleep_time = deadline - GetTickCount(); if (sleep_time <= 0) break; ! /* Wait for a little while. Very short at first, up to 10 msec ! * after looping a few times. */ if (sleep_time > delay) sleep_time = delay; Sleep(sleep_time); --- 3286,3299 ---- else if (r == 0) return CW_ERROR; ! // perhaps write some buffer lines channel_write_any_lines(); sleep_time = deadline - GetTickCount(); if (sleep_time <= 0) break; ! // Wait for a little while. Very short at first, up to 10 msec ! // after looping a few times. if (sleep_time > delay) sleep_time = delay; Sleep(sleep_time); *************** *** 3319,3326 **** FD_ZERO(&rfds); FD_SET((int)fd, &rfds); ! /* Write lines to a pipe when a pipe can be written to. Need to ! * set this every time, some buffers may be done. */ maxfd = (int)fd + 1; FD_ZERO(&wfds); maxfd = channel_fill_wfds(maxfd, &wfds); --- 3319,3326 ---- FD_ZERO(&rfds); FD_SET((int)fd, &rfds); ! // Write lines to a pipe when a pipe can be written to. Need to ! // set this every time, some buffers may be done. maxfd = (int)fd + 1; FD_ZERO(&wfds); maxfd = channel_fill_wfds(maxfd, &wfds); *************** *** 3370,3399 **** char msg[] = "%s(): Read %s from ch_part[%d], closing"; if (is_err) ! /* Do not call emsg(), most likely the other end just exited. */ ch_error(channel, msg, func, "error", part); else ch_log(channel, msg, func, "EOF", part); ! /* Queue a "DETACH" netbeans message in the command queue in order to ! * terminate the netbeans session later. Do not end the session here ! * directly as we may be running in the context of a call to ! * netbeans_parse_messages(): ! * netbeans_parse_messages ! * -> autocmd triggered while processing the netbeans cmd ! * -> ui_breakcheck ! * -> gui event loop or select loop ! * -> channel_read() ! * Only send "DETACH" for a netbeans channel. ! */ if (channel->ch_nb_close_cb != NULL) channel_save(channel, PART_SOCK, (char_u *)DETACH_MSG_RAW, (int)STRLEN(DETACH_MSG_RAW), FALSE, "PUT "); ! /* When reading is not possible close this part of the channel. Don't ! * close the channel yet, there may be something to read on another part. ! * When stdout and stderr use the same FD we get the error only on one of ! * them, also close the other. */ if (part == PART_OUT || part == PART_ERR) { ch_part_T other = part == PART_OUT ? PART_ERR : PART_OUT; --- 3370,3398 ---- char msg[] = "%s(): Read %s from ch_part[%d], closing"; if (is_err) ! // Do not call emsg(), most likely the other end just exited. ch_error(channel, msg, func, "error", part); else ch_log(channel, msg, func, "EOF", part); ! // Queue a "DETACH" netbeans message in the command queue in order to ! // terminate the netbeans session later. Do not end the session here ! // directly as we may be running in the context of a call to ! // netbeans_parse_messages(): ! // netbeans_parse_messages ! // -> autocmd triggered while processing the netbeans cmd ! // -> ui_breakcheck ! // -> gui event loop or select loop ! // -> channel_read() ! // Only send "DETACH" for a netbeans channel. if (channel->ch_nb_close_cb != NULL) channel_save(channel, PART_SOCK, (char_u *)DETACH_MSG_RAW, (int)STRLEN(DETACH_MSG_RAW), FALSE, "PUT "); ! // When reading is not possible close this part of the channel. Don't ! // close the channel yet, there may be something to read on another part. ! // When stdout and stderr use the same FD we get the error only on one of ! // them, also close the other. if (part == PART_OUT || part == PART_ERR) { ch_part_T other = part == PART_OUT ? PART_ERR : PART_OUT; *************** *** 3404,3410 **** ch_close_part(channel, part); #ifdef FEAT_GUI ! /* Stop listening to GUI events right away. */ channel_gui_unregister_one(channel, part); #endif } --- 3403,3409 ---- ch_close_part(channel, part); #ifdef FEAT_GUI ! // Stop listening to GUI events right away. channel_gui_unregister_one(channel, part); #endif } *************** *** 3441,3457 **** } use_socket = fd == channel->CH_SOCK_FD; ! /* Allocate a buffer to read into. */ if (buf == NULL) { buf = alloc(MAXMSGSIZE); if (buf == NULL) ! return; /* out of memory! */ } ! /* Keep on reading for as long as there is something to read. ! * Use select() or poll() to avoid blocking on a message that is exactly ! * MAXMSGSIZE long. */ for (;;) { if (channel_wait(channel, fd, 0) != CW_READY) --- 3440,3456 ---- } use_socket = fd == channel->CH_SOCK_FD; ! // Allocate a buffer to read into. if (buf == NULL) { buf = alloc(MAXMSGSIZE); if (buf == NULL) ! return; // out of memory! } ! // Keep on reading for as long as there is something to read. ! // Use select() or poll() to avoid blocking on a message that is exactly ! // MAXMSGSIZE long. for (;;) { if (channel_wait(channel, fd, 0) != CW_READY) *************** *** 3461,3476 **** else len = fd_read(fd, (char *)buf, MAXMSGSIZE); if (len <= 0) ! break; /* error or nothing more to read */ ! /* Store the read message in the queue. */ channel_save(channel, part, buf, len, FALSE, "RECV "); readlen += len; if (len < MAXMSGSIZE) ! break; /* did read everything that's available */ } ! /* Reading a disconnection (readlen == 0), or an error. */ if (readlen <= 0) { if (!channel->ch_keep_open) --- 3460,3475 ---- else len = fd_read(fd, (char *)buf, MAXMSGSIZE); if (len <= 0) ! break; // error or nothing more to read ! // Store the read message in the queue. channel_save(channel, part, buf, len, FALSE, "RECV "); readlen += len; if (len < MAXMSGSIZE) ! break; // did read everything that's available } ! // Reading a disconnection (readlen == 0), or an error. if (readlen <= 0) { if (!channel->ch_keep_open) *************** *** 3478,3484 **** } #if defined(CH_HAS_GUI) && defined(FEAT_GUI_GTK) else if (CH_HAS_GUI && gtk_main_level() > 0) ! /* signal the main loop that there is something to read */ gtk_main_quit(); #endif } --- 3477,3483 ---- } #if defined(CH_HAS_GUI) && defined(FEAT_GUI_GTK) else if (CH_HAS_GUI && gtk_main_level() > 0) ! // signal the main loop that there is something to read gtk_main_quit(); #endif } *************** *** 3512,3528 **** { if (mode == MODE_RAW || (mode == MODE_NL && channel_first_nl(node) != NULL)) ! /* got a complete message */ break; if (channel_collapse(channel, part, mode == MODE_NL) == OK) continue; ! /* If not blocking or nothing more is coming then return what we ! * have. */ if (raw || fd == INVALID_FD) break; } ! /* Wait for up to the channel timeout. */ if (fd == INVALID_FD) return NULL; if (channel_wait(channel, fd, timeout) != CW_READY) --- 3511,3527 ---- { if (mode == MODE_RAW || (mode == MODE_NL && channel_first_nl(node) != NULL)) ! // got a complete message break; if (channel_collapse(channel, part, mode == MODE_NL) == OK) continue; ! // If not blocking or nothing more is coming then return what we ! // have. if (raw || fd == INVALID_FD) break; } ! // Wait for up to the channel timeout. if (fd == INVALID_FD) return NULL; if (channel_wait(channel, fd, timeout) != CW_READY) *************** *** 3533,3539 **** channel_read(channel, part, "channel_read_block"); } ! /* We have a complete message now. */ if (mode == MODE_RAW || outlen != NULL) { msg = channel_get_all(channel, part, outlen); --- 3532,3538 ---- channel_read(channel, part, "channel_read_block"); } ! // We have a complete message now. if (mode == MODE_RAW || outlen != NULL) { msg = channel_get_all(channel, part, outlen); *************** *** 3545,3570 **** buf = node->rq_buffer; nl = channel_first_nl(node); ! /* Convert NUL to NL, the internal representation. */ for (p = buf; (nl == NULL || p < nl) && p < buf + node->rq_buflen; ++p) if (*p == NUL) *p = NL; if (nl == NULL) { ! /* must be a closed channel with missing NL */ msg = channel_get(channel, part, NULL); } else if (nl + 1 == buf + node->rq_buflen) { ! /* get the whole buffer */ msg = channel_get(channel, part, NULL); *nl = NUL; } else { ! /* Copy the message into allocated memory and remove it from the ! * buffer. */ msg = vim_strnsave(buf, (int)(nl - buf)); channel_consume(channel, part, (int)(nl - buf) + 1); } --- 3544,3569 ---- buf = node->rq_buffer; nl = channel_first_nl(node); ! // Convert NUL to NL, the internal representation. for (p = buf; (nl == NULL || p < nl) && p < buf + node->rq_buflen; ++p) if (*p == NUL) *p = NL; if (nl == NULL) { ! // must be a closed channel with missing NL msg = channel_get(channel, part, NULL); } else if (nl + 1 == buf + node->rq_buflen) { ! // get the whole buffer msg = channel_get(channel, part, NULL); *nl = NUL; } else { ! // Copy the message into allocated memory and remove it from the ! // buffer. msg = vim_strnsave(buf, (int)(nl - buf)); channel_consume(channel, part, (int)(nl - buf) + 1); } *************** *** 3627,3639 **** if (!more) { ! /* Handle any other messages in the queue. If done some more ! * messages may have arrived. */ if (channel_parse_messages()) continue; ! /* Wait for up to the timeout. If there was an incomplete message ! * use the deadline for that. */ timeout = timeout_arg; if (chanpart->ch_wait_len > 0) { --- 3626,3638 ---- if (!more) { ! // Handle any other messages in the queue. If done some more ! // messages may have arrived. if (channel_parse_messages()) continue; ! // Wait for up to the timeout. If there was an incomplete message ! // use the deadline for that. timeout = timeout_arg; if (chanpart->ch_wait_len > 0) { *************** *** 3653,3660 **** #endif if (timeout < 0) { ! /* Something went wrong, channel_parse_json() didn't ! * discard message. Cancel waiting. */ chanpart->ch_wait_len = 0; timeout = timeout_arg; } --- 3652,3659 ---- #endif if (timeout < 0) { ! // Something went wrong, channel_parse_json() didn't ! // discard message. Cancel waiting. chanpart->ch_wait_len = 0; timeout = timeout_arg; } *************** *** 3737,3743 **** int id = -1; typval_T *listtv = NULL; ! /* return an empty string by default */ rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; --- 3736,3742 ---- int id = -1; typval_T *listtv = NULL; ! // return an empty string by default rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; *************** *** 3824,3830 **** if (only_keep_open && !channel->ch_keep_open) continue; ! /* check the socket and pipes */ for (part = PART_SOCK; part < PART_IN; ++part) { fd = channel->ch_part[part].ch_fd; --- 3823,3829 ---- if (only_keep_open && !channel->ch_keep_open) continue; ! // check the socket and pipes for (part = PART_SOCK; part < PART_IN; ++part) { fd = channel->ch_part[part].ch_fd; *************** *** 3933,3939 **** if (wq->wq_next != NULL) { ! /* first write what was queued */ buf = wq->wq_next->wq_ga.ga_data; len = wq->wq_next->wq_ga.ga_len; did_use_queue = TRUE; --- 3932,3938 ---- if (wq->wq_next != NULL) { ! // first write what was queued buf = wq->wq_next->wq_ga.ga_data; len = wq->wq_next->wq_ga.ga_len; did_use_queue = TRUE; *************** *** 3941,3947 **** else { if (len_arg == 0) ! /* nothing to write, called from channel_select_check() */ return OK; buf = buf_arg; len = len_arg; --- 3940,3946 ---- else { if (len_arg == 0) ! // nothing to write, called from channel_select_check() return OK; buf = buf_arg; len = len_arg; *************** *** 3965,3971 **** || errno == EAGAIN #endif )) ! res = 0; /* nothing got written */ if (res >= 0 && ch_part->ch_nonblocking) { --- 3964,3970 ---- || errno == EAGAIN #endif )) ! res = 0; // nothing got written if (res >= 0 && ch_part->ch_nonblocking) { *************** *** 3975,3984 **** ch_log(channel, "Sent %d bytes now", res); if (res == len) { ! /* Wrote all the buf[len] bytes. */ if (entry != NULL) { ! /* Remove the entry from the write queue. */ remove_from_writeque(wq, entry); continue; } --- 3974,3983 ---- ch_log(channel, "Sent %d bytes now", res); if (res == len) { ! // Wrote all the buf[len] bytes. if (entry != NULL) { ! // Remove the entry from the write queue. remove_from_writeque(wq, entry); continue; } *************** *** 3987,3998 **** } else { ! /* Wrote only buf[res] bytes, can't write more now. */ if (entry != NULL) { if (res > 0) { ! /* Remove the bytes that were written. */ mch_memmove(entry->wq_ga.ga_data, (char *)entry->wq_ga.ga_data + res, len - res); --- 3986,3997 ---- } else { ! // Wrote only buf[res] bytes, can't write more now. if (entry != NULL) { if (res > 0) { ! // Remove the bytes that were written. mch_memmove(entry->wq_ga.ga_data, (char *)entry->wq_ga.ga_data + res, len - res); *************** *** 4008,4021 **** } ch_log(channel, "Adding %d bytes to the write queue", len); ! /* Append the not written bytes of the argument to the write ! * buffer. Limit entries to 4000 bytes. */ if (wq->wq_prev != NULL && wq->wq_prev->wq_ga.ga_len + len < 4000) { writeq_T *last = wq->wq_prev; ! /* append to the last entry */ if (len > 0 && ga_grow(&last->wq_ga, len) == OK) { mch_memmove((char *)last->wq_ga.ga_data --- 4007,4020 ---- } ch_log(channel, "Adding %d bytes to the write queue", len); ! // Append the not written bytes of the argument to the write ! // buffer. Limit entries to 4000 bytes. if (wq->wq_prev != NULL && wq->wq_prev->wq_ga.ga_len + len < 4000) { writeq_T *last = wq->wq_prev; ! // append to the last entry if (len > 0 && ga_grow(&last->wq_ga, len) == OK) { mch_memmove((char *)last->wq_ga.ga_data *************** *** 4093,4101 **** if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT, 0) == FAIL) return NULL; ! /* Set the callback. An empty callback means no callback and not reading ! * the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not ! * allowed. */ if (opt->jo_callback.cb_name != NULL && *opt->jo_callback.cb_name != NUL) { if (eval) --- 4092,4100 ---- if (get_job_options(&argvars[2], opt, JO_CALLBACK + JO_TIMEOUT, 0) == FAIL) return NULL; ! // Set the callback. An empty callback means no callback and not reading ! // the response. With "ch_evalexpr()" and "ch_evalraw()" a callback is not ! // allowed. if (opt->jo_callback.cb_name != NULL && *opt->jo_callback.cb_name != NUL) { if (eval) *************** *** 4128,4134 **** jobopt_T opt; int timeout; ! /* return an empty string by default */ rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; --- 4127,4133 ---- jobopt_T opt; int timeout; ! // return an empty string by default rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; *************** *** 4164,4171 **** { list_T *list = listtv->vval.v_list; ! /* Move the item from the list and then change the type to ! * avoid the value being freed. */ *rettv = list->lv_last->li_tv; list->lv_last->li_tv.v_type = VAR_NUMBER; free_tv(listtv); --- 4163,4170 ---- { list_T *list = listtv->vval.v_list; ! // Move the item from the list and then change the type to ! // avoid the value being freed. *rettv = list->lv_last->li_tv; list->lv_last->li_tv.v_type = VAR_NUMBER; free_tv(listtv); *************** *** 4188,4194 **** jobopt_T opt; int timeout; ! /* return an empty string by default */ rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; --- 4187,4193 ---- jobopt_T opt; int timeout; ! // return an empty string by default rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; *************** *** 4216,4222 **** free_job_options(&opt); } ! #define KEEP_OPEN_TIME 20 /* msec */ #if (defined(UNIX) && !defined(HAVE_SELECT)) || defined(PROTO) /* --- 4215,4221 ---- free_job_options(&opt); } ! #define KEEP_OPEN_TIME 20 // msec #if (defined(UNIX) && !defined(HAVE_SELECT)) || defined(PROTO) /* *************** *** 4242,4250 **** { if (channel->ch_keep_open) { ! /* For unknown reason poll() returns immediately for a ! * keep-open channel. Instead of adding it to the fds add ! * a short timeout and check, like polling. */ if (*towait < 0 || *towait > KEEP_OPEN_TIME) *towait = KEEP_OPEN_TIME; } --- 4241,4249 ---- { if (channel->ch_keep_open) { ! // For unknown reason poll() returns immediately for a ! // keep-open channel. Instead of adding it to the fds add ! // a short timeout and check, like polling. if (*towait < 0 || *towait > KEEP_OPEN_TIME) *towait = KEEP_OPEN_TIME; } *************** *** 4293,4299 **** else if (channel->ch_part[part].ch_fd != INVALID_FD && channel->ch_keep_open) { ! /* polling a keep-open channel */ channel_read(channel, part, "channel_poll_check_keep_open"); } } --- 4292,4298 ---- else if (channel->ch_part[part].ch_fd != INVALID_FD && channel->ch_keep_open) { ! // polling a keep-open channel channel_read(channel, part, "channel_poll_check_keep_open"); } } *************** *** 4309,4315 **** return ret; } ! #endif /* UNIX && !HAVE_SELECT */ #if (!defined(MSWIN) && defined(HAVE_SELECT)) || defined(PROTO) --- 4308,4314 ---- return ret; } ! #endif // UNIX && !HAVE_SELECT #if (!defined(MSWIN) && defined(HAVE_SELECT)) || defined(PROTO) *************** *** 4340,4348 **** { if (channel->ch_keep_open) { ! /* For unknown reason select() returns immediately for a ! * keep-open channel. Instead of adding it to the rfds add ! * a short timeout and check, like polling. */ if (*tvp == NULL || tv->tv_sec > 0 || tv->tv_usec > KEEP_OPEN_TIME * 1000) { --- 4339,4347 ---- { if (channel->ch_keep_open) { ! // For unknown reason select() returns immediately for a ! // keep-open channel. Instead of adding it to the rfds add ! // a short timeout and check, like polling. if (*tvp == NULL || tv->tv_sec > 0 || tv->tv_usec > KEEP_OPEN_TIME * 1000) { *************** *** 4393,4399 **** } else if (fd != INVALID_FD && channel->ch_keep_open) { ! /* polling a keep-open channel */ channel_read(channel, part, "channel_select_check_keep_open"); } } --- 4392,4398 ---- } else if (fd != INVALID_FD && channel->ch_keep_open) { ! // polling a keep-open channel channel_read(channel, part, "channel_select_check_keep_open"); } } *************** *** 4434,4441 **** ++safe_to_invoke_callback; ! /* Only do this message when another message was given, otherwise we get ! * lots of them. */ if ((did_repeated_msg & REPEATED_MSG_LOOKING) == 0) { ch_log(NULL, "looking for messages on channels"); --- 4433,4440 ---- ++safe_to_invoke_callback; ! // Only do this message when another message was given, otherwise we get ! // lots of them. if ((did_repeated_msg & REPEATED_MSG_LOOKING) == 0) { ch_log(NULL, "looking for messages on channels"); *************** *** 4475,4496 **** if (channel->ch_part[part].ch_fd != INVALID_FD || channel_has_readahead(channel, part)) { ! /* Increase the refcount, in case the handler causes the channel ! * to be unreferenced or closed. */ ++channel->ch_refcount; r = may_invoke_callback(channel, part); if (r == OK) ret = TRUE; if (channel_unref(channel) || (r == OK #ifdef ELAPSED_FUNC ! /* Limit the time we loop here to 100 msec, otherwise ! * Vim becomes unresponsive when the callback takes ! * more than a bit of time. */ && ELAPSED_FUNC(start_tv) < 100L #endif )) { ! /* channel was freed or something was done, start over */ channel = first_channel; part = PART_SOCK; continue; --- 4474,4495 ---- if (channel->ch_part[part].ch_fd != INVALID_FD || channel_has_readahead(channel, part)) { ! // Increase the refcount, in case the handler causes the channel ! // to be unreferenced or closed. ++channel->ch_refcount; r = may_invoke_callback(channel, part); if (r == OK) ret = TRUE; if (channel_unref(channel) || (r == OK #ifdef ELAPSED_FUNC ! // Limit the time we loop here to 100 msec, otherwise ! // Vim becomes unresponsive when the callback takes ! // more than a bit of time. && ELAPSED_FUNC(start_tv) < 100L #endif )) { ! // channel was freed or something was done, start over channel = first_channel; part = PART_SOCK; continue; *************** *** 4983,4989 **** p = opt->jo_term_opencmd = tv_get_string_chk(item); if (p != NULL) { ! /* Must have %d and no other %. */ p = vim_strchr(p, '%'); if (p != NULL && (p[1] != 'd' || vim_strchr(p + 2, '%') != NULL)) --- 4982,4988 ---- p = opt->jo_term_opencmd = tv_get_string_chk(item); if (p != NULL) { ! // Must have %d and no other %. p = vim_strchr(p, '%'); if (p != NULL && (p[1] != 'd' || vim_strchr(p + 2, '%') != NULL)) *************** *** 5283,5293 **** ch_log(job->jv_channel, "Freeing job"); if (job->jv_channel != NULL) { ! /* The link from the channel to the job doesn't count as a reference, ! * thus don't decrement the refcount of the job. The reference from ! * the job to the channel does count the reference, decrement it and ! * NULL the reference. We don't set ch_job_killed, unreferencing the ! * job doesn't mean it stops running. */ job->jv_channel->ch_job = NULL; channel_unref(job->jv_channel); } --- 5282,5292 ---- ch_log(job->jv_channel, "Freeing job"); if (job->jv_channel != NULL) { ! // The link from the channel to the job doesn't count as a reference, ! // thus don't decrement the refcount of the job. The reference from ! // the job to the channel does count the reference, decrement it and ! // NULL the reference. We don't set ch_job_killed, unreferencing the ! // job doesn't mean it stops running. job->jv_channel->ch_job = NULL; channel_unref(job->jv_channel); } *************** *** 5456,5462 **** char_u *escaped_arg; int has_spaces = FALSE; ! /* First count the number of extra bytes required. */ slen = (int)STRLEN(arg); dlen = slen; for (s = arg; *s != NUL; MB_PTR_ADV(s)) --- 5455,5461 ---- char_u *escaped_arg; int has_spaces = FALSE; ! // First count the number of extra bytes required. slen = (int)STRLEN(arg); dlen = slen; for (s = arg; *s != NUL; MB_PTR_ADV(s)) *************** *** 5473,5479 **** if (dlen == slen) return vim_strsave(arg); ! /* Allocate memory for the result and fill it. */ escaped_arg = alloc(dlen + 1); if (escaped_arg == NULL) return NULL; --- 5472,5478 ---- if (dlen == slen) return vim_strsave(arg); ! // Allocate memory for the result and fill it. escaped_arg = alloc(dlen + 1); if (escaped_arg == NULL) return NULL; *************** *** 5506,5512 **** } } ! /* add terminating quote and finish with a NUL */ if (has_spaces) { for (i = 0; i < escaping; i++) --- 5505,5511 ---- } } ! // add terminating quote and finish with a NUL if (has_spaces) { for (i = 0; i < escaping; i++) *************** *** 5559,5568 **** if (job->jv_status != JOB_ENDED) return; ! /* Ready to cleanup the job. */ job->jv_status = JOB_FINISHED; ! /* When only channel-in is kept open, close explicitly. */ if (job->jv_channel != NULL) ch_close_part(job->jv_channel, PART_IN); --- 5558,5567 ---- if (job->jv_status != JOB_ENDED) return; ! // Ready to cleanup the job. job->jv_status = JOB_FINISHED; ! // When only channel-in is kept open, close explicitly. if (job->jv_channel != NULL) ch_close_part(job->jv_channel, PART_IN); *************** *** 5571,5577 **** typval_T argv[3]; typval_T rettv; ! /* Invoke the exit callback. Make sure the refcount is > 0. */ ch_log(job->jv_channel, "Invoking exit callback %s", job->jv_exit_cb.cb_name); ++job->jv_refcount; --- 5570,5576 ---- typval_T argv[3]; typval_T rettv; ! // Invoke the exit callback. Make sure the refcount is > 0. ch_log(job->jv_channel, "Invoking exit callback %s", job->jv_exit_cb.cb_name); ++job->jv_refcount; *************** *** 5625,5644 **** { if (job != NULL && --job->jv_refcount <= 0) { ! /* Do not free the job if there is a channel where the close callback ! * may get the job info. */ if (!job_channel_still_useful(job)) { ! /* Do not free the job when it has not ended yet and there is a ! * "stoponexit" flag or an exit callback. */ if (!job_need_end_check(job)) { job_free(job); } else if (job->jv_channel != NULL) { ! /* Do remove the link to the channel, otherwise it hangs ! * around until Vim exits. See job_free() for refcount. */ ch_log(job->jv_channel, "detaching channel from job"); job->jv_channel->ch_job = NULL; channel_unref(job->jv_channel); --- 5624,5643 ---- { if (job != NULL && --job->jv_refcount <= 0) { ! // Do not free the job if there is a channel where the close callback ! // may get the job info. if (!job_channel_still_useful(job)) { ! // Do not free the job when it has not ended yet and there is a ! // "stoponexit" flag or an exit callback. if (!job_need_end_check(job)) { job_free(job); } else if (job->jv_channel != NULL) { ! // Do remove the link to the channel, otherwise it hangs ! // around until Vim exits. See job_free() for refcount. ch_log(job->jv_channel, "detaching channel from job"); job->jv_channel->ch_job = NULL; channel_unref(job->jv_channel); *************** *** 5658,5665 **** if ((job->jv_copyID & mask) != (copyID & mask) && !job_still_useful(job)) { ! /* Free the channel and ordinary items it contains, but don't ! * recurse into Lists, Dictionaries etc. */ job_free_contents(job); did_free = TRUE; } --- 5657,5664 ---- if ((job->jv_copyID & mask) != (copyID & mask) && !job_still_useful(job)) { ! // Free the channel and ordinary items it contains, but don't ! // recurse into Lists, Dictionaries etc. job_free_contents(job); did_free = TRUE; } *************** *** 5678,5684 **** if ((job->jv_copyID & mask) != (copyID & mask) && !job_still_useful(job)) { ! /* Free the job struct itself. */ job_free_job(job); } } --- 5677,5683 ---- if ((job->jv_copyID & mask) != (copyID & mask) && !job_still_useful(job)) { ! // Free the job struct itself. job_free_job(job); } } *************** *** 5755,5762 **** job_T *job; for (job = first_job; job != NULL; job = job->jv_next) ! /* Only should check if the channel has been closed, if the channel is ! * open the job won't exit. */ if ((job->jv_status == JOB_STARTED && !job_channel_still_useful(job)) || (job->jv_status == JOB_FINISHED && job_channel_can_close(job))) --- 5754,5761 ---- job_T *job; for (job = first_job; job != NULL; job = job->jv_next) ! // Only should check if the channel has been closed, if the channel is ! // open the job won't exit. if ((job->jv_status == JOB_STARTED && !job_channel_still_useful(job)) || (job->jv_status == JOB_FINISHED && job_channel_can_close(job))) *************** *** 5843,5849 **** opt = *opt_arg; else { ! /* Default mode is NL. */ clear_job_options(&opt); opt.jo_mode = MODE_NL; if (get_job_options(&argvars[1], &opt, --- 5842,5848 ---- opt = *opt_arg; else { ! // Default mode is NL. clear_job_options(&opt); opt.jo_mode = MODE_NL; if (get_job_options(&argvars[1], &opt, *************** *** 5853,5859 **** goto theend; } ! /* Check that when io is "file" that there is a file name. */ for (part = PART_OUT; part < PART_COUNT; ++part) if ((opt.jo_set & (JO_OUT_IO << (part - PART_OUT))) && opt.jo_io[part] == JIO_FILE --- 5852,5858 ---- goto theend; } ! // Check that when io is "file" that there is a file name. for (part = PART_OUT; part < PART_COUNT; ++part) if ((opt.jo_set & (JO_OUT_IO << (part - PART_OUT))) && opt.jo_io[part] == JIO_FILE *************** *** 5868,5874 **** { buf_T *buf = NULL; ! /* check that we can find the buffer before starting the job */ if (opt.jo_set & JO_IN_BUF) { buf = buflist_findnr(opt.jo_io_buf[PART_IN]); --- 5867,5873 ---- { buf_T *buf = NULL; ! // check that we can find the buffer before starting the job if (opt.jo_set & JO_IN_BUF) { buf = buflist_findnr(opt.jo_io_buf[PART_IN]); *************** *** 5906,5912 **** #ifdef USE_ARGV if (argv_arg != NULL) { ! /* Make a copy of argv_arg for job->jv_argv. */ for (i = 0; argv_arg[i] != NULL; i++) argc++; argv = ALLOC_MULT(char *, argc + 1); --- 5905,5911 ---- #ifdef USE_ARGV if (argv_arg != NULL) { ! // Make a copy of argv_arg for job->jv_argv. for (i = 0; argv_arg[i] != NULL; i++) argc++; argv = ALLOC_MULT(char *, argc + 1); *************** *** 5920,5926 **** #endif if (argvars[0].v_type == VAR_STRING) { ! /* Command is a string. */ cmd = argvars[0].vval.v_string; if (cmd == NULL || *cmd == NUL) { --- 5919,5925 ---- #endif if (argvars[0].v_type == VAR_STRING) { ! // Command is a string. cmd = argvars[0].vval.v_string; if (cmd == NULL || *cmd == NUL) { *************** *** 5951,5957 **** #endif } ! /* Save the command used to start the job. */ job->jv_argv = argv; #ifdef USE_ARGV --- 5950,5956 ---- #endif } ! // Save the command used to start the job. job->jv_argv = argv; #ifdef USE_ARGV *************** *** 5976,5982 **** mch_job_start((char *)cmd, job, &opt); #endif ! /* If the channel is reading from a buffer, write lines now. */ if (job->jv_channel != NULL) channel_write_in(job->jv_channel); --- 5975,5981 ---- mch_job_start((char *)cmd, job, &opt); #endif ! // If the channel is reading from a buffer, write lines now. if (job->jv_channel != NULL) channel_write_in(job->jv_channel); *************** *** 6000,6006 **** char *result; if (job->jv_status >= JOB_ENDED) ! /* No need to check, dead is dead. */ result = "dead"; else if (job->jv_status == JOB_FAILED) result = "fail"; --- 5999,6005 ---- char *result; if (job->jv_status >= JOB_ENDED) ! // No need to check, dead is dead. result = "dead"; else if (job->jv_status == JOB_FAILED) result = "fail"; *************** *** 6050,6061 **** if (mch_signal_job(job, arg) == FAIL) return 0; ! /* Assume that only "kill" will kill the job. */ if (job->jv_channel != NULL && STRCMP(arg, "kill") == 0) job->jv_channel->ch_job_killed = TRUE; ! /* We don't try freeing the job, obviously the caller still has a ! * reference to it. */ return 1; } --- 6049,6060 ---- if (mch_signal_job(job, arg) == FAIL) return 0; ! // Assume that only "kill" will kill the job. if (job->jv_channel != NULL && STRCMP(arg, "kill") == 0) job->jv_channel->ch_job_killed = TRUE; ! // We don't try freeing the job, obviously the caller still has a ! // reference to it. return 1; } *************** *** 6300,6306 **** char_u *opt = (char_u *)""; char_u buf[NUMBUFLEN]; ! /* Don't open a file in restricted mode. */ if (check_restricted() || check_secure()) return; fname = tv_get_string(&argvars[0]); --- 6299,6305 ---- char_u *opt = (char_u *)""; char_u buf[NUMBUFLEN]; ! // Don't open a file in restricted mode. if (check_restricted() || check_secure()) return; fname = tv_get_string(&argvars[0]); *************** *** 6413,6419 **** jobopt_T opt; int part = -1; ! /* return an empty string by default */ rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; --- 6412,6418 ---- jobopt_T opt; int part = -1; ! // return an empty string by default rettv->v_type = VAR_STRING; rettv->vval.v_string = NULL; *************** *** 6612,6615 **** rettv->vval.v_number = job_stop(job, argvars, NULL); } ! #endif /* FEAT_JOB_CHANNEL */ --- 6611,6614 ---- rettv->vval.v_number = job_stop(job, argvars, NULL); } ! #endif // FEAT_JOB_CHANNEL *** ../vim-8.1.2367/src/charset.c 2019-11-09 23:26:36.901570979 +0100 --- src/charset.c 2019-11-30 20:49:03.359329561 +0100 *************** *** 10,16 **** #include "vim.h" #if defined(HAVE_WCHAR_H) ! # include /* for towupper() and towlower() */ #endif static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp); --- 10,16 ---- #include "vim.h" #if defined(HAVE_WCHAR_H) ! # include // for towupper() and towlower() #endif static int win_nolbr_chartabsize(win_T *wp, char_u *s, colnr_T col, int *headp); *************** *** 18,39 **** static int chartab_initialized = FALSE; ! /* b_chartab[] is an array of 32 bytes, each bit representing one of the ! * characters 0-255. */ #define SET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> 3] |= (1 << ((c) & 0x7)) #define RESET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7)) #define GET_CHARTAB(buf, c) ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7))) ! /* table used below, see init_chartab() for an explanation */ static char_u g_chartab[256]; /* * Flags for g_chartab[]. */ ! #define CT_CELL_MASK 0x07 /* mask: nr of display cells (1, 2 or 4) */ ! #define CT_PRINT_CHAR 0x10 /* flag: set for printable chars */ ! #define CT_ID_CHAR 0x20 /* flag: set for ID chars */ ! #define CT_FNAME_CHAR 0x40 /* flag: set for file name chars */ static int in_win_border(win_T *wp, colnr_T vcol); --- 18,39 ---- static int chartab_initialized = FALSE; ! // b_chartab[] is an array of 32 bytes, each bit representing one of the ! // characters 0-255. #define SET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> 3] |= (1 << ((c) & 0x7)) #define RESET_CHARTAB(buf, c) (buf)->b_chartab[(unsigned)(c) >> 3] &= ~(1 << ((c) & 0x7)) #define GET_CHARTAB(buf, c) ((buf)->b_chartab[(unsigned)(c) >> 3] & (1 << ((c) & 0x7))) ! // table used below, see init_chartab() for an explanation static char_u g_chartab[256]; /* * Flags for g_chartab[]. */ ! #define CT_CELL_MASK 0x07 // mask: nr of display cells (1, 2 or 4) ! #define CT_PRINT_CHAR 0x10 // flag: set for printable chars ! #define CT_ID_CHAR 0x20 // flag: set for ID chars ! #define CT_FNAME_CHAR 0x40 // flag: set for file name chars static int in_win_border(win_T *wp, colnr_T vcol); *************** *** 72,78 **** int buf_init_chartab( buf_T *buf, ! int global) /* FALSE: only set buf->b_chartab[] */ { int c; int c2; --- 72,78 ---- int buf_init_chartab( buf_T *buf, ! int global) // FALSE: only set buf->b_chartab[] { int c; int c2; *************** *** 102,122 **** g_chartab[c++] = 1 + CT_PRINT_CHAR; while (c < 256) { ! /* UTF-8: bytes 0xa0 - 0xff are printable (latin1) */ if (enc_utf8 && c >= 0xa0) g_chartab[c++] = CT_PRINT_CHAR + 1; ! /* euc-jp characters starting with 0x8e are single width */ else if (enc_dbcs == DBCS_JPNU && c == 0x8e) g_chartab[c++] = CT_PRINT_CHAR + 1; ! /* other double-byte chars can be printable AND double-width */ else if (enc_dbcs != 0 && MB_BYTE2LEN(c) == 2) g_chartab[c++] = CT_PRINT_CHAR + 2; else ! /* the rest is unprintable by default */ g_chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; } ! /* Assume that every multi-byte char is a filename character. */ for (c = 1; c < 256; ++c) if ((enc_dbcs != 0 && MB_BYTE2LEN(c) > 1) || (enc_dbcs == DBCS_JPNU && c == 0x8e) --- 102,122 ---- g_chartab[c++] = 1 + CT_PRINT_CHAR; while (c < 256) { ! // UTF-8: bytes 0xa0 - 0xff are printable (latin1) if (enc_utf8 && c >= 0xa0) g_chartab[c++] = CT_PRINT_CHAR + 1; ! // euc-jp characters starting with 0x8e are single width else if (enc_dbcs == DBCS_JPNU && c == 0x8e) g_chartab[c++] = CT_PRINT_CHAR + 1; ! // other double-byte chars can be printable AND double-width else if (enc_dbcs != 0 && MB_BYTE2LEN(c) == 2) g_chartab[c++] = CT_PRINT_CHAR + 2; else ! // the rest is unprintable by default g_chartab[c++] = (dy_flags & DY_UHEX) ? 4 : 2; } ! // Assume that every multi-byte char is a filename character. for (c = 1; c < 256; ++c) if ((enc_dbcs != 0 && MB_BYTE2LEN(c) > 1) || (enc_dbcs == DBCS_JPNU && c == 0x8e) *************** *** 131,137 **** if (enc_dbcs != 0) for (c = 0; c < 256; ++c) { ! /* double-byte characters are probably word characters */ if (MB_BYTE2LEN(c) == 2) SET_CHARTAB(buf, c); } --- 131,137 ---- if (enc_dbcs != 0) for (c = 0; c < 256; ++c) { ! // double-byte characters are probably word characters if (MB_BYTE2LEN(c) == 2) SET_CHARTAB(buf, c); } *************** *** 144,163 **** SET_CHARTAB(buf, '-'); #endif ! /* Walk through the 'isident', 'iskeyword', 'isfname' and 'isprint' ! * options Each option is a list of characters, character numbers or ! * ranges, separated by commas, e.g.: "200-210,x,#-178,-" ! */ for (i = global ? 0 : 3; i <= 3; ++i) { if (i == 0) ! p = p_isi; /* first round: 'isident' */ else if (i == 1) ! p = p_isp; /* second round: 'isprint' */ else if (i == 2) ! p = p_isf; /* third round: 'isfname' */ ! else /* i == 3 */ ! p = buf->b_p_isk; /* fourth round: 'iskeyword' */ while (*p) { --- 144,162 ---- SET_CHARTAB(buf, '-'); #endif ! // Walk through the 'isident', 'iskeyword', 'isfname' and 'isprint' ! // options Each option is a list of characters, character numbers or ! // ranges, separated by commas, e.g.: "200-210,x,#-178,-" for (i = global ? 0 : 3; i <= 3; ++i) { if (i == 0) ! p = p_isi; // first round: 'isident' else if (i == 1) ! p = p_isp; // second round: 'isprint' else if (i == 2) ! p = p_isf; // third round: 'isfname' ! else // i == 3 ! p = buf->b_p_isk; // fourth round: 'iskeyword' while (*p) { *************** *** 191,197 **** || !(*p == NUL || *p == ',')) return FAIL; ! if (c2 == -1) /* not a range */ { /* * A single '@' (not "@-@"): --- 190,196 ---- || !(*p == NUL || *p == ',')) return FAIL; ! if (c2 == -1) // not a range { /* * A single '@' (not "@-@"): *************** *** 210,228 **** } while (c <= c2) { ! /* Use the MB_ functions here, because isalpha() doesn't ! * work properly when 'encoding' is "latin1" and the locale is ! * "C". */ if (!do_isalpha || MB_ISLOWER(c) || MB_ISUPPER(c)) { ! if (i == 0) /* (re)set ID flag */ { if (tilde) g_chartab[c] &= ~CT_ID_CHAR; else g_chartab[c] |= CT_ID_CHAR; } ! else if (i == 1) /* (re)set printable */ { if ((c < ' ' #ifndef EBCDIC --- 209,227 ---- } while (c <= c2) { ! // Use the MB_ functions here, because isalpha() doesn't ! // work properly when 'encoding' is "latin1" and the locale is ! // "C". if (!do_isalpha || MB_ISLOWER(c) || MB_ISUPPER(c)) { ! if (i == 0) // (re)set ID flag { if (tilde) g_chartab[c] &= ~CT_ID_CHAR; else g_chartab[c] |= CT_ID_CHAR; } ! else if (i == 1) // (re)set printable { if ((c < ' ' #ifndef EBCDIC *************** *** 245,258 **** } } } ! else if (i == 2) /* (re)set fname flag */ { if (tilde) g_chartab[c] &= ~CT_FNAME_CHAR; else g_chartab[c] |= CT_FNAME_CHAR; } ! else /* i == 3 */ /* (re)set keyword flag */ { if (tilde) RESET_CHARTAB(buf, c); --- 244,257 ---- } } } ! else if (i == 2) // (re)set fname flag { if (tilde) g_chartab[c] &= ~CT_FNAME_CHAR; else g_chartab[c] |= CT_FNAME_CHAR; } ! else // i == 3 (re)set keyword flag { if (tilde) RESET_CHARTAB(buf, c); *************** *** 266,272 **** c = *p; p = skip_to_option_part(p); if (c == ',' && *p == NUL) ! /* Trailing comma is not allowed. */ return FAIL; } } --- 265,271 ---- c = *p; p = skip_to_option_part(p); if (c == ',' && *p == NUL) ! // Trailing comma is not allowed. return FAIL; } } *************** *** 284,299 **** char_u *buf, int bufsize) { ! int len; /* length of string needing translation */ ! int room; /* room in buffer after string */ ! char_u *trs; /* translated character */ ! int trs_len; /* length of trs[] */ len = (int)STRLEN(buf); room = bufsize - len; while (*buf != 0) { ! /* Assume a multi-byte character doesn't need translation. */ if (has_mbyte && (trs_len = (*mb_ptr2len)(buf)) > 1) len -= trs_len; else --- 283,298 ---- char_u *buf, int bufsize) { ! int len; // length of string needing translation ! int room; // room in buffer after string ! char_u *trs; // translated character ! int trs_len; // length of trs[] len = (int)STRLEN(buf); room = bufsize - len; while (*buf != 0) { ! // Assume a multi-byte character doesn't need translation. if (has_mbyte && (trs_len = (*mb_ptr2len)(buf)) > 1) len -= trs_len; else *************** *** 328,335 **** if (has_mbyte) { ! /* Compute the length of the result, taking account of unprintable ! * multi-byte characters. */ len = 0; p = s; while (*p != NUL) --- 327,334 ---- if (has_mbyte) { ! // Compute the length of the result, taking account of unprintable ! // multi-byte characters. len = 0; p = s; while (*p != NUL) *************** *** 352,358 **** if (l > 0) len += l; else ! len += 4; /* illegal byte sequence */ } } res = alloc(len + 1); --- 351,357 ---- if (l > 0) len += l; else ! len += 4; // illegal byte sequence } } res = alloc(len + 1); *************** *** 369,375 **** { c = (*mb_ptr2char)(p); if (vim_isprintc(c)) ! STRNCAT(res, p, l); /* append printable multi-byte char */ else transchar_hex(res + STRLEN(res), c); p += l; --- 368,374 ---- { c = (*mb_ptr2char)(p); if (vim_isprintc(c)) ! STRNCAT(res, p, l); // append printable multi-byte char else transchar_hex(res + STRLEN(res), c); p += l; *************** *** 403,409 **** #define STR_CHAR(i) (buf == NULL ? GA_CHAR(i) : buf[i]) #define STR_PTR(i) (buf == NULL ? GA_PTR(i) : buf + i) ! /* Copy "str" into "buf" or allocated memory, unmodified. */ if (buf == NULL) { ga_init2(&ga, 1, 10); --- 402,408 ---- #define STR_CHAR(i) (buf == NULL ? GA_CHAR(i) : buf[i]) #define STR_PTR(i) (buf == NULL ? GA_PTR(i) : buf + i) ! // Copy "str" into "buf" or allocated memory, unmodified. if (buf == NULL) { ga_init2(&ga, 1, 10); *************** *** 414,420 **** } else { ! if (len >= buflen) /* Ugly! */ len = buflen - 1; mch_memmove(buf, str, (size_t)len); } --- 413,419 ---- } else { ! if (len >= buflen) // Ugly! len = buflen - 1; mch_memmove(buf, str, (size_t)len); } *************** *** 423,429 **** else buf[len] = NUL; ! /* Make each character lower case. */ i = 0; while (STR_CHAR(i) != NUL) { --- 422,428 ---- else buf[len] = NUL; ! // Make each character lower case. i = 0; while (STR_CHAR(i) != NUL) { *************** *** 435,449 **** int olen = utf_ptr2len(STR_PTR(i)); int lc = utf_tolower(c); ! /* Only replace the character when it is not an invalid ! * sequence (ASCII character or more than one byte) and ! * utf_tolower() doesn't return the original character. */ if ((c < 0x80 || olen > 1) && c != lc) { int nlen = utf_char2len(lc); ! /* If the byte length changes need to shift the following ! * characters forward or backward. */ if (olen != nlen) { if (nlen > olen) --- 434,448 ---- int olen = utf_ptr2len(STR_PTR(i)); int lc = utf_tolower(c); ! // Only replace the character when it is not an invalid ! // sequence (ASCII character or more than one byte) and ! // utf_tolower() doesn't return the original character. if ((c < 0x80 || olen > 1) && c != lc) { int nlen = utf_char2len(lc); ! // If the byte length changes need to shift the following ! // characters forward or backward. if (olen != nlen) { if (nlen > olen) *************** *** 452,458 **** ? ga_grow(&ga, nlen - olen + 1) == FAIL : len + nlen - olen >= buflen) { ! /* out of memory, keep old char */ lc = c; nlen = olen; } --- 451,457 ---- ? ga_grow(&ga, nlen - olen + 1) == FAIL : len + nlen - olen >= buflen) { ! // out of memory, keep old char lc = c; nlen = olen; } *************** *** 474,480 **** (void)utf_char2bytes(lc, STR_PTR(i)); } } ! /* skip to next multi-byte char */ i += (*mb_ptr2len)(STR_PTR(i)); } else --- 473,479 ---- (void)utf_char2bytes(lc, STR_PTR(i)); } } ! // skip to next multi-byte char i += (*mb_ptr2len)(STR_PTR(i)); } else *************** *** 508,514 **** int i; i = 0; ! if (IS_SPECIAL(c)) /* special key code, display as ~@ char */ { transchar_buf[0] = '~'; transchar_buf[1] = '@'; --- 507,513 ---- int i; i = 0; ! if (IS_SPECIAL(c)) // special key code, display as ~@ char { transchar_buf[0] = '~'; transchar_buf[1] = '@'; *************** *** 524,530 **** #endif )) || (c < 256 && vim_isprintc_strict(c))) { ! /* printable character */ transchar_buf[i] = c; transchar_buf[i + 1] = NUL; } --- 523,529 ---- #endif )) || (c < 256 && vim_isprintc_strict(c))) { ! // printable character transchar_buf[i] = c; transchar_buf[i + 1] = NUL; } *************** *** 557,584 **** transchar_nonprint(char_u *buf, int c) { if (c == NL) ! c = NUL; /* we use newline in place of a NUL */ else if (c == CAR && get_fileformat(curbuf) == EOL_MAC) ! c = NL; /* we use CR in place of NL in this case */ ! if (dy_flags & DY_UHEX) /* 'display' has "uhex" */ transchar_hex(buf, c); #ifdef EBCDIC ! /* For EBCDIC only the characters 0-63 and 255 are not printable */ else if (CtrlChar(c) != 0 || c == DEL) #else ! else if (c <= 0x7f) /* 0x00 - 0x1f and 0x7f */ #endif { buf[0] = '^'; #ifdef EBCDIC if (c == DEL) ! buf[1] = '?'; /* DEL displayed as ^? */ else buf[1] = CtrlChar(c); #else ! buf[1] = c ^ 0x40; /* DEL displayed as ^? */ #endif buf[2] = NUL; --- 556,583 ---- transchar_nonprint(char_u *buf, int c) { if (c == NL) ! c = NUL; // we use newline in place of a NUL else if (c == CAR && get_fileformat(curbuf) == EOL_MAC) ! c = NL; // we use CR in place of NL in this case ! if (dy_flags & DY_UHEX) // 'display' has "uhex" transchar_hex(buf, c); #ifdef EBCDIC ! // For EBCDIC only the characters 0-63 and 255 are not printable else if (CtrlChar(c) != 0 || c == DEL) #else ! else if (c <= 0x7f) // 0x00 - 0x1f and 0x7f #endif { buf[0] = '^'; #ifdef EBCDIC if (c == DEL) ! buf[1] = '?'; // DEL displayed as ^? else buf[1] = CtrlChar(c); #else ! buf[1] = c ^ 0x40; // DEL displayed as ^? #endif buf[2] = NUL; *************** *** 588,594 **** transchar_hex(buf, c); } #ifndef EBCDIC ! else if (c >= ' ' + 0x80 && c <= '~' + 0x80) /* 0xa0 - 0xfe */ { buf[0] = '|'; buf[1] = c - 0x80; --- 587,593 ---- transchar_hex(buf, c); } #ifndef EBCDIC ! else if (c >= ' ' + 0x80 && c <= '~' + 0x80) // 0xa0 - 0xfe { buf[0] = '|'; buf[1] = c - 0x80; *************** *** 602,608 **** buf[2] = NUL; } #endif ! else /* 0x80 - 0x9f and 0xff */ { /* * TODO: EBCDIC I don't know what to do with this chars, so I display --- 601,607 ---- buf[2] = NUL; } #endif ! else // 0x80 - 0x9f and 0xff { /* * TODO: EBCDIC I don't know what to do with this chars, so I display *************** *** 610,618 **** */ buf[0] = '~'; #ifdef EBCDIC ! buf[1] = '?'; /* 0xff displayed as ~? */ #else ! buf[1] = (c - 0x80) ^ 0x40; /* 0xff displayed as ~? */ #endif buf[2] = NUL; } --- 609,617 ---- */ buf[0] = '~'; #ifdef EBCDIC ! buf[1] = '?'; // 0xff displayed as ~? #else ! buf[1] = (c - 0x80) ^ 0x40; // 0xff displayed as ~? #endif buf[2] = NUL; } *************** *** 676,686 **** return char2cells(K_SECOND(c)) + 2; if (c >= 0x80) { ! /* UTF-8: above 0x80 need to check the value */ if (enc_utf8) return utf_char2cells(c); ! /* DBCS: double-byte means double-width, except for euc-jp with first ! * byte 0x8e */ if (enc_dbcs != 0 && c >= 0x100) { if (enc_dbcs == DBCS_JPNU && ((unsigned)c >> 8) == 0x8e) --- 675,685 ---- return char2cells(K_SECOND(c)) + 2; if (c >= 0x80) { ! // UTF-8: above 0x80 need to check the value if (enc_utf8) return utf_char2cells(c); ! // DBCS: double-byte means double-width, except for euc-jp with first ! // byte 0x8e if (enc_dbcs != 0 && c >= 0x100) { if (enc_dbcs == DBCS_JPNU && ((unsigned)c >> 8) == 0x8e) *************** *** 698,707 **** int ptr2cells(char_u *p) { ! /* For UTF-8 we need to look at more bytes if the first byte is >= 0x80. */ if (enc_utf8 && *p >= 0x80) return utf_ptr2cells(p); ! /* For DBCS we can tell the cell count from the first byte. */ return (g_chartab[*p] & CT_CELL_MASK); } --- 697,706 ---- int ptr2cells(char_u *p) { ! // For UTF-8 we need to look at more bytes if the first byte is >= 0x80. if (enc_utf8 && *p >= 0x80) return utf_ptr2cells(p); ! // For DBCS we can tell the cell count from the first byte. return (g_chartab[*p] & CT_CELL_MASK); } *************** *** 797,803 **** linetabsize_col(int startcol, char_u *s) { colnr_T col = startcol; ! char_u *line = s; /* pointer to start of line, for breakindent */ while (*s != NUL) col += lbr_chartabsize_adv(line, &s, col); --- 796,802 ---- linetabsize_col(int startcol, char_u *s) { colnr_T col = startcol; ! char_u *line = s; // pointer to start of line, for breakindent while (*s != NUL) col += lbr_chartabsize_adv(line, &s, col); *************** *** 931,937 **** */ int lbr_chartabsize( ! char_u *line UNUSED, /* start of the line */ unsigned char *s, colnr_T col) { --- 930,936 ---- */ int lbr_chartabsize( ! char_u *line UNUSED, // start of the line unsigned char *s, colnr_T col) { *************** *** 954,960 **** */ int lbr_chartabsize_adv( ! char_u *line, /* start of the line */ char_u **s, colnr_T col) { --- 953,959 ---- */ int lbr_chartabsize_adv( ! char_u *line, // start of the line char_u **s, colnr_T col) { *************** *** 975,981 **** int win_lbr_chartabsize( win_T *wp, ! char_u *line UNUSED, /* start of the line */ char_u *s, colnr_T col, int *headp UNUSED) --- 974,980 ---- int win_lbr_chartabsize( win_T *wp, ! char_u *line UNUSED, // start of the line char_u *s, colnr_T col, int *headp UNUSED) *************** *** 984,990 **** int c; int size; colnr_T col2; ! colnr_T col_adj = 0; /* col + screen size of tab */ colnr_T colmax; int added; int mb_added = 0; --- 983,989 ---- int c; int size; colnr_T col2; ! colnr_T col_adj = 0; // col + screen size of tab colnr_T colmax; int added; int mb_added = 0; *************** *** 1051,1057 **** break; col2 += win_chartabsize(wp, s, col2); ! if (col2 >= colmax) /* doesn't fit */ { size = colmax - col + col_adj; break; --- 1050,1056 ---- break; col2 += win_chartabsize(wp, s, col2); ! if (col2 >= colmax) // doesn't fit { size = colmax - col + col_adj; break; *************** *** 1061,1067 **** else if (has_mbyte && size == 2 && MB_BYTE2LEN(*s) > 1 && wp->w_p_wrap && in_win_border(wp, col)) { ! ++size; /* Count the ">" in the last column. */ mb_added = 1; } --- 1060,1066 ---- else if (has_mbyte && size == 2 && MB_BYTE2LEN(*s) > 1 && wp->w_p_wrap && in_win_border(wp, col)) { ! ++size; // Count the ">" in the last column. mb_added = 1; } *************** *** 1159,1166 **** # endif } n = ptr2cells(s); ! /* Add one cell for a double-width character in the last column of the ! * window, displayed with a ">". */ if (n == 2 && MB_BYTE2LEN(*s) > 1 && in_win_border(wp, col)) { if (headp != NULL) --- 1158,1165 ---- # endif } n = ptr2cells(s); ! // Add one cell for a double-width character in the last column of the ! // window, displayed with a ">". if (n == 2 && MB_BYTE2LEN(*s) > 1 && in_win_border(wp, col)) { if (headp != NULL) *************** *** 1177,1186 **** static int in_win_border(win_T *wp, colnr_T vcol) { ! int width1; /* width of first line (after line number) */ ! int width2; /* width of further lines */ ! if (wp->w_width == 0) /* there is no border */ return FALSE; width1 = wp->w_width - win_col_off(wp); if ((int)vcol < width1 - 1) --- 1176,1185 ---- static int in_win_border(win_T *wp, colnr_T vcol) { ! int width1; // width of first line (after line number) ! int width2; // width of further lines ! if (wp->w_width == 0) // there is no border return FALSE; width1 = wp->w_width - win_col_off(wp); if ((int)vcol < width1 - 1) *************** *** 1210,1218 **** colnr_T *end) { colnr_T vcol; ! char_u *ptr; /* points to current char */ ! char_u *posptr; /* points to char at pos->col */ ! char_u *line; /* start of the line */ int incr; int head; #ifdef FEAT_VARTABS --- 1209,1217 ---- colnr_T *end) { colnr_T vcol; ! char_u *ptr; // points to current char ! char_u *posptr; // points to char at pos->col ! char_u *line; // start of the line int incr; int head; #ifdef FEAT_VARTABS *************** *** 1224,1239 **** vcol = 0; line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); if (pos->col == MAXCOL) ! posptr = NULL; /* continue until the NUL */ else { ! /* Special check for an empty line, which can happen on exit, when ! * ml_get_buf() always returns an empty string. */ if (*ptr == NUL) pos->col = 0; posptr = ptr + pos->col; if (has_mbyte) ! /* always start on the first byte */ posptr -= (*mb_head_off)(line, posptr); } --- 1223,1238 ---- vcol = 0; line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); if (pos->col == MAXCOL) ! posptr = NULL; // continue until the NUL else { ! // Special check for an empty line, which can happen on exit, when ! // ml_get_buf() always returns an empty string. if (*ptr == NUL) pos->col = 0; posptr = ptr + pos->col; if (has_mbyte) ! // always start on the first byte posptr -= (*mb_head_off)(line, posptr); } *************** *** 1253,1265 **** { head = 0; c = *ptr; ! /* make sure we don't go past the end of the line */ if (c == NUL) { ! incr = 1; /* NUL at end of line only takes one column */ break; } ! /* A tab gets expanded, depending on the current column */ if (c == TAB) #ifdef FEAT_VARTABS incr = tabstop_padding(vcol, ts, vts); --- 1252,1264 ---- { head = 0; c = *ptr; ! // make sure we don't go past the end of the line if (c == NUL) { ! incr = 1; // NUL at end of line only takes one column break; } ! // A tab gets expanded, depending on the current column if (c == TAB) #ifdef FEAT_VARTABS incr = tabstop_padding(vcol, ts, vts); *************** *** 1270,1285 **** { if (has_mbyte) { ! /* For utf-8, if the byte is >= 0x80, need to look at ! * further bytes to find the cell width. */ if (enc_utf8 && c >= 0x80) incr = utf_ptr2cells(ptr); else incr = g_chartab[c] & CT_CELL_MASK; ! /* If a double-cell char doesn't fit at the end of a line ! * it wraps to the next line, it's like this char is three ! * cells wide. */ if (incr == 2 && wp->w_p_wrap && MB_BYTE2LEN(*ptr) > 1 && in_win_border(wp, vcol)) { --- 1269,1284 ---- { if (has_mbyte) { ! // For utf-8, if the byte is >= 0x80, need to look at ! // further bytes to find the cell width. if (enc_utf8 && c >= 0x80) incr = utf_ptr2cells(ptr); else incr = g_chartab[c] & CT_CELL_MASK; ! // If a double-cell char doesn't fit at the end of a line ! // it wraps to the next line, it's like this char is three ! // cells wide. if (incr == 2 && wp->w_p_wrap && MB_BYTE2LEN(*ptr) > 1 && in_win_border(wp, vcol)) { *************** *** 1291,1297 **** incr = g_chartab[c] & CT_CELL_MASK; } ! if (posptr != NULL && ptr >= posptr) /* character at pos->col */ break; vcol += incr; --- 1290,1296 ---- incr = g_chartab[c] & CT_CELL_MASK; } ! if (posptr != NULL && ptr >= posptr) // character at pos->col break; vcol += incr; *************** *** 1302,1318 **** { for (;;) { ! /* A tab gets expanded, depending on the current column */ head = 0; incr = win_lbr_chartabsize(wp, line, ptr, vcol, &head); ! /* make sure we don't go past the end of the line */ if (*ptr == NUL) { ! incr = 1; /* NUL at end of line only takes one column */ break; } ! if (posptr != NULL && ptr >= posptr) /* character at pos->col */ break; vcol += incr; --- 1301,1317 ---- { for (;;) { ! // A tab gets expanded, depending on the current column head = 0; incr = win_lbr_chartabsize(wp, line, ptr, vcol, &head); ! // make sure we don't go past the end of the line if (*ptr == NUL) { ! incr = 1; // NUL at end of line only takes one column break; } ! if (posptr != NULL && ptr >= posptr) // character at pos->col break; vcol += incr; *************** *** 1332,1340 **** && !(VIsual_active && (*p_sel == 'e' || LTOREQ_POS(*pos, VIsual))) ) ! *cursor = vcol + incr - 1; /* cursor at end */ else ! *cursor = vcol + head; /* cursor at start */ } } --- 1331,1339 ---- && !(VIsual_active && (*p_sel == 'e' || LTOREQ_POS(*pos, VIsual))) ) ! *cursor = vcol + incr - 1; // cursor at end else ! *cursor = vcol + head; // cursor at start } } *************** *** 1374,1385 **** if (virtual_active()) { ! /* For virtual mode, only want one value */ getvcol(wp, pos, &col, NULL, NULL); coladd = pos->coladd; endadd = 0; ! /* Cannot put the cursor on part of a wide character. */ ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); if (pos->col < (colnr_T)STRLEN(ptr)) { --- 1373,1384 ---- if (virtual_active()) { ! // For virtual mode, only want one value getvcol(wp, pos, &col, NULL, NULL); coladd = pos->coladd; endadd = 0; ! // Cannot put the cursor on part of a wide character. ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); if (pos->col < (colnr_T)STRLEN(ptr)) { *************** *** 1388,1394 **** if (c != TAB && vim_isprintc(c)) { endadd = (colnr_T)(char2cells(c) - 1); ! if (coladd > endadd) /* past end of line */ endadd = 0; else coladd = 0; --- 1387,1393 ---- if (c != TAB && vim_isprintc(c)) { endadd = (colnr_T)(char2cells(c) - 1); ! if (coladd > endadd) // past end of line endadd = 0; else coladd = 0; *************** *** 1453,1459 **** { char_u *p = q; ! while (VIM_ISWHITE(*p)) /* skip to next non-white */ ++p; return p; } --- 1452,1458 ---- { char_u *p = q; ! while (VIM_ISWHITE(*p)) // skip to next non-white ++p; return p; } *************** *** 1482,1488 **** { char_u *p = q; ! while (VIM_ISDIGIT(*p)) /* skip to next non-digit */ ++p; return p; } --- 1481,1487 ---- { char_u *p = q; ! while (VIM_ISDIGIT(*p)) // skip to next non-digit ++p; return p; } *************** *** 1496,1502 **** { char_u *p = q; ! while (vim_isbdigit(*p)) /* skip to next non-digit */ ++p; return p; } --- 1495,1501 ---- { char_u *p = q; ! while (vim_isbdigit(*p)) // skip to next non-digit ++p; return p; } *************** *** 1509,1515 **** { char_u *p = q; ! while (vim_isxdigit(*p)) /* skip to next non-digit */ ++p; return p; } --- 1508,1514 ---- { char_u *p = q; ! while (vim_isxdigit(*p)) // skip to next non-digit ++p; return p; } *************** *** 1523,1529 **** { char_u *p = q; ! while (*p != NUL && !vim_isbdigit(*p)) /* skip to next digit */ ++p; return p; } --- 1522,1528 ---- { char_u *p = q; ! while (*p != NUL && !vim_isbdigit(*p)) // skip to next digit ++p; return p; } *************** *** 1536,1542 **** { char_u *p = q; ! while (*p != NUL && !VIM_ISDIGIT(*p)) /* skip to next digit */ ++p; return p; } --- 1535,1541 ---- { char_u *p = q; ! while (*p != NUL && !VIM_ISDIGIT(*p)) // skip to next digit ++p; return p; } *************** *** 1549,1555 **** { char_u *p = q; ! while (*p != NUL && !vim_isxdigit(*p)) /* skip to next digit */ ++p; return p; } --- 1548,1554 ---- { char_u *p = q; ! while (*p != NUL && !vim_isxdigit(*p)) // skip to next digit ++p; return p; } *************** *** 1617,1623 **** if (has_mbyte) return iswlower(c); #endif ! /* islower() can't handle these chars and may crash */ return FALSE; } if (enc_latin1like) --- 1616,1622 ---- if (has_mbyte) return iswlower(c); #endif ! // islower() can't handle these chars and may crash return FALSE; } if (enc_latin1like) *************** *** 1641,1647 **** if (has_mbyte) return iswupper(c); #endif ! /* islower() can't handle these chars and may crash */ return FALSE; } if (enc_latin1like) --- 1640,1646 ---- if (has_mbyte) return iswupper(c); #endif ! // islower() can't handle these chars and may crash return FALSE; } if (enc_latin1like) *************** *** 1665,1671 **** if (has_mbyte) return towupper(c); #endif ! /* toupper() can't handle these chars and may crash */ return c; } if (enc_latin1like) --- 1664,1670 ---- if (has_mbyte) return towupper(c); #endif ! // toupper() can't handle these chars and may crash return c; } if (enc_latin1like) *************** *** 1691,1697 **** if (has_mbyte) return towlower(c); #endif ! /* tolower() can't handle these chars and may crash */ return c; } if (enc_latin1like) --- 1690,1696 ---- if (has_mbyte) return towlower(c); #endif ! // tolower() can't handle these chars and may crash return c; } if (enc_latin1like) *************** *** 1740,1748 **** p = *pp; retval = atol((char *)p); ! if (*p == '-') /* skip negative sign */ ++p; ! p = skipdigits(p); /* skip to next non-digit */ *pp = p; return retval; } --- 1739,1747 ---- p = *pp; retval = atol((char *)p); ! if (*p == '-') // skip negative sign ++p; ! p = skipdigits(p); // skip to next non-digit *pp = p; return retval; } *************** *** 1808,1814 **** ++ptr; } ! /* Recognize hex, octal, and bin. */ if (ptr[0] == '0' && ptr[1] != '8' && ptr[1] != '9' && (maxlen == 0 || maxlen > 1)) { --- 1807,1813 ---- ++ptr; } ! // Recognize hex, octal, and bin. if (ptr[0] == '0' && ptr[1] != '8' && ptr[1] != '9' && (maxlen == 0 || maxlen > 1)) { *************** *** 1816,1843 **** if ((what & STR2NR_HEX) && (pre == 'X' || pre == 'x') && vim_isxdigit(ptr[2]) && (maxlen == 0 || maxlen > 2)) ! /* hexadecimal */ ptr += 2; else if ((what & STR2NR_BIN) && (pre == 'B' || pre == 'b') && vim_isbdigit(ptr[2]) && (maxlen == 0 || maxlen > 2)) ! /* binary */ ptr += 2; else { ! /* decimal or octal, default is decimal */ pre = 0; if (what & STR2NR_OCT) { ! /* Don't interpret "0", "08" or "0129" as octal. */ for (n = 1; n != maxlen && VIM_ISDIGIT(ptr[n]); ++n) { if (ptr[n] > '7') { ! pre = 0; /* can't be octal */ break; } ! pre = '0'; /* assume octal */ } } } --- 1815,1842 ---- if ((what & STR2NR_HEX) && (pre == 'X' || pre == 'x') && vim_isxdigit(ptr[2]) && (maxlen == 0 || maxlen > 2)) ! // hexadecimal ptr += 2; else if ((what & STR2NR_BIN) && (pre == 'B' || pre == 'b') && vim_isbdigit(ptr[2]) && (maxlen == 0 || maxlen > 2)) ! // binary ptr += 2; else { ! // decimal or octal, default is decimal pre = 0; if (what & STR2NR_OCT) { ! // Don't interpret "0", "08" or "0129" as octal. for (n = 1; n != maxlen && VIM_ISDIGIT(ptr[n]); ++n) { if (ptr[n] > '7') { ! pre = 0; // can't be octal break; } ! pre = '0'; // assume octal } } } *************** *** 1848,1859 **** if (pre == 'B' || pre == 'b' || ((what & STR2NR_BIN) && (what & STR2NR_FORCE))) { ! /* bin */ if (pre != 0) ! n += 2; /* skip over "0b" */ while ('0' <= *ptr && *ptr <= '1') { ! /* avoid ubsan error for overflow */ if (un <= UVARNUM_MAX / 2) un = 2 * un + (uvarnumber_T)(*ptr - '0'); else --- 1847,1858 ---- if (pre == 'B' || pre == 'b' || ((what & STR2NR_BIN) && (what & STR2NR_FORCE))) { ! // bin if (pre != 0) ! n += 2; // skip over "0b" while ('0' <= *ptr && *ptr <= '1') { ! // avoid ubsan error for overflow if (un <= UVARNUM_MAX / 2) un = 2 * un + (uvarnumber_T)(*ptr - '0'); else *************** *** 1872,1881 **** } else if (pre == '0' || ((what & STR2NR_OCT) && (what & STR2NR_FORCE))) { ! /* octal */ while ('0' <= *ptr && *ptr <= '7') { ! /* avoid ubsan error for overflow */ if (un <= UVARNUM_MAX / 8) un = 8 * un + (uvarnumber_T)(*ptr - '0'); else --- 1871,1880 ---- } else if (pre == '0' || ((what & STR2NR_OCT) && (what & STR2NR_FORCE))) { ! // octal while ('0' <= *ptr && *ptr <= '7') { ! // avoid ubsan error for overflow if (un <= UVARNUM_MAX / 8) un = 8 * un + (uvarnumber_T)(*ptr - '0'); else *************** *** 1894,1905 **** } else if (pre != 0 || ((what & STR2NR_HEX) && (what & STR2NR_FORCE))) { ! /* hex */ if (pre != 0) ! n += 2; /* skip over "0x" */ while (vim_isxdigit(*ptr)) { ! /* avoid ubsan error for overflow */ if (un <= UVARNUM_MAX / 16) un = 16 * un + (uvarnumber_T)hex2nr(*ptr); else --- 1893,1904 ---- } else if (pre != 0 || ((what & STR2NR_HEX) && (what & STR2NR_FORCE))) { ! // hex if (pre != 0) ! n += 2; // skip over "0x" while (vim_isxdigit(*ptr)) { ! // avoid ubsan error for overflow if (un <= UVARNUM_MAX / 16) un = 16 * un + (uvarnumber_T)hex2nr(*ptr); else *************** *** 1917,1928 **** } else { ! /* decimal */ while (VIM_ISDIGIT(*ptr)) { uvarnumber_T digit = (uvarnumber_T)(*ptr - '0'); ! /* avoid ubsan error for overflow */ if (un < UVARNUM_MAX / 10 || (un == UVARNUM_MAX / 10 && digit <= UVARNUM_MAX % 10)) un = 10 * un + digit; --- 1916,1927 ---- } else { ! // decimal while (VIM_ISDIGIT(*ptr)) { uvarnumber_T digit = (uvarnumber_T)(*ptr - '0'); ! // avoid ubsan error for overflow if (un < UVARNUM_MAX / 10 || (un == UVARNUM_MAX / 10 && digit <= UVARNUM_MAX % 10)) un = 10 * un + digit; *************** *** 1951,1959 **** *len = (int)(ptr - start); if (nptr != NULL) { ! if (negative) /* account for leading '-' for decimal numbers */ { ! /* avoid ubsan error for overflow */ if (un > VARNUM_MAX) *nptr = VARNUM_MIN; else --- 1950,1958 ---- *len = (int)(ptr - start); if (nptr != NULL) { ! if (negative) // account for leading '-' for decimal numbers { ! // avoid ubsan error for overflow if (un > VARNUM_MAX) *nptr = VARNUM_MIN; else *** ../vim-8.1.2367/src/cindent.c 2019-11-02 22:54:37.397188845 +0100 --- src/cindent.c 2019-11-30 20:49:29.711253134 +0100 *************** *** 1628,1636 **** * Ignore a '{' that is in a comment, makes indenting the next three lines * work. */ ! /* foo() */ ! /* { */ ! /* } */ static pos_T * find_start_brace(void) // XXX --- 1628,1636 ---- * Ignore a '{' that is in a comment, makes indenting the next three lines * work. */ ! // foo() ! // { ! // } static pos_T * find_start_brace(void) // XXX *** ../vim-8.1.2367/src/crypt.c 2019-11-02 22:54:37.397188845 +0100 --- src/crypt.c 2019-11-30 20:50:07.235141656 +0100 *************** *** 30,82 **** */ typedef struct { ! char *name; /* encryption name as used in 'cryptmethod' */ ! char *magic; /* magic bytes stored in file header */ ! int salt_len; /* length of salt, or 0 when not using salt */ ! int seed_len; /* length of seed, or 0 when not using salt */ #ifdef CRYPT_NOT_INPLACE ! int works_inplace; /* encryption/decryption can be done in-place */ #endif ! int whole_undofile; /* whole undo file is encrypted */ ! /* Optional function pointer for a self-test. */ int (* self_test_fn)(); // Function pointer for initializing encryption/decryption. int (* init_fn)(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len); ! /* Function pointers for encoding/decoding from one buffer into another. ! * Optional, however, these or the _buffer ones should be configured. */ void (*encode_fn)(cryptstate_T *state, char_u *from, size_t len, char_u *to); void (*decode_fn)(cryptstate_T *state, char_u *from, size_t len, char_u *to); ! /* Function pointers for encoding and decoding, can buffer data if needed. ! * Optional (however, these or the above should be configured). */ long (*encode_buffer_fn)(cryptstate_T *state, char_u *from, size_t len, char_u **newptr); long (*decode_buffer_fn)(cryptstate_T *state, char_u *from, size_t len, char_u **newptr); ! /* Function pointers for in-place encoding and decoding, used for ! * crypt_*_inplace(). "from" and "to" arguments will be equal. ! * These may be the same as decode_fn and encode_fn above, however an ! * algorithm may implement them in a way that is not interchangeable with ! * the crypt_(en|de)code() interface (for example because it wishes to add ! * padding to files). ! * This method is used for swap and undo files which have a rigid format. ! */ void (*encode_inplace_fn)(cryptstate_T *state, char_u *p1, size_t len, char_u *p2); void (*decode_inplace_fn)(cryptstate_T *state, char_u *p1, size_t len, char_u *p2); } cryptmethod_T; ! /* index is method_nr of cryptstate_T, CRYPT_M_* */ static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = { ! /* PK_Zip; very weak */ { "zip", "VimCrypt~01!", --- 30,81 ---- */ typedef struct { ! char *name; // encryption name as used in 'cryptmethod' ! char *magic; // magic bytes stored in file header ! int salt_len; // length of salt, or 0 when not using salt ! int seed_len; // length of seed, or 0 when not using salt #ifdef CRYPT_NOT_INPLACE ! int works_inplace; // encryption/decryption can be done in-place #endif ! int whole_undofile; // whole undo file is encrypted ! // Optional function pointer for a self-test. int (* self_test_fn)(); // Function pointer for initializing encryption/decryption. int (* init_fn)(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len); ! // Function pointers for encoding/decoding from one buffer into another. ! // Optional, however, these or the _buffer ones should be configured. void (*encode_fn)(cryptstate_T *state, char_u *from, size_t len, char_u *to); void (*decode_fn)(cryptstate_T *state, char_u *from, size_t len, char_u *to); ! // Function pointers for encoding and decoding, can buffer data if needed. ! // Optional (however, these or the above should be configured). long (*encode_buffer_fn)(cryptstate_T *state, char_u *from, size_t len, char_u **newptr); long (*decode_buffer_fn)(cryptstate_T *state, char_u *from, size_t len, char_u **newptr); ! // Function pointers for in-place encoding and decoding, used for ! // crypt_*_inplace(). "from" and "to" arguments will be equal. ! // These may be the same as decode_fn and encode_fn above, however an ! // algorithm may implement them in a way that is not interchangeable with ! // the crypt_(en|de)code() interface (for example because it wishes to add ! // padding to files). ! // This method is used for swap and undo files which have a rigid format. void (*encode_inplace_fn)(cryptstate_T *state, char_u *p1, size_t len, char_u *p2); void (*decode_inplace_fn)(cryptstate_T *state, char_u *p1, size_t len, char_u *p2); } cryptmethod_T; ! // index is method_nr of cryptstate_T, CRYPT_M_* static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = { ! // PK_Zip; very weak { "zip", "VimCrypt~01!", *************** *** 93,99 **** crypt_zip_encode, crypt_zip_decode, }, ! /* Blowfish/CFB + SHA-256 custom key derivation; implementation issues. */ { "blowfish", "VimCrypt~02!", --- 92,98 ---- crypt_zip_encode, crypt_zip_decode, }, ! // Blowfish/CFB + SHA-256 custom key derivation; implementation issues. { "blowfish", "VimCrypt~02!", *************** *** 110,116 **** crypt_blowfish_encode, crypt_blowfish_decode, }, ! /* Blowfish/CFB + SHA-256 custom key derivation; fixed. */ { "blowfish2", "VimCrypt~03!", --- 109,115 ---- crypt_blowfish_encode, crypt_blowfish_decode, }, ! // Blowfish/CFB + SHA-256 custom key derivation; fixed. { "blowfish2", "VimCrypt~03!", *************** *** 127,137 **** crypt_blowfish_encode, crypt_blowfish_decode, }, ! /* NOTE: when adding a new method, use some random bytes for the magic key, ! * to avoid that a text file is recognized as encrypted. */ }; ! #define CRYPT_MAGIC_LEN 12 /* cannot change */ static char crypt_magic_head[] = "VimCrypt~"; /* --- 126,136 ---- crypt_blowfish_encode, crypt_blowfish_decode, }, ! // NOTE: when adding a new method, use some random bytes for the magic key, ! // to avoid that a text file is recognized as encrypted. }; ! #define CRYPT_MAGIC_LEN 12 // cannot change static char crypt_magic_head[] = "VimCrypt~"; /* *************** *** 363,371 **** if (seed_len > 0) seed = *header + CRYPT_MAGIC_LEN + salt_len; ! /* TODO: Should this be crypt method specific? (Probably not worth ! * it). sha2_seed is pretty bad for large amounts of entropy, so make ! * that into something which is suitable for anything. */ sha2_seed(salt, salt_len, seed, seed_len); } --- 362,370 ---- if (seed_len > 0) seed = *header + CRYPT_MAGIC_LEN + salt_len; ! // TODO: Should this be crypt method specific? (Probably not worth ! // it). sha2_seed is pretty bad for large amounts of entropy, so make ! // that into something which is suitable for anything. sha2_seed(salt, salt_len, seed, seed_len); } *************** *** 401,410 **** cryptmethod_T *method = &cryptmethods[state->method_nr]; if (method->encode_buffer_fn != NULL) ! /* Has buffer function, pass through. */ return method->encode_buffer_fn(state, from, len, newptr); if (len == 0) ! /* Not buffering, just return EOF. */ return (long)len; *newptr = alloc(len); --- 400,409 ---- cryptmethod_T *method = &cryptmethods[state->method_nr]; if (method->encode_buffer_fn != NULL) ! // Has buffer function, pass through. return method->encode_buffer_fn(state, from, len, newptr); if (len == 0) ! // Not buffering, just return EOF. return (long)len; *newptr = alloc(len); *************** *** 429,439 **** cryptmethod_T *method = &cryptmethods[state->method_nr]; if (method->decode_buffer_fn != NULL) ! /* Has buffer function, pass through. */ return method->decode_buffer_fn(state, ptr, len, newptr); if (len == 0) ! /* Not buffering, just return EOF. */ return len; *newptr = alloc(len); --- 428,438 ---- cryptmethod_T *method = &cryptmethods[state->method_nr]; if (method->decode_buffer_fn != NULL) ! // Has buffer function, pass through. return method->decode_buffer_fn(state, ptr, len, newptr); if (len == 0) ! // Not buffering, just return EOF. return len; *newptr = alloc(len); *************** *** 542,548 **** char_u * crypt_get_key( int store, ! int twice) /* Ask for the key twice. */ { char_u *p1, *p2 = NULL; int round; --- 541,547 ---- char_u * crypt_get_key( int store, ! int twice) // Ask for the key twice. { char_u *p1, *p2 = NULL; int round; *************** *** 568,574 **** crypt_free_key(p1); crypt_free_key(p2); p2 = NULL; ! round = -1; /* do it again */ continue; } --- 567,573 ---- crypt_free_key(p1); crypt_free_key(p2); p2 = NULL; ! round = -1; // do it again continue; } *************** *** 583,589 **** p2 = p1; } ! /* since the user typed this, no need to wait for return */ if (msg_didout) msg_putchar('\n'); need_wait_return = FALSE; --- 582,588 ---- p2 = p1; } ! // since the user typed this, no need to wait for return if (msg_didout) msg_putchar('\n'); need_wait_return = FALSE; *************** *** 611,614 **** } } ! #endif /* FEAT_CRYPT */ --- 610,613 ---- } } ! #endif // FEAT_CRYPT *** ../vim-8.1.2367/src/crypt_zip.c 2019-05-28 23:08:12.052648779 +0200 --- src/crypt_zip.c 2019-11-30 20:50:30.635070642 +0100 *************** *** 23,32 **** * problem since this code was originally created in Europe and India. */ ! /* Need a type that should be 32 bits. 64 also works but wastes space. */ ! typedef unsigned int u32_T; /* int is at least 32 bits */ ! /* The state of encryption, referenced by cryptstate_T. */ typedef struct { u32_T keys[3]; } zip_state_T; --- 23,32 ---- * problem since this code was originally created in Europe and India. */ ! // Need a type that should be 32 bits. 64 also works but wastes space. ! typedef unsigned int u32_T; // int is at least 32 bits ! // The state of encryption, referenced by cryptstate_T. typedef struct { u32_T keys[3]; } zip_state_T; *************** *** 151,154 **** } } ! #endif /* FEAT_CRYPT */ --- 151,154 ---- } } ! #endif // FEAT_CRYPT *** ../vim-8.1.2367/src/version.c 2019-11-30 19:48:42.650673642 +0100 --- src/version.c 2019-11-30 20:31:30.171597790 +0100 *************** *** 739,740 **** --- 739,742 ---- { /* Add new patch number below this line */ + /**/ + 2368, /**/ -- Although the scythe isn't pre-eminent among the weapons of war, anyone who has been on the wrong end of, say, a peasants' revolt will know that in skilled hands it is fearsome. -- (Terry Pratchett, Mort) /// 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 ///