Data Types

Numbers

Emacs Lisp supports integers and floating-point numbers. They're written in just the way you'd expect: as a string of base-10 digits with an optional leading minus sign and optional decimal point. Some functions that operate on numbers are:

(numberp x)

Test whether x is a number.

(integerp x)

Test whether x is an integer.

(zerop x)

Test whether x is zero.

(= a b)

Test whether two numbers are equal.

(+ a b c … )

Addition.

(- a b c … )

Subtraction.

Characters

Single characters can be written in Emacs Lisp by preceding them with a question mark. For instance, ?a denotes lowercase a. Some special characters, particularly those that can be used to begin other kinds of Lisp expression, must be preceded with question mark-backslash, such as ?\", ?\(, and ?\). Some special characters can be written by combining a backslash with a letter. For instance, ?\t is a tab character, and ?\n is a newline character.

The result of evaluating a character is its ASCII code. For instance, evaluating ?a yields 97. In fact, integers can be used wherever characters are expected; Emacs Lisp does not distinguish between the two, except to allow the more convenient form of denoting characters.

(char-equal a b)

Test whether two characters are equal. Ignores case if the variable case-fold-search is non-nil.

(char-to-string c)

Create a one-character string containing c.

Strings

A string is a sequence of characters, and is written by enclosing the characters in double-quotes, "like this". If a double-quote or ...

Get Writing GNU Emacs Extensions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.