Karsten Hopp 81c285
To: vim-dev@vim.org
Karsten Hopp 81c285
Subject: Patch 7.2.221
Karsten Hopp 81c285
Fcc: outbox
Karsten Hopp 81c285
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 81c285
Mime-Version: 1.0
Karsten Hopp 81c285
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 81c285
Content-Transfer-Encoding: 8bit
Karsten Hopp 81c285
------------
Karsten Hopp 81c285
Karsten Hopp 81c285
Patch 7.2.221
Karsten Hopp 81c285
Problem:    X cut_buffer0 text is used as-is, it may be in the wrong encoding.
Karsten Hopp 81c285
Solution:   Convert between 'enc' and latin1. (James Vega)
Karsten Hopp 81c285
Files:	    src/gui_gtk_x11.c, src/message.c, src/ops.c, src/proto/ui.pro,
Karsten Hopp 81c285
	    src/ui.c
Karsten Hopp 81c285
Karsten Hopp 81c285
Karsten Hopp 81c285
*** ../vim-7.2.220/src/gui_gtk_x11.c	2009-06-16 15:23:07.000000000 +0200
Karsten Hopp 81c285
--- src/gui_gtk_x11.c	2009-07-01 11:55:34.000000000 +0200
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 6717,6724 ****
Karsten Hopp 81c285
  {
Karsten Hopp 81c285
      GdkAtom	target;
Karsten Hopp 81c285
      unsigned	i;
Karsten Hopp 81c285
-     int		nbytes;
Karsten Hopp 81c285
-     char_u	*buffer;
Karsten Hopp 81c285
      time_t	start;
Karsten Hopp 81c285
  
Karsten Hopp 81c285
      for (i = 0; i < N_SELECTION_TARGETS; ++i)
Karsten Hopp 81c285
--- 6717,6722 ----
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 6746,6767 ****
Karsten Hopp 81c285
      }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
      /* Final fallback position - use the X CUT_BUFFER0 store */
Karsten Hopp 81c285
!     nbytes = 0;
Karsten Hopp 81c285
!     buffer = (char_u *)XFetchBuffer(GDK_WINDOW_XDISPLAY(gui.mainwin->window),
Karsten Hopp 81c285
! 				    &nbytes, 0);
Karsten Hopp 81c285
!     if (nbytes > 0)
Karsten Hopp 81c285
!     {
Karsten Hopp 81c285
! 	/* Got something */
Karsten Hopp 81c285
! 	clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
Karsten Hopp 81c285
! 	if (p_verbose > 0)
Karsten Hopp 81c285
! 	{
Karsten Hopp 81c285
! 	    verbose_enter();
Karsten Hopp 81c285
! 	    smsg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
Karsten Hopp 81c285
! 	    verbose_leave();
Karsten Hopp 81c285
! 	}
Karsten Hopp 81c285
!     }
Karsten Hopp 81c285
!     if (buffer != NULL)
Karsten Hopp 81c285
! 	XFree(buffer);
Karsten Hopp 81c285
  }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  /*
Karsten Hopp 81c285
--- 6744,6750 ----
Karsten Hopp 81c285
      }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
      /* Final fallback position - use the X CUT_BUFFER0 store */
Karsten Hopp 81c285
!     yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gui.mainwin->window), cbd);
Karsten Hopp 81c285
  }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  /*
Karsten Hopp 81c285
*** ../vim-7.2.220/src/message.c	2009-05-17 13:30:58.000000000 +0200
Karsten Hopp 81c285
--- src/message.c	2009-07-01 16:43:08.000000000 +0200
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 107,113 ****
Karsten Hopp 81c285
  }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  #if defined(FEAT_EVAL) || defined(FEAT_X11) || defined(USE_XSMP) \
Karsten Hopp 81c285
!     || defined(PROTO)
Karsten Hopp 81c285
  /*
Karsten Hopp 81c285
   * Like msg() but keep it silent when 'verbosefile' is set.
Karsten Hopp 81c285
   */
Karsten Hopp 81c285
--- 107,113 ----
Karsten Hopp 81c285
  }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  #if defined(FEAT_EVAL) || defined(FEAT_X11) || defined(USE_XSMP) \
Karsten Hopp 81c285
!     || defined(FEAT_GUI_GTK) || defined(PROTO)
Karsten Hopp 81c285
  /*
Karsten Hopp 81c285
   * Like msg() but keep it silent when 'verbosefile' is set.
Karsten Hopp 81c285
   */
Karsten Hopp 81c285
*** ../vim-7.2.220/src/ops.c	2009-05-26 18:12:13.000000000 +0200
Karsten Hopp 81c285
--- src/ops.c	2009-07-01 12:15:31.000000000 +0200
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 5591,5596 ****
Karsten Hopp 81c285
--- 5591,5619 ----
Karsten Hopp 81c285
      if (dpy != NULL && str != NULL && motion_type >= 0
Karsten Hopp 81c285
  					       && len < 1024*1024 && len > 0)
