37e4ea2
To: vim_dev@googlegroups.com
37e4ea2
Subject: Patch 7.3.440
37e4ea2
Fcc: outbox
37e4ea2
From: Bram Moolenaar <Bram@moolenaar.net>
37e4ea2
Mime-Version: 1.0
37e4ea2
Content-Type: text/plain; charset=UTF-8
37e4ea2
Content-Transfer-Encoding: 8bit
37e4ea2
------------
37e4ea2
37e4ea2
Patch 7.3.440
37e4ea2
Problem:    Vim does not support UTF8_STRING for the X selection.
37e4ea2
Solution:   Add UTF8_STRING atom support. (Alex Efros) Use it only when
37e4ea2
            'encoding' is set to Unicode.
37e4ea2
Files:      src/ui.c
37e4ea2
37e4ea2
37e4ea2
*** ../vim-7.3.439/src/ui.c	2012-02-04 21:57:44.000000000 +0100
37e4ea2
--- src/ui.c	2012-02-12 01:28:30.000000000 +0100
37e4ea2
***************
37e4ea2
*** 1917,1922 ****
37e4ea2
--- 1917,1923 ----
37e4ea2
  static Atom	vim_atom;	/* Vim's own special selection format */
37e4ea2
  #ifdef FEAT_MBYTE
37e4ea2
  static Atom	vimenc_atom;	/* Vim's extended selection format */
37e4ea2
+ static Atom	utf8_atom;
37e4ea2
  #endif
37e4ea2
  static Atom	compound_text_atom;
37e4ea2
  static Atom	text_atom;
37e4ea2
***************
37e4ea2
*** 1930,1935 ****
37e4ea2
--- 1931,1937 ----
37e4ea2
      vim_atom	       = XInternAtom(dpy, VIM_ATOM_NAME,   False);
37e4ea2
  #ifdef FEAT_MBYTE
37e4ea2
      vimenc_atom	       = XInternAtom(dpy, VIMENC_ATOM_NAME,False);
37e4ea2
+     utf8_atom	       = XInternAtom(dpy, "UTF8_STRING",   False);
37e4ea2
  #endif
37e4ea2
      compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False);
37e4ea2
      text_atom	       = XInternAtom(dpy, "TEXT",	   False);
37e4ea2
***************
37e4ea2
*** 2074,2080 ****
37e4ea2
      }
37e4ea2
  #endif
37e4ea2
  
37e4ea2
!     else if (*type == compound_text_atom || (
37e4ea2
  #ifdef FEAT_MBYTE
37e4ea2
  		enc_dbcs != 0 &&
37e4ea2
  #endif
37e4ea2
--- 2076,2086 ----
37e4ea2
      }
37e4ea2
  #endif
37e4ea2
  
37e4ea2
!     else if (*type == compound_text_atom
37e4ea2
! #ifdef FEAT_MBYTE
37e4ea2
! 	    || *type == utf8_atom
37e4ea2
! #endif
37e4ea2
! 	    || (
37e4ea2
  #ifdef FEAT_MBYTE
37e4ea2
  		enc_dbcs != 0 &&
37e4ea2
  #endif
37e4ea2
***************
37e4ea2
*** 2128,2134 ****
37e4ea2
  #else
37e4ea2
  	    1
37e4ea2
  #endif
37e4ea2
! 	    ; i < 5; i++)
37e4ea2
      {
37e4ea2
  	switch (i)
37e4ea2
  	{
37e4ea2
--- 2134,2140 ----
37e4ea2
  #else
37e4ea2
  	    1
37e4ea2
  #endif
37e4ea2
! 	    ; i < 6; i++)
37e4ea2
      {
37e4ea2
  	switch (i)
37e4ea2
  	{
37e4ea2
***************
37e4ea2
*** 2136,2145 ****
37e4ea2
  	    case 0:  type = vimenc_atom;	break;
37e4ea2
  #endif
37e4ea2
  	    case 1:  type = vim_atom;		break;
37e4ea2
! 	    case 2:  type = compound_text_atom; break;
37e4ea2
! 	    case 3:  type = text_atom;		break;
37e4ea2
  	    default: type = XA_STRING;
37e4ea2
  	}
37e4ea2
  	success = MAYBE;
37e4ea2
  	XtGetSelectionValue(myShell, cbd->sel_atom, type,
37e4ea2
  	    clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime);
37e4ea2
--- 2142,2159 ----
37e4ea2
  	    case 0:  type = vimenc_atom;	break;
37e4ea2
  #endif
37e4ea2
  	    case 1:  type = vim_atom;		break;
37e4ea2
! #ifdef FEAT_MBYTE
37e4ea2
! 	    case 2:  type = utf8_atom;		break;
37e4ea2
! #endif
37e4ea2
! 	    case 3:  type = compound_text_atom; break;
37e4ea2
! 	    case 4:  type = text_atom;		break;
37e4ea2
  	    default: type = XA_STRING;
37e4ea2
  	}
37e4ea2
+ #ifdef FEAT_MBYTE
37e4ea2
+ 	if (type == utf8_atom && !enc_utf8)
37e4ea2
+ 	    /* Only request utf-8 when 'encoding' is utf8. */
37e4ea2
+ 	    continue;
37e4ea2
+ #endif
37e4ea2
  	success = MAYBE;
37e4ea2
  	XtGetSelectionValue(myShell, cbd->sel_atom, type,
37e4ea2
  	    clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime);
37e4ea2
***************
37e4ea2
*** 2230,2247 ****
37e4ea2
      {
37e4ea2
  	Atom *array;
37e4ea2
  
37e4ea2
! 	if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 6))) == NULL)
37e4ea2
  	    return False;
