diff options
| author | Vasilij Schneidermann | 2017-06-01 21:25:58 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-06-01 21:25:58 +0300 |
| commit | cb9aa3515ac00826fd27ade7dfc829134ed38acc (patch) | |
| tree | 1363798d47fc5a7433519129fb726651a4c12a2e | |
| parent | e5de79992a22f2932abb5f1f2600f576a60ae6ef (diff) | |
| download | emacs-cb9aa3515ac00826fd27ade7dfc829134ed38acc.tar.gz emacs-cb9aa3515ac00826fd27ade7dfc829134ed38acc.zip | |
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. (Bug#27122)
* lisp/cus-start.el: Add defcustom form for display-raw-bytes-as-hex.
* doc/emacs/display.texi: Document the new variable.
* etc/NEWS: Mention display-raw-bytes-as-hex.
* test/manual/redisplay-testsuite.el (test-redisplay-5-toggle)
(test-redisplay-5): New tests.
(test-redisplay): Call test-redisplay-5.
| -rw-r--r-- | doc/emacs/display.texi | 6 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/cus-start.el | 1 | ||||
| -rw-r--r-- | src/xdisp.c | 16 | ||||
| -rw-r--r-- | test/manual/redisplay-testsuite.el | 27 |
5 files changed, 50 insertions, 4 deletions
diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi index a0d0792eacc..c4554eb3187 100644 --- a/doc/emacs/display.texi +++ b/doc/emacs/display.texi | |||
| @@ -1763,3 +1763,9 @@ itself, in pixels; the default is 2. | |||
| 1763 | in text that is hard to read. Call the function | 1763 | in text that is hard to read. Call the function |
| 1764 | @code{tty-suppress-bold-inverse-default-colors} with a non-@code{nil} | 1764 | @code{tty-suppress-bold-inverse-default-colors} with a non-@code{nil} |
| 1765 | argument to suppress the effect of bold-face in this case. | 1765 | argument to suppress the effect of bold-face in this case. |
| 1766 | |||
| 1767 | @vindex display-raw-bytes-as-hex | ||
| 1768 | Raw bytes are displayed in octal format by default, for example a | ||
| 1769 | byte with a decimal value of 128 is displayed as @code{\200}. To | ||
| 1770 | change display to the hexadecimal format of @code{\x80}, set the | ||
| 1771 | variable @code{display-raw-bytes-as-hex} to @code{t}. | ||
| @@ -364,6 +364,10 @@ large integers from being displayed as characters. | |||
| 364 | ** Two new commands for finding the source code of Emacs Lisp | 364 | ** Two new commands for finding the source code of Emacs Lisp |
| 365 | libraries: 'find-library-other-window' and 'find-library-other-frame'. | 365 | libraries: 'find-library-other-window' and 'find-library-other-frame'. |
| 366 | 366 | ||
| 367 | +++ | ||
| 368 | ** The new variable 'display-raw-bytes-as-hex' allows to change the | ||
| 369 | display of raw bytes from octal to hex. | ||
| 370 | |||
| 367 | 371 | ||
| 368 | * Editing Changes in Emacs 26.1 | 372 | * Editing Changes in Emacs 26.1 |
| 369 | 373 | ||
diff --git a/lisp/cus-start.el b/lisp/cus-start.el index 4253d40b759..744fe7f69ee 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el | |||
| @@ -583,6 +583,7 @@ since it could result in memory overflow and make Emacs crash." | |||
| 583 | (const :tag "Fit (t)" :value t) | 583 | (const :tag "Fit (t)" :value t) |
| 584 | (const :tag "Grow only" :value grow-only)) | 584 | (const :tag "Grow only" :value grow-only)) |
| 585 | "25.1") | 585 | "25.1") |
| 586 | (display-raw-bytes-as-hex display boolean "26.1") | ||
| 586 | ;; xfaces.c | 587 | ;; xfaces.c |
| 587 | (scalable-fonts-allowed display boolean "22.1") | 588 | (scalable-fonts-allowed display boolean "22.1") |
| 588 | ;; xfns.c | 589 | ;; xfns.c |
diff --git a/src/xdisp.c b/src/xdisp.c index eaa701e9cf1..53210e5be5b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -7055,7 +7055,7 @@ get_next_display_element (struct it *it) | |||
| 7055 | translated too. | 7055 | translated too. |
| 7056 | 7056 | ||
| 7057 | Non-printable characters and raw-byte characters are also | 7057 | Non-printable characters and raw-byte characters are also |
| 7058 | translated to octal form. */ | 7058 | translated to octal or hexadecimal form. */ |
| 7059 | if (((c < ' ' || c == 127) /* ASCII control chars. */ | 7059 | if (((c < ' ' || c == 127) /* ASCII control chars. */ |
| 7060 | ? (it->area != TEXT_AREA | 7060 | ? (it->area != TEXT_AREA |
| 7061 | /* In mode line, treat \n, \t like other crl chars. */ | 7061 | /* In mode line, treat \n, \t like other crl chars. */ |
| @@ -7162,9 +7162,12 @@ get_next_display_element (struct it *it) | |||
| 7162 | int len, i; | 7162 | int len, i; |
| 7163 | 7163 | ||
| 7164 | if (CHAR_BYTE8_P (c)) | 7164 | if (CHAR_BYTE8_P (c)) |
| 7165 | /* Display \200 instead of \17777600. */ | 7165 | /* Display \200 or \x80 instead of \17777600. */ |
| 7166 | c = CHAR_TO_BYTE8 (c); | 7166 | c = CHAR_TO_BYTE8 (c); |
| 7167 | len = sprintf (str, "%03o", c + 0u); | 7167 | const char *format_string = display_raw_bytes_as_hex |
| 7168 | ? "x%02x" | ||
| 7169 | : "%03o"; | ||
| 7170 | len = sprintf (str, format_string, c + 0u); | ||
| 7168 | 7171 | ||
| 7169 | XSETINT (it->ctl_chars[0], escape_glyph); | 7172 | XSETINT (it->ctl_chars[0], escape_glyph); |
| 7170 | for (i = 0; i < len; i++) | 7173 | for (i = 0; i < len; i++) |
| @@ -32231,6 +32234,13 @@ display table takes effect; in this case, Emacs does not consult | |||
| 32231 | /* Initialize to t, since we need to disable reordering until | 32234 | /* Initialize to t, since we need to disable reordering until |
| 32232 | loadup.el successfully loads charprop.el. */ | 32235 | loadup.el successfully loads charprop.el. */ |
| 32233 | redisplay__inhibit_bidi = true; | 32236 | redisplay__inhibit_bidi = true; |
| 32237 | |||
| 32238 | DEFVAR_BOOL ("display-raw-bytes-as-hex", display_raw_bytes_as_hex, | ||
| 32239 | doc: /* Non-nil means display raw bytes in hexadecimal format. | ||
| 32240 | The default is to use octal format (\200) whereas hexadecimal (\x80) | ||
| 32241 | may be more familar to users. */); | ||
| 32242 | display_raw_bytes_as_hex = false; | ||
| 32243 | |||
| 32234 | } | 32244 | } |
| 32235 | 32245 | ||
| 32236 | 32246 | ||
diff --git a/test/manual/redisplay-testsuite.el b/test/manual/redisplay-testsuite.el index 694d55ab1db..2175cbab1b7 100644 --- a/test/manual/redisplay-testsuite.el +++ b/test/manual/redisplay-testsuite.el | |||
| @@ -34,7 +34,8 @@ | |||
| 34 | (setq overlay (make-overlay opoint (point))) | 34 | (setq overlay (make-overlay opoint (point))) |
| 35 | (while props | 35 | (while props |
| 36 | (overlay-put overlay (car props) (cadr props)) | 36 | (overlay-put overlay (car props) (cadr props)) |
| 37 | (setq props (cddr props))))) | 37 | (setq props (cddr props))) |
| 38 | overlay)) | ||
| 38 | 39 | ||
| 39 | (defun test-redisplay-1 () | 40 | (defun test-redisplay-1 () |
| 40 | (insert "Test 1: Displaying adjacent and overlapping overlays:\n\n") | 41 | (insert "Test 1: Displaying adjacent and overlapping overlays:\n\n") |
| @@ -293,6 +294,29 @@ static unsigned char x_bits[] = {0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xbd, 0x81, 0xff | |||
| 293 | 294 | ||
| 294 | (insert "\n")) | 295 | (insert "\n")) |
| 295 | 296 | ||
| 297 | (defvar test-redisplay-5-expected-overlay nil) | ||
| 298 | (defvar test-redisplay-5-result-overlay nil) | ||
| 299 | |||
| 300 | (defun test-redisplay-5-toggle (_event) | ||
| 301 | (interactive "e") | ||
| 302 | (setq display-raw-bytes-as-hex (not display-raw-bytes-as-hex)) | ||
| 303 | (let ((label (if display-raw-bytes-as-hex "\\x80" "\\200"))) | ||
| 304 | (overlay-put test-redisplay-5-expected-overlay 'display | ||
| 305 | (propertize label 'face 'escape-glyph)))) | ||
| 306 | |||
| 307 | (defun test-redisplay-5 () | ||
| 308 | (insert "Test 5: Display of raw bytes:\n\n") | ||
| 309 | (insert " Expected: ") | ||
| 310 | (setq test-redisplay-5-expected-overlay | ||
| 311 | (test-insert-overlay " " 'display | ||
| 312 | (propertize "\\200" 'face 'escape-glyph))) | ||
| 313 | (insert "\n Result: ") | ||
| 314 | (setq test-redisplay-5-result-overlay | ||
| 315 | (test-insert-overlay " " 'display "\200")) | ||
| 316 | (insert "\n\n") | ||
| 317 | (insert-button "Toggle between octal and hex display" | ||
| 318 | 'action 'test-redisplay-5-toggle)) | ||
| 319 | |||
| 296 | 320 | ||
| 297 | (defun test-redisplay () | 321 | (defun test-redisplay () |
| 298 | (interactive) | 322 | (interactive) |
| @@ -309,5 +333,6 @@ static unsigned char x_bits[] = {0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xbd, 0x81, 0xff | |||
| 309 | (test-redisplay-2) | 333 | (test-redisplay-2) |
| 310 | (test-redisplay-3) | 334 | (test-redisplay-3) |
| 311 | (test-redisplay-4) | 335 | (test-redisplay-4) |
| 336 | (test-redisplay-5) | ||
| 312 | (goto-char (point-min)))) | 337 | (goto-char (point-min)))) |
| 313 | 338 | ||