【问题标题】:How to reset emacs to save files in utf-8-unix character encoding?如何重置emacs以utf-8-unix字符编码保存文件?
【发布时间】:2013-12-21 20:27:30
【问题描述】:

我有问题。我发现 emacs 最近停止使用默认字符集“utf-8-unix”保存我的所有新文件。 我不明白我做了什么,但是当我打开一个文件时,在迷你缓冲区上方我看到“--:---”而不是“-U:---”,其中“U”表示文件以 utf-8-unix 字符集保存。 如何重置 emacs 以将文件保存在正确的编码系统中???

【问题讨论】:

  • 我已经尝试了所有这些命令,但仍然得到“undecided-unix”(“--:---”)编码而不是 UTF-8... 我该如何解决?
  • 您可以在文件顶部添加# -STAR- coding: utf-8 -STAR- ....肯定会工作...但也可以看看:stackoverflow.com/questions/1674481/…跨度>
  • 用星号替换 STAR
  • @MiteshPathak: 应该是; -*- coding: utf-8 -*-(也就是说,在行首使用 Emacs 注释标记,分号,而不是井号)。

标签: linux emacs encoding utf-8


【解决方案1】:

这是我的设置:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ENCODING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C-h C RET
;; M-x describe-current-coding-system

(add-to-list 'file-coding-system-alist '("\\.tex" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.txt" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.el" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("\\.scratch" . utf-8-unix) )
(add-to-list 'file-coding-system-alist '("user_prefs" . utf-8-unix) )

(add-to-list 'process-coding-system-alist '("\\.txt" . utf-8-unix) )

(add-to-list 'network-coding-system-alist '("\\.txt" . utf-8-unix) )

(prefer-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix)
(set-selection-coding-system 'utf-8-unix)
(setq-default buffer-file-coding-system 'utf-8-unix)

;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))

;; mnemonic for utf-8 is "U", which is defined in the mule.el
(setq eol-mnemonic-dos ":CRLF")
(setq eol-mnemonic-mac ":CR")
(setq eol-mnemonic-undecided ":?")
(setq eol-mnemonic-unix ":LF")

(defalias 'read-buffer-file-coding-system 'lawlist-read-buffer-file-coding-system)
(defun lawlist-read-buffer-file-coding-system ()
  (let* ((bcss (find-coding-systems-region (point-min) (point-max)))
         (css-table
          (unless (equal bcss '(undecided))
            (append '("dos" "unix" "mac")
                    (delq nil (mapcar (lambda (cs)
                                        (if (memq (coding-system-base cs) bcss)
                                            (symbol-name cs)))
                                      coding-system-list)))))
         (combined-table
          (if css-table
              (completion-table-in-turn css-table coding-system-alist)
            coding-system-alist))
         (auto-cs
          (unless find-file-literally
            (save-excursion
              (save-restriction
                (widen)
                (goto-char (point-min))
                (funcall set-auto-coding-function
                         (or buffer-file-name "") (buffer-size))))))
         (preferred 'utf-8-unix)
         (default 'utf-8-unix)
         (completion-ignore-case t)
         (completion-pcm--delim-wild-regex ; Let "u8" complete to "utf-8".
          (concat completion-pcm--delim-wild-regex
                  "\\|\\([[:alpha:]]\\)[[:digit:]]"))
         (cs (completing-read
              (format "Coding system for saving file (default %s): " default)
              combined-table
              nil t nil 'coding-system-history
              (if default (symbol-name default)))))
    (unless (zerop (length cs)) (intern cs))))

【讨论】:

  • 我不知道为什么连这个都不起作用,但是非常感谢你的sn-p,我会试试的!
  • 如果您通常处理的文件有扩展名,请继续像我在示例中所做的那样添加它们 -- file-coding-system-alist。我什至添加了一个没有扩展名的——例如,user-prefs
【解决方案2】:

出于某种原因,Windows 开始将我的 init.el 文件解释为以非 UTF-8 编码,并被“ö”和“§”等字符阻塞。解决方案是在文件开头添加一行; -*- coding: utf-8 -*-

为了确保在每种情况下都使用 UTF-8,我在 init.el 中有以下几行:

;; Use UTF-8 for all character encoding.
(set-language-environment 'utf-8)
(set-default-coding-systems 'utf-8)
(set-selection-coding-system 'utf-8)
(set-locale-environment "en.UTF-8")
(prefer-coding-system 'utf-8)
(setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding

【讨论】:

    【解决方案3】:

    要恢复所描述的旧行为,请尝试添加

    (set-language-environment "UTF-8")
    

    到您的.emacs 启动文件。

    【讨论】:

    • 我试过了,但是没有用。我不知道我搞砸了什么......但它不起作用......还有其他方法吗?
    • -Q (--no-init-file --no-site-file --no-splash) 开头的emacs有什么改变吗?
    • 不它不会改变任何与缓冲区字符集有关的东西,它只加载没有 .emacs 文件的 emacs,但实际上我仍然遇到编码问题......我该怎么办?
    • 告诉我们更多关于环境的信息(OS/Distribution,Emacs 版本)。
    • 我在 Ubuntu 13.04 上使用 Emacs 23.4
    猜你喜欢
    • 2013-02-02
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 2014-10-13
    • 1970-01-01
    • 1970-01-01
    • 2014-06-09
    • 1970-01-01
    相关资源
    最近更新 更多