37e4ea2
  	*value = (XtPointer)array;
37e4ea2
  	i = 0;
37e4ea2
- 	array[i++] = XA_STRING;
37e4ea2
  	array[i++] = targets_atom;
37e4ea2
  #ifdef FEAT_MBYTE
37e4ea2
  	array[i++] = vimenc_atom;
37e4ea2
  #endif
37e4ea2
  	array[i++] = vim_atom;
37e4ea2
  	array[i++] = text_atom;
37e4ea2
  	array[i++] = compound_text_atom;
37e4ea2
  	*type = XA_ATOM;
37e4ea2
  	/* This used to be: *format = sizeof(Atom) * 8; but that caused
37e4ea2
  	 * crashes on 64 bit machines. (Peter Derr) */
37e4ea2
--- 2244,2266 ----
37e4ea2
      {
37e4ea2
  	Atom *array;
37e4ea2
  
37e4ea2
! 	if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 7))) == NULL)
37e4ea2
  	    return False;
37e4ea2
  	*value = (XtPointer)array;
37e4ea2
  	i = 0;
37e4ea2
  	array[i++] = targets_atom;
37e4ea2
  #ifdef FEAT_MBYTE
37e4ea2
  	array[i++] = vimenc_atom;
37e4ea2
  #endif
37e4ea2
  	array[i++] = vim_atom;
37e4ea2
+ #ifdef FEAT_MBYTE
37e4ea2
+ 	if (enc_utf8)
37e4ea2
+ 	    array[i++] = utf8_atom;
37e4ea2
+ #endif
37e4ea2
+ 	array[i++] = XA_STRING;
37e4ea2
  	array[i++] = text_atom;
37e4ea2
  	array[i++] = compound_text_atom;
37e4ea2
+ 
37e4ea2
  	*type = XA_ATOM;
37e4ea2
  	/* This used to be: *format = sizeof(Atom) * 8; but that caused
37e4ea2
  	 * crashes on 64 bit machines. (Peter Derr) */
37e4ea2
***************
37e4ea2
*** 2253,2258 ****
37e4ea2
--- 2272,2278 ----
37e4ea2
      if (       *target != XA_STRING
37e4ea2
  #ifdef FEAT_MBYTE
37e4ea2
  	    && *target != vimenc_atom
37e4ea2
+ 	    && *target != utf8_atom
37e4ea2
  #endif
37e4ea2
  	    && *target != vim_atom
37e4ea2
  	    && *target != text_atom
37e4ea2
***************
37e4ea2
*** 2282,2294 ****
37e4ea2
  	return False;
37e4ea2
      }
37e4ea2
  
37e4ea2
!     if (*target == XA_STRING)
37e4ea2
      {
37e4ea2
  	mch_memmove(result, string, (size_t)(*length));
37e4ea2
! 	*type = XA_STRING;
37e4ea2
      }
37e4ea2
!     else if (*target == compound_text_atom
37e4ea2
! 	    || *target == text_atom)
37e4ea2
      {
37e4ea2
  	XTextProperty	text_prop;
37e4ea2
  	char		*string_nt = (char *)alloc((unsigned)*length + 1);
37e4ea2
--- 2302,2317 ----
37e4ea2
  	return False;
37e4ea2
      }
37e4ea2
  
37e4ea2
!     if (*target == XA_STRING
37e4ea2
! #ifdef FEAT_MBYTE
37e4ea2
! 	    || (*target == utf8_atom && enc_utf8)
37e4ea2
! #endif
37e4ea2
! 	    )
37e4ea2
      {
37e4ea2
  	mch_memmove(result, string, (size_t)(*length));
37e4ea2
! 	*type = *target;
37e4ea2
      }
37e4ea2
!     else if (*target == compound_text_atom || *target == text_atom)
37e4ea2
      {
37e4ea2
  	XTextProperty	text_prop;
37e4ea2
  	char		*string_nt = (char *)alloc((unsigned)*length + 1);
37e4ea2
*** ../vim-7.3.439/src/version.c	2012-02-12 00:31:47.000000000 +0100
37e4ea2
--- src/version.c	2012-02-12 01:34:22.000000000 +0100
37e4ea2
***************
37e4ea2
*** 716,717 ****
37e4ea2
--- 716,719 ----
37e4ea2
  {   /* Add new patch number below this line */
37e4ea2
+ /**/
37e4ea2
+     440,
37e4ea2
  /**/
37e4ea2
37e4ea2
-- 
37e4ea2
hundred-and-one symptoms of being an internet addict:
37e4ea2
42. Your virtual girlfriend finds a new net sweetheart with a larger bandwidth.
37e4ea2
37e4ea2
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
37e4ea2
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
37e4ea2
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
37e4ea2
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///