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