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

10. Strings and Characters

A string in XEmacs Lisp is an array that contains an ordered sequence of characters. Strings are used as names of symbols, buffers, and files, to send messages to users, to hold text being copied between buffers, and for many other purposes. Because strings are so important, XEmacs Lisp has many functions expressly for manipulating them. XEmacs Lisp programs use strings more often than individual characters.


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

10.1 String and Character Basics

Strings in XEmacs Lisp are arrays that contain an ordered sequence of characters. Characters are their own primitive object type in XEmacs 20. However, in XEmacs 19, characters are represented in XEmacs Lisp as integers; whether an integer was intended as a character or not is determined only by how it is used. See section Character Type.

The length of a string (like any array) is fixed and independent of the string contents, and cannot be altered. Strings in Lisp are not terminated by a distinguished character code. (By contrast, strings in C are terminated by a character with ASCII code 0.) This means that any character, including the null character (ASCII code 0), is a valid element of a string.

Since strings are considered arrays, you can operate on them with the general array functions. (See section Sequences, Arrays, and Vectors.) For example, you can access or change individual characters in a string using the functions aref and aset (see section Functions that Operate on Arrays).

Strings use an efficient representation for storing the characters in them, and thus take up much less memory than a vector of the same length.

Sometimes you will see strings used to hold key sequences. This exists for backward compatibility with Emacs 18, but should not be used in new code, since many key chords can’t be represented at all and others (in particular meta key chords) are confused with accented characters.

Strings are useful for holding regular expressions. You can also match regular expressions against strings (see section Regular Expression Searching). The functions match-string (see section Simple Match Data Access) and replace-match (see section Replacing the Text That Matched) are useful for decomposing and modifying strings based on regular expression matching.

Like a buffer, a string can contain extents in it. These extents are created when a function such as buffer-substring is called on a region with duplicable extents in it. When the string is inserted into a buffer, the extents are inserted along with it. See section Duplicable Extents.

See section Text, for information about functions that display strings or copy them into buffers. See section Character Type, and String Type, for information about the syntax of characters and strings.


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

10.2 The Predicates for Strings

For more information about general sequence and array predicates, see Sequences, Arrays, and Vectors, and Arrays.

Function: stringp object

This function returns t if object is a string, nil otherwise.

Function: char-or-string-p object

This function returns t if object is a string or a character, nil otherwise.

In XEmacs addition, this function also returns t if object is an integer that can be represented as a character. This is because of compatibility with previous XEmacs and should not be depended on.


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

10.3 Creating Strings

The following functions create strings, either from scratch, or by putting strings together, or by taking them apart.

Function: string &rest characters

This function returns a new string made up of characters.

 
(string ?X ?E ?m ?a ?c ?s)
     ⇒ "XEmacs"
(string)
     ⇒ ""

Analogous functions operating on other data types include list, cons (see section Building Cons Cells and Lists), vector (see section Vectors) and bit-vector (see section Bit Vectors). This function has not been available in XEmacs prior to 21.0 and FSF Emacs prior to 20.3.

Function: make-string length character

This function returns a new string consisting entirely of length successive copies of character. length must be a non-negative fixnum.

 
(make-string 5 ?x)
     ⇒ "xxxxx"
(make-string 0 ?x)
     ⇒ ""

Other functions to compare with this one include char-to-string (see section Conversion of Characters and Strings), make-vector (see section Vectors), and make-list (see section Building Cons Cells and Lists).

Function: substring string start &optional end

This function returns a new string which consists of those characters from string in the range from (and including) the character at the index start up to (but excluding) the character at the index end. The first character is at index zero.

In this implementation, substring is an alias for subseq, so string can be any sequence. In GNU Emacs, string can be a string or a vector, and in older XEmacs it can only be a string.

 
(substring "abcdefg" 0 3)
     ⇒ "abc"

Here the index for ‘a’ is 0, the index for ‘b’ is 1, and the index for ‘c’ is 2. Thus, three letters, ‘abc’, are copied from the string "abcdefg". The index 3 marks the character position up to which the substring is copied. The character whose index is 3 is actually the fourth character in the string.

