开发者

Which coding system should I use in Emacs?

I have just tried to save a simple *.rtf file with some websites and tips on how to use emacs and I got

These default coding systems were tried to encode text in the buffer `notes.rtf': (iso-latin-1-dos (315 . 8216) (338 . 8217) (1514 . 8220) (1525 . 8221)) However, each of them encountered characters it couldn't encode: iso-latin-1-dos cannot encode these: ‘ ’ “ ”

....

etc, etc, etc

Now what is that? Now it is asking me to chose an encoding system

Select coding system (default chinese-iso-8bit):

I don't even know what an encoding system is, and I would rather not have to choose one every time I try and save a document... Is there any way I can set an encoding system that will work with all my files so I don't have to worry about this?

I saw another question and asnswer elsewhere in this website (see it here) and it seems that if I type the following

(defun set-coding-system () (setq buffer-file-coding-system 'utf-8-unix)) (add-hook 'find-file-hook 'set-coding-system)

开发者_如何学编程

then I can have Emacs do this, but I am not sure... Can someone confirm this to me?


Here's a pretty comprehensive group of magic invocations to make Emacs use UTF-8 everywhere by default:

  (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)


You should use UTF8; it can handle all the characters you'll ever need


Just in case it can complement Vivi's comments on SLacks's answer, about "How to permanently choose a encoding system in emacs for opening and saving?", here is a way to choose the coding system permanently and just for one file : Write -*- coding: NAME OF THE CODING SYSTEM -*- at the very top of the file, where you have to specify 'NAME OF THE CODING SYSTEM'.

You can find the name of a coding system by typing M-x list-coding-systems <RET>. Information about a coding system can be obtained by typing C-h C NAME OF THE CODING SYSTEM <RET>.

All I mention here is explained in the Emacs Manual, of course.

Note that you can set the mode for a specific file the same way as the coding system, just put -*- mode: NAME OF THE MODE -*- at the top of the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