]> git.pld-linux.org Git - packages/vim.git/blame - 6.2.184
- use new bonobo patch (20040115)
[packages/vim.git] / 6.2.184
CommitLineData
d02ad552
AG
1To: vim-dev@vim.org
2Subject: Patch 6.2.184
3Fcc: outbox
4From: Bram Moolenaar <Bram@moolenaar.net>
5Mime-Version: 1.0
6Content-Type: text/plain; charset=ISO-8859-1
7Content-Transfer-Encoding: 8bit
8------------
9
10Patch 6.2.184
11Problem: With 'formatoptions' set to "1aw" inserting text may cause the
12 paragraph to be ended. (Alan Schmitt)
13Solution: Temporarily add an extra space to make the paragraph continue
14 after moving the word after the cursor to the next line.
15 Also format when pressing Esc.
16Files: src/edit.c, src/normal.c, src/proto/edit.pro
17
18
19*** ../vim-6.2.183/src/edit.c Sun Nov 9 20:26:53 2003
20--- src/edit.c Sun Jan 18 20:23:49 2004
21***************
22*** 121,132 ****
23 static void ins_ctrl_v __ARGS((void));
24 static void undisplay_dollar __ARGS((void));
25 static void insert_special __ARGS((int, int, int));
26 #ifdef FEAT_COMMENTS
27 static int cmplen __ARGS((char_u *s1, char_u *s2));
28 #endif
29 static void redo_literal __ARGS((int c));
30 static void start_arrow __ARGS((pos_T *end_insert_pos));
31! static void stop_insert __ARGS((pos_T *end_insert_pos));
32 static int echeck_abbr __ARGS((int));
33 static void replace_push_off __ARGS((int c));
34 static int replace_pop __ARGS((void));
35--- 121,133 ----
36 static void ins_ctrl_v __ARGS((void));
37 static void undisplay_dollar __ARGS((void));
38 static void insert_special __ARGS((int, int, int));
39+ static void check_auto_format __ARGS((int));
40 #ifdef FEAT_COMMENTS
41 static int cmplen __ARGS((char_u *s1, char_u *s2));
42 #endif
43 static void redo_literal __ARGS((int c));
44 static void start_arrow __ARGS((pos_T *end_insert_pos));
45! static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
46 static int echeck_abbr __ARGS((int));
47 static void replace_push_off __ARGS((int c));
48 static int replace_pop __ARGS((void));
49***************
50*** 195,204 ****
51 static int old_indent = 0; /* for ^^D command in insert mode */
52
53 #ifdef FEAT_RIGHTLEFT
54! int revins_on; /* reverse insert mode on */
55! int revins_chars; /* how much to skip after edit */
56! int revins_legal; /* was the last char 'legal'? */
57! int revins_scol; /* start column of revins session */
58 #endif
59
60 #if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
61--- 196,205 ----
62 static int old_indent = 0; /* for ^^D command in insert mode */
63
64 #ifdef FEAT_RIGHTLEFT
65! int revins_on; /* reverse insert mode on */
66! int revins_chars; /* how much to skip after edit */
67! int revins_legal; /* was the last char 'legal'? */
68! int revins_scol; /* start column of revins session */
69 #endif
70
71 #if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
72***************
73*** 209,214 ****
74--- 210,218 ----
75 char. Set when edit() is called.
76 after that arrow_used is used. */
77
78+ static int did_add_space = FALSE; /* auto_format() added an extra space
79+ under the cursor */
80+
81 /*
82 * edit(): Start inserting text.
83 *
84***************
85*** 866,872 ****
86 /* insert the contents of a register */
87 case Ctrl_R:
88 ins_reg();
89! auto_format();
90 inserted_space = FALSE;
91 break;
92
93--- 870,876 ----
94 /* insert the contents of a register */
95 case Ctrl_R:
96 ins_reg();
97! auto_format(FALSE);
98 inserted_space = FALSE;
99 break;
100
101***************
102*** 961,967 ****
103 }
104 # endif
105 ins_shift(c, lastc);
106! auto_format();
107 inserted_space = FALSE;
108 break;
109
110--- 965,971 ----
111 }
112 # endif
113 ins_shift(c, lastc);
114! auto_format(FALSE);
115 inserted_space = FALSE;
116 break;
117
118***************
119*** 969,994 ****
120 case K_DEL:
121 case K_KDEL:
122 ins_del();
123! auto_format();
124 break;
125
126 /* delete character before the cursor */
127 case K_BS:
128 case Ctrl_H:
129 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
130! auto_format();
131 break;
132
133 /* delete word before the cursor */
134 case Ctrl_W:
135 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
136! auto_format();
137 break;
138
139 /* delete all inserted text in current line */
140 case Ctrl_U:
141 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
142! auto_format();
143 inserted_space = FALSE;
144 break;
145
146--- 973,998 ----
147 case K_DEL:
148 case K_KDEL:
149 ins_del();
150! auto_format(FALSE);
151 break;
152
153 /* delete character before the cursor */
154 case K_BS:
155 case Ctrl_H:
156 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
157! auto_format(FALSE);
158 break;
159
160 /* delete word before the cursor */
161 case Ctrl_W:
162 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
163! auto_format(FALSE);
164 break;
165
166 /* delete all inserted text in current line */
167 case Ctrl_U:
168 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
169! auto_format(FALSE);
170 inserted_space = FALSE;
171 break;
172
173***************
174*** 1111,1117 ****
175 inserted_space = FALSE;
176 if (ins_tab())
177 goto normalchar; /* insert TAB as a normal char */
178! auto_format();
179 break;
180
181 case K_KENTER:
182--- 1115,1121 ----
183 inserted_space = FALSE;
184 if (ins_tab())
185 goto normalchar; /* insert TAB as a normal char */
186! auto_format(FALSE);
187 break;
188
189 case K_KENTER:
190***************
191*** 1138,1144 ****
192 #endif
193 if (ins_eol(c) && !p_im)
194 goto doESCkey; /* out of memory */
195! auto_format();
196 inserted_space = FALSE;
197 break;
198
199--- 1142,1148 ----
200 #endif
201 if (ins_eol(c) && !p_im)
202 goto doESCkey; /* out of memory */
203! auto_format(FALSE);
204 inserted_space = FALSE;
205 break;
206
207***************
208*** 1252,1258 ****
209 revins_legal++;
210 #endif
211 c = Ctrl_V; /* pretend CTRL-V is last character */
212! auto_format();
213 }
214 }
215 break;
216--- 1256,1262 ----
217 revins_legal++;
218 #endif
219 c = Ctrl_V; /* pretend CTRL-V is last character */
220! auto_format(FALSE);
221 }
222 }
223 break;
224***************
225*** 1299,1305 ****
226 #endif
227 }
228
229! auto_format();
230
231 #ifdef FEAT_FOLDING
232 /* When inserting a character the cursor line must never be in a
233--- 1303,1309 ----
234 #endif
235 }
236
237! auto_format(FALSE);
238
239 #ifdef FEAT_FOLDING
240 /* When inserting a character the cursor line must never be in a
241***************
242*** 2489,2495 ****
243 curwin->w_cursor.col++;
244 }
245
246! auto_format();
247
248 ins_compl_free();
249 started_completion = FALSE;
250--- 2504,2510 ----
251 curwin->w_cursor.col++;
252 }
253
254! auto_format(FALSE);
255
256 ins_compl_free();
257 started_completion = FALSE;
258***************
259*** 4346,4357 ****
260 * saved here.
261 */
262 void
263! auto_format()
264 {
265 pos_T pos;
266 colnr_T len;
267 char_u *old, *pold;
268 char_u *new, *pnew;
269
270 if (!has_format_option(FO_AUTO))
271 return;
272--- 4361,4374 ----
273 * saved here.
274 */
275 void
276! auto_format(trailblank)
277! int trailblank; /* when TRUE also format with trailing blank */
278 {
279 pos_T pos;
280 colnr_T len;
281 char_u *old, *pold;
282 char_u *new, *pnew;
283+ int wasatend;
284
285 if (!has_format_option(FO_AUTO))
286 return;
287***************
288*** 4359,4370 ****
289 pos = curwin->w_cursor;
290 old = ml_get_curline();
291
292 /* Don't format in Insert mode when the cursor is on a trailing blank, the
293 * user might insert normal text next. Also skip formatting when "1" is
294 * in 'formatoptions' and there is a single character before the cursor.
295 * Otherwise the line would be broken and when typing another non-white
296 * next they are not joined back together. */
297! if (*old != NUL && pos.col == STRLEN(old))
298 {
299 dec_cursor();
300 if (!WHITECHAR(gchar_cursor())
301--- 4376,4391 ----
302 pos = curwin->w_cursor;
303 old = ml_get_curline();
304
305+ /* may remove added space */
306+ check_auto_format(FALSE);
307+
308 /* Don't format in Insert mode when the cursor is on a trailing blank, the
309 * user might insert normal text next. Also skip formatting when "1" is
310 * in 'formatoptions' and there is a single character before the cursor.
311 * Otherwise the line would be broken and when typing another non-white
312 * next they are not joined back together. */
313! wasatend = (pos.col == STRLEN(old));
314! if (*old != NUL && !trailblank && wasatend)
315 {
316 dec_cursor();
317 if (!WHITECHAR(gchar_cursor())
318***************
319*** 4426,4432 ****
320 len = (colnr_T)STRLEN(pnew);
321 if ((pold - old) + len >= pos.col)
322 {
323! curwin->w_cursor.col = pos.col - (pold - old) + (pnew - new);
324 break;
325 }
326 /* Cursor wraps to next line */
327--- 4447,4477 ----
328 len = (colnr_T)STRLEN(pnew);
329 if ((pold - old) + len >= pos.col)
330 {
331! if (pos.col <= (colnr_T)(pold - old))
332! curwin->w_cursor.col = (pnew - new);
333! else
334! curwin->w_cursor.col = pos.col - (pold - old) + (pnew - new);
335!
336! /* Insert mode: If the cursor is now after the end of the line
337! * while it previously wasn't, the line was broken. Because of
338! * the rule above we need to add a space when 'w' is in
339! * 'formatoptions' to keep a paragraph formatted. */
340! if (!wasatend && has_format_option(FO_WHITE_PAR))
341! {
342! len = STRLEN(new);
343! if (curwin->w_cursor.col == len)
344! {
345! pnew = vim_strnsave(new, len + 2);
346! pnew[len] = ' ';
347! pnew[len + 1] = NUL;
348! ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
349! /* remove the space later */
350! did_add_space = TRUE;
351! }
352! else
353! /* may remove added space */
354! check_auto_format(FALSE);
355! }
356 break;
357 }
358 /* Cursor wraps to next line */
359***************
360*** 4437,4442 ****
361--- 4482,4521 ----
362 vim_free(old);
363 }
364
365+ /*
366+ * When an extra space was added to continue a paragraph for auto-formatting,
367+ * delete it now. The space must be under the cursor, just after the insert
368+ * position.
369+ */
370+ static void
371+ check_auto_format(end_insert)
372+ int end_insert; /* TRUE when ending Insert mode */
373+ {
374+ int c = ' ';
375+
376+ if (did_add_space)
377+ {
378+ if (!WHITECHAR(gchar_cursor()))
379+ /* Somehow the space was removed already. */
380+ did_add_space = FALSE;
381+ else
382+ {
383+ if (!end_insert)
384+ {
385+ inc_cursor();
386+ c = gchar_cursor();
387+ dec_cursor();
388+ }
389+ if (c != NUL)
390+ {
391+ /* The space is no longer at the end of the line, delete it. */
392+ del_char(FALSE);
393+ did_add_space = FALSE;
394+ }
395+ }
396+ }
397+ }
398+
399 #ifdef FEAT_COMMENTS
400 /*
401 * Return the number of bytes for which strings "s1" and "s2" are equal.
402***************
403*** 4536,4543 ****
404 if (!arrow_used) /* something has been inserted */
405 {
406 AppendToRedobuff(ESC_STR);
407 arrow_used = TRUE; /* this means we stopped the current insert */
408- stop_insert(end_insert_pos);
409 }
410 }
411
412--- 4615,4622 ----
413 if (!arrow_used) /* something has been inserted */
414 {
415 AppendToRedobuff(ESC_STR);
416+ stop_insert(end_insert_pos, FALSE);
417 arrow_used = TRUE; /* this means we stopped the current insert */
418 }
419 }
420
421***************
422*** 4587,4594 ****
423 * do a few things to stop inserting
424 */
425 static void
426! stop_insert(end_insert_pos)
427 pos_T *end_insert_pos; /* where insert ended */
428 {
429 int cc;
430
431--- 4666,4674 ----
432 * do a few things to stop inserting
433 */
434 static void
435! stop_insert(end_insert_pos, esc)
436 pos_T *end_insert_pos; /* where insert ended */
437+ int esc; /* called by ins_esc() */
438 {
439 int cc;
440
441***************
442*** 4602,4635 ****
443 last_insert = get_inserted();
444 last_insert_skip = new_insert_skip;
445
446! /*
447! * If we just did an auto-indent, remove the white space from the end of
448! * the line, and put the cursor back.
449! */
450! if (did_ai && !arrow_used)
451 {
452! if (gchar_cursor() == NUL && curwin->w_cursor.col > 0)
453! --curwin->w_cursor.col;
454! while (cc = gchar_cursor(), vim_iswhite(cc))
455! (void)del_char(TRUE);
456! if (cc != NUL)
457! ++curwin->w_cursor.col; /* put cursor back on the NUL */
458
459 #ifdef FEAT_VISUAL
460! /* <C-S-Right> may have started Visual mode, adjust the position for
461! * deleted characters. */
462! if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum)
463! {
464! cc = STRLEN(ml_get_curline());
465! if (VIsual.col > (colnr_T)cc)
466 {
467! VIsual.col = cc;
468 # ifdef FEAT_VIRTUALEDIT
469! VIsual.coladd = 0;
470 # endif
471 }
472- }
473 #endif
474 }
475 did_ai = FALSE;
476 #ifdef FEAT_SMARTINDENT
477--- 4682,4726 ----
478 last_insert = get_inserted();
479 last_insert_skip = new_insert_skip;
480
481! if (!arrow_used)
482 {
483! /* Auto-format now. It may seem strange to do this when stopping an
484! * insertion (or moving the cursor), but it's required when appending
485! * a line and having it end in a space. But only do it when something
486! * was actually inserted, otherwise undo won't work. */
487! if (!ins_need_undo)
488! auto_format(TRUE);
489!
490! /* If a space was inserted for auto-formatting, remove it now. */
491! check_auto_format(TRUE);
492!
493! /* If we just did an auto-indent, remove the white space from the end
494! * of the line, and put the cursor back. */
495! if (did_ai && esc)
496! {
497! if (gchar_cursor() == NUL && curwin->w_cursor.col > 0)
498! --curwin->w_cursor.col;
499! while (cc = gchar_cursor(), vim_iswhite(cc))
500! (void)del_char(TRUE);
501! if (cc != NUL)
502! ++curwin->w_cursor.col; /* put cursor back on the NUL */
503
504 #ifdef FEAT_VISUAL
505! /* <C-S-Right> may have started Visual mode, adjust the position for
506! * deleted characters. */
507! if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum)
508 {
509! cc = STRLEN(ml_get_curline());
510! if (VIsual.col > (colnr_T)cc)
511! {
512! VIsual.col = cc;
513 # ifdef FEAT_VIRTUALEDIT
514! VIsual.coladd = 0;
515 # endif
516+ }
517 }
518 #endif
519+ }
520 }
521 did_ai = FALSE;
522 #ifdef FEAT_SMARTINDENT
523***************
524*** 5988,5994 ****
525 disabled_redraw = TRUE;
526 return FALSE; /* repeat the insert */
527 }
528! stop_insert(&curwin->w_cursor);
529 undisplay_dollar();
530 }
531
532--- 6079,6085 ----
533 disabled_redraw = TRUE;
534 return FALSE; /* repeat the insert */
535 }
536! stop_insert(&curwin->w_cursor, TRUE);
537 undisplay_dollar();
538 }
539
540*** ../vim-6.2.183/src/normal.c Sun Jan 18 20:17:41 2004
541--- src/normal.c Sun Jan 18 18:49:04 2004
542***************
543*** 1753,1759 ****
544 oap->is_VIsual ? (int)cap->count1 :
545 #endif
546 1);
547! auto_format();
548 break;
549
550 case OP_JOIN_NS:
551--- 1753,1759 ----
552 oap->is_VIsual ? (int)cap->count1 :
553 #endif
554 1);
555! auto_format(FALSE);
556 break;
557
558 case OP_JOIN_NS:
559***************
560*** 1766,1772 ****
561 else
562 {
563 do_do_join(oap->line_count, oap->op_type == OP_JOIN);
564! auto_format();
565 }
566 break;
567
568--- 1766,1772 ----
569 else
570 {
571 do_do_join(oap->line_count, oap->op_type == OP_JOIN);
572! auto_format(FALSE);
573 }
574 break;
575
576***************
577*** 1781,1787 ****
578 (void)op_delete(oap);
579 if (oap->motion_type == MLINE && has_format_option(FO_AUTO))
580 u_save_cursor(); /* cursor line wasn't saved yet */
581! auto_format();
582 }
583 break;
584
585--- 1781,1787 ----
586 (void)op_delete(oap);
587 if (oap->motion_type == MLINE && has_format_option(FO_AUTO))
588 u_save_cursor(); /* cursor line wasn't saved yet */
589! auto_format(FALSE);
590 }
591 break;
592
593***************
594*** 1896,1902 ****
595
596 /* TODO: when inserting in several lines, should format all
597 * the lines. */
598! auto_format();
599
600 if (restart_edit == 0)
601 restart_edit = restart_edit_save;
602--- 1896,1902 ----
603
604 /* TODO: when inserting in several lines, should format all
605 * the lines. */
606! auto_format(FALSE);
607
608 if (restart_edit == 0)
609 restart_edit = restart_edit_save;
610***************
611*** 8193,8199 ****
612 if (reg2 != NULL)
613 put_register(regname, reg2);
614 #endif
615! auto_format();
616 }
617 }
618
619--- 8205,8211 ----
620 if (reg2 != NULL)
621 put_register(regname, reg2);
622 #endif
623! auto_format(FALSE);
624 }
625 }
626
627*** ../vim-6.2.183/src/proto/edit.pro Sun Jun 1 12:26:07 2003
628--- src/proto/edit.pro Thu Jan 15 20:57:54 2004
629***************
630*** 13,19 ****
631 void ins_compl_check_keys __ARGS((void));
632 int get_literal __ARGS((void));
633 void insertchar __ARGS((int c, int flags, int second_indent));
634! void auto_format __ARGS((void));
635 int comp_textwidth __ARGS((int ff));
636 int stop_arrow __ARGS((void));
637 void set_last_insert __ARGS((int c));
638--- 13,19 ----
639 void ins_compl_check_keys __ARGS((void));
640 int get_literal __ARGS((void));
641 void insertchar __ARGS((int c, int flags, int second_indent));
642! void auto_format __ARGS((int trailblank));
643 int comp_textwidth __ARGS((int ff));
644 int stop_arrow __ARGS((void));
645 void set_last_insert __ARGS((int c));
646*** ../vim-6.2.183/src/version.c Sun Jan 18 20:17:41 2004
647--- src/version.c Sun Jan 18 20:19:10 2004
648***************
649*** 639,640 ****
650--- 639,642 ----
651 { /* Add new patch number below this line */
652+ /**/
653+ 184,
654 /**/
655
656--
657 [clop clop]
658MORTICIAN: Who's that then?
659CUSTOMER: I don't know.
660MORTICIAN: Must be a king.
661CUSTOMER: Why?
662MORTICIAN: He hasn't got shit all over him.
663 The Quest for the Holy Grail (Monty Python)
664
665 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
666/// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
667\\\ Project leader for A-A-P -- http://www.A-A-P.org ///
668 \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
This page took 0.09141 seconds and 4 git commands to generate.