How to Reset Emacs to Save Files in Utf-8-Unix Character Encoding

How to reset emacs to save files in utf-8-unix character encoding?

Here is my setup:

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

How to reset emacs to save files in utf-8-unix character encoding?

Here is my setup:

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

Emacs opening and saving encoding

You could add this comment to the top of the file:

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

Emacs opening and saving encoding

You could add this comment to the top of the file:

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

How to make emacs accept UTF-8 (uppercase) encoding?

I think, that following code will help you:

(define-coding-system-alias 'UTF-8 'utf-8)

How do i prevent emacs from adding coding information in the first line?

It looks like this is part of the ruby-mode in emacs.

I found a link to an article that shows how to edit the ruby-mode.el file. Not sure if it works, but there is also a comment on that article that may work better:

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

If instead of using ruby-mode your are using enh-ruby-mode you should set this variable:

(setq enh-ruby-add-encoding-comment-on-save nil)

Links:

Fix: Emacs/Aquamacs keeps adding encoding comments to my files

Also, semi-related question but pertinent answer by Michael Kohl: How can I avoid putting the magic encoding comment on top of every UTF-8 file in Ruby 1.9?

Enh-ruby-mode comment encoding line



Related Topics



Leave a reply



Submit