comparison man/lispref/text.texi @ 414:da8ed4261e83 r21-2-15

Import from CVS: tag r21-2-15
author cvs
date Mon, 13 Aug 2007 11:21:38 +0200
parents 697ef44129c6
children
comparison
equal deleted inserted replaced
413:901169e5ca31 414:da8ed4261e83
2462 @end example 2462 @end example
2463 @end defun 2463 @end defun
2464 2464
2465 @defun translate-region start end table 2465 @defun translate-region start end table
2466 This function applies a translation table to the characters in the 2466 This function applies a translation table to the characters in the
2467 buffer between positions @var{start} and @var{end}. 2467 buffer between positions @var{start} and @var{end}. The translation
2468 2468 table @var{table} can be either a string, a vector, or a char-table.
2469 The translation table @var{table} is a string; @code{(aref @var{table} 2469
2470 @var{ochar})} gives the translated character corresponding to 2470 If @var{table} is a string, its @var{n}th element is the mapping for the
2471 @var{ochar}. If the length of @var{table} is less than 256, any 2471 character with code @var{n}.
2472 characters with codes larger than the length of @var{table} are not 2472
2473 altered by the translation. 2473 If @var{table} is a vector, its @var{n}th element is the mapping for
2474 character with code @var{n}. Legal mappings are characters, strings, or
2475 @code{nil} (meaning don't replace.)
2476
2477 If @var{table} is a char-table, its elements describe the mapping
2478 between characters and their replacements. The char-table should be of
2479 type @code{char} or @code{generic}.
2480
2481 When the @var{table} is a string or vector and its length is less than
2482 the total number of characters (256 without Mule), any characters with
2483 codes larger than the length of @var{table} are not altered by the
2484 translation.
2474 2485
2475 The return value of @code{translate-region} is the number of 2486 The return value of @code{translate-region} is the number of
2476 characters that were actually changed by the translation. This does 2487 characters that were actually changed by the translation. This does
2477 not count characters that were mapped into themselves in the 2488 not count characters that were mapped into themselves in the
2478 translation table. 2489 translation table.
2490
2491 @strong{NOTE}: Prior to XEmacs 21.2, the @var{table} argument was
2492 allowed only to be a string. This is still the case in FSF Emacs.
2493
2494 The following example creates a char-table that is passed to
2495 @code{translate-region}, which translates character @samp{a} to
2496 @samp{the letter a}, removes character @samp{b}, and translates
2497 character @samp{c} to newline.
2498
2499 @example
2500 @group
2501 ---------- Buffer: foo ----------
2502 Here is a sentence in the buffer.
2503 ---------- Buffer: foo ----------
2504 @end group
2505
2506 @group
2507 (let ((table (make-char-table 'generic)))
2508 (put-char-table ?a "the letter a" table)
2509 (put-char-table ?b "" table)
2510 (put-char-table ?c ?\n table)
2511 (translate-region (point-min) (point-max) table))
2512 @result{} 3
2513
2514 ---------- Buffer: foo ----------
2515 Here is the letter a senten
2516 e in the uffer.
2517 ---------- Buffer: foo ----------
2518 @end group
2519 @end example
2479 @end defun 2520 @end defun
2480 2521
2481 @node Registers 2522 @node Registers
2482 @section Registers 2523 @section Registers
2483 @cindex registers 2524 @cindex registers