]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blame - vim/patches/vim-7.3.461.patch0
libpng: Update to 1.6.10.
[people/ms/ipfire-3.x.git] / vim / patches / vim-7.3.461.patch0
CommitLineData
c6060300
MT
1To: vim_dev@googlegroups.com
2Subject: Patch 7.3.461
3Fcc: outbox
4From: Bram Moolenaar <Bram@moolenaar.net>
5Mime-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8------------
9
10Patch 7.3.461
11Problem: The InsertCharPre autocommand event is not triggered during
12 completion and when typing several characters quickly.
13Solution: Also trigger InsertCharPre during completion. Do not read ahead
14 when an InsertCharPre autocommand is defined. (Yasuhiro Matsumoto)
15Files: src/edit.c, src/fileio.c, src/proto/fileio.pro
16
17
18*** ../vim-7.3.460/src/edit.c 2012-02-04 23:34:57.000000000 +0100
19--- src/edit.c 2012-02-29 18:17:31.000000000 +0100
20***************
21*** 259,264 ****
22--- 259,267 ----
23 static void ins_try_si __ARGS((int c));
24 #endif
25 static colnr_T get_nolist_virtcol __ARGS((void));
26+ #ifdef FEAT_AUTOCMD
27+ static char_u *do_insert_char_pre __ARGS((int c));
28+ #endif
29
30 static colnr_T Insstart_textlen; /* length of line when insert started */
31 static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
32***************
33*** 784,790 ****
34 * completion: Add to "compl_leader". */
35 if (ins_compl_accept_char(c))
36 {
37! ins_compl_addleader(c);
38 continue;
39 }
40
41--- 787,806 ----
42 * completion: Add to "compl_leader". */
43 if (ins_compl_accept_char(c))
44 {
45! #ifdef FEAT_AUTOCMD
46! /* Trigger InsertCharPre. */
47! char_u *str = do_insert_char_pre(c);
48! char_u *p;
49!
50! if (str != NULL)
51! {
52! for (p = str; *p != NUL; mb_ptr_adv(p))
53! ins_compl_addleader(PTR2CHAR(p));
54! vim_free(str);
55! }
56! else
57! #endif
58! ins_compl_addleader(c);
59 continue;
60 }
61
62***************
63*** 1393,1426 ****
64 #ifdef FEAT_AUTOCMD
65 if (!p_paste)
66 {
67! /* Trigger the InsertCharPre event. Lock the text to avoid
68! * weird things from happening. */
69! set_vim_var_char(c);
70! ++textlock;
71! if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL,
72! FALSE, curbuf))
73! {
74! /* Get the new value of v:char. If it is more than one
75! * character insert it literally. */
76! char_u *s = get_vim_var_str(VV_CHAR);
77! if (MB_CHARLEN(s) > 1)
78 {
79! if (stop_arrow() != FAIL)
80 {
81! ins_str(s);
82! AppendToRedobuffLit(s, -1);
83 }
84! c = NUL;
85 }
86! else
87! c = PTR2CHAR(s);
88 }
89
90! set_vim_var_string(VV_CHAR, NULL, -1);
91! --textlock;
92!
93! /* If the new value is an empty string then don't insert a
94! * char. */
95 if (c == NUL)
96 break;
97 }
98--- 1409,1439 ----
99 #ifdef FEAT_AUTOCMD
100 if (!p_paste)
101 {
102! /* Trigger InsertCharPre. */
103! char_u *str = do_insert_char_pre(c);
104! char_u *p;
105!
106! if (str != NULL)
107! {
108! if (*str != NUL && stop_arrow() != FAIL)
109 {
110! /* Insert the new value of v:char literally. */
111! for (p = str; *p != NUL; mb_ptr_adv(p))
112 {
113! c = PTR2CHAR(p);
114! if (c == CAR || c == K_KENTER || c == NL)
115! ins_eol(c);
116! else
117! ins_char(c);
118 }
119! AppendToRedobuffLit(str, -1);
120 }
121! vim_free(str);
122! c = NUL;
123 }
124
125! /* If the new value is already inserted or an empty string
126! * then don't insert any character. */
127 if (c == NUL)
128 break;
129 }
130***************
131*** 5883,5888 ****
132--- 5896,5903 ----
133 * Don't do this when 'cindent' or 'indentexpr' is set, because we might
134 * need to re-indent at a ':', or any other character (but not what
135 * 'paste' is set)..
136+ * Don't do this when there an InsertCharPre autocommand is defined,
137+ * because we need to fire the event for every character.
138 */
139 #ifdef USE_ON_FLY_SCROLL
140 dont_scroll = FALSE; /* allow scrolling here */
141***************
142*** 5900,5905 ****
143--- 5915,5923 ----
144 #ifdef FEAT_RIGHTLEFT
145 && !p_ri
146 #endif
147+ #ifdef FEAT_AUTOCMD
148+ && !has_insertcharpre()
149+ #endif
150 )
151 {
152 #define INPUT_BUFLEN 100
153***************
154*** 10068,10070 ****
155--- 10086,10123 ----
156 validate_virtcol();
157 return curwin->w_virtcol;
158 }
159+
160+ #ifdef FEAT_AUTOCMD
161+ /*
162+ * Handle the InsertCharPre autocommand.
163+ * "c" is the character that was typed.
164+ * Return a pointer to allocated memory with the replacement string.
165+ * Return NULL to continue inserting "c".
166+ */
167+ static char_u *
168+ do_insert_char_pre(c)
169+ int c;
170+ {
171+ char_u *res;
172+
173+ /* Return quickly when there is nothing to do. */
174+ if (!has_insertcharpre())
175+ return NULL;
176+
177+ /* Lock the text to avoid weird things from happening. */
178+ ++textlock;
179+ set_vim_var_char(c); /* set v:char */
180+
181+ if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL, FALSE, curbuf))
182+ /* Get the new value of v:char. It may be empty or more than one
183+ * character. */
184+ res = vim_strsave(get_vim_var_str(VV_CHAR));
185+ else
186+ res = NULL;
187+
188+ set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */
189+ --textlock;
190+
191+ return res;
192+ }
193+ #endif
194*** ../vim-7.3.460/src/fileio.c 2012-02-12 20:13:55.000000000 +0100
195--- src/fileio.c 2012-02-29 17:50:32.000000000 +0100
196***************
197*** 9116,9121 ****
198--- 9116,9130 ----
199 return (first_autopat[(int)EVENT_CURSORMOVEDI] != NULL);
200 }
201
202+ /*
203+ * Return TRUE when there is an InsertCharPre autocommand defined.
204+ */
205+ int
206+ has_insertcharpre()
207+ {
208+ return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL);
209+ }
210+
211 static int
212 apply_autocmds_group(event, fname, fname_io, force, group, buf, eap)
213 event_T event;
214*** ../vim-7.3.460/src/proto/fileio.pro 2012-02-12 20:13:55.000000000 +0100
215--- src/proto/fileio.pro 2012-02-29 17:50:38.000000000 +0100
216***************
217*** 44,49 ****
218--- 44,50 ----
219 int trigger_cursorhold __ARGS((void));
220 int has_cursormoved __ARGS((void));
221 int has_cursormovedI __ARGS((void));
222+ int has_insertcharpre __ARGS((void));
223 void block_autocmds __ARGS((void));
224 void unblock_autocmds __ARGS((void));
225 int has_autocmd __ARGS((event_T event, char_u *sfname, buf_T *buf));
226*** ../vim-7.3.460/src/version.c 2012-02-29 16:56:35.000000000 +0100
227--- src/version.c 2012-02-29 18:15:34.000000000 +0100
228***************
229*** 716,717 ****
230--- 716,719 ----
231 { /* Add new patch number below this line */
232+ /**/
233+ 461,
234 /**/
235
236--
237"Computers in the future may weigh no more than 1.5 tons."
238 Popular Mechanics, 1949
239
240 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
241/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
242\\\ an exciting new programming language -- http://www.Zimbu.org ///
243 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///