comparison src/print.c @ 20549:ba676f083e7c

(PRINTDECLARE): Declare old_point_byte and start_point_byte. (PRINTPREPARE): For a marker, set old_point_byte and start_point_byte. Set both kinds of PT from the marker. (PRINTFINISH): For a marker, use set_marker_both. Restore both kinds of PT. (print): For strings and symbols, handle multibyte chars.
author Richard M. Stallman <rms@gnu.org>
date Thu, 01 Jan 1998 06:40:47 +0000
parents ed6e0d0465c4
children 0b00b6a96288
comparison
equal deleted inserted replaced
20548:e9733cb049d9 20549:ba676f083e7c
220 */ 220 */
221 221
222 #define PRINTDECLARE \ 222 #define PRINTDECLARE \
223 struct buffer *old = current_buffer; \ 223 struct buffer *old = current_buffer; \
224 int old_point = -1, start_point; \ 224 int old_point = -1, start_point; \
225 int old_point_byte, start_point_byte; \
225 int specpdl_count = specpdl_ptr - specpdl; \ 226 int specpdl_count = specpdl_ptr - specpdl; \
226 int free_print_buffer = 0; \ 227 int free_print_buffer = 0; \
227 Lisp_Object original 228 Lisp_Object original
228 229
229 #define PRINTPREPARE \ 230 #define PRINTPREPARE \
240 if (!(XMARKER (original)->buffer)) \ 241 if (!(XMARKER (original)->buffer)) \
241 error ("Marker does not point anywhere"); \ 242 error ("Marker does not point anywhere"); \
242 if (XMARKER (original)->buffer != current_buffer) \ 243 if (XMARKER (original)->buffer != current_buffer) \
243 set_buffer_internal (XMARKER (original)->buffer); \ 244 set_buffer_internal (XMARKER (original)->buffer); \
244 old_point = PT; \ 245 old_point = PT; \
245 SET_PT (marker_position (printcharfun)); \ 246 old_point_byte = PT_BYTE; \
247 SET_PT_BOTH (marker_position (printcharfun), \
248 marker_byte_position (printcharfun)); \
246 start_point = PT; \ 249 start_point = PT; \
250 start_point_byte = PT_BYTE; \
247 printcharfun = Qnil; \ 251 printcharfun = Qnil; \
248 } \ 252 } \
249 if (NILP (printcharfun)) \ 253 if (NILP (printcharfun)) \
250 { \ 254 { \
251 if (print_buffer != 0) \ 255 if (print_buffer != 0) \
271 xfree (print_buffer); \ 275 xfree (print_buffer); \
272 print_buffer = 0; \ 276 print_buffer = 0; \
273 } \ 277 } \
274 unbind_to (specpdl_count, Qnil); \ 278 unbind_to (specpdl_count, Qnil); \
275 if (MARKERP (original)) \ 279 if (MARKERP (original)) \
276 Fset_marker (original, make_number (PT), Qnil); \ 280 set_marker_both (original, Qnil, PT, PT_BYTE); \
277 if (old_point >= 0) \ 281 if (old_point >= 0) \
278 SET_PT (old_point + (old_point >= start_point \ 282 SET_PT_BOTH (old_point + (old_point >= start_point \
279 ? PT - start_point : 0)); \ 283 ? PT - start_point : 0), \
284 old_point_byte + (old_point_byte >= start_point_byte \
285 ? PT_BYTE - start_point_byte : 0)); \
280 if (old != current_buffer) \ 286 if (old != current_buffer) \
281 set_buffer_internal (old); \ 287 set_buffer_internal (old); \
282 if (!CONSP (Vprint_gensym)) \ 288 if (!CONSP (Vprint_gensym)) \
283 Vprint_gensym_alist = Qnil 289 Vprint_gensym_alist = Qnil
284 290
1065 else 1071 else
1066 { 1072 {
1067 register int i; 1073 register int i;
1068 register unsigned char c; 1074 register unsigned char c;
1069 struct gcpro gcpro1; 1075 struct gcpro gcpro1;
1076 int size;
1070 1077
1071 GCPRO1 (obj); 1078 GCPRO1 (obj);
1072 1079
1073 #ifdef USE_TEXT_PROPERTIES 1080 #ifdef USE_TEXT_PROPERTIES
1074 if (!NULL_INTERVAL_P (XSTRING (obj)->intervals)) 1081 if (!NULL_INTERVAL_P (XSTRING (obj)->intervals))
1077 PRINTCHAR ('('); 1084 PRINTCHAR ('(');
1078 } 1085 }
1079 #endif 1086 #endif
1080 1087
1081 PRINTCHAR ('\"'); 1088 PRINTCHAR ('\"');
1082 for (i = 0; i < XSTRING (obj)->size; i++) 1089 size = XSTRING (obj)->size;
1090 for (i = 0; i < size;)
1083 { 1091 {
1092 /* Here, we must convert each multi-byte form to the
1093 corresponding character code before handing it to PRINTCHAR. */
1094 int len;
1095 int c = STRING_CHAR_AND_LENGTH (&XSTRING (obj)->data[i],
1096 size - i, len);
1097 i += len;
1084 QUIT; 1098 QUIT;
1085 c = XSTRING (obj)->data[i]; 1099
1086 if (c == '\n' && print_escape_newlines) 1100 if (c == '\n' && print_escape_newlines)
1087 { 1101 {
1088 PRINTCHAR ('\\'); 1102 PRINTCHAR ('\\');
1089 PRINTCHAR ('n'); 1103 PRINTCHAR ('n');
1090 } 1104 }
1119 { 1133 {
1120 register int confusing; 1134 register int confusing;
1121 register unsigned char *p = XSYMBOL (obj)->name->data; 1135 register unsigned char *p = XSYMBOL (obj)->name->data;
1122 register unsigned char *end = p + XSYMBOL (obj)->name->size; 1136 register unsigned char *end = p + XSYMBOL (obj)->name->size;
1123 register unsigned char c; 1137 register unsigned char c;
1124 int i; 1138 int i, size;
1125 1139
1126 if (p != end && (*p == '-' || *p == '+')) p++; 1140 if (p != end && (*p == '-' || *p == '+')) p++;
1127 if (p == end) 1141 if (p == end)
1128 confusing = 0; 1142 confusing = 0;
1129 /* If symbol name begins with a digit, and ends with a digit, 1143 /* If symbol name begins with a digit, and ends with a digit,
1176 } 1190 }
1177 PRINTCHAR ('#'); 1191 PRINTCHAR ('#');
1178 PRINTCHAR (':'); 1192 PRINTCHAR (':');
1179 } 1193 }
1180 1194
1181 for (i = 0; i < XSYMBOL (obj)->name->size; i++) 1195 size = XSYMBOL (obj)->name->size;
1196 for (i = 0; i < size;)
1182 { 1197 {
1198 /* Here, we must convert each multi-byte form to the
1199 corresponding character code before handing it to PRINTCHAR. */
1200 int len;
1201 int c = STRING_CHAR_AND_LENGTH (&XSYMBOL (obj)->name->data[i],
1202 size - i, len);
1203 i += len;
1183 QUIT; 1204 QUIT;
1184 c = XSYMBOL (obj)->name->data[i];
1185 1205
1186 if (escapeflag) 1206 if (escapeflag)
1187 { 1207 {
1188 if (c == '\"' || c == '\\' || c == '\'' 1208 if (c == '\"' || c == '\\' || c == '\''
1189 || c == ';' || c == '#' || c == '(' || c == ')' 1209 || c == ';' || c == '#' || c == '(' || c == ')'