home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.201 < prev    next >
Encoding:
Internet Message Format  |  2009-06-15  |  14.1 KB

  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.       exclude:{pattern}
  33.               Defines a pattern that is matched against the name of
  34.               the terminal 'term'.  If there is a match, no
  35. *** ../vim-7.2.200/src/globals.h    2009-06-16 15:12:11.000000000 +0200
  36. --- src/globals.h    2009-06-12 21:10:30.000000000 +0200
  37. ***************
  38. *** 509,514 ****
  39. --- 509,515 ----
  40.   EXTERN int    clip_unnamed INIT(= FALSE);
  41.   EXTERN int    clip_autoselect INIT(= FALSE);
  42.   EXTERN int    clip_autoselectml INIT(= FALSE);
  43. + EXTERN int    clip_html INIT(= FALSE);
  44.   EXTERN regprog_T *clip_exclude_prog INIT(= NULL);
  45.   #endif
  46.   
  47. *** ../vim-7.2.200/src/gui_gtk_x11.c    2009-06-16 15:12:11.000000000 +0200
  48. --- src/gui_gtk_x11.c    2009-06-16 14:44:19.000000000 +0200
  49. ***************
  50. *** 107,112 ****
  51. --- 107,113 ----
  52.       TARGET_UTF8_STRING,
  53.       TARGET_STRING,
  54.       TARGET_COMPOUND_TEXT,
  55. +     TARGET_HTML,
  56.       TARGET_TEXT,
  57.       TARGET_TEXT_URI_LIST,
  58.       TARGET_TEXT_PLAIN,
  59. ***************
  60. *** 123,128 ****
  61. --- 124,130 ----
  62.       {VIMENC_ATOM_NAME,    0, TARGET_VIMENC},
  63.       {VIM_ATOM_NAME,    0, TARGET_VIM},
  64.   #ifdef FEAT_MBYTE
  65. +     {"text/html",    0, TARGET_HTML},
  66.       {"UTF8_STRING",    0, TARGET_UTF8_STRING},
  67.   #endif
  68.       {"COMPOUND_TEXT",    0, TARGET_COMPOUND_TEXT},
  69. ***************
  70. *** 140,145 ****
  71. --- 142,148 ----
  72.   {
  73.       {"text/uri-list",    0, TARGET_TEXT_URI_LIST},
  74.   # ifdef FEAT_MBYTE
  75. +     {"text/html",    0, TARGET_HTML},
  76.       {"UTF8_STRING",    0, TARGET_UTF8_STRING},
  77.   # endif
  78.       {"STRING",        0, TARGET_STRING},
  79. ***************
  80. *** 178,183 ****
  81. --- 181,187 ----
  82.    * Atoms used to control/reference X11 selections.
  83.    */
  84.   #ifdef FEAT_MBYTE
  85. + static GdkAtom html_atom = GDK_NONE;
  86.   static GdkAtom utf8_string_atom = GDK_NONE;
  87.   #endif
  88.   #ifndef HAVE_GTK2
  89. ***************
  90. *** 1364,1369 ****
  91. --- 1368,1391 ----
  92.           else
  93.           text = tmpbuf_utf8;
  94.       }
  95. +     else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe)
  96. +     {
  97. +         vimconv_T conv;
  98. +         /* UTF-16, we get this for HTML */
  99. +         conv.vc_type = CONV_NONE;
  100. +         convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE);
  101. +         if (conv.vc_type != CONV_NONE)
  102. +         {
  103. +         text += 2;
  104. +         len -= 2;
  105. +         tmpbuf = string_convert(&conv, text, &len);
  106. +         convert_setup(&conv, NULL, NULL);
  107. +         }
  108. +         if (tmpbuf != NULL)
  109. +         text = tmpbuf;
  110. +     }
  111.       }
  112.   #else /* !HAVE_GTK2 */
  113.   # ifdef FEAT_MBYTE
  114. ***************
  115. *** 1451,1456 ****
  116. --- 1473,1479 ----
  117.   
  118.       if (info != (guint)TARGET_STRING
  119.   #ifdef FEAT_MBYTE
  120. +         && (!clip_html || info != (guint)TARGET_HTML)
  121.           && info != (guint)TARGET_UTF8_STRING
  122.           && info != (guint)TARGET_VIMENC
  123.   #endif
  124. ***************
  125. *** 1486,1491 ****
  126. --- 1509,1548 ----
  127.       }
  128.   
  129.   #ifdef FEAT_MBYTE
  130. +     else if (info == (guint)TARGET_HTML)
  131. +     {
  132. +     vimconv_T conv;
  133. +     /* Since we get utf-16, we probably should set it as well. */
  134. +     conv.vc_type = CONV_NONE;
  135. +     convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE);
  136. +     if (conv.vc_type != CONV_NONE)
  137. +     {
  138. +         tmpbuf = string_convert(&conv, string, &length);
  139. +         convert_setup(&conv, NULL, NULL);
  140. +         vim_free(string);
  141. +         string = tmpbuf;
  142. +     }
  143. +     /* Prepend the BOM: "fffe" */
  144. +     if (string != NULL)
  145. +     {
  146. +         tmpbuf = alloc(length + 2);
  147. +         tmpbuf[0] = 0xff;
  148. +         tmpbuf[1] = 0xfe;
  149. +         mch_memmove(tmpbuf + 2, string, (size_t)length);
  150. +         vim_free(string);
  151. +         string = tmpbuf;
  152. +         length += 2;
  153. +         selection_data->type = selection_data->target;
  154. +         selection_data->format = 16;    /* 16 bits per char */
  155. +         gtk_selection_data_set(selection_data, html_atom, 16,
  156. +                                   string, length);
  157. +         vim_free(string);
  158. +     }
  159. +     return;
  160. +     }
  161.       else if (info == (guint)TARGET_VIMENC)
  162.       {
  163.       int l = STRLEN(p_enc);
  164. ***************
  165. *** 3464,3469 ****
  166. --- 3521,3527 ----
  167.   
  168.       /* Initialise atoms */
  169.   #ifdef FEAT_MBYTE
  170. +     html_atom = gdk_atom_intern("text/html", FALSE);
  171.       utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);
  172.   #endif
  173.   #ifndef HAVE_GTK2
  174. ***************
  175. *** 6665,6670 ****
  176. --- 6723,6732 ----
  177.   
  178.       for (i = 0; i < N_SELECTION_TARGETS; ++i)
  179.       {
  180. + #ifdef FEAT_MBYTE
  181. +     if (!clip_html && selection_targets[i].info == TARGET_HTML)
  182. +         continue;
  183. + #endif
  184.       received_selection = RS_NONE;
  185.       target = gdk_atom_intern(selection_targets[i].target, FALSE);
  186.   
  187. *** ../vim-7.2.200/src/mbyte.c    2009-06-16 15:12:11.000000000 +0200
  188. --- src/mbyte.c    2009-06-16 15:01:30.000000000 +0200
  189. ***************
  190. *** 3265,3271 ****
  191.   
  192.   # if defined(USE_ICONV) || defined(PROTO)
  193.   
  194. ! static char_u *iconv_string __ARGS((vimconv_T *vcp, char_u *str, int slen, int *unconvlenp));
  195.   
  196.   /*
  197.    * Call iconv_open() with a check if iconv() works properly (there are broken
  198. --- 3265,3271 ----
  199.   
  200.   # if defined(USE_ICONV) || defined(PROTO)
  201.   
  202. ! static char_u *iconv_string __ARGS((vimconv_T *vcp, char_u *str, int slen, int *unconvlenp, int *resultlenp));
  203.   
  204.   /*
  205.    * Call iconv_open() with a check if iconv() works properly (there are broken
  206. ***************
  207. *** 3326,3338 ****
  208.    * If "unconvlenp" is not NULL handle the string ending in an incomplete
  209.    * sequence and set "*unconvlenp" to the length of it.
  210.    * Returns the converted string in allocated memory.  NULL for an error.
  211.    */
  212.       static char_u *
  213. ! iconv_string(vcp, str, slen, unconvlenp)
  214.       vimconv_T    *vcp;
  215.       char_u    *str;
  216.       int        slen;
  217.       int        *unconvlenp;
  218.   {
  219.       const char    *from;
  220.       size_t    fromlen;
  221. --- 3326,3340 ----
  222.    * If "unconvlenp" is not NULL handle the string ending in an incomplete
  223.    * sequence and set "*unconvlenp" to the length of it.
  224.    * Returns the converted string in allocated memory.  NULL for an error.
  225. +  * If resultlenp is not NULL, sets it to the result length in bytes.
  226.    */
  227.       static char_u *
  228. ! iconv_string(vcp, str, slen, unconvlenp, resultlenp)
  229.       vimconv_T    *vcp;
  230.       char_u    *str;
  231.       int        slen;
  232.       int        *unconvlenp;
  233. +     int        *resultlenp;
  234.   {
  235.       const char    *from;
  236.       size_t    fromlen;
  237. ***************
  238. *** 3418,3423 ****
  239. --- 3420,3428 ----
  240.       /* Not enough room or skipping illegal sequence. */
  241.       done = to - (char *)result;
  242.       }
  243. +     if (resultlenp != NULL)
  244. +     *resultlenp = (int)(to - (char *)result);
  245.       return result;
  246.   }
  247.   
  248. ***************
  249. *** 5837,5844 ****
  250. --- 5842,5866 ----
  251.       char_u    *from;
  252.       char_u    *to;
  253.   {
  254. +     return convert_setup_ext(vcp, from, TRUE, to, TRUE);
  255. + }
  256. + /*
  257. +  * As convert_setup(), but only when from_unicode_is_utf8 is TRUE will all
  258. +  * "from" unicode charsets be considered utf-8.  Same for "to".
  259. +  */
  260. +     int
  261. + convert_setup_ext(vcp, from, from_unicode_is_utf8, to, to_unicode_is_utf8)
  262. +     vimconv_T    *vcp;
  263. +     char_u    *from;
  264. +     int        from_unicode_is_utf8;
  265. +     char_u    *to;
  266. +     int        to_unicode_is_utf8;
  267. + {
  268.       int        from_prop;
  269.       int        to_prop;
  270. +     int        from_is_utf8;
  271. +     int        to_is_utf8;
  272.   
  273.       /* Reset to no conversion. */
  274.   # ifdef USE_ICONV
  275. ***************
  276. *** 5856,5892 ****
  277.   
  278.       from_prop = enc_canon_props(from);
  279.       to_prop = enc_canon_props(to);
  280. !     if ((from_prop & ENC_LATIN1) && (to_prop & ENC_UNICODE))
  281.       {
  282.       /* Internal latin1 -> utf-8 conversion. */
  283.       vcp->vc_type = CONV_TO_UTF8;
  284.       vcp->vc_factor = 2;    /* up to twice as long */
  285.       }
  286. !     else if ((from_prop & ENC_LATIN9) && (to_prop & ENC_UNICODE))
  287.       {
  288.       /* Internal latin9 -> utf-8 conversion. */
  289.       vcp->vc_type = CONV_9_TO_UTF8;
  290.       vcp->vc_factor = 3;    /* up to three as long (euro sign) */
  291.       }
  292. !     else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_LATIN1))
  293.       {
  294.       /* Internal utf-8 -> latin1 conversion. */
  295.       vcp->vc_type = CONV_TO_LATIN1;
  296.       }
  297. !     else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_LATIN9))
  298.       {
  299.       /* Internal utf-8 -> latin9 conversion. */
  300.       vcp->vc_type = CONV_TO_LATIN9;
  301.       }
  302.   #ifdef WIN3264
  303.       /* Win32-specific codepage <-> codepage conversion without iconv. */
  304. !     else if (((from_prop & ENC_UNICODE) || encname2codepage(from) > 0)
  305. !         && ((to_prop & ENC_UNICODE) || encname2codepage(to) > 0))
  306.       {
  307.       vcp->vc_type = CONV_CODEPAGE;
  308.       vcp->vc_factor = 2;    /* up to twice as long */
  309. !     vcp->vc_cpfrom = (from_prop & ENC_UNICODE) ? 0 : encname2codepage(from);
  310. !     vcp->vc_cpto = (to_prop & ENC_UNICODE) ? 0 : encname2codepage(to);
  311.       }
  312.   #endif
  313.   #ifdef MACOS_X
  314. --- 5878,5923 ----
  315.   
  316.       from_prop = enc_canon_props(from);
  317.       to_prop = enc_canon_props(to);
  318. !     if (from_unicode_is_utf8)
  319. !     from_is_utf8 = from_prop & ENC_UNICODE;
  320. !     else
  321. !     from_is_utf8 = from_prop == ENC_UNICODE;
  322. !     if (to_unicode_is_utf8)
  323. !     to_is_utf8 = to_prop & ENC_UNICODE;
  324. !     else
  325. !     to_is_utf8 = to_prop == ENC_UNICODE;
  326. !     if ((from_prop & ENC_LATIN1) && to_is_utf8)
  327.       {
  328.       /* Internal latin1 -> utf-8 conversion. */
  329.       vcp->vc_type = CONV_TO_UTF8;
  330.       vcp->vc_factor = 2;    /* up to twice as long */
  331.       }
  332. !     else if ((from_prop & ENC_LATIN9) && to_is_utf8)
  333.       {
  334.       /* Internal latin9 -> utf-8 conversion. */
  335.       vcp->vc_type = CONV_9_TO_UTF8;
  336.       vcp->vc_factor = 3;    /* up to three as long (euro sign) */
  337.       }
  338. !     else if (from_is_utf8 && (to_prop & ENC_LATIN1))
  339.       {
  340.       /* Internal utf-8 -> latin1 conversion. */
  341.       vcp->vc_type = CONV_TO_LATIN1;
  342.       }
  343. !     else if (from_is_utf8 && (to_prop & ENC_LATIN9))
  344.       {
  345.       /* Internal utf-8 -> latin9 conversion. */
  346.       vcp->vc_type = CONV_TO_LATIN9;
  347.       }
  348.   #ifdef WIN3264
  349.       /* Win32-specific codepage <-> codepage conversion without iconv. */
  350. !     else if ((from_is_utf8 || encname2codepage(from) > 0)
  351. !         && (to_is_utf8 || encname2codepage(to) > 0))
  352.       {
  353.       vcp->vc_type = CONV_CODEPAGE;
  354.       vcp->vc_factor = 2;    /* up to twice as long */
  355. !     vcp->vc_cpfrom = from_is_utf8 ? 0 : encname2codepage(from);
  356. !     vcp->vc_cpto = to_is_utf8 ? 0 : encname2codepage(to);
  357.       }
  358.   #endif
  359.   #ifdef MACOS_X
  360. ***************
  361. *** 5894,5900 ****
  362.       {
  363.       vcp->vc_type = CONV_MAC_LATIN1;
  364.       }
  365. !     else if ((from_prop & ENC_MACROMAN) && (to_prop & ENC_UNICODE))
  366.       {
  367.       vcp->vc_type = CONV_MAC_UTF8;
  368.       vcp->vc_factor = 2;    /* up to twice as long */
  369. --- 5925,5931 ----
  370.       {
  371.       vcp->vc_type = CONV_MAC_LATIN1;
  372.       }
  373. !     else if ((from_prop & ENC_MACROMAN) && to_is_utf8)
  374.       {
  375.       vcp->vc_type = CONV_MAC_UTF8;
  376.       vcp->vc_factor = 2;    /* up to twice as long */
  377. ***************
  378. *** 5903,5909 ****
  379.       {
  380.       vcp->vc_type = CONV_LATIN1_MAC;
  381.       }
  382. !     else if ((from_prop & ENC_UNICODE) && (to_prop & ENC_MACROMAN))
  383.       {
  384.       vcp->vc_type = CONV_UTF8_MAC;
  385.       }
  386. --- 5934,5940 ----
  387.       {
  388.       vcp->vc_type = CONV_LATIN1_MAC;
  389.       }
  390. !     else if (from_is_utf8 && (to_prop & ENC_MACROMAN))
  391.       {
  392.       vcp->vc_type = CONV_UTF8_MAC;
  393.       }
  394. ***************
  395. *** 5913,5920 ****
  396.       {
  397.       /* Use iconv() for conversion. */
  398.       vcp->vc_fd = (iconv_t)my_iconv_open(
  399. !         (to_prop & ENC_UNICODE) ? (char_u *)"utf-8" : to,
  400. !         (from_prop & ENC_UNICODE) ? (char_u *)"utf-8" : from);
  401.       if (vcp->vc_fd != (iconv_t)-1)
  402.       {
  403.           vcp->vc_type = CONV_ICONV;
  404. --- 5944,5951 ----
  405.       {
  406.       /* Use iconv() for conversion. */
  407.       vcp->vc_fd = (iconv_t)my_iconv_open(
  408. !         to_is_utf8 ? (char_u *)"utf-8" : to,
  409. !         from_is_utf8 ? (char_u *)"utf-8" : from);
  410.       if (vcp->vc_fd != (iconv_t)-1)
  411.       {
  412.           vcp->vc_type = CONV_ICONV;
  413. ***************
  414. *** 6170,6178 ****
  415.   
  416.   # ifdef USE_ICONV
  417.       case CONV_ICONV:    /* conversion with output_conv.vc_fd */
  418. !         retval = iconv_string(vcp, ptr, len, unconvlenp);
  419. !         if (retval != NULL && lenp != NULL)
  420. !         *lenp = (int)STRLEN(retval);
  421.           break;
  422.   # endif
  423.   # ifdef WIN3264
  424. --- 6201,6207 ----
  425.   
  426.   # ifdef USE_ICONV
  427.       case CONV_ICONV:    /* conversion with output_conv.vc_fd */
  428. !         retval = iconv_string(vcp, ptr, len, unconvlenp, lenp);
  429.           break;
  430.   # endif
  431.   # ifdef WIN3264
  432. *** ../vim-7.2.200/src/option.c    2009-05-17 13:30:58.000000000 +0200
  433. --- src/option.c    2009-06-12 21:09:51.000000000 +0200
  434. ***************
  435. *** 7024,7029 ****
  436. --- 7024,7030 ----
  437.       int        new_unnamed = FALSE;
  438.       int        new_autoselect = FALSE;
  439.       int        new_autoselectml = FALSE;
  440. +     int        new_html = FALSE;
  441.       regprog_T    *new_exclude_prog = NULL;
  442.       char_u    *errmsg = NULL;
  443.       char_u    *p;
  444. ***************
  445. *** 7047,7052 ****
  446. --- 7048,7058 ----
  447.           new_autoselectml = TRUE;
  448.           p += 12;
  449.       }
  450. +     else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
  451. +     {
  452. +         new_html = TRUE;
  453. +         p += 4;
  454. +     }
  455.       else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
  456.       {
  457.           p += 8;
  458. ***************
  459. *** 7068,7073 ****
  460. --- 7074,7080 ----
  461.       clip_unnamed = new_unnamed;
  462.       clip_autoselect = new_autoselect;
  463.       clip_autoselectml = new_autoselectml;
  464. +     clip_html = new_html;
  465.       vim_free(clip_exclude_prog);
  466.       clip_exclude_prog = new_exclude_prog;
  467.       }
  468. *** ../vim-7.2.200/src/version.c    2009-06-16 15:12:11.000000000 +0200
  469. --- src/version.c    2009-06-16 15:14:02.000000000 +0200
  470. ***************
  471. *** 678,679 ****
  472. --- 678,681 ----
  473.   {   /* Add new patch number below this line */
  474. + /**/
  475. +     201,
  476.   /**/
  477.  
  478. -- 
  479. How To Keep A Healthy Level Of Insanity:
  480. 13. Go to a poetry recital and ask why the poems don't rhyme.
  481.  
  482.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  483. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  484. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  485.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  486.