unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 31376@debbugs.gnu.org, schwab@linux-m68k.org, eller.helmut@gmail.com
Subject: bug#31376: 26.0.50; print-charset-text-property not honored
Date: Sun, 13 May 2018 15:42:02 -0400	[thread overview]
Message-ID: <87o9hjjqb9.fsf@gmail.com> (raw)
In-Reply-To: <83lgcnl789.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 13 May 2018 21:51:18 +0300")

[-- Attachment #1: Type: text/plain, Size: 400 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> CHAR_CHARSET always returns 'ascii' for ASCII characters, while
> showing 'charset' for ASCII characters probably makes littles sense.
> Of course, that's only my guess, the default behavior wrt this is pure
> heuristics, so YMMV.
>
> We could mention this exception in the manual.

Yeah, I think we should.  Here's a new patch with updated manual and
tests.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 6005 bytes --]

From b2ff6ca64fbde643867f4ddada1d8939c7e1ba1f Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Fri, 11 May 2018 13:44:46 -0400
Subject: [PATCH v2] 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  | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/doc/lispref/streams.texi b/doc/lispref/streams.texi
index ebd806601e..032669cb10 100644
--- a/doc/lispref/streams.texi
+++ b/doc/lispref/streams.texi
@@ -809,6 +809,21 @@ Output Variables
 one.
 @end defvar
 
+@defvar 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
+@code{default}.
+
+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}.
+@end 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 15177759cf..427ab7d158 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)
@@ -2422,7 +2422,7 @@ representation) and `#N#' in place of each subsequent occurrence,
 
   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'.
 
@@ -2430,7 +2430,8 @@ representation) and `#N#' in place of each subsequent occurrence,
 
 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 01e65028bc..a1825b79d0 100644
--- a/test/src/print-tests.el
+++ b/test/src/print-tests.el
@@ -27,6 +27,44 @@
                      (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
+                     (car (if (eq (char-charset ch) (car charset-list))
+                              charset-list
+                            (cdr charset-list)))
+                   (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)
-- 
2.11.0


  reply	other threads:[~2018-05-13 19:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-07  6:48 bug#31376: 26.0.50; print-charset-text-property not honored Helmut Eller
2018-05-07  7:58 ` Andreas Schwab
2018-05-07  8:38   ` Helmut Eller
2018-05-07 12:57     ` Noam Postavsky
2018-05-07 18:08       ` Helmut Eller
2018-05-11 13:31         ` Eli Zaretskii
2018-05-11 17:44           ` Noam Postavsky
2018-05-11 18:45             ` Eli Zaretskii
2018-05-12 20:02               ` Noam Postavsky
2018-05-13 15:29                 ` Eli Zaretskii
2018-05-13 18:29                   ` Noam Postavsky
2018-05-13 18:51                     ` Eli Zaretskii
2018-05-13 19:42                       ` Noam Postavsky [this message]
2018-05-14 16:34                         ` Eli Zaretskii
2018-05-14 23:15                           ` Noam Postavsky
2018-05-15 17:19                             ` Eli Zaretskii
2018-05-15 23:37                               ` Noam Postavsky
2018-05-23 23:12                                 ` Noam Postavsky
     [not found]             ` <<837eoani9b.fsf@gnu.org>
2018-05-11 19:58               ` Drew Adams
2018-05-12  6:10                 ` Eli Zaretskii
     [not found] <<m2zi1c6jvo.fsf@caladan>

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o9hjjqb9.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=31376@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=eller.helmut@gmail.com \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).