]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix the values and documentation of 'printable-chars' table
authorEli Zaretskii <eliz@gnu.org>
Fri, 28 Feb 2025 14:22:30 +0000 (16:22 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Mar 2025 20:51:30 +0000 (21:51 +0100)
* src/character.c (syms_of_character) <printable-chars>: 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)

doc/lispref/display.texi
doc/lispref/nonascii.texi
doc/lispref/searching.texi
lisp/international/characters.el
src/character.c

index a1b9772dbe2e9b30c627ed8d92924f8539a6de63..c65aceed8e9d099b524754331d062dfabfdf3478 100644 (file)
@@ -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
index 884f54b32ac8d16c75146c6a6e0941e89123e344..cc1f9d6140139cfbdb3d75aea83880a7584b33fa 100644 (file)
@@ -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
index 09ff6202afa5895302f6b3ab630ff9cd5701f7cd..7840fe77e605c08ae2e57012cdcae17935a73ff4 100644 (file)
@@ -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:]}.
index 09932af58e5f3a503cdba377c0d9d2d653685986..66f9bef1a74a8857a01577c2542be8951bbd7ac7 100644 (file)
@@ -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)
 
+\f
+;;; 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
index 4e6cc280b409fb788d3aca0c96c72d222439a6a8..f3c06da37e780d7ca8f49ac2409c9b4746e859d8 100644 (file)
@@ -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);