Your message dated Thu, 18 Jun 2009 01:01:36 -0400
with message-id <20090618050136.ge13...@jamessan.com>
has caused the   report #531372,
regarding vim-gtk: misuses X cut buffer
to be marked as having been forwarded to the upstream software
author(s) Bram Moolenaar <b...@moolenaar.net>

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact ow...@bugs.debian.org
immediately.)


-- 
531372: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=531372
Debian Bug Tracking System
Contact ow...@bugs.debian.org with problems
--- Begin Message ---
Bram,

As described below (and confirmed in the ICCCM documentation[0][1]), Vim
isn't correctly handling reading from/storing to CUT_BUFFER0.  The
attached patch adapts the portions of Vim which manipulate CUT_BUFFER0
to convert text to latin1 before storing to and convert from latin when
reading from the cut buffer.

[0] - http://tronche.com/gui/x/icccm/sec-3.html#s-3
[1] - http://tronche.com/gui/x/icccm/sec-2.html#s-2.6.2

On Sun, May 31, 2009 at 11:10:21PM -0500, Jonathan Nieder wrote:
> 1. Open gvim and type some non-ASCII text such as "étale".
> 2. Yank it (with just "yy", into the default register).
> 3. Exit.
> 4. Paste into a uxterm.
> 
> xterm treats the text as Latin-1, and the word étale appears. Similarly:
> 
> 1. Open uxterm, type some non-ASCII text such as "étale".
> 2. Select it with the mouse.
> 3. Unselect it.
> 4. Paste into gvim (with shift-insert or button-2).
> 
> gvim treats the text as malformed UTF-8, and the text <e9>tale is
> inserted. On the other hand, text can be pasted from gvim to gvim
> without problems.
> 
> This puzzled me (which program is right?) until I read the xterm
> manpage, which informs me
> 
>       But cut-buffers handle only ISO-8859-1 data (officially - some
>       clients ignore the rules).

-- 
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <james...@debian.org>
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index 29ab9a7..dfd12b0 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -6745,12 +6745,33 @@ clip_mch_request_selection(VimClipboard *cbd)
 	    return;
     }
 
-    /* Final fallback position - use the X CUT_BUFFER0 store */
+    /* Final fallback position - use the X CUT_BUFFER0 store, which should
+     * always be latin1. */
     nbytes = 0;
     buffer = (char_u *)XFetchBuffer(GDK_WINDOW_XDISPLAY(gui.mainwin->window),
 				    &nbytes, 0);
     if (nbytes > 0)
     {
+#ifdef FEAT_MBYTE
+	char_u		*conv_buf = buffer;
+	vimconv_T	vc;
+	vc.vc_type = CONV_NONE;
+	if (convert_setup(&vc, "latin1", p_enc) == OK)
+	{
+	    if ((conv_buf = string_convert(&vc, buffer, &nbytes)) != NULL)
+	    {
+		clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd);
+		vim_free(conv_buf);
+		convert_setup(&vc, NULL, NULL);
+		if (p_verbose > 0)
+		{
+		    verbose_enter();
+		    smsg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
+		    verbose_leave();
+		}
+	    }
+	}
+#else
 	/* Got something */
 	clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
 	if (p_verbose > 0)
@@ -6759,9 +6780,9 @@ clip_mch_request_selection(VimClipboard *cbd)
 	    smsg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
 	    verbose_leave();
 	}
+#endif
+	XFree((void *)buffer);
     }
-    if (buffer != NULL)
-	XFree(buffer);
 }
 
 /*
diff --git a/src/ops.c b/src/ops.c
index 3e595fd..83aec03 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -5556,7 +5556,8 @@ write_viminfo_registers(fp)
  * Routine to export any final X selection we had to the environment
  * so that the text is still available after vim has exited. X selections
  * only exist while the owning application exists, so we write to the
- * permanent (while X runs) store CUT_BUFFER0.
+ * permanent (while X runs) store CUT_BUFFER0.  The contents of CUT_BUFFER0
+ * should always bee latin1.
  * Dump the CLIPBOARD selection if we own it (it's logically the more
  * 'permanent' of the two), otherwise the PRIMARY one.
  * For now, use a hard-coded sanity limit of 1Mb of data.
@@ -5591,6 +5592,20 @@ x11_export_final_selection()
     if (dpy != NULL && str != NULL && motion_type >= 0
 					       && len < 1024*1024 && len > 0)
     {
+#ifdef FEAT_MBYTE
+	char_u		*conv_str = str;
+	vimconv_T	vc;
+	vc.vc_type = CONV_NONE;
+	if (convert_setup(&vc, p_enc, "latin1") == OK)
+	{
+	    if ((conv_str = string_convert(&vc, str, (int*)&len)) != NULL)
+	    {
+		vim_free(str);
+		str = conv_str;
+	    }
+	    convert_setup(&vc, NULL, NULL);
+	}
+#endif
 	XStoreBuffer(dpy, (char *)str, (int)len, 0);
 	XFlush(dpy);
     }
diff --git a/src/ui.c b/src/ui.c
index 443f9c4..41c629e 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -2184,15 +2184,33 @@ clip_x11_request_selection(myShell, dpy, cbd)
 	    break;
     }
 
-    /* Final fallback position - use the X CUT_BUFFER0 store */
+    /* Final fallback position - use the X CUT_BUFFER0 store, which should
+     * always be latin1. */
     buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0);
     if (nbytes > 0)
     {
+#ifdef FEAT_MBYTE
+	char_u		*conv_buf = buffer;
+	vimconv_T	vc;
+	vc.vc_type = CONV_NONE;
+	if (convert_setup(&vc, "latin1", p_enc) == OK)
+	{
+	    if ((conv_buf = string_convert(&vc, buffer, &nbytes)) != NULL)
+	    {
+		clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd);
+		vim_free(conv_buf);
+		convert_setup(&vc, NULL, NULL);
+		if (p_verbose > 0)
+		    verb_msg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
+	    }
+	}
+#else
 	/* Got something */
 	clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
-	XFree((void *)buffer);
 	if (p_verbose > 0)
 	    verb_msg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
+#endif
+	XFree((void *)buffer);
     }
 }
 

Attachment: signature.asc
Description: Digital signature


--- End Message ---

Reply via email to