aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-04-16 20:39:57 +0300
committerZyX <kp-pav@yandex.ru>2017-04-16 20:39:57 +0300
commit0f7c260cd873c996da9badb42b9135cd15bee285 (patch)
treee032c4e679e04ecc486e254b3692b33c83c9f72c /src
parente3de83a8291cf0ef1481a2631dda04b37b6e3412 (diff)
downloadrneovim-0f7c260cd873c996da9badb42b9135cd15bee285.tar.gz
rneovim-0f7c260cd873c996da9badb42b9135cd15bee285.tar.bz2
rneovim-0f7c260cd873c996da9badb42b9135cd15bee285.zip
fileio: Simlify help files encoding detection
Most of code is dead when enc_utf8 is always true. Given that `c` is being reused for other purposes I left it set to 1 just in case.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/fileio.c43
1 files changed, 8 insertions, 35 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index c1b8203ed1..74fa5aa1de 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -730,43 +730,16 @@ readfile (
fenc = (char_u *)""; /* binary: don't convert */
fenc_alloced = FALSE;
} else if (curbuf->b_help) {
- char_u firstline[80];
- int fc;
-
- /* Help files are either utf-8 or latin1. Try utf-8 first, if this
- * fails it must be latin1.
- * Always do this when 'encoding' is "utf-8". Otherwise only do
- * this when needed to avoid [converted] remarks all the time.
- * It is needed when the first line contains non-ASCII characters.
- * That is only in *.??x files. */
- fenc = (char_u *)"latin1";
- c = enc_utf8;
- if (!c && !read_stdin) {
- fc = fname[STRLEN(fname) - 1];
- if (TOLOWER_ASC(fc) == 'x') {
- /* Read the first line (and a bit more). Immediately rewind to
- * the start of the file. If the read() fails "len" is -1. */
- len = read_eintr(fd, firstline, 80);
- lseek(fd, (off_t)0L, SEEK_SET);
- for (p = firstline; p < firstline + len; ++p)
- if (*p >= 0x80) {
- c = TRUE;
- break;
- }
- }
- }
+ // Help files are either utf-8 or latin1. Try utf-8 first, if this
+ // fails it must be latin1.
+ // It is needed when the first line contains non-ASCII characters.
+ // That is only in *.??x files.
+ fenc_next = (char_u *)"latin1";
+ fenc = (char_u *)"utf-8";
- if (c) {
- fenc_next = fenc;
- fenc = (char_u *)"utf-8";
+ fenc_alloced = false;
- /* When the file is utf-8 but a character doesn't fit in
- * 'encoding' don't retry. In help text editing utf-8 bytes
- * doesn't make sense. */
- if (!enc_utf8)
- keep_dest_enc = TRUE;
- }
- fenc_alloced = FALSE;
+ c = 1;
} else if (*p_fencs == NUL) {
fenc = curbuf->b_p_fenc; /* use format from buffer */
fenc_alloced = FALSE;