4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
10 CORRECTED PATCH: chunk in gui_gtk_x11.c was removed, it didn't belong here.
13 Problem: The X11 clipboard supports the Vim selection for char/line/block
14 mode, but since the encoding is not included can't copy/paste
15 between two Vims with a different 'encoding'.
16 Solution: Add a new selection format that includes the 'encoding'. Perform
17 conversion when necessary.
18 Files: src/gui_gtk_x11.c, src/ui.c, src/vim.h
21 *** ../vim-6.2.427/src/gui_gtk_x11.c Tue Mar 23 21:19:08 2004
22 --- src/gui_gtk_x11.c Fri Apr 2 12:52:16 2004
45 static const GtkTargetEntry selection_targets[] =
47 + {VIMENC_ATOM_NAME, 0, TARGET_VIMENC},
48 {VIM_ATOM_NAME, 0, TARGET_VIM},
50 {"UTF8_STRING", 0, TARGET_UTF8_STRING},
54 static GdkAtom text_atom = GDK_NONE;
56 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */
58 + static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */
62 * Keycodes recognized by vim.
66 motion_type = *text++;
71 + else if (data->type == vimenc_atom)
76 + motion_type = *text++;
80 + text += STRLEN(text) + 1;
83 + /* If the encoding of the text is different from 'encoding', attempt
85 + conv.vc_type = CONV_NONE;
86 + convert_setup(&conv, enc, p_enc);
87 + if (conv.vc_type != CONV_NONE)
89 + tmpbuf = string_convert(&conv, text, &len);
92 + convert_setup(&conv, NULL, NULL);
98 /* gtk_selection_data_get_text() handles all the nasty details
99 * and targets and encodings etc. This rocks so hard. */
103 if (info != (guint)TARGET_STRING
105 && info != (guint)TARGET_UTF8_STRING
106 + && info != (guint)TARGET_VIMENC
108 && info != (guint)TARGET_VIM
109 && info != (guint)TARGET_COMPOUND_TEXT
118 + else if (info == (guint)TARGET_VIMENC)
120 + int l = STRLEN(p_enc);
122 + /* contents: motion_type 'encoding' NUL text */
123 + tmpbuf = alloc((unsigned)length + l + 2);
124 + if (tmpbuf != NULL)
126 + tmpbuf[0] = motion_type;
127 + STRCPY(tmpbuf + 1, p_enc);
128 + mch_memmove(tmpbuf + l + 2, string, (size_t)length);
133 + type = vimenc_atom;
138 /* gtk_selection_data_set_text() handles everything for us. This is
139 * so easy and simple and cool, it'd be insane not to use it. */
143 * Set clipboard specific atoms
145 vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE);
147 + vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE);
149 clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY;
150 clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE);
156 for (p = s; p < s + len; ++p)
157 ! if (*p & 0x80) goto not_ascii;
159 pango_glyph_string_set_size(glyphs, len);
164 for (p = s; p < s + len; ++p)
168 pango_glyph_string_set_size(glyphs, len);
170 *** ../vim-6.2.427/src/ui.c Fri Apr 2 11:36:09 2004
171 --- src/ui.c Fri Apr 2 12:51:57 2004
177 static Atom vim_atom; /* Vim's own special selection format */
179 + static Atom vimenc_atom; /* Vim's extended selection format */
181 static Atom compound_text_atom;
182 static Atom text_atom;
183 static Atom targets_atom;
189 vim_atom = XInternAtom(dpy, VIM_ATOM_NAME, False);
191 + vimenc_atom = XInternAtom(dpy, VIMENC_ATOM_NAME,False);
193 compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False);
194 text_atom = XInternAtom(dpy, "TEXT", False);
195 targets_atom = XInternAtom(dpy, "TARGETS", False);
200 char **text_list = NULL;
203 + char_u *tmpbuf = NULL;
206 if (*sel_atom == clip_plus.sel_atom)
216 + else if (*type == vimenc_atom)
222 + motion_type = *p++;
226 + p += STRLEN(p) + 1;
229 + /* If the encoding of the text is different from 'encoding', attempt
230 + * converting it. */
231 + conv.vc_type = CONV_NONE;
232 + convert_setup(&conv, enc, p_enc);
233 + if (conv.vc_type != CONV_NONE)
235 + convlen = len; /* Need to use an int here. */
236 + tmpbuf = string_convert(&conv, p, &convlen);
238 + if (tmpbuf != NULL)
240 + convert_setup(&conv, NULL, NULL);
245 else if (*type == compound_text_atom || (
251 if (text_list != NULL)
252 XFreeStringList(text_list);
254 XtFree((char *)value);
255 *(int *)success = TRUE;
259 if (text_list != NULL)
260 XFreeStringList(text_list);
264 XtFree((char *)value);
265 *(int *)success = TRUE;
272 ! for (i = 0; i < 4; i++)
276 ! case 0: type = vim_atom; break;
277 ! case 1: type = compound_text_atom; break;
278 ! case 2: type = text_atom; break;
279 default: type = XA_STRING;
281 XtGetSelectionValue(myShell, cbd->sel_atom, type,
297 ! case 0: type = vimenc_atom; break;
299 ! case 1: type = vim_atom; break;
300 ! case 2: type = compound_text_atom; break;
301 ! case 3: type = text_atom; break;
302 default: type = XA_STRING;
304 XtGetSelectionValue(myShell, cbd->sel_atom, type,
313 if (*sel_atom == clip_plus.sel_atom)
320 ! if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 5))) == NULL)
322 *value = (XtPointer)array;
323 ! array[0] = XA_STRING;
324 ! array[1] = targets_atom;
325 ! array[2] = vim_atom;
326 ! array[3] = text_atom;
327 ! array[4] = compound_text_atom;
329 /* This used to be: *format = sizeof(Atom) * 8; but that caused
330 * crashes on 64 bit machines. (Peter Derr) */
336 if ( *target != XA_STRING
337 && *target != vim_atom
338 && *target != text_atom
339 && *target != compound_text_atom)
344 ! if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 6))) == NULL)
346 *value = (XtPointer)array;
348 ! array[i++] = XA_STRING;
349 ! array[i++] = targets_atom;
351 ! array[i++] = vimenc_atom;
353 ! array[i++] = vim_atom;
354 ! array[i++] = text_atom;
355 ! array[i++] = compound_text_atom;
357 /* This used to be: *format = sizeof(Atom) * 8; but that caused
358 * crashes on 64 bit machines. (Peter Derr) */
364 if ( *target != XA_STRING
366 + && *target != vimenc_atom
368 && *target != vim_atom
369 && *target != text_atom
370 && *target != compound_text_atom)
374 if (*target == vim_atom)
378 + /* Our own format with encoding: motion 'encoding' NUL text */
379 + if (*target == vimenc_atom)
380 + *length += STRLEN(p_enc) + 2;
383 *value = XtMalloc((Cardinal)*length);
384 result = (char_u *)*value;
389 *length = text_prop.nitems;
390 *type = compound_text_atom;
394 + else if (*target == vimenc_atom)
396 + int l = STRLEN(p_enc);
398 + result[0] = motion_type;
399 + STRCPY(result + 1, p_enc);
400 + mch_memmove(result + l + 2, string, (size_t)(*length - l - 2));
401 + *type = vimenc_atom;
407 result[0] = motion_type;
408 *** ../vim-6.2.427/src/vim.h Thu Mar 18 14:39:31 2004
409 --- src/vim.h Fri Apr 2 12:34:09 2004
413 #ifdef FEAT_CLIPBOARD
415 ! /* Vim-specific selection type for X11 */
416 #define VIM_ATOM_NAME "_VIM_TEXT"
418 /* Selection states for modeless selection */
419 # define SELECT_CLEARED 0
422 #ifdef FEAT_CLIPBOARD
424 ! /* VIM_ATOM_NAME is the older Vim-specific selection type for X11. Still
425 ! * supported for when a mix of Vim versions is used. VIMENC_ATOM_NAME includes
426 ! * the encoding to support Vims using different 'encoding' values. */
427 #define VIM_ATOM_NAME "_VIM_TEXT"
428 + #define VIMENC_ATOM_NAME "_VIMENC_TEXT"
430 /* Selection states for modeless selection */
431 # define SELECT_CLEARED 0
432 *** ../vim-6.2.427/src/version.c Fri Apr 2 11:36:09 2004
433 --- src/version.c Fri Apr 2 14:05:46 2004
437 { /* Add new patch number below this line */
443 You can tune a file system, but you can't tuna fish
446 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
447 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
448 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
449 \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///