mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.1314: :messages behavior depends on 'fileformat' of current buffer (#22286)
Problem: :messages behavior depends on 'fileformat' of current buffer.
Solution: Pass the buffer pointer to where it is used. (Mirko Ceroni,
closes vim/vim#11995)
1d87e11a1e
Co-authored-by: cero1988 <mirkoceroni@mirkoceroni.it>
This commit is contained in:
parent
6dfabd0145
commit
0326ef2f41
@ -547,7 +547,6 @@ char *transchar(int c)
|
||||
}
|
||||
|
||||
char_u *transchar_buf(const buf_T *buf, int c)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
int i = 0;
|
||||
if (IS_SPECIAL(c)) {
|
||||
@ -571,21 +570,34 @@ char_u *transchar_buf(const buf_T *buf, int c)
|
||||
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.
|
||||
///
|
||||
/// Checks for an illegal UTF-8 byte.
|
||||
/// Checks for an illegal UTF-8 byte. Uses 'fileformat' of the current buffer.
|
||||
///
|
||||
/// @param[in] c Byte to translate.
|
||||
///
|
||||
/// @return pointer to translated character in transchar_charbuf.
|
||||
char_u *transchar_byte(const int c)
|
||||
FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
return transchar_byte_buf(curbuf, c);
|
||||
}
|
||||
|
||||
/// Like transchar_buf(), but called with a byte instead of a character.
|
||||
///
|
||||
/// Checks for an illegal UTF-8 byte. Uses 'fileformat' of "buf", unless it is NULL.
|
||||
///
|
||||
/// @param[in] c Byte to translate.
|
||||
///
|
||||
/// @return pointer to translated character in transchar_charbuf.
|
||||
char_u *transchar_byte_buf(const buf_T *buf, const int c)
|
||||
FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
if (c >= 0x80) {
|
||||
transchar_nonprint(curbuf, transchar_charbuf, c);
|
||||
transchar_nonprint(buf, transchar_charbuf, c);
|
||||
return transchar_charbuf;
|
||||
}
|
||||
return (char_u *)transchar(c);
|
||||
return transchar_buf(buf, c);
|
||||
}
|
||||
|
||||
/// Convert non-printable characters to 2..4 printable ones
|
||||
@ -598,12 +610,11 @@ char_u *transchar_byte(const int c)
|
||||
/// @param[in] c Character to convert. NUL is assumed to be NL according to
|
||||
/// `:h NL-used-for-NUL`.
|
||||
void transchar_nonprint(const buf_T *buf, char_u *charbuf, int c)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
if (c == NL) {
|
||||
// we use newline in place of a NUL
|
||||
c = NUL;
|
||||
} else if ((c == CAR) && (get_fileformat(buf) == EOL_MAC)) {
|
||||
} else if (buf != NULL && c == CAR && get_fileformat(buf) == EOL_MAC) {
|
||||
// we use CR in place of NL in this case
|
||||
c = NL;
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ bool emsg(const char *s)
|
||||
|
||||
void emsg_invreg(int name)
|
||||
{
|
||||
semsg(_("E354: Invalid register name: '%s'"), transchar(name));
|
||||
semsg(_("E354: Invalid register name: '%s'"), transchar_buf(NULL, name));
|
||||
}
|
||||
|
||||
/// Print an error message with unknown number of arguments
|
||||
@ -1531,7 +1531,7 @@ char *msg_outtrans_one(char *p, int attr)
|
||||
msg_outtrans_len_attr(p, l, attr);
|
||||
return p + l;
|
||||
}
|
||||
msg_puts_attr((const char *)transchar_byte((uint8_t)(*p)), attr);
|
||||
msg_puts_attr((const char *)transchar_byte_buf(NULL, (uint8_t)(*p)), attr);
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
@ -1576,14 +1576,14 @@ int msg_outtrans_len_attr(const char *msgstr, int len, int attr)
|
||||
msg_puts_attr_len(plain_start, str - plain_start, attr);
|
||||
}
|
||||
plain_start = str + mb_l;
|
||||
msg_puts_attr((const char *)transchar(c),
|
||||
msg_puts_attr((const char *)transchar_buf(NULL, c),
|
||||
(attr == 0 ? HL_ATTR(HLF_8) : attr));
|
||||
retval += char2cells(c);
|
||||
}
|
||||
len -= mb_l - 1;
|
||||
str += mb_l;
|
||||
} else {
|
||||
s = (char *)transchar_byte((uint8_t)(*str));
|
||||
s = (char *)transchar_byte_buf(NULL, (uint8_t)(*str));
|
||||
if (s[1] != NUL) {
|
||||
// Unprintable char: print the printable chars so far and the
|
||||
// translation of the unprintable char.
|
||||
@ -1665,7 +1665,7 @@ int msg_outtrans_special(const char *strstart, bool from, int maxlen)
|
||||
}
|
||||
if (text[0] != NUL && text[1] == NUL) {
|
||||
// single-byte character or illegal byte
|
||||
text = (char *)transchar_byte((uint8_t)text[0]);
|
||||
text = (char *)transchar_byte_buf(NULL, (uint8_t)text[0]);
|
||||
}
|
||||
const int len = vim_strsize((char *)text);
|
||||
if (maxlen > 0 && retval + len >= maxlen) {
|
||||
@ -1911,7 +1911,7 @@ void msg_prt_line(char *s, int list)
|
||||
s--;
|
||||
} else if (c != NUL && (n = byte2cells(c)) > 1) {
|
||||
n_extra = n - 1;
|
||||
p_extra = (char *)transchar_byte(c);
|
||||
p_extra = (char *)transchar_byte_buf(NULL, c);
|
||||
c_extra = NUL;
|
||||
c_final = NUL;
|
||||
c = (unsigned char)(*p_extra++);
|
||||
|
Loading…
Reference in New Issue
Block a user