A negative number counts from the end of the string, so that -1 signifies the index of the last character of the string. For example:

 
(substring "abcdefg" -3 -1)
     ⇒ "ef"

In this example, the index for ‘e’ is -3, the index for ‘f’ is -2, and the index for ‘g’ is -1. Therefore, ‘e’ and ‘f’ are included, and ‘g’ is excluded.

When nil is used as an index, it stands for the length of the string. Thus,

 
(substring "abcdefg" -3 nil)
     ⇒ "efg"

Omitting the argument end is equivalent to specifying nil. It follows that (substring string 0) returns a copy of all of string.

 
(substring "abcdefg" 0)
     ⇒ "abcdefg"

But we recommend copy-sequence for this purpose (see section Sequences).

If the characters copied from string have duplicable extents or text properties, those are copied into the new string also. See section Duplicable Extents.

A wrong-type-argument error is signaled if either start or end is not a fixnum or nil. An args-out-of-range error is signaled if start indicates a character following end, or if either integer is out of range for string.

Contrast this function with buffer-substring (see section Examining Buffer Contents), which returns a string containing a portion of the text in the current buffer. The beginning of a string is at index 0, but the beginning of a buffer is at index 1.

Function: concat &rest sequences

This function returns a new string consisting of the characters in the arguments passed to it (along with their text properties, if any). The arguments may be strings, lists of numbers, or vectors of numbers; they are not themselves changed. If concat receives no arguments, it returns an empty string.

 
(concat "abc" "-def")
     ⇒ "abc-def"
(equal (concat "abc" (list 120 (+ 256 121)) [122]) (format "abcx%cz" 377))
     ⇒ t
;; nil is an empty sequence.
(concat "abc" nil "-def")
     ⇒ "abc-def"
(concat "The " "quick brown " "fox.")
     ⇒ "The quick brown fox."
(concat)
     ⇒ ""

The concat function always constructs a new string that is not eq to any existing string.

For information about other concatenation functions, see the description of mapconcat in Mapping Functions, vconcat in Vectors, bvconcat in Bit Vectors, and append in Building Cons Cells and Lists.

The function split-string, in Regular Expression Searching, generates a list of strings by splitting a string on occurrences of a regular expression.


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

10.4 The Predicates for Characters

Function: characterp object

This function returns t if object is a character.

Some functions that work on integers (e.g. the comparison functions <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.) accept characters and implicitly convert them into integers. In general, functions that work on characters also accept char-ints and implicitly convert them into characters. WARNING: Neither of these behaviors is very desirable, and they are maintained for backward compatibility with old E-Lisp programs that confounded characters and integers willy-nilly. These behaviors may change in the future; therefore, do not rely on them. Instead, convert the characters explicitly using char-int.

Function: integer-or-char-p object

This function returns t if object is an integer or character.


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

10.5 Character Codes

Function: char-int character

This function converts a character into an equivalent integer. The resulting integer will always be non-negative. The integers in the range 0 - 255 map to characters as follows:

0 - 31

Control set 0

32 - 127

ASCII

128 - 159

Control set 1

160 - 255

Right half of ISO-8859-1

If support for MULE does not exist, these are the only valid character values. When MULE support exists, the values assigned to other characters may vary depending on the particular version of XEmacs, the order in which character sets were loaded, etc., and you should not depend on them.

Function: int-char integer

This function converts an integer into the equivalent character. Not all integers correspond to valid characters; use char-int-p to determine whether this is the case. If the integer cannot be converted, nil is returned.

Function: char-int-p object

This function returns t if object is an integer that can be converted into a character.

Function: char-or-char-int-p object

This function returns t if object is a character or an integer that can be converted into one.


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

10.6 Comparison of Characters and Strings

Function: char-equal character1 character2 &optional buffer

This function returns t if the arguments represent the same character, nil otherwise. This function ignores differences in case if the value of case-fold-search is non-nil in buffer, which defaults to the current buffer.

 
(char-equal ?x ?x)
     ⇒ t
