diff options
Diffstat (limited to 'src/doc.c')
| -rw-r--r-- | src/doc.c | 62 |
1 files changed, 62 insertions, 0 deletions
| @@ -1028,6 +1028,67 @@ Otherwise, return a new string. */) | |||
| 1028 | xfree (buf); | 1028 | xfree (buf); |
| 1029 | RETURN_UNGCPRO (tem); | 1029 | RETURN_UNGCPRO (tem); |
| 1030 | } | 1030 | } |
| 1031 | |||
| 1032 | DEFUN ("internal--text-restyle", Finternal__text_restyle, | ||
| 1033 | Sinternal__text_restyle, 1, 1, 0, | ||
| 1034 | doc: /* Return STRING, possibly substituting quote characters. | ||
| 1035 | |||
| 1036 | In the result, replace each curved single quote (\\=‘ and \\=’) by | ||
| 1037 | left and right quote characters as specified by ‘text-quoting-style’. | ||
| 1038 | |||
| 1039 | Return the original STRING in the common case where no changes are needed. | ||
| 1040 | Otherwise, return a new string. */) | ||
| 1041 | (Lisp_Object string) | ||
| 1042 | { | ||
| 1043 | bool changed = false; | ||
| 1044 | |||
| 1045 | CHECK_STRING (string); | ||
| 1046 | if (! STRING_MULTIBYTE (string)) | ||
| 1047 | return string; | ||
| 1048 | |||
| 1049 | enum text_quoting_style quoting_style = text_quoting_style (); | ||
| 1050 | if (quoting_style == CURVE_QUOTING_STYLE) | ||
| 1051 | return string; | ||
| 1052 | |||
| 1053 | ptrdiff_t bsize = SBYTES (string); | ||
| 1054 | unsigned char const *strp = SDATA (string); | ||
| 1055 | unsigned char const *strlim = strp + bsize; | ||
| 1056 | USE_SAFE_ALLOCA; | ||
| 1057 | char *buf = SAFE_ALLOCA (bsize); | ||
| 1058 | char *bufp = buf; | ||
| 1059 | ptrdiff_t nchars = 0; | ||
| 1060 | |||
| 1061 | while (strp < strlim) | ||
| 1062 | { | ||
| 1063 | unsigned char const *cp = strp; | ||
| 1064 | switch (STRING_CHAR_ADVANCE (strp)) | ||
| 1065 | { | ||
| 1066 | case LEFT_SINGLE_QUOTATION_MARK: | ||
| 1067 | *bufp++ = quoting_style == GRAVE_QUOTING_STYLE ? '`': '\''; | ||
| 1068 | changed = true; | ||
| 1069 | break; | ||
| 1070 | |||
| 1071 | case RIGHT_SINGLE_QUOTATION_MARK: | ||
| 1072 | *bufp++ = '\''; | ||
| 1073 | changed = true; | ||
| 1074 | break; | ||
| 1075 | |||
| 1076 | default: | ||
| 1077 | do | ||
| 1078 | *bufp++ = *cp++; | ||
| 1079 | while (cp != strp); | ||
| 1080 | |||
| 1081 | break; | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | nchars++; | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | Lisp_Object result | ||
| 1088 | = changed ? make_string_from_bytes (buf, nchars, bufp - buf) : string; | ||
| 1089 | SAFE_FREE (); | ||
| 1090 | return result; | ||
| 1091 | } | ||
| 1031 | 1092 | ||
| 1032 | void | 1093 | void |
| 1033 | syms_of_doc (void) | 1094 | syms_of_doc (void) |
| @@ -1061,4 +1122,5 @@ displayable, and like ‘grave’ otherwise. */); | |||
| 1061 | defsubr (&Sdocumentation_property); | 1122 | defsubr (&Sdocumentation_property); |
| 1062 | defsubr (&Ssnarf_documentation); | 1123 | defsubr (&Ssnarf_documentation); |
| 1063 | defsubr (&Ssubstitute_command_keys); | 1124 | defsubr (&Ssubstitute_command_keys); |
| 1125 | defsubr (&Sinternal__text_restyle); | ||
| 1064 | } | 1126 | } |