Mercurial > vim
annotate src/textformat.c @ 28791:4d35a70c3d5c
Added tag v8.2.4919 for changeset a161c262e94797d8a3bbd27031db4c3e8d449f60
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 08 May 2022 23:45:03 +0200 |
parents | d770568e6c98 |
children | d0241e74bfdb |
rev | line source |
---|---|
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * textformat.c: text formatting functions |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 static int did_add_space = FALSE; // auto_format() added an extra space |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 // under the cursor |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 #define WHITECHAR(cc) (VIM_ISWHITE(cc) && (!enc_utf8 || !utf_iscomposing(utf_ptr2char(ml_get_cursor() + 1)))) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 * Return TRUE if format option 'x' is in effect. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 * Take care of no formatting when 'paste' is set. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 int |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 has_format_option(int x) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 if (p_paste) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 return FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 return (vim_strchr(curbuf->b_p_fo, x) != NULL); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 * Format text at the current insert position. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 * |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 * If the INSCHAR_COM_LIST flag is present, then the value of second_indent |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 * will be the comment leader length sent to open_line(). |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 void |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 internal_format( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 int textwidth, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 int second_indent, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 int flags, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 int format_only, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 int c) // character to be inserted (can be NUL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 int cc; |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
48 int skip_pos; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 int save_char = NUL; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 int haveto_redraw = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 int fo_ins_blank = has_format_option(FO_INS_BLANK); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 int fo_multibyte = has_format_option(FO_MBYTE_BREAK); |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
53 int fo_rigor_tw = has_format_option(FO_RIGOROUS_TW); |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 int fo_white_par = has_format_option(FO_WHITE_PAR); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 int first_line = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 colnr_T leader_len; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 int no_leader = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 int do_comments = (flags & INSCHAR_DO_COM); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 #ifdef FEAT_LINEBREAK |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 int has_lbr = curwin->w_p_lbr; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 // make sure win_lbr_chartabsize() counts correctly |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 curwin->w_p_lbr = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 #endif |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 // When 'ai' is off we don't want a space under the cursor to be |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 // deleted. Replace it with an 'x' temporarily. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 if (!curbuf->b_p_ai && !(State & VREPLACE_FLAG)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 cc = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 if (VIM_ISWHITE(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 save_char = cc; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 pchar_cursor('x'); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 // Repeat breaking lines, until the current line is not too long. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 while (!got_int) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 int startcol; // Cursor column at entry |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 int wantcol; // column at textwidth border |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 int foundcol; // column for start of spaces |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 int end_foundcol = 0; // column for start of word |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 colnr_T len; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 colnr_T virtcol; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 int orig_col = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 char_u *saved_text = NULL; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 colnr_T col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 colnr_T end_col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 int wcc; // counter for whitespace chars |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26448
diff
changeset
|
92 int did_do_comment = FALSE; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 virtcol = get_nolist_virtcol() |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 + char2cells(c != NUL ? c : gchar_cursor()); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 if (virtcol <= (colnr_T)textwidth) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 if (no_leader) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 do_comments = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 else if (!(flags & INSCHAR_FORMAT) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 && has_format_option(FO_WRAP_COMS)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 do_comments = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 // Don't break until after the comment leader |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 if (do_comments) |
28767
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
107 { |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
108 char_u *line = ml_get_curline(); |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
109 |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
110 leader_len = get_leader_len(line, NULL, FALSE, TRUE); |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
111 #ifdef FEAT_CINDENT |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
112 if (leader_len == 0 && curbuf->b_p_cin) |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
113 { |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
114 int comment_start; |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
115 |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
116 // Check for a line comment after code. |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
117 comment_start = check_linecomment(line); |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
118 if (comment_start != MAXCOL) |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
119 { |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
120 leader_len = get_leader_len( |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
121 line + comment_start, NULL, FALSE, TRUE); |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
122 if (leader_len != 0) |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
123 leader_len += comment_start; |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
124 } |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
125 } |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
126 #endif |
7bbd859b2a48
patch 8.2.4908: no text formatting for // comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
27309
diff
changeset
|
127 } |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 leader_len = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 // If the line doesn't start with a comment leader, then don't |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 // start one in a following broken line. Avoids that a %word |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 // moved to the start of the next line causes all following lines |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 // to start with %. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 if (leader_len == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 no_leader = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 if (!(flags & INSCHAR_FORMAT) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 && leader_len == 0 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 && !has_format_option(FO_WRAP)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 if ((startcol = curwin->w_cursor.col) == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 // find column of textwidth border |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 coladvance((colnr_T)textwidth); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 wantcol = curwin->w_cursor.col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 curwin->w_cursor.col = startcol; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 foundcol = 0; |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
151 skip_pos = 0; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 // Find position to break at. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 // Stop at first entered white when 'formatoptions' has 'v' |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 while ((!fo_ins_blank && !has_format_option(FO_INS_VI)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 || (flags & INSCHAR_FORMAT) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 || curwin->w_cursor.lnum != Insstart.lnum |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 || curwin->w_cursor.col >= Insstart.col) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 if (curwin->w_cursor.col == startcol && c != NUL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 cc = c; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 cc = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 if (WHITECHAR(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 // remember position of blank just before text |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 end_col = curwin->w_cursor.col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 // find start of sequence of blanks |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 wcc = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 while (curwin->w_cursor.col > 0 && WHITECHAR(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 dec_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 cc = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 // Increment count of how many whitespace chars in this |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 // group; we only need to know if it's more than one. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 if (wcc < 2) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 wcc++; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 if (curwin->w_cursor.col == 0 && WHITECHAR(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 break; // only spaces in front of text |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 // Don't break after a period when 'formatoptions' has 'p' and |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 // there are less than two spaces. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 if (has_format_option(FO_PERIOD_ABBR) && cc == '.' && wcc < 2) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 continue; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 // Don't break until after the comment leader |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 if (curwin->w_cursor.col < leader_len) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 if (has_format_option(FO_ONE_LETTER)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
194 // do not break after one-letter words |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
195 if (curwin->w_cursor.col == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
196 break; // one-letter word at begin |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 // do not break "#a b" when 'tw' is 2 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 if (curwin->w_cursor.col <= leader_len) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 col = curwin->w_cursor.col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
201 dec_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 cc = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 if (WHITECHAR(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 continue; // one-letter, continue |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 curwin->w_cursor.col = col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 inc_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 end_foundcol = end_col + 1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 foundcol = curwin->w_cursor.col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 if (curwin->w_cursor.col <= (colnr_T)wantcol) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 } |
26807
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
216 else if ((cc >= 0x100 || !utf_allow_break_before(cc)) |
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
217 && fo_multibyte) |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 { |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
219 int ncc; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
220 int allow_break; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
221 |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 // Break after or before a multi-byte character. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 if (curwin->w_cursor.col != startcol) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 // Don't break until after the comment leader |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 if (curwin->w_cursor.col < leader_len) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 col = curwin->w_cursor.col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 inc_cursor(); |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
230 ncc = gchar_cursor(); |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
231 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
232 allow_break = |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
233 (enc_utf8 && utf_allow_break(cc, ncc)) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
234 || enc_dbcs; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
235 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
236 // If we have already checked this position, skip! |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
237 if (curwin->w_cursor.col != skip_pos && allow_break) |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 foundcol = curwin->w_cursor.col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 end_foundcol = foundcol; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 if (curwin->w_cursor.col <= (colnr_T)wantcol) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 curwin->w_cursor.col = col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 if (curwin->w_cursor.col == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
250 ncc = cc; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 col = curwin->w_cursor.col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 dec_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 cc = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 if (WHITECHAR(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 continue; // break with space |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
258 // Don't break until after the comment leader. |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 if (curwin->w_cursor.col < leader_len) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 curwin->w_cursor.col = col; |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
263 skip_pos = curwin->w_cursor.col; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
265 allow_break = |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
266 (enc_utf8 && utf_allow_break(cc, ncc)) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
267 || enc_dbcs; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
268 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
269 // Must handle this to respect line break prohibition. |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
270 if (allow_break) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
271 { |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
272 foundcol = curwin->w_cursor.col; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
273 end_foundcol = foundcol; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
274 } |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 if (curwin->w_cursor.col <= (colnr_T)wantcol) |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
276 { |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
277 int ncc_allow_break = |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
278 (enc_utf8 && utf_allow_break_before(ncc)) || enc_dbcs; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
279 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
280 if (allow_break) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
281 break; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
282 if (!ncc_allow_break && !fo_rigor_tw) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
283 { |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
284 // Enable at most 1 punct hang outside of textwidth. |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
285 if (curwin->w_cursor.col == startcol) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
286 { |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
287 // We are inserting a non-breakable char, postpone |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
288 // line break check to next insert. |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
289 end_foundcol = foundcol = 0; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
290 break; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
291 } |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
292 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
293 // Neither cc nor ncc is NUL if we are here, so |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
294 // it's safe to inc_cursor. |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
295 col = curwin->w_cursor.col; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
296 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
297 inc_cursor(); |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
298 cc = ncc; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
299 ncc = gchar_cursor(); |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
300 // handle insert |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
301 ncc = (ncc != NUL) ? ncc : c; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
302 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
303 allow_break = |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
304 (enc_utf8 && utf_allow_break(cc, ncc)) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
305 || enc_dbcs; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
306 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
307 if (allow_break) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
308 { |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
309 // Break only when we are not at end of line. |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
310 end_foundcol = foundcol = |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
311 ncc == NUL? 0 : curwin->w_cursor.col; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
312 break; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
313 } |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
314 curwin->w_cursor.col = col; |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
315 } |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
316 } |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
317 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
318 if (curwin->w_cursor.col == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
319 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
320 dec_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
321 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
322 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
323 if (foundcol == 0) // no spaces, cannot break line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
324 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
325 curwin->w_cursor.col = startcol; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
326 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
327 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
328 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
329 // Going to break the line, remove any "$" now. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
330 undisplay_dollar(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
331 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
332 // Offset between cursor position and line break is used by replace |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28767
diff
changeset
|
333 // stack functions. MODE_VREPLACE does not use this, and backspaces |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
334 // over the text instead. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
335 if (State & VREPLACE_FLAG) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
336 orig_col = startcol; // Will start backspacing from here |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
337 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
338 replace_offset = startcol - end_foundcol; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
339 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
340 // adjust startcol for spaces that will be deleted and |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
341 // characters that will remain on top line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
342 curwin->w_cursor.col = foundcol; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
343 while ((cc = gchar_cursor(), WHITECHAR(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
344 && (!fo_white_par || curwin->w_cursor.col < startcol)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
345 inc_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
346 startcol -= curwin->w_cursor.col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
347 if (startcol < 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
348 startcol = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
349 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
350 if (State & VREPLACE_FLAG) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
351 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28767
diff
changeset
|
352 // In MODE_VREPLACE state, we will backspace over the text to be |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 // wrapped, so save a copy now to put on the next line. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
354 saved_text = vim_strsave(ml_get_cursor()); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 curwin->w_cursor.col = orig_col; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 if (saved_text == NULL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 break; // Can't do it, out of memory |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 saved_text[startcol] = NUL; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 // Backspace over characters that will move to the next line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 if (!fo_white_par) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 backspace_until_column(foundcol); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
365 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
366 // put cursor after pos. to break line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
367 if (!fo_white_par) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
368 curwin->w_cursor.col = foundcol; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
369 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
370 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
371 // Split the line just before the margin. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 // Only insert/delete lines, but don't really redraw the window. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
373 open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 + (do_comments ? OPENLINE_DO_COM : 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 + ((flags & INSCHAR_COM_LIST) ? OPENLINE_COM_LIST : 0) |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26448
diff
changeset
|
377 , ((flags & INSCHAR_COM_LIST) ? second_indent : old_indent), |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26448
diff
changeset
|
378 &did_do_comment); |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
379 if (!(flags & INSCHAR_COM_LIST)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 old_indent = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
381 |
26516
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26448
diff
changeset
|
382 // If a comment leader was inserted, may also do this on a following |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26448
diff
changeset
|
383 // line. |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26448
diff
changeset
|
384 if (did_do_comment) |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26448
diff
changeset
|
385 no_leader = FALSE; |
9596c652420b
patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents:
26448
diff
changeset
|
386 |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 replace_offset = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 if (first_line) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 if (!(flags & INSCHAR_COM_LIST)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 // This section is for auto-wrap of numeric lists. When not |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 // in insert mode (i.e. format_lines()), the INSCHAR_COM_LIST |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
394 // flag will be set and open_line() will handle it (as seen |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 // above). The code here (and in get_number_indent()) will |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 // recognize comments if needed... |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 if (second_indent < 0 && has_format_option(FO_Q_NUMBER)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 second_indent = |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 get_number_indent(curwin->w_cursor.lnum - 1); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 if (second_indent >= 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
402 if (State & VREPLACE_FLAG) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 change_indent(INDENT_SET, second_indent, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 FALSE, NUL, TRUE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 if (leader_len > 0 && second_indent - leader_len > 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 int i; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 int padding = second_indent - leader_len; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 // We started at the first_line of a numbered list |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 // that has a comment. the open_line() function has |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 // inserted the proper comment leader and positioned |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 // the cursor at the end of the split line. Now we |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 // add the additional whitespace needed after the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 // comment leader for the numbered list. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 for (i = 0; i < padding; i++) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 ins_str((char_u *)" "); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 (void)set_indent(second_indent, SIN_CHANGED); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 first_line = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 if (State & VREPLACE_FLAG) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 { |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28767
diff
changeset
|
431 // In MODE_VREPLACE state we have backspaced over the text to be |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 // moved, now we re-insert it into the new line. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 ins_bytes(saved_text); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 vim_free(saved_text); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 // Check if cursor is not past the NUL off the line, cindent |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 // may have added or removed indent. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 curwin->w_cursor.col += startcol; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 len = (colnr_T)STRLEN(ml_get_curline()); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 if (curwin->w_cursor.col > len) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 curwin->w_cursor.col = len; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 haveto_redraw = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 #ifdef FEAT_CINDENT |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 set_can_cindent(TRUE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 #endif |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 // moved the cursor, don't autoindent or cindent now |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 did_ai = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 #ifdef FEAT_SMARTINDENT |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 did_si = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 can_si = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 can_si_back = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 #endif |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 line_breakcheck(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 if (save_char != NUL) // put back space after cursor |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 pchar_cursor(save_char); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 #ifdef FEAT_LINEBREAK |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 curwin->w_p_lbr = has_lbr; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 #endif |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 if (!format_only && haveto_redraw) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 update_topline(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 redraw_curbuf_later(VALID); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
474 * Blank lines, and lines containing only the comment leader, are left |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
475 * untouched by the formatting. The function returns TRUE in this |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
476 * case. It also returns TRUE when a line starts with the end of a comment |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
477 * ('e' in comment flags), so that this line is skipped, and not joined to the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
478 * previous line. A new paragraph starts after a blank line, or when the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 * comment leader changes -- webb. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 static int |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 fmt_check_par( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 linenr_T lnum, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
484 int *leader_len, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
485 char_u **leader_flags, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
486 int do_comments) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
487 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
488 char_u *flags = NULL; // init for GCC |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 char_u *ptr; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 ptr = ml_get(lnum); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 if (do_comments) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 *leader_len = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 if (*leader_len > 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 // Search for 'e' flag in comment leader flags. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 flags = *leader_flags; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 while (*flags && *flags != ':' && *flags != COM_END) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 ++flags; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 return (*skipwhite(ptr + *leader_len) == NUL |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 || (*leader_len > 0 && *flags == COM_END) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 || startPS(lnum, NUL, FALSE)); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 * Return TRUE if line "lnum" ends in a white character. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
512 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 static int |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 ends_in_white(linenr_T lnum) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 char_u *s = ml_get(lnum); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 size_t l; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 if (*s == NUL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 return FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 // Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 // invocation may call function multiple times". |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 l = STRLEN(s) - 1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 return VIM_ISWHITE(s[l]); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 * Return TRUE if the two comment leaders given are the same. "lnum" is |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 * the first line. White-space is ignored. Note that the whole of |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 static int |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 same_leader( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 linenr_T lnum, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 int leader1_len, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 char_u *leader1_flags, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 int leader2_len, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 char_u *leader2_flags) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
539 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 int idx1 = 0, idx2 = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 char_u *p; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 char_u *line1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 char_u *line2; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
544 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 if (leader1_len == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 return (leader2_len == 0); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 // If first leader has 'f' flag, the lines can be joined only if the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 // second line does not have a leader. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 // If first leader has 'e' flag, the lines can never be joined. |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26516
diff
changeset
|
551 // If first leader has 's' flag, the lines can only be joined if there is |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 // some text after it and the second line has the 'm' flag. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 if (leader1_flags != NULL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
554 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 for (p = leader1_flags; *p && *p != ':'; ++p) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 if (*p == COM_FIRST) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 return (leader2_len == 0); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 if (*p == COM_END) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 return FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 if (*p == COM_START) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 if (*(ml_get(lnum) + leader1_len) == NUL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 return FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 if (leader2_flags == NULL || leader2_len == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 return FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 for (p = leader2_flags; *p && *p != ':'; ++p) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 if (*p == COM_MIDDLE) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 return TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 return FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 // Get current line and next line, compare the leaders. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
576 // The first line has to be saved, only one line can be locked at a time. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
577 line1 = vim_strsave(ml_get(lnum)); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
578 if (line1 != NULL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
579 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
580 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
581 ; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
582 line2 = ml_get(lnum + 1); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 for (idx2 = 0; idx2 < leader2_len; ++idx2) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 if (!VIM_ISWHITE(line2[idx2])) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 if (line1[idx1++] != line2[idx2]) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
590 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 while (VIM_ISWHITE(line1[idx1])) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
592 ++idx1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 vim_free(line1); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 return (idx2 == leader2_len && idx1 == leader1_len); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
598 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 * previous line is in the same paragraph. Used for auto-formatting. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 static int |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 paragraph_start(linenr_T lnum) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 char_u *p; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 int leader_len = 0; // leader len of current line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 char_u *leader_flags = NULL; // flags for leader of current line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 int next_leader_len; // leader len of next line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 char_u *next_leader_flags; // flags for leader of next line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 int do_comments; // format comments |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 if (lnum <= 1) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 return TRUE; // start of the file |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
615 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 p = ml_get(lnum - 1); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 if (*p == NUL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 return TRUE; // after empty line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 do_comments = has_format_option(FO_Q_COMS); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 if (fmt_check_par(lnum - 1, &leader_len, &leader_flags, do_comments)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 return TRUE; // after non-paragraph line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 if (fmt_check_par(lnum, &next_leader_len, &next_leader_flags, do_comments)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 return TRUE; // "lnum" is not a paragraph line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 return TRUE; // missing trailing space in previous line. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 return TRUE; // numbered item starts in "lnum". |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 if (!same_leader(lnum - 1, leader_len, leader_flags, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
634 next_leader_len, next_leader_flags)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
635 return TRUE; // change of comment leader. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
636 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
637 return FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
638 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
639 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
640 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
641 * Called after inserting or deleting text: When 'formatoptions' includes the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
642 * 'a' flag format from the current line until the end of the paragraph. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 * Keep the cursor at the same position relative to the text. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 * The caller must have saved the cursor line for undo, following ones will be |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 * saved here. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 void |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 auto_format( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 int trailblank, // when TRUE also format with trailing blank |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 int prev_line) // may start in previous line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 pos_T pos; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 colnr_T len; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 char_u *old; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 char_u *new, *pnew; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 int wasatend; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 int cc; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 if (!has_format_option(FO_AUTO)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 return; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 pos = curwin->w_cursor; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 old = ml_get_curline(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 // may remove added space |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 check_auto_format(FALSE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 // Don't format in Insert mode when the cursor is on a trailing blank, the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 // user might insert normal text next. Also skip formatting when "1" is |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 // in 'formatoptions' and there is a single character before the cursor. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 // Otherwise the line would be broken and when typing another non-white |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 // next they are not joined back together. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 wasatend = (pos.col == (colnr_T)STRLEN(old)); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 if (*old != NUL && !trailblank && wasatend) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 dec_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 cc = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 if (!WHITECHAR(cc) && curwin->w_cursor.col > 0 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 && has_format_option(FO_ONE_LETTER)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 dec_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 cc = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 if (WHITECHAR(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 curwin->w_cursor = pos; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 return; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 curwin->w_cursor = pos; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 // With the 'c' flag in 'formatoptions' and 't' missing: only format |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 // comments. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 && get_leader_len(old, NULL, FALSE, TRUE) == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 return; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 // May start formatting in a previous line, so that after "x" a word is |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 // moved to the previous line if it fits there now. Only when this is not |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 // the start of a paragraph. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 if (prev_line && !paragraph_start(curwin->w_cursor.lnum)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 --curwin->w_cursor.lnum; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 if (u_save_cursor() == FAIL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 return; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 // Do the formatting and restore the cursor position. "saved_cursor" will |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 // be adjusted for the text formatting. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 saved_cursor = pos; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 format_lines((linenr_T)-1, FALSE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 curwin->w_cursor = saved_cursor; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 saved_cursor.lnum = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
712 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 // "cannot happen" |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 coladvance((colnr_T)MAXCOL); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 check_cursor_col(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 // Insert mode: If the cursor is now after the end of the line while it |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 // previously wasn't, the line was broken. Because of the rule above we |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 // need to add a space when 'w' is in 'formatoptions' to keep a paragraph |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 // formatted. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 if (!wasatend && has_format_option(FO_WHITE_PAR)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 new = ml_get_curline(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 len = (colnr_T)STRLEN(new); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 if (curwin->w_cursor.col == len) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 pnew = vim_strnsave(new, len + 2); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 pnew[len] = ' '; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 pnew[len + 1] = NUL; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 ml_replace(curwin->w_cursor.lnum, pnew, FALSE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 // remove the space later |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 did_add_space = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 // may remove added space |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 check_auto_format(FALSE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
742 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 check_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 * When an extra space was added to continue a paragraph for auto-formatting, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 * delete it now. The space must be under the cursor, just after the insert |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 * position. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 void |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 check_auto_format( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 int end_insert) // TRUE when ending Insert mode |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 int c = ' '; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 int cc; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 if (did_add_space) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 cc = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 if (!WHITECHAR(cc)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 // Somehow the space was removed already. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 did_add_space = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 if (!end_insert) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 inc_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 c = gchar_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 dec_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 if (c != NUL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 // The space is no longer at the end of the line, delete it. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 del_char(FALSE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 did_add_space = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 * Find out textwidth to be used for formatting: |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 * if 'textwidth' option is set, use it |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 * else if 'wrapmargin' option is set, use curwin->w_width - 'wrapmargin' |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 * if invalid value, use 0. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 * Set default to window width (maximum 79) for "gq" operator. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
790 int |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 comp_textwidth( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 int ff) // force formatting (for "gq" command) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
794 int textwidth; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 textwidth = curbuf->b_p_tw; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 if (textwidth == 0 && curbuf->b_p_wm) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 // The width is the window width minus 'wrapmargin' minus all the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 // things that add to the margin. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 textwidth = curwin->w_width - curbuf->b_p_wm; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
802 #ifdef FEAT_CMDWIN |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 if (cmdwin_type != 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 textwidth -= 1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 #endif |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 #ifdef FEAT_FOLDING |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 textwidth -= curwin->w_p_fdc; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 #endif |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 #ifdef FEAT_SIGNS |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 if (signcolumn_on(curwin)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 textwidth -= 1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 #endif |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 if (curwin->w_p_nu || curwin->w_p_rnu) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 textwidth -= 8; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 if (textwidth < 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 textwidth = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 if (ff && textwidth == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 textwidth = curwin->w_width - 1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 if (textwidth > 79) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 textwidth = 79; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 return textwidth; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 * Implementation of the format operator 'gq'. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 void |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 op_format( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 oparg_T *oap, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 int keep_cursor) // keep cursor on same text char |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 long old_line_count = curbuf->b_ml.ml_line_count; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 // Place the cursor where the "gq" or "gw" command was given, so that "u" |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 // can put it back there. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 curwin->w_cursor = oap->cursor_start; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
841 if (u_save((linenr_T)(oap->start.lnum - 1), |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 return; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 curwin->w_cursor = oap->start; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 if (oap->is_VIsual) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 // When there is no change: need to remove the Visual selection |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 redraw_curbuf_later(INVERTED); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
850 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 // Set '[ mark at the start of the formatted area |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 curbuf->b_op_start = oap->start; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 // For "gw" remember the cursor position and put it back below (adjusted |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 // for joined and split lines). |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 if (keep_cursor) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 saved_cursor = oap->cursor_start; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 format_lines(oap->line_count, keep_cursor); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 // Leave the cursor at the first non-blank of the last formatted line. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 // If the cursor was moved one line back (e.g. with "Q}") go to the next |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 // line, so "." will do the next lines. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 ++curwin->w_cursor.lnum; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 beginline(BL_WHITE | BL_FIX); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 msgmore(old_line_count); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
870 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 // put '] mark on the end of the formatted area |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 curbuf->b_op_end = curwin->w_cursor; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 if (keep_cursor) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 curwin->w_cursor = saved_cursor; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 saved_cursor.lnum = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 if (oap->is_VIsual) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
882 win_T *wp; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 FOR_ALL_WINDOWS(wp) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 if (wp->w_old_cursor_lnum != 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 // When lines have been inserted or deleted, adjust the end of |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 // the Visual area to be redrawn. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 wp->w_old_cursor_lnum += old_line_count; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 wp->w_old_visual_lnum += old_line_count; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 #if defined(FEAT_EVAL) || defined(PROTO) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 * Implementation of the format operator 'gq' for when using 'formatexpr'. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
902 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 void |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 op_formatexpr(oparg_T *oap) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 if (oap->is_VIsual) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
907 // When there is no change: need to remove the Visual selection |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 redraw_curbuf_later(INVERTED); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
911 // As documented: when 'formatexpr' returns non-zero fall back to |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
912 // internal formatting. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 op_format(oap, FALSE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 int |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
917 fex_format( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
918 linenr_T lnum, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
919 long count, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
920 int c) // character to be inserted |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 OPT_LOCAL); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 int r; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 char_u *fex; |
27309
391011658d95
patch 8.2.4183: cannot use an import in 'formatexpr'
Bram Moolenaar <Bram@vim.org>
parents:
26807
diff
changeset
|
926 sctx_T save_sctx = current_sctx; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 // Set v:lnum to the first line number and v:count to the number of lines. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 // Set v:char to the character to be inserted (can be NUL). |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 set_vim_var_nr(VV_LNUM, lnum); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 set_vim_var_nr(VV_COUNT, count); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 set_vim_var_char(c); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 // Make a copy, the option could be changed while calling it. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 fex = vim_strsave(curbuf->b_p_fex); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 if (fex == NULL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 return 0; |
27309
391011658d95
patch 8.2.4183: cannot use an import in 'formatexpr'
Bram Moolenaar <Bram@vim.org>
parents:
26807
diff
changeset
|
938 current_sctx = curbuf->b_p_script_ctx[BV_FEX]; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 // Evaluate the function. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
941 if (use_sandbox) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 ++sandbox; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 r = (int)eval_to_number(fex); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 if (use_sandbox) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
945 --sandbox; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 set_vim_var_string(VV_CHAR, NULL, -1); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 vim_free(fex); |
27309
391011658d95
patch 8.2.4183: cannot use an import in 'formatexpr'
Bram Moolenaar <Bram@vim.org>
parents:
26807
diff
changeset
|
949 current_sctx = save_sctx; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
951 return r; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 #endif |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
954 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 /* |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 * Format "line_count" lines, starting at the cursor position. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
957 * When "line_count" is negative, format until the end of the paragraph. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 * Lines after the cursor line are saved for undo, caller must have saved the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
959 * first line. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
960 */ |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 void |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 format_lines( |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 linenr_T line_count, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 int avoid_fex) // don't use 'formatexpr' |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 int max_len; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 int is_not_par; // current line not part of parag. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 int next_is_not_par; // next line not part of paragraph |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 int is_end_par; // at end of paragraph |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 int prev_is_end_par = FALSE;// prev. line not part of parag. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 int next_is_start_par = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 int leader_len = 0; // leader len of current line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 int next_leader_len; // leader len of next line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 char_u *leader_flags = NULL; // flags for leader of current line |
26807
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
975 char_u *next_leader_flags = NULL; // flags for leader of next line |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 int do_comments; // format comments |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 int do_comments_list = 0; // format comments with 'n' or '2' |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 int advance = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 int second_indent = -1; // indent for second line (comment |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 // aware) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 int do_second_indent; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 int do_number_indent; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 int do_trail_white; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 int first_par_line = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 int smd_save; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 long count; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 int need_set_indent = TRUE; // set indent of next paragraph |
26448
748793fcb4e2
patch 8.2.3754: undesired changing of the indent of the first formatted line
Bram Moolenaar <Bram@vim.org>
parents:
26167
diff
changeset
|
988 linenr_T first_line = curwin->w_cursor.lnum; |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 int force_format = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 int old_State = State; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 // length of a line to force formatting: 3 * 'tw' |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 max_len = comp_textwidth(TRUE) * 3; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 // check for 'q', '2' and '1' in 'formatoptions' |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 do_comments = has_format_option(FO_Q_COMS); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 do_second_indent = has_format_option(FO_Q_SECOND); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 do_number_indent = has_format_option(FO_Q_NUMBER); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 do_trail_white = has_format_option(FO_WHITE_PAR); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1001 // Get info about the previous and current line. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 if (curwin->w_cursor.lnum > 1) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1004 , &leader_len, &leader_flags, do_comments); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 is_not_par = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 , &next_leader_len, &next_leader_flags, do_comments); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 is_end_par = (is_not_par || next_is_not_par); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 if (!is_end_par && do_trail_white) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 curwin->w_cursor.lnum--; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 for (count = line_count; count != 0 && !got_int; --count) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 // Advance to next paragraph. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 if (advance) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 curwin->w_cursor.lnum++; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 prev_is_end_par = is_end_par; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 is_not_par = next_is_not_par; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 leader_len = next_leader_len; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 leader_flags = next_leader_flags; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 // The last line to be formatted. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 next_is_not_par = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 next_leader_len = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 next_leader_flags = NULL; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 , &next_leader_len, &next_leader_flags, do_comments); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 if (do_number_indent) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 next_is_start_par = |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 advance = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 if (!is_end_par && do_trail_white) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 is_end_par = !ends_in_white(curwin->w_cursor.lnum); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 // Skip lines that are not in a paragraph. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 if (is_not_par) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 if (line_count < 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 // For the first line of a paragraph, check indent of second line. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 // Don't do this for comments and empty lines. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 if (first_par_line |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 && (do_second_indent || do_number_indent) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 && prev_is_end_par |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 if (leader_len == 0 && next_leader_len == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 // no comment found |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1066 second_indent = |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 get_indent_lnum(curwin->w_cursor.lnum + 1); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1068 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 second_indent = next_leader_len; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 do_comments_list = 1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 else if (do_number_indent) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 if (leader_len == 0 && next_leader_len == 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 // no comment found |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 second_indent = |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 get_number_indent(curwin->w_cursor.lnum); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1083 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1084 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1085 // get_number_indent() is now "comment aware"... |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 second_indent = |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 get_number_indent(curwin->w_cursor.lnum); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 do_comments_list = 1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 // When the comment leader changes, it's the end of the paragraph. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 || !same_leader(curwin->w_cursor.lnum, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 leader_len, leader_flags, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 next_leader_len, next_leader_flags)) |
26807
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1098 { |
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1099 // Special case: If the next line starts with a line comment |
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1100 // and this line has a line comment after some text, the |
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1101 // paragraph doesn't really end. |
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1102 if (next_leader_flags == NULL |
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1103 || STRNCMP(next_leader_flags, "://", 3) != 0 |
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1104 || check_linecomment(ml_get_curline()) == MAXCOL) |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 is_end_par = TRUE; |
26807
c1e083481f5d
patch 8.2.3932: C line comment not formatted properly
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
1106 } |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 // If we have got to the end of a paragraph, or the line is |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 // getting long, format it. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 if (is_end_par || force_format) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 if (need_set_indent) |
26167
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1113 { |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1114 int indent = 0; // amount of indent needed |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1115 |
26448
748793fcb4e2
patch 8.2.3754: undesired changing of the indent of the first formatted line
Bram Moolenaar <Bram@vim.org>
parents:
26167
diff
changeset
|
1116 // Replace indent in first line of a paragraph with minimal |
748793fcb4e2
patch 8.2.3754: undesired changing of the indent of the first formatted line
Bram Moolenaar <Bram@vim.org>
parents:
26167
diff
changeset
|
1117 // number of tabs and spaces, according to current options. |
748793fcb4e2
patch 8.2.3754: undesired changing of the indent of the first formatted line
Bram Moolenaar <Bram@vim.org>
parents:
26167
diff
changeset
|
1118 // For the very first formatted line keep the current |
748793fcb4e2
patch 8.2.3754: undesired changing of the indent of the first formatted line
Bram Moolenaar <Bram@vim.org>
parents:
26167
diff
changeset
|
1119 // indent. |
748793fcb4e2
patch 8.2.3754: undesired changing of the indent of the first formatted line
Bram Moolenaar <Bram@vim.org>
parents:
26167
diff
changeset
|
1120 if (curwin->w_cursor.lnum == first_line) |
748793fcb4e2
patch 8.2.3754: undesired changing of the indent of the first formatted line
Bram Moolenaar <Bram@vim.org>
parents:
26167
diff
changeset
|
1121 indent = get_indent(); |
748793fcb4e2
patch 8.2.3754: undesired changing of the indent of the first formatted line
Bram Moolenaar <Bram@vim.org>
parents:
26167
diff
changeset
|
1122 else |
26167
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1123 # ifdef FEAT_LISP |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1124 if (curbuf->b_p_lisp) |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1125 indent = get_lisp_indent(); |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1126 else |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1127 # endif |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1128 { |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1129 #ifdef FEAT_CINDENT |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1130 if (cindent_on()) |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1131 { |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1132 indent = |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1133 # ifdef FEAT_EVAL |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1134 *curbuf->b_p_inde != NUL ? get_expr_indent() : |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1135 # endif |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1136 get_c_indent(); |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1137 } |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1138 else |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1139 #endif |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1140 indent = get_indent(); |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1141 } |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1142 (void)set_indent(indent, SIN_CHANGED); |
7108cee19a2c
patch 8.2.3615: wrong indent in first line if re-formatting with indent expr
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1143 } |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1144 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1145 // put cursor on last non-space |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28767
diff
changeset
|
1146 State = MODE_NORMAL; // don't go past end-of-line |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1147 coladvance((colnr_T)MAXCOL); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1148 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1149 dec_cursor(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 // do the formatting, without 'showmode' |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28767
diff
changeset
|
1152 State = MODE_INSERT; // for open_line() |
20237
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 smd_save = p_smd; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 p_smd = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1155 insertchar(NUL, INSCHAR_FORMAT |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1156 + (do_comments ? INSCHAR_DO_COM : 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1157 + (do_comments && do_comments_list |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1158 ? INSCHAR_COM_LIST : 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1159 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1160 State = old_State; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1161 p_smd = smd_save; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1162 second_indent = -1; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1163 // at end of par.: need to set indent of next par. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1164 need_set_indent = is_end_par; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1165 if (is_end_par) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 // When called with a negative line count, break at the |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 // end of the paragraph. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 if (line_count < 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 first_par_line = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 force_format = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1176 // When still in same paragraph, join the lines together. But |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 // first delete the leader from the second line. |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 if (!is_end_par) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 advance = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 curwin->w_cursor.lnum++; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 curwin->w_cursor.col = 0; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 if (line_count < 0 && u_save_cursor() == FAIL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1185 if (next_leader_len > 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1187 (void)del_bytes((long)next_leader_len, FALSE, FALSE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1188 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 (long)-next_leader_len, 0); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 else if (second_indent > 0) // the "leader" for FO_Q_SECOND |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 int indent = getwhitecols_curline(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 if (indent > 0) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1197 (void)del_bytes(indent, FALSE, FALSE); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 mark_col_adjust(curwin->w_cursor.lnum, |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1199 (colnr_T)0, 0L, (long)-indent, 0); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1201 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1202 curwin->w_cursor.lnum--; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 { |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 beep_flush(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 break; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 first_par_line = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 // If the line is getting long, format it next time |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1210 if (STRLEN(ml_get_curline()) > (size_t)max_len) |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1211 force_format = TRUE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1212 else |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1213 force_format = FALSE; |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1214 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1215 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1216 line_breakcheck(); |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1217 } |
918245588b50
patch 8.2.0674: some source files are too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1218 } |