diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/print.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/print.c b/src/print.c index 1ded6c56674..229004f7a57 100644 --- a/src/print.c +++ b/src/print.c | |||
| @@ -25,6 +25,7 @@ Boston, MA 02111-1307, USA. */ | |||
| 25 | #include "lisp.h" | 25 | #include "lisp.h" |
| 26 | #include "buffer.h" | 26 | #include "buffer.h" |
| 27 | #include "character.h" | 27 | #include "character.h" |
| 28 | #include "charset.h" | ||
| 28 | #include "keyboard.h" | 29 | #include "keyboard.h" |
| 29 | #include "frame.h" | 30 | #include "frame.h" |
| 30 | #include "window.h" | 31 | #include "window.h" |
| @@ -1306,6 +1307,90 @@ print_preprocess_string (interval, arg) | |||
| 1306 | print_preprocess (interval->plist); | 1307 | print_preprocess (interval->plist); |
| 1307 | } | 1308 | } |
| 1308 | 1309 | ||
| 1310 | /* A flag to control printing of `charset' text property. | ||
| 1311 | The default value is Qdefault. */ | ||
| 1312 | Lisp_Object Vprint_charset_text_property; | ||
| 1313 | extern Lisp_Object Qdefault; | ||
| 1314 | |||
| 1315 | static void print_check_string_charset_prop (); | ||
| 1316 | |||
| 1317 | #define PRINT_STRING_NON_CHARSET_FOUND 1 | ||
| 1318 | #define PRINT_STRING_UNSAFE_CHARSET_FOUND 2 | ||
| 1319 | |||
| 1320 | /* Bitwize or of the abobe macros. */ | ||
| 1321 | static int print_check_string_result; | ||
| 1322 | |||
| 1323 | static void | ||
| 1324 | print_check_string_charset_prop (interval, string) | ||
| 1325 | INTERVAL interval; | ||
| 1326 | Lisp_Object string; | ||
| 1327 | { | ||
| 1328 | Lisp_Object val; | ||
| 1329 | |||
| 1330 | if (NILP (interval->plist) | ||
| 1331 | || (print_check_string_result == (PRINT_STRING_NON_CHARSET_FOUND | ||
| 1332 | | PRINT_STRING_UNSAFE_CHARSET_FOUND))) | ||
| 1333 | return; | ||
| 1334 | for (val = interval->plist; CONSP (val) && ! EQ (XCAR (val), Qcharset); | ||
| 1335 | val = XCDR (XCDR (val))); | ||
| 1336 | if (! CONSP (val)) | ||
| 1337 | { | ||
| 1338 | print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND; | ||
| 1339 | return; | ||
| 1340 | } | ||
| 1341 | if (! (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND)) | ||
| 1342 | { | ||
| 1343 | if (! EQ (val, interval->plist) | ||
| 1344 | || CONSP (XCDR (XCDR (val)))) | ||
| 1345 | print_check_string_result |= PRINT_STRING_NON_CHARSET_FOUND; | ||
| 1346 | } | ||
| 1347 | if (NILP (Vprint_charset_text_property) | ||
| 1348 | || ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND)) | ||
| 1349 | { | ||
| 1350 | int i, c; | ||
| 1351 | int charpos = interval->position; | ||
| 1352 | int bytepos = string_char_to_byte (string, charpos); | ||
| 1353 | Lisp_Object charset; | ||
| 1354 | |||
| 1355 | charset = XCAR (XCDR (val)); | ||
| 1356 | for (i = 0; i < LENGTH (interval); i++) | ||
| 1357 | { | ||
| 1358 | FETCH_STRING_CHAR_ADVANCE (c, string, charpos, bytepos); | ||
| 1359 | if (! EQ (CHARSET_NAME (CHAR_CHARSET (c)), charset)) | ||
| 1360 | { | ||
| 1361 | print_check_string_result |= PRINT_STRING_UNSAFE_CHARSET_FOUND; | ||
| 1362 | break; | ||
| 1363 | } | ||
| 1364 | } | ||
| 1365 | } | ||
| 1366 | } | ||
| 1367 | |||
| 1368 | /* The value is (charset . nil). */ | ||
| 1369 | static Lisp_Object print_prune_charset_plist; | ||
| 1370 | |||
| 1371 | static Lisp_Object | ||
| 1372 | print_prune_string_charset (string) | ||
| 1373 | Lisp_Object string; | ||
| 1374 | { | ||
| 1375 | print_check_string_result = 0; | ||
| 1376 | traverse_intervals (STRING_INTERVALS (string), 0, | ||
| 1377 | print_check_string_charset_prop, string); | ||
| 1378 | if (! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND)) | ||
| 1379 | { | ||
| 1380 | string = Fcopy_sequence (string); | ||
| 1381 | if (print_check_string_result & PRINT_STRING_NON_CHARSET_FOUND) | ||
| 1382 | { | ||
| 1383 | if (NILP (print_prune_charset_plist)) | ||
| 1384 | print_prune_charset_plist = Fcons (Qcharset, Qnil); | ||
| 1385 | Fremove_text_properties (0, SCHARS (string), | ||
| 1386 | print_prune_charset_plist, string); | ||
| 1387 | } | ||
| 1388 | else | ||
| 1389 | Fset_text_properties (0, SCHARS (string), Qnil, string); | ||
| 1390 | } | ||
| 1391 | return string; | ||
| 1392 | } | ||
| 1393 | |||
| 1309 | static void | 1394 | static void |
| 1310 | print_object (obj, printcharfun, escapeflag) | 1395 | print_object (obj, printcharfun, escapeflag) |
| 1311 | Lisp_Object obj; | 1396 | Lisp_Object obj; |
| @@ -1413,6 +1498,9 @@ print_object (obj, printcharfun, escapeflag) | |||
| 1413 | 1498 | ||
| 1414 | GCPRO1 (obj); | 1499 | GCPRO1 (obj); |
| 1415 | 1500 | ||
| 1501 | if (! EQ (Vprint_charset_text_property, Qt)) | ||
| 1502 | obj = print_prune_string_charset (obj); | ||
| 1503 | |||
| 1416 | if (!NULL_INTERVAL_P (STRING_INTERVALS (obj))) | 1504 | if (!NULL_INTERVAL_P (STRING_INTERVALS (obj))) |
| 1417 | { | 1505 | { |
| 1418 | PRINTCHAR ('#'); | 1506 | PRINTCHAR ('#'); |
| @@ -2034,6 +2122,8 @@ print_interval (interval, printcharfun) | |||
| 2034 | INTERVAL interval; | 2122 | INTERVAL interval; |
| 2035 | Lisp_Object printcharfun; | 2123 | Lisp_Object printcharfun; |
| 2036 | { | 2124 | { |
| 2125 | if (NILP (interval->plist)) | ||
| 2126 | return; | ||
| 2037 | PRINTCHAR (' '); | 2127 | PRINTCHAR (' '); |
| 2038 | print_object (make_number (interval->position), printcharfun, 1); | 2128 | print_object (make_number (interval->position), printcharfun, 1); |
| 2039 | PRINTCHAR (' '); | 2129 | PRINTCHAR (' '); |
| @@ -2156,6 +2246,19 @@ the printing done so far has not found any shared structure or objects | |||
| 2156 | that need to be recorded in the table. */); | 2246 | that need to be recorded in the table. */); |
| 2157 | Vprint_number_table = Qnil; | 2247 | Vprint_number_table = Qnil; |
| 2158 | 2248 | ||
| 2249 | DEFVAR_LISP ("print-charset-text-property", &Vprint_charset_text_property, | ||
| 2250 | doc: /* A flag to control printing of `charset' text property on printing a string. | ||
| 2251 | The value must be nil, t, or `default'. | ||
| 2252 | |||
| 2253 | If the value is nil, don't print the text property `charset'. | ||
| 2254 | |||
| 2255 | If the value is t, always print the text property `charset'. | ||
| 2256 | |||
| 2257 | If the value is `default', print the text property `charset' only when | ||
| 2258 | the value is different from what is guessed in the current charset | ||
| 2259 | priorities. */); | ||
| 2260 | Vprint_charset_text_property = Qdefault; | ||
| 2261 | |||
| 2159 | /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */ | 2262 | /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */ |
| 2160 | staticpro (&Vprin1_to_string_buffer); | 2263 | staticpro (&Vprin1_to_string_buffer); |
| 2161 | 2264 | ||
| @@ -2180,5 +2283,8 @@ that need to be recorded in the table. */); | |||
| 2180 | Qprint_escape_nonascii = intern ("print-escape-nonascii"); | 2283 | Qprint_escape_nonascii = intern ("print-escape-nonascii"); |
| 2181 | staticpro (&Qprint_escape_nonascii); | 2284 | staticpro (&Qprint_escape_nonascii); |
| 2182 | 2285 | ||
| 2286 | print_prune_charset_plist = Qnil; | ||
| 2287 | staticpro (&print_prune_charset_plist); | ||
| 2288 | |||
| 2183 | defsubr (&Swith_output_to_temp_buffer); | 2289 | defsubr (&Swith_output_to_temp_buffer); |
| 2184 | } | 2290 | } |