diff options
| author | Noam Postavsky | 2017-02-11 18:13:54 -0500 |
|---|---|---|
| committer | Noam Postavsky | 2017-06-29 19:40:22 -0400 |
| commit | eb9d3eca801c1ea847956a96fafd29eef9bbe5d1 (patch) | |
| tree | bb2fdd865c9dff46545325d41bf2ba078720d7d7 /src | |
| parent | ead545824e511ab18d18b5223eab80e1f4fe3d64 (diff) | |
| download | emacs-eb9d3eca801c1ea847956a96fafd29eef9bbe5d1.tar.gz emacs-eb9d3eca801c1ea847956a96fafd29eef9bbe5d1.zip | |
Escape control characters in backtraces (Bug#6991)
* src/print.c (syms_of_print): Add new variable,
print-escape-control-characters.
(print_object): Print control characters with octal escape codes when
print-escape-control-characters is true.
* lisp/subr.el (backtrace):
* lisp/emacs-lisp/debug.el (debugger-setup-buffer): Bind
`print-escape-control-characters' to t.
Diffstat (limited to 'src')
| -rw-r--r-- | src/print.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/print.c b/src/print.c index 6bf8af9ef93..50c75d7712c 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -1870,21 +1870,36 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag) | |||
| 1870 | } | 1870 | } |
| 1871 | else | 1871 | else |
| 1872 | { | 1872 | { |
| 1873 | bool still_need_nonhex = false; | ||
| 1873 | /* If we just had a hex escape, and this character | 1874 | /* If we just had a hex escape, and this character |
| 1874 | could be taken as part of it, | 1875 | could be taken as part of it, |
| 1875 | output `\ ' to prevent that. */ | 1876 | output `\ ' to prevent that. */ |
| 1876 | if (need_nonhex && c_isxdigit (c)) | 1877 | if (c_isxdigit (c)) |
| 1877 | print_c_string ("\\ ", printcharfun); | 1878 | { |
| 1878 | 1879 | if (need_nonhex) | |
| 1879 | if (c == '\n' && print_escape_newlines | 1880 | print_c_string ("\\ ", printcharfun); |
| 1880 | ? (c = 'n', true) | 1881 | printchar (c, printcharfun); |
| 1881 | : c == '\f' && print_escape_newlines | 1882 | } |
| 1882 | ? (c = 'f', true) | 1883 | else if (c == '\n' && print_escape_newlines |
| 1883 | : c == '\"' || c == '\\') | 1884 | ? (c = 'n', true) |
| 1884 | printchar ('\\', printcharfun); | 1885 | : c == '\f' && print_escape_newlines |
| 1885 | 1886 | ? (c = 'f', true) | |
| 1886 | printchar (c, printcharfun); | 1887 | : c == '\0' && print_escape_control_characters |
| 1887 | need_nonhex = false; | 1888 | ? (c = '0', still_need_nonhex = true) |
| 1889 | : c == '\"' || c == '\\') | ||
| 1890 | { | ||
| 1891 | printchar ('\\', printcharfun); | ||
| 1892 | printchar (c, printcharfun); | ||
| 1893 | } | ||
| 1894 | else if (print_escape_control_characters && c_iscntrl (c)) | ||
| 1895 | { | ||
| 1896 | char outbuf[1 + 3 + 1]; | ||
| 1897 | int len = sprintf (outbuf, "\\%03o", c + 0u); | ||
| 1898 | strout (outbuf, len, len, printcharfun); | ||
| 1899 | } | ||
| 1900 | else | ||
| 1901 | printchar (c, printcharfun); | ||
| 1902 | need_nonhex = still_need_nonhex; | ||
| 1888 | } | 1903 | } |
| 1889 | } | 1904 | } |
| 1890 | printchar ('\"', printcharfun); | 1905 | printchar ('\"', printcharfun); |
| @@ -2329,6 +2344,11 @@ A value of nil means no limit. See also `eval-expression-print-level'. */); | |||
| 2329 | Also print formfeeds as `\\f'. */); | 2344 | Also print formfeeds as `\\f'. */); |
| 2330 | print_escape_newlines = 0; | 2345 | print_escape_newlines = 0; |
| 2331 | 2346 | ||
| 2347 | DEFVAR_BOOL ("print-escape-control-characters", print_escape_control_characters, | ||
| 2348 | doc: /* Non-nil means print control characters in strings as `\\OOO'. | ||
| 2349 | \(OOO is the octal representation of the character code.)*/); | ||
| 2350 | print_escape_control_characters = 0; | ||
| 2351 | |||
| 2332 | DEFVAR_BOOL ("print-escape-nonascii", print_escape_nonascii, | 2352 | DEFVAR_BOOL ("print-escape-nonascii", print_escape_nonascii, |
| 2333 | doc: /* Non-nil means print unibyte non-ASCII chars in strings as \\OOO. | 2353 | doc: /* Non-nil means print unibyte non-ASCII chars in strings as \\OOO. |
| 2334 | \(OOO is the octal representation of the character code.) | 2354 | \(OOO is the octal representation of the character code.) |
| @@ -2418,6 +2438,7 @@ priorities. */); | |||
| 2418 | DEFSYM (Qprint_escape_newlines, "print-escape-newlines"); | 2438 | DEFSYM (Qprint_escape_newlines, "print-escape-newlines"); |
| 2419 | DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte"); | 2439 | DEFSYM (Qprint_escape_multibyte, "print-escape-multibyte"); |
| 2420 | DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii"); | 2440 | DEFSYM (Qprint_escape_nonascii, "print-escape-nonascii"); |
| 2441 | DEFSYM (Qprint_escape_control_characters, "print-escape-control-characters"); | ||
| 2421 | 2442 | ||
| 2422 | print_prune_charset_plist = Qnil; | 2443 | print_prune_charset_plist = Qnil; |
| 2423 | staticpro (&print_prune_charset_plist); | 2444 | staticpro (&print_prune_charset_plist); |