vim-patch:8.2.0943: displaying ^M or ^J depends on current buffer

Problem:    Displaying ^M or ^J depends on current buffer.
Solution:   Pass the displayed buffer to transchar(). (closes vim/vim#6225)
32ee627750

N/A patches for version.c:

vim-patch:8.2.0862: ":term ++curwin" makes the current buffer hidden

Problem:    ":term ++curwin" makes the current buffer hidden. (Harm te
            Hennepe)
Solution:   Do not hide the current buffer. (closes vim/vim#6170)
b10090928c
This commit is contained in:
Jan Edmund Lazo
2020-10-18 00:01:05 -04:00
parent 9817d99140
commit 54d07b648c
6 changed files with 59 additions and 28 deletions

View File

@@ -509,7 +509,7 @@ char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
// Does NOT work for multi-byte characters, c must be <= 255. // Does NOT work for multi-byte characters, c must be <= 255.
// Also doesn't work for the first byte of a multi-byte, "c" must be a // Also doesn't work for the first byte of a multi-byte, "c" must be a
// character! // character!
static char_u transchar_buf[11]; static char_u transchar_charbuf[11];
/// Translate a character into a printable one, leaving printable ASCII intact /// Translate a character into a printable one, leaving printable ASCII intact
/// ///
@@ -519,12 +519,18 @@ static char_u transchar_buf[11];
/// ///
/// @return translated character into a static buffer. /// @return translated character into a static buffer.
char_u *transchar(int c) char_u *transchar(int c)
{
return transchar_buf(curbuf, c);
}
char_u *transchar_buf(const buf_T *buf, int c)
FUNC_ATTR_NONNULL_ALL
{ {
int i = 0; int i = 0;
if (IS_SPECIAL(c)) { if (IS_SPECIAL(c)) {
// special key code, display as ~@ char // special key code, display as ~@ char
transchar_buf[0] = '~'; transchar_charbuf[0] = '~';
transchar_buf[1] = '@'; transchar_charbuf[1] = '@';
i = 2; i = 2;
c = K_SECOND(c); c = K_SECOND(c);
} }
@@ -532,14 +538,14 @@ char_u *transchar(int c)
if ((!chartab_initialized && (((c >= ' ') && (c <= '~')))) if ((!chartab_initialized && (((c >= ' ') && (c <= '~'))))
|| ((c <= 0xFF) && vim_isprintc_strict(c))) { || ((c <= 0xFF) && vim_isprintc_strict(c))) {
// printable character // printable character
transchar_buf[i] = (char_u)c; transchar_charbuf[i] = (char_u)c;
transchar_buf[i + 1] = NUL; transchar_charbuf[i + 1] = NUL;
} else if (c <= 0xFF) { } else if (c <= 0xFF) {
transchar_nonprint(transchar_buf + i, c); transchar_nonprint(buf, transchar_charbuf + i, c);
} else { } else {
transchar_hex((char *)transchar_buf + i, c); transchar_hex((char *)transchar_charbuf + i, c);
} }
return transchar_buf; return transchar_charbuf;
} }
/// Like transchar(), but called with a byte instead of a character /// Like transchar(), but called with a byte instead of a character
@@ -548,13 +554,13 @@ char_u *transchar(int c)
/// ///
/// @param[in] c Byte to translate. /// @param[in] c Byte to translate.
/// ///
/// @return pointer to translated character in transchar_buf. /// @return pointer to translated character in transchar_charbuf.
char_u *transchar_byte(const int c) char_u *transchar_byte(const int c)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_WARN_UNUSED_RESULT
{ {
if (c >= 0x80) { if (c >= 0x80) {
transchar_nonprint(transchar_buf, c); transchar_nonprint(curbuf, transchar_charbuf, c);
return transchar_buf; return transchar_charbuf;
} }
return transchar(c); return transchar(c);
} }
@@ -563,16 +569,18 @@ char_u *transchar_byte(const int c)
/// ///
/// @warning Does not work for multi-byte characters, c must be <= 255. /// @warning Does not work for multi-byte characters, c must be <= 255.
/// ///
/// @param[out] buf Buffer to store result in, must be able to hold at least /// @param[in] buf Required to check the file format
/// 5 bytes (conversion result + NUL). /// @param[out] charbuf Buffer to store result in, must be able to hold
/// at least 5 bytes (conversion result + NUL).
/// @param[in] c Character to convert. NUL is assumed to be NL according to /// @param[in] c Character to convert. NUL is assumed to be NL according to
/// `:h NL-used-for-NUL`. /// `:h NL-used-for-NUL`.
void transchar_nonprint(char_u *buf, int c) void transchar_nonprint(const buf_T *buf, char_u *charbuf, int c)
FUNC_ATTR_NONNULL_ALL
{ {
if (c == NL) { if (c == NL) {
// we use newline in place of a NUL // we use newline in place of a NUL
c = NUL; c = NUL;
} else if ((c == CAR) && (get_fileformat(curbuf) == EOL_MAC)) { } else if ((c == CAR) && (get_fileformat(buf) == EOL_MAC)) {
// we use CR in place of NL in this case // we use CR in place of NL in this case
c = NL; c = NL;
} }
@@ -580,14 +588,14 @@ void transchar_nonprint(char_u *buf, int c)
if (dy_flags & DY_UHEX || c > 0x7f) { if (dy_flags & DY_UHEX || c > 0x7f) {
// 'display' has "uhex" // 'display' has "uhex"
transchar_hex((char *)buf, c); transchar_hex((char *)charbuf, c);
} else { } else {
// 0x00 - 0x1f and 0x7f // 0x00 - 0x1f and 0x7f
buf[0] = '^'; charbuf[0] = '^';
// DEL displayed as ^? // DEL displayed as ^?
buf[1] = (char_u)(c ^ 0x40); charbuf[1] = (char_u)(c ^ 0x40);
buf[2] = NUL; charbuf[2] = NUL;
} }
} }

View File

@@ -135,7 +135,7 @@ void do_ascii(const exarg_T *const eap)
char buf1[20]; char buf1[20];
if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) { if (vim_isprintc_strict(c) && (c < ' ' || c > '~')) {
char_u buf3[7]; char_u buf3[7];
transchar_nonprint(buf3, c); transchar_nonprint(curbuf, buf3, c);
vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3);
} else { } else {
buf1[0] = NUL; buf1[0] = NUL;
@@ -2240,11 +2240,9 @@ int do_ecmd(
goto theend; goto theend;
} }
/* // If the file was changed we may not be allowed to abandon it:
* if the file was changed we may not be allowed to abandon it // - if we are going to re-edit the same file
* - if we are going to re-edit the same file // - or if we are the only window on this file and if ECMD_HIDE is FALSE
* - or if we are the only window on this file and if ECMD_HIDE is FALSE
*/
if ( ((!other_file && !(flags & ECMD_OLDBUF)) if ( ((!other_file && !(flags & ECMD_OLDBUF))
|| (curbuf->b_nwindows == 1 || (curbuf->b_nwindows == 1
&& !(flags & (ECMD_HIDE | ECMD_ADDBUF)))) && !(flags & (ECMD_HIDE | ECMD_ADDBUF))))

View File

@@ -1621,7 +1621,7 @@ const char *str2special(const char **const sp, const bool replace_spaces,
// Check for an illegal byte. // Check for an illegal byte.
if (MB_BYTE2LEN((uint8_t)(*str)) > len) { if (MB_BYTE2LEN((uint8_t)(*str)) > len) {
transchar_nonprint((char_u *)buf, c); transchar_nonprint(curbuf, (char_u *)buf, c);
*sp = str + 1; *sp = str + 1;
return buf; return buf;
} }

View File

@@ -7270,7 +7270,8 @@ unsigned int get_bkc_value(buf_T *buf)
} }
/// Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC. /// Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC.
int get_fileformat(buf_T *buf) int get_fileformat(const buf_T *buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
int c = *buf->b_p_ff; int c = *buf->b_p_ff;

View File

@@ -3634,7 +3634,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
mb_utf8 = false; // don't draw as UTF-8 mb_utf8 = false; // don't draw as UTF-8
} }
} else if (c != NUL) { } else if (c != NUL) {
p_extra = transchar(c); p_extra = transchar_buf(wp->w_buffer, c);
if (n_extra == 0) { if (n_extra == 0) {
n_extra = byte2cells(c) - 1; n_extra = byte2cells(c) - 1;
} }

View File

@@ -202,6 +202,30 @@ func Test_edit_long_file_name()
call delete(longName) call delete(longName)
endfunc endfunc
func Test_unprintable_fileformats()
CheckScreendump
call writefile(["unix\r", "two"], 'Xunix.txt')
call writefile(["mac\r", "two"], 'Xmac.txt')
let lines =<< trim END
edit Xunix.txt
split Xmac.txt
edit ++ff=mac
END
let filename = 'Xunprintable'
call writefile(lines, filename)
let buf = RunVimInTerminal('-S '.filename, #{rows: 9, cols: 50})
call VerifyScreenDump(buf, 'Test_display_unprintable_01', {})
call term_sendkeys(buf, "\<C-W>\<C-W>\<C-L>")
call VerifyScreenDump(buf, 'Test_display_unprintable_02', {})
" clean up
call StopVimInTerminal(buf)
call delete('Xunix.txt')
call delete('Xmac.txt')
call delete(filename)
endfunc
" Test for scrolling that modifies buffer during visual block " Test for scrolling that modifies buffer during visual block
func Test_visual_block_scroll() func Test_visual_block_scroll()
" See test/functional/legacy/visual_mode_spec.lua " See test/functional/legacy/visual_mode_spec.lua