diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-08-25 18:41:31 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-08-25 19:00:20 -0700 |
commit | 71781c31a4860e56434643296eaa303ca43386bb (patch) | |
tree | 271e4e378ac38caa3212d8e2025186715b5e1802 /src/doc.c | |
parent | ef4c2eac6c6e1df8f40efde52d737d911cf2dcf9 (diff) | |
download | emacs-71781c31a4860e56434643296eaa303ca43386bb.tar.gz |
format-message now curves ` and '
That way, the caller doesn’t have to use curved quotes to
get diagnostics that match the text-quoting-style preferences.
Suggested by Dmitry Gutov in:
http://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00893.html
This means we no longer need %qs, so remove that format.
While we’re at it, fix an unlikely bug and lessen the pressure
on the garbage collector by processing the string once rather
than twice in the usual case.
* doc/lispref/strings.texi (Formatting Strings):
* etc/NEWS: Document this.
* lisp/subr.el (format-message): Remove; now done in C.
* src/callint.c (Fcall_interactively):
* src/editfns.c (Fmessage, Fmessage_box):
Use Fformat_message instead of Finternal__text_restyle
followed by Fformat.
* src/doc.c (LSQM, RSQM): Remove; all uses changed to use
uLSQM and uRSQM.
(Fsubstitute_command_keys): Prefer AUTO_STRING to build_string
when pure ASCII now suffices. Fix unlikely bug when parsing
unibyte string containing non-ASCII bytes. Use inline code
rather than memcpy, as it’s a tiny number of bytes.
(Finternal__text_restyle): Remove; no longer used.
(syms_of_doc): Don’t declare it.
* src/editfns.c (Fformat): Rewrite in terms of new function
‘styled_format’.
(Fformat_message): New function, moved here from subr.el.
(styled_format): New function, with the old guts of Fformat,
except it now optionally transliterates quotes, and it transliterates
traditional grave accent and apostrophe quoting as well.
Remove recently-added q flag; no longer needed or used.
(syms_of_editfns): Define format-message.
* src/lisp.h (uLSQM0, uLSQM1, uLSQM2, uRSQM0, uRSQM1, uRSQM2):
Remove; no longer need to be global symbols.
* src/xdisp.c (vadd_to_log): Use Fformat_message, not Fformat,
so that callers can use `%s'.
* src/image.c (image_size_error, xbm_load_image, xbm_load)
(xpm_load, pbm_load, png_load_body, jpeg_load_body, tiff_load)
(gif_load, imagemagick_load_image, imagemagick_load, svg_load)
(svg_load_image, gs_load, x_kill_gs_process):
* src/lread.c (load_warn_old_style_backquotes):
* src/xfaces.c (load_pixmap):
* src/xselect.c (x_clipboard_manager_error_1):
Use `%s' instead of %qs in formats.
Diffstat (limited to 'src/doc.c')
-rw-r--r-- | src/doc.c | 115 |
1 files changed, 24 insertions, 91 deletions
diff --git a/src/doc.c b/src/doc.c index 7a298e28631..637200f648e 100644 --- a/src/doc.c +++ b/src/doc.c @@ -684,10 +684,7 @@ the same file name is found in the `doc-directory'. */) return unbind_to (count, Qnil); } -/* Curved quotation marks. */ -static unsigned char const LSQM[] = { uLSQM0, uLSQM1, uLSQM2 }; -static unsigned char const RSQM[] = { uRSQM0, uRSQM1, uRSQM2 }; - +/* Return true if text quoting style should default to quote `like this'. */ static bool default_to_grave_quoting_style (void) { @@ -925,14 +922,13 @@ Otherwise, return a new string. */) if (NILP (tem)) { name = Fsymbol_name (name); - insert1 (Fsubstitute_command_keys - (build_string ("\nUses keymap "uLSQM))); + AUTO_STRING (msg_prefix, "\nUses keymap `"); + insert1 (Fsubstitute_command_keys (msg_prefix)); insert_from_string (name, 0, 0, SCHARS (name), SBYTES (name), 1); - insert1 (Fsubstitute_command_keys - (build_string - (uRSQM", which is not currently defined.\n"))); + AUTO_STRING (msg_suffix, "', which is not currently defined.\n"); + insert1 (Fsubstitute_command_keys (msg_suffix)); if (start[-1] == '<') keymap = Qnil; } else if (start[-1] == '<') @@ -972,9 +968,9 @@ Otherwise, return a new string. */) else if ((strp[0] == '`' || strp[0] == '\'') && quoting_style == CURVE_QUOTING_STYLE) { - start = strp[0] == '`' ? LSQM : RSQM; + start = (unsigned char const *) (strp[0] == '`' ? uLSQM : uRSQM); length = 1; - length_byte = 3; + length_byte = sizeof uLSQM - 1; idx = strp - SDATA (string) + 1; goto subst; } @@ -985,29 +981,28 @@ Otherwise, return a new string. */) nchars++; changed = true; } - else if (strp[0] == uLSQM0 && strp[1] == uLSQM1 - && (strp[2] == uLSQM2 || strp[2] == uRSQM2) - && quoting_style != CURVE_QUOTING_STYLE) - { - *bufp++ = (strp[2] == uLSQM2 && quoting_style == GRAVE_QUOTING_STYLE - ? '`' : '\''); - strp += 3; - nchars++; - changed = true; - } - else if (! multibyte) /* just copy other chars */ + else if (! multibyte) *bufp++ = *strp++, nchars++; else { int len; - - STRING_CHAR_AND_LENGTH (strp, len); - if (len == 1) - *bufp = *strp; + int ch = STRING_CHAR_AND_LENGTH (strp, len); + if ((ch == LEFT_SINGLE_QUOTATION_MARK + || ch == RIGHT_SINGLE_QUOTATION_MARK) + && quoting_style != CURVE_QUOTING_STYLE) + { + *bufp++ = ((ch == LEFT_SINGLE_QUOTATION_MARK + && quoting_style == GRAVE_QUOTING_STYLE) + ? '`' : '\''); + strp += len; + changed = true; + } else - memcpy (bufp, strp, len); - strp += len; - bufp += len; + { + do + *bufp++ = *strp++; + while (--len != 0); + } nchars++; } } @@ -1019,67 +1014,6 @@ Otherwise, return a new string. */) xfree (buf); RETURN_UNGCPRO (tem); } - -DEFUN ("internal--text-restyle", Finternal__text_restyle, - Sinternal__text_restyle, 1, 1, 0, - doc: /* Return STRING, possibly substituting quote characters. - -In the result, replace each curved single quote (\\=‘ and \\=’) by -left and right quote characters as specified by ‘text-quoting-style’. - -Return the original STRING in the common case where no changes are needed. -Otherwise, return a new string. */) - (Lisp_Object string) -{ - bool changed = false; - - CHECK_STRING (string); - if (! STRING_MULTIBYTE (string)) - return string; - - enum text_quoting_style quoting_style = text_quoting_style (); - if (quoting_style == CURVE_QUOTING_STYLE) - return string; - - ptrdiff_t bsize = SBYTES (string); - unsigned char const *strp = SDATA (string); - unsigned char const *strlim = strp + bsize; - USE_SAFE_ALLOCA; - char *buf = SAFE_ALLOCA (bsize); - char *bufp = buf; - ptrdiff_t nchars = 0; - - while (strp < strlim) - { - unsigned char const *cp = strp; - switch (STRING_CHAR_ADVANCE (strp)) - { - case LEFT_SINGLE_QUOTATION_MARK: - *bufp++ = quoting_style == GRAVE_QUOTING_STYLE ? '`': '\''; - changed = true; - break; - - case RIGHT_SINGLE_QUOTATION_MARK: - *bufp++ = '\''; - changed = true; - break; - - default: - do - *bufp++ = *cp++; - while (cp != strp); - - break; - } - - nchars++; - } - - Lisp_Object result - = changed ? make_string_from_bytes (buf, nchars, bufp - buf) : string; - SAFE_FREE (); - return result; -} void syms_of_doc (void) @@ -1113,5 +1047,4 @@ displayable, and like ‘grave’ otherwise. */); defsubr (&Sdocumentation_property); defsubr (&Ssnarf_documentation); defsubr (&Ssubstitute_command_keys); - defsubr (&Sinternal__text_restyle); } |