]>
Commit | Line | Data |
---|---|---|
ef0610d1 AG |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.2.201 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.2.201 | |
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 | |
15 | ||
16 | ||
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 | |
19 | *************** | |
20 | *** 1443,1448 **** | |
21 | --- 1444,1457 ---- | |
22 | autoselectml Like "autoselect", but for the modeless selection | |
23 | only. Compare to the 'A' flag in 'guioptions'. | |
24 | ||
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. | |
32 | + | |
33 | exclude:{pattern} | |
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 | |
38 | *************** | |
39 | *** 509,514 **** | |
40 | --- 509,515 ---- | |
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); | |
46 | #endif | |
47 | ||
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 | |
50 | *************** | |
51 | *** 107,112 **** | |
52 | --- 107,113 ---- | |
53 | TARGET_UTF8_STRING, | |
54 | TARGET_STRING, | |
55 | TARGET_COMPOUND_TEXT, | |
56 | + TARGET_HTML, | |
57 | TARGET_TEXT, | |
58 | TARGET_TEXT_URI_LIST, | |
59 | TARGET_TEXT_PLAIN, | |
60 | *************** | |
61 | *** 123,128 **** | |
62 | --- 124,130 ---- | |
63 | {VIMENC_ATOM_NAME, 0, TARGET_VIMENC}, | |
64 | {VIM_ATOM_NAME, 0, TARGET_VIM}, | |
65 | #ifdef FEAT_MBYTE | |
66 | + {"text/html", 0, TARGET_HTML}, | |
67 | {"UTF8_STRING", 0, TARGET_UTF8_STRING}, | |
68 | #endif | |
69 | {"COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT}, | |
70 | *************** | |
71 | *** 140,145 **** | |
72 | --- 142,148 ---- | |
73 | { | |
74 | {"text/uri-list", 0, TARGET_TEXT_URI_LIST}, | |
75 | # ifdef FEAT_MBYTE | |
76 | + {"text/html", 0, TARGET_HTML}, | |
77 | {"UTF8_STRING", 0, TARGET_UTF8_STRING}, | |
78 | # endif | |
79 | {"STRING", 0, TARGET_STRING}, | |
80 | *************** | |
81 | *** 178,183 **** | |
82 | --- 181,187 ---- | |
83 | * Atoms used to control/reference X11 selections. | |
84 | */ | |
85 | #ifdef FEAT_MBYTE | |
86 | + static GdkAtom html_atom = GDK_NONE; | |
87 | static GdkAtom utf8_string_atom = GDK_NONE; | |
88 | #endif | |
89 | #ifndef HAVE_GTK2 | |
90 | *************** | |
91 | *** 1364,1369 **** | |
92 | --- 1368,1391 ---- | |
93 | else | |
94 | text = tmpbuf_utf8; | |
95 | } | |
96 | + else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) | |
97 | + { | |
98 | + vimconv_T conv; | |
99 | + | |
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); | |
103 | + | |
104 | + if (conv.vc_type != CONV_NONE) | |
105 | + { | |
106 | + text += 2; | |
107 | + len -= 2; | |
108 | + tmpbuf = string_convert(&conv, text, &len); | |
109 | + convert_setup(&conv, NULL, NULL); | |
110 | + } | |
111 | + if (tmpbuf != NULL) | |
112 | + text = tmpbuf; | |
113 | + } | |
114 | } | |
115 | #else /* !HAVE_GTK2 */ | |
116 | # ifdef FEAT_MBYTE | |
117 | *************** | |
118 | *** 1451,1456 **** | |
119 | --- 1473,1479 ---- | |
120 | ||
121 | if (info != (guint)TARGET_STRING | |
122 | #ifdef FEAT_MBYTE | |
123 | + && (!clip_html || info != (guint)TARGET_HTML) | |
124 | && info != (guint)TARGET_UTF8_STRING | |
125 | && info != (guint)TARGET_VIMENC | |
126 | #endif | |
127 | *************** | |
128 | *** 1486,1491 **** | |
129 | --- 1509,1548 ---- | |
130 | } | |
131 | ||
132 | #ifdef FEAT_MBYTE | |
133 | + else if (info == (guint)TARGET_HTML) | |
134 | + { | |
135 | + vimconv_T conv; | |
136 | + | |
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) | |
141 | + { | |
142 | + tmpbuf = string_convert(&conv, string, &length); | |
143 | + convert_setup(&conv, NULL, NULL); | |
144 | + vim_free(string); | |
145 | + string = tmpbuf; | |
146 | + } | |
147 | + | |
148 | + /* Prepend the BOM: "fffe" */ | |
149 | + if (string != NULL) | |
150 | + { | |
151 | + tmpbuf = alloc(length + 2); | |
152 | + tmpbuf[0] = 0xff; | |
153 | + tmpbuf[1] = 0xfe; | |
154 | + mch_memmove(tmpbuf + 2, string, (size_t)length); | |
155 | + vim_free(string); | |
156 | + string = tmpbuf; | |
157 | + length += 2; | |
158 | + | |
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, | |
162 | + string, length); | |
163 | + vim_free(string); | |
164 | + } | |
165 | + return; | |
166 | + } | |
167 | else if (info == (guint)TARGET_VIMENC) | |
168 | { | |
169 | int l = STRLEN(p_enc); | |
170 | *************** | |
171 | *** 3464,3469 **** | |
172 | --- 3521,3527 ---- | |
173 | ||
174 | /* Initialise atoms */ | |
175 | #ifdef FEAT_MBYTE | |
176 | + html_atom = gdk_atom_intern("text/html", FALSE); | |
177 | utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); | |
178 | #endif | |
179 | #ifndef HAVE_GTK2 | |
180 | *************** | |
181 | *** 6665,6670 **** | |
182 | --- 6723,6732 ---- | |
183 | ||
184 | for (i = 0; i < N_SELECTION_TARGETS; ++i) | |
185 | { | |
186 | + #ifdef FEAT_MBYTE | |
187 | + if (!clip_html && selection_targets[i].info == TARGET_HTML) | |
188 | + continue; | |
189 | + #endif | |
190 | received_selection = RS_NONE; | |
191 | target = gdk_atom_intern(selection_targets[i].target, FALSE); | |
192 | ||
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 | |
195 | *************** | |
196 | *** 3265,3271 **** | |
197 | ||
198 | # if defined(USE_ICONV) || defined(PROTO) | |
199 | ||
200 | ! static char_u *iconv_string __ARGS((vimconv_T *vcp, char_u *str, int slen, int *unconvlenp)); | |
201 | ||
202 | /* | |
203 | * Call iconv_open() with a check if iconv() works properly (there are broken | |
204 | --- 3265,3271 ---- | |
205 | ||
206 | # if defined(USE_ICONV) || defined(PROTO) | |
207 | ||
208 | ! static char_u *iconv_string __ARGS((vimconv_T *vcp, char_u *str, int slen, int *unconvlenp, int *resultlenp)); | |
209 | ||
210 | /* | |
211 | * Call iconv_open() with a check if iconv() works properly (there are broken | |
212 | *************** | |
213 | *** 3326,3338 **** | |
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. | |
217 | */ | |
218 | static char_u * | |
219 | ! iconv_string(vcp, str, slen, unconvlenp) | |
220 | vimconv_T *vcp; | |
221 | char_u *str; | |
222 | int slen; | |
223 | int *unconvlenp; | |
224 | { | |
225 | const char *from; | |
226 | size_t fromlen; | |
227 | --- 3326,3340 ---- | |
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. | |
232 | */ | |
233 | static char_u * | |
234 | ! iconv_string(vcp, str, slen, unconvlenp, resultlenp) | |
235 | vimconv_T *vcp; | |
236 | char_u *str; | |
237 | int slen; | |
238 | int *unconvlenp; | |
239 | + int *resultlenp; | |
240 | { | |
241 | const char *from; | |
242 | size_t fromlen; | |
243 | *************** | |
244 | *** 3418,3423 **** | |
245 | --- 3420,3428 ---- | |
246 | /* Not enough room or skipping illegal sequence. */ | |
247 | done = to - (char *)result; | |
248 | } | |
249 | + | |
250 | + if (resultlenp != NULL) | |
251 | + *resultlenp = (int)(to - (char *)result); | |
252 | return result; | |
253 | } | |
254 | ||
255 | *************** | |
256 | *** 5837,5844 **** | |
257 | --- 5842,5866 ---- | |
258 | char_u *from; | |
259 | char_u *to; | |
260 | { | |
261 | + return convert_setup_ext(vcp, from, TRUE, to, TRUE); | |
262 | + } | |
263 | + | |
264 | + /* | |
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". | |
267 | + */ | |
268 | + int | |
269 | + convert_setup_ext(vcp, from, from_unicode_is_utf8, to, to_unicode_is_utf8) | |
270 | + vimconv_T *vcp; | |
271 | + char_u *from; | |
272 | + int from_unicode_is_utf8; | |
273 | + char_u *to; | |
274 | + int to_unicode_is_utf8; | |
275 | + { | |
276 | int from_prop; | |
277 | int to_prop; | |
278 | + int from_is_utf8; | |
279 | + int to_is_utf8; | |
280 | ||
281 | /* Reset to no conversion. */ | |
282 | # ifdef USE_ICONV | |
283 | *************** | |
284 | *** 5856,5892 **** | |
285 | ||
286 | from_prop = enc_canon_props(from); | |
287 | to_prop = enc_canon_props(to); | |
288 | ! if ((from_prop & ENC_LATIN1) && (to_prop & ENC_UNICODE)) | |
289 | { | |
290 | /* Internal latin1 -> utf-8 conversion. */ | |
291 | vcp->vc_type = CONV_TO_UTF8; | |
292 | vcp->vc_factor = 2; /* up to twice as long */ | |
293 | } | |
294 | ! else if ((from_prop & ENC_LATIN9) && (to_prop & ENC_UNICODE)) | |
295 | { | |
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) */ | |
299 | } | |
300 | ! else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_LATIN1)) | |
301 | { | |
302 | /* Internal utf-8 -> latin1 conversion. */ | |
303 | vcp->vc_type = CONV_TO_LATIN1; | |
304 | } | |
305 | ! else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_LATIN9)) | |
306 | { | |
307 | /* Internal utf-8 -> latin9 conversion. */ | |
308 | vcp->vc_type = CONV_TO_LATIN9; | |
309 | } | |
310 | #ifdef WIN3264 | |
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)) | |
314 | { | |
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); | |
319 | } | |
320 | #endif | |
321 | #ifdef MACOS_X | |
322 | --- 5878,5923 ---- | |
323 | ||
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; | |
328 | ! else | |
329 | ! from_is_utf8 = from_prop == ENC_UNICODE; | |
330 | ! if (to_unicode_is_utf8) | |
331 | ! to_is_utf8 = to_prop & ENC_UNICODE; | |
332 | ! else | |
333 | ! to_is_utf8 = to_prop == ENC_UNICODE; | |
334 | ! | |
335 | ! if ((from_prop & ENC_LATIN1) && to_is_utf8) | |
336 | { | |
337 | /* Internal latin1 -> utf-8 conversion. */ | |
338 | vcp->vc_type = CONV_TO_UTF8; | |
339 | vcp->vc_factor = 2; /* up to twice as long */ | |
340 | } | |
341 | ! else if ((from_prop & ENC_LATIN9) && to_is_utf8) | |
342 | { | |
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) */ | |
346 | } | |
347 | ! else if (from_is_utf8 && (to_prop & ENC_LATIN1)) | |
348 | { | |
349 | /* Internal utf-8 -> latin1 conversion. */ | |
350 | vcp->vc_type = CONV_TO_LATIN1; | |
351 | } | |
352 | ! else if (from_is_utf8 && (to_prop & ENC_LATIN9)) | |
353 | { | |
354 | /* Internal utf-8 -> latin9 conversion. */ | |
355 | vcp->vc_type = CONV_TO_LATIN9; | |
356 | } | |
357 | #ifdef WIN3264 | |
358 | /* Win32-specific codepage <-> codepage conversion without iconv. */ | |
359 | ! else if ((from_is_utf8 || encname2codepage(from) > 0) | |
360 | ! && (to_is_utf8 || encname2codepage(to) > 0)) | |
361 | { | |
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); | |
366 | } | |
367 | #endif | |
368 | #ifdef MACOS_X | |
369 | *************** | |
370 | *** 5894,5900 **** | |
371 | { | |
372 | vcp->vc_type = CONV_MAC_LATIN1; | |
373 | } | |
374 | ! else if ((from_prop & ENC_MACROMAN) && (to_prop & ENC_UNICODE)) | |
375 | { | |
376 | vcp->vc_type = CONV_MAC_UTF8; | |
377 | vcp->vc_factor = 2; /* up to twice as long */ | |
378 | --- 5925,5931 ---- | |
379 | { | |
380 | vcp->vc_type = CONV_MAC_LATIN1; | |
381 | } | |
382 | ! else if ((from_prop & ENC_MACROMAN) && to_is_utf8) | |
383 | { | |
384 | vcp->vc_type = CONV_MAC_UTF8; | |
385 | vcp->vc_factor = 2; /* up to twice as long */ | |
386 | *************** | |
387 | *** 5903,5909 **** | |
388 | { | |
389 | vcp->vc_type = CONV_LATIN1_MAC; | |
390 | } | |
391 | ! else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_MACROMAN)) | |
392 | { | |
393 | vcp->vc_type = CONV_UTF8_MAC; | |
394 | } | |
395 | --- 5934,5940 ---- | |
396 | { | |
397 | vcp->vc_type = CONV_LATIN1_MAC; | |
398 | } | |
399 | ! else if (from_is_utf8 && (to_prop & ENC_MACROMAN)) | |
400 | { | |
401 | vcp->vc_type = CONV_UTF8_MAC; | |
402 | } | |
403 | *************** | |
404 | *** 5913,5920 **** | |
405 | { | |
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) | |
411 | { | |
412 | vcp->vc_type = CONV_ICONV; | |
413 | --- 5944,5951 ---- | |
414 | { | |
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) | |
420 | { | |
421 | vcp->vc_type = CONV_ICONV; | |
422 | *************** | |
423 | *** 6170,6178 **** | |
424 | ||
425 | # ifdef USE_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); | |
430 | break; | |
431 | # endif | |
432 | # ifdef WIN3264 | |
433 | --- 6201,6207 ---- | |
434 | ||
435 | # ifdef USE_ICONV | |
436 | case CONV_ICONV: /* conversion with output_conv.vc_fd */ | |
437 | ! retval = iconv_string(vcp, ptr, len, unconvlenp, lenp); | |
438 | break; | |
439 | # endif | |
440 | # ifdef WIN3264 | |
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 | |
443 | *************** | |
444 | *** 7024,7029 **** | |
445 | --- 7024,7030 ---- | |
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; | |
452 | char_u *p; | |
453 | *************** | |
454 | *** 7047,7052 **** | |
455 | --- 7048,7058 ---- | |
456 | new_autoselectml = TRUE; | |
457 | p += 12; | |
458 | } | |
459 | + else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL)) | |
460 | + { | |
461 | + new_html = TRUE; | |
462 | + p += 4; | |
463 | + } | |
464 | else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL) | |
465 | { | |
466 | p += 8; | |
467 | *************** | |
468 | *** 7068,7073 **** | |
469 | --- 7074,7080 ---- | |
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; | |
476 | } | |
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 | |
479 | *************** | |
480 | *** 678,679 **** | |
481 | --- 678,681 ---- | |
482 | { /* Add new patch number below this line */ | |
483 | + /**/ | |
484 | + 201, | |
485 | /**/ | |
486 | ||
487 | -- | |
488 | How To Keep A Healthy Level Of Insanity: | |
489 | 13. Go to a poetry recital and ask why the poems don't rhyme. | |
490 | ||
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 /// |