aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/charset.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-02-17 07:15:24 +0800
committerGitHub <noreply@github.com>2023-02-17 07:15:24 +0800
commit0326ef2f41a5c18c6cfd2c1b1dda95f7b309a5c4 (patch)
tree2b3acf10e9fd820e13184ccf4ab794f8b87400b5 /src/nvim/charset.c
parent6dfabd0145c712e1419dcd6d5ce9192d766adbe3 (diff)
downloadrneovim-0326ef2f41a5c18c6cfd2c1b1dda95f7b309a5c4.tar.gz
rneovim-0326ef2f41a5c18c6cfd2c1b1dda95f7b309a5c4.tar.bz2
rneovim-0326ef2f41a5c18c6cfd2c1b1dda95f7b309a5c4.zip
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) https://github.com/vim/vim/commit/1d87e11a1ef201b26ed87585fba70182ad0c468a Co-authored-by: cero1988 <mirkoceroni@mirkoceroni.it>
Diffstat (limited to 'src/nvim/charset.c')
-rw-r--r--src/nvim/charset.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index c4c7c5f387..1cfb5350f3 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -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,9 +570,9 @@ 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.
///
@@ -581,11 +580,24 @@ char_u *transchar_buf(const buf_T *buf, int c)
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;
}