4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
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
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
27 ! *change.txt* For Vim version 6.2. Last change: 2003 May 24
30 VIM REFERENCE MANUAL by Bram Moolenaar
32 ! *change.txt* For Vim version 6.2. Last change: 2004 Mar 04
35 VIM REFERENCE MANUAL by Bram Moolenaar
38 {Visual}gq Format the highlighted text. (for {Visual} see
39 |Visual-mode|). {not in Vi}
41 ! Example: To format the current paragraph use: >
44 The "gq" command leaves the cursor in the line where the motion command takes
46 {Visual}gq Format the highlighted text. (for {Visual} see
47 |Visual-mode|). {not in Vi}
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.
55 ! Example: To format the current paragraph use: *gqap* >
58 The "gq" command leaves the cursor in the line where the motion command takes
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).
66 + If you want to format the current paragraph and continue where you were, use: >
68 + If you always want to keep paragraphs formatted you may want to add the 'a'
69 + flag to 'formatoptions'. See |auto-format|.
71 If the 'autoindent' option is on, Vim uses the indent of the first line for
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
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));
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));
89 /* insert the contents of a register */
93 inserted_space = FALSE;
97 /* insert the contents of a register */
100 ! auto_format(FALSE, TRUE);
101 inserted_space = FALSE;
109 ! auto_format(FALSE);
110 inserted_space = FALSE;
117 ! auto_format(FALSE, TRUE);
118 inserted_space = FALSE;
126 ! auto_format(FALSE);
129 /* delete character before the cursor */
132 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
133 ! auto_format(FALSE);
136 /* delete word before the cursor */
138 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
139 ! auto_format(FALSE);
142 /* delete all inserted text in current line */
144 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
145 ! auto_format(FALSE);
146 inserted_space = FALSE;
153 ! auto_format(FALSE, TRUE);
156 /* delete character before the cursor */
159 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
160 ! auto_format(FALSE, TRUE);
163 /* delete word before the cursor */
165 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
166 ! auto_format(FALSE, TRUE);
169 /* delete all inserted text in current line */
171 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
172 ! auto_format(FALSE, TRUE);
173 inserted_space = FALSE;
178 inserted_space = FALSE;
180 goto normalchar; /* insert TAB as a normal char */
181 ! auto_format(FALSE);
186 inserted_space = FALSE;
188 goto normalchar; /* insert TAB as a normal char */
189 ! auto_format(FALSE, TRUE);
196 if (ins_eol(c) && !p_im)
197 goto doESCkey; /* out of memory */
198 ! auto_format(FALSE);
199 inserted_space = FALSE;
204 if (ins_eol(c) && !p_im)
205 goto doESCkey; /* out of memory */
206 ! auto_format(FALSE, FALSE);
207 inserted_space = FALSE;
214 c = Ctrl_V; /* pretend CTRL-V is last character */
215 ! auto_format(FALSE);
222 c = Ctrl_V; /* pretend CTRL-V is last character */
223 ! auto_format(FALSE, TRUE);
232 ! auto_format(FALSE);
235 /* When inserting a character the cursor line must never be in a
240 ! auto_format(FALSE, TRUE);
243 /* When inserting a character the cursor line must never be in a
246 if (State & VREPLACE_FLAG)
248 /* If orig_line didn't allocate, just return. At least we did the job,
249 ! * even if you can't backspace.
251 if (orig_line == NULL)
255 if (State & VREPLACE_FLAG)
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)
264 curwin->w_cursor.col++;
267 ! auto_format(FALSE);
270 started_completion = FALSE;
272 curwin->w_cursor.col++;
275 ! auto_format(FALSE, TRUE);
278 started_completion = FALSE;
281 * Split the line just before the margin.
282 * Only insert/delete lines, but don't really redraw the window.
284 ! open_line(FORWARD, OPENLINE_DELSPACES
285 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
287 + (do_comments ? OPENLINE_DO_COM : 0)
289 * Split the line just before the margin.
290 * Only insert/delete lines, but don't really redraw the window.
292 ! open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
293 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
295 + (do_comments ? OPENLINE_DO_COM : 0)
301 ! auto_format(trailblank)
302 int trailblank; /* when TRUE also format with trailing blank */
306 ! char_u *old, *pold;
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 */
329 ! old = vim_strsave(old);
330 ! format_lines((linenr_T)-1);
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;
339 ! if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
341 ! curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
342 ! curwin->w_cursor.col = MAXCOL;
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);
356 ! /* Skip the leader if the old text matches after it, ignoring
357 ! * white space. Keep in mind that the leader may appear in
359 ! p = skipwhite(new + len);
360 ! if (cmplen(pold, pnew) < cmplen(pold, p))
365 ! len = (colnr_T)STRLEN(pnew);
366 ! if ((pold - old) + len >= pos.col)
368 ! if (pos.col <= (colnr_T)(pold - old))
369 ! curwin->w_cursor.col = (pnew - new);
371 ! curwin->w_cursor.col = pos.col - (pold - old) + (pnew - new);
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))
380 ! if (curwin->w_cursor.col == len)
382 ! pnew = vim_strnsave(new, len + 2);
384 ! pnew[len + 1] = NUL;
385 ! ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
386 ! /* remove the space later */
387 ! did_add_space = TRUE;
390 ! /* may remove added space */
391 ! check_auto_format(FALSE);
395 ! /* Cursor wraps to next line */
396 ! ++curwin->w_cursor.lnum;
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.
413 ! if (prev_line && !paragraph_start(curwin->w_cursor.lnum))
415 ! --curwin->w_cursor.lnum;
416 ! if (u_save_cursor() == FAIL)
421 ! * Do the formatting and restore the cursor position. "saved_cursor" will
422 ! * be adjusted for the text formatting.
424 ! saved_cursor = pos;
425 ! format_lines((linenr_T)-1);
426 ! curwin->w_cursor = saved_cursor;
427 ! saved_cursor.lnum = 0;
429 ! if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
431 ! /* "cannot happen" */
432 ! curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
433 ! coladvance((colnr_T)MAXCOL);
436 ! check_cursor_col();
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
442 ! if (!wasatend && has_format_option(FO_WHITE_PAR))
444 ! new = ml_get_curline();
446 ! if (curwin->w_cursor.col == len)
448 ! pnew = vim_strnsave(new, len + 2);
450 ! pnew[len + 1] = NUL;
451 ! ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
452 ! /* remove the space later */
453 ! did_add_space = TRUE;
456 ! /* may remove added space */
457 ! check_auto_format(FALSE);
469 - #ifdef FEAT_COMMENTS
471 - * Return the number of bytes for which strings "s1" and "s2" are equal.
478 - char_u *p1 = s1, *p2 = s2;
480 - while (*p1 == *p2 && *p1 != NUL)
485 - return (int)(p1 - s1);
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.
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.
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. */
518 /* If a space was inserted for auto-formatting, remove it now. */
519 check_auto_format(TRUE);
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. */
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. */
529 ! if (curwin->w_cursor.col > 0 == NUL && gchar_cursor())
532 ! cc = gchar_cursor();
533 ! if (!vim_iswhite(cc))
537 ! auto_format(TRUE, FALSE);
539 ! if (vim_iswhite(cc) && gchar_cursor() != NUL)
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
550 EXTERN int can_si_back INIT(= FALSE);
553 + EXTERN pos_T saved_cursor /* w_cursor before formatting text. */
560 * Stuff for insert mode.
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
567 /* previous pcmark */
568 one_adjust(&(curwin->w_prev_pcmark.lnum));
570 + /* saved cursor for formatting */
571 + if (saved_cursor.lnum != 0)
572 + one_adjust_nodel(&(saved_cursor.lnum));
575 * Adjust items in all windows related to the current buffer.
581 diff_mark_adjust(line1, line2, amount, amount_after);
585 + /* This code is used often, needs to be fast. */
586 + #define col_adjust(pp) \
589 + if (posp->lnum == lnum && posp->col >= mincol) \
591 + posp->lnum += lnum_amount; \
592 + if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \
595 + posp->col += col_amount; \
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
605 + mark_col_adjust(lnum, mincol, lnum_amount, col_amount)
612 + int fnum = curbuf->b_fnum;
616 + if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks)
617 + return; /* nothing to do */
619 + /* named marks, lower case and upper case */
620 + for (i = 0; i < NMARKS; i++)
622 + col_adjust(&(curbuf->b_namedm[i]));
623 + if (namedfm[i].fmark.fnum == fnum)
624 + col_adjust(&(namedfm[i].fmark.mark));
626 + for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++)
628 + if (namedfm[i].fmark.fnum == fnum)
629 + col_adjust(&(namedfm[i].fmark.mark));
632 + /* last Insert position */
633 + col_adjust(&(curbuf->b_last_insert));
635 + /* last change position */
636 + col_adjust(&(curbuf->b_last_change));
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]));
646 + col_adjust(&(curbuf->b_visual_start));
647 + col_adjust(&(curbuf->b_visual_end));
650 + /* previous context mark */
651 + col_adjust(&(curwin->w_pcmark));
653 + /* previous pcmark */
654 + col_adjust(&(curwin->w_prev_pcmark));
656 + /* saved cursor for formatting */
657 + col_adjust(&saved_cursor);
660 + * Adjust items in all windows related to the current buffer.
662 + FOR_ALL_WINDOWS(win)
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));
671 + if (win->w_buffer == curbuf)
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));
678 + /* cursor position for other windows with the same buffer */
680 + col_adjust(&win->w_cursor);
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
711 ! p = ml_get_curline();
713 /* Calculate the buffer size for the new indent, and check to see if it
714 * isn't already set */
719 ! p = oldline = ml_get_curline();
721 /* Calculate the buffer size for the new indent, and check to see if it
722 * isn't already set */
726 /* Allocate memory for the new line. */
727 if (flags & SIN_INSERT)
728 ! p = ml_get_curline();
731 line_len = (int)STRLEN(p) + 1;
732 ! line = alloc(ind_len + line_len);
736 /* Put the characters in the new line. */
739 /* if 'expandtab' isn't set: use TABs */
743 /* Allocate memory for the new line. */
744 if (flags & SIN_INSERT)
748 line_len = (int)STRLEN(p) + 1;
749 ! newline = alloc(ind_len + line_len);
750 ! if (newline == NULL)
753 /* Put the characters in the new line. */
756 /* if 'expandtab' isn't set: use TABs */
760 * the existing indent structure for the new indent */
761 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
763 ! p = ml_get_curline();
766 while (todo > 0 && vim_iswhite(*p))
768 * the existing indent structure for the new indent */
769 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
774 while (todo > 0 && vim_iswhite(*p))
777 /* Replace the line (unless undo fails). */
778 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
780 ! ml_replace(curwin->w_cursor.lnum, line, FALSE);
781 if (flags & SIN_CHANGED)
782 changed_bytes(curwin->w_cursor.lnum, 0);
787 curwin->w_cursor.col = ind_len;
790 /* Replace the line (unless undo fails). */
791 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
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);
804 curwin->w_cursor.col = ind_len;
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.
814 get_number_indent(lnum)
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.
822 get_number_indent(lnum)
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
829 * Return TRUE for success, FALSE for failure
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 */
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 */
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
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
852 * Return TRUE for success, FALSE for failure
855 open_line(dir, flags, old_indent)
856 int dir; /* FORWARD or BACKWARD */
858 int old_indent; /* indent for after ^^D in Insert mode */
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 */
871 if (REPLACE_NORMAL(State))
872 replace_push(*p_extra);
878 did_ai = FALSE; /* append some text, don't truncate now */
880 + /* columns for marks adjusted for removed columns */
881 + less_cols = (int)(p_extra - saved_line);
888 STRCAT(leader, p_extra);
890 did_ai = TRUE; /* So truncating blanks works with comments */
891 + less_cols -= lead_len;
894 end_comment_pending = NUL; /* turns out there was no leader */
900 (void)set_indent(newindent, SIN_INSERT);
901 + less_cols -= curwin->w_cursor.col;
903 ai_col = curwin->w_cursor.col;
908 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
909 curwin->w_cursor.lnum + 1, 1L);
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);
919 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
925 - int save_msg_scroll = msg_scroll;
927 if (!curbuf->b_changed)
930 /* Create a swap file if that is wanted.
931 * Don't do this for "nofile" and "nowrite" buffer types. */
936 if (!curbuf->b_changed)
938 + int save_msg_scroll = msg_scroll;
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
947 oap->is_VIsual ? (int)cap->count1 :
950 ! auto_format(FALSE);
955 oap->is_VIsual ? (int)cap->count1 :
958 ! auto_format(FALSE, TRUE);
966 do_do_join(oap->line_count, oap->op_type == OP_JOIN);
967 ! auto_format(FALSE);
974 do_do_join(oap->line_count, oap->op_type == OP_JOIN);
975 ! auto_format(FALSE, TRUE);
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);
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);
999 op_colon(oap); /* use external command */
1001 ! op_format(oap); /* use internal function */
1007 op_colon(oap); /* use external command */
1009 ! op_format(oap, FALSE); /* use internal function */
1013 ! op_format(oap, TRUE); /* use internal function */
1020 /* TODO: when inserting in several lines, should format all
1022 ! auto_format(FALSE);
1024 if (restart_edit == 0)
1025 restart_edit = restart_edit_save;
1028 /* TODO: when inserting in several lines, should format all
1030 ! auto_format(FALSE, TRUE);
1032 if (restart_edit == 0)
1033 restart_edit = restart_edit_save;
1038 * Two-character operators:
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
1054 put_register(regname, reg2);
1056 ! auto_format(FALSE);
1062 put_register(regname, reg2);
1064 ! auto_format(FALSE, TRUE);
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
1073 {'z', 'C', TRUE}, /* OP_FOLDCLOSEREC */
1074 {'z', 'd', TRUE}, /* OP_FOLDDEL */
1075 {'z', 'D', TRUE}, /* OP_FOLDDELREC */
1076 + {'g', 'w', TRUE}, /* OP_FORMAT2 */
1087 int endcurr1, endcurr2;
1088 int currsize; /* size of the current line */
1093 ! char_u *next, *next_start;
1095 int endcurr1, endcurr2;
1096 int currsize; /* size of the current line */
1102 ! next = ml_get((linenr_T)(curwin->w_cursor.lnum + 1));
1110 ! next = next_start = ml_get((linenr_T)(curwin->w_cursor.lnum + 1));
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.
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.
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;
1133 * implementation of the format operator 'gq'
1139 long old_line_count = curbuf->b_ml.ml_line_count;
1142 * implementation of the format operator 'gq'
1145 ! op_format(oap, keep_cursor)
1147 + int keep_cursor; /* keep cursor on same text char */
1149 long old_line_count = curbuf->b_ml.ml_line_count;
1154 /* Set '[ mark at the start of the formatted area */
1155 curbuf->b_op_start = oap->start;
1158 + saved_cursor = curwin->w_cursor;
1160 format_lines(oap->line_count);
1166 /* put '] mark on the end of the formatted area */
1167 curbuf->b_op_end = curwin->w_cursor;
1171 + curwin->w_cursor = saved_cursor;
1172 + saved_cursor.lnum = 0;
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);
1188 curwin->w_cursor.lnum--;
1189 if (do_join(TRUE) == FAIL)
1193 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE));
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.
1202 + paragraph_start(lnum)
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 */
1215 + return TRUE; /* start of the file */
1217 + p = ml_get(lnum - 1);
1219 + return TRUE; /* after empty line */
1221 + #ifdef FEAT_COMMENTS
1222 + do_comments = has_format_option(FO_Q_COMS);
1224 + if (fmt_check_par(lnum - 1
1225 + #ifdef FEAT_COMMENTS
1226 + , &leader_len, &leader_flags, do_comments
1229 + return TRUE; /* after non-paragraph line */
1231 + if (fmt_check_par(lnum
1232 + #ifdef FEAT_COMMENTS
1233 + , &next_leader_len, &next_leader_flags, do_comments
1236 + return TRUE; /* "lnum" is not a paragraph line */
1238 + if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1))
1239 + return TRUE; /* missing trailing space in previous line. */
1241 + if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0))
1242 + return TRUE; /* numbered item starts in "lnum". */
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. */
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
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));
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
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
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));
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
1316 + #ifdef FEAT_VIRTUALEDIT
1317 + # define INIT_POS_T {0, 0, 0}
1319 + # define INIT_POS_T {0, 0}
1323 * Same, but without coladd.
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
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 */
1336 * There are four history tables:
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 */
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
1352 { /* Add new patch number below this line */
1358 A fool must search for a greater fool to find admiration.
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 ///