From: Eli Zaretskii Date: Fri, 28 Feb 2025 14:22:30 +0000 (+0200) Subject: Fix the values and documentation of 'printable-chars' table X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b1a6a7dd12bdb3af84e26e3b23d2950649429b64;p=emacs.git Fix the values and documentation of 'printable-chars' table * src/character.c (syms_of_character) : Doc fix. * lisp/international/characters.el (printable-chars): Fix values for non-ASCII characters. * doc/lispref/nonascii.texi (Character Properties): Add cross-reference for what is a printable character. * doc/lispref/display.texi (Usual Display): * doc/lispref/searching.texi (Char Classes): Add indexing. (Bug#76611) (cherry picked from commit 68a37760dec83a8126b03bcacc60a96644a6831f) --- diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index a1b9772dbe2..c65aceed8e9 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -8605,6 +8605,7 @@ The newline character (character code 10) has a special effect: it ends the preceding line and starts a new line. @cindex ASCII control characters +@cindex non-printable ASCII characters @item The non-printable @dfn{@acronym{ASCII} control characters}---character codes 0 through 31, as well as the @key{DEL} character (character code diff --git a/doc/lispref/nonascii.texi b/doc/lispref/nonascii.texi index 884f54b32ac..cc1f9d61401 100644 --- a/doc/lispref/nonascii.texi +++ b/doc/lispref/nonascii.texi @@ -754,7 +754,10 @@ each character in columns that it will occupy on the screen. The value of this variable is a char-table that specifies, for each character, whether it is printable or not. That is, if evaluating @code{(aref printable-chars char)} results in @code{t}, the character -is printable, and if it results in @code{nil}, it is not. +is printable, and if it results in @code{nil}, it is not. The +definition of what is a printable character is the same as for the +@samp{[:print:]} character class in regular expressions, @pxref{Char +Classes}. @end defvar @node Character Sets diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi index 09ff6202afa..7840fe77e60 100644 --- a/doc/lispref/searching.texi +++ b/doc/lispref/searching.texi @@ -622,6 +622,7 @@ This matches any character whose code is in the range 0--31. @item [:digit:] This matches @samp{0} through @samp{9}. Thus, @samp{[-+[:digit:]]} matches any digit, as well as @samp{+} and @samp{-}. +@cindex graphic characters @item [:graph:] This matches graphic characters---everything except spaces, @acronym{ASCII} and non-@acronym{ASCII} control characters, @@ -638,6 +639,7 @@ one. This matches any multibyte character (@pxref{Text Representations}). @item [:nonascii:] This matches any non-@acronym{ASCII} character. +@cindex printable characters @item [:print:] This matches any printing character---either spaces or graphic characters matched by @samp{[:graph:]}. diff --git a/lisp/international/characters.el b/lisp/international/characters.el index 09932af58e5..66f9bef1a74 100644 --- a/lisp/international/characters.el +++ b/lisp/international/characters.el @@ -1608,6 +1608,22 @@ with L, LRE, or LRO Unicode bidi character type.") (lambda (range _ignore) (set-char-table-range char-width-table range 2)) 'arabic-2-column) + +;;; Setting printable-chars. The default is nil for control characters, +;;; otherwise t. +;;; The table is initialized in character.c with a crude approximation, +;;; which considers any non-ASCII character above U+009F to be printable. +;;; Note: this should be consistent with [:print:] character class, +;;; see character.c:printablep. +(let ((table (unicode-property-table-internal 'general-category))) + (when table + (map-char-table (lambda (key val) + ;; Cs: Surrogates + ;; Cn: Unassigned + (when (memq val '(Cs Cn)) + (set-char-table-range printable-chars key nil))) + table))) + ;; Internal use only. ;; Alist of locale symbol vs charsets. In a language environment ;; corresponding to the locale, width of characters in the charsets is diff --git a/src/character.c b/src/character.c index 4e6cc280b40..f3c06da37e7 100644 --- a/src/character.c +++ b/src/character.c @@ -1104,7 +1104,7 @@ symbol naming it. The ID of a translation table is an index into this vector. DEFVAR_LISP ("auto-fill-chars", Vauto_fill_chars, doc: /* A char-table for characters which invoke auto-filling. -Such characters have value t in this table. */); +Such characters have the value t in this table. */); Vauto_fill_chars = Fmake_char_table (Qauto_fill_chars, Qnil); CHAR_TABLE_SET (Vauto_fill_chars, ' ', Qt); CHAR_TABLE_SET (Vauto_fill_chars, '\n', Qt); @@ -1126,7 +1126,8 @@ value of `cjk-ambiguous-chars-are-wide'. */); Vambiguous_width_chars = Fmake_char_table (Qnil, Qnil); DEFVAR_LISP ("printable-chars", Vprintable_chars, - doc: /* A char-table for each printable character. */); + doc: /* A char-table for printable characters. +Such characters have the value t in this table. */); Vprintable_chars = Fmake_char_table (Qnil, Qnil); Fset_char_table_range (Vprintable_chars, Fcons (make_fixnum (32), make_fixnum (126)), Qt);