Don't include cahrset.h, coding.h, composite.h.
[bpt/emacs.git] / src / xselect.c
index 5fd2c86..21b7ecf 100644 (file)
@@ -29,10 +29,7 @@ Boston, MA 02111-1307, USA.  */
 #include "frame.h"     /* Need this to get the X window of selected_frame */
 #include "blockinput.h"
 #include "buffer.h"
-#include "charset.h"
-#include "coding.h"
 #include "process.h"
-#include "composite.h"
 
 struct prop_location;
 
@@ -114,6 +111,8 @@ static Lisp_Object Vselection_coding_system;
 /* Coding system for the next communicating with other X clients.  */
 static Lisp_Object Vnext_selection_coding_system;
 
+static Lisp_Object Qforeign_selection;
+
 /* If this is a smaller number than the max-request-size of the display,
    emacs will use INCR selection transfer when the selection is larger
    than this.  The max-request-size is usually around 64k, so if you want
@@ -1605,74 +1604,21 @@ selection_data_to_lisp_data (display, data, size, type, format)
   /* Convert any 8-bit data to a string, for compactness.  */
   else if (format == 8)
     {
-      Lisp_Object str;
-      int require_encoding = 0;
-
-      if (
-#if 1
-         1
-#else
-         ! NILP (buffer_defaults.enable_multibyte_characters)
-#endif
-         )
-       {
-         /* If TYPE is `TEXT' or `COMPOUND_TEXT', we should decode
-            DATA to Emacs internal format because DATA may be encoded
-            in compound text format.  In addtion, if TYPE is `STRING'
-            and DATA contains any 8-bit Latin-1 code, we should also
-            decode it.  */
-         if (type == dpyinfo->Xatom_TEXT
-             || type == dpyinfo->Xatom_COMPOUND_TEXT)
-           require_encoding = 1;
-         else if (type == XA_STRING)
-           {
-             int i;
-             for (i = 0; i < size; i++)
-               {
-                 if (data[i] >= 0x80)
-                   {
-                     require_encoding = 1;
-                     break;
-                   }
-               }
-           }
-       }
-      if (!require_encoding)
-       {
-         str = make_unibyte_string ((char *) data, size);
-         Vlast_coding_system_used = Qraw_text;
-       }
+      Lisp_Object str, lispy_type;
+
+      str = make_unibyte_string ((char *) data, size);
+      /* Indicate that this string is from foreign selection by a text
+        property `foreign-selection' so that the caller of
+        x-get-selection-internal (usually x-get-selection) can know
+        that the string must be decode.  */
+      if (type == dpyinfo->Xatom_COMPOUND_TEXT)
+       lispy_type = QCOMPOUND_TEXT;
+      else if (type == dpyinfo->Xatom_UTF8_STRING)
+       lispy_type = QUTF8_STRING;
       else
-       {
-         int bufsize;
-         unsigned char *buf;
-         struct coding_system coding;
-
-         if (NILP (Vnext_selection_coding_system))
-           Vnext_selection_coding_system = Vselection_coding_system;
-         setup_coding_system
-           (Fcheck_coding_system(Vnext_selection_coding_system), &coding);
-         coding.src_multibyte = 0;
-         coding.dst_multibyte = 1;
-         Vnext_selection_coding_system = Qnil;
-          coding.mode |= CODING_MODE_LAST_BLOCK;
-         /* We explicitely disable composition handling because
-            selection data should not contain any composition
-            sequence.  */
-         coding.composing = COMPOSITION_DISABLED;
-         bufsize = decoding_buffer_size (&coding, size);
-         buf = (unsigned char *) xmalloc (bufsize);
-         decode_coding (&coding, data, buf, size, bufsize);
-         str = make_string_from_bytes ((char *) buf,
-                                       coding.produced_char, coding.produced);
-         xfree (buf);
-
-         if (SYMBOLP (coding.post_read_conversion)
-             && !NILP (Ffboundp (coding.post_read_conversion)))
-           str = run_pre_post_conversion_on_str (str, &coding, 0);
-         Vlast_coding_system_used = coding.symbol;
-       }
-      compose_chars_in_text (0, SCHARS (str), str);
+       lispy_type = QSTRING;
+      Fput_text_property (make_number (0), make_number (size),
+                         Qforeign_selection, lispy_type, str);
       return str;
     }
   /* Convert a single atom to a Lisp_Symbol.  Convert a set of atoms to
@@ -2451,4 +2397,6 @@ A value of 0 means wait as long as necessary.  This is initialized from the
   QCUT_BUFFER7 = intern ("CUT_BUFFER7"); staticpro (&QCUT_BUFFER7);
 #endif
 
+  Qforeign_selection = intern ("foreign-selection");
+  staticpro (&Qforeign_selection);
 }