emacs 无法解码中文


#1

emacs 26.2 macOs Mojave 10.14.6 python 3.7.3

在我的emacs_py.el 配置如下: ;;; function definitions (defun elpy-goto-definition-or-rgrep () “Go to the definition of the symbol at point, if found. Otherwise, run `elpy-rgrep-symbol’.” (interactive) (ring-insert find-tag-marker-ring (point-marker)) (condition-case nil (elpy-goto-definition) (error (elpy-rgrep-symbol (concat “\(def\|class\)\s” (thing-at-point 'symbol) “(”)))))

(defun rename-python-symbol-at-point (symbol-name) (interactive "snew symbol name: ") (call-interactively 'elpy-multiedit-python-symbol-at-point) (execute-kbd-macro (kbd “diw”)) (insert symbol-name) (elpy-multiedit-stop) (evil-backward-word-begin))

(defun settings-for-elpy () (flycheck-mode) (setq elpy-project-root initial-directory) (setq elpy-get-info-from-shell t) (setq elpy-shell-display-buffer-after-send t) ;;(setq python-shell-interpreter “ipython” python-shell-interpreter-args “-i --simple-prompt”) ;;(setq python-shell-interpreter “python” python-shell-interpreter-args “-i”) (setq python-shell-interpreter “ipython” python-shell-interpreter-args “–simple-prompt -c exec(‘import(\‘readline\’)’) -i”) (setq elpy-autodoc-delay 0.3) (define-evil-normal-keys (“x” . (make-interactive (elpy-format-code) (save-buffer))) (“f d” . 'elpy-doc) (“f f” . 'xref-find-references) (“f F” . 'xref-find-apropos) (“f g” . 'elpy-pdb-debug-buffer) (“f r” . 'rename-python-symbol-at-point) (“f t” . 'elpy-test) (“j” . (with-marker (elpy-goto-definition-or-rgrep))) (“C-j” . (with-marker (elpy-goto-definition-other-window)))) (define-key elpy-mode-map (kbd “C-c C-e”) 'elpy-shell-send-statement))

(defun settings-for-inferior-python () (linum-mode) (define-key inferior-python-mode-map (kbd “C-c C-z”) 'elpy-shell-switch-to-buffer))

;;; elpy (require 'elpy) (setq elpy-modules (delq 'elpy-module-flymake elpy-modules)) (advice-add 'elpy-shell–insert-and-font-lock :around (lambda (f string face &optional no-font-lock) (if (not (eq face 'comint-highlight-input)) (funcall f string face no-font-lock) (funcall f string face t) (python-shell-font-lock-post-command-hook))))

(advice-add 'comint-send-input :around (lambda (f &rest args) (if (eq major-mode 'inferior-python-mode) (cl-letf ((g (symbol-function 'add-text-properties)) ((symbol-function 'add-text-properties) (lambda (start end properties &optional object) (unless (eq (nth 3 properties) 'comint-highlight-input) (funcall g start end properties object))))) (apply f args)) (apply f args))))

(load-file “~/.emacs.d/rc/ycmd.el”)

(add-programming-hook '((lambda () (setq company-backends '(company-ycmd))) ycmd-mode elpy-mode) 'python-mode-hook)

(add-hook 'elpy-mode-hook 'settings-for-elpy) (add-hook 'inferior-python-mode-hook 'settings-for-inferior-python)

(add-to-list 'modes-need-show-buffer-modified 'python-mode) (setq grep-file-exts '("*.py")) (setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters) (set-language-environment 'utf-8) (set-keyboard-coding-system 'utf-8-mac) ; For old Carbon emacs on OS X only (setq locale-coding-system 'utf-8) (set-default-coding-systems 'utf-8) (set-terminal-coding-system 'utf-8) (set-selection-coding-system (if (eq system-type 'windows-nt) 'utf-16-le ;; https://rufflewind.com/2014-07-20/pasting-unicode-in-emacs-on-windows 'utf-8)) (prefer-coding-system 'utf-8)

(setq-default buffer-file-coding-system 'utf-8) (setenv “PYTHONIOENCODING” “utf-8”) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-language-environment “UTF-8”)


#2

编码选择gbk


#3

gbk?不是通用的都是utf-8么?


#4

你的文件含有非utf-8编码的字符,所以显示解码失败。

你好好想想,是不是用windows下的编辑器不小心误设置了


#5

感觉你应该是没仔细看问题。


#6

问题就是emacs没法解码你的文件,里面可能含有非utf-8编码,题目是中文,那我猜gbk有没有问题?

如果其他设置为utf-8编码的编辑器可以正常打开,请你用emacs -Q打开文件,排除你自己的配置问题。

另外麻烦用markdown的语法贴配置,谢谢合作

you want 
something 
just like
this


#7

不是的是由于我用了ycmd-mode,如果我去掉这个配置就ok了,可是没有自动补全。ycmd这个插件做了一次解码,然后python再解码的时候就失败了。同样的配置,我在linuxMint 是可以正常解码的