(let ((case-fold-search t))
  (char-equal ?x ?X))
     ⇒ t
(let ((case-fold-search nil))
  (char-equal ?x ?X))
     ⇒ nil
Function: char= character1 character2

This function returns t if the arguments represent the same character, nil otherwise. Case is significant.

 
(char= ?x ?x)
     ⇒ t
(char= ?x ?X)
     ⇒ nil
(let ((case-fold-search t))
  (char-equal ?x ?X))
     ⇒ nil
(let ((case-fold-search nil))
  (char-equal ?x ?X))
     ⇒ nil
Function: string= string1 string2

This function returns t if the characters of the two strings match exactly; case is significant.

 
(string= "abc" "abc")
     ⇒ t
(string= "abc" "ABC")
     ⇒ nil
(string= "ab" "ABC")
     ⇒ nil
Function: string-equal string1 string2

string-equal is another name for string=.

Function: string< string1 string2

This function compares two strings a character at a time. First it scans both the strings at once to find the first pair of corresponding characters that do not match. If the lesser character of those two is the character from string1, then string1 is less, and this function returns t. If the lesser character is the one from string2, then string1 is greater, and this function returns nil. If the two strings match entirely, the value is nil.

Pairs of characters are compared by their ASCII codes. Keep in mind that lower case letters have higher numeric values in the ASCII character set than their upper case counterparts; numbers and many punctuation characters have a lower numeric value than upper case letters.

 
(string< "abc" "abd")
     ⇒ t
(string< "abd" "abc")
     ⇒ nil
(string< "123" "abc")
     ⇒ t

When the strings have different lengths, and they match up to the length of string1, then the result is t. If they match up to the length of string2, the result is nil. A string of no characters is less than any other string.

 
(string< "" "abc")
     ⇒ t
(string< "ab" "abc")
     ⇒ t
(string< "abc" "")
     ⇒ nil
(string< "abc" "ab")
     ⇒ nil
(string< "" "")
     ⇒ nil
Function: string-lessp string1 string2

string-lessp is another name for string<.

See also compare-buffer-substrings in Comparing Text, for a way to compare text in buffers. The function string-match, which matches a regular expression against a string, can be used for a kind of string comparison; see Regular Expression Searching.


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

10.7 Conversion of Characters and Strings

This section describes functions for conversions between characters, strings and integers. format and prin1-to-string (see section Output Functions) can also convert Lisp objects into strings. read-from-string (see section Input Functions) can “convert” a string representation of a Lisp object into an object.

See section Documentation, for functions that produce textual descriptions of text characters and general input events (single-key-description and text-char-description). These functions are used primarily for making help messages.

Function: char-to-string character

This function returns a new string with a length of one character. The value of character, modulo 256, is used to initialize the element of the string.

This function is similar to make-string with an integer argument of 1. (See section Creating Strings.) This conversion can also be done with format using the ‘%c’ format specification. (See section Formatting Strings.)

 
(char-to-string ?x)
     ⇒ "x"
(char-to-string (+ 256 ?x))
     ⇒ "x"
(make-string 1 ?x)
     ⇒ "x"
Function: string-to-char string

This function returns the first character in string. If the string is empty, the function returns 0. (Under XEmacs 19, the value is also 0 when the first character of string is the null character, ASCII code 0.)

 
(string-to-char "ABC")
     ⇒ ?A   ;; Under XEmacs 20.
     ⇒ 65   ;; Under XEmacs 19.
(string-to-char "xyz")
     ⇒ ?x   ;; Under XEmacs 20.
     ⇒ 120  ;; Under XEmacs 19.
(string-to-char "")
     ⇒ 0
(string-to-char "\000")
     ⇒ ?\^ ;; Under XEmacs 20.
     ⇒ 0    ;; Under XEmacs 20.

This function may be eliminated in the future if it does not seem useful enough to retain.

Function: number-to-string number

