emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 6f037f4 4/4: Honor print-charset-text-property valu


From: Noam Postavsky
Subject: [Emacs-diffs] master 6f037f4 4/4: Honor print-charset-text-property value of nil (Bug#31376)
Date: Wed, 23 May 2018 19:08:53 -0400 (EDT)

branch: master
commit 6f037f427a25160168e842bff0d12b816d69067d
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Honor print-charset-text-property value of nil (Bug#31376)
    
    * src/print.c (print_check_string_charset_prop): Move check
    for nil Vprint_charset_text_property from here...
    (print_prune_string_charset): ... to here.
    (syms_of_print) <print-charset-text-property>: Clarify that any
    non-boolean values are treated the same as `default'.
    * doc/lispref/streams.texi (Output Variables): Add
    print-prune-string-charset.
    * test/src/print-tests.el (print-charset-text-property-nil)
    (print-charset-text-property-default)
    (print-charset-text-property-t): New tests.
    (print-tests--prints-with-charset-p): New helper function.
---
 doc/lispref/streams.texi | 15 +++++++++++++++
 src/print.c              | 11 ++++++-----
 test/src/print-tests.el  | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/doc/lispref/streams.texi b/doc/lispref/streams.texi
index ebd8066..032669c 100644
--- a/doc/lispref/streams.texi
+++ b/doc/lispref/streams.texi
@@ -809,6 +809,21 @@ when the output stream is a unibyte buffer or a marker 
pointing into
 one.
 @end defvar
 
address@hidden print-charset-text-property
+This variable controls printing of `charset' text property on printing
+a string.  The value should be @code{nil}, @code{t}, or
address@hidden
+
+If the value is @code{nil}, @code{charset} text properties are never
+printed.  If @code{t}, they are always printed.
+
+If the value is @code{default}, only print @code{charset} text
+properties if there is an ``unexpected'' @code{charset} property.  For
+ascii characters, all charsets are considered ``expected''.
+Otherwise, the expected @code{charset} property of a character is
+given by @code{char-charset}.
address@hidden defvar
+
 @defvar print-length
 @cindex printing limits
 The value of this variable is the maximum number of elements to print in
diff --git a/src/print.c b/src/print.c
index 7c6856a..8394375 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1317,8 +1317,7 @@ print_check_string_charset_prop (INTERVAL interval, 
Lisp_Object string)
          || CONSP (XCDR (XCDR (val))))
        print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND;
     }
-  if (NILP (Vprint_charset_text_property)
-      || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
+  if (! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
     {
       int i, c;
       ptrdiff_t charpos = interval->position;
@@ -1348,7 +1347,8 @@ print_prune_string_charset (Lisp_Object string)
   print_check_string_result = 0;
   traverse_intervals (string_intervals (string), 0,
                      print_check_string_charset_prop, string);
-  if (! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
+  if (NILP (Vprint_charset_text_property)
+      || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
     {
       string = Fcopy_sequence (string);
       if (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND)
@@ -2423,7 +2423,7 @@ that need to be recorded in the table.  */);
 
   DEFVAR_LISP ("print-charset-text-property", Vprint_charset_text_property,
               doc: /* A flag to control printing of `charset' text property on 
printing a string.
-The value must be nil, t, or `default'.
+The value should be nil, t, or `default'.
 
 If the value is nil, don't print the text property `charset'.
 
@@ -2431,7 +2431,8 @@ If the value is t, always print the text property 
`charset'.
 
 If the value is `default', print the text property `charset' only when
 the value is different from what is guessed in the current charset
-priorities.  */);
+priorities.  Values other than nil or t are also treated as
+`default'.  */);
   Vprint_charset_text_property = Qdefault;
 
   /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
diff --git a/test/src/print-tests.el b/test/src/print-tests.el
index 01e6502..c96cb5d 100644
--- a/test/src/print-tests.el
+++ b/test/src/print-tests.el
@@ -27,6 +27,42 @@
                      (prin1-to-string "\u00A2\ff"))
                    "\"\\x00a2\\ff\"")))
 
+(defun print-tests--prints-with-charset-p (ch odd-charset)
+  "Return t if `prin1-to-string' prints CH with the `charset' property.
+CH is propertized with a `charset' value according to
+ODD-CHARSET: if nil, then use the one returned by `char-charset',
+otherwise, use a different charset."
+  (integerp
+   (string-match
+    "charset"
+    (prin1-to-string
+     (propertize (string ch)
+                 'charset
+                 (if odd-charset
+                     (cl-find (char-charset ch) charset-list :test-not #'eq)
+                   (char-charset ch)))))))
+
+(ert-deftest print-charset-text-property-nil ()
+  (let ((print-charset-text-property nil))
+    (should-not (print-tests--prints-with-charset-p ?\xf6 t)) ; Bug#31376.
+    (should-not (print-tests--prints-with-charset-p ?a t))
+    (should-not (print-tests--prints-with-charset-p ?\xf6 nil))
+    (should-not (print-tests--prints-with-charset-p ?a nil))))
+
+(ert-deftest print-charset-text-property-default ()
+  (let ((print-charset-text-property 'default))
+    (should (print-tests--prints-with-charset-p ?\xf6 t))
+    (should-not (print-tests--prints-with-charset-p ?a t))
+    (should-not (print-tests--prints-with-charset-p ?\xf6 nil))
+    (should-not (print-tests--prints-with-charset-p ?a nil))))
+
+(ert-deftest print-charset-text-property-t ()
+  (let ((print-charset-text-property t))
+    (should (print-tests--prints-with-charset-p ?\xf6 t))
+    (should (print-tests--prints-with-charset-p ?a t))
+    (should (print-tests--prints-with-charset-p ?\xf6 nil))
+    (should (print-tests--prints-with-charset-p ?a nil))))
+
 (ert-deftest terpri ()
   (should (string= (with-output-to-string
                      (princ 'abc)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]