To: vim-dev@vim.org Subject: Patch 6.2.498 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.2.498 Problem: Non-latin1 help files are not properly supported. Solution: Support utf-8 help files and convert them to 'encoding' when needed. Files: src/fileio.c *** ../vim-6.2.497/src/fileio.c Tue Apr 20 12:52:53 2004 --- src/fileio.c Sun Apr 25 14:21:50 2004 *************** *** 259,264 **** --- 259,266 ---- #ifdef FEAT_MBYTE int can_retry; int conv_error = FALSE; /* conversion error detected */ + int keep_dest_enc = FALSE; /* don't retry when char doesn't fit + in destination encoding */ linenr_T illegal_byte = 0; /* line nr with illegal byte */ char_u *tmpname = NULL; /* name of 'charconvert' output file */ int fio_flags = 0; *************** *** 745,758 **** } else if (curbuf->b_help) { /* Help files are either utf-8 or latin1. Try utf-8 first, if this ! * fails it must be latin1. Only do this when 'encoding' is utf-8 to ! * avoid [converted] remarks all the time. */ fenc = (char_u *)"latin1"; ! if (enc_utf8) { fenc_next = fenc; fenc = (char_u *)"utf-8"; } fenc_alloced = FALSE; } --- 747,785 ---- } else if (curbuf->b_help) { + char_u firstline[80]; + /* 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 && TOLOWER_ASC(fname[STRLEN(fname) - 1]) == '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 = vim_read(fd, firstline, 80); ! lseek(fd, (off_t)0L, SEEK_SET); ! for (p = firstline; p < firstline + len; ++p) ! if (*p >= 0x80) ! { ! c = TRUE; ! break; ! } ! } ! ! if (c) { fenc_next = fenc; fenc = (char_u *)"utf-8"; + + /* 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. */ + keep_dest_enc = TRUE; } fenc_alloced = FALSE; } *************** *** 1534,1540 **** /* character doesn't fit in latin1, retry with * another fenc when possible, otherwise just * report the error. */ ! if (can_retry) goto rewind_retry; *dest = 0xBF; conv_error = TRUE; --- 1561,1567 ---- /* character doesn't fit in latin1, retry with * another fenc when possible, otherwise just * report the error. */ ! if (can_retry && !keep_dest_enc) goto rewind_retry; *dest = 0xBF; conv_error = TRUE; *** ../vim-6.2.497/src/version.c Sun Apr 25 14:42:43 2004 --- src/version.c Sun Apr 25 14:44:21 2004 *************** *** 639,640 **** --- 639,642 ---- { /* Add new patch number below this line */ + /**/ + 498, /**/ -- Don't Panic! -- The Hitchhiker's Guide to the Galaxy /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///