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