]> git.pld-linux.org Git - packages/vim.git/blob - 6.2.327
- updated to 6.2.430
[packages/vim.git] / 6.2.327
1 To: vim-dev@vim.org
2 Subject: Patch 6.2.327
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 Patch 6.2.327
11 Problem:    When formatting text all marks in the formatted lines are lost.
12             A word is not joined to a previous line when this would be
13             possible.  (Mikolaj Machowski)
14 Solution:   Try to keep marks in the same position as much as possible.
15             Also keep mark positions when joining lines.
16             Start auto-formatting in the previous line when appropriate.
17             Add the "gw" operator: Like "gq" but keep the cursor where it is.
18 Files:      runtime/doc/change.txt, src/edit.c, src/globals.h, src/mark.c,
19             src/misc1.c, src/normal.c, src/ops.c, src/proto/edit.pro,
20             src/proto/mark.pro, src/proto/ops.pro, src/structs.h, src/vim.h
21
22
23 *** ../vim-6.2.326/runtime/doc/change.txt       Sun Jun  1 12:20:31 2003
24 --- runtime/doc/change.txt      Thu Mar  4 23:02:55 2004
25 ***************
26 *** 1,4 ****
27 ! *change.txt*    For Vim version 6.2.  Last change: 2003 May 24
28   
29   
30                   VIM REFERENCE MANUAL    by Bram Moolenaar
31 --- 1,4 ----
32 ! *change.txt*    For Vim version 6.2.  Last change: 2004 Mar 04
33   
34   
35                   VIM REFERENCE MANUAL    by Bram Moolenaar
36 ***************
37 *** 1104,1110 ****
38   {Visual}gq            Format the highlighted text.  (for {Visual} see
39                         |Visual-mode|).  {not in Vi}
40   
41 ! Example: To format the current paragraph use: >
42         gqap
43   
44   The "gq" command leaves the cursor in the line where the motion command takes
45 --- 1128,1140 ----
46   {Visual}gq            Format the highlighted text.  (for {Visual} see
47                         |Visual-mode|).  {not in Vi}
48   
49 !                                                       *gw*
50 ! gw{motion}            Format the lines that {motion} moves over.  Similar to
51 !                       |gq| but puts the cursor back at the same position in
52 !                       the text.  However, 'formatprg' is not used.
53 !                       {not in Vi}
54
55 ! Example: To format the current paragraph use:                 *gqap*  >
56         gqap
57   
58   The "gq" command leaves the cursor in the line where the motion command takes
59 ***************
60 *** 1112,1117 ****
61 --- 1142,1152 ----
62   works well with "gqj" (format current and next line) and "gq}" (format until
63   end of paragraph).  Note: When 'formatprg' is set, "gq" leaves the cursor on
64   the first formatted line (as with using a filter command).
65
66 + If you want to format the current paragraph and continue where you were, use: >
67 +       gwap
68 + If you always want to keep paragraphs formatted you may want to add the 'a'
69 + flag to 'formatoptions'.  See |auto-format|.
70   
71   If the 'autoindent' option is on, Vim uses the indent of the first line for
72   the following lines.
73 *** ../vim-6.2.326/src/edit.c   Tue Mar  2 14:59:39 2004
74 --- src/edit.c  Mon Mar  8 11:55:50 2004
75 ***************
76 *** 122,130 ****
77   static void undisplay_dollar __ARGS((void));
78   static void insert_special __ARGS((int, int, int));
79   static void check_auto_format __ARGS((int));
80 - #ifdef FEAT_COMMENTS
81 - static int  cmplen __ARGS((char_u *s1, char_u *s2));
82 - #endif
83   static void redo_literal __ARGS((int c));
84   static void start_arrow __ARGS((pos_T *end_insert_pos));
85   static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
86 --- 122,127 ----
87 ***************
88 *** 874,880 ****
89         /* insert the contents of a register */
90         case Ctrl_R:
91             ins_reg();
92 !           auto_format(FALSE);
93             inserted_space = FALSE;
94             break;
95   
96 --- 871,877 ----
97         /* insert the contents of a register */
98         case Ctrl_R:
99             ins_reg();
100 !           auto_format(FALSE, TRUE);
101             inserted_space = FALSE;
102             break;
103   
104 ***************
105 *** 969,975 ****
106             }
107   # endif
108             ins_shift(c, lastc);
109 !           auto_format(FALSE);
110             inserted_space = FALSE;
111             break;
112   
113 --- 966,972 ----
114             }
115   # endif
116             ins_shift(c, lastc);
117 !           auto_format(FALSE, TRUE);
118             inserted_space = FALSE;
119             break;
120   
121 ***************
122 *** 977,1002 ****
123         case K_DEL:
124         case K_KDEL:
125             ins_del();
126 !           auto_format(FALSE);
127             break;
128   
129         /* delete character before the cursor */
130         case K_BS:
131         case Ctrl_H:
132             did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
133 !           auto_format(FALSE);
134             break;
135   
136         /* delete word before the cursor */
137         case Ctrl_W:
138             did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
139 !           auto_format(FALSE);
140             break;
141   
142         /* delete all inserted text in current line */
143         case Ctrl_U:
144             did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
145 !           auto_format(FALSE);
146             inserted_space = FALSE;
147             break;
148   
149 --- 974,999 ----
150         case K_DEL:
151         case K_KDEL:
152             ins_del();
153 !           auto_format(FALSE, TRUE);
154             break;
155   
156         /* delete character before the cursor */
157         case K_BS:
158         case Ctrl_H:
159             did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
160 !           auto_format(FALSE, TRUE);
161             break;
162   
163         /* delete word before the cursor */
164         case Ctrl_W:
165             did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
166 !           auto_format(FALSE, TRUE);
167             break;
168   
169         /* delete all inserted text in current line */
170         case Ctrl_U:
171             did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
172 !           auto_format(FALSE, TRUE);
173             inserted_space = FALSE;
174             break;
175   
176 ***************
177 *** 1119,1125 ****
178             inserted_space = FALSE;
179             if (ins_tab())
180                 goto normalchar;        /* insert TAB as a normal char */
181 !           auto_format(FALSE);
182             break;
183   
184         case K_KENTER:
185 --- 1116,1122 ----
186             inserted_space = FALSE;
187             if (ins_tab())
188                 goto normalchar;        /* insert TAB as a normal char */
189 !           auto_format(FALSE, TRUE);
190             break;
191   
192         case K_KENTER:
193 ***************
194 *** 1146,1152 ****
195   #endif
196             if (ins_eol(c) && !p_im)
197                 goto doESCkey;      /* out of memory */
198 !           auto_format(FALSE);
199             inserted_space = FALSE;
200             break;
201   
202 --- 1143,1149 ----
203   #endif
204             if (ins_eol(c) && !p_im)
205                 goto doESCkey;      /* out of memory */
206 !           auto_format(FALSE, FALSE);
207             inserted_space = FALSE;
208             break;
209   
210 ***************
211 *** 1260,1266 ****
212                     revins_legal++;
213   #endif
214                     c = Ctrl_V; /* pretend CTRL-V is last character */
215 !                   auto_format(FALSE);
216                 }
217             }
218             break;
219 --- 1257,1263 ----
220                     revins_legal++;
221   #endif
222                     c = Ctrl_V; /* pretend CTRL-V is last character */
223 !                   auto_format(FALSE, TRUE);
224                 }
225             }
226             break;
227 ***************
228 *** 1307,1313 ****
229   #endif
230             }
231   
232 !           auto_format(FALSE);
233   
234   #ifdef FEAT_FOLDING
235             /* When inserting a character the cursor line must never be in a
236 --- 1304,1310 ----
237   #endif
238             }
239   
240 !           auto_format(FALSE, TRUE);
241   
242   #ifdef FEAT_FOLDING
243             /* When inserting a character the cursor line must never be in a
244 ***************
245 *** 1767,1774 ****
246       if (State & VREPLACE_FLAG)
247       {
248         /* If orig_line didn't allocate, just return.  At least we did the job,
249 !        * even if you can't backspace.
250 !        */
251         if (orig_line == NULL)
252             return;
253   
254 --- 1764,1770 ----
255       if (State & VREPLACE_FLAG)
256       {
257         /* If orig_line didn't allocate, just return.  At least we did the job,
258 !        * even if you can't backspace. */
259         if (orig_line == NULL)
260             return;
261   
262 ***************
263 *** 2509,2515 ****
264                 curwin->w_cursor.col++;
265             }
266   
267 !           auto_format(FALSE);
268   
269             ins_compl_free();
270             started_completion = FALSE;
271 --- 2505,2511 ----
272                 curwin->w_cursor.col++;
273             }
274   
275 !           auto_format(FALSE, TRUE);
276   
277             ins_compl_free();
278             started_completion = FALSE;
279 ***************
280 *** 4114,4120 ****
281              * Split the line just before the margin.
282              * Only insert/delete lines, but don't really redraw the window.
283              */
284 !           open_line(FORWARD, OPENLINE_DELSPACES
285                     + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
286   #ifdef FEAT_COMMENTS
287                     + (do_comments ? OPENLINE_DO_COM : 0)
288 --- 4110,4116 ----
289              * Split the line just before the margin.
290              * Only insert/delete lines, but don't really redraw the window.
291              */
292 !           open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
293                     + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
294   #ifdef FEAT_COMMENTS
295                     + (do_comments ? OPENLINE_DO_COM : 0)
296 ***************
297 *** 4366,4377 ****
298    * saved here.
299    */
300       void
301 ! auto_format(trailblank)
302       int               trailblank;     /* when TRUE also format with trailing blank */
303   {
304       pos_T     pos;
305       colnr_T   len;
306 !     char_u    *old, *pold;
307       char_u    *new, *pnew;
308       int               wasatend;
309   
310 --- 4362,4374 ----
311    * saved here.
312    */
313       void
314 ! auto_format(trailblank, prev_line)
315       int               trailblank;     /* when TRUE also format with trailing blank */
316 +     int               prev_line;      /* may start in previous line */
317   {
318       pos_T     pos;
319       colnr_T   len;
320 !     char_u    *old;
321       char_u    *new, *pnew;
322       int               wasatend;
323   
324 ***************
325 *** 4413,4490 ****
326         return;
327   #endif
328   
329 !     old = vim_strsave(old);
330 !     format_lines((linenr_T)-1);
331   
332 !     /* Advance to the same text position again.  This is tricky, indents
333 !      * may have changed and comment leaders may have been inserted. */
334 !     curwin->w_cursor.lnum = pos.lnum;
335 !     curwin->w_cursor.col = 0;
336 !     pold = old;
337 !     while (1)
338 !     {
339 !       if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
340 !       {
341 !           curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
342 !           curwin->w_cursor.col = MAXCOL;
343 !           break;
344 !       }
345 !       /* Make "pold" and "pnew" point to the start of the line, ignoring
346 !        * indent and comment leader. */
347 !       pold = skipwhite(pold);
348 !       new = ml_get_curline();
349 !       pnew = skipwhite(new);
350 ! #ifdef FEAT_COMMENTS
351 !       len = get_leader_len(new, NULL, FALSE);
352 !       if (len > 0)
353 !       {
354 !           char_u      *p;
355   
356 !           /* Skip the leader if the old text matches after it, ignoring
357 !            * white space.  Keep in mind that the leader may appear in
358 !            * the text! */
359 !           p = skipwhite(new + len);
360 !           if (cmplen(pold, pnew) < cmplen(pold, p))
361 !               pnew = p;
362 !       }
363 ! #endif
364   
365 !       len = (colnr_T)STRLEN(pnew);
366 !       if ((pold - old) + len >= pos.col)
367         {
368 !           if (pos.col <= (colnr_T)(pold - old))
369 !               curwin->w_cursor.col = (pnew - new);
370 !           else
371 !               curwin->w_cursor.col = pos.col - (pold - old) + (pnew - new);
372
373 !           /* Insert mode: If the cursor is now after the end of the line
374 !            * while it previously wasn't, the line was broken.  Because of
375 !            * the rule above we need to add a space when 'w' is in
376 !            * 'formatoptions' to keep a paragraph formatted. */
377 !           if (!wasatend && has_format_option(FO_WHITE_PAR))
378 !           {
379 !               len = STRLEN(new);
380 !               if (curwin->w_cursor.col == len)
381 !               {
382 !                   pnew = vim_strnsave(new, len + 2);
383 !                   pnew[len] = ' ';
384 !                   pnew[len + 1] = NUL;
385 !                   ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
386 !                   /* remove the space later */
387 !                   did_add_space = TRUE;
388 !               }
389 !               else
390 !                   /* may remove added space */
391 !                   check_auto_format(FALSE);
392 !           }
393 !           break;
394         }
395 !       /* Cursor wraps to next line */
396 !       ++curwin->w_cursor.lnum;
397 !       pold += len;
398       }
399       check_cursor();
400 -     vim_free(old);
401   }
402   
403   /*
404 --- 4410,4468 ----
405         return;
406   #endif
407   
408 !     /*
409 !      * May start formatting in a previous line, so that after "x" a word is
410 !      * moved to the previous line if it fits there now.  Only when this is not
411 !      * the start of a paragraph.
412 !      */
413 !     if (prev_line && !paragraph_start(curwin->w_cursor.lnum))
414 !     {
415 !       --curwin->w_cursor.lnum;
416 !       if (u_save_cursor() == FAIL)
417 !           return;
418 !     }
419   
420 !     /*
421 !      * Do the formatting and restore the cursor position.  "saved_cursor" will
422 !      * be adjusted for the text formatting.
423 !      */
424 !     saved_cursor = pos;
425 !     format_lines((linenr_T)-1);
426 !     curwin->w_cursor = saved_cursor;
427 !     saved_cursor.lnum = 0;
428   
429 !     if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
430 !     {
431 !       /* "cannot happen" */
432 !       curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
433 !       coladvance((colnr_T)MAXCOL);
434 !     }
435 !     else
436 !       check_cursor_col();
437   
438 !     /* Insert mode: If the cursor is now after the end of the line while it
439 !      * previously wasn't, the line was broken.  Because of the rule above we
440 !      * need to add a space when 'w' is in 'formatoptions' to keep a paragraph
441 !      * formatted. */
442 !     if (!wasatend && has_format_option(FO_WHITE_PAR))
443 !     {
444 !       new = ml_get_curline();
445 !       len = STRLEN(new);
446 !       if (curwin->w_cursor.col == len)
447         {
448 !           pnew = vim_strnsave(new, len + 2);
449 !           pnew[len] = ' ';
450 !           pnew[len + 1] = NUL;
451 !           ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
452 !           /* remove the space later */
453 !           did_add_space = TRUE;
454         }
455 !       else
456 !           /* may remove added space */
457 !           check_auto_format(FALSE);
458       }
459
460       check_cursor();
461   }
462   
463   /*
464 ***************
465 *** 4521,4552 ****
466       }
467   }
468   
469 - #ifdef FEAT_COMMENTS
470 - /*
471 -  * Return the number of bytes for which strings "s1" and "s2" are equal.
472 -  */
473 -     static int
474 - cmplen(s1, s2)
475 -     char_u    *s1;
476 -     char_u    *s2;
477 - {
478 -     char_u    *p1 = s1, *p2 = s2;
479
480 -     while (*p1 == *p2 && *p1 != NUL)
481 -     {
482 -       ++p1;
483 -       ++p2;
484 -     }
485 -     return (int)(p1 - s1);
486 - }
487 - #endif
488
489   /*
490    * Find out textwidth to be used for formatting:
491    *    if 'textwidth' option is set, use it
492    *    else if 'wrapmargin' option is set, use W_WIDTH(curwin) - 'wrapmargin'
493    *    if invalid value, use 0.
494 !  *    Set default to window width (maximum 79) for "Q" command.
495    */
496       int
497   comp_textwidth(ff)
498 --- 4499,4510 ----
499       }
500   }
501   
502   /*
503    * Find out textwidth to be used for formatting:
504    *    if 'textwidth' option is set, use it
505    *    else if 'wrapmargin' option is set, use W_WIDTH(curwin) - 'wrapmargin'
506    *    if invalid value, use 0.
507 !  *    Set default to window width (maximum 79) for "gq" operator.
508    */
509       int
510   comp_textwidth(ff)
511 ***************
512 *** 4694,4700 ****
513          * a line and having it end in a space.  But only do it when something
514          * was actually inserted, otherwise undo won't work. */
515         if (!ins_need_undo)
516 !           auto_format(TRUE);
517   
518         /* If a space was inserted for auto-formatting, remove it now. */
519         check_auto_format(TRUE);
520 --- 4652,4675 ----
521          * a line and having it end in a space.  But only do it when something
522          * was actually inserted, otherwise undo won't work. */
523         if (!ins_need_undo)
524 !       {
525 !           /* When the cursor is at the end of the line after a space the
526 !            * formatting will move it to the following word.  Avoid that by
527 !            * moving the cursor onto the space. */
528 !           cc = 'x';
529 !           if (curwin->w_cursor.col > 0 == NUL && gchar_cursor())
530 !           {
531 !               dec_cursor();
532 !               cc = gchar_cursor();
533 !               if (!vim_iswhite(cc))
534 !                   inc_cursor();
535 !           }
536
537 !           auto_format(TRUE, FALSE);
538
539 !           if (vim_iswhite(cc) && gchar_cursor() != NUL)
540 !               inc_cursor();
541 !       }
542   
543         /* If a space was inserted for auto-formatting, remove it now. */
544         check_auto_format(TRUE);
545 *** ../vim-6.2.326/src/globals.h        Sat Mar  6 21:10:59 2004
546 --- src/globals.h       Sat Mar  6 15:13:54 2004
547 ***************
548 *** 608,613 ****
549 --- 608,619 ----
550   EXTERN int    can_si_back INIT(= FALSE);
551   #endif
552   
553 + EXTERN pos_T  saved_cursor            /* w_cursor before formatting text. */
554 + # ifdef DO_INIT
555 +       = INIT_POS_T
556 + # endif
557 +       ;
558
559   /*
560    * Stuff for insert mode.
561    */
562 *** ../vim-6.2.326/src/mark.c   Tue Mar  2 16:04:09 2004
563 --- src/mark.c  Thu Mar  4 13:50:05 2004
564 ***************
565 *** 923,928 ****
566 --- 923,932 ----
567       /* previous pcmark */
568       one_adjust(&(curwin->w_prev_pcmark.lnum));
569   
570 +     /* saved cursor for formatting */
571 +     if (saved_cursor.lnum != 0)
572 +       one_adjust_nodel(&(saved_cursor.lnum));
573
574       /*
575        * Adjust items in all windows related to the current buffer.
576        */
577 ***************
578 *** 1008,1013 ****
579 --- 1012,1117 ----
580       /* adjust diffs */
581       diff_mark_adjust(line1, line2, amount, amount_after);
582   #endif
583 + }
584
585 + /* This code is used often, needs to be fast. */
586 + #define col_adjust(pp) \
587 +     { \
588 +       posp = pp; \
589 +       if (posp->lnum == lnum && posp->col >= mincol) \
590 +       { \
591 +           posp->lnum += lnum_amount; \
592 +           if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \
593 +               posp->col = 0; \
594 +           else \
595 +               posp->col += col_amount; \
596 +       } \
597 +     }
598
599 + /*
600 +  * Adjust marks in line "lnum" at column "mincol" and further: add
601 +  * "lnum_amount" to the line number and add "col_amount" to the column
602 +  * position.
603 +  */
604 +     void
605 + mark_col_adjust(lnum, mincol, lnum_amount, col_amount)
606 +     linenr_T  lnum;
607 +     colnr_T   mincol;
608 +     long      lnum_amount;
609 +     long      col_amount;
610 + {
611 +     int               i;
612 +     int               fnum = curbuf->b_fnum;
613 +     win_T     *win;
614 +     pos_T     *posp;
615
616 +     if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks)
617 +       return; /* nothing to do */
618
619 +     /* named marks, lower case and upper case */
620 +     for (i = 0; i < NMARKS; i++)
621 +     {
622 +       col_adjust(&(curbuf->b_namedm[i]));
623 +       if (namedfm[i].fmark.fnum == fnum)
624 +           col_adjust(&(namedfm[i].fmark.mark));
625 +     }
626 +     for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++)
627 +     {
628 +       if (namedfm[i].fmark.fnum == fnum)
629 +           col_adjust(&(namedfm[i].fmark.mark));
630 +     }
631
632 +     /* last Insert position */
633 +     col_adjust(&(curbuf->b_last_insert));
634
635 +     /* last change position */
636 +     col_adjust(&(curbuf->b_last_change));
637
638 + #ifdef FEAT_JUMPLIST
639 +     /* list of change positions */
640 +     for (i = 0; i < curbuf->b_changelistlen; ++i)
641 +       col_adjust(&(curbuf->b_changelist[i]));
642 + #endif
643
644 + #ifdef FEAT_VISUAL
645 +     /* Visual area */
646 +     col_adjust(&(curbuf->b_visual_start));
647 +     col_adjust(&(curbuf->b_visual_end));
648 + #endif
649
650 +     /* previous context mark */
651 +     col_adjust(&(curwin->w_pcmark));
652
653 +     /* previous pcmark */
654 +     col_adjust(&(curwin->w_prev_pcmark));
655
656 +     /* saved cursor for formatting */
657 +     col_adjust(&saved_cursor);
658
659 +     /*
660 +      * Adjust items in all windows related to the current buffer.
661 +      */
662 +     FOR_ALL_WINDOWS(win)
663 +     {
664 + #ifdef FEAT_JUMPLIST
665 +       /* marks in the jumplist */
666 +       for (i = 0; i < win->w_jumplistlen; ++i)
667 +           if (win->w_jumplist[i].fmark.fnum == fnum)
668 +               col_adjust(&(win->w_jumplist[i].fmark.mark));
669 + #endif
670
671 +       if (win->w_buffer == curbuf)
672 +       {
673 +           /* marks in the tag stack */
674 +           for (i = 0; i < win->w_tagstacklen; i++)
675 +               if (win->w_tagstack[i].fmark.fnum == fnum)
676 +                   col_adjust(&(win->w_tagstack[i].fmark.mark));
677
678 +           /* cursor position for other windows with the same buffer */
679 +           if (win != curwin)
680 +               col_adjust(&win->w_cursor);
681 +       }
682 +     }
683   }
684   
685   #ifdef FEAT_JUMPLIST
686 *** ../vim-6.2.326/src/misc1.c  Sun Mar  7 15:21:39 2004
687 --- src/misc1.c Mon Mar  8 10:27:17 2004
688 ***************
689 *** 95,101 ****
690       int               flags;
691   {
692       char_u    *p;
693 !     char_u    *line;
694       char_u    *s;
695       int               todo;
696       int               ind_len;
697 --- 95,102 ----
698       int               flags;
699   {
700       char_u    *p;
701 !     char_u    *newline;
702 !     char_u    *oldline;
703       char_u    *s;
704       int               todo;
705       int               ind_len;
706 ***************
707 *** 110,116 ****
708        */
709       todo = size;
710       ind_len = 0;
711 !     p = ml_get_curline();
712   
713       /* Calculate the buffer size for the new indent, and check to see if it
714        * isn't already set */
715 --- 111,117 ----
716        */
717       todo = size;
718       ind_len = 0;
719 !     p = oldline = ml_get_curline();
720   
721       /* Calculate the buffer size for the new indent, and check to see if it
722        * isn't already set */
723 ***************
724 *** 188,203 ****
725   
726       /* Allocate memory for the new line. */
727       if (flags & SIN_INSERT)
728 !       p = ml_get_curline();
729       else
730         p = skipwhite(p);
731       line_len = (int)STRLEN(p) + 1;
732 !     line = alloc(ind_len + line_len);
733 !     if (line == NULL)
734         return FALSE;
735   
736       /* Put the characters in the new line. */
737 !     s = line;
738       todo = size;
739       /* if 'expandtab' isn't set: use TABs */
740       if (!curbuf->b_p_et)
741 --- 189,204 ----
742   
743       /* Allocate memory for the new line. */
744       if (flags & SIN_INSERT)
745 !       p = oldline;
746       else
747         p = skipwhite(p);
748       line_len = (int)STRLEN(p) + 1;
749 !     newline = alloc(ind_len + line_len);
750 !     if (newline == NULL)
751         return FALSE;
752   
753       /* Put the characters in the new line. */
754 !     s = newline;
755       todo = size;
756       /* if 'expandtab' isn't set: use TABs */
757       if (!curbuf->b_p_et)
758 ***************
759 *** 206,212 ****
760          * the existing indent structure for the new indent */
761         if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
762         {
763 !           p = ml_get_curline();
764             ind_done = 0;
765   
766             while (todo > 0 && vim_iswhite(*p))
767 --- 207,213 ----
768          * the existing indent structure for the new indent */
769         if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
770         {
771 !           p = oldline;
772             ind_done = 0;
773   
774             while (todo > 0 && vim_iswhite(*p))
775 ***************
776 *** 256,267 ****
777       /* Replace the line (unless undo fails). */
778       if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
779       {
780 !       ml_replace(curwin->w_cursor.lnum, line, FALSE);
781         if (flags & SIN_CHANGED)
782             changed_bytes(curwin->w_cursor.lnum, 0);
783       }
784       else
785 !       vim_free(line);
786   
787       curwin->w_cursor.col = ind_len;
788       return TRUE;
789 --- 257,272 ----
790       /* Replace the line (unless undo fails). */
791       if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
792       {
793 !       ml_replace(curwin->w_cursor.lnum, newline, FALSE);
794         if (flags & SIN_CHANGED)
795             changed_bytes(curwin->w_cursor.lnum, 0);
796 +       /* Correct saved cursor position if it's after the indent. */
797 +       if (saved_cursor.lnum == curwin->w_cursor.lnum
798 +                               && saved_cursor.col >= (colnr_T)(p - oldline))
799 +           saved_cursor.col += ind_len - (p - oldline);
800       }
801       else
802 !       vim_free(newline);
803   
804       curwin->w_cursor.col = ind_len;
805       return TRUE;
806 ***************
807 *** 373,379 ****
808   
809   /*
810    * Return the indent of the current line after a number.  Return -1 if no
811 !  * number was found.  Used for '1' in 'formatoptions': numbered list.
812    */
813       int
814   get_number_indent(lnum)
815 --- 378,384 ----
816   
817   /*
818    * Return the indent of the current line after a number.  Return -1 if no
819 !  * number was found.  Used for 'n' in 'formatoptions': numbered list.
820    */
821       int
822   get_number_indent(lnum)
823 ***************
824 *** 449,466 ****
825    * Caller must take care of undo.  Since VREPLACE may affect any number of
826    * lines however, it may call u_save_cursor() again when starting to change a
827    * new line.
828    *
829    * Return TRUE for success, FALSE for failure
830    */
831       int
832   open_line(dir, flags, old_indent)
833       int               dir;            /* FORWARD or BACKWARD */
834 !     int               flags;          /* OPENLINE_DELSPACES and OPENLINE_DO_COM */
835       int               old_indent;     /* indent for after ^^D in Insert mode */
836   {
837       char_u    *saved_line;            /* copy of the original line */
838       char_u    *next_line = NULL;      /* copy of the next line */
839       char_u    *p_extra = NULL;        /* what goes to next line */
840       pos_T     old_cursor;             /* old cursor position */
841       int               newcol = 0;             /* new cursor column */
842       int               newindent = 0;          /* auto-indent of the new line */
843 --- 454,477 ----
844    * Caller must take care of undo.  Since VREPLACE may affect any number of
845    * lines however, it may call u_save_cursor() again when starting to change a
846    * new line.
847 +  * "flags": OPENLINE_DELSPACES        delete spaces after cursor
848 +  *        OPENLINE_DO_COM     format comments
849 +  *        OPENLINE_KEEPTRAIL  keep trailing spaces
850 +  *        OPENLINE_MARKFIX    adjust mark positions after the line break
851    *
852    * Return TRUE for success, FALSE for failure
853    */
854       int
855   open_line(dir, flags, old_indent)
856       int               dir;            /* FORWARD or BACKWARD */
857 !     int               flags;
858       int               old_indent;     /* indent for after ^^D in Insert mode */
859   {
860       char_u    *saved_line;            /* copy of the original line */
861       char_u    *next_line = NULL;      /* copy of the next line */
862       char_u    *p_extra = NULL;        /* what goes to next line */
863 +     int               less_cols = 0;          /* less columns for mark in new line */
864 +     int               less_cols_off = 0;      /* columns to skip for mark adjust */
865       pos_T     old_cursor;             /* old cursor position */
866       int               newcol = 0;             /* new cursor column */
867       int               newindent = 0;          /* auto-indent of the new line */
868 ***************
869 *** 1138,1147 ****
870 --- 1149,1162 ----
871                 if (REPLACE_NORMAL(State))
872                     replace_push(*p_extra);
873                 ++p_extra;
874 +               ++less_cols_off;
875             }
876         }
877         if (*p_extra != NUL)
878             did_ai = FALSE;         /* append some text, don't truncate now */
879
880 +       /* columns for marks adjusted for removed columns */
881 +       less_cols = (int)(p_extra - saved_line);
882       }
883   
884       if (p_extra == NULL)
885 ***************
886 *** 1154,1159 ****
887 --- 1169,1175 ----
888         STRCAT(leader, p_extra);
889         p_extra = leader;
890         did_ai = TRUE;      /* So truncating blanks works with comments */
891 +       less_cols -= lead_len;
892       }
893       else
894         end_comment_pending = NUL;  /* turns out there was no leader */
895 ***************
896 *** 1225,1230 ****
897 --- 1241,1247 ----
898         }
899         else
900             (void)set_indent(newindent, SIN_INSERT);
901 +       less_cols -= curwin->w_cursor.col;
902   
903         ai_col = curwin->w_cursor.col;
904   
905 ***************
906 *** 1270,1275 ****
907 --- 1287,1298 ----
908                 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
909                                                curwin->w_cursor.lnum + 1, 1L);
910                 did_append = FALSE;
911
912 +               /* Move marks after the line break to the new line. */
913 +               if (flags & OPENLINE_MARKFIX)
914 +                   mark_col_adjust(curwin->w_cursor.lnum,
915 +                                        curwin->w_cursor.col + less_cols_off,
916 +                                                       1L, (long)-less_cols);
917             }
918             else
919                 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
920 ***************
921 *** 2309,2318 ****
922       void
923   changed()
924   {
925 -     int           save_msg_scroll = msg_scroll;
926
927       if (!curbuf->b_changed)
928       {
929         change_warning(0);
930         /* Create a swap file if that is wanted.
931          * Don't do this for "nofile" and "nowrite" buffer types. */
932 --- 2332,2341 ----
933       void
934   changed()
935   {
936       if (!curbuf->b_changed)
937       {
938 +       int     save_msg_scroll = msg_scroll;
939
940         change_warning(0);
941         /* Create a swap file if that is wanted.
942          * Don't do this for "nofile" and "nowrite" buffer types. */
943 *** ../vim-6.2.326/src/normal.c Fri Mar  5 12:12:37 2004
944 --- src/normal.c        Mon Mar  8 10:11:06 2004
945 ***************
946 *** 1792,1798 ****
947                     oap->is_VIsual ? (int)cap->count1 :
948   #endif
949                     1);
950 !           auto_format(FALSE);
951             break;
952   
953         case OP_JOIN_NS:
954 --- 1792,1798 ----
955                     oap->is_VIsual ? (int)cap->count1 :
956   #endif
957                     1);
958 !           auto_format(FALSE, TRUE);
959             break;
960   
961         case OP_JOIN_NS:
962 ***************
963 *** 1805,1811 ****
964             else
965             {
966                 do_do_join(oap->line_count, oap->op_type == OP_JOIN);
967 !               auto_format(FALSE);
968             }
969             break;
970   
971 --- 1805,1811 ----
972             else
973             {
974                 do_do_join(oap->line_count, oap->op_type == OP_JOIN);
975 !               auto_format(FALSE, TRUE);
976             }
977             break;
978   
979 ***************
980 *** 1820,1826 ****
981                 (void)op_delete(oap);
982                 if (oap->motion_type == MLINE && has_format_option(FO_AUTO))
983                     u_save_cursor();        /* cursor line wasn't saved yet */
984 !               auto_format(FALSE);
985             }
986             break;
987   
988 --- 1820,1826 ----
989                 (void)op_delete(oap);
990                 if (oap->motion_type == MLINE && has_format_option(FO_AUTO))
991                     u_save_cursor();        /* cursor line wasn't saved yet */
992 !               auto_format(FALSE, TRUE);
993             }
994             break;
995   
996 ***************
997 *** 1912,1918 ****
998             if (*p_fp != NUL)
999                 op_colon(oap);          /* use external command */
1000             else
1001 !               op_format(oap);         /* use internal function */
1002             break;
1003   
1004         case OP_INSERT:
1005 --- 1912,1922 ----
1006             if (*p_fp != NUL)
1007                 op_colon(oap);          /* use external command */
1008             else
1009 !               op_format(oap, FALSE);  /* use internal function */
1010 !           break;
1011
1012 !       case OP_FORMAT2:
1013 !           op_format(oap, TRUE);       /* use internal function */
1014             break;
1015   
1016         case OP_INSERT:
1017 ***************
1018 *** 1935,1941 ****
1019   
1020                 /* TODO: when inserting in several lines, should format all
1021                  * the lines. */
1022 !               auto_format(FALSE);
1023   
1024                 if (restart_edit == 0)
1025                     restart_edit = restart_edit_save;
1026 --- 1939,1945 ----
1027   
1028                 /* TODO: when inserting in several lines, should format all
1029                  * the lines. */
1030 !               auto_format(FALSE, TRUE);
1031   
1032                 if (restart_edit == 0)
1033                     restart_edit = restart_edit_save;
1034 ***************
1035 *** 7278,7289 ****
1036 --- 7285,7298 ----
1037       /*
1038        *         Two-character operators:
1039        *         "gq"       Format text
1040 +      *         "gw"       Format text and keep cursor position
1041        *         "g~"       Toggle the case of the text.
1042        *         "gu"       Change text to lower case.
1043        *         "gU"       Change text to upper case.
1044        *   "g?"     rot13 encoding
1045        */
1046       case 'q':
1047 +     case 'w':
1048       case '~':
1049       case 'u':
1050       case 'U':
1051 ***************
1052 *** 8298,8304 ****
1053         if (reg2 != NULL)
1054             put_register(regname, reg2);
1055   #endif
1056 !       auto_format(FALSE);
1057       }
1058   }
1059   
1060 --- 8307,8313 ----
1061         if (reg2 != NULL)
1062             put_register(regname, reg2);
1063   #endif
1064 !       auto_format(FALSE, TRUE);
1065       }
1066   }
1067   
1068 *** ../vim-6.2.326/src/ops.c    Wed Mar  3 23:01:29 2004
1069 --- src/ops.c   Thu Mar  4 22:54:41 2004
1070 ***************
1071 *** 163,168 ****
1072 --- 163,169 ----
1073       {'z', 'C', TRUE}, /* OP_FOLDCLOSEREC */
1074       {'z', 'd', TRUE}, /* OP_FOLDDEL */
1075       {'z', 'D', TRUE}, /* OP_FOLDDELREC */
1076 +     {'g', 'w', TRUE}, /* OP_FORMAT2 */
1077   };
1078   
1079   /*
1080 ***************
1081 *** 3845,3851 ****
1082       int               insert_space;
1083   {
1084       char_u    *curr;
1085 !     char_u    *next;
1086       char_u    *newp;
1087       int               endcurr1, endcurr2;
1088       int               currsize;       /* size of the current line */
1089 --- 3846,3852 ----
1090       int               insert_space;
1091   {
1092       char_u    *curr;
1093 !     char_u    *next, *next_start;
1094       char_u    *newp;
1095       int               endcurr1, endcurr2;
1096       int               currsize;       /* size of the current line */
1097 ***************
1098 *** 3883,3889 ****
1099         }
1100       }
1101   
1102 !     next = ml_get((linenr_T)(curwin->w_cursor.lnum + 1));
1103       spaces = 0;
1104       if (insert_space)
1105       {
1106 --- 3884,3890 ----
1107         }
1108       }
1109   
1110 !     next = next_start = ml_get((linenr_T)(curwin->w_cursor.lnum + 1));
1111       spaces = 0;
1112       if (insert_space)
1113       {
1114 ***************
1115 *** 3939,3946 ****
1116 --- 3940,3953 ----
1117        * Delete the following line. To do this we move the cursor there
1118        * briefly, and then move it back. After del_lines() the cursor may
1119        * have moved up (last line deleted), so the current lnum is kept in t.
1120 +      *
1121 +      * Move marks from the deleted line to the joined line, adjusting the
1122 +      * column.  This is not Vi compatible, but Vi deletes the marks, thus that
1123 +      * should not really be a problem.
1124        */
1125       t = curwin->w_cursor.lnum;
1126 +     mark_col_adjust(t + 1, (colnr_T)0, (linenr_T)-1,
1127 +                            (long)(currsize + spaces - (next - next_start)));
1128       ++curwin->w_cursor.lnum;
1129       del_lines(1L, FALSE);
1130       curwin->w_cursor.lnum = t;
1131 ***************
1132 *** 4039,4046 ****
1133    * implementation of the format operator 'gq'
1134    */
1135       void
1136 ! op_format(oap)
1137       oparg_T   *oap;
1138   {
1139       long      old_line_count = curbuf->b_ml.ml_line_count;
1140   
1141 --- 4046,4054 ----
1142    * implementation of the format operator 'gq'
1143    */
1144       void
1145 ! op_format(oap, keep_cursor)
1146       oparg_T   *oap;
1147 +     int               keep_cursor;            /* keep cursor on same text char */
1148   {
1149       long      old_line_count = curbuf->b_ml.ml_line_count;
1150   
1151 ***************
1152 *** 4057,4062 ****
1153 --- 4065,4073 ----
1154       /* Set '[ mark at the start of the formatted area */
1155       curbuf->b_op_start = oap->start;
1156   
1157 +     if (keep_cursor)
1158 +       saved_cursor = curwin->w_cursor;
1159
1160       format_lines(oap->line_count);
1161   
1162       /*
1163 ***************
1164 *** 4073,4078 ****
1165 --- 4084,4095 ----
1166       /* put '] mark on the end of the formatted area */
1167       curbuf->b_op_end = curwin->w_cursor;
1168   
1169 +     if (keep_cursor)
1170 +     {
1171 +       curwin->w_cursor = saved_cursor;
1172 +       saved_cursor.lnum = 0;
1173 +     }
1174
1175   #ifdef FEAT_VISUAL
1176       if (oap->is_VIsual)
1177       {
1178 ***************
1179 *** 4301,4306 ****
1180 --- 4318,4326 ----
1181                         break;
1182   #ifdef FEAT_COMMENTS
1183                 (void)del_bytes((long)next_leader_len, FALSE);
1184 +               if (next_leader_len > 0)
1185 +                   mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
1186 +                                                     (long)-next_leader_len);
1187   #endif
1188                 curwin->w_cursor.lnum--;
1189                 if (do_join(TRUE) == FAIL)
1190 ***************
1191 *** 4385,4390 ****
1192 --- 4405,4466 ----
1193       return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE));
1194   }
1195   #endif
1196
1197 + /*
1198 +  * Return TRUE when a paragraph starts in line "lnum".  Return FALSE when the
1199 +  * previous line is in the same paragraph.  Used for auto-formatting.
1200 +  */
1201 +     int
1202 + paragraph_start(lnum)
1203 +     linenr_T  lnum;
1204 + {
1205 +     char_u    *p;
1206 + #ifdef FEAT_COMMENTS
1207 +     int               leader_len = 0;         /* leader len of current line */
1208 +     char_u    *leader_flags = NULL;   /* flags for leader of current line */
1209 +     int               next_leader_len;        /* leader len of next line */
1210 +     char_u    *next_leader_flags;     /* flags for leader of next line */
1211 +     int               do_comments;            /* format comments */
1212 + #endif
1213
1214 +     if (lnum <= 1)
1215 +       return TRUE;            /* start of the file */
1216
1217 +     p = ml_get(lnum - 1);
1218 +     if (*p == NUL)
1219 +       return TRUE;            /* after empty line */
1220
1221 + #ifdef FEAT_COMMENTS
1222 +     do_comments = has_format_option(FO_Q_COMS);
1223 + #endif
1224 +     if (fmt_check_par(lnum - 1
1225 + #ifdef FEAT_COMMENTS
1226 +                               , &leader_len, &leader_flags, do_comments
1227 + #endif
1228 +               ))
1229 +       return TRUE;            /* after non-paragraph line */
1230
1231 +     if (fmt_check_par(lnum
1232 + #ifdef FEAT_COMMENTS
1233 +                          , &next_leader_len, &next_leader_flags, do_comments
1234 + #endif
1235 +               ))
1236 +       return TRUE;            /* "lnum" is not a paragraph line */
1237
1238 +     if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1))
1239 +       return TRUE;            /* missing trailing space in previous line. */
1240
1241 +     if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0))
1242 +       return TRUE;            /* numbered item starts in "lnum". */
1243
1244 + #ifdef FEAT_COMMENTS
1245 +     if (!same_leader(leader_len, leader_flags,
1246 +                                         next_leader_len, next_leader_flags))
1247 +       return TRUE;            /* change of comment leader. */
1248 + #endif
1249
1250 +     return FALSE;
1251 + }
1252   
1253   #ifdef FEAT_VISUAL
1254   /*
1255 *** ../vim-6.2.326/src/proto/edit.pro   Sun Jan 18 20:28:27 2004
1256 --- src/proto/edit.pro  Mon Mar  8 10:11:10 2004
1257 ***************
1258 *** 13,19 ****
1259   void ins_compl_check_keys __ARGS((void));
1260   int get_literal __ARGS((void));
1261   void insertchar __ARGS((int c, int flags, int second_indent));
1262 ! void auto_format __ARGS((int trailblank));
1263   int comp_textwidth __ARGS((int ff));
1264   int stop_arrow __ARGS((void));
1265   void set_last_insert __ARGS((int c));
1266 --- 13,19 ----
1267   void ins_compl_check_keys __ARGS((void));
1268   int get_literal __ARGS((void));
1269   void insertchar __ARGS((int c, int flags, int second_indent));
1270 ! void auto_format __ARGS((int trailblank, int prev_line));
1271   int comp_textwidth __ARGS((int ff));
1272   int stop_arrow __ARGS((void));
1273   void set_last_insert __ARGS((int c));
1274 *** ../vim-6.2.326/src/proto/mark.pro   Sun Feb 29 20:46:43 2004
1275 --- src/proto/mark.pro  Tue Mar  2 21:23:55 2004
1276 ***************
1277 *** 14,19 ****
1278 --- 14,20 ----
1279   void ex_jumps __ARGS((exarg_T *eap));
1280   void ex_changes __ARGS((exarg_T *eap));
1281   void mark_adjust __ARGS((linenr_T line1, linenr_T line2, long amount, long amount_after));
1282 + void mark_col_adjust __ARGS((linenr_T lnum, colnr_T mincol, long lnum_amount, long col_amount));
1283   void copy_jumplist __ARGS((win_T *from, win_T *to));
1284   void free_jumplist __ARGS((win_T *wp));
1285   void set_last_cursor __ARGS((win_T *win));
1286 *** ../vim-6.2.326/src/proto/ops.pro    Sun Jun  1 12:26:17 2003
1287 --- src/proto/ops.pro   Thu Mar  4 22:51:23 2004
1288 ***************
1289 *** 31,38 ****
1290   void ex_display __ARGS((exarg_T *eap));
1291   void do_do_join __ARGS((long count, int insert_space));
1292   int do_join __ARGS((int insert_space));
1293 ! void op_format __ARGS((oparg_T *oap));
1294   void format_lines __ARGS((linenr_T line_count));
1295   int do_addsub __ARGS((int command, linenr_T Prenum1));
1296   int read_viminfo_register __ARGS((vir_T *virp, int force));
1297   void write_viminfo_registers __ARGS((FILE *fp));
1298 --- 31,39 ----
1299   void ex_display __ARGS((exarg_T *eap));
1300   void do_do_join __ARGS((long count, int insert_space));
1301   int do_join __ARGS((int insert_space));
1302 ! void op_format __ARGS((oparg_T *oap, int keep_cursor));
1303   void format_lines __ARGS((linenr_T line_count));
1304 + int paragraph_start __ARGS((linenr_T lnum));
1305   int do_addsub __ARGS((int command, linenr_T Prenum1));
1306   int read_viminfo_register __ARGS((vir_T *virp, int force));
1307   void write_viminfo_registers __ARGS((FILE *fp));
1308 *** ../vim-6.2.326/src/structs.h        Mon Mar  1 17:11:04 2004
1309 --- src/structs.h       Thu Mar  4 13:44:30 2004
1310 ***************
1311 *** 32,37 ****
1312 --- 32,43 ----
1313   #endif
1314   } pos_T;
1315   
1316 + #ifdef FEAT_VIRTUALEDIT
1317 + # define INIT_POS_T {0, 0, 0}
1318 + #else
1319 + # define INIT_POS_T {0, 0}
1320 + #endif
1321
1322   /*
1323    * Same, but without coladd.
1324    */
1325 *** ../vim-6.2.326/src/vim.h    Mon Mar  1 17:11:04 2004
1326 --- src/vim.h   Thu Mar  4 22:50:17 2004
1327 ***************
1328 *** 848,853 ****
1329 --- 848,854 ----
1330   #define OPENLINE_DELSPACES  1 /* delete spaces after cursor */
1331   #define OPENLINE_DO_COM           2   /* format comments */
1332   #define OPENLINE_KEEPTRAIL  4 /* keep trailing spaces */
1333 + #define OPENLINE_MARKFIX    8 /* fix mark positions */
1334   
1335   /*
1336    * There are four history tables:
1337 ***************
1338 *** 1118,1123 ****
1339 --- 1119,1125 ----
1340   #define OP_FOLDCLOSEREC       23      /* "zC" close folds recursively */
1341   #define OP_FOLDDEL    24      /* "zd" delete folds */
1342   #define OP_FOLDDELREC 25      /* "zD" delete folds recursively */
1343 + #define OP_FORMAT2    26      /* "gw" format operator, keeps cursor pos */
1344   
1345   /*
1346    * Motion types, used for operators and for yank/delete registers.
1347 *** ../vim-6.2.326/src/version.c        Sun Mar  7 19:33:55 2004
1348 --- src/version.c       Mon Mar  8 12:12:35 2004
1349 ***************
1350 *** 639,640 ****
1351 --- 639,642 ----
1352   {   /* Add new patch number below this line */
1353 + /**/
1354 +     327,
1355   /**/
1356
1357 -- 
1358 A fool must search for a greater fool to find admiration.
1359
1360  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
1361 ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
1362 \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
1363  \\\  Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
This page took 0.1331 seconds and 3 git commands to generate.