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