[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

33.10.4 User-Chosen Coding Systems

Function: select-safe-coding-system from to &optional default-coding-system accept-default-p
This function selects a coding system for encoding specified text, asking the user to choose if necessary. Normally the specified text is the text in the current buffer between from and to, defaulting to the whole buffer if they are nil. If from is a string, the string is the specified text, and to is ignored.

If default-coding-system is non-nil, that is the first coding system to try; if that can handle the text, select-safe-coding-system returns that coding system. It can also be a list of coding systems; then the function tries each of them one by one. After trying all of them, it next tries the user's most preferred coding system (see section `the description of prefer-coding-system' in GNU Emacs Manual), and after that the current buffer's value of buffer-file-coding-system (if it is not undecided).

If one of those coding systems can safely encode all the specified text, select-safe-coding-system chooses it and returns it. Otherwise, it asks the user to choose from a list of coding systems which can encode all the text, and returns the user's choice.

The optional argument accept-default-p, if non-nil, should be a function to determine whether the coding system selected without user interaction is acceptable. If this function returns nil, the silently selected coding system is rejected, and the user is asked to select a coding system from a list of possible candidates.

If the variable select-safe-coding-system-accept-default-p is non-nil, its value overrides the value of accept-default-p.

Here are two functions you can use to let the user specify a coding system, with completion. See section 20.5 Completion.

Function: read-coding-system prompt &optional default
This function reads a coding system using the minibuffer, prompting with string prompt, and returns the coding system name as a symbol. If the user enters null input, default specifies which coding system to return. It should be a symbol or a string.

Function: read-non-nil-coding-system prompt
This function reads a coding system using the minibuffer, prompting with string prompt, and returns the coding system name as a symbol. If the user tries to enter null input, it asks the user to try again. See section 33.10 Coding Systems.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on May 2, 2002 using texi2html