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