Karsten Hopp 81c285
      {
Karsten Hopp 81c285
+ #ifdef FEAT_MBYTE
Karsten Hopp 81c285
+ 	/* The CUT_BUFFER0 is supposed to always contain latin1.  Convert from
Karsten Hopp 81c285
+ 	 * 'enc' when it is a multi-byte encoding.  When 'enc' is an 8-bit
Karsten Hopp 81c285
+ 	 * encoding conversion usually doesn't work, so keep the text as-is.
Karsten Hopp 81c285
+ 	 */
Karsten Hopp 81c285
+ 	if (has_mbyte)
Karsten Hopp 81c285
+ 	{
Karsten Hopp 81c285
+ 	    char_u	*conv_str = str;
Karsten Hopp 81c285
+ 	    vimconv_T	vc;
Karsten Hopp 81c285
+ 
Karsten Hopp 81c285
+ 	    vc.vc_type = CONV_NONE;
Karsten Hopp 81c285
+ 	    if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK)
Karsten Hopp 81c285
+ 	    {
Karsten Hopp 81c285
+ 		conv_str = string_convert(&vc, str, (int*)&len;;
Karsten Hopp 81c285
+ 		if (conv_str != NULL)
Karsten Hopp 81c285
+ 		{
Karsten Hopp 81c285
+ 		    vim_free(str);
Karsten Hopp 81c285
+ 		    str = conv_str;
Karsten Hopp 81c285
+ 		}
Karsten Hopp 81c285
+ 		convert_setup(&vc, NULL, NULL);
Karsten Hopp 81c285
+ 	    }
Karsten Hopp 81c285
+ 	}
Karsten Hopp 81c285
+ #endif
Karsten Hopp 81c285
  	XStoreBuffer(dpy, (char *)str, (int)len, 0);
Karsten Hopp 81c285
  	XFlush(dpy);
Karsten Hopp 81c285
      }
Karsten Hopp 81c285
*** ../vim-7.2.220/src/proto/ui.pro	2007-05-05 19:58:49.000000000 +0200
Karsten Hopp 81c285
--- src/proto/ui.pro	2009-07-01 11:48:11.000000000 +0200
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 48,53 ****
Karsten Hopp 81c285
--- 48,54 ----
Karsten Hopp 81c285
  void open_app_context __ARGS((void));
Karsten Hopp 81c285
  void x11_setup_atoms __ARGS((Display *dpy));
Karsten Hopp 81c285
  void clip_x11_request_selection __ARGS((Widget myShell, Display *dpy, VimClipboard *cbd));
Karsten Hopp 81c285
+ void yank_cut_buffer0 __ARGS((Display *dpy, VimClipboard *cbd));
Karsten Hopp 81c285
  void clip_x11_lose_selection __ARGS((Widget myShell, VimClipboard *cbd));
Karsten Hopp 81c285
  int clip_x11_own_selection __ARGS((Widget myShell, VimClipboard *cbd));
Karsten Hopp 81c285
  void clip_x11_set_selection __ARGS((VimClipboard *cbd));
Karsten Hopp 81c285
*** ../vim-7.2.220/src/ui.c	2009-05-17 13:30:58.000000000 +0200
Karsten Hopp 81c285
--- src/ui.c	2009-07-01 15:44:07.000000000 +0200
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 2104,2111 ****
Karsten Hopp 81c285
      Atom	type;
Karsten Hopp 81c285
      static int	success;
Karsten Hopp 81c285
      int		i;
Karsten Hopp 81c285
-     int		nbytes = 0;
Karsten Hopp 81c285
-     char_u	*buffer;
Karsten Hopp 81c285
      time_t	start_time;
Karsten Hopp 81c285
      int		timed_out = FALSE;
Karsten Hopp 81c285
  
Karsten Hopp 81c285
--- 2104,2109 ----
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 2185,2199 ****
Karsten Hopp 81c285
      }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
      /* Final fallback position - use the X CUT_BUFFER0 store */
Karsten Hopp 81c285
!     buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0);
Karsten Hopp 81c285
!     if (nbytes > 0)
Karsten Hopp 81c285
!     {
Karsten Hopp 81c285
! 	/* Got something */
Karsten Hopp 81c285
! 	clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
Karsten Hopp 81c285
! 	XFree((void *)buffer);
Karsten Hopp 81c285
! 	if (p_verbose > 0)
Karsten Hopp 81c285
! 	    verb_msg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
Karsten Hopp 81c285
!     }
Karsten Hopp 81c285
  }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  static Boolean	clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *));
Karsten Hopp 81c285
--- 2183,2189 ----
Karsten Hopp 81c285
      }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
      /* Final fallback position - use the X CUT_BUFFER0 store */
Karsten Hopp 81c285
!     yank_cut_buffer0(dpy, cbd);
Karsten Hopp 81c285
  }
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  static Boolean	clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *));
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 2369,2374 ****
Karsten Hopp 81c285
--- 2359,2418 ----
Karsten Hopp 81c285
  }
