4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Cannot copy/paste HTML to/from Firefox via the clipboard.
12 Solution: Implement this for GTK. Add the "html" value to 'clipboard'.
13 Files: runtime/doc/options.txt, src/globals.h, src/gui_gtk_x11.c,
14 src/mbyte.c, src/proto/mbyte.pro, src/option.c
17 *** ../vim-7.2.200/runtime/doc/options.txt 2009-02-21 20:27:00.000000000 +0100
18 --- runtime/doc/options.txt 2009-06-12 22:25:22.000000000 +0200
22 autoselectml Like "autoselect", but for the modeless selection
23 only. Compare to the 'A' flag in 'guioptions'.
25 + html When the clipboard contains HTML, use this when
26 + pasting. When putting text on the clipboard, mark it
27 + as HTML. This works to copy rendered HTML from
28 + Firefox, paste it as raw HTML in Vim, select the HTML
29 + in Vim and paste it in a rich edit box in Firefox.
30 + Only supported for GTK version 2 and later.
31 + Only available with the |+multi_byte| feature.
34 Defines a pattern that is matched against the name of
35 the terminal 'term'. If there is a match, no
36 *** ../vim-7.2.200/src/globals.h 2009-06-16 15:12:11.000000000 +0200
37 --- src/globals.h 2009-06-12 21:10:30.000000000 +0200
41 EXTERN int clip_unnamed INIT(= FALSE);
42 EXTERN int clip_autoselect INIT(= FALSE);
43 EXTERN int clip_autoselectml INIT(= FALSE);
44 + EXTERN int clip_html INIT(= FALSE);
45 EXTERN regprog_T *clip_exclude_prog INIT(= NULL);
48 *** ../vim-7.2.200/src/gui_gtk_x11.c 2009-06-16 15:12:11.000000000 +0200
49 --- src/gui_gtk_x11.c 2009-06-16 14:44:19.000000000 +0200
63 {VIMENC_ATOM_NAME, 0, TARGET_VIMENC},
64 {VIM_ATOM_NAME, 0, TARGET_VIM},
66 + {"text/html", 0, TARGET_HTML},
67 {"UTF8_STRING", 0, TARGET_UTF8_STRING},
69 {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT},
74 {"text/uri-list", 0, TARGET_TEXT_URI_LIST},
76 + {"text/html", 0, TARGET_HTML},
77 {"UTF8_STRING", 0, TARGET_UTF8_STRING},
79 {"STRING", 0, TARGET_STRING},
83 * Atoms used to control/reference X11 selections.
86 + static GdkAtom html_atom = GDK_NONE;
87 static GdkAtom utf8_string_atom = GDK_NONE;
96 + else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe)
100 + /* UTF-16, we get this for HTML */
101 + conv.vc_type = CONV_NONE;
102 + convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE);
104 + if (conv.vc_type != CONV_NONE)
108 + tmpbuf = string_convert(&conv, text, &len);
109 + convert_setup(&conv, NULL, NULL);
111 + if (tmpbuf != NULL)
115 #else /* !HAVE_GTK2 */
121 if (info != (guint)TARGET_STRING
123 + && (!clip_html || info != (guint)TARGET_HTML)
124 && info != (guint)TARGET_UTF8_STRING
125 && info != (guint)TARGET_VIMENC
133 + else if (info == (guint)TARGET_HTML)
137 + /* Since we get utf-16, we probably should set it as well. */
138 + conv.vc_type = CONV_NONE;
139 + convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE);
140 + if (conv.vc_type != CONV_NONE)
142 + tmpbuf = string_convert(&conv, string, &length);
143 + convert_setup(&conv, NULL, NULL);
148 + /* Prepend the BOM: "fffe" */
149 + if (string != NULL)
151 + tmpbuf = alloc(length + 2);
154 + mch_memmove(tmpbuf + 2, string, (size_t)length);
159 + selection_data->type = selection_data->target;
160 + selection_data->format = 16; /* 16 bits per char */
161 + gtk_selection_data_set(selection_data, html_atom, 16,
167 else if (info == (guint)TARGET_VIMENC)
169 int l = STRLEN(p_enc);
174 /* Initialise atoms */
176 + html_atom = gdk_atom_intern("text/html", FALSE);
177 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);
184 for (i = 0; i < N_SELECTION_TARGETS; ++i)
187 + if (!clip_html && selection_targets[i].info == TARGET_HTML)
190 received_selection = RS_NONE;
191 target = gdk_atom_intern(selection_targets[i].target, FALSE);
193 *** ../vim-7.2.200/src/mbyte.c 2009-06-16 15:12:11.000000000 +0200
194 --- src/mbyte.c 2009-06-16 15:01:30.000000000 +0200
198 # if defined(USE_ICONV) || defined(PROTO)
200 ! static char_u *iconv_string __ARGS((vimconv_T *vcp, char_u *str, int slen, int *unconvlenp));
203 * Call iconv_open() with a check if iconv() works properly (there are broken
206 # if defined(USE_ICONV) || defined(PROTO)
208 ! static char_u *iconv_string __ARGS((vimconv_T *vcp, char_u *str, int slen, int *unconvlenp, int *resultlenp));
211 * Call iconv_open() with a check if iconv() works properly (there are broken
214 * If "unconvlenp" is not NULL handle the string ending in an incomplete
215 * sequence and set "*unconvlenp" to the length of it.
216 * Returns the converted string in allocated memory. NULL for an error.
219 ! iconv_string(vcp, str, slen, unconvlenp)
228 * If "unconvlenp" is not NULL handle the string ending in an incomplete
229 * sequence and set "*unconvlenp" to the length of it.
230 * Returns the converted string in allocated memory. NULL for an error.
231 + * If resultlenp is not NULL, sets it to the result length in bytes.
234 ! iconv_string(vcp, str, slen, unconvlenp, resultlenp)
246 /* Not enough room or skipping illegal sequence. */
247 done = to - (char *)result;
250 + if (resultlenp != NULL)
251 + *resultlenp = (int)(to - (char *)result);
261 + return convert_setup_ext(vcp, from, TRUE, to, TRUE);
265 + * As convert_setup(), but only when from_unicode_is_utf8 is TRUE will all
266 + * "from" unicode charsets be considered utf-8. Same for "to".
269 + convert_setup_ext(vcp, from, from_unicode_is_utf8, to, to_unicode_is_utf8)
272 + int from_unicode_is_utf8;
274 + int to_unicode_is_utf8;
281 /* Reset to no conversion. */
286 from_prop = enc_canon_props(from);
287 to_prop = enc_canon_props(to);
288 ! if ((from_prop & ENC_LATIN1) && (to_prop & ENC_UNICODE))
290 /* Internal latin1 -> utf-8 conversion. */
291 vcp->vc_type = CONV_TO_UTF8;
292 vcp->vc_factor = 2; /* up to twice as long */
294 ! else if ((from_prop & ENC_LATIN9) && (to_prop & ENC_UNICODE))
296 /* Internal latin9 -> utf-8 conversion. */
297 vcp->vc_type = CONV_9_TO_UTF8;
298 vcp->vc_factor = 3; /* up to three as long (euro sign) */
300 ! else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_LATIN1))
302 /* Internal utf-8 -> latin1 conversion. */
303 vcp->vc_type = CONV_TO_LATIN1;
305 ! else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_LATIN9))
307 /* Internal utf-8 -> latin9 conversion. */
308 vcp->vc_type = CONV_TO_LATIN9;
311 /* Win32-specific codepage <-> codepage conversion without iconv. */
312 ! else if (((from_prop & ENC_UNICODE) || encname2codepage(from) > 0)
313 ! && ((to_prop & ENC_UNICODE) || encname2codepage(to) > 0))
315 vcp->vc_type = CONV_CODEPAGE;
316 vcp->vc_factor = 2; /* up to twice as long */
317 ! vcp->vc_cpfrom = (from_prop & ENC_UNICODE) ? 0 : encname2codepage(from);
318 ! vcp->vc_cpto = (to_prop & ENC_UNICODE) ? 0 : encname2codepage(to);
324 from_prop = enc_canon_props(from);
325 to_prop = enc_canon_props(to);
326 ! if (from_unicode_is_utf8)
327 ! from_is_utf8 = from_prop & ENC_UNICODE;
329 ! from_is_utf8 = from_prop == ENC_UNICODE;
330 ! if (to_unicode_is_utf8)
331 ! to_is_utf8 = to_prop & ENC_UNICODE;
333 ! to_is_utf8 = to_prop == ENC_UNICODE;
335 ! if ((from_prop & ENC_LATIN1) && to_is_utf8)
337 /* Internal latin1 -> utf-8 conversion. */
338 vcp->vc_type = CONV_TO_UTF8;
339 vcp->vc_factor = 2; /* up to twice as long */
341 ! else if ((from_prop & ENC_LATIN9) && to_is_utf8)
343 /* Internal latin9 -> utf-8 conversion. */
344 vcp->vc_type = CONV_9_TO_UTF8;
345 vcp->vc_factor = 3; /* up to three as long (euro sign) */
347 ! else if (from_is_utf8 && (to_prop & ENC_LATIN1))
349 /* Internal utf-8 -> latin1 conversion. */
350 vcp->vc_type = CONV_TO_LATIN1;
352 ! else if (from_is_utf8 && (to_prop & ENC_LATIN9))
354 /* Internal utf-8 -> latin9 conversion. */
355 vcp->vc_type = CONV_TO_LATIN9;
358 /* Win32-specific codepage <-> codepage conversion without iconv. */
359 ! else if ((from_is_utf8 || encname2codepage(from) > 0)
360 ! && (to_is_utf8 || encname2codepage(to) > 0))
362 vcp->vc_type = CONV_CODEPAGE;
363 vcp->vc_factor = 2; /* up to twice as long */
364 ! vcp->vc_cpfrom = from_is_utf8 ? 0 : encname2codepage(from);
365 ! vcp->vc_cpto = to_is_utf8 ? 0 : encname2codepage(to);
372 vcp->vc_type = CONV_MAC_LATIN1;
374 ! else if ((from_prop & ENC_MACROMAN) && (to_prop & ENC_UNICODE))
376 vcp->vc_type = CONV_MAC_UTF8;
377 vcp->vc_factor = 2; /* up to twice as long */
380 vcp->vc_type = CONV_MAC_LATIN1;
382 ! else if ((from_prop & ENC_MACROMAN) && to_is_utf8)
384 vcp->vc_type = CONV_MAC_UTF8;
385 vcp->vc_factor = 2; /* up to twice as long */
389 vcp->vc_type = CONV_LATIN1_MAC;
391 ! else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_MACROMAN))
393 vcp->vc_type = CONV_UTF8_MAC;
397 vcp->vc_type = CONV_LATIN1_MAC;
399 ! else if (from_is_utf8 && (to_prop & ENC_MACROMAN))
401 vcp->vc_type = CONV_UTF8_MAC;
406 /* Use iconv() for conversion. */
407 vcp->vc_fd = (iconv_t)my_iconv_open(
408 ! (to_prop & ENC_UNICODE) ? (char_u *)"utf-8" : to,
409 ! (from_prop & ENC_UNICODE) ? (char_u *)"utf-8" : from);
410 if (vcp->vc_fd != (iconv_t)-1)
412 vcp->vc_type = CONV_ICONV;
415 /* Use iconv() for conversion. */
416 vcp->vc_fd = (iconv_t)my_iconv_open(
417 ! to_is_utf8 ? (char_u *)"utf-8" : to,
418 ! from_is_utf8 ? (char_u *)"utf-8" : from);
419 if (vcp->vc_fd != (iconv_t)-1)
421 vcp->vc_type = CONV_ICONV;
426 case CONV_ICONV: /* conversion with output_conv.vc_fd */
427 ! retval = iconv_string(vcp, ptr, len, unconvlenp);
428 ! if (retval != NULL && lenp != NULL)
429 ! *lenp = (int)STRLEN(retval);
436 case CONV_ICONV: /* conversion with output_conv.vc_fd */
437 ! retval = iconv_string(vcp, ptr, len, unconvlenp, lenp);
441 *** ../vim-7.2.200/src/option.c 2009-05-17 13:30:58.000000000 +0200
442 --- src/option.c 2009-06-12 21:09:51.000000000 +0200
446 int new_unnamed = FALSE;
447 int new_autoselect = FALSE;
448 int new_autoselectml = FALSE;
449 + int new_html = FALSE;
450 regprog_T *new_exclude_prog = NULL;
451 char_u *errmsg = NULL;
456 new_autoselectml = TRUE;
459 + else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
464 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
470 clip_unnamed = new_unnamed;
471 clip_autoselect = new_autoselect;
472 clip_autoselectml = new_autoselectml;
473 + clip_html = new_html;
474 vim_free(clip_exclude_prog);
475 clip_exclude_prog = new_exclude_prog;
477 *** ../vim-7.2.200/src/version.c 2009-06-16 15:12:11.000000000 +0200
478 --- src/version.c 2009-06-16 15:14:02.000000000 +0200
482 { /* Add new patch number below this line */
488 How To Keep A Healthy Level Of Insanity:
489 13. Go to a poetry recital and ask why the poems don't rhyme.
491 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
492 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
493 \\\ download, build and distribute -- http://www.A-A-P.org ///
494 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///