From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nathan Trapuzzano Newsgroups: gmane.emacs.bugs Subject: bug#15747: Patch to optionally display raw bytes in hexadecimal Date: Tue, 29 Oct 2013 09:52:55 -0400 Message-ID: <87hac0uqtk.fsf@nbtrap.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1383054868 21210 80.91.229.3 (29 Oct 2013 13:54:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Oct 2013 13:54:28 +0000 (UTC) To: 15747@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 29 14:54:32 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vb9kc-0001Da-Rs for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Oct 2013 14:54:31 +0100 Original-Received: from localhost ([::1]:47319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vb9kc-0005q9-FX for geb-bug-gnu-emacs@m.gmane.org; Tue, 29 Oct 2013 09:54:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vb9kG-0005QE-H9 for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2013 09:54:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vb9kA-0005EL-S0 for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2013 09:54:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vb9kA-0005EH-OJ for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2013 09:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Vb9kA-0000Z3-BV for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2013 09:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Nathan Trapuzzano Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Oct 2013 13:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 15747 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13830548312150 (code B ref -1); Tue, 29 Oct 2013 13:54:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Oct 2013 13:53:51 +0000 Original-Received: from localhost ([127.0.0.1]:50911 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vb9jy-0000Yb-Ee for submit@debbugs.gnu.org; Tue, 29 Oct 2013 09:53:51 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33033) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vb9jq-0000YF-9a for submit@debbugs.gnu.org; Tue, 29 Oct 2013 09:53:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vb9jg-00054G-S0 for submit@debbugs.gnu.org; Tue, 29 Oct 2013 09:53:36 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:46773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vb9jg-00054B-Ok for submit@debbugs.gnu.org; Tue, 29 Oct 2013 09:53:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vb9jb-0005MC-CH for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2013 09:53:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vb9jV-00052t-US for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2013 09:53:27 -0400 Original-Received: from oproxy12-pub.mail.unifiedlayer.com ([50.87.16.10]:55030) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Vb9jV-00052d-Ic for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2013 09:53:21 -0400 Original-Received: (qmail 21746 invoked by uid 0); 29 Oct 2013 13:52:57 -0000 Original-Received: from unknown (HELO host393.hostmonster.com) (66.147.240.193) by oproxy12.mail.unifiedlayer.com with SMTP; 29 Oct 2013 13:52:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbtrap.com; s=default; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From; bh=LtHSirtdxNubgg3R/UxvDotCZGpfz3OhLgBl7s4qZJI=; b=bGqjIM///TilK0+4yQ+hisP8wmhOYfunHYcdDlB+Y94T1zPb8iL30u4DbL5cDyrlKYqajCeI1T7LUIMVs75zs63m5pz2YRqBx/gVX0STjv+FafWBfm1swIffuRQBOtV2; Original-Received: from [50.90.253.209] (port=54653 helo=Nathan-GNU) by host393.hostmonster.com with esmtpsa (TLSv1:CAMELLIA128-SHA:128) (Exim 4.80) (envelope-from ) id 1Vb9j7-0003rl-8z for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2013 07:52:57 -0600 User-Agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux) X-Identified-User: {1585:host393.hostmonster.com:nbtrapco:nbtrap.com} {sentby:smtp auth 50.90.253.209 authed with nbtrap@nbtrap.com} X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:79747 Archived-At: --=-=-= Content-Type: text/plain I never understood why raw bytes in emacs are displayed as octal escapes rather than hexadecimal. The latter is much more intuitive to my mind. The attached patch adds the option to display these bytes in hex rather than octal. If it's not accepted, please advise what changes I can make to give it a better chance. Nathan --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=hex.patch >From 3938a8a7225e5644cadb14d39d24fc18a33cfd3e Mon Sep 17 00:00:00 2001 From: Nathan Trapuzzano Date: Thu, 25 Jul 2013 15:47:23 -0400 Subject: [PATCH] Define and implement `display-raw-bytes-as-hex' variable. This allows raw bytes to be displayed with hexadecimal escape sequences rather than octal. --- doc/emacs/ChangeLog | 4 ++++ doc/emacs/display.texi | 4 ++++ doc/lispref/ChangeLog | 4 ++++ doc/lispref/display.texi | 30 ++++++++++++++++++++---------- lisp/ChangeLog | 4 ++++ lisp/cus-start.el | 1 + src/ChangeLog | 5 +++++ src/xdisp.c | 8 +++++++- 8 files changed, 49 insertions(+), 11 deletions(-) diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog index eafe608..595eef3 100644 --- a/doc/emacs/ChangeLog +++ b/doc/emacs/ChangeLog @@ -1,3 +1,7 @@ +2013-10-29 Nathan Trapuzzano + + * display.texi (Text Display): Document `display-raw-bytes-as-hex'. + 2013-10-23 Glenn Morris * files.texi, glossary.texi, killing.texi, search.texi, sending.texi: diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi index 80dffe2..0ffa79d 100644 --- a/doc/emacs/display.texi +++ b/doc/emacs/display.texi @@ -1400,6 +1400,7 @@ character, @code{U+0001}, is displayed as @samp{^A}. @cindex octal escapes @vindex ctl-arrow +@vindex display-raw-bytes-as-hex The raw bytes with codes @code{U+0080} (octal 200) through @code{U+009F} (octal 237) are displayed as @dfn{octal escape sequences}, with the @code{escape-glyph} face. For instance, @@ -1407,6 +1408,9 @@ character code @code{U+0098} (octal 230) is displayed as @samp{\230}. If you change the buffer-local variable @code{ctl-arrow} to @code{nil}, the @acronym{ASCII} control characters are also displayed as octal escape sequences instead of caret escape sequences. +Moreover, setting @code{display-raw-bytes-as-hex} to non-@code{nil} +causes Emacs to display hexadecimal, rather than octal, escape +sequences. @vindex nobreak-char-display @cindex non-breaking space diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 6416991..e51c3f9 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,7 @@ +2013-10-29 Nathan Trapuzzano + + * display.texi (Usual Display): Document `display-raw-bytes-as-hex'. + 2013-10-29 Xue Fuqiao * display.texi (Showing Images): Add an index for image-size. diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 1194e26..77e3c43 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -5906,11 +5906,13 @@ conversion (@pxref{Coding System Basics}). @cindex octal escapes @item @dfn{Raw bytes} are non-@acronym{ASCII} characters with codes 128 -through 255 (@pxref{Text Representations}). These characters display -as @dfn{octal escapes}: sequences of four glyphs, where the first -glyph is the @acronym{ASCII} code for @samp{\}, and the others are -digit characters representing the character code in octal. (A display -table can specify a glyph to use instead of @samp{\}.) +through 255 (@pxref{Text Representations}). By default, these +characters display as @dfn{octal escapes}: sequences of four glyphs, +where the first glyph is the @acronym{ASCII} code for @samp{\}, and +the others are digit characters representing the character code in +octal. (A display table can specify a glyph to use instead of +@samp{\}.) To display these bytes as hexadecimal escape sequences +rather than octal, set @code{display-raw-bytes-as-hex} to @code{t}. @item Each non-@acronym{ASCII} character with code above 255 is displayed @@ -5928,11 +5930,11 @@ table, for any character whose entry in the active display table is specify the characters for which you want special behavior. The following variables affect how certain characters are displayed -on the screen. Since they change the number of columns the characters -occupy, they also affect the indentation functions. They also affect -how the mode line is displayed; if you want to force redisplay of the -mode line using the new values, call the function -@code{force-mode-line-update} (@pxref{Mode Line Format}). +on the screen. Some of these change the number of columns the +characters occupy, which affects the indentation functions. These +also affect the display of characters in the mode line; if you want to +force redisplay of the mode line using the new values, call the +function @code{force-mode-line-update} (@pxref{Mode Line Format}). @defopt ctl-arrow @cindex control characters in display @@ -5951,6 +5953,14 @@ is completely independent of the user-settable tab stops used by the command @code{tab-to-tab-stop}. @xref{Indent Tabs}. @end defopt +@defopt display-raw-bytes-as-hex +Setting this variable to any value other than @code{nil} will cause +raw bytes to be displayed as hexadecimal escape sequences rather than +octal. The two-digit sequences will be prepended with @samp{x}, which +will in turn be prepended with @samp{\}, or whatever glyph the current +display table specifies for this purpose. +@end defopt + @node Display Tables @subsection Display Tables diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9519a07..fb82d84 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2013-10-29 Nathan Trapuzzano + + * cus-start.el: Add `display-raw-bytes-as-hex' to `display' group. + 2013-10-29 Daniel Colascione * net/tramp.el (tramp-methods): Document new functionality. diff --git a/lisp/cus-start.el b/lisp/cus-start.el index 24f8ac3..f15a744 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -71,6 +71,7 @@ (left-margin fill integer) (tab-width editing-basics integer) (ctl-arrow display boolean) + (display-raw-bytes-as-hex display boolean) (truncate-lines display boolean) (word-wrap display boolean) (selective-display-ellipses display boolean) diff --git a/src/ChangeLog b/src/ChangeLog index c9792e6..a4a4089 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2013-10-29 Nathan Trapuzzano + + * xdisp.c (Vdisplay_raw_bytes_as_hex, get_next_display_element): + Define and implement `display-raw-bytes-as-hex'. + 2013-10-29 Dmitry Antipov * xterm.h (struct x_output): For 'black_relief' and 'white_relief' diff --git a/src/xdisp.c b/src/xdisp.c index d62bc6b..ff074a8 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -6723,6 +6723,7 @@ get_next_display_element (struct it *it) function pointer `method' used here turns out to be faster than using a sequence of if-statements. */ int success_p; + const char *disp_format = Vdisplay_raw_bytes_as_hex ? "x%02X" : "%03o"; get_next: success_p = GET_NEXT_DISPLAY_ELEMENT (it); @@ -6927,7 +6928,7 @@ get_next_display_element (struct it *it) if (CHAR_BYTE8_P (c)) /* Display \200 instead of \17777600. */ c = CHAR_TO_BYTE8 (c); - len = sprintf (str, "%03o", c); + len = sprintf (str, disp_format, c); XSETINT (it->ctl_chars[0], escape_glyph); for (i = 0; i < len; i++) @@ -29347,6 +29348,11 @@ wide as that tab on the display. */); The face used for trailing whitespace is `trailing-whitespace'. */); Vshow_trailing_whitespace = Qnil; + DEFVAR_BOOL ("display-raw-bytes-as-hex", Vdisplay_raw_bytes_as_hex, + doc: /* Non-nil means display raw 8-bit bytes as hexadecimal +escape sequences as opposed to the default octal escape sequences. */); + Vdisplay_raw_bytes_as_hex = 0; + DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display, doc: /* Control highlighting of non-ASCII space and hyphen chars. If the value is t, Emacs highlights non-ASCII chars which have the -- 1.8.4.2 --=-=-=--