Function: encode-coding-region

encode-coding-region is an interactive function defined in coding.c.

Signature

(encode-coding-region START END CODING-SYSTEM &optional DESTINATION)

Documentation

Encode the current region using th specified coding system.

Interactively, prompt for the coding system to encode the region, and replace the region with the bytes that are the result of the encoding.

What's meant by "encoding" is transforming textual data (characters) into bytes. If, for instance, you have a region that contains the single character ?\N{COPYRIGHT SIGN}, after calling this function with the utf-8 coding system, the data in the region will represent the two bytes #xc2 #xa9.

When called from a program, takes four arguments:
        START, END, CODING-SYSTEM and DESTINATION.
START and END are buffer positions.

Optional 4th argument DESTINATION specifies where the encoded text goes. If nil, the region between START and END is replaced by the encoded text. If buffer, the encoded text is inserted in that buffer after point (point does not move). In those cases, the length of the encoded text is returned. If DESTINATION is t, the encoded text is returned.

This function sets last-coding-system-used to the precise coding system used (which may be different from CODING-SYSTEM if CODING-SYSTEM is not fully specified.)

Probably introduced at or before Emacs version 20.4.

Key Bindings

Source Code

// Defined in /usr/src/emacs/src/coding.c
{
  return code_convert_region (start, end, coding_system, destination, 1, 0);
}