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.221 < prev    next >
Encoding:
Internet Message Format  |  2009-06-30  |  6.9 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.221
  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.221
  11. Problem:    X cut_buffer0 text is used as-is, it may be in the wrong encoding.
  12. Solution:   Convert between 'enc' and latin1. (James Vega)
  13. Files:        src/gui_gtk_x11.c, src/message.c, src/ops.c, src/proto/ui.pro,
  14.         src/ui.c
  15.  
  16.  
  17. *** ../vim-7.2.220/src/gui_gtk_x11.c    2009-06-16 15:23:07.000000000 +0200
  18. --- src/gui_gtk_x11.c    2009-07-01 11:55:34.000000000 +0200
  19. ***************
  20. *** 6717,6724 ****
  21.   {
  22.       GdkAtom    target;
  23.       unsigned    i;
  24. -     int        nbytes;
  25. -     char_u    *buffer;
  26.       time_t    start;
  27.   
  28.       for (i = 0; i < N_SELECTION_TARGETS; ++i)
  29. --- 6717,6722 ----
  30. ***************
  31. *** 6746,6767 ****
  32.       }
  33.   
  34.       /* Final fallback position - use the X CUT_BUFFER0 store */
  35. !     nbytes = 0;
  36. !     buffer = (char_u *)XFetchBuffer(GDK_WINDOW_XDISPLAY(gui.mainwin->window),
  37. !                     &nbytes, 0);
  38. !     if (nbytes > 0)
  39. !     {
  40. !     /* Got something */
  41. !     clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
  42. !     if (p_verbose > 0)
  43. !     {
  44. !         verbose_enter();
  45. !         smsg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
  46. !         verbose_leave();
  47. !     }
  48. !     }
  49. !     if (buffer != NULL)
  50. !     XFree(buffer);
  51.   }
  52.   
  53.   /*
  54. --- 6744,6750 ----
  55.       }
  56.   
  57.       /* Final fallback position - use the X CUT_BUFFER0 store */
  58. !     yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gui.mainwin->window), cbd);
  59.   }
  60.   
  61.   /*
  62. *** ../vim-7.2.220/src/message.c    2009-05-17 13:30:58.000000000 +0200
  63. --- src/message.c    2009-07-01 16:43:08.000000000 +0200
  64. ***************
  65. *** 107,113 ****
  66.   }
  67.   
  68.   #if defined(FEAT_EVAL) || defined(FEAT_X11) || defined(USE_XSMP) \
  69. !     || defined(PROTO)
  70.   /*
  71.    * Like msg() but keep it silent when 'verbosefile' is set.
  72.    */
  73. --- 107,113 ----
  74.   }
  75.   
  76.   #if defined(FEAT_EVAL) || defined(FEAT_X11) || defined(USE_XSMP) \
  77. !     || defined(FEAT_GUI_GTK) || defined(PROTO)
  78.   /*
  79.    * Like msg() but keep it silent when 'verbosefile' is set.
  80.    */
  81. *** ../vim-7.2.220/src/ops.c    2009-05-26 18:12:13.000000000 +0200
  82. --- src/ops.c    2009-07-01 12:15:31.000000000 +0200
  83. ***************
  84. *** 5591,5596 ****
  85. --- 5591,5619 ----
  86.       if (dpy != NULL && str != NULL && motion_type >= 0
  87.                              && len < 1024*1024 && len > 0)
  88.       {
  89. + #ifdef FEAT_MBYTE
  90. +     /* The CUT_BUFFER0 is supposed to always contain latin1.  Convert from
  91. +      * 'enc' when it is a multi-byte encoding.  When 'enc' is an 8-bit
  92. +      * encoding conversion usually doesn't work, so keep the text as-is.
  93. +      */
  94. +     if (has_mbyte)
  95. +     {
  96. +         char_u    *conv_str = str;
  97. +         vimconv_T    vc;
  98. +         vc.vc_type = CONV_NONE;
  99. +         if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK)
  100. +         {
  101. +         conv_str = string_convert(&vc, str, (int*)&len);
  102. +         if (conv_str != NULL)
  103. +         {
  104. +             vim_free(str);
  105. +             str = conv_str;
  106. +         }
  107. +         convert_setup(&vc, NULL, NULL);
  108. +         }
  109. +     }
  110. + #endif
  111.       XStoreBuffer(dpy, (char *)str, (int)len, 0);
  112.       XFlush(dpy);
  113.       }
  114. *** ../vim-7.2.220/src/proto/ui.pro    2007-05-05 19:58:49.000000000 +0200
  115. --- src/proto/ui.pro    2009-07-01 11:48:11.000000000 +0200
  116. ***************
  117. *** 48,53 ****
  118. --- 48,54 ----
  119.   void open_app_context __ARGS((void));
  120.   void x11_setup_atoms __ARGS((Display *dpy));
  121.   void clip_x11_request_selection __ARGS((Widget myShell, Display *dpy, VimClipboard *cbd));
  122. + void yank_cut_buffer0 __ARGS((Display *dpy, VimClipboard *cbd));
  123.   void clip_x11_lose_selection __ARGS((Widget myShell, VimClipboard *cbd));
  124.   int clip_x11_own_selection __ARGS((Widget myShell, VimClipboard *cbd));
  125.   void clip_x11_set_selection __ARGS((VimClipboard *cbd));
  126. *** ../vim-7.2.220/src/ui.c    2009-05-17 13:30:58.000000000 +0200
  127. --- src/ui.c    2009-07-01 15:44:07.000000000 +0200
  128. ***************
  129. *** 2104,2111 ****
  130.       Atom    type;
  131.       static int    success;
  132.       int        i;
  133. -     int        nbytes = 0;
  134. -     char_u    *buffer;
  135.       time_t    start_time;
  136.       int        timed_out = FALSE;
  137.   
  138. --- 2104,2109 ----
  139. ***************
  140. *** 2185,2199 ****
  141.       }
  142.   
  143.       /* Final fallback position - use the X CUT_BUFFER0 store */
  144. !     buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0);
  145. !     if (nbytes > 0)
  146. !     {
  147. !     /* Got something */
  148. !     clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
  149. !     XFree((void *)buffer);
  150. !     if (p_verbose > 0)
  151. !         verb_msg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
  152. !     }
  153.   }
  154.   
  155.   static Boolean    clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *));
  156. --- 2183,2189 ----
  157.       }
  158.   
  159.       /* Final fallback position - use the X CUT_BUFFER0 store */
  160. !     yank_cut_buffer0(dpy, cbd);
  161.   }
  162.   
  163.   static Boolean    clip_x11_convert_selection_cb __ARGS((Widget, Atom *, Atom *, Atom *, XtPointer *, long_u *, int *));
  164. ***************
  165. *** 2369,2374 ****
  166. --- 2359,2418 ----
  167.   }
  168.   #endif
  169.   
  170. + #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) \
  171. +     || defined(FEAT_GUI_GTK) || defined(PROTO)
  172. + /*
  173. +  * Get the contents of the X CUT_BUFFER0 and put it in "cbd".
  174. +  */
  175. +     void
  176. + yank_cut_buffer0(dpy, cbd)
  177. +     Display        *dpy;
  178. +     VimClipboard    *cbd;
  179. + {
  180. +     int        nbytes = 0;
  181. +     char_u    *buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0);
  182. +     if (nbytes > 0)
  183. +     {
  184. + #ifdef FEAT_MBYTE
  185. +     int  done = FALSE;
  186. +     /* CUT_BUFFER0 is supposed to be always latin1.  Convert to 'enc' when
  187. +      * using a multi-byte encoding.  Conversion between two 8-bit
  188. +      * character sets usually fails and the text might actually be in
  189. +      * 'enc' anyway. */
  190. +     if (has_mbyte)
  191. +     {
  192. +         char_u    *conv_buf = buffer;
  193. +         vimconv_T    vc;
  194. +         vc.vc_type = CONV_NONE;
  195. +         if (convert_setup(&vc, (char_u *)"latin1", p_enc) == OK)
  196. +         {
  197. +         conv_buf = string_convert(&vc, buffer, &nbytes);
  198. +         if (conv_buf != NULL)
  199. +         {
  200. +             clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd);
  201. +             vim_free(conv_buf);
  202. +             done = TRUE;
  203. +         }
  204. +         convert_setup(&vc, NULL, NULL);
  205. +         }
  206. +     }
  207. +     if (!done)  /* use the text without conversion */
  208. + #endif
  209. +         clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
  210. +     XFree((void *)buffer);
  211. +     if (p_verbose > 0)
  212. +     {
  213. +         verbose_enter();
  214. +         verb_msg((char_u *)_("Used CUT_BUFFER0 instead of empty selection"));
  215. +         verbose_leave();
  216. +     }
  217. +     }
  218. + }
  219. + #endif
  220.   #if defined(FEAT_MOUSE) || defined(PROTO)
  221.   
  222.   /*
  223. *** ../vim-7.2.220/src/version.c    2009-07-01 17:11:40.000000000 +0200
  224. --- src/version.c    2009-07-01 17:56:02.000000000 +0200
  225. ***************
  226. *** 678,679 ****
  227. --- 678,681 ----
  228.   {   /* Add new patch number below this line */
  229. + /**/
  230. +     221,
  231.   /**/
  232.  
  233. -- 
  234. hundred-and-one symptoms of being an internet addict:
  235. 40. You tell the cab driver you live at
  236.     http://123.elm.street/house/bluetrim.html
  237. 41. You actually try that 123.elm.street address.
  238.  
  239.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  240. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  241. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  242.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  243.