Mercurial > vim
annotate src/edit.c @ 18203:e0ec4cd7a865 v8.1.2096
patch 8.1.2096: too many #ifdefs
Commit: https://github.com/vim/vim/commit/8c96af9c05bfcac2d5ae081e098d4863db561511
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 28 19:05:57 2019 +0200
patch 8.1.2096: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_COMMENTS.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 28 Sep 2019 19:15:03 +0200 |
parents | 1868ec23360e |
children | fe5afdc03bd2 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9852
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * edit.c: functions for Insert mode | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 #define BACKSPACE_CHAR 1 | |
17 #define BACKSPACE_WORD 2 | |
18 #define BACKSPACE_WORD_NOT_SPACE 3 | |
19 #define BACKSPACE_LINE 4 | |
20 | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
21 /* Set when doing something for completion that may call edit() recursively, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
22 * which is not allowed. */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
23 static int compl_busy = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
24 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
25 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
26 static void ins_ctrl_v(void); |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
27 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
28 static void init_prompt(int cmdchar_todo); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
29 #endif |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
30 static void insert_special(int, int, int); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
31 static void internal_format(int textwidth, int second_indent, int flags, int format_only, int c); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
32 static void check_auto_format(int); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
33 static void redo_literal(int c); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
34 static void start_arrow_common(pos_T *end_insert_pos, int change); |
744 | 35 #ifdef FEAT_SPELL |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
36 static void check_spell_redraw(void); |
221 | 37 #endif |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
38 static void stop_insert(pos_T *end_insert_pos, int esc, int nomove); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
39 static int echeck_abbr(int); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
40 static void replace_join(int off); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
41 static void mb_replace_pop_ins(int cc); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
42 static void replace_flush(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
43 static void replace_do_bs(int limit_col); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
44 static int del_char_after_col(int limit_col); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
45 static void ins_reg(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
46 static void ins_ctrl_g(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
47 static void ins_ctrl_hat(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
48 static int ins_esc(long *count, int cmdchar, int nomove); |
7 | 49 #ifdef FEAT_RIGHTLEFT |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
50 static void ins_ctrl_(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
51 #endif |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
52 static int ins_start_select(int c); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
53 static void ins_insert(int replaceState); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
54 static void ins_ctrl_o(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
55 static void ins_shift(int c, int lastc); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
56 static void ins_del(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
57 static int ins_bs(int c, int mode, int *inserted_space_p); |
692 | 58 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
59 static void ins_tabline(int c); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
60 #endif |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
61 static void ins_left(void); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
62 static void ins_home(int c); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
63 static void ins_end(int c); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
64 static void ins_s_left(void); |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
65 static void ins_right(void); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
66 static void ins_s_right(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
67 static void ins_up(int startcol); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
68 static void ins_pageup(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
69 static void ins_down(int startcol); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
70 static void ins_pagedown(void); |
7 | 71 #ifdef FEAT_DND |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
72 static void ins_drop(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
73 #endif |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
74 static int ins_tab(void); |
7 | 75 #ifdef FEAT_DIGRAPHS |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
76 static int ins_digraph(void); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
77 #endif |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
78 static int ins_ctrl_ey(int tc); |
7 | 79 #ifdef FEAT_SMARTINDENT |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
80 static void ins_try_si(int c); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
81 #endif |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
82 #if defined(FEAT_EVAL) |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7141
diff
changeset
|
83 static char_u *do_insert_char_pre(int c); |
3390 | 84 #endif |
7 | 85 |
86 static colnr_T Insstart_textlen; /* length of line when insert started */ | |
87 static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */ | |
5680 | 88 static int update_Insstart_orig = TRUE; /* set Insstart_orig to Insstart */ |
7 | 89 |
90 static char_u *last_insert = NULL; /* the text of the previous insert, | |
91 K_SPECIAL and CSI are escaped */ | |
92 static int last_insert_skip; /* nr of chars in front of previous insert */ | |
93 static int new_insert_skip; /* nr of chars in front of current insert */ | |
603 | 94 static int did_restart_edit; /* "restart_edit" when calling edit() */ |
7 | 95 |
96 #ifdef FEAT_CINDENT | |
97 static int can_cindent; /* may do cindenting on this line */ | |
98 #endif | |
99 | |
100 static int old_indent = 0; /* for ^^D command in insert mode */ | |
101 | |
102 #ifdef FEAT_RIGHTLEFT | |
298 | 103 static int revins_on; /* reverse insert mode on */ |
104 static int revins_chars; /* how much to skip after edit */ | |
105 static int revins_legal; /* was the last char 'legal'? */ | |
106 static int revins_scol; /* start column of revins session */ | |
7 | 107 #endif |
108 | |
109 static int ins_need_undo; /* call u_save() before inserting a | |
110 char. Set when edit() is called. | |
111 after that arrow_used is used. */ | |
112 | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
113 static int did_add_space = FALSE; // auto_format() added an extra space |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
114 // under the cursor |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
115 static int dont_sync_undo = FALSE; // CTRL-G U prevents syncing undo for |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
116 // the next left/right cursor key |
7 | 117 |
118 /* | |
119 * edit(): Start inserting text. | |
120 * | |
121 * "cmdchar" can be: | |
122 * 'i' normal insert command | |
123 * 'a' normal append command | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
124 * K_PS bracketed paste |
7 | 125 * 'R' replace command |
126 * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo, | |
127 * but still only one <CR> is inserted. The <Esc> is not used for redo. | |
128 * 'g' "gI" command. | |
129 * 'V' "gR" command for Virtual Replace mode. | |
130 * 'v' "gr" command for single character Virtual Replace mode. | |
131 * | |
132 * This function is not called recursively. For CTRL-O commands, it returns | |
133 * and lets the caller handle the Normal-mode command. | |
134 * | |
135 * Return TRUE if a CTRL-O command caused the return (insert mode pending). | |
136 */ | |
137 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
138 edit( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
139 int cmdchar, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
140 int startln, /* if set, insert at start of line */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
141 long count) |
7 | 142 { |
143 int c = 0; | |
144 char_u *ptr; | |
8090
54cfe888c627
commit https://github.com/vim/vim/commit/418f81b5fa400ed59793384f2f3d9df45390f080
Christian Brabandt <cb@256bit.org>
parents:
8003
diff
changeset
|
145 int lastc = 0; |
1869 | 146 int mincol; |
7 | 147 static linenr_T o_lnum = 0; |
148 int i; | |
149 int did_backspace = TRUE; /* previous char was backspace */ | |
150 #ifdef FEAT_CINDENT | |
151 int line_is_white = FALSE; /* line is empty before insert */ | |
152 #endif | |
153 linenr_T old_topline = 0; /* topline before insertion */ | |
154 #ifdef FEAT_DIFF | |
155 int old_topfill = -1; | |
156 #endif | |
157 int inserted_space = FALSE; /* just inserted a space */ | |
158 int replaceState = REPLACE; | |
477 | 159 int nomove = FALSE; /* don't move cursor on return */ |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
160 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
161 int cmdchar_todo = cmdchar; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
162 #endif |
7 | 163 |
603 | 164 /* Remember whether editing was restarted after CTRL-O. */ |
165 did_restart_edit = restart_edit; | |
166 | |
7 | 167 /* sleep before redrawing, needed for "CTRL-O :" that results in an |
168 * error message */ | |
169 check_for_delay(TRUE); | |
170 | |
5680 | 171 /* set Insstart_orig to Insstart */ |
172 update_Insstart_orig = TRUE; | |
173 | |
7 | 174 #ifdef HAVE_SANDBOX |
175 /* Don't allow inserting in the sandbox. */ | |
176 if (sandbox != 0) | |
177 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15440
diff
changeset
|
178 emsg(_(e_sandbox)); |
7 | 179 return FALSE; |
180 } | |
181 #endif | |
632 | 182 /* Don't allow changes in the buffer while editing the cmdline. The |
183 * caller of getcmdline() may get confused. */ | |
634 | 184 if (textlock != 0) |
632 | 185 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15440
diff
changeset
|
186 emsg(_(e_secure)); |
632 | 187 return FALSE; |
188 } | |
7 | 189 |
844 | 190 /* Don't allow recursive insert mode when busy with completion. */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
191 if (ins_compl_active() || compl_busy || pum_visible()) |
844 | 192 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15440
diff
changeset
|
193 emsg(_(e_secure)); |
844 | 194 return FALSE; |
195 } | |
7 | 196 ins_compl_clear(); /* clear stuff for CTRL-X mode */ |
197 | |
11 | 198 /* |
199 * Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx". | |
200 */ | |
201 if (cmdchar != 'r' && cmdchar != 'v') | |
202 { | |
4027 | 203 pos_T save_cursor = curwin->w_cursor; |
204 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
205 #ifdef FEAT_EVAL |
11 | 206 if (cmdchar == 'R') |
207 ptr = (char_u *)"r"; | |
208 else if (cmdchar == 'V') | |
209 ptr = (char_u *)"v"; | |
210 else | |
211 ptr = (char_u *)"i"; | |
212 set_vim_var_string(VV_INSERTMODE, ptr, 1); | |
4448 | 213 set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */ |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
214 #endif |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
215 ins_apply_autocmds(EVENT_INSERTENTER); |
4027 | 216 |
4448 | 217 /* Make sure the cursor didn't move. Do call check_cursor_col() in |
218 * case the text was modified. Since Insert mode was not started yet | |
219 * a call to check_cursor_col() may move the cursor, especially with | |
220 * the "A" command, thus set State to avoid that. Also check that the | |
221 * line number is still valid (lines may have been deleted). | |
222 * Do not restore if v:char was set to a non-empty string. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11105
diff
changeset
|
223 if (!EQUAL_POS(curwin->w_cursor, save_cursor) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
224 #ifdef FEAT_EVAL |
4448 | 225 && *get_vim_var_str(VV_CHAR) == NUL |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
226 #endif |
4448 | 227 && save_cursor.lnum <= curbuf->b_ml.ml_line_count) |
4027 | 228 { |
229 int save_state = State; | |
230 | |
231 curwin->w_cursor = save_cursor; | |
232 State = INSERT; | |
233 check_cursor_col(); | |
234 State = save_state; | |
235 } | |
11 | 236 } |
237 | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
238 #ifdef FEAT_CONCEAL |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
239 /* Check if the cursor line needs redrawing before changing State. If |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
240 * 'concealcursor' is "n" it needs to be redrawn without concealing. */ |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13870
diff
changeset
|
241 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
242 #endif |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
243 |
7 | 244 #ifdef FEAT_MOUSE |
245 /* | |
246 * When doing a paste with the middle mouse button, Insstart is set to | |
247 * where the paste started. | |
248 */ | |
249 if (where_paste_started.lnum != 0) | |
250 Insstart = where_paste_started; | |
251 else | |
252 #endif | |
253 { | |
254 Insstart = curwin->w_cursor; | |
255 if (startln) | |
256 Insstart.col = 0; | |
257 } | |
1869 | 258 Insstart_textlen = (colnr_T)linetabsize(ml_get_curline()); |
7 | 259 Insstart_blank_vcol = MAXCOL; |
260 if (!did_ai) | |
261 ai_col = 0; | |
262 | |
263 if (cmdchar != NUL && restart_edit == 0) | |
264 { | |
265 ResetRedobuff(); | |
266 AppendNumberToRedobuff(count); | |
267 if (cmdchar == 'V' || cmdchar == 'v') | |
268 { | |
269 /* "gR" or "gr" command */ | |
270 AppendCharToRedobuff('g'); | |
271 AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R'); | |
272 } | |
273 else | |
274 { | |
10682
d564e73ff9ee
patch 8.0.0231: bracketed paste mode is not tested
Christian Brabandt <cb@256bit.org>
parents:
10680
diff
changeset
|
275 if (cmdchar == K_PS) |
d564e73ff9ee
patch 8.0.0231: bracketed paste mode is not tested
Christian Brabandt <cb@256bit.org>
parents:
10680
diff
changeset
|
276 AppendCharToRedobuff('a'); |
d564e73ff9ee
patch 8.0.0231: bracketed paste mode is not tested
Christian Brabandt <cb@256bit.org>
parents:
10680
diff
changeset
|
277 else |
d564e73ff9ee
patch 8.0.0231: bracketed paste mode is not tested
Christian Brabandt <cb@256bit.org>
parents:
10680
diff
changeset
|
278 AppendCharToRedobuff(cmdchar); |
7 | 279 if (cmdchar == 'g') /* "gI" command */ |
280 AppendCharToRedobuff('I'); | |
281 else if (cmdchar == 'r') /* "r<CR>" command */ | |
282 count = 1; /* insert only one <CR> */ | |
283 } | |
284 } | |
285 | |
286 if (cmdchar == 'R') | |
287 { | |
288 State = REPLACE; | |
289 } | |
290 else if (cmdchar == 'V' || cmdchar == 'v') | |
291 { | |
292 State = VREPLACE; | |
293 replaceState = VREPLACE; | |
294 orig_line_count = curbuf->b_ml.ml_line_count; | |
295 vr_lines_changed = 1; | |
296 } | |
297 else | |
298 State = INSERT; | |
299 | |
300 stop_insert_mode = FALSE; | |
301 | |
302 /* | |
303 * Need to recompute the cursor position, it might move when the cursor is | |
304 * on a TAB or special character. | |
305 */ | |
306 curs_columns(TRUE); | |
307 | |
308 /* | |
309 * Enable langmap or IME, indicated by 'iminsert'. | |
310 * Note that IME may enabled/disabled without us noticing here, thus the | |
311 * 'iminsert' value may not reflect what is actually used. It is updated | |
312 * when hitting <Esc>. | |
313 */ | |
314 if (curbuf->b_p_iminsert == B_IMODE_LMAP) | |
315 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
316 #ifdef HAVE_INPUT_METHOD |
7 | 317 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM); |
318 #endif | |
319 | |
320 setmouse(); | |
321 #ifdef FEAT_CMDL_INFO | |
322 clear_showcmd(); | |
323 #endif | |
324 #ifdef FEAT_RIGHTLEFT | |
325 /* there is no reverse replace mode */ | |
326 revins_on = (State == INSERT && p_ri); | |
327 if (revins_on) | |
328 undisplay_dollar(); | |
329 revins_chars = 0; | |
330 revins_legal = 0; | |
331 revins_scol = -1; | |
332 #endif | |
10684
83a36d655a74
patch 8.0.0232: paste does not work when 'esckeys' is off
Christian Brabandt <cb@256bit.org>
parents:
10682
diff
changeset
|
333 if (!p_ek) |
83a36d655a74
patch 8.0.0232: paste does not work when 'esckeys' is off
Christian Brabandt <cb@256bit.org>
parents:
10682
diff
changeset
|
334 /* Disable bracketed paste mode, we won't recognize the escape |
83a36d655a74
patch 8.0.0232: paste does not work when 'esckeys' is off
Christian Brabandt <cb@256bit.org>
parents:
10682
diff
changeset
|
335 * sequences. */ |
83a36d655a74
patch 8.0.0232: paste does not work when 'esckeys' is off
Christian Brabandt <cb@256bit.org>
parents:
10682
diff
changeset
|
336 out_str(T_BD); |
7 | 337 |
338 /* | |
339 * Handle restarting Insert mode. | |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
11002
diff
changeset
|
340 * Don't do this for "CTRL-O ." (repeat an insert): In that case we get |
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
11002
diff
changeset
|
341 * here with something in the stuff buffer. |
7 | 342 */ |
343 if (restart_edit != 0 && stuff_empty()) | |
344 { | |
345 #ifdef FEAT_MOUSE | |
346 /* | |
347 * After a paste we consider text typed to be part of the insert for | |
348 * the pasted text. You can backspace over the pasted text too. | |
349 */ | |
350 if (where_paste_started.lnum) | |
351 arrow_used = FALSE; | |
352 else | |
353 #endif | |
354 arrow_used = TRUE; | |
355 restart_edit = 0; | |
356 | |
357 /* | |
358 * If the cursor was after the end-of-line before the CTRL-O and it is | |
359 * now at the end-of-line, put it after the end-of-line (this is not | |
360 * correct in very rare cases). | |
361 * Also do this if curswant is greater than the current virtual | |
362 * column. Eg after "^O$" or "^O80|". | |
363 */ | |
364 validate_virtcol(); | |
365 update_curswant(); | |
230 | 366 if (((ins_at_eol && curwin->w_cursor.lnum == o_lnum) |
7 | 367 || curwin->w_curswant > curwin->w_virtcol) |
368 && *(ptr = ml_get_curline() + curwin->w_cursor.col) != NUL) | |
369 { | |
370 if (ptr[1] == NUL) | |
371 ++curwin->w_cursor.col; | |
372 else if (has_mbyte) | |
373 { | |
474 | 374 i = (*mb_ptr2len)(ptr); |
7 | 375 if (ptr[i] == NUL) |
376 curwin->w_cursor.col += i; | |
377 } | |
378 } | |
230 | 379 ins_at_eol = FALSE; |
7 | 380 } |
381 else | |
382 arrow_used = FALSE; | |
383 | |
384 /* we are in insert mode now, don't need to start it anymore */ | |
385 need_start_insertmode = FALSE; | |
386 | |
387 /* Need to save the line for undo before inserting the first char. */ | |
388 ins_need_undo = TRUE; | |
389 | |
390 #ifdef FEAT_MOUSE | |
391 where_paste_started.lnum = 0; | |
392 #endif | |
393 #ifdef FEAT_CINDENT | |
394 can_cindent = TRUE; | |
395 #endif | |
396 #ifdef FEAT_FOLDING | |
397 /* The cursor line is not in a closed fold, unless 'insertmode' is set or | |
398 * restarting. */ | |
399 if (!p_im && did_restart_edit == 0) | |
400 foldOpenCursor(); | |
401 #endif | |
402 | |
403 /* | |
404 * If 'showmode' is set, show the current (insert/replace/..) mode. | |
405 * A warning message for changing a readonly file is given here, before | |
406 * actually changing anything. It's put after the mode, if any. | |
407 */ | |
408 i = 0; | |
644 | 409 if (p_smd && msg_silent == 0) |
7 | 410 i = showmode(); |
411 | |
412 if (!p_im && did_restart_edit == 0) | |
1473 | 413 change_warning(i == 0 ? 0 : i + 1); |
7 | 414 |
415 #ifdef CURSOR_SHAPE | |
416 ui_cursor_shape(); /* may show different cursor shape */ | |
417 #endif | |
418 #ifdef FEAT_DIGRAPHS | |
419 do_digraph(-1); /* clear digraphs */ | |
420 #endif | |
421 | |
603 | 422 /* |
423 * Get the current length of the redo buffer, those characters have to be | |
424 * skipped if we want to get to the inserted characters. | |
425 */ | |
7 | 426 ptr = get_inserted(); |
427 if (ptr == NULL) | |
428 new_insert_skip = 0; | |
429 else | |
430 { | |
431 new_insert_skip = (int)STRLEN(ptr); | |
432 vim_free(ptr); | |
433 } | |
434 | |
435 old_indent = 0; | |
436 | |
437 /* | |
438 * Main loop in Insert mode: repeat until Insert mode is left. | |
439 */ | |
440 for (;;) | |
441 { | |
442 #ifdef FEAT_RIGHTLEFT | |
443 if (!revins_legal) | |
444 revins_scol = -1; /* reset on illegal motions */ | |
445 else | |
446 revins_legal = 0; | |
447 #endif | |
448 if (arrow_used) /* don't repeat insert when arrow key used */ | |
449 count = 0; | |
450 | |
5680 | 451 if (update_Insstart_orig) |
452 Insstart_orig = Insstart; | |
453 | |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
454 if (stop_insert_mode && !pum_visible()) |
7 | 455 { |
456 /* ":stopinsert" used or 'insertmode' reset */ | |
457 count = 0; | |
458 goto doESCkey; | |
459 } | |
460 | |
461 /* set curwin->w_curswant for next K_DOWN or K_UP */ | |
462 if (!arrow_used) | |
463 curwin->w_set_curswant = TRUE; | |
464 | |
465 /* If there is no typeahead may check for timestamps (e.g., for when a | |
466 * menu invoked a shell command). */ | |
467 if (stuff_empty()) | |
468 { | |
469 did_check_timestamps = FALSE; | |
470 if (need_check_timestamps) | |
471 check_timestamps(FALSE); | |
472 } | |
473 | |
474 /* | |
475 * When emsg() was called msg_scroll will have been set. | |
476 */ | |
477 msg_scroll = FALSE; | |
478 | |
479 #ifdef FEAT_GUI | |
480 /* When 'mousefocus' is set a mouse movement may have taken us to | |
481 * another window. "need_mouse_correct" may then be set because of an | |
482 * autocommand. */ | |
483 if (need_mouse_correct) | |
484 gui_mouse_correct(); | |
485 #endif | |
486 | |
487 #ifdef FEAT_FOLDING | |
488 /* Open fold at the cursor line, according to 'foldopen'. */ | |
489 if (fdo_flags & FDO_INSERT) | |
490 foldOpenCursor(); | |
491 /* Close folds where the cursor isn't, according to 'foldclose' */ | |
492 if (!char_avail()) | |
493 foldCheckClose(); | |
494 #endif | |
495 | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
496 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
497 if (bt_prompt(curbuf)) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
498 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
499 init_prompt(cmdchar_todo); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
500 cmdchar_todo = NUL; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
501 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
502 #endif |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
503 |
7 | 504 /* |
505 * If we inserted a character at the last position of the last line in | |
506 * the window, scroll the window one line up. This avoids an extra | |
507 * redraw. | |
508 * This is detected when the cursor column is smaller after inserting | |
509 * something. | |
510 * Don't do this when the topline changed already, it has | |
511 * already been adjusted (by insertchar() calling open_line())). | |
512 */ | |
513 if (curbuf->b_mod_set | |
514 && curwin->w_p_wrap | |
515 && !did_backspace | |
516 && curwin->w_topline == old_topline | |
517 #ifdef FEAT_DIFF | |
518 && curwin->w_topfill == old_topfill | |
519 #endif | |
520 ) | |
521 { | |
522 mincol = curwin->w_wcol; | |
523 validate_cursor_col(); | |
524 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
525 if ( |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
526 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
527 (int)curwin->w_wcol < mincol - tabstop_at( |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
528 get_nolist_virtcol(), curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
529 curbuf->b_p_vts_array) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
530 #else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
531 (int)curwin->w_wcol < mincol - curbuf->b_p_ts |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
532 #endif |
7 | 533 && curwin->w_wrow == W_WINROW(curwin) |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15705
diff
changeset
|
534 + curwin->w_height - 1 - get_scrolloff_value() |
7 | 535 && (curwin->w_cursor.lnum != curwin->w_topline |
536 #ifdef FEAT_DIFF | |
537 || curwin->w_topfill > 0 | |
538 #endif | |
539 )) | |
540 { | |
541 #ifdef FEAT_DIFF | |
542 if (curwin->w_topfill > 0) | |
543 --curwin->w_topfill; | |
544 else | |
545 #endif | |
546 #ifdef FEAT_FOLDING | |
547 if (hasFolding(curwin->w_topline, NULL, &old_topline)) | |
548 set_topline(curwin, old_topline + 1); | |
549 else | |
550 #endif | |
551 set_topline(curwin, curwin->w_topline + 1); | |
552 } | |
553 } | |
554 | |
555 /* May need to adjust w_topline to show the cursor. */ | |
556 update_topline(); | |
557 | |
558 did_backspace = FALSE; | |
559 | |
560 validate_cursor(); /* may set must_redraw */ | |
561 | |
562 /* | |
563 * Redraw the display when no characters are waiting. | |
564 * Also shows mode, ruler and positions cursor. | |
565 */ | |
661 | 566 ins_redraw(TRUE); |
7 | 567 |
568 if (curwin->w_p_scb) | |
569 do_check_scrollbind(TRUE); | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
570 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2227
diff
changeset
|
571 if (curwin->w_p_crb) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2227
diff
changeset
|
572 do_check_cursorbind(); |
7 | 573 update_curswant(); |
574 old_topline = curwin->w_topline; | |
575 #ifdef FEAT_DIFF | |
576 old_topfill = curwin->w_topfill; | |
577 #endif | |
578 | |
579 #ifdef USE_ON_FLY_SCROLL | |
580 dont_scroll = FALSE; /* allow scrolling here */ | |
581 #endif | |
582 | |
583 /* | |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
584 * Get a character for Insert mode. Ignore K_IGNORE and K_NOP. |
7 | 585 */ |
6673 | 586 if (c != K_CURSORHOLD) |
587 lastc = c; /* remember the previous char for CTRL-D */ | |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
588 |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
589 /* After using CTRL-G U the next cursor key will not break undo. */ |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
590 if (dont_sync_undo == MAYBE) |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
591 dont_sync_undo = TRUE; |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
592 else |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
593 dont_sync_undo = FALSE; |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
594 if (cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
595 /* Got here from normal mode when bracketed paste started. */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
596 c = K_PS; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
597 else |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
598 do |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
599 { |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
600 c = safe_vgetc(); |
14035
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
601 |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
602 if (stop_insert_mode) |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
603 { |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
604 // Insert mode ended, possibly from a callback. |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
605 count = 0; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
606 nomove = TRUE; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
607 goto doESCkey; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
608 } |
12960
004bc78c88e6
patch 8.0.1356: using simalt in a GUIEnter autocommand inserts characters
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
609 } while (c == K_IGNORE || c == K_NOP); |
7 | 610 |
978 | 611 /* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */ |
612 did_cursorhold = TRUE; | |
613 | |
7 | 614 #ifdef FEAT_RIGHTLEFT |
615 if (p_hkmap && KeyTyped) | |
616 c = hkmap(c); /* Hebrew mode mapping */ | |
617 #endif | |
618 | |
659 | 619 /* |
620 * Special handling of keys while the popup menu is visible or wanted | |
897 | 621 * and the cursor is still in the completed word. Only when there is |
622 * a match, skip this when no matches were found. | |
659 | 623 */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
624 if (ins_compl_active() |
897 | 625 && pum_wanted() |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
626 && curwin->w_cursor.col >= ins_compl_col() |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
627 && ins_compl_has_shown_match()) |
659 | 628 { |
629 /* BS: Delete one character from "compl_leader". */ | |
630 if ((c == K_BS || c == Ctrl_H) | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
631 && curwin->w_cursor.col > ins_compl_col() |
836 | 632 && (c = ins_compl_bs()) == NUL) |
657 | 633 continue; |
634 | |
659 | 635 /* When no match was selected or it was edited. */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
636 if (!ins_compl_used_match()) |
657 | 637 { |
659 | 638 /* CTRL-L: Add one character from the current match to |
836 | 639 * "compl_leader". Except when at the original match and |
640 * there is nothing to add, CTRL-L works like CTRL-P then. */ | |
641 if (c == Ctrl_L | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
642 && (!ctrl_x_mode_line_or_eval() |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
643 || ins_compl_long_shown_match())) |
659 | 644 { |
645 ins_compl_addfrommatch(); | |
646 continue; | |
647 } | |
648 | |
1430 | 649 /* A non-white character that fits in with the current |
650 * completion: Add to "compl_leader". */ | |
651 if (ins_compl_accept_char(c)) | |
659 | 652 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
653 #if defined(FEAT_EVAL) |
3390 | 654 /* Trigger InsertCharPre. */ |
655 char_u *str = do_insert_char_pre(c); | |
656 char_u *p; | |
657 | |
658 if (str != NULL) | |
659 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
660 for (p = str; *p != NUL; MB_PTR_ADV(p)) |
3390 | 661 ins_compl_addleader(PTR2CHAR(p)); |
662 vim_free(str); | |
663 } | |
664 else | |
665 #endif | |
666 ins_compl_addleader(c); | |
659 | 667 continue; |
668 } | |
665 | 669 |
887 | 670 /* Pressing CTRL-Y selects the current match. When |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
671 * ins_compl_enter_selects() is set the Enter key does the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
672 * same. */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
673 if ((c == Ctrl_Y || (ins_compl_enter_selects() |
10291
d9bd03a0d70f
commit https://github.com/vim/vim/commit/cbd3bd6cbed5baf418b037b17ad46e339ff59174
Christian Brabandt <cb@256bit.org>
parents:
10289
diff
changeset
|
674 && (c == CAR || c == K_KENTER || c == NL))) |
d9bd03a0d70f
commit https://github.com/vim/vim/commit/cbd3bd6cbed5baf418b037b17ad46e339ff59174
Christian Brabandt <cb@256bit.org>
parents:
10289
diff
changeset
|
675 && stop_arrow() == OK) |
665 | 676 { |
677 ins_compl_delete(); | |
10277
154d5a2e7395
commit https://github.com/vim/vim/commit/472e85970ee3a80abd824bef510df12e9cfe9e96
Christian Brabandt <cb@256bit.org>
parents:
10120
diff
changeset
|
678 ins_compl_insert(FALSE); |
665 | 679 } |
657 | 680 } |
681 } | |
682 | |
7 | 683 /* Prepare for or stop CTRL-X mode. This doesn't do completion, but |
684 * it does fix up the text when finishing completion. */ | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
685 ins_compl_init_get_longest(); |
1526 | 686 if (ins_compl_prep(c)) |
657 | 687 continue; |
7 | 688 |
477 | 689 /* CTRL-\ CTRL-N goes to Normal mode, |
690 * CTRL-\ CTRL-G goes to mode selected with 'insertmode', | |
691 * CTRL-\ CTRL-O is like CTRL-O but without moving the cursor. */ | |
7 | 692 if (c == Ctrl_BSL) |
693 { | |
694 /* may need to redraw when no more chars available now */ | |
661 | 695 ins_redraw(FALSE); |
7 | 696 ++no_mapping; |
697 ++allow_keys; | |
1389 | 698 c = plain_vgetc(); |
7 | 699 --no_mapping; |
700 --allow_keys; | |
477 | 701 if (c != Ctrl_N && c != Ctrl_G && c != Ctrl_O) |
7 | 702 { |
477 | 703 /* it's something else */ |
7 | 704 vungetc(c); |
705 c = Ctrl_BSL; | |
706 } | |
707 else if (c == Ctrl_G && p_im) | |
708 continue; | |
709 else | |
710 { | |
477 | 711 if (c == Ctrl_O) |
712 { | |
713 ins_ctrl_o(); | |
714 ins_at_eol = FALSE; /* cursor keeps its column */ | |
715 nomove = TRUE; | |
716 } | |
7 | 717 count = 0; |
718 goto doESCkey; | |
719 } | |
720 } | |
721 | |
722 #ifdef FEAT_DIGRAPHS | |
723 c = do_digraph(c); | |
724 #endif | |
725 | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
726 if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode_cmdline()) |
7 | 727 goto docomplete; |
728 if (c == Ctrl_V || c == Ctrl_Q) | |
729 { | |
730 ins_ctrl_v(); | |
731 c = Ctrl_V; /* pretend CTRL-V is last typed character */ | |
732 continue; | |
733 } | |
734 | |
735 #ifdef FEAT_CINDENT | |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
736 if (cindent_on() && ctrl_x_mode_none()) |
7 | 737 { |
738 /* A key name preceded by a bang means this key is not to be | |
739 * inserted. Skip ahead to the re-indenting below. | |
740 * A key name preceded by a star means that indenting has to be | |
741 * done before inserting the key. */ | |
742 line_is_white = inindent(0); | |
743 if (in_cinkeys(c, '!', line_is_white)) | |
744 goto force_cindent; | |
745 if (can_cindent && in_cinkeys(c, '*', line_is_white) | |
746 && stop_arrow() == OK) | |
747 do_c_expr_indent(); | |
748 } | |
749 #endif | |
750 | |
751 #ifdef FEAT_RIGHTLEFT | |
752 if (curwin->w_p_rl) | |
753 switch (c) | |
754 { | |
755 case K_LEFT: c = K_RIGHT; break; | |
756 case K_S_LEFT: c = K_S_RIGHT; break; | |
757 case K_C_LEFT: c = K_C_RIGHT; break; | |
758 case K_RIGHT: c = K_LEFT; break; | |
759 case K_S_RIGHT: c = K_S_LEFT; break; | |
760 case K_C_RIGHT: c = K_C_LEFT; break; | |
761 } | |
762 #endif | |
763 | |
764 /* | |
765 * If 'keymodel' contains "startsel", may start selection. If it | |
766 * does, a CTRL-O and c will be stuffed, we need to get these | |
767 * characters. | |
768 */ | |
769 if (ins_start_select(c)) | |
770 continue; | |
771 | |
772 /* | |
773 * The big switch to handle a character in insert mode. | |
774 */ | |
775 switch (c) | |
776 { | |
449 | 777 case ESC: /* End input mode */ |
7 | 778 if (echeck_abbr(ESC + ABBR_OFF)) |
779 break; | |
12674
e769c912fcd9
patch 8.0.1215: newer gcc warns for implicit fallthrough
Christian Brabandt <cb@256bit.org>
parents:
12551
diff
changeset
|
780 /* FALLTHROUGH */ |
7 | 781 |
449 | 782 case Ctrl_C: /* End input mode */ |
7 | 783 #ifdef FEAT_CMDWIN |
784 if (c == Ctrl_C && cmdwin_type != 0) | |
785 { | |
786 /* Close the cmdline window. */ | |
787 cmdwin_result = K_IGNORE; | |
788 got_int = FALSE; /* don't stop executing autocommands et al. */ | |
929 | 789 nomove = TRUE; |
7 | 790 goto doESCkey; |
791 } | |
792 #endif | |
14103
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
793 #ifdef FEAT_JOB_CHANNEL |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
794 if (c == Ctrl_C && bt_prompt(curbuf)) |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
795 { |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
796 if (invoke_prompt_interrupt()) |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
797 { |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
798 if (!bt_prompt(curbuf)) |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
799 // buffer changed to a non-prompt buffer, get out of |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
800 // Insert mode |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
801 goto doESCkey; |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
802 break; |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
803 } |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
804 } |
d053ec57d886
patch 8.1.0069: cannot handle pressing CTRL-C in a prompt buffer
Christian Brabandt <cb@256bit.org>
parents:
14093
diff
changeset
|
805 #endif |
7 | 806 |
807 #ifdef UNIX | |
808 do_intr: | |
809 #endif | |
810 /* when 'insertmode' set, and not halfway a mapping, don't leave | |
811 * Insert mode */ | |
812 if (goto_im()) | |
813 { | |
814 if (got_int) | |
815 { | |
816 (void)vgetc(); /* flush all buffers */ | |
817 got_int = FALSE; | |
818 } | |
819 else | |
6949 | 820 vim_beep(BO_IM); |
7 | 821 break; |
822 } | |
823 doESCkey: | |
824 /* | |
825 * This is the ONLY return from edit()! | |
826 */ | |
827 /* Always update o_lnum, so that a "CTRL-O ." that adds a line | |
828 * still puts the cursor back after the inserted text. */ | |
230 | 829 if (ins_at_eol && gchar_cursor() == NUL) |
7 | 830 o_lnum = curwin->w_cursor.lnum; |
831 | |
477 | 832 if (ins_esc(&count, cmdchar, nomove)) |
11 | 833 { |
14985
4ebda55537a5
patch 8.1.0504: when CTRL-C is mapped it triggers InsertLeave
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
834 // When CTRL-C was typed got_int will be set, with the result |
4ebda55537a5
patch 8.1.0504: when CTRL-C is mapped it triggers InsertLeave
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
835 // that the autocommands won't be executed. When mapped got_int |
4ebda55537a5
patch 8.1.0504: when CTRL-C is mapped it triggers InsertLeave
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
836 // is not set, but let's keep the behavior the same. |
4ebda55537a5
patch 8.1.0504: when CTRL-C is mapped it triggers InsertLeave
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
837 if (cmdchar != 'r' && cmdchar != 'v' && c != Ctrl_C) |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
838 ins_apply_autocmds(EVENT_INSERTLEAVE); |
993 | 839 did_cursorhold = FALSE; |
7 | 840 return (c == Ctrl_O); |
11 | 841 } |
7 | 842 continue; |
843 | |
449 | 844 case Ctrl_Z: /* suspend when 'insertmode' set */ |
845 if (!p_im) | |
846 goto normalchar; /* insert CTRL-Z as normal char */ | |
10636
3db97def0f35
patch 8.0.0208: internally used commands end up in history
Christian Brabandt <cb@256bit.org>
parents:
10468
diff
changeset
|
847 do_cmdline_cmd((char_u *)"stop"); |
10980
5362b4b6042c
patch 8.0.0379: CTRL-Z and mouse click use CTRL-O unnecessary
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
848 #ifdef CURSOR_SHAPE |
5362b4b6042c
patch 8.0.0379: CTRL-Z and mouse click use CTRL-O unnecessary
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
849 ui_cursor_shape(); /* may need to update cursor shape */ |
5362b4b6042c
patch 8.0.0379: CTRL-Z and mouse click use CTRL-O unnecessary
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
850 #endif |
5362b4b6042c
patch 8.0.0379: CTRL-Z and mouse click use CTRL-O unnecessary
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
851 continue; |
449 | 852 |
853 case Ctrl_O: /* execute one command */ | |
502 | 854 #ifdef FEAT_COMPL_FUNC |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
855 if (ctrl_x_mode_omni()) |
449 | 856 goto docomplete; |
857 #endif | |
858 if (echeck_abbr(Ctrl_O + ABBR_OFF)) | |
859 break; | |
860 ins_ctrl_o(); | |
853 | 861 |
862 /* don't move the cursor left when 'virtualedit' has "onemore". */ | |
863 if (ve_flags & VE_ONEMORE) | |
864 { | |
865 ins_at_eol = FALSE; | |
866 nomove = TRUE; | |
867 } | |
449 | 868 count = 0; |
869 goto doESCkey; | |
870 | |
464 | 871 case K_INS: /* toggle insert/replace mode */ |
872 case K_KINS: | |
873 ins_insert(replaceState); | |
874 break; | |
875 | |
876 case K_SELECT: /* end of Select mode mapping - ignore */ | |
877 break; | |
878 | |
449 | 879 case K_HELP: /* Help key works like <ESC> <Help> */ |
880 case K_F1: | |
881 case K_XF1: | |
882 stuffcharReadbuff(K_HELP); | |
883 if (p_im) | |
884 need_start_insertmode = TRUE; | |
885 goto doESCkey; | |
886 | |
887 #ifdef FEAT_NETBEANS_INTG | |
888 case K_F21: /* NetBeans command */ | |
889 ++no_mapping; /* don't map the next key hits */ | |
1389 | 890 i = plain_vgetc(); |
449 | 891 --no_mapping; |
892 netbeans_keycommand(i); | |
893 break; | |
894 #endif | |
895 | |
896 case K_ZERO: /* Insert the previously inserted text. */ | |
7 | 897 case NUL: |
898 case Ctrl_A: | |
449 | 899 /* For ^@ the trailing ESC will end the insert, unless there is an |
900 * error. */ | |
7 | 901 if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL |
902 && c != Ctrl_A && !p_im) | |
903 goto doESCkey; /* quit insert mode */ | |
904 inserted_space = FALSE; | |
905 break; | |
906 | |
449 | 907 case Ctrl_R: /* insert the contents of a register */ |
7 | 908 ins_reg(); |
909 auto_format(FALSE, TRUE); | |
910 inserted_space = FALSE; | |
911 break; | |
912 | |
449 | 913 case Ctrl_G: /* commands starting with CTRL-G */ |
7 | 914 ins_ctrl_g(); |
915 break; | |
916 | |
449 | 917 case Ctrl_HAT: /* switch input mode and/or langmap */ |
918 ins_ctrl_hat(); | |
7 | 919 break; |
920 | |
921 #ifdef FEAT_RIGHTLEFT | |
449 | 922 case Ctrl__: /* switch between languages */ |
7 | 923 if (!p_ari) |
924 goto normalchar; | |
925 ins_ctrl_(); | |
926 break; | |
927 #endif | |
928 | |
449 | 929 case Ctrl_D: /* Make indent one shiftwidth smaller. */ |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
930 #if defined(FEAT_FIND_ID) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
931 if (ctrl_x_mode_path_defines()) |
7 | 932 goto docomplete; |
933 #endif | |
934 /* FALLTHROUGH */ | |
935 | |
449 | 936 case Ctrl_T: /* Make indent one shiftwidth greater. */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
937 if (c == Ctrl_T && ctrl_x_mode_thesaurus()) |
7 | 938 { |
449 | 939 if (has_compl_option(FALSE)) |
940 goto docomplete; | |
941 break; | |
7 | 942 } |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
943 |
7 | 944 ins_shift(c, lastc); |
945 auto_format(FALSE, TRUE); | |
946 inserted_space = FALSE; | |
947 break; | |
948 | |
449 | 949 case K_DEL: /* delete character under the cursor */ |
7 | 950 case K_KDEL: |
951 ins_del(); | |
952 auto_format(FALSE, TRUE); | |
953 break; | |
954 | |
449 | 955 case K_BS: /* delete character before the cursor */ |
7 | 956 case Ctrl_H: |
957 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space); | |
958 auto_format(FALSE, TRUE); | |
959 break; | |
960 | |
449 | 961 case Ctrl_W: /* delete word before the cursor */ |
14035
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
962 #ifdef FEAT_JOB_CHANNEL |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
963 if (bt_prompt(curbuf) && (mod_mask & MOD_MASK_SHIFT) == 0) |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
964 { |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
965 // In a prompt window CTRL-W is used for window commands. |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
966 // Use Shift-CTRL-W to delete a word. |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
967 stuffcharReadbuff(Ctrl_W); |
14093
a9d94f10ecef
patch 8.1.0064: typing CTRL-W in a prompt buffer shows mode "-- --"
Christian Brabandt <cb@256bit.org>
parents:
14079
diff
changeset
|
968 restart_edit = 'A'; |
14035
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
969 nomove = TRUE; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
970 count = 0; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
971 goto doESCkey; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
972 } |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
973 #endif |
7 | 974 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space); |
975 auto_format(FALSE, TRUE); | |
976 break; | |
977 | |
449 | 978 case Ctrl_U: /* delete all inserted text in current line */ |
12 | 979 # ifdef FEAT_COMPL_FUNC |
980 /* CTRL-X CTRL-U completes with 'completefunc'. */ | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
981 if (ctrl_x_mode_function()) |
12 | 982 goto docomplete; |
983 # endif | |
7 | 984 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space); |
985 auto_format(FALSE, TRUE); | |
986 inserted_space = FALSE; | |
987 break; | |
988 | |
989 #ifdef FEAT_MOUSE | |
449 | 990 case K_LEFTMOUSE: /* mouse keys */ |
7 | 991 case K_LEFTMOUSE_NM: |
992 case K_LEFTDRAG: | |
993 case K_LEFTRELEASE: | |
994 case K_LEFTRELEASE_NM: | |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
995 case K_MOUSEMOVE: |
7 | 996 case K_MIDDLEMOUSE: |
997 case K_MIDDLEDRAG: | |
998 case K_MIDDLERELEASE: | |
999 case K_RIGHTMOUSE: | |
1000 case K_RIGHTDRAG: | |
1001 case K_RIGHTRELEASE: | |
1002 case K_X1MOUSE: | |
1003 case K_X1DRAG: | |
1004 case K_X1RELEASE: | |
1005 case K_X2MOUSE: | |
1006 case K_X2DRAG: | |
1007 case K_X2RELEASE: | |
1008 ins_mouse(c); | |
1009 break; | |
1010 | |
449 | 1011 case K_MOUSEDOWN: /* Default action for scroll wheel up: scroll up */ |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1012 ins_mousescroll(MSCR_DOWN); |
7 | 1013 break; |
1014 | |
449 | 1015 case K_MOUSEUP: /* Default action for scroll wheel down: scroll down */ |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1016 ins_mousescroll(MSCR_UP); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1017 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1018 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1019 case K_MOUSELEFT: /* Scroll wheel left */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1020 ins_mousescroll(MSCR_LEFT); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1021 break; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1022 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1023 case K_MOUSERIGHT: /* Scroll wheel right */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
1024 ins_mousescroll(MSCR_RIGHT); |
7 | 1025 break; |
1026 #endif | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1027 case K_PS: |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1028 bracketed_paste(PASTE_INSERT, FALSE, NULL); |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1029 if (cmdchar == K_PS) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1030 /* invoked from normal mode, bail out */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1031 goto doESCkey; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1032 break; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1033 case K_PE: |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1034 /* Got K_PE without K_PS, ignore. */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1035 break; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
1036 |
692 | 1037 #ifdef FEAT_GUI_TABLINE |
1038 case K_TABLINE: | |
1039 case K_TABMENU: | |
1040 ins_tabline(c); | |
1041 break; | |
1042 #endif | |
7 | 1043 |
449 | 1044 case K_IGNORE: /* Something mapped to nothing */ |
7 | 1045 break; |
1046 | |
661 | 1047 case K_CURSORHOLD: /* Didn't type something for a while. */ |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1048 ins_apply_autocmds(EVENT_CURSORHOLDI); |
661 | 1049 did_cursorhold = TRUE; |
1050 break; | |
1051 | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1052 #ifdef FEAT_GUI_MSWIN |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1053 /* On MS-Windows ignore <M-F4>, we get it when closing the window |
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1054 * was cancelled. */ |
625 | 1055 case K_F4: |
1056 if (mod_mask != MOD_MASK_ALT) | |
1057 goto normalchar; | |
1058 break; | |
1059 #endif | |
1060 | |
7 | 1061 #ifdef FEAT_GUI |
1062 case K_VER_SCROLLBAR: | |
1063 ins_scroll(); | |
1064 break; | |
1065 | |
1066 case K_HOR_SCROLLBAR: | |
1067 ins_horscroll(); | |
1068 break; | |
1069 #endif | |
1070 | |
449 | 1071 case K_HOME: /* <Home> */ |
7 | 1072 case K_KHOME: |
1073 case K_S_HOME: | |
1074 case K_C_HOME: | |
1075 ins_home(c); | |
1076 break; | |
1077 | |
449 | 1078 case K_END: /* <End> */ |
7 | 1079 case K_KEND: |
1080 case K_S_END: | |
1081 case K_C_END: | |
1082 ins_end(c); | |
1083 break; | |
1084 | |
449 | 1085 case K_LEFT: /* <Left> */ |
180 | 1086 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) |
1087 ins_s_left(); | |
1088 else | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1089 ins_left(); |
7 | 1090 break; |
1091 | |
449 | 1092 case K_S_LEFT: /* <S-Left> */ |
7 | 1093 case K_C_LEFT: |
1094 ins_s_left(); | |
1095 break; | |
1096 | |
449 | 1097 case K_RIGHT: /* <Right> */ |
180 | 1098 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) |
1099 ins_s_right(); | |
1100 else | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1101 ins_right(); |
7 | 1102 break; |
1103 | |
449 | 1104 case K_S_RIGHT: /* <S-Right> */ |
7 | 1105 case K_C_RIGHT: |
1106 ins_s_right(); | |
1107 break; | |
1108 | |
449 | 1109 case K_UP: /* <Up> */ |
665 | 1110 if (pum_visible()) |
1111 goto docomplete; | |
180 | 1112 if (mod_mask & MOD_MASK_SHIFT) |
1113 ins_pageup(); | |
1114 else | |
1115 ins_up(FALSE); | |
7 | 1116 break; |
1117 | |
449 | 1118 case K_S_UP: /* <S-Up> */ |
7 | 1119 case K_PAGEUP: |
1120 case K_KPAGEUP: | |
610 | 1121 if (pum_visible()) |
1122 goto docomplete; | |
7 | 1123 ins_pageup(); |
1124 break; | |
1125 | |
449 | 1126 case K_DOWN: /* <Down> */ |
665 | 1127 if (pum_visible()) |
1128 goto docomplete; | |
180 | 1129 if (mod_mask & MOD_MASK_SHIFT) |
1130 ins_pagedown(); | |
1131 else | |
1132 ins_down(FALSE); | |
7 | 1133 break; |
1134 | |
449 | 1135 case K_S_DOWN: /* <S-Down> */ |
7 | 1136 case K_PAGEDOWN: |
1137 case K_KPAGEDOWN: | |
610 | 1138 if (pum_visible()) |
1139 goto docomplete; | |
7 | 1140 ins_pagedown(); |
1141 break; | |
1142 | |
1143 #ifdef FEAT_DND | |
449 | 1144 case K_DROP: /* drag-n-drop event */ |
7 | 1145 ins_drop(); |
1146 break; | |
1147 #endif | |
1148 | |
449 | 1149 case K_S_TAB: /* When not mapped, use like a normal TAB */ |
7 | 1150 c = TAB; |
1151 /* FALLTHROUGH */ | |
1152 | |
449 | 1153 case TAB: /* TAB or Complete patterns along path */ |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
1154 #if defined(FEAT_FIND_ID) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1155 if (ctrl_x_mode_path_patterns()) |
7 | 1156 goto docomplete; |
1157 #endif | |
1158 inserted_space = FALSE; | |
1159 if (ins_tab()) | |
1160 goto normalchar; /* insert TAB as a normal char */ | |
1161 auto_format(FALSE, TRUE); | |
1162 break; | |
1163 | |
449 | 1164 case K_KENTER: /* <Enter> */ |
7 | 1165 c = CAR; |
1166 /* FALLTHROUGH */ | |
1167 case CAR: | |
1168 case NL: | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1169 #if defined(FEAT_QUICKFIX) |
7 | 1170 /* In a quickfix window a <CR> jumps to the error under the |
1171 * cursor. */ | |
1172 if (bt_quickfix(curbuf) && c == CAR) | |
1173 { | |
644 | 1174 if (curwin->w_llist_ref == NULL) /* quickfix window */ |
1175 do_cmdline_cmd((char_u *)".cc"); | |
1176 else /* location list window */ | |
1177 do_cmdline_cmd((char_u *)".ll"); | |
7 | 1178 break; |
1179 } | |
1180 #endif | |
1181 #ifdef FEAT_CMDWIN | |
1182 if (cmdwin_type != 0) | |
1183 { | |
1184 /* Execute the command in the cmdline window. */ | |
1185 cmdwin_result = CAR; | |
1186 goto doESCkey; | |
1187 } | |
1188 #endif | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1189 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1190 if (bt_prompt(curbuf)) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1191 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1192 invoke_prompt_callback(); |
14037
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14035
diff
changeset
|
1193 if (!bt_prompt(curbuf)) |
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14035
diff
changeset
|
1194 // buffer changed to a non-prompt buffer, get out of |
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14035
diff
changeset
|
1195 // Insert mode |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1196 goto doESCkey; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1197 break; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1198 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1199 #endif |
13772
cc21507ee4b1
patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents:
13718
diff
changeset
|
1200 if (ins_eol(c) == FAIL && !p_im) |
7 | 1201 goto doESCkey; /* out of memory */ |
1202 auto_format(FALSE, FALSE); | |
1203 inserted_space = FALSE; | |
1204 break; | |
1205 | |
449 | 1206 case Ctrl_K: /* digraph or keyword completion */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1207 if (ctrl_x_mode_dictionary()) |
7 | 1208 { |
449 | 1209 if (has_compl_option(TRUE)) |
1210 goto docomplete; | |
1211 break; | |
7 | 1212 } |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
1213 #ifdef FEAT_DIGRAPHS |
7 | 1214 c = ins_digraph(); |
1215 if (c == NUL) | |
1216 break; | |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
1217 #endif |
7 | 1218 goto normalchar; |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
1219 |
464 | 1220 case Ctrl_X: /* Enter CTRL-X mode */ |
1221 ins_ctrl_x(); | |
1222 break; | |
1223 | |
449 | 1224 case Ctrl_RSB: /* Tag name completion after ^X */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1225 if (!ctrl_x_mode_tags()) |
7 | 1226 goto normalchar; |
1227 goto docomplete; | |
1228 | |
449 | 1229 case Ctrl_F: /* File name completion after ^X */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1230 if (!ctrl_x_mode_files()) |
7 | 1231 goto normalchar; |
1232 goto docomplete; | |
477 | 1233 |
1234 case 's': /* Spelling completion after ^X */ | |
1235 case Ctrl_S: | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1236 if (!ctrl_x_mode_spell()) |
477 | 1237 goto normalchar; |
1238 goto docomplete; | |
7 | 1239 |
449 | 1240 case Ctrl_L: /* Whole line completion after ^X */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1241 if (!ctrl_x_mode_whole_line()) |
7 | 1242 { |
1243 /* CTRL-L with 'insertmode' set: Leave Insert mode */ | |
1244 if (p_im) | |
1245 { | |
1246 if (echeck_abbr(Ctrl_L + ABBR_OFF)) | |
1247 break; | |
1248 goto doESCkey; | |
1249 } | |
1250 goto normalchar; | |
1251 } | |
1252 /* FALLTHROUGH */ | |
1253 | |
449 | 1254 case Ctrl_P: /* Do previous/next pattern completion */ |
7 | 1255 case Ctrl_N: |
1256 /* if 'complete' is empty then plain ^P is no longer special, | |
1257 * but it is under other ^X modes */ | |
1258 if (*curbuf->b_p_cpt == NUL | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1259 && (ctrl_x_mode_normal() || ctrl_x_mode_whole_line()) |
449 | 1260 && !(compl_cont_status & CONT_LOCAL)) |
7 | 1261 goto normalchar; |
1262 | |
1263 docomplete: | |
1927 | 1264 compl_busy = TRUE; |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
11002
diff
changeset
|
1265 #ifdef FEAT_FOLDING |
8891
d7ba3f9b9ba6
commit https://github.com/vim/vim/commit/429fcfbf9a9275367fe9441a50a3dcd773497d84
Christian Brabandt <cb@256bit.org>
parents:
8362
diff
changeset
|
1266 disable_fold_update++; /* don't redraw folds here */ |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
11002
diff
changeset
|
1267 #endif |
8224
2baf64fead5e
commit https://github.com/vim/vim/commit/8aefbe0ad5d05ee7225b20024b0f3023286ebd0f
Christian Brabandt <cb@256bit.org>
parents:
8090
diff
changeset
|
1268 if (ins_complete(c, TRUE) == FAIL) |
449 | 1269 compl_cont_status = 0; |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
11002
diff
changeset
|
1270 #ifdef FEAT_FOLDING |
8891
d7ba3f9b9ba6
commit https://github.com/vim/vim/commit/429fcfbf9a9275367fe9441a50a3dcd773497d84
Christian Brabandt <cb@256bit.org>
parents:
8362
diff
changeset
|
1271 disable_fold_update--; |
11073
d2178a6cc9f3
patch 8.0.0425: build errors when building without folding
Christian Brabandt <cb@256bit.org>
parents:
11002
diff
changeset
|
1272 #endif |
1927 | 1273 compl_busy = FALSE; |
7 | 1274 break; |
1275 | |
449 | 1276 case Ctrl_Y: /* copy from previous line or scroll down */ |
1277 case Ctrl_E: /* copy from next line or scroll up */ | |
1278 c = ins_ctrl_ey(c); | |
7 | 1279 break; |
1280 | |
1281 default: | |
1282 #ifdef UNIX | |
1283 if (c == intr_char) /* special interrupt char */ | |
1284 goto do_intr; | |
1285 #endif | |
1286 | |
2845 | 1287 normalchar: |
7 | 1288 /* |
4352 | 1289 * Insert a normal character. |
7 | 1290 */ |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1291 #if defined(FEAT_EVAL) |
2845 | 1292 if (!p_paste) |
1293 { | |
3390 | 1294 /* Trigger InsertCharPre. */ |
1295 char_u *str = do_insert_char_pre(c); | |
1296 char_u *p; | |
1297 | |
1298 if (str != NULL) | |
2845 | 1299 { |
3390 | 1300 if (*str != NUL && stop_arrow() != FAIL) |
2845 | 1301 { |
3390 | 1302 /* Insert the new value of v:char literally. */ |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1303 for (p = str; *p != NUL; MB_PTR_ADV(p)) |
2845 | 1304 { |
3390 | 1305 c = PTR2CHAR(p); |
1306 if (c == CAR || c == K_KENTER || c == NL) | |
1307 ins_eol(c); | |
1308 else | |
1309 ins_char(c); | |
2845 | 1310 } |
3390 | 1311 AppendToRedobuffLit(str, -1); |
2845 | 1312 } |
3390 | 1313 vim_free(str); |
1314 c = NUL; | |
2845 | 1315 } |
1316 | |
3390 | 1317 /* If the new value is already inserted or an empty string |
1318 * then don't insert any character. */ | |
2845 | 1319 if (c == NUL) |
1320 break; | |
1321 } | |
1322 #endif | |
7 | 1323 #ifdef FEAT_SMARTINDENT |
1324 /* Try to perform smart-indenting. */ | |
1325 ins_try_si(c); | |
1326 #endif | |
1327 | |
1328 if (c == ' ') | |
1329 { | |
1330 inserted_space = TRUE; | |
1331 #ifdef FEAT_CINDENT | |
1332 if (inindent(0)) | |
1333 can_cindent = FALSE; | |
1334 #endif | |
1335 if (Insstart_blank_vcol == MAXCOL | |
1336 && curwin->w_cursor.lnum == Insstart.lnum) | |
1337 Insstart_blank_vcol = get_nolist_virtcol(); | |
1338 } | |
1339 | |
3448 | 1340 /* Insert a normal character and check for abbreviations on a |
1341 * special character. Let CTRL-] expand abbreviations without | |
1342 * inserting it. */ | |
1343 if (vim_iswordc(c) || (!echeck_abbr( | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
1344 // Add ABBR_OFF for characters above 0x100, this is |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
1345 // what check_abbr() expects. |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
1346 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : c) |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
1347 && c != Ctrl_RSB)) |
7 | 1348 { |
1349 insert_special(c, FALSE, FALSE); | |
1350 #ifdef FEAT_RIGHTLEFT | |
1351 revins_legal++; | |
1352 revins_chars++; | |
1353 #endif | |
1354 } | |
1355 | |
1356 auto_format(FALSE, TRUE); | |
1357 | |
1358 #ifdef FEAT_FOLDING | |
1359 /* When inserting a character the cursor line must never be in a | |
1360 * closed fold. */ | |
1361 foldOpenCursor(); | |
1362 #endif | |
1363 break; | |
1364 } /* end of switch (c) */ | |
1365 | |
978 | 1366 /* If typed something may trigger CursorHoldI again. */ |
8945
a3060addc328
commit https://github.com/vim/vim/commit/245c41070c7f37d52be43cce0cb140bd3ade6c7e
Christian Brabandt <cb@256bit.org>
parents:
8943
diff
changeset
|
1367 if (c != K_CURSORHOLD |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1368 #ifdef FEAT_COMPL_FUNC |
13215
ae5f855a64be
patch 8.0.1482: using feedkeys() does not work to test completion
Christian Brabandt <cb@256bit.org>
parents:
13214
diff
changeset
|
1369 /* but not in CTRL-X mode, a script can't restore the state */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1370 && ctrl_x_mode_normal() |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1371 #endif |
8945
a3060addc328
commit https://github.com/vim/vim/commit/245c41070c7f37d52be43cce0cb140bd3ade6c7e
Christian Brabandt <cb@256bit.org>
parents:
8943
diff
changeset
|
1372 ) |
978 | 1373 did_cursorhold = FALSE; |
1374 | |
7 | 1375 /* If the cursor was moved we didn't just insert a space */ |
1376 if (arrow_used) | |
1377 inserted_space = FALSE; | |
1378 | |
1379 #ifdef FEAT_CINDENT | |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
1380 if (can_cindent && cindent_on() && ctrl_x_mode_normal()) |
7 | 1381 { |
1382 force_cindent: | |
1383 /* | |
1384 * Indent now if a key was typed that is in 'cinkeys'. | |
1385 */ | |
1386 if (in_cinkeys(c, ' ', line_is_white)) | |
1387 { | |
1388 if (stop_arrow() == OK) | |
1389 /* re-indent the current line */ | |
1390 do_c_expr_indent(); | |
1391 } | |
1392 } | |
1393 #endif /* FEAT_CINDENT */ | |
1394 | |
1395 } /* for (;;) */ | |
1396 /* NOTREACHED */ | |
1397 } | |
1398 | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1399 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1400 ins_need_undo_get(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1401 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1402 return ins_need_undo; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1403 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1404 |
7 | 1405 /* |
1406 * Redraw for Insert mode. | |
1407 * This is postponed until getting the next character to make '$' in the 'cpo' | |
1408 * option work correctly. | |
1409 * Only redraw when there are no characters available. This speeds up | |
1410 * inserting sequences of characters (e.g., for CTRL-R). | |
1411 */ | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
1412 void |
16904
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1413 ins_redraw(int ready) // not busy with something |
7 | 1414 { |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
1415 #ifdef FEAT_CONCEAL |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
1416 linenr_T conceal_old_cursor_line = 0; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
1417 linenr_T conceal_new_cursor_line = 0; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
1418 int conceal_update_lines = FALSE; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
1419 #endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
1420 |
5592 | 1421 if (char_avail()) |
1422 return; | |
1423 | |
1424 /* Trigger CursorMoved if the cursor moved. Not when the popup menu is | |
1425 * visible, the command might delete it. */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1426 if (ready && (has_cursormovedI() |
16904
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1427 # ifdef FEAT_TEXT_PROP |
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1428 || popup_visible |
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1429 # endif |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1430 # if defined(FEAT_CONCEAL) |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1431 || curwin->w_p_cole > 0 |
5592 | 1432 # endif |
1433 ) | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1434 && !EQUAL_POS(last_cursormoved, curwin->w_cursor) |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
1435 && !pum_visible()) |
5592 | 1436 { |
1437 # ifdef FEAT_SYN_HL | |
1438 /* Need to update the screen first, to make sure syntax | |
1439 * highlighting is correct after making a change (e.g., inserting | |
1440 * a "(". The autocommand may also require a redraw, so it's done | |
1441 * again below, unfortunately. */ | |
1442 if (syntax_present(curwin) && must_redraw) | |
1443 update_screen(0); | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
1444 # endif |
5592 | 1445 if (has_cursormovedI()) |
8003
94798af62c56
commit https://github.com/vim/vim/commit/f068dcafcfe0c8018e5a559c50769ca1364bd9a5
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1446 { |
94798af62c56
commit https://github.com/vim/vim/commit/f068dcafcfe0c8018e5a559c50769ca1364bd9a5
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1447 /* Make sure curswant is correct, an autocommand may call |
94798af62c56
commit https://github.com/vim/vim/commit/f068dcafcfe0c8018e5a559c50769ca1364bd9a5
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1448 * getcurpos(). */ |
94798af62c56
commit https://github.com/vim/vim/commit/f068dcafcfe0c8018e5a559c50769ca1364bd9a5
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1449 update_curswant(); |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1450 ins_apply_autocmds(EVENT_CURSORMOVEDI); |
8003
94798af62c56
commit https://github.com/vim/vim/commit/f068dcafcfe0c8018e5a559c50769ca1364bd9a5
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
1451 } |
16904
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1452 #ifdef FEAT_TEXT_PROP |
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1453 if (popup_visible) |
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1454 popup_check_cursor_pos(); |
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1455 #endif |
5592 | 1456 # ifdef FEAT_CONCEAL |
1457 if (curwin->w_p_cole > 0) | |
1458 { | |
1459 conceal_old_cursor_line = last_cursormoved.lnum; | |
1460 conceal_new_cursor_line = curwin->w_cursor.lnum; | |
1461 conceal_update_lines = TRUE; | |
1462 } | |
1463 # endif | |
1464 last_cursormoved = curwin->w_cursor; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1465 } |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1466 |
5592 | 1467 /* Trigger TextChangedI if b_changedtick differs. */ |
1468 if (ready && has_textchangedI() | |
13240
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1469 && curbuf->b_last_changedtick != CHANGEDTICK(curbuf) |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
1470 && !pum_visible()) |
5592 | 1471 { |
14079
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1472 aco_save_T aco; |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1473 varnumber_T tick = CHANGEDTICK(curbuf); |
14463
3b87daa5c37a
patch 8.1.0245: calling setline() in TextChangedI autocmd breaks undo
Christian Brabandt <cb@256bit.org>
parents:
14457
diff
changeset
|
1474 |
14079
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1475 // save and restore curwin and curbuf, in case the autocmd changes them |
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1476 aucmd_prepbuf(&aco, curbuf); |
13240
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1477 apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, FALSE, curbuf); |
14079
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1478 aucmd_restbuf(&aco); |
13240
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1479 curbuf->b_last_changedtick = CHANGEDTICK(curbuf); |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1480 if (tick != CHANGEDTICK(curbuf)) // see ins_apply_autocmds() |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1481 u_save(curwin->w_cursor.lnum, |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1482 (linenr_T)(curwin->w_cursor.lnum + 1)); |
13240
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1483 } |
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1484 |
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1485 /* Trigger TextChangedP if b_changedtick differs. When the popupmenu closes |
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1486 * TextChangedI will need to trigger for backwards compatibility, thus use |
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1487 * different b_last_changedtick* variables. */ |
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1488 if (ready && has_textchangedP() |
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1489 && curbuf->b_last_changedtick_pum != CHANGEDTICK(curbuf) |
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1490 && pum_visible()) |
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1491 { |
14079
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1492 aco_save_T aco; |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1493 varnumber_T tick = CHANGEDTICK(curbuf); |
14079
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1494 |
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1495 // save and restore curwin and curbuf, in case the autocmd changes them |
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1496 aucmd_prepbuf(&aco, curbuf); |
13240
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1497 apply_autocmds(EVENT_TEXTCHANGEDP, NULL, NULL, FALSE, curbuf); |
14079
b5e43a048878
patch 8.1.0057: popup menu displayed wrong when using autocmd
Christian Brabandt <cb@256bit.org>
parents:
14071
diff
changeset
|
1498 aucmd_restbuf(&aco); |
13240
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1499 curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf); |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1500 if (tick != CHANGEDTICK(curbuf)) // see ins_apply_autocmds() |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1501 u_save(curwin->w_cursor.lnum, |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
1502 (linenr_T)(curwin->w_cursor.lnum + 1)); |
13240
5ed6e4a25925
patch 8.0.1494: no autocmd triggered in Insert mode with visible popup menu
Christian Brabandt <cb@256bit.org>
parents:
13238
diff
changeset
|
1503 } |
5592 | 1504 |
18098
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1505 // Trigger SafeState if nothing is pending. |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1506 may_trigger_safestate(ready |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1507 && !ins_compl_active() |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1508 && !pum_visible()); |
a2870e6f5b45
patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1509 |
15436
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1510 #if defined(FEAT_CONCEAL) |
5592 | 1511 if ((conceal_update_lines |
1512 && (conceal_old_cursor_line != conceal_new_cursor_line | |
1513 || conceal_cursor_line(curwin))) | |
1514 || need_cursor_line_redraw) | |
1515 { | |
1516 if (conceal_old_cursor_line != conceal_new_cursor_line) | |
15436
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1517 redrawWinline(curwin, conceal_old_cursor_line); |
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1518 redrawWinline(curwin, conceal_new_cursor_line == 0 |
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1519 ? curwin->w_cursor.lnum : conceal_new_cursor_line); |
5592 | 1520 curwin->w_valid &= ~VALID_CROW; |
15436
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1521 need_cursor_line_redraw = FALSE; |
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1522 } |
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1523 #endif |
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1524 if (must_redraw) |
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1525 update_screen(0); |
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1526 else if (clear_cmdline || redraw_cmdline) |
29f3d59bb6f0
patch 8.1.0726: redrawing specifically for conceal feature
Bram Moolenaar <Bram@vim.org>
parents:
15416
diff
changeset
|
1527 showmode(); /* clear cmdline and show mode */ |
5592 | 1528 showruler(FALSE); |
1529 setcursor(); | |
1530 emsg_on_display = FALSE; /* may remove error message now */ | |
7 | 1531 } |
1532 | |
1533 /* | |
1534 * Handle a CTRL-V or CTRL-Q typed in Insert mode. | |
1535 */ | |
1536 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1537 ins_ctrl_v(void) |
7 | 1538 { |
1539 int c; | |
2811 | 1540 int did_putchar = FALSE; |
7 | 1541 |
1542 /* may need to redraw when no more chars available now */ | |
661 | 1543 ins_redraw(FALSE); |
7 | 1544 |
1545 if (redrawing() && !char_avail()) | |
2811 | 1546 { |
7 | 1547 edit_putchar('^', TRUE); |
2811 | 1548 did_putchar = TRUE; |
1549 } | |
7 | 1550 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */ |
1551 | |
1552 #ifdef FEAT_CMDL_INFO | |
1553 add_to_showcmd_c(Ctrl_V); | |
1554 #endif | |
1555 | |
1556 c = get_literal(); | |
2811 | 1557 if (did_putchar) |
1558 /* when the line fits in 'columns' the '^' is at the start of the next | |
1559 * line and will not removed by the redraw */ | |
1560 edit_unputchar(); | |
7 | 1561 #ifdef FEAT_CMDL_INFO |
1562 clear_showcmd(); | |
1563 #endif | |
1564 insert_special(c, FALSE, TRUE); | |
1565 #ifdef FEAT_RIGHTLEFT | |
1566 revins_chars++; | |
1567 revins_legal++; | |
1568 #endif | |
1569 } | |
1570 | |
1571 /* | |
1572 * Put a character directly onto the screen. It's not stored in a buffer. | |
1573 * Used while handling CTRL-K, CTRL-V, etc. in Insert mode. | |
1574 */ | |
1575 static int pc_status; | |
1576 #define PC_STATUS_UNSET 0 /* pc_bytes was not set */ | |
1577 #define PC_STATUS_RIGHT 1 /* right halve of double-wide char */ | |
1578 #define PC_STATUS_LEFT 2 /* left halve of double-wide char */ | |
1579 #define PC_STATUS_SET 3 /* pc_bytes was filled */ | |
1580 static char_u pc_bytes[MB_MAXBYTES + 1]; /* saved bytes */ | |
1581 static int pc_attr; | |
1582 static int pc_row; | |
1583 static int pc_col; | |
1584 | |
1585 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1586 edit_putchar(int c, int highlight) |
7 | 1587 { |
1588 int attr; | |
1589 | |
1590 if (ScreenLines != NULL) | |
1591 { | |
1592 update_topline(); /* just in case w_topline isn't valid */ | |
1593 validate_cursor(); | |
1594 if (highlight) | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1595 attr = HL_ATTR(HLF_8); |
7 | 1596 else |
1597 attr = 0; | |
1598 pc_row = W_WINROW(curwin) + curwin->w_wrow; | |
12513
3ca08bf99396
patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1599 pc_col = curwin->w_wincol; |
7 | 1600 pc_status = PC_STATUS_UNSET; |
1601 #ifdef FEAT_RIGHTLEFT | |
1602 if (curwin->w_p_rl) | |
1603 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1604 pc_col += curwin->w_width - 1 - curwin->w_wcol; |
7 | 1605 if (has_mbyte) |
1606 { | |
1607 int fix_col = mb_fix_col(pc_col, pc_row); | |
1608 | |
1609 if (fix_col != pc_col) | |
1610 { | |
1611 screen_putchar(' ', pc_row, fix_col, attr); | |
1612 --curwin->w_wcol; | |
1613 pc_status = PC_STATUS_RIGHT; | |
1614 } | |
1615 } | |
1616 } | |
1617 else | |
1618 #endif | |
1619 { | |
1620 pc_col += curwin->w_wcol; | |
1621 if (mb_lefthalve(pc_row, pc_col)) | |
1622 pc_status = PC_STATUS_LEFT; | |
1623 } | |
1624 | |
1625 /* save the character to be able to put it back */ | |
1626 if (pc_status == PC_STATUS_UNSET) | |
1627 { | |
1628 screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr); | |
1629 pc_status = PC_STATUS_SET; | |
1630 } | |
1631 screen_putchar(c, pc_row, pc_col, attr); | |
1632 } | |
1633 } | |
1634 | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1635 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1636 /* |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1637 * Return the effective prompt for the current buffer. |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1638 */ |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1639 char_u * |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1640 prompt_text(void) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1641 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1642 if (curbuf->b_prompt_text == NULL) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1643 return (char_u *)"% "; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1644 return curbuf->b_prompt_text; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1645 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1646 |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1647 /* |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1648 * Prepare for prompt mode: Make sure the last line has the prompt text. |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1649 * Move the cursor to this line. |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1650 */ |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1651 static void |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1652 init_prompt(int cmdchar_todo) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1653 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1654 char_u *prompt = prompt_text(); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1655 char_u *text; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1656 |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1657 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1658 text = ml_get_curline(); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1659 if (STRNCMP(text, prompt, STRLEN(prompt)) != 0) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1660 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1661 // prompt is missing, insert it or append a line with it |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1662 if (*text == NUL) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1663 ml_replace(curbuf->b_ml.ml_line_count, prompt, TRUE); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1664 else |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1665 ml_append(curbuf->b_ml.ml_line_count, prompt, 0, FALSE); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1666 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1667 coladvance((colnr_T)MAXCOL); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1668 changed_bytes(curbuf->b_ml.ml_line_count, 0); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1669 } |
14035
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1670 |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1671 // Insert always starts after the prompt, allow editing text after it. |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1672 if (Insstart_orig.lnum != curwin->w_cursor.lnum |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1673 || Insstart_orig.col != (int)STRLEN(prompt)) |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1674 { |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1675 Insstart.lnum = curwin->w_cursor.lnum; |
14045
e182079c3374
patch 8.1.0040: warnings from 64-bit compiler
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
1676 Insstart.col = (int)STRLEN(prompt); |
14035
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1677 Insstart_orig = Insstart; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1678 Insstart_textlen = Insstart.col; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1679 Insstart_blank_vcol = MAXCOL; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1680 arrow_used = FALSE; |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1681 } |
bccd66fa00c1
patch 8.1.0035: not easy to switch between prompt buffer and other windows
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
1682 |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1683 if (cmdchar_todo == 'A') |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1684 coladvance((colnr_T)MAXCOL); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1685 if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt)) |
14045
e182079c3374
patch 8.1.0040: warnings from 64-bit compiler
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
1686 curwin->w_cursor.col = (int)STRLEN(prompt); |
14037
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14035
diff
changeset
|
1687 /* Make sure the cursor is in a valid position. */ |
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14035
diff
changeset
|
1688 check_cursor(); |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1689 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1690 |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1691 /* |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1692 * Return TRUE if the cursor is in the editable position of the prompt line. |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1693 */ |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1694 int |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1695 prompt_curpos_editable() |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1696 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1697 return curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1698 && curwin->w_cursor.col >= (int)STRLEN(prompt_text()); |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1699 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1700 #endif |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1701 |
7 | 1702 /* |
1703 * Undo the previous edit_putchar(). | |
1704 */ | |
1705 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1706 edit_unputchar(void) |
7 | 1707 { |
1708 if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled) | |
1709 { | |
1710 if (pc_status == PC_STATUS_RIGHT) | |
1711 ++curwin->w_wcol; | |
1712 if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT) | |
15400
ac5542aadd9c
patch 8.1.0708: third argument for redrawWinline() is always FALSE
Bram Moolenaar <Bram@vim.org>
parents:
15382
diff
changeset
|
1713 redrawWinline(curwin, curwin->w_cursor.lnum); |
7 | 1714 else |
1715 screen_puts(pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr); | |
1716 } | |
1717 } | |
1718 | |
1719 /* | |
1720 * Called when p_dollar is set: display a '$' at the end of the changed text | |
1721 * Only works when cursor is in the line that changes. | |
1722 */ | |
1723 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1724 display_dollar(colnr_T col) |
7 | 1725 { |
1726 colnr_T save_col; | |
1727 | |
1728 if (!redrawing()) | |
1729 return; | |
1730 | |
1731 cursor_off(); | |
1732 save_col = curwin->w_cursor.col; | |
1733 curwin->w_cursor.col = col; | |
1734 if (has_mbyte) | |
1735 { | |
1736 char_u *p; | |
1737 | |
1738 /* If on the last byte of a multi-byte move to the first byte. */ | |
1739 p = ml_get_curline(); | |
1740 curwin->w_cursor.col -= (*mb_head_off)(p, p + col); | |
1741 } | |
1742 curs_columns(FALSE); /* recompute w_wrow and w_wcol */ | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
1743 if (curwin->w_wcol < curwin->w_width) |
7 | 1744 { |
1745 edit_putchar('$', FALSE); | |
1746 dollar_vcol = curwin->w_virtcol; | |
1747 } | |
1748 curwin->w_cursor.col = save_col; | |
1749 } | |
1750 | |
1751 /* | |
1752 * Call this function before moving the cursor from the normal insert position | |
1753 * in insert mode. | |
1754 */ | |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18098
diff
changeset
|
1755 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1756 undisplay_dollar(void) |
7 | 1757 { |
3318 | 1758 if (dollar_vcol >= 0) |
1759 { | |
1760 dollar_vcol = -1; | |
15400
ac5542aadd9c
patch 8.1.0708: third argument for redrawWinline() is always FALSE
Bram Moolenaar <Bram@vim.org>
parents:
15382
diff
changeset
|
1761 redrawWinline(curwin, curwin->w_cursor.lnum); |
7 | 1762 } |
1763 } | |
1764 | |
1765 /* | |
1766 * Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D). | |
1767 * Keep the cursor on the same character. | |
1768 * type == INDENT_INC increase indent (for CTRL-T or <Tab>) | |
1769 * type == INDENT_DEC decrease indent (for CTRL-D) | |
1770 * type == INDENT_SET set indent to "amount" | |
1771 * if round is TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec). | |
1772 */ | |
1773 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1774 change_indent( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1775 int type, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1776 int amount, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1777 int round, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1778 int replaced, /* replaced character, put on replace stack */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1779 int call_changed_bytes) /* call changed_bytes() */ |
7 | 1780 { |
1781 int vcol; | |
1782 int last_vcol; | |
1783 int insstart_less; /* reduction for Insstart.col */ | |
1784 int new_cursor_col; | |
1785 int i; | |
1786 char_u *ptr; | |
1787 int save_p_list; | |
1788 int start_col; | |
1789 colnr_T vc; | |
1790 colnr_T orig_col = 0; /* init for GCC */ | |
1791 char_u *new_line, *orig_line = NULL; /* init for GCC */ | |
1792 | |
1793 /* VREPLACE mode needs to know what the line was like before changing */ | |
1794 if (State & VREPLACE_FLAG) | |
1795 { | |
1796 orig_line = vim_strsave(ml_get_curline()); /* Deal with NULL below */ | |
1797 orig_col = curwin->w_cursor.col; | |
1798 } | |
1799 | |
1800 /* for the following tricks we don't want list mode */ | |
1801 save_p_list = curwin->w_p_list; | |
1802 curwin->w_p_list = FALSE; | |
1803 vc = getvcol_nolist(&curwin->w_cursor); | |
1804 vcol = vc; | |
1805 | |
1806 /* | |
1807 * For Replace mode we need to fix the replace stack later, which is only | |
1808 * possible when the cursor is in the indent. Remember the number of | |
1809 * characters before the cursor if it's possible. | |
1810 */ | |
1811 start_col = curwin->w_cursor.col; | |
1812 | |
1813 /* determine offset from first non-blank */ | |
1814 new_cursor_col = curwin->w_cursor.col; | |
1815 beginline(BL_WHITE); | |
1816 new_cursor_col -= curwin->w_cursor.col; | |
1817 | |
1818 insstart_less = curwin->w_cursor.col; | |
1819 | |
1820 /* | |
1821 * If the cursor is in the indent, compute how many screen columns the | |
1822 * cursor is to the left of the first non-blank. | |
1823 */ | |
1824 if (new_cursor_col < 0) | |
1825 vcol = get_indent() - vcol; | |
1826 | |
1827 if (new_cursor_col > 0) /* can't fix replace stack */ | |
1828 start_col = -1; | |
1829 | |
1830 /* | |
1831 * Set the new indent. The cursor will be put on the first non-blank. | |
1832 */ | |
1833 if (type == INDENT_SET) | |
1516 | 1834 (void)set_indent(amount, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 1835 else |
1836 { | |
1837 int save_State = State; | |
1838 | |
1839 /* Avoid being called recursively. */ | |
1840 if (State & VREPLACE_FLAG) | |
1841 State = INSERT; | |
1516 | 1842 shift_line(type == INDENT_DEC, round, 1, call_changed_bytes); |
7 | 1843 State = save_State; |
1844 } | |
1845 insstart_less -= curwin->w_cursor.col; | |
1846 | |
1847 /* | |
1848 * Try to put cursor on same character. | |
1849 * If the cursor is at or after the first non-blank in the line, | |
1850 * compute the cursor column relative to the column of the first | |
1851 * non-blank character. | |
1852 * If we are not in insert mode, leave the cursor on the first non-blank. | |
1853 * If the cursor is before the first non-blank, position it relative | |
1854 * to the first non-blank, counted in screen columns. | |
1855 */ | |
1856 if (new_cursor_col >= 0) | |
1857 { | |
1858 /* | |
1859 * When changing the indent while the cursor is touching it, reset | |
1860 * Insstart_col to 0. | |
1861 */ | |
1862 if (new_cursor_col == 0) | |
1863 insstart_less = MAXCOL; | |
1864 new_cursor_col += curwin->w_cursor.col; | |
1865 } | |
1866 else if (!(State & INSERT)) | |
1867 new_cursor_col = curwin->w_cursor.col; | |
1868 else | |
1869 { | |
1870 /* | |
1871 * Compute the screen column where the cursor should be. | |
1872 */ | |
1873 vcol = get_indent() - vcol; | |
1869 | 1874 curwin->w_virtcol = (colnr_T)((vcol < 0) ? 0 : vcol); |
7 | 1875 |
1876 /* | |
1877 * Advance the cursor until we reach the right screen column. | |
1878 */ | |
1879 vcol = last_vcol = 0; | |
1880 new_cursor_col = -1; | |
1881 ptr = ml_get_curline(); | |
1882 while (vcol <= (int)curwin->w_virtcol) | |
1883 { | |
1884 last_vcol = vcol; | |
1885 if (has_mbyte && new_cursor_col >= 0) | |
474 | 1886 new_cursor_col += (*mb_ptr2len)(ptr + new_cursor_col); |
7 | 1887 else |
1888 ++new_cursor_col; | |
5995 | 1889 vcol += lbr_chartabsize(ptr, ptr + new_cursor_col, (colnr_T)vcol); |
7 | 1890 } |
1891 vcol = last_vcol; | |
1892 | |
1893 /* | |
1894 * May need to insert spaces to be able to position the cursor on | |
1895 * the right screen column. | |
1896 */ | |
1897 if (vcol != (int)curwin->w_virtcol) | |
1898 { | |
1869 | 1899 curwin->w_cursor.col = (colnr_T)new_cursor_col; |
7 | 1900 i = (int)curwin->w_virtcol - vcol; |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1901 ptr = alloc(i + 1); |
7 | 1902 if (ptr != NULL) |
1903 { | |
1904 new_cursor_col += i; | |
1905 ptr[i] = NUL; | |
1906 while (--i >= 0) | |
1907 ptr[i] = ' '; | |
1908 ins_str(ptr); | |
1909 vim_free(ptr); | |
1910 } | |
1911 } | |
1912 | |
1913 /* | |
1914 * When changing the indent while the cursor is in it, reset | |
1915 * Insstart_col to 0. | |
1916 */ | |
1917 insstart_less = MAXCOL; | |
1918 } | |
1919 | |
1920 curwin->w_p_list = save_p_list; | |
1921 | |
1922 if (new_cursor_col <= 0) | |
1923 curwin->w_cursor.col = 0; | |
1924 else | |
1869 | 1925 curwin->w_cursor.col = (colnr_T)new_cursor_col; |
7 | 1926 curwin->w_set_curswant = TRUE; |
1927 changed_cline_bef_curs(); | |
1928 | |
1929 /* | |
1930 * May have to adjust the start of the insert. | |
1931 */ | |
1932 if (State & INSERT) | |
1933 { | |
1934 if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0) | |
1935 { | |
1936 if ((int)Insstart.col <= insstart_less) | |
1937 Insstart.col = 0; | |
1938 else | |
1939 Insstart.col -= insstart_less; | |
1940 } | |
1941 if ((int)ai_col <= insstart_less) | |
1942 ai_col = 0; | |
1943 else | |
1944 ai_col -= insstart_less; | |
1945 } | |
1946 | |
1947 /* | |
1948 * For REPLACE mode, may have to fix the replace stack, if it's possible. | |
1949 * If the number of characters before the cursor decreased, need to pop a | |
1950 * few characters from the replace stack. | |
1951 * If the number of characters before the cursor increased, need to push a | |
1952 * few NULs onto the replace stack. | |
1953 */ | |
1954 if (REPLACE_NORMAL(State) && start_col >= 0) | |
1955 { | |
1956 while (start_col > (int)curwin->w_cursor.col) | |
1957 { | |
1958 replace_join(0); /* remove a NUL from the replace stack */ | |
1959 --start_col; | |
1960 } | |
1961 while (start_col < (int)curwin->w_cursor.col || replaced) | |
1962 { | |
1963 replace_push(NUL); | |
1964 if (replaced) | |
1965 { | |
1966 replace_push(replaced); | |
1967 replaced = NUL; | |
1968 } | |
1969 ++start_col; | |
1970 } | |
1971 } | |
1972 | |
1973 /* | |
1974 * For VREPLACE mode, we also have to fix the replace stack. In this case | |
1975 * it is always possible because we backspace over the whole line and then | |
1976 * put it back again the way we wanted it. | |
1977 */ | |
1978 if (State & VREPLACE_FLAG) | |
1979 { | |
1980 /* If orig_line didn't allocate, just return. At least we did the job, | |
1981 * even if you can't backspace. */ | |
1982 if (orig_line == NULL) | |
1983 return; | |
1984 | |
1985 /* Save new line */ | |
1986 new_line = vim_strsave(ml_get_curline()); | |
1987 if (new_line == NULL) | |
1988 return; | |
1989 | |
1990 /* We only put back the new line up to the cursor */ | |
1991 new_line[curwin->w_cursor.col] = NUL; | |
1992 | |
1993 /* Put back original line */ | |
1994 ml_replace(curwin->w_cursor.lnum, orig_line, FALSE); | |
1995 curwin->w_cursor.col = orig_col; | |
1996 | |
1997 /* Backspace from cursor to start of line */ | |
1998 backspace_until_column(0); | |
1999 | |
2000 /* Insert new stuff into line again */ | |
2001 ins_bytes(new_line); | |
2002 | |
2003 vim_free(new_line); | |
2004 } | |
2005 } | |
2006 | |
2007 /* | |
2008 * Truncate the space at the end of a line. This is to be used only in an | |
2009 * insert mode. It handles fixing the replace stack for REPLACE and VREPLACE | |
2010 * modes. | |
2011 */ | |
2012 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2013 truncate_spaces(char_u *line) |
7 | 2014 { |
2015 int i; | |
2016 | |
2017 /* find start of trailing white space */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2018 for (i = (int)STRLEN(line) - 1; i >= 0 && VIM_ISWHITE(line[i]); i--) |
7 | 2019 { |
2020 if (State & REPLACE_FLAG) | |
2021 replace_join(0); /* remove a NUL from the replace stack */ | |
2022 } | |
2023 line[i + 1] = NUL; | |
2024 } | |
2025 | |
2026 /* | |
2027 * Backspace the cursor until the given column. Handles REPLACE and VREPLACE | |
2028 * modes correctly. May also be used when not in insert mode at all. | |
1782 | 2029 * Will attempt not to go before "col" even when there is a composing |
2030 * character. | |
7 | 2031 */ |
2032 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2033 backspace_until_column(int col) |
7 | 2034 { |
2035 while ((int)curwin->w_cursor.col > col) | |
2036 { | |
2037 curwin->w_cursor.col--; | |
2038 if (State & REPLACE_FLAG) | |
1782 | 2039 replace_do_bs(col); |
2040 else if (!del_char_after_col(col)) | |
2041 break; | |
2042 } | |
2043 } | |
2044 | |
2045 /* | |
2046 * Like del_char(), but make sure not to go before column "limit_col". | |
2047 * Only matters when there are composing characters. | |
2048 * Return TRUE when something was deleted. | |
2049 */ | |
2050 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2051 del_char_after_col(int limit_col UNUSED) |
1782 | 2052 { |
2053 if (enc_utf8 && limit_col >= 0) | |
2054 { | |
1869 | 2055 colnr_T ecol = curwin->w_cursor.col + 1; |
1782 | 2056 |
2057 /* Make sure the cursor is at the start of a character, but | |
2058 * skip forward again when going too far back because of a | |
2059 * composing character. */ | |
2060 mb_adjust_cursor(); | |
1796 | 2061 while (curwin->w_cursor.col < (colnr_T)limit_col) |
1782 | 2062 { |
2063 int l = utf_ptr2len(ml_get_cursor()); | |
2064 | |
2065 if (l == 0) /* end of line */ | |
2066 break; | |
2067 curwin->w_cursor.col += l; | |
2068 } | |
2069 if (*ml_get_cursor() == NUL || curwin->w_cursor.col == ecol) | |
2070 return FALSE; | |
1869 | 2071 del_bytes((long)((int)ecol - curwin->w_cursor.col), FALSE, TRUE); |
1782 | 2072 } |
2073 else | |
2074 (void)del_char(FALSE); | |
2075 return TRUE; | |
2076 } | |
7 | 2077 |
2078 /* | |
2079 * Next character is interpreted literally. | |
2080 * A one, two or three digit decimal number is interpreted as its byte value. | |
2081 * If one or two digits are entered, the next character is given to vungetc(). | |
2082 * For Unicode a character > 255 may be returned. | |
2083 */ | |
2084 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2085 get_literal(void) |
7 | 2086 { |
2087 int cc; | |
2088 int nc; | |
2089 int i; | |
2090 int hex = FALSE; | |
2091 int octal = FALSE; | |
2092 int unicode = 0; | |
2093 | |
2094 if (got_int) | |
2095 return Ctrl_C; | |
2096 | |
2097 #ifdef FEAT_GUI | |
2098 /* | |
2099 * In GUI there is no point inserting the internal code for a special key. | |
2100 * It is more useful to insert the string "<KEY>" instead. This would | |
2101 * probably be useful in a text window too, but it would not be | |
2102 * vi-compatible (maybe there should be an option for it?) -- webb | |
2103 */ | |
2104 if (gui.in_use) | |
2105 ++allow_keys; | |
2106 #endif | |
2107 #ifdef USE_ON_FLY_SCROLL | |
2108 dont_scroll = TRUE; /* disallow scrolling here */ | |
2109 #endif | |
2110 ++no_mapping; /* don't map the next key hits */ | |
2111 cc = 0; | |
2112 i = 0; | |
2113 for (;;) | |
2114 { | |
1389 | 2115 nc = plain_vgetc(); |
7 | 2116 #ifdef FEAT_CMDL_INFO |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
2117 if (!(State & CMDLINE) && MB_BYTE2LEN_CHECK(nc) == 1) |
7 | 2118 add_to_showcmd(nc); |
2119 #endif | |
2120 if (nc == 'x' || nc == 'X') | |
2121 hex = TRUE; | |
2122 else if (nc == 'o' || nc == 'O') | |
2123 octal = TRUE; | |
2124 else if (nc == 'u' || nc == 'U') | |
2125 unicode = nc; | |
2126 else | |
2127 { | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
2128 if (hex || unicode != 0) |
7 | 2129 { |
2130 if (!vim_isxdigit(nc)) | |
2131 break; | |
2132 cc = cc * 16 + hex2nr(nc); | |
2133 } | |
2134 else if (octal) | |
2135 { | |
2136 if (nc < '0' || nc > '7') | |
2137 break; | |
2138 cc = cc * 8 + nc - '0'; | |
2139 } | |
2140 else | |
2141 { | |
2142 if (!VIM_ISDIGIT(nc)) | |
2143 break; | |
2144 cc = cc * 10 + nc - '0'; | |
2145 } | |
2146 | |
2147 ++i; | |
2148 } | |
2149 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
2150 if (cc > 255 && unicode == 0) |
7 | 2151 cc = 255; /* limit range to 0-255 */ |
2152 nc = 0; | |
2153 | |
2154 if (hex) /* hex: up to two chars */ | |
2155 { | |
2156 if (i >= 2) | |
2157 break; | |
2158 } | |
2159 else if (unicode) /* Unicode: up to four or eight chars */ | |
2160 { | |
2161 if ((unicode == 'u' && i >= 4) || (unicode == 'U' && i >= 8)) | |
2162 break; | |
2163 } | |
2164 else if (i >= 3) /* decimal or octal: up to three chars */ | |
2165 break; | |
2166 } | |
2167 if (i == 0) /* no number entered */ | |
2168 { | |
2169 if (nc == K_ZERO) /* NUL is stored as NL */ | |
2170 { | |
2171 cc = '\n'; | |
2172 nc = 0; | |
2173 } | |
2174 else | |
2175 { | |
2176 cc = nc; | |
2177 nc = 0; | |
2178 } | |
2179 } | |
2180 | |
2181 if (cc == 0) /* NUL is stored as NL */ | |
2182 cc = '\n'; | |
221 | 2183 if (enc_dbcs && (cc & 0xff) == 0) |
2184 cc = '?'; /* don't accept an illegal DBCS char, the NUL in the | |
2185 second byte will cause trouble! */ | |
7 | 2186 |
2187 --no_mapping; | |
2188 #ifdef FEAT_GUI | |
2189 if (gui.in_use) | |
2190 --allow_keys; | |
2191 #endif | |
2192 if (nc) | |
2193 vungetc(nc); | |
2194 got_int = FALSE; /* CTRL-C typed after CTRL-V is not an interrupt */ | |
2195 return cc; | |
2196 } | |
2197 | |
2198 /* | |
2199 * Insert character, taking care of special keys and mod_mask | |
2200 */ | |
2201 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2202 insert_special( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2203 int c, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2204 int allow_modmask, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2205 int ctrlv) /* c was typed after CTRL-V */ |
7 | 2206 { |
2207 char_u *p; | |
2208 int len; | |
2209 | |
2210 /* | |
2211 * Special function key, translate into "<Key>". Up to the last '>' is | |
2212 * inserted with ins_str(), so as not to replace characters in replace | |
2213 * mode. | |
2214 * Only use mod_mask for special keys, to avoid things like <S-Space>, | |
2215 * unless 'allow_modmask' is TRUE. | |
2216 */ | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2217 #ifdef MACOS_X |
7 | 2218 /* Command-key never produces a normal key */ |
2219 if (mod_mask & MOD_MASK_CMD) | |
2220 allow_modmask = TRUE; | |
2221 #endif | |
2222 if (IS_SPECIAL(c) || (mod_mask && allow_modmask)) | |
2223 { | |
2224 p = get_special_key_name(c, mod_mask); | |
2225 len = (int)STRLEN(p); | |
2226 c = p[len - 1]; | |
2227 if (len > 2) | |
2228 { | |
2229 if (stop_arrow() == FAIL) | |
2230 return; | |
2231 p[len - 1] = NUL; | |
2232 ins_str(p); | |
620 | 2233 AppendToRedobuffLit(p, -1); |
7 | 2234 ctrlv = FALSE; |
2235 } | |
2236 } | |
2237 if (stop_arrow() == OK) | |
2238 insertchar(c, ctrlv ? INSCHAR_CTRLV : 0, -1); | |
2239 } | |
2240 | |
2241 /* | |
2242 * Special characters in this context are those that need processing other | |
2243 * than the simple insertion that can be performed here. This includes ESC | |
2244 * which terminates the insert, and CR/NL which need special processing to | |
2245 * open up a new line. This routine tries to optimize insertions performed by | |
2246 * the "redo", "undo" or "put" commands, so it needs to know when it should | |
2247 * stop and defer processing to the "normal" mechanism. | |
2248 * '0' and '^' are special, because they can be followed by CTRL-D. | |
2249 */ | |
2250 #ifdef EBCDIC | |
2251 # define ISSPECIAL(c) ((c) < ' ' || (c) == '0' || (c) == '^') | |
2252 #else | |
2253 # define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^') | |
2254 #endif | |
2255 | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
2256 #define WHITECHAR(cc) (VIM_ISWHITE(cc) && (!enc_utf8 || !utf_iscomposing(utf_ptr2char(ml_get_cursor() + 1)))) |
7 | 2257 |
3584 | 2258 /* |
2259 * "flags": INSCHAR_FORMAT - force formatting | |
2260 * INSCHAR_CTRLV - char typed just after CTRL-V | |
2261 * INSCHAR_NO_FEX - don't use 'formatexpr' | |
2262 * | |
2263 * NOTE: passes the flags value straight through to internal_format() which, | |
2264 * beside INSCHAR_FORMAT (above), is also looking for these: | |
2265 * INSCHAR_DO_COM - format comments | |
2266 * INSCHAR_COM_LIST - format comments with num list or 2nd line indent | |
2267 */ | |
7 | 2268 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2269 insertchar( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2270 int c, /* character to insert or NUL */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2271 int flags, /* INSCHAR_FORMAT, etc. */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2272 int second_indent) /* indent for second line if >= 0 */ |
7 | 2273 { |
2274 int textwidth; | |
2275 char_u *p; | |
2276 int fo_ins_blank; | |
6667 | 2277 int force_format = flags & INSCHAR_FORMAT; |
2278 | |
2279 textwidth = comp_textwidth(force_format); | |
7 | 2280 fo_ins_blank = has_format_option(FO_INS_BLANK); |
2281 | |
2282 /* | |
2283 * Try to break the line in two or more pieces when: | |
2284 * - Always do this if we have been called to do formatting only. | |
2285 * - Always do this when 'formatoptions' has the 'a' flag and the line | |
2286 * ends in white space. | |
2287 * - Otherwise: | |
2288 * - Don't do this if inserting a blank | |
2289 * - Don't do this if an existing character is being replaced, unless | |
2290 * we're in VREPLACE mode. | |
2291 * - Do this if the cursor is not on the line where insert started | |
2292 * or - 'formatoptions' doesn't have 'l' or the line was not too long | |
2293 * before the insert. | |
2294 * - 'formatoptions' doesn't have 'b' or a blank was inserted at or | |
2295 * before 'textwidth' | |
2296 */ | |
667 | 2297 if (textwidth > 0 |
6667 | 2298 && (force_format |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2299 || (!VIM_ISWHITE(c) |
7 | 2300 && !((State & REPLACE_FLAG) |
2301 && !(State & VREPLACE_FLAG) | |
2302 && *ml_get_cursor() != NUL) | |
2303 && (curwin->w_cursor.lnum != Insstart.lnum | |
2304 || ((!has_format_option(FO_INS_LONG) | |
2305 || Insstart_textlen <= (colnr_T)textwidth) | |
2306 && (!fo_ins_blank | |
2307 || Insstart_blank_vcol <= (colnr_T)textwidth | |
2308 )))))) | |
2309 { | |
667 | 2310 /* Format with 'formatexpr' when it's set. Use internal formatting |
2311 * when 'formatexpr' isn't set or it returns non-zero. */ | |
2312 #if defined(FEAT_EVAL) | |
6667 | 2313 int do_internal = TRUE; |
2314 colnr_T virtcol = get_nolist_virtcol() | |
2315 + char2cells(c != NUL ? c : gchar_cursor()); | |
2316 | |
2317 if (*curbuf->b_p_fex != NUL && (flags & INSCHAR_NO_FEX) == 0 | |
2318 && (force_format || virtcol > (colnr_T)textwidth)) | |
1000 | 2319 { |
2320 do_internal = (fex_format(curwin->w_cursor.lnum, 1L, c) != 0); | |
2321 /* It may be required to save for undo again, e.g. when setline() | |
2322 * was called. */ | |
2323 ins_need_undo = TRUE; | |
2324 } | |
2325 if (do_internal) | |
667 | 2326 #endif |
2004 | 2327 internal_format(textwidth, second_indent, flags, c == NUL, c); |
667 | 2328 } |
2329 | |
7 | 2330 if (c == NUL) /* only formatting was wanted */ |
2331 return; | |
2332 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2333 // Check whether this character should end a comment. |
7 | 2334 if (did_ai && (int)c == end_comment_pending) |
2335 { | |
2336 char_u *line; | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2337 char_u lead_end[COM_MAX_LEN]; // end-comment string |
7 | 2338 int middle_len, end_len; |
2339 int i; | |
2340 | |
2341 /* | |
2342 * Need to remove existing (middle) comment leader and insert end | |
2343 * comment leader. First, check what comment leader we can find. | |
2344 */ | |
3562 | 2345 i = get_leader_len(line = ml_get_curline(), &p, FALSE, TRUE); |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2346 if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) // Just checking |
7 | 2347 { |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2348 // Skip middle-comment string |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2349 while (*p && p[-1] != ':') // find end of middle flags |
7 | 2350 ++p; |
2351 middle_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ","); | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2352 // Don't count trailing white space for middle_len |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2353 while (middle_len > 0 && VIM_ISWHITE(lead_end[middle_len - 1])) |
7 | 2354 --middle_len; |
2355 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2356 // Find the end-comment string |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2357 while (*p && p[-1] != ':') // find end of end flags |
7 | 2358 ++p; |
2359 end_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ","); | |
2360 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2361 // Skip white space before the cursor |
7 | 2362 i = curwin->w_cursor.col; |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2363 while (--i >= 0 && VIM_ISWHITE(line[i])) |
7 | 2364 ; |
2365 i++; | |
2366 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2367 // Skip to before the middle leader |
7 | 2368 i -= middle_len; |
2369 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2370 // Check some expected things before we go on |
7 | 2371 if (i >= 0 && lead_end[end_len - 1] == end_comment_pending) |
2372 { | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2373 // Backspace over all the stuff we want to replace |
7 | 2374 backspace_until_column(i); |
2375 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2376 // Insert the end-comment string, except for the last |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2377 // character, which will get inserted as normal later. |
7 | 2378 ins_bytes_len(lead_end, end_len - 1); |
2379 } | |
2380 } | |
2381 } | |
2382 end_comment_pending = NUL; | |
2383 | |
2384 did_ai = FALSE; | |
2385 #ifdef FEAT_SMARTINDENT | |
2386 did_si = FALSE; | |
2387 can_si = FALSE; | |
2388 can_si_back = FALSE; | |
2389 #endif | |
2390 | |
2391 /* | |
2392 * If there's any pending input, grab up to INPUT_BUFLEN at once. | |
2393 * This speeds up normal text input considerably. | |
2394 * Don't do this when 'cindent' or 'indentexpr' is set, because we might | |
2395 * need to re-indent at a ':', or any other character (but not what | |
2396 * 'paste' is set).. | |
3390 | 2397 * Don't do this when there an InsertCharPre autocommand is defined, |
2398 * because we need to fire the event for every character. | |
13870
08370aad873d
patch 8.0.1806: InsertCharPre causes problems for autocomplete
Christian Brabandt <cb@256bit.org>
parents:
13788
diff
changeset
|
2399 * Do the check for InsertCharPre before the call to vpeekc() because the |
08370aad873d
patch 8.0.1806: InsertCharPre causes problems for autocomplete
Christian Brabandt <cb@256bit.org>
parents:
13788
diff
changeset
|
2400 * InsertCharPre autocommand could change the input buffer. |
7 | 2401 */ |
2402 #ifdef USE_ON_FLY_SCROLL | |
2403 dont_scroll = FALSE; /* allow scrolling here */ | |
2404 #endif | |
2405 | |
2406 if ( !ISSPECIAL(c) | |
2407 && (!has_mbyte || (*mb_char2len)(c) == 1) | |
13870
08370aad873d
patch 8.0.1806: InsertCharPre causes problems for autocomplete
Christian Brabandt <cb@256bit.org>
parents:
13788
diff
changeset
|
2408 && !has_insertcharpre() |
7 | 2409 && vpeekc() != NUL |
2410 && !(State & REPLACE_FLAG) | |
2411 #ifdef FEAT_CINDENT | |
2412 && !cindent_on() | |
2413 #endif | |
2414 #ifdef FEAT_RIGHTLEFT | |
2415 && !p_ri | |
2416 #endif | |
13870
08370aad873d
patch 8.0.1806: InsertCharPre causes problems for autocomplete
Christian Brabandt <cb@256bit.org>
parents:
13788
diff
changeset
|
2417 ) |
7 | 2418 { |
2419 #define INPUT_BUFLEN 100 | |
2420 char_u buf[INPUT_BUFLEN + 1]; | |
2421 int i; | |
2422 colnr_T virtcol = 0; | |
2423 | |
2424 buf[0] = c; | |
2425 i = 1; | |
667 | 2426 if (textwidth > 0) |
7 | 2427 virtcol = get_nolist_virtcol(); |
2428 /* | |
2429 * Stop the string when: | |
2430 * - no more chars available | |
2431 * - finding a special character (command key) | |
2432 * - buffer is full | |
2433 * - running into the 'textwidth' boundary | |
2434 * - need to check for abbreviation: A non-word char after a word-char | |
2435 */ | |
2436 while ( (c = vpeekc()) != NUL | |
2437 && !ISSPECIAL(c) | |
2438 && (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1) | |
2439 && i < INPUT_BUFLEN | |
2440 && (textwidth == 0 | |
2441 || (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth) | |
2442 && !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1]))) | |
2443 { | |
2444 #ifdef FEAT_RIGHTLEFT | |
2445 c = vgetc(); | |
2446 if (p_hkmap && KeyTyped) | |
2447 c = hkmap(c); /* Hebrew mode mapping */ | |
2448 buf[i++] = c; | |
2449 #else | |
2450 buf[i++] = vgetc(); | |
2451 #endif | |
2452 } | |
2453 | |
2454 #ifdef FEAT_DIGRAPHS | |
2455 do_digraph(-1); /* clear digraphs */ | |
2456 do_digraph(buf[i-1]); /* may be the start of a digraph */ | |
2457 #endif | |
2458 buf[i] = NUL; | |
2459 ins_str(buf); | |
2460 if (flags & INSCHAR_CTRLV) | |
2461 { | |
2462 redo_literal(*buf); | |
2463 i = 1; | |
2464 } | |
2465 else | |
2466 i = 0; | |
2467 if (buf[i] != NUL) | |
620 | 2468 AppendToRedobuffLit(buf + i, -1); |
7 | 2469 } |
2470 else | |
2471 { | |
667 | 2472 int cc; |
2473 | |
7 | 2474 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1) |
2475 { | |
2476 char_u buf[MB_MAXBYTES + 1]; | |
2477 | |
2478 (*mb_char2bytes)(c, buf); | |
2479 buf[cc] = NUL; | |
2480 ins_char_bytes(buf, cc); | |
2481 AppendCharToRedobuff(c); | |
2482 } | |
2483 else | |
2484 { | |
2485 ins_char(c); | |
2486 if (flags & INSCHAR_CTRLV) | |
2487 redo_literal(c); | |
2488 else | |
2489 AppendCharToRedobuff(c); | |
2490 } | |
2491 } | |
2492 } | |
2493 | |
2494 /* | |
667 | 2495 * Format text at the current insert position. |
3584 | 2496 * |
2497 * If the INSCHAR_COM_LIST flag is present, then the value of second_indent | |
2498 * will be the comment leader length sent to open_line(). | |
667 | 2499 */ |
2500 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2501 internal_format( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2502 int textwidth, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2503 int second_indent, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2504 int flags, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2505 int format_only, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2506 int c) /* character to be inserted (can be NUL) */ |
667 | 2507 { |
2508 int cc; | |
2509 int save_char = NUL; | |
2510 int haveto_redraw = FALSE; | |
2511 int fo_ins_blank = has_format_option(FO_INS_BLANK); | |
2512 int fo_multibyte = has_format_option(FO_MBYTE_BREAK); | |
2513 int fo_white_par = has_format_option(FO_WHITE_PAR); | |
2514 int first_line = TRUE; | |
2515 colnr_T leader_len; | |
2516 int no_leader = FALSE; | |
2517 int do_comments = (flags & INSCHAR_DO_COM); | |
6199 | 2518 #ifdef FEAT_LINEBREAK |
2519 int has_lbr = curwin->w_p_lbr; | |
2520 | |
2521 /* make sure win_lbr_chartabsize() counts correctly */ | |
2522 curwin->w_p_lbr = FALSE; | |
2523 #endif | |
667 | 2524 |
2525 /* | |
2526 * When 'ai' is off we don't want a space under the cursor to be | |
2527 * deleted. Replace it with an 'x' temporarily. | |
2528 */ | |
14424
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14419
diff
changeset
|
2529 if (!curbuf->b_p_ai && !(State & VREPLACE_FLAG)) |
667 | 2530 { |
2531 cc = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2532 if (VIM_ISWHITE(cc)) |
667 | 2533 { |
2534 save_char = cc; | |
2535 pchar_cursor('x'); | |
2536 } | |
2537 } | |
2538 | |
2539 /* | |
2540 * Repeat breaking lines, until the current line is not too long. | |
2541 */ | |
2542 while (!got_int) | |
2543 { | |
2544 int startcol; /* Cursor column at entry */ | |
2545 int wantcol; /* column at textwidth border */ | |
2546 int foundcol; /* column for start of spaces */ | |
2547 int end_foundcol = 0; /* column for start of word */ | |
2548 colnr_T len; | |
2549 colnr_T virtcol; | |
2550 int orig_col = 0; | |
2551 char_u *saved_text = NULL; | |
2552 colnr_T col; | |
2004 | 2553 colnr_T end_col; |
15440
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2554 int wcc; // counter for whitespace chars |
2004 | 2555 |
2556 virtcol = get_nolist_virtcol() | |
2557 + char2cells(c != NUL ? c : gchar_cursor()); | |
2558 if (virtcol <= (colnr_T)textwidth) | |
667 | 2559 break; |
2560 | |
2561 if (no_leader) | |
2562 do_comments = FALSE; | |
2563 else if (!(flags & INSCHAR_FORMAT) | |
2564 && has_format_option(FO_WRAP_COMS)) | |
2565 do_comments = TRUE; | |
2566 | |
2567 /* Don't break until after the comment leader */ | |
2568 if (do_comments) | |
3562 | 2569 leader_len = get_leader_len(ml_get_curline(), NULL, FALSE, TRUE); |
667 | 2570 else |
2571 leader_len = 0; | |
2572 | |
2573 /* If the line doesn't start with a comment leader, then don't | |
2574 * start one in a following broken line. Avoids that a %word | |
2575 * moved to the start of the next line causes all following lines | |
2576 * to start with %. */ | |
2577 if (leader_len == 0) | |
2578 no_leader = TRUE; | |
2579 if (!(flags & INSCHAR_FORMAT) | |
2580 && leader_len == 0 | |
2581 && !has_format_option(FO_WRAP)) | |
2582 | |
2583 break; | |
2584 if ((startcol = curwin->w_cursor.col) == 0) | |
2585 break; | |
2586 | |
2587 /* find column of textwidth border */ | |
2588 coladvance((colnr_T)textwidth); | |
2589 wantcol = curwin->w_cursor.col; | |
2590 | |
2004 | 2591 curwin->w_cursor.col = startcol; |
667 | 2592 foundcol = 0; |
2593 | |
2594 /* | |
2595 * Find position to break at. | |
2596 * Stop at first entered white when 'formatoptions' has 'v' | |
2597 */ | |
2598 while ((!fo_ins_blank && !has_format_option(FO_INS_VI)) | |
3162 | 2599 || (flags & INSCHAR_FORMAT) |
667 | 2600 || curwin->w_cursor.lnum != Insstart.lnum |
2601 || curwin->w_cursor.col >= Insstart.col) | |
2602 { | |
2004 | 2603 if (curwin->w_cursor.col == startcol && c != NUL) |
2604 cc = c; | |
2605 else | |
2606 cc = gchar_cursor(); | |
667 | 2607 if (WHITECHAR(cc)) |
2608 { | |
2609 /* remember position of blank just before text */ | |
2004 | 2610 end_col = curwin->w_cursor.col; |
667 | 2611 |
15440
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2612 // find start of sequence of blanks |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2613 wcc = 0; |
667 | 2614 while (curwin->w_cursor.col > 0 && WHITECHAR(cc)) |
2615 { | |
2616 dec_cursor(); | |
2617 cc = gchar_cursor(); | |
15440
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2618 |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2619 // Increment count of how many whitespace chars in this |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2620 // group; we only need to know if it's more than one. |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2621 if (wcc < 2) |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2622 wcc++; |
667 | 2623 } |
2624 if (curwin->w_cursor.col == 0 && WHITECHAR(cc)) | |
2625 break; /* only spaces in front of text */ | |
15440
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2626 |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2627 // Don't break after a period when 'formatoptions' has 'p' and |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2628 // there are less than two spaces. |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2629 if (has_format_option(FO_PERIOD_ABBR) && cc == '.' && wcc < 2) |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2630 continue; |
5ecac7734184
patch 8.1.0728: cannot avoid breaking after a single space.
Bram Moolenaar <Bram@vim.org>
parents:
15436
diff
changeset
|
2631 |
667 | 2632 /* Don't break until after the comment leader */ |
2633 if (curwin->w_cursor.col < leader_len) | |
2634 break; | |
2635 if (has_format_option(FO_ONE_LETTER)) | |
2636 { | |
2637 /* do not break after one-letter words */ | |
2638 if (curwin->w_cursor.col == 0) | |
2639 break; /* one-letter word at begin */ | |
2004 | 2640 /* do not break "#a b" when 'tw' is 2 */ |
2641 if (curwin->w_cursor.col <= leader_len) | |
2642 break; | |
667 | 2643 col = curwin->w_cursor.col; |
2644 dec_cursor(); | |
2645 cc = gchar_cursor(); | |
2646 | |
2647 if (WHITECHAR(cc)) | |
2648 continue; /* one-letter, continue */ | |
2649 curwin->w_cursor.col = col; | |
2650 } | |
2004 | 2651 |
2652 inc_cursor(); | |
2653 | |
2654 end_foundcol = end_col + 1; | |
2655 foundcol = curwin->w_cursor.col; | |
2656 if (curwin->w_cursor.col <= (colnr_T)wantcol) | |
667 | 2657 break; |
2658 } | |
2004 | 2659 else if (cc >= 0x100 && fo_multibyte) |
667 | 2660 { |
2661 /* Break after or before a multi-byte character. */ | |
2004 | 2662 if (curwin->w_cursor.col != startcol) |
2663 { | |
2664 /* Don't break until after the comment leader */ | |
2665 if (curwin->w_cursor.col < leader_len) | |
2666 break; | |
2667 col = curwin->w_cursor.col; | |
2668 inc_cursor(); | |
2669 /* Don't change end_foundcol if already set. */ | |
2670 if (foundcol != curwin->w_cursor.col) | |
2671 { | |
2672 foundcol = curwin->w_cursor.col; | |
2673 end_foundcol = foundcol; | |
2674 if (curwin->w_cursor.col <= (colnr_T)wantcol) | |
2675 break; | |
2676 } | |
2677 curwin->w_cursor.col = col; | |
2678 } | |
2679 | |
2680 if (curwin->w_cursor.col == 0) | |
2681 break; | |
2682 | |
2683 col = curwin->w_cursor.col; | |
2684 | |
2685 dec_cursor(); | |
2686 cc = gchar_cursor(); | |
2687 | |
2688 if (WHITECHAR(cc)) | |
2689 continue; /* break with space */ | |
2690 /* Don't break until after the comment leader */ | |
2691 if (curwin->w_cursor.col < leader_len) | |
2692 break; | |
2693 | |
2694 curwin->w_cursor.col = col; | |
2695 | |
667 | 2696 foundcol = curwin->w_cursor.col; |
2697 end_foundcol = foundcol; | |
2004 | 2698 if (curwin->w_cursor.col <= (colnr_T)wantcol) |
2699 break; | |
667 | 2700 } |
2701 if (curwin->w_cursor.col == 0) | |
2702 break; | |
2703 dec_cursor(); | |
2704 } | |
2705 | |
2706 if (foundcol == 0) /* no spaces, cannot break line */ | |
2707 { | |
2708 curwin->w_cursor.col = startcol; | |
2709 break; | |
2710 } | |
2711 | |
2712 /* Going to break the line, remove any "$" now. */ | |
2713 undisplay_dollar(); | |
2714 | |
2715 /* | |
2716 * Offset between cursor position and line break is used by replace | |
2717 * stack functions. VREPLACE does not use this, and backspaces | |
2718 * over the text instead. | |
2719 */ | |
2720 if (State & VREPLACE_FLAG) | |
2721 orig_col = startcol; /* Will start backspacing from here */ | |
2722 else | |
2004 | 2723 replace_offset = startcol - end_foundcol; |
667 | 2724 |
2725 /* | |
2726 * adjust startcol for spaces that will be deleted and | |
2727 * characters that will remain on top line | |
2728 */ | |
2729 curwin->w_cursor.col = foundcol; | |
2004 | 2730 while ((cc = gchar_cursor(), WHITECHAR(cc)) |
2731 && (!fo_white_par || curwin->w_cursor.col < startcol)) | |
667 | 2732 inc_cursor(); |
2733 startcol -= curwin->w_cursor.col; | |
2734 if (startcol < 0) | |
2735 startcol = 0; | |
2736 | |
2737 if (State & VREPLACE_FLAG) | |
2738 { | |
2739 /* | |
2740 * In VREPLACE mode, we will backspace over the text to be | |
2741 * wrapped, so save a copy now to put on the next line. | |
2742 */ | |
2743 saved_text = vim_strsave(ml_get_cursor()); | |
2744 curwin->w_cursor.col = orig_col; | |
2745 if (saved_text == NULL) | |
2746 break; /* Can't do it, out of memory */ | |
2747 saved_text[startcol] = NUL; | |
2748 | |
2749 /* Backspace over characters that will move to the next line */ | |
2750 if (!fo_white_par) | |
2751 backspace_until_column(foundcol); | |
2752 } | |
2753 else | |
2754 { | |
2755 /* put cursor after pos. to break line */ | |
2756 if (!fo_white_par) | |
2757 curwin->w_cursor.col = foundcol; | |
2758 } | |
2759 | |
2760 /* | |
2761 * Split the line just before the margin. | |
2762 * Only insert/delete lines, but don't really redraw the window. | |
2763 */ | |
2764 open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX | |
2765 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0) | |
2766 + (do_comments ? OPENLINE_DO_COM : 0) | |
3584 | 2767 + ((flags & INSCHAR_COM_LIST) ? OPENLINE_COM_LIST : 0) |
2768 , ((flags & INSCHAR_COM_LIST) ? second_indent : old_indent)); | |
2769 if (!(flags & INSCHAR_COM_LIST)) | |
2770 old_indent = 0; | |
667 | 2771 |
2772 replace_offset = 0; | |
2773 if (first_line) | |
2774 { | |
3584 | 2775 if (!(flags & INSCHAR_COM_LIST)) |
2776 { | |
2777 /* | |
3632 | 2778 * This section is for auto-wrap of numeric lists. When not |
2779 * in insert mode (i.e. format_lines()), the INSCHAR_COM_LIST | |
2780 * flag will be set and open_line() will handle it (as seen | |
2781 * above). The code here (and in get_number_indent()) will | |
2782 * recognize comments if needed... | |
3584 | 2783 */ |
2784 if (second_indent < 0 && has_format_option(FO_Q_NUMBER)) | |
3632 | 2785 second_indent = |
2786 get_number_indent(curwin->w_cursor.lnum - 1); | |
3584 | 2787 if (second_indent >= 0) |
2788 { | |
2789 if (State & VREPLACE_FLAG) | |
2790 change_indent(INDENT_SET, second_indent, | |
2791 FALSE, NUL, TRUE); | |
2792 else | |
3632 | 2793 if (leader_len > 0 && second_indent - leader_len > 0) |
2794 { | |
2795 int i; | |
2796 int padding = second_indent - leader_len; | |
2797 | |
2798 /* We started at the first_line of a numbered list | |
2799 * that has a comment. the open_line() function has | |
2800 * inserted the proper comment leader and positioned | |
2801 * the cursor at the end of the split line. Now we | |
2802 * add the additional whitespace needed after the | |
2803 * comment leader for the numbered list. */ | |
2804 for (i = 0; i < padding; i++) | |
2805 ins_str((char_u *)" "); | |
2806 } | |
2807 else | |
2808 { | |
3584 | 2809 (void)set_indent(second_indent, SIN_CHANGED); |
3632 | 2810 } |
3584 | 2811 } |
667 | 2812 } |
2813 first_line = FALSE; | |
2814 } | |
2815 | |
2816 if (State & VREPLACE_FLAG) | |
2817 { | |
2818 /* | |
2819 * In VREPLACE mode we have backspaced over the text to be | |
2820 * moved, now we re-insert it into the new line. | |
2821 */ | |
2822 ins_bytes(saved_text); | |
2823 vim_free(saved_text); | |
2824 } | |
2825 else | |
2826 { | |
2827 /* | |
2828 * Check if cursor is not past the NUL off the line, cindent | |
2829 * may have added or removed indent. | |
2830 */ | |
2831 curwin->w_cursor.col += startcol; | |
2832 len = (colnr_T)STRLEN(ml_get_curline()); | |
2833 if (curwin->w_cursor.col > len) | |
2834 curwin->w_cursor.col = len; | |
2835 } | |
2836 | |
2837 haveto_redraw = TRUE; | |
2838 #ifdef FEAT_CINDENT | |
2839 can_cindent = TRUE; | |
2840 #endif | |
2841 /* moved the cursor, don't autoindent or cindent now */ | |
2842 did_ai = FALSE; | |
2843 #ifdef FEAT_SMARTINDENT | |
2844 did_si = FALSE; | |
2845 can_si = FALSE; | |
2846 can_si_back = FALSE; | |
2847 #endif | |
2848 line_breakcheck(); | |
2849 } | |
2850 | |
2851 if (save_char != NUL) /* put back space after cursor */ | |
2852 pchar_cursor(save_char); | |
2853 | |
6199 | 2854 #ifdef FEAT_LINEBREAK |
2855 curwin->w_p_lbr = has_lbr; | |
2856 #endif | |
667 | 2857 if (!format_only && haveto_redraw) |
2858 { | |
2859 update_topline(); | |
2860 redraw_curbuf_later(VALID); | |
2861 } | |
2862 } | |
2863 | |
2864 /* | |
7 | 2865 * Called after inserting or deleting text: When 'formatoptions' includes the |
2866 * 'a' flag format from the current line until the end of the paragraph. | |
2867 * Keep the cursor at the same position relative to the text. | |
2868 * The caller must have saved the cursor line for undo, following ones will be | |
2869 * saved here. | |
2870 */ | |
2871 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2872 auto_format( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2873 int trailblank, /* when TRUE also format with trailing blank */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2874 int prev_line) /* may start in previous line */ |
7 | 2875 { |
2876 pos_T pos; | |
2877 colnr_T len; | |
2878 char_u *old; | |
2879 char_u *new, *pnew; | |
2880 int wasatend; | |
301 | 2881 int cc; |
7 | 2882 |
2883 if (!has_format_option(FO_AUTO)) | |
2884 return; | |
2885 | |
2886 pos = curwin->w_cursor; | |
2887 old = ml_get_curline(); | |
2888 | |
2889 /* may remove added space */ | |
2890 check_auto_format(FALSE); | |
2891 | |
2892 /* Don't format in Insert mode when the cursor is on a trailing blank, the | |
2893 * user might insert normal text next. Also skip formatting when "1" is | |
2894 * in 'formatoptions' and there is a single character before the cursor. | |
2895 * Otherwise the line would be broken and when typing another non-white | |
2896 * next they are not joined back together. */ | |
1872 | 2897 wasatend = (pos.col == (colnr_T)STRLEN(old)); |
7 | 2898 if (*old != NUL && !trailblank && wasatend) |
2899 { | |
2900 dec_cursor(); | |
301 | 2901 cc = gchar_cursor(); |
2902 if (!WHITECHAR(cc) && curwin->w_cursor.col > 0 | |
2903 && has_format_option(FO_ONE_LETTER)) | |
7 | 2904 dec_cursor(); |
301 | 2905 cc = gchar_cursor(); |
2906 if (WHITECHAR(cc)) | |
7 | 2907 { |
2908 curwin->w_cursor = pos; | |
2909 return; | |
2910 } | |
2911 curwin->w_cursor = pos; | |
2912 } | |
2913 | |
2914 /* With the 'c' flag in 'formatoptions' and 't' missing: only format | |
2915 * comments. */ | |
2916 if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP) | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
2917 && get_leader_len(old, NULL, FALSE, TRUE) == 0) |
7 | 2918 return; |
2919 | |
2920 /* | |
2921 * May start formatting in a previous line, so that after "x" a word is | |
2922 * moved to the previous line if it fits there now. Only when this is not | |
2923 * the start of a paragraph. | |
2924 */ | |
2925 if (prev_line && !paragraph_start(curwin->w_cursor.lnum)) | |
2926 { | |
2927 --curwin->w_cursor.lnum; | |
2928 if (u_save_cursor() == FAIL) | |
2929 return; | |
2930 } | |
2931 | |
2932 /* | |
2933 * Do the formatting and restore the cursor position. "saved_cursor" will | |
2934 * be adjusted for the text formatting. | |
2935 */ | |
2936 saved_cursor = pos; | |
1563 | 2937 format_lines((linenr_T)-1, FALSE); |
7 | 2938 curwin->w_cursor = saved_cursor; |
2939 saved_cursor.lnum = 0; | |
2940 | |
2941 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
2942 { | |
2943 /* "cannot happen" */ | |
2944 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2945 coladvance((colnr_T)MAXCOL); | |
2946 } | |
2947 else | |
2948 check_cursor_col(); | |
2949 | |
2950 /* Insert mode: If the cursor is now after the end of the line while it | |
2951 * previously wasn't, the line was broken. Because of the rule above we | |
2952 * need to add a space when 'w' is in 'formatoptions' to keep a paragraph | |
2953 * formatted. */ | |
2954 if (!wasatend && has_format_option(FO_WHITE_PAR)) | |
2955 { | |
2956 new = ml_get_curline(); | |
835 | 2957 len = (colnr_T)STRLEN(new); |
7 | 2958 if (curwin->w_cursor.col == len) |
2959 { | |
2960 pnew = vim_strnsave(new, len + 2); | |
2961 pnew[len] = ' '; | |
2962 pnew[len + 1] = NUL; | |
2963 ml_replace(curwin->w_cursor.lnum, pnew, FALSE); | |
2964 /* remove the space later */ | |
2965 did_add_space = TRUE; | |
2966 } | |
2967 else | |
2968 /* may remove added space */ | |
2969 check_auto_format(FALSE); | |
2970 } | |
2971 | |
2972 check_cursor(); | |
2973 } | |
2974 | |
2975 /* | |
2976 * When an extra space was added to continue a paragraph for auto-formatting, | |
2977 * delete it now. The space must be under the cursor, just after the insert | |
2978 * position. | |
2979 */ | |
2980 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2981 check_auto_format( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2982 int end_insert) /* TRUE when ending Insert mode */ |
7 | 2983 { |
2984 int c = ' '; | |
301 | 2985 int cc; |
7 | 2986 |
2987 if (did_add_space) | |
2988 { | |
301 | 2989 cc = gchar_cursor(); |
2990 if (!WHITECHAR(cc)) | |
7 | 2991 /* Somehow the space was removed already. */ |
2992 did_add_space = FALSE; | |
2993 else | |
2994 { | |
2995 if (!end_insert) | |
2996 { | |
2997 inc_cursor(); | |
2998 c = gchar_cursor(); | |
2999 dec_cursor(); | |
3000 } | |
3001 if (c != NUL) | |
3002 { | |
3003 /* The space is no longer at the end of the line, delete it. */ | |
3004 del_char(FALSE); | |
3005 did_add_space = FALSE; | |
3006 } | |
3007 } | |
3008 } | |
3009 } | |
3010 | |
3011 /* | |
3012 * Find out textwidth to be used for formatting: | |
3013 * if 'textwidth' option is set, use it | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3014 * else if 'wrapmargin' option is set, use curwin->w_width - 'wrapmargin' |
7 | 3015 * if invalid value, use 0. |
3016 * Set default to window width (maximum 79) for "gq" operator. | |
3017 */ | |
3018 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3019 comp_textwidth( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3020 int ff) /* force formatting (for "gq" command) */ |
7 | 3021 { |
3022 int textwidth; | |
3023 | |
3024 textwidth = curbuf->b_p_tw; | |
3025 if (textwidth == 0 && curbuf->b_p_wm) | |
3026 { | |
3027 /* The width is the window width minus 'wrapmargin' minus all the | |
3028 * things that add to the margin. */ | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3029 textwidth = curwin->w_width - curbuf->b_p_wm; |
7 | 3030 #ifdef FEAT_CMDWIN |
3031 if (cmdwin_type != 0) | |
3032 textwidth -= 1; | |
3033 #endif | |
3034 #ifdef FEAT_FOLDING | |
3035 textwidth -= curwin->w_p_fdc; | |
3036 #endif | |
3037 #ifdef FEAT_SIGNS | |
9852
4eea48b76d03
commit https://github.com/vim/vim/commit/95ec9d6a6ab3117d60ff638670a803d43974ba51
Christian Brabandt <cb@256bit.org>
parents:
9826
diff
changeset
|
3038 if (signcolumn_on(curwin)) |
7 | 3039 textwidth -= 1; |
3040 #endif | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2107
diff
changeset
|
3041 if (curwin->w_p_nu || curwin->w_p_rnu) |
7 | 3042 textwidth -= 8; |
3043 } | |
3044 if (textwidth < 0) | |
3045 textwidth = 0; | |
3046 if (ff && textwidth == 0) | |
3047 { | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3048 textwidth = curwin->w_width - 1; |
7 | 3049 if (textwidth > 79) |
3050 textwidth = 79; | |
3051 } | |
3052 return textwidth; | |
3053 } | |
3054 | |
3055 /* | |
3056 * Put a character in the redo buffer, for when just after a CTRL-V. | |
3057 */ | |
3058 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3059 redo_literal(int c) |
7 | 3060 { |
3061 char_u buf[10]; | |
3062 | |
3063 /* Only digits need special treatment. Translate them into a string of | |
3064 * three digits. */ | |
3065 if (VIM_ISDIGIT(c)) | |
3066 { | |
1872 | 3067 vim_snprintf((char *)buf, sizeof(buf), "%03d", c); |
7 | 3068 AppendToRedobuff(buf); |
3069 } | |
3070 else | |
3071 AppendCharToRedobuff(c); | |
3072 } | |
3073 | |
3074 /* | |
3075 * start_arrow() is called when an arrow key is used in insert mode. | |
484 | 3076 * For undo/redo it resembles hitting the <ESC> key. |
7 | 3077 */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
3078 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3079 start_arrow( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3080 pos_T *end_insert_pos) /* can be NULL */ |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3081 { |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3082 start_arrow_common(end_insert_pos, TRUE); |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3083 } |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3084 |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3085 /* |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3086 * Like start_arrow() but with end_change argument. |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3087 * Will prepare for redo of CTRL-G U if "end_change" is FALSE. |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3088 */ |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3089 static void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3090 start_arrow_with_change( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3091 pos_T *end_insert_pos, /* can be NULL */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3092 int end_change) /* end undoable change */ |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3093 { |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3094 start_arrow_common(end_insert_pos, end_change); |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3095 if (!end_change) |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3096 { |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3097 AppendCharToRedobuff(Ctrl_G); |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3098 AppendCharToRedobuff('U'); |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3099 } |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3100 } |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3101 |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3102 static void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3103 start_arrow_common( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3104 pos_T *end_insert_pos, /* can be NULL */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3105 int end_change) /* end undoable change */ |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3106 { |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
3107 if (!arrow_used && end_change) /* something has been inserted */ |
7 | 3108 { |
3109 AppendToRedobuff(ESC_STR); | |
5434 | 3110 stop_insert(end_insert_pos, FALSE, FALSE); |
7 | 3111 arrow_used = TRUE; /* this means we stopped the current insert */ |
3112 } | |
744 | 3113 #ifdef FEAT_SPELL |
221 | 3114 check_spell_redraw(); |
3115 #endif | |
7 | 3116 } |
3117 | |
744 | 3118 #ifdef FEAT_SPELL |
221 | 3119 /* |
3120 * If we skipped highlighting word at cursor, do it now. | |
3121 * It may be skipped again, thus reset spell_redraw_lnum first. | |
3122 */ | |
3123 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3124 check_spell_redraw(void) |
221 | 3125 { |
3126 if (spell_redraw_lnum != 0) | |
3127 { | |
3128 linenr_T lnum = spell_redraw_lnum; | |
3129 | |
3130 spell_redraw_lnum = 0; | |
15400
ac5542aadd9c
patch 8.1.0708: third argument for redrawWinline() is always FALSE
Bram Moolenaar <Bram@vim.org>
parents:
15382
diff
changeset
|
3131 redrawWinline(curwin, lnum); |
221 | 3132 } |
3133 } | |
484 | 3134 |
221 | 3135 #endif |
3136 | |
7 | 3137 /* |
3138 * stop_arrow() is called before a change is made in insert mode. | |
3139 * If an arrow key has been used, start a new insertion. | |
3140 * Returns FAIL if undo is impossible, shouldn't insert then. | |
3141 */ | |
3142 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3143 stop_arrow(void) |
7 | 3144 { |
3145 if (arrow_used) | |
3146 { | |
6138 | 3147 Insstart = curwin->w_cursor; /* new insertion starts here */ |
3148 if (Insstart.col > Insstart_orig.col && !ins_need_undo) | |
3149 /* Don't update the original insert position when moved to the | |
3150 * right, except when nothing was inserted yet. */ | |
3151 update_Insstart_orig = FALSE; | |
3152 Insstart_textlen = (colnr_T)linetabsize(ml_get_curline()); | |
3153 | |
7 | 3154 if (u_save_cursor() == OK) |
3155 { | |
3156 arrow_used = FALSE; | |
3157 ins_need_undo = FALSE; | |
3158 } | |
6138 | 3159 |
7 | 3160 ai_col = 0; |
3161 if (State & VREPLACE_FLAG) | |
3162 { | |
3163 orig_line_count = curbuf->b_ml.ml_line_count; | |
3164 vr_lines_changed = 1; | |
3165 } | |
3166 ResetRedobuff(); | |
3167 AppendToRedobuff((char_u *)"1i"); /* pretend we start an insertion */ | |
613 | 3168 new_insert_skip = 2; |
7 | 3169 } |
3170 else if (ins_need_undo) | |
3171 { | |
3172 if (u_save_cursor() == OK) | |
3173 ins_need_undo = FALSE; | |
3174 } | |
3175 | |
3176 #ifdef FEAT_FOLDING | |
3177 /* Always open fold at the cursor line when inserting something. */ | |
3178 foldOpenCursor(); | |
3179 #endif | |
3180 | |
3181 return (arrow_used || ins_need_undo ? FAIL : OK); | |
3182 } | |
3183 | |
3184 /* | |
840 | 3185 * Do a few things to stop inserting. |
3186 * "end_insert_pos" is where insert ended. It is NULL when we already jumped | |
3187 * to another window/buffer. | |
7 | 3188 */ |
3189 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3190 stop_insert( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3191 pos_T *end_insert_pos, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3192 int esc, /* called by ins_esc() */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3193 int nomove) /* <c-\><c-o>, don't move cursor */ |
7 | 3194 { |
603 | 3195 int cc; |
3196 char_u *ptr; | |
7 | 3197 |
3198 stop_redo_ins(); | |
3199 replace_flush(); /* abandon replace stack */ | |
3200 | |
3201 /* | |
603 | 3202 * Save the inserted text for later redo with ^@ and CTRL-A. |
3203 * Don't do it when "restart_edit" was set and nothing was inserted, | |
3204 * otherwise CTRL-O w and then <Left> will clear "last_insert". | |
7 | 3205 */ |
603 | 3206 ptr = get_inserted(); |
615 | 3207 if (did_restart_edit == 0 || (ptr != NULL |
3208 && (int)STRLEN(ptr) > new_insert_skip)) | |
603 | 3209 { |
3210 vim_free(last_insert); | |
3211 last_insert = ptr; | |
3212 last_insert_skip = new_insert_skip; | |
3213 } | |
3214 else | |
3215 vim_free(ptr); | |
7 | 3216 |
840 | 3217 if (!arrow_used && end_insert_pos != NULL) |
7 | 3218 { |
3219 /* Auto-format now. It may seem strange to do this when stopping an | |
3220 * insertion (or moving the cursor), but it's required when appending | |
3221 * a line and having it end in a space. But only do it when something | |
3222 * was actually inserted, otherwise undo won't work. */ | |
10 | 3223 if (!ins_need_undo && has_format_option(FO_AUTO)) |
7 | 3224 { |
10 | 3225 pos_T tpos = curwin->w_cursor; |
3226 | |
7 | 3227 /* When the cursor is at the end of the line after a space the |
3228 * formatting will move it to the following word. Avoid that by | |
3229 * moving the cursor onto the space. */ | |
3230 cc = 'x'; | |
3231 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL) | |
3232 { | |
3233 dec_cursor(); | |
3234 cc = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3235 if (!VIM_ISWHITE(cc)) |
10 | 3236 curwin->w_cursor = tpos; |
7 | 3237 } |
3238 | |
3239 auto_format(TRUE, FALSE); | |
3240 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3241 if (VIM_ISWHITE(cc)) |
10 | 3242 { |
3243 if (gchar_cursor() != NUL) | |
3244 inc_cursor(); | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
3245 // If the cursor is still at the same character, also keep |
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
3246 // the "coladd". |
10 | 3247 if (gchar_cursor() == NUL |
3248 && curwin->w_cursor.lnum == tpos.lnum | |
3249 && curwin->w_cursor.col == tpos.col) | |
3250 curwin->w_cursor.coladd = tpos.coladd; | |
3251 } | |
7 | 3252 } |
3253 | |
3254 /* If a space was inserted for auto-formatting, remove it now. */ | |
3255 check_auto_format(TRUE); | |
3256 | |
3257 /* If we just did an auto-indent, remove the white space from the end | |
10 | 3258 * of the line, and put the cursor back. |
1892 | 3259 * Do this when ESC was used or moving the cursor up/down. |
3260 * Check for the old position still being valid, just in case the text | |
3261 * got changed unexpectedly. */ | |
5434 | 3262 if (!nomove && did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL |
1892 | 3263 && curwin->w_cursor.lnum != end_insert_pos->lnum)) |
3264 && end_insert_pos->lnum <= curbuf->b_ml.ml_line_count) | |
7 | 3265 { |
10 | 3266 pos_T tpos = curwin->w_cursor; |
3267 | |
3268 curwin->w_cursor = *end_insert_pos; | |
1892 | 3269 check_cursor_col(); /* make sure it is not past the line */ |
786 | 3270 for (;;) |
3271 { | |
3272 if (gchar_cursor() == NUL && curwin->w_cursor.col > 0) | |
3273 --curwin->w_cursor.col; | |
3274 cc = gchar_cursor(); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3275 if (!VIM_ISWHITE(cc)) |
786 | 3276 break; |
1892 | 3277 if (del_char(TRUE) == FAIL) |
3278 break; /* should not happen */ | |
786 | 3279 } |
10 | 3280 if (curwin->w_cursor.lnum != tpos.lnum) |
3281 curwin->w_cursor = tpos; | |
6318 | 3282 else |
3283 { | |
6363 | 3284 /* reset tpos, could have been invalidated in the loop above */ |
3285 tpos = curwin->w_cursor; | |
6318 | 3286 tpos.col++; |
3287 if (cc != NUL && gchar_pos(&tpos) == NUL) | |
3288 ++curwin->w_cursor.col; /* put cursor back on the NUL */ | |
3289 } | |
7 | 3290 |
3291 /* <C-S-Right> may have started Visual mode, adjust the position for | |
3292 * deleted characters. */ | |
3293 if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum) | |
3294 { | |
1872 | 3295 int len = (int)STRLEN(ml_get_curline()); |
3296 | |
3297 if (VIsual.col > len) | |
7 | 3298 { |
1872 | 3299 VIsual.col = len; |
7 | 3300 VIsual.coladd = 0; |
3301 } | |
3302 } | |
3303 } | |
3304 } | |
3305 did_ai = FALSE; | |
3306 #ifdef FEAT_SMARTINDENT | |
3307 did_si = FALSE; | |
3308 can_si = FALSE; | |
3309 can_si_back = FALSE; | |
3310 #endif | |
3311 | |
840 | 3312 /* Set '[ and '] to the inserted text. When end_insert_pos is NULL we are |
3313 * now in a different buffer. */ | |
3314 if (end_insert_pos != NULL) | |
3315 { | |
3316 curbuf->b_op_start = Insstart; | |
5680 | 3317 curbuf->b_op_start_orig = Insstart_orig; |
840 | 3318 curbuf->b_op_end = *end_insert_pos; |
3319 } | |
7 | 3320 } |
3321 | |
3322 /* | |
3323 * Set the last inserted text to a single character. | |
3324 * Used for the replace command. | |
3325 */ | |
3326 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3327 set_last_insert(int c) |
7 | 3328 { |
3329 char_u *s; | |
3330 | |
3331 vim_free(last_insert); | |
3332 last_insert = alloc(MB_MAXBYTES * 3 + 5); | |
3333 if (last_insert != NULL) | |
3334 { | |
3335 s = last_insert; | |
3336 /* Use the CTRL-V only when entering a special char */ | |
3337 if (c < ' ' || c == DEL) | |
3338 *s++ = Ctrl_V; | |
3339 s = add_char2buf(c, s); | |
3340 *s++ = ESC; | |
3341 *s++ = NUL; | |
3342 last_insert_skip = 0; | |
3343 } | |
3344 } | |
3345 | |
359 | 3346 #if defined(EXITFREE) || defined(PROTO) |
3347 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3348 free_last_insert(void) |
359 | 3349 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
3350 VIM_CLEAR(last_insert); |
359 | 3351 } |
3352 #endif | |
3353 | |
7 | 3354 /* |
3355 * Add character "c" to buffer "s". Escape the special meaning of K_SPECIAL | |
3356 * and CSI. Handle multi-byte characters. | |
3357 * Returns a pointer to after the added bytes. | |
3358 */ | |
3359 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3360 add_char2buf(int c, char_u *s) |
7 | 3361 { |
3549 | 3362 char_u temp[MB_MAXBYTES + 1]; |
7 | 3363 int i; |
3364 int len; | |
3365 | |
3366 len = (*mb_char2bytes)(c, temp); | |
3367 for (i = 0; i < len; ++i) | |
3368 { | |
3369 c = temp[i]; | |
3370 /* Need to escape K_SPECIAL and CSI like in the typeahead buffer. */ | |
3371 if (c == K_SPECIAL) | |
3372 { | |
3373 *s++ = K_SPECIAL; | |
3374 *s++ = KS_SPECIAL; | |
3375 *s++ = KE_FILLER; | |
3376 } | |
3377 #ifdef FEAT_GUI | |
3378 else if (c == CSI) | |
3379 { | |
3380 *s++ = CSI; | |
3381 *s++ = KS_EXTRA; | |
3382 *s++ = (int)KE_CSI; | |
3383 } | |
3384 #endif | |
3385 else | |
3386 *s++ = c; | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
3387 } |
7 | 3388 return s; |
3389 } | |
3390 | |
3391 /* | |
3392 * move cursor to start of line | |
3393 * if flags & BL_WHITE move to first non-white | |
3394 * if flags & BL_SOL move to first non-white if startofline is set, | |
3395 * otherwise keep "curswant" column | |
3396 * if flags & BL_FIX don't leave the cursor on a NUL. | |
3397 */ | |
3398 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3399 beginline(int flags) |
7 | 3400 { |
3401 if ((flags & BL_SOL) && !p_sol) | |
3402 coladvance(curwin->w_curswant); | |
3403 else | |
3404 { | |
3405 curwin->w_cursor.col = 0; | |
3406 curwin->w_cursor.coladd = 0; | |
3407 | |
3408 if (flags & (BL_WHITE | BL_SOL)) | |
3409 { | |
3410 char_u *ptr; | |
3411 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3412 for (ptr = ml_get_curline(); VIM_ISWHITE(*ptr) |
7 | 3413 && !((flags & BL_FIX) && ptr[1] == NUL); ++ptr) |
3414 ++curwin->w_cursor.col; | |
3415 } | |
3416 curwin->w_set_curswant = TRUE; | |
3417 } | |
3418 } | |
3419 | |
3420 /* | |
3421 * oneright oneleft cursor_down cursor_up | |
3422 * | |
3423 * Move one char {right,left,down,up}. | |
773 | 3424 * Doesn't move onto the NUL past the end of the line, unless it is allowed. |
7 | 3425 * Return OK when successful, FAIL when we hit a line of file boundary. |
3426 */ | |
3427 | |
3428 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3429 oneright(void) |
7 | 3430 { |
3431 char_u *ptr; | |
3432 int l; | |
3433 | |
3434 if (virtual_active()) | |
3435 { | |
3436 pos_T prevpos = curwin->w_cursor; | |
3437 | |
3438 /* Adjust for multi-wide char (excluding TAB) */ | |
3439 ptr = ml_get_cursor(); | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
3440 coladvance(getviscol() + ((*ptr != TAB |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
3441 && vim_isprintc((*mb_ptr2char)(ptr))) |
7 | 3442 ? ptr2cells(ptr) : 1)); |
3443 curwin->w_set_curswant = TRUE; | |
3444 /* Return OK if the cursor moved, FAIL otherwise (at window edge). */ | |
3445 return (prevpos.col != curwin->w_cursor.col | |
3446 || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL; | |
3447 } | |
3448 | |
3449 ptr = ml_get_cursor(); | |
773 | 3450 if (*ptr == NUL) |
3451 return FAIL; /* already at the very end */ | |
3452 | |
3453 if (has_mbyte) | |
3454 l = (*mb_ptr2len)(ptr); | |
7 | 3455 else |
773 | 3456 l = 1; |
3457 | |
3458 /* move "l" bytes right, but don't end up on the NUL, unless 'virtualedit' | |
3459 * contains "onemore". */ | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
3460 if (ptr[l] == NUL && (ve_flags & VE_ONEMORE) == 0) |
773 | 3461 return FAIL; |
3462 curwin->w_cursor.col += l; | |
7 | 3463 |
3464 curwin->w_set_curswant = TRUE; | |
3465 return OK; | |
3466 } | |
3467 | |
3468 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3469 oneleft(void) |
7 | 3470 { |
3471 if (virtual_active()) | |
3472 { | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
3473 #ifdef FEAT_LINEBREAK |
7 | 3474 int width; |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
3475 #endif |
7 | 3476 int v = getviscol(); |
3477 | |
3478 if (v == 0) | |
3479 return FAIL; | |
3480 | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
3481 #ifdef FEAT_LINEBREAK |
7 | 3482 /* We might get stuck on 'showbreak', skip over it. */ |
3483 width = 1; | |
3484 for (;;) | |
3485 { | |
3486 coladvance(v - width); | |
5995 | 3487 /* getviscol() is slow, skip it when 'showbreak' is empty, |
3488 * 'breakindent' is not set and there are no multi-byte | |
3489 * characters */ | |
3490 if ((*p_sbr == NUL && !curwin->w_p_bri | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
3491 && !has_mbyte) || getviscol() < v) |
7 | 3492 break; |
3493 ++width; | |
3494 } | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
3495 #else |
7 | 3496 coladvance(v - 1); |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
3497 #endif |
7 | 3498 |
3499 if (curwin->w_cursor.coladd == 1) | |
3500 { | |
3501 char_u *ptr; | |
3502 | |
3503 /* Adjust for multi-wide char (not a TAB) */ | |
3504 ptr = ml_get_cursor(); | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
3505 if (*ptr != TAB && vim_isprintc((*mb_ptr2char)(ptr)) |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
3506 && ptr2cells(ptr) > 1) |
7 | 3507 curwin->w_cursor.coladd = 0; |
3508 } | |
3509 | |
3510 curwin->w_set_curswant = TRUE; | |
3511 return OK; | |
3512 } | |
3513 | |
3514 if (curwin->w_cursor.col == 0) | |
3515 return FAIL; | |
3516 | |
3517 curwin->w_set_curswant = TRUE; | |
3518 --curwin->w_cursor.col; | |
3519 | |
3520 /* if the character on the left of the current cursor is a multi-byte | |
3521 * character, move to its first byte */ | |
3522 if (has_mbyte) | |
3523 mb_adjust_cursor(); | |
3524 return OK; | |
3525 } | |
3526 | |
3527 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3528 cursor_up( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3529 long n, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3530 int upd_topline) /* When TRUE: update topline */ |
7 | 3531 { |
3532 linenr_T lnum; | |
3533 | |
3534 if (n > 0) | |
3535 { | |
3536 lnum = curwin->w_cursor.lnum; | |
161 | 3537 /* This fails if the cursor is already in the first line or the count |
3538 * is larger than the line number and '-' is in 'cpoptions' */ | |
3539 if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL)) | |
7 | 3540 return FAIL; |
3541 if (n >= lnum) | |
3542 lnum = 1; | |
3543 else | |
3544 #ifdef FEAT_FOLDING | |
3545 if (hasAnyFolding(curwin)) | |
3546 { | |
3547 /* | |
3548 * Count each sequence of folded lines as one logical line. | |
3549 */ | |
4352 | 3550 /* go to the start of the current fold */ |
7 | 3551 (void)hasFolding(lnum, &lnum, NULL); |
3552 | |
3553 while (n--) | |
3554 { | |
3555 /* move up one line */ | |
3556 --lnum; | |
3557 if (lnum <= 1) | |
3558 break; | |
3559 /* If we entered a fold, move to the beginning, unless in | |
3560 * Insert mode or when 'foldopen' contains "all": it will open | |
3561 * in a moment. */ | |
3562 if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL))) | |
3563 (void)hasFolding(lnum, &lnum, NULL); | |
3564 } | |
3565 if (lnum < 1) | |
3566 lnum = 1; | |
3567 } | |
3568 else | |
3569 #endif | |
3570 lnum -= n; | |
3571 curwin->w_cursor.lnum = lnum; | |
3572 } | |
3573 | |
3574 /* try to advance to the column we want to be at */ | |
3575 coladvance(curwin->w_curswant); | |
3576 | |
3577 if (upd_topline) | |
3578 update_topline(); /* make sure curwin->w_topline is valid */ | |
3579 | |
3580 return OK; | |
3581 } | |
3582 | |
3583 /* | |
3584 * Cursor down a number of logical lines. | |
3585 */ | |
3586 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3587 cursor_down( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3588 long n, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3589 int upd_topline) /* When TRUE: update topline */ |
7 | 3590 { |
3591 linenr_T lnum; | |
3592 | |
3593 if (n > 0) | |
3594 { | |
3595 lnum = curwin->w_cursor.lnum; | |
3596 #ifdef FEAT_FOLDING | |
3597 /* Move to last line of fold, will fail if it's the end-of-file. */ | |
3598 (void)hasFolding(lnum, NULL, &lnum); | |
3599 #endif | |
161 | 3600 /* This fails if the cursor is already in the last line or would move |
4352 | 3601 * beyond the last line and '-' is in 'cpoptions' */ |
161 | 3602 if (lnum >= curbuf->b_ml.ml_line_count |
3603 || (lnum + n > curbuf->b_ml.ml_line_count | |
3604 && vim_strchr(p_cpo, CPO_MINUS) != NULL)) | |
7 | 3605 return FAIL; |
3606 if (lnum + n >= curbuf->b_ml.ml_line_count) | |
3607 lnum = curbuf->b_ml.ml_line_count; | |
3608 else | |
3609 #ifdef FEAT_FOLDING | |
3610 if (hasAnyFolding(curwin)) | |
3611 { | |
3612 linenr_T last; | |
3613 | |
3614 /* count each sequence of folded lines as one logical line */ | |
3615 while (n--) | |
3616 { | |
3617 if (hasFolding(lnum, NULL, &last)) | |
3618 lnum = last + 1; | |
3619 else | |
3620 ++lnum; | |
3621 if (lnum >= curbuf->b_ml.ml_line_count) | |
3622 break; | |
3623 } | |
3624 if (lnum > curbuf->b_ml.ml_line_count) | |
3625 lnum = curbuf->b_ml.ml_line_count; | |
3626 } | |
3627 else | |
3628 #endif | |
3629 lnum += n; | |
3630 curwin->w_cursor.lnum = lnum; | |
3631 } | |
3632 | |
3633 /* try to advance to the column we want to be at */ | |
3634 coladvance(curwin->w_curswant); | |
3635 | |
3636 if (upd_topline) | |
3637 update_topline(); /* make sure curwin->w_topline is valid */ | |
3638 | |
3639 return OK; | |
3640 } | |
3641 | |
3642 /* | |
3643 * Stuff the last inserted text in the read buffer. | |
3644 * Last_insert actually is a copy of the redo buffer, so we | |
3645 * first have to remove the command. | |
3646 */ | |
3647 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3648 stuff_inserted( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3649 int c, /* Command character to be inserted */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3650 long count, /* Repeat this many times */ |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3651 int no_esc) /* Don't add an ESC at the end */ |
7 | 3652 { |
3653 char_u *esc_ptr; | |
3654 char_u *ptr; | |
3655 char_u *last_ptr; | |
3656 char_u last = NUL; | |
3657 | |
3658 ptr = get_last_insert(); | |
3659 if (ptr == NULL) | |
3660 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15440
diff
changeset
|
3661 emsg(_(e_noinstext)); |
7 | 3662 return FAIL; |
3663 } | |
3664 | |
3665 /* may want to stuff the command character, to start Insert mode */ | |
3666 if (c != NUL) | |
3667 stuffcharReadbuff(c); | |
3668 if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL) | |
3669 *esc_ptr = NUL; /* remove the ESC */ | |
3670 | |
3671 /* when the last char is either "0" or "^" it will be quoted if no ESC | |
3672 * comes after it OR if it will inserted more than once and "ptr" | |
3673 * starts with ^D. -- Acevedo | |
3674 */ | |
3675 last_ptr = (esc_ptr ? esc_ptr : ptr + STRLEN(ptr)) - 1; | |
3676 if (last_ptr >= ptr && (*last_ptr == '0' || *last_ptr == '^') | |
3677 && (no_esc || (*ptr == Ctrl_D && count > 1))) | |
3678 { | |
3679 last = *last_ptr; | |
3680 *last_ptr = NUL; | |
3681 } | |
3682 | |
3683 do | |
3684 { | |
3685 stuffReadbuff(ptr); | |
3686 /* a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^" */ | |
3687 if (last) | |
3688 stuffReadbuff((char_u *)(last == '0' | |
3689 ? IF_EB("\026\060\064\070", CTRL_V_STR "xf0") | |
3690 : IF_EB("\026^", CTRL_V_STR "^"))); | |
3691 } | |
3692 while (--count > 0); | |
3693 | |
3694 if (last) | |
3695 *last_ptr = last; | |
3696 | |
3697 if (esc_ptr != NULL) | |
3698 *esc_ptr = ESC; /* put the ESC back */ | |
3699 | |
3700 /* may want to stuff a trailing ESC, to get out of Insert mode */ | |
3701 if (!no_esc) | |
3702 stuffcharReadbuff(ESC); | |
3703 | |
3704 return OK; | |
3705 } | |
3706 | |
3707 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3708 get_last_insert(void) |
7 | 3709 { |
3710 if (last_insert == NULL) | |
3711 return NULL; | |
3712 return last_insert + last_insert_skip; | |
3713 } | |
3714 | |
3715 /* | |
3716 * Get last inserted string, and remove trailing <Esc>. | |
3717 * Returns pointer to allocated memory (must be freed) or NULL. | |
3718 */ | |
3719 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3720 get_last_insert_save(void) |
7 | 3721 { |
3722 char_u *s; | |
3723 int len; | |
3724 | |
3725 if (last_insert == NULL) | |
3726 return NULL; | |
3727 s = vim_strsave(last_insert + last_insert_skip); | |
3728 if (s != NULL) | |
3729 { | |
3730 len = (int)STRLEN(s); | |
3731 if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */ | |
3732 s[len - 1] = NUL; | |
3733 } | |
3734 return s; | |
3735 } | |
3736 | |
3737 /* | |
3738 * Check the word in front of the cursor for an abbreviation. | |
3739 * Called when the non-id character "c" has been entered. | |
3740 * When an abbreviation is recognized it is removed from the text and | |
3741 * the replacement string is inserted in typebuf.tb_buf[], followed by "c". | |
3742 */ | |
3743 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3744 echeck_abbr(int c) |
7 | 3745 { |
3746 /* Don't check for abbreviation in paste mode, when disabled and just | |
3747 * after moving around with cursor keys. */ | |
3748 if (p_paste || no_abbr || arrow_used) | |
3749 return FALSE; | |
3750 | |
3751 return check_abbr(c, ml_get_curline(), curwin->w_cursor.col, | |
3752 curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0); | |
3753 } | |
3754 | |
3755 /* | |
3756 * replace-stack functions | |
3757 * | |
3758 * When replacing characters, the replaced characters are remembered for each | |
3759 * new character. This is used to re-insert the old text when backspacing. | |
3760 * | |
3761 * There is a NUL headed list of characters for each character that is | |
3762 * currently in the file after the insertion point. When BS is used, one NUL | |
3763 * headed list is put back for the deleted character. | |
3764 * | |
3765 * For a newline, there are two NUL headed lists. One contains the characters | |
3766 * that the NL replaced. The extra one stores the characters after the cursor | |
3767 * that were deleted (always white space). | |
3768 * | |
3769 * Replace_offset is normally 0, in which case replace_push will add a new | |
3770 * character at the end of the stack. If replace_offset is not 0, that many | |
3771 * characters will be left on the stack above the newly inserted character. | |
3772 */ | |
3773 | |
298 | 3774 static char_u *replace_stack = NULL; |
3775 static long replace_stack_nr = 0; /* next entry in replace stack */ | |
3776 static long replace_stack_len = 0; /* max. number of entries */ | |
7 | 3777 |
3778 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3779 replace_push( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3780 int c) /* character that is replaced (NUL is none) */ |
7 | 3781 { |
3782 char_u *p; | |
3783 | |
3784 if (replace_stack_nr < replace_offset) /* nothing to do */ | |
3785 return; | |
3786 if (replace_stack_len <= replace_stack_nr) | |
3787 { | |
3788 replace_stack_len += 50; | |
16904
9138e2c60bf1
patch 8.1.1453: popup window "moved" property not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3789 p = ALLOC_MULT(char_u, replace_stack_len); |
7 | 3790 if (p == NULL) /* out of memory */ |
3791 { | |
3792 replace_stack_len -= 50; | |
3793 return; | |
3794 } | |
3795 if (replace_stack != NULL) | |
3796 { | |
3797 mch_memmove(p, replace_stack, | |
3798 (size_t)(replace_stack_nr * sizeof(char_u))); | |
3799 vim_free(replace_stack); | |
3800 } | |
3801 replace_stack = p; | |
3802 } | |
3803 p = replace_stack + replace_stack_nr - replace_offset; | |
3804 if (replace_offset) | |
3805 mch_memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u))); | |
3806 *p = c; | |
3807 ++replace_stack_nr; | |
3808 } | |
3809 | |
1470 | 3810 /* |
3811 * Push a character onto the replace stack. Handles a multi-byte character in | |
3812 * reverse byte order, so that the first byte is popped off first. | |
3813 * Return the number of bytes done (includes composing characters). | |
3814 */ | |
3815 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3816 replace_push_mb(char_u *p) |
1470 | 3817 { |
3818 int l = (*mb_ptr2len)(p); | |
3819 int j; | |
3820 | |
3821 for (j = l - 1; j >= 0; --j) | |
3822 replace_push(p[j]); | |
3823 return l; | |
3824 } | |
3825 | |
7 | 3826 /* |
3827 * Pop one item from the replace stack. | |
3828 * return -1 if stack empty | |
3829 * return replaced character or NUL otherwise | |
3830 */ | |
3831 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3832 replace_pop(void) |
7 | 3833 { |
3834 if (replace_stack_nr == 0) | |
3835 return -1; | |
3836 return (int)replace_stack[--replace_stack_nr]; | |
3837 } | |
3838 | |
3839 /* | |
3840 * Join the top two items on the replace stack. This removes to "off"'th NUL | |
3841 * encountered. | |
3842 */ | |
3843 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3844 replace_join( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3845 int off) /* offset for which NUL to remove */ |
7 | 3846 { |
3847 int i; | |
3848 | |
3849 for (i = replace_stack_nr; --i >= 0; ) | |
3850 if (replace_stack[i] == NUL && off-- <= 0) | |
3851 { | |
3852 --replace_stack_nr; | |
3853 mch_memmove(replace_stack + i, replace_stack + i + 1, | |
3854 (size_t)(replace_stack_nr - i)); | |
3855 return; | |
3856 } | |
3857 } | |
3858 | |
3859 /* | |
3860 * Pop bytes from the replace stack until a NUL is found, and insert them | |
3861 * before the cursor. Can only be used in REPLACE or VREPLACE mode. | |
3862 */ | |
3863 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3864 replace_pop_ins(void) |
7 | 3865 { |
3866 int cc; | |
3867 int oldState = State; | |
3868 | |
3869 State = NORMAL; /* don't want REPLACE here */ | |
3870 while ((cc = replace_pop()) > 0) | |
3871 { | |
3872 mb_replace_pop_ins(cc); | |
3873 dec_cursor(); | |
3874 } | |
3875 State = oldState; | |
3876 } | |
3877 | |
3878 /* | |
3879 * Insert bytes popped from the replace stack. "cc" is the first byte. If it | |
3880 * indicates a multi-byte char, pop the other bytes too. | |
3881 */ | |
3882 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3883 mb_replace_pop_ins(int cc) |
7 | 3884 { |
3885 int n; | |
3549 | 3886 char_u buf[MB_MAXBYTES + 1]; |
7 | 3887 int i; |
3888 int c; | |
3889 | |
3890 if (has_mbyte && (n = MB_BYTE2LEN(cc)) > 1) | |
3891 { | |
3892 buf[0] = cc; | |
3893 for (i = 1; i < n; ++i) | |
3894 buf[i] = replace_pop(); | |
3895 ins_bytes_len(buf, n); | |
3896 } | |
3897 else | |
3898 ins_char(cc); | |
3899 | |
3900 if (enc_utf8) | |
3901 /* Handle composing chars. */ | |
3902 for (;;) | |
3903 { | |
3904 c = replace_pop(); | |
3905 if (c == -1) /* stack empty */ | |
3906 break; | |
3907 if ((n = MB_BYTE2LEN(c)) == 1) | |
3908 { | |
3909 /* Not a multi-byte char, put it back. */ | |
3910 replace_push(c); | |
3911 break; | |
3912 } | |
3913 else | |
3914 { | |
3915 buf[0] = c; | |
3916 for (i = 1; i < n; ++i) | |
3917 buf[i] = replace_pop(); | |
3918 if (utf_iscomposing(utf_ptr2char(buf))) | |
3919 ins_bytes_len(buf, n); | |
3920 else | |
3921 { | |
3922 /* Not a composing char, put it back. */ | |
3923 for (i = n - 1; i >= 0; --i) | |
3924 replace_push(buf[i]); | |
3925 break; | |
3926 } | |
3927 } | |
3928 } | |
3929 } | |
3930 | |
3931 /* | |
3932 * make the replace stack empty | |
3933 * (called when exiting replace mode) | |
3934 */ | |
3935 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3936 replace_flush(void) |
7 | 3937 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13240
diff
changeset
|
3938 VIM_CLEAR(replace_stack); |
7 | 3939 replace_stack_len = 0; |
3940 replace_stack_nr = 0; | |
3941 } | |
3942 | |
3943 /* | |
3944 * Handle doing a BS for one character. | |
3945 * cc < 0: replace stack empty, just move cursor | |
3946 * cc == 0: character was inserted, delete it | |
3947 * cc > 0: character was replaced, put cc (first byte of original char) back | |
3948 * and check for more characters to be put back | |
1782 | 3949 * When "limit_col" is >= 0, don't delete before this column. Matters when |
3950 * using composing characters, use del_char_after_col() instead of del_char(). | |
7 | 3951 */ |
3952 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3953 replace_do_bs(int limit_col) |
7 | 3954 { |
3955 int cc; | |
3956 int orig_len = 0; | |
3957 int ins_len; | |
3958 int orig_vcols = 0; | |
3959 colnr_T start_vcol; | |
3960 char_u *p; | |
3961 int i; | |
3962 int vcol; | |
3963 | |
3964 cc = replace_pop(); | |
3965 if (cc > 0) | |
3966 { | |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3967 #ifdef FEAT_TEXT_PROP |
15382
87a0e3c3734c
patch 8.1.0699: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
15377
diff
changeset
|
3968 size_t len_before = 0; // init to shut up GCC |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3969 |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3970 if (curbuf->b_has_textprop) |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3971 { |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3972 // Do not adjust text properties for individual delete and insert |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3973 // operations, do it afterwards on the resulting text. |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3974 len_before = STRLEN(ml_get_curline()); |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3975 ++text_prop_frozen; |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3976 } |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
3977 #endif |
7 | 3978 if (State & VREPLACE_FLAG) |
3979 { | |
3980 /* Get the number of screen cells used by the character we are | |
3981 * going to delete. */ | |
3982 getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL); | |
3983 orig_vcols = chartabsize(ml_get_cursor(), start_vcol); | |
3984 } | |
3985 if (has_mbyte) | |
3986 { | |
1782 | 3987 (void)del_char_after_col(limit_col); |
7 | 3988 if (State & VREPLACE_FLAG) |
835 | 3989 orig_len = (int)STRLEN(ml_get_cursor()); |
7 | 3990 replace_push(cc); |
3991 } | |
3992 else | |
3993 { | |
3994 pchar_cursor(cc); | |
3995 if (State & VREPLACE_FLAG) | |
835 | 3996 orig_len = (int)STRLEN(ml_get_cursor()) - 1; |
7 | 3997 } |
3998 replace_pop_ins(); | |
3999 | |
4000 if (State & VREPLACE_FLAG) | |
4001 { | |
4002 /* Get the number of screen cells used by the inserted characters */ | |
4003 p = ml_get_cursor(); | |
835 | 4004 ins_len = (int)STRLEN(p) - orig_len; |
7 | 4005 vcol = start_vcol; |
4006 for (i = 0; i < ins_len; ++i) | |
4007 { | |
4008 vcol += chartabsize(p + i, vcol); | |
474 | 4009 i += (*mb_ptr2len)(p) - 1; |
7 | 4010 } |
4011 vcol -= start_vcol; | |
4012 | |
4013 /* Delete spaces that were inserted after the cursor to keep the | |
4014 * text aligned. */ | |
4015 curwin->w_cursor.col += ins_len; | |
4016 while (vcol > orig_vcols && gchar_cursor() == ' ') | |
4017 { | |
4018 del_char(FALSE); | |
4019 ++orig_vcols; | |
4020 } | |
4021 curwin->w_cursor.col -= ins_len; | |
4022 } | |
4023 | |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4024 // mark the buffer as changed and prepare for displaying |
7 | 4025 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4026 |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4027 #ifdef FEAT_TEXT_PROP |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4028 if (curbuf->b_has_textprop) |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4029 { |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4030 size_t len_now = STRLEN(ml_get_curline()); |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4031 |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4032 --text_prop_frozen; |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4033 adjust_prop_columns(curwin->w_cursor.lnum, curwin->w_cursor.col, |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
4034 (int)(len_now - len_before), 0); |
15349
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4035 } |
6abee072b93c
patch 8.1.0682: text properties not adjusted when backspacing replaced text
Bram Moolenaar <Bram@vim.org>
parents:
15347
diff
changeset
|
4036 #endif |
7 | 4037 } |
4038 else if (cc == 0) | |
1782 | 4039 (void)del_char_after_col(limit_col); |
7 | 4040 } |
4041 | |
4042 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) | |
4043 /* | |
4044 * Map Hebrew keyboard when in hkmap mode. | |
4045 */ | |
4046 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4047 hkmap(int c) |
7 | 4048 { |
4049 if (p_hkmapp) /* phonetic mapping, by Ilya Dogolazky */ | |
4050 { | |
4051 enum {hALEF=0, BET, GIMEL, DALET, HEI, VAV, ZAIN, HET, TET, IUD, | |
4052 KAFsofit, hKAF, LAMED, MEMsofit, MEM, NUNsofit, NUN, SAMEH, AIN, | |
4053 PEIsofit, PEI, ZADIsofit, ZADI, KOF, RESH, hSHIN, TAV}; | |
4054 static char_u map[26] = | |
4055 {(char_u)hALEF/*a*/, (char_u)BET /*b*/, (char_u)hKAF /*c*/, | |
4056 (char_u)DALET/*d*/, (char_u)-1 /*e*/, (char_u)PEIsofit/*f*/, | |
4057 (char_u)GIMEL/*g*/, (char_u)HEI /*h*/, (char_u)IUD /*i*/, | |
4058 (char_u)HET /*j*/, (char_u)KOF /*k*/, (char_u)LAMED /*l*/, | |
4059 (char_u)MEM /*m*/, (char_u)NUN /*n*/, (char_u)SAMEH /*o*/, | |
4060 (char_u)PEI /*p*/, (char_u)-1 /*q*/, (char_u)RESH /*r*/, | |
4061 (char_u)ZAIN /*s*/, (char_u)TAV /*t*/, (char_u)TET /*u*/, | |
4062 (char_u)VAV /*v*/, (char_u)hSHIN/*w*/, (char_u)-1 /*x*/, | |
4063 (char_u)AIN /*y*/, (char_u)ZADI /*z*/}; | |
4064 | |
4065 if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z') | |
4066 return (int)(map[CharOrd(c)] - 1 + p_aleph); | |
4067 /* '-1'='sofit' */ | |
4068 else if (c == 'x') | |
4069 return 'X'; | |
4070 else if (c == 'q') | |
4071 return '\''; /* {geresh}={'} */ | |
4072 else if (c == 246) | |
4073 return ' '; /* \"o --> ' ' for a german keyboard */ | |
4074 else if (c == 228) | |
4075 return ' '; /* \"a --> ' ' -- / -- */ | |
4076 else if (c == 252) | |
4077 return ' '; /* \"u --> ' ' -- / -- */ | |
4078 #ifdef EBCDIC | |
4079 else if (islower(c)) | |
4080 #else | |
4081 /* NOTE: islower() does not do the right thing for us on Linux so we | |
4082 * do this the same was as 5.7 and previous, so it works correctly on | |
4083 * all systems. Specifically, the e.g. Delete and Arrow keys are | |
4084 * munged and won't work if e.g. searching for Hebrew text. | |
4085 */ | |
4086 else if (c >= 'a' && c <= 'z') | |
4087 #endif | |
4088 return (int)(map[CharOrdLow(c)] + p_aleph); | |
4089 else | |
4090 return c; | |
4091 } | |
4092 else | |
4093 { | |
4094 switch (c) | |
4095 { | |
4096 case '`': return ';'; | |
4097 case '/': return '.'; | |
4098 case '\'': return ','; | |
4099 case 'q': return '/'; | |
4100 case 'w': return '\''; | |
4101 | |
4102 /* Hebrew letters - set offset from 'a' */ | |
4103 case ',': c = '{'; break; | |
4104 case '.': c = 'v'; break; | |
4105 case ';': c = 't'; break; | |
4106 default: { | |
4107 static char str[] = "zqbcxlsjphmkwonu ydafe rig"; | |
4108 | |
4109 #ifdef EBCDIC | |
4110 /* see note about islower() above */ | |
4111 if (!islower(c)) | |
4112 #else | |
4113 if (c < 'a' || c > 'z') | |
4114 #endif | |
4115 return c; | |
4116 c = str[CharOrdLow(c)]; | |
4117 break; | |
4118 } | |
4119 } | |
4120 | |
4121 return (int)(CharOrdLow(c) + p_aleph); | |
4122 } | |
4123 } | |
4124 #endif | |
4125 | |
4126 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4127 ins_reg(void) |
7 | 4128 { |
4129 int need_redraw = FALSE; | |
4130 int regname; | |
4131 int literally = 0; | |
844 | 4132 int vis_active = VIsual_active; |
7 | 4133 |
4134 /* | |
4135 * If we are going to wait for a character, show a '"'. | |
4136 */ | |
4137 pc_status = PC_STATUS_UNSET; | |
4138 if (redrawing() && !char_avail()) | |
4139 { | |
4140 /* may need to redraw when no more chars available now */ | |
661 | 4141 ins_redraw(FALSE); |
7 | 4142 |
4143 edit_putchar('"', TRUE); | |
4144 #ifdef FEAT_CMDL_INFO | |
4145 add_to_showcmd_c(Ctrl_R); | |
4146 #endif | |
4147 } | |
4148 | |
4149 #ifdef USE_ON_FLY_SCROLL | |
4150 dont_scroll = TRUE; /* disallow scrolling here */ | |
4151 #endif | |
4152 | |
4153 /* | |
4154 * Don't map the register name. This also prevents the mode message to be | |
4155 * deleted when ESC is hit. | |
4156 */ | |
4157 ++no_mapping; | |
1389 | 4158 regname = plain_vgetc(); |
7 | 4159 LANGMAP_ADJUST(regname, TRUE); |
4160 if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P) | |
4161 { | |
4162 /* Get a third key for literal register insertion */ | |
4163 literally = regname; | |
4164 #ifdef FEAT_CMDL_INFO | |
4165 add_to_showcmd_c(literally); | |
4166 #endif | |
1389 | 4167 regname = plain_vgetc(); |
7 | 4168 LANGMAP_ADJUST(regname, TRUE); |
4169 } | |
4170 --no_mapping; | |
4171 | |
4172 #ifdef FEAT_EVAL | |
4909
2945fe016b93
updated for version 7.3.1200
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4173 /* Don't call u_sync() while typing the expression or giving an error |
2945fe016b93
updated for version 7.3.1200
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
4174 * message for it. Only call it explicitly. */ |
7 | 4175 ++no_u_sync; |
4176 if (regname == '=') | |
4177 { | |
15569
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4178 pos_T curpos = curwin->w_cursor; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4179 # ifdef HAVE_INPUT_METHOD |
7 | 4180 int im_on = im_get_status(); |
133 | 4181 # endif |
5120
6e611380b4cf
updated for version 7.3.1303
Bram Moolenaar <bram@vim.org>
parents:
5094
diff
changeset
|
4182 /* Sync undo when evaluating the expression calls setline() or |
6e611380b4cf
updated for version 7.3.1303
Bram Moolenaar <bram@vim.org>
parents:
5094
diff
changeset
|
4183 * append(), so that it can be undone separately. */ |
6e611380b4cf
updated for version 7.3.1303
Bram Moolenaar <bram@vim.org>
parents:
5094
diff
changeset
|
4184 u_sync_once = 2; |
5018
d6a7dea44a86
updated for version 7.3.1253
Bram Moolenaar <bram@vim.org>
parents:
4909
diff
changeset
|
4185 |
7 | 4186 regname = get_expr_register(); |
15569
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4187 |
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4188 // Cursor may be moved back a column. |
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4189 curwin->w_cursor = curpos; |
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4190 check_cursor(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4191 # ifdef HAVE_INPUT_METHOD |
15569
43fa814a7977
patch 8.1.0792: bad display if opening cmdline window from Insert completion
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
4192 // Restore the Input Method. |
7 | 4193 if (im_on) |
4194 im_set_active(TRUE); | |
133 | 4195 # endif |
7 | 4196 } |
140 | 4197 if (regname == NUL || !valid_yank_reg(regname, FALSE)) |
4198 { | |
6949 | 4199 vim_beep(BO_REG); |
7 | 4200 need_redraw = TRUE; /* remove the '"' */ |
140 | 4201 } |
7 | 4202 else |
4203 { | |
4204 #endif | |
4205 if (literally == Ctrl_O || literally == Ctrl_P) | |
4206 { | |
4207 /* Append the command to the redo buffer. */ | |
4208 AppendCharToRedobuff(Ctrl_R); | |
4209 AppendCharToRedobuff(literally); | |
4210 AppendCharToRedobuff(regname); | |
4211 | |
4212 do_put(regname, BACKWARD, 1L, | |
4213 (literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND); | |
4214 } | |
4215 else if (insert_reg(regname, literally) == FAIL) | |
4216 { | |
6949 | 4217 vim_beep(BO_REG); |
7 | 4218 need_redraw = TRUE; /* remove the '"' */ |
4219 } | |
133 | 4220 else if (stop_insert_mode) |
4221 /* When the '=' register was used and a function was invoked that | |
4222 * did ":stopinsert" then stuff_empty() returns FALSE but we won't | |
4223 * insert anything, need to remove the '"' */ | |
4224 need_redraw = TRUE; | |
4225 | |
7 | 4226 #ifdef FEAT_EVAL |
4227 } | |
4228 --no_u_sync; | |
5120
6e611380b4cf
updated for version 7.3.1303
Bram Moolenaar <bram@vim.org>
parents:
5094
diff
changeset
|
4229 if (u_sync_once == 1) |
6e611380b4cf
updated for version 7.3.1303
Bram Moolenaar <bram@vim.org>
parents:
5094
diff
changeset
|
4230 ins_need_undo = TRUE; |
6e611380b4cf
updated for version 7.3.1303
Bram Moolenaar <bram@vim.org>
parents:
5094
diff
changeset
|
4231 u_sync_once = 0; |
7 | 4232 #endif |
4233 #ifdef FEAT_CMDL_INFO | |
4234 clear_showcmd(); | |
4235 #endif | |
4236 | |
4237 /* If the inserted register is empty, we need to remove the '"' */ | |
4238 if (need_redraw || stuff_empty()) | |
4239 edit_unputchar(); | |
844 | 4240 |
4241 /* Disallow starting Visual mode here, would get a weird mode. */ | |
4242 if (!vis_active && VIsual_active) | |
4243 end_visual_mode(); | |
7 | 4244 } |
4245 | |
4246 /* | |
4247 * CTRL-G commands in Insert mode. | |
4248 */ | |
4249 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4250 ins_ctrl_g(void) |
7 | 4251 { |
4252 int c; | |
4253 | |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
4254 // Right after CTRL-X the cursor will be after the ruler. |
7 | 4255 setcursor(); |
4256 | |
4257 /* | |
4258 * Don't map the second key. This also prevents the mode message to be | |
4259 * deleted when ESC is hit. | |
4260 */ | |
4261 ++no_mapping; | |
1389 | 4262 c = plain_vgetc(); |
7 | 4263 --no_mapping; |
4264 switch (c) | |
4265 { | |
4266 /* CTRL-G k and CTRL-G <Up>: cursor up to Insstart.col */ | |
4267 case K_UP: | |
4268 case Ctrl_K: | |
4269 case 'k': ins_up(TRUE); | |
4270 break; | |
4271 | |
4272 /* CTRL-G j and CTRL-G <Down>: cursor down to Insstart.col */ | |
4273 case K_DOWN: | |
4274 case Ctrl_J: | |
4275 case 'j': ins_down(TRUE); | |
4276 break; | |
4277 | |
4278 /* CTRL-G u: start new undoable edit */ | |
825 | 4279 case 'u': u_sync(TRUE); |
7 | 4280 ins_need_undo = TRUE; |
626 | 4281 |
4282 /* Need to reset Insstart, esp. because a BS that joins | |
1219 | 4283 * a line to the previous one must save for undo. */ |
5680 | 4284 update_Insstart_orig = FALSE; |
626 | 4285 Insstart = curwin->w_cursor; |
7 | 4286 break; |
4287 | |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
4288 /* CTRL-G U: do not break undo with the next char */ |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
4289 case 'U': |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
4290 /* Allow one left/right cursor movement with the next char, |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
4291 * without breaking undo. */ |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
4292 dont_sync_undo = MAYBE; |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
4293 break; |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
4294 |
7 | 4295 /* Unknown CTRL-G command, reserved for future expansion. */ |
6949 | 4296 default: vim_beep(BO_CTRLG); |
7 | 4297 } |
4298 } | |
4299 | |
4300 /* | |
449 | 4301 * CTRL-^ in Insert mode. |
4302 */ | |
4303 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4304 ins_ctrl_hat(void) |
449 | 4305 { |
782 | 4306 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) |
449 | 4307 { |
4308 /* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */ | |
4309 if (State & LANGMAP) | |
4310 { | |
4311 curbuf->b_p_iminsert = B_IMODE_NONE; | |
4312 State &= ~LANGMAP; | |
4313 } | |
4314 else | |
4315 { | |
4316 curbuf->b_p_iminsert = B_IMODE_LMAP; | |
4317 State |= LANGMAP; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4318 #ifdef HAVE_INPUT_METHOD |
449 | 4319 im_set_active(FALSE); |
4320 #endif | |
4321 } | |
4322 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4323 #ifdef HAVE_INPUT_METHOD |
449 | 4324 else |
4325 { | |
4326 /* There are no ":lmap" mappings, toggle IM */ | |
4327 if (im_get_status()) | |
4328 { | |
4329 curbuf->b_p_iminsert = B_IMODE_NONE; | |
4330 im_set_active(FALSE); | |
4331 } | |
4332 else | |
4333 { | |
4334 curbuf->b_p_iminsert = B_IMODE_IM; | |
4335 State &= ~LANGMAP; | |
4336 im_set_active(TRUE); | |
4337 } | |
4338 } | |
4339 #endif | |
4340 set_iminsert_global(); | |
4341 showmode(); | |
4342 #ifdef FEAT_GUI | |
4343 /* may show different cursor shape or color */ | |
4344 if (gui.in_use) | |
4345 gui_update_cursor(TRUE, FALSE); | |
4346 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
4347 #if defined(FEAT_KEYMAP) |
449 | 4348 /* Show/unshow value of 'keymap' in status lines. */ |
4349 status_redraw_curbuf(); | |
4350 #endif | |
4351 } | |
4352 | |
4353 /* | |
7 | 4354 * Handle ESC in insert mode. |
4355 * Returns TRUE when leaving insert mode, FALSE when going to repeat the | |
4356 * insert. | |
4357 */ | |
4358 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4359 ins_esc( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4360 long *count, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4361 int cmdchar, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4362 int nomove) /* don't move cursor */ |
7 | 4363 { |
4364 int temp; | |
4365 static int disabled_redraw = FALSE; | |
4366 | |
744 | 4367 #ifdef FEAT_SPELL |
449 | 4368 check_spell_redraw(); |
4369 #endif | |
7 | 4370 #if defined(FEAT_HANGULIN) |
4371 # if defined(ESC_CHG_TO_ENG_MODE) | |
4372 hangul_input_state_set(0); | |
4373 # endif | |
4374 if (composing_hangul) | |
4375 { | |
4376 push_raw_key(composing_hangul_buffer, 2); | |
4377 composing_hangul = 0; | |
4378 } | |
4379 #endif | |
4380 | |
4381 temp = curwin->w_cursor.col; | |
4382 if (disabled_redraw) | |
4383 { | |
4384 --RedrawingDisabled; | |
4385 disabled_redraw = FALSE; | |
4386 } | |
4387 if (!arrow_used) | |
4388 { | |
4389 /* | |
4390 * Don't append the ESC for "r<CR>" and "grx". | |
75 | 4391 * When 'insertmode' is set only CTRL-L stops Insert mode. Needed for |
4392 * when "count" is non-zero. | |
7 | 4393 */ |
4394 if (cmdchar != 'r' && cmdchar != 'v') | |
75 | 4395 AppendToRedobuff(p_im ? (char_u *)"\014" : ESC_STR); |
7 | 4396 |
4397 /* | |
4398 * Repeating insert may take a long time. Check for | |
4399 * interrupt now and then. | |
4400 */ | |
4401 if (*count > 0) | |
4402 { | |
4403 line_breakcheck(); | |
4404 if (got_int) | |
4405 *count = 0; | |
4406 } | |
4407 | |
4408 if (--*count > 0) /* repeat what was typed */ | |
4409 { | |
164 | 4410 /* Vi repeats the insert without replacing characters. */ |
4411 if (vim_strchr(p_cpo, CPO_REPLCNT) != NULL) | |
4412 State &= ~REPLACE_FLAG; | |
4413 | |
7 | 4414 (void)start_redo_ins(); |
4415 if (cmdchar == 'r' || cmdchar == 'v') | |
6098 | 4416 stuffRedoReadbuff(ESC_STR); /* no ESC in redo buffer */ |
7 | 4417 ++RedrawingDisabled; |
4418 disabled_redraw = TRUE; | |
4419 return FALSE; /* repeat the insert */ | |
4420 } | |
5434 | 4421 stop_insert(&curwin->w_cursor, TRUE, nomove); |
7 | 4422 undisplay_dollar(); |
4423 } | |
4424 | |
4425 /* When an autoindent was removed, curswant stays after the | |
4426 * indent */ | |
4427 if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col) | |
4428 curwin->w_set_curswant = TRUE; | |
4429 | |
4430 /* Remember the last Insert position in the '^ mark. */ | |
4431 if (!cmdmod.keepjumps) | |
4432 curbuf->b_last_insert = curwin->w_cursor; | |
4433 | |
4434 /* | |
4435 * The cursor should end up on the last inserted character. | |
477 | 4436 * Don't do it for CTRL-O, unless past the end of the line. |
7 | 4437 */ |
477 | 4438 if (!nomove |
4439 && (curwin->w_cursor.col != 0 | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
4440 || curwin->w_cursor.coladd > 0) |
477 | 4441 && (restart_edit == NUL |
5735 | 4442 || (gchar_cursor() == NUL && !VIsual_active)) |
7 | 4443 #ifdef FEAT_RIGHTLEFT |
4444 && !revins_on | |
4445 #endif | |
4446 ) | |
4447 { | |
4448 if (curwin->w_cursor.coladd > 0 || ve_flags == VE_ALL) | |
4449 { | |
4450 oneleft(); | |
4451 if (restart_edit != NUL) | |
4452 ++curwin->w_cursor.coladd; | |
4453 } | |
4454 else | |
4455 { | |
4456 --curwin->w_cursor.col; | |
4457 /* Correct cursor for multi-byte character. */ | |
4458 if (has_mbyte) | |
4459 mb_adjust_cursor(); | |
4460 } | |
4461 } | |
4462 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
4463 #ifdef HAVE_INPUT_METHOD |
7 | 4464 /* Disable IM to allow typing English directly for Normal mode commands. |
4465 * When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as | |
4466 * well). */ | |
4467 if (!(State & LANGMAP)) | |
4468 im_save_status(&curbuf->b_p_iminsert); | |
4469 im_set_active(FALSE); | |
4470 #endif | |
4471 | |
4472 State = NORMAL; | |
4473 /* need to position cursor again (e.g. when on a TAB ) */ | |
4474 changed_cline_bef_curs(); | |
4475 | |
4476 setmouse(); | |
4477 #ifdef CURSOR_SHAPE | |
4478 ui_cursor_shape(); /* may show different cursor shape */ | |
4479 #endif | |
10684
83a36d655a74
patch 8.0.0232: paste does not work when 'esckeys' is off
Christian Brabandt <cb@256bit.org>
parents:
10682
diff
changeset
|
4480 if (!p_ek) |
83a36d655a74
patch 8.0.0232: paste does not work when 'esckeys' is off
Christian Brabandt <cb@256bit.org>
parents:
10682
diff
changeset
|
4481 /* Re-enable bracketed paste mode. */ |
83a36d655a74
patch 8.0.0232: paste does not work when 'esckeys' is off
Christian Brabandt <cb@256bit.org>
parents:
10682
diff
changeset
|
4482 out_str(T_BE); |
7 | 4483 |
16378
3d6b282e2d6e
patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents:
16368
diff
changeset
|
4484 // When recording or for CTRL-O, need to display the new mode. |
3d6b282e2d6e
patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents:
16368
diff
changeset
|
4485 // Otherwise remove the mode message. |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
4486 if (reg_recording != 0 || restart_edit != NUL) |
7 | 4487 showmode(); |
16368
a3b5cbd2effe
patch 8.1.1189: mode is not cleared when leaving Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4488 else if (p_smd && (got_int || !skip_showmode())) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15521
diff
changeset
|
4489 msg(""); |
7 | 4490 |
4491 return TRUE; /* exit Insert mode */ | |
4492 } | |
4493 | |
4494 #ifdef FEAT_RIGHTLEFT | |
4495 /* | |
4496 * Toggle language: hkmap and revins_on. | |
4497 * Move to end of reverse inserted text. | |
4498 */ | |
4499 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4500 ins_ctrl_(void) |
7 | 4501 { |
4502 if (revins_on && revins_chars && revins_scol >= 0) | |
4503 { | |
4504 while (gchar_cursor() != NUL && revins_chars--) | |
4505 ++curwin->w_cursor.col; | |
4506 } | |
4507 p_ri = !p_ri; | |
4508 revins_on = (State == INSERT && p_ri); | |
4509 if (revins_on) | |
4510 { | |
4511 revins_scol = curwin->w_cursor.col; | |
4512 revins_legal++; | |
4513 revins_chars = 0; | |
4514 undisplay_dollar(); | |
4515 } | |
4516 else | |
4517 revins_scol = -1; | |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15738
diff
changeset
|
4518 p_hkmap = curwin->w_p_rl ^ p_ri; // be consistent! |
7 | 4519 showmode(); |
4520 } | |
4521 #endif | |
4522 | |
4523 /* | |
4524 * If 'keymodel' contains "startsel", may start selection. | |
4525 * Returns TRUE when a CTRL-O and other keys stuffed. | |
4526 */ | |
4527 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4528 ins_start_select(int c) |
7 | 4529 { |
4530 if (km_startsel) | |
4531 switch (c) | |
4532 { | |
4533 case K_KHOME: | |
4534 case K_KEND: | |
4535 case K_PAGEUP: | |
4536 case K_KPAGEUP: | |
4537 case K_PAGEDOWN: | |
4538 case K_KPAGEDOWN: | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4539 # ifdef MACOS_X |
7 | 4540 case K_LEFT: |
4541 case K_RIGHT: | |
4542 case K_UP: | |
4543 case K_DOWN: | |
4544 case K_END: | |
4545 case K_HOME: | |
4546 # endif | |
4547 if (!(mod_mask & MOD_MASK_SHIFT)) | |
4548 break; | |
4549 /* FALLTHROUGH */ | |
4550 case K_S_LEFT: | |
4551 case K_S_RIGHT: | |
4552 case K_S_UP: | |
4553 case K_S_DOWN: | |
4554 case K_S_END: | |
4555 case K_S_HOME: | |
4556 /* Start selection right away, the cursor can move with | |
4557 * CTRL-O when beyond the end of the line. */ | |
4558 start_selection(); | |
4559 | |
4560 /* Execute the key in (insert) Select mode. */ | |
4561 stuffcharReadbuff(Ctrl_O); | |
4562 if (mod_mask) | |
4563 { | |
4564 char_u buf[4]; | |
4565 | |
4566 buf[0] = K_SPECIAL; | |
4567 buf[1] = KS_MODIFIER; | |
4568 buf[2] = mod_mask; | |
4569 buf[3] = NUL; | |
4570 stuffReadbuff(buf); | |
4571 } | |
4572 stuffcharReadbuff(c); | |
4573 return TRUE; | |
4574 } | |
4575 return FALSE; | |
4576 } | |
4577 | |
4578 /* | |
4352 | 4579 * <Insert> key in Insert mode: toggle insert/replace mode. |
449 | 4580 */ |
4581 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4582 ins_insert(int replaceState) |
449 | 4583 { |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15738
diff
changeset
|
4584 #ifdef FEAT_EVAL |
449 | 4585 set_vim_var_string(VV_INSERTMODE, |
14424
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14419
diff
changeset
|
4586 (char_u *)((State & REPLACE_FLAG) ? "i" |
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14419
diff
changeset
|
4587 : replaceState == VREPLACE ? "v" |
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14419
diff
changeset
|
4588 : "r"), 1); |
15850
a6ca8cf07a98
patch 8.1.0932: Farsi support is outdated and unused
Bram Moolenaar <Bram@vim.org>
parents:
15738
diff
changeset
|
4589 #endif |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
4590 ins_apply_autocmds(EVENT_INSERTCHANGE); |
449 | 4591 if (State & REPLACE_FLAG) |
4592 State = INSERT | (State & LANGMAP); | |
4593 else | |
4594 State = replaceState | (State & LANGMAP); | |
4595 AppendCharToRedobuff(K_INS); | |
4596 showmode(); | |
4597 #ifdef CURSOR_SHAPE | |
4598 ui_cursor_shape(); /* may show different cursor shape */ | |
4599 #endif | |
4600 } | |
4601 | |
4602 /* | |
4603 * Pressed CTRL-O in Insert mode. | |
4604 */ | |
4605 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4606 ins_ctrl_o(void) |
449 | 4607 { |
4608 if (State & VREPLACE_FLAG) | |
4609 restart_edit = 'V'; | |
4610 else | |
4611 if (State & REPLACE_FLAG) | |
4612 restart_edit = 'R'; | |
4613 else | |
4614 restart_edit = 'I'; | |
4615 if (virtual_active()) | |
4616 ins_at_eol = FALSE; /* cursor always keeps its column */ | |
4617 else | |
4618 ins_at_eol = (gchar_cursor() == NUL); | |
4619 } | |
4620 | |
4621 /* | |
7 | 4622 * If the cursor is on an indent, ^T/^D insert/delete one |
4623 * shiftwidth. Otherwise ^T/^D behave like a "<<" or ">>". | |
1796 | 4624 * Always round the indent to 'shiftwidth', this is compatible |
7 | 4625 * with vi. But vi only supports ^T and ^D after an |
4626 * autoindent, we support it everywhere. | |
4627 */ | |
4628 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4629 ins_shift(int c, int lastc) |
7 | 4630 { |
4631 if (stop_arrow() == FAIL) | |
4632 return; | |
4633 AppendCharToRedobuff(c); | |
4634 | |
4635 /* | |
4636 * 0^D and ^^D: remove all indent. | |
4637 */ | |
1330 | 4638 if (c == Ctrl_D && (lastc == '0' || lastc == '^') |
4639 && curwin->w_cursor.col > 0) | |
7 | 4640 { |
4641 --curwin->w_cursor.col; | |
4642 (void)del_char(FALSE); /* delete the '^' or '0' */ | |
4643 /* In Replace mode, restore the characters that '^' or '0' replaced. */ | |
4644 if (State & REPLACE_FLAG) | |
4645 replace_pop_ins(); | |
4646 if (lastc == '^') | |
4647 old_indent = get_indent(); /* remember curr. indent */ | |
1516 | 4648 change_indent(INDENT_SET, 0, TRUE, 0, TRUE); |
7 | 4649 } |
4650 else | |
1516 | 4651 change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0, TRUE); |
7 | 4652 |
4653 if (did_ai && *skipwhite(ml_get_curline()) != NUL) | |
4654 did_ai = FALSE; | |
4655 #ifdef FEAT_SMARTINDENT | |
4656 did_si = FALSE; | |
4657 can_si = FALSE; | |
4658 can_si_back = FALSE; | |
4659 #endif | |
4660 #ifdef FEAT_CINDENT | |
4661 can_cindent = FALSE; /* no cindenting after ^D or ^T */ | |
4662 #endif | |
4663 } | |
4664 | |
4665 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4666 ins_del(void) |
7 | 4667 { |
4668 int temp; | |
4669 | |
4670 if (stop_arrow() == FAIL) | |
4671 return; | |
4672 if (gchar_cursor() == NUL) /* delete newline */ | |
4673 { | |
4674 temp = curwin->w_cursor.col; | |
4675 if (!can_bs(BS_EOL) /* only if "eol" included */ | |
5848 | 4676 || do_join(2, FALSE, TRUE, FALSE, FALSE) == FAIL) |
6949 | 4677 vim_beep(BO_BS); |
7 | 4678 else |
13402
338b15c63e2c
patch 8.0.1575: crash when using virtual replace
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4679 { |
7 | 4680 curwin->w_cursor.col = temp; |
13402
338b15c63e2c
patch 8.0.1575: crash when using virtual replace
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4681 /* Adjust orig_line_count in case more lines have been deleted than |
338b15c63e2c
patch 8.0.1575: crash when using virtual replace
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4682 * have been added. That makes sure, that open_line() later |
338b15c63e2c
patch 8.0.1575: crash when using virtual replace
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4683 * can access all buffer lines correctly */ |
338b15c63e2c
patch 8.0.1575: crash when using virtual replace
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4684 if (State & VREPLACE_FLAG && |
338b15c63e2c
patch 8.0.1575: crash when using virtual replace
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4685 orig_line_count > curbuf->b_ml.ml_line_count) |
338b15c63e2c
patch 8.0.1575: crash when using virtual replace
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4686 orig_line_count = curbuf->b_ml.ml_line_count; |
338b15c63e2c
patch 8.0.1575: crash when using virtual replace
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4687 } |
7 | 4688 } |
6949 | 4689 else if (del_char(FALSE) == FAIL) /* delete char under cursor */ |
4690 vim_beep(BO_BS); | |
7 | 4691 did_ai = FALSE; |
4692 #ifdef FEAT_SMARTINDENT | |
4693 did_si = FALSE; | |
4694 can_si = FALSE; | |
4695 can_si_back = FALSE; | |
4696 #endif | |
4697 AppendCharToRedobuff(K_DEL); | |
4698 } | |
4699 | |
1460 | 4700 /* |
4701 * Delete one character for ins_bs(). | |
4702 */ | |
4703 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4704 ins_bs_one(colnr_T *vcolp) |
1460 | 4705 { |
4706 dec_cursor(); | |
4707 getvcol(curwin, &curwin->w_cursor, vcolp, NULL, NULL); | |
4708 if (State & REPLACE_FLAG) | |
4709 { | |
4710 /* Don't delete characters before the insert point when in | |
4711 * Replace mode */ | |
4712 if (curwin->w_cursor.lnum != Insstart.lnum | |
4713 || curwin->w_cursor.col >= Insstart.col) | |
1782 | 4714 replace_do_bs(-1); |
1460 | 4715 } |
4716 else | |
4717 (void)del_char(FALSE); | |
4718 } | |
4719 | |
7 | 4720 /* |
4721 * Handle Backspace, delete-word and delete-line in Insert mode. | |
4722 * Return TRUE when backspace was actually used. | |
4723 */ | |
4724 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4725 ins_bs( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4726 int c, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4727 int mode, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4728 int *inserted_space_p) |
7 | 4729 { |
4730 linenr_T lnum; | |
4731 int cc; | |
4732 int temp = 0; /* init for GCC */ | |
1872 | 4733 colnr_T save_col; |
7 | 4734 colnr_T mincol; |
4735 int did_backspace = FALSE; | |
4736 int in_indent; | |
4737 int oldState; | |
714 | 4738 int cpc[MAX_MCO]; /* composing characters */ |
7 | 4739 |
4740 /* | |
4741 * can't delete anything in an empty file | |
4742 * can't backup past first character in buffer | |
4743 * can't backup past starting point unless 'backspace' > 1 | |
4744 * can backup to a previous line if 'backspace' == 0 | |
4745 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11105
diff
changeset
|
4746 if ( BUFEMPTY() |
7 | 4747 || ( |
4748 #ifdef FEAT_RIGHTLEFT | |
4749 !revins_on && | |
4750 #endif | |
4751 ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0) | |
4752 || (!can_bs(BS_START) | |
4753 && (arrow_used | |
5852 | 4754 || (curwin->w_cursor.lnum == Insstart_orig.lnum |
4755 && curwin->w_cursor.col <= Insstart_orig.col))) | |
7 | 4756 || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0 |
4757 && curwin->w_cursor.col <= ai_col) | |
4758 || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0)))) | |
4759 { | |
6949 | 4760 vim_beep(BO_BS); |
7 | 4761 return FALSE; |
4762 } | |
4763 | |
4764 if (stop_arrow() == FAIL) | |
4765 return FALSE; | |
4766 in_indent = inindent(0); | |
4767 #ifdef FEAT_CINDENT | |
4768 if (in_indent) | |
4769 can_cindent = FALSE; | |
4770 #endif | |
4771 end_comment_pending = NUL; /* After BS, don't auto-end comment */ | |
4772 #ifdef FEAT_RIGHTLEFT | |
4773 if (revins_on) /* put cursor after last inserted char */ | |
4774 inc_cursor(); | |
4775 #endif | |
4776 | |
4777 /* Virtualedit: | |
4778 * BACKSPACE_CHAR eats a virtual space | |
4779 * BACKSPACE_WORD eats all coladd | |
4780 * BACKSPACE_LINE eats all coladd and keeps going | |
4781 */ | |
4782 if (curwin->w_cursor.coladd > 0) | |
4783 { | |
4784 if (mode == BACKSPACE_CHAR) | |
4785 { | |
4786 --curwin->w_cursor.coladd; | |
4787 return TRUE; | |
4788 } | |
4789 if (mode == BACKSPACE_WORD) | |
4790 { | |
4791 curwin->w_cursor.coladd = 0; | |
4792 return TRUE; | |
4793 } | |
4794 curwin->w_cursor.coladd = 0; | |
4795 } | |
4796 | |
4797 /* | |
11295
d772bf077b3f
patch 8.0.0533: abbreviation doesn't work after backspacing newline
Christian Brabandt <cb@256bit.org>
parents:
11289
diff
changeset
|
4798 * Delete newline! |
7 | 4799 */ |
4800 if (curwin->w_cursor.col == 0) | |
4801 { | |
6629 | 4802 lnum = Insstart.lnum; |
5852 | 4803 if (curwin->w_cursor.lnum == lnum |
7 | 4804 #ifdef FEAT_RIGHTLEFT |
4805 || revins_on | |
4806 #endif | |
4807 ) | |
4808 { | |
4809 if (u_save((linenr_T)(curwin->w_cursor.lnum - 2), | |
4810 (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL) | |
4811 return FALSE; | |
6629 | 4812 --Insstart.lnum; |
11311
be499043ca70
patch 8.0.0541: compiler warning on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
11295
diff
changeset
|
4813 Insstart.col = (colnr_T)STRLEN(ml_get(Insstart.lnum)); |
7 | 4814 } |
4815 /* | |
4816 * In replace mode: | |
4817 * cc < 0: NL was inserted, delete it | |
4818 * cc >= 0: NL was replaced, put original characters back | |
4819 */ | |
4820 cc = -1; | |
4821 if (State & REPLACE_FLAG) | |
4822 cc = replace_pop(); /* returns -1 if NL was inserted */ | |
4823 /* | |
4824 * In replace mode, in the line we started replacing, we only move the | |
4825 * cursor. | |
4826 */ | |
4827 if ((State & REPLACE_FLAG) && curwin->w_cursor.lnum <= lnum) | |
4828 { | |
4829 dec_cursor(); | |
4830 } | |
4831 else | |
4832 { | |
4833 if (!(State & VREPLACE_FLAG) | |
4834 || curwin->w_cursor.lnum > orig_line_count) | |
4835 { | |
4836 temp = gchar_cursor(); /* remember current char */ | |
4837 --curwin->w_cursor.lnum; | |
278 | 4838 |
4839 /* When "aw" is in 'formatoptions' we must delete the space at | |
4840 * the end of the line, otherwise the line will be broken | |
4841 * again when auto-formatting. */ | |
4842 if (has_format_option(FO_AUTO) | |
4843 && has_format_option(FO_WHITE_PAR)) | |
4844 { | |
4845 char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, | |
4846 TRUE); | |
4847 int len; | |
4848 | |
835 | 4849 len = (int)STRLEN(ptr); |
278 | 4850 if (len > 0 && ptr[len - 1] == ' ') |
4851 ptr[len - 1] = NUL; | |
4852 } | |
4853 | |
5848 | 4854 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); |
7 | 4855 if (temp == NUL && gchar_cursor() != NUL) |
4856 inc_cursor(); | |
4857 } | |
4858 else | |
4859 dec_cursor(); | |
4860 | |
4861 /* | |
4862 * In REPLACE mode we have to put back the text that was replaced | |
4863 * by the NL. On the replace stack is first a NUL-terminated | |
4864 * sequence of characters that were deleted and then the | |
4865 * characters that NL replaced. | |
4866 */ | |
4867 if (State & REPLACE_FLAG) | |
4868 { | |
4869 /* | |
4870 * Do the next ins_char() in NORMAL state, to | |
4871 * prevent ins_char() from replacing characters and | |
4872 * avoiding showmatch(). | |
4873 */ | |
4874 oldState = State; | |
4875 State = NORMAL; | |
4876 /* | |
4877 * restore characters (blanks) deleted after cursor | |
4878 */ | |
4879 while (cc > 0) | |
4880 { | |
1872 | 4881 save_col = curwin->w_cursor.col; |
7 | 4882 mb_replace_pop_ins(cc); |
1872 | 4883 curwin->w_cursor.col = save_col; |
7 | 4884 cc = replace_pop(); |
4885 } | |
4886 /* restore the characters that NL replaced */ | |
4887 replace_pop_ins(); | |
4888 State = oldState; | |
4889 } | |
4890 } | |
4891 did_ai = FALSE; | |
4892 } | |
4893 else | |
4894 { | |
4895 /* | |
4896 * Delete character(s) before the cursor. | |
4897 */ | |
4898 #ifdef FEAT_RIGHTLEFT | |
4899 if (revins_on) /* put cursor on last inserted char */ | |
4900 dec_cursor(); | |
4901 #endif | |
4902 mincol = 0; | |
4903 /* keep indent */ | |
1085 | 4904 if (mode == BACKSPACE_LINE |
4905 && (curbuf->b_p_ai | |
4906 #ifdef FEAT_CINDENT | |
2004 | 4907 || cindent_on() |
1085 | 4908 #endif |
4909 ) | |
7 | 4910 #ifdef FEAT_RIGHTLEFT |
4911 && !revins_on | |
4912 #endif | |
4913 ) | |
4914 { | |
1872 | 4915 save_col = curwin->w_cursor.col; |
7 | 4916 beginline(BL_WHITE); |
1988 | 4917 if (curwin->w_cursor.col < save_col) |
7 | 4918 mincol = curwin->w_cursor.col; |
1872 | 4919 curwin->w_cursor.col = save_col; |
7 | 4920 } |
4921 | |
4922 /* | |
4923 * Handle deleting one 'shiftwidth' or 'softtabstop'. | |
4924 */ | |
4925 if ( mode == BACKSPACE_CHAR | |
4926 && ((p_sta && in_indent) | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4927 || ((get_sts_value() != 0 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4928 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4929 || tabstop_count(curbuf->b_p_vsts_array) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4930 #endif |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4931 ) |
1497 | 4932 && curwin->w_cursor.col > 0 |
7 | 4933 && (*(ml_get_cursor() - 1) == TAB |
4934 || (*(ml_get_cursor() - 1) == ' ' | |
4935 && (!*inserted_space_p | |
4936 || arrow_used)))))) | |
4937 { | |
4938 int ts; | |
4939 colnr_T vcol; | |
4940 colnr_T want_vcol; | |
1460 | 4941 colnr_T start_vcol; |
7 | 4942 |
4943 *inserted_space_p = FALSE; | |
4944 /* Compute the virtual column where we want to be. Since | |
4945 * 'showbreak' may get in the way, need to get the last column of | |
4946 * the previous character. */ | |
4947 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); | |
1460 | 4948 start_vcol = vcol; |
7 | 4949 dec_cursor(); |
4950 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol); | |
4951 inc_cursor(); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4952 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4953 if (p_sta && in_indent) |
14276
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
4954 { |
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
4955 ts = (int)get_sw_value(curbuf); |
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
4956 want_vcol = (want_vcol / ts) * ts; |
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
4957 } |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4958 else |
14243
fbf0681606fa
patch 8.1.0138: negative value of 'softtabstop' not used correctly
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
4959 want_vcol = tabstop_start(want_vcol, get_sts_value(), |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4960 curbuf->b_p_vsts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4961 #else |
14276
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
4962 if (p_sta && in_indent) |
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
4963 ts = (int)get_sw_value(curbuf); |
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
4964 else |
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
4965 ts = (int)get_sts_value(); |
7 | 4966 want_vcol = (want_vcol / ts) * ts; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
4967 #endif |
7 | 4968 |
4969 /* delete characters until we are at or before want_vcol */ | |
4970 while (vcol > want_vcol | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4971 && (cc = *(ml_get_cursor() - 1), VIM_ISWHITE(cc))) |
1460 | 4972 ins_bs_one(&vcol); |
7 | 4973 |
4974 /* insert extra spaces until we are at want_vcol */ | |
4975 while (vcol < want_vcol) | |
4976 { | |
4977 /* Remember the first char we inserted */ | |
5852 | 4978 if (curwin->w_cursor.lnum == Insstart_orig.lnum |
4979 && curwin->w_cursor.col < Insstart_orig.col) | |
4980 Insstart_orig.col = curwin->w_cursor.col; | |
7 | 4981 |
4982 if (State & VREPLACE_FLAG) | |
4983 ins_char(' '); | |
4984 else | |
4985 { | |
4986 ins_str((char_u *)" "); | |
1460 | 4987 if ((State & REPLACE_FLAG)) |
4988 replace_push(NUL); | |
7 | 4989 } |
4990 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); | |
4991 } | |
1460 | 4992 |
4993 /* If we are now back where we started delete one character. Can | |
4994 * happen when using 'sts' and 'linebreak'. */ | |
4995 if (vcol >= start_vcol) | |
4996 ins_bs_one(&vcol); | |
7 | 4997 } |
4998 | |
4999 /* | |
5000 * Delete upto starting point, start of line or previous word. | |
5001 */ | |
6712 | 5002 else |
5003 { | |
5004 int cclass = 0, prev_cclass = 0; | |
5005 | |
5006 if (has_mbyte) | |
5007 cclass = mb_get_class(ml_get_cursor()); | |
5008 do | |
7 | 5009 { |
5010 #ifdef FEAT_RIGHTLEFT | |
6712 | 5011 if (!revins_on) /* put cursor on char to be deleted */ |
5012 #endif | |
7 | 5013 dec_cursor(); |
6712 | 5014 |
5015 cc = gchar_cursor(); | |
5016 /* look multi-byte character class */ | |
5017 if (has_mbyte) | |
5018 { | |
5019 prev_cclass = cclass; | |
5020 cclass = mb_get_class(ml_get_cursor()); | |
5021 } | |
5022 | |
5023 /* start of word? */ | |
5024 if (mode == BACKSPACE_WORD && !vim_isspace(cc)) | |
5025 { | |
5026 mode = BACKSPACE_WORD_NOT_SPACE; | |
5027 temp = vim_iswordc(cc); | |
5028 } | |
5029 /* end of word? */ | |
5030 else if (mode == BACKSPACE_WORD_NOT_SPACE | |
5031 && ((vim_isspace(cc) || vim_iswordc(cc) != temp) | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15569
diff
changeset
|
5032 || prev_cclass != cclass)) |
6712 | 5033 { |
5034 #ifdef FEAT_RIGHTLEFT | |
5035 if (!revins_on) | |
5036 #endif | |
5037 inc_cursor(); | |
5038 #ifdef FEAT_RIGHTLEFT | |
5039 else if (State & REPLACE_FLAG) | |
5040 dec_cursor(); | |
5041 #endif | |
5042 break; | |
5043 } | |
5044 if (State & REPLACE_FLAG) | |
5045 replace_do_bs(-1); | |
5046 else | |
5047 { | |
5048 if (enc_utf8 && p_deco) | |
5049 (void)utfc_ptr2char(ml_get_cursor(), cpc); | |
5050 (void)del_char(FALSE); | |
5051 /* | |
5052 * If there are combining characters and 'delcombine' is set | |
5053 * move the cursor back. Don't back up before the base | |
5054 * character. | |
5055 */ | |
5056 if (enc_utf8 && p_deco && cpc[0] != NUL) | |
5057 inc_cursor(); | |
7 | 5058 #ifdef FEAT_RIGHTLEFT |
6712 | 5059 if (revins_chars) |
5060 { | |
5061 revins_chars--; | |
5062 revins_legal++; | |
5063 } | |
5064 if (revins_on && gchar_cursor() == NUL) | |
5065 break; | |
5066 #endif | |
7 | 5067 } |
6712 | 5068 /* Just a single backspace?: */ |
5069 if (mode == BACKSPACE_CHAR) | |
7 | 5070 break; |
6712 | 5071 } while ( |
7 | 5072 #ifdef FEAT_RIGHTLEFT |
6712 | 5073 revins_on || |
5074 #endif | |
5075 (curwin->w_cursor.col > mincol | |
5076 && (curwin->w_cursor.lnum != Insstart_orig.lnum | |
5077 || curwin->w_cursor.col != Insstart_orig.col))); | |
5078 } | |
7 | 5079 did_backspace = TRUE; |
5080 } | |
5081 #ifdef FEAT_SMARTINDENT | |
5082 did_si = FALSE; | |
5083 can_si = FALSE; | |
5084 can_si_back = FALSE; | |
5085 #endif | |
5086 if (curwin->w_cursor.col <= 1) | |
5087 did_ai = FALSE; | |
5088 /* | |
5089 * It's a little strange to put backspaces into the redo | |
5090 * buffer, but it makes auto-indent a lot easier to deal | |
5091 * with. | |
5092 */ | |
5093 AppendCharToRedobuff(c); | |
5094 | |
5095 /* If deleted before the insertion point, adjust it */ | |
5852 | 5096 if (curwin->w_cursor.lnum == Insstart_orig.lnum |
14037
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14035
diff
changeset
|
5097 && curwin->w_cursor.col < Insstart_orig.col) |
5852 | 5098 Insstart_orig.col = curwin->w_cursor.col; |
7 | 5099 |
5100 /* vi behaviour: the cursor moves backward but the character that | |
5101 * was there remains visible | |
5102 * Vim behaviour: the cursor moves backward and the character that | |
5103 * was there is erased from the screen. | |
5104 * We can emulate the vi behaviour by pretending there is a dollar | |
5105 * displayed even when there isn't. | |
5106 * --pkv Sun Jan 19 01:56:40 EST 2003 */ | |
3318 | 5107 if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == -1) |
7 | 5108 dollar_vcol = curwin->w_virtcol; |
5109 | |
1514 | 5110 #ifdef FEAT_FOLDING |
5111 /* When deleting a char the cursor line must never be in a closed fold. | |
5112 * E.g., when 'foldmethod' is indent and deleting the first non-white | |
5113 * char before a Tab. */ | |
5114 if (did_backspace) | |
5115 foldOpenCursor(); | |
5116 #endif | |
5117 | |
7 | 5118 return did_backspace; |
5119 } | |
5120 | |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5121 /* |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5122 * Handle receiving P_PS: start paste mode. Inserts the following text up to |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5123 * P_PE literally. |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5124 * When "drop" is TRUE then consume the text and drop it. |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5125 */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5126 int |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5127 bracketed_paste(paste_mode_T mode, int drop, garray_T *gap) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5128 { |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5129 int c; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5130 char_u buf[NUMBUFLEN + MB_MAXBYTES]; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5131 int idx = 0; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5132 char_u *end = find_termcode((char_u *)"PE"); |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5133 int ret_char = -1; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5134 int save_allow_keys = allow_keys; |
10696
689e88afdd11
patch 8.0.0238: bracketed paste does not disable autoindent
Christian Brabandt <cb@256bit.org>
parents:
10684
diff
changeset
|
5135 int save_paste = p_paste; |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5136 |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5137 /* If the end code is too long we can't detect it, read everything. */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5138 if (STRLEN(end) >= NUMBUFLEN) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5139 end = NULL; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5140 ++no_mapping; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5141 allow_keys = 0; |
14419
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5142 if (!p_paste) |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5143 // Also have the side effects of setting 'paste' to make it work much |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5144 // faster. |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5145 set_option_value((char_u *)"paste", TRUE, NULL, 0); |
10696
689e88afdd11
patch 8.0.0238: bracketed paste does not disable autoindent
Christian Brabandt <cb@256bit.org>
parents:
10684
diff
changeset
|
5146 |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5147 for (;;) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5148 { |
14419
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5149 // When the end is not defined read everything there is. |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5150 if (end == NULL && vpeekc() == NUL) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5151 break; |
14419
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5152 do |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5153 c = vgetc(); |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
16142
diff
changeset
|
5154 while (c == K_IGNORE || c == K_VER_SCROLLBAR || c == K_HOR_SCROLLBAR); |
14419
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5155 if (c == NUL || got_int) |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5156 // When CTRL-C was encountered the typeahead will be flushed and we |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5157 // won't get the end sequence. |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5158 break; |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5159 |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5160 if (has_mbyte) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5161 idx += (*mb_char2bytes)(c, buf + idx); |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5162 else |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5163 buf[idx++] = c; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5164 buf[idx] = NUL; |
11317
e45c6e4d78af
patch 8.0.0544: cppcheck warnings
Christian Brabandt <cb@256bit.org>
parents:
11311
diff
changeset
|
5165 if (end != NULL && STRNCMP(buf, end, idx) == 0) |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5166 { |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5167 if (end[idx] == NUL) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5168 break; /* Found the end of paste code. */ |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5169 continue; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5170 } |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5171 if (!drop) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5172 { |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5173 switch (mode) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5174 { |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5175 case PASTE_CMDLINE: |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5176 put_on_cmdline(buf, idx, TRUE); |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5177 break; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5178 |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5179 case PASTE_EX: |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5180 if (gap != NULL && ga_grow(gap, idx) == OK) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5181 { |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5182 mch_memmove((char *)gap->ga_data + gap->ga_len, |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5183 buf, (size_t)idx); |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5184 gap->ga_len += idx; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5185 } |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5186 break; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5187 |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5188 case PASTE_INSERT: |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5189 if (stop_arrow() == OK) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5190 { |
10680
75c324ab1270
patch 8.0.0230: bracketed paste does not support line breaks
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
5191 c = buf[0]; |
75c324ab1270
patch 8.0.0230: bracketed paste does not support line breaks
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
5192 if (idx == 1 && (c == CAR || c == K_KENTER || c == NL)) |
75c324ab1270
patch 8.0.0230: bracketed paste does not support line breaks
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
5193 ins_eol(c); |
75c324ab1270
patch 8.0.0230: bracketed paste does not support line breaks
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
5194 else |
10682
d564e73ff9ee
patch 8.0.0231: bracketed paste mode is not tested
Christian Brabandt <cb@256bit.org>
parents:
10680
diff
changeset
|
5195 { |
10680
75c324ab1270
patch 8.0.0230: bracketed paste does not support line breaks
Christian Brabandt <cb@256bit.org>
parents:
10640
diff
changeset
|
5196 ins_char_bytes(buf, idx); |
10682
d564e73ff9ee
patch 8.0.0231: bracketed paste mode is not tested
Christian Brabandt <cb@256bit.org>
parents:
10680
diff
changeset
|
5197 AppendToRedobuffLit(buf, idx); |
d564e73ff9ee
patch 8.0.0231: bracketed paste mode is not tested
Christian Brabandt <cb@256bit.org>
parents:
10680
diff
changeset
|
5198 } |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5199 } |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5200 break; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5201 |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5202 case PASTE_ONE_CHAR: |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5203 if (ret_char == -1) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5204 { |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5205 if (has_mbyte) |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5206 ret_char = (*mb_ptr2char)(buf); |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5207 else |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5208 ret_char = buf[0]; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5209 } |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5210 break; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5211 } |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5212 } |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5213 idx = 0; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5214 } |
10696
689e88afdd11
patch 8.0.0238: bracketed paste does not disable autoindent
Christian Brabandt <cb@256bit.org>
parents:
10684
diff
changeset
|
5215 |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5216 --no_mapping; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5217 allow_keys = save_allow_keys; |
14419
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5218 if (!save_paste) |
cdc4eacdd81d
patch 8.1.0224: hang in bracketed paste mode when t_PE not encountered
Christian Brabandt <cb@256bit.org>
parents:
14301
diff
changeset
|
5219 set_option_value((char_u *)"paste", FALSE, NULL, 0); |
10640
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5220 |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5221 return ret_char; |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5222 } |
27be410d6d29
patch 8.0.0210: no support for bracketed paste
Christian Brabandt <cb@256bit.org>
parents:
10636
diff
changeset
|
5223 |
692 | 5224 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
724 | 5225 static void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5226 ins_tabline(int c) |
692 | 5227 { |
5228 /* We will be leaving the current window, unless closing another tab. */ | |
5229 if (c != K_TABMENU || current_tabmenu != TABLINE_MENU_CLOSE | |
5230 || (current_tab != 0 && current_tab != tabpage_index(curtab))) | |
5231 { | |
5232 undisplay_dollar(); | |
5233 start_arrow(&curwin->w_cursor); | |
5234 # ifdef FEAT_CINDENT | |
5235 can_cindent = TRUE; | |
5236 # endif | |
5237 } | |
5238 | |
5239 if (c == K_TABLINE) | |
5240 goto_tabpage(current_tab); | |
5241 else | |
846 | 5242 { |
692 | 5243 handle_tabmenu(); |
846 | 5244 redraw_statuslines(); /* will redraw the tabline when needed */ |
5245 } | |
692 | 5246 } |
5247 #endif | |
5248 | |
5249 #if defined(FEAT_GUI) || defined(PROTO) | |
7 | 5250 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5251 ins_scroll(void) |
7 | 5252 { |
5253 pos_T tpos; | |
5254 | |
5255 undisplay_dollar(); | |
5256 tpos = curwin->w_cursor; | |
5257 if (gui_do_scroll()) | |
5258 { | |
5259 start_arrow(&tpos); | |
5260 # ifdef FEAT_CINDENT | |
5261 can_cindent = TRUE; | |
5262 # endif | |
5263 } | |
5264 } | |
5265 | |
5266 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5267 ins_horscroll(void) |
7 | 5268 { |
5269 pos_T tpos; | |
5270 | |
5271 undisplay_dollar(); | |
5272 tpos = curwin->w_cursor; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
5273 if (gui_do_horiz_scroll(scrollbar_value, FALSE)) |
7 | 5274 { |
5275 start_arrow(&tpos); | |
5276 # ifdef FEAT_CINDENT | |
5277 can_cindent = TRUE; | |
5278 # endif | |
5279 } | |
5280 } | |
5281 #endif | |
5282 | |
5283 static void | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5284 ins_left(void) |
7 | 5285 { |
5286 pos_T tpos; | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5287 int end_change = dont_sync_undo == FALSE; // end undoable change |
7 | 5288 |
5289 #ifdef FEAT_FOLDING | |
5290 if ((fdo_flags & FDO_HOR) && KeyTyped) | |
5291 foldOpenCursor(); | |
5292 #endif | |
5293 undisplay_dollar(); | |
5294 tpos = curwin->w_cursor; | |
5295 if (oneleft() == OK) | |
5296 { | |
941 | 5297 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
5298 /* Only call start_arrow() when not busy with preediting, it will | |
5299 * break undo. K_LEFT is inserted in im_correct_cursor(). */ | |
12293
1ff5e5dfa9b0
patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
5300 if (p_imst == IM_OVER_THE_SPOT || !im_is_preediting()) |
941 | 5301 #endif |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5302 { |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5303 start_arrow_with_change(&tpos, end_change); |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5304 if (!end_change) |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5305 AppendCharToRedobuff(K_LEFT); |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5306 } |
7 | 5307 #ifdef FEAT_RIGHTLEFT |
5308 /* If exit reversed string, position is fixed */ | |
5309 if (revins_scol != -1 && (int)curwin->w_cursor.col >= revins_scol) | |
5310 revins_legal++; | |
5311 revins_chars++; | |
5312 #endif | |
5313 } | |
5314 | |
5315 /* | |
5316 * if 'whichwrap' set for cursor in insert mode may go to | |
5317 * previous line | |
5318 */ | |
5319 else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1) | |
5320 { | |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5321 /* always break undo when moving upwards/downwards, else undo may break */ |
7 | 5322 start_arrow(&tpos); |
5323 --(curwin->w_cursor.lnum); | |
5324 coladvance((colnr_T)MAXCOL); | |
5325 curwin->w_set_curswant = TRUE; /* so we stay at the end */ | |
5326 } | |
5327 else | |
6949 | 5328 vim_beep(BO_CRSR); |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5329 dont_sync_undo = FALSE; |
7 | 5330 } |
5331 | |
5332 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5333 ins_home(int c) |
7 | 5334 { |
5335 pos_T tpos; | |
5336 | |
5337 #ifdef FEAT_FOLDING | |
5338 if ((fdo_flags & FDO_HOR) && KeyTyped) | |
5339 foldOpenCursor(); | |
5340 #endif | |
5341 undisplay_dollar(); | |
5342 tpos = curwin->w_cursor; | |
5343 if (c == K_C_HOME) | |
5344 curwin->w_cursor.lnum = 1; | |
5345 curwin->w_cursor.col = 0; | |
5346 curwin->w_cursor.coladd = 0; | |
5347 curwin->w_curswant = 0; | |
5348 start_arrow(&tpos); | |
5349 } | |
5350 | |
5351 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5352 ins_end(int c) |
7 | 5353 { |
5354 pos_T tpos; | |
5355 | |
5356 #ifdef FEAT_FOLDING | |
5357 if ((fdo_flags & FDO_HOR) && KeyTyped) | |
5358 foldOpenCursor(); | |
5359 #endif | |
5360 undisplay_dollar(); | |
5361 tpos = curwin->w_cursor; | |
5362 if (c == K_C_END) | |
5363 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
5364 coladvance((colnr_T)MAXCOL); | |
5365 curwin->w_curswant = MAXCOL; | |
5366 | |
5367 start_arrow(&tpos); | |
5368 } | |
5369 | |
5370 static void | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5371 ins_s_left() |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5372 { |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5373 int end_change = dont_sync_undo == FALSE; // end undoable change |
7 | 5374 #ifdef FEAT_FOLDING |
5375 if ((fdo_flags & FDO_HOR) && KeyTyped) | |
5376 foldOpenCursor(); | |
5377 #endif | |
5378 undisplay_dollar(); | |
5379 if (curwin->w_cursor.lnum > 1 || curwin->w_cursor.col > 0) | |
5380 { | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5381 start_arrow_with_change(&curwin->w_cursor, end_change); |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5382 if (!end_change) |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5383 AppendCharToRedobuff(K_S_LEFT); |
7 | 5384 (void)bck_word(1L, FALSE, FALSE); |
5385 curwin->w_set_curswant = TRUE; | |
5386 } | |
5387 else | |
6949 | 5388 vim_beep(BO_CRSR); |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5389 dont_sync_undo = FALSE; |
7 | 5390 } |
5391 | |
5392 static void | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5393 ins_right(void) |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5394 { |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5395 int end_change = dont_sync_undo == FALSE; // end undoable change |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5396 |
7 | 5397 #ifdef FEAT_FOLDING |
5398 if ((fdo_flags & FDO_HOR) && KeyTyped) | |
5399 foldOpenCursor(); | |
5400 #endif | |
5401 undisplay_dollar(); | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15629
diff
changeset
|
5402 if (gchar_cursor() != NUL || virtual_active()) |
7 | 5403 { |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5404 start_arrow_with_change(&curwin->w_cursor, end_change); |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5405 if (!end_change) |
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5406 AppendCharToRedobuff(K_RIGHT); |
7 | 5407 curwin->w_set_curswant = TRUE; |
5408 if (virtual_active()) | |
5409 oneright(); | |
5410 else | |
5411 { | |
5412 if (has_mbyte) | |
474 | 5413 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 5414 else |
5415 ++curwin->w_cursor.col; | |
5416 } | |
5417 | |
5418 #ifdef FEAT_RIGHTLEFT | |
5419 revins_legal++; | |
5420 if (revins_chars) | |
5421 revins_chars--; | |
5422 #endif | |
5423 } | |
5424 /* if 'whichwrap' set for cursor in insert mode, may move the | |
5425 * cursor to the next line */ | |
5426 else if (vim_strchr(p_ww, ']') != NULL | |
5427 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
5428 { | |
5429 start_arrow(&curwin->w_cursor); | |
5430 curwin->w_set_curswant = TRUE; | |
5431 ++curwin->w_cursor.lnum; | |
5432 curwin->w_cursor.col = 0; | |
5433 } | |
5434 else | |
6949 | 5435 vim_beep(BO_CRSR); |
7074
c8efa41dd451
commit https://github.com/vim/vim/commit/8b5f65a527c353b9942e362e719687c3a7592309
Christian Brabandt <cb@256bit.org>
parents:
6971
diff
changeset
|
5436 dont_sync_undo = FALSE; |
7 | 5437 } |
5438 | |
5439 static void | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5440 ins_s_right() |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5441 { |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5442 int end_change = dont_sync_undo == FALSE; // end undoable change |
7 | 5443 #ifdef FEAT_FOLDING |
5444 if ((fdo_flags & FDO_HOR) && KeyTyped) | |
5445 foldOpenCursor(); | |
5446 #endif | |
5447 undisplay_dollar(); | |
5448 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count | |
5449 || gchar_cursor() != NUL) | |
5450 { | |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5451 start_arrow_with_change(&curwin->w_cursor, end_change); |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5452 if (!end_change) |
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5453 AppendCharToRedobuff(K_S_RIGHT); |
7 | 5454 (void)fwd_word(1L, FALSE, 0); |
5455 curwin->w_set_curswant = TRUE; | |
5456 } | |
5457 else | |
6949 | 5458 vim_beep(BO_CRSR); |
16101
5c5d211bd5a8
patch 8.1.1055: CTRL-G U in Insert mode doesn't work for shift-Left
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
5459 dont_sync_undo = FALSE; |
7 | 5460 } |
5461 | |
5462 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5463 ins_up( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5464 int startcol) /* when TRUE move to Insstart.col */ |
7 | 5465 { |
5466 pos_T tpos; | |
5467 linenr_T old_topline = curwin->w_topline; | |
5468 #ifdef FEAT_DIFF | |
5469 int old_topfill = curwin->w_topfill; | |
5470 #endif | |
5471 | |
5472 undisplay_dollar(); | |
5473 tpos = curwin->w_cursor; | |
5474 if (cursor_up(1L, TRUE) == OK) | |
5475 { | |
5476 if (startcol) | |
5477 coladvance(getvcol_nolist(&Insstart)); | |
5478 if (old_topline != curwin->w_topline | |
5479 #ifdef FEAT_DIFF | |
5480 || old_topfill != curwin->w_topfill | |
5481 #endif | |
5482 ) | |
5483 redraw_later(VALID); | |
5484 start_arrow(&tpos); | |
5485 #ifdef FEAT_CINDENT | |
5486 can_cindent = TRUE; | |
5487 #endif | |
5488 } | |
5489 else | |
6949 | 5490 vim_beep(BO_CRSR); |
7 | 5491 } |
5492 | |
5493 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5494 ins_pageup(void) |
7 | 5495 { |
5496 pos_T tpos; | |
5497 | |
5498 undisplay_dollar(); | |
828 | 5499 |
5500 if (mod_mask & MOD_MASK_CTRL) | |
5501 { | |
5502 /* <C-PageUp>: tab page back */ | |
1013 | 5503 if (first_tabpage->tp_next != NULL) |
5504 { | |
5505 start_arrow(&curwin->w_cursor); | |
5506 goto_tabpage(-1); | |
5507 } | |
828 | 5508 return; |
5509 } | |
5510 | |
7 | 5511 tpos = curwin->w_cursor; |
5512 if (onepage(BACKWARD, 1L) == OK) | |
5513 { | |
5514 start_arrow(&tpos); | |
5515 #ifdef FEAT_CINDENT | |
5516 can_cindent = TRUE; | |
5517 #endif | |
5518 } | |
5519 else | |
6949 | 5520 vim_beep(BO_CRSR); |
7 | 5521 } |
5522 | |
5523 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5524 ins_down( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5525 int startcol) /* when TRUE move to Insstart.col */ |
7 | 5526 { |
5527 pos_T tpos; | |
5528 linenr_T old_topline = curwin->w_topline; | |
5529 #ifdef FEAT_DIFF | |
5530 int old_topfill = curwin->w_topfill; | |
5531 #endif | |
5532 | |
5533 undisplay_dollar(); | |
5534 tpos = curwin->w_cursor; | |
5535 if (cursor_down(1L, TRUE) == OK) | |
5536 { | |
5537 if (startcol) | |
5538 coladvance(getvcol_nolist(&Insstart)); | |
5539 if (old_topline != curwin->w_topline | |
5540 #ifdef FEAT_DIFF | |
5541 || old_topfill != curwin->w_topfill | |
5542 #endif | |
5543 ) | |
5544 redraw_later(VALID); | |
5545 start_arrow(&tpos); | |
5546 #ifdef FEAT_CINDENT | |
5547 can_cindent = TRUE; | |
5548 #endif | |
5549 } | |
5550 else | |
6949 | 5551 vim_beep(BO_CRSR); |
7 | 5552 } |
5553 | |
5554 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5555 ins_pagedown(void) |
7 | 5556 { |
5557 pos_T tpos; | |
5558 | |
5559 undisplay_dollar(); | |
828 | 5560 |
5561 if (mod_mask & MOD_MASK_CTRL) | |
5562 { | |
5563 /* <C-PageDown>: tab page forward */ | |
1013 | 5564 if (first_tabpage->tp_next != NULL) |
5565 { | |
5566 start_arrow(&curwin->w_cursor); | |
5567 goto_tabpage(0); | |
5568 } | |
828 | 5569 return; |
5570 } | |
5571 | |
7 | 5572 tpos = curwin->w_cursor; |
5573 if (onepage(FORWARD, 1L) == OK) | |
5574 { | |
5575 start_arrow(&tpos); | |
5576 #ifdef FEAT_CINDENT | |
5577 can_cindent = TRUE; | |
5578 #endif | |
5579 } | |
5580 else | |
6949 | 5581 vim_beep(BO_CRSR); |
7 | 5582 } |
5583 | |
5584 #ifdef FEAT_DND | |
5585 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5586 ins_drop(void) |
7 | 5587 { |
5588 do_put('~', BACKWARD, 1L, PUT_CURSEND); | |
5589 } | |
5590 #endif | |
5591 | |
5592 /* | |
5593 * Handle TAB in Insert or Replace mode. | |
5594 * Return TRUE when the TAB needs to be inserted like a normal character. | |
5595 */ | |
5596 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5597 ins_tab(void) |
7 | 5598 { |
5599 int ind; | |
5600 int i; | |
5601 int temp; | |
5602 | |
5603 if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum) | |
5604 Insstart_blank_vcol = get_nolist_virtcol(); | |
5605 if (echeck_abbr(TAB + ABBR_OFF)) | |
5606 return FALSE; | |
5607 | |
5608 ind = inindent(0); | |
5609 #ifdef FEAT_CINDENT | |
5610 if (ind) | |
5611 can_cindent = FALSE; | |
5612 #endif | |
5613 | |
5614 /* | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5615 * When nothing special, insert TAB like a normal character. |
7 | 5616 */ |
5617 if (!curbuf->b_p_et | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5618 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5619 && !(p_sta && ind |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5620 /* These five lines mean 'tabstop' != 'shiftwidth' */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5621 && ((tabstop_count(curbuf->b_p_vts_array) > 1) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5622 || (tabstop_count(curbuf->b_p_vts_array) == 1 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5623 && tabstop_first(curbuf->b_p_vts_array) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5624 != get_sw_value(curbuf)) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5625 || (tabstop_count(curbuf->b_p_vts_array) == 0 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5626 && curbuf->b_p_ts != get_sw_value(curbuf)))) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5627 && tabstop_count(curbuf->b_p_vsts_array) == 0 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5628 #else |
5438 | 5629 && !(p_sta && ind && curbuf->b_p_ts != get_sw_value(curbuf)) |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5630 #endif |
3873 | 5631 && get_sts_value() == 0) |
7 | 5632 return TRUE; |
5633 | |
5634 if (stop_arrow() == FAIL) | |
5635 return TRUE; | |
5636 | |
5637 did_ai = FALSE; | |
5638 #ifdef FEAT_SMARTINDENT | |
5639 did_si = FALSE; | |
5640 can_si = FALSE; | |
5641 can_si_back = FALSE; | |
5642 #endif | |
5643 AppendToRedobuff((char_u *)"\t"); | |
5644 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5645 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5646 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5647 { |
14276
752ef53d3731
patch 8.1.0154: crash with "set smarttab shiftwidth=0 softtabstop=-1"
Christian Brabandt <cb@256bit.org>
parents:
14243
diff
changeset
|
5648 temp = (int)get_sw_value(curbuf); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5649 temp -= get_nolist_virtcol() % temp; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5650 } |
14243
fbf0681606fa
patch 8.1.0138: negative value of 'softtabstop' not used correctly
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5651 else if (tabstop_count(curbuf->b_p_vsts_array) > 0 || curbuf->b_p_sts != 0) |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5652 /* use 'softtabstop' when set */ |
14243
fbf0681606fa
patch 8.1.0138: negative value of 'softtabstop' not used correctly
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5653 temp = tabstop_padding(get_nolist_virtcol(), get_sts_value(), |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5654 curbuf->b_p_vsts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5655 else /* otherwise use 'tabstop' */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5656 temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5657 curbuf->b_p_vts_array); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5658 #else |
7 | 5659 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ |
5438 | 5660 temp = (int)get_sw_value(curbuf); |
3873 | 5661 else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ |
5662 temp = (int)get_sts_value(); | |
7 | 5663 else /* otherwise use 'tabstop' */ |
5664 temp = (int)curbuf->b_p_ts; | |
5665 temp -= get_nolist_virtcol() % temp; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5666 #endif |
7 | 5667 |
5668 /* | |
5669 * Insert the first space with ins_char(). It will delete one char in | |
5670 * replace mode. Insert the rest with ins_str(); it will not delete any | |
5671 * chars. For VREPLACE mode, we use ins_char() for all characters. | |
5672 */ | |
5673 ins_char(' '); | |
5674 while (--temp > 0) | |
5675 { | |
5676 if (State & VREPLACE_FLAG) | |
5677 ins_char(' '); | |
5678 else | |
5679 { | |
5680 ins_str((char_u *)" "); | |
5681 if (State & REPLACE_FLAG) /* no char replaced */ | |
5682 replace_push(NUL); | |
5683 } | |
5684 } | |
5685 | |
5686 /* | |
5687 * When 'expandtab' not set: Replace spaces by TABs where possible. | |
5688 */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5689 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5690 if (!curbuf->b_p_et && (tabstop_count(curbuf->b_p_vsts_array) > 0 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5691 || get_sts_value() > 0 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5692 || (p_sta && ind))) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5693 #else |
3873 | 5694 if (!curbuf->b_p_et && (get_sts_value() || (p_sta && ind))) |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14103
diff
changeset
|
5695 #endif |
7 | 5696 { |
5697 char_u *ptr; | |
5698 char_u *saved_line = NULL; /* init for GCC */ | |
5699 pos_T pos; | |
5700 pos_T fpos; | |
5701 pos_T *cursor; | |
5702 colnr_T want_vcol, vcol; | |
5703 int change_col = -1; | |
5704 int save_list = curwin->w_p_list; | |
5705 | |
5706 /* | |
5707 * Get the current line. For VREPLACE mode, don't make real changes | |
5708 * yet, just work on a copy of the line. | |
5709 */ | |
5710 if (State & VREPLACE_FLAG) | |
5711 { | |
5712 pos = curwin->w_cursor; | |
5713 cursor = &pos; | |
5714 saved_line = vim_strsave(ml_get_curline()); | |
5715 if (saved_line == NULL) | |
5716 return FALSE; | |
5717 ptr = saved_line + pos.col; | |
5718 } | |
5719 else | |
5720 { | |
5721 ptr = ml_get_cursor(); | |
5722 cursor = &curwin->w_cursor; | |
5723 } | |
5724 | |
5725 /* When 'L' is not in 'cpoptions' a tab always takes up 'ts' spaces. */ | |
5726 if (vim_strchr(p_cpo, CPO_LISTWM) == NULL) | |
5727 curwin->w_p_list = FALSE; | |
5728 | |
5729 /* Find first white before the cursor */ | |
5730 fpos = curwin->w_cursor; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5731 while (fpos.col > 0 && VIM_ISWHITE(ptr[-1])) |
7 | 5732 { |
5733 --fpos.col; | |
5734 --ptr; | |
5735 } | |
5736 | |
5737 /* In Replace mode, don't change characters before the insert point. */ | |
5738 if ((State & REPLACE_FLAG) | |
5739 && fpos.lnum == Insstart.lnum | |
5740 && fpos.col < Insstart.col) | |
5741 { | |
5742 ptr += Insstart.col - fpos.col; | |
5743 fpos.col = Insstart.col; | |
5744 } | |
5745 | |
5746 /* compute virtual column numbers of first white and cursor */ | |
5747 getvcol(curwin, &fpos, &vcol, NULL, NULL); | |
5748 getvcol(curwin, cursor, &want_vcol, NULL, NULL); | |
5749 | |
5995 | 5750 /* Use as many TABs as possible. Beware of 'breakindent', 'showbreak' |
5751 * and 'linebreak' adding extra virtual columns. */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5752 while (VIM_ISWHITE(*ptr)) |
7 | 5753 { |
5995 | 5754 i = lbr_chartabsize(NULL, (char_u *)"\t", vcol); |
7 | 5755 if (vcol + i > want_vcol) |
5756 break; | |
5757 if (*ptr != TAB) | |
5758 { | |
5759 *ptr = TAB; | |
5760 if (change_col < 0) | |
5761 { | |
5762 change_col = fpos.col; /* Column of first change */ | |
5763 /* May have to adjust Insstart */ | |
5764 if (fpos.lnum == Insstart.lnum && fpos.col < Insstart.col) | |
5765 Insstart.col = fpos.col; | |
5766 } | |
5767 } | |
5768 ++fpos.col; | |
5769 ++ptr; | |
5770 vcol += i; | |
5771 } | |
5772 | |
5773 if (change_col >= 0) | |
5774 { | |
5775 int repl_off = 0; | |
5995 | 5776 char_u *line = ptr; |
7 | 5777 |
5778 /* Skip over the spaces we need. */ | |
5779 while (vcol < want_vcol && *ptr == ' ') | |
5780 { | |
5995 | 5781 vcol += lbr_chartabsize(line, ptr, vcol); |
7 | 5782 ++ptr; |
5783 ++repl_off; | |
5784 } | |
5785 if (vcol > want_vcol) | |
5786 { | |
5787 /* Must have a char with 'showbreak' just before it. */ | |
5788 --ptr; | |
5789 --repl_off; | |
5790 } | |
5791 fpos.col += repl_off; | |
5792 | |
5793 /* Delete following spaces. */ | |
5794 i = cursor->col - fpos.col; | |
5795 if (i > 0) | |
5796 { | |
1622 | 5797 STRMOVE(ptr, ptr + i); |
7 | 5798 /* correct replace stack. */ |
14424
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14419
diff
changeset
|
5799 if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG)) |
7 | 5800 for (temp = i; --temp >= 0; ) |
5801 replace_join(repl_off); | |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
5802 #ifdef FEAT_TEXT_PROP |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
5803 curbuf->b_ml.ml_line_len -= i; |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
5804 #endif |
7 | 5805 } |
33 | 5806 #ifdef FEAT_NETBEANS_INTG |
2210 | 5807 if (netbeans_active()) |
33 | 5808 { |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
5809 netbeans_removed(curbuf, fpos.lnum, cursor->col, (long)(i + 1)); |
33 | 5810 netbeans_inserted(curbuf, fpos.lnum, cursor->col, |
5811 (char_u *)"\t", 1); | |
5812 } | |
5813 #endif | |
7 | 5814 cursor->col -= i; |
5815 | |
5816 /* | |
5817 * In VREPLACE mode, we haven't changed anything yet. Do it now by | |
5818 * backspacing over the changed spacing and then inserting the new | |
5819 * spacing. | |
5820 */ | |
5821 if (State & VREPLACE_FLAG) | |
5822 { | |
5823 /* Backspace from real cursor to change_col */ | |
5824 backspace_until_column(change_col); | |
5825 | |
5826 /* Insert each char in saved_line from changed_col to | |
5827 * ptr-cursor */ | |
5828 ins_bytes_len(saved_line + change_col, | |
5829 cursor->col - change_col); | |
5830 } | |
14424
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14419
diff
changeset
|
5831 } |
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14419
diff
changeset
|
5832 |
7 | 5833 if (State & VREPLACE_FLAG) |
5834 vim_free(saved_line); | |
5835 curwin->w_p_list = save_list; | |
5836 } | |
5837 | |
5838 return FALSE; | |
5839 } | |
5840 | |
5841 /* | |
5842 * Handle CR or NL in insert mode. | |
13772
cc21507ee4b1
patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents:
13718
diff
changeset
|
5843 * Return FAIL when out of memory or can't undo. |
7 | 5844 */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
5845 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5846 ins_eol(int c) |
7 | 5847 { |
5848 int i; | |
5849 | |
5850 if (echeck_abbr(c + ABBR_OFF)) | |
13788
a27d380b257f
patch 8.0.1766: expanding abbreviation doesn't work
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
5851 return OK; |
7 | 5852 if (stop_arrow() == FAIL) |
13788
a27d380b257f
patch 8.0.1766: expanding abbreviation doesn't work
Christian Brabandt <cb@256bit.org>
parents:
13772
diff
changeset
|
5853 return FAIL; |
7 | 5854 undisplay_dollar(); |
5855 | |
5856 /* | |
5857 * Strange Vi behaviour: In Replace mode, typing a NL will not delete the | |
5858 * character under the cursor. Only push a NUL on the replace stack, | |
5859 * nothing to put back when the NL is deleted. | |
5860 */ | |
14424
0a69e6e708f9
patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
14419
diff
changeset
|
5861 if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG)) |
7 | 5862 replace_push(NUL); |
5863 | |
5864 /* | |
5865 * In VREPLACE mode, a NL replaces the rest of the line, and starts | |
5866 * replacing the next line, so we push all of the characters left on the | |
5867 * line onto the replace stack. This is not done here though, it is done | |
5868 * in open_line(). | |
5869 */ | |
5870 | |
844 | 5871 /* Put cursor on NUL if on the last char and coladd is 1 (happens after |
5872 * CTRL-O). */ | |
5873 if (virtual_active() && curwin->w_cursor.coladd > 0) | |
5874 coladvance(getviscol()); | |
5875 | |
7 | 5876 #ifdef FEAT_RIGHTLEFT |
5877 /* NL in reverse insert will always start in the end of | |
5878 * current line. */ | |
5879 if (revins_on) | |
5880 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor()); | |
5881 #endif | |
5882 | |
5883 AppendToRedobuff(NL_STR); | |
5884 i = open_line(FORWARD, | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
5885 has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM : 0, old_indent); |
7 | 5886 old_indent = 0; |
5887 #ifdef FEAT_CINDENT | |
5888 can_cindent = TRUE; | |
5889 #endif | |
1032 | 5890 #ifdef FEAT_FOLDING |
5891 /* When inserting a line the cursor line must never be in a closed fold. */ | |
5892 foldOpenCursor(); | |
5893 #endif | |
7 | 5894 |
13772
cc21507ee4b1
patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents:
13718
diff
changeset
|
5895 return i; |
7 | 5896 } |
5897 | |
5898 #ifdef FEAT_DIGRAPHS | |
5899 /* | |
5900 * Handle digraph in insert mode. | |
5901 * Returns character still to be inserted, or NUL when nothing remaining to be | |
5902 * done. | |
5903 */ | |
5904 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5905 ins_digraph(void) |
7 | 5906 { |
5907 int c; | |
5908 int cc; | |
2811 | 5909 int did_putchar = FALSE; |
7 | 5910 |
5911 pc_status = PC_STATUS_UNSET; | |
5912 if (redrawing() && !char_avail()) | |
5913 { | |
5914 /* may need to redraw when no more chars available now */ | |
661 | 5915 ins_redraw(FALSE); |
7 | 5916 |
5917 edit_putchar('?', TRUE); | |
2811 | 5918 did_putchar = TRUE; |
7 | 5919 #ifdef FEAT_CMDL_INFO |
5920 add_to_showcmd_c(Ctrl_K); | |
5921 #endif | |
5922 } | |
5923 | |
5924 #ifdef USE_ON_FLY_SCROLL | |
5925 dont_scroll = TRUE; /* disallow scrolling here */ | |
5926 #endif | |
5927 | |
5928 /* don't map the digraph chars. This also prevents the | |
5929 * mode message to be deleted when ESC is hit */ | |
5930 ++no_mapping; | |
5931 ++allow_keys; | |
1389 | 5932 c = plain_vgetc(); |
7 | 5933 --no_mapping; |
5934 --allow_keys; | |
2811 | 5935 if (did_putchar) |
5936 /* when the line fits in 'columns' the '?' is at the start of the next | |
5937 * line and will not be removed by the redraw */ | |
5938 edit_unputchar(); | |
2319
c79ccf947487
Fix: When entering a digraph or special character after a line that fits the
Bram Moolenaar <bram@vim.org>
parents:
2297
diff
changeset
|
5939 |
7 | 5940 if (IS_SPECIAL(c) || mod_mask) /* special key */ |
5941 { | |
5942 #ifdef FEAT_CMDL_INFO | |
5943 clear_showcmd(); | |
5944 #endif | |
5945 insert_special(c, TRUE, FALSE); | |
5946 return NUL; | |
5947 } | |
5948 if (c != ESC) | |
5949 { | |
2811 | 5950 did_putchar = FALSE; |
7 | 5951 if (redrawing() && !char_avail()) |
5952 { | |
5953 /* may need to redraw when no more chars available now */ | |
661 | 5954 ins_redraw(FALSE); |
7 | 5955 |
5956 if (char2cells(c) == 1) | |
5957 { | |
661 | 5958 ins_redraw(FALSE); |
7 | 5959 edit_putchar(c, TRUE); |
2811 | 5960 did_putchar = TRUE; |
7 | 5961 } |
5962 #ifdef FEAT_CMDL_INFO | |
5963 add_to_showcmd_c(c); | |
5964 #endif | |
5965 } | |
5966 ++no_mapping; | |
5967 ++allow_keys; | |
1389 | 5968 cc = plain_vgetc(); |
7 | 5969 --no_mapping; |
5970 --allow_keys; | |
2811 | 5971 if (did_putchar) |
5972 /* when the line fits in 'columns' the '?' is at the start of the | |
5973 * next line and will not be removed by a redraw */ | |
5974 edit_unputchar(); | |
7 | 5975 if (cc != ESC) |
5976 { | |
5977 AppendToRedobuff((char_u *)CTRL_V_STR); | |
5978 c = getdigraph(c, cc, TRUE); | |
5979 #ifdef FEAT_CMDL_INFO | |
5980 clear_showcmd(); | |
5981 #endif | |
5982 return c; | |
5983 } | |
5984 } | |
5985 #ifdef FEAT_CMDL_INFO | |
5986 clear_showcmd(); | |
5987 #endif | |
5988 return NUL; | |
5989 } | |
5990 #endif | |
5991 | |
5992 /* | |
5993 * Handle CTRL-E and CTRL-Y in Insert mode: copy char from other line. | |
5994 * Returns the char to be inserted, or NUL if none found. | |
5995 */ | |
3501 | 5996 int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5997 ins_copychar(linenr_T lnum) |
7 | 5998 { |
5999 int c; | |
6000 int temp; | |
6001 char_u *ptr, *prev_ptr; | |
5995 | 6002 char_u *line; |
7 | 6003 |
6004 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count) | |
6005 { | |
6949 | 6006 vim_beep(BO_COPY); |
7 | 6007 return NUL; |
6008 } | |
6009 | |
6010 /* try to advance to the cursor column */ | |
6011 temp = 0; | |
5995 | 6012 line = ptr = ml_get(lnum); |
7 | 6013 prev_ptr = ptr; |
6014 validate_virtcol(); | |
6015 while ((colnr_T)temp < curwin->w_virtcol && *ptr != NUL) | |
6016 { | |
6017 prev_ptr = ptr; | |
5995 | 6018 temp += lbr_chartabsize_adv(line, &ptr, (colnr_T)temp); |
7 | 6019 } |
6020 if ((colnr_T)temp > curwin->w_virtcol) | |
6021 ptr = prev_ptr; | |
6022 | |
6023 c = (*mb_ptr2char)(ptr); | |
6024 if (c == NUL) | |
6949 | 6025 vim_beep(BO_COPY); |
7 | 6026 return c; |
6027 } | |
6028 | |
449 | 6029 /* |
6030 * CTRL-Y or CTRL-E typed in Insert mode. | |
6031 */ | |
6032 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6033 ins_ctrl_ey(int tc) |
449 | 6034 { |
6035 int c = tc; | |
6036 | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6037 if (ctrl_x_mode_scroll()) |
449 | 6038 { |
6039 if (c == Ctrl_Y) | |
6040 scrolldown_clamp(); | |
6041 else | |
6042 scrollup_clamp(); | |
6043 redraw_later(VALID); | |
6044 } | |
6045 else | |
6046 { | |
6047 c = ins_copychar(curwin->w_cursor.lnum + (c == Ctrl_Y ? -1 : 1)); | |
6048 if (c != NUL) | |
6049 { | |
6050 long tw_save; | |
6051 | |
6052 /* The character must be taken literally, insert like it | |
6053 * was typed after a CTRL-V, and pretend 'textwidth' | |
6054 * wasn't set. Digits, 'o' and 'x' are special after a | |
6055 * CTRL-V, don't use it for these. */ | |
6056 if (c < 256 && !isalnum(c)) | |
6057 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */ | |
6058 tw_save = curbuf->b_p_tw; | |
6059 curbuf->b_p_tw = -1; | |
6060 insert_special(c, TRUE, FALSE); | |
6061 curbuf->b_p_tw = tw_save; | |
6062 #ifdef FEAT_RIGHTLEFT | |
6063 revins_chars++; | |
6064 revins_legal++; | |
6065 #endif | |
6066 c = Ctrl_V; /* pretend CTRL-V is last character */ | |
6067 auto_format(FALSE, TRUE); | |
6068 } | |
6069 } | |
6070 return c; | |
6071 } | |
6072 | |
7 | 6073 #ifdef FEAT_SMARTINDENT |
6074 /* | |
6075 * Try to do some very smart auto-indenting. | |
6076 * Used when inserting a "normal" character. | |
6077 */ | |
6078 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6079 ins_try_si(int c) |
7 | 6080 { |
6081 pos_T *pos, old_pos; | |
6082 char_u *ptr; | |
6083 int i; | |
6084 int temp; | |
6085 | |
6086 /* | |
6087 * do some very smart indenting when entering '{' or '}' | |
6088 */ | |
6089 if (((did_si || can_si_back) && c == '{') || (can_si && c == '}')) | |
6090 { | |
6091 /* | |
6092 * for '}' set indent equal to indent of line containing matching '{' | |
6093 */ | |
6094 if (c == '}' && (pos = findmatch(NULL, '{')) != NULL) | |
6095 { | |
6096 old_pos = curwin->w_cursor; | |
6097 /* | |
6098 * If the matching '{' has a ')' immediately before it (ignoring | |
6099 * white-space), then line up with the start of the line | |
6100 * containing the matching '(' if there is one. This handles the | |
6101 * case where an "if (..\n..) {" statement continues over multiple | |
6102 * lines -- webb | |
6103 */ | |
6104 ptr = ml_get(pos->lnum); | |
6105 i = pos->col; | |
6106 if (i > 0) /* skip blanks before '{' */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6107 while (--i > 0 && VIM_ISWHITE(ptr[i])) |
7 | 6108 ; |
6109 curwin->w_cursor.lnum = pos->lnum; | |
6110 curwin->w_cursor.col = i; | |
6111 if (ptr[i] == ')' && (pos = findmatch(NULL, '(')) != NULL) | |
6112 curwin->w_cursor = *pos; | |
6113 i = get_indent(); | |
6114 curwin->w_cursor = old_pos; | |
6115 if (State & VREPLACE_FLAG) | |
1516 | 6116 change_indent(INDENT_SET, i, FALSE, NUL, TRUE); |
7 | 6117 else |
6118 (void)set_indent(i, SIN_CHANGED); | |
6119 } | |
6120 else if (curwin->w_cursor.col > 0) | |
6121 { | |
6122 /* | |
6123 * when inserting '{' after "O" reduce indent, but not | |
6124 * more than indent of previous line | |
6125 */ | |
6126 temp = TRUE; | |
6127 if (c == '{' && can_si_back && curwin->w_cursor.lnum > 1) | |
6128 { | |
6129 old_pos = curwin->w_cursor; | |
6130 i = get_indent(); | |
6131 while (curwin->w_cursor.lnum > 1) | |
6132 { | |
6133 ptr = skipwhite(ml_get(--(curwin->w_cursor.lnum))); | |
6134 | |
6135 /* ignore empty lines and lines starting with '#'. */ | |
6136 if (*ptr != '#' && *ptr != NUL) | |
6137 break; | |
6138 } | |
6139 if (get_indent() >= i) | |
6140 temp = FALSE; | |
6141 curwin->w_cursor = old_pos; | |
6142 } | |
6143 if (temp) | |
1516 | 6144 shift_line(TRUE, FALSE, 1, TRUE); |
7 | 6145 } |
6146 } | |
6147 | |
6148 /* | |
6149 * set indent of '#' always to 0 | |
6150 */ | |
6151 if (curwin->w_cursor.col > 0 && can_si && c == '#') | |
6152 { | |
6153 /* remember current indent for next line */ | |
6154 old_indent = get_indent(); | |
6155 (void)set_indent(0, SIN_CHANGED); | |
6156 } | |
6157 | |
6158 /* Adjust ai_col, the char at this position can be deleted. */ | |
6159 if (ai_col > curwin->w_cursor.col) | |
6160 ai_col = curwin->w_cursor.col; | |
6161 } | |
6162 #endif | |
6163 | |
6164 /* | |
6165 * Get the value that w_virtcol would have when 'list' is off. | |
6166 * Unless 'cpo' contains the 'L' flag. | |
6167 */ | |
15062
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
14985
diff
changeset
|
6168 colnr_T |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6169 get_nolist_virtcol(void) |
7 | 6170 { |
15062
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
14985
diff
changeset
|
6171 // check validity of cursor in current buffer |
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
14985
diff
changeset
|
6172 if (curwin->w_buffer == NULL |
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
14985
diff
changeset
|
6173 || curwin->w_buffer->b_ml.ml_mfp == NULL |
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
14985
diff
changeset
|
6174 || curwin->w_cursor.lnum > curwin->w_buffer->b_ml.ml_line_count) |
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
14985
diff
changeset
|
6175 return 0; |
7 | 6176 if (curwin->w_p_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL) |
6177 return getvcol_nolist(&curwin->w_cursor); | |
6178 validate_virtcol(); | |
6179 return curwin->w_virtcol; | |
6180 } | |
3390 | 6181 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
6182 #if defined(FEAT_EVAL) |
3390 | 6183 /* |
6184 * Handle the InsertCharPre autocommand. | |
6185 * "c" is the character that was typed. | |
6186 * Return a pointer to allocated memory with the replacement string. | |
6187 * Return NULL to continue inserting "c". | |
6188 */ | |
6189 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6190 do_insert_char_pre(int c) |
3390 | 6191 { |
3547 | 6192 char_u *res; |
6193 char_u buf[MB_MAXBYTES + 1]; | |
15377
88b0a490816e
patch 8.1.0696: when test_edit fails 'insertmode' may not be reset
Bram Moolenaar <Bram@vim.org>
parents:
15349
diff
changeset
|
6194 int save_State = State; |
3390 | 6195 |
6196 /* Return quickly when there is nothing to do. */ | |
6197 if (!has_insertcharpre()) | |
6198 return NULL; | |
6199 | |
3547 | 6200 if (has_mbyte) |
6201 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6202 else | |
6203 { | |
6204 buf[0] = c; | |
6205 buf[1] = NUL; | |
6206 } | |
6207 | |
3390 | 6208 /* Lock the text to avoid weird things from happening. */ |
6209 ++textlock; | |
3547 | 6210 set_vim_var_string(VV_CHAR, buf, -1); /* set v:char */ |
6211 | |
6212 res = NULL; | |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6213 if (ins_apply_autocmds(EVENT_INSERTCHARPRE)) |
3547 | 6214 { |
6215 /* Get the value of v:char. It may be empty or more than one | |
6216 * character. Only use it when changed, otherwise continue with the | |
6217 * original character to avoid breaking autoindent. */ | |
6218 if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0) | |
6219 res = vim_strsave(get_vim_var_str(VV_CHAR)); | |
6220 } | |
3390 | 6221 |
6222 set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */ | |
6223 --textlock; | |
6224 | |
15377
88b0a490816e
patch 8.1.0696: when test_edit fails 'insertmode' may not be reset
Bram Moolenaar <Bram@vim.org>
parents:
15349
diff
changeset
|
6225 // Restore the State, it may have been changed. |
88b0a490816e
patch 8.1.0696: when test_edit fails 'insertmode' may not be reset
Bram Moolenaar <Bram@vim.org>
parents:
15349
diff
changeset
|
6226 State = save_State; |
88b0a490816e
patch 8.1.0696: when test_edit fails 'insertmode' may not be reset
Bram Moolenaar <Bram@vim.org>
parents:
15349
diff
changeset
|
6227 |
3390 | 6228 return res; |
6229 } | |
6230 #endif | |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6231 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6232 #if defined(FEAT_CINDENT) || defined(PROTO) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6233 int |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18098
diff
changeset
|
6234 get_can_cindent(void) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6235 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6236 return can_cindent; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6237 } |
18135
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18098
diff
changeset
|
6238 |
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18098
diff
changeset
|
6239 void |
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18098
diff
changeset
|
6240 set_can_cindent(int val) |
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18098
diff
changeset
|
6241 { |
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18098
diff
changeset
|
6242 can_cindent = val; |
1868ec23360e
patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
18098
diff
changeset
|
6243 } |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6244 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6245 |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6246 /* |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6247 * Trigger "event" and take care of fixing undo. |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6248 */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
16127
diff
changeset
|
6249 int |
14485
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6250 ins_apply_autocmds(event_T event) |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6251 { |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6252 varnumber_T tick = CHANGEDTICK(curbuf); |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6253 int r; |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6254 |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6255 r = apply_autocmds(event, NULL, NULL, FALSE, curbuf); |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6256 |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6257 // If u_savesub() was called then we are not prepared to start |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6258 // a new line. Call u_save() with no contents to fix that. |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6259 if (tick != CHANGEDTICK(curbuf)) |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6260 u_save(curwin->w_cursor.lnum, (linenr_T)(curwin->w_cursor.lnum + 1)); |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6261 |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6262 return r; |
c71d65c3672f
patch 8.1.0256: using setline() in TextChangedI splits undo
Christian Brabandt <cb@256bit.org>
parents:
14465
diff
changeset
|
6263 } |