To: vim_dev@googlegroups.com Subject: Patch 8.2.0943 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0943 Problem: Displaying ^M or ^J depends on current buffer. Solution: Pass the displayed buffer to transchar(). (closes #6225) Files: src/drawline.c, src/charset.c, src/proto/charset.pro, src/ex_cmds.c, src/gui_beval.c, src/message.c, src/testdir/test_display.vim, src/testdir/dumps/Test_display_unprintable_01.dump, src/testdir/dumps/Test_display_unprintable_02.dump *** ../vim-8.2.0942/src/drawline.c 2020-05-16 14:07:34.816736239 +0200 --- src/drawline.c 2020-06-10 14:06:41.888312695 +0200 *************** *** 1764,1770 **** { // head byte at end of line mb_l = 1; ! transchar_nonprint(extra, c); } else { --- 1764,1770 ---- { // head byte at end of line mb_l = 1; ! transchar_nonprint(wp->w_buffer, extra, c); } else { *************** *** 2224,2230 **** } else if (c != NUL) { ! p_extra = transchar(c); if (n_extra == 0) n_extra = byte2cells(c) - 1; #ifdef FEAT_RIGHTLEFT --- 2224,2230 ---- } else if (c != NUL) { ! p_extra = transchar_buf(wp->w_buffer, c); if (n_extra == 0) n_extra = byte2cells(c) - 1; #ifdef FEAT_RIGHTLEFT *** ../vim-8.2.0942/src/charset.c 2020-06-02 21:38:18.719856309 +0200 --- src/charset.c 2020-06-10 13:55:39.190313437 +0200 *************** *** 499,516 **** * Also doesn't work for the first byte of a multi-byte, "c" must be a * character! */ ! static char_u transchar_buf[7]; char_u * transchar(int c) { int i; i = 0; if (IS_SPECIAL(c)) // special key code, display as ~@ char { ! transchar_buf[0] = '~'; ! transchar_buf[1] = '@'; i = 2; c = K_SECOND(c); } --- 499,522 ---- * Also doesn't work for the first byte of a multi-byte, "c" must be a * character! */ ! static char_u transchar_charbuf[7]; char_u * transchar(int c) { + return transchar_buf(curbuf, c); + } + + char_u * + transchar_buf(buf_T *buf, int c) + { int i; i = 0; if (IS_SPECIAL(c)) // special key code, display as ~@ char { ! transchar_charbuf[0] = '~'; ! transchar_charbuf[1] = '@'; i = 2; c = K_SECOND(c); } *************** *** 524,535 **** )) || (c < 256 && vim_isprintc_strict(c))) { // printable character ! transchar_buf[i] = c; ! transchar_buf[i + 1] = NUL; } else ! transchar_nonprint(transchar_buf + i, c); ! return transchar_buf; } /* --- 530,541 ---- )) || (c < 256 && vim_isprintc_strict(c))) { // printable character ! transchar_charbuf[i] = c; ! transchar_charbuf[i + 1] = NUL; } else ! transchar_nonprint(buf, transchar_charbuf + i, c); ! return transchar_charbuf; } /* *************** *** 541,567 **** { if (enc_utf8 && c >= 0x80) { ! transchar_nonprint(transchar_buf, c); ! return transchar_buf; } return transchar(c); } /* * Convert non-printable character to two or more printable characters in ! * "buf[]". "buf" needs to be able to hold five bytes. * Does NOT work for multi-byte characters, c must be <= 255. */ void ! 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 --- 547,573 ---- { if (enc_utf8 && c >= 0x80) { ! transchar_nonprint(curbuf, transchar_charbuf, c); ! return transchar_charbuf; } return transchar(c); } /* * Convert non-printable character to two or more printable characters in ! * "buf[]". "charbuf" needs to be able to hold five bytes. * Does NOT work for multi-byte characters, c must be <= 255. */ void ! transchar_nonprint(buf_T *buf, char_u *charbuf, int c) { if (c == NL) c = NUL; // we use newline in place of a NUL ! else if (c == CAR && get_fileformat(buf) == EOL_MAC) c = NL; // we use CR in place of NL in this case if (dy_flags & DY_UHEX) // 'display' has "uhex" ! transchar_hex(charbuf, c); #ifdef EBCDIC // For EBCDIC only the characters 0-63 and 255 are not printable *************** *** 570,604 **** 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; } else if (enc_utf8 && c >= 0x80) { ! transchar_hex(buf, c); } #ifndef EBCDIC else if (c >= ' ' + 0x80 && c <= '~' + 0x80) // 0xa0 - 0xfe { ! buf[0] = '|'; ! buf[1] = c - 0x80; ! buf[2] = NUL; } #else else if (c < 64) { ! buf[0] = '~'; ! buf[1] = MetaChar(c); ! buf[2] = NUL; } #endif else // 0x80 - 0x9f and 0xff --- 576,610 ---- else if (c <= 0x7f) // 0x00 - 0x1f and 0x7f #endif { ! charbuf[0] = '^'; #ifdef EBCDIC if (c == DEL) ! charbuf[1] = '?'; // DEL displayed as ^? else ! charbuf[1] = CtrlChar(c); #else ! charbuf[1] = c ^ 0x40; // DEL displayed as ^? #endif ! charbuf[2] = NUL; } else if (enc_utf8 && c >= 0x80) { ! transchar_hex(charbuf, c); } #ifndef EBCDIC else if (c >= ' ' + 0x80 && c <= '~' + 0x80) // 0xa0 - 0xfe { ! charbuf[0] = '|'; ! charbuf[1] = c - 0x80; ! charbuf[2] = NUL; } #else else if (c < 64) { ! charbuf[0] = '~'; ! charbuf[1] = MetaChar(c); ! charbuf[2] = NUL; } #endif else // 0x80 - 0x9f and 0xff *************** *** 607,619 **** * TODO: EBCDIC I don't know what to do with this chars, so I display * them as '~?' for now */ ! buf[0] = '~'; #ifdef EBCDIC ! buf[1] = '?'; // 0xff displayed as ~? #else ! buf[1] = (c - 0x80) ^ 0x40; // 0xff displayed as ~? #endif ! buf[2] = NUL; } } --- 613,625 ---- * TODO: EBCDIC I don't know what to do with this chars, so I display * them as '~?' for now */ ! charbuf[0] = '~'; #ifdef EBCDIC ! charbuf[1] = '?'; // 0xff displayed as ~? #else ! charbuf[1] = (c - 0x80) ^ 0x40; // 0xff displayed as ~? #endif ! charbuf[2] = NUL; } } *** ../vim-8.2.0942/src/proto/charset.pro 2019-12-12 12:55:15.000000000 +0100 --- src/proto/charset.pro 2020-06-10 13:55:43.754298080 +0200 *************** *** 5,12 **** char_u *transstr(char_u *s); char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen); char_u *transchar(int c); char_u *transchar_byte(int c); ! void transchar_nonprint(char_u *buf, int c); void transchar_hex(char_u *buf, int c); int byte2cells(int b); int char2cells(int c); --- 5,13 ---- char_u *transstr(char_u *s); char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen); char_u *transchar(int c); + char_u *transchar_buf(buf_T *buf, int c); char_u *transchar_byte(int c); ! void transchar_nonprint(buf_T *buf, char_u *charbuf, int c); void transchar_hex(char_u *buf, int c); int byte2cells(int b); int char2cells(int c); *** ../vim-8.2.0942/src/ex_cmds.c 2020-05-30 20:30:42.892816571 +0200 --- src/ex_cmds.c 2020-06-10 13:53:49.038684129 +0200 *************** *** 69,75 **** #endif )) { ! transchar_nonprint(buf3, c); vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); } else --- 69,75 ---- #endif )) { ! transchar_nonprint(curbuf, buf3, c); vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); } else *************** *** 2556,2562 **** } /* ! * if the file was changed we may not be allowed to abandon it * - 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 */ --- 2556,2562 ---- } /* ! * If the file was changed we may not be allowed to abandon it: * - 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 */ *** ../vim-8.2.0942/src/gui_beval.c 2019-12-01 21:59:15.000000000 +0100 --- src/gui_beval.c 2020-06-10 13:54:45.510494042 +0200 *************** *** 840,846 **** } else { ! transchar_nonprint(pdest, *p); // ^X outlen = 2; } if (pixel != INVALCOLOR) --- 840,846 ---- } else { ! transchar_nonprint(curbuf, pdest, *p); // ^X outlen = 2; } if (pixel != INVALCOLOR) *** ../vim-8.2.0942/src/message.c 2020-05-29 22:41:36.925691046 +0200 --- src/message.c 2020-06-10 13:54:50.590476953 +0200 *************** *** 1752,1758 **** // For multi-byte characters check for an illegal byte. if (has_mbyte && MB_BYTE2LEN(*str) > len) { ! transchar_nonprint(buf, c); *sp = str + 1; return buf; } --- 1752,1758 ---- // For multi-byte characters check for an illegal byte. if (has_mbyte && MB_BYTE2LEN(*str) > len) { ! transchar_nonprint(curbuf, buf, c); *sp = str + 1; return buf; } *** ../vim-8.2.0942/src/testdir/test_display.vim 2020-04-08 21:50:18.872619665 +0200 --- src/testdir/test_display.vim 2020-06-10 14:15:06.651203642 +0200 *************** *** 197,199 **** --- 197,222 ---- call delete(longName) 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, "\\\") + call VerifyScreenDump(buf, 'Test_display_unprintable_02', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xunix.txt') + call delete('Xmac.txt') + call delete(filename) + endfunc *** ../vim-8.2.0942/src/testdir/dumps/Test_display_unprintable_01.dump 2020-06-10 14:15:46.439101803 +0200 --- src/testdir/dumps/Test_display_unprintable_01.dump 2020-06-10 14:03:40.656698059 +0200 *************** *** 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 *** ../vim-8.2.0942/src/testdir/dumps/Test_display_unprintable_02.dump 2020-06-10 14:15:46.443101792 +0200 --- src/testdir/dumps/Test_display_unprintable_02.dump 2020-06-10 14:14:05.447357255 +0200 *************** *** 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 *** ../vim-8.2.0942/src/version.c 2020-06-10 13:12:25.071026049 +0200 --- src/version.c 2020-06-10 14:15:31.083141278 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 943, /**/ -- A vacation is a period of travel during which you find that you took twice as many clothes and half as much money as you needed. /// 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 ///