1. 程式人生 > >emacs 在shell下中文亂碼解決方案

emacs 在shell下中文亂碼解決方案

 

;;;; 設定編輯環境
;; 設定為中文簡體語言環境
(set-language-environment 'Chinese-GB)
;; 設定emacs 使用 utf-8
(setq locale-coding-system 'utf-8)
;; 設定鍵盤輸入時的字元編碼
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
;; 檔案預設儲存為 utf-8
(set-buffer-file-coding-system 'utf-8)
(set-default buffer-file-coding-system 'utf8)
(set-default-coding-systems 'utf-8)
;; 解決貼上中文出現亂碼的問題
(set-clipboard-coding-system 'utf-8)
;; 終端中文亂碼
(set-terminal-coding-system 'utf-8)
(modify-coding-system-alist 'process "*" 'utf-8)
(setq default-process-coding-system '(utf-8 . utf-8))
;; 解決檔案目錄的中文名亂碼
(setq-default pathname-coding-system 'utf-8)
(set-file-name-coding-system 'utf-8)
;; 解決 Shell Mode(cmd) 下中文亂碼問題

(defun change-shell-mode-coding ()

  (progn
    (set-terminal-coding-system 'gbk)
    (set-keyboard-coding-system 'gbk)
    (set-selection-coding-system 'gbk)
    (set-buffer-file-coding-system 'gbk)
    (set-file-name-coding-system 'gbk)
    (modify-coding-system-alist 'process "*" 'gbk)
    (set-buffer-process-coding-system 'gbk 'gbk)

    (set-file-name-coding-system 'gbk)))

 

轉自:Windows下emacs shell-mode中文亂碼解決方案

 

直接在緩衝區修改編碼:

1、開啟檔案出現亂碼時,可以嘗試修改字元的編碼:
M-x revert-buffer-with-coding-system RET(回車)

C-x return r
然後輸入對應編碼,如:utf-8 或者 chinese-gbk。

2、在儲存的時候還可以指定檔案的儲存編碼:
M-x set-buffer-file-coding-system

C-x return f

3、檢視Emacs編碼格式
M-x describe-coding-system