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 / 6.2.428 < prev    next >
Encoding:
Internet Message Format  |  2004-04-01  |  10.9 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.2.428
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. CORRECTED PATCH: chunk in gui_gtk_x11.c was removed, it didn't belong here.
  11.  
  12. Patch 6.2.428
  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
  19.  
  20.  
  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
  23. ***************
  24. *** 102,108 ****
  25.       TARGET_TEXT,
  26.       TARGET_TEXT_URI_LIST,
  27.       TARGET_TEXT_PLAIN,
  28. !     TARGET_VIM
  29.   };
  30.   
  31.   /*
  32. --- 102,109 ----
  33.       TARGET_TEXT,
  34.       TARGET_TEXT_URI_LIST,
  35.       TARGET_TEXT_PLAIN,
  36. !     TARGET_VIM,
  37. !     TARGET_VIMENC
  38.   };
  39.   
  40.   /*
  41. ***************
  42. *** 111,116 ****
  43. --- 112,118 ----
  44.    */
  45.   static const GtkTargetEntry selection_targets[] =
  46.   {
  47. +     {VIMENC_ATOM_NAME,    0, TARGET_VIMENC},
  48.       {VIM_ATOM_NAME,    0, TARGET_VIM},
  49.   #ifdef FEAT_MBYTE
  50.       {"UTF8_STRING",    0, TARGET_UTF8_STRING},
  51. ***************
  52. *** 175,180 ****
  53. --- 177,185 ----
  54.   static GdkAtom text_atom = GDK_NONE;
  55.   #endif
  56.   static GdkAtom vim_atom = GDK_NONE;    /* Vim's own special selection format */
  57. + #ifdef FEAT_MBYTE
  58. + static GdkAtom vimenc_atom = GDK_NONE;    /* Vim's extended selection format */
  59. + #endif
  60.   
  61.   /*
  62.    * Keycodes recognized by vim.
  63. ***************
  64. *** 1244,1249 ****
  65. --- 1255,1288 ----
  66.       motion_type = *text++;
  67.       --len;
  68.       }
  69. + #ifdef FEAT_MBYTE
  70. +     else if (data->type == vimenc_atom)
  71. +     {
  72. +     char_u        *enc;
  73. +     vimconv_T    conv;
  74. +     motion_type = *text++;
  75. +     --len;
  76. +     enc = text;
  77. +     text += STRLEN(text) + 1;
  78. +     len -= text - enc;
  79. +     /* If the encoding of the text is different from 'encoding', attempt
  80. +      * converting it. */
  81. +     conv.vc_type = CONV_NONE;
  82. +     convert_setup(&conv, enc, p_enc);
  83. +     if (conv.vc_type != CONV_NONE)
  84. +     {
  85. +         tmpbuf = string_convert(&conv, text, &len);
  86. +         if (tmpbuf != NULL)
  87. +         text = tmpbuf;
  88. +         convert_setup(&conv, NULL, NULL);
  89. +     }
  90. +     }
  91. + #endif
  92.   #ifdef HAVE_GTK2
  93.       /* gtk_selection_data_get_text() handles all the nasty details
  94.        * and targets and encodings etc.  This rocks so hard. */
  95. ***************
  96. *** 1351,1356 ****
  97. --- 1390,1396 ----
  98.       if (info != (guint)TARGET_STRING
  99.   #ifdef FEAT_MBYTE
  100.           && info != (guint)TARGET_UTF8_STRING
  101. +         && info != (guint)TARGET_VIMENC
  102.   #endif
  103.           && info != (guint)TARGET_VIM
  104.           && info != (guint)TARGET_COMPOUND_TEXT
  105. ***************
  106. *** 1382,1387 ****
  107. --- 1422,1448 ----
  108.       string = tmpbuf;
  109.       type = vim_atom;
  110.       }
  111. + #ifdef FEAT_MBYTE
  112. +     else if (info == (guint)TARGET_VIMENC)
  113. +     {
  114. +     int l = STRLEN(p_enc);
  115. +     /* contents: motion_type 'encoding' NUL text */
  116. +     tmpbuf = alloc((unsigned)length + l + 2);
  117. +     if (tmpbuf != NULL)
  118. +     {
  119. +         tmpbuf[0] = motion_type;
  120. +         STRCPY(tmpbuf + 1, p_enc);
  121. +         mch_memmove(tmpbuf + l + 2, string, (size_t)length);
  122. +     }
  123. +     length += l + 2;
  124. +     vim_free(string);
  125. +     string = tmpbuf;
  126. +     type = vimenc_atom;
  127. +     }
  128. + #endif
  129.   #ifdef HAVE_GTK2
  130.       /* gtk_selection_data_set_text() handles everything for us.  This is
  131.        * so easy and simple and cool, it'd be insane not to use it. */
  132. ***************
  133. *** 3180,3185 ****
  134. --- 3241,3249 ----
  135.        * Set clipboard specific atoms
  136.        */
  137.       vim_atom = gdk_atom_intern(VIM_ATOM_NAME, FALSE);
  138. + #ifdef FEAT_MBYTE
  139. +     vimenc_atom = gdk_atom_intern(VIMENC_ATOM_NAME, FALSE);
  140. + #endif
  141.       clip_star.gtk_sel_atom = GDK_SELECTION_PRIMARY;
  142.       clip_plus.gtk_sel_atom = gdk_atom_intern("CLIPBOARD", FALSE);
  143.   
  144. ***************
  145. *** 5128,5134 ****
  146.       char_u *p;
  147.   
  148.       for (p = s; p < s + len; ++p)
  149. !         if (*p & 0x80) goto not_ascii;
  150.   
  151.       pango_glyph_string_set_size(glyphs, len);
  152.   
  153. --- 5188,5195 ----
  154.       char_u *p;
  155.   
  156.       for (p = s; p < s + len; ++p)
  157. !         if (*p & 0x80)
  158. !         goto not_ascii;
  159.   
  160.       pango_glyph_string_set_size(glyphs, len);
  161.   
  162. *** ../vim-6.2.427/src/ui.c    Fri Apr  2 11:36:09 2004
  163. --- src/ui.c    Fri Apr  2 12:51:57 2004
  164. ***************
  165. *** 1913,1918 ****
  166. --- 1913,1921 ----
  167.   }
  168.   
  169.   static Atom    vim_atom;    /* Vim's own special selection format */
  170. + #ifdef FEAT_MBYTE
  171. + static Atom    vimenc_atom;    /* Vim's extended selection format */
  172. + #endif
  173.   static Atom    compound_text_atom;
  174.   static Atom    text_atom;
  175.   static Atom    targets_atom;
  176. ***************
  177. *** 1922,1927 ****
  178. --- 1925,1933 ----
  179.       Display    *dpy;
  180.   {
  181.       vim_atom           = XInternAtom(dpy, VIM_ATOM_NAME,   False);
  182. + #ifdef FEAT_MBYTE
  183. +     vimenc_atom           = XInternAtom(dpy, VIMENC_ATOM_NAME,False);
  184. + #endif
  185.       compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False);
  186.       text_atom           = XInternAtom(dpy, "TEXT",       False);
  187.       targets_atom       = XInternAtom(dpy, "TARGETS",       False);
  188. ***************
  189. *** 1952,1957 ****
  190. --- 1958,1966 ----
  191.       char_u    *p;
  192.       char    **text_list = NULL;
  193.       VimClipboard    *cbd;
  194. + #ifdef FEAT_MBYTE
  195. +     char_u    *tmpbuf = NULL;
  196. + #endif
  197.   
  198.       if (*sel_atom == clip_plus.sel_atom)
  199.       cbd = &clip_plus;
  200. ***************
  201. *** 1972,1977 ****
  202. --- 1981,2017 ----
  203.       motion_type = *p++;
  204.       len--;
  205.       }
  206. + #ifdef FEAT_MBYTE
  207. +     else if (*type == vimenc_atom)
  208. +     {
  209. +     char_u        *enc;
  210. +     vimconv_T    conv;
  211. +     int        convlen;
  212. +     motion_type = *p++;
  213. +     --len;
  214. +     enc = p;
  215. +     p += STRLEN(p) + 1;
  216. +     len -= p - enc;
  217. +     /* If the encoding of the text is different from 'encoding', attempt
  218. +      * converting it. */
  219. +     conv.vc_type = CONV_NONE;
  220. +     convert_setup(&conv, enc, p_enc);
  221. +     if (conv.vc_type != CONV_NONE)
  222. +     {
  223. +         convlen = len;    /* Need to use an int here. */
  224. +         tmpbuf = string_convert(&conv, p, &convlen);
  225. +         len = convlen;
  226. +         if (tmpbuf != NULL)
  227. +         p = tmpbuf;
  228. +         convert_setup(&conv, NULL, NULL);
  229. +     }
  230. +     }
  231. + #endif
  232.       else if (*type == compound_text_atom || (
  233.   #ifdef FEAT_MBYTE
  234.           enc_dbcs != 0 &&
  235. ***************
  236. *** 2000,2006 ****
  237.   
  238.       if (text_list != NULL)
  239.       XFreeStringList(text_list);
  240.       XtFree((char *)value);
  241.       *(int *)success = TRUE;
  242.   }
  243. --- 2040,2048 ----
  244.   
  245.       if (text_list != NULL)
  246.       XFreeStringList(text_list);
  247. ! #ifdef FEAT_MBYTE
  248. !     vim_free(tmpbuf);
  249. ! #endif
  250.       XtFree((char *)value);
  251.       *(int *)success = TRUE;
  252.   }
  253. ***************
  254. *** 2018,2030 ****
  255.       int        nbytes = 0;
  256.       char_u    *buffer;
  257.   
  258. !     for (i = 0; i < 4; i++)
  259.       {
  260.       switch (i)
  261.       {
  262. !         case 0:  type = vim_atom;    break;
  263. !         case 1:  type = compound_text_atom; break;
  264. !         case 2:  type = text_atom;    break;
  265.           default: type = XA_STRING;
  266.       }
  267.       XtGetSelectionValue(myShell, cbd->sel_atom, type,
  268. --- 2060,2081 ----
  269.       int        nbytes = 0;
  270.       char_u    *buffer;
  271.   
  272. !     for (i =
  273. ! #ifdef FEAT_MBYTE
  274. !         0
  275. ! #else
  276. !         1
  277. ! #endif
  278. !         ; i < 5; i++)
  279.       {
  280.       switch (i)
  281.       {
  282. ! #ifdef FEAT_MBYTE
  283. !         case 0:  type = vimenc_atom;    break;
  284. ! #endif
  285. !         case 1:  type = vim_atom;        break;
  286. !         case 2:  type = compound_text_atom; break;
  287. !         case 3:  type = text_atom;        break;
  288.           default: type = XA_STRING;
  289.       }
  290.       XtGetSelectionValue(myShell, cbd->sel_atom, type,
  291. ***************
  292. *** 2084,2089 ****
  293. --- 2138,2144 ----
  294.       char_u    *result;
  295.       int        motion_type;
  296.       VimClipboard    *cbd;
  297. +     int        i;
  298.   
  299.       if (*sel_atom == clip_plus.sel_atom)
  300.       cbd = &clip_plus;
  301. ***************
  302. *** 2098,2120 ****
  303.       {
  304.       Atom *array;
  305.   
  306. !     if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 5))) == NULL)
  307.           return False;
  308.       *value = (XtPointer)array;
  309. !     array[0] = XA_STRING;
  310. !     array[1] = targets_atom;
  311. !     array[2] = vim_atom;
  312. !     array[3] = text_atom;
  313. !     array[4] = compound_text_atom;
  314.       *type = XA_ATOM;
  315.       /* This used to be: *format = sizeof(Atom) * 8; but that caused
  316.        * crashes on 64 bit machines. (Peter Derr) */
  317.       *format = 32;
  318. !     *length = 5;
  319.       return True;
  320.       }
  321.   
  322.       if (       *target != XA_STRING
  323.           && *target != vim_atom
  324.           && *target != text_atom
  325.           && *target != compound_text_atom)
  326. --- 2153,2182 ----
  327.       {
  328.       Atom *array;
  329.   
  330. !     if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 6))) == NULL)
  331.           return False;
  332.       *value = (XtPointer)array;
  333. !     i = 0;
  334. !     array[i++] = XA_STRING;
  335. !     array[i++] = targets_atom;
  336. ! #ifdef FEAT_MBYTE
  337. !     array[i++] = vimenc_atom;
  338. ! #endif
  339. !     array[i++] = vim_atom;
  340. !     array[i++] = text_atom;
  341. !     array[i++] = compound_text_atom;
  342.       *type = XA_ATOM;
  343.       /* This used to be: *format = sizeof(Atom) * 8; but that caused
  344.        * crashes on 64 bit machines. (Peter Derr) */
  345.       *format = 32;
  346. !     *length = i;
  347.       return True;
  348.       }
  349.   
  350.       if (       *target != XA_STRING
  351. + #ifdef FEAT_MBYTE
  352. +         && *target != vimenc_atom
  353. + #endif
  354.           && *target != vim_atom
  355.           && *target != text_atom
  356.           && *target != compound_text_atom)
  357. ***************
  358. *** 2129,2134 ****
  359. --- 2191,2202 ----
  360.       if (*target == vim_atom)
  361.       (*length)++;
  362.   
  363. + #ifdef FEAT_MBYTE
  364. +     /* Our own format with encoding: motion 'encoding' NUL text */
  365. +     if (*target == vimenc_atom)
  366. +     *length += STRLEN(p_enc) + 2;
  367. + #endif
  368.       *value = XtMalloc((Cardinal)*length);
  369.       result = (char_u *)*value;
  370.       if (result == NULL)
  371. ***************
  372. *** 2159,2164 ****
  373. --- 2227,2245 ----
  374.       *length = text_prop.nitems;
  375.       *type = compound_text_atom;
  376.       }
  377. + #ifdef FEAT_MBYTE
  378. +     else if (*target == vimenc_atom)
  379. +     {
  380. +     int l = STRLEN(p_enc);
  381. +     result[0] = motion_type;
  382. +     STRCPY(result + 1, p_enc);
  383. +     mch_memmove(result + l + 2, string, (size_t)(*length - l - 2));
  384. +     *type = vimenc_atom;
  385. +     }
  386. + #endif
  387.       else
  388.       {
  389.       result[0] = motion_type;
  390. *** ../vim-6.2.427/src/vim.h    Thu Mar 18 14:39:31 2004
  391. --- src/vim.h    Fri Apr  2 12:34:09 2004
  392. ***************
  393. *** 1473,1480 ****
  394.   
  395.   #ifdef FEAT_CLIPBOARD
  396.   
  397. ! /* Vim-specific selection type for X11 */
  398.   #define VIM_ATOM_NAME "_VIM_TEXT"
  399.   
  400.   /* Selection states for modeless selection */
  401.   # define SELECT_CLEARED        0
  402. --- 1473,1483 ----
  403.   
  404.   #ifdef FEAT_CLIPBOARD
  405.   
  406. ! /* VIM_ATOM_NAME is the older Vim-specific selection type for X11.  Still
  407. !  * supported for when a mix of Vim versions is used. VIMENC_ATOM_NAME includes
  408. !  * the encoding to support Vims using different 'encoding' values. */
  409.   #define VIM_ATOM_NAME "_VIM_TEXT"
  410. + #define VIMENC_ATOM_NAME "_VIMENC_TEXT"
  411.   
  412.   /* Selection states for modeless selection */
  413.   # define SELECT_CLEARED        0
  414. *** ../vim-6.2.427/src/version.c    Fri Apr  2 11:36:09 2004
  415. --- src/version.c    Fri Apr  2 14:05:46 2004
  416. ***************
  417. *** 639,640 ****
  418. --- 639,642 ----
  419.   {   /* Add new patch number below this line */
  420. + /**/
  421. +     428,
  422.   /**/
  423.  
  424. -- 
  425. You can tune a file system, but you can't tuna fish
  426.                             -- man tunefs
  427.  
  428.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  429. ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  430. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  431.  \\\  Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
  432.