This function returns a string consisting of the printed representation of number, which may be an integer or a floating point number. The value starts with a sign if the argument is negative.

 
(number-to-string 256)
     ⇒ "256"
(number-to-string -23)
     ⇒ "-23"
(number-to-string -23.5)
     ⇒ "-23.5"

int-to-string is a semi-obsolete alias for this function.

See also the function format in Formatting Strings.

Function: string-to-number string &optional base

This function returns the numeric value represented by string, read in base. It skips spaces and tabs at the beginning of string, then reads as much of string as it can interpret as a number. (On some systems it ignores other whitespace at the beginning, not just spaces and tabs.) If the first character after the ignored whitespace is not a digit or a minus sign, this function returns 0.

If base is not specified, it defaults to ten. With base other than ten, only integers can be read.

 
(string-to-number "256")
     ⇒ 256
(string-to-number "25 is a perfect square.")
     ⇒ 25
(string-to-number "X256")
     ⇒ 0
(string-to-number "-4.5")
     ⇒ -4.5
(string-to-number "ffff" 16)
     ⇒ 65535

string-to-int is an obsolete alias for this function.


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

10.8 Modifying Strings

You can modify a string using the general array-modifying primitives. See section Arrays. The function aset modifies a single character; the function fillarray sets all characters in the string to a specified character.

Each string has a tick counter that starts out at zero (when the string is created) and is incremented each time a change is made to that string.

Function: string-modified-tick string

This function returns the tick counter for ‘string’.


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

10.9 String Properties

Just as with symbols, extents, faces, and glyphs, you can attach additional information to strings in the form of string properties. These differ from text properties, which are logically attached to particular characters in the string.

To attach a property to a string, use put. To retrieve a property from a string, use get. You can also use remprop to remove a property from a string and object-plist to retrieve a list of all the properties in a string.


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

10.10 Formatting Strings

Formatting means constructing a string by substitution of computed values at various places in a constant string. This string controls how the other values are printed as well as where they appear; it is called a format string.

Formatting is often useful for computing messages to be displayed. In fact, the functions message and error provide the same formatting feature described here; they differ from format only in how they use the result of formatting.

Function: format string &rest objects

This function returns a new string that is made by copying string and then replacing any format specification in the copy with encodings of the corresponding objects. The arguments objects are the computed values to be formatted.

A format specification is a sequence of characters beginning with a ‘%’. Thus, if there is a ‘%d’ in string, the format function replaces it with the printed representation of one of the values to be formatted (one of the arguments objects). For example:

 
(format "The value of fill-column is %d." fill-column)
     ⇒ "The value of fill-column is 72."

If string contains more than one format specification, the format specifications correspond with successive values from objects. Thus, the first format specification in string uses the first such value, the second format specification uses the second such value, and so on. Any extra format specifications (those for which there are no corresponding values) cause unpredictable behavior. Any extra values to be formatted are ignored.

Certain format specifications require values of particular types. However, no error is signaled if the value actually supplied fails to have the expected type. Instead, the output is likely to be meaningless.

Here is a table of valid format specifications:

%s

Replace the specification with the printed representation of the object, made without quoting. Thus, strings are represented by their contents alone, with no ‘"’ characters, and symbols appear without ‘\’ characters. This is equivalent to printing the object with princ.

If there is no corresponding object, the empty string is used.

%S

Replace the specification with the printed representation of the object, made with quoting. Thus, strings are enclosed in ‘"’ characters, and ‘\’ characters appear where necessary before special characters. This is equivalent to printing the object with prin1.

If there is no corresponding object, the empty string is used.

%o

Replace the specification with the base-eight representation of an integer.

%d
%i

Replace the specification with the base-ten representation of an integer.

%x

Replace the specification with the base-sixteen representation of an integer, using lowercase letters.

%X

Replace the specification with the base-sixteen representation of an integer, using uppercase letters.

%b

Replace the specification with the base-two representation of an integer.

%c

Replace the specification with the character which is the value given.

%e

Replace the specification with the exponential notation for a floating point number (e.g. ‘7.85200e+03’).

%f

