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