使用原生emacs,编辑一个路径存在中文的代码文件(比如~/文档/test.cpp),eglot/flymake无法正常工作?
起因是我最近在尝试写个人的emacs配置,所以希望尽可能做到轻量化,于是走的是eglot+flymake路线
我一开始以为是我个人配置问题,问了半天AI,对着各种.el配置文件调试了半天
但是当我卸载所有配置,使用原生emacs编辑那个有问题的代码文件(也就是路径存在中文的),eglot/flymake也不会工作,因此不可能是我的配置问题(如图所示)
于是我又调试了一阵CMake编译数据库还有.clangd编译器配置文件之类的,当然没有任何收获
最后,在机缘巧合之下,当我编辑某个路径没有中文的文件时(比如~/admin/test.cpp),eglot/flymake神奇地工作了(如图所示)
总结:
因为我个人是从spacemacs入门的,所以对lsp-mode和flycheck还算有一点了解——在原生emacs基础上,使用lsp-mode+flymake或者eglot+flycheck都不会因为文件路径出现无法工作的问题,因此我无法将问题锁定到某个特定的插件上。
这个问题是否说明,对于我这样的新手应当放弃为了轻量化而追求使用eglot + flymake?
或者也许有某种我尚不知晓的解决方案,可以解决类似的中文路径问题?
eglot 支持包含 中文路径/中文名称 的文件.
flymake 貌似不支持.
请尝试 emacs -Q 编辑文件看看是什么问题?
1 个赞
wsug
3
flymake好像是不支持,搜了下我以前的贴子,flycheck语法检查在win7不支持中文文件名的问题,解决了 ,换flycheck也很可能还是会遇到不支持的情况。
1 个赞
我向eglot提交过相关问题, 作者表示他没有其他编辑器所以无法测试
My suggestion, Eli, is to ask in [email protected], Emacs help or even
better Reddit (you have or at least has an account there, I think).
I often see other people comparing Eglot and Emacs to other clients on
other editors… They can easily do an experiment… I don’t have other
editors or LSP clients set up.
Gosto
João Távora
我的解决方法是
(defun myfix/eglot-uri-to-path (uri)
"Convert URI to file path, helped by `eglot-current-server'."
(when (keywordp uri) (setq uri (substring (symbol-name uri) 1)))
(let* ((server (eglot-current-server))
(remote-prefix (and server (eglot--trampish-p server)))
(url (url-generic-parse-url uri)))
;; Only parse file:// URIs, leave other URI untouched as
;; `file-name-handler-alist' should know how to handle them
;; (bug#58790).
(if (string= "file" (url-type url))
(let* ((retval (decode-coding-string (url-unhex-string (url-filename url)) 'utf-8))
;; Remove the leading "/" for local MS Windows-style paths.
(normalized (if (and (not remote-prefix)
(eq system-type 'windows-nt)
(cl-plusp (length retval)))
(w32-long-file-name (substring retval 1))
retval)))
(concat remote-prefix normalized))
uri)))
(advice-add 'eglot-uri-to-path :override #'myfix/eglot-uri-to-path)
1 个赞
虽然代码完全看不懂,不过直接复制到配置文件里就生效了,感谢