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