Replace the specification with the decimal-point notation for a floating point number.

%g

Replace the specification with notation for a floating point number, using a “pretty format”. Either exponential notation or decimal-point notation will be used (usually whichever is shorter), and trailing zeroes are removed from the fractional part.

%%

A single ‘%’ is placed in the string. This format specification is unusual in that it does not use a value. For example, (format "%% %d" 30) returns "% 30".

Any other format character results in an ‘Invalid format operation’ error.

Here are several examples:

 
(format "The name of this buffer is %s." (buffer-name))
     ⇒ "The name of this buffer is strings.texi."

(format "The buffer object prints as %s." (current-buffer))
     ⇒ "The buffer object prints as #<buffer strings.texi>."

(format "The octal value of %d is %o,
         and the hex value is %x." 18 18 18)
     ⇒ "The octal value of 18 is 22,
         and the hex value is 12."

There are many additional flags and specifications that can occur between the ‘%’ and the format character, in the following order:

  1. An optional repositioning specification, which is a positive integer followed by a ‘$’.
  2. Zero or more of the optional flag characters ‘-’, ‘+’, ‘ ’, ‘0’, and ‘#’.
  3. An asterisk (‘*’, meaning that the field width is now assumed to have been specified as an argument.
  4. An optional minimum field width.
  5. An optional precision, preceded by a ‘.’ character.

A repositioning specification changes which argument to format is used by the current and all following format specifications. Normally the first specification uses the first argument, the second specification uses the second argument, etc. Using a repositioning specification, you can change this. By placing a number n followed by a ‘$’ between the ‘%’ and the format character, you cause the specification to use the nth argument. The next specification will use the n+1’th argument, etc.

For example:

 
(format "Can't find file `%s' in directory `%s'."
        "ignatius.c" "loyola/")
     ⇒ "Can't find file `ignatius.c' in directory `loyola/'."

(format "In directory `%2$s', the file `%1$s' was not found."
        "ignatius.c" "loyola/")
     ⇒ "In directory `loyola/', the file `ignatius.c' was not found."

(format
    "The numbers %d and %d are %1$x and %x in hex and %1$o and %o in octal."
    37 12)
⇒ "The numbers 37 and 12 are 25 and c in hex and 45 and 14 in octal."

As you can see, this lets you reprocess arguments more than once or reword a format specification (thereby moving the arguments around) without having to actually reorder the arguments. This is especially useful in translating messages from one language to another: Different languages use different word orders, and this sometimes entails changing the order of the arguments. By using repositioning specifications, this can be accomplished without having to embed knowledge of particular languages into the location in the program’s code where the message is displayed.

All the specification characters allow an optional numeric prefix between the ‘%’ and the character, and following any repositioning specification or flag. The optional numeric prefix defines the minimum width for the object. If the printed representation of the object contains fewer characters than this, then it is padded. The padding is normally on the left, but will be on the right if the ‘-’ flag character is given. The padding character is normally a space, but if the ‘0’ flag character is given, zeros are used for padding.

 
(format "%06d is padded on the left with zeros" 123)
     ⇒ "000123 is padded on the left with zeros"

(format "%-6d is padded on the right" 123)
     ⇒ "123    is padded on the right"

format never truncates an object’s printed representation, no matter what width you specify. Thus, you can use a numeric prefix to specify a minimum spacing between columns with no risk of losing information.

In the following three examples, ‘%7s’ specifies a minimum width of 7. In the first case, the string inserted in place of ‘%7s’ has only 3 letters, so 4 blank spaces are inserted for padding. In the second case, the string "specification" is 13 letters wide but is not truncated. In the third case, the padding is on the right.

 
(format "The word `%7s' actually has %d letters in it."
        "foo" (length "foo"))
     ⇒ "The word `    foo' actually has 3 letters in it."
(format "The word `%7s' actually has %d letters in it."
        "specification" (length "specification"))
     ⇒ "The word `specification' actually has 13 letters in it."
(format "The word `%-7s' actually has %d letters in it."
        "foo" (length "foo"))
     ⇒ "The word `foo    ' actually has 3 letters in it."

After any minimum field width, a precision may be specified by preceding it with a ‘.’ character. The precision specifies the minimum number of digits to appear in ‘%d’, ‘%i’, ‘%o’, ‘%x’, and ‘%X’ conversions (the number is padded on the left with zeroes as necessary); the number of digits printed after the decimal point for ‘%f’, ‘%e’, and ‘%E’ conversions; the number of significant digits printed in ‘%g’ and ‘%G’ conversions; and the maximum number of non-padding characters printed in ‘%s’ and ‘%S’ conversions. The default precision for floating-point conversions is six.

The other flag characters have the following meanings:


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

10.11 Character Case

The character case functions change the case of single characters or of the contents of strings. The functions convert only alphabetic characters (the letters ‘A’ through ‘Z’ and ‘a’ through ‘z’); other characters are not altered. The functions do not modify the strings that are passed to them as arguments.

The examples below use the characters ‘X’ and ‘x’ which have ASCII codes 88 and 120 respectively.

Function: downcase string-or-char &optional buffer

This function converts a character or a string to lower case.

When the argument to downcase is a string, the function creates and returns a new string in which each letter in the argument that is upper case is converted to lower case. When the argument to downcase is a character, downcase returns the corresponding lower case character. (This value is actually an integer under XEmacs 19.) If the original character is lower case, or is not a letter, then the value equals the original character.

Optional second arg buffer specifies which buffer’s case tables to use, and defaults to the current buffer.

 
(downcase "The cat in the hat")
     ⇒ "the cat in the hat"

(downcase ?X)
     ⇒ ?x   ;; Under XEmacs 20.
     ⇒ 120  ;; Under XEmacs 19.

Function: upcase string-or-char &optional buffer

This function converts a character or a string to upper case.

When the argument to upcase is a string, the function creates and returns a new string in which each letter in the argument that is lower case is converted to upper case.

When the argument to upcase is a character, upcase returns the corresponding upper case character. (This value is actually an integer under XEmacs 19.) If the original character is upper case, or is not a letter, then the value equals the original character.

Optional second arg buffer specifies which buffer’s case tables to use, and defaults to the current buffer.

 
(upcase "The cat in the hat")
     ⇒ "THE CAT IN THE HAT"

(upcase ?x)
     ⇒ ?X   ;; Under XEmacs 20.
     ⇒ 88   ;; Under XEmacs 19.
Function: capitalize string-or-char &optional buffer

This function capitalizes strings or characters. If string-or-char is a string, the function creates and returns a new string, whose contents are a copy of string-or-char in which each word has been capitalized. This means that the first character of each word is converted to upper case, and the rest are converted to lower case.

The definition of a word is any sequence of consecutive characters that are assigned to the word constituent syntax class in the current syntax table (see section Table of Syntax Classes).

When the argument to capitalize is a character, capitalize has the same result as upcase.

Optional second arg buffer specifies which buffer’s case tables to use, and defaults to the current buffer.

 
(capitalize "The cat in the hat")
     ⇒ "The Cat In The Hat"

(capitalize "THE 77TH-HATTED CAT")
     ⇒ "The 77th-Hatted Cat"

(capitalize ?x)
     ⇒ ?X   ;; Under XEmacs 20.
     ⇒ 88   ;; Under XEmacs 19.

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

10.12 The Case Table

You can customize case conversion by installing a special case table. A case table specifies the mapping between upper case and lower case letters. It affects both the string and character case conversion functions (see the previous section) and those that apply to text in the buffer (see section Case Changes). You need a case table if you are using a language which has letters other than the standard ASCII letters.

A case table is a list of this form:

 
(downcase upcase canonicalize equivalences)

where each element is either nil or a string of length 256. The element downcase says how to map each character to its lower-case equivalent. The element upcase maps each character to its upper-case equivalent. If lower and upper case characters are in one-to-one correspondence, use nil for upcase; then XEmacs deduces the upcase table from downcase.

For some languages, upper and lower case letters are not in one-to-one correspondence. There may be two different lower case letters with the same upper case equivalent. In these cases, you need to specify the maps for both directions.

The element canonicalize maps each character to a canonical equivalent; any two characters that are related by case-conversion have the same canonical equivalent character.

The element equivalences is a map that cyclicly permutes each equivalence class (of characters with the same canonical equivalent). (For ordinary ASCII, this would map ‘a’ into ‘A’ and ‘A’ into ‘a’, and likewise for each set of equivalent characters.)

When you construct a case table, you can provide nil for canonicalize; then Emacs fills in this string from upcase and downcase. You can also provide nil for equivalences; then Emacs fills in this string from canonicalize. In a case table that is actually in use, those components are non-nil. Do not try to specify equivalences without also specifying canonicalize.

Each buffer has a case table. XEmacs also has a standard case table which is copied into each buffer when you create the buffer. Changing the standard case table doesn’t affect any existing buffers.

Here are the functions for working with case tables:

Function: case-table-p object

This predicate returns non-nil if object is a valid case table.

Function: set-standard-case-table case-table

This function makes case-table the standard case table, so that it will apply to any buffers created subsequently.

Function: standard-case-table

This returns the standard case table.

Function: current-case-table &optional buffer

This function returns the case table of buffer, which defaults to the current buffer.

Function: set-case-table case-table

This sets the current buffer’s case table to case-table.

The following three functions are convenient subroutines for packages that define non-ASCII character sets. They modify a string downcase-table provided as an argument; this should be a string to be used as the downcase part of a case table. They also modify the standard syntax table. See section Syntax Tables.

Function: set-case-syntax-pair uc lc downcase-table

This function specifies a pair of corresponding letters, one upper case and one lower case.

Function: set-case-syntax-delims l r downcase-table

This function makes characters l and r a matching pair of case-invariant delimiters.

Function: set-case-syntax char syntax downcase-table

This function makes char case-invariant, with syntax syntax.

Command: describe-buffer-case-table

This command displays a description of the contents of the current buffer’s case table.

You can load the library ‘iso-syntax’ to set up the standard syntax table and define a case table for the 8-bit ISO Latin 1 character set.


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

10.13 The Char Table

A char table is a table that maps characters (or ranges of characters) to values. Char tables are specialized for characters, only allowing particular sorts of ranges to be assigned values. Although this loses in generality, it makes for extremely fast (constant-time) lookups, and thus is feasible for applications that do an extremely large number of lookups (e.g. scanning a buffer for a character in a particular syntax, where a lookup in the syntax table must occur once per character).

Note that char tables as a primitive type, and all of the functions in this section, exist only in XEmacs 20. In XEmacs 19, char tables are generally implemented using a vector of 256 elements.

When MULE support exists, the types of ranges that can be assigned values are

When MULE support is not present, the types of ranges that can be assigned values are

Function: char-table-p object

This function returns non-nil if object is a char table.


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

10.13.1 Char Table Types

Each char table type is used for a different purpose and allows different sorts of values. The different char table types are

category

Used for category tables, which specify the regexp categories that a character is in. The valid values are nil or a bit vector of 95 elements. Higher-level Lisp functions are provided for working with category tables. Currently categories and category tables only exist when MULE support is present.

char

A generalized char table, for mapping from one character to another. Used for case tables, syntax matching tables, keyboard-translate-table, etc. The valid values are characters.

generic

An even more generalized char table, for mapping from a character to anything.

display

Used for display tables, which specify how a particular character is to appear when displayed. #### Not yet implemented.

syntax

Used for syntax tables, which specify the syntax of a particular character. Higher-level Lisp functions are provided for working with syntax tables. The valid values are fixnums.

Function: char-table-type char-table

This function returns the type of char table char-table.

Function: char-table-type-list

This function returns a list of the recognized char table types.

Function: valid-char-table-type-p type

This function returns t if type if a recognized char table type.



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

This document was generated by Aidan Kehoe on December 27, 2016 using texi2html 1.82.