Function: prefer-coding-system

prefer-coding-system is an interactive and byte-compiled function defined in mule-cmds.el.gz.

Signature

(prefer-coding-system CODING-SYSTEM)

Documentation

Add CODING-SYSTEM at the front of the priority list for automatic detection.

This also sets the following coding systems:
  o coding system of a newly created buffer
  o default coding system for subprocess I/O
This also sets the following values:
  o default value used as file-name-coding-system for converting file names
  o default value for the command set-terminal-coding-system
  o default value for the command set-keyboard-coding-system

If CODING-SYSTEM specifies a certain type of EOL conversion, the coding systems set by this function will use that type of EOL conversion.

A coding system that requires automatic detection of text+encoding
(e.g. undecided, unix) can't be preferred.

To prefer, for instance, utf-8, say the following:

  (prefer-coding-system 'utf-8)

View in manual

Probably introduced at or before Emacs version 20.4.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/international/mule-cmds.el.gz
(defun prefer-coding-system (coding-system)
  "Add CODING-SYSTEM at the front of the priority list for automatic detection.
This also sets the following coding systems:
  o coding system of a newly created buffer
  o default coding system for subprocess I/O
This also sets the following values:
  o default value used as `file-name-coding-system' for converting file names
  o default value for the command `set-terminal-coding-system'
  o default value for the command `set-keyboard-coding-system'

If CODING-SYSTEM specifies a certain type of EOL conversion, the coding
systems set by this function will use that type of EOL conversion.

A coding system that requires automatic detection of text+encoding
\(e.g. undecided, unix) can't be preferred.

To prefer, for instance, utf-8, say the following:

  (prefer-coding-system \\='utf-8)"
  (interactive "zPrefer coding system: ")
  (if (not (and coding-system (coding-system-p coding-system)))
      (error "Invalid coding system `%s'" coding-system))
  (if (memq (coding-system-type coding-system) '(raw-text undecided))
      (error "Can't prefer the coding system `%s'" coding-system))
  (let ((base (coding-system-base coding-system))
	(eol-type (coding-system-eol-type coding-system)))
    (set-coding-system-priority base)
    (and (called-interactively-p 'interactive)
	 (or (eq base coding-system)
	     (message "Highest priority is set to %s (base of %s)"
		      base coding-system)))
    ;; If they asked for specific EOL conversion, honor that.
    (if (memq eol-type '(0 1 2))
	(setq base
	      (coding-system-change-eol-conversion base eol-type)))
    (set-default-coding-systems base)
    (if (called-interactively-p 'interactive)
	(or (eq base (coding-system-type default-file-name-coding-system))
	    (message "The default value of `file-name-coding-system' was not changed because the specified coding system is not suitable for file names.")))))