comparison src/print.c @ 89717:2e9328140e82

Include charset.h. (Vprint_charset_text_property): New variable. (Qdefault): Extern it. (PRINT_STRING_NON_CHARSET_FOUND) (PRINT_STRING_UNSAFE_CHARSET_FOUND): New macros. (print_check_string_result): New variable. (print_check_string_charset_prop): New function. (print_prune_charset_plist): New variable. (print_prune_string_charset): New function. (print_object): Call print_prune_string_charset if Vprint_charset_text_property is not t. (print_interval): Print nothing if itnerval->plist is nil. (syms_of_print): Declare Vprint_charset_text_property as a lisp variable. Init and staticpro print_prune_charset_plist.
author Kenichi Handa <handa@m17n.org>
date Sun, 18 Jan 2004 23:27:07 +0000
parents 1961cc2af44d
children 75a2373c03cc
comparison
equal deleted inserted replaced
89716:ae8be7325b11 89717:2e9328140e82
23 #include <config.h> 23 #include <config.h>
24 #include <stdio.h> 24 #include <stdio.h>
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"
31 #include "process.h" 32 #include "process.h"
32 #include "dispextern.h" 33 #include "dispextern.h"
1304 Lisp_Object arg; 1305 Lisp_Object arg;
1305 { 1306 {
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;
1312 register Lisp_Object printcharfun; 1397 register Lisp_Object printcharfun;
1313 int escapeflag; 1398 int escapeflag;
1410 cannot be taken as part of a hex character escape. */ 1495 cannot be taken as part of a hex character escape. */
1411 int need_nonhex = 0; 1496 int need_nonhex = 0;
1412 int multibyte = STRING_MULTIBYTE (obj); 1497 int multibyte = STRING_MULTIBYTE (obj);
1413 1498
1414 GCPRO1 (obj); 1499 GCPRO1 (obj);
1500
1501 if (! EQ (Vprint_charset_text_property, Qt))
1502 obj = print_prune_string_charset (obj);
1415 1503
1416 if (!NULL_INTERVAL_P (STRING_INTERVALS (obj))) 1504 if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
1417 { 1505 {
1418 PRINTCHAR ('#'); 1506 PRINTCHAR ('#');
1419 PRINTCHAR ('('); 1507 PRINTCHAR ('(');
2032 void 2120 void
2033 print_interval (interval, printcharfun) 2121 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 (' ');
2040 print_object (make_number (interval->position + LENGTH (interval)), 2130 print_object (make_number (interval->position + LENGTH (interval)),
2041 printcharfun, 1); 2131 printcharfun, 1);
2154 done. If all elements of `print-number-table' are nil, it means that 2244 done. If all elements of `print-number-table' are nil, it means that
2155 the printing done so far has not found any shared structure or objects 2245 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
2162 defsubr (&Sprin1); 2265 defsubr (&Sprin1);
2163 defsubr (&Sprin1_to_string); 2266 defsubr (&Sprin1_to_string);
2178 staticpro (&Qprint_escape_multibyte); 2281 staticpro (&Qprint_escape_multibyte);
2179 2282
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 }