Karsten Hopp 81c285
  #endif
Karsten Hopp 81c285
  
Karsten Hopp 81c285
+ #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) \
Karsten Hopp 81c285
+     || defined(FEAT_GUI_GTK) || defined(PROTO)
Karsten Hopp 81c285
+ /*
Karsten Hopp 81c285
+  * Get the contents of the X CUT_BUFFER0 and put it in "cbd".
Karsten Hopp 81c285
+  */
Karsten Hopp 81c285
+     void
Karsten Hopp 81c285
+ yank_cut_buffer0(dpy, cbd)
Karsten Hopp 81c285
+     Display		*dpy;
Karsten Hopp 81c285
+     VimClipboard	*cbd;
Karsten Hopp 81c285
+ {
Karsten Hopp 81c285
+     int		nbytes = 0;
Karsten Hopp 81c285
+     char_u	*buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0);
Karsten Hopp 81c285
+ 
Karsten Hopp 81c285
+     if (nbytes > 0)
Karsten Hopp 81c285
+     {
Karsten Hopp 81c285
+ #ifdef FEAT_MBYTE
Karsten Hopp 81c285
+ 	int  done = FALSE;
Karsten Hopp 81c285
+ 
Karsten Hopp 81c285
+ 	/* CUT_BUFFER0 is supposed to be always latin1.  Convert to 'enc' when
Karsten Hopp 81c285
+ 	 * using a multi-byte encoding.  Conversion between two 8-bit
Karsten Hopp 81c285
+ 	 * character sets usually fails and the text might actually be in
Karsten Hopp 81c285
+ 	 * 'enc' anyway. */
Karsten Hopp 81c285
+ 	if (has_mbyte)
Karsten Hopp 81c285
+ 	{
Karsten Hopp 81c285
+ 	    char_u	*conv_buf = buffer;
Karsten Hopp 81c285
+ 	    vimconv_T	vc;
Karsten Hopp 81c285
+ 
Karsten Hopp 81c285
+ 	    vc.vc_type = CONV_NONE;
Karsten Hopp 81c285
+ 	    if (convert_setup(&vc, (char_u *)"latin1", p_enc) == OK)
Karsten Hopp 81c285
+ 	    {
Karsten Hopp 81c285
+ 		conv_buf = string_convert(&vc, buffer, &nbytes);
Karsten Hopp 81c285
+ 		if (conv_buf != NULL)
Karsten Hopp 81c285
+ 		{
Karsten Hopp 81c285
+ 		    clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd);
Karsten Hopp 81c285
+ 		    vim_free(conv_buf);
Karsten Hopp 81c285
+ 		    done = TRUE;
Karsten Hopp 81c285
+ 		}
Karsten Hopp 81c285
+ 		convert_setup(&vc, NULL, NULL);
Karsten Hopp 81c285
+ 	    }
Karsten Hopp 81c285
+ 	}
Karsten Hopp 81c285
+ 	if (!done)  /* use the text without conversion */
Karsten Hopp 81c285
+ #endif
Karsten Hopp 81c285
+ 	    clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
Karsten Hopp 81c285
+ 	XFree((void *)buffer);
Karsten Hopp 81c285
+ 	if (p_verbose > 0)
Karsten Hopp 81c285
+ 	{
Karsten Hopp 81c285
+ 	    verbose_enter();
Karsten Hopp 81c285
+ 	    verb_msg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
Karsten Hopp 81c285
+ 	    verbose_leave();
Karsten Hopp 81c285
+ 	}
Karsten Hopp 81c285
+     }
Karsten Hopp 81c285
+ }
Karsten Hopp 81c285
+ #endif
Karsten Hopp 81c285
+ 
Karsten Hopp 81c285
  #if defined(FEAT_MOUSE) || defined(PROTO)
Karsten Hopp 81c285
  
Karsten Hopp 81c285
  /*
Karsten Hopp 81c285
*** ../vim-7.2.220/src/version.c	2009-07-01 17:11:40.000000000 +0200
Karsten Hopp 81c285
--- src/version.c	2009-07-01 17:56:02.000000000 +0200
Karsten Hopp 81c285
***************
Karsten Hopp 81c285
*** 678,679 ****
Karsten Hopp 81c285
--- 678,681 ----
Karsten Hopp 81c285
  {   /* Add new patch number below this line */
Karsten Hopp 81c285
+ /**/
Karsten Hopp 81c285
+     221,
Karsten Hopp 81c285
  /**/
Karsten Hopp 81c285
Karsten Hopp 81c285
-- 
Karsten Hopp 81c285
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 81c285
40. You tell the cab driver you live at
Karsten Hopp 81c285
    http://123.elm.street/house/bluetrim.html
Karsten Hopp 81c285
41. You actually try that 123.elm.street address.
Karsten Hopp 81c285
Karsten Hopp 81c285
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 81c285
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 81c285
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 81c285
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///