Open kotatsuyaki opened 5 years ago
I can reproduce this error on the following system:
After looking at the source code for a bit, I think I get what's happening.
If you look at the function ycmd--get-basic-request-data
, defined in ycmd.el, you'll notice that it's constructing a server request that has the field "file_data" which in turn has the field "contents". The data accompanying this field name is defined using ycmd--encode-string
. Said function uses (encode-coding-string s 'utf-8 t)
.
Problems arise when you try to insert the return value of (encode-coding-string s 'utf-8 t)
into a temp buffer when s
is string containing CJK characters. As an example, run the following code in your *scratch* buffer:
(with-temp-file (make-temp-file "dummy-file")
(insert (encode-coding-string "你好" 'utf-8 t)))
It raises a very similar warning.
Here's a guess. The characters 你 and 好 are multi-byte, and when you run toggle-enable-multibyte-characters
in your buffer they show up as "\344\275\240" and "\345\245\275" respectively, which matches the numbers in your screenshot. The temporary file probably doesn't support multi-byte characters and then shoots a warning. I feel justified in saying this because running the following code doesn't give me any warning:
(with-temp-file (make-temp-file "dummy-file")
(toggle-enable-multibyte-characters)
(insert (encode-coding-string "你好" 'utf-8))
)
This is very similar to #387 from a few years ago. A workaround that avoids the issue entirely is changing the request backend away from curl: (setq request-backend 'url-retrieve)
. However, url-retrieve
has its own bugs, so I hope there's a fix soon.
Here's a better workaround - use advice to change the request backend just for YCMD:
(defun my-ycmd--request-url-retrieve (f &rest args)
"Change ‘request-backend’ in ‘ycmd--request’ to ‘url-retrieve’.
Work around https://github.com/abingham/emacs-ycmd/issues/496.
"
(let ((request-backend 'url-retrieve))
(apply f args)))
(advice-add 'ycmd--request :around #'my-ycmd--request-url-retrieve)
This should be fixed by https://github.com/tkf/emacs-request/pull/136, and the workaround is no longer needed after that PR. Please close the issue if you upgrade request and no longer see this issue.
Recently I found out that when using
emacs-ycmd
, if a javascript file contains CJK characters, then each time when I open the file, emacs keeps asking me toSelect coding system (default raw-test):
. The interesting part is that it's not the javascript file itself (otherwise I know how to configure it) but a*temp file*
buffer, which leads me to believe that this is triggered by ycmd.The screenshot below gives an idea of what's happening:
The
*temp file*
's content is like this:This is part of the
*ycmd-server*
output, which I think is related to the issue.4.19.45-1-MANJARO
GNU Emacs 26.2
20190416.807
, installed via MELPA