comparison src/xselect.c @ 51598:8e404f2a6715

Don't include cahrset.h, coding.h, composite.h. (Qforeign_selection): New variable. (syms_of_xselect): Intern and static it. (selection_data_to_lisp_data): Return a unibyte string made from data with `foreign-selection' text property.
author Kenichi Handa <handa@m17n.org>
date Tue, 17 Jun 2003 10:51:11 +0000
parents d89a8e99c73b
children 695cf19ef79e
comparison
equal deleted inserted replaced
51597:9b14210f4740 51598:8e404f2a6715
27 #include "xterm.h" /* for all of the X includes */ 27 #include "xterm.h" /* for all of the X includes */
28 #include "dispextern.h" /* frame.h seems to want this */ 28 #include "dispextern.h" /* frame.h seems to want this */
29 #include "frame.h" /* Need this to get the X window of selected_frame */ 29 #include "frame.h" /* Need this to get the X window of selected_frame */
30 #include "blockinput.h" 30 #include "blockinput.h"
31 #include "buffer.h" 31 #include "buffer.h"
32 #include "charset.h"
33 #include "coding.h"
34 #include "process.h" 32 #include "process.h"
35 #include "composite.h"
36 33
37 struct prop_location; 34 struct prop_location;
38 35
39 static Lisp_Object x_atom_to_symbol P_ ((Display *dpy, Atom atom)); 36 static Lisp_Object x_atom_to_symbol P_ ((Display *dpy, Atom atom));
40 static Atom symbol_to_x_atom P_ ((struct x_display_info *, Display *, 37 static Atom symbol_to_x_atom P_ ((struct x_display_info *, Display *,
112 static Lisp_Object Vselection_coding_system; 109 static Lisp_Object Vselection_coding_system;
113 110
114 /* Coding system for the next communicating with other X clients. */ 111 /* Coding system for the next communicating with other X clients. */
115 static Lisp_Object Vnext_selection_coding_system; 112 static Lisp_Object Vnext_selection_coding_system;
116 113
114 static Lisp_Object Qforeign_selection;
115
117 /* If this is a smaller number than the max-request-size of the display, 116 /* If this is a smaller number than the max-request-size of the display,
118 emacs will use INCR selection transfer when the selection is larger 117 emacs will use INCR selection transfer when the selection is larger
119 than this. The max-request-size is usually around 64k, so if you want 118 than this. The max-request-size is usually around 64k, so if you want
120 emacs to use incremental selection transfers when the selection is 119 emacs to use incremental selection transfers when the selection is
121 smaller than that, set this. I added this mostly for debugging the 120 smaller than that, set this. I added this mostly for debugging the
1603 return QNULL; 1602 return QNULL;
1604 1603
1605 /* Convert any 8-bit data to a string, for compactness. */ 1604 /* Convert any 8-bit data to a string, for compactness. */
1606 else if (format == 8) 1605 else if (format == 8)
1607 { 1606 {
1608 Lisp_Object str; 1607 Lisp_Object str, lispy_type;
1609 int require_encoding = 0; 1608
1610 1609 str = make_unibyte_string ((char *) data, size);
1611 if ( 1610 /* Indicate that this string is from foreign selection by a text
1612 #if 1 1611 property `foreign-selection' so that the caller of
1613 1 1612 x-get-selection-internal (usually x-get-selection) can know
1614 #else 1613 that the string must be decode. */
1615 ! NILP (buffer_defaults.enable_multibyte_characters) 1614 if (type == dpyinfo->Xatom_COMPOUND_TEXT)
1616 #endif 1615 lispy_type = QCOMPOUND_TEXT;
1617 ) 1616 else if (type == dpyinfo->Xatom_UTF8_STRING)
1618 { 1617 lispy_type = QUTF8_STRING;
1619 /* If TYPE is `TEXT' or `COMPOUND_TEXT', we should decode
1620 DATA to Emacs internal format because DATA may be encoded
1621 in compound text format. In addtion, if TYPE is `STRING'
1622 and DATA contains any 8-bit Latin-1 code, we should also
1623 decode it. */
1624 if (type == dpyinfo->Xatom_TEXT
1625 || type == dpyinfo->Xatom_COMPOUND_TEXT)
1626 require_encoding = 1;
1627 else if (type == XA_STRING)
1628 {
1629 int i;
1630 for (i = 0; i < size; i++)
1631 {
1632 if (data[i] >= 0x80)
1633 {
1634 require_encoding = 1;
1635 break;
1636 }
1637 }
1638 }
1639 }
1640 if (!require_encoding)
1641 {
1642 str = make_unibyte_string ((char *) data, size);
1643 Vlast_coding_system_used = Qraw_text;
1644 }
1645 else 1618 else
1646 { 1619 lispy_type = QSTRING;
1647 int bufsize; 1620 Fput_text_property (make_number (0), make_number (size),
1648 unsigned char *buf; 1621 Qforeign_selection, lispy_type, str);
1649 struct coding_system coding;
1650
1651 if (NILP (Vnext_selection_coding_system))
1652 Vnext_selection_coding_system = Vselection_coding_system;
1653 setup_coding_system
1654 (Fcheck_coding_system(Vnext_selection_coding_system), &coding);
1655 coding.src_multibyte = 0;
1656 coding.dst_multibyte = 1;
1657 Vnext_selection_coding_system = Qnil;
1658 coding.mode |= CODING_MODE_LAST_BLOCK;
1659 /* We explicitely disable composition handling because
1660 selection data should not contain any composition
1661 sequence. */
1662 coding.composing = COMPOSITION_DISABLED;
1663 bufsize = decoding_buffer_size (&coding, size);
1664 buf = (unsigned char *) xmalloc (bufsize);
1665 decode_coding (&coding, data, buf, size, bufsize);
1666 str = make_string_from_bytes ((char *) buf,
1667 coding.produced_char, coding.produced);
1668 xfree (buf);
1669
1670 if (SYMBOLP (coding.post_read_conversion)
1671 && !NILP (Ffboundp (coding.post_read_conversion)))
1672 str = run_pre_post_conversion_on_str (str, &coding, 0);
1673 Vlast_coding_system_used = coding.symbol;
1674 }
1675 compose_chars_in_text (0, SCHARS (str), str);
1676 return str; 1622 return str;
1677 } 1623 }
1678 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to 1624 /* Convert a single atom to a Lisp_Symbol. Convert a set of atoms to
1679 a vector of symbols. 1625 a vector of symbols.
1680 */ 1626 */
2449 QCUT_BUFFER5 = intern ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5); 2395 QCUT_BUFFER5 = intern ("CUT_BUFFER5"); staticpro (&QCUT_BUFFER5);
2450 QCUT_BUFFER6 = intern ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6); 2396 QCUT_BUFFER6 = intern ("CUT_BUFFER6"); staticpro (&QCUT_BUFFER6);
2451 QCUT_BUFFER7 = intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7); 2397 QCUT_BUFFER7 = intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7);
2452 #endif 2398 #endif
2453 2399
2454 } 2400 Qforeign_selection = intern ("foreign-selection");
2401 staticpro (&Qforeign_selection);
2402 }