From fe074611cd5b3319a3f639f68289df6a718e64eb Mon Sep 17 00:00:00 2001 From: Jurica Bradarić Date: Sun, 6 Oct 2019 05:35:48 +0200 Subject: vim-patch:8.1.1371: cannot recover from a swap file #11081 Problem: Cannot recover from a swap file. Solution: Do not expand environment variables in the swap file name. Do not check the extension when we already know a file is a swap file. (Ken Takata, closes 4415, closes vim/vim#4369) https://github.com/vim/vim/commit/99499b1c05f85f83876b828eea3f6e14f0f407b4 --- src/nvim/memline.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 15dd2767a2..f1d6ee064c 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -738,10 +738,10 @@ static void add_b0_fenc(ZERO_BL *b0p, buf_T *buf) } -/* - * Try to recover curbuf from the .swp file. - */ -void ml_recover(void) +/// Try to recover curbuf from the .swp file. +/// @param checkext If true, check the extension and detect whether it is a +/// swap file. +void ml_recover(bool checkext) { buf_T *buf = NULL; memfile_T *mfp = NULL; @@ -785,7 +785,7 @@ void ml_recover(void) if (fname == NULL) /* When there is no file name */ fname = (char_u *)""; len = (int)STRLEN(fname); - if (len >= 4 + if (checkext && len >= 4 && STRNICMP(fname + len - 4, ".s", 2) == 0 && vim_strchr((char_u *)"abcdefghijklmnopqrstuvw", TOLOWER_ASC(fname[len - 2])) != NULL @@ -1375,7 +1375,9 @@ recover_names ( if (curbuf->b_ml.ml_mfp != NULL && (p = curbuf->b_ml.ml_mfp->mf_fname) != NULL) { for (int i = 0; i < num_files; i++) { - if (path_full_compare(p, files[i], true) & kEqualFiles) { + // Do not expand wildcards, on Windows would try to expand + // "%tmp%" in "%tmp%file" + if (path_full_compare(p, files[i], true, false) & kEqualFiles) { // Remove the name from files[i]. Move further entries // down. When the array becomes empty free it here, since // FreeWild() won't be called below. -- cgit From 3de4dc539ae938c5fdeddbdf25722fd1f6d9c77c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 19 Oct 2019 23:11:31 +0200 Subject: vim-patch:8.1.2180: Error E303 is not useful when 'directory' is empty (#11257) Problem: Error E303 is not useful when 'directory' is empty. Solution: Skip the error message. (Daniel Hahler, vim/vim#5067) https://github.com/vim/vim/commit/00e192becd50a38cb21a1bc3f86fcc7a21f8ee88 --- src/nvim/memline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index f1d6ee064c..b85c23e50f 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -523,9 +523,9 @@ void ml_open_file(buf_T *buf) } } - if (mfp->mf_fname == NULL) { /* Failed! */ - need_wait_return = TRUE; /* call wait_return later */ - ++no_wait_return; + if (*p_dir != NUL && mfp->mf_fname == NULL) { + need_wait_return = true; // call wait_return later + no_wait_return++; (void)EMSG2(_( "E303: Unable to open swap file for \"%s\", recovery impossible"), buf_spname(buf) != NULL ? buf_spname(buf) : buf->b_fname); -- cgit From 6dceaf33613cc4d1ff361053e65ce801ce2678cf Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 12 Oct 2019 18:25:27 -0400 Subject: vim-patch:8.1.0014: qf_init_ext() is too long Problem: qf_init_ext() is too long. Solution: Split it into multiple functions. (Yegappan Lakshmanan, closes vim/vim#2939) https://github.com/vim/vim/commit/6053f2d29a979ffed1fe01b0a2f28e23750530e9 --- src/nvim/memline.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index b85c23e50f..05cc62bb33 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1929,6 +1929,7 @@ int ml_append_buf( colnr_T len, // length of new line, including NUL, or 0 bool newfile // flag, see above ) + FUNC_ATTR_NONNULL_ARG(1) { if (buf->b_ml.ml_mfp == NULL) return FAIL; -- cgit From 1ff5b60cb96aea3b3f6ef9e2792c5797dfda72dc Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Mon, 18 Nov 2019 15:38:27 +0800 Subject: vim-patch:8.1.0251: support full paths for 'backupdir' #11269 Problem: Using a full path is supported for 'directory' but not for 'backupdir'. (Mikolaj Machowski) Solution: Support 'backupdir' as well. (Christian Brabandt, closes vim/vim#179) https://github.com/vim/vim/commit/b782ba475a3f8f2b0be99dda164ba4545347f60f --- src/nvim/memline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 05cc62bb33..2824d57f49 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1437,7 +1437,7 @@ recover_names ( * Append the full path to name with path separators made into percent * signs, to dir. An unnamed buffer is handled as "" (/"") */ -static char *make_percent_swname(const char *dir, char *name) +char *make_percent_swname(const char *dir, char *name) FUNC_ATTR_NONNULL_ARG(1) { char *d = NULL; -- cgit From 8819b5c06eea1f47d6a8f2c00498e55a580d5519 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 24 Nov 2019 23:10:25 -0500 Subject: vim-patch:8.1.0461: quickfix: change comment style #11453 Problem: Quickfix code uses too many /* */ comments. Solution: Change to // comments. (Yegappan Lakshmanan) https://github.com/vim/vim/commit/00bf8cd2115be7c14258aee48c0a7568147c9cd7 --- src/nvim/memline.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 2824d57f49..e5ba17a0a7 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -540,7 +540,7 @@ void ml_open_file(buf_T *buf) /// file, or reading into an existing buffer, create a swap file now. /// /// @param newfile reading file into new buffer -void check_need_swap(int newfile) +void check_need_swap(bool newfile) { int old_msg_silent = msg_silent; // might be reset by an E325 message msg_silent = 0; // If swap dialog prompts for input, user needs to see it! @@ -937,8 +937,9 @@ void ml_recover(bool checkext) */ if (directly) { expand_env(b0p->b0_fname, NameBuff, MAXPATHL); - if (setfname(curbuf, NameBuff, NULL, TRUE) == FAIL) + if (setfname(curbuf, NameBuff, NULL, true) == FAIL) { goto theend; + } } home_replace(NULL, mfp->mf_fname, NameBuff, MAXPATHL, TRUE); -- cgit From 94ad6652f11e1d6791292d0a2bf2d777ddeefbcc Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 24 Jan 2020 23:40:47 -0500 Subject: Remove enc_utf8,has_mbyte dead code --- src/nvim/memline.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index e5ba17a0a7..922b684120 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1802,9 +1802,10 @@ char_u *ml_get(linenr_T lnum) /* * Return pointer to position "pos". */ -char_u *ml_get_pos(pos_T *pos) +char_u *ml_get_pos(const pos_T *pos) + FUNC_ATTR_NONNULL_ALL { - return ml_get_buf(curbuf, pos->lnum, FALSE) + pos->col; + return ml_get_buf(curbuf, pos->lnum, false) + pos->col; } /* -- cgit From bde4f47eb29b757e3282fb08ae6ee844941b1f65 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 9 Feb 2020 21:48:11 -0500 Subject: vim-patch:8.1.2223: cannot see what buffer an ml_get error is for Problem: Cannot see what buffer an ml_get error is for. Solution: Add the buffer number and name in the message https://github.com/vim/vim/commit/cb86893114ce33dc9c7bd4ff992b05c12406b35d --- src/nvim/memline.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 922b684120..fa7c39cc65 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1863,7 +1863,10 @@ errorret: // Avoid giving this message for a recursive call, may happen // when the GUI redraws part of the text. recursive++; - IEMSGN(_("E316: ml_get: cannot find line %" PRId64), lnum); + get_trans_bufname(buf); + shorten_dir(NameBuff); + iemsgf(_("E316: ml_get: cannot find line %" PRId64 " in buffer %d %s"), + lnum, buf->b_fnum, NameBuff); recursive--; } goto errorret; -- cgit From 573671b1fbcbc43b622391f50f4df30594f14751 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 20 Mar 2020 05:50:16 -0400 Subject: vim-patch:8.1.1313: warnings for using localtime() and ctime() Problem: Warnings for using localtime() and ctime(). Solution: Use localtime_r() if available. Avoid using ctime(). https://github.com/vim/vim/commit/63d2555c9cefbbeeca3ec87fdd5d241e9488f9dd --- src/nvim/memline.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index fa7c39cc65..b695d0e139 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1504,16 +1504,15 @@ static time_t swapfile_info(char_u *fname) int fd; struct block0 b0; time_t x = (time_t)0; - char *p; #ifdef UNIX char uname[B0_UNAME_SIZE]; #endif - /* print the swap file date */ + // print the swap file date FileInfo file_info; if (os_fileinfo((char *)fname, &file_info)) { #ifdef UNIX - /* print name of owner of the file */ + // print name of owner of the file if (os_get_uname(file_info.stat.st_uid, uname, B0_UNAME_SIZE) == OK) { MSG_PUTS(_(" owned by: ")); msg_outtrans((char_u *)uname); @@ -1522,11 +1521,8 @@ static time_t swapfile_info(char_u *fname) #endif MSG_PUTS(_(" dated: ")); x = file_info.stat.st_mtim.tv_sec; - p = ctime(&x); // includes '\n' - if (p == NULL) - MSG_PUTS("(invalid)\n"); - else - MSG_PUTS(p); + char ctime_buf[50]; + MSG_PUTS(os_ctime_r(&x, ctime_buf, sizeof(ctime_buf))); } /* @@ -3267,15 +3263,13 @@ attention_message ( ) { assert(buf->b_fname != NULL); - time_t x, sx; - char *p; ++no_wait_return; (void)EMSG(_("E325: ATTENTION")); MSG_PUTS(_("\nFound a swap file by the name \"")); msg_home_replace(fname); MSG_PUTS("\"\n"); - sx = swapfile_info(fname); + const time_t swap_mtime = swapfile_info(fname); MSG_PUTS(_("While opening file \"")); msg_outtrans(buf->b_fname); MSG_PUTS("\"\n"); @@ -3284,14 +3278,12 @@ attention_message ( MSG_PUTS(_(" CANNOT BE FOUND")); } else { MSG_PUTS(_(" dated: ")); - x = file_info.stat.st_mtim.tv_sec; - p = ctime(&x); // includes '\n' - if (p == NULL) - MSG_PUTS("(invalid)\n"); - else - MSG_PUTS(p); - if (sx != 0 && x > sx) + time_t x = file_info.stat.st_mtim.tv_sec; + char ctime_buf[50]; + MSG_PUTS(os_ctime_r(&x, ctime_buf, sizeof(ctime_buf))); + if (swap_mtime != 0 && x > swap_mtime) { MSG_PUTS(_(" NEWER than swap file!\n")); + } } /* Some of these messages are long to allow translation to * other languages. */ -- cgit From d20142a31f40140ae789e20d86094ecccb84d6fb Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Fri, 24 Apr 2020 18:38:48 +0200 Subject: folds: decrease reliance on global 'curwin' TODO in a future commit: - remains 2 instances of changed_lines that dont take into account buffer --- src/nvim/memline.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index b695d0e139..8c66154b6f 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -2389,6 +2389,11 @@ static int ml_append_int( } void ml_add_deleted_len(char_u *ptr, ssize_t len) +{ + ml_add_deleted_len_buf(curbuf, ptr, len); +} + +void ml_add_deleted_len_buf(buf_T *buf, char_u *ptr, ssize_t len) { if (inhibit_delete_count) { return; @@ -2396,15 +2401,21 @@ void ml_add_deleted_len(char_u *ptr, ssize_t len) if (len == -1) { len = STRLEN(ptr); } - curbuf->deleted_bytes += len+1; - if (curbuf->update_need_codepoints) { - mb_utflen(ptr, len, &curbuf->deleted_codepoints, - &curbuf->deleted_codeunits); - curbuf->deleted_codepoints++; // NL char - curbuf->deleted_codeunits++; + buf->deleted_bytes += len+1; + if (buf->update_need_codepoints) { + mb_utflen(ptr, len, &buf->deleted_codepoints, + &buf->deleted_codeunits); + buf->deleted_codepoints++; // NL char + buf->deleted_codeunits++; } } + +int ml_replace(linenr_T lnum, char_u *line, bool copy) +{ + return ml_replace_buf(curbuf, lnum, line, copy); +} + /* * Replace line lnum, with buffering, in current buffer. * @@ -2416,13 +2427,13 @@ void ml_add_deleted_len(char_u *ptr, ssize_t len) * * return FAIL for failure, OK otherwise */ -int ml_replace(linenr_T lnum, char_u *line, bool copy) +int ml_replace_buf(buf_T *buf, linenr_T lnum, char_u *line, bool copy) { if (line == NULL) /* just checking... */ return FAIL; /* When starting up, we might still need to create the memfile */ - if (curbuf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) + if (buf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) return FAIL; bool readlen = true; @@ -2430,22 +2441,22 @@ int ml_replace(linenr_T lnum, char_u *line, bool copy) if (copy) { line = vim_strsave(line); } - if (curbuf->b_ml.ml_line_lnum != lnum) { // other line buffered - ml_flush_line(curbuf); // flush it - } else if (curbuf->b_ml.ml_flags & ML_LINE_DIRTY) { // same line allocated - ml_add_deleted_len(curbuf->b_ml.ml_line_ptr, -1); + if (buf->b_ml.ml_line_lnum != lnum) { // other line buffered + ml_flush_line(buf); // flush it + } else if (buf->b_ml.ml_flags & ML_LINE_DIRTY) { // same line allocated + ml_add_deleted_len(buf->b_ml.ml_line_ptr, -1); readlen = false; // already added the length - xfree(curbuf->b_ml.ml_line_ptr); // free it + xfree(buf->b_ml.ml_line_ptr); // free it } - if (readlen && kv_size(curbuf->update_callbacks)) { - ml_add_deleted_len(ml_get_buf(curbuf, lnum, false), -1); + if (readlen && kv_size(buf->update_callbacks)) { + ml_add_deleted_len(ml_get_buf(buf, lnum, false), -1); } - curbuf->b_ml.ml_line_ptr = line; - curbuf->b_ml.ml_line_lnum = lnum; - curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; + buf->b_ml.ml_line_ptr = line; + buf->b_ml.ml_line_lnum = lnum; + buf->b_ml.ml_flags = (buf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; return OK; } @@ -3990,7 +4001,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) int extra = 0; /* take care of cached line first */ - ml_flush_line(curbuf); + ml_flush_line(buf); if (buf->b_ml.ml_usedchunks == -1 || buf->b_ml.ml_chunksize == NULL -- cgit From 6da348f22020b08c868282a1c72473ae4659e4c7 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Fri, 24 Apr 2020 20:01:31 +0200 Subject: lint: fix linting issues --- src/nvim/memline.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 8c66154b6f..6e074b3249 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -2432,9 +2432,10 @@ int ml_replace_buf(buf_T *buf, linenr_T lnum, char_u *line, bool copy) if (line == NULL) /* just checking... */ return FAIL; - /* When starting up, we might still need to create the memfile */ - if (buf->b_ml.ml_mfp == NULL && open_buffer(FALSE, NULL, 0) == FAIL) + // When starting up, we might still need to create the memfile + if (buf->b_ml.ml_mfp == NULL && open_buffer(false, NULL, 0) == FAIL) { return FAIL; + } bool readlen = true; @@ -4000,7 +4001,7 @@ long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp, bool no_ff) int ffdos = !no_ff && (get_fileformat(buf) == EOL_DOS); int extra = 0; - /* take care of cached line first */ + // take care of cached line first ml_flush_line(buf); if (buf->b_ml.ml_usedchunks == -1 -- cgit From 2c34780c32c479950ee6c6797b5fbb88b0f9fd51 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Thu, 16 Jul 2020 09:28:18 +0200 Subject: buffer_updates: emit valid old_byte_size Test this using treesitter highlighting, which is based on this old_byte_size. --- src/nvim/memline.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 6e074b3249..7f55296096 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1876,8 +1876,10 @@ errorret: buf->b_ml.ml_line_lnum = lnum; buf->b_ml.ml_flags &= ~ML_LINE_DIRTY; } - if (will_change) + if (will_change) { buf->b_ml.ml_flags |= (ML_LOCKED_DIRTY | ML_LOCKED_POS); + ml_add_deleted_len_buf(buf, buf->b_ml.ml_line_ptr, -1); + } return buf->b_ml.ml_line_ptr; } -- cgit From be057197d3b74df1886c3b5e2026276ef7c2116e Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Mon, 20 Jul 2020 23:28:05 +0200 Subject: buffer_updates: prefer using ml_add_deleted_len_buf --- src/nvim/memline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/memline.c') diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 7f55296096..d5788d96b3 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -2447,14 +2447,14 @@ int ml_replace_buf(buf_T *buf, linenr_T lnum, char_u *line, bool copy) if (buf->b_ml.ml_line_lnum != lnum) { // other line buffered ml_flush_line(buf); // flush it } else if (buf->b_ml.ml_flags & ML_LINE_DIRTY) { // same line allocated - ml_add_deleted_len(buf->b_ml.ml_line_ptr, -1); + ml_add_deleted_len_buf(buf, buf->b_ml.ml_line_ptr, -1); readlen = false; // already added the length xfree(buf->b_ml.ml_line_ptr); // free it } if (readlen && kv_size(buf->update_callbacks)) { - ml_add_deleted_len(ml_get_buf(buf, lnum, false), -1); + ml_add_deleted_len_buf(buf, ml_get_buf(buf, lnum, false), -1); } buf->b_ml.ml_line_ptr = line; @@ -2541,7 +2541,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) // Line should always have an NL char internally (represented as NUL), // even if 'noeol' is set. assert(line_size >= 1); - ml_add_deleted_len((char_u *)dp + line_start, line_size-1); + ml_add_deleted_len_buf(buf, (char_u *)dp + line_start, line_size-1); /* * special case: If there is only one line in the data block it becomes empty. -- cgit