diff options
| author | Paul Eggert | 2015-08-14 15:50:35 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-08-14 15:55:57 -0700 |
| commit | 244c801689d2f7a80480d83cd7d092d4762ebe08 (patch) | |
| tree | 6a07abc8b26966002de304b3546f3ccbebb2c865 /src/doc.c | |
| parent | 293775f10555f7da7e61ed8dbdb78d72f30f7e2d (diff) | |
| download | emacs-244c801689d2f7a80480d83cd7d092d4762ebe08.tar.gz 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.c | 52 |
1 files changed, 26 insertions, 26 deletions
| @@ -684,19 +684,32 @@ the same file name is found in the `doc-directory'. */) | |||
| 684 | return unbind_to (count, Qnil); | 684 | return unbind_to (count, Qnil); |
| 685 | } | 685 | } |
| 686 | 686 | ||
| 687 | /* Declare named constants for U+2018 LEFT SINGLE QUOTATION MARK and | 687 | /* Curved quotation marks. */ |
| 688 | U+2019 RIGHT SINGLE QUOTATION MARK, which have UTF-8 encodings | ||
| 689 | "\xE2\x80\x98" and "\xE2\x80\x99", respectively. */ | ||
| 690 | enum | ||
| 691 | { | ||
| 692 | uLSQM0 = 0xE2, uLSQM1 = 0x80, uLSQM2 = 0x98, | ||
| 693 | uRSQM0 = 0xE2, uRSQM1 = 0x80, uRSQM2 = 0x99, | ||
| 694 | }; | ||
| 695 | static unsigned char const LSQM[] = { uLSQM0, uLSQM1, uLSQM2 }; | 688 | static unsigned char const LSQM[] = { uLSQM0, uLSQM1, uLSQM2 }; |
| 696 | static unsigned char const RSQM[] = { uRSQM0, uRSQM1, uRSQM2 }; | 689 | static unsigned char const RSQM[] = { uRSQM0, uRSQM1, uRSQM2 }; |
| 697 | #define uLSQM "\xE2\x80\x98" | 690 | #define uLSQM "\xE2\x80\x98" |
| 698 | #define uRSQM "\xE2\x80\x99" | 691 | #define uRSQM "\xE2\x80\x99" |
| 699 | 692 | ||
| 693 | /* Return the current effective text quoting style. */ | ||
| 694 | enum text_quoting_style | ||
| 695 | text_quoting_style (void) | ||
| 696 | { | ||
| 697 | if (EQ (Vtext_quoting_style, Qgrave)) | ||
| 698 | return GRAVE_QUOTING_STYLE; | ||
| 699 | else if (EQ (Vtext_quoting_style, Qstraight)) | ||
| 700 | return STRAIGHT_QUOTING_STYLE; | ||
| 701 | else if (NILP (Vtext_quoting_style) | ||
| 702 | && DISP_TABLE_P (Vstandard_display_table)) | ||
| 703 | { | ||
| 704 | Lisp_Object dv = DISP_CHAR_VECTOR (XCHAR_TABLE (Vstandard_display_table), | ||
| 705 | LEFT_SINGLE_QUOTATION_MARK); | ||
| 706 | if (VECTORP (dv) && ASIZE (dv) == 1 | ||
| 707 | && EQ (AREF (dv, 0), make_number ('`'))) | ||
| 708 | return GRAVE_QUOTING_STYLE; | ||
| 709 | } | ||
| 710 | return CURVE_QUOTING_STYLE; | ||
| 711 | } | ||
| 712 | |||
| 700 | DEFUN ("substitute-command-keys", Fsubstitute_command_keys, | 713 | DEFUN ("substitute-command-keys", Fsubstitute_command_keys, |
| 701 | Ssubstitute_command_keys, 1, 1, 0, | 714 | Ssubstitute_command_keys, 1, 1, 0, |
| 702 | doc: /* Substitute key descriptions for command names in STRING. | 715 | doc: /* Substitute key descriptions for command names in STRING. |
| @@ -751,20 +764,7 @@ Otherwise, return a new string. */) | |||
| 751 | name = Qnil; | 764 | name = Qnil; |
| 752 | GCPRO4 (string, tem, keymap, name); | 765 | GCPRO4 (string, tem, keymap, name); |
| 753 | 766 | ||
| 754 | enum { unicode, grave_accent, apostrophe } quote_translation = unicode; | 767 | enum text_quoting_style quoting_style = text_quoting_style (); |
| 755 | if (EQ (Vtext_quoting_style, Qgrave)) | ||
| 756 | quote_translation = grave_accent; | ||
| 757 | else if (EQ (Vtext_quoting_style, Qstraight)) | ||
| 758 | quote_translation = apostrophe; | ||
| 759 | else if (NILP (Vtext_quoting_style) | ||
| 760 | && DISP_TABLE_P (Vstandard_display_table)) | ||
| 761 | { | ||
| 762 | Lisp_Object dv = DISP_CHAR_VECTOR (XCHAR_TABLE (Vstandard_display_table), | ||
| 763 | LEFT_SINGLE_QUOTATION_MARK); | ||
| 764 | if (VECTORP (dv) && ASIZE (dv) == 1 | ||
| 765 | && EQ (AREF (dv, 0), make_number ('`'))) | ||
| 766 | quote_translation = grave_accent; | ||
| 767 | } | ||
| 768 | 768 | ||
| 769 | multibyte = STRING_MULTIBYTE (string); | 769 | multibyte = STRING_MULTIBYTE (string); |
| 770 | nchars = 0; | 770 | nchars = 0; |
| @@ -966,7 +966,7 @@ Otherwise, return a new string. */) | |||
| 966 | strp = SDATA (string) + idx; | 966 | strp = SDATA (string) + idx; |
| 967 | } | 967 | } |
| 968 | } | 968 | } |
| 969 | else if (strp[0] == '`' && quote_translation == unicode) | 969 | else if (strp[0] == '`' && quoting_style == CURVE_QUOTING_STYLE) |
| 970 | { | 970 | { |
| 971 | in_quote = true; | 971 | in_quote = true; |
| 972 | start = LSQM; | 972 | start = LSQM; |
| @@ -976,7 +976,7 @@ Otherwise, return a new string. */) | |||
| 976 | idx = strp - SDATA (string) + 1; | 976 | idx = strp - SDATA (string) + 1; |
| 977 | goto subst; | 977 | goto subst; |
| 978 | } | 978 | } |
| 979 | else if (strp[0] == '`' && quote_translation == apostrophe) | 979 | else if (strp[0] == '`' && quoting_style == STRAIGHT_QUOTING_STYLE) |
| 980 | { | 980 | { |
| 981 | *bufp++ = '\''; | 981 | *bufp++ = '\''; |
| 982 | strp++; | 982 | strp++; |
| @@ -991,9 +991,9 @@ Otherwise, return a new string. */) | |||
| 991 | } | 991 | } |
| 992 | else if (strp[0] == uLSQM0 && strp[1] == uLSQM1 | 992 | else if (strp[0] == uLSQM0 && strp[1] == uLSQM1 |
| 993 | && (strp[2] == uLSQM2 || strp[2] == uRSQM2) | 993 | && (strp[2] == uLSQM2 || strp[2] == uRSQM2) |
| 994 | && quote_translation != unicode) | 994 | && quoting_style != CURVE_QUOTING_STYLE) |
| 995 | { | 995 | { |
| 996 | *bufp++ = (strp[2] == uLSQM2 && quote_translation == grave_accent | 996 | *bufp++ = (strp[2] == uLSQM2 && quoting_style == GRAVE_QUOTING_STYLE |
| 997 | ? '`' : '\''); | 997 | ? '`' : '\''); |
| 998 | strp += 3; | 998 | strp += 3; |
| 999 | nchars++; | 999 | nchars++; |