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