Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windowsでhelpgrepが日本語マッチしない #95

Closed
mattn opened this issue Nov 28, 2011 · 7 comments
Closed

windowsでhelpgrepが日本語マッチしない #95

mattn opened this issue Nov 28, 2011 · 7 comments

Comments

@mattn
Copy link
Member

@mattn mattn commented Nov 28, 2011

jaxはutf-8ですが、encoding=cp932なwindowsでhelpgrepすると、utf-8のまま正規表現されているらしく、何もヒットしない。
encoding=utf-8でhelpgrepするとマッチする。

コードはquickfix.cの3945あたり。mch_openした後で、何も変換していない。

@mattn

This comment has been minimized.

Copy link
Member Author

@mattn mattn commented Nov 28, 2011

パッチ。安定してから出します。

diff -r 379a6398d462 src/quickfix.c
--- a/src/quickfix.c    Wed Oct 26 23:48:21 2011 +0200
+++ b/src/quickfix.c    Mon Nov 28 19:52:13 2011 +0900
@@ -3914,6 +3914,14 @@
     regmatch.rm_ic = FALSE;
     if (regmatch.regprog != NULL)
     {
+#ifdef FEAT_MBYTE
+   vimconv_T   vc;
+
+   vc.vc_type = CONV_NONE;
+   if (!enc_utf8)
+       convert_setup(&vc, "utf-8", p_enc);
+#endif
+
    /* create a new quickfix list */
    qf_new_list(qi, *eap->cmdlinep);

@@ -3948,21 +3956,31 @@
            lnum = 1;
            while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
            {
-               if (vim_regexec(&regmatch, IObuff, (colnr_T)0))
+
+               char_u      *line = IObuff;
+#ifdef FEAT_MBYTE
+               if (vc.vc_type != CONV_NONE) {
+               line = string_convert(&vc, IObuff, NULL);
+               if (!line)
+                   line = IObuff;
+               }
+#endif
+
+               if (vim_regexec(&regmatch, line, (colnr_T)0))
                {
-               int l = (int)STRLEN(IObuff);
+               int l = (int)STRLEN(line);

                /* remove trailing CR, LF, spaces, etc. */
-               while (l > 0 && IObuff[l - 1] <= ' ')
-                    IObuff[--l] = NUL;
+               while (l > 0 && line[l - 1] <= ' ')
+                    line[--l] = NUL;

                if (qf_add_entry(qi, &prevp,
                        NULL,   /* dir */
                        fnames[fi],
                        0,
-                       IObuff,
+                       line,
                        lnum,
-                       (int)(regmatch.startp[0] - IObuff)
+                       (int)(regmatch.startp[0] - line)
                                + 1, /* col */
                        FALSE,  /* vis_col */
                        NULL,   /* search pattern */
@@ -3975,6 +3993,11 @@
                    break;
                }
                }
+#ifdef FEAT_MBYTE
+               if (line != IObuff)
+               vim_free(line);
+#endif
+
                ++lnum;
                line_breakcheck();
            }
@@ -3990,6 +4013,11 @@
    qi->qf_lists[qi->qf_curlist].qf_ptr =
        qi->qf_lists[qi->qf_curlist].qf_start;
    qi->qf_lists[qi->qf_curlist].qf_index = 1;
+
+#ifdef FEAT_MBYTE
+   if (vc.vc_type != CONV_NONE)
+       convert_setup(&vc, NULL, NULL);
+#endif
     }

     if (p_cpo == empty_option)
@mattn

This comment has been minimized.

Copy link
Member Author

@mattn mattn commented Nov 28, 2011

上記のままpatch送付。

@ynkdir

This comment has been minimized.

Copy link
Member

@ynkdir ynkdir commented Nov 28, 2011

latin1 or utf-8 の判定がいるような気がします

@mattn

This comment has been minimized.

Copy link
Member Author

@mattn mattn commented Nov 28, 2011

ですね。パッチ更新しときます。

@ynkdir

This comment has been minimized.

Copy link
Member

@ynkdir ynkdir commented Nov 29, 2011

ヘルプファイルの一行目を見てマルチバイト文字があればutf-8、なければlatin1と判定するほうの話です。
すみません。

@mattn

This comment has been minimized.

Copy link
Member Author

@mattn mattn commented Nov 29, 2011

あー、であればファイルの拡張子を見るべきかと。

@h-east

This comment has been minimized.

Copy link
Member

@h-east h-east commented Jan 10, 2012

Patch 7.3.397で取り込まれました!
https://groups.google.com/d/topic/vim_dev/QeQ5OG2YXrg/discussion

@mattn mattn closed this Jan 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.