unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Vasilij Schneidermann <v.schneidermann@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 27122@debbugs.gnu.org
Subject: bug#27122: 26.0.50; [PATCH] Add customizable to display unprintables as hex
Date: Tue, 30 May 2017 10:16:28 +0200	[thread overview]
Message-ID: <20170530081628.xwl2ztjnkeqp4m47@odonien.localdomain> (raw)
In-Reply-To: <83tw42eua6.fsf@gnu.org>

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

> OK, please submit the patch with the necessary documentation, and
> please add a test for the original and the new behavior.

Where and how should this feature be tested?  I've found
test/manual/redisplay-testsuite.el for manual testing of xdisp.c
features, but also test/src/textprop.el for automated testing which
suggests test/src/xdisp.el might work out.  The only issue with
automatic testing here is that all ERT tests I've seen run in batch mode
which prevents `emacs --batch --eval "(princ (char-to-string ?\200))"`
from doing the right thing.

I've fixed the remaining points.

[-- Attachment #2: 0001-Add-customizable-to-display-raw-bytes-as-hex.patch --]
[-- Type: text/x-diff, Size: 3783 bytes --]

From 5a6584d517736eed4a3a067bb7139bc4db6dd797 Mon Sep 17 00:00:00 2001
From: Vasilij Schneidermann <mail@vasilij.de>
Date: Sun, 28 May 2017 22:31:34 +0200
Subject: [PATCH] Add customizable to display raw bytes as hex

* src/xdisp.c (get_next_display_element): Dispatch used format string
  for unprintables based on new display-raw-bytes-as-hex
  variable
  (display-raw-bytes-as-hex): New variable
* doc/emacs/display.texi: Document the new variable
---
 doc/emacs/display.texi |  6 ++++++
 etc/NEWS               |  4 ++++
 lisp/cus-start.el      |  1 +
 src/xdisp.c            | 16 +++++++++++++---
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index d07913cefb..edcb575722 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -1756,3 +1756,9 @@ Display Custom
 in text that is hard to read.  Call the function
 @code{tty-suppress-bold-inverse-default-colors} with a non-@code{nil}
 argument to suppress the effect of bold-face in this case.
+
+@vindex display-raw-bytes-as-hex
+  Raw bytes are displayed in octal format by default, for example a
+byte with a decimal value of 128 is displayed as @code{\200}.  To
+change display to the hexadecimal format of @code{\x80}, set the
+variable @code{display-raw-bytes-as-hex} to @code{t}.
diff --git a/etc/NEWS b/etc/NEWS
index 60066b7c9f..ee941624d8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -363,6 +363,10 @@ large integers from being displayed as characters.
 ** Two new commands for finding the source code of Emacs Lisp
 libraries: 'find-library-other-window' and 'find-library-other-frame'.
 
++++
+** The new variable 'display-raw-bytes-as-hex' allows to change the
+display of raw bytes from octal to hex.
+
 \f
 * Editing Changes in Emacs 26.1
 
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 4253d40b75..744fe7f69e 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -583,6 +583,7 @@ minibuffer-prompt-properties--setter
 		       (const :tag "Fit (t)" :value t)
 		       (const :tag "Grow only" :value grow-only))
 	      "25.1")
+	     (display-raw-bytes-as-hex display boolean "26.1")
 	     ;; xfaces.c
 	     (scalable-fonts-allowed display boolean "22.1")
 	     ;; xfns.c
diff --git a/src/xdisp.c b/src/xdisp.c
index ddb26b8def..10124d6f3d 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -7044,7 +7044,7 @@ get_next_display_element (struct it *it)
 	     translated too.
 
 	     Non-printable characters and raw-byte characters are also
-	     translated to octal form.  */
+	     translated to octal or hexadecimal form.  */
 	  if (((c < ' ' || c == 127) /* ASCII control chars.  */
 	       ? (it->area != TEXT_AREA
 		  /* In mode line, treat \n, \t like other crl chars.  */
@@ -7151,9 +7151,12 @@ get_next_display_element (struct it *it)
 		int len, i;
 
 		if (CHAR_BYTE8_P (c))
-		  /* Display \200 instead of \17777600.  */
+		  /* Display \200 or \x80 instead of \17777600.  */
 		  c = CHAR_TO_BYTE8 (c);
-		len = sprintf (str, "%03o", c + 0u);
+		const char *format_string = display_raw_bytes_as_hex
+					    ? "x%02x"
+					    : "%03o";
+		len = sprintf (str, format_string, c + 0u);
 
 		XSETINT (it->ctl_chars[0], escape_glyph);
 		for (i = 0; i < len; i++)
@@ -32209,6 +32212,13 @@ display table takes effect; in this case, Emacs does not consult
   /* Initialize to t, since we need to disable reordering until
      loadup.el successfully loads charprop.el.  */
   redisplay__inhibit_bidi = true;
+
+  DEFVAR_BOOL ("display-raw-bytes-as-hex", display_raw_bytes_as_hex,
+    doc: /* Non-nil means display raw bytes in hexadecimal format.
+The default is to use octal format (\200) whereas hexadecimal (\x80)
+may be more familar to users.  */);
+  display_raw_bytes_as_hex = false;
+
 }
 
 
-- 
2.13.0


  reply	other threads:[~2017-05-30  8:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-28 20:42 bug#27122: 26.0.50; [PATCH] Add customizable to display unprintables as hex Vasilij Schneidermann
2017-05-29  2:33 ` Eli Zaretskii
2017-05-29  6:28   ` Vasilij Schneidermann
2017-05-29 18:46     ` Robert Cochran
2017-05-29 19:52       ` Eli Zaretskii
2017-05-29 20:20         ` Vasilij Schneidermann
2017-05-29 23:55           ` Robert Cochran
2017-05-30  0:11             ` npostavs
2017-05-30  0:47               ` Robert Cochran
2017-05-29 19:39     ` Eli Zaretskii
2017-05-29 20:15       ` Vasilij Schneidermann
2017-05-30  6:24         ` Eli Zaretskii
2017-05-30  8:16           ` Vasilij Schneidermann [this message]
2017-05-30  8:38             ` Eli Zaretskii
2017-06-01 17:05               ` Vasilij Schneidermann
2017-06-01 18:19                 ` Eli Zaretskii
2017-05-30 12:06           ` npostavs

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=20170530081628.xwl2ztjnkeqp4m47@odonien.localdomain \
    --to=v.schneidermann@gmail.com \
    --cc=27122@debbugs.gnu.org \
    --cc=eliz@gnu.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).