diff src/charset.c @ 20782:c4bce986c31a v8.2.0943

patch 8.2.0943: displaying ^M or ^J depends on current buffer Commit: https://github.com/vim/vim/commit/32ee627750e8b7b3fa6516b893e72f6e6af54710 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 10 14:16:49 2020 +0200 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 https://github.com/vim/vim/issues/6225)
author Bram Moolenaar <Bram@vim.org>
date Wed, 10 Jun 2020 14:30:04 +0200
parents 6ff992bf4c82
children ee43d943c3bb
line wrap: on
line diff
--- a/src/charset.c
+++ b/src/charset.c
@@ -499,18 +499,24 @@ str_foldcase(
  * Also doesn't work for the first byte of a multi-byte, "c" must be a
  * character!
  */
-static char_u	transchar_buf[7];
+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_buf[0] = '~';
-	transchar_buf[1] = '@';
+	transchar_charbuf[0] = '~';
+	transchar_charbuf[1] = '@';
 	i = 2;
 	c = K_SECOND(c);
     }
@@ -524,12 +530,12 @@ transchar(int c)
 		)) || (c < 256 && vim_isprintc_strict(c)))
     {
 	// printable character
-	transchar_buf[i] = c;
-	transchar_buf[i + 1] = NUL;
+	transchar_charbuf[i] = c;
+	transchar_charbuf[i + 1] = NUL;
     }
     else
-	transchar_nonprint(transchar_buf + i, c);
-    return transchar_buf;
+	transchar_nonprint(buf, transchar_charbuf + i, c);
+    return transchar_charbuf;
 }
 
 /*
@@ -541,27 +547,27 @@ transchar_byte(int c)
 {
     if (enc_utf8 && c >= 0x80)
     {
-	transchar_nonprint(transchar_buf, c);
-	return transchar_buf;
+	transchar_nonprint(curbuf, transchar_charbuf, c);
+	return transchar_charbuf;
     }
     return transchar(c);
 }
 
 /*
  * 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.
  */
     void
-transchar_nonprint(char_u *buf, int c)
+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(curbuf) == EOL_MAC)
+    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(buf, c);
+	transchar_hex(charbuf, c);
 
 #ifdef EBCDIC
     // 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
 #endif
     {
-	buf[0] = '^';
+	charbuf[0] = '^';
 #ifdef EBCDIC
 	if (c == DEL)
-	    buf[1] = '?';		// DEL displayed as ^?
+	    charbuf[1] = '?';		// DEL displayed as ^?
 	else
-	    buf[1] = CtrlChar(c);
+	    charbuf[1] = CtrlChar(c);
 #else
-	buf[1] = c ^ 0x40;		// DEL displayed as ^?
+	charbuf[1] = c ^ 0x40;		// DEL displayed as ^?
 #endif
 
-	buf[2] = NUL;
+	charbuf[2] = NUL;
     }
     else if (enc_utf8 && c >= 0x80)
     {
-	transchar_hex(buf, c);
+	transchar_hex(charbuf, c);
     }
 #ifndef EBCDIC
     else if (c >= ' ' + 0x80 && c <= '~' + 0x80)    // 0xa0 - 0xfe
     {
-	buf[0] = '|';
-	buf[1] = c - 0x80;
-	buf[2] = NUL;
+	charbuf[0] = '|';
+	charbuf[1] = c - 0x80;
+	charbuf[2] = NUL;
     }
 #else
     else if (c < 64)
     {
-	buf[0] = '~';
-	buf[1] = MetaChar(c);
-	buf[2] = NUL;
+	charbuf[0] = '~';
+	charbuf[1] = MetaChar(c);
+	charbuf[2] = NUL;
     }
 #endif
     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
 	 * them as '~?' for now
 	 */
-	buf[0] = '~';
+	charbuf[0] = '~';
 #ifdef EBCDIC
-	buf[1] = '?';			// 0xff displayed as ~?
+	charbuf[1] = '?';			// 0xff displayed as ~?
 #else
-	buf[1] = (c - 0x80) ^ 0x40;	// 0xff displayed as ~?
+	charbuf[1] = (c - 0x80) ^ 0x40;	// 0xff displayed as ~?
 #endif
-	buf[2] = NUL;
+	charbuf[2] = NUL;
     }
 }