From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#31376: 26.0.50; print-charset-text-property not honored Date: Sun, 13 May 2018 15:42:02 -0400 Message-ID: <87o9hjjqb9.fsf@gmail.com> References: <87d0y7ew2h.fsf@linux-m68k.org> <87603zmxna.fsf@gmail.com> <83mux6nws8.fsf@gnu.org> <837eoani9b.fsf@gnu.org> <871seglk1y.fsf@gmail.com> <83r2mflgkh.fsf@gnu.org> <87r2mfjtnd.fsf@gmail.com> <83lgcnl789.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1526251358 7010 195.159.176.226 (13 May 2018 22:42:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 13 May 2018 22:42:38 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: 31376@debbugs.gnu.org, schwab@linux-m68k.org, eller.helmut@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 14 00:42:33 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fHzhJ-0001gU-1b for geb-bug-gnu-emacs@m.gmane.org; Mon, 14 May 2018 00:42:33 +0200 Original-Received: from localhost ([::1]:33066 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHzjO-0006rq-LJ for geb-bug-gnu-emacs@m.gmane.org; Sun, 13 May 2018 18:44:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHzg2-0008Qk-Sa for bug-gnu-emacs@gnu.org; Sun, 13 May 2018 18:41:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fHwta-0008Ad-Qs for bug-gnu-emacs@gnu.org; Sun, 13 May 2018 15:43:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53117) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fHwta-0008AS-L4 for bug-gnu-emacs@gnu.org; Sun, 13 May 2018 15:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fHwta-0002VK-5g for bug-gnu-emacs@gnu.org; Sun, 13 May 2018 15:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 13 May 2018 19:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31376 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 31376-submit@debbugs.gnu.org id=B31376.15262405319569 (code B ref 31376); Sun, 13 May 2018 19:43:02 +0000 Original-Received: (at 31376) by debbugs.gnu.org; 13 May 2018 19:42:11 +0000 Original-Received: from localhost ([127.0.0.1]:32781 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fHwsl-0002UG-1s for submit@debbugs.gnu.org; Sun, 13 May 2018 15:42:11 -0400 Original-Received: from mail-it0-f43.google.com ([209.85.214.43]:40660) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fHwsj-0002U2-Oc for 31376@debbugs.gnu.org; Sun, 13 May 2018 15:42:10 -0400 Original-Received: by mail-it0-f43.google.com with SMTP id j186-v6so8163606ita.5 for <31376@debbugs.gnu.org>; Sun, 13 May 2018 12:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=/aukJtsYg42a5YbxvVWdSWzUrRcwKrqVFq1RkIk3Nbg=; b=hwOTrfATNy9FfiJtLmxaM6+mRe1JAe1g7KVmSxNgBtzxQapdHWiMhfY+LuN43Nfvmk tc+o0sDlE7ciXAU6RUvht62hSklgZb9l+6wnDRjavcDS1m/0d5BTDII8R9Yv+DxxHAiJ vBF7Q2K32ZfTqUPb9yjdU/QVmrn4pmUKzDXo43q7rV3Zm21jmjW619LGp1fnK13aWR0+ Iu5gD07XbSuzUmLKW9nxZkiU9XtfSrmnWHQX6SeSEl9C8lcWIC/79ADCAd9G3nG2PgRR tCFbpNi/hEIvDUKfFnO4l41Z0cYe6Iq79rO3FCwXOlMCXwqX4TNGGgUWBsYgUjASB4A0 pNZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=/aukJtsYg42a5YbxvVWdSWzUrRcwKrqVFq1RkIk3Nbg=; b=Gellp6OsN+TjqM++cNH/FhRL4iKtLW06XlhVY0nsimwGL2g+L+8eTO7UGyXdn4SvK8 huVr1eCqSTkCJb8mB46H4YSTaBEtKy14aKbGqJnGn9Lc5YWFFnzlKrZcb5vgGIY8Ds3A T5u2iKMHU3DrM/Zwk/vY3WzVvwo56iImvGNXsA73/ki8M0ov/72tGQKxKZ/z+BqRZLae c3iBzeh4k3OdxbaFK1Qh42cUPgs15bvzQx7xJIhx/vkQp0cV0COq+ZUrc+aeeif2y1MY 5V7wuovP+sq713vKwD84G2eI4+XOu5ZvfVoDysVYugxKTkqQ7oWpfcaLXRZh/tanMjpg j3pg== X-Gm-Message-State: ALKqPwce642Y8JcWyai187wE+XMVkHJrIw9nZ/ta1YiFeYlT8qivK4LA an3VyfdGs1Njp2kT1yCAYy4= X-Google-Smtp-Source: AB8JxZpewHKKpTyc0U1b5FfU+WtIafKiANAayCyn2bNVySPJ4mQYFLyscg2zE4hVRJ7S8mhSm/blXg== X-Received: by 2002:a24:b54d:: with SMTP id j13-v6mr6173699iti.127.1526240524229; Sun, 13 May 2018 12:42:04 -0700 (PDT) Original-Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id r137-v6sm2816995ita.8.2018.05.13.12.42.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 May 2018 12:42:03 -0700 (PDT) In-Reply-To: <83lgcnl789.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 13 May 2018 21:51:18 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:146158 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v2-0001-Honor-print-charset-text-property-value-of-nil-Bu.patch Content-Description: patch >From b2ff6ca64fbde643867f4ddada1d8939c7e1ba1f Mon Sep 17 00:00:00 2001 From: Noam Postavsky 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) : 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 --=-=-=--