Elisp: Character Type

By Xah Lee. Date: . Last updated: .

In emacs lisp, character is represented as integer of the character's Unicode codepoint.

For example, the char a in elisp is just 97, because its codepoint is 97.

Note: elisp “Character Type” is not technically a “type” of value in the sense of most programing languages, because there's no way to distinguish integer from char. There is no function that returns true/false on whether a value is a character type. (by comparison, there are stringp, integerp, listp, symbolp, etc.) Whether a integer is a character depends on programer's intention.

Char Syntax

Char can also be represented like this ?a for easy reading. ?a means the character a.

You can also represent char by (string-to-char "a")

(equal 97 ?a ) ;; t
(equal 97 (string-to-char "a")) ;; t

Find a Char's Codepoint

Alt+x describe-char.

Useful Function on Character

(char-before) return the unicode codepoint (integer) of character before cursor.
(char-after) return the unicode codepoint (integer) of character after cursor.
(char-to-string CHAR) convert a CHAR (unicode codepoint (integer)) to string of single character.
(string-to-char STRING) return the first char in string. (return a integer that's the char's unicode codepoint)
(char-equal C1 C2). Return t if two characters match, optionally ignoring case. Case is ignored if case-fold-search is non-nil in the current buffer.

ASCII Control Chars and Backslash

Syntax of the form ?\char may have special meaning, depending what char is. They either represent a ASCII control character, or just the character char. For example, ?\n is the newline char. ?\\ is backslash char.

Here's a list of special meaning with the backslash:

7 ; control-g, C-g
8 ; backspace, BS, C-h
9 ; tab, TAB, C-i
10 ; newline, C-j
11 ; vertical tab, C-k
12 ; formfeed character, C-l
13 ; carriage return, RET, C-m
27 ; escape character, ESC, C-[
32 ; space character, SPC
92 ; backslash character, \
127 ; delete character, DEL

[see ASCII Table]


(info "(elisp) Character Type")

(info "(elisp) Basic Char Syntax")

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys


ELisp Examples

ELisp Write Major Mode

ELisp Write Major Mode


Package Name/Load

Syntax Table