mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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 #6225)
This commit is contained in:
@@ -499,18 +499,24 @@ str_foldcase(
|
|||||||
* 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[7];
|
static char_u transchar_charbuf[7];
|
||||||
|
|
||||||
char_u *
|
char_u *
|
||||||
transchar(int c)
|
transchar(int c)
|
||||||
|
{
|
||||||
|
return transchar_buf(curbuf, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
char_u *
|
||||||
|
transchar_buf(buf_T *buf, int c)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (IS_SPECIAL(c)) // special key code, display as ~@ char
|
if (IS_SPECIAL(c)) // 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);
|
||||||
}
|
}
|
||||||
@@ -524,12 +530,12 @@ transchar(int c)
|
|||||||
)) || (c < 256 && vim_isprintc_strict(c)))
|
)) || (c < 256 && vim_isprintc_strict(c)))
|
||||||
{
|
{
|
||||||
// printable character
|
// printable character
|
||||||
transchar_buf[i] = c;
|
transchar_charbuf[i] = c;
|
||||||
transchar_buf[i + 1] = NUL;
|
transchar_charbuf[i + 1] = NUL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
transchar_nonprint(transchar_buf + i, c);
|
transchar_nonprint(buf, transchar_charbuf + i, c);
|
||||||
return transchar_buf;
|
return transchar_charbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -541,27 +547,27 @@ transchar_byte(int c)
|
|||||||
{
|
{
|
||||||
if (enc_utf8 && c >= 0x80)
|
if (enc_utf8 && 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert non-printable character to two or more printable characters in
|
* Convert non-printable character to two or more printable characters in
|
||||||
* "buf[]". "buf" needs to be able to hold five bytes.
|
* "buf[]". "charbuf" needs to be able to hold five bytes.
|
||||||
* Does NOT work for multi-byte characters, c must be <= 255.
|
* Does NOT work for multi-byte characters, c must be <= 255.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
transchar_nonprint(char_u *buf, int c)
|
transchar_nonprint(buf_T *buf, char_u *charbuf, int c)
|
||||||
{
|
{
|
||||||
if (c == NL)
|
if (c == NL)
|
||||||
c = NUL; // we use newline in place of a NUL
|
c = NUL; // we use newline in place of a NUL
|
||||||
else if (c == CAR && get_fileformat(curbuf) == EOL_MAC)
|
else if (c == CAR && get_fileformat(buf) == EOL_MAC)
|
||||||
c = NL; // we use CR in place of NL in this case
|
c = NL; // we use CR in place of NL in this case
|
||||||
|
|
||||||
if (dy_flags & DY_UHEX) // 'display' has "uhex"
|
if (dy_flags & DY_UHEX) // 'display' has "uhex"
|
||||||
transchar_hex(buf, c);
|
transchar_hex(charbuf, c);
|
||||||
|
|
||||||
#ifdef EBCDIC
|
#ifdef EBCDIC
|
||||||
// For EBCDIC only the characters 0-63 and 255 are not printable
|
// For EBCDIC only the characters 0-63 and 255 are not printable
|
||||||
@@ -570,35 +576,35 @@ transchar_nonprint(char_u *buf, int c)
|
|||||||
else if (c <= 0x7f) // 0x00 - 0x1f and 0x7f
|
else if (c <= 0x7f) // 0x00 - 0x1f and 0x7f
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
buf[0] = '^';
|
charbuf[0] = '^';
|
||||||
#ifdef EBCDIC
|
#ifdef EBCDIC
|
||||||
if (c == DEL)
|
if (c == DEL)
|
||||||
buf[1] = '?'; // DEL displayed as ^?
|
charbuf[1] = '?'; // DEL displayed as ^?
|
||||||
else
|
else
|
||||||
buf[1] = CtrlChar(c);
|
charbuf[1] = CtrlChar(c);
|
||||||
#else
|
#else
|
||||||
buf[1] = c ^ 0x40; // DEL displayed as ^?
|
charbuf[1] = c ^ 0x40; // DEL displayed as ^?
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
buf[2] = NUL;
|
charbuf[2] = NUL;
|
||||||
}
|
}
|
||||||
else if (enc_utf8 && c >= 0x80)
|
else if (enc_utf8 && c >= 0x80)
|
||||||
{
|
{
|
||||||
transchar_hex(buf, c);
|
transchar_hex(charbuf, c);
|
||||||
}
|
}
|
||||||
#ifndef EBCDIC
|
#ifndef EBCDIC
|
||||||
else if (c >= ' ' + 0x80 && c <= '~' + 0x80) // 0xa0 - 0xfe
|
else if (c >= ' ' + 0x80 && c <= '~' + 0x80) // 0xa0 - 0xfe
|
||||||
{
|
{
|
||||||
buf[0] = '|';
|
charbuf[0] = '|';
|
||||||
buf[1] = c - 0x80;
|
charbuf[1] = c - 0x80;
|
||||||
buf[2] = NUL;
|
charbuf[2] = NUL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
else if (c < 64)
|
else if (c < 64)
|
||||||
{
|
{
|
||||||
buf[0] = '~';
|
charbuf[0] = '~';
|
||||||
buf[1] = MetaChar(c);
|
charbuf[1] = MetaChar(c);
|
||||||
buf[2] = NUL;
|
charbuf[2] = NUL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else // 0x80 - 0x9f and 0xff
|
else // 0x80 - 0x9f and 0xff
|
||||||
@@ -607,13 +613,13 @@ transchar_nonprint(char_u *buf, int c)
|
|||||||
* TODO: EBCDIC I don't know what to do with this chars, so I display
|
* TODO: EBCDIC I don't know what to do with this chars, so I display
|
||||||
* them as '~?' for now
|
* them as '~?' for now
|
||||||
*/
|
*/
|
||||||
buf[0] = '~';
|
charbuf[0] = '~';
|
||||||
#ifdef EBCDIC
|
#ifdef EBCDIC
|
||||||
buf[1] = '?'; // 0xff displayed as ~?
|
charbuf[1] = '?'; // 0xff displayed as ~?
|
||||||
#else
|
#else
|
||||||
buf[1] = (c - 0x80) ^ 0x40; // 0xff displayed as ~?
|
charbuf[1] = (c - 0x80) ^ 0x40; // 0xff displayed as ~?
|
||||||
#endif
|
#endif
|
||||||
buf[2] = NUL;
|
charbuf[2] = NUL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1764,7 +1764,7 @@ win_line(
|
|||||||
{
|
{
|
||||||
// head byte at end of line
|
// head byte at end of line
|
||||||
mb_l = 1;
|
mb_l = 1;
|
||||||
transchar_nonprint(extra, c);
|
transchar_nonprint(wp->w_buffer, extra, c);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -2224,7 +2224,7 @@ win_line(
|
|||||||
}
|
}
|
||||||
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;
|
||||||
#ifdef FEAT_RIGHTLEFT
|
#ifdef FEAT_RIGHTLEFT
|
||||||
|
@@ -69,7 +69,7 @@ do_ascii(exarg_T *eap UNUSED)
|
|||||||
#endif
|
#endif
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
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
|
||||||
@@ -2556,7 +2556,7 @@ do_ecmd(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
@@ -840,7 +840,7 @@ set_printable_label_text(GtkLabel *label, char_u *text)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
transchar_nonprint(pdest, *p); // ^X
|
transchar_nonprint(curbuf, pdest, *p); // ^X
|
||||||
outlen = 2;
|
outlen = 2;
|
||||||
}
|
}
|
||||||
if (pixel != INVALCOLOR)
|
if (pixel != INVALCOLOR)
|
||||||
|
@@ -1752,7 +1752,7 @@ str2special(
|
|||||||
// For multi-byte characters check for an illegal byte.
|
// For multi-byte characters check for an illegal byte.
|
||||||
if (has_mbyte && MB_BYTE2LEN(*str) > len)
|
if (has_mbyte && MB_BYTE2LEN(*str) > len)
|
||||||
{
|
{
|
||||||
transchar_nonprint(buf, c);
|
transchar_nonprint(curbuf, buf, c);
|
||||||
*sp = str + 1;
|
*sp = str + 1;
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@@ -5,8 +5,9 @@ void trans_characters(char_u *buf, int bufsize);
|
|||||||
char_u *transstr(char_u *s);
|
char_u *transstr(char_u *s);
|
||||||
char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen);
|
char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen);
|
||||||
char_u *transchar(int c);
|
char_u *transchar(int c);
|
||||||
|
char_u *transchar_buf(buf_T *buf, int c);
|
||||||
char_u *transchar_byte(int c);
|
char_u *transchar_byte(int c);
|
||||||
void transchar_nonprint(char_u *buf, int c);
|
void transchar_nonprint(buf_T *buf, char_u *charbuf, int c);
|
||||||
void transchar_hex(char_u *buf, int c);
|
void transchar_hex(char_u *buf, int c);
|
||||||
int byte2cells(int b);
|
int byte2cells(int b);
|
||||||
int char2cells(int c);
|
int char2cells(int c);
|
||||||
|
9
src/testdir/dumps/Test_display_unprintable_01.dump
Normal file
9
src/testdir/dumps/Test_display_unprintable_01.dump
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
>m+0&#ffffff0|a|c| @46
|
||||||
|
|^+0#0000e05&|J|t+0#0000000&|w|o|^+0#0000e05&|J| +0#0000000&@42
|
||||||
|
|~+0#4040ff13&| @48
|
||||||
|
|X+3#0000000&|m|a|c|.|t|x|t| @23|1|,|1| @11|A|l@1
|
||||||
|
|u+0&&|n|i|x|^+0#0000e05&|M| +0#0000000&@43
|
||||||
|
|t|w|o| @46
|
||||||
|
|~+0#4040ff13&| @48
|
||||||
|
|X+1#0000000&|u|n|i|x|.|t|x|t| @22|1|,|1| @11|A|l@1
|
||||||
|
|"+0&&|X|m|a|c|.|t|x|t|"| |[|n|o|e|o|l|]|[|m|a|c|]| |2|L|,| |9|C| @19
|
9
src/testdir/dumps/Test_display_unprintable_02.dump
Normal file
9
src/testdir/dumps/Test_display_unprintable_02.dump
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|m+0&#ffffff0|a|c| @46
|
||||||
|
|^+0#0000e05&|J|t+0#0000000&|w|o|^+0#0000e05&|J| +0#0000000&@42
|
||||||
|
|~+0#4040ff13&| @48
|
||||||
|
|X+1#0000000&|m|a|c|.|t|x|t| @23|1|,|1| @11|A|l@1
|
||||||
|
>u+0&&|n|i|x|^+0#0000e05&|M| +0#0000000&@43
|
||||||
|
|t|w|o| @46
|
||||||
|
|~+0#4040ff13&| @48
|
||||||
|
|X+3#0000000&|u|n|i|x|.|t|x|t| @22|1|,|1| @11|A|l@1
|
||||||
|
| +0&&@49
|
@@ -197,3 +197,26 @@ 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
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
943,
|
||||||
/**/
|
/**/
|
||||||
942,
|
942,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user