From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Vasilij Schneidermann Newsgroups: gmane.emacs.bugs Subject: bug#27122: 26.0.50; [PATCH] Add customizable to display unprintables as hex Date: Tue, 30 May 2017 10:16:28 +0200 Message-ID: <20170530081628.xwl2ztjnkeqp4m47@odonien.localdomain> References: <20170528204250.wjbrm2pul6cf6xam@odonien.localdomain> <83o9ucfl37.fsf@gnu.org> <20170529062859.mwoveygr5oh5iphz@odonien.localdomain> <8360gjfo51.fsf@gnu.org> <20170529201558.yogm76php5fbpz35@odonien.localdomain> <83tw42eua6.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ylfbeiqzpjn6lm4f" X-Trace: blaine.gmane.org 1496132234 26035 195.159.176.226 (30 May 2017 08:17:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 30 May 2017 08:17:14 +0000 (UTC) User-Agent: NeoMutt/20170428-45-01e908 (1.8.2) Cc: 27122@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 30 10:17:10 2017 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 1dFcL0-0006YY-0s for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 May 2017 10:17:10 +0200 Original-Received: from localhost ([::1]:52090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFcL2-0000yJ-7C for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 May 2017 04:17:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFcKw-0000wp-7M for bug-gnu-emacs@gnu.org; Tue, 30 May 2017 04:17:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFcKs-0007Dz-WE for bug-gnu-emacs@gnu.org; Tue, 30 May 2017 04:17:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41453) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dFcKs-0007Dt-Rz for bug-gnu-emacs@gnu.org; Tue, 30 May 2017 04:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dFcKs-0001na-Gk for bug-gnu-emacs@gnu.org; Tue, 30 May 2017 04:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vasilij Schneidermann Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 30 May 2017 08:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27122 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 27122-submit@debbugs.gnu.org id=B27122.14961322026882 (code B ref 27122); Tue, 30 May 2017 08:17:02 +0000 Original-Received: (at 27122) by debbugs.gnu.org; 30 May 2017 08:16:42 +0000 Original-Received: from localhost ([127.0.0.1]:44130 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dFcKX-0001mw-V2 for submit@debbugs.gnu.org; Tue, 30 May 2017 04:16:42 -0400 Original-Received: from mail-wm0-f66.google.com ([74.125.82.66]:35045) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dFcKV-0001mh-MY for 27122@debbugs.gnu.org; Tue, 30 May 2017 04:16:40 -0400 Original-Received: by mail-wm0-f66.google.com with SMTP id g15so23281968wmc.2 for <27122@debbugs.gnu.org>; Tue, 30 May 2017 01:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Kcf/NXFoT/KD/dp0Cfm+FIfGSoBn2TZgE/29kbT9s0c=; b=T2PoTvVHO4GGEpJ/VMcdzyrK51GNLHY+LuVQUCM51ixlkFoBE/O2AZHlAegq/RarMV qy7hhsWbYvqswM2651s0JjBDUdDxGhNVaqSPkskojWuA+EO03EifuY1eQpNI7wiRlGWk io2FQLuqAn6QfOtleprTpw+tsH1ZIxrxPOg2PCuYAjVDCsnOLpldjgQ/WUqmsNV9FH0E rDRzCb9zfP4PDEeO0umb96VRgw3NF/ho9XDpG0uyXiG1DR9ykxog1JepTr1QMPv0+4CR yE4lzz5QSEfQLYvogAI10LbIfDwGeZEhS/LFw+DNEvnYOFRY8ohXu035crTriBlvx8Ak bgkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Kcf/NXFoT/KD/dp0Cfm+FIfGSoBn2TZgE/29kbT9s0c=; b=bQgoy94CjHFFZHTO6NUyfu6iv+Pt6n7mXwroF71s5Fk16na4VT05otBviW/t35GIV3 a3eLmjXZmyZDDuw7uEkf4TY7s0IosN/YvqL+XgZV4/YfpadEE+PXxa2g+NUsN8itKNd5 TqhcVZ0E5WVx0WLd6Mv8zi6E20G6f+F+/tFtkS6rUJYAAQwI3FCJKuYKtsan8zHoZU6z MjL2amtmAX1Jagg3Moer92ikXZsy3JHEoF6lNzuQNJmhDoVRH+0VOeRv3z4TpkvbnO8N RZdCglzEMTQH0TfCPUdfpQOTcJrZDAgudz4c36lN4BqdJTCyBgmCUgfm7OvAunDwzTi1 BNEw== X-Gm-Message-State: AODbwcCrSc+Mf+9oyhnDNiQUiisV9YPi4RY2lwWpzoW2YX33o1bqNmB1 oiC1aJM4CMEOpA== X-Received: by 10.28.23.131 with SMTP id 125mr763189wmx.42.1496132193791; Tue, 30 May 2017 01:16:33 -0700 (PDT) Original-Received: from localhost (tmo-109-35.customers.d1-online.com. [80.187.109.35]) by smtp.gmail.com with ESMTPSA id q98sm7500996wrb.3.2017.05.30.01.16.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 May 2017 01:16:32 -0700 (PDT) Content-Disposition: inline In-Reply-To: <83tw42eua6.fsf@gnu.org> 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:133046 Archived-At: --ylfbeiqzpjn6lm4f Content-Type: text/plain; charset=utf-8 Content-Disposition: inline > 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. --ylfbeiqzpjn6lm4f Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-Add-customizable-to-display-raw-bytes-as-hex.patch" >From 5a6584d517736eed4a3a067bb7139bc4db6dd797 Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann 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. + * 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 --ylfbeiqzpjn6lm4f--