emacs 24.5.1
editorconfig.el 20150831.1054 (melpa)
状況
editorconfigを入れてから、バッファにマルチバイト文字が含まれる際、
保存時にエンコードエラーが出るようになった。
sample
These default coding systems were tried to encode text
in the buffer `xxxxx.txt':
(undecided (123 . 45678))
ちなみに文字コードの設定はこうなっている。
(prefer-coding-system 'utf-8-unix)
追ってみる
*-coding-system
を触っているのはこの辺り
(defun edconf-set-line-ending (end-of-line)
"Set line ending style to CR, LF, or CRLF"
(set-buffer-file-coding-system
(cond
((equal end-of-line "lf") 'undecided-unix)
((equal end-of-line "cr") 'undecided-mac)
((equal end-of-line "crlf") 'undecided-dos)
(t 'undecided))
nil t))
edconfig-set-line-ending
はfind-fileされる度に呼ばれる。
;;;###autoload
(defun edconf-find-file-hook ()
(when (executable-find edconf-exec-path)
(let ((props (edconf-parse-properties (edconf-get-properties))))
(edconf-set-indentation (gethash 'indent_style props)
(gethash 'indent_size props)
(gethash 'tab_width props))
(edconf-set-line-ending (gethash 'end_of_line props))
(edconf-set-trailing-nl (gethash 'insert_final_newline props))
(edconf-set-trailing-ws (gethash 'trim_trailing_whitespace props))
(edconf-set-line-length (gethash 'max_line_length props)))))
つまり
-
end_of_line
が設定されていないとundecided
- 設定されていると対応するOSに合わせて
undecided-xxx
がemacs側で設定される。
解決方法
- .editorconfigに
end_of_line
をちゃんと設定する - editorconfig.elの該当する行を書き換える
(色々試してみたが上手くいかなかったので最終的に力技で解決。。)
.editorconfig
# 略
end_of_line = lf
# 略
--- editorconfig-20150831.1054.el 2015-10-17 17:26:06.000000000 +0900
+++ modified.el 2015-10-17 20:22:17.000000000 +0900
@@ -213,9 +213,9 @@
"Set line ending style to CR, LF, or CRLF"
(set-buffer-file-coding-system
(cond
- ((equal end-of-line "lf") 'undecided-unix)
- ((equal end-of-line "cr") 'undecided-mac)
- ((equal end-of-line "crlf") 'undecided-dos)
+ ((equal end-of-line "lf") 'utf-8-unix)
+ ((equal end-of-line "cr") 'utf-8-mac)
+ ((equal end-of-line "crlf") 'utf-8-dos)
(t 'undecided))
nil t))
デフォルトの値がundecided
になっているのは、
どんな環境でも動くようになのかな。