summaryrefslogtreecommitdiff
path: root/src/doc.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-08-14 15:50:35 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-08-14 15:55:57 -0700
commit244c801689d2f7a80480d83cd7d092d4762ebe08 (patch)
tree6a07abc8b26966002de304b3546f3ccbebb2c865 /src/doc.c
parent293775f10555f7da7e61ed8dbdb78d72f30f7e2d (diff)
downloademacs-244c801689d2f7a80480d83cd7d092d4762ebe08.tar.gz
emacs-244c801689d2f7a80480d83cd7d092d4762ebe08.tar.bz2
emacs-244c801689d2f7a80480d83cd7d092d4762ebe08.zip
Extend ‘format’ to translate curved quotes
This is a followup to the recent doc string change, and deals with diagnostics and the like. This patch is more conservative than the doc string change, in that the behavior of ‘format’ changes only if its first arg contains curved quotes and the user prefers straight or grave quotes. (Come to think of it, perhaps we should be similarly conservative with doc strings too, but that can wait.) The upside of this conservatism is that existing usage is almost surely unaffected. The downside is that we'll eventually have to change Emacs's format strings to use curved quotes in places where the user might want curved quotes, but that's a simple and mechanical translation that I'm willing to do later. (Bug#21222) * doc/lispref/help.texi (Keys in Documentation): Move description of text-quoting-style from here ... * doc/lispref/strings.texi (Formatting Strings): ... to here, and describe new behavior of ‘format’. * etc/NEWS: Describe new behavior. * lisp/calc/calc-help.el (calc-describe-thing): * lisp/emacs-lisp/derived.el (derived-mode-make-docstring): * lisp/info.el (Info-find-index-name): Use ‘concat’ rather than ‘format’ to avoid misinterpretation of recently-added curved quotes. * src/doc.c (uLSQM0, uLSQM1, uLSQM2, uRSQM0, uRSQM1, uRSQM2): Move from here ... * src/lisp.h: ... to here. * src/doc.c (text_quoting_style): New function. (Fsubstitute_command_keys): Use it. * src/editfns.c (Fformat): Implement new behavior. * src/lisp.h (enum text_quoting_style): New enum.
Diffstat (limited to 'src/doc.c')
-rw-r--r--src/doc.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/doc.c b/src/doc.c
index cb52266ef58..9f0ddbc5260 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -684,19 +684,32 @@ the same file name is found in the `doc-directory'. */)
return unbind_to (count, Qnil);
}
-/* Declare named constants for U+2018 LEFT SINGLE QUOTATION MARK and
- U+2019 RIGHT SINGLE QUOTATION MARK, which have UTF-8 encodings
- "\xE2\x80\x98" and "\xE2\x80\x99", respectively. */
-enum
- {
- uLSQM0 = 0xE2, uLSQM1 = 0x80, uLSQM2 = 0x98,
- uRSQM0 = 0xE2, uRSQM1 = 0x80, uRSQM2 = 0x99,
- };
+/* Curved quotation marks. */
static unsigned char const LSQM[] = { uLSQM0, uLSQM1, uLSQM2 };
static unsigned char const RSQM[] = { uRSQM0, uRSQM1, uRSQM2 };
#define uLSQM "\xE2\x80\x98"
#define uRSQM "\xE2\x80\x99"
+/* Return the current effective text quoting style. */
+enum text_quoting_style
+text_quoting_style (void)
+{
+ if (EQ (Vtext_quoting_style, Qgrave))
+ return GRAVE_QUOTING_STYLE;
+ else if (EQ (Vtext_quoting_style, Qstraight))
+ return STRAIGHT_QUOTING_STYLE;
+ else if (NILP (Vtext_quoting_style)
+ && DISP_TABLE_P (Vstandard_display_table))
+ {
+ Lisp_Object dv = DISP_CHAR_VECTOR (XCHAR_TABLE (Vstandard_display_table),
+ LEFT_SINGLE_QUOTATION_MARK);
+ if (VECTORP (dv) && ASIZE (dv) == 1
+ && EQ (AREF (dv, 0), make_number ('`')))
+ return GRAVE_QUOTING_STYLE;
+ }
+ return CURVE_QUOTING_STYLE;
+}
+
DEFUN ("substitute-command-keys", Fsubstitute_command_keys,
Ssubstitute_command_keys, 1, 1, 0,
doc: /* Substitute key descriptions for command names in STRING.
@@ -751,20 +764,7 @@ Otherwise, return a new string. */)
name = Qnil;
GCPRO4 (string, tem, keymap, name);
- enum { unicode, grave_accent, apostrophe } quote_translation = unicode;
- if (EQ (Vtext_quoting_style, Qgrave))
- quote_translation = grave_accent;
- else if (EQ (Vtext_quoting_style, Qstraight))
- quote_translation = apostrophe;
- else if (NILP (Vtext_quoting_style)
- && DISP_TABLE_P (Vstandard_display_table))
- {
- Lisp_Object dv = DISP_CHAR_VECTOR (XCHAR_TABLE (Vstandard_display_table),
- LEFT_SINGLE_QUOTATION_MARK);
- if (VECTORP (dv) && ASIZE (dv) == 1
- && EQ (AREF (dv, 0), make_number ('`')))
- quote_translation = grave_accent;
- }
+ enum text_quoting_style quoting_style = text_quoting_style ();
multibyte = STRING_MULTIBYTE (string);
nchars = 0;
@@ -966,7 +966,7 @@ Otherwise, return a new string. */)
strp = SDATA (string) + idx;
}
}
- else if (strp[0] == '`' && quote_translation == unicode)
+ else if (strp[0] == '`' && quoting_style == CURVE_QUOTING_STYLE)
{
in_quote = true;
start = LSQM;
@@ -976,7 +976,7 @@ Otherwise, return a new string. */)
idx = strp - SDATA (string) + 1;
goto subst;
}
- else if (strp[0] == '`' && quote_translation == apostrophe)
+ else if (strp[0] == '`' && quoting_style == STRAIGHT_QUOTING_STYLE)
{
*bufp++ = '\'';
strp++;
@@ -991,9 +991,9 @@ Otherwise, return a new string. */)
}
else if (strp[0] == uLSQM0 && strp[1] == uLSQM1
&& (strp[2] == uLSQM2 || strp[2] == uRSQM2)
- && quote_translation != unicode)
+ && quoting_style != CURVE_QUOTING_STYLE)
{
- *bufp++ = (strp[2] == uLSQM2 && quote_translation == grave_accent
+ *bufp++ = (strp[2] == uLSQM2 && quoting_style == GRAVE_QUOTING_STYLE
? '`' : '\'');
strp += 3;
nchars++;