Change Emacs Default Coding System

后端 未结 7 1369
-上瘾入骨i
-上瘾入骨i 2021-02-01 17:44

My problem stems from Emacs inserting the coding system headers into source files containing non-ascii characters:

# -*- coding: utf-8 -*-

My c

相关标签:
7条回答
  • 2021-02-01 18:25

    I had this problem today. For me, the problem was that I copied and pasted some TODO text from an email. When I removed that text, [ # -- coding: utf-8 -- ] was no longer inserted by emacs.

    0 讨论(0)
  • 2021-02-01 18:31

    You can also use directory local variables to set up the variables: http://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html

    If you put a file with a special name .dir-locals.el in a directory, Emacs will read it when it visits any file in that directory or any of its subdirectories, and apply the settings it specifies to the file's buffer. Emacs searches for .dir-locals.el starting in the directory of the visited file, and moving up the directory tree. (To avoid slowdown, this search is skipped for remote files.)

    0 讨论(0)
  • 2021-02-01 18:32

    This works for me:

    (setq ruby-insert-encoding-magic-comment nil)
    

    As suggested here

    I believe you're correct that it only happens in ruby-mode. It seems ruby-mode is trying to be helpful by adding the line, which makes Ruby detect the source file encoding automatically.

    0 讨论(0)
  • 2021-02-01 18:33

    First, I agree with the the original answer, but I would also add that if I had your issue I would use something like the following:

    (defun java-setup ()
      (setq tab-stop-list
            '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92)
            indent-tabs-mode nil
            tab-width 4
        fill-column 96
        buffer-file-coding-system 'utf-8-unix
        c-comment-start-regexp "\\(@\\|/\\(/\\|[*][*]?\\)\\)"))
    
    (add-hook 'java-mode-hook 'java-setup)
    
    0 讨论(0)
  • 2021-02-01 18:40

    In root of your project create file called .dir-locals.el with content:

    ((nil . ((buffer-file-coding-system . utf-8))))
    

    It will apply this coding to any mode and file. You may see more info here https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html

    0 讨论(0)
  • 2021-02-01 18:48

    By default, Emacs will not write file variables into your files. You must have asked it to do so somewhere in your .emacs. Try running emacs -q and see if the file variables get inserted.

    0 讨论(0)
提交回复
热议问题